@fileverse-dev/ddoc 3.2.5 → 3.2.6-sg-2

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 (31) hide show
  1. package/dist/index.es.js +29603 -27664
  2. package/dist/package/components/inline-comment/comment-card.d.ts +19 -1
  3. package/dist/package/components/inline-comment/comment-drawer-constants.d.ts +1 -0
  4. package/dist/package/components/inline-comment/comment-drawer-desktop.d.ts +35 -0
  5. package/dist/package/components/inline-comment/comment-drawer-mobile.d.ts +43 -0
  6. package/dist/package/components/inline-comment/context/types.d.ts +9 -1
  7. package/dist/package/components/inline-comment/floating-comment/floating-auth-prompt.d.ts +3 -1
  8. package/dist/package/components/inline-comment/floating-comment/suggestion-draft-floating-card.d.ts +17 -0
  9. package/dist/package/components/inline-comment/floating-comment/suggestion-thread-floating-card.d.ts +15 -0
  10. package/dist/package/components/inline-comment/floating-comment/types.d.ts +6 -1
  11. package/dist/package/components/inline-comment/floating-comment-layout-utils.d.ts +4 -1
  12. package/dist/package/components/inline-comment/mobile-inline-comment-sheet.d.ts +15 -0
  13. package/dist/package/components/inline-comment/mobile-suggestion-draft-sheet.d.ts +15 -0
  14. package/dist/package/components/inline-comment/types.d.ts +1 -0
  15. package/dist/package/components/inline-comment/use-comment-drawer-drafts.d.ts +22 -0
  16. package/dist/package/components/inline-comment/use-comment-drawer-filters.d.ts +40 -0
  17. package/dist/package/components/inline-comment/use-comment-drawer-focus.d.ts +17 -0
  18. package/dist/package/components/inline-comment/use-comment-drawer-lifecycle.d.ts +13 -0
  19. package/dist/package/components/inline-comment/use-mobile-comment-navigation.d.ts +20 -0
  20. package/dist/package/components/toc/document-outline-toc-panel.d.ts +1 -1
  21. package/dist/package/extensions/comment/comment-decoration-plugin.d.ts +33 -7
  22. package/dist/package/extensions/comment/comment.d.ts +5 -0
  23. package/dist/package/extensions/suggestion/suggestion-tracking-extension.d.ts +45 -0
  24. package/dist/package/hooks/use-editing-context.d.ts +2 -0
  25. package/dist/package/hooks/use-tab-editor.d.ts +4 -1
  26. package/dist/package/stores/comment-store-provider.d.ts +10 -1
  27. package/dist/package/stores/comment-store.d.ts +85 -0
  28. package/dist/package/types.d.ts +10 -0
  29. package/dist/package/use-ddoc-editor.d.ts +3 -1
  30. package/dist/style.css +1 -1
  31. package/package.json +1 -1
