@zipify/wysiwyg 1.0.0-dev.5 → 1.0.0-dev.52
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 -1
- package/.stylelintignore +1 -0
- package/.stylelintrc +0 -4
- package/README.md +2 -2
- package/config/jest/setupTests.js +4 -0
- 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 +1 -0
- package/dist/wysiwyg.mjs +18305 -0
- package/dist/wysiwyg.mjs.map +1 -0
- package/example/ExampleApp.vue +20 -1
- package/example/{example.html → index.html} +1 -0
- package/example/pageBlocks.js +31 -0
- package/example/presets.js +2 -2
- package/jest.config.js +3 -1
- package/lib/Wysiwyg.vue +50 -25
- package/lib/__tests__/utils/NodeFactory.js +13 -0
- 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 +21 -1
- package/lib/components/base/Checkbox.vue +89 -0
- package/lib/components/base/FieldLabel.vue +2 -1
- package/lib/components/base/Icon.vue +18 -10
- package/lib/components/base/Modal.vue +0 -1
- package/lib/components/base/NumberField.vue +1 -1
- package/lib/components/base/ScrollView.vue +0 -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 +6 -1
- 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/usePickerHotkeys.js +2 -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/useValidator.js +23 -0
- package/lib/components/base/dropdown/Dropdown.vue +15 -3
- package/lib/components/base/dropdown/DropdownActivator.vue +19 -3
- package/lib/components/base/index.js +3 -1
- package/lib/components/toolbar/Toolbar.vue +49 -9
- package/lib/components/toolbar/ToolbarFull.vue +10 -2
- package/lib/components/toolbar/__tests__/Toolbar.test.js +6 -0
- package/lib/components/toolbar/controls/FontSizeControl.vue +7 -0
- package/lib/components/toolbar/controls/ListControl.vue +1 -5
- package/lib/components/toolbar/controls/StylePresetControl.vue +14 -1
- package/lib/components/toolbar/controls/UnderlineControl.vue +2 -2
- package/lib/components/toolbar/controls/__tests__/StylePresetControl.test.js +16 -0
- package/lib/components/toolbar/controls/__tests__/UnderlineControl.test.js +4 -0
- package/lib/components/toolbar/controls/index.js +1 -0
- package/lib/components/toolbar/controls/link/LinkControl.vue +155 -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/__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 +8 -0
- package/lib/components/toolbar/controls/link/composables/__tests__/useLink.test.js +114 -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/__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__/useEditor.test.js +2 -2
- package/lib/composables/useEditor.js +5 -7
- package/lib/composables/useToolbar.js +23 -28
- 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 +21 -7
- package/lib/extensions/BackgroundColor.js +14 -6
- package/lib/extensions/DeviceManager.js +0 -4
- package/lib/extensions/FontColor.js +14 -6
- package/lib/extensions/FontFamily.js +25 -8
- package/lib/extensions/FontSize.js +31 -12
- package/lib/extensions/FontStyle.js +23 -13
- package/lib/extensions/FontWeight.js +24 -14
- package/lib/extensions/LineHeight.js +31 -28
- package/lib/extensions/Link.js +89 -0
- package/lib/extensions/StylePreset.js +16 -15
- package/lib/extensions/TextDecoration.js +45 -12
- package/lib/extensions/__tests__/Alignment.test.js +11 -5
- package/lib/extensions/__tests__/BackgroundColor.test.js +11 -5
- package/lib/extensions/__tests__/CaseStyle.test.js +3 -5
- package/lib/extensions/__tests__/FontColor.test.js +11 -5
- package/lib/extensions/__tests__/FontFamily.test.js +32 -7
- package/lib/extensions/__tests__/FontSize.test.js +13 -6
- package/lib/extensions/__tests__/FontStyle.test.js +11 -5
- package/lib/extensions/__tests__/FontWeight.test.js +19 -5
- package/lib/extensions/__tests__/LineHeight.test.js +23 -11
- package/lib/extensions/__tests__/Link.test.js +102 -0
- package/lib/extensions/__tests__/StylePreset.test.js +70 -6
- package/lib/extensions/__tests__/TextDecoration.test.js +51 -5
- 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/TextProcessor.js +10 -0
- package/lib/extensions/core/__tests__/NodeProcessor.test.js +3 -5
- package/lib/extensions/core/__tests__/SelectionProcessor.test.js +3 -5
- package/lib/extensions/core/__tests__/TextProcessor.test.js +138 -12
- 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/__tests__/List.test.js +3 -5
- package/lib/extensions/list/__tests__/__snapshots__/List.test.js.snap +45 -15
- package/lib/injectionTokens.js +2 -1
- package/lib/services/ContentNormalizer.js +113 -29
- package/lib/services/ContextWidnow.js +23 -0
- package/lib/services/__tests__/ContentNormalizer.test.js +75 -7
- package/lib/services/index.js +1 -0
- package/lib/styles/content.css +102 -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 +13 -0
- package/lib/utils/index.js +4 -0
- package/lib/utils/renderInlineSetting.js +1 -1
- package/package.json +21 -25
- package/config/webpack/example.config.js +0 -86
- 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 -7
- package/config/webpack/loaders/svg-loader.js +0 -4
- package/config/webpack/loaders/vue-loader.js +0 -4
- package/lib/assets/icons.svg +0 -69
- package/lib/composables/__tests__/useToolbar.test.js +0 -56
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="zw-field">
|
|
3
|
+
<label class="zw-field__label" :for="fieldId" data-test-selector="label">
|
|
4
|
+
{{ label }}
|
|
5
|
+
</label>
|
|
6
|
+
|
|
7
|
+
<input
|
|
8
|
+
class="zw-field__input"
|
|
9
|
+
type="text"
|
|
10
|
+
:value="value"
|
|
11
|
+
:id="fieldId"
|
|
12
|
+
:placeholder="placeholder"
|
|
13
|
+
@input="onInput"
|
|
14
|
+
data-test-selector="input"
|
|
15
|
+
>
|
|
16
|
+
|
|
17
|
+
<p class="zw-field__label--error" v-if="error" data-test-selector="error">
|
|
18
|
+
{{ error }}
|
|
19
|
+
</p>
|
|
20
|
+
</div>
|
|
21
|
+
</template>
|
|
22
|
+
|
|
23
|
+
<script>
|
|
24
|
+
import { computed } from '@vue/composition-api';
|
|
25
|
+
|
|
26
|
+
export default {
|
|
27
|
+
name: 'TextField',
|
|
28
|
+
|
|
29
|
+
props: {
|
|
30
|
+
value: {
|
|
31
|
+
type: [Number, String],
|
|
32
|
+
required: true
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
label: {
|
|
36
|
+
type: String,
|
|
37
|
+
required: true
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
placeholder: {
|
|
41
|
+
type: String,
|
|
42
|
+
required: false,
|
|
43
|
+
default: ''
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
error: {
|
|
47
|
+
type: String,
|
|
48
|
+
required: false,
|
|
49
|
+
default: null
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
setup(props, { emit }) {
|
|
54
|
+
const onInput = (event) => emit('input', event.target.value);
|
|
55
|
+
const fieldId = computed(() => {
|
|
56
|
+
return props.label.toLowerCase().replace(/[^a-zA-Z0-9]+(.)/g, (m, chr) => chr.toUpperCase());
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
return { onInput, fieldId };
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
</script>
|
|
63
|
+
|
|
64
|
+
<style scoped>
|
|
65
|
+
.zw-field {
|
|
66
|
+
display: flex;
|
|
67
|
+
flex-direction: column;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.zw-field__input {
|
|
71
|
+
--border-color: rgb(var(--zw-color-n60));
|
|
72
|
+
--text-color: rgb(var(--zw-color-n85));
|
|
73
|
+
|
|
74
|
+
border: 1px solid var(--border-color);
|
|
75
|
+
background-color: transparent;
|
|
76
|
+
color: var(--text-color);
|
|
77
|
+
font-size: var(--zw-font-size-xxs);
|
|
78
|
+
outline: none;
|
|
79
|
+
padding: 6px;
|
|
80
|
+
line-height: var(--zw-line-height-xxs);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.zw-field__input:hover {
|
|
84
|
+
--border-color: rgb(var(--zw-color-n80));
|
|
85
|
+
--text-color: rgb(var(--zw-color-n85));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.zw-field__input:focus,
|
|
89
|
+
.zw-field__input:focus-within {
|
|
90
|
+
--border-color: rgb(var(--zw-color-white));
|
|
91
|
+
--text-color: rgb(var(--zw-color-white));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.zw-field__label {
|
|
95
|
+
display: inline-block;
|
|
96
|
+
font-size: var(--zw-font-size-xxs);
|
|
97
|
+
padding-bottom: var(--zw-offset-xxs);
|
|
98
|
+
line-height: var(--zw-line-height-xxs);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.zw-field__label--error {
|
|
102
|
+
font-size: var(--zw-font-size-xxs);
|
|
103
|
+
margin: var(--zw-offset-xxs) 0 0;
|
|
104
|
+
color: rgb(var(--zw-color-red));
|
|
105
|
+
}
|
|
106
|
+
</style>
|
|
@@ -14,32 +14,25 @@ function createComponent({ name, size, isAutoColor } = {}) {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
describe('rendering', () => {
|
|
17
|
-
test('should render url to icon', () => {
|
|
18
|
-
const wrapper = createComponent({ name: 'close' });
|
|
19
|
-
const useWrapper = wrapper.find('use');
|
|
20
|
-
|
|
21
|
-
expect(useWrapper.attributes('href')).toBe('http://zipify.com/icons.svg#close');
|
|
22
|
-
});
|
|
23
|
-
|
|
24
17
|
test('should render without size', () => {
|
|
25
18
|
const wrapper = createComponent({ size: '' });
|
|
26
19
|
|
|
27
|
-
expect(wrapper.
|
|
28
|
-
expect(wrapper.
|
|
20
|
+
expect(wrapper.element).not.toElementHasStyle('--zw-icon-width');
|
|
21
|
+
expect(wrapper.element).not.toElementHasStyle('--zw-icon-height');
|
|
29
22
|
});
|
|
30
23
|
|
|
31
24
|
test('should render size without units', () => {
|
|
32
25
|
const wrapper = createComponent({ size: '12' });
|
|
33
26
|
|
|
34
|
-
expect(wrapper.
|
|
35
|
-
expect(wrapper.
|
|
27
|
+
expect(wrapper.element).toElementHasStyle('--zw-icon-width', '12px');
|
|
28
|
+
expect(wrapper.element).toElementHasStyle('--zw-icon-height', '12px');
|
|
36
29
|
});
|
|
37
30
|
|
|
38
31
|
test('should percent size', () => {
|
|
39
32
|
const wrapper = createComponent({ size: '12%' });
|
|
40
33
|
|
|
41
|
-
expect(wrapper.
|
|
42
|
-
expect(wrapper.
|
|
34
|
+
expect(wrapper.element).toElementHasStyle('--zw-icon-width', '12%');
|
|
35
|
+
expect(wrapper.element).toElementHasStyle('--zw-icon-height', '12%');
|
|
43
36
|
});
|
|
44
37
|
|
|
45
38
|
test('should render auto color style', () => {
|
|
@@ -3,6 +3,11 @@ import { shallowMount } from '@vue/test-utils';
|
|
|
3
3
|
import { InjectionTokens } from '../../../injectionTokens';
|
|
4
4
|
import Modal from '../Modal';
|
|
5
5
|
|
|
6
|
+
jest.mock('../composables', () => ({
|
|
7
|
+
useDeselectionLock: jest.fn(),
|
|
8
|
+
useModalToggler: jest.fn()
|
|
9
|
+
}));
|
|
10
|
+
|
|
6
11
|
const createToggler = (isOpened) => ({
|
|
7
12
|
close: jest.fn(),
|
|
8
13
|
isOpened: ref(isOpened ?? true)
|
|
@@ -42,7 +47,7 @@ describe('open/close', () => {
|
|
|
42
47
|
});
|
|
43
48
|
|
|
44
49
|
test('should open', async () => {
|
|
45
|
-
const toggler = createToggler(false);
|
|
50
|
+
const toggler = createToggler({ value: false });
|
|
46
51
|
const wrapper = createComponent({ toggler });
|
|
47
52
|
|
|
48
53
|
toggler.isOpened.value = true;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { shallowMount } from '@vue/test-utils';
|
|
2
|
+
import TextField from '../TextField';
|
|
3
|
+
|
|
4
|
+
function createComponent(label, error) {
|
|
5
|
+
return shallowMount(TextField, {
|
|
6
|
+
propsData: {
|
|
7
|
+
value: '',
|
|
8
|
+
label: label ?? '',
|
|
9
|
+
placeholder: '',
|
|
10
|
+
error: error ?? null
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const SELECTORS = {
|
|
16
|
+
LABEL: '[data-test-selector="label"]',
|
|
17
|
+
INPUT: '[data-test-selector="input"]',
|
|
18
|
+
ERROR: '[data-test-selector="error"]'
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
describe('rendering', () => {
|
|
22
|
+
test('should render label', () => {
|
|
23
|
+
const label = 'Hello world!';
|
|
24
|
+
const wrapper = createComponent(label);
|
|
25
|
+
|
|
26
|
+
expect(wrapper.find(SELECTORS.LABEL).text()).toEqual(label);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('should generate label', () => {
|
|
30
|
+
const wrapper = createComponent('hello world label');
|
|
31
|
+
|
|
32
|
+
expect(wrapper.find(SELECTORS.INPUT).element.id).toBe('helloWorldLabel');
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('should render errors', () => {
|
|
36
|
+
const wrapper = createComponent('_', 'some error');
|
|
37
|
+
|
|
38
|
+
expect(wrapper.contains(SELECTORS.ERROR)).toBeTruthy();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('should not render errors', () => {
|
|
42
|
+
const wrapper = createComponent();
|
|
43
|
+
|
|
44
|
+
expect(wrapper.contains(SELECTORS.ERROR)).toBeFalsy();
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe('input change handling', () => {
|
|
49
|
+
test('should emit parsed value', () => {
|
|
50
|
+
const wrapper = createComponent();
|
|
51
|
+
const inputComponentWrapper = wrapper.find(SELECTORS.INPUT);
|
|
52
|
+
|
|
53
|
+
inputComponentWrapper.setValue('Hello world!!!');
|
|
54
|
+
|
|
55
|
+
expect(wrapper.emitted('input')).toMatchSnapshot();
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
</template>
|
|
21
21
|
|
|
22
22
|
<script>
|
|
23
|
-
import { ZipifyColorPicker } from 'zipify
|
|
23
|
+
import { ZipifyColorPicker } from '@zipify/colorpicker';
|
|
24
24
|
import { inject, ref, toRef } from '@vue/composition-api';
|
|
25
25
|
import { outClick } from '../../../directives';
|
|
26
26
|
import { InjectionTokens } from '../../../injectionTokens';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ref } from '@vue/composition-api';
|
|
2
|
+
import { ContextWindow } from '../../../../services';
|
|
2
3
|
import { useActivatedListener } from '../../composables';
|
|
3
4
|
|
|
4
5
|
export function usePickerHotkeys({ isOpenedRef, onCancel, onApply }) {
|
|
@@ -16,7 +17,7 @@ export function usePickerHotkeys({ isOpenedRef, onCancel, onApply }) {
|
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
useActivatedListener({
|
|
19
|
-
targetRef: ref(document),
|
|
20
|
+
targetRef: ref(ContextWindow.document),
|
|
20
21
|
isActiveRef: isOpenedRef,
|
|
21
22
|
event: 'keydown',
|
|
22
23
|
onEvent: handle,
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { useValidator } from '../useValidator';
|
|
2
|
+
|
|
3
|
+
describe('validation', () => {
|
|
4
|
+
test('should show error', () => {
|
|
5
|
+
const value = '';
|
|
6
|
+
const isEmpty = () => value ? false : 'Can\'t be empty';
|
|
7
|
+
|
|
8
|
+
const validator = useValidator({
|
|
9
|
+
validations: [isEmpty]
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
validator.validate();
|
|
13
|
+
|
|
14
|
+
expect(validator.error.value).toBe('Can\'t be empty');
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test('should pass validation', () => {
|
|
18
|
+
const value = 'hello';
|
|
19
|
+
const isEmpty = () => value ? false : 'Can\'t be empty';
|
|
20
|
+
|
|
21
|
+
const validator = useValidator({
|
|
22
|
+
validations: [isEmpty]
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
validator.validate();
|
|
26
|
+
|
|
27
|
+
expect(validator.error.value).toBe(null);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('should reset error', () => {
|
|
31
|
+
const value = '';
|
|
32
|
+
const isEmpty = () => value ? false : 'Can\'t be empty';
|
|
33
|
+
|
|
34
|
+
const validator = useValidator({
|
|
35
|
+
validations: [isEmpty]
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
validator.validate();
|
|
39
|
+
expect(validator.error.value).toBe('Can\'t be empty');
|
|
40
|
+
|
|
41
|
+
validator.reset();
|
|
42
|
+
expect(validator.error.value).toBe(null);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ref } from '@vue/composition-api';
|
|
2
|
+
|
|
3
|
+
export function useValidator({ validations }) {
|
|
4
|
+
const error = ref(null);
|
|
5
|
+
|
|
6
|
+
function validate() {
|
|
7
|
+
for (const validate of validations) {
|
|
8
|
+
const validationError = validate();
|
|
9
|
+
|
|
10
|
+
if (validationError) {
|
|
11
|
+
return error.value = validationError;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
error.value = null;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function reset() {
|
|
19
|
+
error.value = null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return { error, validate, reset };
|
|
23
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div class="zw-dropdown" ref="dropdownRef">
|
|
3
|
-
<DropdownActivator>
|
|
3
|
+
<DropdownActivator :color="color">
|
|
4
4
|
<template #default="attrs">
|
|
5
5
|
<slot name="activator" v-bind="attrs" />
|
|
6
6
|
</template>
|
|
7
7
|
</DropdownActivator>
|
|
8
8
|
|
|
9
|
-
<Modal max-height="300" max-width="
|
|
9
|
+
<Modal max-height="300" :max-width="maxWidth" :toggler="toggler" ref="modalRef">
|
|
10
10
|
<DropdownMenu :options="options">
|
|
11
11
|
<template #option="attrs">
|
|
12
12
|
<slot name="option" v-bind="attrs" />
|
|
@@ -40,7 +40,7 @@ export default {
|
|
|
40
40
|
|
|
41
41
|
props: {
|
|
42
42
|
value: {
|
|
43
|
-
type: String,
|
|
43
|
+
type: [String, Number],
|
|
44
44
|
required: false,
|
|
45
45
|
default: null
|
|
46
46
|
},
|
|
@@ -48,6 +48,18 @@ export default {
|
|
|
48
48
|
options: {
|
|
49
49
|
type: Array,
|
|
50
50
|
required: true
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
maxWidth: {
|
|
54
|
+
type: Number,
|
|
55
|
+
required: false,
|
|
56
|
+
default: 156
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
color: {
|
|
60
|
+
type: String,
|
|
61
|
+
required: false,
|
|
62
|
+
default: 'none'
|
|
51
63
|
}
|
|
52
64
|
},
|
|
53
65
|
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
</template>
|
|
25
25
|
|
|
26
26
|
<script>
|
|
27
|
-
import { computed, inject } from '@vue/composition-api';
|
|
27
|
+
import { computed, inject, toRef } from '@vue/composition-api';
|
|
28
28
|
import Button from '../Button';
|
|
29
29
|
import Icon from '../Icon';
|
|
30
30
|
import { InjectionTokens } from './injectionTokens';
|
|
@@ -42,14 +42,24 @@ export default {
|
|
|
42
42
|
event: 'change'
|
|
43
43
|
},
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
props: {
|
|
46
|
+
color: {
|
|
47
|
+
type: String,
|
|
48
|
+
required: false,
|
|
49
|
+
default: 'none'
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
setup(props) {
|
|
46
54
|
const activeOptionManager = inject(InjectionTokens.ACTIVE_MANAGER);
|
|
47
55
|
const dropdownToggler = inject(InjectionTokens.TOGGLER);
|
|
56
|
+
const color = toRef(props, 'color');
|
|
48
57
|
|
|
49
58
|
const activeOptionTitle = useDropdownEntityTitle(activeOptionManager.activeOption);
|
|
50
59
|
|
|
51
60
|
const dropdownClasses = computed(() => ({
|
|
52
|
-
'zw-dropdown__activator--active': dropdownToggler.isOpened.value
|
|
61
|
+
'zw-dropdown__activator--active': dropdownToggler.isOpened.value,
|
|
62
|
+
'zw-dropdown__activator--gray': color.value === 'gray'
|
|
53
63
|
}));
|
|
54
64
|
|
|
55
65
|
return {
|
|
@@ -78,4 +88,10 @@ export default {
|
|
|
78
88
|
.zw-dropdown__activator--active .zw-dropdown__activator-arrow {
|
|
79
89
|
transform: rotateX(180deg);
|
|
80
90
|
}
|
|
91
|
+
|
|
92
|
+
.zw-dropdown__activator--gray {
|
|
93
|
+
background-color: rgb(var(--zw-color-n20));
|
|
94
|
+
font-size: var(--zw-font-size-xxs);
|
|
95
|
+
color: rgb(var(--zw-color-white));
|
|
96
|
+
}
|
|
81
97
|
</style>
|
|
@@ -6,6 +6,8 @@ export { default as FieldLabel } from './FieldLabel';
|
|
|
6
6
|
export { default as Range } from './Range';
|
|
7
7
|
export { default as NumberField } from './NumberField';
|
|
8
8
|
export { default as Modal } from './Modal';
|
|
9
|
-
export {
|
|
9
|
+
export { default as TextField } from './TextField';
|
|
10
|
+
export { default as Checkbox } from './Checkbox';
|
|
11
|
+
export { useModalToggler, useElementRef } from './composables';
|
|
10
12
|
export * from './dropdown';
|
|
11
13
|
export * from './colorPicker';
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
3
|
-
<
|
|
4
|
-
<
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
<keep-alive>
|
|
3
|
+
<transition name="zw-toolbar-" duration="150">
|
|
4
|
+
<div class="zw-toolbar" :style="toolbarStyles" ref="toolbarRef" v-if="isVisible">
|
|
5
|
+
<component :is="toolbarComponent" />
|
|
6
|
+
</div>
|
|
7
|
+
</transition>
|
|
8
|
+
</keep-alive>
|
|
7
9
|
</template>
|
|
8
10
|
|
|
9
11
|
<script>
|
|
10
|
-
import { computed } from '@vue/composition-api';
|
|
12
|
+
import { computed, ref, watch } from '@vue/composition-api';
|
|
11
13
|
import { Devices } from '../../enums';
|
|
12
14
|
import ToolbarFull from './ToolbarFull';
|
|
13
15
|
import ToolbarDevice from './ToolbarDevice';
|
|
@@ -19,6 +21,11 @@ export default {
|
|
|
19
21
|
device: {
|
|
20
22
|
type: String,
|
|
21
23
|
required: true
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
toolbar: {
|
|
27
|
+
type: Object,
|
|
28
|
+
required: true
|
|
22
29
|
}
|
|
23
30
|
},
|
|
24
31
|
|
|
@@ -26,8 +33,23 @@ export default {
|
|
|
26
33
|
const toolbarComponent = computed(() => {
|
|
27
34
|
return props.device === Devices.DESKTOP ? ToolbarFull : ToolbarDevice;
|
|
28
35
|
});
|
|
36
|
+
const isVisible = computed(() => props.toolbar.isActiveRef.value);
|
|
37
|
+
const toolbarRef = ref(null);
|
|
38
|
+
|
|
39
|
+
watch(toolbarRef, (toolbarEl) => {
|
|
40
|
+
toolbarEl && props.toolbar.mount(toolbarEl);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const toolbarStyles = computed(() => ({
|
|
44
|
+
'--zw-toolbar-offset-y': `${props.toolbar.offsets[1]}px`
|
|
45
|
+
}));
|
|
29
46
|
|
|
30
|
-
return {
|
|
47
|
+
return {
|
|
48
|
+
toolbarComponent,
|
|
49
|
+
isVisible,
|
|
50
|
+
toolbarRef,
|
|
51
|
+
toolbarStyles
|
|
52
|
+
};
|
|
31
53
|
}
|
|
32
54
|
};
|
|
33
55
|
</script>
|
|
@@ -37,12 +59,30 @@ export default {
|
|
|
37
59
|
border-radius: 2px;
|
|
38
60
|
background-color: rgb(var(--zw-color-n15));
|
|
39
61
|
color: rgb(var(--zw-color-n70));
|
|
40
|
-
z-index:
|
|
62
|
+
z-index: 999999;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.zw-toolbar::before,
|
|
66
|
+
.zw-toolbar::after {
|
|
67
|
+
content: "";
|
|
68
|
+
display: block;
|
|
69
|
+
width: 100%;
|
|
70
|
+
height: calc(var(--zw-toolbar-offset-y) + 4px);
|
|
71
|
+
position: absolute;
|
|
72
|
+
--zw-toolbar-safe-zone: calc(-1 * var(--zw-toolbar-offset-y));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.zw-toolbar::before {
|
|
76
|
+
top: var(--zw-toolbar-safe-zone);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.zw-toolbar::after {
|
|
80
|
+
bottom: var(--zw-toolbar-safe-zone);
|
|
41
81
|
}
|
|
42
82
|
|
|
43
83
|
.zw-toolbar--enter-active,
|
|
44
84
|
.zw-toolbar--leave-active {
|
|
45
|
-
transition: opacity
|
|
85
|
+
transition: opacity 150ms ease-out;
|
|
46
86
|
}
|
|
47
87
|
|
|
48
88
|
.zw-toolbar--leave-active {
|
|
@@ -33,12 +33,18 @@
|
|
|
33
33
|
|
|
34
34
|
<ToolbarGroup>
|
|
35
35
|
<LineHeightControl />
|
|
36
|
+
</ToolbarGroup>
|
|
37
|
+
|
|
38
|
+
<ToolbarDivider vertical />
|
|
39
|
+
|
|
40
|
+
<ToolbarGroup>
|
|
36
41
|
<ListControl />
|
|
37
42
|
</ToolbarGroup>
|
|
38
43
|
|
|
39
44
|
<ToolbarDivider vertical />
|
|
40
45
|
|
|
41
46
|
<ToolbarGroup>
|
|
47
|
+
<LinkControl />
|
|
42
48
|
<RemoveFormatControl />
|
|
43
49
|
</ToolbarGroup>
|
|
44
50
|
</ToolbarRow>
|
|
@@ -64,7 +70,8 @@ import {
|
|
|
64
70
|
SuperscriptControl,
|
|
65
71
|
UnderlineControl,
|
|
66
72
|
ListControl,
|
|
67
|
-
RemoveFormatControl
|
|
73
|
+
RemoveFormatControl,
|
|
74
|
+
LinkControl
|
|
68
75
|
} from './controls';
|
|
69
76
|
|
|
70
77
|
export default {
|
|
@@ -88,7 +95,8 @@ export default {
|
|
|
88
95
|
AlignmentControl,
|
|
89
96
|
LineHeightControl,
|
|
90
97
|
ListControl,
|
|
91
|
-
RemoveFormatControl
|
|
98
|
+
RemoveFormatControl,
|
|
99
|
+
LinkControl
|
|
92
100
|
}
|
|
93
101
|
};
|
|
94
102
|
</script>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { shallowMount } from '@vue/test-utils';
|
|
2
|
+
import { ref } from '@vue/composition-api';
|
|
2
3
|
import { Devices } from '../../../enums';
|
|
3
4
|
import Toolbar from '../Toolbar';
|
|
4
5
|
import ToolbarFull from '../ToolbarFull';
|
|
@@ -7,6 +8,11 @@ import ToolbarDevice from '../ToolbarDevice';
|
|
|
7
8
|
function createComponent({ device }) {
|
|
8
9
|
return shallowMount(Toolbar, {
|
|
9
10
|
propsData: {
|
|
11
|
+
toolbar: {
|
|
12
|
+
mount: jest.fn(),
|
|
13
|
+
isActiveRef: ref(true),
|
|
14
|
+
offsets: [0, 8]
|
|
15
|
+
},
|
|
10
16
|
device: device ?? Devices.DESKTOP
|
|
11
17
|
}
|
|
12
18
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<Dropdown
|
|
3
|
+
class="zw-font-size-control"
|
|
3
4
|
:options="options"
|
|
4
5
|
:value="currentValue"
|
|
5
6
|
@change="apply"
|
|
@@ -43,3 +44,9 @@ export default {
|
|
|
43
44
|
}
|
|
44
45
|
};
|
|
45
46
|
</script>
|
|
47
|
+
|
|
48
|
+
<style scoped>
|
|
49
|
+
.zw-font-size-control {
|
|
50
|
+
width: 64px;
|
|
51
|
+
}
|
|
52
|
+
</style>
|
|
@@ -17,11 +17,7 @@
|
|
|
17
17
|
</template>
|
|
18
18
|
|
|
19
19
|
<template #option="{ option }">
|
|
20
|
-
<DropdownOption
|
|
21
|
-
class="zw-list-control__option"
|
|
22
|
-
:option="option"
|
|
23
|
-
v-tooltip="option.tooltip"
|
|
24
|
-
>
|
|
20
|
+
<DropdownOption class="zw-list-control__option" :option="option">
|
|
25
21
|
<Icon :name="option.icon" size="28px" auto-color />
|
|
26
22
|
</DropdownOption>
|
|
27
23
|
</template>
|
|
@@ -25,6 +25,9 @@ import { computed, inject } from '@vue/composition-api';
|
|
|
25
25
|
import { InjectionTokens } from '../../../injectionTokens';
|
|
26
26
|
import { Dropdown, Button, Icon } from '../../base';
|
|
27
27
|
import { tooltip } from '../../../directives';
|
|
28
|
+
import { TextSettings } from '../../../enums';
|
|
29
|
+
|
|
30
|
+
const CLEAR_MARKS = [TextSettings.FONT_SIZE, TextSettings.FONT_WEIGHT];
|
|
28
31
|
|
|
29
32
|
export default {
|
|
30
33
|
name: 'StylePresetControl',
|
|
@@ -59,7 +62,17 @@ export default {
|
|
|
59
62
|
}));
|
|
60
63
|
});
|
|
61
64
|
|
|
62
|
-
const apply = (value) =>
|
|
65
|
+
const apply = (value) => {
|
|
66
|
+
editor.chain()
|
|
67
|
+
.focus()
|
|
68
|
+
.applyPreset(value)
|
|
69
|
+
.storeSelection()
|
|
70
|
+
.expandSelectionToBlock()
|
|
71
|
+
.unsetMarks(CLEAR_MARKS)
|
|
72
|
+
.restoreSelection()
|
|
73
|
+
.run();
|
|
74
|
+
};
|
|
75
|
+
|
|
63
76
|
const removeCustomization = () => editor.chain().focus().removePresetCustomization().run();
|
|
64
77
|
|
|
65
78
|
return {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
</template>
|
|
12
12
|
|
|
13
13
|
<script>
|
|
14
|
-
import { inject } from '@vue/composition-api';
|
|
14
|
+
import { inject, computed } from '@vue/composition-api';
|
|
15
15
|
import { Button, Icon } from '../../base';
|
|
16
16
|
import { InjectionTokens } from '../../../injectionTokens';
|
|
17
17
|
import { tooltip } from '../../../directives';
|
|
@@ -31,7 +31,7 @@ export default {
|
|
|
31
31
|
setup() {
|
|
32
32
|
const editor = inject(InjectionTokens.EDITOR);
|
|
33
33
|
|
|
34
|
-
const currentValue = editor.commands.isUnderline();
|
|
34
|
+
const currentValue = computed(() => editor.commands.isUnderline().value);
|
|
35
35
|
const apply = () => editor.chain().focus().toggleUnderline().run();
|
|
36
36
|
|
|
37
37
|
return {
|