@zipify/wysiwyg 3.0.0 → 3.0.2-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/config/build/cli.config.js +1 -1
- package/config/build/lib.config.js +1 -1
- package/dist/cli.js +3 -3
- package/dist/wysiwyg.css +25 -22
- package/dist/wysiwyg.mjs +919 -886
- package/example/ExampleApp.vue +1 -1
- package/example/presets.js +7 -7
- package/lib/__tests__/utils/buildTestExtensions.js +24 -2
- package/lib/components/base/dropdown/DropdownActivator.vue +4 -0
- package/lib/components/toolbar/controls/StylePresetControl.vue +1 -1
- package/lib/{entry-cli.js → entryCli.js} +0 -0
- package/lib/{entry-lib.js → entryLib.js} +0 -0
- package/lib/extensions/Alignment.js +6 -6
- package/lib/extensions/StylePreset.js +8 -46
- package/lib/extensions/__tests__/Alignment.test.js +1 -1
- package/lib/extensions/__tests__/StylePreset.test.js +90 -119
- package/lib/extensions/__tests__/__snapshots__/Alignment.test.js.snap +2 -2
- package/lib/extensions/__tests__/__snapshots__/StylePreset.test.js.snap +0 -2
- package/lib/extensions/core/NodeProcessor.js +6 -2
- package/lib/extensions/index.js +7 -3
- package/lib/extensions/list/__tests__/List.test.js +6 -1
- package/lib/services/ContentSerializer.js +1 -1
- package/lib/services/{ContextWidnow.js → ContextWindow.js} +0 -0
- package/lib/services/StylePresetRenderer.js +73 -0
- package/lib/services/__tests__/StylePresetRenderer.test.js +98 -0
- package/lib/services/__tests__/__snapshots__/StylePresetRenderer.test.js.snap +5 -0
- package/lib/services/index.js +2 -1
- package/lib/styles/content.css +10 -10
- package/package.json +6 -2
|
@@ -119,40 +119,36 @@ const MockLink = Extension.create({
|
|
|
119
119
|
});
|
|
120
120
|
|
|
121
121
|
function createEditor({ content, presets, defaultId, link }) {
|
|
122
|
-
return new
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
MockLink.configure(link)
|
|
153
|
-
]
|
|
154
|
-
})
|
|
155
|
-
});
|
|
122
|
+
return new Editor({
|
|
123
|
+
content: ContentNormalizer.normalize(content),
|
|
124
|
+
|
|
125
|
+
extensions: buildTestExtensions({
|
|
126
|
+
include: [
|
|
127
|
+
StylePreset.configure({
|
|
128
|
+
presets,
|
|
129
|
+
defaultId,
|
|
130
|
+
|
|
131
|
+
styleRenderer: {
|
|
132
|
+
makePresetHtmlClass: (preset) => `zw ts-${preset.id}`,
|
|
133
|
+
makePresetCssClass: (preset) => `.zw.ts-${preset.id}`,
|
|
134
|
+
inject: jest.fn()
|
|
135
|
+
}
|
|
136
|
+
}),
|
|
137
|
+
List.configure({
|
|
138
|
+
baseClass: 'zw-list--'
|
|
139
|
+
}),
|
|
140
|
+
MockFontSize,
|
|
141
|
+
MockFontWeight,
|
|
142
|
+
MockAlignment,
|
|
143
|
+
MockBackgroundColor,
|
|
144
|
+
MockFontColor,
|
|
145
|
+
MockFontFamily,
|
|
146
|
+
MockFontStyle,
|
|
147
|
+
MockTextDecoration,
|
|
148
|
+
MockSuperscript,
|
|
149
|
+
MockLink.configure(link)
|
|
150
|
+
]
|
|
151
|
+
})
|
|
156
152
|
});
|
|
157
153
|
}
|
|
158
154
|
|
|
@@ -166,33 +162,8 @@ const createPreset = (attrs = {}) => ({
|
|
|
166
162
|
});
|
|
167
163
|
|
|
168
164
|
describe('render preset styles', () => {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
test('should render styles', async () => {
|
|
172
|
-
const editor = await createEditor({
|
|
173
|
-
content: NodeFactory.doc([]),
|
|
174
|
-
presets: [createPreset()]
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
expect(getStyleEl(editor).innerHTML).toMatchSnapshot();
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
test('should not create multiple style elements', async () => {
|
|
181
|
-
const editor1 = await createEditor({
|
|
182
|
-
content: NodeFactory.doc([]),
|
|
183
|
-
presets: [createPreset()]
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
const editor2 = await createEditor({
|
|
187
|
-
content: NodeFactory.doc([]),
|
|
188
|
-
presets: [createPreset()]
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
expect(getStyleEl(editor1)).toBe(getStyleEl(editor2));
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
test('should render preset class', async () => {
|
|
195
|
-
const editor = await createEditor({
|
|
165
|
+
test('should render preset class', () => {
|
|
166
|
+
const editor = createEditor({
|
|
196
167
|
content: NodeFactory.doc([
|
|
197
168
|
NodeFactory.paragraph({ preset: { id: 'regular-1' } }, 'test')
|
|
198
169
|
]),
|
|
@@ -202,8 +173,8 @@ describe('render preset styles', () => {
|
|
|
202
173
|
expect(editor.getHTML()).toMatchSnapshot();
|
|
203
174
|
});
|
|
204
175
|
|
|
205
|
-
test('should render node without preset',
|
|
206
|
-
const editor =
|
|
176
|
+
test('should render node without preset', () => {
|
|
177
|
+
const editor = createEditor({
|
|
207
178
|
content: NodeFactory.doc([
|
|
208
179
|
NodeFactory.paragraph({ preset: null }, 'test')
|
|
209
180
|
]),
|
|
@@ -215,8 +186,8 @@ describe('render preset styles', () => {
|
|
|
215
186
|
});
|
|
216
187
|
|
|
217
188
|
describe('get preset', () => {
|
|
218
|
-
test('should get preset from selection',
|
|
219
|
-
const editor =
|
|
189
|
+
test('should get preset from selection', () => {
|
|
190
|
+
const editor = createEditor({
|
|
220
191
|
content: NodeFactory.doc([
|
|
221
192
|
NodeFactory.paragraph({ preset: { id: 'regular-1' } }, 'test')
|
|
222
193
|
]),
|
|
@@ -227,8 +198,8 @@ describe('get preset', () => {
|
|
|
227
198
|
expect(preset.value).toMatchSnapshot();
|
|
228
199
|
});
|
|
229
200
|
|
|
230
|
-
test('should return null if no preset in selection',
|
|
231
|
-
const editor =
|
|
201
|
+
test('should return null if no preset in selection', () => {
|
|
202
|
+
const editor = createEditor({
|
|
232
203
|
content: NodeFactory.doc([
|
|
233
204
|
NodeFactory.paragraph({ preset: null }, 'test')
|
|
234
205
|
]),
|
|
@@ -239,8 +210,8 @@ describe('get preset', () => {
|
|
|
239
210
|
expect(preset.value).toBeFalsy();
|
|
240
211
|
});
|
|
241
212
|
|
|
242
|
-
test('should get setting from link if selected',
|
|
243
|
-
const editor =
|
|
213
|
+
test('should get setting from link if selected', () => {
|
|
214
|
+
const editor = createEditor({
|
|
244
215
|
content: NodeFactory.doc([
|
|
245
216
|
NodeFactory.paragraph({ preset: { id: 'regular-1' } }, 'test')
|
|
246
217
|
]),
|
|
@@ -273,8 +244,8 @@ describe('get preset', () => {
|
|
|
273
244
|
});
|
|
274
245
|
|
|
275
246
|
describe('apply preset', () => {
|
|
276
|
-
test('should apply preset to text',
|
|
277
|
-
const editor =
|
|
247
|
+
test('should apply preset to text', () => {
|
|
248
|
+
const editor = createEditor({
|
|
278
249
|
content: NodeFactory.doc([
|
|
279
250
|
NodeFactory.paragraph({ preset: null }, 'test')
|
|
280
251
|
]),
|
|
@@ -287,8 +258,8 @@ describe('apply preset', () => {
|
|
|
287
258
|
expect(editor.getJSON()).toMatchSnapshot();
|
|
288
259
|
});
|
|
289
260
|
|
|
290
|
-
test('should apply heading to text',
|
|
291
|
-
const editor =
|
|
261
|
+
test('should apply heading to text', () => {
|
|
262
|
+
const editor = createEditor({
|
|
292
263
|
content: NodeFactory.doc([
|
|
293
264
|
NodeFactory.paragraph({ preset: null }, 'test')
|
|
294
265
|
]),
|
|
@@ -303,8 +274,8 @@ describe('apply preset', () => {
|
|
|
303
274
|
expect(editor.getJSON()).toMatchSnapshot();
|
|
304
275
|
});
|
|
305
276
|
|
|
306
|
-
test('should change paragraph to heading',
|
|
307
|
-
const editor =
|
|
277
|
+
test('should change paragraph to heading', () => {
|
|
278
|
+
const editor = createEditor({
|
|
308
279
|
content: NodeFactory.doc([
|
|
309
280
|
NodeFactory.paragraph({ preset: { id: 'regular-1' } }, 'test')
|
|
310
281
|
]),
|
|
@@ -320,8 +291,8 @@ describe('apply preset', () => {
|
|
|
320
291
|
expect(editor.getJSON()).toMatchSnapshot();
|
|
321
292
|
});
|
|
322
293
|
|
|
323
|
-
test('should apply regular to list',
|
|
324
|
-
const editor =
|
|
294
|
+
test('should apply regular to list', () => {
|
|
295
|
+
const editor = createEditor({
|
|
325
296
|
content: NodeFactory.doc([
|
|
326
297
|
NodeFactory.list(ListTypes.LATIN, [
|
|
327
298
|
NodeFactory.paragraph('Item 1'),
|
|
@@ -337,8 +308,8 @@ describe('apply preset', () => {
|
|
|
337
308
|
expect(editor.getJSON()).toMatchSnapshot();
|
|
338
309
|
});
|
|
339
310
|
|
|
340
|
-
test('should apply heading to list',
|
|
341
|
-
const editor =
|
|
311
|
+
test('should apply heading to list', () => {
|
|
312
|
+
const editor = createEditor({
|
|
342
313
|
content: NodeFactory.doc([
|
|
343
314
|
NodeFactory.list(ListTypes.LATIN, [
|
|
344
315
|
NodeFactory.paragraph('Item 1'),
|
|
@@ -356,8 +327,8 @@ describe('apply preset', () => {
|
|
|
356
327
|
expect(editor.getJSON()).toMatchSnapshot();
|
|
357
328
|
});
|
|
358
329
|
|
|
359
|
-
test('should apply default preset',
|
|
360
|
-
const editor =
|
|
330
|
+
test('should apply default preset', () => {
|
|
331
|
+
const editor = createEditor({
|
|
361
332
|
content: NodeFactory.doc([
|
|
362
333
|
NodeFactory.paragraph({ preset: null }, 'test')
|
|
363
334
|
]),
|
|
@@ -371,8 +342,8 @@ describe('apply preset', () => {
|
|
|
371
342
|
expect(editor.getJSON()).toMatchSnapshot();
|
|
372
343
|
});
|
|
373
344
|
|
|
374
|
-
test('should keep text attributes on apply',
|
|
375
|
-
const editor =
|
|
345
|
+
test('should keep text attributes on apply', () => {
|
|
346
|
+
const editor = createEditor({
|
|
376
347
|
content: NodeFactory.doc([
|
|
377
348
|
NodeFactory.paragraph({
|
|
378
349
|
preset: { id: 'regular-1' },
|
|
@@ -393,8 +364,8 @@ describe('apply preset', () => {
|
|
|
393
364
|
});
|
|
394
365
|
|
|
395
366
|
describe('get preset customization', () => {
|
|
396
|
-
test('should return empty customization',
|
|
397
|
-
const editor =
|
|
367
|
+
test('should return empty customization', () => {
|
|
368
|
+
const editor = createEditor({
|
|
398
369
|
content: NodeFactory.doc([
|
|
399
370
|
NodeFactory.paragraph({ preset: { id: 'regular-1' } }, 'test')
|
|
400
371
|
]),
|
|
@@ -405,8 +376,8 @@ describe('get preset customization', () => {
|
|
|
405
376
|
expect(customization.value).toMatchSnapshot();
|
|
406
377
|
});
|
|
407
378
|
|
|
408
|
-
test('should not is setting customized',
|
|
409
|
-
const editor =
|
|
379
|
+
test('should not is setting customized', () => {
|
|
380
|
+
const editor = createEditor({
|
|
410
381
|
content: NodeFactory.doc([
|
|
411
382
|
NodeFactory.paragraph({ preset: { id: 'regular-1' } }, 'test')
|
|
412
383
|
]),
|
|
@@ -420,8 +391,8 @@ describe('get preset customization', () => {
|
|
|
420
391
|
expect(isAlignmentCustomized.value).toBe(false);
|
|
421
392
|
});
|
|
422
393
|
|
|
423
|
-
test('should find marks',
|
|
424
|
-
const editor =
|
|
394
|
+
test('should find marks', () => {
|
|
395
|
+
const editor = createEditor({
|
|
425
396
|
content: NodeFactory.doc([
|
|
426
397
|
NodeFactory.paragraph({ preset: { id: 'regular-1' } }, [
|
|
427
398
|
NodeFactory.text('test', [
|
|
@@ -440,8 +411,8 @@ describe('get preset customization', () => {
|
|
|
440
411
|
expect(customization.value).toMatchSnapshot();
|
|
441
412
|
});
|
|
442
413
|
|
|
443
|
-
test('should is marks setting customized',
|
|
444
|
-
const editor =
|
|
414
|
+
test('should is marks setting customized', () => {
|
|
415
|
+
const editor = createEditor({
|
|
445
416
|
content: NodeFactory.doc([
|
|
446
417
|
NodeFactory.paragraph({ preset: { id: 'regular-1' } }, [
|
|
447
418
|
NodeFactory.text('test', [
|
|
@@ -459,8 +430,8 @@ describe('get preset customization', () => {
|
|
|
459
430
|
expect(isFontSizeCustomized.value).toBe(true);
|
|
460
431
|
});
|
|
461
432
|
|
|
462
|
-
test('should find attributes',
|
|
463
|
-
const editor =
|
|
433
|
+
test('should find attributes', () => {
|
|
434
|
+
const editor = createEditor({
|
|
464
435
|
content: NodeFactory.doc([
|
|
465
436
|
NodeFactory.paragraph({
|
|
466
437
|
preset: { id: 'regular-1' },
|
|
@@ -477,8 +448,8 @@ describe('get preset customization', () => {
|
|
|
477
448
|
expect(customization.value).toMatchSnapshot();
|
|
478
449
|
});
|
|
479
450
|
|
|
480
|
-
test('should is attributes setting customized',
|
|
481
|
-
const editor =
|
|
451
|
+
test('should is attributes setting customized', () => {
|
|
452
|
+
const editor = createEditor({
|
|
482
453
|
content: NodeFactory.doc([
|
|
483
454
|
NodeFactory.paragraph({
|
|
484
455
|
preset: { id: 'regular-1' },
|
|
@@ -496,8 +467,8 @@ describe('get preset customization', () => {
|
|
|
496
467
|
});
|
|
497
468
|
|
|
498
469
|
describe('get content customization', () => {
|
|
499
|
-
test('should return empty content customization',
|
|
500
|
-
const editor =
|
|
470
|
+
test('should return empty content customization', () => {
|
|
471
|
+
const editor = createEditor({
|
|
501
472
|
content: NodeFactory.doc([
|
|
502
473
|
NodeFactory.paragraph({ preset: { id: 'regular-1' } }, 'test')
|
|
503
474
|
]),
|
|
@@ -508,8 +479,8 @@ describe('get content customization', () => {
|
|
|
508
479
|
expect(customization.value).toMatchSnapshot();
|
|
509
480
|
});
|
|
510
481
|
|
|
511
|
-
test('should find marks',
|
|
512
|
-
const editor =
|
|
482
|
+
test('should find marks', () => {
|
|
483
|
+
const editor = createEditor({
|
|
513
484
|
content: NodeFactory.doc([
|
|
514
485
|
NodeFactory.paragraph({ preset: { id: 'regular-2' } }, [
|
|
515
486
|
NodeFactory.text('test', [
|
|
@@ -526,8 +497,8 @@ describe('get content customization', () => {
|
|
|
526
497
|
expect(customization.value).toMatchSnapshot();
|
|
527
498
|
});
|
|
528
499
|
|
|
529
|
-
test('should find attributes',
|
|
530
|
-
const editor =
|
|
500
|
+
test('should find attributes', () => {
|
|
501
|
+
const editor = createEditor({
|
|
531
502
|
content: NodeFactory.doc([
|
|
532
503
|
NodeFactory.paragraph({
|
|
533
504
|
preset: { id: 'regular-2' },
|
|
@@ -544,8 +515,8 @@ describe('get content customization', () => {
|
|
|
544
515
|
});
|
|
545
516
|
|
|
546
517
|
describe('remove preset customization', () => {
|
|
547
|
-
test('should remove all marks in block',
|
|
548
|
-
const editor =
|
|
518
|
+
test('should remove all marks in block', () => {
|
|
519
|
+
const editor = createEditor({
|
|
549
520
|
content: NodeFactory.doc([
|
|
550
521
|
NodeFactory.paragraph({ preset: { id: 'regular-1' } }, [
|
|
551
522
|
NodeFactory.text('test', [
|
|
@@ -566,8 +537,8 @@ describe('remove preset customization', () => {
|
|
|
566
537
|
expect(editor.getJSON()).toMatchSnapshot();
|
|
567
538
|
});
|
|
568
539
|
|
|
569
|
-
test('should remove all attributes',
|
|
570
|
-
const editor =
|
|
540
|
+
test('should remove all attributes', () => {
|
|
541
|
+
const editor = createEditor({
|
|
571
542
|
content: NodeFactory.doc([
|
|
572
543
|
NodeFactory.heading(1, {
|
|
573
544
|
preset: { id: 'regular-1' },
|
|
@@ -589,8 +560,8 @@ describe('remove preset customization', () => {
|
|
|
589
560
|
expect(editor.getJSON()).toMatchSnapshot();
|
|
590
561
|
});
|
|
591
562
|
|
|
592
|
-
test('should keep selection',
|
|
593
|
-
const editor =
|
|
563
|
+
test('should keep selection', () => {
|
|
564
|
+
const editor = createEditor({
|
|
594
565
|
content: NodeFactory.doc([
|
|
595
566
|
NodeFactory.paragraph({ preset: { id: 'regular-1' } }, [
|
|
596
567
|
NodeFactory.text('test', [
|
|
@@ -615,8 +586,8 @@ describe('remove preset customization', () => {
|
|
|
615
586
|
});
|
|
616
587
|
|
|
617
588
|
describe('parsing html', () => {
|
|
618
|
-
test('should get by fallback class',
|
|
619
|
-
const editor =
|
|
589
|
+
test('should get by fallback class', () => {
|
|
590
|
+
const editor = createEditor({
|
|
620
591
|
content: '<p class="zpa-regular2">lorem ipsum</p>',
|
|
621
592
|
defaultId: 'regular-1',
|
|
622
593
|
presets: [
|
|
@@ -628,8 +599,8 @@ describe('parsing html', () => {
|
|
|
628
599
|
expect(editor.getJSON()).toMatchSnapshot();
|
|
629
600
|
});
|
|
630
601
|
|
|
631
|
-
test('should get by preset class',
|
|
632
|
-
const editor =
|
|
602
|
+
test('should get by preset class', () => {
|
|
603
|
+
const editor = createEditor({
|
|
633
604
|
content: '<p class="zw ts-regular-2">lorem ipsum</p>',
|
|
634
605
|
defaultId: 'regular-1',
|
|
635
606
|
presets: [
|
|
@@ -641,8 +612,8 @@ describe('parsing html', () => {
|
|
|
641
612
|
expect(editor.getJSON()).toMatchSnapshot();
|
|
642
613
|
});
|
|
643
614
|
|
|
644
|
-
test('should get by heading tag',
|
|
645
|
-
const editor =
|
|
615
|
+
test('should get by heading tag', () => {
|
|
616
|
+
const editor = createEditor({
|
|
646
617
|
content: '<h3>lorem ipsum</h3>',
|
|
647
618
|
defaultId: 'regular-1',
|
|
648
619
|
presets: [
|
|
@@ -654,8 +625,8 @@ describe('parsing html', () => {
|
|
|
654
625
|
expect(editor.getJSON()).toMatchSnapshot();
|
|
655
626
|
});
|
|
656
627
|
|
|
657
|
-
test('should set default preset to unstyled paragraph',
|
|
658
|
-
const editor =
|
|
628
|
+
test('should set default preset to unstyled paragraph', () => {
|
|
629
|
+
const editor = createEditor({
|
|
659
630
|
content: '<p>lorem ipsum</p>',
|
|
660
631
|
defaultId: 'regular-1',
|
|
661
632
|
presets: [createPreset({ id: 'regular-1' })]
|
|
@@ -664,8 +635,8 @@ describe('parsing html', () => {
|
|
|
664
635
|
expect(editor.getJSON()).toMatchSnapshot();
|
|
665
636
|
});
|
|
666
637
|
|
|
667
|
-
test('should set null to list item',
|
|
668
|
-
const editor =
|
|
638
|
+
test('should set null to list item', () => {
|
|
639
|
+
const editor = createEditor({
|
|
669
640
|
content: '<ul><li>lorem ipsum</li></ul>',
|
|
670
641
|
defaultId: 'regular-1',
|
|
671
642
|
presets: [createPreset({ id: 'regular-1' })]
|
|
@@ -674,8 +645,8 @@ describe('parsing html', () => {
|
|
|
674
645
|
expect(editor.getJSON()).toMatchSnapshot();
|
|
675
646
|
});
|
|
676
647
|
|
|
677
|
-
test('should set null to list item with preset',
|
|
678
|
-
const editor =
|
|
648
|
+
test('should set null to list item with preset', () => {
|
|
649
|
+
const editor = createEditor({
|
|
679
650
|
content: '<ul class="zw regular-1"><li>lorem ipsum</li></ul>',
|
|
680
651
|
defaultId: 'regular-1',
|
|
681
652
|
presets: [createPreset({ id: 'regular-1' })]
|
|
@@ -136,6 +136,6 @@ Object {
|
|
|
136
136
|
}
|
|
137
137
|
`;
|
|
138
138
|
|
|
139
|
-
exports[`rendering should render all devices 1`] = `"<p class="zw-style" style="--zw-
|
|
139
|
+
exports[`rendering should render all devices 1`] = `"<p class="zw-style" style="--zw-alignment-mobile:left;--zw-alignment-tablet:right;--zw-alignment-desktop:center;">hello world</p>"`;
|
|
140
140
|
|
|
141
|
-
exports[`rendering should render only desktop 1`] = `"<p class="zw-style" style="--zw-
|
|
141
|
+
exports[`rendering should render only desktop 1`] = `"<p class="zw-style" style="--zw-alignment-desktop:center;">hello world</p>"`;
|
|
@@ -521,5 +521,3 @@ Object {
|
|
|
521
521
|
exports[`render preset styles should render node without preset 1`] = `"<p class="zw-style">test</p>"`;
|
|
522
522
|
|
|
523
523
|
exports[`render preset styles should render preset class 1`] = `"<p class="zw-style zw ts-regular-1">test</p>"`;
|
|
524
|
-
|
|
525
|
-
exports[`render preset styles should render styles 1`] = `" .zw.ts-regular-1 { --zw-preset-font-weight: var(--common-regular-1-font-weight, inherit); --zw-preset-mobile-font-size: var(--mobile-regular-1-font-size, inherit); --zw-preset-tablet-font-size: var(--tablet-regular-1-font-size, inherit); --zw-preset-desktop-font-size: var(--desktop-regular-1-font-size, inherit); }"`;
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
isNodeFullySelected,
|
|
8
8
|
resolveTextPosition
|
|
9
9
|
} from '../../utils';
|
|
10
|
-
import { MarkGroups, NodeTypes } from '../../enums';
|
|
10
|
+
import { MarkGroups, NodeTypes, TextSettings } from '../../enums';
|
|
11
11
|
import { AddNodeMarkStep, AttrStep, RemoveNodeMarkStep } from './steps';
|
|
12
12
|
|
|
13
13
|
export const NodeProcessor = Extension.create({
|
|
@@ -46,6 +46,7 @@ export const NodeProcessor = Extension.create({
|
|
|
46
46
|
applyMark: createCommand(({ state, commands }, name, value, customizer = {}) => {
|
|
47
47
|
const { tr, doc, schema } = state;
|
|
48
48
|
const { $from, $to } = tr.selection;
|
|
49
|
+
const linkMarkType = getMarkType(TextSettings.LINK, schema);
|
|
49
50
|
const markType = getMarkType(name, schema);
|
|
50
51
|
const markGroup = markType.spec.group || '';
|
|
51
52
|
|
|
@@ -71,7 +72,10 @@ export const NodeProcessor = Extension.create({
|
|
|
71
72
|
const applyingMark = markType.create({ ...(initialMark?.attrs || {}), ...value });
|
|
72
73
|
const textPosition = resolveTextPosition($from, $to, node, position);
|
|
73
74
|
|
|
74
|
-
|
|
75
|
+
const isAppliedToParent = !linkMarkType.isInSet(node.marks)
|
|
76
|
+
&& isMarkAppliedToParent(tr.doc, position, applyingMark, customizer.isAppliedToParent);
|
|
77
|
+
|
|
78
|
+
if (isAppliedToParent) {
|
|
75
79
|
return onAppliedToParent({ tr, node, position, mark: applyingMark });
|
|
76
80
|
}
|
|
77
81
|
|
package/lib/extensions/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { reactive, toRef, watch } from 'vue';
|
|
2
|
+
import { StylePresetRenderer } from '../services';
|
|
3
|
+
import { buildCoreExtensions } from './core';
|
|
2
4
|
import { FontFamily } from './FontFamily';
|
|
3
5
|
import { StylePreset } from './StylePreset';
|
|
4
6
|
import { FontWeight } from './FontWeight';
|
|
@@ -14,7 +16,6 @@ import { LineHeight } from './LineHeight';
|
|
|
14
16
|
import { List } from './list';
|
|
15
17
|
import { Link } from './Link';
|
|
16
18
|
import { Superscript } from './Superscript';
|
|
17
|
-
import { buildCoreExtensions } from './core';
|
|
18
19
|
import { Margin } from './Margin';
|
|
19
20
|
|
|
20
21
|
export function buildExtensions(options) {
|
|
@@ -30,8 +31,11 @@ export function buildExtensions(options) {
|
|
|
30
31
|
StylePreset.configure({
|
|
31
32
|
presets: options.presetsRef,
|
|
32
33
|
defaultId: options.defaultPresetId,
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
styleRenderer: new StylePresetRenderer({
|
|
35
|
+
baseClass: options.basePresetClass,
|
|
36
|
+
makeVariable: options.makePresetVariable,
|
|
37
|
+
linkPresetId: options.linkPresetId
|
|
38
|
+
})
|
|
35
39
|
}),
|
|
36
40
|
List.configure({
|
|
37
41
|
baseClass: options.baseListClass,
|
|
@@ -29,7 +29,12 @@ function createEditor({ content }) {
|
|
|
29
29
|
}
|
|
30
30
|
],
|
|
31
31
|
defaultId: 'regular-1',
|
|
32
|
-
|
|
32
|
+
|
|
33
|
+
styleRenderer: {
|
|
34
|
+
makePresetHtmlClass: (preset) => `zw ts-${preset.id}`,
|
|
35
|
+
makePresetCssClass: (preset) => `.zw.ts-${preset.id}`,
|
|
36
|
+
render: () => ''
|
|
37
|
+
}
|
|
33
38
|
}),
|
|
34
39
|
MockFontWeight
|
|
35
40
|
]
|
|
@@ -4,7 +4,7 @@ import { DOMParser } from 'prosemirror-model';
|
|
|
4
4
|
import { buildExtensions } from '../extensions';
|
|
5
5
|
import { Devices } from '../enums';
|
|
6
6
|
import { ContentNormalizer } from './normalizer';
|
|
7
|
-
import { ContextWindow } from './
|
|
7
|
+
import { ContextWindow } from './ContextWindow';
|
|
8
8
|
|
|
9
9
|
export class ContentSerializer {
|
|
10
10
|
static build({ config, nodeDomParser }) {
|
|
File without changes
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Devices } from '../enums';
|
|
2
|
+
import { ContextWindow } from './ContextWindow';
|
|
3
|
+
|
|
4
|
+
export class StylePresetRenderer {
|
|
5
|
+
#baseClass;
|
|
6
|
+
#makeVariable;
|
|
7
|
+
#linkPresetId;
|
|
8
|
+
|
|
9
|
+
constructor({ baseClass, makeVariable, linkPresetId }) {
|
|
10
|
+
this.#baseClass = baseClass;
|
|
11
|
+
this.#makeVariable = makeVariable;
|
|
12
|
+
this.#linkPresetId = linkPresetId;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
inject(hostEl, presets) {
|
|
16
|
+
let styleEl = hostEl.querySelector('[data-zw-styles]');
|
|
17
|
+
|
|
18
|
+
if (styleEl) return;
|
|
19
|
+
|
|
20
|
+
styleEl = ContextWindow.document.createElement('style');
|
|
21
|
+
styleEl.dataset.zwStyles = '';
|
|
22
|
+
styleEl.innerHTML = this.render(presets);
|
|
23
|
+
|
|
24
|
+
hostEl.append(styleEl);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
render(presets) {
|
|
28
|
+
let css = '';
|
|
29
|
+
|
|
30
|
+
for (const preset of presets) {
|
|
31
|
+
const isLink = preset.id === this.#linkPresetId;
|
|
32
|
+
const className = this.makePresetCssClass(preset);
|
|
33
|
+
|
|
34
|
+
css += ` ${className} {`;
|
|
35
|
+
|
|
36
|
+
for (const device of Devices.values) {
|
|
37
|
+
for (const setting of Object.keys(preset[device])) {
|
|
38
|
+
const variable = this.#makeVariable({ device, preset, property: setting });
|
|
39
|
+
const internalVariable = this.#makeInternalVariableName(setting, device);
|
|
40
|
+
|
|
41
|
+
css += `${internalVariable}: var(${variable}, inherit);`;
|
|
42
|
+
|
|
43
|
+
// Encapsulate link styles in editor from parent
|
|
44
|
+
|
|
45
|
+
if (isLink) {
|
|
46
|
+
const overrideVariable = internalVariable.replace('preset-', '');
|
|
47
|
+
|
|
48
|
+
css += `${overrideVariable}: var(${internalVariable});`;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
css += '}';
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return css;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
#makeInternalVariableName(setting, device) {
|
|
60
|
+
const property = setting === 'color' ? 'font-color' : setting.replace(/_/i, '-');
|
|
61
|
+
const prefix = device === Devices.COMMON ? '' : `-${device}`;
|
|
62
|
+
|
|
63
|
+
return `--zw-preset-${property}${prefix}`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
makePresetHtmlClass(preset) {
|
|
67
|
+
return this.#baseClass + preset.id;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
makePresetCssClass(preset) {
|
|
71
|
+
return this.makePresetHtmlClass(preset).split(' ').map((part) => `.${part}`).join('');
|
|
72
|
+
}
|
|
73
|
+
}
|