@zipify/wysiwyg 1.0.0-dev.1

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 (255) hide show
  1. package/.editorconfig +18 -0
  2. package/.eslintrc.js +253 -0
  3. package/.github/actions/deploy-example/action.yaml +61 -0
  4. package/.github/actions/lint-css/action.yaml +15 -0
  5. package/.github/actions/lint-js/action.yaml +22 -0
  6. package/.github/actions/setup/action.yaml +19 -0
  7. package/.github/actions/unit-tests/action.yaml +13 -0
  8. package/.github/actions/unit-tests/jest.config.js +8 -0
  9. package/.github/dependabot.yaml +17 -0
  10. package/.github/pull_request_template.md +17 -0
  11. package/.github/workflows/frontend-ci.yaml +120 -0
  12. package/.husky/pre-commit +4 -0
  13. package/.lintstagedrc +12 -0
  14. package/.release-it.json +6 -0
  15. package/.stylelintrc +110 -0
  16. package/README.md +61 -0
  17. package/babel.config.js +15 -0
  18. package/ci/example/deploy.sh +25 -0
  19. package/config/jest/TestEnvironment.js +27 -0
  20. package/config/jest/matchers/index.js +6 -0
  21. package/config/jest/matchers/toElementHasStyle.js +27 -0
  22. package/config/jest/matchers/toVueContainComponent.js +20 -0
  23. package/config/jest/matchers/toVueContainElement.js +34 -0
  24. package/config/jest/matchers/toVueContainLazyComponent.js +19 -0
  25. package/config/jest/matchers/toVueEmpty.js +16 -0
  26. package/config/jest/matchers/toVuexActionHasBeenDispatched.js +19 -0
  27. package/config/jest/setupMatchers.js +4 -0
  28. package/config/jest/setupTests.js +32 -0
  29. package/config/jest/typing.d.ts +14 -0
  30. package/config/svgo.js +22 -0
  31. package/config/webpack/example.config.js +86 -0
  32. package/config/webpack/loaders/index.js +6 -0
  33. package/config/webpack/loaders/js-loader.js +5 -0
  34. package/config/webpack/loaders/style-loader.js +7 -0
  35. package/config/webpack/loaders/svg-loader.js +4 -0
  36. package/config/webpack/loaders/vue-loader.js +4 -0
  37. package/config/webpack/settings.js +9 -0
  38. package/example/ExampleApp.vue +136 -0
  39. package/example/example.html +17 -0
  40. package/example/example.js +19 -0
  41. package/example/fonts.js +474 -0
  42. package/example/presets.js +245 -0
  43. package/example/tooltip/Tooltip.js +241 -0
  44. package/example/tooltip/TooltipManager.js +132 -0
  45. package/example/tooltip/index.js +3 -0
  46. package/example/tooltip/modifiers/TooltipCloseOnScrollModifier.js +73 -0
  47. package/example/tooltip/modifiers/index.js +1 -0
  48. package/example/tooltip/tooltip.css +95 -0
  49. package/jest.config.js +17 -0
  50. package/lib/Wysiwyg.vue +156 -0
  51. package/lib/__mocks__/svgMock.js +1 -0
  52. package/lib/__tests__/utils/NodeFactory.js +67 -0
  53. package/lib/__tests__/utils/index.js +4 -0
  54. package/lib/__tests__/utils/setReadonlyProperty.js +9 -0
  55. package/lib/__tests__/utils/waitAsyncOperation.js +6 -0
  56. package/lib/__tests__/utils/withComponentContext.js +14 -0
  57. package/lib/assets/icons.svg +69 -0
  58. package/lib/components/base/Button.vue +117 -0
  59. package/lib/components/base/ButtonToggle.vue +40 -0
  60. package/lib/components/base/FieldLabel.vue +28 -0
  61. package/lib/components/base/Icon.vue +67 -0
  62. package/lib/components/base/Modal.vue +116 -0
  63. package/lib/components/base/NumberField.vue +242 -0
  64. package/lib/components/base/Range.vue +196 -0
  65. package/lib/components/base/ScrollView.vue +60 -0
  66. package/lib/components/base/__tests__/Button.test.js +50 -0
  67. package/lib/components/base/__tests__/Icon.test.js +56 -0
  68. package/lib/components/base/__tests__/Modal.test.js +69 -0
  69. package/lib/components/base/__tests__/Range.test.js +39 -0
  70. package/lib/components/base/colorPicker/ColorPicker.vue +93 -0
  71. package/lib/components/base/colorPicker/composables/__tests__/usePickerApi.test.js +81 -0
  72. package/lib/components/base/colorPicker/composables/index.js +2 -0
  73. package/lib/components/base/colorPicker/composables/usePickerApi.js +35 -0
  74. package/lib/components/base/colorPicker/composables/usePickerHotkeys.js +25 -0
  75. package/lib/components/base/colorPicker/index.js +1 -0
  76. package/lib/components/base/composables/__tests__/useActivatedListener.test.js +89 -0
  77. package/lib/components/base/composables/__tests__/useDeselectionLock.test.js +80 -0
  78. package/lib/components/base/composables/__tests__/useElementRef.test.js +29 -0
  79. package/lib/components/base/composables/__tests__/useModalToggler.test.js +55 -0
  80. package/lib/components/base/composables/__tests__/useNumberValue.test.js +153 -0
  81. package/lib/components/base/composables/__tests__/useScrollView.test.js +43 -0
  82. package/lib/components/base/composables/__tests__/useTempValue.test.js +38 -0
  83. package/lib/components/base/composables/index.js +7 -0
  84. package/lib/components/base/composables/useActivatedListener.js +23 -0
  85. package/lib/components/base/composables/useDeselectionLock.js +35 -0
  86. package/lib/components/base/composables/useElementRef.js +5 -0
  87. package/lib/components/base/composables/useModalToggler.js +58 -0
  88. package/lib/components/base/composables/useNumberValue.js +53 -0
  89. package/lib/components/base/composables/useScrollView.js +22 -0
  90. package/lib/components/base/composables/useTempValue.js +11 -0
  91. package/lib/components/base/dropdown/Dropdown.vue +88 -0
  92. package/lib/components/base/dropdown/DropdownActivator.vue +81 -0
  93. package/lib/components/base/dropdown/DropdownDivider.vue +21 -0
  94. package/lib/components/base/dropdown/DropdownGroup.vue +55 -0
  95. package/lib/components/base/dropdown/DropdownMenu.vue +62 -0
  96. package/lib/components/base/dropdown/DropdownOption.vue +91 -0
  97. package/lib/components/base/dropdown/__tests__/DropdownActivator.test.js +54 -0
  98. package/lib/components/base/dropdown/__tests__/DropdownMenu.test.js +67 -0
  99. package/lib/components/base/dropdown/__tests__/DropdownOption.test.js +81 -0
  100. package/lib/components/base/dropdown/composables/__tests__/useActiveOptionManager.test.js +41 -0
  101. package/lib/components/base/dropdown/composables/__tests__/useDropdownEntityTitle.test.js +24 -0
  102. package/lib/components/base/dropdown/composables/index.js +2 -0
  103. package/lib/components/base/dropdown/composables/useActiveOptionManager.js +25 -0
  104. package/lib/components/base/dropdown/composables/useDropdownEntityTitle.js +5 -0
  105. package/lib/components/base/dropdown/index.js +2 -0
  106. package/lib/components/base/dropdown/injectionTokens.js +5 -0
  107. package/lib/components/base/index.js +11 -0
  108. package/lib/components/index.js +1 -0
  109. package/lib/components/toolbar/Toolbar.vue +56 -0
  110. package/lib/components/toolbar/ToolbarDevice.vue +35 -0
  111. package/lib/components/toolbar/ToolbarDivider.vue +50 -0
  112. package/lib/components/toolbar/ToolbarFull.vue +94 -0
  113. package/lib/components/toolbar/ToolbarGroup.vue +18 -0
  114. package/lib/components/toolbar/ToolbarRow.vue +19 -0
  115. package/lib/components/toolbar/__tests__/Toolbar.test.js +33 -0
  116. package/lib/components/toolbar/__tests__/ToolbarDivider.test.js +26 -0
  117. package/lib/components/toolbar/controls/AlignmentControl.vue +72 -0
  118. package/lib/components/toolbar/controls/AlignmentDeviceControl.vue +67 -0
  119. package/lib/components/toolbar/controls/BackgroundColorControl.vue +48 -0
  120. package/lib/components/toolbar/controls/CaseStyleControl.vue +54 -0
  121. package/lib/components/toolbar/controls/FontColorControl.vue +48 -0
  122. package/lib/components/toolbar/controls/FontFamilyControl.vue +96 -0
  123. package/lib/components/toolbar/controls/FontSizeControl.vue +45 -0
  124. package/lib/components/toolbar/controls/FontWeightControl.vue +43 -0
  125. package/lib/components/toolbar/controls/ItalicControl.vue +47 -0
  126. package/lib/components/toolbar/controls/LineHeightControl.vue +102 -0
  127. package/lib/components/toolbar/controls/ListControl.vue +86 -0
  128. package/lib/components/toolbar/controls/RemoveFormatControl.vue +37 -0
  129. package/lib/components/toolbar/controls/StrikeThroughControl.vue +44 -0
  130. package/lib/components/toolbar/controls/StylePresetControl.vue +95 -0
  131. package/lib/components/toolbar/controls/SuperscriptControl.vue +44 -0
  132. package/lib/components/toolbar/controls/UnderlineControl.vue +44 -0
  133. package/lib/components/toolbar/controls/__tests__/AlignmentControl.test.js +51 -0
  134. package/lib/components/toolbar/controls/__tests__/AlignmentDeviceControl.test.js +77 -0
  135. package/lib/components/toolbar/controls/__tests__/BackgroundColorControl.test.js +59 -0
  136. package/lib/components/toolbar/controls/__tests__/CaseStyleControl.test.js +43 -0
  137. package/lib/components/toolbar/controls/__tests__/FontColorControl.test.js +59 -0
  138. package/lib/components/toolbar/controls/__tests__/FontFamilyControl.test.js +57 -0
  139. package/lib/components/toolbar/controls/__tests__/FontSizeControl.test.js +47 -0
  140. package/lib/components/toolbar/controls/__tests__/FontWeightControl.test.js +45 -0
  141. package/lib/components/toolbar/controls/__tests__/ItalicControl.test.js +63 -0
  142. package/lib/components/toolbar/controls/__tests__/LineHeightControl.test.js +120 -0
  143. package/lib/components/toolbar/controls/__tests__/ListControl.test.js +82 -0
  144. package/lib/components/toolbar/controls/__tests__/RemoveFormatControl.test.js +34 -0
  145. package/lib/components/toolbar/controls/__tests__/StrikeThroughControl.test.js +44 -0
  146. package/lib/components/toolbar/controls/__tests__/StylePresetControl.test.js +129 -0
  147. package/lib/components/toolbar/controls/__tests__/SuperscriptControl.test.js +44 -0
  148. package/lib/components/toolbar/controls/__tests__/UnderlineControl.test.js +44 -0
  149. package/lib/components/toolbar/controls/composables/__tests__/useRecentFonts.test.js +69 -0
  150. package/lib/components/toolbar/controls/composables/index.js +1 -0
  151. package/lib/components/toolbar/controls/composables/useRecentFonts.js +18 -0
  152. package/lib/components/toolbar/controls/index.js +16 -0
  153. package/lib/components/toolbar/index.js +1 -0
  154. package/lib/composables/__tests__/__snapshots__/useEditor.test.js.snap +24 -0
  155. package/lib/composables/__tests__/useEditor.test.js +67 -0
  156. package/lib/composables/__tests__/useToolbar.test.js +56 -0
  157. package/lib/composables/index.js +2 -0
  158. package/lib/composables/useEditor.js +21 -0
  159. package/lib/composables/useToolbar.js +44 -0
  160. package/lib/directives/__tests__/outClick.test.js +86 -0
  161. package/lib/directives/__tests__/tooltip.test.js +39 -0
  162. package/lib/directives/index.js +2 -0
  163. package/lib/directives/outClick.js +37 -0
  164. package/lib/directives/tooltip.js +7 -0
  165. package/lib/enums/Alignments.js +6 -0
  166. package/lib/enums/CaseStyles.js +5 -0
  167. package/lib/enums/Devices.js +15 -0
  168. package/lib/enums/ListTypes.js +23 -0
  169. package/lib/enums/NodeTypes.js +12 -0
  170. package/lib/enums/TextSettings.js +30 -0
  171. package/lib/enums/index.js +6 -0
  172. package/lib/extensions/Alignment.js +67 -0
  173. package/lib/extensions/BackgroundColor.js +28 -0
  174. package/lib/extensions/CaseStyle.js +36 -0
  175. package/lib/extensions/DeviceManager.js +16 -0
  176. package/lib/extensions/FontColor.js +36 -0
  177. package/lib/extensions/FontFamily.js +62 -0
  178. package/lib/extensions/FontSize.js +74 -0
  179. package/lib/extensions/FontStyle.js +62 -0
  180. package/lib/extensions/FontWeight.js +56 -0
  181. package/lib/extensions/LineHeight.js +60 -0
  182. package/lib/extensions/StylePreset.js +168 -0
  183. package/lib/extensions/Superscript.js +5 -0
  184. package/lib/extensions/TextDecoration.js +97 -0
  185. package/lib/extensions/__tests__/Alignment.test.js +107 -0
  186. package/lib/extensions/__tests__/BackgroundColor.test.js +75 -0
  187. package/lib/extensions/__tests__/CaseStyle.test.js +58 -0
  188. package/lib/extensions/__tests__/FontColor.test.js +85 -0
  189. package/lib/extensions/__tests__/FontFamily.test.js +171 -0
  190. package/lib/extensions/__tests__/FontSize.test.js +183 -0
  191. package/lib/extensions/__tests__/FontStyle.test.js +136 -0
  192. package/lib/extensions/__tests__/FontWeight.test.js +151 -0
  193. package/lib/extensions/__tests__/LineHeight.test.js +106 -0
  194. package/lib/extensions/__tests__/StylePreset.test.js +400 -0
  195. package/lib/extensions/__tests__/TextDecoration.test.js +258 -0
  196. package/lib/extensions/__tests__/__snapshots__/Alignment.test.js.snap +29 -0
  197. package/lib/extensions/__tests__/__snapshots__/BackgroundColor.test.js.snap +28 -0
  198. package/lib/extensions/__tests__/__snapshots__/CaseStyle.test.js.snap +69 -0
  199. package/lib/extensions/__tests__/__snapshots__/FontColor.test.js.snap +28 -0
  200. package/lib/extensions/__tests__/__snapshots__/FontFamily.test.js.snap +158 -0
  201. package/lib/extensions/__tests__/__snapshots__/FontSize.test.js.snap +140 -0
  202. package/lib/extensions/__tests__/__snapshots__/FontStyle.test.js.snap +87 -0
  203. package/lib/extensions/__tests__/__snapshots__/FontWeight.test.js.snap +140 -0
  204. package/lib/extensions/__tests__/__snapshots__/LineHeight.test.js.snap +29 -0
  205. package/lib/extensions/__tests__/__snapshots__/StylePreset.test.js.snap +310 -0
  206. package/lib/extensions/__tests__/__snapshots__/TextDecoration.test.js.snap +206 -0
  207. package/lib/extensions/core/NodeProcessor.js +32 -0
  208. package/lib/extensions/core/SelectionProcessor.js +37 -0
  209. package/lib/extensions/core/TextProcessor.js +57 -0
  210. package/lib/extensions/core/__tests__/NodeProcessor.test.js +120 -0
  211. package/lib/extensions/core/__tests__/SelectionProcessor.test.js +78 -0
  212. package/lib/extensions/core/__tests__/TextProcessor.test.js +61 -0
  213. package/lib/extensions/core/__tests__/__snapshots__/NodeProcessor.test.js.snap +93 -0
  214. package/lib/extensions/core/__tests__/__snapshots__/TextProcessor.test.js.snap +43 -0
  215. package/lib/extensions/core/index.js +17 -0
  216. package/lib/extensions/core/inputRules/closeDoubleQuote.js +6 -0
  217. package/lib/extensions/core/inputRules/closeSingleQuote.js +6 -0
  218. package/lib/extensions/core/inputRules/copyright.js +6 -0
  219. package/lib/extensions/core/inputRules/ellipsis.js +6 -0
  220. package/lib/extensions/core/inputRules/emDash.js +6 -0
  221. package/lib/extensions/core/inputRules/index.js +9 -0
  222. package/lib/extensions/core/inputRules/openDoubleQuote.js +6 -0
  223. package/lib/extensions/core/inputRules/openSingleQuote.js +6 -0
  224. package/lib/extensions/core/inputRules/registeredTrademark.js +6 -0
  225. package/lib/extensions/core/inputRules/trademark.js +6 -0
  226. package/lib/extensions/index.js +49 -0
  227. package/lib/extensions/list/List.js +81 -0
  228. package/lib/extensions/list/ListItem.js +12 -0
  229. package/lib/extensions/list/__tests__/List.test.js +130 -0
  230. package/lib/extensions/list/__tests__/__snapshots__/List.test.js.snap +212 -0
  231. package/lib/extensions/list/index.js +1 -0
  232. package/lib/index.js +1 -0
  233. package/lib/injectionTokens.js +7 -0
  234. package/lib/models/Font.js +37 -0
  235. package/lib/models/__tests__/Font.test.js +58 -0
  236. package/lib/models/index.js +1 -0
  237. package/lib/services/FavoriteColors.js +6 -0
  238. package/lib/services/JsonSerializer.js +15 -0
  239. package/lib/services/Storage.js +49 -0
  240. package/lib/services/index.js +3 -0
  241. package/lib/styles/content.css +39 -0
  242. package/lib/styles/helpers/common.css +3 -0
  243. package/lib/styles/helpers/offsets.css +3 -0
  244. package/lib/styles/helpers/text.css +6 -0
  245. package/lib/styles/main.css +5 -0
  246. package/lib/styles/variables.css +57 -0
  247. package/lib/utils/__tests__/__snapshots__/renderInlineSetting.test.js.snap +40 -0
  248. package/lib/utils/__tests__/capitalize.test.js +11 -0
  249. package/lib/utils/__tests__/renderInlineSetting.test.js +39 -0
  250. package/lib/utils/capitalize.js +3 -0
  251. package/lib/utils/createCommand.js +3 -0
  252. package/lib/utils/createKeyboardShortcut.js +6 -0
  253. package/lib/utils/index.js +4 -0
  254. package/lib/utils/renderInlineSetting.js +17 -0
  255. package/package.json +75 -0
