@zipify/wysiwyg 1.0.0-dev.4 → 1.0.0-dev.42

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.
Files changed (217) hide show
  1. package/.editorconfig +1 -1
  2. package/.eslintignore +1 -0
  3. package/.eslintrc.js +2 -2
  4. package/.github/dependabot.yaml +1 -0
  5. package/.lintstagedrc +2 -2
  6. package/.release-it.json +3 -2
  7. package/.stylelintignore +1 -0
  8. package/.stylelintrc +0 -4
  9. package/README.md +5 -3
  10. package/config/jest/setupTests.js +7 -4
  11. package/config/vite/lib.config.js +31 -0
  12. package/config/vite/settings.js +9 -0
  13. package/config/webpack/example.config.js +2 -0
  14. package/config/webpack/lib.config.js +43 -0
  15. package/config/webpack/loaders/style-loader.js +3 -1
  16. package/config/webpack/loaders/svg-loader.js +1 -1
  17. package/dist/wysiwyg.css +1 -0
  18. package/dist/wysiwyg.mjs +18198 -0
  19. package/example/ExampleApp.vue +52 -33
  20. package/example/example.js +25 -2
  21. package/example/pageBlocks.js +31 -0
  22. package/example/presets.js +4 -2
  23. package/lib/Wysiwyg.vue +42 -22
  24. package/lib/__tests__/utils/withComponentContext.js +1 -1
  25. package/lib/assets/icons/alignment-center.svg +3 -0
  26. package/lib/assets/icons/alignment-justify.svg +3 -0
  27. package/lib/assets/icons/alignment-left.svg +3 -0
  28. package/lib/assets/icons/alignment-right.svg +3 -0
  29. package/lib/assets/icons/arrow.svg +3 -0
  30. package/lib/assets/icons/background-color.svg +3 -0
  31. package/lib/assets/icons/case-style.svg +3 -0
  32. package/lib/assets/icons/font-color.svg +5 -0
  33. package/lib/assets/icons/italic.svg +3 -0
  34. package/lib/assets/icons/line-height.svg +3 -0
  35. package/lib/assets/icons/link.svg +3 -0
  36. package/lib/assets/icons/list-circle.svg +3 -0
  37. package/lib/assets/icons/list-decimal.svg +3 -0
  38. package/lib/assets/icons/list-disc.svg +3 -0
  39. package/lib/assets/icons/list-latin.svg +3 -0
  40. package/lib/assets/icons/list-roman.svg +3 -0
  41. package/lib/assets/icons/list-square.svg +3 -0
  42. package/lib/assets/icons/remove-format.svg +3 -0
  43. package/lib/assets/icons/reset-styles.svg +3 -0
  44. package/lib/assets/icons/strike-through.svg +3 -0
  45. package/lib/assets/icons/superscript.svg +3 -0
  46. package/lib/assets/icons/underline.svg +3 -0
  47. package/lib/assets/icons/unlink.svg +3 -0
  48. package/lib/components/base/Button.vue +22 -2
  49. package/lib/components/base/Checkbox.vue +89 -0
  50. package/lib/components/base/FieldLabel.vue +2 -1
  51. package/lib/components/base/Icon.vue +19 -11
  52. package/lib/components/base/Modal.vue +1 -2
  53. package/lib/components/base/NumberField.vue +2 -2
  54. package/lib/components/base/Range.vue +1 -1
  55. package/lib/components/base/ScrollView.vue +2 -2
  56. package/lib/components/base/TextField.vue +106 -0
  57. package/lib/components/base/__tests__/Icon.test.js +6 -13
  58. package/lib/components/base/__tests__/Modal.test.js +8 -2
  59. package/lib/components/base/__tests__/TextField.test.js +57 -0
  60. package/lib/components/base/__tests__/__snapshots__/TextField.test.js.snap +9 -0
  61. package/lib/components/base/colorPicker/ColorPicker.vue +1 -1
  62. package/lib/components/base/colorPicker/composables/__tests__/usePickerApi.test.js +1 -1
  63. package/lib/components/base/colorPicker/composables/usePickerApi.js +1 -1
  64. package/lib/components/base/colorPicker/composables/usePickerHotkeys.js +3 -2
  65. package/lib/components/base/composables/__tests__/useActivatedListener.test.js +1 -1
  66. package/lib/components/base/composables/__tests__/useDeselectionLock.test.js +1 -1
  67. package/lib/components/base/composables/__tests__/useElementRef.test.js +1 -1
  68. package/lib/components/base/composables/__tests__/useModalToggler.test.js +1 -1
  69. package/lib/components/base/composables/__tests__/useNumberValue.test.js +1 -1
  70. package/lib/components/base/composables/__tests__/useScrollView.test.js +1 -1
  71. package/lib/components/base/composables/__tests__/useTempValue.test.js +1 -1
  72. package/lib/components/base/composables/index.js +1 -0
  73. package/lib/components/base/composables/useActivatedListener.js +1 -1
  74. package/lib/components/base/composables/useDeselectionLock.js +1 -1
  75. package/lib/components/base/composables/useElementRef.js +1 -1
  76. package/lib/components/base/composables/useModalToggler.js +1 -1
  77. package/lib/components/base/composables/useScrollView.js +1 -1
  78. package/lib/components/base/composables/useTempValue.js +1 -1
  79. package/lib/components/base/composables/useValidator.js +19 -0
  80. package/lib/components/base/dropdown/Dropdown.vue +16 -4
  81. package/lib/components/base/dropdown/DropdownActivator.vue +19 -3
  82. package/lib/components/base/dropdown/DropdownGroup.vue +1 -1
  83. package/lib/components/base/dropdown/DropdownMenu.vue +1 -1
  84. package/lib/components/base/dropdown/DropdownOption.vue +1 -1
  85. package/lib/components/base/dropdown/__tests__/DropdownActivator.test.js +1 -1
  86. package/lib/components/base/dropdown/__tests__/DropdownMenu.test.js +1 -1
  87. package/lib/components/base/dropdown/__tests__/DropdownOption.test.js +1 -1
  88. package/lib/components/base/dropdown/composables/__tests__/useActiveOptionManager.test.js +1 -1
  89. package/lib/components/base/dropdown/composables/__tests__/useDropdownEntityTitle.test.js +1 -1
  90. package/lib/components/base/dropdown/composables/useActiveOptionManager.js +1 -1
  91. package/lib/components/base/dropdown/composables/useDropdownEntityTitle.js +1 -1
  92. package/lib/components/base/index.js +3 -1
  93. package/lib/components/toolbar/Toolbar.vue +49 -9
  94. package/lib/components/toolbar/ToolbarDivider.vue +1 -1
  95. package/lib/components/toolbar/ToolbarFull.vue +10 -2
  96. package/lib/components/toolbar/__tests__/Toolbar.test.js +8 -1
  97. package/lib/components/toolbar/controls/AlignmentControl.vue +1 -1
  98. package/lib/components/toolbar/controls/AlignmentDeviceControl.vue +1 -1
  99. package/lib/components/toolbar/controls/BackgroundColorControl.vue +1 -1
  100. package/lib/components/toolbar/controls/CaseStyleControl.vue +1 -1
  101. package/lib/components/toolbar/controls/FontColorControl.vue +1 -1
  102. package/lib/components/toolbar/controls/FontFamilyControl.vue +1 -1
  103. package/lib/components/toolbar/controls/FontSizeControl.vue +8 -1
  104. package/lib/components/toolbar/controls/FontWeightControl.vue +1 -1
  105. package/lib/components/toolbar/controls/ItalicControl.vue +1 -1
  106. package/lib/components/toolbar/controls/LineHeightControl.vue +1 -1
  107. package/lib/components/toolbar/controls/ListControl.vue +2 -6
  108. package/lib/components/toolbar/controls/RemoveFormatControl.vue +1 -1
  109. package/lib/components/toolbar/controls/StrikeThroughControl.vue +1 -1
  110. package/lib/components/toolbar/controls/StylePresetControl.vue +1 -1
  111. package/lib/components/toolbar/controls/SuperscriptControl.vue +1 -1
  112. package/lib/components/toolbar/controls/UnderlineControl.vue +2 -2
  113. package/lib/components/toolbar/controls/__tests__/AlignmentControl.test.js +1 -1
  114. package/lib/components/toolbar/controls/__tests__/AlignmentDeviceControl.test.js +1 -1
  115. package/lib/components/toolbar/controls/__tests__/BackgroundColorControl.test.js +1 -1
  116. package/lib/components/toolbar/controls/__tests__/CaseStyleControl.test.js +1 -1
  117. package/lib/components/toolbar/controls/__tests__/FontColorControl.test.js +1 -1
  118. package/lib/components/toolbar/controls/__tests__/FontFamilyControl.test.js +1 -1
  119. package/lib/components/toolbar/controls/__tests__/FontSizeControl.test.js +1 -1
  120. package/lib/components/toolbar/controls/__tests__/FontWeightControl.test.js +1 -1
  121. package/lib/components/toolbar/controls/__tests__/ItalicControl.test.js +1 -1
  122. package/lib/components/toolbar/controls/__tests__/LineHeightControl.test.js +1 -1
  123. package/lib/components/toolbar/controls/__tests__/ListControl.test.js +1 -1
  124. package/lib/components/toolbar/controls/__tests__/StrikeThroughControl.test.js +1 -1
  125. package/lib/components/toolbar/controls/__tests__/StylePresetControl.test.js +1 -1
  126. package/lib/components/toolbar/controls/__tests__/UnderlineControl.test.js +5 -1
  127. package/lib/components/toolbar/controls/composables/useRecentFonts.js +1 -1
  128. package/lib/components/toolbar/controls/index.js +1 -0
  129. package/lib/components/toolbar/controls/link/LinkControl.vue +152 -0
  130. package/lib/components/toolbar/controls/link/LinkControlApply.vue +35 -0
  131. package/lib/components/toolbar/controls/link/LinkControlHeader.vue +67 -0
  132. package/lib/components/toolbar/controls/link/composables/index.js +1 -0
  133. package/lib/components/toolbar/controls/link/composables/useLink.js +61 -0
  134. package/lib/components/toolbar/controls/link/destination/LinkControlDestination.vue +103 -0
  135. package/lib/components/toolbar/controls/link/destination/LinkControlPageBlock.vue +54 -0
  136. package/lib/components/toolbar/controls/link/destination/LinkControlUrl.vue +52 -0
  137. package/lib/components/toolbar/controls/link/destination/index.js +1 -0
  138. package/lib/components/toolbar/controls/link/index.js +1 -0
  139. package/lib/composables/__tests__/useEditor.test.js +15 -6
  140. package/lib/composables/useEditor.js +13 -8
  141. package/lib/composables/useToolbar.js +14 -29
  142. package/lib/directives/outClick.js +20 -4
  143. package/lib/enums/LinkDestinations.js +4 -0
  144. package/lib/enums/LinkTargets.js +4 -0
  145. package/lib/enums/TextSettings.js +3 -1
  146. package/lib/enums/index.js +2 -0
  147. package/lib/extensions/Alignment.js +22 -4
  148. package/lib/extensions/BackgroundColor.js +17 -2
  149. package/lib/extensions/DeviceManager.js +2 -5
  150. package/lib/extensions/FontColor.js +17 -2
  151. package/lib/extensions/FontFamily.js +27 -3
  152. package/lib/extensions/FontSize.js +29 -4
  153. package/lib/extensions/FontStyle.js +24 -3
  154. package/lib/extensions/FontWeight.js +34 -2
  155. package/lib/extensions/LineHeight.js +30 -4
  156. package/lib/extensions/Link.js +101 -0
  157. package/lib/extensions/StylePreset.js +38 -15
  158. package/lib/extensions/TextDecoration.js +30 -4
  159. package/lib/extensions/__tests__/Alignment.test.js +32 -5
  160. package/lib/extensions/__tests__/BackgroundColor.test.js +39 -4
  161. package/lib/extensions/__tests__/CaseStyle.test.js +4 -3
  162. package/lib/extensions/__tests__/FontColor.test.js +39 -4
  163. package/lib/extensions/__tests__/FontFamily.test.js +60 -6
  164. package/lib/extensions/__tests__/FontSize.test.js +40 -5
  165. package/lib/extensions/__tests__/FontStyle.test.js +47 -4
  166. package/lib/extensions/__tests__/FontWeight.test.js +67 -4
  167. package/lib/extensions/__tests__/LineHeight.test.js +51 -5
  168. package/lib/extensions/__tests__/StylePreset.test.js +144 -6
  169. package/lib/extensions/__tests__/TextDecoration.test.js +88 -4
  170. package/lib/extensions/__tests__/__snapshots__/Alignment.test.js.snap +70 -2
  171. package/lib/extensions/__tests__/__snapshots__/BackgroundColor.test.js.snap +121 -1
  172. package/lib/extensions/__tests__/__snapshots__/FontColor.test.js.snap +109 -1
  173. package/lib/extensions/__tests__/__snapshots__/FontFamily.test.js.snap +179 -1
  174. package/lib/extensions/__tests__/__snapshots__/FontSize.test.js.snap +132 -2
  175. package/lib/extensions/__tests__/__snapshots__/FontStyle.test.js.snap +142 -1
  176. package/lib/extensions/__tests__/__snapshots__/FontWeight.test.js.snap +179 -1
  177. package/lib/extensions/__tests__/__snapshots__/LineHeight.test.js.snap +118 -2
  178. package/lib/extensions/__tests__/__snapshots__/StylePreset.test.js.snap +171 -2
  179. package/lib/extensions/__tests__/__snapshots__/TextDecoration.test.js.snap +300 -3
  180. package/lib/extensions/core/CopyPasteProcessor.js +10 -0
  181. package/lib/extensions/core/NodeProcessor.js +1 -1
  182. package/lib/extensions/core/TextProcessor.js +10 -0
  183. package/lib/extensions/core/__tests__/NodeProcessor.test.js +4 -3
  184. package/lib/extensions/core/__tests__/SelectionProcessor.test.js +9 -6
  185. package/lib/extensions/core/__tests__/TextProcessor.test.js +139 -10
  186. package/lib/extensions/core/__tests__/__snapshots__/TextProcessor.test.js.snap +26 -0
  187. package/lib/extensions/core/index.js +11 -2
  188. package/lib/extensions/core/plugins/PastePlugin.js +48 -0
  189. package/lib/extensions/core/plugins/ProseMirrorPlugin.js +20 -0
  190. package/lib/extensions/core/plugins/index.js +1 -0
  191. package/lib/extensions/index.js +41 -33
  192. package/lib/extensions/list/List.js +35 -1
  193. package/lib/extensions/list/__tests__/List.test.js +117 -8
  194. package/lib/extensions/list/__tests__/__snapshots__/List.test.js.snap +481 -0
  195. package/lib/injectionTokens.js +2 -1
  196. package/lib/services/ContentNormalizer.js +157 -0
  197. package/lib/services/ContextWidnow.js +23 -0
  198. package/lib/services/Storage.js +1 -13
  199. package/lib/services/__tests__/ContentNormalizer.test.js +74 -0
  200. package/lib/services/__tests__/FavoriteColors.test.js +20 -0
  201. package/lib/services/__tests__/JsonSerializer.test.js +23 -0
  202. package/lib/services/__tests__/Storage.test.js +79 -0
  203. package/lib/services/index.js +2 -0
  204. package/lib/styles/content.css +96 -9
  205. package/lib/styles/helpers/offsets.css +16 -0
  206. package/lib/styles/variables.css +6 -0
  207. package/lib/utils/__tests__/__snapshots__/renderInlineSetting.test.js.snap +4 -4
  208. package/lib/utils/__tests__/convertColor.test.js +19 -0
  209. package/lib/utils/__tests__/createKeyboardShortcut.test.js +25 -0
  210. package/lib/utils/__tests__/renderInlineSetting.test.js +26 -0
  211. package/lib/utils/convertColor.js +7 -0
  212. package/lib/utils/importIcon.js +13 -0
  213. package/lib/utils/index.js +2 -0
  214. package/lib/utils/renderInlineSetting.js +2 -2
  215. package/package.json +21 -16
  216. package/lib/assets/icons.svg +0 -69
  217. package/lib/composables/__tests__/useToolbar.test.js +0 -56
