Skip to content

Commit 94a968f

Browse files
committed
feat(editor): commands dynamic prefixs
1 parent 5d12538 commit 94a968f

File tree

7 files changed

+144
-27
lines changed

7 files changed

+144
-27
lines changed

src/components/editor/absolute/EditorCommands.vue

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@
2525
>
2626
<EditorAbsoluteCommands
2727
:title="t('editor.aside.commands.contents[0].title')"
28-
:description="t('editor.aside.commands.contents[0].description')"
28+
:description="
29+
t('editor.aside.commands.contents[0].description', {
30+
prefix: `${EDITOR.configuration.commands.prefix}${EDITOR.configuration.commands.paragraph.prefix}`,
31+
})
32+
"
2933
>
3034
<template #icon>
3135
<svg
@@ -47,7 +51,11 @@
4751
</EditorAbsoluteCommands>
4852
<EditorAbsoluteCommands
4953
:title="t('editor.aside.commands.contents[4].title')"
50-
:description="t('editor.aside.commands.contents[4].description')"
54+
:description="
55+
t('editor.aside.commands.contents[4].description', {
56+
prefix: `${EDITOR.configuration.commands.prefix}${EDITOR.configuration.commands.headingTwo.prefix}`,
57+
})
58+
"
5159
>
5260
<template #icon>
5361
<svg
@@ -75,7 +83,11 @@
7583
</EditorAbsoluteCommands>
7684
<EditorAbsoluteCommands
7785
:title="t('editor.aside.commands.contents[5].title')"
78-
:description="t('editor.aside.commands.contents[5].description')"
86+
:description="
87+
t('editor.aside.commands.contents[5].description', {
88+
prefix: `${EDITOR.configuration.commands.prefix}${EDITOR.configuration.commands.lineBreak.prefix}`,
89+
})
90+
"
7991
>
8092
<template #icon>
8193
<svg
@@ -103,7 +115,11 @@
103115
</EditorAbsoluteCommands>
104116
<EditorAbsoluteCommands
105117
:title="t('editor.aside.commands.contents[6].title')"
106-
:description="t('editor.aside.commands.contents[6].description')"
118+
:description="
119+
t('editor.aside.commands.contents[6].description', {
120+
prefix: `${EDITOR.configuration.commands.prefix}${EDITOR.configuration.commands.pageBreak.prefix}`,
121+
})
122+
"
107123
>
108124
<template #icon>
109125
<svg
@@ -151,7 +167,11 @@
151167
</EditorAbsoluteCommands>
152168
<EditorAbsoluteCommands
153169
:title="t('editor.aside.commands.contents[7].title')"
154-
:description="t('editor.aside.commands.contents[7].description')"
170+
:description="
171+
t('editor.aside.commands.contents[7].description', {
172+
prefix: `${EDITOR.configuration.commands.prefix}${EDITOR.configuration.commands.lineBreak.prefix}`,
173+
})
174+
"
155175
>
156176
<template #icon>
157177
<svg
@@ -174,7 +194,11 @@
174194
</EditorAbsoluteCommands>
175195
<EditorAbsoluteCommands
176196
:title="t('editor.aside.commands.contents[8].title')"
177-
:description="t('editor.aside.commands.contents[8].description')"
197+
:description="
198+
t('editor.aside.commands.contents[8].description', {
199+
prefix: `${EDITOR.configuration.commands.prefix}${EDITOR.configuration.commands.image.prefix}`,
200+
})
201+
"
178202
>
179203
<template #icon>
180204
<svg
@@ -196,7 +220,12 @@
196220
</EditorAbsoluteCommands>
197221
<EditorAbsoluteCommands
198222
:title="t('editor.aside.commands.contents[9].title')"
199-
:description="t('editor.aside.commands.contents[9].description')"
223+
:description="
224+
t('editor.aside.commands.contents[9].description', {
225+
prefix: `${EDITOR.configuration.commands.prefix}${EDITOR.configuration.commands.dialogue.prefix}`,
226+
value: EDITOR.configuration.commands.dialogue.value,
227+
})
228+
"
200229
>
201230
<template #icon>
202231
<svg
@@ -220,7 +249,10 @@
220249
</template>
221250

222251
<script setup lang="ts">
252+
import { useEditorStore } from '@/store/editor'
223253
import { useI18n } from 'vue-i18n'
224254
255+
const EDITOR = useEditorStore()
256+
225257
const { t } = useI18n()
226258
</script>

src/components/editor/entity/EditorEntityInput.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ import { useUtils } from '@/use/utils'
205205
206206
input.value.setSelectionRange(offset, offset)
207207
208-
// cmp.value = sub
208+
cmp.value = sub
209209
return
210210
}
211211

