@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,29 +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';
4
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
+ });
5
16
 
6
17
  const MockFontWeight = Mark.create({
7
- name: 'font_weight',
18
+ name: TextSettings.FONT_WEIGHT,
8
19
 
9
20
  addAttributes: () => ({
10
- value: { required: true }
21
+ value: { default: null }
11
22
  }),
12
23
 
13
- renderHTML(context) {
14
- const { value } = context.HTMLAttributes;
24
+ renderHTML: () => ['span', {}, 0]
25
+ });
26
+
27
+ const MockAlignment = Extension.create({
28
+ name: TextSettings.ALIGNMENT,
15
29
 
16
- return ['span', { style: `font-weight: ${value}` }, 0];
17
- }
30
+ addGlobalAttributes: () => [
31
+ {
32
+ types: [NodeTypes.PARAGRAPH, NodeTypes.HEADING],
33
+ attributes: {
34
+ [TextSettings.ALIGNMENT]: {
35
+ default: null,
36
+ renderHTML: () => ({})
37
+ }
38
+ }
39
+ }
40
+ ]
18
41
  });
19
42
 
20
- function createEditor({ content }) {
21
- const normalizer = new ContentNormalizer();
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,
65
+
66
+ addAttributes: () => ({
67
+ value: { default: null }
68
+ }),
69
+
70
+ renderHTML: () => ['span', {}, 0]
71
+ });
72
+
73
+ const MockFontStyle = Mark.create({
74
+ name: TextSettings.FONT_STYLE,
75
+
76
+ addAttributes: () => ({
77
+ value: { default: null }
78
+ }),
79
+
80
+ renderHTML: () => ['span', {}, 0]
81
+ });
82
+
83
+ const MockTextDecoration = Mark.create({
84
+ name: TextSettings.TEXT_DECORATION,
85
+
86
+ addAttributes: () => ({
87
+ value: { default: null }
88
+ }),
22
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]
101
+ });
102
+
103
+ function createEditor({ content }) {
23
104
  return new Editor({
24
- content: normalizer.normalize(content),
105
+ content: ContentNormalizer.normalize(content),
25
106
  element: document.createElement('div'),
26
- 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
+ )
27
118
  });
28
119
  }
29
120
 
@@ -62,3 +153,38 @@ describe('transform text', () => {
62
153
  expect(editor.getJSON()).toMatchSnapshot();
63
154
  });
64
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,57 @@
1
+ import { ContentNormalizer } from '../../../services';
2
+ import { NodeTypes } from '../../../enums';
3
+ import { ProseMirrorPlugin } from './ProseMirrorPlugin';
4
+
5
+ export class PastePlugin extends ProseMirrorPlugin {
6
+ buildProps() {
7
+ return {
8
+ transformPastedHTML: ContentNormalizer.normalize,
9
+ handlePaste: this._handlePaste.bind(this)
10
+ };
11
+ }
12
+
13
+ _handlePaste(view, _, slice) {
14
+ const transaction = this._insertPastedContent(view, slice)
15
+ .scrollIntoView()
16
+ .setMeta('paste', true)
17
+ .setMeta('uiEvent', 'paste');
18
+
19
+ view.dispatch(transaction);
20
+
21
+ return true;
22
+ }
23
+
24
+ _insertPastedContent({ state, input }, slice) {
25
+ if (!this._isFullBlockSelected(state)) {
26
+ return state.tr.replaceSelection(slice);
27
+ }
28
+
29
+ return state.tr.replaceSelectionWith(slice.content, input.shiftKey);
30
+ }
31
+
32
+ _isFullBlockSelected(state) {
33
+ const blocksSelection = this._expandSelectionToBlocks(state);
34
+ const isFromMatch = this._isMatchPosition(blocksSelection.from, state.selection.from);
35
+ const isToMatch = this._isMatchPosition(blocksSelection.to, state.selection.to);
36
+
37
+ return isFromMatch && isToMatch;
38
+ }
39
+
40
+ _expandSelectionToBlocks({ selection, doc }) {
41
+ let from = selection.from;
42
+ let to = selection.to;
43
+
44
+ doc.nodesBetween(from, to, (node, position, parent) => {
45
+ if (parent.type.name !== NodeTypes.DOCUMENT) return;
46
+
47
+ from = Math.min(from, position + 1);
48
+ to = Math.max(to, position + node.nodeSize - 1);
49
+ });
50
+
51
+ return { from, to };
52
+ }
53
+
54
+ _isMatchPosition(position1, position2) {
55
+ return Math.abs(position1 - position2) < 5;
56
+ }
57
+ }
@@ -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
+ }
@@ -0,0 +1 @@
1
+ export { PastePlugin } from './PastePlugin';
@@ -1,5 +1,3 @@
1
- import History from '@tiptap/extension-history';
2
- import { CORE_EXTENSIONS } from './core';
3
1
  import { FontFamily } from './FontFamily';
