@ai-matrx/office 0.8.21 → 0.8.23

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/docs.d.cts CHANGED
@@ -785,4 +785,55 @@ declare function documentBodyWriteHandler(deps: {
785
785
  assertWritable: (whatItBlocks: string) => void;
786
786
  }): DocumentBodyWriteHandler;
787
787
 
788
- export { type BodyEdit, type BodyText, CARET_HEARTBEAT_MS, CARET_MAX_RANGES, CARET_STALE_MS, type CaretRange, type CreateDocumentArgs, DOCUMENT_BODY_MAX_LENGTH, DOCUMENT_DESCRIPTION_MAX_LENGTH, DOCUMENT_NAME_MAX_LENGTH, DOCUMENT_SAVE_DELAY_MS, type DocsHostPorts, type DocsSupabase, type DocumentAwareness, type DocumentBodyPort, type DocumentBodyWriteHandler, type DocumentCollabBase, type DocumentCollabFactory, type DocumentCollabHandle, DocumentModel, type DocumentModelDeps, type DocumentOtFactory, type DocumentOtHandle, type DocumentSnapshotData, type DocumentViewPort, EMOJI_GROUPS, type Glyph, MIN_FIT_ZOOM, type ParkedDocumentEditor, type PublishedCaret, type RemoteCaret, RemoteCaretBook, SPECIAL_GROUPS, type SaveDocumentSnapshotArgs, bodyTextOf, configureDocsHost, copyDocument, createDocument, deleteDocument, discardFailedDocument, documentBodyWriteHandler, documentSourceLabel, fitZoomRatio, getDocsHost, getDocument, getLatestDocumentSnapshot, listAccessibleDocuments, listDocumentSnapshots, listTrashedDocuments, moveDocument, movePeerRangesThroughBodyEdit, moveRangesThroughBodyEdit, planBodyEdit, publishedCaretFromSelection, renameDocument, restoreDocument, sanitizeUniverDocSnapshot, saveDocumentSnapshot, searchSymbols, updateDocumentDescription, validateDocumentBody, validateDocumentDescription, validateDocumentName, writeBodyText };
788
+ /**
789
+ * Comment anchors in a document (COLLAB-DESIGN §8, unit C9).
790
+ *
791
+ * A comment points at its passage through a CUSTOM RANGE in the document body (`rangeType` COMMENT, `rangeId` =
792
+ * the anchor id). The range is part of the document, so it travels in the same `rich-text-editing` ops as the
793
+ * text and moves through every concurrent edit with our transform (C0: custom ranges pass against every family;
794
+ * Univer's own comment DECORATIONS do not, and are never used). The thread itself (messages, author, resolved)
795
+ * lives in the platform's one comment store, `platform.comments`, as a `part_anchor` whose `part_key` is
796
+ * `anchor:<id>` and whose `label` is the quoted text when the comment was made.
797
+ *
798
+ * A thread whose anchor no longer appears in the body had all of its text removed: it is ORPHANED and shown as
799
+ * "text removed", never dropped.
800
+ */
801
+
802
+ /** The custom-range type our anchors use. Univer draws no style for it; the highlight is ours. */
803
+ declare const COMMENT_ANCHOR_RANGE_TYPE = CustomRangeType.COMMENT;
804
+ /** `part_anchor.part_key` prefix of a comment anchored inside a Doc or a Sheet. */
805
+ declare const COMMENT_ANCHOR_PART_PREFIX = "anchor:";
806
+ /** The quoted text kept on the thread (the `part_anchor.label` limit). */
807
+ declare const COMMENT_ANCHOR_LABEL_MAX = 200;
808
+ /** A fresh anchor id: 16 random base-36 characters (custom-range ids are plain strings). */
809
+ declare function newCommentAnchorId(): string;
810
+ declare function commentAnchorPartKey(anchorId: string): string;
811
+ /** The anchor id a `part_anchor` names, or null when it is not one of ours. */
812
+ declare function anchorIdOfPartAnchor(anchor: unknown): string | null;
813
+ /** The `part_anchor` a new thread on this anchor carries. */
814
+ declare function commentPartAnchor(anchorId: string, quote: string): {
815
+ __kind: "part_anchor";
816
+ part_key: string;
817
+ label?: string;
818
+ };
819
+ /** Where one anchor sits in the body now: `[start, end)` in body offsets, and the text it covers. */
820
+ interface CommentAnchorSpan {
821
+ id: string;
822
+ start: number;
823
+ end: number;
824
+ text: string;
825
+ }
826
+ /**
827
+ * Every comment anchor in a body, by id. A range Univer split into pieces (text inserted inside it, a paragraph
828
+ * break) is one anchor from its first piece's start to its last piece's end. Univer's `endIndex` is inclusive.
829
+ */
830
+ declare function commentAnchorsOf(body: unknown): Map<string, CommentAnchorSpan>;
831
+ /** The `rich-text-editing` actions that anchor `[start, end)` of the body to `anchorId` (null when it cannot). */
832
+ declare function addCommentAnchorActions(body: unknown, start: number, end: number, anchorId: string): unknown[] | null;
833
+ /**
834
+ * The `rich-text-editing` actions that take one anchor out of the body (a draft the person cancelled), keeping
835
+ * its text. Null when the anchor is not there.
836
+ */
837
+ declare function removeCommentAnchorActions(documentDataModel: unknown, anchorId: string): unknown[] | null;
838
+
839
+ export { type BodyEdit, type BodyText, CARET_HEARTBEAT_MS, CARET_MAX_RANGES, CARET_STALE_MS, COMMENT_ANCHOR_LABEL_MAX, COMMENT_ANCHOR_PART_PREFIX, COMMENT_ANCHOR_RANGE_TYPE, type CaretRange, type CommentAnchorSpan, type CreateDocumentArgs, DOCUMENT_BODY_MAX_LENGTH, DOCUMENT_DESCRIPTION_MAX_LENGTH, DOCUMENT_NAME_MAX_LENGTH, DOCUMENT_SAVE_DELAY_MS, type DocsHostPorts, type DocsSupabase, type DocumentAwareness, type DocumentBodyPort, type DocumentBodyWriteHandler, type DocumentCollabBase, type DocumentCollabFactory, type DocumentCollabHandle, DocumentModel, type DocumentModelDeps, type DocumentOtFactory, type DocumentOtHandle, type DocumentSnapshotData, type DocumentViewPort, EMOJI_GROUPS, type Glyph, MIN_FIT_ZOOM, type ParkedDocumentEditor, type PublishedCaret, type RemoteCaret, RemoteCaretBook, SPECIAL_GROUPS, type SaveDocumentSnapshotArgs, addCommentAnchorActions, anchorIdOfPartAnchor, bodyTextOf, commentAnchorPartKey, commentAnchorsOf, commentPartAnchor, configureDocsHost, copyDocument, createDocument, deleteDocument, discardFailedDocument, documentBodyWriteHandler, documentSourceLabel, fitZoomRatio, getDocsHost, getDocument, getLatestDocumentSnapshot, listAccessibleDocuments, listDocumentSnapshots, listTrashedDocuments, moveDocument, movePeerRangesThroughBodyEdit, moveRangesThroughBodyEdit, newCommentAnchorId, planBodyEdit, publishedCaretFromSelection, removeCommentAnchorActions, renameDocument, restoreDocument, sanitizeUniverDocSnapshot, saveDocumentSnapshot, searchSymbols, updateDocumentDescription, validateDocumentBody, validateDocumentDescription, validateDocumentName, writeBodyText };
package/dist/docs.d.ts CHANGED
@@ -785,4 +785,55 @@ declare function documentBodyWriteHandler(deps: {
785
785
  assertWritable: (whatItBlocks: string) => void;
786
786
  }): DocumentBodyWriteHandler;
