@stll/folio-react 0.34.1 → 0.35.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.
Files changed (26) hide show
  1. package/README.md +15 -0
  2. package/dist/{CommentsSidebar-myF8qhju.js → CommentsSidebar-l092CpvD.js} +31 -39
  3. package/dist/{FindReplaceDialog-DbbzquBV.js → FindReplaceDialog-DTK6xana.js} +2 -2
  4. package/dist/{FootnotePropertiesDialog-BBq9iBzN.js → FootnotePropertiesDialog-mDtUjPE_.js} +2 -2
  5. package/dist/{ImagePositionDialog-CznMopDr.js → ImagePositionDialog-ZJQNtqFy.js} +2 -2
  6. package/dist/{ImagePropertiesDialog-TAm7NKLM.js → ImagePropertiesDialog-DChYHwgl.js} +2 -2
  7. package/dist/{InsertSymbolDialog-CrHgjUTz.js → InsertSymbolDialog-J_pp6t9O.js} +2 -2
  8. package/dist/{PageSetupDialog-DpTPXo9U.js → PageSetupDialog-CS6fgx2j.js} +2 -2
  9. package/dist/{SetNumberingValueDialog-BzUWmoaZ.js → SetNumberingValueDialog-D7pc4iaY.js} +1 -1
  10. package/dist/{TablePropertiesDialog-fDJc5_NR.js → TablePropertiesDialog-CrVVT48x.js} +2 -2
  11. package/dist/compat/eigenpal.d.ts +1 -1
  12. package/dist/compat/eigenpal.js +2 -2
  13. package/dist/{dialogs-BQ-7aAfV.js → dialogs-BgWQFSlU.js} +1 -1
  14. package/dist/{dialogs-CQHVbEgA.d.ts → dialogs-BjWjcllk.d.ts} +12 -11
  15. package/dist/dialogs.d.ts +1 -1
  16. package/dist/dialogs.js +8 -8
  17. package/dist/{folio-ui-CEFqJgCh.js → folio-ui-DNlnaoih.js} +1 -1
  18. package/dist/index.d.ts +7 -7
  19. package/dist/index.js +11 -13
  20. package/dist/{messages-DjrCTI3y.js → messages-BmWt6Yeu.js} +2 -2
  21. package/dist/messages.js +1 -1
  22. package/dist/{renderAsync-k1iPk-aX.js → renderAsync-CeGgJz8j.js} +1643 -1324
  23. package/dist/{renderAsync-CRk3aj3J.d.ts → renderAsync-Ddsn6AyR.d.ts} +96 -38
  24. package/dist/{rolldown-runtime-782esTHO.js → rolldown-runtime-BKpuH2hG.js} +4 -4
  25. package/dist/standalone.css +1 -1
  26. package/package.json +7 -7
