@stll/folio-react 0.3.0 → 0.4.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.
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ import React$1, { CSSProperties, ComponentProps, ComponentType, ReactNode, Ref,
2
2
  import { EditorState, Plugin, Transaction } from "prosemirror-state";
3
3
  import { EditorView } from "prosemirror-view";
4
4
  import { XmlFragment } from "yjs";
5
- import { FolioAIBlock, FolioAIBlockAnchor, FolioAIBlockKind, FolioAIBlockPreviewRun, FolioAIComment, FolioAIEditAppliedOperation, FolioAIEditApplyMode, FolioAIEditApplyMode as FolioAIEditApplyMode$1, FolioAIEditApplyResult, FolioAIEditApplyResult as FolioAIEditApplyResult$1, FolioAIEditOperation, FolioAIEditOperation as FolioAIEditOperation$1, FolioAIEditReviewMeta, FolioAIEditSeverity, FolioAIEditSkipReason, FolioAIEditSkippedOperation, FolioAIEditSnapshot, FolioAIEditSnapshot as FolioAIEditSnapshot$1, FolioAISignatureParty, WordDiffSegment, applyFolioAIEditOperations, createFolioAIEditSnapshot, diffWordSegments, hashFolioAIBlockText, normalizeFolioAIBlockText } from "@stll/folio-core/ai-edits";
5
+ import { FolioAIBlock, FolioAIBlockAnchor, FolioAIBlockKind, FolioAIBlockPreviewRun, FolioAIComment, FolioAIEditAppliedOperation, FolioAIEditApplyMode, FolioAIEditApplyMode as FolioAIEditApplyMode$1, FolioAIEditApplyResult, FolioAIEditApplyResult as FolioAIEditApplyResult$1, FolioAIEditOperation, FolioAIEditOperation as FolioAIEditOperation$1, FolioAIEditReviewMeta, FolioAIEditSeverity, FolioAIEditSkipReason, FolioAIEditSkippedOperation, FolioAIEditSnapshot, FolioAIEditSnapshot as FolioAIEditSnapshot$1, FolioAISignatureParty, FolioCommentAnchor, FolioReviewChange, WordDiffSegment, applyFolioAIEditOperations, createFolioAIEditSnapshot, diffWordSegments, hashFolioAIBlockText, normalizeFolioAIBlockText } from "@stll/folio-core/ai-edits";
6
6
  import { ContentControlFilter, SetContentControlContentInput, SetContentControlValueInput } from "@stll/folio-core/content-controls";
7
7
  import { FolioEditor } from "@stll/folio-core/controller/folioEditor";
8
8
  import { DocxCompatibility, DocxCompatibility as DocxCompatibility$1 } from "@stll/folio-core/docx/compatibility";
@@ -818,6 +818,28 @@ type DocxEditorRef = {
818
818
  * a fresh-from-live-doc snapshot.
819
819
  */
820
820
  scrollToBlock: (blockId: string, snapshot?: FolioAIEditSnapshot$1) => boolean;
821
+ /**
822
+ * The tracked changes (insertions and deletions) present in the live
823
+ * document, read from the current ProseMirror `state.doc`. Empty array
824
+ * before the editor view mounts.
825
+ */
826
+ getTrackedChanges: () => FolioReviewChange[];
827
+ /**
828
+ * The comment anchors present in the live document, read from the current
829
+ * ProseMirror `state.doc`. Empty array before the editor view mounts.
830
+ */
831
+ getCommentAnchors: () => FolioCommentAnchor[];
832
+ /**
833
+ * The plain text of the current selection, or `""` when the editor has no
834
+ * view or the selection is collapsed.
835
+ */
836
+ getSelectionText: () => string;
837
+ /**
838
+ * The plain text of a single rendered page (1-based), joining each of its
839
+ * layout fragments with a newline. Returns `null` when the page number is
840
+ * out of range or the layout hasn't been computed yet.
841
+ */
842
+ getPageText: (page: number) => string | null;
821
843
  /**
822
844
  * List every block-level content control in the live document, filtered by
823
845
  * tag / alias / id / sdtType. Returns the modeled SdtProperties projection
package/dist/index.js CHANGED
@@ -6,11 +6,11 @@ import * as React$1 from "react";
6
6
  import React, { Component, Suspense, cloneElement, createContext, isValidElement, lazy, memo, useCallback, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
7
7
  import { AlertCircleIcon, AlertTriangleIcon, AlignCenterIcon, AlignJustifyIcon, AlignLeftIcon, AlignRightIcon, BaselineIcon, BoldIcon, CheckIcon, ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, ClipboardCopyIcon, EyeIcon, FileIcon, GlobeIcon, ImageIcon, IndentDecreaseIcon, IndentIncreaseIcon, InfoIcon, ItalicIcon, LinkIcon, ListIcon, ListOrderedIcon, MoreHorizontalIcon, PaintbrushIcon, PenLineIcon, PencilIcon, PilcrowIcon, Redo2Icon, RulerIcon, SeparatorHorizontalIcon, SquarePenIcon, StickyNoteIcon, TableIcon, TableOfContentsIcon, TypeIcon, UnderlineIcon, Undo2Icon, UnlinkIcon, XIcon } from "lucide-react";
8
8
  import { IntlProvider, useTranslations } from "use-intl";
9
- import { applyFolioAIEditOperations, applyFolioAIEditOperations as applyFolioAIEditOperations$1, createFolioAIEditSnapshot, createFolioAIEditSnapshot as createFolioAIEditSnapshot$1, diffWordSegments, hashFolioAIBlockText, normalizeFolioAIBlockText } from "@stll/folio-core/ai-edits";
9
+ import { applyFolioAIEditOperations, applyFolioAIEditOperations as applyFolioAIEditOperations$1, createFolioAIEditSnapshot, createFolioAIEditSnapshot as createFolioAIEditSnapshot$1, diffWordSegments, getCommentAnchorsFromDoc, getTrackedChangesFromDoc, hashFolioAIBlockText, normalizeFolioAIBlockText } from "@stll/folio-core/ai-edits";
10
10
  import { normalizeBaseDirection } from "@stll/folio-core/docx/normalizeBaseDirection";
11
11
  import { getCachedNumberingMap } from "@stll/folio-core/docx/numberingParser";
12
12
  import { computeScrollPageInfo, updateScrollPageTotal } from "@stll/folio-core/paged-layout/scrollPageInfo";
13
- import { TextSelection, addColumnLeft, addColumnRight, addRowAbove, addRowBelow, applyFormatMarks, applyStyle, applyTableStyle, autoFitContents, captureFormatMarks, clearFormatting, clearTextColor, createStyleResolver, decreaseIndent, decreaseListLevel, deleteColumn, deleteRow, deleteTable, distributeColumns, extractSelectionState, getTableContext, increaseIndent, increaseListLevel, insertImageFromFile, insertPageBreakInView, insertTableInView, insertTableOfContentsInView, mergeCells, removeTabStop, removeTableBorders, schema, selectColumn, selectRow, selectTable, setAlignment, setAllTableBorders, setCellBorder, setCellFillColor, setCellMargins, setCellTextDirection, setCellVerticalAlign, setFontFamily, setFontSize, setHighlight, setIndentFirstLine, setIndentLeft, setIndentRight, setInsideTableBorders, setLineSpacing, setLtr, setOutsideTableBorders, setRowHeight, setRtl, setTableBorderColor, setTableBorderPreset, setTableBorderWidth, setTableProperties, setTextColor, splitCell, toggleBidi, toggleBold, toggleBulletList, toggleHeaderRow, toggleItalic, toggleNoWrap, toggleNumberedList, toggleStrike, toggleSubscript, toggleSuperscript, toggleUnderline } from "@stll/folio-core/prosemirror";
13
+ import { TextSelection, addColumnLeft, addColumnRight, addRowAbove, addRowBelow, applyFormatMarks, applyStyle, applyTableStyle, autoFitContents, captureFormatMarks, clearFormatting, clearTextColor, createStyleResolver, decreaseIndent, decreaseListLevel, deleteColumn, deleteRow, deleteTable, distributeColumns, extractSelectionState, getSelectedText, getTableContext, increaseIndent, increaseListLevel, insertImageFromFile, insertPageBreakInView, insertTableInView, insertTableOfContentsInView, mergeCells, removeTabStop, removeTableBorders, schema, selectColumn, selectRow, selectTable, setAlignment, setAllTableBorders, setCellBorder, setCellFillColor, setCellMargins, setCellTextDirection, setCellVerticalAlign, setFontFamily, setFontSize, setHighlight, setIndentFirstLine, setIndentLeft, setIndentRight, setInsideTableBorders, setLineSpacing, setLtr, setOutsideTableBorders, setRowHeight, setRtl, setTableBorderColor, setTableBorderPreset, setTableBorderWidth, setTableProperties, setTextColor, splitCell, toggleBidi, toggleBold, toggleBulletList, toggleHeaderRow, toggleItalic, toggleNoWrap, toggleNumberedList, toggleStrike, toggleSubscript, toggleSuperscript, toggleUnderline } from "@stll/folio-core/prosemirror";
14
14
  import { acceptAIEditRevision, acceptChange, findAIEditRevisionRange, findChangeAtPosition, findNextChange, findParagraphBoundaryChangeAtPosition, findPreviousChange, rejectAIEditRevision, rejectChange } from "@stll/folio-core/prosemirror/commands/comments";
15
15
  import { blockSdtAttrsToSdtProperties, findBlockSdtMatch, findBlockSdtMatches, removeContentControlTr, setContentControlContentTr, setContentControlValueTr } from "@stll/folio-core/prosemirror/commands/contentControls";
16
16
  import { setContentControlContentBlocksTr } from "@stll/folio-core/prosemirror/commands/contentControlsBlockFill";
@@ -6142,6 +6142,26 @@ function resolveCommentCreationRange({ docSize, capturedRange, currentRange, sav
6142
6142
  })();
6143
6143
  return range ? clampCommentMarkRange(docSize, range) : null;
6144
6144
  }
6145
+ //#endregion
6146
+ //#region src/components/pageText.ts
6147
+ /**
6148
+ * The plain text of a single rendered page (1-based), read by joining each of
6149
+ * the page's layout fragments' `[pmStart, pmEnd)` document text with a
6150
+ * newline. Fragments with no `pmStart`/`pmEnd` (e.g. a page-shell placeholder)
6151
+ * are skipped. Returns `null` when the layout hasn't been computed yet or the
6152
+ * page number is out of range.
6153
+ */
6154
+ const getPageTextFromLayout = (layout, doc, page) => {
6155
+ if (!layout || !Number.isInteger(page) || page < 1) return null;
6156
+ const layoutPage = layout.pages[page - 1];
6157
+ if (!layoutPage) return null;
6158
+ const fragmentTexts = [];
6159
+ for (const fragment of layoutPage.fragments) {
6160
+ if (typeof fragment.pmStart !== "number" || typeof fragment.pmEnd !== "number") continue;
6161
+ fragmentTexts.push(doc.textBetween(fragment.pmStart, fragment.pmEnd, "\n"));
6162
+ }
6163
+ return fragmentTexts.join("\n");
6164
+ };
6145
6165
  /** Stable empty anchor positions Map used as the initial state. */
6146
6166
  const EMPTY_ANCHOR_POSITIONS = /* @__PURE__ */ new Map();
6147
6167
  let nextCommentId = Date.now();
@@ -11681,6 +11701,23 @@ function DocxEditor({ ref, documentBuffer, document: initialDocument, documentKe
11681
11701
  });
11682
11702
  return true;
11683
11703
  },
11704
+ getTrackedChanges: () => {
11705
+ const view = pagedEditorRef.current?.getView();
11706
+ return view ? getTrackedChangesFromDoc(view.state.doc) : [];
11707
+ },
11708
+ getCommentAnchors: () => {
11709
+ const view = pagedEditorRef.current?.getView();
11710
+ return view ? getCommentAnchorsFromDoc(view.state.doc) : [];
11711
+ },
11712
+ getSelectionText: () => {
11713
+ const view = pagedEditorRef.current?.getView();
11714
+ return view ? getSelectedText(view.state) : "";
11715
+ },
11716
+ getPageText: (page) => {
11717
+ const view = pagedEditorRef.current?.getView();
11718
+ if (!view) return null;
11719
+ return getPageTextFromLayout(pagedEditorRef.current?.getEditor()?.getLayout() ?? null, view.state.doc, page);
11720
+ },
11684
11721
  getContentControls: (filter = {}) => {
11685
11722
  const view = pagedEditorRef.current?.getView();
11686
11723
  if (!view) return [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stll/folio-react",
3
- "version": "0.3.0",
3
+ "version": "0.4.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",
@@ -58,7 +58,7 @@
58
58
  "@fontsource/cousine": "^5.2.7",
59
59
  "@fontsource/noto-sans-arabic": "^5.2.7",
60
60
  "@fontsource/tinos": "^5.2.7",
61
- "@stll/folio-core": "^0.1.3",
61
+ "@stll/folio-core": "^0.2.0",
62
62
  "better-result": "2.9.2",
63
63
  "lucide-react": "1.21.0",
64
64
  "prosemirror-history": "^1.5.0",
@@ -82,6 +82,7 @@
82
82
  "types": "./dist/index.d.ts",
83
83
  "files": [
84
84
  "dist",
85
+ "skills",
85
86
  "README.md",
86
87
  "LICENSE",
87
88
  "NOTICE.md"