Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,9 @@ const handleTrackedChangeTransaction = (trackedChangeMeta, trackedChanges, newEd
const getTrackedChangeText = ({ node, mark, trackedChangeType, isDeletionInsertion, deletionNodes = [] }) => {
const deletionText = deletionNodes.length ? deletionNodes[0].text : null;

let trackedChangeText = isDeletionInsertion ? nextNode.text : node.text;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@harbournick - Not sure what you wanted to do here, but nextNode variable was not defined.

let nextNode = null; //
let trackedChangeText = isDeletionInsertion ? nextNode?.text : node?.text;
if (!trackedChangeText) trackedChangeText = '';

// If this is a format change, let's get the string of what changes were made
const isFormatChange = trackedChangeType === TrackFormatMarkName;
Expand All @@ -483,9 +485,12 @@ const createOrUpdateTrackedChangeComment = ({ event, marks, deletionNodes, nodes

let id = attrs.id;

if (!nodes.length) return;
// if (!nodes.length) {
// return;
// }

const node = nodes[0];
const nextTrackedNode = null; //
const isDeletionInsertion = (
trackedChangeType === TrackDeleteMarkName && nextTrackedNode?.type?.name === TrackInsertMarkName
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

nextTrackedNode variable was not defined too.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Oh yeah, I'll remove some of this. This was left over from the previous iteration of this and prob not needed. I'll clean it up.

);
Expand Down
5 changes: 5 additions & 0 deletions packages/super-editor/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import Toolbar from './components/toolbar/Toolbar.vue';
import SuperInput from './components/SuperInput.vue';
import * as fieldAnnotationHelpers from './extensions/field-annotation/fieldAnnotationHelpers/index.js';
import * as trackChangesHelpers from './extensions/track-changes/trackChangesHelpers/index.js';
import { TrackChangesBasePluginKey } from './extensions/track-changes/plugins/index.js';
import { CommentsPluginKey } from './extensions/comment/comments-plugin.js';

const Extensions = {
Node,
Expand Down Expand Up @@ -60,4 +62,7 @@ export {

// External extensions classes
Extensions,

TrackChangesBasePluginKey,
CommentsPluginKey,
};
1 change: 1 addition & 0 deletions packages/superdoc/src/SuperDoc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ const onCommentsLoaded = ({ editor, comments, replacedFile }) => {
nextTick(() => {
commentsStore.processLoadedDocxComments({
superdoc: proxy.$superdoc,
editor,
comments,
documentId: editor.options.documentId
});
Expand Down
32 changes: 30 additions & 2 deletions packages/superdoc/src/stores/comments-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ref, reactive, computed } from 'vue';
import { comments_module_events } from '@harbour-enterprises/common';
import { useSuperdocStore } from '@superdoc/stores/superdoc-store';
import { syncCommentsToClients } from '../core/collaboration/helpers.js';
import { Editor, } from '@harbour-enterprises/super-editor';
import { Editor, trackChangesHelpers, TrackChangesBasePluginKey, CommentsPluginKey } from '@harbour-enterprises/super-editor';
import { getRichTextExtensions } from '@harbour-enterprises/super-editor';
import useComment from '@superdoc/components/CommentsLayer/use-comment';

Expand Down Expand Up @@ -441,7 +441,7 @@ export const useCommentsStore = defineStore('comments', () => {
* @param {String} param0.documentId The document ID
* @returns {void}
*/
const processLoadedDocxComments = async ({ superdoc, comments, documentId }) => {
const processLoadedDocxComments = async ({ superdoc, editor, comments, documentId }) => {
const document = superdocStore.getDocument(documentId);

if (__IS_DEBUG__) console.debug('[processLoadedDocxComments] processing comments...', comments);
Expand Down Expand Up @@ -478,6 +478,34 @@ export const useCommentsStore = defineStore('comments', () => {

addComment({ superdoc, comment: newComment });
});

const trackedChanges = trackChangesHelpers.getTrackChanges(editor.state);

// Create comments for tracked changes
// that do not have a corresponding comment (created in Word).
trackedChanges.forEach(({ mark }) => {
const foundComment = commentsList.value.find((i) => i.commentId === mark.attrs.id);

if (foundComment) {
return;
}

const { dispatch } = editor.view;
const { tr } = editor.view.state;

const markMetaKeys = {
trackInsert: 'insertedMark',
trackDelete: 'deletionMark',
trackFormat: 'formatMark',
};

const markKeyName = markMetaKeys[mark.type.name];
if (markKeyName) {
tr.setMeta(CommentsPluginKey, { type: 'force' });
tr.setMeta(TrackChangesBasePluginKey, { [markKeyName]: mark });
dispatch(tr);
}
});
}

const translateCommentsForExport = () => {
Expand Down