@zipify/wysiwyg 1.0.0-dev.9 → 1.0.0-dev.92
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +1 -1
- package/.eslintrc.js +2 -2
- package/.github/dependabot.yaml +1 -0
- package/.lintstagedrc +2 -2
- package/.release-it.json +3 -1
- package/.stylelintrc +0 -4
- package/README.md +2 -2
- package/config/jest/setupTests.js +0 -3
- package/config/vite/example.config.js +25 -0
- package/config/vite/lib.config.js +30 -0
- package/config/{webpack → vite}/settings.js +0 -0
- package/dist/wysiwyg.css +404 -373
- package/dist/wysiwyg.mjs +26015 -0
- package/example/ExampleApp.vue +35 -4
- package/example/example.js +0 -3
- package/example/{example.html → index.html} +1 -0
- package/example/pageBlocks.js +31 -0
- package/example/presets.js +2 -2
- package/example/tooltip/Tooltip.js +1 -1
- package/jest.config.js +3 -1
- package/lib/Wysiwyg.vue +73 -14
- package/lib/__tests__/utils/index.js +0 -1
- package/lib/__tests__/utils/withComponentContext.js +1 -1
- package/lib/assets/icons/background-color.svg +3 -1
- package/lib/assets/icons/font-color.svg +1 -3
- package/lib/assets/icons/link.svg +3 -0
- package/lib/assets/icons/unlink.svg +3 -0
- package/lib/components/base/Button.vue +23 -2
- package/lib/components/base/Checkbox.vue +89 -0
- package/lib/components/base/FieldLabel.vue +2 -1
- package/lib/components/base/Icon.vue +3 -3
- 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 +1 -3
- package/lib/components/base/TextField.vue +108 -0
- package/lib/components/base/__tests__/Modal.test.js +7 -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 +14 -12
- package/lib/components/base/colorPicker/composables/__tests__/usePickerApi.test.js +6 -6
- package/lib/components/base/colorPicker/composables/usePickerApi.js +15 -8
- 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/__tests__/useValidator.test.js +44 -0
- 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 +6 -2
- 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 +23 -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 +51 -9
- package/lib/components/toolbar/ToolbarDivider.vue +1 -1
- package/lib/components/toolbar/ToolbarFull.vue +41 -10
- package/lib/components/toolbar/ToolbarRow.vue +1 -0
- package/lib/components/toolbar/__tests__/Toolbar.test.js +6 -0
- 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 +2 -2
- 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 +70 -36
- 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 +17 -4
- package/lib/components/toolbar/controls/SuperscriptControl.vue +1 -1
- package/lib/components/toolbar/controls/UnderlineControl.vue +1 -1
- 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 +18 -3
- package/lib/components/toolbar/controls/__tests__/StrikeThroughControl.test.js +1 -1
- package/lib/components/toolbar/controls/__tests__/StylePresetControl.test.js +17 -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 +160 -0
- package/lib/components/toolbar/controls/link/LinkControlApply.vue +35 -0
- package/lib/components/toolbar/controls/link/LinkControlHeader.vue +69 -0
- package/lib/components/toolbar/controls/link/__tests__/LinkControl.test.js +79 -0
- package/lib/components/toolbar/controls/link/__tests__/LinkControlHeader.test.js +42 -0
- package/lib/components/toolbar/controls/link/composables/__tests__/__snapshots__/useLink.test.js.snap +15 -0
- package/lib/components/toolbar/controls/link/composables/__tests__/useLink.test.js +172 -0
- package/lib/components/toolbar/controls/link/composables/index.js +1 -0
- package/lib/components/toolbar/controls/link/composables/useLink.js +82 -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/__tests__/LinkControlPageBlock.test.js +36 -0
- package/lib/components/toolbar/controls/link/destination/__tests__/LinkControlUrl.test.js +46 -0
- package/lib/components/toolbar/controls/link/destination/__tests__/__snapshots__/LinkControlPageBlock.test.js.snap +9 -0
- package/lib/components/toolbar/controls/link/destination/__tests__/__snapshots__/LinkControlUrl.test.js.snap +17 -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__/__snapshots__/useEditor.test.js.snap +1 -0
- package/lib/composables/__tests__/useEditor.test.js +5 -4
- package/lib/composables/useEditor.js +12 -9
- package/lib/composables/useToolbar.js +26 -19
- package/lib/directives/__tests__/outClick.test.js +6 -0
- package/lib/directives/outClick.js +19 -6
- package/lib/enums/Alignments.js +10 -1
- 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 +25 -11
- package/lib/extensions/BackgroundColor.js +15 -7
- package/lib/extensions/DeviceManager.js +2 -5
- package/lib/extensions/FontColor.js +17 -9
- package/lib/extensions/FontFamily.js +30 -13
- package/lib/extensions/FontSize.js +38 -18
- package/lib/extensions/FontStyle.js +30 -20
- package/lib/extensions/FontWeight.js +34 -23
- package/lib/extensions/LineHeight.js +36 -32
- package/lib/extensions/Link.js +92 -0
- package/lib/extensions/StylePreset.js +23 -22
- package/lib/extensions/Superscript.js +5 -1
- package/lib/extensions/TextDecoration.js +52 -19
- package/lib/extensions/__tests__/Alignment.test.js +14 -9
- package/lib/extensions/__tests__/BackgroundColor.test.js +13 -8
- package/lib/extensions/__tests__/CaseStyle.test.js +4 -7
- package/lib/extensions/__tests__/FontColor.test.js +13 -8
- package/lib/extensions/__tests__/FontFamily.test.js +34 -10
- package/lib/extensions/__tests__/FontSize.test.js +16 -10
- package/lib/extensions/__tests__/FontStyle.test.js +13 -8
- package/lib/extensions/__tests__/FontWeight.test.js +21 -8
- package/lib/extensions/__tests__/LineHeight.test.js +25 -14
- package/lib/extensions/__tests__/Link.test.js +101 -0
- package/lib/extensions/__tests__/StylePreset.test.js +72 -10
- package/lib/extensions/__tests__/TextDecoration.test.js +53 -8
- package/lib/extensions/__tests__/__snapshots__/Alignment.test.js.snap +26 -2
- package/lib/extensions/__tests__/__snapshots__/BackgroundColor.test.js.snap +30 -1
- package/lib/extensions/__tests__/__snapshots__/FontColor.test.js.snap +18 -1
- package/lib/extensions/__tests__/__snapshots__/FontFamily.test.js.snap +88 -1
- package/lib/extensions/__tests__/__snapshots__/FontSize.test.js.snap +33 -2
- package/lib/extensions/__tests__/__snapshots__/FontStyle.test.js.snap +25 -4
- package/lib/extensions/__tests__/__snapshots__/FontWeight.test.js.snap +47 -1
- package/lib/extensions/__tests__/__snapshots__/LineHeight.test.js.snap +26 -2
- package/lib/extensions/__tests__/__snapshots__/Link.test.js.snap +225 -0
- package/lib/extensions/__tests__/__snapshots__/StylePreset.test.js.snap +6 -2
- package/lib/extensions/__tests__/__snapshots__/TextDecoration.test.js.snap +183 -3
- package/lib/extensions/core/CopyPasteProcessor.js +10 -0
- package/lib/extensions/core/NodeProcessor.js +2 -2
- package/lib/extensions/core/TextProcessor.js +11 -24
- package/lib/extensions/core/__tests__/NodeProcessor.test.js +4 -7
- package/lib/extensions/core/__tests__/SelectionProcessor.test.js +4 -7
- package/lib/extensions/core/__tests__/TextProcessor.test.js +139 -14
- 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 +57 -0
- package/lib/extensions/core/plugins/ProseMirrorPlugin.js +20 -0
- package/lib/extensions/core/plugins/index.js +1 -0
- package/lib/extensions/index.js +46 -34
- package/lib/extensions/list/List.js +7 -6
- package/lib/extensions/list/__tests__/List.test.js +6 -10
- package/lib/extensions/list/__tests__/__snapshots__/List.test.js.snap +60 -20
- package/lib/index.js +3 -0
- package/lib/injectionTokens.js +3 -1
- package/lib/services/ContentNormalizer.js +144 -28
- package/lib/services/ContextWidnow.js +23 -0
- package/lib/{__tests__/utils → services}/NodeFactory.js +5 -1
- package/lib/services/__tests__/ContentNormalizer.test.js +124 -8
- package/lib/services/__tests__/FavoriteColors.test.js +1 -1
- package/lib/services/index.js +2 -0
- package/lib/styles/content.css +108 -13
- 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__/convertAlignment.test.js +16 -0
- package/lib/utils/__tests__/convertFontSize.test.js +21 -0
- package/lib/utils/__tests__/convertLineHeight.test.js +21 -0
- package/lib/utils/convertAlignment.js +12 -0
- package/lib/utils/convertColor.js +1 -1
- package/lib/utils/convertFontSize.js +8 -0
- package/lib/utils/convertLineHeight.js +17 -0
- package/lib/utils/importIcon.js +7 -6
- package/lib/utils/index.js +4 -0
- package/lib/utils/isWysiwygContent.js +12 -0
- package/lib/utils/renderInlineSetting.js +1 -1
- package/package.json +26 -30
- package/config/webpack/example.config.js +0 -88
- package/config/webpack/lib.config.js +0 -44
- package/config/webpack/loaders/index.js +0 -6
- package/config/webpack/loaders/js-loader.js +0 -5
- package/config/webpack/loaders/style-loader.js +0 -9
- package/config/webpack/loaders/svg-loader.js +0 -4
- package/config/webpack/loaders/vue-loader.js +0 -4
- package/dist/wysiwyg.js +0 -2
- package/dist/wysiwyg.js.LICENSE.txt +0 -1
- package/lib/extensions/core/inputRules/closeDoubleQuote.js +0 -6
- package/lib/extensions/core/inputRules/closeSingleQuote.js +0 -6
- package/lib/extensions/core/inputRules/copyright.js +0 -6
- package/lib/extensions/core/inputRules/ellipsis.js +0 -6
- package/lib/extensions/core/inputRules/emDash.js +0 -6
- package/lib/extensions/core/inputRules/index.js +0 -9
- package/lib/extensions/core/inputRules/openDoubleQuote.js +0 -6
- package/lib/extensions/core/inputRules/openSingleQuote.js +0 -6
- package/lib/extensions/core/inputRules/registeredTrademark.js +0 -6
- package/lib/extensions/core/inputRules/trademark.js +0 -6
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { ref } from 'vue';
|
|
2
|
+
import { withComponentContext } from '../../../../../../__tests__/utils';
|
|
3
|
+
import { InjectionTokens } from '../../../../../../injectionTokens';
|
|
4
|
+
import { LinkDestinations, LinkTargets } from '../../../../../../enums';
|
|
5
|
+
import { useLink } from '../useLink';
|
|
6
|
+
|
|
7
|
+
const createEditor = (text, destination) => ({
|
|
8
|
+
commands: {
|
|
9
|
+
storeSelection: jest.fn(),
|
|
10
|
+
restoreSelection: jest.fn(),
|
|
11
|
+
getSelectedText: jest.fn(() => text ?? ''),
|
|
12
|
+
focus: jest.fn().mockReturnThis(),
|
|
13
|
+
unsetLink: jest.fn().mockReturnThis(),
|
|
14
|
+
applyLink: jest.fn().mockReturnThis(),
|
|
15
|
+
run: jest.fn()
|
|
16
|
+
},
|
|
17
|
+
|
|
18
|
+
chain() {
|
|
19
|
+
return this.commands;
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
getAttributes: jest.fn(() => ({
|
|
23
|
+
destination: destination ?? null
|
|
24
|
+
}))
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
function useComposable(text, destination) {
|
|
28
|
+
return withComponentContext(() => useLink(), {
|
|
29
|
+
provide: {
|
|
30
|
+
[InjectionTokens.EDITOR]: createEditor(text, destination),
|
|
31
|
+
[InjectionTokens.PAGE_BLOCKS]: ref([{ id: 1 }, { id: 2 }])
|
|
32
|
+
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
describe('init link', () => {
|
|
38
|
+
test('should prepare initial fields', () => {
|
|
39
|
+
const link = useComposable();
|
|
40
|
+
|
|
41
|
+
link.prepareInitialFields();
|
|
42
|
+
|
|
43
|
+
expect(link.currentDestination.value.id).toBe(LinkDestinations.URL);
|
|
44
|
+
expect(link.linkData.value.target).toBe(LinkTargets.SELF);
|
|
45
|
+
expect(link.destinationHrefs.value).toMatchSnapshot();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test('should take text from selection', () => {
|
|
49
|
+
const link = useComposable('hello world');
|
|
50
|
+
|
|
51
|
+
link.prepareInitialFields();
|
|
52
|
+
|
|
53
|
+
expect(link.linkData.value.text).toBe('hello world');
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe('actions with link', () => {
|
|
58
|
+
test('should update url', () => {
|
|
59
|
+
const link = useComposable('hello world');
|
|
60
|
+
|
|
61
|
+
link.updateLink('https://hello.world');
|
|
62
|
+
|
|
63
|
+
expect(link.destinationHrefs.value.url).toBe('https://hello.world');
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test('should update block destination', () => {
|
|
67
|
+
const link = useComposable('hello world', LinkDestinations.BLOCK);
|
|
68
|
+
|
|
69
|
+
link.prepareInitialFields();
|
|
70
|
+
link.updateLink('3456');
|
|
71
|
+
|
|
72
|
+
expect(link.destinationHrefs.value.block).toBe('3456');
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test('should remove link', () => {
|
|
76
|
+
const link = useComposable();
|
|
77
|
+
|
|
78
|
+
link.removeLink();
|
|
79
|
+
|
|
80
|
+
expect(link.editor.commands.unsetLink).toHaveBeenCalled();
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test('should apply link', () => {
|
|
84
|
+
const link = useComposable();
|
|
85
|
+
|
|
86
|
+
link.updateText('hello');
|
|
87
|
+
link.updateLink('/world');
|
|
88
|
+
|
|
89
|
+
link.apply();
|
|
90
|
+
|
|
91
|
+
expect(link.editor.commands.applyLink).toHaveBeenCalledWith({
|
|
92
|
+
destination: LinkDestinations.URL,
|
|
93
|
+
href: '/world',
|
|
94
|
+
target: LinkTargets.SELF,
|
|
95
|
+
text: 'hello'
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test('should apply link target', () => {
|
|
100
|
+
const link = useComposable();
|
|
101
|
+
|
|
102
|
+
link.updateTarget(false);
|
|
103
|
+
|
|
104
|
+
expect(link.linkData.value.target).toBe(LinkTargets.SELF);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test('should apply link target', () => {
|
|
108
|
+
const link = useComposable();
|
|
109
|
+
|
|
110
|
+
link.updateTarget(true);
|
|
111
|
+
|
|
112
|
+
expect(link.linkData.value.target).toBe(LinkTargets.BLANK);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test('should reset destination', () => {
|
|
116
|
+
const link = useComposable();
|
|
117
|
+
|
|
118
|
+
link.resetDestinations();
|
|
119
|
+
|
|
120
|
+
expect(link.destinationHrefs.value).toMatchSnapshot();
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
describe('format link', () => {
|
|
125
|
+
test('should format absolute link without href', () => {
|
|
126
|
+
const link = useComposable();
|
|
127
|
+
|
|
128
|
+
link.updateText('hello');
|
|
129
|
+
link.updateLink('world.com');
|
|
130
|
+
|
|
131
|
+
link.apply();
|
|
132
|
+
|
|
133
|
+
expect(link.editor.commands.applyLink).toHaveBeenCalledWith({
|
|
134
|
+
destination: LinkDestinations.URL,
|
|
135
|
+
href: 'https://world.com',
|
|
136
|
+
target: LinkTargets.SELF,
|
|
137
|
+
text: 'hello'
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test('should format absolute link with href', () => {
|
|
142
|
+
const link = useComposable();
|
|
143
|
+
|
|
144
|
+
link.updateText('hello');
|
|
145
|
+
link.updateLink('https://world.com');
|
|
146
|
+
|
|
147
|
+
link.apply();
|
|
148
|
+
|
|
149
|
+
expect(link.editor.commands.applyLink).toHaveBeenCalledWith({
|
|
150
|
+
destination: LinkDestinations.URL,
|
|
151
|
+
href: 'https://world.com',
|
|
152
|
+
target: LinkTargets.SELF,
|
|
153
|
+
text: 'hello'
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
test('should format relative link', () => {
|
|
158
|
+
const link = useComposable();
|
|
159
|
+
|
|
160
|
+
link.updateText('hello');
|
|
161
|
+
link.updateLink('/world/new');
|
|
162
|
+
|
|
163
|
+
link.apply();
|
|
164
|
+
|
|
165
|
+
expect(link.editor.commands.applyLink).toHaveBeenCalledWith({
|
|
166
|
+
destination: LinkDestinations.URL,
|
|
167
|
+
href: '/world/new',
|
|
168
|
+
target: LinkTargets.SELF,
|
|
169
|
+
text: 'hello'
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useLink } from './useLink';
|
|
@@ -0,0 +1,82 @@
|
|
|
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
|
+
linkData.value.target = editor.getAttributes('link').target || LinkTargets.SELF;
|
|
21
|
+
|
|
22
|
+
if (editor.getAttributes('link').href) {
|
|
23
|
+
destinationHrefs.value[currentDestination.value.id] = editor.getAttributes('link').href;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function resetDestinations() {
|
|
28
|
+
destinationHrefs.value.block = pageBlocks.value[0].id;
|
|
29
|
+
destinationHrefs.value.url = '';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function getFormattedHref() {
|
|
33
|
+
if (currentDestination.value.id === LinkDestinations.URL) {
|
|
34
|
+
const url = destinationHrefs.value.url;
|
|
35
|
+
const isRelative = !!url.startsWith('/');
|
|
36
|
+
const hasProtocol = /^https?:\/\/.+$/i.test(url);
|
|
37
|
+
|
|
38
|
+
return isRelative || hasProtocol ? url : `https://${url}`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return destinationHrefs.value[currentDestination.value.id];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function apply() {
|
|
45
|
+
editor
|
|
46
|
+
.chain()
|
|
47
|
+
.focus()
|
|
48
|
+
.applyLink({
|
|
49
|
+
href: getFormattedHref(),
|
|
50
|
+
text: linkData.value.text,
|
|
51
|
+
target: linkData.value.target,
|
|
52
|
+
destination: currentDestination.value.id
|
|
53
|
+
})
|
|
54
|
+
.run();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function removeLink() {
|
|
58
|
+
editor.chain().focus().unsetLink().run();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function updateLink(value) {
|
|
62
|
+
destinationHrefs.value[currentDestination.value.id] = value;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function updateText(text) {
|
|
66
|
+
linkData.value.text = text;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
editor,
|
|
71
|
+
linkData,
|
|
72
|
+
destinationHrefs,
|
|
73
|
+
currentDestination,
|
|
74
|
+
resetDestinations,
|
|
75
|
+
prepareInitialFields,
|
|
76
|
+
updateTarget,
|
|
77
|
+
updateLink,
|
|
78
|
+
apply,
|
|
79
|
+
removeLink,
|
|
80
|
+
updateText
|
|
81
|
+
};
|
|
82
|
+
}
|
|
@@ -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
|
+
@update-link="updateLink"
|
|
30
|
+
@update-target="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 === LinkDestinations.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('update-link', value);
|
|
47
|
+
const updateTarget = (value) => emit('update-target', value);
|
|
48
|
+
|
|
49
|
+
return { updateLink, updateTarget };
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
</script>
|
package/lib/components/toolbar/controls/link/destination/__tests__/LinkControlPageBlock.test.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ref, h } from 'vue';
|
|
2
|
+
import { shallowMount } from '@vue/test-utils';
|
|
3
|
+
import LinkControlPageBlock from '../LinkControlPageBlock';
|
|
4
|
+
import { InjectionTokens } from '../../../../../../injectionTokens';
|
|
5
|
+
import { Dropdown } from '../../../../../base';
|
|
6
|
+
|
|
7
|
+
function createComponent() {
|
|
8
|
+
return shallowMount(LinkControlPageBlock, {
|
|
9
|
+
propsData: {
|
|
10
|
+
value: 12
|
|
11
|
+
},
|
|
12
|
+
|
|
13
|
+
stubs: {
|
|
14
|
+
Dropdown: {
|
|
15
|
+
render: () => h('div'),
|
|
16
|
+
props: ['value']
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
|
|
20
|
+
provide: {
|
|
21
|
+
[InjectionTokens.PAGE_BLOCKS]: ref([{ id: 1 }, { id: 2 }])
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
describe('applying block', () => {
|
|
27
|
+
test('should apply block', () => {
|
|
28
|
+
const wrapper = createComponent();
|
|
29
|
+
|
|
30
|
+
const dropdownWrapper = wrapper.findComponent(Dropdown);
|
|
31
|
+
|
|
32
|
+
dropdownWrapper.vm.$emit('change', 2);
|
|
33
|
+
|
|
34
|
+
expect(wrapper.emitted('update')).toMatchSnapshot();
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ref, h } from 'vue';
|
|
2
|
+
import { shallowMount } from '@vue/test-utils';
|
|
3
|
+
import { Checkbox, TextField } from '../../../../../base';
|
|
4
|
+
import LinkControlUrl from '../LinkControlUrl';
|
|
5
|
+
|
|
6
|
+
function createComponent() {
|
|
7
|
+
return shallowMount(LinkControlUrl, {
|
|
8
|
+
propsData: {
|
|
9
|
+
validator: { error: ref({ value: null }) },
|
|
10
|
+
href: '',
|
|
11
|
+
isTargetBlank: false
|
|
12
|
+
},
|
|
13
|
+
|
|
14
|
+
stubs: {
|
|
15
|
+
TextField: {
|
|
16
|
+
render: () => h('div'),
|
|
17
|
+
props: ['value']
|
|
18
|
+
},
|
|
19
|
+
|
|
20
|
+
Checkbox: {
|
|
21
|
+
render: () => h('div'),
|
|
22
|
+
props: ['value']
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
describe('update link', () => {
|
|
29
|
+
test('should update link url', () => {
|
|
30
|
+
const wrapper = createComponent();
|
|
31
|
+
const textFieldWrapper = wrapper.findComponent(TextField);
|
|
32
|
+
|
|
33
|
+
textFieldWrapper.vm.$emit('input', 'Some text');
|
|
34
|
+
|
|
35
|
+
expect(wrapper.emitted('update-link')).toMatchSnapshot();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('should update link target', () => {
|
|
39
|
+
const wrapper = createComponent();
|
|
40
|
+
const textFieldWrapper = wrapper.findComponent(Checkbox);
|
|
41
|
+
|
|
42
|
+
textFieldWrapper.vm.$emit('input', true);
|
|
43
|
+
|
|
44
|
+
expect(wrapper.emitted('update-target')).toMatchSnapshot();
|
|
45
|
+
});
|
|
46
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`update link should update link target 1`] = `
|
|
4
|
+
Array [
|
|
5
|
+
Array [
|
|
6
|
+
true,
|
|
7
|
+
],
|
|
8
|
+
]
|
|
9
|
+
`;
|
|
10
|
+
|
|
11
|
+
exports[`update link should update link url 1`] = `
|
|
12
|
+
Array [
|
|
13
|
+
Array [
|
|
14
|
+
"Some text",
|
|
15
|
+
],
|
|
16
|
+
]
|
|
17
|
+
`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as LinkControlDestination } from './LinkControlDestination';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as LinkControl } from './LinkControl';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { h, toRef } from '
|
|
1
|
+
import { h, ref, 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
|
-
import { NodeFactory } from '../../
|
|
5
|
+
import { NodeFactory } from '../../services';
|
|
6
|
+
import { buildCoreExtensions } from '../../extensions/core';
|
|
7
7
|
|
|
8
8
|
const TestComponent = {
|
|
9
9
|
name: 'Test',
|
|
@@ -18,8 +18,9 @@ const TestComponent = {
|
|
|
18
18
|
|
|
19
19
|
setup(props, { emit }) {
|
|
20
20
|
const editor = useEditor({
|
|
21
|
+
isReadonlyRef: ref(false),
|
|
21
22
|
content: toRef(props, 'value'),
|
|
22
|
-
extensions:
|
|
23
|
+
extensions: buildCoreExtensions(),
|
|
23
24
|
onChange: (content) => emit('input', content),
|
|
24
25
|
onFocus: () => emit('focus')
|
|
25
26
|
});
|
|
@@ -1,27 +1,30 @@
|
|
|
1
1
|
import { Editor } from '@tiptap/vue-2';
|
|
2
|
-
import { onUnmounted, watch, reactive } from '
|
|
2
|
+
import { onUnmounted, watch, reactive } from 'vue';
|
|
3
3
|
import { ContentNormalizer } from '../services';
|
|
4
|
+
import { markWysiwygContent, unmarkWysiwygContent } from '../utils';
|
|
4
5
|
|
|
5
|
-
export function useEditor({ content, onChange, extensions }) {
|
|
6
|
-
const normalizer = new ContentNormalizer();
|
|
7
|
-
|
|
6
|
+
export function useEditor({ content, onChange, extensions, isReadonlyRef }) {
|
|
8
7
|
const editor = reactive(new Editor({
|
|
9
|
-
content:
|
|
10
|
-
onUpdate: () => onChange(editor.getJSON()),
|
|
11
|
-
extensions
|
|
8
|
+
content: ContentNormalizer.normalize(content.value),
|
|
9
|
+
onUpdate: () => onChange(markWysiwygContent(editor.getJSON())),
|
|
10
|
+
extensions,
|
|
11
|
+
injectCSS: false
|
|
12
12
|
}));
|
|
13
13
|
|
|
14
14
|
onUnmounted(() => editor.destroy());
|
|
15
15
|
|
|
16
16
|
watch(content, (value) => {
|
|
17
|
-
const
|
|
17
|
+
const content = unmarkWysiwygContent(value);
|
|
18
|
+
const isChanged = JSON.stringify(editor.getJSON()) !== JSON.stringify(content);
|
|
18
19
|
|
|
19
20
|
if (isChanged) {
|
|
20
|
-
const content =
|
|
21
|
+
const content = ContentNormalizer.normalize(value);
|
|
21
22
|
|
|
22
23
|
editor.commands.setContent(content, false);
|
|
23
24
|
}
|
|
24
25
|
});
|
|
25
26
|
|
|
27
|
+
watch(isReadonlyRef, (isReadonly) => editor.setEditable(!isReadonly), { immediate: true });
|
|
28
|
+
|
|
26
29
|
return editor;
|
|
27
30
|
}
|