787
787
 
788
- export { type BodyEdit, type BodyText, CARET_HEARTBEAT_MS, CARET_MAX_RANGES, CARET_STALE_MS, type CaretRange, type CreateDocumentArgs, DOCUMENT_BODY_MAX_LENGTH, DOCUMENT_DESCRIPTION_MAX_LENGTH, DOCUMENT_NAME_MAX_LENGTH, DOCUMENT_SAVE_DELAY_MS, type DocsHostPorts, type DocsSupabase, type DocumentAwareness, type DocumentBodyPort, type DocumentBodyWriteHandler, type DocumentCollabBase, type DocumentCollabFactory, type DocumentCollabHandle, DocumentModel, type DocumentModelDeps, type DocumentOtFactory, type DocumentOtHandle, type DocumentSnapshotData, type DocumentViewPort, EMOJI_GROUPS, type Glyph, MIN_FIT_ZOOM, type ParkedDocumentEditor, type PublishedCaret, type RemoteCaret, RemoteCaretBook, SPECIAL_GROUPS, type SaveDocumentSnapshotArgs, bodyTextOf, configureDocsHost, copyDocument, createDocument, deleteDocument, discardFailedDocument, documentBodyWriteHandler, documentSourceLabel, fitZoomRatio, getDocsHost, getDocument, getLatestDocumentSnapshot, listAccessibleDocuments, listDocumentSnapshots, listTrashedDocuments, moveDocument, movePeerRangesThroughBodyEdit, moveRangesThroughBodyEdit, planBodyEdit, publishedCaretFromSelection, renameDocument, restoreDocument, sanitizeUniverDocSnapshot, saveDocumentSnapshot, searchSymbols, updateDocumentDescription, validateDocumentBody, validateDocumentDescription, validateDocumentName, writeBodyText };
788
+ /**
789
+ * Comment anchors in a document (COLLAB-DESIGN §8, unit C9).
790
+ *
791
+ * A comment points at its passage through a CUSTOM RANGE in the document body (`rangeType` COMMENT, `rangeId` =
792
+ * the anchor id). The range is part of the document, so it travels in the same `rich-text-editing` ops as the
793
+ * text and moves through every concurrent edit with our transform (C0: custom ranges pass against every family;
794
+ * Univer's own comment DECORATIONS do not, and are never used). The thread itself (messages, author, resolved)
795
+ * lives in the platform's one comment store, `platform.comments`, as a `part_anchor` whose `part_key` is
796
+ * `anchor:<id>` and whose `label` is the quoted text when the comment was made.
797
+ *
798
+ * A thread whose anchor no longer appears in the body had all of its text removed: it is ORPHANED and shown as
799
+ * "text removed", never dropped.
800
+ */
801
+
802
+ /** The custom-range type our anchors use. Univer draws no style for it; the highlight is ours. */
803
+ declare const COMMENT_ANCHOR_RANGE_TYPE = CustomRangeType.COMMENT;
804
+ /** `part_anchor.part_key` prefix of a comment anchored inside a Doc or a Sheet. */
805
+ declare const COMMENT_ANCHOR_PART_PREFIX = "anchor:";
806
+ /** The quoted text kept on the thread (the `part_anchor.label` limit). */
807
+ declare const COMMENT_ANCHOR_LABEL_MAX = 200;
808
+ /** A fresh anchor id: 16 random base-36 characters (custom-range ids are plain strings). */
809
+ declare function newCommentAnchorId(): string;
810
+ declare function commentAnchorPartKey(anchorId: string): string;
811
+ /** The anchor id a `part_anchor` names, or null when it is not one of ours. */
812
+ declare function anchorIdOfPartAnchor(anchor: unknown): string | null;
813
+ /** The `part_anchor` a new thread on this anchor carries. */
814
+ declare function commentPartAnchor(anchorId: string, quote: string): {
815
+ __kind: "part_anchor";
816
+ part_key: string;
817
+ label?: string;
818
+ };
819
+ /** Where one anchor sits in the body now: `[start, end)` in body offsets, and the text it covers. */
820
+ interface CommentAnchorSpan {
821
+ id: string;
822
+ start: number;
823
+ end: number;
824
+ text: string;
825
+ }
826
+ /**
827
+ * Every comment anchor in a body, by id. A range Univer split into pieces (text inserted inside it, a paragraph
828
+ * break) is one anchor from its first piece's start to its last piece's end. Univer's `endIndex` is inclusive.
829
+ */
830
+ declare function commentAnchorsOf(body: unknown): Map<string, CommentAnchorSpan>;
831
+ /** The `rich-text-editing` actions that anchor `[start, end)` of the body to `anchorId` (null when it cannot). */
832
+ declare function addCommentAnchorActions(body: unknown, start: number, end: number, anchorId: string): unknown[] | null;
833
+ /**
834
+ * The `rich-text-editing` actions that take one anchor out of the body (a draft the person cancelled), keeping
835
+ * its text. Null when the anchor is not there.
836
+ */
837
+ declare function removeCommentAnchorActions(documentDataModel: unknown, anchorId: string): unknown[] | null;
838
+
839
+ export { type BodyEdit, type BodyText, CARET_HEARTBEAT_MS, CARET_MAX_RANGES, CARET_STALE_MS, COMMENT_ANCHOR_LABEL_MAX, COMMENT_ANCHOR_PART_PREFIX, COMMENT_ANCHOR_RANGE_TYPE, type CaretRange, type CommentAnchorSpan, type CreateDocumentArgs, DOCUMENT_BODY_MAX_LENGTH, DOCUMENT_DESCRIPTION_MAX_LENGTH, DOCUMENT_NAME_MAX_LENGTH, DOCUMENT_SAVE_DELAY_MS, type DocsHostPorts, type DocsSupabase, type DocumentAwareness, type DocumentBodyPort, type DocumentBodyWriteHandler, type DocumentCollabBase, type DocumentCollabFactory, type DocumentCollabHandle, DocumentModel, type DocumentModelDeps, type DocumentOtFactory, type DocumentOtHandle, type DocumentSnapshotData, type DocumentViewPort, EMOJI_GROUPS, type Glyph, MIN_FIT_ZOOM, type ParkedDocumentEditor, type PublishedCaret, type RemoteCaret, RemoteCaretBook, SPECIAL_GROUPS, type SaveDocumentSnapshotArgs, addCommentAnchorActions, anchorIdOfPartAnchor, bodyTextOf, commentAnchorPartKey, commentAnchorsOf, commentPartAnchor, configureDocsHost, copyDocument, createDocument, deleteDocument, discardFailedDocument, documentBodyWriteHandler, documentSourceLabel, fitZoomRatio, getDocsHost, getDocument, getLatestDocumentSnapshot, listAccessibleDocuments, listDocumentSnapshots, listTrashedDocuments, moveDocument, movePeerRangesThroughBodyEdit, moveRangesThroughBodyEdit, newCommentAnchorId, planBodyEdit, publishedCaretFromSelection, removeCommentAnchorActions, renameDocument, restoreDocument, sanitizeUniverDocSnapshot, saveDocumentSnapshot, searchSymbols, updateDocumentDescription, validateDocumentBody, validateDocumentDescription, validateDocumentName, writeBodyText };
package/dist/docs.js CHANGED
@@ -959,10 +959,76 @@ var RemoteCaretBook = class {
959
959
  return out;
960
960
  }
