goodteditor-ui 1.0.17 → 1.0.19

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.
Files changed (46) hide show
  1. package/index.js +2 -0
  2. package/package.json +15 -2
  3. package/src/components/ui/WysiwygEditor/WysiwygEditor.d.ts +119 -0
  4. package/src/components/ui/WysiwygEditor/constants.js +255 -0
  5. package/src/components/ui/WysiwygEditor/extensions/blockquote.js +15 -0
  6. package/src/components/ui/WysiwygEditor/extensions/bold.js +15 -0
  7. package/src/components/ui/WysiwygEditor/extensions/bullet-list.js +15 -0
  8. package/src/components/ui/WysiwygEditor/extensions/code-block.js +13 -0
  9. package/src/components/ui/WysiwygEditor/extensions/code.js +13 -0
  10. package/src/components/ui/WysiwygEditor/extensions/font-size.js +34 -0
  11. package/src/components/ui/WysiwygEditor/extensions/formatting.js +14 -0
  12. package/src/components/ui/WysiwygEditor/extensions/heading.js +13 -0
  13. package/src/components/ui/WysiwygEditor/extensions/horizontal-rule.js +15 -0
  14. package/src/components/ui/WysiwygEditor/extensions/image.js +15 -0
  15. package/src/components/ui/WysiwygEditor/extensions/index.d.ts +32 -0
  16. package/src/components/ui/WysiwygEditor/extensions/index.js +32 -0
  17. package/src/components/ui/WysiwygEditor/extensions/italic.js +15 -0
  18. package/src/components/ui/WysiwygEditor/extensions/link.js +16 -0
  19. package/src/components/ui/WysiwygEditor/extensions/list-item.js +15 -0
  20. package/src/components/ui/WysiwygEditor/extensions/ordered-list.js +15 -0
  21. package/src/components/ui/WysiwygEditor/extensions/paragraph.js +23 -0
  22. package/src/components/ui/WysiwygEditor/extensions/strike.js +15 -0
  23. package/src/components/ui/WysiwygEditor/extensions/table-cell.js +13 -0
  24. package/src/components/ui/WysiwygEditor/extensions/table-header.js +15 -0
  25. package/src/components/ui/WysiwygEditor/extensions/table-row.js +15 -0
  26. package/src/components/ui/WysiwygEditor/extensions/table.js +29 -0
  27. package/src/components/ui/WysiwygEditor/extensions/text-align.js +5 -0
  28. package/src/components/ui/WysiwygEditor/extensions/text-style.js +15 -0
  29. package/src/components/ui/WysiwygEditor/extensions/underline.js +15 -0
  30. package/src/components/ui/WysiwygEditor/index.d.ts +4 -0
  31. package/src/components/ui/WysiwygEditor/index.js +4 -0
  32. package/src/components/ui/WysiwygEditor/renders/Button.vue +26 -0
  33. package/src/components/ui/WysiwygEditor/renders/ColorPicker.vue +42 -0
  34. package/src/components/ui/WysiwygEditor/renders/InputAuto.vue +33 -0
  35. package/src/components/ui/WysiwygEditor/renders/InputBrowse.vue +35 -0
  36. package/src/components/ui/WysiwygEditor/renders/InputUnits.vue +37 -0
  37. package/src/components/ui/WysiwygEditor/renders/Select.vue +45 -0
  38. package/src/components/ui/WysiwygEditor/renders/ToolbarPopover.vue +50 -0
  39. package/src/components/ui/WysiwygEditor/renders/index.d.ts +7 -0
  40. package/src/components/ui/WysiwygEditor/renders/index.js +7 -0
  41. package/src/components/ui/WysiwygEditor/renders/mixins/RenderMixin.js +39 -0
  42. package/src/components/ui/WysiwygEditor/renders/mixins/index.js +1 -0
  43. package/src/components/ui/WysiwygEditor/tools-and-commands.js +709 -0
  44. package/src/components/ui/WysiwygEditor/utils.js +72 -0
  45. package/src/components/ui/WysiwygEditor.md +18 -0
  46. package/src/components/ui/WysiwygEditor.vue +260 -0
