@zipify/wysiwyg 1.0.0-dev.4 → 1.0.0-dev.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +1 -1
- package/.eslintignore +1 -0
- package/.eslintrc.js +2 -2
- package/.github/dependabot.yaml +1 -0
- package/.lintstagedrc +1 -1
- package/.release-it.json +3 -2
- package/.stylelintignore +1 -0
- package/.stylelintrc +0 -4
- package/README.md +5 -3
- package/config/jest/setupTests.js +7 -4
- package/config/vite/lib.config.js +25 -0
- package/config/vite/settings.js +9 -0
- package/config/webpack/example.config.js +2 -0
- package/config/webpack/lib.config.js +43 -0
- package/config/webpack/loaders/style-loader.js +3 -1
- package/config/webpack/loaders/svg-loader.js +1 -1
- package/dist/style.css +1 -0
- package/dist/wysiwyg.mjs +18198 -0
- package/example/ExampleApp.vue +52 -33
- package/example/example.js +25 -2
- package/example/pageBlocks.js +31 -0
- package/example/presets.js +4 -2
- package/lib/Wysiwyg.vue +42 -22
- package/lib/__tests__/utils/withComponentContext.js +1 -1
- package/lib/assets/icons/alignment-center.svg +3 -0
- package/lib/assets/icons/alignment-justify.svg +3 -0
- package/lib/assets/icons/alignment-left.svg +3 -0
- package/lib/assets/icons/alignment-right.svg +3 -0
- package/lib/assets/icons/arrow.svg +3 -0
- package/lib/assets/icons/background-color.svg +3 -0
- package/lib/assets/icons/case-style.svg +3 -0
- package/lib/assets/icons/font-color.svg +5 -0
- package/lib/assets/icons/italic.svg +3 -0
- package/lib/assets/icons/line-height.svg +3 -0
- package/lib/assets/icons/link.svg +3 -0
- package/lib/assets/icons/list-circle.svg +3 -0
- package/lib/assets/icons/list-decimal.svg +3 -0
- package/lib/assets/icons/list-disc.svg +3 -0
- package/lib/assets/icons/list-latin.svg +3 -0
- package/lib/assets/icons/list-roman.svg +3 -0
- package/lib/assets/icons/list-square.svg +3 -0
- package/lib/assets/icons/remove-format.svg +3 -0
- package/lib/assets/icons/reset-styles.svg +3 -0
- package/lib/assets/icons/strike-through.svg +3 -0
- package/lib/assets/icons/superscript.svg +3 -0
- package/lib/assets/icons/underline.svg +3 -0
- package/lib/assets/icons/unlink.svg +3 -0
- package/lib/components/base/Button.vue +22 -2
- package/lib/components/base/Checkbox.vue +89 -0
- package/lib/components/base/FieldLabel.vue +2 -1
- package/lib/components/base/Icon.vue +19 -11
- package/lib/components/base/Modal.vue +1 -2
- package/lib/components/base/NumberField.vue +2 -2
- package/lib/components/base/Range.vue +1 -1
- package/lib/components/base/ScrollView.vue +2 -2
- package/lib/components/base/TextField.vue +106 -0
- package/lib/components/base/__tests__/Icon.test.js +6 -13
- package/lib/components/base/__tests__/Modal.test.js +8 -2
- package/lib/components/base/__tests__/TextField.test.js +57 -0
- package/lib/components/base/__tests__/__snapshots__/TextField.test.js.snap +9 -0
- package/lib/components/base/colorPicker/ColorPicker.vue +1 -1
- package/lib/components/base/colorPicker/composables/__tests__/usePickerApi.test.js +1 -1
- package/lib/components/base/colorPicker/composables/usePickerApi.js +1 -1
- package/lib/components/base/colorPicker/composables/usePickerHotkeys.js +3 -2
- package/lib/components/base/composables/__tests__/useActivatedListener.test.js +1 -1
- package/lib/components/base/composables/__tests__/useDeselectionLock.test.js +1 -1
- package/lib/components/base/composables/__tests__/useElementRef.test.js +1 -1
- package/lib/components/base/composables/__tests__/useModalToggler.test.js +1 -1
- package/lib/components/base/composables/__tests__/useNumberValue.test.js +1 -1
- package/lib/components/base/composables/__tests__/useScrollView.test.js +1 -1
- package/lib/components/base/composables/__tests__/useTempValue.test.js +1 -1
- package/lib/components/base/composables/index.js +1 -0
- package/lib/components/base/composables/useActivatedListener.js +1 -1
- package/lib/components/base/composables/useDeselectionLock.js +1 -1
- package/lib/components/base/composables/useElementRef.js +1 -1
- package/lib/components/base/composables/useModalToggler.js +1 -1
- package/lib/components/base/composables/useScrollView.js +1 -1
- package/lib/components/base/composables/useTempValue.js +1 -1
- package/lib/components/base/composables/useValidator.js +19 -0
- package/lib/components/base/dropdown/Dropdown.vue +16 -4
- package/lib/components/base/dropdown/DropdownActivator.vue +19 -3
- package/lib/components/base/dropdown/DropdownGroup.vue +1 -1
- package/lib/components/base/dropdown/DropdownMenu.vue +1 -1
- package/lib/components/base/dropdown/DropdownOption.vue +1 -1
- package/lib/components/base/dropdown/__tests__/DropdownActivator.test.js +1 -1
- package/lib/components/base/dropdown/__tests__/DropdownMenu.test.js +1 -1
- package/lib/components/base/dropdown/__tests__/DropdownOption.test.js +1 -1
- package/lib/components/base/dropdown/composables/__tests__/useActiveOptionManager.test.js +1 -1
- package/lib/components/base/dropdown/composables/__tests__/useDropdownEntityTitle.test.js +1 -1
- package/lib/components/base/dropdown/composables/useActiveOptionManager.js +1 -1
- package/lib/components/base/dropdown/composables/useDropdownEntityTitle.js +1 -1
- package/lib/components/base/index.js +3 -1
- package/lib/components/toolbar/Toolbar.vue +49 -9
- package/lib/components/toolbar/ToolbarDivider.vue +1 -1
- package/lib/components/toolbar/ToolbarFull.vue +10 -2
- package/lib/components/toolbar/__tests__/Toolbar.test.js +8 -1
- package/lib/components/toolbar/controls/AlignmentControl.vue +1 -1
- package/lib/components/toolbar/controls/AlignmentDeviceControl.vue +1 -1
- package/lib/components/toolbar/controls/BackgroundColorControl.vue +1 -1
- package/lib/components/toolbar/controls/CaseStyleControl.vue +1 -1
- package/lib/components/toolbar/controls/FontColorControl.vue +1 -1
- package/lib/components/toolbar/controls/FontFamilyControl.vue +1 -1
- package/lib/components/toolbar/controls/FontSizeControl.vue +8 -1
- package/lib/components/toolbar/controls/FontWeightControl.vue +1 -1
- package/lib/components/toolbar/controls/ItalicControl.vue +1 -1
- package/lib/components/toolbar/controls/LineHeightControl.vue +1 -1
- package/lib/components/toolbar/controls/ListControl.vue +2 -6
- package/lib/components/toolbar/controls/RemoveFormatControl.vue +1 -1
- package/lib/components/toolbar/controls/StrikeThroughControl.vue +1 -1
- package/lib/components/toolbar/controls/StylePresetControl.vue +1 -1
- package/lib/components/toolbar/controls/SuperscriptControl.vue +1 -1
- package/lib/components/toolbar/controls/UnderlineControl.vue +2 -2
- package/lib/components/toolbar/controls/__tests__/AlignmentControl.test.js +1 -1
- package/lib/components/toolbar/controls/__tests__/AlignmentDeviceControl.test.js +1 -1
- package/lib/components/toolbar/controls/__tests__/BackgroundColorControl.test.js +1 -1
- package/lib/components/toolbar/controls/__tests__/CaseStyleControl.test.js +1 -1
- package/lib/components/toolbar/controls/__tests__/FontColorControl.test.js +1 -1
- package/lib/components/toolbar/controls/__tests__/FontFamilyControl.test.js +1 -1
- package/lib/components/toolbar/controls/__tests__/FontSizeControl.test.js +1 -1
- package/lib/components/toolbar/controls/__tests__/FontWeightControl.test.js +1 -1
- package/lib/components/toolbar/controls/__tests__/ItalicControl.test.js +1 -1
- package/lib/components/toolbar/controls/__tests__/LineHeightControl.test.js +1 -1
- package/lib/components/toolbar/controls/__tests__/ListControl.test.js +1 -1
- package/lib/components/toolbar/controls/__tests__/StrikeThroughControl.test.js +1 -1
- package/lib/components/toolbar/controls/__tests__/StylePresetControl.test.js +1 -1
- package/lib/components/toolbar/controls/__tests__/UnderlineControl.test.js +5 -1
- package/lib/components/toolbar/controls/composables/useRecentFonts.js +1 -1
- package/lib/components/toolbar/controls/index.js +1 -0
- package/lib/components/toolbar/controls/link/LinkControl.vue +152 -0
- package/lib/components/toolbar/controls/link/LinkControlApply.vue +35 -0
- package/lib/components/toolbar/controls/link/LinkControlHeader.vue +67 -0
- package/lib/components/toolbar/controls/link/composables/index.js +1 -0
- package/lib/components/toolbar/controls/link/composables/useLink.js +61 -0
- package/lib/components/toolbar/controls/link/destination/LinkControlDestination.vue +103 -0
- package/lib/components/toolbar/controls/link/destination/LinkControlPageBlock.vue +54 -0
- package/lib/components/toolbar/controls/link/destination/LinkControlUrl.vue +52 -0
- package/lib/components/toolbar/controls/link/destination/index.js +1 -0
- package/lib/components/toolbar/controls/link/index.js +1 -0
- package/lib/composables/__tests__/useEditor.test.js +15 -6
- package/lib/composables/useEditor.js +13 -8
- package/lib/composables/useToolbar.js +14 -29
- package/lib/directives/outClick.js +20 -4
- package/lib/enums/LinkDestinations.js +4 -0
- package/lib/enums/LinkTargets.js +4 -0
- package/lib/enums/TextSettings.js +3 -1
- package/lib/enums/index.js +2 -0
- package/lib/extensions/Alignment.js +22 -4
- package/lib/extensions/BackgroundColor.js +17 -2
- package/lib/extensions/DeviceManager.js +2 -5
- package/lib/extensions/FontColor.js +17 -2
- package/lib/extensions/FontFamily.js +27 -3
- package/lib/extensions/FontSize.js +29 -4
- package/lib/extensions/FontStyle.js +24 -3
- package/lib/extensions/FontWeight.js +34 -2
- package/lib/extensions/LineHeight.js +30 -4
- package/lib/extensions/Link.js +101 -0
- package/lib/extensions/StylePreset.js +38 -15
- package/lib/extensions/TextDecoration.js +30 -4
- package/lib/extensions/__tests__/Alignment.test.js +32 -5
- package/lib/extensions/__tests__/BackgroundColor.test.js +39 -4
- package/lib/extensions/__tests__/CaseStyle.test.js +4 -3
- package/lib/extensions/__tests__/FontColor.test.js +39 -4
- package/lib/extensions/__tests__/FontFamily.test.js +60 -6
- package/lib/extensions/__tests__/FontSize.test.js +40 -5
- package/lib/extensions/__tests__/FontStyle.test.js +47 -4
- package/lib/extensions/__tests__/FontWeight.test.js +67 -4
- package/lib/extensions/__tests__/LineHeight.test.js +51 -5
- package/lib/extensions/__tests__/StylePreset.test.js +144 -6
- package/lib/extensions/__tests__/TextDecoration.test.js +88 -4
- package/lib/extensions/__tests__/__snapshots__/Alignment.test.js.snap +70 -2
- package/lib/extensions/__tests__/__snapshots__/BackgroundColor.test.js.snap +121 -1
- package/lib/extensions/__tests__/__snapshots__/FontColor.test.js.snap +109 -1
- package/lib/extensions/__tests__/__snapshots__/FontFamily.test.js.snap +179 -1
- package/lib/extensions/__tests__/__snapshots__/FontSize.test.js.snap +132 -2
- package/lib/extensions/__tests__/__snapshots__/FontStyle.test.js.snap +142 -1
- package/lib/extensions/__tests__/__snapshots__/FontWeight.test.js.snap +179 -1
- package/lib/extensions/__tests__/__snapshots__/LineHeight.test.js.snap +118 -2
- package/lib/extensions/__tests__/__snapshots__/StylePreset.test.js.snap +171 -2
- package/lib/extensions/__tests__/__snapshots__/TextDecoration.test.js.snap +300 -3
- package/lib/extensions/core/CopyPasteProcessor.js +10 -0
- package/lib/extensions/core/NodeProcessor.js +1 -1
- package/lib/extensions/core/TextProcessor.js +10 -0
- package/lib/extensions/core/__tests__/NodeProcessor.test.js +4 -3
- package/lib/extensions/core/__tests__/SelectionProcessor.test.js +9 -6
- package/lib/extensions/core/__tests__/TextProcessor.test.js +139 -10
- package/lib/extensions/core/__tests__/__snapshots__/TextProcessor.test.js.snap +26 -0
- package/lib/extensions/core/index.js +11 -2
- package/lib/extensions/core/plugins/PastePlugin.js +48 -0
- package/lib/extensions/core/plugins/ProseMirrorPlugin.js +20 -0
- package/lib/extensions/core/plugins/index.js +1 -0
- package/lib/extensions/index.js +41 -33
- package/lib/extensions/list/List.js +35 -1
- package/lib/extensions/list/__tests__/List.test.js +117 -8
- package/lib/extensions/list/__tests__/__snapshots__/List.test.js.snap +481 -0
- package/lib/injectionTokens.js +2 -1
- package/lib/services/ContentNormalizer.js +157 -0
- package/lib/services/ContextWidnow.js +23 -0
- package/lib/services/Storage.js +1 -13
- package/lib/services/__tests__/ContentNormalizer.test.js +74 -0
- package/lib/services/__tests__/FavoriteColors.test.js +20 -0
- package/lib/services/__tests__/JsonSerializer.test.js +23 -0
- package/lib/services/__tests__/Storage.test.js +79 -0
- package/lib/services/index.js +2 -0
- package/lib/styles/content.css +96 -9
- package/lib/styles/helpers/offsets.css +16 -0
- package/lib/styles/variables.css +6 -0
- package/lib/utils/__tests__/__snapshots__/renderInlineSetting.test.js.snap +4 -4
- package/lib/utils/__tests__/convertColor.test.js +19 -0
- package/lib/utils/__tests__/createKeyboardShortcut.test.js +25 -0
- package/lib/utils/__tests__/renderInlineSetting.test.js +26 -0
- package/lib/utils/convertColor.js +7 -0
- package/lib/utils/importIcon.js +13 -0
- package/lib/utils/index.js +2 -0
- package/lib/utils/renderInlineSetting.js +2 -2
- package/package.json +21 -16
- package/lib/assets/icons.svg +0 -69
- package/lib/composables/__tests__/useToolbar.test.js +0 -56
|
@@ -1,44 +1,29 @@
|
|
|
1
1
|
import { createPopper } from '@popperjs/core';
|
|
2
|
-
import {
|
|
3
|
-
import { useElementRef } from '../components/base/composables';
|
|
2
|
+
import { useElementRef } from '../components/base';
|
|
4
3
|
|
|
5
|
-
export function useToolbar({ wrapperRef,
|
|
4
|
+
export function useToolbar({ wrapperRef, offsets, isActiveRef }) {
|
|
5
|
+
const wrapperEl = useElementRef(wrapperRef);
|
|
6
6
|
let toolbar;
|
|
7
|
-
const isShow = ref(false);
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const toolbarEl = useElementRef(popperRef).value;
|
|
12
|
-
|
|
13
|
-
toolbar = createPopper(wrapperEl, toolbarEl, {
|
|
8
|
+
function mount(element) {
|
|
9
|
+
toolbar = createPopper(wrapperEl.value, element, {
|
|
14
10
|
placement: 'top-start',
|
|
15
11
|
modifiers: [
|
|
16
12
|
{
|
|
17
13
|
name: 'offset',
|
|
18
|
-
options: {
|
|
19
|
-
offset: offsets
|
|
20
|
-
}
|
|
14
|
+
options: { offset: offsets }
|
|
21
15
|
}
|
|
22
16
|
]
|
|
23
17
|
});
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
onUnmounted(() => {
|
|
27
|
-
toolbar.destroy();
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
function hide() {
|
|
31
|
-
isShow.value = false;
|
|
32
18
|
}
|
|
33
19
|
|
|
34
|
-
|
|
35
|
-
isShow.value = true;
|
|
36
|
-
this.update();
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function update() {
|
|
40
|
-
toolbar.update();
|
|
41
|
-
}
|
|
20
|
+
const update = () => toolbar?.update();
|
|
42
21
|
|
|
43
|
-
return {
|
|
22
|
+
return {
|
|
23
|
+
toolbar,
|
|
24
|
+
update,
|
|
25
|
+
mount,
|
|
26
|
+
isActiveRef,
|
|
27
|
+
offsets
|
|
28
|
+
};
|
|
44
29
|
}
|
|
@@ -1,5 +1,21 @@
|
|
|
1
|
+
import { ContextWindow } from '../services';
|
|
2
|
+
|
|
1
3
|
const dataStorage = new WeakMap();
|
|
2
4
|
|
|
5
|
+
function attachListener(onClick) {
|
|
6
|
+
if (ContextWindow.window !== window) {
|
|
7
|
+
window.document.addEventListener('click', onClick);
|
|
8
|
+
}
|
|
9
|
+
ContextWindow.document.addEventListener('click', onClick);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function removeListener(onClick) {
|
|
13
|
+
if (ContextWindow.window !== window) {
|
|
14
|
+
window.document.removeEventListener('click', onClick);
|
|
15
|
+
}
|
|
16
|
+
ContextWindow.document.removeEventListener('click', onClick);
|
|
17
|
+
}
|
|
18
|
+
|
|
3
19
|
export const outClick = {
|
|
4
20
|
bind(el, { value }) {
|
|
5
21
|
const onOutClick = value.onOutClick || value;
|
|
@@ -14,7 +30,7 @@ export const outClick = {
|
|
|
14
30
|
dataStorage.set(el, { callback: onClick, isEnabled });
|
|
15
31
|
|
|
16
32
|
if (isEnabled) {
|
|
17
|
-
setTimeout(() =>
|
|
33
|
+
setTimeout(() => attachListener(onClick));
|
|
18
34
|
}
|
|
19
35
|
},
|
|
20
36
|
|
|
@@ -25,13 +41,13 @@ export const outClick = {
|
|
|
25
41
|
if (isEnabled === data.isEnabled) return;
|
|
26
42
|
|
|
27
43
|
isEnabled
|
|
28
|
-
?
|
|
29
|
-
:
|
|
44
|
+
? attachListener(data.callback)
|
|
45
|
+
: removeListener(data.callback);
|
|
30
46
|
|
|
31
47
|
dataStorage.set(el, { callback: data.callback, isEnabled });
|
|
32
48
|
},
|
|
33
49
|
|
|
34
50
|
unbind(el) {
|
|
35
|
-
|
|
51
|
+
removeListener(dataStorage.get(el).callback);
|
|
36
52
|
}
|
|
37
53
|
};
|
|
@@ -8,6 +8,7 @@ export const TextSettings = Object.freeze({
|
|
|
8
8
|
FONT_WEIGHT: 'font_weight',
|
|
9
9
|
LINE_HEIGHT: 'line_height',
|
|
10
10
|
TEXT_DECORATION: 'text_decoration',
|
|
11
|
+
SUPERSCRIPT: 'superscript',
|
|
11
12
|
|
|
12
13
|
get attributes() {
|
|
13
14
|
return [
|
|
@@ -24,7 +25,8 @@ export const TextSettings = Object.freeze({
|
|
|
24
25
|
this.FONT_SIZE,
|
|
25
26
|
this.FONT_STYLE,
|
|
26
27
|
this.FONT_WEIGHT,
|
|
27
|
-
this.TEXT_DECORATION
|
|
28
|
+
this.TEXT_DECORATION,
|
|
29
|
+
this.SUPERSCRIPT
|
|
28
30
|
];
|
|
29
31
|
}
|
|
30
32
|
});
|
package/lib/enums/index.js
CHANGED
|
@@ -4,3 +4,5 @@ export { Alignments } from './Alignments';
|
|
|
4
4
|
export { NodeTypes } from './NodeTypes';
|
|
5
5
|
export { ListTypes } from './ListTypes';
|
|
6
6
|
export { TextSettings } from './TextSettings';
|
|
7
|
+
export { LinkTargets } from './LinkTargets';
|
|
8
|
+
export { LinkDestinations } from './LinkDestinations';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Extension } from '@tiptap/vue-2';
|
|
2
|
-
import { computed } from '
|
|
2
|
+
import { computed } from 'vue';
|
|
3
3
|
import { createCommand, createKeyboardShortcut, renderInlineSetting } from '../utils';
|
|
4
4
|
import { Alignments, NodeTypes, TextSettings } from '../enums';
|
|
5
5
|
|
|
@@ -19,13 +19,31 @@ export const Alignment = Extension.create({
|
|
|
19
19
|
[TextSettings.ALIGNMENT]: {
|
|
20
20
|
isRequired: false,
|
|
21
21
|
|
|
22
|
+
parseHTML({ style }) {
|
|
23
|
+
if (style.textAlign) {
|
|
24
|
+
return {
|
|
25
|
+
desktop: style.textAlign,
|
|
26
|
+
tablet: style.textAlign,
|
|
27
|
+
mobile: style.textAlign
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const mobile = style.getPropertyValue('--zw-text-align-mobile') || null;
|
|
32
|
+
const tablet = style.getPropertyValue('--zw-text-align-tablet') || null;
|
|
33
|
+
const desktop = style.getPropertyValue('--zw-text-align-desktop') || null;
|
|
34
|
+
|
|
35
|
+
if (!mobile && !tablet && !desktop) return null;
|
|
36
|
+
|
|
37
|
+
return { desktop, tablet, mobile };
|
|
38
|
+
},
|
|
39
|
+
|
|
22
40
|
renderHTML(attrs) {
|
|
23
41
|
if (!attrs.alignment) return null;
|
|
24
42
|
|
|
25
43
|
return renderInlineSetting({
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
44
|
+
text_align_mobile: attrs.alignment.mobile,
|
|
45
|
+
text_align_tablet: attrs.alignment.tablet,
|
|
46
|
+
text_align_desktop: attrs.alignment.desktop
|
|
29
47
|
});
|
|
30
48
|
}
|
|
31
49
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Mark } from '@tiptap/vue-2';
|
|
2
|
-
import { computed } from '
|
|
3
|
-
import { createCommand, renderMark } from '../utils';
|
|
2
|
+
import { computed } from 'vue';
|
|
3
|
+
import { convertColor, createCommand, renderMark } from '../utils';
|
|
4
4
|
import { TextSettings } from '../enums';
|
|
5
5
|
|
|
6
6
|
export const BackgroundColor = Mark.create({
|
|
@@ -22,6 +22,21 @@ export const BackgroundColor = Mark.create({
|
|
|
22
22
|
};
|
|
23
23
|
},
|
|
24
24
|
|
|
25
|
+
parseHTML() {
|
|
26
|
+
const getAttrs = (value) => ({ value: convertColor(value) });
|
|
27
|
+
|
|
28
|
+
return [
|
|
29
|
+
{
|
|
30
|
+
style: '--zw-background-color',
|
|
31
|
+
getAttrs
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
style: 'background-color',
|
|
35
|
+
getAttrs
|
|
36
|
+
}
|
|
37
|
+
];
|
|
38
|
+
},
|
|
39
|
+
|
|
25
40
|
renderHTML({ HTMLAttributes: attrs }) {
|
|
26
41
|
return renderMark({ background_color: attrs.value });
|
|
27
42
|
}
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
+
import { toRef } from 'vue';
|
|
1
2
|
import { Extension } from '@tiptap/vue-2';
|
|
2
3
|
import { createCommand } from '../utils';
|
|
3
4
|
|
|
4
5
|
export const DeviceManager = Extension.create({
|
|
5
6
|
name: 'device_manager',
|
|
6
7
|
|
|
7
|
-
addOptions: () => ({
|
|
8
|
-
deviceRef: null
|
|
9
|
-
}),
|
|
10
|
-
|
|
11
8
|
addCommands() {
|
|
12
9
|
return {
|
|
13
|
-
getDevice: createCommand(() => this.options
|
|
10
|
+
getDevice: createCommand(() => toRef(this.options, 'device'))
|
|
14
11
|
};
|
|
15
12
|
}
|
|
16
13
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Mark } from '@tiptap/vue-2';
|
|
2
|
-
import { computed } from '
|
|
3
|
-
import { createCommand, renderMark } from '../utils';
|
|
2
|
+
import { computed } from 'vue';
|
|
3
|
+
import { convertColor, createCommand, renderMark } from '../utils';
|
|
4
4
|
import { TextSettings } from '../enums';
|
|
5
5
|
|
|
6
6
|
export const FontColor = Mark.create({
|
|
@@ -30,6 +30,21 @@ export const FontColor = Mark.create({
|
|
|
30
30
|
};
|
|
31
31
|
},
|
|
32
32
|
|
|
33
|
+
parseHTML() {
|
|
34
|
+
const getAttrs = (value) => ({ value: convertColor(value) });
|
|
35
|
+
|
|
36
|
+
return [
|
|
37
|
+
{
|
|
38
|
+
style: '--zw-font-color',
|
|
39
|
+
getAttrs
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
style: 'color',
|
|
43
|
+
getAttrs
|
|
44
|
+
}
|
|
45
|
+
];
|
|
46
|
+
},
|
|
47
|
+
|
|
33
48
|
renderHTML({ HTMLAttributes: attrs }) {
|
|
34
49
|
return renderMark({ font_color: attrs.value });
|
|
35
50
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Mark } from '@tiptap/vue-2';
|
|
2
|
-
import { computed } from '
|
|
2
|
+
import { computed } from 'vue';
|
|
3
3
|
import { createCommand, renderMark } from '../utils';
|
|
4
4
|
import { TextSettings } from '../enums';
|
|
5
5
|
|
|
@@ -7,7 +7,8 @@ export const FontFamily = Mark.create({
|
|
|
7
7
|
name: TextSettings.FONT_FAMILY,
|
|
8
8
|
|
|
9
9
|
addOptions: () => ({
|
|
10
|
-
fonts: []
|
|
10
|
+
fonts: [],
|
|
11
|
+
defaultFont: ''
|
|
11
12
|
}),
|
|
12
13
|
|
|
13
14
|
addAttributes: () => ({
|
|
@@ -56,7 +57,30 @@ export const FontFamily = Mark.create({
|
|
|
56
57
|
};
|
|
57
58
|
},
|
|
58
59
|
|
|
60
|
+
parseHTML() {
|
|
61
|
+
const getAttrs = (input) => {
|
|
62
|
+
const parsed = input.replace(/"/g, '');
|
|
63
|
+
const isExists = this.options.fonts.some((font) => font.name === parsed);
|
|
64
|
+
const value = isExists ? parsed : this.options.defaultFont;
|
|
65
|
+
|
|
66
|
+
return { value };
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
return [
|
|
70
|
+
{
|
|
71
|
+
style: '--zw-font-family',
|
|
72
|
+
getAttrs
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
style: 'font-family',
|
|
76
|
+
getAttrs
|
|
77
|
+
}
|
|
78
|
+
];
|
|
79
|
+
},
|
|
80
|
+
|
|
59
81
|
renderHTML({ HTMLAttributes: attrs }) {
|
|
60
|
-
|
|
82
|
+
const font_family = attrs.value ? `"${attrs.value}"` : null;
|
|
83
|
+
|
|
84
|
+
return renderMark({ font_family });
|
|
61
85
|
}
|
|
62
86
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Mark } from '@tiptap/vue-2';
|
|
2
|
-
import { computed } from '
|
|
2
|
+
import { computed } from 'vue';
|
|
3
3
|
import { createCommand, createKeyboardShortcut, renderMark } from '../utils';
|
|
4
4
|
import { TextSettings } from '../enums';
|
|
5
5
|
|
|
@@ -62,13 +62,38 @@ export const FontSize = Mark.create({
|
|
|
62
62
|
'Mod-Shift--': createKeyboardShortcut('decreaseFontSize')
|
|
63
63
|
}),
|
|
64
64
|
|
|
65
|
+
parseHTML() {
|
|
66
|
+
const parseSize = (value) => value ? String(parseInt(value)) : null;
|
|
67
|
+
|
|
68
|
+
return [
|
|
69
|
+
{
|
|
70
|
+
tag: '[style*="--zw-font-size"]',
|
|
71
|
+
|
|
72
|
+
getAttrs: ({ style }) => ({
|
|
73
|
+
mobile: parseSize(style.getPropertyValue('--zw-font-size-mobile')),
|
|
74
|
+
tablet: parseSize(style.getPropertyValue('--zw-font-size-tablet')),
|
|
75
|
+
desktop: parseSize(style.getPropertyValue('--zw-font-size-desktop'))
|
|
76
|
+
})
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
style: 'font-size',
|
|
80
|
+
|
|
81
|
+
getAttrs: (input) => {
|
|
82
|
+
const value = parseSize(input);
|
|
83
|
+
|
|
84
|
+
return { desktop: value, tablet: value, mobile: value };
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
];
|
|
88
|
+
},
|
|
89
|
+
|
|
65
90
|
renderHTML({ HTMLAttributes: attrs }) {
|
|
66
91
|
const addUnits = (value) => value ? `${value}px` : null;
|
|
67
92
|
|
|
68
93
|
return renderMark({
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
94
|
+
font_size_mobile: addUnits(attrs.mobile),
|
|
95
|
+
font_size_tablet: addUnits(attrs.tablet),
|
|
96
|
+
font_size_desktop: addUnits(attrs.desktop)
|
|
72
97
|
});
|
|
73
98
|
}
|
|
74
99
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Mark } from '@tiptap/vue-2';
|
|
2
|
-
import { computed } from '
|
|
2
|
+
import { computed } from 'vue';
|
|
3
3
|
import { createCommand, createKeyboardShortcut, renderMark } from '../utils';
|
|
4
4
|
import { TextSettings } from '../enums';
|
|
5
5
|
|
|
@@ -56,7 +56,28 @@ export const FontStyle = Mark.create({
|
|
|
56
56
|
'Mod-I': createKeyboardShortcut('toggleItalic')
|
|
57
57
|
}),
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
parseHTML() {
|
|
60
|
+
const getAttrs = (value) => value.includes('italic') && { italic: true };
|
|
61
|
+
|
|
62
|
+
return [
|
|
63
|
+
{
|
|
64
|
+
style: '--zw-font-style',
|
|
65
|
+
getAttrs
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
style: 'font-style',
|
|
69
|
+
getAttrs
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
tag: 'i',
|
|
73
|
+
attrs: { italic: true }
|
|
74
|
+
}
|
|
75
|
+
];
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
renderHTML({ HTMLAttributes: attrs }) {
|
|
79
|
+
const font_style = attrs.italic ? 'italic' : null;
|
|
80
|
+
|
|
81
|
+
return renderMark({ font_style });
|
|
61
82
|
}
|
|
62
83
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Mark } from '@tiptap/vue-2';
|
|
2
|
-
import { computed } from '
|
|
2
|
+
import { computed } from 'vue';
|
|
3
3
|
import { createCommand, createKeyboardShortcut, renderMark } from '../utils';
|
|
4
4
|
import { TextSettings } from '../enums';
|
|
5
5
|
|
|
@@ -33,8 +33,17 @@ export const FontWeight = Mark.create({
|
|
|
33
33
|
|
|
34
34
|
getFontWeight: createCommand(({ editor, commands }) => {
|
|
35
35
|
const defaultValue = commands.getDefaultFontWeight();
|
|
36
|
+
const font = commands.getFont();
|
|
36
37
|
|
|
37
|
-
return computed(() =>
|
|
38
|
+
return computed(() => {
|
|
39
|
+
const weight = editor.getAttributes(this.name)?.value ?? defaultValue.value;
|
|
40
|
+
|
|
41
|
+
if (font.value.isWeightSupported(weight)) {
|
|
42
|
+
return weight;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return font.value.findClosestWeight(weight);
|
|
46
|
+
});
|
|
38
47
|
}),
|
|
39
48
|
|
|
40
49
|
getDefaultFontWeight: createCommand(({ commands }) => {
|
|
@@ -50,6 +59,29 @@ export const FontWeight = Mark.create({
|
|
|
50
59
|
'Mod-B': createKeyboardShortcut('toggleBold')
|
|
51
60
|
}),
|
|
52
61
|
|
|
62
|
+
parseHTML() {
|
|
63
|
+
const getAttrs = (value) => ({ value });
|
|
64
|
+
|
|
65
|
+
return [
|
|
66
|
+
{
|
|
67
|
+
style: '--zw-font-weight',
|
|
68
|
+
getAttrs
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
style: 'font-weight',
|
|
72
|
+
getAttrs
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
tag: 'b',
|
|
76
|
+
attrs: { value: '700' }
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
tag: 'strong',
|
|
80
|
+
attrs: { value: '700' }
|
|
81
|
+
}
|
|
82
|
+
];
|
|
83
|
+
},
|
|
84
|
+
|
|
53
85
|
renderHTML({ HTMLAttributes: attrs }) {
|
|
54
86
|
return renderMark({ font_weight: attrs.value });
|
|
55
87
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Extension } from '@tiptap/vue-2';
|
|
2
|
-
import { computed } from '
|
|
2
|
+
import { computed } from 'vue';
|
|
3
3
|
import { createCommand, renderInlineSetting } from '../utils';
|
|
4
4
|
import { NodeTypes, TextSettings } from '../enums';
|
|
5
|
+
import { ContextWindow } from '../services';
|
|
5
6
|
|
|
6
7
|
const DEFAULTS = {
|
|
7
8
|
mobile: null,
|
|
@@ -19,13 +20,38 @@ export const LineHeight = Extension.create({
|
|
|
19
20
|
[TextSettings.LINE_HEIGHT]: {
|
|
20
21
|
isRequired: false,
|
|
21
22
|
|
|
23
|
+
parseHTML(element) {
|
|
24
|
+
if (element.matches('[style*="--zw-line-height"]')) {
|
|
25
|
+
const mobile = element.style.getPropertyValue('--zw-line-height-mobile') || null;
|
|
26
|
+
const tablet = element.style.getPropertyValue('--zw-line-height-tablet') || null;
|
|
27
|
+
const desktop = element.style.getPropertyValue('--zw-line-height-desktop') || null;
|
|
28
|
+
|
|
29
|
+
return { mobile, tablet, desktop };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const value = element.style.lineHeight;
|
|
33
|
+
|
|
34
|
+
if (!value) return null;
|
|
35
|
+
|
|
36
|
+
if (!value.includes('px')) {
|
|
37
|
+
return { desktop: value, tablet: value, mobile: value };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// element is not connected to window so getComputedStyle is not working on element
|
|
41
|
+
const childFontSize = element.firstElementChild.style.fontSize;
|
|
42
|
+
const fontSize = childFontSize || ContextWindow.getComputedStyle(ContextWindow.body).fontSize;
|
|
43
|
+
const relative = (parseFloat(value) / parseFloat(fontSize)).toFixed(2);
|
|
44
|
+
|
|
45
|
+
return { desktop: relative, tablet: relative, mobile: relative };
|
|
46
|
+
},
|
|
47
|
+
|
|
22
48
|
renderHTML(attrs) {
|
|
23
49
|
if (!attrs.line_height) return null;
|
|
24
50
|
|
|
25
51
|
return renderInlineSetting({
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
52
|
+
line_height_mobile: attrs.line_height.mobile,
|
|
53
|
+
line_height_tablet: attrs.line_height.tablet,
|
|
54
|
+
line_height_desktop: attrs.line_height.desktop
|
|
29
55
|
});
|
|
30
56
|
}
|
|
31
57
|
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import Base from '@tiptap/extension-link';
|
|
2
|
+
import { createCommand } from '../utils';
|
|
3
|
+
import { LinkDestinations, LinkTargets } from '../enums';
|
|
4
|
+
|
|
5
|
+
export const Link = Base.extend({
|
|
6
|
+
name: 'link',
|
|
7
|
+
|
|
8
|
+
addOptions() {
|
|
9
|
+
return {
|
|
10
|
+
...this.parent?.(),
|
|
11
|
+
openOnClick: false,
|
|
12
|
+
HTMLAttributes: {
|
|
13
|
+
target: LinkTargets.SELF
|
|
14
|
+
},
|
|
15
|
+
preset: {},
|
|
16
|
+
basePresetClass: null,
|
|
17
|
+
pageBlocks: []
|
|
18
|
+
};
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
addAttributes() {
|
|
22
|
+
return {
|
|
23
|
+
href: {
|
|
24
|
+
default: null,
|
|
25
|
+
parseHTML: (element) => {
|
|
26
|
+
const href = element.getAttribute('href');
|
|
27
|
+
|
|
28
|
+
if (!href.startsWith('#')) return href;
|
|
29
|
+
|
|
30
|
+
return parseFloat(element.getAttribute('href').replace('#', ''));
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
target: {
|
|
35
|
+
default: this.options.target,
|
|
36
|
+
parseHTML: (element) => {
|
|
37
|
+
const target = element.getAttribute('target');
|
|
38
|
+
|
|
39
|
+
if (!target) return LinkTargets.SELF;
|
|
40
|
+
|
|
41
|
+
return target;
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
destination: {
|
|
46
|
+
default: LinkDestinations.URL,
|
|
47
|
+
parseHTML: (element) => {
|
|
48
|
+
const href = element.getAttribute('href');
|
|
49
|
+
|
|
50
|
+
if (!href.startsWith('#')) return LinkDestinations.URL;
|
|
51
|
+
|
|
52
|
+
const id = href.replace('#', '');
|
|
53
|
+
const block = this.options.pageBlocks.value.find((block) => block.id === parseInt(id));
|
|
54
|
+
|
|
55
|
+
return block ? LinkDestinations.BLOCK : LinkDestinations.URL;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
addCommands() {
|
|
62
|
+
return {
|
|
63
|
+
...this.parent?.(),
|
|
64
|
+
applyLink: createCommand(({ commands, chain }, attributes) => {
|
|
65
|
+
if (!commands.getSelectedText()) {
|
|
66
|
+
return commands.insertContent({
|
|
67
|
+
type: 'text',
|
|
68
|
+
marks: [
|
|
69
|
+
{
|
|
70
|
+
type: 'link',
|
|
71
|
+
attrs: { ...attributes }
|
|
72
|
+
}
|
|
73
|
+
],
|
|
74
|
+
text: attributes.text
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return chain()
|
|
79
|
+
.setMark(this.name, attributes)
|
|
80
|
+
.transformText(() => attributes.text)
|
|
81
|
+
.extendMarkRange('link')
|
|
82
|
+
.run();
|
|
83
|
+
})
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
renderHTML({ HTMLAttributes: attrs }) {
|
|
88
|
+
const href = attrs.destination === LinkDestinations.BLOCK ? `#${attrs.href}` : attrs.href;
|
|
89
|
+
|
|
90
|
+
const presetClass = this.options.basePresetClass + this.options.preset.id;
|
|
91
|
+
const classes = `${presetClass} zw-style`;
|
|
92
|
+
|
|
93
|
+
const linkAttrs = {
|
|
94
|
+
href,
|
|
95
|
+
target: attrs.target,
|
|
96
|
+
class: classes
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
return ['a', linkAttrs, 0];
|
|
100
|
+
}
|
|
101
|
+
});
|