@stll/folio-react 0.28.0 → 0.30.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.
@@ -1,6 +1,7 @@
1
- import { i as cn, n as FolioUIProvider, r as useFolioUI, t as DEFAULT_COMPONENTS } from "./folio-ui-rCHqCEG6.js";
1
+ import { i as cn, n as FolioUIProvider, r as useFolioUI, t as DEFAULT_COMPONENTS } from "./folio-ui-ruRywxeb.js";
2
2
  import { t as messages_exports } from "./messages.js";
3
3
  import { c } from "react-compiler-runtime";
4
+ import { readBlobText } from "@stll/folio-core/utils/textEncoding";
4
5
  import { CANONICAL_GAP, canonicalRefusalMessage, usesCanonicalSession } from "@stll/folio-core/types/canonicalCapabilities";
5
6
  import * as React$1 from "react";
6
7
  import React, { Component, Suspense, cloneElement, createContext, forwardRef, isValidElement, lazy, memo, useCallback, useEffect, useEffectEvent, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
@@ -30,7 +31,6 @@ import { executeEditorCommand, executeFirstEditorCommand } from "@stll/folio-cor
30
31
  import { insertPageBreak } from "@stll/folio-core/prosemirror/commands/pageBreak";
31
32
  import { clearTrackedChanges, getChangedParagraphIds, hasStructuralChanges, hasUntrackedChanges, repackWithEditorSectionRemovals } from "@stll/folio-core/prosemirror/extensions/features/ParagraphChangeTrackerExtension";
32
33
  import { createStarterKit } from "@stll/folio-core/prosemirror/extensions/StarterKit";
33
- import { resolveFindMatchRange } from "@stll/folio-core/prosemirror/findReplaceSelection";
34
34
  import { createAICitationDecorationsPlugin } from "@stll/folio-core/prosemirror/plugins/aiCitationDecorations";
35
35
  import { AI_SUGGESTION_SEVERITY_CLASS, aiSuggestionDecorationsKey, createAISuggestionDecorationsPlugin } from "@stll/folio-core/prosemirror/plugins/aiSuggestionDecorations";
36
36
  import { anonymizationDecorationsKey, createAnonymizationDecorationsPlugin, slugAnonymizationLabel } from "@stll/folio-core/prosemirror/plugins/anonymizationDecorations";
@@ -106,14 +106,18 @@ import { getFolioParaIdFromBlockId } from "@stll/folio-core/types/block-id";
106
106
  import { getPageTextFromLayout } from "@stll/folio-core/paged-layout/pageText";
107
107
  import { allocateCommentId, seedCommentIdAbove } from "@stll/folio-core/prosemirror/commentIdAllocator";
108
108
  import { ContentControlWidgetController } from "@stll/folio-core/controller/contentControlWidgetController";
109
- import { createDefaultFindOptions, findInDocument } from "@stll/folio-core/utils/findReplace";
109
+ import { createDefaultFindOptions, replaceEligibility } from "@stll/folio-core/utils/findReplace";
110
110
  import { PANEL_METRICS, computePanelLayout } from "@stll/folio-core/panel-layout";
111
111
  import { ErrorManager } from "@stll/folio-core/managers/ErrorManager";
112
112
  import { ContextMenuManager } from "@stll/folio-core/managers/ContextMenuManager";
113
113
  import { DocumentLoaderManager } from "@stll/folio-core/managers/DocumentLoaderManager";
114
114
  import { getDocumentLoadSource } from "@stll/folio-core/utils/documentLoaderBehavior";
115
- import { DISPLAY_MODES, EditorModeManager, isReadOnlyMode, isTrackChangesMode, toggledTrackChangesMode } from "@stll/folio-core/managers/EditorModeManager";
115
+ import { DISPLAY_MODES, EditorModeManager, getEditorReadOnlyReason, getReviewViewReadOnlyReason, isTrackChangesMode, toggledTrackChangesMode } from "@stll/folio-core/managers/EditorModeManager";
116
+ import { reviewDisplayModeToDisplayMode } from "@stll/folio-core/managers/reviewDisplayMode";
116
117
  import { FindReplaceManager } from "@stll/folio-core/managers/FindReplaceManager";
118
+ import { findInDisplayedDocument } from "@stll/folio-core/prosemirror/findReplaceSelection";
119
+ import { createFindQueryKey, createFindSearchKey, sameFindBodyVersion, sameFindSearchKey } from "@stll/folio-core/utils/findSearchKey";
120
+ import { createFindMatchView, getRenderedSearchStories } from "@stll/folio-core/utils/findMatchView";
117
121
  import { createEmptyHeaderFooter, pickActiveHeaderFooterRId, removeHeaderFooter, resolveEffectiveSectionProperties, resolveHeaderFooterContent, saveHeaderFooterContent } from "@stll/folio-core/utils/headerFooter";
118
122
  import { createCanonicalHeaderFooterOperation, removeCanonicalHeaderFooterOperations } from "@stll/folio-core/controller/canonicalOperations";
119
123
  import { editHyperlinkAtCursor, removeHyperlinkAtCursor } from "@stll/folio-core/prosemirror/commands/hyperlink";
@@ -354,9 +358,10 @@ const HOST_STYLES = {
354
358
  zIndex: -1,
355
359
  pointerEvents: "none"
356
360
  };
357
- const HiddenHeaderFooterPMs = memo(forwardRef(function HiddenHeaderFooterPMs({ document, styles, theme, onTransaction, experimentalSession, getCanonicalApi, onSessionRefusal }, ref) {
361
+ const HiddenHeaderFooterPMs = memo(forwardRef(function HiddenHeaderFooterPMs({ document, readOnly, styles, theme, onTransaction, experimentalSession, getCanonicalApi, onSessionRefusal }, ref) {
358
362
  const hostRef = useRef(null);
359
363
  const documentRef = useRef(document);
364
+ const readOnlyRef = useRef(readOnly);
360
365
  const stylesRef = useRef(styles);
361
366
  const themeRef = useRef(theme);
362
367
  const onTransactionRef = useRef(onTransaction);
@@ -366,6 +371,7 @@ const HiddenHeaderFooterPMs = memo(forwardRef(function HiddenHeaderFooterPMs({ d
366
371
  const managerRef = useRef(null);
367
372
  useLayoutEffect(() => {
368
373
  documentRef.current = document;
374
+ readOnlyRef.current = readOnly;
369
375
  stylesRef.current = styles;
370
376
  themeRef.current = theme;
371
377
  onTransactionRef.current = onTransaction;
@@ -375,6 +381,7 @@ const HiddenHeaderFooterPMs = memo(forwardRef(function HiddenHeaderFooterPMs({ d
375
381
  managerRef.current ??= createHeaderFooterEditorManager({
376
382
  getHost: () => hostRef.current,
377
383
  getDocument: () => documentRef.current,
384
+ getReadOnly: () => readOnlyRef.current ?? false,
378
385
  getStyles: () => stylesRef.current,
379
386
  getTheme: () => themeRef.current,
380
387
  getCanonicalApi: () => canonicalApiRef.current?.() ?? null,
@@ -384,8 +391,10 @@ const HiddenHeaderFooterPMs = memo(forwardRef(function HiddenHeaderFooterPMs({ d
384
391
  onTransactionRef.current?.(rId, kind, view, docChanged, selectionChanged);
385
392
  }
386
393
  });
394
+ managerRef.current.sync();
387
395
  }, [
388
396
  document,
397
+ readOnly,
389
398
  styles,
390
399
  theme,
391
400
  onTransaction,
@@ -393,9 +402,6 @@ const HiddenHeaderFooterPMs = memo(forwardRef(function HiddenHeaderFooterPMs({ d
393
402
  experimentalSession,
394
403
  onSessionRefusal
395
404
  ]);
396
- useEffect(() => {
397
- managerRef.current?.sync();
398
- });
399
405
  useEffect(() => () => {
400
406
  managerRef.current?.destroy();
401
407
  }, []);
@@ -3044,7 +3050,7 @@ function buildFootnoteRenderItems(pageFootnoteMap, footnoteContentMap, doc) {
3044
3050
  * PagedEditor - Main paginated editing component.
3045
3051
  */
3046
3052
  const PagedEditor = forwardRef(function PagedEditor(props, ref) {
3047
- const { document, documentIO, documentIdentity, experimentalSession, fonts: hostFonts, styles, theme: _theme, sectionProperties, headerContent, footerContent, firstPageHeaderContent, firstPageFooterContent, headerContentRId, footerContentRId, firstPageHeaderContentRId, firstPageFooterContentRId, readOnly = false, pageGap = 24, zoom = 1, pageRenderer, markupView, showMarginGuides = false, marginGuideColor, onDocumentChange, onReadOnlyEditAttempt, onCopy, onCut, onPaste, onSelectionChange, onSelectionTextChange, onEditorViewReady, externalPlugins = EMPTY_PLUGINS, showTemplateDirectives = true, collaboration, extensionManager, suggestionModeActive = false, suggestionAuthor, onActiveNoteStoryChange, onHeaderFooterDoubleClick, hfEditMode, activeHeaderFooterRId, onBodyClick, className, style, pageEndGutter = 0, sidebarOverlay, scrollContainerRef: scrollContainerRefProp, onHyperlinkClick, onContextMenu, onAnchorPositionsChange, onTotalPagesChange, onError, anchorPositionMode = "comments-and-revisions", onAnonymizationTermClick, selectedAnonymizationCanonical = null, anonymizationSelectionSeq } = props;
3053
+ const { document, documentIO, documentIdentity, experimentalSession, fonts: hostFonts, styles, theme: _theme, sectionProperties, headerContent, footerContent, firstPageHeaderContent, firstPageFooterContent, headerContentRId, footerContentRId, firstPageHeaderContentRId, firstPageFooterContentRId, readOnly = false, pageGap = 24, zoom = 1, pageRenderer, markupView, showCommentHighlights = true, showMarginGuides = false, marginGuideColor, onDocumentChange, onReadOnlyEditAttempt, onCopy, onCut, onPaste, onSelectionChange, onSelectionTextChange, onEditorViewReady, externalPlugins = EMPTY_PLUGINS, showTemplateDirectives = true, collaboration, extensionManager, suggestionModeActive = false, suggestionAuthor, onActiveNoteStoryChange, onHeaderFooterDoubleClick, hfEditMode, activeHeaderFooterRId, onBodyClick, className, style, pageEndGutter = 0, sidebarOverlay, scrollContainerRef: scrollContainerRefProp, onHyperlinkClick, onContextMenu, onAnchorPositionsChange, onTotalPagesChange, onError, anchorPositionMode = "comments-and-revisions", onAnonymizationTermClick, selectedAnonymizationCanonical = null, anonymizationSelectionSeq } = props;
3048
3054
  const getScrollContainer = useCallback(() => {
3049
3055
  if (scrollContainerRefProp && typeof scrollContainerRefProp === "object") return getEditorScrollRoot(scrollContainerRefProp.current);
3050
3056
  return getEditorScrollRoot(containerRef.current);
@@ -3321,6 +3327,7 @@ const PagedEditor = forwardRef(function PagedEditor(props, ref) {
3321
3327
  const layoutInputSignature = useMemo(() => buildLayoutInputSignature({
3322
3328
  columns,
3323
3329
  markupView,
3330
+ showCommentHighlights,
3324
3331
  contentWidth,
3325
3332
  defaultTabStop,
3326
3333
  mirrorMargins,
@@ -3342,6 +3349,7 @@ const PagedEditor = forwardRef(function PagedEditor(props, ref) {
3342
3349
  }), [
3343
3350
  columns,
3344
3351
  markupView,
3352
+ showCommentHighlights,
3345
3353
  contentWidth,
3346
3354
  defaultTabStop,
3347
3355
  mirrorMargins,
@@ -3416,7 +3424,8 @@ const PagedEditor = forwardRef(function PagedEditor(props, ref) {
3416
3424
  emptyTemplatePreviewEntries: EMPTY_TEMPLATE_PREVIEW_ENTRIES,
3417
3425
  emptyTemplatePreviewHidden: EMPTY_TEMPLATE_PREVIEW_HIDDEN,
3418
3426
  hyphenationReadiness,
3419
- markupView
3427
+ markupView,
3428
+ showCommentHighlights
3420
3429
  }, state, options);
3421
3430
  if (outcome.blocks) setBlocks(outcome.blocks);
3422
3431
  if (outcome.measures !== void 0) setMeasures(outcome.measures);
@@ -3453,6 +3462,7 @@ const PagedEditor = forwardRef(function PagedEditor(props, ref) {
3453
3462
  mirrorMargins,
3454
3463
  styles,
3455
3464
  markupView,
3465
+ showCommentHighlights,
3456
3466
  layoutInputSignature,
3457
3467
  hyphenationReadiness
3458
3468
  ]);
@@ -5532,7 +5542,7 @@ const PagedEditor = forwardRef(function PagedEditor(props, ref) {
5532
5542
  setIsFocused(true);
5533
5543
  });
5534
5544
  };
5535
- if (layoutSessionRef.current.lastPmDoc?.eq(view_24.state.doc) && layoutSessionRef.current.lastMeasureInputs?.markupView === markupView) {
5545
+ if (layoutSessionRef.current.lastPmDoc?.eq(view_24.state.doc) && layoutSessionRef.current.lastMeasureInputs?.markupView === markupView && layoutSessionRef.current.lastMeasureInputs?.showCommentHighlights === (showCommentHighlights && markupView !== "no-markup" && markupView !== "original")) {
5536
5546
  const lastPreview = layoutSessionRef.current.lastTemplatePreview;
5537
5547
  if (templatePreviewRef.current.mode !== lastPreview.mode || templatePreviewDirtyRange(lastPreview, templatePreviewRef.current) !== null) runLayoutPipeline$1(view_24.state, { reason: "manual" });
5538
5548
  updateSelectionOverlay(view_24.state);
@@ -5573,7 +5583,8 @@ const PagedEditor = forwardRef(function PagedEditor(props, ref) {
5573
5583
  updateAutocompleteOverlay,
5574
5584
  readOnly,
5575
5585
  refreshBodyImeCaretAnchor,
5576
- markupView
5586
+ markupView,
5587
+ showCommentHighlights
5577
5588
  ]);
5578
5589
  const handleEditorViewDestroy = useCallback(() => {
5579
5590
  onEditorViewReadyRef.current?.(null);
@@ -5961,6 +5972,7 @@ const PagedEditor = forwardRef(function PagedEditor(props, ref) {
5961
5972
  /* @__PURE__ */ jsx(HiddenHeaderFooterPMs, {
5962
5973
  ref: hfPMsRef,
5963
5974
  document,
5975
+ readOnly,
5964
5976
  onTransaction: handleHfPmTransaction,
5965
5977
  getCanonicalApi,
5966
5978
  onSessionRefusal: handleSessionRefusal,
@@ -7519,12 +7531,6 @@ const readFindSelectionSeed = () => {
7519
7531
  return selection && !selection.isCollapsed ? selection.toString() : "";
7520
7532
  };
7521
7533
  //#endregion
7522
- //#region src/components/dialogs/findReplaceUtils.ts
7523
- const scrollToMatch = (containerElement, match) => {
7524
- if (!containerElement) return;
7525
- scrollEditorElementIntoView(containerElement.querySelector(`[data-paragraph-index="${match.paragraphIndex}"]`) ?? containerElement.querySelector(`.layout-paragraph[data-block-id="block-${match.paragraphIndex + 1}"]`) ?? containerElement.querySelectorAll(".layout-paragraph").item(match.paragraphIndex));
7526
- };
7527
- //#endregion
7528
7534
  //#region src/components/dialogs/useFindReplace.ts
7529
7535
  /**
7530
7536
  * useFindReplace Hook
@@ -8338,97 +8344,103 @@ function _temp$10(heading) {
8338
8344
  }
8339
8345
  //#endregion
8340
8346
  //#region src/components/DocxEditorDialogs.tsx
8341
- const FindReplaceDialog = lazy(() => import("./FindReplaceDialog-LlVMe3EW.js").then((n) => n.n).then((m) => ({ default: m.FindReplaceDialog })));
8342
- const TablePropertiesDialog = lazy(() => import("./TablePropertiesDialog-Vu0HXQz6.js").then((n) => n.n).then((m) => ({ default: m.TablePropertiesDialog })));
8343
- const ImagePositionDialog = lazy(() => import("./ImagePositionDialog-Cwt6R8iM.js").then((n) => n.n).then((m) => ({ default: m.ImagePositionDialog })));
8344
- const ImagePropertiesDialog = lazy(() => import("./ImagePropertiesDialog-GNZLBFLB.js").then((n) => n.n).then((m) => ({ default: m.ImagePropertiesDialog })));
8345
- const FootnotePropertiesDialog = lazy(() => import("./FootnotePropertiesDialog-D73t3LNP.js").then((n) => n.n).then((m) => ({ default: m.FootnotePropertiesDialog })));
8346
- const PageSetupDialog = lazy(() => import("./PageSetupDialog-DD6IEZAo.js").then((n) => n.n).then((m) => ({ default: m.PageSetupDialog })));
8347
- const SetNumberingValueDialog = lazy(() => import("./SetNumberingValueDialog-CDQGDvP1.js").then((m) => ({ default: m.SetNumberingValueDialog })));
8348
- const InsertSymbolDialog = lazy(() => import("./InsertSymbolDialog-CeEhkEvc.js").then((n) => n.n).then((m) => ({ default: m.InsertSymbolDialog })));
8347
+ const FindReplaceDialog = lazy(() => import("./FindReplaceDialog-C3njN6OI.js").then((n) => n.n).then((m) => ({ default: m.FindReplaceDialog })));
8348
+ const TablePropertiesDialog = lazy(() => import("./TablePropertiesDialog-uSTmyEcu.js").then((n) => n.n).then((m) => ({ default: m.TablePropertiesDialog })));
8349
+ const ImagePositionDialog = lazy(() => import("./ImagePositionDialog-Oap9knQ-.js").then((n) => n.n).then((m) => ({ default: m.ImagePositionDialog })));
8350
+ const ImagePropertiesDialog = lazy(() => import("./ImagePropertiesDialog-lLMKHv0u.js").then((n) => n.n).then((m) => ({ default: m.ImagePropertiesDialog })));
8351
+ const FootnotePropertiesDialog = lazy(() => import("./FootnotePropertiesDialog-BEs7N62_.js").then((n) => n.n).then((m) => ({ default: m.FootnotePropertiesDialog })));
8352
+ const PageSetupDialog = lazy(() => import("./PageSetupDialog-DTWCdPkX.js").then((n) => n.n).then((m) => ({ default: m.PageSetupDialog })));
8353
+ const SetNumberingValueDialog = lazy(() => import("./SetNumberingValueDialog-twVIZMLc.js").then((m) => ({ default: m.SetNumberingValueDialog })));
8354
+ const InsertSymbolDialog = lazy(() => import("./InsertSymbolDialog-Drm40-9j.js").then((n) => n.n).then((m) => ({ default: m.InsertSymbolDialog })));
8349
8355
  function DocxEditorDialogs(t0) {
8350
- const $ = c(52);
8356
+ const $ = c(55);
8351
8357
  const { findReplace, tableProperties, imagePosition, imageProperties, pageSetup, footnoteProperties, insertSymbol, setNumberingValue } = t0;
8352
8358
  let t1;
8353
- if ($[0] !== findReplace.currentResult || $[1] !== findReplace.onClose || $[2] !== findReplace.onFind || $[3] !== findReplace.onFindNext || $[4] !== findReplace.onFindPrevious || $[5] !== findReplace.onReplace || $[6] !== findReplace.onReplaceAll || $[7] !== findReplace.state.dialog.status || $[8] !== findReplace.state.searchText) {
8359
+ if ($[0] !== findReplace.currentSearch || $[1] !== findReplace.onClose || $[2] !== findReplace.onFind || $[3] !== findReplace.onFindNext || $[4] !== findReplace.onFindPrevious || $[5] !== findReplace.onQueryChange || $[6] !== findReplace.onReplace || $[7] !== findReplace.onReplaceAll || $[8] !== findReplace.readOnly || $[9] !== findReplace.state.dialog.mode || $[10] !== findReplace.state.dialog.status || $[11] !== findReplace.state.searchText) {
8354
8360
  t1 = findReplace.state.dialog.status === "open" && /* @__PURE__ */ jsx(FindReplaceDialog, {
8355
8361
  isOpen: true,
8356
8362
  onClose: findReplace.onClose,
8357
8363
  onFind: findReplace.onFind,
8364
+ onQueryChange: findReplace.onQueryChange,
8358
8365
  onFindNext: findReplace.onFindNext,
8359
8366
  onFindPrevious: findReplace.onFindPrevious,
8360
8367
  onReplace: findReplace.onReplace,
8361
8368
  onReplaceAll: findReplace.onReplaceAll,
8362
8369
  initialSearchText: findReplace.state.searchText,
8363
- currentResult: findReplace.currentResult
8370
+ currentSearch: findReplace.currentSearch,
8371
+ readOnly: findReplace.readOnly,
8372
+ replaceMode: findReplace.state.dialog.mode === "replace"
8364
8373
  });
8365
- $[0] = findReplace.currentResult;
8374
+ $[0] = findReplace.currentSearch;
8366
8375
  $[1] = findReplace.onClose;
8367
8376
  $[2] = findReplace.onFind;
8368
8377
  $[3] = findReplace.onFindNext;
8369
8378
  $[4] = findReplace.onFindPrevious;
8370
- $[5] = findReplace.onReplace;
8371
- $[6] = findReplace.onReplaceAll;
8372
- $[7] = findReplace.state.dialog.status;
8373
- $[8] = findReplace.state.searchText;
8374
- $[9] = t1;
8375
- } else t1 = $[9];
8379
+ $[5] = findReplace.onQueryChange;
8380
+ $[6] = findReplace.onReplace;
8381
+ $[7] = findReplace.onReplaceAll;
8382
+ $[8] = findReplace.readOnly;
8383
+ $[9] = findReplace.state.dialog.mode;
8384
+ $[10] = findReplace.state.dialog.status;
8385
+ $[11] = findReplace.state.searchText;
8386
+ $[12] = t1;
8387
+ } else t1 = $[12];
8376
8388
  let t2;
8377
- if ($[10] !== tableProperties.currentProps || $[11] !== tableProperties.isOpen || $[12] !== tableProperties.onApply || $[13] !== tableProperties.onClose) {
8389
+ if ($[13] !== tableProperties.currentProps || $[14] !== tableProperties.isOpen || $[15] !== tableProperties.onApply || $[16] !== tableProperties.onClose) {
8378
8390
  t2 = tableProperties.isOpen && /* @__PURE__ */ jsx(TablePropertiesDialog, {
8379
8391
  isOpen: tableProperties.isOpen,
8380
8392
  onClose: tableProperties.onClose,
8381
8393
  onApply: tableProperties.onApply,
8382
8394
  ...tableProperties.currentProps ? { currentProps: tableProperties.currentProps } : {}
8383
8395
  });
8384
- $[10] = tableProperties.currentProps;
8385
- $[11] = tableProperties.isOpen;
8386
- $[12] = tableProperties.onApply;
8387
- $[13] = tableProperties.onClose;
8388
- $[14] = t2;
8389
- } else t2 = $[14];
8396
+ $[13] = tableProperties.currentProps;
8397
+ $[14] = tableProperties.isOpen;
8398
+ $[15] = tableProperties.onApply;
8399
+ $[16] = tableProperties.onClose;
8400
+ $[17] = t2;
8401
+ } else t2 = $[17];
8390
8402
  let t3;
8391
- if ($[15] !== imagePosition.isOpen || $[16] !== imagePosition.onApply || $[17] !== imagePosition.onClose) {
8403
+ if ($[18] !== imagePosition.isOpen || $[19] !== imagePosition.onApply || $[20] !== imagePosition.onClose) {
8392
8404
  t3 = imagePosition.isOpen && /* @__PURE__ */ jsx(ImagePositionDialog, {
8393
8405
  isOpen: imagePosition.isOpen,
8394
8406
  onClose: imagePosition.onClose,
8395
8407
  onApply: imagePosition.onApply
8396
8408
  });
8397
- $[15] = imagePosition.isOpen;
8398
- $[16] = imagePosition.onApply;
8399
- $[17] = imagePosition.onClose;
8400
- $[18] = t3;
8401
- } else t3 = $[18];
8409
+ $[18] = imagePosition.isOpen;
8410
+ $[19] = imagePosition.onApply;
8411
+ $[20] = imagePosition.onClose;
8412
+ $[21] = t3;
8413
+ } else t3 = $[21];
8402
8414
  let t4;
8403
- if ($[19] !== imageProperties.currentData || $[20] !== imageProperties.isOpen || $[21] !== imageProperties.onApply || $[22] !== imageProperties.onClose) {
8415
+ if ($[22] !== imageProperties.currentData || $[23] !== imageProperties.isOpen || $[24] !== imageProperties.onApply || $[25] !== imageProperties.onClose) {
8404
8416
  t4 = imageProperties.isOpen && /* @__PURE__ */ jsx(ImagePropertiesDialog, {
8405
8417
  isOpen: imageProperties.isOpen,
8406
8418
  onClose: imageProperties.onClose,
8407
8419
  onApply: imageProperties.onApply,
8408
8420
  ...imageProperties.currentData ? { currentData: imageProperties.currentData } : {}
8409
8421
  });
8410
- $[19] = imageProperties.currentData;
8411
- $[20] = imageProperties.isOpen;
8412
- $[21] = imageProperties.onApply;
8413
- $[22] = imageProperties.onClose;
8414
- $[23] = t4;
8415
- } else t4 = $[23];
8422
+ $[22] = imageProperties.currentData;
8423
+ $[23] = imageProperties.isOpen;
8424
+ $[24] = imageProperties.onApply;
8425
+ $[25] = imageProperties.onClose;
8426
+ $[26] = t4;
8427
+ } else t4 = $[26];
8416
8428
  let t5;
8417
- if ($[24] !== pageSetup.currentProps || $[25] !== pageSetup.isOpen || $[26] !== pageSetup.onApply || $[27] !== pageSetup.onClose) {
8429
+ if ($[27] !== pageSetup.currentProps || $[28] !== pageSetup.isOpen || $[29] !== pageSetup.onApply || $[30] !== pageSetup.onClose) {
8418
8430
  t5 = pageSetup.isOpen && /* @__PURE__ */ jsx(PageSetupDialog, {
8419
8431
  isOpen: pageSetup.isOpen,
8420
8432
  onClose: pageSetup.onClose,
8421
8433
  onApply: pageSetup.onApply,
8422
8434
  ...pageSetup.currentProps ? { currentProps: pageSetup.currentProps } : {}
8423
8435
  });
8424
- $[24] = pageSetup.currentProps;
8425
- $[25] = pageSetup.isOpen;
8426
- $[26] = pageSetup.onApply;
8427
- $[27] = pageSetup.onClose;
8428
- $[28] = t5;
8429
- } else t5 = $[28];
8436
+ $[27] = pageSetup.currentProps;
8437
+ $[28] = pageSetup.isOpen;
8438
+ $[29] = pageSetup.onApply;
8439
+ $[30] = pageSetup.onClose;
8440
+ $[31] = t5;
8441
+ } else t5 = $[31];
8430
8442
  let t6;
8431
- if ($[29] !== footnoteProperties.endnotePr || $[30] !== footnoteProperties.footnotePr || $[31] !== footnoteProperties.isOpen || $[32] !== footnoteProperties.onApply || $[33] !== footnoteProperties.onClose) {
8443
+ if ($[32] !== footnoteProperties.endnotePr || $[33] !== footnoteProperties.footnotePr || $[34] !== footnoteProperties.isOpen || $[35] !== footnoteProperties.onApply || $[36] !== footnoteProperties.onClose) {
8432
8444
  t6 = footnoteProperties.isOpen && /* @__PURE__ */ jsx(FootnotePropertiesDialog, {
8433
8445
  isOpen: footnoteProperties.isOpen,
8434
8446
  onClose: footnoteProperties.onClose,
@@ -8436,39 +8448,39 @@ function DocxEditorDialogs(t0) {
8436
8448
  ...footnoteProperties.footnotePr ? { footnotePr: footnoteProperties.footnotePr } : {},
8437
8449
  ...footnoteProperties.endnotePr ? { endnotePr: footnoteProperties.endnotePr } : {}
8438
8450
  });
8439
- $[29] = footnoteProperties.endnotePr;
8440
- $[30] = footnoteProperties.footnotePr;
8441
- $[31] = footnoteProperties.isOpen;
8442
- $[32] = footnoteProperties.onApply;
8443
- $[33] = footnoteProperties.onClose;
8444
- $[34] = t6;
8445
- } else t6 = $[34];
8451
+ $[32] = footnoteProperties.endnotePr;
8452
+ $[33] = footnoteProperties.footnotePr;
8453
+ $[34] = footnoteProperties.isOpen;
8454
+ $[35] = footnoteProperties.onApply;
8455
+ $[36] = footnoteProperties.onClose;
8456
+ $[37] = t6;
8457
+ } else t6 = $[37];
8446
8458
  let t7;
8447
- if ($[35] !== insertSymbol.isOpen || $[36] !== insertSymbol.onClose || $[37] !== insertSymbol.onInsert) {
8459
+ if ($[38] !== insertSymbol.isOpen || $[39] !== insertSymbol.onClose || $[40] !== insertSymbol.onInsert) {
8448
8460
  t7 = insertSymbol.isOpen && /* @__PURE__ */ jsx(InsertSymbolDialog, {
8449
8461
  isOpen: insertSymbol.isOpen,
8450
8462
  onClose: insertSymbol.onClose,
8451
8463
  onInsert: insertSymbol.onInsert
8452
8464
  });
8453
- $[35] = insertSymbol.isOpen;
8454
- $[36] = insertSymbol.onClose;
8455
- $[37] = insertSymbol.onInsert;
8456
- $[38] = t7;
8457
- } else t7 = $[38];
8465
+ $[38] = insertSymbol.isOpen;
8466
+ $[39] = insertSymbol.onClose;
8467
+ $[40] = insertSymbol.onInsert;
8468
+ $[41] = t7;
8469
+ } else t7 = $[41];
8458
8470
  let t8;
8459
- if ($[39] !== setNumberingValue.isOpen || $[40] !== setNumberingValue.onApply || $[41] !== setNumberingValue.onClose) {
8471
+ if ($[42] !== setNumberingValue.isOpen || $[43] !== setNumberingValue.onApply || $[44] !== setNumberingValue.onClose) {
8460
8472
  t8 = setNumberingValue.isOpen && /* @__PURE__ */ jsx(SetNumberingValueDialog, {
8461
8473
  isOpen: setNumberingValue.isOpen,
8462
8474
  onClose: setNumberingValue.onClose,
8463
8475
  onApply: setNumberingValue.onApply
8464
8476
  });
8465
- $[39] = setNumberingValue.isOpen;
8466
- $[40] = setNumberingValue.onApply;
8467
- $[41] = setNumberingValue.onClose;
8468
- $[42] = t8;
8469
- } else t8 = $[42];
8477
+ $[42] = setNumberingValue.isOpen;
8478
+ $[43] = setNumberingValue.onApply;
8479
+ $[44] = setNumberingValue.onClose;
8480
+ $[45] = t8;
8481
+ } else t8 = $[45];
8470
8482
  let t9;
8471
- if ($[43] !== t1 || $[44] !== t2 || $[45] !== t3 || $[46] !== t4 || $[47] !== t5 || $[48] !== t6 || $[49] !== t7 || $[50] !== t8) {
8483
+ if ($[46] !== t1 || $[47] !== t2 || $[48] !== t3 || $[49] !== t4 || $[50] !== t5 || $[51] !== t6 || $[52] !== t7 || $[53] !== t8) {
8472
8484
  t9 = /* @__PURE__ */ jsxs(Suspense, {
8473
8485
  fallback: null,
8474
8486
  children: [
@@ -8482,16 +8494,16 @@ function DocxEditorDialogs(t0) {
8482
8494
  t8
8483
8495
  ]
8484
8496
  });
8485
- $[43] = t1;
8486
- $[44] = t2;
8487
- $[45] = t3;
8488
- $[46] = t4;
8489
- $[47] = t5;
8490
- $[48] = t6;
8491
- $[49] = t7;
8492
- $[50] = t8;
8493
- $[51] = t9;
8494
- } else t9 = $[51];
8497
+ $[46] = t1;
8498
+ $[47] = t2;
8499
+ $[48] = t3;
8500
+ $[49] = t4;
8501
+ $[50] = t5;
8502
+ $[51] = t6;
8503
+ $[52] = t7;
8504
+ $[53] = t8;
8505
+ $[54] = t9;
8506
+ } else t9 = $[54];
8495
8507
  return t9;
8496
8508
  }
8497
8509
  //#endregion
@@ -10785,8 +10797,8 @@ const useDocumentLoader = (t0) => {
10785
10797
  * editing mode does not switch the display mode.
10786
10798
  */
10787
10799
  function useEditorMode(t0) {
10788
- const $ = c(24);
10789
- const { modeProp, onModeChange, readOnlyProp } = t0;
10800
+ const $ = c(28);
10801
+ const { modeProp, onModeChange, readOnlyProp, reviewDisplayMode } = t0;
10790
10802
  let t1;
10791
10803
  if ($[0] !== modeProp) {
10792
10804
  t1 = () => new EditorModeManager(modeProp ?? "editing");
@@ -10808,60 +10820,75 @@ function useEditorMode(t0) {
10808
10820
  $[5] = t2;
10809
10821
  } else t2 = $[5];
10810
10822
  const setEditingMode = t2;
10823
+ let effectiveDisplayMode;
10811
10824
  let t3;
10812
- if ($[6] !== editingMode || $[7] !== readOnlyProp) {
10813
- t3 = isReadOnlyMode(editingMode, readOnlyProp);
10814
- $[6] = editingMode;
10815
- $[7] = readOnlyProp;
10816
- $[8] = t3;
10817
- } else t3 = $[8];
10818
- const readOnly = t3;
10825
+ if ($[6] !== displayMode || $[7] !== editingMode || $[8] !== readOnlyProp || $[9] !== reviewDisplayMode) {
10826
+ effectiveDisplayMode = reviewDisplayMode === void 0 ? displayMode : reviewDisplayModeToDisplayMode(reviewDisplayMode);
10827
+ t3 = getEditorReadOnlyReason({
10828
+ editingMode,
10829
+ readOnlyProp,
10830
+ displayMode: effectiveDisplayMode
10831
+ });
10832
+ $[6] = displayMode;
10833
+ $[7] = editingMode;
10834
+ $[8] = readOnlyProp;
10835
+ $[9] = reviewDisplayMode;
10836
+ $[10] = effectiveDisplayMode;
10837
+ $[11] = t3;
10838
+ } else {
10839
+ effectiveDisplayMode = $[10];
10840
+ t3 = $[11];
10841
+ }
10842
+ const readOnlyReason = t3;
10843
+ const readOnly = readOnlyReason !== null;
10819
10844
  let t4;
10820
- if ($[9] !== editingMode) {
10845
+ if ($[12] !== editingMode) {
10821
10846
  t4 = isTrackChangesMode(editingMode);
10822
- $[9] = editingMode;
10823
- $[10] = t4;
10824
- } else t4 = $[10];
10847
+ $[12] = editingMode;
10848
+ $[13] = t4;
10849
+ } else t4 = $[13];
10825
10850
  const trackChangesOn = t4;
10826
10851
  let t5;
10827
- if ($[11] !== editingMode || $[12] !== setEditingMode) {
10852
+ if ($[14] !== editingMode || $[15] !== setEditingMode) {
10828
10853
  t5 = () => {
10829
10854
  setEditingMode(toggledTrackChangesMode(editingMode));
10830
10855
  };
10831
- $[11] = editingMode;
10832
- $[12] = setEditingMode;
10833
- $[13] = t5;
10834
- } else t5 = $[13];
10856
+ $[14] = editingMode;
10857
+ $[15] = setEditingMode;
10858
+ $[16] = t5;
10859
+ } else t5 = $[16];
10835
10860
  const toggleTrackChanges = t5;
10836
10861
  let t6;
10837
- if ($[14] !== manager) {
10862
+ if ($[17] !== manager) {
10838
10863
  t6 = (mode_0) => {
10839
10864
  manager.setDisplayMode(mode_0);
10840
10865
  };
10841
- $[14] = manager;
10842
- $[15] = t6;
10843
- } else t6 = $[15];
10866
+ $[17] = manager;
10867
+ $[18] = t6;
10868
+ } else t6 = $[18];
10844
10869
  const setDisplayMode = t6;
10845
10870
  let t7;
10846
- if ($[16] !== displayMode || $[17] !== editingMode || $[18] !== readOnly || $[19] !== setDisplayMode || $[20] !== setEditingMode || $[21] !== toggleTrackChanges || $[22] !== trackChangesOn) {
10871
+ if ($[19] !== editingMode || $[20] !== effectiveDisplayMode || $[21] !== readOnly || $[22] !== readOnlyReason || $[23] !== setDisplayMode || $[24] !== setEditingMode || $[25] !== toggleTrackChanges || $[26] !== trackChangesOn) {
10847
10872
  t7 = {
10848
10873
  editingMode,
10849
10874
  setEditingMode,
10850
10875
  readOnly,
10876
+ readOnlyReason,
10851
10877
  trackChangesOn,
10852
10878
  toggleTrackChanges,
10853
- displayMode,
10879
+ displayMode: effectiveDisplayMode,
10854
10880
  setDisplayMode
10855
10881
  };
10856
- $[16] = displayMode;
10857
- $[17] = editingMode;
10858
- $[18] = readOnly;
10859
- $[19] = setDisplayMode;
10860
- $[20] = setEditingMode;
10861
- $[21] = toggleTrackChanges;
10862
- $[22] = trackChangesOn;
10863
- $[23] = t7;
10864
- } else t7 = $[23];
10882
+ $[19] = editingMode;
10883
+ $[20] = effectiveDisplayMode;
10884
+ $[21] = readOnly;
10885
+ $[22] = readOnlyReason;
10886
+ $[23] = setDisplayMode;
10887
+ $[24] = setEditingMode;
10888
+ $[25] = toggleTrackChanges;
10889
+ $[26] = trackChangesOn;
10890
+ $[27] = t7;
10891
+ } else t7 = $[27];
10865
10892
  return t7;
10866
10893
  }
10867
10894
  //#endregion
@@ -10880,151 +10907,492 @@ function useEditorMode(t0) {
10880
10907
  * operations (find, replace, scroll-to-match) on top.
10881
10908
  */
10882
10909
  function useFindReplace(t0) {
10883
- const $ = c(35);
10884
- const { documentState, getDocumentState, containerRef, handleDocumentChange, findReplace, selectMatch } = t0;
10910
+ const $ = c(89);
10911
+ const { documentState, getDocumentState, getEditorState, containerRef, handleDocumentChange, findReplace, selectMatch, getBodyDoc, getLayout, displayMode, onFindResultChange, readOnlyReason, onReadonlyEditAttempt } = t0;
10885
10912
  let t1;
10886
- if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
10887
- t1 = new FindReplaceManager();
10888
- $[0] = t1;
10889
- } else t1 = $[0];
10890
- const manager = t1;
10891
- const [currentResult, setCurrentResult] = useState(null);
10892
- const { setMatches, goToMatch } = findReplace;
10913
+ if ($[0] !== displayMode || $[1] !== readOnlyReason) {
10914
+ t1 = getReviewViewReadOnlyReason(displayMode ?? "all-markup") ?? readOnlyReason ?? null;
10915
+ $[0] = displayMode;
10916
+ $[1] = readOnlyReason;
10917
+ $[2] = t1;
10918
+ } else t1 = $[2];
10919
+ const replacementRefusal = t1;
10893
10920
  let t2;
10894
- if ($[1] !== setMatches) {
10895
- t2 = () => {
10921
+ if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
10922
+ t2 = new FindReplaceManager();
10923
+ $[3] = t2;
10924
+ } else t2 = $[3];
10925
+ const manager = t2;
10926
+ let t3;
10927
+ if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
10928
+ t3 = { status: "cleared" };
10929
+ $[4] = t3;
10930
+ } else t3 = $[4];
10931
+ const [publishedResult, setPublishedResult] = useState(t3);
10932
+ const { setMatches, goToMatch } = findReplace;
10933
+ const matchView = useRef(null);
10934
+ const query = useRef(null);
10935
+ const searchSource = useRef(null);
10936
+ let t4;
10937
+ if ($[5] === Symbol.for("react.memo_cache_sentinel")) {
10938
+ t4 = { status: "ready" };
10939
+ $[5] = t4;
10940
+ } else t4 = $[5];
10941
+ const replacementGate = useRef(t4);
10942
+ const resultCallback = useRef(onFindResultChange);
10943
+ let t5;
10944
+ let t6;
10945
+ if ($[6] !== onFindResultChange) {
10946
+ t5 = () => {
10947
+ resultCallback.current = onFindResultChange;
10948
+ };
10949
+ t6 = [onFindResultChange];
10950
+ $[6] = onFindResultChange;
10951
+ $[7] = t5;
10952
+ $[8] = t6;
10953
+ } else {
10954
+ t5 = $[7];
10955
+ t6 = $[8];
10956
+ }
10957
+ useEffect(t5, t6);
10958
+ let t7;
10959
+ if ($[9] === Symbol.for("react.memo_cache_sentinel")) {
10960
+ t7 = (result) => {
10961
+ if (result) {
10962
+ const source = searchSource.current;
10963
+ if (!source) panic("Find result published without a search key");
10964
+ setPublishedResult({
10965
+ status: "ready",
10966
+ queryKey: source.intentKey,
10967
+ result
10968
+ });
10969
+ } else setPublishedResult({ status: "cleared" });
10970
+ resultCallback.current?.(result);
10971
+ };
10972
+ $[9] = t7;
10973
+ } else t7 = $[9];
10974
+ const publish = t7;
10975
+ let t8;
10976
+ let t9;
10977
+ if ($[10] === Symbol.for("react.memo_cache_sentinel")) {
10978
+ t8 = () => () => matchView.current?.destroy();
10979
+ t9 = [];
10980
+ $[10] = t8;
10981
+ $[11] = t9;
10982
+ } else {
10983
+ t8 = $[10];
10984
+ t9 = $[11];
10985
+ }
10986
+ useEffect(t8, t9);
10987
+ let t10;
10988
+ if ($[12] !== setMatches) {
10989
+ t10 = () => {
10896
10990
  manager.clear();
10897
- setCurrentResult(null);
10991
+ searchSource.current = null;
10992
+ matchView.current?.destroy();
10993
+ matchView.current = null;
10994
+ publish(null);
10898
10995
  setMatches([], 0);
10899
10996
  };
10900
- $[1] = setMatches;
10901
- $[2] = t2;
10902
- } else t2 = $[2];
10903
- const resetFindResult = t2;
10904
- let t3;
10905
- if ($[3] !== documentState || $[4] !== getDocumentState) {
10906
- t3 = () => getDocumentState?.() ?? documentState ?? null;
10907
- $[3] = documentState;
10908
- $[4] = getDocumentState;
10909
- $[5] = t3;
10910
- } else t3 = $[5];
10911
- const readDocumentState = t3;
10912
- let t4;
10913
- if ($[6] !== containerRef || $[7] !== selectMatch) {
10914
- t4 = (match) => {
10915
- if (!selectMatch?.(match) && containerRef.current) scrollToMatch(containerRef.current, match);
10997
+ $[12] = setMatches;
10998
+ $[13] = t10;
10999
+ } else t10 = $[13];
11000
+ const clearFindResult = t10;
11001
+ let t11;
11002
+ if ($[14] !== clearFindResult) {
11003
+ t11 = () => {
11004
+ query.current = null;
11005
+ clearFindResult();
10916
11006
  };
10917
- $[6] = containerRef;
10918
- $[7] = selectMatch;
10919
- $[8] = t4;
10920
- } else t4 = $[8];
10921
- const revealMatch = t4;
10922
- let t5;
10923
- if ($[9] !== readDocumentState || $[10] !== resetFindResult || $[11] !== revealMatch || $[12] !== setMatches) {
10924
- t5 = (searchText, options) => {
10925
- const currentDocument = readDocumentState();
10926
- if (!currentDocument || !searchText.trim()) {
11007
+ $[14] = clearFindResult;
11008
+ $[15] = t11;
11009
+ } else t11 = $[15];
11010
+ const resetFindResult = t11;
11011
+ let t12;
11012
+ if ($[16] !== documentState || $[17] !== getDocumentState) {
11013
+ t12 = () => getDocumentState?.() ?? documentState ?? null;
11014
+ $[16] = documentState;
11015
+ $[17] = getDocumentState;
11016
+ $[18] = t12;
11017
+ } else t12 = $[18];
11018
+ const readDocumentState = t12;
11019
+ let t13;
11020
+ if ($[19] !== getEditorState) {
11021
+ t13 = (currentDocument, searchText, options, context) => findInDisplayedDocument({
11022
+ document: currentDocument,
11023
+ ...getEditorState && { state: getEditorState() },
11024
+ searchText,
11025
+ options,
11026
+ context
11027
+ });
11028
+ $[19] = getEditorState;
11029
+ $[20] = t13;
11030
+ } else t13 = $[20];
11031
+ const findDisplayedMatches = t13;
11032
+ let t14;
11033
+ if ($[21] !== selectMatch) {
11034
+ t14 = (match) => {
11035
+ const index = manager.getResult()?.currentIndex ?? 0;
11036
+ matchView.current?.navigate(index, () => selectMatch?.(match));
11037
+ };
11038
+ $[21] = selectMatch;
11039
+ $[22] = t14;
11040
+ } else t14 = $[22];
11041
+ const revealMatch = t14;
11042
+ let t15;
11043
+ if ($[23] === Symbol.for("react.memo_cache_sentinel")) {
11044
+ t15 = (text, options_0) => {
11045
+ query.current = {
11046
+ text,
11047
+ options: options_0
11048
+ };
11049
+ };
11050
+ $[23] = t15;
11051
+ } else t15 = $[23];
11052
+ const handleQueryChange = t15;
11053
+ let t16;
11054
+ if ($[24] !== clearFindResult || $[25] !== containerRef || $[26] !== displayMode || $[27] !== findDisplayedMatches || $[28] !== getBodyDoc || $[29] !== getLayout || $[30] !== readDocumentState || $[31] !== resetFindResult || $[32] !== revealMatch || $[33] !== setMatches) {
11055
+ t16 = (searchText_0, options_1) => {
11056
+ const currentDocument_0 = readDocumentState();
11057
+ if (!currentDocument_0 || !searchText_0.trim()) {
10927
11058
  resetFindResult();
10928
11059
  return null;
10929
11060
  }
10930
- const matches = findInDocument(currentDocument, searchText, options);
10931
- const result = manager.setMatches(matches);
10932
- setCurrentResult(result);
10933
- setMatches(matches, 0);
10934
- if (matches.length > 0) revealMatch(matches[0]);
10935
- return result;
11061
+ const bodyDoc = getBodyDoc?.();
11062
+ const effectiveOptions = {
11063
+ ...options_1,
11064
+ includeComments: true,
11065
+ ...displayMode && { displayMode }
11066
+ };
11067
+ const context_0 = getLayout ? { renderedStories: getRenderedSearchStories(getLayout()) } : void 0;
11068
+ const matches = findDisplayedMatches(currentDocument_0, searchText_0, effectiveOptions, context_0);
11069
+ if (matches === null) {
11070
+ query.current = {
11071
+ text: searchText_0,
11072
+ options: options_1
11073
+ };
11074
+ clearFindResult();
11075
+ return null;
11076
+ }
11077
+ const nextSource = createFindSearchKey({
11078
+ query: searchText_0,
11079
+ options: effectiveOptions,
11080
+ document: currentDocument_0,
11081
+ ...bodyDoc && { bodyVersion: bodyDoc },
11082
+ ...context_0 && { context: context_0 }
11083
+ });
11084
+ const refresh = searchSource.current?.query === nextSource.query;
11085
+ const currentIndex = refresh ? manager.getResult()?.currentIndex ?? 0 : 0;
11086
+ query.current = {
11087
+ text: searchText_0,
11088
+ options: options_1
11089
+ };
11090
+ searchSource.current = {
11091
+ ...nextSource,
11092
+ intentKey: createFindQueryKey(searchText_0, options_1)
11093
+ };
11094
+ const result_0 = manager.setMatches(matches, currentIndex);
11095
+ matchView.current?.destroy();
11096
+ const container = containerRef.current;
11097
+ matchView.current = container ? createFindMatchView({
11098
+ container,
11099
+ document: currentDocument_0,
11100
+ bodyDoc,
11101
+ matches,
11102
+ layout: getLayout?.()
11103
+ }) : null;
11104
+ publish(result_0);
11105
+ setMatches(matches, result_0.currentIndex);
11106
+ matchView.current?.paint(result_0.currentIndex);
11107
+ if (matches.length > 0 && !refresh) revealMatch(matches[0]);
11108
+ return result_0;
10936
11109
  };
10937
- $[9] = readDocumentState;
10938
- $[10] = resetFindResult;
10939
- $[11] = revealMatch;
10940
- $[12] = setMatches;
10941
- $[13] = t5;
10942
- } else t5 = $[13];
10943
- const handleFind = t5;
10944
- let t6;
10945
- if ($[14] !== goToMatch || $[15] !== revealMatch) {
10946
- t6 = () => {
11110
+ $[24] = clearFindResult;
11111
+ $[25] = containerRef;
11112
+ $[26] = displayMode;
11113
+ $[27] = findDisplayedMatches;
11114
+ $[28] = getBodyDoc;
11115
+ $[29] = getLayout;
11116
+ $[30] = readDocumentState;
11117
+ $[31] = resetFindResult;
11118
+ $[32] = revealMatch;
11119
+ $[33] = setMatches;
11120
+ $[34] = t16;
11121
+ } else t16 = $[34];
11122
+ const handleFind = t16;
11123
+ let t17;
11124
+ let t18;
11125
+ if ($[35] !== handleFind) {
11126
+ t17 = () => {
11127
+ if (!query.current) return;
11128
+ const timer = setTimeout(() => {
11129
+ const active = query.current;
11130
+ if (active) handleFind(active.text, active.options);
11131
+ }, 200);
11132
+ return () => clearTimeout(timer);
11133
+ };
11134
+ t18 = [handleFind];
11135
+ $[35] = handleFind;
11136
+ $[36] = t17;
11137
+ $[37] = t18;
11138
+ } else {
11139
+ t17 = $[36];
11140
+ t18 = $[37];
11141
+ }
11142
+ useEffect(t17, t18);
11143
+ const previousDisplayMode = useRef(displayMode);
11144
+ let t19;
11145
+ let t20;
11146
+ if ($[38] !== displayMode || $[39] !== handleFind) {
11147
+ t19 = () => {
11148
+ if (previousDisplayMode.current === displayMode) return;
11149
+ previousDisplayMode.current = displayMode;
11150
+ const active_0 = query.current;
11151
+ if (active_0) handleFind(active_0.text, active_0.options);
11152
+ };
11153
+ t20 = [displayMode, handleFind];
11154
+ $[38] = displayMode;
11155
+ $[39] = handleFind;
11156
+ $[40] = t19;
11157
+ $[41] = t20;
11158
+ } else {
11159
+ t19 = $[40];
11160
+ t20 = $[41];
11161
+ }
11162
+ useEffect(t19, t20);
11163
+ let t21;
11164
+ if ($[42] !== goToMatch || $[43] !== revealMatch) {
11165
+ t21 = () => {
10947
11166
  const stepped = manager.navigate("next");
10948
11167
  if (!stepped) return null;
10949
- setCurrentResult(manager.getResult());
11168
+ publish(manager.getResult());
10950
11169
  goToMatch(stepped.index);
10951
11170
  revealMatch(stepped.match);
10952
11171
  return stepped.match;
10953
11172
  };
10954
- $[14] = goToMatch;
10955
- $[15] = revealMatch;
10956
- $[16] = t6;
10957
- } else t6 = $[16];
10958
- const handleFindNext = t6;
10959
- let t7;
10960
- if ($[17] !== goToMatch || $[18] !== revealMatch) {
10961
- t7 = () => {
11173
+ $[42] = goToMatch;
11174
+ $[43] = revealMatch;
11175
+ $[44] = t21;
11176
+ } else t21 = $[44];
11177
+ const handleFindNext = t21;
11178
+ let t22;
11179
+ if ($[45] !== goToMatch || $[46] !== revealMatch) {
11180
+ t22 = () => {
10962
11181
  const stepped_0 = manager.navigate("previous");
10963
11182
  if (!stepped_0) return null;
10964
- setCurrentResult(manager.getResult());
11183
+ publish(manager.getResult());
10965
11184
  goToMatch(stepped_0.index);
10966
11185
  revealMatch(stepped_0.match);
10967
11186
  return stepped_0.match;
10968
11187
  };
10969
- $[17] = goToMatch;
10970
- $[18] = revealMatch;
10971
- $[19] = t7;
10972
- } else t7 = $[19];
10973
- const handleFindPrevious = t7;
10974
- let t8;
10975
- if ($[20] !== handleDocumentChange || $[21] !== readDocumentState) {
10976
- t8 = (replaceText) => {
10977
- const currentDocument_0 = readDocumentState();
10978
- if (!currentDocument_0) return false;
10979
- const newDoc = manager.replaceCurrent(currentDocument_0, replaceText);
11188
+ $[45] = goToMatch;
11189
+ $[46] = revealMatch;
11190
+ $[47] = t22;
11191
+ } else t22 = $[47];
11192
+ const handleFindPrevious = t22;
11193
+ let t23;
11194
+ if ($[48] !== displayMode || $[49] !== getBodyDoc || $[50] !== getLayout || $[51] !== handleFind) {
11195
+ t23 = (currentDocument_1) => {
11196
+ const active_1 = query.current;
11197
+ if (!active_1) return false;
11198
+ const bodyDoc_0 = getBodyDoc?.();
11199
+ const context_1 = getLayout ? { renderedStories: getRenderedSearchStories(getLayout()) } : void 0;
11200
+ const currentSource = createFindSearchKey({
11201
+ query: active_1.text,
11202
+ options: {
11203
+ ...active_1.options,
11204
+ includeComments: true,
11205
+ ...displayMode && { displayMode }
11206
+ },
11207
+ document: currentDocument_1,
11208
+ ...bodyDoc_0 && { bodyVersion: bodyDoc_0 },
11209
+ ...context_1 && { context: context_1 }
11210
+ });
11211
+ bb215: switch (replacementGate.current.status) {
11212
+ case "awaiting-document":
11213
+ if (sameFindBodyVersion(replacementGate.current.source, currentSource)) return true;
11214
+ replacementGate.current = { status: "ready" };
11215
+ break bb215;
11216
+ case "ready": break bb215;
11217
+ default: return replacementGate.current;
11218
+ }
11219
+ if (sameFindSearchKey(searchSource.current, currentSource)) return false;
11220
+ handleFind(active_1.text, active_1.options);
11221
+ return true;
11222
+ };
11223
+ $[48] = displayMode;
11224
+ $[49] = getBodyDoc;
11225
+ $[50] = getLayout;
11226
+ $[51] = handleFind;
11227
+ $[52] = t23;
11228
+ } else t23 = $[52];
11229
+ const refreshChangedSource = t23;
11230
+ let t24;
11231
+ if ($[53] !== clearFindResult || $[54] !== handleDocumentChange) {
11232
+ t24 = (nextDocument) => {
11233
+ const source_0 = searchSource.current;
11234
+ if (!source_0) panic("Replacement accepted without a search key");
11235
+ replacementGate.current = {
11236
+ status: "awaiting-document",
11237
+ source: source_0
11238
+ };
11239
+ clearFindResult();
11240
+ handleDocumentChange(nextDocument);
11241
+ };
11242
+ $[53] = clearFindResult;
11243
+ $[54] = handleDocumentChange;
11244
+ $[55] = t24;
11245
+ } else t24 = $[55];
11246
+ const acceptReplacement = t24;
11247
+ let t25;
11248
+ if ($[56] !== acceptReplacement || $[57] !== readDocumentState || $[58] !== refreshChangedSource) {
11249
+ t25 = (replaceText) => {
11250
+ const currentDocument_2 = readDocumentState();
11251
+ if (!currentDocument_2) return false;
11252
+ if (refreshChangedSource(currentDocument_2)) return false;
11253
+ const result_1 = manager.getResult();
11254
+ const match_0 = result_1?.matches.at(result_1.currentIndex);
11255
+ if (!match_0 || replaceEligibility(match_0).status === "blocked") return false;
11256
+ if (match_0.text === replaceText) return true;
11257
+ const newDoc = manager.replaceCurrent(currentDocument_2, replaceText);
10980
11258
  if (!newDoc) return false;
10981
- handleDocumentChange(newDoc);
11259
+ acceptReplacement(newDoc);
10982
11260
  return true;
10983
11261
  };
10984
- $[20] = handleDocumentChange;
10985
- $[21] = readDocumentState;
10986
- $[22] = t8;
10987
- } else t8 = $[22];
10988
- const handleReplace = t8;
10989
- let t9;
10990
- if ($[23] !== handleDocumentChange || $[24] !== readDocumentState || $[25] !== resetFindResult) {
10991
- t9 = (searchText_0, replaceText_0, options_0) => {
10992
- const currentDocument_1 = readDocumentState();
10993
- if (!currentDocument_1 || !searchText_0.trim()) return 0;
10994
- const matches_0 = findInDocument(currentDocument_1, searchText_0, options_0);
10995
- const outcome = manager.replaceAll(currentDocument_1, matches_0, replaceText_0);
10996
- if (!outcome) return 0;
10997
- handleDocumentChange(outcome.document);
10998
- resetFindResult();
10999
- return outcome.replacedCount;
11262
+ $[56] = acceptReplacement;
11263
+ $[57] = readDocumentState;
11264
+ $[58] = refreshChangedSource;
11265
+ $[59] = t25;
11266
+ } else t25 = $[59];
11267
+ const handleReplace = t25;
11268
+ let t26;
11269
+ if ($[60] !== acceptReplacement || $[61] !== displayMode || $[62] !== findDisplayedMatches || $[63] !== getLayout || $[64] !== readDocumentState || $[65] !== refreshChangedSource) {
11270
+ t26 = (searchText_1, replaceText_0, options_2) => {
11271
+ const currentDocument_3 = readDocumentState();
11272
+ if (!currentDocument_3 || !searchText_1.trim()) return {
11273
+ replacedCount: 0,
11274
+ skippedCount: 0
11275
+ };
11276
+ const previousCount = manager.getResult()?.matches.length ?? 0;
11277
+ handleQueryChange(searchText_1, options_2);
11278
+ if (refreshChangedSource(currentDocument_3)) return {
11279
+ replacedCount: 0,
11280
+ skippedCount: previousCount
11281
+ };
11282
+ const matches_0 = findDisplayedMatches(currentDocument_3, searchText_1, {
11283
+ ...options_2,
11284
+ includeComments: true,
11285
+ ...displayMode && { displayMode }
11286
+ }, getLayout ? { renderedStories: getRenderedSearchStories(getLayout()) } : void 0);
11287
+ if (matches_0 === null) return {
11288
+ replacedCount: 0,
11289
+ skippedCount: previousCount
11290
+ };
11291
+ const mutationMatches = matches_0.filter((match_1) => replaceEligibility(match_1).status === "blocked" || match_1.text !== replaceText_0);
11292
+ const unchangedCount = matches_0.length - mutationMatches.length;
11293
+ if (mutationMatches.length === 0) return {
11294
+ replacedCount: unchangedCount,
11295
+ skippedCount: 0
11296
+ };
11297
+ const outcome = manager.replaceAll(currentDocument_3, mutationMatches, replaceText_0);
11298
+ if (!outcome) return {
11299
+ replacedCount: 0,
11300
+ skippedCount: 0
11301
+ };
11302
+ if (outcome.replacedCount > 0) acceptReplacement(outcome.document);
11303
+ return {
11304
+ replacedCount: outcome.replacedCount + unchangedCount,
11305
+ skippedCount: outcome.skippedCount
11306
+ };
11000
11307
  };
11001
- $[23] = handleDocumentChange;
11002
- $[24] = readDocumentState;
11003
- $[25] = resetFindResult;
11004
- $[26] = t9;
11005
- } else t9 = $[26];
11006
- const handleReplaceAll = t9;
11007
- let t10;
11008
- if ($[27] !== currentResult || $[28] !== handleFind || $[29] !== handleFindNext || $[30] !== handleFindPrevious || $[31] !== handleReplace || $[32] !== handleReplaceAll || $[33] !== resetFindResult) {
11009
- t10 = {
11010
- currentResult,
11308
+ $[60] = acceptReplacement;
11309
+ $[61] = displayMode;
11310
+ $[62] = findDisplayedMatches;
11311
+ $[63] = getLayout;
11312
+ $[64] = readDocumentState;
11313
+ $[65] = refreshChangedSource;
11314
+ $[66] = t26;
11315
+ } else t26 = $[66];
11316
+ const handleReplaceAll = t26;
11317
+ let t27;
11318
+ if ($[67] !== onReadonlyEditAttempt || $[68] !== replacementRefusal) {
11319
+ t27 = () => {
11320
+ if (replacementRefusal) onReadonlyEditAttempt?.(replacementRefusal);
11321
+ return false;
11322
+ };
11323
+ $[67] = onReadonlyEditAttempt;
11324
+ $[68] = replacementRefusal;
11325
+ $[69] = t27;
11326
+ } else t27 = $[69];
11327
+ const refuseReplace = t27;
11328
+ let t28;
11329
+ if ($[70] !== refuseReplace) {
11330
+ t28 = () => {
11331
+ refuseReplace();
11332
+ return {
11333
+ replacedCount: 0,
11334
+ skippedCount: manager.getResult()?.totalCount ?? 0
11335
+ };
11336
+ };
11337
+ $[70] = refuseReplace;
11338
+ $[71] = t28;
11339
+ } else t28 = $[71];
11340
+ const refuseReplaceAll = t28;
11341
+ const t29 = publishedResult.status === "ready" ? publishedResult.result : null;
11342
+ let t30;
11343
+ if ($[72] !== publishedResult.queryKey || $[73] !== publishedResult.result || $[74] !== publishedResult.status) {
11344
+ t30 = publishedResult.status === "ready" ? {
11345
+ queryKey: publishedResult.queryKey,
11346
+ result: publishedResult.result
11347
+ } : null;
11348
+ $[72] = publishedResult.queryKey;
11349
+ $[73] = publishedResult.result;
11350
+ $[74] = publishedResult.status;
11351
+ $[75] = t30;
11352
+ } else t30 = $[75];
11353
+ const t31 = replacementRefusal ? refuseReplace : handleReplace;
11354
+ const t32 = replacementRefusal ? refuseReplaceAll : handleReplaceAll;
11355
+ let t33;
11356
+ if ($[76] === Symbol.for("react.memo_cache_sentinel")) {
11357
+ t33 = () => manager.getResult();
11358
+ $[76] = t33;
11359
+ } else t33 = $[76];
11360
+ let t34;
11361
+ if ($[77] !== handleFind) {
11362
+ t34 = () => {
11363
+ const active_2 = query.current;
11364
+ if (active_2) handleFind(active_2.text, active_2.options);
11365
+ };
11366
+ $[77] = handleFind;
11367
+ $[78] = t34;
11368
+ } else t34 = $[78];
11369
+ let t35;
11370
+ if ($[79] !== handleFind || $[80] !== handleFindNext || $[81] !== handleFindPrevious || $[82] !== resetFindResult || $[83] !== t29 || $[84] !== t30 || $[85] !== t31 || $[86] !== t32 || $[87] !== t34) {
11371
+ t35 = {
11372
+ currentResult: t29,
11373
+ currentSearch: t30,
11011
11374
  resetFindResult,
11012
11375
  handleFind,
11376
+ handleQueryChange,
11013
11377
  handleFindNext,
11014
11378
  handleFindPrevious,
11015
- handleReplace,
11016
- handleReplaceAll
11379
+ handleReplace: t31,
11380
+ handleReplaceAll: t32,
11381
+ getFindResult: t33,
11382
+ refreshFind: t34
11017
11383
  };
11018
- $[27] = currentResult;
11019
- $[28] = handleFind;
11020
- $[29] = handleFindNext;
11021
- $[30] = handleFindPrevious;
11022
- $[31] = handleReplace;
11023
- $[32] = handleReplaceAll;
11024
- $[33] = resetFindResult;
11025
- $[34] = t10;
11026
- } else t10 = $[34];
11027
- return t10;
11384
+ $[79] = handleFind;
11385
+ $[80] = handleFindNext;
11386
+ $[81] = handleFindPrevious;
11387
+ $[82] = resetFindResult;
11388
+ $[83] = t29;
11389
+ $[84] = t30;
11390
+ $[85] = t31;
11391
+ $[86] = t32;
11392
+ $[87] = t34;
11393
+ $[88] = t35;
11394
+ } else t35 = $[88];
11395
+ return t35;
11028
11396
  }
11029
11397
  //#endregion
11030
11398
  //#region src/components/hooks/useHeaderFooterEditor.ts
@@ -13818,7 +14186,7 @@ function _temp(id_4) {
13818
14186
  */
13819
14187
  /** No headings to track while the outline is not shown. */
13820
14188
  const NO_HEADINGS = [];
13821
- const CommentsSidebar = lazy(() => import("./CommentsSidebar-mv0x1JQX.js").then((m) => ({ default: m.CommentsSidebar })));
14189
+ const CommentsSidebar = lazy(() => import("./CommentsSidebar-6K9GbqAA.js").then((m) => ({ default: m.CommentsSidebar })));
13822
14190
  const TextContextMenu = lazy(() => import("./TextContextMenu-DZ3AUFKh.js").then((m) => ({ default: m.TextContextMenu })));
13823
14191
  const loadAttemptSelectiveSave = async () => {
13824
14192
  const { attemptSelectiveSave } = await import("@stll/folio-core/docx/selectiveSave");
@@ -13920,7 +14288,7 @@ const createPagedEditorBinding = () => {
13920
14288
  /**
13921
14289
  * DocxEditor - Complete DOCX editor component
13922
14290
  */
13923
- const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, document: initialDocument, onSave, author = "User", onChange, onSelectionChange, onSelectionTextChange, onError, onFontsLoaded: onFontsLoadedCallback, fontFamilies, fonts, theme, showToolbar = true, showZoomControl = true, showReviewControls = true, showHeaderFooterEditing = true, pageRenderer, showMarginGuides = false, marginGuideColor, showRuler: showRulerProp = false, rulerUnit = "inch", initialZoom = 1, enableWheelZoom = true, keyboardShortcuts = DEFAULT_KEYBOARD_SHORTCUT_SCOPE, hostShortcuts: hostShortcutsProp, readOnly: readOnlyProp = false, autoOpenReviewSidebar = true, components, toolbarExtra, className = "", style, placeholder, loadingIndicator, preserveDocumentWhileLoading = false, initialScrollTop, onScrollTopChange, showOutline: showOutlineProp = true, outlineDepth: outlineDepthProp, onOutlineDepthChange, onPrint, onInsertImage, onInsertTable, showTableInsert = true, onInsertPageBreak, onInsertTOC, onCopy, onCut, onPaste, mode: modeProp, onModeChange, onReadonlyEditAttempt, onCompatibilityChange, onEditorViewReady, onAnonymizationMatchesChange, onAnonymizationTermClick, selectedAnonymizationCanonical = null, anonymizationSelectionSeq, showTemplateDirectives = false, onSlashMenuChange, onSlashMenuKeyAction, customContextMenuItems, onCustomContextAction, comments: commentsProp, onCommentsChange, collaboration, plugins, featureFlags, experimentalSession, onSelectiveSaveTripwire }, ref) {
14291
+ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, document: initialDocument, onSave, author = "User", onChange, onFindResultChange, onSelectionChange, onSelectionTextChange, onError, onFontsLoaded: onFontsLoadedCallback, fontFamilies, fonts, theme, showToolbar = true, showZoomControl = true, showReviewControls = true, showHeaderFooterEditing = true, pageRenderer, showMarginGuides = false, marginGuideColor, showRuler: showRulerProp = false, rulerUnit = "inch", initialZoom = 1, enableWheelZoom = true, keyboardShortcuts = DEFAULT_KEYBOARD_SHORTCUT_SCOPE, hostShortcuts: hostShortcutsProp, readOnly: readOnlyProp = false, reviewDisplayMode, showCommentHighlights = true, autoOpenReviewSidebar = true, components, toolbarExtra, className = "", style, placeholder, loadingIndicator, preserveDocumentWhileLoading = false, initialScrollTop, onScrollTopChange, showOutline: showOutlineProp = true, outlineDepth: outlineDepthProp, onOutlineDepthChange, onPrint, onInsertImage, onInsertTable, showTableInsert = true, onInsertPageBreak, onInsertTOC, onCopy, onCut, onPaste, mode: modeProp, onModeChange, onReadonlyEditAttempt, onCompatibilityChange, onEditorViewReady, onAnonymizationMatchesChange, onAnonymizationTermClick, selectedAnonymizationCanonical = null, anonymizationSelectionSeq, showTemplateDirectives = false, onSlashMenuChange, onSlashMenuKeyAction, customContextMenuItems, onCustomContextAction, comments: commentsProp, onCommentsChange, collaboration, plugins, featureFlags, experimentalSession, onSelectiveSaveTripwire }, ref) {
13924
14292
  const pagedEditorRef = useRef(null);
13925
14293
  const [pagedEditorBinding] = useState(createPagedEditorBinding);
13926
14294
  const scrollContainerRef = useRef(null);
@@ -13975,10 +14343,11 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
13975
14343
  setTrackedChangeEntries(entries);
13976
14344
  }, []);
13977
14345
  const [anchorPositions, setAnchorPositions] = useState(EMPTY_ANCHOR_POSITIONS);
13978
- const { editingMode, readOnly, trackChangesOn, toggleTrackChanges, displayMode, setDisplayMode } = useEditorMode({
14346
+ const { editingMode, readOnly, readOnlyReason, trackChangesOn, toggleTrackChanges, displayMode, setDisplayMode } = useEditorMode({
13979
14347
  modeProp,
13980
14348
  onModeChange,
13981
- readOnlyProp
14349
+ readOnlyProp,
14350
+ ...reviewDisplayMode === void 0 ? {} : { reviewDisplayMode }
13982
14351
  });
13983
14352
  useEffect(() => {
13984
14353
  pagedEditorRef.current?.getEditor().setCanonicalMode(editingMode === "suggesting" ? {
@@ -14321,6 +14690,13 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
14321
14690
  ...!usesCanonicalSession(experimentalSession, CANONICAL_GAP.authorityRouting) ? {} : { experimentalSession },
14322
14691
  getHfView: pagedEditorBinding.getHfView
14323
14692
  });
14693
+ useLayoutEffect(() => {
14694
+ if (readOnly && hfEditPosition) handleBodyClick();
14695
+ }, [
14696
+ readOnly,
14697
+ hfEditPosition,
14698
+ handleBodyClick
14699
+ ]);
14324
14700
  let activeHfRId = hfEditIsFirstPage ? activeFirstFooterRId : activeFooterRId;
14325
14701
  if (hfEditPosition === "header") activeHfRId = hfEditIsFirstPage ? activeFirstHeaderRId : activeHeaderRId;
14326
14702
  const visibleOutlineHeadings = useMemo(() => filterHeadingsByDepth(outlineHeadings, outlineDepth), [outlineDepth, outlineHeadings]);
@@ -14670,39 +15046,87 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
14670
15046
  canonicalCommentsSerialized,
14671
15047
  onCommentsChange
14672
15048
  ]);
14673
- const { currentResult: currentFindResult, resetFindResult, handleFind, handleFindNext, handleFindPrevious, handleReplace, handleReplaceAll } = useFindReplace({
15049
+ const selectFindMatch = useCallback((match) => {
15050
+ if (match.commentId !== void 0) {
15051
+ setVisibleCommentAuthors(null);
15052
+ setShowCommentsSidebar(true);
15053
+ setActiveCommentId(commentsRef.current.find(({ id }) => id === match.commentId)?.parentId ?? match.commentId);
15054
+ return true;
15055
+ }
15056
+ return false;
15057
+ }, [
15058
+ setActiveCommentId,
15059
+ setVisibleCommentAuthors,
15060
+ setShowCommentsSidebar,
15061
+ commentsRef
15062
+ ]);
15063
+ const getFindEditorState = useCallback(() => {
15064
+ pagedEditorRef.current?.ensureView({ focus: false });
15065
+ return pagedEditorRef.current?.getView()?.state ?? null;
15066
+ }, []);
15067
+ const getFindBodyDoc = useCallback(() => getFindEditorState()?.doc, [getFindEditorState]);
15068
+ const getFindLayout = useCallback(() => pagedEditorRef.current?.getLayout() ?? null, []);
15069
+ const notifyReadonlyEditAttempt = useCallback(() => {
15070
+ if (readOnlyReason) onReadonlyEditAttempt?.(readOnlyReason);
15071
+ }, [readOnlyReason, onReadonlyEditAttempt]);
15072
+ const { currentSearch: currentFindSearch, resetFindResult, handleFind, handleQueryChange, handleFindNext, handleFindPrevious, handleReplace, handleReplaceAll, getFindResult, refreshFind } = useFindReplace({
15073
+ documentState: history.state,
14674
15074
  getDocumentState: buildCurrentDocument,
15075
+ getEditorState: getFindEditorState,
14675
15076
  containerRef,
14676
15077
  handleDocumentChange,
14677
15078
  findReplace,
14678
- selectMatch: useCallback((match) => {
14679
- const editor_1 = pagedEditorRef.current;
14680
- const view_8 = editor_1?.getView();
14681
- if (!editor_1 || !view_8) return false;
14682
- const range = resolveFindMatchRange(view_8.state.doc, match);
14683
- if (!range) return false;
14684
- editor_1.setSelection(range.from, range.to);
14685
- requestAnimationFrame(() => {
14686
- editor_1.scrollToPosition(range.from);
14687
- });
14688
- return true;
14689
- }, [])
15079
+ selectMatch: selectFindMatch,
15080
+ getBodyDoc: getFindBodyDoc,
15081
+ getLayout: getFindLayout,
15082
+ displayMode,
15083
+ onFindResultChange,
15084
+ readOnlyReason,
15085
+ onReadonlyEditAttempt
14690
15086
  });
15087
+ const refreshFindRef = useRef(refreshFind);
15088
+ useLayoutEffect(() => {
15089
+ refreshFindRef.current = refreshFind;
15090
+ }, [refreshFind]);
15091
+ useEffect(() => {
15092
+ if (bodyViewEpoch === 0) return;
15093
+ const editor_1 = pagedEditorRef.current?.getEditor();
15094
+ if (!editor_1) return;
15095
+ let timer_1 = null;
15096
+ const schedule = () => {
15097
+ if (timer_1 !== null) clearTimeout(timer_1);
15098
+ timer_1 = setTimeout(() => refreshFindRef.current(), 200);
15099
+ };
15100
+ const unsubscribe = editor_1.on("docChange", schedule);
15101
+ const unsubscribeLayout = editor_1.on("layoutComplete", schedule);
15102
+ return () => {
15103
+ unsubscribe();
15104
+ unsubscribeLayout();
15105
+ if (timer_1 !== null) clearTimeout(timer_1);
15106
+ };
15107
+ }, [bodyViewEpoch]);
15108
+ useEffect(() => {
15109
+ const snapshot = comments;
15110
+ const timer_2 = setTimeout(() => {
15111
+ if (commentsRef.current === snapshot) refreshFindRef.current();
15112
+ }, 200);
15113
+ return () => clearTimeout(timer_2);
15114
+ }, [comments, commentsRef]);
14691
15115
  useLayoutEffect(() => {
14692
15116
  resetFindResultRef.current = resetFindResult;
14693
15117
  }, [resetFindResult]);
14694
15118
  const handleSelectionChange = useCallback((selectionState) => {
14695
- const view_9 = getActiveEditorView();
14696
- if (view_9) {
14697
- const { from, to } = view_9.state.selection;
15119
+ const view_8 = getActiveEditorView();
15120
+ if (view_8) {
15121
+ const { from, to } = view_8.state.selection;
14698
15122
  lastSelectionRef.current = {
14699
15123
  from,
14700
15124
  to
14701
15125
  };
14702
15126
  }
14703
15127
  let pmTableCtx = null;
14704
- if (view_9) {
14705
- pmTableCtx = getTableContext(view_9.state);
15128
+ if (view_8) {
15129
+ pmTableCtx = getTableContext(view_8.state);
14706
15130
  if (!pmTableCtx.isInTable) pmTableCtx = null;
14707
15131
  }
14708
15132
  if (pmTableCtx?.cellBorderColor) {
@@ -14714,8 +15138,8 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
14714
15138
  color: { rgb }
14715
15139
  };
14716
15140
  }
14717
- const pmImageCtx = view_9 ? detectImageContext(view_9.state) : null;
14718
- const trackedChange = view_9 ? detectActiveTrackedChange(view_9.state) : null;
15141
+ const pmImageCtx = view_8 ? detectImageContext(view_8.state) : null;
15142
+ const trackedChange = view_8 ? detectActiveTrackedChange(view_8.state) : null;
14719
15143
  if (!selectionState) {
14720
15144
  setFloatingCommentBtn(null);
14721
15145
  setState((prev_1) => {
@@ -14778,10 +15202,10 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
14778
15202
  activeTrackedChange: activeTrackedChange_0
14779
15203
  };
14780
15204
  });
14781
- if (view_9 && selectionState.hasSelection && !isAddingComment && !readOnly) {
15205
+ if (view_8 && selectionState.hasSelection && !isAddingComment && !readOnly) {
14782
15206
  const container = scrollContainerRef.current;
14783
15207
  const parentEl = editorContentRef.current;
14784
- const { from: selFrom } = view_9.state.selection;
15208
+ const { from: selFrom } = view_8.state.selection;
14785
15209
  const top = findSelectionYPosition(container, parentEl, selFrom);
14786
15210
  if (top !== null && container && parentEl) {
14787
15211
  const pagesEl = container.querySelector(".paged-editor__pages");
@@ -14789,7 +15213,7 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
14789
15213
  const parentRect = parentEl.getBoundingClientRect();
14790
15214
  const rawLeft = pageEl ? pageEl.getBoundingClientRect().right - parentRect.left + 12 : parentRect.width / 2 + 408;
14791
15215
  const left = Math.max(16, Math.min(rawLeft, parentRect.width - 16));
14792
- const { from: from_0, to: to_0 } = view_9.state.selection;
15216
+ const { from: from_0, to: to_0 } = view_8.state.selection;
14793
15217
  if (from_0 !== to_0) setFloatingCommentBtn({
14794
15218
  top,
14795
15219
  left,
@@ -14952,98 +15376,98 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
14952
15376
  refuseCanonicalModelEdit
14953
15377
  ]);
14954
15378
  const handleTableAction = useCallback((action_0) => {
14955
- const view_10 = getActiveEditorView();
14956
- if (!view_10) return;
15379
+ const view_9 = getActiveEditorView();
15380
+ if (!view_9) return;
14957
15381
  switch (action_0) {
14958
15382
  case "addRowAbove":
14959
- addRowAbove(view_10.state, view_10.dispatch);
15383
+ addRowAbove(view_9.state, view_9.dispatch);
14960
15384
  break;
14961
15385
  case "addRowBelow":
14962
- addRowBelow(view_10.state, view_10.dispatch);
15386
+ addRowBelow(view_9.state, view_9.dispatch);
14963
15387
  break;
14964
15388
  case "addColumnLeft":
14965
- addColumnLeft(view_10.state, view_10.dispatch);
15389
+ addColumnLeft(view_9.state, view_9.dispatch);
14966
15390
  break;
14967
15391
  case "addColumnRight":
14968
- addColumnRight(view_10.state, view_10.dispatch);
15392
+ addColumnRight(view_9.state, view_9.dispatch);
14969
15393
  break;
14970
15394
  case "deleteRow":
14971
- deleteRow(view_10.state, view_10.dispatch);
15395
+ deleteRow(view_9.state, view_9.dispatch);
14972
15396
  break;
14973
15397
  case "deleteColumn":
14974
- deleteColumn(view_10.state, view_10.dispatch);
15398
+ deleteColumn(view_9.state, view_9.dispatch);
14975
15399
  break;
14976
15400
  case "deleteTable":
14977
- deleteTable(view_10.state, view_10.dispatch);
15401
+ deleteTable(view_9.state, view_9.dispatch);
14978
15402
  break;
14979
15403
  case "selectTable":
14980
- selectTable(view_10.state, view_10.dispatch);
15404
+ selectTable(view_9.state, view_9.dispatch);
14981
15405
  break;
14982
15406
  case "selectRow":
14983
- selectRow(view_10.state, view_10.dispatch);
15407
+ selectRow(view_9.state, view_9.dispatch);
14984
15408
  break;
14985
15409
  case "selectColumn":
14986
- selectColumn(view_10.state, view_10.dispatch);
15410
+ selectColumn(view_9.state, view_9.dispatch);
14987
15411
  break;
14988
15412
  case "mergeCells":
14989
- mergeCells(view_10.state, view_10.dispatch);
15413
+ mergeCells(view_9.state, view_9.dispatch);
14990
15414
  break;
14991
15415
  case "splitCell":
14992
- splitCell(view_10.state, view_10.dispatch);
15416
+ splitCell(view_9.state, view_9.dispatch);
14993
15417
  break;
14994
15418
  case "borderAll":
14995
- setAllTableBorders(view_10.state, view_10.dispatch, borderSpecRef.current);
15419
+ setAllTableBorders(view_9.state, view_9.dispatch, borderSpecRef.current);
14996
15420
  break;
14997
15421
  case "borderOutside":
14998
- setOutsideTableBorders(view_10.state, view_10.dispatch, borderSpecRef.current);
15422
+ setOutsideTableBorders(view_9.state, view_9.dispatch, borderSpecRef.current);
14999
15423
  break;
15000
15424
  case "borderInside":
15001
- setInsideTableBorders(view_10.state, view_10.dispatch, borderSpecRef.current);
15425
+ setInsideTableBorders(view_9.state, view_9.dispatch, borderSpecRef.current);
15002
15426
  break;
15003
15427
  case "borderNone":
15004
- removeTableBorders(view_10.state, view_10.dispatch);
15428
+ removeTableBorders(view_9.state, view_9.dispatch);
15005
15429
  break;
15006
15430
  case "borderTop":
15007
- setCellBorder("top", borderSpecRef.current, true)(view_10.state, view_10.dispatch);
15431
+ setCellBorder("top", borderSpecRef.current, true)(view_9.state, view_9.dispatch);
15008
15432
  break;
15009
15433
  case "borderBottom":
15010
- setCellBorder("bottom", borderSpecRef.current, true)(view_10.state, view_10.dispatch);
15434
+ setCellBorder("bottom", borderSpecRef.current, true)(view_9.state, view_9.dispatch);
15011
15435
  break;
15012
15436
  case "borderLeft":
15013
- setCellBorder("left", borderSpecRef.current, true)(view_10.state, view_10.dispatch);
15437
+ setCellBorder("left", borderSpecRef.current, true)(view_9.state, view_9.dispatch);
15014
15438
  break;
15015
15439
  case "borderRight":
15016
- setCellBorder("right", borderSpecRef.current, true)(view_10.state, view_10.dispatch);
15440
+ setCellBorder("right", borderSpecRef.current, true)(view_9.state, view_9.dispatch);
15017
15441
  break;
15018
- default: if (typeof action_0 === "object") if (action_0.type === "cellFillColor") setCellFillColor(action_0.color)(view_10.state, view_10.dispatch);
15442
+ default: if (typeof action_0 === "object") if (action_0.type === "cellFillColor") setCellFillColor(action_0.color)(view_9.state, view_9.dispatch);
15019
15443
  else if (action_0.type === "borderColor") {
15020
15444
  const rgb_0 = action_0.color.replace(/^#/u, "");
15021
15445
  borderSpecRef.current = {
15022
15446
  ...borderSpecRef.current,
15023
15447
  color: { rgb: rgb_0 }
15024
15448
  };
15025
- setTableBorderColor(action_0.color)(view_10.state, view_10.dispatch);
15449
+ setTableBorderColor(action_0.color)(view_9.state, view_9.dispatch);
15026
15450
  } else if (action_0.type === "borderWidth") {
15027
15451
  borderSpecRef.current = {
15028
15452
  ...borderSpecRef.current,
15029
15453
  size: action_0.size
15030
15454
  };
15031
- setTableBorderWidth(action_0.size)(view_10.state, view_10.dispatch);
15455
+ setTableBorderWidth(action_0.size)(view_9.state, view_9.dispatch);
15032
15456
  } else if (action_0.type === "cellBorder") setCellBorder(action_0.side, {
15033
15457
  style: action_0.style,
15034
15458
  size: action_0.size,
15035
15459
  color: { rgb: action_0.color.replace(/^#/u, "") }
15036
- })(view_10.state, view_10.dispatch);
15037
- else if (action_0.type === "cellVerticalAlign") setCellVerticalAlign(action_0.align)(view_10.state, view_10.dispatch);
15038
- else if (action_0.type === "cellMargins") setCellMargins(action_0.margins)(view_10.state, view_10.dispatch);
15039
- else if (action_0.type === "cellTextDirection") setCellTextDirection(action_0.direction)(view_10.state, view_10.dispatch);
15040
- else if (action_0.type === "toggleNoWrap") toggleNoWrap()(view_10.state, view_10.dispatch);
15041
- else if (action_0.type === "rowHeight") setRowHeight(action_0.height, action_0.rule)(view_10.state, view_10.dispatch);
15042
- else if (action_0.type === "toggleHeaderRow") toggleHeaderRow()(view_10.state, view_10.dispatch);
15043
- else if (action_0.type === "distributeColumns") distributeColumns()(view_10.state, view_10.dispatch);
15044
- else if (action_0.type === "autoFitContents") autoFitContents()(view_10.state, view_10.dispatch);
15460
+ })(view_9.state, view_9.dispatch);
15461
+ else if (action_0.type === "cellVerticalAlign") setCellVerticalAlign(action_0.align)(view_9.state, view_9.dispatch);
15462
+ else if (action_0.type === "cellMargins") setCellMargins(action_0.margins)(view_9.state, view_9.dispatch);
15463
+ else if (action_0.type === "cellTextDirection") setCellTextDirection(action_0.direction)(view_9.state, view_9.dispatch);
15464
+ else if (action_0.type === "toggleNoWrap") toggleNoWrap()(view_9.state, view_9.dispatch);
15465
+ else if (action_0.type === "rowHeight") setRowHeight(action_0.height, action_0.rule)(view_9.state, view_9.dispatch);
15466
+ else if (action_0.type === "toggleHeaderRow") toggleHeaderRow()(view_9.state, view_9.dispatch);
15467
+ else if (action_0.type === "distributeColumns") distributeColumns()(view_9.state, view_9.dispatch);
15468
+ else if (action_0.type === "autoFitContents") autoFitContents()(view_9.state, view_9.dispatch);
15045
15469
  else if (action_0.type === "openTableProperties") setTablePropsOpen(true);
15046
- else if (action_0.type === "tableProperties") setTableProperties(action_0.props)(view_10.state, view_10.dispatch);
15470
+ else if (action_0.type === "tableProperties") setTableProperties(action_0.props)(view_9.state, view_9.dispatch);
15047
15471
  else {
15048
15472
  let preset = getBuiltinTableStyle(action_0.styleId);
15049
15473
  const currentDocForTable = historyStateRef.current;
@@ -15114,7 +15538,7 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
15114
15538
  if (preset.tableBorders) styleArg.tableBorders = preset.tableBorders;
15115
15539
  if (preset.conditionals) styleArg.conditionals = preset.conditionals;
15116
15540
  if (preset.look) styleArg.look = preset.look;
15117
- applyTableStyle(styleArg)(view_10.state, view_10.dispatch);
15541
+ applyTableStyle(styleArg)(view_9.state, view_9.dispatch);
15118
15542
  }
15119
15543
  }
15120
15544
  else tableSelection.handleAction(action_0);
@@ -15135,86 +15559,86 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
15135
15559
  });
15136
15560
  }, [openContextMenu]);
15137
15561
  const handleFormat = useCallback((action_1) => {
15138
- const view_11 = getActiveEditorView();
15139
- if (!view_11) return;
15140
- view_11.focus();
15141
- const isBodyEditor = view_11 === pagedEditorRef.current?.getView();
15142
- const { from: from_1, to: to_1 } = view_11.state.selection;
15562
+ const view_10 = getActiveEditorView();
15563
+ if (!view_10) return;
15564
+ view_10.focus();
15565
+ const isBodyEditor = view_10 === pagedEditorRef.current?.getView();
15566
+ const { from: from_1, to: to_1 } = view_10.state.selection;
15143
15567
  const savedSelection = lastSelectionRef.current;
15144
15568
  if (isBodyEditor && savedSelection && (from_1 !== savedSelection.from || to_1 !== savedSelection.to)) try {
15145
- const tr = view_11.state.tr.setSelection(TextSelection.create(view_11.state.doc, savedSelection.from, savedSelection.to));
15146
- view_11.dispatch(tr);
15569
+ const tr = view_10.state.tr.setSelection(TextSelection.create(view_10.state.doc, savedSelection.from, savedSelection.to));
15570
+ view_10.dispatch(tr);
15147
15571
  } catch {}
15148
15572
  if (action_1 === "bold") {
15149
- executeEditorCommand(view_11, toggleBold);
15573
+ executeEditorCommand(view_10, toggleBold);
15150
15574
  return;
15151
15575
  }
15152
15576
  if (action_1 === "italic") {
15153
- executeEditorCommand(view_11, toggleItalic);
15577
+ executeEditorCommand(view_10, toggleItalic);
15154
15578
  return;
15155
15579
  }
15156
15580
  if (action_1 === "underline") {
15157
- executeEditorCommand(view_11, toggleUnderline);
15581
+ executeEditorCommand(view_10, toggleUnderline);
15158
15582
  return;
15159
15583
  }
15160
15584
  if (action_1 === "strikethrough") {
15161
- executeEditorCommand(view_11, toggleStrike);
15585
+ executeEditorCommand(view_10, toggleStrike);
15162
15586
  return;
15163
15587
  }
15164
15588
  if (action_1 === "superscript") {
15165
- executeEditorCommand(view_11, toggleSuperscript);
15589
+ executeEditorCommand(view_10, toggleSuperscript);
15166
15590
  return;
15167
15591
  }
15168
15592
  if (action_1 === "subscript") {
15169
- executeEditorCommand(view_11, toggleSubscript);
15593
+ executeEditorCommand(view_10, toggleSubscript);
15170
15594
  return;
15171
15595
  }
15172
15596
  if (action_1 === "bulletList") {
15173
- executeEditorCommand(view_11, toggleBulletList);
15597
+ executeEditorCommand(view_10, toggleBulletList);
15174
15598
  return;
15175
15599
  }
15176
15600
  if (action_1 === "numberedList") {
15177
- executeEditorCommand(view_11, toggleNumberedList);
15601
+ executeEditorCommand(view_10, toggleNumberedList);
15178
15602
  return;
15179
15603
  }
15180
15604
  if (action_1 === "indent") {
15181
- executeFirstEditorCommand(view_11, [increaseListLevel, increaseIndent()]);
15605
+ executeFirstEditorCommand(view_10, [increaseListLevel, increaseIndent()]);
15182
15606
  return;
15183
15607
  }
15184
15608
  if (action_1 === "outdent") {
15185
- executeFirstEditorCommand(view_11, [decreaseListLevel, decreaseIndent()]);
15609
+ executeFirstEditorCommand(view_10, [decreaseListLevel, decreaseIndent()]);
15186
15610
  return;
15187
15611
  }
15188
15612
  if (action_1 === "clearFormatting") {
15189
- executeEditorCommand(view_11, clearFormatting);
15613
+ executeEditorCommand(view_10, clearFormatting);
15190
15614
  return;
15191
15615
  }
15192
15616
  if (action_1 === "setRtl") {
15193
- executeEditorCommand(view_11, setRtl);
15617
+ executeEditorCommand(view_10, setRtl);
15194
15618
  return;
15195
15619
  }
15196
15620
  if (action_1 === "setLtr") {
15197
- executeEditorCommand(view_11, setLtr);
15621
+ executeEditorCommand(view_10, setLtr);
15198
15622
  return;
15199
15623
  }
15200
15624
  if (action_1 === "insertPageBreak") {
15201
- executeEditorCommand(view_11, insertPageBreak);
15625
+ executeEditorCommand(view_10, insertPageBreak);
15202
15626
  return;
15203
15627
  }
15204
15628
  if (typeof action_1 === "object") switch (action_1.type) {
15205
15629
  case "alignment":
15206
- executeEditorCommand(view_11, setAlignment(action_1.value));
15630
+ executeEditorCommand(view_10, setAlignment(action_1.value));
15207
15631
  break;
15208
15632
  case "toggleDirection":
15209
- executeEditorCommand(view_11, toggleBidi);
15633
+ executeEditorCommand(view_10, toggleBidi);
15210
15634
  break;
15211
15635
  case "textColor": {
15212
15636
  const colorVal_0 = action_1.value;
15213
- if (typeof colorVal_0 === "string") executeEditorCommand(view_11, setTextColor({ rgb: colorVal_0.replace("#", "") }));
15214
- else if (colorVal_0.auto) executeEditorCommand(view_11, clearTextColor);
15637
+ if (typeof colorVal_0 === "string") executeEditorCommand(view_10, setTextColor({ rgb: colorVal_0.replace("#", "") }));
15638
+ else if (colorVal_0.auto) executeEditorCommand(view_10, clearTextColor);
15215
15639
  else {
15216
15640
  const themeColor = typeof colorVal_0.themeColor === "string" ? colorVal_0.themeColor : void 0;
15217
- executeEditorCommand(view_11, setTextColor({
15641
+ executeEditorCommand(view_10, setTextColor({
15218
15642
  ...colorVal_0.rgb === void 0 ? {} : { rgb: colorVal_0.rgb },
15219
15643
  ...themeColor ? { themeColor } : {},
15220
15644
  ...colorVal_0.themeTint === void 0 ? {} : { themeTint: colorVal_0.themeTint },
@@ -15224,16 +15648,16 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
15224
15648
  break;
15225
15649
  }
15226
15650
  case "highlightColor":
15227
- executeEditorCommand(view_11, setHighlight((action_1.value ? mapHexToHighlightName(action_1.value) : "") || action_1.value));
15651
+ executeEditorCommand(view_10, setHighlight((action_1.value ? mapHexToHighlightName(action_1.value) : "") || action_1.value));
15228
15652
  break;
15229
15653
  case "fontSize":
15230
- executeEditorCommand(view_11, setFontSize(pointsToHalfPoints(action_1.value)));
15654
+ executeEditorCommand(view_10, setFontSize(pointsToHalfPoints(action_1.value)));
15231
15655
  break;
15232
15656
  case "fontFamily":
15233
- executeEditorCommand(view_11, setFontFamily(action_1.value));
15657
+ executeEditorCommand(view_10, setFontFamily(action_1.value));
15234
15658
  break;
15235
15659
  case "lineSpacing":
15236
- executeEditorCommand(view_11, setLineSpacing(action_1.value));
15660
+ executeEditorCommand(view_10, setLineSpacing(action_1.value));
15237
15661
  break;
15238
15662
  case "applyStyle": {
15239
15663
  const currentDoc_0 = historyStateRef.current;
@@ -15246,22 +15670,22 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
15246
15670
  const styleName = styleResolver_0.getStyle(action_1.value)?.name;
15247
15671
  if (styleName) styleAttrs.styleName = styleName;
15248
15672
  styleAttrs.numbering = currentDoc_0?.package.numbering ? getCachedNumberingMap(currentDoc_0.package.numbering) : null;
15249
- executeEditorCommand(view_11, applyStyle(action_1.value, styleAttrs));
15250
- } else executeEditorCommand(view_11, applyStyle(action_1.value));
15673
+ executeEditorCommand(view_10, applyStyle(action_1.value, styleAttrs));
15674
+ } else executeEditorCommand(view_10, applyStyle(action_1.value));
15251
15675
  break;
15252
15676
  }
15253
15677
  default: break;
15254
15678
  }
15255
15679
  }, [getActiveEditorView, getCachedStyleResolver]);
15256
15680
  const captureFormatPainter = useCallback(() => {
15257
- const view_12 = getActiveEditorView();
15258
- capturedFormatMarksRef.current = view_12 ? captureFormatMarks(view_12.state) : null;
15681
+ const view_11 = getActiveEditorView();
15682
+ capturedFormatMarksRef.current = view_11 ? captureFormatMarks(view_11.state) : null;
15259
15683
  }, [getActiveEditorView]);
15260
15684
  const paintFormatToSelection = useCallback(() => {
15261
- const view_13 = getActiveEditorView();
15262
- if (!view_13) return false;
15263
- const applied = applyFormatMarks(capturedFormatMarksRef.current)(view_13.state, view_13.dispatch);
15264
- if (applied) requestAnimationFrame(() => view_13.focus());
15685
+ const view_12 = getActiveEditorView();
15686
+ if (!view_12) return false;
15687
+ const applied = applyFormatMarks(capturedFormatMarksRef.current)(view_12.state, view_12.dispatch);
15688
+ if (applied) requestAnimationFrame(() => view_12.focus());
15265
15689
  return applied;
15266
15690
  }, [getActiveEditorView]);
15267
15691
  const handleFormatPainter = useCallback((sticky) => {
@@ -15440,15 +15864,15 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
15440
15864
  ]);
15441
15865
  const { from: contextSelectionFrom, to: contextSelectionTo } = contextMenu.selectionRange;
15442
15866
  const handleContextMenuAction = useCallback(async (action_2) => {
15443
- const view_14 = getActiveEditorView();
15444
- if (!view_14) return;
15867
+ const view_13 = getActiveEditorView();
15868
+ if (!view_13) return;
15445
15869
  focusActiveEditor();
15446
15870
  if (readOnly && action_2 !== "copy" && action_2 !== "selectAll") return;
15447
15871
  if (action_2.startsWith("custom:")) {
15448
15872
  const { from: from_2, to: to_2 } = contextSelectionFrom !== contextSelectionTo ? {
15449
15873
  from: contextSelectionFrom,
15450
15874
  to: contextSelectionTo
15451
- } : view_14.state.selection;
15875
+ } : view_13.state.selection;
15452
15876
  onCustomContextAction?.(action_2.slice(7), {
15453
15877
  from: from_2,
15454
15878
  to: to_2
@@ -15458,16 +15882,16 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
15458
15882
  switch (action_2) {
15459
15883
  case "cut": {
15460
15884
  if (readOnly) return;
15461
- const { from: from_7, to: to_7 } = view_14.state.selection;
15462
- const text_2 = view_14.state.doc.textBetween(from_7, to_7, "\n");
15885
+ const { from: from_7, to: to_7 } = view_13.state.selection;
15886
+ const text_2 = view_13.state.doc.textBetween(from_7, to_7, "\n");
15463
15887
  navigator.clipboard.writeText(text_2).catch(() => void 0);
15464
- if (!deleteSelectionAsSuggestion(view_14.state, view_14.dispatch)) view_14.dispatch(view_14.state.tr.deleteSelection());
15888
+ if (!deleteSelectionAsSuggestion(view_13.state, view_13.dispatch)) view_13.dispatch(view_13.state.tr.deleteSelection());
15465
15889
  onCut?.();
15466
15890
  break;
15467
15891
  }
15468
15892
  case "copy": {
15469
- const { from: cf, to: ct } = view_14.state.selection;
15470
- const copied = view_14.state.doc.textBetween(cf, ct, "\n");
15893
+ const { from: cf, to: ct } = view_13.state.selection;
15894
+ const copied = view_13.state.doc.textBetween(cf, ct, "\n");
15471
15895
  navigator.clipboard.writeText(copied).catch(() => void 0);
15472
15896
  onCopy?.();
15473
15897
  break;
@@ -15479,8 +15903,8 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
15479
15903
  let html = "";
15480
15904
  let text_1 = "";
15481
15905
  for (const item_1 of items_0) {
15482
- if (item_1.types.includes("text/html")) html = await (await item_1.getType("text/html")).text();
15483
- if (item_1.types.includes("text/plain")) text_1 = await (await item_1.getType("text/plain")).text();
15906
+ if (item_1.types.includes("text/html")) html = await readBlobText(await item_1.getType("text/html"));
15907
+ if (item_1.types.includes("text/plain")) text_1 = await readBlobText(await item_1.getType("text/plain"));
15484
15908
  }
15485
15909
  const dt = new DataTransfer();
15486
15910
  if (html) dt.items.add(html, "text/html");
@@ -15490,12 +15914,12 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
15490
15914
  bubbles: true,
15491
15915
  cancelable: true
15492
15916
  });
15493
- view_14.dom.dispatchEvent(pasteEvent);
15917
+ view_13.dom.dispatchEvent(pasteEvent);
15494
15918
  } catch {
15495
15919
  try {
15496
15920
  const text_0 = await navigator.clipboard.readText();
15497
15921
  if (text_0) {
15498
- view_14.dispatch(view_14.state.tr.insertText(text_0));
15922
+ view_13.dispatch(view_13.state.tr.insertText(text_0));
15499
15923
  onPaste?.();
15500
15924
  }
15501
15925
  } catch {}
@@ -15504,9 +15928,9 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
15504
15928
  case "pasteAsPlainText":
15505
15929
  try {
15506
15930
  const text = await navigator.clipboard.readText();
15507
- if (text && !view_14.isDestroyed) {
15508
- const slice = buildPlainTextSlice(text, view_14.state.schema);
15509
- view_14.dispatch(view_14.state.tr.replaceSelection(slice).scrollIntoView());
15931
+ if (text && !view_13.isDestroyed) {
15932
+ const slice = buildPlainTextSlice(text, view_13.state.schema);
15933
+ view_13.dispatch(view_13.state.tr.replaceSelection(slice).scrollIntoView());
15510
15934
  onPaste?.();
15511
15935
  }
15512
15936
  } catch {
@@ -15514,42 +15938,42 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
15514
15938
  }
15515
15939
  break;
15516
15940
  case "delete": {
15517
- const { from: from_6, to: to_6 } = view_14.state.selection;
15518
- if (from_6 !== to_6) view_14.dispatch(view_14.state.tr.deleteRange(from_6, to_6));
15941
+ const { from: from_6, to: to_6 } = view_13.state.selection;
15942
+ if (from_6 !== to_6) view_13.dispatch(view_13.state.tr.deleteRange(from_6, to_6));
15519
15943
  break;
15520
15944
  }
15521
15945
  case "selectAll":
15522
- view_14.dispatch(view_14.state.tr.setSelection(TextSelection.create(view_14.state.doc, 0, view_14.state.doc.content.size)));
15946
+ view_13.dispatch(view_13.state.tr.setSelection(TextSelection.create(view_13.state.doc, 0, view_13.state.doc.content.size)));
15523
15947
  break;
15524
15948
  case "addRowAbove":
15525
- addRowAbove(view_14.state, view_14.dispatch);
15949
+ addRowAbove(view_13.state, view_13.dispatch);
15526
15950
  break;
15527
15951
  case "addRowBelow":
15528
- addRowBelow(view_14.state, view_14.dispatch);
15952
+ addRowBelow(view_13.state, view_13.dispatch);
15529
15953
  break;
15530
15954
  case "deleteRow":
15531
- deleteRow(view_14.state, view_14.dispatch);
15955
+ deleteRow(view_13.state, view_13.dispatch);
15532
15956
  break;
15533
15957
  case "addColumnLeft":
15534
- addColumnLeft(view_14.state, view_14.dispatch);
15958
+ addColumnLeft(view_13.state, view_13.dispatch);
15535
15959
  break;
15536
15960
  case "addColumnRight":
15537
- addColumnRight(view_14.state, view_14.dispatch);
15961
+ addColumnRight(view_13.state, view_13.dispatch);
15538
15962
  break;
15539
15963
  case "deleteColumn":
15540
- deleteColumn(view_14.state, view_14.dispatch);
15964
+ deleteColumn(view_13.state, view_13.dispatch);
15541
15965
  break;
15542
15966
  case "tableBordersAll":
15543
- setTableBorderPreset("all")(view_14.state, view_14.dispatch);
15967
+ setTableBorderPreset("all")(view_13.state, view_13.dispatch);
15544
15968
  break;
15545
15969
  case "tableBordersNone":
15546
- setTableBorderPreset("none")(view_14.state, view_14.dispatch);
15970
+ setTableBorderPreset("none")(view_13.state, view_13.dispatch);
15547
15971
  break;
15548
15972
  case "addComment": {
15549
15973
  const { from: from_5, to: to_5 } = contextSelectionFrom !== contextSelectionTo ? {
15550
15974
  from: contextSelectionFrom,
15551
15975
  to: contextSelectionTo
15552
- } : view_14.state.selection;
15976
+ } : view_13.state.selection;
15553
15977
  if (from_5 === to_5) break;
15554
15978
  const commentY = findSelectionYPosition(scrollContainerRef.current, editorContentRef.current, from_5) ?? getFallbackCommentYPosition(scrollContainerRef.current);
15555
15979
  setCommentSelectionRange({
@@ -15557,7 +15981,7 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
15557
15981
  to: to_5
15558
15982
  });
15559
15983
  if (commentDraftMode === "prosemirror") {
15560
- if (!applyCommentMarkRange(view_14, {
15984
+ if (!applyCommentMarkRange(view_13, {
15561
15985
  from: from_5,
15562
15986
  to: to_5
15563
15987
  }, -1, { selectEnd: true })) break;
@@ -15569,30 +15993,30 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
15569
15993
  break;
15570
15994
  }
15571
15995
  case "acceptChange": {
15572
- const { from: from_4, to: to_4 } = view_14.state.selection;
15573
- const range_1 = findChangeAtPosition(view_14.state, from_4, to_4);
15996
+ const { from: from_4, to: to_4 } = view_13.state.selection;
15997
+ const range_0 = findChangeAtPosition(view_13.state, from_4, to_4);
15574
15998
  if (resolveCanonicalReviewRange({
15575
15999
  editor: pagedEditorRef.current?.getEditor(),
15576
- ...range_1,
16000
+ ...range_0,
15577
16001
  resolution: "accept"
15578
- }) === null) acceptChange(range_1.from, range_1.to)(view_14.state, view_14.dispatch);
16002
+ }) === null) acceptChange(range_0.from, range_0.to)(view_13.state, view_13.dispatch);
15579
16003
  break;
15580
16004
  }
15581
16005
  case "rejectChange": {
15582
- const { from: from_3, to: to_3 } = view_14.state.selection;
15583
- const range_0 = findChangeAtPosition(view_14.state, from_3, to_3);
16006
+ const { from: from_3, to: to_3 } = view_13.state.selection;
16007
+ const range = findChangeAtPosition(view_13.state, from_3, to_3);
15584
16008
  if (resolveCanonicalReviewRange({
15585
16009
  editor: pagedEditorRef.current?.getEditor(),
15586
- ...range_0,
16010
+ ...range,
15587
16011
  resolution: "reject"
15588
- }) === null) rejectChange(range_0.from, range_0.to)(view_14.state, view_14.dispatch);
16012
+ }) === null) rejectChange(range.from, range.to)(view_13.state, view_13.dispatch);
15589
16013
  break;
15590
16014
  }
15591
16015
  case "restartNumbering":
15592
- restartNumbering(view_14.state, view_14.dispatch);
16016
+ restartNumbering(view_13.state, view_13.dispatch);
15593
16017
  break;
15594
16018
  case "continueNumbering":
15595
- continueNumbering(view_14.state, view_14.dispatch);
16019
+ continueNumbering(view_13.state, view_13.dispatch);
15596
16020
  break;
15597
16021
  case "setNumberingValue":
15598
16022
  setNumberingValueDialogOpen(true);
@@ -15652,37 +16076,37 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
15652
16076
  const handleTopMarginChange = useCallback((twips_1) => handlePageSetupApply({ marginTop: twips_1 }), [handlePageSetupApply]);
15653
16077
  const handleBottomMarginChange = useCallback((twips_2) => handlePageSetupApply({ marginBottom: twips_2 }), [handlePageSetupApply]);
15654
16078
  const handleIndentLeftChange = useCallback((twips_3) => {
16079
+ const view_14 = getActiveEditorView();
16080
+ if (!view_14) return;
16081
+ setIndentLeft(twips_3)(view_14.state, view_14.dispatch);
16082
+ }, [getActiveEditorView]);
16083
+ const handleIndentRightChange = useCallback((twips_4) => {
15655
16084
  const view_15 = getActiveEditorView();
15656
16085
  if (!view_15) return;
15657
- setIndentLeft(twips_3)(view_15.state, view_15.dispatch);
16086
+ setIndentRight(twips_4)(view_15.state, view_15.dispatch);
15658
16087
  }, [getActiveEditorView]);
15659
- const handleIndentRightChange = useCallback((twips_4) => {
16088
+ const handleFirstLineIndentChange = useCallback((twips_5) => {
15660
16089
  const view_16 = getActiveEditorView();
15661
16090
  if (!view_16) return;
15662
- setIndentRight(twips_4)(view_16.state, view_16.dispatch);
16091
+ if (twips_5 < 0) setIndentFirstLine(-twips_5, true)(view_16.state, view_16.dispatch);
16092
+ else setIndentFirstLine(twips_5, false)(view_16.state, view_16.dispatch);
15663
16093
  }, [getActiveEditorView]);
15664
- const handleFirstLineIndentChange = useCallback((twips_5) => {
16094
+ const handleTabStopRemove = useCallback((positionTwips) => {
15665
16095
  const view_17 = getActiveEditorView();
15666
16096
  if (!view_17) return;
15667
- if (twips_5 < 0) setIndentFirstLine(-twips_5, true)(view_17.state, view_17.dispatch);
15668
- else setIndentFirstLine(twips_5, false)(view_17.state, view_17.dispatch);
15669
- }, [getActiveEditorView]);
15670
- const handleTabStopRemove = useCallback((positionTwips) => {
15671
- const view_18 = getActiveEditorView();
15672
- if (!view_18) return;
15673
- removeTabStop(positionTwips)(view_18.state, view_18.dispatch);
16097
+ removeTabStop(positionTwips)(view_17.state, view_17.dispatch);
15674
16098
  }, [getActiveEditorView]);
15675
16099
  const serializeCurrentDocx = useCallback(async (options) => {
15676
16100
  let tripwireResult = null;
15677
16101
  let savedBuffer = null;
15678
16102
  try {
15679
16103
  const editor_2 = pagedEditorRef.current?.getEditor();
15680
- const snapshot = editor_2?.captureCanonicalSave();
15681
- if (snapshot && editor_2) {
15682
- const view_19 = editor_2.getView();
15683
- const editorState = view_19?.state;
16104
+ const snapshot_0 = editor_2?.captureCanonicalSave();
16105
+ if (snapshot_0 && editor_2) {
16106
+ const view_18 = editor_2.getView();
16107
+ const editorState = view_18?.state;
15684
16108
  const result_2 = await serializeCanonicalSave({
15685
- snapshot,
16109
+ snapshot: snapshot_0,
15686
16110
  options,
15687
16111
  featureFlags
15688
16112
  });
@@ -15692,12 +16116,12 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
15692
16116
  message: `Canonical save used a fidelity fallback: ${diagnostic.type} (${diagnostic.part}).`
15693
16117
  }));
15694
16118
  tripwireResult = result_2.tripwireResult;
15695
- if (view_19 && pagedEditorRef.current?.getEditor() === editor_2 && editor_2.getView() === view_19 && view_19.state.doc === editorState?.doc && editor_2.isCanonicalSaveCurrent(snapshot.version)) view_19.dispatch(clearTrackedChanges(view_19.state));
16119
+ 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));
15696
16120
  savedBuffer = result_2.buffer;
15697
16121
  } else {
15698
16122
  if (usesCanonicalSession(experimentalSession, CANONICAL_GAP.save)) return null;
15699
- const view_20 = pagedEditorRef.current?.getView();
15700
- const editorState_0 = view_20?.state;
16123
+ const view_19 = pagedEditorRef.current?.getView();
16124
+ const editorState_0 = view_19?.state;
15701
16125
  const baselineBuffer = originalBufferRef.current;
15702
16126
  const current = buildCurrentDocument();
15703
16127
  const doc_1 = current ? withoutUnreferencedNotes(current) : null;
@@ -15738,9 +16162,9 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
15738
16162
  const { compareSelectiveVsFull } = await import("@stll/folio-core/docx/selectiveSaveTripwire");
15739
16163
  tripwireResult = await compareSelectiveVsFull(selectiveBuffer, fullBuffer);
15740
16164
  } catch {}
15741
- if (view_20 && pagedEditorRef.current?.getView() === view_20 && view_20.state.doc === editorState_0?.doc) {
16165
+ if (view_19 && pagedEditorRef.current?.getView() === view_19 && view_19.state.doc === editorState_0?.doc) {
15742
16166
  originalBufferRef.current = buffer;
15743
- view_20.dispatch(clearTrackedChanges(view_20.state));
16167
+ view_19.dispatch(clearTrackedChanges(view_19.state));
15744
16168
  }
15745
16169
  savedBuffer = buffer;
15746
16170
  }
@@ -15785,11 +16209,20 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
15785
16209
  onError?.(error_1);
15786
16210
  }, [onError]);
15787
16211
  useImperativeHandle(ref, () => ({
16212
+ getReadOnlyReason: () => readOnlyReason,
15788
16213
  getDocument: () => buildCurrentDocument(),
16214
+ find: (searchText, options_1) => handleFind(searchText, {
16215
+ ...createDefaultFindOptions(),
16216
+ ...options_1
16217
+ }),
16218
+ findNext: handleFindNext,
16219
+ findPrevious: handleFindPrevious,
16220
+ getFindResult,
16221
+ clearFind: resetFindResult,
15789
16222
  hasPendingChanges: () => {
15790
- const view_21 = pagedEditorRef.current?.getView();
15791
- if (!view_21) return false;
15792
- return getCommentsDirty() || getChangedParagraphIds(view_21.state).size > 0 || hasStructuralChanges(view_21.state) || hasUntrackedChanges(view_21.state);
16223
+ const view_20 = pagedEditorRef.current?.getView();
16224
+ if (!view_20) return false;
16225
+ return getCommentsDirty() || getChangedParagraphIds(view_20.state).size > 0 || hasStructuralChanges(view_20.state) || hasUntrackedChanges(view_20.state);
15793
16226
  },
15794
16227
  getEditorRef: () => pagedEditorRef.current,
15795
16228
  getEditor: () => pagedEditorRef.current?.getEditor() ?? null,
@@ -15804,13 +16237,17 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
15804
16237
  scrollToPage: (pageNumber_0) => {
15805
16238
  pagedEditorRef.current?.scrollToPage(pageNumber_0);
15806
16239
  },
15807
- scrollToParaId: (paraId, options_1) => pagedEditorRef.current?.scrollToParaId(paraId, options_1) ?? false,
16240
+ scrollToParaId: (paraId, options_2) => pagedEditorRef.current?.scrollToParaId(paraId, options_2) ?? false,
15808
16241
  openPrintPreview: handleDirectPrint,
15809
16242
  print: handleDirectPrint,
15810
16243
  openFind: () => {
15811
16244
  openFind(readFindSelectionSeed());
15812
16245
  },
15813
16246
  openReplace: () => {
16247
+ if (readOnlyReason) {
16248
+ notifyReadonlyEditAttempt();
16249
+ return;
16250
+ }
15814
16251
  openReplace(readFindSelectionSeed());
15815
16252
  },
15816
16253
  loadDocument: (document_0) => {
@@ -15826,17 +16263,17 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
15826
16263
  pendingSuggestionRegistryRef.current.clear();
15827
16264
  return pagedEditorRef.current?.getEditor().loadDocx(buffer_1) ?? loadBuffer(buffer_1);
15828
16265
  },
15829
- ensureEditorView: (options_2) => {
15830
- pagedEditorRef.current?.ensureView(options_2);
16266
+ ensureEditorView: (options_3) => {
16267
+ pagedEditorRef.current?.ensureView(options_3);
15831
16268
  },
15832
16269
  createAIEditSnapshot: () => {
15833
- const view_22 = pagedEditorRef.current?.getView();
15834
- return view_22 ? createFolioAIEditSnapshot(view_22.state.doc) : null;
16270
+ const view_21 = pagedEditorRef.current?.getView();
16271
+ return view_21 ? createFolioAIEditSnapshot(view_21.state.doc) : null;
15835
16272
  },
15836
- applyDocumentOperations: ({ undefinedReferences, snapshot: snapshot_0, batch, author: operationAuthor = author }) => {
16273
+ applyDocumentOperations: ({ undefinedReferences, snapshot: snapshot_1, batch, author: operationAuthor = author }) => {
15837
16274
  assertSupportedFolioDocumentOperationVersion(batch.version);
15838
- const view_23 = pagedEditorRef.current?.getView();
15839
- if (!view_23) {
16275
+ const view_22 = pagedEditorRef.current?.getView();
16276
+ if (!view_22) {
15840
16277
  let status = "committed";
15841
16278
  if (batch.dryRun === true) status = "previewed";
15842
16279
  else if (batch.atomic === true) status = "rejected";
@@ -15856,27 +16293,27 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
15856
16293
  }
15857
16294
  const canonical_1 = getCanonicalApi()?.applyCanonicalDocumentOperations({
15858
16295
  undefinedReferences,
15859
- snapshot: snapshot_0,
16296
+ snapshot: snapshot_1,
15860
16297
  batch,
15861
16298
  author: operationAuthor
15862
16299
  });
15863
16300
  if (canonical_1) return canonical_1;
15864
16301
  const existingUndoEntry = documentOperationUndoEntriesRef.current.at(-1);
15865
- if (existingUndoEntry && (!view_23.state.doc.eq(existingUndoEntry.afterState.doc) || canonicalJson(commentsRef.current) !== existingUndoEntry.commentsAfterJson)) documentOperationUndoEntriesRef.current.length = 0;
16302
+ if (existingUndoEntry && (!view_22.state.doc.eq(existingUndoEntry.afterState.doc) || canonicalJson(commentsRef.current) !== existingUndoEntry.commentsAfterJson)) documentOperationUndoEntriesRef.current.length = 0;
15866
16303
  const commentsBefore = commentsRef.current;
15867
16304
  const createdComments = [];
15868
16305
  const operationView = {
15869
- state: view_23.state,
16306
+ state: view_22.state,
15870
16307
  dispatch: (transaction) => {
15871
- view_23.dispatch(closeHistory(transaction));
15872
- operationView.state = view_23.state;
16308
+ view_22.dispatch(closeHistory(transaction));
16309
+ operationView.state = view_22.state;
15873
16310
  }
15874
16311
  };
15875
- const activeSuggestionIds = new Set(getSuggestions(view_23.state).map((s_0) => s_0.suggestionId));
16312
+ const activeSuggestionIds = new Set(getSuggestions(view_22.state).map((s_0) => s_0.suggestionId));
15876
16313
  const result_3 = applyFolioDocumentOperations({
15877
16314
  undefinedReferences,
15878
16315
  view: operationView,
15879
- snapshot: snapshot_0,
16316
+ snapshot: snapshot_1,
15880
16317
  batch,
15881
16318
  author: operationAuthor,
15882
16319
  createCommentId: (text_3) => {
@@ -15890,7 +16327,7 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
15890
16327
  })
15891
16328
  });
15892
16329
  if (batch.mode === "suggested" && result_3.status === "committed") pendingSuggestionRegistryRef.current.recordApplied({
15893
- snapshot: snapshot_0,
16330
+ snapshot: snapshot_1,
15894
16331
  story: { type: "main" },
15895
16332
  operations: batch.operations,
15896
16333
  applied: result_3.applied,
@@ -15902,7 +16339,7 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
15902
16339
  if (batchComments.length > 0) replaceComments(commentsAfter);
15903
16340
  if (result_3.undoHandle !== null) documentOperationUndoEntriesRef.current.push({
15904
16341
  undoHandle: result_3.undoHandle,
15905
- afterState: view_23.state,
16342
+ afterState: view_22.state,
15906
16343
  commentsBefore,
15907
16344
  commentsAfterJson: canonicalJson(commentsAfter)
15908
16345
  });
@@ -15924,18 +16361,18 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
15924
16361
  reason: "notLatest"
15925
16362
  };
15926
16363
  const entry_3 = entries_0.at(-1);
15927
- const view_24 = pagedEditorRef.current?.getView();
15928
- if (!entry_3 || !view_24) return {
16364
+ const view_23 = pagedEditorRef.current?.getView();
16365
+ if (!entry_3 || !view_23) return {
15929
16366
  status: "rejected",
15930
16367
  undoHandle,
15931
16368
  reason: "unknownHandle"
15932
16369
  };
15933
- if (!view_24.state.doc.eq(entry_3.afterState.doc) || canonicalJson(commentsRef.current) !== entry_3.commentsAfterJson) return {
16370
+ if (!view_23.state.doc.eq(entry_3.afterState.doc) || canonicalJson(commentsRef.current) !== entry_3.commentsAfterJson) return {
15934
16371
  status: "rejected",
15935
16372
  undoHandle,
15936
16373
  reason: "documentChanged"
15937
16374
  };
15938
- if (!undo(view_24.state, view_24.dispatch)) return {
16375
+ if (!undo(view_23.state, view_23.dispatch)) return {
15939
16376
  status: "rejected",
15940
16377
  undoHandle,
15941
16378
  reason: "documentChanged"
@@ -15948,9 +16385,9 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
15948
16385
  undoHandle
15949
16386
  };
15950
16387
  },
15951
- applyAIEditOperations: ({ undefinedReferences: undefinedReferences_0, snapshot: snapshot_1, operations, mode = "tracked-changes", author: operationAuthor_0 = author }) => {
15952
- const view_25 = pagedEditorRef.current?.getView();
15953
- if (!view_25) return {
16388
+ applyAIEditOperations: ({ undefinedReferences: undefinedReferences_0, snapshot: snapshot_2, operations, mode = "tracked-changes", author: operationAuthor_0 = author }) => {
16389
+ const view_24 = pagedEditorRef.current?.getView();
16390
+ if (!view_24) return {
15954
16391
  applied: [],
15955
16392
  skipped: operations.map((operation_0) => ({
15956
16393
  id: operation_0.id,
@@ -15959,7 +16396,7 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
15959
16396
  };
15960
16397
  const canonical_3 = getCanonicalApi()?.applyCanonicalDocumentOperations({
15961
16398
  undefinedReferences: undefinedReferences_0,
15962
- snapshot: snapshot_1,
16399
+ snapshot: snapshot_2,
15963
16400
  batch: {
15964
16401
  version: FOLIO_DOCUMENT_OPERATION_CONTRACT_VERSION,
15965
16402
  operations,
@@ -15969,11 +16406,11 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
15969
16406
  });
15970
16407
  if (canonical_3) return canonical_3;
15971
16408
  const createdComments_0 = [];
15972
- const activeSuggestionIds_0 = new Set(getSuggestions(view_25.state).map((s_1) => s_1.suggestionId));
16409
+ const activeSuggestionIds_0 = new Set(getSuggestions(view_24.state).map((s_1) => s_1.suggestionId));
15973
16410
  const { applied: applied_0, skipped: skipped_0 } = applyFolioDocumentOperations({
15974
16411
  undefinedReferences: undefinedReferences_0,
15975
- view: view_25,
15976
- snapshot: snapshot_1,
16412
+ view: view_24,
16413
+ snapshot: snapshot_2,
15977
16414
  batch: {
15978
16415
  version: FOLIO_DOCUMENT_OPERATION_CONTRACT_VERSION,
15979
16416
  operations,
@@ -15989,7 +16426,7 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
15989
16426
  const batchComments_0 = appliedOperationComments(createdComments_0, applied_0);
15990
16427
  if (batchComments_0.length > 0) updateComments((currentComments_0) => [...currentComments_0, ...batchComments_0]);
15991
16428
  if (mode === "suggested") pendingSuggestionRegistryRef.current.recordApplied({
15992
- snapshot: snapshot_1,
16429
+ snapshot: snapshot_2,
15993
16430
  story: { type: "main" },
15994
16431
  operations,
15995
16432
  applied: applied_0,
@@ -16002,18 +16439,18 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
16002
16439
  };
16003
16440
  },
16004
16441
  acceptAIEditOperation: (revisionId) => {
16005
- const view_26 = pagedEditorRef.current?.getView();
16006
- if (!view_26) return false;
16442
+ const view_25 = pagedEditorRef.current?.getView();
16443
+ if (!view_25) return false;
16007
16444
  const editor_5 = pagedEditorRef.current?.getEditor();
16008
16445
  if (editor_5?.getCanonicalDocument()) return editor_5.resolveCanonicalRevisions(typeof revisionId === "number" ? [revisionId] : revisionId, "accept");
16009
- return acceptAIEditRevision(revisionId)(view_26.state, view_26.dispatch);
16446
+ return acceptAIEditRevision(revisionId)(view_25.state, view_25.dispatch);
16010
16447
  },
16011
16448
  rejectAIEditOperation: (revisionId_0) => {
16012
- const view_27 = pagedEditorRef.current?.getView();
16013
- if (!view_27) return false;
16449
+ const view_26 = pagedEditorRef.current?.getView();
16450
+ if (!view_26) return false;
16014
16451
  const editor_6 = pagedEditorRef.current?.getEditor();
16015
16452
  if (editor_6?.getCanonicalDocument()) return editor_6.resolveCanonicalRevisions(typeof revisionId_0 === "number" ? [revisionId_0] : revisionId_0, "reject");
16016
- return rejectAIEditRevision(revisionId_0)(view_27.state, view_27.dispatch);
16453
+ return rejectAIEditRevision(revisionId_0)(view_26.state, view_26.dispatch);
16017
16454
  },
16018
16455
  undo: () => {
16019
16456
  if (!usesCanonicalSession(experimentalSession, CANONICAL_GAP.authorityRouting) && getActiveEditorStory().type === "headerFooter" && hfEditorRef.current) return hfEditorRef.current.undo();
@@ -16028,45 +16465,45 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
16028
16465
  return redone;
16029
16466
  },
16030
16467
  scrollToAIEditOperation: (revisionId_1) => {
16031
- const view_28 = pagedEditorRef.current?.getView();
16032
- if (!view_28) return false;
16033
- const range_2 = findAIEditRevisionRange(view_28.state, revisionId_1);
16034
- if (!range_2) return false;
16035
- const { from: from_8, to: to_8 } = clampRangeToDocSize(view_28.state.doc.content.size, range_2);
16036
- const $from = view_28.state.doc.resolve(from_8);
16037
- const $to = view_28.state.doc.resolve(to_8);
16038
- view_28.dispatch(view_28.state.tr.setSelection(TextSelection.between($from, $to)));
16468
+ const view_27 = pagedEditorRef.current?.getView();
16469
+ if (!view_27) return false;
16470
+ const range_1 = findAIEditRevisionRange(view_27.state, revisionId_1);
16471
+ if (!range_1) return false;
16472
+ const { from: from_8, to: to_8 } = clampRangeToDocSize(view_27.state.doc.content.size, range_1);
16473
+ const $from = view_27.state.doc.resolve(from_8);
16474
+ const $to = view_27.state.doc.resolve(to_8);
16475
+ view_27.dispatch(view_27.state.tr.setSelection(TextSelection.between($from, $to)));
16039
16476
  requestAnimationFrame(() => {
16040
16477
  pagedEditorRef.current?.scrollToPosition(from_8);
16041
16478
  });
16042
16479
  return true;
16043
16480
  },
16044
- scrollToBlock: (blockId, snapshot_2) => {
16045
- const view_29 = pagedEditorRef.current?.getView();
16046
- if (!view_29) return false;
16047
- const range_3 = resolveFolioAIBlockRange({
16481
+ scrollToBlock: (blockId, snapshot_3) => {
16482
+ const view_28 = pagedEditorRef.current?.getView();
16483
+ if (!view_28) return false;
16484
+ const range_2 = resolveFolioAIBlockRange({
16048
16485
  blockId,
16049
- doc: view_29.state.doc,
16050
- snapshot: snapshot_2
16486
+ doc: view_28.state.doc,
16487
+ snapshot: snapshot_3
16051
16488
  });
16052
- if (range_3 === null) return false;
16053
- const { from: from_9, to: to_9 } = range_3;
16054
- const $from_0 = view_29.state.doc.resolve(from_9);
16055
- const $to_0 = view_29.state.doc.resolve(to_9);
16056
- view_29.dispatch(view_29.state.tr.setSelection(TextSelection.between($from_0, $to_0)));
16489
+ if (range_2 === null) return false;
16490
+ const { from: from_9, to: to_9 } = range_2;
16491
+ const $from_0 = view_28.state.doc.resolve(from_9);
16492
+ const $to_0 = view_28.state.doc.resolve(to_9);
16493
+ view_28.dispatch(view_28.state.tr.setSelection(TextSelection.between($from_0, $to_0)));
16057
16494
  requestAnimationFrame(() => {
16058
16495
  pagedEditorRef.current?.scrollToPosition(from_9);
16059
16496
  });
16060
16497
  return true;
16061
16498
  },
16062
- highlightPassage: ({ blockId: blockId_0, text: text_5, snapshot: snapshot_3 }) => {
16063
- const view_30 = pagedEditorRef.current?.getView();
16064
- if (!view_30) return "none";
16499
+ highlightPassage: ({ blockId: blockId_0, text: text_5, snapshot: snapshot_4 }) => {
16500
+ const view_29 = pagedEditorRef.current?.getView();
16501
+ if (!view_29) return "none";
16065
16502
  const passageRange = resolvePassageRange({
16066
16503
  blockId: blockId_0,
16067
16504
  text: text_5,
16068
- doc: view_30.state.doc,
16069
- snapshot: snapshot_3
16505
+ doc: view_29.state.doc,
16506
+ snapshot: snapshot_4
16070
16507
  });
16071
16508
  if (passageRange !== null) {
16072
16509
  pagedEditorRef.current?.setPassageHighlight(passageRange);
@@ -16078,16 +16515,16 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
16078
16515
  pagedEditorRef.current?.setPassageHighlight(null);
16079
16516
  const blockRange = resolveFolioAIBlockRange({
16080
16517
  blockId: blockId_0,
16081
- doc: view_30.state.doc,
16082
- snapshot: snapshot_3
16518
+ doc: view_29.state.doc,
16519
+ snapshot: snapshot_4
16083
16520
  });
16084
16521
  if (blockRange === null) return "none";
16085
16522
  const paraId_0 = getFolioParaIdFromBlockId(blockId_0);
16086
16523
  if (paraId_0 !== null && pagedEditorRef.current?.scrollToParaId(paraId_0, { highlight: {} })) return "block";
16087
16524
  const { from: from_10, to: to_10 } = blockRange;
16088
- const $from_1 = view_30.state.doc.resolve(from_10);
16089
- const $to_1 = view_30.state.doc.resolve(to_10);
16090
- view_30.dispatch(view_30.state.tr.setSelection(TextSelection.between($from_1, $to_1)));
16525
+ const $from_1 = view_29.state.doc.resolve(from_10);
16526
+ const $to_1 = view_29.state.doc.resolve(to_10);
16527
+ view_29.dispatch(view_29.state.tr.setSelection(TextSelection.between($from_1, $to_1)));
16091
16528
  requestAnimationFrame(() => {
16092
16529
  pagedEditorRef.current?.scrollToPosition(from_10);
16093
16530
  });
@@ -16096,59 +16533,59 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
16096
16533
  clearPassageHighlight: () => {
16097
16534
  pagedEditorRef.current?.setPassageHighlight(null);
16098
16535
  },
16099
- showInDocument: (target_1, snapshot_4) => {
16100
- const view_31 = pagedEditorRef.current?.getView();
16101
- if (!view_31) return false;
16102
- const range_4 = target_1.type === "textRange" ? resolveFolioAITextRange({
16536
+ showInDocument: (target_1, snapshot_5) => {
16537
+ const view_30 = pagedEditorRef.current?.getView();
16538
+ if (!view_30) return false;
16539
+ const range_3 = target_1.type === "textRange" ? resolveFolioAITextRange({
16103
16540
  range: target_1,
16104
- doc: view_31.state.doc,
16105
- snapshot: snapshot_4
16541
+ doc: view_30.state.doc,
16542
+ snapshot: snapshot_5
16106
16543
  }) : resolveFolioAIBlockRange({
16107
16544
  blockId: target_1.blockId,
16108
- doc: view_31.state.doc,
16109
- snapshot: snapshot_4
16545
+ doc: view_30.state.doc,
16546
+ snapshot: snapshot_5
16110
16547
  });
16111
- if (range_4 === null) return false;
16112
- const { from: from_11, to: to_11 } = range_4;
16113
- const $from_2 = view_31.state.doc.resolve(from_11);
16114
- const $to_2 = view_31.state.doc.resolve(to_11);
16115
- view_31.dispatch(view_31.state.tr.setSelection(TextSelection.between($from_2, $to_2)));
16548
+ if (range_3 === null) return false;
16549
+ const { from: from_11, to: to_11 } = range_3;
16550
+ const $from_2 = view_30.state.doc.resolve(from_11);
16551
+ const $to_2 = view_30.state.doc.resolve(to_11);
16552
+ view_30.dispatch(view_30.state.tr.setSelection(TextSelection.between($from_2, $to_2)));
16116
16553
  requestAnimationFrame(() => {
16117
16554
  pagedEditorRef.current?.scrollToPosition(from_11);
16118
16555
  });
16119
16556
  return true;
16120
16557
  },
16121
16558
  getSuggestions: () => {
16122
- const view_32 = pagedEditorRef.current?.getView();
16123
- return view_32 ? getSuggestions(view_32.state) : [];
16559
+ const view_31 = pagedEditorRef.current?.getView();
16560
+ return view_31 ? getSuggestions(view_31.state) : [];
16124
16561
  },
16125
16562
  exportPendingSuggestions: () => {
16126
- const view_33 = pagedEditorRef.current?.getView();
16127
- const activeIds = new Set(view_33 ? getSuggestions(view_33.state).map((s_2) => s_2.suggestionId) : []);
16563
+ const view_32 = pagedEditorRef.current?.getView();
16564
+ const activeIds = new Set(view_32 ? getSuggestions(view_32.state).map((s_2) => s_2.suggestionId) : []);
16128
16565
  return pendingSuggestionRegistryRef.current.exportPendingSuggestions({
16129
16566
  activeSuggestionIds: activeIds,
16130
- snapshotForStory: (story_0, commentIds) => story_0.type === "main" && view_33 ? createPendingSuggestionSourceSnapshot(view_33.state, commentIds) : null
16567
+ snapshotForStory: (story_0, commentIds) => story_0.type === "main" && view_32 ? createPendingSuggestionSourceSnapshot(view_32.state, commentIds) : null
16131
16568
  });
16132
16569
  },
16133
16570
  loadPendingSuggestions: (records) => pendingSuggestionRegistryRef.current.loadPendingSuggestions({
16134
16571
  records,
16135
16572
  snapshotForStory: (story_1) => {
16136
- const view_34 = pagedEditorRef.current?.getView();
16137
- return story_1.type === "main" && view_34 ? createFolioAIEditSnapshot(view_34.state.doc) : null;
16573
+ const view_33 = pagedEditorRef.current?.getView();
16574
+ return story_1.type === "main" && view_33 ? createFolioAIEditSnapshot(view_33.state.doc) : null;
16138
16575
  },
16139
16576
  sourceSnapshotForStory: (story_2, commentIds_0) => {
16140
- const view_35 = pagedEditorRef.current?.getView();
16141
- return story_2.type === "main" && view_35 ? createPendingSuggestionSourceSnapshot(view_35.state, commentIds_0) : null;
16577
+ const view_34 = pagedEditorRef.current?.getView();
16578
+ return story_2.type === "main" && view_34 ? createPendingSuggestionSourceSnapshot(view_34.state, commentIds_0) : null;
16142
16579
  },
16143
- apply: (record, snapshot_5) => {
16144
- const view_36 = pagedEditorRef.current?.getView();
16145
- if (!view_36) return {
16580
+ apply: (record, snapshot_6) => {
16581
+ const view_35 = pagedEditorRef.current?.getView();
16582
+ if (!view_35) return {
16146
16583
  applied: [],
16147
16584
  skipped: []
16148
16585
  };
16149
16586
  const canonical_4 = getCanonicalApi()?.applyCanonicalDocumentOperations({
16150
16587
  undefinedReferences: "refuse",
16151
- snapshot: snapshot_5,
16588
+ snapshot: snapshot_6,
16152
16589
  batch: {
16153
16590
  version: FOLIO_DOCUMENT_OPERATION_CONTRACT_VERSION,
16154
16591
  operations: [record.operation],
@@ -16160,8 +16597,8 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
16160
16597
  const createdComments_1 = [];
16161
16598
  const result_4 = applyFolioDocumentOperations({
16162
16599
  undefinedReferences: "refuse",
16163
- view: view_36,
16164
- snapshot: snapshot_5,
16600
+ view: view_35,
16601
+ snapshot: snapshot_6,
16165
16602
  batch: {
16166
16603
  version: FOLIO_DOCUMENT_OPERATION_CONTRACT_VERSION,
16167
16604
  operations: [record.operation],
@@ -16182,128 +16619,141 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
16182
16619
  };
16183
16620
  },
16184
16621
  activeSuggestionIds: () => {
16185
- const view_37 = pagedEditorRef.current?.getView();
16186
- return new Set(view_37 ? getSuggestions(view_37.state).map((s_3) => s_3.suggestionId) : []);
16622
+ const view_36 = pagedEditorRef.current?.getView();
16623
+ return new Set(view_36 ? getSuggestions(view_36.state).map((s_3) => s_3.suggestionId) : []);
16187
16624
  }
16188
16625
  }),
16189
- acceptSuggestion: (suggestionId, options_3) => {
16190
- const view_38 = pagedEditorRef.current?.getView();
16191
- if (!view_38) return {
16626
+ acceptSuggestion: (suggestionId, options_4) => {
16627
+ const view_37 = pagedEditorRef.current?.getView();
16628
+ if (!view_37) return {
16192
16629
  accepted: false,
16193
16630
  appliedAs: null
16194
16631
  };
16195
- const appliedAs = getSuggestions(view_38.state).find((s_4) => s_4.suggestionId === suggestionId)?.appliedAs ?? null;
16196
- const accepted = acceptSuggestion(suggestionId, { author: options_3?.author ?? author })(view_38.state, view_38.dispatch);
16632
+ const appliedAs = getSuggestions(view_37.state).find((s_4) => s_4.suggestionId === suggestionId)?.appliedAs ?? null;
16633
+ const accepted = acceptSuggestion(suggestionId, { author: options_4?.author ?? author })(view_37.state, view_37.dispatch);
16197
16634
  return {
16198
16635
  accepted,
16199
16636
  appliedAs: accepted ? appliedAs : null
16200
16637
  };
16201
16638
  },
16202
16639
  rejectSuggestion: (suggestionId_0) => {
16203
- const view_39 = pagedEditorRef.current?.getView();
16204
- if (!view_39) return false;
16205
- return rejectSuggestion(suggestionId_0)(view_39.state, view_39.dispatch);
16640
+ const view_38 = pagedEditorRef.current?.getView();
16641
+ if (!view_38) return false;
16642
+ return rejectSuggestion(suggestionId_0)(view_38.state, view_38.dispatch);
16206
16643
  },
16207
16644
  scrollToSuggestion: (suggestionId_1) => {
16208
- const view_40 = pagedEditorRef.current?.getView();
16209
- if (!view_40) return false;
16210
- const range_5 = findSuggestionRange(view_40.state, suggestionId_1);
16211
- if (!range_5) return false;
16212
- const { from: from_12, to: to_12 } = clampRangeToDocSize(view_40.state.doc.content.size, range_5);
16213
- const $from_3 = view_40.state.doc.resolve(from_12);
16214
- const $to_3 = view_40.state.doc.resolve(to_12);
16215
- view_40.dispatch(view_40.state.tr.setSelection(TextSelection.between($from_3, $to_3)));
16645
+ const view_39 = pagedEditorRef.current?.getView();
16646
+ if (!view_39) return false;
16647
+ const range_4 = findSuggestionRange(view_39.state, suggestionId_1);
16648
+ if (!range_4) return false;
16649
+ const { from: from_12, to: to_12 } = clampRangeToDocSize(view_39.state.doc.content.size, range_4);
16650
+ const $from_3 = view_39.state.doc.resolve(from_12);
16651
+ const $to_3 = view_39.state.doc.resolve(to_12);
16652
+ view_39.dispatch(view_39.state.tr.setSelection(TextSelection.between($from_3, $to_3)));
16216
16653
  requestAnimationFrame(() => {
16217
16654
  pagedEditorRef.current?.scrollToPosition(from_12);
16218
16655
  });
16219
16656
  return true;
16220
16657
  },
16221
16658
  getTrackedChanges: () => {
16222
- const view_41 = pagedEditorRef.current?.getView();
16223
- return view_41 ? getTrackedChangesFromDoc(view_41.state.doc) : [];
16659
+ const view_40 = pagedEditorRef.current?.getView();
16660
+ return view_40 ? getTrackedChangesFromDoc(view_40.state.doc) : [];
16224
16661
  },
16225
16662
  getCommentAnchors: () => {
16226
- const view_42 = pagedEditorRef.current?.getView();
16227
- return view_42 ? getCommentAnchorsFromDoc(view_42.state.doc) : [];
16663
+ const view_41 = pagedEditorRef.current?.getView();
16664
+ return view_41 ? getCommentAnchorsFromDoc(view_41.state.doc) : [];
16228
16665
  },
16229
16666
  getSelectionText: () => {
16230
- const view_43 = pagedEditorRef.current?.getView();
16231
- return view_43 ? getSelectedText(view_43.state) : "";
16667
+ const view_42 = pagedEditorRef.current?.getView();
16668
+ return view_42 ? getSelectedText(view_42.state) : "";
16232
16669
  },
16233
16670
  getPageText: (page_1) => {
16671
+ const view_43 = pagedEditorRef.current?.getView();
16672
+ if (!view_43) return null;
16673
+ return getPageTextFromLayout({
16674
+ layout: pagedEditorRef.current?.getEditor()?.getLayout() ?? null,
16675
+ doc: view_43.state.doc,
16676
+ page: page_1,
16677
+ projection: projectMarkupView(view_43.state, displayMode)
16678
+ });
16679
+ },
16680
+ getTargetPage: (target_2, snapshot_7) => {
16234
16681
  const view_44 = pagedEditorRef.current?.getView();
16235
16682
  if (!view_44) return null;
16236
- return getPageTextFromLayout(pagedEditorRef.current?.getEditor()?.getLayout() ?? null, view_44.state.doc, page_1);
16237
- },
16238
- getTargetPage: (target_2, snapshot_6) => {
16239
- const view_45 = pagedEditorRef.current?.getView();
16240
- if (!view_45) return null;
16241
- const range_6 = target_2.type === "textRange" ? resolveFolioAITextRange({
16683
+ const range_5 = target_2.type === "textRange" ? resolveFolioAITextRange({
16242
16684
  range: target_2,
16243
- doc: view_45.state.doc,
16244
- snapshot: snapshot_6
16685
+ doc: view_44.state.doc,
16686
+ snapshot: snapshot_7
16245
16687
  }) : resolveFolioAIBlockRange({
16246
16688
  blockId: target_2.blockId,
16247
- doc: view_45.state.doc,
16248
- snapshot: snapshot_6
16689
+ doc: view_44.state.doc,
16690
+ snapshot: snapshot_7
16249
16691
  });
16250
- if (range_6 === null) return null;
16251
- return pagedEditorRef.current?.getPageNumberForPmPos(range_6.from) ?? null;
16692
+ if (range_5 === null) return null;
16693
+ return pagedEditorRef.current?.getPageNumberForPmPos(range_5.from) ?? null;
16252
16694
  },
16253
16695
  getBlockRect: (blockId_1) => pagedEditorRef.current?.getBlockRect(blockId_1) ?? null,
16254
16696
  getBlockRects: (blockIds) => pagedEditorRef.current?.getBlockRects(blockIds) ?? /* @__PURE__ */ new Map(),
16255
16697
  getScrollRoot: () => pagedEditorRef.current?.getScrollRoot() ?? null,
16256
16698
  onLayoutChange: (listener) => pagedEditorRef.current?.onLayoutChange(listener) ?? (() => {}),
16257
16699
  getContentControls: (filter = {}) => {
16258
- const view_46 = pagedEditorRef.current?.getView();
16259
- if (!view_46) return [];
16260
- return findBlockSdtMatches(view_46.state.doc, filter).map((match_0) => ({
16700
+ const view_45 = pagedEditorRef.current?.getView();
16701
+ if (!view_45) return [];
16702
+ return findBlockSdtMatches(view_45.state.doc, filter).map((match_0) => ({
16261
16703
  properties: blockSdtAttrsToSdtProperties(match_0.node),
16262
16704
  path: match_0.path,
16263
16705
  pmPos: match_0.pos
16264
16706
  }));
16265
16707
  },
16266
16708
  scrollToContentControl: (filter_0) => {
16267
- const view_47 = pagedEditorRef.current?.getView();
16268
- if (!view_47) return false;
16269
- const match_1 = findBlockSdtMatch(view_47.state.doc, filter_0);
16709
+ const view_46 = pagedEditorRef.current?.getView();
16710
+ if (!view_46) return false;
16711
+ const match_1 = findBlockSdtMatch(view_46.state.doc, filter_0);
16270
16712
  if (!match_1) return false;
16271
16713
  const inside = match_1.pos + 1;
16272
- const $pos = view_47.state.doc.resolve(inside);
16273
- view_47.dispatch(view_47.state.tr.setSelection(TextSelection.near($pos)));
16714
+ const $pos = view_46.state.doc.resolve(inside);
16715
+ view_46.dispatch(view_46.state.tr.setSelection(TextSelection.near($pos)));
16274
16716
  requestAnimationFrame(() => {
16275
16717
  pagedEditorRef.current?.scrollToPosition(inside);
16276
16718
  });
16277
16719
  return true;
16278
16720
  },
16279
- setContentControlContent: (filter_1, input, options_4 = {}) => {
16280
- const view_48 = pagedEditorRef.current?.getView();
16281
- if (!view_48) return false;
16282
- const tr_0 = typeof input === "string" ? setContentControlContentTr(view_48.state, filter_1, input, options_4) : setContentControlContentBlocksTr(view_48.state, filter_1, input, options_4);
16721
+ setContentControlContent: (filter_1, input, options_5 = {}) => {
16722
+ const view_47 = pagedEditorRef.current?.getView();
16723
+ if (!view_47) return false;
16724
+ const tr_0 = typeof input === "string" ? setContentControlContentTr(view_47.state, filter_1, input, options_5) : setContentControlContentBlocksTr(view_47.state, filter_1, input, options_5);
16283
16725
  if (!tr_0) return false;
16284
- view_48.dispatch(tr_0);
16726
+ view_47.dispatch(tr_0);
16285
16727
  return true;
16286
16728
  },
16287
- setContentControlValue: (filter_2, input_0, options_5 = {}) => {
16288
- const view_49 = pagedEditorRef.current?.getView();
16289
- if (!view_49) return false;
16290
- const tr_1 = setContentControlValueTr(view_49.state, filter_2, input_0, options_5);
16729
+ setContentControlValue: (filter_2, input_0, options_6 = {}) => {
16730
+ const view_48 = pagedEditorRef.current?.getView();
16731
+ if (!view_48) return false;
16732
+ const tr_1 = setContentControlValueTr(view_48.state, filter_2, input_0, options_6);
16291
16733
  if (!tr_1) return false;
16292
- view_49.dispatch(tr_1);
16734
+ view_48.dispatch(tr_1);
16293
16735
  return true;
16294
16736
  },
16295
- removeContentControl: (filter_3, options_6 = {}) => {
16296
- const view_50 = pagedEditorRef.current?.getView();
16297
- if (!view_50) return false;
16298
- const tr_2 = removeContentControlTr(view_50.state, filter_3, options_6);
16737
+ removeContentControl: (filter_3, options_7 = {}) => {
16738
+ const view_49 = pagedEditorRef.current?.getView();
16739
+ if (!view_49) return false;
16740
+ const tr_2 = removeContentControlTr(view_49.state, filter_3, options_7);
16299
16741
  if (!tr_2) return false;
16300
- view_50.dispatch(tr_2);
16742
+ view_49.dispatch(tr_2);
16301
16743
  return true;
16302
16744
  }
16303
16745
  }), [
16304
16746
  author,
16305
16747
  buildCurrentDocument,
16748
+ displayMode,
16749
+ readOnlyReason,
16750
+ notifyReadonlyEditAttempt,
16306
16751
  scrollPageInfo,
16752
+ handleFind,
16753
+ handleFindNext,
16754
+ handleFindPrevious,
16755
+ getFindResult,
16756
+ resetFindResult,
16307
16757
  handleSave,
16308
16758
  setZoomWithViewportAnchor,
16309
16759
  zoomRef,
@@ -16382,47 +16832,47 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
16382
16832
  if (isDisplayMode(value)) setDisplayMode(value);
16383
16833
  }, [setDisplayMode]);
16384
16834
  const handleAcceptActiveChange = useCallback(() => {
16385
- const view_51 = pagedEditorRef.current?.getView();
16386
- if (!view_51) return;
16387
- const { from: from_13, to: to_13 } = view_51.state.selection;
16388
- const range_7 = findChangeAtPosition(view_51.state, from_13, to_13);
16835
+ const view_50 = pagedEditorRef.current?.getView();
16836
+ if (!view_50) return;
16837
+ const { from: from_13, to: to_13 } = view_50.state.selection;
16838
+ const range_6 = findChangeAtPosition(view_50.state, from_13, to_13);
16389
16839
  if (resolveCanonicalReviewRange({
16390
16840
  editor: pagedEditorRef.current?.getEditor(),
16391
- ...range_7,
16841
+ ...range_6,
16392
16842
  resolution: "accept"
16393
- }) === null) acceptChange(range_7.from, range_7.to)(view_51.state, view_51.dispatch);
16843
+ }) === null) acceptChange(range_6.from, range_6.to)(view_50.state, view_50.dispatch);
16394
16844
  }, []);
16395
16845
  const handleRejectActiveChange = useCallback(() => {
16396
- const view_52 = pagedEditorRef.current?.getView();
16397
- if (!view_52) return;
16398
- const { from: from_14, to: to_14 } = view_52.state.selection;
16399
- const range_8 = findChangeAtPosition(view_52.state, from_14, to_14);
16846
+ const view_51 = pagedEditorRef.current?.getView();
16847
+ if (!view_51) return;
16848
+ const { from: from_14, to: to_14 } = view_51.state.selection;
16849
+ const range_7 = findChangeAtPosition(view_51.state, from_14, to_14);
16400
16850
  if (resolveCanonicalReviewRange({
16401
16851
  editor: pagedEditorRef.current?.getEditor(),
16402
- ...range_8,
16852
+ ...range_7,
16403
16853
  resolution: "reject"
16404
- }) === null) rejectChange(range_8.from, range_8.to)(view_52.state, view_52.dispatch);
16854
+ }) === null) rejectChange(range_7.from, range_7.to)(view_51.state, view_51.dispatch);
16405
16855
  }, []);
16406
16856
  const handlePreviousChange = useCallback(() => {
16407
- const view_53 = pagedEditorRef.current?.getView();
16408
- if (!view_53) return;
16409
- const { from: from_15 } = view_53.state.selection;
16410
- const change = findPreviousChange(view_53.state, from_15);
16857
+ const view_52 = pagedEditorRef.current?.getView();
16858
+ if (!view_52) return;
16859
+ const { from: from_15 } = view_52.state.selection;
16860
+ const change = findPreviousChange(view_52.state, from_15);
16411
16861
  if (!change) return;
16412
- view_53.dispatch(view_53.state.tr.setSelection(TextSelection.create(view_53.state.doc, change.from, change.to)));
16413
- view_53.focus();
16862
+ view_52.dispatch(view_52.state.tr.setSelection(TextSelection.create(view_52.state.doc, change.from, change.to)));
16863
+ view_52.focus();
16414
16864
  requestAnimationFrame(() => {
16415
16865
  pagedEditorRef.current?.scrollToPosition(change.from);
16416
16866
  });
16417
16867
  }, []);
16418
16868
  const handleNextChange = useCallback(() => {
16419
- const view_54 = pagedEditorRef.current?.getView();
16420
- if (!view_54) return;
16421
- const { to: to_15 } = view_54.state.selection;
16422
- const change_0 = findNextChange(view_54.state, to_15);
16869
+ const view_53 = pagedEditorRef.current?.getView();
16870
+ if (!view_53) return;
16871
+ const { to: to_15 } = view_53.state.selection;
16872
+ const change_0 = findNextChange(view_53.state, to_15);
16423
16873
  if (!change_0) return;
16424
- view_54.dispatch(view_54.state.tr.setSelection(TextSelection.create(view_54.state.doc, change_0.from, change_0.to)));
16425
- view_54.focus();
16874
+ view_53.dispatch(view_53.state.tr.setSelection(TextSelection.create(view_53.state.doc, change_0.from, change_0.to)));
16875
+ view_53.focus();
16426
16876
  requestAnimationFrame(() => {
16427
16877
  pagedEditorRef.current?.scrollToPosition(change_0.from);
16428
16878
  });
@@ -16592,52 +17042,52 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
16592
17042
  requestAnimationFrame(syncCommentHighlightStyles);
16593
17043
  }, [onScrollTopChange, syncCommentHighlightStyles]);
16594
17044
  const handlePagedSelectionChange = useCallback((_from, _to) => {
16595
- const view_55 = getActiveEditorView() ?? pagedEditorRef.current?.getView() ?? null;
16596
- handleSelectionChange(view_55 ? extractSelectionState(view_55.state) : null);
17045
+ const view_54 = getActiveEditorView() ?? pagedEditorRef.current?.getView() ?? null;
17046
+ handleSelectionChange(view_54 ? extractSelectionState(view_54.state) : null);
16597
17047
  }, [getActiveEditorView, handleSelectionChange]);
16598
17048
  const handleTotalPagesChange = useCallback((totalPages) => {
16599
17049
  setScrollPageInfo((previous) => updateScrollPageTotal(previous, totalPages));
16600
17050
  }, [setScrollPageInfo]);
16601
- const handleCommentClick = useCallback((id) => setActiveCommentId(id), [setActiveCommentId]);
16602
- const handleCommentResolve = useCallback((id_0) => {
17051
+ const handleCommentClick = useCallback((id_0) => setActiveCommentId(id_0), [setActiveCommentId]);
17052
+ const handleCommentResolve = useCallback((id_1) => {
16603
17053
  if (applyCanonicalComment({
16604
17054
  type: "resolve",
16605
- id: id_0,
17055
+ id: id_1,
16606
17056
  status: "resolved"
16607
17057
  }) !== null) return;
16608
- updateComments((previous_0) => previous_0.map((comment_2) => comment_2.id === id_0 ? {
17058
+ updateComments((previous_0) => previous_0.map((comment_2) => comment_2.id === id_1 ? {
16609
17059
  ...comment_2,
16610
17060
  done: true
16611
17061
  } : comment_2));
16612
17062
  }, [applyCanonicalComment, updateComments]);
16613
- const handleCommentDelete = useCallback((id_1) => {
17063
+ const handleCommentDelete = useCallback((id_2) => {
16614
17064
  const result_5 = applyCanonicalComment({
16615
17065
  type: "delete",
16616
- id: id_1
17066
+ id: id_2
16617
17067
  });
16618
17068
  if (result_5 !== null) {
16619
- if (result_5.status === "applied" && activeCommentId === id_1) setActiveCommentId(null);
17069
+ if (result_5.status === "applied" && activeCommentId === id_2) setActiveCommentId(null);
16620
17070
  return;
16621
17071
  }
16622
- updateComments((previous_1) => previous_1.filter((comment_3) => comment_3.id !== id_1 && comment_3.parentId !== id_1));
16623
- if (activeCommentId === id_1) setActiveCommentId(null);
17072
+ updateComments((previous_1) => previous_1.filter((comment_3) => comment_3.id !== id_2 && comment_3.parentId !== id_2));
17073
+ if (activeCommentId === id_2) setActiveCommentId(null);
16624
17074
  }, [
16625
17075
  activeCommentId,
16626
17076
  applyCanonicalComment,
16627
17077
  setActiveCommentId,
16628
17078
  updateComments
16629
17079
  ]);
16630
- const handleCommentReply = useCallback((id_2, text_6) => {
17080
+ const handleCommentReply = useCallback((id_3, text_6) => {
16631
17081
  if (applyCanonicalComment({
16632
17082
  type: "create",
16633
17083
  text: text_6,
16634
17084
  author,
16635
17085
  anchor: {
16636
17086
  kind: "reply",
16637
- parentId: id_2
17087
+ parentId: id_3
16638
17088
  }
16639
17089
  }) !== null) return;
16640
- updateComments((previous_2) => [...previous_2, createComment(text_6, author, id_2)]);
17090
+ updateComments((previous_2) => [...previous_2, createComment(text_6, author, id_3)]);
16641
17091
  }, [
16642
17092
  applyCanonicalComment,
16643
17093
  author,
@@ -16645,8 +17095,8 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
16645
17095
  updateComments
16646
17096
  ]);
16647
17097
  const handleAddComment = useCallback((addText) => {
16648
- const view_56 = pagedEditorRef.current?.getView();
16649
- if (!view_56 || !commentSelectionRange) return false;
17098
+ const view_55 = pagedEditorRef.current?.getView();
17099
+ if (!view_55 || !commentSelectionRange) return false;
16650
17100
  const result_6 = applyCanonicalComment({
16651
17101
  type: "create",
16652
17102
  text: addText,
@@ -16662,7 +17112,7 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
16662
17112
  setVisibleCommentAuthors((current_0) => {
16663
17113
  if (current_0 === null) return null;
16664
17114
  const next_1 = new Set(current_0);
16665
- const created = result_6.comments.find(({ id: id_3 }) => id_3 === result_6.commentId);
17115
+ const created = result_6.comments.find(({ id: id_4 }) => id_4 === result_6.commentId);
16666
17116
  if (created) next_1.add(getCommentAuthorKey(created.author));
16667
17117
  return next_1;
16668
17118
  });
@@ -16673,7 +17123,7 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
16673
17123
  return true;
16674
17124
  }
16675
17125
  const comment_4 = createComment(addText, author);
16676
- if (!applyCommentMarkRange(view_56, commentSelectionRange, comment_4.id, { replacePending: true })) return false;
17126
+ if (!applyCommentMarkRange(view_55, commentSelectionRange, comment_4.id, { replacePending: true })) return false;
16677
17127
  const commentAuthor_2 = getCommentAuthorKey(comment_4.author);
16678
17128
  setVisibleCommentAuthors((current_1) => {
16679
17129
  if (current_1 === null) return null;
@@ -16724,8 +17174,8 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
16724
17174
  updateComments
16725
17175
  ]);
16726
17176
  const handleCancelAddComment = useCallback(() => {
16727
- const view_57 = pagedEditorRef.current?.getView();
16728
- if (view_57 && commentSelectionRange && commentDraftMode === "prosemirror") removePendingCommentMarkRange(view_57, commentSelectionRange);
17177
+ const view_56 = pagedEditorRef.current?.getView();
17178
+ if (view_56 && commentSelectionRange && commentDraftMode === "prosemirror") removePendingCommentMarkRange(view_56, commentSelectionRange);
16729
17179
  setIsAddingComment(false);
16730
17180
  setCommentSelectionRange(null);
16731
17181
  setAddCommentYPosition(null);
@@ -16742,23 +17192,23 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
16742
17192
  })?.revisionId ?? null;
16743
17193
  }, []);
16744
17194
  const handleSidebarAcceptChange = useCallback((from_17, to_17) => {
16745
- const view_58 = pagedEditorRef.current?.getView();
16746
- if (!view_58) return;
17195
+ const view_57 = pagedEditorRef.current?.getView();
17196
+ if (!view_57) return;
16747
17197
  const revisionId_3 = resolveSidebarChangeRevisionId(from_17, to_17);
16748
17198
  if (revisionId_3 === null) return;
16749
17199
  const editor_7 = pagedEditorRef.current?.getEditor();
16750
17200
  if (editor_7?.getCanonicalDocument()) editor_7.resolveCanonicalRevisions([revisionId_3], "accept");
16751
- else acceptAIEditRevision(revisionId_3)(view_58.state, view_58.dispatch);
17201
+ else acceptAIEditRevision(revisionId_3)(view_57.state, view_57.dispatch);
16752
17202
  extractTrackedChanges();
16753
17203
  }, [extractTrackedChanges, resolveSidebarChangeRevisionId]);
16754
17204
  const handleSidebarRejectChange = useCallback((from_18, to_18) => {
16755
- const view_59 = pagedEditorRef.current?.getView();
16756
- if (!view_59) return;
17205
+ const view_58 = pagedEditorRef.current?.getView();
17206
+ if (!view_58) return;
16757
17207
  const revisionId_4 = resolveSidebarChangeRevisionId(from_18, to_18);
16758
17208
  if (revisionId_4 === null) return;
16759
17209
  const editor_8 = pagedEditorRef.current?.getEditor();
16760
17210
  if (editor_8?.getCanonicalDocument()) editor_8.resolveCanonicalRevisions([revisionId_4], "reject");
16761
- else rejectAIEditRevision(revisionId_4)(view_59.state, view_59.dispatch);
17211
+ else rejectAIEditRevision(revisionId_4)(view_58.state, view_58.dispatch);
16762
17212
  extractTrackedChanges();
16763
17213
  }, [extractTrackedChanges, resolveSidebarChangeRevisionId]);
16764
17214
  const commentsPageWidth = history.state?.package.document.finalSectionProperties?.pageWidth;
@@ -16893,9 +17343,9 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
16893
17343
  };
16894
17344
  requestAnimationFrame(flash);
16895
17345
  }, []);
16896
- const handleOutlineJump = useCallback((id_4) => {
16897
- markHeadingJumped(id_4);
16898
- handleOutlineHeadingClick(Number(id_4));
17346
+ const handleOutlineJump = useCallback((id_5) => {
17347
+ markHeadingJumped(id_5);
17348
+ handleOutlineHeadingClick(Number(id_5));
16899
17349
  }, [handleOutlineHeadingClick, markHeadingJumped]);
16900
17350
  const handleTextContextAction = useCallback((action_3) => {
16901
17351
  handleContextMenuAction(action_3);
@@ -16908,8 +17358,8 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
16908
17358
  }, [readOnly]);
16909
17359
  const closeTableProperties = useCallback(() => setTablePropsOpen(false), []);
16910
17360
  const applyTableProperties = useCallback((props_0) => {
16911
- const view_60 = getActiveEditorView();
16912
- if (view_60) setTableProperties(props_0)(view_60.state, view_60.dispatch);
17361
+ const view_59 = getActiveEditorView();
17362
+ if (view_59) setTableProperties(props_0)(view_59.state, view_59.dispatch);
16913
17363
  }, [getActiveEditorView]);
16914
17364
  const closeImagePosition = useCallback(() => setImagePositionOpen(false), [setImagePositionOpen]);
16915
17365
  const closeImageProperties = useCallback(() => setImagePropsOpen(false), [setImagePropsOpen]);
@@ -16917,28 +17367,37 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
16917
17367
  const closeFootnoteProperties = useCallback(() => setFootnotePropsOpen(false), []);
16918
17368
  const closeInsertSymbol = useCallback(() => setShowInsertSymbol(false), []);
16919
17369
  const insertSymbol = useCallback((symbol) => {
16920
- const view_61 = getActiveEditorView();
16921
- if (view_61) view_61.dispatch(view_61.state.tr.insertText(symbol).scrollIntoView());
17370
+ const view_60 = getActiveEditorView();
17371
+ if (view_60) view_60.dispatch(view_60.state.tr.insertText(symbol).scrollIntoView());
16922
17372
  }, [getActiveEditorView]);
16923
17373
  const imagePropertiesCurrentData = useMemo(() => buildImagePropertiesData(state.pmImageContext), [state.pmImageContext]);
17374
+ const { close: closeFindDialog } = findReplace;
16924
17375
  const findReplaceDialog = useMemo(() => ({
16925
17376
  state: findReplace.state,
16926
- onClose: findReplace.close,
17377
+ onClose: () => {
17378
+ closeFindDialog();
17379
+ resetFindResult();
17380
+ },
16927
17381
  onFind: handleFind,
17382
+ onQueryChange: handleQueryChange,
16928
17383
  onFindNext: handleFindNext,
16929
17384
  onFindPrevious: handleFindPrevious,
16930
17385
  onReplace: handleReplace,
16931
17386
  onReplaceAll: handleReplaceAll,
16932
- currentResult: currentFindResult
17387
+ currentSearch: currentFindSearch,
17388
+ readOnly
16933
17389
  }), [
16934
- currentFindResult,
16935
- findReplace.close,
17390
+ currentFindSearch,
17391
+ readOnly,
17392
+ closeFindDialog,
16936
17393
  findReplace.state,
16937
17394
  handleFind,
17395
+ handleQueryChange,
16938
17396
  handleFindNext,
16939
17397
  handleFindPrevious,
16940
17398
  handleReplace,
16941
- handleReplaceAll
17399
+ handleReplaceAll,
17400
+ resetFindResult
16942
17401
  ]);
16943
17402
  const tablePropertiesDialog = useMemo(() => {
16944
17403
  const table = state.pmTableContext?.table;
@@ -17000,8 +17459,8 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
17000
17459
  ]);
17001
17460
  const closeNumberingValueDialog = useCallback(() => setNumberingValueDialogOpen(false), []);
17002
17461
  const applyNumberingValue = useCallback((value_0) => {
17003
- const view_62 = getActiveEditorView();
17004
- if (view_62) setNumberingValue(value_0)(view_62.state, view_62.dispatch);
17462
+ const view_61 = getActiveEditorView();
17463
+ if (view_61) setNumberingValue(value_0)(view_61.state, view_61.dispatch);
17005
17464
  }, [getActiveEditorView]);
17006
17465
  const numberingValueDialog = useMemo(() => ({
17007
17466
  isOpen: numberingValueDialogOpen,
@@ -17022,6 +17481,7 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
17022
17481
  showInsertSymbol
17023
17482
  ]);
17024
17483
  const containerStyle = {
17484
+ position: "relative",
17025
17485
  display: "flex",
17026
17486
  flexDirection: "column",
17027
17487
  height: "100%",
@@ -17241,6 +17701,7 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
17241
17701
  documentIO,
17242
17702
  documentIdentity: loadedDocumentIdentity,
17243
17703
  markupView: displayMode,
17704
+ showCommentHighlights,
17244
17705
  ...fonts !== void 0 ? { fonts } : {},
17245
17706
  theme: history.state.package.theme || theme || null,
17246
17707
  sectionProperties: effectiveSectionProperties ?? null,
@@ -17271,7 +17732,7 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
17271
17732
  ...onCopy !== void 0 ? { onCopy } : {},
17272
17733
  ...onCut !== void 0 ? { onCut } : {},
17273
17734
  ...onPaste !== void 0 ? { onPaste } : {},
17274
- ...onReadonlyEditAttempt !== void 0 ? { onReadOnlyEditAttempt: onReadonlyEditAttempt } : {},
17735
+ ...onReadonlyEditAttempt !== void 0 ? { onReadOnlyEditAttempt: notifyReadonlyEditAttempt } : {},
17275
17736
  onSelectionChange: handlePagedSelectionChange,
17276
17737
  ...onSelectionTextChange !== void 0 ? { onSelectionTextChange } : {},
17277
17738
  onEditorViewReady: handleBodyViewReady,
@@ -17300,8 +17761,8 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
17300
17761
  onMouseDown: (e_1) => {
17301
17762
  e_1.preventDefault();
17302
17763
  e_1.stopPropagation();
17303
- const view_63 = pagedEditorRef.current?.getView();
17304
- if (!view_63) {
17764
+ const view_62 = pagedEditorRef.current?.getView();
17765
+ if (!view_62) {
17305
17766
  setFloatingCommentBtn(null);
17306
17767
  return;
17307
17768
  }
@@ -17309,9 +17770,9 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
17309
17770
  from: floatingCommentBtn.from,
17310
17771
  to: floatingCommentBtn.to
17311
17772
  };
17312
- const currentSelection = view_63.state.selection;
17773
+ const currentSelection = view_62.state.selection;
17313
17774
  const safeRange = resolveCommentCreationRange({
17314
- docSize: view_63.state.doc.content.size,
17775
+ docSize: view_62.state.doc.content.size,
17315
17776
  capturedRange,
17316
17777
  currentRange: {
17317
17778
  from: currentSelection.from,
@@ -17326,7 +17787,7 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
17326
17787
  }
17327
17788
  setCommentSelectionRange(safeRange);
17328
17789
  if (commentDraftMode === "prosemirror") {
17329
- if (!applyCommentMarkRange(view_63, safeRange, -1, { selectEnd: true })) {
17790
+ if (!applyCommentMarkRange(view_62, safeRange, -1, { selectEnd: true })) {
17330
17791
  setCommentSelectionRange(null);
17331
17792
  setFloatingCommentBtn(null);
17332
17793
  return;