@@ -21,6 +21,7 @@ export interface CommentExternalDeps {
21
21
  onResolveComment?: (commentId: string, meta?: CommentMutationMeta) => void;
22
22
  onUnresolveComment?: (commentId: string, meta?: CommentMutationMeta) => void;
23
23
  onDeleteComment?: (commentId: string, meta?: CommentMutationMeta) => void;
24
+ onDeleteReply?: (commentId: string, replyId: string) => void;
24
25
  onInlineComment?: () => void;
25
26
  onComment?: () => void;
26
27
  setCommentDrawerOpen?: (open: boolean) => void;
@@ -29,7 +30,38 @@ export interface CommentExternalDeps {
29
30
  ensResolutionUrl: string;
30
31
  commentAnchorsRef?: React.MutableRefObject<CommentAnchor[]>;
31
32
  refreshCommentAnchorState?: () => void;
33
+ /**
34
+ * Derived anchor list for in-progress suggestion drafts. Maintained by the
35
+ * store (not the consumer) — draft actions upsert into this ref whenever
36
+ * state.drafts changes. The decoration extension reads this ref alongside
37
+ * commentAnchorsRef to render both layers identically.
38
+ */
39
+ draftAnchorsRef?: React.MutableRefObject<CommentAnchor[]>;
40
+ }
41
+ /**
42
+ * A suggestion draft is the viewer's in-progress proposed edit — kept local
43
+ * until Submit. Drafts live in memory only (lost on refresh). Derived into
44
+ * a CommentAnchor for decoration rendering via deriveDraftAnchor(). Most
45
+ * suggestion types are derived at use time from hadDeletion + insertedText;
46
+ * linkHref marks a link suggestion over the original selected text.
47
+ */
48
+ export interface DraftSuggestion {
49
+ id: string;
50
+ anchorFrom: Y.RelativePosition;
51
+ anchorTo: Y.RelativePosition;
52
+ /** The text that was selected at draft creation (for Delete/Replace strikethrough). */
53
+ originalContent: string;
54
+ /** Accumulated text the viewer has typed. Empty for a pure Delete draft. */
55
+ insertedText: string;
56
+ /** Per-keystroke history for undo — each entry is one typed character. */
57
+ keystrokes: string[];
58
+ /** True when the draft was created via select+delete or select+type. */
59
+ hadDeletion: boolean;
60
+ /** Pasted link href for a link suggestion. */
61
+ linkHref?: string;
32
62
  }
63
+ type SuggestionDeleteDirection = 'backward' | 'forward';
64
+ export declare function isRangeDraft(draft: DraftSuggestion): boolean;
33
65
  type FloatingCardsUpdater = React.SetStateAction<CommentFloatingCard[]>;
34
66
  type InlineCommentDataUpdater = Partial<InlineCommentData> | ((prev: InlineCommentData) => Partial<InlineCommentData> | InlineCommentData);
35
67
  type InlineDraftRecordMap = Record<string, InlineCommentDraft>;
@@ -92,6 +124,8 @@ export interface CommentStoreState {
92
124
  inlineCommentData: InlineCommentData;
93
125
  floatingCards: CommentFloatingCard[];
94
126
  pendingPrehydrationFloatingThreadIds: string[];
127
+ /** In-progress suggestion drafts — keyed by suggestionId. Viewer-local, lost on refresh. */
128
+ drafts: Record<string, DraftSuggestion>;
95
129
  inlineDrafts: InlineDraftRecordMap;
96
130
  activeDraftId: string | null;
97
131
  isDesktopFloatingEnabled: boolean;
@@ -155,6 +189,7 @@ export interface CommentStoreState {
155
189
  cancelFloatingDraft: (draftId: string) => void;
156
190
  submitFloatingDraft: (draftId: string) => void;
157
191
  openFloatingThread: (commentId: string) => void;
192
+ focusSubmittedSuggestionFromEditor: (commentId: string) => boolean;
158
193
  closeFloatingCard: (floatingCardId: string) => void;
159
194
  blurFloatingCard: (floatingCardId: string) => void;
160
195
  focusFloatingCard: (floatingCardId: string) => void;
@@ -177,6 +212,55 @@ export interface CommentStoreState {
177
212
  deleteComment: (commentId: string, options?: {
178
213
  skipExternalCallback?: boolean;
179
214
  }) => void;
215
+ acceptSuggestion: (commentId: string) => void;
216
+ /**
217
+ * Append typed characters to the draft at the current cursor position.
218
+ * Creates a new Add draft if no draft exists at the cursor.
219
+ */
220
+ appendToDraftAtCursor: (text: string) => void;
221
+ /**
222
+ * Create a Delete (or pending Replace) draft from a selection range.
223
+ * Captures originalContent, leaves insertedText empty; type becomes 'replace'
224
+ * as soon as the viewer types.
225
+ */
226
+ startDeleteDraft: (from: number, to: number, collapseTo?: number) => void;
227
+ /**
228
+ * Create a link suggestion from a selected range and pasted href.
229
+ * The document stays unchanged until the owner accepts the suggestion.
230
+ */
231
+ startLinkDraft: (from: number, to: number, href: string) => void;
232
+ /**
233
+ * Convert a collapsed-caret Backspace/Delete into a delete draft when the
234
+ * caret is adjacent to text, or shrink the active draft if the caret is
235
+ * already inside one.
236
+ */
237
+ deleteAtCursorOrUndoActiveDraft: (direction: SuggestionDeleteDirection) => void;
238
+ /**
239
+ * Handle browser deletion paths that resolved to a concrete range even
240
+ * though the user had no explicit selection.
241
+ */
242
+ deleteRangeOrUndoActiveDraft: (from: number, to: number) => void;
243
+ /**
244
+ * Undo the last keystroke in the draft at the current cursor position.
245
+ * When the draft has no keystrokes left, it is discarded.
246
+ * For a pure Delete draft (no keystrokes ever), calling this discards.
247
+ */
248
+ undoLastKeystrokeInActiveDraft: () => void;
249
+ /** Drop a draft entirely — removes the inline overlay and draft card. */
250
+ discardDraft: (suggestionId: string) => void;
251
+ /**
252
+ * Refresh the `originalContent` (and the suggestion-draft card's selectedText)
253
+ * for a Delete/Replace draft whose anchored range still resolves but now
254
+ * covers different text — happens when the owner edits within the anchored
255
+ * range while the viewer's draft is open.
256
+ */
257
+ refreshDraftOriginalContent: (suggestionId: string, currentText: string) => void;
258
+ /**
259
+ * Promote a draft to a submitted suggestion. Pushes the anchor into
260
+ * commentAnchorsRef, calls onNewComment, removes the draft, and swaps the
261
+ * suggestion-draft floating card for a thread card (same floatingCardId).
262
+ */
263
+ submitDraft: (suggestionId: string) => void;
180
264
  deleteReply: (commentId: string, replyId: string) => void;
181
265
  requestEditComment: (commentId: string) => void;
182
266
  requestEditReply: (commentId: string, replyId: string) => void;
@@ -184,6 +268,7 @@ export interface CommentStoreState {
184
268
  editReplyContent: (commentId: string, replyId: string, content: string) => void;
185
269
  handleAddReply: (activeCommentId: string, replyContent: string, replyCallback?: (activeCommentId: string, reply: IComment) => void) => void;
186
270
  focusCommentInEditor: (commentId: string, options?: FocusCommentInEditorOptions) => void;
271
+ focusSuggestionDraftInEditor: (suggestionId: string) => void;
187
272
  onPrevComment: () => void;
188
273
  onNextComment: () => void;
189
274
  getEnsStatus: (walletAddress: string, setEnsStatus: React.Dispatch<React.SetStateAction<EnsStatus>>) => void;
@@ -20,6 +20,7 @@ export type InlineCommentData = {
20
20
  handleClick: boolean;
21
21
  };
22
22
  export type CommentMutationType = 'create' | 'edit' | 'resolve' | 'unresolve' | 'delete';
23
+ export type SuggestionType = 'add' | 'replace' | 'delete' | 'link';
23
24
  export interface CommentMutationMeta {
24
25
  type: CommentMutationType;
25
26
  updateChunk?: string;
@@ -27,6 +28,9 @@ export interface CommentMutationMeta {
27
28
  anchorTo?: string;
28
29
  selectedContent?: string;
29
30
  content?: string;
31
+ suggestionType?: SuggestionType;
32
+ originalContent?: string;
33
+ suggestedContent?: string;
30
34
  }
31
35
  export interface SerializedCommentAnchor {
32
36
  id: string;
@@ -34,6 +38,10 @@ export interface SerializedCommentAnchor {
34
38
  anchorTo: string;
35
39
  resolved: boolean;
36
40
  deleted: boolean;
41
+ isSuggestion?: boolean;
42
+ suggestionType?: SuggestionType;
43
+ originalContent?: string;
44
+ suggestedContent?: string;
37
45
  }
38
46
  export interface CommentAccountProps {
39
47
  isConnected?: boolean;
@@ -127,6 +135,7 @@ export interface DdocProps extends CommentAccountProps {
127
135
  onResolveComment?: (activeCommentId: string, meta?: CommentMutationMeta) => void;
128
136
  onUnresolveComment?: (activeCommentId: string, meta?: CommentMutationMeta) => void;
129
137
  onDeleteComment?: (activeCommentId: string, meta?: CommentMutationMeta) => void;
138
+ onDeleteReply?: (activeCommentId: string, replyId: string) => void;
130
139
  showTOC?: boolean;
131
140
  setShowTOC?: React.Dispatch<SetStateAction<boolean>>;
132
141
  extensions?: Record<string, Extension | any>;
@@ -144,6 +153,7 @@ export interface DdocProps extends CommentAccountProps {
144
153
  editorCanvasClassNames?: string;
145
154
  isCommentSectionOpen?: boolean;
146
155
  isPreviewMode: boolean;
156
+ viewerMode?: 'suggest' | 'view-only';
147
157
  ensResolutionUrl?: string;
148
158
  ipfsImageUploadFn?: (file: File) => Promise<IpfsImageUploadResponse>;
149
159
  enableIndexeddbSync?: boolean;
@@ -1,7 +1,7 @@
1
1
  import { DdocProps } from './types';
2
2
  import { Editor } from '@tiptap/react';
3
3
 
4
- export declare const useDdocEditor: ({ isPreviewMode, initialContent, versionHistoryState, collaboration, onChange, onCollaboratorChange, onCommentInteraction, onError, setCharacterCount, setWordCount, setPageCount, ipfsImageUploadFn, ddocId, enableIndexeddbSync, unFocused, isFocusMode, theme, zoomLevel, onInvalidContentError, ignoreCorruptedData, isPresentationMode, metadataProxyUrl, extensions: externalExtensions, onCopyHeadingLink, ipfsImageFetchFn, fetchV1ImageFn, isConnected, activeModel, maxTokens, isAIAgentEnabled, onIndexedDbError, disableInlineComment, initialCommentAnchors, ...rest }: Partial<DdocProps> & {
4
+ export declare const useDdocEditor: ({ isPreviewMode, viewerMode, initialContent, versionHistoryState, collaboration, onChange, onCollaboratorChange, onCommentInteraction, onError, setCharacterCount, setWordCount, setPageCount, ipfsImageUploadFn, ddocId, enableIndexeddbSync, unFocused, isFocusMode, theme, zoomLevel, onInvalidContentError, ignoreCorruptedData, isPresentationMode, metadataProxyUrl, extensions: externalExtensions, onCopyHeadingLink, ipfsImageFetchFn, fetchV1ImageFn, isConnected, activeModel, maxTokens, isAIAgentEnabled, onIndexedDbError, disableInlineComment, initialCommentAnchors, ...rest }: Partial<DdocProps> & {
5
5
  isFocusMode?: boolean;
6
6
  }) => {
7
7
  ydoc: import('yjs').Doc;
@@ -41,4 +41,6 @@ export declare const useDdocEditor: ({ isPreviewMode, initialContent, versionHis
41
41
  setActiveCommentId: import('react').Dispatch<import('react').SetStateAction<string | null>>;
42
42
  focusCommentWithActiveId: (id: string) => void;
43
43
  commentAnchorsRef: import('react').MutableRefObject<import('./extensions/comment/comment-decoration-plugin').CommentAnchor[]>;
44
+ draftAnchorsRef: import('react').MutableRefObject<import('./extensions/comment/comment-decoration-plugin').CommentAnchor[]>;
45
+ storeApiRef: import('react').MutableRefObject<import('zustand').StoreApi<import('./stores/comment-store').CommentStoreState> | null>;
44
46
  };