@zipify/wysiwyg 3.1.2 → 4.0.0-vue3.0

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 (134) hide show
  1. package/.eslintrc.js +1 -1
  2. package/config/build/example.config.js +12 -2
  3. package/config/build/lib.config.js +10 -2
  4. package/config/jest/matchers/index.js +0 -2
  5. package/config/jest/setupTests.js +4 -7
  6. package/config/jest/typing.d.ts +1 -2
  7. package/dist/cli.js +2 -7
  8. package/dist/wysiwyg.css +153 -152
  9. package/dist/wysiwyg.mjs +3594 -3172
  10. package/example/example.js +34 -35
  11. package/jest.config.js +4 -1
  12. package/lib/Wysiwyg.vue +166 -190
  13. package/lib/__tests__/utils/buildTestExtensions.js +1 -1
  14. package/lib/components/base/Button.vue +31 -37
  15. package/lib/components/base/ButtonToggle.vue +11 -17
  16. package/lib/components/base/Checkbox.vue +14 -20
  17. package/lib/components/base/FieldLabel.vue +7 -11
  18. package/lib/components/base/Icon.vue +31 -43
  19. package/lib/components/base/Modal.vue +59 -74
  20. package/lib/components/base/NumberField.vue +65 -80
  21. package/lib/components/base/Range.vue +46 -56
  22. package/lib/components/base/ScrollView.vue +13 -21
  23. package/lib/components/base/TextField.vue +28 -33
  24. package/lib/components/base/__tests__/Button.test.js +1 -1
  25. package/lib/components/base/__tests__/Icon.test.js +1 -1
  26. package/lib/components/base/__tests__/Modal.test.js +21 -13
  27. package/lib/components/base/__tests__/Range.test.js +1 -1
  28. package/lib/components/base/__tests__/TextField.test.js +8 -7
  29. package/lib/components/base/colorPicker/ColorPicker.vue +33 -51
  30. package/lib/components/base/composables/__tests__/useDeselectionLock.test.js +4 -2
  31. package/lib/components/base/composables/__tests__/useModalToggler.test.js +3 -1
  32. package/lib/components/base/composables/__tests__/useScrollView.test.js +3 -1
  33. package/lib/components/base/dropdown/Dropdown.vue +35 -55
  34. package/lib/components/base/dropdown/DropdownActivator.vue +38 -66
  35. package/lib/components/base/dropdown/DropdownDivider.vue +0 -6
  36. package/lib/components/base/dropdown/DropdownGroup.vue +8 -20
  37. package/lib/components/base/dropdown/DropdownMenu.vue +8 -21
  38. package/lib/components/base/dropdown/DropdownOption.vue +27 -45
  39. package/lib/components/base/dropdown/__tests__/DropdownActivator.test.js +5 -3
  40. package/lib/components/base/dropdown/__tests__/DropdownOption.test.js +9 -7
  41. package/lib/components/toolbar/Toolbar.vue +26 -42
  42. package/lib/components/toolbar/__tests__/Toolbar.test.js +1 -1
  43. package/lib/components/toolbar/base/__tests__/ToolbarDivider.test.js +1 -1
  44. package/lib/components/toolbar/controls/AlignmentControl.vue +27 -46
  45. package/lib/components/toolbar/controls/BackgroundColorControl.vue +5 -26
  46. package/lib/components/toolbar/controls/CaseStyleControl.vue +10 -32
  47. package/lib/components/toolbar/controls/FontColorControl.vue +5 -27
  48. package/lib/components/toolbar/controls/FontFamilyControl.vue +27 -49
  49. package/lib/components/toolbar/controls/FontSizeControl.vue +9 -29
  50. package/lib/components/toolbar/controls/FontWeightControl.vue +7 -27
  51. package/lib/components/toolbar/controls/ItalicControl.vue +6 -27
  52. package/lib/components/toolbar/controls/LineHeightControl.vue +10 -37
  53. package/lib/components/toolbar/controls/ListControl.vue +18 -49
  54. package/lib/components/toolbar/controls/RemoveFormatControl.vue +4 -21
  55. package/lib/components/toolbar/controls/StrikeThroughControl.vue +5 -25
  56. package/lib/components/toolbar/controls/StylePresetControl.vue +34 -59
  57. package/lib/components/toolbar/controls/SuperscriptControl.vue +5 -25
  58. package/lib/components/toolbar/controls/UnderlineControl.vue +5 -26
  59. package/lib/components/toolbar/controls/__tests__/AlignmentControl.test.js +15 -13
  60. package/lib/components/toolbar/controls/__tests__/BackgroundColorControl.test.js +17 -15
  61. package/lib/components/toolbar/controls/__tests__/CaseStyleControl.test.js +9 -8
  62. package/lib/components/toolbar/controls/__tests__/FontColorControl.test.js +17 -15
  63. package/lib/components/toolbar/controls/__tests__/FontFamilyControl.test.js +14 -12
  64. package/lib/components/toolbar/controls/__tests__/FontSizeControl.test.js +5 -3
  65. package/lib/components/toolbar/controls/__tests__/FontWeightControl.test.js +3 -1
  66. package/lib/components/toolbar/controls/__tests__/ItalicControl.test.js +3 -1
  67. package/lib/components/toolbar/controls/__tests__/LineHeightControl.test.js +11 -9
  68. package/lib/components/toolbar/controls/__tests__/ListControl.test.js +16 -14
  69. package/lib/components/toolbar/controls/__tests__/RemoveFormatControl.test.js +3 -1
  70. package/lib/components/toolbar/controls/__tests__/StrikeThroughControl.test.js +3 -1
  71. package/lib/components/toolbar/controls/__tests__/StylePresetControl.test.js +3 -1
  72. package/lib/components/toolbar/controls/__tests__/SuperscriptControl.test.js +3 -1
  73. package/lib/components/toolbar/controls/__tests__/UnderlineControl.test.js +3 -1
  74. package/lib/components/toolbar/controls/composables/__tests__/useRecentFonts.test.js +6 -4
  75. package/lib/components/toolbar/controls/link/LinkControl.vue +75 -108
  76. package/lib/components/toolbar/controls/link/LinkControlHeader.vue +8 -14
  77. package/lib/components/toolbar/controls/link/__tests__/LinkControl.test.js +5 -3
  78. package/lib/components/toolbar/controls/link/__tests__/LinkControlHeader.test.js +3 -1
  79. package/lib/components/toolbar/controls/link/composables/__tests__/useLink.test.js +5 -4
  80. package/lib/components/toolbar/controls/link/destination/LinkControlDestination.vue +28 -47
  81. package/lib/components/toolbar/controls/link/destination/LinkControlPageBlock.vue +12 -20
  82. package/lib/components/toolbar/controls/link/destination/LinkControlUrl.vue +18 -26
  83. package/lib/components/toolbar/controls/link/destination/__tests__/LinkControlPageBlock.test.js +10 -10
  84. package/lib/components/toolbar/controls/link/destination/__tests__/LinkControlUrl.test.js +12 -10
  85. package/lib/components/toolbar/layouts/ToolbarDesktop.vue +36 -64
  86. package/lib/components/toolbar/layouts/ToolbarMobile.vue +38 -66
  87. package/lib/components/toolbar/layouts/ToolbarPopup.vue +36 -64
  88. package/lib/composables/__tests__/useEditor.test.js +3 -3
  89. package/lib/composables/useEditor.js +1 -1
  90. package/lib/directives/__tests__/outClick.test.js +9 -9
  91. package/lib/directives/outClick.js +3 -3
  92. package/lib/extensions/Alignment.js +1 -1
  93. package/lib/extensions/BackgroundColor.js +1 -1
  94. package/lib/extensions/CaseStyle.js +1 -1
  95. package/lib/extensions/DeviceManager.js +1 -1
  96. package/lib/extensions/FontColor.js +1 -1
  97. package/lib/extensions/FontFamily.js +2 -2
  98. package/lib/extensions/FontSize.js +3 -3
  99. package/lib/extensions/FontStyle.js +1 -1
  100. package/lib/extensions/FontWeight.js +1 -1
  101. package/lib/extensions/LineHeight.js +1 -1
  102. package/lib/extensions/Link.js +1 -1
  103. package/lib/extensions/Margin.js +1 -1
  104. package/lib/extensions/StylePreset.js +9 -9
  105. package/lib/extensions/Superscript.js +1 -1
  106. package/lib/extensions/TextDecoration.js +1 -1
  107. package/lib/extensions/__tests__/Alignment.test.js +1 -1
  108. package/lib/extensions/__tests__/BackgroundColor.test.js +1 -1
  109. package/lib/extensions/__tests__/CaseStyle.test.js +1 -1
  110. package/lib/extensions/__tests__/FontColor.test.js +1 -1
  111. package/lib/extensions/__tests__/FontFamily.test.js +1 -1
  112. package/lib/extensions/__tests__/FontSize.test.js +1 -1
  113. package/lib/extensions/__tests__/FontStyle.test.js +1 -1
  114. package/lib/extensions/__tests__/FontWeight.test.js +1 -1
  115. package/lib/extensions/__tests__/LineHeight.test.js +1 -1
  116. package/lib/extensions/__tests__/Link.test.js +1 -1
  117. package/lib/extensions/__tests__/StylePreset.test.js +1 -1
  118. package/lib/extensions/__tests__/Superscript.test.js +1 -1
  119. package/lib/extensions/__tests__/TextDecoration.test.js +1 -1
  120. package/lib/extensions/core/NodeProcessor.js +1 -1
  121. package/lib/extensions/core/SelectionProcessor.js +1 -1
  122. package/lib/extensions/core/TextProcessor.js +1 -1
  123. package/lib/extensions/core/__tests__/NodeProcessor.test.js +1 -1
  124. package/lib/extensions/core/__tests__/SelectionProcessor.test.js +1 -1
  125. package/lib/extensions/core/__tests__/TextProcessor.test.js +1 -1
  126. package/lib/extensions/core/index.js +1 -1
  127. package/lib/extensions/index.js +1 -1
  128. package/lib/extensions/list/List.js +4 -4
  129. package/lib/extensions/list/__tests__/List.test.js +1 -1
  130. package/package.json +19 -20
  131. package/config/jest/matchers/toVueEmpty.js +0 -16
  132. package/config/jest/matchers/toVuexActionHasBeenDispatched.js +0 -19
  133. package/lib/components/base/__tests__/__snapshots__/TextField.test.js.snap +0 -9
  134. package/lib/components/base/dropdown/__tests__/DropdownMenu.test.js +0 -67