src/lang/br/editor.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ export default {
328328
{
329329
tag: 'P',
330330
title: 'Parágrafo',
331-
description: '/p texto aqui',
331+
description: '{prefix} texto aqui',
332332
},
333333
{
334334
tag: 'B',
@@ -342,38 +342,38 @@ export default {
342342
},
343343
{
344344
tag: 'H1',
345-
title: 'Heading 1',
346-
description: '/h1 texto aqui',
345+
title: 'Cabeçalho 1',
346+
description: '{prefix} texto aqui',
347347
},
348348
{
349349
tag: 'H2',
350-
title: 'Heading 2',
351-
description: '/h2 texto aqui',
350+
title: 'Cabeçalho 2',
351+
description: '{prefix} texto aqui',
352352
},
353353
{
354354
tag: 'H3',
355-
title: 'Heading 3',
356-
description: '/h3 texto aqui',
355+
title: 'Cabeçalho 3',
356+
description: '{prefix} texto aqui',
357357
},
358358
{
359359
tag: 'BP',
360360
title: 'Quebra de Página',
361-
description: '/bp',
361+
description: '{prefix}',
362362
},
363363
{
364364
tag: 'LB',
365365
title: 'Quebra de Linha',
366-
description: '/lb',
366+
description: '{prefix}',
367367
},
368368
{
369369
tag: 'IM',
370370
title: 'Imagem',
371-
description: '/im',
371+
description: '{prefix}',
372372
},
373373
{
374374
tag: 'D',
375375
title: 'Diálogo',
376-
description: '/d',
376+
description: '{prefix} {value}',
377377
},
378378
],
379379
},

src/lang/en/editor.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ export default {
328328
{
329329
tag: 'P',
330330
title: 'Paragraph',
331-
description: '/p text here',
331+
description: '{prefix} text here',
332332
},
333333
{
334334
tag: 'B',
@@ -343,37 +343,37 @@ export default {
343343
{
344344
tag: 'H1',
345345
title: 'Heading 1',
346-
description: '/h1 text here',
346+
description: '{prefix} text here',
347347
},
348348
{
349349
tag: 'H2',
350350
title: 'Heading 2',
351-
description: '/h2 text here',
351+
description: '{prefix} text here',
352352
},
353353
{
354354
tag: 'H3',
355355
title: 'Heading 3',
356-
description: '/h3 text here',
356+
description: '{prefix} text here',
357357
},
358358
{
359359
tag: 'BP',
360360
title: 'Page Break',
361-
description: '/bp',
361+
description: '{prefix}',
362362
},
363363
{
364364
tag: 'LB',
365365
title: 'Line Break',
366-
description: '/lb',
366+
description: '{prefix}',
367367
},
368368
{
369369
tag: 'IM',
370370
title: 'Image',
371-
description: '/im',
371+
description: '{prefix}',
372372
},
373373
{
374374
tag: 'D',
375375
title: 'Dialogue',
376-
description: '/d',
376+
description: '{prefix} {value}',
377377
},
378378
],
379379
},

src/store/editor.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,31 @@ export const useEditorStore = defineStore('editor', {
5454
entity: {
5555
updateTime: true,
5656
},
57+
commands: {
58+
prefix: '/',
59+
paragraph: {
60+
prefix: 'p',
61+
},
62+
headingTwo: {
63+
prefix: 'h2',
64+
},
65+
headingThree: {
66+
prefix: 'h3',
67+
},
68+
pageBreak: {
69+
prefix: 'bp',
70+
},
71+
lineBreak: {
72+
prefix: 'lb',
73+
},
74+
image: {
75+
prefix: 'im',
76+
},
77+
dialogue: {
78+
prefix: 'd',
79+
value: '— ',
80+
},
81+
},
5782
},
5883
actives: {
5984
entity: {

src/types/editor.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,40 @@ export interface EditorStateConfigurationEntity {
3434
updateTime: boolean
3535
}
3636

37+
export interface EditorStateConfigurationCommands {
38+
prefix: string
39+
paragraph: {
40+
prefix: string
41+
}
42+
headingTwo: {
43+
prefix: string
44+
}
45+
headingThree: {
46+
prefix: string
47+
}
48+
pageBreak: {
49+
prefix: string
50+
}
51+
lineBreak: {
52+
prefix: string
53+
}
54+
image: {
55+
prefix: string
56+
}
57+
dialogue: {
58+
prefix: string
59+
value: string
60+
}
61+
}
62+
3763
export interface EditorStateConfiguration {
3864
theme: BetterWriteThemes
3965
lang?: boolean
4066
draggable: boolean
4167
bars: boolean
4268
auto: number | 'never'
4369
entity: EditorStateConfigurationEntity
70+
commands: EditorStateConfigurationCommands
4471
}
4572

4673
export interface EditorStateStyles {

src/use/storage/storage.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,39 @@ export const useStorage = () => {
168168
bars: false,
169169
}
170170
}
171+
172+
// <= 0.9.3
173+
if (!_.editor.configuration.commands) {
174+
_.editor.configuration = {
175+
..._.editor.configuration,
176+
commands: {
177+
prefix: '/',
178+
paragraph: {
179+
prefix: 'p',
180+
},
181+
headingTwo: {
182+
prefix: 'h2',
183+
},
184+
headingThree: {
185+
prefix: 'h3',
186+
},
187+
pageBreak: {
188+
prefix: 'bp',
189+
},
190+
lineBreak: {
191+
prefix: 'lb',
192+
},
193+
image: {
194+
prefix: 'im',
195+
},
196+
dialogue: {
197+
prefix: 'd',
198+
value: '— ',
199+
},
200+
},
201+
}
202+
}
203+
171204
return _
172205
}
173206

0 commit comments

Comments
 (0)