@zipify/wysiwyg 3.1.0-2 → 3.1.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/.eslintrc.js +17 -235
- package/.github/actions/setup/action.yaml +1 -1
- package/README.md +2 -0
- package/config/build/cli.config.js +6 -6
- package/config/build/lib.config.js +5 -3
- package/config/svgo.js +6 -3
- package/dist/cli.js +5 -4
- package/dist/wysiwyg.css +18 -18
- package/dist/wysiwyg.mjs +12502 -11732
- package/example/tooltip/Tooltip.js +92 -69
- package/example/tooltip/modifiers/TooltipCloseOnScrollModifier.js +2 -5
- package/example/tooltip/tooltip.css +8 -31
- package/lib/Wysiwyg.vue +3 -0
- package/lib/cli/commands/ToJsonCommand.js +6 -6
- package/lib/components/base/__tests__/Button.test.js +1 -1
- package/lib/components/base/composables/__tests__/useDeselectionLock.test.js +2 -2
- package/lib/components/base/composables/__tests__/useElementRef.test.js +1 -1
- package/lib/components/base/composables/__tests__/useModalToggler.test.js +0 -2
- package/lib/components/base/composables/__tests__/useValidator.test.js +2 -2
- package/lib/components/base/composables/useModalToggler.js +30 -24
- package/lib/components/toolbar/Toolbar.vue +1 -1
- package/lib/components/toolbar/base/__tests__/ToolbarDivider.test.js +1 -1
- package/lib/components/toolbar/controls/StylePresetControl.vue +1 -1
- package/lib/components/toolbar/controls/__tests__/LineHeightControl.test.js +0 -2
- package/lib/components/toolbar/controls/composables/__tests__/useRecentFonts.test.js +1 -1
- package/lib/components/toolbar/controls/link/composables/__tests__/useLink.test.js +2 -2
- package/lib/composables/useToolbar.js +24 -19
- package/lib/extensions/FontSize.js +1 -2
- package/lib/extensions/Link.js +2 -0
- package/lib/extensions/__tests__/BackgroundColor.test.js +2 -2
- package/lib/extensions/__tests__/FontColor.test.js +3 -3
- package/lib/extensions/__tests__/FontFamily.test.js +3 -3
- package/lib/extensions/__tests__/FontSize.test.js +3 -3
- package/lib/extensions/__tests__/FontWeight.test.js +4 -4
- package/lib/extensions/__tests__/LineHeight.test.js +2 -2
- package/lib/extensions/__tests__/Link.test.js +33 -5
- package/lib/extensions/__tests__/__snapshots__/Link.test.js.snap +27 -0
- package/lib/extensions/core/Document.js +8 -1
- package/lib/extensions/core/NodeProcessor.js +3 -4
- package/lib/extensions/core/__tests__/NodeProcessor.test.js +6 -8
- package/lib/extensions/core/__tests__/TextProcessor.test.js +1 -1
- package/lib/extensions/core/index.js +0 -2
- package/lib/extensions/core/plugins/PlaceholderPlugin.js +2 -2
- package/lib/extensions/list/List.js +4 -5
- package/lib/extensions/list/ListItem.js +1 -2
- package/lib/extensions/list/__tests__/List.test.js +1 -1
- package/lib/models/Font.js +2 -2
- package/lib/models/__tests__/Font.test.js +3 -9
- package/lib/services/ContentSerializer.js +8 -8
- package/lib/services/HtmlToJsonParser.js +3 -3
- package/lib/services/NodeFactory.js +6 -6
- package/lib/services/StylePresetRenderer.js +11 -11
- package/lib/services/__tests__/JsonSerializer.test.js +1 -1
- package/lib/services/__tests__/Storage.test.js +1 -1
- package/lib/services/__tests__/StylePresetRenderer.test.js +1 -1
- package/lib/services/normalizer/BrowserDomParser.js +2 -2
- package/lib/services/normalizer/ContentNormalizer.js +3 -3
- package/lib/services/normalizer/HtmlNormalizer.js +52 -52
- package/lib/services/normalizer/JsonNormalizer.js +21 -21
- package/lib/utils/__tests__/convertAlignment.test.js +1 -1
- package/lib/utils/__tests__/renderInlineSetting.test.js +2 -2
- package/package.json +50 -48
- package/lib/extensions/core/steps/AddNodeMarkStep.js +0 -66
- package/lib/extensions/core/steps/AttrStep.js +0 -60
- package/lib/extensions/core/steps/RemoveNodeMarkStep.js +0 -56
- package/lib/extensions/core/steps/index.js +0 -3
|
@@ -1,33 +1,38 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { autoUpdate, computePosition, limitShift, offset, shift } from '@floating-ui/dom';
|
|
1
|
+
import { createPopper } from '@popperjs/core';
|
|
3
2
|
import { useElementRef } from '../components/base';
|
|
4
3
|
|
|
5
4
|
export function useToolbar({ wrapperRef, offsets, isActiveRef, placementRef }) {
|
|
6
5
|
const wrapperEl = useElementRef(wrapperRef);
|
|
7
|
-
let
|
|
6
|
+
let popper;
|
|
8
7
|
|
|
9
8
|
function mount(element) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
9
|
+
popper = createPopper(wrapperEl.value, element, {
|
|
10
|
+
placement: placementRef.value,
|
|
11
|
+
strategy: 'fixed',
|
|
12
|
+
modifiers: [
|
|
13
|
+
{
|
|
14
|
+
name: 'offset',
|
|
15
|
+
options: { offset: offsets }
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
name: 'preventOverflow',
|
|
19
|
+
options: {
|
|
20
|
+
altAxis: true,
|
|
21
|
+
padding: 2
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: 'flip',
|
|
26
|
+
enabled: false
|
|
27
|
+
}
|
|
28
|
+
]
|
|
25
29
|
});
|
|
26
30
|
}
|
|
27
31
|
|
|
28
|
-
|
|
32
|
+
const update = () => popper?.update();
|
|
29
33
|
|
|
30
34
|
return {
|
|
35
|
+
update,
|
|
31
36
|
mount,
|
|
32
37
|
isActiveRef,
|
|
33
38
|
offsets
|
|
@@ -2,7 +2,6 @@ import { Mark } from '@tiptap/vue-2';
|
|
|
2
2
|
import { computed, unref } from 'vue';
|
|
3
3
|
import { convertFontSize, createCommand, createKeyboardShortcut, renderMark } from '../utils';
|
|
4
4
|
import { MarkGroups, TextSettings } from '../enums';
|
|
5
|
-
import { AddNodeMarkStep } from './core';
|
|
6
5
|
|
|
7
6
|
export const FontSize = Mark.create({
|
|
8
7
|
name: TextSettings.FONT_SIZE,
|
|
@@ -57,7 +56,7 @@ export const FontSize = Mark.create({
|
|
|
57
56
|
return;
|
|
58
57
|
}
|
|
59
58
|
|
|
60
|
-
tr.
|
|
59
|
+
tr.addNodeMark(position, updated);
|
|
61
60
|
}
|
|
62
61
|
});
|
|
63
62
|
}),
|
package/lib/extensions/Link.js
CHANGED
|
@@ -55,6 +55,8 @@ export const Link = Base.extend({
|
|
|
55
55
|
...this.parent?.(),
|
|
56
56
|
|
|
57
57
|
applyLink: createCommand(({ commands, chain }, attributes) => {
|
|
58
|
+
commands.setMeta('preventAutolink', true);
|
|
59
|
+
|
|
58
60
|
if (!commands.getSelectedText()) {
|
|
59
61
|
return commands.insertContent(NodeFactory.text(attributes.text, [
|
|
60
62
|
NodeFactory.mark(TextSettings.LINK, attributes)
|
|
@@ -41,7 +41,7 @@ describe('get background color', () => {
|
|
|
41
41
|
|
|
42
42
|
editor.commands.selectAll();
|
|
43
43
|
|
|
44
|
-
expect(editor.commands.getBackgroundColor().value).
|
|
44
|
+
expect(editor.commands.getBackgroundColor().value).toBe('green');
|
|
45
45
|
});
|
|
46
46
|
|
|
47
47
|
test('should get default background color', () => {
|
|
@@ -49,7 +49,7 @@ describe('get background color', () => {
|
|
|
49
49
|
content: createContent(NodeFactory.text('hello world'))
|
|
50
50
|
});
|
|
51
51
|
|
|
52
|
-
expect(editor.commands.getBackgroundColor().value).
|
|
52
|
+
expect(editor.commands.getBackgroundColor().value).toBe('rgba(255, 255, 255, 0%)');
|
|
53
53
|
});
|
|
54
54
|
});
|
|
55
55
|
|
|
@@ -41,7 +41,7 @@ describe('get font color', () => {
|
|
|
41
41
|
|
|
42
42
|
editor.commands.selectAll();
|
|
43
43
|
|
|
44
|
-
expect(editor.commands.getFontColor().value).
|
|
44
|
+
expect(editor.commands.getFontColor().value).toBe('green');
|
|
45
45
|
});
|
|
46
46
|
|
|
47
47
|
test('should get default font color', () => {
|
|
@@ -49,7 +49,7 @@ describe('get font color', () => {
|
|
|
49
49
|
content: createContent(NodeFactory.text('hello world'))
|
|
50
50
|
});
|
|
51
51
|
|
|
52
|
-
expect(editor.commands.getDefaultFontColor().value).
|
|
52
|
+
expect(editor.commands.getDefaultFontColor().value).toBe('red');
|
|
53
53
|
});
|
|
54
54
|
|
|
55
55
|
test('should get from preset', () => {
|
|
@@ -59,7 +59,7 @@ describe('get font color', () => {
|
|
|
59
59
|
|
|
60
60
|
editor.commands.selectAll();
|
|
61
61
|
|
|
62
|
-
expect(editor.commands.getFontColor().value).
|
|
62
|
+
expect(editor.commands.getFontColor().value).toBe('red');
|
|
63
63
|
});
|
|
64
64
|
});
|
|
65
65
|
|
|
@@ -62,7 +62,7 @@ describe('get font family', () => {
|
|
|
62
62
|
|
|
63
63
|
editor.commands.selectAll();
|
|
64
64
|
|
|
65
|
-
expect(editor.commands.getFontFamily().value).
|
|
65
|
+
expect(editor.commands.getFontFamily().value).toBe('Bungee');
|
|
66
66
|
});
|
|
67
67
|
|
|
68
68
|
test('should get default font family', () => {
|
|
@@ -70,7 +70,7 @@ describe('get font family', () => {
|
|
|
70
70
|
content: createContent(NodeFactory.text('hello world'))
|
|
71
71
|
});
|
|
72
72
|
|
|
73
|
-
expect(editor.commands.getDefaultFontFamily().value).
|
|
73
|
+
expect(editor.commands.getDefaultFontFamily().value).toBe('Lato');
|
|
74
74
|
});
|
|
75
75
|
|
|
76
76
|
test('should get from preset', () => {
|
|
@@ -80,7 +80,7 @@ describe('get font family', () => {
|
|
|
80
80
|
|
|
81
81
|
editor.commands.selectAll();
|
|
82
82
|
|
|
83
|
-
expect(editor.commands.getFontFamily().value).
|
|
83
|
+
expect(editor.commands.getFontFamily().value).toBe('Lato');
|
|
84
84
|
});
|
|
85
85
|
|
|
86
86
|
test('should find font model by name', () => {
|
|
@@ -58,7 +58,7 @@ describe('get font size', () => {
|
|
|
58
58
|
|
|
59
59
|
editor.commands.selectAll();
|
|
60
60
|
|
|
61
|
-
expect(editor.commands.getFontSize().value).
|
|
61
|
+
expect(editor.commands.getFontSize().value).toBe('14');
|
|
62
62
|
});
|
|
63
63
|
|
|
64
64
|
test('should default value', () => {
|
|
@@ -66,7 +66,7 @@ describe('get font size', () => {
|
|
|
66
66
|
content: createContent(NodeFactory.text('hello world'))
|
|
67
67
|
});
|
|
68
68
|
|
|
69
|
-
expect(editor.commands.getDefaultFontSize().value).
|
|
69
|
+
expect(editor.commands.getDefaultFontSize().value).toBe('14');
|
|
70
70
|
});
|
|
71
71
|
|
|
72
72
|
test('should get from preset', () => {
|
|
@@ -76,7 +76,7 @@ describe('get font size', () => {
|
|
|
76
76
|
|
|
77
77
|
editor.commands.selectAll();
|
|
78
78
|
|
|
79
|
-
expect(editor.commands.getFontSize().value).
|
|
79
|
+
expect(editor.commands.getFontSize().value).toBe('14');
|
|
80
80
|
});
|
|
81
81
|
});
|
|
82
82
|
|
|
@@ -60,7 +60,7 @@ describe('get font weight', () => {
|
|
|
60
60
|
|
|
61
61
|
editor.commands.selectAll();
|
|
62
62
|
|
|
63
|
-
expect(editor.commands.getFontWeight().value).
|
|
63
|
+
expect(editor.commands.getFontWeight().value).toBe('700');
|
|
64
64
|
});
|
|
65
65
|
|
|
66
66
|
test('should default value', () => {
|
|
@@ -68,7 +68,7 @@ describe('get font weight', () => {
|
|
|
68
68
|
content: createContent(NodeFactory.text('hello world'))
|
|
69
69
|
});
|
|
70
70
|
|
|
71
|
-
expect(editor.commands.getDefaultFontWeight().value).
|
|
71
|
+
expect(editor.commands.getDefaultFontWeight().value).toBe('400');
|
|
72
72
|
});
|
|
73
73
|
|
|
74
74
|
test('should get from preset', () => {
|
|
@@ -78,7 +78,7 @@ describe('get font weight', () => {
|
|
|
78
78
|
|
|
79
79
|
editor.commands.selectAll();
|
|
80
80
|
|
|
81
|
-
expect(editor.commands.getFontWeight().value).
|
|
81
|
+
expect(editor.commands.getFontWeight().value).toBe('400');
|
|
82
82
|
});
|
|
83
83
|
|
|
84
84
|
test('should get closest available font weight', () => {
|
|
@@ -90,7 +90,7 @@ describe('get font weight', () => {
|
|
|
90
90
|
|
|
91
91
|
editor.commands.selectAll();
|
|
92
92
|
|
|
93
|
-
expect(editor.commands.getFontWeight().value).
|
|
93
|
+
expect(editor.commands.getFontWeight().value).toBe('700');
|
|
94
94
|
});
|
|
95
95
|
});
|
|
96
96
|
|
|
@@ -62,7 +62,7 @@ describe('get value', () => {
|
|
|
62
62
|
content: createContent({ line_height: null })
|
|
63
63
|
});
|
|
64
64
|
|
|
65
|
-
expect(editor.commands.getDefaultLineHeight().value).
|
|
65
|
+
expect(editor.commands.getDefaultLineHeight().value).toBe('1.2');
|
|
66
66
|
});
|
|
67
67
|
|
|
68
68
|
test('should get from preset', () => {
|
|
@@ -70,7 +70,7 @@ describe('get value', () => {
|
|
|
70
70
|
content: createContent({ line_height: null })
|
|
71
71
|
});
|
|
72
72
|
|
|
73
|
-
expect(editor.commands.getLineHeight().value).
|
|
73
|
+
expect(editor.commands.getLineHeight().value).toBe('1.2');
|
|
74
74
|
});
|
|
75
75
|
});
|
|
76
76
|
|
|
@@ -3,7 +3,7 @@ import { Editor, Mark } from '@tiptap/vue-2';
|
|
|
3
3
|
import { buildTestExtensions } from '../../__tests__/utils';
|
|
4
4
|
import { ContentNormalizer, NodeFactory } from '../../services';
|
|
5
5
|
import { Link } from '../Link';
|
|
6
|
-
import { TextSettings } from '../../enums';
|
|
6
|
+
import { LinkDestinations, LinkTargets, TextSettings } from '../../enums';
|
|
7
7
|
|
|
8
8
|
const MockFontWeight = Mark.create({
|
|
9
9
|
name: TextSettings.FONT_WEIGHT,
|
|
@@ -27,11 +27,12 @@ function createEditor({ content }) {
|
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
const createLink = (
|
|
31
|
-
href:
|
|
30
|
+
const createLink = (attrs = {}) => ({
|
|
31
|
+
href: '/test',
|
|
32
32
|
text: 'Hello world link',
|
|
33
|
-
target:
|
|
34
|
-
destination:
|
|
33
|
+
target: LinkTargets.SELF,
|
|
34
|
+
destination: LinkDestinations.URL,
|
|
35
|
+
...attrs
|
|
35
36
|
});
|
|
36
37
|
|
|
37
38
|
describe('get link', () => {
|
|
@@ -108,6 +109,33 @@ describe('apply link', () => {
|
|
|
108
109
|
|
|
109
110
|
expect(editor.getJSON()).toMatchSnapshot();
|
|
110
111
|
});
|
|
112
|
+
|
|
113
|
+
test('should apply link to text with link', () => {
|
|
114
|
+
const editor = createEditor({
|
|
115
|
+
content: NodeFactory.doc([
|
|
116
|
+
NodeFactory.paragraph([
|
|
117
|
+
NodeFactory.text('https://google.com', [
|
|
118
|
+
NodeFactory.mark(TextSettings.LINK, {
|
|
119
|
+
href: 'https://google.com',
|
|
120
|
+
destination: LinkDestinations.URL,
|
|
121
|
+
target: LinkTargets.SELF
|
|
122
|
+
})
|
|
123
|
+
])
|
|
124
|
+
])
|
|
125
|
+
])
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
editor.commands.selectAll();
|
|
129
|
+
|
|
130
|
+
editor.commands.applyLink({
|
|
131
|
+
text: 'https://google.com',
|
|
132
|
+
href: 'https://google.com',
|
|
133
|
+
destination: LinkDestinations.URL,
|
|
134
|
+
target: LinkTargets.BLANK
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
138
|
+
});
|
|
111
139
|
});
|
|
112
140
|
|
|
113
141
|
describe('parse html', () => {
|
|
@@ -60,6 +60,33 @@ Object {
|
|
|
60
60
|
}
|
|
61
61
|
`;
|
|
62
62
|
|
|
63
|
+
exports[`apply link should apply link to text with link 1`] = `
|
|
64
|
+
Object {
|
|
65
|
+
"content": Array [
|
|
66
|
+
Object {
|
|
67
|
+
"content": Array [
|
|
68
|
+
Object {
|
|
69
|
+
"marks": Array [
|
|
70
|
+
Object {
|
|
71
|
+
"attrs": Object {
|
|
72
|
+
"destination": "url",
|
|
73
|
+
"href": "https://google.com",
|
|
74
|
+
"target": "_blank",
|
|
75
|
+
},
|
|
76
|
+
"type": "link",
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
"text": "https://google.com",
|
|
80
|
+
"type": "text",
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
"type": "paragraph",
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
"type": "doc",
|
|
87
|
+
}
|
|
88
|
+
`;
|
|
89
|
+
|
|
63
90
|
exports[`apply link should apply link when no selected text 1`] = `
|
|
64
91
|
Object {
|
|
65
92
|
"content": Array [
|
|
@@ -2,5 +2,12 @@ import { Document as Base } from '@tiptap/extension-document';
|
|
|
2
2
|
import { MarkGroups } from '../../enums';
|
|
3
3
|
|
|
4
4
|
export const Document = Base.extend({
|
|
5
|
-
marks: MarkGroups.SETTINGS
|
|
5
|
+
marks: MarkGroups.SETTINGS,
|
|
6
|
+
|
|
7
|
+
onCreate() {
|
|
8
|
+
// Prevent open links in new tab when editor is readonly
|
|
9
|
+
this.editor.view.dom.addEventListener('click', (event) => {
|
|
10
|
+
if (event.target.closest('a')) event.preventDefault();
|
|
11
|
+
});
|
|
12
|
+
}
|
|
6
13
|
});
|
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
resolveTextPosition
|
|
9
9
|
} from '../../utils';
|
|
10
10
|
import { MarkGroups, NodeTypes, TextSettings } from '../../enums';
|
|
11
|
-
import { AddNodeMarkStep, AttrStep, RemoveNodeMarkStep } from './steps';
|
|
12
11
|
|
|
13
12
|
export const NodeProcessor = Extension.create({
|
|
14
13
|
name: 'node_processor',
|
|
@@ -23,7 +22,7 @@ export const NodeProcessor = Extension.create({
|
|
|
23
22
|
doc.nodesBetween(from, to, (node, position) => {
|
|
24
23
|
if (!NodeTypes.blocks.includes(node.type.name)) return;
|
|
25
24
|
|
|
26
|
-
tr.
|
|
25
|
+
tr.setNodeAttribute(position, name, { ...defaults, ...current, ...attrs });
|
|
27
26
|
});
|
|
28
27
|
}),
|
|
29
28
|
|
|
@@ -85,7 +84,7 @@ export const NodeProcessor = Extension.create({
|
|
|
85
84
|
}
|
|
86
85
|
|
|
87
86
|
if (isNodeFullySelected(tr.doc, tr.selection, node, position)) {
|
|
88
|
-
tr.
|
|
87
|
+
tr.addNodeMark(position, applyingMark);
|
|
89
88
|
}
|
|
90
89
|
});
|
|
91
90
|
}),
|
|
@@ -168,7 +167,7 @@ export const NodeProcessor = Extension.create({
|
|
|
168
167
|
_removeNodeMark: createCommand((context, { tr, node, position, mark }) => {
|
|
169
168
|
return node.isText
|
|
170
169
|
? tr.removeMark(position, position + node.nodeSize, mark)
|
|
171
|
-
: tr.
|
|
170
|
+
: tr.removeNodeMark(position, mark);
|
|
172
171
|
})
|
|
173
172
|
};
|
|
174
173
|
}
|
|
@@ -127,7 +127,7 @@ describe('block attributes', () => {
|
|
|
127
127
|
});
|
|
128
128
|
const attrs = editor.commands.getBlockAttributes(TextSettings.LINE_HEIGHT);
|
|
129
129
|
|
|
130
|
-
expect(attrs.value).
|
|
130
|
+
expect(attrs.value).toBeNull();
|
|
131
131
|
});
|
|
132
132
|
|
|
133
133
|
test('should set attributes', () => {
|
|
@@ -267,9 +267,7 @@ describe('apply mark', () => {
|
|
|
267
267
|
|
|
268
268
|
expect(editor.getJSON()).toMatchSnapshot();
|
|
269
269
|
});
|
|
270
|
-
});
|
|
271
270
|
|
|
272
|
-
describe('apply mark', () => {
|
|
273
271
|
test('should apply inline mark', () => {
|
|
274
272
|
const editor = createEditor({
|
|
275
273
|
content: NodeFactory.doc([
|
|
@@ -481,7 +479,7 @@ describe('get setting mark', () => {
|
|
|
481
479
|
editor.commands.selectAll();
|
|
482
480
|
const selectionRef = editor.commands.getCommonSettingMark(TextSettings.FONT_WEIGHT);
|
|
483
481
|
|
|
484
|
-
expect(selectionRef.value).
|
|
482
|
+
expect(selectionRef.value).toBe('400');
|
|
485
483
|
});
|
|
486
484
|
|
|
487
485
|
test('should get default of common setting mark', () => {
|
|
@@ -494,7 +492,7 @@ describe('get setting mark', () => {
|
|
|
494
492
|
editor.commands.selectAll();
|
|
495
493
|
const selectionRef = editor.commands.getCommonSettingMark(TextSettings.FONT_WEIGHT, ref('400'));
|
|
496
494
|
|
|
497
|
-
expect(selectionRef.value).
|
|
495
|
+
expect(selectionRef.value).toBe('400');
|
|
498
496
|
});
|
|
499
497
|
|
|
500
498
|
test('should get device setting mark', () => {
|
|
@@ -510,7 +508,7 @@ describe('get setting mark', () => {
|
|
|
510
508
|
editor.commands.selectAll();
|
|
511
509
|
const selectionRef = editor.commands.getDeviceSettingMark(TextSettings.FONT_SIZE);
|
|
512
510
|
|
|
513
|
-
expect(selectionRef.value).
|
|
511
|
+
expect(selectionRef.value).toBe('23');
|
|
514
512
|
});
|
|
515
513
|
|
|
516
514
|
test('should get default of device setting mark', () => {
|
|
@@ -524,7 +522,7 @@ describe('get setting mark', () => {
|
|
|
524
522
|
editor.commands.selectAll();
|
|
525
523
|
const selectionRef = editor.commands.getDeviceSettingMark(TextSettings.FONT_SIZE, ref('23'));
|
|
526
524
|
|
|
527
|
-
expect(selectionRef.value).
|
|
525
|
+
expect(selectionRef.value).toBe('23');
|
|
528
526
|
});
|
|
529
527
|
|
|
530
528
|
test('should inherit device setting mark', () => {
|
|
@@ -545,7 +543,7 @@ describe('get setting mark', () => {
|
|
|
545
543
|
editor.commands.selectAll();
|
|
546
544
|
const selectionRef = editor.commands.getDeviceSettingMark(TextSettings.FONT_SIZE);
|
|
547
545
|
|
|
548
|
-
expect(selectionRef.value).
|
|
546
|
+
expect(selectionRef.value).toBe('23');
|
|
549
547
|
});
|
|
550
548
|
});
|
|
551
549
|
|
|
@@ -3,10 +3,10 @@ import { ProseMirrorPlugin } from './ProseMirrorPlugin';
|
|
|
3
3
|
|
|
4
4
|
export class PlaceholderPlugin extends ProseMirrorPlugin {
|
|
5
5
|
buildProps() {
|
|
6
|
-
return { decorations: this
|
|
6
|
+
return { decorations: this._buildDecorations.bind(this) };
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
_buildDecorations({ doc }) {
|
|
10
10
|
const decorations = [];
|
|
11
11
|
|
|
12
12
|
if (!this.editor.isEditable) return null;
|
|
@@ -2,7 +2,6 @@ import { Node, wrappingInputRule } from '@tiptap/vue-2';
|
|
|
2
2
|
import { computed, unref } from 'vue';
|
|
3
3
|
import { copyMark, createCommand } from '../../utils';
|
|
4
4
|
import { ListTypes, MarkGroups, NodeTypes, TextSettings } from '../../enums';
|
|
5
|
-
import { AddNodeMarkStep, RemoveNodeMarkStep } from '../core/steps';
|
|
6
5
|
import { ListItem } from './ListItem';
|
|
7
6
|
|
|
8
7
|
export const List = Node.create({
|
|
@@ -122,13 +121,13 @@ export const List = Node.create({
|
|
|
122
121
|
node.forEach((child) => {
|
|
123
122
|
for (const childMark of child.marks) {
|
|
124
123
|
if (childMark.isInSet(bubbled)) {
|
|
125
|
-
tr.
|
|
124
|
+
tr.removeNodeMark(position + 1, childMark);
|
|
126
125
|
continue;
|
|
127
126
|
}
|
|
128
127
|
|
|
129
128
|
if (canBubbleMark(node, childMark)) {
|
|
130
|
-
tr.
|
|
131
|
-
tr.
|
|
129
|
+
tr.removeNodeMark(position + 1, childMark);
|
|
130
|
+
tr.addNodeMark(position, copyMark(childMark));
|
|
132
131
|
bubbled.push(childMark);
|
|
133
132
|
}
|
|
134
133
|
}
|
|
@@ -152,7 +151,7 @@ export const List = Node.create({
|
|
|
152
151
|
});
|
|
153
152
|
|
|
154
153
|
for (const mark of addingMarks) {
|
|
155
|
-
tr.
|
|
154
|
+
tr.addNodeMark(position, copyMark(mark));
|
|
156
155
|
}
|
|
157
156
|
|
|
158
157
|
return false;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import Base from '@tiptap/extension-list-item';
|
|
2
2
|
import { MarkGroups, NodeTypes } from '../../enums';
|
|
3
3
|
import { copyMark, createCommand } from '../../utils';
|
|
4
|
-
import { AddNodeMarkStep } from '../core/steps';
|
|
5
4
|
|
|
6
5
|
export const ListItem = Base.extend({
|
|
7
6
|
name: NodeTypes.LIST_ITEM,
|
|
@@ -22,7 +21,7 @@ export const ListItem = Base.extend({
|
|
|
22
21
|
const position = getItemPosition(tr);
|
|
23
22
|
|
|
24
23
|
for (const mark of initialNode.marks) {
|
|
25
|
-
tr.
|
|
24
|
+
tr.addNodeMark(position, copyMark(mark));
|
|
26
25
|
}
|
|
27
26
|
|
|
28
27
|
return true;
|
package/lib/models/Font.js
CHANGED
|
@@ -3,10 +3,10 @@ export class Font {
|
|
|
3
3
|
this.name = name;
|
|
4
4
|
this.category = category;
|
|
5
5
|
this.styles = styles;
|
|
6
|
-
this.weights = this
|
|
6
|
+
this.weights = this._getWeights();
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
_getWeights() {
|
|
10
10
|
const weights = this.styles.map((style) => style.replace('i', ''));
|
|
11
11
|
|
|
12
12
|
return Array.from(new Set(weights));
|
|
@@ -19,21 +19,21 @@ describe('weights', () => {
|
|
|
19
19
|
const font = new Font({ styles: ['400', '700'] });
|
|
20
20
|
const weight = font.findClosestWeight('500');
|
|
21
21
|
|
|
22
|
-
expect(weight).
|
|
22
|
+
expect(weight).toBe('400');
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
test('should find closest font weight from upper side', () => {
|
|
26
26
|
const font = new Font({ styles: ['400', '700'] });
|
|
27
27
|
const weight = font.findClosestWeight('900');
|
|
28
28
|
|
|
29
|
-
expect(weight).
|
|
29
|
+
expect(weight).toBe('700');
|
|
30
30
|
});
|
|
31
31
|
|
|
32
32
|
test('should find closest font weight from lower side', () => {
|
|
33
33
|
const font = new Font({ styles: ['400', '700'] });
|
|
34
34
|
const weight = font.findClosestWeight('200');
|
|
35
35
|
|
|
36
|
-
expect(weight).
|
|
36
|
+
expect(weight).toBe('400');
|
|
37
37
|
});
|
|
38
38
|
});
|
|
39
39
|
|
|
@@ -56,12 +56,6 @@ describe('style checks', () => {
|
|
|
56
56
|
expect(font.isItalicSupported('400')).toBe(true);
|
|
57
57
|
});
|
|
58
58
|
|
|
59
|
-
test('should detect if weight not supported', () => {
|
|
60
|
-
const font = new Font({ styles: ['400', '700'] });
|
|
61
|
-
|
|
62
|
-
expect(font.isItalicSupported('700')).toBe(false);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
59
|
test('should detect italic only weight', () => {
|
|
66
60
|
const font = new Font({ styles: ['400i'] });
|
|
67
61
|
|
|
@@ -31,21 +31,21 @@ export class ContentSerializer {
|
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
_schema;
|
|
35
|
+
_domParser;
|
|
36
|
+
_nodeDomParser;
|
|
37
37
|
|
|
38
38
|
constructor({ schema, domParser, nodeDomParser }) {
|
|
39
|
-
this
|
|
40
|
-
this
|
|
41
|
-
this
|
|
39
|
+
this._schema = schema;
|
|
40
|
+
this._domParser = domParser;
|
|
41
|
+
this._nodeDomParser = nodeDomParser;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
toJSON(html) {
|
|
45
|
-
const normalizer = ContentNormalizer.build(html, { parser: this
|
|
45
|
+
const normalizer = ContentNormalizer.build(html, { parser: this._nodeDomParser });
|
|
46
46
|
|
|
47
47
|
normalizer.normalizeHTML();
|
|
48
48
|
|
|
49
|
-
return this
|
|
49
|
+
return this._domParser.parse(normalizer.dom.body).toJSON();
|
|
50
50
|
}
|
|
51
51
|
}
|
|
@@ -5,13 +5,13 @@ export class HtmlToJsonParser {
|
|
|
5
5
|
return new HtmlToJsonParser(ContentSerializer.build({ config }));
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
_contentSerializer;
|
|
9
9
|
|
|
10
10
|
constructor(contentSerializer) {
|
|
11
|
-
this
|
|
11
|
+
this._contentSerializer = contentSerializer;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
toJSON(html) {
|
|
15
|
-
return this
|
|
15
|
+
return this._contentSerializer.toJSON(html);
|
|
16
16
|
}
|
|
17
17
|
}
|