@zipify/wysiwyg 1.0.0-dev.9 → 1.0.0-dev.92

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 (232) 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 +30 -0
  11. package/config/{webpack → vite}/settings.js +0 -0
  12. package/dist/wysiwyg.css +404 -373
  13. package/dist/wysiwyg.mjs +26015 -0
  14. package/example/ExampleApp.vue +35 -4
  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 +73 -14
  22. package/lib/__tests__/utils/index.js +0 -1
  23. package/lib/__tests__/utils/withComponentContext.js +1 -1
  24. package/lib/assets/icons/background-color.svg +3 -1
  25. package/lib/assets/icons/font-color.svg +1 -3
  26. package/lib/assets/icons/link.svg +3 -0
  27. package/lib/assets/icons/unlink.svg +3 -0
  28. package/lib/components/base/Button.vue +23 -2
  29. package/lib/components/base/Checkbox.vue +89 -0
  30. package/lib/components/base/FieldLabel.vue +2 -1
  31. package/lib/components/base/Icon.vue +3 -3
  32. package/lib/components/base/Modal.vue +1 -2
  33. package/lib/components/base/NumberField.vue +2 -2
  34. package/lib/components/base/Range.vue +1 -1
  35. package/lib/components/base/ScrollView.vue +1 -3
  36. package/lib/components/base/TextField.vue +108 -0
  37. package/lib/components/base/__tests__/Modal.test.js +7 -2
  38. package/lib/components/base/__tests__/TextField.test.js +57 -0
  39. package/lib/components/base/__tests__/__snapshots__/TextField.test.js.snap +9 -0
  40. package/lib/components/base/colorPicker/ColorPicker.vue +14 -12
  41. package/lib/components/base/colorPicker/composables/__tests__/usePickerApi.test.js +6 -6
  42. package/lib/components/base/colorPicker/composables/usePickerApi.js +15 -8
  43. package/lib/components/base/colorPicker/composables/usePickerHotkeys.js +3 -2
  44. package/lib/components/base/composables/__tests__/useActivatedListener.test.js +1 -1
  45. package/lib/components/base/composables/__tests__/useDeselectionLock.test.js +1 -1
  46. package/lib/components/base/composables/__tests__/useElementRef.test.js +1 -1
  47. package/lib/components/base/composables/__tests__/useModalToggler.test.js +1 -1
  48. package/lib/components/base/composables/__tests__/useNumberValue.test.js +1 -1
  49. package/lib/components/base/composables/__tests__/useScrollView.test.js +1 -1
  50. package/lib/components/base/composables/__tests__/useTempValue.test.js +1 -1
  51. package/lib/components/base/composables/__tests__/useValidator.test.js +44 -0
  52. package/lib/components/base/composables/index.js +1 -0
  53. package/lib/components/base/composables/useActivatedListener.js +1 -1
  54. package/lib/components/base/composables/useDeselectionLock.js +1 -1
  55. package/lib/components/base/composables/useElementRef.js +1 -1
  56. package/lib/components/base/composables/useModalToggler.js +6 -2
  57. package/lib/components/base/composables/useScrollView.js +1 -1
  58. package/lib/components/base/composables/useTempValue.js +1 -1
  59. package/lib/components/base/composables/useValidator.js +23 -0
  60. package/lib/components/base/dropdown/Dropdown.vue +16 -4
  61. package/lib/components/base/dropdown/DropdownActivator.vue +19 -3
  62. package/lib/components/base/dropdown/DropdownGroup.vue +1 -1
  63. package/lib/components/base/dropdown/DropdownMenu.vue +1 -1
  64. package/lib/components/base/dropdown/DropdownOption.vue +1 -1
  65. package/lib/components/base/dropdown/__tests__/DropdownActivator.test.js +1 -1
  66. package/lib/components/base/dropdown/__tests__/DropdownMenu.test.js +1 -1
  67. package/lib/components/base/dropdown/__tests__/DropdownOption.test.js +1 -1
  68. package/lib/components/base/dropdown/composables/__tests__/useActiveOptionManager.test.js +1 -1
  69. package/lib/components/base/dropdown/composables/__tests__/useDropdownEntityTitle.test.js +1 -1
  70. package/lib/components/base/dropdown/composables/useActiveOptionManager.js +1 -1
  71. package/lib/components/base/dropdown/composables/useDropdownEntityTitle.js +1 -1
  72. package/lib/components/base/index.js +3 -1
  73. package/lib/components/toolbar/Toolbar.vue +51 -9
  74. package/lib/components/toolbar/ToolbarDivider.vue +1 -1
  75. package/lib/components/toolbar/ToolbarFull.vue +41 -10
  76. package/lib/components/toolbar/ToolbarRow.vue +1 -0
  77. package/lib/components/toolbar/__tests__/Toolbar.test.js +6 -0
  78. package/lib/components/toolbar/controls/AlignmentControl.vue +1 -1
  79. package/lib/components/toolbar/controls/AlignmentDeviceControl.vue +1 -1
  80. package/lib/components/toolbar/controls/BackgroundColorControl.vue +1 -1
  81. package/lib/components/toolbar/controls/CaseStyleControl.vue +1 -1
  82. package/lib/components/toolbar/controls/FontColorControl.vue +1 -1
  83. package/lib/components/toolbar/controls/FontFamilyControl.vue +1 -1
  84. package/lib/components/toolbar/controls/FontSizeControl.vue +8 -1
  85. package/lib/components/toolbar/controls/FontWeightControl.vue +2 -2
  86. package/lib/components/toolbar/controls/ItalicControl.vue +1 -1
  87. package/lib/components/toolbar/controls/LineHeightControl.vue +1 -1
  88. package/lib/components/toolbar/controls/ListControl.vue +70 -36
  89. package/lib/components/toolbar/controls/RemoveFormatControl.vue +1 -1
  90. package/lib/components/toolbar/controls/StrikeThroughControl.vue +1 -1
  91. package/lib/components/toolbar/controls/StylePresetControl.vue +17 -4
  92. package/lib/components/toolbar/controls/SuperscriptControl.vue +1 -1
  93. package/lib/components/toolbar/controls/UnderlineControl.vue +1 -1
  94. package/lib/components/toolbar/controls/__tests__/AlignmentControl.test.js +1 -1
  95. package/lib/components/toolbar/controls/__tests__/AlignmentDeviceControl.test.js +1 -1
  96. package/lib/components/toolbar/controls/__tests__/BackgroundColorControl.test.js +1 -1
  97. package/lib/components/toolbar/controls/__tests__/CaseStyleControl.test.js +1 -1
  98. package/lib/components/toolbar/controls/__tests__/FontColorControl.test.js +1 -1
  99. package/lib/components/toolbar/controls/__tests__/FontFamilyControl.test.js +1 -1
  100. package/lib/components/toolbar/controls/__tests__/FontSizeControl.test.js +1 -1
  101. package/lib/components/toolbar/controls/__tests__/FontWeightControl.test.js +1 -1
  102. package/lib/components/toolbar/controls/__tests__/ItalicControl.test.js +1 -1
  103. package/lib/components/toolbar/controls/__tests__/LineHeightControl.test.js +1 -1
  104. package/lib/components/toolbar/controls/__tests__/ListControl.test.js +18 -3
  105. package/lib/components/toolbar/controls/__tests__/StrikeThroughControl.test.js +1 -1
  106. package/lib/components/toolbar/controls/__tests__/StylePresetControl.test.js +17 -1
  107. package/lib/components/toolbar/controls/__tests__/UnderlineControl.test.js +5 -1
  108. package/lib/components/toolbar/controls/composables/useRecentFonts.js +1 -1
  109. package/lib/components/toolbar/controls/index.js +1 -0
  110. package/lib/components/toolbar/controls/link/LinkControl.vue +160 -0
  111. package/lib/components/toolbar/controls/link/LinkControlApply.vue +35 -0
  112. package/lib/components/toolbar/controls/link/LinkControlHeader.vue +69 -0
  113. package/lib/components/toolbar/controls/link/__tests__/LinkControl.test.js +79 -0
  114. package/lib/components/toolbar/controls/link/__tests__/LinkControlHeader.test.js +42 -0
  115. package/lib/components/toolbar/controls/link/composables/__tests__/__snapshots__/useLink.test.js.snap +15 -0
  116. package/lib/components/toolbar/controls/link/composables/__tests__/useLink.test.js +172 -0
  117. package/lib/components/toolbar/controls/link/composables/index.js +1 -0
  118. package/lib/components/toolbar/controls/link/composables/useLink.js +82 -0
  119. package/lib/components/toolbar/controls/link/destination/LinkControlDestination.vue +103 -0
  120. package/lib/components/toolbar/controls/link/destination/LinkControlPageBlock.vue +54 -0
  121. package/lib/components/toolbar/controls/link/destination/LinkControlUrl.vue +52 -0
  122. package/lib/components/toolbar/controls/link/destination/__tests__/LinkControlPageBlock.test.js +36 -0
  123. package/lib/components/toolbar/controls/link/destination/__tests__/LinkControlUrl.test.js +46 -0
  124. package/lib/components/toolbar/controls/link/destination/__tests__/__snapshots__/LinkControlPageBlock.test.js.snap +9 -0
  125. package/lib/components/toolbar/controls/link/destination/__tests__/__snapshots__/LinkControlUrl.test.js.snap +17 -0
  126. package/lib/components/toolbar/controls/link/destination/index.js +1 -0
  127. package/lib/components/toolbar/controls/link/index.js +1 -0
  128. package/lib/composables/__tests__/__snapshots__/useEditor.test.js.snap +1 -0
  129. package/lib/composables/__tests__/useEditor.test.js +5 -4
  130. package/lib/composables/useEditor.js +12 -9
  131. package/lib/composables/useToolbar.js +26 -19
  132. package/lib/directives/__tests__/outClick.test.js +6 -0
  133. package/lib/directives/outClick.js +19 -6
  134. package/lib/enums/Alignments.js +10 -1
  135. package/lib/enums/LinkDestinations.js +4 -0
  136. package/lib/enums/LinkTargets.js +4 -0
  137. package/lib/enums/TextSettings.js +3 -1
  138. package/lib/enums/index.js +2 -0
  139. package/lib/extensions/Alignment.js +25 -11
  140. package/lib/extensions/BackgroundColor.js +15 -7
  141. package/lib/extensions/DeviceManager.js +2 -5
  142. package/lib/extensions/FontColor.js +17 -9
  143. package/lib/extensions/FontFamily.js +30 -13
  144. package/lib/extensions/FontSize.js +38 -18
  145. package/lib/extensions/FontStyle.js +30 -20
  146. package/lib/extensions/FontWeight.js +34 -23
  147. package/lib/extensions/LineHeight.js +36 -32
  148. package/lib/extensions/Link.js +92 -0
  149. package/lib/extensions/StylePreset.js +23 -22
  150. package/lib/extensions/Superscript.js +5 -1
  151. package/lib/extensions/TextDecoration.js +52 -19
  152. package/lib/extensions/__tests__/Alignment.test.js +14 -9
  153. package/lib/extensions/__tests__/BackgroundColor.test.js +13 -8
  154. package/lib/extensions/__tests__/CaseStyle.test.js +4 -7
  155. package/lib/extensions/__tests__/FontColor.test.js +13 -8
  156. package/lib/extensions/__tests__/FontFamily.test.js +34 -10
  157. package/lib/extensions/__tests__/FontSize.test.js +16 -10
  158. package/lib/extensions/__tests__/FontStyle.test.js +13 -8
  159. package/lib/extensions/__tests__/FontWeight.test.js +21 -8
  160. package/lib/extensions/__tests__/LineHeight.test.js +25 -14
  161. package/lib/extensions/__tests__/Link.test.js +101 -0
  162. package/lib/extensions/__tests__/StylePreset.test.js +72 -10
  163. package/lib/extensions/__tests__/TextDecoration.test.js +53 -8
  164. package/lib/extensions/__tests__/__snapshots__/Alignment.test.js.snap +26 -2
  165. package/lib/extensions/__tests__/__snapshots__/BackgroundColor.test.js.snap +30 -1
  166. package/lib/extensions/__tests__/__snapshots__/FontColor.test.js.snap +18 -1
  167. package/lib/extensions/__tests__/__snapshots__/FontFamily.test.js.snap +88 -1
  168. package/lib/extensions/__tests__/__snapshots__/FontSize.test.js.snap +33 -2
  169. package/lib/extensions/__tests__/__snapshots__/FontStyle.test.js.snap +25 -4
  170. package/lib/extensions/__tests__/__snapshots__/FontWeight.test.js.snap +47 -1
  171. package/lib/extensions/__tests__/__snapshots__/LineHeight.test.js.snap +26 -2
  172. package/lib/extensions/__tests__/__snapshots__/Link.test.js.snap +225 -0
  173. package/lib/extensions/__tests__/__snapshots__/StylePreset.test.js.snap +6 -2
  174. package/lib/extensions/__tests__/__snapshots__/TextDecoration.test.js.snap +183 -3
  175. package/lib/extensions/core/CopyPasteProcessor.js +10 -0
  176. package/lib/extensions/core/NodeProcessor.js +2 -2
  177. package/lib/extensions/core/TextProcessor.js +11 -24
  178. package/lib/extensions/core/__tests__/NodeProcessor.test.js +4 -7
  179. package/lib/extensions/core/__tests__/SelectionProcessor.test.js +4 -7
  180. package/lib/extensions/core/__tests__/TextProcessor.test.js +139 -14
  181. package/lib/extensions/core/__tests__/__snapshots__/TextProcessor.test.js.snap +26 -0
  182. package/lib/extensions/core/index.js +11 -2
  183. package/lib/extensions/core/plugins/PastePlugin.js +57 -0
  184. package/lib/extensions/core/plugins/ProseMirrorPlugin.js +20 -0
  185. package/lib/extensions/core/plugins/index.js +1 -0
  186. package/lib/extensions/index.js +46 -34
  187. package/lib/extensions/list/List.js +7 -6
  188. package/lib/extensions/list/__tests__/List.test.js +6 -10
  189. package/lib/extensions/list/__tests__/__snapshots__/List.test.js.snap +60 -20
  190. package/lib/index.js +3 -0
  191. package/lib/injectionTokens.js +3 -1
  192. package/lib/services/ContentNormalizer.js +144 -28
  193. package/lib/services/ContextWidnow.js +23 -0
  194. package/lib/{__tests__/utils → services}/NodeFactory.js +5 -1
  195. package/lib/services/__tests__/ContentNormalizer.test.js +124 -8
  196. package/lib/services/__tests__/FavoriteColors.test.js +1 -1
  197. package/lib/services/index.js +2 -0
  198. package/lib/styles/content.css +108 -13
  199. package/lib/styles/helpers/offsets.css +16 -0
  200. package/lib/styles/variables.css +6 -0
  201. package/lib/utils/__tests__/__snapshots__/renderInlineSetting.test.js.snap +4 -4
  202. package/lib/utils/__tests__/convertAlignment.test.js +16 -0
  203. package/lib/utils/__tests__/convertFontSize.test.js +21 -0
  204. package/lib/utils/__tests__/convertLineHeight.test.js +21 -0
  205. package/lib/utils/convertAlignment.js +12 -0
  206. package/lib/utils/convertColor.js +1 -1
  207. package/lib/utils/convertFontSize.js +8 -0
  208. package/lib/utils/convertLineHeight.js +17 -0
  209. package/lib/utils/importIcon.js +7 -6
  210. package/lib/utils/index.js +4 -0
  211. package/lib/utils/isWysiwygContent.js +12 -0
  212. package/lib/utils/renderInlineSetting.js +1 -1
  213. package/package.json +26 -30
  214. package/config/webpack/example.config.js +0 -88
  215. package/config/webpack/lib.config.js +0 -44
  216. package/config/webpack/loaders/index.js +0 -6
  217. package/config/webpack/loaders/js-loader.js +0 -5
  218. package/config/webpack/loaders/style-loader.js +0 -9
  219. package/config/webpack/loaders/svg-loader.js +0 -4
  220. package/config/webpack/loaders/vue-loader.js +0 -4
  221. package/dist/wysiwyg.js +0 -2
  222. package/dist/wysiwyg.js.LICENSE.txt +0 -1
  223. package/lib/extensions/core/inputRules/closeDoubleQuote.js +0 -6
  224. package/lib/extensions/core/inputRules/closeSingleQuote.js +0 -6
  225. package/lib/extensions/core/inputRules/copyright.js +0 -6
  226. package/lib/extensions/core/inputRules/ellipsis.js +0 -6
  227. package/lib/extensions/core/inputRules/emDash.js +0 -6
  228. package/lib/extensions/core/inputRules/index.js +0 -9
  229. package/lib/extensions/core/inputRules/openDoubleQuote.js +0 -6
  230. package/lib/extensions/core/inputRules/openSingleQuote.js +0 -6
  231. package/lib/extensions/core/inputRules/registeredTrademark.js +0 -6
  232. package/lib/extensions/core/inputRules/trademark.js +0 -6
