@zipify/wysiwyg 1.0.0-dev.6 → 1.0.0-dev.62

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/.eslintrc.js +2 -2
  3. package/.github/dependabot.yaml +1 -0
  4. package/.lintstagedrc +2 -2
  5. package/.release-it.json +3 -1
  6. package/.stylelintrc +0 -4
  7. package/README.md +2 -2
  8. package/config/jest/setupTests.js +0 -3
  9. package/config/vite/example.config.js +25 -0
  10. package/config/vite/lib.config.js +28 -0
  11. package/config/{webpack → vite}/settings.js +0 -0
  12. package/dist/wysiwyg.css +1 -837
  13. package/dist/wysiwyg.mjs +18353 -0
  14. package/example/ExampleApp.vue +41 -3
  15. package/example/example.js +0 -3
  16. package/example/{example.html → index.html} +1 -0
  17. package/example/pageBlocks.js +31 -0
  18. package/example/presets.js +2 -2
  19. package/example/tooltip/Tooltip.js +1 -1
  20. package/jest.config.js +3 -1
  21. package/lib/Wysiwyg.vue +65 -26
  22. package/lib/__tests__/utils/NodeFactory.js +13 -0
  23. package/lib/__tests__/utils/withComponentContext.js +1 -1
  24. package/lib/assets/icons/link.svg +3 -0
  25. package/lib/assets/icons/unlink.svg +3 -0
  26. package/lib/components/base/Button.vue +22 -2
  27. package/lib/components/base/Checkbox.vue +89 -0
  28. package/lib/components/base/FieldLabel.vue +2 -1
  29. package/lib/components/base/Icon.vue +3 -3
  30. package/lib/components/base/Modal.vue +1 -2
  31. package/lib/components/base/NumberField.vue +2 -2
  32. package/lib/components/base/Range.vue +1 -1
  33. package/lib/components/base/ScrollView.vue +1 -3
  34. package/lib/components/base/TextField.vue +106 -0
  35. package/lib/components/base/__tests__/Modal.test.js +7 -2
  36. package/lib/components/base/__tests__/TextField.test.js +57 -0
  37. package/lib/components/base/__tests__/__snapshots__/TextField.test.js.snap +9 -0
  38. package/lib/components/base/colorPicker/ColorPicker.vue +2 -2
  39. package/lib/components/base/colorPicker/composables/__tests__/usePickerApi.test.js +1 -1
  40. package/lib/components/base/colorPicker/composables/usePickerApi.js +3 -3
  41. package/lib/components/base/colorPicker/composables/usePickerHotkeys.js +3 -2
  42. package/lib/components/base/composables/__tests__/useActivatedListener.test.js +1 -1
  43. package/lib/components/base/composables/__tests__/useDeselectionLock.test.js +1 -1
  44. package/lib/components/base/composables/__tests__/useElementRef.test.js +1 -1
  45. package/lib/components/base/composables/__tests__/useModalToggler.test.js +1 -1
  46. package/lib/components/base/composables/__tests__/useNumberValue.test.js +1 -1
  47. package/lib/components/base/composables/__tests__/useScrollView.test.js +1 -1
  48. package/lib/components/base/composables/__tests__/useTempValue.test.js +1 -1
  49. package/lib/components/base/composables/__tests__/useValidator.test.js +44 -0
  50. package/lib/components/base/composables/index.js +1 -0
  51. package/lib/components/base/composables/useActivatedListener.js +1 -1
  52. package/lib/components/base/composables/useDeselectionLock.js +1 -1
  53. package/lib/components/base/composables/useElementRef.js +1 -1
  54. package/lib/components/base/composables/useModalToggler.js +1 -1
  55. package/lib/components/base/composables/useScrollView.js +1 -1
  56. package/lib/components/base/composables/useTempValue.js +1 -1
  57. package/lib/components/base/composables/useValidator.js +23 -0
  58. package/lib/components/base/dropdown/Dropdown.vue +16 -4
  59. package/lib/components/base/dropdown/DropdownActivator.vue +19 -3
  60. package/lib/components/base/dropdown/DropdownGroup.vue +1 -1
  61. package/lib/components/base/dropdown/DropdownMenu.vue +1 -1
  62. package/lib/components/base/dropdown/DropdownOption.vue +1 -1
  63. package/lib/components/base/dropdown/__tests__/DropdownActivator.test.js +1 -1
  64. package/lib/components/base/dropdown/__tests__/DropdownMenu.test.js +1 -1
  65. package/lib/components/base/dropdown/__tests__/DropdownOption.test.js +1 -1
  66. package/lib/components/base/dropdown/composables/__tests__/useActiveOptionManager.test.js +1 -1
  67. package/lib/components/base/dropdown/composables/__tests__/useDropdownEntityTitle.test.js +1 -1
  68. package/lib/components/base/dropdown/composables/useActiveOptionManager.js +1 -1
  69. package/lib/components/base/dropdown/composables/useDropdownEntityTitle.js +1 -1
  70. package/lib/components/base/index.js +3 -1
  71. package/lib/components/toolbar/Toolbar.vue +49 -9
  72. package/lib/components/toolbar/ToolbarDivider.vue +1 -1
  73. package/lib/components/toolbar/ToolbarFull.vue +10 -2
  74. package/lib/components/toolbar/ToolbarRow.vue +1 -0
  75. package/lib/components/toolbar/__tests__/Toolbar.test.js +6 -0
  76. package/lib/components/toolbar/controls/AlignmentControl.vue +1 -1
  77. package/lib/components/toolbar/controls/AlignmentDeviceControl.vue +1 -1
  78. package/lib/components/toolbar/controls/BackgroundColorControl.vue +1 -1
  79. package/lib/components/toolbar/controls/CaseStyleControl.vue +1 -1
  80. package/lib/components/toolbar/controls/FontColorControl.vue +1 -1
  81. package/lib/components/toolbar/controls/FontFamilyControl.vue +1 -1
  82. package/lib/components/toolbar/controls/FontSizeControl.vue +8 -1
  83. package/lib/components/toolbar/controls/FontWeightControl.vue +1 -1
  84. package/lib/components/toolbar/controls/ItalicControl.vue +1 -1
  85. package/lib/components/toolbar/controls/LineHeightControl.vue +1 -1
  86. package/lib/components/toolbar/controls/ListControl.vue +68 -34
  87. package/lib/components/toolbar/controls/RemoveFormatControl.vue +1 -1
  88. package/lib/components/toolbar/controls/StrikeThroughControl.vue +1 -1
  89. package/lib/components/toolbar/controls/StylePresetControl.vue +15 -2
  90. package/lib/components/toolbar/controls/SuperscriptControl.vue +1 -1
  91. package/lib/components/toolbar/controls/UnderlineControl.vue +2 -2
  92. package/lib/components/toolbar/controls/__tests__/AlignmentControl.test.js +1 -1
  93. package/lib/components/toolbar/controls/__tests__/AlignmentDeviceControl.test.js +1 -1
  94. package/lib/components/toolbar/controls/__tests__/BackgroundColorControl.test.js +1 -1
  95. package/lib/components/toolbar/controls/__tests__/CaseStyleControl.test.js +1 -1
  96. package/lib/components/toolbar/controls/__tests__/FontColorControl.test.js +1 -1
  97. package/lib/components/toolbar/controls/__tests__/FontFamilyControl.test.js +1 -1
  98. package/lib/components/toolbar/controls/__tests__/FontSizeControl.test.js +1 -1
  99. package/lib/components/toolbar/controls/__tests__/FontWeightControl.test.js +1 -1
  100. package/lib/components/toolbar/controls/__tests__/ItalicControl.test.js +1 -1
  101. package/lib/components/toolbar/controls/__tests__/LineHeightControl.test.js +1 -1
  102. package/lib/components/toolbar/controls/__tests__/ListControl.test.js +18 -3
  103. package/lib/components/toolbar/controls/__tests__/StrikeThroughControl.test.js +1 -1
  104. package/lib/components/toolbar/controls/__tests__/StylePresetControl.test.js +17 -1
  105. package/lib/components/toolbar/controls/__tests__/UnderlineControl.test.js +5 -1
  106. package/lib/components/toolbar/controls/composables/useRecentFonts.js +1 -1
  107. package/lib/components/toolbar/controls/index.js +1 -0
  108. package/lib/components/toolbar/controls/link/LinkControl.vue +155 -0
  109. package/lib/components/toolbar/controls/link/LinkControlApply.vue +35 -0
  110. package/lib/components/toolbar/controls/link/LinkControlHeader.vue +67 -0
  111. package/lib/components/toolbar/controls/link/__tests__/LinkControl.test.js +79 -0
  112. package/lib/components/toolbar/controls/link/__tests__/LinkControlHeader.test.js +42 -0
  113. package/lib/components/toolbar/controls/link/composables/__tests__/__snapshots__/useLink.test.js.snap +8 -0
  114. package/lib/components/toolbar/controls/link/composables/__tests__/useLink.test.js +114 -0
  115. package/lib/components/toolbar/controls/link/composables/index.js +1 -0
  116. package/lib/components/toolbar/controls/link/composables/useLink.js +61 -0
  117. package/lib/components/toolbar/controls/link/destination/LinkControlDestination.vue +103 -0
  118. package/lib/components/toolbar/controls/link/destination/LinkControlPageBlock.vue +54 -0
  119. package/lib/components/toolbar/controls/link/destination/LinkControlUrl.vue +52 -0
  120. package/lib/components/toolbar/controls/link/destination/__tests__/LinkControlPageBlock.test.js +36 -0
  121. package/lib/components/toolbar/controls/link/destination/__tests__/LinkControlUrl.test.js +46 -0
  122. package/lib/components/toolbar/controls/link/destination/__tests__/__snapshots__/LinkControlPageBlock.test.js.snap +9 -0
  123. package/lib/components/toolbar/controls/link/destination/__tests__/__snapshots__/LinkControlUrl.test.js.snap +17 -0
  124. package/lib/components/toolbar/controls/link/destination/index.js +1 -0
  125. package/lib/components/toolbar/controls/link/index.js +1 -0
  126. package/lib/composables/__tests__/useEditor.test.js +4 -3
  127. package/lib/composables/useEditor.js +8 -8
  128. package/lib/composables/useToolbar.js +23 -28
  129. package/lib/directives/__tests__/outClick.test.js +6 -0
  130. package/lib/directives/outClick.js +19 -6
  131. package/lib/enums/Alignments.js +10 -1
  132. package/lib/enums/LinkDestinations.js +4 -0
  133. package/lib/enums/LinkTargets.js +4 -0
  134. package/lib/enums/TextSettings.js +3 -1
  135. package/lib/enums/index.js +2 -0
  136. package/lib/extensions/Alignment.js +22 -8
  137. package/lib/extensions/BackgroundColor.js +15 -7
  138. package/lib/extensions/DeviceManager.js +2 -5
  139. package/lib/extensions/FontColor.js +15 -7
  140. package/lib/extensions/FontFamily.js +26 -9
  141. package/lib/extensions/FontSize.js +32 -13
  142. package/lib/extensions/FontStyle.js +24 -14
  143. package/lib/extensions/FontWeight.js +25 -15
  144. package/lib/extensions/LineHeight.js +32 -29
  145. package/lib/extensions/Link.js +90 -0
  146. package/lib/extensions/StylePreset.js +20 -19
  147. package/lib/extensions/Superscript.js +5 -1
  148. package/lib/extensions/TextDecoration.js +46 -13
  149. package/lib/extensions/__tests__/Alignment.test.js +13 -7
  150. package/lib/extensions/__tests__/BackgroundColor.test.js +12 -6
  151. package/lib/extensions/__tests__/CaseStyle.test.js +3 -5
  152. package/lib/extensions/__tests__/FontColor.test.js +12 -6
  153. package/lib/extensions/__tests__/FontFamily.test.js +33 -8
  154. package/lib/extensions/__tests__/FontSize.test.js +15 -8
  155. package/lib/extensions/__tests__/FontStyle.test.js +12 -6
  156. package/lib/extensions/__tests__/FontWeight.test.js +20 -6
  157. package/lib/extensions/__tests__/LineHeight.test.js +24 -12
  158. package/lib/extensions/__tests__/Link.test.js +102 -0
  159. package/lib/extensions/__tests__/StylePreset.test.js +71 -8
  160. package/lib/extensions/__tests__/TextDecoration.test.js +52 -6
  161. package/lib/extensions/__tests__/__snapshots__/Alignment.test.js.snap +26 -2
  162. package/lib/extensions/__tests__/__snapshots__/BackgroundColor.test.js.snap +30 -1
  163. package/lib/extensions/__tests__/__snapshots__/FontColor.test.js.snap +18 -1
  164. package/lib/extensions/__tests__/__snapshots__/FontFamily.test.js.snap +88 -1
  165. package/lib/extensions/__tests__/__snapshots__/FontSize.test.js.snap +33 -2
  166. package/lib/extensions/__tests__/__snapshots__/FontStyle.test.js.snap +25 -4
  167. package/lib/extensions/__tests__/__snapshots__/FontWeight.test.js.snap +47 -1
  168. package/lib/extensions/__tests__/__snapshots__/LineHeight.test.js.snap +26 -2
  169. package/lib/extensions/__tests__/__snapshots__/Link.test.js.snap +225 -0
  170. package/lib/extensions/__tests__/__snapshots__/StylePreset.test.js.snap +6 -2
  171. package/lib/extensions/__tests__/__snapshots__/TextDecoration.test.js.snap +183 -3
  172. package/lib/extensions/core/CopyPasteProcessor.js +10 -0
  173. package/lib/extensions/core/NodeProcessor.js +1 -1
  174. package/lib/extensions/core/TextProcessor.js +10 -0
  175. package/lib/extensions/core/__tests__/NodeProcessor.test.js +3 -5
  176. package/lib/extensions/core/__tests__/SelectionProcessor.test.js +3 -5
  177. package/lib/extensions/core/__tests__/TextProcessor.test.js +138 -12
  178. package/lib/extensions/core/__tests__/__snapshots__/TextProcessor.test.js.snap +26 -0
  179. package/lib/extensions/core/index.js +11 -2
  180. package/lib/extensions/core/plugins/PastePlugin.js +57 -0
  181. package/lib/extensions/core/plugins/ProseMirrorPlugin.js +20 -0
  182. package/lib/extensions/core/plugins/index.js +1 -0
  183. package/lib/extensions/index.js +46 -34
  184. package/lib/extensions/list/List.js +2 -3
  185. package/lib/extensions/list/__tests__/List.test.js +5 -8
  186. package/lib/extensions/list/__tests__/__snapshots__/List.test.js.snap +60 -20
  187. package/lib/injectionTokens.js +2 -1
  188. package/lib/services/ContentNormalizer.js +122 -29
  189. package/lib/services/ContextWidnow.js +23 -0
  190. package/lib/services/__tests__/ContentNormalizer.test.js +96 -7
  191. package/lib/services/__tests__/FavoriteColors.test.js +1 -1
  192. package/lib/services/index.js +1 -0
  193. package/lib/styles/content.css +110 -13
  194. package/lib/styles/helpers/offsets.css +16 -0
  195. package/lib/styles/variables.css +6 -0
  196. package/lib/utils/__tests__/__snapshots__/renderInlineSetting.test.js.snap +4 -4
  197. package/lib/utils/__tests__/convertAlignment.test.js +16 -0
  198. package/lib/utils/__tests__/convertFontSize.test.js +21 -0
  199. package/lib/utils/__tests__/convertLineHeight.test.js +21 -0
  200. package/lib/utils/convertAlignment.js +12 -0
  201. package/lib/utils/convertColor.js +1 -1
  202. package/lib/utils/convertFontSize.js +8 -0
  203. package/lib/utils/convertLineHeight.js +17 -0
  204. package/lib/utils/importIcon.js +7 -6
  205. package/lib/utils/index.js +3 -0
  206. package/lib/utils/renderInlineSetting.js +1 -1
  207. package/package.json +26 -31
  208. package/config/webpack/example.config.js +0 -88
  209. package/config/webpack/lib.config.js +0 -40
  210. package/config/webpack/loaders/index.js +0 -6
  211. package/config/webpack/loaders/js-loader.js +0 -5
  212. package/config/webpack/loaders/style-loader.js +0 -9
  213. package/config/webpack/loaders/svg-loader.js +0 -4
  214. package/config/webpack/loaders/vue-loader.js +0 -4
  215. package/dist/wysiwyg.js +0 -2
  216. package/dist/wysiwyg.js.LICENSE.txt +0 -1
  217. package/lib/composables/__tests__/useToolbar.test.js +0 -56
