@tiptap/core 3.0.0-beta.25 → 3.0.0-beta.26

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/index.cjs CHANGED
@@ -15331,6 +15331,7 @@ __export(index_exports, {
15331
15331
  textInputRule: () => textInputRule,
15332
15332
  textPasteRule: () => textPasteRule,
15333
15333
  textblockTypeInputRule: () => textblockTypeInputRule,
15334
+ updateMarkViewAttributes: () => updateMarkViewAttributes,
15334
15335
  wrappingInputRule: () => wrappingInputRule
15335
15336
  });
15336
15337
  module.exports = __toCommonJS(index_exports);
@@ -17602,7 +17603,10 @@ var ExtensionManager = class {
17602
17603
  // tiptap-specific
17603
17604
  editor,
17604
17605
  extension,
17605
- HTMLAttributes
17606
+ HTMLAttributes,
17607
+ updateAttributes: (attrs) => {
17608
+ updateMarkViewAttributes(mark, editor, attrs);
17609
+ }
17606
17610
  });
17607
17611
  };
17608
17612
  return [extension.name, markView];
@@ -20355,6 +20359,42 @@ function isString(value) {
20355
20359
  }
20356
20360
 
20357
20361
  // src/MarkView.ts
20362
+ function updateMarkViewAttributes(checkMark, editor, attrs = {}) {
20363
+ const { state } = editor;
20364
+ const { doc: doc2, tr } = state;
20365
+ const thisMark = checkMark;
20366
+ doc2.descendants((node, pos) => {
20367
+ const from = tr.mapping.map(pos);
20368
+ const to = tr.mapping.map(pos) + node.nodeSize;
20369
+ let foundMark = null;
20370
+ node.marks.forEach((mark) => {
20371
+ if (mark !== thisMark) {
20372
+ return false;
20373
+ }
20374
+ foundMark = mark;
20375
+ });
20376
+ if (!foundMark) {
20377
+ return;
20378
+ }
20379
+ let needsUpdate = false;
20380
+ Object.keys(attrs).forEach((k) => {
20381
+ if (attrs[k] !== foundMark.attrs[k]) {
20382
+ needsUpdate = true;
20383
+ }
20384
+ });
20385
+ if (needsUpdate) {
20386
+ const updatedMark = checkMark.type.create({
20387
+ ...checkMark.attrs,
20388
+ ...attrs
20389
+ });
20390
+ tr.removeMark(from, to, checkMark.type);
20391
+ tr.addMark(from, to, updatedMark);
20392
+ }
20393
+ });
20394
+ if (tr.docChanged) {
20395
+ editor.view.dispatch(tr);
20396
+ }
20397
+ }
20358
20398
  var MarkView = class {
20359
20399
  constructor(component, props, options) {
20360
20400
  this.component = component;
@@ -20369,6 +20409,13 @@ var MarkView = class {
20369
20409
  get contentDOM() {
20370
20410
  return null;
20371
20411
  }
20412
+ /**
20413
+ * Update the attributes of the mark in the document.
20414
+ * @param attrs The attributes to update.
20415
+ */
20416
+ updateAttributes(attrs, checkMark) {
20417
+ updateMarkViewAttributes(checkMark || this.mark, this.editor, attrs);
20418
+ }
20372
20419
  ignoreMutation(mutation) {
20373
20420
  if (!this.dom || !this.contentDOM) {
20374
20421
  return true;
@@ -20809,6 +20856,7 @@ var Tracker = class {
20809
20856
  textInputRule,
20810
20857
  textPasteRule,
20811
20858
  textblockTypeInputRule,
20859
+ updateMarkViewAttributes,
20812
20860
  wrappingInputRule
20813
20861
  });
20814
20862
  //# sourceMappingURL=index.cjs.map