@@ -9,64 +9,46 @@
9
9
  </Button>
10
10
  </template>
11
11
 
12
- <script>
12
+ <script setup>
13
13
  import { computed, inject, nextTick, onMounted, ref, toRef } from 'vue';
14
14
  import Button from '../Button';
15
15
  import { useScrollView } from '../composables';
16
16
  import { InjectionTokens } from './injectionTokens';
17
17
  import { useDropdownEntityTitle } from './composables';
18
18
 
19
- export default {
20
- name: 'DropdownOption',
21
-
22
- components: {
23
- Button
24
- },
25
-
26
- props: {
27
- option: {
28
- type: Object,
29
- required: true
30
- }
31
- },
32
-
33
- setup(props) {
34
- const activeOptionManager = inject(InjectionTokens.ACTIVE_MANAGER);
35
- const dropdownToggler = inject(InjectionTokens.TOGGLER);
36
- const session = inject(InjectionTokens.SESSION);
19
+ const props = defineProps({
20
+ option: {
21
+ type: Object,
22
+ required: true
23
+ }
24
+ });
37
25
 
38
- const optionRef = ref(null);
39
- const scrollView = useScrollView();
40
- const optionTitle = useDropdownEntityTitle(toRef(props, 'option'));
41
- const isActive = computed(() => props.option.id === activeOptionManager.activeOption.value?.id);
42
- const classes = computed(() => ({ 'zw-dropdown__option--active': isActive.value }));
26
+ const activeOptionManager = inject(InjectionTokens.ACTIVE_MANAGER);
27
+ const dropdownToggler = inject(InjectionTokens.TOGGLER);
28
+ const session = inject(InjectionTokens.SESSION);
43
29
 
44
- function activate() {
45
- activeOptionManager.activateOption(props.option);
46
- dropdownToggler.close();
47
- }
30
+ const optionRef = ref(null);
31
+ const scrollView = useScrollView();
32
+ const optionTitle = useDropdownEntityTitle(toRef(props, 'option'));
33
+ const isActive = computed(() => props.option.id === activeOptionManager.activeOption.value?.id);
34
+ const classes = computed(() => ({ 'zw-dropdown__option--active': isActive.value }));
48
35
 
49
- onMounted(async () => {
50
- if (isActive.value && !session.scrolled) {
51
- session.scrolled = true; // Prevent multiple scrolling to option
36
+ function activate() {
37
+ activeOptionManager.activateOption(props.option);
38
+ dropdownToggler.close();
39
+ }
52
40
 
53
- await nextTick();
54
- const el = optionRef.value.$el;
55
- const offset = el.offsetHeight * 1.5;
41
+ onMounted(async () => {
42
+ if (isActive.value && !session.scrolled) {
43
+ session.scrolled = true; // Prevent multiple scrolling to option
56
44
 
57
- scrollView.scrollToElement(el, { offset });
58
- }
59
- });
45
+ await nextTick();
46
+ const el = optionRef.value.$el;
47
+ const offset = el.offsetHeight * 1.5;
60
48
 
61
- return {
62
- optionTitle,
63
- classes,
64
- isActive,
65
- optionRef,
66
- activate
67
- };
49
+ scrollView.scrollToElement(el, { offset });
68
50
  }
69
- };
51
+ });
70
52
  </script>
71
53
 
72
54
  <style scoped>
@@ -15,9 +15,11 @@ const createActiveOptionManager = ({ activeOption } = {}) => ({
15
15
 
16
16
  function createComponent({ toggler, activeOptionManager } = {}) {
17
17
  return shallowMount(DropdownActivator, {
18
- provide: {
19
- [InjectionTokens.TOGGLER]: toggler ?? createToggler(),
20
- [InjectionTokens.ACTIVE_MANAGER]: activeOptionManager ?? createActiveOptionManager()
18
+ global: {
19
+ provide: {
20
+ [InjectionTokens.TOGGLER]: toggler ?? createToggler(),
21
+ [InjectionTokens.ACTIVE_MANAGER]: activeOptionManager ?? createActiveOptionManager()
22
+ }
21
23
  }
22
24
  });
23
25
  }
@@ -17,13 +17,15 @@ const createToggler = () => ({
17
17
 
18
18
  function createComponent({ option, activeManager, toggler }) {
19
19
  return shallowMount(DropdownOption, {
20
- propsData: { option },
21
-
22
- provide: {
23
- [InjectionTokens.ACTIVE_MANAGER]: activeManager ?? createActiveManager(),
24
- [InjectionTokens.TOGGLER]: toggler ?? createToggler(),
25
- [InjectionTokens.SESSION]: {},
26
- [SCROLL_VIEW]: ref(null)
20
+ props: { option },
21
+
22
+ global: {
23
+ provide: {
24
+ [InjectionTokens.ACTIVE_MANAGER]: activeManager ?? createActiveManager(),
25
+ [InjectionTokens.TOGGLER]: toggler ?? createToggler(),
26
+ [InjectionTokens.SESSION]: {},
27
+ [SCROLL_VIEW]: ref(null)
28
+ }
27
29
  }
28
30
  });
29
31
  }
@@ -1,64 +1,47 @@
1
1
  <template>
2
2
  <keep-alive>
3
3
  <transition name="zw-toolbar-" duration="150">
4
- <div class="zw-toolbar" :style="toolbarStyles" ref="toolbarRef" v-if="isVisible">
4
+ <div class="zw-toolbar" ref="toolbarRef" v-if="isVisible">
5
5
  <component :is="layoutComponent" />
6
6
  </div>
7
7
  </transition>
8
8
  </keep-alive>
9
9
  </template>
10
10
 
11
- <script>
11
+ <script setup>
12
12
  import { computed, ref, watch } from 'vue';
13
13
  import { Devices } from '../../enums';
14
14
  import { ToolbarDesktop, ToolbarMobile, ToolbarPopup } from './layouts';
15
15
 
16
- export default {
17
- name: 'Toolbar',
18
-
19
- props: {
20
- device: {
21
- type: String,
22
- required: true
23
- },
24
-
25
- toolbar: {
26
- type: Object,
27
- required: true
28
- },
29
-
30
- popupMode: {
31
- type: Boolean,
32
- required: true
33
- }
16
+ const props = defineProps({
17
+ device: {
18
+ type: String,
19
+ required: true
34
20
  },
35
21
 
36
- setup(props) {
37
- const layoutComponent = computed(() => {
38
- if (props.popupMode) return ToolbarPopup;
22
+ toolbar: {
23
+ type: Object,
24
+ required: true
25
+ },
39
26
 
40
- return props.device === Devices.MOBILE ? ToolbarMobile : ToolbarDesktop;
41
- });
27
+ popupMode: {
28
+ type: Boolean,
29
+ required: true
30
+ }
31
+ });
42
32
 
43
- const isVisible = computed(() => props.toolbar.isActiveRef.value);
44
- const toolbarRef = ref(null);
33
+ const layoutComponent = computed(() => {
34
+ if (props.popupMode) return ToolbarPopup;
45
35
 
46
- watch(toolbarRef, (toolbarEl) => {
47
- toolbarEl && props.toolbar.mount(toolbarEl);
48
- });
36
+ return props.device === Devices.MOBILE ? ToolbarMobile : ToolbarDesktop;
37
+ });
49
38
 
50
- const toolbarStyles = computed(() => ({
51
- '--zw-toolbar-offset-y': `${props.toolbar.offsets[1]}px`
52
- }));
39
+ const isVisible = computed(() => props.toolbar.isActiveRef.value);
40
+ const toolbarRef = ref(null);
53
41
 
54
- return {
55
- layoutComponent,
56
- isVisible,
57
- toolbarRef,
58
- toolbarStyles
59
- };
60
- }
61
- };
42
+ watch(toolbarRef, (toolbarEl) => {
43
+ toolbarEl && props.toolbar.mount(toolbarEl);
44
+ });
62
45
  </script>
63
46
 
64
47
  <style scoped>
@@ -69,6 +52,7 @@ export default {
69
52
  z-index: 999999;
70
53
  text-align: left;
71
54
  position: absolute;
55
+ --zw-toolbar-offset-y: calc(v-bind("toolbar.offsets[1]") * 1px)
72
56
  }
73
57
 
74
58
  .zw-toolbar::before,
@@ -98,7 +82,7 @@ export default {
98
82
  transition: opacity 0s ease-in;
99
83
  }
100
84
 
101
- .zw-toolbar--enter,
85
+ .zw-toolbar--enter-from,
102
86
  .zw-toolbar--leave-to {
103
87
  opacity: 0;
104
88
  }
@@ -6,7 +6,7 @@ import { ToolbarMobile, ToolbarDesktop, ToolbarPopup } from '../layouts';
6
6
 
7
7
  function createComponent({ device, popupMode }) {
8
8
  return shallowMount(Toolbar, {
9
- propsData: {
9
+ props: {
10
10
  toolbar: {
11
11
  mount: jest.fn(),
12
12
  isActiveRef: ref({ value: true }),
@@ -3,7 +3,7 @@ import ToolbarDivider from '../ToolbarDivider';
3
3
 
4
4
  function createComponent({ isVertical, isHorizontal }) {
5
5
  return shallowMount(ToolbarDivider, {
6
- propsData: {
6
+ props: {
7
7
  vertical: isVertical ?? false,
8
8
  horizontal: isHorizontal ?? false
9
9
  }
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <ButtonToggle :value="currentValue" :options="$options.alignments" @change="toggle">
2
+ <ButtonToggle :value="currentValue" :options="alignments" @change="toggle">
3
3
  <template #option="{ isActive, option, activate }">
4
4
  <Button
5
5
  class="zw-position--relative"
@@ -15,59 +15,40 @@
15
15
  </ButtonToggle>
16
16
  </template>
17
17
 
18
- <script>
18
+ <script setup>
19
19
  import { inject, computed, unref } from 'vue';
20
20
  import { InjectionTokens } from '../../../injectionTokens';
21
21
  import { Alignments } from '../../../enums';
22
22
  import { ButtonToggle, Button, Icon } from '../../base';
23
- import { tooltip } from '../../../directives';
23
+ import { tooltip as vTooltip } from '../../../directives';
24
24
 
25
- export default {
26
- name: 'AlignmentControl',
27
-
28
- alignments: [
29
- {
30
- id: Alignments.LEFT,
31
- tooltip: { text: 'Align Left', hotkey: 'Mod Shift L' }
32
- },
33
- {
34
- id: Alignments.CENTER,
35
- tooltip: { text: 'Align Center', hotkey: 'Mod Shift E' }
36
- },
37
- {
38
- id: Alignments.RIGHT,
39
- tooltip: { text: 'Align Right', hotkey: 'Mod Shift R' }
40
- },
41
- {
42
- id: Alignments.JUSTIFY,
43
- tooltip: { text: 'Justify', hotkey: 'Mod Shift J' }
44
- }
45
- ],
46
-
47
- components: {
48
- ButtonToggle,
49
- Button,
50
- Icon
25
+ const alignments = [
26
+ {
27
+ id: Alignments.LEFT,
28
+ tooltip: { text: 'Align Left', hotkey: 'Mod Shift L' }
51
29
  },
52
-
53
- directives: {
54
- tooltip
30
+ {
31
+ id: Alignments.CENTER,
32
+ tooltip: { text: 'Align Center', hotkey: 'Mod Shift E' }
55
33
  },
34
+ {
35
+ id: Alignments.RIGHT,
36
+ tooltip: { text: 'Align Right', hotkey: 'Mod Shift R' }
37
+ },
38
+ {
39
+ id: Alignments.JUSTIFY,
40
+ tooltip: { text: 'Justify', hotkey: 'Mod Shift J' }
41
+ }
42
+ ];
56
43
 
57
- setup(_, { emit }) {
58
- const editor = inject(InjectionTokens.EDITOR);
59
- const alignment = editor.commands.getAlignment();
60
- const currentValue = computed(() => unref(alignment) ?? 'none');
44
+ const emit = defineEmits(['applied']);
61
45
 
62
- function toggle(value) {
63
- editor.chain().focus().toggleAlignment(value).run();
64
- emit('applied');
65
- }
46
+ const editor = inject(InjectionTokens.EDITOR);
47
+ const alignment = editor.commands.getAlignment();
48
+ const currentValue = computed(() => unref(alignment) ?? 'none');
66
49
 
67
- return {
68
- currentValue,
69
- toggle
70
- };
71
- }
72
- };
50
+ function toggle(value) {
51
+ editor.chain().focus().toggleAlignment(value).run();
52
+ emit('applied');
53
+ }
73
54
  </script>
@@ -14,35 +14,14 @@
14
14
  </ColorPicker>
15
15
  </template>
16
16
 
17
- <script>
17
+ <script setup>
18
18
  import { inject } from 'vue';
19
19
  import { ColorPicker, Button, Icon } from '../../base';
20
20
  import { InjectionTokens } from '../../../injectionTokens';
21
- import { tooltip } from '../../../directives';
21
+ import { tooltip as vTooltip } from '../../../directives';
22
22
 
23
- export default {
24
- name: 'BackgroundColorControl',
23
+ const editor = inject(InjectionTokens.EDITOR);
25
24
 
26
- components: {
27
- ColorPicker,
28
- Button,
29
- Icon
30
- },
31
-
32
- directives: {
33
- tooltip
34
- },
35
-
36
- setup() {
37
- const editor = inject(InjectionTokens.EDITOR);
38
-
39
- const currentValue = editor.commands.getBackgroundColor();
40
- const apply = (color) => editor.chain().applyBackgroundColor(color).run();
41
-
42
- return {
43
- currentValue,
44
- apply
45
- };
46
- }
47
- };
25
+ const currentValue = editor.commands.getBackgroundColor();
26
+ const apply = (color) => editor.chain().applyBackgroundColor(color).run();
48
27
  </script>
@@ -1,8 +1,5 @@
1
1
  <template>
2
- <Dropdown
3
- :options="$options.styles"
4
- @change="apply"
5
- >
2
+ <Dropdown :options="styles" @change="apply">
6
3
  <template #activator="{ open, isOpened }">
7
4
  <Button
8
5
  icon
@@ -17,38 +14,19 @@
17
14
  </Dropdown>
18
15
  </template>
19
16
 
20
- <script>
17
+ <script setup>
21
18
  import { inject } from 'vue';
22
19
  import { CaseStyles } from '../../../enums';
23
20
  import { Dropdown, Button, Icon } from '../../base';
24
21
  import { InjectionTokens } from '../../../injectionTokens';
25
- import { tooltip } from '../../../directives';
22
+ import { tooltip as vTooltip } from '../../../directives';
26
23
 
27
- export default {
28
- name: 'CaseStyleControl',
24
+ const styles = [
25
+ { id: CaseStyles.UPPERCASE, title: 'UPPERCASE' },
26
+ { id: CaseStyles.LOWERCASE, title: 'lowercase' },
27
+ { id: CaseStyles.CAPITALIZE, title: 'Capitalize' }
28
+ ];
29
29
 
30
- components: {
31
- Dropdown,
32
- Button,
33
- Icon
34
- },
35
-
36
- directives: {
37
- tooltip
38
- },
39
-
40
- styles: [
41
- { id: CaseStyles.UPPERCASE, title: 'UPPERCASE' },
42
- { id: CaseStyles.LOWERCASE, title: 'lowercase' },
43
- { id: CaseStyles.CAPITALIZE, title: 'Capitalize' }
44
- ],
45
-
46
- setup() {
47
- const editor = inject(InjectionTokens.EDITOR);
48
-
49
- const apply = (value) => editor.chain().focus().applyCaseStyle(value).run();
50
-
51
- return { apply };
52
- }
53
- };
30
+ const editor = inject(InjectionTokens.EDITOR);
31
+ const apply = (value) => editor.chain().focus().applyCaseStyle(value).run();
54
32
  </script>
@@ -14,36 +14,14 @@
14
14
  </ColorPicker>
15
15
  </template>
16
16
 
17
- <script>
17
+ <script setup>
18
18
  import { inject } from 'vue';
19
19
  import { ColorPicker, Button, Icon } from '../../base';
20
20
  import { InjectionTokens } from '../../../injectionTokens';
21
- import { tooltip } from '../../../directives';
21
+ import { tooltip as vTooltip } from '../../../directives';
22
22
 
23
- export default {
24
- name: 'FontColorControl',
23
+ const editor = inject(InjectionTokens.EDITOR);
25
24
 
26
- components: {
27
- ColorPicker,
28
- Button,
29
- Icon
30
- },
31
-
32
- directives: {
33
- tooltip
34
- },
35
-
36
- setup() {
37
- const editor = inject(InjectionTokens.EDITOR);
38
-
39
- const currentValue = editor.commands.getFontColor();
40
-
41
- const apply = (color) => editor.chain().applyFontColor(color).run();
42
-
43
- return {
44
- currentValue,
45
- apply
46
- };
47
- }
48
- };
25
+ const currentValue = editor.commands.getFontColor();
26
+ const apply = (color) => editor.chain().applyFontColor(color).run();
49
27
  </script>
@@ -17,69 +17,47 @@
17
17
  </Dropdown>
18
18
  </template>
19
19
 
20
- <script>
20
+ <script setup>
21
21
  import { computed, inject } from 'vue';
22
22
  import { InjectionTokens } from '../../../injectionTokens';
23
- import { tooltip } from '../../../directives';
23
+ import { tooltip as vTooltip } from '../../../directives';
24
24
  import { Dropdown, DropdownOption } from '../../base';
25
25
  import { useRecentFonts } from './composables';
26
26
 
27
- export default {
28
- name: 'FontFamilyControl',
27
+ const fonts = inject(InjectionTokens.FONTS);
28
+ const editor = inject(InjectionTokens.EDITOR);
29
29
 
30
- components: {
31
- Dropdown,
32
- DropdownOption
33
- },
30
+ const recentFontNames = useRecentFonts({ limit: 5 });
34
31
 
35
- directives: {
36
- tooltip
37
- },
32
+ const recentFontsCategory = computed(() => ({
33
+ id: 'Recently Used',
34
+ options: recentFontNames.fonts.value.map((name) => ({ id: name }))
35
+ }));
38
36
 
39
- setup() {
40
- const fonts = inject(InjectionTokens.FONTS);
41
- const editor = inject(InjectionTokens.EDITOR);
37
+ const options = computed(() => {
38
+ const list = {};
42
39
 
43
- const recentFontNames = useRecentFonts({ limit: 5 });
44
-
45
- const recentFontsCategory = computed(() => ({
46
- id: 'Recently Used',
47
- options: recentFontNames.fonts.value.map((name) => ({ id: name }))
48
- }));
49
-
50
- const options = computed(() => {
51
- const list = {};
52
-
53
- for (const font of fonts) {
54
- list[font.category] ??= { id: font.category, options: [] };
55
- list[font.category].options.push({ id: font.name });
56
- }
57
-
58
- if (recentFontNames.isEmpty.value) {
59
- return Object.values(list);
60
- }
40
+ for (const font of fonts) {
41
+ list[font.category] ??= { id: font.category, options: [] };
42
+ list[font.category].options.push({ id: font.name });
43
+ }
61
44
 
62
- return [recentFontsCategory.value, ...Object.values(list)];
63
- });
45
+ if (recentFontNames.isEmpty.value) {
46
+ return Object.values(list);
47
+ }
64
48
 
65
- function renderOptionStyles(option) {
66
- return { '--zw-font-family-option': `"${option.id}"` };
67
- }
49
+ return [recentFontsCategory.value, ...Object.values(list)];
50
+ });
68
51
 
69
- const currentValue = editor.commands.getFont();
52
+ function renderOptionStyles(option) {
53
+ return { '--zw-font-family-option': `"${option.id}"` };
54
+ }
70
55
 
71
- const apply = (fontFamily) => {
72
- recentFontNames.add(fontFamily);
73
- editor.chain().focus().applyFontFamily(fontFamily).run();
74
- };
56
+ const currentValue = editor.commands.getFont();
75
57
 
76
- return {
77
- options,
78
- currentValue,
79
- renderOptionStyles,
80
- apply
81
- };
82
- }
58
+ const apply = (fontFamily) => {
59
+ recentFontNames.add(fontFamily);
60
+ editor.chain().focus().applyFontFamily(fontFamily).run();
83
61
  };
84
62
  </script>
85
63
 
@@ -8,42 +8,22 @@
8
8
  />
9
9
  </template>
10
10
 
11
- <script>
11
+ <script setup>
12
12
  import { computed, inject } from 'vue';
13
13
  import { Dropdown } from '../../base';
14
14
  import { InjectionTokens } from '../../../injectionTokens';
15
- import { tooltip } from '../../../directives';
15
+ import { tooltip as vTooltip } from '../../../directives';
16
16
 
17
- export default {
18
- name: 'FontSizeControl',
17
+ const fontSizes = inject(InjectionTokens.FONT_SIZES);
18
+ const editor = inject(InjectionTokens.EDITOR);
19
19
 
20
- components: {
21
- Dropdown
22
- },
20
+ const options = computed(() => {
21
+ return fontSizes.map((size) => ({ id: size, title: `${size}px` }));
22
+ });
23
23
 
24
- directives: {
25
- tooltip
26
- },
24
+ const currentValue = editor.commands.getFontSize();
27
25
 
28
- setup() {
29
- const fontSizes = inject(InjectionTokens.FONT_SIZES);
30
- const editor = inject(InjectionTokens.EDITOR);
31
-
32
- const options = computed(() => {
33
- return fontSizes.map((size) => ({ id: size, title: `${size}px` }));
34
- });
35
-
36
- const currentValue = editor.commands.getFontSize();
37
-
38
- const apply = (value) => editor.chain().focus().applyFontSize(value).run();
39
-
40
- return {
41
- options,
42
- currentValue,
43
- apply
44
- };
45
- }
46
- };
26
+ const apply = (value) => editor.chain().focus().applyFontSize(value).run();
47
27
  </script>
48
28
 
49
29
  <style scoped>