4
2
  import { StylePreset } from './StylePreset';
5
3
  import { FontWeight } from './FontWeight';
@@ -13,38 +11,52 @@ import { CaseStyle } from './CaseStyle';
13
11
  import { Alignment } from './Alignment';
14
12
  import { LineHeight } from './LineHeight';
15
13
  import { List } from './list';
14
+ import { Link } from './Link';
16
15
  import { Superscript } from './Superscript';
16
+ import { buildCoreExtensions } from './core';
17
17
 
18
- export { CORE_EXTENSIONS };
18
+ export function buildExtensions(options) {
19
+ const getPresetById = (id) => options.presetsRef.value.find((preset) => preset.id === id);
20
+ const defaultPreset = getPresetById(options.defaultPresetId);
21
+ const linkPreset = getPresetById(options.linkPresetId);
19
22
 
20
- export const getExtensions = (options) => CORE_EXTENSIONS.concat([
21
- History,
22
- StylePreset.configure({
23
- presetsRef: options.presetsRef,
24
- defaultId: options.defaultPresetId,
25
- baseClass: options.basePresetClass,
26
- makeVariable: options.makePresetVariable
27
- }),
28
- List.configure({
29
- baseClass: options.baseListClass
30
- }),
31
- DeviceManager.configure({
32
- deviceRef: options.deviceRef
33
- }),
34
- FontFamily.configure({
35
- fonts: options.fonts
36
- }),
37
- FontWeight,
38
- FontSize.configure({
39
- minSize: options.minFontSize,
40
- maxSize: options.maxFontSize
41
- }),
42
- FontColor,
43
- BackgroundColor,
44
- FontStyle,
45
- TextDecoration,
46
- CaseStyle,
47
- Superscript,
48
- Alignment,
49
- LineHeight
50
- ]);
23
+ return buildCoreExtensions(options).concat([
24
+ StylePreset.configure({
25
+ presets: options.presetsRef,
26
+ defaultId: options.defaultPresetId,
27
+ baseClass: options.basePresetClass,
28
+ makeVariable: options.makePresetVariable
29
+ }),
30
+ List.configure({
31
+ baseClass: options.baseListClass
32
+ }),
33
+ DeviceManager.configure({
34
+ device: options.deviceRef
35
+ }),
36
+ FontFamily.configure({
37
+ fonts: options.fonts,
38
+ defaultFont: defaultPreset.common.font_family
39
+ }),
40
+ FontWeight,
41
+ FontSize.configure({
42
+ minSize: options.minFontSize,
43
+ maxSize: options.maxFontSize,
44
+ wrapperRef: options.wrapperRef
45
+ }),
46
+ FontColor,
47
+ BackgroundColor,
48
+ FontStyle,
49
+ TextDecoration,
50
+ CaseStyle,
51
+ Superscript,
52
+ Alignment,
53
+ LineHeight.configure({
54
+ wrapperRef: options.wrapperRef
55
+ }),
56
+ Link.configure({
57
+ preset: linkPreset,
58
+ basePresetClass: options.basePresetClass,
59
+ pageBlocks: options.pageBlocksRef
60
+ })
61
+ ]);
62
+ }
@@ -1,5 +1,5 @@
1
1
  import { Node, wrappingInputRule } 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 { ListTypes, NodeTypes } from '../../enums';
5
5
  import { ListItem } from './ListItem';
