mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2025-12-16 06:42:53 +00:00
chore: update ts defined
This commit is contained in:
parent
dbd9382117
commit
0d92011863
@ -5,18 +5,6 @@ import { Menu } from '@alifd/next';
|
|||||||
import { engineConfig } from '@alilc/lowcode-editor-core';
|
import { engineConfig } from '@alilc/lowcode-editor-core';
|
||||||
import './context-menu-actions.scss';
|
import './context-menu-actions.scss';
|
||||||
|
|
||||||
export interface IContextMenuActions {
|
|
||||||
actions: IPublicTypeContextMenuAction[];
|
|
||||||
|
|
||||||
adjustMenuLayoutFn: (actions: IPublicTypeContextMenuItem[]) => IPublicTypeContextMenuItem[];
|
|
||||||
|
|
||||||
addMenuAction: IPublicApiMaterial['addContextMenuOption'];
|
|
||||||
|
|
||||||
removeMenuAction: IPublicApiMaterial['removeContextMenuOption'];
|
|
||||||
|
|
||||||
adjustMenuLayout: IPublicApiMaterial['adjustContextMenuLayout'];
|
|
||||||
}
|
|
||||||
|
|
||||||
let adjustMenuLayoutFn: Function = (actions: IPublicTypeContextMenuAction[]) => actions;
|
let adjustMenuLayoutFn: Function = (actions: IPublicTypeContextMenuAction[]) => actions;
|
||||||
|
|
||||||
export class GlobalContextMenuActions {
|
export class GlobalContextMenuActions {
|
||||||
@ -116,7 +104,7 @@ export class GlobalContextMenuActions {
|
|||||||
|
|
||||||
const globalContextMenuActions = new GlobalContextMenuActions();
|
const globalContextMenuActions = new GlobalContextMenuActions();
|
||||||
|
|
||||||
export class ContextMenuActions implements IContextMenuActions {
|
export class ContextMenuActions {
|
||||||
actions: IPublicTypeContextMenuAction[] = [];
|
actions: IPublicTypeContextMenuAction[] = [];
|
||||||
|
|
||||||
designer: IDesigner;
|
designer: IDesigner;
|
||||||
@ -204,30 +192,32 @@ export class ContextMenuActions implements IContextMenuActions {
|
|||||||
originalEvent.stopPropagation();
|
originalEvent.stopPropagation();
|
||||||
originalEvent.preventDefault();
|
originalEvent.preventDefault();
|
||||||
// 如果右键的节点不在 当前选中的节点中,选中该节点
|
// 如果右键的节点不在 当前选中的节点中,选中该节点
|
||||||
if (!designer.currentSelection.has(node.id)) {
|
if (!designer.currentSelection?.has(node.id)) {
|
||||||
designer.currentSelection.select(node.id);
|
designer.currentSelection?.select(node.id);
|
||||||
}
|
}
|
||||||
const nodes = designer.currentSelection.getNodes();
|
const nodes = designer.currentSelection?.getNodes();
|
||||||
this.handleContextMenu(nodes, originalEvent);
|
this.handleContextMenu(nodes, originalEvent);
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
addMenuAction(action: IPublicTypeContextMenuAction) {
|
addMenuAction: IPublicApiMaterial['addContextMenuOption'] = (action: IPublicTypeContextMenuAction) => {
|
||||||
this.actions.push({
|
this.actions.push({
|
||||||
type: IPublicEnumContextMenuType.MENU_ITEM,
|
type: IPublicEnumContextMenuType.MENU_ITEM,
|
||||||
...action,
|
...action,
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
removeMenuAction(name: string) {
|
removeMenuAction: IPublicApiMaterial['removeContextMenuOption'] = (name: string) => {
|
||||||
const i = this.actions.findIndex((action) => action.name === name);
|
const i = this.actions.findIndex((action) => action.name === name);
|
||||||
if (i > -1) {
|
if (i > -1) {
|
||||||
this.actions.splice(i, 1);
|
this.actions.splice(i, 1);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
adjustMenuLayout(fn: (actions: IPublicTypeContextMenuItem[]) => IPublicTypeContextMenuItem[]) {
|
adjustMenuLayout: IPublicApiMaterial['adjustContextMenuLayout'] = (fn: (actions: IPublicTypeContextMenuItem[]) => IPublicTypeContextMenuItem[]) => {
|
||||||
adjustMenuLayoutFn = fn;
|
adjustMenuLayoutFn = fn;
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IContextMenuActions extends ContextMenuActions {}
|
||||||
@ -1,16 +1,16 @@
|
|||||||
import { Component } from 'react';
|
import { Component } from 'react';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import BuiltinDragGhostComponent from './drag-ghost';
|
import BuiltinDragGhostComponent from './drag-ghost';
|
||||||
import { Designer, DesignerProps } from './designer';
|
import { Designer, DesignerProps, IDesigner } from './designer';
|
||||||
import { ProjectView } from '../project';
|
import { ProjectView } from '../project';
|
||||||
import './designer.less';
|
import './designer.less';
|
||||||
|
|
||||||
type IProps = DesignerProps & {
|
type IProps = DesignerProps & {
|
||||||
designer?: Designer;
|
designer?: IDesigner;
|
||||||
};
|
};
|
||||||
|
|
||||||
export class DesignerView extends Component<IProps> {
|
export class DesignerView extends Component<IProps> {
|
||||||
readonly designer: Designer;
|
readonly designer: IDesigner;
|
||||||
readonly viewName: string | undefined;
|
readonly viewName: string | undefined;
|
||||||
|
|
||||||
constructor(props: IProps) {
|
constructor(props: IProps) {
|
||||||
|
|||||||
@ -6,7 +6,6 @@ import {
|
|||||||
IPublicTypeComponentAction,
|
IPublicTypeComponentAction,
|
||||||
IPublicTypeNpmInfo,
|
IPublicTypeNpmInfo,
|
||||||
IPublicModelEditor,
|
IPublicModelEditor,
|
||||||
IPublicTypeCompositeObject,
|
|
||||||
IPublicTypePropsList,
|
IPublicTypePropsList,
|
||||||
IPublicTypeNodeSchema,
|
IPublicTypeNodeSchema,
|
||||||
IPublicTypePropsTransducer,
|
IPublicTypePropsTransducer,
|
||||||
@ -17,15 +16,16 @@ import {
|
|||||||
IPublicTypeLocationData,
|
IPublicTypeLocationData,
|
||||||
IPublicEnumTransformStage,
|
IPublicEnumTransformStage,
|
||||||
IPublicModelLocateEvent,
|
IPublicModelLocateEvent,
|
||||||
|
IPublicTypePropsMap,
|
||||||
} from '@alilc/lowcode-types';
|
} from '@alilc/lowcode-types';
|
||||||
import { mergeAssets, IPublicTypeAssetsJson, isNodeSchema, isDragNodeObject, isDragNodeDataObject, isLocationChildrenDetail, Logger } from '@alilc/lowcode-utils';
|
import { mergeAssets, IPublicTypeAssetsJson, isNodeSchema, isDragNodeObject, isDragNodeDataObject, isLocationChildrenDetail, Logger } from '@alilc/lowcode-utils';
|
||||||
import { IProject, Project } from '../project';
|
import { IProject, Project } from '../project';
|
||||||
import { Node, DocumentModel, insertChildren, INode, ISelection } from '../document';
|
import { Node, DocumentModel, insertChildren, INode } from '../document';
|
||||||
import { ComponentMeta, IComponentMeta } from '../component-meta';
|
import { ComponentMeta, IComponentMeta } from '../component-meta';
|
||||||
import { INodeSelector, Component } from '../simulator';
|
import { INodeSelector, Component } from '../simulator';
|
||||||
import { Scroller } from './scroller';
|
import { Scroller } from './scroller';
|
||||||
import { Dragon, IDragon } from './dragon';
|
import { Dragon, IDragon } from './dragon';
|
||||||
import { ActiveTracker, IActiveTracker } from './active-tracker';
|
import { ActiveTracker } from './active-tracker';
|
||||||
import { Detecting } from './detecting';
|
import { Detecting } from './detecting';
|
||||||
import { DropLocation } from './location';
|
import { DropLocation } from './location';
|
||||||
import { OffsetObserver, createOffsetObserver } from './offset-observer';
|
import { OffsetObserver, createOffsetObserver } from './offset-observer';
|
||||||
@ -47,7 +47,7 @@ export interface DesignerProps {
|
|||||||
viewName?: string;
|
viewName?: string;
|
||||||
simulatorProps?: Record<string, any> | ((document: DocumentModel) => object);
|
simulatorProps?: Record<string, any> | ((document: DocumentModel) => object);
|
||||||
simulatorComponent?: ComponentType<any>;
|
simulatorComponent?: ComponentType<any>;
|
||||||
dragGhostComponent?: ComponentType<any>;
|
dragGhostComponent?: ComponentType<{ designer: IDesigner }>;
|
||||||
suspensed?: boolean;
|
suspensed?: boolean;
|
||||||
componentMetadatas?: IPublicTypeComponentMetadata[];
|
componentMetadatas?: IPublicTypeComponentMetadata[];
|
||||||
globalComponentActions?: IPublicTypeComponentAction[];
|
globalComponentActions?: IPublicTypeComponentAction[];
|
||||||
@ -60,70 +60,10 @@ export interface DesignerProps {
|
|||||||
) => void;
|
) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IDesigner {
|
export class Designer {
|
||||||
readonly shellModelFactory: IShellModelFactory;
|
|
||||||
|
|
||||||
viewName: string | undefined;
|
|
||||||
|
|
||||||
readonly project: IProject;
|
|
||||||
|
|
||||||
get dragon(): IDragon;
|
|
||||||
|
|
||||||
get activeTracker(): IActiveTracker;
|
|
||||||
|
|
||||||
get componentActions(): ComponentActions;
|
|
||||||
|
|
||||||
get contextMenuActions(): ContextMenuActions;
|
|
||||||
|
|
||||||
get editor(): IPublicModelEditor;
|
|
||||||
|
|
||||||
get detecting(): Detecting;
|
|
||||||
|
|
||||||
get simulatorComponent(): ComponentType<any> | undefined;
|
|
||||||
|
|
||||||
get currentSelection(): ISelection;
|
|
||||||
|
|
||||||
createScroller(scrollable: IPublicTypeScrollable): IPublicModelScroller;
|
|
||||||
|
|
||||||
refreshComponentMetasMap(): void;
|
|
||||||
|
|
||||||
createOffsetObserver(nodeInstance: INodeSelector): OffsetObserver | null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建插入位置,考虑放到 dragon 中
|
|
||||||
*/
|
|
||||||
createLocation(locationData: IPublicTypeLocationData<INode>): DropLocation;
|
|
||||||
|
|
||||||
get componentsMap(): { [key: string]: IPublicTypeNpmInfo | Component };
|
|
||||||
|
|
||||||
loadIncrementalAssets(incrementalAssets: IPublicTypeAssetsJson): Promise<void>;
|
|
||||||
|
|
||||||
getComponentMeta(
|
|
||||||
componentName: string,
|
|
||||||
generateMetadata?: () => IPublicTypeComponentMetadata | null,
|
|
||||||
): IComponentMeta;
|
|
||||||
|
|
||||||
clearLocation(): void;
|
|
||||||
|
|
||||||
createComponentMeta(data: IPublicTypeComponentMetadata): IComponentMeta | null;
|
|
||||||
|
|
||||||
getComponentMetasMap(): Map<string, IComponentMeta>;
|
|
||||||
|
|
||||||
addPropsReducer(reducer: IPublicTypePropsTransducer, stage: IPublicEnumTransformStage): void;
|
|
||||||
|
|
||||||
postEvent(event: string, ...args: any[]): void;
|
|
||||||
|
|
||||||
transformProps(props: IPublicTypeCompositeObject | IPublicTypePropsList, node: Node, stage: IPublicEnumTransformStage): IPublicTypeCompositeObject | IPublicTypePropsList;
|
|
||||||
|
|
||||||
createSettingEntry(nodes: INode[]): ISettingTopEntry;
|
|
||||||
|
|
||||||
autorun(effect: (reaction: IReactionPublic) => void, options?: IReactionOptions<any, any>): IReactionDisposer;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class Designer implements IDesigner {
|
|
||||||
dragon: IDragon;
|
dragon: IDragon;
|
||||||
|
|
||||||
viewName: string | undefined;
|
readonly viewName: string | undefined;
|
||||||
|
|
||||||
readonly componentActions = new ComponentActions();
|
readonly componentActions = new ComponentActions();
|
||||||
|
|
||||||
@ -423,7 +363,7 @@ export class Designer implements IDesigner {
|
|||||||
if (props.simulatorProps !== this.props.simulatorProps) {
|
if (props.simulatorProps !== this.props.simulatorProps) {
|
||||||
this._simulatorProps = props.simulatorProps;
|
this._simulatorProps = props.simulatorProps;
|
||||||
// 重新 setupSelection
|
// 重新 setupSelection
|
||||||
if (props.simulatorProps?.designMode !== this.props.simulatorProps?.designMode) {
|
if ((props.simulatorProps as any)?.designMode !== (this.props.simulatorProps as any)?.designMode) {
|
||||||
this.setupSelection();
|
this.setupSelection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -612,7 +552,7 @@ export class Designer implements IDesigner {
|
|||||||
return maps;
|
return maps;
|
||||||
}
|
}
|
||||||
|
|
||||||
transformProps(props: IPublicTypeCompositeObject | IPublicTypePropsList, node: Node, stage: IPublicEnumTransformStage) {
|
transformProps(props: IPublicTypePropsMap | IPublicTypePropsList, node: Node, stage: IPublicEnumTransformStage): IPublicTypePropsMap | IPublicTypePropsList {
|
||||||
if (Array.isArray(props)) {
|
if (Array.isArray(props)) {
|
||||||
// current not support, make this future
|
// current not support, make this future
|
||||||
return props;
|
return props;
|
||||||
@ -623,7 +563,7 @@ export class Designer implements IDesigner {
|
|||||||
return props;
|
return props;
|
||||||
}
|
}
|
||||||
|
|
||||||
return reducers.reduce((xprops, reducer) => {
|
return reducers.reduce((xprops, reducer: IPublicTypePropsTransducer) => {
|
||||||
try {
|
try {
|
||||||
return reducer(xprops, node.internalToShellNode() as any, { stage });
|
return reducer(xprops, node.internalToShellNode() as any, { stage });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -655,3 +595,5 @@ export class Designer implements IDesigner {
|
|||||||
// TODO:
|
// TODO:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IDesigner extends Designer {}
|
||||||
|
|||||||
@ -95,17 +95,13 @@ function isDragEvent(e: any): e is DragEvent {
|
|||||||
return e?.type?.startsWith('drag');
|
return e?.type?.startsWith('drag');
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IDragon extends IPublicModelDragon<
|
|
||||||
INode,
|
|
||||||
ILocateEvent
|
|
||||||
> {
|
|
||||||
emitter: IEventBus;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Drag-on 拖拽引擎
|
* Drag-on 拖拽引擎
|
||||||
*/
|
*/
|
||||||
export class Dragon implements IDragon {
|
export class Dragon implements IPublicModelDragon<
|
||||||
|
INode,
|
||||||
|
ILocateEvent
|
||||||
|
> {
|
||||||
private sensors: IPublicModelSensor[] = [];
|
private sensors: IPublicModelSensor[] = [];
|
||||||
|
|
||||||
private nodeInstPointerEvents: boolean;
|
private nodeInstPointerEvents: boolean;
|
||||||
@ -637,3 +633,5 @@ export class Dragon implements IDragon {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IDragon extends Dragon { }
|
||||||
|
|||||||
@ -28,11 +28,11 @@ export class OffsetObserver {
|
|||||||
@obx private _bottom = 0;
|
@obx private _bottom = 0;
|
||||||
|
|
||||||
@computed get height() {
|
@computed get height() {
|
||||||
return this.isRoot ? this.viewport.height : this._height * this.scale;
|
return this.isRoot ? this.viewport?.height : this._height * this.scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
@computed get width() {
|
@computed get width() {
|
||||||
return this.isRoot ? this.viewport.width : this._width * this.scale;
|
return this.isRoot ? this.viewport?.width : this._width * this.scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
@computed get top() {
|
@computed get top() {
|
||||||
@ -44,51 +44,51 @@ export class OffsetObserver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@computed get bottom() {
|
@computed get bottom() {
|
||||||
return this.isRoot ? this.viewport.height : this._bottom * this.scale;
|
return this.isRoot ? this.viewport?.height : this._bottom * this.scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
@computed get right() {
|
@computed get right() {
|
||||||
return this.isRoot ? this.viewport.width : this._right * this.scale;
|
return this.isRoot ? this.viewport?.width : this._right * this.scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
@obx hasOffset = false;
|
@obx hasOffset = false;
|
||||||
|
|
||||||
@computed get offsetLeft() {
|
@computed get offsetLeft() {
|
||||||
if (this.isRoot) {
|
if (this.isRoot) {
|
||||||
return this.viewport.scrollX * this.scale;
|
return (this.viewport?.scrollX || 0) * this.scale;
|
||||||
}
|
}
|
||||||
if (!this.viewport.scrolling || this.lastOffsetLeft == null) {
|
if (!this.viewport?.scrolling || this.lastOffsetLeft == null) {
|
||||||
this.lastOffsetLeft = this.left + this.viewport.scrollX * this.scale;
|
this.lastOffsetLeft = this.left + (this.viewport?.scrollX || 0) * this.scale;
|
||||||
}
|
}
|
||||||
return this.lastOffsetLeft;
|
return this.lastOffsetLeft;
|
||||||
}
|
}
|
||||||
|
|
||||||
@computed get offsetTop() {
|
@computed get offsetTop() {
|
||||||
if (this.isRoot) {
|
if (this.isRoot) {
|
||||||
return this.viewport.scrollY * this.scale;
|
return (this.viewport?.scrollY || 0) * this.scale;
|
||||||
}
|
}
|
||||||
if (!this.viewport.scrolling || this.lastOffsetTop == null) {
|
if (!this.viewport?.scrolling || this.lastOffsetTop == null) {
|
||||||
this.lastOffsetTop = this.top + this.viewport.scrollY * this.scale;
|
this.lastOffsetTop = this.top + (this.viewport?.scrollY || 0) * this.scale;
|
||||||
}
|
}
|
||||||
return this.lastOffsetTop;
|
return this.lastOffsetTop;
|
||||||
}
|
}
|
||||||
|
|
||||||
@computed get offsetHeight() {
|
@computed get offsetHeight() {
|
||||||
if (!this.viewport.scrolling || this.lastOffsetHeight == null) {
|
if (!this.viewport?.scrolling || this.lastOffsetHeight == null) {
|
||||||
this.lastOffsetHeight = this.isRoot ? this.viewport.height : this.height;
|
this.lastOffsetHeight = this.isRoot ? (this.viewport?.height || 0) : this.height;
|
||||||
}
|
}
|
||||||
return this.lastOffsetHeight;
|
return this.lastOffsetHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
@computed get offsetWidth() {
|
@computed get offsetWidth() {
|
||||||
if (!this.viewport.scrolling || this.lastOffsetWidth == null) {
|
if (!(this.viewport?.scrolling || 0) || this.lastOffsetWidth == null) {
|
||||||
this.lastOffsetWidth = this.isRoot ? this.viewport.width : this.width;
|
this.lastOffsetWidth = this.isRoot ? (this.viewport?.width || 0) : this.width;
|
||||||
}
|
}
|
||||||
return this.lastOffsetWidth;
|
return this.lastOffsetWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
@computed get scale() {
|
@computed get scale() {
|
||||||
return this.viewport.scale;
|
return this.viewport?.scale || 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private pid: number | undefined;
|
private pid: number | undefined;
|
||||||
@ -124,11 +124,11 @@ export class OffsetObserver {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const rect = host.computeComponentInstanceRect(instance!, node.componentMeta.rootSelector);
|
const rect = host?.computeComponentInstanceRect(instance!, node.componentMeta.rootSelector);
|
||||||
|
|
||||||
if (!rect) {
|
if (!rect) {
|
||||||
this.hasOffset = false;
|
this.hasOffset = false;
|
||||||
} else if (!this.viewport.scrolling || !this.hasOffset) {
|
} else if (!this.viewport?.scrolling || !this.hasOffset) {
|
||||||
this._height = rect.height;
|
this._height = rect.height;
|
||||||
this._width = rect.width;
|
this._width = rect.width;
|
||||||
this._left = rect.left;
|
this._left = rect.left;
|
||||||
|
|||||||
@ -56,104 +56,30 @@ export type GetDataType<T, NodeType> = T extends undefined
|
|||||||
: any
|
: any
|
||||||
: T;
|
: T;
|
||||||
|
|
||||||
export interface IDocumentModel extends Omit<IPublicModelDocumentModel<
|
export class DocumentModel implements Omit<IPublicModelDocumentModel<
|
||||||
ISelection,
|
ISelection,
|
||||||
IHistory,
|
IHistory,
|
||||||
INode,
|
INode,
|
||||||
IDropLocation,
|
IDropLocation,
|
||||||
IModalNodesManager,
|
IModalNodesManager,
|
||||||
IProject
|
IProject
|
||||||
>,
|
>,
|
||||||
'detecting' |
|
'detecting' |
|
||||||
'checkNesting' |
|
'checkNesting' |
|
||||||
'getNodeById' |
|
'getNodeById' |
|
||||||
// 以下属性在内部的 document 中不存在
|
// 以下属性在内部的 document 中不存在
|
||||||
'exportSchema' |
|
'exportSchema' |
|
||||||
'importSchema' |
|
'importSchema' |
|
||||||
'onAddNode' |
|
'onAddNode' |
|
||||||
'onRemoveNode' |
|
'onRemoveNode' |
|
||||||
'onChangeDetecting' |
|
'onChangeDetecting' |
|
||||||
'onChangeSelection' |
|
'onChangeSelection' |
|
||||||
'onChangeNodeProp' |
|
'onChangeNodeProp' |
|
||||||
'onImportSchema' |
|
'onImportSchema' |
|
||||||
'isDetectingNode' |
|
'isDetectingNode' |
|
||||||
'onFocusNodeChanged' |
|
'onFocusNodeChanged' |
|
||||||
'onDropLocationChanged'
|
'onDropLocationChanged'
|
||||||
> {
|
> {
|
||||||
|
|
||||||
readonly designer: IDesigner;
|
|
||||||
|
|
||||||
selection: ISelection;
|
|
||||||
|
|
||||||
get rootNode(): INode | null;
|
|
||||||
|
|
||||||
get simulator(): ISimulatorHost | null;
|
|
||||||
|
|
||||||
get active(): boolean;
|
|
||||||
|
|
||||||
get nodesMap(): Map<string, INode>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否为非激活状态
|
|
||||||
*/
|
|
||||||
get suspensed(): boolean;
|
|
||||||
|
|
||||||
get fileName(): string;
|
|
||||||
|
|
||||||
get currentRoot(): INode | null;
|
|
||||||
|
|
||||||
isBlank(): boolean;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据 id 获取节点
|
|
||||||
*/
|
|
||||||
getNode(id: string): INode | null;
|
|
||||||
|
|
||||||
getRoot(): INode | null;
|
|
||||||
|
|
||||||
getHistory(): IHistory;
|
|
||||||
|
|
||||||
checkNesting(
|
|
||||||
dropTarget: INode,
|
|
||||||
dragObject: IPublicTypeDragNodeObject | IPublicTypeNodeSchema | INode | IPublicTypeDragNodeDataObject,
|
|
||||||
): boolean;
|
|
||||||
|
|
||||||
getNodeCount(): number;
|
|
||||||
|
|
||||||
nextId(possibleId: string | undefined): string;
|
|
||||||
|
|
||||||
import(schema: IPublicTypeRootSchema, checkId?: boolean): void;
|
|
||||||
|
|
||||||
export(stage: IPublicEnumTransformStage): IPublicTypeRootSchema | undefined;
|
|
||||||
|
|
||||||
onNodeCreate(func: (node: INode) => void): IPublicTypeDisposable;
|
|
||||||
|
|
||||||
onNodeDestroy(func: (node: INode) => void): IPublicTypeDisposable;
|
|
||||||
|
|
||||||
onChangeNodeVisible(fn: (node: INode, visible: boolean) => void): IPublicTypeDisposable;
|
|
||||||
|
|
||||||
addWillPurge(node: INode): void;
|
|
||||||
|
|
||||||
removeWillPurge(node: INode): void;
|
|
||||||
|
|
||||||
getComponentMeta(componentName: string): IComponentMeta;
|
|
||||||
|
|
||||||
insertNodes(parent: INode, thing: INode[] | IPublicTypeNodeData[], at?: number | null, copy?: boolean): INode[];
|
|
||||||
|
|
||||||
open(): IDocumentModel;
|
|
||||||
|
|
||||||
remove(): void;
|
|
||||||
|
|
||||||
suspense(): void;
|
|
||||||
|
|
||||||
close(): void;
|
|
||||||
|
|
||||||
unlinkNode(node: INode): void;
|
|
||||||
|
|
||||||
destroyNode(node: INode): void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class DocumentModel implements IDocumentModel {
|
|
||||||
/**
|
/**
|
||||||
* 根节点 类型有:Page/Component/Block
|
* 根节点 类型有:Page/Component/Block
|
||||||
*/
|
*/
|
||||||
@ -322,7 +248,7 @@ export class DocumentModel implements IDocumentModel {
|
|||||||
// 兼容 vision
|
// 兼容 vision
|
||||||
this.id = project.getSchema()?.id || this.id;
|
this.id = project.getSchema()?.id || this.id;
|
||||||
|
|
||||||
this.rootNode = this.createNode(
|
this.rootNode = this.createNode<IRootNode, IPublicTypeRootSchema>(
|
||||||
schema || {
|
schema || {
|
||||||
componentName: 'Page',
|
componentName: 'Page',
|
||||||
id: 'root',
|
id: 'root',
|
||||||
@ -425,7 +351,7 @@ export class DocumentModel implements IDocumentModel {
|
|||||||
* 根据 schema 创建一个节点
|
* 根据 schema 创建一个节点
|
||||||
*/
|
*/
|
||||||
@action
|
@action
|
||||||
createNode<T extends INode = INode, C = undefined>(data: GetDataType<C, T>): T {
|
createNode<T = INode, S = IPublicTypeNodeSchema>(data: S): T {
|
||||||
let schema: any;
|
let schema: any;
|
||||||
if (isDOMText(data) || isJSExpression(data)) {
|
if (isDOMText(data) || isJSExpression(data)) {
|
||||||
schema = {
|
schema = {
|
||||||
@ -529,7 +455,7 @@ export class DocumentModel implements IDocumentModel {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const wrapper = this.createNode(schema);
|
const wrapper = this.createNode(schema);
|
||||||
if (wrapper.isParental()) {
|
if (wrapper?.isParental()) {
|
||||||
const first = nodes[0];
|
const first = nodes[0];
|
||||||
// TODO: check nesting rules x 2
|
// TODO: check nesting rules x 2
|
||||||
insertChild(first.parent!, wrapper, first.index);
|
insertChild(first.parent!, wrapper, first.index);
|
||||||
@ -538,7 +464,7 @@ export class DocumentModel implements IDocumentModel {
|
|||||||
return wrapper;
|
return wrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.removeNode(wrapper);
|
wrapper && this.removeNode(wrapper);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -928,3 +854,5 @@ export function isDocumentModel(obj: any): obj is IDocumentModel {
|
|||||||
export function isPageSchema(obj: any): obj is IPublicTypePageSchema {
|
export function isPageSchema(obj: any): obj is IPublicTypePageSchema {
|
||||||
return obj?.componentName === 'Page';
|
return obj?.componentName === 'Page';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IDocumentModel extends DocumentModel {}
|
||||||
@ -10,63 +10,12 @@ export interface IOnChangeOptions {
|
|||||||
node: Node;
|
node: Node;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface INodeChildren extends Omit<IPublicModelNodeChildren<INode>,
|
export class NodeChildren implements Omit<IPublicModelNodeChildren<INode>,
|
||||||
'importSchema' |
|
'importSchema' |
|
||||||
'exportSchema' |
|
'exportSchema' |
|
||||||
'isEmpty' |
|
'isEmpty' |
|
||||||
'notEmpty'
|
'notEmpty'
|
||||||
> {
|
> {
|
||||||
children: INode[];
|
|
||||||
|
|
||||||
get owner(): INode;
|
|
||||||
|
|
||||||
get length(): number;
|
|
||||||
|
|
||||||
unlinkChild(node: INode): void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除一个节点
|
|
||||||
*/
|
|
||||||
internalDelete(
|
|
||||||
node: INode,
|
|
||||||
purge: boolean,
|
|
||||||
useMutator: boolean,
|
|
||||||
options: NodeRemoveOptions
|
|
||||||
): boolean;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 插入一个节点,返回新长度
|
|
||||||
*/
|
|
||||||
internalInsert(node: INode, at?: number | null, useMutator?: boolean): void;
|
|
||||||
|
|
||||||
import(data?: IPublicTypeNodeData | IPublicTypeNodeData[], checkId?: boolean): void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 导出 schema
|
|
||||||
*/
|
|
||||||
export(stage: IPublicEnumTransformStage): IPublicTypeNodeData[];
|
|
||||||
|
|
||||||
/** following methods are overriding super interface, using different param types */
|
|
||||||
/** overriding methods start */
|
|
||||||
|
|
||||||
forEach(fn: (item: INode, index: number) => void): void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据索引获得节点
|
|
||||||
*/
|
|
||||||
get(index: number): INode | null;
|
|
||||||
|
|
||||||
isEmpty(): boolean;
|
|
||||||
|
|
||||||
notEmpty(): boolean;
|
|
||||||
|
|
||||||
internalInitParent(): void;
|
|
||||||
|
|
||||||
onChange(fn: (info?: IOnChangeOptions) => void): IPublicTypeDisposable;
|
|
||||||
|
|
||||||
/** overriding methods end */
|
|
||||||
}
|
|
||||||
export class NodeChildren implements INodeChildren {
|
|
||||||
@obx.shallow children: INode[];
|
@obx.shallow children: INode[];
|
||||||
|
|
||||||
private emitter: IEventBus = createModuleEventBus('NodeChildren');
|
private emitter: IEventBus = createModuleEventBus('NodeChildren');
|
||||||
@ -99,11 +48,10 @@ export class NodeChildren implements INodeChildren {
|
|||||||
constructor(
|
constructor(
|
||||||
readonly owner: INode,
|
readonly owner: INode,
|
||||||
data: IPublicTypeNodeData | IPublicTypeNodeData[],
|
data: IPublicTypeNodeData | IPublicTypeNodeData[],
|
||||||
options: any = {},
|
|
||||||
) {
|
) {
|
||||||
makeObservable(this);
|
makeObservable(this);
|
||||||
this.children = (Array.isArray(data) ? data : [data]).filter(child => !!child).map((child) => {
|
this.children = (Array.isArray(data) ? data : [data]).filter(child => !!child).map((child) => {
|
||||||
return this.owner.document?.createNode(child, options.checkId);
|
return this.owner.document?.createNode(child);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,9 +90,12 @@ export class NodeChildren implements INodeChildren {
|
|||||||
node = child;
|
node = child;
|
||||||
node.import(item);
|
node.import(item);
|
||||||
} else {
|
} else {
|
||||||
node = this.owner.document?.createNode(item, checkId);
|
node = this.owner.document?.createNode(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node) {
|
||||||
|
children[i] = node;
|
||||||
}
|
}
|
||||||
children[i] = node;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.children = children;
|
this.children = children;
|
||||||
@ -176,13 +127,13 @@ export class NodeChildren implements INodeChildren {
|
|||||||
/**
|
/**
|
||||||
* 回收销毁
|
* 回收销毁
|
||||||
*/
|
*/
|
||||||
purge(useMutator = true) {
|
purge() {
|
||||||
if (this.purged) {
|
if (this.purged) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.purged = true;
|
this.purged = true;
|
||||||
this.children.forEach((child) => {
|
this.children.forEach((child) => {
|
||||||
child.purge(useMutator);
|
child.purge();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,7 +163,7 @@ export class NodeChildren implements INodeChildren {
|
|||||||
node.internalPurgeStart();
|
node.internalPurgeStart();
|
||||||
if (node.isParentalNode) {
|
if (node.isParentalNode) {
|
||||||
foreachReverse(
|
foreachReverse(
|
||||||
node.children,
|
node.children!,
|
||||||
(subNode: Node) => {
|
(subNode: Node) => {
|
||||||
subNode.remove(useMutator, purge, options);
|
subNode.remove(useMutator, purge, options);
|
||||||
},
|
},
|
||||||
@ -459,11 +410,11 @@ export class NodeChildren implements INodeChildren {
|
|||||||
const items = adder(this.children);
|
const items = adder(this.children);
|
||||||
if (items && items.length > 0) {
|
if (items && items.length > 0) {
|
||||||
items.forEach((child: IPublicTypeNodeData) => {
|
items.forEach((child: IPublicTypeNodeData) => {
|
||||||
const node: INode = this.owner.document?.createNode(child);
|
const node: INode | null = this.owner.document?.createNode(child);
|
||||||
this.children.push(node);
|
node && this.children.push(node);
|
||||||
node.internalSetParent(this.owner);
|
node?.internalSetParent(this.owner);
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
const editor = node.document?.designer.editor;
|
const editor = node?.document?.designer.editor;
|
||||||
editor?.eventBus.emit('node.add', { node });
|
editor?.eventBus.emit('node.add', { node });
|
||||||
});
|
});
|
||||||
changed = true;
|
changed = true;
|
||||||
@ -504,7 +455,7 @@ export class NodeChildren implements INodeChildren {
|
|||||||
try {
|
try {
|
||||||
callbacks?.onSubtreeModified.call(
|
callbacks?.onSubtreeModified.call(
|
||||||
node.internalToShellNode(),
|
node.internalToShellNode(),
|
||||||
owner.internalToShellNode(),
|
owner.internalToShellNode()!,
|
||||||
options,
|
options,
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -517,3 +468,5 @@ export class NodeChildren implements INodeChildren {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface INodeChildren extends NodeChildren {}
|
||||||
@ -13,7 +13,6 @@ import {
|
|||||||
GlobalEvent,
|
GlobalEvent,
|
||||||
IPublicTypeComponentAction,
|
IPublicTypeComponentAction,
|
||||||
IPublicModelNode,
|
IPublicModelNode,
|
||||||
IPublicModelExclusiveGroup,
|
|
||||||
IPublicEnumTransformStage,
|
IPublicEnumTransformStage,
|
||||||
IPublicTypeDisposable,
|
IPublicTypeDisposable,
|
||||||
IBaseModelNode,
|
IBaseModelNode,
|
||||||
@ -37,132 +36,7 @@ export interface NodeStatus {
|
|||||||
inPlaceEditing: boolean;
|
inPlaceEditing: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IBaseNode<Schema extends IPublicTypeNodeSchema = IPublicTypeNodeSchema> extends Omit<IBaseModelNode<
|
export interface IBaseNode extends Node {}
|
||||||
IDocumentModel,
|
|
||||||
IBaseNode,
|
|
||||||
INodeChildren,
|
|
||||||
IComponentMeta,
|
|
||||||
ISettingTopEntry,
|
|
||||||
IProps,
|
|
||||||
IProp,
|
|
||||||
IExclusiveGroup
|
|
||||||
>,
|
|
||||||
'isRoot' |
|
|
||||||
'isPage' |
|
|
||||||
'isComponent' |
|
|
||||||
'isModal' |
|
|
||||||
'isSlot' |
|
|
||||||
'isParental' |
|
|
||||||
'isLeaf' |
|
|
||||||
'settingEntry' |
|
|
||||||
// 在内部的 node 模型中不存在
|
|
||||||
'getExtraPropValue' |
|
|
||||||
'setExtraPropValue' |
|
|
||||||
'exportSchema' |
|
|
||||||
'visible' |
|
|
||||||
'importSchema' |
|
|
||||||
// 内外实现有差异
|
|
||||||
'isContainer' |
|
|
||||||
'isEmpty'
|
|
||||||
> {
|
|
||||||
isNode: boolean;
|
|
||||||
|
|
||||||
get componentMeta(): IComponentMeta;
|
|
||||||
|
|
||||||
get settingEntry(): ISettingTopEntry;
|
|
||||||
|
|
||||||
get isPurged(): boolean;
|
|
||||||
|
|
||||||
get index(): number | undefined;
|
|
||||||
|
|
||||||
get isPurging(): boolean;
|
|
||||||
|
|
||||||
getId(): string;
|
|
||||||
|
|
||||||
getParent(): INode | null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 内部方法,请勿使用
|
|
||||||
* @param useMutator 是否触发联动逻辑
|
|
||||||
*/
|
|
||||||
internalSetParent(parent: INode | null, useMutator?: boolean): void;
|
|
||||||
|
|
||||||
setConditionGroup(grp: IPublicModelExclusiveGroup | string | null): void;
|
|
||||||
|
|
||||||
internalToShellNode(): IPublicModelNode | null;
|
|
||||||
|
|
||||||
internalPurgeStart(): void;
|
|
||||||
|
|
||||||
unlinkSlot(slotNode: INode): void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 导出 schema
|
|
||||||
*/
|
|
||||||
export<T = Schema>(stage: IPublicEnumTransformStage, options?: any): T;
|
|
||||||
|
|
||||||
emitPropChange(val: IPublicTypePropChangeOptions): void;
|
|
||||||
|
|
||||||
import(data: Schema, checkId?: boolean): void;
|
|
||||||
|
|
||||||
internalSetSlotFor(slotFor: Prop | null | undefined): void;
|
|
||||||
|
|
||||||
addSlot(slotNode: INode): void;
|
|
||||||
|
|
||||||
onVisibleChange(func: (flag: boolean) => any): () => void;
|
|
||||||
|
|
||||||
getSuitablePlace(node: INode, ref: any): any;
|
|
||||||
|
|
||||||
onChildrenChange(fn: (param?: { type: string; node: INode }) => void): IPublicTypeDisposable | undefined;
|
|
||||||
|
|
||||||
onPropChange(func: (info: IPublicTypePropChangeOptions) => void): IPublicTypeDisposable;
|
|
||||||
|
|
||||||
isModal(): boolean;
|
|
||||||
|
|
||||||
isRoot(): boolean;
|
|
||||||
|
|
||||||
isPage(): boolean;
|
|
||||||
|
|
||||||
isComponent(): boolean;
|
|
||||||
|
|
||||||
isSlot(): boolean;
|
|
||||||
|
|
||||||
isParental(): boolean;
|
|
||||||
|
|
||||||
isLeaf(): boolean;
|
|
||||||
|
|
||||||
isContainer(): boolean;
|
|
||||||
|
|
||||||
isEmpty(): boolean;
|
|
||||||
|
|
||||||
remove(
|
|
||||||
useMutator?: boolean,
|
|
||||||
purge?: boolean,
|
|
||||||
options?: NodeRemoveOptions,
|
|
||||||
): void;
|
|
||||||
|
|
||||||
didDropIn(dragment: INode): void;
|
|
||||||
|
|
||||||
didDropOut(dragment: INode): void;
|
|
||||||
|
|
||||||
purge(): void;
|
|
||||||
|
|
||||||
removeSlot(slotNode: INode): boolean;
|
|
||||||
|
|
||||||
setVisible(flag: boolean): void;
|
|
||||||
|
|
||||||
getVisible(): boolean;
|
|
||||||
|
|
||||||
getChildren(): INodeChildren | null;
|
|
||||||
|
|
||||||
clearPropValue(path: string | number): void;
|
|
||||||
|
|
||||||
setProps(props?: IPublicTypePropsMap | IPublicTypePropsList | Props | null): void;
|
|
||||||
|
|
||||||
mergeProps(props: IPublicTypePropsMap): void;
|
|
||||||
|
|
||||||
/** 是否可以选中 */
|
|
||||||
canSelect(): boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 基础节点
|
* 基础节点
|
||||||
@ -212,7 +86,34 @@ export interface IBaseNode<Schema extends IPublicTypeNodeSchema = IPublicTypeNod
|
|||||||
* isLocked
|
* isLocked
|
||||||
* hidden
|
* hidden
|
||||||
*/
|
*/
|
||||||
export class Node<Schema extends IPublicTypeNodeSchema = IPublicTypeNodeSchema> implements IBaseNode {
|
export class Node<Schema extends IPublicTypeNodeSchema = IPublicTypeNodeSchema> implements Omit<IBaseModelNode<
|
||||||
|
IDocumentModel,
|
||||||
|
IBaseNode,
|
||||||
|
INodeChildren,
|
||||||
|
IComponentMeta,
|
||||||
|
ISettingTopEntry,
|
||||||
|
IProps,
|
||||||
|
IProp,
|
||||||
|
IExclusiveGroup
|
||||||
|
>,
|
||||||
|
'isRoot' |
|
||||||
|
'isPage' |
|
||||||
|
'isComponent' |
|
||||||
|
'isModal' |
|
||||||
|
'isSlot' |
|
||||||
|
'isParental' |
|
||||||
|
'isLeaf' |
|
||||||
|
'settingEntry' |
|
||||||
|
// 在内部的 node 模型中不存在
|
||||||
|
'getExtraPropValue' |
|
||||||
|
'setExtraPropValue' |
|
||||||
|
'exportSchema' |
|
||||||
|
'visible' |
|
||||||
|
'importSchema' |
|
||||||
|
// 内外实现有差异
|
||||||
|
'isContainer' |
|
||||||
|
'isEmpty'
|
||||||
|
> {
|
||||||
private emitter: IEventBus;
|
private emitter: IEventBus;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -690,7 +591,7 @@ export class Node<Schema extends IPublicTypeNodeSchema = IPublicTypeNodeSchema>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
setConditionGroup(grp: IPublicModelExclusiveGroup | string | null) {
|
setConditionGroup(grp: IExclusiveGroup | string | null) {
|
||||||
let _grp: IExclusiveGroup | null = null;
|
let _grp: IExclusiveGroup | null = null;
|
||||||
if (!grp) {
|
if (!grp) {
|
||||||
this.getExtraProp('conditionGroup', false)?.remove();
|
this.getExtraProp('conditionGroup', false)?.remove();
|
||||||
@ -1389,11 +1290,11 @@ export interface LeafNode extends Node {
|
|||||||
|
|
||||||
export type IPublicTypePropChangeOptions = Omit<GlobalEvent.Node.Prop.ChangeOptions, 'node'>;
|
export type IPublicTypePropChangeOptions = Omit<GlobalEvent.Node.Prop.ChangeOptions, 'node'>;
|
||||||
|
|
||||||
export type ISlotNode = IBaseNode<IPublicTypeSlotSchema>;
|
export interface ISlotNode extends Node<IPublicTypeSlotSchema> {}
|
||||||
export type IPageNode = IBaseNode<IPublicTypePageSchema>;
|
export interface IPageNode extends Node<IPublicTypePageSchema> {}
|
||||||
export type IComponentNode = IBaseNode<IPublicTypeComponentSchema>;
|
export interface IComponentNode extends Node<IPublicTypeComponentSchema> {}
|
||||||
export type IRootNode = IPageNode | IComponentNode;
|
export interface IRootNode extends Node<IPublicTypePageSchema | IPublicTypeComponentSchema> {}
|
||||||
export type INode = IPageNode | ISlotNode | IComponentNode | IRootNode;
|
export interface INode extends Node<IPublicTypePageSchema | IPublicTypeSlotSchema | IPublicTypeComponentSchema | IPublicTypeNodeSchema> {}
|
||||||
|
|
||||||
export function isRootNode(node: INode): node is IRootNode {
|
export function isRootNode(node: INode): node is IRootNode {
|
||||||
return node && node.isRootNode;
|
return node && node.isRootNode;
|
||||||
@ -1505,7 +1406,7 @@ export function insertChild(
|
|||||||
|
|
||||||
export function insertChildren(
|
export function insertChildren(
|
||||||
container: INode,
|
container: INode,
|
||||||
nodes: INode[] | IPublicTypeNodeData[],
|
nodes: INode[] | IPublicTypeNodeData[] | IPublicModelNode[],
|
||||||
at?: number | null,
|
at?: number | null,
|
||||||
copy?: boolean,
|
copy?: boolean,
|
||||||
): INode[] {
|
): INode[] {
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { untracked, computed, obx, engineConfig, action, makeObservable, mobx, runInAction } from '@alilc/lowcode-editor-core';
|
import { untracked, computed, obx, engineConfig, action, makeObservable, mobx, runInAction } from '@alilc/lowcode-editor-core';
|
||||||
import { GlobalEvent, IPublicEnumTransformStage } from '@alilc/lowcode-types';
|
import { GlobalEvent, IPublicEnumTransformStage } from '@alilc/lowcode-types';
|
||||||
import type { IPublicTypeCompositeValue, IPublicTypeJSSlot, IPublicTypeSlotSchema, IPublicModelProp } from '@alilc/lowcode-types';
|
import type { IPublicTypeCompositeValue, IPublicTypeJSSlot, IPublicTypeSlotSchema, IPublicModelProp, IPublicTypeNodeData } from '@alilc/lowcode-types';
|
||||||
import { uniqueId, isPlainObject, hasOwnProperty, compatStage, isJSExpression, isJSSlot, isNodeSchema } from '@alilc/lowcode-utils';
|
import { uniqueId, isPlainObject, hasOwnProperty, compatStage, isJSExpression, isJSSlot, isNodeSchema } from '@alilc/lowcode-utils';
|
||||||
import { valueToSource } from './value-to-source';
|
import { valueToSource } from './value-to-source';
|
||||||
import { IPropParent } from './props';
|
import { IPropParent } from './props';
|
||||||
@ -227,7 +227,7 @@ export class Prop implements IProp, IPropParent {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public parent: IPropParent,
|
public parent: IPropParent,
|
||||||
value: IPublicTypeCompositeValue | UNSET = UNSET,
|
value: IPublicTypeCompositeValue | IPublicTypeNodeData | IPublicTypeNodeData[] | UNSET = UNSET,
|
||||||
key?: string | number,
|
key?: string | number,
|
||||||
spread = false,
|
spread = false,
|
||||||
options = {},
|
options = {},
|
||||||
@ -351,7 +351,7 @@ export class Prop implements IProp, IPropParent {
|
|||||||
* set value, val should be JSON Object
|
* set value, val should be JSON Object
|
||||||
*/
|
*/
|
||||||
@action
|
@action
|
||||||
setValue(val: IPublicTypeCompositeValue) {
|
setValue(val: IPublicTypeCompositeValue | IPublicTypeNodeData | IPublicTypeNodeData[]) {
|
||||||
if (val === this._value) return;
|
if (val === this._value) return;
|
||||||
const oldValue = this._value;
|
const oldValue = this._value;
|
||||||
this._value = val;
|
this._value = val;
|
||||||
|
|||||||
@ -37,30 +37,9 @@ export interface IPropParent {
|
|||||||
delete(prop: IProp): void;
|
delete(prop: IProp): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IProps extends Omit<IBaseModelProps<IProp>, | 'getExtraProp' | 'getExtraPropValue' | 'setExtraPropValue' | 'node'>, IPropParent {
|
export interface IProps extends Props {}
|
||||||
|
|
||||||
/**
|
export class Props implements Omit<IBaseModelProps<IProp>, | 'getExtraProp' | 'getExtraPropValue' | 'setExtraPropValue' | 'node'>, IPropParent {
|
||||||
* 获取 props 对应的 node
|
|
||||||
*/
|
|
||||||
getNode(): INode;
|
|
||||||
|
|
||||||
get(path: string, createIfNone?: boolean): IProp | null;
|
|
||||||
|
|
||||||
export(stage?: IPublicEnumTransformStage): {
|
|
||||||
props?: IPublicTypePropsMap | IPublicTypePropsList;
|
|
||||||
extras?: ExtrasObject;
|
|
||||||
};
|
|
||||||
|
|
||||||
merge(value: IPublicTypePropsMap, extras?: IPublicTypePropsMap): void;
|
|
||||||
|
|
||||||
purge(): void;
|
|
||||||
|
|
||||||
query(path: string, createIfNone: boolean): IProp | null;
|
|
||||||
|
|
||||||
import(value?: IPublicTypePropsMap | IPublicTypePropsList | null, extras?: ExtrasObject): void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class Props implements IProps, IPropParent {
|
|
||||||
readonly id = uniqueId('props');
|
readonly id = uniqueId('props');
|
||||||
|
|
||||||
@obx.shallow private items: IProp[] = [];
|
@obx.shallow private items: IProp[] = [];
|
||||||
|
|||||||
@ -20,6 +20,7 @@ import {
|
|||||||
IPublicEnumPluginRegisterLevel,
|
IPublicEnumPluginRegisterLevel,
|
||||||
IPublicModelWindow,
|
IPublicModelWindow,
|
||||||
IPublicApiCommonUI,
|
IPublicApiCommonUI,
|
||||||
|
IPublicApiCommand,
|
||||||
} from '@alilc/lowcode-types';
|
} from '@alilc/lowcode-types';
|
||||||
import {
|
import {
|
||||||
IPluginContextOptions,
|
IPluginContextOptions,
|
||||||
@ -48,6 +49,7 @@ export default class PluginContext implements
|
|||||||
editorWindow: IPublicModelWindow;
|
editorWindow: IPublicModelWindow;
|
||||||
commonUI: IPublicApiCommonUI;
|
commonUI: IPublicApiCommonUI;
|
||||||
isPluginRegisteredInWorkspace: false;
|
isPluginRegisteredInWorkspace: false;
|
||||||
|
command: IPublicApiCommand;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
options: IPluginContextOptions,
|
options: IPluginContextOptions,
|
||||||
|
|||||||
@ -44,72 +44,27 @@ export enum SkeletonEvents {
|
|||||||
WIDGET_ENABLE = 'skeleton.widget.enable',
|
WIDGET_ENABLE = 'skeleton.widget.enable',
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ISkeleton extends Omit<IPublicApiSkeleton,
|
export interface ISkeleton extends Skeleton {}
|
||||||
'showPanel' |
|
|
||||||
'hidePanel' |
|
export class Skeleton implements Omit<IPublicApiSkeleton,
|
||||||
'showWidget' |
|
'showPanel' |
|
||||||
'enableWidget' |
|
'hidePanel' |
|
||||||
'hideWidget' |
|
'showWidget' |
|
||||||
'disableWidget' |
|
'enableWidget' |
|
||||||
'showArea' |
|
'hideWidget' |
|
||||||
'onShowPanel' |
|
'disableWidget' |
|
||||||
'onHidePanel' |
|
'showArea' |
|
||||||
'onShowWidget' |
|
'onShowPanel' |
|
||||||
'onHideWidget' |
|
'onHidePanel' |
|
||||||
'remove' |
|
'onShowWidget' |
|
||||||
'hideArea' |
|
'onHideWidget' |
|
||||||
'add'
|
'remove' |
|
||||||
|
'hideArea' |
|
||||||
|
'add' |
|
||||||
|
'getAreaItems' |
|
||||||
|
'onDisableWidget' |
|
||||||
|
'onEnableWidget'
|
||||||
> {
|
> {
|
||||||
editor: IEditor;
|
|
||||||
|
|
||||||
readonly leftArea: Area<DockConfig | PanelDockConfig | DialogDockConfig>;
|
|
||||||
|
|
||||||
readonly topArea: Area<DockConfig | DividerConfig | PanelDockConfig | DialogDockConfig>;
|
|
||||||
|
|
||||||
readonly subTopArea: Area<DockConfig | DividerConfig | PanelDockConfig | DialogDockConfig>;
|
|
||||||
|
|
||||||
readonly toolbar: Area<DockConfig | DividerConfig | PanelDockConfig | DialogDockConfig>;
|
|
||||||
|
|
||||||
readonly leftFixedArea: Area<IPublicTypePanelConfig, Panel>;
|
|
||||||
|
|
||||||
readonly leftFloatArea: Area<IPublicTypePanelConfig, Panel>;
|
|
||||||
|
|
||||||
readonly rightArea: Area<IPublicTypePanelConfig, Panel>;
|
|
||||||
|
|
||||||
readonly mainArea: Area<WidgetConfig | IPublicTypePanelConfig, Widget | Panel>;
|
|
||||||
|
|
||||||
readonly bottomArea: Area<IPublicTypePanelConfig, Panel>;
|
|
||||||
|
|
||||||
readonly stages: Area<StageConfig, Stage>;
|
|
||||||
|
|
||||||
readonly widgets: IWidget[];
|
|
||||||
|
|
||||||
readonly focusTracker: FocusTracker;
|
|
||||||
|
|
||||||
getPanel(name: string): Panel | undefined;
|
|
||||||
|
|
||||||
getWidget(name: string): IWidget | undefined;
|
|
||||||
|
|
||||||
buildFromConfig(config?: EditorConfig, components?: PluginClassSet): void;
|
|
||||||
|
|
||||||
createStage(config: any): string | undefined;
|
|
||||||
|
|
||||||
getStage(name: string): Stage | null;
|
|
||||||
|
|
||||||
createContainer(
|
|
||||||
name: string,
|
|
||||||
handle: (item: any) => any,
|
|
||||||
exclusive?: boolean,
|
|
||||||
checkVisible?: () => boolean,
|
|
||||||
defaultSetCurrent?: boolean,
|
|
||||||
): WidgetContainer;
|
|
||||||
|
|
||||||
createPanel(config: IPublicTypePanelConfig): Panel;
|
|
||||||
|
|
||||||
add(config: IPublicTypeSkeletonConfig, extraConfig?: Record<string, any>): IWidget | Widget | Panel | Stage | Dock | PanelDock | undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class Skeleton implements ISkeleton {
|
|
||||||
private panels = new Map<string, Panel>();
|
private panels = new Map<string, Panel>();
|
||||||
|
|
||||||
private configTransducers: IPublicTypeConfigTransducer[] = [];
|
private configTransducers: IPublicTypeConfigTransducer[] = [];
|
||||||
@ -431,7 +386,7 @@ export class Skeleton implements ISkeleton {
|
|||||||
}
|
}
|
||||||
const { content, ...restConfig } = config;
|
const { content, ...restConfig } = config;
|
||||||
if (content) {
|
if (content) {
|
||||||
if (isPlainObject(content) && !isValidElement(content)) {
|
if (isPlainObject<IPublicTypePanelConfig>(content) && !isValidElement(content)) {
|
||||||
Object.keys(content).forEach((key) => {
|
Object.keys(content).forEach((key) => {
|
||||||
if (/props$/i.test(key) && restConfig[key]) {
|
if (/props$/i.test(key) && restConfig[key]) {
|
||||||
restConfig[key] = {
|
restConfig[key] = {
|
||||||
|
|||||||
@ -229,7 +229,7 @@ export async function init(
|
|||||||
document.body.appendChild(engineContainer);
|
document.body.appendChild(engineContainer);
|
||||||
} else {
|
} else {
|
||||||
engineOptions = options;
|
engineOptions = options;
|
||||||
engineContainer = container;
|
engineContainer = container!;
|
||||||
if (!container) {
|
if (!container) {
|
||||||
engineContainer = document.createElement('div');
|
engineContainer = document.createElement('div');
|
||||||
engineContainer.id = 'engine';
|
engineContainer.id = 'engine';
|
||||||
|
|||||||
@ -1,29 +1,32 @@
|
|||||||
interface UtilsMetadata {
|
// interface UtilsMetadata {
|
||||||
name: string;
|
// name: string;
|
||||||
npm: {
|
// npm: {
|
||||||
package: string;
|
// package: string;
|
||||||
version?: string;
|
// version?: string;
|
||||||
exportName: string;
|
// exportName: string;
|
||||||
subName?: string;
|
// subName?: string;
|
||||||
destructuring?: boolean;
|
// destructuring?: boolean;
|
||||||
main?: string;
|
// main?: string;
|
||||||
};
|
// };
|
||||||
}
|
// }
|
||||||
|
|
||||||
interface LibrayMap {
|
// invalid code
|
||||||
[key: string]: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getProjectUtils(librayMap: LibrayMap, utilsMetadata: UtilsMetadata[]) {
|
// interface LibrayMap {
|
||||||
const projectUtils: { [packageName: string]: any } = {};
|
// [key: string]: string;
|
||||||
if (utilsMetadata) {
|
// }
|
||||||
utilsMetadata.forEach(meta => {
|
|
||||||
if (librayMap[meta?.npm.package]) {
|
// export function getProjectUtils(librayMap: LibrayMap, utilsMetadata: UtilsMetadata[]) {
|
||||||
const lib = window[librayMap[meta?.npm.package]];
|
|
||||||
}
|
// const projectUtils: { [packageName: string]: any } = {};
|
||||||
});
|
// if (utilsMetadata) {
|
||||||
}
|
// utilsMetadata.forEach(meta => {
|
||||||
}
|
// if (librayMap[meta?.npm.package]) {
|
||||||
|
// const lib = window[librayMap[meta?.npm.package] as any];
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* judges if current simulator renderer deteched or not
|
* judges if current simulator renderer deteched or not
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { IPublicApiWorkspace, IPublicResourceList, IPublicTypeDisposable, IPublicTypeResourceType } from '@alilc/lowcode-types';
|
import { IPublicApiWorkspace, IPublicModelResource, IPublicResourceList, IPublicTypeDisposable, IPublicTypeResourceType } from '@alilc/lowcode-types';
|
||||||
import { IWorkspace } from '@alilc/lowcode-workspace';
|
import { IWorkspace } from '@alilc/lowcode-workspace';
|
||||||
import { resourceSymbol, workspaceSymbol } from '../symbols';
|
import { resourceSymbol, workspaceSymbol } from '../symbols';
|
||||||
import { Resource as ShellResource, Window as ShellWindow } from '../model';
|
import { Resource as ShellResource, Window as ShellWindow } from '../model';
|
||||||
@ -13,7 +13,7 @@ export class Workspace implements IPublicApiWorkspace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get resourceList() {
|
get resourceList() {
|
||||||
return this[workspaceSymbol].getResourceList().map((d) => new ShellResource(d));
|
return this[workspaceSymbol].getResourceList().map((d) => new ShellResource(d) as IPublicModelResource);
|
||||||
}
|
}
|
||||||
|
|
||||||
setResourceList(resourceList: IPublicResourceList) {
|
setResourceList(resourceList: IPublicResourceList) {
|
||||||
|
|||||||
@ -46,7 +46,7 @@ export class Resource implements IPublicModelResource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get children() {
|
get children() {
|
||||||
return this[resourceSymbol].children.map((child) => new Resource(child));
|
return this[resourceSymbol].children.map((child) => new Resource(child) as IPublicModelResource);
|
||||||
}
|
}
|
||||||
|
|
||||||
get viewName() {
|
get viewName() {
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
import { Component, ReactNode } from 'react';
|
import { Component, ReactElement, ReactNode } from 'react';
|
||||||
import { IPublicTypeI18nData, IPublicTypeNodeSchema, IPublicTypeTitleContent } from '../type';
|
import { IPublicTypeI18nData, IPublicTypeNodeSchema, IPublicTypeTitleContent } from '../type';
|
||||||
import { IPublicEnumTransitionType } from '../enum';
|
import { IPublicEnumTransitionType } from '../enum';
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ export interface IPublicApiCommonUtils {
|
|||||||
/**
|
/**
|
||||||
* i18n 转换方法
|
* i18n 转换方法
|
||||||
*/
|
*/
|
||||||
intl(data: IPublicTypeI18nData | string, params?: object): string;
|
intl(data: IPublicTypeI18nData | string | undefined | ReactElement, params?: object): string;
|
||||||
}
|
}
|
||||||
export interface IPublicApiCommonSkeletonCabin {
|
export interface IPublicApiCommonSkeletonCabin {
|
||||||
|
|
||||||
|
|||||||
@ -108,7 +108,7 @@ export interface IPublicModelDocumentModel<
|
|||||||
* @param data
|
* @param data
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
createNode<T = Node>(data: IPublicTypeNodeSchema): T | null;
|
createNode<T = Node, S = IPublicTypeNodeSchema>(data: S): T | null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 移除指定节点/节点id
|
* 移除指定节点/节点id
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { IPublicEnumTransformStage } from '../enum';
|
import { IPublicEnumTransformStage } from '../enum';
|
||||||
import { IPublicTypeCompositeValue } from '../type';
|
import { IPublicTypeCompositeValue, IPublicTypeNodeData } from '../type';
|
||||||
import { IPublicModelNode } from './';
|
import { IPublicModelNode } from './';
|
||||||
|
|
||||||
export interface IPublicModelProp<
|
export interface IPublicModelProp<
|
||||||
@ -48,7 +48,7 @@ export interface IPublicModelProp<
|
|||||||
* set value for this prop
|
* set value for this prop
|
||||||
* @param val
|
* @param val
|
||||||
*/
|
*/
|
||||||
setValue(val: IPublicTypeCompositeValue): void;
|
setValue(val: IPublicTypeCompositeValue | IPublicTypeNodeData | IPublicTypeNodeData[]): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取值
|
* 获取值
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { ReactElement } from 'react';
|
import { ComponentType, ReactElement } from 'react';
|
||||||
|
|
||||||
export interface IBaseModelResource<
|
export interface IBaseModelResource<
|
||||||
Resource
|
Resource
|
||||||
@ -7,7 +7,7 @@ export interface IBaseModelResource<
|
|||||||
|
|
||||||
get id(): string | undefined;
|
get id(): string | undefined;
|
||||||
|
|
||||||
get icon(): ReactElement | undefined;
|
get icon(): ReactElement | undefined | ComponentType;
|
||||||
|
|
||||||
get options(): Record<string, any>;
|
get options(): Record<string, any>;
|
||||||
|
|
||||||
|
|||||||
@ -102,7 +102,7 @@ export interface IPublicTypeFilterItem {
|
|||||||
}
|
}
|
||||||
export interface IPublicTypeAutorunItem {
|
export interface IPublicTypeAutorunItem {
|
||||||
name: string;
|
name: string;
|
||||||
autorun: (target: IPublicModelSettingField | null) => any;
|
autorun: (target: IPublicModelSettingField | null | undefined) => any;
|
||||||
}
|
}
|
||||||
|
|
||||||
// thinkof Array
|
// thinkof Array
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
import { IPublicEnumTransformStage } from '../enum';
|
import { IPublicEnumTransformStage } from '../enum';
|
||||||
import { IPublicModelNode } from '../model';
|
import { IPublicModelNode } from '../model';
|
||||||
import { IPublicTypeCompositeObject } from './';
|
import { IPublicTypePropsMap } from './';
|
||||||
|
|
||||||
export type IPublicTypePropsTransducer = (
|
export type IPublicTypePropsTransducer = (
|
||||||
props: IPublicTypeCompositeObject,
|
props: IPublicTypePropsMap,
|
||||||
node: IPublicModelNode,
|
node: IPublicModelNode,
|
||||||
ctx?: {
|
ctx?: {
|
||||||
stage: IPublicEnumTransformStage;
|
stage: IPublicEnumTransformStage;
|
||||||
},
|
},
|
||||||
) => IPublicTypeCompositeObject;
|
) => IPublicTypePropsMap;
|
||||||
|
|||||||
@ -36,7 +36,7 @@ export interface IPublicTypeWidgetBaseConfig {
|
|||||||
*/
|
*/
|
||||||
area?: IPublicTypeWidgetConfigArea;
|
area?: IPublicTypeWidgetConfigArea;
|
||||||
props?: Record<string, any>;
|
props?: Record<string, any>;
|
||||||
content?: string | ReactElement | ComponentType<any> | IPublicTypePanelConfig[];
|
content?: string | ReactElement | ComponentType<any> | IPublicTypePanelConfig[] | IPublicTypePanelConfig;
|
||||||
contentProps?: Record<string, any>;
|
contentProps?: Record<string, any>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { isObject } from './is-object';
|
import { isObject } from './is-object';
|
||||||
|
|
||||||
export function isPlainObject(value: any): value is any {
|
export function isPlainObject<T extends object = object>(value: any): value is T {
|
||||||
if (!isObject(value)) {
|
if (!isObject(value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -55,32 +55,10 @@ import { getLogger, Logger as InnerLogger } from '@alilc/lowcode-utils';
|
|||||||
import { IWorkspace } from '../workspace';
|
import { IWorkspace } from '../workspace';
|
||||||
import { IEditorWindow } from '../window';
|
import { IEditorWindow } from '../window';
|
||||||
|
|
||||||
export interface IBasicContext extends Omit<IPublicModelPluginContext, 'workspace'> {
|
export interface IBasicContext extends BasicContext {
|
||||||
skeleton: IPublicApiSkeleton;
|
|
||||||
plugins: IPublicApiPlugins;
|
|
||||||
project: IPublicApiProject;
|
|
||||||
setters: IPublicApiSetters;
|
|
||||||
material: IPublicApiMaterial;
|
|
||||||
common: IPublicApiCommon;
|
|
||||||
config: IEngineConfig;
|
|
||||||
event: IPublicApiEvent;
|
|
||||||
logger: InnerLogger;
|
|
||||||
hotkey: IPublicApiHotkey;
|
|
||||||
innerProject: IProject;
|
|
||||||
editor: Editor;
|
|
||||||
designer: IDesigner;
|
|
||||||
registerInnerPlugins: () => Promise<void>;
|
|
||||||
innerSetters: InnerSetters;
|
|
||||||
innerSkeleton: ISkeleton;
|
|
||||||
innerHotkey: IHotKey;
|
|
||||||
innerPlugins: ILowCodePluginManager;
|
|
||||||
canvas: IPublicApiCanvas;
|
|
||||||
pluginEvent: IPublicApiEvent;
|
|
||||||
preference: IPluginPreferenceMananger;
|
|
||||||
workspace: IWorkspace;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class BasicContext implements IBasicContext {
|
export class BasicContext implements Omit<IPublicModelPluginContext, 'workspace' | 'commonUI' | 'command' | 'isPluginRegisteredInWorkspace' | 'editorWindow'> {
|
||||||
skeleton: IPublicApiSkeleton;
|
skeleton: IPublicApiSkeleton;
|
||||||
plugins: IPublicApiPlugins;
|
plugins: IPublicApiPlugins;
|
||||||
project: IPublicApiProject;
|
project: IPublicApiProject;
|
||||||
|
|||||||
@ -1,14 +1,8 @@
|
|||||||
import { IPublicTypeResourceType } from '@alilc/lowcode-types';
|
import { IPublicTypeResourceType } from '@alilc/lowcode-types';
|
||||||
|
|
||||||
export interface IResourceType extends Omit<IPublicTypeResourceType, 'resourceName' | 'resourceType'> {
|
export interface IResourceType extends ResourceType {}
|
||||||
name: string;
|
|
||||||
|
|
||||||
type: 'editor' | 'webview';
|
export class ResourceType implements Omit<IPublicTypeResourceType, 'resourceName' | 'resourceType'> {
|
||||||
|
|
||||||
resourceTypeModel: IPublicTypeResourceType;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class ResourceType implements IResourceType {
|
|
||||||
constructor(readonly resourceTypeModel: IPublicTypeResourceType) {
|
constructor(readonly resourceTypeModel: IPublicTypeResourceType) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,35 +1,14 @@
|
|||||||
import { ISkeleton } from '@alilc/lowcode-editor-skeleton';
|
|
||||||
import { IPublicTypeEditorView, IPublicResourceData, IPublicResourceTypeConfig, IBaseModelResource, IPublicEnumPluginRegisterLevel } from '@alilc/lowcode-types';
|
import { IPublicTypeEditorView, IPublicResourceData, IPublicResourceTypeConfig, IBaseModelResource, IPublicEnumPluginRegisterLevel } from '@alilc/lowcode-types';
|
||||||
import { Logger } from '@alilc/lowcode-utils';
|
import { Logger } from '@alilc/lowcode-utils';
|
||||||
import { BasicContext, IBasicContext } from './context/base-context';
|
import { BasicContext, IBasicContext } from './context/base-context';
|
||||||
import { ResourceType, IResourceType } from './resource-type';
|
import { IResourceType } from './resource-type';
|
||||||
import { IWorkspace } from './workspace';
|
import { IWorkspace } from './workspace';
|
||||||
|
|
||||||
const logger = new Logger({ level: 'warn', bizName: 'workspace:resource' });
|
const logger = new Logger({ level: 'warn', bizName: 'workspace:resource' });
|
||||||
|
|
||||||
export interface IBaseResource<T> extends IBaseModelResource<T> {
|
export interface IResource extends Resource {}
|
||||||
readonly resourceType: ResourceType;
|
|
||||||
|
|
||||||
skeleton: ISkeleton;
|
export class Resource implements IBaseModelResource<IResource> {
|
||||||
|
|
||||||
description?: string;
|
|
||||||
|
|
||||||
get editorViews(): IPublicTypeEditorView[];
|
|
||||||
|
|
||||||
get defaultViewName(): string | undefined;
|
|
||||||
|
|
||||||
getEditorView(name: string): IPublicTypeEditorView | undefined;
|
|
||||||
|
|
||||||
import(schema: any): Promise<any>;
|
|
||||||
|
|
||||||
save(value: any): Promise<any>;
|
|
||||||
|
|
||||||
url(): Promise<string | undefined>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type IResource = IBaseResource<IResource>;
|
|
||||||
|
|
||||||
export class Resource implements IResource {
|
|
||||||
private context: IBasicContext;
|
private context: IBasicContext;
|
||||||
|
|
||||||
resourceTypeInstance: IPublicResourceTypeConfig;
|
resourceTypeInstance: IPublicResourceTypeConfig;
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
import { PureComponent } from 'react';
|
import { PureComponent } from 'react';
|
||||||
import { ResourceView } from './resource-view';
|
import { ResourceView } from './resource-view';
|
||||||
import { engineConfig, observer } from '@alilc/lowcode-editor-core';
|
import { engineConfig, observer } from '@alilc/lowcode-editor-core';
|
||||||
import { EditorWindow } from '../window';
|
import { IEditorWindow } from '../window';
|
||||||
import { BuiltinLoading } from '@alilc/lowcode-designer';
|
import { BuiltinLoading } from '@alilc/lowcode-designer';
|
||||||
import { DesignerView } from '../inner-plugins/webview';
|
import { DesignerView } from '../inner-plugins/webview';
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
export class WindowView extends PureComponent<{
|
export class WindowView extends PureComponent<{
|
||||||
window: EditorWindow;
|
window: IEditorWindow;
|
||||||
active: boolean;
|
active: boolean;
|
||||||
}, any> {
|
}, any> {
|
||||||
render() {
|
render() {
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { uniqueId } from '@alilc/lowcode-utils';
|
import { uniqueId } from '@alilc/lowcode-utils';
|
||||||
import { createModuleEventBus, IEventBus, makeObservable, obx } from '@alilc/lowcode-editor-core';
|
import { createModuleEventBus, IEventBus, makeObservable, obx } from '@alilc/lowcode-editor-core';
|
||||||
import { Context, IViewContext } from './context/view-context';
|
import { Context } from './context/view-context';
|
||||||
import { IWorkspace } from './workspace';
|
import { IWorkspace } from './workspace';
|
||||||
import { IResource } from './resource';
|
import { IResource } from './resource';
|
||||||
import { IPublicModelWindow, IPublicTypeDisposable } from '@alilc/lowcode-types';
|
import { IPublicModelWindow, IPublicTypeDisposable } from '@alilc/lowcode-types';
|
||||||
@ -12,23 +12,7 @@ interface IWindowCOnfig {
|
|||||||
sleep?: boolean;
|
sleep?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IEditorWindow extends Omit<IPublicModelWindow<IResource>, 'changeViewType' | 'currentEditorView' | 'editorViews'> {
|
export interface IEditorWindow extends EditorWindow {}
|
||||||
readonly resource: IResource;
|
|
||||||
|
|
||||||
editorViews: Map<string, IViewContext>;
|
|
||||||
|
|
||||||
_editorView: IViewContext;
|
|
||||||
|
|
||||||
changeViewName: (name: string, ignoreEmit?: boolean) => void;
|
|
||||||
|
|
||||||
initReady: boolean;
|
|
||||||
|
|
||||||
sleep?: boolean;
|
|
||||||
|
|
||||||
init(): void;
|
|
||||||
|
|
||||||
updateState(state: WINDOW_STATE): void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum WINDOW_STATE {
|
export enum WINDOW_STATE {
|
||||||
// 睡眠
|
// 睡眠
|
||||||
@ -44,7 +28,7 @@ export enum WINDOW_STATE {
|
|||||||
destroyed = 'destroyed'
|
destroyed = 'destroyed'
|
||||||
}
|
}
|
||||||
|
|
||||||
export class EditorWindow implements IEditorWindow {
|
export class EditorWindow implements Omit<IPublicModelWindow<IResource>, 'changeViewType' | 'currentEditorView' | 'editorViews'> {
|
||||||
id: string = uniqueId('window');
|
id: string = uniqueId('window');
|
||||||
icon: React.ReactElement | undefined;
|
icon: React.ReactElement | undefined;
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { IDesigner, ILowCodePluginManager, LowCodePluginManager } from '@alilc/lowcode-designer';
|
import { IDesigner, LowCodePluginManager } from '@alilc/lowcode-designer';
|
||||||
import { createModuleEventBus, Editor, IEditor, IEventBus, makeObservable, obx } from '@alilc/lowcode-editor-core';
|
import { createModuleEventBus, IEditor, IEventBus, makeObservable, obx } from '@alilc/lowcode-editor-core';
|
||||||
import { IPublicApiPlugins, IPublicApiWorkspace, IPublicEnumPluginRegisterLevel, IPublicResourceList, IPublicTypeDisposable, IPublicTypeResourceType, IShellModelFactory } from '@alilc/lowcode-types';
|
import { IPublicApiPlugins, IPublicApiWorkspace, IPublicEnumPluginRegisterLevel, IPublicResourceList, IPublicTypeDisposable, IPublicTypeResourceType } from '@alilc/lowcode-types';
|
||||||
import { BasicContext } from './context/base-context';
|
import { BasicContext } from './context/base-context';
|
||||||
import { EditorWindow, WINDOW_STATE } from './window';
|
import { EditorWindow, WINDOW_STATE } from './window';
|
||||||
import type { IEditorWindow } from './window';
|
import type { IEditorWindow } from './window';
|
||||||
@ -20,56 +20,11 @@ enum EVENT {
|
|||||||
|
|
||||||
const CHANGE_EVENT = 'resource.list.change';
|
const CHANGE_EVENT = 'resource.list.change';
|
||||||
|
|
||||||
export interface IWorkspace extends Omit<IPublicApiWorkspace<
|
export class Workspace implements Omit<IPublicApiWorkspace<
|
||||||
LowCodePluginManager,
|
LowCodePluginManager,
|
||||||
|
ISkeleton,
|
||||||
IEditorWindow
|
IEditorWindow
|
||||||
>, 'resourceList' | 'plugins' | 'openEditorWindow' | 'removeEditorWindow'> {
|
>, 'resourceList' | 'plugins' | 'openEditorWindow' | 'removeEditorWindow'> {
|
||||||
readonly registryInnerPlugin: (designer: IDesigner, editor: Editor, plugins: IPublicApiPlugins) => Promise<IPublicTypeDisposable>;
|
|
||||||
|
|
||||||
readonly shellModelFactory: IShellModelFactory;
|
|
||||||
|
|
||||||
enableAutoOpenFirstWindow: boolean;
|
|
||||||
|
|
||||||
window: IEditorWindow;
|
|
||||||
|
|
||||||
plugins: ILowCodePluginManager;
|
|
||||||
|
|
||||||
skeleton: ISkeleton;
|
|
||||||
|
|
||||||
resourceTypeMap: Map<string, ResourceType>;
|
|
||||||
|
|
||||||
getResourceList(): IResource[];
|
|
||||||
|
|
||||||
getResourceType(resourceName: string): IResourceType;
|
|
||||||
|
|
||||||
checkWindowQueue(): void;
|
|
||||||
|
|
||||||
emitWindowRendererReady(): void;
|
|
||||||
|
|
||||||
initWindow(): void;
|
|
||||||
|
|
||||||
setActive(active: boolean): void;
|
|
||||||
|
|
||||||
onChangeActiveEditorView(fn: () => void): IPublicTypeDisposable;
|
|
||||||
|
|
||||||
emitChangeActiveEditorView(): void;
|
|
||||||
|
|
||||||
openEditorWindowByResource(resource: IResource, sleep: boolean): Promise<void>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
removeEditorWindow(resourceName: string, id: string): void;
|
|
||||||
|
|
||||||
removeEditorWindowByResource(resource: IResource): void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
openEditorWindow(name: string, title: string, options: Object, viewName?: string, sleep?: boolean): Promise<void>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class Workspace implements IWorkspace {
|
|
||||||
context: BasicContext;
|
context: BasicContext;
|
||||||
|
|
||||||
enableAutoOpenFirstWindow: boolean;
|
enableAutoOpenFirstWindow: boolean;
|
||||||
@ -377,3 +332,5 @@ export class Workspace implements IWorkspace {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IWorkspace extends Workspace {}
|
||||||
Loading…
x
Reference in New Issue
Block a user