import { mergeListToMap } from 'ts-toolset/dist/common/map'; import { MapStore, EventBus } from '../services'; import { IHtmlComponentEntity } from '../models/html'; import { IocContainer, ServicesIoc, WorkbenchIoc } from '../ioc'; import { HtmlEvents, MapStoreKeys } from '../workbench/integration/html/common'; import { HtmlDatasetIntegrator, HtmlWorkbenchInitiator, HtmlInterfaceIntegrator, HtmlSyntaxIntegrator, InitHtmlInterfaceIntegratorParams, EditIntegrator } from '../workbench/integration/html'; export * from '../workbench/integration/html/common'; export interface InitHtmlUIEditorParams { // data dataset: { components: any, editorOptions: any, pageSchemas?: any, templateSchemas?: any, codeTemplates?: any }; // part interfaceParams: InitHtmlInterfaceIntegratorParams } /** UI编辑器配置 */ export interface HtmlUIEditorOptions { /** 当前版本号 */ version: string; } export class HtmlUIEditor { private _options: HtmlUIEditorOptions; // 服务 private _eventBus: EventBus; private _mapStore: MapStore; // 工作台 private _dataset: HtmlDatasetIntegrator; private _interface: HtmlInterfaceIntegrator; private _syntax: HtmlSyntaxIntegrator; private _edit: EditIntegrator; constructor(options: HtmlUIEditorOptions) { this._options = options; //==== 初始化服务 ==== this._eventBus = IocContainer.get(ServicesIoc.Identifier.EventBus); this._mapStore = IocContainer.get(ServicesIoc.Identifier.MapStore); //==== 初始化工作台 ==== IocContainer.get(WorkbenchIoc.HtmlIntegrationIdentifier.WorkbenchInitiator); this._dataset = IocContainer.get(WorkbenchIoc.HtmlIntegrationIdentifier.DatasetIntegrator); this._interface = IocContainer.get(WorkbenchIoc.HtmlIntegrationIdentifier.InterfaceIntegrator); this._edit = IocContainer.get(WorkbenchIoc.HtmlIntegrationIdentifier.EditIntegrator); this._syntax = IocContainer.get(WorkbenchIoc.HtmlIntegrationIdentifier.SyntaxIntegrator); this._eventBus.register(HtmlEvents.initial, this._initial, { scope: this }); } get eventBus() { return this._eventBus; } /** 界面操作类 */ get interface() { return this._interface; } get edit() { return this._edit; } get dataset() { return this._dataset; } get syntax() { return this._syntax; } private _initial({ dataset, interfaceParams }: InitHtmlUIEditorParams) { // data mergeListToMap(this._mapStore.get(MapStoreKeys.pageSchemaStore)!, dataset.pageSchemas, 'id'); mergeListToMap(this._mapStore.get(MapStoreKeys.templateSchemaStore)!, dataset.templateSchemas, 'id'); mergeListToMap(this._mapStore.get(MapStoreKeys.editorOptionStore)!, dataset.editorOptions, 'key'); mergeListToMap(this._mapStore.get(MapStoreKeys.componentStore)!, dataset.components, (v: IHtmlComponentEntity) => `${v.libraryKey}.${v.key}`); // part this._interface.initial(interfaceParams); } }