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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (217) hide show
  1. package/.editorconfig +1 -1
  2. package/.eslintignore +1 -0
  3. package/.eslintrc.js +2 -2
  4. package/.github/dependabot.yaml +1 -0
  5. package/.lintstagedrc +2 -2
  6. package/.release-it.json +3 -2
  7. package/.stylelintignore +1 -0
  8. package/.stylelintrc +0 -4
  9. package/README.md +5 -3
  10. package/config/jest/setupTests.js +7 -4
  11. package/config/vite/lib.config.js +31 -0
  12. package/config/vite/settings.js +9 -0
  13. package/config/webpack/example.config.js +2 -0
  14. package/config/webpack/lib.config.js +43 -0
  15. package/config/webpack/loaders/style-loader.js +3 -1
  16. package/config/webpack/loaders/svg-loader.js +1 -1
  17. package/dist/wysiwyg.css +1 -0
  18. package/dist/wysiwyg.mjs +18198 -0
  19. package/example/ExampleApp.vue +52 -33
  20. package/example/example.js +25 -2
  21. package/example/pageBlocks.js +31 -0
  22. package/example/presets.js +4 -2
  23. package/lib/Wysiwyg.vue +42 -22
  24. package/lib/__tests__/utils/withComponentContext.js +1 -1
  25. package/lib/assets/icons/alignment-center.svg +3 -0
  26. package/lib/assets/icons/alignment-justify.svg +3 -0
  27. package/lib/assets/icons/alignment-left.svg +3 -0
  28. package/lib/assets/icons/alignment-right.svg +3 -0
  29. package/lib/assets/icons/arrow.svg +3 -0
  30. package/lib/assets/icons/background-color.svg +3 -0
  31. package/lib/assets/icons/case-style.svg +3 -0
  32. package/lib/assets/icons/font-color.svg +5 -0
  33. package/lib/assets/icons/italic.svg +3 -0
  34. package/lib/assets/icons/line-height.svg +3 -0
  35. package/lib/assets/icons/link.svg +3 -0
  36. package/lib/assets/icons/list-circle.svg +3 -0
  37. package/lib/assets/icons/list-decimal.svg +3 -0
  38. package/lib/assets/icons/list-disc.svg +3 -0
  39. package/lib/assets/icons/list-latin.svg +3 -0
  40. package/lib/assets/icons/list-roman.svg +3 -0
  41. package/lib/assets/icons/list-square.svg +3 -0
  42. package/lib/assets/icons/remove-format.svg +3 -0
  43. package/lib/assets/icons/reset-styles.svg +3 -0
  44. package/lib/assets/icons/strike-through.svg +3 -0
  45. package/lib/assets/icons/superscript.svg +3 -0
  46. package/lib/assets/icons/underline.svg +3 -0
  47. package/lib/assets/icons/unlink.svg +3 -0
  48. package/lib/components/base/Button.vue +22 -2
  49. package/lib/components/base/Checkbox.vue +89 -0
  50. package/lib/components/base/FieldLabel.vue +2 -1
  51. package/lib/components/base/Icon.vue +19 -11
  52. package/lib/components/base/Modal.vue +1 -2
  53. package/lib/components/base/NumberField.vue +2 -2
  54. package/lib/components/base/Range.vue +1 -1
  55. package/lib/components/base/ScrollView.vue +2 -2
  56. package/lib/components/base/TextField.vue +106 -0
  57. package/lib/components/base/__tests__/Icon.test.js +6 -13
  58. package/lib/components/base/__tests__/Modal.test.js +8 -2
  59. package/lib/components/base/__tests__/TextField.test.js +57 -0
  60. package/lib/components/base/__tests__/__snapshots__/TextField.test.js.snap +9 -0
  61. package/lib/components/base/colorPicker/ColorPicker.vue +1 -1
  62. package/lib/components/base/colorPicker/composables/__tests__/usePickerApi.test.js +1 -1
  63. package/lib/components/base/colorPicker/composables/usePickerApi.js +1 -1
  64. package/lib/components/base/colorPicker/composables/usePickerHotkeys.js +3 -2
  65. package/lib/components/base/composables/__tests__/useActivatedListener.test.js +1 -1
  66. package/lib/components/base/composables/__tests__/useDeselectionLock.test.js +1 -1
  67. package/lib/components/base/composables/__tests__/useElementRef.test.js +1 -1
  68. package/lib/components/base/composables/__tests__/useModalToggler.test.js +1 -1
  69. package/lib/components/base/composables/__tests__/useNumberValue.test.js +1 -1
  70. package/lib/components/base/composables/__tests__/useScrollView.test.js +1 -1
  71. package/lib/components/base/composables/__tests__/useTempValue.test.js +1 -1
  72. package/lib/components/base/composables/index.js +1 -0
  73. package/lib/components/base/composables/useActivatedListener.js +1 -1
  74. package/lib/components/base/composables/useDeselectionLock.js +1 -1
  75. package/lib/components/base/composables/useElementRef.js +1 -1
  76. package/lib/components/base/composables/useModalToggler.js +1 -1
  77. package/lib/components/base/composables/useScrollView.js +1 -1
  78. package/lib/components/base/composables/useTempValue.js +1 -1
  79. package/lib/components/base/composables/useValidator.js +19 -0
  80. package/lib/components/base/dropdown/Dropdown.vue +16 -4
  81. package/lib/components/base/dropdown/DropdownActivator.vue +19 -3
  82. package/lib/components/base/dropdown/DropdownGroup.vue +1 -1
  83. package/lib/components/base/dropdown/DropdownMenu.vue +1 -1
  84. package/lib/components/base/dropdown/DropdownOption.vue +1 -1
  85. package/lib/components/base/dropdown/__tests__/DropdownActivator.test.js +1 -1
  86. package/lib/components/base/dropdown/__tests__/DropdownMenu.test.js +1 -1
  87. package/lib/components/base/dropdown/__tests__/DropdownOption.test.js +1 -1
  88. package/lib/components/base/dropdown/composables/__tests__/useActiveOptionManager.test.js +1 -1
  89. package/lib/components/base/dropdown/composables/__tests__/useDropdownEntityTitle.test.js +1 -1
  90. package/lib/components/base/dropdown/composables/useActiveOptionManager.js +1 -1
  91. package/lib/components/base/dropdown/composables/useDropdownEntityTitle.js +1 -1
  92. package/lib/components/base/index.js +3 -1
  93. package/lib/components/toolbar/Toolbar.vue +49 -9
  94. package/lib/components/toolbar/ToolbarDivider.vue +1 -1
  95. package/lib/components/toolbar/ToolbarFull.vue +10 -2
  96. package/lib/components/toolbar/__tests__/Toolbar.test.js +8 -1
  97. package/lib/components/toolbar/controls/AlignmentControl.vue +1 -1
  98. package/lib/components/toolbar/controls/AlignmentDeviceControl.vue +1 -1
  99. package/lib/components/toolbar/controls/BackgroundColorControl.vue +1 -1
  100. package/lib/components/toolbar/controls/CaseStyleControl.vue +1 -1
  101. package/lib/components/toolbar/controls/FontColorControl.vue +1 -1
  102. package/lib/components/toolbar/controls/FontFamilyControl.vue +1 -1
  103. package/lib/components/toolbar/controls/FontSizeControl.vue +8 -1
  104. package/lib/components/toolbar/controls/FontWeightControl.vue +1 -1
  105. package/lib/components/toolbar/controls/ItalicControl.vue +1 -1
  106. package/lib/components/toolbar/controls/LineHeightControl.vue +1 -1
  107. package/lib/components/toolbar/controls/ListControl.vue +2 -6
  108. package/lib/components/toolbar/controls/RemoveFormatControl.vue +1 -1
  109. package/lib/components/toolbar/controls/StrikeThroughControl.vue +1 -1
  110. package/lib/components/toolbar/controls/StylePresetControl.vue +1 -1
  111. package/lib/components/toolbar/controls/SuperscriptControl.vue +1 -1
  112. package/lib/components/toolbar/controls/UnderlineControl.vue +2 -2
  113. package/lib/components/toolbar/controls/__tests__/AlignmentControl.test.js +1 -1
  114. package/lib/components/toolbar/controls/__tests__/AlignmentDeviceControl.test.js +1 -1
  115. package/lib/components/toolbar/controls/__tests__/BackgroundColorControl.test.js +1 -1
  116. package/lib/components/toolbar/controls/__tests__/CaseStyleControl.test.js +1 -1
  117. package/lib/components/toolbar/controls/__tests__/FontColorControl.test.js +1 -1
  118. package/lib/components/toolbar/controls/__tests__/FontFamilyControl.test.js +1 -1
  119. package/lib/components/toolbar/controls/__tests__/FontSizeControl.test.js +1 -1
  120. package/lib/components/toolbar/controls/__tests__/FontWeightControl.test.js +1 -1
  121. package/lib/components/toolbar/controls/__tests__/ItalicControl.test.js +1 -1
  122. package/lib/components/toolbar/controls/__tests__/LineHeightControl.test.js +1 -1
  123. package/lib/components/toolbar/controls/__tests__/ListControl.test.js +1 -1
  124. package/lib/components/toolbar/controls/__tests__/StrikeThroughControl.test.js +1 -1
  125. package/lib/components/toolbar/controls/__tests__/StylePresetControl.test.js +1 -1
  126. package/lib/components/toolbar/controls/__tests__/UnderlineControl.test.js +5 -1
  127. package/lib/components/toolbar/controls/composables/useRecentFonts.js +1 -1
  128. package/lib/components/toolbar/controls/index.js +1 -0
  129. package/lib/components/toolbar/controls/link/LinkControl.vue +152 -0
  130. package/lib/components/toolbar/controls/link/LinkControlApply.vue +35 -0
  131. package/lib/components/toolbar/controls/link/LinkControlHeader.vue +67 -0
  132. package/lib/components/toolbar/controls/link/composables/index.js +1 -0
  133. package/lib/components/toolbar/controls/link/composables/useLink.js +61 -0
  134. package/lib/components/toolbar/controls/link/destination/LinkControlDestination.vue +103 -0
  135. package/lib/components/toolbar/controls/link/destination/LinkControlPageBlock.vue +54 -0
  136. package/lib/components/toolbar/controls/link/destination/LinkControlUrl.vue +52 -0
  137. package/lib/components/toolbar/controls/link/destination/index.js +1 -0
  138. package/lib/components/toolbar/controls/link/index.js +1 -0
  139. package/lib/composables/__tests__/useEditor.test.js +15 -6
  140. package/lib/composables/useEditor.js +13 -8
  141. package/lib/composables/useToolbar.js +14 -29
  142. package/lib/directives/outClick.js +20 -4
  143. package/lib/enums/LinkDestinations.js +4 -0
  144. package/lib/enums/LinkTargets.js +4 -0
  145. package/lib/enums/TextSettings.js +3 -1
  146. package/lib/enums/index.js +2 -0
  147. package/lib/extensions/Alignment.js +22 -4
  148. package/lib/extensions/BackgroundColor.js +17 -2
  149. package/lib/extensions/DeviceManager.js +2 -5
  150. package/lib/extensions/FontColor.js +17 -2
  151. package/lib/extensions/FontFamily.js +27 -3
  152. package/lib/extensions/FontSize.js +29 -4
  153. package/lib/extensions/FontStyle.js +24 -3
  154. package/lib/extensions/FontWeight.js +34 -2
  155. package/lib/extensions/LineHeight.js +30 -4
  156. package/lib/extensions/Link.js +101 -0
  157. package/lib/extensions/StylePreset.js +38 -15
  158. package/lib/extensions/TextDecoration.js +30 -4
  159. package/lib/extensions/__tests__/Alignment.test.js +32 -5
  160. package/lib/extensions/__tests__/BackgroundColor.test.js +39 -4
  161. package/lib/extensions/__tests__/CaseStyle.test.js +4 -3
  162. package/lib/extensions/__tests__/FontColor.test.js +39 -4
  163. package/lib/extensions/__tests__/FontFamily.test.js +60 -6
  164. package/lib/extensions/__tests__/FontSize.test.js +40 -5
  165. package/lib/extensions/__tests__/FontStyle.test.js +47 -4
  166. package/lib/extensions/__tests__/FontWeight.test.js +67 -4
  167. package/lib/extensions/__tests__/LineHeight.test.js +51 -5
  168. package/lib/extensions/__tests__/StylePreset.test.js +144 -6
  169. package/lib/extensions/__tests__/TextDecoration.test.js +88 -4
  170. package/lib/extensions/__tests__/__snapshots__/Alignment.test.js.snap +70 -2
  171. package/lib/extensions/__tests__/__snapshots__/BackgroundColor.test.js.snap +121 -1
  172. package/lib/extensions/__tests__/__snapshots__/FontColor.test.js.snap +109 -1
  173. package/lib/extensions/__tests__/__snapshots__/FontFamily.test.js.snap +179 -1
  174. package/lib/extensions/__tests__/__snapshots__/FontSize.test.js.snap +132 -2
  175. package/lib/extensions/__tests__/__snapshots__/FontStyle.test.js.snap +142 -1
  176. package/lib/extensions/__tests__/__snapshots__/FontWeight.test.js.snap +179 -1
  177. package/lib/extensions/__tests__/__snapshots__/LineHeight.test.js.snap +118 -2
  178. package/lib/extensions/__tests__/__snapshots__/StylePreset.test.js.snap +171 -2
  179. package/lib/extensions/__tests__/__snapshots__/TextDecoration.test.js.snap +300 -3
  180. package/lib/extensions/core/CopyPasteProcessor.js +10 -0
  181. package/lib/extensions/core/NodeProcessor.js +1 -1
  182. package/lib/extensions/core/TextProcessor.js +10 -0
  183. package/lib/extensions/core/__tests__/NodeProcessor.test.js +4 -3
  184. package/lib/extensions/core/__tests__/SelectionProcessor.test.js +9 -6
  185. package/lib/extensions/core/__tests__/TextProcessor.test.js +139 -10
  186. package/lib/extensions/core/__tests__/__snapshots__/TextProcessor.test.js.snap +26 -0
  187. package/lib/extensions/core/index.js +11 -2
  188. package/lib/extensions/core/plugins/PastePlugin.js +48 -0
  189. package/lib/extensions/core/plugins/ProseMirrorPlugin.js +20 -0
  190. package/lib/extensions/core/plugins/index.js +1 -0
  191. package/lib/extensions/index.js +41 -33
  192. package/lib/extensions/list/List.js +35 -1
  193. package/lib/extensions/list/__tests__/List.test.js +117 -8
  194. package/lib/extensions/list/__tests__/__snapshots__/List.test.js.snap +481 -0
  195. package/lib/injectionTokens.js +2 -1
  196. package/lib/services/ContentNormalizer.js +157 -0
  197. package/lib/services/ContextWidnow.js +23 -0
  198. package/lib/services/Storage.js +1 -13
  199. package/lib/services/__tests__/ContentNormalizer.test.js +74 -0
  200. package/lib/services/__tests__/FavoriteColors.test.js +20 -0
  201. package/lib/services/__tests__/JsonSerializer.test.js +23 -0
  202. package/lib/services/__tests__/Storage.test.js +79 -0
  203. package/lib/services/index.js +2 -0
  204. package/lib/styles/content.css +96 -9
  205. package/lib/styles/helpers/offsets.css +16 -0
  206. package/lib/styles/variables.css +6 -0
  207. package/lib/utils/__tests__/__snapshots__/renderInlineSetting.test.js.snap +4 -4
  208. package/lib/utils/__tests__/convertColor.test.js +19 -0
  209. package/lib/utils/__tests__/createKeyboardShortcut.test.js +25 -0
  210. package/lib/utils/__tests__/renderInlineSetting.test.js +26 -0
  211. package/lib/utils/convertColor.js +7 -0
  212. package/lib/utils/importIcon.js +13 -0
  213. package/lib/utils/index.js +2 -0
  214. package/lib/utils/renderInlineSetting.js +2 -2
  215. package/package.json +21 -16
  216. package/lib/assets/icons.svg +0 -69
  217. package/lib/composables/__tests__/useToolbar.test.js +0 -56
