@zipify/wysiwyg 1.3.0-0 → 1.4.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
@@ -23277,28 +23277,12 @@ const StylePreset = Extension.create({
23277
23277
  removePreset: createCommand(({ commands: commands2 }) => {
23278
23278
  commands2.setNode(NodeTypes.PARAGRAPH, { preset: null });
23279
23279
  }),
23280
- getPresetCustomization: createCommand(({ editor }) => {
23280
+ getPresetCustomization: createCommand(({ editor, commands: commands2 }) => {
23281
23281
  const state = toRef(editor, "state");
23282
23282
  return computed(() => {
23283
- const attributes = /* @__PURE__ */ new Set();
23284
- const marks = /* @__PURE__ */ new Set();
23285
- const { from: from2, to } = state.value.selection;
23286
- state.value.doc.nodesBetween(from2, to, (node) => {
23287
- for (const [name, value] of Object.entries(node.attrs)) {
23288
- const isSetting = TextSettings.attributes.includes(name);
23289
- if (isSetting && value)
23290
- attributes.add(name);
23291
- }
23292
- for (const { type } of node.marks) {
23293
- if (TextSettings.marks.includes(type.name)) {
23294
- marks.add(type.name);
23295
- }
23296
- }
23297
- });
23298
- return {
23299
- attributes: Array.from(attributes),
23300
- marks: Array.from(marks)
23301
- };
23283
+ const { selection, doc: doc2 } = unref(state);
23284
+ const { from: from2, to } = selection;
23285
+ return commands2._getSettingCustomization(doc2, from2, to);
23302
23286
  });
23303
23287
  }),
23304
23288
  isSettingCustomized: createCommand(({ commands: commands2 }, group, name) => {
@@ -23308,6 +23292,33 @@ const StylePreset = Extension.create({
23308
23292
  return (_b = (_a = unref(customization)[group]) == null ? void 0 : _a.includes(name)) != null ? _b : false;
23309
23293
  });
23310
23294
  }),
23295
+ getContentCustomization: createCommand(({ editor, commands: commands2 }) => {
23296
+ const state = toRef(editor, "state");
23297
+ return computed(() => {
23298
+ const { doc: doc2 } = unref(state);
23299
+ return commands2._getSettingCustomization(doc2, 0, doc2.content.size);
23300
+ });
23301
+ }),
23302
+ _getSettingCustomization: createCommand((_, doc2, from2, to) => {
23303
+ const marks = /* @__PURE__ */ new Set();
23304
+ const attributes = /* @__PURE__ */ new Set();
23305
+ doc2.nodesBetween(from2, to, (node) => {
23306
+ for (const [name, value] of Object.entries(node.attrs)) {
23307
+ const isSetting = TextSettings.attributes.includes(name);
23308
+ if (isSetting && value)
23309
+ attributes.add(name);
23310
+ }
23311
+ for (const { type } of node.marks) {
23312
+ if (TextSettings.marks.includes(type.name)) {
23313
+ marks.add(type.name);
23314
+ }
23315
+ }
23316
+ });
23317
+ return {
23318
+ attributes: Array.from(attributes),
23319
+ marks: Array.from(marks)
23320
+ };
23321
+ }),
23311
23322
  removePresetCustomization: createCommand(({ chain }) => {
23312
23323
  chain().storeSelection().expandSelectionToBlock().unsetMarks(TextSettings.marks).resetAttributes(NodeTypes.PARAGRAPH, TextSettings.attributes).resetAttributes(NodeTypes.HEADING, TextSettings.attributes).restoreSelection().run();
23313
23324
  }),
@@ -26215,6 +26226,7 @@ const __vue2_script = {
26215
26226
  listRef: toRef(props, "favoriteColors"),
26216
26227
  triggerUpdate: (colors) => emit("update-favorite-colors", colors)
26217
26228
  });
26229
+ const getContentCustomization = () => editor.commands.getContentCustomization();
26218
26230
  provide(InjectionTokens$1.EDITOR, editor);
26219
26231
  provide(InjectionTokens$1.FONTS, fonts);
26220
26232
  provide(InjectionTokens$1.FONT_SIZES, fontSizes);
@@ -26227,7 +26239,8 @@ const __vue2_script = {
26227
26239
  toolbarRef,
26228
26240
  wysiwygRef,
26229
26241
  toolbar,
26230
- updateToolbar
26242
+ updateToolbar,
26243
+ getContentCustomization
26231
26244
  };
26232
26245
  }
26233
26246
  };
package/lib/Wysiwyg.vue CHANGED
@@ -193,6 +193,8 @@ export default {
193
193
  triggerUpdate: (colors) => emit('update-favorite-colors', colors)
194
194
  });
195
195
 
196
+ const getContentCustomization = () => editor.commands.getContentCustomization();
197
+
196
198
  provide(InjectionTokens.EDITOR, editor);
197
199
  provide(InjectionTokens.FONTS, fonts);
198
200
  provide(InjectionTokens.FONT_SIZES, fontSizes);
@@ -206,7 +208,8 @@ export default {
206
208
  toolbarRef,
207
209
  wysiwygRef,
208
210
  toolbar,
209
- updateToolbar
211
+ updateToolbar,
212
+ getContentCustomization
210
213
  };
211
214
  }
212
215
  };
@@ -140,32 +140,14 @@ export const StylePreset = Extension.create({
140
140
  commands.setNode(NodeTypes.PARAGRAPH, { preset: null });
141
141
  }),
142
142
 
