@superdoc-dev/cli 0.7.0-next.16 → 0.7.0-next.18

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 +1401 -562
  2. package/package.json +9 -9
package/dist/index.js CHANGED
@@ -7984,6 +7984,7 @@ function buildContentControlSchemas() {
7984
7984
  kind: { enum: ["block", "inline"] },
7985
7985
  controlType: { type: "string" },
7986
7986
  target: contentControlTargetSchema,
7987
+ at: selectionTargetSchema,
7987
7988
  tag: { type: "string" },
7988
7989
  alias: { type: "string" },
7989
7990
  lockMode: { enum: ["unlocked", "sdtLocked", "contentLocked", "sdtContentLocked"] },
@@ -17670,9 +17671,15 @@ function executeCreateContentControl(adapter, input, options) {
17670
17671
  if (input.lockMode !== undefined && !VALID_LOCK_MODES.has(input.lockMode)) {
17671
17672
  throw new DocumentApiValidationError("INVALID_INPUT", `create.contentControl lockMode must be one of: ${[...VALID_LOCK_MODES].join(", ")}.`, { field: "lockMode", value: input.lockMode });
17672
17673
  }
17674
+ if (input.at !== undefined && input.target !== undefined) {
17675
+ throw new DocumentApiValidationError("INVALID_INPUT", `create.contentControl: "at" and "target" are mutually exclusive — provide one or neither.`, { field: "at" });
17676
+ }
17673
17677
  if (input.target !== undefined) {
17674
17678
  validateCCTarget(input.target, "create.contentControl");
17675
17679
  }
17680
+ if (input.at !== undefined && !isSelectionTarget(input.at)) {
17681
+ throw new DocumentApiValidationError("INVALID_INPUT", `create.contentControl: "at" must be a valid SelectionTarget with kind "selection", start, and end.`, { field: "at", value: input.at });
17682
+ }
17676
17683
  if (input.content !== undefined && typeof input.content !== "string") {
17677
17684
  throw new DocumentApiValidationError("INVALID_INPUT", `create.contentControl content must be a string, got ${typeof input.content}.`, { field: "content", value: input.content });
17678
17685
  }
@@ -17682,6 +17689,7 @@ var VALID_NODE_KINDS, VALID_LOCK_MODES, VALID_CC_TYPES, VALID_CC_APPEARANCES, VA
17682
17689
  var init_content_controls = __esm(() => {
17683
17690
  init_errors2();
17684
17691
  init_validation_primitives();
17692
+ init_selection_target_validator();
17685
17693
  init_content_controls_types();
17686
17694
  init_base();
17687
17695
  VALID_NODE_KINDS = new Set(NODE_KINDS);
@@ -65493,7 +65501,7 @@ var init_remark_gfm_BhnWr3yf_es = __esm(() => {
65493
65501
  emptyOptions2 = {};
65494
65502
  });
65495
65503
 
65496
- // ../../packages/superdoc/dist/chunks/SuperConverter-w6yaFRT5.es.js
65504
+ // ../../packages/superdoc/dist/chunks/SuperConverter-BgwP1GeS.es.js
65497
65505
  function getExtensionConfigField(extension$1, field, context = { name: "" }) {
65498
65506
  const fieldValue = extension$1.config[field];
65499
65507
  if (typeof fieldValue === "function")
@@ -67608,6 +67616,7 @@ function buildContentControlSchemas2() {
67608
67616
  kind: { enum: ["block", "inline"] },
67609
67617
  controlType: { type: "string" },
67610
67618
  target: contentControlTargetSchema2,
67619
+ at: selectionTargetSchema2,
67611
67620
  tag: { type: "string" },
67612
67621
  alias: { type: "string" },
67613
67622
  lockMode: { enum: [
@@ -71740,8 +71749,15 @@ function executeCreateContentControl2(adapter, input, options) {
71740
71749
  field: "lockMode",
71741
71750
  value: input.lockMode
71742
71751
  });
71752
+ if (input.at !== undefined && input.target !== undefined)
71753
+ throw new DocumentApiValidationError2("INVALID_INPUT", `create.contentControl: "at" and "target" are mutually exclusive — provide one or neither.`, { field: "at" });
71743
71754
  if (input.target !== undefined)
71744
71755
  validateCCTarget2(input.target, "create.contentControl");
71756
+ if (input.at !== undefined && !isSelectionTarget2(input.at))
71757
+ throw new DocumentApiValidationError2("INVALID_INPUT", `create.contentControl: "at" must be a valid SelectionTarget with kind "selection", start, and end.`, {
71758
+ field: "at",
71759
+ value: input.at
71760
+ });
71745
71761
  if (input.content !== undefined && typeof input.content !== "string")
71746
71762
  throw new DocumentApiValidationError2("INVALID_INPUT", `create.contentControl content must be a string, got ${typeof input.content}.`, {
71747
71763
  field: "content",
@@ -76843,7 +76859,7 @@ function checkTextSelection($pos) {
76843
76859
  }
76844
76860
  function findSelectionIn(doc$2, node3, pos, index2, dir, text$2 = false) {
76845
76861
  if (node3.inlineContent)
76846
- return TextSelection2.create(doc$2, pos);
76862
+ return TextSelection.create(doc$2, pos);
76847
76863
  for (let i$1 = index2 - (dir > 0 ? 0 : 1);dir > 0 ? i$1 < node3.childCount : i$1 >= 0; i$1 += dir) {
76848
76864
  let child = node3.child(i$1);
76849
76865
  if (!child.isAtom) {
@@ -80028,7 +80044,7 @@ function selectionToDOM(view, force = false) {
80028
80044
  selectCursorWrapper(view);
80029
80045
  else {
80030
80046
  let { anchor, head } = sel, resetEditableFrom, resetEditableTo;
80031
- if (brokenSelectBetweenUneditable && !(sel instanceof TextSelection2)) {
80047
+ if (brokenSelectBetweenUneditable && !(sel instanceof TextSelection)) {
80032
80048
  if (!sel.$from.parent.inlineContent)
80033
80049
  resetEditableFrom = temporarilyEditableNear(view, sel.from);
80034
80050
  if (!sel.empty && !sel.$from.parent.inlineContent)
@@ -80129,7 +80145,7 @@ function clearNodeSelection(view) {
80129
80145
  }
80130
80146
  }
80131
80147
  function selectionBetween(view, $anchor, $head, bias) {
80132
- 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);
80133
80149
  }
80134
80150
  function hasFocusAndSelection(view) {
80135
80151
  if (view.editable && !view.hasFocus())
@@ -80163,13 +80179,13 @@ function apply(view, sel) {
80163
80179
  }
80164
80180
  function selectHorizontally(view, dir, mods) {
80165
80181
  let sel = view.state.selection;
80166
- if (sel instanceof TextSelection2) {
80182
+ if (sel instanceof TextSelection) {
80167
80183
  if (mods.indexOf("s") > -1) {
80168
80184
  let { $head } = sel, node3 = $head.textOffset ? null : dir < 0 ? $head.nodeBefore : $head.nodeAfter;
80169
80185
  if (!node3 || node3.isText || !node3.isLeaf)
80170
80186
  return false;
80171
80187
  let $newHead = view.state.doc.resolve($head.pos + node3.nodeSize * (dir < 0 ? -1 : 1));
80172
- return apply(view, new TextSelection2(sel.$anchor, $newHead));
80188
+ return apply(view, new TextSelection(sel.$anchor, $newHead));
80173
80189
  } else if (!sel.empty)
80174
80190
  return false;
80175
80191
  else if (view.endOfTextblock(dir > 0 ? "forward" : "backward")) {
@@ -80187,12 +80203,12 @@ function selectHorizontally(view, dir, mods) {
80187
80203
  if (NodeSelection.isSelectable(node3))
80188
80204
  return apply(view, new NodeSelection(dir < 0 ? view.state.doc.resolve($head.pos - node3.nodeSize) : $head));
80189
80205
  else if (webkit)
80190
- 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)));
80191
80207
  else
80192
80208
  return false;
80193
80209
  }
80194
80210
  } else if (sel instanceof NodeSelection && sel.node.isInline)
80195
- return apply(view, new TextSelection2(dir > 0 ? sel.$to : sel.$from));
80211
+ return apply(view, new TextSelection(dir > 0 ? sel.$to : sel.$from));
80196
80212
  else {
80197
80213
  let next = moveSelectionBlock(view.state, dir);
80198
80214
  if (next)
@@ -80381,7 +80397,7 @@ function findDirection(view, pos) {
80381
80397
  }
80382
80398
  function selectVertically(view, dir, mods) {
80383
80399
  let sel = view.state.selection;
80384
- if (sel instanceof TextSelection2 && !sel.empty || mods.indexOf("s") > -1)
80400
+ if (sel instanceof TextSelection && !sel.empty || mods.indexOf("s") > -1)
80385
80401
  return false;
80386
80402
  if (mac$2 && mods.indexOf("m") > -1)
80387
80403
  return false;
@@ -80399,7 +80415,7 @@ function selectVertically(view, dir, mods) {
80399
80415
  return false;
80400
80416
  }
80401
80417
  function stopNativeHorizontalDelete(view, dir) {
80402
- if (!(view.state.selection instanceof TextSelection2))
80418
+ if (!(view.state.selection instanceof TextSelection))
80403
80419
  return true;
80404
80420
  let { $head, $anchor, empty: empty$1 } = view.state.selection;
80405
80421
  if (!$head.sameParent($anchor))
@@ -80830,7 +80846,7 @@ function defaultTripleClick(view, inside, event) {
80830
80846
  let doc$2 = view.state.doc;
80831
80847
  if (inside == -1) {
80832
80848
  if (doc$2.inlineContent) {
80833
- 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");
80834
80850
  return true;
80835
80851
  }
80836
80852
  return false;
@@ -80840,7 +80856,7 @@ function defaultTripleClick(view, inside, event) {
80840
80856
  let node3 = i$1 > $pos.depth ? $pos.nodeAfter : $pos.node(i$1);
80841
80857
  let nodePos = $pos.before(i$1);
80842
80858
  if (node3.inlineContent)
80843
- 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");
80844
80860
  else if (NodeSelection.isSelectable(node3))
80845
80861
  updateSelection(view, NodeSelection.create(doc$2, nodePos), "pointer");
80846
80862
  else
@@ -81425,7 +81441,7 @@ function readDOMChange(view, from4, to, typeOver, addedNodes) {
81425
81441
  return;
81426
81442
  }
81427
81443
  if (!change)
81428
- 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))
81429
81445
  change = {
81430
81446
  start: sel.from,
81431
81447
  endA: sel.to,
@@ -81443,7 +81459,7 @@ function readDOMChange(view, from4, to, typeOver, addedNodes) {
81443
81459
  }
81444
81460
  return;
81445
81461
  }
81446
- 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) {
81447
81463
  if (change.start > view.state.selection.from && change.start <= view.state.selection.from + 2 && view.state.selection.from >= parse$1.from)
81448
81464
  change.start = view.state.selection.from;
81449
81465
  else if (change.endA < view.state.selection.to && change.endA >= view.state.selection.to - 2 && view.state.selection.to <= parse$1.to) {
@@ -82083,10 +82099,10 @@ function normalizeSelection(state, tr, allowTableNodeSelection) {
82083
82099
  const lastCell = start + map4.map[map4.width * map4.height - 1];
82084
82100
  normalize$1 = CellSelection.create(doc$2, start + 1, lastCell);
82085
82101
  }
82086
- } else if (sel instanceof TextSelection2 && isCellBoundarySelection(sel))
82087
- normalize$1 = TextSelection2.create(doc$2, sel.from);
82088
- else if (sel instanceof TextSelection2 && isTextSelectionAcrossCells(sel))
82089
- 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());
82090
82106
  if (normalize$1)
82091
82107
  (tr || (tr = state.tr)).setSelection(normalize$1);
82092
82108
  return tr;
@@ -82616,7 +82632,7 @@ function goToNextCell(direction) {
82616
82632
  return false;
82617
82633
  if (dispatch) {
82618
82634
  const $cell = state.doc.resolve(cell);
82619
- dispatch(state.tr.setSelection(TextSelection2.between($cell, moveCellForward($cell))).scrollIntoView());
82635
+ dispatch(state.tr.setSelection(TextSelection.between($cell, moveCellForward($cell))).scrollIntoView());
82620
82636
  }
82621
82637
  return true;
82622
82638
  };
@@ -83005,7 +83021,7 @@ function handleMouseDown$1(view, startEvent) {
83005
83021
  view.root.addEventListener("mousemove", move);
83006
83022
  }
83007
83023
  function atEndOfCell(view, axis, dir) {
83008
- if (!(view.state.selection instanceof TextSelection2))
83024
+ if (!(view.state.selection instanceof TextSelection))
83009
83025
  return null;
83010
83026
  const { $head } = view.state.selection;
83011
83027
  for (let d = $head.depth - 1;d >= 0; d--) {
@@ -83505,7 +83521,7 @@ function stableStringifyInlineProps(inlineProps) {
83505
83521
  function createSelectionPreserver(tr, originalSelection, originalStoredMarks = null) {
83506
83522
  if (!originalSelection)
83507
83523
  return null;
83508
- const isTextSelection$1 = originalSelection instanceof TextSelection2;
83524
+ const isTextSelection$1 = originalSelection instanceof TextSelection;
83509
83525
  let preservedAnchor = isTextSelection$1 ? originalSelection.anchor : null;
83510
83526
  let preservedHead = isTextSelection$1 ? originalSelection.head : null;
83511
83527
  const anchorAssoc = preservedAnchor != null && preservedHead != null && preservedAnchor <= preservedHead ? -1 : 1;
@@ -83545,7 +83561,7 @@ function createSelectionPreserver(tr, originalSelection, originalStoredMarks = n
83545
83561
  if (!tr.docChanged)
83546
83562
  return;
83547
83563
  if (isTextSelection$1 && preservedAnchor != null && preservedHead != null) {
83548
- tr.setSelection(TextSelection2.create(tr.doc, preservedAnchor, preservedHead));
83564
+ tr.setSelection(TextSelection.create(tr.doc, preservedAnchor, preservedHead));
83549
83565
  if (preservedAnchor === preservedHead && originalStoredMarks !== null)
83550
83566
  tr.setStoredMarks(originalStoredMarks);
83551
83567
  return;
@@ -84801,7 +84817,7 @@ function canAllocateRels(editor) {
84801
84817
  function handlePlainTextUrlPaste(editor, view, plainText, detected) {
84802
84818
  const { state } = view;
84803
84819
  const { selection } = state;
84804
- if (!(selection instanceof TextSelection2))
84820
+ if (!(selection instanceof TextSelection))
84805
84821
  return false;
84806
84822
  const linkMarkType = editor.schema.marks.link;
84807
84823
  const underlineMarkType = editor.schema.marks.underline;
@@ -104768,7 +104784,7 @@ var isRegExp = (value) => {
104768
104784
  }
104769
104785
  }
104770
104786
  static findFrom($pos, dir, textOnly = false) {
104771
- 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);
104772
104788
  if (inner)
104773
104789
  return inner;
104774
104790
  for (let depth = $pos.depth - 1;depth >= 0; depth--) {
@@ -104803,14 +104819,14 @@ var isRegExp = (value) => {
104803
104819
  return selectionClass;
104804
104820
  }
104805
104821
  getBookmark() {
104806
- return TextSelection2.between(this.$anchor, this.$head).getBookmark();
104822
+ return TextSelection.between(this.$anchor, this.$head).getBookmark();
104807
104823
  }
104808
104824
  }, SelectionRange = class {
104809
104825
  constructor($from, $to) {
104810
104826
  this.$from = $from;
104811
104827
  this.$to = $to;
104812
104828
  }
104813
- }, warnedAboutTextSelection = false, TextSelection2, TextBookmark = class TextBookmark2 {
104829
+ }, warnedAboutTextSelection = false, TextSelection, TextBookmark = class TextBookmark2 {
104814
104830
  constructor(anchor, head) {
104815
104831
  this.anchor = anchor;
104816
104832
  this.head = head;
@@ -104819,7 +104835,7 @@ var isRegExp = (value) => {
104819
104835
  return new TextBookmark2(mapping.map(this.anchor), mapping.map(this.head));
104820
104836
  }
104821
104837
  resolve(doc$2) {
104822
- 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));
104823
104839
  }
104824
104840
  }, NodeSelection, NodeBookmark = class NodeBookmark2 {
104825
104841
  constructor(anchor) {
@@ -109271,7 +109287,7 @@ var isRegExp = (value) => {
109271
109287
  return false;
109272
109288
  return group.split(" ").includes("list");
109273
109289
  }, isTextSelection = (value) => {
109274
- return value instanceof TextSelection2;
109290
+ return value instanceof TextSelection;
109275
109291
  }, domIndex = function(node3) {
109276
109292
  for (var index2 = 0;; index2++) {
109277
109293
  node3 = node3.previousSibling;
@@ -117203,7 +117219,7 @@ var isRegExp = (value) => {
117203
117219
  state.kern = kernNode.attributes["w:val"];
117204
117220
  }
117205
117221
  }, SuperConverter;
117206
- var init_SuperConverter_w6yaFRT5_es = __esm(() => {
117222
+ var init_SuperConverter_BgwP1GeS_es = __esm(() => {
117207
117223
  init_rolldown_runtime_Bg48TavK_es();
117208
117224
  init_jszip_C49i9kUs_es();
117209
117225
  init_xml_js_CqGKpaft_es();
@@ -133383,7 +133399,7 @@ var init_SuperConverter_w6yaFRT5_es = __esm(() => {
133383
133399
  TransformError.prototype.name = "TransformError";
133384
133400
  classesById = Object.create(null);
133385
133401
  Selection.prototype.visible = true;
133386
- TextSelection2 = class TextSelection3 extends Selection {
133402
+ TextSelection = class TextSelection2 extends Selection {
133387
133403
  constructor($anchor, $head = $anchor) {
133388
133404
  checkTextSelection($anchor);
133389
133405
  checkTextSelection($head);
@@ -133397,7 +133413,7 @@ var init_SuperConverter_w6yaFRT5_es = __esm(() => {
133397
133413
  if (!$head.parent.inlineContent)
133398
133414
  return Selection.near($head);
133399
133415
  let $anchor = doc$2.resolve(mapping.map(this.anchor));
133400
- return new TextSelection3($anchor.parent.inlineContent ? $anchor : $head, $head);
133416
+ return new TextSelection2($anchor.parent.inlineContent ? $anchor : $head, $head);
133401
133417
  }
133402
133418
  replace(tr, content$2 = Slice.empty) {
133403
133419
  super.replace(tr, content$2);
@@ -133408,7 +133424,7 @@ var init_SuperConverter_w6yaFRT5_es = __esm(() => {
133408
133424
  }
133409
133425
  }
133410
133426
  eq(other) {
133411
- 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;
133412
133428
  }
133413
133429
  getBookmark() {
133414
133430
  return new TextBookmark(this.anchor, this.head);
@@ -133423,7 +133439,7 @@ var init_SuperConverter_w6yaFRT5_es = __esm(() => {
133423
133439
  static fromJSON(doc$2, json) {
133424
133440
  if (typeof json.anchor != "number" || typeof json.head != "number")
133425
133441
  throw new RangeError("Invalid input for TextSelection.fromJSON");
133426
- 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));
133427
133443
  }
133428
133444
  static create(doc$2, anchor, head = anchor) {
133429
133445
  let $anchor = doc$2.resolve(anchor);
@@ -133448,10 +133464,10 @@ var init_SuperConverter_w6yaFRT5_es = __esm(() => {
133448
133464
  if ($anchor.pos < $head.pos != dPos < 0)
133449
133465
  $anchor = $head;
133450
133466
  }
133451
- return new TextSelection3($anchor, $head);
133467
+ return new TextSelection2($anchor, $head);
133452
133468
  }
133453
133469
  };
133454
- Selection.jsonID("text", TextSelection2);
133470
+ Selection.jsonID("text", TextSelection);
133455
133471
  NodeSelection = class NodeSelection2 extends Selection {
133456
133472
  constructor($pos) {
133457
133473
  let node3 = $pos.nodeAfter;
@@ -145102,7 +145118,7 @@ var init_SuperConverter_w6yaFRT5_es = __esm(() => {
145102
145118
  }
145103
145119
  localCompositionInfo(view, pos) {
145104
145120
  let { from: from4, to } = view.state.selection;
145105
- 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)
145106
145122
  return null;
145107
145123
  let textNode = view.input.compositionNode;
145108
145124
  if (!textNode || !this.dom.contains(textNode.parentNode))
@@ -145364,7 +145380,7 @@ var init_SuperConverter_w6yaFRT5_es = __esm(() => {
145364
145380
  return;
145365
145381
  }
145366
145382
  let sel = view.state.selection;
145367
- if (!(sel instanceof TextSelection2) || !sel.$from.sameParent(sel.$to)) {
145383
+ if (!(sel instanceof TextSelection) || !sel.$from.sameParent(sel.$to)) {
145368
145384
  let text$2 = String.fromCharCode(event.charCode);
145369
145385
  let deflt = () => view.state.tr.insertText(text$2).scrollIntoView();
145370
145386
  if (!/[\r\n]/.test(text$2) && !view.someProp("handleTextInput", (f2) => f2(view, sel.$from.pos, sel.$to.pos, text$2, deflt)))
@@ -145418,7 +145434,7 @@ var init_SuperConverter_w6yaFRT5_es = __esm(() => {
145418
145434
  if (!view.composing) {
145419
145435
  view.domObserver.flush();
145420
145436
  let { state } = view, $pos = state.selection.$to;
145421
- 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))) {
145422
145438
  view.markCursor = view.state.storedMarks || $pos.marks();
145423
145439
  endComposition(view, true);
145424
145440
  view.markCursor = null;
@@ -145751,7 +145767,7 @@ var init_SuperConverter_w6yaFRT5_es = __esm(() => {
145751
145767
  else
145752
145768
  return new CellSelection$1($anchorCell, $headCell);
145753
145769
  }
145754
- return TextSelection2.between($anchorCell, $headCell);
145770
+ return TextSelection.between($anchorCell, $headCell);
145755
145771
  }
145756
145772
  content() {
145757
145773
  const table = this.$anchorCell.node(-1);
@@ -154449,7 +154465,7 @@ var init_SuperConverter_w6yaFRT5_es = __esm(() => {
154449
154465
  };
154450
154466
  });
154451
154467
 
154452
- // ../../packages/superdoc/dist/chunks/create-headless-toolbar-CHK8yJic.es.js
154468
+ // ../../packages/superdoc/dist/chunks/create-headless-toolbar-Dcw4Hyt2.es.js
154453
154469
  function parseSizeUnit(val = "0") {
154454
154470
  const length3 = val.toString() || "0";
154455
154471
  const value = Number.parseFloat(length3);
@@ -154460,7 +154476,7 @@ function getPreservedSelection(state) {
154460
154476
  return CustomSelectionPluginKey.getState(state)?.preservedSelection ?? null;
154461
154477
  }
154462
154478
  function createSelectionTrackingBookmark(selection) {
154463
- if (selection instanceof TextSelection2 && !selection.empty)
154479
+ if (selection instanceof TextSelection && !selection.empty)
154464
154480
  return new InclusiveTextSelectionBookmark(selection.anchor, selection.head);
154465
154481
  return selection.getBookmark();
154466
154482
  }
@@ -154747,7 +154763,7 @@ var CSS_DIMENSION_REGEX, DOM_SIZE_UNITS, Extension = class Extension2 {
154747
154763
  return new InclusiveTextSelectionBookmark2(mapping.map(this.anchor, isForward ? -1 : 1), mapping.map(this.head, isForward ? 1 : -1));
154748
154764
  }
154749
154765
  resolve(doc2) {
154750
- return TextSelection2.between(doc2.resolve(this.anchor), doc2.resolve(this.head));
154766
+ return TextSelection.between(doc2.resolve(this.anchor), doc2.resolve(this.head));
154751
154767
  }
154752
154768
  }, nextHandleId = 1, SelectionHandlePluginKey, DEFAULT_MIME_TYPE = "application/octet-stream", simpleHash2 = (str) => {
154753
154769
  let hash = 0;
@@ -156049,6 +156065,246 @@ var CSS_DIMENSION_REGEX, DOM_SIZE_UNITS, Extension = class Extension2 {
156049
156065
  comment: change.comment ?? null
156050
156066
  }) !== false;
156051
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;
156052
156308
  }, isOffValue = (value) => {
156053
156309
  if (value == null)
156054
156310
  return false;
@@ -156059,9 +156315,750 @@ var CSS_DIMENSION_REGEX, DOM_SIZE_UNITS, Extension = class Extension2 {
156059
156315
  if (typeof checker !== "function")
156060
156316
  return false;
156061
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
+ };
156062
157059
  };
156063
- var init_create_headless_toolbar_CHK8yJic_es = __esm(() => {
156064
- init_SuperConverter_w6yaFRT5_es();
157060
+ var init_create_headless_toolbar_Dcw4Hyt2_es = __esm(() => {
157061
+ init_SuperConverter_BgwP1GeS_es();
156065
157062
  init_constants_CGhJRd87_es();
156066
157063
  init_dist_B8HfvhaK_es();
156067
157064
  CSS_DIMENSION_REGEX = /[\d-.]+(\w+)$/;
@@ -204499,7 +205496,7 @@ var init_remark_gfm_eZN6yzWQ_es = __esm(() => {
204499
205496
  init_remark_gfm_BhnWr3yf_es();
204500
205497
  });
204501
205498
 
204502
- // ../../packages/superdoc/dist/chunks/src-84ZC-Jm8.es.js
205499
+ // ../../packages/superdoc/dist/chunks/src-yUVuhLM1.es.js
204503
205500
  function deleteProps(obj, propOrProps) {
204504
205501
  const props = typeof propOrProps === "string" ? [propOrProps] : propOrProps;
204505
205502
  const removeNested = (target, pathParts, index2 = 0) => {
@@ -205224,9 +206221,9 @@ function mapPreservedSelection(selection, tr) {
205224
206221
  function applySelectionCleanup(editor, tr) {
205225
206222
  let cleaned = tr.setMeta(CustomSelectionPluginKey, DEFAULT_SELECTION_STATE);
205226
206223
  const sel = cleaned.selection;
205227
- if (sel && sel instanceof TextSelection2 && !sel.empty)
206224
+ if (sel && sel instanceof TextSelection && !sel.empty)
205228
206225
  try {
205229
- const collapsed = TextSelection2.create(cleaned.doc, sel.head);
206226
+ const collapsed = TextSelection.create(cleaned.doc, sel.head);
205230
206227
  cleaned = cleaned.setSelection(collapsed);
205231
206228
  } catch {}
205232
206229
  editor.setOptions({
@@ -205339,7 +206336,7 @@ function arrow$1(axis, dir) {
205339
206336
  return function(state, dispatch, view) {
205340
206337
  let sel = state.selection;
205341
206338
  let $start = dir > 0 ? sel.$to : sel.$from, mustMove = sel.empty;
205342
- if (sel instanceof TextSelection2) {
206339
+ if (sel instanceof TextSelection) {
205343
206340
  if (!view.endOfTextblock(dirStr) || $start.depth == 0)
205344
206341
  return false;
205345
206342
  mustMove = false;
@@ -205379,7 +206376,7 @@ function beforeinput(view, event) {
205379
206376
  for (let i4 = insert.length - 1;i4 >= 0; i4--)
205380
206377
  frag = Fragment.from(insert[i4].createAndFill(null, frag));
205381
206378
  let tr = view.state.tr.replace($from.pos, $from.pos, new Slice(frag, 0, 0));
205382
- tr.setSelection(TextSelection2.near(tr.doc.resolve($from.pos + 1)));
206379
+ tr.setSelection(TextSelection.near(tr.doc.resolve($from.pos + 1)));
205383
206380
  view.dispatch(tr);
205384
206381
  return false;
205385
206382
  }
@@ -206266,7 +207263,7 @@ function createStructuredContentSelectPlugin(editor) {
206266
207263
  for (let od = old$pos.depth;od > 0; od--)
206267
207264
  if (old$pos.node(od).type.name === "structuredContent" && old$pos.before(od) === sdtStart)
206268
207265
  return null;
206269
- return newState.tr.setSelection(TextSelection2.create(newState.doc, contentFrom, contentTo));
207266
+ return newState.tr.setSelection(TextSelection.create(newState.doc, contentFrom, contentTo));
206270
207267
  }
206271
207268
  return null;
206272
207269
  } });
@@ -206477,7 +207474,7 @@ function splitBlockPatch(state, dispatch, editor) {
206477
207474
  }
206478
207475
  }
206479
207476
  let tr = state.tr;
206480
- if (state.selection instanceof TextSelection2 || state.selection instanceof AllSelection)
207477
+ if (state.selection instanceof TextSelection || state.selection instanceof AllSelection)
206481
207478
  tr.deleteSelection();
206482
207479
  let splitPos = tr.mapping.map($from.pos);
206483
207480
  let can = canSplit(tr.doc, splitPos, types3.length, types3);
@@ -206682,7 +207679,7 @@ function splitBlockAs(splitNode) {
206682
207679
  types3.unshift(null);
206683
207680
  }
206684
207681
  let tr = state.tr;
206685
- if (state.selection instanceof TextSelection2 || state.selection instanceof AllSelection)
207682
+ if (state.selection instanceof TextSelection || state.selection instanceof AllSelection)
206686
207683
  tr.deleteSelection();
206687
207684
  let splitPos = tr.mapping.map($from.pos);
206688
207685
  let can = canSplit(tr.doc, splitPos, types3.length, types3);
@@ -206780,7 +207777,7 @@ function selectTextblockSide(side) {
206780
207777
  if (!$pos.node(depth).isTextblock)
206781
207778
  return false;
206782
207779
  if (dispatch)
206783
- 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))));
206784
207781
  return true;
206785
207782
  };
206786
207783
  }
@@ -207108,7 +208105,7 @@ function skipTab(dir) {
207108
208105
  return false;
207109
208106
  const nextPos = dir > 0 ? Math.min($nextPos.pos + nextNode.nodeSize + 1, state.doc.nodeSize) : Math.max(0, $nextPos.pos - nextNode.nodeSize - 1);
207110
208107
  if (dispatch)
207111
- dispatch(state.tr.setSelection(TextSelection2.create(state.doc, nextPos)));
208108
+ dispatch(state.tr.setSelection(TextSelection.create(state.doc, nextPos)));
207112
208109
  return true;
207113
208110
  };
207114
208111
  }
@@ -208828,7 +209825,7 @@ function getTableBoundaryExitSelection(state, dir) {
208828
209825
  const boundaryPos = helpers.getTableBoundaryPos(context);
208829
209826
  const targetPos = helpers.findTextPosAcrossBoundary(state, boundaryPos);
208830
209827
  if (targetPos != null)
208831
- return TextSelection2.create(state.doc, targetPos);
209828
+ return TextSelection.create(state.doc, targetPos);
208832
209829
  return findSelectionNearBoundary(state, boundaryPos, dir);
208833
209830
  }
208834
209831
  function getAdjacentTableEntrySelection(state, dir) {
@@ -208849,13 +209846,13 @@ function getAdjacentTableEntrySelection(state, dir) {
208849
209846
  if (dir > 0) {
208850
209847
  const targetPos$1 = findFirstTextPosInNode(adjacentNode, boundaryPos);
208851
209848
  if (targetPos$1 != null)
208852
- return TextSelection2.create(state.doc, targetPos$1);
209849
+ return TextSelection.create(state.doc, targetPos$1);
208853
209850
  return findSelectionNearBoundary(state, boundaryPos, 1);
208854
209851
  }
208855
209852
  const tablePos = boundaryPos - adjacentNode.nodeSize;
208856
209853
  const targetPos = findLastTextPosInNode(adjacentNode, tablePos);
208857
209854
  if (targetPos != null)
208858
- return TextSelection2.create(state.doc, targetPos);
209855
+ return TextSelection.create(state.doc, targetPos);
208859
209856
  return findSelectionNearBoundary(state, tablePos + adjacentNode.nodeSize, -1);
208860
209857
  }
208861
209858
  function createTableBoundaryNavigationPlugin() {
@@ -209199,7 +210196,7 @@ function insertRowAtIndex({ tr, tablePos, tableNode, sourceRowIndex, insertIndex
209199
210196
  if (newRow) {
209200
210197
  tr.insert(insertPos, newRow);
209201
210198
  const cursorPos = insertPos + ROW_START_TO_TEXT_OFFSET;
209202
- tr.setSelection(TextSelection2.create(tr.doc, cursorPos));
210199
+ tr.setSelection(TextSelection.create(tr.doc, cursorPos));
209203
210200
  const firstTextNode = newCells[0].firstChild?.firstChild;
209204
210201
  if (firstTextNode?.marks?.length)
209205
210202
  tr.setStoredMarks(firstTextNode.marks);
@@ -209208,7 +210205,7 @@ function insertRowAtIndex({ tr, tablePos, tableNode, sourceRowIndex, insertIndex
209208
210205
  }
209209
210206
  } else if (cellsToExtend.length > 0) {
209210
210207
  const cursorPos = cellsToExtend[0].pos + CELL_TO_TEXT_OFFSET;
209211
- tr.setSelection(TextSelection2.create(tr.doc, cursorPos));
210208
+ tr.setSelection(TextSelection.create(tr.doc, cursorPos));
209212
210209
  }
209213
210210
  return true;
209214
210211
  }
@@ -212939,7 +213936,7 @@ function findCommand(wrap5, dir) {
212939
213936
  let next2 = dir > 0 ? nextMatch(search$1, state, wrap5, from$1, to) : prevMatch(search$1, state, wrap5, from$1, to);
212940
213937
  if (!next2)
212941
213938
  return false;
212942
- let selection = TextSelection2.create(state.doc, next2.from, next2.to);
213939
+ let selection = TextSelection.create(state.doc, next2.from, next2.to);
212943
213940
  if (dispatch)
212944
213941
  dispatch(state.tr.setSelection(selection).scrollIntoView());
212945
213942
  return true;
@@ -212964,14 +213961,14 @@ function replaceCommand(wrap5, moveForward) {
212964
213961
  }
212965
213962
  let after2 = moveForward && nextMatch(search$1, state, wrap5, next2.from, next2.to);
212966
213963
  if (after2)
212967
- 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)));
212968
213965
  else
212969
- 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)));
212970
213967
  dispatch(tr.scrollIntoView());
212971
213968
  } else if (!moveForward)
212972
213969
  return false;
212973
213970
  else
212974
- 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());
212975
213972
  return true;
212976
213973
  };
212977
213974
  }
@@ -213041,9 +214038,9 @@ function buildSelection(state, pos, extend) {
213041
214038
  const clamped = Math.max(0, Math.min(pos, doc$12.content.size));
213042
214039
  if (extend) {
213043
214040
  const anchor = selection.anchor ?? selection.from;
213044
- return TextSelection2.create(doc$12, anchor, clamped);
214041
+ return TextSelection.create(doc$12, anchor, clamped);
213045
214042
  }
213046
- return TextSelection2.create(doc$12, clamped);
214043
+ return TextSelection.create(doc$12, clamped);
213047
214044
  }
213048
214045
  function findLineElementAtPoint(doc$12, x, y$1) {
213049
214046
  if (typeof doc$12?.elementsFromPoint !== "function")
@@ -216205,13 +217202,6 @@ function scrollToElement(targetElement, options = {
216205
217202
  behavior: options.behavior
216206
217203
  });
216207
217204
  }
216208
- function getParagraphFontFamilyFromProperties(paragraphProps, convertedXml = {}) {
216209
- const fontFamilyProps = paragraphProps?.runProperties?.fontFamily;
216210
- if (!fontFamilyProps)
216211
- return null;
216212
- const [markDef] = encodeMarksFromRPr({ fontFamily: fontFamilyProps }, convertedXml);
216213
- return markDef?.attrs?.fontFamily ?? null;
216214
- }
216215
217205
  function getDefaultExportFromCjs2(x) {
216216
217206
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
216217
217207
  }
@@ -226316,7 +227306,7 @@ function applyTextSelection(editor, from$1, to) {
226316
227306
  }
226317
227307
  if (editor.state?.tr && typeof editor.dispatch === "function")
226318
227308
  try {
226319
- const tr = editor.state.tr.setSelection(TextSelection2.create(editor.state.doc, from$1, to)).setMeta("inputType", "programmatic");
227309
+ const tr = editor.state.tr.setSelection(TextSelection.create(editor.state.doc, from$1, to)).setMeta("inputType", "programmatic");
226320
227310
  editor.dispatch(tr);
226321
227311
  return true;
226322
227312
  } catch {
@@ -238713,8 +239703,7 @@ function groupUngroupWrapper(editor, input2, options) {
238713
239703
  }
238714
239704
  function createWrapper(editor, input2, options) {
238715
239705
  const commandName = input2.kind === "block" ? "insertStructuredContentBlock" : "insertStructuredContentInline";
238716
- const insertCmd = editor.commands?.[commandName];
238717
- if (typeof insertCmd !== "function")
239706
+ if (typeof editor.commands?.[commandName] !== "function")
238718
239707
  throw new DocumentApiAdapterError("CAPABILITY_UNAVAILABLE", `${commandName} command not available.`);
238719
239708
  const id2 = generateSdtId();
238720
239709
  const target = {
@@ -238767,17 +239756,26 @@ function createWrapper(editor, input2, options) {
238767
239756
  dispatchTransaction(editor, tr);
238768
239757
  return true;
238769
239758
  }
239759
+ if (input2.at) {
239760
+ const { absFrom, absTo } = resolveSelectionTarget(editor, input2.at);
239761
+ const { tr } = editor.state;
239762
+ tr.setSelection(TextSelection.create(tr.doc, absFrom, absTo));
239763
+ dispatchTransaction(editor, tr);
239764
+ }
239765
+ const cmd = editor.commands?.[commandName];
239766
+ if (typeof cmd !== "function")
239767
+ return false;
238770
239768
  if (contentText !== undefined) {
238771
239769
  if (input2.kind === "block") {
238772
239770
  if (isCheckboxCreate)
238773
- return Boolean(insertCmd({
239771
+ return Boolean(cmd({
238774
239772
  attrs,
238775
239773
  json: {
238776
239774
  type: "paragraph",
238777
239775
  content: [buildCheckboxTextJson(checkboxSymbol)]
238778
239776
  }
238779
239777
  }));
238780
- return Boolean(insertCmd({
239778
+ return Boolean(cmd({
238781
239779
  attrs,
238782
239780
  json: {
238783
239781
  type: "paragraph",
@@ -238789,16 +239787,16 @@ function createWrapper(editor, input2, options) {
238789
239787
  }));
238790
239788
  }
238791
239789
  if (isCheckboxCreate)
238792
- return Boolean(insertCmd({
239790
+ return Boolean(cmd({
238793
239791
  attrs,
238794
239792
  json: buildCheckboxTextJson(checkboxSymbol)
238795
239793
  }));
238796
- return Boolean(insertCmd({
239794
+ return Boolean(cmd({
238797
239795
  attrs,
238798
239796
  text: contentText
238799
239797
  }));
238800
239798
  }
238801
- return Boolean(insertCmd({ attrs }));
239799
+ return Boolean(cmd({ attrs }));
238802
239800
  });
238803
239801
  }
238804
239802
  function createContentControlsAdapter(editor) {
@@ -254914,13 +255912,13 @@ function normalizeFieldAnnotationMetadata(attrs) {
254914
255912
  displayLabel: toOptionalString(attrs.displayLabel),
254915
255913
  defaultDisplayLabel: toOptionalString(attrs.defaultDisplayLabel),
254916
255914
  alias: toOptionalString(attrs.alias),
254917
- fieldColor: normalizeColorValue(attrs.fieldColor),
254918
- borderColor: normalizeColorValue(attrs.borderColor),
255915
+ fieldColor: normalizeColorValue2(attrs.fieldColor),
255916
+ borderColor: normalizeColorValue2(attrs.borderColor),
254919
255917
  highlighted: toBoolean$2(attrs.highlighted, true),
254920
255918
  fontFamily: toNullableString(attrs.fontFamily),
254921
255919
  fontSize: normalizeFontSize$1(attrs.fontSize),
254922
- textColor: normalizeColorValue(attrs.textColor) ?? null,
254923
- textHighlight: normalizeColorValue(attrs.textHighlight) ?? null,
255920
+ textColor: normalizeColorValue2(attrs.textColor) ?? null,
255921
+ textHighlight: normalizeColorValue2(attrs.textHighlight) ?? null,
254924
255922
  linkUrl: toNullableString(attrs.linkUrl),
254925
255923
  imageSrc: toNullableString(attrs.imageSrc),
254926
255924
  rawHtml: attrs.rawHtml ?? undefined,
@@ -255004,7 +256002,7 @@ function normalizeVisibility(value) {
255004
256002
  if (normalized === "visible" || normalized === "hidden")
255005
256003
  return normalized;
255006
256004
  }
255007
- function normalizeColorValue(value) {
256005
+ function normalizeColorValue2(value) {
255008
256006
  if (typeof value !== "string")
255009
256007
  return;
255010
256008
  const trimmed = value.trim();
@@ -262039,7 +263037,7 @@ var Node$13 = class Node$14 {
262039
263037
  const anchor = relativePositionToAbsolutePosition(binding.doc, binding.type, relSel.anchor, binding.mapping);
262040
263038
  const head = relativePositionToAbsolutePosition(binding.doc, binding.type, relSel.head, binding.mapping);
262041
263039
  if (anchor !== null && head !== null) {
262042
- const sel = TextSelection2.between(tr.doc.resolve(anchor), tr.doc.resolve(head));
263040
+ const sel = TextSelection.between(tr.doc.resolve(anchor), tr.doc.resolve(head));
262043
263041
  tr.setSelection(sel);
262044
263042
  }
262045
263043
  }
@@ -262124,7 +263122,7 @@ var Node$13 = class Node$14 {
262124
263122
  if (sel) {
262125
263123
  const clampedAnchor = min$1(max$1(sel.anchor, 0), tr.doc.content.size);
262126
263124
  const clampedHead = min$1(max$1(sel.head, 0), tr.doc.content.size);
262127
- tr.setSelection(TextSelection2.create(tr.doc, clampedAnchor, clampedHead));
263125
+ tr.setSelection(TextSelection.create(tr.doc, clampedAnchor, clampedHead));
262128
263126
  }
262129
263127
  this.prosemirrorView.dispatch(tr.setMeta(ySyncPluginKey, {
262130
263128
  isChangeOrigin: true,
@@ -264012,19 +265010,19 @@ var Node$13 = class Node$14 {
264012
265010
  const leftRun = runType.create(run2.attrs, leftFrag, run2.marks);
264013
265011
  const rightRun = runType.create(run2.attrs, rightFrag, run2.marks);
264014
265012
  const gapPos = runStart + leftRun.nodeSize;
264015
- tr.replaceWith(runStart, runEnd, [leftRun, rightRun]).setSelection(TextSelection2.create(tr.doc, gapPos));
265013
+ tr.replaceWith(runStart, runEnd, [leftRun, rightRun]).setSelection(TextSelection.create(tr.doc, gapPos));
264016
265014
  if (dispatch)
264017
265015
  dispatch(tr);
264018
265016
  return true;
264019
265017
  }, cleanupEmptyRunsPlugin, preserveStoredMarks = (state, tr) => {
264020
- if (!(tr.selection instanceof TextSelection2) || !tr.selection.empty)
265018
+ if (!(tr.selection instanceof TextSelection) || !tr.selection.empty)
264021
265019
  return;
264022
265020
  if (state.storedMarks === null)
264023
265021
  return;
264024
265022
  tr.setStoredMarks(state.storedMarks);
264025
265023
  }, normalizeSelectionIntoRun = (tr, runType) => {
264026
265024
  const selection = tr.selection;
264027
- if (!(selection instanceof TextSelection2))
265025
+ if (!(selection instanceof TextSelection))
264028
265026
  return;
264029
265027
  if (selection.from !== selection.to)
264030
265028
  return;
@@ -264035,14 +265033,14 @@ var Node$13 = class Node$14 {
264035
265033
  if (nodeAfter?.type === runType && nodeAfter.content.size > 0) {
264036
265034
  const nextPos = selection.from + 1;
264037
265035
  if (nextPos <= tr.doc.content.size)
264038
- tr.setSelection(TextSelection2.create(tr.doc, nextPos));
265036
+ tr.setSelection(TextSelection.create(tr.doc, nextPos));
264039
265037
  return;
264040
265038
  }
264041
265039
  const nodeBefore = $pos.nodeBefore;
264042
265040
  if (nodeBefore?.type === runType && nodeBefore.content.size > 0) {
264043
265041
  const prevPos = selection.from - 1;
264044
265042
  if (prevPos >= 0)
264045
- tr.setSelection(TextSelection2.create(tr.doc, prevPos));
265043
+ tr.setSelection(TextSelection.create(tr.doc, prevPos));
264046
265044
  }
264047
265045
  }, copyRunPropertiesFromParagraph = (state, pos, textNode, runType, editor) => {
264048
265046
  let updatedTextNode = textNode;
@@ -264180,7 +265178,7 @@ var Node$13 = class Node$14 {
264180
265178
  const runProperties = getSplitRunProperties(state, $from);
264181
265179
  newAttrs = syncSplitParagraphRunProperties(newAttrs, runProperties);
264182
265180
  }
264183
- if (selection instanceof TextSelection2)
265181
+ if (selection instanceof TextSelection)
264184
265182
  tr.deleteSelection();
264185
265183
  const deflt = $from.depth === 0 ? null : defaultBlockAt($from.node(-1).contentMatchAt($from.indexAfter(-1)));
264186
265184
  let types3 = atEnd && deflt ? [{
@@ -264252,7 +265250,7 @@ var Node$13 = class Node$14 {
264252
265250
  const { from: from$1 } = tr.selection;
264253
265251
  const tabText = state.schema.text("\t");
264254
265252
  tr = tr.replaceSelectionWith(tabText);
264255
- tr = tr.setSelection(TextSelection2.create(tr.doc, from$1 + 1));
265253
+ tr = tr.setSelection(TextSelection.create(tr.doc, from$1 + 1));
264256
265254
  if (dispatch)
264257
265255
  dispatch(tr);
264258
265256
  return true;
@@ -264280,7 +265278,7 @@ var Node$13 = class Node$14 {
264280
265278
  newPos = tr.selection.from;
264281
265279
  }
264282
265280
  tr.insert(newPos, tabNode);
264283
- tr = tr.setSelection(TextSelection2.create(tr.doc, newPos + tabNode.nodeSize));
265281
+ tr = tr.setSelection(TextSelection.create(tr.doc, newPos + tabNode.nodeSize));
264284
265282
  if (dispatch)
264285
265283
  dispatch(tr);
264286
265284
  return true;
@@ -264449,7 +265447,7 @@ var Node$13 = class Node$14 {
264449
265447
  if (dispatch) {
264450
265448
  let side = (!$from.parentOffset && $to.index() < $to.parent.childCount ? $from : $to).pos;
264451
265449
  let tr = state.tr.insert(side, type.createAndFill());
264452
- tr.setSelection(TextSelection2.create(tr.doc, side + 1));
265450
+ tr.setSelection(TextSelection.create(tr.doc, side + 1));
264453
265451
  dispatch(tr.scrollIntoView());
264454
265452
  }
264455
265453
  return true;
@@ -265177,7 +266175,7 @@ var Node$13 = class Node$14 {
265177
266175
  const paraPos = $from.before();
265178
266176
  let tr = state.tr.deleteRange(paraPos, paraPos + para.nodeSize).scrollIntoView();
265179
266177
  const targetPos = Math.max(1, Math.min(paraPos - 1, tr.doc.content.size));
265180
- tr = tr.setSelection(TextSelection2.create(tr.doc, targetPos));
266178
+ tr = tr.setSelection(TextSelection.create(tr.doc, targetPos));
265181
266179
  dispatch(tr);
265182
266180
  }
265183
266181
  return true;
@@ -265443,7 +266441,7 @@ var Node$13 = class Node$14 {
265443
266441
  if (selection.empty && paragraphsInSelection.length === 1)
265444
266442
  tr.setSelection(Selection.near(tr.doc.resolve(restoredSelectionRange.to), -1));
265445
266443
  else
265446
- tr.setSelection(TextSelection2.create(tr.doc, restoredSelectionRange.from, restoredSelectionRange.to));
266444
+ tr.setSelection(TextSelection.create(tr.doc, restoredSelectionRange.from, restoredSelectionRange.to));
265447
266445
  } catch {}
265448
266446
  }
265449
266447
  dispatch(tr);
@@ -265552,7 +266550,7 @@ var Node$13 = class Node$14 {
265552
266550
  return true;
265553
266551
  }, restoreSelection = () => ({ editor, state, tr }) => {
265554
266552
  if (editor.options.lastSelection) {
265555
- tr.setSelection(TextSelection2.create(state.doc, editor.options.lastSelection.from, editor.options.lastSelection.to));
266553
+ tr.setSelection(TextSelection.create(state.doc, editor.options.lastSelection.from, editor.options.lastSelection.to));
265556
266554
  return true;
265557
266555
  }
265558
266556
  return false;
@@ -265564,7 +266562,7 @@ var Node$13 = class Node$14 {
265564
266562
  const nextFrom = clamp$1(typeof from$1 === "number" ? from$1 : state.selection.from, 0, docSize);
265565
266563
  const nextTo = clamp$1(typeof to === "number" ? to : nextFrom, 0, docSize);
265566
266564
  const [head, anchor] = nextFrom <= nextTo ? [nextFrom, nextTo] : [nextTo, nextFrom];
265567
- const selection = TextSelection2.create(doc$12, head, anchor);
266565
+ const selection = TextSelection.create(doc$12, head, anchor);
265568
266566
  if (dispatch)
265569
266567
  dispatch(state.tr.setSelection(selection));
265570
266568
  if (editor?.view?.dom && typeof editor.view.dom.focus === "function")
@@ -269712,9 +270710,9 @@ var Node$13 = class Node$14 {
269712
270710
  }, syncSelectionFromTransaction = ({ targetTr, sourceSelection }) => {
269713
270711
  const boundedFrom = Math.max(0, Math.min(sourceSelection.from, targetTr.doc.content.size));
269714
270712
  const boundedTo = Math.max(0, Math.min(sourceSelection.to, targetTr.doc.content.size));
269715
- if (sourceSelection instanceof TextSelection2)
270713
+ if (sourceSelection instanceof TextSelection)
269716
270714
  try {
269717
- targetTr.setSelection(TextSelection2.create(targetTr.doc, boundedFrom, boundedTo));
270715
+ targetTr.setSelection(TextSelection.create(targetTr.doc, boundedFrom, boundedTo));
269718
270716
  return;
269719
270717
  } catch {
269720
270718
  targetTr.setSelection(Selection.near(targetTr.doc.resolve(boundedFrom), -1));
@@ -270425,29 +271423,29 @@ var Node$13 = class Node$14 {
270425
271423
  const boundedPos = Math.max(0, Math.min(trackMeta.selectionPos, newTr.doc.content.size));
270426
271424
  const $pos = newTr.doc.resolve(boundedPos);
270427
271425
  if ($pos.parent.inlineContent)
270428
- newTr.setSelection(TextSelection2.create(newTr.doc, boundedPos));
271426
+ newTr.setSelection(TextSelection.create(newTr.doc, boundedPos));
270429
271427
  else
270430
- newTr.setSelection(TextSelection2.near($pos, -1));
271428
+ newTr.setSelection(TextSelection.near($pos, -1));
270431
271429
  } else if (tr.selectionSet)
270432
- if (tr.selection instanceof TextSelection2 && (tr.selection.from < state.selection.from || tr.getMeta("inputType") === "deleteContentBackward")) {
271430
+ if (tr.selection instanceof TextSelection && (tr.selection.from < state.selection.from || tr.getMeta("inputType") === "deleteContentBackward")) {
270433
271431
  const caretPos = map$12.map(tr.selection.from, -1);
270434
- newTr.setSelection(new TextSelection2(newTr.doc.resolve(caretPos)));
271432
+ newTr.setSelection(new TextSelection(newTr.doc.resolve(caretPos)));
270435
271433
  } else if (trackMeta?.insertedTo !== undefined) {
270436
271434
  const boundedInsertedTo = Math.max(0, Math.min(trackMeta.insertedTo, newTr.doc.content.size));
270437
271435
  const $insertPos = newTr.doc.resolve(boundedInsertedTo);
270438
- newTr.setSelection(TextSelection2.near($insertPos, 1));
271436
+ newTr.setSelection(TextSelection.near($insertPos, 1));
270439
271437
  } else {
270440
271438
  const deletionMarkSchema = state.schema.marks[TrackDeleteMarkName];
270441
271439
  const deletionMark = findMark(state, deletionMarkSchema, false);
270442
271440
  if (tr.selection.from > state.selection.from && deletionMark) {
270443
271441
  const caretPos = map$12.map(deletionMark.to + 1, 1);
270444
- newTr.setSelection(new TextSelection2(newTr.doc.resolve(caretPos)));
271442
+ newTr.setSelection(new TextSelection(newTr.doc.resolve(caretPos)));
270445
271443
  } else
270446
271444
  newTr.setSelection(tr.selection.map(newTr.doc, map$12));
270447
271445
  }
270448
271446
  else if (state.selection.from - tr.selection.from > 1 && tr.selection.$head.depth > 1) {
270449
271447
  const caretPos = map$12.map(tr.selection.from - 2, -1);
270450
- newTr.setSelection(new TextSelection2(newTr.doc.resolve(caretPos)));
271448
+ newTr.setSelection(new TextSelection(newTr.doc.resolve(caretPos)));
270451
271449
  }
270452
271450
  if (tr.storedMarksSet)
270453
271451
  newTr.setStoredMarks(tr.storedMarks);
@@ -270918,7 +271916,7 @@ var Node$13 = class Node$14 {
270918
271916
  to
270919
271917
  });
270920
271918
  else if (this.#editor.state) {
270921
- const tr = this.#editor.state.tr.setSelection(TextSelection2.create(this.#editor.state.doc, from$1, to)).scrollIntoView();
271919
+ const tr = this.#editor.state.tr.setSelection(TextSelection.create(this.#editor.state.doc, from$1, to)).scrollIntoView();
270922
271920
  this.#editor.dispatch(tr);
270923
271921
  }
270924
271922
  const presentationEditor = this.#editor.presentationEditor;
@@ -272191,7 +273189,7 @@ var Node$13 = class Node$14 {
272191
273189
  }, icons, getAvailableColorOptions = () => {
272192
273190
  return icons.flat().map((item) => item.value);
272193
273191
  }, _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>
272194
- `, _hoisted_1$12, _hoisted_2$8, _hoisted_3$6, SearchInput_default, TOOLBAR_FONTS, TOOLBAR_FONT_SIZES, closeDropdown = (dropdown) => {
273192
+ `, _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) => {
272195
273193
  dropdown.expand.value = false;
272196
273194
  }, makeDefaultItems = ({ superToolbar, toolbarIcons: toolbarIcons$1, toolbarTexts: toolbarTexts$1, toolbarFonts, hideButtons, availableWidth, role, isDev = false } = {}) => {
272197
273195
  const bold2 = useToolbarItem({
@@ -272830,16 +273828,6 @@ var Node$13 = class Node$14 {
272830
273828
  group: "left",
272831
273829
  attributes: { ariaLabel: "Redo" }
272832
273830
  });
272833
- const toggleTrackChanges = useToolbarItem({
272834
- type: "button",
272835
- disabled: false,
272836
- name: "toggleTrackChanges",
272837
- tooltip: toolbarTexts$1.trackChanges,
272838
- command: "toggleTrackChanges",
272839
- icon: toolbarIcons$1.trackChanges,
272840
- group: "left",
272841
- attributes: { ariaLabel: "Track changes" }
272842
- });
272843
273831
  const acceptTrackedChangeBySelection = useToolbarItem({
272844
273832
  type: "button",
272845
273833
  disabled: false,
@@ -272860,26 +273848,6 @@ var Node$13 = class Node$14 {
272860
273848
  group: "left",
272861
273849
  attributes: { ariaLabel: "Reject tracked changes" }
272862
273850
  });
272863
- const toggleTrackChangesOriginal = useToolbarItem({
272864
- type: "button",
272865
- disabled: false,
272866
- name: "toggleTrackChangesShowOriginal",
272867
- tooltip: toolbarTexts$1.trackChangesOriginal,
272868
- command: "toggleTrackChangesShowOriginal",
272869
- icon: toolbarIcons$1.trackChangesOriginal,
272870
- group: "left",
272871
- attributes: { ariaLabel: "Toggle tracked changes show original" }
272872
- });
272873
- const toggleTrackChangesFinal = useToolbarItem({
272874
- type: "button",
272875
- disabled: false,
272876
- name: "toggleTrackChangesShowFinal",
272877
- tooltip: toolbarTexts$1.trackChangesFinal,
272878
- command: "toggleTrackChangesShowFinal",
272879
- icon: toolbarIcons$1.trackChangesFinal,
272880
- group: "left",
272881
- attributes: { ariaLabel: "Toggle tracked changes show final" }
272882
- });
272883
273851
  const clearFormatting = useToolbarItem({
272884
273852
  type: "button",
272885
273853
  name: "clearFormatting",
@@ -273159,11 +274127,7 @@ var Node$13 = class Node$14 {
273159
274127
  ];
273160
274128
  toolbarItems = toolbarItems.filter((item) => !filterItems.includes(item.name.value));
273161
274129
  }
273162
- const devItems = [
273163
- toggleTrackChanges,
273164
- toggleTrackChangesOriginal,
273165
- toggleTrackChangesFinal
273166
- ];
274130
+ const devItems = [];
273167
274131
  if (!isDev) {
273168
274132
  if (role === "viewer")
273169
274133
  devItems.push(...[acceptTrackedChangeBySelection, rejectTrackedChangeOnSelection]);
@@ -273208,7 +274172,24 @@ var Node$13 = class Node$14 {
273208
274172
  defaultItems: visibleItems,
273209
274173
  overflowItems: overflowItems.filter((item) => item.type !== "separator")
273210
274174
  };
273211
- }, _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 {
274175
+ }, _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 = {}) => {
274176
+ const fontFamilyProps = paragraphProps?.runProperties?.fontFamily;
274177
+ if (!fontFamilyProps)
274178
+ return null;
274179
+ const [markDef] = encodeMarksFromRPr({ fontFamily: fontFamilyProps }, convertedXml);
274180
+ return markDef?.attrs?.fontFamily ?? null;
274181
+ }, findElementBySelector = (selector) => {
274182
+ let el = null;
274183
+ if (selector) {
274184
+ if (selector.startsWith("#") || selector.startsWith("."))
274185
+ el = document.querySelector(selector);
274186
+ else
274187
+ el = document.getElementById(selector);
274188
+ if (!el)
274189
+ return null;
274190
+ }
274191
+ return el;
274192
+ }, SuperToolbar, Schema3 = class Schema4 {
273212
274193
  static createSchemaByExtensions(extensions, editor) {
273213
274194
  const nodeExtensions = extensions.filter((e) => e.type === "node");
273214
274195
  const markExtensions = extensions.filter((e) => e.type === "mark");
@@ -284621,7 +285602,7 @@ var Node$13 = class Node$14 {
284621
285602
  if (isolatingDepth > 0) {
284622
285603
  const boundary = forward ? $head.before(isolatingDepth) : $head.after(isolatingDepth);
284623
285604
  const near = Selection.near(doc$12.resolve(boundary), forward ? -1 : 1);
284624
- if (near instanceof TextSelection2)
285605
+ if (near instanceof TextSelection)
284625
285606
  return near.head;
284626
285607
  return anchor;
284627
285608
  }
@@ -284968,7 +285949,7 @@ var Node$13 = class Node$14 {
284968
285949
  const resolved = this.#resolveStructuredContentInlineFromElement(doc$12, inlineStructuredContentLabel);
284969
285950
  if (resolved) {
284970
285951
  try {
284971
- const tr = editor.state.tr.setSelection(TextSelection2.create(doc$12, resolved.start, resolved.end));
285952
+ const tr = editor.state.tr.setSelection(TextSelection.create(doc$12, resolved.start, resolved.end));
284972
285953
  editor.view?.dispatch(tr);
284973
285954
  } catch {}
284974
285955
  this.#callbacks.scheduleSelectionUpdate?.();
@@ -284982,7 +285963,7 @@ var Node$13 = class Node$14 {
284982
285963
  if (resolved) {
284983
285964
  try {
284984
285965
  const contentRange = this.#findStructuredContentBlockContentRange(resolved);
284985
- const selection = contentRange != null ? TextSelection2.create(doc$12, contentRange.from, contentRange.to) : NodeSelection.create(editor.state.doc, resolved.pos);
285966
+ const selection = contentRange != null ? TextSelection.create(doc$12, contentRange.from, contentRange.to) : NodeSelection.create(editor.state.doc, resolved.pos);
284986
285967
  const tr = editor.state.tr.setSelection(selection);
284987
285968
  editor.view?.dispatch(tr);
284988
285969
  } catch {}
@@ -285073,12 +286054,12 @@ var Node$13 = class Node$14 {
285073
286054
  if (sdtBlock)
285074
286055
  nextSelection = NodeSelection.create(doc$12, sdtBlock.pos);
285075
286056
  else {
285076
- nextSelection = TextSelection2.create(doc$12, hit.pos);
286057
+ nextSelection = TextSelection.create(doc$12, hit.pos);
285077
286058
  if (!nextSelection.$from.parent.inlineContent)
285078
286059
  nextSelection = Selection.near(doc$12.resolve(hit.pos), 1);
285079
286060
  }
285080
286061
  const tr = editor.state.tr.setSelection(nextSelection);
285081
- if (nextSelection instanceof TextSelection2 && nextSelection.empty && editor.state.storedMarks)
286062
+ if (nextSelection instanceof TextSelection && nextSelection.empty && editor.state.storedMarks)
285082
286063
  tr.setStoredMarks(editor.state.storedMarks);
285083
286064
  editor.view?.dispatch(tr);
285084
286065
  } catch {}
@@ -285508,7 +286489,7 @@ var Node$13 = class Node$14 {
285508
286489
  const anchor = editor.state.selection.anchor;
285509
286490
  const { selAnchor, selHead } = this.#calculateExtendedSelection(anchor, headPos, this.#dragExtensionMode);
285510
286491
  try {
285511
- const tr = editor.state.tr.setSelection(TextSelection2.create(editor.state.doc, selAnchor, selHead));
286492
+ const tr = editor.state.tr.setSelection(TextSelection.create(editor.state.doc, selAnchor, selHead));
285512
286493
  editor.view?.dispatch(tr);
285513
286494
  this.#callbacks.scheduleSelectionUpdate?.();
285514
286495
  } catch (error3) {
@@ -285591,7 +286572,7 @@ var Node$13 = class Node$14 {
285591
286572
  head = this.#clampHeadAtIsolatingBoundary(doc$12, anchor, head);
285592
286573
  const { selAnchor, selHead } = this.#calculateExtendedSelection(anchor, head, this.#dragExtensionMode);
285593
286574
  try {
285594
- const tr = editor.state.tr.setSelection(TextSelection2.create(editor.state.doc, selAnchor, selHead));
286575
+ const tr = editor.state.tr.setSelection(TextSelection.create(editor.state.doc, selAnchor, selHead));
285595
286576
  editor.view?.dispatch(tr);
285596
286577
  this.#callbacks.scheduleSelectionUpdate?.();
285597
286578
  } catch (error3) {
@@ -285622,7 +286603,7 @@ var Node$13 = class Node$14 {
285622
286603
  const head = hit.pos;
285623
286604
  const { selAnchor, selHead } = this.#calculateExtendedSelection(anchor, head, this.#dragExtensionMode);
285624
286605
  try {
285625
- const tr = editor.state.tr.setSelection(TextSelection2.create(editor.state.doc, selAnchor, selHead));
286606
+ const tr = editor.state.tr.setSelection(TextSelection.create(editor.state.doc, selAnchor, selHead));
285626
286607
  editor.view?.dispatch(tr);
285627
286608
  this.#callbacks.scheduleSelectionUpdate?.();
285628
286609
  } catch {}
@@ -285669,7 +286650,7 @@ var Node$13 = class Node$14 {
285669
286650
  if (pendingMarginClick.kind === "aboveFirstLine") {
285670
286651
  const pos = this.#getFirstTextPosition();
285671
286652
  try {
285672
- const tr = editor.state.tr.setSelection(TextSelection2.create(doc$12, pos));
286653
+ const tr = editor.state.tr.setSelection(TextSelection.create(doc$12, pos));
285673
286654
  editor.view?.dispatch(tr);
285674
286655
  this.#callbacks.scheduleSelectionUpdate?.();
285675
286656
  } catch {}
@@ -285693,7 +286674,7 @@ var Node$13 = class Node$14 {
285693
286674
  }
285694
286675
  const caretPos = Math.max(0, Math.min(mappedEnd$1.pos, doc$12.content.size));
285695
286676
  try {
285696
- const tr = editor.state.tr.setSelection(TextSelection2.create(doc$12, caretPos));
286677
+ const tr = editor.state.tr.setSelection(TextSelection.create(doc$12, caretPos));
285697
286678
  editor.view?.dispatch(tr);
285698
286679
  this.#callbacks.scheduleSelectionUpdate?.();
285699
286680
  } catch {}
@@ -285718,7 +286699,7 @@ var Node$13 = class Node$14 {
285718
286699
  const selFrom = Math.max(0, Math.min(Math.min(mappedStart.pos, mappedEnd.pos), doc$12.content.size));
285719
286700
  const selTo = Math.max(0, Math.min(Math.max(mappedStart.pos, mappedEnd.pos), doc$12.content.size));
285720
286701
  try {
285721
- const tr = editor.state.tr.setSelection(TextSelection2.create(doc$12, selFrom, selTo));
286702
+ const tr = editor.state.tr.setSelection(TextSelection.create(doc$12, selFrom, selTo));
285722
286703
  editor.view?.dispatch(tr);
285723
286704
  this.#callbacks.scheduleSelectionUpdate?.();
285724
286705
  } catch {}
@@ -285756,7 +286737,7 @@ var Node$13 = class Node$14 {
285756
286737
  const doc$12 = editor?.state?.doc;
285757
286738
  if (doc$12)
285758
286739
  try {
285759
- const tr = editor.state.tr.setSelection(TextSelection2.create(doc$12, validPos));
286740
+ const tr = editor.state.tr.setSelection(TextSelection.create(doc$12, validPos));
285760
286741
  editor.view?.dispatch(tr);
285761
286742
  } catch {}
285762
286743
  editorDom.focus();
@@ -286254,10 +287235,10 @@ var Node$13 = class Node$14 {
286254
287235
  return;
286255
287236
  const pos = Math.min(Math.max(hit.pos, 1), doc$12.content.size);
286256
287237
  const currentSelection = activeEditor.state.selection;
286257
- if (currentSelection instanceof TextSelection2 && currentSelection.from === pos && currentSelection.to === pos)
287238
+ if (currentSelection instanceof TextSelection && currentSelection.from === pos && currentSelection.to === pos)
286258
287239
  return;
286259
287240
  try {
286260
- const tr = activeEditor.state.tr.setSelection(TextSelection2.create(doc$12, pos)).setMeta("addToHistory", false);
287241
+ const tr = activeEditor.state.tr.setSelection(TextSelection.create(doc$12, pos)).setMeta("addToHistory", false);
286261
287242
  activeEditor.view?.dispatch(tr);
286262
287243
  this.#deps.scheduleSelectionUpdate();
286263
287244
  } catch {}
@@ -286311,7 +287292,7 @@ var Node$13 = class Node$14 {
286311
287292
  return;
286312
287293
  const clampedPos = Math.min(Math.max(pos, 1), doc$12.content.size);
286313
287294
  try {
286314
- const tr = activeEditor.state.tr.setSelection(TextSelection2.create(doc$12, clampedPos)).setMeta("addToHistory", false);
287295
+ const tr = activeEditor.state.tr.setSelection(TextSelection.create(doc$12, clampedPos)).setMeta("addToHistory", false);
286315
287296
  activeEditor.view?.dispatch(tr);
286316
287297
  } catch {}
286317
287298
  }
@@ -286392,7 +287373,7 @@ var Node$13 = class Node$14 {
286392
287373
  if (attributes && isValidFieldAnnotationAttributes(attributes)) {
286393
287374
  activeEditor.commands?.addFieldAnnotation?.(pos, attributes, true);
286394
287375
  const posAfter = Math.min(pos + 1, activeEditor.state?.doc?.content.size ?? pos + 1);
286395
- const tr = activeEditor.state?.tr.setSelection(TextSelection2.create(activeEditor.state.doc, posAfter));
287376
+ const tr = activeEditor.state?.tr.setSelection(TextSelection.create(activeEditor.state.doc, posAfter));
286396
287377
  if (tr)
286397
287378
  activeEditor.view?.dispatch(tr);
286398
287379
  this.#deps.scheduleSelectionUpdate();
@@ -288134,12 +289115,12 @@ var Node$13 = class Node$14 {
288134
289115
  return;
288135
289116
  console.log(...args$1);
288136
289117
  }, 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;
288137
- var init_src_84ZC_Jm8_es = __esm(() => {
289118
+ var init_src_yUVuhLM1_es = __esm(() => {
288138
289119
  init_rolldown_runtime_Bg48TavK_es();
288139
- init_SuperConverter_w6yaFRT5_es();
289120
+ init_SuperConverter_BgwP1GeS_es();
288140
289121
  init_jszip_C49i9kUs_es();
288141
289122
  init_uuid_qzgm05fK_es();
288142
- init_create_headless_toolbar_CHK8yJic_es();
289123
+ init_create_headless_toolbar_Dcw4Hyt2_es();
288143
289124
  init_constants_CGhJRd87_es();
288144
289125
  init_dist_B8HfvhaK_es();
288145
289126
  init_unified_Dsuw2be5_es();
@@ -288811,7 +289792,7 @@ ${err.toString()}`);
288811
289792
  }));
288812
289793
  if (!selection.empty && !this.editor.options.element?.contains(target)) {
288813
289794
  this.editor.setOptions({ lastSelection: selection });
288814
- const clearSelectionTr = view.state.tr.setSelection(TextSelection2.create(view.state.doc, 0));
289795
+ const clearSelectionTr = view.state.tr.setSelection(TextSelection.create(view.state.doc, 0));
288815
289796
  view.dispatch(clearSelectionTr);
288816
289797
  }
288817
289798
  }
@@ -290182,7 +291163,7 @@ ${err.toString()}`);
290182
291163
  fragments.push(runType.create(parentRun.attrs, rightContent, parentRun.marks));
290183
291164
  tr.replaceWith(runStart, runEnd, fragments);
290184
291165
  const cursorPos = runStart + (leftContent.size > 0 ? leftContent.size + 2 : 0) + node3.nodeSize;
290185
- tr.setSelection(TextSelection2.create(tr.doc, cursorPos));
291166
+ tr.setSelection(TextSelection.create(tr.doc, cursorPos));
290186
291167
  } else
290187
291168
  tr.replaceWith(from$1, to, node3);
290188
291169
  }
@@ -290761,7 +291742,7 @@ ${err.toString()}`);
290761
291742
  return null;
290762
291743
  const tr = newState.tr;
290763
291744
  toDelete.sort((a2, b$1) => b$1.from - a2.from).forEach(({ from: from$1, to }) => tr.deleteRange(from$1, to));
290764
- if (tr.selection instanceof TextSelection2 && tr.selection.empty && newState.storedMarks !== null)
291745
+ if (tr.selection instanceof TextSelection && tr.selection.empty && newState.storedMarks !== null)
290765
291746
  tr.setStoredMarks(newState.storedMarks);
290766
291747
  return tr.docChanged ? tr : null;
290767
291748
  } });
@@ -291123,7 +292104,7 @@ ${err.toString()}`);
291123
292104
  if (findParentNode(isList)(state.selection))
291124
292105
  return null;
291125
292106
  const { tr } = state;
291126
- tr.delete(range.from, range.to).setSelection(TextSelection2.create(tr.doc, range.from));
292107
+ tr.delete(range.from, range.to).setSelection(TextSelection.create(tr.doc, range.from));
291127
292108
  ListHelpers.createNewList({
291128
292109
  listType: type,
291129
292110
  tr,
@@ -291580,7 +292561,7 @@ ${err.toString()}`);
291580
292561
  const { from: from$1 } = findRangeById(state.doc, id2) || {};
291581
292562
  if (from$1 != null) {
291582
292563
  const tr = state.tr;
291583
- tr.setSelection(TextSelection2.create(state.doc, from$1));
292564
+ tr.setSelection(TextSelection.create(state.doc, from$1));
291584
292565
  if (options.activeCommentId)
291585
292566
  tr.setMeta(CommentsPluginKey, {
291586
292567
  type: "setActiveComment",
@@ -292275,7 +293256,7 @@ ${err.toString()}`);
292275
293256
  const { from: from$1, to, tablePos } = structuredContentInsertion;
292276
293257
  tr.replaceWith(from$1, to, node3);
292277
293258
  const selectionPos$1 = getFirstTableCellTextPos(tablePos, node3);
292278
- tr.scrollIntoView().setSelection(TextSelection2.near(tr.doc.resolve(selectionPos$1)));
293259
+ tr.scrollIntoView().setSelection(TextSelection.near(tr.doc.resolve(selectionPos$1)));
292279
293260
  return true;
292280
293261
  }
292281
293262
  let offset$1;
@@ -292305,7 +293286,7 @@ ${err.toString()}`);
292305
293286
  if (!inserted)
292306
293287
  return false;
292307
293288
  const selectionPos = getFirstTableCellTextPos(offset$1, node3);
292308
- tr.scrollIntoView().setSelection(TextSelection2.near(tr.doc.resolve(selectionPos)));
293289
+ tr.scrollIntoView().setSelection(TextSelection.near(tr.doc.resolve(selectionPos)));
292309
293290
  }
292310
293291
  return true;
292311
293292
  },
@@ -305788,7 +306769,7 @@ function print() { __p += __j.call(arguments, '') }
305788
306769
  if (typeof from$1 !== "number" || typeof to !== "number")
305789
306770
  return false;
305790
306771
  editor.view.focus();
305791
- const tr$1 = state.tr.setSelection(TextSelection2.create(state.doc, from$1, to)).scrollIntoView();
306772
+ const tr$1 = state.tr.setSelection(TextSelection.create(state.doc, from$1, to)).scrollIntoView();
305792
306773
  if (dispatch)
305793
306774
  dispatch(tr$1);
305794
306775
  const presentationEditor$1 = editor.presentationEditor;
@@ -305811,7 +306792,7 @@ function print() { __p += __j.call(arguments, '') }
305811
306792
  return false;
305812
306793
  const firstDeco = decorations[0];
305813
306794
  editor.view.focus();
305814
- const tr = state.tr.setSelection(TextSelection2.create(state.doc, firstDeco.from, firstDeco.to)).scrollIntoView();
306795
+ const tr = state.tr.setSelection(TextSelection.create(state.doc, firstDeco.from, firstDeco.to)).scrollIntoView();
305815
306796
  if (dispatch)
305816
306797
  dispatch(tr);
305817
306798
  const presentationEditor = editor.presentationEditor;
@@ -305878,7 +306859,7 @@ function print() { __p += __j.call(arguments, '') }
305878
306859
  from$1 = normalized.from;
305879
306860
  to = normalized.to;
305880
306861
  editor.view.focus();
305881
- const tr = state.tr.setSelection(TextSelection2.create(state.doc, from$1, to)).scrollIntoView();
306862
+ const tr = state.tr.setSelection(TextSelection.create(state.doc, from$1, to)).scrollIntoView();
305882
306863
  if (dispatch)
305883
306864
  dispatch(tr);
305884
306865
  const presentationEditor = editor.presentationEditor;
@@ -306609,7 +307590,7 @@ function print() { __p += __j.call(arguments, '') }
306609
307590
  if (selectionState.value) {
306610
307591
  const { state } = props.editor;
306611
307592
  const { from: from$1, to } = selectionState.value;
306612
- const tr = state.tr.setSelection(TextSelection2.create(state.doc, from$1, to));
307593
+ const tr = state.tr.setSelection(TextSelection.create(state.doc, from$1, to));
306613
307594
  props.editor.view.dispatch(tr);
306614
307595
  } else
306615
307596
  console.warn("[AIWriter] No stored selection to restore");
@@ -307247,7 +308228,7 @@ function print() { __p += __j.call(arguments, '') }
307247
308228
  text: finalText
307248
308229
  });
307249
308230
  const endPos = editor.view.state.selection.$to.pos;
307250
- editor.view.dispatch(editor.view.state.tr.setSelection(new TextSelection2(editor.view.state.doc.resolve(endPos))));
308231
+ editor.view.dispatch(editor.view.state.tr.setSelection(new TextSelection(editor.view.state.doc.resolve(endPos))));
307251
308232
  setTimeout(() => editor.view.focus(), 100);
307252
308233
  props.closePopover();
307253
308234
  };
@@ -307874,6 +308855,52 @@ function print() { __p += __j.call(arguments, '') }
307874
308855
  props: { "data-item": "btn-fontSize-option" }
307875
308856
  }
307876
308857
  ];
308858
+ HEADLESS_ITEM_MAP = {
308859
+ undo: "undo",
308860
+ redo: "redo",
308861
+ bold: "bold",
308862
+ italic: "italic",
308863
+ underline: "underline",
308864
+ strike: "strikethrough",
308865
+ acceptTrackedChangeBySelection: "track-changes-accept-selection",
308866
+ rejectTrackedChangeOnSelection: "track-changes-reject-selection",
308867
+ ruler: "ruler",
308868
+ zoom: "zoom",
308869
+ documentMode: "document-mode",
308870
+ link: "link",
308871
+ fontFamily: "font-family",
308872
+ fontSize: "font-size",
308873
+ list: "bullet-list",
308874
+ numberedlist: "numbered-list",
308875
+ table: "table-insert",
308876
+ image: "image",
308877
+ color: "text-color",
308878
+ highlight: "highlight-color",
308879
+ textAlign: "text-align",
308880
+ lineHeight: "line-height",
308881
+ linkedStyles: "linked-style",
308882
+ indentleft: "indent-decrease",
308883
+ indentright: "indent-increase",
308884
+ clearFormatting: "clear-formatting",
308885
+ copyFormat: "copy-format"
308886
+ };
308887
+ TABLE_ACTION_COMMAND_MAP = {
308888
+ addRowBefore: "table-add-row-before",
308889
+ addRowAfter: "table-add-row-after",
308890
+ deleteRow: "table-delete-row",
308891
+ addColumnBefore: "table-add-column-before",
308892
+ addColumnAfter: "table-add-column-after",
308893
+ deleteColumn: "table-delete-column",
308894
+ deleteTable: "table-delete",
308895
+ deleteCellAndTableBorders: "table-remove-borders",
308896
+ mergeCells: "table-merge-cells",
308897
+ splitCell: "table-split-cell",
308898
+ fixTables: "table-fix"
308899
+ };
308900
+ TABLE_ACTION_COMMAND_IDS = Object.values(TABLE_ACTION_COMMAND_MAP);
308901
+ HEADLESS_TOOLBAR_COMMANDS = [...new Set([...Object.values(HEADLESS_ITEM_MAP), ...TABLE_ACTION_COMMAND_IDS])];
308902
+ NON_HEADLESS_EXECUTE_ITEM_NAMES = new Set(["link"]);
308903
+ HEADLESS_EXECUTE_ITEMS = new Set(Object.keys(HEADLESS_ITEM_MAP).filter((itemName) => !NON_HEADLESS_EXECUTE_ITEM_NAMES.has(itemName)));
307877
308904
  _hoisted_1$11 = { class: "toolbar-icon" };
307878
308905
  _hoisted_2$7 = ["innerHTML"];
307879
308906
  ToolbarButtonIcon_default = /* @__PURE__ */ __plugin_vue_export_helper_default({
@@ -309257,11 +310284,13 @@ function print() { __p += __j.call(arguments, '') }
309257
310284
  };
309258
310285
  this.toolbarItems = [];
309259
310286
  this.overflowItems = [];
309260
- this.documentMode = config2.documentMode || "editing";
309261
310287
  this.isDev = config2.isDev || false;
309262
310288
  this.superdoc = config2.superdoc;
309263
310289
  this.role = config2.role || "editor";
309264
310290
  this.toolbarContainer = null;
310291
+ this.controller = null;
310292
+ this.snapshot = null;
310293
+ this._unsubscribeController = null;
309265
310294
  if (this.config.editor)
309266
310295
  this.config.mode = this.config.editor.options.mode;
309267
310296
  this.config.icons = {
@@ -309284,7 +310313,7 @@ function print() { __p += __j.call(arguments, '') }
309284
310313
  this._restoreFocusTimeoutId = null;
309285
310314
  if (!this.config.selector && this.config.element)
309286
310315
  this.config.selector = this.config.element;
309287
- this.toolbarContainer = this.findElementBySelector(this.config.selector);
310316
+ this.toolbarContainer = findElementBySelector(this.config.selector);
309288
310317
  if (this.toolbarContainer) {
309289
310318
  const uiFontFamily = (this.config?.uiDisplayFallbackFont || "").toString().trim() || "Arial, Helvetica, sans-serif";
309290
310319
  this.toolbarContainer.style.setProperty("--sd-ui-font-family", uiFontFamily);
@@ -309306,215 +310335,39 @@ function print() { __p += __j.call(arguments, '') }
309306
310335
  if (this.toolbarContainer)
309307
310336
  this.toolbar = this.app.mount(this.toolbarContainer);
309308
310337
  this.activeEditor = config2.editor || null;
310338
+ this.initHeadlessToolbar();
309309
310339
  this.updateToolbarState();
309310
310340
  }
309311
- findElementBySelector(selector) {
309312
- let el = null;
309313
- if (selector) {
309314
- if (selector.startsWith("#") || selector.startsWith("."))
309315
- el = document.querySelector(selector);
309316
- else
309317
- el = document.getElementById(selector);
309318
- if (!el)
309319
- return null;
309320
- }
309321
- return el;
310341
+ createHeadlessToolbar() {
310342
+ if (!this.superdoc)
310343
+ return null;
310344
+ return createHeadlessToolbar({
310345
+ superdoc: this.superdoc,
310346
+ commands: HEADLESS_TOOLBAR_COMMANDS
310347
+ });
310348
+ }
310349
+ initHeadlessToolbar() {
310350
+ if (!this.superdoc)
310351
+ return;
310352
+ this.destroyHeadlessToolbar();
310353
+ this.controller = this.createHeadlessToolbar();
310354
+ this.snapshot = this.controller.getSnapshot();
310355
+ this._unsubscribeController = this.controller.subscribe(({ snapshot: snapshot2 }) => {
310356
+ this.snapshot = snapshot2;
310357
+ this.updateToolbarState();
310358
+ });
310359
+ }
310360
+ destroyHeadlessToolbar() {
310361
+ this._unsubscribeController?.();
310362
+ this.controller?.destroy();
310363
+ this.controller = null;
310364
+ this.snapshot = null;
310365
+ this._unsubscribeController = null;
309322
310366
  }
309323
310367
  #initToolbarGroups() {
309324
310368
  if (this.config.groups && !Array.isArray(this.config.groups) && Object.keys(this.config.groups).length)
309325
310369
  this.config.toolbarGroups = Object.keys(this.config.groups);
309326
310370
  }
309327
- #interceptedCommands = {
309328
- setZoom: ({ item, argument }) => {
309329
- if (!argument)
309330
- return;
309331
- item.onActivate({ zoom: argument });
309332
- this.emit("superdoc-command", {
309333
- item,
309334
- argument
309335
- });
309336
- this.superdoc.superdocStore.activeZoom = parseInt(argument, 10);
309337
- },
309338
- setDocumentMode: ({ item, argument }) => {
309339
- if (!argument)
309340
- return;
309341
- this.emit("superdoc-command", {
309342
- item,
309343
- argument
309344
- });
309345
- },
309346
- setFontSize: ({ item, argument }) => {
309347
- if (this.#isFieldAnnotationSelection() && argument) {
309348
- this.activeEditor?.commands.setFieldAnnotationsFontSize(argument, true);
309349
- this.updateToolbarState();
309350
- return;
309351
- }
309352
- this.#runCommandWithArgumentOnly({
309353
- item,
309354
- argument
309355
- }, () => {
309356
- this.activeEditor?.commands.setFieldAnnotationsFontSize(argument, true);
309357
- });
309358
- },
309359
- setFontFamily: ({ item, argument }) => {
309360
- if (this.#isFieldAnnotationSelection() && argument) {
309361
- this.activeEditor?.commands.setFieldAnnotationsFontFamily(argument, true);
309362
- this.updateToolbarState();
309363
- return;
309364
- }
309365
- this.#runCommandWithArgumentOnly({
309366
- item,
309367
- argument
309368
- }, () => {
309369
- this.activeEditor?.commands.setFieldAnnotationsFontFamily(argument, true);
309370
- });
309371
- },
309372
- setColor: ({ argument }) => {
309373
- if (!argument || !this.activeEditor)
309374
- return;
309375
- const isNone = argument === "none";
309376
- const value = isNone ? "inherit" : argument;
309377
- if (this.activeEditor?.commands?.setColor)
309378
- this.activeEditor.commands.setColor(value);
309379
- const argValue = isNone ? null : argument;
309380
- this.activeEditor?.commands.setFieldAnnotationsTextColor(argValue, true);
309381
- this.updateToolbarState();
309382
- },
309383
- setHighlight: ({ argument }) => {
309384
- if (!argument || !this.activeEditor)
309385
- return;
309386
- const inlineColor = argument !== "none" ? argument : "transparent";
309387
- if (this.activeEditor?.commands?.setHighlight)
309388
- this.activeEditor.commands.setHighlight(inlineColor);
309389
- const argValue = argument !== "none" ? argument : null;
309390
- this.activeEditor?.commands.setFieldAnnotationsTextHighlight(argValue, true);
309391
- this.activeEditor?.commands.setCellBackground(argValue);
309392
- this.updateToolbarState();
309393
- },
309394
- toggleRuler: () => {
309395
- this.superdoc.toggleRuler();
309396
- this.updateToolbarState();
309397
- },
309398
- startImageUpload: async () => {
309399
- try {
309400
- let result = await getFileOpener()();
309401
- if (!result?.file)
309402
- return;
309403
- await processAndInsertImageFile({
309404
- file: result.file,
309405
- editor: this.activeEditor,
309406
- view: this.activeEditor.view,
309407
- editorOptions: this.activeEditor.options,
309408
- getMaxContentSize: () => this.activeEditor.getMaxContentSize()
309409
- });
309410
- } catch (error3) {
309411
- const err = /* @__PURE__ */ new Error("[super-toolbar \uD83C\uDFA8] Image upload failed");
309412
- this.emit("exception", {
309413
- error: err,
309414
- editor: this.activeEditor,
309415
- originalError: error3
309416
- });
309417
- console.error(err, error3);
309418
- }
309419
- },
309420
- increaseTextIndent: ({ item, argument }) => {
309421
- let command$1 = item.command;
309422
- if (this.activeEditor.commands.increaseListIndent?.())
309423
- return true;
309424
- if (command$1 in this.activeEditor.commands)
309425
- this.activeEditor.commands[command$1](argument);
309426
- },
309427
- decreaseTextIndent: ({ item, argument }) => {
309428
- let command$1 = item.command;
309429
- if (this.activeEditor.commands.decreaseListIndent?.())
309430
- return true;
309431
- if (command$1 in this.activeEditor.commands)
309432
- this.activeEditor.commands[command$1](argument);
309433
- },
309434
- toggleBold: ({ item, argument }) => {
309435
- if (this.#isFieldAnnotationSelection()) {
309436
- this.activeEditor?.commands.toggleFieldAnnotationsFormat("bold", true);
309437
- this.updateToolbarState();
309438
- return;
309439
- }
309440
- let command$1 = item.command;
309441
- if (command$1 in this.activeEditor.commands) {
309442
- this.activeEditor.commands[command$1](argument);
309443
- this.activeEditor.commands.toggleFieldAnnotationsFormat("bold", true);
309444
- }
309445
- this.updateToolbarState();
309446
- },
309447
- toggleItalic: ({ item, argument }) => {
309448
- if (this.#isFieldAnnotationSelection()) {
309449
- this.activeEditor?.commands.toggleFieldAnnotationsFormat("italic", true);
309450
- this.updateToolbarState();
309451
- return;
309452
- }
309453
- let command$1 = item.command;
309454
- if (command$1 in this.activeEditor.commands) {
309455
- this.activeEditor.commands[command$1](argument);
309456
- this.activeEditor.commands.toggleFieldAnnotationsFormat("italic", true);
309457
- }
309458
- this.updateToolbarState();
309459
- },
309460
- toggleUnderline: ({ item, argument }) => {
309461
- if (this.#isFieldAnnotationSelection()) {
309462
- this.activeEditor?.commands.toggleFieldAnnotationsFormat("underline", true);
309463
- this.updateToolbarState();
309464
- return;
309465
- }
309466
- let command$1 = item.command;
309467
- if (command$1 in this.activeEditor.commands) {
309468
- this.activeEditor.commands[command$1](argument);
309469
- this.activeEditor.commands.toggleFieldAnnotationsFormat("underline", true);
309470
- }
309471
- this.updateToolbarState();
309472
- },
309473
- toggleLink: ({ item, argument }) => {
309474
- let command$1 = item.command;
309475
- if (command$1 in this.activeEditor.commands) {
309476
- this.activeEditor.commands[command$1](argument);
309477
- const { view } = this.activeEditor;
309478
- let { selection } = view.state;
309479
- if (this.activeEditor.options.isHeaderOrFooter)
309480
- selection = this.activeEditor.options.lastSelection;
309481
- const endPos = selection.$to.pos;
309482
- const newSelection = new TextSelection(view.state.doc.resolve(endPos));
309483
- const tr = view.state.tr.setSelection(newSelection);
309484
- const state = view.state.apply(tr);
309485
- view.updateState(state);
309486
- if (!this.activeEditor.options.isHeaderOrFooter)
309487
- setTimeout(() => {
309488
- view.focus();
309489
- }, 100);
309490
- }
309491
- this.updateToolbarState();
309492
- },
309493
- insertTable: ({ item, argument }) => {
309494
- this.#runCommandWithArgumentOnly({
309495
- item,
309496
- argument
309497
- });
309498
- },
309499
- executeTableCommand: ({ argument }) => {
309500
- if (!argument)
309501
- return;
309502
- let command$1 = argument.command;
309503
- if (command$1 in this.activeEditor.commands)
309504
- this.activeEditor.commands[command$1](argument);
309505
- this.updateToolbarState();
309506
- }
309507
- };
309508
- log(...args$1) {
309509
- console.debug("[\uD83C\uDFA8 super-toolbar]", ...args$1);
309510
- }
309511
- setZoom(percent_int) {
309512
- const item = [...this.toolbarItems, ...this.overflowItems].find((item$1) => item$1.name.value === "zoom");
309513
- this.#interceptedCommands.setZoom({
309514
- item,
309515
- argument: percent_int
309516
- });
309517
- }
309518
310371
  setActiveEditor(editor) {
309519
310372
  if (this.activeEditor && this._boundEditorHandlers.transaction) {
309520
310373
  this.activeEditor.off("transaction", this._boundEditorHandlers.transaction);
@@ -309602,7 +310455,7 @@ function print() { __p += __j.call(arguments, '') }
309602
310455
  const documentModeItem = this.getToolbarItemByName("documentMode");
309603
310456
  if (!documentModeItem)
309604
310457
  return;
309605
- const mode = (this.documentMode || "editing").toLowerCase();
310458
+ const mode = (this.snapshot?.commands?.["document-mode"]?.value || "editing").toLowerCase();
309606
310459
  const texts = this.config.texts || {};
309607
310460
  const icons$1 = this.config.icons || {};
309608
310461
  const map$12 = {
@@ -309627,12 +310480,127 @@ function print() { __p += __j.call(arguments, '') }
309627
310480
  if (documentModeItem.icon?.value !== undefined && next2.icon)
309628
310481
  documentModeItem.icon.value = next2.icon;
309629
310482
  }
310483
+ #getFontFamilyFallbackValue() {
310484
+ if (!this.activeEditor?.state)
310485
+ return null;
310486
+ const { state } = this.activeEditor;
310487
+ const selection = state.selection;
310488
+ if (!selection?.empty)
310489
+ return null;
310490
+ const paragraphParent = findParentNode((n) => n.type.name === "paragraph")(selection);
310491
+ if (!paragraphParent || paragraphParent.node?.content?.size !== 0)
310492
+ return null;
310493
+ return getParagraphFontFamilyFromProperties(calculateResolvedParagraphProperties(this.activeEditor, paragraphParent.node, state.doc.resolve(paragraphParent.pos)), this.activeEditor?.converter?.convertedXml ?? {}) || null;
310494
+ }
310495
+ #isFontSizeMixedState(commandState) {
310496
+ return Boolean(commandState?.active) && commandState?.value == null;
310497
+ }
310498
+ #applyHeadlessState(item) {
310499
+ if (item.name.value === "tableActions") {
310500
+ const hasAnyEnabled = TABLE_ACTION_COMMAND_IDS.map((commandId$1) => this.snapshot?.commands?.[commandId$1]).some((state) => state && !state.disabled);
310501
+ item.setDisabled(!hasAnyEnabled);
310502
+ return true;
310503
+ }
310504
+ const commandId = HEADLESS_ITEM_MAP[item.name.value];
310505
+ if (!commandId)
310506
+ return false;
310507
+ const commandState = this.snapshot?.commands?.[commandId];
310508
+ const setDisabled = () => {
310509
+ item.setDisabled(Boolean(commandState?.disabled));
310510
+ };
310511
+ const handlers3 = {
310512
+ textAlign: () => {
310513
+ if (commandState?.value)
310514
+ item.activate({ textAlign: commandState.value });
310515
+ else
310516
+ item.deactivate();
310517
+ },
310518
+ lineHeight: () => {
310519
+ item.selectedValue.value = commandState?.value != null ? commandState.value : "";
310520
+ },
310521
+ zoom: () => {
310522
+ if (commandState?.value != null) {
310523
+ const value = typeof commandState.value === "number" ? `${commandState.value}%` : String(commandState.value);
310524
+ item.onActivate({ zoom: value });
310525
+ }
310526
+ },
310527
+ documentMode: () => {
310528
+ this.#syncDocumentModeUi();
310529
+ },
310530
+ link: () => {
310531
+ item.active.value = Boolean(commandState?.active);
310532
+ item.attributes.value = commandState?.value ? { href: commandState.value } : {};
310533
+ },
310534
+ fontFamily: () => {
310535
+ if (commandState?.value != null) {
310536
+ item.activate({ fontFamily: commandState.value });
310537
+ return;
310538
+ }
310539
+ const fallbackFontFamily = this.#getFontFamilyFallbackValue();
310540
+ if (fallbackFontFamily) {
310541
+ item.activate({ fontFamily: fallbackFontFamily });
310542
+ return;
310543
+ }
310544
+ item.deactivate();
310545
+ },
310546
+ fontSize: () => {
310547
+ if (commandState?.value != null) {
310548
+ item.activate({ fontSize: commandState.value });
310549
+ return;
310550
+ }
310551
+ if (this.#isFontSizeMixedState(commandState)) {
310552
+ item.activate({}, true);
310553
+ return;
310554
+ }
310555
+ item.deactivate();
310556
+ },
310557
+ color: () => {
310558
+ if (commandState?.value != null)
310559
+ item.activate({ color: commandState.value });
310560
+ else
310561
+ item.deactivate();
310562
+ },
310563
+ highlight: () => {
310564
+ if (commandState?.value != null)
310565
+ item.activate({ color: commandState.value });
310566
+ else
310567
+ item.deactivate();
310568
+ },
310569
+ linkedStyles: () => {
310570
+ if (commandState?.value != null)
310571
+ item.activate({ styleId: commandState.value });
310572
+ else
310573
+ item.label.value = this.config.texts?.formatText || "Format text";
310574
+ },
310575
+ default: () => {
310576
+ if (commandState?.active)
310577
+ item.activate();
310578
+ else
310579
+ item.deactivate();
310580
+ }
310581
+ };
310582
+ const handler2 = handlers3[item.name.value] ?? handlers3.default;
310583
+ setDisabled();
310584
+ handler2();
310585
+ return true;
310586
+ }
310587
+ #executeHeadlessCommand(item, argument) {
310588
+ const isTableActions = item?.name?.value === "tableActions";
310589
+ const commandId = isTableActions ? TABLE_ACTION_COMMAND_MAP[argument?.command] : HEADLESS_ITEM_MAP[item?.name?.value];
310590
+ if (!commandId || !this.controller?.execute)
310591
+ return false;
310592
+ if (isTableActions)
310593
+ this.controller.execute(commandId);
310594
+ else
310595
+ this.controller.execute(commandId, argument);
310596
+ return true;
310597
+ }
309630
310598
  updateToolbarState() {
309631
310599
  this.#syncDocumentModeUi();
309632
- this.#updateToolbarHistory();
309633
310600
  this.#initDefaultFonts();
309634
310601
  this.#updateHighlightColors();
309635
- if (!this.activeEditor || this.documentMode === "viewing") {
310602
+ const currentMode = this.snapshot?.commands?.["document-mode"]?.value || "editing";
310603
+ if (!this.activeEditor || currentMode === "viewing") {
309636
310604
  this.#deactivateAll();
309637
310605
  return;
309638
310606
  }
@@ -309641,96 +310609,9 @@ function print() { __p += __j.call(arguments, '') }
309641
310609
  this.#deactivateAll();
309642
310610
  return;
309643
310611
  }
309644
- const selection = state.selection;
309645
- const selectionTrackedChanges = this.#enrichTrackedChanges(collectTrackedChanges({
309646
- state,
309647
- from: selection.from,
309648
- to: selection.to
309649
- }));
309650
- const hasValidSelection = selectionTrackedChanges.length > 0;
309651
- const canAcceptTrackedChanges = hasValidSelection && isTrackedChangeActionAllowed({
309652
- editor: this.activeEditor,
309653
- action: "accept",
309654
- trackedChanges: selectionTrackedChanges
309655
- });
309656
- const canRejectTrackedChanges = hasValidSelection && isTrackedChangeActionAllowed({
309657
- editor: this.activeEditor,
309658
- action: "reject",
309659
- trackedChanges: selectionTrackedChanges
309660
- });
309661
- const marks = getActiveFormatting(this.activeEditor);
309662
- const inTable = isInTable(this.activeEditor.state);
309663
- const paragraphParent = findParentNode((n) => n.type.name === "paragraph")(selection);
309664
- const paragraphProps = paragraphParent ? calculateResolvedParagraphProperties(this.activeEditor, paragraphParent.node, state.doc.resolve(paragraphParent.pos)) : null;
309665
- const selectionIsCollapsed = selection.empty;
309666
- const paragraphIsEmpty = paragraphParent?.node?.content?.size === 0;
309667
- const paragraphFontFamily = getParagraphFontFamilyFromProperties(paragraphProps, this.activeEditor?.converter?.convertedXml ?? {});
309668
310612
  this.toolbarItems.forEach((item) => {
309669
310613
  item.resetDisabled();
309670
- let activatedFromLinkedStyle = false;
309671
- if (item.name.value === "undo")
309672
- item.setDisabled(this.undoDepth === 0);
309673
- if (item.name.value === "redo")
309674
- item.setDisabled(this.redoDepth === 0);
309675
- if (item.name.value === "acceptTrackedChangeBySelection")
309676
- item.setDisabled(!canAcceptTrackedChanges);
309677
- if (item.name.value === "rejectTrackedChangeOnSelection")
309678
- item.setDisabled(!canRejectTrackedChanges);
309679
- if (item.name.value === "linkedStyles")
309680
- if (this.activeEditor && !getQuickFormatList(this.activeEditor).length)
309681
- return item.deactivate();
309682
- else
309683
- return item.activate({ styleId: paragraphProps?.styleId || null });
309684
- const rawActiveMark = marks.find((mark2) => mark2.name === item.name.value);
309685
- const markNegated = rawActiveMark ? isNegatedMark(rawActiveMark.name, rawActiveMark.attrs) : false;
309686
- const activeMark = markNegated ? null : rawActiveMark;
309687
- if (activeMark)
309688
- if (activeMark.name === "fontSize") {
309689
- const fontSizes = marks.filter((i4) => i4.name === "fontSize").map((i4) => i4.attrs.fontSize);
309690
- const isMultiple = [...new Set(fontSizes)].length > 1;
309691
- item.activate(activeMark.attrs, isMultiple);
309692
- } else
309693
- item.activate(activeMark.attrs);
309694
- else
309695
- item.deactivate();
309696
- if (!activeMark && !markNegated && paragraphParent && paragraphProps?.styleId) {
309697
- const markToStyleMap = {
309698
- fontSize: "font-size",
309699
- fontFamily: "font-family",
309700
- bold: "bold"
309701
- };
309702
- const linkedStyles = this.activeEditor.converter?.linkedStyles.find((style2) => style2.id === paragraphProps.styleId);
309703
- if (linkedStyles && linkedStyles.definition && linkedStyles.definition.styles && markToStyleMap[item.name.value] in linkedStyles.definition.styles) {
309704
- const linkedStylesItem = linkedStyles.definition.styles[markToStyleMap[item.name.value]];
309705
- const value = { [item.name.value]: linkedStylesItem };
309706
- item.activate(value);
309707
- activatedFromLinkedStyle = true;
309708
- }
309709
- }
309710
- if (item.name.value === "textAlign" && paragraphProps?.justification)
309711
- item.activate({ textAlign: paragraphProps.justification });
309712
- if (item.name.value === "fontFamily" && selectionIsCollapsed && paragraphIsEmpty && !activeMark && !markNegated && !activatedFromLinkedStyle && paragraphFontFamily)
309713
- item.activate({ fontFamily: paragraphFontFamily });
309714
- if (item.name.value === "lineHeight")
309715
- if (paragraphProps?.spacing)
309716
- item.selectedValue.value = twipsToLines(paragraphProps.spacing.line);
309717
- else
309718
- item.selectedValue.value = "";
309719
- if (item.name.value === "tableActions")
309720
- item.disabled.value = !inTable;
309721
- const listParent = isList(paragraphParent?.node) ? paragraphParent.node : null;
309722
- if (listParent) {
309723
- const numberingType = listParent.attrs.listRendering.numberingType;
309724
- if (item.name.value === "list" && numberingType === "bullet")
309725
- item.activate();
309726
- else if (item.name.value === "numberedlist" && numberingType !== "bullet")
309727
- item.activate();
309728
- }
309729
- if (item.name.value === "ruler")
309730
- if (this.superdoc?.config?.rulers)
309731
- item.activate();
309732
- else
309733
- item.deactivate();
310614
+ this.#applyHeadlessState(item);
309734
310615
  });
309735
310616
  }
309736
310617
  onToolbarResize = () => {
@@ -309755,48 +310636,22 @@ function print() { __p += __j.call(arguments, '') }
309755
310636
  item.setDisabled(true);
309756
310637
  });
309757
310638
  }
309758
- #updateToolbarHistory() {
309759
- if (!this.activeEditor?.state)
309760
- return;
309761
- try {
309762
- if (this.activeEditor.options.ydoc) {
309763
- const undoManager = yUndoPluginKey.getState(this.activeEditor.state)?.undoManager;
309764
- this.undoDepth = undoManager?.undoStack.length || 0;
309765
- this.redoDepth = undoManager?.redoStack.length || 0;
309766
- } else {
309767
- this.undoDepth = undoDepth(this.activeEditor.state);
309768
- this.redoDepth = redoDepth(this.activeEditor.state);
309769
- }
309770
- } catch {
309771
- this.undoDepth = 0;
309772
- this.redoDepth = 0;
309773
- }
309774
- }
309775
- #enrichTrackedChanges(trackedChanges = []) {
309776
- if (!trackedChanges?.length)
309777
- return trackedChanges;
309778
- const store = this.superdoc?.commentsStore;
309779
- if (!store?.getComment)
309780
- return trackedChanges;
309781
- return trackedChanges.map((change) => {
309782
- const commentId = change.id;
309783
- if (!commentId)
309784
- return change;
309785
- const storeComment = store.getComment(commentId);
309786
- if (!storeComment)
309787
- return change;
309788
- const comment2 = typeof storeComment.getValues === "function" ? storeComment.getValues() : storeComment;
309789
- return {
309790
- ...change,
309791
- comment: comment2
309792
- };
309793
- });
309794
- }
309795
310639
  onEditorTransaction({ transaction }) {
309796
310640
  if (!transaction.docChanged && !transaction.selectionSet)
309797
310641
  return;
309798
310642
  this.updateToolbarState();
309799
310643
  }
310644
+ #scheduleRestoreEditorFocus() {
310645
+ if (!this.activeEditor || this.activeEditor.options.isHeaderOrFooter)
310646
+ return;
310647
+ clearTimeout(this._restoreFocusTimeoutId);
310648
+ this._restoreFocusTimeoutId = setTimeout(() => {
310649
+ this._restoreFocusTimeoutId = null;
310650
+ if (!this.activeEditor || this.activeEditor.options.isHeaderOrFooter)
310651
+ return;
310652
+ this.activeEditor.focus();
310653
+ }, 0);
310654
+ }
309800
310655
  emitCommand({ item, argument, option }) {
309801
310656
  const hasFocusFn = this.activeEditor?.view?.hasFocus;
309802
310657
  const wasFocused = Boolean(typeof hasFocusFn === "function" && hasFocusFn.call(this.activeEditor.view));
@@ -309827,14 +310682,21 @@ function print() { __p += __j.call(arguments, '') }
309827
310682
  this.activeEditor.focus();
309828
310683
  if (!command$1)
309829
310684
  return;
309830
- if (command$1 in this.#interceptedCommands) {
309831
- const result = this.#interceptedCommands[command$1]({
309832
- item,
309833
- argument
309834
- });
309835
- if (isMarkToggle)
309836
- this.#syncStickyMarksFromState();
309837
- return result;
310685
+ if (item?.name?.value === "tableActions") {
310686
+ if (this.#executeHeadlessCommand(item, argument)) {
310687
+ this.updateToolbarState();
310688
+ return;
310689
+ }
310690
+ }
310691
+ if (HEADLESS_EXECUTE_ITEMS.has(item?.name?.value)) {
310692
+ if (this.#executeHeadlessCommand(item, argument)) {
310693
+ if (isMarkToggle)
310694
+ this.#syncStickyMarksFromState();
310695
+ this.updateToolbarState();
310696
+ if (shouldRestoreFocus)
310697
+ this.#scheduleRestoreEditorFocus();
310698
+ return;
310699
+ }
309838
310700
  }
309839
310701
  if (this.activeEditor && this.activeEditor.commands && command$1 in this.activeEditor.commands)
309840
310702
  this.activeEditor.commands[command$1](argument);
@@ -309855,13 +310717,8 @@ function print() { __p += __j.call(arguments, '') }
309855
310717
  if (isMarkToggle)
309856
310718
  this.#syncStickyMarksFromState();
309857
310719
  this.updateToolbarState();
309858
- if (shouldRestoreFocus && this.activeEditor && !this.activeEditor.options.isHeaderOrFooter)
309859
- this._restoreFocusTimeoutId = setTimeout(() => {
309860
- this._restoreFocusTimeoutId = null;
309861
- if (!this.activeEditor || this.activeEditor.options.isHeaderOrFooter)
309862
- return;
309863
- this.activeEditor.focus();
309864
- }, 0);
310720
+ if (shouldRestoreFocus)
310721
+ this.#scheduleRestoreEditorFocus();
309865
310722
  }
309866
310723
  onEditorSelectionUpdate() {
309867
310724
  if (!this.activeEditor)
@@ -309873,12 +310730,16 @@ function print() { __p += __j.call(arguments, '') }
309873
310730
  if (!command$1)
309874
310731
  return;
309875
310732
  try {
309876
- if (command$1 in this.#interceptedCommands)
309877
- this.#interceptedCommands[command$1]({
309878
- item,
309879
- argument
309880
- });
309881
- else if (this.activeEditor.commands && command$1 in this.activeEditor.commands)
310733
+ if (HEADLESS_EXECUTE_ITEMS.has(item?.name?.value)) {
310734
+ if (this.#executeHeadlessCommand(item, argument)) {
310735
+ this.#ensureStoredMarksForMarkToggle({
310736
+ command: command$1,
310737
+ argument
310738
+ });
310739
+ return;
310740
+ }
310741
+ }
310742
+ if (this.activeEditor.commands && command$1 in this.activeEditor.commands)
309882
310743
  this.activeEditor.commands[command$1](argument);
309883
310744
  this.#ensureStoredMarksForMarkToggle({
309884
310745
  command: command$1,
@@ -309913,25 +310774,6 @@ function print() { __p += __j.call(arguments, '') }
309913
310774
  const name = item?.name?.value;
309914
310775
  return SuperToolbar2.#MARK_TOGGLE_NAMES.has(name);
309915
310776
  }
309916
- #runCommandWithArgumentOnly({ item, argument, noArgumentCallback = false }, callback) {
309917
- if (!argument || !this.activeEditor)
309918
- return;
309919
- let command$1 = item.command;
309920
- const noArgumentCommand = item.noArgumentCommand;
309921
- if (argument === "none" && this.activeEditor && this.activeEditor.commands && noArgumentCommand in this.activeEditor.commands) {
309922
- this.activeEditor.commands[noArgumentCommand]();
309923
- if (typeof callback === "function" && noArgumentCallback)
309924
- callback(argument);
309925
- this.updateToolbarState();
309926
- return;
309927
- }
309928
- if (this.activeEditor && this.activeEditor.commands && command$1 in this.activeEditor.commands) {
309929
- this.activeEditor.commands[command$1](argument);
309930
- if (typeof callback === "function")
309931
- callback(argument);
309932
- this.updateToolbarState();
309933
- }
309934
- }
309935
310777
  #syncStickyMarksFromState() {
309936
310778
  if (!this.activeEditor)
309937
310779
  return;
@@ -309981,15 +310823,12 @@ function print() { __p += __j.call(arguments, '') }
309981
310823
  const tr = state.tr.setStoredMarks([mark2]);
309982
310824
  view.dispatch(tr);
309983
310825
  }
309984
- #isFieldAnnotationSelection() {
309985
- const selection = this.activeEditor?.state?.selection;
309986
- return selection instanceof NodeSelection && selection?.node?.type?.name === "fieldAnnotation";
309987
- }
309988
310826
  destroy() {
309989
310827
  if (this._restoreFocusTimeoutId !== null) {
309990
310828
  clearTimeout(this._restoreFocusTimeoutId);
309991
310829
  this._restoreFocusTimeoutId = null;
309992
310830
  }
310831
+ this.destroyHeadlessToolbar();
309993
310832
  }
309994
310833
  };
309995
310834
  Commands = Extension.create({
@@ -320808,7 +321647,7 @@ function print() { __p += __j.call(arguments, '') }
320808
321647
  const range = computeWordSelectionRangeAt(state, pos);
320809
321648
  if (!range)
320810
321649
  return false;
320811
- const tr = state.tr.setSelection(TextSelection2.create(state.doc, range.from, range.to));
321650
+ const tr = state.tr.setSelection(TextSelection.create(state.doc, range.from, range.to));
320812
321651
  try {
320813
321652
  this.#editor.view?.dispatch(tr);
320814
321653
  return true;
@@ -320825,7 +321664,7 @@ function print() { __p += __j.call(arguments, '') }
320825
321664
  const range = computeParagraphSelectionRangeAt(state, pos);
320826
321665
  if (!range)
320827
321666
  return false;
320828
- const tr = state.tr.setSelection(TextSelection2.create(state.doc, range.from, range.to));
321667
+ const tr = state.tr.setSelection(TextSelection.create(state.doc, range.from, range.to));
320829
321668
  try {
320830
321669
  this.#editor.view?.dispatch(tr);
320831
321670
  return true;
@@ -321648,8 +322487,8 @@ function print() { __p += __j.call(arguments, '') }
321648
322487
  }
321649
322488
  try {
321650
322489
  this.#localSelectionLayer.innerHTML = "";
321651
- const isFieldAnnotationSelection = selection instanceof NodeSelection && selection.node?.type?.name === "fieldAnnotation";
321652
- if (domRects.length > 0 && !isFieldAnnotationSelection)
322490
+ const isFieldAnnotationSelection2 = selection instanceof NodeSelection && selection.node?.type?.name === "fieldAnnotation";
322491
+ if (domRects.length > 0 && !isFieldAnnotationSelection2)
321653
322492
  renderSelectionRects({
321654
322493
  localSelectionLayer: this.#localSelectionLayer,
321655
322494
  rects: domRects,
@@ -322080,7 +322919,7 @@ function print() { __p += __j.call(arguments, '') }
322080
322919
  if (current.from === desiredFrom && current.to === desiredTo)
322081
322920
  return;
322082
322921
  try {
322083
- const tr = this.#editor.state.tr.setSelection(TextSelection2.create(this.#editor.state.doc, selAnchor, selHead));
322922
+ const tr = this.#editor.state.tr.setSelection(TextSelection.create(this.#editor.state.doc, selAnchor, selHead));
322084
322923
  this.#editor.view?.dispatch(tr);
322085
322924
  this.#scheduleSelectionUpdate();
322086
322925
  } catch {}
@@ -322894,11 +323733,11 @@ var init_zipper_DbkgrypV_es = __esm(() => {
322894
323733
 
322895
323734
  // ../../packages/superdoc/dist/super-editor.es.js
322896
323735
  var init_super_editor_es = __esm(() => {
322897
- init_src_84ZC_Jm8_es();
322898
- init_SuperConverter_w6yaFRT5_es();
323736
+ init_src_yUVuhLM1_es();
323737
+ init_SuperConverter_BgwP1GeS_es();
322899
323738
  init_jszip_C49i9kUs_es();
322900
323739
  init_xml_js_CqGKpaft_es();
322901
- init_create_headless_toolbar_CHK8yJic_es();
323740
+ init_create_headless_toolbar_Dcw4Hyt2_es();
322902
323741
  init_constants_CGhJRd87_es();
322903
323742
  init_dist_B8HfvhaK_es();
322904
323743
  init_unified_Dsuw2be5_es();