@@ -80,12 +80,11 @@ export const List = Node.create({
80
80
  return;
81
81
  }
82
82
 
83
- return chain().removeList()._addList(type).run();
83
+ return chain().applyDefaultPreset()._addList(type).run();
84
84
  }),
85
85
 
86
86
  _addList: createCommand(({ chain }, type) => {
87
87
  return chain()
88
- .removePreset()
89
88
  .toggleList(NodeTypes.LIST, NodeTypes.LIST_ITEM)
90
89
  .setBlockAttributes('bullet', { type })
91
90
  .run();
@@ -1,24 +1,21 @@
1
1
  import { Editor } from '@tiptap/vue-2';
2
- import { ref } from '@vue/composition-api';
3
2
  import { NodeFactory } from '../../../__tests__/utils';
4
3
  import { ListTypes } from '../../../enums';
5
- import { CORE_EXTENSIONS } from '../../core';
6
4
  import { StylePreset } from '../../StylePreset';
7
5
  import { List } from '../List';
8
6
  import { ContentNormalizer } from '../../../services';
7
+ import { buildCoreExtensions } from '../../core';
9
8
 
10
9
  function createEditor({ content }) {
11
- const normalizer = new ContentNormalizer();
12
-
13
10
  return new Editor({
14
- content: normalizer.normalize(content),
11
+ content: ContentNormalizer.normalize(content),
15
12
  element: document.createElement('div'),
16
- extensions: CORE_EXTENSIONS.concat(
13
+ extensions: buildCoreExtensions().concat(
17
14
  List.configure({
18
15
  baseClass: 'zw-list--'
19
16
  }),
20
17
  StylePreset.configure({
21
- presetsRef: ref([
18
+ presets: [
22
19
  {
23
20
  id: 'regular-1',
24
21
  common: {},
@@ -26,7 +23,7 @@ function createEditor({ content }) {
26
23
  tablet: {},
27
24
  desktop: {}
28
25
  }
29
- ]),
26
+ ],
30
27
  defaultId: 'regular-1',
31
28
  baseClass: 'zw ts-'
32
29
  })
@@ -14,7 +14,9 @@ Object {
14
14
  "content": Array [
15
15
  Object {
16
16
  "attrs": Object {
17
- "preset": null,
17
+ "preset": Object {
18
+ "id": "regular-1",
19
+ },
18
20
  },
19
21
  "content": Array [
20
22
  Object {
@@ -49,7 +51,9 @@ Object {
49
51
  "content": Array [
50
52
  Object {
51
53
  "attrs": Object {
52
- "preset": null,
54
+ "preset": Object {
55
+ "id": "regular-1",
56
+ },
53
57
  },
54
58
  "content": Array [
55
59
  Object {
@@ -66,7 +70,9 @@ Object {
66
70
  "content": Array [
67
71
  Object {
68
72
  "attrs": Object {
69
- "preset": null,
73
+ "preset": Object {
74
+ "id": "regular-1",
75
+ },
70
76
  },
71
77
  "content": Array [
72
78
  Object {
@@ -92,7 +98,9 @@ Object {
92
98
  "content": Array [
93
99
  Object {
94
100
  "attrs": Object {
95
- "preset": null,
101
+ "preset": Object {
102
+ "id": "regular-1",
103
+ },
96
104
  },
97
105
  "content": Array [
98
106
  Object {
@@ -104,7 +112,9 @@ Object {
104
112
  },
105
113
  Object {
106
114
  "attrs": Object {
107
- "preset": null,
115
+ "preset": Object {
116
+ "id": "regular-1",
117
+ },
108
118
  },
109
119
  "content": Array [
110
120
  Object {
@@ -133,7 +143,9 @@ Object {
133
143
  "content": Array [
134
144
  Object {
135
145
  "attrs": Object {
136
- "preset": null,
146
+ "preset": Object {
147
+ "id": "regular-1",
148
+ },
137
149
  },
138
150
  "content": Array [
139
151
  Object {
@@ -150,7 +162,9 @@ Object {
150
162
  "content": Array [
151
163
  Object {
152
164
  "attrs": Object {
153
- "preset": null,
165
+ "preset": Object {
166
+ "id": "regular-1",
167
+ },
154
168
  },
155
169
  "content": Array [
156
170
  Object {
@@ -221,7 +235,9 @@ Object {
221
235
  "content": Array [
222
236
  Object {
223
237
  "attrs": Object {
224
- "preset": null,
238
+ "preset": Object {
239
+ "id": "regular-1",
240
+ },
225
241
  },
226
242
  "content": Array [
227
243
  Object {
@@ -256,7 +272,9 @@ Object {
256
272
  "content": Array [
257
273
  Object {
258
274
  "attrs": Object {
259
- "preset": null,
275
+ "preset": Object {
276
+ "id": "regular-1",
277
+ },
260
278
  },
261
279
  "content": Array [
262
280
  Object {
@@ -291,7 +309,9 @@ Object {
291
309
  "content": Array [
292
310
  Object {
293
311
  "attrs": Object {
294
- "preset": null,
312
+ "preset": Object {
313
+ "id": "regular-1",
314
+ },
295
315
  },
296
316
  "content": Array [
297
317
  Object {
@@ -326,7 +346,9 @@ Object {
326
346
  "content": Array [
327
347
  Object {
328
348
  "attrs": Object {
329
- "preset": null,
349
+ "preset": Object {
350
+ "id": "regular-1",
351
+ },
330
352
  },
331
353
  "content": Array [
332
354
  Object {
@@ -361,7 +383,9 @@ Object {
361
383
  "content": Array [
362
384
  Object {
363
385
  "attrs": Object {
364
- "preset": null,
386
+ "preset": Object {
387
+ "id": "regular-1",
388
+ },
365
389
  },
366
390
  "content": Array [
367
391
  Object {
@@ -396,7 +420,9 @@ Object {
396
420
  "content": Array [
397
421
  Object {
398
422
  "attrs": Object {
399
- "preset": null,
423
+ "preset": Object {
424
+ "id": "regular-1",
425
+ },
400
426
  },
401
427
  "content": Array [
402
428
  Object {
@@ -431,7 +457,9 @@ Object {
431
457
  "content": Array [
432
458
  Object {
433
459
  "attrs": Object {
434
- "preset": null,
460
+ "preset": Object {
461
+ "id": "regular-1",
462
+ },
435
463
  },
436
464
  "content": Array [
437
465
  Object {
@@ -466,7 +494,9 @@ Object {
466
494
  "content": Array [
467
495
  Object {
468
496
  "attrs": Object {
469
- "preset": null,
497
+ "preset": Object {
498
+ "id": "regular-1",
499
+ },
470
500
  },
471
501
  "content": Array [
472
502
  Object {
@@ -501,7 +531,9 @@ Object {
501
531
  "content": Array [
502
532
  Object {
503
533
  "attrs": Object {
504
- "preset": null,
534
+ "preset": Object {
535
+ "id": "regular-1",
536
+ },
505
537
  },
506
538
  "content": Array [
507
539
  Object {
@@ -536,7 +568,9 @@ Object {
536
568
  "content": Array [
537
569
  Object {
538
570
  "attrs": Object {
539
- "preset": null,
571
+ "preset": Object {
572
+ "id": "regular-1",
573
+ },
540
574
  },
541
575
  "content": Array [
542
576
  Object {
@@ -571,7 +605,9 @@ Object {
571
605
  "content": Array [
572
606
  Object {
573
607
  "attrs": Object {
574
- "preset": null,
608
+ "preset": Object {
609
+ "id": "regular-1",
610
+ },
575
611
  },
576
612
  "content": Array [
577
613
  Object {
@@ -606,7 +642,9 @@ Object {
606
642
  "content": Array [
607
643
  Object {
608
644
  "attrs": Object {
609
- "preset": null,
645
+ "preset": Object {
646
+ "id": "regular-1",
647
+ },
610
648
  },
611
649
  "content": Array [
612
650
  Object {
@@ -641,7 +679,9 @@ Object {
641
679
  "content": Array [
642
680
  Object {
643
681
  "attrs": Object {
644
- "preset": null,
682
+ "preset": Object {
683
+ "id": "regular-1",
684
+ },
645
685
  },
646
686
  "content": Array [
647
687
  Object {