@yltrcc/vditor 0.0.7 โ†’ 0.0.8

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.
@@ -1,454 +1,455 @@
1
- import {Constants} from "../constants";
2
- import {merge} from "./merge";
3
-
4
- export class Options {
5
- public options: IOptions;
6
- private defaultOptions: IOptions = {
7
- rtl: false,
8
- after: undefined,
9
- cache: {
10
- enable: true,
11
- },
12
- cdn: Constants.CDN,
13
- classes: {
14
- preview: "",
15
- },
16
- comment: {
17
- enable: false,
18
- },
19
- counter: {
20
- enable: false,
21
- type: "markdown",
22
- },
23
- customRenders: [],
24
- debugger: false,
25
- fullscreen: {
26
- index: 90,
27
- },
28
- height: "auto",
29
- hint: {
30
- delay: 200,
31
- emoji: {
32
- "+1": "๐Ÿ‘",
33
- "-1": "๐Ÿ‘Ž",
34
- "confused": "๐Ÿ˜•",
35
- "eyes": "๐Ÿ‘€๏ธ",
36
- "heart": "โค๏ธ",
37
- "rocket": "๐Ÿš€๏ธ",
38
- "smile": "๐Ÿ˜„",
39
- "tada": "๐ŸŽ‰๏ธ",
40
- },
41
- emojiPath: `${Constants.CDN}/dist/images/emoji`,
42
- extend: [],
43
- parse: true,
44
- },
45
- icon: "ant",
46
- lang: "zh_CN",
47
- mode: "ir",
48
- outline: {
49
- enable: false,
50
- position: "left",
51
- },
52
- placeholder: "",
53
- preview: {
54
- actions: ["desktop", "tablet", "mobile", "mp-wechat", "zhihu"],
55
- delay: 1000,
56
- hljs: Constants.HLJS_OPTIONS,
57
- markdown: Constants.MARKDOWN_OPTIONS,
58
- math: Constants.MATH_OPTIONS,
59
- maxWidth: 800,
60
- mode: "both",
61
- theme: Constants.THEME_OPTIONS,
62
- render: {
63
- media: {
64
- enable: true,
65
- }
66
- }
67
- },
68
- link: {
69
- isOpen: true,
70
- },
71
- image: {
72
- isPreview: true,
73
- },
74
- resize: {
75
- enable: false,
76
- position: "bottom",
77
- },
78
- theme: "classic",
79
- toolbar: [
80
- "emoji",
81
- "headings",
82
- "bold",
83
- "italic",
84
- "strike",
85
- "link",
86
- "|",
87
- "list",
88
- "ordered-list",
89
- "check",
90
- "outdent",
91
- "indent",
92
- "|",
93
- "quote",
94
- "line",
95
- "code",
96
- "inline-code",
97
- "insert-before",
98
- "insert-after",
99
- "|",
100
- "upload",
101
- "record",
102
- "table",
103
- "|",
104
- "undo",
105
- "redo",
106
- "|",
107
- "fullscreen",
108
- "edit-mode",
109
- {
110
- name: "more",
111
- toolbar: [
112
- "both",
113
- "code-theme",
114
- "content-theme",
115
- "export",
116
- "outline",
117
- "preview",
118
- "devtools",
119
- "info",
120
- "help",
121
- ],
122
- },
123
- ],
124
- toolbarConfig: {
125
- hide: false,
126
- pin: false,
127
- },
128
- typewriterMode: false,
129
- undoDelay: 800,
130
- upload: {
131
- extraData: {},
132
- fieldName: "file[]",
133
- filename: (name: string) => name.replace(/\W/g, ""),
134
- linkToImgUrl: "",
135
- max: 10 * 1024 * 1024,
136
- multiple: true,
137
- url: "",
138
- withCredentials: false,
139
- },
140
- value: "",
141
- width: "auto",
142
- };
143
-
144
- constructor(options: IOptions) {
145
- this.options = options;
146
- }
147
-
148
- public merge(): IOptions {
149
- if (this.options) {
150
- if (this.options.toolbar) {
151
- this.options.toolbar = this.mergeToolbar(this.options.toolbar);
152
- } else {
153
- this.options.toolbar = this.mergeToolbar(this.defaultOptions.toolbar);
154
- }
155
- if (this.options.preview?.theme?.list) {
156
- this.defaultOptions.preview.theme.list = this.options.preview.theme.list;
157
- }
158
- if (this.options.preview?.render?.media?.enable) {
159
- this.defaultOptions.preview.render.media.enable = this.options.preview.render.media.enable;
160
- }
161
- if (this.options.hint?.emoji) {
162
- this.defaultOptions.hint.emoji = this.options.hint.emoji;
163
- }
164
- if (this.options.comment) {
165
- this.defaultOptions.comment = this.options.comment;
166
- }
167
-
168
- if (this.options.cdn) {
169
- if (!this.options.preview?.theme?.path) {
170
- this.defaultOptions.preview.theme.path = `${this.options.cdn}/dist/css/content-theme`
171
- }
172
- if (!this.options.hint?.emojiPath) {
173
- this.defaultOptions.hint.emojiPath = `${this.options.cdn}/dist/images/emoji`;
174
- }
175
- }
176
- }
177
-
178
- const mergedOptions = merge(this.defaultOptions, this.options);
179
-
180
- if (mergedOptions.cache.enable && !mergedOptions.cache.id) {
181
- throw new Error(
182
- "need options.cache.id, see https://ld246.com/article/1549638745630#options",
183
- );
184
- }
185
-
186
- return mergedOptions;
187
- }
188
-
189
- private mergeToolbar(toolbar: Array<string | IMenuItem>) {
190
- const toolbarItem = [
191
- {
192
- icon: '<svg><use xlink:href="#vditor-icon-export"></use></svg>',
193
- name: "export",
194
- tipPosition: "ne",
195
- },
196
- {
197
- hotkey: "โŒ˜E",
198
- icon: '<svg><use xlink:href="#vditor-icon-emoji"></use></svg>',
199
- name: "emoji",
200
- tipPosition: "ne",
201
- },
202
- {
203
- hotkey: "โŒ˜H",
204
- icon:
205
- '<svg><use xlink:href="#vditor-icon-headings"></use></svg>',
206
- name: "headings",
207
- tipPosition: "ne",
208
- },
209
- {
210
- hotkey: "โŒ˜B",
211
- icon: '<svg><use xlink:href="#vditor-icon-bold"></use></svg>',
212
- name: "bold",
213
- prefix: "**",
214
- suffix: "**",
215
- tipPosition: "ne",
216
- },
217
- {
218
- hotkey: "โŒ˜I",
219
- icon: '<svg><use xlink:href="#vditor-icon-italic"></use></svg>',
220
- name: "italic",
221
- prefix: "*",
222
- suffix: "*",
223
- tipPosition: "ne",
224
- },
225
- {
226
- hotkey: "โŒ˜D",
227
- icon: '<svg><use xlink:href="#vditor-icon-strike"></use></svg>',
228
- name: "strike",
229
- prefix: "~~",
230
- suffix: "~~",
231
- tipPosition: "ne",
232
- },
233
- {
234
- hotkey: "โŒ˜K",
235
- icon: '<svg><use xlink:href="#vditor-icon-link"></use></svg>',
236
- name: "link",
237
- prefix: "[",
238
- suffix: "](https://)",
239
- tipPosition: "n",
240
- },
241
- {
242
- name: "|",
243
- },
244
- {
245
- hotkey: "โŒ˜L",
246
- icon: '<svg><use xlink:href="#vditor-icon-list"></use></svg>',
247
- name: "list",
248
- prefix: "* ",
249
- tipPosition: "n",
250
- },
251
- {
252
- hotkey: "โŒ˜O",
253
- icon:
254
- '<svg><use xlink:href="#vditor-icon-ordered-list"></use></svg>',
255
- name: "ordered-list",
256
- prefix: "1. ",
257
- tipPosition: "n",
258
- },
259
- {
260
- hotkey: "โŒ˜J",
261
- icon: '<svg><use xlink:href="#vditor-icon-check"></use></svg>',
262
- name: "check",
263
- prefix: "* [ ] ",
264
- tipPosition: "n",
265
- },
266
- {
267
- hotkey: "โ‡งโŒ˜I",
268
- icon:
269
- '<svg><use xlink:href="#vditor-icon-outdent"></use></svg>',
270
- name: "outdent",
271
- tipPosition: "n",
272
- },
273
- {
274
- hotkey: "โ‡งโŒ˜O",
275
- icon: '<svg><use xlink:href="#vditor-icon-indent"></use></svg>',
276
- name: "indent",
277
- tipPosition: "n",
278
- },
279
- {
280
- name: "|",
281
- },
282
- {
283
- hotkey: "โŒ˜;",
284
- icon: '<svg><use xlink:href="#vditor-icon-quote"></use></svg>',
285
- name: "quote",
286
- prefix: "> ",
287
- tipPosition: "n",
288
- },
289
- {
290
- hotkey: "โ‡งโŒ˜H",
291
- icon: '<svg><use xlink:href="#vditor-icon-line"></use></svg>',
292
- name: "line",
293
- prefix: "---",
294
- tipPosition: "n",
295
- },
296
- {
297
- hotkey: "โŒ˜U",
298
- icon: '<svg><use xlink:href="#vditor-icon-code"></use></svg>',
299
- name: "code",
300
- prefix: "```",
301
- suffix: "\n```",
302
- tipPosition: "n",
303
- },
304
- {
305
- hotkey: "โŒ˜G",
306
- icon:
307
- '<svg><use xlink:href="#vditor-icon-inline-code"></use></svg>',
308
- name: "inline-code",
309
- prefix: "`",
310
- suffix: "`",
311
- tipPosition: "n",
312
- },
313
- {
314
- hotkey: "โ‡งโŒ˜B",
315
- icon: '<svg><use xlink:href="#vditor-icon-before"></use></svg>',
316
- name: "insert-before",
317
- tipPosition: "n",
318
- },
319
- {
320
- hotkey: "โ‡งโŒ˜E",
321
- icon: '<svg><use xlink:href="#vditor-icon-after"></use></svg>',
322
- name: "insert-after",
323
- tipPosition: "n",
324
- },
325
- {
326
- name: "|",
327
- },
328
- {
329
- icon: '<svg><use xlink:href="#vditor-icon-upload"></use></svg>',
330
- name: "upload",
331
- tipPosition: "n",
332
- },
333
- {
334
- icon: '<svg><use xlink:href="#vditor-icon-record"></use></svg>',
335
- name: "record",
336
- tipPosition: "n",
337
- },
338
- {
339
- hotkey: "โŒ˜M",
340
- icon: '<svg><use xlink:href="#vditor-icon-table"></use></svg>',
341
- name: "table",
342
- prefix: "| col1",
343
- suffix:
344
- " | col2 | col3 |\n| --- | --- | --- |\n| | | |\n| | | |",
345
- tipPosition: "n",
346
- },
347
- {
348
- name: "|",
349
- },
350
- {
351
- hotkey: "โŒ˜Z",
352
- icon: '<svg><use xlink:href="#vditor-icon-undo"></use></svg>',
353
- name: "undo",
354
- tipPosition: "nw",
355
- },
356
- {
357
- hotkey: "โŒ˜Y",
358
- icon: '<svg><use xlink:href="#vditor-icon-redo"></use></svg>',
359
- name: "redo",
360
- tipPosition: "nw",
361
- },
362
- {
363
- name: "|",
364
- },
365
- {
366
- icon: '<svg><use xlink:href="#vditor-icon-more"></use></svg>',
367
- name: "more",
368
- tipPosition: "e",
369
- },
370
- {
371
- hotkey: "โŒ˜'",
372
- icon:
373
- '<svg><use xlink:href="#vditor-icon-fullscreen"></use></svg>',
374
- name: "fullscreen",
375
- tipPosition: "nw",
376
- },
377
- {
378
- icon: '<svg><use xlink:href="#vditor-icon-edit"></use></svg>',
379
- name: "edit-mode",
380
- tipPosition: "nw",
381
- },
382
- {
383
- hotkey: "โŒ˜P",
384
- icon: '<svg><use xlink:href="#vditor-icon-both"></use></svg>',
385
- name: "both",
386
- tipPosition: "nw",
387
- },
388
- {
389
- icon:
390
- '<svg><use xlink:href="#vditor-icon-preview"></use></svg>',
391
- name: "preview",
392
- tipPosition: "nw",
393
- },
394
- {
395
- icon:
396
- '<svg><use xlink:href="#vditor-icon-align-center"></use></svg>',
397
- name: "outline",
398
- tipPosition: "nw",
399
- },
400
- {
401
- icon: '<svg><use xlink:href="#vditor-icon-theme"></use></svg>',
402
- name: "content-theme",
403
- tipPosition: "nw",
404
- },
405
- {
406
- icon:
407
- '<svg><use xlink:href="#vditor-icon-code-theme"></use></svg>',
408
- name: "code-theme",
409
- tipPosition: "nw",
410
- },
411
- {
412
- icon: '<svg><use xlink:href="#vditor-icon-bug"></use></svg>',
413
- name: "devtools",
414
- tipPosition: "nw",
415
- },
416
- {
417
- icon: '<svg><use xlink:href="#vditor-icon-info"></use></svg>',
418
- name: "info",
419
- tipPosition: "nw",
420
- },
421
- {
422
- icon: '<svg><use xlink:href="#vditor-icon-help"></use></svg>',
423
- name: "help",
424
- tipPosition: "nw",
425
- },
426
- {
427
- name: "br",
428
- },
429
- ];
430
- const toolbarResult: IMenuItem[] = [];
431
- toolbar.forEach((menuItem: IMenuItem) => {
432
- let currentMenuItem = menuItem;
433
- toolbarItem.forEach((defaultMenuItem: IMenuItem) => {
434
- if (
435
- typeof menuItem === "string" &&
436
- defaultMenuItem.name === menuItem
437
- ) {
438
- currentMenuItem = defaultMenuItem;
439
- }
440
- if (
441
- typeof menuItem === "object" &&
442
- defaultMenuItem.name === menuItem.name
443
- ) {
444
- currentMenuItem = Object.assign({}, defaultMenuItem, menuItem);
445
- }
446
- });
447
- if (menuItem.toolbar) {
448
- currentMenuItem.toolbar = this.mergeToolbar(menuItem.toolbar);
449
- }
450
- toolbarResult.push(currentMenuItem);
451
- });
452
- return toolbarResult;
453
- }
454
- }
1
+ import {Constants} from "../constants";
2
+ import {merge} from "./merge";
3
+
4
+ export class Options {
5
+ public options: IOptions;
6
+ private defaultOptions: IOptions = {
7
+ rtl: false,
8
+ after: undefined,
9
+ cache: {
10
+ enable: true,
11
+ },
12
+ cdn: Constants.CDN,
13
+ classes: {
14
+ preview: "",
15
+ },
16
+ comment: {
17
+ enable: false,
18
+ },
19
+ counter: {
20
+ enable: false,
21
+ type: "markdown",
22
+ },
23
+ customRenders: [],
24
+ debugger: false,
25
+ fullscreen: {
26
+ index: 90,
27
+ },
28
+ height: "auto",
29
+ hint: {
30
+ delay: 200,
31
+ emoji: {
32
+ "+1": "๐Ÿ‘",
33
+ "-1": "๐Ÿ‘Ž",
34
+ "confused": "๐Ÿ˜•",
35
+ "eyes": "๐Ÿ‘€๏ธ",
36
+ "heart": "โค๏ธ",
37
+ "rocket": "๐Ÿš€๏ธ",
38
+ "smile": "๐Ÿ˜„",
39
+ "tada": "๐ŸŽ‰๏ธ",
40
+ },
41
+ emojiPath: `${Constants.CDN}/dist/images/emoji`,
42
+ extend: [],
43
+ parse: true,
44
+ },
45
+ icon: "ant",
46
+ lang: "zh_CN",
47
+ mode: "ir",
48
+ outline: {
49
+ enable: false,
50
+ position: "left",
51
+ },
52
+ placeholder: "",
53
+ preview: {
54
+ actions: ["desktop", "tablet", "mobile", "mp-wechat", "zhihu"],
55
+ delay: 1000,
56
+ hljs: Constants.HLJS_OPTIONS,
57
+ markdown: Constants.MARKDOWN_OPTIONS,
58
+ math: Constants.MATH_OPTIONS,
59
+ maxWidth: 800,
60
+ mode: "both",
61
+ theme: Constants.THEME_OPTIONS,
62
+ render: {
63
+ media: {
64
+ enable: true,
65
+ }
66
+ }
67
+ },
68
+ link: {
69
+ isOpen: true,
70
+ },
71
+ image: {
72
+ isPreview: true,
73
+ },
74
+ resize: {
75
+ enable: false,
76
+ position: "bottom",
77
+ },
78
+ theme: "classic",
79
+ toolbar: [
80
+ "emoji",
81
+ "headings",
82
+ "bold",
83
+ "italic",
84
+ "strike",
85
+ "link",
86
+ "|",
87
+ "list",
88
+ "ordered-list",
89
+ "check",
90
+ "outdent",
91
+ "indent",
92
+ "|",
93
+ "quote",
94
+ "line",
95
+ "code",
96
+ "inline-code",
97
+ "insert-before",
98
+ "insert-after",
99
+ "|",
100
+ "upload",
101
+ "record",
102
+ "table",
103
+ "|",
104
+ "undo",
105
+ "redo",
106
+ "|",
107
+ "fullscreen",
108
+ "edit-mode",
109
+ {
110
+ name: "more",
111
+ toolbar: [
112
+ "both",
113
+ "code-theme",
114
+ "content-theme",
115
+ "export",
116
+ "outline",
117
+ "preview",
118
+ "devtools",
119
+ "info",
120
+ "help",
121
+ ],
122
+ },
123
+ ],
124
+ toolbarConfig: {
125
+ hide: false,
126
+ pin: false,
127
+ },
128
+ typewriterMode: false,
129
+ undoDelay: 800,
130
+ docLinkDelay: 50,
131
+ upload: {
132
+ extraData: {},
133
+ fieldName: "file[]",
134
+ filename: (name: string) => name.replace(/\W/g, ""),
135
+ linkToImgUrl: "",
136
+ max: 10 * 1024 * 1024,
137
+ multiple: true,
138
+ url: "",
139
+ withCredentials: false,
140
+ },
141
+ value: "",
142
+ width: "auto",
143
+ };
144
+
145
+ constructor(options: IOptions) {
146
+ this.options = options;
147
+ }
148
+
149
+ public merge(): IOptions {
150
+ if (this.options) {
151
+ if (this.options.toolbar) {
152
+ this.options.toolbar = this.mergeToolbar(this.options.toolbar);
153
+ } else {
154
+ this.options.toolbar = this.mergeToolbar(this.defaultOptions.toolbar);
155
+ }
156
+ if (this.options.preview?.theme?.list) {
157
+ this.defaultOptions.preview.theme.list = this.options.preview.theme.list;
158
+ }
159
+ if (this.options.preview?.render?.media?.enable) {
160
+ this.defaultOptions.preview.render.media.enable = this.options.preview.render.media.enable;
161
+ }
162
+ if (this.options.hint?.emoji) {
163
+ this.defaultOptions.hint.emoji = this.options.hint.emoji;
164
+ }
165
+ if (this.options.comment) {
166
+ this.defaultOptions.comment = this.options.comment;
167
+ }
168
+
169
+ if (this.options.cdn) {
170
+ if (!this.options.preview?.theme?.path) {
171
+ this.defaultOptions.preview.theme.path = `${this.options.cdn}/dist/css/content-theme`
172
+ }
173
+ if (!this.options.hint?.emojiPath) {
174
+ this.defaultOptions.hint.emojiPath = `${this.options.cdn}/dist/images/emoji`;
175
+ }
176
+ }
177
+ }
178
+
179
+ const mergedOptions = merge(this.defaultOptions, this.options);
180
+
181
+ if (mergedOptions.cache.enable && !mergedOptions.cache.id) {
182
+ throw new Error(
183
+ "need options.cache.id, see https://ld246.com/article/1549638745630#options",
184
+ );
185
+ }
186
+
187
+ return mergedOptions;
188
+ }
189
+
190
+ private mergeToolbar(toolbar: Array<string | IMenuItem>) {
191
+ const toolbarItem = [
192
+ {
193
+ icon: '<svg><use xlink:href="#vditor-icon-export"></use></svg>',
194
+ name: "export",
195
+ tipPosition: "ne",
196
+ },
197
+ {
198
+ hotkey: "โŒ˜E",
199
+ icon: '<svg><use xlink:href="#vditor-icon-emoji"></use></svg>',
200
+ name: "emoji",
201
+ tipPosition: "ne",
202
+ },
203
+ {
204
+ hotkey: "โŒ˜H",
205
+ icon:
206
+ '<svg><use xlink:href="#vditor-icon-headings"></use></svg>',
207
+ name: "headings",
208
+ tipPosition: "ne",
209
+ },
210
+ {
211
+ hotkey: "โŒ˜B",
212
+ icon: '<svg><use xlink:href="#vditor-icon-bold"></use></svg>',
213
+ name: "bold",
214
+ prefix: "**",
215
+ suffix: "**",
216
+ tipPosition: "ne",
217
+ },
218
+ {
219
+ hotkey: "โŒ˜I",
220
+ icon: '<svg><use xlink:href="#vditor-icon-italic"></use></svg>',
221
+ name: "italic",
222
+ prefix: "*",
223
+ suffix: "*",
224
+ tipPosition: "ne",
225
+ },
226
+ {
227
+ hotkey: "โŒ˜D",
228
+ icon: '<svg><use xlink:href="#vditor-icon-strike"></use></svg>',
229
+ name: "strike",
230
+ prefix: "~~",
231
+ suffix: "~~",
232
+ tipPosition: "ne",
233
+ },
234
+ {
235
+ hotkey: "โŒ˜K",
236
+ icon: '<svg><use xlink:href="#vditor-icon-link"></use></svg>',
237
+ name: "link",
238
+ prefix: "[",
239
+ suffix: "](https://)",
240
+ tipPosition: "n",
241
+ },
242
+ {
243
+ name: "|",
244
+ },
245
+ {
246
+ hotkey: "โŒ˜L",
247
+ icon: '<svg><use xlink:href="#vditor-icon-list"></use></svg>',
248
+ name: "list",
249
+ prefix: "* ",
250
+ tipPosition: "n",
251
+ },
252
+ {
253
+ hotkey: "โŒ˜O",
254
+ icon:
255
+ '<svg><use xlink:href="#vditor-icon-ordered-list"></use></svg>',
256
+ name: "ordered-list",
257
+ prefix: "1. ",
258
+ tipPosition: "n",
259
+ },
260
+ {
261
+ hotkey: "โŒ˜J",
262
+ icon: '<svg><use xlink:href="#vditor-icon-check"></use></svg>',
263
+ name: "check",
264
+ prefix: "* [ ] ",
265
+ tipPosition: "n",
266
+ },
267
+ {
268
+ hotkey: "โ‡งโŒ˜I",
269
+ icon:
270
+ '<svg><use xlink:href="#vditor-icon-outdent"></use></svg>',
271
+ name: "outdent",
272
+ tipPosition: "n",
273
+ },
274
+ {
275
+ hotkey: "โ‡งโŒ˜O",
276
+ icon: '<svg><use xlink:href="#vditor-icon-indent"></use></svg>',
277
+ name: "indent",
278
+ tipPosition: "n",
279
+ },
280
+ {
281
+ name: "|",
282
+ },
283
+ {
284
+ hotkey: "โŒ˜;",
285
+ icon: '<svg><use xlink:href="#vditor-icon-quote"></use></svg>',
286
+ name: "quote",
287
+ prefix: "> ",
288
+ tipPosition: "n",
289
+ },
290
+ {
291
+ hotkey: "โ‡งโŒ˜H",
292
+ icon: '<svg><use xlink:href="#vditor-icon-line"></use></svg>',
293
+ name: "line",
294
+ prefix: "---",
295
+ tipPosition: "n",
296
+ },
297
+ {
298
+ hotkey: "โŒ˜U",
299
+ icon: '<svg><use xlink:href="#vditor-icon-code"></use></svg>',
300
+ name: "code",
301
+ prefix: "```",
302
+ suffix: "\n```",
303
+ tipPosition: "n",
304
+ },
305
+ {
306
+ hotkey: "โŒ˜G",
307
+ icon:
308
+ '<svg><use xlink:href="#vditor-icon-inline-code"></use></svg>',
309
+ name: "inline-code",
310
+ prefix: "`",
311
+ suffix: "`",
312
+ tipPosition: "n",
313
+ },
314
+ {
315
+ hotkey: "โ‡งโŒ˜B",
316
+ icon: '<svg><use xlink:href="#vditor-icon-before"></use></svg>',
317
+ name: "insert-before",
318
+ tipPosition: "n",
319
+ },
320
+ {
321
+ hotkey: "โ‡งโŒ˜E",
322
+ icon: '<svg><use xlink:href="#vditor-icon-after"></use></svg>',
323
+ name: "insert-after",
324
+ tipPosition: "n",
325
+ },
326
+ {
327
+ name: "|",
328
+ },
329
+ {
330
+ icon: '<svg><use xlink:href="#vditor-icon-upload"></use></svg>',
331
+ name: "upload",
332
+ tipPosition: "n",
333
+ },
334
+ {
335
+ icon: '<svg><use xlink:href="#vditor-icon-record"></use></svg>',
336
+ name: "record",
337
+ tipPosition: "n",
338
+ },
339
+ {
340
+ hotkey: "โŒ˜M",
341
+ icon: '<svg><use xlink:href="#vditor-icon-table"></use></svg>',
342
+ name: "table",
343
+ prefix: "| col1",
344
+ suffix:
345
+ " | col2 | col3 |\n| --- | --- | --- |\n| | | |\n| | | |",
346
+ tipPosition: "n",
347
+ },
348
+ {
349
+ name: "|",
350
+ },
351
+ {
352
+ hotkey: "โŒ˜Z",
353
+ icon: '<svg><use xlink:href="#vditor-icon-undo"></use></svg>',
354
+ name: "undo",
355
+ tipPosition: "nw",
356
+ },
357
+ {
358
+ hotkey: "โŒ˜Y",
359
+ icon: '<svg><use xlink:href="#vditor-icon-redo"></use></svg>',
360
+ name: "redo",
361
+ tipPosition: "nw",
362
+ },
363
+ {
364
+ name: "|",
365
+ },
366
+ {
367
+ icon: '<svg><use xlink:href="#vditor-icon-more"></use></svg>',
368
+ name: "more",
369
+ tipPosition: "e",
370
+ },
371
+ {
372
+ hotkey: "โŒ˜'",
373
+ icon:
374
+ '<svg><use xlink:href="#vditor-icon-fullscreen"></use></svg>',
375
+ name: "fullscreen",
376
+ tipPosition: "nw",
377
+ },
378
+ {
379
+ icon: '<svg><use xlink:href="#vditor-icon-edit"></use></svg>',
380
+ name: "edit-mode",
381
+ tipPosition: "nw",
382
+ },
383
+ {
384
+ hotkey: "โŒ˜P",
385
+ icon: '<svg><use xlink:href="#vditor-icon-both"></use></svg>',
386
+ name: "both",
387
+ tipPosition: "nw",
388
+ },
389
+ {
390
+ icon:
391
+ '<svg><use xlink:href="#vditor-icon-preview"></use></svg>',
392
+ name: "preview",
393
+ tipPosition: "nw",
394
+ },
395
+ {
396
+ icon:
397
+ '<svg><use xlink:href="#vditor-icon-align-center"></use></svg>',
398
+ name: "outline",
399
+ tipPosition: "nw",
400
+ },
401
+ {
402
+ icon: '<svg><use xlink:href="#vditor-icon-theme"></use></svg>',
403
+ name: "content-theme",
404
+ tipPosition: "nw",
405
+ },
406
+ {
407
+ icon:
408
+ '<svg><use xlink:href="#vditor-icon-code-theme"></use></svg>',
409
+ name: "code-theme",
410
+ tipPosition: "nw",
411
+ },
412
+ {
413
+ icon: '<svg><use xlink:href="#vditor-icon-bug"></use></svg>',
414
+ name: "devtools",
415
+ tipPosition: "nw",
416
+ },
417
+ {
418
+ icon: '<svg><use xlink:href="#vditor-icon-info"></use></svg>',
419
+ name: "info",
420
+ tipPosition: "nw",
421
+ },
422
+ {
423
+ icon: '<svg><use xlink:href="#vditor-icon-help"></use></svg>',
424
+ name: "help",
425
+ tipPosition: "nw",
426
+ },
427
+ {
428
+ name: "br",
429
+ },
430
+ ];
431
+ const toolbarResult: IMenuItem[] = [];
432
+ toolbar.forEach((menuItem: IMenuItem) => {
433
+ let currentMenuItem = menuItem;
434
+ toolbarItem.forEach((defaultMenuItem: IMenuItem) => {
435
+ if (
436
+ typeof menuItem === "string" &&
437
+ defaultMenuItem.name === menuItem
438
+ ) {
439
+ currentMenuItem = defaultMenuItem;
440
+ }
441
+ if (
442
+ typeof menuItem === "object" &&
443
+ defaultMenuItem.name === menuItem.name
444
+ ) {
445
+ currentMenuItem = Object.assign({}, defaultMenuItem, menuItem);
446
+ }
447
+ });
448
+ if (menuItem.toolbar) {
449
+ currentMenuItem.toolbar = this.mergeToolbar(menuItem.toolbar);
450
+ }
451
+ toolbarResult.push(currentMenuItem);
452
+ });
453
+ return toolbarResult;
454
+ }
455
+ }