diff --git a/packages/editor/src/core/plugins/file/delete.ts b/packages/editor/src/core/plugins/file/delete.ts index 3d7e16fe8e..b77841c229 100644 --- a/packages/editor/src/core/plugins/file/delete.ts +++ b/packages/editor/src/core/plugins/file/delete.ts @@ -7,9 +7,11 @@ import { TFileHandler } from "@/types"; // local imports import { TFileNode } from "./types"; +const DELETE_PLUGIN_KEY = new PluginKey("delete-utility"); + export const TrackFileDeletionPlugin = (editor: Editor, deleteHandler: TFileHandler["delete"]): Plugin => new Plugin({ - key: new PluginKey("delete-utility"), + key: DELETE_PLUGIN_KEY, appendTransaction: (transactions: readonly Transaction[], oldState: EditorState, newState: EditorState) => { const newFileSources: { [nodeType: string]: Set | undefined; @@ -20,10 +22,10 @@ export const TrackFileDeletionPlugin = (editor: Editor, deleteHandler: TFileHand const nodeType = node.type.name; const nodeFileSetDetails = NODE_FILE_MAP[nodeType]; if (nodeFileSetDetails) { - if (newFileSources.nodeType) { - newFileSources.nodeType.add(node.attrs.src); + if (newFileSources[nodeType]) { + newFileSources[nodeType].add(node.attrs.src); } else { - newFileSources.nodeType = new Set([node.attrs.src]); + newFileSources[nodeType] = new Set([node.attrs.src]); } } }); diff --git a/packages/editor/src/core/plugins/file/restore.ts b/packages/editor/src/core/plugins/file/restore.ts index 791c3ce2fa..04a4c295cc 100644 --- a/packages/editor/src/core/plugins/file/restore.ts +++ b/packages/editor/src/core/plugins/file/restore.ts @@ -9,9 +9,11 @@ import { TFileHandler } from "@/types"; // local imports import { TFileNode } from "./types"; +const RESTORE_PLUGIN_KEY = new PluginKey("restore-utility"); + export const TrackFileRestorationPlugin = (editor: Editor, restoreHandler: TFileHandler["restore"]): Plugin => new Plugin({ - key: new PluginKey("restore-utility"), + key: RESTORE_PLUGIN_KEY, appendTransaction: (transactions: readonly Transaction[], oldState: EditorState, newState: EditorState) => { if (!transactions.some((tr) => tr.docChanged)) return null; @@ -22,10 +24,10 @@ export const TrackFileRestorationPlugin = (editor: Editor, restoreHandler: TFile const nodeType = node.type.name; const nodeFileSetDetails = NODE_FILE_MAP[nodeType]; if (nodeFileSetDetails) { - if (oldFileSources.nodeType) { - oldFileSources.nodeType.add(node.attrs.src); + if (oldFileSources[nodeType]) { + oldFileSources[nodeType].add(node.attrs.src); } else { - oldFileSources.nodeType = new Set([node.attrs.src]); + oldFileSources[nodeType] = new Set([node.attrs.src]); } } });