Add GetDefaultEditorState to App CustomEvents

This commit is contained in:
Eric NGUYEN 2022-10-13 15:01:38 +02:00
parent a89b92eab8
commit 749609f9a0
2 changed files with 30 additions and 1 deletions

View file

@ -4,6 +4,7 @@
*/
type IHistoryState = SVGLD.IHistoryState;
type IEditorState = SVGLD.IEditorState;
type IConfiguration = SVGLD.IConfiguration;
export class SVGLayoutDesigner extends Components.ComponentBase {
@ -178,6 +179,20 @@
const component = this.GetAppComponent();
component.dispatchEvent(new CustomEvent(eventType, { detail: history }));
}
/**
* Construct a default EditorState from a given configuration.
* This is the same method used when loading the editor
* for the first time after fetch the configuration from the API.
* @param configuration History to revive
* @param callback Callback with the revived state
*/
public GetDefaultEditorState(configuration: IConfiguration, callback: (state: IEditorState) => void) {
const eventType = 'getDefaultEditorState';
this.app.AddEventListener(eventType, callback);
const component = this.GetAppComponent();
component.dispatchEvent(new CustomEvent(eventType, { detail: configuration }));
}
}