@@ -1,5 +1,5 @@
1
1
  import { shallowMount } from '@vue/test-utils';
2
- import { h, ref } from '@vue/composition-api';
2
+ import { h, ref } from 'vue';
3
3
  import { InjectionTokens } from '../../../../injectionTokens';
4
4
  import { Dropdown, Icon } from '../../../base';
5
5
  import ListControl from '../ListControl';
@@ -1,5 +1,5 @@
1
1
  import { shallowMount } from '@vue/test-utils';
2
- import { ref } from '@vue/composition-api';
2
+ import { ref } from 'vue';
3
3
  import { InjectionTokens } from '../../../../injectionTokens';
4
4
  import { Button } from '../../../base';
5
5
  import StrikeThroughControl from '../StrikeThroughControl';
@@ -1,5 +1,5 @@
1
1
  import { shallowMount } from '@vue/test-utils';
2
- import { ref } from '@vue/composition-api';
2
+ import { ref } from 'vue';
3
3
  import { InjectionTokens } from '../../../../injectionTokens';
4
4
  import { Button, Dropdown } from '../../../base';
5
5
  import StylePresetControl from '../StylePresetControl';
@@ -1,5 +1,5 @@
1
1
  import { shallowMount } from '@vue/test-utils';
2
- import { ref } from '@vue/composition-api';
2
+ import { ref } from 'vue';
3
3
  import { InjectionTokens } from '../../../../injectionTokens';
