@zipify/wysiwyg 1.3.0-0 → 2.0.0-0
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/dist/cli.js +2 -2
- package/dist/wysiwyg.css +31 -42
- package/dist/wysiwyg.mjs +454 -399
- package/lib/__tests__/utils/buildTestExtensions.js +14 -0
- package/lib/__tests__/utils/index.js +1 -0
- package/lib/components/base/Button.vue +0 -7
- package/lib/components/base/dropdown/Dropdown.vue +1 -7
- package/lib/components/base/dropdown/DropdownActivator.vue +4 -19
- package/lib/components/base/dropdown/__tests__/DropdownActivator.test.js +1 -23
- package/lib/components/toolbar/controls/AlignmentControl.vue +1 -11
- package/lib/components/toolbar/controls/FontColorControl.vue +0 -13
- package/lib/components/toolbar/controls/FontFamilyControl.vue +0 -4
- package/lib/components/toolbar/controls/FontSizeControl.vue +1 -6
- package/lib/components/toolbar/controls/FontWeightControl.vue +0 -12
- package/lib/components/toolbar/controls/ItalicControl.vue +0 -13
- package/lib/components/toolbar/controls/LineHeightControl.vue +0 -14
- package/lib/components/toolbar/controls/SuperscriptControl.vue +2 -2
- package/lib/components/toolbar/controls/UnderlineControl.vue +0 -12
- package/lib/components/toolbar/controls/__tests__/AlignmentControl.test.js +5 -72
- package/lib/components/toolbar/controls/__tests__/FontColorControl.test.js +1 -22
- package/lib/components/toolbar/controls/__tests__/FontFamilyControl.test.js +0 -1
- package/lib/components/toolbar/controls/__tests__/FontSizeControl.test.js +0 -1
- package/lib/components/toolbar/controls/__tests__/FontWeightControl.test.js +0 -1
- package/lib/components/toolbar/controls/__tests__/ItalicControl.test.js +1 -23
- package/lib/components/toolbar/controls/__tests__/LineHeightControl.test.js +1 -23
- package/lib/components/toolbar/controls/__tests__/SuperscriptControl.test.js +2 -2
- package/lib/components/toolbar/controls/__tests__/UnderlineControl.test.js +1 -25
- package/lib/composables/__tests__/useEditor.test.js +2 -2
- package/lib/extensions/BackgroundColor.js +4 -4
- package/lib/extensions/FontColor.js +4 -5
- package/lib/extensions/FontFamily.js +4 -5
- package/lib/extensions/FontSize.js +5 -7
- package/lib/extensions/FontStyle.js +13 -11
- package/lib/extensions/FontWeight.js +6 -9
- package/lib/extensions/StylePreset.js +0 -14
- package/lib/extensions/Superscript.js +23 -1
- package/lib/extensions/TextDecoration.js +33 -20
- package/lib/extensions/__tests__/Alignment.test.js +10 -7
- package/lib/extensions/__tests__/BackgroundColor.test.js +6 -3
- package/lib/extensions/__tests__/CaseStyle.test.js +11 -7
- package/lib/extensions/__tests__/FontColor.test.js +6 -3
- package/lib/extensions/__tests__/FontFamily.test.js +29 -22
- package/lib/extensions/__tests__/FontSize.test.js +24 -17
- package/lib/extensions/__tests__/FontStyle.test.js +22 -16
- package/lib/extensions/__tests__/FontWeight.test.js +26 -19
- package/lib/extensions/__tests__/LineHeight.test.js +14 -11
- package/lib/extensions/__tests__/Link.test.js +14 -10
- package/lib/extensions/__tests__/Margin.test.js +2 -2
- package/lib/extensions/__tests__/StylePreset.test.js +49 -100
- package/lib/extensions/__tests__/TextDecoration.test.js +72 -46
- package/lib/extensions/__tests__/__snapshots__/BackgroundColor.test.js.snap +24 -24
- package/lib/extensions/__tests__/__snapshots__/FontColor.test.js.snap +24 -24
- package/lib/extensions/__tests__/__snapshots__/FontFamily.test.js.snap +86 -82
- package/lib/extensions/__tests__/__snapshots__/FontSize.test.js.snap +70 -70
- package/lib/extensions/__tests__/__snapshots__/FontStyle.test.js.snap +53 -45
- package/lib/extensions/__tests__/__snapshots__/FontWeight.test.js.snap +64 -60
- package/lib/extensions/__tests__/__snapshots__/TextDecoration.test.js.snap +148 -83
- package/lib/extensions/core/Document.js +5 -0
- package/lib/extensions/core/Heading.js +10 -0
- package/lib/extensions/core/NodeProcessor.js +84 -4
- package/lib/extensions/core/Paragraph.js +9 -0
- package/lib/extensions/core/TextProcessor.js +10 -12
- package/lib/extensions/core/__tests__/NodeProcessor.test.js +82 -10
- package/lib/extensions/core/__tests__/SelectionProcessor.test.js +2 -2
- package/lib/extensions/core/__tests__/TextProcessor.test.js +18 -20
- package/lib/extensions/core/__tests__/__snapshots__/NodeProcessor.test.js.snap +132 -0
- package/lib/extensions/core/index.js +5 -5
- package/lib/extensions/core/steps/AddNodeMarkStep.js +60 -0
- package/lib/extensions/core/steps/RemoveNodeMarkStep.js +50 -0
- package/lib/extensions/core/steps/index.js +2 -0
- package/lib/extensions/list/List.js +1 -0
- package/lib/extensions/list/ListItem.js +5 -0
- package/lib/extensions/list/__tests__/List.test.js +30 -25
- package/lib/services/ContentNormalizer.js +1 -100
- package/lib/services/NodeFactory.js +16 -6
- package/lib/services/__tests__/ContentNormalizer.test.js +0 -64
- package/lib/utils/findMarkByType.js +5 -0
- package/lib/utils/index.js +5 -0
- package/lib/utils/isMarkAppliedToParent.js +15 -0
- package/lib/utils/isNodeFullySelected.js +10 -0
- package/lib/utils/resolveNodePosition.js +6 -0
- package/lib/utils/resolveTextPosition.js +6 -0
- package/package.json +1 -1
- package/lib/assets/icons/indicator.svg +0 -5
|
@@ -6,18 +6,18 @@ Object {
|
|
|
6
6
|
Object {
|
|
7
7
|
"content": Array [
|
|
8
8
|
Object {
|
|
9
|
-
"marks": Array [
|
|
10
|
-
Object {
|
|
11
|
-
"attrs": Object {
|
|
12
|
-
"value": "700",
|
|
13
|
-
},
|
|
14
|
-
"type": "font_weight",
|
|
15
|
-
},
|
|
16
|
-
],
|
|
17
9
|
"text": "hello world",
|
|
18
10
|
"type": "text",
|
|
19
11
|
},
|
|
20
12
|
],
|
|
13
|
+
"marks": Array [
|
|
14
|
+
Object {
|
|
15
|
+
"attrs": Object {
|
|
16
|
+
"value": "700",
|
|
17
|
+
},
|
|
18
|
+
"type": "font_weight",
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
21
|
"type": "paragraph",
|
|
22
22
|
},
|
|
23
23
|
],
|
|
@@ -31,18 +31,18 @@ Object {
|
|
|
31
31
|
Object {
|
|
32
32
|
"content": Array [
|
|
33
33
|
Object {
|
|
34
|
-
"marks": Array [
|
|
35
|
-
Object {
|
|
36
|
-
"attrs": Object {
|
|
37
|
-
"value": "700",
|
|
38
|
-
},
|
|
39
|
-
"type": "font_weight",
|
|
40
|
-
},
|
|
41
|
-
],
|
|
42
34
|
"text": "hello world",
|
|
43
35
|
"type": "text",
|
|
44
36
|
},
|
|
45
37
|
],
|
|
38
|
+
"marks": Array [
|
|
39
|
+
Object {
|
|
40
|
+
"attrs": Object {
|
|
41
|
+
"value": "700",
|
|
42
|
+
},
|
|
43
|
+
"type": "font_weight",
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
46
|
"type": "paragraph",
|
|
47
47
|
},
|
|
48
48
|
],
|
|
@@ -63,17 +63,19 @@ Object {
|
|
|
63
63
|
},
|
|
64
64
|
"type": "font_family",
|
|
65
65
|
},
|
|
66
|
-
Object {
|
|
67
|
-
"attrs": Object {
|
|
68
|
-
"value": "800",
|
|
69
|
-
},
|
|
70
|
-
"type": "font_weight",
|
|
71
|
-
},
|
|
72
66
|
],
|
|
73
67
|
"text": "hello world",
|
|
74
68
|
"type": "text",
|
|
75
69
|
},
|
|
76
70
|
],
|
|
71
|
+
"marks": Array [
|
|
72
|
+
Object {
|
|
73
|
+
"attrs": Object {
|
|
74
|
+
"value": "800",
|
|
75
|
+
},
|
|
76
|
+
"type": "font_weight",
|
|
77
|
+
},
|
|
78
|
+
],
|
|
77
79
|
"type": "paragraph",
|
|
78
80
|
},
|
|
79
81
|
],
|
|
@@ -94,17 +96,19 @@ Object {
|
|
|
94
96
|
},
|
|
95
97
|
"type": "font_family",
|
|
96
98
|
},
|
|
97
|
-
Object {
|
|
98
|
-
"attrs": Object {
|
|
99
|
-
"value": "300",
|
|
100
|
-
},
|
|
101
|
-
"type": "font_weight",
|
|
102
|
-
},
|
|
103
99
|
],
|
|
104
100
|
"text": "hello world",
|
|
105
101
|
"type": "text",
|
|
106
102
|
},
|
|
107
103
|
],
|
|
104
|
+
"marks": Array [
|
|
105
|
+
Object {
|
|
106
|
+
"attrs": Object {
|
|
107
|
+
"value": "300",
|
|
108
|
+
},
|
|
109
|
+
"type": "font_weight",
|
|
110
|
+
},
|
|
111
|
+
],
|
|
108
112
|
"type": "paragraph",
|
|
109
113
|
},
|
|
110
114
|
],
|
|
@@ -118,18 +122,18 @@ Object {
|
|
|
118
122
|
Object {
|
|
119
123
|
"content": Array [
|
|
120
124
|
Object {
|
|
121
|
-
"marks": Array [
|
|
122
|
-
Object {
|
|
123
|
-
"attrs": Object {
|
|
124
|
-
"value": "400",
|
|
125
|
-
},
|
|
126
|
-
"type": "font_weight",
|
|
127
|
-
},
|
|
128
|
-
],
|
|
129
125
|
"text": "hello world",
|
|
130
126
|
"type": "text",
|
|
131
127
|
},
|
|
132
128
|
],
|
|
129
|
+
"marks": Array [
|
|
130
|
+
Object {
|
|
131
|
+
"attrs": Object {
|
|
132
|
+
"value": "400",
|
|
133
|
+
},
|
|
134
|
+
"type": "font_weight",
|
|
135
|
+
},
|
|
136
|
+
],
|
|
133
137
|
"type": "paragraph",
|
|
134
138
|
},
|
|
135
139
|
],
|
|
@@ -172,18 +176,18 @@ Object {
|
|
|
172
176
|
Object {
|
|
173
177
|
"content": Array [
|
|
174
178
|
Object {
|
|
175
|
-
"marks": Array [
|
|
176
|
-
Object {
|
|
177
|
-
"attrs": Object {
|
|
178
|
-
"value": "700",
|
|
179
|
-
},
|
|
180
|
-
"type": "font_weight",
|
|
181
|
-
},
|
|
182
|
-
],
|
|
183
179
|
"text": "test",
|
|
184
180
|
"type": "text",
|
|
185
181
|
},
|
|
186
182
|
],
|
|
183
|
+
"marks": Array [
|
|
184
|
+
Object {
|
|
185
|
+
"attrs": Object {
|
|
186
|
+
"value": "700",
|
|
187
|
+
},
|
|
188
|
+
"type": "font_weight",
|
|
189
|
+
},
|
|
190
|
+
],
|
|
187
191
|
"type": "paragraph",
|
|
188
192
|
},
|
|
189
193
|
],
|
|
@@ -313,18 +317,18 @@ Object {
|
|
|
313
317
|
"type": "text",
|
|
314
318
|
},
|
|
315
319
|
Object {
|
|
316
|
-
"marks": Array [
|
|
317
|
-
Object {
|
|
318
|
-
"attrs": Object {
|
|
319
|
-
"value": "500",
|
|
320
|
-
},
|
|
321
|
-
"type": "font_weight",
|
|
322
|
-
},
|
|
323
|
-
],
|
|
324
320
|
"text": " ipsum",
|
|
325
321
|
"type": "text",
|
|
326
322
|
},
|
|
327
323
|
],
|
|
324
|
+
"marks": Array [
|
|
325
|
+
Object {
|
|
326
|
+
"attrs": Object {
|
|
327
|
+
"value": "500",
|
|
328
|
+
},
|
|
329
|
+
"type": "font_weight",
|
|
330
|
+
},
|
|
331
|
+
],
|
|
328
332
|
"type": "paragraph",
|
|
329
333
|
},
|
|
330
334
|
],
|
|
@@ -338,18 +342,18 @@ Object {
|
|
|
338
342
|
Object {
|
|
339
343
|
"content": Array [
|
|
340
344
|
Object {
|
|
341
|
-
"marks": Array [
|
|
342
|
-
Object {
|
|
343
|
-
"attrs": Object {
|
|
344
|
-
"value": "700",
|
|
345
|
-
},
|
|
346
|
-
"type": "font_weight",
|
|
347
|
-
},
|
|
348
|
-
],
|
|
349
345
|
"text": "test",
|
|
350
346
|
"type": "text",
|
|
351
347
|
},
|
|
352
348
|
],
|
|
349
|
+
"marks": Array [
|
|
350
|
+
Object {
|
|
351
|
+
"attrs": Object {
|
|
352
|
+
"value": "700",
|
|
353
|
+
},
|
|
354
|
+
"type": "font_weight",
|
|
355
|
+
},
|
|
356
|
+
],
|
|
353
357
|
"type": "paragraph",
|
|
354
358
|
},
|
|
355
359
|
],
|
|
@@ -1,6 +1,32 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
3
|
exports[`apply decoration should apply decoration 1`] = `
|
|
4
|
+
Object {
|
|
5
|
+
"content": Array [
|
|
6
|
+
Object {
|
|
7
|
+
"content": Array [
|
|
8
|
+
Object {
|
|
9
|
+
"text": "hello world",
|
|
10
|
+
"type": "text",
|
|
11
|
+
},
|
|
12
|
+
],
|
|
13
|
+
"marks": Array [
|
|
14
|
+
Object {
|
|
15
|
+
"attrs": Object {
|
|
16
|
+
"strike_through": false,
|
|
17
|
+
"underline": true,
|
|
18
|
+
},
|
|
19
|
+
"type": "text_decoration",
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
"type": "paragraph",
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
"type": "doc",
|
|
26
|
+
}
|
|
27
|
+
`;
|
|
28
|
+
|
|
29
|
+
exports[`apply decoration should apply decoration with decorated parent false value 1`] = `
|
|
4
30
|
Object {
|
|
5
31
|
"content": Array [
|
|
6
32
|
Object {
|
|
@@ -15,10 +41,49 @@ Object {
|
|
|
15
41
|
"type": "text_decoration",
|
|
16
42
|
},
|
|
17
43
|
],
|
|
44
|
+
"text": "hello",
|
|
45
|
+
"type": "text",
|
|
46
|
+
},
|
|
47
|
+
Object {
|
|
48
|
+
"text": " world",
|
|
49
|
+
"type": "text",
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
"marks": Array [
|
|
53
|
+
Object {
|
|
54
|
+
"attrs": Object {
|
|
55
|
+
"strike_through": false,
|
|
56
|
+
"underline": false,
|
|
57
|
+
},
|
|
58
|
+
"type": "text_decoration",
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
"type": "paragraph",
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
"type": "doc",
|
|
65
|
+
}
|
|
66
|
+
`;
|
|
67
|
+
|
|
68
|
+
exports[`apply decoration should not apply decoration with decorated parent 1`] = `
|
|
69
|
+
Object {
|
|
70
|
+
"content": Array [
|
|
71
|
+
Object {
|
|
72
|
+
"content": Array [
|
|
73
|
+
Object {
|
|
18
74
|
"text": "hello world",
|
|
19
75
|
"type": "text",
|
|
20
76
|
},
|
|
21
77
|
],
|
|
78
|
+
"marks": Array [
|
|
79
|
+
Object {
|
|
80
|
+
"attrs": Object {
|
|
81
|
+
"strike_through": false,
|
|
82
|
+
"underline": true,
|
|
83
|
+
},
|
|
84
|
+
"type": "text_decoration",
|
|
85
|
+
},
|
|
86
|
+
],
|
|
22
87
|
"type": "paragraph",
|
|
23
88
|
},
|
|
24
89
|
],
|
|
@@ -32,19 +97,19 @@ Object {
|
|
|
32
97
|
Object {
|
|
33
98
|
"content": Array [
|
|
34
99
|
Object {
|
|
35
|
-
"marks": Array [
|
|
36
|
-
Object {
|
|
37
|
-
"attrs": Object {
|
|
38
|
-
"strike_through": true,
|
|
39
|
-
"underline": true,
|
|
40
|
-
},
|
|
41
|
-
"type": "text_decoration",
|
|
42
|
-
},
|
|
43
|
-
],
|
|
44
100
|
"text": "hello world",
|
|
45
101
|
"type": "text",
|
|
46
102
|
},
|
|
47
103
|
],
|
|
104
|
+
"marks": Array [
|
|
105
|
+
Object {
|
|
106
|
+
"attrs": Object {
|
|
107
|
+
"strike_through": true,
|
|
108
|
+
"underline": true,
|
|
109
|
+
},
|
|
110
|
+
"type": "text_decoration",
|
|
111
|
+
},
|
|
112
|
+
],
|
|
48
113
|
"type": "paragraph",
|
|
49
114
|
},
|
|
50
115
|
],
|
|
@@ -58,19 +123,19 @@ Object {
|
|
|
58
123
|
Object {
|
|
59
124
|
"content": Array [
|
|
60
125
|
Object {
|
|
61
|
-
"
|
|
62
|
-
Object {
|
|
63
|
-
"attrs": Object {
|
|
64
|
-
"strike_through": false,
|
|
65
|
-
"underline": true,
|
|
66
|
-
},
|
|
67
|
-
"type": "text_decoration",
|
|
68
|
-
},
|
|
69
|
-
],
|
|
70
|
-
"text": "hello world",
|
|
126
|
+
"text": "lorem ipsum",
|
|
71
127
|
"type": "text",
|
|
72
128
|
},
|
|
73
129
|
],
|
|
130
|
+
"marks": Array [
|
|
131
|
+
Object {
|
|
132
|
+
"attrs": Object {
|
|
133
|
+
"strike_through": false,
|
|
134
|
+
"underline": false,
|
|
135
|
+
},
|
|
136
|
+
"type": "text_decoration",
|
|
137
|
+
},
|
|
138
|
+
],
|
|
74
139
|
"type": "paragraph",
|
|
75
140
|
},
|
|
76
141
|
],
|
|
@@ -84,19 +149,19 @@ Object {
|
|
|
84
149
|
Object {
|
|
85
150
|
"content": Array [
|
|
86
151
|
Object {
|
|
87
|
-
"marks": Array [
|
|
88
|
-
Object {
|
|
89
|
-
"attrs": Object {
|
|
90
|
-
"strike_through": true,
|
|
91
|
-
"underline": false,
|
|
92
|
-
},
|
|
93
|
-
"type": "text_decoration",
|
|
94
|
-
},
|
|
95
|
-
],
|
|
96
152
|
"text": "hello world",
|
|
97
153
|
"type": "text",
|
|
98
154
|
},
|
|
99
155
|
],
|
|
156
|
+
"marks": Array [
|
|
157
|
+
Object {
|
|
158
|
+
"attrs": Object {
|
|
159
|
+
"strike_through": true,
|
|
160
|
+
"underline": false,
|
|
161
|
+
},
|
|
162
|
+
"type": "text_decoration",
|
|
163
|
+
},
|
|
164
|
+
],
|
|
100
165
|
"type": "paragraph",
|
|
101
166
|
},
|
|
102
167
|
],
|
|
@@ -110,19 +175,19 @@ Object {
|
|
|
110
175
|
Object {
|
|
111
176
|
"content": Array [
|
|
112
177
|
Object {
|
|
113
|
-
"
|
|
114
|
-
Object {
|
|
115
|
-
"attrs": Object {
|
|
116
|
-
"strike_through": true,
|
|
117
|
-
"underline": false,
|
|
118
|
-
},
|
|
119
|
-
"type": "text_decoration",
|
|
120
|
-
},
|
|
121
|
-
],
|
|
122
|
-
"text": "hello world",
|
|
178
|
+
"text": "lorem ipsum",
|
|
123
179
|
"type": "text",
|
|
124
180
|
},
|
|
125
181
|
],
|
|
182
|
+
"marks": Array [
|
|
183
|
+
Object {
|
|
184
|
+
"attrs": Object {
|
|
185
|
+
"strike_through": false,
|
|
186
|
+
"underline": false,
|
|
187
|
+
},
|
|
188
|
+
"type": "text_decoration",
|
|
189
|
+
},
|
|
190
|
+
],
|
|
126
191
|
"type": "paragraph",
|
|
127
192
|
},
|
|
128
193
|
],
|
|
@@ -136,19 +201,19 @@ Object {
|
|
|
136
201
|
Object {
|
|
137
202
|
"content": Array [
|
|
138
203
|
Object {
|
|
139
|
-
"marks": Array [
|
|
140
|
-
Object {
|
|
141
|
-
"attrs": Object {
|
|
142
|
-
"strike_through": false,
|
|
143
|
-
"underline": true,
|
|
144
|
-
},
|
|
145
|
-
"type": "text_decoration",
|
|
146
|
-
},
|
|
147
|
-
],
|
|
148
204
|
"text": "hello world",
|
|
149
205
|
"type": "text",
|
|
150
206
|
},
|
|
151
207
|
],
|
|
208
|
+
"marks": Array [
|
|
209
|
+
Object {
|
|
210
|
+
"attrs": Object {
|
|
211
|
+
"strike_through": false,
|
|
212
|
+
"underline": true,
|
|
213
|
+
},
|
|
214
|
+
"type": "text_decoration",
|
|
215
|
+
},
|
|
216
|
+
],
|
|
152
217
|
"type": "paragraph",
|
|
153
218
|
},
|
|
154
219
|
],
|
|
@@ -162,19 +227,19 @@ Object {
|
|
|
162
227
|
Object {
|
|
163
228
|
"content": Array [
|
|
164
229
|
Object {
|
|
165
|
-
"marks": Array [
|
|
166
|
-
Object {
|
|
167
|
-
"attrs": Object {
|
|
168
|
-
"strike_through": true,
|
|
169
|
-
"underline": true,
|
|
170
|
-
},
|
|
171
|
-
"type": "text_decoration",
|
|
172
|
-
},
|
|
173
|
-
],
|
|
174
230
|
"text": "test",
|
|
175
231
|
"type": "text",
|
|
176
232
|
},
|
|
177
233
|
],
|
|
234
|
+
"marks": Array [
|
|
235
|
+
Object {
|
|
236
|
+
"attrs": Object {
|
|
237
|
+
"strike_through": true,
|
|
238
|
+
"underline": true,
|
|
239
|
+
},
|
|
240
|
+
"type": "text_decoration",
|
|
241
|
+
},
|
|
242
|
+
],
|
|
178
243
|
"type": "paragraph",
|
|
179
244
|
},
|
|
180
245
|
],
|
|
@@ -278,19 +343,19 @@ Object {
|
|
|
278
343
|
Object {
|
|
279
344
|
"content": Array [
|
|
280
345
|
Object {
|
|
281
|
-
"marks": Array [
|
|
282
|
-
Object {
|
|
283
|
-
"attrs": Object {
|
|
284
|
-
"strike_through": true,
|
|
285
|
-
"underline": false,
|
|
286
|
-
},
|
|
287
|
-
"type": "text_decoration",
|
|
288
|
-
},
|
|
289
|
-
],
|
|
290
346
|
"text": "test",
|
|
291
347
|
"type": "text",
|
|
292
348
|
},
|
|
293
349
|
],
|
|
350
|
+
"marks": Array [
|
|
351
|
+
Object {
|
|
352
|
+
"attrs": Object {
|
|
353
|
+
"strike_through": true,
|
|
354
|
+
"underline": false,
|
|
355
|
+
},
|
|
356
|
+
"type": "text_decoration",
|
|
357
|
+
},
|
|
358
|
+
],
|
|
294
359
|
"type": "paragraph",
|
|
295
360
|
},
|
|
296
361
|
],
|
|
@@ -364,19 +429,19 @@ Object {
|
|
|
364
429
|
Object {
|
|
365
430
|
"content": Array [
|
|
366
431
|
Object {
|
|
367
|
-
"marks": Array [
|
|
368
|
-
Object {
|
|
369
|
-
"attrs": Object {
|
|
370
|
-
"strike_through": false,
|
|
371
|
-
"underline": true,
|
|
372
|
-
},
|
|
373
|
-
"type": "text_decoration",
|
|
374
|
-
},
|
|
375
|
-
],
|
|
376
432
|
"text": "test",
|
|
377
433
|
"type": "text",
|
|
378
434
|
},
|
|
379
435
|
],
|
|
436
|
+
"marks": Array [
|
|
437
|
+
Object {
|
|
438
|
+
"attrs": Object {
|
|
439
|
+
"strike_through": false,
|
|
440
|
+
"underline": true,
|
|
441
|
+
},
|
|
442
|
+
"type": "text_decoration",
|
|
443
|
+
},
|
|
444
|
+
],
|
|
380
445
|
"type": "paragraph",
|
|
381
446
|
},
|
|
382
447
|
],
|
|
@@ -463,19 +528,19 @@ Object {
|
|
|
463
528
|
"type": "text",
|
|
464
529
|
},
|
|
465
530
|
Object {
|
|
466
|
-
"marks": Array [
|
|
467
|
-
Object {
|
|
468
|
-
"attrs": Object {
|
|
469
|
-
"strike_through": false,
|
|
470
|
-
"underline": true,
|
|
471
|
-
},
|
|
472
|
-
"type": "text_decoration",
|
|
473
|
-
},
|
|
474
|
-
],
|
|
475
531
|
"text": " ipsum",
|
|
476
532
|
"type": "text",
|
|
477
533
|
},
|
|
478
534
|
],
|
|
535
|
+
"marks": Array [
|
|
536
|
+
Object {
|
|
537
|
+
"attrs": Object {
|
|
538
|
+
"strike_through": false,
|
|
539
|
+
"underline": true,
|
|
540
|
+
},
|
|
541
|
+
"type": "text_decoration",
|
|
542
|
+
},
|
|
543
|
+
],
|
|
479
544
|
"type": "paragraph",
|
|
480
545
|
},
|
|
481
546
|
],
|
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
import { Extension } from '@tiptap/vue-2';
|
|
2
|
-
import { computed, unref } from 'vue';
|
|
3
|
-
import {
|
|
1
|
+
import { Extension, getMarkType } from '@tiptap/vue-2';
|
|
2
|
+
import { computed, toRef, unref } from 'vue';
|
|
3
|
+
import {
|
|
4
|
+
createCommand,
|
|
5
|
+
findMarkByType,
|
|
6
|
+
isMarkAppliedToParent,
|
|
7
|
+
isNodeFullySelected,
|
|
8
|
+
resolveTextPosition
|
|
9
|
+
} from '../../utils';
|
|
4
10
|
import { NodeTypes } from '../../enums';
|
|
11
|
+
import { AddNodeMarkStep } from './steps';
|
|
5
12
|
|
|
6
13
|
export const NodeProcessor = Extension.create({
|
|
7
14
|
name: 'node_processor',
|
|
@@ -26,7 +33,80 @@ export const NodeProcessor = Extension.create({
|
|
|
26
33
|
}
|
|
27
34
|
|
|
28
35
|
return Object.keys(attrs).length ? attrs : null;
|
|
29
|
-
}))
|
|
36
|
+
})),
|
|
37
|
+
|
|
38
|
+
applyMark: createCommand(({ state }, name, value, customizer = {}) => {
|
|
39
|
+
const { tr, doc, schema } = state;
|
|
40
|
+
const { $from, $to } = tr.selection;
|
|
41
|
+
const markType = getMarkType(name, schema);
|
|
42
|
+
|
|
43
|
+
const onAppliedToParent = customizer.onAppliedToParent || ((context) => {
|
|
44
|
+
const { tr, textPosition, applyingMark } = context;
|
|
45
|
+
|
|
46
|
+
tr.removeMark(textPosition.from, textPosition.to, applyingMark.type);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
if ($from.pos === $to.pos) return;
|
|
50
|
+
|
|
51
|
+
doc.nodesBetween($from.pos, $to.pos, (node, position) => {
|
|
52
|
+
if (node.type.name === NodeTypes.LIST) return;
|
|
53
|
+
|
|
54
|
+
const initialMark = findMarkByType(node.marks, name);
|
|
55
|
+
const applyingMark = markType.create({ ...(initialMark?.attrs || {}), ...value });
|
|
56
|
+
const textPosition = resolveTextPosition($from, $to, node, position);
|
|
57
|
+
|
|
58
|
+
if (isMarkAppliedToParent(tr, position, applyingMark, customizer.compareParentMark)) {
|
|
59
|
+
onAppliedToParent({ tr, textPosition, applyingMark, initialMark, node });
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (node.isText) {
|
|
64
|
+
tr.addMark(textPosition.from, textPosition.to, applyingMark);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (isNodeFullySelected($from, $to, node, position)) {
|
|
69
|
+
tr.step(new AddNodeMarkStep(position, applyingMark));
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}),
|
|
73
|
+
|
|
74
|
+
getMarks: createCommand(({ editor }, name) => {
|
|
75
|
+
const stateRef = toRef(editor, 'state');
|
|
76
|
+
|
|
77
|
+
return computed(() => {
|
|
78
|
+
const { selection, doc } = unref(stateRef);
|
|
79
|
+
const { from, to } = unref(selection);
|
|
80
|
+
const marks = [];
|
|
81
|
+
|
|
82
|
+
doc.nodesBetween(from, to, (node) => {
|
|
83
|
+
for (const mark of node.marks) {
|
|
84
|
+
if (mark.type.name === name) marks.unshift(mark.attrs);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
return marks;
|
|
89
|
+
});
|
|
90
|
+
}),
|
|
91
|
+
|
|
92
|
+
getMark: createCommand(({ commands }, name) => {
|
|
93
|
+
const marksRef = commands.getMarks(name);
|
|
94
|
+
|
|
95
|
+
return computed(() => unref(marksRef)[0] ?? null);
|
|
96
|
+
}),
|
|
97
|
+
|
|
98
|
+
getCommonSettingMark: createCommand(({ commands }, name, defaultRef) => {
|
|
99
|
+
const selectionRef = commands.getMark(name);
|
|
100
|
+
|
|
101
|
+
return computed(() => unref(selectionRef)?.value ?? unref(defaultRef));
|
|
102
|
+
}),
|
|
103
|
+
|
|
104
|
+
getDeviceSettingMark: createCommand(({ commands }, name, defaultRef) => {
|
|
105
|
+
const selectionRef = commands.getMark(name);
|
|
106
|
+
const deviceRef = commands.getDevice();
|
|
107
|
+
|
|
108
|
+
return computed(() => unref(selectionRef)?.[unref(deviceRef)] ?? unref(defaultRef));
|
|
109
|
+
})
|
|
30
110
|
};
|
|
31
111
|
}
|
|
32
112
|
});
|