@zipify/wysiwyg 2.4.2-0 → 2.5.0
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/dist/cli.js +2 -2
- package/dist/wysiwyg.mjs +2755 -2714
- package/example/fonts.js +0 -7
- package/lib/extensions/Alignment.js +2 -5
- package/lib/extensions/FontSize.js +24 -6
- package/lib/extensions/FontStyle.js +8 -3
- package/lib/extensions/LineHeight.js +2 -8
- package/lib/extensions/__tests__/FontFamily.test.js +3 -1
- package/lib/extensions/__tests__/__snapshots__/Alignment.test.js.snap +4 -4
- package/lib/extensions/__tests__/__snapshots__/FontSize.test.js.snap +5 -5
- package/lib/extensions/__tests__/__snapshots__/LineHeight.test.js.snap +1 -1
- package/lib/extensions/core/NodeProcessor.js +11 -3
- package/lib/extensions/core/index.js +2 -0
- package/lib/models/Font.js +10 -3
- package/lib/models/__tests__/Font.test.js +19 -1
- package/lib/services/NodeFactory.js +1 -4
- package/lib/services/__tests__/__snapshots__/NodeFactory.test.js.snap +1 -1
- package/lib/utils/__tests__/isMarkAppliedToParent.test.js +5 -5
- package/lib/utils/isMarkAppliedToParent.js +7 -2
- package/package.json +1 -1
package/example/fonts.js
CHANGED
|
@@ -59,12 +59,9 @@ export const Alignment = Extension.create({
|
|
|
59
59
|
}),
|
|
60
60
|
|
|
61
61
|
applyAlignment: createCommand(({ commands }, value) => {
|
|
62
|
-
|
|
63
|
-
//
|
|
64
|
-
// commands.setBlockAttributes(this.name, { [device]: value }, DEFAULTS);
|
|
62
|
+
const device = unref(commands.getDevice());
|
|
65
63
|
|
|
66
|
-
|
|
67
|
-
commands.setBlockAttributes(this.name, { desktop: value, tablet: value, mobile: value });
|
|
64
|
+
commands.setBlockAttributes(this.name, { [device]: value }, DEFAULTS);
|
|
68
65
|
}),
|
|
69
66
|
|
|
70
67
|
removeAlignment: createCommand(({ commands }) => commands.removeBlockAttributes(this.name)),
|
|
@@ -2,6 +2,7 @@ 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';
|
|
5
6
|
|
|
6
7
|
export const FontSize = Mark.create({
|
|
7
8
|
name: TextSettings.FONT_SIZE,
|
|
@@ -34,12 +35,31 @@ export const FontSize = Mark.create({
|
|
|
34
35
|
}),
|
|
35
36
|
|
|
36
37
|
applyFontSize: createCommand(({ commands }, value) => {
|
|
37
|
-
|
|
38
|
+
const device = unref(commands.getDevice());
|
|
38
39
|
|
|
39
|
-
|
|
40
|
+
commands.applyMark(this.name, { [device]: value }, {
|
|
41
|
+
isAppliedToParent: (parentMark, mark) => {
|
|
42
|
+
if (parentMark.type.name !== mark.type.name) return false;
|
|
40
43
|
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
return parentMark.attrs[device] === mark.attrs[device];
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
onAppliedToParent: ({ tr, node, position, mark }) => {
|
|
48
|
+
const attrs = { ...mark.attrs, [device]: null };
|
|
49
|
+
const canRemove = !Object.values(attrs).some((value) => !!value);
|
|
50
|
+
|
|
51
|
+
if (canRemove) return false;
|
|
52
|
+
|
|
53
|
+
const updated = mark.type.create(attrs);
|
|
54
|
+
|
|
55
|
+
if (node.isText) {
|
|
56
|
+
tr.addMark(position, position + node.nodeSize, updated);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
tr.step(new AddNodeMarkStep(position, updated));
|
|
61
|
+
}
|
|
62
|
+
});
|
|
43
63
|
}),
|
|
44
64
|
|
|
45
65
|
increaseFontSize: createCommand(({ commands }) => {
|
|
@@ -89,8 +109,6 @@ export const FontSize = Mark.create({
|
|
|
89
109
|
getAttrs: (input) => {
|
|
90
110
|
const value = parseSize(input);
|
|
91
111
|
|
|
92
|
-
// return { desktop: value, tablet: value, mobile: value };
|
|
93
|
-
// Temporary until release BUILDER_MODES
|
|
94
112
|
return { desktop: value, tablet: value, mobile: null };
|
|
95
113
|
}
|
|
96
114
|
}
|
|
@@ -21,10 +21,15 @@ export const FontStyle = Mark.create({
|
|
|
21
21
|
}),
|
|
22
22
|
|
|
23
23
|
isItalicAvailable: createCommand(({ commands }) => {
|
|
24
|
-
const
|
|
25
|
-
const
|
|
24
|
+
const fontRef = commands.getFont();
|
|
25
|
+
const fontWeightRef = commands.getFontWeight();
|
|
26
26
|
|
|
27
|
-
return computed(() =>
|
|
27
|
+
return computed(() => {
|
|
28
|
+
const font = unref(fontRef);
|
|
29
|
+
const weight = unref(fontWeightRef);
|
|
30
|
+
|
|
31
|
+
return font.isItalicSupported(weight) && !font.isWeightItalicOnly(weight);
|
|
32
|
+
});
|
|
28
33
|
}),
|
|
29
34
|
|
|
30
35
|
getDefaultFontStyle: createCommand(({ commands }) => {
|
|
@@ -36,9 +36,6 @@ export const LineHeight = Extension.create({
|
|
|
36
36
|
const wrapperEl = unref(this.options.wrapperRef);
|
|
37
37
|
const converted = convertLineHeight(value, element, wrapperEl);
|
|
38
38
|
|
|
39
|
-
// return { desktop: converted, tablet: converted, mobile: converted };
|
|
40
|
-
|
|
41
|
-
// Temporary until release BUILDER_MODES
|
|
42
39
|
return { desktop: converted, tablet: converted, mobile: null };
|
|
43
40
|
},
|
|
44
41
|
|
|
@@ -75,12 +72,9 @@ export const LineHeight = Extension.create({
|
|
|
75
72
|
}),
|
|
76
73
|
|
|
77
74
|
applyLineHeight: createCommand(({ commands }, value) => {
|
|
78
|
-
|
|
79
|
-
//
|
|
80
|
-
// commands.setBlockAttributes(this.name, { [device]: value }, DEFAULTS);
|
|
75
|
+
const device = unref(commands.getDevice());
|
|
81
76
|
|
|
82
|
-
|
|
83
|
-
commands.setBlockAttributes(this.name, { desktop: value, tablet: value, mobile: null }, DEFAULTS);
|
|
77
|
+
commands.setBlockAttributes(this.name, { [device]: value }, DEFAULTS);
|
|
84
78
|
})
|
|
85
79
|
};
|
|
86
80
|
}
|
|
@@ -88,7 +88,9 @@ describe('get font family', () => {
|
|
|
88
88
|
content: createContent(NodeFactory.text('hello world'))
|
|
89
89
|
});
|
|
90
90
|
|
|
91
|
-
expect(editor.commands.findFontByName('Bungee')).toEqual(
|
|
91
|
+
expect(editor.commands.findFontByName('Bungee')).toEqual(
|
|
92
|
+
expect.objectContaining({ name: 'Bungee' })
|
|
93
|
+
);
|
|
92
94
|
});
|
|
93
95
|
|
|
94
96
|
test('should get font model from selection', () => {
|
|
@@ -7,8 +7,8 @@ Object {
|
|
|
7
7
|
"attrs": Object {
|
|
8
8
|
"alignment": Object {
|
|
9
9
|
"desktop": "right",
|
|
10
|
-
"mobile":
|
|
11
|
-
"tablet":
|
|
10
|
+
"mobile": null,
|
|
11
|
+
"tablet": null,
|
|
12
12
|
},
|
|
13
13
|
},
|
|
14
14
|
"content": Array [
|
|
@@ -51,8 +51,8 @@ Object {
|
|
|
51
51
|
"attrs": Object {
|
|
52
52
|
"alignment": Object {
|
|
53
53
|
"desktop": "right",
|
|
54
|
-
"mobile":
|
|
55
|
-
"tablet":
|
|
54
|
+
"mobile": null,
|
|
55
|
+
"tablet": null,
|
|
56
56
|
},
|
|
57
57
|
},
|
|
58
58
|
"content": Array [
|
|
@@ -15,7 +15,7 @@ Object {
|
|
|
15
15
|
"attrs": Object {
|
|
16
16
|
"desktop": "16",
|
|
17
17
|
"mobile": null,
|
|
18
|
-
"tablet":
|
|
18
|
+
"tablet": null,
|
|
19
19
|
},
|
|
20
20
|
"type": "font_size",
|
|
21
21
|
},
|
|
@@ -42,7 +42,7 @@ Object {
|
|
|
42
42
|
"attrs": Object {
|
|
43
43
|
"desktop": "13",
|
|
44
44
|
"mobile": null,
|
|
45
|
-
"tablet":
|
|
45
|
+
"tablet": null,
|
|
46
46
|
},
|
|
47
47
|
"type": "font_size",
|
|
48
48
|
},
|
|
@@ -69,7 +69,7 @@ Object {
|
|
|
69
69
|
"attrs": Object {
|
|
70
70
|
"desktop": "15",
|
|
71
71
|
"mobile": null,
|
|
72
|
-
"tablet":
|
|
72
|
+
"tablet": null,
|
|
73
73
|
},
|
|
74
74
|
"type": "font_size",
|
|
75
75
|
},
|
|
@@ -96,7 +96,7 @@ Object {
|
|
|
96
96
|
"attrs": Object {
|
|
97
97
|
"desktop": "5",
|
|
98
98
|
"mobile": null,
|
|
99
|
-
"tablet":
|
|
99
|
+
"tablet": null,
|
|
100
100
|
},
|
|
101
101
|
"type": "font_size",
|
|
102
102
|
},
|
|
@@ -123,7 +123,7 @@ Object {
|
|
|
123
123
|
"attrs": Object {
|
|
124
124
|
"desktop": "20",
|
|
125
125
|
"mobile": null,
|
|
126
|
-
"tablet":
|
|
126
|
+
"tablet": null,
|
|
127
127
|
},
|
|
128
128
|
"type": "font_size",
|
|
129
129
|
},
|
|
@@ -43,7 +43,7 @@ export const NodeProcessor = Extension.create({
|
|
|
43
43
|
}
|
|
44
44
|
}),
|
|
45
45
|
|
|
46
|
-
applyMark: createCommand(({ state, commands }, name, value) => {
|
|
46
|
+
applyMark: createCommand(({ state, commands }, name, value, customizer = {}) => {
|
|
47
47
|
const { tr, doc, schema } = state;
|
|
48
48
|
const { $from, $to } = tr.selection;
|
|
49
49
|
const markType = getMarkType(name, schema);
|
|
@@ -56,6 +56,14 @@ export const NodeProcessor = Extension.create({
|
|
|
56
56
|
|
|
57
57
|
if ($from.pos === $to.pos) return;
|
|
58
58
|
|
|
59
|
+
const onAppliedToParent = (context) => {
|
|
60
|
+
if (!customizer.onAppliedToParent || customizer.onAppliedToParent(context) === false) {
|
|
61
|
+
const { tr, node, position, mark } = context;
|
|
62
|
+
|
|
63
|
+
commands._removeNodeMark({ tr, node, position, mark: mark.type });
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
59
67
|
doc.nodesBetween($from.pos, $to.pos, (node, position) => {
|
|
60
68
|
if (node.type.name === NodeTypes.LIST) return;
|
|
61
69
|
|
|
@@ -63,8 +71,8 @@ export const NodeProcessor = Extension.create({
|
|
|
63
71
|
const applyingMark = markType.create({ ...(initialMark?.attrs || {}), ...value });
|
|
64
72
|
const textPosition = resolveTextPosition($from, $to, node, position);
|
|
65
73
|
|
|
66
|
-
if (isMarkAppliedToParent(tr.doc, position, applyingMark)) {
|
|
67
|
-
return
|
|
74
|
+
if (isMarkAppliedToParent(tr.doc, position, applyingMark, customizer.isAppliedToParent)) {
|
|
75
|
+
return onAppliedToParent({ tr, node, position, mark: applyingMark });
|
|
68
76
|
}
|
|
69
77
|
|
|
70
78
|
if (node.isText) {
|
package/lib/models/Font.js
CHANGED
|
@@ -3,20 +3,27 @@ export class Font {
|
|
|
3
3
|
this.name = name;
|
|
4
4
|
this.category = category;
|
|
5
5
|
this.styles = styles;
|
|
6
|
+
this.weights = this.#getWeights();
|
|
6
7
|
}
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
#getWeights() {
|
|
10
|
+
const weights = this.styles.map((style) => style.replace('i', ''));
|
|
11
|
+
|
|
12
|
+
return Array.from(new Set(weights));
|
|
10
13
|
}
|
|
11
14
|
|
|
12
15
|
isWeightSupported(weight) {
|
|
13
|
-
return this.
|
|
16
|
+
return this.weights.includes(weight);
|
|
14
17
|
}
|
|
15
18
|
|
|
16
19
|
isItalicSupported(weight) {
|
|
17
20
|
return this.styles.includes(`${weight}i`);
|
|
18
21
|
}
|
|
19
22
|
|
|
23
|
+
isWeightItalicOnly(weight) {
|
|
24
|
+
return this.isItalicSupported(weight) && !this.styles.includes(weight);
|
|
25
|
+
}
|
|
26
|
+
|
|
20
27
|
findClosestWeight(searchedWeight) {
|
|
21
28
|
const weights = this.weights.map((weight) => parseInt(weight));
|
|
22
29
|
|
|
@@ -9,6 +9,12 @@ describe('weights', () => {
|
|
|
9
9
|
expect(font.weights).toEqual(['400', '700']);
|
|
10
10
|
});
|
|
11
11
|
|
|
12
|
+
test('should display italic only style', () => {
|
|
13
|
+
const font = new Font({ styles: ['700i'] });
|
|
14
|
+
|
|
15
|
+
expect(font.weights).toEqual(['700']);
|
|
16
|
+
});
|
|
17
|
+
|
|
12
18
|
test('should find closest font weight', () => {
|
|
13
19
|
const font = new Font({ styles: ['400', '700'] });
|
|
14
20
|
const weight = font.findClosestWeight('500');
|
|
@@ -41,7 +47,7 @@ describe('style checks', () => {
|
|
|
41
47
|
test('should detect if weight not supported', () => {
|
|
42
48
|
const font = new Font({ styles: ['400', '700i'] });
|
|
43
49
|
|
|
44
|
-
expect(font.isWeightSupported('
|
|
50
|
+
expect(font.isWeightSupported('800')).toBe(false);
|
|
45
51
|
});
|
|
46
52
|
|
|
47
53
|
test('should detect if italic supported', () => {
|
|
@@ -55,4 +61,16 @@ describe('style checks', () => {
|
|
|
55
61
|
|
|
56
62
|
expect(font.isItalicSupported('700')).toBe(false);
|
|
57
63
|
});
|
|
64
|
+
|
|
65
|
+
test('should detect italic only weight', () => {
|
|
66
|
+
const font = new Font({ styles: ['400i'] });
|
|
67
|
+
|
|
68
|
+
expect(font.isItalicSupported('400')).toBe(true);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('should detect non italic only weight', () => {
|
|
72
|
+
const font = new Font({ styles: ['400i', '400'] });
|
|
73
|
+
|
|
74
|
+
expect(font.isItalicSupported('400')).toBe(true);
|
|
75
|
+
});
|
|
58
76
|
});
|
|
@@ -136,9 +136,6 @@ export class NodeFactory {
|
|
|
136
136
|
* @returns {{tablet, desktop, mobile}}
|
|
137
137
|
*/
|
|
138
138
|
static populateAllDevices(value) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
// Temporary until release BUILDER_MODES
|
|
142
|
-
return { mobile: null, tablet: value, desktop: value };
|
|
139
|
+
return { mobile: value, tablet: value, desktop: value };
|
|
143
140
|
}
|
|
144
141
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { isMarkAppliedToParent } from '../isMarkAppliedToParent';
|
|
2
2
|
|
|
3
3
|
const createMark = (attrs = {}) => ({
|
|
4
|
-
|
|
5
|
-
return
|
|
4
|
+
eq(another) {
|
|
5
|
+
return JSON.stringify(this) === JSON.stringify(another);
|
|
6
6
|
},
|
|
7
7
|
...attrs
|
|
8
8
|
});
|
|
@@ -34,15 +34,15 @@ describe('is mark applied to parent', () => {
|
|
|
34
34
|
});
|
|
35
35
|
|
|
36
36
|
test('should return false if not applied to parent', () => {
|
|
37
|
-
const checkingMark = createMark();
|
|
37
|
+
const checkingMark = createMark({ attrs: { value: '400' } });
|
|
38
38
|
const doc = createNode();
|
|
39
39
|
|
|
40
40
|
doc.resolve.mockReturnValue({
|
|
41
41
|
path: [
|
|
42
|
-
createNode({ marks: [createMark()] }),
|
|
42
|
+
createNode({ marks: [createMark({ attrs: { value: '700' } })] }),
|
|
43
43
|
0,
|
|
44
44
|
0,
|
|
45
|
-
createNode({ marks: [createMark()] }),
|
|
45
|
+
createNode({ marks: [createMark({ attrs: { value: '700' } })] }),
|
|
46
46
|
0,
|
|
47
47
|
1
|
|
48
48
|
]
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
const DEFAULT_COMPARATOR = (parentMark, mark) => parentMark.eq(mark);
|
|
2
|
+
|
|
3
|
+
export function isMarkAppliedToParent(doc, position, checkingMark, comparator = DEFAULT_COMPARATOR) {
|
|
2
4
|
const steps = doc.resolve(position).path.reverse();
|
|
3
5
|
|
|
4
6
|
for (const step of steps) {
|
|
5
7
|
if (typeof step === 'number') continue;
|
|
6
|
-
|
|
8
|
+
|
|
9
|
+
for (const mark of step.marks) {
|
|
10
|
+
if (comparator(mark, checkingMark)) return true;
|
|
11
|
+
}
|
|
7
12
|
}
|
|
8
13
|
|
|
9
14
|
return false;
|