@@ -0,0 +1,108 @@
1
+ <template>
2
+ <div class="zw-field">
3
+ <label class="zw-field__label" :for="fieldId" data-test-selector="label">
4
+ {{ label }}
5
+ </label>
6
+
7
+ <input
8
+ class="zw-field__input"
9
+ type="text"
10
+ :value="value"
11
+ :id="fieldId"
12
+ :placeholder="placeholder"
13
+ @input="onInput"
14
+ data-test-selector="input"
15
+ >
16
+
17
+ <p class="zw-field__label--error" v-if="error" data-test-selector="error">
18
+ {{ error }}
19
+ </p>
20
+ </div>
21
+ </template>
22
+
23
+ <script>
24
+ import { computed } from 'vue';
25
+
26
+ export default {
27
+ name: 'TextField',
28
+
29
+ props: {
30
+ value: {
31
+ type: [Number, String],
32
+ required: true
33
+ },
34
+
35
+ label: {
36
+ type: String,
37
+ required: true
38
+ },
39
+
40
+ placeholder: {
41
+ type: String,
42
+ required: false,
43
+ default: ''
44
+ },
45
+
46
+ error: {
47
+ type: String,
48
+ required: false,
49
+ default: null
50
+ }
51
+ },
52
+
53
+ setup(props, { emit }) {
54
+ const onInput = (event) => emit('input', event.target.value);
55
+ const fieldId = computed(() => {
56
+ return props.label.toLowerCase().replace(/[^a-zA-Z0-9]+(.)/g, (m, chr) => chr.toUpperCase());
57
+ });
58
+
59
+ return { onInput, fieldId };
60
+ }
61
+ };
62
+ </script>
63
+
64
+ <style scoped>
65
+ .zw-field {
66
+ display: flex;
67
+ flex-direction: column;
68
+ }
69
+
70
+ .zw-field__input {
71
+ --border-color: rgb(var(--zw-color-n60));
72
+ --text-color: rgb(var(--zw-color-n85));
73
+
74
+ border: 1px solid var(--border-color);
75
+ background-color: transparent;
76
+ color: var(--text-color);
77
+ font-size: var(--zw-font-size-xxs);
78
+ outline: none;
79
+ padding: 6px;
80
+ line-height: var(--zw-line-height-xxs);
81
+ transition: 0.1s border ease-out, 0.1s color ease-out;
82
+ will-change: border, color;
83
+ }
84
+
85
+ .zw-field__input:hover {
86
+ --border-color: rgb(var(--zw-color-n80));
87
+ --text-color: rgb(var(--zw-color-n85));
88
+ }
89
+
90
+ .zw-field__input:focus,
91
+ .zw-field__input:focus-within {
92
+ --border-color: rgb(var(--zw-color-white));
93
+ --text-color: rgb(var(--zw-color-white));
94
+ }
95
+
96
+ .zw-field__label {
97
+ display: inline-block;
98
+ font-size: var(--zw-font-size-xxs);
99
+ padding-bottom: var(--zw-offset-xxs);
100
+ line-height: var(--zw-line-height-xxs);
101
+ }
102
+
103
+ .zw-field__label--error {
104
+ font-size: var(--zw-font-size-xxs);
105
+ margin: var(--zw-offset-xxs) 0 0;
106
+ color: rgb(var(--zw-color-red));
107
+ }
108
+ </style>
@@ -1,8 +1,13 @@
1
- import { nextTick, ref } from '@vue/composition-api';
1
+ import { nextTick, ref } from 'vue';
2
2
  import { shallowMount } from '@vue/test-utils';
