Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions packages/superdoc/src/components/CommentsLayer/CommentDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,12 @@ const handleAddComment = () => {
};

const handleReject = () => {
if (props.comment.trackedChange) {
const customHandler = proxy.$superdoc.config.onTrackedChangeBubbleReject;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new handlers should be added to apps/docs/core/superdoc/configuration.mdx, e.g.

 <ParamField path="onTrackedChangeBubbleAccept" type="function">
   Custom handler for accepting tracked changes from comment bubbles.
   Replaces default behavior entirely when provided.

   ```javascript
   onTrackedChangeBubbleAccept: (comment, editor) => {
     // Your custom logic here
     editor.commands.acceptTrackedChangeById(comment.commentId);
     await saveDocument(); // e.g., custom save after accept
   }

   Only fires from bubble buttons, not toolbar or context menu


if (props.comment.trackedChange && typeof customHandler === 'function') {
// Custom handler replaces default behavior
customHandler(props.comment, proxy.$superdoc.activeEditor);
} else if (props.comment.trackedChange) {
props.comment.resolveComment({
email: superdocStore.user.email,
name: superdocStore.user.name,
Expand All @@ -230,6 +235,7 @@ const handleReject = () => {
commentsStore.deleteComment({ superdoc: proxy.$superdoc, commentId: props.comment.commentId });
}

// Always cleanup the dialog state
nextTick(() => {
commentsStore.lastUpdate = new Date();
activeComment.value = null;
Expand All @@ -238,16 +244,24 @@ const handleReject = () => {
};

const handleResolve = () => {
if (props.comment.trackedChange) {
proxy.$superdoc.activeEditor.commands.acceptTrackedChangeById(props.comment.commentId);
}
const customHandler = proxy.$superdoc.config.onTrackedChangeBubbleAccept;

props.comment.resolveComment({
email: superdocStore.user.email,
name: superdocStore.user.name,
superdoc: proxy.$superdoc,
});
if (props.comment.trackedChange && typeof customHandler === 'function') {
// Custom handler replaces default behavior
customHandler(props.comment, proxy.$superdoc.activeEditor);
} else {
if (props.comment.trackedChange) {
proxy.$superdoc.activeEditor.commands.acceptTrackedChangeById(props.comment.commentId);
}

props.comment.resolveComment({
email: superdocStore.user.email,
name: superdocStore.user.name,
superdoc: proxy.$superdoc,
});
}

// Always cleanup the dialog state
nextTick(() => {
commentsStore.lastUpdate = new Date();
activeComment.value = null;
Expand Down
6 changes: 6 additions & 0 deletions packages/superdoc/src/core/SuperDoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ export class SuperDoc extends EventEmitter {
onListDefinitionsChange: () => null,
onTransaction: () => null,
onFontsResolved: null,

// Tracked change bubble handlers - replace default accept/reject behavior
// Only fires from bubble buttons, not toolbar or context menu
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we document that the default behavior includes resolving the comment and clearing active state?

users might not realize they need to handle these themselves - maybe add an example showing the full flow?

// Signature: (comment, editor) => void
onTrackedChangeBubbleAccept: null,
onTrackedChangeBubbleReject: null,
// Image upload handler
// async (file) => url;
handleImageUpload: null,
Expand Down
11 changes: 11 additions & 0 deletions packages/superdoc/src/dev/components/SuperdocDev.vue
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,17 @@ const init = async () => {
onEditorCreate,
onContentError,
// handleImageUpload: async (file) => url,

// Tracked change bubble button handlers - replace default accept/reject behavior
// Only fires from bubble buttons, not toolbar or context menu
// onTrackedChangeBubbleAccept: (comment, editor) => {
// console.log('Custom accept handler', comment);
// editor.commands.acceptTrackedChangeById(comment.commentId);
// },
// onTrackedChangeBubbleReject: (comment, editor) => {
// console.log('Custom reject handler', comment);
// editor.commands.rejectTrackedChangeById(comment.commentId);
// },
// Override icons.
toolbarIcons: {},
onCommentsUpdate,
Expand Down