replace commitToHistory with storeAction

This commit is contained in:
zsviczian
2024-05-22 21:22:39 +02:00
parent 32cd3a62b6
commit c4e95d9207
4 changed files with 24 additions and 15 deletions

View File

@@ -422,6 +422,7 @@ export declare class ExcalidrawAutomate {
appState?: AppState;
files?: BinaryFileData;
commitToHistory?: boolean;
storeAction?: "capture" | "none" | "update";
}, restore?: boolean): void;
/**
* connect an object to the selected element in the view

View File

@@ -1833,7 +1833,7 @@ export class ExcalidrawAutomate {
this.targetView.updateScene({
elements: el.filter((e: ExcalidrawElement) => !elToDelete.includes(e)),
appState: st,
commitToHistory: true,
storeAction: "capture",
});
//this.targetView.save();
return true;
@@ -1951,7 +1951,7 @@ export class ExcalidrawAutomate {
appState: {
viewModeEnabled: !isFullscreen,
},
commitToHistory: false,
storeAction: "none",
});
this.targetView.toolsPanelRef?.current?.setExcalidrawViewMode(!isFullscreen);
}
@@ -1986,6 +1986,7 @@ export class ExcalidrawAutomate {
appState?: AppState,
files?: BinaryFileData,
commitToHistory?: boolean,
storeAction?: "capture" | "none" | "update",
},
restore: boolean = false,
):void {
@@ -1994,7 +1995,16 @@ export class ExcalidrawAutomate {
errorMessage("targetView not set", "viewToggleFullScreen()");
return;
}
this.targetView.updateScene(scene,restore);
if (!Boolean(scene.storeAction)) {
scene.storeAction = scene.commitToHistory ? "capture" : "none";
}
this.targetView.updateScene({
elements: scene.elements,
appState: scene.appState,
files: scene.files,
storeAction: scene.storeAction,
},restore);
}
/**
@@ -2555,7 +2565,7 @@ export class ExcalidrawAutomate {
elements.splice(newZIndex, 0, elements.splice(oldZIndex, 1)[0]);
this.targetView.updateScene({
elements,
commitToHistory: true,
storeAction: "capture",
});
};

View File

@@ -206,7 +206,7 @@ export const addFiles = async (
view.updateScene({
elements: s.scene.elements,
appState: s.scene.appState,
commitToHistory: false,
storeAction: "none",
});
}
for (const f of files) {
@@ -1492,7 +1492,7 @@ export default class ExcalidrawView extends TextFileView {
...st,
theme,
},
commitToHistory: false,
storeAction: "none",
});
}
@@ -2275,7 +2275,7 @@ export default class ExcalidrawView extends TextFileView {
{
elements: excalidrawData.elements.concat(deletedElements??[]), //need to preserve deleted elements during autosave if images, links, etc. are updated
files: excalidrawData.files,
commitToHistory: true,
storeAction: "update",
},
justloaded
);
@@ -2288,7 +2288,7 @@ export default class ExcalidrawView extends TextFileView {
? this.excalidrawData.selectedElementIds
: {},
zenModeEnabled,
viewModeEnabled: viewModeEnabled,
viewModeEnabled,
linkOpacity: this.excalidrawData.getLinkOpacity(),
trayModeEnabled: this.plugin.settings.defaultTrayMode,
penMode: penEnabled,
@@ -2298,10 +2298,7 @@ export default class ExcalidrawView extends TextFileView {
pinnedScripts: this.plugin.settings.pinnedScripts,
customPens: this.plugin.settings.customPens.slice(0,this.plugin.settings.numberOfCustomPens),
},
//files: excalidrawData.files,
//commitToHistory: true,
},
//justloaded,
);
if (
this.app.workspace.getActiveViewOfType(ExcalidrawView) === this.leaf.view &&
@@ -2971,7 +2968,7 @@ export default class ExcalidrawView extends TextFileView {
this.updateScene(
{
elements,
commitToHistory: true,
storeAction: "capture",
},
shouldRestoreElements,
);
@@ -5387,7 +5384,7 @@ export default class ExcalidrawView extends TextFileView {
elements?: ExcalidrawElement[];
appState?: any;
files?: any;
commitToHistory?: boolean;
storeAction?: "capture" | "none" | "update"; //https://github.com/excalidraw/excalidraw/pull/7898
},
shouldRestore: boolean = false,
) {

View File

@@ -686,8 +686,9 @@ export const EXCALIDRAW_AUTOMATE_INFO: SuggesterInfo[] = [
},
{
field: "viewUpdateScene",
code: "viewUpdateScene(scene:{elements?:ExcalidrawElement[],appState?: AppState,files?: BinaryFileData,commitToHistory?: boolean,},restore:boolean=false):void",
desc: "Calls the ExcalidrawAPI updateScene function for the targetView. When restore=true, excalidraw will try to correct errors in the scene such as setting default values to missing element properties.",
code: "viewUpdateScene(scene:{elements?:ExcalidrawElement[],appState?: AppState,files?: BinaryFileData,commitToHistory?: boolean,storeAction?: 'capture' | 'none' | 'update'},restore:boolean=false):void",
desc: "Calls the ExcalidrawAPI updateScene function for the targetView. When restore=true, excalidraw will try to correct errors in the scene such as setting default values to missing element properties. " +
`Note that commitToHistory has been deprecated in Excalidraw and is no longer used. You should use storeAction instead. See ${hyperlink("https://github.com/excalidraw/excalidraw/pull/7898", "ExcalidrawAPI")} documentation for more information.`,
after: "",
},
{