@stll/folio-react 0.12.3 → 0.13.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,4 +1,4 @@
1
- import { d as containedHandler } from "./renderAsync-DFwDFNB9.js";
1
+ import { d as containedHandler } from "./renderAsync-DLhuA3FM.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";
@@ -1,4 +1,4 @@
1
- import { c as DocxEditorRef, i as renderAsync, n as EditorHandle, r as RenderAsyncOptions, s as DocxEditorProps, t as DocxEditorHandle } from "../renderAsync-CH8S7yqU.js";
1
+ import { c as DocxEditorRef, i as renderAsync, n as EditorHandle, r as RenderAsyncOptions, s as DocxEditorProps, t as DocxEditorHandle } from "../renderAsync-B_Bi9oSr.js";
2
2
  import { ReactNode } from "react";
3
3
  import { CreateEmptyDocumentOptions, createDocumentWithText, createEmptyDocument } from "@stll/folio-core/utils/createDocument";
4
4
  //#region src/compat/eigenpal.d.ts
@@ -1,4 +1,4 @@
1
- import { n as DocxEditor$1, t as renderAsync } from "../renderAsync-DFwDFNB9.js";
1
+ import { n as DocxEditor$1, t as renderAsync } from "../renderAsync-DLhuA3FM.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.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { _ as FolioUIProvider, a as DocxEditorApplyDocumentOperationsOptions, c as DocxEditorRef, d as ToolbarProps, f as EditorMode, g as FolioUIComponents, h as FolioButtonProps, i as renderAsync, l as HighlightPassageOptions, m as ColorPreset, n as EditorHandle, o as DocxEditorCollaboration, p as FontOption, r as RenderAsyncOptions, s as DocxEditorProps, t as DocxEditorHandle, u as HighlightPassageResult, v as OutlineItem, y as FontDefinition } from "./renderAsync-CH8S7yqU.js";
1
+ import { _ as FolioUIProvider, a as DocxEditorApplyDocumentOperationsOptions, c as DocxEditorRef, d as ToolbarProps, f as EditorMode, g as FolioUIComponents, h as FolioButtonProps, i as renderAsync, l as HighlightPassageOptions, m as ColorPreset, n as EditorHandle, o as DocxEditorCollaboration, p as FontOption, r as RenderAsyncOptions, s as DocxEditorProps, t as DocxEditorHandle, u as HighlightPassageResult, v as OutlineItem, y as FontDefinition } from "./renderAsync-B_Bi9oSr.js";
2
2
  import { A as HyperlinkDialog, C as ImagePropertiesData, D as ImagePositionDialog, E as ImagePositionData, F as FindReplaceDialog, I as FindReplaceDialogProps, M as HyperlinkDialogProps, N as FootnotePropertiesDialog, O as ImagePositionDialogProps, P as FootnotePropertiesDialogProps, S as InsertImageDialogProps, T as ImagePropertiesDialogProps, _ as InsertTableStyleOption, a as TablePropertiesDialogProps, b as InsertImageDialog, c as SplitCellDialogProps, d as PasteSpecialMode, f as PageSetupDialog, g as InsertTableDialogProps, h as InsertTableDialogData, i as TablePropertiesDialog, j as HyperlinkDialogData, k as HyperlinkBookmarkOption, l as PasteSpecialDialog, m as InsertTableDialog, n as WatermarkDialogProps, o as SplitCellDialog, p as PageSetupDialogProps, r as TableProperties, s as SplitCellDialogData, t as WatermarkDialog, u as PasteSpecialDialogProps, v as InsertSymbolDialog, w as ImagePropertiesDialog, x as InsertImageDialogData, y as InsertSymbolDialogProps } from "./dialogs-lCOx21mG.js";
3
3
  import React, { CSSProperties, ReactNode, RefObject } from "react";
4
4
  import { CreateEmptyDocumentOptions, createEmptyDocument } from "@stll/folio-core/utils/createDocument";
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-DFwDFNB9.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-DLhuA3FM.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";
@@ -694,8 +694,12 @@ type DocxEditorProps = {
694
694
  showRuler?: boolean;
695
695
  /** Measurement unit shown on the rulers (default: 'inch'). */
696
696
  rulerUnit?: "inch" | "cm";
697
- /** Initial zoom level (default: 1.0) */
698
- initialZoom?: number;
697
+ /**
698
+ * Initial zoom level as a number (default: 1.0 = 100%), or `"fit-width"` to
699
+ * size the page to the editor's width and keep it fit as the editor resizes.
700
+ * A manual zoom (toolbar or `ref.setZoom`) afterwards overrides the fit.
701
+ */
702
+ initialZoom?: number | "fit-width";
699
703
  /** Whether Ctrl/Cmd+wheel and trackpad-pinch zoom are enabled (default: true) */
700
704
  enableWheelZoom?: boolean;
701
705
  /** Whether the editor is read-only. When true, hides toolbar and rulers */
@@ -10714,8 +10714,12 @@ function useKeyboardShortcuts({ pagedEditorRef, findReplace, tableSelection, onD
10714
10714
  //#endregion
10715
10715
  //#region src/components/hooks/useZoomAndPageInfo.ts
10716
10716
  const PAGE_INFO_FADE_MS = 600;
10717
+ const FIT_TO_WIDTH_PADDING_PX = 16;
10718
+ const FIT_TO_WIDTH_MIN_ZOOM = .1;
10719
+ const FIT_TO_WIDTH_MAX_ZOOM = 1;
10717
10720
  function useZoomAndPageInfo({ scrollContainerRef, pagedEditorRef, initialZoom }) {
10718
- const [zoom, setZoom] = useState(initialZoom);
10721
+ const fitToWidth = initialZoom === "fit-width";
10722
+ const [zoom, setZoom] = useState(typeof initialZoom === "number" ? initialZoom : 1);
10719
10723
  const zoomRef = useRef(zoom);
10720
10724
  const pendingZoomAnchorRef = useRef(null);
10721
10725
  const [scrollPageInfo, setScrollPageInfo] = useState({
@@ -10801,6 +10805,36 @@ function useZoomAndPageInfo({ scrollContainerRef, pagedEditorRef, initialZoom })
10801
10805
  scheduleScrollPageInfoFade,
10802
10806
  updateScrollPageInfo
10803
10807
  ]);
10808
+ useEffect(() => {
10809
+ if (!fitToWidth || !scrollContainerEl) return;
10810
+ let rafId = 0;
10811
+ const applyFit = () => {
10812
+ const pageWidth = pagedEditorRef.current?.getLayout()?.pages[0]?.size.w ?? 0;
10813
+ if (pageWidth <= 0) {
10814
+ rafId = requestAnimationFrame(applyFit);
10815
+ return;
10816
+ }
10817
+ const available = scrollContainerEl.clientWidth - FIT_TO_WIDTH_PADDING_PX;
10818
+ if (available <= 0) return;
10819
+ const target = Math.min(FIT_TO_WIDTH_MAX_ZOOM, Math.max(FIT_TO_WIDTH_MIN_ZOOM, Math.round(available / pageWidth * 100) / 100));
10820
+ if (Math.abs(target - zoomRef.current) > .005) setZoomWithViewportAnchor(target);
10821
+ };
10822
+ const observer = new ResizeObserver(() => {
10823
+ cancelAnimationFrame(rafId);
10824
+ rafId = requestAnimationFrame(applyFit);
10825
+ });
10826
+ observer.observe(scrollContainerEl);
10827
+ applyFit();
10828
+ return () => {
10829
+ cancelAnimationFrame(rafId);
10830
+ observer.disconnect();
10831
+ };
10832
+ }, [
10833
+ fitToWidth,
10834
+ scrollContainerEl,
10835
+ pagedEditorRef,
10836
+ setZoomWithViewportAnchor
10837
+ ]);
10804
10838
  return {
10805
10839
  zoom,
10806
10840
  zoomRef,
@@ -12400,7 +12434,7 @@ function useFolioComments({ doc, autoOpenReviewSidebar, anchorPositions, editorC
12400
12434
  * - Error boundary
12401
12435
  * - Loading states
12402
12436
  */
12403
- const CommentsSidebar = lazy(() => import("./CommentsSidebar-mwa9JsIj.js").then((m) => ({ default: m.CommentsSidebar })));
12437
+ const CommentsSidebar = lazy(() => import("./CommentsSidebar-ZHaLP2Kq.js").then((m) => ({ default: m.CommentsSidebar })));
12404
12438
  const TextContextMenu = lazy(() => import("./TextContextMenu-Ci7-M4oU.js").then((m) => ({ default: m.TextContextMenu })));
12405
12439
  const loadAttemptSelectiveSave = async () => {
12406
12440
  const { attemptSelectiveSave } = await import("@stll/folio-core/docx/selectiveSave");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stll/folio-react",
3
- "version": "0.12.3",
3
+ "version": "0.13.0",
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",