@fileverse-dev/ddoc 3.2.9 → 3.3.0-viem-1

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 (34) hide show
  1. package/dist/index.es.js +45022 -34621
  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/comment-floating-layout.d.ts +2 -0
  7. package/dist/package/components/inline-comment/comment-reply-input.d.ts +1 -1
  8. package/dist/package/components/inline-comment/context/types.d.ts +9 -1
  9. package/dist/package/components/inline-comment/floating-comment/suggestion-draft-floating-card.d.ts +17 -0
  10. package/dist/package/components/inline-comment/floating-comment/suggestion-thread-floating-card.d.ts +15 -0
  11. package/dist/package/components/inline-comment/floating-comment/types.d.ts +6 -1
  12. package/dist/package/components/inline-comment/floating-comment-layout-utils.d.ts +9 -2
  13. package/dist/package/components/inline-comment/mobile-inline-comment-sheet.d.ts +15 -0
  14. package/dist/package/components/inline-comment/mobile-suggestion-draft-sheet.d.ts +15 -0
  15. package/dist/package/components/inline-comment/suggestion-diff-summary.d.ts +11 -0
  16. package/dist/package/components/inline-comment/types.d.ts +1 -0
  17. package/dist/package/components/inline-comment/use-comment-drawer-drafts.d.ts +22 -0
  18. package/dist/package/components/inline-comment/use-comment-drawer-filters.d.ts +40 -0
  19. package/dist/package/components/inline-comment/use-comment-drawer-focus.d.ts +17 -0
  20. package/dist/package/components/inline-comment/use-comment-drawer-lifecycle.d.ts +13 -0
  21. package/dist/package/components/inline-comment/use-is-selected-content-deleted.d.ts +1 -1
  22. package/dist/package/components/inline-comment/use-mobile-comment-navigation.d.ts +20 -0
  23. package/dist/package/extensions/comment/comment-decoration-plugin.d.ts +34 -7
  24. package/dist/package/extensions/comment/comment.d.ts +5 -0
  25. package/dist/package/extensions/suggestion/suggestion-tracking-extension.d.ts +45 -0
  26. package/dist/package/hooks/use-editing-context.d.ts +2 -0
  27. package/dist/package/hooks/use-tab-editor.d.ts +4 -1
  28. package/dist/package/stores/comment-store-provider.d.ts +1 -1
  29. package/dist/package/stores/comment-store.d.ts +84 -0
  30. package/dist/package/types.d.ts +9 -0
  31. package/dist/package/use-ddoc-editor.d.ts +3 -1
  32. package/dist/style.css +1 -1
  33. package/package.json +2 -2
  34. package/dist/package/utils/getAddressName.d.ts +0 -7
@@ -30,7 +30,38 @@ export interface CommentExternalDeps {
30
30
  ensResolutionUrl: string;
31
31
  commentAnchorsRef?: React.MutableRefObject<CommentAnchor[]>;
32
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;
33
62
  }
63
+ type SuggestionDeleteDirection = 'backward' | 'forward';
64
+ export declare function isRangeDraft(draft: DraftSuggestion): boolean;
34
65
  type FloatingCardsUpdater = React.SetStateAction<CommentFloatingCard[]>;
35
66
  type InlineCommentDataUpdater = Partial<InlineCommentData> | ((prev: InlineCommentData) => Partial<InlineCommentData> | InlineCommentData);
36
67
  type InlineDraftRecordMap = Record<string, InlineCommentDraft>;
@@ -93,6 +124,8 @@ export interface CommentStoreState {
93
124
  inlineCommentData: InlineCommentData;
94
125
  floatingCards: CommentFloatingCard[];
95
126
  pendingPrehydrationFloatingThreadIds: string[];
127
+ /** In-progress suggestion drafts — keyed by suggestionId. Viewer-local, lost on refresh. */
128
+ drafts: Record<string, DraftSuggestion>;
96
129
  inlineDrafts: InlineDraftRecordMap;
97
130
  activeDraftId: string | null;
98
131
  isDesktopFloatingEnabled: boolean;
@@ -156,6 +189,7 @@ export interface CommentStoreState {
156
189
  cancelFloatingDraft: (draftId: string) => void;
157
190
  submitFloatingDraft: (draftId: string) => void;
158
191
  openFloatingThread: (commentId: string) => void;
192
+ focusSubmittedSuggestionFromEditor: (commentId: string) => boolean;
159
193
  closeFloatingCard: (floatingCardId: string) => void;
160
194
  blurFloatingCard: (floatingCardId: string) => void;
161
195
  focusFloatingCard: (floatingCardId: string) => void;
@@ -178,6 +212,55 @@ export interface CommentStoreState {
178
212
  deleteComment: (commentId: string, options?: {
179
213
  skipExternalCallback?: boolean;
180
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;
181
264
  deleteReply: (commentId: string, replyId: string) => void;
182
265
  requestEditComment: (commentId: string) => void;
183
266
  requestEditReply: (commentId: string, replyId: string) => void;
@@ -185,6 +268,7 @@ export interface CommentStoreState {
185
268
  editReplyContent: (commentId: string, replyId: string, content: string) => void;
186
269
  handleAddReply: (activeCommentId: string, replyContent: string, replyCallback?: (activeCommentId: string, reply: IComment) => void) => void;
187
270
  focusCommentInEditor: (commentId: string, options?: FocusCommentInEditorOptions) => void;
271
+ focusSuggestionDraftInEditor: (suggestionId: string) => void;
188
272
  onPrevComment: () => void;
189
273
  onNextComment: () => void;
190
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;
@@ -145,6 +153,7 @@ export interface DdocProps extends CommentAccountProps {
145
153
  editorCanvasClassNames?: string;
146
154
  isCommentSectionOpen?: boolean;
147
155
  isPreviewMode: boolean;
156
+ viewerMode?: 'suggest' | 'view-only';
148
157
  ensResolutionUrl?: string;
149
158
  ipfsImageUploadFn?: (file: File) => Promise<IpfsImageUploadResponse>;
150
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
  };