@zipify/wysiwyg 2.4.3 → 2.4.4-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.css +2 -2
- package/dist/wysiwyg.mjs +2729 -2687
- package/lib/components/toolbar/controls/AlignmentDeviceControl.vue +15 -4
- package/lib/extensions/Alignment.js +2 -5
- package/lib/extensions/FontSize.js +24 -6
- package/lib/extensions/LineHeight.js +2 -8
- package/lib/extensions/Link.js +1 -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 +17 -3
- package/lib/extensions/core/index.js +2 -0
- 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
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
@click="toggler.open"
|
|
8
8
|
v-tooltip="'Alignment'"
|
|
9
9
|
>
|
|
10
|
-
<Icon :name="
|
|
10
|
+
<Icon :name="icon" size="28px" auto-color />
|
|
11
11
|
</Button>
|
|
12
12
|
|
|
13
13
|
<Modal class="zw-alignment-control__modal" ref="modalRef" :toggler="toggler">
|
|
@@ -17,10 +17,11 @@
|
|
|
17
17
|
</template>
|
|
18
18
|
|
|
19
19
|
<script>
|
|
20
|
-
import { inject, ref } from 'vue';
|
|
20
|
+
import { computed, inject, ref, unref } from 'vue';
|
|
21
21
|
import { InjectionTokens } from '../../../injectionTokens';
|
|
22
|
-
import { Button, Icon, Modal, useModalToggler } from '../../base';
|
|
23
22
|
import { tooltip } from '../../../directives';
|
|
23
|
+
import { Alignments } from '../../../enums';
|
|
24
|
+
import { Button, Icon, Modal, useModalToggler } from '../../base';
|
|
24
25
|
import AlignmentControl from './AlignmentControl';
|
|
25
26
|
|
|
26
27
|
export default {
|
|
@@ -43,12 +44,22 @@ export default {
|
|
|
43
44
|
const wrapperRef = ref(null);
|
|
44
45
|
const modalRef = ref(null);
|
|
45
46
|
|
|
46
|
-
const toggler = useModalToggler({
|
|
47
|
+
const toggler = useModalToggler({
|
|
48
|
+
wrapperRef,
|
|
49
|
+
modalRef
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const icon = computed(() => {
|
|
53
|
+
const name = unref(currentValue) || Alignments.LEFT;
|
|
54
|
+
|
|
55
|
+
return `alignment-${name}`;
|
|
56
|
+
});
|
|
47
57
|
|
|
48
58
|
return {
|
|
49
59
|
wrapperRef,
|
|
50
60
|
modalRef,
|
|
51
61
|
currentValue,
|
|
62
|
+
icon,
|
|
52
63
|
toggler,
|
|
53
64
|
isOpened: toggler.isOpened
|
|
54
65
|
};
|
|
@@ -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
|
}
|
|
@@ -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
|
}
|
package/lib/extensions/Link.js
CHANGED
|
@@ -68,7 +68,7 @@ export const Link = Base.extend({
|
|
|
68
68
|
.run();
|
|
69
69
|
}),
|
|
70
70
|
|
|
71
|
-
isLink: createCommand(({
|
|
71
|
+
isLink: createCommand(({ commands }) => commands.hasMark(this.name)),
|
|
72
72
|
getLinkPreset: createCommand(() => computed(() => this.options.preset))
|
|
73
73
|
};
|
|
74
74
|
},
|
|
@@ -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) {
|
|
@@ -102,6 +110,12 @@ export const NodeProcessor = Extension.create({
|
|
|
102
110
|
return computed(() => unref(marksRef)[0] ?? null);
|
|
103
111
|
}),
|
|
104
112
|
|
|
113
|
+
hasMark: createCommand(({ commands }, name) => {
|
|
114
|
+
const mark = commands.getMark(name);
|
|
115
|
+
|
|
116
|
+
return computed(() => !!unref(mark));
|
|
117
|
+
}),
|
|
118
|
+
|
|
105
119
|
getCommonSettingMark: createCommand(({ commands }, name, defaultRef) => {
|
|
106
120
|
const selectionRef = commands.getMark(name);
|
|
107
121
|
|
|
@@ -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;
|