@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,168 @@
|
|
|
1
|
+
import { Extension } from '@tiptap/vue-2';
|
|
2
|
+
import { computed, toRef } from '@vue/composition-api';
|
|
3
|
+
import { Heading } from '@tiptap/extension-heading';
|
|
4
|
+
import { createCommand } from '../utils';
|
|
5
|
+
import { Devices, NodeTypes, TextSettings } from '../enums';
|
|
6
|
+
|
|
7
|
+
export const StylePreset = Extension.create({
|
|
8
|
+
name: 'style_preset',
|
|
9
|
+
|
|
10
|
+
addExtensions: () => [
|
|
11
|
+
Heading.configure({
|
|
12
|
+
levels: [1, 2, 3, 4],
|
|
13
|
+
HTMLAttributes: { class: 'zw-style' }
|
|
14
|
+
})
|
|
15
|
+
],
|
|
16
|
+
|
|
17
|
+
addOptions: () => ({
|
|
18
|
+
presetsRef: null,
|
|
19
|
+
defaultId: null,
|
|
20
|
+
makeVariable: null
|
|
21
|
+
}),
|
|
22
|
+
|
|
23
|
+
addStorage: () => ({
|
|
24
|
+
presetStyleEl: null
|
|
25
|
+
}),
|
|
26
|
+
|
|
27
|
+
addGlobalAttributes() {
|
|
28
|
+
return [
|
|
29
|
+
{
|
|
30
|
+
types: [NodeTypes.PARAGRAPH, NodeTypes.HEADING],
|
|
31
|
+
attributes: {
|
|
32
|
+
preset: {
|
|
33
|
+
isRequired: false,
|
|
34
|
+
default: { id: this.options.defaultId },
|
|
35
|
+
renderHTML: (attrs) => {
|
|
36
|
+
if (!attrs.preset) return null;
|
|
37
|
+
|
|
38
|
+
return { class: `zw-preset--${attrs.preset.id}` };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
];
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
addCommands() {
|
|
47
|
+
function findPresetById(presets, id) {
|
|
48
|
+
return presets.find((preset) => id === preset.id);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
getPresetList: createCommand(() => computed(() => {
|
|
53
|
+
return this.options.presetsRef.value.filter((preset) => !preset.hidden);
|
|
54
|
+
})),
|
|
55
|
+
|
|
56
|
+
getPreset: createCommand(({ commands }) => {
|
|
57
|
+
const selection = commands.getBlockAttributes('preset', { id: this.options.defaultId });
|
|
58
|
+
const presets = commands.getPresetList();
|
|
59
|
+
|
|
60
|
+
return computed(() => findPresetById(presets.value, selection.value.id));
|
|
61
|
+
}),
|
|
62
|
+
|
|
63
|
+
applyPreset: createCommand(({ commands, chain }, presetId) => {
|
|
64
|
+
const presets = commands.getPresetList().value;
|
|
65
|
+
const preset = findPresetById(presets, presetId);
|
|
66
|
+
const nodeType = preset.node?.type ?? NodeTypes.PARAGRAPH;
|
|
67
|
+
|
|
68
|
+
const attrs = {
|
|
69
|
+
preset: { id: presetId }
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
if (preset.node) {
|
|
73
|
+
attrs.level = preset.node.level;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
for (const textAttribute of TextSettings.attributes) {
|
|
77
|
+
attrs[textAttribute] = commands.getBlockAttributes(textAttribute).value;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
chain().removeList().setNode(nodeType, attrs).run();
|
|
81
|
+
}),
|
|
82
|
+
|
|
83
|
+
applyDefaultPreset: createCommand(({ commands }) => {
|
|
84
|
+
commands.applyPreset(this.options.defaultId);
|
|
85
|
+
}),
|
|
86
|
+
|
|
87
|
+
removePreset: createCommand(({ commands }) => {
|
|
88
|
+
commands.setNode(NodeTypes.PARAGRAPH, { preset: null });
|
|
89
|
+
}),
|
|
90
|
+
|
|
91
|
+
getPresetCustomization: createCommand(({ editor }) => {
|
|
92
|
+
const state = toRef(editor, 'state');
|
|
93
|
+
|
|
94
|
+
return computed(() => {
|
|
95
|
+
const attributes = new Set();
|
|
96
|
+
const marks = new Set();
|
|
97
|
+
const { from, to } = state.value.selection;
|
|
98
|
+
|
|
99
|
+
state.value.doc.nodesBetween(from, to, (node) => {
|
|
100
|
+
for (const [name, value] of Object.entries(node.attrs)) {
|
|
101
|
+
const isSetting = TextSettings.attributes.includes(name);
|
|
102
|
+
|
|
103
|
+
if (isSetting && value) attributes.add(name);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
for (const { type } of node.marks) {
|
|
107
|
+
if (TextSettings.marks.includes(type.name)) {
|
|
108
|
+
marks.add(type.name);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
return {
|
|
114
|
+
attributes: Array.from(attributes),
|
|
115
|
+
marks: Array.from(marks)
|
|
116
|
+
};
|
|
117
|
+
});
|
|
118
|
+
}),
|
|
119
|
+
|
|
120
|
+
removePresetCustomization: createCommand(({ chain }) => {
|
|
121
|
+
chain()
|
|
122
|
+
.storeSelection()
|
|
123
|
+
.expandSelectionToBlock()
|
|
124
|
+
.unsetAllMarks()
|
|
125
|
+
.resetAttributes(NodeTypes.PARAGRAPH, TextSettings.attributes)
|
|
126
|
+
.resetAttributes(NodeTypes.HEADING, TextSettings.attributes)
|
|
127
|
+
.restoreSelection()
|
|
128
|
+
.run();
|
|
129
|
+
}),
|
|
130
|
+
|
|
131
|
+
removeFormat: createCommand(({ commands }) => {
|
|
132
|
+
commands.removePresetCustomization();
|
|
133
|
+
commands.applyDefaultPreset();
|
|
134
|
+
})
|
|
135
|
+
};
|
|
136
|
+
},
|
|
137
|
+
|
|
138
|
+
onCreate() {
|
|
139
|
+
const existingStyleEl = document.querySelector('[data-zw-styles]');
|
|
140
|
+
|
|
141
|
+
if (existingStyleEl) {
|
|
142
|
+
this.storage.presetStyleEl = existingStyleEl;
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
this.storage.presetStyleEl = document.createElement('style');
|
|
147
|
+
this.storage.presetStyleEl.dataset.zwStyles = '';
|
|
148
|
+
|
|
149
|
+
for (const preset of this.options.presetsRef.value) {
|
|
150
|
+
const css = [` .zw-preset--${preset.id} {`];
|
|
151
|
+
|
|
152
|
+
for (const device of Devices.values) {
|
|
153
|
+
for (const setting of Object.keys(preset[device])) {
|
|
154
|
+
const variable = this.options.makeVariable({ device, preset, property: setting });
|
|
155
|
+
const property = setting.replace(/_/i, '-');
|
|
156
|
+
const prefix = device === Devices.COMMON ? 'preset' : `preset-${device}`;
|
|
157
|
+
|
|
158
|
+
css.push(`--zw-${prefix}-${property}: var(${variable}, inherit);`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
css.push('}');
|
|
163
|
+
this.storage.presetStyleEl.innerHTML += css.join(' ');
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
document.head.append(this.storage.presetStyleEl);
|
|
167
|
+
}
|
|
168
|
+
});
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { Mark } from '@tiptap/vue-2';
|
|
2
|
+
import { computed } from '@vue/composition-api';
|
|
3
|
+
import { createCommand, createKeyboardShortcut, renderMark } from '../utils';
|
|
4
|
+
import { TextSettings } from '../enums';
|
|
5
|
+
|
|
6
|
+
export const TextDecoration = Mark.create({
|
|
7
|
+
name: TextSettings.TEXT_DECORATION,
|
|
8
|
+
|
|
9
|
+
addAttributes: () => ({
|
|
10
|
+
underline: { default: false },
|
|
11
|
+
strike_through: { default: false }
|
|
12
|
+
}),
|
|
13
|
+
|
|
14
|
+
addCommands() {
|
|
15
|
+
return {
|
|
16
|
+
isUnderline: createCommand(({ commands }) => {
|
|
17
|
+
const decoration = commands.getTextDecoration();
|
|
18
|
+
|
|
19
|
+
return computed(() => decoration.value.underline);
|
|
20
|
+
}),
|
|
21
|
+
|
|
22
|
+
isStrikeThrough: createCommand(({ commands }) => {
|
|
23
|
+
const decoration = commands.getTextDecoration();
|
|
24
|
+
|
|
25
|
+
return computed(() => decoration.value.strike_through);
|
|
26
|
+
}),
|
|
27
|
+
|
|
28
|
+
getTextDecoration: createCommand(({ editor, commands }) => {
|
|
29
|
+
const defaultValue = commands.getDefaultTextDecoration();
|
|
30
|
+
|
|
31
|
+
return computed(() => {
|
|
32
|
+
const attrs = editor.getAttributes(this.name) ?? {};
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
underline: attrs.underline ?? defaultValue.value.underline,
|
|
36
|
+
strike_through: attrs.strike_through ?? defaultValue.value.strike_through
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
}),
|
|
40
|
+
|
|
41
|
+
getDefaultTextDecoration: createCommand(({ commands }) => {
|
|
42
|
+
const preset = commands.getPreset();
|
|
43
|
+
|
|
44
|
+
return computed(() => {
|
|
45
|
+
const decoration = preset.value.common.text_decoration;
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
underline: decoration.includes('underline'),
|
|
49
|
+
strike_through: decoration.includes('line-through')
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
}),
|
|
53
|
+
|
|
54
|
+
toggleUnderline: createCommand(({ commands }) => {
|
|
55
|
+
commands.toggleTextDecoration('underline');
|
|
56
|
+
}),
|
|
57
|
+
|
|
58
|
+
toggleStrikeThrough: createCommand(({ commands }) => {
|
|
59
|
+
commands.toggleTextDecoration('strike_through');
|
|
60
|
+
}),
|
|
61
|
+
|
|
62
|
+
toggleTextDecoration: createCommand(({ commands }, name) => {
|
|
63
|
+
const isEnabled = commands.getTextDecoration().value[name];
|
|
64
|
+
|
|
65
|
+
isEnabled ? commands.removeTextDecoration(name) : commands.applyTextDecoration(name);
|
|
66
|
+
}),
|
|
67
|
+
|
|
68
|
+
applyTextDecoration: createCommand(({ commands }, name) => {
|
|
69
|
+
commands.setMark(this.name, { [name]: true });
|
|
70
|
+
}),
|
|
71
|
+
|
|
72
|
+
removeTextDecoration: createCommand(({ commands }, name) => {
|
|
73
|
+
const mark = {
|
|
74
|
+
...commands.getTextDecoration().value,
|
|
75
|
+
[name]: false
|
|
76
|
+
};
|
|
77
|
+
const isRemoveMark = !mark.underline && !mark.strike_through;
|
|
78
|
+
|
|
79
|
+
isRemoveMark ? commands.unsetMark(this.name) : commands.setMark(this.name, mark);
|
|
80
|
+
})
|
|
81
|
+
};
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
addKeyboardShortcuts: () => ({
|
|
85
|
+
'Mod-u': createKeyboardShortcut('toggleUnderline'),
|
|
86
|
+
'Mod-U': createKeyboardShortcut('toggleUnderline')
|
|
87
|
+
}),
|
|
88
|
+
|
|
89
|
+
renderHTML({ HTMLAttributes: attrs }) {
|
|
90
|
+
const decorations = [];
|
|
91
|
+
|
|
92
|
+
if (attrs.underline) decorations.push('underline');
|
|
93
|
+
if (attrs.strike_through) decorations.push('line-through');
|
|
94
|
+
|
|
95
|
+
return renderMark({ text_decoration: decorations.join(' ') });
|
|
96
|
+
}
|
|
97
|
+
});
|
|
@@ -0,0 +1,107 @@
|
|
|
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 { Alignment } from '../Alignment';
|
|
7
|
+
import { DeviceManager } from '../DeviceManager';
|
|
8
|
+
import { Alignments } from '../../enums';
|
|
9
|
+
|
|
10
|
+
const MockStylePreset = Extension.create({
|
|
11
|
+
name: 'style_preset',
|
|
12
|
+
|
|
13
|
+
addCommands() {
|
|
14
|
+
return {
|
|
15
|
+
getPreset: createCommand(() => ref({
|
|
16
|
+
mobile: { alignment: Alignments.JUSTIFY },
|
|
17
|
+
tablet: { alignment: Alignments.JUSTIFY },
|
|
18
|
+
desktop: { alignment: Alignments.JUSTIFY }
|
|
19
|
+
}))
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
function createEditor({ content }) {
|
|
25
|
+
return new Editor({
|
|
26
|
+
content,
|
|
27
|
+
extensions: CORE_EXTENSIONS.concat(
|
|
28
|
+
MockStylePreset,
|
|
29
|
+
DeviceManager.configure({ deviceRef: ref('desktop') }),
|
|
30
|
+
Alignment
|
|
31
|
+
)
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const createContent = (attrs) => NodeFactory.doc([
|
|
36
|
+
NodeFactory.paragraph(attrs, [
|
|
37
|
+
NodeFactory.text('hello world')
|
|
38
|
+
])
|
|
39
|
+
]);
|
|
40
|
+
|
|
41
|
+
describe('get value', () => {
|
|
42
|
+
test('should get from selection', () => {
|
|
43
|
+
const editor = createEditor({
|
|
44
|
+
content: createContent({
|
|
45
|
+
alignment: { desktop: Alignments.CENTER }
|
|
46
|
+
})
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
editor.commands.selectAll();
|
|
50
|
+
|
|
51
|
+
expect(editor.commands.getAlignment().value).toEqual(Alignments.CENTER);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('should get default value', () => {
|
|
55
|
+
const editor = createEditor({
|
|
56
|
+
content: createContent({ alignment: null })
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
expect(editor.commands.getDefaultAlignment().value).toEqual(Alignments.JUSTIFY);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test('should get from preset', () => {
|
|
63
|
+
const editor = createEditor({
|
|
64
|
+
content: createContent({ alignment: null })
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
expect(editor.commands.getAlignment().value).toEqual(Alignments.JUSTIFY);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe('apply value', () => {
|
|
72
|
+
test('should change value', () => {
|
|
73
|
+
const editor = createEditor({
|
|
74
|
+
content: createContent({ alignment: null })
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
editor.chain().selectAll().applyAlignment(Alignments.RIGHT).run();
|
|
78
|
+
|
|
79
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe('rendering', () => {
|
|
84
|
+
test('should render only desktop', () => {
|
|
85
|
+
const editor = createEditor({
|
|
86
|
+
content: createContent({
|
|
87
|
+
alignment: { desktop: Alignments.CENTER }
|
|
88
|
+
})
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
expect(editor.getHTML()).toMatchSnapshot();
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test('should render all devices', () => {
|
|
95
|
+
const editor = createEditor({
|
|
96
|
+
content: createContent({
|
|
97
|
+
alignment: {
|
|
98
|
+
desktop: Alignments.CENTER,
|
|
99
|
+
tablet: Alignments.RIGHT,
|
|
100
|
+
mobile: Alignments.LEFT
|
|
101
|
+
}
|
|
102
|
+
})
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
expect(editor.getHTML()).toMatchSnapshot();
|
|
106
|
+
});
|
|
107
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
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 { BackgroundColor } from '../BackgroundColor';
|
|
7
|
+
|
|
8
|
+
const MockStylePreset = Extension.create({
|
|
9
|
+
name: 'style_preset',
|
|
10
|
+
|
|
11
|
+
addCommands() {
|
|
12
|
+
return {
|
|
13
|
+
getPreset: createCommand(() => ref({
|
|
14
|
+
common: { background_color: 'red' }
|
|
15
|
+
}))
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
function createEditor({ content }) {
|
|
21
|
+
return new Editor({
|
|
22
|
+
content,
|
|
23
|
+
extensions: CORE_EXTENSIONS.concat(MockStylePreset, BackgroundColor)
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const createContent = (text) => NodeFactory.doc([
|
|
28
|
+
NodeFactory.paragraph([text])
|
|
29
|
+
]);
|
|
30
|
+
|
|
31
|
+
describe('get background color', () => {
|
|
32
|
+
test('should get from selection', () => {
|
|
33
|
+
const editor = createEditor({
|
|
34
|
+
content: createContent(NodeFactory.text('hello world', [
|
|
35
|
+
NodeFactory.mark('background_color', { value: 'green' })
|
|
36
|
+
]))
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
editor.commands.selectAll();
|
|
40
|
+
|
|
41
|
+
expect(editor.commands.getBackgroundColor().value).toEqual('green');
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('should get default background color', () => {
|
|
45
|
+
const editor = createEditor({
|
|
46
|
+
content: createContent(NodeFactory.text('hello world'))
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
expect(editor.commands.getBackgroundColor().value).toEqual('rgba(255, 255, 255, 0%)');
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe('apply background color', () => {
|
|
54
|
+
test('should change background color', () => {
|
|
55
|
+
const editor = createEditor({
|
|
56
|
+
content: createContent(NodeFactory.text('hello world'))
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
editor.chain().selectAll().applyBackgroundColor('green').run();
|
|
60
|
+
|
|
61
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
describe('rendering', () => {
|
|
66
|
+
test('should render html', () => {
|
|
67
|
+
const editor = createEditor({
|
|
68
|
+
content: createContent(NodeFactory.text('hello world', [
|
|
69
|
+
NodeFactory.mark('background_color', { value: 'green' })
|
|
70
|
+
]))
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
expect(editor.getHTML()).toMatchSnapshot();
|
|
74
|
+
});
|
|
75
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Editor } from '@tiptap/vue-2';
|
|
2
|
+
import { NodeFactory } from '../../__tests__/utils';
|
|
3
|
+
import { CaseStyles } from '../../enums';
|
|
4
|
+
import { CORE_EXTENSIONS } from '../core';
|
|
5
|
+
import { CaseStyle } from '../CaseStyle';
|
|
6
|
+
|
|
7
|
+
function createEditor({ content }) {
|
|
8
|
+
return new Editor({
|
|
9
|
+
content,
|
|
10
|
+
extensions: CORE_EXTENSIONS.concat(CaseStyle)
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const createContent = (text) => NodeFactory.doc([
|
|
15
|
+
NodeFactory.paragraph([text])
|
|
16
|
+
]);
|
|
17
|
+
|
|
18
|
+
describe('apply case style', () => {
|
|
19
|
+
test('should apply capitalize', () => {
|
|
20
|
+
const editor = createEditor({
|
|
21
|
+
content: createContent(NodeFactory.text('hello world'))
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
editor.chain().selectAll().applyCapitalize().run();
|
|
25
|
+
|
|
26
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('should apply lowercase', () => {
|
|
30
|
+
const editor = createEditor({
|
|
31
|
+
content: createContent(NodeFactory.text('HeLlO wOrLd'))
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
editor.chain().selectAll().applyLowerCase().run();
|
|
35
|
+
|
|
36
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('should apply uppercase', () => {
|
|
40
|
+
const editor = createEditor({
|
|
41
|
+
content: createContent(NodeFactory.text('hello world'))
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
editor.chain().selectAll().applyUpperCase().run();
|
|
45
|
+
|
|
46
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('should apply case by type', () => {
|
|
50
|
+
const editor = createEditor({
|
|
51
|
+
content: createContent(NodeFactory.text('hello world'))
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
editor.chain().selectAll().applyCaseStyle(CaseStyles.CAPITALIZE).run();
|
|
55
|
+
|
|
56
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
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 { FontColor } from '../FontColor';
|
|
7
|
+
|
|
8
|
+
const MockStylePreset = Extension.create({
|
|
9
|
+
name: 'style_preset',
|
|
10
|
+
|
|
11
|
+
addCommands() {
|
|
12
|
+
return {
|
|
13
|
+
getPreset: createCommand(() => ref({
|
|
14
|
+
common: { color: 'red' }
|
|
15
|
+
}))
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
function createEditor({ content }) {
|
|
21
|
+
return new Editor({
|
|
22
|
+
content,
|
|
23
|
+
extensions: CORE_EXTENSIONS.concat(MockStylePreset, FontColor)
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const createContent = (text) => NodeFactory.doc([
|
|
28
|
+
NodeFactory.paragraph([text])
|
|
29
|
+
]);
|
|
30
|
+
|
|
31
|
+
describe('get font color', () => {
|
|
32
|
+
test('should get from selection', () => {
|
|
33
|
+
const editor = createEditor({
|
|
34
|
+
content: createContent(NodeFactory.text('hello world', [
|
|
35
|
+
NodeFactory.mark('font_color', { value: 'green' })
|
|
36
|
+
]))
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
editor.commands.selectAll();
|
|
40
|
+
|
|
41
|
+
expect(editor.commands.getFontColor().value).toEqual('green');
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('should get default font color', () => {
|
|
45
|
+
const editor = createEditor({
|
|
46
|
+
content: createContent(NodeFactory.text('hello world'))
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
expect(editor.commands.getDefaultFontColor().value).toEqual('red');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('should get from preset', () => {
|
|
53
|
+
const editor = createEditor({
|
|
54
|
+
content: createContent(NodeFactory.text('hello world'))
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
editor.commands.selectAll();
|
|
58
|
+
|
|
59
|
+
expect(editor.commands.getFontColor().value).toEqual('red');
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe('apply font color', () => {
|
|
64
|
+
test('should change font color', () => {
|
|
65
|
+
const editor = createEditor({
|
|
66
|
+
content: createContent(NodeFactory.text('hello world'))
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
editor.chain().selectAll().applyFontColor('green').run();
|
|
70
|
+
|
|
71
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe('rendering', () => {
|
|
76
|
+
test('should render html', () => {
|
|
77
|
+
const editor = createEditor({
|
|
78
|
+
content: createContent(NodeFactory.text('hello world', [
|
|
79
|
+
NodeFactory.mark('font_color', { value: 'green' })
|
|
80
|
+
]))
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
expect(editor.getHTML()).toMatchSnapshot();
|
|
84
|
+
});
|
|
85
|
+
});
|