@@ -210,3 +210,484 @@ Object {
210
210
  "type": "doc",
211
211
  }
212
212
  `;
213
+
214
+ exports[`parsing html should parse circle type by class 1`] = `
215
+ Object {
216
+ "content": Array [
217
+ Object {
218
+ "attrs": Object {
219
+ "bullet": Object {
220
+ "type": "circle",
221
+ },
222
+ },
223
+ "content": Array [
224
+ Object {
225
+ "content": Array [
226
+ Object {
227
+ "attrs": Object {
228
+ "preset": Object {
229
+ "id": "regular-1",
230
+ },
231
+ },
232
+ "content": Array [
233
+ Object {
234
+ "text": "lorem ipsum",
235
+ "type": "text",
236
+ },
237
+ ],
238
+ "type": "paragraph",
239
+ },
240
+ ],
241
+ "type": "listItem",
242
+ },
243
+ ],
244
+ "type": "list",
245
+ },
246
+ ],
247
+ "type": "doc",
248
+ }
249
+ `;
250
+
251
+ exports[`parsing html should parse decimal as default 1`] = `
252
+ Object {
253
+ "content": Array [
254
+ Object {
255
+ "attrs": Object {
256
+ "bullet": Object {
257
+ "type": "decimal",
258
+ },
259
+ },
260
+ "content": Array [
261
+ Object {
262
+ "content": Array [
263
+ Object {
264
+ "attrs": Object {
265
+ "preset": Object {
266
+ "id": "regular-1",
267
+ },
268
+ },
269
+ "content": Array [
270
+ Object {
271
+ "text": "lorem ipsum",
272
+ "type": "text",
273
+ },
274
+ ],
275
+ "type": "paragraph",
276
+ },
277
+ ],
278
+ "type": "listItem",
279
+ },
280
+ ],
281
+ "type": "list",
282
+ },
283
+ ],
284
+ "type": "doc",
285
+ }
286
+ `;
287
+
288
+ exports[`parsing html should parse decimal type by attribute 1`] = `
289
+ Object {
290
+ "content": Array [
291
+ Object {
292
+ "attrs": Object {
293
+ "bullet": Object {
294
+ "type": "decimal",
295
+ },
296
+ },
297
+ "content": Array [
298
+ Object {
299
+ "content": Array [
300
+ Object {
301
+ "attrs": Object {
302
+ "preset": Object {
303
+ "id": "regular-1",
304
+ },
305
+ },
306
+ "content": Array [
307
+ Object {
308
+ "text": "lorem ipsum",
309
+ "type": "text",
310
+ },
311
+ ],
312
+ "type": "paragraph",
313
+ },
314
+ ],
315
+ "type": "listItem",
316
+ },
317
+ ],
318
+ "type": "list",
319
+ },
320
+ ],
321
+ "type": "doc",
322
+ }
323
+ `;
324
+
325
+ exports[`parsing html should parse decimal type by class 1`] = `
326
+ Object {
327
+ "content": Array [
328
+ Object {
329
+ "attrs": Object {
330
+ "bullet": Object {
331
+ "type": "decimal",
332
+ },
333
+ },
334
+ "content": Array [
335
+ Object {
336
+ "content": Array [
337
+ Object {
338
+ "attrs": Object {
339
+ "preset": Object {
340
+ "id": "regular-1",
341
+ },
342
+ },
343
+ "content": Array [
344
+ Object {
345
+ "text": "lorem ipsum",
346
+ "type": "text",
347
+ },
348
+ ],
349
+ "type": "paragraph",
350
+ },
351
+ ],
352
+ "type": "listItem",
353
+ },
354
+ ],
355
+ "type": "list",
356
+ },
357
+ ],
358
+ "type": "doc",
359
+ }
360
+ `;
361
+
362
+ exports[`parsing html should parse disc as default 1`] = `
363
+ Object {
364
+ "content": Array [
365
+ Object {
366
+ "attrs": Object {
367
+ "bullet": Object {
368
+ "type": "disc",
369
+ },
370
+ },
371
+ "content": Array [
372
+ Object {
373
+ "content": Array [
374
+ Object {
375
+ "attrs": Object {
376
+ "preset": Object {
377
+ "id": "regular-1",
378
+ },
379
+ },
380
+ "content": Array [
381
+ Object {
382
+ "text": "lorem ipsum",
383
+ "type": "text",
384
+ },
385
+ ],
386
+ "type": "paragraph",
387
+ },
388
+ ],
389
+ "type": "listItem",
390
+ },
391
+ ],
392
+ "type": "list",
393
+ },
394
+ ],
395
+ "type": "doc",
396
+ }
397
+ `;
398
+
399
+ exports[`parsing html should parse disc type by class 1`] = `
400
+ Object {
401
+ "content": Array [
402
+ Object {
403
+ "attrs": Object {
404
+ "bullet": Object {
405
+ "type": "disc",
406
+ },
407
+ },
408
+ "content": Array [
409
+ Object {
410
+ "content": Array [
411
+ Object {
412
+ "attrs": Object {
413
+ "preset": Object {
414
+ "id": "regular-1",
415
+ },
416
+ },
417
+ "content": Array [
418
+ Object {
419
+ "text": "lorem ipsum",
420
+ "type": "text",
421
+ },
422
+ ],
423
+ "type": "paragraph",
424
+ },
425
+ ],
426
+ "type": "listItem",
427
+ },
428
+ ],
429
+ "type": "list",
430
+ },
431
+ ],
432
+ "type": "doc",
433
+ }
434
+ `;
435
+
436
+ exports[`parsing html should parse latin type by class 1`] = `
437
+ Object {
438
+ "content": Array [
439
+ Object {
440
+ "attrs": Object {
441
+ "bullet": Object {
442
+ "type": "latin",
443
+ },
444
+ },
445
+ "content": Array [
446
+ Object {
447
+ "content": Array [
448
+ Object {
449
+ "attrs": Object {
450
+ "preset": Object {
451
+ "id": "regular-1",
452
+ },
453
+ },
454
+ "content": Array [
455
+ Object {
456
+ "text": "lorem ipsum",
457
+ "type": "text",
458
+ },
459
+ ],
460
+ "type": "paragraph",
461
+ },
462
+ ],
463
+ "type": "listItem",
464
+ },
465
+ ],
466
+ "type": "list",
467
+ },
468
+ ],
469
+ "type": "doc",
470
+ }
471
+ `;
472
+
473
+ exports[`parsing html should parse latin type by lower attribute 1`] = `
474
+ Object {
475
+ "content": Array [
476
+ Object {
477
+ "attrs": Object {
478
+ "bullet": Object {
479
+ "type": "latin",
480
+ },
481
+ },
482
+ "content": Array [
483
+ Object {
484
+ "content": Array [
485
+ Object {
486
+ "attrs": Object {
487
+ "preset": Object {
488
+ "id": "regular-1",
489
+ },
490
+ },
491
+ "content": Array [
492
+ Object {
493
+ "text": "lorem ipsum",
494
+ "type": "text",
495
+ },
496
+ ],
497
+ "type": "paragraph",
498
+ },
499
+ ],
500
+ "type": "listItem",
501
+ },
502
+ ],
503
+ "type": "list",
504
+ },
505
+ ],
506
+ "type": "doc",
507
+ }
508
+ `;
509
+
510
+ exports[`parsing html should parse latin type by upper attribute 1`] = `
511
+ Object {
512
+ "content": Array [
513
+ Object {
514
+ "attrs": Object {
515
+ "bullet": Object {
516
+ "type": "latin",
517
+ },
518
+ },
519
+ "content": Array [
520
+ Object {
521
+ "content": Array [
522
+ Object {
523
+ "attrs": Object {
524
+ "preset": Object {
525
+ "id": "regular-1",
526
+ },
527
+ },
528
+ "content": Array [
529
+ Object {
530
+ "text": "lorem ipsum",
531
+ "type": "text",
532
+ },
533
+ ],
534
+ "type": "paragraph",
535
+ },
536
+ ],
537
+ "type": "listItem",
538
+ },
539
+ ],
540
+ "type": "list",
541
+ },
542
+ ],
543
+ "type": "doc",
544
+ }
545
+ `;
546
+
547
+ exports[`parsing html should parse roman type by class 1`] = `
548
+ Object {
549
+ "content": Array [
550
+ Object {
551
+ "attrs": Object {
552
+ "bullet": Object {
553
+ "type": "roman",
554
+ },
555
+ },
556
+ "content": Array [
557
+ Object {
558
+ "content": Array [
559
+ Object {
560
+ "attrs": Object {
561
+ "preset": Object {
562
+ "id": "regular-1",
563
+ },
564
+ },
565
+ "content": Array [
566
+ Object {
567
+ "text": "lorem ipsum",
568
+ "type": "text",
569
+ },
570
+ ],
571
+ "type": "paragraph",
572
+ },
573
+ ],
574
+ "type": "listItem",
575
+ },
576
+ ],
577
+ "type": "list",
578
+ },
579
+ ],
580
+ "type": "doc",
581
+ }
582
+ `;
583
+
584
+ exports[`parsing html should parse roman type by lower attribute 1`] = `
585
+ Object {
586
+ "content": Array [
587
+ Object {
588
+ "attrs": Object {
589
+ "bullet": Object {
590
+ "type": "roman",
591
+ },
592
+ },
593
+ "content": Array [
594
+ Object {
595
+ "content": Array [
596
+ Object {
597
+ "attrs": Object {
598
+ "preset": Object {
599
+ "id": "regular-1",
600
+ },
601
+ },
602
+ "content": Array [
603
+ Object {
604
+ "text": "lorem ipsum",
605
+ "type": "text",
606
+ },
607
+ ],
608
+ "type": "paragraph",
609
+ },
610
+ ],
611
+ "type": "listItem",
612
+ },
613
+ ],
614
+ "type": "list",
615
+ },
616
+ ],
617
+ "type": "doc",
618
+ }
619
+ `;
620
+
621
+ exports[`parsing html should parse roman type by upper attribute 1`] = `
622
+ Object {
623
+ "content": Array [
624
+ Object {
625
+ "attrs": Object {
626
+ "bullet": Object {
627
+ "type": "roman",
628
+ },
629
+ },
630
+ "content": Array [
631
+ Object {
632
+ "content": Array [
633
+ Object {
634
+ "attrs": Object {
635
+ "preset": Object {
636
+ "id": "regular-1",
637
+ },
638
+ },
639
+ "content": Array [
640
+ Object {
641
+ "text": "lorem ipsum",
642
+ "type": "text",
643
+ },
644
+ ],
645
+ "type": "paragraph",
646
+ },
647
+ ],
648
+ "type": "listItem",
649
+ },
650
+ ],
651
+ "type": "list",
652
+ },
653
+ ],
654
+ "type": "doc",
655
+ }
656
+ `;
657
+
658
+ exports[`parsing html should parse square type by class 1`] = `
659
+ Object {
660
+ "content": Array [
661
+ Object {
662
+ "attrs": Object {
663
+ "bullet": Object {
664
+ "type": "square",
665
+ },
666
+ },
667
+ "content": Array [
668
+ Object {
669
+ "content": Array [
670
+ Object {
671
+ "attrs": Object {
672
+ "preset": Object {
673
+ "id": "regular-1",
674
+ },
675
+ },
676
+ "content": Array [
677
+ Object {
678
+ "text": "lorem ipsum",
679
+ "type": "text",
680
+ },
681
+ ],
682
+ "type": "paragraph",
683
+ },
684
+ ],
685
+ "type": "listItem",
686
+ },
687
+ ],
688
+ "type": "list",
689
+ },
690
+ ],
691
+ "type": "doc",
692
+ }
693
+ `;
@@ -3,5 +3,6 @@ export const InjectionTokens = Object.freeze({
3
3
  FONT_SIZES: Symbol('fontSizes'),
4
4
  EDITOR: Symbol('editor'),
5
5
  LOCAL_STORAGE: Symbol('localStorage'),
6
- FAVORITE_COLORS: Symbol('favoriteColors')
6
+ FAVORITE_COLORS: Symbol('favoriteColors'),
7
+ PAGE_BLOCKS: Symbol('pageBlocks')
7
8
  });
@@ -0,0 +1,157 @@
1
+ import { ContextWindow } from './ContextWidnow';
2
+
3
+ export class ContentNormalizer {
4
+ static BLOCK_STYLES = ['text-align', 'line-height'];
5
+
6
+ static normalize(content) {
7
+ return new ContentNormalizer(content).normalize();
8
+ }
9
+
10
+ constructor(content) {
11
+ this._content = content;
12
+ this._dom = null;
13
+ }
14
+
15
+ normalize() {
16
+ if (typeof this._content !== 'string') {
17
+ return this._content;
18
+ }
19
+ return this._normalizeTextContent();
20
+ }
21
+
22
+ _normalizeTextContent() {
23
+ this._dom = new DOMParser().parseFromString(this._content, 'text/html');
24
+
25
+ this._iterateNodes(this._normalizeListItems.bind(this), (node) => node.tagName === 'LI');
26
+ this._iterateNodes(this._normalizeSettingsStructure.bind(this), (node) => node.tagName === 'SPAN');
27
+ this._iterateNodes(this._normalizeStyles.bind(this), (node) => node.tagName !== 'SPAN');
28
+
29
+ return this._dom.body.innerHTML;
30
+ }
31
+
32
+ _iterateNodes(handler, condition) {
33
+ const iterator = this._dom.createNodeIterator(this._dom.body, NodeFilter.SHOW_ELEMENT, {
34
+ acceptNode: (node) => condition(node) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_REJECT
35
+ });
36
+ let currentNode = iterator.nextNode();
37
+
38
+ while (currentNode) {
39
+ handler(currentNode);
40
+ currentNode = iterator.nextNode();
41
+ }
42
+ }
43
+
44
+ _normalizeListItems(itemEl) {
45
+ const fragment = new DocumentFragment();
46
+ const children = Array.from(itemEl.childNodes);
47
+ let capturingParagraph;
48
+
49
+ const append = (node) => {
50
+ this._assignElementProperties(node, itemEl, ContentNormalizer.BLOCK_STYLES);
51
+ fragment.append(node);
52
+ };
53
+
54
+ for (const node of children) {
55
+ if (node.tagName === 'P') {
56
+ append(node);
57
+ capturingParagraph = null;
58
+ continue;
59
+ }
60
+
61
+ if (!capturingParagraph) {
62
+ capturingParagraph = document.createElement('p');
63
+ append(capturingParagraph);
64
+ }
65
+
66
+ capturingParagraph.append(node);
67
+ }
68
+
69
+ itemEl.append(fragment);
70
+ this._removeStyleProperties(itemEl, ContentNormalizer.BLOCK_STYLES);
71
+ }
72
+
73
+ _normalizeSettingsStructure(element) {
74
+ const isTextChildren = Array.from(element.childNodes)
75
+ .every((node) => node.nodeType === Node.TEXT_NODE);
76
+
77
+ if (isTextChildren) return;
78
+
79
+ const cloned = element.cloneNode(true);
80
+ const migratingStyles = this._getMigratingStyles(element, { customProperties: true });
81
+ const content = [];
82
+
83
+ for (const node of cloned.childNodes) {
84
+ let child = node;
85
+
86
+ if (migratingStyles.length) {
87
+ child = this._wrapTextNode(cloned, node);
88
+ this._assignElementProperties(child, cloned, migratingStyles);
89
+ }
90
+
91
+ content.push(child);
92
+ }
93
+
94
+ element.replaceWith(...content);
95
+ }
96
+
97
+ _normalizeStyles(element) {
98
+ const properties = this._getMigratingStyles(element);
99
+
100
+ for (const node of element.childNodes) {
101
+ const child = this._wrapTextNode(element, node);
102
+
103
+ this._assignElementProperties(child, element, properties);
104
+ }
105
+
106
+ this._removeStyleProperties(element, properties);
107
+ }
108
+
109
+ _getMigratingStyles(element, { customProperties } = {}) {
110
+ const blacklist = ContentNormalizer.BLOCK_STYLES;
111
+ const properties = [];
112
+
113
+ for (let index = 0; index < element.style.length; index++) {
114
+ const property = element.style.item(index);
115
+
116
+ if (blacklist.includes(property)) continue;
117
+ if (!customProperties && property.startsWith('--')) continue;
118
+
119
+ properties.push(property);
120
+ }
121
+
122
+ return properties;
123
+ }
124
+
125
+ _wrapTextNode(parent, node) {
126
+ if (node.nodeType !== Node.TEXT_NODE) return node;
127
+
128
+ const span = ContextWindow.document.createElement('span');
129
+
130
+ span.append(node.cloneNode());
131
+ parent.replaceChild(span, node);
132
+
133
+ return span;
134
+ }
135
+
136
+ _assignElementProperties(target, source, properties) {
137
+ for (const property of properties) {
138
+ if (target.style.getPropertyValue(property)) {
139
+ continue;
140
+ }
141
+
142
+ const value = source.style.getPropertyValue(property);
143
+
144
+ if (value) target.style.setProperty(property, value);
145
+ }
146
+ }
147
+
148
+ _removeStyleProperties(element, properties) {
149
+ for (const property of properties) {
150
+ element.style.removeProperty(property);
151
+ }
152
+
153
+ if (element.style.length === 0) {
154
+ element.removeAttribute('style');
155
+ }
156
+ }
157
+ }
@@ -0,0 +1,23 @@
1
+ export class ContextWindow {
2
+ static window = window;
3
+
4
+ static use(window) {
5
+ this.window = window;
6
+ }
7
+
8
+ static get document() {
9
+ return this.window.document;
10
+ }
11
+
12
+ static get body() {
13
+ return this.document.body;
14
+ }
15
+
16
+ static get head() {
17
+ return this.document.head;
18
+ }
19
+
20
+ static getComputedStyle(element) {
21
+ return this.window.getComputedStyle(element);
22
+ }
23
+ }
@@ -17,19 +17,11 @@ export class Storage {
17
17
  }
18
18
 
19
19
  getItem(key) {
20
- const json = this._getItemFromStorage(key);
20
+ const json = this.accessToStorage((storage) => storage.getItem(this.makeKey(key)));
21
21
 
22
22
  return JsonSerializer.decode(json);
23
23
  }
24
24
 
25
- removeItem(key) {
26
- this.accessToStorage((storage) => storage.removeItem(this.makeKey(key)));
27
- }
28
-
29
- hasItem(key) {
30
- return !!this._getItemFromStorage(key);
31
- }
32
-
33
25
  accessToStorage(action) {
34
26
  try {
35
27
  return action(this.nativeStorage);
@@ -38,10 +30,6 @@ export class Storage {
38
30
  }
39
31
  }
40
32
 
41
- _getItemFromStorage(key) {
42
- return this.accessToStorage((storage) => storage.getItem(this.makeKey(key)));
43
- }
44
-
45
33
  onPrivateModeEnabled(error) {
46
34
  // eslint-disable-next-line no-console
47
35
  console.error(error);