forked from alibaba/lowcode-engine
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsimulator-host.ts
More file actions
76 lines (65 loc) · 1.76 KB
/
simulator-host.ts
File metadata and controls
76 lines (65 loc) · 1.76 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
import { BuiltinSimulatorHost } from '@felce/lowcode-designer';
import { simulatorHostSymbol, nodeSymbol } from '../symbols';
import {
IPublicApiSimulatorHost,
IPublicModelNode,
IPublicModelSimulatorRender,
} from '@felce/lowcode-types';
import { SimulatorRender } from '../model/simulator-render';
export class SimulatorHost implements IPublicApiSimulatorHost {
private readonly [simulatorHostSymbol]: BuiltinSimulatorHost;
constructor(simulator: BuiltinSimulatorHost) {
this[simulatorHostSymbol] = simulator;
}
static create(host: BuiltinSimulatorHost): IPublicApiSimulatorHost | null {
if (!host) return null;
return new SimulatorHost(host);
}
/**
* 获取 contentWindow
*/
get contentWindow(): Window | undefined {
return this[simulatorHostSymbol].contentWindow;
}
/**
* 获取 contentDocument
*/
get contentDocument(): Document | undefined {
return this[simulatorHostSymbol].contentDocument;
}
get renderer(): IPublicModelSimulatorRender | undefined {
if (this[simulatorHostSymbol].renderer) {
return SimulatorRender.create(this[simulatorHostSymbol].renderer);
}
return undefined;
}
/**
* 设置 host 配置值
* @param key
* @param value
*/
set(key: string, value: any): void {
this[simulatorHostSymbol].set(key, value);
}
/**
* 获取 host 配置值
* @param key
* @returns
*/
get(key: string): any {
return this[simulatorHostSymbol].get(key);
}
/**
* scroll to specific node
* @param node
*/
scrollToNode(node: IPublicModelNode): void {
this[simulatorHostSymbol].scrollToNode((node as any)[nodeSymbol]);
}
/**
* 触发组件构建,并刷新渲染画布
*/
rerender(): void {
this[simulatorHostSymbol].rerender();
}
}