forked from alibaba/lowcode-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimulator.ts
More file actions
189 lines (161 loc) · 4.1 KB
/
simulator.ts
File metadata and controls
189 lines (161 loc) · 4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import { Component as ReactComponent, ComponentType } from 'react';
import { ComponentMetadata, NodeSchema } from '@alilc/lowcode-types';
import { ISensor, Point, ScrollTarget, IScrollable, LocateEvent, LocationData } from './designer';
import { BuiltinSimulatorRenderer } from './builtin-simulator/renderer';
import { Node, ParentalNode } from './document';
export type AutoFit = '100%';
// eslint-disable-next-line no-redeclare
export const AutoFit = '100%';
export interface IViewport extends IScrollable {
/**
* 视口大小
*/
width: number;
height: number;
/**
* 内容大小
*/
contentWidth: number | AutoFit;
contentHeight: number | AutoFit;
/**
* 内容缩放
*/
scale: number;
/**
* 视口矩形维度
*/
readonly bounds: DOMRect;
/**
* 内容矩形维度
*/
readonly contentBounds: DOMRect;
/**
* 视口滚动对象
*/
readonly scrollTarget?: ScrollTarget;
/**
* 是否滚动中
*/
readonly scrolling: boolean;
/**
* 内容当前滚动 X
*/
readonly scrollX: number;
/**
* 内容当前滚动 Y
*/
readonly scrollY: number;
/**
* 全局坐标系转化为本地坐标系
*/
toLocalPoint(point: Point): Point;
/**
* 本地坐标系转化为全局坐标系
*/
toGlobalPoint(point: Point): Point;
}
export interface DropContainer {
container: ParentalNode;
instance: ComponentInstance;
}
/**
* 模拟器控制进程协议
*/
export interface ISimulatorHost<P = object> extends ISensor {
readonly isSimulator: true;
/**
* 获得边界维度等信息
*/
readonly viewport: IViewport;
readonly contentWindow?: Window;
readonly contentDocument?: Document;
readonly renderer?: BuiltinSimulatorRenderer;
// dependsAsset // like react jQuery lodash
// themesAsset
// componentsAsset
// simulatorUrl //
// utils, dataSource, constants 模拟
//
// later:
// layout: ComponentName
// 获取区块代码, 通过 components 传递,可异步获取
// 设置 simulator Props
setProps(props: P): void;
// 设置单个 Prop
set(key: string, value: any): void;
setSuspense(suspensed: boolean): void;
// #region ========= drag and drop helpers =============
/**
* 设置文字拖选
*/
setNativeSelection(enableFlag: boolean): void;
/**
* 设置拖拽态
*/
setDraggingState(state: boolean): void;
/**
* 设置拷贝态
*/
setCopyState(state: boolean): void;
/**
* 清除所有态:拖拽态、拷贝态
*/
clearState(): void;
// #endregion
/**
* 滚动视口到节点
*/
scrollToNode(node: Node, detail?: any): void;
/**
* 描述组件
*/
generateComponentMetadata(componentName: string): ComponentMetadata;
/**
* 根据组件信息获取组件类
*/
getComponent(componentName: string): Component | any;
/**
* 根据节点获取节点的组件实例
*/
getComponentInstances(node: Node): ComponentInstance[] | null;
/**
* 根据 schema 创建组件类
*/
createComponent(schema: NodeSchema): Component | null;
/**
* 根据节点获取节点的组件运行上下文
*/
getComponentContext(node: Node): object | null;
getClosestNodeInstance(from: ComponentInstance, specId?: string): NodeInstance | null;
computeRect(node: Node): DOMRect | null;
computeComponentInstanceRect(instance: ComponentInstance, selector?: string): DOMRect | null;
findDOMNodes(instance: ComponentInstance, selector?: string): Array<Element | Text> | null;
getDropContainer(e: LocateEvent): DropContainer | null;
postEvent(evtName: string, evtData: any): void;
rerender(): void;
/**
* 销毁
*/
purge(): void;
}
export function isSimulatorHost(obj: any): obj is ISimulatorHost {
return obj && obj.isSimulator;
}
export interface NodeInstance<T = ComponentInstance> {
docId: string;
nodeId: string;
instance: T;
node?: Node | null;
}
/**
* 组件类定义
*/
export type Component = ComponentType<any> | object;
/**
* 组件实例定义
*/
export type ComponentInstance = Element | ReactComponent<any> | object;
export interface INodeSelector {
node: Node;
instance?: ComponentInstance;
}