@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
@@ -19,19 +19,21 @@ const createEditor = ({ fontFamily } = {}) => ({
19
19
 
20
20
  function createComponent({ editor }) {
21
21
  return shallowMount(FontFamilyControl, {
22
- stubs: {
23
- Dropdown: {
24
- render: () => h('div'),
25
- props: ['value']
22
+ global: {
23
+ stubs: {
24
+ Dropdown: {
25
+ render: () => h('div'),
26
+ props: ['value']
27
+ }
28
+ },
29
+ provide: {
30
+ [InjectionTokens.EDITOR]: editor,
31
+ [InjectionTokens.FONTS]: [
32
+ { name: 'Lato', category: 'test' },
33
+ { name: 'Bungee', category: 'test' }
34
+ ],
35
+ [InjectionTokens.LOCAL_STORAGE]: localStorage
26
36
  }
27
- },
28
- provide: {
29
- [InjectionTokens.EDITOR]: editor,
30
- [InjectionTokens.FONTS]: [
31
- { name: 'Lato', category: 'test' },
32
- { name: 'Bungee', category: 'test' }
33
- ],
34
- [InjectionTokens.LOCAL_STORAGE]: localStorage
35
37
  }
36
38
  });
37
39
  }
@@ -19,9 +19,11 @@ const createEditor = ({ fontSize } = {}) => ({
19
19
 
20
20
  function createComponent({ editor }) {
21
21
  return shallowMount(FontSizeControl, {
22
- provide: {
23
- [InjectionTokens.EDITOR]: editor,
24
- [InjectionTokens.FONT_SIZES]: ['12', '23']
22
+ global: {
23
+ provide: {
24
+ [InjectionTokens.EDITOR]: editor,
25
+ [InjectionTokens.FONT_SIZES]: ['12', '23']
26
+ }
25
27
  }
26
28
  });
27
29
  }
@@ -20,7 +20,9 @@ const createEditor = ({ fontWeight, fontWeightList } = {}) => ({
20
20
 
21
21
  function createComponent({ editor }) {
22
22
  return shallowMount(FontWeightControl, {
23
- provide: { [InjectionTokens.EDITOR]: editor }
23
+ global: {
24
+ provide: { [InjectionTokens.EDITOR]: editor }
25
+ }
24
26
  });
25
27
  }
26
28
 
@@ -20,7 +20,9 @@ const createEditor = ({ isItalic, isItalicAvailable } = {}) => ({
20
20
 
21
21
  function createComponent({ editor }) {
22
22
  return shallowMount(ItalicControl, {
23
- provide: { [InjectionTokens.EDITOR]: editor }
23
+ global: {
24
+ provide: { [InjectionTokens.EDITOR]: editor }
25
+ }
24
26
  });
25
27
  }
26
28
 
@@ -28,15 +28,17 @@ const createEditor = ({ height } = {}) => {
28
28
 
29
29
  function createComponent({ editor } = {}) {
30
30
  return shallowMount(LineHeightControl, {
31
- stubs: {
32
- Modal: {
33
- render() {
34
- return h('div', null, this.$slots.default);
35
- },
36
- props: ['toggler']
37
- }
38
- },
39
- provide: { [InjectionTokens.EDITOR]: editor ?? createEditor() }
31
+ global: {
32
+ stubs: {
33
+ Modal: {
34
+ render() {
35
+ return h('div', null, this.$slots.default());
36
+ },
37
+ props: ['toggler']
38
+ }
39
+ },
40
+ provide: { [InjectionTokens.EDITOR]: editor ?? createEditor() }
41
+ }
40
42
  });
41
43
  }
42
44
 
@@ -20,20 +20,22 @@ const createEditor = ({ listType } = {}) => ({
20
20
 
21
21
  function createComponent({ editor }) {
22
22
  return shallowMount(ListControl, {
23
- stubs: {
24
- Dropdown: {
25
- render() {
26
- const activator = this.$scopedSlots.activator({
27
- open: jest.fn(),
28
- isOpened: false
29
- });
30
-
31
- return h('div', null, [activator]);
32
- },
33
- props: ['value']
34
- }
35
- },
36
- provide: { [InjectionTokens.EDITOR]: editor }
23
+ global: {
24
+ stubs: {
25
+ Dropdown: {
26
+ render() {
27
+ const activator = this.$slots.activator({
28
+ open: jest.fn(),
29
+ isOpened: false
30
+ });
31
+
32
+ return h('div', null, [activator]);
33
+ },
34
+ props: ['value']
35
+ }
36
+ },
37
+ provide: { [InjectionTokens.EDITOR]: editor }
38
+ }
37
39
  });
38
40
  }
39
41
 
@@ -17,7 +17,9 @@ const createEditor = () => ({
17
17
 
18
18
  function createComponent({ editor }) {
19
19
  return shallowMount(RemoveFormatControl, {
20
- provide: { [InjectionTokens.EDITOR]: editor }
20
+ global: {
21
+ provide: { [InjectionTokens.EDITOR]: editor }
22
+ }
21
23
  });
22
24
  }
23
25
 
@@ -19,7 +19,9 @@ const createEditor = ({ isStrikeThrough } = {}) => ({
19
19
 
20
20
  function createComponent({ editor }) {
21
21
  return shallowMount(StrikeThroughControl, {
22
- provide: { [InjectionTokens.EDITOR]: editor }
22
+ global: {
23
+ provide: { [InjectionTokens.EDITOR]: editor }
24
+ }
23
25
  });
24
26
  }
25
27
 
@@ -27,7 +27,9 @@ const createEditor = ({ presets, preset, customization } = {}) => ({
27
27
 
28
28
  function createComponent({ editor }) {
29
29
  return shallowMount(StylePresetControl, {
30
- provide: { [InjectionTokens.EDITOR]: editor }
30
+ global: {
31
+ provide: { [InjectionTokens.EDITOR]: editor }
32
+ }
31
33
  });
32
34
  }
33
35
 
@@ -19,7 +19,9 @@ const createEditor = ({ isSuperscript } = {}) => ({
19
19
 
20
20
  function createComponent({ editor }) {
21
21
  return shallowMount(SuperscriptControl, {
22
- provide: { [InjectionTokens.EDITOR]: editor }
22
+ global: {
23
+ provide: { [InjectionTokens.EDITOR]: editor }
24
+ }
23
25
  });
24
26
  }
25
27
 
@@ -23,7 +23,9 @@ const createEditor = ({ isUnderline } = {}) => ({
23
23
 
24
24
  function createComponent({ editor }) {
25
25
  return shallowMount(UnderlineControl, {
26
- provide: { [InjectionTokens.EDITOR]: editor }
26
+ global: {
27
+ provide: { [InjectionTokens.EDITOR]: editor }
28
+ }
27
29
  });
28
30
  }
29
31
 
@@ -18,10 +18,12 @@ function createWrapper({ initial } = {}) {
18
18
  return withComponentContext(() => {
19
19
  return useRecentFonts({ limit: 3 });
20
20
  }, {
21
- provide: {
22
- [InjectionTokens.LOCAL_STORAGE]: createStorage({
23
- 'wswg.recently_used_fonts': initial
24
- })
21
+ global: {
22
+ provide: {
23
+ [InjectionTokens.LOCAL_STORAGE]: createStorage({
24
+ 'wswg.recently_used_fonts': initial
25
+ })
26
+ }
25
27
  }
26
28
  });
27
29
  }
@@ -38,123 +38,90 @@
38
38
  </div>
39
39
  </template>
40
40
 
41
- <script>
41
+ <script setup>
42
42
  import { computed, ref, inject, unref } from 'vue';
43
43
  import { LinkDestinations, TextSettings } from '../../../../enums';
44
44
  import { InjectionTokens } from '../../../../injectionTokens';
45
45
  import { RegExps } from '../../../../regExps';
46
- import { tooltip } from '../../../../directives';
46
+ import { tooltip as vTooltip } from '../../../../directives';
47
47
  import { useValidator } from '../../../base/composables';
48
48
  import { Button, Icon, Modal, TextField, useModalToggler } from '../../../base';
49
49
  import LinkControlHeader from './LinkControlHeader';
50
50
  import { useLink } from './composables';
51
51
  import { LinkControlDestination } from './destination';
52
52
 
53
- export default {
54
- name: 'LinkControl',
55
-
56
- components: {
57
- LinkControlDestination,
58
- LinkControlHeader,
59
- TextField,
60
- Modal,
61
- Icon,
62
- Button
63
- },
64
-
65
- directives: {
66
- tooltip
67
- },
68
-
69
- setup() {
70
- const wrapperRef = ref(null);
71
- const modalRef = ref(null);
72
-
73
- const editor = inject(InjectionTokens.EDITOR);
74
-
75
- const link = useLink();
76
-
77
- const isEmpty = () => {
78
- return link.linkData.value.text ? false : 'Can\'t be empty';
79
- };
80
-
81
- const isValidUrl = () => {
82
- if (link.currentDestination.value.id !== LinkDestinations.URL) return false;
83
-
84
- const href = link.destinationHrefs.value.url;
85
- const isTelOrMail = RegExps.TEL_PROTOCOL.test(href) || RegExps.MAILTO_PROTOCOL.test(href);
86
-
87
- if (isTelOrMail) return false;
88
- if (href.startsWith('/')) return false;
89
-
90
- const isUrl = RegExps.URL.test(href);
91
-
92
- return isUrl ? false : 'Please enter a valid URL';
93
- };
94
-
95
- const nameValidator = useValidator({
96
- validations: [isEmpty]
97
- });
98
-
99
- const urlValidator = useValidator({
100
- validations: [isValidUrl]
101
- });
102
-
103
- const resetErrors = () => {
104
- nameValidator.reset();
105
- urlValidator.reset();
106
- };
107
-
108
- const onBeforeOpened = () => {
109
- editor.commands.extendMarkRange(TextSettings.LINK);
110
- resetErrors();
111
- link.prepareInitialFields();
112
- };
113
-
114
- const toggler = useModalToggler({
115
- onBeforeOpened: () => onBeforeOpened(),
116
- wrapperRef,
117
- modalRef
118
- });
119
-
120
- const isLink = editor.commands.isLink();
121
- const isActive = computed(() => unref(toggler.isOpened) || unref(isLink));
122
-
123
- const updateLinkText = (value) => {
124
- resetErrors();
125
- link.updateText(value);
126
- };
127
-
128
- const applyLink = () => {
129
- urlValidator.validate();
130
- nameValidator.validate();
131
-
132
- if (urlValidator.error.value || nameValidator.error.value) return;
133
-
134
- link.apply();
135
- toggler.close();
136
- link.resetDestinations();
137
- };
138
-
139
- const removeLink = () => {
140
- link.removeLink();
141
- toggler.close();
142
- };
143
-
144
- return {
145
- wrapperRef,
146
- modalRef,
147
- link,
148
- toggler,
149
- isActive,
150
- nameValidator,
151
- urlValidator,
152
- updateLinkText,
153
- resetErrors,
154
- applyLink,
155
- removeLink
156
- };
157
- }
53
+ const wrapperRef = ref(null);
54
+ const modalRef = ref(null);
55
+
56
+ const editor = inject(InjectionTokens.EDITOR);
57
+
58
+ const link = useLink();
59
+
60
+ const isEmpty = () => {
61
+ return link.linkData.value.text ? false : 'Can\'t be empty';
62
+ };
63
+
64
+ const isValidUrl = () => {
65
+ if (link.currentDestination.value.id !== LinkDestinations.URL) return false;
66
+
67
+ const href = link.destinationHrefs.value.url;
68
+ const isTelOrMail = RegExps.TEL_PROTOCOL.test(href) || RegExps.MAILTO_PROTOCOL.test(href);
69
+
70
+ if (isTelOrMail) return false;
71
+ if (href.startsWith('/')) return false;
72
+
73
+ const isUrl = RegExps.URL.test(href);
74
+
75
+ return isUrl ? false : 'Please enter a valid URL';
76
+ };
77
+
78
+ const nameValidator = useValidator({
79
+ validations: [isEmpty]
80
+ });
81
+
82
+ const urlValidator = useValidator({
83
+ validations: [isValidUrl]
84
+ });
85
+
86
+ const resetErrors = () => {
87
+ nameValidator.reset();
88
+ urlValidator.reset();
89
+ };
90
+
91
+ const onBeforeOpened = () => {
92
+ editor.commands.extendMarkRange(TextSettings.LINK);
93
+ resetErrors();
94
+ link.prepareInitialFields();
95
+ };
96
+
97
+ const toggler = useModalToggler({
98
+ onBeforeOpened: () => onBeforeOpened(),
99
+ wrapperRef,
100
+ modalRef
101
+ });
102
+
103
+ const isLink = editor.commands.isLink();
104
+ const isActive = computed(() => unref(toggler.isOpened) || unref(isLink));
105
+
106
+ const updateLinkText = (value) => {
107
+ resetErrors();
108
+ link.updateText(value);
109
+ };
110
+
111
+ const applyLink = () => {
112
+ urlValidator.validate();
113
+ nameValidator.validate();
114
+
115
+ if (urlValidator.error.value || nameValidator.error.value) return;
116
+
117
+ link.apply();
118
+ toggler.close();
119
+ link.resetDestinations();
120
+ };
121
+
122
+ const removeLink = () => {
123
+ link.removeLink();
124
+ toggler.close();
158
125
  };
159
126
  </script>
160
127
 
@@ -172,7 +139,7 @@ export default {
172
139
  justify-content: flex-end;
173
140
  }
174
141
 
175
- ::v-deep .zw-link-modal-dropdown__option {
142
+ :deep(.zw-link-modal-dropdown__option) {
176
143
  width: 234px;
177
144
  }
178
145
  </style>
@@ -1,6 +1,8 @@
1
1
  <template>
2
2
  <div class="zw-link-modal-header">
3
- <span class="zw-link-modal-header__title">Link</span>
3
+ <span class="zw-link-modal-header__title">
4
+ Link
5
+ </span>
4
6
 
5
7
  <Button class="zw-link-modal-header__unlink-button" :disabled="!isLink" data-initial-focus="false" @click="removeLink">
6
8
  <Icon class="zw-link-modal-header__unlink-icon" name="unlink" size="14px" auto-color />
@@ -9,25 +11,17 @@
9
11
  </div>
10
12
  </template>
11
13
 
12
- <script>
14
+ <script setup>
13
15
  import { inject } from 'vue';
14
16
  import { Icon, Button } from '../../../base';
15
17
  import { InjectionTokens } from '../../../../injectionTokens';
16
18
 
17
- export default {
18
- name: 'LinkControlHeader',
19
+ const emit = defineEmits(['remove-link']);
19
20
 
20
- components: { Icon, Button },
21
+ const editor = inject(InjectionTokens.EDITOR);
22
+ const isLink = editor.commands.isLink();
21
23
 
22
- setup(_, { emit }) {
23
- const editor = inject(InjectionTokens.EDITOR);
24
- const isLink = editor.commands.isLink();
25
-
26
- const removeLink = () => emit('remove-link');
27
-
28
- return { isLink, removeLink };
29
- }
30
- };
24
+ const removeLink = () => emit('remove-link');
31
25
  </script>
32
26
 
33
27
  <style scoped>
@@ -11,9 +11,11 @@ const createEditor = (isActive) => ({
11
11
 
12
12
  function createComponent({ editor }) {
13
13
  return shallowMount(LinkControl, {
14
- provide: {
15
- [InjectionTokens.EDITOR]: editor,
16
- [InjectionTokens.PAGE_BLOCKS]: ref([{ id: 1 }])
14
+ global: {
15
+ provide: {
16
+ [InjectionTokens.EDITOR]: editor,
17
+ [InjectionTokens.PAGE_BLOCKS]: ref([{ id: 1 }])
18
+ }
17
19
  }
18
20
  });
19
21
  }
@@ -9,7 +9,9 @@ const createEditor = (isActive) => ({
9
9
 
10
10
  function createComponent({ editor }) {
11
11
  return shallowMount(LinkControlHeader, {
12
- provide: { [InjectionTokens.EDITOR]: editor }
12
+ global: {
13
+ provide: { [InjectionTokens.EDITOR]: editor }
14
+ }
13
15
  });
14
16
  }
15
17
 
@@ -27,10 +27,11 @@ const createEditor = (text, destination) => ({
27
27
 
28
28
  function useComposable(text, destination) {
29
29
  return withComponentContext(() => useLink(), {
30
- provide: {
31
- [InjectionTokens.EDITOR]: createEditor(text, destination),
32
- [InjectionTokens.PAGE_BLOCKS]: ref([{ id: 1 }, { id: 2 }])
33
-
30
+ global: {
31
+ provide: {
32
+ [InjectionTokens.EDITOR]: createEditor(text, destination),
33
+ [InjectionTokens.PAGE_BLOCKS]: ref([{ id: 1 }, { id: 2 }])
34
+ }
34
35
  }
35
36
  });
36
37
  }
@@ -9,7 +9,7 @@
9
9
  color="gray"
10
10
  :max-width="266"
11
11
  :value="link.currentDestination.value.id"
12
- :options="$options.destinationTypes"
12
+ :options="destinationTypes"
13
13
  @change="changeDestination"
14
14
  >
15
15
  <template #option="{ option }">
@@ -38,66 +38,47 @@
38
38
  </div>
39
39
  </template>
40
40
 
41
- <script>
41
+ <script setup>
42
42
  import { computed, toRef } from 'vue';
43
43
  import { LinkDestinations, LinkTargets } from '../../../../../enums';
44
44
  import { Dropdown, DropdownOption, FieldLabel } from '../../../../base';
45
45
  import LinkControlPageBlock from './LinkControlPageBlock';
46
46
  import LinkControlUrl from './LinkControlUrl';
47
47
 
48
- export default {
49
- name: 'LinkControlDestination',
48
+ const destinationTypes = [
49
+ { id: LinkDestinations.URL, title: 'URL' },
50
+ { id: LinkDestinations.BLOCK, title: 'Page Block' }
51
+ ];
50
52
 
51
- destinationTypes: [
52
- { id: LinkDestinations.URL, title: 'URL' },
53
- { id: LinkDestinations.BLOCK, title: 'Page Block' }
54
- ],
55
-
56
- components: {
57
- LinkControlPageBlock,
58
- LinkControlUrl,
59
- FieldLabel,
60
- DropdownOption,
61
- Dropdown
53
+ const props = defineProps({
54
+ link: {
55
+ type: Object,
56
+ required: true
62
57
  },
63
58
 
64
- props: {
65
- link: {
66
- type: Object,
67
- required: true
68
- },
69
-
70
- validator: {
71
- type: Object,
72
- required: true
73
- }
74
- },
59
+ validator: {
60
+ type: Object,
61
+ required: true
62
+ }
63
+ });
75
64
 
76
- setup(props, { emit }) {
77
- const link = toRef(props, 'link');
78
- const isURLDestination = computed(() => link.value.currentDestination.value.id === LinkDestinations.URL);
79
- const isTargetBlank = computed(() => link.value.linkData.value.target === LinkTargets.BLANK);
65
+ const emit = defineEmits(['reset-errors']);
80
66
 
81
- const changeDestination = (value) => {
82
- emit('reset-errors');
83
- link.value.currentDestination.value.id = value;
84
- if (!isURLDestination.value) link.value.target = LinkTargets.SELF;
67
+ const link = toRef(props, 'link');
68
+ const isURLDestination = computed(() => link.value.currentDestination.value.id === LinkDestinations.URL);
69
+ const isTargetBlank = computed(() => link.value.linkData.value.target === LinkTargets.BLANK);
85
70
 
86
- link.value.destinationHrefs.value.url = '';
87
- };
71
+ const changeDestination = (value) => {
72
+ emit('reset-errors');
73
+ link.value.currentDestination.value.id = value;
74
+ if (!isURLDestination.value) link.value.target = LinkTargets.SELF;
88
75
 
89
- const updateLink = (value) => {
90
- emit('reset-errors');
76
+ link.value.destinationHrefs.value.url = '';
77
+ };
91
78
 
92
- link.value.updateLink(value);
93
- };
79
+ const updateLink = (value) => {
80
+ emit('reset-errors');
94
81
 
95
- return {
96
- isTargetBlank,
97
- isURLDestination,
98
- changeDestination,
99
- updateLink
100
- };
101
- }
82
+ link.value.updateLink(value);
102
83
  };
103
84
  </script>
@@ -21,34 +21,26 @@
21
21
  </div>
22
22
  </template>
23
23
 
24
- <script>
24
+ <script setup>
25
25
  import { inject } from 'vue';
26
26
  import { FieldLabel, DropdownOption, Dropdown } from '../../../../base';
27
27
  import { InjectionTokens } from '../../../../../injectionTokens';
28
28
 
29
- export default {
30
- name: 'LinkControlPageBlock',
31
-
32
- components: { DropdownOption, Dropdown, FieldLabel },
33
-
34
- props: {
35
- value: {
36
- type: Number,
37
- required: true
38
- }
39
- },
29
+ defineProps({
30
+ value: {
31
+ type: Number,
32
+ required: true
33
+ }
34
+ });
40
35
 
41
- setup(_, { emit }) {
42
- const pageBlocks = inject(InjectionTokens.PAGE_BLOCKS);
36
+ const emit = defineEmits(['update']);
43
37
 
44
- const applyBlock = (id) => {
45
- const block = pageBlocks.value.find((block) => block.id === id);
38
+ const pageBlocks = inject(InjectionTokens.PAGE_BLOCKS);
46
39
 
47
- emit('update', block.id);
48
- };
40
+ const applyBlock = (id) => {
41
+ const block = pageBlocks.value.find((block) => block.id === id);
49
42
 
50
- return { pageBlocks, applyBlock };
51
- }
43
+ emit('update', block.id);
52
44
  };
53
45
  </script>
54
46