fix: file plugin object reference

This commit is contained in:
Aaryan Khandelwal
2025-05-27 21:04:29 +05:30
parent e9d69ff1ac
commit dbca7d3bf3
2 changed files with 12 additions and 8 deletions

View File

@@ -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<string> | 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]);
}
}
});

View File

@@ -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]);
}
}
});