@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,37 @@
|
|
|
1
|
+
const dataStorage = new WeakMap();
|
|
2
|
+
|
|
3
|
+
export const outClick = {
|
|
4
|
+
bind(el, { value }) {
|
|
5
|
+
const onOutClick = value.onOutClick || value;
|
|
6
|
+
const isEnabled = !value.isDisabled;
|
|
7
|
+
|
|
8
|
+
function onClick(event) {
|
|
9
|
+
const isInside = event.target === el || el.contains(event.target);
|
|
10
|
+
|
|
11
|
+
if (event.target.isConnected && !isInside) onOutClick(event);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
dataStorage.set(el, { callback: onClick, isEnabled });
|
|
15
|
+
|
|
16
|
+
if (isEnabled) {
|
|
17
|
+
setTimeout(() => document.addEventListener('click', onClick));
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
update(el, { value }) {
|
|
22
|
+
const data = dataStorage.get(el);
|
|
23
|
+
const isEnabled = !value.isDisabled;
|
|
24
|
+
|
|
25
|
+
if (isEnabled === data.isEnabled) return;
|
|
26
|
+
|
|
27
|
+
isEnabled
|
|
28
|
+
? document.addEventListener('click', data.callback)
|
|
29
|
+
: document.removeEventListener('click', data.callback);
|
|
30
|
+
|
|
31
|
+
dataStorage.set(el, { callback: data.callback, isEnabled });
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
unbind(el) {
|
|
35
|
+
document.removeEventListener('click', dataStorage.get(el).callback);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export const ListTypes = Object.freeze({
|
|
2
|
+
DISC: 'disc',
|
|
3
|
+
CIRCLE: 'circle',
|
|
4
|
+
SQUARE: 'square',
|
|
5
|
+
DECIMAL: 'decimal',
|
|
6
|
+
ROMAN: 'roman',
|
|
7
|
+
LATIN: 'latin',
|
|
8
|
+
|
|
9
|
+
get values() {
|
|
10
|
+
return [
|
|
11
|
+
this.DISC,
|
|
12
|
+
this.CIRCLE,
|
|
13
|
+
this.SQUARE,
|
|
14
|
+
this.DECIMAL,
|
|
15
|
+
this.ROMAN,
|
|
16
|
+
this.LATIN
|
|
17
|
+
];
|
|
18
|
+
},
|
|
19
|
+
|
|
20
|
+
get ordered() {
|
|
21
|
+
return [this.DECIMAL, this.ROMAN, this.LATIN];
|
|
22
|
+
}
|
|
23
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export const TextSettings = Object.freeze({
|
|
2
|
+
ALIGNMENT: 'alignment',
|
|
3
|
+
BACKGROUND_COLOR: 'background_color',
|
|
4
|
+
FONT_COLOR: 'font_color',
|
|
5
|
+
FONT_FAMILY: 'font_family',
|
|
6
|
+
FONT_SIZE: 'font_size',
|
|
7
|
+
FONT_STYLE: 'font_style',
|
|
8
|
+
FONT_WEIGHT: 'font_weight',
|
|
9
|
+
LINE_HEIGHT: 'line_height',
|
|
10
|
+
TEXT_DECORATION: 'text_decoration',
|
|
11
|
+
|
|
12
|
+
get attributes() {
|
|
13
|
+
return [
|
|
14
|
+
this.ALIGNMENT,
|
|
15
|
+
this.LINE_HEIGHT
|
|
16
|
+
];
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
get marks() {
|
|
20
|
+
return [
|
|
21
|
+
this.BACKGROUND_COLOR,
|
|
22
|
+
this.FONT_COLOR,
|
|
23
|
+
this.FONT_FAMILY,
|
|
24
|
+
this.FONT_SIZE,
|
|
25
|
+
this.FONT_STYLE,
|
|
26
|
+
this.FONT_WEIGHT,
|
|
27
|
+
this.TEXT_DECORATION
|
|
28
|
+
];
|
|
29
|
+
}
|
|
30
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Extension } from '@tiptap/vue-2';
|
|
2
|
+
import { computed } from '@vue/composition-api';
|
|
3
|
+
import { createCommand, createKeyboardShortcut, renderInlineSetting } from '../utils';
|
|
4
|
+
import { Alignments, NodeTypes, TextSettings } from '../enums';
|
|
5
|
+
|
|
6
|
+
const DEFAULTS = {
|
|
7
|
+
mobile: null,
|
|
8
|
+
tablet: null,
|
|
9
|
+
desktop: null
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const Alignment = Extension.create({
|
|
13
|
+
name: TextSettings.ALIGNMENT,
|
|
14
|
+
|
|
15
|
+
addGlobalAttributes: () => [
|
|
16
|
+
{
|
|
17
|
+
types: [NodeTypes.PARAGRAPH, NodeTypes.HEADING],
|
|
18
|
+
attributes: {
|
|
19
|
+
[TextSettings.ALIGNMENT]: {
|
|
20
|
+
isRequired: false,
|
|
21
|
+
|
|
22
|
+
renderHTML(attrs) {
|
|
23
|
+
if (!attrs.alignment) return null;
|
|
24
|
+
|
|
25
|
+
return renderInlineSetting({
|
|
26
|
+
mobile_text_align: attrs.alignment.mobile,
|
|
27
|
+
tablet_text_align: attrs.alignment.tablet,
|
|
28
|
+
desktop_text_align: attrs.alignment.desktop
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
],
|
|
35
|
+
|
|
36
|
+
addCommands() {
|
|
37
|
+
return {
|
|
38
|
+
applyAlignment: createCommand(({ commands }, value) => {
|
|
39
|
+
const device = commands.getDevice().value;
|
|
40
|
+
|
|
41
|
+
commands.setBlockAttributes(this.name, { [device]: value }, DEFAULTS);
|
|
42
|
+
}),
|
|
43
|
+
|
|
44
|
+
getAlignment: createCommand(({ commands }) => {
|
|
45
|
+
const attribute = commands.getBlockAttributes(this.name, DEFAULTS);
|
|
46
|
+
const device = commands.getDevice();
|
|
47
|
+
const defaultValue = commands.getDefaultAlignment();
|
|
48
|
+
|
|
49
|
+
return computed(() => attribute.value?.[device.value] ?? defaultValue.value);
|
|
50
|
+
}),
|
|
51
|
+
|
|
52
|
+
getDefaultAlignment: createCommand(({ commands }) => {
|
|
53
|
+
const device = commands.getDevice();
|
|
54
|
+
const preset = commands.getPreset();
|
|
55
|
+
|
|
56
|
+
return computed(() => preset.value[device.value].alignment);
|
|
57
|
+
})
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
addKeyboardShortcuts: () => ({
|
|
62
|
+
'Mod-Shift-l': createKeyboardShortcut('applyAlignment', Alignments.LEFT),
|
|
63
|
+
'Mod-Shift-e': createKeyboardShortcut('applyAlignment', Alignments.CENTER),
|
|
64
|
+
'Mod-Shift-r': createKeyboardShortcut('applyAlignment', Alignments.RIGHT),
|
|
65
|
+
'Mod-Shift-j': createKeyboardShortcut('applyAlignment', Alignments.JUSTIFY)
|
|
66
|
+
})
|
|
67
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Mark } from '@tiptap/vue-2';
|
|
2
|
+
import { computed } from '@vue/composition-api';
|
|
3
|
+
import { createCommand, renderMark } from '../utils';
|
|
4
|
+
import { TextSettings } from '../enums';
|
|
5
|
+
|
|
6
|
+
export const BackgroundColor = Mark.create({
|
|
7
|
+
name: TextSettings.BACKGROUND_COLOR,
|
|
8
|
+
|
|
9
|
+
addAttributes: () => ({
|
|
10
|
+
value: { required: true }
|
|
11
|
+
}),
|
|
12
|
+
|
|
13
|
+
addCommands() {
|
|
14
|
+
return {
|
|
15
|
+
getBackgroundColor: createCommand(({ editor }) => {
|
|
16
|
+
return computed(() => editor.getAttributes(this.name)?.value ?? 'rgba(255, 255, 255, 0%)');
|
|
17
|
+
}),
|
|
18
|
+
|
|
19
|
+
applyBackgroundColor: createCommand(({ commands }, value) => {
|
|
20
|
+
commands.setMark(this.name, { value });
|
|
21
|
+
})
|
|
22
|
+
};
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
renderHTML({ HTMLAttributes: attrs }) {
|
|
26
|
+
return renderMark({ background_color: attrs.value });
|
|
27
|
+
}
|
|
28
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Extension } from '@tiptap/vue-2';
|
|
2
|
+
import { capitalize, createCommand } from '../utils';
|
|
3
|
+
import { CaseStyles } from '../enums';
|
|
4
|
+
|
|
5
|
+
export const CaseStyle = Extension.create({
|
|
6
|
+
name: 'case_style',
|
|
7
|
+
|
|
8
|
+
addCommands() {
|
|
9
|
+
return {
|
|
10
|
+
applyCaseStyle: createCommand(({ commands }, value) => {
|
|
11
|
+
switch (value) {
|
|
12
|
+
case CaseStyles.CAPITALIZE:
|
|
13
|
+
return commands.applyCapitalize();
|
|
14
|
+
|
|
15
|
+
case CaseStyles.LOWERCASE:
|
|
16
|
+
return commands.applyLowerCase();
|
|
17
|
+
|
|
18
|
+
case CaseStyles.UPPERCASE:
|
|
19
|
+
return commands.applyUpperCase();
|
|
20
|
+
}
|
|
21
|
+
}),
|
|
22
|
+
|
|
23
|
+
applyCapitalize: createCommand(({ commands }) => {
|
|
24
|
+
commands.transformText(({ text }) => capitalize(text));
|
|
25
|
+
}),
|
|
26
|
+
|
|
27
|
+
applyLowerCase: createCommand(({ commands }) => {
|
|
28
|
+
commands.transformText(({ text }) => text.toLowerCase());
|
|
29
|
+
}),
|
|
30
|
+
|
|
31
|
+
applyUpperCase: createCommand(({ commands }) => {
|
|
32
|
+
commands.transformText(({ text }) => text.toUpperCase());
|
|
33
|
+
})
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Extension } from '@tiptap/vue-2';
|
|
2
|
+
import { createCommand } from '../utils';
|
|
3
|
+
|
|
4
|
+
export const DeviceManager = Extension.create({
|
|
5
|
+
name: 'device_manager',
|
|
6
|
+
|
|
7
|
+
addOptions: () => ({
|
|
8
|
+
deviceRef: null
|
|
9
|
+
}),
|
|
10
|
+
|
|
11
|
+
addCommands() {
|
|
12
|
+
return {
|
|
13
|
+
getDevice: createCommand(() => this.options.deviceRef)
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Mark } from '@tiptap/vue-2';
|
|
2
|
+
import { computed } from '@vue/composition-api';
|
|
3
|
+
import { createCommand, renderMark } from '../utils';
|
|
4
|
+
import { TextSettings } from '../enums';
|
|
5
|
+
|
|
6
|
+
export const FontColor = Mark.create({
|
|
7
|
+
name: TextSettings.FONT_COLOR,
|
|
8
|
+
|
|
9
|
+
addAttributes: () => ({
|
|
10
|
+
value: { required: true }
|
|
11
|
+
}),
|
|
12
|
+
|
|
13
|
+
addCommands() {
|
|
14
|
+
return {
|
|
15
|
+
getFontColor: createCommand(({ commands, editor }) => {
|
|
16
|
+
const defaultValue = commands.getDefaultFontColor();
|
|
17
|
+
|
|
18
|
+
return computed(() => editor.getAttributes(this.name)?.value ?? defaultValue.value);
|
|
19
|
+
}),
|
|
20
|
+
|
|
21
|
+
getDefaultFontColor: createCommand(({ commands }) => {
|
|
22
|
+
const preset = commands.getPreset();
|
|
23
|
+
|
|
24
|
+
return computed(() => preset.value.common.color);
|
|
25
|
+
}),
|
|
26
|
+
|
|
27
|
+
applyFontColor: createCommand(({ commands }, value) => {
|
|
28
|
+
commands.setMark(this.name, { value });
|
|
29
|
+
})
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
renderHTML({ HTMLAttributes: attrs }) {
|
|
34
|
+
return renderMark({ font_color: attrs.value });
|
|
35
|
+
}
|
|
36
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Mark } from '@tiptap/vue-2';
|
|
2
|
+
import { computed } from '@vue/composition-api';
|
|
3
|
+
import { createCommand, renderMark } from '../utils';
|
|
4
|
+
import { TextSettings } from '../enums';
|
|
5
|
+
|
|
6
|
+
export const FontFamily = Mark.create({
|
|
7
|
+
name: TextSettings.FONT_FAMILY,
|
|
8
|
+
|
|
9
|
+
addOptions: () => ({
|
|
10
|
+
fonts: []
|
|
11
|
+
}),
|
|
12
|
+
|
|
13
|
+
addAttributes: () => ({
|
|
14
|
+
value: { required: true }
|
|
15
|
+
}),
|
|
16
|
+
|
|
17
|
+
addCommands() {
|
|
18
|
+
return {
|
|
19
|
+
applyFontFamily: createCommand(({ commands }, value) => {
|
|
20
|
+
commands.setMark(this.name, { value });
|
|
21
|
+
|
|
22
|
+
const font = commands.findFontByName(value);
|
|
23
|
+
let fontWeight = commands.getFontWeight().value;
|
|
24
|
+
|
|
25
|
+
if (!font.isWeightSupported(fontWeight)) {
|
|
26
|
+
fontWeight = font.findClosestWeight(fontWeight);
|
|
27
|
+
commands.applyFontWeight(fontWeight);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!font.isItalicSupported(fontWeight)) {
|
|
31
|
+
commands.removeItalic();
|
|
32
|
+
}
|
|
33
|
+
}),
|
|
34
|
+
|
|
35
|
+
getFont: createCommand(({ commands }) => {
|
|
36
|
+
const fontFamily = commands.getFontFamily();
|
|
37
|
+
|
|
38
|
+
return computed(() => commands.findFontByName(fontFamily.value));
|
|
39
|
+
}),
|
|
40
|
+
|
|
41
|
+
findFontByName: createCommand((_, name) => {
|
|
42
|
+
return this.options.fonts.find((font) => font.name === name);
|
|
43
|
+
}),
|
|
44
|
+
|
|
45
|
+
getFontFamily: createCommand(({ editor, commands }) => {
|
|
46
|
+
const defaultValue = commands.getDefaultFontFamily();
|
|
47
|
+
|
|
48
|
+
return computed(() => editor.getAttributes(this.name)?.value ?? defaultValue.value);
|
|
49
|
+
}),
|
|
50
|
+
|
|
51
|
+
getDefaultFontFamily: createCommand(({ commands }) => {
|
|
52
|
+
const preset = commands.getPreset();
|
|
53
|
+
|
|
54
|
+
return computed(() => preset.value.common.font_family);
|
|
55
|
+
})
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
renderHTML({ HTMLAttributes: attrs }) {
|
|
60
|
+
return renderMark({ font_family: attrs.value });
|
|
61
|
+
}
|
|
62
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
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 FontSize = Mark.create({
|
|
7
|
+
name: TextSettings.FONT_SIZE,
|
|
8
|
+
|
|
9
|
+
addOptions: () => ({
|
|
10
|
+
minSize: 1,
|
|
11
|
+
maxSize: 100
|
|
12
|
+
}),
|
|
13
|
+
|
|
14
|
+
addAttributes() {
|
|
15
|
+
return {
|
|
16
|
+
mobile: { default: null },
|
|
17
|
+
tablet: { default: null },
|
|
18
|
+
desktop: { default: null }
|
|
19
|
+
};
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
addCommands() {
|
|
23
|
+
return {
|
|
24
|
+
getFontSize: createCommand(({ editor, commands }) => {
|
|
25
|
+
const device = commands.getDevice();
|
|
26
|
+
const defaultValue = commands.getDefaultFontSize();
|
|
27
|
+
|
|
28
|
+
return computed(() => editor.getAttributes(this.name)?.[device.value] ?? defaultValue.value);
|
|
29
|
+
}),
|
|
30
|
+
|
|
31
|
+
getDefaultFontSize: createCommand(({ commands }) => {
|
|
32
|
+
const device = commands.getDevice();
|
|
33
|
+
const preset = commands.getPreset();
|
|
34
|
+
|
|
35
|
+
return computed(() => preset.value[device.value].font_size.replace('px', ''));
|
|
36
|
+
}),
|
|
37
|
+
|
|
38
|
+
applyFontSize: createCommand(({ commands }, value) => {
|
|
39
|
+
const device = commands.getDevice().value;
|
|
40
|
+
|
|
41
|
+
commands.setMark(this.name, { [device]: value });
|
|
42
|
+
}),
|
|
43
|
+
|
|
44
|
+
increaseFontSize: createCommand(({ commands }) => {
|
|
45
|
+
const size = Number(commands.getFontSize().value);
|
|
46
|
+
const nextSize = Math.min(size + 1, this.options.maxSize);
|
|
47
|
+
|
|
48
|
+
commands.applyFontSize(String(nextSize));
|
|
49
|
+
}),
|
|
50
|
+
|
|
51
|
+
decreaseFontSize: createCommand(({ commands }) => {
|
|
52
|
+
const size = Number(commands.getFontSize().value);
|
|
53
|
+
const nextSize = Math.max(size - 1, this.options.minSize);
|
|
54
|
+
|
|
55
|
+
commands.applyFontSize(String(nextSize));
|
|
56
|
+
})
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
addKeyboardShortcuts: () => ({
|
|
61
|
+
'Mod-Shift-=': createKeyboardShortcut('increaseFontSize'),
|
|
62
|
+
'Mod-Shift--': createKeyboardShortcut('decreaseFontSize')
|
|
63
|
+
}),
|
|
64
|
+
|
|
65
|
+
renderHTML({ HTMLAttributes: attrs }) {
|
|
66
|
+
const addUnits = (value) => value ? `${value}px` : null;
|
|
67
|
+
|
|
68
|
+
return renderMark({
|
|
69
|
+
mobile_font_size: addUnits(attrs.mobile),
|
|
70
|
+
tablet_font_size: addUnits(attrs.tablet),
|
|
71
|
+
desktop_font_size: addUnits(attrs.desktop)
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
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 FontStyle = Mark.create({
|
|
7
|
+
name: TextSettings.FONT_STYLE,
|
|
8
|
+
|
|
9
|
+
addAttributes: () => ({
|
|
10
|
+
italic: { required: true }
|
|
11
|
+
}),
|
|
12
|
+
|
|
13
|
+
addCommands() {
|
|
14
|
+
return {
|
|
15
|
+
isItalic: createCommand(({ editor, commands }) => {
|
|
16
|
+
const defaultValue = commands.getDefaultFontStyle();
|
|
17
|
+
|
|
18
|
+
return computed(() => editor.getAttributes(this.name)?.italic ?? defaultValue.value.italic);
|
|
19
|
+
}),
|
|
20
|
+
|
|
21
|
+
isItalicAvailable: createCommand(({ commands }) => {
|
|
22
|
+
const font = commands.getFont();
|
|
23
|
+
const fontWeight = commands.getFontWeight();
|
|
24
|
+
|
|
25
|
+
return computed(() => font.value.isItalicSupported(fontWeight.value));
|
|
26
|
+
}),
|
|
27
|
+
|
|
28
|
+
getDefaultFontStyle: createCommand(({ commands }) => {
|
|
29
|
+
const preset = commands.getPreset();
|
|
30
|
+
|
|
31
|
+
return computed(() => ({
|
|
32
|
+
italic: preset.value.common.font_style === 'italic'
|
|
33
|
+
}));
|
|
34
|
+
}),
|
|
35
|
+
|
|
36
|
+
toggleItalic: createCommand(({ commands }) => {
|
|
37
|
+
const isItalicAvailable = this.editor.commands.isItalicAvailable();
|
|
38
|
+
|
|
39
|
+
if (!isItalicAvailable.value) return;
|
|
40
|
+
|
|
41
|
+
commands.isItalic().value ? commands.removeItalic() : commands.applyItalic();
|
|
42
|
+
}),
|
|
43
|
+
|
|
44
|
+
applyItalic: createCommand(({ commands }) => {
|
|
45
|
+
commands.setMark(this.name, { italic: true });
|
|
46
|
+
}),
|
|
47
|
+
|
|
48
|
+
removeItalic: createCommand(({ commands }) => {
|
|
49
|
+
commands.unsetMark(this.name);
|
|
50
|
+
})
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
addKeyboardShortcuts: () => ({
|
|
55
|
+
'Mod-i': createKeyboardShortcut('toggleItalic'),
|
|
56
|
+
'Mod-I': createKeyboardShortcut('toggleItalic')
|
|
57
|
+
}),
|
|
58
|
+
|
|
59
|
+
renderHTML() {
|
|
60
|
+
return renderMark({ font_style: 'italic' });
|
|
61
|
+
}
|
|
62
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
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 FontWeight = Mark.create({
|
|
7
|
+
name: TextSettings.FONT_WEIGHT,
|
|
8
|
+
|
|
9
|
+
addAttributes: () => ({
|
|
10
|
+
value: { required: true }
|
|
11
|
+
}),
|
|
12
|
+
|
|
13
|
+
addCommands() {
|
|
14
|
+
return {
|
|
15
|
+
applyFontWeight: createCommand(({ commands }, value) => {
|
|
16
|
+
commands.setMark(this.name, { value });
|
|
17
|
+
const font = commands.getFont().value;
|
|
18
|
+
|
|
19
|
+
if (!font.isItalicSupported(value)) {
|
|
20
|
+
commands.removeItalic();
|
|
21
|
+
}
|
|
22
|
+
}),
|
|
23
|
+
|
|
24
|
+
toggleBold: createCommand(({ commands }) => {
|
|
25
|
+
const currentWeight = commands.getFontWeight().value;
|
|
26
|
+
const currentFont = commands.getFont().value;
|
|
27
|
+
const isBold = Number(currentWeight) >= 600;
|
|
28
|
+
const wantedWeight = isBold ? '400' : '700';
|
|
29
|
+
const nextWeight = currentFont.findClosestWeight(wantedWeight);
|
|
30
|
+
|
|
31
|
+
commands.applyFontWeight(nextWeight);
|
|
32
|
+
}),
|
|
33
|
+
|
|
34
|
+
getFontWeight: createCommand(({ editor, commands }) => {
|
|
35
|
+
const defaultValue = commands.getDefaultFontWeight();
|
|
36
|
+
|
|
37
|
+
return computed(() => editor.getAttributes(this.name)?.value ?? defaultValue.value);
|
|
38
|
+
}),
|
|
39
|
+
|
|
40
|
+
getDefaultFontWeight: createCommand(({ commands }) => {
|
|
41
|
+
const preset = commands.getPreset();
|
|
42
|
+
|
|
43
|
+
return computed(() => preset.value.common.font_weight);
|
|
44
|
+
})
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
addKeyboardShortcuts: () => ({
|
|
49
|
+
'Mod-b': createKeyboardShortcut('toggleBold'),
|
|
50
|
+
'Mod-B': createKeyboardShortcut('toggleBold')
|
|
51
|
+
}),
|
|
52
|
+
|
|
53
|
+
renderHTML({ HTMLAttributes: attrs }) {
|
|
54
|
+
return renderMark({ font_weight: attrs.value });
|
|
55
|
+
}
|
|
56
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Extension } from '@tiptap/vue-2';
|
|
2
|
+
import { computed } from '@vue/composition-api';
|
|
3
|
+
import { createCommand, renderInlineSetting } from '../utils';
|
|
4
|
+
import { NodeTypes, TextSettings } from '../enums';
|
|
5
|
+
|
|
6
|
+
const DEFAULTS = {
|
|
7
|
+
mobile: null,
|
|
8
|
+
tablet: null,
|
|
9
|
+
desktop: null
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const LineHeight = Extension.create({
|
|
13
|
+
name: TextSettings.LINE_HEIGHT,
|
|
14
|
+
|
|
15
|
+
addGlobalAttributes: () => [
|
|
16
|
+
{
|
|
17
|
+
types: [NodeTypes.PARAGRAPH, NodeTypes.HEADING],
|
|
18
|
+
attributes: {
|
|
19
|
+
[TextSettings.LINE_HEIGHT]: {
|
|
20
|
+
isRequired: false,
|
|
21
|
+
|
|
22
|
+
renderHTML(attrs) {
|
|
23
|
+
if (!attrs.line_height) return null;
|
|
24
|
+
|
|
25
|
+
return renderInlineSetting({
|
|
26
|
+
mobile_line_height: attrs.line_height.mobile,
|
|
27
|
+
tablet_line_height: attrs.line_height.tablet,
|
|
28
|
+
desktop_line_height: attrs.line_height.desktop
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
],
|
|
35
|
+
|
|
36
|
+
addCommands() {
|
|
37
|
+
return {
|
|
38
|
+
getLineHeight: createCommand(({ commands }) => {
|
|
39
|
+
const attribute = commands.getBlockAttributes(this.name, DEFAULTS);
|
|
40
|
+
const device = commands.getDevice();
|
|
41
|
+
const defaultValue = commands.getDefaultLineHeight();
|
|
42
|
+
|
|
43
|
+
return computed(() => attribute.value?.[device.value] ?? defaultValue.value);
|
|
44
|
+
}),
|
|
45
|
+
|
|
46
|
+
getDefaultLineHeight: createCommand(({ commands }) => {
|
|
47
|
+
const device = commands.getDevice();
|
|
48
|
+
const preset = commands.getPreset();
|
|
49
|
+
|
|
50
|
+
return computed(() => preset.value[device.value].line_height);
|
|
51
|
+
}),
|
|
52
|
+
|
|
53
|
+
applyLineHeight: createCommand(({ commands }, value) => {
|
|
54
|
+
const device = commands.getDevice().value;
|
|
55
|
+
|
|
56
|
+
commands.setBlockAttributes(this.name, { [device]: value }, DEFAULTS);
|
|
57
|
+
})
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
});
|