3
3
  import { InjectionTokens } from '../../../injectionTokens';
4
4
  import Modal from '../Modal';
5
5
 
6
+ jest.mock('../composables', () => ({
7
+ useDeselectionLock: jest.fn(),
8
+ useModalToggler: jest.fn()
9
+ }));
10
+
6
11
  const createToggler = (isOpened) => ({
7
12
  close: jest.fn(),
8
13
  isOpened: ref(isOpened ?? true)
@@ -42,7 +47,7 @@ describe('open/close', () => {
42
47
  });
43
48
 
44
49
  test('should open', async () => {
45
- const toggler = createToggler(false);
50
+ const toggler = createToggler({ value: false });
46
51
  const wrapper = createComponent({ toggler });
47
52
 
48
53
  toggler.isOpened.value = true;
@@ -0,0 +1,57 @@
1
+ import { shallowMount } from '@vue/test-utils';
2
+ import TextField from '../TextField';
3
+
4
+ function createComponent(label, error) {
5
+ return shallowMount(TextField, {
6
+ propsData: {
7
+ value: '',
8
+ label: label ?? '',
9
+ placeholder: '',
10
+ error: error ?? null
11
+ }
12
+ });
13
+ }
14
+
15
+ const SELECTORS = {
16
+ LABEL: '[data-test-selector="label"]',
17
+ INPUT: '[data-test-selector="input"]',
18
+ ERROR: '[data-test-selector="error"]'
19
+ };
20
+
21
+ describe('rendering', () => {
22
+ test('should render label', () => {
23
+ const label = 'Hello world!';
24
+ const wrapper = createComponent(label);
25
+
26
+ expect(wrapper.find(SELECTORS.LABEL).text()).toEqual(label);
27
+ });
28
+
29
+ test('should generate label', () => {
30
+ const wrapper = createComponent('hello world label');
31
+
32
+ expect(wrapper.find(SELECTORS.INPUT).element.id).toBe('helloWorldLabel');
33
+ });
34
+
35
+ test('should render errors', () => {
36
+ const wrapper = createComponent('_', 'some error');
37
+
38
+ expect(wrapper.contains(SELECTORS.ERROR)).toBeTruthy();
39
+ });
40
+
41
+ test('should not render errors', () => {
42
+ const wrapper = createComponent();
43
+
44
+ expect(wrapper.contains(SELECTORS.ERROR)).toBeFalsy();
45
+ });
46
+ });
47
+
48
+ describe('input change handling', () => {
49
+ test('should emit parsed value', () => {
50
+ const wrapper = createComponent();
51
+ const inputComponentWrapper = wrapper.find(SELECTORS.INPUT);
52
+
53
+ inputComponentWrapper.setValue('Hello world!!!');
54
+
55
+ expect(wrapper.emitted('input')).toMatchSnapshot();
56
+ });
57
+ });
@@ -0,0 +1,9 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`input change handling should emit parsed value 1`] = `
4
+ Array [
5
+ Array [
6
+ "Hello world!!!",
7
+ ],
8
+ ]
9
+ `;
@@ -2,7 +2,9 @@
2
2
  <ZipifyColorPicker
3
3
  ref="pickerRef"
4
4
  placement="bottom-end"
5
+ placement-strategy="fixed"
5
6
  :favorite-colors="favoriteColors"
7
+ :window="window"
6
8
  @changeFavoriteColors="updateFavoriteColors"
7
9
  v-model="editingColor"
8
10
  v-out-click="{ onOutClick: close, isDisabled: !isOpened }"
@@ -20,10 +22,11 @@
20
22
  </template>
21
23
 
22
24
  <script>
23
- import { ZipifyColorPicker } from 'zipify-colorpicker';
24
- import { inject, ref, toRef } from '@vue/composition-api';
25
+ import { ZipifyColorPicker } from '@zipify/colorpicker';
26
+ import { inject, ref, toRef } from 'vue';
25
27
  import { outClick } from '../../../directives';
26
28
  import { InjectionTokens } from '../../../injectionTokens';
29
+ import { ContextWindow } from '../../../services';
27
30
  import { useDeselectionLock } from '../composables';
28
31
  import { usePickerApi, usePickerHotkeys } from './composables';
29
32
 
@@ -51,16 +54,14 @@ export default {
51
54
  const pickerRef = ref(null);
52
55
 
53
56
  const api = usePickerApi({
54
- onClosed: (color) => {
55
- editor.commands.restoreSelection();
56
- if (color !== props.value) emit('change', color);
57
+ onChange: (color) => {
58
+ emit('change', color);
59
+ editor.chain().focus().restoreSelection().run();
57
60
  },
58
- onBeforeOpened: () => {
59
- editor.commands.storeSelection();
60
- emit('before-opened');
61
- },
62
- pickerRef,
63
- initialColorRef: toRef(props, 'value')
61
+ onClosed: () => editor.commands.restoreSelection(),
62
+ onBeforeOpened: () => editor.commands.storeSelection(),
63
+ colorRef: toRef(props, 'value'),
64
+ pickerRef
64
65
  });
65
66
 
66
67
  usePickerHotkeys({
@@ -86,7 +87,8 @@ export default {
86
87
  close: api.close,
87
88
  toggle: api.toggle,
88
89
  favoriteColors: favoriteColors.listRef,
89
- updateFavoriteColors
90
+ updateFavoriteColors,
91
+ window: ContextWindow.window
90
92
  };
91
93
  }
92
94
  };
@@ -1,4 +1,4 @@
1
- import { ref } from '@vue/composition-api';
1
+ import { ref } from 'vue';
2
2
  import { usePickerApi } from '../usePickerApi';
3
3
 
4
4
  const createPickerRef = ({ isOpened } = {}) => ref({
@@ -20,7 +20,7 @@ describe('open/close picker', () => {
20
20
  onClosed: jest.fn(),
21
21
  onBeforeOpened: jest.fn(),
22
22
  pickerRef: createPickerRef({ isOpened: true }),
23
- initialColorRef: ref('red')
23
+ colorRef: ref('red')
24
24
  });
25
25
 
26
26
  expect(toggler.isOpened.value).toBe(true);
@@ -31,7 +31,7 @@ describe('open/close picker', () => {
31
31
  onClosed: jest.fn(),
32
32
  onBeforeOpened: jest.fn(),
33
33
  pickerRef: ref(null),
34
- initialColorRef: ref('red')
34
+ colorRef: ref('red')
35
35
  });
36
36
 
37
37
  expect(toggler.isOpened.value).toBe(false);
@@ -43,7 +43,7 @@ describe('open/close picker', () => {
43
43
  onClosed: jest.fn(),
44
44
  onBeforeOpened: jest.fn(),
45
45
  pickerRef,
46
- initialColorRef: ref('red')
46
+ colorRef: ref('red')
47
47
  });
48
48
 
49
49
  toggler.open();
@@ -57,7 +57,7 @@ describe('open/close picker', () => {
57
57
  onClosed: jest.fn(),
58
58
  onBeforeOpened: jest.fn(),
59
59
  pickerRef,
60
- initialColorRef: ref('red')
60
+ colorRef: ref('red')
61
61
  });
62
62
 
63
63
  toggler.toggle();
@@ -71,7 +71,7 @@ describe('open/close picker', () => {
71
71
  onClosed: jest.fn(),
72
72
  onBeforeOpened: jest.fn(),
73
73
  pickerRef,
74
- initialColorRef: ref('red')
74
+ colorRef: ref('red')
75
75
  });
76
76
 
77
77
  toggler.close();
@@ -1,18 +1,18 @@
1
- import { computed, ref } from '@vue/composition-api';
1
+ import { computed } from 'vue';
2
2
 
3
- export function usePickerApi({ pickerRef, initialColorRef, onClosed, onBeforeOpened }) {
4
- const editingColor = ref(initialColorRef.value);
3
+ export function usePickerApi({ pickerRef, colorRef, onChange, onClosed, onBeforeOpened }) {
5
4
  const isOpened = computed(() => pickerRef.value?.isVisible ?? false);
5
+ let initialColor;
6
6
 
7
7
  function open() {
8
8
  onBeforeOpened();
9
- editingColor.value = initialColorRef.value;
9
+ initialColor = colorRef.value;
10
10
  pickerRef.value.open(pickerRef.value.$el);
11
11
  }
12
12
 
13
13
  function close() {
14
- pickerRef.value.close(editingColor.value);
15
- onClosed(editingColor.value);
14
+ pickerRef.value?.close(colorRef.value);
15
+ onClosed();
16
16
  }
17
17
 
18
18
  function toggle() {
@@ -20,10 +20,17 @@ export function usePickerApi({ pickerRef, initialColorRef, onClosed, onBeforeOpe
20
20
  }
21
21
 
22
22
  function cancel() {
23
- editingColor.value = initialColorRef.value;
24
- pickerRef.value.close(editingColor.value);
23
+ const color = initialColor ?? colorRef.value;
24
+
25
+ onChange(color);
26
+ pickerRef.value?.close(color);
25
27
  }
26
28
 
29
+ const editingColor = computed({
30
+ get: () => colorRef.value,
31
+ set: (color) => colorRef.value !== color && onChange(color)
32
+ });
33
+
27
34
  return {
28
35
  isOpened,
29
36
  editingColor,
@@ -1,4 +1,5 @@
1
- import { ref } from '@vue/composition-api';
1
+ import { ref } from 'vue';
2
+ import { ContextWindow } from '../../../../services';
2
3
  import { useActivatedListener } from '../../composables';
3
4
 
4
5
  export function usePickerHotkeys({ isOpenedRef, onCancel, onApply }) {
@@ -16,7 +17,7 @@ export function usePickerHotkeys({ isOpenedRef, onCancel, onApply }) {
16
17
  }
17
18
 
18
19
  useActivatedListener({
19
- targetRef: ref(document),
20
+ targetRef: ref(ContextWindow.document),
20
21
  isActiveRef: isOpenedRef,
21
22
  event: 'keydown',
22
23
  onEvent: handle,
@@ -1,4 +1,4 @@
1
- import { nextTick, ref } from '@vue/composition-api';
1
+ import { nextTick, ref } from 'vue';
2
2
  import { useActivatedListener } from '../useActivatedListener';
3
3
  import { withComponentContext } from '../../../../__tests__/utils';
4
4
 
@@ -1,4 +1,4 @@
1
- import { ref } from '@vue/composition-api';
1
+ import { ref } from 'vue';
2
2
  import { setReadonlyProperty, withComponentContext } from '../../../../__tests__/utils';
3
3
  import { InjectionTokens } from '../../../../injectionTokens';
4
4
  import { useDeselectionLock } from '../useDeselectionLock';
@@ -1,4 +1,4 @@
1
- import { h, ref } from '@vue/composition-api';
1
+ import { h, ref } from 'vue';
2
2
  import { shallowMount } from '@vue/test-utils';
3
3
  import { useElementRef } from '../useElementRef';
4
4
 
@@ -1,4 +1,4 @@
1
- import { ref } from '@vue/composition-api';
1
+ import { ref } from 'vue';
2
2
  import { withComponentContext } from '../../../../__tests__/utils';
3
3
  import { InjectionTokens } from '../../../../injectionTokens';
4
4
  import { useModalToggler } from '../useModalToggler';
@@ -1,4 +1,4 @@
1
- import { ref } from '@vue/composition-api';
1
+ import { ref } from 'vue';
2
2
  import { useNumberValue } from '../useNumberValue';
3
3
 
4
4
  describe('change', () => {
@@ -1,4 +1,4 @@
1
- import { ref } from '@vue/composition-api';
1
+ import { ref } from 'vue';
2
2
  import { SCROLL_VIEW, useScrollView } from '../useScrollView';
3
3
  import { withComponentContext } from '../../../../__tests__/utils';
4
4
 
@@ -1,4 +1,4 @@
1
- import { nextTick, ref } from '@vue/composition-api';
1
+ import { nextTick, ref } from 'vue';
2
2
  import { useTempValue } from '../useTempValue';
3
3
 
4
4
  describe('sync with original', () => {
@@ -0,0 +1,44 @@
1
+ import { useValidator } from '../useValidator';
2
+
3
+ describe('validation', () => {
4
+ test('should show error', () => {
5
+ const value = '';
6
+ const isEmpty = () => value ? false : 'Can\'t be empty';
7
+
8
+ const validator = useValidator({
9
+ validations: [isEmpty]
10
+ });
11
+
12
+ validator.validate();
13
+
14
+ expect(validator.error.value).toBe('Can\'t be empty');
15
+ });
16
+
17
+ test('should pass validation', () => {
18
+ const value = 'hello';
19
+ const isEmpty = () => value ? false : 'Can\'t be empty';
20
+
21
+ const validator = useValidator({
22
+ validations: [isEmpty]
23
+ });
24
+
25
+ validator.validate();
26
+
27
+ expect(validator.error.value).toBe(null);
28
+ });
29
+
30
+ test('should reset error', () => {
31
+ const value = '';
32
+ const isEmpty = () => value ? false : 'Can\'t be empty';
33
+
34
+ const validator = useValidator({
35
+ validations: [isEmpty]
36
+ });
37
+
38
+ validator.validate();
39
+ expect(validator.error.value).toBe('Can\'t be empty');
40
+
41
+ validator.reset();
42
+ expect(validator.error.value).toBe(null);
43
+ });
44
+ });
@@ -1,3 +1,4 @@
1
+ export { useValidator } from './useValidator';
1
2
  export { useTempValue } from './useTempValue';
2
3
  export { useElementRef } from './useElementRef';
3
4
  export { useNumberValue } from './useNumberValue';
@@ -1,4 +1,4 @@
1
- import { onUnmounted, watch } from '@vue/composition-api';
1
+ import { onUnmounted, watch } from 'vue';
2
2
 
3
3
  export function useActivatedListener({ targetRef, isActiveRef, event, onEvent, options }) {
4
4
  function addListener() {
@@ -1,4 +1,4 @@
1
- import { inject } from '@vue/composition-api';
1
+ import { inject } from 'vue';
2
2
  import { InjectionTokens } from '../../../injectionTokens';
3
3
  import { useActivatedListener } from './useActivatedListener';
4
4
  import { useElementRef } from './useElementRef';
@@ -1,4 +1,4 @@
1
- import { computed } from '@vue/composition-api';
1
+ import { computed } from 'vue';
2
2
 
3
3
  export function useElementRef(ref) {
4
4
  return computed(() => ref.value?.$el || ref.value);
@@ -1,5 +1,5 @@
1
1
  import { createPopper } from '@popperjs/core';
2
- import { inject, nextTick, ref, onUnmounted } from '@vue/composition-api';
2
+ import { inject, nextTick, ref, onUnmounted } from 'vue';
3
3
  import { InjectionTokens } from '../../../injectionTokens';
4
4
  import { useElementRef } from './useElementRef';
5
5
 
@@ -14,6 +14,7 @@ export function useModalToggler({ onBeforeOpened, onClosed, wrapperRef, modalRef
14
14
 
15
15
  popper = createPopper(wrapperEl.value, modalEl.value, {
16
16
  placement: 'bottom',
17
+ strategy: 'fixed',
17
18
  modifiers: [
18
19
  {
19
20
  name: 'offset',
@@ -21,12 +22,15 @@ export function useModalToggler({ onBeforeOpened, onClosed, wrapperRef, modalRef
21
22
  offset: [0, 4]
22
23
  }
23
24
  },
24
-
25
25
  {
26
26
  name: 'preventOverflow',
27
27
  options: {
28
28
  padding: 16
29
29
  }
30
+ },
31
+ {
32
+ name: 'flip',
33
+ enabled: false
30
34
  }
31
35
  ]
32
36
  });
@@ -1,4 +1,4 @@
1
- import { inject } from '@vue/composition-api';
1
+ import { inject } from 'vue';
2
2
 
3
3
  export const SCROLL_VIEW = Symbol('scrollView');
4
4
 
@@ -1,4 +1,4 @@
1
- import { ref, watch } from '@vue/composition-api';
1
+ import { ref, watch } from 'vue';
2
2
 
3
3
  const noFormatter = (value) => value;
4
4
 
@@ -0,0 +1,23 @@
1
+ import { ref } from 'vue';
2
+
3
+ export function useValidator({ validations }) {
4
+ const error = ref(null);
5
+
6
+ function validate() {
7
+ for (const validate of validations) {
8
+ const validationError = validate();
9
+
10
+ if (validationError) {
11
+ return error.value = validationError;
12
+ }
13
+
14
+ error.value = null;
15
+ }
16
+ }
17
+
18
+ function reset() {
19
+ error.value = null;
20
+ }
21
+
22
+ return { error, validate, reset };
23
+ }
@@ -1,12 +1,12 @@
1
1
  <template>
2
2
  <div class="zw-dropdown" ref="dropdownRef">
3
- <DropdownActivator>
3
+ <DropdownActivator :color="color">
4
4
  <template #default="attrs">
5
5
  <slot name="activator" v-bind="attrs" />
6
6
  </template>
7
7
  </DropdownActivator>
8
8
 
9
- <Modal max-height="300" max-width="156" :toggler="toggler" ref="modalRef">
9
+ <Modal max-height="300" :max-width="maxWidth" :toggler="toggler" ref="modalRef">
10
10
  <DropdownMenu :options="options">
11
11
  <template #option="attrs">
12
12
  <slot name="option" v-bind="attrs" />
@@ -17,7 +17,7 @@
17
17
  </template>
18
18
 
19
19
  <script>
20
- import { provide, toRef, ref } from '@vue/composition-api';
20
+ import { provide, toRef, ref } from 'vue';
21
21
  import Modal from '../Modal';
22
22
  import { useModalToggler } from '../composables';
23
23
  import { InjectionTokens } from './injectionTokens';
@@ -40,7 +40,7 @@ export default {
40
40
 
41
41
  props: {
42
42
  value: {
43
- type: String,
43
+ type: [String, Number],
44
44
  required: false,
45
45
  default: null
46
46
  },
@@ -48,6 +48,18 @@ export default {
48
48
  options: {
49
49
  type: Array,
50
50
  required: true
51
+ },
52
+
53
+ maxWidth: {
54
+ type: Number,
55
+ required: false,
56
+ default: 156
57
+ },
58
+
59
+ color: {
60
+ type: String,
61
+ required: false,
62
+ default: 'none'
51
63
  }
52
64
  },
53
65
 
@@ -24,7 +24,7 @@
24
24
  </template>
25
25
 
26
26
  <script>
27
- import { computed, inject } from '@vue/composition-api';
27
+ import { computed, inject, toRef } from 'vue';
28
28
  import Button from '../Button';
29
29
  import Icon from '../Icon';
30
30
  import { InjectionTokens } from './injectionTokens';
@@ -42,14 +42,24 @@ export default {
42
42
  event: 'change'
43
43
  },
44
44
 
45
- setup() {
45
+ props: {
46
+ color: {
47
+ type: String,
48
+ required: false,
49
+ default: 'none'
50
+ }
51
+ },
52
+
53
+ setup(props) {
46
54
  const activeOptionManager = inject(InjectionTokens.ACTIVE_MANAGER);
47
55
  const dropdownToggler = inject(InjectionTokens.TOGGLER);
56
+ const color = toRef(props, 'color');
48
57
 
49
58
  const activeOptionTitle = useDropdownEntityTitle(activeOptionManager.activeOption);
50
59
 
51
60
  const dropdownClasses = computed(() => ({
52
- 'zw-dropdown__activator--active': dropdownToggler.isOpened.value
61
+ 'zw-dropdown__activator--active': dropdownToggler.isOpened.value,
62
+ 'zw-dropdown__activator--gray': color.value === 'gray'
53
63
  }));
54
64
 
55
65
  return {
@@ -78,4 +88,10 @@ export default {
78
88
  .zw-dropdown__activator--active .zw-dropdown__activator-arrow {
79
89
  transform: rotateX(180deg);
80
90
  }
91
+
92
+ .zw-dropdown__activator--gray {
93
+ background-color: rgb(var(--zw-color-n20));
94
+ font-size: var(--zw-font-size-xxs);
95
+ color: rgb(var(--zw-color-white));
96
+ }
81
97
  </style>
@@ -11,7 +11,7 @@
11
11
  </template>
12
12
 
13
13
  <script>
14
- import { toRef } from '@vue/composition-api';
14
+ import { toRef } from 'vue';
15
15
  import DropdownOption from './DropdownOption';
16
16
  import { useDropdownEntityTitle } from './composables';
17
17