@zipify/wysiwyg 2.4.3 → 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.
@@ -59,12 +59,9 @@ export const Alignment = Extension.create({
59
59
  }),
60
60
 
61
61
  applyAlignment: createCommand(({ commands }, value) => {
62
- // const device = unref(commands.getDevice());
63
- //
64
- // commands.setBlockAttributes(this.name, { [device]: value }, DEFAULTS);
62
+ const device = unref(commands.getDevice());
65
63
 
66
- // Temporary until release BUILDER_MODES
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
- // const device = unref(commands.getDevice());
38
+ const device = unref(commands.getDevice());
38
39
 
39
- // commands.applyMark(this.name, { [device]: value });
40
+ commands.applyMark(this.name, { [device]: value }, {
41
+ isAppliedToParent: (parentMark, mark) => {
42
+ if (parentMark.type.name !== mark.type.name) return false;
40
43
 
41
- // Temporary until release BUILDER_MODES
42
- commands.applyMark(this.name, { desktop: value, tablet: value, mobile: null });
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
- // const device = unref(commands.getDevice());
79
- //
80
- // commands.setBlockAttributes(this.name, { [device]: value }, DEFAULTS);
75
+ const device = unref(commands.getDevice());
81
76
 
82
- // Temporary until release BUILDER_MODES
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
  }
@@ -7,8 +7,8 @@ Object {
7
7
  "attrs": Object {
8
8
  "alignment": Object {
9
9
  "desktop": "right",
10
- "mobile": "right",
11
- "tablet": "right",
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": "right",
55
- "tablet": "right",
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": "16",
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": "13",
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": "15",
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": "5",
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": "20",
126
+ "tablet": null,
127
127
  },
128
128
  "type": "font_size",
129
129
  },
@@ -8,7 +8,7 @@ Object {
8
8
  "line_height": Object {
9
9
  "desktop": "1.41",
10
10
  "mobile": null,
11
- "tablet": "1.41",
11
+ "tablet": null,
12
12
  },
13
13
  },
14
14
  "content": Array [
@@ -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 commands._removeNodeMark({ tr, node, position, mark: markType });
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) {
@@ -31,3 +31,5 @@ export const buildCoreExtensions = () => [
31
31
  SelectionProcessor,
32
32
  ProseMirrorPlugins
33
33
  ];
34
+
35
+ export * from './steps';
@@ -136,9 +136,6 @@ export class NodeFactory {
136
136
  * @returns {{tablet, desktop, mobile}}
137
137
  */
138
138
  static populateAllDevices(value) {
139
- // return { mobile: value, tablet: value, desktop: value };
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
  }
@@ -320,7 +320,7 @@ Object {
320
320
  exports[`build node should populate value to all devices 1`] = `
321
321
  Object {
322
322
  "desktop": "18",
323
- "mobile": null,
323
+ "mobile": "18",
324
324
  "tablet": "18",
325
325
  }
326
326
  `;
@@ -1,8 +1,8 @@
1
1
  import { isMarkAppliedToParent } from '../isMarkAppliedToParent';
2
2
 
3
3
  const createMark = (attrs = {}) => ({
4
- isInSet(set) {
5
- return set.includes(this);
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
- export function isMarkAppliedToParent(doc, position, checkingMark) {
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
- if (checkingMark.isInSet(step.marks)) return true;
8
+
9
+ for (const mark of step.marks) {
10
+ if (comparator(mark, checkingMark)) return true;
11
+ }
7
12
  }
8
13
 
9
14
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zipify/wysiwyg",
3
- "version": "2.4.3",
3
+ "version": "2.5.0",
4
4
  "description": "Zipify modification of TipTap text editor",
5
5
  "main": "dist/wysiwyg.mjs",
6
6
  "bin": {