143
- getPresetCustomization: createCommand(({ editor }) => {
143
+ getPresetCustomization: createCommand(({ editor, commands }) => {
144
144
  const state = toRef(editor, 'state');
145
145
 
146
146
  return computed(() => {
147
- const attributes = new Set();
148
- const marks = new Set();
149
- const { from, to } = state.value.selection;
147
+ const { selection, doc } = unref(state);
148
+ const { from, to } = selection;
150
149
 
151
- state.value.doc.nodesBetween(from, to, (node) => {
152
- for (const [name, value] of Object.entries(node.attrs)) {
153
- const isSetting = TextSettings.attributes.includes(name);
154
-
155
- if (isSetting && value) attributes.add(name);
156
- }
157
-
158
- for (const { type } of node.marks) {
159
- if (TextSettings.marks.includes(type.name)) {
160
- marks.add(type.name);
161
- }
162
- }
163
- });
164
-
165
- return {
166
- attributes: Array.from(attributes),
167
- marks: Array.from(marks)
168
- };
150
+ return commands._getSettingCustomization(doc, from, to);
169
151
  });
170
152
  }),
171
153
 
@@ -175,6 +157,40 @@ export const StylePreset = Extension.create({
175
157
  return computed(() => unref(customization)[group]?.includes(name) ?? false);
176
158
  }),
177
159
 
160
+ getContentCustomization: createCommand(({ editor, commands }) => {
161
+ const state = toRef(editor, 'state');
162
+
163
+ return computed(() => {
164
+ const { doc } = unref(state);
165
+
166
+ return commands._getSettingCustomization(doc, 0, doc.content.size);
167
+ });
168
+ }),
169
+
170
+ _getSettingCustomization: createCommand((_, doc, from, to) => {
171
+ const marks = new Set();
172
+ const attributes = new Set();
173
+
174
+ doc.nodesBetween(from, to, (node) => {
175
+ for (const [name, value] of Object.entries(node.attrs)) {
176
+ const isSetting = TextSettings.attributes.includes(name);
177
+
178
+ if (isSetting && value) attributes.add(name);
179
+ }
180
+
181
+ for (const { type } of node.marks) {
182
+ if (TextSettings.marks.includes(type.name)) {
183
+ marks.add(type.name);
184
+ }
185
+ }
186
+ });
187
+
188
+ return {
189
+ attributes: Array.from(attributes),
190
+ marks: Array.from(marks)
191
+ };
192
+ }),
193
+
178
194
  removePresetCustomization: createCommand(({ chain }) => {
179
195
  chain()
180
196
  .storeSelection()
@@ -486,6 +486,54 @@ describe('get preset customization', () => {
486
486
  });
487
487
  });
488
488
 
489
+ describe('get content customization', () => {
490
+ test('should return empty content customization', async () => {
491
+ const editor = await createEditor({
492
+ content: NodeFactory.doc([
493
+ NodeFactory.paragraph({ preset: { id: 'regular-1' } }, 'test')
494
+ ]),
495
+ presets: [createPreset({ id: 'regular-1' })]
496
+ });
497
+ const customization = editor.commands.getContentCustomization();
498
+
499
+ expect(customization.value).toMatchSnapshot();
500
+ });
501
+
502
+ test('should find marks', async () => {
503
+ const editor = await createEditor({
504
+ content: NodeFactory.doc([
505
+ NodeFactory.paragraph({ preset: { id: 'regular-2' } }, [
506
+ NodeFactory.text('test', [
507
+ NodeFactory.mark(TextSettings.FONT_SIZE, { value: '44' }),
508
+ NodeFactory.mark(TextSettings.FONT_WEIGHT, { value: '500' })
509
+ ])
510
+ ])
511
+ ]),
512
+ presets: [createPreset({ id: 'regular-1' })]
513
+ });
514
+
515
+ const customization = editor.commands.getContentCustomization();
516
+
517
+ expect(customization.value).toMatchSnapshot();
518
+ });
519
+
520
+ test('should find attributes', async () => {
521
+ const editor = await createEditor({
522
+ content: NodeFactory.doc([
523
+ NodeFactory.paragraph({
524
+ preset: { id: 'regular-2' },
525
+ alignment: { value: 'right' }
526
+ }, 'test')
527
+ ]),
528
+ presets: [createPreset({ id: 'regular-2' })]
529
+ });
530
+
531
+ const customization = editor.commands.getContentCustomization();
532
+
533
+ expect(customization.value).toMatchSnapshot();
534
+ });
535
+ });
536
+
489
537
  describe('remove preset customization', () => {
490
538
  test('should remove all marks in block', async () => {
491
539
  const editor = await createEditor({
@@ -197,6 +197,32 @@ Object {
197
197
  }
198
198
  `;
199
199
 
200
+ exports[`get content customization should find attributes 1`] = `
201
+ Object {
202
+ "attributes": Array [
203
+ "alignment",
204
+ ],
205
+ "marks": Array [],
206
+ }
207
+ `;
208
+
209
+ exports[`get content customization should find marks 1`] = `
210
+ Object {
211
+ "attributes": Array [],
212
+ "marks": Array [
213
+ "font_size",
214
+ "font_weight",
215
+ ],
216
+ }
217
+ `;
218
+
219
+ exports[`get content customization should return empty content customization 1`] = `
220
+ Object {
221
+ "attributes": Array [],
222
+ "marks": Array [],
223
+ }
224
+ `;
225
+
200
226
  exports[`get preset customization should find attributes 1`] = `
201
227
  Object {
202
228
  "attributes": Array [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zipify/wysiwyg",
3
- "version": "1.3.0-0",
3
+ "version": "1.4.0-0",
4
4
  "description": "Zipify modification of TipTap text editor",
5
5
  "main": "dist/wysiwyg.mjs",
6
6
  "bin": {