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

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 (216) 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 +18339 -0
  14. package/example/ExampleApp.vue +21 -2
  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 +51 -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 +3 -3
  127. package/lib/composables/useEditor.js +6 -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/TextDecoration.js +46 -13
  148. package/lib/extensions/__tests__/Alignment.test.js +13 -7
  149. package/lib/extensions/__tests__/BackgroundColor.test.js +12 -6
  150. package/lib/extensions/__tests__/CaseStyle.test.js +3 -5
  151. package/lib/extensions/__tests__/FontColor.test.js +12 -6
  152. package/lib/extensions/__tests__/FontFamily.test.js +33 -8
  153. package/lib/extensions/__tests__/FontSize.test.js +15 -8
  154. package/lib/extensions/__tests__/FontStyle.test.js +12 -6
  155. package/lib/extensions/__tests__/FontWeight.test.js +20 -6
  156. package/lib/extensions/__tests__/LineHeight.test.js +24 -12
  157. package/lib/extensions/__tests__/Link.test.js +102 -0
  158. package/lib/extensions/__tests__/StylePreset.test.js +71 -8
  159. package/lib/extensions/__tests__/TextDecoration.test.js +52 -6
  160. package/lib/extensions/__tests__/__snapshots__/Alignment.test.js.snap +26 -2
  161. package/lib/extensions/__tests__/__snapshots__/BackgroundColor.test.js.snap +30 -1
  162. package/lib/extensions/__tests__/__snapshots__/FontColor.test.js.snap +18 -1
  163. package/lib/extensions/__tests__/__snapshots__/FontFamily.test.js.snap +88 -1
  164. package/lib/extensions/__tests__/__snapshots__/FontSize.test.js.snap +33 -2
  165. package/lib/extensions/__tests__/__snapshots__/FontStyle.test.js.snap +25 -4
  166. package/lib/extensions/__tests__/__snapshots__/FontWeight.test.js.snap +47 -1
  167. package/lib/extensions/__tests__/__snapshots__/LineHeight.test.js.snap +26 -2
  168. package/lib/extensions/__tests__/__snapshots__/Link.test.js.snap +225 -0
  169. package/lib/extensions/__tests__/__snapshots__/StylePreset.test.js.snap +6 -2
  170. package/lib/extensions/__tests__/__snapshots__/TextDecoration.test.js.snap +183 -3
  171. package/lib/extensions/core/CopyPasteProcessor.js +10 -0
  172. package/lib/extensions/core/NodeProcessor.js +1 -1
  173. package/lib/extensions/core/TextProcessor.js +10 -0
  174. package/lib/extensions/core/__tests__/NodeProcessor.test.js +3 -5
  175. package/lib/extensions/core/__tests__/SelectionProcessor.test.js +3 -5
  176. package/lib/extensions/core/__tests__/TextProcessor.test.js +138 -12
  177. package/lib/extensions/core/__tests__/__snapshots__/TextProcessor.test.js.snap +26 -0
  178. package/lib/extensions/core/index.js +11 -2
  179. package/lib/extensions/core/plugins/PastePlugin.js +57 -0
  180. package/lib/extensions/core/plugins/ProseMirrorPlugin.js +20 -0
  181. package/lib/extensions/core/plugins/index.js +1 -0
  182. package/lib/extensions/index.js +46 -34
  183. package/lib/extensions/list/List.js +2 -3
  184. package/lib/extensions/list/__tests__/List.test.js +5 -8
  185. package/lib/extensions/list/__tests__/__snapshots__/List.test.js.snap +60 -20
  186. package/lib/injectionTokens.js +2 -1
  187. package/lib/services/ContentNormalizer.js +122 -29
  188. package/lib/services/ContextWidnow.js +23 -0
  189. package/lib/services/__tests__/ContentNormalizer.test.js +96 -7
  190. package/lib/services/__tests__/FavoriteColors.test.js +1 -1
  191. package/lib/services/index.js +1 -0
  192. package/lib/styles/content.css +102 -13
  193. package/lib/styles/helpers/offsets.css +16 -0
  194. package/lib/styles/variables.css +6 -0
  195. package/lib/utils/__tests__/__snapshots__/renderInlineSetting.test.js.snap +4 -4
  196. package/lib/utils/__tests__/convertAlignment.test.js +16 -0
  197. package/lib/utils/__tests__/convertFontSize.test.js +21 -0
  198. package/lib/utils/__tests__/convertLineHeight.test.js +21 -0
  199. package/lib/utils/convertAlignment.js +12 -0
  200. package/lib/utils/convertColor.js +1 -1
  201. package/lib/utils/convertFontSize.js +8 -0
  202. package/lib/utils/convertLineHeight.js +17 -0
  203. package/lib/utils/importIcon.js +7 -6
  204. package/lib/utils/index.js +3 -0
  205. package/lib/utils/renderInlineSetting.js +1 -1
  206. package/package.json +26 -31
  207. package/config/webpack/example.config.js +0 -88
  208. package/config/webpack/lib.config.js +0 -40
  209. package/config/webpack/loaders/index.js +0 -6
  210. package/config/webpack/loaders/js-loader.js +0 -5
  211. package/config/webpack/loaders/style-loader.js +0 -9
  212. package/config/webpack/loaders/svg-loader.js +0 -4
  213. package/config/webpack/loaders/vue-loader.js +0 -4
  214. package/dist/wysiwyg.js +0 -2
  215. package/dist/wysiwyg.js.LICENSE.txt +0 -1
  216. package/lib/composables/__tests__/useToolbar.test.js +0 -56