@@ -1,5 +1,5 @@
1
1
  import { Mark } from '@tiptap/vue-2';
2
- import { computed } from '@vue/composition-api';
2
+ import { computed } from 'vue';
3
3
  import { convertColor, createCommand, renderMark } from '../utils';
4
4
  import { TextSettings } from '../enums';
5
5
 
@@ -22,12 +22,20 @@ export const BackgroundColor = Mark.create({
22
22
  };
23
23
  },
24
24
 
25
- parseHTML: () => [
26
- {
27
- style: 'background-color',
28
- getAttrs: (value) => ({ value: convertColor(value) })
29
- }
30
- ],
25
+ parseHTML() {
26
+ const getAttrs = (value) => ({ value: convertColor(value) });
27
+
28
+ return [
29
+ {
30
+ style: '--zw-background-color',
31
+ getAttrs
32
+ },
33
+ {
34
+ style: 'background-color',
35
+ getAttrs
36
+ }
37
+ ];
38
+ },
31
39
 
32
40
  renderHTML({ HTMLAttributes: attrs }) {
33
41
  return renderMark({ background_color: attrs.value });
@@ -1,16 +1,13 @@
1
+ import { toRef } from 'vue';
1
2
  import { Extension } from '@tiptap/vue-2';
2
3
  import { createCommand } from '../utils';
3
4
 
4
5
  export const DeviceManager = Extension.create({
5
6
  name: 'device_manager',
6
7
 
7
- addOptions: () => ({
8
- deviceRef: null
9
- }),
10
-
11
8
  addCommands() {
12
9
  return {
13
- getDevice: createCommand(() => this.options.deviceRef)
10
+ getDevice: createCommand(() => toRef(this.options, 'device'))
14
11
  };
15
12
  }
16
13
  });
@@ -1,5 +1,5 @@
1
1
  import { Mark } from '@tiptap/vue-2';
2
- import { computed } from '@vue/composition-api';
2
+ import { computed } from 'vue';
3
3
  import { convertColor, createCommand, renderMark } from '../utils';
4
4
  import { TextSettings } from '../enums';
5
5
 
@@ -30,12 +30,20 @@ export const FontColor = Mark.create({
30
30
  };
31
31
  },
32
32
 
33
- parseHTML: () => [
34
- {
35
- style: 'color',
36
- getAttrs: (value) => ({ value: convertColor(value) })
37
- }
38
- ],
33
+ parseHTML() {
34
+ const getAttrs = (value) => ({ value: convertColor(value) });
35
+
36
+ return [
37
+ {
38
+ style: '--zw-font-color',
39
+ getAttrs
40
+ },
41
+ {
42
+ style: 'color',
43
+ getAttrs
44
+ }
45
+ ];
46
+ },
39
47
 
40
48
  renderHTML({ HTMLAttributes: attrs }) {
41
49
  return renderMark({ font_color: attrs.value });
@@ -1,5 +1,5 @@
1
1
  import { Mark } from '@tiptap/vue-2';
2
- import { computed } from '@vue/composition-api';
2
+ import { computed } from 'vue';
3
3
  import { createCommand, renderMark } from '../utils';
4
4
  import { TextSettings } from '../enums';
5
5
 
@@ -7,7 +7,8 @@ export const FontFamily = Mark.create({
7
7
  name: TextSettings.FONT_FAMILY,
8
8
 
9
9
  addOptions: () => ({
10
- fonts: []
10
+ fonts: [],
11
+ defaultFont: ''
11
12
  }),
12
13
 
13
14
  addAttributes: () => ({
@@ -56,14 +57,30 @@ export const FontFamily = Mark.create({
56
57
  };
57
58
  },
58
59
 
59
- parseHTML: () => [
60
- {
61
- style: 'font-family',
62
- getAttrs: (value) => ({ value })
63
- }
64
- ],
60
+ parseHTML() {
61
+ const getAttrs = (input) => {
62
+ const parsed = input.replace(/"/g, '');
63
+ const isExists = this.options.fonts.some((font) => font.name === parsed);
64
+ const value = isExists ? parsed : this.options.defaultFont;
65
+
66
+ return { value };
67
+ };
68
+
69
+ return [
70
+ {
71
+ style: '--zw-font-family',
72
+ getAttrs
73
+ },
74
+ {
75
+ style: 'font-family',
76
+ getAttrs
77
+ }
78
+ ];
79
+ },
65
80
 
66
81
  renderHTML({ HTMLAttributes: attrs }) {
67
- return renderMark({ font_family: attrs.value });
82
+ const font_family = attrs.value ? `"${attrs.value}"` : null;
83
+
84
+ return renderMark({ font_family });
68
85
  }
69
86
  });
@@ -1,6 +1,6 @@
1
1
  import { Mark } from '@tiptap/vue-2';
2
- import { computed } from '@vue/composition-api';
3
- import { createCommand, createKeyboardShortcut, renderMark } from '../utils';
2
+ import { computed } from 'vue';
3
+ import { convertFontSize, createCommand, createKeyboardShortcut, renderMark } from '../utils';
4
4
  import { TextSettings } from '../enums';
5
5
 
6
6
  export const FontSize = Mark.create({
@@ -62,25 +62,44 @@ export const FontSize = Mark.create({
62
62
  'Mod-Shift--': createKeyboardShortcut('decreaseFontSize')
63
63
  }),
64
64
 
65
- parseHTML: () => [
66
- {
67
- style: 'font-size',
65
+ parseHTML() {
66
+ const parseSize = (value) => {
67
+ if (!value) return null;
68
68
 
69
- getAttrs: (input) => {
70
- const value = String(parseInt(input));
69
+ const converted = convertFontSize(value, this.options.wrapperRef.value);
71
70
 
72
- return { desktop: value, tablet: value, mobile: value };
71
+ return String(converted);
72
+ };
73
+
74
+ return [
75
+ {
76
+ tag: '[style*="--zw-font-size"]',
77
+
78
+ getAttrs: ({ style }) => ({
79
+ mobile: parseSize(style.getPropertyValue('--zw-font-size-mobile')),
80
+ tablet: parseSize(style.getPropertyValue('--zw-font-size-tablet')),
81
+ desktop: parseSize(style.getPropertyValue('--zw-font-size-desktop'))
82
+ })
83
+ },
84
+ {
85
+ style: 'font-size',
86
+
87
+ getAttrs: (input) => {
88
+ const value = parseSize(input);
89
+
90
+ return { desktop: value, tablet: value, mobile: value };
91
+ }
73
92
  }
74
- }
75
- ],
93
+ ];
94
+ },
76
95
 
77
96
  renderHTML({ HTMLAttributes: attrs }) {
78
97
  const addUnits = (value) => value ? `${value}px` : null;
79
98
 
80
99
  return renderMark({
81
- mobile_font_size: addUnits(attrs.mobile),
82
- tablet_font_size: addUnits(attrs.tablet),
83
- desktop_font_size: addUnits(attrs.desktop)
100
+ font_size_mobile: addUnits(attrs.mobile),
101
+ font_size_tablet: addUnits(attrs.tablet),
102
+ font_size_desktop: addUnits(attrs.desktop)
84
103
  });
85
104
  }
86
105
  });
@@ -1,5 +1,5 @@
1
1
  import { Mark } from '@tiptap/vue-2';
2
- import { computed } from '@vue/composition-api';
2
+ import { computed } from 'vue';
3
3
  import { createCommand, createKeyboardShortcut, renderMark } from '../utils';
4
4
  import { TextSettings } from '../enums';
5
5
 
@@ -56,18 +56,28 @@ export const FontStyle = Mark.create({
56
56
  'Mod-I': createKeyboardShortcut('toggleItalic')
57
57
  }),
58
58
 
59
- parseHTML: () => [
60
- {
61
- tag: 'i',
62
- attrs: { italic: true }
63
- },
64
- {
65
- style: 'font-style',
66
- getAttrs: (value) => ({ italic: value.includes('italic') })
67
- }
68
- ],
69
-
70
- renderHTML() {
71
- return renderMark({ font_style: 'italic' });
59
+ parseHTML() {
60
+ const getAttrs = (value) => value.includes('italic') && { italic: true };
61
+
62
+ return [
63
+ {
64
+ style: '--zw-font-style',
65
+ getAttrs
66
+ },
67
+ {
68
+ style: 'font-style',
69
+ getAttrs
70
+ },
71
+ {
72
+ tag: 'i',
73
+ attrs: { italic: true }
74
+ }
75
+ ];
76
+ },
77
+
78
+ renderHTML({ HTMLAttributes: attrs }) {
79
+ const font_style = attrs.italic ? 'italic' : null;
80
+
81
+ return renderMark({ font_style });
72
82
  }
73
83
  });
@@ -1,5 +1,5 @@
1
1
  import { Mark } from '@tiptap/vue-2';
2
- import { computed } from '@vue/composition-api';
2
+ import { computed } from 'vue';
3
3
  import { createCommand, createKeyboardShortcut, renderMark } from '../utils';
4
4
  import { TextSettings } from '../enums';
5
5
 
@@ -59,20 +59,30 @@ export const FontWeight = Mark.create({
59
59
  'Mod-B': createKeyboardShortcut('toggleBold')
60
60
  }),
61
61
 
62
- parseHTML: () => [
63
- {
64
- tag: 'b',
65
- attrs: { value: '700' }
66
- },
67
- {
68
- tag: 'strong',
69
- attrs: { value: '700' }
70
- },
71
- {
72
- style: 'font-weight',
73
- getAttrs: (value) => ({ value })
74
- }
75
- ],
62
+ parseHTML() {
63
+ const getAttrs = (value) => {
64
+ return Number(value) ? { value } : false;
65
+ };
66
+
67
+ return [
68
+ {
69
+ style: '--zw-font-weight',
70
+ getAttrs
71
+ },
72
+ {
73
+ style: 'font-weight',
74
+ getAttrs
75
+ },
76
+ {
77
+ tag: 'b',
78
+ attrs: { value: '700' }
79
+ },
80
+ {
81
+ tag: 'strong',
82
+ attrs: { value: '700' }
83
+ }
84
+ ];
85
+ },
76
86
 
77
87
  renderHTML({ HTMLAttributes: attrs }) {
78
88
  return renderMark({ font_weight: attrs.value });
@@ -1,6 +1,6 @@
1
1
  import { Extension } from '@tiptap/vue-2';
2
- import { computed } from '@vue/composition-api';
3
- import { createCommand, renderInlineSetting } from '../utils';
2
+ import { computed } from 'vue';
3
+ import { createCommand, renderInlineSetting, convertLineHeight } from '../utils';
4
4
  import { NodeTypes, TextSettings } from '../enums';
5
5
 
6
6
  const DEFAULTS = {
@@ -12,43 +12,46 @@ const DEFAULTS = {
12
12
  export const LineHeight = Extension.create({
13
13
  name: TextSettings.LINE_HEIGHT,
14
14
 
15
- addGlobalAttributes: () => [
16
- {
17
- types: [NodeTypes.PARAGRAPH, NodeTypes.HEADING],
18
- attributes: {
19
- [TextSettings.LINE_HEIGHT]: {
20
- isRequired: false,
15
+ addGlobalAttributes() {
16
+ return [
17
+ {
18
+ types: [NodeTypes.PARAGRAPH, NodeTypes.HEADING],
19
+ attributes: {
20
+ [TextSettings.LINE_HEIGHT]: {
21
+ isRequired: false,
21
22
 
22
- parseHTML(element) {
23
- const value = element.style.lineHeight;
23
+ parseHTML: (element) => {
24
+ if (element.matches('[style*="--zw-line-height"]')) {
25
+ const mobile = element.style.getPropertyValue('--zw-line-height-mobile') || null;
26
+ const tablet = element.style.getPropertyValue('--zw-line-height-tablet') || null;
27
+ const desktop = element.style.getPropertyValue('--zw-line-height-desktop') || null;
24
28
 
25
- if (!value) return null;
29
+ return { mobile, tablet, desktop };
30
+ }
26
31
 
27
- if (!value.includes('px')) {
28
- return { desktop: value, tablet: value, mobile: value };
29
- }
32
+ const value = element.style.lineHeight;
33
+
34
+ if (!value) return null;
30
35
 
31
- // element is not connected to window so getComputedStyle is not working on element
32
- const childFontSize = element.firstElementChild.style.fontSize;
33
- const fontSize = childFontSize || window.getComputedStyle(document.body).fontSize;
34
- const relative = (parseFloat(value) / parseFloat(fontSize)).toFixed(2);
36
+ const converted = convertLineHeight(value, element, this.options.wrapperRef.value);
35
37
 
36
- return { desktop: relative, tablet: relative, mobile: relative };
37
- },
38
+ return { desktop: converted, tablet: converted, mobile: converted };
39
+ },
38
40
 
39
- renderHTML(attrs) {
40
- if (!attrs.line_height) return null;
41
+ renderHTML(attrs) {
42
+ if (!attrs.line_height) return null;
41
43
 
42
- return renderInlineSetting({
43
- mobile_line_height: attrs.line_height.mobile,
44
- tablet_line_height: attrs.line_height.tablet,
45
- desktop_line_height: attrs.line_height.desktop
46
- });
44
+ return renderInlineSetting({
45
+ line_height_mobile: attrs.line_height.mobile,
46
+ line_height_tablet: attrs.line_height.tablet,
47
+ line_height_desktop: attrs.line_height.desktop
48
+ });
49
+ }
47
50
  }
48
51
  }
49
52
  }
50
- }
51
- ],
53
+ ];
54
+ },
52
55
 
53
56
  addCommands() {
54
57
  return {
@@ -0,0 +1,90 @@
1
+ import Base from '@tiptap/extension-link';
2
+ import { createCommand } from '../utils';
3
+ import { LinkDestinations, LinkTargets } from '../enums';
4
+
5
+ export const Link = Base.extend({
6
+ name: 'link',
7
+
8
+ addOptions() {
9
+ return {
10
+ ...this.parent?.(),
11
+ openOnClick: false
12
+ };
13
+ },
14
+
15
+ addAttributes() {
16
+ return {
17
+ href: {
18
+ default: null,
19
+ parseHTML: (element) => {
20
+ const href = element.getAttribute('href');
21
+
22
+ if (!href.startsWith('#')) return href;
23
+
24
+ return parseFloat(element.getAttribute('href').replace('#', ''));
25
+ }
26
+ },
27
+
28
+ target: {
29
+ default: LinkTargets.SELF,
30
+ parseHTML: (element) => element.getAttribute('target') || LinkTargets.SELF
31
+ },
32
+
33
+ destination: {
34
+ default: LinkDestinations.URL,
35
+ parseHTML: (element) => {
36
+ const href = element.getAttribute('href');
37
+
38
+ if (!href.startsWith('#')) return LinkDestinations.URL;
39
+
40
+ const id = href.replace('#', '');
41
+ const blocks = this.options.pageBlocks.value || this.options.pageBlocks;
42
+ const block = blocks.find((block) => block.id === parseInt(id));
43
+
44
+ return block ? LinkDestinations.BLOCK : LinkDestinations.URL;
45
+ }
46
+ }
47
+ };
48
+ },
49
+
50
+ addCommands() {
51
+ return {
52
+ ...this.parent?.(),
53
+ applyLink: createCommand(({ commands, chain }, attributes) => {
54
+ if (!commands.getSelectedText()) {
55
+ return commands.insertContent({
56
+ type: 'text',
57
+ marks: [
58
+ {
59
+ type: 'link',
60
+ attrs: { ...attributes }
61
+ }
62
+ ],
63
+ text: attributes.text
64
+ });
65
+ }
66
+
67
+ return chain()
68
+ .setMark(this.name, attributes)
69
+ .transformText(() => attributes.text)
70
+ .extendMarkRange('link')
71
+ .run();
72
+ })
73
+ };
74
+ },
75
+
76
+ renderHTML({ HTMLAttributes: attrs }) {
77
+ const href = attrs.destination === LinkDestinations.BLOCK ? `#${attrs.href}` : attrs.href;
78
+
79
+ const presetClass = this.options.basePresetClass + this.options.preset.id;
80
+ const classes = `${presetClass} zw-style`;
81
+
82
+ const linkAttrs = {
83
+ href,
84
+ target: attrs.target,
85
+ class: classes
86
+ };
87
+
88
+ return ['a', linkAttrs, 0];
89
+ }
90
+ });
@@ -1,8 +1,9 @@
1
1
  import { Extension } from '@tiptap/vue-2';
2
- import { computed, toRef } from '@vue/composition-api';
2
+ import { computed, toRef } from 'vue';
3
3
  import { Heading } from '@tiptap/extension-heading';
4
4
  import { createCommand } from '../utils';
5
5
  import { Devices, NodeTypes, TextSettings } from '../enums';
6
+ import { ContextWindow } from '../services';
6
7
 
7
8
  function makePresetClass(base, preset) {
8
9
  const baseClass = base.split(' ').map((part) => `.${part}`).join('');
@@ -20,13 +21,6 @@ export const StylePreset = Extension.create({
20
21
  })
21
22
  ],
22
23
 
23
- addOptions: () => ({
24
- presetsRef: null,
25
- defaultId: null,
26
- baseClass: null,
27
- makeVariable: null
28
- }),
29
-
30
24
  addStorage: () => ({
31
25
  presetStyleEl: null
32
26
  }),
@@ -38,10 +32,12 @@ export const StylePreset = Extension.create({
38
32
  attributes: {
39
33
  preset: {
40
34
  isRequired: false,
41
- default: null,
35
+ default: { id: this.options.defaultId },
42
36
 
43
37
  parseHTML: (element) => {
44
- const presets = this.options.presetsRef.value;
38
+ const presets = this.options.presets.value || this.options.presets;
39
+
40
+ if (element.parentElement.tagName === 'LI') return null;
45
41
 
46
42
  for (const { id, node, fallbackClass } of presets) {
47
43
  const isFallback = fallbackClass && element.classList.contains(fallbackClass);
@@ -76,7 +72,7 @@ export const StylePreset = Extension.create({
76
72
 
77
73
  return {
78
74
  getPresetList: createCommand(() => computed(() => {
79
- return this.options.presetsRef.value.filter((preset) => !preset.hidden);
75
+ return this.options.presets.filter((preset) => !preset.hidden);
80
76
  })),
81
77
 
82
78
  getPreset: createCommand(({ commands }) => {
@@ -147,32 +143,37 @@ export const StylePreset = Extension.create({
147
143
  chain()
148
144
  .storeSelection()
149
145
  .expandSelectionToBlock()
150
- .unsetAllMarks()
146
+ .unsetMarks(TextSettings.marks)
151
147
  .resetAttributes(NodeTypes.PARAGRAPH, TextSettings.attributes)
152
148
  .resetAttributes(NodeTypes.HEADING, TextSettings.attributes)
153
149
  .restoreSelection()
154
150
  .run();
155
151
  }),
156
152
 
157
- removeFormat: createCommand(({ commands }) => {
158
- commands.removePresetCustomization();
159
- commands.applyDefaultPreset();
153
+ removeFormat: createCommand(({ chain }) => {
154
+ chain()
155
+ .storeSelection()
156
+ .expandSelectionToBlock()
157
+ .unsetAllMarks()
158
+ .applyDefaultPreset()
159
+ .restoreSelection()
160
+ .run();
160
161
  })
161
162
  };
162
163
  },
163
164
 
164
165
  onCreate() {
165
- const existingStyleEl = document.querySelector('[data-zw-styles]');
166
+ const existingStyleEl = ContextWindow.document.querySelector('[data-zw-styles]');
166
167
 
167
168
  if (existingStyleEl) {
168
169
  this.storage.presetStyleEl = existingStyleEl;
169
170
  return;
170
171
  }
171
172
 
172
- this.storage.presetStyleEl = document.createElement('style');
173
+ this.storage.presetStyleEl = ContextWindow.document.createElement('style');
173
174
  this.storage.presetStyleEl.dataset.zwStyles = '';
174
175
 
175
- for (const preset of this.options.presetsRef.value) {
176
+ for (const preset of this.options.presets) {
176
177
  const className = makePresetClass(this.options.baseClass, preset);
177
178
  const css = [` ${className} {`];
178
179
 
@@ -190,6 +191,6 @@ export const StylePreset = Extension.create({
190
191
  this.storage.presetStyleEl.innerHTML += css.join(' ');
191
192
  }
192
193
 
193
- document.head.append(this.storage.presetStyleEl);
194
+ ContextWindow.head.append(this.storage.presetStyleEl);
194
195
  }
195
196
  });
@@ -1,5 +1,9 @@
1
1
  import Base from '@tiptap/extension-superscript';
2
2
 
3
3
  export const Superscript = Base.extend({
4
- addKeyboardShortcuts: null
4
+ addKeyboardShortcuts: null,
5
+
6
+ addOptions: () => ({
7
+ HTMLAttributes: { class: 'zw-superscript' }
8
+ })
5
9
  });