@@ -1,10 +1,14 @@
1
- import React$1, { CSSProperties, ComponentProps, ComponentType, ForwardRefExoticComponent, JSX, ReactElement, ReactNode, RefAttributes, RefObject } from "react";
1
+ import React$1, { CSSProperties, ComponentProps, ComponentType, 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";
5
5
  import { FolioAIEditApplyMode, FolioAIEditApplyResult, FolioAIEditOperation, FolioAIEditSnapshot, FolioCommentAnchor, FolioDocumentNavigationTarget, FolioPendingSuggestionLoadResult, FolioPendingSuggestionRecord, FolioReviewChange, FolioUndefinedReferencePolicy } from "@stll/folio-core/ai-edits";
6
+ import { CanonicalHistoryDrop, CanonicalHistoryEffect } from "@stll/folio-core/canonical/canonicalSession";
6
7
  import { ContentControlFilter, SetContentControlContentInput, SetContentControlValueInput } from "@stll/folio-core/content-controls";
7
- import { FolioEditor } from "@stll/folio-core/controller/folioEditor";
8
+ import { FolioAnonymizationMatch, FolioAnonymizationTerm } from "@stll/folio-core/controller/anonymizationHighlights";
9
+ import { FolioAutocompleteApi, FolioAutocompleteState } from "@stll/folio-core/controller/autocompleteSuggestion";
10
+ import { CanonicalRoomCollaboration } from "@stll/folio-core/controller/canonicalRoomEditor";
11
+ import { FolioEditor, FolioSaveOptions, TextPosition } from "@stll/folio-core/controller/folioEditor";
8
12
  import { PageRendererName } from "@stll/folio-core/display-list/editor/pageRenderer";
9
13
  import { DocxCompatibility } from "@stll/folio-core/docx/compatibility";
10
14
  import { FolioSelectiveSaveFlags } from "@stll/folio-core/docx/selectiveSaveFlags";
@@ -16,29 +20,22 @@ import { BlockRect } from "@stll/folio-core/paged-layout/blockGeometry";
16
20
  import { ScrollToParaIdOptions } from "@stll/folio-core/paged-layout/paragraphFlash";
17
21
  import { ListState, SelectionState } from "@stll/folio-core/prosemirror";
18
22
  import { FolioSuggestion, SuggestionAppliedAs } from "@stll/folio-core/prosemirror/commands/comments";
19
- import { AnonymizationMatch } from "@stll/folio-core/prosemirror/plugins/anonymizationDecorations";
20
23
  import { TemplateSlashMenuKeyAction, TemplateSlashMenuState } from "@stll/folio-core/prosemirror/plugins/templateSlashMenu";
21
24
  import { FolioDocumentOperationBatch, FolioDocumentOperationResult, FolioDocumentOperationUndoHandle, FolioDocumentOperationUndoResult } from "@stll/folio-core/server";
25
+ import { EditorSession } from "@stll/folio-core/types/canonicalCapabilities";
22
26
  import { Comment } from "@stll/folio-core/types/content";
23
- import { ColorValue, Document, ParagraphAlignment, SdtProperties, SectionProperties, Style, Theme } from "@stll/folio-core/types/document";
27
+ import { ColorValue, Document, ParagraphAlignment, SdtProperties, Style, Theme } from "@stll/folio-core/types/document";
28
+ import { DeepReadonly, ReadonlyDocument } from "@stll/folio-core/types/documentModel";
24
29
  import { DocxInput } from "@stll/folio-core/utils/docxInput";
25
30
  import { FindMatch, FindOptions, FindResult } from "@stll/folio-core/utils/findReplace";
26
31
  import { OutlineDepth } from "@stll/folio-core/utils/outlineDepth";
27
- import "@stll/folio-core/controller/noteEditorManager";
28
32
  import { Layout } from "@stll/folio-core/layout-engine/types";
29
- import "@stll/folio-core/prosemirror/extensions/ExtensionManager";
30
- import "@stll/folio-core/controller/hiddenEditorApi";
31
- import "@stll/folio-core/controller/hiddenEditorManager";
32
- import "@stll/folio-core/types/canonicalCapabilities";
33
33
  import { Checkbox } from "@base-ui/react/checkbox";
34
34
  import { Dialog } from "@base-ui/react/dialog";
35
35
  import { Menu } from "@base-ui/react/menu";
36
36
  import { Popover } from "@base-ui/react/popover";
37
37
  import { Select } from "@base-ui/react/select";
38
- import "@stll/folio-core/managers/DocumentLoaderManager";
39
- import "@stll/folio-core/managers/HistoryManager";
40
38
  import { TableAction } from "@stll/folio-core/utils/tableOperations";
41
- import "react/jsx-runtime";
42
39
  /**
43
40
  * Declarative description of one custom font face the host registers with the
44
41
  * editor. Multiple entries can share `family` to register distinct weights.
@@ -56,8 +53,16 @@ type FontDefinition = {
56
53
  type PagedEditorRef = {
57
54
  /** The headless editor controller (imperative API + events; Seam 6). */
58
55
  getEditor: () => FolioEditor;
59
- /** Get the current document. */
60
- getDocument: () => Document | null;
56
+ /**
57
+ * The current document, built over the editor's model and sharing its
58
+ * parts: read it, never write it (`DocxEditorRef.getDocument` hands a copy).
59
+ */
60
+ getDocument: () => ReadonlyDocument | null;
61
+ /**
62
+ * The editor's document model, without a copy: in a canonical session the
63
+ * session's own document (read it, never write it); otherwise null.
64
+ */
65
+ readDocumentModel: () => ReadonlyDocument | null;
61
66
  /** Get the ProseMirror EditorState. */
62
67
  getState: () => EditorState | null;
63
68
  /** Get the ProseMirror EditorView. */
@@ -121,10 +126,6 @@ type PagedEditorRef = {
121
126
  from: number;
122
127
  to: number;
123
128
  } | null) => void;
