@stll/folio-react 0.33.1 → 0.34.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,9 +13,9 @@ import { afterCanonicalCompositionSettles } from "@stll/folio-core/controller/ca
13
13
  import { resolveCanonicalReviewRange } from "@stll/folio-core/controller/canonicalReview";
14
14
  import { FOLIO_DOCX_SERIALIZATION_MODE, createFolioEditor } from "@stll/folio-core/controller/folioEditor";
15
15
  import { CanonicalSessionRefusalError, collectRemoteSelections, createHiddenEditorManager, createHiddenEditorState } from "@stll/folio-core/controller/hiddenEditorManager";
16
- import { setDocumentBodyComments } from "@stll/folio-core/docx/canonicalModel";
17
16
  import { CanonicalSaveDiagnosticError, serializeCanonicalSave } from "@stll/folio-core/docx/canonicalSave";
18
17
  import { cloneDocumentWithParagraphPropertySources } from "@stll/folio-core/docx/document-clone";
18
+ import { getCommentParentId, getCommentParentId as getCommentParentId$1, withHostCommentThreads } from "@stll/folio-core/docx/hostCommentThreads";
19
19
  import { normalizeBaseDirection } from "@stll/folio-core/docx/normalizeBaseDirection";
20
20
  import { getCachedNumberingMap } from "@stll/folio-core/docx/numberingParser";
21
21
  import { DEFAULT_KEYBOARD_SHORTCUT_SCOPE, classifyEditorKeydown, deleteSelectedTable, historyShortcutOwner, isFocusInInputLike, isKeydownInShortcutScope, isMacPlatform } from "@stll/folio-core/managers/editorShortcuts";
@@ -25,7 +25,7 @@ import { computeScrollPageInfo, updateScrollPageTotal } from "@stll/folio-core/p
25
25
  import { DEFAULT_PAGE_HEIGHT_PX, getMargins, getPageSize, twipsToPixels } from "@stll/folio-core/paged-layout/sectionGeometry";
26
26
  import { NO_LIST_STATE, TextSelection, addColumnLeft, addColumnRight, addRowAbove, addRowBelow, applyFormatMarks, applyStyle, applyTableStyle, autoFitContents, captureFormatMarks, clearFormatting, clearTextColor, continueNumbering, createStyleResolver, decreaseIndent, decreaseListLevel, deleteColumn, deleteRow, deleteTable, distributeColumns, extractSelectionState, getDocumentBuiltInStyles, getSelectedText, getTableContext, increaseIndent, increaseListLevel, listStateLevel, mergeCells, removeTabStop, removeTableBorders, restartNumbering, sameListState, schema, selectColumn, selectRow, selectTable, setAlignment, setAllTableBorders, setCellBorder, setCellFillColor, setCellMargins, setCellTextDirection, setCellVerticalAlign, setFontFamily, setFontSize, setHighlight, setIndentFirstLine, setIndentLeft, setIndentRight, setInsideTableBorders, setLineSpacing, setLtr, setNumberingValue, setOutsideTableBorders, setRowHeight, setRtl, setTableBorderColor, setTableBorderPreset, setTableBorderWidth, setTableProperties, setTextColor, splitCell, toggleBidi, toggleBold, toggleBulletList, toggleHeaderRow, toggleItalic, toggleNoWrap, toggleNumberedList, toggleStrike, toggleSubscript, toggleSuperscript, toggleUnderline } from "@stll/folio-core/prosemirror";
27
27
  import { expectImageAttrs, expectTableAttrs } from "@stll/folio-core/prosemirror/attrs";
28
- import { acceptAIEditRevision, acceptChange, acceptSuggestion, findAIEditRevisionRange, findChangeAtPosition, findNextChange, findParagraphBoundaryChangeAtPosition, findPreviousChange, findSuggestionRange, getSuggestions, rejectAIEditRevision, rejectChange, rejectSuggestion } from "@stll/folio-core/prosemirror/commands/comments";
28
+ import { acceptAIEditRevision, acceptChange, acceptSuggestion, changeResolutionLockViolation, findAIEditRevisionRange, findChangeAtPosition, findNextChange, findParagraphBoundaryChangeAtPosition, findPreviousChange, findSuggestionRange, getSuggestions, rejectAIEditRevision, rejectChange, rejectSuggestion } from "@stll/folio-core/prosemirror/commands/comments";
29
29
  import { blockSdtAttrsToSdtProperties, findBlockSdtMatch, findBlockSdtMatches, removeContentControlTr, setContentControlContentTr, setContentControlValueTr } from "@stll/folio-core/prosemirror/commands/contentControls";
30
30
  import { setContentControlContentBlocksTr } from "@stll/folio-core/prosemirror/commands/contentControlsBlockFill";
31
31
  import { insertPageBreak } from "@stll/folio-core/prosemirror/commands/pageBreak";
@@ -46,7 +46,7 @@ import { createTemplateDirectivesPlugin, templateDirectivesKey } from "@stll/fol
46
46
  import { createTemplatePreviewValuesPlugin, templatePreviewValuesKey } from "@stll/folio-core/prosemirror/plugins/templatePreviewValues";
47
47
  import { getTemplateSlashMenu, templateSlashMenuPlugin } from "@stll/folio-core/prosemirror/plugins/templateSlashMenu";
48
48
  import { getFolioParaIdFromBlockId } from "@stll/folio-core/types/block-id";
49
- import { CANONICAL_GAP, canonicalRefusalMessage, usesCanonicalSession } from "@stll/folio-core/types/canonicalCapabilities";
49
+ import { CANONICAL_GAP, canonicalRefusalMessage, canonicalRefusalNotice, usesCanonicalSession } from "@stll/folio-core/types/canonicalCapabilities";
50
50
  import { canonicalJson } from "@stll/folio-core/utils/canonicalJson";
51
51
  import { resolveColor } from "@stll/folio-core/utils/colorResolver";
52
52
  import { closestHtmlElement, htmlQueryAll, queryHtmlElement } from "@stll/folio-core/utils/domGuards";
