@superdoc-dev/cli 0.7.0-next.17 → 0.7.0-next.19

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.
Files changed (2) hide show
  1. package/dist/index.js +1536 -553
  2. package/package.json +8 -8
package/dist/index.js CHANGED
@@ -76859,7 +76859,7 @@ function checkTextSelection($pos) {
76859
76859
  }
76860
76860
  function findSelectionIn(doc$2, node3, pos, index2, dir, text$2 = false) {
76861
76861
  if (node3.inlineContent)
76862
- return TextSelection2.create(doc$2, pos);
76862
+ return TextSelection.create(doc$2, pos);
76863
76863
  for (let i$1 = index2 - (dir > 0 ? 0 : 1);dir > 0 ? i$1 < node3.childCount : i$1 >= 0; i$1 += dir) {
76864
76864
  let child = node3.child(i$1);
76865
76865
  if (!child.isAtom) {
@@ -80044,7 +80044,7 @@ function selectionToDOM(view, force = false) {
80044
80044
  selectCursorWrapper(view);
80045
80045
  else {
80046
80046
  let { anchor, head } = sel, resetEditableFrom, resetEditableTo;
80047
- if (brokenSelectBetweenUneditable && !(sel instanceof TextSelection2)) {
80047
+ if (brokenSelectBetweenUneditable && !(sel instanceof TextSelection)) {
80048
80048
  if (!sel.$from.parent.inlineContent)
80049
80049
  resetEditableFrom = temporarilyEditableNear(view, sel.from);
80050
80050
  if (!sel.empty && !sel.$from.parent.inlineContent)
@@ -80145,7 +80145,7 @@ function clearNodeSelection(view) {
80145
80145
  }
80146
80146
  }
80147
80147
  function selectionBetween(view, $anchor, $head, bias) {
80148
- return view.someProp("createSelectionBetween", (f2) => f2(view, $anchor, $head)) || TextSelection2.between($anchor, $head, bias);
80148
+ return view.someProp("createSelectionBetween", (f2) => f2(view, $anchor, $head)) || TextSelection.between($anchor, $head, bias);
80149
80149
  }
80150
80150
  function hasFocusAndSelection(view) {
80151
80151
  if (view.editable && !view.hasFocus())
@@ -80179,13 +80179,13 @@ function apply(view, sel) {
80179
80179
  }
80180
80180
  function selectHorizontally(view, dir, mods) {
80181
80181
  let sel = view.state.selection;
80182
- if (sel instanceof TextSelection2) {
80182
+ if (sel instanceof TextSelection) {
80183
80183
  if (mods.indexOf("s") > -1) {
80184
80184
  let { $head } = sel, node3 = $head.textOffset ? null : dir < 0 ? $head.nodeBefore : $head.nodeAfter;
80185
80185
  if (!node3 || node3.isText || !node3.isLeaf)
80186
80186
  return false;
80187
80187
  let $newHead = view.state.doc.resolve($head.pos + node3.nodeSize * (dir < 0 ? -1 : 1));
80188
- return apply(view, new TextSelection2(sel.$anchor, $newHead));
80188
+ return apply(view, new TextSelection(sel.$anchor, $newHead));
80189
80189
  } else if (!sel.empty)
80190
80190
  return false;
80191
80191
  else if (view.endOfTextblock(dir > 0 ? "forward" : "backward")) {
@@ -80203,12 +80203,12 @@ function selectHorizontally(view, dir, mods) {
80203
80203
  if (NodeSelection.isSelectable(node3))
80204
80204
  return apply(view, new NodeSelection(dir < 0 ? view.state.doc.resolve($head.pos - node3.nodeSize) : $head));
80205
80205
  else if (webkit)
80206
- return apply(view, new TextSelection2(view.state.doc.resolve(dir < 0 ? nodePos : nodePos + node3.nodeSize)));
80206
+ return apply(view, new TextSelection(view.state.doc.resolve(dir < 0 ? nodePos : nodePos + node3.nodeSize)));
80207
80207
  else
80208
80208
  return false;
80209
80209
  }
80210
80210
  } else if (sel instanceof NodeSelection && sel.node.isInline)
80211
- return apply(view, new TextSelection2(dir > 0 ? sel.$to : sel.$from));
80211
+ return apply(view, new TextSelection(dir > 0 ? sel.$to : sel.$from));
80212
80212
  else {
80213
80213
  let next = moveSelectionBlock(view.state, dir);
80214
80214
  if (next)
@@ -80397,7 +80397,7 @@ function findDirection(view, pos) {
80397
80397
  }
80398
80398
  function selectVertically(view, dir, mods) {
80399
80399
  let sel = view.state.selection;
80400
- if (sel instanceof TextSelection2 && !sel.empty || mods.indexOf("s") > -1)
80400
+ if (sel instanceof TextSelection && !sel.empty || mods.indexOf("s") > -1)
80401
80401
  return false;
80402
80402
  if (mac$2 && mods.indexOf("m") > -1)
80403
80403
  return false;
@@ -80415,7 +80415,7 @@ function selectVertically(view, dir, mods) {
80415
80415
  return false;
80416
80416
  }
80417
80417
  function stopNativeHorizontalDelete(view, dir) {
80418
- if (!(view.state.selection instanceof TextSelection2))
80418
+ if (!(view.state.selection instanceof TextSelection))
80419
80419
  return true;
80420
80420
  let { $head, $anchor, empty: empty$1 } = view.state.selection;
80421
80421
  if (!$head.sameParent($anchor))
@@ -80846,7 +80846,7 @@ function defaultTripleClick(view, inside, event) {
80846
80846
  let doc$2 = view.state.doc;
80847
80847
  if (inside == -1) {
80848
80848
  if (doc$2.inlineContent) {
80849
- updateSelection(view, TextSelection2.create(doc$2, 0, doc$2.content.size), "pointer");
80849
+ updateSelection(view, TextSelection.create(doc$2, 0, doc$2.content.size), "pointer");
80850
80850
  return true;
80851
80851
  }
80852
80852
  return false;
@@ -80856,7 +80856,7 @@ function defaultTripleClick(view, inside, event) {
80856
80856
  let node3 = i$1 > $pos.depth ? $pos.nodeAfter : $pos.node(i$1);
80857
80857
  let nodePos = $pos.before(i$1);
80858
80858
  if (node3.inlineContent)
80859
- updateSelection(view, TextSelection2.create(doc$2, nodePos + 1, nodePos + 1 + node3.content.size), "pointer");
80859
+ updateSelection(view, TextSelection.create(doc$2, nodePos + 1, nodePos + 1 + node3.content.size), "pointer");
80860
80860
  else if (NodeSelection.isSelectable(node3))
80861
80861
  updateSelection(view, NodeSelection.create(doc$2, nodePos), "pointer");
80862
80862
  else
@@ -81441,7 +81441,7 @@ function readDOMChange(view, from4, to, typeOver, addedNodes) {
81441
81441
  return;
81442
81442
  }
81443
81443
  if (!change)
81444
- if (typeOver && sel instanceof TextSelection2 && !sel.empty && sel.$head.sameParent(sel.$anchor) && !view.composing && !(parse$1.sel && parse$1.sel.anchor != parse$1.sel.head))
81444
+ if (typeOver && sel instanceof TextSelection && !sel.empty && sel.$head.sameParent(sel.$anchor) && !view.composing && !(parse$1.sel && parse$1.sel.anchor != parse$1.sel.head))
81445
81445
  change = {
81446
81446
  start: sel.from,
81447
81447
  endA: sel.to,
@@ -81459,7 +81459,7 @@ function readDOMChange(view, from4, to, typeOver, addedNodes) {
81459
81459
  }
81460
81460
  return;
81461
81461
  }
81462
- if (view.state.selection.from < view.state.selection.to && change.start == change.endB && view.state.selection instanceof TextSelection2) {
81462
+ if (view.state.selection.from < view.state.selection.to && change.start == change.endB && view.state.selection instanceof TextSelection) {
81463
81463
  if (change.start > view.state.selection.from && change.start <= view.state.selection.from + 2 && view.state.selection.from >= parse$1.from)
81464
81464
  change.start = view.state.selection.from;
81465
81465
  else if (change.endA < view.state.selection.to && change.endA >= view.state.selection.to - 2 && view.state.selection.to <= parse$1.to) {
@@ -82099,10 +82099,10 @@ function normalizeSelection(state, tr, allowTableNodeSelection) {
82099
82099
  const lastCell = start + map4.map[map4.width * map4.height - 1];
82100
82100
  normalize$1 = CellSelection.create(doc$2, start + 1, lastCell);
82101
82101
  }
82102
- } else if (sel instanceof TextSelection2 && isCellBoundarySelection(sel))
82103
- normalize$1 = TextSelection2.create(doc$2, sel.from);
82104
- else if (sel instanceof TextSelection2 && isTextSelectionAcrossCells(sel))
82105
- normalize$1 = TextSelection2.create(doc$2, sel.$from.start(), sel.$from.end());
82102
+ } else if (sel instanceof TextSelection && isCellBoundarySelection(sel))
82103
+ normalize$1 = TextSelection.create(doc$2, sel.from);
82104
+ else if (sel instanceof TextSelection && isTextSelectionAcrossCells(sel))
82105
+ normalize$1 = TextSelection.create(doc$2, sel.$from.start(), sel.$from.end());
82106
82106
  if (normalize$1)
82107
82107
  (tr || (tr = state.tr)).setSelection(normalize$1);
82108
82108
  return tr;
@@ -82632,7 +82632,7 @@ function goToNextCell(direction) {
82632
82632
  return false;
82633
82633
  if (dispatch) {
82634
82634
  const $cell = state.doc.resolve(cell);
82635
- dispatch(state.tr.setSelection(TextSelection2.between($cell, moveCellForward($cell))).scrollIntoView());
82635
+ dispatch(state.tr.setSelection(TextSelection.between($cell, moveCellForward($cell))).scrollIntoView());
82636
82636
  }
82637
82637
  return true;
82638
82638
  };
@@ -83021,7 +83021,7 @@ function handleMouseDown$1(view, startEvent) {
83021
83021
  view.root.addEventListener("mousemove", move);
83022
83022
  }
83023
83023
  function atEndOfCell(view, axis, dir) {
83024
- if (!(view.state.selection instanceof TextSelection2))
83024
+ if (!(view.state.selection instanceof TextSelection))
83025
83025
  return null;
83026
83026
  const { $head } = view.state.selection;
83027
83027
  for (let d = $head.depth - 1;d >= 0; d--) {
@@ -83521,7 +83521,7 @@ function stableStringifyInlineProps(inlineProps) {
83521
83521
  function createSelectionPreserver(tr, originalSelection, originalStoredMarks = null) {
83522
83522
  if (!originalSelection)
83523
83523
  return null;
83524
- const isTextSelection$1 = originalSelection instanceof TextSelection2;
83524
+ const isTextSelection$1 = originalSelection instanceof TextSelection;
83525
83525
  let preservedAnchor = isTextSelection$1 ? originalSelection.anchor : null;
83526
83526
  let preservedHead = isTextSelection$1 ? originalSelection.head : null;
83527
83527
  const anchorAssoc = preservedAnchor != null && preservedHead != null && preservedAnchor <= preservedHead ? -1 : 1;
@@ -83561,7 +83561,7 @@ function createSelectionPreserver(tr, originalSelection, originalStoredMarks = n
83561
83561
  if (!tr.docChanged)
83562
83562
  return;
83563
83563
  if (isTextSelection$1 && preservedAnchor != null && preservedHead != null) {
83564
- tr.setSelection(TextSelection2.create(tr.doc, preservedAnchor, preservedHead));
83564
+ tr.setSelection(TextSelection.create(tr.doc, preservedAnchor, preservedHead));
83565
83565
  if (preservedAnchor === preservedHead && originalStoredMarks !== null)
83566
83566
  tr.setStoredMarks(originalStoredMarks);
83567
83567
  return;
@@ -84817,7 +84817,7 @@ function canAllocateRels(editor) {
84817
84817
  function handlePlainTextUrlPaste(editor, view, plainText, detected) {
84818
84818
  const { state } = view;
84819
84819
  const { selection } = state;
84820
- if (!(selection instanceof TextSelection2))
84820
+ if (!(selection instanceof TextSelection))
84821
84821
  return false;
84822
84822
  const linkMarkType = editor.schema.marks.link;
84823
84823
  const underlineMarkType = editor.schema.marks.underline;
@@ -104784,7 +104784,7 @@ var isRegExp = (value) => {
104784
104784
  }
104785
104785
  }
104786
104786
  static findFrom($pos, dir, textOnly = false) {
104787
- let inner = $pos.parent.inlineContent ? new TextSelection2($pos) : findSelectionIn($pos.node(0), $pos.parent, $pos.pos, $pos.index(), dir, textOnly);
104787
+ let inner = $pos.parent.inlineContent ? new TextSelection($pos) : findSelectionIn($pos.node(0), $pos.parent, $pos.pos, $pos.index(), dir, textOnly);
104788
104788
  if (inner)
104789
104789
  return inner;
104790
104790
  for (let depth = $pos.depth - 1;depth >= 0; depth--) {
@@ -104819,14 +104819,14 @@ var isRegExp = (value) => {
104819
104819
  return selectionClass;
104820
104820
  }
104821
104821
  getBookmark() {
104822
- return TextSelection2.between(this.$anchor, this.$head).getBookmark();
104822
+ return TextSelection.between(this.$anchor, this.$head).getBookmark();
104823
104823
  }
104824
104824
  }, SelectionRange = class {
104825
104825
  constructor($from, $to) {
104826
104826
  this.$from = $from;
104827
104827
  this.$to = $to;
104828
104828
  }
104829
- }, warnedAboutTextSelection = false, TextSelection2, TextBookmark = class TextBookmark2 {
104829
+ }, warnedAboutTextSelection = false, TextSelection, TextBookmark = class TextBookmark2 {
104830
104830
  constructor(anchor, head) {
104831
104831
  this.anchor = anchor;
104832
104832
  this.head = head;
@@ -104835,7 +104835,7 @@ var isRegExp = (value) => {
104835
104835
  return new TextBookmark2(mapping.map(this.anchor), mapping.map(this.head));
104836
104836
  }
104837
104837
  resolve(doc$2) {
104838
- return TextSelection2.between(doc$2.resolve(this.anchor), doc$2.resolve(this.head));
104838
+ return TextSelection.between(doc$2.resolve(this.anchor), doc$2.resolve(this.head));
104839
104839
  }
104840
104840
  }, NodeSelection, NodeBookmark = class NodeBookmark2 {
104841
104841
  constructor(anchor) {
@@ -109287,7 +109287,7 @@ var isRegExp = (value) => {
109287
109287
  return false;
109288
109288
  return group.split(" ").includes("list");
109289
109289
  }, isTextSelection = (value) => {
109290
- return value instanceof TextSelection2;
109290
+ return value instanceof TextSelection;
109291
109291
  }, domIndex = function(node3) {
109292
109292
  for (var index2 = 0;; index2++) {
109293
109293
  node3 = node3.previousSibling;
@@ -133399,7 +133399,7 @@ var init_SuperConverter_BgwP1GeS_es = __esm(() => {
133399
133399
  TransformError.prototype.name = "TransformError";
133400
133400
  classesById = Object.create(null);
133401
133401
  Selection.prototype.visible = true;
133402
- TextSelection2 = class TextSelection3 extends Selection {
133402
+ TextSelection = class TextSelection2 extends Selection {
133403
133403
  constructor($anchor, $head = $anchor) {
133404
133404
  checkTextSelection($anchor);
133405
133405
  checkTextSelection($head);
@@ -133413,7 +133413,7 @@ var init_SuperConverter_BgwP1GeS_es = __esm(() => {
133413
133413
  if (!$head.parent.inlineContent)
133414
133414
  return Selection.near($head);
133415
133415
  let $anchor = doc$2.resolve(mapping.map(this.anchor));
133416
- return new TextSelection3($anchor.parent.inlineContent ? $anchor : $head, $head);
133416
+ return new TextSelection2($anchor.parent.inlineContent ? $anchor : $head, $head);
133417
133417
  }
133418
133418
  replace(tr, content$2 = Slice.empty) {
133419
133419
  super.replace(tr, content$2);
@@ -133424,7 +133424,7 @@ var init_SuperConverter_BgwP1GeS_es = __esm(() => {
133424
133424
  }
133425
133425
  }
133426
133426
  eq(other) {
133427
- return other instanceof TextSelection3 && other.anchor == this.anchor && other.head == this.head;
133427
+ return other instanceof TextSelection2 && other.anchor == this.anchor && other.head == this.head;
133428
133428
  }
133429
133429
  getBookmark() {
133430
133430
  return new TextBookmark(this.anchor, this.head);
@@ -133439,7 +133439,7 @@ var init_SuperConverter_BgwP1GeS_es = __esm(() => {
133439
133439
  static fromJSON(doc$2, json) {
133440
133440
  if (typeof json.anchor != "number" || typeof json.head != "number")
133441
133441
  throw new RangeError("Invalid input for TextSelection.fromJSON");
133442
- return new TextSelection3(doc$2.resolve(json.anchor), doc$2.resolve(json.head));
133442
+ return new TextSelection2(doc$2.resolve(json.anchor), doc$2.resolve(json.head));
133443
133443
  }
133444
133444
  static create(doc$2, anchor, head = anchor) {
133445
133445
  let $anchor = doc$2.resolve(anchor);
@@ -133464,10 +133464,10 @@ var init_SuperConverter_BgwP1GeS_es = __esm(() => {
133464
133464
  if ($anchor.pos < $head.pos != dPos < 0)
133465
133465
  $anchor = $head;
133466
133466
  }
133467
- return new TextSelection3($anchor, $head);
133467
+ return new TextSelection2($anchor, $head);
133468
133468
  }
133469
133469
  };
133470
- Selection.jsonID("text", TextSelection2);
133470
+ Selection.jsonID("text", TextSelection);
133471
133471
  NodeSelection = class NodeSelection2 extends Selection {
133472
133472
  constructor($pos) {
133473
133473
  let node3 = $pos.nodeAfter;
@@ -145118,7 +145118,7 @@ var init_SuperConverter_BgwP1GeS_es = __esm(() => {
145118
145118
  }
145119
145119
  localCompositionInfo(view, pos) {
145120
145120
  let { from: from4, to } = view.state.selection;
145121
- if (!(view.state.selection instanceof TextSelection2) || from4 < pos || to > pos + this.node.content.size)
145121
+ if (!(view.state.selection instanceof TextSelection) || from4 < pos || to > pos + this.node.content.size)
145122
145122
  return null;
145123
145123
  let textNode = view.input.compositionNode;
145124
145124
  if (!textNode || !this.dom.contains(textNode.parentNode))
@@ -145380,7 +145380,7 @@ var init_SuperConverter_BgwP1GeS_es = __esm(() => {
145380
145380
  return;
145381
145381
  }
145382
145382
  let sel = view.state.selection;
145383
- if (!(sel instanceof TextSelection2) || !sel.$from.sameParent(sel.$to)) {
145383
+ if (!(sel instanceof TextSelection) || !sel.$from.sameParent(sel.$to)) {
145384
145384
  let text$2 = String.fromCharCode(event.charCode);
145385
145385
  let deflt = () => view.state.tr.insertText(text$2).scrollIntoView();
145386
145386
  if (!/[\r\n]/.test(text$2) && !view.someProp("handleTextInput", (f2) => f2(view, sel.$from.pos, sel.$to.pos, text$2, deflt)))
@@ -145434,7 +145434,7 @@ var init_SuperConverter_BgwP1GeS_es = __esm(() => {
145434
145434
  if (!view.composing) {
145435
145435
  view.domObserver.flush();
145436
145436
  let { state } = view, $pos = state.selection.$to;
145437
- if (state.selection instanceof TextSelection2 && (state.storedMarks || !$pos.textOffset && $pos.parentOffset && $pos.nodeBefore.marks.some((m) => m.type.spec.inclusive === false) || chrome && windows$1 && selectionBeforeUneditable(view))) {
145437
+ if (state.selection instanceof TextSelection && (state.storedMarks || !$pos.textOffset && $pos.parentOffset && $pos.nodeBefore.marks.some((m) => m.type.spec.inclusive === false) || chrome && windows$1 && selectionBeforeUneditable(view))) {
145438
145438
  view.markCursor = view.state.storedMarks || $pos.marks();
145439
145439
  endComposition(view, true);
145440
145440
  view.markCursor = null;
@@ -145767,7 +145767,7 @@ var init_SuperConverter_BgwP1GeS_es = __esm(() => {
145767
145767
  else
145768
145768
  return new CellSelection$1($anchorCell, $headCell);
145769
145769
  }
145770
- return TextSelection2.between($anchorCell, $headCell);
145770
+ return TextSelection.between($anchorCell, $headCell);
145771
145771
  }
145772
145772
  content() {
145773
145773
  const table = this.$anchorCell.node(-1);
@@ -154465,7 +154465,7 @@ var init_SuperConverter_BgwP1GeS_es = __esm(() => {
154465
154465
  };
154466
154466
  });
154467
154467
 
154468
- // ../../packages/superdoc/dist/chunks/create-headless-toolbar-zEz71NHQ.es.js
154468
+ // ../../packages/superdoc/dist/chunks/create-headless-toolbar-Dcw4Hyt2.es.js
154469
154469
  function parseSizeUnit(val = "0") {
154470
154470
  const length3 = val.toString() || "0";
154471
154471
  const value = Number.parseFloat(length3);
@@ -154476,7 +154476,7 @@ function getPreservedSelection(state) {
154476
154476
  return CustomSelectionPluginKey.getState(state)?.preservedSelection ?? null;
154477
154477
  }
154478
154478
  function createSelectionTrackingBookmark(selection) {
154479
- if (selection instanceof TextSelection2 && !selection.empty)
154479
+ if (selection instanceof TextSelection && !selection.empty)
154480
154480
  return new InclusiveTextSelectionBookmark(selection.anchor, selection.head);
154481
154481
  return selection.getBookmark();
154482
154482
  }
@@ -154763,7 +154763,7 @@ var CSS_DIMENSION_REGEX, DOM_SIZE_UNITS, Extension = class Extension2 {
154763
154763
  return new InclusiveTextSelectionBookmark2(mapping.map(this.anchor, isForward ? -1 : 1), mapping.map(this.head, isForward ? 1 : -1));
154764
154764
  }
154765
154765
  resolve(doc2) {
154766
- return TextSelection2.between(doc2.resolve(this.anchor), doc2.resolve(this.head));
154766
+ return TextSelection.between(doc2.resolve(this.anchor), doc2.resolve(this.head));
154767
154767
  }
154768
154768
  }, nextHandleId = 1, SelectionHandlePluginKey, DEFAULT_MIME_TYPE = "application/octet-stream", simpleHash2 = (str) => {
154769
154769
  let hash = 0;
@@ -156065,6 +156065,246 @@ var CSS_DIMENSION_REGEX, DOM_SIZE_UNITS, Extension = class Extension2 {
156065
156065
  comment: change.comment ?? null
156066
156066
  }) !== false;
156067
156067
  });
156068
+ }, resolveSurface = (activeEditor) => {
156069
+ if (activeEditor?.options?.isHeaderOrFooter) {
156070
+ const headerFooterType = activeEditor.options?.headerFooterType;
156071
+ if (headerFooterType === "footer")
156072
+ return "footer";
156073
+ if (headerFooterType === "header")
156074
+ return "header";
156075
+ }
156076
+ return "body";
156077
+ }, resolveSelectionEmpty = (editor) => {
156078
+ return editor.state?.selection?.empty ?? true;
156079
+ }, createEditorToolbarTarget = (editor) => {
156080
+ return {
156081
+ commands: editor.commands ?? {},
156082
+ doc: editor.doc
156083
+ };
156084
+ }, createPresentationToolbarTarget = (editor) => {
156085
+ return {
156086
+ commands: editor.commands ?? {},
156087
+ doc: editor.getActiveEditor()?.doc
156088
+ };
156089
+ }, resolvePresentationEditor = (superdoc) => {
156090
+ const documentId = superdoc.activeEditor?.options?.documentId;
156091
+ if (!documentId)
156092
+ return null;
156093
+ return (superdoc.superdocStore?.documents ?? []).find((doc2) => doc2.getEditor?.()?.options?.documentId === documentId)?.getPresentationEditor?.() ?? null;
156094
+ }, resolveToolbarSources = (superdoc) => {
156095
+ const presentationEditor = resolvePresentationEditor(superdoc);
156096
+ if (presentationEditor) {
156097
+ const routedEditor = presentationEditor.getActiveEditor();
156098
+ return {
156099
+ activeEditor: routedEditor ?? null,
156100
+ presentationEditor,
156101
+ context: {
156102
+ target: createPresentationToolbarTarget(presentationEditor),
156103
+ surface: resolveSurface(routedEditor),
156104
+ isEditable: presentationEditor.isEditable,
156105
+ selectionEmpty: resolveSelectionEmpty(presentationEditor),
156106
+ editor: routedEditor ?? undefined,
156107
+ presentationEditor
156108
+ }
156109
+ };
156110
+ }
156111
+ const activeEditor = superdoc.activeEditor;
156112
+ if (!activeEditor)
156113
+ return {
156114
+ activeEditor: null,
156115
+ presentationEditor: null,
156116
+ context: null
156117
+ };
156118
+ return {
156119
+ activeEditor,
156120
+ presentationEditor: null,
156121
+ context: {
156122
+ target: createEditorToolbarTarget(activeEditor),
156123
+ surface: "body",
156124
+ isEditable: activeEditor.isEditable,
156125
+ selectionEmpty: resolveSelectionEmpty(activeEditor),
156126
+ editor: activeEditor
156127
+ }
156128
+ };
156129
+ }, buildCommandStateMap = ({ commands = [], superdoc, context, toolbarRegistry }) => {
156130
+ const entries2 = commands.map((command) => {
156131
+ const entry = toolbarRegistry[command];
156132
+ if (!entry)
156133
+ return [command, {
156134
+ active: false,
156135
+ disabled: true
156136
+ }];
156137
+ return [command, entry.state({
156138
+ context,
156139
+ superdoc
156140
+ })];
156141
+ });
156142
+ return Object.fromEntries(entries2);
156143
+ }, createToolbarSnapshot = ({ superdoc, commands = [], toolbarRegistry }) => {
156144
+ const { context } = resolveToolbarSources(superdoc);
156145
+ return {
156146
+ context,
156147
+ commands: buildCommandStateMap({
156148
+ commands,
156149
+ superdoc,
156150
+ context,
156151
+ toolbarRegistry
156152
+ })
156153
+ };
156154
+ }, subscribeToSuperdocEvents = (superdoc, onChange3) => {
156155
+ if (!superdoc?.on || !superdoc?.off)
156156
+ return null;
156157
+ superdoc.on("editorCreate", onChange3);
156158
+ superdoc.on("document-mode-change", onChange3);
156159
+ superdoc.on("zoomChange", onChange3);
156160
+ return () => {
156161
+ superdoc.off?.("editorCreate", onChange3);
156162
+ superdoc.off?.("document-mode-change", onChange3);
156163
+ superdoc.off?.("zoomChange", onChange3);
156164
+ };
156165
+ }, subscribeToEditorEvents = (editor, onChange3) => {
156166
+ if (!editor?.on || !editor?.off)
156167
+ return null;
156168
+ editor.on("focus", onChange3);
156169
+ editor.on("selectionUpdate", onChange3);
156170
+ editor.on("transaction", onChange3);
156171
+ return () => {
156172
+ editor.off?.("focus", onChange3);
156173
+ editor.off?.("selectionUpdate", onChange3);
156174
+ editor.off?.("transaction", onChange3);
156175
+ };
156176
+ }, subscribeToPresentationEvents = (presentationEditor, onChange3) => {
156177
+ if (!presentationEditor?.on || !presentationEditor?.off)
156178
+ return null;
156179
+ presentationEditor.on("headerFooterEditingContext", onChange3);
156180
+ presentationEditor.on("headerFooterUpdate", onChange3);
156181
+ presentationEditor.on("headerFooterTransaction", onChange3);
156182
+ return () => {
156183
+ presentationEditor.off?.("headerFooterEditingContext", onChange3);
156184
+ presentationEditor.off?.("headerFooterUpdate", onChange3);
156185
+ presentationEditor.off?.("headerFooterTransaction", onChange3);
156186
+ };
156187
+ }, subscribeToolbarEvents = (options, onChange3) => {
156188
+ const { activeEditor: editor, presentationEditor } = resolveToolbarSources(options.superdoc);
156189
+ const unbindSuperdocEvents = subscribeToSuperdocEvents(options.superdoc, onChange3);
156190
+ const unbindEditorEvents = subscribeToEditorEvents(editor, onChange3);
156191
+ const unbindPresentationEvents = subscribeToPresentationEvents(presentationEditor, onChange3);
156192
+ return () => {
156193
+ unbindEditorEvents?.();
156194
+ unbindPresentationEvents?.();
156195
+ unbindSuperdocEvents?.();
156196
+ };
156197
+ }, resolveStateEditor = (context) => {
156198
+ if (!context)
156199
+ return null;
156200
+ return context.editor ?? context.presentationEditor?.getActiveEditor() ?? null;
156201
+ }, getCurrentParagraphParent = (context) => {
156202
+ const stateEditor = resolveStateEditor(context);
156203
+ const selection = stateEditor?.state?.selection;
156204
+ if (!stateEditor || !selection)
156205
+ return null;
156206
+ return findParentNode((node3) => node3.type.name === "paragraph")(selection);
156207
+ }, getCurrentResolvedParagraphProperties = (context) => {
156208
+ const paragraphParent = getCurrentParagraphParent(context);
156209
+ const stateEditor = resolveStateEditor(context);
156210
+ if (!stateEditor || !paragraphParent)
156211
+ return null;
156212
+ return calculateResolvedParagraphProperties(stateEditor, paragraphParent.node, stateEditor.state.doc.resolve(paragraphParent.pos));
156213
+ }, isFieldAnnotationSelection = (context) => {
156214
+ const selection = resolveStateEditor(context)?.state?.selection;
156215
+ return selection instanceof NodeSelection && selection?.node?.type?.name === "fieldAnnotation";
156216
+ }, isCommandDisabled = (context) => {
156217
+ if (!context || !context.isEditable)
156218
+ return true;
156219
+ return (context.presentationEditor?.editor ?? context.editor)?.options?.documentMode === "viewing";
156220
+ }, createDisabledStateDeriver = (options) => ({ context }) => {
156221
+ const disabled = isCommandDisabled(context);
156222
+ if (options?.withValue)
156223
+ return {
156224
+ active: false,
156225
+ disabled,
156226
+ value: null
156227
+ };
156228
+ return {
156229
+ active: false,
156230
+ disabled
156231
+ };
156232
+ }, createDirectCommandExecute = (commandName) => ({ context, payload }) => {
156233
+ const editor = resolveStateEditor(context);
156234
+ const command = commandName ? editor?.commands[commandName] : null;
156235
+ if (typeof command !== "function")
156236
+ return false;
156237
+ const result = payload === undefined ? command() : command(payload);
156238
+ return Boolean(result);
156239
+ }, getCurrentUndoDepth = (context) => {
156240
+ const stateEditor = resolveStateEditor(context);
156241
+ if (!stateEditor?.state)
156242
+ return 0;
156243
+ try {
156244
+ if (stateEditor.options?.ydoc)
156245
+ return yUndoPluginKey.getState(stateEditor.state)?.undoManager?.undoStack?.length ?? 0;
156246
+ return undoDepth(stateEditor.state);
156247
+ } catch {
156248
+ return 0;
156249
+ }
156250
+ }, getCurrentRedoDepth = (context) => {
156251
+ const stateEditor = resolveStateEditor(context);
156252
+ if (!stateEditor?.state)
156253
+ return 0;
156254
+ try {
156255
+ if (stateEditor.options?.ydoc)
156256
+ return yUndoPluginKey.getState(stateEditor.state)?.undoManager?.redoStack?.length ?? 0;
156257
+ return redoDepth(stateEditor.state);
156258
+ } catch {
156259
+ return 0;
156260
+ }
156261
+ }, createHistoryStateDeriver = (kind) => ({ context }) => {
156262
+ if (isCommandDisabled(context))
156263
+ return {
156264
+ active: false,
156265
+ disabled: true
156266
+ };
156267
+ return {
156268
+ active: false,
156269
+ disabled: (kind === "undo" ? getCurrentUndoDepth(context) : getCurrentRedoDepth(context)) === 0
156270
+ };
156271
+ }, createRulerStateDeriver = () => ({ context, superdoc }) => {
156272
+ return {
156273
+ active: Boolean(superdoc?.config?.rulers),
156274
+ disabled: isCommandDisabled(context)
156275
+ };
156276
+ }, createZoomStateDeriver = () => ({ context, superdoc }) => {
156277
+ return {
156278
+ active: false,
156279
+ disabled: !context,
156280
+ value: typeof superdoc?.getZoom === "function" ? superdoc.getZoom() : 100
156281
+ };
156282
+ }, createDocumentModeStateDeriver = () => ({ context, superdoc }) => {
156283
+ return {
156284
+ active: false,
156285
+ disabled: !context,
156286
+ value: superdoc?.config?.documentMode ?? "editing"
156287
+ };
156288
+ }, createRulerExecute = () => ({ superdoc }) => {
156289
+ superdoc.toggleRuler?.();
156290
+ return true;
156291
+ }, createZoomExecute = () => ({ superdoc, payload }) => {
156292
+ const normalizedPayload = Number.parseInt(String(payload), 10);
156293
+ if (!Number.isFinite(normalizedPayload) || normalizedPayload <= 0)
156294
+ return false;
156295
+ superdoc.setZoom?.(normalizedPayload);
156296
+ return true;
156297
+ }, createDocumentModeExecute = () => ({ superdoc, payload }) => {
156298
+ const validModes = [
156299
+ "editing",
156300
+ "suggesting",
156301
+ "viewing"
156302
+ ];
156303
+ const normalizedPayload = typeof payload === "string" ? payload.toLowerCase() : payload;
156304
+ if (typeof superdoc?.setDocumentMode !== "function" || typeof normalizedPayload !== "string" || !validModes.includes(normalizedPayload))
156305
+ return false;
156306
+ superdoc.setDocumentMode(normalizedPayload);
156307
+ return true;
156068
156308
  }, isOffValue = (value) => {
156069
156309
  if (value == null)
156070
156310
  return false;
@@ -156075,8 +156315,749 @@ var CSS_DIMENSION_REGEX, DOM_SIZE_UNITS, Extension = class Extension2 {
156075
156315
  if (typeof checker !== "function")
156076
156316
  return false;
156077
156317
  return Boolean(checker(attrs));
156318
+ }, normalizeFontSizeValue = (value) => {
156319
+ if (typeof value === "number")
156320
+ return `${value}pt`;
156321
+ if (typeof value === "string") {
156322
+ const [numericValue, unit] = parseSizeUnit(value);
156323
+ if (!Number.isNaN(numericValue))
156324
+ return `${numericValue}${unit || "pt"}`;
156325
+ }
156326
+ return value;
156327
+ }, normalizeFontFamilyValue = (value) => {
156328
+ if (typeof value !== "string")
156329
+ return value;
156330
+ return value;
156331
+ }, normalizeLinkHrefValue = (value) => {
156332
+ return typeof value === "string" && value.length > 0 ? value : null;
156333
+ }, normalizeColorValue = (value) => {
156334
+ if (typeof value === "string" && value.length > 0)
156335
+ return value.toLowerCase();
156336
+ return null;
156337
+ }, isFormattingActivatedFromLinkedStyle = (context, styleKey) => {
156338
+ const stateEditor = resolveStateEditor(context);
156339
+ if (!stateEditor?.state?.selection?.$from)
156340
+ return false;
156341
+ const styleId = getCurrentResolvedParagraphProperties(context)?.styleId;
156342
+ const linkedStyle = stateEditor?.converter?.linkedStyles?.find((style) => style.id === styleId);
156343
+ return Boolean(linkedStyle?.definition?.styles && styleKey in linkedStyle.definition.styles);
156344
+ }, hasNegatedFormattingMark = (formatting, markName) => {
156345
+ const rawActiveMark = formatting.find((mark) => mark.name === markName);
156346
+ return rawActiveMark ? isNegatedMark(rawActiveMark.name, rawActiveMark.attrs) : false;
156347
+ }, createBoldStateDeriver = () => ({ context }) => {
156348
+ const stateEditor = resolveStateEditor(context);
156349
+ const formatting = stateEditor ? getActiveFormatting(stateEditor) : [];
156350
+ if (isCommandDisabled(context))
156351
+ return {
156352
+ active: false,
156353
+ disabled: true
156354
+ };
156355
+ const isActiveFromMark = formatting.some((mark) => mark.name === "bold");
156356
+ const markNegated = hasNegatedFormattingMark(formatting, "bold");
156357
+ const activeFromLinkedStyle = !isActiveFromMark && !markNegated ? isFormattingActivatedFromLinkedStyle(context, "bold") : false;
156358
+ return {
156359
+ active: isActiveFromMark || activeFromLinkedStyle,
156360
+ disabled: false
156361
+ };
156362
+ }, createItalicStateDeriver = () => ({ context }) => {
156363
+ const stateEditor = resolveStateEditor(context);
156364
+ const formatting = stateEditor ? getActiveFormatting(stateEditor) : [];
156365
+ if (isCommandDisabled(context))
156366
+ return {
156367
+ active: false,
156368
+ disabled: true
156369
+ };
156370
+ return {
156371
+ active: !hasNegatedFormattingMark(formatting, "italic") && formatting.some((mark) => mark.name === "italic"),
156372
+ disabled: false
156373
+ };
156374
+ }, createUnderlineStateDeriver = () => ({ context }) => {
156375
+ const stateEditor = resolveStateEditor(context);
156376
+ const formatting = stateEditor ? getActiveFormatting(stateEditor) : [];
156377
+ if (isCommandDisabled(context))
156378
+ return {
156379
+ active: false,
156380
+ disabled: true
156381
+ };
156382
+ return {
156383
+ active: !hasNegatedFormattingMark(formatting, "underline") && formatting.some((mark) => mark.name === "underline"),
156384
+ disabled: false
156385
+ };
156386
+ }, createStrikethroughStateDeriver = () => ({ context }) => {
156387
+ const stateEditor = resolveStateEditor(context);
156388
+ const formatting = stateEditor ? getActiveFormatting(stateEditor) : [];
156389
+ if (isCommandDisabled(context))
156390
+ return {
156391
+ active: false,
156392
+ disabled: true
156393
+ };
156394
+ return {
156395
+ active: !hasNegatedFormattingMark(formatting, "strike") && formatting.some((mark) => mark.name === "strike"),
156396
+ disabled: false
156397
+ };
156398
+ }, createFontSizeStateDeriver = () => ({ context }) => {
156399
+ const stateEditor = resolveStateEditor(context);
156400
+ const formatting = stateEditor ? getActiveFormatting(stateEditor) : [];
156401
+ if (isCommandDisabled(context))
156402
+ return {
156403
+ active: false,
156404
+ disabled: true,
156405
+ value: null
156406
+ };
156407
+ const normalizedValues = formatting.filter((mark) => mark.name === "fontSize").map((mark) => mark.attrs?.fontSize).filter((value$1) => value$1 != null).map((value$1) => normalizeFontSizeValue(value$1));
156408
+ const uniqueValues = [...new Set(normalizedValues)];
156409
+ const hasDirectValue = uniqueValues.length > 0;
156410
+ const canUseLinkedStyle = !hasDirectValue && isFormattingActivatedFromLinkedStyle(context, "font-size");
156411
+ const paragraphProps = canUseLinkedStyle ? getCurrentResolvedParagraphProperties(context) : null;
156412
+ const documentEditor = context?.presentationEditor?.editor ?? context?.editor ?? null;
156413
+ const linkedStyleValue = normalizeFontSizeValue((canUseLinkedStyle ? documentEditor?.converter?.linkedStyles?.find((style) => style.id === paragraphProps?.styleId) : null)?.definition?.styles?.["font-size"]) ?? null;
156414
+ const value = uniqueValues.length === 1 ? uniqueValues[0] : linkedStyleValue;
156415
+ return {
156416
+ active: hasDirectValue || linkedStyleValue != null,
156417
+ disabled: false,
156418
+ value
156419
+ };
156420
+ }, createFontFamilyStateDeriver = () => ({ context }) => {
156421
+ const stateEditor = resolveStateEditor(context);
156422
+ const formatting = stateEditor ? getActiveFormatting(stateEditor) : [];
156423
+ if (isCommandDisabled(context))
156424
+ return {
156425
+ active: false,
156426
+ disabled: true,
156427
+ value: null
156428
+ };
156429
+ const normalizedValues = formatting.filter((mark) => mark.name === "fontFamily").map((mark) => mark.attrs?.fontFamily).filter((value$1) => value$1 != null).map((value$1) => normalizeFontFamilyValue(value$1));
156430
+ const uniqueValues = [...new Set(normalizedValues)];
156431
+ const canUseLinkedStyle = !(uniqueValues.length > 0) && isFormattingActivatedFromLinkedStyle(context, "font-family");
156432
+ const paragraphProps = canUseLinkedStyle ? getCurrentResolvedParagraphProperties(context) : null;
156433
+ const documentEditor = context?.presentationEditor?.editor ?? context?.editor ?? null;
156434
+ const linkedStyleValue = normalizeFontFamilyValue((canUseLinkedStyle ? documentEditor?.converter?.linkedStyles?.find((style) => style.id === paragraphProps?.styleId) : null)?.definition?.styles?.["font-family"]) ?? null;
156435
+ const value = uniqueValues.length === 1 ? uniqueValues[0] : linkedStyleValue;
156436
+ return {
156437
+ active: uniqueValues.length > 0 || linkedStyleValue != null,
156438
+ disabled: false,
156439
+ value
156440
+ };
156441
+ }, createTextColorStateDeriver = () => ({ context }) => {
156442
+ const stateEditor = resolveStateEditor(context);
156443
+ const formatting = stateEditor ? getActiveFormatting(stateEditor) : [];
156444
+ if (isCommandDisabled(context))
156445
+ return {
156446
+ active: false,
156447
+ disabled: true,
156448
+ value: null
156449
+ };
156450
+ const values = formatting.filter((mark) => mark.name === "color").map((mark) => mark.attrs?.color).filter((value$1) => value$1 != null);
156451
+ const markNegated = hasNegatedFormattingMark(formatting, "color");
156452
+ const normalizedValues = values.map((value$1) => normalizeColorValue(value$1));
156453
+ const uniqueValues = [...new Set(normalizedValues)];
156454
+ const value = uniqueValues.length === 1 ? uniqueValues[0] : null;
156455
+ return {
156456
+ active: !markNegated && uniqueValues.length > 0,
156457
+ disabled: false,
156458
+ value
156459
+ };
156460
+ }, createHighlightColorStateDeriver = () => ({ context }) => {
156461
+ const stateEditor = resolveStateEditor(context);
156462
+ const formatting = stateEditor ? getActiveFormatting(stateEditor) : [];
156463
+ if (isCommandDisabled(context))
156464
+ return {
156465
+ active: false,
156466
+ disabled: true,
156467
+ value: null
156468
+ };
156469
+ const values = formatting.filter((mark) => mark.name === "highlight").map((mark) => mark.attrs?.color).filter((value$1) => value$1 != null);
156470
+ const markNegated = hasNegatedFormattingMark(formatting, "highlight");
156471
+ const normalizedValues = values.map((value$1) => normalizeColorValue(value$1));
156472
+ const uniqueValues = [...new Set(normalizedValues)];
156473
+ const value = uniqueValues.length === 1 ? uniqueValues[0] : null;
156474
+ return {
156475
+ active: !markNegated && uniqueValues.length > 0,
156476
+ disabled: false,
156477
+ value
156478
+ };
156479
+ }, createLinkStateDeriver = () => ({ context }) => {
156480
+ const stateEditor = resolveStateEditor(context);
156481
+ const formatting = stateEditor ? getActiveFormatting(stateEditor) : [];
156482
+ if (isCommandDisabled(context))
156483
+ return {
156484
+ active: false,
156485
+ disabled: true,
156486
+ value: null
156487
+ };
156488
+ const normalizedValues = formatting.filter((mark) => mark.name === "link").map((mark) => mark.attrs?.href).filter((value$1) => value$1 != null).map((value$1) => normalizeLinkHrefValue(value$1));
156489
+ const uniqueValues = [...new Set(normalizedValues)];
156490
+ const value = uniqueValues.length === 1 ? uniqueValues[0] : null;
156491
+ return {
156492
+ active: uniqueValues.length > 0,
156493
+ disabled: false,
156494
+ value
156495
+ };
156496
+ }, createBoldExecute = () => ({ context, payload }) => {
156497
+ const editor = resolveStateEditor(context);
156498
+ if (isFieldAnnotationSelection(context)) {
156499
+ editor?.commands?.toggleFieldAnnotationsFormat?.("bold", true);
156500
+ return true;
156501
+ }
156502
+ if (!createDirectCommandExecute("toggleBold")({
156503
+ context,
156504
+ payload
156505
+ }))
156506
+ return false;
156507
+ editor?.commands?.toggleFieldAnnotationsFormat?.("bold", true);
156508
+ return true;
156509
+ }, createItalicExecute = () => ({ context, payload }) => {
156510
+ const editor = resolveStateEditor(context);
156511
+ if (isFieldAnnotationSelection(context)) {
156512
+ editor?.commands?.toggleFieldAnnotationsFormat?.("italic", true);
156513
+ return true;
156514
+ }
156515
+ if (!createDirectCommandExecute("toggleItalic")({
156516
+ context,
156517
+ payload
156518
+ }))
156519
+ return false;
156520
+ editor?.commands?.toggleFieldAnnotationsFormat?.("italic", true);
156521
+ return true;
156522
+ }, createUnderlineExecute = () => ({ context, payload }) => {
156523
+ const editor = resolveStateEditor(context);
156524
+ if (isFieldAnnotationSelection(context)) {
156525
+ editor?.commands?.toggleFieldAnnotationsFormat?.("underline", true);
156526
+ return true;
156527
+ }
156528
+ if (!createDirectCommandExecute("toggleUnderline")({
156529
+ context,
156530
+ payload
156531
+ }))
156532
+ return false;
156533
+ editor?.commands?.toggleFieldAnnotationsFormat?.("underline", true);
156534
+ return true;
156535
+ }, createFontSizeExecute = () => ({ context, payload }) => {
156536
+ if (payload === undefined)
156537
+ return false;
156538
+ const editor = resolveStateEditor(context);
156539
+ if (isFieldAnnotationSelection(context)) {
156540
+ editor?.commands?.setFieldAnnotationsFontSize?.(payload, true);
156541
+ return true;
156542
+ }
156543
+ if (!createDirectCommandExecute("setFontSize")({
156544
+ context,
156545
+ payload
156546
+ }))
156547
+ return false;
156548
+ editor?.commands?.setFieldAnnotationsFontSize?.(payload, true);
156549
+ return true;
156550
+ }, createFontFamilyExecute = () => ({ context, payload }) => {
156551
+ if (payload === undefined)
156552
+ return false;
156553
+ const editor = resolveStateEditor(context);
156554
+ if (isFieldAnnotationSelection(context)) {
156555
+ editor?.commands?.setFieldAnnotationsFontFamily?.(payload, true);
156556
+ return true;
156557
+ }
156558
+ if (!createDirectCommandExecute("setFontFamily")({
156559
+ context,
156560
+ payload
156561
+ }))
156562
+ return false;
156563
+ editor?.commands?.setFieldAnnotationsFontFamily?.(payload, true);
156564
+ return true;
156565
+ }, createTextColorExecute = () => ({ context, payload }) => {
156566
+ const editor = resolveStateEditor(context);
156567
+ if (typeof payload !== "string" || payload.length === 0)
156568
+ return false;
156569
+ const isNone = payload === "none";
156570
+ const inlineValue = isNone ? "inherit" : payload;
156571
+ const result = createDirectCommandExecute("setColor")({
156572
+ context,
156573
+ payload: inlineValue
156574
+ });
156575
+ editor?.commands?.setFieldAnnotationsTextColor?.(isNone ? null : payload, true);
156576
+ return result;
156577
+ }, createHighlightColorExecute = () => ({ context, payload }) => {
156578
+ const editor = resolveStateEditor(context);
156579
+ if (typeof payload !== "string" || payload.length === 0)
156580
+ return false;
156581
+ const isNone = payload === "none";
156582
+ const inlineValue = isNone ? "transparent" : payload;
156583
+ const result = createDirectCommandExecute("setHighlight")({
156584
+ context,
156585
+ payload: inlineValue
156586
+ });
156587
+ const argValue = isNone ? null : payload;
156588
+ editor?.commands?.setFieldAnnotationsTextHighlight?.(argValue, true);
156589
+ editor?.commands?.setCellBackground?.(argValue);
156590
+ return result;
156591
+ }, applyLinkPostExecute = (editor) => {
156592
+ const { view } = editor;
156593
+ let selection = view.state.selection;
156594
+ if (editor.options?.isHeaderOrFooter && editor.options?.lastSelection)
156595
+ selection = editor.options.lastSelection;
156596
+ const endPos = selection?.$to?.pos;
156597
+ if (typeof endPos !== "number")
156598
+ return;
156599
+ try {
156600
+ const newSelection = new TextSelection(view.state.doc.resolve(endPos));
156601
+ const tr = view.state.tr.setSelection(newSelection);
156602
+ const state = view.state.apply(tr);
156603
+ view.updateState(state);
156604
+ if (!editor.options?.isHeaderOrFooter)
156605
+ setTimeout(() => {
156606
+ view.focus();
156607
+ }, 100);
156608
+ } catch {
156609
+ return;
156610
+ }
156611
+ }, createLinkExecute = () => ({ context, payload }) => {
156612
+ const editor = resolveStateEditor(context);
156613
+ const result = createDirectCommandExecute("toggleLink")({
156614
+ context,
156615
+ payload
156616
+ });
156617
+ if (!result || !editor?.view)
156618
+ return result;
156619
+ applyLinkPostExecute(editor);
156620
+ return true;
156621
+ }, createImageExecute = () => ({ context }) => {
156622
+ const editor = resolveStateEditor(context);
156623
+ if (!editor?.view)
156624
+ return false;
156625
+ getFileOpener()().then(async (result) => {
156626
+ if (!result?.file)
156627
+ return;
156628
+ await processAndInsertImageFile({
156629
+ file: result.file,
156630
+ editor,
156631
+ view: editor.view,
156632
+ editorOptions: editor.options,
156633
+ getMaxContentSize: () => editor.getMaxContentSize()
156634
+ });
156635
+ }).catch((err) => {
156636
+ const originalError = err instanceof Error ? err : new Error(String(err));
156637
+ const error3 = /* @__PURE__ */ new Error(`[headless-toolbar] Image insertion failed: ${originalError.message}`);
156638
+ editor?.emit?.("exception", {
156639
+ error: error3,
156640
+ editor
156641
+ });
156642
+ console.error(error3, originalError);
156643
+ });
156644
+ return true;
156645
+ }, getCurrentParagraphJustification = (context) => {
156646
+ const justification = getCurrentResolvedParagraphProperties(context)?.justification ?? null;
156647
+ if (justification === "both")
156648
+ return "justify";
156649
+ return justification;
156650
+ }, createTextAlignStateDeriver = () => ({ context }) => {
156651
+ if (isCommandDisabled(context))
156652
+ return {
156653
+ active: false,
156654
+ disabled: true,
156655
+ value: null
156656
+ };
156657
+ const value = getCurrentParagraphJustification(context) ?? null;
156658
+ return {
156659
+ active: value != null,
156660
+ disabled: false,
156661
+ value
156662
+ };
156663
+ }, createLineHeightStateDeriver = () => ({ context }) => {
156664
+ if (isCommandDisabled(context))
156665
+ return {
156666
+ active: false,
156667
+ disabled: true,
156668
+ value: null
156669
+ };
156670
+ const line = getCurrentResolvedParagraphProperties(context)?.spacing?.line;
156671
+ const value = line != null ? twipsToLines(line) : null;
156672
+ return {
156673
+ active: value != null,
156674
+ disabled: false,
156675
+ value
156676
+ };
156677
+ }, createLinkedStyleStateDeriver = () => ({ context }) => {
156678
+ const isDisabled = isCommandDisabled(context);
156679
+ const stateEditor = resolveStateEditor(context);
156680
+ if (isDisabled || !stateEditor)
156681
+ return {
156682
+ active: false,
156683
+ disabled: true,
156684
+ value: null
156685
+ };
156686
+ if (!getQuickFormatList(stateEditor).length)
156687
+ return {
156688
+ active: false,
156689
+ disabled: true,
156690
+ value: null
156691
+ };
156692
+ const value = getCurrentResolvedParagraphProperties(context)?.styleId ?? null;
156693
+ return {
156694
+ active: value != null,
156695
+ disabled: false,
156696
+ value
156697
+ };
156698
+ }, createListStateDeriver = (numberingType) => ({ context }) => {
156699
+ if (isCommandDisabled(context))
156700
+ return {
156701
+ active: false,
156702
+ disabled: true
156703
+ };
156704
+ const paragraphNode = getCurrentParagraphParent(context)?.node ?? null;
156705
+ const paragraphProperties = getCurrentResolvedParagraphProperties(context);
156706
+ const activeNumberingType = isList(paragraphNode) || Boolean(paragraphProperties?.numberingProperties && paragraphNode?.attrs?.listRendering) ? paragraphNode?.attrs?.listRendering?.numberingType : null;
156707
+ return {
156708
+ active: numberingType === "bullet" ? activeNumberingType === "bullet" : activeNumberingType != null && activeNumberingType !== "bullet",
156709
+ disabled: false
156710
+ };
156711
+ }, createIndentIncreaseExecute = () => ({ context }) => {
156712
+ if (resolveStateEditor(context)?.commands?.increaseListIndent?.())
156713
+ return true;
156714
+ return createDirectCommandExecute("increaseTextIndent")({ context });
156715
+ }, createIndentDecreaseExecute = () => ({ context }) => {
156716
+ if (resolveStateEditor(context)?.commands?.decreaseListIndent?.())
156717
+ return true;
156718
+ return createDirectCommandExecute("decreaseTextIndent")({ context });
156719
+ }, createTableActionsStateDeriver = () => ({ context }) => {
156720
+ const editor = resolveStateEditor(context);
156721
+ const inTable = editor?.state?.selection?.$head ? isInTable(editor.state) : false;
156722
+ return {
156723
+ active: false,
156724
+ disabled: isCommandDisabled(context) || !inTable
156725
+ };
156726
+ }, enrichTrackedChanges = (trackedChanges = [], superdoc) => {
156727
+ if (!trackedChanges.length)
156728
+ return trackedChanges;
156729
+ const store = superdoc?.commentsStore;
156730
+ if (!store?.getComment)
156731
+ return trackedChanges;
156732
+ return trackedChanges.map((change) => {
156733
+ const commentId = change.id;
156734
+ if (!commentId)
156735
+ return change;
156736
+ const storeComment = store.getComment(commentId);
156737
+ if (!storeComment)
156738
+ return change;
156739
+ const comment = typeof storeComment.getValues === "function" ? storeComment.getValues() : storeComment;
156740
+ return {
156741
+ ...change,
156742
+ comment
156743
+ };
156744
+ });
156745
+ }, createTrackChangesSelectionActionStateDeriver = (action) => ({ context, superdoc }) => {
156746
+ if (isCommandDisabled(context))
156747
+ return {
156748
+ active: false,
156749
+ disabled: true
156750
+ };
156751
+ const editor = resolveStateEditor(context);
156752
+ const state = editor?.state;
156753
+ const selection = state?.selection;
156754
+ if (!editor || !state?.doc || !selection)
156755
+ return {
156756
+ active: false,
156757
+ disabled: true
156758
+ };
156759
+ const trackedChanges = enrichTrackedChanges(collectTrackedChanges({
156760
+ state,
156761
+ from: selection.from,
156762
+ to: selection.to
156763
+ }), superdoc);
156764
+ if (!trackedChanges.length)
156765
+ return {
156766
+ active: false,
156767
+ disabled: true
156768
+ };
156769
+ return {
156770
+ active: false,
156771
+ disabled: !isTrackedChangeActionAllowed({
156772
+ editor,
156773
+ action,
156774
+ trackedChanges
156775
+ })
156776
+ };
156777
+ }, createToolbarRegistry = () => {
156778
+ return {
156779
+ bold: {
156780
+ id: "bold",
156781
+ directCommandName: "toggleBold",
156782
+ state: createBoldStateDeriver(),
156783
+ execute: createBoldExecute()
156784
+ },
156785
+ italic: {
156786
+ id: "italic",
156787
+ directCommandName: "toggleItalic",
156788
+ state: createItalicStateDeriver(),
156789
+ execute: createItalicExecute()
156790
+ },
156791
+ underline: {
156792
+ id: "underline",
156793
+ directCommandName: "toggleUnderline",
156794
+ state: createUnderlineStateDeriver(),
156795
+ execute: createUnderlineExecute()
156796
+ },
156797
+ strikethrough: {
156798
+ id: "strikethrough",
156799
+ directCommandName: "toggleStrike",
156800
+ state: createStrikethroughStateDeriver()
156801
+ },
156802
+ "font-size": {
156803
+ id: "font-size",
156804
+ directCommandName: "setFontSize",
156805
+ state: createFontSizeStateDeriver(),
156806
+ execute: createFontSizeExecute()
156807
+ },
156808
+ "font-family": {
156809
+ id: "font-family",
156810
+ directCommandName: "setFontFamily",
156811
+ state: createFontFamilyStateDeriver(),
156812
+ execute: createFontFamilyExecute()
156813
+ },
156814
+ "text-color": {
156815
+ id: "text-color",
156816
+ directCommandName: "setColor",
156817
+ state: createTextColorStateDeriver(),
156818
+ execute: createTextColorExecute()
156819
+ },
156820
+ "highlight-color": {
156821
+ id: "highlight-color",
156822
+ directCommandName: "setHighlight",
156823
+ state: createHighlightColorStateDeriver(),
156824
+ execute: createHighlightColorExecute()
156825
+ },
156826
+ link: {
156827
+ id: "link",
156828
+ directCommandName: "toggleLink",
156829
+ state: createLinkStateDeriver(),
156830
+ execute: createLinkExecute()
156831
+ },
156832
+ "text-align": {
156833
+ id: "text-align",
156834
+ directCommandName: "setTextAlign",
156835
+ state: createTextAlignStateDeriver()
156836
+ },
156837
+ "line-height": {
156838
+ id: "line-height",
156839
+ directCommandName: "setLineHeight",
156840
+ state: createLineHeightStateDeriver()
156841
+ },
156842
+ "linked-style": {
156843
+ id: "linked-style",
156844
+ directCommandName: "setLinkedStyle",
156845
+ state: createLinkedStyleStateDeriver(),
156846
+ execute: createDirectCommandExecute("setLinkedStyle")
156847
+ },
156848
+ "bullet-list": {
156849
+ id: "bullet-list",
156850
+ directCommandName: "toggleBulletList",
156851
+ state: createListStateDeriver("bullet")
156852
+ },
156853
+ "numbered-list": {
156854
+ id: "numbered-list",
156855
+ directCommandName: "toggleOrderedList",
156856
+ state: createListStateDeriver("ordered")
156857
+ },
156858
+ "indent-increase": {
156859
+ id: "indent-increase",
156860
+ state: createDisabledStateDeriver(),
156861
+ execute: createIndentIncreaseExecute()
156862
+ },
156863
+ "indent-decrease": {
156864
+ id: "indent-decrease",
156865
+ state: createDisabledStateDeriver(),
156866
+ execute: createIndentDecreaseExecute()
156867
+ },
156868
+ undo: {
156869
+ id: "undo",
156870
+ directCommandName: "undo",
156871
+ state: createHistoryStateDeriver("undo")
156872
+ },
156873
+ redo: {
156874
+ id: "redo",
156875
+ directCommandName: "redo",
156876
+ state: createHistoryStateDeriver("redo")
156877
+ },
156878
+ ruler: {
156879
+ id: "ruler",
156880
+ state: createRulerStateDeriver(),
156881
+ execute: createRulerExecute()
156882
+ },
156883
+ zoom: {
156884
+ id: "zoom",
156885
+ state: createZoomStateDeriver(),
156886
+ execute: createZoomExecute()
156887
+ },
156888
+ "document-mode": {
156889
+ id: "document-mode",
156890
+ state: createDocumentModeStateDeriver(),
156891
+ execute: createDocumentModeExecute()
156892
+ },
156893
+ "clear-formatting": {
156894
+ id: "clear-formatting",
156895
+ directCommandName: "clearFormat",
156896
+ state: createDisabledStateDeriver()
156897
+ },
156898
+ "copy-format": {
156899
+ id: "copy-format",
156900
+ directCommandName: "copyFormat",
156901
+ state: createDisabledStateDeriver()
156902
+ },
156903
+ "track-changes-accept-selection": {
156904
+ id: "track-changes-accept-selection",
156905
+ directCommandName: "acceptTrackedChangeFromToolbar",
156906
+ state: createTrackChangesSelectionActionStateDeriver("accept")
156907
+ },
156908
+ "track-changes-reject-selection": {
156909
+ id: "track-changes-reject-selection",
156910
+ directCommandName: "rejectTrackedChangeFromToolbar",
156911
+ state: createTrackChangesSelectionActionStateDeriver("reject")
156912
+ },
156913
+ image: {
156914
+ id: "image",
156915
+ state: createDisabledStateDeriver(),
156916
+ execute: createImageExecute()
156917
+ },
156918
+ "table-insert": {
156919
+ id: "table-insert",
156920
+ directCommandName: "insertTable",
156921
+ state: createDisabledStateDeriver(),
156922
+ execute: createDirectCommandExecute("insertTable")
156923
+ },
156924
+ "table-add-row-before": {
156925
+ id: "table-add-row-before",
156926
+ directCommandName: "addRowBefore",
156927
+ state: createTableActionsStateDeriver()
156928
+ },
156929
+ "table-add-row-after": {
156930
+ id: "table-add-row-after",
156931
+ directCommandName: "addRowAfter",
156932
+ state: createTableActionsStateDeriver()
156933
+ },
156934
+ "table-delete-row": {
156935
+ id: "table-delete-row",
156936
+ directCommandName: "deleteRow",
156937
+ state: createTableActionsStateDeriver()
156938
+ },
156939
+ "table-add-column-before": {
156940
+ id: "table-add-column-before",
156941
+ directCommandName: "addColumnBefore",
156942
+ state: createTableActionsStateDeriver()
156943
+ },
156944
+ "table-add-column-after": {
156945
+ id: "table-add-column-after",
156946
+ directCommandName: "addColumnAfter",
156947
+ state: createTableActionsStateDeriver()
156948
+ },
156949
+ "table-delete-column": {
156950
+ id: "table-delete-column",
156951
+ directCommandName: "deleteColumn",
156952
+ state: createTableActionsStateDeriver()
156953
+ },
156954
+ "table-delete": {
156955
+ id: "table-delete",
156956
+ directCommandName: "deleteTable",
156957
+ state: createTableActionsStateDeriver()
156958
+ },
156959
+ "table-merge-cells": {
156960
+ id: "table-merge-cells",
156961
+ directCommandName: "mergeCells",
156962
+ state: createTableActionsStateDeriver()
156963
+ },
156964
+ "table-split-cell": {
156965
+ id: "table-split-cell",
156966
+ directCommandName: "splitCell",
156967
+ state: createTableActionsStateDeriver()
156968
+ },
156969
+ "table-remove-borders": {
156970
+ id: "table-remove-borders",
156971
+ directCommandName: "deleteCellAndTableBorders",
156972
+ state: createTableActionsStateDeriver()
156973
+ },
156974
+ "table-fix": {
156975
+ id: "table-fix",
156976
+ directCommandName: "fixTables",
156977
+ state: createTableActionsStateDeriver()
156978
+ }
156979
+ };
156980
+ }, executeDirectCommand = (id2, snapshot2, toolbarRegistry, payload) => {
156981
+ const commandName = toolbarRegistry[id2]?.directCommandName;
156982
+ const command = commandName ? snapshot2.context?.target?.commands?.[commandName] : null;
156983
+ if (typeof command !== "function")
156984
+ return false;
156985
+ const result = payload === undefined ? command() : command(payload);
156986
+ return typeof result === "boolean" ? result : Boolean(result);
156987
+ }, executeRegistryCommand = (id2, superdoc, snapshot2, toolbarRegistry, payload) => {
156988
+ const entry = toolbarRegistry[id2];
156989
+ if (!entry)
156990
+ return false;
156991
+ if (typeof entry.execute === "function")
156992
+ return entry.execute({
156993
+ context: snapshot2.context,
156994
+ superdoc,
156995
+ payload
156996
+ });
156997
+ return executeDirectCommand(id2, snapshot2, toolbarRegistry, payload);
156998
+ }, createHeadlessToolbar = (options) => {
156999
+ const listeners = /* @__PURE__ */ new Set;
157000
+ const toolbarRegistry = createToolbarRegistry();
157001
+ const buildSnapshot = () => {
157002
+ return createToolbarSnapshot({
157003
+ ...options,
157004
+ toolbarRegistry
157005
+ });
157006
+ };
157007
+ let snapshot2 = buildSnapshot();
157008
+ let destroyed = false;
157009
+ let unsubscribeEvents = null;
157010
+ const notifyListeners = () => {
157011
+ listeners.forEach((listener) => listener({ snapshot: snapshot2 }));
157012
+ };
157013
+ const rebindEvents = () => {
157014
+ unsubscribeEvents?.();
157015
+ unsubscribeEvents = subscribeToolbarEvents(options, handleChange);
157016
+ };
157017
+ const rebuildSnapshot = () => {
157018
+ snapshot2 = buildSnapshot();
157019
+ };
157020
+ const refreshControllerState = () => {
157021
+ rebuildSnapshot();
157022
+ rebindEvents();
157023
+ notifyListeners();
157024
+ };
157025
+ const handleChange = () => {
157026
+ if (destroyed)
157027
+ return;
157028
+ refreshControllerState();
157029
+ };
157030
+ rebindEvents();
157031
+ return {
157032
+ getSnapshot() {
157033
+ return snapshot2;
157034
+ },
157035
+ subscribe(listener) {
157036
+ if (destroyed)
157037
+ return () => {};
157038
+ listeners.add(listener);
157039
+ listener({ snapshot: snapshot2 });
157040
+ return () => {
157041
+ listeners.delete(listener);
157042
+ };
157043
+ },
157044
+ execute(id2, payload) {
157045
+ const result = executeRegistryCommand(id2, options.superdoc, snapshot2, toolbarRegistry, payload);
157046
+ if (result && !destroyed)
157047
+ refreshControllerState();
157048
+ return result;
157049
+ },
157050
+ destroy() {
157051
+ if (destroyed)
157052
+ return;
157053
+ destroyed = true;
157054
+ unsubscribeEvents?.();
157055
+ unsubscribeEvents = null;
157056
+ listeners.clear();
157057
+ }
157058
+ };
156078
157059
  };
156079
- var init_create_headless_toolbar_zEz71NHQ_es = __esm(() => {
157060
+ var init_create_headless_toolbar_Dcw4Hyt2_es = __esm(() => {
156080
157061
  init_SuperConverter_BgwP1GeS_es();
156081
157062
  init_constants_CGhJRd87_es();
156082
157063
  init_dist_B8HfvhaK_es();
@@ -204515,7 +205496,7 @@ var init_remark_gfm_eZN6yzWQ_es = __esm(() => {
204515
205496
  init_remark_gfm_BhnWr3yf_es();
204516
205497
  });
204517
205498
 
204518
- // ../../packages/superdoc/dist/chunks/src-DjgWBzME.es.js
205499
+ // ../../packages/superdoc/dist/chunks/src-DlMaB1h-.es.js
204519
205500
  function deleteProps(obj, propOrProps) {
204520
205501
  const props = typeof propOrProps === "string" ? [propOrProps] : propOrProps;
204521
205502
  const removeNested = (target, pathParts, index2 = 0) => {
@@ -205240,9 +206221,9 @@ function mapPreservedSelection(selection, tr) {
205240
206221
  function applySelectionCleanup(editor, tr) {
205241
206222
  let cleaned = tr.setMeta(CustomSelectionPluginKey, DEFAULT_SELECTION_STATE);
205242
206223
  const sel = cleaned.selection;
205243
- if (sel && sel instanceof TextSelection2 && !sel.empty)
206224
+ if (sel && sel instanceof TextSelection && !sel.empty)
205244
206225
  try {
205245
- const collapsed = TextSelection2.create(cleaned.doc, sel.head);
206226
+ const collapsed = TextSelection.create(cleaned.doc, sel.head);
205246
206227
  cleaned = cleaned.setSelection(collapsed);
205247
206228
  } catch {}
205248
206229
  editor.setOptions({
@@ -205355,7 +206336,7 @@ function arrow$1(axis, dir) {
205355
206336
  return function(state, dispatch, view) {
205356
206337
  let sel = state.selection;
205357
206338
  let $start = dir > 0 ? sel.$to : sel.$from, mustMove = sel.empty;
205358
- if (sel instanceof TextSelection2) {
206339
+ if (sel instanceof TextSelection) {
205359
206340
  if (!view.endOfTextblock(dirStr) || $start.depth == 0)
205360
206341
  return false;
205361
206342
  mustMove = false;
@@ -205395,7 +206376,7 @@ function beforeinput(view, event) {
205395
206376
  for (let i4 = insert.length - 1;i4 >= 0; i4--)
205396
206377
  frag = Fragment.from(insert[i4].createAndFill(null, frag));
205397
206378
  let tr = view.state.tr.replace($from.pos, $from.pos, new Slice(frag, 0, 0));
205398
- tr.setSelection(TextSelection2.near(tr.doc.resolve($from.pos + 1)));
206379
+ tr.setSelection(TextSelection.near(tr.doc.resolve($from.pos + 1)));
205399
206380
  view.dispatch(tr);
205400
206381
  return false;
205401
206382
  }
@@ -206282,7 +207263,7 @@ function createStructuredContentSelectPlugin(editor) {
206282
207263
  for (let od = old$pos.depth;od > 0; od--)
206283
207264
  if (old$pos.node(od).type.name === "structuredContent" && old$pos.before(od) === sdtStart)
206284
207265
  return null;
206285
- return newState.tr.setSelection(TextSelection2.create(newState.doc, contentFrom, contentTo));
207266
+ return newState.tr.setSelection(TextSelection.create(newState.doc, contentFrom, contentTo));
206286
207267
  }
206287
207268
  return null;
206288
207269
  } });
@@ -206493,7 +207474,7 @@ function splitBlockPatch(state, dispatch, editor) {
206493
207474
  }
206494
207475
  }
206495
207476
  let tr = state.tr;
206496
- if (state.selection instanceof TextSelection2 || state.selection instanceof AllSelection)
207477
+ if (state.selection instanceof TextSelection || state.selection instanceof AllSelection)
206497
207478
  tr.deleteSelection();
206498
207479
  let splitPos = tr.mapping.map($from.pos);
206499
207480
  let can = canSplit(tr.doc, splitPos, types3.length, types3);
@@ -206698,7 +207679,7 @@ function splitBlockAs(splitNode) {
206698
207679
  types3.unshift(null);
206699
207680
  }
206700
207681
  let tr = state.tr;
206701
- if (state.selection instanceof TextSelection2 || state.selection instanceof AllSelection)
207682
+ if (state.selection instanceof TextSelection || state.selection instanceof AllSelection)
206702
207683
  tr.deleteSelection();
206703
207684
  let splitPos = tr.mapping.map($from.pos);
206704
207685
  let can = canSplit(tr.doc, splitPos, types3.length, types3);
@@ -206796,7 +207777,7 @@ function selectTextblockSide(side) {
206796
207777
  if (!$pos.node(depth).isTextblock)
206797
207778
  return false;
206798
207779
  if (dispatch)
206799
- dispatch(state.tr.setSelection(TextSelection2.create(state.doc, side < 0 ? $pos.start(depth) : $pos.end(depth))));
207780
+ dispatch(state.tr.setSelection(TextSelection.create(state.doc, side < 0 ? $pos.start(depth) : $pos.end(depth))));
206800
207781
  return true;
206801
207782
  };
206802
207783
  }
@@ -207124,7 +208105,7 @@ function skipTab(dir) {
207124
208105
  return false;
207125
208106
  const nextPos = dir > 0 ? Math.min($nextPos.pos + nextNode.nodeSize + 1, state.doc.nodeSize) : Math.max(0, $nextPos.pos - nextNode.nodeSize - 1);
207126
208107
  if (dispatch)
207127
- dispatch(state.tr.setSelection(TextSelection2.create(state.doc, nextPos)));
208108
+ dispatch(state.tr.setSelection(TextSelection.create(state.doc, nextPos)));
207128
208109
  return true;
207129
208110
  };
207130
208111
  }
@@ -208844,7 +209825,7 @@ function getTableBoundaryExitSelection(state, dir) {
208844
209825
  const boundaryPos = helpers.getTableBoundaryPos(context);
208845
209826
  const targetPos = helpers.findTextPosAcrossBoundary(state, boundaryPos);
208846
209827
  if (targetPos != null)
208847
- return TextSelection2.create(state.doc, targetPos);
209828
+ return TextSelection.create(state.doc, targetPos);
208848
209829
  return findSelectionNearBoundary(state, boundaryPos, dir);
208849
209830
  }
208850
209831
  function getAdjacentTableEntrySelection(state, dir) {
@@ -208865,13 +209846,13 @@ function getAdjacentTableEntrySelection(state, dir) {
208865
209846
  if (dir > 0) {
208866
209847
  const targetPos$1 = findFirstTextPosInNode(adjacentNode, boundaryPos);
208867
209848
  if (targetPos$1 != null)
208868
- return TextSelection2.create(state.doc, targetPos$1);
209849
+ return TextSelection.create(state.doc, targetPos$1);
208869
209850
  return findSelectionNearBoundary(state, boundaryPos, 1);
208870
209851
  }
208871
209852
  const tablePos = boundaryPos - adjacentNode.nodeSize;
208872
209853
  const targetPos = findLastTextPosInNode(adjacentNode, tablePos);
208873
209854
  if (targetPos != null)
208874
- return TextSelection2.create(state.doc, targetPos);
209855
+ return TextSelection.create(state.doc, targetPos);
208875
209856
  return findSelectionNearBoundary(state, tablePos + adjacentNode.nodeSize, -1);
208876
209857
  }
208877
209858
  function createTableBoundaryNavigationPlugin() {
@@ -209215,7 +210196,7 @@ function insertRowAtIndex({ tr, tablePos, tableNode, sourceRowIndex, insertIndex
209215
210196
  if (newRow) {
209216
210197
  tr.insert(insertPos, newRow);
209217
210198
  const cursorPos = insertPos + ROW_START_TO_TEXT_OFFSET;
209218
- tr.setSelection(TextSelection2.create(tr.doc, cursorPos));
210199
+ tr.setSelection(TextSelection.create(tr.doc, cursorPos));
209219
210200
  const firstTextNode = newCells[0].firstChild?.firstChild;
209220
210201
  if (firstTextNode?.marks?.length)
209221
210202
  tr.setStoredMarks(firstTextNode.marks);
@@ -209224,7 +210205,7 @@ function insertRowAtIndex({ tr, tablePos, tableNode, sourceRowIndex, insertIndex
209224
210205
  }
209225
210206
  } else if (cellsToExtend.length > 0) {
209226
210207
  const cursorPos = cellsToExtend[0].pos + CELL_TO_TEXT_OFFSET;
209227
- tr.setSelection(TextSelection2.create(tr.doc, cursorPos));
210208
+ tr.setSelection(TextSelection.create(tr.doc, cursorPos));
209228
210209
  }
209229
210210
  return true;
209230
210211
  }
@@ -212955,7 +213936,7 @@ function findCommand(wrap5, dir) {
212955
213936
  let next2 = dir > 0 ? nextMatch(search$1, state, wrap5, from$1, to) : prevMatch(search$1, state, wrap5, from$1, to);
212956
213937
  if (!next2)
212957
213938
  return false;
212958
- let selection = TextSelection2.create(state.doc, next2.from, next2.to);
213939
+ let selection = TextSelection.create(state.doc, next2.from, next2.to);
212959
213940
  if (dispatch)
212960
213941
  dispatch(state.tr.setSelection(selection).scrollIntoView());
212961
213942
  return true;
@@ -212980,14 +213961,14 @@ function replaceCommand(wrap5, moveForward) {
212980
213961
  }
212981
213962
  let after2 = moveForward && nextMatch(search$1, state, wrap5, next2.from, next2.to);
212982
213963
  if (after2)
212983
- tr.setSelection(TextSelection2.create(tr.doc, tr.mapping.map(after2.from, 1), tr.mapping.map(after2.to, -1)));
213964
+ tr.setSelection(TextSelection.create(tr.doc, tr.mapping.map(after2.from, 1), tr.mapping.map(after2.to, -1)));
212984
213965
  else
212985
- tr.setSelection(TextSelection2.create(tr.doc, next2.from, tr.mapping.map(next2.to, 1)));
213966
+ tr.setSelection(TextSelection.create(tr.doc, next2.from, tr.mapping.map(next2.to, 1)));
212986
213967
  dispatch(tr.scrollIntoView());
212987
213968
  } else if (!moveForward)
212988
213969
  return false;
212989
213970
  else
212990
- dispatch(state.tr.setSelection(TextSelection2.create(state.doc, next2.from, next2.to)).scrollIntoView());
213971
+ dispatch(state.tr.setSelection(TextSelection.create(state.doc, next2.from, next2.to)).scrollIntoView());
212991
213972
  return true;
212992
213973
  };
212993
213974
  }
@@ -213057,9 +214038,9 @@ function buildSelection(state, pos, extend) {
213057
214038
  const clamped = Math.max(0, Math.min(pos, doc$12.content.size));
213058
214039
  if (extend) {
213059
214040
  const anchor = selection.anchor ?? selection.from;
213060
- return TextSelection2.create(doc$12, anchor, clamped);
214041
+ return TextSelection.create(doc$12, anchor, clamped);
213061
214042
  }
213062
- return TextSelection2.create(doc$12, clamped);
214043
+ return TextSelection.create(doc$12, clamped);
213063
214044
  }
213064
214045
  function findLineElementAtPoint(doc$12, x, y$1) {
213065
214046
  if (typeof doc$12?.elementsFromPoint !== "function")
@@ -216221,13 +217202,6 @@ function scrollToElement(targetElement, options = {
216221
217202
  behavior: options.behavior
216222
217203
  });
216223
217204
  }
216224
- function getParagraphFontFamilyFromProperties(paragraphProps, convertedXml = {}) {
216225
- const fontFamilyProps = paragraphProps?.runProperties?.fontFamily;
216226
- if (!fontFamilyProps)
216227
- return null;
216228
- const [markDef] = encodeMarksFromRPr({ fontFamily: fontFamilyProps }, convertedXml);
216229
- return markDef?.attrs?.fontFamily ?? null;
216230
- }
216231
217205
  function getDefaultExportFromCjs2(x) {
216232
217206
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
216233
217207
  }
@@ -222241,6 +223215,124 @@ function normalizeReplacementText(text5, stepId) {
222241
223215
  throw planError("INVALID_INPUT", "replacement text normalized to zero blocks", stepId);
222242
223216
  return chunks;
222243
223217
  }
223218
+ function tokenizeWords(text5) {
223219
+ const tokens = [];
223220
+ const regex = /(\s+|\S+)/g;
223221
+ let match$1;
223222
+ while ((match$1 = regex.exec(text5)) !== null)
223223
+ tokens.push({
223224
+ text: match$1[0],
223225
+ offset: match$1.index
223226
+ });
223227
+ return tokens;
223228
+ }
223229
+ function getWordChanges(oldText, newText) {
223230
+ if (oldText === newText)
223231
+ return [];
223232
+ const oldTokens = tokenizeWords(oldText);
223233
+ const newTokens = tokenizeWords(newText);
223234
+ if (oldTokens.length === 0 && newTokens.length === 0)
223235
+ return [];
223236
+ if (oldTokens.length === 0)
223237
+ return [{
223238
+ type: "insert",
223239
+ insertAt: 0,
223240
+ newText
223241
+ }];
223242
+ if (newTokens.length === 0)
223243
+ return [{
223244
+ type: "delete",
223245
+ oldFrom: 0,
223246
+ oldTo: oldText.length
223247
+ }];
223248
+ const ops = myersDiff(oldTokens, newTokens, (a2, b$1) => a2.text === b$1.text);
223249
+ const steps = [];
223250
+ let oldIdx = 0;
223251
+ let newIdx = 0;
223252
+ for (const op of ops) {
223253
+ steps.push({
223254
+ type: op,
223255
+ oldIdx,
223256
+ newIdx
223257
+ });
223258
+ if (op === "equal") {
223259
+ oldIdx++;
223260
+ newIdx++;
223261
+ } else if (op === "delete")
223262
+ oldIdx++;
223263
+ else
223264
+ newIdx++;
223265
+ }
223266
+ const result = [];
223267
+ let i4 = 0;
223268
+ while (i4 < steps.length) {
223269
+ if (steps[i4].type === "equal") {
223270
+ i4++;
223271
+ continue;
223272
+ }
223273
+ let deleteStart = -1;
223274
+ let deleteEnd = -1;
223275
+ let insertText2 = "";
223276
+ while (i4 < steps.length && (steps[i4].type === "delete" || steps[i4].type === "insert")) {
223277
+ const s2 = steps[i4];
223278
+ if (s2.type === "delete") {
223279
+ const token$1 = oldTokens[s2.oldIdx];
223280
+ if (deleteStart === -1)
223281
+ deleteStart = token$1.offset;
223282
+ deleteEnd = token$1.offset + token$1.text.length;
223283
+ } else
223284
+ insertText2 += newTokens[s2.newIdx].text;
223285
+ i4++;
223286
+ }
223287
+ if (deleteStart !== -1 && insertText2.length > 0)
223288
+ result.push({
223289
+ type: "replace",
223290
+ oldFrom: deleteStart,
223291
+ oldTo: deleteEnd,
223292
+ newText: insertText2
223293
+ });
223294
+ else if (deleteStart !== -1)
223295
+ result.push({
223296
+ type: "delete",
223297
+ oldFrom: deleteStart,
223298
+ oldTo: deleteEnd
223299
+ });
223300
+ else if (insertText2.length > 0) {
223301
+ const prevStep = i4 > 0 ? steps[i4 - 1] : null;
223302
+ let insertAt = 0;
223303
+ if (prevStep && prevStep.type === "equal") {
223304
+ const prevToken = oldTokens[prevStep.oldIdx];
223305
+ insertAt = prevToken.offset + prevToken.text.length;
223306
+ } else if (result.length > 0) {
223307
+ const lastOp = result[result.length - 1];
223308
+ insertAt = "oldTo" in lastOp ? lastOp.oldTo : ("insertAt" in lastOp) ? lastOp.insertAt : 0;
223309
+ }
223310
+ result.push({
223311
+ type: "insert",
223312
+ insertAt,
223313
+ newText: insertText2
223314
+ });
223315
+ }
223316
+ }
223317
+ return result;
223318
+ }
223319
+ function charOffsetToDocPos(doc$12, rangeFrom, rangeTo, charOffset) {
223320
+ let count2 = 0;
223321
+ let foundPos = -1;
223322
+ doc$12.nodesBetween(rangeFrom, rangeTo, (node3, pos) => {
223323
+ if (foundPos >= 0)
223324
+ return false;
223325
+ if (!node3.isText)
223326
+ return true;
223327
+ const textStart = Math.max(pos, rangeFrom);
223328
+ const textLen = Math.min(pos + node3.nodeSize, rangeTo) - textStart;
223329
+ if (count2 + textLen >= charOffset)
223330
+ foundPos = textStart + (charOffset - count2);
223331
+ count2 += textLen;
223332
+ return false;
223333
+ });
223334
+ return foundPos >= 0 ? foundPos : rangeTo;
223335
+ }
222244
223336
  function debugTextRewrite(message, details) {
222245
223337
  if (!DEBUG_TEXT_REWRITE)
222246
223338
  return;
@@ -222729,8 +223821,58 @@ function executeTextRewrite(editor, tr, target, step3, mapping) {
222729
223821
  });
222730
223822
  }
222731
223823
  }
222732
- const textNode = editor.state.schema.text(replacementText, asProseMirrorMarks(marks));
222733
- tr.replaceWith(absFrom, absTo, textNode);
223824
+ const originalText = tr.doc.textBetween(absFrom, absTo, "", "");
223825
+ const origLen = originalText.length;
223826
+ const replLen = replacementText.length;
223827
+ let prefix2 = 0;
223828
+ while (prefix2 < origLen && prefix2 < replLen && originalText[prefix2] === replacementText[prefix2])
223829
+ prefix2++;
223830
+ if (prefix2 === origLen && prefix2 === replLen)
223831
+ return { changed: false };
223832
+ let suffix = 0;
223833
+ while (suffix < origLen - prefix2 && suffix < replLen - prefix2 && originalText[origLen - 1 - suffix] === replacementText[replLen - 1 - suffix])
223834
+ suffix++;
223835
+ const trimmedFrom = charOffsetToDocPos(tr.doc, absFrom, absTo, prefix2);
223836
+ const trimmedTo = charOffsetToDocPos(tr.doc, absFrom, absTo, origLen - suffix);
223837
+ const trimmedOld = originalText.slice(prefix2, origLen - suffix);
223838
+ const trimmedNew = replacementText.slice(prefix2, replLen - suffix);
223839
+ const wordChanges = getWordChanges(trimmedOld, trimmedNew);
223840
+ if (wordChanges.length > 1) {
223841
+ const doc$12 = tr.doc;
223842
+ const baseSteps = tr.steps.length;
223843
+ const mapped = wordChanges.map((change) => {
223844
+ if (change.type === "insert")
223845
+ return {
223846
+ ...change,
223847
+ docPos: charOffsetToDocPos(doc$12, trimmedFrom, trimmedTo, change.insertAt)
223848
+ };
223849
+ return {
223850
+ ...change,
223851
+ docFrom: charOffsetToDocPos(doc$12, trimmedFrom, trimmedTo, change.oldFrom),
223852
+ docTo: charOffsetToDocPos(doc$12, trimmedFrom, trimmedTo, change.oldTo)
223853
+ };
223854
+ });
223855
+ for (let i4 = 0;i4 < mapped.length; i4++) {
223856
+ const change = mapped[i4];
223857
+ const remap = (pos) => {
223858
+ for (let s2 = baseSteps;s2 < tr.steps.length; s2++)
223859
+ pos = tr.steps[s2].getMap().map(pos);
223860
+ return pos;
223861
+ };
223862
+ if (change.type === "delete")
223863
+ tr.delete(remap(change.docFrom), remap(change.docTo));
223864
+ else if (change.type === "insert") {
223865
+ const node3 = editor.state.schema.text(change.newText, asProseMirrorMarks(marks));
223866
+ tr.insert(remap(change.docPos), node3);
223867
+ } else {
223868
+ const node3 = editor.state.schema.text(change.newText, asProseMirrorMarks(marks));
223869
+ tr.replaceWith(remap(change.docFrom), remap(change.docTo), node3);
223870
+ }
223871
+ }
223872
+ } else {
223873
+ const textNode = editor.state.schema.text(trimmedNew, asProseMirrorMarks(marks));
223874
+ tr.replaceWith(trimmedFrom, trimmedTo, textNode);
223875
+ }
222734
223876
  return { changed: replacementText !== target.text };
222735
223877
  }
222736
223878
  function executeTextInsert(editor, tr, target, step3, mapping) {
@@ -226332,7 +227474,7 @@ function applyTextSelection(editor, from$1, to) {
226332
227474
  }
226333
227475
  if (editor.state?.tr && typeof editor.dispatch === "function")
226334
227476
  try {
226335
- const tr = editor.state.tr.setSelection(TextSelection2.create(editor.state.doc, from$1, to)).setMeta("inputType", "programmatic");
227477
+ const tr = editor.state.tr.setSelection(TextSelection.create(editor.state.doc, from$1, to)).setMeta("inputType", "programmatic");
226336
227478
  editor.dispatch(tr);
226337
227479
  return true;
226338
227480
  } catch {
@@ -238785,7 +239927,7 @@ function createWrapper(editor, input2, options) {
238785
239927
  if (input2.at) {
238786
239928
  const { absFrom, absTo } = resolveSelectionTarget(editor, input2.at);
238787
239929
  const { tr } = editor.state;
238788
- tr.setSelection(TextSelection2.create(tr.doc, absFrom, absTo));
239930
+ tr.setSelection(TextSelection.create(tr.doc, absFrom, absTo));
238789
239931
  dispatchTransaction(editor, tr);
238790
239932
  }
238791
239933
  const cmd = editor.commands?.[commandName];
@@ -254938,13 +256080,13 @@ function normalizeFieldAnnotationMetadata(attrs) {
254938
256080
  displayLabel: toOptionalString(attrs.displayLabel),
254939
256081
  defaultDisplayLabel: toOptionalString(attrs.defaultDisplayLabel),
254940
256082
  alias: toOptionalString(attrs.alias),
254941
- fieldColor: normalizeColorValue(attrs.fieldColor),
254942
- borderColor: normalizeColorValue(attrs.borderColor),
256083
+ fieldColor: normalizeColorValue2(attrs.fieldColor),
256084
+ borderColor: normalizeColorValue2(attrs.borderColor),
254943
256085
  highlighted: toBoolean$2(attrs.highlighted, true),
254944
256086
  fontFamily: toNullableString(attrs.fontFamily),
254945
256087
  fontSize: normalizeFontSize$1(attrs.fontSize),
254946
- textColor: normalizeColorValue(attrs.textColor) ?? null,
254947
- textHighlight: normalizeColorValue(attrs.textHighlight) ?? null,
256088
+ textColor: normalizeColorValue2(attrs.textColor) ?? null,
256089
+ textHighlight: normalizeColorValue2(attrs.textHighlight) ?? null,
254948
256090
  linkUrl: toNullableString(attrs.linkUrl),
254949
256091
  imageSrc: toNullableString(attrs.imageSrc),
254950
256092
  rawHtml: attrs.rawHtml ?? undefined,
@@ -255028,7 +256170,7 @@ function normalizeVisibility(value) {
255028
256170
  if (normalized === "visible" || normalized === "hidden")
255029
256171
  return normalized;
255030
256172
  }
255031
- function normalizeColorValue(value) {
256173
+ function normalizeColorValue2(value) {
255032
256174
  if (typeof value !== "string")
255033
256175
  return;
255034
256176
  const trimmed = value.trim();
@@ -262063,7 +263205,7 @@ var Node$13 = class Node$14 {
262063
263205
  const anchor = relativePositionToAbsolutePosition(binding.doc, binding.type, relSel.anchor, binding.mapping);
262064
263206
  const head = relativePositionToAbsolutePosition(binding.doc, binding.type, relSel.head, binding.mapping);
262065
263207
  if (anchor !== null && head !== null) {
262066
- const sel = TextSelection2.between(tr.doc.resolve(anchor), tr.doc.resolve(head));
263208
+ const sel = TextSelection.between(tr.doc.resolve(anchor), tr.doc.resolve(head));
262067
263209
  tr.setSelection(sel);
262068
263210
  }
262069
263211
  }
@@ -262148,7 +263290,7 @@ var Node$13 = class Node$14 {
262148
263290
  if (sel) {
262149
263291
  const clampedAnchor = min$1(max$1(sel.anchor, 0), tr.doc.content.size);
262150
263292
  const clampedHead = min$1(max$1(sel.head, 0), tr.doc.content.size);
262151
- tr.setSelection(TextSelection2.create(tr.doc, clampedAnchor, clampedHead));
263293
+ tr.setSelection(TextSelection.create(tr.doc, clampedAnchor, clampedHead));
262152
263294
  }
262153
263295
  this.prosemirrorView.dispatch(tr.setMeta(ySyncPluginKey, {
262154
263296
  isChangeOrigin: true,
@@ -264036,19 +265178,19 @@ var Node$13 = class Node$14 {
264036
265178
  const leftRun = runType.create(run2.attrs, leftFrag, run2.marks);
264037
265179
  const rightRun = runType.create(run2.attrs, rightFrag, run2.marks);
264038
265180
  const gapPos = runStart + leftRun.nodeSize;
264039
- tr.replaceWith(runStart, runEnd, [leftRun, rightRun]).setSelection(TextSelection2.create(tr.doc, gapPos));
265181
+ tr.replaceWith(runStart, runEnd, [leftRun, rightRun]).setSelection(TextSelection.create(tr.doc, gapPos));
264040
265182
  if (dispatch)
264041
265183
  dispatch(tr);
264042
265184
  return true;
264043
265185
  }, cleanupEmptyRunsPlugin, preserveStoredMarks = (state, tr) => {
264044
- if (!(tr.selection instanceof TextSelection2) || !tr.selection.empty)
265186
+ if (!(tr.selection instanceof TextSelection) || !tr.selection.empty)
264045
265187
  return;
264046
265188
  if (state.storedMarks === null)
264047
265189
  return;
264048
265190
  tr.setStoredMarks(state.storedMarks);
264049
265191
  }, normalizeSelectionIntoRun = (tr, runType) => {
264050
265192
  const selection = tr.selection;
264051
- if (!(selection instanceof TextSelection2))
265193
+ if (!(selection instanceof TextSelection))
264052
265194
  return;
264053
265195
  if (selection.from !== selection.to)
264054
265196
  return;
@@ -264059,14 +265201,14 @@ var Node$13 = class Node$14 {
264059
265201
  if (nodeAfter?.type === runType && nodeAfter.content.size > 0) {
264060
265202
  const nextPos = selection.from + 1;
264061
265203
  if (nextPos <= tr.doc.content.size)
264062
- tr.setSelection(TextSelection2.create(tr.doc, nextPos));
265204
+ tr.setSelection(TextSelection.create(tr.doc, nextPos));
264063
265205
  return;
264064
265206
  }
264065
265207
  const nodeBefore = $pos.nodeBefore;
264066
265208
  if (nodeBefore?.type === runType && nodeBefore.content.size > 0) {
264067
265209
  const prevPos = selection.from - 1;
264068
265210
  if (prevPos >= 0)
264069
- tr.setSelection(TextSelection2.create(tr.doc, prevPos));
265211
+ tr.setSelection(TextSelection.create(tr.doc, prevPos));
264070
265212
  }
264071
265213
  }, copyRunPropertiesFromParagraph = (state, pos, textNode, runType, editor) => {
264072
265214
  let updatedTextNode = textNode;
@@ -264204,7 +265346,7 @@ var Node$13 = class Node$14 {
264204
265346
  const runProperties = getSplitRunProperties(state, $from);
264205
265347
  newAttrs = syncSplitParagraphRunProperties(newAttrs, runProperties);
264206
265348
  }
264207
- if (selection instanceof TextSelection2)
265349
+ if (selection instanceof TextSelection)
264208
265350
  tr.deleteSelection();
264209
265351
  const deflt = $from.depth === 0 ? null : defaultBlockAt($from.node(-1).contentMatchAt($from.indexAfter(-1)));
264210
265352
  let types3 = atEnd && deflt ? [{
@@ -264276,7 +265418,7 @@ var Node$13 = class Node$14 {
264276
265418
  const { from: from$1 } = tr.selection;
264277
265419
  const tabText = state.schema.text("\t");
264278
265420
  tr = tr.replaceSelectionWith(tabText);
264279
- tr = tr.setSelection(TextSelection2.create(tr.doc, from$1 + 1));
265421
+ tr = tr.setSelection(TextSelection.create(tr.doc, from$1 + 1));
264280
265422
  if (dispatch)
264281
265423
  dispatch(tr);
264282
265424
  return true;
@@ -264304,7 +265446,7 @@ var Node$13 = class Node$14 {
264304
265446
  newPos = tr.selection.from;
264305
265447
  }
264306
265448
  tr.insert(newPos, tabNode);
264307
- tr = tr.setSelection(TextSelection2.create(tr.doc, newPos + tabNode.nodeSize));
265449
+ tr = tr.setSelection(TextSelection.create(tr.doc, newPos + tabNode.nodeSize));
264308
265450
  if (dispatch)
264309
265451
  dispatch(tr);
264310
265452
  return true;
@@ -264473,7 +265615,7 @@ var Node$13 = class Node$14 {
264473
265615
  if (dispatch) {
264474
265616
  let side = (!$from.parentOffset && $to.index() < $to.parent.childCount ? $from : $to).pos;
264475
265617
  let tr = state.tr.insert(side, type.createAndFill());
264476
- tr.setSelection(TextSelection2.create(tr.doc, side + 1));
265618
+ tr.setSelection(TextSelection.create(tr.doc, side + 1));
264477
265619
  dispatch(tr.scrollIntoView());
264478
265620
  }
264479
265621
  return true;
@@ -265201,7 +266343,7 @@ var Node$13 = class Node$14 {
265201
266343
  const paraPos = $from.before();
265202
266344
  let tr = state.tr.deleteRange(paraPos, paraPos + para.nodeSize).scrollIntoView();
265203
266345
  const targetPos = Math.max(1, Math.min(paraPos - 1, tr.doc.content.size));
265204
- tr = tr.setSelection(TextSelection2.create(tr.doc, targetPos));
266346
+ tr = tr.setSelection(TextSelection.create(tr.doc, targetPos));
265205
266347
  dispatch(tr);
265206
266348
  }
265207
266349
  return true;
@@ -265467,7 +266609,7 @@ var Node$13 = class Node$14 {
265467
266609
  if (selection.empty && paragraphsInSelection.length === 1)
265468
266610
  tr.setSelection(Selection.near(tr.doc.resolve(restoredSelectionRange.to), -1));
265469
266611
  else
265470
- tr.setSelection(TextSelection2.create(tr.doc, restoredSelectionRange.from, restoredSelectionRange.to));
266612
+ tr.setSelection(TextSelection.create(tr.doc, restoredSelectionRange.from, restoredSelectionRange.to));
265471
266613
  } catch {}
265472
266614
  }
265473
266615
  dispatch(tr);
@@ -265576,7 +266718,7 @@ var Node$13 = class Node$14 {
265576
266718
  return true;
265577
266719
  }, restoreSelection = () => ({ editor, state, tr }) => {
265578
266720
  if (editor.options.lastSelection) {
265579
- tr.setSelection(TextSelection2.create(state.doc, editor.options.lastSelection.from, editor.options.lastSelection.to));
266721
+ tr.setSelection(TextSelection.create(state.doc, editor.options.lastSelection.from, editor.options.lastSelection.to));
265580
266722
  return true;
265581
266723
  }
265582
266724
  return false;
@@ -265588,7 +266730,7 @@ var Node$13 = class Node$14 {
265588
266730
  const nextFrom = clamp$1(typeof from$1 === "number" ? from$1 : state.selection.from, 0, docSize);
265589
266731
  const nextTo = clamp$1(typeof to === "number" ? to : nextFrom, 0, docSize);
265590
266732
  const [head, anchor] = nextFrom <= nextTo ? [nextFrom, nextTo] : [nextTo, nextFrom];
265591
- const selection = TextSelection2.create(doc$12, head, anchor);
266733
+ const selection = TextSelection.create(doc$12, head, anchor);
265592
266734
  if (dispatch)
265593
266735
  dispatch(state.tr.setSelection(selection));
265594
266736
  if (editor?.view?.dom && typeof editor.view.dom.focus === "function")
@@ -269736,9 +270878,9 @@ var Node$13 = class Node$14 {
269736
270878
  }, syncSelectionFromTransaction = ({ targetTr, sourceSelection }) => {
269737
270879
  const boundedFrom = Math.max(0, Math.min(sourceSelection.from, targetTr.doc.content.size));
269738
270880
  const boundedTo = Math.max(0, Math.min(sourceSelection.to, targetTr.doc.content.size));
269739
- if (sourceSelection instanceof TextSelection2)
270881
+ if (sourceSelection instanceof TextSelection)
269740
270882
  try {
269741
- targetTr.setSelection(TextSelection2.create(targetTr.doc, boundedFrom, boundedTo));
270883
+ targetTr.setSelection(TextSelection.create(targetTr.doc, boundedFrom, boundedTo));
269742
270884
  return;
269743
270885
  } catch {
269744
270886
  targetTr.setSelection(Selection.near(targetTr.doc.resolve(boundedFrom), -1));
@@ -270449,29 +271591,29 @@ var Node$13 = class Node$14 {
270449
271591
  const boundedPos = Math.max(0, Math.min(trackMeta.selectionPos, newTr.doc.content.size));
270450
271592
  const $pos = newTr.doc.resolve(boundedPos);
270451
271593
  if ($pos.parent.inlineContent)
270452
- newTr.setSelection(TextSelection2.create(newTr.doc, boundedPos));
271594
+ newTr.setSelection(TextSelection.create(newTr.doc, boundedPos));
270453
271595
  else
270454
- newTr.setSelection(TextSelection2.near($pos, -1));
271596
+ newTr.setSelection(TextSelection.near($pos, -1));
270455
271597
  } else if (tr.selectionSet)
270456
- if (tr.selection instanceof TextSelection2 && (tr.selection.from < state.selection.from || tr.getMeta("inputType") === "deleteContentBackward")) {
271598
+ if (tr.selection instanceof TextSelection && (tr.selection.from < state.selection.from || tr.getMeta("inputType") === "deleteContentBackward")) {
270457
271599
  const caretPos = map$12.map(tr.selection.from, -1);
270458
- newTr.setSelection(new TextSelection2(newTr.doc.resolve(caretPos)));
271600
+ newTr.setSelection(new TextSelection(newTr.doc.resolve(caretPos)));
270459
271601
  } else if (trackMeta?.insertedTo !== undefined) {
270460
271602
  const boundedInsertedTo = Math.max(0, Math.min(trackMeta.insertedTo, newTr.doc.content.size));
270461
271603
  const $insertPos = newTr.doc.resolve(boundedInsertedTo);
270462
- newTr.setSelection(TextSelection2.near($insertPos, 1));
271604
+ newTr.setSelection(TextSelection.near($insertPos, 1));
270463
271605
  } else {
270464
271606
  const deletionMarkSchema = state.schema.marks[TrackDeleteMarkName];
270465
271607
  const deletionMark = findMark(state, deletionMarkSchema, false);
270466
271608
  if (tr.selection.from > state.selection.from && deletionMark) {
270467
271609
  const caretPos = map$12.map(deletionMark.to + 1, 1);
270468
- newTr.setSelection(new TextSelection2(newTr.doc.resolve(caretPos)));
271610
+ newTr.setSelection(new TextSelection(newTr.doc.resolve(caretPos)));
270469
271611
  } else
270470
271612
  newTr.setSelection(tr.selection.map(newTr.doc, map$12));
270471
271613
  }
270472
271614
  else if (state.selection.from - tr.selection.from > 1 && tr.selection.$head.depth > 1) {
270473
271615
  const caretPos = map$12.map(tr.selection.from - 2, -1);
270474
- newTr.setSelection(new TextSelection2(newTr.doc.resolve(caretPos)));
271616
+ newTr.setSelection(new TextSelection(newTr.doc.resolve(caretPos)));
270475
271617
  }
270476
271618
  if (tr.storedMarksSet)
270477
271619
  newTr.setStoredMarks(tr.storedMarks);
@@ -270942,7 +272084,7 @@ var Node$13 = class Node$14 {
270942
272084
  to
270943
272085
  });
270944
272086
  else if (this.#editor.state) {
270945
- const tr = this.#editor.state.tr.setSelection(TextSelection2.create(this.#editor.state.doc, from$1, to)).scrollIntoView();
272087
+ const tr = this.#editor.state.tr.setSelection(TextSelection.create(this.#editor.state.doc, from$1, to)).scrollIntoView();
270946
272088
  this.#editor.dispatch(tr);
270947
272089
  }
270948
272090
  const presentationEditor = this.#editor.presentationEditor;
@@ -272215,7 +273357,7 @@ var Node$13 = class Node$14 {
272215
273357
  }, icons, getAvailableColorOptions = () => {
272216
273358
  return icons.flat().map((item) => item.value);
272217
273359
  }, _hoisted_1$14, _hoisted_2$10, ROW_SIZE = 5, TableGrid_default, _hoisted_1$13, _hoisted_2$9, _hoisted_3$7, _hoisted_4$5, _hoisted_5$2, TableActions_default, check_default = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M438.6 105.4c12.5 12.5 12.5 32.8 0 45.3l-256 256c-12.5 12.5-32.8 12.5-45.3 0l-128-128c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0L160 338.7 393.4 105.4c12.5-12.5 32.8-12.5 45.3 0z"/></svg>
272218
- `, _hoisted_1$12, _hoisted_2$8, _hoisted_3$6, SearchInput_default, TOOLBAR_FONTS, TOOLBAR_FONT_SIZES, closeDropdown = (dropdown) => {
273360
+ `, _hoisted_1$12, _hoisted_2$8, _hoisted_3$6, SearchInput_default, TOOLBAR_FONTS, TOOLBAR_FONT_SIZES, HEADLESS_ITEM_MAP, TABLE_ACTION_COMMAND_MAP, TABLE_ACTION_COMMAND_IDS, HEADLESS_TOOLBAR_COMMANDS, NON_HEADLESS_EXECUTE_ITEM_NAMES, HEADLESS_EXECUTE_ITEMS, closeDropdown = (dropdown) => {
272219
273361
  dropdown.expand.value = false;
272220
273362
  }, makeDefaultItems = ({ superToolbar, toolbarIcons: toolbarIcons$1, toolbarTexts: toolbarTexts$1, toolbarFonts, hideButtons, availableWidth, role, isDev = false } = {}) => {
272221
273363
  const bold2 = useToolbarItem({
@@ -272854,16 +273996,6 @@ var Node$13 = class Node$14 {
272854
273996
  group: "left",
272855
273997
  attributes: { ariaLabel: "Redo" }
272856
273998
  });
272857
- const toggleTrackChanges = useToolbarItem({
272858
- type: "button",
272859
- disabled: false,
272860
- name: "toggleTrackChanges",
272861
- tooltip: toolbarTexts$1.trackChanges,
272862
- command: "toggleTrackChanges",
272863
- icon: toolbarIcons$1.trackChanges,
272864
- group: "left",
272865
- attributes: { ariaLabel: "Track changes" }
272866
- });
272867
273999
  const acceptTrackedChangeBySelection = useToolbarItem({
272868
274000
  type: "button",
272869
274001
  disabled: false,
@@ -272884,26 +274016,6 @@ var Node$13 = class Node$14 {
272884
274016
  group: "left",
272885
274017
  attributes: { ariaLabel: "Reject tracked changes" }
272886
274018
  });
272887
- const toggleTrackChangesOriginal = useToolbarItem({
272888
- type: "button",
272889
- disabled: false,
272890
- name: "toggleTrackChangesShowOriginal",
272891
- tooltip: toolbarTexts$1.trackChangesOriginal,
272892
- command: "toggleTrackChangesShowOriginal",
272893
- icon: toolbarIcons$1.trackChangesOriginal,
272894
- group: "left",
272895
- attributes: { ariaLabel: "Toggle tracked changes show original" }
272896
- });
272897
- const toggleTrackChangesFinal = useToolbarItem({
272898
- type: "button",
272899
- disabled: false,
272900
- name: "toggleTrackChangesShowFinal",
272901
- tooltip: toolbarTexts$1.trackChangesFinal,
272902
- command: "toggleTrackChangesShowFinal",
272903
- icon: toolbarIcons$1.trackChangesFinal,
272904
- group: "left",
272905
- attributes: { ariaLabel: "Toggle tracked changes show final" }
272906
- });
272907
274019
  const clearFormatting = useToolbarItem({
272908
274020
  type: "button",
272909
274021
  name: "clearFormatting",
@@ -273183,11 +274295,7 @@ var Node$13 = class Node$14 {
273183
274295
  ];
273184
274296
  toolbarItems = toolbarItems.filter((item) => !filterItems.includes(item.name.value));
273185
274297
  }
273186
- const devItems = [
273187
- toggleTrackChanges,
273188
- toggleTrackChangesOriginal,
273189
- toggleTrackChangesFinal
273190
- ];
274298
+ const devItems = [];
273191
274299
  if (!isDev) {
273192
274300
  if (role === "viewer")
273193
274301
  devItems.push(...[acceptTrackedChangeBySelection, rejectTrackedChangeOnSelection]);
@@ -273232,7 +274340,24 @@ var Node$13 = class Node$14 {
273232
274340
  defaultItems: visibleItems,
273233
274341
  overflowItems: overflowItems.filter((item) => item.type !== "separator")
273234
274342
  };
273235
- }, _hoisted_1$11, _hoisted_2$7, ToolbarButtonIcon_default, _hoisted_1$10, _hoisted_2$6, _hoisted_3$5, _hoisted_4$4, _hoisted_5$1, _hoisted_6, _hoisted_7, _hoisted_8, ToolbarButton_default, _hoisted_1$9, ToolbarSeparator_default, _hoisted_1$8, _hoisted_2$5, _hoisted_3$4, OverflowMenu_default, _hoisted_1$7, _hoisted_2$4, _hoisted_3$3, _hoisted_4$3, ToolbarDropdown_default, SdTooltip_default, _hoisted_1$6, _hoisted_2$3, _hoisted_3$2, _hoisted_4$2, ButtonGroup_default, DEFAULT_UI_FONT_FAMILY = "Arial, Helvetica, sans-serif", Toolbar_default, toolbarTexts, SuperToolbar, Schema3 = class Schema4 {
274343
+ }, _hoisted_1$11, _hoisted_2$7, ToolbarButtonIcon_default, _hoisted_1$10, _hoisted_2$6, _hoisted_3$5, _hoisted_4$4, _hoisted_5$1, _hoisted_6, _hoisted_7, _hoisted_8, ToolbarButton_default, _hoisted_1$9, ToolbarSeparator_default, _hoisted_1$8, _hoisted_2$5, _hoisted_3$4, OverflowMenu_default, _hoisted_1$7, _hoisted_2$4, _hoisted_3$3, _hoisted_4$3, ToolbarDropdown_default, SdTooltip_default, _hoisted_1$6, _hoisted_2$3, _hoisted_3$2, _hoisted_4$2, ButtonGroup_default, DEFAULT_UI_FONT_FAMILY = "Arial, Helvetica, sans-serif", Toolbar_default, toolbarTexts, getParagraphFontFamilyFromProperties = (paragraphProps, convertedXml = {}) => {
274344
+ const fontFamilyProps = paragraphProps?.runProperties?.fontFamily;
274345
+ if (!fontFamilyProps)
274346
+ return null;
274347
+ const [markDef] = encodeMarksFromRPr({ fontFamily: fontFamilyProps }, convertedXml);
274348
+ return markDef?.attrs?.fontFamily ?? null;
274349
+ }, findElementBySelector = (selector) => {
274350
+ let el = null;
274351
+ if (selector) {
274352
+ if (selector.startsWith("#") || selector.startsWith("."))
274353
+ el = document.querySelector(selector);
274354
+ else
274355
+ el = document.getElementById(selector);
274356
+ if (!el)
274357
+ return null;
274358
+ }
274359
+ return el;
274360
+ }, SuperToolbar, Schema3 = class Schema4 {
273236
274361
  static createSchemaByExtensions(extensions, editor) {
273237
274362
  const nodeExtensions = extensions.filter((e) => e.type === "node");
273238
274363
  const markExtensions = extensions.filter((e) => e.type === "mark");
@@ -284645,7 +285770,7 @@ var Node$13 = class Node$14 {
284645
285770
  if (isolatingDepth > 0) {
284646
285771
  const boundary = forward ? $head.before(isolatingDepth) : $head.after(isolatingDepth);
284647
285772
  const near = Selection.near(doc$12.resolve(boundary), forward ? -1 : 1);
284648
- if (near instanceof TextSelection2)
285773
+ if (near instanceof TextSelection)
284649
285774
  return near.head;
284650
285775
  return anchor;
284651
285776
  }
@@ -284992,7 +286117,7 @@ var Node$13 = class Node$14 {
284992
286117
  const resolved = this.#resolveStructuredContentInlineFromElement(doc$12, inlineStructuredContentLabel);
284993
286118
  if (resolved) {
284994
286119
  try {
284995
- const tr = editor.state.tr.setSelection(TextSelection2.create(doc$12, resolved.start, resolved.end));
286120
+ const tr = editor.state.tr.setSelection(TextSelection.create(doc$12, resolved.start, resolved.end));
284996
286121
  editor.view?.dispatch(tr);
284997
286122
  } catch {}
284998
286123
  this.#callbacks.scheduleSelectionUpdate?.();
@@ -285006,7 +286131,7 @@ var Node$13 = class Node$14 {
285006
286131
  if (resolved) {
285007
286132
  try {
285008
286133
  const contentRange = this.#findStructuredContentBlockContentRange(resolved);
285009
- const selection = contentRange != null ? TextSelection2.create(doc$12, contentRange.from, contentRange.to) : NodeSelection.create(editor.state.doc, resolved.pos);
286134
+ const selection = contentRange != null ? TextSelection.create(doc$12, contentRange.from, contentRange.to) : NodeSelection.create(editor.state.doc, resolved.pos);
285010
286135
  const tr = editor.state.tr.setSelection(selection);
285011
286136
  editor.view?.dispatch(tr);
285012
286137
  } catch {}
@@ -285097,12 +286222,12 @@ var Node$13 = class Node$14 {
285097
286222
  if (sdtBlock)
285098
286223
  nextSelection = NodeSelection.create(doc$12, sdtBlock.pos);
285099
286224
  else {
285100
- nextSelection = TextSelection2.create(doc$12, hit.pos);
286225
+ nextSelection = TextSelection.create(doc$12, hit.pos);
285101
286226
  if (!nextSelection.$from.parent.inlineContent)
285102
286227
  nextSelection = Selection.near(doc$12.resolve(hit.pos), 1);
285103
286228
  }
285104
286229
  const tr = editor.state.tr.setSelection(nextSelection);
285105
- if (nextSelection instanceof TextSelection2 && nextSelection.empty && editor.state.storedMarks)
286230
+ if (nextSelection instanceof TextSelection && nextSelection.empty && editor.state.storedMarks)
285106
286231
  tr.setStoredMarks(editor.state.storedMarks);
285107
286232
  editor.view?.dispatch(tr);
285108
286233
  } catch {}
@@ -285532,7 +286657,7 @@ var Node$13 = class Node$14 {
285532
286657
  const anchor = editor.state.selection.anchor;
285533
286658
  const { selAnchor, selHead } = this.#calculateExtendedSelection(anchor, headPos, this.#dragExtensionMode);
285534
286659
  try {
285535
- const tr = editor.state.tr.setSelection(TextSelection2.create(editor.state.doc, selAnchor, selHead));
286660
+ const tr = editor.state.tr.setSelection(TextSelection.create(editor.state.doc, selAnchor, selHead));
285536
286661
  editor.view?.dispatch(tr);
285537
286662
  this.#callbacks.scheduleSelectionUpdate?.();
285538
286663
  } catch (error3) {
@@ -285615,7 +286740,7 @@ var Node$13 = class Node$14 {
285615
286740
  head = this.#clampHeadAtIsolatingBoundary(doc$12, anchor, head);
285616
286741
  const { selAnchor, selHead } = this.#calculateExtendedSelection(anchor, head, this.#dragExtensionMode);
285617
286742
  try {
285618
- const tr = editor.state.tr.setSelection(TextSelection2.create(editor.state.doc, selAnchor, selHead));
286743
+ const tr = editor.state.tr.setSelection(TextSelection.create(editor.state.doc, selAnchor, selHead));
285619
286744
  editor.view?.dispatch(tr);
285620
286745
  this.#callbacks.scheduleSelectionUpdate?.();
285621
286746
  } catch (error3) {
@@ -285646,7 +286771,7 @@ var Node$13 = class Node$14 {
285646
286771
  const head = hit.pos;
285647
286772
  const { selAnchor, selHead } = this.#calculateExtendedSelection(anchor, head, this.#dragExtensionMode);
285648
286773
  try {
285649
- const tr = editor.state.tr.setSelection(TextSelection2.create(editor.state.doc, selAnchor, selHead));
286774
+ const tr = editor.state.tr.setSelection(TextSelection.create(editor.state.doc, selAnchor, selHead));
285650
286775
  editor.view?.dispatch(tr);
285651
286776
  this.#callbacks.scheduleSelectionUpdate?.();
285652
286777
  } catch {}
@@ -285693,7 +286818,7 @@ var Node$13 = class Node$14 {
285693
286818
  if (pendingMarginClick.kind === "aboveFirstLine") {
285694
286819
  const pos = this.#getFirstTextPosition();
285695
286820
  try {
285696
- const tr = editor.state.tr.setSelection(TextSelection2.create(doc$12, pos));
286821
+ const tr = editor.state.tr.setSelection(TextSelection.create(doc$12, pos));
285697
286822
  editor.view?.dispatch(tr);
285698
286823
  this.#callbacks.scheduleSelectionUpdate?.();
285699
286824
  } catch {}
@@ -285717,7 +286842,7 @@ var Node$13 = class Node$14 {
285717
286842
  }
285718
286843
  const caretPos = Math.max(0, Math.min(mappedEnd$1.pos, doc$12.content.size));
285719
286844
  try {
285720
- const tr = editor.state.tr.setSelection(TextSelection2.create(doc$12, caretPos));
286845
+ const tr = editor.state.tr.setSelection(TextSelection.create(doc$12, caretPos));
285721
286846
  editor.view?.dispatch(tr);
285722
286847
  this.#callbacks.scheduleSelectionUpdate?.();
285723
286848
  } catch {}
@@ -285742,7 +286867,7 @@ var Node$13 = class Node$14 {
285742
286867
  const selFrom = Math.max(0, Math.min(Math.min(mappedStart.pos, mappedEnd.pos), doc$12.content.size));
285743
286868
  const selTo = Math.max(0, Math.min(Math.max(mappedStart.pos, mappedEnd.pos), doc$12.content.size));
285744
286869
  try {
285745
- const tr = editor.state.tr.setSelection(TextSelection2.create(doc$12, selFrom, selTo));
286870
+ const tr = editor.state.tr.setSelection(TextSelection.create(doc$12, selFrom, selTo));
285746
286871
  editor.view?.dispatch(tr);
285747
286872
  this.#callbacks.scheduleSelectionUpdate?.();
285748
286873
  } catch {}
@@ -285780,7 +286905,7 @@ var Node$13 = class Node$14 {
285780
286905
  const doc$12 = editor?.state?.doc;
285781
286906
  if (doc$12)
285782
286907
  try {
285783
- const tr = editor.state.tr.setSelection(TextSelection2.create(doc$12, validPos));
286908
+ const tr = editor.state.tr.setSelection(TextSelection.create(doc$12, validPos));
285784
286909
  editor.view?.dispatch(tr);
285785
286910
  } catch {}
285786
286911
  editorDom.focus();
@@ -286278,10 +287403,10 @@ var Node$13 = class Node$14 {
286278
287403
  return;
286279
287404
  const pos = Math.min(Math.max(hit.pos, 1), doc$12.content.size);
286280
287405
  const currentSelection = activeEditor.state.selection;
286281
- if (currentSelection instanceof TextSelection2 && currentSelection.from === pos && currentSelection.to === pos)
287406
+ if (currentSelection instanceof TextSelection && currentSelection.from === pos && currentSelection.to === pos)
286282
287407
  return;
286283
287408
  try {
286284
- const tr = activeEditor.state.tr.setSelection(TextSelection2.create(doc$12, pos)).setMeta("addToHistory", false);
287409
+ const tr = activeEditor.state.tr.setSelection(TextSelection.create(doc$12, pos)).setMeta("addToHistory", false);
286285
287410
  activeEditor.view?.dispatch(tr);
286286
287411
  this.#deps.scheduleSelectionUpdate();
286287
287412
  } catch {}
@@ -286335,7 +287460,7 @@ var Node$13 = class Node$14 {
286335
287460
  return;
286336
287461
  const clampedPos = Math.min(Math.max(pos, 1), doc$12.content.size);
286337
287462
  try {
286338
- const tr = activeEditor.state.tr.setSelection(TextSelection2.create(doc$12, clampedPos)).setMeta("addToHistory", false);
287463
+ const tr = activeEditor.state.tr.setSelection(TextSelection.create(doc$12, clampedPos)).setMeta("addToHistory", false);
286339
287464
  activeEditor.view?.dispatch(tr);
286340
287465
  } catch {}
286341
287466
  }
@@ -286416,7 +287541,7 @@ var Node$13 = class Node$14 {
286416
287541
  if (attributes && isValidFieldAnnotationAttributes(attributes)) {
286417
287542
  activeEditor.commands?.addFieldAnnotation?.(pos, attributes, true);
286418
287543
  const posAfter = Math.min(pos + 1, activeEditor.state?.doc?.content.size ?? pos + 1);
286419
- const tr = activeEditor.state?.tr.setSelection(TextSelection2.create(activeEditor.state.doc, posAfter));
287544
+ const tr = activeEditor.state?.tr.setSelection(TextSelection.create(activeEditor.state.doc, posAfter));
286420
287545
  if (tr)
286421
287546
  activeEditor.view?.dispatch(tr);
286422
287547
  this.#deps.scheduleSelectionUpdate();
@@ -288158,12 +289283,12 @@ var Node$13 = class Node$14 {
288158
289283
  return;
288159
289284
  console.log(...args$1);
288160
289285
  }, HEADER_FOOTER_INIT_BUDGET_MS = 200, MAX_ZOOM_WARNING_THRESHOLD = 10, MAX_SELECTION_RECTS_PER_USER = 100, SEMANTIC_RESIZE_DEBOUNCE_MS = 120, MIN_SEMANTIC_CONTENT_WIDTH_PX = 1, GLOBAL_PERFORMANCE, PresentationEditor, ICONS, TEXTS, tableActionsOptions;
288161
- var init_src_DjgWBzME_es = __esm(() => {
289286
+ var init_src_DlMaB1h_es = __esm(() => {
288162
289287
  init_rolldown_runtime_Bg48TavK_es();
288163
289288
  init_SuperConverter_BgwP1GeS_es();
288164
289289
  init_jszip_C49i9kUs_es();
288165
289290
  init_uuid_qzgm05fK_es();
288166
- init_create_headless_toolbar_zEz71NHQ_es();
289291
+ init_create_headless_toolbar_Dcw4Hyt2_es();
288167
289292
  init_constants_CGhJRd87_es();
288168
289293
  init_dist_B8HfvhaK_es();
288169
289294
  init_unified_Dsuw2be5_es();
@@ -288835,7 +289960,7 @@ ${err.toString()}`);
288835
289960
  }));
288836
289961
  if (!selection.empty && !this.editor.options.element?.contains(target)) {
288837
289962
  this.editor.setOptions({ lastSelection: selection });
288838
- const clearSelectionTr = view.state.tr.setSelection(TextSelection2.create(view.state.doc, 0));
289963
+ const clearSelectionTr = view.state.tr.setSelection(TextSelection.create(view.state.doc, 0));
288839
289964
  view.dispatch(clearSelectionTr);
288840
289965
  }
288841
289966
  }
@@ -290206,7 +291331,7 @@ ${err.toString()}`);
290206
291331
  fragments.push(runType.create(parentRun.attrs, rightContent, parentRun.marks));
290207
291332
  tr.replaceWith(runStart, runEnd, fragments);
290208
291333
  const cursorPos = runStart + (leftContent.size > 0 ? leftContent.size + 2 : 0) + node3.nodeSize;
290209
- tr.setSelection(TextSelection2.create(tr.doc, cursorPos));
291334
+ tr.setSelection(TextSelection.create(tr.doc, cursorPos));
290210
291335
  } else
290211
291336
  tr.replaceWith(from$1, to, node3);
290212
291337
  }
@@ -290785,7 +291910,7 @@ ${err.toString()}`);
290785
291910
  return null;
290786
291911
  const tr = newState.tr;
290787
291912
  toDelete.sort((a2, b$1) => b$1.from - a2.from).forEach(({ from: from$1, to }) => tr.deleteRange(from$1, to));
290788
- if (tr.selection instanceof TextSelection2 && tr.selection.empty && newState.storedMarks !== null)
291913
+ if (tr.selection instanceof TextSelection && tr.selection.empty && newState.storedMarks !== null)
290789
291914
  tr.setStoredMarks(newState.storedMarks);
290790
291915
  return tr.docChanged ? tr : null;
290791
291916
  } });
@@ -291147,7 +292272,7 @@ ${err.toString()}`);
291147
292272
  if (findParentNode(isList)(state.selection))
291148
292273
  return null;
291149
292274
  const { tr } = state;
291150
- tr.delete(range.from, range.to).setSelection(TextSelection2.create(tr.doc, range.from));
292275
+ tr.delete(range.from, range.to).setSelection(TextSelection.create(tr.doc, range.from));
291151
292276
  ListHelpers.createNewList({
291152
292277
  listType: type,
291153
292278
  tr,
@@ -291604,7 +292729,7 @@ ${err.toString()}`);
291604
292729
  const { from: from$1 } = findRangeById(state.doc, id2) || {};
291605
292730
  if (from$1 != null) {
291606
292731
  const tr = state.tr;
291607
- tr.setSelection(TextSelection2.create(state.doc, from$1));
292732
+ tr.setSelection(TextSelection.create(state.doc, from$1));
291608
292733
  if (options.activeCommentId)
291609
292734
  tr.setMeta(CommentsPluginKey, {
291610
292735
  type: "setActiveComment",
@@ -292299,7 +293424,7 @@ ${err.toString()}`);
292299
293424
  const { from: from$1, to, tablePos } = structuredContentInsertion;
292300
293425
  tr.replaceWith(from$1, to, node3);
292301
293426
  const selectionPos$1 = getFirstTableCellTextPos(tablePos, node3);
292302
- tr.scrollIntoView().setSelection(TextSelection2.near(tr.doc.resolve(selectionPos$1)));
293427
+ tr.scrollIntoView().setSelection(TextSelection.near(tr.doc.resolve(selectionPos$1)));
292303
293428
  return true;
292304
293429
  }
292305
293430
  let offset$1;
@@ -292329,7 +293454,7 @@ ${err.toString()}`);
292329
293454
  if (!inserted)
292330
293455
  return false;
292331
293456
  const selectionPos = getFirstTableCellTextPos(offset$1, node3);
292332
- tr.scrollIntoView().setSelection(TextSelection2.near(tr.doc.resolve(selectionPos)));
293457
+ tr.scrollIntoView().setSelection(TextSelection.near(tr.doc.resolve(selectionPos)));
292333
293458
  }
292334
293459
  return true;
292335
293460
  },
@@ -305812,7 +306937,7 @@ function print() { __p += __j.call(arguments, '') }
305812
306937
  if (typeof from$1 !== "number" || typeof to !== "number")
305813
306938
  return false;
305814
306939
  editor.view.focus();
305815
- const tr$1 = state.tr.setSelection(TextSelection2.create(state.doc, from$1, to)).scrollIntoView();
306940
+ const tr$1 = state.tr.setSelection(TextSelection.create(state.doc, from$1, to)).scrollIntoView();
305816
306941
  if (dispatch)
305817
306942
  dispatch(tr$1);
305818
306943
  const presentationEditor$1 = editor.presentationEditor;
@@ -305835,7 +306960,7 @@ function print() { __p += __j.call(arguments, '') }
305835
306960
  return false;
305836
306961
  const firstDeco = decorations[0];
305837
306962
  editor.view.focus();
305838
- const tr = state.tr.setSelection(TextSelection2.create(state.doc, firstDeco.from, firstDeco.to)).scrollIntoView();
306963
+ const tr = state.tr.setSelection(TextSelection.create(state.doc, firstDeco.from, firstDeco.to)).scrollIntoView();
305839
306964
  if (dispatch)
305840
306965
  dispatch(tr);
305841
306966
  const presentationEditor = editor.presentationEditor;
@@ -305902,7 +307027,7 @@ function print() { __p += __j.call(arguments, '') }
305902
307027
  from$1 = normalized.from;
305903
307028
  to = normalized.to;
305904
307029
  editor.view.focus();
305905
- const tr = state.tr.setSelection(TextSelection2.create(state.doc, from$1, to)).scrollIntoView();
307030
+ const tr = state.tr.setSelection(TextSelection.create(state.doc, from$1, to)).scrollIntoView();
305906
307031
  if (dispatch)
305907
307032
  dispatch(tr);
305908
307033
  const presentationEditor = editor.presentationEditor;
@@ -306633,7 +307758,7 @@ function print() { __p += __j.call(arguments, '') }
306633
307758
  if (selectionState.value) {
306634
307759
  const { state } = props.editor;
306635
307760
  const { from: from$1, to } = selectionState.value;
306636
- const tr = state.tr.setSelection(TextSelection2.create(state.doc, from$1, to));
307761
+ const tr = state.tr.setSelection(TextSelection.create(state.doc, from$1, to));
306637
307762
  props.editor.view.dispatch(tr);
306638
307763
  } else
306639
307764
  console.warn("[AIWriter] No stored selection to restore");
@@ -307271,7 +308396,7 @@ function print() { __p += __j.call(arguments, '') }
307271
308396
  text: finalText
307272
308397
  });
307273
308398
  const endPos = editor.view.state.selection.$to.pos;
307274
- editor.view.dispatch(editor.view.state.tr.setSelection(new TextSelection2(editor.view.state.doc.resolve(endPos))));
308399
+ editor.view.dispatch(editor.view.state.tr.setSelection(new TextSelection(editor.view.state.doc.resolve(endPos))));
307275
308400
  setTimeout(() => editor.view.focus(), 100);
307276
308401
  props.closePopover();
307277
308402
  };
@@ -307898,6 +309023,52 @@ function print() { __p += __j.call(arguments, '') }
307898
309023
  props: { "data-item": "btn-fontSize-option" }
307899
309024
  }
307900
309025
  ];
309026
+ HEADLESS_ITEM_MAP = {
309027
+ undo: "undo",
309028
+ redo: "redo",
309029
+ bold: "bold",
309030
+ italic: "italic",
309031
+ underline: "underline",
309032
+ strike: "strikethrough",
309033
+ acceptTrackedChangeBySelection: "track-changes-accept-selection",
309034
+ rejectTrackedChangeOnSelection: "track-changes-reject-selection",
309035
+ ruler: "ruler",
309036
+ zoom: "zoom",
309037
+ documentMode: "document-mode",
309038
+ link: "link",
309039
+ fontFamily: "font-family",
309040
+ fontSize: "font-size",
309041
+ list: "bullet-list",
309042
+ numberedlist: "numbered-list",
309043
+ table: "table-insert",
309044
+ image: "image",
309045
+ color: "text-color",
309046
+ highlight: "highlight-color",
309047
+ textAlign: "text-align",
309048
+ lineHeight: "line-height",
309049
+ linkedStyles: "linked-style",
309050
+ indentleft: "indent-decrease",
309051
+ indentright: "indent-increase",
309052
+ clearFormatting: "clear-formatting",
309053
+ copyFormat: "copy-format"
309054
+ };
309055
+ TABLE_ACTION_COMMAND_MAP = {
309056
+ addRowBefore: "table-add-row-before",
309057
+ addRowAfter: "table-add-row-after",
309058
+ deleteRow: "table-delete-row",
309059
+ addColumnBefore: "table-add-column-before",
309060
+ addColumnAfter: "table-add-column-after",
309061
+ deleteColumn: "table-delete-column",
309062
+ deleteTable: "table-delete",
309063
+ deleteCellAndTableBorders: "table-remove-borders",
309064
+ mergeCells: "table-merge-cells",
309065
+ splitCell: "table-split-cell",
309066
+ fixTables: "table-fix"
309067
+ };
309068
+ TABLE_ACTION_COMMAND_IDS = Object.values(TABLE_ACTION_COMMAND_MAP);
309069
+ HEADLESS_TOOLBAR_COMMANDS = [...new Set([...Object.values(HEADLESS_ITEM_MAP), ...TABLE_ACTION_COMMAND_IDS])];
309070
+ NON_HEADLESS_EXECUTE_ITEM_NAMES = new Set(["link"]);
309071
+ HEADLESS_EXECUTE_ITEMS = new Set(Object.keys(HEADLESS_ITEM_MAP).filter((itemName) => !NON_HEADLESS_EXECUTE_ITEM_NAMES.has(itemName)));
307901
309072
  _hoisted_1$11 = { class: "toolbar-icon" };
307902
309073
  _hoisted_2$7 = ["innerHTML"];
307903
309074
  ToolbarButtonIcon_default = /* @__PURE__ */ __plugin_vue_export_helper_default({
@@ -309281,11 +310452,13 @@ function print() { __p += __j.call(arguments, '') }
309281
310452
  };
309282
310453
  this.toolbarItems = [];
309283
310454
  this.overflowItems = [];
309284
- this.documentMode = config2.documentMode || "editing";
309285
310455
  this.isDev = config2.isDev || false;
309286
310456
  this.superdoc = config2.superdoc;
309287
310457
  this.role = config2.role || "editor";
309288
310458
  this.toolbarContainer = null;
310459
+ this.controller = null;
310460
+ this.snapshot = null;
310461
+ this._unsubscribeController = null;
309289
310462
  if (this.config.editor)
309290
310463
  this.config.mode = this.config.editor.options.mode;
309291
310464
  this.config.icons = {
@@ -309308,7 +310481,7 @@ function print() { __p += __j.call(arguments, '') }
309308
310481
  this._restoreFocusTimeoutId = null;
309309
310482
  if (!this.config.selector && this.config.element)
309310
310483
  this.config.selector = this.config.element;
309311
- this.toolbarContainer = this.findElementBySelector(this.config.selector);
310484
+ this.toolbarContainer = findElementBySelector(this.config.selector);
309312
310485
  if (this.toolbarContainer) {
309313
310486
  const uiFontFamily = (this.config?.uiDisplayFallbackFont || "").toString().trim() || "Arial, Helvetica, sans-serif";
309314
310487
  this.toolbarContainer.style.setProperty("--sd-ui-font-family", uiFontFamily);
@@ -309330,215 +310503,39 @@ function print() { __p += __j.call(arguments, '') }
309330
310503
  if (this.toolbarContainer)
309331
310504
  this.toolbar = this.app.mount(this.toolbarContainer);
309332
310505
  this.activeEditor = config2.editor || null;
310506
+ this.initHeadlessToolbar();
309333
310507
  this.updateToolbarState();
309334
310508
  }
309335
- findElementBySelector(selector) {
309336
- let el = null;
309337
- if (selector) {
309338
- if (selector.startsWith("#") || selector.startsWith("."))
309339
- el = document.querySelector(selector);
309340
- else
309341
- el = document.getElementById(selector);
309342
- if (!el)
309343
- return null;
309344
- }
309345
- return el;
310509
+ createHeadlessToolbar() {
310510
+ if (!this.superdoc)
310511
+ return null;
310512
+ return createHeadlessToolbar({
310513
+ superdoc: this.superdoc,
310514
+ commands: HEADLESS_TOOLBAR_COMMANDS
310515
+ });
310516
+ }
310517
+ initHeadlessToolbar() {
310518
+ if (!this.superdoc)
310519
+ return;
310520
+ this.destroyHeadlessToolbar();
310521
+ this.controller = this.createHeadlessToolbar();
310522
+ this.snapshot = this.controller.getSnapshot();
310523
+ this._unsubscribeController = this.controller.subscribe(({ snapshot: snapshot2 }) => {
310524
+ this.snapshot = snapshot2;
310525
+ this.updateToolbarState();
310526
+ });
310527
+ }
310528
+ destroyHeadlessToolbar() {
310529
+ this._unsubscribeController?.();
310530
+ this.controller?.destroy();
310531
+ this.controller = null;
310532
+ this.snapshot = null;
310533
+ this._unsubscribeController = null;
309346
310534
  }
309347
310535
  #initToolbarGroups() {
309348
310536
  if (this.config.groups && !Array.isArray(this.config.groups) && Object.keys(this.config.groups).length)
309349
310537
  this.config.toolbarGroups = Object.keys(this.config.groups);
309350
310538
  }
309351
- #interceptedCommands = {
309352
- setZoom: ({ item, argument }) => {
309353
- if (!argument)
309354
- return;
309355
- item.onActivate({ zoom: argument });
309356
- this.emit("superdoc-command", {
309357
- item,
309358
- argument
309359
- });
309360
- this.superdoc.superdocStore.activeZoom = parseInt(argument, 10);
309361
- },
309362
- setDocumentMode: ({ item, argument }) => {
309363
- if (!argument)
309364
- return;
309365
- this.emit("superdoc-command", {
309366
- item,
309367
- argument
309368
- });
309369
- },
309370
- setFontSize: ({ item, argument }) => {
309371
- if (this.#isFieldAnnotationSelection() && argument) {
309372
- this.activeEditor?.commands.setFieldAnnotationsFontSize(argument, true);
309373
- this.updateToolbarState();
309374
- return;
309375
- }
309376
- this.#runCommandWithArgumentOnly({
309377
- item,
309378
- argument
309379
- }, () => {
309380
- this.activeEditor?.commands.setFieldAnnotationsFontSize(argument, true);
309381
- });
309382
- },
309383
- setFontFamily: ({ item, argument }) => {
309384
- if (this.#isFieldAnnotationSelection() && argument) {
309385
- this.activeEditor?.commands.setFieldAnnotationsFontFamily(argument, true);
309386
- this.updateToolbarState();
309387
- return;
309388
- }
309389
- this.#runCommandWithArgumentOnly({
309390
- item,
309391
- argument
309392
- }, () => {
309393
- this.activeEditor?.commands.setFieldAnnotationsFontFamily(argument, true);
309394
- });
309395
- },
309396
- setColor: ({ argument }) => {
309397
- if (!argument || !this.activeEditor)
309398
- return;
309399
- const isNone = argument === "none";
309400
- const value = isNone ? "inherit" : argument;
309401
- if (this.activeEditor?.commands?.setColor)
309402
- this.activeEditor.commands.setColor(value);
309403
- const argValue = isNone ? null : argument;
309404
- this.activeEditor?.commands.setFieldAnnotationsTextColor(argValue, true);
309405
- this.updateToolbarState();
309406
- },
309407
- setHighlight: ({ argument }) => {
309408
- if (!argument || !this.activeEditor)
309409
- return;
309410
- const inlineColor = argument !== "none" ? argument : "transparent";
309411
- if (this.activeEditor?.commands?.setHighlight)
309412
- this.activeEditor.commands.setHighlight(inlineColor);
309413
- const argValue = argument !== "none" ? argument : null;
309414
- this.activeEditor?.commands.setFieldAnnotationsTextHighlight(argValue, true);
309415
- this.activeEditor?.commands.setCellBackground(argValue);
309416
- this.updateToolbarState();
309417
- },
309418
- toggleRuler: () => {
309419
- this.superdoc.toggleRuler();
309420
- this.updateToolbarState();
309421
- },
309422
- startImageUpload: async () => {
309423
- try {
309424
- let result = await getFileOpener()();
309425
- if (!result?.file)
309426
- return;
309427
- await processAndInsertImageFile({
309428
- file: result.file,
309429
- editor: this.activeEditor,
309430
- view: this.activeEditor.view,
309431
- editorOptions: this.activeEditor.options,
309432
- getMaxContentSize: () => this.activeEditor.getMaxContentSize()
309433
- });
309434
- } catch (error3) {
309435
- const err = /* @__PURE__ */ new Error("[super-toolbar \uD83C\uDFA8] Image upload failed");
309436
- this.emit("exception", {
309437
- error: err,
309438
- editor: this.activeEditor,
309439
- originalError: error3
309440
- });
309441
- console.error(err, error3);
309442
- }
309443
- },
309444
- increaseTextIndent: ({ item, argument }) => {
309445
- let command$1 = item.command;
309446
- if (this.activeEditor.commands.increaseListIndent?.())
309447
- return true;
309448
- if (command$1 in this.activeEditor.commands)
309449
- this.activeEditor.commands[command$1](argument);
309450
- },
309451
- decreaseTextIndent: ({ item, argument }) => {
309452
- let command$1 = item.command;
309453
- if (this.activeEditor.commands.decreaseListIndent?.())
309454
- return true;
309455
- if (command$1 in this.activeEditor.commands)
309456
- this.activeEditor.commands[command$1](argument);
309457
- },
309458
- toggleBold: ({ item, argument }) => {
309459
- if (this.#isFieldAnnotationSelection()) {
309460
- this.activeEditor?.commands.toggleFieldAnnotationsFormat("bold", true);
309461
- this.updateToolbarState();
309462
- return;
309463
- }
309464
- let command$1 = item.command;
309465
- if (command$1 in this.activeEditor.commands) {
309466
- this.activeEditor.commands[command$1](argument);
309467
- this.activeEditor.commands.toggleFieldAnnotationsFormat("bold", true);
309468
- }
309469
- this.updateToolbarState();
309470
- },
309471
- toggleItalic: ({ item, argument }) => {
309472
- if (this.#isFieldAnnotationSelection()) {
309473
- this.activeEditor?.commands.toggleFieldAnnotationsFormat("italic", true);
309474
- this.updateToolbarState();
309475
- return;
309476
- }
309477
- let command$1 = item.command;
309478
- if (command$1 in this.activeEditor.commands) {
309479
- this.activeEditor.commands[command$1](argument);
309480
- this.activeEditor.commands.toggleFieldAnnotationsFormat("italic", true);
309481
- }
309482
- this.updateToolbarState();
309483
- },
309484
- toggleUnderline: ({ item, argument }) => {
309485
- if (this.#isFieldAnnotationSelection()) {
309486
- this.activeEditor?.commands.toggleFieldAnnotationsFormat("underline", true);
309487
- this.updateToolbarState();
309488
- return;
309489
- }
309490
- let command$1 = item.command;
309491
- if (command$1 in this.activeEditor.commands) {
309492
- this.activeEditor.commands[command$1](argument);
309493
- this.activeEditor.commands.toggleFieldAnnotationsFormat("underline", true);
309494
- }
309495
- this.updateToolbarState();
309496
- },
309497
- toggleLink: ({ item, argument }) => {
309498
- let command$1 = item.command;
309499
- if (command$1 in this.activeEditor.commands) {
309500
- this.activeEditor.commands[command$1](argument);
309501
- const { view } = this.activeEditor;
309502
- let { selection } = view.state;
309503
- if (this.activeEditor.options.isHeaderOrFooter)
309504
- selection = this.activeEditor.options.lastSelection;
309505
- const endPos = selection.$to.pos;
309506
- const newSelection = new TextSelection(view.state.doc.resolve(endPos));
309507
- const tr = view.state.tr.setSelection(newSelection);
309508
- const state = view.state.apply(tr);
309509
- view.updateState(state);
309510
- if (!this.activeEditor.options.isHeaderOrFooter)
309511
- setTimeout(() => {
309512
- view.focus();
309513
- }, 100);
309514
- }
309515
- this.updateToolbarState();
309516
- },
309517
- insertTable: ({ item, argument }) => {
309518
- this.#runCommandWithArgumentOnly({
309519
- item,
309520
- argument
309521
- });
309522
- },
309523
- executeTableCommand: ({ argument }) => {
309524
- if (!argument)
309525
- return;
309526
- let command$1 = argument.command;
309527
- if (command$1 in this.activeEditor.commands)
309528
- this.activeEditor.commands[command$1](argument);
309529
- this.updateToolbarState();
309530
- }
309531
- };
309532
- log(...args$1) {
309533
- console.debug("[\uD83C\uDFA8 super-toolbar]", ...args$1);
309534
- }
309535
- setZoom(percent_int) {
309536
- const item = [...this.toolbarItems, ...this.overflowItems].find((item$1) => item$1.name.value === "zoom");
309537
- this.#interceptedCommands.setZoom({
309538
- item,
309539
- argument: percent_int
309540
- });
309541
- }
309542
310539
  setActiveEditor(editor) {
309543
310540
  if (this.activeEditor && this._boundEditorHandlers.transaction) {
309544
310541
  this.activeEditor.off("transaction", this._boundEditorHandlers.transaction);
@@ -309626,7 +310623,7 @@ function print() { __p += __j.call(arguments, '') }
309626
310623
  const documentModeItem = this.getToolbarItemByName("documentMode");
309627
310624
  if (!documentModeItem)
309628
310625
  return;
309629
- const mode = (this.documentMode || "editing").toLowerCase();
310626
+ const mode = (this.snapshot?.commands?.["document-mode"]?.value || "editing").toLowerCase();
309630
310627
  const texts = this.config.texts || {};
309631
310628
  const icons$1 = this.config.icons || {};
309632
310629
  const map$12 = {
@@ -309651,12 +310648,127 @@ function print() { __p += __j.call(arguments, '') }
309651
310648
  if (documentModeItem.icon?.value !== undefined && next2.icon)
309652
310649
  documentModeItem.icon.value = next2.icon;
309653
310650
  }
310651
+ #getFontFamilyFallbackValue() {
310652
+ if (!this.activeEditor?.state)
310653
+ return null;
310654
+ const { state } = this.activeEditor;
310655
+ const selection = state.selection;
310656
+ if (!selection?.empty)
310657
+ return null;
310658
+ const paragraphParent = findParentNode((n) => n.type.name === "paragraph")(selection);
310659
+ if (!paragraphParent || paragraphParent.node?.content?.size !== 0)
310660
+ return null;
310661
+ return getParagraphFontFamilyFromProperties(calculateResolvedParagraphProperties(this.activeEditor, paragraphParent.node, state.doc.resolve(paragraphParent.pos)), this.activeEditor?.converter?.convertedXml ?? {}) || null;
310662
+ }
310663
+ #isFontSizeMixedState(commandState) {
310664
+ return Boolean(commandState?.active) && commandState?.value == null;
310665
+ }
310666
+ #applyHeadlessState(item) {
310667
+ if (item.name.value === "tableActions") {
310668
+ const hasAnyEnabled = TABLE_ACTION_COMMAND_IDS.map((commandId$1) => this.snapshot?.commands?.[commandId$1]).some((state) => state && !state.disabled);
310669
+ item.setDisabled(!hasAnyEnabled);
310670
+ return true;
310671
+ }
310672
+ const commandId = HEADLESS_ITEM_MAP[item.name.value];
310673
+ if (!commandId)
310674
+ return false;
310675
+ const commandState = this.snapshot?.commands?.[commandId];
310676
+ const setDisabled = () => {
310677
+ item.setDisabled(Boolean(commandState?.disabled));
310678
+ };
310679
+ const handlers3 = {
310680
+ textAlign: () => {
310681
+ if (commandState?.value)
310682
+ item.activate({ textAlign: commandState.value });
310683
+ else
310684
+ item.deactivate();
310685
+ },
310686
+ lineHeight: () => {
310687
+ item.selectedValue.value = commandState?.value != null ? commandState.value : "";
310688
+ },
310689
+ zoom: () => {
310690
+ if (commandState?.value != null) {
310691
+ const value = typeof commandState.value === "number" ? `${commandState.value}%` : String(commandState.value);
310692
+ item.onActivate({ zoom: value });
310693
+ }
310694
+ },
310695
+ documentMode: () => {
310696
+ this.#syncDocumentModeUi();
310697
+ },
310698
+ link: () => {
310699
+ item.active.value = Boolean(commandState?.active);
310700
+ item.attributes.value = commandState?.value ? { href: commandState.value } : {};
310701
+ },
310702
+ fontFamily: () => {
310703
+ if (commandState?.value != null) {
310704
+ item.activate({ fontFamily: commandState.value });
310705
+ return;
310706
+ }
310707
+ const fallbackFontFamily = this.#getFontFamilyFallbackValue();
310708
+ if (fallbackFontFamily) {
310709
+ item.activate({ fontFamily: fallbackFontFamily });
310710
+ return;
310711
+ }
310712
+ item.deactivate();
310713
+ },
310714
+ fontSize: () => {
310715
+ if (commandState?.value != null) {
310716
+ item.activate({ fontSize: commandState.value });
310717
+ return;
310718
+ }
310719
+ if (this.#isFontSizeMixedState(commandState)) {
310720
+ item.activate({}, true);
310721
+ return;
310722
+ }
310723
+ item.deactivate();
310724
+ },
310725
+ color: () => {
310726
+ if (commandState?.value != null)
310727
+ item.activate({ color: commandState.value });
310728
+ else
310729
+ item.deactivate();
310730
+ },
310731
+ highlight: () => {
310732
+ if (commandState?.value != null)
310733
+ item.activate({ color: commandState.value });
310734
+ else
310735
+ item.deactivate();
310736
+ },
310737
+ linkedStyles: () => {
310738
+ if (commandState?.value != null)
310739
+ item.activate({ styleId: commandState.value });
310740
+ else
310741
+ item.label.value = this.config.texts?.formatText || "Format text";
310742
+ },
310743
+ default: () => {
310744
+ if (commandState?.active)
310745
+ item.activate();
310746
+ else
310747
+ item.deactivate();
310748
+ }
310749
+ };
310750
+ const handler2 = handlers3[item.name.value] ?? handlers3.default;
310751
+ setDisabled();
310752
+ handler2();
310753
+ return true;
310754
+ }
310755
+ #executeHeadlessCommand(item, argument) {
310756
+ const isTableActions = item?.name?.value === "tableActions";
310757
+ const commandId = isTableActions ? TABLE_ACTION_COMMAND_MAP[argument?.command] : HEADLESS_ITEM_MAP[item?.name?.value];
310758
+ if (!commandId || !this.controller?.execute)
310759
+ return false;
310760
+ if (isTableActions)
310761
+ this.controller.execute(commandId);
310762
+ else
310763
+ this.controller.execute(commandId, argument);
310764
+ return true;
310765
+ }
309654
310766
  updateToolbarState() {
309655
310767
  this.#syncDocumentModeUi();
309656
- this.#updateToolbarHistory();
309657
310768
  this.#initDefaultFonts();
309658
310769
  this.#updateHighlightColors();
309659
- if (!this.activeEditor || this.documentMode === "viewing") {
310770
+ const currentMode = this.snapshot?.commands?.["document-mode"]?.value || "editing";
310771
+ if (!this.activeEditor || currentMode === "viewing") {
309660
310772
  this.#deactivateAll();
309661
310773
  return;
309662
310774
  }
@@ -309665,96 +310777,9 @@ function print() { __p += __j.call(arguments, '') }
309665
310777
  this.#deactivateAll();
309666
310778
  return;
309667
310779
  }
309668
- const selection = state.selection;
309669
- const selectionTrackedChanges = this.#enrichTrackedChanges(collectTrackedChanges({
309670
- state,
309671
- from: selection.from,
309672
- to: selection.to
309673
- }));
309674
- const hasValidSelection = selectionTrackedChanges.length > 0;
309675
- const canAcceptTrackedChanges = hasValidSelection && isTrackedChangeActionAllowed({
309676
- editor: this.activeEditor,
309677
- action: "accept",
309678
- trackedChanges: selectionTrackedChanges
309679
- });
309680
- const canRejectTrackedChanges = hasValidSelection && isTrackedChangeActionAllowed({
309681
- editor: this.activeEditor,
309682
- action: "reject",
309683
- trackedChanges: selectionTrackedChanges
309684
- });
309685
- const marks = getActiveFormatting(this.activeEditor);
309686
- const inTable = isInTable(this.activeEditor.state);
309687
- const paragraphParent = findParentNode((n) => n.type.name === "paragraph")(selection);
309688
- const paragraphProps = paragraphParent ? calculateResolvedParagraphProperties(this.activeEditor, paragraphParent.node, state.doc.resolve(paragraphParent.pos)) : null;
309689
- const selectionIsCollapsed = selection.empty;
309690
- const paragraphIsEmpty = paragraphParent?.node?.content?.size === 0;
309691
- const paragraphFontFamily = getParagraphFontFamilyFromProperties(paragraphProps, this.activeEditor?.converter?.convertedXml ?? {});
309692
310780
  this.toolbarItems.forEach((item) => {
309693
310781
  item.resetDisabled();
309694
- let activatedFromLinkedStyle = false;
309695
- if (item.name.value === "undo")
309696
- item.setDisabled(this.undoDepth === 0);
309697
- if (item.name.value === "redo")
309698
- item.setDisabled(this.redoDepth === 0);
309699
- if (item.name.value === "acceptTrackedChangeBySelection")
309700
- item.setDisabled(!canAcceptTrackedChanges);
309701
- if (item.name.value === "rejectTrackedChangeOnSelection")
309702
- item.setDisabled(!canRejectTrackedChanges);
309703
- if (item.name.value === "linkedStyles")
309704
- if (this.activeEditor && !getQuickFormatList(this.activeEditor).length)
309705
- return item.deactivate();
309706
- else
309707
- return item.activate({ styleId: paragraphProps?.styleId || null });
309708
- const rawActiveMark = marks.find((mark2) => mark2.name === item.name.value);
309709
- const markNegated = rawActiveMark ? isNegatedMark(rawActiveMark.name, rawActiveMark.attrs) : false;
309710
- const activeMark = markNegated ? null : rawActiveMark;
309711
- if (activeMark)
309712
- if (activeMark.name === "fontSize") {
309713
- const fontSizes = marks.filter((i4) => i4.name === "fontSize").map((i4) => i4.attrs.fontSize);
309714
- const isMultiple = [...new Set(fontSizes)].length > 1;
309715
- item.activate(activeMark.attrs, isMultiple);
309716
- } else
309717
- item.activate(activeMark.attrs);
309718
- else
309719
- item.deactivate();
309720
- if (!activeMark && !markNegated && paragraphParent && paragraphProps?.styleId) {
309721
- const markToStyleMap = {
309722
- fontSize: "font-size",
309723
- fontFamily: "font-family",
309724
- bold: "bold"
309725
- };
309726
- const linkedStyles = this.activeEditor.converter?.linkedStyles.find((style2) => style2.id === paragraphProps.styleId);
309727
- if (linkedStyles && linkedStyles.definition && linkedStyles.definition.styles && markToStyleMap[item.name.value] in linkedStyles.definition.styles) {
309728
- const linkedStylesItem = linkedStyles.definition.styles[markToStyleMap[item.name.value]];
309729
- const value = { [item.name.value]: linkedStylesItem };
309730
- item.activate(value);
309731
- activatedFromLinkedStyle = true;
309732
- }
309733
- }
309734
- if (item.name.value === "textAlign" && paragraphProps?.justification)
309735
- item.activate({ textAlign: paragraphProps.justification });
309736
- if (item.name.value === "fontFamily" && selectionIsCollapsed && paragraphIsEmpty && !activeMark && !markNegated && !activatedFromLinkedStyle && paragraphFontFamily)
309737
- item.activate({ fontFamily: paragraphFontFamily });
309738
- if (item.name.value === "lineHeight")
309739
- if (paragraphProps?.spacing)
309740
- item.selectedValue.value = twipsToLines(paragraphProps.spacing.line);
309741
- else
309742
- item.selectedValue.value = "";
309743
- if (item.name.value === "tableActions")
309744
- item.disabled.value = !inTable;
309745
- const listParent = isList(paragraphParent?.node) ? paragraphParent.node : null;
309746
- if (listParent) {
309747
- const numberingType = listParent.attrs.listRendering.numberingType;
309748
- if (item.name.value === "list" && numberingType === "bullet")
309749
- item.activate();
309750
- else if (item.name.value === "numberedlist" && numberingType !== "bullet")
309751
- item.activate();
309752
- }
309753
- if (item.name.value === "ruler")
309754
- if (this.superdoc?.config?.rulers)
309755
- item.activate();
309756
- else
309757
- item.deactivate();
310782
+ this.#applyHeadlessState(item);
309758
310783
  });
309759
310784
  }
309760
310785
  onToolbarResize = () => {
@@ -309779,48 +310804,22 @@ function print() { __p += __j.call(arguments, '') }
309779
310804
  item.setDisabled(true);
309780
310805
  });
309781
310806
  }
309782
- #updateToolbarHistory() {
309783
- if (!this.activeEditor?.state)
309784
- return;
309785
- try {
309786
- if (this.activeEditor.options.ydoc) {
309787
- const undoManager = yUndoPluginKey.getState(this.activeEditor.state)?.undoManager;
309788
- this.undoDepth = undoManager?.undoStack.length || 0;
309789
- this.redoDepth = undoManager?.redoStack.length || 0;
309790
- } else {
309791
- this.undoDepth = undoDepth(this.activeEditor.state);
309792
- this.redoDepth = redoDepth(this.activeEditor.state);
309793
- }
309794
- } catch {
309795
- this.undoDepth = 0;
309796
- this.redoDepth = 0;
309797
- }
309798
- }
309799
- #enrichTrackedChanges(trackedChanges = []) {
309800
- if (!trackedChanges?.length)
309801
- return trackedChanges;
309802
- const store = this.superdoc?.commentsStore;
309803
- if (!store?.getComment)
309804
- return trackedChanges;
309805
- return trackedChanges.map((change) => {
309806
- const commentId = change.id;
309807
- if (!commentId)
309808
- return change;
309809
- const storeComment = store.getComment(commentId);
309810
- if (!storeComment)
309811
- return change;
309812
- const comment2 = typeof storeComment.getValues === "function" ? storeComment.getValues() : storeComment;
309813
- return {
309814
- ...change,
309815
- comment: comment2
309816
- };
309817
- });
309818
- }
309819
310807
  onEditorTransaction({ transaction }) {
309820
310808
  if (!transaction.docChanged && !transaction.selectionSet)
309821
310809
  return;
309822
310810
  this.updateToolbarState();
309823
310811
  }
310812
+ #scheduleRestoreEditorFocus() {
310813
+ if (!this.activeEditor || this.activeEditor.options.isHeaderOrFooter)
310814
+ return;
310815
+ clearTimeout(this._restoreFocusTimeoutId);
310816
+ this._restoreFocusTimeoutId = setTimeout(() => {
310817
+ this._restoreFocusTimeoutId = null;
310818
+ if (!this.activeEditor || this.activeEditor.options.isHeaderOrFooter)
310819
+ return;
310820
+ this.activeEditor.focus();
310821
+ }, 0);
310822
+ }
309824
310823
  emitCommand({ item, argument, option }) {
309825
310824
  const hasFocusFn = this.activeEditor?.view?.hasFocus;
309826
310825
  const wasFocused = Boolean(typeof hasFocusFn === "function" && hasFocusFn.call(this.activeEditor.view));
@@ -309851,14 +310850,21 @@ function print() { __p += __j.call(arguments, '') }
309851
310850
  this.activeEditor.focus();
309852
310851
  if (!command$1)
309853
310852
  return;
309854
- if (command$1 in this.#interceptedCommands) {
309855
- const result = this.#interceptedCommands[command$1]({
309856
- item,
309857
- argument
309858
- });
309859
- if (isMarkToggle)
309860
- this.#syncStickyMarksFromState();
309861
- return result;
310853
+ if (item?.name?.value === "tableActions") {
310854
+ if (this.#executeHeadlessCommand(item, argument)) {
310855
+ this.updateToolbarState();
310856
+ return;
310857
+ }
310858
+ }
310859
+ if (HEADLESS_EXECUTE_ITEMS.has(item?.name?.value)) {
310860
+ if (this.#executeHeadlessCommand(item, argument)) {
310861
+ if (isMarkToggle)
310862
+ this.#syncStickyMarksFromState();
310863
+ this.updateToolbarState();
310864
+ if (shouldRestoreFocus)
310865
+ this.#scheduleRestoreEditorFocus();
310866
+ return;
310867
+ }
309862
310868
  }
309863
310869
  if (this.activeEditor && this.activeEditor.commands && command$1 in this.activeEditor.commands)
309864
310870
  this.activeEditor.commands[command$1](argument);
@@ -309879,13 +310885,8 @@ function print() { __p += __j.call(arguments, '') }
309879
310885
  if (isMarkToggle)
309880
310886
  this.#syncStickyMarksFromState();
309881
310887
  this.updateToolbarState();
309882
- if (shouldRestoreFocus && this.activeEditor && !this.activeEditor.options.isHeaderOrFooter)
309883
- this._restoreFocusTimeoutId = setTimeout(() => {
309884
- this._restoreFocusTimeoutId = null;
309885
- if (!this.activeEditor || this.activeEditor.options.isHeaderOrFooter)
309886
- return;
309887
- this.activeEditor.focus();
309888
- }, 0);
310888
+ if (shouldRestoreFocus)
310889
+ this.#scheduleRestoreEditorFocus();
309889
310890
  }
309890
310891
  onEditorSelectionUpdate() {
309891
310892
  if (!this.activeEditor)
@@ -309897,12 +310898,16 @@ function print() { __p += __j.call(arguments, '') }
309897
310898
  if (!command$1)
309898
310899
  return;
309899
310900
  try {
309900
- if (command$1 in this.#interceptedCommands)
309901
- this.#interceptedCommands[command$1]({
309902
- item,
309903
- argument
309904
- });
309905
- else if (this.activeEditor.commands && command$1 in this.activeEditor.commands)
310901
+ if (HEADLESS_EXECUTE_ITEMS.has(item?.name?.value)) {
310902
+ if (this.#executeHeadlessCommand(item, argument)) {
310903
+ this.#ensureStoredMarksForMarkToggle({
310904
+ command: command$1,
310905
+ argument
310906
+ });
310907
+ return;
310908
+ }
310909
+ }
310910
+ if (this.activeEditor.commands && command$1 in this.activeEditor.commands)
309906
310911
  this.activeEditor.commands[command$1](argument);
309907
310912
  this.#ensureStoredMarksForMarkToggle({
309908
310913
  command: command$1,
@@ -309937,25 +310942,6 @@ function print() { __p += __j.call(arguments, '') }
309937
310942
  const name = item?.name?.value;
309938
310943
  return SuperToolbar2.#MARK_TOGGLE_NAMES.has(name);
309939
310944
  }
309940
- #runCommandWithArgumentOnly({ item, argument, noArgumentCallback = false }, callback) {
309941
- if (!argument || !this.activeEditor)
309942
- return;
309943
- let command$1 = item.command;
309944
- const noArgumentCommand = item.noArgumentCommand;
309945
- if (argument === "none" && this.activeEditor && this.activeEditor.commands && noArgumentCommand in this.activeEditor.commands) {
309946
- this.activeEditor.commands[noArgumentCommand]();
309947
- if (typeof callback === "function" && noArgumentCallback)
309948
- callback(argument);
309949
- this.updateToolbarState();
309950
- return;
309951
- }
309952
- if (this.activeEditor && this.activeEditor.commands && command$1 in this.activeEditor.commands) {
309953
- this.activeEditor.commands[command$1](argument);
309954
- if (typeof callback === "function")
309955
- callback(argument);
309956
- this.updateToolbarState();
309957
- }
309958
- }
309959
310945
  #syncStickyMarksFromState() {
309960
310946
  if (!this.activeEditor)
309961
310947
  return;
@@ -310005,15 +310991,12 @@ function print() { __p += __j.call(arguments, '') }
310005
310991
  const tr = state.tr.setStoredMarks([mark2]);
310006
310992
  view.dispatch(tr);
310007
310993
  }
310008
- #isFieldAnnotationSelection() {
310009
- const selection = this.activeEditor?.state?.selection;
310010
- return selection instanceof NodeSelection && selection?.node?.type?.name === "fieldAnnotation";
310011
- }
310012
310994
  destroy() {
310013
310995
  if (this._restoreFocusTimeoutId !== null) {
310014
310996
  clearTimeout(this._restoreFocusTimeoutId);
310015
310997
  this._restoreFocusTimeoutId = null;
310016
310998
  }
310999
+ this.destroyHeadlessToolbar();
310017
311000
  }
310018
311001
  };
310019
311002
  Commands = Extension.create({
@@ -320832,7 +321815,7 @@ function print() { __p += __j.call(arguments, '') }
320832
321815
  const range = computeWordSelectionRangeAt(state, pos);
320833
321816
  if (!range)
320834
321817
  return false;
320835
- const tr = state.tr.setSelection(TextSelection2.create(state.doc, range.from, range.to));
321818
+ const tr = state.tr.setSelection(TextSelection.create(state.doc, range.from, range.to));
320836
321819
  try {
320837
321820
  this.#editor.view?.dispatch(tr);
320838
321821
  return true;
@@ -320849,7 +321832,7 @@ function print() { __p += __j.call(arguments, '') }
320849
321832
  const range = computeParagraphSelectionRangeAt(state, pos);
320850
321833
  if (!range)
320851
321834
  return false;
320852
- const tr = state.tr.setSelection(TextSelection2.create(state.doc, range.from, range.to));
321835
+ const tr = state.tr.setSelection(TextSelection.create(state.doc, range.from, range.to));
320853
321836
  try {
320854
321837
  this.#editor.view?.dispatch(tr);
320855
321838
  return true;
@@ -321672,8 +322655,8 @@ function print() { __p += __j.call(arguments, '') }
321672
322655
  }
321673
322656
  try {
321674
322657
  this.#localSelectionLayer.innerHTML = "";
321675
- const isFieldAnnotationSelection = selection instanceof NodeSelection && selection.node?.type?.name === "fieldAnnotation";
321676
- if (domRects.length > 0 && !isFieldAnnotationSelection)
322658
+ const isFieldAnnotationSelection2 = selection instanceof NodeSelection && selection.node?.type?.name === "fieldAnnotation";
322659
+ if (domRects.length > 0 && !isFieldAnnotationSelection2)
321677
322660
  renderSelectionRects({
321678
322661
  localSelectionLayer: this.#localSelectionLayer,
321679
322662
  rects: domRects,
@@ -322104,7 +323087,7 @@ function print() { __p += __j.call(arguments, '') }
322104
323087
  if (current.from === desiredFrom && current.to === desiredTo)
322105
323088
  return;
322106
323089
  try {
322107
- const tr = this.#editor.state.tr.setSelection(TextSelection2.create(this.#editor.state.doc, selAnchor, selHead));
323090
+ const tr = this.#editor.state.tr.setSelection(TextSelection.create(this.#editor.state.doc, selAnchor, selHead));
322108
323091
  this.#editor.view?.dispatch(tr);
322109
323092
  this.#scheduleSelectionUpdate();
322110
323093
  } catch {}
@@ -322918,11 +323901,11 @@ var init_zipper_DbkgrypV_es = __esm(() => {
322918
323901
 
322919
323902
  // ../../packages/superdoc/dist/super-editor.es.js
322920
323903
  var init_super_editor_es = __esm(() => {
322921
- init_src_DjgWBzME_es();
323904
+ init_src_DlMaB1h_es();
322922
323905
  init_SuperConverter_BgwP1GeS_es();
322923
323906
  init_jszip_C49i9kUs_es();
322924
323907
  init_xml_js_CqGKpaft_es();
322925
- init_create_headless_toolbar_zEz71NHQ_es();
323908
+ init_create_headless_toolbar_Dcw4Hyt2_es();
322926
323909
  init_constants_CGhJRd87_es();
322927
323910
  init_dist_B8HfvhaK_es();
322928
323911
  init_unified_Dsuw2be5_es();