shouldRestoreElements

This commit is contained in:
zsviczian
2023-07-17 13:36:42 +00:00
parent 1a9f56bb09
commit 982f206ca4
5 changed files with 7 additions and 3 deletions

View File

@@ -1626,6 +1626,7 @@ export class ExcalidrawAutomate implements ExcalidrawAutomateInterface {
repositionToCursor: boolean = false,
save: boolean = true,
newElementsOnTop: boolean = false,
shouldRestoreElements: boolean = false, //restore elements - auto corrects broken, incomplete or old elements included in the update
): Promise<boolean> {
//@ts-ignore
if (!this.targetView || !this.targetView?._loaded) {
@@ -1639,6 +1640,7 @@ export class ExcalidrawAutomate implements ExcalidrawAutomateInterface {
save,
this.imagesDict,
newElementsOnTop,
shouldRestoreElements,
);
};

View File

@@ -2610,6 +2610,7 @@ export default class ExcalidrawView extends TextFileView {
save: boolean = false,
images: any,
newElementsOnTop: boolean = false,
shouldRestoreElements: boolean = false,
): Promise<boolean> => {
const api = this.excalidrawAPI as ExcalidrawImperativeAPI;
if (!excalidrawRef?.current || !api) {
@@ -2668,7 +2669,7 @@ export default class ExcalidrawView extends TextFileView {
elements,
commitToHistory: true,
},
true, //set to true because svtToExcalidraw generates a legacy Excalidraw object
shouldRestoreElements,
);
if (images && Object.keys(images).length >0) {

View File

@@ -44,7 +44,7 @@ export class ImportSVGDialog extends FuzzySuggestModal<TFile> {
const svg = await app.vault.read(item);
if(!svg || svg === "") return;
ea.importSVG(svg);
ea.addElementsToView(true, true, true);
ea.addElementsToView(true, true, true,true);
}
public start(view: ExcalidrawView) {

View File

@@ -356,7 +356,7 @@ export const EXCALIDRAW_AUTOMATE_INFO: SuggesterInfo[] = [
},
{
field: "addElementsToView",
code: "addElementsToView(repositionToCursor?: boolean, save?: boolean, newElementsOnTop?: boolean,): Promise<boolean>;",
code: "addElementsToView(repositionToCursor?: boolean, save?: boolean, newElementsOnTop?: boolean,shouldRestoreElements?: boolean,): Promise<boolean>;",
desc: "Adds elements from elementsDict to the current view\nrepositionToCursor: default is false\nsave: default is true\nnewElementsOnTop: default is false, i.e. the new elements get to the bottom of the stack\nnewElementsOnTop controls whether elements created with ExcalidrawAutomate are added at the bottom of the stack or the top of the stack of elements already in the view\nNote that elements copied to the view with copyViewElementsToEAforEditing retain their position in the stack of elements in the view even if modified using EA",
after: "",
},

1
src/types.d.ts vendored
View File

@@ -203,6 +203,7 @@ export interface ExcalidrawAutomateInterface {
//Note that elements copied to the view with copyViewElementsToEAforEditing retain their
//position in the stack of elements in the view even if modified using EA
newElementsOnTop?: boolean, //default is false, i.e. the new elements get to the bottom of the stack
shouldRestoreElements?: boolean, //restore elements - auto corrects broken, incomplete or old elements included in the update
): Promise<boolean>;
//Register instance of EA to use for hooks with TargetView
//By default ExcalidrawViews will check window.ExcalidrawAutomate for event hooks.