124
- /** Resolve the page number (1-indexed) that contains the given PM position,
125
- * or null if no layout is available yet. Works for unrendered pages too via
126
- * the page shell map. */
127
- getPageNumberForPmPos: (pmPos: number) => number | null;
128
129
  /** Painted geometry for one AI-snapshot block. */
129
130
  getBlockRect: (blockId: string) => BlockRect | null;
130
131
  /** Painted geometry for many AI-snapshot blocks in one layout read. */
@@ -532,9 +533,9 @@ type ToolbarProps = {
532
533
  */
533
534
  onFormatPainter?: ((sticky: boolean) => void) | undefined;
534
535
  /** Document styles for the style picker */
535
- documentStyles?: Style[] | undefined;
536
+ documentStyles?: DeepReadonly<Style[]> | undefined;
536
537
  /** Theme for the style picker */
537
- theme?: Theme | null | undefined;
538
+ theme?: DeepReadonly<Theme> | null | undefined;
538
539
  /** Callback for print action */
539
540
  onPrint?: (() => void) | undefined;
540
541
  /** Whether to show print button (default: true) */
@@ -594,7 +595,7 @@ type ToolbarProps = {
594
595
  columnCount?: number | undefined;
595
596
  canSplitCell?: boolean | undefined;
596
597
  hasMultiCellSelection?: boolean | undefined;
597
- cellBorderColor?: ColorValue | undefined;
598
+ cellBorderColor?: DeepReadonly<ColorValue> | undefined;
598
599
  cellBackgroundColor?: string | undefined;
599
600
  } | null;
600
601
  /** Callback when a table action is triggered */
@@ -611,8 +612,16 @@ type DocxEditorProps = {
611
612
  password?: string | undefined;
612
613
  /** Pre-parsed document (alternative to documentBuffer) */
613
614
  document?: Document | null;
614
- /** Experimental plain-text canonical session; unsupported edits are refused. */
615
- experimentalSession?: "canonical";
615
+ /**
616
+ * The editing engine. Unset, the editor runs the canonical session, which
617
+ * refuses unsupported edits with a notice, or the legacy session when
618
+ * `collaboration` is a Yjs fragment. `"legacy"` selects the
619
+ * ProseMirror-owned engine.
620
+ * A host plugin's transaction or a direct dispatch that changes the
621
+ * document is refused too, its refusal naming the transaction's meta keys:
622
+ * express such an edit as document operations (`applyDocumentOperations`).
623
+ */
624
+ experimentalSession?: EditorSession;
616
625
  /** Callback when document is saved */
617
626
  onSave?: (buffer: ArrayBuffer) => void;
618
627
  /** Author name used for comments and track changes */
@@ -658,7 +667,7 @@ type DocxEditorProps = {
658
667
  */
659
668
  fonts?: ReadonlyArray<FontDefinition>;
660
669
  /** Theme for styling */
661
- theme?: Theme | null;
670
+ theme?: DeepReadonly<Theme> | null;
662
671
  /** Whether to show toolbar (default: true) */
663
672
  showToolbar?: boolean;
664
673
  /** Whether to show zoom control (default: true) */
@@ -823,8 +832,9 @@ type DocxEditorProps = {
823
832
  /**
824
833
  * Controlled comments array. When provided, the editor reads comment thread
825
834
  * metadata from this prop and emits every change through `onCommentsChange`.
826
- * Use with collaboration backends (Yjs, etc.) so comment threads sync across
827
- * peers; PM carries range markers, thread metadata lives outside the doc.
835
+ * In a canonical room the comments are operations of the room's journal:
836
+ * the editor reports them through `onCommentsChange` and never reads this
837
+ * prop back.
828
838
  */
829
839
  comments?: Comment[];
830
840
  /** Fires whenever the comments array changes (controlled and uncontrolled). */
@@ -837,6 +847,21 @@ type DocxEditorProps = {
837
847
  * (decoration meta, apply, scroll-to) from outside the editor.
838
848
  */
839
849
  onEditorViewReady?: (view: EditorView | null) => void;
850
+ /**
851
+ * With the canonical session: called after each edit, undo or redo is
852
+ * published in any story, with what it did to the session's undo history.
853
+ * A host that keeps its own undo stack (and owns `hostShortcuts`'
854
+ * `"history"`) adds one entry per `opened` and sends undo / redo back
855
+ * through `DocxEditorRef.undo` / `redo`.
856
+ */
857
+ onCanonicalHistory?: (effect: CanonicalHistoryEffect) => void;
858
+ /**
859
+ * With the canonical session: called when a peer's edit in a canonical
860
+ * room left local history steps unusable, with how many of each stack it
861
+ * dropped, counted from the bottom. A host that mirrors the steps in its
862
+ * own undo stack removes as many.
863
+ */
864
+ onCanonicalHistoryDrop?: (drop: CanonicalHistoryDrop) => void;
840
865
  /**
841
866
  * Host ProseMirror plugins for the body editor, retained across document
842
867
  * replacements. Keep the array and plugin instances stable for a mounted
@@ -844,16 +869,30 @@ type DocxEditorProps = {
844
869
  * host, collaboration, and built-in plugins.
845
870
  */
846
871
  plugins?: readonly Plugin[] | undefined;
847
- /** Yjs-backed collaboration owner. Experimental and opt-in. */
872
+ /**
873
+ * Edit together with other editors. With the canonical session, the
874
+ * canonical room the session joins; with the legacy session, the Yjs
875
+ * fragment it edits. Experimental and opt-in.
876
+ */
848
877
  collaboration?: DocxEditorCollaboration | undefined;
849
878
  /**
850
- * Fires with the current anonymization match list every time
851
- * the decoration plugin recomputes it (initial mount, term
852
- * push, doc edit, async DOCX load). The host uses this to
853
- * mirror per-document counts and "matching workspace terms"
854
- * to the inspector facet without polling the plugin state.
879
+ * Terms to highlight wherever they occur in the shown text of every story
880
+ * (body, table cells, headers, footers, notes), in either session. A term
881
+ * matches literally, case-insensitively and on word boundaries, across
882
+ * formatting runs; text inside a tracked deletion is matched too.
883
+ * Highlights are view state: they never change the document, its undo
884
+ * history or its pending changes, and they follow every edit, a peer's
885
+ * included. Pass a new array to change the terms.
886
+ */
887
+ anonymizationTerms?: readonly FolioAnonymizationTerm[] | undefined;
888
+ /** Called with the inline autocomplete suggestion each time it changes. */
889
+ onAutocompleteChange?: ((state: FolioAutocompleteState) => void) | undefined;
890
+ /**
891
+ * Fires with every occurrence, as text positions, each time the set of
892
+ * occurrences changes (new terms, an edit, a load). An edit elsewhere in
893
+ * the document does not fire it.
855
894
  */
856
- onAnonymizationMatchesChange?: (matches: readonly AnonymizationMatch[]) => void;
895
+ onAnonymizationMatchesChange?: (matches: readonly FolioAnonymizationMatch[]) => void;
857
896
  /**
858
897
  * Fires when the user clicks an anonymization highlight in
859
898
  * the rendered document. Hosts use this to push the
@@ -921,7 +960,9 @@ type DocxEditorProps = {
921
960
  */
922
961
  onSelectiveSaveTripwire?: (result: TripwireResult) => void;
923
962
  };
924
- type DocxEditorCollaboration = {
963
+ type DocxEditorCollaboration = CanonicalRoomCollaboration | DocxEditorYjsCollaboration;
964
+ /** A Yjs fragment the legacy session edits, and the plugins that bind it. */
965
+ type DocxEditorYjsCollaboration = {
925
966
  awareness?: {
926
967
  clientID: number;
927
968
  getStates: () => Map<number, unknown>;
@@ -932,6 +973,8 @@ type DocxEditorCollaboration = {
932
973
  plugins?: Plugin[] | undefined;
933
974
  shouldSeed?: boolean | undefined;
934
975
  yXmlFragment: XmlFragment;
976
+ /** A canonical room is reached through `connect`; a Yjs fragment has none. */
977
+ connect?: never;
935
978
  };
936
979
  type DocxEditorApplyDocumentOperationsOptions = {
937
980
  undefinedReferences: FolioUndefinedReferencePolicy;
@@ -975,9 +1018,7 @@ type DocxEditorRef = {
975
1018
  /** The headless editor controller (Seam 6), or null before the editor mounts. */
976
1019
  getEditor: () => FolioEditor | null;
977
1020
  /** Save the document to buffer. Pass { selective: false } to force full repack. */
978
- save: (options?: {
979
- selective?: boolean;
980
- }) => Promise<ArrayBuffer | null>;
1021
+ save: (options?: FolioSaveOptions) => Promise<ArrayBuffer | null>;
981
1022
  /** Set zoom level */
982
1023
  setZoom: (zoom: number) => void;
983
1024
  /** Get current zoom level */
@@ -1153,6 +1194,23 @@ type DocxEditorRef = {
1153
1194
  getPageText: (page: number) => string | null;
1154
1195
  /** Resolve a stable block or text range to its real 1-based rendered page. */
1155
1196
  getTargetPage: (target: FolioDocumentNavigationTarget, snapshot?: FolioAIEditSnapshot) => number | null;
1197
+ /**
1198
+ * The 1-based rendered page that shows a body text position (story,
1199
+ * paragraph id, offset), or null before layout or when no paragraph in the
1200
+ * body has that id.
1201
+ */
1202
+ getPositionPage: (position: TextPosition) => number | null;
1203
+ /**
1204
+ * The inline autocomplete suggestion: ghost text streamed in at a text
1205
+ * position and shown beside the caret, in either session. It is view
1206
+ * state: it never changes the document, its undo history or its pending
1207
+ * changes, and it stays on its text when a peer edits. Typing its next
1208
+ * characters consumes them; any other edit dismisses it. Tab accepts it,
1209
+ * Mod-ArrowRight its next word, Escape dismisses it.
1210
+ */
1211
+ autocomplete: FolioAutocompleteApi;
1212
+ /** Every occurrence of the `anonymizationTerms`, as text positions. */
1213
+ getAnonymizationMatches: () => readonly FolioAnonymizationMatch[];
1156
1214
  /** Painted geometry for one block, relative to this editor's scroll root. */
1157
1215
  getBlockRect: (blockId: string) => BlockRect | null;
1158
1216
  /** Painted geometry for many blocks in one layout read; missing ids are omitted. */
@@ -1253,4 +1311,4 @@ type RenderAsyncOptions = Omit<DocxEditorProps, "documentBuffer" | "document"> &
1253
1311
  * Rejects if `onError` runs before that milestone.
1254
1312
  */
1255
1313
  declare const renderAsync: (input: DocxInput, container: HTMLElement, options: RenderAsyncOptions) => Promise<DocxEditorHandle>;
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 };
1314
+ export { FolioUIComponents as _, DocxEditorApplyDocumentOperationsOptions as a, FontDefinition as b, DocxEditorRef as c, HighlightPassageResult as d, ToolbarProps as f, FolioButtonProps as g, ColorPreset as h, renderAsync as i, DocxEditorYjsCollaboration as l, EditorMode as m, EditorHandle as n, DocxEditorCollaboration as o, FontOption as p, RenderAsyncOptions as r, DocxEditorProps as s, DocxEditorHandle as t, HighlightPassageOptions as u, FolioUIProvider as v, OutlineItem as y };
@@ -3,14 +3,14 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __exportAll = (all, no_symbols) => {
7
- let target = {};
6
+ var __exportAll = (all, flags) => {
7
+ let target = Object.setPrototypeOf({}, null);
8
8
  for (var name in all) __defProp(target, name, {
9
9
  get: all[name],
10
10
  enumerable: true
11
11
  });
12
- if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
13
- return target;
12
+ if (!(flags & 1)) __defProp(target, Symbol.toStringTag, { value: "Module" });
13
+ return flags & 2 ? target : Object.preventExtensions(target);
14
14
  };
15
15
  var __copyProps = (to, from, except, desc) => {
16
16
  if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {