@zipify/wysiwyg 2.1.0 → 2.2.0-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/wysiwyg.mjs CHANGED
@@ -22158,6 +22158,8 @@ const __vue2_script$p = {
22158
22158
  const pickerRef = ref(null);
22159
22159
  const api = usePickerApi({
22160
22160
  onChange: (color) => {
22161
+ if (!unref(api.isOpened))
22162
+ return false;
22161
22163
  emit("change", color);
22162
22164
  editor.chain().focus().restoreSelection().run();
22163
22165
  },
@@ -23158,7 +23160,7 @@ var render$d = function __render__32() {
23158
23160
  "options": _vm.$options.alignments
23159
23161
  },
23160
23162
  on: {
23161
- "change": _vm.apply
23163
+ "change": _vm.toggle
23162
23164
  },
23163
23165
  scopedSlots: _vm._u([{
23164
23166
  key: "option",
@@ -23238,16 +23240,20 @@ const __vue2_script$d = {
23238
23240
  },
23239
23241
  setup(_, { emit }) {
23240
23242
  const editor = inject(InjectionTokens$1.EDITOR);
23241
- const currentValue = editor.commands.getAlignment();
23243
+ const alignment = editor.commands.getAlignment();
23244
+ const currentValue = computed(() => {
23245
+ var _a;
23246
+ return (_a = unref(alignment)) != null ? _a : "none";
23247
+ });
23242
23248
  const isCustomized = editor.commands.isSettingCustomized(TextSettings.ALIGNMENT);
23243
- function apply2(value) {
23244
- editor.chain().focus().applyAlignment(value).run();
23249
+ function toggle(value) {
23250
+ editor.chain().focus().toggleAlignment(value).run();
23245
23251
  emit("applied");
23246
23252
  }
23247
23253
  return {
23248
23254
  currentValue,
23249
23255
  isCustomized,
23250
- apply: apply2
23256
+ toggle
23251
23257
  };
23252
23258
  }
23253
23259
  };
@@ -25249,9 +25255,15 @@ const Alignment = Extension.create({
25249
25255
  ],
25250
25256
  addCommands() {
25251
25257
  return {
25258
+ toggleAlignment: createCommand(({ commands: commands2 }, value) => {
25259
+ const currentValue = commands2.getAlignment();
25260
+ const isCurrentValue = unref(currentValue) === value;
25261
+ !isCurrentValue ? commands2.applyAlignment(value) : commands2.removeAlignment();
25262
+ }),
25252
25263
  applyAlignment: createCommand(({ commands: commands2 }, value) => {
25253
25264
  commands2.setBlockAttributes(this.name, { desktop: value, tablet: value, mobile: value });
25254
25265
  }),
25266
+ removeAlignment: createCommand(({ commands: commands2 }) => commands2.removeBlockAttributes(this.name)),
25255
25267
  getAlignment: createCommand(({ commands: commands2 }) => {
25256
25268
  const attribute = commands2.getBlockAttributes(this.name, DEFAULTS$1);
25257
25269
  const device = commands2.getDevice();
@@ -27323,6 +27335,11 @@ const NodeProcessor = Extension.create({
27323
27335
  }
27324
27336
  return Object.keys(attrs).length ? attrs : null;
27325
27337
  })),
27338
+ removeBlockAttributes: createCommand(({ commands: commands2 }, names) => {
27339
+ for (const type of NodeTypes.blocks) {
27340
+ commands2.resetAttributes(type, names);
27341
+ }
27342
+ }),
27326
27343
  applyMark: createCommand(({ state, commands: commands2 }, name, value) => {
27327
27344
  const { tr, doc: doc2, schema } = state;
27328
27345
  const { $from, $to } = tr.selection;
@@ -7,7 +7,7 @@ export const PRESETS = [
7
7
  'level': 1
8
8
  },
9
9
  'desktop': {
10
- 'alignment': 'left',
10
+ 'alignment': null,
11
11
  'line_height': '1.2',
12
12
  'font_size': '40px'
13
13
  },
@@ -19,12 +19,12 @@ export const PRESETS = [
19
19
  'text_decoration': 'none'
20
20
  },
21
21
  'tablet': {
22
- 'alignment': 'left',
22
+ 'alignment': null,
23
23
  'line_height': '1.2',
24
24
  'font_size': '40px'
25
25
  },
26
26
  'mobile': {
27
- 'alignment': 'left',
27
+ 'alignment': null,
28
28
  'line_height': '1.2',
29
29
  'font_size': '28px'
30
30
  }
@@ -37,7 +37,7 @@ export const PRESETS = [
37
37
  'level': 2
38
38
  },
39
39
  'desktop': {
40
- 'alignment': 'left',
40
+ 'alignment': null,
41
41
  'line_height': '1.2',
42
42
  'font_size': '32px'
43
43
  },
@@ -49,12 +49,12 @@ export const PRESETS = [
49
49
  'text_decoration': 'none'
50
50
  },
51
51
  'tablet': {
52
- 'alignment': 'left',
52
+ 'alignment': null,
53
53
  'line_height': '1.2',
54
54
  'font_size': '32px'
55
55
  },
56
56
  'mobile': {
57
- 'alignment': 'left',
57
+ 'alignment': null,
58
58
  'line_height': '1.2',
59
59
  'font_size': '24px'
60
60
  }
@@ -67,7 +67,7 @@ export const PRESETS = [
67
67
  'level': 3
68
68
  },
69
69
  'desktop': {
70
- 'alignment': 'left',
70
+ 'alignment': null,
71
71
  'line_height': '1.2',
72
72
  'font_size': '28px'
73
73
  },
@@ -79,12 +79,12 @@ export const PRESETS = [
79
79
  'text_decoration': 'none'
80
80
  },
81
81
  'tablet': {
82
- 'alignment': 'left',
82
+ 'alignment': null,
83
83
  'line_height': '1.2',
84
84
  'font_size': '28px'
85
85
  },
86
86
  'mobile': {
87
- 'alignment': 'left',
87
+ 'alignment': null,
88
88
  'line_height': '1.2',
89
89
  'font_size': '20px'
90
90
  }
@@ -97,7 +97,7 @@ export const PRESETS = [
97
97
  'level': 4
98
98
  },
99
99
  'desktop': {
100
- 'alignment': 'left',
100
+ 'alignment': null,
101
101
  'line_height': '1.2',
102
102
  'font_size': '24px'
103
103
  },
@@ -109,12 +109,12 @@ export const PRESETS = [
109
109
  'text_decoration': 'none'
110
110
  },
111
111
  'tablet': {
112
- 'alignment': 'left',
112
+ 'alignment': null,
113
113
  'line_height': '1.2',
114
114
  'font_size': '24px'
115
115
  },
116
116
  'mobile': {
117
- 'alignment': 'left',
117
+ 'alignment': null,
118
118
  'line_height': '1.2',
119
119
  'font_size': '18px'
120
120
  }
@@ -124,7 +124,7 @@ export const PRESETS = [
124
124
  'name': 'Link',
125
125
  'hidden': true,
126
126
  'desktop': {
127
- 'alignment': 'left',
127
+ 'alignment': null,
128
128
  'line_height': 'inherit',
129
129
  'font_size': 'inherit'
130
130
  },
@@ -136,12 +136,12 @@ export const PRESETS = [
136
136
  'text_decoration': 'underline'
137
137
  },
138
138
  'tablet': {
139
- 'alignment': 'left',
139
+ 'alignment': null,
140
140
  'line_height': 'inherit',
141
141
  'font_size': 'inherit'
142
142
  },
143
143
  'mobile': {
144
- 'alignment': 'left',
144
+ 'alignment': null,
145
145
  'line_height': 'inherit',
146
146
  'font_size': 'inherit'
147
147
  }
@@ -150,7 +150,7 @@ export const PRESETS = [
150
150
  'id': 'regular-1',
151
151
  'name': 'Regular',
152
152
  'desktop': {
153
- 'alignment': 'left',
153
+ 'alignment': null,
154
154
  'line_height': '1.43',
155
155
  'font_size': '18px'
156
156
  },
@@ -162,12 +162,12 @@ export const PRESETS = [
162
162
  'text_decoration': 'none'
163
163
  },
164
164
  'tablet': {
165
- 'alignment': 'left',
165
+ 'alignment': null,
166
166
  'line_height': '1.43',
167
167
  'font_size': '18px'
168
168
  },
169
169
  'mobile': {
170
- 'alignment': 'left',
170
+ 'alignment': null,
171
171
  'line_height': '1.43',
172
172
  'font_size': '18px'
173
173
  }
@@ -177,7 +177,7 @@ export const PRESETS = [
177
177
  'name': 'Regular 2',
178
178
  'fallbackClass': 'zpa-regular2',
179
179
  'desktop': {
180
- 'alignment': 'left',
180
+ 'alignment': null,
181
181
  'line_height': '1.43',
182
182
  'font_size': '16px'
183
183
  },
@@ -189,12 +189,12 @@ export const PRESETS = [
189
189
  'text_decoration': 'none'
190
190
  },
191
191
  'tablet': {
192
- 'alignment': 'left',
192
+ 'alignment': null,
193
193
  'line_height': '1.43',
194
194
  'font_size': '16px'
195
195
  },
196
196
  'mobile': {
197
- 'alignment': 'left',
197
+ 'alignment': null,
198
198
  'line_height': '1.43',
199
199
  'font_size': '16px'
200
200
  }
@@ -204,7 +204,7 @@ export const PRESETS = [
204
204
  'name': 'Regular 3',
205
205
  'fallbackClass': 'zpa-regular3',
206
206
  'desktop': {
207
- 'alignment': 'left',
207
+ 'alignment': null,
208
208
  'line_height': '1.43',
209
209
  'font_size': '12px'
210
210
  },
@@ -216,12 +216,12 @@ export const PRESETS = [
216
216
  'text_decoration': 'none'
217
217
  },
218
218
  'tablet': {
219
- 'alignment': 'left',
219
+ 'alignment': null,
220
220
  'line_height': '1.43',
221
221
  'font_size': '12px'
222
222
  },
223
223
  'mobile': {
224
- 'alignment': 'left',
224
+ 'alignment': null,
225
225
  'line_height': '1.43',
226
226
  'font_size': '12px'
227
227
  }
@@ -23,7 +23,7 @@
23
23
 
24
24
  <script>
25
25
  import { ZipifyColorPicker } from '@zipify/colorpicker';
26
- import { inject, ref, toRef } from 'vue';
26
+ import { inject, ref, toRef, unref } from 'vue';
27
27
  import { outClick } from '../../../directives';
28
28
  import { InjectionTokens } from '../../../injectionTokens';
29
29
  import { ContextWindow } from '../../../services';
@@ -55,6 +55,8 @@ export default {
55
55
 
56
56
  const api = usePickerApi({
57
57
  onChange: (color) => {
58
+ if (!unref(api.isOpened)) return false;
59
+
58
60
  emit('change', color);
59
61
  editor.chain().focus().restoreSelection().run();
60
62
  },
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <ButtonToggle :value="currentValue" :options="$options.alignments" @change="apply">
2
+ <ButtonToggle :value="currentValue" :options="$options.alignments" @change="toggle">
3
3
  <template #option="{ isActive, option, activate }">
4
4
  <Button
5
5
  class="zw-position--relative"
@@ -24,7 +24,7 @@
24
24
  </template>
25
25
 
26
26
  <script>
27
- import { inject } from 'vue';
27
+ import { inject, computed, unref } from 'vue';
28
28
  import { InjectionTokens } from '../../../injectionTokens';
29
29
  import { Alignments, TextSettings } from '../../../enums';
30
30
  import { ButtonToggle, Button, Icon } from '../../base';
@@ -64,19 +64,19 @@ export default {
64
64
 
65
65
  setup(_, { emit }) {
66
66
  const editor = inject(InjectionTokens.EDITOR);
67
-
68
- const currentValue = editor.commands.getAlignment();
67
+ const alignment = editor.commands.getAlignment();
68
+ const currentValue = computed(() => unref(alignment) ?? 'none');
69
69
  const isCustomized = editor.commands.isSettingCustomized(TextSettings.ALIGNMENT);
70
70
 
71
- function apply(value) {
72
- editor.chain().focus().applyAlignment(value).run();
71
+ function toggle(value) {
72
+ editor.chain().focus().toggleAlignment(value).run();
73
73
  emit('applied');
74
74
  }
75
75
 
76
76
  return {
77
77
  currentValue,
78
78
  isCustomized,
79
- apply
79
+ toggle
80
80
  };
81
81
  }
82
82
  };
@@ -14,7 +14,7 @@ const createEditor = ({ alignment, isSettingCustomized } = {}) => ({
14
14
  getAlignment: () => ref(alignment),
15
15
  isSettingCustomized: () => ref(isSettingCustomized ?? false),
16
16
  focus: jest.fn().mockReturnThis(),
17
- applyAlignment: jest.fn().mockReturnThis(),
17
+ toggleAlignment: jest.fn().mockReturnThis(),
18
18
  run: jest.fn()
19
19
  },
20
20
 
@@ -60,7 +60,7 @@ describe('selection value', () => {
60
60
  expect(buttonWrapper.props('value')).toBe(Alignments.RIGHT);
61
61
  });
62
62
 
63
- test('should apply new value', () => {
63
+ test('should toggle new value', () => {
64
64
  const editor = createEditor({ alignment: Alignments.RIGHT });
65
65
  const wrapper = createComponent({
66
66
  editor,
@@ -76,7 +76,7 @@ describe('selection value', () => {
76
76
 
77
77
  buttonWrapper.vm.$emit('change', Alignments.CENTER);
78
78
 
79
- expect(editor.commands.applyAlignment).toHaveBeenCalledWith(Alignments.CENTER);
79
+ expect(editor.commands.toggleAlignment).toHaveBeenCalledWith(Alignments.CENTER);
80
80
  });
81
81
  });
82
82
 
@@ -51,6 +51,13 @@ export const Alignment = Extension.create({
51
51
 
52
52
  addCommands() {
53
53
  return {
54
+ toggleAlignment: createCommand(({ commands }, value) => {
55
+ const currentValue = commands.getAlignment();
56
+ const isCurrentValue = unref(currentValue) === value;
57
+
58
+ !isCurrentValue ? commands.applyAlignment(value) : commands.removeAlignment();
59
+ }),
60
+
54
61
  applyAlignment: createCommand(({ commands }, value) => {
55
62
  // const device = unref(commands.getDevice());
56
63
  //
@@ -60,6 +67,8 @@ export const Alignment = Extension.create({
60
67
  commands.setBlockAttributes(this.name, { desktop: value, tablet: value, mobile: value });
61
68
  }),
62
69
 
70
+ removeAlignment: createCommand(({ commands }) => commands.removeBlockAttributes(this.name)),
71
+
63
72
  getAlignment: createCommand(({ commands }) => {
64
73
  const attribute = commands.getBlockAttributes(this.name, DEFAULTS);
65
74
  const device = commands.getDevice();
@@ -70,8 +70,19 @@ describe('get value', () => {
70
70
  });
71
71
  });
72
72
 
73
- describe('apply value', () => {
74
- test('should change value', () => {
73
+ describe('change value', () => {
74
+ test('should toggle value', () => {
75
+ const editor = createEditor({
76
+ content: createContent({ alignment: null })
77
+ });
78
+
79
+ editor.commands.selectAll();
80
+ editor.commands.toggleAlignment(Alignments.RIGHT);
81
+
82
+ expect(editor.getJSON()).toMatchSnapshot();
83
+ });
84
+
85
+ test('should apply value', () => {
75
86
  const editor = createEditor({
76
87
  content: createContent({ alignment: null })
77
88
  });
@@ -81,6 +92,19 @@ describe('apply value', () => {
81
92
 
82
93
  expect(editor.getJSON()).toMatchSnapshot();
83
94
  });
95
+
96
+ test('should remove value', () => {
97
+ const editor = createEditor({
98
+ content: createContent({
99
+ alignment: { desktop: Alignments.CENTER }
100
+ })
101
+ });
102
+
103
+ editor.commands.selectAll();
104
+ editor.commands.removeAlignment(TextSettings.ALIGNMENT);
105
+
106
+ expect(editor.getJSON()).toMatchSnapshot();
107
+ });
84
108
  });
85
109
 
86
110
  describe('rendering', () => {
@@ -1,6 +1,50 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
- exports[`apply value should change value 1`] = `
3
+ exports[`change value should apply value 1`] = `
4
+ Object {
5
+ "content": Array [
6
+ Object {
7
+ "attrs": Object {
8
+ "alignment": Object {
9
+ "desktop": "right",
10
+ "mobile": "right",
11
+ "tablet": "right",
12
+ },
13
+ },
14
+ "content": Array [
15
+ Object {
16
+ "text": "hello world",
17
+ "type": "text",
18
+ },
19
+ ],
20
+ "type": "paragraph",
21
+ },
22
+ ],
23
+ "type": "doc",
24
+ }
25
+ `;
26
+
27
+ exports[`change value should remove value 1`] = `
28
+ Object {
29
+ "content": Array [
30
+ Object {
31
+ "attrs": Object {
32
+ "alignment": null,
33
+ },
34
+ "content": Array [
35
+ Object {
36
+ "text": "hello world",
37
+ "type": "text",
38
+ },
39
+ ],
40
+ "type": "paragraph",
41
+ },
42
+ ],
43
+ "type": "doc",
44
+ }
45
+ `;
46
+
47
+ exports[`change value should toggle value 1`] = `
4
48
  Object {
5
49
  "content": Array [
6
50
  Object {
@@ -37,6 +37,12 @@ export const NodeProcessor = Extension.create({
37
37
  return Object.keys(attrs).length ? attrs : null;
38
38
  })),
39
39
 
40
+ removeBlockAttributes: createCommand(({ commands }, names) => {
41
+ for (const type of NodeTypes.blocks) {
42
+ commands.resetAttributes(type, names);
43
+ }
44
+ }),
45
+
40
46
  applyMark: createCommand(({ state, commands }, name, value) => {
41
47
  const { tr, doc, schema } = state;
42
48
  const { $from, $to } = tr.selection;
@@ -16,6 +16,9 @@ const MockLineHeight = Extension.create({
16
16
  line_height: {
17
17
  isRequired: false,
18
18
  renderHTML: (attrs) => ({ style: `line-height: ${attrs.line_height}` })
19
+ },
20
+ alignment: {
21
+ isRequired: false
19
22
  }
20
23
  }
21
24
  }
@@ -138,6 +141,37 @@ describe('block attributes', () => {
138
141
  expect(editor.getJSON()).toMatchSnapshot();
139
142
  });
140
143
 
144
+ test('should remove some attribute', () => {
145
+ const editor = createEditor({
146
+ content: createContent({
147
+ line_height: { mobile: '1.2' }
148
+ })
149
+ });
150
+
151
+ editor.commands.selectAll();
152
+ editor.commands.removeBlockAttributes(TextSettings.LINE_HEIGHT);
153
+
154
+ expect(editor.getJSON()).toMatchSnapshot();
155
+ });
156
+
157
+ test('should remove a few some attributes', () => {
158
+ const editor = createEditor({
159
+ content: createContent({
160
+ line_height: { mobile: '1.2' },
161
+ alignment: {
162
+ mobile: 'center',
163
+ tablet: 'center',
164
+ desktop: 'center'
165
+ }
166
+ })
167
+ });
168
+
169
+ editor.commands.selectAll();
170
+ editor.commands.removeBlockAttributes([TextSettings.LINE_HEIGHT, TextSettings.ALIGNMENT]);
171
+
172
+ expect(editor.getJSON()).toMatchSnapshot();
173
+ });
174
+
141
175
  test('should set attributes with defaults', () => {
142
176
  const editor = createEditor({
143
177
  content: createContent({ line_height: null })