@zipify/wysiwyg 3.1.0-2 → 3.1.1
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 +17 -235
- package/.github/actions/setup/action.yaml +1 -1
- package/README.md +2 -0
- package/config/build/cli.config.js +6 -6
- package/config/build/lib.config.js +5 -3
- package/config/svgo.js +6 -3
- package/dist/cli.js +5 -4
- package/dist/wysiwyg.css +18 -18
- package/dist/wysiwyg.mjs +12502 -11732
- package/example/tooltip/Tooltip.js +92 -69
- package/example/tooltip/modifiers/TooltipCloseOnScrollModifier.js +2 -5
- package/example/tooltip/tooltip.css +8 -31
- package/lib/Wysiwyg.vue +3 -0
- package/lib/cli/commands/ToJsonCommand.js +6 -6
- package/lib/components/base/__tests__/Button.test.js +1 -1
- package/lib/components/base/composables/__tests__/useDeselectionLock.test.js +2 -2
- package/lib/components/base/composables/__tests__/useElementRef.test.js +1 -1
- package/lib/components/base/composables/__tests__/useModalToggler.test.js +0 -2
- package/lib/components/base/composables/__tests__/useValidator.test.js +2 -2
- package/lib/components/base/composables/useModalToggler.js +30 -24
- package/lib/components/toolbar/Toolbar.vue +1 -1
- package/lib/components/toolbar/base/__tests__/ToolbarDivider.test.js +1 -1
- package/lib/components/toolbar/controls/StylePresetControl.vue +1 -1
- package/lib/components/toolbar/controls/__tests__/LineHeightControl.test.js +0 -2
- package/lib/components/toolbar/controls/composables/__tests__/useRecentFonts.test.js +1 -1
- package/lib/components/toolbar/controls/link/composables/__tests__/useLink.test.js +2 -2
- package/lib/composables/useToolbar.js +24 -19
- package/lib/extensions/FontSize.js +1 -2
- package/lib/extensions/Link.js +2 -0
- package/lib/extensions/__tests__/BackgroundColor.test.js +2 -2
- package/lib/extensions/__tests__/FontColor.test.js +3 -3
- package/lib/extensions/__tests__/FontFamily.test.js +3 -3
- package/lib/extensions/__tests__/FontSize.test.js +3 -3
- package/lib/extensions/__tests__/FontWeight.test.js +4 -4
- package/lib/extensions/__tests__/LineHeight.test.js +2 -2
- package/lib/extensions/__tests__/Link.test.js +33 -5
- package/lib/extensions/__tests__/__snapshots__/Link.test.js.snap +27 -0
- package/lib/extensions/core/Document.js +8 -1
- package/lib/extensions/core/NodeProcessor.js +3 -4
- package/lib/extensions/core/__tests__/NodeProcessor.test.js +6 -8
- package/lib/extensions/core/__tests__/TextProcessor.test.js +1 -1
- package/lib/extensions/core/index.js +0 -2
- package/lib/extensions/core/plugins/PlaceholderPlugin.js +2 -2
- package/lib/extensions/list/List.js +4 -5
- package/lib/extensions/list/ListItem.js +1 -2
- package/lib/extensions/list/__tests__/List.test.js +1 -1
- package/lib/models/Font.js +2 -2
- package/lib/models/__tests__/Font.test.js +3 -9
- package/lib/services/ContentSerializer.js +8 -8
- package/lib/services/HtmlToJsonParser.js +3 -3
- package/lib/services/NodeFactory.js +6 -6
- package/lib/services/StylePresetRenderer.js +11 -11
- package/lib/services/__tests__/JsonSerializer.test.js +1 -1
- package/lib/services/__tests__/Storage.test.js +1 -1
- package/lib/services/__tests__/StylePresetRenderer.test.js +1 -1
- package/lib/services/normalizer/BrowserDomParser.js +2 -2
- package/lib/services/normalizer/ContentNormalizer.js +3 -3
- package/lib/services/normalizer/HtmlNormalizer.js +52 -52
- package/lib/services/normalizer/JsonNormalizer.js +21 -21
- package/lib/utils/__tests__/convertAlignment.test.js +1 -1
- package/lib/utils/__tests__/renderInlineSetting.test.js +2 -2
- package/package.json +50 -48
- package/lib/extensions/core/steps/AddNodeMarkStep.js +0 -66
- package/lib/extensions/core/steps/AttrStep.js +0 -60
- package/lib/extensions/core/steps/RemoveNodeMarkStep.js +0 -56
- package/lib/extensions/core/steps/index.js +0 -3
|
@@ -46,7 +46,7 @@ export class NodeFactory {
|
|
|
46
46
|
* }}
|
|
47
47
|
*/
|
|
48
48
|
static listItem(...args) {
|
|
49
|
-
const { attrs, content: children, marks } = this
|
|
49
|
+
const { attrs, content: children, marks } = this._normalizeTextBlockArgs(args);
|
|
50
50
|
|
|
51
51
|
return {
|
|
52
52
|
type: NodeTypes.LIST_ITEM,
|
|
@@ -66,7 +66,7 @@ export class NodeFactory {
|
|
|
66
66
|
* }}
|
|
67
67
|
*/
|
|
68
68
|
static heading(level, ...args) {
|
|
69
|
-
const config = this
|
|
69
|
+
const config = this._textBlock(args, this.text);
|
|
70
70
|
|
|
71
71
|
config.attrs ??= {};
|
|
72
72
|
config.attrs.level = level;
|
|
@@ -84,12 +84,12 @@ export class NodeFactory {
|
|
|
84
84
|
static paragraph(...args) {
|
|
85
85
|
return {
|
|
86
86
|
type: NodeTypes.PARAGRAPH,
|
|
87
|
-
...this
|
|
87
|
+
...this._textBlock(args, this.text)
|
|
88
88
|
};
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
static
|
|
92
|
-
const { attrs, content, marks } = this
|
|
91
|
+
static _textBlock(args) {
|
|
92
|
+
const { attrs, content, marks } = this._normalizeTextBlockArgs(args);
|
|
93
93
|
const children = typeof content === 'string' ? [this.text(content)] : content;
|
|
94
94
|
|
|
95
95
|
return {
|
|
@@ -99,7 +99,7 @@ export class NodeFactory {
|
|
|
99
99
|
};
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
static
|
|
102
|
+
static _normalizeTextBlockArgs(args) {
|
|
103
103
|
if (args.length === 1) {
|
|
104
104
|
return { attrs: null, marks: null, content: args[0] };
|
|
105
105
|
}
|
|
@@ -2,14 +2,14 @@ import { Devices } from '../enums';
|
|
|
2
2
|
import { ContextWindow } from './ContextWindow';
|
|
3
3
|
|
|
4
4
|
export class StylePresetRenderer {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
_baseClass;
|
|
6
|
+
_makeVariable;
|
|
7
|
+
_linkPresetId;
|
|
8
8
|
|
|
9
9
|
constructor({ baseClass, makeVariable, linkPresetId }) {
|
|
10
|
-
this
|
|
11
|
-
this
|
|
12
|
-
this
|
|
10
|
+
this._baseClass = baseClass;
|
|
11
|
+
this._makeVariable = makeVariable;
|
|
12
|
+
this._linkPresetId = linkPresetId;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
inject(hostEl, presets) {
|
|
@@ -28,15 +28,15 @@ export class StylePresetRenderer {
|
|
|
28
28
|
let css = '';
|
|
29
29
|
|
|
30
30
|
for (const preset of presets) {
|
|
31
|
-
const isLink = preset.id === this
|
|
31
|
+
const isLink = preset.id === this._linkPresetId;
|
|
32
32
|
const className = this.makePresetCssClass(preset);
|
|
33
33
|
|
|
34
34
|
css += ` ${className} {`;
|
|
35
35
|
|
|
36
36
|
for (const device of Devices.values) {
|
|
37
37
|
for (const setting of Object.keys(preset[device])) {
|
|
38
|
-
const variable = this
|
|
39
|
-
const internalVariable = this
|
|
38
|
+
const variable = this._makeVariable({ device, preset, property: setting });
|
|
39
|
+
const internalVariable = this._makeInternalVariableName(setting, device);
|
|
40
40
|
|
|
41
41
|
css += `${internalVariable}: var(${variable}, inherit);`;
|
|
42
42
|
|
|
@@ -56,7 +56,7 @@ export class StylePresetRenderer {
|
|
|
56
56
|
return css;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
_makeInternalVariableName(setting, device) {
|
|
60
60
|
const property = setting === 'color' ? 'font-color' : setting.replace(/_/i, '-');
|
|
61
61
|
const prefix = device === Devices.COMMON ? '' : `-${device}`;
|
|
62
62
|
|
|
@@ -64,7 +64,7 @@ export class StylePresetRenderer {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
makePresetHtmlClass(preset) {
|
|
67
|
-
return this
|
|
67
|
+
return this._baseClass + preset.id;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
makePresetCssClass(preset) {
|
|
@@ -51,7 +51,7 @@ describe('inject styles', () => {
|
|
|
51
51
|
renderer.inject(host, presets);
|
|
52
52
|
renderer.inject(host, presets);
|
|
53
53
|
|
|
54
|
-
expect(host.querySelectorAll('[data-zw-styles]')
|
|
54
|
+
expect(host.querySelectorAll('[data-zw-styles]')).toHaveLength(1);
|
|
55
55
|
});
|
|
56
56
|
});
|
|
57
57
|
|
|
@@ -4,17 +4,17 @@ import { JsonNormalizer } from './JsonNormalizer';
|
|
|
4
4
|
|
|
5
5
|
export class ContentNormalizer {
|
|
6
6
|
static build(content, options = {}) {
|
|
7
|
-
return typeof content === 'string' ? this
|
|
7
|
+
return typeof content === 'string' ? this._buildHtml(content, options) : this._buildJson(content);
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
static
|
|
10
|
+
static _buildHtml(content, options) {
|
|
11
11
|
return new HtmlNormalizer({
|
|
12
12
|
content,
|
|
13
13
|
parser: options.parser || new BrowserDomParser()
|
|
14
14
|
});
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
static
|
|
17
|
+
static _buildJson(content) {
|
|
18
18
|
return new JsonNormalizer({ content });
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -14,11 +14,11 @@ export class HtmlNormalizer extends BaseNormalizer {
|
|
|
14
14
|
'margin-right'
|
|
15
15
|
];
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
_parser;
|
|
18
18
|
|
|
19
19
|
constructor({ content, parser }) {
|
|
20
20
|
super({ content });
|
|
21
|
-
this
|
|
21
|
+
this._parser = parser;
|
|
22
22
|
this.dom = null;
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -28,42 +28,42 @@ export class HtmlNormalizer extends BaseNormalizer {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
normalizeHTML() {
|
|
31
|
-
this.dom = this
|
|
32
|
-
|
|
33
|
-
this
|
|
34
|
-
this
|
|
35
|
-
this
|
|
36
|
-
this
|
|
37
|
-
this
|
|
38
|
-
this
|
|
39
|
-
this
|
|
31
|
+
this.dom = this._parser.parse(this.content.replace(/(\r)?\n/g, ''));
|
|
32
|
+
|
|
33
|
+
this._removeComments();
|
|
34
|
+
this._normalizeRootTags();
|
|
35
|
+
this._iterateNodes(this._normalizeBreakLines, (node) => node.tagName === 'BR');
|
|
36
|
+
this._iterateNodes(this._removeEmptyNodes, this._isBlockNode);
|
|
37
|
+
this._iterateNodes(this._normalizeListItems, (node) => node.tagName === 'LI');
|
|
38
|
+
this._normalizeBlockTextDecoration();
|
|
39
|
+
this._normalizeBlockBackgroundColor();
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
get normalizedHTML() {
|
|
43
43
|
return this.dom.body.innerHTML;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
get
|
|
47
|
-
return this
|
|
46
|
+
get _NodeFilter() {
|
|
47
|
+
return this._parser.types.NodeFilter;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
get
|
|
51
|
-
return this
|
|
50
|
+
get _Node() {
|
|
51
|
+
return this._parser.types.Node;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
const iterator = this
|
|
54
|
+
_removeComments() {
|
|
55
|
+
const iterator = this._createNodeIterator(this._NodeFilter.SHOW_COMMENT);
|
|
56
56
|
|
|
57
|
-
this
|
|
57
|
+
this._runIterator(iterator, (node) => node.remove());
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
_normalizeRootTags() {
|
|
61
61
|
const children = Array.from(this.dom.body.childNodes);
|
|
62
62
|
const fragment = this.dom.createDocumentFragment();
|
|
63
63
|
let capturingParagraph;
|
|
64
64
|
|
|
65
65
|
for (const node of children) {
|
|
66
|
-
if (this
|
|
66
|
+
if (this._isRootNode(node)) {
|
|
67
67
|
fragment.append(node);
|
|
68
68
|
capturingParagraph = null;
|
|
69
69
|
continue;
|
|
@@ -81,21 +81,21 @@ export class HtmlNormalizer extends BaseNormalizer {
|
|
|
81
81
|
this.dom.body.append(fragment);
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+
_createNodeIterator(whatToShow, filter) {
|
|
85
85
|
return this.dom.createNodeIterator(this.dom.body, whatToShow, filter);
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
|
|
88
|
+
_iterateNodes(handler, condition = () => true) {
|
|
89
89
|
const checkCondition = (node) => node.tagName !== 'BODY' && condition.call(this, node);
|
|
90
90
|
|
|
91
|
-
const iterator = this
|
|
92
|
-
acceptNode: (node) => checkCondition(node) ? this
|
|
91
|
+
const iterator = this._createNodeIterator(this._NodeFilter.SHOW_ELEMENT, {
|
|
92
|
+
acceptNode: (node) => checkCondition(node) ? this._NodeFilter.FILTER_ACCEPT : this._NodeFilter.FILTER_REJECT
|
|
93
93
|
});
|
|
94
94
|
|
|
95
|
-
this
|
|
95
|
+
this._runIterator(iterator, handler);
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
|
|
98
|
+
_runIterator(iterator, handler) {
|
|
99
99
|
let currentNode = iterator.nextNode();
|
|
100
100
|
|
|
101
101
|
while (currentNode) {
|
|
@@ -104,24 +104,24 @@ export class HtmlNormalizer extends BaseNormalizer {
|
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
|
|
107
|
+
_removeEmptyNodes(node) {
|
|
108
108
|
if (!node.innerHTML.trim()) node.remove();
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
|
|
111
|
+
_normalizeListItems(itemEl) {
|
|
112
112
|
const fragment = this.dom.createDocumentFragment();
|
|
113
113
|
const children = Array.from(itemEl.childNodes);
|
|
114
114
|
let capturingParagraph, previousNode;
|
|
115
115
|
|
|
116
116
|
const append = (node) => {
|
|
117
|
-
this
|
|
117
|
+
this._assignElementProperties(node, itemEl, HtmlNormalizer.BLOCK_STYLES);
|
|
118
118
|
fragment.append(node);
|
|
119
119
|
};
|
|
120
120
|
|
|
121
|
-
this
|
|
121
|
+
this._assignElementProperties(itemEl, itemEl.parentElement, HtmlNormalizer.BLOCK_STYLES);
|
|
122
122
|
|
|
123
123
|
for (const node of children) {
|
|
124
|
-
if (this
|
|
124
|
+
if (this._isBlockNode(node)) {
|
|
125
125
|
append(node);
|
|
126
126
|
capturingParagraph = null;
|
|
127
127
|
previousNode = node;
|
|
@@ -154,18 +154,18 @@ export class HtmlNormalizer extends BaseNormalizer {
|
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
itemEl.append(fragment);
|
|
157
|
-
this
|
|
157
|
+
this._removeStyleProperties(itemEl, HtmlNormalizer.BLOCK_STYLES);
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
-
|
|
160
|
+
_isBlockNode(node) {
|
|
161
161
|
return HtmlNormalizer.BLOCK_NODE_NAMES.includes(node.tagName);
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
-
|
|
164
|
+
_isRootNode(node) {
|
|
165
165
|
return HtmlNormalizer.ROOT_NODE_NAMES.includes(node.tagName);
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
-
|
|
168
|
+
_assignElementProperties(target, source, properties) {
|
|
169
169
|
for (const property of properties) {
|
|
170
170
|
const value = source.style.getPropertyValue(property);
|
|
171
171
|
|
|
@@ -175,7 +175,7 @@ export class HtmlNormalizer extends BaseNormalizer {
|
|
|
175
175
|
}
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
-
|
|
178
|
+
_removeStyleProperties(element, properties) {
|
|
179
179
|
for (const property of properties) {
|
|
180
180
|
element.style.removeProperty(property);
|
|
181
181
|
}
|
|
@@ -185,8 +185,8 @@ export class HtmlNormalizer extends BaseNormalizer {
|
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
187
|
|
|
188
|
-
|
|
189
|
-
if (!this
|
|
188
|
+
_normalizeBreakLines({ parentElement }) {
|
|
189
|
+
if (!this._isBlockNode(parentElement)) return;
|
|
190
190
|
if (!parentElement.textContent) return;
|
|
191
191
|
|
|
192
192
|
const fragment = this.dom.createDocumentFragment();
|
|
@@ -197,7 +197,7 @@ export class HtmlNormalizer extends BaseNormalizer {
|
|
|
197
197
|
let capturingParagraph = parentTemplate.cloneNode();
|
|
198
198
|
|
|
199
199
|
const append = (node) => {
|
|
200
|
-
this
|
|
200
|
+
this._assignElementProperties(node, parentElement, HtmlNormalizer.BLOCK_STYLES);
|
|
201
201
|
fragment.append(node);
|
|
202
202
|
};
|
|
203
203
|
|
|
@@ -215,16 +215,16 @@ export class HtmlNormalizer extends BaseNormalizer {
|
|
|
215
215
|
parentElement.replaceWith(fragment);
|
|
216
216
|
}
|
|
217
217
|
|
|
218
|
-
|
|
218
|
+
_normalizeBlockTextDecoration() {
|
|
219
219
|
const blockEls = this.dom.querySelectorAll('[style*="text-decoration"]:where(p, h1, h2, h3, h4, li)');
|
|
220
220
|
|
|
221
221
|
for (const blockEl of blockEls) {
|
|
222
|
-
this
|
|
222
|
+
this._moveTextDecorationToChildren(blockEl);
|
|
223
223
|
}
|
|
224
224
|
}
|
|
225
225
|
|
|
226
|
-
|
|
227
|
-
const blockDecoration = this
|
|
226
|
+
_moveTextDecorationToChildren(blockEl) {
|
|
227
|
+
const blockDecoration = this._parseTextDecoration(blockEl);
|
|
228
228
|
|
|
229
229
|
blockEl.style.removeProperty('text-decoration-line');
|
|
230
230
|
blockEl.style.removeProperty('text-decoration');
|
|
@@ -233,8 +233,8 @@ export class HtmlNormalizer extends BaseNormalizer {
|
|
|
233
233
|
if (blockDecoration.none) return;
|
|
234
234
|
|
|
235
235
|
for (const childNode of blockEl.childNodes) {
|
|
236
|
-
const textEl = this
|
|
237
|
-
const textDecoration = this
|
|
236
|
+
const textEl = this._wrapTextNode(blockEl, childNode);
|
|
237
|
+
const textDecoration = this._parseTextDecoration(textEl);
|
|
238
238
|
|
|
239
239
|
const mergedDecoration = {
|
|
240
240
|
underline: textDecoration.underline || blockDecoration.underline,
|
|
@@ -251,7 +251,7 @@ export class HtmlNormalizer extends BaseNormalizer {
|
|
|
251
251
|
}
|
|
252
252
|
}
|
|
253
253
|
|
|
254
|
-
|
|
254
|
+
_parseTextDecoration(element) {
|
|
255
255
|
const { textDecoration, textDecorationLine } = element.style;
|
|
256
256
|
const decoration = textDecoration || textDecorationLine || '';
|
|
257
257
|
|
|
@@ -262,30 +262,30 @@ export class HtmlNormalizer extends BaseNormalizer {
|
|
|
262
262
|
};
|
|
263
263
|
}
|
|
264
264
|
|
|
265
|
-
|
|
265
|
+
_normalizeBlockBackgroundColor() {
|
|
266
266
|
const blockEls = this.dom.querySelectorAll('[style*="background-color"]:where(p, h1, h2, h3, h4, li)');
|
|
267
267
|
|
|
268
268
|
for (const blockEl of blockEls) {
|
|
269
|
-
this
|
|
269
|
+
this._moveBackgroundColorToChildren(blockEl);
|
|
270
270
|
}
|
|
271
271
|
}
|
|
272
272
|
|
|
273
|
-
|
|
273
|
+
_moveBackgroundColorToChildren(blockEl) {
|
|
274
274
|
const blockColor = blockEl.style.backgroundColor;
|
|
275
275
|
|
|
276
276
|
blockEl.style.removeProperty('background-color');
|
|
277
277
|
if (!blockEl.style.cssText) blockEl.removeAttribute('style');
|
|
278
278
|
|
|
279
279
|
for (const childNode of blockEl.childNodes) {
|
|
280
|
-
const textEl = this
|
|
280
|
+
const textEl = this._wrapTextNode(blockEl, childNode);
|
|
281
281
|
const color = textEl.style.backgroundColor || blockColor;
|
|
282
282
|
|
|
283
283
|
textEl.style.backgroundColor = color;
|
|
284
284
|
}
|
|
285
285
|
}
|
|
286
286
|
|
|
287
|
-
|
|
288
|
-
if (node.nodeType !== this
|
|
287
|
+
_wrapTextNode(parent, node) {
|
|
288
|
+
if (node.nodeType !== this._Node.TEXT_NODE) return node;
|
|
289
289
|
|
|
290
290
|
const span = this.dom.createElement('span');
|
|
291
291
|
|
|
@@ -4,22 +4,22 @@ import { BaseNormalizer } from './BaseNormalizer';
|
|
|
4
4
|
|
|
5
5
|
export class JsonNormalizer extends BaseNormalizer {
|
|
6
6
|
normalize() {
|
|
7
|
-
this
|
|
7
|
+
this._iterateNodes(this._bubbleMarks);
|
|
8
8
|
return this.content;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
this
|
|
11
|
+
_iterateNodes(handler) {
|
|
12
|
+
this._iterateChildNodes(this.content, handler);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
_iterateChildNodes(node, handler) {
|
|
16
16
|
for (const child of node.content) {
|
|
17
|
-
child.content && this
|
|
17
|
+
child.content && this._iterateChildNodes(child, handler);
|
|
18
18
|
handler.call(this, child);
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
_bubbleMarks(node) {
|
|
23
23
|
if (!node.content) return;
|
|
24
24
|
if (node.type === NodeTypes.LIST) return;
|
|
25
25
|
|
|
@@ -27,56 +27,56 @@ export class JsonNormalizer extends BaseNormalizer {
|
|
|
27
27
|
if (!child.marks) continue;
|
|
28
28
|
|
|
29
29
|
for (const childMark of child.marks.slice()) {
|
|
30
|
-
if (this
|
|
31
|
-
this
|
|
30
|
+
if (this._includesMark(node, childMark)) {
|
|
31
|
+
this._removeMark(child, childMark);
|
|
32
32
|
continue;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
if (this
|
|
36
|
-
this
|
|
37
|
-
this
|
|
35
|
+
if (this._canBubbleMark(node, childMark)) {
|
|
36
|
+
this._removeMark(child, childMark);
|
|
37
|
+
this._addMark(node, childMark);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
_canBubbleMark(node, childMark) {
|
|
44
44
|
if (TextSettings.inlineMarks.includes(childMark.type)) return false;
|
|
45
|
-
if (this
|
|
45
|
+
if (this._includesMarkType(node, childMark.type)) return false;
|
|
46
46
|
|
|
47
47
|
for (const child of node.content) {
|
|
48
48
|
if (!child.content && node.type === NodeTypes.LIST_ITEM) continue;
|
|
49
49
|
if (!child.marks) return false;
|
|
50
|
-
if (!this
|
|
50
|
+
if (!this._includesMark(child, childMark)) return false;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
return true;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
_includesMark(node, checkingMark) {
|
|
57
57
|
return node.marks?.some((mark) => isEqual(mark, checkingMark)) ?? false;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
_includesMarkType(node, type) {
|
|
61
61
|
return node.marks?.some((mark) => mark.type === type) ?? false;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
_removeMark(node, mark) {
|
|
65
65
|
if (!node.marks) return;
|
|
66
66
|
|
|
67
|
-
const index = this
|
|
67
|
+
const index = this._findMarkIndexByType(node, mark.type);
|
|
68
68
|
|
|
69
69
|
if (index >= 0) node.marks.splice(index, 1);
|
|
70
70
|
if (!node.marks.length) delete node.marks;
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
|
|
74
|
-
this
|
|
73
|
+
_addMark(node, mark) {
|
|
74
|
+
this._removeMark(node, mark);
|
|
75
75
|
node.marks ??= [];
|
|
76
76
|
node.marks.push(mark);
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
|
|
79
|
+
_findMarkIndexByType(node, type) {
|
|
80
80
|
return node.marks?.findIndex((mark) => mark.type === type) ?? null;
|
|
81
81
|
}
|
|
82
82
|
}
|
|
@@ -50,7 +50,7 @@ describe('render settings', () => {
|
|
|
50
50
|
test('should return null if no styles', () => {
|
|
51
51
|
const result = renderInlineSetting({});
|
|
52
52
|
|
|
53
|
-
expect(result).
|
|
53
|
+
expect(result).toBeNull();
|
|
54
54
|
});
|
|
55
55
|
|
|
56
56
|
test('should return null if all styles empty', () => {
|
|
@@ -60,6 +60,6 @@ describe('render settings', () => {
|
|
|
60
60
|
desktop_font_size: null
|
|
61
61
|
});
|
|
62
62
|
|
|
63
|
-
expect(result).
|
|
63
|
+
expect(result).toBeNull();
|
|
64
64
|
});
|
|
65
65
|
});
|