@@ -1,12 +1,12 @@
1
1
  import { Editor, Extension } from '@tiptap/vue-2';
2
- import { ref } from '@vue/composition-api';
2
+ import { ref } from 'vue';
3
3
  import { NodeFactory } from '../../__tests__/utils';
4
4
  import { createCommand } from '../../utils';
5
- import { CORE_EXTENSIONS } from '../core';
6
5
  import { Alignment } from '../Alignment';
7
6
  import { DeviceManager } from '../DeviceManager';
8
7
  import { Alignments } from '../../enums';
9
8
  import { ContentNormalizer } from '../../services';
9
+ import { buildCoreExtensions } from '../core';
10
10
 
11
11
  const MockStylePreset = Extension.create({
12
12
  name: 'style_preset',
@@ -23,13 +23,11 @@ const MockStylePreset = Extension.create({
23
23
  });
24
24
 
25
25
  function createEditor({ content }) {
26
- const normalizer = new ContentNormalizer();
27
-
28
26
  return new Editor({
29
- content: normalizer.normalize(content),
30
- extensions: CORE_EXTENSIONS.concat(
27
+ content: ContentNormalizer.normalize(content),
28
+ extensions: buildCoreExtensions().concat(
31
29
  MockStylePreset,
32
- DeviceManager.configure({ deviceRef: ref('desktop') }),
30
+ DeviceManager.configure({ device: ref('desktop') }),
33
31
  Alignment
34
32
  )
35
33
  });
@@ -118,6 +116,14 @@ describe('parsing html', () => {
118
116
  expect(editor.getJSON()).toMatchSnapshot();
119
117
  });
120
118
 
119
+ test('should get alignment from rendered view', () => {
120
+ const editor = createEditor({
121
+ content: '<p style="--zw-text-align-mobile:center;--zw-text-align-desktop:right">test</p>'
122
+ });
123
+
124
+ expect(editor.getJSON()).toMatchSnapshot();
125
+ });
126
+
121
127
  test('should set null if no alignment', () => {
122
128
  const editor = createEditor({
123
129
  content: '<p>test</p>'
@@ -1,10 +1,10 @@
1
1
  import { Editor, Extension } from '@tiptap/vue-2';
2
- import { ref } from '@vue/composition-api';
2
+ import { ref } from 'vue';
3
3
  import { NodeFactory } from '../../__tests__/utils';
4
4
  import { createCommand } from '../../utils';
5
- import { CORE_EXTENSIONS } from '../core';
6
5
  import { BackgroundColor } from '../BackgroundColor';
7
6
  import { ContentNormalizer } from '../../services';
7
+ import { buildCoreExtensions } from '../core';
8
8
 
9
9
  const MockStylePreset = Extension.create({
10
10
  name: 'style_preset',
@@ -19,11 +19,9 @@ const MockStylePreset = Extension.create({
19
19
  });
20
20
 
21
21
  function createEditor({ content }) {
22
- const normalizer = new ContentNormalizer();
23
-
24
22
  return new Editor({
25
- content: normalizer.normalize(content),
26
- extensions: CORE_EXTENSIONS.concat(MockStylePreset, BackgroundColor)
23
+ content: ContentNormalizer.normalize(content),
24
+ extensions: buildCoreExtensions().concat(MockStylePreset, BackgroundColor)
27
25
  });
28
26
  }
29
27
 
@@ -94,6 +92,14 @@ describe('parsing html', () => {
94
92
  expect(editor.getJSON()).toMatchSnapshot();
95
93
  });
96
94
 
95
+ test('should get value from rendered view', () => {
96
+ const editor = createEditor({
97
+ content: '<p><span style="--zw-background-color: red">lorem</span> ipsum</p>'
98
+ });
99
+
100
+ expect(editor.getJSON()).toMatchSnapshot();
101
+ });
102
+
97
103
  test('should merge paragraph and text settings', () => {
98
104
  const editor = createEditor({
99
105
  content: '<p style="background-color: red"><span style="background-color: #000">lorem</span> ipsum</p>'
@@ -1,16 +1,14 @@
1
1
  import { Editor } from '@tiptap/vue-2';
2
2
  import { NodeFactory } from '../../__tests__/utils';
3
3
  import { CaseStyles } from '../../enums';
4
- import { CORE_EXTENSIONS } from '../core';
5
4
  import { CaseStyle } from '../CaseStyle';
6
5
  import { ContentNormalizer } from '../../services';
6
+ import { buildCoreExtensions } from '../core';
7
7
 
8
8
  function createEditor({ content }) {
9
- const normalizer = new ContentNormalizer();
10
-
11
9
  return new Editor({
12
- content: normalizer.normalize(content),
13
- extensions: CORE_EXTENSIONS.concat(CaseStyle)
10
+ content: ContentNormalizer.normalize(content),
11
+ extensions: buildCoreExtensions().concat(CaseStyle)
14
12
  });
15
13
  }
16
14
 
@@ -1,10 +1,10 @@
1
1
  import { Editor, Extension } from '@tiptap/vue-2';
2
- import { ref } from '@vue/composition-api';
2
+ import { ref } from 'vue';
3
3
  import { NodeFactory } from '../../__tests__/utils';
4
4
  import { createCommand } from '../../utils';
5
- import { CORE_EXTENSIONS } from '../core';
6
5
  import { FontColor } from '../FontColor';
7
6
  import { ContentNormalizer } from '../../services';
7
+ import { buildCoreExtensions } from '../core';
8
8
 
9
9
  const MockStylePreset = Extension.create({
10
10
  name: 'style_preset',
@@ -19,11 +19,9 @@ const MockStylePreset = Extension.create({
19
19
  });
20
20
 
21
21
  function createEditor({ content }) {
22
- const normalizer = new ContentNormalizer();
23
-
24
22
  return new Editor({
25
- content: normalizer.normalize(content),
26
- extensions: CORE_EXTENSIONS.concat(MockStylePreset, FontColor)
23
+ content: ContentNormalizer.normalize(content),
24
+ extensions: buildCoreExtensions().concat(MockStylePreset, FontColor)
27
25
  });
28
26
  }
29
27
 
@@ -104,6 +102,14 @@ describe('parsing html', () => {
104
102
  expect(editor.getJSON()).toMatchSnapshot();
105
103
  });
106
104
 
105
+ test('should get value from parsed view', () => {
106
+ const editor = createEditor({
107
+ content: '<p><span style="--zw-color: red">lorem</span> ipsum</p>'
108
+ });
109
+
110
+ expect(editor.getJSON()).toMatchSnapshot();
111
+ });
112
+
107
113
  test('should merge paragraph and text settings', () => {
108
114
  const editor = createEditor({
109
115
  content: '<p style="color: red"><span style="color: #000">lorem</span> ipsum</p>'
@@ -1,13 +1,13 @@
1
1
  import { Editor, Extension } from '@tiptap/vue-2';
2
- import { ref } from '@vue/composition-api';
2
+ import { ref } from 'vue';
3
3
  import { NodeFactory } from '../../__tests__/utils';
4
4
  import { createCommand } from '../../utils';
5
- import { CORE_EXTENSIONS } from '../core';
6
5
  import { Font } from '../../models';
7
6
  import { FontFamily } from '../FontFamily';
8
7
  import { FontWeight } from '../FontWeight';
9
8
  import { FontStyle } from '../FontStyle';
10
9
  import { ContentNormalizer } from '../../services';
10
+ import { buildCoreExtensions } from '../core';
11
11
 
12
12
  const MockStylePreset = Extension.create({
13
13
  name: 'style_preset',
@@ -25,17 +25,18 @@ const MockStylePreset = Extension.create({
25
25
  });
26
26
 
27
27
  function createEditor({ content }) {
28
- const normalizer = new ContentNormalizer();
29
-
30
28
  return new Editor({
31
- content: normalizer.normalize(content),
32
- extensions: CORE_EXTENSIONS.concat(
29
+ content: ContentNormalizer.normalize(content),
30
+ extensions: buildCoreExtensions().concat(
33
31
  MockStylePreset,
34
32
  FontFamily.configure({
35
33
  fonts: [
36
34
  new Font({ name: 'Lato', styles: ['400', '700', '700i'] }),
37
- new Font({ name: 'Bungee', styles: ['400'] })
38
- ]
35
+ new Font({ name: 'Bungee', styles: ['400'] }),
36
+ new Font({ name: 'Roboto', styles: ['400'] }),
37
+ new Font({ name: 'Josefin Slab', styles: ['400'] })
38
+ ],
39
+ defaultFont: 'Lato'
39
40
  }),
40
41
  FontWeight,
41
42
  FontStyle
@@ -190,6 +191,22 @@ describe('parsing html', () => {
190
191
  expect(editor.getJSON()).toMatchSnapshot();
191
192
  });
192
193
 
194
+ test('should get value from rendered view', () => {
195
+ const editor = createEditor({
196
+ content: '<p><span style="--zw-font-family: Lato">lorem</span> ipsum</p>'
197
+ });
198
+
199
+ expect(editor.getJSON()).toMatchSnapshot();
200
+ });
201
+
202
+ test('should get set default if undefined font', () => {
203
+ const editor = createEditor({
204
+ content: '<p><span style="--zw-font-family: Arial">lorem</span> ipsum</p>'
205
+ });
206
+
207
+ expect(editor.getJSON()).toMatchSnapshot();
208
+ });
209
+
193
210
  test('should merge paragraph and text settings', () => {
194
211
  const editor = createEditor({
195
212
  content: '<p style="font-family: Lato"><span style="font-family: Roboto">lorem</span> ipsum</p>'
@@ -197,4 +214,12 @@ describe('parsing html', () => {
197
214
 
198
215
  expect(editor.getJSON()).toMatchSnapshot();
199
216
  });
217
+
218
+ test('should get parse font name with quotes', () => {
219
+ const editor = createEditor({
220
+ content: '<p>hello <span style="font-family: &quot;Josefin Slab&quot;;">world</span></p>'
221
+ });
222
+
223
+ expect(editor.getJSON()).toMatchSnapshot();
224
+ });
200
225
  });
@@ -1,11 +1,11 @@
1
1
  import { Editor, Extension } from '@tiptap/vue-2';
2
- import { ref } from '@vue/composition-api';
2
+ import { ref } from 'vue';
3
3
  import { NodeFactory } from '../../__tests__/utils';
4
4
  import { createCommand } from '../../utils';
5
- import { CORE_EXTENSIONS } from '../core';
6
5
  import { FontSize } from '../FontSize';
7
6
  import { DeviceManager } from '../DeviceManager';
8
7
  import { ContentNormalizer } from '../../services';
8
+ import { buildCoreExtensions } from '../core';
9
9
 
10
10
  const MockStylePreset = Extension.create({
11
11
  name: 'style_preset',
@@ -22,18 +22,17 @@ const MockStylePreset = Extension.create({
22
22
  });
23
23
 
24
24
  function createEditor({ content }) {
25
- const normalizer = new ContentNormalizer();
26
-
27
25
  return new Editor({
28
- content: normalizer.normalize(content),
29
- extensions: CORE_EXTENSIONS.concat(
26
+ content: ContentNormalizer.normalize(content),
27
+ extensions: buildCoreExtensions().concat(
30
28
  MockStylePreset,
31
29
  DeviceManager.configure({
32
- deviceRef: ref('desktop')
30
+ device: ref('desktop')
33
31
  }),
34
32
  FontSize.configure({
35
33
  minSize: 5,
36
- maxSize: 20
34
+ maxSize: 20,
35
+ wrapperRef: ref(document.createElement('div'))
37
36
  })
38
37
  )
39
38
  });
@@ -202,6 +201,14 @@ describe('parsing html', () => {
202
201
  expect(editor.getJSON()).toMatchSnapshot();
203
202
  });
204
203
 
204
+ test('should get value from rendered view', () => {
205
+ const editor = createEditor({
206
+ content: '<p><span style="--zw-font-size-mobile: 24px; --zw-font-size-desktop:30px">lorem</span> ipsum</p>'
207
+ });
208
+
209
+ expect(editor.getJSON()).toMatchSnapshot();
210
+ });
211
+
205
212
  test('should merge paragraph and text settings', () => {
206
213
  const editor = createEditor({
207
214
  content: '<p style="font-size: 24px"><span style="font-size: 20px">lorem</span> ipsum</p>'
@@ -1,13 +1,13 @@
1
1
  import { Editor, Extension } from '@tiptap/vue-2';
2
- import { ref } from '@vue/composition-api';
2
+ import { ref } from 'vue';
3
3
  import { NodeFactory } from '../../__tests__/utils';
4
4
  import { createCommand } from '../../utils';
5
- import { CORE_EXTENSIONS } from '../core';
6
5
  import { FontStyle } from '../FontStyle';
7
6
  import { FontFamily } from '../FontFamily';
8
7
  import { Font } from '../../models';
9
8
  import { FontWeight } from '../FontWeight';
10
9
  import { ContentNormalizer } from '../../services';
10
+ import { buildCoreExtensions } from '../core';
11
11
 
12
12
  const MockStylePreset = Extension.create({
13
13
  name: 'style_preset',
@@ -26,11 +26,9 @@ const MockStylePreset = Extension.create({
26
26
  });
27
27
 
28
28
  function createEditor({ content }) {
29
- const normalizer = new ContentNormalizer();
30
-
31
29
  return new Editor({
32
- content: normalizer.normalize(content),
33
- extensions: CORE_EXTENSIONS.concat(
30
+ content: ContentNormalizer.normalize(content),
31
+ extensions: buildCoreExtensions().concat(
34
32
  MockStylePreset,
35
33
  FontStyle,
36
34
  FontWeight,
@@ -155,6 +153,14 @@ describe('parsing html', () => {
155
153
  expect(editor.getJSON()).toMatchSnapshot();
156
154
  });
157
155
 
156
+ test('should get value from rendered view', () => {
157
+ const editor = createEditor({
158
+ content: '<p><span style="--zw-font-style: italic">lorem</span> ipsum</p>'
159
+ });
160
+
161
+ expect(editor.getJSON()).toMatchSnapshot();
162
+ });
163
+
158
164
  test('should get value from i tag', () => {
159
165
  const editor = createEditor({
160
166
  content: '<p><i>lorem</i> ipsum</p>'
@@ -1,13 +1,13 @@
1
1
  import { Editor, Extension } from '@tiptap/vue-2';
2
- import { ref } from '@vue/composition-api';
2
+ import { ref } from 'vue';
3
3
  import { NodeFactory } from '../../__tests__/utils';
4
4
  import { createCommand } from '../../utils';
5
- import { CORE_EXTENSIONS } from '../core';
6
5
  import { Font } from '../../models';
7
6
  import { FontWeight } from '../FontWeight';
8
7
  import { FontFamily } from '../FontFamily';
9
8
  import { FontStyle } from '../FontStyle';
10
9
  import { ContentNormalizer } from '../../services';
10
+ import { buildCoreExtensions } from '../core';
11
11
 
12
12
  const MockStylePreset = Extension.create({
13
13
  name: 'style_preset',
@@ -25,11 +25,9 @@ const MockStylePreset = Extension.create({
25
25
  });
26
26
 
27
27
  function createEditor({ content }) {
28
- const normalizer = new ContentNormalizer();
29
-
30
28
  return new Editor({
31
- content: normalizer.normalize(content),
32
- extensions: CORE_EXTENSIONS.concat(
29
+ content: ContentNormalizer.normalize(content),
30
+ extensions: buildCoreExtensions().concat(
33
31
  MockStylePreset,
34
32
  FontFamily.configure({
35
33
  fonts: [
@@ -182,6 +180,14 @@ describe('parsing html', () => {
182
180
  expect(editor.getJSON()).toMatchSnapshot();
183
181
  });
184
182
 
183
+ test('should get value from rendered view', () => {
184
+ const editor = createEditor({
185
+ content: '<p><span style="--zw-font-weight: 700">lorem</span> ipsum</p>'
186
+ });
187
+
188
+ expect(editor.getJSON()).toMatchSnapshot();
189
+ });
190
+
185
191
  test('should get value from b tag', () => {
186
192
  const editor = createEditor({
187
193
  content: '<p><b>lorem</b> ipsum</p>'
@@ -205,4 +211,12 @@ describe('parsing html', () => {
205
211
 
206
212
  expect(editor.getJSON()).toMatchSnapshot();
207
213
  });
214
+
215
+ test('should ignore invalid value', () => {
216
+ const editor = createEditor({
217
+ content: '<p><span style="font-weight: var(--font-weight)">lorem</span> ipsum</p>'
218
+ });
219
+
220
+ expect(editor.getJSON()).toMatchSnapshot();
221
+ });
208
222
  });
@@ -1,11 +1,11 @@
1
1
  import { Editor, Extension } from '@tiptap/vue-2';
2
- import { ref } from '@vue/composition-api';
2
+ import { ref } from 'vue';
3
3
  import { NodeFactory } from '../../__tests__/utils';
4
4
  import { createCommand } from '../../utils';
5
- import { CORE_EXTENSIONS } from '../core';
6
5
  import { DeviceManager } from '../DeviceManager';
7
6
  import { LineHeight } from '../LineHeight';
8
7
  import { ContentNormalizer } from '../../services';
8
+ import { buildCoreExtensions } from '../core';
9
9
 
10
10
  const MockStylePreset = Extension.create({
11
11
  name: 'style_preset',
@@ -21,15 +21,17 @@ const MockStylePreset = Extension.create({
21
21
  }
22
22
  });
23
23
 
24
- function createEditor({ content }) {
25
- const normalizer = new ContentNormalizer();
26
-
24
+ function createEditor({ content, wrapperEl }) {
27
25
  return new Editor({
28
- content: normalizer.normalize(content),
29
- extensions: CORE_EXTENSIONS.concat(
26
+ content: ContentNormalizer.normalize(content),
27
+ extensions: buildCoreExtensions().concat(
30
28
  MockStylePreset,
31
- DeviceManager.configure({ deviceRef: ref('desktop') }),
32
- LineHeight
29
+ DeviceManager.configure({
30
+ device: ref('desktop')
31
+ }),
32
+ LineHeight.configure({
33
+ wrapperRef: ref(wrapperEl ?? document.createElement('div'))
34
+ })
33
35
  )
34
36
  });
35
37
  }
@@ -126,14 +128,24 @@ describe('parsing html', () => {
126
128
  });
127
129
 
128
130
  test('should get value from text in px units with no font size', () => {
129
- global.document.body.style.fontSize = '20px';
131
+ const wrapperEl = document.createElement('div');
132
+
133
+ wrapperEl.style.fontSize = '20px';
134
+
135
+ const editor = createEditor({
136
+ content: '<p style="line-height: 24px">test</p>',
137
+ wrapperEl
138
+ });
139
+
140
+ expect(editor.getJSON()).toMatchSnapshot();
141
+ });
130
142
 
143
+ test('should get value from rendered view', () => {
131
144
  const editor = createEditor({
132
- content: '<p style="line-height: 24px">test</p>'
145
+ content: '<p style="--zw-line-height-mobile:1.2;--zw-line-height-desktop:1.4">test</p>'
133
146
  });
134
147
 
135
148
  expect(editor.getJSON()).toMatchSnapshot();
136
- global.document.body.style.removeProperty('font-size');
137
149
  });
138
150
 
139
151
  test('should set null if no alignment', () => {
@@ -0,0 +1,102 @@
1
+ import { ref } from 'vue';
2
+ import { Editor } from '@tiptap/vue-2';
3
+ import { ContentNormalizer } from '../../services';
4
+ import { Link } from '../Link';
5
+ import { NodeFactory } from '../../__tests__/utils';
6
+ import { buildCoreExtensions } from '../core';
7
+
8
+ function createEditor({ content }) {
9
+ return new Editor({
10
+ content: ContentNormalizer.normalize(content),
11
+ extensions: buildCoreExtensions().concat(
12
+ Link.configure({
13
+ preset: 'link',
14
+ baseClass: 'zw ts-',
15
+ pageBlocks: ref([{ id: 987654 }])
16
+ })
17
+ )
18
+ });
19
+ }
20
+
21
+ const createContent = (text) => NodeFactory.doc([
22
+ NodeFactory.paragraph([text])
23
+ ]);
24
+
25
+ const linkAttributes = (href) => ({
26
+ href: href ?? '/test',
27
+ text: 'Hello world link',
28
+ target: '_self',
29
+ destination: 'url'
30
+ });
31
+
32
+ describe('apply link', () => {
33
+ test('should apply link', () => {
34
+ const editor = createEditor({
35
+ content: createContent(NodeFactory.text('hello world'))
36
+ });
37
+
38
+ editor.chain().selectAll().applyLink(linkAttributes()).run();
39
+
40
+ expect(editor.getJSON()).toMatchSnapshot();
41
+ });
42
+
43
+ test('should apply link when no selected text', () => {
44
+ const editor = createEditor({
45
+ content: createContent(NodeFactory.text('Some text'))
46
+ });
47
+
48
+ editor.chain().setTextSelection(6).applyLink(linkAttributes()).run();
49
+
50
+ expect(editor.getJSON()).toMatchSnapshot();
51
+ });
52
+ });
53
+
54
+ describe('parse html', () => {
55
+ test('should parse url links from html', () => {
56
+ const editor = createEditor({
57
+ content: '<a href="https://hello.world" target="_blank">Hello</a>'
58
+ });
59
+
60
+ expect(editor.getJSON()).toMatchSnapshot();
61
+ });
62
+
63
+ test('should parse block links from html', () => {
64
+ const editor = createEditor({
65
+ content: '<a href="#987654" target="_blank">Hello</a>'
66
+ });
67
+
68
+ expect(editor.getJSON()).toMatchSnapshot();
69
+ });
70
+
71
+ test('should parse link target', () => {
72
+ const editor = createEditor({
73
+ content: '<a href="https://hello.world" target="_blank">Hello</a>'
74
+ });
75
+
76
+ expect(editor.getJSON()).toMatchSnapshot();
77
+ });
78
+
79
+ test('should add default self target for links from html without target', () => {
80
+ const editor = createEditor({
81
+ content: '<a href="https://hello.world">Hello</a>'
82
+ });
83
+
84
+ expect(editor.getJSON()).toMatchSnapshot();
85
+ });
86
+
87
+ test('should parse value for relative url', () => {
88
+ const editor = createEditor({
89
+ content: '<a href="/hello-world">Hello</a>'
90
+ });
91
+
92
+ expect(editor.getJSON()).toMatchSnapshot();
93
+ });
94
+
95
+ test('should parse not valid value', () => {
96
+ const editor = createEditor({
97
+ content: '<a href="934238">Hello</a>'
98
+ });
99
+
100
+ expect(editor.getJSON()).toMatchSnapshot();
101
+ });
102
+ });
@@ -1,11 +1,10 @@
1
1
  import { Editor, Extension, Mark } from '@tiptap/vue-2';
2
- import { ref } from '@vue/composition-api';
3
2
  import { NodeFactory } from '../../__tests__/utils';
4
- import { CORE_EXTENSIONS } from '../core';
5
3
  import { StylePreset } from '../StylePreset';
6
4
  import { List } from '../list';
7
5
  import { ListTypes, NodeTypes, TextSettings } from '../../enums';
8
6
  import { ContentNormalizer } from '../../services';
7
+ import { buildCoreExtensions } from '../core';
9
8
 
10
9
  const MockFontSize = Mark.create({
11
10
  name: TextSettings.FONT_SIZE,
@@ -43,17 +42,75 @@ const MockAlignment = Extension.create({
43
42
  ]
44
43
  });
45
44
 
45
+ const MockBackgroundColor = Mark.create({
46
+ name: TextSettings.BACKGROUND_COLOR,
47
+
48
+ addAttributes: () => ({
49
+ value: { default: null }
50
+ }),
51
+
52
+ renderHTML: () => ['span', {}, 0]
53
+ });
54
+
55
+ const MockFontColor = Mark.create({
56
+ name: TextSettings.FONT_COLOR,
57
+
58
+ addAttributes: () => ({
59
+ value: { default: null }
60
+ }),
61
+
62
+ renderHTML: () => ['span', {}, 0]
63
+ });
64
+
65
+ const MockFontFamily = Mark.create({
66
+ name: TextSettings.FONT_FAMILY,
67
+
68
+ addAttributes: () => ({
69
+ value: { default: null }
70
+ }),
71
+
72
+ renderHTML: () => ['span', {}, 0]
73
+ });
74
+
75
+ const MockFontStyle = Mark.create({
76
+ name: TextSettings.FONT_STYLE,
77
+
78
+ addAttributes: () => ({
79
+ value: { default: null }
80
+ }),
81
+
82
+ renderHTML: () => ['span', {}, 0]
83
+ });
84
+
85
+ const MockTextDecoration = Mark.create({
86
+ name: TextSettings.TEXT_DECORATION,
87
+
88
+ addAttributes: () => ({
89
+ value: { default: null }
90
+ }),
91
+
92
+ renderHTML: () => ['span', {}, 0]
93
+ });
94
+
95
+ const MockSuperscript = Mark.create({
96
+ name: TextSettings.SUPERSCRIPT,
97
+
98
+ addAttributes: () => ({
99
+ value: { default: null }
100
+ }),
101
+
102
+ renderHTML: () => ['span', {}, 0]
103
+ });
104
+
46
105
  function createEditor({ content, presets, defaultId }) {
47
106
  return new Promise((resolve) => {
48
- const normalizer = new ContentNormalizer();
49
-
50
107
  const editor = new Editor({
51
- content: normalizer.normalize(content),
108
+ content: ContentNormalizer.normalize(content),
52
109
  onCreate: () => resolve(editor),
53
110
 
54
- extensions: CORE_EXTENSIONS.concat(
111
+ extensions: buildCoreExtensions().concat(
55
112
  StylePreset.configure({
56
- presetsRef: ref(presets),
113
+ presets: presets,
57
114
  baseClass: 'zw ts-',
58
115
  defaultId,
59
116
 
@@ -68,7 +125,13 @@ function createEditor({ content, presets, defaultId }) {
68
125
  }),
69
126
  MockFontSize,
70
127
  MockFontWeight,
71
- MockAlignment
128
+ MockAlignment,
129
+ MockBackgroundColor,
130
+ MockFontColor,
131
+ MockFontFamily,
132
+ MockFontStyle,
133
+ MockTextDecoration,
134
+ MockSuperscript
72
135
  )
73
136
  });
74
137
  });