4
4
  import { Button } from '../../../base';
5
5
  import UnderlineControl from '../UnderlineControl';
@@ -12,6 +12,10 @@ const createEditor = ({ isUnderline } = {}) => ({
12
12
  run: jest.fn()
13
13
  },
14
14
 
15
+ isActive() {
16
+ return false;
17
+ },
18
+
15
19
  chain() {
16
20
  return this.commands;
17
21
  }
@@ -1,4 +1,4 @@
1
- import { computed, inject, ref } from '@vue/composition-api';
1
+ import { computed, inject, ref } from 'vue';
2
2
  import { InjectionTokens } from '../../../../injectionTokens';
3
3
 
4
4
  const STORAGE_KEY = 'wswg.recently_used_fonts';
@@ -14,3 +14,4 @@ export { default as AlignmentDeviceControl } from './AlignmentDeviceControl';
14
14
  export { default as LineHeightControl } from './LineHeightControl';
15
15
  export { default as ListControl } from './ListControl';
16
16
  export { default as RemoveFormatControl } from './RemoveFormatControl';
17
+ export { LinkControl } from './link';
@@ -0,0 +1,152 @@
1
+ <template>
2
+ <div class="zw-position--relative" ref="wrapperRef">
3
+ <Button icon skin="toolbar" :active="isActive" @click="toggler.open" v-tooltip="'Link'">
4
+ <Icon name="link" size="28px" auto-color />
5
+ </Button>
6
+
7
+ <Modal class="zw-link-modal" :toggler="toggler" ref="modalRef">
8
+ <LinkControlHeader @remove-link="removeLink" />
9
+
10
+ <div class="zw-link-modal__body">
11
+ <TextField
12
+ class="zw-margin-bottom--sm"
13
+ :value="link.linkData.value.text"
14
+ label="Text to display"
15
+ placeholder="Type Text"
16
+ :error="nameValidator.error.value"
17
+ @input="link.updateText"
18
+ />
19
+
20
+ <LinkControlDestination
21
+ class="zw-margin-bottom--md"
22
+ :link="link"
23
+ :validator="urlValidator"
24
+ @reset-errors="resetErrors"
25
+ />
26
+
27
+ <LinkControlApply @cancel="toggler.close" @apply="applyLink" />
28
+ </div>
29
+ </Modal>
30
+ </div>
31
+ </template>
32
+
33
+ <script>
34
+ import { computed, ref, inject } from 'vue';
35
+ import { InjectionTokens } from '../../../../injectionTokens';
36
+ import { tooltip } from '../../../../directives';
37
+ import { useValidator } from '../../../base/composables';
38
+ import { Button, Icon, Modal, TextField, useModalToggler } from '../../../base';
39
+ import LinkControlHeader from './LinkControlHeader';
40
+ import LinkControlApply from './LinkControlApply';
41
+ import { useLink } from './composables';
42
+ import { LinkControlDestination } from './destination';
43
+
44
+ export default {
45
+ name: 'LinkControl',
46
+
47
+ components: {
48
+ LinkControlDestination,
49
+ LinkControlApply,
50
+ LinkControlHeader,
51
+ TextField,
52
+ Modal,
53
+ Icon,
54
+ Button
55
+ },
56
+
57
+ directives: {
58
+ tooltip
59
+ },
60
+
61
+ setup() {
62
+ const wrapperRef = ref(null);
63
+ const modalRef = ref(null);
64
+ const nameError = ref(false);
65
+ const urlError = ref(false);
66
+
67
+ const editor = inject(InjectionTokens.EDITOR);
68
+
69
+ const link = useLink();
70
+
71
+ const resetErrors = () => {
72
+ nameError.value = null;
73
+ urlError.value = null;
74
+ };
75
+
76
+ const onBeforeOpened = () => {
77
+ editor.commands.extendMarkRange('link');
78
+ resetErrors();
79
+ link.prepareInitialFields();
80
+ };
81
+
82
+ const toggler = useModalToggler({
83
+ onBeforeOpened: () => onBeforeOpened(),
84
+ wrapperRef,
85
+ modalRef
86
+ });
87
+
88
+ const isActive = computed(() => toggler.isOpened.value || editor.isActive('link'));
89
+ const isEmpty = () => {
90
+ return link.linkData.value.text ? false : 'Can\'t be empty';
91
+ };
92
+ const isUrl = () => {
93
+ if (link.currentDestination.value.id !== 'url') return false;
94
+
95
+ return /(^(https?:\/\/|\/)(?:www\.|(?!www))?[^\s])/.test(link.destinationHrefs.value.url) ? false : 'Please enter a valid URL';
96
+ };
97
+
98
+ const nameValidator = useValidator({
99
+ validations: [isEmpty],
100
+ value: link.linkData.value.text
101
+ });
102
+
103
+ const urlValidator = useValidator({
104
+ validations: [isUrl],
105
+ value: link.linkData.value.text
106
+ });
107
+
108
+ const applyLink = () => {
109
+ urlError.value = urlValidator.validate();
110
+ nameError.value = nameValidator.validate();
111
+
112
+ if (urlError.value || nameError.value) return;
113
+
114
+ link.apply();
115
+ toggler.close();
116
+ };
117
+
118
+ const removeLink = () => {
119
+ link.removeLink();
120
+ toggler.close();
121
+ };
122
+
123
+ return {
124
+ wrapperRef,
125
+ modalRef,
126
+ link,
127
+ toggler,
128
+ isActive,
129
+ nameValidator,
130
+ urlValidator,
131
+ nameError,
132
+ resetErrors,
133
+ applyLink,
134
+ removeLink
135
+ };
136
+ }
137
+ };
138
+ </script>
139
+
140
+ <style scoped>
141
+ .zw-link-modal {
142
+ width: 266px;
143
+ }
144
+
145
+ .zw-link-modal__body {
146
+ padding: var(--zw-offset-sm);
147
+ }
148
+
149
+ ::v-deep .zw-link-modal-dropdown__option {
150
+ width: 234px;
151
+ }
152
+ </style>
@@ -0,0 +1,35 @@
1
+ <template>
2
+ <div class="zw-link-modal__apply">
3
+ <Button class="zw-margin-right--xs" skin="secondary" @click="cancel">
4
+ Cancel
5
+ </Button>
6
+
7
+ <Button @click="apply" skin="primary">
8
+ Save
9
+ </Button>
10
+ </div>
11
+ </template>
12
+
13
+ <script>
14
+ import { Button } from '../../../base';
15
+
16
+ export default {
17
+ name: 'LinkControlApply',
18
+
19
+ components: { Button },
20
+
21
+ setup(_, { emit }) {
22
+ const cancel = () => emit('cancel');
23
+ const apply = () => emit('apply');
24
+
25
+ return { cancel, apply };
26
+ }
27
+ };
28
+ </script>
29
+
30
+ <style scoped>
31
+ .zw-link-modal__apply {
32
+ display: flex;
33
+ justify-content: flex-end;
34
+ }
35
+ </style>
@@ -0,0 +1,67 @@
1
+ <template>
2
+ <div class="zw-link-modal-header">
3
+ <span class="zw-link-modal-header__title">Link</span>
4
+
5
+ <Button class="zw-link-modal-header__unlink-button" :disabled="!isLink" @click="removeLink">
6
+ <Icon class="zw-link-modal-header__unlink-icon" name="unlink" size="14px" auto-color />
7
+ Remove
8
+ </Button>
9
+ </div>
10
+ </template>
11
+
12
+ <script>
13
+ import { computed, inject } from 'vue';
14
+ import { Icon, Button } from '../../../base';
15
+ import { InjectionTokens } from '../../../../injectionTokens';
16
+
17
+ export default {
18
+ name: 'LinkControlHeader',
19
+
20
+ components: { Icon, Button },
21
+
22
+ setup(_, { emit }) {
23
+ const editor = inject(InjectionTokens.EDITOR);
24
+ const isLink = computed(() => editor.isActive('link'));
25
+
26
+ const removeLink = () => emit('remove-link');
27
+
28
+ return { isLink, removeLink };
29
+ }
30
+ };
31
+ </script>
32
+
33
+ <style scoped>
34
+ .zw-link-modal-header {
35
+ display: flex;
36
+ align-items: center;
37
+ justify-content: space-between;
38
+ padding: var(--zw-offset-sm);
39
+ border-bottom: 2px solid rgb(var(--zw-color-n5));
40
+ }
41
+
42
+ .zw-link-modal-header__title {
43
+ text-transform: uppercase;
44
+ font-weight: var(--zw-font-weight-semibold);
45
+ font-size: var(--zw-font-size-xxs);
46
+ color: rgb(var(--zw-color-white));
47
+ }
48
+
49
+ .zw-link-modal-header__unlink-icon {
50
+ margin-right: var(--zw-offset-xxs);
51
+ }
52
+
53
+ .zw-link-modal-header__unlink-button {
54
+ color: rgb(var(--zw-color-n80));
55
+ font-size: var(--zw-font-size-xxs);
56
+ transition: 0.1s opacity ease-out;
57
+ will-change: opacity;
58
+ }
59
+
60
+ .zw-link-modal-header__unlink-button:disabled {
61
+ opacity: 0.35;
62
+ }
63
+
64
+ .zw-link-modal-header__unlink-button:hover {
65
+ color: rgb(var(--zw-color-white));
66
+ }
67
+ </style>
@@ -0,0 +1 @@
1
+ export { useLink } from './useLink';
@@ -0,0 +1,61 @@
1
+ import { ref, inject } from 'vue';
2
+ import { LinkTargets, LinkDestinations } from '../../../../../enums';
3
+ import { InjectionTokens } from '../../../../../injectionTokens';
4
+
5
+ export function useLink() {
6
+ const editor = inject(InjectionTokens.EDITOR);
7
+ const pageBlocks = inject(InjectionTokens.PAGE_BLOCKS);
8
+
9
+ const linkData = ref({ text: '', target: LinkTargets.SELF, destination: LinkDestinations.URL });
10
+ const destinationHrefs = ref({ block: pageBlocks.value[0].id, url: '' });
11
+ const currentDestination = ref({ id: LinkDestinations.URL });
12
+
13
+ function updateTarget(isChecked) {
14
+ linkData.value.target = isChecked ? LinkTargets.BLANK : LinkTargets.SELF;
15
+ }
16
+
17
+ function prepareInitialFields() {
18
+ linkData.value.text = editor.commands.getSelectedText();
19
+ currentDestination.value.id = editor.getAttributes('link').destination || LinkDestinations.URL;
20
+ destinationHrefs.value[currentDestination.value.id] = editor.getAttributes('link').href || '';
21
+ linkData.value.target = editor.getAttributes('link').target || LinkTargets.SELF;
22
+ }
23
+
24
+ function apply() {
25
+ editor
26
+ .chain()
27
+ .focus()
28
+ .applyLink({
29
+ href: destinationHrefs.value[currentDestination.value.id],
30
+ text: linkData.value.text,
31
+ target: linkData.value.target,
32
+ destination: currentDestination.value.id
33
+ })
34
+ .run();
35
+ }
36
+
37
+ function removeLink() {
38
+ editor.chain().focus().unsetLink().run();
39
+ }
40
+
41
+ function updateLink(value) {
42
+ destinationHrefs.value[currentDestination.value.id] = value;
43
+ }
44
+
45
+ function updateText(text) {
46
+ linkData.value.text = text;
47
+ }
48
+
49
+ return {
50
+ editor,
51
+ linkData,
52
+ destinationHrefs,
53
+ currentDestination,
54
+ prepareInitialFields,
55
+ updateTarget,
56
+ updateLink,
57
+ apply,
58
+ removeLink,
59
+ updateText
60
+ };
61
+ }
@@ -0,0 +1,103 @@
1
+ <template>
2
+ <div>
3
+ <FieldLabel class="zw-margin-bottom--xxs">
4
+ Destination
5
+ </FieldLabel>
6
+
7
+ <Dropdown
8
+ class="zw-margin-bottom--sm"
9
+ color="gray"
10
+ :max-width="266"
11
+ :value="link.currentDestination.value.id"
12
+ :options="$options.destinationTypes"
13
+ @change="changeDestination"
14
+ >
15
+ <template #option="{ option }">
16
+ <DropdownOption
17
+ class="zw-link-modal-dropdown__option"
18
+ :option="option"
19
+ />
20
+ </template>
21
+ </Dropdown>
22
+
23
+ <LinkControlUrl
24
+ class="zw-margin-bottom--md"
25
+ v-if="isURLDestination"
26
+ :href="link.destinationHrefs.value.url"
27
+ :isTargetBlank="isTargetBlank"
28
+ :validator="validator"
29
+ @updateLink="updateLink"
30
+ @updateTarget="link.updateTarget"
31
+ />
32
+
33
+ <LinkControlPageBlock
34
+ v-else
35
+ :value="link.destinationHrefs.value.block"
36
+ @update="updateLink"
37
+ />
38
+ </div>
39
+ </template>
40
+
41
+ <script>
42
+ import { computed, toRef } from 'vue';
43
+ import { LinkDestinations, LinkTargets } from '../../../../../enums';
44
+ import { Dropdown, DropdownOption, FieldLabel } from '../../../../base';
45
+ import LinkControlPageBlock from './LinkControlPageBlock';
46
+ import LinkControlUrl from './LinkControlUrl';
47
+
48
+ export default {
49
+ name: 'LinkControlDestination',
50
+
51
+ destinationTypes: [
52
+ { id: LinkDestinations.URL, title: 'URL' },
53
+ { id: LinkDestinations.BLOCK, title: 'Page Block' }
54
+ ],
55
+
56
+ components: {
57
+ LinkControlPageBlock,
58
+ LinkControlUrl,
59
+ FieldLabel,
60
+ DropdownOption,
61
+ Dropdown
62
+ },
63
+
64
+ props: {
65
+ link: {
66
+ type: Object,
67
+ required: true
68
+ },
69
+
70
+ validator: {
71
+ type: Object,
72
+ required: true
73
+ }
74
+ },
75
+
76
+ setup(props, { emit }) {
77
+ const link = toRef(props, 'link');
78
+ const isURLDestination = computed(() => link.value.currentDestination.value.id === 'url');
79
+ const isTargetBlank = computed(() => link.value.linkData.value.target === LinkTargets.BLANK);
80
+
81
+ const changeDestination = (value) => {
82
+ emit('reset-errors');
83
+ link.value.currentDestination.value.id = value;
84
+ if (!isURLDestination.value) link.value.target = LinkTargets.SELF;
85
+
86
+ link.value.destinationHrefs.value.url = '';
87
+ };
88
+
89
+ const updateLink = (value) => {
90
+ emit('reset-errors');
91
+
92
+ link.value.updateLink(value);
93
+ };
94
+
95
+ return {
96
+ isTargetBlank,
97
+ isURLDestination,
98
+ changeDestination,
99
+ updateLink
100
+ };
101
+ }
102
+ };
103
+ </script>
@@ -0,0 +1,54 @@
1
+ <template>
2
+ <div>
3
+ <FieldLabel class="zw-margin-bottom--xxs" field-id="link-destination">
4
+ Select block
5
+ </FieldLabel>
6
+
7
+ <Dropdown
8
+ color="gray"
9
+ :max-width="266"
10
+ :value="value"
11
+ :options="pageBlocks"
12
+ @change="applyBlock"
13
+ >
14
+ <template #option="{ option }">
15
+ <DropdownOption
16
+ class="zw-link-modal-dropdown__option"
17
+ :option="option"
18
+ />
19
+ </template>
20
+ </Dropdown>
21
+ </div>
22
+ </template>
23
+
24
+ <script>
25
+ import { inject } from 'vue';
26
+ import { FieldLabel, DropdownOption, Dropdown } from '../../../../base';
27
+ import { InjectionTokens } from '../../../../../injectionTokens';
28
+
29
+ export default {
30
+ name: 'LinkControlPageBlock',
31
+
32
+ components: { DropdownOption, Dropdown, FieldLabel },
33
+
34
+ props: {
35
+ value: {
36
+ type: Number,
37
+ required: true
38
+ }
39
+ },
40
+
41
+ setup(_, { emit }) {
42
+ const pageBlocks = inject(InjectionTokens.PAGE_BLOCKS);
43
+
44
+ const applyBlock = (id) => {
45
+ const block = pageBlocks.value.find((block) => block.id === id);
46
+
47
+ emit('update', block.id);
48
+ };
49
+
50
+ return { pageBlocks, applyBlock };
51
+ }
52
+ };
53
+ </script>
54
+
@@ -0,0 +1,52 @@
1
+ <template>
2
+ <div>
3
+ <TextField
4
+ class="zw-margin-bottom--xs"
5
+ label="To what URL should this link go?"
6
+ placeholder="https://"
7
+ :value="href"
8
+ :error="validator.error.value"
9
+ @input="updateLink"
10
+ />
11
+
12
+ <Checkbox
13
+ label="Open in new tab"
14
+ :value="isTargetBlank"
15
+ @input="updateTarget"
16
+ />
17
+ </div>
18
+ </template>
19
+
20
+ <script>
21
+ import { TextField, Checkbox } from '../../../../base';
22
+
23
+ export default {
24
+ name: 'LinkControlUrl',
25
+
26
+ components: { TextField, Checkbox },
27
+
28
+ props: {
29
+ href: {
30
+ type: String,
31
+ required: true
32
+ },
33
+
34
+ isTargetBlank: {
35
+ type: Boolean,
36
+ required: true
37
+ },
38
+
39
+ validator: {
40
+ type: Object,
41
+ required: true
42
+ }
43
+ },
44
+
45
+ setup(props, { emit }) {
46
+ const updateLink = (value) => emit('updateLink', value);
47
+ const updateTarget = (value) => emit('updateTarget', value);
48
+
49
+ return { updateLink, updateTarget };
50
+ }
51
+ };
52
+ </script>
@@ -0,0 +1 @@
1
+ export { default as LinkControlDestination } from './LinkControlDestination';
@@ -0,0 +1 @@
1
+ export { default as LinkControl } from './LinkControl';
@@ -1,26 +1,27 @@
1
- import { h, toRef } from '@vue/composition-api';
1
+ import { h, toRef } from 'vue';
2
2
  import { EditorContent } from '@tiptap/vue-2';
3
3
  import { shallowMount } from '@vue/test-utils';
4
- import { CORE_EXTENSIONS } from '../../extensions';
5
4
  import { useEditor } from '../useEditor';
6
5
  import { NodeFactory } from '../../__tests__/utils';
6
+ import { buildCoreExtensions } from '../../extensions/core';
7
7
 
8
8
  const TestComponent = {
9
9
  name: 'Test',
10
+
10
11
  render() {
11
12
  return h(EditorContent, {
12
13
  props: { editor: this.editor }
13
14
  });
14
15
  },
16
+
15
17
  props: ['value'],
16
18
 
17
19
  setup(props, { emit }) {
18
20
  const editor = useEditor({
19
21
  content: toRef(props, 'value'),
20
- extensions: CORE_EXTENSIONS,
21
- onChange: (content) => {
22
- emit('input', content);
23
- }
22
+ extensions: buildCoreExtensions(),
23
+ onChange: (content) => emit('input', content),
24
+ onFocus: () => emit('focus')
24
25
  });
25
26
 
26
27
  return { editor };
@@ -64,4 +65,12 @@ describe('life cycle', () => {
64
65
 
65
66
  expect(editor.isDestroyed).toBe(true);
66
67
  });
68
+
69
+ test('should update content on value change', async () => {
70
+ const { editor, wrapper } = createComponent({ content: '<p>old</p>' });
71
+
72
+ await wrapper.setProps({ value: '<p>new</p>' });
73
+
74
+ expect(editor.getHTML()).toBe('<p class="zw-style">new</p>');
75
+ });
67
76
  });
@@ -1,20 +1,25 @@
1
1
  import { Editor } from '@tiptap/vue-2';
2
- import { onUnmounted, watch } from '@vue/composition-api';
2
+ import { onUnmounted, watch, reactive } from 'vue';
3
+ import { ContentNormalizer } from '../services';
3
4
 
4
- export function useEditor({ content, onChange, onFocus, extensions }) {
5
- const editor = new Editor({
6
- content: content.value,
5
+ export function useEditor({ content, onChange, extensions }) {
6
+ const editor = reactive(new Editor({
7
+ content: ContentNormalizer.normalize(content.value),
7
8
  onUpdate: () => onChange(editor.getJSON()),
8
- onFocus: () => onFocus(),
9
- extensions
10
- });
9
+ extensions,
10
+ injectCSS: false
11
+ }));
11
12
 
12
13
  onUnmounted(() => editor.destroy());
13
14
 
14
15
  watch(content, (value) => {
15
16
  const isChanged = JSON.stringify(editor.getJSON()) !== JSON.stringify(value);
16
17
 
17
- if (isChanged) editor.commands.setContent(value, false);
18
+ if (isChanged) {
19
+ const content = ContentNormalizer.normalize(value);
20
+
21
+ editor.commands.setContent(content, false);
22
+ }
18
23
  });
19
24
 
20
25
  return editor;