@zipify/wysiwyg 2.0.0-0 → 2.0.0-10
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 +1 -1
- package/config/build/cli.config.js +8 -2
- package/config/build/lib.config.js +4 -2
- package/dist/cli.js +10 -2
- package/dist/wysiwyg.css +53 -37
- package/dist/wysiwyg.mjs +2131 -405
- package/example/ExampleApp.vue +13 -2
- package/lib/Wysiwyg.vue +3 -2
- package/lib/__tests__/utils/buildTestExtensions.js +2 -1
- package/lib/assets/icons/indicator.svg +4 -0
- package/lib/cli/commands/Command.js +39 -0
- package/lib/cli/commands/ToJsonCommand.js +46 -0
- package/lib/cli/commands/VersionCommand.js +11 -0
- package/lib/cli/commands/index.js +2 -0
- package/lib/cli/index.js +1 -0
- package/lib/components/base/Button.vue +6 -0
- package/lib/components/base/dropdown/Dropdown.vue +7 -1
- package/lib/components/base/dropdown/DropdownActivator.vue +25 -4
- package/lib/components/base/dropdown/__tests__/DropdownActivator.test.js +23 -1
- package/lib/components/toolbar/controls/AlignmentControl.vue +12 -1
- package/lib/components/toolbar/controls/FontColorControl.vue +14 -0
- package/lib/components/toolbar/controls/FontFamilyControl.vue +4 -0
- package/lib/components/toolbar/controls/FontSizeControl.vue +6 -1
- package/lib/components/toolbar/controls/FontWeightControl.vue +12 -0
- package/lib/components/toolbar/controls/ItalicControl.vue +14 -0
- package/lib/components/toolbar/controls/LineHeightControl.vue +15 -0
- package/lib/components/toolbar/controls/StylePresetControl.vue +1 -1
- package/lib/components/toolbar/controls/UnderlineControl.vue +13 -0
- package/lib/components/toolbar/controls/__tests__/AlignmentControl.test.js +72 -5
- package/lib/components/toolbar/controls/__tests__/FontColorControl.test.js +22 -1
- package/lib/components/toolbar/controls/__tests__/FontFamilyControl.test.js +1 -0
- package/lib/components/toolbar/controls/__tests__/FontSizeControl.test.js +1 -0
- package/lib/components/toolbar/controls/__tests__/FontWeightControl.test.js +1 -0
- package/lib/components/toolbar/controls/__tests__/ItalicControl.test.js +23 -1
- package/lib/components/toolbar/controls/__tests__/LineHeightControl.test.js +23 -1
- package/lib/components/toolbar/controls/__tests__/StylePresetControl.test.js +6 -6
- package/lib/components/toolbar/controls/__tests__/UnderlineControl.test.js +25 -1
- package/lib/composables/__tests__/useEditor.test.js +1 -1
- package/lib/composables/useEditor.js +9 -8
- package/lib/directives/__tests__/tooltip.test.js +22 -4
- package/lib/directives/tooltip.js +4 -1
- package/lib/entry-cli.js +7 -20
- package/lib/entry-lib.js +1 -1
- package/lib/enums/MarkGroups.js +4 -0
- package/lib/enums/TextSettings.js +5 -5
- package/lib/enums/index.js +1 -0
- package/lib/extensions/BackgroundColor.js +0 -1
- package/lib/extensions/FontColor.js +2 -2
- package/lib/extensions/FontFamily.js +3 -3
- package/lib/extensions/FontSize.js +2 -2
- package/lib/extensions/FontStyle.js +2 -2
- package/lib/extensions/FontWeight.js +2 -2
- package/lib/extensions/Link.js +1 -1
- package/lib/extensions/StylePreset.js +9 -3
- package/lib/extensions/Superscript.js +5 -2
- package/lib/extensions/TextDecoration.js +19 -29
- package/lib/extensions/__tests__/Alignment.test.js +2 -2
- package/lib/extensions/__tests__/BackgroundColor.test.js +4 -3
- package/lib/extensions/__tests__/FontColor.test.js +4 -3
- package/lib/extensions/__tests__/FontFamily.test.js +6 -6
- package/lib/extensions/__tests__/FontSize.test.js +9 -8
- package/lib/extensions/__tests__/FontStyle.test.js +6 -5
- package/lib/extensions/__tests__/FontWeight.test.js +2 -2
- package/lib/extensions/__tests__/LineHeight.test.js +2 -1
- package/lib/extensions/__tests__/StylePreset.test.js +51 -0
- package/lib/extensions/__tests__/Superscript.test.js +102 -0
- package/lib/extensions/__tests__/TextDecoration.test.js +40 -24
- package/lib/extensions/__tests__/__snapshots__/BackgroundColor.test.js.snap +24 -24
- package/lib/extensions/__tests__/__snapshots__/FontColor.test.js.snap +1 -1
- package/lib/extensions/__tests__/__snapshots__/FontFamily.test.js.snap +19 -23
- package/lib/extensions/__tests__/__snapshots__/FontSize.test.js.snap +2 -2
- package/lib/extensions/__tests__/__snapshots__/FontStyle.test.js.snap +1 -1
- package/lib/extensions/__tests__/__snapshots__/FontWeight.test.js.snap +13 -17
- package/lib/extensions/__tests__/__snapshots__/Superscript.test.js.snap +107 -0
- package/lib/extensions/__tests__/__snapshots__/TextDecoration.test.js.snap +102 -102
- package/lib/extensions/core/Document.js +2 -1
- package/lib/extensions/core/Heading.js +2 -1
- package/lib/extensions/core/NodeProcessor.js +63 -20
- package/lib/extensions/core/Paragraph.js +2 -1
- package/lib/extensions/core/TextProcessor.js +0 -5
- package/lib/extensions/core/__tests__/NodeProcessor.test.js +364 -11
- package/lib/extensions/core/__tests__/TextProcessor.test.js +1 -22
- package/lib/extensions/core/__tests__/__snapshots__/NodeProcessor.test.js.snap +309 -0
- package/lib/extensions/core/__tests__/__snapshots__/TextProcessor.test.js.snap +7 -27
- package/lib/extensions/core/steps/AddNodeMarkStep.js +6 -0
- package/lib/extensions/core/steps/AttrStep.js +60 -0
- package/lib/extensions/core/steps/RemoveNodeMarkStep.js +6 -0
- package/lib/extensions/core/steps/index.js +1 -0
- package/lib/extensions/list/List.js +70 -9
- package/lib/extensions/list/ListItem.js +2 -2
- package/lib/extensions/list/__tests__/List.test.js +26 -17
- package/lib/extensions/list/__tests__/__snapshots__/List.test.js.snap +36 -36
- package/lib/services/NodeFactory.js +73 -13
- package/lib/services/__tests__/NodeFactory.test.js +124 -0
- package/lib/services/__tests__/__snapshots__/NodeFactory.test.js.snap +326 -0
- package/lib/services/index.js +1 -1
- package/lib/services/normalizer/BaseNormalizer.js +11 -0
- package/lib/services/{BrowserDomParser.js → normalizer/BrowserDomParser.js} +0 -0
- package/lib/services/normalizer/ContentNormalizer.js +24 -0
- package/lib/services/normalizer/HtmlNormalizer.js +297 -0
- package/lib/services/normalizer/JsonNormalizer.js +82 -0
- package/lib/services/{__tests__/ContentNormalizer.test.js → normalizer/__tests__/HtmlNormalizer.test.js} +42 -4
- package/lib/services/normalizer/__tests__/JsonNormalizer.test.js +87 -0
- package/lib/services/normalizer/__tests__/__snapshots__/JsonNormalizer.test.js.snap +196 -0
- package/lib/services/normalizer/index.js +1 -0
- package/lib/styles/content.css +8 -0
- package/lib/utils/__tests__/findMarkByType.test.js +17 -0
- package/lib/utils/__tests__/isMarkAppliedToParent.test.js +53 -0
- package/lib/utils/__tests__/isNodeFullySelected.test.js +44 -0
- package/lib/utils/__tests__/resolveTextPosition.test.js +39 -0
- package/lib/utils/copyMark.js +5 -0
- package/lib/utils/index.js +1 -1
- package/lib/utils/isMarkAppliedToParent.js +2 -7
- package/lib/utils/isNodeFullySelected.js +4 -7
- package/lib/utils/resolveTextPosition.js +4 -6
- package/package.json +31 -27
- package/lib/services/ContentNormalizer.js +0 -194
- package/lib/utils/resolveNodePosition.js +0 -6
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
|
+
exports[`apply mark should apply inline mark 1`] = `
|
|
4
|
+
Object {
|
|
5
|
+
"content": Array [
|
|
6
|
+
Object {
|
|
7
|
+
"attrs": Object {
|
|
8
|
+
"line_height": null,
|
|
9
|
+
},
|
|
10
|
+
"content": Array [
|
|
11
|
+
Object {
|
|
12
|
+
"marks": Array [
|
|
13
|
+
Object {
|
|
14
|
+
"attrs": Object {
|
|
15
|
+
"strike_through": false,
|
|
16
|
+
"underline": true,
|
|
17
|
+
},
|
|
18
|
+
"type": "text_decoration",
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
"text": "lorem ipsum",
|
|
22
|
+
"type": "text",
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
"type": "paragraph",
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
"type": "doc",
|
|
29
|
+
}
|
|
30
|
+
`;
|
|
31
|
+
|
|
3
32
|
exports[`apply mark should apply mark to block 1`] = `
|
|
4
33
|
Object {
|
|
5
34
|
"content": Array [
|
|
@@ -28,6 +57,126 @@ Object {
|
|
|
28
57
|
}
|
|
29
58
|
`;
|
|
30
59
|
|
|
60
|
+
exports[`apply mark should apply mark to list item 1`] = `
|
|
61
|
+
Object {
|
|
62
|
+
"content": Array [
|
|
63
|
+
Object {
|
|
64
|
+
"attrs": Object {
|
|
65
|
+
"bullet": Object {
|
|
66
|
+
"type": "disc",
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
"content": Array [
|
|
70
|
+
Object {
|
|
71
|
+
"content": Array [
|
|
72
|
+
Object {
|
|
73
|
+
"attrs": Object {
|
|
74
|
+
"line_height": null,
|
|
75
|
+
},
|
|
76
|
+
"content": Array [
|
|
77
|
+
Object {
|
|
78
|
+
"text": "lorem ipsum 1",
|
|
79
|
+
"type": "text",
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
"type": "paragraph",
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
"marks": Array [
|
|
86
|
+
Object {
|
|
87
|
+
"attrs": Object {
|
|
88
|
+
"value": "700",
|
|
89
|
+
},
|
|
90
|
+
"type": "font_weight",
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
"type": "listItem",
|
|
94
|
+
},
|
|
95
|
+
Object {
|
|
96
|
+
"content": Array [
|
|
97
|
+
Object {
|
|
98
|
+
"attrs": Object {
|
|
99
|
+
"line_height": null,
|
|
100
|
+
},
|
|
101
|
+
"content": Array [
|
|
102
|
+
Object {
|
|
103
|
+
"text": "lorem ipsum 2",
|
|
104
|
+
"type": "text",
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
"type": "paragraph",
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
"type": "listItem",
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
"type": "list",
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
"type": "doc",
|
|
117
|
+
}
|
|
118
|
+
`;
|
|
119
|
+
|
|
120
|
+
exports[`apply mark should apply mark to paragraph 1`] = `
|
|
121
|
+
Object {
|
|
122
|
+
"content": Array [
|
|
123
|
+
Object {
|
|
124
|
+
"attrs": Object {
|
|
125
|
+
"line_height": null,
|
|
126
|
+
},
|
|
127
|
+
"content": Array [
|
|
128
|
+
Object {
|
|
129
|
+
"text": "lorem ipsum",
|
|
130
|
+
"type": "text",
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
"marks": Array [
|
|
134
|
+
Object {
|
|
135
|
+
"attrs": Object {
|
|
136
|
+
"value": "700",
|
|
137
|
+
},
|
|
138
|
+
"type": "font_weight",
|
|
139
|
+
},
|
|
140
|
+
],
|
|
141
|
+
"type": "paragraph",
|
|
142
|
+
},
|
|
143
|
+
],
|
|
144
|
+
"type": "doc",
|
|
145
|
+
}
|
|
146
|
+
`;
|
|
147
|
+
|
|
148
|
+
exports[`apply mark should apply mark to part of text 1`] = `
|
|
149
|
+
Object {
|
|
150
|
+
"content": Array [
|
|
151
|
+
Object {
|
|
152
|
+
"attrs": Object {
|
|
153
|
+
"line_height": null,
|
|
154
|
+
},
|
|
155
|
+
"content": Array [
|
|
156
|
+
Object {
|
|
157
|
+
"marks": Array [
|
|
158
|
+
Object {
|
|
159
|
+
"attrs": Object {
|
|
160
|
+
"value": "700",
|
|
161
|
+
},
|
|
162
|
+
"type": "font_weight",
|
|
163
|
+
},
|
|
164
|
+
],
|
|
165
|
+
"text": "lorem",
|
|
166
|
+
"type": "text",
|
|
167
|
+
},
|
|
168
|
+
Object {
|
|
169
|
+
"text": " ipsum",
|
|
170
|
+
"type": "text",
|
|
171
|
+
},
|
|
172
|
+
],
|
|
173
|
+
"type": "paragraph",
|
|
174
|
+
},
|
|
175
|
+
],
|
|
176
|
+
"type": "doc",
|
|
177
|
+
}
|
|
178
|
+
`;
|
|
179
|
+
|
|
31
180
|
exports[`apply mark should apply mark to word 1`] = `
|
|
32
181
|
Object {
|
|
33
182
|
"content": Array [
|
|
@@ -132,6 +281,106 @@ Object {
|
|
|
132
281
|
}
|
|
133
282
|
`;
|
|
134
283
|
|
|
284
|
+
exports[`apply mark should remove paragraph mark on applying to list item 1`] = `
|
|
285
|
+
Object {
|
|
286
|
+
"content": Array [
|
|
287
|
+
Object {
|
|
288
|
+
"attrs": Object {
|
|
289
|
+
"bullet": Object {
|
|
290
|
+
"type": "disc",
|
|
291
|
+
},
|
|
292
|
+
},
|
|
293
|
+
"content": Array [
|
|
294
|
+
Object {
|
|
295
|
+
"content": Array [
|
|
296
|
+
Object {
|
|
297
|
+
"attrs": Object {
|
|
298
|
+
"line_height": null,
|
|
299
|
+
},
|
|
300
|
+
"content": Array [
|
|
301
|
+
Object {
|
|
302
|
+
"text": "lorem ipsum 1",
|
|
303
|
+
"type": "text",
|
|
304
|
+
},
|
|
305
|
+
],
|
|
306
|
+
"type": "paragraph",
|
|
307
|
+
},
|
|
308
|
+
Object {
|
|
309
|
+
"attrs": Object {
|
|
310
|
+
"line_height": null,
|
|
311
|
+
},
|
|
312
|
+
"content": Array [
|
|
313
|
+
Object {
|
|
314
|
+
"text": "lorem ipsum 2",
|
|
315
|
+
"type": "text",
|
|
316
|
+
},
|
|
317
|
+
],
|
|
318
|
+
"type": "paragraph",
|
|
319
|
+
},
|
|
320
|
+
],
|
|
321
|
+
"marks": Array [
|
|
322
|
+
Object {
|
|
323
|
+
"attrs": Object {
|
|
324
|
+
"value": "700",
|
|
325
|
+
},
|
|
326
|
+
"type": "font_weight",
|
|
327
|
+
},
|
|
328
|
+
],
|
|
329
|
+
"type": "listItem",
|
|
330
|
+
},
|
|
331
|
+
Object {
|
|
332
|
+
"content": Array [
|
|
333
|
+
Object {
|
|
334
|
+
"attrs": Object {
|
|
335
|
+
"line_height": null,
|
|
336
|
+
},
|
|
337
|
+
"content": Array [
|
|
338
|
+
Object {
|
|
339
|
+
"text": "lorem ipsum 3",
|
|
340
|
+
"type": "text",
|
|
341
|
+
},
|
|
342
|
+
],
|
|
343
|
+
"type": "paragraph",
|
|
344
|
+
},
|
|
345
|
+
],
|
|
346
|
+
"type": "listItem",
|
|
347
|
+
},
|
|
348
|
+
],
|
|
349
|
+
"type": "list",
|
|
350
|
+
},
|
|
351
|
+
],
|
|
352
|
+
"type": "doc",
|
|
353
|
+
}
|
|
354
|
+
`;
|
|
355
|
+
|
|
356
|
+
exports[`apply mark should remove text mark on applying to paragraph 1`] = `
|
|
357
|
+
Object {
|
|
358
|
+
"content": Array [
|
|
359
|
+
Object {
|
|
360
|
+
"attrs": Object {
|
|
361
|
+
"line_height": null,
|
|
362
|
+
},
|
|
363
|
+
"content": Array [
|
|
364
|
+
Object {
|
|
365
|
+
"text": "lorem ipsum",
|
|
366
|
+
"type": "text",
|
|
367
|
+
},
|
|
368
|
+
],
|
|
369
|
+
"marks": Array [
|
|
370
|
+
Object {
|
|
371
|
+
"attrs": Object {
|
|
372
|
+
"value": "700",
|
|
373
|
+
},
|
|
374
|
+
"type": "font_weight",
|
|
375
|
+
},
|
|
376
|
+
],
|
|
377
|
+
"type": "paragraph",
|
|
378
|
+
},
|
|
379
|
+
],
|
|
380
|
+
"type": "doc",
|
|
381
|
+
}
|
|
382
|
+
`;
|
|
383
|
+
|
|
135
384
|
exports[`block attributes should set attributes 1`] = `
|
|
136
385
|
Object {
|
|
137
386
|
"content": Array [
|
|
@@ -223,3 +472,63 @@ Object {
|
|
|
223
472
|
"type": "doc",
|
|
224
473
|
}
|
|
225
474
|
`;
|
|
475
|
+
|
|
476
|
+
exports[`remove marks should remove block and text marks 1`] = `
|
|
477
|
+
Object {
|
|
478
|
+
"content": Array [
|
|
479
|
+
Object {
|
|
480
|
+
"attrs": Object {
|
|
481
|
+
"line_height": null,
|
|
482
|
+
},
|
|
483
|
+
"content": Array [
|
|
484
|
+
Object {
|
|
485
|
+
"text": "lorem ipsum",
|
|
486
|
+
"type": "text",
|
|
487
|
+
},
|
|
488
|
+
],
|
|
489
|
+
"type": "paragraph",
|
|
490
|
+
},
|
|
491
|
+
],
|
|
492
|
+
"type": "doc",
|
|
493
|
+
}
|
|
494
|
+
`;
|
|
495
|
+
|
|
496
|
+
exports[`remove marks should remove block marks 1`] = `
|
|
497
|
+
Object {
|
|
498
|
+
"content": Array [
|
|
499
|
+
Object {
|
|
500
|
+
"attrs": Object {
|
|
501
|
+
"line_height": null,
|
|
502
|
+
},
|
|
503
|
+
"content": Array [
|
|
504
|
+
Object {
|
|
505
|
+
"text": "lorem ipsum",
|
|
506
|
+
"type": "text",
|
|
507
|
+
},
|
|
508
|
+
],
|
|
509
|
+
"type": "paragraph",
|
|
510
|
+
},
|
|
511
|
+
],
|
|
512
|
+
"type": "doc",
|
|
513
|
+
}
|
|
514
|
+
`;
|
|
515
|
+
|
|
516
|
+
exports[`remove marks should remove text marks 1`] = `
|
|
517
|
+
Object {
|
|
518
|
+
"content": Array [
|
|
519
|
+
Object {
|
|
520
|
+
"attrs": Object {
|
|
521
|
+
"line_height": null,
|
|
522
|
+
},
|
|
523
|
+
"content": Array [
|
|
524
|
+
Object {
|
|
525
|
+
"text": "lorem ipsum",
|
|
526
|
+
"type": "text",
|
|
527
|
+
},
|
|
528
|
+
],
|
|
529
|
+
"type": "paragraph",
|
|
530
|
+
},
|
|
531
|
+
],
|
|
532
|
+
"type": "doc",
|
|
533
|
+
}
|
|
534
|
+
`;
|
|
@@ -9,36 +9,16 @@ Object {
|
|
|
9
9
|
},
|
|
10
10
|
"content": Array [
|
|
11
11
|
Object {
|
|
12
|
-
"marks": Array [
|
|
13
|
-
Object {
|
|
14
|
-
"attrs": Object {
|
|
15
|
-
"value": "700",
|
|
16
|
-
},
|
|
17
|
-
"type": "font_weight",
|
|
18
|
-
},
|
|
19
|
-
],
|
|
20
12
|
"text": "hELLO world",
|
|
21
13
|
"type": "text",
|
|
22
14
|
},
|
|
23
15
|
],
|
|
24
|
-
"
|
|
25
|
-
},
|
|
26
|
-
],
|
|
27
|
-
"type": "doc",
|
|
28
|
-
}
|
|
29
|
-
`;
|
|
30
|
-
|
|
31
|
-
exports[`transform text should transform selected text 1`] = `
|
|
32
|
-
Object {
|
|
33
|
-
"content": Array [
|
|
34
|
-
Object {
|
|
35
|
-
"attrs": Object {
|
|
36
|
-
"alignment": null,
|
|
37
|
-
},
|
|
38
|
-
"content": Array [
|
|
16
|
+
"marks": Array [
|
|
39
17
|
Object {
|
|
40
|
-
"
|
|
41
|
-
|
|
18
|
+
"attrs": Object {
|
|
19
|
+
"value": "700",
|
|
20
|
+
},
|
|
21
|
+
"type": "font_weight",
|
|
42
22
|
},
|
|
43
23
|
],
|
|
44
24
|
"type": "paragraph",
|
|
@@ -48,7 +28,7 @@ Object {
|
|
|
48
28
|
}
|
|
49
29
|
`;
|
|
50
30
|
|
|
51
|
-
exports[`
|
|
31
|
+
exports[`transform text should transform selected text 1`] = `
|
|
52
32
|
Object {
|
|
53
33
|
"content": Array [
|
|
54
34
|
Object {
|
|
@@ -57,7 +37,7 @@ Object {
|
|
|
57
37
|
},
|
|
58
38
|
"content": Array [
|
|
59
39
|
Object {
|
|
60
|
-
"text": "
|
|
40
|
+
"text": "hELLO world",
|
|
61
41
|
"type": "text",
|
|
62
42
|
},
|
|
63
43
|
],
|
|
@@ -2,6 +2,12 @@ import { Step, StepResult } from 'prosemirror-transform';
|
|
|
2
2
|
import { Slice, Fragment } from 'prosemirror-model';
|
|
3
3
|
import { RemoveNodeMarkStep } from './RemoveNodeMarkStep';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Copy&Paste from the latest version prosemirror-transform
|
|
7
|
+
* Can be replaced to built-in commands when tiptap update dependencies
|
|
8
|
+
*
|
|
9
|
+
* Original file: https://github.com/ProseMirror/prosemirror-transform/blob/e659a51eacb6eab66be992ea86b9bf70881d7c5d/src/mark_step.ts#L131
|
|
10
|
+
*/
|
|
5
11
|
export class AddNodeMarkStep extends Step {
|
|
6
12
|
static fromJSON(schema, json) {
|
|
7
13
|
if (typeof json.pos != 'number') {
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Step, StepResult, StepMap } from 'prosemirror-transform';
|
|
2
|
+
import { Fragment, Slice } from 'prosemirror-model';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Copy&Paste from the latest version prosemirror-transform
|
|
6
|
+
* Can be replaced to built-in commands when tiptap update dependencies
|
|
7
|
+
*
|
|
8
|
+
* Original file: https://github.com/ProseMirror/prosemirror-transform/blob/9ee7c0806f38180bae0e60d7d84af4fd9ee44f26/src/attr_step.ts#L6
|
|
9
|
+
*/
|
|
10
|
+
export class AttrStep extends Step {
|
|
11
|
+
static fromJSON(schema, json) {
|
|
12
|
+
if (typeof json.pos != 'number' || typeof json.attr != 'string') {
|
|
13
|
+
throw new RangeError('Invalid input for AttrStep.fromJSON');
|
|
14
|
+
}
|
|
15
|
+
return new AttrStep(json.pos, json.attr, json.value);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
constructor(pos, attr, value) {
|
|
19
|
+
super();
|
|
20
|
+
this.pos = pos;
|
|
21
|
+
this.attr = attr;
|
|
22
|
+
this.value = value;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
apply(doc) {
|
|
26
|
+
const node = doc.nodeAt(this.pos);
|
|
27
|
+
|
|
28
|
+
if (!node) return StepResult.fail('No node at attribute step\'s position');
|
|
29
|
+
|
|
30
|
+
const attrs = Object.create(null);
|
|
31
|
+
|
|
32
|
+
for (let name in node.attrs) attrs[name] = node.attrs[name];
|
|
33
|
+
attrs[this.attr] = this.value;
|
|
34
|
+
|
|
35
|
+
const updated = node.type.create(attrs, null, node.marks);
|
|
36
|
+
const slice = new Slice(Fragment.from(updated), 0, node.isLeaf ? 0 : 1);
|
|
37
|
+
|
|
38
|
+
return StepResult.fromReplace(doc, this.pos, this.pos + 1, slice);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
getMap() {
|
|
42
|
+
return StepMap.empty;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
invert(doc) {
|
|
46
|
+
return new AttrStep(this.pos, this.attr, doc.nodeAt(this.pos).attrs[this.attr]);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
map(mapping) {
|
|
50
|
+
let pos = mapping.mapResult(this.pos, 1);
|
|
51
|
+
|
|
52
|
+
return pos.deletedAfter ? null : new AttrStep(pos.pos, this.attr, this.value);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
toJSON() {
|
|
56
|
+
return { stepType: 'attr', pos: this.pos, attr: this.attr, value: this.value };
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
Step.jsonID('attr', AttrStep);
|
|
@@ -2,6 +2,12 @@ import { Step, StepResult } from 'prosemirror-transform';
|
|
|
2
2
|
import { Slice, Fragment } from 'prosemirror-model';
|
|
3
3
|
import { AddNodeMarkStep } from './AddNodeMarkStep';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Copy&Paste from the latest version prosemirror-transform
|
|
7
|
+
* Can be replaced to built-in commands when tiptap update dependencies
|
|
8
|
+
*
|
|
9
|
+
* Original file: https://github.com/ProseMirror/prosemirror-transform/blob/e659a51eacb6eab66be992ea86b9bf70881d7c5d/src/mark_step.ts#L183
|
|
10
|
+
*/
|
|
5
11
|
export class RemoveNodeMarkStep extends Step {
|
|
6
12
|
static fromJSON(schema, json) {
|
|
7
13
|
if (typeof json.pos != 'number') {
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { Node, wrappingInputRule } from '@tiptap/vue-2';
|
|
2
2
|
import { computed, unref } from 'vue';
|
|
3
|
-
import { createCommand } from '../../utils';
|
|
4
|
-
import { ListTypes, NodeTypes } from '../../enums';
|
|
3
|
+
import { copyMark, createCommand } from '../../utils';
|
|
4
|
+
import { ListTypes, MarkGroups, NodeTypes, TextSettings } from '../../enums';
|
|
5
|
+
import { AddNodeMarkStep, RemoveNodeMarkStep } from '../core/steps';
|
|
5
6
|
import { ListItem } from './ListItem';
|
|
6
7
|
|
|
7
8
|
export const List = Node.create({
|
|
8
9
|
name: NodeTypes.LIST,
|
|
9
10
|
content: `${NodeTypes.LIST_ITEM}+`,
|
|
10
11
|
group: 'block list',
|
|
11
|
-
marks:
|
|
12
|
+
marks: MarkGroups.SETTINGS,
|
|
12
13
|
|
|
13
14
|
addExtensions: () => [
|
|
14
15
|
ListItem
|
|
@@ -79,21 +80,81 @@ export const List = Node.create({
|
|
|
79
80
|
|
|
80
81
|
// Remove List
|
|
81
82
|
if (currentType === type) {
|
|
82
|
-
commands.
|
|
83
|
+
commands.removeList();
|
|
83
84
|
return;
|
|
84
85
|
}
|
|
85
86
|
|
|
86
|
-
return chain().applyDefaultPreset()._addList(type).run();
|
|
87
|
-
}),
|
|
88
|
-
|
|
89
|
-
_addList: createCommand(({ chain }, type) => {
|
|
90
87
|
return chain()
|
|
88
|
+
.applyDefaultPreset()
|
|
91
89
|
.toggleList(NodeTypes.LIST, NodeTypes.LIST_ITEM)
|
|
92
90
|
.setBlockAttributes('bullet', { type })
|
|
91
|
+
.command(({ commands, tr }) => commands._bubbleListItemMarks(tr))
|
|
93
92
|
.run();
|
|
94
93
|
}),
|
|
95
94
|
|
|
96
|
-
|
|
95
|
+
_bubbleListItemMarks: createCommand((_, tr) => {
|
|
96
|
+
const { doc, selection } = tr;
|
|
97
|
+
const from = selection.$from.start();
|
|
98
|
+
const to = selection.$to.end();
|
|
99
|
+
|
|
100
|
+
function canBubbleMark(node, childMark) {
|
|
101
|
+
if (TextSettings.inlineMarks.includes(childMark.type)) return false;
|
|
102
|
+
if (childMark.type.isInSet(node.marks)) return false;
|
|
103
|
+
|
|
104
|
+
for (const child of node.content.content) {
|
|
105
|
+
if (!child.childCount) continue;
|
|
106
|
+
if (!child.marks) return false;
|
|
107
|
+
if (!childMark.isInSet(child.marks)) return false;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
doc.nodesBetween(from, to, (node, position) => {
|
|
114
|
+
if (node.type.name === NodeTypes.LIST) return;
|
|
115
|
+
if (node.type.name !== NodeTypes.LIST_ITEM) return false;
|
|
116
|
+
|
|
117
|
+
const bubbled = [];
|
|
118
|
+
|
|
119
|
+
node.forEach((child) => {
|
|
120
|
+
for (const childMark of child.marks) {
|
|
121
|
+
if (childMark.isInSet(bubbled)) {
|
|
122
|
+
tr.step(new RemoveNodeMarkStep(position + 1, childMark));
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (canBubbleMark(node, childMark)) {
|
|
127
|
+
tr.step(new RemoveNodeMarkStep(position + 1, childMark));
|
|
128
|
+
tr.step(new AddNodeMarkStep(position, copyMark(childMark)));
|
|
129
|
+
bubbled.push(childMark);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
return false;
|
|
135
|
+
});
|
|
136
|
+
}),
|
|
137
|
+
|
|
138
|
+
removeList: createCommand(({ commands, state }) => {
|
|
139
|
+
const { tr, doc, selection } = state;
|
|
140
|
+
const from = selection.$from.start();
|
|
141
|
+
const to = selection.$to.end();
|
|
142
|
+
|
|
143
|
+
doc.nodesBetween(from, to, (node, position, parent) => {
|
|
144
|
+
if ([NodeTypes.LIST, NodeTypes.LIST_ITEM].includes(node.type.name)) return;
|
|
145
|
+
if (parent.type.name !== NodeTypes.LIST_ITEM) return false;
|
|
146
|
+
|
|
147
|
+
const addingMarks = parent.marks.filter(function (mark) {
|
|
148
|
+
return !mark.type.isInSet(node.marks);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
for (const mark of addingMarks) {
|
|
152
|
+
tr.step(new AddNodeMarkStep(position, copyMark(mark)));
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return false;
|
|
156
|
+
});
|
|
157
|
+
|
|
97
158
|
commands.liftListItem(NodeTypes.LIST_ITEM);
|
|
98
159
|
})
|
|
99
160
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import Base from '@tiptap/extension-list-item';
|
|
2
|
-
import { NodeTypes } from '../../enums';
|
|
2
|
+
import { MarkGroups, NodeTypes } from '../../enums';
|
|
3
3
|
|
|
4
4
|
export const ListItem = Base.extend({
|
|
5
5
|
name: NodeTypes.LIST_ITEM,
|
|
6
|
-
marks:
|
|
6
|
+
marks: MarkGroups.SETTINGS,
|
|
7
7
|
|
|
8
8
|
addOptions: () => ({
|
|
9
9
|
HTMLAttributes: { class: 'zw-style' }
|