@zipify/wysiwyg 3.0.0 → 3.0.2-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/config/build/cli.config.js +1 -1
- package/config/build/lib.config.js +1 -1
- package/dist/cli.js +3 -3
- package/dist/wysiwyg.css +25 -22
- package/dist/wysiwyg.mjs +919 -886
- package/example/ExampleApp.vue +1 -1
- package/example/presets.js +7 -7
- package/lib/__tests__/utils/buildTestExtensions.js +24 -2
- package/lib/components/base/dropdown/DropdownActivator.vue +4 -0
- package/lib/components/toolbar/controls/StylePresetControl.vue +1 -1
- package/lib/{entry-cli.js → entryCli.js} +0 -0
- package/lib/{entry-lib.js → entryLib.js} +0 -0
- package/lib/extensions/Alignment.js +6 -6
- package/lib/extensions/StylePreset.js +8 -46
- package/lib/extensions/__tests__/Alignment.test.js +1 -1
- package/lib/extensions/__tests__/StylePreset.test.js +90 -119
- package/lib/extensions/__tests__/__snapshots__/Alignment.test.js.snap +2 -2
- package/lib/extensions/__tests__/__snapshots__/StylePreset.test.js.snap +0 -2
- package/lib/extensions/core/NodeProcessor.js +6 -2
- package/lib/extensions/index.js +7 -3
- package/lib/extensions/list/__tests__/List.test.js +6 -1
- package/lib/services/ContentSerializer.js +1 -1
- package/lib/services/{ContextWidnow.js → ContextWindow.js} +0 -0
- package/lib/services/StylePresetRenderer.js +73 -0
- package/lib/services/__tests__/StylePresetRenderer.test.js +98 -0
- package/lib/services/__tests__/__snapshots__/StylePresetRenderer.test.js.snap +5 -0
- package/lib/services/index.js +2 -1
- package/lib/styles/content.css +10 -10
- package/package.json +6 -2
package/example/ExampleApp.vue
CHANGED
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
|
|
51
51
|
<script>
|
|
52
52
|
import { computed, onMounted, ref, unref } from 'vue';
|
|
53
|
-
import { Wysiwyg } from '../lib/
|
|
53
|
+
import { Wysiwyg } from '../lib/entryLib';
|
|
54
54
|
import { FONTS } from './fonts';
|
|
55
55
|
import { PRESETS, renderPresetVariable } from './presets';
|
|
56
56
|
import { PAGE_BLOCKS } from './pageBlocks';
|
package/example/presets.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export const PRESETS = [
|
|
2
2
|
{
|
|
3
3
|
'id': 'h1',
|
|
4
|
-
'name': '
|
|
4
|
+
'name': 'Heading 1',
|
|
5
5
|
'node': {
|
|
6
6
|
'type': 'heading',
|
|
7
7
|
'level': 1
|
|
@@ -31,7 +31,7 @@ export const PRESETS = [
|
|
|
31
31
|
},
|
|
32
32
|
{
|
|
33
33
|
'id': 'h2',
|
|
34
|
-
'name': '
|
|
34
|
+
'name': 'Heading 2',
|
|
35
35
|
'node': {
|
|
36
36
|
'type': 'heading',
|
|
37
37
|
'level': 2
|
|
@@ -61,7 +61,7 @@ export const PRESETS = [
|
|
|
61
61
|
},
|
|
62
62
|
{
|
|
63
63
|
'id': 'h3',
|
|
64
|
-
'name': '
|
|
64
|
+
'name': 'Sub-heading 1',
|
|
65
65
|
'node': {
|
|
66
66
|
'type': 'heading',
|
|
67
67
|
'level': 3
|
|
@@ -91,7 +91,7 @@ export const PRESETS = [
|
|
|
91
91
|
},
|
|
92
92
|
{
|
|
93
93
|
'id': 'h4',
|
|
94
|
-
'name': '
|
|
94
|
+
'name': 'Sub-heading 2',
|
|
95
95
|
'node': {
|
|
96
96
|
'type': 'heading',
|
|
97
97
|
'level': 4
|
|
@@ -148,7 +148,7 @@ export const PRESETS = [
|
|
|
148
148
|
},
|
|
149
149
|
{
|
|
150
150
|
'id': 'regular-1',
|
|
151
|
-
'name': '
|
|
151
|
+
'name': 'Body Copy 1',
|
|
152
152
|
'desktop': {
|
|
153
153
|
'alignment': null,
|
|
154
154
|
'line_height': '1.43',
|
|
@@ -174,7 +174,7 @@ export const PRESETS = [
|
|
|
174
174
|
},
|
|
175
175
|
{
|
|
176
176
|
'id': 'regular-2',
|
|
177
|
-
'name': '
|
|
177
|
+
'name': 'Body Copy 2',
|
|
178
178
|
'fallbackClass': 'zpa-regular2',
|
|
179
179
|
'desktop': {
|
|
180
180
|
'alignment': null,
|
|
@@ -201,7 +201,7 @@ export const PRESETS = [
|
|
|
201
201
|
},
|
|
202
202
|
{
|
|
203
203
|
'id': 'regular-3',
|
|
204
|
-
'name': '
|
|
204
|
+
'name': 'Body Copy 3',
|
|
205
205
|
'fallbackClass': 'zpa-regular3',
|
|
206
206
|
'desktop': {
|
|
207
207
|
'alignment': null,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Mark } from '@tiptap/vue-2';
|
|
2
2
|
import { buildCoreExtensions } from '../../extensions/core';
|
|
3
|
-
import { MarkGroups } from '../../enums';
|
|
3
|
+
import { MarkGroups, TextSettings } from '../../enums';
|
|
4
4
|
|
|
5
5
|
// each node allows using 'settings' group of marks,
|
|
6
6
|
// and it fails when there are no nodes with this group
|
|
@@ -10,6 +10,28 @@ const SettingMark = Mark.create({
|
|
|
10
10
|
renderHTML: () => []
|
|
11
11
|
});
|
|
12
12
|
|
|
13
|
+
// NodeProcessor requires link mark
|
|
14
|
+
const LinkMark = Mark.create({
|
|
15
|
+
name: TextSettings.LINK,
|
|
16
|
+
renderHTML: () => []
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const isMark = (extension) => extension && extension.type === 'mark';
|
|
20
|
+
|
|
13
21
|
export function buildTestExtensions({ include } = {}) {
|
|
14
|
-
|
|
22
|
+
const extensions = buildCoreExtensions().concat(include || []);
|
|
23
|
+
|
|
24
|
+
const isSettingPreset = extensions.some((extension) => {
|
|
25
|
+
return isMark(extension) && extension.config.group === MarkGroups.SETTINGS;
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
if (!isSettingPreset) extensions.push(SettingMark);
|
|
29
|
+
|
|
30
|
+
const isLinkPreset = extensions.some((extension) => {
|
|
31
|
+
return isMark(extension) && extension.name === TextSettings.LINK;
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
if (!isLinkPreset) extensions.push(LinkMark);
|
|
35
|
+
|
|
36
|
+
return extensions;
|
|
15
37
|
}
|
|
File without changes
|
|
File without changes
|
|
@@ -26,9 +26,9 @@ export const Alignment = Extension.create({
|
|
|
26
26
|
return { desktop: textAlign, tablet: textAlign, mobile: textAlign };
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
const mobile = style.getPropertyValue('--zw-
|
|
30
|
-
const tablet = style.getPropertyValue('--zw-
|
|
31
|
-
const desktop = style.getPropertyValue('--zw-
|
|
29
|
+
const mobile = style.getPropertyValue('--zw-alignment-mobile') || null;
|
|
30
|
+
const tablet = style.getPropertyValue('--zw-alignment-tablet') || null;
|
|
31
|
+
const desktop = style.getPropertyValue('--zw-alignment-desktop') || null;
|
|
32
32
|
|
|
33
33
|
if (!mobile && !tablet && !desktop) return null;
|
|
34
34
|
|
|
@@ -39,9 +39,9 @@ export const Alignment = Extension.create({
|
|
|
39
39
|
if (!attrs.alignment) return null;
|
|
40
40
|
|
|
41
41
|
return renderInlineSetting({
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
alignment_mobile: attrs.alignment.mobile,
|
|
43
|
+
alignment_tablet: attrs.alignment.tablet,
|
|
44
|
+
alignment_desktop: attrs.alignment.desktop
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
47
|
}
|
|
@@ -1,22 +1,12 @@
|
|
|
1
1
|
import { Extension } from '@tiptap/vue-2';
|
|
2
2
|
import { computed, toRef, unref } from 'vue';
|
|
3
3
|
import { createCommand } from '../utils';
|
|
4
|
-
import {
|
|
4
|
+
import { NodeTypes, TextSettings } from '../enums';
|
|
5
5
|
import { ContextWindow } from '../services';
|
|
6
6
|
|
|
7
|
-
function makePresetClass(base, preset) {
|
|
8
|
-
const baseClass = base.split(' ').map((part) => `.${part}`).join('');
|
|
9
|
-
|
|
10
|
-
return baseClass + preset.id;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
7
|
export const StylePreset = Extension.create({
|
|
14
8
|
name: TextSettings.STYLE_PRESET,
|
|
15
9
|
|
|
16
|
-
addStorage: () => ({
|
|
17
|
-
presetStyleEl: null
|
|
18
|
-
}),
|
|
19
|
-
|
|
20
10
|
addGlobalAttributes() {
|
|
21
11
|
return [
|
|
22
12
|
{
|
|
@@ -32,13 +22,13 @@ export const StylePreset = Extension.create({
|
|
|
32
22
|
if (element.parentElement.tagName === 'LI') return null;
|
|
33
23
|
|
|
34
24
|
for (const { id, node, fallbackClass } of presets) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
25
|
+
if (fallbackClass && element.classList.contains(fallbackClass)) {
|
|
26
|
+
return { id };
|
|
27
|
+
}
|
|
38
28
|
|
|
39
|
-
const
|
|
29
|
+
const presetSelector = this.options.styleRenderer.makePresetCssClass({ id });
|
|
40
30
|
|
|
41
|
-
if (element.matches(
|
|
31
|
+
if (element.matches(presetSelector)) return { id };
|
|
42
32
|
if (element.tagName === `H${node?.level}`) return { id };
|
|
43
33
|
}
|
|
44
34
|
|
|
@@ -49,7 +39,7 @@ export const StylePreset = Extension.create({
|
|
|
49
39
|
renderHTML: (attrs) => {
|
|
50
40
|
if (!attrs.preset) return null;
|
|
51
41
|
|
|
52
|
-
return { class: this.options.
|
|
42
|
+
return { class: this.options.styleRenderer.makePresetHtmlClass(attrs.preset) };
|
|
53
43
|
}
|
|
54
44
|
}
|
|
55
45
|
}
|
|
@@ -208,34 +198,6 @@ export const StylePreset = Extension.create({
|
|
|
208
198
|
},
|
|
209
199
|
|
|
210
200
|
onCreate() {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
if (existingStyleEl) {
|
|
214
|
-
this.storage.presetStyleEl = existingStyleEl;
|
|
215
|
-
return;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
this.storage.presetStyleEl = ContextWindow.document.createElement('style');
|
|
219
|
-
this.storage.presetStyleEl.dataset.zwStyles = '';
|
|
220
|
-
|
|
221
|
-
for (const preset of this.options.presets) {
|
|
222
|
-
const className = makePresetClass(this.options.baseClass, preset);
|
|
223
|
-
const css = [` ${className} {`];
|
|
224
|
-
|
|
225
|
-
for (const device of Devices.values) {
|
|
226
|
-
for (const setting of Object.keys(preset[device])) {
|
|
227
|
-
const variable = this.options.makeVariable({ device, preset, property: setting });
|
|
228
|
-
const property = setting.replace(/_/i, '-');
|
|
229
|
-
const prefix = device === Devices.COMMON ? 'preset' : `preset-${device}`;
|
|
230
|
-
|
|
231
|
-
css.push(`--zw-${prefix}-${property}: var(${variable}, inherit);`);
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
css.push('}');
|
|
236
|
-
this.storage.presetStyleEl.innerHTML += css.join(' ');
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
ContextWindow.head.append(this.storage.presetStyleEl);
|
|
201
|
+
this.options.styleRenderer.inject(ContextWindow.head, this.options.presets);
|
|
240
202
|
}
|
|
241
203
|
});
|
|
@@ -144,7 +144,7 @@ describe('parsing html', () => {
|
|
|
144
144
|
|
|
145
145
|
test('should get alignment from rendered view', () => {
|
|
146
146
|
const editor = createEditor({
|
|
147
|
-
content: '<p style="--zw-
|
|
147
|
+
content: '<p style="--zw-alignment-mobile:center;--zw-alignment-desktop:right">test</p>'
|
|
148
148
|
});
|
|
149
149
|
|
|
150
150
|
expect(editor.getJSON()).toMatchSnapshot();
|