mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2025-12-11 18:42:56 +00:00
feat: add types for shell, and move functions in types to utils
This commit is contained in:
parent
aed94f1532
commit
55c3fc9e58
@ -248,7 +248,7 @@ onChangeNodeVisible(fn: (node: Node, visible: boolean) => void)
|
||||
|
||||
### onChangeNodeChildren
|
||||
|
||||
onChangeNodeChildren(fn: (info?: IOnChangeOptions) => void)
|
||||
onChangeNodeChildren(fn: (info?: IPublicOnChangeOptions) => void)
|
||||
|
||||
当前 document 的节点 children 变更事件
|
||||
|
||||
|
||||
@ -147,7 +147,7 @@ const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) =>
|
||||
function __$$eval(expr) {
|
||||
try {
|
||||
return expr();
|
||||
} catch (error) {
|
||||
} catch (error) {
|
||||
${evalErrorsHandler}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,7 +2,8 @@ import * as React from 'react';
|
||||
import { Component, Fragment, ReactElement, PureComponent } from 'react';
|
||||
import classNames from 'classnames';
|
||||
import { computed, observer, Title, globalLocale } from '@alilc/lowcode-editor-core';
|
||||
import { I18nData, isI18nData, TitleContent } from '@alilc/lowcode-types';
|
||||
import { I18nData, TitleContent } from '@alilc/lowcode-types';
|
||||
import { isI18nData } from '@alilc/lowcode-utils';
|
||||
import { DropLocation } from '../../designer';
|
||||
import { BuiltinSimulatorHost } from '../../builtin-simulator/host';
|
||||
import { ParentalNode } from '../../document/node';
|
||||
|
||||
@ -9,9 +9,9 @@ import {
|
||||
ComponentType,
|
||||
} from 'react';
|
||||
import classNames from 'classnames';
|
||||
import { observer, computed, Tip, globalContext, makeObservable } from '@alilc/lowcode-editor-core';
|
||||
import { createIcon, isReactComponent } from '@alilc/lowcode-utils';
|
||||
import { ActionContentObject, isActionContentObject } from '@alilc/lowcode-types';
|
||||
import { observer, computed, Tip, globalContext } from '@alilc/lowcode-editor-core';
|
||||
import { createIcon, isReactComponent, isActionContentObject } from '@alilc/lowcode-utils';
|
||||
import { ActionContentObject } from '@alilc/lowcode-types';
|
||||
import { BuiltinSimulatorHost } from '../host';
|
||||
import { OffsetObserver } from '../../designer';
|
||||
import { Node } from '../../document';
|
||||
|
||||
@ -39,8 +39,6 @@ import {
|
||||
transactionManager,
|
||||
} from '@alilc/lowcode-utils';
|
||||
import {
|
||||
DragObjectType,
|
||||
DragNodeObject,
|
||||
isShaken,
|
||||
LocateEvent,
|
||||
isDragAnyObject,
|
||||
@ -62,6 +60,8 @@ import {
|
||||
ComponentSchema,
|
||||
Package,
|
||||
TransitionType,
|
||||
DragObjectType,
|
||||
DragNodeObject,
|
||||
} from '@alilc/lowcode-types';
|
||||
import { BuiltinSimulatorRenderer } from './renderer';
|
||||
import clipboard from '../designer/clipboard';
|
||||
|
||||
@ -8,12 +8,12 @@ import {
|
||||
TitleContent,
|
||||
TransformedComponentMetadata,
|
||||
NestingFilter,
|
||||
isTitleConfig,
|
||||
I18nData,
|
||||
LiveTextEditingConfig,
|
||||
FieldConfig,
|
||||
MetadataTransducer,
|
||||
} from '@alilc/lowcode-types';
|
||||
import { deprecate, isRegExp } from '@alilc/lowcode-utils';
|
||||
import { deprecate, isRegExp, isTitleConfig } from '@alilc/lowcode-utils';
|
||||
import { computed, engineConfig } from '@alilc/lowcode-editor-core';
|
||||
import EventEmitter from 'events';
|
||||
import { componentDefaults, legacyIssues } from './transducers';
|
||||
@ -128,8 +128,8 @@ export class ComponentMeta {
|
||||
|
||||
private _isTopFixed?: boolean;
|
||||
|
||||
get isTopFixed() {
|
||||
return this._isTopFixed;
|
||||
get isTopFixed(): boolean {
|
||||
return !!(this._isTopFixed);
|
||||
}
|
||||
|
||||
private parentWhitelist?: NestingFilter | null;
|
||||
@ -279,7 +279,7 @@ export class ComponentMeta {
|
||||
return result as any;
|
||||
}
|
||||
|
||||
isRootComponent(includeBlock = true) {
|
||||
isRootComponent(includeBlock = true): boolean {
|
||||
return (
|
||||
this.componentName === 'Page' ||
|
||||
this.componentName === 'Component' ||
|
||||
@ -326,7 +326,7 @@ export class ComponentMeta {
|
||||
return true;
|
||||
}
|
||||
|
||||
checkNestingDown(my: Node, target: Node | NodeSchema | NodeSchema[]) {
|
||||
checkNestingDown(my: Node, target: Node | NodeSchema | NodeSchema[]): boolean {
|
||||
// 检查父子关系,直接约束型,在画布中拖拽直接掠过目标容器
|
||||
if (this.childWhitelist) {
|
||||
const _target: any = !Array.isArray(target) ? [target] : target;
|
||||
@ -375,19 +375,7 @@ function preprocessMetadata(metadata: ComponentMetadata): TransformedComponentMe
|
||||
};
|
||||
}
|
||||
|
||||
export interface MetadataTransducer {
|
||||
(prev: TransformedComponentMetadata): TransformedComponentMetadata;
|
||||
/**
|
||||
* 0 - 9 system
|
||||
* 10 - 99 builtin-plugin
|
||||
* 100 - app & plugin
|
||||
*/
|
||||
level?: number;
|
||||
/**
|
||||
* use to replace TODO
|
||||
*/
|
||||
id?: string;
|
||||
}
|
||||
|
||||
const metadataTransducers: MetadataTransducer[] = [];
|
||||
|
||||
export function registerMetadataTransducer(
|
||||
|
||||
@ -8,10 +8,10 @@ import {
|
||||
IEditor,
|
||||
CompositeObject,
|
||||
PropsList,
|
||||
isNodeSchema,
|
||||
NodeSchema,
|
||||
PropsTransducer,
|
||||
} from '@alilc/lowcode-types';
|
||||
import { megreAssets, AssetsJson } from '@alilc/lowcode-utils';
|
||||
import { megreAssets, AssetsJson, isNodeSchema } from '@alilc/lowcode-utils';
|
||||
import { Project } from '../project';
|
||||
import { Node, DocumentModel, insertChildren, ParentalNode, TransformStage } from '../document';
|
||||
import { ComponentMeta } from '../component-meta';
|
||||
@ -494,7 +494,7 @@ export class Designer {
|
||||
getComponentMeta(
|
||||
componentName: string,
|
||||
generateMetadata?: () => ComponentMetadata | null,
|
||||
): ComponentMeta {
|
||||
) {
|
||||
if (this._componentMetasMap.has(componentName)) {
|
||||
return this._componentMetasMap.get(componentName)!;
|
||||
}
|
||||
@ -536,7 +536,7 @@ export class Designer {
|
||||
return maps;
|
||||
}
|
||||
|
||||
private propsReducers = new Map<TransformStage, PropsReducer[]>();
|
||||
private propsReducers = new Map<TransformStage, PropsTransducer[]>();
|
||||
|
||||
transformProps(props: CompositeObject | PropsList, node: Node, stage: TransformStage) {
|
||||
if (Array.isArray(props)) {
|
||||
@ -560,7 +560,7 @@ export class Designer {
|
||||
}, props);
|
||||
}
|
||||
|
||||
addPropsReducer(reducer: PropsReducer, stage: TransformStage) {
|
||||
addPropsReducer(reducer: PropsTransducer, stage: TransformStage) {
|
||||
const reducers = this.propsReducers.get(stage);
|
||||
if (reducers) {
|
||||
reducers.push(reducer);
|
||||
@ -576,11 +576,4 @@ export class Designer {
|
||||
purge() {
|
||||
// TODO:
|
||||
}
|
||||
}
|
||||
|
||||
export type PropsReducerContext = { stage: TransformStage };
|
||||
export type PropsReducer = (
|
||||
props: CompositeObject,
|
||||
node: Node,
|
||||
ctx?: PropsReducerContext,
|
||||
) => CompositeObject;
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
import { EventEmitter } from 'events';
|
||||
import { obx, makeObservable } from '@alilc/lowcode-editor-core';
|
||||
import { NodeSchema } from '@alilc/lowcode-types';
|
||||
import { DragNodeObject, DragAnyObject, DragObjectType, DragNodeDataObject, DragObject } from '@alilc/lowcode-types';
|
||||
import { Node as ShellNode } from '@alilc/lowcode-shell';
|
||||
import { setNativeSelection, cursor } from '@alilc/lowcode-utils';
|
||||
import { DropLocation } from './location';
|
||||
@ -80,31 +80,6 @@ export interface ISensor {
|
||||
getNodeInstanceFromElement(e: Element | null): NodeInstance<ComponentInstance> | null;
|
||||
}
|
||||
|
||||
export type DragObject = DragNodeObject | DragNodeDataObject | DragAnyObject;
|
||||
|
||||
export enum DragObjectType {
|
||||
// eslint-disable-next-line no-shadow
|
||||
Node = 'node',
|
||||
NodeData = 'nodedata',
|
||||
}
|
||||
|
||||
export interface DragNodeObject {
|
||||
type: DragObjectType.Node;
|
||||
nodes: (Node | ShellNode)[];
|
||||
}
|
||||
export interface DragNodeDataObject {
|
||||
type: DragObjectType.NodeData;
|
||||
data: NodeSchema | NodeSchema[];
|
||||
thumbnail?: string;
|
||||
description?: string;
|
||||
[extra: string]: any;
|
||||
}
|
||||
|
||||
export interface DragAnyObject {
|
||||
type: string;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
export function isDragNodeObject(obj: any): obj is DragNodeObject {
|
||||
return obj && obj.type === DragObjectType.Node;
|
||||
}
|
||||
|
||||
@ -1,10 +1,9 @@
|
||||
import { TitleContent, isDynamicSetter, SetterType, DynamicSetter, FieldExtraProps, FieldConfig, CustomView, isCustomView } from '@alilc/lowcode-types';
|
||||
import { TitleContent, SetterType, DynamicSetter, FieldExtraProps, FieldConfig, CustomView, ISetValueOptions } from '@alilc/lowcode-types';
|
||||
import { Transducer } from './utils';
|
||||
import { SettingPropEntry } from './setting-prop-entry';
|
||||
import { SettingEntry } from './setting-entry';
|
||||
import { computed, obx, makeObservable, action } from '@alilc/lowcode-editor-core';
|
||||
import { cloneDeep } from '@alilc/lowcode-utils';
|
||||
import type { ISetValueOptions } from '../../types';
|
||||
import { cloneDeep, isCustomView, isDynamicSetter } from '@alilc/lowcode-utils';
|
||||
|
||||
function getSettingFieldCollectorKey(parent: SettingEntry, config: FieldConfig) {
|
||||
let cur = parent;
|
||||
|
||||
@ -1,13 +1,12 @@
|
||||
import { obx, computed, makeObservable, runInAction } from '@alilc/lowcode-editor-core';
|
||||
import { GlobalEvent, IEditor, isJSExpression } from '@alilc/lowcode-types';
|
||||
import { uniqueId } from '@alilc/lowcode-utils';
|
||||
import { GlobalEvent, IEditor, ISetValueOptions } from '@alilc/lowcode-types';
|
||||
import { uniqueId, isJSExpression } from '@alilc/lowcode-utils';
|
||||
import { SettingPropEntry as ShellSettingPropEntry } from '@alilc/lowcode-shell';
|
||||
import { SettingEntry } from './setting-entry';
|
||||
import { Node } from '../../document';
|
||||
import { ComponentMeta } from '../../component-meta';
|
||||
import { Designer } from '../designer';
|
||||
import { EventEmitter } from 'events';
|
||||
import { ISetValueOptions } from '../../types';
|
||||
import { isSettingField } from './setting-field';
|
||||
|
||||
export class SettingPropEntry implements SettingEntry {
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import { EventEmitter } from 'events';
|
||||
import { CustomView, isCustomView, IEditor } from '@alilc/lowcode-types';
|
||||
import { CustomView, IEditor } from '@alilc/lowcode-types';
|
||||
import { isCustomView } from '@alilc/lowcode-utils';
|
||||
import { computed } from '@alilc/lowcode-editor-core';
|
||||
import { SettingEntry } from './setting-entry';
|
||||
import { SettingField } from './setting-field';
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
// all this file for polyfill vision logic
|
||||
import { isValidElement } from 'react';
|
||||
import { isSetterConfig, isDynamicSetter, FieldConfig, SetterConfig } from '@alilc/lowcode-types';
|
||||
import { FieldConfig, SetterConfig } from '@alilc/lowcode-types';
|
||||
import { isSetterConfig, isDynamicSetter } from '@alilc/lowcode-utils';
|
||||
import { getSetter } from '@alilc/lowcode-editor-core';
|
||||
import { SettingField } from './setting-field';
|
||||
|
||||
|
||||
@ -1,15 +1,15 @@
|
||||
import { makeObservable, obx, engineConfig, action, runWithGlobalEventOff, wrapWithEventSwitch } from '@alilc/lowcode-editor-core';
|
||||
import { NodeData, isJSExpression, isDOMText, NodeSchema, isNodeSchema, RootSchema, PageSchema, ComponentsMap } from '@alilc/lowcode-types';
|
||||
import { NodeData, NodeSchema, RootSchema, PageSchema, ComponentsMap, DragNodeObject, DragNodeDataObject } from '@alilc/lowcode-types';
|
||||
import { EventEmitter } from 'events';
|
||||
import { Project } from '../project';
|
||||
import { ISimulatorHost } from '../simulator';
|
||||
import { ComponentMeta } from '../component-meta';
|
||||
import { isDragNodeDataObject, DragNodeObject, DragNodeDataObject, DropLocation, Designer, isDragNodeObject } from '../designer';
|
||||
import { isDragNodeDataObject, DropLocation, Designer, isDragNodeObject } from '../designer';
|
||||
import { Node, insertChildren, insertChild, isNode, RootNode, ParentalNode } from './node/node';
|
||||
import { Selection } from './selection';
|
||||
import { History } from './history';
|
||||
import { TransformStage, ModalNodesManager } from './node';
|
||||
import { uniqueId, isPlainObject, compatStage } from '@alilc/lowcode-utils';
|
||||
import { uniqueId, isPlainObject, compatStage, isJSExpression, isDOMText, isNodeSchema } from '@alilc/lowcode-utils';
|
||||
|
||||
export type GetDataType<T, NodeType> = T extends undefined
|
||||
? NodeType extends {
|
||||
|
||||
@ -1,17 +1,15 @@
|
||||
import { obx, computed, globalContext, makeObservable } from '@alilc/lowcode-editor-core';
|
||||
import { Node, ParentalNode } from './node';
|
||||
import { TransformStage } from './transform-stage';
|
||||
import { NodeData, isNodeSchema } from '@alilc/lowcode-types';
|
||||
import { shallowEqual, compatStage } from '@alilc/lowcode-utils';
|
||||
import { NodeData } from '@alilc/lowcode-types';
|
||||
import { shallowEqual, compatStage, isNodeSchema } from '@alilc/lowcode-utils';
|
||||
import { EventEmitter } from 'events';
|
||||
import { foreachReverse } from '../../utils/tree';
|
||||
import { NodeRemoveOptions } from '../../types';
|
||||
|
||||
export interface IOnChangeOptions {
|
||||
type: string;
|
||||
node: Node;
|
||||
}
|
||||
|
||||
export class NodeChildren {
|
||||
@obx.shallow private children: Node[];
|
||||
|
||||
@ -350,7 +348,7 @@ export class NodeChildren {
|
||||
return this.children.find(fn);
|
||||
}
|
||||
|
||||
reduce(fn: (acc: any, cur: Node) => any, initialValue: any) {
|
||||
reduce(fn: (acc: any, cur: Node) => any, initialValue: any): void {
|
||||
return this.children.reduce(fn, initialValue);
|
||||
}
|
||||
|
||||
@ -358,7 +356,7 @@ export class NodeChildren {
|
||||
remover: (node: Node, idx: number) => boolean,
|
||||
adder: (children: Node[]) => NodeData[] | null,
|
||||
sorter: (firstNode: Node, secondNode: Node) => number,
|
||||
) {
|
||||
): any {
|
||||
let changed = false;
|
||||
if (remover) {
|
||||
const willRemove = this.children.filter(remover);
|
||||
|
||||
@ -2,8 +2,6 @@ import { ReactElement } from 'react';
|
||||
import { EventEmitter } from 'events';
|
||||
import { obx, computed, autorun, makeObservable, runInAction, wrapWithEventSwitch, action } from '@alilc/lowcode-editor-core';
|
||||
import {
|
||||
isDOMText,
|
||||
isJSExpression,
|
||||
NodeSchema,
|
||||
PropsMap,
|
||||
PropsList,
|
||||
@ -17,7 +15,7 @@ import {
|
||||
GlobalEvent,
|
||||
ComponentAction,
|
||||
} from '@alilc/lowcode-types';
|
||||
import { compatStage } from '@alilc/lowcode-utils';
|
||||
import { compatStage, isDOMText, isJSExpression } from '@alilc/lowcode-utils';
|
||||
import { SettingTopEntry } from '@alilc/lowcode-designer';
|
||||
import { Node as ShellNode } from '@alilc/lowcode-shell';
|
||||
import { Props, getConvertedExtraKey } from './props/props';
|
||||
@ -94,7 +92,7 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
||||
|
||||
/**
|
||||
* 节点组件类型
|
||||
* 特殊节点:
|
||||
* 特殊节点:
|
||||
* * Page 页面
|
||||
* * Block 区块
|
||||
* * Component 组件/元件
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { untracked, computed, obx, engineConfig, action, makeObservable, mobx, runInAction } from '@alilc/lowcode-editor-core';
|
||||
import { CompositeValue, GlobalEvent, isJSExpression, isJSSlot, JSSlot, SlotSchema } from '@alilc/lowcode-types';
|
||||
import { uniqueId, isPlainObject, hasOwnProperty, compatStage } from '@alilc/lowcode-utils';
|
||||
import { CompositeValue, GlobalEvent, JSSlot, SlotSchema } from '@alilc/lowcode-types';
|
||||
import { uniqueId, isPlainObject, hasOwnProperty, compatStage, isJSExpression, isJSSlot } from '@alilc/lowcode-utils';
|
||||
import { valueToSource } from './value-to-source';
|
||||
import { Props } from './props';
|
||||
import { SlotNode, Node } from '../node';
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
import { CompositeObject, ComponentAction } from '@alilc/lowcode-types';
|
||||
import { CompositeObject, ComponentAction, MetadataTransducer } from '@alilc/lowcode-types';
|
||||
import Logger from 'zen-logger';
|
||||
import { Hotkey, Skeleton, Project, Event, Material, Common } from '@alilc/lowcode-shell';
|
||||
import { EngineConfig } from '@alilc/lowcode-editor-core';
|
||||
import { MetadataTransducer } from '@alilc/lowcode-designer';
|
||||
import { Setters } from '../types';
|
||||
|
||||
export type PreferenceValueType = string | number | boolean;
|
||||
|
||||
@ -7,9 +7,8 @@ import {
|
||||
RootSchema,
|
||||
ComponentsMap,
|
||||
TransformStage,
|
||||
isLowCodeComponentType,
|
||||
isProCodeComponentType,
|
||||
} from '@alilc/lowcode-types';
|
||||
import { isLowCodeComponentType, isProCodeComponentType } from '@alilc/lowcode-utils';
|
||||
import { ISimulatorHost } from '../simulator';
|
||||
|
||||
export class Project {
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import { getSetter, registerSetter, getSettersMap } from '@alilc/lowcode-editor-core';
|
||||
import { isFormEvent, compatibleLegaoSchema, getNodeSchemaById } from '@alilc/lowcode-utils';
|
||||
import { isNodeSchema } from '@alilc/lowcode-types';
|
||||
import { isFormEvent, compatibleLegaoSchema, getNodeSchemaById, isNodeSchema } from '@alilc/lowcode-utils';
|
||||
|
||||
export type Setters = {
|
||||
getSetter: typeof getSetter;
|
||||
@ -18,21 +17,4 @@ export const utils = {
|
||||
compatibleLegaoSchema,
|
||||
getNodeSchemaById,
|
||||
};
|
||||
export type Utils = typeof utils;
|
||||
|
||||
export enum PROP_VALUE_CHANGED_TYPE {
|
||||
/**
|
||||
* normal set value
|
||||
*/
|
||||
SET_VALUE = 'SET_VALUE',
|
||||
/**
|
||||
* value changed caused by sub-prop value change
|
||||
*/
|
||||
SUB_VALUE_CHANGE = 'SUB_VALUE_CHANGE',
|
||||
}
|
||||
|
||||
export interface ISetValueOptions {
|
||||
disableMutator?: boolean;
|
||||
type?: PROP_VALUE_CHANGED_TYPE;
|
||||
fromSetHotValue?: boolean;
|
||||
}
|
||||
export type Utils = typeof utils;
|
||||
@ -1,7 +1,7 @@
|
||||
// @ts-nocheck
|
||||
import { Editor } from '@alilc/lowcode-editor-core';
|
||||
import { isJSBlock, TransformStage } from '@alilc/lowcode-types';
|
||||
import { isPlainObject, isVariable } from '@alilc/lowcode-utils';
|
||||
import { TransformStage } from '@alilc/lowcode-types';
|
||||
import { isPlainObject, isVariable, isJSBlock } from '@alilc/lowcode-utils';
|
||||
import '../fixtures/window';
|
||||
import { Designer } from '../../src/designer/designer';
|
||||
import { DocumentModel } from '../../src/document/document-model';
|
||||
|
||||
@ -1,30 +1,14 @@
|
||||
// @ts-ignore
|
||||
import React from 'react';
|
||||
import set from 'lodash/set';
|
||||
import cloneDeep from 'lodash/cloneDeep';
|
||||
import '../fixtures/window';
|
||||
import { Editor, globalContext } from '@alilc/lowcode-editor-core';
|
||||
import {
|
||||
AssetLevel,
|
||||
Asset,
|
||||
AssetList,
|
||||
assetBundle,
|
||||
assetItem,
|
||||
AssetType,
|
||||
} from '@alilc/lowcode-utils';
|
||||
import {
|
||||
Dragon,
|
||||
isDragNodeObject,
|
||||
isDragNodeDataObject,
|
||||
isDragAnyObject,
|
||||
isLocateEvent,
|
||||
DragObjectType,
|
||||
isShaken,
|
||||
setShaken,
|
||||
} from '../../src/designer/dragon';
|
||||
} from '@alilc/lowcode-types';
|
||||
import { Project } from '../../src/project/project';
|
||||
import pageMetadata from '../fixtures/component-metadata/page';
|
||||
import { Node } from '../../src/document/node/node';
|
||||
import { Designer } from '../../src/designer/designer';
|
||||
import { DocumentModel } from '../../src/document/document-model';
|
||||
import formSchema from '../fixtures/schema/form';
|
||||
|
||||
@ -3,7 +3,7 @@ import { Editor, globalContext } from '@alilc/lowcode-editor-core';
|
||||
import { Project } from '../../src/project/project';
|
||||
import { DocumentModel } from '../../src/document/document-model';
|
||||
import { Designer } from '../../src/designer/designer';
|
||||
import { Dragon, DragObjectType } from '../../src/designer/dragon';
|
||||
import { Dragon } from '../../src/designer/dragon';
|
||||
import { TransformStage } from '../../src/document/node/transform-stage';
|
||||
import formSchema from '../fixtures/schema/form';
|
||||
import buttonMetadata from '../fixtures/component-metadata/button';
|
||||
@ -11,6 +11,7 @@ import pageMetadata from '../fixtures/component-metadata/page';
|
||||
import divMetadata from '../fixtures/component-metadata/div';
|
||||
import { delayObxTick } from '../utils';
|
||||
import { fireEvent } from '@testing-library/react';
|
||||
import { DragObjectType } from '@alilc/lowcode-types';
|
||||
|
||||
const mockNode = {
|
||||
internalToShellNode() {
|
||||
|
||||
@ -10,12 +10,12 @@ import {
|
||||
isDragNodeDataObject,
|
||||
isDragAnyObject,
|
||||
isLocateEvent,
|
||||
DragObjectType,
|
||||
isShaken,
|
||||
setShaken,
|
||||
isInvalidPoint,
|
||||
isSameAs,
|
||||
} from '../../src/designer/dragon';
|
||||
import { DragObjectType } from '@alilc/lowcode-types';
|
||||
import formSchema from '../fixtures/schema/form';
|
||||
import { fireEvent } from '@testing-library/react';
|
||||
|
||||
|
||||
@ -1,35 +1,13 @@
|
||||
import '../fixtures/window';
|
||||
import { set } from '../utils';
|
||||
import { Editor, globalContext } from '@alilc/lowcode-editor-core';
|
||||
import { Project } from '../../src/project/project';
|
||||
import { DocumentModel } from '../../src/document/document-model';
|
||||
import { ScrollTarget, Scroller } from '../../src/designer/scroller';
|
||||
import {
|
||||
isRootNode,
|
||||
isNode,
|
||||
comparePosition,
|
||||
contains,
|
||||
insertChild,
|
||||
insertChildren,
|
||||
PositionNO,
|
||||
} from '../../src/document/node/node';
|
||||
import { Designer } from '../../src/designer/designer';
|
||||
import {
|
||||
Dragon,
|
||||
isDragNodeObject,
|
||||
isDragNodeDataObject,
|
||||
isDragAnyObject,
|
||||
isLocateEvent,
|
||||
DragObjectType,
|
||||
isShaken,
|
||||
setShaken,
|
||||
} from '../../src/designer/dragon';
|
||||
import formSchema from '../fixtures/schema/form';
|
||||
import divMetadata from '../fixtures/component-metadata/div';
|
||||
import formMetadata from '../fixtures/component-metadata/form';
|
||||
import otherMeta from '../fixtures/component-metadata/other';
|
||||
import pageMetadata from '../fixtures/component-metadata/page';
|
||||
import { fireEvent } from '@testing-library/react';
|
||||
|
||||
describe('Scroller 测试', () => {
|
||||
let editor: Editor;
|
||||
|
||||
@ -1,23 +1,8 @@
|
||||
import { ReactNode } from 'react';
|
||||
import { CustomView, isCustomView, TitleContent } from '@alilc/lowcode-types';
|
||||
import { createContent } from '@alilc/lowcode-utils';
|
||||
import { CustomView, RegisteredSetter } from '@alilc/lowcode-types';
|
||||
import { createContent, isCustomView } from '@alilc/lowcode-utils';
|
||||
|
||||
|
||||
export type RegisteredSetter = {
|
||||
component: CustomView;
|
||||
defaultProps?: object;
|
||||
title?: TitleContent;
|
||||
/**
|
||||
* for MixedSetter to check this setter if available
|
||||
*/
|
||||
condition?: (field: any) => boolean;
|
||||
/**
|
||||
* for MixedSetter to manual change to this setter
|
||||
*/
|
||||
initialValue?: any | ((field: any) => any);
|
||||
recommend?: boolean;
|
||||
// 标识是否为动态setter,默认为true
|
||||
isDynamic?: boolean;
|
||||
};
|
||||
const settersMap = new Map<string, RegisteredSetter & {
|
||||
type: string;
|
||||
}>();
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { isEqual } from 'lodash';
|
||||
import { globalContext } from './di';
|
||||
import { Editor } from './editor';
|
||||
import { HotkeyCallback } from '@alilc/lowcode-types';
|
||||
|
||||
interface KeyMap {
|
||||
[key: number]: string;
|
||||
@ -22,8 +23,6 @@ interface HotkeyDirectMap {
|
||||
[key: string]: HotkeyCallback;
|
||||
}
|
||||
|
||||
export type HotkeyCallback = (e: KeyboardEvent, combo?: string) => any | false;
|
||||
|
||||
interface HotkeyCallbackCfg {
|
||||
callback: HotkeyCallback;
|
||||
modifiers: string[];
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { ReactNode, Component, createElement } from 'react';
|
||||
import { IntlMessageFormat } from 'intl-messageformat';
|
||||
import { globalLocale } from './global-locale';
|
||||
import { isI18nData } from '@alilc/lowcode-types';
|
||||
import { isI18nData } from '@alilc/lowcode-utils';
|
||||
import { observer } from '../utils';
|
||||
|
||||
function generateTryLocales(locale: string) {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { Component, isValidElement, ReactNode } from 'react';
|
||||
import classNames from 'classnames';
|
||||
import { createIcon } from '@alilc/lowcode-utils';
|
||||
import { TitleContent, isI18nData, I18nData } from '@alilc/lowcode-types';
|
||||
import { createIcon, isI18nData } from '@alilc/lowcode-utils';
|
||||
import { TitleContent, I18nData } from '@alilc/lowcode-types';
|
||||
import { intl } from '../../intl';
|
||||
import { Tip } from '../tip';
|
||||
import './title.less';
|
||||
|
||||
@ -1,13 +1,12 @@
|
||||
import { Component, MouseEvent, Fragment } from 'react';
|
||||
import { shallowIntl, createSetterContent, observer, obx, engineConfig, runInAction, globalContext } from '@alilc/lowcode-editor-core';
|
||||
import { createContent } from '@alilc/lowcode-utils';
|
||||
import { createContent, isJSSlot, isSetterConfig } from '@alilc/lowcode-utils';
|
||||
import { Skeleton } from '@alilc/lowcode-editor-skeleton';
|
||||
import { isSetterConfig, CustomView, isJSSlot } from '@alilc/lowcode-types';
|
||||
import { CustomView } from '@alilc/lowcode-types';
|
||||
import { SettingField, isSettingField, SettingTopEntry, SettingEntry, ComponentMeta } from '@alilc/lowcode-designer';
|
||||
import { createField } from '../field';
|
||||
import PopupService, { PopupPipe } from '../popup';
|
||||
import { SkeletonContext } from '../../context';
|
||||
// import { Icon } from '@alifd/next';
|
||||
import { intl } from '../../locale';
|
||||
|
||||
function isStandardComponent(componentMeta: ComponentMeta | null) {
|
||||
|
||||
@ -4,7 +4,7 @@ import classNames from 'classnames';
|
||||
import { IconArrow } from '../../icons/arrow';
|
||||
import { IconExit } from '../../icons/exit';
|
||||
import { Stage as StageWidget } from '../../widget/stage';
|
||||
import { isTitleConfig } from '@alilc/lowcode-types';
|
||||
import { isTitleConfig } from '@alilc/lowcode-utils';
|
||||
|
||||
export const StageDefaultProps = {
|
||||
current: false,
|
||||
|
||||
@ -3,7 +3,6 @@ import {
|
||||
DockConfig,
|
||||
PanelConfig,
|
||||
WidgetConfig,
|
||||
IWidgetBaseConfig,
|
||||
PanelDockConfig,
|
||||
DialogDockConfig,
|
||||
isDockConfig,
|
||||
@ -11,7 +10,6 @@ import {
|
||||
isPanelConfig,
|
||||
DividerConfig,
|
||||
isDividerConfig,
|
||||
IWidgetConfigArea,
|
||||
} from './types';
|
||||
import Panel, { isPanel } from './widget/panel';
|
||||
import WidgetContainer from './widget/widget-container';
|
||||
@ -23,7 +21,12 @@ import { Stage, StageConfig } from './widget/stage';
|
||||
import { isValidElement } from 'react';
|
||||
import { isPlainObject, uniqueId } from '@alilc/lowcode-utils';
|
||||
import { Divider } from '@alifd/next';
|
||||
import { EditorConfig, PluginClassSet } from '@alilc/lowcode-types';
|
||||
import {
|
||||
EditorConfig,
|
||||
PluginClassSet,
|
||||
IWidgetBaseConfig,
|
||||
IWidgetConfigArea,
|
||||
} from '@alilc/lowcode-types';
|
||||
|
||||
export enum SkeletonEvents {
|
||||
PANEL_DOCK_ACTIVE = 'skeleton.panel-dock.active',
|
||||
|
||||
@ -1,9 +1,5 @@
|
||||
import {
|
||||
FieldConfig,
|
||||
TransformedComponentMetadata,
|
||||
isJSFunction,
|
||||
} from '@alilc/lowcode-types';
|
||||
import { isPlainObject } from '@alilc/lowcode-utils';
|
||||
import { TransformedComponentMetadata } from '@alilc/lowcode-types';
|
||||
import { isPlainObject, isJSFunction } from '@alilc/lowcode-utils';
|
||||
|
||||
const leadingFnRe = /^function/;
|
||||
const leadingFnNameRe = /^\w+\s*\(/;
|
||||
|
||||
@ -1,35 +1,14 @@
|
||||
import { ReactElement, ComponentType } from 'react';
|
||||
import { TitleContent, IconType, I18nData, TipContent } from '@alilc/lowcode-types';
|
||||
import {
|
||||
TitleContent,
|
||||
IconType,
|
||||
I18nData,
|
||||
TipContent,
|
||||
IWidgetConfigArea,
|
||||
IWidgetBaseConfig,
|
||||
} from '@alilc/lowcode-types';
|
||||
import { IWidget } from './widget/widget';
|
||||
|
||||
/**
|
||||
* 所有可能的停靠位置
|
||||
*/
|
||||
export type IWidgetConfigArea =
|
||||
| 'leftArea' | 'left' | 'rightArea'
|
||||
| 'right' | 'topArea' | 'top'
|
||||
| 'toolbar' | 'mainArea' | 'main'
|
||||
| 'center' | 'centerArea' | 'bottomArea'
|
||||
| 'bottom' | 'leftFixedArea'
|
||||
| 'leftFloatArea' | 'stages';
|
||||
|
||||
export interface IWidgetBaseConfig {
|
||||
type: string;
|
||||
name: string;
|
||||
/**
|
||||
* 停靠位置:
|
||||
* - 当 type 为 'Panel' 时自动为 'leftFloatArea';
|
||||
* - 当 type 为 'Widget' 时自动为 'mainArea';
|
||||
* - 其他时候自动为 'leftArea';
|
||||
*/
|
||||
area?: IWidgetConfigArea;
|
||||
props?: Record<string, any>;
|
||||
content?: any;
|
||||
contentProps?: Record<string, any>;
|
||||
// index?: number;
|
||||
[extra: string]: any;
|
||||
}
|
||||
|
||||
export interface WidgetConfig extends IWidgetBaseConfig {
|
||||
type: 'Widget';
|
||||
props?: {
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { IconType, TitleContent, isI18nData, TipContent, isTitleConfig } from '@alilc/lowcode-types';
|
||||
import { IconType, TitleContent, TipContent } from '@alilc/lowcode-types';
|
||||
import { isI18nData, isTitleConfig } from '@alilc/lowcode-utils';
|
||||
import { isValidElement } from 'react';
|
||||
|
||||
export function composeTitle(title?: TitleContent, icon?: IconType, tip?: TipContent, tipAsTitle?: boolean, noIcon?: boolean) {
|
||||
|
||||
@ -33,7 +33,6 @@ import './modules/live-editing';
|
||||
import classes from './modules/classes';
|
||||
import symbols from './modules/symbols';
|
||||
|
||||
export * from './modules/editor-types';
|
||||
export * from './modules/skeleton-types';
|
||||
export * from './modules/designer-types';
|
||||
export * from './modules/lowcode-types';
|
||||
|
||||
@ -13,7 +13,4 @@ export type ILowCodePluginConfig = designerCabin.ILowCodePluginConfig;
|
||||
export type ILowCodePluginManager = designerCabin.ILowCodePluginManager;
|
||||
export type ILowCodePluginContext = designerCabin.ILowCodePluginContext;
|
||||
export type IPluginConfigCreator = designerCabin.IPluginConfigCreator;
|
||||
export type PluginPreference = designerCabin.PluginPreference;
|
||||
export type PropsReducerContext = designerCabin.PropsReducerContext;
|
||||
export type DragObjectType = designerCabin.DragObjectType;
|
||||
export type DragNodeDataObject = designerCabin.DragNodeDataObject;
|
||||
export type PluginPreference = designerCabin.PluginPreference;
|
||||
@ -1,3 +0,0 @@
|
||||
import * as editorCabin from '@alilc/lowcode-editor-core';
|
||||
|
||||
export type RegisteredSetter = editorCabin.RegisteredSetter;
|
||||
@ -1,5 +1,5 @@
|
||||
import { EditingTarget, Node as DocNode, SaveHandler, LiveEditing } from '@alilc/lowcode-designer';
|
||||
import { isJSExpression } from '@alilc/lowcode-types';
|
||||
import { isJSExpression } from '@alilc/lowcode-utils';
|
||||
|
||||
function getText(node: DocNode, prop: string) {
|
||||
const p = node.getProp(prop, false);
|
||||
@ -53,8 +53,7 @@ function equalText(v: any, innerText: string) {
|
||||
|
||||
export const liveEditingSaveHander: SaveHandler = {
|
||||
condition: (prop) => {
|
||||
// const v = prop.getValue();
|
||||
return prop.type === 'expression'; // || isI18nData(v);
|
||||
return prop.type === 'expression';
|
||||
},
|
||||
onSaveContent: (content, prop) => {
|
||||
const v = prop.getValue();
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { TitleContent, isI18nData } from '@alilc/lowcode-types';
|
||||
import { TitleContent } from '@alilc/lowcode-types';
|
||||
import { isI18nData } from '@alilc/lowcode-utils';
|
||||
import { computed, obx, intl, makeObservable, action } from '@alilc/lowcode-editor-core';
|
||||
import { Node, DocumentModel, isLocationChildrenDetail, LocationChildrenDetail, Designer } from '@alilc/lowcode-designer';
|
||||
import { Tree } from './tree';
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
import { Component, MouseEvent as ReactMouseEvent } from 'react';
|
||||
import { observer, Editor, globalContext } from '@alilc/lowcode-editor-core';
|
||||
import { Node, DragObjectType, isShaken } from '@alilc/lowcode-designer';
|
||||
import { Node, isShaken } from '@alilc/lowcode-designer';
|
||||
import { isFormEvent, canClickNode } from '@alilc/lowcode-utils';
|
||||
import { Tree } from '../tree';
|
||||
import RootTreeNodeView from './root-tree-node';
|
||||
import { DragObjectType } from '@alilc/lowcode-types';
|
||||
|
||||
function getTreeNodeIdByEvent(e: ReactMouseEvent, stop: Element): null | string {
|
||||
let target: Element | null = e.target as Element;
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import { BuiltinSimulatorRenderer, Component, DocumentModel, Node, NodeInstance } from '@alilc/lowcode-designer';
|
||||
import { ComponentSchema, NodeSchema, NpmInfo, RootSchema, TransformStage } from '@alilc/lowcode-types';
|
||||
import { ComponentSchema, NodeSchema, NpmInfo, TransformStage } from '@alilc/lowcode-types';
|
||||
import { Asset, compatibleLegaoSchema, cursor, isElement, isESModule, isPlainObject, isReactComponent, setNativeSelection } from '@alilc/lowcode-utils';
|
||||
import LowCodeRenderer from '@alilc/lowcode-rax-renderer';
|
||||
import { computed, observable as obx, untracked, makeObservable, configure } from 'mobx';
|
||||
import { computed, observable as obx, makeObservable, configure } from 'mobx';
|
||||
import DriverUniversal from 'driver-universal';
|
||||
import { EventEmitter } from 'events';
|
||||
import { createMemoryHistory, MemoryHistory } from 'history';
|
||||
|
||||
@ -3,7 +3,8 @@
|
||||
/* eslint-disable react/prop-types */
|
||||
import classnames from 'classnames';
|
||||
import { create as createDataSourceEngine } from '@alilc/lowcode-datasource-engine/interpret';
|
||||
import { isI18nData, isJSExpression, isJSFunction, NodeSchema, NodeData, JSONValue, CompositeValue } from '@alilc/lowcode-types';
|
||||
import { NodeSchema, NodeData, JSONValue, CompositeValue } from '@alilc/lowcode-types';
|
||||
import { isI18nData, isJSExpression, isJSFunction } from '@alilc/lowcode-utils';
|
||||
import adapter from '../adapter';
|
||||
import divFactory from '../components/Div';
|
||||
import visualDomFactory from '../components/VisualDom';
|
||||
@ -29,7 +30,7 @@ import {
|
||||
isVariable,
|
||||
isJSSlot,
|
||||
} from '../utils';
|
||||
import { IBaseRendererProps, INodeInfo, IBaseRenderComponent, IBaseRendererContext, IGeneralConstructor, IRendererAppHelper, DataSource } from '../types';
|
||||
import { IBaseRendererProps, INodeInfo, IBaseRenderComponent, IBaseRendererContext, IRendererAppHelper, DataSource } from '../types';
|
||||
import { compWrapper } from '../hoc';
|
||||
import { IComponentConstruct, leafWrapper } from '../hoc/leaf';
|
||||
import logger from '../utils/logger';
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
/* eslint-disable no-console */
|
||||
/* eslint-disable no-new-func */
|
||||
import logger from './logger';
|
||||
import { isI18nData, RootSchema, NodeSchema, isJSExpression, JSSlot } from '@alilc/lowcode-types';
|
||||
import { RootSchema, NodeSchema, JSSlot } from '@alilc/lowcode-types';
|
||||
import { isI18nData, isJSExpression } from '@alilc/lowcode-utils';
|
||||
import { isEmpty } from 'lodash';
|
||||
import IntlMessageFormat from 'intl-messageformat';
|
||||
import pkg from '../../package.json';
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/* eslint-disable no-console */
|
||||
/* eslint-disable max-len */
|
||||
/* eslint-disable object-curly-newline */
|
||||
import { isJSFunction } from '@alilc/lowcode-types';
|
||||
import { isJSFunction } from '@alilc/lowcode-utils';
|
||||
import { transformArrayToMap, transformStringToFunction } from './common';
|
||||
import { jsonp, request, get, post } from './request';
|
||||
import logger from './logger';
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { isJSExpression, JSExpression } from '@alilc/lowcode-types';
|
||||
import { JSExpression } from '@alilc/lowcode-types';
|
||||
import { isJSExpression } from '@alilc/lowcode-utils';
|
||||
|
||||
// 1.渲染模式下,loop 是数组,则按照数组长度渲染组件
|
||||
// 2.设计模式下,loop 需要长度大于 0,按照循环模式渲染,防止无法设计的情况
|
||||
|
||||
@ -1,16 +1,19 @@
|
||||
import { Designer } from '@alilc/lowcode-designer';
|
||||
import { designerSymbol } from './symbols';
|
||||
import DropLocation from './drop-location';
|
||||
import { IPublicModelCanvas } from '@alilc/lowcode-types';
|
||||
|
||||
export default class Canvas {
|
||||
export default class Canvas implements IPublicModelCanvas {
|
||||
private readonly [designerSymbol]: Designer;
|
||||
|
||||
constructor(designer: Designer) {
|
||||
this[designerSymbol] = designer;
|
||||
}
|
||||
|
||||
static create(designer: Designer) {
|
||||
if (!designer) return null;
|
||||
static create(designer: Designer): IPublicModelCanvas | null {
|
||||
if (!designer) {
|
||||
return null;
|
||||
}
|
||||
return new Canvas(designer);
|
||||
}
|
||||
|
||||
|
||||
@ -4,12 +4,17 @@ import {
|
||||
compatibleLegaoSchema as innerCompatibleLegaoSchema,
|
||||
getNodeSchemaById as innerGetNodeSchemaById,
|
||||
transactionManager,
|
||||
isNodeSchema as innerIsNodeSchema,
|
||||
} from '@alilc/lowcode-utils';
|
||||
import {
|
||||
isNodeSchema as innerIsNodeSchema,
|
||||
NodeSchema,
|
||||
TransitionType,
|
||||
TransformStage as InnerTransitionStage,
|
||||
IPublicCommonDesignerCabin,
|
||||
IPublicCommonSkeletonCabin,
|
||||
IPublicCommonUtils,
|
||||
IPublicApiCommon,
|
||||
DragObjectType as InnerDragObjectType,
|
||||
} from '@alilc/lowcode-types';
|
||||
import {
|
||||
SettingField as InnerSettingField,
|
||||
@ -19,7 +24,6 @@ import {
|
||||
isDragNodeDataObject as innerIsDragNodeDataObject,
|
||||
isDragNodeObject as innerIsDragNodeObject,
|
||||
isDragAnyObject as innerIsDragAnyObject,
|
||||
DragObjectType as InnerDragObjectType,
|
||||
isNode as innerIsNode,
|
||||
isShaken as innerIsShaken,
|
||||
contains as innerContains,
|
||||
@ -56,7 +60,7 @@ import {
|
||||
import { ReactNode } from 'react';
|
||||
|
||||
|
||||
class DesignerCabin {
|
||||
class DesignerCabin implements IPublicCommonDesignerCabin {
|
||||
private readonly [editorSymbol]: Editor;
|
||||
/**
|
||||
* @deprecated
|
||||
@ -147,7 +151,7 @@ class DesignerCabin {
|
||||
}
|
||||
}
|
||||
|
||||
class SkeletonCabin {
|
||||
class SkeletonCabin implements IPublicCommonSkeletonCabin {
|
||||
private readonly [skeletonSymbol]: InnerSkeleton;
|
||||
|
||||
constructor(skeleton: InnerSkeleton) {
|
||||
@ -181,7 +185,7 @@ class SkeletonCabin {
|
||||
}
|
||||
}
|
||||
|
||||
class Utils {
|
||||
class Utils implements IPublicCommonUtils {
|
||||
isNodeSchema(data: any): data is NodeSchema {
|
||||
return innerIsNodeSchema(data);
|
||||
}
|
||||
@ -314,7 +318,7 @@ class EditorCabin {
|
||||
}
|
||||
|
||||
|
||||
export default class Common {
|
||||
export default class Common implements IPublicApiCommon {
|
||||
private readonly __designerCabin: any;
|
||||
private readonly __skeletonCabin: any;
|
||||
private readonly __editorCabin: any;
|
||||
|
||||
@ -2,19 +2,21 @@ import {
|
||||
ComponentMeta as InnerComponentMeta,
|
||||
ParentalNode,
|
||||
} from '@alilc/lowcode-designer';
|
||||
import Node from './node';
|
||||
import { NodeData, NodeSchema } from '@alilc/lowcode-types';
|
||||
import { NodeData, NodeSchema, IPublicModelComponentMeta, I18nData, IconType, NpmInfo, TransformedComponentMetadata, IPublicModelNode } from '@alilc/lowcode-types';
|
||||
import { componentMetaSymbol, nodeSymbol } from './symbols';
|
||||
import { ReactElement } from 'react';
|
||||
|
||||
export default class ComponentMeta {
|
||||
export default class ComponentMeta implements IPublicModelComponentMeta {
|
||||
private readonly [componentMetaSymbol]: InnerComponentMeta;
|
||||
|
||||
constructor(componentMeta: InnerComponentMeta) {
|
||||
this[componentMetaSymbol] = componentMeta;
|
||||
}
|
||||
|
||||
static create(componentMeta: InnerComponentMeta | null) {
|
||||
if (!componentMeta) return null;
|
||||
static create(componentMeta: InnerComponentMeta | null): IPublicModelComponentMeta | null {
|
||||
if (!componentMeta) {
|
||||
return null;
|
||||
}
|
||||
return new ComponentMeta(componentMeta);
|
||||
}
|
||||
|
||||
@ -52,28 +54,28 @@ export default class ComponentMeta {
|
||||
/**
|
||||
* 元数据配置
|
||||
*/
|
||||
get configure() {
|
||||
get configure(): any {
|
||||
return this[componentMetaSymbol].configure;
|
||||
}
|
||||
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
get title() {
|
||||
get title(): string | I18nData | ReactElement {
|
||||
return this[componentMetaSymbol].title;
|
||||
}
|
||||
|
||||
/**
|
||||
* 图标
|
||||
*/
|
||||
get icon() {
|
||||
get icon(): IconType {
|
||||
return this[componentMetaSymbol].icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* 组件 npm 信息
|
||||
*/
|
||||
get npm() {
|
||||
get npm(): NpmInfo {
|
||||
return this[componentMetaSymbol].npm;
|
||||
}
|
||||
|
||||
@ -84,7 +86,7 @@ export default class ComponentMeta {
|
||||
return this[componentMetaSymbol].prototype;
|
||||
}
|
||||
|
||||
get availableActions() {
|
||||
get availableActions(): any {
|
||||
return this[componentMetaSymbol].availableActions;
|
||||
}
|
||||
|
||||
@ -92,7 +94,7 @@ export default class ComponentMeta {
|
||||
* 设置 npm 信息
|
||||
* @param npm
|
||||
*/
|
||||
setNpm(npm: any) {
|
||||
setNpm(npm: NpmInfo): void {
|
||||
this[componentMetaSymbol].setNpm(npm);
|
||||
}
|
||||
|
||||
@ -100,7 +102,7 @@ export default class ComponentMeta {
|
||||
* 获取元数据
|
||||
* @returns
|
||||
*/
|
||||
getMetadata() {
|
||||
getMetadata(): TransformedComponentMetadata {
|
||||
return this[componentMetaSymbol].getMetadata();
|
||||
}
|
||||
|
||||
@ -110,8 +112,8 @@ export default class ComponentMeta {
|
||||
* @param parent
|
||||
* @returns
|
||||
*/
|
||||
checkNestingUp(my: Node | NodeData, parent: ParentalNode<NodeSchema>) {
|
||||
const curNode = my.isNode ? my[nodeSymbol] : my;
|
||||
checkNestingUp(my: IPublicModelNode | NodeData, parent: ParentalNode<NodeSchema>): boolean {
|
||||
const curNode = (my as any).isNode ? (my as any)[nodeSymbol] : my;
|
||||
return this[componentMetaSymbol].checkNestingUp(curNode as any, parent);
|
||||
}
|
||||
|
||||
@ -121,12 +123,12 @@ export default class ComponentMeta {
|
||||
* @param parent
|
||||
* @returns
|
||||
*/
|
||||
checkNestingDown(my: Node | NodeData, target: NodeSchema | Node | NodeSchema[]) {
|
||||
const curNode = my.isNode ? my[nodeSymbol] : my;
|
||||
return this[componentMetaSymbol].checkNestingDown(curNode as any, target[nodeSymbol] || target);
|
||||
checkNestingDown(my: IPublicModelNode | NodeData, target: NodeSchema | IPublicModelNode | NodeSchema[]) {
|
||||
const curNode = (my as any)?.isNode ? (my as any)[nodeSymbol] : my;
|
||||
return this[componentMetaSymbol].checkNestingDown(curNode as any, (target as any)[nodeSymbol] || target);
|
||||
}
|
||||
|
||||
refreshMetadata() {
|
||||
refreshMetadata(): void {
|
||||
this[componentMetaSymbol].refreshMetadata();
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,8 +4,9 @@ import {
|
||||
DocumentModel as InnerDocumentModel,
|
||||
} from '@alilc/lowcode-designer';
|
||||
import { documentSymbol, detectingSymbol } from './symbols';
|
||||
import { IPublicModelDetecting } from '@alilc/lowcode-types';
|
||||
|
||||
export default class Detecting {
|
||||
export default class Detecting implements IPublicModelDetecting {
|
||||
private readonly [documentSymbol]: InnerDocumentModel;
|
||||
private readonly [detectingSymbol]: InnerDetecting;
|
||||
|
||||
|
||||
@ -2,16 +2,26 @@ import { Editor } from '@alilc/lowcode-editor-core';
|
||||
import {
|
||||
DocumentModel as InnerDocumentModel,
|
||||
Node as InnerNode,
|
||||
IOnChangeOptions as InnerIOnChangeOptions,
|
||||
DragObject as InnerDragObject,
|
||||
DragNodeObject,
|
||||
DragNodeDataObject,
|
||||
isDragNodeObject,
|
||||
IOnChangeOptions as InnerOnChangeOptions,
|
||||
} from '@alilc/lowcode-designer';
|
||||
import {
|
||||
TransformStage,
|
||||
RootSchema,
|
||||
GlobalEvent,
|
||||
IPublicModelDocumentModel,
|
||||
IPublicOnChangeOptions,
|
||||
DragObject,
|
||||
DragNodeObject,
|
||||
DragNodeDataObject,
|
||||
IPublicModelNode,
|
||||
IPublicModelSelection,
|
||||
IPublicModelDetecting,
|
||||
IPublicModelHistory,
|
||||
IPublicModelCanvas,
|
||||
IPublicApiProject,
|
||||
IPublicModelModalNodesManager,
|
||||
PropChangeOptions,
|
||||
} from '@alilc/lowcode-types';
|
||||
import Node from './node';
|
||||
import Selection from './selection';
|
||||
@ -23,33 +33,20 @@ import Canvas from './canvas';
|
||||
import ModalNodesManager from './modal-nodes-manager';
|
||||
import { documentSymbol, editorSymbol, nodeSymbol } from './symbols';
|
||||
|
||||
type IOnChangeOptions = {
|
||||
type: string;
|
||||
node: Node;
|
||||
};
|
||||
|
||||
type PropChangeOptions = {
|
||||
key?: string | number;
|
||||
prop?: Prop;
|
||||
node: Node;
|
||||
newValue: any;
|
||||
oldValue: any;
|
||||
};
|
||||
|
||||
const Events = {
|
||||
IMPORT_SCHEMA: 'shell.document.importSchema',
|
||||
};
|
||||
|
||||
const shellDocSymbol = Symbol('shellDocSymbol');
|
||||
|
||||
export default class DocumentModel {
|
||||
export default class DocumentModel implements IPublicModelDocumentModel {
|
||||
private readonly [documentSymbol]: InnerDocumentModel;
|
||||
private readonly [editorSymbol]: Editor;
|
||||
private _focusNode: Node;
|
||||
public selection: Selection;
|
||||
public detecting: Detecting;
|
||||
public history: History;
|
||||
public canvas: Canvas;
|
||||
private _focusNode: IPublicModelNode | null;
|
||||
selection: IPublicModelSelection;
|
||||
detecting: IPublicModelDetecting;
|
||||
history: IPublicModelHistory;
|
||||
canvas: IPublicModelCanvas;
|
||||
|
||||
constructor(document: InnerDocumentModel) {
|
||||
this[documentSymbol] = document;
|
||||
@ -62,10 +59,14 @@ export default class DocumentModel {
|
||||
this._focusNode = Node.create(this[documentSymbol].focusNode);
|
||||
}
|
||||
|
||||
static create(document: InnerDocumentModel | undefined | null) {
|
||||
if (!document) return null;
|
||||
static create(document: InnerDocumentModel | undefined | null): IPublicModelDocumentModel | null {
|
||||
if (!document) {
|
||||
return null;
|
||||
}
|
||||
// @ts-ignore 直接返回已挂载的 shell doc 实例
|
||||
if (document[shellDocSymbol]) return document[shellDocSymbol];
|
||||
if (document[shellDocSymbol]) {
|
||||
return (document as any)[shellDocSymbol];
|
||||
}
|
||||
const shellDoc = new DocumentModel(document);
|
||||
// @ts-ignore 直接返回已挂载的 shell doc 实例
|
||||
document[shellDocSymbol] = shellDoc;
|
||||
@ -75,7 +76,7 @@ export default class DocumentModel {
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
get id() {
|
||||
get id(): string {
|
||||
return this[documentSymbol].id;
|
||||
}
|
||||
|
||||
@ -87,7 +88,7 @@ export default class DocumentModel {
|
||||
* 获取当前文档所属的 project
|
||||
* @returns
|
||||
*/
|
||||
get project() {
|
||||
get project(): IPublicApiProject | null {
|
||||
return Project.create(this[documentSymbol].project);
|
||||
}
|
||||
|
||||
@ -95,15 +96,15 @@ export default class DocumentModel {
|
||||
* 获取文档的根节点
|
||||
* @returns
|
||||
*/
|
||||
get root(): Node | null {
|
||||
get root(): IPublicModelNode | null {
|
||||
return Node.create(this[documentSymbol].getRoot());
|
||||
}
|
||||
|
||||
get focusNode(): Node {
|
||||
get focusNode(): IPublicModelNode | null {
|
||||
return this._focusNode || this.root;
|
||||
}
|
||||
|
||||
set focusNode(node: Node) {
|
||||
set focusNode(node: IPublicModelNode | null) {
|
||||
this._focusNode = node;
|
||||
}
|
||||
|
||||
@ -111,8 +112,8 @@ export default class DocumentModel {
|
||||
* 获取文档下所有节点
|
||||
* @returns
|
||||
*/
|
||||
get nodesMap() {
|
||||
const map = new Map<string, Node>();
|
||||
get nodesMap(): any {
|
||||
const map = new Map<string, IPublicModelNode>();
|
||||
for (let id of this[documentSymbol].nodesMap.keys()) {
|
||||
map.set(id, this.getNodeById(id)!);
|
||||
}
|
||||
@ -122,12 +123,15 @@ export default class DocumentModel {
|
||||
/**
|
||||
* 模态节点管理
|
||||
*/
|
||||
get modalNodesManager() {
|
||||
get modalNodesManager(): IPublicModelModalNodesManager | null {
|
||||
return ModalNodesManager.create(this[documentSymbol].modalNodesManager);
|
||||
}
|
||||
|
||||
// @TODO: 不能直接暴露
|
||||
get dropLocation() {
|
||||
/**
|
||||
* @TODO: 不能直接暴露
|
||||
* @deprecated
|
||||
*/
|
||||
get dropLocation(): any {
|
||||
return this[documentSymbol].dropLocation;
|
||||
}
|
||||
|
||||
@ -136,7 +140,7 @@ export default class DocumentModel {
|
||||
* @param nodeId
|
||||
* @returns
|
||||
*/
|
||||
getNodeById(nodeId: string) {
|
||||
getNodeById(nodeId: string): IPublicModelNode | null {
|
||||
return Node.create(this[documentSymbol].getNode(nodeId));
|
||||
}
|
||||
|
||||
@ -144,7 +148,7 @@ export default class DocumentModel {
|
||||
* 导入 schema
|
||||
* @param schema
|
||||
*/
|
||||
importSchema(schema: RootSchema) {
|
||||
importSchema(schema: RootSchema): void {
|
||||
this[documentSymbol].import(schema);
|
||||
this[editorSymbol].emit(Events.IMPORT_SCHEMA, schema);
|
||||
}
|
||||
@ -154,7 +158,7 @@ export default class DocumentModel {
|
||||
* @param stage
|
||||
* @returns
|
||||
*/
|
||||
exportSchema(stage: TransformStage = TransformStage.Render) {
|
||||
exportSchema(stage: TransformStage = TransformStage.Render): any {
|
||||
return this[documentSymbol].export(stage);
|
||||
}
|
||||
|
||||
@ -167,14 +171,14 @@ export default class DocumentModel {
|
||||
* @returns
|
||||
*/
|
||||
insertNode(
|
||||
parent: Node,
|
||||
thing: Node,
|
||||
parent: IPublicModelNode,
|
||||
thing: IPublicModelNode,
|
||||
at?: number | null | undefined,
|
||||
copy?: boolean | undefined,
|
||||
) {
|
||||
): IPublicModelNode | null {
|
||||
const node = this[documentSymbol].insertNode(
|
||||
parent[nodeSymbol] ? parent[nodeSymbol] : parent,
|
||||
thing?.[nodeSymbol] ? thing[nodeSymbol] : thing,
|
||||
(parent as any)[nodeSymbol] ? (parent as any)[nodeSymbol] : parent,
|
||||
(thing as any)?.[nodeSymbol] ? (thing as any)[nodeSymbol] : thing,
|
||||
at,
|
||||
copy,
|
||||
);
|
||||
@ -186,7 +190,7 @@ export default class DocumentModel {
|
||||
* @param data
|
||||
* @returns
|
||||
*/
|
||||
createNode(data: any) {
|
||||
createNode(data: any): IPublicModelNode | null {
|
||||
return Node.create(this[documentSymbol].createNode(data));
|
||||
}
|
||||
|
||||
@ -194,7 +198,7 @@ export default class DocumentModel {
|
||||
* 移除指定节点/节点id
|
||||
* @param idOrNode
|
||||
*/
|
||||
removeNode(idOrNode: string | Node) {
|
||||
removeNode(idOrNode: string | IPublicModelNode): void {
|
||||
this[documentSymbol].removeNode(idOrNode as any);
|
||||
}
|
||||
|
||||
@ -203,7 +207,7 @@ export default class DocumentModel {
|
||||
* @param extraComps
|
||||
* @returns
|
||||
*/
|
||||
getComponentsMap(extraComps?: string[]) {
|
||||
getComponentsMap(extraComps?: string[]): any {
|
||||
return this[documentSymbol].getComponentsMap(extraComps);
|
||||
}
|
||||
|
||||
@ -213,13 +217,16 @@ export default class DocumentModel {
|
||||
* @param dragObject 拖拽的对象
|
||||
* @returns boolean 是否可以放置
|
||||
*/
|
||||
checkNesting(dropTarget: Node, dragObject: DragNodeObject | DragNodeDataObject): boolean {
|
||||
let innerDragObject: InnerDragObject = dragObject;
|
||||
checkNesting(
|
||||
dropTarget: IPublicModelNode,
|
||||
dragObject: DragNodeObject | DragNodeDataObject,
|
||||
): boolean {
|
||||
let innerDragObject: DragObject = dragObject;
|
||||
if (isDragNodeObject(dragObject)) {
|
||||
innerDragObject.nodes = innerDragObject.nodes.map((node: Node) => (node[nodeSymbol] || node));
|
||||
}
|
||||
return this[documentSymbol].checkNesting(
|
||||
(dropTarget[nodeSymbol] || dropTarget) as any,
|
||||
((dropTarget as any)[nodeSymbol] || dropTarget) as any,
|
||||
innerDragObject as any,
|
||||
);
|
||||
}
|
||||
@ -227,7 +234,7 @@ export default class DocumentModel {
|
||||
/**
|
||||
* 当前 document 新增节点事件
|
||||
*/
|
||||
onAddNode(fn: (node: Node) => void) {
|
||||
onAddNode(fn: (node: IPublicModelNode) => void): () => void {
|
||||
return this[documentSymbol].onNodeCreate((node: InnerNode) => {
|
||||
fn(Node.create(node)!);
|
||||
});
|
||||
@ -236,7 +243,7 @@ export default class DocumentModel {
|
||||
/**
|
||||
* 当前 document 新增节点事件,此时节点已经挂载到 document 上
|
||||
*/
|
||||
onMountNode(fn: (payload: { node: Node }) => void) {
|
||||
onMountNode(fn: (payload: { node: IPublicModelNode }) => void): () => void {
|
||||
this[editorSymbol].on('node.add', fn as any);
|
||||
return () => {
|
||||
this[editorSymbol].off('node.add', fn as any);
|
||||
@ -246,7 +253,7 @@ export default class DocumentModel {
|
||||
/**
|
||||
* 当前 document 删除节点事件
|
||||
*/
|
||||
onRemoveNode(fn: (node: Node) => void) {
|
||||
onRemoveNode(fn: (node: IPublicModelNode) => void): () => void {
|
||||
return this[documentSymbol].onNodeDestroy((node: InnerNode) => {
|
||||
fn(Node.create(node)!);
|
||||
});
|
||||
@ -255,7 +262,7 @@ export default class DocumentModel {
|
||||
/**
|
||||
* 当前 document 的 hover 变更事件
|
||||
*/
|
||||
onChangeDetecting(fn: (node: Node) => void) {
|
||||
onChangeDetecting(fn: (node: IPublicModelNode) => void): () => void {
|
||||
return this[documentSymbol].designer.detecting.onDetectingChange((node: InnerNode) => {
|
||||
fn(Node.create(node)!);
|
||||
});
|
||||
@ -264,7 +271,7 @@ export default class DocumentModel {
|
||||
/**
|
||||
* 当前 document 的选中变更事件
|
||||
*/
|
||||
onChangeSelection(fn: (ids: string[]) => void) {
|
||||
onChangeSelection(fn: (ids: string[]) => void): () => void {
|
||||
return this[documentSymbol].selection.onSelectionChange((ids: string[]) => {
|
||||
fn(ids);
|
||||
});
|
||||
@ -274,9 +281,9 @@ export default class DocumentModel {
|
||||
* 当前 document 的节点显隐状态变更事件
|
||||
* @param fn
|
||||
*/
|
||||
onChangeNodeVisible(fn: (node: Node, visible: boolean) => void) {
|
||||
onChangeNodeVisible(fn: (node: IPublicModelNode, visible: boolean) => void): void {
|
||||
// TODO: history 变化时需要重新绑定
|
||||
this[documentSymbol].nodesMap.forEach((node) => {
|
||||
this[documentSymbol].nodesMap?.forEach((node) => {
|
||||
node.onVisibleChange((flag: boolean) => {
|
||||
fn(Node.create(node)!, flag);
|
||||
});
|
||||
@ -287,10 +294,10 @@ export default class DocumentModel {
|
||||
* 当前 document 的节点 children 变更事件
|
||||
* @param fn
|
||||
*/
|
||||
onChangeNodeChildren(fn: (info?: IOnChangeOptions) => void) {
|
||||
onChangeNodeChildren(fn: (info?: IPublicOnChangeOptions) => void): void {
|
||||
// TODO: history 变化时需要重新绑定
|
||||
this[documentSymbol].nodesMap.forEach((node) => {
|
||||
node.onChildrenChange((info?: InnerIOnChangeOptions) => {
|
||||
this[documentSymbol].nodesMap?.forEach((node) => {
|
||||
node.onChildrenChange((info?: InnerOnChangeOptions) => {
|
||||
return info
|
||||
? fn({
|
||||
type: info.type,
|
||||
@ -305,7 +312,7 @@ export default class DocumentModel {
|
||||
* 当前 document 节点属性修改事件
|
||||
* @param fn
|
||||
*/
|
||||
onChangeNodeProp(fn: (info: PropChangeOptions) => void) {
|
||||
onChangeNodeProp(fn: (info: PropChangeOptions) => void): void {
|
||||
this[editorSymbol].on(
|
||||
GlobalEvent.Node.Prop.InnerChange,
|
||||
(info: GlobalEvent.Node.Prop.ChangeOptions) => {
|
||||
@ -324,7 +331,7 @@ export default class DocumentModel {
|
||||
* import schema event
|
||||
* @param fn
|
||||
*/
|
||||
onImportSchema(fn: (schema: RootSchema) => void) {
|
||||
onImportSchema(fn: (schema: RootSchema) => void): void {
|
||||
this[editorSymbol].on(Events.IMPORT_SCHEMA, fn as any);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,30 +1,34 @@
|
||||
import { DragObject as InnerDragObject, DragNodeDataObject } from '@alilc/lowcode-designer';
|
||||
import { dragObjectSymbol } from './symbols';
|
||||
import { IPublicModelDragObject, DragObject as InnerDragObject, DragNodeDataObject } from '@alilc/lowcode-types';
|
||||
import Node from './node';
|
||||
|
||||
export default class DragObject {
|
||||
export default class DragObject implements IPublicModelDragObject {
|
||||
private readonly [dragObjectSymbol]: InnerDragObject;
|
||||
|
||||
constructor(dragObject: InnerDragObject) {
|
||||
this[dragObjectSymbol] = dragObject;
|
||||
}
|
||||
|
||||
static create(dragObject: InnerDragObject) {
|
||||
if (!dragObject) return null;
|
||||
static create(dragObject: InnerDragObject): IPublicModelDragObject | null {
|
||||
if (!dragObject) {
|
||||
return null;
|
||||
}
|
||||
return new DragObject(dragObject);
|
||||
}
|
||||
|
||||
get type() {
|
||||
get type(): any {
|
||||
return this[dragObjectSymbol].type;
|
||||
}
|
||||
|
||||
get nodes() {
|
||||
get nodes(): any {
|
||||
const { nodes } = this[dragObjectSymbol];
|
||||
if (!nodes) return null;
|
||||
if (!nodes) {
|
||||
return null;
|
||||
}
|
||||
return nodes.map(Node.create);
|
||||
}
|
||||
|
||||
get data() {
|
||||
get data(): any {
|
||||
return (this[dragObjectSymbol] as DragNodeDataObject).data;
|
||||
}
|
||||
}
|
||||
@ -1,29 +1,36 @@
|
||||
import {
|
||||
Dragon as InnerDragon,
|
||||
DragObject as InnerDragObject,
|
||||
DragNodeDataObject,
|
||||
LocateEvent as InnerLocateEvent,
|
||||
} from '@alilc/lowcode-designer';
|
||||
import { dragonSymbol } from './symbols';
|
||||
import LocateEvent from './locate-event';
|
||||
import DragObject from './drag-object';
|
||||
import {
|
||||
IPublicModelDragon,
|
||||
IPublicModelLocateEvent,
|
||||
IPublicModelDragObject,
|
||||
DragObject as InnerDragObject,
|
||||
DragNodeDataObject,
|
||||
} from '@alilc/lowcode-types';
|
||||
|
||||
export default class Dragon {
|
||||
export default class Dragon implements IPublicModelDragon {
|
||||
private readonly [dragonSymbol]: InnerDragon;
|
||||
|
||||
constructor(dragon: InnerDragon) {
|
||||
this[dragonSymbol] = dragon;
|
||||
}
|
||||
|
||||
static create(dragon: InnerDragon | null) {
|
||||
if (!dragon) return null;
|
||||
static create(dragon: InnerDragon | null): IPublicModelDragon | null {
|
||||
if (!dragon) {
|
||||
return null;
|
||||
}
|
||||
return new Dragon(dragon);
|
||||
}
|
||||
|
||||
/**
|
||||
* is dragging or not
|
||||
*/
|
||||
get dragging() {
|
||||
get dragging(): boolean {
|
||||
return this[dragonSymbol].dragging;
|
||||
}
|
||||
|
||||
@ -32,7 +39,7 @@ export default class Dragon {
|
||||
* @param func
|
||||
* @returns
|
||||
*/
|
||||
onDragstart(func: (e: LocateEvent) => any) {
|
||||
onDragstart(func: (e: IPublicModelLocateEvent) => any): () => void {
|
||||
return this[dragonSymbol].onDragstart((e: InnerLocateEvent) => func(LocateEvent.create(e)!));
|
||||
}
|
||||
|
||||
@ -41,7 +48,7 @@ export default class Dragon {
|
||||
* @param func
|
||||
* @returns
|
||||
*/
|
||||
onDrag(func: (e: LocateEvent) => any) {
|
||||
onDrag(func: (e: IPublicModelLocateEvent) => any): () => void {
|
||||
return this[dragonSymbol].onDrag((e: InnerLocateEvent) => func(LocateEvent.create(e)!));
|
||||
}
|
||||
|
||||
@ -50,7 +57,7 @@ export default class Dragon {
|
||||
* @param func
|
||||
* @returns
|
||||
*/
|
||||
onDragend(func: (o: { dragObject: DragObject; copy?: boolean }) => any) {
|
||||
onDragend(func: (o: { dragObject: IPublicModelDragObject; copy?: boolean }) => any): () => void {
|
||||
return this[dragonSymbol].onDragend(
|
||||
(o: { dragObject: InnerDragObject; copy?: boolean }) => func({
|
||||
dragObject: DragObject.create(o.dragObject)!,
|
||||
@ -64,7 +71,7 @@ export default class Dragon {
|
||||
* @param shell 拖拽监听的区域
|
||||
* @param boost 拖拽转换函数
|
||||
*/
|
||||
from(shell: Element, boost: (e: MouseEvent) => DragNodeDataObject | null) {
|
||||
from(shell: Element, boost: (e: MouseEvent) => DragNodeDataObject | null): any {
|
||||
return this[dragonSymbol].from(shell, boost);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,16 +3,19 @@ import {
|
||||
} from '@alilc/lowcode-designer';
|
||||
import { dropLocationSymbol } from './symbols';
|
||||
import Node from './node';
|
||||
import { IPublicModelDropLocation } from '@alilc/lowcode-types';
|
||||
|
||||
export default class DropLocation {
|
||||
export default class DropLocation implements IPublicModelDropLocation {
|
||||
private readonly [dropLocationSymbol]: InnerDropLocation;
|
||||
|
||||
constructor(dropLocation: InnerDropLocation) {
|
||||
this[dropLocationSymbol] = dropLocation;
|
||||
}
|
||||
|
||||
static create(dropLocation: InnerDropLocation | null) {
|
||||
if (!dropLocation) return null;
|
||||
static create(dropLocation: InnerDropLocation | null): DropLocation | null {
|
||||
if (!dropLocation) {
|
||||
return null;
|
||||
}
|
||||
return new DropLocation(dropLocation);
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { Editor as InnerEditor, globalContext } from '@alilc/lowcode-editor-core';
|
||||
import { Editor as InnerEditor } from '@alilc/lowcode-editor-core';
|
||||
import { getLogger } from '@alilc/lowcode-utils';
|
||||
import { editorSymbol } from './symbols';
|
||||
import { IPublicApiEvent } from '@alilc/lowcode-types';
|
||||
|
||||
const logger = getLogger({ level: 'warn', bizName: 'shell:event' });
|
||||
|
||||
@ -8,7 +9,7 @@ type EventOptions = {
|
||||
prefix: string;
|
||||
};
|
||||
|
||||
export default class Event {
|
||||
export default class Event implements IPublicApiEvent {
|
||||
private readonly [editorSymbol]: InnerEditor;
|
||||
private readonly options: EventOptions;
|
||||
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
import { History as InnerHistory, DocumentModel as InnerDocumentModel } from '@alilc/lowcode-designer';
|
||||
import { DocumentModel as InnerDocumentModel } from '@alilc/lowcode-designer';
|
||||
import { historySymbol, documentSymbol } from './symbols';
|
||||
import { IPublicModelHistory } from '@alilc/lowcode-types';
|
||||
|
||||
export default class History {
|
||||
export default class History implements IPublicModelHistory {
|
||||
private readonly [documentSymbol]: InnerDocumentModel;
|
||||
|
||||
private get [historySymbol]() {
|
||||
@ -16,28 +17,28 @@ export default class History {
|
||||
* 历史记录跳转到指定位置
|
||||
* @param cursor
|
||||
*/
|
||||
go(cursor: number) {
|
||||
go(cursor: number): void {
|
||||
this[historySymbol].go(cursor);
|
||||
}
|
||||
|
||||
/**
|
||||
* 历史记录后退
|
||||
*/
|
||||
back() {
|
||||
back(): void {
|
||||
this[historySymbol].back();
|
||||
}
|
||||
|
||||
/**
|
||||
* 历史记录前进
|
||||
*/
|
||||
forward() {
|
||||
forward(): void {
|
||||
this[historySymbol].forward();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存当前状态
|
||||
*/
|
||||
savePoint() {
|
||||
savePoint(): void {
|
||||
this[historySymbol].savePoint();
|
||||
}
|
||||
|
||||
@ -45,7 +46,7 @@ export default class History {
|
||||
* 当前是否是「保存点」,即是否有状态变更但未保存
|
||||
* @returns
|
||||
*/
|
||||
isSavePoint() {
|
||||
isSavePoint(): boolean {
|
||||
return this[historySymbol].isSavePoint();
|
||||
}
|
||||
|
||||
@ -53,7 +54,7 @@ export default class History {
|
||||
* 获取 state,判断当前是否为「可回退」、「可前进」的状态
|
||||
* @returns
|
||||
*/
|
||||
getState() {
|
||||
getState(): any {
|
||||
return this[historySymbol].getState();
|
||||
}
|
||||
|
||||
@ -62,7 +63,7 @@ export default class History {
|
||||
* @param func
|
||||
* @returns
|
||||
*/
|
||||
onChangeState(func: () => any) {
|
||||
onChangeState(func: () => any): () => void {
|
||||
return this[historySymbol].onStateChange(func);
|
||||
}
|
||||
|
||||
@ -71,7 +72,7 @@ export default class History {
|
||||
* @param func
|
||||
* @returns
|
||||
*/
|
||||
onChangeCursor(func: () => any) {
|
||||
onChangeCursor(func: () => any): () => void {
|
||||
return this[historySymbol].onCursor(func);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { hotkey, HotkeyCallback } from '@alilc/lowcode-editor-core';
|
||||
import { Disposable } from '@alilc/lowcode-types';
|
||||
import { hotkey } from '@alilc/lowcode-editor-core';
|
||||
import { Disposable, HotkeyCallback, IPublicApiHotkey } from '@alilc/lowcode-types';
|
||||
|
||||
export default class Hotkey {
|
||||
export default class Hotkey implements IPublicApiHotkey {
|
||||
get callbacks() {
|
||||
return hotkey.callBacks;
|
||||
}
|
||||
|
||||
@ -1,48 +1,51 @@
|
||||
import { LocateEvent as InnerLocateEvent } from '@alilc/lowcode-designer';
|
||||
import { locateEventSymbol } from './symbols';
|
||||
import DragObject from './drag-object';
|
||||
import { IPublicModelLocateEvent, IPublicModelDragObject } from '@alilc/lowcode-types';
|
||||
|
||||
export default class LocateEvent {
|
||||
export default class LocateEvent implements IPublicModelLocateEvent {
|
||||
private readonly [locateEventSymbol]: InnerLocateEvent;
|
||||
|
||||
constructor(locateEvent: InnerLocateEvent) {
|
||||
this[locateEventSymbol] = locateEvent;
|
||||
}
|
||||
|
||||
static create(locateEvent: InnerLocateEvent) {
|
||||
if (!locateEvent) return null;
|
||||
static create(locateEvent: InnerLocateEvent): IPublicModelLocateEvent | null {
|
||||
if (!locateEvent) {
|
||||
return null;
|
||||
}
|
||||
return new LocateEvent(locateEvent);
|
||||
}
|
||||
|
||||
get type() {
|
||||
get type(): string {
|
||||
return this[locateEventSymbol].type;
|
||||
}
|
||||
|
||||
get globalX() {
|
||||
get globalX(): number {
|
||||
return this[locateEventSymbol].globalX;
|
||||
}
|
||||
|
||||
get globalY() {
|
||||
get globalY(): number {
|
||||
return this[locateEventSymbol].globalY;
|
||||
}
|
||||
|
||||
get originalEvent() {
|
||||
get originalEvent(): MouseEvent | DragEvent {
|
||||
return this[locateEventSymbol].originalEvent;
|
||||
}
|
||||
|
||||
get target() {
|
||||
get target(): Element | null | undefined {
|
||||
return this[locateEventSymbol].target;
|
||||
}
|
||||
|
||||
get canvasX() {
|
||||
get canvasX(): number | undefined {
|
||||
return this[locateEventSymbol].canvasX;
|
||||
}
|
||||
|
||||
get canvasY() {
|
||||
get canvasY(): number | undefined {
|
||||
return this[locateEventSymbol].canvasY;
|
||||
}
|
||||
|
||||
get dragObject() {
|
||||
get dragObject(): IPublicModelDragObject | null {
|
||||
return DragObject.create(this[locateEventSymbol].dragObject);
|
||||
}
|
||||
}
|
||||
@ -2,7 +2,6 @@ import { Editor } from '@alilc/lowcode-editor-core';
|
||||
import {
|
||||
Designer,
|
||||
registerMetadataTransducer,
|
||||
MetadataTransducer,
|
||||
getRegisteredMetadataTransducers,
|
||||
addBuiltinComponentAction,
|
||||
removeBuiltinComponentAction,
|
||||
@ -10,11 +9,17 @@ import {
|
||||
isComponentMeta,
|
||||
} from '@alilc/lowcode-designer';
|
||||
import { AssetsJson } from '@alilc/lowcode-utils';
|
||||
import { ComponentAction, ComponentMetadata } from '@alilc/lowcode-types';
|
||||
import {
|
||||
ComponentAction,
|
||||
ComponentMetadata,
|
||||
IPublicApiMaterial,
|
||||
MetadataTransducer,
|
||||
IPublicModelComponentMeta,
|
||||
} from '@alilc/lowcode-types';
|
||||
import { editorSymbol, designerSymbol } from './symbols';
|
||||
import ComponentMeta from './component-meta';
|
||||
|
||||
export default class Material {
|
||||
export default class Material implements IPublicApiMaterial {
|
||||
private readonly [editorSymbol]: Editor;
|
||||
private readonly [designerSymbol]: Designer;
|
||||
|
||||
@ -83,8 +88,9 @@ export default class Material {
|
||||
* @param componentName
|
||||
* @returns
|
||||
*/
|
||||
getComponentMeta(componentName: string) {
|
||||
return ComponentMeta.create(this[designerSymbol].getComponentMeta(componentName));
|
||||
getComponentMeta(componentName: string): IPublicModelComponentMeta | null {
|
||||
const innerMeta = this[designerSymbol].getComponentMeta(componentName);
|
||||
return ComponentMeta.create(innerMeta);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -109,8 +115,8 @@ export default class Material {
|
||||
* 获取所有已注册的物料元数据
|
||||
* @returns
|
||||
*/
|
||||
getComponentMetasMap() {
|
||||
const map = new Map<string, ComponentMeta>();
|
||||
getComponentMetasMap(): Map<string, IPublicModelComponentMeta> {
|
||||
const map = new Map<string, IPublicModelComponentMeta>();
|
||||
const originalMap = this[designerSymbol].getComponentMetasMap();
|
||||
for (let componentName of originalMap.keys()) {
|
||||
map.set(componentName, this.getComponentMeta(componentName)!);
|
||||
|
||||
@ -1,24 +1,28 @@
|
||||
import { ModalNodesManager as InnerModalNodesManager, Node as InnerNode } from '@alilc/lowcode-designer';
|
||||
import { NodeSchema, NodeData, TransformStage } from '@alilc/lowcode-types';
|
||||
import { IPublicModelModalNodesManager, IPublicModelNode } from '@alilc/lowcode-types';
|
||||
import Node from './node';
|
||||
import { nodeSymbol, modalNodesManagerSymbol } from './symbols';
|
||||
|
||||
export default class ModalNodesManager {
|
||||
export default class ModalNodesManager implements IPublicModelModalNodesManager {
|
||||
private readonly [modalNodesManagerSymbol]: InnerModalNodesManager;
|
||||
|
||||
constructor(modalNodesManager: InnerModalNodesManager) {
|
||||
this[modalNodesManagerSymbol] = modalNodesManager;
|
||||
}
|
||||
|
||||
static create(modalNodesManager: InnerModalNodesManager | null) {
|
||||
if (!modalNodesManager) return null;
|
||||
static create(
|
||||
modalNodesManager: InnerModalNodesManager | null,
|
||||
): IPublicModelModalNodesManager | null {
|
||||
if (!modalNodesManager) {
|
||||
return null;
|
||||
}
|
||||
return new ModalNodesManager(modalNodesManager);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置模态节点,触发内部事件
|
||||
*/
|
||||
setNodes() {
|
||||
setNodes(): void {
|
||||
this[modalNodesManagerSymbol].setNodes();
|
||||
}
|
||||
|
||||
@ -26,7 +30,7 @@ export default class ModalNodesManager {
|
||||
* 获取模态节点(们)
|
||||
* @returns
|
||||
*/
|
||||
getModalNodes() {
|
||||
getModalNodes(): any {
|
||||
return this[modalNodesManagerSymbol].getModalNodes().map((node) => Node.create(node));
|
||||
}
|
||||
|
||||
@ -34,14 +38,14 @@ export default class ModalNodesManager {
|
||||
* 获取当前可见的模态节点
|
||||
* @returns
|
||||
*/
|
||||
getVisibleModalNode() {
|
||||
getVisibleModalNode(): any {
|
||||
return Node.create(this[modalNodesManagerSymbol].getVisibleModalNode());
|
||||
}
|
||||
|
||||
/**
|
||||
* 隐藏模态节点(们)
|
||||
*/
|
||||
hideModalNodes() {
|
||||
hideModalNodes(): void {
|
||||
this[modalNodesManagerSymbol].hideModalNodes();
|
||||
}
|
||||
|
||||
@ -49,7 +53,7 @@ export default class ModalNodesManager {
|
||||
* 设置指定节点为可见态
|
||||
* @param node Node
|
||||
*/
|
||||
setVisible(node: Node) {
|
||||
setVisible(node: IPublicModelNode): void {
|
||||
this[modalNodesManagerSymbol].setVisible(node[nodeSymbol]);
|
||||
}
|
||||
|
||||
@ -57,7 +61,7 @@ export default class ModalNodesManager {
|
||||
* 设置指定节点为不可见态
|
||||
* @param node Node
|
||||
*/
|
||||
setInvisible(node: Node) {
|
||||
setInvisible(node: IPublicModelNode): void {
|
||||
this[modalNodesManagerSymbol].setInvisible(node[nodeSymbol]);
|
||||
}
|
||||
}
|
||||
@ -1,31 +1,33 @@
|
||||
import { NodeChildren as InnerNodeChildren, Node as InnerNode } from '@alilc/lowcode-designer';
|
||||
import { NodeSchema, NodeData, TransformStage } from '@alilc/lowcode-types';
|
||||
import { NodeSchema, NodeData, TransformStage, IPublicModelNodeChildren, IPublicModelNode } from '@alilc/lowcode-types';
|
||||
import Node from './node';
|
||||
import { nodeSymbol, nodeChildrenSymbol } from './symbols';
|
||||
|
||||
export default class NodeChildren {
|
||||
export default class NodeChildren implements IPublicModelNodeChildren {
|
||||
private readonly [nodeChildrenSymbol]: InnerNodeChildren;
|
||||
|
||||
constructor(nodeChildren: InnerNodeChildren) {
|
||||
this[nodeChildrenSymbol] = nodeChildren;
|
||||
}
|
||||
|
||||
static create(nodeChldren: InnerNodeChildren | null) {
|
||||
if (!nodeChldren) return null;
|
||||
static create(nodeChldren: InnerNodeChildren | null): IPublicModelNodeChildren | null {
|
||||
if (!nodeChldren) {
|
||||
return null;
|
||||
}
|
||||
return new NodeChildren(nodeChldren);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回当前 children 实例所属的节点实例
|
||||
*/
|
||||
get owner(): Node | null {
|
||||
get owner(): IPublicModelNode | null {
|
||||
return Node.create(this[nodeChildrenSymbol].owner);
|
||||
}
|
||||
|
||||
/**
|
||||
* children 内的节点实例数
|
||||
*/
|
||||
get size() {
|
||||
get size(): number {
|
||||
return this[nodeChildrenSymbol].size;
|
||||
}
|
||||
|
||||
@ -33,14 +35,14 @@ export default class NodeChildren {
|
||||
* 是否为空
|
||||
* @returns
|
||||
*/
|
||||
get isEmpty() {
|
||||
get isEmpty(): boolean {
|
||||
return this[nodeChildrenSymbol].isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* judge if it is not empty
|
||||
*/
|
||||
get notEmpty() {
|
||||
get notEmpty(): boolean {
|
||||
return !this.isEmpty;
|
||||
}
|
||||
|
||||
@ -49,8 +51,8 @@ export default class NodeChildren {
|
||||
* @param node
|
||||
* @returns
|
||||
*/
|
||||
delete(node: Node) {
|
||||
return this[nodeChildrenSymbol].delete(node[nodeSymbol]);
|
||||
delete(node: IPublicModelNode): boolean {
|
||||
return this[nodeChildrenSymbol].delete((node as any)[nodeSymbol]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -59,8 +61,8 @@ export default class NodeChildren {
|
||||
* @param at 插入下标
|
||||
* @returns
|
||||
*/
|
||||
insert(node: Node, at?: number | null) {
|
||||
return this[nodeChildrenSymbol].insert(node[nodeSymbol], at, true);
|
||||
insert(node: IPublicModelNode, at?: number | null): void {
|
||||
return this[nodeChildrenSymbol].insert((node as any)[nodeSymbol], at, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -68,8 +70,8 @@ export default class NodeChildren {
|
||||
* @param node
|
||||
* @returns
|
||||
*/
|
||||
indexOf(node: Node) {
|
||||
return this[nodeChildrenSymbol].indexOf(node[nodeSymbol]);
|
||||
indexOf(node: IPublicModelNode): number {
|
||||
return this[nodeChildrenSymbol].indexOf((node as any)[nodeSymbol]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -78,8 +80,8 @@ export default class NodeChildren {
|
||||
* @param deleteCount
|
||||
* @param node
|
||||
*/
|
||||
splice(start: number, deleteCount: number, node?: Node) {
|
||||
this[nodeChildrenSymbol].splice(start, deleteCount, node?.[nodeSymbol]);
|
||||
splice(start: number, deleteCount: number, node?: IPublicModelNode): any {
|
||||
this[nodeChildrenSymbol].splice(start, deleteCount, (node as any)?.[nodeSymbol]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -87,7 +89,7 @@ export default class NodeChildren {
|
||||
* @param index
|
||||
* @returns
|
||||
*/
|
||||
get(index: number) {
|
||||
get(index: number): any {
|
||||
return Node.create(this[nodeChildrenSymbol].get(index));
|
||||
}
|
||||
|
||||
@ -96,15 +98,15 @@ export default class NodeChildren {
|
||||
* @param node
|
||||
* @returns
|
||||
*/
|
||||
has(node: Node) {
|
||||
return this[nodeChildrenSymbol].has(node[nodeSymbol]);
|
||||
has(node: IPublicModelNode): boolean {
|
||||
return this[nodeChildrenSymbol].has((node as any)[nodeSymbol]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 类似数组的 forEach
|
||||
* @param fn
|
||||
*/
|
||||
forEach(fn: (node: Node, index: number) => void) {
|
||||
forEach(fn: (node: IPublicModelNode, index: number) => void): void {
|
||||
this[nodeChildrenSymbol].forEach((item: InnerNode<NodeSchema>, index: number) => {
|
||||
fn(Node.create(item)!, index);
|
||||
});
|
||||
@ -114,7 +116,7 @@ export default class NodeChildren {
|
||||
* 类似数组的 map
|
||||
* @param fn
|
||||
*/
|
||||
map<T>(fn: (node: Node, index: number) => T[]) {
|
||||
map<T>(fn: (node: IPublicModelNode, index: number) => T[]): any[] | null {
|
||||
return this[nodeChildrenSymbol].map((item: InnerNode<NodeSchema>, index: number) => {
|
||||
return fn(Node.create(item)!, index);
|
||||
});
|
||||
@ -124,7 +126,7 @@ export default class NodeChildren {
|
||||
* 类似数组的 every
|
||||
* @param fn
|
||||
*/
|
||||
every(fn: (node: Node, index: number) => boolean) {
|
||||
every(fn: (node: IPublicModelNode, index: number) => boolean): boolean {
|
||||
return this[nodeChildrenSymbol].every((item: InnerNode<NodeSchema>, index: number) => {
|
||||
return fn(Node.create(item)!, index);
|
||||
});
|
||||
@ -134,7 +136,7 @@ export default class NodeChildren {
|
||||
* 类似数组的 some
|
||||
* @param fn
|
||||
*/
|
||||
some(fn: (node: Node, index: number) => boolean) {
|
||||
some(fn: (node: IPublicModelNode, index: number) => boolean): boolean {
|
||||
return this[nodeChildrenSymbol].some((item: InnerNode<NodeSchema>, index: number) => {
|
||||
return fn(Node.create(item)!, index);
|
||||
});
|
||||
@ -144,7 +146,7 @@ export default class NodeChildren {
|
||||
* 类似数组的 filter
|
||||
* @param fn
|
||||
*/
|
||||
filter(fn: (node: Node, index: number) => boolean) {
|
||||
filter(fn: (node: IPublicModelNode, index: number) => boolean): any {
|
||||
return this[nodeChildrenSymbol]
|
||||
.filter((item: InnerNode<NodeSchema>, index: number) => {
|
||||
return fn(Node.create(item)!, index);
|
||||
@ -156,7 +158,7 @@ export default class NodeChildren {
|
||||
* 类似数组的 find
|
||||
* @param fn
|
||||
*/
|
||||
find(fn: (node: Node, index: number) => boolean) {
|
||||
find(fn: (node: IPublicModelNode, index: number) => boolean): IPublicModelNode | null {
|
||||
return Node.create(
|
||||
this[nodeChildrenSymbol].find((item: InnerNode<NodeSchema>, index: number) => {
|
||||
return fn(Node.create(item)!, index);
|
||||
@ -168,7 +170,7 @@ export default class NodeChildren {
|
||||
* 类似数组的 reduce
|
||||
* @param fn
|
||||
*/
|
||||
reduce(fn: (acc: any, cur: Node) => any, initialValue: any) {
|
||||
reduce(fn: (acc: any, cur: IPublicModelNode) => any, initialValue: any): void {
|
||||
return this[nodeChildrenSymbol].reduce((acc: any, cur: InnerNode) => {
|
||||
return fn(acc, Node.create(cur)!);
|
||||
}, initialValue);
|
||||
@ -178,7 +180,7 @@ export default class NodeChildren {
|
||||
* 导入 schema
|
||||
* @param data
|
||||
*/
|
||||
importSchema(data?: NodeData | NodeData[]) {
|
||||
importSchema(data?: NodeData | NodeData[]): void {
|
||||
this[nodeChildrenSymbol].import(data);
|
||||
}
|
||||
|
||||
@ -187,7 +189,7 @@ export default class NodeChildren {
|
||||
* @param stage
|
||||
* @returns
|
||||
*/
|
||||
exportSchema(stage: TransformStage = TransformStage.Render) {
|
||||
exportSchema(stage: TransformStage = TransformStage.Render): any {
|
||||
return this[nodeChildrenSymbol].export(stage);
|
||||
}
|
||||
|
||||
@ -198,9 +200,9 @@ export default class NodeChildren {
|
||||
* @param sorter
|
||||
*/
|
||||
mergeChildren(
|
||||
remover: (node: Node, idx: number) => boolean,
|
||||
adder: (children: Node[]) => any,
|
||||
sorter: (firstNode: Node, secondNode: Node) => number,
|
||||
remover: (node: IPublicModelNode, idx: number) => boolean,
|
||||
adder: (children: IPublicModelNode[]) => any,
|
||||
sorter: (firstNode: IPublicModelNode, secondNode: IPublicModelNode) => number,
|
||||
) {
|
||||
if (!sorter) {
|
||||
sorter = () => 0;
|
||||
|
||||
@ -1,9 +1,23 @@
|
||||
import {
|
||||
DocumentModel as InnerDocumentModel,
|
||||
Node as InnerNode,
|
||||
getConvertedExtraKey,
|
||||
} from '@alilc/lowcode-designer';
|
||||
import { CompositeValue, NodeSchema, TransformStage } from '@alilc/lowcode-types';
|
||||
import {
|
||||
CompositeValue,
|
||||
NodeSchema,
|
||||
TransformStage,
|
||||
IPublicModelNode,
|
||||
IconType,
|
||||
I18nData,
|
||||
IPublicModelComponentMeta,
|
||||
IPublicModelDocumentModel,
|
||||
IPublicModelNodeChildren,
|
||||
IPublicModelProp,
|
||||
IPublicModelProps,
|
||||
PropsMap,
|
||||
PropsList,
|
||||
IPublicModelSettingTopEntry,
|
||||
} from '@alilc/lowcode-types';
|
||||
import Prop from './prop';
|
||||
import Props from './props';
|
||||
import DocumentModel from './document-model';
|
||||
@ -11,10 +25,11 @@ import NodeChildren from './node-children';
|
||||
import ComponentMeta from './component-meta';
|
||||
import SettingTopEntry from './setting-top-entry';
|
||||
import { documentSymbol, nodeSymbol } from './symbols';
|
||||
import { ReactElement } from 'react';
|
||||
|
||||
const shellNodeSymbol = Symbol('shellNodeSymbol');
|
||||
|
||||
export default class Node {
|
||||
export default class Node implements IPublicModelNode {
|
||||
private readonly [documentSymbol]: InnerDocumentModel;
|
||||
private readonly [nodeSymbol]: InnerNode;
|
||||
|
||||
@ -27,10 +42,14 @@ export default class Node {
|
||||
this._id = this[nodeSymbol].id;
|
||||
}
|
||||
|
||||
static create(node: InnerNode | null | undefined) {
|
||||
if (!node) return null;
|
||||
static create(node: InnerNode | null | undefined): IPublicModelNode | null {
|
||||
if (!node) {
|
||||
return null;
|
||||
}
|
||||
// @ts-ignore 直接返回已挂载的 shell node 实例
|
||||
if (node[shellNodeSymbol]) return node[shellNodeSymbol];
|
||||
if (node[shellNodeSymbol]) {
|
||||
return (node as any)[shellNodeSymbol];
|
||||
}
|
||||
const shellNode = new Node(node);
|
||||
// @ts-ignore 挂载 shell node 实例
|
||||
node[shellNodeSymbol] = shellNode;
|
||||
@ -54,70 +73,70 @@ export default class Node {
|
||||
/**
|
||||
* 节点标题
|
||||
*/
|
||||
get title() {
|
||||
get title(): string | I18nData | ReactElement {
|
||||
return this[nodeSymbol].title;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为「容器型」节点
|
||||
*/
|
||||
get isContainer() {
|
||||
get isContainer(): boolean {
|
||||
return this[nodeSymbol].isContainer();
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为根节点
|
||||
*/
|
||||
get isRoot() {
|
||||
get isRoot(): boolean {
|
||||
return this[nodeSymbol].isRoot();
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为空节点(无 children 或者 children 为空)
|
||||
*/
|
||||
get isEmpty() {
|
||||
get isEmpty(): boolean {
|
||||
return this[nodeSymbol].isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为 Page 节点
|
||||
*/
|
||||
get isPage() {
|
||||
get isPage(): boolean {
|
||||
return this[nodeSymbol].isPage();
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为 Component 节点
|
||||
*/
|
||||
get isComponent() {
|
||||
get isComponent(): boolean {
|
||||
return this[nodeSymbol].isComponent();
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为「模态框」节点
|
||||
*/
|
||||
get isModal() {
|
||||
get isModal(): boolean {
|
||||
return this[nodeSymbol].isModal();
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为插槽节点
|
||||
*/
|
||||
get isSlot() {
|
||||
get isSlot(): boolean {
|
||||
return this[nodeSymbol].isSlot();
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为父类/分支节点
|
||||
*/
|
||||
get isParental() {
|
||||
get isParental(): boolean {
|
||||
return this[nodeSymbol].isParental();
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为叶子节点
|
||||
*/
|
||||
get isLeaf() {
|
||||
get isLeaf(): boolean {
|
||||
return this[nodeSymbol].isLeaf();
|
||||
}
|
||||
|
||||
@ -129,7 +148,7 @@ export default class Node {
|
||||
/**
|
||||
* 获取当前节点的锁定状态
|
||||
*/
|
||||
get isLocked() {
|
||||
get isLocked(): boolean {
|
||||
return this[nodeSymbol].isLocked;
|
||||
}
|
||||
|
||||
@ -143,28 +162,28 @@ export default class Node {
|
||||
/**
|
||||
* 图标
|
||||
*/
|
||||
get icon() {
|
||||
get icon(): IconType {
|
||||
return this[nodeSymbol].icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* 节点所在树的层级深度,根节点深度为 0
|
||||
*/
|
||||
get zLevel() {
|
||||
get zLevel(): number {
|
||||
return this[nodeSymbol].zLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 节点 componentName
|
||||
*/
|
||||
get componentName() {
|
||||
get componentName(): string {
|
||||
return this[nodeSymbol].componentName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 节点的物料元数据
|
||||
*/
|
||||
get componentMeta() {
|
||||
get componentMeta(): IPublicModelComponentMeta | null {
|
||||
return ComponentMeta.create(this[nodeSymbol].componentMeta);
|
||||
}
|
||||
|
||||
@ -172,7 +191,7 @@ export default class Node {
|
||||
* 获取节点所属的文档模型对象
|
||||
* @returns
|
||||
*/
|
||||
get document() {
|
||||
get document(): IPublicModelDocumentModel | null {
|
||||
return DocumentModel.create(this[documentSymbol]);
|
||||
}
|
||||
|
||||
@ -180,7 +199,7 @@ export default class Node {
|
||||
* 获取当前节点的前一个兄弟节点
|
||||
* @returns
|
||||
*/
|
||||
get prevSibling(): Node | null {
|
||||
get prevSibling(): IPublicModelNode | null {
|
||||
return Node.create(this[nodeSymbol].prevSibling);
|
||||
}
|
||||
|
||||
@ -188,7 +207,7 @@ export default class Node {
|
||||
* 获取当前节点的后一个兄弟节点
|
||||
* @returns
|
||||
*/
|
||||
get nextSibling(): Node | null {
|
||||
get nextSibling(): IPublicModelNode | null {
|
||||
return Node.create(this[nodeSymbol].nextSibling);
|
||||
}
|
||||
|
||||
@ -196,7 +215,7 @@ export default class Node {
|
||||
* 获取当前节点的父亲节点
|
||||
* @returns
|
||||
*/
|
||||
get parent(): Node | null {
|
||||
get parent(): IPublicModelNode | null {
|
||||
return Node.create(this[nodeSymbol].parent);
|
||||
}
|
||||
|
||||
@ -204,46 +223,46 @@ export default class Node {
|
||||
* 获取当前节点的孩子节点模型
|
||||
* @returns
|
||||
*/
|
||||
get children() {
|
||||
get children(): IPublicModelNodeChildren | null {
|
||||
return NodeChildren.create(this[nodeSymbol].children);
|
||||
}
|
||||
|
||||
/**
|
||||
* 节点上挂载的插槽节点们
|
||||
*/
|
||||
get slots(): Node[] {
|
||||
get slots(): IPublicModelNode[] {
|
||||
return this[nodeSymbol].slots.map((node: InnerNode) => Node.create(node)!);
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前节点为插槽节点时,返回节点对应的属性实例
|
||||
*/
|
||||
get slotFor() {
|
||||
get slotFor(): IPublicModelProp | null {
|
||||
return Prop.create(this[nodeSymbol].slotFor);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回节点的属性集
|
||||
*/
|
||||
get props() {
|
||||
get props(): IPublicModelProps | null {
|
||||
return Props.create(this[nodeSymbol].props);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回节点的属性集
|
||||
*/
|
||||
get propsData() {
|
||||
get propsData(): PropsMap | PropsList | null {
|
||||
return this[nodeSymbol].propsData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取符合搭建协议-节点 schema 结构
|
||||
* 获取符合搭建协议 - 节点 schema 结构
|
||||
*/
|
||||
get schema(): any {
|
||||
get schema(): NodeSchema {
|
||||
return this[nodeSymbol].schema;
|
||||
}
|
||||
|
||||
get settingEntry(): any {
|
||||
get settingEntry(): IPublicModelSettingTopEntry {
|
||||
return SettingTopEntry.create(this[nodeSymbol].settingEntry as any);
|
||||
}
|
||||
|
||||
@ -256,6 +275,7 @@ export default class Node {
|
||||
|
||||
/**
|
||||
* 获取节点实例对应的 dom 节点
|
||||
* @deprecated
|
||||
*/
|
||||
getDOMNode() {
|
||||
return this[nodeSymbol].getDOMNode();
|
||||
@ -268,10 +288,10 @@ export default class Node {
|
||||
* @param sorter
|
||||
*/
|
||||
mergeChildren(
|
||||
remover: (node: Node, idx: number) => boolean,
|
||||
adder: (children: Node[]) => any,
|
||||
sorter: (firstNode: Node, secondNode: Node) => number,
|
||||
) {
|
||||
remover: (node: IPublicModelNode, idx: number) => boolean,
|
||||
adder: (children: IPublicModelNode[]) => any,
|
||||
sorter: (firstNode: IPublicModelNode, secondNode: IPublicModelNode) => number,
|
||||
): any {
|
||||
return this.children?.mergeChildren(remover, adder, sorter);
|
||||
}
|
||||
|
||||
@ -279,7 +299,7 @@ export default class Node {
|
||||
* 返回节点的尺寸、位置信息
|
||||
* @returns
|
||||
*/
|
||||
getRect() {
|
||||
getRect(): DOMRect | null {
|
||||
return this[nodeSymbol].getRect();
|
||||
}
|
||||
|
||||
@ -287,7 +307,7 @@ export default class Node {
|
||||
* 是否有挂载插槽节点
|
||||
* @returns
|
||||
*/
|
||||
hasSlots() {
|
||||
hasSlots(): boolean {
|
||||
return this[nodeSymbol].hasSlots();
|
||||
}
|
||||
|
||||
@ -295,7 +315,7 @@ export default class Node {
|
||||
* 是否设定了渲染条件
|
||||
* @returns
|
||||
*/
|
||||
hasCondition() {
|
||||
hasCondition(): boolean {
|
||||
return this[nodeSymbol].hasCondition();
|
||||
}
|
||||
|
||||
@ -303,19 +323,19 @@ export default class Node {
|
||||
* 是否设定了循环数据
|
||||
* @returns
|
||||
*/
|
||||
hasLoop() {
|
||||
hasLoop(): boolean {
|
||||
return this[nodeSymbol].hasLoop();
|
||||
}
|
||||
|
||||
getVisible() {
|
||||
getVisible(): boolean {
|
||||
return this[nodeSymbol].getVisible();
|
||||
}
|
||||
|
||||
setVisible(flag: boolean) {
|
||||
setVisible(flag: boolean): void {
|
||||
this[nodeSymbol].setVisible(flag);
|
||||
}
|
||||
|
||||
isConditionalVisible() {
|
||||
isConditionalVisible(): boolean | undefined {
|
||||
return this[nodeSymbol].isConditionalVisible();
|
||||
}
|
||||
|
||||
@ -323,7 +343,7 @@ export default class Node {
|
||||
* 设置节点锁定状态
|
||||
* @param flag
|
||||
*/
|
||||
lock(flag?: boolean) {
|
||||
lock(flag?: boolean): void {
|
||||
this[nodeSymbol].lock(flag);
|
||||
}
|
||||
|
||||
@ -334,8 +354,8 @@ export default class Node {
|
||||
return this.props;
|
||||
}
|
||||
|
||||
contains(node: Node) {
|
||||
return this[nodeSymbol].contains(node[nodeSymbol]);
|
||||
contains(node: IPublicModelNode): boolean {
|
||||
return this[nodeSymbol].contains((node as any)[nodeSymbol]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -343,7 +363,7 @@ export default class Node {
|
||||
* @param path 属性路径,支持 a / a.b / a.0 等格式
|
||||
* @returns
|
||||
*/
|
||||
getProp(path: string, createIfNone = true): Prop | null {
|
||||
getProp(path: string, createIfNone = true): IPublicModelProp | null {
|
||||
return Prop.create(this[nodeSymbol].getProp(path, createIfNone));
|
||||
}
|
||||
|
||||
@ -363,7 +383,7 @@ export default class Node {
|
||||
* @param createIfNone 当没有属性的时候,是否创建一个属性
|
||||
* @returns
|
||||
*/
|
||||
getExtraProp(path: string, createIfNone?: boolean): Prop | null {
|
||||
getExtraProp(path: string, createIfNone?: boolean): IPublicModelProp | null {
|
||||
return Prop.create(this[nodeSymbol].getExtraProp(path, createIfNone));
|
||||
}
|
||||
|
||||
@ -373,7 +393,7 @@ export default class Node {
|
||||
* @param path 属性路径,支持 a / a.b / a.0 等格式
|
||||
* @returns
|
||||
*/
|
||||
getExtraPropValue(path: string) {
|
||||
getExtraPropValue(path: string): any {
|
||||
return this.getExtraProp(path)?.getValue();
|
||||
}
|
||||
|
||||
@ -383,7 +403,7 @@ export default class Node {
|
||||
* @param value 值
|
||||
* @returns
|
||||
*/
|
||||
setPropValue(path: string, value: CompositeValue) {
|
||||
setPropValue(path: string, value: CompositeValue): void {
|
||||
return this.getProp(path)?.setValue(value);
|
||||
}
|
||||
|
||||
@ -393,7 +413,7 @@ export default class Node {
|
||||
* @param value 值
|
||||
* @returns
|
||||
*/
|
||||
setExtraPropValue(path: string, value: CompositeValue) {
|
||||
setExtraPropValue(path: string, value: CompositeValue): void {
|
||||
return this.getExtraProp(path)?.setValue(value);
|
||||
}
|
||||
|
||||
@ -401,7 +421,7 @@ export default class Node {
|
||||
* 导入节点数据
|
||||
* @param data
|
||||
*/
|
||||
importSchema(data: NodeSchema) {
|
||||
importSchema(data: NodeSchema): void {
|
||||
this[nodeSymbol].import(data);
|
||||
}
|
||||
|
||||
@ -411,7 +431,7 @@ export default class Node {
|
||||
* @param options
|
||||
* @returns
|
||||
*/
|
||||
exportSchema(stage: TransformStage = TransformStage.Render, options?: any) {
|
||||
exportSchema(stage: TransformStage = TransformStage.Render, options?: any): NodeSchema {
|
||||
return this[nodeSymbol].export(stage, options);
|
||||
}
|
||||
|
||||
@ -421,8 +441,16 @@ export default class Node {
|
||||
* @param ref
|
||||
* @param useMutator
|
||||
*/
|
||||
insertBefore(node: Node, ref?: Node | undefined, useMutator?: boolean) {
|
||||
this[nodeSymbol].insertBefore(node[nodeSymbol] || node, ref?.[nodeSymbol], useMutator);
|
||||
insertBefore(
|
||||
node: IPublicModelNode,
|
||||
ref?: IPublicModelNode | undefined,
|
||||
useMutator?: boolean,
|
||||
): void {
|
||||
this[nodeSymbol].insertBefore(
|
||||
(node as any)[nodeSymbol] || node,
|
||||
(ref as any)?.[nodeSymbol],
|
||||
useMutator,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -431,8 +459,16 @@ export default class Node {
|
||||
* @param ref
|
||||
* @param useMutator
|
||||
*/
|
||||
insertAfter(node: Node, ref?: Node | undefined, useMutator?: boolean) {
|
||||
this[nodeSymbol].insertAfter(node[nodeSymbol] || node, ref?.[nodeSymbol], useMutator);
|
||||
insertAfter(
|
||||
node: IPublicModelNode,
|
||||
ref?: IPublicModelNode | undefined,
|
||||
useMutator?: boolean,
|
||||
): void {
|
||||
this[nodeSymbol].insertAfter(
|
||||
(node as any)[nodeSymbol] || node,
|
||||
(ref as any)?.[nodeSymbol],
|
||||
useMutator,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -441,22 +477,22 @@ export default class Node {
|
||||
* @param data 用作替换的节点对象或者节点描述
|
||||
* @returns
|
||||
*/
|
||||
replaceChild(node: Node, data: any) {
|
||||
return Node.create(this[nodeSymbol].replaceChild(node[nodeSymbol], data));
|
||||
replaceChild(node: IPublicModelNode, data: any): IPublicModelNode | null {
|
||||
return Node.create(this[nodeSymbol].replaceChild((node as any)[nodeSymbol], data));
|
||||
}
|
||||
|
||||
/**
|
||||
* 将当前节点替换成指定节点描述
|
||||
* @param schema
|
||||
*/
|
||||
replaceWith(schema: NodeSchema) {
|
||||
replaceWith(schema: NodeSchema): any {
|
||||
this[nodeSymbol].replaceWith(schema);
|
||||
}
|
||||
|
||||
/**
|
||||
* 选中当前节点实例
|
||||
*/
|
||||
select() {
|
||||
select(): void {
|
||||
this[nodeSymbol].select();
|
||||
}
|
||||
|
||||
@ -464,14 +500,14 @@ export default class Node {
|
||||
* 设置悬停态
|
||||
* @param flag
|
||||
*/
|
||||
hover(flag = true) {
|
||||
hover(flag = true): void {
|
||||
this[nodeSymbol].hover(flag);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除当前节点实例
|
||||
*/
|
||||
remove() {
|
||||
remove(): void {
|
||||
this[nodeSymbol].remove();
|
||||
}
|
||||
/**
|
||||
|
||||
@ -1,15 +1,22 @@
|
||||
import {
|
||||
BuiltinSimulatorHost,
|
||||
Project as InnerProject,
|
||||
PropsReducer as PropsTransducer,
|
||||
TransformStage,
|
||||
} from '@alilc/lowcode-designer';
|
||||
import { RootSchema, ProjectSchema, IEditor } from '@alilc/lowcode-types';
|
||||
import {
|
||||
RootSchema,
|
||||
ProjectSchema,
|
||||
IEditor,
|
||||
IPublicApiProject,
|
||||
IPublicApiSimulatorHost,
|
||||
IPublicModelDocumentModel,
|
||||
PropsTransducer,
|
||||
} from '@alilc/lowcode-types';
|
||||
import DocumentModel from './document-model';
|
||||
import SimulatorHost from './simulator-host';
|
||||
import { editorSymbol, projectSymbol, simulatorHostSymbol, simulatorRendererSymbol, documentSymbol } from './symbols';
|
||||
|
||||
export default class Project {
|
||||
export default class Project implements IPublicApiProject {
|
||||
private readonly [projectSymbol]: InnerProject;
|
||||
private readonly [editorSymbol]: IEditor;
|
||||
private [simulatorHostSymbol]: BuiltinSimulatorHost;
|
||||
@ -28,7 +35,7 @@ export default class Project {
|
||||
* 获取当前的 document
|
||||
* @returns
|
||||
*/
|
||||
get currentDocument(): DocumentModel | null {
|
||||
get currentDocument(): IPublicModelDocumentModel | null {
|
||||
return this.getCurrentDocument();
|
||||
}
|
||||
|
||||
@ -36,14 +43,14 @@ export default class Project {
|
||||
* 获取当前 project 下所有 documents
|
||||
* @returns
|
||||
*/
|
||||
get documents(): DocumentModel[] {
|
||||
get documents(): IPublicModelDocumentModel[] {
|
||||
return this[projectSymbol].documents.map((doc) => DocumentModel.create(doc)!);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取模拟器的 host
|
||||
*/
|
||||
get simulatorHost() {
|
||||
get simulatorHost(): IPublicApiSimulatorHost | null {
|
||||
return SimulatorHost.create(this[projectSymbol].simulator as any || this[simulatorHostSymbol]);
|
||||
}
|
||||
|
||||
@ -70,7 +77,7 @@ export default class Project {
|
||||
* @param data
|
||||
* @returns
|
||||
*/
|
||||
createDocument(data?: RootSchema): DocumentModel | null {
|
||||
createDocument(data?: RootSchema): IPublicModelDocumentModel | null {
|
||||
const doc = this[projectSymbol].createDocument(data);
|
||||
return DocumentModel.create(doc);
|
||||
}
|
||||
@ -79,8 +86,8 @@ export default class Project {
|
||||
* 删除一个 document
|
||||
* @param doc
|
||||
*/
|
||||
removeDocument(doc: DocumentModel) {
|
||||
this[projectSymbol].removeDocument(doc[documentSymbol]);
|
||||
removeDocument(doc: IPublicModelDocumentModel) {
|
||||
this[projectSymbol].removeDocument((doc as any)[documentSymbol]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -88,7 +95,7 @@ export default class Project {
|
||||
* @param fileName
|
||||
* @returns
|
||||
*/
|
||||
getDocumentByFileName(fileName: string): DocumentModel | null {
|
||||
getDocumentByFileName(fileName: string): IPublicModelDocumentModel | null {
|
||||
return DocumentModel.create(this[projectSymbol].getDocumentByFileName(fileName));
|
||||
}
|
||||
|
||||
@ -97,7 +104,7 @@ export default class Project {
|
||||
* @param id
|
||||
* @returns
|
||||
*/
|
||||
getDocumentById(id: string): DocumentModel | null {
|
||||
getDocumentById(id: string): IPublicModelDocumentModel | null {
|
||||
return DocumentModel.create(this[projectSymbol].getDocument(id));
|
||||
}
|
||||
|
||||
@ -113,7 +120,7 @@ export default class Project {
|
||||
* 导入 project
|
||||
* @param schema 待导入的 project 数据
|
||||
*/
|
||||
importSchema(schema?: ProjectSchema) {
|
||||
importSchema(schema?: ProjectSchema): void {
|
||||
this[projectSymbol].load(schema, true);
|
||||
}
|
||||
|
||||
@ -121,7 +128,7 @@ export default class Project {
|
||||
* 获取当前的 document
|
||||
* @returns
|
||||
*/
|
||||
getCurrentDocument(): DocumentModel | null {
|
||||
getCurrentDocument(): IPublicModelDocumentModel | null {
|
||||
return DocumentModel.create(this[projectSymbol].currentDocument);
|
||||
}
|
||||
|
||||
@ -130,7 +137,7 @@ export default class Project {
|
||||
* @param transducer
|
||||
* @param stage
|
||||
*/
|
||||
addPropsTransducer(transducer: PropsTransducer, stage: TransformStage) {
|
||||
addPropsTransducer(transducer: PropsTransducer, stage: TransformStage): void {
|
||||
this[projectSymbol].designer.addPropsReducer(transducer, stage);
|
||||
}
|
||||
|
||||
@ -139,14 +146,14 @@ export default class Project {
|
||||
* @param fn
|
||||
* @returns
|
||||
*/
|
||||
onRemoveDocument(fn: (data: { id: string}) => void) {
|
||||
onRemoveDocument(fn: (data: { id: string}) => void): any {
|
||||
return this[editorSymbol].on('designer.document.remove', (data: { id: string }) => fn(data));
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前 project 内的 document 变更事件
|
||||
*/
|
||||
onChangeDocument(fn: (doc: DocumentModel) => void) {
|
||||
onChangeDocument(fn: (doc: IPublicModelDocumentModel) => void) {
|
||||
const offFn = this[projectSymbol].onCurrentDocumentChange((originalDoc) => {
|
||||
fn(DocumentModel.create(originalDoc)!);
|
||||
});
|
||||
@ -159,7 +166,7 @@ export default class Project {
|
||||
/**
|
||||
* 当前 project 的模拟器 ready 事件
|
||||
*/
|
||||
onSimulatorHostReady(fn: (host: SimulatorHost) => void) {
|
||||
onSimulatorHostReady(fn: (host: IPublicApiSimulatorHost) => void) {
|
||||
const offFn = this[projectSymbol].onSimulatorReady((simulator: BuiltinSimulatorHost) => {
|
||||
this[simulatorHostSymbol] = simulator;
|
||||
fn(SimulatorHost.create(simulator)!);
|
||||
|
||||
@ -1,65 +1,69 @@
|
||||
import { Prop as InnerProp } from '@alilc/lowcode-designer';
|
||||
import { CompositeValue, TransformStage } from '@alilc/lowcode-types';
|
||||
import { CompositeValue, TransformStage, IPublicModelProp, IPublicModelNode } from '@alilc/lowcode-types';
|
||||
import { propSymbol } from './symbols';
|
||||
import Node from './node';
|
||||
|
||||
export default class Prop {
|
||||
export default class Prop implements IPublicModelProp {
|
||||
private readonly [propSymbol]: InnerProp;
|
||||
|
||||
constructor(prop: InnerProp) {
|
||||
this[propSymbol] = prop;
|
||||
}
|
||||
|
||||
static create(prop: InnerProp | undefined | null) {
|
||||
if (!prop) return null;
|
||||
static create(prop: InnerProp | undefined | null): IPublicModelProp | null {
|
||||
if (!prop) {
|
||||
return null;
|
||||
}
|
||||
return new Prop(prop);
|
||||
}
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
get id() {
|
||||
get id(): string {
|
||||
return this[propSymbol].id;
|
||||
}
|
||||
|
||||
/**
|
||||
* key 值
|
||||
*/
|
||||
get key() {
|
||||
get key(): string | number | undefined {
|
||||
return this[propSymbol].key;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回当前 prop 的路径
|
||||
*/
|
||||
get path() {
|
||||
get path(): any[] {
|
||||
return this[propSymbol].path;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回所属的节点实例
|
||||
*/
|
||||
get node(): Node | null {
|
||||
get node(): IPublicModelNode | null {
|
||||
return Node.create(this[propSymbol].getNode());
|
||||
}
|
||||
|
||||
/**
|
||||
* return the slot node (only if the current prop represents a slot)
|
||||
*/
|
||||
get slotNode(): Node | null {
|
||||
get slotNode(): IPublicModelNode | null {
|
||||
return Node.create(this[propSymbol].slotNode);
|
||||
}
|
||||
|
||||
/**
|
||||
* judge if it is a prop or not
|
||||
*/
|
||||
get isProp() { return true; }
|
||||
get isProp(): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置值
|
||||
* @param val
|
||||
*/
|
||||
setValue(val: CompositeValue) {
|
||||
setValue(val: CompositeValue): void {
|
||||
this[propSymbol].setValue(val);
|
||||
}
|
||||
|
||||
@ -67,14 +71,14 @@ export default class Prop {
|
||||
* 获取值
|
||||
* @returns
|
||||
*/
|
||||
getValue() {
|
||||
getValue(): any {
|
||||
return this[propSymbol].getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除值
|
||||
*/
|
||||
remove() {
|
||||
remove(): void {
|
||||
this[propSymbol].remove();
|
||||
}
|
||||
|
||||
|
||||
@ -1,39 +1,41 @@
|
||||
import { Props as InnerProps, getConvertedExtraKey } from '@alilc/lowcode-designer';
|
||||
import { CompositeValue, TransformStage } from '@alilc/lowcode-types';
|
||||
import { CompositeValue, IPublicModelProps, IPublicModelNode, IPublicModelProp } from '@alilc/lowcode-types';
|
||||
import { propsSymbol } from './symbols';
|
||||
import Node from './node';
|
||||
import Prop from './prop';
|
||||
|
||||
export default class Props {
|
||||
export default class Props implements IPublicModelProps {
|
||||
private readonly [propsSymbol]: InnerProps;
|
||||
|
||||
constructor(props: InnerProps) {
|
||||
this[propsSymbol] = props;
|
||||
}
|
||||
|
||||
static create(props: InnerProps | undefined | null) {
|
||||
if (!props) return null;
|
||||
static create(props: InnerProps | undefined | null): IPublicModelProps | null {
|
||||
if (!props) {
|
||||
return null;
|
||||
}
|
||||
return new Props(props);
|
||||
}
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
get id() {
|
||||
get id(): string {
|
||||
return this[propsSymbol].id;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回当前 props 的路径
|
||||
*/
|
||||
get path() {
|
||||
get path(): any[] {
|
||||
return this[propsSymbol].path;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回所属的 node 实例
|
||||
*/
|
||||
get node(): Node | null {
|
||||
get node(): IPublicModelNode | null {
|
||||
return Node.create(this[propsSymbol].getNode());
|
||||
}
|
||||
|
||||
@ -42,7 +44,7 @@ export default class Props {
|
||||
* @param path 属性路径,支持 a / a.b / a.0 等格式
|
||||
* @returns
|
||||
*/
|
||||
getProp(path: string): Prop | null {
|
||||
getProp(path: string): IPublicModelProp | null {
|
||||
return Prop.create(this[propsSymbol].getProp(path));
|
||||
}
|
||||
|
||||
@ -51,7 +53,7 @@ export default class Props {
|
||||
* @param path 属性路径,支持 a / a.b / a.0 等格式
|
||||
* @returns
|
||||
*/
|
||||
getPropValue(path: string) {
|
||||
getPropValue(path: string): any {
|
||||
return this.getProp(path)?.getValue();
|
||||
}
|
||||
|
||||
@ -61,7 +63,7 @@ export default class Props {
|
||||
* @param path 属性路径,支持 a / a.b / a.0 等格式
|
||||
* @returns
|
||||
*/
|
||||
getExtraProp(path: string): Prop | null {
|
||||
getExtraProp(path: string): IPublicModelProp | null {
|
||||
return Prop.create(this[propsSymbol].getProp(getConvertedExtraKey(path)));
|
||||
}
|
||||
|
||||
@ -71,7 +73,7 @@ export default class Props {
|
||||
* @param path 属性路径,支持 a / a.b / a.0 等格式
|
||||
* @returns
|
||||
*/
|
||||
getExtraPropValue(path: string) {
|
||||
getExtraPropValue(path: string): any {
|
||||
return this.getExtraProp(path)?.getValue();
|
||||
}
|
||||
|
||||
@ -81,7 +83,7 @@ export default class Props {
|
||||
* @param value 值
|
||||
* @returns
|
||||
*/
|
||||
setPropValue(path: string, value: CompositeValue) {
|
||||
setPropValue(path: string, value: CompositeValue): void {
|
||||
return this.getProp(path)?.setValue(value);
|
||||
}
|
||||
|
||||
@ -91,7 +93,7 @@ export default class Props {
|
||||
* @param value 值
|
||||
* @returns
|
||||
*/
|
||||
setExtraPropValue(path: string, value: CompositeValue) {
|
||||
setExtraPropValue(path: string, value: CompositeValue): void {
|
||||
return this.getExtraProp(path)?.setValue(value);
|
||||
}
|
||||
|
||||
@ -100,7 +102,7 @@ export default class Props {
|
||||
* @param key
|
||||
* @returns
|
||||
*/
|
||||
has(key: string) {
|
||||
has(key: string): boolean {
|
||||
return this[propsSymbol].has(key);
|
||||
}
|
||||
|
||||
@ -110,7 +112,7 @@ export default class Props {
|
||||
* @param key
|
||||
* @returns
|
||||
*/
|
||||
add(value: CompositeValue, key?: string | number | undefined) {
|
||||
add(value: CompositeValue, key?: string | number | undefined): any {
|
||||
return this[propsSymbol].add(value, key);
|
||||
}
|
||||
}
|
||||
@ -4,14 +4,13 @@ import {
|
||||
Selection as InnerSelection,
|
||||
} from '@alilc/lowcode-designer';
|
||||
import Node from './node';
|
||||
import { documentSymbol, selectionSymbol } from './symbols';
|
||||
import { selectionSymbol } from './symbols';
|
||||
import { IPublicModelSelection, IPublicModelNode } from '@alilc/lowcode-types';
|
||||
|
||||
export default class Selection {
|
||||
private readonly [documentSymbol]: InnerDocumentModel;
|
||||
export default class Selection implements IPublicModelSelection {
|
||||
private readonly [selectionSymbol]: InnerSelection;
|
||||
|
||||
constructor(document: InnerDocumentModel) {
|
||||
this[documentSymbol] = document;
|
||||
this[selectionSymbol] = document.selection;
|
||||
}
|
||||
|
||||
@ -25,15 +24,16 @@ export default class Selection {
|
||||
/**
|
||||
* return selected Node instance
|
||||
*/
|
||||
get node(): Node {
|
||||
return this.getNodes()[0];
|
||||
get node(): IPublicModelNode | null {
|
||||
const nodes = this.getNodes();
|
||||
return nodes && nodes.length > 0 ? nodes[0] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 选中指定节点(覆盖方式)
|
||||
* @param id
|
||||
*/
|
||||
select(id: string) {
|
||||
select(id: string): void {
|
||||
this[selectionSymbol].select(id);
|
||||
}
|
||||
|
||||
@ -41,7 +41,7 @@ export default class Selection {
|
||||
* 批量选中指定节点们
|
||||
* @param ids
|
||||
*/
|
||||
selectAll(ids: string[]) {
|
||||
selectAll(ids: string[]): void {
|
||||
this[selectionSymbol].selectAll(ids);
|
||||
}
|
||||
|
||||
@ -49,14 +49,14 @@ export default class Selection {
|
||||
* 移除选中的指定节点
|
||||
* @param id
|
||||
*/
|
||||
remove(id: string) {
|
||||
remove(id: string): void {
|
||||
this[selectionSymbol].remove(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除所有选中节点
|
||||
*/
|
||||
clear() {
|
||||
clear(): void {
|
||||
this[selectionSymbol].clear();
|
||||
}
|
||||
|
||||
@ -65,7 +65,7 @@ export default class Selection {
|
||||
* @param id
|
||||
* @returns
|
||||
*/
|
||||
has(id: string) {
|
||||
has(id: string): boolean {
|
||||
return this[selectionSymbol].has(id);
|
||||
}
|
||||
|
||||
@ -73,7 +73,7 @@ export default class Selection {
|
||||
* 选中指定节点(增量方式)
|
||||
* @param id
|
||||
*/
|
||||
add(id: string) {
|
||||
add(id: string): void {
|
||||
this[selectionSymbol].add(id);
|
||||
}
|
||||
|
||||
@ -81,7 +81,7 @@ export default class Selection {
|
||||
* 获取选中的节点实例
|
||||
* @returns
|
||||
*/
|
||||
getNodes(): Node[] {
|
||||
getNodes(): Array<IPublicModelNode | null> {
|
||||
return this[selectionSymbol].getNodes().map((node: InnerNode) => Node.create(node));
|
||||
}
|
||||
|
||||
@ -92,7 +92,7 @@ export default class Selection {
|
||||
* getTopNodes() will return [A, B], subA will be removed
|
||||
* @returns
|
||||
*/
|
||||
getTopNodes(): Node[] {
|
||||
getTopNodes(): Array<IPublicModelNode | null> {
|
||||
return this[selectionSymbol].getTopNodes().map((node: InnerNode) => Node.create(node));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
import { getSetter, registerSetter, getSettersMap, RegisteredSetter } from '@alilc/lowcode-editor-core';
|
||||
import { CustomView } from '@alilc/lowcode-types';
|
||||
import { getSetter, registerSetter, getSettersMap } from '@alilc/lowcode-editor-core';
|
||||
import { CustomView, IPublicApiSetters, RegisteredSetter } from '@alilc/lowcode-types';
|
||||
|
||||
export default class Setters {
|
||||
export default class Setters implements IPublicApiSetters {
|
||||
/**
|
||||
* 获取指定 setter
|
||||
* @param type
|
||||
* @returns
|
||||
*/
|
||||
getSetter(type: string) {
|
||||
getSetter(type: string): RegisteredSetter | null {
|
||||
return getSetter(type);
|
||||
}
|
||||
|
||||
@ -15,7 +15,9 @@ export default class Setters {
|
||||
* 获取已注册的所有 settersMap
|
||||
* @returns
|
||||
*/
|
||||
getSettersMap() {
|
||||
getSettersMap(): Map<string, RegisteredSetter & {
|
||||
type: string;
|
||||
}> {
|
||||
return getSettersMap();
|
||||
}
|
||||
|
||||
|
||||
@ -1,106 +1,118 @@
|
||||
import { SettingField, ISetValueOptions } from '@alilc/lowcode-designer';
|
||||
import { CompositeValue, FieldConfig, CustomView, isCustomView } from '@alilc/lowcode-types';
|
||||
import { SettingField, SettingEntry } from '@alilc/lowcode-designer';
|
||||
import {
|
||||
CompositeValue,
|
||||
FieldConfig,
|
||||
CustomView,
|
||||
IPublicModelSettingPropEntry,
|
||||
SetterType,
|
||||
FieldExtraProps,
|
||||
IPublicModelSettingTopEntry,
|
||||
IPublicModelNode,
|
||||
IPublicModelComponentMeta,
|
||||
ISetValueOptions,
|
||||
} from '@alilc/lowcode-types';
|
||||
import { settingPropEntrySymbol } from './symbols';
|
||||
import Node from './node';
|
||||
import SettingTopEntry from './setting-top-entry';
|
||||
import ComponentMeta from './component-meta';
|
||||
import { isCustomView } from '@alilc/lowcode-utils';
|
||||
|
||||
export default class SettingPropEntry {
|
||||
export default class SettingPropEntry implements IPublicModelSettingPropEntry {
|
||||
private readonly [settingPropEntrySymbol]: SettingField;
|
||||
|
||||
constructor(prop: SettingField) {
|
||||
this[settingPropEntrySymbol] = prop;
|
||||
}
|
||||
|
||||
static create(prop: SettingField) {
|
||||
static create(prop: SettingField): IPublicModelSettingPropEntry {
|
||||
return new SettingPropEntry(prop);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设置属性的 isGroup
|
||||
*/
|
||||
get isGroup() {
|
||||
get isGroup(): boolean {
|
||||
return this[settingPropEntrySymbol].isGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设置属性的 id
|
||||
*/
|
||||
get id() {
|
||||
get id(): string {
|
||||
return this[settingPropEntrySymbol].id;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设置属性的 name
|
||||
*/
|
||||
get name() {
|
||||
get name(): string | number {
|
||||
return this[settingPropEntrySymbol].name;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设置属性的 key
|
||||
*/
|
||||
get key() {
|
||||
get key(): string | number {
|
||||
return this[settingPropEntrySymbol].getKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设置属性的 path
|
||||
*/
|
||||
get path() {
|
||||
get path(): any[] {
|
||||
return this[settingPropEntrySymbol].path;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设置属性的 title
|
||||
*/
|
||||
get title() {
|
||||
get title(): any {
|
||||
return this[settingPropEntrySymbol].title;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设置属性的 setter
|
||||
*/
|
||||
get setter() {
|
||||
get setter(): SetterType | null {
|
||||
return this[settingPropEntrySymbol].setter;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设置属性的 expanded
|
||||
*/
|
||||
get expanded() {
|
||||
get expanded(): boolean {
|
||||
return this[settingPropEntrySymbol].expanded;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设置属性的 extraProps
|
||||
*/
|
||||
get extraProps() {
|
||||
get extraProps(): FieldExtraProps {
|
||||
return this[settingPropEntrySymbol].extraProps;
|
||||
}
|
||||
|
||||
get props() {
|
||||
get props(): IPublicModelSettingTopEntry {
|
||||
return SettingTopEntry.create(this[settingPropEntrySymbol].props);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设置属性对应的节点实例
|
||||
*/
|
||||
get node(): Node | null {
|
||||
get node(): IPublicModelNode | null {
|
||||
return Node.create(this[settingPropEntrySymbol].getNode());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设置属性的父设置属性
|
||||
*/
|
||||
get parent(): SettingPropEntry {
|
||||
get parent(): IPublicModelSettingPropEntry {
|
||||
return SettingPropEntry.create(this[settingPropEntrySymbol].parent as any);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取顶级设置属性
|
||||
*/
|
||||
get top(): SettingTopEntry {
|
||||
get top(): IPublicModelSettingTopEntry {
|
||||
return SettingTopEntry.create(this[settingPropEntrySymbol].top);
|
||||
}
|
||||
|
||||
@ -114,14 +126,14 @@ export default class SettingPropEntry {
|
||||
/**
|
||||
* componentMeta
|
||||
*/
|
||||
get componentMeta(): ComponentMeta | null {
|
||||
get componentMeta(): IPublicModelComponentMeta | null {
|
||||
return ComponentMeta.create(this[settingPropEntrySymbol].componentMeta);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设置属性的 items
|
||||
*/
|
||||
get items(): Array<SettingPropEntry | CustomView> {
|
||||
get items(): Array<IPublicModelSettingPropEntry | CustomView> {
|
||||
return this[settingPropEntrySymbol].items?.map((item) => {
|
||||
if (isCustomView(item)) {
|
||||
return item;
|
||||
@ -134,7 +146,7 @@ export default class SettingPropEntry {
|
||||
* 设置 key 值
|
||||
* @param key
|
||||
*/
|
||||
setKey(key: string | number) {
|
||||
setKey(key: string | number): void {
|
||||
this[settingPropEntrySymbol].setKey(key);
|
||||
}
|
||||
|
||||
@ -156,7 +168,7 @@ export default class SettingPropEntry {
|
||||
* 设置值
|
||||
* @param val 值
|
||||
*/
|
||||
setValue(val: CompositeValue, extraOptions?: ISetValueOptions) {
|
||||
setValue(val: CompositeValue, extraOptions?: ISetValueOptions): void {
|
||||
this[settingPropEntrySymbol].setValue(val, false, false, extraOptions);
|
||||
}
|
||||
|
||||
@ -165,7 +177,7 @@ export default class SettingPropEntry {
|
||||
* @param propName 子属性名
|
||||
* @param value 值
|
||||
*/
|
||||
setPropValue(propName: string | number, value: any) {
|
||||
setPropValue(propName: string | number, value: any): void {
|
||||
this[settingPropEntrySymbol].setPropValue(propName, value);
|
||||
}
|
||||
|
||||
@ -173,7 +185,7 @@ export default class SettingPropEntry {
|
||||
* 清空指定属性值
|
||||
* @param propName
|
||||
*/
|
||||
clearPropValue(propName: string | number) {
|
||||
clearPropValue(propName: string | number): void {
|
||||
this[settingPropEntrySymbol].clearPropValue(propName);
|
||||
}
|
||||
|
||||
@ -181,7 +193,7 @@ export default class SettingPropEntry {
|
||||
* 获取配置的默认值
|
||||
* @returns
|
||||
*/
|
||||
getDefaultValue() {
|
||||
getDefaultValue(): any {
|
||||
return this[settingPropEntrySymbol].getDefaultValue();
|
||||
}
|
||||
|
||||
@ -189,7 +201,7 @@ export default class SettingPropEntry {
|
||||
* 获取值
|
||||
* @returns
|
||||
*/
|
||||
getValue() {
|
||||
getValue(): any {
|
||||
return this[settingPropEntrySymbol].getValue();
|
||||
}
|
||||
|
||||
@ -198,21 +210,21 @@ export default class SettingPropEntry {
|
||||
* @param propName 子属性名
|
||||
* @returns
|
||||
*/
|
||||
getPropValue(propName: string | number) {
|
||||
getPropValue(propName: string | number): any {
|
||||
return this[settingPropEntrySymbol].getPropValue(propName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取顶层附属属性值
|
||||
*/
|
||||
getExtraPropValue(propName: string) {
|
||||
getExtraPropValue(propName: string): any {
|
||||
return this[settingPropEntrySymbol].getExtraPropValue(propName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置顶层附属属性值
|
||||
*/
|
||||
setExtraPropValue(propName: string, value: any) {
|
||||
setExtraPropValue(propName: string, value: any): void {
|
||||
this[settingPropEntrySymbol].setExtraPropValue(propName, value);
|
||||
}
|
||||
|
||||
@ -220,7 +232,7 @@ export default class SettingPropEntry {
|
||||
* 获取设置属性集
|
||||
* @returns
|
||||
*/
|
||||
getProps() {
|
||||
getProps(): IPublicModelSettingTopEntry {
|
||||
return SettingTopEntry.create(this[settingPropEntrySymbol].getProps() as SettingEntry) as any;
|
||||
}
|
||||
|
||||
@ -228,7 +240,7 @@ export default class SettingPropEntry {
|
||||
* 是否绑定了变量
|
||||
* @returns
|
||||
*/
|
||||
isUseVariable() {
|
||||
isUseVariable(): boolean {
|
||||
return this[settingPropEntrySymbol].isUseVariable();
|
||||
}
|
||||
|
||||
@ -236,7 +248,7 @@ export default class SettingPropEntry {
|
||||
* 设置绑定变量
|
||||
* @param flag
|
||||
*/
|
||||
setUseVariable(flag: boolean) {
|
||||
setUseVariable(flag: boolean): void {
|
||||
this[settingPropEntrySymbol].setUseVariable(flag);
|
||||
}
|
||||
|
||||
@ -245,7 +257,7 @@ export default class SettingPropEntry {
|
||||
* @param config
|
||||
* @returns
|
||||
*/
|
||||
createField(config: FieldConfig) {
|
||||
createField(config: FieldConfig): IPublicModelSettingPropEntry {
|
||||
return SettingPropEntry.create(this[settingPropEntrySymbol].createField(config));
|
||||
}
|
||||
|
||||
@ -253,21 +265,21 @@ export default class SettingPropEntry {
|
||||
* 获取值,当为变量时,返回 mock
|
||||
* @returns
|
||||
*/
|
||||
getMockOrValue() {
|
||||
getMockOrValue(): any {
|
||||
return this[settingPropEntrySymbol].getMockOrValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* 销毁当前 field 实例
|
||||
*/
|
||||
purge() {
|
||||
purge(): void {
|
||||
this[settingPropEntrySymbol].purge();
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除当前 field 实例
|
||||
*/
|
||||
remove() {
|
||||
remove(): void {
|
||||
this[settingPropEntrySymbol].remove();
|
||||
}
|
||||
|
||||
@ -276,7 +288,7 @@ export default class SettingPropEntry {
|
||||
* @param action
|
||||
* @returns
|
||||
*/
|
||||
onEffect(action: () => void) {
|
||||
onEffect(action: () => void): () => void {
|
||||
return this[settingPropEntrySymbol].onEffect(action);
|
||||
}
|
||||
|
||||
|
||||
@ -2,22 +2,23 @@ import { SettingEntry } from '@alilc/lowcode-designer';
|
||||
import { settingTopEntrySymbol } from './symbols';
|
||||
import Node from './node';
|
||||
import SettingPropEntry from './setting-prop-entry';
|
||||
import { IPublicModelSettingTopEntry, IPublicModelNode, IPublicModelSettingPropEntry } from '@alilc/lowcode-types';
|
||||
|
||||
export default class SettingTopEntry {
|
||||
export default class SettingTopEntry implements IPublicModelSettingTopEntry {
|
||||
private readonly [settingTopEntrySymbol]: SettingEntry;
|
||||
|
||||
constructor(prop: SettingEntry) {
|
||||
this[settingTopEntrySymbol] = prop;
|
||||
}
|
||||
|
||||
static create(prop: SettingEntry) {
|
||||
static create(prop: SettingEntry): IPublicModelSettingTopEntry {
|
||||
return new SettingTopEntry(prop);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回所属的节点实例
|
||||
*/
|
||||
get node(): Node | null {
|
||||
get node(): IPublicModelNode | null {
|
||||
return Node.create(this[settingTopEntrySymbol].getNode());
|
||||
}
|
||||
|
||||
@ -26,7 +27,7 @@ export default class SettingTopEntry {
|
||||
* @param propName
|
||||
* @returns
|
||||
*/
|
||||
get(propName: string | number) {
|
||||
get(propName: string | number): IPublicModelSettingPropEntry {
|
||||
return SettingPropEntry.create(this[settingTopEntrySymbol].get(propName) as any);
|
||||
}
|
||||
|
||||
@ -42,7 +43,7 @@ export default class SettingTopEntry {
|
||||
* @param propName
|
||||
* @returns
|
||||
*/
|
||||
getPropValue(propName: string | number) {
|
||||
getPropValue(propName: string | number): any {
|
||||
return this[settingTopEntrySymbol].getPropValue(propName);
|
||||
}
|
||||
|
||||
@ -51,7 +52,7 @@ export default class SettingTopEntry {
|
||||
* @param propName
|
||||
* @param value
|
||||
*/
|
||||
setPropValue(propName: string | number, value: any) {
|
||||
setPropValue(propName: string | number, value: any): void {
|
||||
this[settingTopEntrySymbol].setPropValue(propName, value);
|
||||
}
|
||||
}
|
||||
@ -2,16 +2,17 @@ import {
|
||||
BuiltinSimulatorHost,
|
||||
} from '@alilc/lowcode-designer';
|
||||
import { simulatorHostSymbol, nodeSymbol } from './symbols';
|
||||
import { IPublicApiSimulatorHost, IPublicModelNode } from '@alilc/lowcode-types';
|
||||
import type Node from './node';
|
||||
|
||||
export default class SimulatorHost {
|
||||
export default class SimulatorHost implements IPublicApiSimulatorHost {
|
||||
private readonly [simulatorHostSymbol]: BuiltinSimulatorHost;
|
||||
|
||||
constructor(simulator: BuiltinSimulatorHost) {
|
||||
this[simulatorHostSymbol] = simulator;
|
||||
}
|
||||
|
||||
static create(host: BuiltinSimulatorHost) {
|
||||
static create(host: BuiltinSimulatorHost): IPublicApiSimulatorHost | null {
|
||||
if (!host) return null;
|
||||
return new SimulatorHost(host);
|
||||
}
|
||||
@ -19,18 +20,18 @@ export default class SimulatorHost {
|
||||
/**
|
||||
* 获取 contentWindow
|
||||
*/
|
||||
get contentWindow() {
|
||||
get contentWindow(): Window | undefined {
|
||||
return this[simulatorHostSymbol].contentWindow;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 contentDocument
|
||||
*/
|
||||
get contentDocument() {
|
||||
get contentDocument(): Document | undefined {
|
||||
return this[simulatorHostSymbol].contentDocument;
|
||||
}
|
||||
|
||||
get renderer() {
|
||||
get renderer(): any {
|
||||
return this[simulatorHostSymbol].renderer;
|
||||
}
|
||||
|
||||
@ -39,7 +40,7 @@ export default class SimulatorHost {
|
||||
* @param key
|
||||
* @param value
|
||||
*/
|
||||
set(key: string, value: any) {
|
||||
set(key: string, value: any): void {
|
||||
this[simulatorHostSymbol].set(key, value);
|
||||
}
|
||||
|
||||
@ -48,7 +49,7 @@ export default class SimulatorHost {
|
||||
* @param key
|
||||
* @returns
|
||||
*/
|
||||
get(key: string) {
|
||||
get(key: string): any {
|
||||
return this[simulatorHostSymbol].get(key);
|
||||
}
|
||||
|
||||
@ -56,14 +57,14 @@ export default class SimulatorHost {
|
||||
* scroll to specific node
|
||||
* @param node
|
||||
*/
|
||||
scrollToNode(node: Node) {
|
||||
this[simulatorHostSymbol].scrollToNode(node[nodeSymbol]);
|
||||
scrollToNode(node: IPublicModelNode): void {
|
||||
this[simulatorHostSymbol].scrollToNode((node as any)[nodeSymbol]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新渲染画布
|
||||
*/
|
||||
rerender() {
|
||||
rerender(): void {
|
||||
this[simulatorHostSymbol].rerender();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,12 +1,11 @@
|
||||
import {
|
||||
Skeleton as InnerSkeleton,
|
||||
IWidgetBaseConfig,
|
||||
IWidgetConfigArea,
|
||||
SkeletonEvents,
|
||||
} from '@alilc/lowcode-editor-skeleton';
|
||||
import { skeletonSymbol } from './symbols';
|
||||
import { IPublicApiSkeleton, IWidgetBaseConfig, IWidgetConfigArea } from '@alilc/lowcode-types';
|
||||
|
||||
export default class Skeleton {
|
||||
export default class Skeleton implements IPublicApiSkeleton {
|
||||
private readonly [skeletonSymbol]: InnerSkeleton;
|
||||
|
||||
constructor(skeleton: InnerSkeleton) {
|
||||
@ -28,11 +27,13 @@ export default class Skeleton {
|
||||
* @param config
|
||||
* @returns
|
||||
*/
|
||||
remove(config: IWidgetBaseConfig) {
|
||||
remove(config: IWidgetBaseConfig): number | undefined {
|
||||
const { area, name } = config;
|
||||
const skeleton = this[skeletonSymbol];
|
||||
if (!normalizeArea(area)) return;
|
||||
skeleton[normalizeArea(area)!].container.remove(name);
|
||||
if (!normalizeArea(area)) {
|
||||
return;
|
||||
}
|
||||
skeleton[normalizeArea(area)!].container?.remove(name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
18
packages/types/src/deprecated/index.ts
Normal file
18
packages/types/src/deprecated/index.ts
Normal file
@ -0,0 +1,18 @@
|
||||
export * from './isActionContentObject';
|
||||
export * from './isCustomView';
|
||||
export * from './isDOMText';
|
||||
export * from './isDynamicSetter';
|
||||
export * from './isI18nData';
|
||||
export * from './isJSBlock';
|
||||
export * from './isJSExpression';
|
||||
export * from './isJSFunction';
|
||||
export * from './isJSSlot';
|
||||
export * from './isLowCodeComponentType';
|
||||
export * from './isNodeSchema';
|
||||
export * from './isPlainObject';
|
||||
export * from './isProCodeComponentType';
|
||||
export * from './isProjectSchema';
|
||||
export * from './isReactClass';
|
||||
export * from './isReactComponent';
|
||||
export * from './isSetterConfig';
|
||||
export * from './isTitleConfig';
|
||||
8
packages/types/src/deprecated/isActionContentObject.ts
Normal file
8
packages/types/src/deprecated/isActionContentObject.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { ActionContentObject } from '../metadata';
|
||||
|
||||
/**
|
||||
* @deprecated use same function from '@alilc/lowcode-utils' instead
|
||||
*/
|
||||
export function isActionContentObject(obj: any): obj is ActionContentObject {
|
||||
return obj && typeof obj === 'object';
|
||||
}
|
||||
10
packages/types/src/deprecated/isCustomView.ts
Normal file
10
packages/types/src/deprecated/isCustomView.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import { isValidElement } from 'react';
|
||||
import { isReactComponent } from './isReactComponent';
|
||||
import { CustomView } from '../setter-config';
|
||||
|
||||
/**
|
||||
* @deprecated use same function from '@alilc/lowcode-utils' instead
|
||||
*/
|
||||
export function isCustomView(obj: any): obj is CustomView {
|
||||
return obj && (isValidElement(obj) || isReactComponent(obj));
|
||||
}
|
||||
8
packages/types/src/deprecated/isDOMText.ts
Normal file
8
packages/types/src/deprecated/isDOMText.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { DOMText } from '../schema';
|
||||
|
||||
/**
|
||||
* @deprecated use same function from '@alilc/lowcode-utils' instead
|
||||
*/
|
||||
export function isDOMText(data: any): data is DOMText {
|
||||
return typeof data === 'string';
|
||||
}
|
||||
9
packages/types/src/deprecated/isDynamicSetter.ts
Normal file
9
packages/types/src/deprecated/isDynamicSetter.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { isReactClass } from './isReactClass';
|
||||
import { DynamicSetter } from '../setter-config';
|
||||
|
||||
/**
|
||||
* @deprecated use same function from '@alilc/lowcode-utils' instead
|
||||
*/
|
||||
export function isDynamicSetter(obj: any): obj is DynamicSetter {
|
||||
return obj && typeof obj === 'function' && !isReactClass(obj);
|
||||
}
|
||||
8
packages/types/src/deprecated/isI18nData.ts
Normal file
8
packages/types/src/deprecated/isI18nData.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { I18nData } from '../i18n';
|
||||
|
||||
/**
|
||||
* @deprecated use same function from '@alilc/lowcode-utils' instead
|
||||
*/
|
||||
export function isI18nData(obj: any): obj is I18nData {
|
||||
return obj && obj.type === 'i18n';
|
||||
}
|
||||
8
packages/types/src/deprecated/isJSBlock.ts
Normal file
8
packages/types/src/deprecated/isJSBlock.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { JSBlock } from '../value-type';
|
||||
|
||||
/**
|
||||
* @deprecated use same function from '@alilc/lowcode-utils' instead
|
||||
*/
|
||||
export function isJSBlock(data: any): data is JSBlock {
|
||||
return data && data.type === 'JSBlock';
|
||||
}
|
||||
8
packages/types/src/deprecated/isJSExpression.ts
Normal file
8
packages/types/src/deprecated/isJSExpression.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { JSExpression } from '../value-type';
|
||||
|
||||
/**
|
||||
* @deprecated use same function from '@alilc/lowcode-utils' instead
|
||||
*/
|
||||
export function isJSExpression(data: any): data is JSExpression {
|
||||
return data && data.type === 'JSExpression' && data.extType !== 'function';
|
||||
}
|
||||
8
packages/types/src/deprecated/isJSFunction.ts
Normal file
8
packages/types/src/deprecated/isJSFunction.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { JSFunction } from '../value-type';
|
||||
|
||||
/**
|
||||
* @deprecated use same function from '@alilc/lowcode-utils' instead
|
||||
*/
|
||||
export function isJSFunction(x: any): x is JSFunction {
|
||||
return typeof x === 'object' && x && x.type === 'JSFunction';
|
||||
}
|
||||
8
packages/types/src/deprecated/isJSSlot.ts
Normal file
8
packages/types/src/deprecated/isJSSlot.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { JSSlot } from '../value-type';
|
||||
|
||||
/**
|
||||
* @deprecated use same function from '@alilc/lowcode-utils' instead
|
||||
*/
|
||||
export function isJSSlot(data: any): data is JSSlot {
|
||||
return data && data.type === 'JSSlot';
|
||||
}
|
||||
9
packages/types/src/deprecated/isLowCodeComponentType.ts
Normal file
9
packages/types/src/deprecated/isLowCodeComponentType.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { isProCodeComponentType } from './isProCodeComponentType';
|
||||
import { ComponentMap, LowCodeComponentType } from '../npm';
|
||||
|
||||
/**
|
||||
* @deprecated use same function from '@alilc/lowcode-utils' instead
|
||||
*/
|
||||
export function isLowCodeComponentType(desc: ComponentMap): desc is LowCodeComponentType {
|
||||
return !isProCodeComponentType(desc);
|
||||
}
|
||||
8
packages/types/src/deprecated/isNodeSchema.ts
Normal file
8
packages/types/src/deprecated/isNodeSchema.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { NodeSchema } from '../schema';
|
||||
|
||||
/**
|
||||
* @deprecated use same function from '@alilc/lowcode-utils' instead
|
||||
*/
|
||||
export function isNodeSchema(data: any): data is NodeSchema {
|
||||
return data && data.componentName;
|
||||
}
|
||||
10
packages/types/src/deprecated/isPlainObject.ts
Normal file
10
packages/types/src/deprecated/isPlainObject.ts
Normal file
@ -0,0 +1,10 @@
|
||||
/**
|
||||
* @deprecated use same function from '@alilc/lowcode-utils' instead
|
||||
*/
|
||||
export function isPlainObject(value: any): value is Record<string, unknown> {
|
||||
if (typeof value !== 'object') {
|
||||
return false;
|
||||
}
|
||||
const proto = Object.getPrototypeOf(value);
|
||||
return proto === Object.prototype || proto === null || Object.getPrototypeOf(proto) === null;
|
||||
}
|
||||
8
packages/types/src/deprecated/isProCodeComponentType.ts
Normal file
8
packages/types/src/deprecated/isProCodeComponentType.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { ComponentMap, ProCodeComponentType } from '../npm';
|
||||
|
||||
/**
|
||||
* @deprecated use same function from '@alilc/lowcode-utils' instead
|
||||
*/
|
||||
export function isProCodeComponentType(desc: ComponentMap): desc is ProCodeComponentType {
|
||||
return 'package' in desc;
|
||||
}
|
||||
8
packages/types/src/deprecated/isProjectSchema.ts
Normal file
8
packages/types/src/deprecated/isProjectSchema.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { ProjectSchema } from '../schema';
|
||||
|
||||
/**
|
||||
* @deprecated use same function from '@alilc/lowcode-utils' instead
|
||||
*/
|
||||
export function isProjectSchema(data: any): data is ProjectSchema {
|
||||
return data && data.componentsTree;
|
||||
}
|
||||
8
packages/types/src/deprecated/isReactClass.ts
Normal file
8
packages/types/src/deprecated/isReactClass.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { ComponentClass, Component } from 'react';
|
||||
|
||||
/**
|
||||
* @deprecated use same function from '@alilc/lowcode-utils' instead
|
||||
*/
|
||||
export function isReactClass(obj: any): obj is ComponentClass<any> {
|
||||
return obj && obj.prototype && (obj.prototype.isReactComponent || obj.prototype instanceof Component);
|
||||
}
|
||||
9
packages/types/src/deprecated/isReactComponent.ts
Normal file
9
packages/types/src/deprecated/isReactComponent.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { ComponentType } from 'react';
|
||||
import { isReactClass } from './isReactClass';
|
||||
|
||||
/**
|
||||
* @deprecated use same function from '@alilc/lowcode-utils' instead
|
||||
*/
|
||||
export function isReactComponent(obj: any): obj is ComponentType<any> {
|
||||
return obj && (isReactClass(obj) || typeof obj === 'function');
|
||||
}
|
||||
9
packages/types/src/deprecated/isSetterConfig.ts
Normal file
9
packages/types/src/deprecated/isSetterConfig.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { SetterConfig } from '../setter-config';
|
||||
import { isCustomView } from './isCustomView';
|
||||
|
||||
/**
|
||||
* @deprecated use same function from '@alilc/lowcode-utils' instead
|
||||
*/
|
||||
export function isSetterConfig(obj: any): obj is SetterConfig {
|
||||
return obj && typeof obj === 'object' && 'componentName' in obj && !isCustomView(obj);
|
||||
}
|
||||
10
packages/types/src/deprecated/isTitleConfig.ts
Normal file
10
packages/types/src/deprecated/isTitleConfig.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import { isI18nData } from './isI18nData';
|
||||
import { isPlainObject } from './isPlainObject';
|
||||
import { TitleConfig } from '../title';
|
||||
|
||||
/**
|
||||
* @deprecated use same function from '@alilc/lowcode-utils' instead
|
||||
*/
|
||||
export function isTitleConfig(obj: any): obj is TitleConfig {
|
||||
return isPlainObject(obj) && !isI18nData(obj);
|
||||
}
|
||||
23
packages/types/src/designer.ts
Normal file
23
packages/types/src/designer.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import { IPublicModelNode } from './shell';
|
||||
|
||||
export enum PROP_VALUE_CHANGED_TYPE {
|
||||
/**
|
||||
* normal set value
|
||||
*/
|
||||
SET_VALUE = 'SET_VALUE',
|
||||
/**
|
||||
* value changed caused by sub-prop value change
|
||||
*/
|
||||
SUB_VALUE_CHANGE = 'SUB_VALUE_CHANGE',
|
||||
}
|
||||
|
||||
export interface ISetValueOptions {
|
||||
disableMutator?: boolean;
|
||||
type?: PROP_VALUE_CHANGED_TYPE;
|
||||
fromSetHotValue?: boolean;
|
||||
}
|
||||
|
||||
export interface IPublicOnChangeOptions {
|
||||
type: string;
|
||||
node: IPublicModelNode;
|
||||
}
|
||||
29
packages/types/src/dragon.ts
Normal file
29
packages/types/src/dragon.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import { NodeSchema } from './schema';
|
||||
import { IPublicModelNode } from './shell';
|
||||
|
||||
export interface DragAnyObject {
|
||||
type: string;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
export interface DragNodeDataObject {
|
||||
type: DragObjectType.NodeData;
|
||||
data: NodeSchema | NodeSchema[];
|
||||
thumbnail?: string;
|
||||
description?: string;
|
||||
[extra: string]: any;
|
||||
}
|
||||
|
||||
export type DragObject = DragNodeObject | DragNodeDataObject | DragAnyObject;
|
||||
|
||||
// eslint-disable-next-line no-shadow
|
||||
export enum DragObjectType {
|
||||
// eslint-disable-next-line no-shadow
|
||||
Node = 'node',
|
||||
NodeData = 'nodedata',
|
||||
}
|
||||
|
||||
export interface DragNodeObject {
|
||||
type: DragObjectType.Node;
|
||||
nodes: (Node | IPublicModelNode)[];
|
||||
}
|
||||
27
packages/types/src/editor-skeleton.ts
Normal file
27
packages/types/src/editor-skeleton.ts
Normal file
@ -0,0 +1,27 @@
|
||||
/**
|
||||
* 所有可能的停靠位置
|
||||
*/
|
||||
export type IWidgetConfigArea =
|
||||
| 'leftArea' | 'left' | 'rightArea'
|
||||
| 'right' | 'topArea' | 'top'
|
||||
| 'toolbar' | 'mainArea' | 'main'
|
||||
| 'center' | 'centerArea' | 'bottomArea'
|
||||
| 'bottom' | 'leftFixedArea'
|
||||
| 'leftFloatArea' | 'stages';
|
||||
|
||||
export interface IWidgetBaseConfig {
|
||||
type: string;
|
||||
name: string;
|
||||
/**
|
||||
* 停靠位置:
|
||||
* - 当 type 为 'Panel' 时自动为 'leftFloatArea';
|
||||
* - 当 type 为 'Widget' 时自动为 'mainArea';
|
||||
* - 其他时候自动为 'leftArea';
|
||||
*/
|
||||
area?: IWidgetConfigArea;
|
||||
props?: Record<string, any>;
|
||||
content?: any;
|
||||
contentProps?: Record<string, any>;
|
||||
// index?: number;
|
||||
[extra: string]: any;
|
||||
}
|
||||
@ -3,6 +3,8 @@ import StrictEventEmitter from 'strict-event-emitter-types';
|
||||
import { ReactNode, ComponentType } from 'react';
|
||||
import { NpmInfo } from './npm';
|
||||
import * as GlobalEvent from './event';
|
||||
import { CustomView } from './setter-config';
|
||||
import { TitleContent } from './title';
|
||||
|
||||
export type KeyType = (new (...args: any[]) => any) | symbol | string;
|
||||
export type ClassType = new (...args: any[]) => any;
|
||||
@ -197,3 +199,22 @@ export interface PluginStatus {
|
||||
export interface PluginStatusSet {
|
||||
[key: string]: PluginStatus;
|
||||
}
|
||||
|
||||
export type HotkeyCallback = (e: KeyboardEvent, combo?: string) => any | false;
|
||||
|
||||
export interface RegisteredSetter {
|
||||
component: CustomView;
|
||||
defaultProps?: object;
|
||||
title?: TitleContent;
|
||||
/**
|
||||
* for MixedSetter to check this setter if available
|
||||
*/
|
||||
condition?: (field: any) => boolean;
|
||||
/**
|
||||
* for MixedSetter to manual change to this setter
|
||||
*/
|
||||
initialValue?: any | ((field: any) => any);
|
||||
recommend?: boolean;
|
||||
// 标识是否为动态 setter,默认为 true
|
||||
isDynamic?: boolean;
|
||||
}
|
||||
@ -6,11 +6,6 @@ export interface I18nData {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
// type checks
|
||||
export function isI18nData(obj: any): obj is I18nData {
|
||||
return obj && obj.type === 'i18n';
|
||||
}
|
||||
|
||||
export interface I18nMap {
|
||||
[lang: string]: { [key: string]: string };
|
||||
}
|
||||
|
||||
@ -22,3 +22,10 @@ export * from './assets';
|
||||
export * as GlobalEvent from './event';
|
||||
export * from './disposable';
|
||||
export * from './start-transaction';
|
||||
export * from './props-transducer';
|
||||
export * from './editor-skeleton';
|
||||
export * from './designer';
|
||||
export * from './dragon';
|
||||
export * from './shell';
|
||||
// TODO: remove this in future versions
|
||||
export * from './deprecated';
|
||||
|
||||
@ -336,10 +336,6 @@ export interface ComponentAction {
|
||||
important?: boolean;
|
||||
}
|
||||
|
||||
export function isActionContentObject(obj: any): obj is ActionContentObject {
|
||||
return obj && typeof obj === 'object';
|
||||
}
|
||||
|
||||
/**
|
||||
* 组件 meta 配置
|
||||
*/
|
||||
@ -473,3 +469,17 @@ export interface Callbacks {
|
||||
currentNode: any,
|
||||
) => void;
|
||||
}
|
||||
|
||||
export interface MetadataTransducer {
|
||||
(prev: TransformedComponentMetadata): TransformedComponentMetadata;
|
||||
/**
|
||||
* 0 - 9 system
|
||||
* 10 - 99 builtin-plugin
|
||||
* 100 - app & plugin
|
||||
*/
|
||||
level?: number;
|
||||
/**
|
||||
* use to replace TODO
|
||||
*/
|
||||
id?: string;
|
||||
}
|
||||
@ -1,3 +1,4 @@
|
||||
|
||||
/**
|
||||
* npm 源引入完整描述对象
|
||||
*/
|
||||
@ -45,13 +46,4 @@ export interface LowCodeComponentType {
|
||||
|
||||
export type ProCodeComponentType = NpmInfo;
|
||||
export type ComponentMap = ProCodeComponentType | LowCodeComponentType;
|
||||
|
||||
export function isProCodeComponentType(desc: ComponentMap): desc is ProCodeComponentType {
|
||||
return 'package' in desc;
|
||||
}
|
||||
|
||||
export function isLowCodeComponentType(desc: ComponentMap): desc is LowCodeComponentType {
|
||||
return !isProCodeComponentType(desc);
|
||||
}
|
||||
|
||||
export type ComponentsMap = ComponentMap[];
|
||||
|
||||
12
packages/types/src/props-transducer.ts
Normal file
12
packages/types/src/props-transducer.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { TransformStage } from './transform-stage';
|
||||
import { CompositeObject } from './value-type';
|
||||
|
||||
export type PropsReducerContext = {
|
||||
stage: TransformStage;
|
||||
};
|
||||
|
||||
export type PropsTransducer = (
|
||||
props: CompositeObject,
|
||||
node: Node,
|
||||
ctx?: PropsReducerContext,
|
||||
) => CompositeObject;
|
||||
@ -75,11 +75,6 @@ export type PropsList = Array<{
|
||||
|
||||
export type NodeData = NodeSchema | JSExpression | DOMText;
|
||||
export type NodeDataType = NodeData | NodeData[];
|
||||
|
||||
export function isDOMText(data: any): data is DOMText {
|
||||
return typeof data === 'string';
|
||||
}
|
||||
|
||||
export type DOMText = string;
|
||||
|
||||
/**
|
||||
@ -217,12 +212,4 @@ export interface ProjectSchema {
|
||||
* 当前应用元数据信息
|
||||
*/
|
||||
meta?: Record<string, any>;
|
||||
}
|
||||
|
||||
export function isNodeSchema(data: any): data is NodeSchema {
|
||||
return data && data.componentName;
|
||||
}
|
||||
|
||||
export function isProjectSchema(data: any): data is ProjectSchema {
|
||||
return data && data.componentsTree;
|
||||
}
|
||||
}
|
||||
@ -1,18 +1,9 @@
|
||||
import { ComponentClass, Component, ComponentType, ReactElement, isValidElement } from 'react';
|
||||
import { ComponentType, ReactElement } from 'react';
|
||||
import { TitleContent } from './title';
|
||||
import { SettingTarget } from './setting-target';
|
||||
import { CompositeValue } from './value-type';
|
||||
|
||||
function isReactClass(obj: any): obj is ComponentClass<any> {
|
||||
return obj && obj.prototype && (obj.prototype.isReactComponent || obj.prototype instanceof Component);
|
||||
}
|
||||
|
||||
function isReactComponent(obj: any): obj is ComponentType<any> {
|
||||
return obj && (isReactClass(obj) || typeof obj === 'function');
|
||||
}
|
||||
|
||||
export type CustomView = ReactElement | ComponentType<any>;
|
||||
|
||||
export type DynamicProps = (target: SettingTarget) => Record<string, unknown>;
|
||||
export type DynamicSetter = (target: SettingTarget) => string | SetterConfig | CustomView;
|
||||
|
||||
@ -63,21 +54,9 @@ export interface SetterConfig {
|
||||
* @todo 物料协议推进
|
||||
*/
|
||||
valueType?: CompositeValue[];
|
||||
// 标识是否为动态setter,默认为true
|
||||
// 标识是否为动态 setter,默认为 true
|
||||
isDynamic?: boolean;
|
||||
}
|
||||
|
||||
// if *string* passed must be a registered Setter Name, future support blockSchema
|
||||
export type SetterType = SetterConfig | SetterConfig[] | string | CustomView;
|
||||
|
||||
export function isSetterConfig(obj: any): obj is SetterConfig {
|
||||
return obj && typeof obj === 'object' && 'componentName' in obj && !isCustomView(obj);
|
||||
}
|
||||
|
||||
export function isCustomView(obj: any): obj is CustomView {
|
||||
return obj && (isValidElement(obj) || isReactComponent(obj));
|
||||
}
|
||||
|
||||
export function isDynamicSetter(obj: any): obj is DynamicSetter {
|
||||
return obj && typeof obj === 'function' && !isReactClass(obj);
|
||||
}
|
||||
export type SetterType = SetterConfig | SetterConfig[] | string | CustomView;
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user