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