@zipify/wysiwyg 1.0.0-dev.9 → 1.0.0-dev.90
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 +26014 -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 +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 +68 -34
- 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 +15 -2
- 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 +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 +22 -8
- package/lib/extensions/BackgroundColor.js +15 -7
- package/lib/extensions/DeviceManager.js +2 -5
- package/lib/extensions/FontColor.js +15 -7
- package/lib/extensions/FontFamily.js +26 -9
- package/lib/extensions/FontSize.js +33 -13
- package/lib/extensions/FontStyle.js +24 -14
- package/lib/extensions/FontWeight.js +25 -15
- package/lib/extensions/LineHeight.js +33 -29
- package/lib/extensions/Link.js +90 -0
- package/lib/extensions/StylePreset.js +20 -19
- package/lib/extensions/Superscript.js +5 -1
- package/lib/extensions/TextDecoration.js +46 -13
- 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 +1 -1
- 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 +5 -4
- 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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { shallowMount } from '@vue/test-utils';
|
|
2
|
-
import { ref, h, nextTick } from '
|
|
2
|
+
import { ref, h, nextTick } from 'vue';
|
|
3
3
|
import { InjectionTokens } from '../../../../injectionTokens';
|
|
4
4
|
import { Alignments } from '../../../../enums';
|
|
5
5
|
import { Button, Icon, Modal } from '../../../base';
|
|
@@ -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 { ColorPicker } from '../../../base';
|
|
5
5
|
import BackgroundColorControl from '../BackgroundColorControl';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { shallowMount } from '@vue/test-utils';
|
|
2
|
-
import { h } from '
|
|
2
|
+
import { h } from 'vue';
|
|
3
3
|
import { InjectionTokens } from '../../../../injectionTokens';
|
|
4
4
|
import { Dropdown } from '../../../base';
|
|
5
5
|
import CaseStyleControl from '../CaseStyleControl';
|
|
@@ -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 { ColorPicker } from '../../../base';
|
|
5
5
|
import FontColorControl from '../FontColorControl';
|
|
@@ -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 } from '../../../base';
|
|
5
5
|
import FontFamilyControl from '../FontFamilyControl';
|
|
@@ -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 { Dropdown } from '../../../base';
|
|
5
5
|
import FontSizeControl from '../FontSizeControl';
|
|
@@ -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 { Dropdown } from '../../../base';
|
|
5
5
|
import FontWeightControl from '../FontWeightControl';
|
|
@@ -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 ItalicControl from '../ItalicControl';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { shallowMount } from '@vue/test-utils';
|
|
2
|
-
import { h, nextTick, ref } from '
|
|
2
|
+
import { h, nextTick, ref } from 'vue';
|
|
3
3
|
import { InjectionTokens } from '../../../../injectionTokens';
|
|
4
4
|
import { Button, Modal, NumberField, Range } from '../../../base';
|
|
5
5
|
import LineHeightControl from '../LineHeightControl';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { shallowMount } from '@vue/test-utils';
|
|
2
|
-
import { h, ref } from '
|
|
2
|
+
import { h, ref, nextTick } from 'vue';
|
|
3
3
|
import { InjectionTokens } from '../../../../injectionTokens';
|
|
4
|
-
import { Dropdown, Icon } from '../../../base';
|
|
4
|
+
import { Button, Dropdown, Icon } from '../../../base';
|
|
5
5
|
import ListControl from '../ListControl';
|
|
6
6
|
import { ListTypes } from '../../../../enums';
|
|
7
7
|
|
|
@@ -62,10 +62,15 @@ describe('selection value', () => {
|
|
|
62
62
|
expect(iconWrapper.props('name')).toBe('list-disc');
|
|
63
63
|
});
|
|
64
64
|
|
|
65
|
-
test('should render type icon', () => {
|
|
65
|
+
test('should render type icon', async () => {
|
|
66
66
|
const editor = createEditor({ listType: ListTypes.DECIMAL });
|
|
67
67
|
const wrapper = createComponent({ editor });
|
|
68
68
|
const iconWrapper = wrapper.findComponent(Icon);
|
|
69
|
+
const dropdownWrapper = wrapper.findComponent(Dropdown);
|
|
70
|
+
|
|
71
|
+
dropdownWrapper.vm.$emit('change', ListTypes.DECIMAL);
|
|
72
|
+
|
|
73
|
+
await nextTick();
|
|
69
74
|
|
|
70
75
|
expect(iconWrapper.props('name')).toBe('list-decimal');
|
|
71
76
|
});
|
|
@@ -79,4 +84,14 @@ describe('selection value', () => {
|
|
|
79
84
|
|
|
80
85
|
expect(editor.commands.applyList).toHaveBeenCalledWith(ListTypes.LATIN);
|
|
81
86
|
});
|
|
87
|
+
|
|
88
|
+
test('should apply list with default type', () => {
|
|
89
|
+
const editor = createEditor();
|
|
90
|
+
const wrapper = createComponent({ editor });
|
|
91
|
+
const buttonWrapper = wrapper.findComponent(Button);
|
|
92
|
+
|
|
93
|
+
buttonWrapper.vm.$emit('click');
|
|
94
|
+
|
|
95
|
+
expect(editor.commands.applyList).toHaveBeenCalledWith(ListTypes.DISC);
|
|
96
|
+
});
|
|
82
97
|
});
|
|
@@ -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,8 +1,9 @@
|
|
|
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';
|
|
6
|
+
import { TextSettings } from '../../../../enums';
|
|
6
7
|
|
|
7
8
|
const createEditor = ({ presets, preset, customization } = {}) => ({
|
|
8
9
|
commands: {
|
|
@@ -12,6 +13,10 @@ const createEditor = ({ presets, preset, customization } = {}) => ({
|
|
|
12
13
|
getPresetCustomization: () => ref(customization || { attributes: [], marks: [] }),
|
|
13
14
|
applyPreset: jest.fn().mockReturnThis(),
|
|
14
15
|
removePresetCustomization: jest.fn().mockReturnThis(),
|
|
16
|
+
storeSelection: jest.fn().mockReturnThis(),
|
|
17
|
+
restoreSelection: jest.fn().mockReturnThis(),
|
|
18
|
+
expandSelectionToBlock: jest.fn().mockReturnThis(),
|
|
19
|
+
unsetMarks: jest.fn().mockReturnThis(),
|
|
15
20
|
run: jest.fn()
|
|
16
21
|
},
|
|
17
22
|
|
|
@@ -114,6 +119,17 @@ describe('apply preset', () => {
|
|
|
114
119
|
|
|
115
120
|
expect(editor.commands.applyPreset).toHaveBeenCalledWith('regular-1');
|
|
116
121
|
});
|
|
122
|
+
|
|
123
|
+
test('should remove settings on preset change', () => {
|
|
124
|
+
const editor = createEditor();
|
|
125
|
+
const wrapper = createComponent({ editor });
|
|
126
|
+
const dropdownWrapper = wrapper.findComponent(Dropdown);
|
|
127
|
+
|
|
128
|
+
dropdownWrapper.vm.$emit('change', 'regular-1');
|
|
129
|
+
|
|
130
|
+
expect(editor.commands.expandSelectionToBlock).toHaveBeenCalled();
|
|
131
|
+
expect(editor.commands.unsetMarks).toHaveBeenCalledWith([TextSettings.FONT_SIZE, TextSettings.FONT_WEIGHT]);
|
|
132
|
+
});
|
|
117
133
|
});
|
|
118
134
|
|
|
119
135
|
describe('remove customization', () => {
|
|
@@ -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,160 @@
|
|
|
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="updateLinkText"
|
|
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 { LinkDestinations } from '../../../../enums';
|
|
36
|
+
import { InjectionTokens } from '../../../../injectionTokens';
|
|
37
|
+
import { tooltip } from '../../../../directives';
|
|
38
|
+
import { useValidator } from '../../../base/composables';
|
|
39
|
+
import { Button, Icon, Modal, TextField, useModalToggler } from '../../../base';
|
|
40
|
+
import LinkControlHeader from './LinkControlHeader';
|
|
41
|
+
import LinkControlApply from './LinkControlApply';
|
|
42
|
+
import { useLink } from './composables';
|
|
43
|
+
import { LinkControlDestination } from './destination';
|
|
44
|
+
|
|
45
|
+
export default {
|
|
46
|
+
name: 'LinkControl',
|
|
47
|
+
|
|
48
|
+
components: {
|
|
49
|
+
LinkControlDestination,
|
|
50
|
+
LinkControlApply,
|
|
51
|
+
LinkControlHeader,
|
|
52
|
+
TextField,
|
|
53
|
+
Modal,
|
|
54
|
+
Icon,
|
|
55
|
+
Button
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
directives: {
|
|
59
|
+
tooltip
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
setup() {
|
|
63
|
+
const wrapperRef = ref(null);
|
|
64
|
+
const modalRef = ref(null);
|
|
65
|
+
|
|
66
|
+
const editor = inject(InjectionTokens.EDITOR);
|
|
67
|
+
|
|
68
|
+
const link = useLink();
|
|
69
|
+
const urlRegExp = /^(https:\/\/www\.|https:\/\/)?[a-z0-9]+([-.]{1}[a-z0-9]+)*\.[a-z]{2,100}(:[0-9]{1,5})?(\/.*)?$/i;
|
|
70
|
+
|
|
71
|
+
const isEmpty = () => {
|
|
72
|
+
return link.linkData.value.text ? false : 'Can\'t be empty';
|
|
73
|
+
};
|
|
74
|
+
const isUrl = () => {
|
|
75
|
+
if (link.currentDestination.value.id !== LinkDestinations.URL) return false;
|
|
76
|
+
|
|
77
|
+
const href = link.destinationHrefs.value.url;
|
|
78
|
+
const isValidUrl = href.startsWith('/') || urlRegExp.test(href);
|
|
79
|
+
|
|
80
|
+
return isValidUrl ? false : 'Please enter a valid URL';
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const nameValidator = useValidator({
|
|
84
|
+
validations: [isEmpty]
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const urlValidator = useValidator({
|
|
88
|
+
validations: [isUrl]
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
const resetErrors = () => {
|
|
92
|
+
nameValidator.reset();
|
|
93
|
+
urlValidator.reset();
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const onBeforeOpened = () => {
|
|
97
|
+
editor.commands.extendMarkRange('link');
|
|
98
|
+
resetErrors();
|
|
99
|
+
link.prepareInitialFields();
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const toggler = useModalToggler({
|
|
103
|
+
onBeforeOpened: () => onBeforeOpened(),
|
|
104
|
+
wrapperRef,
|
|
105
|
+
modalRef
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
const isActive = computed(() => toggler.isOpened.value || editor.isActive('link'));
|
|
109
|
+
|
|
110
|
+
const updateLinkText = (value) => {
|
|
111
|
+
resetErrors();
|
|
112
|
+
link.updateText(value);
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const applyLink = () => {
|
|
116
|
+
urlValidator.validate();
|
|
117
|
+
nameValidator.validate();
|
|
118
|
+
|
|
119
|
+
if (urlValidator.error.value || nameValidator.error.value) return;
|
|
120
|
+
|
|
121
|
+
link.apply();
|
|
122
|
+
toggler.close();
|
|
123
|
+
link.resetDestinations();
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const removeLink = () => {
|
|
127
|
+
link.removeLink();
|
|
128
|
+
toggler.close();
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
return {
|
|
132
|
+
wrapperRef,
|
|
133
|
+
modalRef,
|
|
134
|
+
link,
|
|
135
|
+
toggler,
|
|
136
|
+
isActive,
|
|
137
|
+
nameValidator,
|
|
138
|
+
urlValidator,
|
|
139
|
+
updateLinkText,
|
|
140
|
+
resetErrors,
|
|
141
|
+
applyLink,
|
|
142
|
+
removeLink
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
</script>
|
|
147
|
+
|
|
148
|
+
<style scoped>
|
|
149
|
+
.zw-link-modal {
|
|
150
|
+
width: 266px;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
.zw-link-modal__body {
|
|
154
|
+
padding: var(--zw-offset-sm);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
::v-deep .zw-link-modal-dropdown__option {
|
|
158
|
+
width: 234px;
|
|
159
|
+
}
|
|
160
|
+
</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,69 @@
|
|
|
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, 0.1s color ease-out;
|
|
57
|
+
will-change: opacity, color;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.zw-link-modal-header__unlink-button:disabled {
|
|
61
|
+
opacity: 0.35;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.zw-link-modal-header__unlink-button:focus,
|
|
65
|
+
.zw-link-modal-header__unlink-button:focus-within,
|
|
66
|
+
.zw-link-modal-header__unlink-button:hover {
|
|
67
|
+
color: rgb(var(--zw-color-white));
|
|
68
|
+
}
|
|
69
|
+
</style>
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { shallowMount } from '@vue/test-utils';
|
|
2
|
+
import { ref, nextTick } from 'vue';
|
|
3
|
+
import LinkControl from '../LinkControl';
|
|
4
|
+
import { InjectionTokens } from '../../../../../injectionTokens';
|
|
5
|
+
import { Button, TextField } from '../../../../base';
|
|
6
|
+
import LinkControlApply from '../LinkControlApply';
|
|
7
|
+
import { LinkControlDestination } from '../destination';
|
|
8
|
+
|
|
9
|
+
const createEditor = (isActive) => ({
|
|
10
|
+
isActive: () => isActive ?? false
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
function createComponent({ editor }) {
|
|
14
|
+
return shallowMount(LinkControl, {
|
|
15
|
+
provide: {
|
|
16
|
+
[InjectionTokens.EDITOR]: editor,
|
|
17
|
+
[InjectionTokens.PAGE_BLOCKS]: ref([{ id: 1 }])
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
describe('selection value', () => {
|
|
23
|
+
test('should render link status', () => {
|
|
24
|
+
const editor = createEditor(true );
|
|
25
|
+
const wrapper = createComponent({ editor });
|
|
26
|
+
const buttonWrapper = wrapper.findComponent(Button);
|
|
27
|
+
|
|
28
|
+
expect(buttonWrapper.props('active')).toBe(true);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('validation', () => {
|
|
33
|
+
test('should show error on apply', async () => {
|
|
34
|
+
const editor = createEditor(true );
|
|
35
|
+
const wrapper = createComponent({ editor });
|
|
36
|
+
const textFieldWrapper = wrapper.findComponent(TextField);
|
|
37
|
+
const linkControlDestinationWrapper = wrapper.findComponent(LinkControlDestination);
|
|
38
|
+
const applyWrapper = wrapper.findComponent(LinkControlApply);
|
|
39
|
+
|
|
40
|
+
applyWrapper.vm.$emit('apply');
|
|
41
|
+
await nextTick();
|
|
42
|
+
|
|
43
|
+
expect(textFieldWrapper.props('error')).toBe('Can\'t be empty');
|
|
44
|
+
expect(linkControlDestinationWrapper.props('validator').error.value).toBe('Please enter a valid URL');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('should reset errors on input', async () => {
|
|
48
|
+
const editor = createEditor(true );
|
|
49
|
+
const wrapper = createComponent({ editor });
|
|
50
|
+
const textFieldWrapper = wrapper.findComponent(TextField);
|
|
51
|
+
const linkControlDestinationWrapper = wrapper.findComponent(LinkControlDestination);
|
|
52
|
+
const applyWrapper = wrapper.findComponent(LinkControlApply);
|
|
53
|
+
|
|
54
|
+
applyWrapper.vm.$emit('apply');
|
|
55
|
+
textFieldWrapper.vm.$emit('input', 'hello');
|
|
56
|
+
|
|
57
|
+
await nextTick();
|
|
58
|
+
|
|
59
|
+
expect(textFieldWrapper.props('error')).toBeNull();
|
|
60
|
+
expect(linkControlDestinationWrapper.props('validator').error.value).toBeNull();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('should reset errors on change destination', async () => {
|
|
64
|
+
const editor = createEditor(true );
|
|
65
|
+
const wrapper = createComponent({ editor });
|
|
66
|
+
const textFieldWrapper = wrapper.findComponent(TextField);
|
|
67
|
+
const linkControlDestinationWrapper = wrapper.findComponent(LinkControlDestination);
|
|
68
|
+
const applyWrapper = wrapper.findComponent(LinkControlApply);
|
|
69
|
+
|
|
70
|
+
applyWrapper.vm.$emit('apply');
|
|
71
|
+
linkControlDestinationWrapper.vm.$emit('reset-errors');
|
|
72
|
+
|
|
73
|
+
await nextTick();
|
|
74
|
+
|
|
75
|
+
expect(textFieldWrapper.props('error')).toBeNull();
|
|
76
|
+
expect(linkControlDestinationWrapper.props('validator').error.value).toBeNull();
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { shallowMount } from '@vue/test-utils';
|
|
2
|
+
import { InjectionTokens } from '../../../../../injectionTokens';
|
|
3
|
+
import { Button } from '../../../../base';
|
|
4
|
+
import LinkControlHeader from '../LinkControlHeader';
|
|
5
|
+
|
|
6
|
+
const createEditor = (isActive) => ({
|
|
7
|
+
isActive: () => isActive ?? false
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
function createComponent({ editor }) {
|
|
11
|
+
return shallowMount(LinkControlHeader, {
|
|
12
|
+
provide: { [InjectionTokens.EDITOR]: editor }
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
describe('rendering unlink button', () => {
|
|
17
|
+
test('should button be disabled when no link', () => {
|
|
18
|
+
const editor = createEditor(true );
|
|
19
|
+
const wrapper = createComponent({ editor });
|
|
20
|
+
const buttonWrapper = wrapper.findComponent(Button);
|
|
21
|
+
|
|
22
|
+
expect(buttonWrapper.props('disabled')).toBe(false);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('should button be enabled when link selected', () => {
|
|
26
|
+
const editor = createEditor(false );
|
|
27
|
+
const wrapper = createComponent({ editor });
|
|
28
|
+
const buttonWrapper = wrapper.findComponent(Button);
|
|
29
|
+
|
|
30
|
+
expect(buttonWrapper.props('disabled')).toBe(true);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('should send unlink event', () => {
|
|
34
|
+
const editor = createEditor(true );
|
|
35
|
+
const wrapper = createComponent({ editor });
|
|
36
|
+
const buttonWrapper = wrapper.findComponent(Button);
|
|
37
|
+
|
|
38
|
+
buttonWrapper.vm.$emit('click');
|
|
39
|
+
|
|
40
|
+
expect(wrapper.emitted('remove-link')).toBeTruthy();
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`actions with link should reset destination 1`] = `
|
|
4
|
+
Object {
|
|
5
|
+
"block": 1,
|
|
6
|
+
"url": "",
|
|
7
|
+
}
|
|
8
|
+
`;
|
|
9
|
+
|
|
10
|
+
exports[`init link should prepare initial fields 1`] = `
|
|
11
|
+
Object {
|
|
12
|
+
"block": 1,
|
|
13
|
+
"url": "",
|
|
14
|
+
}
|
|
15
|
+
`;
|