refactor: reorganize types

This commit is contained in:
JackLian 2023-01-05 16:54:11 +08:00 committed by 刘菊萍(絮黎)
parent b07d33e99a
commit c4bfeaa201
47 changed files with 300 additions and 342 deletions

View File

@ -41,5 +41,12 @@ module.exports = {
'@typescript-eslint/dot-notation': 0, // for lint performance '@typescript-eslint/dot-notation': 0, // for lint performance
'@typescript-eslint/restrict-plus-operands': 0, // for lint performance '@typescript-eslint/restrict-plus-operands': 0, // for lint performance
'no-unexpected-multiline': 1, 'no-unexpected-multiline': 1,
'no-multiple-empty-lines': ['error', { "max": 1 }],
'lines-around-comment': ['error', {
"beforeBlockComment": true,
"afterBlockComment": false,
"afterLineComment": false,
"allowBlockStart": true,
}],
} }
}; };

View File

@ -5,7 +5,7 @@
import changeCase from 'change-case'; import changeCase from 'change-case';
import { import {
IPublicTypeUtilItem, IPublicTypeUtilItem,
NodeDataType, IPublicTypeNodeDataType,
IPublicTypeNodeSchema, IPublicTypeNodeSchema,
IPublicTypeContainerSchema, IPublicTypeContainerSchema,
IPublicTypeProjectSchema, IPublicTypeProjectSchema,
@ -81,7 +81,7 @@ function processChildren(schema: IPublicTypeNodeSchema): void {
if (nodeProps.children) { if (nodeProps.children) {
if (!schema.children) { if (!schema.children) {
// eslint-disable-next-line no-param-reassign // eslint-disable-next-line no-param-reassign
schema.children = nodeProps.children as NodeDataType; schema.children = nodeProps.children as IPublicTypeNodeDataType;
} else { } else {
let _children: IPublicTypeNodeData[] = []; let _children: IPublicTypeNodeData[] = [];
@ -331,7 +331,7 @@ export class SchemaParser implements ISchemaParser {
}; };
} }
getComponentNames(children: NodeDataType): string[] { getComponentNames(children: IPublicTypeNodeDataType): string[] {
return handleSubNodes<string>( return handleSubNodes<string>(
children, children,
{ {

View File

@ -5,7 +5,7 @@ import {
IPublicTypeCompositeObject, IPublicTypeCompositeObject,
ResultDir, ResultDir,
ResultFile, ResultFile,
NodeDataType, IPublicTypeNodeDataType,
IPublicTypeProjectSchema, IPublicTypeProjectSchema,
IPublicTypeJSExpression, IPublicTypeJSExpression,
IPublicTypeJSFunction, IPublicTypeJSFunction,
@ -65,7 +65,10 @@ export interface ICodeStruct extends IBaseCodeStruct {
/** 上下文数据,用来在插件之间共享一些数据 */ /** 上下文数据,用来在插件之间共享一些数据 */
export interface IContextData extends IProjectBuilderOptions { export interface IContextData extends IProjectBuilderOptions {
/** 是否使用了 Ref 的 API (this.$/this.$$) */
/**
* 使 Ref API (this.$/this.$$)
* */
useRefApi?: boolean; useRefApi?: boolean;
/** /**
@ -108,6 +111,7 @@ export interface IModuleBuilder {
* @interface ICodeGenerator * @interface ICodeGenerator
*/ */
export interface ICodeGenerator { export interface ICodeGenerator {
/** /**
* Schema * Schema
* *
@ -138,26 +142,27 @@ export interface IProjectPlugins {
} }
export interface IProjectBuilderOptions { export interface IProjectBuilderOptions {
/** 是否处于严格模式(默认: 否) */
/** 是否处于严格模式 (默认:否) */
inStrictMode?: boolean; inStrictMode?: boolean;
/** /**
* JSExpression * JSExpression
* true * true
* : 如果容忍异 try-catch * try-catch
* catch CustomEvent * catch CustomEvent
*/ */
tolerateEvalErrors?: boolean; tolerateEvalErrors?: boolean;
/** /**
* *
* 默认: *
* *
* window.dispatchEvent(new CustomEvent('lowcode-eval-error', { error, expr })) * window.dispatchEvent(new CustomEvent('lowcode-eval-error', { error, expr }))
* *
* *
* *
* : *
* - error: 异常信息 * - error: 异常信息
* - expr: 求值的表达式 * - expr: 求值的表达式
*/ */
@ -205,7 +210,7 @@ type CompositeTypeGenerator<I, T> =
| BaseGenerator<I, T, CompositeValueGeneratorOptions> | BaseGenerator<I, T, CompositeValueGeneratorOptions>
| Array<BaseGenerator<I, T, CompositeValueGeneratorOptions>>; | Array<BaseGenerator<I, T, CompositeValueGeneratorOptions>>;
export type NodeGenerator<T> = (nodeItem: NodeDataType, scope: IScope) => T; export type NodeGenerator<T> = (nodeItem: IPublicTypeNodeDataType, scope: IScope) => T;
// FIXME: 在新的实现中,添加了第一参数 this: CustomHandlerSet 作为上下文。究其本质 // FIXME: 在新的实现中,添加了第一参数 this: CustomHandlerSet 作为上下文。究其本质
// scopeBindings?: IScopeBindings; // scopeBindings?: IScopeBindings;

View File

@ -1,6 +1,6 @@
import _ from 'lodash'; import _ from 'lodash';
import { pipe } from 'fp-ts/function'; import { pipe } from 'fp-ts/function';
import { IPublicTypeNodeSchema, isNodeSchema, NodeDataType, IPublicTypeCompositeValue } from '@alilc/lowcode-types'; import { IPublicTypeNodeSchema, isNodeSchema, IPublicTypeNodeDataType, IPublicTypeCompositeValue } from '@alilc/lowcode-types';
import { import {
IScope, IScope,
@ -365,7 +365,7 @@ export function generateReactExprInJS(
const handleChildren = (v: string[]) => v.join(''); const handleChildren = (v: string[]) => v.join('');
export function createNodeGenerator(cfg: NodeGeneratorConfig = {}): NodeGenerator<string> { export function createNodeGenerator(cfg: NodeGeneratorConfig = {}): NodeGenerator<string> {
const generateNode = (nodeItem: NodeDataType, scope: IScope): string => { const generateNode = (nodeItem: IPublicTypeNodeDataType, scope: IScope): string => {
if (_.isArray(nodeItem)) { if (_.isArray(nodeItem)) {
const resList = nodeItem.map((n) => generateNode(n, scope)); const resList = nodeItem.map((n) => generateNode(n, scope));
return handleChildren(resList); return handleChildren(resList);
@ -390,7 +390,7 @@ export function createNodeGenerator(cfg: NodeGeneratorConfig = {}): NodeGenerato
return `{${valueStr}}`; return `{${valueStr}}`;
}; };
return (nodeItem: NodeDataType, scope: IScope) => unwrapJsExprQuoteInJsx(generateNode(nodeItem, scope)); return (nodeItem: IPublicTypeNodeDataType, scope: IScope) => unwrapJsExprQuoteInJsx(generateNode(nodeItem, scope));
} }
const defaultReactGeneratorConfig: NodeGeneratorConfig = { const defaultReactGeneratorConfig: NodeGeneratorConfig = {

View File

@ -6,7 +6,6 @@ import { getClosestNode } from '@alilc/lowcode-utils';
import { intl } from '../../locale'; import { intl } from '../../locale';
import { BuiltinSimulatorHost } from '../host'; import { BuiltinSimulatorHost } from '../host';
export class BorderDetectingInstance extends PureComponent<{ export class BorderDetectingInstance extends PureComponent<{
title: IPublicTypeTitleContent; title: IPublicTypeTitleContent;
rect: DOMRect | null; rect: DOMRect | null;
@ -77,11 +76,9 @@ export class BorderDetecting extends Component<{ host: BuiltinSimulatorHost }> {
const { host } = this.props; const { host } = this.props;
const { current } = this; const { current } = this;
const canHoverHook = current?.componentMeta.getMetadata()?.configure.advanced?.callbacks?.onHoverHook; const canHoverHook = current?.componentMeta.getMetadata()?.configure.advanced?.callbacks?.onHoverHook;
const canHover = (canHoverHook && typeof canHoverHook === 'function') ? canHoverHook(current.internalToShellNode()) : true; const canHover = (canHoverHook && typeof canHoverHook === 'function') ? canHoverHook(current.internalToShellNode()) : true;
if (!canHover || !current || host.viewport.scrolling || host.liveEditing.editing) { if (!canHover || !current || host.viewport.scrolling || host.liveEditing.editing) {
return null; return null;
} }

View File

@ -57,7 +57,7 @@ import {
IPublicEnumTransitionType, IPublicEnumTransitionType,
IPublicEnumDragObjectType, IPublicEnumDragObjectType,
IPublicTypeDragNodeObject, IPublicTypeDragNodeObject,
NodeInstance, IPublicTypeNodeInstance,
IPublicTypeComponentInstance, IPublicTypeComponentInstance,
IPublicTypeLocationChildrenDetail, IPublicTypeLocationChildrenDetail,
IPublicTypeLocationDetailType, IPublicTypeLocationDetailType,
@ -173,7 +173,6 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
readonly emitter: IEventBus = createModuleEventBus('BuiltinSimulatorHost'); readonly emitter: IEventBus = createModuleEventBus('BuiltinSimulatorHost');
readonly componentsConsumer: ResourceConsumer; readonly componentsConsumer: ResourceConsumer;
readonly injectionConsumer: ResourceConsumer; readonly injectionConsumer: ResourceConsumer;
@ -898,7 +897,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
/** /**
* @see ISimulator * @see ISimulator
*/ */
getComponentInstances(node: Node, context?: NodeInstance): IPublicTypeComponentInstance[] | null { getComponentInstances(node: Node, context?: IPublicTypeNodeInstance): IPublicTypeComponentInstance[] | null {
const docId = node.document.id; const docId = node.document.id;
const instances = this.instancesMap[docId]?.get(node.id) || null; const instances = this.instancesMap[docId]?.get(node.id) || null;
@ -925,7 +924,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
getClosestNodeInstance( getClosestNodeInstance(
from: IPublicTypeComponentInstance, from: IPublicTypeComponentInstance,
specId?: string, specId?: string,
): NodeInstance<IPublicTypeComponentInstance> | null { ): IPublicTypeNodeInstance<IPublicTypeComponentInstance> | null {
return this.renderer?.getClosestNodeInstance(from, specId) || null; return this.renderer?.getClosestNodeInstance(from, specId) || null;
} }
@ -1028,7 +1027,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
/** /**
* DOM simulator * DOM simulator
*/ */
getNodeInstanceFromElement(target: Element | null): NodeInstance<IPublicTypeComponentInstance> | null { getNodeInstanceFromElement(target: Element | null): IPublicTypeNodeInstance<IPublicTypeComponentInstance> | null {
if (!target) { if (!target) {
return null; return null;
} }
@ -1111,14 +1110,14 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
private _sensorAvailable = true; private _sensorAvailable = true;
/** /**
* @see ISensor * @see IPublicModelSensor
*/ */
get sensorAvailable(): boolean { get sensorAvailable(): boolean {
return this._sensorAvailable; return this._sensorAvailable;
} }
/** /**
* @see ISensor * @see IPublicModelSensor
*/ */
fixEvent(e: ILocateEvent): ILocateEvent { fixEvent(e: ILocateEvent): ILocateEvent {
if (e.fixed) { if (e.fixed) {
@ -1149,7 +1148,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
} }
/** /**
* @see ISensor * @see IPublicModelSensor
*/ */
isEnter(e: ILocateEvent): boolean { isEnter(e: ILocateEvent): boolean {
const rect = this.viewport.bounds; const rect = this.viewport.bounds;
@ -1164,7 +1163,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
private sensing = false; private sensing = false;
/** /**
* @see ISensor * @see IPublicModelSensor
*/ */
deactiveSensor() { deactiveSensor() {
this.sensing = false; this.sensing = false;
@ -1174,7 +1173,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
// ========= drag location logic: helper for locate ========== // ========= drag location logic: helper for locate ==========
/** /**
* @see ISensor * @see IPublicModelSensor
*/ */
locate(e: ILocateEvent): any { locate(e: ILocateEvent): any {
const { dragObject } = e; const { dragObject } = e;
@ -1372,7 +1371,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
const document = this.project.currentDocument!; const document = this.project.currentDocument!;
const { currentRoot } = document; const { currentRoot } = document;
let container: INode; let container: INode;
let nodeInstance: NodeInstance<IPublicTypeComponentInstance> | undefined; let nodeInstance: IPublicTypeNodeInstance<IPublicTypeComponentInstance> | undefined;
if (target) { if (target) {
const ref = this.getNodeInstanceFromElement(target); const ref = this.getNodeInstanceFromElement(target);

View File

@ -214,7 +214,6 @@ function selectRange(doc: Document, range: Range) {
} }
} }
function queryPropElement(rootElement: HTMLElement, targetElement: HTMLElement, selector?: string) { function queryPropElement(rootElement: HTMLElement, targetElement: HTMLElement, selector?: string) {
if (!selector) { if (!selector) {
return null; return null;

View File

@ -1,5 +1,5 @@
import { Component } from '../simulator'; import { Component } from '../simulator';
import { IPublicTypeNodeSchema, IPublicTypeComponentInstance, NodeInstance } from '@alilc/lowcode-types'; import { IPublicTypeNodeSchema, IPublicTypeComponentInstance, IPublicTypeNodeInstance } from '@alilc/lowcode-types';
export interface BuiltinSimulatorRenderer { export interface BuiltinSimulatorRenderer {
readonly isSimulatorRenderer: true; readonly isSimulatorRenderer: true;
@ -8,7 +8,7 @@ export interface BuiltinSimulatorRenderer {
getClosestNodeInstance( getClosestNodeInstance(
from: IPublicTypeComponentInstance, from: IPublicTypeComponentInstance,
nodeId?: string, nodeId?: string,
): NodeInstance<IPublicTypeComponentInstance> | null; ): IPublicTypeNodeInstance<IPublicTypeComponentInstance> | null;
findDOMNodes(instance: IPublicTypeComponentInstance): Array<Element | Text> | null; findDOMNodes(instance: IPublicTypeComponentInstance): Array<Element | Text> | null;
getClientRects(element: Element | Text): DOMRect[]; getClientRects(element: Element | Text): DOMRect[];
setNativeSelection(enableFlag: boolean): void; setNativeSelection(enableFlag: boolean): void;

View File

@ -18,23 +18,8 @@ function getDataFromPasteEvent(event: ClipboardEvent) {
}; };
} }
} catch (error) { } catch (error) {
/*
const html = clipboardData.getData('text/html');
if (html !== '') {
// TODO: clear the html
return {
code: '<div dangerouslySetInnerHTML={ __html: html } />',
maps: {},
};
}
*/
// TODO: open the parser implement // TODO: open the parser implement
return { }; return { };
/*
return {
code: clipboardData.getData('text/plain'),
maps: {},
}; */
} }
} }

View File

@ -13,10 +13,12 @@ import {
IShellModelFactory, IShellModelFactory,
IPublicModelDragObject, IPublicModelDragObject,
IPublicModelScrollable, IPublicModelScrollable,
IDesigner,
IPublicModelScroller, IPublicModelScroller,
IPublicTypeLocationData, IPublicTypeLocationData,
IPublicEnumTransformStage, IPublicEnumTransformStage,
IPublicModelDragon,
IPublicModelActiveTracker,
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';
@ -57,6 +59,16 @@ export interface DesignerProps {
[key: string]: any; [key: string]: any;
} }
export interface IDesigner {
get dragon(): IPublicModelDragon;
get activeTracker(): IPublicModelActiveTracker;
createScroller(scrollable: IPublicModelScrollable): IPublicModelScroller;
/**
* dragon
*/
createLocation(locationData: IPublicTypeLocationData): IPublicModelDropLocation;
}
export class Designer implements IDesigner { export class Designer implements IDesigner {
dragon: Dragon; dragon: Dragon;

View File

@ -8,7 +8,7 @@ import {
IPublicModelNode, IPublicModelNode,
IPublicModelDragon, IPublicModelDragon,
IPublicModelLocateEvent, IPublicModelLocateEvent,
ISensor, IPublicModelSensor,
} from '@alilc/lowcode-types'; } from '@alilc/lowcode-types';
import { setNativeSelection, cursor } from '@alilc/lowcode-utils'; import { setNativeSelection, cursor } from '@alilc/lowcode-utils';
import { Node } from '../document'; import { Node } from '../document';
@ -22,7 +22,7 @@ export interface ILocateEvent extends IPublicModelLocateEvent {
/** /**
* *
*/ */
sensor?: ISensor; sensor?: IPublicModelSensor;
} }
@ -52,6 +52,7 @@ export function isLocateEvent(e: any): e is ILocateEvent {
} }
const SHAKE_DISTANCE = 4; const SHAKE_DISTANCE = 4;
/** /**
* mouse shake check * mouse shake check
*/ */
@ -103,16 +104,16 @@ export interface IDragon extends IPublicModelDragon {
* Drag-on * Drag-on
*/ */
export class Dragon implements IDragon { export class Dragon implements IDragon {
private sensors: ISensor[] = []; private sensors: IPublicModelSensor[] = [];
key = Math.random(); key = Math.random();
/** /**
* current active sensor, * current active sensor,
*/ */
@obx.ref private _activeSensor: ISensor | undefined; @obx.ref private _activeSensor: IPublicModelSensor | undefined;
get activeSensor(): ISensor | undefined { get activeSensor(): IPublicModelSensor | undefined {
return this._activeSensor; return this._activeSensor;
} }
@ -173,7 +174,7 @@ export class Dragon implements IDragon {
const forceCopyState = const forceCopyState =
isDragNodeObject(dragObject) && dragObject.nodes.some((node: Node | IPublicModelNode) => (typeof node.isSlot === 'function' ? node.isSlot() : node.isSlot)); isDragNodeObject(dragObject) && dragObject.nodes.some((node: Node | IPublicModelNode) => (typeof node.isSlot === 'function' ? node.isSlot() : node.isSlot));
const isBoostFromDragAPI = isDragEvent(boostEvent); const isBoostFromDragAPI = isDragEvent(boostEvent);
let lastSensor: ISensor | undefined; let lastSensor: IPublicModelSensor | undefined;
this._dragging = false; this._dragging = false;
@ -462,7 +463,7 @@ export class Dragon implements IDragon {
/* istanbul ignore next */ /* istanbul ignore next */
const chooseSensor = (e: ILocateEvent) => { const chooseSensor = (e: ILocateEvent) => {
// this.sensors will change on dragstart // this.sensors will change on dragstart
const sensors: ISensor[] = this.sensors.concat(masterSensors as ISensor[]); const sensors: IPublicModelSensor[] = this.sensors.concat(masterSensors as IPublicModelSensor[]);
let sensor = let sensor =
e.sensor && e.sensor.isEnter(e) e.sensor && e.sensor.isEnter(e)
? e.sensor ? e.sensor

View File

@ -15,8 +15,7 @@ import {
IPublicApiProject, IPublicApiProject,
IPublicModelDropLocation, IPublicModelDropLocation,
IPublicEnumTransformStage, IPublicEnumTransformStage,
IPublicOnChangeOptions, IPublicTypeOnChangeOptions,
EDITOR_EVENT,
} from '@alilc/lowcode-types'; } from '@alilc/lowcode-types';
import { Project } from '../project'; import { Project } from '../project';
import { ISimulatorHost } from '../simulator'; import { ISimulatorHost } from '../simulator';
@ -27,6 +26,7 @@ import { Selection } from './selection';
import { History } from './history'; import { History } from './history';
import { ModalNodesManager } from './node'; import { 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';
export type GetDataType<T, NodeType> = T extends undefined export type GetDataType<T, NodeType> = T extends undefined
? NodeType extends { ? NodeType extends {
@ -168,7 +168,7 @@ export class DocumentModel implements IDocumentModel {
}; };
} }
onChangeNodeChildren(fn: (info: IPublicOnChangeOptions) => void): () => void { onChangeNodeChildren(fn: (info: IPublicTypeOnChangeOptions) => void): () => void {
this.designer.editor?.eventBus.on(EDITOR_EVENT.NODE_VISIBLE_CHANGE, fn); this.designer.editor?.eventBus.on(EDITOR_EVENT.NODE_VISIBLE_CHANGE, fn);
return () => { return () => {
@ -338,7 +338,6 @@ 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: IPublicModelDropLocation | null) {
this._dropLocation = loc; this._dropLocation = loc;
// pub event // pub event

View File

@ -6,17 +6,15 @@ import {
IPublicTypePropsList, IPublicTypePropsList,
IPublicTypeNodeData, IPublicTypeNodeData,
IPublicTypeI18nData, IPublicTypeI18nData,
SlotSchema, IPublicTypeSlotSchema,
IPublicTypePageSchema, IPublicTypePageSchema,
IPublicTypeComponentSchema, IPublicTypeComponentSchema,
NodeStatus,
IPublicTypeCompositeValue, IPublicTypeCompositeValue,
GlobalEvent, GlobalEvent,
IPublicTypeComponentAction, IPublicTypeComponentAction,
IPublicModelNode, IPublicModelNode,
IPublicModelExclusiveGroup, IPublicModelExclusiveGroup,
IPublicEnumTransformStage, IPublicEnumTransformStage,
EDITOR_EVENT,
} 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';
@ -28,8 +26,13 @@ import { ComponentMeta } 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';
import { NodeRemoveOptions } from '../../types'; import { NodeRemoveOptions, EDITOR_EVENT } from '../../types';
export interface NodeStatus {
locking: boolean;
pseudo: boolean;
inPlaceEditing: boolean;
}
export interface INode extends IPublicModelNode { export interface INode extends IPublicModelNode {
@ -1235,14 +1238,13 @@ function ensureNode(node: any, document: DocumentModel): Node {
return nodeInstance; return nodeInstance;
} }
export interface LeafNode extends Node { export interface LeafNode extends Node {
readonly children: null; readonly children: null;
} }
export type IPublicTypePropChangeOptions = Omit<GlobalEvent.Node.Prop.ChangeOptions, 'node'>; export type IPublicTypePropChangeOptions = Omit<GlobalEvent.Node.Prop.ChangeOptions, 'node'>;
export type SlotNode = Node<SlotSchema>; export type SlotNode = Node<IPublicTypeSlotSchema>;
export type PageNode = Node<IPublicTypePageSchema>; export type PageNode = Node<IPublicTypePageSchema>;
export type ComponentNode = Node<IPublicTypeComponentSchema>; export type ComponentNode = Node<IPublicTypeComponentSchema>;
export type RootNode = PageNode | ComponentNode; export type RootNode = PageNode | ComponentNode;

View File

@ -1,5 +1,5 @@
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 { IPublicTypeCompositeValue, GlobalEvent, IPublicTypeJSSlot, SlotSchema, IPublicEnumTransformStage } from '@alilc/lowcode-types'; import { IPublicTypeCompositeValue, GlobalEvent, IPublicTypeJSSlot, IPublicTypeSlotSchema, IPublicEnumTransformStage } from '@alilc/lowcode-types';
import { uniqueId, isPlainObject, hasOwnProperty, compatStage, isJSExpression, isJSSlot } from '@alilc/lowcode-utils'; import { uniqueId, isPlainObject, hasOwnProperty, compatStage, isJSExpression, isJSSlot } from '@alilc/lowcode-utils';
import { valueToSource } from './value-to-source'; import { valueToSource } from './value-to-source';
import { Props } from './props'; import { Props } from './props';
@ -314,10 +314,10 @@ export class Prop implements IPropParent {
@action @action
setAsSlot(data: IPublicTypeJSSlot) { setAsSlot(data: IPublicTypeJSSlot) {
this._type = 'slot'; this._type = 'slot';
let slotSchema: SlotSchema; let slotSchema: IPublicTypeSlotSchema;
// 当 data.value 的结构为 { componentName: 'Slot' } 时,复用部分 slotSchema 数据 // 当 data.value 的结构为 { componentName: 'Slot' } 时,复用部分 slotSchema 数据
if ((isPlainObject(data.value) && data.value?.componentName === 'Slot')) { if ((isPlainObject(data.value) && data.value?.componentName === 'Slot')) {
const value = data.value as SlotSchema; const value = data.value as IPublicTypeSlotSchema;
slotSchema = { slotSchema = {
componentName: 'Slot', componentName: 'Slot',
title: value.title || value.props?.slotTitle, title: value.title || value.props?.slotTitle,
@ -325,7 +325,7 @@ export class Prop implements IPropParent {
name: value.name || value.props?.slotName, name: value.name || value.props?.slotName,
params: value.params || value.props?.slotParams, params: value.params || value.props?.slotParams,
children: data.value, children: data.value,
} as SlotSchema; } as IPublicTypeSlotSchema;
} else { } else {
slotSchema = { slotSchema = {
componentName: 'Slot', componentName: 'Slot',

View File

@ -1,5 +1,5 @@
import { ComponentType } from 'react'; import { ComponentType } from 'react';
import { IPublicTypeComponentMetadata, IPublicTypeNodeSchema, IPublicModelScrollable, IPublicTypeComponentInstance, ISensor, NodeInstance } from '@alilc/lowcode-types'; import { IPublicTypeComponentMetadata, IPublicTypeNodeSchema, IPublicModelScrollable, IPublicTypeComponentInstance, IPublicModelSensor, IPublicTypeNodeInstance } from '@alilc/lowcode-types';
import { Point, ScrollTarget, ILocateEvent } from './designer'; import { Point, ScrollTarget, ILocateEvent } from './designer';
import { BuiltinSimulatorRenderer } from './builtin-simulator/renderer'; import { BuiltinSimulatorRenderer } from './builtin-simulator/renderer';
import { Node, INode } from './document'; import { Node, INode } from './document';
@ -11,6 +11,7 @@ export const AutoFit = '100%';
export interface IScrollable extends IPublicModelScrollable { export interface IScrollable extends IPublicModelScrollable {
} }
export interface IViewport extends IScrollable { export interface IViewport extends IScrollable {
/** /**
* *
*/ */
@ -32,22 +33,27 @@ export interface IViewport extends IScrollable {
* *
*/ */
readonly bounds: DOMRect; readonly bounds: DOMRect;
/** /**
* *
*/ */
readonly contentBounds: DOMRect; readonly contentBounds: DOMRect;
/** /**
* *
*/ */
readonly scrollTarget?: ScrollTarget; readonly scrollTarget?: ScrollTarget;
/** /**
* *
*/ */
readonly scrolling: boolean; readonly scrolling: boolean;
/** /**
* X * X
*/ */
readonly scrollX: number; readonly scrollX: number;
/** /**
* Y * Y
*/ */
@ -72,8 +78,9 @@ export interface DropContainer {
/** /**
* *
*/ */
export interface ISimulatorHost<P = object> extends ISensor { export interface ISimulatorHost<P = object> extends IPublicModelSensor {
readonly isSimulator: true; readonly isSimulator: true;
/** /**
* *
*/ */
@ -104,14 +111,17 @@ export interface ISimulatorHost<P = object> extends ISensor {
* *
*/ */
setNativeSelection(enableFlag: boolean): void; setNativeSelection(enableFlag: boolean): void;
/** /**
* *
*/ */
setDraggingState(state: boolean): void; setDraggingState(state: boolean): void;
/** /**
* *
*/ */
setCopyState(state: boolean): void; setCopyState(state: boolean): void;
/** /**
* *
*/ */
@ -128,24 +138,28 @@ export interface ISimulatorHost<P = object> extends ISensor {
* *
*/ */
generateComponentMetadata(componentName: string): IPublicTypeComponentMetadata; generateComponentMetadata(componentName: string): IPublicTypeComponentMetadata;
/** /**
* *
*/ */
getComponent(componentName: string): Component | any; getComponent(componentName: string): Component | any;
/** /**
* *
*/ */
getComponentInstances(node: Node): IPublicTypeComponentInstance[] | null; getComponentInstances(node: Node): IPublicTypeComponentInstance[] | null;
/** /**
* schema * schema
*/ */
createComponent(schema: IPublicTypeNodeSchema): Component | null; createComponent(schema: IPublicTypeNodeSchema): Component | null;
/** /**
* *
*/ */
getComponentContext(node: Node): object | null; getComponentContext(node: Node): object | null;
getClosestNodeInstance(from: IPublicTypeComponentInstance, specId?: string): NodeInstance | null; getClosestNodeInstance(from: IPublicTypeComponentInstance, specId?: string): IPublicTypeNodeInstance | null;
computeRect(node: Node): DOMRect | null; computeRect(node: Node): DOMRect | null;
@ -158,6 +172,7 @@ export interface ISimulatorHost<P = object> extends ISensor {
postEvent(evtName: string, evtData: any): void; postEvent(evtName: string, evtData: any): void;
rerender(): void; rerender(): void;
/** /**
* *
*/ */

View File

@ -11,4 +11,10 @@ export const utils = {
getNodeSchemaById, getNodeSchemaById,
}; };
export enum EDITOR_EVENT {
NODE_CHILDREN_CHANGE = 'node.children.change',
NODE_VISIBLE_CHANGE = 'node.visible.change',
}
export type Utils = typeof utils; export type Utils = typeof utils;

View File

@ -7,8 +7,8 @@ import {
IPublicModelEditor, IPublicModelEditor,
EditorConfig, EditorConfig,
PluginClassSet, PluginClassSet,
KeyType, IPublicTypeEditorValueKey,
GetReturnType, IPublicTypeEditorGetResult,
HookConfig, HookConfig,
IPublicTypeComponentDescription, IPublicTypeComponentDescription,
IPublicTypeRemoteComponentDescription, IPublicTypeRemoteComponentDescription,
@ -61,10 +61,11 @@ export class Editor extends (EventEmitter as any) implements IPublicModelEditor
this.setMaxListeners(200); this.setMaxListeners(200);
this.eventBus = new EventBus(this); this.eventBus = new EventBus(this);
} }
/** /**
* Ioc Container * Ioc Container
*/ */
@obx.shallow private context = new Map<KeyType, any>(); @obx.shallow private context = new Map<IPublicTypeEditorValueKey, any>();
get locale() { get locale() {
return globalLocale.getLocale(); return globalLocale.getLocale();
@ -76,15 +77,15 @@ export class Editor extends (EventEmitter as any) implements IPublicModelEditor
get<T = undefined, KeyOrType = any>( get<T = undefined, KeyOrType = any>(
keyOrType: KeyOrType, keyOrType: KeyOrType,
): GetReturnType<T, KeyOrType> | undefined { ): IPublicTypeEditorGetResult<T, KeyOrType> | undefined {
return this.context.get(keyOrType as any); return this.context.get(keyOrType as any);
} }
has(keyOrType: KeyType): boolean { has(keyOrType: IPublicTypeEditorValueKey): boolean {
return this.context.has(keyOrType); return this.context.has(keyOrType);
} }
set(key: KeyType, data: any): void | Promise<void> { set(key: IPublicTypeEditorValueKey, data: any): void | Promise<void> {
if (key === 'assets') { if (key === 'assets') {
return this.setAssets(data); return this.setAssets(data);
} }
@ -172,7 +173,7 @@ export class Editor extends (EventEmitter as any) implements IPublicModelEditor
this.notifyGot('assets'); this.notifyGot('assets');
} }
onceGot<T = undefined, KeyOrType extends KeyType = any>(keyOrType: KeyOrType): Promise<GetReturnType<T, KeyOrType>> { onceGot<T = undefined, KeyOrType extends IPublicTypeEditorValueKey = any>(keyOrType: KeyOrType): Promise<IPublicTypeEditorGetResult<T, KeyOrType>> {
const x = this.context.get(keyOrType); const x = this.context.get(keyOrType);
if (x !== undefined) { if (x !== undefined) {
return Promise.resolve(x); return Promise.resolve(x);
@ -182,9 +183,9 @@ export class Editor extends (EventEmitter as any) implements IPublicModelEditor
}); });
} }
onGot<T = undefined, KeyOrType extends KeyType = any>( onGot<T = undefined, KeyOrType extends IPublicTypeEditorValueKey = any>(
keyOrType: KeyOrType, keyOrType: KeyOrType,
fn: (data: GetReturnType<T, KeyOrType>) => void, fn: (data: IPublicTypeEditorGetResult<T, KeyOrType>) => void,
): () => void { ): () => void {
const x = this.context.get(keyOrType); const x = this.context.get(keyOrType);
if (x !== undefined) { if (x !== undefined) {
@ -198,7 +199,7 @@ export class Editor extends (EventEmitter as any) implements IPublicModelEditor
} }
} }
register(data: any, key?: KeyType): void { register(data: any, key?: IPublicTypeEditorValueKey): void {
this.context.set(key || data, data); this.context.set(key || data, data);
this.notifyGot(key || data); this.notifyGot(key || data);
} }
@ -273,7 +274,7 @@ export class Editor extends (EventEmitter as any) implements IPublicModelEditor
/* eslint-disable */ /* eslint-disable */
private waits = new Map< private waits = new Map<
KeyType, IPublicTypeEditorValueKey,
Array<{ Array<{
once?: boolean; once?: boolean;
resolve: (data: any) => void; resolve: (data: any) => void;
@ -281,7 +282,7 @@ export class Editor extends (EventEmitter as any) implements IPublicModelEditor
>(); >();
/* eslint-enable */ /* eslint-enable */
private notifyGot(key: KeyType) { private notifyGot(key: IPublicTypeEditorValueKey) {
let waits = this.waits.get(key); let waits = this.waits.get(key);
if (!waits) { if (!waits) {
return; return;
@ -301,7 +302,7 @@ export class Editor extends (EventEmitter as any) implements IPublicModelEditor
} }
} }
private setWait(key: KeyType, resolve: (data: any) => void, once?: boolean) { private setWait(key: IPublicTypeEditorValueKey, resolve: (data: any) => void, once?: boolean) {
const waits = this.waits.get(key); const waits = this.waits.get(key);
if (waits) { if (waits) {
waits.push({ resolve, once }); waits.push({ resolve, once });
@ -310,7 +311,7 @@ export class Editor extends (EventEmitter as any) implements IPublicModelEditor
} }
} }
private delWait(key: KeyType, fn: any) { private delWait(key: IPublicTypeEditorValueKey, fn: any) {
const waits = this.waits.get(key); const waits = this.waits.get(key);
if (!waits) { if (!waits) {
return; return;

View File

@ -1,12 +1,20 @@
/* eslint-disable max-len */ /* eslint-disable max-len */
import { obx, computed, makeObservable } from '@alilc/lowcode-editor-core'; import { obx, computed, makeObservable } from '@alilc/lowcode-editor-core';
import { Logger } from '@alilc/lowcode-utils'; import { Logger } from '@alilc/lowcode-utils';
import { IPublicTypeWidgetBaseConfig, IArea } from '@alilc/lowcode-types'; import { IPublicTypeWidgetBaseConfig } from '@alilc/lowcode-types';
import { WidgetContainer } from './widget/widget-container'; import { WidgetContainer } from './widget/widget-container';
import { Skeleton } from './skeleton'; import { Skeleton } from './skeleton';
import { IWidget } from './widget/widget'; import { IWidget } from './widget/widget';
const logger = new Logger({ level: 'warn', bizName: 'skeleton:area' }); const logger = new Logger({ level: 'warn', bizName: 'skeleton:area' });
export interface IArea<C, T> {
isEmpty(): boolean;
add(config: T | C): T;
remove(config: T | string): number;
setVisible(flag: boolean): void;
hide(): void;
show(): void;
}
export class Area<C extends IPublicTypeWidgetBaseConfig = any, T extends IWidget = IWidget> implements IArea<C, T> { export class Area<C extends IPublicTypeWidgetBaseConfig = any, T extends IWidget = IWidget> implements IArea<C, T> {
@obx private _visible = true; @obx private _visible = true;

View File

@ -9,7 +9,7 @@ import {
import { import {
IPublicModelDragObject, IPublicModelDragObject,
IPublicModelScrollable, IPublicModelScrollable,
ISensor, IPublicModelSensor,
IPublicTypeLocationChildrenDetail, IPublicTypeLocationChildrenDetail,
IPublicTypeLocationDetailType, IPublicTypeLocationDetailType,
IPublicModelNode, IPublicModelNode,
@ -24,7 +24,7 @@ import { IndentTrack } from '../helper/indent-track';
import DwellTimer from '../helper/dwell-timer'; import DwellTimer from '../helper/dwell-timer';
import { ITreeBoard, TreeMaster } from './tree-master'; import { ITreeBoard, TreeMaster } from './tree-master';
export class PaneController implements ISensor, ITreeBoard, IPublicModelScrollable { export class PaneController implements IPublicModelSensor, ITreeBoard, IPublicModelScrollable {
private pluginContext: IPublicModelPluginContext; private pluginContext: IPublicModelPluginContext;
private treeMaster?: TreeMaster; private treeMaster?: TreeMaster;
@ -50,12 +50,12 @@ export class PaneController implements ISensor, ITreeBoard, IPublicModelScrollab
setup(); setup();
} }
/** -------------------- ISensor begin -------------------- */ /** -------------------- IPublicModelSensor begin -------------------- */
private indentTrack = new IndentTrack(); private indentTrack = new IndentTrack();
/** /**
* @see ISensor * @see IPublicModelSensor
*/ */
fixEvent(e: IPublicModelLocateEvent): IPublicModelLocateEvent { fixEvent(e: IPublicModelLocateEvent): IPublicModelLocateEvent {
if (e.fixed) { if (e.fixed) {
@ -77,7 +77,7 @@ export class PaneController implements ISensor, ITreeBoard, IPublicModelScrollab
} }
/** /**
* @see ISensor * @see IPublicModelSensor
*/ */
locate(e: IPublicModelLocateEvent): IPublicModelDropLocation | undefined | null { locate(e: IPublicModelLocateEvent): IPublicModelDropLocation | undefined | null {
this.sensing = true; this.sensing = true;
@ -213,7 +213,7 @@ export class PaneController implements ISensor, ITreeBoard, IPublicModelScrollab
} }
/** /**
* @see ISensor * @see IPublicModelSensor
*/ */
isEnter(e: IPublicModelLocateEvent): boolean { isEnter(e: IPublicModelLocateEvent): boolean {
if (!this._shell) { if (!this._shell) {
@ -224,7 +224,7 @@ export class PaneController implements ISensor, ITreeBoard, IPublicModelScrollab
} }
/** /**
* @see ISensor * @see IPublicModelSensor
*/ */
deactiveSensor() { deactiveSensor() {
this.sensing = false; this.sensing = false;
@ -234,15 +234,15 @@ export class PaneController implements ISensor, ITreeBoard, IPublicModelScrollab
} }
private _sensorAvailable = false; private _sensorAvailable = false;
/** /**
* @see ISensor * @see IPublicModelSensor
*/ */
get sensorAvailable() { get sensorAvailable() {
return this._sensorAvailable; return this._sensorAvailable;
} }
/** -------------------- ISensor end -------------------- */ /** -------------------- IPublicModelSensor end -------------------- */
/** -------------------- ITreeBoard begin -------------------- */ /** -------------------- ITreeBoard begin -------------------- */
@ -564,7 +564,6 @@ export class PaneController implements ISensor, ITreeBoard, IPublicModelScrollab
return this._scrollTarget; return this._scrollTarget;
} }
private scroller?: IPublicModelScroller; private scroller?: IPublicModelScroller;
purge() { purge() {
@ -573,7 +572,6 @@ export class PaneController implements ISensor, ITreeBoard, IPublicModelScrollab
this.treeMaster?.removeBoard(this); this.treeMaster?.removeBoard(this);
} }
private _shell: HTMLDivElement | null = null; private _shell: HTMLDivElement | null = null;
mount(shell: HTMLDivElement | null) { mount(shell: HTMLDivElement | null) {

View File

@ -1,5 +1,5 @@
import { BuiltinSimulatorRenderer, Component, DocumentModel, Node } from '@alilc/lowcode-designer'; import { BuiltinSimulatorRenderer, Component, DocumentModel, Node } from '@alilc/lowcode-designer';
import { IPublicTypeComponentSchema, IPublicTypeNodeSchema, IPublicTypeNpmInfo, IPublicEnumTransformStage, NodeInstance } from '@alilc/lowcode-types'; import { IPublicTypeComponentSchema, IPublicTypeNodeSchema, IPublicTypeNpmInfo, IPublicEnumTransformStage, IPublicTypeNodeInstance } from '@alilc/lowcode-types';
import { Asset, compatibleLegaoSchema, cursor, isElement, isESModule, isPlainObject, isReactComponent, setNativeSelection } from '@alilc/lowcode-utils'; import { Asset, compatibleLegaoSchema, cursor, isElement, isESModule, isPlainObject, isReactComponent, setNativeSelection } from '@alilc/lowcode-utils';
import LowCodeRenderer from '@alilc/lowcode-rax-renderer'; import LowCodeRenderer from '@alilc/lowcode-rax-renderer';
import { computed, observable as obx, makeObservable, configure } from 'mobx'; import { computed, observable as obx, makeObservable, configure } from 'mobx';
@ -94,7 +94,7 @@ function isValidDesignModeRaxComponentInstance(
raxComponentInst: any, raxComponentInst: any,
): raxComponentInst is { ): raxComponentInst is {
props: { props: {
_leaf: Exclude<NodeInstance<any>['node'], null | undefined>; _leaf: Exclude<IPublicTypeNodeInstance<any>['node'], null | undefined>;
}; };
} { } {
const leaf = raxComponentInst?.props?._leaf; const leaf = raxComponentInst?.props?._leaf;
@ -370,6 +370,7 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer {
@computed get componentsMap(): any { @computed get componentsMap(): any {
return this._componentsMap; return this._componentsMap;
} }
/** /**
* *
*/ */
@ -396,7 +397,7 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer {
} }
} }
getNodeInstance(dom: HTMLElement): NodeInstance<any> | null { getNodeInstance(dom: HTMLElement): IPublicTypeNodeInstance<any> | null {
const INTERNAL = '_internal'; const INTERNAL = '_internal';
let instance: any = dom; let instance: any = dom;
if (!isElement(instance)) { if (!isElement(instance)) {
@ -429,7 +430,7 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer {
return null; return null;
} }
getClosestNodeInstance(from: any, nodeId?: string): NodeInstance<any> | null { getClosestNodeInstance(from: any, nodeId?: string): IPublicTypeNodeInstance<any> | null {
const el: any = from; const el: any = from;
if (el) { if (el) {
// if (isElement(el)) { // if (isElement(el)) {
@ -510,7 +511,6 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer {
doc.getElementsByTagName('head')[0].appendChild(s); doc.getElementsByTagName('head')[0].appendChild(s);
} }
const renderer = this; const renderer = this;
const { componentsMap: components } = renderer; const { componentsMap: components } = renderer;

View File

@ -17,7 +17,7 @@ import {
AssetLoader, AssetLoader,
getProjectUtils, getProjectUtils,
} from '@alilc/lowcode-utils'; } from '@alilc/lowcode-utils';
import { IPublicTypeComponentSchema, IPublicEnumTransformStage, IPublicTypeNodeSchema, NodeInstance } from '@alilc/lowcode-types'; import { IPublicTypeComponentSchema, IPublicEnumTransformStage, IPublicTypeNodeSchema, IPublicTypeNodeInstance } from '@alilc/lowcode-types';
// just use types // just use types
import { BuiltinSimulatorRenderer, Component, DocumentModel, Node } from '@alilc/lowcode-designer'; import { BuiltinSimulatorRenderer, Component, DocumentModel, Node } from '@alilc/lowcode-designer';
import LowCodeRenderer from '@alilc/lowcode-react-renderer'; import LowCodeRenderer from '@alilc/lowcode-react-renderer';
@ -368,6 +368,7 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer {
* *
*/ */
autoRepaintNode = true; autoRepaintNode = true;
/** /**
* *
*/ */
@ -399,7 +400,7 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer {
} }
} }
getClosestNodeInstance(from: ReactInstance, nodeId?: string): NodeInstance<ReactInstance> | null { getClosestNodeInstance(from: ReactInstance, nodeId?: string): IPublicTypeNodeInstance<ReactInstance> | null {
return getClosestNodeInstance(from, nodeId); return getClosestNodeInstance(from, nodeId);
} }
@ -557,7 +558,7 @@ const SYMBOL_VDID = Symbol('_LCDocId');
function getClosestNodeInstance( function getClosestNodeInstance(
from: ReactInstance, from: ReactInstance,
specId?: string, specId?: string,
): NodeInstance<ReactInstance> | null { ): IPublicTypeNodeInstance<ReactInstance> | null {
let el: any = from; let el: any = from;
if (el) { if (el) {
if (isElement(el)) { if (isElement(el)) {
@ -587,7 +588,7 @@ function getClosestNodeInstance(
return null; return null;
} }
function getNodeInstance(fiberNode: any, specId?: string): NodeInstance<ReactInstance> | null { function getNodeInstance(fiberNode: any, specId?: string): IPublicTypeNodeInstance<ReactInstance> | null {
const instance = fiberNode?.stateNode; const instance = fiberNode?.stateNode;
if (instance && SYMBOL_VNID in instance) { if (instance && SYMBOL_VNID in instance) {
const nodeId = instance[SYMBOL_VNID]; const nodeId = instance[SYMBOL_VNID];

View File

@ -4,7 +4,6 @@ import {
IPublicModelScrollTarget, IPublicModelScrollTarget,
IPublicModelScrollable, IPublicModelScrollable,
IPublicModelScroller, IPublicModelScroller,
IDesigner,
IPublicTypeLocationData, IPublicTypeLocationData,
IPublicModelEditor, IPublicModelEditor,
IPublicModelDragon, IPublicModelDragon,
@ -12,13 +11,13 @@ import {
} from '@alilc/lowcode-types'; } from '@alilc/lowcode-types';
import { import {
ScrollTarget as InnerScrollTarget, ScrollTarget as InnerScrollTarget,
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 { Dragon } from '../model';
import { DropLocation } from '../model/drop-location'; import { DropLocation } from '../model/drop-location';
import { ActiveTracker } from '../model/active-tracker'; import { ActiveTracker } from '../model/active-tracker';
export class Canvas implements IPublicApiCanvas { export class Canvas implements IPublicApiCanvas {
private readonly [editorSymbol]: IPublicModelEditor; private readonly [editorSymbol]: IPublicModelEditor;

View File

@ -25,7 +25,6 @@ import {
IPublicTypeLocationDetailType as InnerLocationDetailType, IPublicTypeLocationDetailType as InnerLocationDetailType,
IPublicApiCommonEditorCabin, IPublicApiCommonEditorCabin,
IPublicModelDragon, IPublicModelDragon,
IDesigner,
} from '@alilc/lowcode-types'; } from '@alilc/lowcode-types';
import { import {
SettingField as InnerSettingField, SettingField as InnerSettingField,
@ -35,6 +34,7 @@ import {
ScrollTarget as InnerScrollTarget, ScrollTarget as InnerScrollTarget,
getConvertedExtraKey as innerGetConvertedExtraKey, getConvertedExtraKey as innerGetConvertedExtraKey,
getOriginalExtraKey as innerGetOriginalExtraKey, getOriginalExtraKey as innerGetOriginalExtraKey,
IDesigner,
} from '@alilc/lowcode-designer'; } from '@alilc/lowcode-designer';
import { import {
Skeleton as InnerSkeleton, Skeleton as InnerSkeleton,
@ -63,6 +63,7 @@ import { ReactNode, Component } from 'react';
class DesignerCabin implements IPublicApiCommonDesignerCabin { class DesignerCabin implements IPublicApiCommonDesignerCabin {
private readonly [editorSymbol]: Editor; private readonly [editorSymbol]: Editor;
/** /**
* @deprecated * @deprecated
*/ */
@ -240,6 +241,7 @@ class EditorCabin implements IPublicApiCommonEditorCabin {
constructor(editor: Editor) { constructor(editor: Editor) {
this[editorSymbol] = editor; this[editorSymbol] = editor;
} }
/** /**
* Title * Title
* @experimental unstable API, pay extra caution when trying to use this * @experimental unstable API, pay extra caution when trying to use this
@ -335,7 +337,6 @@ class EditorCabin implements IPublicApiCommonEditorCabin {
} }
} }
export class Common implements IPublicApiCommon { export class Common implements IPublicApiCommon {
private readonly __designerCabin: any; private readonly __designerCabin: any;
private readonly __skeletonCabin: any; private readonly __skeletonCabin: any;

View File

@ -3,14 +3,13 @@ import {
DocumentModel as InnerDocumentModel, DocumentModel as InnerDocumentModel,
Node as InnerNode, Node as InnerNode,
isDragNodeObject, isDragNodeObject,
IOnChangeOptions as InnerOnChangeOptions,
} from '@alilc/lowcode-designer'; } from '@alilc/lowcode-designer';
import { import {
IPublicEnumTransformStage, IPublicEnumTransformStage,
IPublicTypeRootSchema, IPublicTypeRootSchema,
GlobalEvent, GlobalEvent,
IPublicModelDocumentModel, IPublicModelDocumentModel,
IPublicOnChangeOptions, IPublicTypeOnChangeOptions,
IPublicModelDragObject, IPublicModelDragObject,
IPublicTypeDragNodeObject, IPublicTypeDragNodeObject,
IPublicTypeDragNodeDataObject, IPublicTypeDragNodeDataObject,
@ -45,6 +44,7 @@ export class DocumentModel implements IPublicModelDocumentModel {
selection: IPublicModelSelection; selection: IPublicModelSelection;
detecting: IPublicModelDetecting; detecting: IPublicModelDetecting;
history: IPublicModelHistory; history: IPublicModelHistory;
/** /**
* @deprecated use canvas API instead * @deprecated use canvas API instead
*/ */
@ -141,6 +141,7 @@ export class DocumentModel implements IPublicModelDocumentModel {
set dropLocation(loc: IPublicModelDropLocation | null) { set dropLocation(loc: IPublicModelDropLocation | null) {
this[documentSymbol].dropLocation = loc; this[documentSymbol].dropLocation = loc;
} }
/** /**
* nodeId Node * nodeId Node
* get node instance by nodeId * get node instance by nodeId
@ -297,8 +298,8 @@ export class DocumentModel implements IPublicModelDocumentModel {
* document children * document children
* @param fn * @param fn
*/ */
onChangeNodeChildren(fn: (info: IPublicOnChangeOptions) => void): void { onChangeNodeChildren(fn: (info: IPublicTypeOnChangeOptions) => void): void {
this[documentSymbol].onChangeNodeChildren((info?: IPublicOnChangeOptions) => { this[documentSymbol].onChangeNodeChildren((info?: IPublicTypeOnChangeOptions) => {
if (!info) { if (!info) {
return; return;
} }

View File

@ -7,7 +7,7 @@ export enum ActivityType {
'COMPOSITE' = 'composite', 'COMPOSITE' = 'composite',
} }
export interface IActivityPayload { interface IActivityPayload {
schema: IPublicTypeNodeSchema; schema: IPublicTypeNodeSchema;
location?: { location?: {
parent: { parent: {
@ -20,6 +20,10 @@ export interface IActivityPayload {
newValue: any; newValue: any;
} }
/**
* TODO: not sure if this is used anywhere
* @deprecated
*/
export type ActivityData = { export type ActivityData = {
type: ActivityType; type: ActivityType;
payload: IActivityPayload; payload: IActivityPayload;

View File

@ -1,12 +1,3 @@
export interface AssetItem {
type: AssetType;
content?: string | null;
device?: string;
level?: AssetLevel;
id?: string;
}
export enum AssetLevel { export enum AssetLevel {
// 环境依赖库 比如 react, react-dom // 环境依赖库 比如 react, react-dom
Environment = 1, Environment = 1,
@ -41,12 +32,20 @@ export enum AssetType {
Bundle = 'bundle', Bundle = 'bundle',
} }
export interface AssetItem {
type: AssetType;
content?: string | null;
device?: string;
level?: AssetLevel;
id?: string;
}
export type AssetList = Array<Asset | undefined | null>;
export type Asset = AssetList | AssetBundle | AssetItem | URL;
export interface AssetBundle { export interface AssetBundle {
type: AssetType.Bundle; type: AssetType.Bundle;
level?: AssetLevel; level?: AssetLevel;
assets?: Asset | AssetList | null; assets?: Asset | AssetList | null;
} }
export type Asset = AssetList | AssetBundle | AssetItem | URL;
export type AssetList = Array<Asset | undefined | null>;

View File

@ -1,25 +0,0 @@
import { IPublicModelNode, IPublicModelDragon, IPublicModelDropLocation, IPublicModelScroller, IPublicModelScrollable, IPublicTypeComponentInstance, IPublicTypeLocationData, IPublicModelActiveTracker } from './shell';
export interface IPublicOnChangeOptions {
type: string;
node: IPublicModelNode;
}
export interface NodeInstance<T = IPublicTypeComponentInstance> {
docId: string;
nodeId: string;
instance: T;
node?: Node | null;
}
export interface IDesigner {
get dragon(): IPublicModelDragon;
get activeTracker(): IPublicModelActiveTracker;
createScroller(scrollable: IPublicModelScrollable): IPublicModelScroller;
/**
* dragon
*/
createLocation(locationData: IPublicTypeLocationData): IPublicModelDropLocation;
}

View File

@ -1,82 +0,0 @@
import { NodeInstance } from './designer';
import {
IPublicModelDocumentModel,
IPublicModelLocateEvent,
IPublicModelDropLocation,
IPublicTypeComponentInstance,
} from './shell';
import { IPublicTypeDragObject } from './shell/type/drag-object';
export interface LocateEvent {
readonly type: 'LocateEvent';
/**
*
*/
readonly globalX: number;
readonly globalY: number;
/**
*
*/
readonly originalEvent: MouseEvent | DragEvent;
/**
*
*/
readonly dragObject: IPublicTypeDragObject;
/**
*
*/
sensor?: ISensor;
// ======= 以下是 激活的 sensor 将填充的值 ========
/**
*
*/
target?: Element | null;
/**
*
*/
canvasX?: number;
canvasY?: number;
/**
*
*/
documentModel?: IPublicModelDocumentModel;
/**
* canvasX,canvasY,
*/
fixed?: true;
}
/**
*
*/
export interface ISensor {
/**
* false
*/
readonly sensorAvailable: boolean;
/**
*
*/
fixEvent(e: IPublicModelLocateEvent): IPublicModelLocateEvent;
/**
*
*/
locate(e: IPublicModelLocateEvent): IPublicModelDropLocation | undefined | null;
/**
*
*/
isEnter(e: IPublicModelLocateEvent): boolean;
/**
*
*/
deactiveSensor(): void;
/**
*
*/
getNodeInstanceFromElement?: (e: Element | null) => NodeInstance<IPublicTypeComponentInstance> | null;
}

View File

@ -1,8 +0,0 @@
export interface IArea<C, T> {
isEmpty(): boolean;
add(config: T | C): T;
remove(config: T | string): number;
setVisible(flag: boolean): void;
hide(): void;
show(): void;
}

View File

@ -1,34 +1,6 @@
import { ReactNode, ComponentType } from 'react'; import { ReactNode, ComponentType } from 'react';
import { IPublicTypeNpmInfo, IPublicModelEditor } from './shell'; import { IPublicTypeNpmInfo, IPublicModelEditor } from './shell';
export type KeyType = (new (...args: any[]) => any) | symbol | string;
export type ClassType = new (...args: any[]) => any;
export interface GetOptions {
forceNew?: boolean;
sourceCls?: ClassType;
}
export type GetReturnType<T, ClsType> = T extends undefined
? ClsType extends {
prototype: infer R;
}
? R
: any
: T;
/**
* duck-typed power-di
*
* @see https://www.npmjs.com/package/power-di
*/
export interface PowerDIRegisterOptions {
/** default: true */
singleton?: boolean;
/** if data a class, auto new a instance.
* if data a function, auto run(lazy).
* default: true */
autoNew?: boolean;
}
export interface EditorConfig { export interface EditorConfig {
skeleton?: SkeletonConfig; skeleton?: SkeletonConfig;
theme?: ThemeConfig; theme?: ThemeConfig;
@ -172,10 +144,4 @@ export interface PluginStatus {
export interface PluginStatusSet { export interface PluginStatusSet {
[key: string]: PluginStatus; [key: string]: PluginStatus;
}
export enum EDITOR_EVENT {
NODE_CHILDREN_CHANGE = 'node.children.change',
NODE_VISIBLE_CHANGE = 'node.visible.change',
} }

View File

@ -1,29 +1,10 @@
export * from '@alilc/lowcode-datasource-types'; export * from '@alilc/lowcode-datasource-types';
export * from './editor'; export * from './editor';
export * from './shell/type/field-extra-props';
export * from './shell/type/i18n-map';
export * from './shell/type/icon-config';
export * from './shell/type/metadata';
export * from './shell/type/npm';
export * from './shell/type/prop-types';
export * from './schema';
export * from './activity'; export * from './activity';
export * from './shell/type/tip-config';
export * from './shell/type/title-content';
export * from './utils';
export * from './shell/type/value-type';
export * from './shell/type/setter-config';
export * from './shell/model/setting-target';
export * from './node';
export * from './shell/enum/transform-stage';
export * from './code-intermediate'; export * from './code-intermediate';
export * from './code-result'; export * from './code-result';
export * from './assets'; export * from './assets';
export * as GlobalEvent from './event'; export * as GlobalEvent from './event';
export * from './shell/type/props-transducer';
export * from './editor-skeleton';
export * from './designer';
export * from './dragon';
export * from './shell'; export * from './shell';
export * from './shell-model-factory'; export * from './shell-model-factory';
// TODO: remove this in future versions // TODO: remove this in future versions

View File

@ -1,10 +0,0 @@
export interface NodeStatus {
locking: boolean;
pseudo: boolean;
inPlaceEditing: boolean;
}
export interface LeafNode extends Node {
readonly children: null;
}

View File

@ -1,19 +0,0 @@
import { IPublicTypeNodeSchema } from './shell/type/node-schema';
import { IPublicTypeNodeData } from './shell/type/node-data';
export type NodeDataType = IPublicTypeNodeData | IPublicTypeNodeData[];
/**
* Slot schema
*/
export interface SlotSchema extends IPublicTypeNodeSchema {
componentName: 'Slot';
name?: string;
title?: string;
params?: string[];
props?: {
slotTitle?: string;
slotName?: string;
slotParams?: string[];
};
children?: IPublicTypeNodeSchema[];
}

View File

@ -2,7 +2,7 @@ import { IPublicTypeRootSchema, IPublicTypeDragNodeDataObject, IPublicTypeDragNo
import { IPublicEnumTransformStage } from '../enum'; import { IPublicEnumTransformStage } from '../enum';
import { IPublicApiProject } from '../api'; import { IPublicApiProject } from '../api';
import { IPublicModelDropLocation, IPublicModelDetecting, IPublicModelNode, IPublicModelSelection, IPublicModelHistory, IPublicModelModalNodesManager } from './'; import { IPublicModelDropLocation, IPublicModelDetecting, IPublicModelNode, IPublicModelSelection, IPublicModelHistory, IPublicModelModalNodesManager } from './';
import { IPublicOnChangeOptions } from '@alilc/lowcode-types'; import { IPublicTypeOnChangeOptions } from '@alilc/lowcode-types';
export interface IPublicModelDocumentModel { export interface IPublicModelDocumentModel {
@ -168,12 +168,11 @@ export interface IPublicModelDocumentModel {
*/ */
onChangeNodeVisible(fn: (node: IPublicModelNode, visible: boolean) => void): void; onChangeNodeVisible(fn: (node: IPublicModelNode, visible: boolean) => void): void;
/** /**
* document children * document children
* @param fn * @param fn
*/ */
onChangeNodeChildren(fn: (info: IPublicOnChangeOptions) => void): void; onChangeNodeChildren(fn: (info: IPublicTypeOnChangeOptions) => void): void;
/** /**
* document * document
@ -210,7 +209,6 @@ export interface IPublicModelDocumentModel {
*/ */
set dropLocation(loc: IPublicModelDropLocation | null); set dropLocation(loc: IPublicModelDropLocation | null);
/** /**
* *
* triggered focused node is set mannually from plugin * triggered focused node is set mannually from plugin

View File

@ -3,27 +3,26 @@ 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 { GetOptions, GetReturnType, KeyType, PowerDIRegisterOptions } from '../../editor'; import { IPublicTypeEditorValueKey, IPublicTypeEditorGetOptions, IPublicTypeEditorGetResult, IPublicTypeEditorRegisterOptions } 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>(
keyOrType: KeyOrType, keyOrType: KeyOrType,
opt?: GetOptions opt?: IPublicTypeEditorGetOptions
) => GetReturnType<T, KeyOrType> | undefined; ) => IPublicTypeEditorGetResult<T, KeyOrType> | undefined;
has: (keyOrType: KeyType) => boolean; has: (keyOrType: IPublicTypeEditorValueKey) => boolean;
set: (key: KeyType, data: any) => void | Promise<void>; set: (key: IPublicTypeEditorValueKey, data: any) => void | Promise<void>;
onceGot: <T = undefined, KeyOrType extends KeyType = any>(keyOrType: KeyOrType) => Promise<GetReturnType<T, KeyOrType>>; onceGot: <T = undefined, KeyOrType extends IPublicTypeEditorValueKey = any>(keyOrType: KeyOrType) => Promise<IPublicTypeEditorGetResult<T, KeyOrType>>;
onGot: <T = undefined, KeyOrType extends KeyType = any>( onGot: <T = undefined, KeyOrType extends IPublicTypeEditorValueKey = any>(
keyOrType: KeyOrType, keyOrType: KeyOrType,
fn: (data: GetReturnType<T, KeyOrType>) => void fn: (data: IPublicTypeEditorGetResult<T, KeyOrType>) => void
) => () => void; ) => () => void;
register: (data: any, key?: KeyType, options?: PowerDIRegisterOptions) => void; register: (data: any, key?: IPublicTypeEditorValueKey, options?: IPublicTypeEditorRegisterOptions) => void;
get eventBus(): IPublicApiEvent; get eventBus(): IPublicApiEvent;
} }

View File

@ -26,4 +26,5 @@ export * from './setting-target';
export * from './engine-config'; export * from './engine-config';
export * from './editor'; export * from './editor';
export * from './preference'; export * from './preference';
export * from './plugin-instance'; export * from './plugin-instance';
export * from './sensor';

View File

@ -0,0 +1,42 @@
import { IPublicTypeNodeInstance } from '../type/node-instance';
import {
IPublicModelLocateEvent,
IPublicModelDropLocation,
IPublicTypeComponentInstance,
} from '..';
/**
*
*/
export interface IPublicModelSensor {
/**
* false
*/
readonly sensorAvailable: boolean;
/**
*
*/
fixEvent(e: IPublicModelLocateEvent): IPublicModelLocateEvent;
/**
*
*/
locate(e: IPublicModelLocateEvent): IPublicModelDropLocation | undefined | null;
/**
*
*/
isEnter(e: IPublicModelLocateEvent): boolean;
/**
*
*/
deactiveSensor(): void;
/**
*
*/
getNodeInstanceFromElement?: (e: Element | null) => IPublicTypeNodeInstance<IPublicTypeComponentInstance> | null;
}

View File

@ -0,0 +1,5 @@
export interface IPublicTypeEditorGetOptions {
forceNew?: boolean;
sourceCls?: new (...args: any[]) => any;
}

View File

@ -0,0 +1,4 @@
export type IPublicTypeEditorGetResult<T, ClsType> = T extends undefined ? ClsType extends {
prototype: infer R;
} ? R : any : T;

View File

@ -0,0 +1,19 @@
/**
* duck-typed power-di
*
* @see https://www.npmjs.com/package/power-di
*/
export interface IPublicTypeEditorRegisterOptions {
/**
* default: true
*/
singleton?: boolean;
/**
* if data a class, auto new a instance.
* if data a function, auto run(lazy).
* default: true
*/
autoNew?: boolean;
}

View File

@ -0,0 +1,2 @@
export type IPublicTypeEditorValueKey = (new (...args: any[]) => any) | symbol | string;

View File

@ -1,6 +1,6 @@
// this folder contains all interfaces/types working as type definition // this folder contains all interfaces/types working as type definition
// - some exists as type TypeName // - some exists as type TypeName
// - some althought exists as interfaces , but there won`t be a class implements them. // - some althought exists as interfaces , but there won`t be any class implements them.
// all of above cases will with prefix IPublicType, eg. IPublicTypeSomeName // all of above cases will with prefix IPublicType, eg. IPublicTypeSomeName
export * from './location'; export * from './location';
export * from './active-target'; export * from './active-target';
@ -74,4 +74,12 @@ export * from './widget-config-area';
export * from './hotkey-callback'; export * from './hotkey-callback';
export * from './plugin-register-options'; export * from './plugin-register-options';
export * from './resource-options'; export * from './resource-options';
export * from './engine-options'; export * from './engine-options';
export * from './on-change-options';
export * from './slot-schema';
export * from './node-data-type';
export * from './node-instance';
export * from './editor-value-key';
export * from './editor-get-options';
export * from './editor-get-result';
export * from './editor-register-options';

View File

@ -0,0 +1,3 @@
import { IPublicTypeNodeData } from './node-data';
export type IPublicTypeNodeDataType = IPublicTypeNodeData | IPublicTypeNodeData[];

View File

@ -0,0 +1,8 @@
import { IPublicTypeComponentInstance, IPublicModelNode } from '..';
export interface IPublicTypeNodeInstance<T = IPublicTypeComponentInstance> {
docId: string;
nodeId: string;
instance: T;
node?: IPublicModelNode | null;
}

View File

@ -0,0 +1,6 @@
import { IPublicModelNode } from '..';
export interface IPublicTypeOnChangeOptions {
type: string;
node: IPublicModelNode;
}

View File

@ -0,0 +1,17 @@
import { IPublicTypeNodeSchema } from './node-schema';
/**
* Slot schema
*/
export interface IPublicTypeSlotSchema extends IPublicTypeNodeSchema {
componentName: 'Slot';
name?: string;
title?: string;
params?: string[];
props?: {
slotTitle?: string;
slotName?: string;
slotParams?: string[];
};
children?: IPublicTypeNodeSchema[];
}

View File

@ -119,6 +119,10 @@ function getNodeSchemaFromPropsById(props: any, nodeId: string): IPublicTypeNode
} }
} }
/**
* TODO: not sure if this is used anywhere
* @deprecated
*/
export function applyActivities(pivotSchema: IPublicTypeRootSchema, activities: any, options?: any): IPublicTypeRootSchema { export function applyActivities(pivotSchema: IPublicTypeRootSchema, activities: any, options?: any): IPublicTypeRootSchema {
let schema = { ...pivotSchema }; let schema = { ...pivotSchema };
if (!Array.isArray(activities)) { if (!Array.isArray(activities)) {