@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
@@ -199,8 +199,305 @@ Object {
199
199
  }
200
200
  `;
201
201
 
202
- exports[`rendering should render both 1`] = `"<p class=\\"zw-style\\"><span style=\\"--zw-text-decoration: underline line-through;\\" class=\\"zw-style\\">hello world</span></p>"`;
202
+ exports[`parsing html should get both from paragraph 1`] = `
203
+ Object {
204
+ "content": Array [
205
+ Object {
206
+ "content": Array [
207
+ Object {
208
+ "marks": Array [
209
+ Object {
210
+ "attrs": Object {
211
+ "strike_through": true,
212
+ "underline": true,
213
+ },
214
+ "type": "text_decoration",
215
+ },
216
+ ],
217
+ "text": "test",
218
+ "type": "text",
219
+ },
220
+ ],
221
+ "type": "paragraph",
222
+ },
223
+ ],
224
+ "type": "doc",
225
+ }
226
+ `;
227
+
228
+ exports[`parsing html should get both from rendered view 1`] = `
229
+ Object {
230
+ "content": Array [
231
+ Object {
232
+ "content": Array [
233
+ Object {
234
+ "marks": Array [
235
+ Object {
236
+ "attrs": Object {
237
+ "strike_through": true,
238
+ "underline": true,
239
+ },
240
+ "type": "text_decoration",
241
+ },
242
+ ],
243
+ "text": "lorem",
244
+ "type": "text",
245
+ },
246
+ Object {
247
+ "text": " ipsum",
248
+ "type": "text",
249
+ },
250
+ ],
251
+ "type": "paragraph",
252
+ },
253
+ ],
254
+ "type": "doc",
255
+ }
256
+ `;
257
+
258
+ exports[`parsing html should get both from text 1`] = `
259
+ Object {
260
+ "content": Array [
261
+ Object {
262
+ "content": Array [
263
+ Object {
264
+ "marks": Array [
265
+ Object {
266
+ "attrs": Object {
267
+ "strike_through": true,
268
+ "underline": true,
269
+ },
270
+ "type": "text_decoration",
271
+ },
272
+ ],
273
+ "text": "lorem",
274
+ "type": "text",
275
+ },
276
+ Object {
277
+ "text": " ipsum",
278
+ "type": "text",
279
+ },
280
+ ],
281
+ "type": "paragraph",
282
+ },
283
+ ],
284
+ "type": "doc",
285
+ }
286
+ `;
287
+
288
+ exports[`parsing html should get strike through from paragraph 1`] = `
289
+ Object {
290
+ "content": Array [
291
+ Object {
292
+ "content": Array [
293
+ Object {
294
+ "marks": Array [
295
+ Object {
296
+ "attrs": Object {
297
+ "strike_through": true,
298
+ "underline": false,
299
+ },
300
+ "type": "text_decoration",
301
+ },
302
+ ],
303
+ "text": "test",
304
+ "type": "text",
305
+ },
306
+ ],
307
+ "type": "paragraph",
308
+ },
309
+ ],
310
+ "type": "doc",
311
+ }
312
+ `;
313
+
314
+ exports[`parsing html should get strike through from rendered view 1`] = `
315
+ Object {
316
+ "content": Array [
317
+ Object {
318
+ "content": Array [
319
+ Object {
320
+ "marks": Array [
321
+ Object {
322
+ "attrs": Object {
323
+ "strike_through": true,
324
+ "underline": false,
325
+ },
326
+ "type": "text_decoration",
327
+ },
328
+ ],
329
+ "text": "lorem",
330
+ "type": "text",
331
+ },
332
+ Object {
333
+ "text": " ipsum",
334
+ "type": "text",
335
+ },
336
+ ],
337
+ "type": "paragraph",
338
+ },
339
+ ],
340
+ "type": "doc",
341
+ }
342
+ `;
343
+
344
+ exports[`parsing html should get strike through from text 1`] = `
345
+ Object {
346
+ "content": Array [
347
+ Object {
348
+ "content": Array [
349
+ Object {
350
+ "marks": Array [
351
+ Object {
352
+ "attrs": Object {
353
+ "strike_through": true,
354
+ "underline": false,
355
+ },
356
+ "type": "text_decoration",
357
+ },
358
+ ],
359
+ "text": "lorem",
360
+ "type": "text",
361
+ },
362
+ Object {
363
+ "text": " ipsum",
364
+ "type": "text",
365
+ },
366
+ ],
367
+ "type": "paragraph",
368
+ },
369
+ ],
370
+ "type": "doc",
371
+ }
372
+ `;
373
+
374
+ exports[`parsing html should get underline from paragraph 1`] = `
375
+ Object {
376
+ "content": Array [
377
+ Object {
378
+ "content": Array [
379
+ Object {
380
+ "marks": Array [
381
+ Object {
382
+ "attrs": Object {
383
+ "strike_through": false,
384
+ "underline": true,
385
+ },
386
+ "type": "text_decoration",
387
+ },
388
+ ],
389
+ "text": "test",
390
+ "type": "text",
391
+ },
392
+ ],
393
+ "type": "paragraph",
394
+ },
395
+ ],
396
+ "type": "doc",
397
+ }
398
+ `;
399
+
400
+ exports[`parsing html should get underline from rendered view 1`] = `
401
+ Object {
402
+ "content": Array [
403
+ Object {
404
+ "content": Array [
405
+ Object {
406
+ "marks": Array [
407
+ Object {
408
+ "attrs": Object {
409
+ "strike_through": false,
410
+ "underline": true,
411
+ },
412
+ "type": "text_decoration",
413
+ },
414
+ ],
415
+ "text": "lorem",
416
+ "type": "text",
417
+ },
418
+ Object {
419
+ "text": " ipsum",
420
+ "type": "text",
421
+ },
422
+ ],
423
+ "type": "paragraph",
424
+ },
425
+ ],
426
+ "type": "doc",
427
+ }
428
+ `;
429
+
430
+ exports[`parsing html should get underline from text 1`] = `
431
+ Object {
432
+ "content": Array [
433
+ Object {
434
+ "content": Array [
435
+ Object {
436
+ "marks": Array [
437
+ Object {
438
+ "attrs": Object {
439
+ "strike_through": false,
440
+ "underline": true,
441
+ },
442
+ "type": "text_decoration",
443
+ },
444
+ ],
445
+ "text": "lorem",
446
+ "type": "text",
447
+ },
448
+ Object {
449
+ "text": " ipsum",
450
+ "type": "text",
451
+ },
452
+ ],
453
+ "type": "paragraph",
454
+ },
455
+ ],
456
+ "type": "doc",
457
+ }
458
+ `;
459
+
460
+ exports[`parsing html should merge paragraph and text settings 1`] = `
461
+ Object {
462
+ "content": Array [
463
+ Object {
464
+ "content": Array [
465
+ Object {
466
+ "marks": Array [
467
+ Object {
468
+ "attrs": Object {
469
+ "strike_through": true,
470
+ "underline": false,
471
+ },
472
+ "type": "text_decoration",
473
+ },
474
+ ],
475
+ "text": "lorem",
476
+ "type": "text",
477
+ },
478
+ Object {
479
+ "marks": Array [
480
+ Object {
481
+ "attrs": Object {
482
+ "strike_through": false,
483
+ "underline": true,
484
+ },
485
+ "type": "text_decoration",
486
+ },
487
+ ],
488
+ "text": " ipsum",
489
+ "type": "text",
490
+ },
491
+ ],
492
+ "type": "paragraph",
493
+ },
494
+ ],
495
+ "type": "doc",
496
+ }
497
+ `;
498
+
499
+ exports[`rendering should render both 1`] = `"<p class=\\"zw-style\\"><span style=\\"--zw-text-decoration:underline line-through;\\" class=\\"zw-style\\">hello world</span></p>"`;
203
500
 
204
- exports[`rendering should render strike through only 1`] = `"<p class=\\"zw-style\\"><span style=\\"--zw-text-decoration: line-through;\\" class=\\"zw-style\\">hello world</span></p>"`;
501
+ exports[`rendering should render strike through only 1`] = `"<p class=\\"zw-style\\"><span style=\\"--zw-text-decoration:line-through;\\" class=\\"zw-style\\">hello world</span></p>"`;
205
502
 
206
- exports[`rendering should render underline only 1`] = `"<p class=\\"zw-style\\"><span style=\\"--zw-text-decoration: underline;\\" class=\\"zw-style\\">hello world</span></p>"`;
503
+ exports[`rendering should render underline only 1`] = `"<p class=\\"zw-style\\"><span style=\\"--zw-text-decoration:underline;\\" class=\\"zw-style\\">hello world</span></p>"`;
@@ -0,0 +1,10 @@
1
+ import { Extension } from '@tiptap/vue-2';
2
+ import { PastePlugin } from './plugins';
3
+
4
+ export const CopyPasteProcessor = Extension.create({
5
+ name: 'copy_paste_processor',
6
+
7
+ addProseMirrorPlugins() {
8
+ return [PastePlugin.create()];
9
+ }
10
+ });
@@ -1,5 +1,5 @@
1
1
  import { Extension } from '@tiptap/vue-2';
2
- import { computed } from '@vue/composition-api';
2
+ import { computed } from 'vue';
3
3
  import { createCommand } from '../../utils';
4
4
  import { NodeTypes } from '../../enums';
5
5
 
@@ -17,6 +17,16 @@ export const TextProcessor = Extension.create({
17
17
 
18
18
  addCommands() {
19
19
  return {
20
+ getSelectedText: createCommand(({ state }) => {
21
+ const { from, to } = state.selection;
22
+
23
+ return state.doc.textBetween(from, to, ' ');
24
+ }),
25
+
26
+ unsetMarks: createCommand(({ commands }, marks) => {
27
+ marks.forEach((mark) => commands.unsetMark(mark));
28
+ }),
29
+
20
30
  transformText: createCommand(({ state }, transform) => {
21
31
  const { selection } = state.tr;
22
32
 
@@ -1,7 +1,8 @@
1
1
  import { Editor, Extension } from '@tiptap/vue-2';
2
2
  import { NodeFactory } from '../../../__tests__/utils';
3
- import { CORE_EXTENSIONS } from '../index';
4
3
  import { NodeTypes } from '../../../enums';
4
+ import { ContentNormalizer } from '../../../services';
5
+ import { buildCoreExtensions } from '../index';
5
6
 
6
7
  const LineHeight = Extension.create({
7
8
  name: 'line_height',
@@ -21,8 +22,8 @@ const LineHeight = Extension.create({
21
22
 
22
23
  function createEditor({ content }) {
23
24
  return new Editor({
24
- content,
25
- extensions: CORE_EXTENSIONS.concat(LineHeight) // Included to core extensions
25
+ content: ContentNormalizer.normalize(content),
26
+ extensions: buildCoreExtensions().concat(LineHeight) // Included to core extensions
26
27
  });
27
28
  }
28
29
 
@@ -1,14 +1,17 @@
1
1
  import { Editor } from '@tiptap/vue-2';
2
- import { CORE_EXTENSIONS } from '../index';
3
2
  import { NodeFactory } from '../../../__tests__/utils';
3
+ import { ContentNormalizer } from '../../../services';
4
+ import { buildCoreExtensions } from '../index';
4
5
 
5
6
  function createEditor() {
7
+ const content = NodeFactory.doc([
8
+ NodeFactory.paragraph('Lorem ipsum dolor sit amet'),
9
+ NodeFactory.paragraph('consectetur adipisicing elit')
10
+ ]);
11
+
6
12
  return new Editor({
7
- content: NodeFactory.doc([
8
- NodeFactory.paragraph('Lorem ipsum dolor sit amet'),
9
- NodeFactory.paragraph('consectetur adipisicing elit')
10
- ]),
11
- extensions: CORE_EXTENSIONS // included to core
13
+ content: ContentNormalizer.normalize(content),
14
+ extensions: buildCoreExtensions() // included to core
12
15
  });
13
16
  }
14
17
 
@@ -1,26 +1,120 @@
1
- import { Editor, Mark } from '@tiptap/vue-2';
1
+ import { Editor, Mark, Extension } from '@tiptap/vue-2';
2
2
  import { NodeFactory } from '../../../__tests__/utils';
3
- import { CORE_EXTENSIONS } from '../index';
3
+ import { ContentNormalizer } from '../../../services';
4
+ import { NodeTypes, TextSettings } from '../../../enums';
5
+ import { buildCoreExtensions } from '../index';
6
+
7
+ const MockFontSize = Mark.create({
8
+ name: TextSettings.FONT_SIZE,
9
+
10
+ addAttributes: () => ({
11
+ value: { default: null }
12
+ }),
13
+
14
+ renderHTML: () => ['span', {}, 0]
15
+ });
4
16
 
5
17
  const MockFontWeight = Mark.create({
6
- name: 'font_weight',
18
+ name: TextSettings.FONT_WEIGHT,
19
+
20
+ addAttributes: () => ({
21
+ value: { default: null }
22
+ }),
23
+
24
+ renderHTML: () => ['span', {}, 0]
25
+ });
26
+
27
+ const MockAlignment = Extension.create({
28
+ name: TextSettings.ALIGNMENT,
29
+
30
+ addGlobalAttributes: () => [
31
+ {
32
+ types: [NodeTypes.PARAGRAPH, NodeTypes.HEADING],
33
+ attributes: {
34
+ [TextSettings.ALIGNMENT]: {
35
+ default: null,
36
+ renderHTML: () => ({})
37
+ }
38
+ }
39
+ }
40
+ ]
41
+ });
42
+
43
+ const MockBackgroundColor = Mark.create({
44
+ name: TextSettings.BACKGROUND_COLOR,
45
+
46
+ addAttributes: () => ({
47
+ value: { default: null }
48
+ }),
49
+
50
+ renderHTML: () => ['span', {}, 0]
51
+ });
52
+
53
+ const MockFontColor = Mark.create({
54
+ name: TextSettings.FONT_COLOR,
55
+
56
+ addAttributes: () => ({
57
+ value: { default: null }
58
+ }),
59
+
60
+ renderHTML: () => ['span', {}, 0]
61
+ });
62
+
63
+ const MockFontFamily = Mark.create({
64
+ name: TextSettings.FONT_FAMILY,
7
65
 
8
66
  addAttributes: () => ({
9
- value: { required: true }
67
+ value: { default: null }
10
68
  }),
11
69
 
12
- renderHTML(context) {
13
- const { value } = context.HTMLAttributes;
70
+ renderHTML: () => ['span', {}, 0]
71
+ });
72
+
73
+ const MockFontStyle = Mark.create({
74
+ name: TextSettings.FONT_STYLE,
75
+
76
+ addAttributes: () => ({
77
+ value: { default: null }
78
+ }),
14
79
 
15
- return ['span', { style: `font-weight: ${value}` }, 0];
16
- }
80
+ renderHTML: () => ['span', {}, 0]
81
+ });
82
+
83
+ const MockTextDecoration = Mark.create({
84
+ name: TextSettings.TEXT_DECORATION,
85
+
86
+ addAttributes: () => ({
87
+ value: { default: null }
88
+ }),
89
+
90
+ renderHTML: () => ['span', {}, 0]
91
+ });
92
+
93
+ const MockSuperscript = Mark.create({
94
+ name: TextSettings.SUPERSCRIPT,
95
+
96
+ addAttributes: () => ({
97
+ value: { default: null }
98
+ }),
99
+
100
+ renderHTML: () => ['span', {}, 0]
17
101
  });
18
102
 
19
103
  function createEditor({ content }) {
20
104
  return new Editor({
21
- content,
105
+ content: ContentNormalizer.normalize(content),
22
106
  element: document.createElement('div'),
23
- extensions: CORE_EXTENSIONS.concat(MockFontWeight)
107
+ extensions: buildCoreExtensions().concat(
108
+ MockFontSize,
109
+ MockFontWeight,
110
+ MockAlignment,
111
+ MockBackgroundColor,
112
+ MockFontColor,
113
+ MockFontFamily,
114
+ MockFontStyle,
115
+ MockTextDecoration,
116
+ MockSuperscript
117
+ )
24
118
  });
25
119
  }
26
120
 
@@ -59,3 +153,38 @@ describe('transform text', () => {
59
153
  expect(editor.getJSON()).toMatchSnapshot();
60
154
  });
61
155
  });
156
+
157
+ describe('selected text', () => {
158
+ test('should return selected text', () => {
159
+ const editor = createEditor({
160
+ content: NodeFactory.doc([
161
+ NodeFactory.paragraph('hello world')
162
+ ])
163
+ });
164
+
165
+ editor.commands.setTextSelection({ from: 5, to: 11 });
166
+
167
+ expect(editor.commands.getSelectedText()).toEqual('o worl');
168
+ });
169
+ });
170
+
171
+ describe('unset marks', () => {
172
+ test('should reset all marks', () => {
173
+ const editor = createEditor({
174
+ content: NodeFactory.doc([
175
+ NodeFactory.paragraph([
176
+ NodeFactory.text('hello world', [
177
+ NodeFactory.mark('font_weight', { value: '700' })
178
+ ])
179
+ ])
180
+ ])
181
+ });
182
+
183
+ editor.chain()
184
+ .selectAll()
185
+ .unsetMarks(TextSettings.marks)
186
+ .run();
187
+
188
+ expect(editor.getJSON()).toMatchSnapshot();
189
+ });
190
+ });
@@ -4,6 +4,9 @@ exports[`transform text should keep text marks 1`] = `
4
4
  Object {
5
5
  "content": Array [
6
6
  Object {
7
+ "attrs": Object {
8
+ "alignment": null,
9
+ },
7
10
  "content": Array [
8
11
  Object {
9
12
  "marks": Array [
@@ -29,6 +32,9 @@ exports[`transform text should transform selected text 1`] = `
29
32
  Object {
30
33
  "content": Array [
31
34
  Object {
35
+ "attrs": Object {
36
+ "alignment": null,
37
+ },
32
38
  "content": Array [
33
39
  Object {
34
40
  "text": "hELLO world",
@@ -41,3 +47,23 @@ Object {
41
47
  "type": "doc",
42
48
  }
43
49
  `;
50
+
51
+ exports[`unset marks should reset all marks 1`] = `
52
+ Object {
53
+ "content": Array [
54
+ Object {
55
+ "attrs": Object {
56
+ "alignment": null,
57
+ },
58
+ "content": Array [
59
+ Object {
60
+ "text": "hello world",
61
+ "type": "text",
62
+ },
63
+ ],
64
+ "type": "paragraph",
65
+ },
66
+ ],
67
+ "type": "doc",
68
+ }
69
+ `;
@@ -1,17 +1,26 @@
1
1
  import Document from '@tiptap/extension-document';
2
2
  import Paragraph from '@tiptap/extension-paragraph';
3
3
  import Text from '@tiptap/extension-text';
4
+ import Placeholder from '@tiptap/extension-placeholder';
5
+ import History from '@tiptap/extension-history';
4
6
  import { NodeProcessor } from './NodeProcessor';
5
7
  import { TextProcessor } from './TextProcessor';
6
8
  import { SelectionProcessor } from './SelectionProcessor';
9
+ import { CopyPasteProcessor } from './CopyPasteProcessor';
7
10
 
8
- export const CORE_EXTENSIONS = [
11
+ export const buildCoreExtensions = () => [
9
12
  Document,
10
13
  Paragraph.configure({
11
14
  HTMLAttributes: { class: 'zw-style' }
12
15
  }),
13
16
  Text,
17
+ Placeholder.configure({
18
+ placeholder: 'Type your text here...',
19
+ emptyNodeClass: 'zw-wysiwyg__placeholder'
20
+ }),
21
+ History,
14
22
  NodeProcessor,
15
23
  TextProcessor,
16
- SelectionProcessor
24
+ SelectionProcessor,
25
+ CopyPasteProcessor
17
26
  ];
@@ -0,0 +1,48 @@
1
+ import { ContentNormalizer } from '../../../services';
2
+ import { ProseMirrorPlugin } from './ProseMirrorPlugin';
3
+
4
+ export class PastePlugin extends ProseMirrorPlugin {
5
+ buildProps() {
6
+ return {
7
+ transformPastedHTML: ContentNormalizer.normalize,
8
+ handlePaste: this._handlePaste.bind(this)
9
+ };
10
+ }
11
+
12
+ _handlePaste(view, _, slice) {
13
+ const transaction = this._insertPastedContent(view, slice)
14
+ .scrollIntoView()
15
+ .setMeta('paste', true)
16
+ .setMeta('uiEvent', 'paste');
17
+
18
+ view.dispatch(transaction);
19
+
20
+ return true;
21
+ }
22
+
23
+ _insertPastedContent({ state, input }, slice) {
24
+ if (!this._isSingleNode(slice)) {
25
+ return state.tr.replaceSelection(slice);
26
+ }
27
+
28
+ const { $from, $to } = state.selection;
29
+ const isSingleNodeReplacing = $from.sharedDepth($to.pos) === $from.depth;
30
+
31
+ if (!isSingleNodeReplacing) {
32
+ return state.tr.replaceSelection(slice);
33
+ }
34
+
35
+ const selectionSize = Math.abs($from.pos - $to.pos);
36
+ const { nodeSize } = $to.path.reverse().find((step) => typeof step === 'object');
37
+
38
+ if (nodeSize - selectionSize > 5) {
39
+ return state.tr.replaceSelection(slice);
40
+ }
41
+
42
+ return state.tr.replaceSelectionWith(slice.content.firstChild, input.shiftKey);
43
+ }
44
+
45
+ _isSingleNode({ openStart, openEnd, content }) {
46
+ return openStart === 1 && openEnd === 1 && content.childCount === 1;
47
+ }
48
+ }
@@ -0,0 +1,20 @@
1
+ import { Plugin, PluginKey } from 'prosemirror-state';
2
+
3
+ export class ProseMirrorPlugin {
4
+ static create(options) {
5
+ const plugin = new this(options || {});
6
+
7
+ return new Plugin({
8
+ key: new PluginKey(this.name),
9
+ props: plugin.buildProps()
10
+ });
11
+ }
12
+
13
+ constructor(options) {
14
+ this.options = options;
15
+ }
16
+
17
+ buildProps() {
18
+ return {};
19
+ }
20
+ }