@zipify/wysiwyg 1.0.0-dev.1
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 +18 -0
- package/.eslintrc.js +253 -0
- package/.github/actions/deploy-example/action.yaml +61 -0
- package/.github/actions/lint-css/action.yaml +15 -0
- package/.github/actions/lint-js/action.yaml +22 -0
- package/.github/actions/setup/action.yaml +19 -0
- package/.github/actions/unit-tests/action.yaml +13 -0
- package/.github/actions/unit-tests/jest.config.js +8 -0
- package/.github/dependabot.yaml +17 -0
- package/.github/pull_request_template.md +17 -0
- package/.github/workflows/frontend-ci.yaml +120 -0
- package/.husky/pre-commit +4 -0
- package/.lintstagedrc +12 -0
- package/.release-it.json +6 -0
- package/.stylelintrc +110 -0
- package/README.md +61 -0
- package/babel.config.js +15 -0
- package/ci/example/deploy.sh +25 -0
- package/config/jest/TestEnvironment.js +27 -0
- package/config/jest/matchers/index.js +6 -0
- package/config/jest/matchers/toElementHasStyle.js +27 -0
- package/config/jest/matchers/toVueContainComponent.js +20 -0
- package/config/jest/matchers/toVueContainElement.js +34 -0
- package/config/jest/matchers/toVueContainLazyComponent.js +19 -0
- package/config/jest/matchers/toVueEmpty.js +16 -0
- package/config/jest/matchers/toVuexActionHasBeenDispatched.js +19 -0
- package/config/jest/setupMatchers.js +4 -0
- package/config/jest/setupTests.js +32 -0
- package/config/jest/typing.d.ts +14 -0
- package/config/svgo.js +22 -0
- package/config/webpack/example.config.js +86 -0
- package/config/webpack/loaders/index.js +6 -0
- package/config/webpack/loaders/js-loader.js +5 -0
- package/config/webpack/loaders/style-loader.js +7 -0
- package/config/webpack/loaders/svg-loader.js +4 -0
- package/config/webpack/loaders/vue-loader.js +4 -0
- package/config/webpack/settings.js +9 -0
- package/example/ExampleApp.vue +136 -0
- package/example/example.html +17 -0
- package/example/example.js +19 -0
- package/example/fonts.js +474 -0
- package/example/presets.js +245 -0
- package/example/tooltip/Tooltip.js +241 -0
- package/example/tooltip/TooltipManager.js +132 -0
- package/example/tooltip/index.js +3 -0
- package/example/tooltip/modifiers/TooltipCloseOnScrollModifier.js +73 -0
- package/example/tooltip/modifiers/index.js +1 -0
- package/example/tooltip/tooltip.css +95 -0
- package/jest.config.js +17 -0
- package/lib/Wysiwyg.vue +156 -0
- package/lib/__mocks__/svgMock.js +1 -0
- package/lib/__tests__/utils/NodeFactory.js +67 -0
- package/lib/__tests__/utils/index.js +4 -0
- package/lib/__tests__/utils/setReadonlyProperty.js +9 -0
- package/lib/__tests__/utils/waitAsyncOperation.js +6 -0
- package/lib/__tests__/utils/withComponentContext.js +14 -0
- package/lib/assets/icons.svg +69 -0
- package/lib/components/base/Button.vue +117 -0
- package/lib/components/base/ButtonToggle.vue +40 -0
- package/lib/components/base/FieldLabel.vue +28 -0
- package/lib/components/base/Icon.vue +67 -0
- package/lib/components/base/Modal.vue +116 -0
- package/lib/components/base/NumberField.vue +242 -0
- package/lib/components/base/Range.vue +196 -0
- package/lib/components/base/ScrollView.vue +60 -0
- package/lib/components/base/__tests__/Button.test.js +50 -0
- package/lib/components/base/__tests__/Icon.test.js +56 -0
- package/lib/components/base/__tests__/Modal.test.js +69 -0
- package/lib/components/base/__tests__/Range.test.js +39 -0
- package/lib/components/base/colorPicker/ColorPicker.vue +93 -0
- package/lib/components/base/colorPicker/composables/__tests__/usePickerApi.test.js +81 -0
- package/lib/components/base/colorPicker/composables/index.js +2 -0
- package/lib/components/base/colorPicker/composables/usePickerApi.js +35 -0
- package/lib/components/base/colorPicker/composables/usePickerHotkeys.js +25 -0
- package/lib/components/base/colorPicker/index.js +1 -0
- package/lib/components/base/composables/__tests__/useActivatedListener.test.js +89 -0
- package/lib/components/base/composables/__tests__/useDeselectionLock.test.js +80 -0
- package/lib/components/base/composables/__tests__/useElementRef.test.js +29 -0
- package/lib/components/base/composables/__tests__/useModalToggler.test.js +55 -0
- package/lib/components/base/composables/__tests__/useNumberValue.test.js +153 -0
- package/lib/components/base/composables/__tests__/useScrollView.test.js +43 -0
- package/lib/components/base/composables/__tests__/useTempValue.test.js +38 -0
- package/lib/components/base/composables/index.js +7 -0
- package/lib/components/base/composables/useActivatedListener.js +23 -0
- package/lib/components/base/composables/useDeselectionLock.js +35 -0
- package/lib/components/base/composables/useElementRef.js +5 -0
- package/lib/components/base/composables/useModalToggler.js +58 -0
- package/lib/components/base/composables/useNumberValue.js +53 -0
- package/lib/components/base/composables/useScrollView.js +22 -0
- package/lib/components/base/composables/useTempValue.js +11 -0
- package/lib/components/base/dropdown/Dropdown.vue +88 -0
- package/lib/components/base/dropdown/DropdownActivator.vue +81 -0
- package/lib/components/base/dropdown/DropdownDivider.vue +21 -0
- package/lib/components/base/dropdown/DropdownGroup.vue +55 -0
- package/lib/components/base/dropdown/DropdownMenu.vue +62 -0
- package/lib/components/base/dropdown/DropdownOption.vue +91 -0
- package/lib/components/base/dropdown/__tests__/DropdownActivator.test.js +54 -0
- package/lib/components/base/dropdown/__tests__/DropdownMenu.test.js +67 -0
- package/lib/components/base/dropdown/__tests__/DropdownOption.test.js +81 -0
- package/lib/components/base/dropdown/composables/__tests__/useActiveOptionManager.test.js +41 -0
- package/lib/components/base/dropdown/composables/__tests__/useDropdownEntityTitle.test.js +24 -0
- package/lib/components/base/dropdown/composables/index.js +2 -0
- package/lib/components/base/dropdown/composables/useActiveOptionManager.js +25 -0
- package/lib/components/base/dropdown/composables/useDropdownEntityTitle.js +5 -0
- package/lib/components/base/dropdown/index.js +2 -0
- package/lib/components/base/dropdown/injectionTokens.js +5 -0
- package/lib/components/base/index.js +11 -0
- package/lib/components/index.js +1 -0
- package/lib/components/toolbar/Toolbar.vue +56 -0
- package/lib/components/toolbar/ToolbarDevice.vue +35 -0
- package/lib/components/toolbar/ToolbarDivider.vue +50 -0
- package/lib/components/toolbar/ToolbarFull.vue +94 -0
- package/lib/components/toolbar/ToolbarGroup.vue +18 -0
- package/lib/components/toolbar/ToolbarRow.vue +19 -0
- package/lib/components/toolbar/__tests__/Toolbar.test.js +33 -0
- package/lib/components/toolbar/__tests__/ToolbarDivider.test.js +26 -0
- package/lib/components/toolbar/controls/AlignmentControl.vue +72 -0
- package/lib/components/toolbar/controls/AlignmentDeviceControl.vue +67 -0
- package/lib/components/toolbar/controls/BackgroundColorControl.vue +48 -0
- package/lib/components/toolbar/controls/CaseStyleControl.vue +54 -0
- package/lib/components/toolbar/controls/FontColorControl.vue +48 -0
- package/lib/components/toolbar/controls/FontFamilyControl.vue +96 -0
- package/lib/components/toolbar/controls/FontSizeControl.vue +45 -0
- package/lib/components/toolbar/controls/FontWeightControl.vue +43 -0
- package/lib/components/toolbar/controls/ItalicControl.vue +47 -0
- package/lib/components/toolbar/controls/LineHeightControl.vue +102 -0
- package/lib/components/toolbar/controls/ListControl.vue +86 -0
- package/lib/components/toolbar/controls/RemoveFormatControl.vue +37 -0
- package/lib/components/toolbar/controls/StrikeThroughControl.vue +44 -0
- package/lib/components/toolbar/controls/StylePresetControl.vue +95 -0
- package/lib/components/toolbar/controls/SuperscriptControl.vue +44 -0
- package/lib/components/toolbar/controls/UnderlineControl.vue +44 -0
- package/lib/components/toolbar/controls/__tests__/AlignmentControl.test.js +51 -0
- package/lib/components/toolbar/controls/__tests__/AlignmentDeviceControl.test.js +77 -0
- package/lib/components/toolbar/controls/__tests__/BackgroundColorControl.test.js +59 -0
- package/lib/components/toolbar/controls/__tests__/CaseStyleControl.test.js +43 -0
- package/lib/components/toolbar/controls/__tests__/FontColorControl.test.js +59 -0
- package/lib/components/toolbar/controls/__tests__/FontFamilyControl.test.js +57 -0
- package/lib/components/toolbar/controls/__tests__/FontSizeControl.test.js +47 -0
- package/lib/components/toolbar/controls/__tests__/FontWeightControl.test.js +45 -0
- package/lib/components/toolbar/controls/__tests__/ItalicControl.test.js +63 -0
- package/lib/components/toolbar/controls/__tests__/LineHeightControl.test.js +120 -0
- package/lib/components/toolbar/controls/__tests__/ListControl.test.js +82 -0
- package/lib/components/toolbar/controls/__tests__/RemoveFormatControl.test.js +34 -0
- package/lib/components/toolbar/controls/__tests__/StrikeThroughControl.test.js +44 -0
- package/lib/components/toolbar/controls/__tests__/StylePresetControl.test.js +129 -0
- package/lib/components/toolbar/controls/__tests__/SuperscriptControl.test.js +44 -0
- package/lib/components/toolbar/controls/__tests__/UnderlineControl.test.js +44 -0
- package/lib/components/toolbar/controls/composables/__tests__/useRecentFonts.test.js +69 -0
- package/lib/components/toolbar/controls/composables/index.js +1 -0
- package/lib/components/toolbar/controls/composables/useRecentFonts.js +18 -0
- package/lib/components/toolbar/controls/index.js +16 -0
- package/lib/components/toolbar/index.js +1 -0
- package/lib/composables/__tests__/__snapshots__/useEditor.test.js.snap +24 -0
- package/lib/composables/__tests__/useEditor.test.js +67 -0
- package/lib/composables/__tests__/useToolbar.test.js +56 -0
- package/lib/composables/index.js +2 -0
- package/lib/composables/useEditor.js +21 -0
- package/lib/composables/useToolbar.js +44 -0
- package/lib/directives/__tests__/outClick.test.js +86 -0
- package/lib/directives/__tests__/tooltip.test.js +39 -0
- package/lib/directives/index.js +2 -0
- package/lib/directives/outClick.js +37 -0
- package/lib/directives/tooltip.js +7 -0
- package/lib/enums/Alignments.js +6 -0
- package/lib/enums/CaseStyles.js +5 -0
- package/lib/enums/Devices.js +15 -0
- package/lib/enums/ListTypes.js +23 -0
- package/lib/enums/NodeTypes.js +12 -0
- package/lib/enums/TextSettings.js +30 -0
- package/lib/enums/index.js +6 -0
- package/lib/extensions/Alignment.js +67 -0
- package/lib/extensions/BackgroundColor.js +28 -0
- package/lib/extensions/CaseStyle.js +36 -0
- package/lib/extensions/DeviceManager.js +16 -0
- package/lib/extensions/FontColor.js +36 -0
- package/lib/extensions/FontFamily.js +62 -0
- package/lib/extensions/FontSize.js +74 -0
- package/lib/extensions/FontStyle.js +62 -0
- package/lib/extensions/FontWeight.js +56 -0
- package/lib/extensions/LineHeight.js +60 -0
- package/lib/extensions/StylePreset.js +168 -0
- package/lib/extensions/Superscript.js +5 -0
- package/lib/extensions/TextDecoration.js +97 -0
- package/lib/extensions/__tests__/Alignment.test.js +107 -0
- package/lib/extensions/__tests__/BackgroundColor.test.js +75 -0
- package/lib/extensions/__tests__/CaseStyle.test.js +58 -0
- package/lib/extensions/__tests__/FontColor.test.js +85 -0
- package/lib/extensions/__tests__/FontFamily.test.js +171 -0
- package/lib/extensions/__tests__/FontSize.test.js +183 -0
- package/lib/extensions/__tests__/FontStyle.test.js +136 -0
- package/lib/extensions/__tests__/FontWeight.test.js +151 -0
- package/lib/extensions/__tests__/LineHeight.test.js +106 -0
- package/lib/extensions/__tests__/StylePreset.test.js +400 -0
- package/lib/extensions/__tests__/TextDecoration.test.js +258 -0
- package/lib/extensions/__tests__/__snapshots__/Alignment.test.js.snap +29 -0
- package/lib/extensions/__tests__/__snapshots__/BackgroundColor.test.js.snap +28 -0
- package/lib/extensions/__tests__/__snapshots__/CaseStyle.test.js.snap +69 -0
- package/lib/extensions/__tests__/__snapshots__/FontColor.test.js.snap +28 -0
- package/lib/extensions/__tests__/__snapshots__/FontFamily.test.js.snap +158 -0
- package/lib/extensions/__tests__/__snapshots__/FontSize.test.js.snap +140 -0
- package/lib/extensions/__tests__/__snapshots__/FontStyle.test.js.snap +87 -0
- package/lib/extensions/__tests__/__snapshots__/FontWeight.test.js.snap +140 -0
- package/lib/extensions/__tests__/__snapshots__/LineHeight.test.js.snap +29 -0
- package/lib/extensions/__tests__/__snapshots__/StylePreset.test.js.snap +310 -0
- package/lib/extensions/__tests__/__snapshots__/TextDecoration.test.js.snap +206 -0
- package/lib/extensions/core/NodeProcessor.js +32 -0
- package/lib/extensions/core/SelectionProcessor.js +37 -0
- package/lib/extensions/core/TextProcessor.js +57 -0
- package/lib/extensions/core/__tests__/NodeProcessor.test.js +120 -0
- package/lib/extensions/core/__tests__/SelectionProcessor.test.js +78 -0
- package/lib/extensions/core/__tests__/TextProcessor.test.js +61 -0
- package/lib/extensions/core/__tests__/__snapshots__/NodeProcessor.test.js.snap +93 -0
- package/lib/extensions/core/__tests__/__snapshots__/TextProcessor.test.js.snap +43 -0
- package/lib/extensions/core/index.js +17 -0
- package/lib/extensions/core/inputRules/closeDoubleQuote.js +6 -0
- package/lib/extensions/core/inputRules/closeSingleQuote.js +6 -0
- package/lib/extensions/core/inputRules/copyright.js +6 -0
- package/lib/extensions/core/inputRules/ellipsis.js +6 -0
- package/lib/extensions/core/inputRules/emDash.js +6 -0
- package/lib/extensions/core/inputRules/index.js +9 -0
- package/lib/extensions/core/inputRules/openDoubleQuote.js +6 -0
- package/lib/extensions/core/inputRules/openSingleQuote.js +6 -0
- package/lib/extensions/core/inputRules/registeredTrademark.js +6 -0
- package/lib/extensions/core/inputRules/trademark.js +6 -0
- package/lib/extensions/index.js +49 -0
- package/lib/extensions/list/List.js +81 -0
- package/lib/extensions/list/ListItem.js +12 -0
- package/lib/extensions/list/__tests__/List.test.js +130 -0
- package/lib/extensions/list/__tests__/__snapshots__/List.test.js.snap +212 -0
- package/lib/extensions/list/index.js +1 -0
- package/lib/index.js +1 -0
- package/lib/injectionTokens.js +7 -0
- package/lib/models/Font.js +37 -0
- package/lib/models/__tests__/Font.test.js +58 -0
- package/lib/models/index.js +1 -0
- package/lib/services/FavoriteColors.js +6 -0
- package/lib/services/JsonSerializer.js +15 -0
- package/lib/services/Storage.js +49 -0
- package/lib/services/index.js +3 -0
- package/lib/styles/content.css +39 -0
- package/lib/styles/helpers/common.css +3 -0
- package/lib/styles/helpers/offsets.css +3 -0
- package/lib/styles/helpers/text.css +6 -0
- package/lib/styles/main.css +5 -0
- package/lib/styles/variables.css +57 -0
- package/lib/utils/__tests__/__snapshots__/renderInlineSetting.test.js.snap +40 -0
- package/lib/utils/__tests__/capitalize.test.js +11 -0
- package/lib/utils/__tests__/renderInlineSetting.test.js +39 -0
- package/lib/utils/capitalize.js +3 -0
- package/lib/utils/createCommand.js +3 -0
- package/lib/utils/createKeyboardShortcut.js +6 -0
- package/lib/utils/index.js +4 -0
- package/lib/utils/renderInlineSetting.js +17 -0
- package/package.json +75 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { Editor, Extension } from '@tiptap/vue-2';
|
|
2
|
+
import { ref } from '@vue/composition-api';
|
|
3
|
+
import { NodeFactory } from '../../__tests__/utils';
|
|
4
|
+
import { createCommand } from '../../utils';
|
|
5
|
+
import { CORE_EXTENSIONS } from '../core';
|
|
6
|
+
import { DeviceManager } from '../DeviceManager';
|
|
7
|
+
import { LineHeight } from '../LineHeight';
|
|
8
|
+
|
|
9
|
+
const MockStylePreset = Extension.create({
|
|
10
|
+
name: 'style_preset',
|
|
11
|
+
|
|
12
|
+
addCommands() {
|
|
13
|
+
return {
|
|
14
|
+
getPreset: createCommand(() => ref({
|
|
15
|
+
mobile: { line_height: '1.2' },
|
|
16
|
+
tablet: { line_height: '1.2' },
|
|
17
|
+
desktop: { line_height: '1.2' }
|
|
18
|
+
}))
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
function createEditor({ content }) {
|
|
24
|
+
return new Editor({
|
|
25
|
+
content,
|
|
26
|
+
extensions: CORE_EXTENSIONS.concat(
|
|
27
|
+
MockStylePreset,
|
|
28
|
+
DeviceManager.configure({ deviceRef: ref('desktop') }),
|
|
29
|
+
LineHeight
|
|
30
|
+
)
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const createContent = (attrs) => NodeFactory.doc([
|
|
35
|
+
NodeFactory.paragraph(attrs, [
|
|
36
|
+
NodeFactory.text('hello world')
|
|
37
|
+
])
|
|
38
|
+
]);
|
|
39
|
+
|
|
40
|
+
describe('get value', () => {
|
|
41
|
+
test('should get from selection', () => {
|
|
42
|
+
const editor = createEditor({
|
|
43
|
+
content: createContent({
|
|
44
|
+
line_height: { desktop: '1.4' }
|
|
45
|
+
})
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
editor.commands.selectAll();
|
|
49
|
+
|
|
50
|
+
expect(editor.commands.getLineHeight().value).toBe('1.4');
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('should get default value', () => {
|
|
54
|
+
const editor = createEditor({
|
|
55
|
+
content: createContent({ line_height: null })
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
expect(editor.commands.getDefaultLineHeight().value).toEqual('1.2');
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('should get from preset', () => {
|
|
62
|
+
const editor = createEditor({
|
|
63
|
+
content: createContent({ line_height: null })
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
expect(editor.commands.getLineHeight().value).toEqual('1.2');
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
describe('apply value', () => {
|
|
71
|
+
test('should change value', () => {
|
|
72
|
+
const editor = createEditor({
|
|
73
|
+
content: createContent({ line_height: null })
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
editor.chain().selectAll().applyLineHeight('1.41').run();
|
|
77
|
+
|
|
78
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
describe('rendering', () => {
|
|
83
|
+
test('should render only desktop', () => {
|
|
84
|
+
const editor = createEditor({
|
|
85
|
+
content: createContent({
|
|
86
|
+
line_height: { desktop: '1.3' }
|
|
87
|
+
})
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
expect(editor.getHTML()).toMatchSnapshot();
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test('should render all devices', () => {
|
|
94
|
+
const editor = createEditor({
|
|
95
|
+
content: createContent({
|
|
96
|
+
line_height: {
|
|
97
|
+
desktop: '1.6',
|
|
98
|
+
tablet: '1.4',
|
|
99
|
+
mobile: '1.21'
|
|
100
|
+
}
|
|
101
|
+
})
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
expect(editor.getHTML()).toMatchSnapshot();
|
|
105
|
+
});
|
|
106
|
+
});
|
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
import { Editor, Extension, Mark } from '@tiptap/vue-2';
|
|
2
|
+
import { ref } from '@vue/composition-api';
|
|
3
|
+
import { NodeFactory } from '../../__tests__/utils';
|
|
4
|
+
import { CORE_EXTENSIONS } from '../core';
|
|
5
|
+
import { StylePreset } from '../StylePreset';
|
|
6
|
+
import { List } from '../list';
|
|
7
|
+
import { ListTypes, NodeTypes, TextSettings } from '../../enums';
|
|
8
|
+
|
|
9
|
+
const MockFontSize = Mark.create({
|
|
10
|
+
name: TextSettings.FONT_SIZE,
|
|
11
|
+
|
|
12
|
+
addAttributes: () => ({
|
|
13
|
+
value: { default: null }
|
|
14
|
+
}),
|
|
15
|
+
|
|
16
|
+
renderHTML: () => ['span', {}, 0]
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const MockFontWeight = Mark.create({
|
|
20
|
+
name: TextSettings.FONT_WEIGHT,
|
|
21
|
+
|
|
22
|
+
addAttributes: () => ({
|
|
23
|
+
value: { default: null }
|
|
24
|
+
}),
|
|
25
|
+
|
|
26
|
+
renderHTML: () => ['span', {}, 0]
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const MockAlignment = Extension.create({
|
|
30
|
+
name: TextSettings.ALIGNMENT,
|
|
31
|
+
|
|
32
|
+
addGlobalAttributes: () => [
|
|
33
|
+
{
|
|
34
|
+
types: [NodeTypes.PARAGRAPH, NodeTypes.HEADING],
|
|
35
|
+
attributes: {
|
|
36
|
+
[TextSettings.ALIGNMENT]: {
|
|
37
|
+
default: null,
|
|
38
|
+
renderHTML: () => ({})
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
]
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
function createEditor({ content, presets, defaultId }) {
|
|
46
|
+
return new Promise((resolve) => {
|
|
47
|
+
const editor = new Editor({
|
|
48
|
+
content,
|
|
49
|
+
onCreate: () => resolve(editor),
|
|
50
|
+
|
|
51
|
+
extensions: CORE_EXTENSIONS.concat(
|
|
52
|
+
StylePreset.configure({
|
|
53
|
+
presetsRef: ref(presets),
|
|
54
|
+
defaultId,
|
|
55
|
+
|
|
56
|
+
makeVariable({ device, preset, property }) {
|
|
57
|
+
const formattedProperty = property.replace(/_/i, '-');
|
|
58
|
+
|
|
59
|
+
return `--${device}-${preset.id}-${formattedProperty}`;
|
|
60
|
+
}
|
|
61
|
+
}),
|
|
62
|
+
List.configure({
|
|
63
|
+
baseClass: 'zw-list--'
|
|
64
|
+
}),
|
|
65
|
+
MockFontSize,
|
|
66
|
+
MockFontWeight,
|
|
67
|
+
MockAlignment
|
|
68
|
+
)
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const createPreset = (attrs = {}) => ({
|
|
74
|
+
id: 'regular-1',
|
|
75
|
+
common: { font_weight: '400' },
|
|
76
|
+
mobile: { font_size: '12' },
|
|
77
|
+
tablet: { font_size: '14' },
|
|
78
|
+
desktop: { font_size: '16' },
|
|
79
|
+
...attrs
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
describe('render preset styles', () => {
|
|
83
|
+
const getStyleEl = (editor) => editor.storage.style_preset.presetStyleEl;
|
|
84
|
+
|
|
85
|
+
test('should render styles', async () => {
|
|
86
|
+
const editor = await createEditor({
|
|
87
|
+
content: NodeFactory.doc([]),
|
|
88
|
+
presets: [createPreset()]
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
expect(getStyleEl(editor).innerHTML).toMatchSnapshot();
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test('should not create multiple style elements', async () => {
|
|
95
|
+
const editor1 = await createEditor({
|
|
96
|
+
content: NodeFactory.doc([]),
|
|
97
|
+
presets: [createPreset()]
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
const editor2 = await createEditor({
|
|
101
|
+
content: NodeFactory.doc([]),
|
|
102
|
+
presets: [createPreset()]
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
expect(getStyleEl(editor1)).toBe(getStyleEl(editor2));
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test('should render preset class', async () => {
|
|
109
|
+
const editor = await createEditor({
|
|
110
|
+
content: NodeFactory.doc([
|
|
111
|
+
NodeFactory.paragraph({ preset: { id: 'regular-1' } }, 'test')
|
|
112
|
+
]),
|
|
113
|
+
presets: [createPreset({ id: 'regular-1' })]
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
expect(editor.getHTML()).toMatchSnapshot();
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test('should render node without preset', async () => {
|
|
120
|
+
const editor = await createEditor({
|
|
121
|
+
content: NodeFactory.doc([
|
|
122
|
+
NodeFactory.paragraph({ preset: null }, 'test')
|
|
123
|
+
]),
|
|
124
|
+
presets: [createPreset()]
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
expect(editor.getHTML()).toMatchSnapshot();
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
describe('get preset', () => {
|
|
132
|
+
test('should get preset from selection', async () => {
|
|
133
|
+
const editor = await createEditor({
|
|
134
|
+
content: NodeFactory.doc([
|
|
135
|
+
NodeFactory.paragraph({ preset: { id: 'regular-1' } }, 'test')
|
|
136
|
+
]),
|
|
137
|
+
presets: [createPreset({ id: 'regular-1' })]
|
|
138
|
+
});
|
|
139
|
+
const preset = editor.commands.getPreset();
|
|
140
|
+
|
|
141
|
+
expect(preset.value).toMatchSnapshot();
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test('should return null if no preset in selection', async () => {
|
|
145
|
+
const editor = await createEditor({
|
|
146
|
+
content: NodeFactory.doc([
|
|
147
|
+
NodeFactory.paragraph({ preset: null }, 'test')
|
|
148
|
+
]),
|
|
149
|
+
presets: [createPreset()]
|
|
150
|
+
});
|
|
151
|
+
const preset = editor.commands.getPreset();
|
|
152
|
+
|
|
153
|
+
expect(preset.value).toBeFalsy();
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
describe('apply preset', () => {
|
|
158
|
+
test('should apply preset to text', async () => {
|
|
159
|
+
const editor = await createEditor({
|
|
160
|
+
content: NodeFactory.doc([
|
|
161
|
+
NodeFactory.paragraph({ preset: null }, 'test')
|
|
162
|
+
]),
|
|
163
|
+
presets: [createPreset({ id: 'regular-1' })]
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
editor.chain().selectAll().applyPreset('regular-1').run();
|
|
167
|
+
|
|
168
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
test('should apply heading to text', async () => {
|
|
172
|
+
const editor = await createEditor({
|
|
173
|
+
content: NodeFactory.doc([
|
|
174
|
+
NodeFactory.paragraph({ preset: null }, 'test')
|
|
175
|
+
]),
|
|
176
|
+
presets: [
|
|
177
|
+
createPreset({ id: 'h1', node: { type: 'heading', level: 1 } })
|
|
178
|
+
]
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
editor.chain().selectAll().applyPreset('h1').run();
|
|
182
|
+
|
|
183
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
test('should change paragraph to heading', async () => {
|
|
187
|
+
const editor = await createEditor({
|
|
188
|
+
content: NodeFactory.doc([
|
|
189
|
+
NodeFactory.paragraph({ preset: { id: 'regular-1' } }, 'test')
|
|
190
|
+
]),
|
|
191
|
+
presets: [
|
|
192
|
+
createPreset({ id: 'regular-1' }),
|
|
193
|
+
createPreset({ id: 'h1', node: { type: 'heading', level: 1 } })
|
|
194
|
+
]
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
editor.chain().selectAll().applyPreset('h1').run();
|
|
198
|
+
|
|
199
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
test('should apply regular to list', async () => {
|
|
203
|
+
const editor = await createEditor({
|
|
204
|
+
content: NodeFactory.doc([
|
|
205
|
+
NodeFactory.list(ListTypes.LATIN, [
|
|
206
|
+
NodeFactory.paragraph('Item 1'),
|
|
207
|
+
NodeFactory.paragraph('Item 2')
|
|
208
|
+
])
|
|
209
|
+
]),
|
|
210
|
+
presets: [createPreset({ id: 'regular-1' })]
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
editor.chain().selectAll().applyPreset('regular-1').run();
|
|
214
|
+
|
|
215
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
test('should apply heading to list', async () => {
|
|
219
|
+
const editor = await createEditor({
|
|
220
|
+
content: NodeFactory.doc([
|
|
221
|
+
NodeFactory.list(ListTypes.LATIN, [
|
|
222
|
+
NodeFactory.paragraph('Item 1'),
|
|
223
|
+
NodeFactory.paragraph('Item 2')
|
|
224
|
+
])
|
|
225
|
+
]),
|
|
226
|
+
presets: [
|
|
227
|
+
createPreset({ id: 'h1', node: { type: 'heading', level: 1 } })
|
|
228
|
+
]
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
editor.chain().selectAll().applyPreset('h1').run();
|
|
232
|
+
|
|
233
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
test('should apply default preset', async () => {
|
|
237
|
+
const editor = await createEditor({
|
|
238
|
+
content: NodeFactory.doc([
|
|
239
|
+
NodeFactory.paragraph({ preset: null }, 'test')
|
|
240
|
+
]),
|
|
241
|
+
presets: [createPreset({ id: 'regular-1' })],
|
|
242
|
+
defaultId: 'regular-1'
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
editor.chain().selectAll().applyDefaultPreset().run();
|
|
246
|
+
|
|
247
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
test('should keep text attributes on apply', async () => {
|
|
251
|
+
const editor = await createEditor({
|
|
252
|
+
content: NodeFactory.doc([
|
|
253
|
+
NodeFactory.paragraph({
|
|
254
|
+
preset: { id: 'regular-1' },
|
|
255
|
+
alignment: { value: 'center' }
|
|
256
|
+
}, 'test')
|
|
257
|
+
]),
|
|
258
|
+
presets: [
|
|
259
|
+
createPreset({ id: 'regular-1' }),
|
|
260
|
+
createPreset({ id: 'regular-2' })
|
|
261
|
+
]
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
editor.chain().selectAll().applyPreset('regular-2').run();
|
|
265
|
+
|
|
266
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
describe('get preset customization', () => {
|
|
271
|
+
test('should return empty customization', async () => {
|
|
272
|
+
const editor = await createEditor({
|
|
273
|
+
content: NodeFactory.doc([
|
|
274
|
+
NodeFactory.paragraph({ preset: { id: 'regular-1' } }, 'test')
|
|
275
|
+
]),
|
|
276
|
+
presets: [createPreset({ id: 'regular-1' })]
|
|
277
|
+
});
|
|
278
|
+
const customization = editor.commands.getPresetCustomization();
|
|
279
|
+
|
|
280
|
+
expect(customization.value).toMatchSnapshot();
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
test('should find marks', async () => {
|
|
284
|
+
const editor = await createEditor({
|
|
285
|
+
content: NodeFactory.doc([
|
|
286
|
+
NodeFactory.paragraph({ preset: { id: 'regular-1' } }, [
|
|
287
|
+
NodeFactory.text('test', [
|
|
288
|
+
NodeFactory.mark(TextSettings.FONT_SIZE, { value: '12' }),
|
|
289
|
+
NodeFactory.mark(TextSettings.FONT_WEIGHT, { value: '400' })
|
|
290
|
+
])
|
|
291
|
+
])
|
|
292
|
+
]),
|
|
293
|
+
presets: [createPreset({ id: 'regular-1' })]
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
editor.commands.selectAll();
|
|
297
|
+
|
|
298
|
+
const customization = editor.commands.getPresetCustomization();
|
|
299
|
+
|
|
300
|
+
expect(customization.value).toMatchSnapshot();
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
test('should find attributes', async () => {
|
|
304
|
+
const editor = await createEditor({
|
|
305
|
+
content: NodeFactory.doc([
|
|
306
|
+
NodeFactory.paragraph({
|
|
307
|
+
preset: { id: 'regular-1' },
|
|
308
|
+
alignment: { value: 'center' }
|
|
309
|
+
}, 'test')
|
|
310
|
+
]),
|
|
311
|
+
presets: [createPreset({ id: 'regular-1' })]
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
editor.commands.selectAll();
|
|
315
|
+
|
|
316
|
+
const customization = editor.commands.getPresetCustomization();
|
|
317
|
+
|
|
318
|
+
expect(customization.value).toMatchSnapshot();
|
|
319
|
+
});
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
describe('remove preset customization', () => {
|
|
323
|
+
test('should remove all marks in block', async () => {
|
|
324
|
+
const editor = await createEditor({
|
|
325
|
+
content: NodeFactory.doc([
|
|
326
|
+
NodeFactory.paragraph({ preset: { id: 'regular-1' } }, [
|
|
327
|
+
NodeFactory.text('test', [
|
|
328
|
+
NodeFactory.mark(TextSettings.FONT_SIZE, { value: '12' }),
|
|
329
|
+
NodeFactory.mark(TextSettings.FONT_WEIGHT, { value: '400' })
|
|
330
|
+
]),
|
|
331
|
+
NodeFactory.text(' test', [
|
|
332
|
+
NodeFactory.mark(TextSettings.FONT_SIZE, { value: '12' })
|
|
333
|
+
])
|
|
334
|
+
])
|
|
335
|
+
]),
|
|
336
|
+
presets: [createPreset({ id: 'regular-1' })]
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
editor
|
|
340
|
+
.chain()
|
|
341
|
+
.setTextSelection({ from: 1, to: 2 })
|
|
342
|
+
.removePresetCustomization()
|
|
343
|
+
.run();
|
|
344
|
+
|
|
345
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
test('should remove all attributes', async () => {
|
|
349
|
+
const editor = await createEditor({
|
|
350
|
+
content: NodeFactory.doc([
|
|
351
|
+
NodeFactory.heading(1, {
|
|
352
|
+
preset: { id: 'regular-1' },
|
|
353
|
+
alignment: { value: 'center' }
|
|
354
|
+
}, 'heading'),
|
|
355
|
+
|
|
356
|
+
NodeFactory.paragraph({
|
|
357
|
+
preset: { id: 'regular-1' },
|
|
358
|
+
alignment: { value: 'center' }
|
|
359
|
+
}, 'paragraph')
|
|
360
|
+
]),
|
|
361
|
+
|
|
362
|
+
presets: [createPreset({ id: 'regular-1' })]
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
editor
|
|
366
|
+
.chain()
|
|
367
|
+
.setTextSelection({ from: 1, to: 10 })
|
|
368
|
+
.removePresetCustomization()
|
|
369
|
+
.run();
|
|
370
|
+
|
|
371
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
test('should keep selection', async () => {
|
|
375
|
+
const editor = await createEditor({
|
|
376
|
+
content: NodeFactory.doc([
|
|
377
|
+
NodeFactory.paragraph({ preset: { id: 'regular-1' } }, [
|
|
378
|
+
NodeFactory.text('test', [
|
|
379
|
+
NodeFactory.mark(TextSettings.FONT_SIZE, { value: '12' }),
|
|
380
|
+
NodeFactory.mark(TextSettings.FONT_WEIGHT, { value: '400' })
|
|
381
|
+
]),
|
|
382
|
+
NodeFactory.text(' test', [
|
|
383
|
+
NodeFactory.mark(TextSettings.FONT_SIZE, { value: '12' })
|
|
384
|
+
])
|
|
385
|
+
])
|
|
386
|
+
]),
|
|
387
|
+
presets: [createPreset({ id: 'regular-1' })]
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
editor
|
|
391
|
+
.chain()
|
|
392
|
+
.setTextSelection({ from: 1, to: 2 })
|
|
393
|
+
.removePresetCustomization()
|
|
394
|
+
.run();
|
|
395
|
+
|
|
396
|
+
expect(editor.state.selection).toEqual(
|
|
397
|
+
expect.objectContaining({ from: 1, to: 2 })
|
|
398
|
+
);
|
|
399
|
+
});
|
|
400
|
+
});
|