@stll/folio-react 0.20.2 → 0.20.3

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,9 +1,10 @@
1
- import { d as containedHandler } from "./renderAsync-dUCMzc_W.js";
1
+ import { d as containedHandler } from "./renderAsync-DMNxIBO9.js";
2
2
  import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
3
3
  import { CheckIcon, MoreVerticalIcon } from "lucide-react";
4
4
  import { useLocale, useTranslations } from "use-intl";
5
5
  import { closestHtmlElement, queryHtmlElement } from "@stll/folio-core/utils/domGuards";
6
6
  import { jsx, jsxs } from "react/jsx-runtime";
7
+ import { commentAnchorSelector } from "@stll/folio-core/render-dom/commentAnchorAttributes";
7
8
  //#region src/components/CommentsSidebar.tsx
8
9
  /**
9
10
  * Comments Sidebar
@@ -174,7 +175,7 @@ const CommentsSidebar = ({ comments, onCommentClick, activeCommentId = null, onC
174
175
  };
175
176
  for (const comment of visibleComments) {
176
177
  const cardId = `comment-${comment.id}`;
177
- const el = pagesEl.querySelector(`[data-comment-id="${CSS.escape(String(comment.id))}"]`);
178
+ const el = pagesEl.querySelector(commentAnchorSelector(comment.id));
178
179
  if (el) {
179
180
  pushPosition(cardId, el.getBoundingClientRect().top - containerRect.top + scrollTop, cardRefs.current.get(cardId)?.offsetHeight || DEFAULT_CARD_HEIGHT);
180
181
  continue;
@@ -1,4 +1,4 @@
1
- import { n as DocxEditor$1, t as renderAsync } from "../renderAsync-dUCMzc_W.js";
1
+ import { n as DocxEditor$1, t as renderAsync } from "../renderAsync-DMNxIBO9.js";
2
2
  import { t as messages_exports } from "../messages.js";
3
3
  import { c } from "react-compiler-runtime";
4
4
  import { forwardRef } from "react";
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as formatZoom, c as FormattingBar, i as clampZoom, l as ZoomControl, n as DocxEditor, o as parseZoom, r as ZOOM_PRESETS, s as useWheelZoom, t as renderAsync, u as AutocompleteCaretOverlay } from "./renderAsync-dUCMzc_W.js";
1
+ import { a as formatZoom, c as FormattingBar, i as clampZoom, l as ZoomControl, n as DocxEditor, o as parseZoom, r as ZOOM_PRESETS, s as useWheelZoom, t as renderAsync, u as AutocompleteCaretOverlay } from "./renderAsync-DMNxIBO9.js";
2
2
  import { n as FolioUIProvider } from "./folio-ui-BgDDRsUX.js";
3
3
  import { t as FindReplaceDialog } from "./FindReplaceDialog-CqKK82nE.js";
4
4
  import { t as FootnotePropertiesDialog } from "./FootnotePropertiesDialog-CixRdIiT.js";
@@ -108,6 +108,7 @@ import { applyImagePosition, applyImageProperties, applyImageTransform, applyIma
108
108
  import { classifyEditorKeydown, deleteSelectedTable, isFocusInInputLike, isKeydownInShortcutScope, isMacPlatform } from "@stll/folio-core/managers/editorShortcuts";
109
109
  import { getScrollTopForZoomAnchor, getViewportCenterZoomAnchorForZoomChange } from "@stll/folio-core/paged-layout/zoomScrollAnchor";
110
110
  import { ZOOM_MAX, ZOOM_MIN, ZOOM_STEP } from "@stll/folio-core/utils/zoom";
111
+ import { COMMENT_ANCHOR_SELECTOR, commentAnchorIds } from "@stll/folio-core/render-dom/commentAnchorAttributes";
111
112
  import { isValidHexId } from "@stll/folio-core/utils/hexId";
112
113
  import { createRoot } from "react-dom/client";
113
114
  //#region src/hooks/useHistory.ts
@@ -210,7 +211,7 @@ function useDocumentHistory(document, t0) {
210
211
  $[1] = t1;
211
212
  } else t1 = $[1];
212
213
  const options = t1;
213
- const isEqual = _temp$11;
214
+ const isEqual = _temp$12;
214
215
  let t2;
215
216
  if ($[2] !== options) {
216
217
  t2 = {
@@ -222,7 +223,7 @@ function useDocumentHistory(document, t0) {
222
223
  } else t2 = $[3];
223
224
  return useHistory(document, t2);
224
225
  }
225
- function _temp$11(a, b) {
226
+ function _temp$12(a, b) {
226
227
  if (a === b) return true;
227
228
  const aPackage = a?.package;
228
229
  const bPackage = b?.package;
@@ -743,7 +744,7 @@ const AISuggestionRectsOverlay = (t0) => {
743
744
  if (groups.length === 0) return null;
744
745
  let t1;
745
746
  if ($[0] !== groups) {
746
- t1 = groups.map(_temp$10);
747
+ t1 = groups.map(_temp$11);
747
748
  $[0] = groups;
748
749
  $[1] = t1;
749
750
  } else t1 = $[1];
@@ -759,7 +760,7 @@ const AISuggestionRectsOverlay = (t0) => {
759
760
  } else t2 = $[3];
760
761
  return t2;
761
762
  };
762
- function _temp$10(t0) {
763
+ function _temp$11(t0) {
763
764
  const { suggestion, rects, focused, font } = t0;
764
765
  const replacementAnchor = rects.at(-1);
765
766
  const showReplacement = focused && suggestion.suggestedText.length > 0 && replacementAnchor !== void 0;
@@ -994,7 +995,7 @@ const PassageHighlightOverlay = (t0) => {
994
995
  if (rects.length === 0) return null;
995
996
  let t1;
996
997
  if ($[0] !== rects) {
997
- t1 = rects.map(_temp$9);
998
+ t1 = rects.map(_temp$10);
998
999
  $[0] = rects;
999
1000
  $[1] = t1;
1000
1001
  } else t1 = $[1];
@@ -1010,7 +1011,7 @@ const PassageHighlightOverlay = (t0) => {
1010
1011
  } else t2 = $[3];
1011
1012
  return t2;
1012
1013
  };
1013
- function _temp$9(rect, idx) {
1014
+ function _temp$10(rect, idx) {
1014
1015
  return /* @__PURE__ */ jsx("span", {
1015
1016
  className: "folio-passage-highlight",
1016
1017
  style: {
@@ -2471,7 +2472,7 @@ function HfCaretOverlay(t0) {
2471
2472
  if (!pagesContainer) return null;
2472
2473
  let t4;
2473
2474
  if ($[17] !== rangeRects) {
2474
- t4 = rangeRects.map(_temp$8);
2475
+ t4 = rangeRects.map(_temp$9);
2475
2476
  $[17] = rangeRects;
2476
2477
  $[18] = t4;
2477
2478
  } else t4 = $[18];
@@ -2510,7 +2511,7 @@ function HfCaretOverlay(t0) {
2510
2511
  } else t7 = $[26];
2511
2512
  return t7;
2512
2513
  }
2513
- function _temp$8(r, i) {
2514
+ function _temp$9(r, i) {
2514
2515
  return /* @__PURE__ */ jsx("div", {
2515
2516
  "data-testid": "hf-selection-rect",
2516
2517
  style: {
@@ -7108,6 +7109,7 @@ function ContentControlWidgetsOverlay(t0) {
7108
7109
  "aria-label": t11,
7109
7110
  style,
7110
7111
  className: "bg-popover text-popover-foreground min-w-[10rem] rounded-md border p-1 shadow-md",
7112
+ onPointerDown: _temp$8,
7111
7113
  children: [t12, t13]
7112
7114
  })
7113
7115
  }), document.body);
@@ -7119,6 +7121,9 @@ function ContentControlWidgetsOverlay(t0) {
7119
7121
  } else t14 = $[31];
7120
7122
  return t14;
7121
7123
  }
7124
+ function _temp$8(event) {
7125
+ return event.stopPropagation();
7126
+ }
7122
7127
  function ContentControlDropdownItem(t0) {
7123
7128
  const $ = c(7);
7124
7129
  const { item, MenuItem, onPick } = t0;
@@ -12197,17 +12202,17 @@ function useFolioComments({ doc, autoOpenReviewSidebar, anchorPositions, editorC
12197
12202
  const syncCommentHighlightStyles = useCallback(() => {
12198
12203
  const root = editorContentRef.current;
12199
12204
  if (!root) return;
12200
- const nodes = root.querySelectorAll(".layout-run-text[data-comment-id]");
12205
+ const nodes = root.querySelectorAll(`.layout-run-text${COMMENT_ANCHOR_SELECTOR}`);
12201
12206
  for (const node of nodes) {
12202
- const commentId = Number.parseInt(node.dataset["commentId"] ?? "", 10);
12203
- if (!(commentId === -1 || visibleCommentIds.has(commentId))) {
12207
+ const commentIds = commentAnchorIds(node).map((id) => Number.parseInt(id, 10));
12208
+ if (!commentIds.some((commentId) => commentId === -1 || visibleCommentIds.has(commentId))) {
12204
12209
  node.style.backgroundColor = "transparent";
12205
12210
  node.style.borderBottom = "2px solid transparent";
12206
12211
  node.style.boxShadow = "none";
12207
12212
  delete node.dataset["activeComment"];
12208
12213
  continue;
12209
12214
  }
12210
- if (activeCommentId === commentId) {
12215
+ if (activeCommentId !== null && commentIds.includes(activeCommentId)) {
12211
12216
  node.style.backgroundColor = "var(--doc-comment-active-bg, rgba(255, 212, 0, 0.22))";
12212
12217
  node.style.borderBottom = "1px solid var(--doc-comment-active-border, rgba(180, 130, 0, 0.62))";
12213
12218
  node.style.boxShadow = "none";
@@ -12279,7 +12284,7 @@ function useFolioComments({ doc, autoOpenReviewSidebar, anchorPositions, editorC
12279
12284
  * - Error boundary
12280
12285
  * - Loading states
12281
12286
  */
12282
- const CommentsSidebar = lazy(() => import("./CommentsSidebar-D6n3ifAJ.js").then((m) => ({ default: m.CommentsSidebar })));
12287
+ const CommentsSidebar = lazy(() => import("./CommentsSidebar-BiBt77_z.js").then((m) => ({ default: m.CommentsSidebar })));
12283
12288
  const TextContextMenu = lazy(() => import("./TextContextMenu-Ci7-M4oU.js").then((m) => ({ default: m.TextContextMenu })));
12284
12289
  const loadAttemptSelectiveSave = async () => {
12285
12290
  const { attemptSelectiveSave } = await import("@stll/folio-core/docx/selectiveSave");
@@ -12541,6 +12546,7 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
12541
12546
  const imageInputRef = useRef(null);
12542
12547
  const editorContentRef = useRef(null);
12543
12548
  const scrollContainerRef = useRef(null);
12549
+ const initialScrollAppliedRef = useRef(false);
12544
12550
  const [formatPainterMode, setFormatPainterModeState] = useState("off");
12545
12551
  const formatPainterModeRef = useRef("off");
12546
12552
  const capturedFormatMarksRef = useRef(null);
@@ -12688,6 +12694,11 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
12688
12694
  onError,
12689
12695
  onCompatibilityChange,
12690
12696
  onReset: useCallback(() => {
12697
+ initialScrollAppliedRef.current = false;
12698
+ if (scrollContainerRef.current) {
12699
+ scrollContainerRef.current.scrollTop = 0;
12700
+ scrollContainerRef.current.scrollLeft = 0;
12701
+ }
12691
12702
  commentsDirtyRef.current = false;
12692
12703
  commentsLoadedRef.current = false;
12693
12704
  trackedChangesLoadedRef.current = false;
@@ -12755,7 +12766,6 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
12755
12766
  autoOpenReviewSidebar,
12756
12767
  setShowCommentsSidebar
12757
12768
  ]);
12758
- const initialScrollAppliedRef = useRef(false);
12759
12769
  useEffect(() => {
12760
12770
  if (initialScrollTop === void 0 || state.documentLoad.status !== "ready" || initialScrollAppliedRef.current) return;
12761
12771
  initialScrollAppliedRef.current = true;
@@ -12765,7 +12775,11 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
12765
12775
  return () => {
12766
12776
  cancelAnimationFrame(frame);
12767
12777
  };
12768
- }, [initialScrollTop, state.documentLoad.status]);
12778
+ }, [
12779
+ initialScrollTop,
12780
+ loadedDocumentIdentity,
12781
+ state.documentLoad.status
12782
+ ]);
12769
12783
  useEffect(() => {
12770
12784
  return onFontsLoaded(() => {
12771
12785
  onFontsLoadedCallback?.();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stll/folio-react",
3
- "version": "0.20.2",
3
+ "version": "0.20.3",
4
4
  "description": "React editor for folio: a Word-document (.docx) editor for the browser, built on @stll/folio-core and ProseMirror.",
5
5
  "keywords": [
6
6
  "document-editor",
@@ -68,7 +68,7 @@
68
68
  "@fontsource/noto-sans-arabic": "^5.2.7",
69
69
  "@fontsource/source-sans-3": "^5.2.9",
70
70
  "@fontsource/tinos": "^5.2.7",
71
- "@stll/folio-core": "^0.45.0",
71
+ "@stll/folio-core": "^0.46.0",
72
72
  "better-result": "3.0.1",
73
73
  "lucide-react": "1.24.0",
74
74
  "prosemirror-history": "^1.5.0",