@zipify/wysiwyg 2.0.0-0 → 2.0.0-10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +1 -1
- package/config/build/cli.config.js +8 -2
- package/config/build/lib.config.js +4 -2
- package/dist/cli.js +10 -2
- package/dist/wysiwyg.css +53 -37
- package/dist/wysiwyg.mjs +2131 -405
- package/example/ExampleApp.vue +13 -2
- package/lib/Wysiwyg.vue +3 -2
- package/lib/__tests__/utils/buildTestExtensions.js +2 -1
- package/lib/assets/icons/indicator.svg +4 -0
- package/lib/cli/commands/Command.js +39 -0
- package/lib/cli/commands/ToJsonCommand.js +46 -0
- package/lib/cli/commands/VersionCommand.js +11 -0
- package/lib/cli/commands/index.js +2 -0
- package/lib/cli/index.js +1 -0
- package/lib/components/base/Button.vue +6 -0
- package/lib/components/base/dropdown/Dropdown.vue +7 -1
- package/lib/components/base/dropdown/DropdownActivator.vue +25 -4
- package/lib/components/base/dropdown/__tests__/DropdownActivator.test.js +23 -1
- package/lib/components/toolbar/controls/AlignmentControl.vue +12 -1
- package/lib/components/toolbar/controls/FontColorControl.vue +14 -0
- package/lib/components/toolbar/controls/FontFamilyControl.vue +4 -0
- package/lib/components/toolbar/controls/FontSizeControl.vue +6 -1
- package/lib/components/toolbar/controls/FontWeightControl.vue +12 -0
- package/lib/components/toolbar/controls/ItalicControl.vue +14 -0
- package/lib/components/toolbar/controls/LineHeightControl.vue +15 -0
- package/lib/components/toolbar/controls/StylePresetControl.vue +1 -1
- package/lib/components/toolbar/controls/UnderlineControl.vue +13 -0
- package/lib/components/toolbar/controls/__tests__/AlignmentControl.test.js +72 -5
- package/lib/components/toolbar/controls/__tests__/FontColorControl.test.js +22 -1
- package/lib/components/toolbar/controls/__tests__/FontFamilyControl.test.js +1 -0
- package/lib/components/toolbar/controls/__tests__/FontSizeControl.test.js +1 -0
- package/lib/components/toolbar/controls/__tests__/FontWeightControl.test.js +1 -0
- package/lib/components/toolbar/controls/__tests__/ItalicControl.test.js +23 -1
- package/lib/components/toolbar/controls/__tests__/LineHeightControl.test.js +23 -1
- package/lib/components/toolbar/controls/__tests__/StylePresetControl.test.js +6 -6
- package/lib/components/toolbar/controls/__tests__/UnderlineControl.test.js +25 -1
- package/lib/composables/__tests__/useEditor.test.js +1 -1
- package/lib/composables/useEditor.js +9 -8
- package/lib/directives/__tests__/tooltip.test.js +22 -4
- package/lib/directives/tooltip.js +4 -1
- package/lib/entry-cli.js +7 -20
- package/lib/entry-lib.js +1 -1
- package/lib/enums/MarkGroups.js +4 -0
- package/lib/enums/TextSettings.js +5 -5
- package/lib/enums/index.js +1 -0
- package/lib/extensions/BackgroundColor.js +0 -1
- package/lib/extensions/FontColor.js +2 -2
- package/lib/extensions/FontFamily.js +3 -3
- package/lib/extensions/FontSize.js +2 -2
- package/lib/extensions/FontStyle.js +2 -2
- package/lib/extensions/FontWeight.js +2 -2
- package/lib/extensions/Link.js +1 -1
- package/lib/extensions/StylePreset.js +9 -3
- package/lib/extensions/Superscript.js +5 -2
- package/lib/extensions/TextDecoration.js +19 -29
- package/lib/extensions/__tests__/Alignment.test.js +2 -2
- package/lib/extensions/__tests__/BackgroundColor.test.js +4 -3
- package/lib/extensions/__tests__/FontColor.test.js +4 -3
- package/lib/extensions/__tests__/FontFamily.test.js +6 -6
- package/lib/extensions/__tests__/FontSize.test.js +9 -8
- package/lib/extensions/__tests__/FontStyle.test.js +6 -5
- package/lib/extensions/__tests__/FontWeight.test.js +2 -2
- package/lib/extensions/__tests__/LineHeight.test.js +2 -1
- package/lib/extensions/__tests__/StylePreset.test.js +51 -0
- package/lib/extensions/__tests__/Superscript.test.js +102 -0
- package/lib/extensions/__tests__/TextDecoration.test.js +40 -24
- package/lib/extensions/__tests__/__snapshots__/BackgroundColor.test.js.snap +24 -24
- package/lib/extensions/__tests__/__snapshots__/FontColor.test.js.snap +1 -1
- package/lib/extensions/__tests__/__snapshots__/FontFamily.test.js.snap +19 -23
- package/lib/extensions/__tests__/__snapshots__/FontSize.test.js.snap +2 -2
- package/lib/extensions/__tests__/__snapshots__/FontStyle.test.js.snap +1 -1
- package/lib/extensions/__tests__/__snapshots__/FontWeight.test.js.snap +13 -17
- package/lib/extensions/__tests__/__snapshots__/Superscript.test.js.snap +107 -0
- package/lib/extensions/__tests__/__snapshots__/TextDecoration.test.js.snap +102 -102
- package/lib/extensions/core/Document.js +2 -1
- package/lib/extensions/core/Heading.js +2 -1
- package/lib/extensions/core/NodeProcessor.js +63 -20
- package/lib/extensions/core/Paragraph.js +2 -1
- package/lib/extensions/core/TextProcessor.js +0 -5
- package/lib/extensions/core/__tests__/NodeProcessor.test.js +364 -11
- package/lib/extensions/core/__tests__/TextProcessor.test.js +1 -22
- package/lib/extensions/core/__tests__/__snapshots__/NodeProcessor.test.js.snap +309 -0
- package/lib/extensions/core/__tests__/__snapshots__/TextProcessor.test.js.snap +7 -27
- package/lib/extensions/core/steps/AddNodeMarkStep.js +6 -0
- package/lib/extensions/core/steps/AttrStep.js +60 -0
- package/lib/extensions/core/steps/RemoveNodeMarkStep.js +6 -0
- package/lib/extensions/core/steps/index.js +1 -0
- package/lib/extensions/list/List.js +70 -9
- package/lib/extensions/list/ListItem.js +2 -2
- package/lib/extensions/list/__tests__/List.test.js +26 -17
- package/lib/extensions/list/__tests__/__snapshots__/List.test.js.snap +36 -36
- package/lib/services/NodeFactory.js +73 -13
- package/lib/services/__tests__/NodeFactory.test.js +124 -0
- package/lib/services/__tests__/__snapshots__/NodeFactory.test.js.snap +326 -0
- package/lib/services/index.js +1 -1
- package/lib/services/normalizer/BaseNormalizer.js +11 -0
- package/lib/services/{BrowserDomParser.js → normalizer/BrowserDomParser.js} +0 -0
- package/lib/services/normalizer/ContentNormalizer.js +24 -0
- package/lib/services/normalizer/HtmlNormalizer.js +297 -0
- package/lib/services/normalizer/JsonNormalizer.js +82 -0
- package/lib/services/{__tests__/ContentNormalizer.test.js → normalizer/__tests__/HtmlNormalizer.test.js} +42 -4
- package/lib/services/normalizer/__tests__/JsonNormalizer.test.js +87 -0
- package/lib/services/normalizer/__tests__/__snapshots__/JsonNormalizer.test.js.snap +196 -0
- package/lib/services/normalizer/index.js +1 -0
- package/lib/styles/content.css +8 -0
- package/lib/utils/__tests__/findMarkByType.test.js +17 -0
- package/lib/utils/__tests__/isMarkAppliedToParent.test.js +53 -0
- package/lib/utils/__tests__/isNodeFullySelected.test.js +44 -0
- package/lib/utils/__tests__/resolveTextPosition.test.js +39 -0
- package/lib/utils/copyMark.js +5 -0
- package/lib/utils/index.js +1 -1
- package/lib/utils/isMarkAppliedToParent.js +2 -7
- package/lib/utils/isNodeFullySelected.js +4 -7
- package/lib/utils/resolveTextPosition.js +4 -6
- package/package.json +31 -27
- package/lib/services/ContentNormalizer.js +0 -194
- package/lib/utils/resolveNodePosition.js +0 -6
|
@@ -1,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
|
});
|
|
@@ -190,3 +234,312 @@ describe('apply mark', () => {
|
|
|
190
234
|
expect(editor.getJSON()).toMatchSnapshot();
|
|
191
235
|
});
|
|
192
236
|
});
|
|
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
|
+
|
|
492
|
+
describe('remove marks', () => {
|
|
493
|
+
test('should remove text marks', () => {
|
|
494
|
+
const editor = createEditor({
|
|
495
|
+
content: NodeFactory.doc([
|
|
496
|
+
NodeFactory.paragraph([
|
|
497
|
+
NodeFactory.text('lorem', [
|
|
498
|
+
NodeFactory.mark(TextSettings.FONT_WEIGHT, { value: '700' })
|
|
499
|
+
]),
|
|
500
|
+
NodeFactory.text(' ipsum')
|
|
501
|
+
])
|
|
502
|
+
])
|
|
503
|
+
});
|
|
504
|
+
|
|
505
|
+
editor.commands.selectAll();
|
|
506
|
+
editor.commands.removeMarks([TextSettings.FONT_WEIGHT]);
|
|
507
|
+
|
|
508
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
509
|
+
});
|
|
510
|
+
|
|
511
|
+
test('should remove block marks', () => {
|
|
512
|
+
const editor = createEditor({
|
|
513
|
+
content: NodeFactory.doc([
|
|
514
|
+
NodeFactory.paragraph(null, [
|
|
515
|
+
NodeFactory.mark(TextSettings.FONT_WEIGHT, { value: '700' })
|
|
516
|
+
], 'lorem ipsum')
|
|
517
|
+
])
|
|
518
|
+
});
|
|
519
|
+
|
|
520
|
+
editor.commands.selectAll();
|
|
521
|
+
editor.commands.removeMarks([TextSettings.FONT_WEIGHT]);
|
|
522
|
+
|
|
523
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
524
|
+
});
|
|
525
|
+
|
|
526
|
+
test('should remove block and text marks', () => {
|
|
527
|
+
const editor = createEditor({
|
|
528
|
+
content: NodeFactory.doc([
|
|
529
|
+
NodeFactory.paragraph(null, [
|
|
530
|
+
NodeFactory.mark(TextSettings.FONT_WEIGHT, { value: '700' })
|
|
531
|
+
], [
|
|
532
|
+
NodeFactory.text('lorem'),
|
|
533
|
+
NodeFactory.text(' ipsum', [
|
|
534
|
+
NodeFactory.mark(TextSettings.FONT_WEIGHT, { value: '400' })
|
|
535
|
+
])
|
|
536
|
+
])
|
|
537
|
+
])
|
|
538
|
+
});
|
|
539
|
+
|
|
540
|
+
editor.commands.selectAll();
|
|
541
|
+
editor.commands.removeMarks([TextSettings.FONT_WEIGHT]);
|
|
542
|
+
|
|
543
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
544
|
+
});
|
|
545
|
+
});
|
|
@@ -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
|
])
|
|
@@ -164,24 +164,3 @@ describe('selected text', () => {
|
|
|
164
164
|
expect(editor.commands.getSelectedText()).toEqual('o worl');
|
|
165
165
|
});
|
|
166
166
|
});
|
|
167
|
-
|
|
168
|
-
describe('unset marks', () => {
|
|
169
|
-
test('should reset all marks', () => {
|
|
170
|
-
const editor = createEditor({
|
|
171
|
-
content: NodeFactory.doc([
|
|
172
|
-
NodeFactory.paragraph([
|
|
173
|
-
NodeFactory.text('hello world', [
|
|
174
|
-
NodeFactory.mark('font_weight', { value: '700' })
|
|
175
|
-
])
|
|
176
|
-
])
|
|
177
|
-
])
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
editor.chain()
|
|
181
|
-
.selectAll()
|
|
182
|
-
.unsetMarks(TextSettings.marks)
|
|
183
|
-
.run();
|
|
184
|
-
|
|
185
|
-
expect(editor.getJSON()).toMatchSnapshot();
|
|
186
|
-
});
|
|
187
|
-
});
|