import Log from 'sap/base/Log'; import type RuntimeAuthoring from 'sap/ui/rta/RuntimeAuthoring'; import type RTAOutlineService from 'sap/ui/rta/command/OutlineService'; import type { ExternalAction } from '@sap-ux-private/control-property-editor-common'; import { outlineChanged } from '@sap-ux-private/control-property-editor-common'; import { getError } from '../../utils/error.js'; import { ChangeService } from '../changes/index.js'; import { ControlTreeIndex } from '../types.js'; import { transformNodes } from './nodes.js'; export const OUTLINE_CHANGE_EVENT = 'OUTLINE_CHANGED'; export interface OutlineChangedEventDetail { controlIndex: ControlTreeIndex; } /** * A Class of WorkspaceConnectorService */ export class OutlineService extends EventTarget { constructor(private readonly rta: RuntimeAuthoring, private readonly changeService: ChangeService) { super(); } /** * Initializes connector service. * * @param sendAction action sender function */ public async init(sendAction: (action: ExternalAction) => void): Promise { const outline = await this.rta.getService('outline'); const { scenario } = this.rta.getFlexSettings(); const syncOutline = async () => { try { const viewNodes = await outline.get(); const controlIndex: ControlTreeIndex = {}; const configPropertyIdMap = new Map(); const outlineNodes = await transformNodes( viewNodes, scenario, controlIndex, this.changeService, configPropertyIdMap ); const event = new CustomEvent(OUTLINE_CHANGE_EVENT, { detail: { controlIndex } }); this.dispatchEvent(event); sendAction(outlineChanged(outlineNodes)); await this.changeService.updateConfigurationProps(configPropertyIdMap); } catch (error) { Log.error('Outline sync failed!', getError(error)); } }; await syncOutline(); outline.attachEvent('update', syncOutline); } public onOutlineChange(handler: (event: CustomEvent) => void | Promise): void { this.addEventListener(OUTLINE_CHANGE_EVENT, handler as EventListener); } }