@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
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
isNodeFullySelected,
|
|
8
8
|
resolveTextPosition
|
|
9
9
|
} from '../../utils';
|
|
10
|
-
import { NodeTypes } from '../../enums';
|
|
10
|
+
import { MarkGroups, NodeTypes } from '../../enums';
|
|
11
11
|
import { AddNodeMarkStep, AttrStep, RemoveNodeMarkStep } from './steps';
|
|
12
12
|
|
|
13
13
|
export const NodeProcessor = Extension.create({
|
|
@@ -18,8 +18,7 @@ export const NodeProcessor = Extension.create({
|
|
|
18
18
|
setBlockAttributes: createCommand(({ commands, state }, name, attrs, defaults = {}) => {
|
|
19
19
|
const current = unref(commands.getBlockAttributes(name)) ?? {};
|
|
20
20
|
const { doc, tr } = state;
|
|
21
|
-
const {
|
|
22
|
-
const { from, to } = selection;
|
|
21
|
+
const { from, to } = tr.selection;
|
|
23
22
|
|
|
24
23
|
doc.nodesBetween(from, to, (node, position) => {
|
|
25
24
|
if (!NodeTypes.blocks.includes(node.type.name)) return;
|
|
@@ -44,7 +43,7 @@ export const NodeProcessor = Extension.create({
|
|
|
44
43
|
const markType = getMarkType(name, schema);
|
|
45
44
|
const markGroup = markType.spec.group || '';
|
|
46
45
|
|
|
47
|
-
if (!markGroup.includes(
|
|
46
|
+
if (!markGroup.includes(MarkGroups.SETTINGS)) {
|
|
48
47
|
// Apply inline mark if block level not supported
|
|
49
48
|
return commands.setMark(name, value);
|
|
50
49
|
}
|
|
@@ -58,9 +57,8 @@ export const NodeProcessor = Extension.create({
|
|
|
58
57
|
const applyingMark = markType.create({ ...(initialMark?.attrs || {}), ...value });
|
|
59
58
|
const textPosition = resolveTextPosition($from, $to, node, position);
|
|
60
59
|
|
|
61
|
-
if (isMarkAppliedToParent(tr, position, applyingMark)) {
|
|
62
|
-
|
|
63
|
-
return;
|
|
60
|
+
if (isMarkAppliedToParent(tr.doc, position, applyingMark)) {
|
|
61
|
+
return commands._removeNodeMark({ tr, node, position, mark: markType });
|
|
64
62
|
}
|
|
65
63
|
|
|
66
64
|
if (node.isText) {
|
|
@@ -68,7 +66,7 @@ export const NodeProcessor = Extension.create({
|
|
|
68
66
|
return;
|
|
69
67
|
}
|
|
70
68
|
|
|
71
|
-
if (isNodeFullySelected(
|
|
69
|
+
if (isNodeFullySelected(tr.doc, tr.selection, node, position)) {
|
|
72
70
|
tr.step(new AddNodeMarkStep(position, applyingMark));
|
|
73
71
|
}
|
|
74
72
|
});
|
|
@@ -105,29 +103,52 @@ export const NodeProcessor = Extension.create({
|
|
|
105
103
|
}),
|
|
106
104
|
|
|
107
105
|
getDeviceSettingMark: createCommand(({ commands }, name, defaultRef) => {
|
|
108
|
-
const selectionRef = commands.
|
|
106
|
+
const selectionRef = commands.getMarks(name);
|
|
109
107
|
const deviceRef = commands.getDevice();
|
|
110
108
|
|
|
111
|
-
return computed(() =>
|
|
109
|
+
return computed(() => {
|
|
110
|
+
for (const attrs of unref(selectionRef)) {
|
|
111
|
+
const value = attrs[unref(deviceRef)];
|
|
112
|
+
|
|
113
|
+
if (value) return value;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return unref(defaultRef);
|
|
117
|
+
});
|
|
112
118
|
}),
|
|
113
119
|
|
|
114
|
-
|
|
115
|
-
const { tr,
|
|
116
|
-
const {
|
|
120
|
+
removeAllMarks: createCommand(({ state, commands }) => {
|
|
121
|
+
const { tr, doc } = state;
|
|
122
|
+
const { from, to } = tr.selection;
|
|
117
123
|
|
|
118
|
-
|
|
124
|
+
doc.nodesBetween(from, to, (node, position) => {
|
|
125
|
+
for (const mark of node.marks) {
|
|
126
|
+
commands._removeNodeMark({ tr, node, position, mark });
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}),
|
|
119
130
|
|
|
120
|
-
|
|
121
|
-
|
|
131
|
+
removeMarks: createCommand(({ state, commands }, marks) => {
|
|
132
|
+
const { tr, doc } = state;
|
|
133
|
+
const { from, to } = tr.selection;
|
|
122
134
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
: tr.step(new RemoveNodeMarkStep(position, mark));
|
|
135
|
+
doc.nodesBetween(from, to, (node, position) => {
|
|
136
|
+
const removingMarks = node.marks.filter((mark) => marks.includes(mark.type.name));
|
|
126
137
|
|
|
127
|
-
for (const mark of
|
|
128
|
-
|
|
138
|
+
for (const mark of removingMarks) {
|
|
139
|
+
commands._removeNodeMark({ tr, node, position, mark });
|
|
129
140
|
}
|
|
130
141
|
});
|
|
142
|
+
}),
|
|
143
|
+
|
|
144
|
+
removeMark: createCommand(({ commands, state }, node, position, mark) => {
|
|
145
|
+
commands._removeNodeMark({ tr: state.tr, node, position, mark });
|
|
146
|
+
}),
|
|
147
|
+
|
|
148
|
+
_removeNodeMark: createCommand((context, { tr, node, position, mark }) => {
|
|
149
|
+
return node.isText
|
|
150
|
+
? tr.removeMark(position, position + node.nodeSize, mark)
|
|
151
|
+
: tr.step(new RemoveNodeMarkStep(position, mark));
|
|
131
152
|
})
|
|
132
153
|
};
|
|
133
154
|
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import { ref } from 'vue';
|
|
1
2
|
import { Editor, Extension, Mark } from '@tiptap/vue-2';
|
|
2
3
|
import { buildTestExtensions } from '../../../__tests__/utils';
|
|
3
|
-
import { NodeTypes, TextSettings } from '../../../enums';
|
|
4
|
+
import { Devices, ListTypes, MarkGroups, NodeTypes, TextSettings } from '../../../enums';
|
|
4
5
|
import { ContentNormalizer, NodeFactory } from '../../../services';
|
|
6
|
+
import { createCommand } from '../../../utils';
|
|
7
|
+
import { List } from '../../list';
|
|
5
8
|
|
|
6
9
|
const MockLineHeight = Extension.create({
|
|
7
10
|
name: TextSettings.LINE_HEIGHT,
|
|
@@ -19,18 +22,59 @@ const MockLineHeight = Extension.create({
|
|
|
19
22
|
]
|
|
20
23
|
});
|
|
21
24
|
|
|
25
|
+
const MockTextDecoration = Mark.create({
|
|
26
|
+
name: TextSettings.TEXT_DECORATION,
|
|
27
|
+
renderHTML: () => ['span', {}, 0],
|
|
28
|
+
|
|
29
|
+
addAttributes: () => ({
|
|
30
|
+
underline: { default: false },
|
|
31
|
+
strike_through: { default: false }
|
|
32
|
+
})
|
|
33
|
+
});
|
|
34
|
+
|
|
22
35
|
const MockFontWeight = Mark.create({
|
|
23
36
|
name: TextSettings.FONT_WEIGHT,
|
|
24
|
-
group:
|
|
37
|
+
group: MarkGroups.SETTINGS,
|
|
25
38
|
renderHTML: () => ['span', {}, 0],
|
|
26
39
|
addAttributes: () => ({ value: { required: true } })
|
|
27
40
|
});
|
|
28
41
|
|
|
29
|
-
|
|
42
|
+
const MockFontSize = Mark.create({
|
|
43
|
+
name: TextSettings.FONT_SIZE,
|
|
44
|
+
group: MarkGroups.SETTINGS,
|
|
45
|
+
renderHTML: () => ['span', {}, 0],
|
|
46
|
+
|
|
47
|
+
addAttributes: () => ({
|
|
48
|
+
mobile: { default: null },
|
|
49
|
+
tablet: { default: null },
|
|
50
|
+
desktop: { default: null }
|
|
51
|
+
})
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const DeviceManager = Extension.create({
|
|
55
|
+
name: 'device_manager',
|
|
56
|
+
|
|
57
|
+
addOptions: () => ({
|
|
58
|
+
device: { required: true }
|
|
59
|
+
}),
|
|
60
|
+
|
|
61
|
+
addCommands() {
|
|
62
|
+
return { getDevice: createCommand(() => ref(this.options.device)) };
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
function createEditor({ content, device }) {
|
|
30
67
|
return new Editor({
|
|
31
68
|
content: ContentNormalizer.normalize(content),
|
|
32
69
|
extensions: buildTestExtensions({
|
|
33
|
-
include: [
|
|
70
|
+
include: [
|
|
71
|
+
MockLineHeight,
|
|
72
|
+
MockFontWeight,
|
|
73
|
+
MockFontSize,
|
|
74
|
+
MockTextDecoration,
|
|
75
|
+
List.configure({ baseClass: 'zw-list--' }),
|
|
76
|
+
DeviceManager.configure({ device: device ?? Devices.DESKTOP })
|
|
77
|
+
]
|
|
34
78
|
})
|
|
35
79
|
});
|
|
36
80
|
}
|
|
@@ -54,7 +98,7 @@ describe('block attributes', () => {
|
|
|
54
98
|
line_height: { mobile: '1.2' }
|
|
55
99
|
})
|
|
56
100
|
});
|
|
57
|
-
const attrs = editor.commands.getBlockAttributes(
|
|
101
|
+
const attrs = editor.commands.getBlockAttributes(TextSettings.LINE_HEIGHT);
|
|
58
102
|
|
|
59
103
|
expect(attrs.value).toEqual({ mobile: '1.2' });
|
|
60
104
|
});
|
|
@@ -65,7 +109,7 @@ describe('block attributes', () => {
|
|
|
65
109
|
line_height: { mobile: '1.2' }
|
|
66
110
|
})
|
|
67
111
|
});
|
|
68
|
-
const attrs = editor.commands.getBlockAttributes(
|
|
112
|
+
const attrs = editor.commands.getBlockAttributes(TextSettings.LINE_HEIGHT, DEFAULTS);
|
|
69
113
|
|
|
70
114
|
expect(attrs.value).toEqual({
|
|
71
115
|
mobile: '1.2',
|
|
@@ -78,7 +122,7 @@ describe('block attributes', () => {
|
|
|
78
122
|
const editor = createEditor({
|
|
79
123
|
content: createContent({ line_height: null })
|
|
80
124
|
});
|
|
81
|
-
const attrs = editor.commands.getBlockAttributes(
|
|
125
|
+
const attrs = editor.commands.getBlockAttributes(TextSettings.LINE_HEIGHT);
|
|
82
126
|
|
|
83
127
|
expect(attrs.value).toEqual(null);
|
|
84
128
|
});
|
|
@@ -89,7 +133,7 @@ describe('block attributes', () => {
|
|
|
89
133
|
});
|
|
90
134
|
|
|
91
135
|
editor.commands.selectAll();
|
|
92
|
-
editor.commands.setBlockAttributes(
|
|
136
|
+
editor.commands.setBlockAttributes(TextSettings.LINE_HEIGHT, { mobile: '1.3' });
|
|
93
137
|
|
|
94
138
|
expect(editor.getJSON()).toMatchSnapshot();
|
|
95
139
|
});
|
|
@@ -100,7 +144,7 @@ describe('block attributes', () => {
|
|
|
100
144
|
});
|
|
101
145
|
|
|
102
146
|
editor.commands.selectAll();
|
|
103
|
-
editor.commands.setBlockAttributes(
|
|
147
|
+
editor.commands.setBlockAttributes(TextSettings.LINE_HEIGHT, { mobile: '1.3' }, DEFAULTS);
|
|
104
148
|
|
|
105
149
|
expect(editor.getJSON()).toMatchSnapshot();
|
|
106
150
|
});
|
|
@@ -113,7 +157,7 @@ describe('block attributes', () => {
|
|
|
113
157
|
});
|
|
114
158
|
|
|
115
159
|
editor.commands.selectAll();
|
|
116
|
-
editor.commands.setBlockAttributes(
|
|
160
|
+
editor.commands.setBlockAttributes(TextSettings.LINE_HEIGHT, { mobile: '1.3' });
|
|
117
161
|
|
|
118
162
|
expect(editor.getJSON()).toMatchSnapshot();
|
|
119
163
|
});
|
|
@@ -126,7 +170,7 @@ describe('block attributes', () => {
|
|
|
126
170
|
});
|
|
127
171
|
|
|
128
172
|
editor.commands.selectAll();
|
|
129
|
-
editor.commands.setBlockAttributes(
|
|
173
|
+
editor.commands.setBlockAttributes(TextSettings.LINE_HEIGHT, { mobile: '1.3' }, DEFAULTS);
|
|
130
174
|
|
|
131
175
|
expect(editor.getJSON()).toMatchSnapshot();
|
|
132
176
|
});
|
|
@@ -191,6 +235,260 @@ describe('apply mark', () => {
|
|
|
191
235
|
});
|
|
192
236
|
});
|
|
193
237
|
|
|
238
|
+
describe('apply mark', () => {
|
|
239
|
+
test('should apply inline mark', () => {
|
|
240
|
+
const editor = createEditor({
|
|
241
|
+
content: NodeFactory.doc([
|
|
242
|
+
NodeFactory.paragraph('lorem ipsum')
|
|
243
|
+
])
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
editor.commands.selectAll();
|
|
247
|
+
editor.commands.applyMark(TextSettings.TEXT_DECORATION, { underline: true });
|
|
248
|
+
|
|
249
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
test('should apply mark to part of text', () => {
|
|
253
|
+
const editor = createEditor({
|
|
254
|
+
content: NodeFactory.doc([
|
|
255
|
+
NodeFactory.paragraph('lorem ipsum')
|
|
256
|
+
])
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
editor.commands.setTextSelection({ from: 1, to: 6 });
|
|
260
|
+
editor.commands.applyMark(TextSettings.FONT_WEIGHT, { value: '700' });
|
|
261
|
+
|
|
262
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
test('should apply mark to paragraph', () => {
|
|
266
|
+
const editor = createEditor({
|
|
267
|
+
content: NodeFactory.doc([
|
|
268
|
+
NodeFactory.paragraph('lorem ipsum')
|
|
269
|
+
])
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
editor.commands.selectAll();
|
|
273
|
+
editor.commands.applyMark(TextSettings.FONT_WEIGHT, { value: '700' });
|
|
274
|
+
|
|
275
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
test('should remove text mark on applying to paragraph', () => {
|
|
279
|
+
const editor = createEditor({
|
|
280
|
+
content: NodeFactory.doc([
|
|
281
|
+
NodeFactory.paragraph([
|
|
282
|
+
NodeFactory.text('lorem', [
|
|
283
|
+
NodeFactory.mark(TextSettings.FONT_WEIGHT, { value: '400' })
|
|
284
|
+
]),
|
|
285
|
+
NodeFactory.text(' ipsum')
|
|
286
|
+
])
|
|
287
|
+
])
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
editor.commands.selectAll();
|
|
291
|
+
editor.commands.applyMark(TextSettings.FONT_WEIGHT, { value: '700' });
|
|
292
|
+
|
|
293
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
test('should apply mark to list item', () => {
|
|
297
|
+
const editor = createEditor({
|
|
298
|
+
content: NodeFactory.doc([
|
|
299
|
+
NodeFactory.list(ListTypes.DISC, [
|
|
300
|
+
'lorem ipsum 1',
|
|
301
|
+
'lorem ipsum 2'
|
|
302
|
+
])
|
|
303
|
+
])
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
editor.commands.setTextSelection({ from: 1, to: 16 });
|
|
307
|
+
editor.commands.applyMark(TextSettings.FONT_WEIGHT, { value: '700' });
|
|
308
|
+
|
|
309
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
test('should remove paragraph mark on applying to list item', () => {
|
|
313
|
+
const editor = createEditor({
|
|
314
|
+
content: NodeFactory.doc([
|
|
315
|
+
NodeFactory.list(ListTypes.DISC, [
|
|
316
|
+
NodeFactory.listItem([
|
|
317
|
+
NodeFactory.paragraph(null, [
|
|
318
|
+
NodeFactory.mark(TextSettings.FONT_WEIGHT, { value: '400' })
|
|
319
|
+
], 'lorem ipsum 1'),
|
|
320
|
+
|
|
321
|
+
'lorem ipsum 2' // prevent move mark to list item on init
|
|
322
|
+
]),
|
|
323
|
+
|
|
324
|
+
'lorem ipsum 3'
|
|
325
|
+
])
|
|
326
|
+
])
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
editor.commands.setTextSelection({ from: 1, to: 31 });
|
|
330
|
+
editor.commands.applyMark(TextSettings.FONT_WEIGHT, { value: '700' });
|
|
331
|
+
|
|
332
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
333
|
+
});
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
describe('get marks', () => {
|
|
337
|
+
test('should get marks', () => {
|
|
338
|
+
const editor = createEditor({
|
|
339
|
+
content: NodeFactory.doc([
|
|
340
|
+
NodeFactory.paragraph(null, [
|
|
341
|
+
NodeFactory.mark(TextSettings.FONT_WEIGHT, { value: '400' })
|
|
342
|
+
], [
|
|
343
|
+
NodeFactory.text('lorem', [
|
|
344
|
+
NodeFactory.mark(TextSettings.FONT_WEIGHT, { value: '700' })
|
|
345
|
+
]),
|
|
346
|
+
NodeFactory.text(' ipsum')
|
|
347
|
+
])
|
|
348
|
+
])
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
editor.commands.selectAll();
|
|
352
|
+
const selectionRef = editor.commands.getMarks(TextSettings.FONT_WEIGHT);
|
|
353
|
+
|
|
354
|
+
expect(selectionRef.value).toEqual([
|
|
355
|
+
{ value: '700' },
|
|
356
|
+
{ value: '400' }
|
|
357
|
+
]);
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
test('should get empty marks', () => {
|
|
361
|
+
const editor = createEditor({
|
|
362
|
+
content: NodeFactory.doc([
|
|
363
|
+
NodeFactory.paragraph('lorem ipsum')
|
|
364
|
+
])
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
editor.commands.selectAll();
|
|
368
|
+
const selectionRef = editor.commands.getMarks(TextSettings.FONT_WEIGHT);
|
|
369
|
+
|
|
370
|
+
expect(selectionRef.value).toEqual([]);
|
|
371
|
+
});
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
describe('get mark', () => {
|
|
375
|
+
test('should get text mark', () => {
|
|
376
|
+
const editor = createEditor({
|
|
377
|
+
content: NodeFactory.doc([
|
|
378
|
+
NodeFactory.paragraph(null, [
|
|
379
|
+
NodeFactory.mark(TextSettings.FONT_WEIGHT, { value: '400' })
|
|
380
|
+
], [
|
|
381
|
+
NodeFactory.text('lorem', [
|
|
382
|
+
NodeFactory.mark(TextSettings.FONT_WEIGHT, { value: '700' })
|
|
383
|
+
]),
|
|
384
|
+
NodeFactory.text(' ipsum')
|
|
385
|
+
])
|
|
386
|
+
])
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
editor.commands.selectAll();
|
|
390
|
+
const selectionRef = editor.commands.getMark(TextSettings.FONT_WEIGHT);
|
|
391
|
+
|
|
392
|
+
expect(selectionRef.value).toEqual({ value: '700' });
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
test('should get block mark', () => {
|
|
396
|
+
const editor = createEditor({
|
|
397
|
+
content: NodeFactory.doc([
|
|
398
|
+
NodeFactory.paragraph(null, [
|
|
399
|
+
NodeFactory.mark(TextSettings.FONT_WEIGHT, { value: '400' })
|
|
400
|
+
], 'lorem ipsum')
|
|
401
|
+
])
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
editor.commands.selectAll();
|
|
405
|
+
const selectionRef = editor.commands.getMark(TextSettings.FONT_WEIGHT);
|
|
406
|
+
|
|
407
|
+
expect(selectionRef.value).toEqual({ value: '400' });
|
|
408
|
+
});
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
describe('get setting mark', () => {
|
|
412
|
+
test('should get common setting mark', () => {
|
|
413
|
+
const editor = createEditor({
|
|
414
|
+
content: NodeFactory.doc([
|
|
415
|
+
NodeFactory.paragraph(null, [
|
|
416
|
+
NodeFactory.mark(TextSettings.FONT_WEIGHT, { value: '400' })
|
|
417
|
+
], 'lorem ipsum')
|
|
418
|
+
])
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
editor.commands.selectAll();
|
|
422
|
+
const selectionRef = editor.commands.getCommonSettingMark(TextSettings.FONT_WEIGHT);
|
|
423
|
+
|
|
424
|
+
expect(selectionRef.value).toEqual('400');
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
test('should get default of common setting mark', () => {
|
|
428
|
+
const editor = createEditor({
|
|
429
|
+
content: NodeFactory.doc([
|
|
430
|
+
NodeFactory.paragraph('lorem ipsum')
|
|
431
|
+
])
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
editor.commands.selectAll();
|
|
435
|
+
const selectionRef = editor.commands.getCommonSettingMark(TextSettings.FONT_WEIGHT, ref('400'));
|
|
436
|
+
|
|
437
|
+
expect(selectionRef.value).toEqual('400');
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
test('should get device setting mark', () => {
|
|
441
|
+
const editor = createEditor({
|
|
442
|
+
content: NodeFactory.doc([
|
|
443
|
+
NodeFactory.paragraph(null, [
|
|
444
|
+
NodeFactory.mark(TextSettings.FONT_SIZE, { mobile: '23' })
|
|
445
|
+
], 'lorem ipsum')
|
|
446
|
+
]),
|
|
447
|
+
device: Devices.MOBILE
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
editor.commands.selectAll();
|
|
451
|
+
const selectionRef = editor.commands.getDeviceSettingMark(TextSettings.FONT_SIZE);
|
|
452
|
+
|
|
453
|
+
expect(selectionRef.value).toEqual('23');
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
test('should get default of device setting mark', () => {
|
|
457
|
+
const editor = createEditor({
|
|
458
|
+
content: NodeFactory.doc([
|
|
459
|
+
NodeFactory.paragraph('lorem ipsum')
|
|
460
|
+
]),
|
|
461
|
+
device: Devices.MOBILE
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
editor.commands.selectAll();
|
|
465
|
+
const selectionRef = editor.commands.getDeviceSettingMark(TextSettings.FONT_SIZE, ref('23'));
|
|
466
|
+
|
|
467
|
+
expect(selectionRef.value).toEqual('23');
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
test('should inherit device setting mark', () => {
|
|
471
|
+
const editor = createEditor({
|
|
472
|
+
content: NodeFactory.doc([
|
|
473
|
+
NodeFactory.paragraph(null, [
|
|
474
|
+
NodeFactory.mark(TextSettings.FONT_SIZE, { mobile: '23' })
|
|
475
|
+
], [
|
|
476
|
+
NodeFactory.text('lorem', [
|
|
477
|
+
NodeFactory.mark(TextSettings.FONT_SIZE, { tablet: '25' })
|
|
478
|
+
]),
|
|
479
|
+
NodeFactory.text(' ipsum')
|
|
480
|
+
])
|
|
481
|
+
]),
|
|
482
|
+
device: Devices.MOBILE
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
editor.commands.selectAll();
|
|
486
|
+
const selectionRef = editor.commands.getDeviceSettingMark(TextSettings.FONT_SIZE);
|
|
487
|
+
|
|
488
|
+
expect(selectionRef.value).toEqual('23');
|
|
489
|
+
});
|
|
490
|
+
});
|
|
491
|
+
|
|
194
492
|
describe('remove marks', () => {
|
|
195
493
|
test('should remove text marks', () => {
|
|
196
494
|
const editor = createEditor({
|
|
@@ -138,7 +138,7 @@ describe('transform text', () => {
|
|
|
138
138
|
content: NodeFactory.doc([
|
|
139
139
|
NodeFactory.paragraph([
|
|
140
140
|
NodeFactory.text('hello world', [
|
|
141
|
-
NodeFactory.mark(
|
|
141
|
+
NodeFactory.mark(TextSettings.FONT_WEIGHT, { value: '700' })
|
|
142
142
|
])
|
|
143
143
|
])
|
|
144
144
|
])
|