961
961
  };
962
+
963
+ // src/docs/comment-anchors.ts
964
+ import { BuildTextUtils, CustomRangeType, JSONX } from "@univerjs/core";
965
+ var COMMENT_ANCHOR_RANGE_TYPE = CustomRangeType.COMMENT;
966
+ var COMMENT_ANCHOR_PART_PREFIX = "anchor:";
967
+ var COMMENT_ANCHOR_LABEL_MAX = 200;
968
+ var ID_ALPHABET = "abcdefghijklmnopqrstuvwxyz0123456789";
969
+ function newCommentAnchorId() {
970
+ const bytes = new Uint8Array(16);
971
+ globalThis.crypto.getRandomValues(bytes);
972
+ let out = "c";
973
+ for (const b of bytes) out += ID_ALPHABET[b % ID_ALPHABET.length];
974
+ return out;
975
+ }
976
+ function commentAnchorPartKey(anchorId) {
977
+ return `${COMMENT_ANCHOR_PART_PREFIX}${anchorId}`;
978
+ }
979
+ function anchorIdOfPartAnchor(anchor) {
980
+ if (!anchor || typeof anchor !== "object") return null;
981
+ const a = anchor;
982
+ if (a.__kind !== "part_anchor" || typeof a.part_key !== "string") return null;
983
+ if (!a.part_key.startsWith(COMMENT_ANCHOR_PART_PREFIX)) return null;
984
+ const id = a.part_key.slice(COMMENT_ANCHOR_PART_PREFIX.length);
985
+ return id.length > 0 ? id : null;
986
+ }
987
+ function commentPartAnchor(anchorId, quote) {
988
+ const label = quote.replace(/\s+/g, " ").trim().slice(0, COMMENT_ANCHOR_LABEL_MAX);
989
+ return { __kind: "part_anchor", part_key: commentAnchorPartKey(anchorId), ...label ? { label } : {} };
990
+ }
991
+ var CONTROL = /[\u0000-\u001f\u007f]/g;
992
+ function commentAnchorsOf(body) {
993
+ const out = /* @__PURE__ */ new Map();
994
+ const b = body ?? {};
995
+ const stream = typeof b.dataStream === "string" ? b.dataStream : "";
996
+ for (const r of b.customRanges ?? []) {
997
+ if (!r || r.rangeType !== COMMENT_ANCHOR_RANGE_TYPE || typeof r.rangeId !== "string") continue;
998
+ const start = r.startIndex;
999
+ const end = r.endIndex + 1;
1000
+ if (!(end > start)) continue;
1001
+ const had = out.get(r.rangeId);
1002
+ const s2 = had ? Math.min(had.start, start) : start;
1003
+ const e2 = had ? Math.max(had.end, end) : end;
1004
+ out.set(r.rangeId, { id: r.rangeId, start: s2, end: e2, text: "" });
1005
+ }
1006
+ for (const span of out.values()) span.text = stream.slice(span.start, span.end).replace(CONTROL, " ");
1007
+ return out;
1008
+ }
1009
+ function addCommentAnchorActions(body, start, end, anchorId) {
1010
+ if (!(end > start) || start < 0) return null;
1011
+ const textX = BuildTextUtils.customRange.add({
1012
+ body,
1013
+ ranges: [{ startOffset: start, endOffset: end, collapsed: false }],
1014
+ rangeId: anchorId,
1015
+ rangeType: COMMENT_ANCHOR_RANGE_TYPE
1016
+ });
1017
+ if (!textX) return null;
1018
+ return JSONX.getInstance().editOp(textX.serialize(), ["body"]);
1019
+ }
1020
+ function removeCommentAnchorActions(documentDataModel, anchorId) {
1021
+ const textX = BuildTextUtils.customRange.delete({ documentDataModel, rangeId: anchorId });
1022
+ if (!textX) return null;
1023
+ return JSONX.getInstance().editOp(textX.serialize(), ["body"]);
1024
+ }
962
1025
  export {
963
1026
  CARET_HEARTBEAT_MS,
964
1027
  CARET_MAX_RANGES,
965
1028
  CARET_STALE_MS,
1029
+ COMMENT_ANCHOR_LABEL_MAX,
1030
+ COMMENT_ANCHOR_PART_PREFIX,
1031
+ COMMENT_ANCHOR_RANGE_TYPE,
966
1032
  DOCUMENT_BODY_MAX_LENGTH,
967
1033
  DOCUMENT_DESCRIPTION_MAX_LENGTH,
968
1034
  DOCUMENT_NAME_MAX_LENGTH,
@@ -972,7 +1038,12 @@ export {
972
1038
  MIN_FIT_ZOOM,
973
1039
  RemoteCaretBook,
974
1040
  SPECIAL_GROUPS,
1041
+ addCommentAnchorActions,
1042
+ anchorIdOfPartAnchor,
975
1043
  bodyTextOf,
1044
+ commentAnchorPartKey,
1045
+ commentAnchorsOf,
1046
+ commentPartAnchor,
976
1047
  configureDocsHost,
977
1048
  copyDocument,
978
1049
  createDocument,
@@ -990,8 +1061,10 @@ export {
990
1061
  moveDocument,
991
1062
  movePeerRangesThroughBodyEdit,
992
1063
  moveRangesThroughBodyEdit,
1064
+ newCommentAnchorId,
993
1065
  planBodyEdit,
994
1066
  publishedCaretFromSelection,
1067
+ removeCommentAnchorActions,
995
1068
  renameDocument,
996
1069
  restoreDocument,
997
1070
  sanitizeUniverDocSnapshot,