@@ -632,7 +632,7 @@ const HiddenHeaderFooterPMs = memo(forwardRef(function HiddenHeaderFooterPMs({ d
632
632
  getTheme: () => themeRef.current,
633
633
  getCanonicalApi: () => canonicalApiRef.current?.() ?? null,
634
634
  getExperimentalSession: () => sessionRef.current,
635
- onSessionRefusal: (reason, gap, error) => refusalRef.current?.(reason, gap, error),
635
+ onSessionRefusal: (reason, ground, error) => refusalRef.current?.(reason, ground, error),
636
636
  onTransaction: ({ rId, kind, view, docChanged, selectionChanged }) => {
637
637
  onTransactionRef.current?.(rId, kind, view, docChanged, selectionChanged);
638
638
  }
@@ -737,7 +737,7 @@ const NoteStoryEditor = forwardRef(function NoteStoryEditor(t0, ref) {
737
737
  getTheme: () => themeRef.current,
738
738
  getCanonicalApi: () => canonicalApiRef.current?.() ?? null,
739
739
  getExperimentalSession: () => sessionRef.current,
740
- onSessionRefusal: (reason, gap, error) => refusalRef.current?.(reason, gap, error),
740
+ onSessionRefusal: (reason, ground, error) => refusalRef.current?.(reason, ground, error),
741
741
  onTransaction: (t3) => {
742
742
  const { docChanged, selectionChanged, view } = t3;
743
743
  if (docChanged) {
@@ -1428,7 +1428,7 @@ const HiddenProseMirror = forwardRef((props, ref) => {
1428
1428
  getExperimentalSession: () => experimentalSessionRef.current,
1429
1429
  getEditingMode: () => suggestionModeActiveRef.current ? "suggesting" : "editing",
1430
1430
  getSuggestionAuthor: () => suggestionAuthorRef.current,
1431
- onSessionRefusal: (reason, gap, error) => onSessionRefusalRef.current?.(reason, gap, error),
1431
+ onSessionRefusal: (reason, ground, error) => onSessionRefusalRef.current?.(reason, ground, error),
1432
1432
  getDocumentIdentity: () => documentIdentityRef.current,
1433
1433
  getDocumentContext: () => documentRef.current,
1434
1434
  onTransaction: (update) => onTransactionRef.current?.(update),
@@ -3306,9 +3306,9 @@ const PagedEditor = forwardRef(function PagedEditor(props, ref) {
3306
3306
  onTotalPagesChange,
3307
3307
  onError
3308
3308
  ]);
3309
- const handleSessionRefusal = useCallback((message, gap, error) => {
3309
+ const handleSessionRefusal = useCallback((message, ground, error) => {
3310
3310
  onErrorRef.current?.(error ?? new CanonicalSessionRefusalError({
3311
- gap,
3311
+ ground,
3312
3312
  message
3313
3313
  }));
3314
3314
  }, []);
@@ -6357,9 +6357,6 @@ function createComment(text, authorName, parentId, id) {
6357
6357
  ...parentId !== void 0 && { parentId }
6358
6358
  };
6359
6359
  }
6360
- function getCommentParentId(comment) {
6361
- return comment.parentId;
6362
- }
6363
6360
  /**
6364
6361
  * Threads the comments sidebar shows a card for: top-level comments not yet
6365
6362
  * resolved. Tracked changes are painted inline and have no card, so a
@@ -6384,91 +6381,6 @@ function applyCommentMarkRange(view, range, commentId, options) {
6384
6381
  view.dispatch(tr);
6385
6382
  return true;
6386
6383
  }
6387
- /**
6388
- * Walk arbitrary Folio content subtrees and collect every comment id that
6389
- * is *referenced* by an inline anchor (`commentRangeStart`,
6390
- * `commentRangeEnd`, or `commentReference`). Used at save time to detect
6391
- * which comment threads still have something to anchor to, so that
6392
- * comments whose underlying text has been edited away can be pruned
6393
- * before serialization instead of being written out as phantom threads
6394
- * that no Word reader can scroll to.
6395
- *
6396
- * Pass every part of the document that can carry anchors — comments can
6397
- * live in headers, footers, footnotes, and endnotes as well as the
6398
- * main body, and a save path that only checks the body would prune
6399
- * legitimate header/footer/note comments.
6400
- *
6401
- * Uses `for (const key in obj)` instead of `Object.values(obj)` so the
6402
- * recursive walk doesn't allocate a values array at every node; also
6403
- * handles `Map` containers (e.g., `package.headers`) which `Object.values`
6404
- * would silently skip.
6405
- */
6406
- function collectCommentIdsFromSources(...sources) {
6407
- const ids = /* @__PURE__ */ new Set();
6408
- const visit = (node) => {
6409
- if (node === null || node === void 0) return;
6410
- if (Array.isArray(node)) {
6411
- for (const item of node) visit(item);
6412
- return;
6413
- }
6414
- if (node instanceof Map) {
6415
- for (const value of node.values()) visit(value);
6416
- return;
6417
- }
6418
- if (typeof node !== "object") return;
6419
- const obj = node;
6420
- const type = obj["type"];
6421
- if ((type === "commentRangeStart" || type === "commentRangeEnd" || type === "commentReference") && typeof obj["id"] === "number") ids.add(obj["id"]);
6422
- for (const key in obj) visit(obj[key]);
6423
- };
6424
- for (const source of sources) visit(source);
6425
- return ids;
6426
- }
6427
- /**
6428
- * Filter `comments` to drop entries whose reply chain has lost its root.
6429
- *
6430
- * Kept:
6431
- * - every top-level comment (`parentId` is null/undefined), regardless of
6432
- * whether its id appears in `referencedIds`,
6433
- * - replies whose parent chain transitively reaches a kept top-level
6434
- * comment.
6435
- *
6436
- * Dropped:
6437
- * - replies whose explicit `parentId` does not reach a kept top-level
6438
- * comment (a true broken-thread orphan).
6439
- *
6440
- * Why we don't prune unanchored top-level comments: pre-Word-2013
6441
- * documents (and any document missing `commentsExtended.xml`) carry no
6442
- * reply-thread metadata, so Word replies in those files arrive with
6443
- * `parentId === undefined` and look indistinguishable from a true
6444
- * top-level comment whose anchor has been edited away. Dropping
6445
- * unanchored top-level entries would silently lose every reply in
6446
- * those older files on the first save — a strictly worse failure mode
6447
- * than re-emitting a comment whose anchor was actually deleted. The
6448
- * complementary "overwrite stale `comments.xml`" fix in the save paths
6449
- * already prevents the phantom-thread regression when the array does
6450
- * end up empty.
6451
- */
6452
- function pruneOrphanedComments(comments, _referencedIds) {
6453
- const keptIds = /* @__PURE__ */ new Set();
6454
- for (const comment of comments) {
6455
- const parentId = getCommentParentId(comment);
6456
- if (parentId === null || parentId === void 0) keptIds.add(comment.id);
6457
- }
6458
- let addedThisPass = true;
6459
- while (addedThisPass) {
6460
- addedThisPass = false;
6461
- for (const comment of comments) {
6462
- if (keptIds.has(comment.id)) continue;
6463
- const parentId = getCommentParentId(comment);
6464
- if (parentId !== null && parentId !== void 0 && keptIds.has(parentId)) {
6465
- keptIds.add(comment.id);
6466
- addedThisPass = true;
6467
- }
6468
- }
6469
- }
6470
- return comments.filter((comment) => keptIds.has(comment.id));
6471
- }
6472
6384
  function removePendingCommentMarkRange(view, range) {
6473
6385
  const commentMark = view.state.schema.marks["comment"];
6474
6386
  const safeRange = clampCommentMarkRange(view.state.doc.content.size, range);
@@ -9616,17 +9528,8 @@ function detectImageContext(state) {
9616
9528
  function detectActiveTrackedChange(state) {
9617
9529
  const { from } = state.selection;
9618
9530
  const $pos = state.doc.resolve(from);
9619
- const node = $pos.parent;
9620
- if (!node.isTextblock) return null;
9621
- let childOffset = 0;
9622
- for (let index = 0; index < node.childCount; index += 1) {
9623
- const child = node.child(index);
9624
- const childStart = $pos.start() + childOffset;
9625
- const childEnd = childStart + child.nodeSize;
9626
- if (from < childStart || from > childEnd || !child.isText) {
9627
- childOffset += child.nodeSize;
9628
- continue;
9629
- }
9531
+ for (const child of [$pos.nodeBefore, $pos.nodeAfter]) {
9532
+ if (!child?.isText) continue;
9630
9533
  for (const mark of child.marks) {
9631
9534
  if (mark.type.name !== "insertion" && mark.type.name !== "deletion") continue;
9632
9535
  const range = findChangeAtPosition(state, from, from);
@@ -9635,10 +9538,10 @@ function detectActiveTrackedChange(state) {
9635
9538
  author: mark.attrs["author"] || "Unknown",
9636
9539
  date: mark.attrs["date"] || null,
9637
9540
  from: range.from,
9638
- to: range.to
9541
+ to: range.to,
9542
+ heldByLock: heldByLock(state, range)
9639
9543
  };
9640
9544
  }
9641
- childOffset += child.nodeSize;
9642
9545
  }
9643
9546
  const paragraphChange = findParagraphBoundaryChangeAtPosition(state, from);
9644
9547
  if (!paragraphChange) return null;
@@ -9647,9 +9550,21 @@ function detectActiveTrackedChange(state) {
9647
9550
  author: paragraphChange.author || "Unknown",
9648
9551
  date: paragraphChange.date || null,
9649
9552
  from: paragraphChange.from,
9650
- to: paragraphChange.to
9553
+ to: paragraphChange.to,
9554
+ heldByLock: heldByLock(state, paragraphChange)
9651
9555
  };
9652
9556
  }
9557
+ /** What the content-control locks say about resolving the changes in `range`. */
9558
+ const heldByLock = (state, range) => ({
9559
+ accept: changeResolutionLockViolation(state, {
9560
+ ...range,
9561
+ mode: "accept"
9562
+ }) !== null,
9563
+ reject: changeResolutionLockViolation(state, {
9564
+ ...range,
9565
+ mode: "reject"
9566
+ }) !== null
9567
+ });
9653
9568
  // src/components/hooks/useContextMenu.ts
9654
9569
  function useContextMenu(t0) {
9655
9570
  const $ = c(7);
@@ -13878,7 +13793,7 @@ function useFolioComments(t0) {
13878
13793
  if ($[38] !== listedComments || $[39] !== visibleCommentIds) {
13879
13794
  visibleRootIds = /* @__PURE__ */ new Set();
13880
13795
  for (const comment_1 of listedComments) {
13881
- const parentId_0 = getCommentParentId(comment_1);
13796
+ const parentId_0 = getCommentParentId$1(comment_1);
13882
13797
  if (parentId_0 === null || parentId_0 === void 0 || !visibleCommentIds.has(comment_1.id)) continue;
13883
13798
  visibleRootIds.add(parentId_0);
13884
13799
  }
@@ -13891,7 +13806,7 @@ function useFolioComments(t0) {
13891
13806
  let t20;
13892
13807
  if ($[45] !== visibleCommentIds || $[46] !== visibleRootIds) {
13893
13808
  t20 = (comment_2) => {
13894
- const parentId_1 = getCommentParentId(comment_2);
13809
+ const parentId_1 = getCommentParentId$1(comment_2);
13895
13810
  if (parentId_1 !== null && parentId_1 !== void 0) return visibleCommentIds.has(comment_2.id);
13896
13811
  return visibleCommentIds.has(comment_2.id) || visibleRootIds.has(comment_2.id);
13897
13812
  };
@@ -14048,8 +13963,8 @@ function _temp(id_4) {
14048
13963
  // src/components/DocxEditor.tsx
14049
13964
  /** No headings to track while the outline is not shown. */
14050
13965
  const NO_HEADINGS = [];
14051
- const CommentsSidebar = lazy(() => import("./CommentsSidebar-CUCUQpXb.js").then((m) => ({ default: m.CommentsSidebar })));
14052
- const TextContextMenu = lazy(() => import("./TextContextMenu-BxnNvhJg.js").then((m) => ({ default: m.TextContextMenu })));
13966
+ const CommentsSidebar = lazy(() => import("./CommentsSidebar-4XdScjMH.js").then((m) => ({ default: m.CommentsSidebar })));
13967
+ const TextContextMenu = lazy(() => import("./TextContextMenu-jOBgICwD.js").then((m) => ({ default: m.TextContextMenu })));
14053
13968
  const loadAttemptSelectiveSave = async () => {
14054
13969
  const { attemptSelectiveSave } = await import("@stll/folio-core/docx/selectiveSave");
14055
13970
  return attemptSelectiveSave;
@@ -14114,7 +14029,7 @@ function areImageContextsEqual(a, b) {
14114
14029
  function areActiveTrackedChangesEqual(a, b) {
14115
14030
  if (a === b) return true;
14116
14031
  if (!a || !b) return false;
14117
- return a.type === b.type && a.author === b.author && a.date === b.date && a.from === b.from && a.to === b.to;
14032
+ return a.type === b.type && a.author === b.author && a.date === b.date && a.from === b.from && a.to === b.to && a.heldByLock.accept === b.heldByLock.accept && a.heldByLock.reject === b.heldByLock.reject;
14118
14033
  }
14119
14034
  const assignRef = (ref, value) => {
14120
14035
  ref.current = value;
@@ -14207,12 +14122,15 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
14207
14122
  readOnlyProp,
14208
14123
  ...reviewDisplayMode === void 0 ? {} : { reviewDisplayMode }
14209
14124
  });
14210
- useEffect(() => {
14125
+ const syncCanonicalMode = useCallback(() => {
14211
14126
  pagedEditorRef.current?.getEditor().setCanonicalMode(editingMode === "suggesting" ? {
14212
14127
  type: "suggesting",
14213
14128
  author
14214
14129
  } : { type: "editing" });
14215
14130
  }, [editingMode, author]);
14131
+ useEffect(() => {
14132
+ syncCanonicalMode();
14133
+ }, [syncCanonicalMode]);
14216
14134
  const extractTrackedChangesTimerRef = useRef(null);
14217
14135
  const extractTrackedChanges = useCallback(() => {
14218
14136
  const view = pagedEditorRef.current?.getView();
@@ -14265,7 +14183,7 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
14265
14183
  const refuseCanonicalModelEdit = useCallback((gap, message) => {
14266
14184
  if (!usesCanonicalSession(experimentalSession, CANONICAL_GAP.authorityRouting)) return false;
14267
14185
  const error = new CanonicalSessionRefusalError({
14268
- gap,
14186
+ ground: { gap },
14269
14187
  message: canonicalRefusalMessage(gap, message)
14270
14188
  });
14271
14189
  toast(error.message);
@@ -14372,21 +14290,34 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
14372
14290
  };
14373
14291
  }, [onEditorViewReady, reportEditorViewReady]);
14374
14292
  const [bodyViewEpoch, setBodyViewEpoch] = useState(0);
14375
- const handleBodyViewReady = useCallback((view_2) => {
14376
- reportEditorViewReady(view_2);
14293
+ const syncSuggestionMode = useCallback((view_2) => {
14294
+ const active = editingMode === "suggesting";
14295
+ const current = suggestionModeKey.getState(view_2.state);
14296
+ if (current?.active !== active || current.author !== author) setSuggestionMode(active, view_2.state, view_2.dispatch, author);
14297
+ }, [editingMode, author]);
14298
+ const handleBodyViewReady = useCallback((view_3) => {
14299
+ if (view_3) {
14300
+ syncSuggestionMode(view_3);
14301
+ syncCanonicalMode();
14302
+ }
14303
+ reportEditorViewReady(view_3);
14377
14304
  setBodyViewEpoch((epoch) => epoch + 1);
14378
- }, [reportEditorViewReady]);
14305
+ }, [
14306
+ reportEditorViewReady,
14307
+ syncCanonicalMode,
14308
+ syncSuggestionMode
14309
+ ]);
14379
14310
  useEffect(() => {
14380
14311
  const pagedEditor = pagedEditorRef.current;
14381
14312
  if (!showOutline || bodyViewEpoch === 0 || !pagedEditor) return;
14382
14313
  let collectedDoc = null;
14383
14314
  let collected = [];
14384
14315
  const refresh = (layout) => {
14385
- const view_3 = pagedEditor.getView();
14386
- if (!view_3) return;
14387
- if (view_3.state.doc !== collectedDoc) {
14388
- collectedDoc = view_3.state.doc;
14389
- collected = collectHeadings(view_3.state.doc, getDocumentBuiltInStyles(view_3.state));
14316
+ const view_4 = pagedEditor.getView();
14317
+ if (!view_4) return;
14318
+ if (view_4.state.doc !== collectedDoc) {
14319
+ collectedDoc = view_4.state.doc;
14320
+ collected = collectHeadings(view_4.state.doc, getDocumentBuiltInStyles(view_4.state));
14390
14321
  }
14391
14322
  setHeadingInfos((previous) => resolveOutlineHeadings({
14392
14323
  collected,
@@ -14737,9 +14668,9 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
14737
14668
  });
14738
14669
  }, [onFontsLoadedCallback]);
14739
14670
  useEffect(() => {
14740
- const view_4 = pagedEditorRef.current?.getView();
14741
- if (view_4) setSuggestionMode(editingMode === "suggesting", view_4.state, view_4.dispatch, author);
14742
- }, [editingMode, author]);
14671
+ const view_5 = pagedEditorRef.current?.getView();
14672
+ if (view_5) syncSuggestionMode(view_5);
14673
+ }, [syncSuggestionMode]);
14743
14674
  const handleDocumentChange = useCallback((newDocument) => {
14744
14675
  const canonical = usesCanonicalSession(experimentalSession, CANONICAL_GAP.authorityRouting);
14745
14676
  const currentComments = commentsRef.current;
@@ -14786,16 +14717,14 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
14786
14717
  const flushBag = (bag) => {
14787
14718
  if (!bag) return;
14788
14719
  for (const [rId, hf] of bag) {
14789
- const view_5 = editor_0.getHfView(rId);
14790
- if (view_5) hf.content = proseDocToBlocks(view_5.state.doc, hf.content);
14720
+ const view_6 = editor_0.getHfView(rId);
14721
+ if (view_6) hf.content = proseDocToBlocks(view_6.state.doc, hf.content);
14791
14722
  }
14792
14723
  };
14793
14724
  flushBag(doc_0.package.headers);
14794
14725
  flushBag(doc_0.package.footers);
14795
14726
  }
14796
- const referencedCommentIds = collectCommentIdsFromSources(doc_0.package.document.content, doc_0.package.headers, doc_0.package.footers, doc_0.package.footnotes, doc_0.package.endnotes);
14797
- setDocumentBodyComments(doc_0.package.document, pruneOrphanedComments(commentsRef.current, referencedCommentIds));
14798
- return doc_0;
14727
+ return withHostCommentThreads(doc_0, commentsRef.current);
14799
14728
  }, [commentsRef, experimentalSession]);
14800
14729
  const applyCanonicalComment = useCallback((request) => {
14801
14730
  return getCanonicalApi()?.applyCanonicalComment(request) ?? null;
@@ -14842,9 +14771,9 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
14842
14771
  return;
14843
14772
  }
14844
14773
  if (result?.status !== "refused" || result.retry !== "afterComposition") return;
14845
- const view_6 = getCanonicalApi()?.getView();
14846
- if (!view_6) return;
14847
- return afterCanonicalCompositionSettles(view_6, () => setControlledCommentsRetry((attempt) => attempt + 1));
14774
+ const view_7 = getCanonicalApi()?.getView();
14775
+ if (!view_7) return;
14776
+ return afterCanonicalCompositionSettles(view_7, () => setControlledCommentsRetry((attempt) => attempt + 1));
14848
14777
  });
14849
14778
  useEffect(() => synchronizeControlledComments({
14850
14779
  commentsProp,
@@ -14945,17 +14874,17 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
14945
14874
  resetFindResultRef.current = resetFindResult;
14946
14875
  }, [resetFindResult]);
14947
14876
  const handleSelectionChange = useCallback((selectionState) => {
14948
- const view_7 = getActiveEditorView();
14949
- if (view_7) {
14950
- const { from, to } = view_7.state.selection;
14877
+ const view_8 = getActiveEditorView();
14878
+ if (view_8) {
14879
+ const { from, to } = view_8.state.selection;
14951
14880
  lastSelectionRef.current = {
14952
14881
  from,
14953
14882
  to
14954
14883
  };
14955
14884
  }
14956
14885
  let pmTableCtx = null;
14957
- if (view_7) {
14958
- pmTableCtx = getTableContext(view_7.state);
14886
+ if (view_8) {
14887
+ pmTableCtx = getTableContext(view_8.state);
14959
14888
  if (!pmTableCtx.isInTable) pmTableCtx = null;
14960
14889
  }
14961
14890
  if (pmTableCtx?.cellBorderColor) {
@@ -14967,8 +14896,8 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
14967
14896
  color: { rgb }
14968
14897
  };
14969
14898
  }
14970
- const pmImageCtx = view_7 ? detectImageContext(view_7.state) : null;
14971
- const trackedChange = view_7 ? detectActiveTrackedChange(view_7.state) : null;
14899
+ const pmImageCtx = view_8 ? detectImageContext(view_8.state) : null;
14900
+ const trackedChange = view_8 ? detectActiveTrackedChange(view_8.state) : null;
14972
14901
  if (!selectionState) {
14973
14902
  setFloatingCommentBtn(null);
14974
14903
  setState((prev_1) => {
@@ -15031,10 +14960,10 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
15031
14960
  activeTrackedChange: activeTrackedChange_0
15032
14961
  };
15033
14962
  });
15034
- if (view_7 && selectionState.hasSelection && !isAddingComment && !readOnly) {
14963
+ if (view_8 && selectionState.hasSelection && !isAddingComment && !readOnly) {
15035
14964
  const container = scrollContainerRef.current;
15036
14965
  const parentEl = editorContentRef.current;
15037
- const { from: selFrom } = view_7.state.selection;
14966
+ const { from: selFrom } = view_8.state.selection;
15038
14967
  const top = findSelectionYPosition(container, parentEl, selFrom);
15039
14968
  if (top !== null && container && parentEl) {
15040
14969
  const pagesEl = container.querySelector(".paged-editor__pages");
@@ -15042,7 +14971,7 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
15042
14971
  const parentRect = parentEl.getBoundingClientRect();
15043
14972
  const rawLeft = pageEl ? pageEl.getBoundingClientRect().right - parentRect.left + 12 : parentRect.width / 2 + 408;
15044
14973
  const left = Math.max(16, Math.min(rawLeft, parentRect.width - 16));
15045
- const { from: from_0, to: to_0 } = view_7.state.selection;
14974
+ const { from: from_0, to: to_0 } = view_8.state.selection;
15046
14975
  if (from_0 !== to_0) setFloatingCommentBtn({
15047
14976
  top,
15048
14977
  left,
@@ -15205,99 +15134,99 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
15205
15134
  refuseCanonicalModelEdit
15206
15135
  ]);
15207
15136
  const handleTableAction = useCallback((action_0) => {
15208
- const view_8 = getActiveEditorView();
15209
- if (!view_8) return;
15137
+ const view_9 = getActiveEditorView();
15138
+ if (!view_9) return;
15210
15139
  switch (action_0) {
15211
15140
  case "addRowAbove":
15212
- addRowAbove(view_8.state, view_8.dispatch);
15141
+ addRowAbove(view_9.state, view_9.dispatch);
15213
15142
  break;
15214
15143
  case "addRowBelow":
15215
- addRowBelow(view_8.state, view_8.dispatch);
15144
+ addRowBelow(view_9.state, view_9.dispatch);
15216
15145
  break;
15217
15146
  case "addColumnLeft":
15218
- addColumnLeft(view_8.state, view_8.dispatch);
15147
+ addColumnLeft(view_9.state, view_9.dispatch);
15219
15148
  break;
15220
15149
  case "addColumnRight":
15221
- addColumnRight(view_8.state, view_8.dispatch);
15150
+ addColumnRight(view_9.state, view_9.dispatch);
15222
15151
  break;
15223
15152
  case "deleteRow":
15224
- deleteRow(view_8.state, view_8.dispatch);
15153
+ deleteRow(view_9.state, view_9.dispatch);
15225
15154
  break;
15226
15155
  case "deleteColumn":
15227
- deleteColumn(view_8.state, view_8.dispatch);
15156
+ deleteColumn(view_9.state, view_9.dispatch);
15228
15157
  break;
15229
15158
  case "deleteTable":
15230
- deleteTable(view_8.state, view_8.dispatch);
15159
+ deleteTable(view_9.state, view_9.dispatch);
15231
15160
  break;
15232
15161
  case "selectTable":
15233
- selectTable(view_8.state, view_8.dispatch);
15162
+ selectTable(view_9.state, view_9.dispatch);
15234
15163
  break;
15235
15164
  case "selectRow":
15236
- selectRow(view_8.state, view_8.dispatch);
15165
+ selectRow(view_9.state, view_9.dispatch);
15237
15166
  break;
15238
15167
  case "selectColumn":
15239
- selectColumn(view_8.state, view_8.dispatch);
15168
+ selectColumn(view_9.state, view_9.dispatch);
15240
15169
  break;
15241
15170
  case "mergeCells":
15242
- mergeCells(view_8.state, view_8.dispatch);
15171
+ mergeCells(view_9.state, view_9.dispatch);
15243
15172
  break;
15244
15173
  case "splitCell":
15245
- splitCell(view_8.state, view_8.dispatch);
15174
+ splitCell(view_9.state, view_9.dispatch);
15246
15175
  break;
15247
15176
  case "borderAll":
15248
- setAllTableBorders(view_8.state, view_8.dispatch, borderSpecRef.current);
15177
+ setAllTableBorders(view_9.state, view_9.dispatch, borderSpecRef.current);
15249
15178
  break;
15250
15179
  case "borderOutside":
15251
- setOutsideTableBorders(view_8.state, view_8.dispatch, borderSpecRef.current);
15180
+ setOutsideTableBorders(view_9.state, view_9.dispatch, borderSpecRef.current);
15252
15181
  break;
15253
15182
  case "borderInside":
15254
- setInsideTableBorders(view_8.state, view_8.dispatch, borderSpecRef.current);
15183
+ setInsideTableBorders(view_9.state, view_9.dispatch, borderSpecRef.current);
15255
15184
  break;
15256
15185
  case "borderNone":
15257
- removeTableBorders(view_8.state, view_8.dispatch);
15186
+ removeTableBorders(view_9.state, view_9.dispatch);
15258
15187
  break;
15259
15188
  case "borderTop":
15260
- setCellBorder("top", borderSpecRef.current, true)(view_8.state, view_8.dispatch);
15189
+ setCellBorder("top", borderSpecRef.current, true)(view_9.state, view_9.dispatch);
15261
15190
  break;
15262
15191
  case "borderBottom":
15263
- setCellBorder("bottom", borderSpecRef.current, true)(view_8.state, view_8.dispatch);
15192
+ setCellBorder("bottom", borderSpecRef.current, true)(view_9.state, view_9.dispatch);
15264
15193
  break;
15265
15194
  case "borderLeft":
15266
- setCellBorder("left", borderSpecRef.current, true)(view_8.state, view_8.dispatch);
15195
+ setCellBorder("left", borderSpecRef.current, true)(view_9.state, view_9.dispatch);
15267
15196
  break;
15268
15197
  case "borderRight":
15269
- setCellBorder("right", borderSpecRef.current, true)(view_8.state, view_8.dispatch);
15198
+ setCellBorder("right", borderSpecRef.current, true)(view_9.state, view_9.dispatch);
15270
15199
  break;
15271
15200
  default: if (typeof action_0 === "object") {
15272
- if (action_0.type === "cellFillColor") setCellFillColor(action_0.color)(view_8.state, view_8.dispatch);
15201
+ if (action_0.type === "cellFillColor") setCellFillColor(action_0.color)(view_9.state, view_9.dispatch);
15273
15202
  else if (action_0.type === "borderColor") {
15274
15203
  const rgb_0 = action_0.color.replace(/^#/u, "");
15275
15204
  borderSpecRef.current = {
15276
15205
  ...borderSpecRef.current,
15277
15206
  color: { rgb: rgb_0 }
15278
15207
  };
15279
- setTableBorderColor(action_0.color)(view_8.state, view_8.dispatch);
15208
+ setTableBorderColor(action_0.color)(view_9.state, view_9.dispatch);
15280
15209
  } else if (action_0.type === "borderWidth") {
15281
15210
  borderSpecRef.current = {
15282
15211
  ...borderSpecRef.current,
15283
15212
  size: action_0.size
15284
15213
  };
15285
- setTableBorderWidth(action_0.size)(view_8.state, view_8.dispatch);
15214
+ setTableBorderWidth(action_0.size)(view_9.state, view_9.dispatch);
15286
15215
  } else if (action_0.type === "cellBorder") setCellBorder(action_0.side, {
15287
15216
  style: action_0.style,
15288
15217
  size: action_0.size,
15289
15218
  color: { rgb: action_0.color.replace(/^#/u, "") }
15290
- })(view_8.state, view_8.dispatch);
15291
- else if (action_0.type === "cellVerticalAlign") setCellVerticalAlign(action_0.align)(view_8.state, view_8.dispatch);
15292
- else if (action_0.type === "cellMargins") setCellMargins(action_0.margins)(view_8.state, view_8.dispatch);
15293
- else if (action_0.type === "cellTextDirection") setCellTextDirection(action_0.direction)(view_8.state, view_8.dispatch);
15294
- else if (action_0.type === "toggleNoWrap") toggleNoWrap()(view_8.state, view_8.dispatch);
15295
- else if (action_0.type === "rowHeight") setRowHeight(action_0.height, action_0.rule)(view_8.state, view_8.dispatch);
15296
- else if (action_0.type === "toggleHeaderRow") toggleHeaderRow()(view_8.state, view_8.dispatch);
15297
- else if (action_0.type === "distributeColumns") distributeColumns()(view_8.state, view_8.dispatch);
15298
- else if (action_0.type === "autoFitContents") autoFitContents()(view_8.state, view_8.dispatch);
15219
+ })(view_9.state, view_9.dispatch);
15220
+ else if (action_0.type === "cellVerticalAlign") setCellVerticalAlign(action_0.align)(view_9.state, view_9.dispatch);
15221
+ else if (action_0.type === "cellMargins") setCellMargins(action_0.margins)(view_9.state, view_9.dispatch);
15222
+ else if (action_0.type === "cellTextDirection") setCellTextDirection(action_0.direction)(view_9.state, view_9.dispatch);
15223
+ else if (action_0.type === "toggleNoWrap") toggleNoWrap()(view_9.state, view_9.dispatch);
15224
+ else if (action_0.type === "rowHeight") setRowHeight(action_0.height, action_0.rule)(view_9.state, view_9.dispatch);
15225
+ else if (action_0.type === "toggleHeaderRow") toggleHeaderRow()(view_9.state, view_9.dispatch);
15226
+ else if (action_0.type === "distributeColumns") distributeColumns()(view_9.state, view_9.dispatch);
15227
+ else if (action_0.type === "autoFitContents") autoFitContents()(view_9.state, view_9.dispatch);
15299
15228
  else if (action_0.type === "openTableProperties") setTablePropsOpen(true);
15300
- else if (action_0.type === "tableProperties") setTableProperties(action_0.props)(view_8.state, view_8.dispatch);
15229
+ else if (action_0.type === "tableProperties") setTableProperties(action_0.props)(view_9.state, view_9.dispatch);
15301
15230
  else {
15302
15231
  let preset = getBuiltinTableStyle(action_0.styleId);
15303
15232
  const currentDocForTable = historyStateRef.current;
@@ -15368,7 +15297,7 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
15368
15297
  if (preset.tableBorders) styleArg.tableBorders = preset.tableBorders;
15369
15298
  if (preset.conditionals) styleArg.conditionals = preset.conditionals;
15370
15299
  if (preset.look) styleArg.look = preset.look;
15371
- applyTableStyle(styleArg)(view_8.state, view_8.dispatch);
15300
+ applyTableStyle(styleArg)(view_9.state, view_9.dispatch);
15372
15301
  }
15373
15302
  }
15374
15303
  } else tableSelection.handleAction(action_0);
@@ -15389,86 +15318,86 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
15389
15318
  });
15390
15319
  }, [openContextMenu]);
15391
15320
  const handleFormat = useCallback((action_1) => {
15392
- const view_9 = getActiveEditorView();
15393
- if (!view_9) return;
15394
- view_9.focus();
15395
- const isBodyEditor = view_9 === pagedEditorRef.current?.getView();
15396
- const { from: from_1, to: to_1 } = view_9.state.selection;
15321
+ const view_10 = getActiveEditorView();
15322
+ if (!view_10) return;
15323
+ view_10.focus();
15324
+ const isBodyEditor = view_10 === pagedEditorRef.current?.getView();
15325
+ const { from: from_1, to: to_1 } = view_10.state.selection;
15397
15326
  const savedSelection = lastSelectionRef.current;
15398
15327
  if (isBodyEditor && savedSelection && (from_1 !== savedSelection.from || to_1 !== savedSelection.to)) try {
15399
- const tr = view_9.state.tr.setSelection(TextSelection.create(view_9.state.doc, savedSelection.from, savedSelection.to));
15400
- view_9.dispatch(tr);
15328
+ const tr = view_10.state.tr.setSelection(TextSelection.create(view_10.state.doc, savedSelection.from, savedSelection.to));
15329
+ view_10.dispatch(tr);
15401
15330
  } catch {}
15402
15331
  if (action_1 === "bold") {
15403
- executeEditorCommand(view_9, toggleBold);
15332
+ executeEditorCommand(view_10, toggleBold);
15404
15333
  return;
15405
15334
  }
15406
15335
  if (action_1 === "italic") {
15407
- executeEditorCommand(view_9, toggleItalic);
15336
+ executeEditorCommand(view_10, toggleItalic);
15408
15337
  return;
15409
15338
  }
15410
15339
  if (action_1 === "underline") {
15411
- executeEditorCommand(view_9, toggleUnderline);
15340
+ executeEditorCommand(view_10, toggleUnderline);
15412
15341
  return;
15413
15342
  }
15414
15343
  if (action_1 === "strikethrough") {
15415
- executeEditorCommand(view_9, toggleStrike);
15344
+ executeEditorCommand(view_10, toggleStrike);
15416
15345
  return;
15417
15346
  }
15418
15347
  if (action_1 === "superscript") {
15419
- executeEditorCommand(view_9, toggleSuperscript);
15348
+ executeEditorCommand(view_10, toggleSuperscript);
15420
15349
  return;
15421
15350
  }
15422
15351
  if (action_1 === "subscript") {
15423
- executeEditorCommand(view_9, toggleSubscript);
15352
+ executeEditorCommand(view_10, toggleSubscript);
15424
15353
  return;
15425
15354
  }
15426
15355
  if (action_1 === "bulletList") {
15427
- executeEditorCommand(view_9, toggleBulletList);
15356
+ executeEditorCommand(view_10, toggleBulletList);
15428
15357
  return;
15429
15358
  }
15430
15359
  if (action_1 === "numberedList") {
15431
- executeEditorCommand(view_9, toggleNumberedList);
15360
+ executeEditorCommand(view_10, toggleNumberedList);
15432
15361
  return;
15433
15362
  }
15434
15363
  if (action_1 === "indent") {
15435
- executeFirstEditorCommand(view_9, [increaseListLevel, increaseIndent()]);
15364
+ executeFirstEditorCommand(view_10, [increaseListLevel, increaseIndent()]);
15436
15365
  return;
15437
15366
  }
15438
15367
  if (action_1 === "outdent") {
15439
- executeFirstEditorCommand(view_9, [decreaseListLevel, decreaseIndent()]);
15368
+ executeFirstEditorCommand(view_10, [decreaseListLevel, decreaseIndent()]);
15440
15369
  return;
15441
15370
  }
15442
15371
  if (action_1 === "clearFormatting") {
15443
- executeEditorCommand(view_9, clearFormatting);
15372
+ executeEditorCommand(view_10, clearFormatting);
15444
15373
  return;
15445
15374
  }
15446
15375
  if (action_1 === "setRtl") {
15447
- executeEditorCommand(view_9, setRtl);
15376
+ executeEditorCommand(view_10, setRtl);
15448
15377
  return;
15449
15378
  }
15450
15379
  if (action_1 === "setLtr") {
15451
- executeEditorCommand(view_9, setLtr);
15380
+ executeEditorCommand(view_10, setLtr);
15452
15381
  return;
15453
15382
  }
15454
15383
  if (action_1 === "insertPageBreak") {
15455
- executeEditorCommand(view_9, insertPageBreak);
15384
+ executeEditorCommand(view_10, insertPageBreak);
15456
15385
  return;
15457
15386
  }
15458
15387
  if (typeof action_1 === "object") switch (action_1.type) {
15459
15388
  case "alignment":
15460
- executeEditorCommand(view_9, setAlignment(action_1.value));
15389
+ executeEditorCommand(view_10, setAlignment(action_1.value));
15461
15390
  break;
15462
15391
  case "toggleDirection":
15463
- executeEditorCommand(view_9, toggleBidi);
15392
+ executeEditorCommand(view_10, toggleBidi);
15464
15393
  break;
15465
15394
  case "textColor": {
15466
15395
  const colorVal_0 = action_1.value;
15467
- if (typeof colorVal_0 === "string") executeEditorCommand(view_9, setTextColor({ rgb: colorVal_0.replace("#", "") }));
15468
- else if (colorVal_0.auto) executeEditorCommand(view_9, clearTextColor);
15396
+ if (typeof colorVal_0 === "string") executeEditorCommand(view_10, setTextColor({ rgb: colorVal_0.replace("#", "") }));
15397
+ else if (colorVal_0.auto) executeEditorCommand(view_10, clearTextColor);
15469
15398
  else {
15470
15399
  const themeColor = typeof colorVal_0.themeColor === "string" ? colorVal_0.themeColor : void 0;
15471
- executeEditorCommand(view_9, setTextColor({
15400
+ executeEditorCommand(view_10, setTextColor({
15472
15401
  ...colorVal_0.rgb === void 0 ? {} : { rgb: colorVal_0.rgb },
15473
15402
  ...themeColor ? { themeColor } : {},
15474
15403
  ...colorVal_0.themeTint === void 0 ? {} : { themeTint: colorVal_0.themeTint },
@@ -15479,17 +15408,17 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
15479
15408
  }
15480
15409
  case "highlightColor": {
15481
15410
  const highlightName = action_1.value ? mapHexToHighlightName(action_1.value) : "";
15482
- executeEditorCommand(view_9, setHighlight(highlightName || action_1.value));
15411
+ executeEditorCommand(view_10, setHighlight(highlightName || action_1.value));
15483
15412
  break;
15484
15413
  }
15485
15414
  case "fontSize":
15486
- executeEditorCommand(view_9, setFontSize(pointsToHalfPoints(action_1.value)));
15415
+ executeEditorCommand(view_10, setFontSize(pointsToHalfPoints(action_1.value)));
15487
15416
  break;
15488
15417
  case "fontFamily":
15489
- executeEditorCommand(view_9, setFontFamily(action_1.value));
15418
+ executeEditorCommand(view_10, setFontFamily(action_1.value));
15490
15419
  break;
15491
15420
  case "lineSpacing":
15492
- executeEditorCommand(view_9, setLineSpacing(action_1.value));
15421
+ executeEditorCommand(view_10, setLineSpacing(action_1.value));
15493
15422
  break;
15494
15423
  case "applyStyle": {
15495
15424
  const currentDoc_0 = historyStateRef.current;
@@ -15502,21 +15431,21 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
15502
15431
  const styleName = styleResolver_0.getStyle(action_1.value)?.name;
15503
15432
  if (styleName) styleAttrs.styleName = styleName;
15504
15433
  styleAttrs.numbering = currentDoc_0?.package.numbering ? getCachedNumberingMap(currentDoc_0.package.numbering) : null;
15505
- executeEditorCommand(view_9, applyStyle(action_1.value, styleAttrs));
15506
- } else executeEditorCommand(view_9, applyStyle(action_1.value));
15434
+ executeEditorCommand(view_10, applyStyle(action_1.value, styleAttrs));
15435
+ } else executeEditorCommand(view_10, applyStyle(action_1.value));
15507
15436
  break;
15508
15437
  }
15509
15438
  }
15510
15439
  }, [getActiveEditorView, getCachedStyleResolver]);
15511
15440
  const captureFormatPainter = useCallback(() => {
15512
- const view_10 = getActiveEditorView();
15513
- capturedFormatMarksRef.current = view_10 ? captureFormatMarks(view_10.state) : null;
15441
+ const view_11 = getActiveEditorView();
15442
+ capturedFormatMarksRef.current = view_11 ? captureFormatMarks(view_11.state) : null;
15514
15443
  }, [getActiveEditorView]);
15515
15444
  const paintFormatToSelection = useCallback(() => {
15516
- const view_11 = getActiveEditorView();
15517
- if (!view_11) return false;
15518
- const applied = applyFormatMarks(capturedFormatMarksRef.current)(view_11.state, view_11.dispatch);
15519
- if (applied) requestAnimationFrame(() => view_11.focus());
15445
+ const view_12 = getActiveEditorView();
15446
+ if (!view_12) return false;
15447
+ const applied = applyFormatMarks(capturedFormatMarksRef.current)(view_12.state, view_12.dispatch);
15448
+ if (applied) requestAnimationFrame(() => view_12.focus());
15520
15449
  return applied;
15521
15450
  }, [getActiveEditorView]);
15522
15451
  const handleFormatPainter = useCallback((sticky) => {
@@ -15658,14 +15587,29 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
15658
15587
  label: t("tableBordersNone"),
15659
15588
  dividerAfter: true
15660
15589
  });
15661
- if (contextMenu.cursorInTrackedChange) items.push({
15662
- action: "acceptChange",
15663
- label: t("acceptChange")
15664
- }, {
15665
- action: "rejectChange",
15666
- label: t("rejectChange"),
15667
- dividerAfter: true
15668
- });
15590
+ if (contextMenu.cursorInTrackedChange) {
15591
+ const held = state.activeTrackedChange?.heldByLock ?? {
15592
+ accept: false,
15593
+ reject: false
15594
+ };
15595
+ const reason = t("trackedChanges.heldByLock");
15596
+ items.push({
15597
+ action: "acceptChange",
15598
+ label: t("acceptChange"),
15599
+ ...held.accept && {
15600
+ disabled: true,
15601
+ disabledReason: reason
15602
+ }
15603
+ }, {
15604
+ action: "rejectChange",
15605
+ label: t("rejectChange"),
15606
+ dividerAfter: true,
15607
+ ...held.reject && {
15608
+ disabled: true,
15609
+ disabledReason: reason
15610
+ }
15611
+ });
15612
+ }
15669
15613
  if (contextMenu.listNumbering.type === "listItem") items.push({
15670
15614
  action: "restartNumbering",
15671
15615
  label: t("contextMenu.restartNumbering")
@@ -15691,19 +15635,20 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
15691
15635
  contextMenu.listNumbering,
15692
15636
  customContextMenuItems,
15693
15637
  readOnly,
15638
+ state.activeTrackedChange?.heldByLock,
15694
15639
  t
15695
15640
  ]);
15696
15641
  const { from: contextSelectionFrom, to: contextSelectionTo } = contextMenu.selectionRange;
15697
15642
  const handleContextMenuAction = useCallback(async (action_2) => {
15698
- const view_12 = getActiveEditorView();
15699
- if (!view_12) return;
15643
+ const view_13 = getActiveEditorView();
15644
+ if (!view_13) return;
15700
15645
  focusActiveEditor();
15701
15646
  if (readOnly && action_2 !== "copy" && action_2 !== "selectAll") return;
15702
15647
  if (action_2.startsWith("custom:")) {
15703
15648
  const { from: from_2, to: to_2 } = contextSelectionFrom !== contextSelectionTo ? {
15704
15649
  from: contextSelectionFrom,
15705
15650
  to: contextSelectionTo
15706
- } : view_12.state.selection;
15651
+ } : view_13.state.selection;
15707
15652
  onCustomContextAction?.(action_2.slice(7), {
15708
15653
  from: from_2,
15709
15654
  to: to_2
@@ -15713,16 +15658,16 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
15713
15658
  switch (action_2) {
15714
15659
  case "cut": {
15715
15660
  if (readOnly) return;
15716
- const { from: from_7, to: to_7 } = view_12.state.selection;
15717
- const text_2 = view_12.state.doc.textBetween(from_7, to_7, "\n");
15661
+ const { from: from_7, to: to_7 } = view_13.state.selection;
15662
+ const text_2 = view_13.state.doc.textBetween(from_7, to_7, "\n");
15718
15663
  navigator.clipboard.writeText(text_2).catch(() => void 0);
15719
- if (!deleteSelectionAsSuggestion(view_12.state, view_12.dispatch)) view_12.dispatch(view_12.state.tr.deleteSelection());
15664
+ if (!deleteSelectionAsSuggestion(view_13.state, view_13.dispatch)) view_13.dispatch(view_13.state.tr.deleteSelection());
15720
15665
  onCut?.();
15721
15666
  break;
15722
15667
  }
15723
15668
  case "copy": {
15724
- const { from: cf, to: ct } = view_12.state.selection;
15725
- const copied = view_12.state.doc.textBetween(cf, ct, "\n");
15669
+ const { from: cf, to: ct } = view_13.state.selection;
15670
+ const copied = view_13.state.doc.textBetween(cf, ct, "\n");
15726
15671
  navigator.clipboard.writeText(copied).catch(() => void 0);
15727
15672
  onCopy?.();
15728
15673
  break;
@@ -15745,12 +15690,12 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
15745
15690
  bubbles: true,
15746
15691
  cancelable: true
15747
15692
  });
15748
- view_12.dom.dispatchEvent(pasteEvent);
15693
+ view_13.dom.dispatchEvent(pasteEvent);
15749
15694
  } catch {
15750
15695
  try {
15751
15696
  const text_0 = await navigator.clipboard.readText();
15752
15697
  if (text_0) {
15753
- view_12.dispatch(view_12.state.tr.insertText(text_0));
15698
+ view_13.dispatch(view_13.state.tr.insertText(text_0));
15754
15699
  onPaste?.();
15755
15700
  }
15756
15701
  } catch {}
@@ -15759,8 +15704,8 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
15759
15704
  case "pasteAsPlainText":
15760
15705
  try {
15761
15706
  const text = await navigator.clipboard.readText();
15762
- if (text && !view_12.isDestroyed) {
15763
- pastePlainTextSlice(view_12, buildPlainTextSlice(text, view_12.state.schema));
15707
+ if (text && !view_13.isDestroyed) {
15708
+ pastePlainTextSlice(view_13, buildPlainTextSlice(text, view_13.state.schema));
15764
15709
  onPaste?.();
15765
15710
  }
15766
15711
  } catch {
@@ -15768,42 +15713,42 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
15768
15713
  }
15769
15714
  break;
15770
15715
  case "delete": {
15771
- const { from: from_6, to: to_6 } = view_12.state.selection;
15772
- if (from_6 !== to_6) view_12.dispatch(view_12.state.tr.deleteRange(from_6, to_6));
15716
+ const { from: from_6, to: to_6 } = view_13.state.selection;
15717
+ if (from_6 !== to_6) view_13.dispatch(view_13.state.tr.deleteRange(from_6, to_6));
15773
15718
  break;
15774
15719
  }
15775
15720
  case "selectAll":
15776
- view_12.dispatch(view_12.state.tr.setSelection(TextSelection.create(view_12.state.doc, 0, view_12.state.doc.content.size)));
15721
+ view_13.dispatch(view_13.state.tr.setSelection(TextSelection.create(view_13.state.doc, 0, view_13.state.doc.content.size)));
15777
15722
  break;
15778
15723
  case "addRowAbove":
15779
- addRowAbove(view_12.state, view_12.dispatch);
15724
+ addRowAbove(view_13.state, view_13.dispatch);
15780
15725
  break;
15781
15726
  case "addRowBelow":
15782
- addRowBelow(view_12.state, view_12.dispatch);
15727
+ addRowBelow(view_13.state, view_13.dispatch);
15783
15728
  break;
15784
15729
  case "deleteRow":
15785
- deleteRow(view_12.state, view_12.dispatch);
15730
+ deleteRow(view_13.state, view_13.dispatch);
15786
15731
  break;
15787
15732
  case "addColumnLeft":
15788
- addColumnLeft(view_12.state, view_12.dispatch);
15733
+ addColumnLeft(view_13.state, view_13.dispatch);
15789
15734
  break;
15790
15735
  case "addColumnRight":
15791
- addColumnRight(view_12.state, view_12.dispatch);
15736
+ addColumnRight(view_13.state, view_13.dispatch);
15792
15737
  break;
15793
15738
  case "deleteColumn":
15794
- deleteColumn(view_12.state, view_12.dispatch);
15739
+ deleteColumn(view_13.state, view_13.dispatch);
15795
15740
  break;
15796
15741
  case "tableBordersAll":
15797
- setTableBorderPreset("all")(view_12.state, view_12.dispatch);
15742
+ setTableBorderPreset("all")(view_13.state, view_13.dispatch);
15798
15743
  break;
15799
15744
  case "tableBordersNone":
15800
- setTableBorderPreset("none")(view_12.state, view_12.dispatch);
15745
+ setTableBorderPreset("none")(view_13.state, view_13.dispatch);
15801
15746
  break;
15802
15747
  case "addComment": {
15803
15748
  const { from: from_5, to: to_5 } = contextSelectionFrom !== contextSelectionTo ? {
15804
15749
  from: contextSelectionFrom,
15805
15750
  to: contextSelectionTo
15806
- } : view_12.state.selection;
15751
+ } : view_13.state.selection;
15807
15752
  if (from_5 === to_5) break;
15808
15753
  const commentY = findSelectionYPosition(scrollContainerRef.current, editorContentRef.current, from_5) ?? getFallbackCommentYPosition(scrollContainerRef.current);
15809
15754
  setCommentSelectionRange({
@@ -15811,7 +15756,7 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
15811
15756
  to: to_5
15812
15757
  });
15813
15758
  if (commentDraftMode === "prosemirror") {
15814
- if (!applyCommentMarkRange(view_12, {
15759
+ if (!applyCommentMarkRange(view_13, {
15815
15760
  from: from_5,
15816
15761
  to: to_5
15817
15762
  }, -1, { selectEnd: true })) break;
@@ -15823,30 +15768,30 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
15823
15768
  break;
15824
15769
  }
15825
15770
  case "acceptChange": {
15826
- const { from: from_4, to: to_4 } = view_12.state.selection;
15827
- const range_0 = findChangeAtPosition(view_12.state, from_4, to_4);
15771
+ const { from: from_4, to: to_4 } = view_13.state.selection;
15772
+ const range_0 = findChangeAtPosition(view_13.state, from_4, to_4);
15828
15773
  if (resolveCanonicalReviewRange({
15829
15774
  editor: pagedEditorRef.current?.getEditor(),
15830
15775
  ...range_0,
15831
15776
  resolution: "accept"
15832
- }) === null) acceptChange(range_0.from, range_0.to)(view_12.state, view_12.dispatch);
15777
+ }) === null) acceptChange(range_0.from, range_0.to)(view_13.state, view_13.dispatch);
15833
15778
  break;
15834
15779
  }
15835
15780
  case "rejectChange": {
15836
- const { from: from_3, to: to_3 } = view_12.state.selection;
15837
- const range = findChangeAtPosition(view_12.state, from_3, to_3);
15781
+ const { from: from_3, to: to_3 } = view_13.state.selection;
15782
+ const range = findChangeAtPosition(view_13.state, from_3, to_3);
15838
15783
  if (resolveCanonicalReviewRange({
15839
15784
  editor: pagedEditorRef.current?.getEditor(),
15840
15785
  ...range,
15841
15786
  resolution: "reject"
15842
- }) === null) rejectChange(range.from, range.to)(view_12.state, view_12.dispatch);
15787
+ }) === null) rejectChange(range.from, range.to)(view_13.state, view_13.dispatch);
15843
15788
  break;
15844
15789
  }
15845
15790
  case "restartNumbering":
15846
- restartNumbering(view_12.state, view_12.dispatch);
15791
+ restartNumbering(view_13.state, view_13.dispatch);
15847
15792
  break;
15848
15793
  case "continueNumbering":
15849
- continueNumbering(view_12.state, view_12.dispatch);
15794
+ continueNumbering(view_13.state, view_13.dispatch);
15850
15795
  break;
15851
15796
  case "setNumberingValue": setNumberingValueDialogOpen(true);
15852
15797
  }
@@ -15903,25 +15848,25 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
15903
15848
  const handleTopMarginChange = useCallback((twips_1) => handlePageSetupApply({ marginTop: twips_1 }), [handlePageSetupApply]);
15904
15849
  const handleBottomMarginChange = useCallback((twips_2) => handlePageSetupApply({ marginBottom: twips_2 }), [handlePageSetupApply]);
15905
15850
  const handleIndentLeftChange = useCallback((twips_3) => {
15906
- const view_13 = getActiveEditorView();
15907
- if (!view_13) return;
15908
- setIndentLeft(twips_3)(view_13.state, view_13.dispatch);
15909
- }, [getActiveEditorView]);
15910
- const handleIndentRightChange = useCallback((twips_4) => {
15911
15851
  const view_14 = getActiveEditorView();
15912
15852
  if (!view_14) return;
15913
- setIndentRight(twips_4)(view_14.state, view_14.dispatch);
15853
+ setIndentLeft(twips_3)(view_14.state, view_14.dispatch);
15914
15854
  }, [getActiveEditorView]);
15915
- const handleFirstLineIndentChange = useCallback((twips_5) => {
15855
+ const handleIndentRightChange = useCallback((twips_4) => {
15916
15856
  const view_15 = getActiveEditorView();
15917
15857
  if (!view_15) return;
15918
- if (twips_5 < 0) setIndentFirstLine(-twips_5, true)(view_15.state, view_15.dispatch);
15919
- else setIndentFirstLine(twips_5, false)(view_15.state, view_15.dispatch);
15858
+ setIndentRight(twips_4)(view_15.state, view_15.dispatch);
15920
15859
  }, [getActiveEditorView]);
15921
- const handleTabStopRemove = useCallback((positionTwips) => {
15860
+ const handleFirstLineIndentChange = useCallback((twips_5) => {
15922
15861
  const view_16 = getActiveEditorView();
15923
15862
  if (!view_16) return;
15924
- removeTabStop(positionTwips)(view_16.state, view_16.dispatch);
15863
+ if (twips_5 < 0) setIndentFirstLine(-twips_5, true)(view_16.state, view_16.dispatch);
15864
+ else setIndentFirstLine(twips_5, false)(view_16.state, view_16.dispatch);
15865
+ }, [getActiveEditorView]);
15866
+ const handleTabStopRemove = useCallback((positionTwips) => {
15867
+ const view_17 = getActiveEditorView();
15868
+ if (!view_17) return;
15869
+ removeTabStop(positionTwips)(view_17.state, view_17.dispatch);
15925
15870
  }, [getActiveEditorView]);
15926
15871
  const serializeCurrentDocx = useCallback(async (options) => {
15927
15872
  let tripwireResult = null;
@@ -15930,8 +15875,8 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
15930
15875
  const editor_2 = pagedEditorRef.current?.getEditor();
15931
15876
  const snapshot_0 = editor_2?.captureCanonicalSave();
15932
15877
  if (snapshot_0 && editor_2) {
15933
- const view_17 = editor_2.getView();
15934
- const editorState = view_17?.state;
15878
+ const view_18 = editor_2.getView();
15879
+ const editorState = view_18?.state;
15935
15880
  const result_2 = await serializeCanonicalSave({
15936
15881
  snapshot: snapshot_0,
15937
15882
  options,
@@ -15943,15 +15888,15 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
15943
15888
  message: `Canonical save used a fidelity fallback: ${diagnostic.type} (${diagnostic.part}).`
15944
15889
  }));
15945
15890
  tripwireResult = result_2.tripwireResult;
15946
- if (view_17 && pagedEditorRef.current?.getEditor() === editor_2 && editor_2.getView() === view_17 && view_17.state.doc === editorState?.doc && editor_2.isCanonicalSaveCurrent(snapshot_0.version)) view_17.dispatch(clearTrackedChanges(view_17.state));
15891
+ if (view_18 && pagedEditorRef.current?.getEditor() === editor_2 && editor_2.getView() === view_18 && view_18.state.doc === editorState?.doc && editor_2.isCanonicalSaveCurrent(snapshot_0.version)) view_18.dispatch(clearTrackedChanges(view_18.state));
15947
15892
  savedBuffer = result_2.buffer;
15948
15893
  } else {
15949
15894
  if (usesCanonicalSession(experimentalSession, CANONICAL_GAP.save)) return null;
15950
- const view_18 = pagedEditorRef.current?.getView();
15951
- const editorState_0 = view_18?.state;
15895
+ const view_19 = pagedEditorRef.current?.getView();
15896
+ const editorState_0 = view_19?.state;
15952
15897
  const baselineBuffer = originalBufferRef.current;
15953
- const current = buildCurrentDocument();
15954
- const doc_1 = current ? withoutUnreferencedNotes(current) : null;
15898
+ const current_0 = buildCurrentDocument();
15899
+ const doc_1 = current_0 ? withoutUnreferencedNotes(current_0) : null;
15955
15900
  if (!doc_1) return null;
15956
15901
  const { resolveSelectiveSaveFlags } = await import("@stll/folio-core/docx/selectiveSaveFlags");
15957
15902
  const flags = resolveSelectiveSaveFlags(featureFlags);
@@ -15989,9 +15934,9 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
15989
15934
  const { compareSelectiveVsFull } = await import("@stll/folio-core/docx/selectiveSaveTripwire");
15990
15935
  tripwireResult = await compareSelectiveVsFull(selectiveBuffer, fullBuffer);
15991
15936
  } catch {}
15992
- if (view_18 && pagedEditorRef.current?.getView() === view_18 && view_18.state.doc === editorState_0?.doc) {
15937
+ if (view_19 && pagedEditorRef.current?.getView() === view_19 && view_19.state.doc === editorState_0?.doc) {
15993
15938
  originalBufferRef.current = buffer;
15994
- view_18.dispatch(clearTrackedChanges(view_18.state));
15939
+ view_19.dispatch(clearTrackedChanges(view_19.state));
15995
15940
  }
15996
15941
  savedBuffer = buffer;
15997
15942
  }
@@ -16032,9 +15977,9 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
16032
15977
  serializeCurrentDocx
16033
15978
  ]);
16034
15979
  const handleEditorError = useCallback((error_1) => {
16035
- if (CanonicalSessionRefusalError.is(error_1)) toast(error_1.message);
15980
+ if (CanonicalSessionRefusalError.is(error_1)) toast(canonicalRefusalNotice(error_1.ground, error_1.message, t));
16036
15981
  onError?.(error_1);
16037
- }, [onError]);
15982
+ }, [onError, t]);
16038
15983
  useImperativeHandle(ref, () => ({
16039
15984
  getReadOnlyReason: () => readOnlyReason,
16040
15985
  getDocument: () => buildCurrentDocument(),
@@ -16047,9 +15992,9 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
16047
15992
  getFindResult,
16048
15993
  clearFind: resetFindResult,
16049
15994
  hasPendingChanges: () => {
16050
- const view_19 = pagedEditorRef.current?.getView();
16051
- if (!view_19) return false;
16052
- return getCommentsDirty() || getChangedParagraphIds(view_19.state).size > 0 || hasStructuralChanges(view_19.state) || hasUntrackedChanges(view_19.state);
15995
+ const view_20 = pagedEditorRef.current?.getView();
15996
+ if (!view_20) return false;
15997
+ return getCommentsDirty() || getChangedParagraphIds(view_20.state).size > 0 || hasStructuralChanges(view_20.state) || hasUntrackedChanges(view_20.state);
16053
15998
  },
16054
15999
  getEditorRef: () => pagedEditorRef.current,
16055
16000
  getEditor: () => pagedEditorRef.current?.getEditor() ?? null,
@@ -16094,13 +16039,13 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
16094
16039
  pagedEditorRef.current?.ensureView(options_3);
16095
16040
  },
16096
16041
  createAIEditSnapshot: () => {
16097
- const view_20 = pagedEditorRef.current?.getView();
16098
- return view_20 ? createFolioAIEditSnapshot(view_20.state.doc) : null;
16042
+ const view_21 = pagedEditorRef.current?.getView();
16043
+ return view_21 ? createFolioAIEditSnapshot(view_21.state.doc) : null;
16099
16044
  },
16100
16045
  applyDocumentOperations: ({ undefinedReferences, snapshot: snapshot_1, batch, author: operationAuthor = author }) => {
16101
16046
  assertSupportedFolioDocumentOperationVersion(batch.version);
16102
- const view_21 = pagedEditorRef.current?.getView();
16103
- if (!view_21) {
16047
+ const view_22 = pagedEditorRef.current?.getView();
16048
+ if (!view_22) {
16104
16049
  let status = "committed";
16105
16050
  if (batch.dryRun === true) status = "previewed";
16106
16051
  else if (batch.atomic === true) status = "rejected";
@@ -16118,25 +16063,36 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
16118
16063
  undoHandle: null
16119
16064
  };
16120
16065
  }
16066
+ const activeBeforeCanonical = new Set(getSuggestions(view_22.state).map((s_0) => s_0.suggestionId));
16121
16067
  const canonical_1 = getCanonicalApi()?.applyCanonicalDocumentOperations({
16122
16068
  undefinedReferences,
16123
16069
  snapshot: snapshot_1,
16124
16070
  batch,
16125
16071
  author: operationAuthor
16126
16072
  });
16127
- if (canonical_1) return canonical_1;
16073
+ if (canonical_1) {
16074
+ if (batch.mode === "suggested" && canonical_1.status === "committed") pendingSuggestionRegistryRef.current.recordApplied({
16075
+ snapshot: snapshot_1,
16076
+ story: { type: "main" },
16077
+ operations: batch.operations,
16078
+ applied: canonical_1.applied,
16079
+ author: operationAuthor,
16080
+ activeSuggestionIds: activeBeforeCanonical
16081
+ });
16082
+ return canonical_1;
16083
+ }
16128
16084
  const existingUndoEntry = documentOperationUndoEntriesRef.current.at(-1);
16129
- if (existingUndoEntry && (!view_21.state.doc.eq(existingUndoEntry.afterState.doc) || canonicalJson(commentsRef.current) !== existingUndoEntry.commentsAfterJson)) documentOperationUndoEntriesRef.current.length = 0;
16085
+ if (existingUndoEntry && (!view_22.state.doc.eq(existingUndoEntry.afterState.doc) || canonicalJson(commentsRef.current) !== existingUndoEntry.commentsAfterJson)) documentOperationUndoEntriesRef.current.length = 0;
16130
16086
  const commentsBefore = commentsRef.current;
16131
16087
  const createdComments = [];
16132
16088
  const operationView = {
16133
- state: view_21.state,
16089
+ state: view_22.state,
16134
16090
  dispatch: (transaction) => {
16135
- view_21.dispatch(closeHistory(transaction));
16136
- operationView.state = view_21.state;
16091
+ view_22.dispatch(closeHistory(transaction));
16092
+ operationView.state = view_22.state;
16137
16093
  }
16138
16094
  };
16139
- const activeSuggestionIds = new Set(getSuggestions(view_21.state).map((s_0) => s_0.suggestionId));
16095
+ const activeSuggestionIds = new Set(getSuggestions(view_22.state).map((s_1) => s_1.suggestionId));
16140
16096
  const result_3 = applyFolioDocumentOperations({
16141
16097
  undefinedReferences,
16142
16098
  view: operationView,
@@ -16166,7 +16122,7 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
16166
16122
  if (batchComments.length > 0) replaceComments(commentsAfter);
16167
16123
  if (result_3.undoHandle !== null) documentOperationUndoEntriesRef.current.push({
16168
16124
  undoHandle: result_3.undoHandle,
16169
- afterState: view_21.state,
16125
+ afterState: view_22.state,
16170
16126
  commentsBefore,
16171
16127
  commentsAfterJson: canonicalJson(commentsAfter)
16172
16128
  });
@@ -16188,18 +16144,18 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
16188
16144
  reason: "notLatest"
16189
16145
  };
16190
16146
  const entry_3 = entries_0.at(-1);
16191
- const view_22 = pagedEditorRef.current?.getView();
16192
- if (!entry_3 || !view_22) return {
16147
+ const view_23 = pagedEditorRef.current?.getView();
16148
+ if (!entry_3 || !view_23) return {
16193
16149
  status: "rejected",
16194
16150
  undoHandle,
16195
16151
  reason: "unknownHandle"
16196
16152
  };
16197
- if (!view_22.state.doc.eq(entry_3.afterState.doc) || canonicalJson(commentsRef.current) !== entry_3.commentsAfterJson) return {
16153
+ if (!view_23.state.doc.eq(entry_3.afterState.doc) || canonicalJson(commentsRef.current) !== entry_3.commentsAfterJson) return {
16198
16154
  status: "rejected",
16199
16155
  undoHandle,
16200
16156
  reason: "documentChanged"
16201
16157
  };
16202
- if (!undo(view_22.state, view_22.dispatch)) return {
16158
+ if (!undo(view_23.state, view_23.dispatch)) return {
16203
16159
  status: "rejected",
16204
16160
  undoHandle,
16205
16161
  reason: "documentChanged"
@@ -16213,14 +16169,15 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
16213
16169
  };
16214
16170
  },
16215
16171
  applyAIEditOperations: ({ undefinedReferences: undefinedReferences_0, snapshot: snapshot_2, operations, mode = "tracked-changes", author: operationAuthor_0 = author }) => {
16216
- const view_23 = pagedEditorRef.current?.getView();
16217
- if (!view_23) return {
16172
+ const view_24 = pagedEditorRef.current?.getView();
16173
+ if (!view_24) return {
16218
16174
  applied: [],
16219
16175
  skipped: operations.map((operation_0) => ({
16220
16176
  id: operation_0.id,
16221
16177
  reason: "unsupportedBlock"
16222
16178
  }))
16223
16179
  };
16180
+ const activeSuggestionIds_0 = new Set(getSuggestions(view_24.state).map((s_2) => s_2.suggestionId));
16224
16181
  const canonical_3 = getCanonicalApi()?.applyCanonicalDocumentOperations({
16225
16182
  undefinedReferences: undefinedReferences_0,
16226
16183
  snapshot: snapshot_2,
@@ -16231,12 +16188,21 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
16231
16188
  },
16232
16189
  author: operationAuthor_0
16233
16190
  });
16234
- if (canonical_3) return canonical_3;
16191
+ if (canonical_3) {
16192
+ if (mode === "suggested" && canonical_3.status === "committed") pendingSuggestionRegistryRef.current.recordApplied({
16193
+ snapshot: snapshot_2,
16194
+ story: { type: "main" },
16195
+ operations,
16196
+ applied: canonical_3.applied,
16197
+ author: operationAuthor_0,
16198
+ activeSuggestionIds: activeSuggestionIds_0
16199
+ });
16200
+ return canonical_3;
16201
+ }
16235
16202
  const createdComments_0 = [];
16236
- const activeSuggestionIds_0 = new Set(getSuggestions(view_23.state).map((s_1) => s_1.suggestionId));
16237
16203
  const { applied: applied_0, skipped: skipped_0 } = applyFolioDocumentOperations({
16238
16204
  undefinedReferences: undefinedReferences_0,
16239
- view: view_23,
16205
+ view: view_24,
16240
16206
  snapshot: snapshot_2,
16241
16207
  batch: {
16242
16208
  version: FOLIO_DOCUMENT_OPERATION_CONTRACT_VERSION,
@@ -16266,18 +16232,18 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
16266
16232
  };
16267
16233
  },
16268
16234
  acceptAIEditOperation: (revisionId) => {
16269
- const view_24 = pagedEditorRef.current?.getView();
16270
- if (!view_24) return false;
16235
+ const view_25 = pagedEditorRef.current?.getView();
16236
+ if (!view_25) return false;
16271
16237
  const editor_5 = pagedEditorRef.current?.getEditor();
16272
16238
  if (editor_5?.getCanonicalDocument()) return editor_5.resolveCanonicalRevisions(typeof revisionId === "number" ? [revisionId] : revisionId, "accept");
16273
- return acceptAIEditRevision(revisionId)(view_24.state, view_24.dispatch);
16239
+ return acceptAIEditRevision(revisionId)(view_25.state, view_25.dispatch);
16274
16240
  },
16275
16241
  rejectAIEditOperation: (revisionId_0) => {
16276
- const view_25 = pagedEditorRef.current?.getView();
16277
- if (!view_25) return false;
16242
+ const view_26 = pagedEditorRef.current?.getView();
16243
+ if (!view_26) return false;
16278
16244
  const editor_6 = pagedEditorRef.current?.getEditor();
16279
16245
  if (editor_6?.getCanonicalDocument()) return editor_6.resolveCanonicalRevisions(typeof revisionId_0 === "number" ? [revisionId_0] : revisionId_0, "reject");
16280
- return rejectAIEditRevision(revisionId_0)(view_25.state, view_25.dispatch);
16246
+ return rejectAIEditRevision(revisionId_0)(view_26.state, view_26.dispatch);
16281
16247
  },
16282
16248
  undo: () => {
16283
16249
  if (!usesCanonicalSession(experimentalSession, CANONICAL_GAP.authorityRouting) && getActiveEditorStory().type === "headerFooter" && hfEditorRef.current) return hfEditorRef.current.undo();
@@ -16292,44 +16258,44 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
16292
16258
  return redone;
16293
16259
  },
16294
16260
  scrollToAIEditOperation: (revisionId_1) => {
16295
- const view_26 = pagedEditorRef.current?.getView();
16296
- if (!view_26) return false;
16297
- const range_1 = findAIEditRevisionRange(view_26.state, revisionId_1);
16261
+ const view_27 = pagedEditorRef.current?.getView();
16262
+ if (!view_27) return false;
16263
+ const range_1 = findAIEditRevisionRange(view_27.state, revisionId_1);
16298
16264
  if (!range_1) return false;
16299
- const { from: from_8, to: to_8 } = clampRangeToDocSize(view_26.state.doc.content.size, range_1);
16300
- const $from = view_26.state.doc.resolve(from_8);
16301
- const $to = view_26.state.doc.resolve(to_8);
16302
- view_26.dispatch(view_26.state.tr.setSelection(TextSelection.between($from, $to)));
16265
+ const { from: from_8, to: to_8 } = clampRangeToDocSize(view_27.state.doc.content.size, range_1);
16266
+ const $from = view_27.state.doc.resolve(from_8);
16267
+ const $to = view_27.state.doc.resolve(to_8);
16268
+ view_27.dispatch(view_27.state.tr.setSelection(TextSelection.between($from, $to)));
16303
16269
  requestAnimationFrame(() => {
16304
16270
  pagedEditorRef.current?.scrollToPosition(from_8);
16305
16271
  });
16306
16272
  return true;
16307
16273
  },
16308
16274
  scrollToBlock: (blockId, snapshot_3) => {
16309
- const view_27 = pagedEditorRef.current?.getView();
16310
- if (!view_27) return false;
16275
+ const view_28 = pagedEditorRef.current?.getView();
16276
+ if (!view_28) return false;
16311
16277
  const range_2 = resolveFolioAIBlockRange({
16312
16278
  blockId,
16313
- doc: view_27.state.doc,
16279
+ doc: view_28.state.doc,
16314
16280
  snapshot: snapshot_3
16315
16281
  });
16316
16282
  if (range_2 === null) return false;
16317
16283
  const { from: from_9, to: to_9 } = range_2;
16318
- const $from_0 = view_27.state.doc.resolve(from_9);
16319
- const $to_0 = view_27.state.doc.resolve(to_9);
16320
- view_27.dispatch(view_27.state.tr.setSelection(TextSelection.between($from_0, $to_0)));
16284
+ const $from_0 = view_28.state.doc.resolve(from_9);
16285
+ const $to_0 = view_28.state.doc.resolve(to_9);
16286
+ view_28.dispatch(view_28.state.tr.setSelection(TextSelection.between($from_0, $to_0)));
16321
16287
  requestAnimationFrame(() => {
16322
16288
  pagedEditorRef.current?.scrollToPosition(from_9);
16323
16289
  });
16324
16290
  return true;
16325
16291
  },
16326
16292
  highlightPassage: ({ blockId: blockId_0, text: text_5, snapshot: snapshot_4 }) => {
16327
- const view_28 = pagedEditorRef.current?.getView();
16328
- if (!view_28) return "none";
16293
+ const view_29 = pagedEditorRef.current?.getView();
16294
+ if (!view_29) return "none";
16329
16295
  const passageRange = resolvePassageRange({
16330
16296
  blockId: blockId_0,
16331
16297
  text: text_5,
16332
- doc: view_28.state.doc,
16298
+ doc: view_29.state.doc,
16333
16299
  snapshot: snapshot_4
16334
16300
  });
16335
16301
  if (passageRange !== null) {
@@ -16342,16 +16308,16 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
16342
16308
  pagedEditorRef.current?.setPassageHighlight(null);
16343
16309
  const blockRange = resolveFolioAIBlockRange({
16344
16310
  blockId: blockId_0,
16345
- doc: view_28.state.doc,
16311
+ doc: view_29.state.doc,
16346
16312
  snapshot: snapshot_4
16347
16313
  });
16348
16314
  if (blockRange === null) return "none";
16349
16315
  const paraId_0 = getFolioParaIdFromBlockId(blockId_0);
16350
16316
  if (paraId_0 !== null && pagedEditorRef.current?.scrollToParaId(paraId_0, { highlight: {} })) return "block";
16351
16317
  const { from: from_10, to: to_10 } = blockRange;
16352
- const $from_1 = view_28.state.doc.resolve(from_10);
16353
- const $to_1 = view_28.state.doc.resolve(to_10);
16354
- view_28.dispatch(view_28.state.tr.setSelection(TextSelection.between($from_1, $to_1)));
16318
+ const $from_1 = view_29.state.doc.resolve(from_10);
16319
+ const $to_1 = view_29.state.doc.resolve(to_10);
16320
+ view_29.dispatch(view_29.state.tr.setSelection(TextSelection.between($from_1, $to_1)));
16355
16321
  requestAnimationFrame(() => {
16356
16322
  pagedEditorRef.current?.scrollToPosition(from_10);
16357
16323
  });
@@ -16361,52 +16327,52 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
16361
16327
  pagedEditorRef.current?.setPassageHighlight(null);
16362
16328
  },
16363
16329
  showInDocument: (target_1, snapshot_5) => {
16364
- const view_29 = pagedEditorRef.current?.getView();
16365
- if (!view_29) return false;
16330
+ const view_30 = pagedEditorRef.current?.getView();
16331
+ if (!view_30) return false;
16366
16332
  const range_3 = target_1.type === "textRange" ? resolveFolioAITextRange({
16367
16333
  range: target_1,
16368
- doc: view_29.state.doc,
16334
+ doc: view_30.state.doc,
16369
16335
  snapshot: snapshot_5
16370
16336
  }) : resolveFolioAIBlockRange({
16371
16337
  blockId: target_1.blockId,
16372
- doc: view_29.state.doc,
16338
+ doc: view_30.state.doc,
16373
16339
  snapshot: snapshot_5
16374
16340
  });
16375
16341
  if (range_3 === null) return false;
16376
16342
  const { from: from_11, to: to_11 } = range_3;
16377
- const $from_2 = view_29.state.doc.resolve(from_11);
16378
- const $to_2 = view_29.state.doc.resolve(to_11);
16379
- view_29.dispatch(view_29.state.tr.setSelection(TextSelection.between($from_2, $to_2)));
16343
+ const $from_2 = view_30.state.doc.resolve(from_11);
16344
+ const $to_2 = view_30.state.doc.resolve(to_11);
16345
+ view_30.dispatch(view_30.state.tr.setSelection(TextSelection.between($from_2, $to_2)));
16380
16346
  requestAnimationFrame(() => {
16381
16347
  pagedEditorRef.current?.scrollToPosition(from_11);
16382
16348
  });
16383
16349
  return true;
16384
16350
  },
16385
16351
  getSuggestions: () => {
16386
- const view_30 = pagedEditorRef.current?.getView();
16387
- return view_30 ? getSuggestions(view_30.state) : [];
16352
+ const view_31 = pagedEditorRef.current?.getView();
16353
+ return view_31 ? getSuggestions(view_31.state) : [];
16388
16354
  },
16389
16355
  exportPendingSuggestions: () => {
16390
- const view_31 = pagedEditorRef.current?.getView();
16391
- const activeIds = new Set(view_31 ? getSuggestions(view_31.state).map((s_2) => s_2.suggestionId) : []);
16356
+ const view_32 = pagedEditorRef.current?.getView();
16357
+ const activeIds = new Set(view_32 ? getSuggestions(view_32.state).map((s_3) => s_3.suggestionId) : []);
16392
16358
  return pendingSuggestionRegistryRef.current.exportPendingSuggestions({
16393
16359
  activeSuggestionIds: activeIds,
16394
- snapshotForStory: (story_0, commentIds) => story_0.type === "main" && view_31 ? createPendingSuggestionSourceSnapshot(view_31.state, commentIds) : null
16360
+ snapshotForStory: (story_0, commentIds) => story_0.type === "main" && view_32 ? createPendingSuggestionSourceSnapshot(view_32.state, commentIds) : null
16395
16361
  });
16396
16362
  },
16397
16363
  loadPendingSuggestions: (records) => pendingSuggestionRegistryRef.current.loadPendingSuggestions({
16398
16364
  records,
16399
16365
  snapshotForStory: (story_1) => {
16400
- const view_32 = pagedEditorRef.current?.getView();
16401
- return story_1.type === "main" && view_32 ? createFolioAIEditSnapshot(view_32.state.doc) : null;
16366
+ const view_33 = pagedEditorRef.current?.getView();
16367
+ return story_1.type === "main" && view_33 ? createFolioAIEditSnapshot(view_33.state.doc) : null;
16402
16368
  },
16403
16369
  sourceSnapshotForStory: (story_2, commentIds_0) => {
16404
- const view_33 = pagedEditorRef.current?.getView();
16405
- return story_2.type === "main" && view_33 ? createPendingSuggestionSourceSnapshot(view_33.state, commentIds_0) : null;
16370
+ const view_34 = pagedEditorRef.current?.getView();
16371
+ return story_2.type === "main" && view_34 ? createPendingSuggestionSourceSnapshot(view_34.state, commentIds_0) : null;
16406
16372
  },
16407
16373
  apply: (record, snapshot_6) => {
16408
- const view_34 = pagedEditorRef.current?.getView();
16409
- if (!view_34) return {
16374
+ const view_35 = pagedEditorRef.current?.getView();
16375
+ if (!view_35) return {
16410
16376
  applied: [],
16411
16377
  skipped: []
16412
16378
  };
@@ -16424,7 +16390,7 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
16424
16390
  const createdComments_1 = [];
16425
16391
  const result_4 = applyFolioDocumentOperations({
16426
16392
  undefinedReferences: "refuse",
16427
- view: view_34,
16393
+ view: view_35,
16428
16394
  snapshot: snapshot_6,
16429
16395
  batch: {
16430
16396
  version: FOLIO_DOCUMENT_OPERATION_CONTRACT_VERSION,
@@ -16446,75 +16412,78 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
16446
16412
  };
16447
16413
  },
16448
16414
  activeSuggestionIds: () => {
16449
- const view_35 = pagedEditorRef.current?.getView();
16450
- return new Set(view_35 ? getSuggestions(view_35.state).map((s_3) => s_3.suggestionId) : []);
16415
+ const view_36 = pagedEditorRef.current?.getView();
16416
+ return new Set(view_36 ? getSuggestions(view_36.state).map((s_4) => s_4.suggestionId) : []);
16451
16417
  }
16452
16418
  }),
16453
16419
  acceptSuggestion: (suggestionId, options_4) => {
16454
- const view_36 = pagedEditorRef.current?.getView();
16455
- if (!view_36) return {
16420
+ const view_37 = pagedEditorRef.current?.getView();
16421
+ if (!view_37) return {
16456
16422
  accepted: false,
16457
16423
  appliedAs: null
16458
16424
  };
16459
- const appliedAs = getSuggestions(view_36.state).find((s_4) => s_4.suggestionId === suggestionId)?.appliedAs ?? null;
16460
- const accepted = acceptSuggestion(suggestionId, { author: options_4?.author ?? author })(view_36.state, view_36.dispatch);
16425
+ const appliedAs = getSuggestions(view_37.state).find((s_5) => s_5.suggestionId === suggestionId)?.appliedAs ?? null;
16426
+ const editor_7 = pagedEditorRef.current?.getEditor();
16427
+ const accepted = editor_7?.getCanonicalDocument() ? editor_7.resolveCanonicalSuggestion(suggestionId, "accept", options_4?.author ?? author) : acceptSuggestion(suggestionId, { author: options_4?.author ?? author })(view_37.state, view_37.dispatch);
16461
16428
  return {
16462
16429
  accepted,
16463
16430
  appliedAs: accepted ? appliedAs : null
16464
16431
  };
16465
16432
  },
16466
16433
  rejectSuggestion: (suggestionId_0) => {
16467
- const view_37 = pagedEditorRef.current?.getView();
16468
- if (!view_37) return false;
16469
- return rejectSuggestion(suggestionId_0)(view_37.state, view_37.dispatch);
16470
- },
16471
- scrollToSuggestion: (suggestionId_1) => {
16472
16434
  const view_38 = pagedEditorRef.current?.getView();
16473
16435
  if (!view_38) return false;
16474
- const range_4 = findSuggestionRange(view_38.state, suggestionId_1);
16436
+ const editor_8 = pagedEditorRef.current?.getEditor();
16437
+ if (editor_8?.getCanonicalDocument()) return editor_8.resolveCanonicalSuggestion(suggestionId_0, "reject", author);
16438
+ return rejectSuggestion(suggestionId_0)(view_38.state, view_38.dispatch);
16439
+ },
16440
+ scrollToSuggestion: (suggestionId_1) => {
16441
+ const view_39 = pagedEditorRef.current?.getView();
16442
+ if (!view_39) return false;
16443
+ const range_4 = findSuggestionRange(view_39.state, suggestionId_1);
16475
16444
  if (!range_4) return false;
16476
- const { from: from_12, to: to_12 } = clampRangeToDocSize(view_38.state.doc.content.size, range_4);
16477
- const $from_3 = view_38.state.doc.resolve(from_12);
16478
- const $to_3 = view_38.state.doc.resolve(to_12);
16479
- view_38.dispatch(view_38.state.tr.setSelection(TextSelection.between($from_3, $to_3)));
16445
+ const { from: from_12, to: to_12 } = clampRangeToDocSize(view_39.state.doc.content.size, range_4);
16446
+ const $from_3 = view_39.state.doc.resolve(from_12);
16447
+ const $to_3 = view_39.state.doc.resolve(to_12);
16448
+ view_39.dispatch(view_39.state.tr.setSelection(TextSelection.between($from_3, $to_3)));
16480
16449
  requestAnimationFrame(() => {
16481
16450
  pagedEditorRef.current?.scrollToPosition(from_12);
16482
16451
  });
16483
16452
  return true;
16484
16453
  },
16485
16454
  getTrackedChanges: () => {
16486
- const view_39 = pagedEditorRef.current?.getView();
16487
- return view_39 ? getTrackedChangesFromDoc(view_39.state.doc) : [];
16455
+ const view_40 = pagedEditorRef.current?.getView();
16456
+ return view_40 ? getTrackedChangesFromDoc(view_40.state.doc) : [];
16488
16457
  },
16489
16458
  getCommentAnchors: () => {
16490
- const view_40 = pagedEditorRef.current?.getView();
16491
- return view_40 ? getCommentAnchorsFromDoc(view_40.state.doc) : [];
16459
+ const view_41 = pagedEditorRef.current?.getView();
16460
+ return view_41 ? getCommentAnchorsFromDoc(view_41.state.doc) : [];
16492
16461
  },
16493
16462
  getSelectionText: () => {
16494
- const view_41 = pagedEditorRef.current?.getView();
16495
- return view_41 ? getSelectedText(view_41.state) : "";
16463
+ const view_42 = pagedEditorRef.current?.getView();
16464
+ return view_42 ? getSelectedText(view_42.state) : "";
16496
16465
  },
16497
16466
  getPageText: (page_0) => {
16498
- const view_42 = pagedEditorRef.current?.getView();
16499
- if (!view_42) return null;
16467
+ const view_43 = pagedEditorRef.current?.getView();
16468
+ if (!view_43) return null;
16500
16469
  const layout_0 = pagedEditorRef.current?.getEditor()?.getLayout() ?? null;
16501
16470
  return getPageTextFromLayout({
16502
16471
  layout: layout_0,
16503
- doc: view_42.state.doc,
16472
+ doc: view_43.state.doc,
16504
16473
  page: page_0,
16505
- projection: projectMarkupView(view_42.state, displayMode)
16474
+ projection: projectMarkupView(view_43.state, displayMode)
16506
16475
  });
16507
16476
  },
16508
16477
  getTargetPage: (target_2, snapshot_7) => {
16509
- const view_43 = pagedEditorRef.current?.getView();
16510
- if (!view_43) return null;
16478
+ const view_44 = pagedEditorRef.current?.getView();
16479
+ if (!view_44) return null;
16511
16480
  const range_5 = target_2.type === "textRange" ? resolveFolioAITextRange({
16512
16481
  range: target_2,
16513
- doc: view_43.state.doc,
16482
+ doc: view_44.state.doc,
16514
16483
  snapshot: snapshot_7
16515
16484
  }) : resolveFolioAIBlockRange({
16516
16485
  blockId: target_2.blockId,
16517
- doc: view_43.state.doc,
16486
+ doc: view_44.state.doc,
16518
16487
  snapshot: snapshot_7
16519
16488
  });
16520
16489
  if (range_5 === null) return null;
@@ -16525,49 +16494,49 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
16525
16494
  getScrollRoot: () => pagedEditorRef.current?.getScrollRoot() ?? null,
16526
16495
  onLayoutChange: (listener) => pagedEditorRef.current?.onLayoutChange(listener) ?? (() => {}),
16527
16496
  getContentControls: (filter = {}) => {
16528
- const view_44 = pagedEditorRef.current?.getView();
16529
- if (!view_44) return [];
16530
- return findBlockSdtMatches(view_44.state.doc, filter).map((match_0) => ({
16497
+ const view_45 = pagedEditorRef.current?.getView();
16498
+ if (!view_45) return [];
16499
+ return findBlockSdtMatches(view_45.state.doc, filter).map((match_0) => ({
16531
16500
  properties: blockSdtAttrsToSdtProperties(match_0.node),
16532
16501
  path: match_0.path,
16533
16502
  pmPos: match_0.pos
16534
16503
  }));
16535
16504
  },
16536
16505
  scrollToContentControl: (filter_0) => {
16537
- const view_45 = pagedEditorRef.current?.getView();
16538
- if (!view_45) return false;
16539
- const match_1 = findBlockSdtMatch(view_45.state.doc, filter_0);
16506
+ const view_46 = pagedEditorRef.current?.getView();
16507
+ if (!view_46) return false;
16508
+ const match_1 = findBlockSdtMatch(view_46.state.doc, filter_0);
16540
16509
  if (!match_1) return false;
16541
16510
  const inside = match_1.pos + 1;
16542
- const $pos = view_45.state.doc.resolve(inside);
16543
- view_45.dispatch(view_45.state.tr.setSelection(TextSelection.near($pos)));
16511
+ const $pos = view_46.state.doc.resolve(inside);
16512
+ view_46.dispatch(view_46.state.tr.setSelection(TextSelection.near($pos)));
16544
16513
  requestAnimationFrame(() => {
16545
16514
  pagedEditorRef.current?.scrollToPosition(inside);
16546
16515
  });
16547
16516
  return true;
16548
16517
  },
16549
16518
  setContentControlContent: (filter_1, input, options_5 = {}) => {
16550
- const view_46 = pagedEditorRef.current?.getView();
16551
- if (!view_46) return false;
16552
- const tr_0 = typeof input === "string" ? setContentControlContentTr(view_46.state, filter_1, input, options_5) : setContentControlContentBlocksTr(view_46.state, filter_1, input, options_5);
16519
+ const view_47 = pagedEditorRef.current?.getView();
16520
+ if (!view_47) return false;
16521
+ const tr_0 = typeof input === "string" ? setContentControlContentTr(view_47.state, filter_1, input, options_5) : setContentControlContentBlocksTr(view_47.state, filter_1, input, options_5);
16553
16522
  if (!tr_0) return false;
16554
- view_46.dispatch(tr_0);
16523
+ view_47.dispatch(tr_0);
16555
16524
  return true;
16556
16525
  },
16557
16526
  setContentControlValue: (filter_2, input_0, options_6 = {}) => {
16558
- const view_47 = pagedEditorRef.current?.getView();
16559
- if (!view_47) return false;
16560
- const tr_1 = setContentControlValueTr(view_47.state, filter_2, input_0, options_6);
16527
+ const view_48 = pagedEditorRef.current?.getView();
16528
+ if (!view_48) return false;
16529
+ const tr_1 = setContentControlValueTr(view_48.state, filter_2, input_0, options_6);
16561
16530
  if (!tr_1) return false;
16562
- view_47.dispatch(tr_1);
16531
+ view_48.dispatch(tr_1);
16563
16532
  return true;
16564
16533
  },
16565
16534
  removeContentControl: (filter_3, options_7 = {}) => {
16566
- const view_48 = pagedEditorRef.current?.getView();
16567
- if (!view_48) return false;
16568
- const tr_2 = removeContentControlTr(view_48.state, filter_3, options_7);
16535
+ const view_49 = pagedEditorRef.current?.getView();
16536
+ if (!view_49) return false;
16537
+ const tr_2 = removeContentControlTr(view_49.state, filter_3, options_7);
16569
16538
  if (!tr_2) return false;
16570
- view_48.dispatch(tr_2);
16539
+ view_49.dispatch(tr_2);
16571
16540
  return true;
16572
16541
  }
16573
16542
  }), [
@@ -16660,47 +16629,47 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
16660
16629
  if (isDisplayMode(value)) setDisplayMode(value);
16661
16630
  }, [setDisplayMode]);
16662
16631
  const handleAcceptActiveChange = useCallback(() => {
16663
- const view_49 = pagedEditorRef.current?.getView();
16664
- if (!view_49) return;
16665
- const { from: from_13, to: to_13 } = view_49.state.selection;
16666
- const range_6 = findChangeAtPosition(view_49.state, from_13, to_13);
16632
+ const view_50 = pagedEditorRef.current?.getView();
16633
+ if (!view_50) return;
16634
+ const { from: from_13, to: to_13 } = view_50.state.selection;
16635
+ const range_6 = findChangeAtPosition(view_50.state, from_13, to_13);
16667
16636
  if (resolveCanonicalReviewRange({
16668
16637
  editor: pagedEditorRef.current?.getEditor(),
16669
16638
  ...range_6,
16670
16639
  resolution: "accept"
16671
- }) === null) acceptChange(range_6.from, range_6.to)(view_49.state, view_49.dispatch);
16640
+ }) === null) acceptChange(range_6.from, range_6.to)(view_50.state, view_50.dispatch);
16672
16641
  }, []);
16673
16642
  const handleRejectActiveChange = useCallback(() => {
16674
- const view_50 = pagedEditorRef.current?.getView();
16675
- if (!view_50) return;
16676
- const { from: from_14, to: to_14 } = view_50.state.selection;
16677
- const range_7 = findChangeAtPosition(view_50.state, from_14, to_14);
16643
+ const view_51 = pagedEditorRef.current?.getView();
16644
+ if (!view_51) return;
16645
+ const { from: from_14, to: to_14 } = view_51.state.selection;
16646
+ const range_7 = findChangeAtPosition(view_51.state, from_14, to_14);
16678
16647
  if (resolveCanonicalReviewRange({
16679
16648
  editor: pagedEditorRef.current?.getEditor(),
16680
16649
  ...range_7,
16681
16650
  resolution: "reject"
16682
- }) === null) rejectChange(range_7.from, range_7.to)(view_50.state, view_50.dispatch);
16651
+ }) === null) rejectChange(range_7.from, range_7.to)(view_51.state, view_51.dispatch);
16683
16652
  }, []);
16684
16653
  const handlePreviousChange = useCallback(() => {
16685
- const view_51 = pagedEditorRef.current?.getView();
16686
- if (!view_51) return;
16687
- const { from: from_15 } = view_51.state.selection;
16688
- const change = findPreviousChange(view_51.state, from_15);
16654
+ const view_52 = pagedEditorRef.current?.getView();
16655
+ if (!view_52) return;
16656
+ const { from: from_15 } = view_52.state.selection;
16657
+ const change = findPreviousChange(view_52.state, from_15);
16689
16658
  if (!change) return;
16690
- view_51.dispatch(view_51.state.tr.setSelection(TextSelection.create(view_51.state.doc, change.from, change.to)));
16691
- view_51.focus();
16659
+ view_52.dispatch(view_52.state.tr.setSelection(TextSelection.create(view_52.state.doc, change.from, change.to)));
16660
+ view_52.focus();
16692
16661
  requestAnimationFrame(() => {
16693
16662
  pagedEditorRef.current?.scrollToPosition(change.from);
16694
16663
  });
16695
16664
  }, []);
16696
16665
  const handleNextChange = useCallback(() => {
16697
- const view_52 = pagedEditorRef.current?.getView();
16698
- if (!view_52) return;
16699
- const { to: to_15 } = view_52.state.selection;
16700
- const change_0 = findNextChange(view_52.state, to_15);
16666
+ const view_53 = pagedEditorRef.current?.getView();
16667
+ if (!view_53) return;
16668
+ const { to: to_15 } = view_53.state.selection;
16669
+ const change_0 = findNextChange(view_53.state, to_15);
16701
16670
  if (!change_0) return;
16702
- view_52.dispatch(view_52.state.tr.setSelection(TextSelection.create(view_52.state.doc, change_0.from, change_0.to)));
16703
- view_52.focus();
16671
+ view_53.dispatch(view_53.state.tr.setSelection(TextSelection.create(view_53.state.doc, change_0.from, change_0.to)));
16672
+ view_53.focus();
16704
16673
  requestAnimationFrame(() => {
16705
16674
  pagedEditorRef.current?.scrollToPosition(change_0.from);
16706
16675
  });
@@ -16812,15 +16781,15 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
16812
16781
  }),
16813
16782
  /* @__PURE__ */ jsx(ToolbarButton, {
16814
16783
  onClick: handleAcceptActiveChange,
16815
- disabled: readOnly || !state.activeTrackedChange,
16816
- title: t("acceptChange"),
16784
+ disabled: readOnly || !state.activeTrackedChange || state.activeTrackedChange.heldByLock.accept,
16785
+ title: state.activeTrackedChange?.heldByLock.accept ? t("trackedChanges.heldByLock") : t("acceptChange"),
16817
16786
  ariaLabel: t("acceptChange"),
16818
16787
  children: /* @__PURE__ */ jsx(CheckIcon, { size: 16 })
16819
16788
  }),
16820
16789
  /* @__PURE__ */ jsx(ToolbarButton, {
16821
16790
  onClick: handleRejectActiveChange,
16822
- disabled: readOnly || !state.activeTrackedChange,
16823
- title: t("rejectChange"),
16791
+ disabled: readOnly || !state.activeTrackedChange || state.activeTrackedChange.heldByLock.reject,
16792
+ title: state.activeTrackedChange?.heldByLock.reject ? t("trackedChanges.heldByLock") : t("rejectChange"),
16824
16793
  ariaLabel: t("rejectChange"),
16825
16794
  children: /* @__PURE__ */ jsx(XIcon, { size: 16 })
16826
16795
  }),
@@ -16870,8 +16839,8 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
16870
16839
  requestAnimationFrame(syncCommentHighlightStyles);
16871
16840
  }, [onScrollTopChange, syncCommentHighlightStyles]);
16872
16841
  const handlePagedSelectionChange = useCallback((_from, _to) => {
16873
- const view_53 = getActiveEditorView() ?? pagedEditorRef.current?.getView() ?? null;
16874
- handleSelectionChange(view_53 ? extractSelectionState(view_53.state) : null);
16842
+ const view_54 = getActiveEditorView() ?? pagedEditorRef.current?.getView() ?? null;
16843
+ handleSelectionChange(view_54 ? extractSelectionState(view_54.state) : null);
16875
16844
  }, [getActiveEditorView, handleSelectionChange]);
16876
16845
  const handleTotalPagesChange = useCallback((totalPages) => {
16877
16846
  setScrollPageInfo((previous_0) => updateScrollPageTotal(previous_0, totalPages));
@@ -16883,11 +16852,20 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
16883
16852
  id: id_1,
16884
16853
  status: "resolved"
16885
16854
  }) !== null) return;
16855
+ if (readOnly) {
16856
+ notifyReadonlyEditAttempt();
16857
+ return;
16858
+ }
16886
16859
  updateComments((previous_1) => previous_1.map((comment_2) => comment_2.id === id_1 ? {
16887
16860
  ...comment_2,
16888
16861
  done: true
16889
16862
  } : comment_2));
16890
- }, [applyCanonicalComment, updateComments]);
16863
+ }, [
16864
+ applyCanonicalComment,
16865
+ notifyReadonlyEditAttempt,
16866
+ readOnly,
16867
+ updateComments
16868
+ ]);
16891
16869
  const handleCommentDelete = useCallback((id_2) => {
16892
16870
  const result_5 = applyCanonicalComment({
16893
16871
  type: "delete",
@@ -16897,11 +16875,17 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
16897
16875
  if (result_5.status === "applied" && activeCommentId === id_2) setActiveCommentId(null);
16898
16876
  return;
16899
16877
  }
16878
+ if (readOnly) {
16879
+ notifyReadonlyEditAttempt();
16880
+ return;
16881
+ }
16900
16882
  updateComments((previous_2) => previous_2.filter((comment_3) => comment_3.id !== id_2 && comment_3.parentId !== id_2));
16901
16883
  if (activeCommentId === id_2) setActiveCommentId(null);
16902
16884
  }, [
16903
16885
  activeCommentId,
16904
16886
  applyCanonicalComment,
16887
+ notifyReadonlyEditAttempt,
16888
+ readOnly,
16905
16889
  setActiveCommentId,
16906
16890
  updateComments
16907
16891
  ]);
@@ -16915,16 +16899,22 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
16915
16899
  parentId: id_3
16916
16900
  }
16917
16901
  }) !== null) return;
16902
+ if (readOnly) {
16903
+ notifyReadonlyEditAttempt();
16904
+ return;
16905
+ }
16918
16906
  updateComments((previous_3) => [...previous_3, createComment(text_6, author, id_3)]);
16919
16907
  }, [
16920
16908
  applyCanonicalComment,
16921
16909
  author,
16922
16910
  createComment,
16911
+ notifyReadonlyEditAttempt,
16912
+ readOnly,
16923
16913
  updateComments
16924
16914
  ]);
16925
16915
  const handleAddComment = useCallback((addText) => {
16926
- const view_54 = pagedEditorRef.current?.getView();
16927
- if (!view_54 || !commentSelectionRange) return false;
16916
+ const view_55 = pagedEditorRef.current?.getView();
16917
+ if (!view_55 || !commentSelectionRange) return false;
16928
16918
  const result_6 = applyCanonicalComment({
16929
16919
  type: "create",
16930
16920
  text: addText,
@@ -16937,9 +16927,9 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
16937
16927
  });
16938
16928
  if (result_6 !== null) {
16939
16929
  if (result_6?.status !== "applied") return false;
16940
- setVisibleCommentAuthors((current_0) => {
16941
- if (current_0 === null) return null;
16942
- const next_1 = new Set(current_0);
16930
+ setVisibleCommentAuthors((current_1) => {
16931
+ if (current_1 === null) return null;
16932
+ const next_1 = new Set(current_1);
16943
16933
  const created = result_6.comments.find(({ id: id_4 }) => id_4 === result_6.commentId);
16944
16934
  if (created) next_1.add(getCommentAuthorKey(created.author));
16945
16935
  return next_1;
@@ -16950,12 +16940,16 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
16950
16940
  setAddCommentYPosition(null);
16951
16941
  return true;
16952
16942
  }
16943
+ if (readOnly) {
16944
+ notifyReadonlyEditAttempt();
16945
+ return false;
16946
+ }
16953
16947
  const comment_4 = createComment(addText, author);
16954
- if (!applyCommentMarkRange(view_54, commentSelectionRange, comment_4.id, { replacePending: true })) return false;
16948
+ if (!applyCommentMarkRange(view_55, commentSelectionRange, comment_4.id, { replacePending: true })) return false;
16955
16949
  const commentAuthor_2 = getCommentAuthorKey(comment_4.author);
16956
- setVisibleCommentAuthors((current_1) => {
16957
- if (current_1 === null) return null;
16958
- const next_2 = new Set(current_1);
16950
+ setVisibleCommentAuthors((current_2) => {
16951
+ if (current_2 === null) return null;
16952
+ const next_2 = new Set(current_2);
16959
16953
  next_2.add(commentAuthor_2);
16960
16954
  return next_2;
16961
16955
  });
@@ -16975,6 +16969,8 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
16975
16969
  applyCanonicalComment,
16976
16970
  commentSelectionRange,
16977
16971
  createComment,
16972
+ notifyReadonlyEditAttempt,
16973
+ readOnly,
16978
16974
  setActiveCommentId,
16979
16975
  setAddCommentYPosition,
16980
16976
  setCommentSelectionRange,
@@ -16994,16 +16990,22 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
16994
16990
  revisionId: revisionId_2
16995
16991
  }
16996
16992
  }) !== null) return;
16993
+ if (readOnly) {
16994
+ notifyReadonlyEditAttempt();
16995
+ return;
16996
+ }
16997
16997
  updateComments((previous_5) => [...previous_5, createComment(text_7, author, revisionId_2)]);
16998
16998
  }, [
16999
16999
  applyCanonicalComment,
17000
17000
  author,
17001
17001
  createComment,
17002
+ notifyReadonlyEditAttempt,
17003
+ readOnly,
17002
17004
  updateComments
17003
17005
  ]);
17004
17006
  const handleCancelAddComment = useCallback(() => {
17005
- const view_55 = pagedEditorRef.current?.getView();
17006
- if (view_55 && commentSelectionRange && commentDraftMode === "prosemirror") removePendingCommentMarkRange(view_55, commentSelectionRange);
17007
+ const view_56 = pagedEditorRef.current?.getView();
17008
+ if (view_56 && commentSelectionRange && commentDraftMode === "prosemirror") removePendingCommentMarkRange(view_56, commentSelectionRange);
17007
17009
  setIsAddingComment(false);
17008
17010
  setCommentSelectionRange(null);
17009
17011
  setAddCommentYPosition(null);
@@ -17020,23 +17022,23 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
17020
17022
  })?.revisionId ?? null;
17021
17023
  }, []);
17022
17024
  const handleSidebarAcceptChange = useCallback((from_17, to_17) => {
17023
- const view_56 = pagedEditorRef.current?.getView();
17024
- if (!view_56) return;
17025
+ const view_57 = pagedEditorRef.current?.getView();
17026
+ if (!view_57) return;
17025
17027
  const revisionId_3 = resolveSidebarChangeRevisionId(from_17, to_17);
17026
17028
  if (revisionId_3 === null) return;
17027
- const editor_7 = pagedEditorRef.current?.getEditor();
17028
- if (editor_7?.getCanonicalDocument()) editor_7.resolveCanonicalRevisions([revisionId_3], "accept");
17029
- else acceptAIEditRevision(revisionId_3)(view_56.state, view_56.dispatch);
17029
+ const editor_9 = pagedEditorRef.current?.getEditor();
17030
+ if (editor_9?.getCanonicalDocument()) editor_9.resolveCanonicalRevisions([revisionId_3], "accept");
17031
+ else acceptAIEditRevision(revisionId_3)(view_57.state, view_57.dispatch);
17030
17032
  extractTrackedChanges();
17031
17033
  }, [extractTrackedChanges, resolveSidebarChangeRevisionId]);
17032
17034
  const handleSidebarRejectChange = useCallback((from_18, to_18) => {
17033
- const view_57 = pagedEditorRef.current?.getView();
17034
- if (!view_57) return;
17035
+ const view_58 = pagedEditorRef.current?.getView();
17036
+ if (!view_58) return;
17035
17037
  const revisionId_4 = resolveSidebarChangeRevisionId(from_18, to_18);
17036
17038
  if (revisionId_4 === null) return;
17037
- const editor_8 = pagedEditorRef.current?.getEditor();
17038
- if (editor_8?.getCanonicalDocument()) editor_8.resolveCanonicalRevisions([revisionId_4], "reject");
17039
- else rejectAIEditRevision(revisionId_4)(view_57.state, view_57.dispatch);
17039
+ const editor_10 = pagedEditorRef.current?.getEditor();
17040
+ if (editor_10?.getCanonicalDocument()) editor_10.resolveCanonicalRevisions([revisionId_4], "reject");
17041
+ else rejectAIEditRevision(revisionId_4)(view_58.state, view_58.dispatch);
17040
17042
  extractTrackedChanges();
17041
17043
  }, [extractTrackedChanges, resolveSidebarChangeRevisionId]);
17042
17044
  const commentsPageWidth = history.state?.package.document.finalSectionProperties?.pageWidth;
@@ -17186,8 +17188,8 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
17186
17188
  }, [readOnly]);
17187
17189
  const closeTableProperties = useCallback(() => setTablePropsOpen(false), []);
17188
17190
  const applyTableProperties = useCallback((props_0) => {
17189
- const view_58 = getActiveEditorView();
17190
- if (view_58) setTableProperties(props_0)(view_58.state, view_58.dispatch);
17191
+ const view_59 = getActiveEditorView();
17192
+ if (view_59) setTableProperties(props_0)(view_59.state, view_59.dispatch);
17191
17193
  }, [getActiveEditorView]);
17192
17194
  const closeImagePosition = useCallback(() => setImagePositionOpen(false), [setImagePositionOpen]);
17193
17195
  const closeImageProperties = useCallback(() => setImagePropsOpen(false), [setImagePropsOpen]);
@@ -17195,8 +17197,8 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
17195
17197
  const closeFootnoteProperties = useCallback(() => setFootnotePropsOpen(false), []);
17196
17198
  const closeInsertSymbol = useCallback(() => setShowInsertSymbol(false), []);
17197
17199
  const insertSymbol = useCallback((symbol) => {
17198
- const view_59 = getActiveEditorView();
17199
- if (view_59) view_59.dispatch(view_59.state.tr.insertText(symbol).scrollIntoView());
17200
+ const view_60 = getActiveEditorView();
17201
+ if (view_60) view_60.dispatch(view_60.state.tr.insertText(symbol).scrollIntoView());
17200
17202
  }, [getActiveEditorView]);
17201
17203
  const imagePropertiesCurrentData = useMemo(() => buildImagePropertiesData(state.pmImageContext), [state.pmImageContext]);
17202
17204
  const { close: closeFindDialog } = findReplace;
@@ -17287,8 +17289,8 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
17287
17289
  ]);
17288
17290
  const closeNumberingValueDialog = useCallback(() => setNumberingValueDialogOpen(false), []);
17289
17291
  const applyNumberingValue = useCallback((value_0) => {
17290
- const view_60 = getActiveEditorView();
17291
- if (view_60) setNumberingValue(value_0)(view_60.state, view_60.dispatch);
17292
+ const view_61 = getActiveEditorView();
17293
+ if (view_61) setNumberingValue(value_0)(view_61.state, view_61.dispatch);
17292
17294
  }, [getActiveEditorView]);
17293
17295
  const numberingValueDialog = useMemo(() => ({
17294
17296
  isOpen: numberingValueDialogOpen,
@@ -17588,11 +17590,12 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
17588
17590
  delayMs: 300,
17589
17591
  children: /* @__PURE__ */ jsx("button", {
17590
17592
  type: "button",
17593
+ "aria-label": "Add comment",
17591
17594
  onMouseDown: (e_1) => {
17592
17595
  e_1.preventDefault();
17593
17596
  e_1.stopPropagation();
17594
- const view_61 = pagedEditorRef.current?.getView();
17595
- if (!view_61) {
17597
+ const view_62 = pagedEditorRef.current?.getView();
17598
+ if (!view_62) {
17596
17599
  setFloatingCommentBtn(null);
17597
17600
  return;
17598
17601
  }
@@ -17600,9 +17603,9 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
17600
17603
  from: floatingCommentBtn.from,
17601
17604
  to: floatingCommentBtn.to
17602
17605
  };
17603
- const currentSelection = view_61.state.selection;
17606
+ const currentSelection = view_62.state.selection;
17604
17607
  const safeRange = resolveCommentCreationRange({
17605
- docSize: view_61.state.doc.content.size,
17608
+ docSize: view_62.state.doc.content.size,
17606
17609
  capturedRange,
17607
17610
  currentRange: {
17608
17611
  from: currentSelection.from,
@@ -17617,7 +17620,7 @@ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, documentBuff
17617
17620
  }
17618
17621
  setCommentSelectionRange(safeRange);
17619
17622
  if (commentDraftMode === "prosemirror") {
17620
- if (!applyCommentMarkRange(view_61, safeRange, -1, { selectEnd: true })) {
17623
+ if (!applyCommentMarkRange(view_62, safeRange, -1, { selectEnd: true })) {
17621
17624
  setCommentSelectionRange(null);
17622
17625
  setFloatingCommentBtn(null);
17623
17626
  return;