fix: fix lint issues in shell

This commit is contained in:
JackLian 2023-01-12 11:37:22 +08:00 committed by 刘菊萍(絮黎)
parent c1299e3143
commit 8537eff893
38 changed files with 429 additions and 262 deletions

View File

@ -77,7 +77,7 @@ hover 节点变化事件
* set callback which will be called when hovering object changed. * set callback which will be called when hovering object changed.
* @since v1.1.0 * @since v1.1.0
*/ */
onDetectingChange(fn: (node: IPublicModelNode) => void): IPublicTypeDisposable; onDetectingChange(fn: (node: IPublicModelNode | null) => void): IPublicTypeDisposable;
``` ```
相关类型: 相关类型:

View File

@ -6,7 +6,7 @@ import {
} from '@alilc/lowcode-types'; } from '@alilc/lowcode-types';
import { isNode } from '@alilc/lowcode-utils'; import { isNode } from '@alilc/lowcode-utils';
export interface IActiveTracker extends IPublicModelActiveTracker { export interface IActiveTracker extends Omit< IPublicModelActiveTracker, 'track' > {
track(originalTarget: IPublicTypeActiveTarget | INode): void; track(originalTarget: IPublicTypeActiveTarget | INode): void;
} }

View File

@ -17,17 +17,16 @@ import {
IPublicTypeLocationData, IPublicTypeLocationData,
IPublicEnumTransformStage, IPublicEnumTransformStage,
IPublicModelDragon, IPublicModelDragon,
IPublicModelActiveTracker,
IPublicModelDropLocation, IPublicModelDropLocation,
} from '@alilc/lowcode-types'; } from '@alilc/lowcode-types';
import { megreAssets, IPublicTypeAssetsJson, isNodeSchema, isDragNodeObject, isDragNodeDataObject, isLocationChildrenDetail, Logger } from '@alilc/lowcode-utils'; import { megreAssets, IPublicTypeAssetsJson, isNodeSchema, isDragNodeObject, isDragNodeDataObject, isLocationChildrenDetail, Logger } from '@alilc/lowcode-utils';
import { Project } from '../project'; import { Project } from '../project';
import { Node, DocumentModel, insertChildren, INode } from '../document'; import { Node, DocumentModel, insertChildren, INode } from '../document';
import { ComponentMeta } 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, ILocateEvent } from './dragon'; import { Dragon, IDragon, ILocateEvent } from './dragon';
import { ActiveTracker } from './active-tracker'; import { ActiveTracker, IActiveTracker } 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';
@ -56,24 +55,49 @@ export interface DesignerProps {
onMount?: (designer: Designer) => void; onMount?: (designer: Designer) => void;
onDragstart?: (e: ILocateEvent) => void; onDragstart?: (e: ILocateEvent) => void;
onDrag?: (e: ILocateEvent) => void; onDrag?: (e: ILocateEvent) => void;
onDragend?: (e: { dragObject: IPublicModelDragObject; copy: boolean }, loc?: DropLocation) => void; onDragend?: (
e: { dragObject: IPublicModelDragObject; copy: boolean },
loc?: DropLocation,
) => void;
} }
export interface IDesigner { export interface IDesigner {
get dragon(): IPublicModelDragon; get dragon(): IPublicModelDragon;
get activeTracker(): IPublicModelActiveTracker;
get activeTracker(): IActiveTracker;
get componentActions(): ComponentActions;
get editor(): IPublicModelEditor;
createScroller(scrollable: IPublicModelScrollable): IPublicModelScroller; createScroller(scrollable: IPublicModelScrollable): IPublicModelScroller;
/** /**
* dragon * dragon
*/ */
createLocation(locationData: IPublicTypeLocationData): IPublicModelDropLocation; createLocation(locationData: IPublicTypeLocationData): IPublicModelDropLocation;
get componentsMap(): { [key: string]: IPublicTypeNpmInfo | Component };
loadIncrementalAssets(incrementalAssets: IPublicTypeAssetsJson): Promise<void>;
getComponentMeta(
componentName: string,
generateMetadata?: () => IPublicTypeComponentMetadata | null,
): IComponentMeta;
createComponentMeta(data: IPublicTypeComponentMetadata): IComponentMeta | null;
getComponentMetasMap(): Map<string, IComponentMeta>;
addPropsReducer(reducer: IPublicTypePropsTransducer, stage: IPublicEnumTransformStage): void;
} }
export class Designer implements IDesigner { export class Designer implements IDesigner {
public dragon: Dragon; dragon: IDragon;
public viewName: string | undefined; viewName: string | undefined;
readonly componentActions = new ComponentActions(); readonly componentActions = new ComponentActions();
@ -99,7 +123,7 @@ export class Designer implements IDesigner {
private oobxList: OffsetObserver[] = []; private oobxList: OffsetObserver[] = [];
@obx.ref private _componentMetasMap = new Map<string, ComponentMeta>(); @obx.ref private _componentMetasMap = new Map<string, IComponentMeta>();
@obx.ref private _simulatorComponent?: ComponentType<any>; @obx.ref private _simulatorComponent?: ComponentType<any>;
@ -483,7 +507,7 @@ export class Designer implements IDesigner {
metas.forEach((data) => this.createComponentMeta(data)); metas.forEach((data) => this.createComponentMeta(data));
} }
createComponentMeta(data: IPublicTypeComponentMetadata): ComponentMeta | null { createComponentMeta(data: IPublicTypeComponentMetadata): IComponentMeta | null {
const key = data.componentName; const key = data.componentName;
if (!key) { if (!key) {
return null; return null;
@ -515,7 +539,7 @@ export class Designer implements IDesigner {
getComponentMeta( getComponentMeta(
componentName: string, componentName: string,
generateMetadata?: () => IPublicTypeComponentMetadata | null, generateMetadata?: () => IPublicTypeComponentMetadata | null,
) { ): IComponentMeta {
if (this._componentMetasMap.has(componentName)) { if (this._componentMetasMap.has(componentName)) {
return this._componentMetasMap.get(componentName)!; return this._componentMetasMap.get(componentName)!;
} }

View File

@ -1,14 +1,18 @@
import { makeObservable, obx, IEventBus, createModuleEventBus } from '@alilc/lowcode-editor-core'; import { makeObservable, obx, IEventBus, createModuleEventBus } from '@alilc/lowcode-editor-core';
import { IPublicModelDetecting, IPublicModelNode, IPublicModelDocumentModel } from '@alilc/lowcode-types'; import { IPublicModelDetecting } from '@alilc/lowcode-types';
import { IDocumentModel } from '../document/document-model';
import { INode } from '../document/node/node';
const DETECTING_CHANGE_EVENT = 'detectingChange'; const DETECTING_CHANGE_EVENT = 'detectingChange';
export interface IDetecting extends Omit< IPublicModelDetecting, 'capture' | 'release' | 'leave' > { export interface IDetecting extends Omit< IPublicModelDetecting, 'capture' | 'release' | 'leave' > {
capture(node: IPublicModelNode | null): void; capture(node: INode | null): void;
release(node: IPublicModelNode | null): void; release(node: INode | null): void;
leave(document: IPublicModelDocumentModel | undefined): void; leave(document: IDocumentModel | undefined): void;
get current(): INode | null;
} }
export class Detecting implements IDetecting { export class Detecting implements IDetecting {
@ -31,7 +35,7 @@ export class Detecting implements IDetecting {
@obx.ref xRayMode = false; @obx.ref xRayMode = false;
@obx.ref private _current: IPublicModelNode | null = null; @obx.ref private _current: INode | null = null;
private emitter: IEventBus = createModuleEventBus('Detecting'); private emitter: IEventBus = createModuleEventBus('Detecting');
@ -43,27 +47,27 @@ export class Detecting implements IDetecting {
return this._current; return this._current;
} }
capture(node: IPublicModelNode | null) { capture(node: INode | null) {
if (this._current !== node) { if (this._current !== node) {
this._current = node; this._current = node;
this.emitter.emit(DETECTING_CHANGE_EVENT, this.current); this.emitter.emit(DETECTING_CHANGE_EVENT, this.current);
} }
} }
release(node: IPublicModelNode | null) { release(node: INode | null) {
if (this._current === node) { if (this._current === node) {
this._current = null; this._current = null;
this.emitter.emit(DETECTING_CHANGE_EVENT, this.current); this.emitter.emit(DETECTING_CHANGE_EVENT, this.current);
} }
} }
leave(document: IPublicModelDocumentModel | undefined) { leave(document: IDocumentModel | undefined) {
if (this.current && this.current.document === document) { if (this.current && this.current.document === document) {
this._current = null; this._current = null;
} }
} }
onDetectingChange(fn: (node: IPublicModelNode) => void) { onDetectingChange(fn: (node: INode) => void) {
this.emitter.on(DETECTING_CHANGE_EVENT, fn); this.emitter.on(DETECTING_CHANGE_EVENT, fn);
return () => { return () => {
this.emitter.off(DETECTING_CHANGE_EVENT, fn); this.emitter.off(DETECTING_CHANGE_EVENT, fn);

View File

@ -9,21 +9,18 @@ import {
IPublicTypeDragNodeDataObject, IPublicTypeDragNodeDataObject,
IPublicModelDocumentModel, IPublicModelDocumentModel,
IPublicModelHistory, IPublicModelHistory,
IPublicModelModalNodesManager,
IPublicModelNode, IPublicModelNode,
IPublicApiProject,
IPublicModelDropLocation,
IPublicEnumTransformStage, IPublicEnumTransformStage,
IPublicTypeOnChangeOptions, IPublicTypeOnChangeOptions,
} from '@alilc/lowcode-types'; } from '@alilc/lowcode-types';
import { Project } from '../project'; import { IProject, Project } from '../project';
import { ISimulatorHost } from '../simulator'; import { ISimulatorHost } from '../simulator';
import { ComponentMeta } from '../component-meta'; import { ComponentMeta } from '../component-meta';
import { IDropLocation, Designer } from '../designer'; import { IDropLocation, Designer, IHistory } from '../designer';
import { Node, insertChildren, insertChild, isNode, RootNode, INode } from './node/node'; import { Node, insertChildren, insertChild, isNode, RootNode, INode } from './node/node';
import { Selection, ISelection } from './selection'; import { Selection, ISelection } from './selection';
import { History } from './history'; import { History } from './history';
import { ModalNodesManager } from './node'; import { IModalNodesManager, ModalNodesManager } from './node';
import { uniqueId, isPlainObject, compatStage, isJSExpression, isDOMText, isNodeSchema, isDragNodeObject, isDragNodeDataObject } from '@alilc/lowcode-utils'; import { uniqueId, isPlainObject, compatStage, isJSExpression, isDOMText, isNodeSchema, isDragNodeObject, isDragNodeDataObject } from '@alilc/lowcode-utils';
import { EDITOR_EVENT } from '../types'; import { EDITOR_EVENT } from '../types';
@ -44,17 +41,31 @@ export interface IDocumentModel extends Omit< IPublicModelDocumentModel, 'select
*/ */
readonly selection: ISelection; readonly selection: ISelection;
readonly project: IProject;
/**
*
*/
readonly modalNodesManager: IModalNodesManager;
/** /**
* id * id
*/ */
getNode(id: string): INode | null; getNode(id: string): INode | null;
getHistory(): IHistory;
get focusNode(): INode | null;
get rootNode(): INode | null;
} }
export class DocumentModel implements IDocumentModel { export class DocumentModel implements IDocumentModel {
/** /**
* Page/Component/Block * Page/Component/Block
*/ */
rootNode: RootNode | null; rootNode: INode | null;
/** /**
* *
@ -74,11 +85,11 @@ export class DocumentModel implements IDocumentModel {
/** /**
* *
*/ */
readonly modalNodesManager: IPublicModelModalNodesManager; readonly modalNodesManager: IModalNodesManager;
private _nodesMap = new Map<string, IPublicModelNode>(); private _nodesMap = new Map<string, IPublicModelNode>();
readonly project: IPublicApiProject; readonly project: IProject;
readonly designer: Designer; readonly designer: Designer;
@ -114,7 +125,7 @@ export class DocumentModel implements IDocumentModel {
this.rootNode?.getExtraProp('fileName', true)?.setValue(fileName); this.rootNode?.getExtraProp('fileName', true)?.setValue(fileName);
} }
get focusNode() { get focusNode(): INode {
if (this._drillDownNode) { if (this._drillDownNode) {
return this._drillDownNode; return this._drillDownNode;
} }
@ -147,7 +158,7 @@ export class DocumentModel implements IDocumentModel {
@obx.ref private _dropLocation: IDropLocation | null = null; @obx.ref private _dropLocation: IDropLocation | null = null;
set dropLocation(loc: IPublicModelDropLocation | null) { set dropLocation(loc: IDropLocation | null) {
this._dropLocation = loc; this._dropLocation = loc;
// pub event // pub event
this.designer.editor.eventBus.emit( this.designer.editor.eventBus.emit(
@ -626,7 +637,7 @@ export class DocumentModel implements IDocumentModel {
return data; return data;
} }
getHistory(): History { getHistory(): IHistory {
return this.history; return this.history;
} }

View File

@ -193,7 +193,7 @@ export class History<T = IPublicTypeNodeSchema> implements IHistory {
return this.onStateChange(func); return this.onStateChange(func);
} }
onStateChange(func: () => any) { onStateChange(func: () => any): () => void {
this.emitter.on('statechange', func); this.emitter.on('statechange', func);
return () => { return () => {
this.emitter.removeListener('statechange', func); this.emitter.removeListener('statechange', func);
@ -208,7 +208,8 @@ export class History<T = IPublicTypeNodeSchema> implements IHistory {
onChangeCursor(func: () => any): () => void { onChangeCursor(func: () => any): () => void {
return this.onCursor(func); return this.onCursor(func);
} }
onCursor(func: () => any) {
onCursor(func: () => any): () => void {
this.emitter.on('cursor', func); this.emitter.on('cursor', func);
return () => { return () => {
this.emitter.removeListener('cursor', func); this.emitter.removeListener('cursor', func);

View File

@ -11,7 +11,10 @@ export interface IOnChangeOptions {
} }
export interface INodeChildren extends Omit<IPublicModelNodeChildren, 'forEach' | 'map' | 'every' | 'some' | 'filter' | 'find' | 'reduce' | 'mergeChildren' > { export interface INodeChildren extends Omit<IPublicModelNodeChildren, 'forEach' | 'map' | 'every' | 'some' | 'filter' | 'find' | 'reduce' | 'mergeChildren' > {
get owner(): INode;
unlinkChild(node: INode): void; unlinkChild(node: INode): void;
/** /**
* *
*/ */
@ -57,6 +60,11 @@ export interface INodeChildren extends Omit<IPublicModelNodeChildren, 'forEach'
sorter: (firstNode: INode, secondNode: INode) => number, sorter: (firstNode: INode, secondNode: INode) => number,
): any; ): any;
/**
*
*/
get(index: number): INode | null;
/** overriding methods end */ /** overriding methods end */
} }
export class NodeChildren implements INodeChildren { export class NodeChildren implements INodeChildren {
@ -64,6 +72,31 @@ export class NodeChildren implements INodeChildren {
private emitter: IEventBus = createModuleEventBus('NodeChildren'); private emitter: IEventBus = createModuleEventBus('NodeChildren');
/**
*
*/
@computed get size(): number {
return this.children.length;
}
get isEmptyNode(): boolean {
return this.size < 1;
}
get notEmptyNode(): boolean {
return this.size > 0;
}
@computed get length(): number {
return this.children.length;
}
private purged = false;
get [Symbol.toStringTag]() {
// 保证向前兼容性
return 'Array';
}
constructor( constructor(
readonly owner: INode, readonly owner: INode,
data: IPublicTypeNodeData | IPublicTypeNodeData[], data: IPublicTypeNodeData | IPublicTypeNodeData[],
@ -130,13 +163,6 @@ export class NodeChildren implements INodeChildren {
return this.children.concat(nodes); return this.children.concat(nodes);
} }
/**
*
*/
@computed get size(): number {
return this.children.length;
}
/** /**
* *
*/ */
@ -144,24 +170,10 @@ export class NodeChildren implements INodeChildren {
return this.isEmptyNode; return this.isEmptyNode;
} }
get isEmptyNode(): boolean {
return this.size < 1;
}
notEmpty() { notEmpty() {
return this.notEmptyNode; return this.notEmptyNode;
} }
get notEmptyNode(): boolean {
return this.size > 0;
}
@computed get length(): number {
return this.children.length;
}
private purged = false;
/** /**
* *
*/ */
@ -483,11 +495,6 @@ export class NodeChildren implements INodeChildren {
}; };
} }
get [Symbol.toStringTag]() {
// 保证向前兼容性
return 'Array';
}
private reportModified(node: INode, owner: INode, options = {}) { private reportModified(node: INode, owner: INode, options = {}) {
if (!node) { if (!node) {
return; return;

View File

@ -18,11 +18,11 @@ import {
} from '@alilc/lowcode-types'; } from '@alilc/lowcode-types';
import { compatStage, isDOMText, isJSExpression } from '@alilc/lowcode-utils'; import { compatStage, isDOMText, isJSExpression } from '@alilc/lowcode-utils';
import { SettingTopEntry } from '@alilc/lowcode-designer'; import { SettingTopEntry } from '@alilc/lowcode-designer';
import { Props, getConvertedExtraKey } from './props/props'; import { Props, getConvertedExtraKey, IProps } from './props/props';
import { DocumentModel, IDocumentModel } from '../document-model'; import { DocumentModel, IDocumentModel } from '../document-model';
import { NodeChildren, INodeChildren } from './node-children'; import { NodeChildren, INodeChildren } from './node-children';
import { Prop } from './props/prop'; import { IProp, Prop } from './props/prop';
import { ComponentMeta } from '../../component-meta'; import { ComponentMeta, IComponentMeta } from '../../component-meta';
import { ExclusiveGroup, isExclusiveGroup } from './exclusive-group'; import { ExclusiveGroup, isExclusiveGroup } from './exclusive-group';
import { includeSlot, removeSlot } from '../../utils/slot'; import { includeSlot, removeSlot } from '../../utils/slot';
import { foreachReverse } from '../../utils/tree'; import { foreachReverse } from '../../utils/tree';
@ -41,6 +41,34 @@ export interface INode extends IPublicModelNode {
*/ */
get children(): INodeChildren | null; get children(): INodeChildren | null;
/**
*
*/
get prevSibling(): INode | null;
/**
*
*/
get nextSibling(): INode | null;
/**
*
*/
get parent(): INode | null;
get slots(): INode[];
/**
*
*/
get slotFor(): IProp | null;
get props(): IProps;
get componentMeta(): IComponentMeta;
get document(): IDocumentModel;
setVisible(flag: boolean): void; setVisible(flag: boolean): void;
getVisible(): boolean; getVisible(): boolean;
@ -66,8 +94,6 @@ export interface INode extends IPublicModelNode {
*/ */
export(stage: IPublicEnumTransformStage, options?: any): IPublicTypeNodeSchema; export(stage: IPublicEnumTransformStage, options?: any): IPublicTypeNodeSchema;
get document(): IDocumentModel;
emitPropChange(val: IPublicTypePropChangeOptions): void; emitPropChange(val: IPublicTypePropChangeOptions): void;
import(data: IPublicTypeNodeSchema, checkId?: boolean): void; import(data: IPublicTypeNodeSchema, checkId?: boolean): void;
@ -76,9 +102,13 @@ export interface INode extends IPublicModelNode {
addSlot(slotNode: INode): void; addSlot(slotNode: INode): void;
get componentMeta(): ComponentMeta;
onVisibleChange(func: (flag: boolean) => any): () => void; onVisibleChange(func: (flag: boolean) => any): () => void;
getProp(path: string, createIfNone?: boolean): IProp | null;
getExtraProp(key: string, createIfNone?: boolean): IProp | null;
replaceChild(node: INode, data: any): INode;
} }
/** /**
@ -157,7 +187,7 @@ export class Node<Schema extends IPublicTypeNodeSchema = IPublicTypeNodeSchema>
/** /**
* *
*/ */
props: Props; props: IProps;
protected _children?: INodeChildren; protected _children?: INodeChildren;
@ -241,11 +271,11 @@ export class Node<Schema extends IPublicTypeNodeSchema = IPublicTypeNodeSchema>
return !!this._isRGLContainer; return !!this._isRGLContainer;
} }
private _slotFor?: Prop | null = null; private _slotFor?: IProp | null = null;
@obx.shallow _slots: INode[] = []; @obx.shallow _slots: INode[] = [];
get slots() { get slots(): INode[] {
return this._slots; return this._slots;
} }
@ -509,7 +539,7 @@ export class Node<Schema extends IPublicTypeNodeSchema = IPublicTypeNodeSchema>
/** /**
* *
*/ */
get slotFor() { get slotFor(): IProp | null {
return this._slotFor; return this._slotFor;
} }
@ -665,10 +695,10 @@ export class Node<Schema extends IPublicTypeNodeSchema = IPublicTypeNodeSchema>
/** /**
* *
* *
* @param {Node} node * @param {INode} node
* @param {object} data * @param {object} data
*/ */
replaceChild(node: Node, data: any): Node { replaceChild(node: INode, data: any): INode {
if (this.children?.has(node)) { if (this.children?.has(node)) {
const selected = this.document.selection.has(node.id); const selected = this.document.selection.has(node.id);
@ -703,11 +733,11 @@ export class Node<Schema extends IPublicTypeNodeSchema = IPublicTypeNodeSchema>
}; };
} }
getProp(path: string, createIfNone = true): Prop | null { getProp(path: string, createIfNone = true): IProp | null {
return this.props.query(path, createIfNone) || null; return this.props.query(path, createIfNone) || null;
} }
getExtraProp(key: string, createIfNone = true): Prop | null { getExtraProp(key: string, createIfNone = true): IProp | null {
return this.props.get(getConvertedExtraKey(key), createIfNone) || null; return this.props.get(getConvertedExtraKey(key), createIfNone) || null;
} }
@ -767,7 +797,7 @@ export class Node<Schema extends IPublicTypeNodeSchema = IPublicTypeNodeSchema>
/** /**
* *
*/ */
get nextSibling(): Node | null { get nextSibling(): INode | null {
if (!this.parent) { if (!this.parent) {
return null; return null;
} }
@ -781,7 +811,7 @@ export class Node<Schema extends IPublicTypeNodeSchema = IPublicTypeNodeSchema>
/** /**
* *
*/ */
get prevSibling(): Node | null { get prevSibling(): INode | null {
if (!this.parent) { if (!this.parent) {
return null; return null;
} }

View File

@ -1,6 +1,6 @@
import { obx, computed, makeObservable, action, IEventBus, createModuleEventBus } from '@alilc/lowcode-editor-core'; import { obx, computed, makeObservable, action, IEventBus, createModuleEventBus } from '@alilc/lowcode-editor-core';
import { Designer } from '../designer'; import { IDesigner } from '../designer';
import { DocumentModel, isDocumentModel } from '../document'; import { DocumentModel, IDocumentModel, isDocumentModel } from '../document';
import { import {
IPublicTypeProjectSchema, IPublicTypeProjectSchema,
IPublicTypeRootSchema, IPublicTypeRootSchema,
@ -12,14 +12,60 @@ import {
import { isLowCodeComponentType, isProCodeComponentType } from '@alilc/lowcode-utils'; import { isLowCodeComponentType, isProCodeComponentType } from '@alilc/lowcode-utils';
import { ISimulatorHost } from '../simulator'; import { ISimulatorHost } from '../simulator';
export interface IProject extends IPublicApiProject { export interface IProject extends Omit< IPublicApiProject, 'simulatorHost' | 'importSchema' | 'exportSchema' | 'openDocument' | 'getDocumentById' | 'getCurrentDocument' | 'addPropsTransducer' | 'onRemoveDocument' | 'onChangeDocument' | 'onSimulatorHostReady' | 'onSimulatorRendererReady' | 'setI18n' > {
get designer(): IDesigner;
get simulator(): ISimulatorHost | null;
get currentDocument(): IDocumentModel | null;
get documents(): IDocumentModel[];
open(doc?: string | IDocumentModel | IPublicTypeRootSchema): IDocumentModel | null;
getDocumentByFileName(fileName: string): IDocumentModel | null;
createDocument(data?: IPublicTypeRootSchema): IDocumentModel;
load(schema?: IPublicTypeProjectSchema, autoOpen?: boolean | string): void;
getSchema(
stage: IPublicEnumTransformStage,
): IPublicTypeProjectSchema;
getDocument(id: string): IDocumentModel | null;
onCurrentDocumentChange(fn: (doc: IDocumentModel) => void): () => void;
onSimulatorReady(fn: (args: any) => void): () => void;
onRendererReady(fn: () => void): () => void;
/**
*
*/
set(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
key:
| 'version'
| 'componentsTree'
| 'componentsMap'
| 'utils'
| 'constants'
| 'i18n'
| 'css'
| 'dataSource'
| string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
value: any,
): void;
} }
export class Project implements IProject { export class Project implements IProject {
private emitter: IEventBus = createModuleEventBus('Project'); private emitter: IEventBus = createModuleEventBus('Project');
@obx.shallow readonly documents: IPublicModelDocumentModel[] = []; @obx.shallow readonly documents: IDocumentModel[] = [];
private data: IPublicTypeProjectSchema = { private data: IPublicTypeProjectSchema = {
version: '1.0.0', version: '1.0.0',
@ -41,14 +87,7 @@ export class Project implements IProject {
key = Math.random(); key = Math.random();
// TODO: 考虑项目级别 History @computed get currentDocument(): IDocumentModel | null {
constructor(readonly designer: Designer, schema?: IPublicTypeProjectSchema, readonly viewName = 'global') {
makeObservable(this);
this.load(schema);
}
@computed get currentDocument() {
return this.documents.find((doc) => doc.active); return this.documents.find((doc) => doc.active);
} }
@ -69,6 +108,13 @@ export class Project implements IProject {
this._i18n = value || {}; this._i18n = value || {};
} }
private documentsMap = new Map<string, DocumentModel>();
constructor(readonly designer: IDesigner, schema?: IPublicTypeProjectSchema, readonly viewName = 'global') {
makeObservable(this);
this.load(schema);
}
private getComponentsMap(): IPublicTypeComponentsMap { private getComponentsMap(): IPublicTypeComponentsMap {
return this.documents.reduce(( return this.documents.reduce((
compomentsMap: IPublicTypeComponentsMap, compomentsMap: IPublicTypeComponentsMap,
@ -104,7 +150,9 @@ export class Project implements IProject {
/** /**
* schema * schema
*/ */
getSchema(stage: IPublicEnumTransformStage = IPublicEnumTransformStage.Save): IPublicTypeProjectSchema { getSchema(
stage: IPublicEnumTransformStage = IPublicEnumTransformStage.Save,
): IPublicTypeProjectSchema {
return { return {
...this.data, ...this.data,
componentsMap: this.getComponentsMap(), componentsMap: this.getComponentsMap(),
@ -240,26 +288,24 @@ export class Project implements IProject {
return Reflect.get(this.data, key); return Reflect.get(this.data, key);
} }
private documentsMap = new Map<string, DocumentModel>(); getDocument(id: string): IDocumentModel | null {
getDocument(id: string): DocumentModel | null {
// 此处不能使用 this.documentsMap.get(id),因为在乐高 rollback 场景document.id 会被改成其他值 // 此处不能使用 this.documentsMap.get(id),因为在乐高 rollback 场景document.id 会被改成其他值
return this.documents.find((doc) => doc.id === id) || null; return this.documents.find((doc) => doc.id === id) || null;
} }
getDocumentByFileName(fileName: string): DocumentModel | null { getDocumentByFileName(fileName: string): IDocumentModel | null {
return this.documents.find((doc) => doc.fileName === fileName) || null; return this.documents.find((doc) => doc.fileName === fileName) || null;
} }
@action @action
createDocument(data?: IPublicTypeRootSchema): DocumentModel { createDocument(data?: IPublicTypeRootSchema): IDocumentModel {
const doc = new DocumentModel(this, data || this?.data?.componentsTree?.[0]); const doc = new DocumentModel(this, data || this?.data?.componentsTree?.[0]);
this.documents.push(doc); this.documents.push(doc);
this.documentsMap.set(doc.id, doc); this.documentsMap.set(doc.id, doc);
return doc; return doc;
} }
open(doc?: string | DocumentModel | IPublicTypeRootSchema): DocumentModel | null { open(doc?: string | IDocumentModel | IPublicTypeRootSchema): IDocumentModel | null {
if (!doc) { if (!doc) {
const got = this.documents.find((item) => item.isBlank()); const got = this.documents.find((item) => item.isBlank());
if (got) { if (got) {
@ -341,7 +387,7 @@ export class Project implements IProject {
}; };
} }
onCurrentDocumentChange(fn: (doc: DocumentModel) => void): () => void { onCurrentDocumentChange(fn: (doc: IDocumentModel) => void): () => void {
this.emitter.on('current-document.change', fn); this.emitter.on('current-document.change', fn);
return () => { return () => {
this.emitter.removeListener('current-document.change', fn); this.emitter.removeListener('current-document.change', fn);

View File

@ -1,6 +1,6 @@
import { isEqual } from 'lodash'; import { isEqual } from 'lodash';
import { globalContext } from './di'; import { globalContext } from './di';
import { IPublicTypeHotkeyCallback, IPublicApiHotkey } from '@alilc/lowcode-types'; import { IPublicTypeHotkeyCallback, IPublicTypeHotkeyCallbackConfig, IPublicTypeHotkeyCallbacks, IPublicApiHotkey } from '@alilc/lowcode-types';
interface KeyMap { interface KeyMap {
[key: number]: string; [key: number]: string;
@ -14,23 +14,10 @@ interface ActionEvent {
type: string; type: string;
} }
interface IPublicTypeHotkeyCallbacks {
[key: string]: IPublicTypeHotkeyCallbackCfg[];
}
interface HotkeyDirectMap { interface HotkeyDirectMap {
[key: string]: IPublicTypeHotkeyCallback; [key: string]: IPublicTypeHotkeyCallback;
} }
interface IPublicTypeHotkeyCallbackCfg {
callback: IPublicTypeHotkeyCallback;
modifiers: string[];
action: string;
seq?: string;
level?: number;
combo?: string;
}
interface KeyInfo { interface KeyInfo {
key: string; key: string;
modifiers: string[]; modifiers: string[];
@ -444,10 +431,10 @@ export class Hotkey implements IHotKey {
sequenceName?: string, sequenceName?: string,
combination?: string, combination?: string,
level?: number, level?: number,
): IPublicTypeHotkeyCallbackCfg[] { ): IPublicTypeHotkeyCallbackConfig[] {
let i: number; let i: number;
let callback: IPublicTypeHotkeyCallbackCfg; let callback: IPublicTypeHotkeyCallbackConfig;
const matches: IPublicTypeHotkeyCallbackCfg[] = []; const matches: IPublicTypeHotkeyCallbackConfig[] = [];
const action: string = e.type; const action: string = e.type;
// if there are no events related to this keycode // if there are no events related to this keycode
@ -498,7 +485,7 @@ export class Hotkey implements IHotKey {
} }
private handleKey(character: string, modifiers: string[], e: KeyboardEvent): void { private handleKey(character: string, modifiers: string[], e: KeyboardEvent): void {
const callbacks: IPublicTypeHotkeyCallbackCfg[] = this.getMatches(character, modifiers, e); const callbacks: IPublicTypeHotkeyCallbackConfig[] = this.getMatches(character, modifiers, e);
let i: number; let i: number;
const doNotReset: SequenceLevels = {}; const doNotReset: SequenceLevels = {};
let maxLevel = 0; let maxLevel = 0;

View File

@ -14,9 +14,11 @@ import {
IDesigner, IDesigner,
} from '@alilc/lowcode-designer'; } from '@alilc/lowcode-designer';
import { editorSymbol, designerSymbol, nodeSymbol } from '../symbols'; import { editorSymbol, designerSymbol, nodeSymbol } from '../symbols';
import { Dragon } from '../model'; import {
import { DropLocation } from '../model/drop-location'; Dragon as ShellDragon,
import { ActiveTracker } from '../model/active-tracker'; DropLocation as ShellDropLocation,
ActiveTracker as ShellActiveTracker,
} from '../model';
export class Canvas implements IPublicApiCanvas { export class Canvas implements IPublicApiCanvas {
private readonly [editorSymbol]: IPublicModelEditor; private readonly [editorSymbol]: IPublicModelEditor;
@ -25,6 +27,15 @@ export class Canvas implements IPublicApiCanvas {
return this[editorSymbol].get('designer') as IDesigner; return this[editorSymbol].get('designer') as IDesigner;
} }
get dragon(): IPublicModelDragon | null {
return ShellDragon.create(this[designerSymbol].dragon, this.workspaceMode);
}
get activeTracker(): IPublicModelActiveTracker | null {
const activeTracker = new ShellActiveTracker(this[designerSymbol].activeTracker);
return activeTracker;
}
constructor(editor: IPublicModelEditor, readonly workspaceMode: boolean = false) { constructor(editor: IPublicModelEditor, readonly workspaceMode: boolean = false) {
this[editorSymbol] = editor; this[editorSymbol] = editor;
} }
@ -47,19 +58,10 @@ export class Canvas implements IPublicApiCanvas {
}); });
} }
get dragon(): IPublicModelDragon | null {
return Dragon.create(this[designerSymbol].dragon, this.workspaceMode);
}
get activeTracker(): IPublicModelActiveTracker | null {
const activeTracker = new ActiveTracker(this[designerSymbol].activeTracker);
return activeTracker;
}
/** /**
* @deprecated * @deprecated
*/ */
get dropLocation() { get dropLocation() {
return DropLocation.create((this[designerSymbol] as any).dropLocation || null); return ShellDropLocation.create((this[designerSymbol] as any).dropLocation || null);
} }
} }

View File

@ -58,7 +58,7 @@ import {
computed as innerComputed, computed as innerComputed,
observer as innerObserver, observer as innerObserver,
} from '@alilc/lowcode-editor-core'; } from '@alilc/lowcode-editor-core';
import { Dragon } from '../model'; import { Dragon as ShellDragon } from '../model';
import { ReactNode, Component } from 'react'; import { ReactNode, Component } from 'react';
class DesignerCabin implements IPublicApiCommonDesignerCabin { class DesignerCabin implements IPublicApiCommonDesignerCabin {
@ -149,7 +149,7 @@ class DesignerCabin implements IPublicApiCommonDesignerCabin {
* @deprecated please use canvas.dragon * @deprecated please use canvas.dragon
*/ */
get dragon(): IPublicModelDragon | null { get dragon(): IPublicModelDragon | null {
return Dragon.create(this[designerSymbol].dragon); return ShellDragon.create(this[designerSymbol].dragon, false);
} }
} }

View File

@ -14,12 +14,6 @@ export class Event implements IPublicApiEvent {
private readonly [eventBusSymbol]: EventBus; private readonly [eventBusSymbol]: EventBus;
private readonly options: EventOptions; private readonly options: EventOptions;
// TODO:
/**
*
*/
readonly names = [];
constructor(eventBus: EventBus, options: EventOptions, public workspaceMode = false) { constructor(eventBus: EventBus, options: EventOptions, public workspaceMode = false) {
this[eventBusSymbol] = eventBus; this[eventBusSymbol] = eventBus;
this.options = options; this.options = options;

View File

@ -1,6 +1,6 @@
import { globalContext, Hotkey as InnerHotkey } from '@alilc/lowcode-editor-core'; import { globalContext, Hotkey as InnerHotkey } from '@alilc/lowcode-editor-core';
import { hotkeySymbol } from '../symbols'; import { hotkeySymbol } from '../symbols';
import { IPublicTypeDisposable, IPublicTypeHotkeyCallback, IPublicApiHotkey } from '@alilc/lowcode-types'; import { IPublicTypeDisposable, IPublicTypeHotkeyCallback, IPublicTypeHotkeyCallbacks, IPublicApiHotkey } from '@alilc/lowcode-types';
const innerHotkeySymbol = Symbol('innerHotkey'); const innerHotkeySymbol = Symbol('innerHotkey');
@ -22,15 +22,17 @@ export class Hotkey implements IPublicApiHotkey {
this[innerHotkeySymbol] = hotkey; this[innerHotkeySymbol] = hotkey;
} }
get callbacks(): any { get callbacks(): IPublicTypeHotkeyCallbacks {
return this[hotkeySymbol].callBacks; return this[hotkeySymbol].callBacks;
} }
/** /**
* @deprecated * @deprecated
*/ */
get callBacks() { get callBacks() {
return this.callbacks; return this.callbacks;
} }
/** /**
* *
* @param combos ['command + s'] ['ctrl + shift + s'] * @param combos ['command + s'] ['ctrl + shift + s']
@ -38,7 +40,11 @@ export class Hotkey implements IPublicApiHotkey {
* @param action * @param action
* @returns * @returns
*/ */
bind(combos: string[] | string, callback: IPublicTypeHotkeyCallback, action?: string): IPublicTypeDisposable { bind(
combos: string[] | string,
callback: IPublicTypeHotkeyCallback,
action?: string,
): IPublicTypeDisposable {
this[hotkeySymbol].bind(combos, callback, action); this[hotkeySymbol].bind(combos, callback, action);
return () => { return () => {
this[hotkeySymbol].unbind(combos, callback, action); this[hotkeySymbol].unbind(combos, callback, action);

View File

@ -1,6 +1,6 @@
import { Editor, globalContext } from '@alilc/lowcode-editor-core'; import { globalContext } from '@alilc/lowcode-editor-core';
import { import {
Designer, IDesigner,
isComponentMeta, isComponentMeta,
} from '@alilc/lowcode-designer'; } from '@alilc/lowcode-designer';
import { IPublicTypeAssetsJson } from '@alilc/lowcode-utils'; import { IPublicTypeAssetsJson } from '@alilc/lowcode-utils';
@ -11,21 +11,22 @@ import {
IPublicTypeMetadataTransducer, IPublicTypeMetadataTransducer,
IPublicModelComponentMeta, IPublicModelComponentMeta,
IPublicTypeNpmInfo, IPublicTypeNpmInfo,
IPublicModelEditor,
} from '@alilc/lowcode-types'; } from '@alilc/lowcode-types';
import { Workspace } from '@alilc/lowcode-workspace'; import { Workspace as InnerWorkspace } from '@alilc/lowcode-workspace';
import { editorSymbol, designerSymbol } from '../symbols'; import { editorSymbol, designerSymbol } from '../symbols';
import { ComponentMeta } from '../model/component-meta'; import { ComponentMeta as ShellComponentMeta } from '../model';
import { ComponentType } from 'react'; import { ComponentType } from 'react';
const innerEditorSymbol = Symbol('editor'); const innerEditorSymbol = Symbol('editor');
export class Material implements IPublicApiMaterial { export class Material implements IPublicApiMaterial {
private readonly [innerEditorSymbol]: Editor; private readonly [innerEditorSymbol]: IPublicModelEditor;
get [editorSymbol](): Editor { get [editorSymbol](): IPublicModelEditor {
if (this.workspaceMode) { if (this.workspaceMode) {
return this[innerEditorSymbol]; return this[innerEditorSymbol];
} }
const workspace: Workspace = globalContext.get('workspace'); const workspace: InnerWorkspace = globalContext.get('workspace');
if (workspace.isActive) { if (workspace.isActive) {
return workspace.window.editor; return workspace.window.editor;
} }
@ -33,11 +34,11 @@ export class Material implements IPublicApiMaterial {
return this[innerEditorSymbol]; return this[innerEditorSymbol];
} }
get [designerSymbol](): Designer { get [designerSymbol](): IDesigner {
return this[editorSymbol].get('designer')!; return this[editorSymbol].get('designer')!;
} }
constructor(editor: Editor, readonly workspaceMode: boolean = false) { constructor(editor: IPublicModelEditor, readonly workspaceMode: boolean = false) {
this[innerEditorSymbol] = editor; this[innerEditorSymbol] = editor;
} }
@ -103,7 +104,7 @@ export class Material implements IPublicApiMaterial {
*/ */
getComponentMeta(componentName: string): IPublicModelComponentMeta | null { getComponentMeta(componentName: string): IPublicModelComponentMeta | null {
const innerMeta = this[designerSymbol].getComponentMeta(componentName); const innerMeta = this[designerSymbol].getComponentMeta(componentName);
return ComponentMeta.create(innerMeta); return ShellComponentMeta.create(innerMeta);
} }
/** /**
@ -112,7 +113,7 @@ export class Material implements IPublicApiMaterial {
* @returns * @returns
*/ */
createComponentMeta(metadata: IPublicTypeComponentMetadata) { createComponentMeta(metadata: IPublicTypeComponentMetadata) {
return ComponentMeta.create(this[designerSymbol].createComponentMeta(metadata)); return ShellComponentMeta.create(this[designerSymbol].createComponentMeta(metadata));
} }
/** /**
@ -158,7 +159,10 @@ export class Material implements IPublicApiMaterial {
* @param actionName * @param actionName
* @param handle * @param handle
*/ */
modifyBuiltinComponentAction(actionName: string, handle: (action: IPublicTypeComponentAction) => void) { modifyBuiltinComponentAction(
actionName: string,
handle: (action: IPublicTypeComponentAction) => void,
) {
this[designerSymbol].componentActions.modifyBuiltinComponentAction(actionName, handle); this[designerSymbol].componentActions.modifyBuiltinComponentAction(actionName, handle);
} }

View File

@ -9,7 +9,7 @@ import {
IPublicTypePluginRegisterOptions, IPublicTypePluginRegisterOptions,
IPublicTypePreferenceValueType, IPublicTypePreferenceValueType,
} from '@alilc/lowcode-types'; } from '@alilc/lowcode-types';
import { PluginInstance } from '../model/plugin-instance'; import { PluginInstance as ShellPluginInstance } from '../model';
import { pluginsSymbol } from '../symbols'; import { pluginsSymbol } from '../symbols';
const innerPluginsSymbol = Symbol('plugin'); const innerPluginsSymbol = Symbol('plugin');
@ -43,21 +43,23 @@ export class Plugins implements IPublicApiPlugins {
await this[pluginsSymbol].init(registerOptions); await this[pluginsSymbol].init(registerOptions);
} }
getPluginPreference(pluginName: string): Record<string, IPublicTypePreferenceValueType> | null | undefined { getPluginPreference(
pluginName: string,
): Record<string, IPublicTypePreferenceValueType> | null | undefined {
return this[pluginsSymbol].getPluginPreference(pluginName); return this[pluginsSymbol].getPluginPreference(pluginName);
} }
get(pluginName: string): IPublicModelPluginInstance | null { get(pluginName: string): IPublicModelPluginInstance | null {
const instance = this[pluginsSymbol].get(pluginName); const instance = this[pluginsSymbol].get(pluginName);
if (instance) { if (instance) {
return new PluginInstance(instance); return new ShellPluginInstance(instance);
} }
return null; return null;
} }
getAll() { getAll() {
return this[pluginsSymbol].getAll()?.map(d => new PluginInstance(d)); return this[pluginsSymbol].getAll()?.map((d) => new ShellPluginInstance(d));
} }
has(pluginName: string) { has(pluginName: string) {

View File

@ -1,6 +1,6 @@
import { import {
BuiltinSimulatorHost, BuiltinSimulatorHost,
Project as InnerProject, IProject as InnerProject,
} from '@alilc/lowcode-designer'; } from '@alilc/lowcode-designer';
import { globalContext } from '@alilc/lowcode-editor-core'; import { globalContext } from '@alilc/lowcode-editor-core';
import { import {
@ -14,9 +14,7 @@ import {
IPublicEnumTransformStage, IPublicEnumTransformStage,
IPublicTypeDisposable, IPublicTypeDisposable,
} from '@alilc/lowcode-types'; } from '@alilc/lowcode-types';
import { DocumentModel as ShellDocumentModel } from '../model';
import { DocumentModel } from '../model/document-model';
import { SimulatorHost } from './simulator-host'; import { SimulatorHost } from './simulator-host';
import { editorSymbol, projectSymbol, simulatorHostSymbol, documentSymbol } from '../symbols'; import { editorSymbol, projectSymbol, simulatorHostSymbol, documentSymbol } from '../symbols';
@ -61,7 +59,7 @@ export class Project implements IPublicApiProject {
* @returns * @returns
*/ */
get documents(): IPublicModelDocumentModel[] { get documents(): IPublicModelDocumentModel[] {
return this[projectSymbol].documents.map((doc) => DocumentModel.create(doc)!); return this[projectSymbol].documents.map((doc) => ShellDocumentModel.create(doc)!);
} }
/** /**
@ -85,8 +83,10 @@ export class Project implements IPublicApiProject {
*/ */
openDocument(doc?: string | IPublicTypeRootSchema | undefined) { openDocument(doc?: string | IPublicTypeRootSchema | undefined) {
const documentModel = this[projectSymbol].open(doc); const documentModel = this[projectSymbol].open(doc);
if (!documentModel) return null; if (!documentModel) {
return DocumentModel.create(documentModel); return null;
}
return ShellDocumentModel.create(documentModel);
} }
/** /**
@ -96,7 +96,7 @@ export class Project implements IPublicApiProject {
*/ */
createDocument(data?: IPublicTypeRootSchema): IPublicModelDocumentModel | null { createDocument(data?: IPublicTypeRootSchema): IPublicModelDocumentModel | null {
const doc = this[projectSymbol].createDocument(data); const doc = this[projectSymbol].createDocument(data);
return DocumentModel.create(doc); return ShellDocumentModel.create(doc);
} }
/** /**
@ -113,7 +113,8 @@ export class Project implements IPublicApiProject {
* @returns * @returns
*/ */
getDocumentByFileName(fileName: string): IPublicModelDocumentModel | null { getDocumentByFileName(fileName: string): IPublicModelDocumentModel | null {
return DocumentModel.create(this[projectSymbol].getDocumentByFileName(fileName)); const innerDocumentModel = this[projectSymbol].getDocumentByFileName(fileName);
return ShellDocumentModel.create(innerDocumentModel);
} }
/** /**
@ -122,7 +123,7 @@ export class Project implements IPublicApiProject {
* @returns * @returns
*/ */
getDocumentById(id: string): IPublicModelDocumentModel | null { getDocumentById(id: string): IPublicModelDocumentModel | null {
return DocumentModel.create(this[projectSymbol].getDocument(id)); return ShellDocumentModel.create(this[projectSymbol].getDocument(id));
} }
/** /**
@ -146,7 +147,7 @@ export class Project implements IPublicApiProject {
* @returns * @returns
*/ */
getCurrentDocument(): IPublicModelDocumentModel | null { getCurrentDocument(): IPublicModelDocumentModel | null {
return DocumentModel.create(this[projectSymbol].currentDocument); return ShellDocumentModel.create(this[projectSymbol].currentDocument);
} }
/** /**
@ -154,7 +155,10 @@ export class Project implements IPublicApiProject {
* @param transducer * @param transducer
* @param stage * @param stage
*/ */
addPropsTransducer(transducer: IPublicTypePropsTransducer, stage: IPublicEnumTransformStage): void { addPropsTransducer(
transducer: IPublicTypePropsTransducer,
stage: IPublicEnumTransformStage,
): void {
this[projectSymbol].designer.addPropsReducer(transducer, stage); this[projectSymbol].designer.addPropsReducer(transducer, stage);
} }
@ -175,10 +179,10 @@ export class Project implements IPublicApiProject {
*/ */
onChangeDocument(fn: (doc: IPublicModelDocumentModel) => void): IPublicTypeDisposable { onChangeDocument(fn: (doc: IPublicModelDocumentModel) => void): IPublicTypeDisposable {
const offFn = this[projectSymbol].onCurrentDocumentChange((originalDoc) => { const offFn = this[projectSymbol].onCurrentDocumentChange((originalDoc) => {
fn(DocumentModel.create(originalDoc)!); fn(ShellDocumentModel.create(originalDoc)!);
}); });
if (this[projectSymbol].currentDocument) { if (this[projectSymbol].currentDocument) {
fn(DocumentModel.create(this[projectSymbol].currentDocument)!); fn(ShellDocumentModel.create(this[projectSymbol].currentDocument)!);
} }
return offFn; return offFn;
} }

View File

@ -23,7 +23,11 @@ export class Skeleton implements IPublicApiSkeleton {
return this[innerSkeletonSymbol]; return this[innerSkeletonSymbol];
} }
constructor(skeleton: InnerSkeleton, pluginName: string, readonly workspaceMode: boolean = false) { constructor(
skeleton: InnerSkeleton,
pluginName: string,
readonly workspaceMode: boolean = false,
) {
this[innerSkeletonSymbol] = skeleton; this[innerSkeletonSymbol] = skeleton;
this.pluginName = pluginName; this.pluginName = pluginName;
} }

View File

@ -1,9 +1,8 @@
import { IPublicApiWorkspace, IPublicResourceList, IPublicTypeResourceType } from '@alilc/lowcode-types'; import { IPublicApiWorkspace, IPublicResourceList, IPublicTypeResourceType } from '@alilc/lowcode-types';
import { Workspace as InnerWorkSpace } from '@alilc/lowcode-workspace'; import { Workspace as InnerWorkSpace } from '@alilc/lowcode-workspace';
import { Plugins } from '@alilc/lowcode-shell'; import { Plugins } from '@alilc/lowcode-shell';
import { Window } from '../model/window';
import { workspaceSymbol } from '../symbols'; import { workspaceSymbol } from '../symbols';
import { Resource } from '../model'; import { Resource as ShellResource, Window as ShellWindow } from '../model';
export class Workspace implements IPublicApiWorkspace { export class Workspace implements IPublicApiWorkspace {
readonly [workspaceSymbol]: InnerWorkSpace; readonly [workspaceSymbol]: InnerWorkSpace;
@ -13,7 +12,7 @@ export class Workspace implements IPublicApiWorkspace {
} }
get resourceList() { get resourceList() {
return this[workspaceSymbol].getResourceList().map(d => new Resource(d)); return this[workspaceSymbol].getResourceList().map((d) => new ShellResource(d));
} }
setResourceList(resourceList: IPublicResourceList) { setResourceList(resourceList: IPublicResourceList) {
@ -29,14 +28,14 @@ export class Workspace implements IPublicApiWorkspace {
} }
get window() { get window() {
return new Window(this[workspaceSymbol].window); return new ShellWindow(this[workspaceSymbol].window);
} }
registerResourceType(resourceTypeModel: IPublicTypeResourceType): void { registerResourceType(resourceTypeModel: IPublicTypeResourceType): void {
this[workspaceSymbol].registerResourceType(resourceTypeModel); this[workspaceSymbol].registerResourceType(resourceTypeModel);
} }
openEditorWindow(resourceName: string, title: string, extra: Object, viewName?: string) { openEditorWindow(resourceName: string, title: string, extra: object, viewName?: string) {
this[workspaceSymbol].openEditorWindow(resourceName, title, extra, viewName); this[workspaceSymbol].openEditorWindow(resourceName, title, extra, viewName);
} }
@ -57,7 +56,7 @@ export class Workspace implements IPublicApiWorkspace {
} }
get windows() { get windows() {
return this[workspaceSymbol].windows.map(d => new Window(d)); return this[workspaceSymbol].windows.map((d) => new ShellWindow(d));
} }
onChangeWindows(fn: () => void) { onChangeWindows(fn: () => void) {

View File

@ -1,16 +1,14 @@
import { IPublicModelActiveTracker, IPublicModelNode, IPublicTypeActiveTarget } from '@alilc/lowcode-types'; import { IPublicModelActiveTracker, IPublicModelNode, IPublicTypeActiveTarget } from '@alilc/lowcode-types';
import { IActiveTracker } from '@alilc/lowcode-designer'; import { IActiveTracker as InnerActiveTracker, INode as InnerNode } from '@alilc/lowcode-designer';
import { Node } from './node'; import { Node as ShellNode } from './node';
import { nodeSymbol } from '../symbols'; import { nodeSymbol } from '../symbols';
const activeTrackerSymbol = Symbol('activeTracker'); const activeTrackerSymbol = Symbol('activeTracker');
export class ActiveTracker implements IPublicModelActiveTracker { export class ActiveTracker implements IPublicModelActiveTracker {
private readonly [activeTrackerSymbol]: IActiveTracker; private readonly [activeTrackerSymbol]: InnerActiveTracker;
constructor(innerTracker: InnerActiveTracker) {
constructor(innerTracker: IActiveTracker) {
this[activeTrackerSymbol] = innerTracker; this[activeTrackerSymbol] = innerTracker;
} }
@ -20,7 +18,7 @@ export class ActiveTracker implements IPublicModelActiveTracker {
} }
return this[activeTrackerSymbol].onChange((t: IPublicTypeActiveTarget) => { return this[activeTrackerSymbol].onChange((t: IPublicTypeActiveTarget) => {
const { node: innerNode, detail, instance } = t; const { node: innerNode, detail, instance } = t;
const publicNode = Node.create(innerNode); const publicNode = ShellNode.create(innerNode as InnerNode);
const publicActiveTarget = { const publicActiveTarget = {
node: publicNode!, node: publicNode!,
detail, detail,

View File

@ -1,5 +1,5 @@
import { import {
ComponentMeta as InnerComponentMeta, IComponentMeta as InnerComponentMeta,
INode, INode,
} from '@alilc/lowcode-designer'; } from '@alilc/lowcode-designer';
import { IPublicTypeNodeData, IPublicTypeNodeSchema, IPublicModelComponentMeta, IPublicTypeI18nData, IPublicTypeIconType, IPublicTypeNpmInfo, IPublicTypeTransformedComponentMetadata, IPublicModelNode } from '@alilc/lowcode-types'; import { IPublicTypeNodeData, IPublicTypeNodeSchema, IPublicModelComponentMeta, IPublicTypeI18nData, IPublicTypeIconType, IPublicTypeNpmInfo, IPublicTypeTransformedComponentMetadata, IPublicModelNode } from '@alilc/lowcode-types';
@ -9,6 +9,8 @@ import { ReactElement } from 'react';
export class ComponentMeta implements IPublicModelComponentMeta { export class ComponentMeta implements IPublicModelComponentMeta {
private readonly [componentMetaSymbol]: InnerComponentMeta; private readonly [componentMetaSymbol]: InnerComponentMeta;
isComponentMeta = true;
constructor(componentMeta: InnerComponentMeta) { constructor(componentMeta: InnerComponentMeta) {
this[componentMetaSymbol] = componentMeta; this[componentMetaSymbol] = componentMeta;
} }
@ -83,7 +85,7 @@ export class ComponentMeta implements IPublicModelComponentMeta {
* @deprecated * @deprecated
*/ */
get prototype() { get prototype() {
return this[componentMetaSymbol].prototype; return (this[componentMetaSymbol] as any).prototype;
} }
get availableActions(): any { get availableActions(): any {
@ -106,7 +108,6 @@ export class ComponentMeta implements IPublicModelComponentMeta {
return this[componentMetaSymbol].getMetadata(); return this[componentMetaSymbol].getMetadata();
} }
isComponentMeta = true;
/** /**
* check if the current node could be placed in parent node * check if the current node could be placed in parent node
* @param my * @param my
@ -124,9 +125,15 @@ export class ComponentMeta implements IPublicModelComponentMeta {
* @param parent * @param parent
* @returns * @returns
*/ */
checkNestingDown(my: IPublicModelNode | IPublicTypeNodeData, target: IPublicTypeNodeSchema | IPublicModelNode | IPublicTypeNodeSchema[]) { checkNestingDown(
my: IPublicModelNode | IPublicTypeNodeData,
target: IPublicTypeNodeSchema | IPublicModelNode | IPublicTypeNodeSchema[],
) {
const curNode = (my as any)?.isNode ? (my as any)[nodeSymbol] : my; const curNode = (my as any)?.isNode ? (my as any)[nodeSymbol] : my;
return this[componentMetaSymbol].checkNestingDown(curNode as any, (target as any)[nodeSymbol] || target); return this[componentMetaSymbol].checkNestingDown(
curNode as any,
(target as any)[nodeSymbol] || target,
);
} }
refreshMetadata(): void { refreshMetadata(): void {

View File

@ -2,6 +2,7 @@ import { Node as ShellNode } from './node';
import { import {
Detecting as InnerDetecting, Detecting as InnerDetecting,
IDocumentModel as InnerDocumentModel, IDocumentModel as InnerDocumentModel,
INode as InnerNode,
} from '@alilc/lowcode-designer'; } from '@alilc/lowcode-designer';
import { documentSymbol, detectingSymbol } from '../symbols'; import { documentSymbol, detectingSymbol } from '../symbols';
import { IPublicModelDetecting, IPublicModelNode, IPublicTypeDisposable } from '@alilc/lowcode-types'; import { IPublicModelDetecting, IPublicModelNode, IPublicTypeDisposable } from '@alilc/lowcode-types';
@ -52,7 +53,11 @@ export class Detecting implements IPublicModelDetecting {
this[detectingSymbol].leave(this[documentSymbol]); this[detectingSymbol].leave(this[documentSymbol]);
} }
onDetectingChange(fn: (node: IPublicModelNode) => void): IPublicTypeDisposable { onDetectingChange(fn: (node: IPublicModelNode | null) => void): IPublicTypeDisposable {
return this[detectingSymbol].onDetectingChange(fn); const innerFn = (innerNode: InnerNode) => {
const shellNode = ShellNode.create(innerNode);
fn(shellNode);
};
return this[detectingSymbol].onDetectingChange(innerFn);
} }
} }

View File

@ -1,8 +1,6 @@
import { Editor } from '@alilc/lowcode-editor-core';
import { import {
DocumentModel as InnerDocumentModel, IDocumentModel as InnerDocumentModel,
Node as InnerNode, INode as InnerNode,
isDragNodeObject,
} from '@alilc/lowcode-designer'; } from '@alilc/lowcode-designer';
import { import {
IPublicEnumTransformStage, IPublicEnumTransformStage,
@ -23,23 +21,24 @@ import {
IPublicModelDropLocation, IPublicModelDropLocation,
IPublicApiCanvas, IPublicApiCanvas,
IPublicTypeDisposable, IPublicTypeDisposable,
IPublicModelEditor,
} from '@alilc/lowcode-types'; } from '@alilc/lowcode-types';
import { Node } from './node'; import { isDragNodeObject } from '@alilc/lowcode-utils';
import { Selection } from './selection'; import { Node as ShellNode } from './node';
import { Detecting } from './detecting'; import { Selection as ShellSelection } from './selection';
import { History } from './history'; import { Detecting as ShellDetecting } from './detecting';
import { DropLocation } from './drop-location'; import { History as ShellHistory } from './history';
import { Project } from '../api/project'; import { DropLocation as ShellDropLocation } from './drop-location';
import { Prop } from './prop'; import { Project as ShellProject, Canvas as ShellCanvas } from '../api';
import { Prop as ShellProp } from './prop';
import { ModalNodesManager } from './modal-nodes-manager'; import { ModalNodesManager } from './modal-nodes-manager';
import { documentSymbol, editorSymbol, nodeSymbol } from '../symbols'; import { documentSymbol, editorSymbol, nodeSymbol } from '../symbols';
import { Canvas } from '../api';
const shellDocSymbol = Symbol('shellDocSymbol'); const shellDocSymbol = Symbol('shellDocSymbol');
export class DocumentModel implements IPublicModelDocumentModel { export class DocumentModel implements IPublicModelDocumentModel {
private readonly [documentSymbol]: InnerDocumentModel; private readonly [documentSymbol]: InnerDocumentModel;
private readonly [editorSymbol]: Editor; private readonly [editorSymbol]: IPublicModelEditor;
private _focusNode: IPublicModelNode | null; private _focusNode: IPublicModelNode | null;
selection: IPublicModelSelection; selection: IPublicModelSelection;
detecting: IPublicModelDetecting; detecting: IPublicModelDetecting;
@ -52,13 +51,13 @@ export class DocumentModel implements IPublicModelDocumentModel {
constructor(document: InnerDocumentModel) { constructor(document: InnerDocumentModel) {
this[documentSymbol] = document; this[documentSymbol] = document;
this[editorSymbol] = document.designer?.editor as Editor; this[editorSymbol] = document.designer?.editor as IPublicModelEditor;
this.selection = new Selection(document); this.selection = new ShellSelection(document);
this.detecting = new Detecting(document); this.detecting = new ShellDetecting(document);
this.history = new History(document); this.history = new ShellHistory(document);
this.canvas = new Canvas(this[editorSymbol]); this.canvas = new ShellCanvas(this[editorSymbol]);
this._focusNode = Node.create(this[documentSymbol].focusNode); this._focusNode = ShellNode.create(this[documentSymbol].focusNode);
} }
static create(document: InnerDocumentModel | undefined | null): IPublicModelDocumentModel | null { static create(document: InnerDocumentModel | undefined | null): IPublicModelDocumentModel | null {
@ -91,7 +90,7 @@ export class DocumentModel implements IPublicModelDocumentModel {
* @returns * @returns
*/ */
get project(): IPublicApiProject { get project(): IPublicApiProject {
return Project.create(this[documentSymbol].project); return ShellProject.create(this[documentSymbol].project);
} }
/** /**
@ -100,7 +99,7 @@ export class DocumentModel implements IPublicModelDocumentModel {
* @returns * @returns
*/ */
get root(): IPublicModelNode | null { get root(): IPublicModelNode | null {
return Node.create(this[documentSymbol].getRoot()); return ShellNode.create(this[documentSymbol].rootNode);
} }
get focusNode(): IPublicModelNode | null { get focusNode(): IPublicModelNode | null {
@ -135,7 +134,7 @@ export class DocumentModel implements IPublicModelDocumentModel {
} }
get dropLocation(): IPublicModelDropLocation | null { get dropLocation(): IPublicModelDropLocation | null {
return DropLocation.create(this[documentSymbol].dropLocation); return ShellDropLocation.create(this[documentSymbol].dropLocation);
} }
set dropLocation(loc: IPublicModelDropLocation | null) { set dropLocation(loc: IPublicModelDropLocation | null) {
@ -148,7 +147,7 @@ export class DocumentModel implements IPublicModelDocumentModel {
* @param {string} nodeId * @param {string} nodeId
*/ */
getNodeById(nodeId: string): IPublicModelNode | null { getNodeById(nodeId: string): IPublicModelNode | null {
return Node.create(this[documentSymbol].getNode(nodeId)); return ShellNode.create(this[documentSymbol].getNode(nodeId));
} }
/** /**
@ -189,7 +188,7 @@ export class DocumentModel implements IPublicModelDocumentModel {
at, at,
copy, copy,
); );
return Node.create(node); return ShellNode.create(node);
} }
/** /**
@ -198,7 +197,7 @@ export class DocumentModel implements IPublicModelDocumentModel {
* @returns * @returns
*/ */
createNode(data: any): IPublicModelNode | null { createNode(data: any): IPublicModelNode | null {
return Node.create(this[documentSymbol].createNode(data)); return ShellNode.create(this[documentSymbol].createNode(data));
} }
/** /**
@ -243,7 +242,7 @@ export class DocumentModel implements IPublicModelDocumentModel {
*/ */
onAddNode(fn: (node: IPublicModelNode) => void): IPublicTypeDisposable { onAddNode(fn: (node: IPublicModelNode) => void): IPublicTypeDisposable {
return this[documentSymbol].onNodeCreate((node: InnerNode) => { return this[documentSymbol].onNodeCreate((node: InnerNode) => {
fn(Node.create(node)!); fn(ShellNode.create(node)!);
}); });
} }
@ -262,7 +261,7 @@ export class DocumentModel implements IPublicModelDocumentModel {
*/ */
onRemoveNode(fn: (node: IPublicModelNode) => void): IPublicTypeDisposable { onRemoveNode(fn: (node: IPublicModelNode) => void): IPublicTypeDisposable {
return this[documentSymbol].onNodeDestroy((node: InnerNode) => { return this[documentSymbol].onNodeDestroy((node: InnerNode) => {
fn(Node.create(node)!); fn(ShellNode.create(node)!);
}); });
} }
@ -271,7 +270,7 @@ export class DocumentModel implements IPublicModelDocumentModel {
*/ */
onChangeDetecting(fn: (node: IPublicModelNode) => void): IPublicTypeDisposable { onChangeDetecting(fn: (node: IPublicModelNode) => void): IPublicTypeDisposable {
return this[documentSymbol].designer.detecting.onDetectingChange((node: InnerNode) => { return this[documentSymbol].designer.detecting.onDetectingChange((node: InnerNode) => {
fn(Node.create(node)!); fn(ShellNode.create(node)!);
}); });
} }
@ -290,7 +289,7 @@ export class DocumentModel implements IPublicModelDocumentModel {
*/ */
onChangeNodeVisible(fn: (node: IPublicModelNode, visible: boolean) => void): void { onChangeNodeVisible(fn: (node: IPublicModelNode, visible: boolean) => void): void {
this[documentSymbol].onChangeNodeVisible((node: IPublicModelNode, visible: boolean) => { this[documentSymbol].onChangeNodeVisible((node: IPublicModelNode, visible: boolean) => {
fn(Node.create(node)!, visible); fn(ShellNode.create(node)!, visible);
}); });
} }
@ -305,7 +304,7 @@ export class DocumentModel implements IPublicModelDocumentModel {
} }
fn({ fn({
type: info.type, type: info.type,
node: Node.create(info.node)!, node: ShellNode.create(info.node)!,
}); });
}); });
} }
@ -322,8 +321,8 @@ export class DocumentModel implements IPublicModelDocumentModel {
key: info.key, key: info.key,
oldValue: info.oldValue, oldValue: info.oldValue,
newValue: info.newValue, newValue: info.newValue,
prop: Prop.create(info.prop)!, prop: ShellProp.create(info.prop)!,
node: Node.create(info.node as any)!, node: ShellNode.create(info.node as any)!,
}); });
}, },
); );

View File

@ -9,7 +9,7 @@ export class DragObject implements IPublicModelDragObject {
this[dragObjectSymbol] = dragObject; this[dragObjectSymbol] = dragObject;
} }
static create(dragObject: InnerDragObject): IPublicModelDragObject | null { static create(dragObject: InnerDragObject | null): IPublicModelDragObject | null {
if (!dragObject) { if (!dragObject) {
return null; return null;
} }

View File

@ -15,7 +15,6 @@ import {
export const innerDragonSymbol = Symbol('innerDragonSymbol'); export const innerDragonSymbol = Symbol('innerDragonSymbol');
export class Dragon implements IPublicModelDragon { export class Dragon implements IPublicModelDragon {
private readonly [innerDragonSymbol]: IPublicModelDragon; private readonly [innerDragonSymbol]: IPublicModelDragon;
@ -38,7 +37,10 @@ export class Dragon implements IPublicModelDragon {
return designer.dragon; return designer.dragon;
} }
static create(dragon: IPublicModelDragon | null, workspaceMode: boolean): IPublicModelDragon | null { static create(
dragon: IPublicModelDragon | null,
workspaceMode: boolean,
): IPublicModelDragon | null {
if (!dragon) { if (!dragon) {
return null; return null;
} }

View File

@ -1,5 +1,5 @@
import { import {
DropLocation as InnerDropLocation, IDropLocation as InnerDropLocation,
} from '@alilc/lowcode-designer'; } from '@alilc/lowcode-designer';
import { dropLocationSymbol } from '../symbols'; import { dropLocationSymbol } from '../symbols';
import { Node } from './node'; import { Node } from './node';

View File

@ -1,11 +1,11 @@
import { DocumentModel as InnerDocumentModel } from '@alilc/lowcode-designer'; import { IDocumentModel as InnerDocumentModel, IHistory as InnerHistory } from '@alilc/lowcode-designer';
import { historySymbol, documentSymbol } from '../symbols'; import { historySymbol, documentSymbol } from '../symbols';
import { IPublicModelHistory, IPublicTypeDisposable } from '@alilc/lowcode-types'; import { IPublicModelHistory, IPublicTypeDisposable } from '@alilc/lowcode-types';
export class History implements IPublicModelHistory { export class History implements IPublicModelHistory {
private readonly [documentSymbol]: InnerDocumentModel; private readonly [documentSymbol]: InnerDocumentModel;
private get [historySymbol]() { private get [historySymbol](): InnerHistory {
return this[documentSymbol].getHistory(); return this[documentSymbol].getHistory();
} }
@ -64,7 +64,7 @@ export class History implements IPublicModelHistory {
* @returns * @returns
*/ */
onChangeState(func: () => any): IPublicTypeDisposable { onChangeState(func: () => any): IPublicTypeDisposable {
return this[historySymbol].onStateChange(func); return this[historySymbol].onChangeState(func);
} }
/** /**
@ -73,6 +73,6 @@ export class History implements IPublicModelHistory {
* @returns * @returns
*/ */
onChangeCursor(func: () => any): IPublicTypeDisposable { onChangeCursor(func: () => any): IPublicTypeDisposable {
return this[historySymbol].onCursor(func); return this[historySymbol].onChangeCursor(func);
} }
} }

View File

@ -15,3 +15,6 @@ export * from './selection';
export * from './setting-prop-entry'; export * from './setting-prop-entry';
export * from './setting-top-entry'; export * from './setting-top-entry';
export * from './resource'; export * from './resource';
export * from './active-tracker';
export * from './plugin-instance';
export * from './window';

View File

@ -1,6 +1,6 @@
import { INode as InnerNode, INodeChildren } from '@alilc/lowcode-designer'; import { INode as InnerNode, INodeChildren } from '@alilc/lowcode-designer';
import { IPublicTypeNodeData, IPublicEnumTransformStage, IPublicModelNodeChildren, IPublicModelNode } from '@alilc/lowcode-types'; import { IPublicTypeNodeData, IPublicEnumTransformStage, IPublicModelNodeChildren, IPublicModelNode } from '@alilc/lowcode-types';
import { Node } from './node'; import { Node as ShellNode } from './node';
import { nodeSymbol, nodeChildrenSymbol } from '../symbols'; import { nodeSymbol, nodeChildrenSymbol } from '../symbols';
export class NodeChildren implements IPublicModelNodeChildren { export class NodeChildren implements IPublicModelNodeChildren {
@ -21,7 +21,7 @@ export class NodeChildren implements IPublicModelNodeChildren {
* children * children
*/ */
get owner(): IPublicModelNode | null { get owner(): IPublicModelNode | null {
return Node.create(this[nodeChildrenSymbol].owner); return ShellNode.create(this[nodeChildrenSymbol].owner);
} }
/** /**
@ -107,7 +107,7 @@ export class NodeChildren implements IPublicModelNodeChildren {
* @returns * @returns
*/ */
get(index: number): IPublicModelNode | null { get(index: number): IPublicModelNode | null {
return Node.create(this[nodeChildrenSymbol].get(index)); return ShellNode.create(this[nodeChildrenSymbol].get(index));
} }
/** /**
@ -125,7 +125,7 @@ export class NodeChildren implements IPublicModelNodeChildren {
*/ */
forEach(fn: (node: IPublicModelNode, index: number) => void): void { forEach(fn: (node: IPublicModelNode, index: number) => void): void {
this[nodeChildrenSymbol].forEach((item: InnerNode, index: number) => { this[nodeChildrenSymbol].forEach((item: InnerNode, index: number) => {
fn(Node.create(item)!, index); fn(ShellNode.create(item)!, index);
}); });
} }
@ -135,7 +135,7 @@ export class NodeChildren implements IPublicModelNodeChildren {
*/ */
map<T>(fn: (node: IPublicModelNode, index: number) => T[]): any[] | null { map<T>(fn: (node: IPublicModelNode, index: number) => T[]): any[] | null {
return this[nodeChildrenSymbol].map((item: InnerNode, index: number) => { return this[nodeChildrenSymbol].map((item: InnerNode, index: number) => {
return fn(Node.create(item)!, index); return fn(ShellNode.create(item)!, index);
}); });
} }
@ -145,7 +145,7 @@ export class NodeChildren implements IPublicModelNodeChildren {
*/ */
every(fn: (node: IPublicModelNode, index: number) => boolean): boolean { every(fn: (node: IPublicModelNode, index: number) => boolean): boolean {
return this[nodeChildrenSymbol].every((item: InnerNode, index: number) => { return this[nodeChildrenSymbol].every((item: InnerNode, index: number) => {
return fn(Node.create(item)!, index); return fn(ShellNode.create(item)!, index);
}); });
} }
@ -155,7 +155,7 @@ export class NodeChildren implements IPublicModelNodeChildren {
*/ */
some(fn: (node: IPublicModelNode, index: number) => boolean): boolean { some(fn: (node: IPublicModelNode, index: number) => boolean): boolean {
return this[nodeChildrenSymbol].some((item: InnerNode, index: number) => { return this[nodeChildrenSymbol].some((item: InnerNode, index: number) => {
return fn(Node.create(item)!, index); return fn(ShellNode.create(item)!, index);
}); });
} }
@ -166,9 +166,9 @@ export class NodeChildren implements IPublicModelNodeChildren {
filter(fn: (node: IPublicModelNode, index: number) => boolean): any { filter(fn: (node: IPublicModelNode, index: number) => boolean): any {
return this[nodeChildrenSymbol] return this[nodeChildrenSymbol]
.filter((item: InnerNode, index: number) => { .filter((item: InnerNode, index: number) => {
return fn(Node.create(item)!, index); return fn(ShellNode.create(item)!, index);
}) })
.map((item: InnerNode) => Node.create(item)!); .map((item: InnerNode) => ShellNode.create(item)!);
} }
/** /**
@ -176,9 +176,9 @@ export class NodeChildren implements IPublicModelNodeChildren {
* @param fn * @param fn
*/ */
find(fn: (node: IPublicModelNode, index: number) => boolean): IPublicModelNode | null { find(fn: (node: IPublicModelNode, index: number) => boolean): IPublicModelNode | null {
return Node.create( return ShellNode.create(
this[nodeChildrenSymbol].find((item: InnerNode, index: number) => { this[nodeChildrenSymbol].find((item: InnerNode, index: number) => {
return fn(Node.create(item)!, index); return fn(ShellNode.create(item)!, index);
}), }),
); );
} }
@ -189,7 +189,7 @@ export class NodeChildren implements IPublicModelNodeChildren {
*/ */
reduce(fn: (acc: any, cur: IPublicModelNode) => any, initialValue: any): void { reduce(fn: (acc: any, cur: IPublicModelNode) => any, initialValue: any): void {
return this[nodeChildrenSymbol].reduce((acc: any, cur: InnerNode) => { return this[nodeChildrenSymbol].reduce((acc: any, cur: InnerNode) => {
return fn(acc, Node.create(cur)!); return fn(acc, ShellNode.create(cur)!);
}, initialValue); }, initialValue);
} }
@ -226,10 +226,11 @@ export class NodeChildren implements IPublicModelNodeChildren {
sorter = () => 0; sorter = () => 0;
} }
this[nodeChildrenSymbol].mergeChildren( this[nodeChildrenSymbol].mergeChildren(
(node: InnerNode, idx: number) => remover(Node.create(node)!, idx), (node: InnerNode, idx: number) => remover(ShellNode.create(node)!, idx),
(children: InnerNode[]) => adder(children.map((node) => Node.create(node)!)), (children: InnerNode[]) => adder(children.map((node) => ShellNode.create(node)!)),
(firstNode: InnerNode, secondNode: InnerNode) => (firstNode: InnerNode, secondNode: InnerNode) => {
sorter(Node.create(firstNode)!, Node.create(secondNode)!), return sorter(ShellNode.create(firstNode)!, ShellNode.create(secondNode)!);
},
); );
} }
} }

View File

@ -283,7 +283,7 @@ export class Node implements IPublicModelNode {
* *
*/ */
get slots(): IPublicModelNode[] { get slots(): IPublicModelNode[] {
return this[nodeSymbol].slots.map((node: IPublicModelNode) => Node.create(node)!); return this[nodeSymbol].slots.map((node: InnerNode) => Node.create(node)!);
} }
/** /**
@ -318,7 +318,7 @@ export class Node implements IPublicModelNode {
return ShellSettingTopEntry.create(this[nodeSymbol].settingEntry as any); return ShellSettingTopEntry.create(this[nodeSymbol].settingEntry as any);
} }
constructor(node: IPublicModelNode) { constructor(node: InnerNode) {
this[nodeSymbol] = node; this[nodeSymbol] = node;
this[documentSymbol] = node.document; this[documentSymbol] = node.document;
@ -351,7 +351,7 @@ export class Node implements IPublicModelNode {
* @deprecated * @deprecated
*/ */
getDOMNode() { getDOMNode() {
return this[nodeSymbol].getDOMNode(); return (this[nodeSymbol] as any).getDOMNode();
} }
/** /**
@ -512,7 +512,10 @@ export class Node implements IPublicModelNode {
* @param options * @param options
* @returns * @returns
*/ */
exportSchema(stage: IPublicEnumTransformStage = IPublicEnumTransformStage.Render, options?: any): IPublicTypeNodeSchema { exportSchema(
stage: IPublicEnumTransformStage = IPublicEnumTransformStage.Render,
options?: any,
): IPublicTypeNodeSchema {
return this[nodeSymbol].export(stage, options); return this[nodeSymbol].export(stage, options);
} }

View File

@ -1,7 +1,14 @@
import { IPublicTypeDisposable, IPublicTypeHotkeyCallback } from '../type'; import { IPublicTypeDisposable, IPublicTypeHotkeyCallback, IPublicTypeHotkeyCallbacks } from '../type';
export interface IPublicApiHotkey { export interface IPublicApiHotkey {
get callbacks(): any;
/**
*
*
* @experimental
* @since v1.1.0
*/
get callbacks(): IPublicTypeHotkeyCallbacks;
/** /**
* *
@ -9,7 +16,6 @@ export interface IPublicApiHotkey {
* @param combos ['command + s'] ['ctrl + shift + s'] * @param combos ['command + s'] ['ctrl + shift + s']
* @param callback * @param callback
* @param action * @param action
* @returns
*/ */
bind( bind(
combos: string[] | string, combos: string[] | string,

View File

@ -3,8 +3,8 @@ import { IPublicEnumTransformStage } from '../enum';
import { IPublicApiSimulatorHost } from './'; import { IPublicApiSimulatorHost } from './';
import { IPublicModelDocumentModel } from '../model'; import { IPublicModelDocumentModel } from '../model';
export interface IPublicApiProject { export interface IPublicApiProject {
/** /**
* document * document
* get current document * get current document
@ -40,7 +40,6 @@ export interface IPublicApiProject {
*/ */
createDocument(data?: IPublicTypeRootSchema): IPublicModelDocumentModel | null; createDocument(data?: IPublicTypeRootSchema): IPublicModelDocumentModel | null;
/** /**
* document * document
* remove a document * remove a document

View File

@ -3,6 +3,7 @@ import { ReactElement } from 'react';
import { IPublicModelNode } from './node'; import { IPublicModelNode } from './node';
export interface IPublicModelComponentMeta { export interface IPublicModelComponentMeta {
/** /**
* *
*/ */
@ -79,6 +80,5 @@ export interface IPublicModelComponentMeta {
target: IPublicTypeNodeSchema | IPublicModelNode | IPublicTypeNodeSchema[], target: IPublicTypeNodeSchema | IPublicModelNode | IPublicTypeNodeSchema[],
): boolean; ): boolean;
refreshMetadata(): void; refreshMetadata(): void;
} }

View File

@ -42,5 +42,5 @@ export interface IPublicModelDetecting {
* set callback which will be called when hovering object changed. * set callback which will be called when hovering object changed.
* @since v1.1.0 * @since v1.1.0
*/ */
onDetectingChange(fn: (node: IPublicModelNode) => void): IPublicTypeDisposable; onDetectingChange(fn: (node: IPublicModelNode | null) => void): IPublicTypeDisposable;
} }

View File

@ -3,7 +3,7 @@ import { EventEmitter } from 'events';
import StrictEventEmitter from 'strict-event-emitter-types'; import StrictEventEmitter from 'strict-event-emitter-types';
import * as GlobalEvent from '../../event'; import * as GlobalEvent from '../../event';
import { IPublicApiEvent } from '../api'; import { IPublicApiEvent } from '../api';
import { IPublicTypeEditorValueKey, IPublicTypeEditorGetOptions, IPublicTypeEditorGetResult, IPublicTypeEditorRegisterOptions } from '../type'; import { IPublicTypeEditorValueKey, IPublicTypeEditorGetOptions, IPublicTypeEditorGetResult, IPublicTypeEditorRegisterOptions, IPublicTypeAssetsJson } from '../type';
export interface IPublicModelEditor extends StrictEventEmitter<EventEmitter, GlobalEvent.EventConfig> { export interface IPublicModelEditor extends StrictEventEmitter<EventEmitter, GlobalEvent.EventConfig> {
get: <T = undefined, KeyOrType = any>( get: <T = undefined, KeyOrType = any>(
@ -25,4 +25,6 @@ export interface IPublicModelEditor extends StrictEventEmitter<EventEmitter, Glo
register: (data: any, key?: IPublicTypeEditorValueKey, options?: IPublicTypeEditorRegisterOptions) => void; register: (data: any, key?: IPublicTypeEditorValueKey, options?: IPublicTypeEditorRegisterOptions) => void;
get eventBus(): IPublicApiEvent; get eventBus(): IPublicApiEvent;
setAssets(assets: IPublicTypeAssetsJson): void;
} }

View File

@ -0,0 +1,10 @@
import { IPublicTypeHotkeyCallback } from './';
export interface IPublicTypeHotkeyCallbackConfig {
callback: IPublicTypeHotkeyCallback;
modifiers: string[];
action: string;
seq?: string;
level?: number;
combo?: string;
}

View File

@ -0,0 +1,5 @@
import { IPublicTypeHotkeyCallbackConfig } from './';
export interface IPublicTypeHotkeyCallbacks {
[key: string]: IPublicTypeHotkeyCallbackConfig[];
}

View File

@ -87,3 +87,5 @@ export * from './editor-view';
export * from './resource-type'; export * from './resource-type';
export * from './resource-type-config'; export * from './resource-type-config';
export * from './editor-view-config'; export * from './editor-view-config';
export * from './hotkey-callback-config';
export * from './hotkey-callbacks';