@@ -0,0 +1,709 @@
1
+ import {
2
+ NodeType,
3
+ MarkType,
4
+ CommandType,
5
+ ToolType,
6
+ createButtonTool,
7
+ createColorPickerTool,
8
+ createCommand,
9
+ createInputUnitsTool,
10
+ createSelectTool,
11
+ createToolbarPopoverTool,
12
+ createInputAutoTool,
13
+ createInputBrowseTool
14
+ } from './constants';
15
+
16
+ export const CommandMap = {
17
+ [CommandType.PARAGRAPH]: createCommand({
18
+ name: CommandType.PARAGRAPH,
19
+ title: 'Абзац',
20
+ exec() {
21
+ this.editor
22
+ .chain()
23
+ .focus()
24
+ .setParagraph()
25
+ .setParagraphClass('p')
26
+ .resetAttributes(MarkType.TEXT_STYLE, 'fontSize')
27
+ .run();
28
+ },
29
+ isActive() {
30
+ return this.editor.isActive(NodeType.PARAGRAPH, { class: 'p' });
31
+ }
32
+ }),
33
+ [CommandType.HEADING_1]: createCommand({
34
+ name: CommandType.HEADING_1,
35
+ title: 'Заголовок 1',
36
+ exec() {
37
+ this.editor
38
+ .chain()
39
+ .focus()
40
+ .setHeading({ level: 1 })
41
+ .resetAttributes(MarkType.TEXT_STYLE, 'fontSize')
42
+ .run();
43
+ },
44
+ isActive() {
45
+ return this.editor.isActive(NodeType.HEADING, { level: 1 });
46
+ }
47
+ }),
48
+ [CommandType.HEADING_2]: createCommand({
49
+ name: CommandType.HEADING_2,
50
+ title: 'Заголовок 2',
51
+ exec() {
52
+ this.editor
53
+ .chain()
54
+ .focus()
55
+ .setHeading({ level: 2 })
56
+ .resetAttributes(MarkType.TEXT_STYLE, 'fontSize')
57
+ .run();
58
+ },
59
+ isActive() {
60
+ return this.editor.isActive(NodeType.HEADING, { level: 2 });
61
+ }
62
+ }),
63
+ [CommandType.HEADING_3]: createCommand({
64
+ name: CommandType.HEADING_3,
65
+ title: 'Заголовок 3',
66
+ exec() {
67
+ this.editor
68
+ .chain()
69
+ .focus()
70
+ .setHeading({ level: 3 })
71
+ .resetAttributes(MarkType.TEXT_STYLE, 'fontSize')
72
+ .run();
73
+ },
74
+ isActive() {
75
+ return this.editor.isActive(NodeType.HEADING, { level: 3 });
76
+ }
77
+ }),
78
+ [CommandType.HEADING_4]: createCommand({
79
+ name: CommandType.HEADING_4,
80
+ title: 'Заголовок 4',
81
+ exec() {
82
+ this.editor
83
+ .chain()
84
+ .focus()
85
+ .setHeading({ level: 4 })
86
+ .resetAttributes(MarkType.TEXT_STYLE, 'fontSize')
87
+ .run();
88
+ },
89
+ isActive() {
90
+ return this.editor.isActive(NodeType.HEADING, { level: 4 });
91
+ }
92
+ }),
93
+ [CommandType.TEXT_SMALL]: createCommand({
94
+ name: CommandType.TEXT_SMALL,
95
+ title: 'Small',
96
+ exec() {
97
+ this.editor
98
+ .chain()
99
+ .focus()
100
+ .setParagraph()
101
+ .setParagraphClass('text-small')
102
+ .resetAttributes(MarkType.TEXT_STYLE, 'fontSize')
103
+ .run();
104
+ },
105
+ isActive() {
106
+ return this.editor.isActive(NodeType.PARAGRAPH, { class: 'text-small' });
107
+ }
108
+ }),
109
+ [CommandType.TEXT_XSMALL]: createCommand({
110
+ name: CommandType.TEXT_XSMALL,
111
+ title: 'Xsmall',
112
+ exec() {
113
+ this.editor
114
+ .chain()
115
+ .focus()
116
+ .setParagraph()
117
+ .setParagraphClass('text-xsmall')
118
+ .resetAttributes(MarkType.TEXT_STYLE, 'fontSize')
119
+ .run();
120
+ },
121
+ isActive() {
122
+ return this.editor.isActive(NodeType.PARAGRAPH, { class: 'text-xsmall' });
123
+ }
124
+ }),
125
+ [CommandType.CODE_BLOCK]: createCommand({
126
+ name: CommandType.CODE_BLOCK,
127
+ title: 'Код',
128
+ exec() {
129
+ this.editor
130
+ .chain()
131
+ .focus()
132
+ .setCodeBlock()
133
+ .run();
134
+ },
135
+ isActive() {
136
+ return this.editor.isActive(NodeType.CODE_BLOCK);
137
+ }
138
+ }),
139
+ [CommandType.SINK_LIST_ITEM]: createCommand({
140
+ name: CommandType.SINK_LIST_ITEM,
141
+ title: 'Опустить элемент списка',
142
+ exec() {
143
+ this.editor
144
+ .chain()
145
+ .focus()
146
+ .sinkListItem(NodeType.LIST_ITEM)
147
+ .run();
148
+ },
149
+ isEnabled() {
150
+ return this.editor.can().sinkListItem(NodeType.LIST_ITEM);
151
+ }
152
+ }),
153
+ [CommandType.LIFT_LIST_ITEM]: createCommand({
154
+ name: CommandType.LIFT_LIST_ITEM,
155
+ title: 'Поднять элемент списка',
156
+ exec() {
157
+ this.editor.chain().focus().liftListItem(NodeType.LIST_ITEM).run();
158
+ },
159
+ isEnabled() {
160
+ return this.editor.can().liftListItem(NodeType.LIST_ITEM);
161
+ }
162
+ })
163
+ };
164
+
165
+ export const TableOptionsMap = {
166
+ [ToolType.INSERT_TABLE]: createButtonTool({
167
+ name: ToolType.INSERT_TABLE,
168
+ icon: 'table',
169
+ title: 'Вставить таблицу',
170
+ exec() {
171
+ this.editor
172
+ .chain()
173
+ .focus()
174
+ .insertTable({ rows: 3, cols: 3, withHeaderRow: true })
175
+ .run();
176
+ },
177
+ isEnabled() {
178
+ return this.editor.can().insertTable();
179
+ }
180
+ }),
181
+ [ToolType.DELETE_TABLE]: createButtonTool({
182
+ name: ToolType.DELETE_TABLE,
183
+ icon: 'table-remove',
184
+ title: 'Удалить таблицу',
185
+ exec() {
186
+ this.editor.chain().focus().deleteTable().run();
187
+ },
188
+ isEnabled() {
189
+ return this.editor.can().deleteTable();
190
+ }
191
+ }),
192
+ [ToolType.ADD_COLUMN_BEFORE]: createButtonTool({
193
+ name: ToolType.ADD_COLUMN_BEFORE,
194
+ icon: 'table-column-plus-before',
195
+ title: 'Добавить колонку перед',
196
+ exec() {
197
+ this.editor.chain().focus().addColumnBefore().run();
198
+ },
199
+ isEnabled() {
200
+ return this.editor.can().addColumnBefore();
201
+ }
202
+ }),
203
+ [ToolType.ADD_COLUMN_AFTER]: createButtonTool({
204
+ name: ToolType.ADD_COLUMN_AFTER,
205
+ icon: 'table-column-plus-after',
206
+ title: 'Добавить колонку после',
207
+ exec() {
208
+ this.editor.chain().focus().addColumnAfter().run();
209
+ },
210
+ isEnabled() {
211
+ return this.editor.can().addColumnAfter();
212
+ }
213
+ }),
214
+ [ToolType.DELETE_COLUMN]: createButtonTool({
215
+ name: ToolType.DELETE_COLUMN,
216
+ icon: 'table-column-remove',
217
+ title: 'Удалить колонку',
218
+ exec() {
219
+ this.editor.chain().focus().deleteColumn().run();
220
+ },
221
+ isEnabled() {
222
+ return this.editor.can().deleteColumn();
223
+ }
224
+ }),
225
+ [ToolType.ADD_ROW_BEFORE]: createButtonTool({
226
+ name: ToolType.ADD_ROW_BEFORE,
227
+ icon: 'table-row-plus-before',
228
+ title: 'Добавить строку перед',
229
+ exec() {
230
+ this.editor.chain().focus().addRowBefore().run();
231
+ },
232
+ isEnabled() {
233
+ return this.editor.can().addRowBefore();
234
+ }
235
+ }),
236
+ [ToolType.ADD_ROW_AFTER]: createButtonTool({
237
+ name: ToolType.ADD_ROW_AFTER,
238
+ icon: 'table-row-plus-after',
239
+ title: 'Добавить строку после',
240
+ exec() {
241
+ this.editor.chain().focus().addRowAfter().run();
242
+ },
243
+ isEnabled() {
244
+ return this.editor.can().addRowAfter();
245
+ }
246
+ }),
247
+ [ToolType.DELETE_ROW]: createButtonTool({
248
+ name: ToolType.DELETE_ROW,
249
+ icon: 'table-row-remove',
250
+ title: 'Удалить строку',
251
+ exec() {
252
+ this.editor.chain().focus().deleteRow().run();
253
+ },
254
+ isEnabled() {
255
+ return this.editor.can().deleteRow();
256
+ }
257
+ }),
258
+ [ToolType.MERGE_CELLS]: createButtonTool({
259
+ name: ToolType.MERGE_CELLS,
260
+ icon: 'table-merge-cells',
261
+ title: 'Объединить ячейки',
262
+ exec() {
263
+ this.editor.chain().focus().mergeCells().run();
264
+ },
265
+ isEnabled() {
266
+ return this.editor.can().mergeCells();
267
+ }
268
+ }),
269
+ [ToolType.SPLIT_CELL]: createButtonTool({
270
+ name: ToolType.SPLIT_CELL,
271
+ icon: 'table-split-cell',
272
+ title: 'Разделить ячейки',
273
+ exec() {
274
+ this.editor.chain().focus().splitCell().run();
275
+ },
276
+ isEnabled() {
277
+ return this.editor.can().splitCell();
278
+ }
279
+ }),
280
+ [ToolType.TOGGLE_HEADER_ROW]: createButtonTool({
281
+ name: ToolType.TOGGLE_HEADER_ROW,
282
+ icon: 'table-row-height',
283
+ title: 'Переключить строку заголовка',
284
+ exec() {
285
+ this.editor.chain().focus().toggleHeaderRow().run();
286
+ },
287
+ isEnabled() {
288
+ return this.editor.can().toggleHeaderRow();
289
+ }
290
+ }),
291
+ [ToolType.TOGGLE_HEADER_COLUMN]: createButtonTool({
292
+ name: ToolType.TOGGLE_HEADER_COLUMN,
293
+ icon: 'table-column-width',
294
+ title: 'Переключить колонку заголовка',
295
+ exec() {
296
+ this.editor.chain().focus().toggleHeaderColumn().run();
297
+ },
298
+ isEnabled() {
299
+ return this.editor.can().toggleHeaderColumn();
300
+ }
301
+ }),
302
+ [ToolType.ALIGN_V_TOP]: createButtonTool({
303
+ name: ToolType.ALIGN_V_TOP,
304
+ icon: 'align-vertical-top',
305
+ title: 'Выровнять по верхнему краю',
306
+ exec() {
307
+ const classNames = this.editor.getAttributes(NodeType.TABLE).class;
308
+ this.editor.chain().focus().toggleTableAlignment('table-vtop', classNames).run();
309
+ },
310
+ isEnabled() {
311
+ return this.editor.isActive(NodeType.TABLE);
312
+ },
313
+ isActive() {
314
+ const classNames = this.editor.getAttributes(NodeType.TABLE).class;
315
+ return classNames?.includes('table-vtop') ?? false;
316
+ }
317
+ }),
318
+ [ToolType.ALIGN_V_MID]: createButtonTool({
319
+ name: ToolType.ALIGN_V_MID,
320
+ icon: 'align-vertical-center',
321
+ title: 'Выровнять по центру',
322
+ exec() {
323
+ const classNames = this.editor.getAttributes(NodeType.TABLE).class;
324
+ this.editor.chain().focus().toggleTableAlignment('table-vmid', classNames).run();
325
+ },
326
+ isEnabled() {
327
+ return this.editor.isActive(NodeType.TABLE);
328
+ },
329
+ isActive() {
330
+ const classNames = this.editor.getAttributes(NodeType.TABLE).class;
331
+ return classNames?.includes('table-vmid') ?? false;
332
+ }
333
+ }),
334
+ [ToolType.ALIGN_V_BOT]: createButtonTool({
335
+ name: ToolType.ALIGN_V_BOT,
336
+ icon: 'align-vertical-bottom',
337
+ title: 'Выровнять по нижнему краю',
338
+ exec() {
339
+ const classNames = this.editor.getAttributes(NodeType.TABLE).class;
340
+ this.editor.chain().focus().toggleTableAlignment('table-vbot', classNames).run();
341
+ },
342
+ isEnabled() {
343
+ return this.editor.isActive(NodeType.TABLE);
344
+ },
345
+ isActive() {
346
+ const classNames = this.editor.getAttributes(NodeType.TABLE).class;
347
+ return classNames?.includes('table-vbot') ?? false;
348
+ }
349
+ }),
350
+ [ToolType.TOGGLE_BORDERS]: createButtonTool({
351
+ name: ToolType.TOGGLE_BORDERS,
352
+ icon: 'border-all',
353
+ title: 'Границы',
354
+ exec() {
355
+ const classNames = this.editor.getAttributes(NodeType.TABLE).class;
356
+ this.editor.chain().focus().toggleTableClass('table-borders', classNames).run();
357
+ },
358
+ isEnabled() {
359
+ return this.editor.isActive(NodeType.TABLE);
360
+ },
361
+ isActive() {
362
+ const classNames = this.editor.getAttributes(NodeType.TABLE).class;
363
+ return classNames?.includes('table-borders') ?? false;
364
+ }
365
+ }),
366
+ [ToolType.TOGGLE_ZEBRA]: createButtonTool({
367
+ name: ToolType.TOGGLE_ZEBRA,
368
+ icon: 'view-stream',
369
+ title: 'Стиль "зебра"',
370
+ exec() {
371
+ const classNames = this.editor.getAttributes(NodeType.TABLE).class;
372
+ this.editor.chain().focus().toggleTableClass('table-zebra', classNames).run();
373
+ },
374
+ isEnabled() {
375
+ return this.editor.isActive(NodeType.TABLE);
376
+ },
377
+ isActive() {
378
+ const classNames = this.editor.getAttributes(NodeType.TABLE).class;
379
+ return classNames?.includes('table-zebra') ?? false;
380
+ }
381
+ })
382
+ };
383
+
384
+ export const ImageOptionsMap = {
385
+ [ToolType.INSERT_IMAGE]: createInputBrowseTool({
386
+ name: ToolType.INSERT_IMAGE,
387
+ title: 'Вставить изображение',
388
+ async exec(fromInputUrl) {
389
+ const setImage = (url) => {
390
+ this.editor.chain().focus().setImage({ src: url }).run();
391
+ };
392
+
393
+ if (fromInputUrl != null) {
394
+ setImage(fromInputUrl);
395
+ return;
396
+ }
397
+
398
+ const imageUrl = await this.getImageUrl();
399
+
400
+ if (imageUrl != null) {
401
+ setImage(imageUrl);
402
+ }
403
+ },
404
+ getValue() {
405
+ return this.editor.getAttributes(NodeType.IMAGE).src;
406
+ }
407
+ })
408
+ };
409
+
410
+ export const LinkOptionsMap = {
411
+ [ToolType.INSERT_LINK]: createInputAutoTool({
412
+ name: ToolType.INSERT_LINK,
413
+ title: 'Вставить ссылку',
414
+ exec(url) {
415
+ const { editor } = this;
416
+
417
+ if (url === '') {
418
+ editor
419
+ .chain()
420
+ .focus()
421
+ .extendMarkRange(MarkType.LINK)
422
+ .unsetLink()
423
+ .run();
424
+
425
+ return;
426
+ }
427
+
428
+ editor
429
+ .chain()
430
+ .focus()
431
+ .extendMarkRange(MarkType.LINK)
432
+ .setLink({ href: url })
433
+ .run();
434
+ },
435
+ getValue() {
436
+ return this.editor.getAttributes(MarkType.LINK).href;
437
+ },
438
+ isEnabled() {
439
+ return this.editor.can().setLink();
440
+ },
441
+ })
442
+ }
443
+
444
+ export const ToolsMap = {
445
+ [ToolType.UNDO]: createButtonTool({
446
+ name: ToolType.UNDO,
447
+ icon: 'undo-variant',
448
+ title: 'Назад',
449
+ exec() {
450
+ this.editor.commands.undo();
451
+ },
452
+ isEnabled() {
453
+ return this.editor.can().undo();
454
+ }
455
+ }),
456
+ [ToolType.REDO]: createButtonTool({
457
+ name: ToolType.REDO,
458
+ icon: 'redo-variant',
459
+ title: 'Вперед',
460
+ exec() {
461
+ this.editor.commands.redo();
462
+ },
463
+ isEnabled() {
464
+ return this.editor.can().redo();
465
+ }
466
+ }),
467
+ [ToolType.SAVE]: createButtonTool({
468
+ name: ToolType.SAVE,
469
+ icon: 'content-save',
470
+ title: 'Сохранить',
471
+ exec() {
472
+ this.onChange();
473
+ }
474
+ }),
475
+ [ToolType.PARAGRAPH_STYLE]: createSelectTool({
476
+ name: ToolType.PARAGRAPH_STYLE,
477
+ title: 'Стиль параграфа',
478
+ exec(command) {
479
+ if (command.name in CommandMap && command.isEnabled()) {
480
+ command.exec();
481
+ }
482
+ },
483
+ getValue(options) {
484
+ return options.find(({ value }) => value.isActive()) ?? null;
485
+ },
486
+ options: [
487
+ CommandMap[CommandType.PARAGRAPH],
488
+ CommandMap[CommandType.HEADING_1],
489
+ CommandMap[CommandType.HEADING_2],
490
+ CommandMap[CommandType.HEADING_3],
491
+ CommandMap[CommandType.HEADING_4],
492
+ CommandMap[CommandType.TEXT_SMALL],
493
+ CommandMap[CommandType.TEXT_XSMALL],
494
+ CommandMap[CommandType.CODE_BLOCK]
495
+ ]
496
+ }),
497
+ [ToolType.FONT_SIZE]: createInputUnitsTool({
498
+ name: ToolType.FONT_SIZE,
499
+ title: 'Размер шрифта',
500
+ exec(value) {
501
+ this.editor.commands.setFontSize(value);
502
+ },
503
+ isEnabled() {
504
+ const { editor } = this;
505
+
506
+ return (
507
+ editor.isActive(NodeType.HEADING) ||
508
+ editor.isActive(NodeType.PARAGRAPH, { class: 'text-small' }) ||
509
+ editor.isActive(NodeType.PARAGRAPH, { class: 'text-xsmall' })
510
+ ) === false;
511
+ },
512
+ getValue() {
513
+ return this.editor.getAttributes(MarkType.TEXT_STYLE).fontSize;
514
+ },
515
+ units: ["rem", "em", "%", "px", "vh", "vw"]
516
+ }),
517
+ [ToolType.TEXT_COLOR]: createColorPickerTool({
518
+ name: ToolType.TEXT_COLOR,
519
+ icon: 'format-color-fill',
520
+ title: 'Цвет',
521
+ exec(value) {
522
+ this.editor.chain().focus().setColor(value).run();
523
+ },
524
+ getValue() {
525
+ return this.editor.getAttributes(MarkType.TEXT_STYLE).color;
526
+ }
527
+ }),
528
+ [ToolType.FONT_FAMILY]: createInputAutoTool({
529
+ name: ToolType.FONT_FAMILY,
530
+ title: 'Семейство шрифта',
531
+ exec(value) {
532
+ this.editor.commands.setFontFamily(value);
533
+ },
534
+ getValue() {
535
+ return this.editor.getAttributes(MarkType.TEXT_STYLE).fontFamily;
536
+ },
537
+ options: ['serif', 'sans-serif']
538
+ }),
539
+ [ToolType.BLOCKQUOTE]: createButtonTool({
540
+ name: ToolType.BLOCKQUOTE,
541
+ icon: 'format-quote-close-outline',
542
+ title: 'Цитата',
543
+ exec() {
544
+ this.editor
545
+ .chain()
546
+ .focus()
547
+ .toggleBlockquote()
548
+ .run();
549
+ },
550
+ isActive() {
551
+ return this.editor.isActive(NodeType.BLOCKQUOTE);
552
+ }
553
+ }),
554
+ [ToolType.HARD_BREAK]: createButtonTool({
555
+ name: ToolType.HARD_BREAK,
556
+ title: 'Перевод строки',
557
+ icon: 'keyboard-return',
558
+ exec() {
559
+ this.editor.chain().focus().setHardBreak().run();
560
+ }
561
+ }),
562
+ [ToolType.CODE]: createButtonTool({
563
+ name: ToolType.CODE,
564
+ icon: 'code-not-equal-variant',
565
+ title: 'Код',
566
+ exec() {
567
+ this.editor.chain().focus().toggleCode().run();
568
+ },
569
+ isActive() {
570
+ return this.editor.isActive(MarkType.CODE);
571
+ }
572
+ }),
573
+ [ToolType.IMAGE]: createToolbarPopoverTool({
574
+ name: ToolType.IMAGE,
575
+ icon: 'image-plus',
576
+ title: 'Изображение',
577
+ options: Object.values(ImageOptionsMap)
578
+ }),
579
+ [ToolType.ORDERED_LIST]: createButtonTool({
580
+ name: ToolType.ORDERED_LIST,
581
+ icon: 'format-list-numbered',
582
+ title: 'Нумерованный список',
583
+ exec() {
584
+ this.editor.chain().focus().toggleOrderedList().run();
585
+ },
586
+ isActive() {
587
+ return this.editor.isActive(NodeType.ORDERED_LIST);
588
+ }
589
+ }),
590
+ [ToolType.BULLET_LIST]: createButtonTool({
591
+ name: ToolType.BULLET_LIST,
592
+ icon: 'format-list-bulleted',
593
+ title: 'Маркированный список',
594
+ exec() {
595
+ this.editor.chain().focus().toggleBulletList().run();
596
+ },
597
+ isActive() {
598
+ return this.editor.isActive(NodeType.BULLET_LIST);
599
+ }
600
+ }),
601
+ [ToolType.TEXT_ALIGN_LEFT]: createButtonTool({
602
+ name: ToolType.TEXT_ALIGN_LEFT,
603
+ icon: 'format-align-left',
604
+ title: 'По левому краю',
605
+ exec() {
606
+ this.editor.chain().focus().setTextAlign('left').run();
607
+ },
608
+ isActive() {
609
+ return this.editor.isActive({ textAlign: 'left' });
610
+ }
611
+ }),
612
+ [ToolType.TEXT_ALIGN_CENTER]: createButtonTool({
613
+ name: ToolType.TEXT_ALIGN_CENTER,
614
+ icon: 'format-align-center',
615
+ title: 'По центру',
616
+ exec() {
617
+ this.editor.chain().focus().setTextAlign('center').run();
618
+ },
619
+ isActive() {
620
+ return this.editor.isActive({ textAlign: 'center' });
621
+ }
622
+ }),
623
+ [ToolType.TEXT_ALIGN_RIGHT]: createButtonTool({
624
+ name: ToolType.TEXT_ALIGN_RIGHT,
625
+ icon: 'format-align-right',
626
+ title: 'По правому краю',
627
+ exec() {
628
+ this.editor.chain().focus().setTextAlign('right').run();
629
+ },
630
+ isActive() {
631
+ return this.editor.isActive({ textAlign: 'right' });
632
+ }
633
+ }),
634
+ [ToolType.HORIZONTAL_RULE]: createButtonTool({
635
+ name: ToolType.HORIZONTAL_RULE,
636
+ icon: 'minus',
637
+ title: 'Вертикальный разделитель',
638
+ exec() {
639
+ this.editor.chain().focus().setHorizontalRule().run();
640
+ },
641
+ isEnabled() {
642
+ return this.editor.can().setHorizontalRule();
643
+ }
644
+ }),
645
+ [ToolType.LINK]: createToolbarPopoverTool({
646
+ name: ToolType.LINK,
647
+ icon: 'link-plus',
648
+ title: 'Ссылка',
649
+ options: Object.values(LinkOptionsMap)
650
+ }),
651
+ [ToolType.BOLD]: createButtonTool({
652
+ name: ToolType.BOLD,
653
+ icon: 'format-bold',
654
+ title: 'Жирный',
655
+ exec() {
656
+ this.editor.chain().focus().toggleBold().run();
657
+ },
658
+ isActive() {
659
+ return this.editor.isActive(MarkType.BOLD);
660
+ }
661
+ }),
662
+ [ToolType.ITALIC]: createButtonTool({
663
+ name: ToolType.ITALIC,
664
+ icon: 'format-italic',
665
+ title: 'Курсив',
666
+ exec() {
667
+ this.editor.chain().focus().toggleItalic().run();
668
+ },
669
+ isActive() {
670
+ return this.editor.isActive(MarkType.ITALIC);
671
+ }
672
+ }),
673
+ [ToolType.STRIKE]: createButtonTool({
674
+ name: ToolType.STRIKE,
675
+ icon: 'format-strikethrough-variant',
676
+ title: 'Зачеркивание',
677
+ exec() {
678
+ this.editor.chain().focus().toggleStrike().run();
679
+ },
680
+ isActive() {
681
+ return this.editor.isActive(MarkType.STRIKE);
682
+ }
683
+ }),
684
+ [ToolType.UNDERLINE]: createButtonTool({
685
+ name: ToolType.UNDERLINE,
686
+ icon: 'format-underline',
687
+ title: 'Подчеркивание',
688
+ exec() {
689
+ this.editor.chain().focus().toggleUnderline().run();
690
+ },
691
+ isActive() {
692
+ return this.editor.isActive(MarkType.UNDERLINE);
693
+ }
694
+ }),
695
+ [ToolType.TABLE]: createToolbarPopoverTool({
696
+ name: ToolType.TABLE,
697
+ icon: 'table-plus',
698
+ title: 'таблица',
699
+ options: Object.values(TableOptionsMap)
700
+ }),
701
+ [ToolType.CLEAR_FORMATTING]: createButtonTool({
702
+ name: ToolType.CLEAR_FORMATTING,
703
+ icon: 'eraser',
704
+ title: 'Очистить форматирование',
705
+ exec() {
706
+ this.editor.chain().focus().clearFormatting().run();
707
+ }
708
+ })
709
+ };