@zipify/wysiwyg 1.0.0-dev.17 → 1.0.0-dev.18
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/.github/dependabot.yaml +1 -0
- package/dist/wysiwyg.css +199 -12
- package/dist/wysiwyg.js +1 -1
- package/example/ExampleApp.vue +6 -2
- package/example/pageBlocks.js +31 -0
- package/example/presets.js +2 -2
- package/lib/Wysiwyg.vue +14 -3
- package/lib/assets/icons/link.svg +3 -0
- package/lib/assets/icons/unlink.svg +3 -0
- package/lib/components/base/Button.vue +21 -1
- package/lib/components/base/Checkbox.vue +89 -0
- package/lib/components/base/FieldLabel.vue +2 -1
- package/lib/components/base/Icon.vue +2 -2
- package/lib/components/base/Modal.vue +0 -1
- package/lib/components/base/TextField.vue +106 -0
- 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/composables/index.js +1 -0
- package/lib/components/base/composables/useValidator.js +19 -0
- package/lib/components/base/dropdown/Dropdown.vue +15 -3
- package/lib/components/base/dropdown/DropdownActivator.vue +19 -3
- package/lib/components/base/index.js +2 -0
- package/lib/components/toolbar/Toolbar.vue +5 -5
- package/lib/components/toolbar/ToolbarFull.vue +10 -2
- package/lib/components/toolbar/controls/FontSizeControl.vue +7 -0
- package/lib/components/toolbar/controls/UnderlineControl.vue +2 -2
- package/lib/components/toolbar/controls/__tests__/UnderlineControl.test.js +4 -0
- package/lib/components/toolbar/controls/index.js +1 -0
- package/lib/components/toolbar/controls/link/LinkControl.vue +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 +2 -2
- package/lib/composables/useEditor.js +2 -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 +18 -6
- package/lib/extensions/BackgroundColor.js +14 -6
- package/lib/extensions/FontColor.js +14 -6
- package/lib/extensions/FontFamily.js +25 -8
- package/lib/extensions/FontSize.js +26 -13
- package/lib/extensions/FontStyle.js +23 -13
- package/lib/extensions/FontWeight.js +22 -14
- package/lib/extensions/LineHeight.js +11 -3
- package/lib/extensions/Link.js +101 -0
- package/lib/extensions/StylePreset.js +4 -2
- package/lib/extensions/TextDecoration.js +27 -12
- package/lib/extensions/__tests__/Alignment.test.js +11 -5
- package/lib/extensions/__tests__/BackgroundColor.test.js +11 -5
- package/lib/extensions/__tests__/CaseStyle.test.js +3 -5
- package/lib/extensions/__tests__/FontColor.test.js +11 -5
- package/lib/extensions/__tests__/FontFamily.test.js +32 -7
- package/lib/extensions/__tests__/FontSize.test.js +11 -5
- package/lib/extensions/__tests__/FontStyle.test.js +11 -5
- package/lib/extensions/__tests__/FontWeight.test.js +11 -5
- package/lib/extensions/__tests__/LineHeight.test.js +11 -5
- package/lib/extensions/__tests__/StylePreset.test.js +70 -6
- package/lib/extensions/__tests__/TextDecoration.test.js +27 -5
- package/lib/extensions/__tests__/__snapshots__/Alignment.test.js.snap +26 -2
- package/lib/extensions/__tests__/__snapshots__/BackgroundColor.test.js.snap +30 -1
- package/lib/extensions/__tests__/__snapshots__/FontColor.test.js.snap +18 -1
- package/lib/extensions/__tests__/__snapshots__/FontFamily.test.js.snap +88 -1
- package/lib/extensions/__tests__/__snapshots__/FontSize.test.js.snap +33 -2
- package/lib/extensions/__tests__/__snapshots__/FontStyle.test.js.snap +25 -4
- package/lib/extensions/__tests__/__snapshots__/FontWeight.test.js.snap +30 -1
- package/lib/extensions/__tests__/__snapshots__/LineHeight.test.js.snap +26 -2
- package/lib/extensions/__tests__/__snapshots__/StylePreset.test.js.snap +6 -2
- package/lib/extensions/__tests__/__snapshots__/TextDecoration.test.js.snap +93 -3
- package/lib/extensions/core/CopyPasteProcessor.js +10 -0
- package/lib/extensions/core/TextProcessor.js +10 -0
- package/lib/extensions/core/__tests__/NodeProcessor.test.js +3 -5
- package/lib/extensions/core/__tests__/SelectionProcessor.test.js +3 -5
- package/lib/extensions/core/__tests__/TextProcessor.test.js +138 -12
- package/lib/extensions/core/__tests__/__snapshots__/TextProcessor.test.js.snap +26 -0
- package/lib/extensions/core/index.js +11 -2
- package/lib/extensions/core/plugins/PastePlugin.js +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 -34
- package/lib/extensions/list/__tests__/List.test.js +3 -5
- package/lib/extensions/list/__tests__/__snapshots__/List.test.js.snap +45 -15
- package/lib/injectionTokens.js +2 -1
- package/lib/services/ContentNormalizer.js +62 -20
- package/lib/services/__tests__/ContentNormalizer.test.js +40 -7
- package/lib/styles/content.css +17 -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/renderInlineSetting.js +1 -1
- package/package.json +11 -9
|
@@ -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';
|
|
@@ -19,19 +19,31 @@ export const Alignment = Extension.create({
|
|
|
19
19
|
[TextSettings.ALIGNMENT]: {
|
|
20
20
|
isRequired: false,
|
|
21
21
|
|
|
22
|
-
parseHTML(
|
|
23
|
-
|
|
22
|
+
parseHTML({ style }) {
|
|
23
|
+
if (style.textAlign) {
|
|
24
|
+
return {
|
|
25
|
+
desktop: style.textAlign,
|
|
26
|
+
tablet: style.textAlign,
|
|
27
|
+
mobile: style.textAlign
|
|
28
|
+
};
|
|
29
|
+
}
|
|
24
30
|
|
|
25
|
-
|
|
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 };
|
|
26
38
|
},
|
|
27
39
|
|
|
28
40
|
renderHTML(attrs) {
|
|
29
41
|
if (!attrs.alignment) return null;
|
|
30
42
|
|
|
31
43
|
return renderInlineSetting({
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
44
|
+
text_align_mobile: attrs.alignment.mobile,
|
|
45
|
+
text_align_tablet: attrs.alignment.tablet,
|
|
46
|
+
text_align_desktop: attrs.alignment.desktop
|
|
35
47
|
});
|
|
36
48
|
}
|
|
37
49
|
}
|
|
@@ -22,12 +22,20 @@ export const BackgroundColor = Mark.create({
|
|
|
22
22
|
};
|
|
23
23
|
},
|
|
24
24
|
|
|
25
|
-
parseHTML
|
|
26
|
-
{
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
+
},
|
|
31
39
|
|
|
32
40
|
renderHTML({ HTMLAttributes: attrs }) {
|
|
33
41
|
return renderMark({ background_color: attrs.value });
|
|
@@ -30,12 +30,20 @@ export const FontColor = Mark.create({
|
|
|
30
30
|
};
|
|
31
31
|
},
|
|
32
32
|
|
|
33
|
-
parseHTML
|
|
34
|
-
{
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
+
},
|
|
39
47
|
|
|
40
48
|
renderHTML({ HTMLAttributes: attrs }) {
|
|
41
49
|
return renderMark({ font_color: attrs.value });
|
|
@@ -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,14 +57,30 @@ export const FontFamily = Mark.create({
|
|
|
56
57
|
};
|
|
57
58
|
},
|
|
58
59
|
|
|
59
|
-
parseHTML
|
|
60
|
-
{
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
+
},
|
|
65
80
|
|
|
66
81
|
renderHTML({ HTMLAttributes: attrs }) {
|
|
67
|
-
|
|
82
|
+
const font_family = attrs.value ? `"${attrs.value}"` : null;
|
|
83
|
+
|
|
84
|
+
return renderMark({ font_family });
|
|
68
85
|
}
|
|
69
86
|
});
|
|
@@ -62,25 +62,38 @@ export const FontSize = Mark.create({
|
|
|
62
62
|
'Mod-Shift--': createKeyboardShortcut('decreaseFontSize')
|
|
63
63
|
}),
|
|
64
64
|
|
|
65
|
-
parseHTML
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
+
}
|
|
73
86
|
}
|
|
74
|
-
|
|
75
|
-
|
|
87
|
+
];
|
|
88
|
+
},
|
|
76
89
|
|
|
77
90
|
renderHTML({ HTMLAttributes: attrs }) {
|
|
78
91
|
const addUnits = (value) => value ? `${value}px` : null;
|
|
79
92
|
|
|
80
93
|
return renderMark({
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
94
|
+
font_size_mobile: addUnits(attrs.mobile),
|
|
95
|
+
font_size_tablet: addUnits(attrs.tablet),
|
|
96
|
+
font_size_desktop: addUnits(attrs.desktop)
|
|
84
97
|
});
|
|
85
98
|
}
|
|
86
99
|
});
|
|
@@ -56,18 +56,28 @@ export const FontStyle = Mark.create({
|
|
|
56
56
|
'Mod-I': createKeyboardShortcut('toggleItalic')
|
|
57
57
|
}),
|
|
58
58
|
|
|
59
|
-
parseHTML
|
|
60
|
-
{
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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 });
|
|
72
82
|
}
|
|
73
83
|
});
|
|
@@ -59,20 +59,28 @@ export const FontWeight = Mark.create({
|
|
|
59
59
|
'Mod-B': createKeyboardShortcut('toggleBold')
|
|
60
60
|
}),
|
|
61
61
|
|
|
62
|
-
parseHTML
|
|
63
|
-
{
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
+
},
|
|
76
84
|
|
|
77
85
|
renderHTML({ HTMLAttributes: attrs }) {
|
|
78
86
|
return renderMark({ font_weight: attrs.value });
|
|
@@ -21,6 +21,14 @@ export const LineHeight = Extension.create({
|
|
|
21
21
|
isRequired: false,
|
|
22
22
|
|
|
23
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
|
+
|
|
24
32
|
const value = element.style.lineHeight;
|
|
25
33
|
|
|
26
34
|
if (!value) return null;
|
|
@@ -41,9 +49,9 @@ export const LineHeight = Extension.create({
|
|
|
41
49
|
if (!attrs.line_height) return null;
|
|
42
50
|
|
|
43
51
|
return renderInlineSetting({
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
52
|
+
line_height_mobile: attrs.line_height.mobile,
|
|
53
|
+
line_height_tablet: attrs.line_height.tablet,
|
|
54
|
+
line_height_desktop: attrs.line_height.desktop
|
|
47
55
|
});
|
|
48
56
|
}
|
|
49
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
|
+
});
|
|
@@ -39,11 +39,13 @@ export const StylePreset = Extension.create({
|
|
|
39
39
|
attributes: {
|
|
40
40
|
preset: {
|
|
41
41
|
isRequired: false,
|
|
42
|
-
default:
|
|
42
|
+
default: { id: this.options.defaultId },
|
|
43
43
|
|
|
44
44
|
parseHTML: (element) => {
|
|
45
45
|
const presets = this.options.presetsRef.value;
|
|
46
46
|
|
|
47
|
+
if (element.parentElement.tagName === 'LI') return null;
|
|
48
|
+
|
|
47
49
|
for (const { id, node, fallbackClass } of presets) {
|
|
48
50
|
const isFallback = fallbackClass && element.classList.contains(fallbackClass);
|
|
49
51
|
|
|
@@ -148,7 +150,7 @@ export const StylePreset = Extension.create({
|
|
|
148
150
|
chain()
|
|
149
151
|
.storeSelection()
|
|
150
152
|
.expandSelectionToBlock()
|
|
151
|
-
.
|
|
153
|
+
.unsetMarks(TextSettings.marks)
|
|
152
154
|
.resetAttributes(NodeTypes.PARAGRAPH, TextSettings.attributes)
|
|
153
155
|
.resetAttributes(NodeTypes.HEADING, TextSettings.attributes)
|
|
154
156
|
.restoreSelection()
|
|
@@ -13,10 +13,10 @@ export const TextDecoration = Mark.create({
|
|
|
13
13
|
|
|
14
14
|
addCommands() {
|
|
15
15
|
return {
|
|
16
|
-
isUnderline: createCommand(({ commands }) => {
|
|
16
|
+
isUnderline: createCommand(({ commands, editor }) => {
|
|
17
17
|
const decoration = commands.getTextDecoration();
|
|
18
18
|
|
|
19
|
-
return computed(() => decoration.value.underline);
|
|
19
|
+
return computed(() => editor.isActive('link') || decoration.value.underline);
|
|
20
20
|
}),
|
|
21
21
|
|
|
22
22
|
isStrikeThrough: createCommand(({ commands }) => {
|
|
@@ -51,7 +51,9 @@ export const TextDecoration = Mark.create({
|
|
|
51
51
|
});
|
|
52
52
|
}),
|
|
53
53
|
|
|
54
|
-
toggleUnderline: createCommand(({ commands }) => {
|
|
54
|
+
toggleUnderline: createCommand(({ commands, editor }) => {
|
|
55
|
+
if (editor.isActive('link')) return;
|
|
56
|
+
|
|
55
57
|
commands.toggleTextDecoration('underline');
|
|
56
58
|
}),
|
|
57
59
|
|
|
@@ -86,16 +88,29 @@ export const TextDecoration = Mark.create({
|
|
|
86
88
|
'Mod-U': createKeyboardShortcut('toggleUnderline')
|
|
87
89
|
}),
|
|
88
90
|
|
|
89
|
-
parseHTML
|
|
90
|
-
{
|
|
91
|
-
|
|
91
|
+
parseHTML() {
|
|
92
|
+
const getAttrs = (value) => {
|
|
93
|
+
const underline = value.includes('underline');
|
|
94
|
+
const strike_through = value.includes('line-through');
|
|
92
95
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
96
|
+
if (!underline && !strike_through) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return { underline, strike_through };
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
return [
|
|
104
|
+
{
|
|
105
|
+
style: '--zw-text-decoration',
|
|
106
|
+
getAttrs
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
style: 'text-decoration-line',
|
|
110
|
+
getAttrs
|
|
111
|
+
}
|
|
112
|
+
];
|
|
113
|
+
},
|
|
99
114
|
|
|
100
115
|
renderHTML({ HTMLAttributes: attrs }) {
|
|
101
116
|
const decorations = [];
|
|
@@ -2,11 +2,11 @@ import { Editor, Extension } from '@tiptap/vue-2';
|
|
|
2
2
|
import { ref } from '@vue/composition-api';
|
|
3
3
|
import { NodeFactory } from '../../__tests__/utils';
|
|
4
4
|
import { createCommand } from '../../utils';
|
|
5
|
-
import { CORE_EXTENSIONS } from '../core';
|
|
6
5
|
import { Alignment } from '../Alignment';
|
|
7
6
|
import { DeviceManager } from '../DeviceManager';
|
|
8
7
|
import { Alignments } from '../../enums';
|
|
9
8
|
import { ContentNormalizer } from '../../services';
|
|
9
|
+
import { buildCoreExtensions } from '../core';
|
|
10
10
|
|
|
11
11
|
const MockStylePreset = Extension.create({
|
|
12
12
|
name: 'style_preset',
|
|
@@ -23,11 +23,9 @@ const MockStylePreset = Extension.create({
|
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
function createEditor({ content }) {
|
|
26
|
-
const normalizer = new ContentNormalizer();
|
|
27
|
-
|
|
28
26
|
return new Editor({
|
|
29
|
-
content:
|
|
30
|
-
extensions:
|
|
27
|
+
content: ContentNormalizer.normalize(content),
|
|
28
|
+
extensions: buildCoreExtensions().concat(
|
|
31
29
|
MockStylePreset,
|
|
32
30
|
DeviceManager.configure({ deviceRef: ref('desktop') }),
|
|
33
31
|
Alignment
|
|
@@ -118,6 +116,14 @@ describe('parsing html', () => {
|
|
|
118
116
|
expect(editor.getJSON()).toMatchSnapshot();
|
|
119
117
|
});
|
|
120
118
|
|
|
119
|
+
test('should get alignment from rendered view', () => {
|
|
120
|
+
const editor = createEditor({
|
|
121
|
+
content: '<p style="--zw-text-align-mobile:center;--zw-text-align-desktop:right">test</p>'
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
125
|
+
});
|
|
126
|
+
|
|
121
127
|
test('should set null if no alignment', () => {
|
|
122
128
|
const editor = createEditor({
|
|
123
129
|
content: '<p>test</p>'
|
|
@@ -2,9 +2,9 @@ import { Editor, Extension } from '@tiptap/vue-2';
|
|
|
2
2
|
import { ref } from '@vue/composition-api';
|
|
3
3
|
import { NodeFactory } from '../../__tests__/utils';
|
|
4
4
|
import { createCommand } from '../../utils';
|
|
5
|
-
import { CORE_EXTENSIONS } from '../core';
|
|
6
5
|
import { BackgroundColor } from '../BackgroundColor';
|
|
7
6
|
import { ContentNormalizer } from '../../services';
|
|
7
|
+
import { buildCoreExtensions } from '../core';
|
|
8
8
|
|
|
9
9
|
const MockStylePreset = Extension.create({
|
|
10
10
|
name: 'style_preset',
|
|
@@ -19,11 +19,9 @@ const MockStylePreset = Extension.create({
|
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
function createEditor({ content }) {
|
|
22
|
-
const normalizer = new ContentNormalizer();
|
|
23
|
-
|
|
24
22
|
return new Editor({
|
|
25
|
-
content:
|
|
26
|
-
extensions:
|
|
23
|
+
content: ContentNormalizer.normalize(content),
|
|
24
|
+
extensions: buildCoreExtensions().concat(MockStylePreset, BackgroundColor)
|
|
27
25
|
});
|
|
28
26
|
}
|
|
29
27
|
|
|
@@ -94,6 +92,14 @@ describe('parsing html', () => {
|
|
|
94
92
|
expect(editor.getJSON()).toMatchSnapshot();
|
|
95
93
|
});
|
|
96
94
|
|
|
95
|
+
test('should get value from rendered view', () => {
|
|
96
|
+
const editor = createEditor({
|
|
97
|
+
content: '<p><span style="--zw-background-color: red">lorem</span> ipsum</p>'
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
101
|
+
});
|
|
102
|
+
|
|
97
103
|
test('should merge paragraph and text settings', () => {
|
|
98
104
|
const editor = createEditor({
|
|
99
105
|
content: '<p style="background-color: red"><span style="background-color: #000">lorem</span> ipsum</p>'
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import { Editor } from '@tiptap/vue-2';
|
|
2
2
|
import { NodeFactory } from '../../__tests__/utils';
|
|
3
3
|
import { CaseStyles } from '../../enums';
|
|
4
|
-
import { CORE_EXTENSIONS } from '../core';
|
|
5
4
|
import { CaseStyle } from '../CaseStyle';
|
|
6
5
|
import { ContentNormalizer } from '../../services';
|
|
6
|
+
import { buildCoreExtensions } from '../core';
|
|
7
7
|
|
|
8
8
|
function createEditor({ content }) {
|
|
9
|
-
const normalizer = new ContentNormalizer();
|
|
10
|
-
|
|
11
9
|
return new Editor({
|
|
12
|
-
content:
|
|
13
|
-
extensions:
|
|
10
|
+
content: ContentNormalizer.normalize(content),
|
|
11
|
+
extensions: buildCoreExtensions().concat(CaseStyle)
|
|
14
12
|
});
|
|
15
13
|
}
|
|
16
14
|
|
|
@@ -2,9 +2,9 @@ import { Editor, Extension } from '@tiptap/vue-2';
|
|
|
2
2
|
import { ref } from '@vue/composition-api';
|
|
3
3
|
import { NodeFactory } from '../../__tests__/utils';
|
|
4
4
|
import { createCommand } from '../../utils';
|
|
5
|
-
import { CORE_EXTENSIONS } from '../core';
|
|
6
5
|
import { FontColor } from '../FontColor';
|
|
7
6
|
import { ContentNormalizer } from '../../services';
|
|
7
|
+
import { buildCoreExtensions } from '../core';
|
|
8
8
|
|
|
9
9
|
const MockStylePreset = Extension.create({
|
|
10
10
|
name: 'style_preset',
|
|
@@ -19,11 +19,9 @@ const MockStylePreset = Extension.create({
|
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
function createEditor({ content }) {
|
|
22
|
-
const normalizer = new ContentNormalizer();
|
|
23
|
-
|
|
24
22
|
return new Editor({
|
|
25
|
-
content:
|
|
26
|
-
extensions:
|
|
23
|
+
content: ContentNormalizer.normalize(content),
|
|
24
|
+
extensions: buildCoreExtensions().concat(MockStylePreset, FontColor)
|
|
27
25
|
});
|
|
28
26
|
}
|
|
29
27
|
|
|
@@ -104,6 +102,14 @@ describe('parsing html', () => {
|
|
|
104
102
|
expect(editor.getJSON()).toMatchSnapshot();
|
|
105
103
|
});
|
|
106
104
|
|
|
105
|
+
test('should get value from parsed view', () => {
|
|
106
|
+
const editor = createEditor({
|
|
107
|
+
content: '<p><span style="--zw-color: red">lorem</span> ipsum</p>'
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
111
|
+
});
|
|
112
|
+
|
|
107
113
|
test('should merge paragraph and text settings', () => {
|
|
108
114
|
const editor = createEditor({
|
|
109
115
|
content: '<p style="color: red"><span style="color: #000">lorem</span> ipsum</p>'
|