@fileverse-dev/ddoc 3.2.1 → 3.2.2-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.
- package/dist/index.es.js +28391 -27417
- package/dist/package/components/inline-comment/context/types.d.ts +7 -1
- package/dist/package/components/inline-comment/floating-comment/suggestion-draft-floating-card.d.ts +17 -0
- package/dist/package/components/inline-comment/floating-comment/suggestion-thread-floating-card.d.ts +15 -0
- package/dist/package/components/inline-comment/floating-comment/types.d.ts +6 -1
- package/dist/package/components/inline-comment/floating-comment-layout-utils.d.ts +4 -1
- package/dist/package/extensions/comment/comment-decoration-plugin.d.ts +25 -0
- package/dist/package/extensions/comment/comment.d.ts +5 -0
- package/dist/package/extensions/suggestion/suggestion-tracking-extension.d.ts +30 -0
- package/dist/package/hooks/use-editing-context.d.ts +2 -0
- package/dist/package/hooks/use-tab-editor.d.ts +4 -1
- package/dist/package/stores/comment-store-provider.d.ts +9 -1
- package/dist/package/stores/comment-store.d.ts +62 -0
- package/dist/package/types.d.ts +9 -0
- package/dist/package/use-ddoc-editor.d.ts +3 -1
- package/dist/style.css +1 -1
- package/package.json +2 -2
|
@@ -26,7 +26,13 @@ export interface CommentFloatingThreadCard extends CommentFloatingBaseCard {
|
|
|
26
26
|
type: 'thread';
|
|
27
27
|
commentId: string;
|
|
28
28
|
}
|
|
29
|
-
export
|
|
29
|
+
export interface SuggestionFloatingDraftCard extends CommentFloatingBaseCard {
|
|
30
|
+
type: 'suggestion-draft';
|
|
31
|
+
suggestionId: string;
|
|
32
|
+
/** Accumulated inserted text from the live suggestion context. */
|
|
33
|
+
insertedText: string;
|
|
34
|
+
}
|
|
35
|
+
export type CommentFloatingCard = CommentFloatingDraftCard | CommentFloatingThreadCard | SuggestionFloatingDraftCard;
|
|
30
36
|
export interface InlineCommentData {
|
|
31
37
|
highlightedTextContent?: string;
|
|
32
38
|
inlineCommentText: string;
|
package/dist/package/components/inline-comment/floating-comment/suggestion-draft-floating-card.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SuggestionDraftFloatingCardProps } from './types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* SuggestionDraftFloatingCard
|
|
5
|
+
*
|
|
6
|
+
* Shown while a viewer is composing a suggestion (in suggestion mode).
|
|
7
|
+
* Uses the same one-line diff format as the submitted thread card
|
|
8
|
+
* (Add: "X" / Delete: "X" / Replace: "X" with "Y") plus a Submit action
|
|
9
|
+
* and a Discard (X) button.
|
|
10
|
+
*
|
|
11
|
+
* When the viewer hasn't joined yet (no username / wallet), the card
|
|
12
|
+
* renders FloatingAuthPrompt inside — same pattern as the inline-comment
|
|
13
|
+
* draft card. The first keystroke that triggered this card is preserved
|
|
14
|
+
* as the draft's first character; once the viewer joins, the card
|
|
15
|
+
* transitions to the normal diff/Submit UI without losing what they typed.
|
|
16
|
+
*/
|
|
17
|
+
export declare const SuggestionDraftFloatingCard: ({ card, isHidden, registerCardNode, }: SuggestionDraftFloatingCardProps) => import("react/jsx-runtime").JSX.Element;
|
package/dist/package/components/inline-comment/floating-comment/suggestion-thread-floating-card.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ThreadFloatingCardProps } from './types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* SuggestionThreadFloatingCard
|
|
5
|
+
*
|
|
6
|
+
* Shown in place of the generic ThreadFloatingCard for submitted suggestions
|
|
7
|
+
* (comments with `isSuggestion: true`). Renders the Figma-specified layout:
|
|
8
|
+
* author + timestamp header, Accept/Reject (owner) or Withdraw (author)
|
|
9
|
+
* actions, a one-line diff summary (Add/Delete/Replace), and a reply input.
|
|
10
|
+
*
|
|
11
|
+
* Renders from the underlying IComment — the same source ThreadFloatingCard
|
|
12
|
+
* uses — so once a draft is submitted, nothing else in the pipeline needs
|
|
13
|
+
* to change to show the suggestion here.
|
|
14
|
+
*/
|
|
15
|
+
export declare const SuggestionThreadFloatingCard: ({ thread, comment, isHidden, registerCardNode, }: ThreadFloatingCardProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Editor } from '@tiptap/react';
|
|
2
2
|
import { ReactNode, RefObject } from 'react';
|
|
3
3
|
import { IComment } from '../../../extensions/comment';
|
|
4
|
-
import { CommentFloatingDraftCard, CommentFloatingThreadCard } from '../context/types';
|
|
4
|
+
import { CommentFloatingDraftCard, CommentFloatingThreadCard, SuggestionFloatingDraftCard } from '../context/types';
|
|
5
5
|
|
|
6
6
|
export type RegisterCardNode = (floatingCardId: string, node: HTMLDivElement | null) => void;
|
|
7
7
|
export interface CommentFloatingContainerProps {
|
|
@@ -32,3 +32,8 @@ export interface ThreadFloatingCardProps {
|
|
|
32
32
|
registerCardNode: RegisterCardNode;
|
|
33
33
|
isCollaborationEnabled?: boolean;
|
|
34
34
|
}
|
|
35
|
+
export interface SuggestionDraftFloatingCardProps {
|
|
36
|
+
card: SuggestionFloatingDraftCard;
|
|
37
|
+
isHidden: boolean;
|
|
38
|
+
registerCardNode: RegisterCardNode;
|
|
39
|
+
}
|
|
@@ -2,7 +2,7 @@ import { Editor } from '@tiptap/react';
|
|
|
2
2
|
import { FloatingLayoutInvalidationFlag, FloatingCardLayoutInput } from './comment-floating-layout';
|
|
3
3
|
import { CommentFloatingCard } from './context/types';
|
|
4
4
|
|
|
5
|
-
export type AnchorType = 'draft' | 'thread';
|
|
5
|
+
export type AnchorType = 'draft' | 'thread' | 'suggestion-draft';
|
|
6
6
|
export interface CachedAnchorRect {
|
|
7
7
|
top: number;
|
|
8
8
|
height: number;
|
|
@@ -40,6 +40,9 @@ export declare const FLOATING_VIEWPORT_BUFFER_MULTIPLIER = 1;
|
|
|
40
40
|
export declare const getAnchorIdentity: (floatingCard: CommentFloatingCard) => {
|
|
41
41
|
anchorId: string;
|
|
42
42
|
anchorType: "draft";
|
|
43
|
+
} | {
|
|
44
|
+
anchorId: string;
|
|
45
|
+
anchorType: "suggestion-draft";
|
|
43
46
|
} | {
|
|
44
47
|
anchorId: string;
|
|
45
48
|
anchorType: "thread";
|
|
@@ -2,6 +2,7 @@ import { Extension, Editor } from '@tiptap/core';
|
|
|
2
2
|
import { EditorState, PluginKey } from '@tiptap/pm/state';
|
|
3
3
|
import { Transform } from '@tiptap/pm/transform';
|
|
4
4
|
import { DecorationSet } from '@tiptap/pm/view';
|
|
5
|
+
import { SuggestionType } from '../../types';
|
|
5
6
|
|
|
6
7
|
import * as Y from 'yjs';
|
|
7
8
|
export interface CommentAnchor {
|
|
@@ -10,6 +11,10 @@ export interface CommentAnchor {
|
|
|
10
11
|
anchorTo: Y.RelativePosition;
|
|
11
12
|
resolved: boolean;
|
|
12
13
|
deleted: boolean;
|
|
14
|
+
isSuggestion?: boolean;
|
|
15
|
+
suggestionType?: SuggestionType;
|
|
16
|
+
originalContent?: string;
|
|
17
|
+
suggestedContent?: string;
|
|
13
18
|
}
|
|
14
19
|
interface CommentDecorationPluginState {
|
|
15
20
|
decorations: DecorationSet;
|
|
@@ -34,6 +39,13 @@ export type CommentAnchorTransactionChange = {
|
|
|
34
39
|
} & CommentAnchorRange & CommentAnchorRelativeRange);
|
|
35
40
|
export declare const commentDecorationPluginKey: PluginKey<CommentDecorationPluginState>;
|
|
36
41
|
export declare function resolveCommentAnchorRangeInState(anchor: Pick<CommentAnchor, 'anchorFrom' | 'anchorTo'>, state: EditorState): CommentAnchorRange | null;
|
|
42
|
+
/**
|
|
43
|
+
* Resolve anchorFrom to a single absolute position.
|
|
44
|
+
* Used for 'add' suggestion anchors where anchorFrom === anchorTo (cursor,
|
|
45
|
+
* no initial selection) — resolveCommentAnchorRangeInState rejects from >= to,
|
|
46
|
+
* so we need a separate path that allows a point position.
|
|
47
|
+
*/
|
|
48
|
+
export declare function resolveCommentAnchorPointInState(anchor: Pick<CommentAnchor, 'anchorFrom'>, state: EditorState): number | null;
|
|
37
49
|
export declare function resolveCommentAnchorRangeForAnalysis(anchor: Pick<CommentAnchor, 'id' | 'anchorFrom' | 'anchorTo'>, state: EditorState): CommentAnchorRange | null;
|
|
38
50
|
/**
|
|
39
51
|
* Analyze transaction changes to classify each active anchor's mutation status.
|
|
@@ -63,8 +75,21 @@ export declare const CommentDecorationExtension: Extension<CommentDecorationOpti
|
|
|
63
75
|
* These are consumed by the draft-creation flow and transaction-analysis layer.
|
|
64
76
|
*/
|
|
65
77
|
export declare function createCommentAnchorFromEditor(editor: Editor, from: number, to: number): CommentAnchorRelativeRange | null;
|
|
78
|
+
/**
|
|
79
|
+
* Create a point anchor (anchorFrom === anchorTo) at a single doc position.
|
|
80
|
+
* Used by the suggestion-mode draft flow when the viewer places a cursor
|
|
81
|
+
* without selecting text — createCommentAnchorFromEditor rejects from >= to
|
|
82
|
+
* since an empty range is invalid for regular comments.
|
|
83
|
+
*/
|
|
84
|
+
export declare function createCommentAnchorPointFromEditor(editor: Editor, pos: number): CommentAnchorRelativeRange | null;
|
|
66
85
|
export declare function createCommentAnchorFromSelection(editor: Editor): CommentAnchorRelativeRange | null;
|
|
67
86
|
export declare function triggerDecorationRebuild(editor: Editor): void;
|
|
68
87
|
export declare function getCommentAtPosition(editor: Editor, pos: number, getAnchors: () => CommentAnchor[]): CommentAnchor | null;
|
|
69
88
|
export declare function getCommentAnchorRange(editor: Editor, commentId: string, getAnchors: () => CommentAnchor[]): CommentAnchorRange | null;
|
|
89
|
+
/**
|
|
90
|
+
* Apply the accepted suggestion's change to the document.
|
|
91
|
+
* Called by the store's acceptSuggestion action before resolving on-chain.
|
|
92
|
+
* Returns false if the anchor can't be resolved or the suggestion type is unknown.
|
|
93
|
+
*/
|
|
94
|
+
export declare function applyAcceptedSuggestion(editor: Editor, anchor: CommentAnchor): boolean;
|
|
70
95
|
export {};
|
|
@@ -2,6 +2,7 @@ import { Mark, Range } from '@tiptap/core';
|
|
|
2
2
|
import { Mark as PMMark } from '@tiptap/pm/model';
|
|
3
3
|
import { PluginKey, EditorState } from '@tiptap/pm/state';
|
|
4
4
|
import { DecorationSet } from '@tiptap/pm/view';
|
|
5
|
+
import { SuggestionType } from '../../types';
|
|
5
6
|
|
|
6
7
|
declare module '@tiptap/core' {
|
|
7
8
|
interface Commands<ReturnType> {
|
|
@@ -93,6 +94,10 @@ export interface IComment {
|
|
|
93
94
|
deleted?: boolean;
|
|
94
95
|
commentIndex?: number;
|
|
95
96
|
version?: string;
|
|
97
|
+
isSuggestion?: boolean;
|
|
98
|
+
suggestionType?: SuggestionType;
|
|
99
|
+
originalContent?: string;
|
|
100
|
+
suggestedContent?: string;
|
|
96
101
|
}
|
|
97
102
|
export declare const CommentExtension: Mark<CommentOptions, CommentStorage>;
|
|
98
103
|
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Extension } from '@tiptap/core';
|
|
2
|
+
import { PluginKey } from '@tiptap/pm/state';
|
|
3
|
+
import { SuggestionType } from '../../types';
|
|
4
|
+
import { CommentAnchor } from '../comment/comment-decoration-plugin';
|
|
5
|
+
|
|
6
|
+
import * as Y from 'yjs';
|
|
7
|
+
export interface SuggestionReadyData {
|
|
8
|
+
suggestionId: string;
|
|
9
|
+
anchorFrom: Y.RelativePosition;
|
|
10
|
+
anchorTo: Y.RelativePosition;
|
|
11
|
+
suggestionType: SuggestionType;
|
|
12
|
+
originalContent: string;
|
|
13
|
+
suggestedContent: string;
|
|
14
|
+
}
|
|
15
|
+
export interface SuggestionTrackingOptions {
|
|
16
|
+
/** Returns true when the editor is in suggestion mode. */
|
|
17
|
+
getIsSuggestionMode: () => boolean;
|
|
18
|
+
/** Viewer types text with a collapsed cursor (Add gesture). */
|
|
19
|
+
onTextInput: (text: string) => void;
|
|
20
|
+
/** Viewer types text over a non-empty selection (Replace gesture). */
|
|
21
|
+
onReplaceTyping: (from: number, to: number, text: string) => void;
|
|
22
|
+
/** Viewer presses Backspace/Delete with a non-empty selection. */
|
|
23
|
+
onDeleteSelection: (from: number, to: number) => void;
|
|
24
|
+
/** Viewer presses Cmd+Z (or Ctrl+Z). Shrinks the active draft by one keystroke. */
|
|
25
|
+
onUndo: () => void;
|
|
26
|
+
onLiveSuggestion?: ((anchor: CommentAnchor) => void) | null;
|
|
27
|
+
onSuggestionReady?: ((data: SuggestionReadyData) => void) | null;
|
|
28
|
+
}
|
|
29
|
+
export declare const suggestionTrackingPluginKey: PluginKey<null>;
|
|
30
|
+
export declare const SuggestionTrackingExtension: Extension<SuggestionTrackingOptions, any>;
|
|
@@ -4,6 +4,7 @@ type EditingContextType = {
|
|
|
4
4
|
isPreviewMode: boolean;
|
|
5
5
|
isPresentationMode?: boolean;
|
|
6
6
|
isCollaboratorsDoc?: boolean;
|
|
7
|
+
isSuggestionMode?: boolean;
|
|
7
8
|
};
|
|
8
9
|
export declare const useEditingContext: () => EditingContextType;
|
|
9
10
|
type EditingProviderProps = {
|
|
@@ -12,6 +13,7 @@ type EditingProviderProps = {
|
|
|
12
13
|
isPresentationMode?: boolean;
|
|
13
14
|
isCollaboratorsDoc?: boolean;
|
|
14
15
|
isPreviewEditor?: boolean;
|
|
16
|
+
isSuggestionMode?: boolean;
|
|
15
17
|
};
|
|
16
18
|
export declare const EditingProvider: React.FC<EditingProviderProps>;
|
|
17
19
|
export {};
|
|
@@ -12,6 +12,7 @@ interface UseTabEditorArgs {
|
|
|
12
12
|
hasTabState?: boolean;
|
|
13
13
|
versionId?: string;
|
|
14
14
|
isPreviewMode?: boolean;
|
|
15
|
+
viewerMode?: DdocProps['viewerMode'];
|
|
15
16
|
initialContent: DdocProps['initialContent'];
|
|
16
17
|
collaboration?: CollaborationProps;
|
|
17
18
|
isReady?: boolean;
|
|
@@ -51,7 +52,7 @@ interface UseTabEditorArgs {
|
|
|
51
52
|
editorRef?: MutableRefObject<Editor | null>;
|
|
52
53
|
initialCommentAnchors?: SerializedCommentAnchor[];
|
|
53
54
|
}
|
|
54
|
-
export declare const useTabEditor: ({ ydoc, isVersionMode, hasTabState, versionId, isPreviewMode, initialContent, collaboration, isReady, isSyncing, awareness, disableInlineComment, isFocusMode, onCommentInteraction, onError, ipfsImageUploadFn, metadataProxyUrl, onCopyHeadingLink, ipfsImageFetchFn, fetchV1ImageFn, isConnected, activeModel, maxTokens, isAIAgentEnabled, setCharacterCount, setWordCount, setPageCount, setIsContentLoading, setIsCollabContentLoading, unFocused, zoomLevel, isPresentationMode, onInvalidContentError, ignoreCorruptedData, onCollaboratorChange, onConnect, hasCollabContentInitialised, initialiseYjsIndexedDbProvider, externalExtensions, isContentLoading, activeTabId, theme, editorRef, initialCommentAnchors, }: UseTabEditorArgs) => {
|
|
55
|
+
export declare const useTabEditor: ({ ydoc, isVersionMode, hasTabState, versionId, isPreviewMode, viewerMode, initialContent, collaboration, isReady, isSyncing, awareness, disableInlineComment, isFocusMode, onCommentInteraction, onError, ipfsImageUploadFn, metadataProxyUrl, onCopyHeadingLink, ipfsImageFetchFn, fetchV1ImageFn, isConnected, activeModel, maxTokens, isAIAgentEnabled, setCharacterCount, setWordCount, setPageCount, setIsContentLoading, setIsCollabContentLoading, unFocused, zoomLevel, isPresentationMode, onInvalidContentError, ignoreCorruptedData, onCollaboratorChange, onConnect, hasCollabContentInitialised, initialiseYjsIndexedDbProvider, externalExtensions, isContentLoading, activeTabId, theme, editorRef, initialCommentAnchors, }: UseTabEditorArgs) => {
|
|
55
56
|
editor: Editor | null;
|
|
56
57
|
ref: import('react').RefObject<HTMLDivElement>;
|
|
57
58
|
slides: string[];
|
|
@@ -63,5 +64,7 @@ export declare const useTabEditor: ({ ydoc, isVersionMode, hasTabState, versionI
|
|
|
63
64
|
focusCommentWithActiveId: (id: string) => void;
|
|
64
65
|
isContentLoading: boolean | undefined;
|
|
65
66
|
commentAnchorsRef: MutableRefObject<CommentAnchor[]>;
|
|
67
|
+
draftAnchorsRef: MutableRefObject<CommentAnchor[]>;
|
|
68
|
+
storeApiRef: MutableRefObject<import('zustand').StoreApi<import('../stores/comment-store').CommentStoreState> | null>;
|
|
66
69
|
};
|
|
67
70
|
export {};
|
|
@@ -3,6 +3,7 @@ import { Editor } from '@tiptap/core';
|
|
|
3
3
|
import { IComment } from '../extensions/comment';
|
|
4
4
|
import { CommentAnchor } from '../extensions/comment/comment-decoration-plugin';
|
|
5
5
|
import { CommentMutationMeta, SerializedCommentAnchor } from '../types';
|
|
6
|
+
import { createCommentStore } from './comment-store';
|
|
6
7
|
|
|
7
8
|
import * as Y from 'yjs';
|
|
8
9
|
export interface CommentStoreProviderProps {
|
|
@@ -27,6 +28,13 @@ export interface CommentStoreProviderProps {
|
|
|
27
28
|
connectViaUsername?: (username: string) => Promise<void>;
|
|
28
29
|
ensResolutionUrl: string;
|
|
29
30
|
commentAnchorsRef?: React.MutableRefObject<CommentAnchor[]>;
|
|
31
|
+
draftAnchorsRef?: React.MutableRefObject<CommentAnchor[]>;
|
|
32
|
+
/**
|
|
33
|
+
* Ref populated by the provider with the Zustand store instance.
|
|
34
|
+
* SuggestionTrackingExtension reads this inside event handlers to route
|
|
35
|
+
* keystrokes into draft actions without rebuilding the editor.
|
|
36
|
+
*/
|
|
37
|
+
storeApiRef?: React.MutableRefObject<ReturnType<typeof createCommentStore> | null>;
|
|
30
38
|
initialCommentAnchors?: SerializedCommentAnchor[];
|
|
31
39
|
initialComments: IComment[];
|
|
32
40
|
username: string | null;
|
|
@@ -37,7 +45,7 @@ export interface CommentStoreProviderProps {
|
|
|
37
45
|
isDDocOwner?: boolean;
|
|
38
46
|
setUsername?: React.Dispatch<React.SetStateAction<string>>;
|
|
39
47
|
}
|
|
40
|
-
export declare const CommentStoreProvider: ({ children, editor, ydoc, isFocusMode, setActiveCommentId, focusCommentWithActiveId, setInitialComments, onNewComment, onEditComment, onEditReply, onCommentReply, onResolveComment, onUnresolveComment, onDeleteComment, onInlineComment, onComment, setCommentDrawerOpen, connectViaWallet, connectViaUsername, ensResolutionUrl, commentAnchorsRef, initialCommentAnchors, setUsername: setUsernameProp, initialComments, username, activeCommentId, activeTabId, isConnected, isLoading, isDDocOwner, }: CommentStoreProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
48
|
+
export declare const CommentStoreProvider: ({ children, editor, ydoc, isFocusMode, setActiveCommentId, focusCommentWithActiveId, setInitialComments, onNewComment, onEditComment, onEditReply, onCommentReply, onResolveComment, onUnresolveComment, onDeleteComment, onInlineComment, onComment, setCommentDrawerOpen, connectViaWallet, connectViaUsername, ensResolutionUrl, commentAnchorsRef, draftAnchorsRef, storeApiRef, initialCommentAnchors, setUsername: setUsernameProp, initialComments, username, activeCommentId, activeTabId, isConnected, isLoading, isDDocOwner, }: CommentStoreProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
41
49
|
interface CommentRefsContextType {
|
|
42
50
|
commentsSectionRef: React.RefObject<HTMLDivElement>;
|
|
43
51
|
replySectionRef: React.RefObject<HTMLDivElement>;
|
|
@@ -29,6 +29,33 @@ export interface CommentExternalDeps {
|
|
|
29
29
|
ensResolutionUrl: string;
|
|
30
30
|
commentAnchorsRef?: React.MutableRefObject<CommentAnchor[]>;
|
|
31
31
|
refreshCommentAnchorState?: () => void;
|
|
32
|
+
/**
|
|
33
|
+
* Derived anchor list for in-progress suggestion drafts. Maintained by the
|
|
34
|
+
* store (not the consumer) — draft actions upsert into this ref whenever
|
|
35
|
+
* state.drafts changes. The decoration extension reads this ref alongside
|
|
36
|
+
* commentAnchorsRef to render both layers identically.
|
|
37
|
+
*/
|
|
38
|
+
draftAnchorsRef?: React.MutableRefObject<CommentAnchor[]>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* A suggestion draft is the viewer's in-progress proposed edit — kept local
|
|
42
|
+
* until Submit. Drafts live in memory only (lost on refresh). Derived into
|
|
43
|
+
* a CommentAnchor for decoration rendering via deriveDraftAnchor(). The
|
|
44
|
+
* suggestion type ('add' | 'delete' | 'replace') is not stored; it is derived
|
|
45
|
+
* at use time from hadDeletion + insertedText.
|
|
46
|
+
*/
|
|
47
|
+
export interface DraftSuggestion {
|
|
48
|
+
id: string;
|
|
49
|
+
anchorFrom: Y.RelativePosition;
|
|
50
|
+
anchorTo: Y.RelativePosition;
|
|
51
|
+
/** The text that was selected at draft creation (for Delete/Replace strikethrough). */
|
|
52
|
+
originalContent: string;
|
|
53
|
+
/** Accumulated text the viewer has typed. Empty for a pure Delete draft. */
|
|
54
|
+
insertedText: string;
|
|
55
|
+
/** Per-keystroke history for undo — each entry is one typed character. */
|
|
56
|
+
keystrokes: string[];
|
|
57
|
+
/** True when the draft was created via select+delete or select+type. */
|
|
58
|
+
hadDeletion: boolean;
|
|
32
59
|
}
|
|
33
60
|
type FloatingCardsUpdater = React.SetStateAction<CommentFloatingCard[]>;
|
|
34
61
|
type InlineCommentDataUpdater = Partial<InlineCommentData> | ((prev: InlineCommentData) => Partial<InlineCommentData> | InlineCommentData);
|
|
@@ -92,6 +119,8 @@ export interface CommentStoreState {
|
|
|
92
119
|
inlineCommentData: InlineCommentData;
|
|
93
120
|
floatingCards: CommentFloatingCard[];
|
|
94
121
|
pendingPrehydrationFloatingThreadIds: string[];
|
|
122
|
+
/** In-progress suggestion drafts — keyed by suggestionId. Viewer-local, lost on refresh. */
|
|
123
|
+
drafts: Record<string, DraftSuggestion>;
|
|
95
124
|
inlineDrafts: InlineDraftRecordMap;
|
|
96
125
|
activeDraftId: string | null;
|
|
97
126
|
isDesktopFloatingEnabled: boolean;
|
|
@@ -177,6 +206,39 @@ export interface CommentStoreState {
|
|
|
177
206
|
deleteComment: (commentId: string, options?: {
|
|
178
207
|
skipExternalCallback?: boolean;
|
|
179
208
|
}) => void;
|
|
209
|
+
acceptSuggestion: (commentId: string) => void;
|
|
210
|
+
/**
|
|
211
|
+
* Append typed characters to the draft at the current cursor position.
|
|
212
|
+
* Creates a new Add draft if no draft exists at the cursor.
|
|
213
|
+
*/
|
|
214
|
+
appendToDraftAtCursor: (text: string) => void;
|
|
215
|
+
/**
|
|
216
|
+
* Create a Delete (or pending Replace) draft from a selection range.
|
|
217
|
+
* Captures originalContent, leaves insertedText empty; type becomes 'replace'
|
|
218
|
+
* as soon as the viewer types.
|
|
219
|
+
*/
|
|
220
|
+
startDeleteDraft: (from: number, to: number) => void;
|
|
221
|
+
/**
|
|
222
|
+
* Undo the last keystroke in the draft at the current cursor position.
|
|
223
|
+
* When the draft has no keystrokes left, it is discarded.
|
|
224
|
+
* For a pure Delete draft (no keystrokes ever), calling this discards.
|
|
225
|
+
*/
|
|
226
|
+
undoLastKeystrokeInActiveDraft: () => void;
|
|
227
|
+
/** Drop a draft entirely — removes the inline overlay and draft card. */
|
|
228
|
+
discardDraft: (suggestionId: string) => void;
|
|
229
|
+
/**
|
|
230
|
+
* Refresh the `originalContent` (and the suggestion-draft card's selectedText)
|
|
231
|
+
* for a Delete/Replace draft whose anchored range still resolves but now
|
|
232
|
+
* covers different text — happens when the owner edits within the anchored
|
|
233
|
+
* range while the viewer's draft is open.
|
|
234
|
+
*/
|
|
235
|
+
refreshDraftOriginalContent: (suggestionId: string, currentText: string) => void;
|
|
236
|
+
/**
|
|
237
|
+
* Promote a draft to a submitted suggestion. Pushes the anchor into
|
|
238
|
+
* commentAnchorsRef, calls onNewComment, removes the draft, and swaps the
|
|
239
|
+
* suggestion-draft floating card for a thread card (same floatingCardId).
|
|
240
|
+
*/
|
|
241
|
+
submitDraft: (suggestionId: string) => void;
|
|
180
242
|
deleteReply: (commentId: string, replyId: string) => void;
|
|
181
243
|
requestEditComment: (commentId: string) => void;
|
|
182
244
|
requestEditReply: (commentId: string, replyId: string) => void;
|
package/dist/package/types.d.ts
CHANGED
|
@@ -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';
|
|
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;
|
|
@@ -144,6 +152,7 @@ export interface DdocProps extends CommentAccountProps {
|
|
|
144
152
|
editorCanvasClassNames?: string;
|
|
145
153
|
isCommentSectionOpen?: boolean;
|
|
146
154
|
isPreviewMode: boolean;
|
|
155
|
+
viewerMode?: 'suggest' | 'view-only';
|
|
147
156
|
ensResolutionUrl?: string;
|
|
148
157
|
ipfsImageUploadFn?: (file: File) => Promise<IpfsImageUploadResponse>;
|
|
149
158
|
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
|
};
|