Implement save/load events
This commit is contained in:
parent
614016462f
commit
da3bd0a323
3 changed files with 127 additions and 17 deletions
|
@ -27,67 +27,136 @@
|
|||
.contentDocument;
|
||||
}
|
||||
|
||||
|
||||
/// Custom Events ///
|
||||
|
||||
public GetCurrentHistoryState(callback: (state: IHistoryState) => void) {
|
||||
const component = this.GetEditorComponent();
|
||||
const eventType = 'getCurrentHistoryState';
|
||||
component.dispatchEvent(new CustomEvent(eventType));
|
||||
this.AddEventListener(callback, eventType);
|
||||
const component = this.GetEditorComponent();
|
||||
component.dispatchEvent(new CustomEvent(eventType));
|
||||
}
|
||||
|
||||
public GetEditorState(callback: (state: IEditorState) => void) {
|
||||
const component = this.GetEditorComponent();
|
||||
const eventType = 'getEditorState';
|
||||
component.dispatchEvent(new CustomEvent(eventType));
|
||||
this.AddEventListener(callback, eventType);
|
||||
const component = this.GetEditorComponent();
|
||||
component.dispatchEvent(new CustomEvent(eventType));
|
||||
}
|
||||
|
||||
public SetEditorState(history: SVGLD.IHistoryState[], callback?: (state: IEditorState) => void) {
|
||||
const eventType = 'setEditorState';
|
||||
this.AddEventListener(callback, eventType);
|
||||
const component = this.GetEditorComponent();
|
||||
component.dispatchEvent(new CustomEvent(eventType, { detail: history }));
|
||||
}
|
||||
|
||||
public ReviveEditorState(editorState: SVGLD.IEditorState, callback: (state: IEditorState) => void) {
|
||||
const eventType = 'reviveEditorState';
|
||||
this.AddEventListener(callback, eventType);
|
||||
const component = this.GetEditorComponent();
|
||||
component.dispatchEvent(new CustomEvent(eventType, { detail: editorState }));
|
||||
}
|
||||
|
||||
public ReviveHistory(history: SVGLD.IHistoryState[], callback: (state: IHistoryState[]) => void) {
|
||||
const eventType = 'reviveHistory';
|
||||
this.AddEventListener(callback, eventType);
|
||||
const component = this.GetEditorComponent();
|
||||
component.dispatchEvent(new CustomEvent(eventType, { detail: history }));
|
||||
}
|
||||
|
||||
public AppendNewHistoryState(historyState: SVGLD.IHistoryState, callback?: (state: IEditorState) => void) {
|
||||
const eventType = 'appendNewState';
|
||||
this.GetEditorComponent().dispatchEvent(new CustomEvent(eventType, { detail: historyState }));
|
||||
this.AddEventListener(callback, eventType);
|
||||
this.GetEditorComponent().dispatchEvent(new CustomEvent(eventType, { detail: historyState }));
|
||||
}
|
||||
|
||||
public AddContainer(index: number, type: string, parentId: string, callback?: (state: IEditorState) => void) {
|
||||
const eventType = 'addContainer';
|
||||
this.AddEventListener(callback, eventType);
|
||||
const detail = {
|
||||
index,
|
||||
type,
|
||||
parentId
|
||||
}
|
||||
const eventType = 'addContainer';
|
||||
this.GetEditorComponent().dispatchEvent(new CustomEvent(eventType, { detail }));
|
||||
this.AddEventListener(callback, eventType);
|
||||
}
|
||||
|
||||
public AddContainerToSelectedContainer(index: number, type: string, callback?: (state: IEditorState) => void) {
|
||||
const eventType = 'addContainerToSelectedContainer';
|
||||
this.AddEventListener(callback, eventType);
|
||||
const detail = {
|
||||
index,
|
||||
type
|
||||
}
|
||||
const eventType = 'addContainerToSelectedContainer';
|
||||
this.GetEditorComponent().dispatchEvent(new CustomEvent(eventType, { detail }));
|
||||
this.AddEventListener(callback, eventType);
|
||||
}
|
||||
|
||||
public AppendContainer(type: string, parentId: string, callback?: (state: IEditorState) => void) {
|
||||
const eventType = 'appendContainer';
|
||||
this.AddEventListener(callback, eventType);
|
||||
const detail = {
|
||||
type,
|
||||
parentId
|
||||
}
|
||||
const eventType = 'appendContainer';
|
||||
this.GetEditorComponent().dispatchEvent(new CustomEvent(eventType, { detail }));
|
||||
this.AddEventListener(callback, eventType);
|
||||
}
|
||||
|
||||
public AppendContainerToSelectedContainer(type: string, callback?: (state: IEditorState) => void) {
|
||||
const eventType = 'appendContainerToSelectedContainer';
|
||||
this.AddEventListener(callback, eventType);
|
||||
const detail = {
|
||||
type
|
||||
}
|
||||
const eventType = 'appendContainerToSelectedContainer';
|
||||
this.GetEditorComponent().dispatchEvent(new CustomEvent(eventType, { detail }));
|
||||
this.AddEventListener(callback, eventType);
|
||||
}
|
||||
|
||||
private AddEventListener(callback: (...args: any[]) => void, eventType: string) {
|
||||
public SelectContainer(containerId: string, callback?: (state: IEditorState) => void) {
|
||||
const eventType = 'selectContainer';
|
||||
this.AddEventListener(callback, eventType);
|
||||
const detail = {
|
||||
containerId
|
||||
}
|
||||
this.GetEditorComponent().dispatchEvent(new CustomEvent(eventType, { detail }));
|
||||
}
|
||||
|
||||
public DeleteContainer(containerId: string, callback?: (state: IEditorState) => void) {
|
||||
const eventType = 'deleteContainer';
|
||||
this.AddEventListener(callback, eventType);
|
||||
const detail = {
|
||||
containerId
|
||||
}
|
||||
this.GetEditorComponent().dispatchEvent(new CustomEvent(eventType, { detail }));
|
||||
}
|
||||
|
||||
public AddSymbol(name: string, callback?: (state: IEditorState) => void) {
|
||||
const eventType = 'addSymbol';
|
||||
this.AddEventListener(callback, eventType);
|
||||
const detail = {
|
||||
name
|
||||
}
|
||||
this.GetEditorComponent().dispatchEvent(new CustomEvent(eventType, { detail }));
|
||||
}
|
||||
|
||||
public SelectSymbol(symbolId, callback?: (state: IEditorState) => void) {
|
||||
const eventType = 'selectSymbol';
|
||||
this.AddEventListener(callback, eventType);
|
||||
const detail = {
|
||||
symbolId
|
||||
}
|
||||
this.GetEditorComponent().dispatchEvent(new CustomEvent(eventType, { detail }));
|
||||
}
|
||||
|
||||
public DeleteSymbol(symbolId: string, callback?: (state: IEditorState) => void) {
|
||||
const eventType = 'deleteSymbol';
|
||||
this.AddEventListener(callback, eventType);
|
||||
const detail = {
|
||||
symbolId
|
||||
}
|
||||
this.GetEditorComponent().dispatchEvent(new CustomEvent(eventType, { detail }));
|
||||
}
|
||||
|
||||
private AddEventListener(callback: ((...args: any[]) => void) | undefined, eventType: string) {
|
||||
const root = this.GetRootComponent();
|
||||
const listener = (e: CustomEvent) => {
|
||||
e.target.removeEventListener(e.type, listener);
|
||||
|
@ -106,3 +175,4 @@
|
|||
template: { element: 'svg-layout-designer' }
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue