svg-layout-designer-react/public/smartcomponent/svg-layout-designer.ts
2022-08-26 11:14:31 +02:00

49 lines
No EOL
1.9 KiB
TypeScript

namespace SmartBusiness.Web.Components {
export class SVGLayoutDesigner extends Components.ComponentBase {
public constructor(componentInfo: KnockoutComponentTypes.ComponentInfo, params: any) {
super(componentInfo, params);
setTimeout(() => (window as any).SVGLayoutDesigner.Render(this.$component[0]));
this.InitEventsListener();
}
public GetEditorComponent() {
return this.$component[0].querySelector('.Editor');
}
public GetCurrentHistoryState() {
this.GetEditorComponent().dispatchEvent(new CustomEvent('getCurrentHistoryState'));
}
public GetEditorState() {
this.GetEditorComponent().dispatchEvent(new CustomEvent('getEditorState'));
}
public SetEditorState(editorState: IEditorState) {
this.GetEditorComponent().dispatchEvent(new CustomEvent('SetEditorState', { detail: editorState }));
}
public AppendNewHistoryState(historyState: IHistoryState) {
this.GetEditorComponent().dispatchEvent(new CustomEvent('appendNewState', { detail: historyState }));
}
public OHistoryState: KnockoutObservable<any>;
private InitEventsListener() {
this.$component[0].addEventListener('getCurrentHistoryState', (e: CustomEvent) => {
this.OHistoryState(e.detail);
console.log(this.OHistoryState());
});
this.$component[0].addEventListener('getEditorState', (e) => console.log((e as any).detail));
}
}
ko.components.register('svg-layout-designer', {
viewModel: {
createViewModel: function (params, componentInfo) {
return new SmartBusiness.Web.Components.SVGLayoutDesigner(componentInfo, params);
}
},
template: { element: 'svg-layout-designer' }
});
}