@stll/folio-react 0.32.3 → 0.33.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 { i as cn, n as FolioUIProvider, r as useFolioUI, t as DEFAULT_COMPONENTS } from "./folio-ui-B8i_O5aS.js";
1
+ import { i as cn, n as FolioUIProvider, r as useFolioUI, t as DEFAULT_COMPONENTS } from "./folio-ui-CEFqJgCh.js";
2
2
  import { t as messages_exports } from "./messages-DjrCTI3y.js";
3
3
  import { c } from "react-compiler-runtime";
4
4
  import * as React$1 from "react";
@@ -3235,7 +3235,7 @@ function buildFootnoteRenderItems(pageFootnoteMap, footnoteContentMap, doc) {
3235
3235
  * PagedEditor - Main paginated editing component.
3236
3236
  */
3237
3237
  const PagedEditor = forwardRef(function PagedEditor(props, ref) {
3238
- 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;
3238
+ const { accessibleName, 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;
3239
3239
  const getScrollContainer = useCallback(() => {
3240
3240
  if (scrollContainerRefProp && typeof scrollContainerRefProp === "object") return getEditorScrollRoot(scrollContainerRefProp.current);
3241
3241
  return getEditorScrollRoot(containerRef.current);
@@ -6102,8 +6102,9 @@ const PagedEditor = forwardRef(function PagedEditor(props, ref) {
6102
6102
  ...style
6103
6103
  },
6104
6104
  tabIndex: 0,
6105
- role: "textbox",
6106
- "aria-multiline": true,
6105
+ role: readOnly ? "document" : "textbox",
6106
+ "aria-label": accessibleName,
6107
+ "aria-multiline": readOnly ? void 0 : true,
6107
6108
  onFocus: handleContainedFocus,
6108
6109
  onBlur: handleContainerBlur,
6109
6110
  onKeyDown: handleKeyDown,
@@ -7369,14 +7370,14 @@ function _temp$11(heading) {
7369
7370
  return item;
7370
7371
  }
7371
7372
  // src/components/DocxEditorDialogs.tsx
7372
- const FindReplaceDialog = lazy(() => import("./FindReplaceDialog-B446W1cL.js").then((n) => n.n).then((m) => ({ default: m.FindReplaceDialog })));
7373
- const TablePropertiesDialog = lazy(() => import("./TablePropertiesDialog-edzovlyc.js").then((n) => n.n).then((m) => ({ default: m.TablePropertiesDialog })));
7374
- const ImagePositionDialog = lazy(() => import("./ImagePositionDialog-DdokSGoN.js").then((n) => n.n).then((m) => ({ default: m.ImagePositionDialog })));
7375
- const ImagePropertiesDialog = lazy(() => import("./ImagePropertiesDialog-C-xQU8Eq.js").then((n) => n.n).then((m) => ({ default: m.ImagePropertiesDialog })));
7376
- const FootnotePropertiesDialog = lazy(() => import("./FootnotePropertiesDialog-J5zg-K3w.js").then((n) => n.n).then((m) => ({ default: m.FootnotePropertiesDialog })));
7377
- const PageSetupDialog = lazy(() => import("./PageSetupDialog-BXK9tKw5.js").then((n) => n.n).then((m) => ({ default: m.PageSetupDialog })));
7378
- const SetNumberingValueDialog = lazy(() => import("./SetNumberingValueDialog-DZUrre78.js").then((m) => ({ default: m.SetNumberingValueDialog })));
7379
- const InsertSymbolDialog = lazy(() => import("./InsertSymbolDialog-p7UOS4me.js").then((n) => n.n).then((m) => ({ default: m.InsertSymbolDialog })));
7373
+ const FindReplaceDialog = lazy(() => import("./FindReplaceDialog-DbbzquBV.js").then((n) => n.n).then((m) => ({ default: m.FindReplaceDialog })));
7374
+ const TablePropertiesDialog = lazy(() => import("./TablePropertiesDialog-fDJc5_NR.js").then((n) => n.n).then((m) => ({ default: m.TablePropertiesDialog })));
7375
+ const ImagePositionDialog = lazy(() => import("./ImagePositionDialog-CznMopDr.js").then((n) => n.n).then((m) => ({ default: m.ImagePositionDialog })));
7376
+ const ImagePropertiesDialog = lazy(() => import("./ImagePropertiesDialog-TAm7NKLM.js").then((n) => n.n).then((m) => ({ default: m.ImagePropertiesDialog })));
7377
+ const FootnotePropertiesDialog = lazy(() => import("./FootnotePropertiesDialog-BBq9iBzN.js").then((n) => n.n).then((m) => ({ default: m.FootnotePropertiesDialog })));
7378
+ const PageSetupDialog = lazy(() => import("./PageSetupDialog-DpTPXo9U.js").then((n) => n.n).then((m) => ({ default: m.PageSetupDialog })));
7379
+ const SetNumberingValueDialog = lazy(() => import("./SetNumberingValueDialog-BzUWmoaZ.js").then((m) => ({ default: m.SetNumberingValueDialog })));
7380
+ const InsertSymbolDialog = lazy(() => import("./InsertSymbolDialog-CrHgjUTz.js").then((n) => n.n).then((m) => ({ default: m.InsertSymbolDialog })));
7380
7381
  function DocxEditorDialogs(t0) {
7381
7382
  const $ = c(55);
7382
7383
  const { findReplace, tableProperties, imagePosition, imageProperties, pageSetup, footnoteProperties, insertSymbol, setNumberingValue } = t0;
@@ -8090,13 +8091,15 @@ function getTooltipLabel(content) {
8090
8091
  * Individual toolbar button with shadcn styling.
8091
8092
  * Compact editor chrome button.
8092
8093
  */
8093
- function ToolbarButton({ active = false, disabled = false, title, onClick, onDoubleClick, children, className, ariaLabel, testId }) {
8094
+ function ToolbarButton({ active = false, disabled = false, title, onClick, onDoubleClick, children, className, ariaLabel, testId, onMouseDown, ...passThrough }) {
8094
8095
  const derivedTestId = toToolbarTestId(ariaLabel) || toToolbarTestId(title, { stripParentheses: true });
8095
8096
  const resolvedTestId = testId ?? (derivedTestId ? `toolbar-${derivedTestId}` : void 0);
8096
8097
  const handleMouseDown = (e) => {
8097
8098
  e.preventDefault();
8099
+ onMouseDown?.(e);
8098
8100
  };
8099
8101
  const button = /* @__PURE__ */ jsx("button", {
8102
+ ...passThrough,
8100
8103
  type: "button",
8101
8104
  className: cn("flex h-8 w-8 shrink-0 items-center justify-center rounded-md", "transition-colors duration-100", "antialiased", "text-[var(--doc-text-muted)] hover:bg-[var(--doc-primary-light)] hover:text-[var(--doc-text)]", active && "bg-[var(--doc-primary-light)] text-[var(--doc-text)] hover:bg-[var(--doc-primary-light)]", disabled && "cursor-not-allowed text-[var(--doc-text-subtle)] opacity-[0.16] disabled:hover:bg-transparent disabled:hover:text-[var(--doc-text-subtle)]", className),
8102
8105
  onMouseDown: handleMouseDown,
@@ -9204,6 +9207,28 @@ function FormattingBar(props) {
9204
9207
  const handleBarMouseUp = useCallback(() => {
9205
9208
  requestAnimationFrame(() => onRefocusEditor?.());
9206
9209
  }, [onRefocusEditor]);
9210
+ const fontColorLabel = t("fontColor");
9211
+ const fontColorSwatch = (() => {
9212
+ if (!currentFormatting.color) return "#000000";
9213
+ if (currentFormatting.color.startsWith("#")) return currentFormatting.color;
9214
+ return `#${currentFormatting.color}`;
9215
+ })();
9216
+ const fontColorTrigger = useMemo(() => /* @__PURE__ */ jsxs(ToolbarButton, {
9217
+ disabled,
9218
+ title: fontColorLabel,
9219
+ ariaLabel: fontColorLabel,
9220
+ children: [/* @__PURE__ */ jsxs("div", {
9221
+ className: "flex flex-col items-center gap-0",
9222
+ children: [/* @__PURE__ */ jsx(BaselineIcon, { size: ICON_SIZE }), /* @__PURE__ */ jsx("span", {
9223
+ className: "mt-[-2px] h-1 w-4 rounded-sm",
9224
+ style: { backgroundColor: fontColorSwatch }
9225
+ })]
9226
+ }), /* @__PURE__ */ jsx(ChevronDownIcon, { size: 10 })]
9227
+ }), [
9228
+ disabled,
9229
+ fontColorLabel,
9230
+ fontColorSwatch
9231
+ ]);
9207
9232
  const moreFormattingLabel = t("moreFormatting");
9208
9233
  const overflowTrigger = useMemo(() => /* @__PURE__ */ jsx("button", {
9209
9234
  type: "button",
@@ -9235,24 +9260,7 @@ function FormattingBar(props) {
9235
9260
  value: currentFormatting.color?.replace(/^#/u, "").toUpperCase(),
9236
9261
  onSelect: handleTextColorSelect,
9237
9262
  onClear: handleTextColorClear,
9238
- children: /* @__PURE__ */ jsxs(ToolbarButton, {
9239
- disabled,
9240
- title: t("fontColor"),
9241
- ariaLabel: t("fontColor"),
9242
- children: [/* @__PURE__ */ jsxs("div", {
9243
- className: "flex flex-col items-center gap-0",
9244
- children: [/* @__PURE__ */ jsx(BaselineIcon, { size: ICON_SIZE }), /* @__PURE__ */ jsx("span", {
9245
- className: "mt-[-2px] h-1 w-4 rounded-sm",
9246
- style: { backgroundColor: (() => {
9247
- if (currentFormatting.color) return (() => {
9248
- if (currentFormatting.color.startsWith("#")) return currentFormatting.color;
9249
- return `#${currentFormatting.color}`;
9250
- })();
9251
- return "#000000";
9252
- })() }
9253
- })]
9254
- }), /* @__PURE__ */ jsx(ChevronDownIcon, { size: 10 })]
9255
- })
9263
+ trigger: fontColorTrigger
9256
9264
  })
9257
9265
  ]
9258
9266
  }),
@@ -14032,7 +14040,7 @@ function _temp(id_4) {
14032
14040
  // src/components/DocxEditor.tsx
14033
14041
  /** No headings to track while the outline is not shown. */
14034
14042
  const NO_HEADINGS = [];
14035
- const CommentsSidebar = lazy(() => import("./CommentsSidebar-DnxzLs1o.js").then((m) => ({ default: m.CommentsSidebar })));
14043
+ const CommentsSidebar = lazy(() => import("./CommentsSidebar-CQJT9gei.js").then((m) => ({ default: m.CommentsSidebar })));
14036
14044
  const TextContextMenu = lazy(() => import("./TextContextMenu-BxnNvhJg.js").then((m) => ({ default: m.TextContextMenu })));
14037
14045
  const loadAttemptSelectiveSave = async () => {
14038
14046
  const { attemptSelectiveSave } = await import("@stll/folio-core/docx/selectiveSave");
@@ -14134,7 +14142,7 @@ const createPagedEditorBinding = () => {
14134
14142
  /**
14135
14143
  * DocxEditor - Complete DOCX editor component
14136
14144
  */
14137
- 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) {
14145
+ const DocxEditor = forwardRef(function DocxEditor({ accessibleName, 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) {
14138
14146
  const pagedEditorRef = useRef(null);
14139
14147
  const [pagedEditorBinding] = useState(createPagedEditorBinding);
14140
14148
  const scrollContainerRef = useRef(null);
@@ -14751,11 +14759,12 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
14751
14759
  experimentalSession
14752
14760
  ]);
14753
14761
  const buildCurrentDocument = useCallback(() => {
14754
- if (!history.state) return null;
14762
+ const committed = historyStateRef.current;
14763
+ if (!committed) return null;
14755
14764
  const canonical_0 = pagedEditorRef.current?.getEditor().getCanonicalDocument();
14756
14765
  if (canonical_0) return canonical_0;
14757
14766
  if (usesCanonicalSession(experimentalSession, CANONICAL_GAP.authorityRouting)) return null;
14758
- let doc_0 = cloneDocumentWithParagraphPropertySources(history.state);
14767
+ let doc_0 = cloneDocumentWithParagraphPropertySources(committed);
14759
14768
  const pmDoc = pagedEditorRef.current?.getDocument();
14760
14769
  if (pmDoc) {
14761
14770
  doc_0.package.document.content = pmDoc.package.document.content;
@@ -14779,11 +14788,7 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
14779
14788
  const referencedCommentIds = collectCommentIdsFromSources(doc_0.package.document.content, doc_0.package.headers, doc_0.package.footers, doc_0.package.footnotes, doc_0.package.endnotes);
14780
14789
  setDocumentBodyComments(doc_0.package.document, pruneOrphanedComments(commentsRef.current, referencedCommentIds));
14781
14790
  return doc_0;
14782
- }, [
14783
- history.state,
14784
- commentsRef,
14785
- experimentalSession
14786
- ]);
14791
+ }, [commentsRef, experimentalSession]);
14787
14792
  const applyCanonicalComment = useCallback((request) => {
14788
14793
  return getCanonicalApi()?.applyCanonicalComment(request) ?? null;
14789
14794
  }, [getCanonicalApi]);
@@ -17512,6 +17517,7 @@ const DocxEditor = forwardRef(function DocxEditor({ documentBuffer, password, do
17512
17517
  })
17513
17518
  }),
17514
17519
  /* @__PURE__ */ jsx(PagedEditor, {
17520
+ accessibleName,
17515
17521
  ref: attachPagedEditor,
17516
17522
  document: history.state,
17517
17523
  documentIO,
@@ -17795,6 +17801,7 @@ function CommentAuthorVisibilityItem(t0) {
17795
17801
  * import "@stll/folio-react/standalone.css";
17796
17802
  *
17797
17803
  * const editor = await renderAsync(buffer, document.getElementById("host")!, {
17804
+ * accessibleName: "Document editor",
17798
17805
  * readOnly: false,
17799
17806
  * showToolbar: true,
17800
17807
  * });
@@ -17809,7 +17816,7 @@ function CommentAuthorVisibilityItem(t0) {
17809
17816
  * Resolves once the document has parsed and the first `onChange` fires.
17810
17817
  * Rejects if `onError` runs before that milestone.
17811
17818
  */
17812
- const renderAsync = (input, container, options = {}) => {
17819
+ const renderAsync = (input, container, options) => {
17813
17820
  const { locale = "en", ...editorOptions } = options;
17814
17821
  return new Promise((resolve, reject) => {
17815
17822
  const ref = React.createRef();
@@ -1,4 +1,4 @@
1
- import React$1, { CSSProperties, ComponentProps, ComponentType, ForwardRefExoticComponent, JSX, ReactNode, RefAttributes, RefObject } from "react";
1
+ import React$1, { CSSProperties, ComponentProps, ComponentType, ForwardRefExoticComponent, JSX, ReactElement, ReactNode, RefAttributes, RefObject } from "react";
2
2
  import { EditorState, Plugin, Transaction } from "prosemirror-state";
3
3
  import { EditorView } from "prosemirror-view";
4
4
  import { XmlFragment } from "yjs";
@@ -310,8 +310,8 @@ type ColorPreset = {
310
310
  color?: string;
311
311
  };
312
312
  /**
313
- * The ColorPicker prop subset folio's chrome relies on. The picker wraps a
314
- * trigger (`children`) in a popover exposing the `presets` plus a custom-color
313
+ * The ColorPicker prop subset folio's chrome relies on. The picker opens a
314
+ * popover from `trigger`, exposing the `presets` plus a custom-color
315
315
  * input; `onSelect` fires with a preset value or a 6-char hex (no `#`), and
316
316
  * `onClear` clears the color. The design-system ColorPicker accepts a superset
317
317
  * (placement, expansion, className) so it stays assignable as an override.
@@ -322,7 +322,12 @@ type FolioColorPickerProps = {
322
322
  onClear?: () => void;
323
323
  presets?: ColorPreset[];
324
324
  columns?: number;
325
- children: ReactNode;
325
+ /**
326
+ * One native `<button>` element that becomes the popover trigger itself. It
327
+ * must accept and forward props and a ref, so the picker never wraps it in a
328
+ * second, unnamed button.
329
+ */
330
+ trigger: ReactElement;
326
331
  };
327
332
  /**
328
333
  * The DatePickerPopover prop subset folio's chrome relies on. `value` accepts
@@ -596,6 +601,8 @@ type ToolbarProps = {
596
601
  onTableAction?: ((action: TableAction) => void) | undefined;
597
602
  };
598
603
  type DocxEditorProps = {
604
+ /** Accessible name announced for the editor or read-only document. */
605
+ accessibleName: string;
599
606
  /** Active document search result, including the zero-based current match index. */
600
607
  onFindResultChange?: (result: FindResult | null) => void;
601
608
  /** Document data — ArrayBuffer, Uint8Array, Blob, or File */
@@ -1245,5 +1252,5 @@ type RenderAsyncOptions = Omit<DocxEditorProps, "documentBuffer" | "document"> &
1245
1252
  * Resolves once the document has parsed and the first `onChange` fires.
1246
1253
  * Rejects if `onError` runs before that milestone.
1247
1254
  */
1248
- declare const renderAsync: (input: DocxInput, container: HTMLElement, options?: RenderAsyncOptions) => Promise<DocxEditorHandle>;
1255
+ declare const renderAsync: (input: DocxInput, container: HTMLElement, options: RenderAsyncOptions) => Promise<DocxEditorHandle>;
1249
1256
  export { FolioUIProvider as _, DocxEditorApplyDocumentOperationsOptions as a, DocxEditorRef as c, ToolbarProps as d, FontOption as f, FolioUIComponents as g, FolioButtonProps as h, renderAsync as i, HighlightPassageOptions as l, ColorPreset as m, EditorHandle as n, DocxEditorCollaboration as o, EditorMode as p, RenderAsyncOptions as r, DocxEditorProps as s, DocxEditorHandle as t, HighlightPassageResult as u, OutlineItem as v, FontDefinition as y };