@zipify/wysiwyg 2.0.0-1 → 2.0.0-11
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/config/build/cli.config.js +8 -2
- package/dist/cli.js +3 -3
- package/dist/wysiwyg.css +41 -31
- package/dist/wysiwyg.mjs +2015 -1359
- package/example/ExampleApp.vue +10 -1
- 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 +55 -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/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 +4 -4
- 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 +1 -1
- 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/StylePreset.js +9 -2
- package/lib/extensions/Superscript.js +5 -2
- package/lib/extensions/TextDecoration.js +7 -0
- 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__/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 +20 -0
- package/lib/extensions/__tests__/__snapshots__/BackgroundColor.test.js.snap +25 -25
- package/lib/extensions/__tests__/__snapshots__/Superscript.test.js.snap +107 -0
- package/lib/extensions/core/Document.js +2 -1
- package/lib/extensions/core/Heading.js +2 -1
- package/lib/extensions/core/NodeProcessor.js +42 -21
- package/lib/extensions/core/Paragraph.js +2 -1
- package/lib/extensions/core/__tests__/NodeProcessor.test.js +309 -11
- package/lib/extensions/core/__tests__/TextProcessor.test.js +1 -1
- package/lib/extensions/core/__tests__/__snapshots__/NodeProcessor.test.js.snap +249 -0
- package/lib/extensions/core/steps/AddNodeMarkStep.js +6 -0
- package/lib/extensions/core/steps/AttrStep.js +6 -0
- package/lib/extensions/core/steps/RemoveNodeMarkStep.js +6 -0
- package/lib/extensions/list/List.js +70 -9
- package/lib/extensions/list/ListItem.js +27 -5
- 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 +69 -3
- package/lib/services/__tests__/NodeFactory.test.js +124 -0
- package/lib/services/__tests__/__snapshots__/NodeFactory.test.js.snap +326 -0
- package/lib/services/normalizer/HtmlNormalizer.js +54 -2
- package/lib/services/normalizer/JsonNormalizer.js +6 -5
- package/lib/services/normalizer/__tests__/HtmlNormalizer.test.js +14 -0
- package/lib/services/normalizer/__tests__/JsonNormalizer.test.js +20 -3
- package/lib/services/normalizer/__tests__/__snapshots__/JsonNormalizer.test.js.snap +37 -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 +1 -1
- package/lib/utils/isNodeFullySelected.js +4 -7
- package/lib/utils/resolveTextPosition.js +4 -6
- package/package.json +37 -27
- 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 [
|
|
@@ -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') {
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { Step, StepResult, StepMap } from 'prosemirror-transform';
|
|
2
2
|
import { Fragment, Slice } from 'prosemirror-model';
|
|
3
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
|
+
*/
|
|
4
10
|
export class AttrStep extends Step {
|
|
5
11
|
static fromJSON(schema, json) {
|
|
6
12
|
if (typeof json.pos != 'number' || typeof json.attr != 'string') {
|
|
@@ -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,17 +1,39 @@
|
|
|
1
1
|
import Base from '@tiptap/extension-list-item';
|
|
2
|
-
import { NodeTypes } from '../../enums';
|
|
2
|
+
import { MarkGroups, NodeTypes } from '../../enums';
|
|
3
|
+
import { copyMark, createCommand, createKeyboardShortcut } from '../../utils';
|
|
4
|
+
import { AddNodeMarkStep } from '../core/steps';
|
|
3
5
|
|
|
4
6
|
export const ListItem = Base.extend({
|
|
5
7
|
name: NodeTypes.LIST_ITEM,
|
|
6
|
-
marks:
|
|
8
|
+
marks: MarkGroups.SETTINGS,
|
|
9
|
+
|
|
10
|
+
addCommands() {
|
|
11
|
+
const getSelectedListItem = ({ selection, doc }) => {
|
|
12
|
+
const position = selection.$cursor.before(selection.$cursor.depth - 1);
|
|
13
|
+
|
|
14
|
+
return { position, node: doc.nodeAt(position) };
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
listItemNewline: createCommand(({ commands, tr }) => {
|
|
19
|
+
const { node: initialNode } = getSelectedListItem(tr);
|
|
20
|
+
|
|
21
|
+
commands.splitListItem(this.name);
|
|
22
|
+
|
|
23
|
+
const { position } = getSelectedListItem(tr);
|
|
24
|
+
|
|
25
|
+
for (const mark of initialNode.marks) {
|
|
26
|
+
tr.step(new AddNodeMarkStep(position, copyMark(mark)));
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
};
|
|
30
|
+
},
|
|
7
31
|
|
|
8
32
|
addOptions: () => ({
|
|
9
33
|
HTMLAttributes: { class: 'zw-style' }
|
|
10
34
|
}),
|
|
11
35
|
|
|
12
36
|
addKeyboardShortcuts() {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return { Enter };
|
|
37
|
+
return { Enter: createKeyboardShortcut('listItemNewline') };
|
|
16
38
|
}
|
|
17
39
|
});
|
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
import { Editor } from '@tiptap/vue-2';
|
|
1
|
+
import { Editor, Mark } from '@tiptap/vue-2';
|
|
2
2
|
import { buildTestExtensions } from '../../../__tests__/utils';
|
|
3
|
-
import { ListTypes } from '../../../enums';
|
|
3
|
+
import { ListTypes, TextSettings } from '../../../enums';
|
|
4
4
|
import { StylePreset } from '../../StylePreset';
|
|
5
5
|
import { ContentNormalizer, NodeFactory } from '../../../services';
|
|
6
6
|
import { List } from '../List';
|
|
7
7
|
|
|
8
|
+
const MockFontWeight = Mark.create({
|
|
9
|
+
name: TextSettings.FONT_WEIGHT,
|
|
10
|
+
renderHTML: () => ['span', {}, 0],
|
|
11
|
+
addAttributes: () => ({ value: { required: true } })
|
|
12
|
+
});
|
|
13
|
+
|
|
8
14
|
function createEditor({ content }) {
|
|
9
15
|
return new Editor({
|
|
10
16
|
content: ContentNormalizer.normalize(content),
|
|
@@ -24,7 +30,8 @@ function createEditor({ content }) {
|
|
|
24
30
|
],
|
|
25
31
|
defaultId: 'regular-1',
|
|
26
32
|
baseClass: 'zw ts-'
|
|
27
|
-
})
|
|
33
|
+
}),
|
|
34
|
+
MockFontWeight
|
|
28
35
|
]
|
|
29
36
|
})
|
|
30
37
|
});
|
|
@@ -73,7 +80,7 @@ describe('apply list', () => {
|
|
|
73
80
|
expect(editor.getJSON()).toMatchSnapshot();
|
|
74
81
|
});
|
|
75
82
|
|
|
76
|
-
test('should
|
|
83
|
+
test('should toggle list', () => {
|
|
77
84
|
const editor = createEditor({
|
|
78
85
|
content: NodeFactory.doc([
|
|
79
86
|
NodeFactory.list(ListTypes.LATIN, [
|
|
@@ -84,12 +91,12 @@ describe('apply list', () => {
|
|
|
84
91
|
});
|
|
85
92
|
|
|
86
93
|
editor.commands.selectAll();
|
|
87
|
-
editor.commands.
|
|
94
|
+
editor.commands.applyList(ListTypes.LATIN);
|
|
88
95
|
|
|
89
96
|
expect(editor.getJSON()).toMatchSnapshot();
|
|
90
97
|
});
|
|
91
98
|
|
|
92
|
-
test('should
|
|
99
|
+
test('should change list type', () => {
|
|
93
100
|
const editor = createEditor({
|
|
94
101
|
content: NodeFactory.doc([
|
|
95
102
|
NodeFactory.list(ListTypes.LATIN, [
|
|
@@ -100,37 +107,39 @@ describe('apply list', () => {
|
|
|
100
107
|
});
|
|
101
108
|
|
|
102
109
|
editor.commands.selectAll();
|
|
103
|
-
editor.commands.applyList(ListTypes.
|
|
110
|
+
editor.commands.applyList(ListTypes.ROMAN);
|
|
104
111
|
|
|
105
112
|
expect(editor.getJSON()).toMatchSnapshot();
|
|
106
113
|
});
|
|
107
114
|
|
|
108
|
-
test('should
|
|
115
|
+
test('should remove preset', () => {
|
|
109
116
|
const editor = createEditor({
|
|
110
117
|
content: NodeFactory.doc([
|
|
111
|
-
NodeFactory.
|
|
112
|
-
|
|
113
|
-
NodeFactory.paragraph('Item 2')
|
|
114
|
-
])
|
|
118
|
+
NodeFactory.paragraph({ preset: { id: 'regular-1' } }, 'Item 1'),
|
|
119
|
+
NodeFactory.paragraph({ preset: { id: 'regular-1' } }, 'Item 2')
|
|
115
120
|
])
|
|
116
121
|
});
|
|
117
122
|
|
|
118
123
|
editor.commands.selectAll();
|
|
119
|
-
editor.commands.applyList(ListTypes.
|
|
124
|
+
editor.commands.applyList(ListTypes.LATIN);
|
|
120
125
|
|
|
121
126
|
expect(editor.getJSON()).toMatchSnapshot();
|
|
122
127
|
});
|
|
128
|
+
});
|
|
123
129
|
|
|
124
|
-
|
|
130
|
+
describe('remove list', () => {
|
|
131
|
+
test('should remove list', () => {
|
|
125
132
|
const editor = createEditor({
|
|
126
133
|
content: NodeFactory.doc([
|
|
127
|
-
NodeFactory.
|
|
128
|
-
|
|
134
|
+
NodeFactory.list(ListTypes.LATIN, [
|
|
135
|
+
NodeFactory.paragraph('Item 1'),
|
|
136
|
+
NodeFactory.paragraph('Item 2')
|
|
137
|
+
])
|
|
129
138
|
])
|
|
130
139
|
});
|
|
131
140
|
|
|
132
141
|
editor.commands.selectAll();
|
|
133
|
-
editor.commands.
|
|
142
|
+
editor.commands.removeList();
|
|
134
143
|
|
|
135
144
|
expect(editor.getJSON()).toMatchSnapshot();
|
|
136
145
|
});
|
|
@@ -93,42 +93,6 @@ Object {
|
|
|
93
93
|
}
|
|
94
94
|
`;
|
|
95
95
|
|
|
96
|
-
exports[`apply list should remove list 1`] = `
|
|
97
|
-
Object {
|
|
98
|
-
"content": Array [
|
|
99
|
-
Object {
|
|
100
|
-
"attrs": Object {
|
|
101
|
-
"preset": Object {
|
|
102
|
-
"id": "regular-1",
|
|
103
|
-
},
|
|
104
|
-
},
|
|
105
|
-
"content": Array [
|
|
106
|
-
Object {
|
|
107
|
-
"text": "Item 1",
|
|
108
|
-
"type": "text",
|
|
109
|
-
},
|
|
110
|
-
],
|
|
111
|
-
"type": "paragraph",
|
|
112
|
-
},
|
|
113
|
-
Object {
|
|
114
|
-
"attrs": Object {
|
|
115
|
-
"preset": Object {
|
|
116
|
-
"id": "regular-1",
|
|
117
|
-
},
|
|
118
|
-
},
|
|
119
|
-
"content": Array [
|
|
120
|
-
Object {
|
|
121
|
-
"text": "Item 2",
|
|
122
|
-
"type": "text",
|
|
123
|
-
},
|
|
124
|
-
],
|
|
125
|
-
"type": "paragraph",
|
|
126
|
-
},
|
|
127
|
-
],
|
|
128
|
-
"type": "doc",
|
|
129
|
-
}
|
|
130
|
-
`;
|
|
131
|
-
|
|
132
96
|
exports[`apply list should remove preset 1`] = `
|
|
133
97
|
Object {
|
|
134
98
|
"content": Array [
|
|
@@ -701,3 +665,39 @@ Object {
|
|
|
701
665
|
"type": "doc",
|
|
702
666
|
}
|
|
703
667
|
`;
|
|
668
|
+
|
|
669
|
+
exports[`remove list should remove list 1`] = `
|
|
670
|
+
Object {
|
|
671
|
+
"content": Array [
|
|
672
|
+
Object {
|
|
673
|
+
"attrs": Object {
|
|
674
|
+
"preset": Object {
|
|
675
|
+
"id": "regular-1",
|
|
676
|
+
},
|
|
677
|
+
},
|
|
678
|
+
"content": Array [
|
|
679
|
+
Object {
|
|
680
|
+
"text": "Item 1",
|
|
681
|
+
"type": "text",
|
|
682
|
+
},
|
|
683
|
+
],
|
|
684
|
+
"type": "paragraph",
|
|
685
|
+
},
|
|
686
|
+
Object {
|
|
687
|
+
"attrs": Object {
|
|
688
|
+
"preset": Object {
|
|
689
|
+
"id": "regular-1",
|
|
690
|
+
},
|
|
691
|
+
},
|
|
692
|
+
"content": Array [
|
|
693
|
+
Object {
|
|
694
|
+
"text": "Item 2",
|
|
695
|
+
"type": "text",
|
|
696
|
+
},
|
|
697
|
+
],
|
|
698
|
+
"type": "paragraph",
|
|
699
|
+
},
|
|
700
|
+
],
|
|
701
|
+
"type": "doc",
|
|
702
|
+
}
|
|
703
|
+
`;
|