goodteditor-ui 1.0.23 → 1.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +7 -7
- package/.prettierrc +14 -14
- package/README.md +35 -35
- package/babel.config.js +5 -5
- package/dist/js.png +0 -0
- package/index.js +53 -53
- package/jsconfig.json +13 -13
- package/package.json +67 -66
- package/src/App.vue +36 -36
- package/src/components/ui/Avatar.md +68 -68
- package/src/components/ui/Avatar.vue +180 -180
- package/src/components/ui/Badge.md +20 -20
- package/src/components/ui/Badge.vue +75 -75
- package/src/components/ui/Collapse.md +90 -90
- package/src/components/ui/Collapse.vue +86 -86
- package/src/components/ui/ColorPicker/Alpha.vue +114 -114
- package/src/components/ui/ColorPicker/Colors.vue +117 -117
- package/src/components/ui/ColorPicker/Hue.vue +113 -113
- package/src/components/ui/ColorPicker/Preview.vue +55 -55
- package/src/components/ui/ColorPicker/Saturation.vue +123 -123
- package/src/components/ui/ColorPicker/mixin.js +105 -105
- package/src/components/ui/ColorPicker.md +17 -17
- package/src/components/ui/ColorPicker.vue +314 -314
- package/src/components/ui/Datalist.md +41 -41
- package/src/components/ui/Datalist.vue +157 -157
- package/src/components/ui/DatePicker.md +168 -168
- package/src/components/ui/DatePicker.vue +527 -527
- package/src/components/ui/FileSelector.md +105 -105
- package/src/components/ui/FileSelector.vue +82 -82
- package/src/components/ui/Grid.md +130 -130
- package/src/components/ui/Grid.vue +92 -92
- package/src/components/ui/Image.md +59 -59
- package/src/components/ui/Image.vue +57 -57
- package/src/components/ui/InputAutocomplete.md +115 -115
- package/src/components/ui/InputAutocomplete.vue +341 -341
- package/src/components/ui/InputColorPicker.md +51 -51
- package/src/components/ui/InputColorPicker.vue +151 -151
- package/src/components/ui/InputDatePicker.md +121 -121
- package/src/components/ui/InputDatePicker.vue +326 -326
- package/src/components/ui/InputTags.md +51 -51
- package/src/components/ui/InputTags.vue +184 -184
- package/src/components/ui/InputTimePicker.md +25 -25
- package/src/components/ui/InputTimePicker.vue +253 -253
- package/src/components/ui/InputUnits.md +20 -20
- package/src/components/ui/InputUnits.vue +257 -257
- package/src/components/ui/Lazy.md +37 -37
- package/src/components/ui/Lazy.vue +92 -92
- package/src/components/ui/Pagination.md +74 -74
- package/src/components/ui/Pagination.vue +138 -138
- package/src/components/ui/Paginator.md +34 -34
- package/src/components/ui/Paginator.vue +83 -83
- package/src/components/ui/Popover.md +34 -34
- package/src/components/ui/Popover.vue +274 -274
- package/src/components/ui/Popup.md +59 -59
- package/src/components/ui/Popup.vue +150 -150
- package/src/components/ui/ResponsiveContainer.md +58 -58
- package/src/components/ui/ResponsiveContainer.vue +99 -99
- package/src/components/ui/Select.md +187 -187
- package/src/components/ui/Select.vue +421 -421
- package/src/components/ui/TimePicker.md +50 -50
- package/src/components/ui/TimePicker.vue +252 -252
- package/src/components/ui/Tooltip.md +54 -54
- package/src/components/ui/Tooltip.vue +113 -113
- package/src/components/ui/WysiwygEditor/WysiwygEditor.d.ts +119 -119
- package/src/components/ui/WysiwygEditor/constants.js +264 -264
- package/src/components/ui/WysiwygEditor/extensions/blockquote.js +15 -15
- package/src/components/ui/WysiwygEditor/extensions/bold.js +15 -15
- package/src/components/ui/WysiwygEditor/extensions/bullet-list.js +15 -15
- package/src/components/ui/WysiwygEditor/extensions/code-block.js +13 -13
- package/src/components/ui/WysiwygEditor/extensions/code.js +13 -13
- package/src/components/ui/WysiwygEditor/extensions/font-size.js +34 -34
- package/src/components/ui/WysiwygEditor/extensions/formatting.js +14 -14
- package/src/components/ui/WysiwygEditor/extensions/heading.js +13 -13
- package/src/components/ui/WysiwygEditor/extensions/horizontal-rule.js +15 -15
- package/src/components/ui/WysiwygEditor/extensions/image.js +19 -19
- package/src/components/ui/WysiwygEditor/extensions/index.d.ts +32 -32
- package/src/components/ui/WysiwygEditor/extensions/index.js +32 -32
- package/src/components/ui/WysiwygEditor/extensions/italic.js +15 -15
- package/src/components/ui/WysiwygEditor/extensions/link.js +16 -16
- package/src/components/ui/WysiwygEditor/extensions/list-item.js +15 -15
- package/src/components/ui/WysiwygEditor/extensions/ordered-list.js +15 -15
- package/src/components/ui/WysiwygEditor/extensions/paragraph.js +23 -23
- package/src/components/ui/WysiwygEditor/extensions/strike.js +15 -15
- package/src/components/ui/WysiwygEditor/extensions/table-cell.js +13 -13
- package/src/components/ui/WysiwygEditor/extensions/table-header.js +15 -15
- package/src/components/ui/WysiwygEditor/extensions/table-row.js +15 -15
- package/src/components/ui/WysiwygEditor/extensions/table.js +29 -29
- package/src/components/ui/WysiwygEditor/extensions/text-align.js +6 -6
- package/src/components/ui/WysiwygEditor/extensions/text-style.js +15 -15
- package/src/components/ui/WysiwygEditor/extensions/underline.js +15 -15
- package/src/components/ui/WysiwygEditor/index.d.ts +4 -4
- package/src/components/ui/WysiwygEditor/index.js +4 -4
- package/src/components/ui/WysiwygEditor/renders/Button.vue +28 -28
- package/src/components/ui/WysiwygEditor/renders/ColorPicker.vue +41 -41
- package/src/components/ui/WysiwygEditor/renders/InputAuto.vue +34 -34
- package/src/components/ui/WysiwygEditor/renders/InputBrowse.vue +35 -35
- package/src/components/ui/WysiwygEditor/renders/InputUnits.vue +38 -38
- package/src/components/ui/WysiwygEditor/renders/Link.vue +87 -87
- package/src/components/ui/WysiwygEditor/renders/Select.vue +47 -47
- package/src/components/ui/WysiwygEditor/renders/ToolbarPopover.vue +49 -49
- package/src/components/ui/WysiwygEditor/renders/index.d.ts +8 -8
- package/src/components/ui/WysiwygEditor/renders/index.js +8 -8
- package/src/components/ui/WysiwygEditor/renders/mixins/RenderMixin.js +39 -39
- package/src/components/ui/WysiwygEditor/renders/mixins/index.js +1 -1
- package/src/components/ui/WysiwygEditor/tools-and-commands.js +704 -704
- package/src/components/ui/WysiwygEditor/utils.js +72 -72
- package/src/components/ui/WysiwygEditor.md +18 -18
- package/src/components/ui/WysiwygEditor.vue +266 -271
- package/src/components/ui/utils/FormComponent.js +107 -107
- package/src/components/ui/utils/Helpers.js +84 -84
- package/src/components/ui/utils/WithPopover.js +81 -81
- package/src/main.js +8 -8
- package/styleguide.config.js +37 -37
- package/vue.config.js +8 -8
|
@@ -1,271 +1,266 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<grid class="editor" v-bind="$options.static.GridProps">
|
|
3
|
-
<template #editor-toolbar="{ style }">
|
|
4
|
-
<div :style="style" class="editor-toolbar">
|
|
5
|
-
<!--
|
|
6
|
-
@slot Toolbar slot
|
|
7
|
-
@binding {Tool[][]} toolGroups 2d matrix of using tools split into groups
|
|
8
|
-
@binding {Function} resolveGroupTitle resolve group title function(index:number)
|
|
9
|
-
@binding {Function} buildToolBinds build tool binds function(tool:Tool)
|
|
10
|
-
-->
|
|
11
|
-
<slot
|
|
12
|
-
v-if="editor != null"
|
|
13
|
-
name="toolbar"
|
|
14
|
-
v-bind="{ toolGroups, resolveGroupTitle, buildToolBinds }">
|
|
15
|
-
<div class="row row-gap-l1">
|
|
16
|
-
<div
|
|
17
|
-
v-for="(toolsGroup, groupIndex) of toolGroups"
|
|
18
|
-
:key="groupIndex"
|
|
19
|
-
class="col col-vmid col-auto">
|
|
20
|
-
<div class="d-flex flex-col flex-v-center">
|
|
21
|
-
<div class="group-header">
|
|
22
|
-
<!--
|
|
23
|
-
@slot Group header slot
|
|
24
|
-
@binding {number} groupIndex index of the tools group
|
|
25
|
-
@binding {Function} resolveGroupTitle resolve group title function(index:number)
|
|
26
|
-
-->
|
|
27
|
-
<slot name="group-header" v-bind="{ groupIndex, resolveGroupTitle }">
|
|
28
|
-
<div class="text-small text-center">{{ resolveGroupTitle(groupIndex) }}</div>
|
|
29
|
-
</slot>
|
|
30
|
-
</div>
|
|
31
|
-
<div>
|
|
32
|
-
<div
|
|
33
|
-
v-for="tool of toolsGroup"
|
|
34
|
-
:key="tool.name"
|
|
35
|
-
class="tool d-inline-block">
|
|
36
|
-
<!--
|
|
37
|
-
@slot Tool slot
|
|
38
|
-
@binding {Tool} tool tool's already bound to editor context
|
|
39
|
-
-->
|
|
40
|
-
<slot name="tool" v-bind="buildToolBinds(tool)">
|
|
41
|
-
<component :is="tool.render" :tool="buildToolBinds(tool)" />
|
|
42
|
-
</slot>
|
|
43
|
-
</div>
|
|
44
|
-
</div>
|
|
45
|
-
</div>
|
|
46
|
-
</div>
|
|
47
|
-
</div>
|
|
48
|
-
</slot>
|
|
49
|
-
</div>
|
|
50
|
-
</template>
|
|
51
|
-
<template #editor-content="{ style }">
|
|
52
|
-
<div :style="style" class="editor-content pad-v-l1" >
|
|
53
|
-
<div class="h-100">
|
|
54
|
-
<editor-content :editor="editor" class="h-100"/>
|
|
55
|
-
</div>
|
|
56
|
-
</div>
|
|
57
|
-
</template>
|
|
58
|
-
</grid>
|
|
59
|
-
</template>
|
|
60
|
-
|
|
61
|
-
<script>
|
|
62
|
-
import { Editor, EditorContent } from '@tiptap/vue-2';
|
|
63
|
-
|
|
64
|
-
import { debounce } from './utils/Helpers';
|
|
65
|
-
import Grid from './Grid.vue';
|
|
66
|
-
import * as Extensions from './WysiwygEditor/extensions';
|
|
67
|
-
import { buildToolGroups, bindContext } from './WysiwygEditor/utils';
|
|
68
|
-
import { DefaultTools, DefaultToolGroupsTitles } from './WysiwygEditor/constants';
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* @typedef {import('./WysiwygEditor/WysiwygEditor').ToolDef} Tool
|
|
72
|
-
*/
|
|
73
|
-
|
|
74
|
-
export default {
|
|
75
|
-
components: {
|
|
76
|
-
Grid,
|
|
77
|
-
EditorContent
|
|
78
|
-
},
|
|
79
|
-
props: {
|
|
80
|
-
/**
|
|
81
|
-
* @model
|
|
82
|
-
*/
|
|
83
|
-
value: {
|
|
84
|
-
type: String,
|
|
85
|
-
default: '',
|
|
86
|
-
},
|
|
87
|
-
/**
|
|
88
|
-
* 2d matrix of using tools
|
|
89
|
-
*/
|
|
90
|
-
tools: {
|
|
91
|
-
type: Array,
|
|
92
|
-
default: () => [],
|
|
93
|
-
validator: (tools) => tools.flat().every((tool) =>
|
|
94
|
-
typeof tool === 'string' || (tool != null && typeof tool === 'object' && Array.isArray(tool) === false)
|
|
95
|
-
)
|
|
96
|
-
},
|
|
97
|
-
/**
|
|
98
|
-
* editor tool groups titles
|
|
99
|
-
*/
|
|
100
|
-
groupsTitles: {
|
|
101
|
-
type: Array,
|
|
102
|
-
default: () => [],
|
|
103
|
-
validator: (titles) => titles.every((title) => typeof title === 'string')
|
|
104
|
-
},
|
|
105
|
-
/**
|
|
106
|
-
* @public
|
|
107
|
-
* func allows to receive image url from the environment
|
|
108
|
-
*/
|
|
109
|
-
getImageUrl: {
|
|
110
|
-
type: Function,
|
|
111
|
-
default: async () => {}
|
|
112
|
-
}
|
|
113
|
-
},
|
|
114
|
-
data: () => ({
|
|
115
|
-
/** @type {Editor} */
|
|
116
|
-
editor: null,
|
|
117
|
-
/** @type {Tool[][]} */
|
|
118
|
-
appliedTools: null,
|
|
119
|
-
/** @type {string[]} */
|
|
120
|
-
appliedGroupsTitles: null,
|
|
121
|
-
/** @type {number} */
|
|
122
|
-
caretPosition: 0
|
|
123
|
-
}),
|
|
124
|
-
computed: {
|
|
125
|
-
/**
|
|
126
|
-
* @return {string}
|
|
127
|
-
*/
|
|
128
|
-
content() {
|
|
129
|
-
return this.editor?.getHTML() ?? '';
|
|
130
|
-
},
|
|
131
|
-
/**
|
|
132
|
-
* @return {Tool[][]}
|
|
133
|
-
*/
|
|
134
|
-
toolGroups() {
|
|
135
|
-
return buildToolGroups(this.appliedTools);
|
|
136
|
-
}
|
|
137
|
-
},
|
|
138
|
-
static: {
|
|
139
|
-
GridProps: {
|
|
140
|
-
areas: [['editor-toolbar'], ['editor-content']],
|
|
141
|
-
rows: ['auto', '1fr'],
|
|
142
|
-
gap: ['0.5rem', 0]
|
|
143
|
-
}
|
|
144
|
-
},
|
|
145
|
-
watch: {
|
|
146
|
-
/**
|
|
147
|
-
* @param {string} value
|
|
148
|
-
*/
|
|
149
|
-
value(value) {
|
|
150
|
-
const isSame = this.content === value;
|
|
151
|
-
|
|
152
|
-
if (isSame) {
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
this.editor.commands.setContent(value, false);
|
|
157
|
-
},
|
|
158
|
-
},
|
|
159
|
-
created() {
|
|
160
|
-
this.onSelectionUpdateDebounced = debounce(this.onSelectionUpdate, 300);
|
|
161
|
-
this.appliedTools = this.tools.length === 0 ? DefaultTools : this.tools;
|
|
162
|
-
this.appliedGroupsTitles = this.groupsTitles.length === 0 ? DefaultToolGroupsTitles : this.groupsTitles;
|
|
163
|
-
|
|
164
|
-
this.editor = new Editor({
|
|
165
|
-
content: this.value,
|
|
166
|
-
extensions: Object.values(Extensions),
|
|
167
|
-
autofocus: 'end',
|
|
168
|
-
editorProps: {
|
|
169
|
-
attributes: {
|
|
170
|
-
class: 'pad-3 scroll-y',
|
|
171
|
-
style: 'min-height: 100%; height: 0;'
|
|
172
|
-
}
|
|
173
|
-
},
|
|
174
|
-
onUpdate: () => {
|
|
175
|
-
this.onInput();
|
|
176
|
-
this.onChange();
|
|
177
|
-
},
|
|
178
|
-
onSelectionUpdate: this.onSelectionUpdateDebounced
|
|
179
|
-
});
|
|
180
|
-
},
|
|
181
|
-
activated() {
|
|
182
|
-
this.editor.commands.focus(this.caretPosition);
|
|
183
|
-
},
|
|
184
|
-
beforeDestroy() {
|
|
185
|
-
this.editor?.destroy();
|
|
186
|
-
},
|
|
187
|
-
methods: {
|
|
188
|
-
onInput() {
|
|
189
|
-
/**
|
|
190
|
-
* Input event
|
|
191
|
-
* @property {string} value
|
|
192
|
-
*/
|
|
193
|
-
this.$emit('input', this.content);
|
|
194
|
-
},
|
|
195
|
-
onChange() {
|
|
196
|
-
/**
|
|
197
|
-
* change event
|
|
198
|
-
* @property {string} value
|
|
199
|
-
*/
|
|
200
|
-
this.$emit('change', this.content);
|
|
201
|
-
},
|
|
202
|
-
/**
|
|
203
|
-
* @param {Transaction} transaction
|
|
204
|
-
*/
|
|
205
|
-
onSelectionUpdate({ transaction }) {
|
|
206
|
-
this.caretPosition = transaction.curSelection.to;
|
|
207
|
-
},
|
|
208
|
-
/**
|
|
209
|
-
* @param {Tool} tool
|
|
210
|
-
* @return Tool
|
|
211
|
-
*/
|
|
212
|
-
buildToolBinds(tool) {
|
|
213
|
-
const { editor, toolGroups } = this;
|
|
214
|
-
|
|
215
|
-
const context = Object.freeze({
|
|
216
|
-
get editor() {
|
|
217
|
-
return editor;
|
|
218
|
-
},
|
|
219
|
-
get tool() {
|
|
220
|
-
return tool;
|
|
221
|
-
},
|
|
222
|
-
get tools() {
|
|
223
|
-
return toolGroups.flat();
|
|
224
|
-
},
|
|
225
|
-
change: this.change,
|
|
226
|
-
getImageUrl: this.getImageUrl
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
return bindContext(tool, context);
|
|
230
|
-
},
|
|
231
|
-
/**
|
|
232
|
-
* @param {number} groupIndex
|
|
233
|
-
* @return string
|
|
234
|
-
*/
|
|
235
|
-
resolveGroupTitle(groupIndex) {
|
|
236
|
-
const title = this.appliedGroupsTitles[groupIndex];
|
|
237
|
-
return typeof title === 'string' ? title : `Group ${groupIndex + 1}`;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
</script>
|
|
242
|
-
<style lang="less" scoped>
|
|
243
|
-
.editor {
|
|
244
|
-
&-toolbar {}
|
|
245
|
-
|
|
246
|
-
&-content {
|
|
247
|
-
min-height: 7.5rem;
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
.group-header {
|
|
252
|
-
min-height: calc(var(--line-height)*1rem)
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
.tool {
|
|
256
|
-
&:not(:last-child) {
|
|
257
|
-
margin-right: 0.25rem;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
::v-deep .ProseMirror {
|
|
262
|
-
& .ProseMirror-selectednode {
|
|
263
|
-
outline: 2px solid var(--color-focus);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
display: inline-block;
|
|
268
|
-
margin: 0;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
</style>
|
|
1
|
+
<template>
|
|
2
|
+
<grid class="editor" v-bind="$options.static.GridProps">
|
|
3
|
+
<template #editor-toolbar="{ style }">
|
|
4
|
+
<div :style="style" class="editor-toolbar">
|
|
5
|
+
<!--
|
|
6
|
+
@slot Toolbar slot
|
|
7
|
+
@binding {Tool[][]} toolGroups 2d matrix of using tools split into groups
|
|
8
|
+
@binding {Function} resolveGroupTitle resolve group title function(index:number)
|
|
9
|
+
@binding {Function} buildToolBinds build tool binds function(tool:Tool)
|
|
10
|
+
-->
|
|
11
|
+
<slot
|
|
12
|
+
v-if="editor != null"
|
|
13
|
+
name="toolbar"
|
|
14
|
+
v-bind="{ toolGroups, resolveGroupTitle, buildToolBinds }">
|
|
15
|
+
<div class="row row-gap-l1">
|
|
16
|
+
<div
|
|
17
|
+
v-for="(toolsGroup, groupIndex) of toolGroups"
|
|
18
|
+
:key="groupIndex"
|
|
19
|
+
class="col col-vmid col-auto">
|
|
20
|
+
<div class="d-flex flex-col flex-v-center">
|
|
21
|
+
<div class="group-header">
|
|
22
|
+
<!--
|
|
23
|
+
@slot Group header slot
|
|
24
|
+
@binding {number} groupIndex index of the tools group
|
|
25
|
+
@binding {Function} resolveGroupTitle resolve group title function(index:number)
|
|
26
|
+
-->
|
|
27
|
+
<slot name="group-header" v-bind="{ groupIndex, resolveGroupTitle }">
|
|
28
|
+
<div class="text-small text-center">{{ resolveGroupTitle(groupIndex) }}</div>
|
|
29
|
+
</slot>
|
|
30
|
+
</div>
|
|
31
|
+
<div>
|
|
32
|
+
<div
|
|
33
|
+
v-for="tool of toolsGroup"
|
|
34
|
+
:key="tool.name"
|
|
35
|
+
class="tool d-inline-block">
|
|
36
|
+
<!--
|
|
37
|
+
@slot Tool slot
|
|
38
|
+
@binding {Tool} tool tool's already bound to editor context
|
|
39
|
+
-->
|
|
40
|
+
<slot name="tool" v-bind="buildToolBinds(tool)">
|
|
41
|
+
<component :is="tool.render" :tool="buildToolBinds(tool)" />
|
|
42
|
+
</slot>
|
|
43
|
+
</div>
|
|
44
|
+
</div>
|
|
45
|
+
</div>
|
|
46
|
+
</div>
|
|
47
|
+
</div>
|
|
48
|
+
</slot>
|
|
49
|
+
</div>
|
|
50
|
+
</template>
|
|
51
|
+
<template #editor-content="{ style }">
|
|
52
|
+
<div :style="style" class="editor-content pad-v-l1" >
|
|
53
|
+
<div class="h-100">
|
|
54
|
+
<editor-content :editor="editor" class="h-100"/>
|
|
55
|
+
</div>
|
|
56
|
+
</div>
|
|
57
|
+
</template>
|
|
58
|
+
</grid>
|
|
59
|
+
</template>
|
|
60
|
+
|
|
61
|
+
<script>
|
|
62
|
+
import { Editor, EditorContent } from '@tiptap/vue-2';
|
|
63
|
+
|
|
64
|
+
import { debounce } from './utils/Helpers';
|
|
65
|
+
import Grid from './Grid.vue';
|
|
66
|
+
import * as Extensions from './WysiwygEditor/extensions';
|
|
67
|
+
import { buildToolGroups, bindContext } from './WysiwygEditor/utils';
|
|
68
|
+
import { DefaultTools, DefaultToolGroupsTitles } from './WysiwygEditor/constants';
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @typedef {import('./WysiwygEditor/WysiwygEditor').ToolDef} Tool
|
|
72
|
+
*/
|
|
73
|
+
|
|
74
|
+
export default {
|
|
75
|
+
components: {
|
|
76
|
+
Grid,
|
|
77
|
+
EditorContent
|
|
78
|
+
},
|
|
79
|
+
props: {
|
|
80
|
+
/**
|
|
81
|
+
* @model
|
|
82
|
+
*/
|
|
83
|
+
value: {
|
|
84
|
+
type: String,
|
|
85
|
+
default: '',
|
|
86
|
+
},
|
|
87
|
+
/**
|
|
88
|
+
* 2d matrix of using tools
|
|
89
|
+
*/
|
|
90
|
+
tools: {
|
|
91
|
+
type: Array,
|
|
92
|
+
default: () => [],
|
|
93
|
+
validator: (tools) => tools.flat().every((tool) =>
|
|
94
|
+
typeof tool === 'string' || (tool != null && typeof tool === 'object' && Array.isArray(tool) === false)
|
|
95
|
+
)
|
|
96
|
+
},
|
|
97
|
+
/**
|
|
98
|
+
* editor tool groups titles
|
|
99
|
+
*/
|
|
100
|
+
groupsTitles: {
|
|
101
|
+
type: Array,
|
|
102
|
+
default: () => [],
|
|
103
|
+
validator: (titles) => titles.every((title) => typeof title === 'string')
|
|
104
|
+
},
|
|
105
|
+
/**
|
|
106
|
+
* @public
|
|
107
|
+
* func allows to receive image url from the environment
|
|
108
|
+
*/
|
|
109
|
+
getImageUrl: {
|
|
110
|
+
type: Function,
|
|
111
|
+
default: async () => {}
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
data: () => ({
|
|
115
|
+
/** @type {Editor} */
|
|
116
|
+
editor: null,
|
|
117
|
+
/** @type {Tool[][]} */
|
|
118
|
+
appliedTools: null,
|
|
119
|
+
/** @type {string[]} */
|
|
120
|
+
appliedGroupsTitles: null,
|
|
121
|
+
/** @type {number} */
|
|
122
|
+
caretPosition: 0
|
|
123
|
+
}),
|
|
124
|
+
computed: {
|
|
125
|
+
/**
|
|
126
|
+
* @return {string}
|
|
127
|
+
*/
|
|
128
|
+
content() {
|
|
129
|
+
return this.editor?.getHTML() ?? '';
|
|
130
|
+
},
|
|
131
|
+
/**
|
|
132
|
+
* @return {Tool[][]}
|
|
133
|
+
*/
|
|
134
|
+
toolGroups() {
|
|
135
|
+
return buildToolGroups(this.appliedTools);
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
static: {
|
|
139
|
+
GridProps: {
|
|
140
|
+
areas: [['editor-toolbar'], ['editor-content']],
|
|
141
|
+
rows: ['auto', '1fr'],
|
|
142
|
+
gap: ['0.5rem', 0]
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
watch: {
|
|
146
|
+
/**
|
|
147
|
+
* @param {string} value
|
|
148
|
+
*/
|
|
149
|
+
value(value) {
|
|
150
|
+
const isSame = this.content === value;
|
|
151
|
+
|
|
152
|
+
if (isSame) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
this.editor.commands.setContent(value, false);
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
created() {
|
|
160
|
+
this.onSelectionUpdateDebounced = debounce(this.onSelectionUpdate, 300);
|
|
161
|
+
this.appliedTools = this.tools.length === 0 ? DefaultTools : this.tools;
|
|
162
|
+
this.appliedGroupsTitles = this.groupsTitles.length === 0 ? DefaultToolGroupsTitles : this.groupsTitles;
|
|
163
|
+
|
|
164
|
+
this.editor = new Editor({
|
|
165
|
+
content: this.value,
|
|
166
|
+
extensions: Object.values(Extensions),
|
|
167
|
+
autofocus: 'end',
|
|
168
|
+
editorProps: {
|
|
169
|
+
attributes: {
|
|
170
|
+
class: 'pad-3 scroll-y',
|
|
171
|
+
style: 'min-height: 100%; height: 0;'
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
onUpdate: () => {
|
|
175
|
+
this.onInput();
|
|
176
|
+
this.onChange();
|
|
177
|
+
},
|
|
178
|
+
onSelectionUpdate: this.onSelectionUpdateDebounced
|
|
179
|
+
});
|
|
180
|
+
},
|
|
181
|
+
activated() {
|
|
182
|
+
this.editor.commands.focus(this.caretPosition);
|
|
183
|
+
},
|
|
184
|
+
beforeDestroy() {
|
|
185
|
+
this.editor?.destroy();
|
|
186
|
+
},
|
|
187
|
+
methods: {
|
|
188
|
+
onInput() {
|
|
189
|
+
/**
|
|
190
|
+
* Input event
|
|
191
|
+
* @property {string} value
|
|
192
|
+
*/
|
|
193
|
+
this.$emit('input', this.content);
|
|
194
|
+
},
|
|
195
|
+
onChange() {
|
|
196
|
+
/**
|
|
197
|
+
* change event
|
|
198
|
+
* @property {string} value
|
|
199
|
+
*/
|
|
200
|
+
this.$emit('change', this.content);
|
|
201
|
+
},
|
|
202
|
+
/**
|
|
203
|
+
* @param {Transaction} transaction
|
|
204
|
+
*/
|
|
205
|
+
onSelectionUpdate({ transaction }) {
|
|
206
|
+
this.caretPosition = transaction.curSelection.to;
|
|
207
|
+
},
|
|
208
|
+
/**
|
|
209
|
+
* @param {Tool} tool
|
|
210
|
+
* @return Tool
|
|
211
|
+
*/
|
|
212
|
+
buildToolBinds(tool) {
|
|
213
|
+
const { editor, toolGroups } = this;
|
|
214
|
+
|
|
215
|
+
const context = Object.freeze({
|
|
216
|
+
get editor() {
|
|
217
|
+
return editor;
|
|
218
|
+
},
|
|
219
|
+
get tool() {
|
|
220
|
+
return tool;
|
|
221
|
+
},
|
|
222
|
+
get tools() {
|
|
223
|
+
return toolGroups.flat();
|
|
224
|
+
},
|
|
225
|
+
change: this.change,
|
|
226
|
+
getImageUrl: this.getImageUrl
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
return bindContext(tool, context);
|
|
230
|
+
},
|
|
231
|
+
/**
|
|
232
|
+
* @param {number} groupIndex
|
|
233
|
+
* @return string
|
|
234
|
+
*/
|
|
235
|
+
resolveGroupTitle(groupIndex) {
|
|
236
|
+
const title = this.appliedGroupsTitles[groupIndex];
|
|
237
|
+
return typeof title === 'string' ? title : `Group ${groupIndex + 1}`;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
</script>
|
|
242
|
+
<style lang="less" scoped>
|
|
243
|
+
.editor {
|
|
244
|
+
&-toolbar {}
|
|
245
|
+
|
|
246
|
+
&-content {
|
|
247
|
+
min-height: 7.5rem;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
.group-header {
|
|
252
|
+
min-height: calc(var(--line-height)*1rem)
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
.tool {
|
|
256
|
+
&:not(:last-child) {
|
|
257
|
+
margin-right: 0.25rem;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
::v-deep .ProseMirror {
|
|
262
|
+
& .ProseMirror-selectednode {
|
|
263
|
+
outline: 2px solid var(--color-focus);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
</style>
|