@@ -0,0 +1,43 @@
1
+ <template>
2
+ <Dropdown
3
+ :options="options"
4
+ :value="currentValue"
5
+ @change="apply"
6
+ v-tooltip="{ text: 'Font Weight', hotkey: 'Mod B' }"
7
+ />
8
+ </template>
9
+
10
+ <script>
11
+ import { computed, inject } from '@vue/composition-api';
12
+ import { InjectionTokens } from '../../../injectionTokens';
13
+ import { Dropdown } from '../../base';
14
+ import { tooltip } from '../../../directives';
15
+
16
+ export default {
17
+ name: 'FontWeightControl',
18
+
19
+ components: {
20
+ Dropdown
21
+ },
22
+
23
+ directives: {
24
+ tooltip
25
+ },
26
+
27
+ setup() {
28
+ const editor = inject(InjectionTokens.EDITOR);
29
+ const font = editor.commands.getFont();
30
+
31
+ const options = computed(() => font.value.weights.map((style) => ({ id: style })));
32
+ const currentValue = editor.commands.getFontWeight();
33
+
34
+ const apply = (value) => editor.chain().focus().applyFontWeight(value).run();
35
+
36
+ return {
37
+ options,
38
+ currentValue,
39
+ apply
40
+ };
41
+ }
42
+ };
43
+ </script>
@@ -0,0 +1,47 @@
1
+ <template>
2
+ <Button
3
+ skin="toolbar"
4
+ icon
5
+ :active="currentValue"
6
+ :disabled="!isAvailable"
7
+ @click="apply"
8
+ v-tooltip="{ text: 'Italic', hotkey: 'Mod I' }"
9
+ >
10
+ <Icon name="italic" size="28px" auto-color />
11
+ </Button>
12
+ </template>
13
+
14
+ <script>
15
+ import { inject } from '@vue/composition-api';
16
+ import { Button, Icon } from '../../base';
17
+ import { InjectionTokens } from '../../../injectionTokens';
18
+ import { tooltip } from '../../../directives';
19
+
20
+ export default {
21
+ name: 'ItalicControl',
22
+
23
+ components: {
24
+ Button,
25
+ Icon
26
+ },
27
+
28
+ directives: {
29
+ tooltip
30
+ },
31
+
32
+ setup() {
33
+ const editor = inject(InjectionTokens.EDITOR);
34
+
35
+ const currentValue = editor.commands.isItalic();
36
+ const isAvailable = editor.commands.isItalicAvailable();
37
+ const apply = () => editor.chain().focus().toggleItalic().run();
38
+
39
+ return {
40
+ isAvailable,
41
+ currentValue,
42
+ apply
43
+ };
44
+ }
45
+ };
46
+ </script>
47
+
@@ -0,0 +1,102 @@
1
+ <template>
2
+ <div class="zw-position--relative" ref="wrapperRef">
3
+ <Button
4
+ icon
5
+ skin="toolbar"
6
+ :active="isOpened"
7
+ @click="toggler.open"
8
+ v-tooltip="'Line Height'"
9
+ >
10
+ <Icon name="line-height" size="28px" auto-color />
11
+ </Button>
12
+
13
+ <Modal class="zw-line-height-control__modal" ref="modalRef" :toggler="toggler">
14
+ <FieldLabel class="zw-margin-bottom--xs" field-id="wswg-line-height">
15
+ Line Height
16
+ </FieldLabel>
17
+
18
+ <div class="zw-line-height-control__row">
19
+ <Range
20
+ class="zw-line-height-control__range"
21
+ step="0.1"
22
+ min="1"
23
+ max="3"
24
+ :value="currentValue"
25
+ @input="apply"
26
+ />
27
+
28
+ <NumberField
29
+ step="0.1"
30
+ min="1"
31
+ max="3"
32
+ class="zw-line-height-control__field"
33
+ field-id="wswg-line-height"
34
+ :value="currentValue"
35
+ @input="apply"
36
+ />
37
+ </div>
38
+ </Modal>
39
+ </div>
40
+ </template>
41
+
42
+ <script>
43
+ import { inject, ref } from '@vue/composition-api';
44
+ import { Button, Icon, Modal, Range, NumberField, FieldLabel, useModalToggler } from '../../base';
45
+ import { InjectionTokens } from '../../../injectionTokens';
46
+ import { tooltip } from '../../../directives';
47
+
48
+ export default {
49
+ name: 'LineHeightControl',
50
+
51
+ components: {
52
+ Range,
53
+ Modal,
54
+ Icon,
55
+ Button,
56
+ NumberField,
57
+ FieldLabel
58
+ },
59
+
60
+ directives: {
61
+ tooltip
62
+ },
63
+
64
+ setup() {
65
+ const wrapperRef = ref(null);
66
+ const modalRef = ref(null);
67
+ const editor = inject(InjectionTokens.EDITOR);
68
+ const toggler = useModalToggler({ wrapperRef, modalRef });
69
+ const currentValue = editor.commands.getLineHeight();
70
+ const apply = (value) => editor.commands.applyLineHeight(String(value));
71
+
72
+ return {
73
+ wrapperRef,
74
+ modalRef,
75
+ isOpened: toggler.isOpened,
76
+ toggler,
77
+ currentValue,
78
+ apply
79
+ };
80
+ }
81
+ };
82
+ </script>
83
+
84
+ <style scoped>
85
+ .zw-line-height-control__modal {
86
+ padding: var(--zw-offset-sm);
87
+ }
88
+
89
+ .zw-line-height-control__row {
90
+ display: flex;
91
+ align-items: center;
92
+ }
93
+
94
+ .zw-line-height-control__range {
95
+ width: 156px;
96
+ }
97
+
98
+ .zw-line-height-control__field {
99
+ width: 52px;
100
+ margin-left: var(--zw-offset-sm);
101
+ }
102
+ </style>
@@ -0,0 +1,86 @@
1
+ <template>
2
+ <Dropdown
3
+ :value="currentValue"
4
+ :options="$options.listTypes"
5
+ @change="apply"
6
+ >
7
+ <template #activator="{ open, isOpened }">
8
+ <Button
9
+ icon
10
+ skin="toolbar"
11
+ :active="isOpened || isList"
12
+ @click="open"
13
+ v-tooltip="'Bullet Styles'"
14
+ >
15
+ <Icon :name="currentIcon" size="28px" auto-color />
16
+ </Button>
17
+ </template>
18
+
19
+ <template #option="{ option }">
20
+ <DropdownOption
21
+ class="zw-list-control__option"
22
+ :option="option"
23
+ v-tooltip="option.tooltip"
24
+ >
25
+ <Icon :name="option.icon" size="28px" auto-color />
26
+ </DropdownOption>
27
+ </template>
28
+ </Dropdown>
29
+ </template>
30
+
31
+ <script>
32
+ import { computed, inject } from '@vue/composition-api';
33
+ import { InjectionTokens } from '../../../injectionTokens';
34
+ import { Dropdown, DropdownOption, Button, Icon } from '../../base';
35
+ import { ListTypes } from '../../../enums';
36
+ import { tooltip } from '../../../directives';
37
+
38
+ export default {
39
+ name: 'ListControl',
40
+
41
+ listTypes: ListTypes.values.map((type) => ({
42
+ id: type,
43
+ icon: `list-${type}`
44
+ })),
45
+
46
+ components: {
47
+ Dropdown,
48
+ DropdownOption,
49
+ Button,
50
+ Icon
51
+ },
52
+
53
+ directives: {
54
+ tooltip
55
+ },
56
+
57
+ setup() {
58
+ const editor = inject(InjectionTokens.EDITOR);
59
+ const selectionValue = editor.commands.getListType();
60
+ const isList = computed(() => !!selectionValue.value);
61
+ const currentValue = computed(() => selectionValue.value || 'none');
62
+
63
+ const currentIcon = computed(() => {
64
+ const type = selectionValue.value || ListTypes.DISC;
65
+
66
+ return `list-${type}`;
67
+ });
68
+
69
+ const apply = (type) => editor.chain().focus().applyList(type).run();
70
+
71
+ return {
72
+ isList,
73
+ currentValue,
74
+ currentIcon,
75
+ apply
76
+ };
77
+ }
78
+ };
79
+ </script>
80
+
81
+ <style scoped>
82
+ .zw-list-control__option {
83
+ padding: 0 var(--zw-offset-xs);
84
+ display: flex;
85
+ }
86
+ </style>
@@ -0,0 +1,37 @@
1
+ <template>
2
+ <Button
3
+ skin="toolbar"
4
+ icon
5
+ @click="apply"
6
+ v-tooltip="'Remove Styles'"
7
+ >
8
+ <Icon name="remove-format" size="28px" auto-color />
9
+ </Button>
10
+ </template>
11
+
12
+ <script>
13
+ import { inject } from '@vue/composition-api';
14
+ import { Button, Icon } from '../../base';
15
+ import { InjectionTokens } from '../../../injectionTokens';
16
+ import { tooltip } from '../../../directives';
17
+
18
+ export default {
19
+ name: 'RemoveFormatControl',
20
+
21
+ components: {
22
+ Icon,
23
+ Button
24
+ },
25
+
26
+ directives: {
27
+ tooltip
28
+ },
29
+
30
+ setup() {
31
+ const editor = inject(InjectionTokens.EDITOR);
32
+ const apply = () => editor.chain().focus().removeFormat().run();
33
+
34
+ return { apply };
35
+ }
36
+ };
37
+ </script>
@@ -0,0 +1,44 @@
1
+ <template>
2
+ <Button
3
+ skin="toolbar"
4
+ icon
5
+ :active="currentValue"
6
+ @click="apply"
7
+ v-tooltip="'Strikethrough'"
8
+ >
9
+ <Icon name="strike-through" size="28px" auto-color />
10
+ </Button>
11
+ </template>
12
+
13
+ <script>
14
+ import { inject } from '@vue/composition-api';
15
+ import { Button, Icon } from '../../base';
16
+ import { InjectionTokens } from '../../../injectionTokens';
17
+ import { tooltip } from '../../../directives';
18
+
19
+ export default {
20
+ name: 'StrikeThroughControl',
21
+
22
+ components: {
23
+ Button,
24
+ Icon
25
+ },
26
+
27
+ directives: {
28
+ tooltip
29
+ },
30
+
31
+ setup() {
32
+ const editor = inject(InjectionTokens.EDITOR);
33
+
34
+ const currentValue = editor.commands.isStrikeThrough();
35
+ const apply = () => editor.chain().focus().toggleStrikeThrough().run();
36
+
37
+ return {
38
+ currentValue,
39
+ apply
40
+ };
41
+ }
42
+ };
43
+ </script>
44
+
@@ -0,0 +1,95 @@
1
+ <template>
2
+ <div class="zw-style-preset-control">
3
+ <Dropdown
4
+ class="zw-style-preset-control__dropdown"
5
+ :value="preset.id"
6
+ :options="options"
7
+ @change="apply"
8
+ v-tooltip="'Text Type'"
9
+ />
10
+
11
+ <Button
12
+ class="zw-style-preset-control__reset"
13
+ :disabled="!isCustomized"
14
+ icon
15
+ @click="removeCustomization"
16
+ v-tooltip="'Reset Styles'"
17
+ >
18
+ <Icon name="reset-styles" size="28px" auto-color />
19
+ </Button>
20
+ </div>
21
+ </template>
22
+
23
+ <script>
24
+ import { computed, inject } from '@vue/composition-api';
25
+ import { InjectionTokens } from '../../../injectionTokens';
26
+ import { Dropdown, Button, Icon } from '../../base';
27
+ import { tooltip } from '../../../directives';
28
+
29
+ export default {
30
+ name: 'StylePresetControl',
31
+
32
+ components: {
33
+ Icon,
34
+ Button,
35
+ Dropdown
36
+ },
37
+
38
+ directives: {
39
+ tooltip
40
+ },
41
+
42
+ setup() {
43
+ const editor = inject(InjectionTokens.EDITOR);
44
+
45
+ const presets = editor.commands.getPresetList();
46
+ const preset = editor.commands.getPreset();
47
+ const customization = editor.commands.getPresetCustomization();
48
+
49
+ const isCustomized = computed(() => {
50
+ const { attributes, marks } = customization.value;
51
+
52
+ return !!attributes.length || !!marks.length;
53
+ });
54
+
55
+ const options = computed(() => {
56
+ return presets.value.map((preset) => ({
57
+ id: preset.id,
58
+ title: preset.name
59
+ }));
60
+ });
61
+
62
+ const apply = (value) => editor.chain().focus().applyPreset(value).run();
63
+ const removeCustomization = () => editor.chain().focus().removePresetCustomization().run();
64
+
65
+ return {
66
+ options,
67
+ preset,
68
+ isCustomized,
69
+ apply,
70
+ removeCustomization
71
+ };
72
+ }
73
+ };
74
+ </script>
75
+
76
+ <style scoped>
77
+ .zw-style-preset-control {
78
+ display: flex;
79
+ align-items: center;
80
+ }
81
+
82
+ .zw-style-preset-control__dropdown {
83
+ width: 96px;
84
+ }
85
+
86
+ .zw-style-preset-control__reset {
87
+ color: rgb(var(--zw-color-n70));
88
+ }
89
+
90
+ .zw-style-preset-control__reset:not(:disabled):hover,
91
+ .zw-style-preset-control__reset:not(:disabled):focus,
92
+ .zw-style-preset-control__reset:not(:disabled):focus-within {
93
+ color: rgb(var(--zw-color-white));
94
+ }
95
+ </style>
@@ -0,0 +1,44 @@
1
+ <template>
2
+ <Button
3
+ skin="toolbar"
4
+ icon
5
+ :active="currentValue"
6
+ @click="apply"
7
+ v-tooltip="'Superscript'"
8
+ >
9
+ <Icon name="superscript" size="28px" auto-color />
10
+ </Button>
11
+ </template>
12
+
13
+ <script>
14
+ import { computed, inject } from '@vue/composition-api';
15
+ import { Button, Icon } from '../../base';
16
+ import { InjectionTokens } from '../../../injectionTokens';
17
+ import { tooltip } from '../../../directives';
18
+
19
+ export default {
20
+ name: 'SuperscriptControl',
21
+
22
+ components: {
23
+ Button,
24
+ Icon
25
+ },
26
+
27
+ directives: {
28
+ tooltip
29
+ },
30
+
31
+ setup() {
32
+ const editor = inject(InjectionTokens.EDITOR);
33
+
34
+ const currentValue = computed(() => editor.isActive('superscript'));
35
+ const apply = () => editor.chain().focus().toggleSuperscript().run();
36
+
37
+ return {
38
+ currentValue,
39
+ apply
40
+ };
41
+ }
42
+ };
43
+ </script>
44
+
@@ -0,0 +1,44 @@
1
+ <template>
2
+ <Button
3
+ skin="toolbar"
4
+ icon
5
+ :active="currentValue"
6
+ @click="apply"
7
+ v-tooltip="{ text: 'Underline', hotkey: 'Mod U' }"
8
+ >
9
+ <Icon name="underline" size="28px" auto-color />
10
+ </Button>
11
+ </template>
12
+
13
+ <script>
14
+ import { inject } from '@vue/composition-api';
15
+ import { Button, Icon } from '../../base';
16
+ import { InjectionTokens } from '../../../injectionTokens';
17
+ import { tooltip } from '../../../directives';
18
+
19
+ export default {
20
+ name: 'UnderlineControl',
21
+
22
+ components: {
23
+ Button,
24
+ Icon
25
+ },
26
+
27
+ directives: {
28
+ tooltip
29
+ },
30
+
31
+ setup() {
32
+ const editor = inject(InjectionTokens.EDITOR);
33
+
34
+ const currentValue = editor.commands.isUnderline();
35
+ const apply = () => editor.chain().focus().toggleUnderline().run();
36
+
37
+ return {
38
+ currentValue,
39
+ apply
40
+ };
41
+ }
42
+ };
43
+ </script>
44
+
@@ -0,0 +1,51 @@
1
+ import { shallowMount } from '@vue/test-utils';
2
+ import { h, ref } from '@vue/composition-api';
3
+ import { InjectionTokens } from '../../../../injectionTokens';
4
+ import { Alignments } from '../../../../enums';
5
+ import { ButtonToggle } from '../../../base';
6
+ import AlignmentControl from '../AlignmentControl';
7
+
8
+ const createEditor = ({ alignment } = {}) => ({
9
+ commands: {
10
+ getAlignment: () => ref(alignment),
11
+ focus: jest.fn().mockReturnThis(),
12
+ applyAlignment: jest.fn().mockReturnThis(),
13
+ run: jest.fn()
14
+ },
15
+
16
+ chain() {
17
+ return this.commands;
18
+ }
19
+ });
20
+
21
+ function createComponent({ editor }) {
22
+ return shallowMount(AlignmentControl, {
23
+ stubs: {
24
+ ButtonToggle: {
25
+ render: () => h('div'),
26
+ props: ['value']
27
+ }
28
+ },
29
+ provide: { [InjectionTokens.EDITOR]: editor }
30
+ });
31
+ }
32
+
33
+ describe('selection value', () => {
34
+ test('should render value from selection', () => {
35
+ const editor = createEditor({ alignment: Alignments.RIGHT });
36
+ const wrapper = createComponent({ editor });
37
+ const buttonWrapper = wrapper.findComponent(ButtonToggle);
38
+
39
+ expect(buttonWrapper.props('value')).toBe(Alignments.RIGHT);
40
+ });
41
+
42
+ test('should apply new value', () => {
43
+ const editor = createEditor({ alignment: Alignments.RIGHT });
44
+ const wrapper = createComponent({ editor });
45
+ const buttonWrapper = wrapper.findComponent(ButtonToggle);
46
+
47
+ buttonWrapper.vm.$emit('change', Alignments.CENTER);
48
+
49
+ expect(editor.commands.applyAlignment).toHaveBeenCalledWith(Alignments.CENTER);
50
+ });
51
+ });
@@ -0,0 +1,77 @@
1
+ import { shallowMount } from '@vue/test-utils';
2
+ import { ref, h, nextTick } from '@vue/composition-api';
3
+ import { InjectionTokens } from '../../../../injectionTokens';
4
+ import { Alignments } from '../../../../enums';
5
+ import { Button, Icon, Modal } from '../../../base';
6
+ import AlignmentDeviceControl from '../AlignmentDeviceControl';
7
+ import AlignmentControl from '../AlignmentControl';
8
+
9
+ const createEditor = ({ alignment } = {}) => ({
10
+ commands: {
11
+ getAlignment: () => ref(alignment),
12
+ storeSelection: jest.fn(),
13
+ restoreSelection: jest.fn()
14
+ }
15
+ });
16
+
17
+ function createComponent({ editor } = {}) {
18
+ return shallowMount(AlignmentDeviceControl, {
19
+ stubs: {
20
+ Modal: {
21
+ render() {
22
+ return h('div', null, this.$slots.default);
23
+ },
24
+ props: ['toggler']
25
+ }
26
+ },
27
+ provide: {
28
+ [InjectionTokens.EDITOR]: editor ?? createEditor()
29
+ }
30
+ });
31
+ }
32
+
33
+ describe('rendering', () => {
34
+ test('should render alignment icon', () => {
35
+ const editor = createEditor({ alignment: Alignments.RIGHT });
36
+ const wrapper = createComponent({ editor });
37
+ const iconWrapper = wrapper.findComponent(Icon);
38
+
39
+ expect(iconWrapper.props('name')).toBe('alignment-right');
40
+ });
41
+
42
+ test('should render closed state', async () => {
43
+ const wrapper = createComponent();
44
+ const buttonWrapper = wrapper.findComponent(Button);
45
+ const modalWrapper = wrapper.findComponent(Modal);
46
+
47
+ expect(buttonWrapper.props('active')).toBe(false);
48
+ expect(modalWrapper.props('toggler').isOpened.value).toBe(false);
49
+ });
50
+
51
+ test('should open modal', async () => {
52
+ const wrapper = createComponent();
53
+ const buttonWrapper = wrapper.findComponent(Button);
54
+ const modalWrapper = wrapper.findComponent(Modal);
55
+
56
+ buttonWrapper.vm.$emit('click');
57
+ await nextTick();
58
+
59
+ expect(buttonWrapper.props('active')).toBe(true);
60
+ expect(modalWrapper.props('toggler').isOpened.value).toBe(true);
61
+ });
62
+
63
+ test('should close on apply value', async () => {
64
+ const wrapper = createComponent();
65
+ const buttonWrapper = wrapper.findComponent(Button);
66
+ const modalWrapper = wrapper.findComponent(Modal);
67
+
68
+ buttonWrapper.vm.$emit('click');
69
+ await nextTick();
70
+
71
+ wrapper.findComponent(AlignmentControl).vm.$emit('applied');
72
+ await nextTick();
73
+
74
+ expect(buttonWrapper.props('active')).toBe(false);
75
+ expect(modalWrapper.props('toggler').isOpened.value).toBe(false);
76
+ });
77
+ });