@netless/window-manager 1.0.0-canary.9 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +21 -0
- package/README.md +90 -64
- package/README.zh-cn.md +224 -0
- package/dist/index.d.ts +1133 -40
- package/dist/index.js +62 -0
- package/dist/index.js.map +1 -0
- package/dist/{index.es.js → index.mjs} +7954 -5445
- package/dist/index.mjs.map +1 -0
- package/dist/style.css +1 -1
- package/docs/advanced.md +55 -55
- package/docs/api.md +126 -113
- package/docs/app-context.md +248 -209
- package/docs/basic.md +25 -26
- package/docs/camera.md +21 -21
- package/docs/cn/advanced.md +137 -0
- package/docs/cn/api.md +311 -0
- package/docs/cn/app-context.md +369 -0
- package/docs/cn/basic.md +64 -0
- package/docs/cn/camera.md +53 -0
- package/docs/cn/concept.md +9 -0
- package/docs/cn/custom-max-bar.md +31 -0
- package/docs/cn/develop-app.md +94 -0
- package/docs/cn/export-pdf.md +48 -0
- package/docs/cn/migrate.md +60 -0
- package/docs/cn/replay.md +40 -0
- package/docs/concept.md +6 -5
- package/docs/custom-max-bar.md +31 -0
- package/docs/develop-app.md +22 -19
- package/docs/export-pdf.md +48 -0
- package/docs/migrate.md +25 -27
- package/docs/quickstart.md +50 -0
- package/docs/replay.md +20 -20
- package/package.json +32 -22
- package/src/App/AppContext.ts +105 -73
- package/src/App/AppPageStateImpl.ts +6 -25
- package/src/App/AppProxy.ts +41 -166
- package/src/App/MagixEvent/index.ts +38 -38
- package/src/App/Storage/StorageEvent.ts +13 -13
- package/src/App/Storage/index.ts +269 -245
- package/src/App/Storage/typings.ts +4 -2
- package/src/App/Storage/utils.ts +3 -3
- package/src/App/index.ts +0 -1
- package/src/AppListener.ts +8 -8
- package/src/AppManager.ts +88 -77
- package/src/AttributesDelegate.ts +42 -22
- package/src/BoxEmitter.ts +12 -6
- package/src/BoxManager.ts +128 -108
- package/src/ContainerResizeObserver.ts +75 -0
- package/src/Cursor/Cursor.svelte +16 -5
- package/src/Cursor/Cursor.svelte.d.ts +21 -0
- package/src/Cursor/Cursor.ts +77 -13
- package/src/Cursor/icons.ts +6 -0
- package/src/Cursor/icons2.ts +66 -0
- package/src/Cursor/index.ts +127 -26
- package/src/Helper.ts +94 -14
- package/src/InternalEmitter.ts +2 -7
- package/src/Page/index.ts +1 -1
- package/src/PageState.ts +6 -5
- package/src/ReconnectRefresher.ts +9 -4
- package/src/RedoUndo.ts +3 -3
- package/src/Register/index.ts +22 -17
- package/src/Register/loader.ts +26 -22
- package/src/Register/storage.ts +13 -13
- package/src/Utils/Common.ts +18 -14
- package/src/Utils/Reactive.ts +26 -25
- package/src/Utils/RoomHacker.ts +4 -4
- package/src/Utils/error.ts +0 -1
- package/src/View/IframeBridge.ts +680 -0
- package/src/View/MainView.ts +127 -53
- package/src/callback.ts +21 -1
- package/src/constants.ts +0 -2
- package/src/image/pencil-eraser-1.svg +3 -0
- package/src/image/pencil-eraser-2.svg +3 -0
- package/src/image/pencil-eraser-3.svg +3 -0
- package/src/index.ts +220 -83
- package/src/style.css +27 -10
- package/src/typings.ts +20 -10
- package/.prettierignore +0 -7
- package/.prettierrc.json +0 -9
- package/CHANGELOG.md +0 -196
- package/__mocks__/white-web-sdk.ts +0 -50
- package/dist/App/AppContext.d.ts +0 -76
- package/dist/App/AppPageStateImpl.d.ts +0 -21
- package/dist/App/AppProxy.d.ts +0 -86
- package/dist/App/AppViewSync.d.ts +0 -11
- package/dist/App/MagixEvent/index.d.ts +0 -29
- package/dist/App/Storage/StorageEvent.d.ts +0 -8
- package/dist/App/Storage/index.d.ts +0 -39
- package/dist/App/Storage/typings.d.ts +0 -22
- package/dist/App/Storage/utils.d.ts +0 -5
- package/dist/App/WhiteboardView.d.ts +0 -22
- package/dist/App/index.d.ts +0 -3
- package/dist/AppListener.d.ts +0 -21
- package/dist/AppManager.d.ts +0 -107
- package/dist/AttributesDelegate.d.ts +0 -80
- package/dist/BoxEmitter.d.ts +0 -34
- package/dist/BoxManager.d.ts +0 -99
- package/dist/BuiltinApps.d.ts +0 -5
- package/dist/Cursor/Cursor.d.ts +0 -39
- package/dist/Cursor/icons.d.ts +0 -3
- package/dist/Cursor/index.d.ts +0 -46
- package/dist/Helper.d.ts +0 -17
- package/dist/InternalEmitter.d.ts +0 -39
- package/dist/Page/PageController.d.ts +0 -21
- package/dist/Page/index.d.ts +0 -3
- package/dist/PageState.d.ts +0 -9
- package/dist/ReconnectRefresher.d.ts +0 -24
- package/dist/RedoUndo.d.ts +0 -18
- package/dist/Register/index.d.ts +0 -28
- package/dist/Register/loader.d.ts +0 -4
- package/dist/Register/storage.d.ts +0 -8
- package/dist/Utils/AppCreateQueue.d.ts +0 -15
- package/dist/Utils/Common.d.ts +0 -23
- package/dist/Utils/Reactive.d.ts +0 -6
- package/dist/Utils/RoomHacker.d.ts +0 -3
- package/dist/Utils/error.d.ts +0 -27
- package/dist/Utils/log.d.ts +0 -1
- package/dist/View/CameraSynchronizer.d.ts +0 -16
- package/dist/View/MainView.d.ts +0 -47
- package/dist/View/ViewManager.d.ts +0 -13
- package/dist/callback.d.ts +0 -24
- package/dist/constants.d.ts +0 -49
- package/dist/index.cjs.js +0 -46
- package/dist/index.umd.js +0 -46
- package/dist/typings.d.ts +0 -82
- package/jest.config.js +0 -27
- package/pnpm-lock.yaml +0 -6302
- package/src/App/AppViewSync.ts +0 -68
- package/src/App/WhiteboardView.ts +0 -83
- package/src/View/CameraSynchronizer.ts +0 -56
- package/vite.config.js +0 -51
- /package/docs/{qickstart.md → cn/quickstart.md} +0 -0
package/src/App/AppProxy.ts
CHANGED
@@ -3,22 +3,15 @@ import { AppAttributes, AppEvents, Events, SETUP_APP_DELAY } from "../constants"
|
|
3
3
|
import { AppContext } from "./AppContext";
|
4
4
|
import { AppPageStateImpl } from "./AppPageStateImpl";
|
5
5
|
import { appRegister } from "../Register";
|
6
|
-
import {
|
7
|
-
import { autorun, reaction, toJS } from "white-web-sdk";
|
8
|
-
import { boxEmitter } from "../BoxEmitter";
|
6
|
+
import { autorun } from "white-web-sdk";
|
9
7
|
import { BoxManagerNotFoundError } from "../Utils/error";
|
10
|
-
import { calculateNextIndex } from "../Page";
|
11
|
-
import { combine, Val, ValManager } from "value-enhancer";
|
12
8
|
import { debounce, get } from "lodash";
|
13
|
-
import {
|
9
|
+
import { internalEmitter } from "../InternalEmitter";
|
14
10
|
import { Fields } from "../AttributesDelegate";
|
15
11
|
import { log } from "../Utils/log";
|
16
|
-
import { SideEffectManager } from "side-effect-manager";
|
17
|
-
import type { ICamera, ISize } from "../AttributesDelegate";
|
18
12
|
import {
|
19
13
|
entireScenes,
|
20
14
|
getScenePath,
|
21
|
-
putScenes,
|
22
15
|
removeScenes,
|
23
16
|
setScenePath,
|
24
17
|
setViewFocusScenePath,
|
@@ -30,11 +23,14 @@ import type {
|
|
30
23
|
setAppOptions,
|
31
24
|
AppListenerKeys,
|
32
25
|
} from "../index";
|
33
|
-
import type { SceneState, View, SceneDefinition
|
26
|
+
import type { SceneState, View, SceneDefinition } from "white-web-sdk";
|
34
27
|
import type { AppManager } from "../AppManager";
|
35
28
|
import type { NetlessApp } from "../typings";
|
36
29
|
import type { ReadonlyTeleBox } from "@netless/telebox-insider";
|
37
30
|
import type { PageRemoveService, PageState } from "../Page";
|
31
|
+
import { calculateNextIndex } from "../Page";
|
32
|
+
import { boxEmitter } from "../BoxEmitter";
|
33
|
+
import { callbacks } from "../callback";
|
38
34
|
|
39
35
|
export type AppEmitter = Emittery<AppEmitterEvent>;
|
40
36
|
|
@@ -42,7 +38,6 @@ export class AppProxy implements PageRemoveService {
|
|
42
38
|
public kind: string;
|
43
39
|
public id: string;
|
44
40
|
public scenePath?: string;
|
45
|
-
private appScenePath: string;
|
46
41
|
public appEmitter: AppEmitter;
|
47
42
|
public scenes?: SceneDefinition[];
|
48
43
|
|
@@ -51,27 +46,16 @@ export class AppProxy implements PageRemoveService {
|
|
51
46
|
private appProxies = this.manager.appProxies;
|
52
47
|
private viewManager = this.manager.viewManager;
|
53
48
|
private store = this.manager.store;
|
54
|
-
public uid = this.manager.uid;
|
55
49
|
|
56
50
|
public isAddApp: boolean;
|
57
|
-
|
51
|
+
private status: "normal" | "destroyed" = "normal";
|
58
52
|
private stateKey: string;
|
59
|
-
|
53
|
+
private _pageState: AppPageStateImpl;
|
54
|
+
private _prevFullPath: string | undefined;
|
60
55
|
|
61
56
|
public appResult?: NetlessApp<any>;
|
62
57
|
public appContext?: AppContext<any, any>;
|
63
58
|
|
64
|
-
private sideEffectManager = new SideEffectManager();
|
65
|
-
private valManager = new ValManager();
|
66
|
-
|
67
|
-
private fullPath$ = this.valManager.attach(new Val<string | undefined>(undefined));
|
68
|
-
private appViewSync?: AppViewSync;
|
69
|
-
|
70
|
-
public camera$ = this.valManager.attach(new Val<ICamera | undefined>(undefined));
|
71
|
-
public size$ = this.valManager.attach(new Val<ISize | undefined>(undefined));
|
72
|
-
public box$ = this.valManager.attach(new Val<ReadonlyTeleBox | undefined>(undefined));
|
73
|
-
public view$ = this.valManager.attach(new Val<View | undefined>(undefined));
|
74
|
-
|
75
59
|
constructor(
|
76
60
|
private params: BaseInsertParams,
|
77
61
|
private manager: AppManager,
|
@@ -80,7 +64,6 @@ export class AppProxy implements PageRemoveService {
|
|
80
64
|
) {
|
81
65
|
this.kind = params.kind;
|
82
66
|
this.id = appId;
|
83
|
-
this.appScenePath = `/${this.id}-app-dir`;
|
84
67
|
this.stateKey = `${this.id}_state`;
|
85
68
|
this.appProxies.set(this.id, this);
|
86
69
|
this.appEmitter = new Emittery();
|
@@ -93,87 +76,12 @@ export class AppProxy implements PageRemoveService {
|
|
93
76
|
// 只有传入了 scenePath 的 App 才会创建 View
|
94
77
|
this.createView();
|
95
78
|
}
|
96
|
-
if (!this.scenePath) {
|
97
|
-
this.scenePath = this.appScenePath;
|
98
|
-
}
|
99
79
|
this._pageState = new AppPageStateImpl({
|
100
80
|
displayer: this.manager.displayer,
|
101
81
|
scenePath: this.scenePath,
|
102
82
|
view: this.view,
|
103
83
|
notifyPageStateChange: this.notifyPageStateChange,
|
104
84
|
});
|
105
|
-
this.sideEffectManager.add(() => () => this._pageState.destroy());
|
106
|
-
this.sideEffectManager.add(() =>
|
107
|
-
emitter.on("roomMembersChange", members => {
|
108
|
-
this.appEmitter.emit("roomMembersChange", members);
|
109
|
-
})
|
110
|
-
);
|
111
|
-
this.camera$.setValue(toJS(this.appAttributes.camera));
|
112
|
-
this.size$.setValue(toJS(this.appAttributes.size));
|
113
|
-
this.addCameraReaction();
|
114
|
-
this.addSizeReaction();
|
115
|
-
this.sideEffectManager.add(() =>
|
116
|
-
combine([this.box$, this.view$]).subscribe(([box, view]) => {
|
117
|
-
if (box && view) {
|
118
|
-
if (!this.camera$.value) {
|
119
|
-
this.storeCamera({
|
120
|
-
centerX: 0,
|
121
|
-
centerY: 0,
|
122
|
-
scale: 1,
|
123
|
-
id: this.uid,
|
124
|
-
});
|
125
|
-
this.camera$.setValue(toJS(this.appAttributes.camera));
|
126
|
-
}
|
127
|
-
if (!this.size$.value && box.contentStageRect) {
|
128
|
-
this.storeSize({
|
129
|
-
id: this.uid,
|
130
|
-
width: box.contentStageRect?.width,
|
131
|
-
height: box.contentStageRect?.height,
|
132
|
-
});
|
133
|
-
this.size$.setValue(toJS(this.appAttributes.size));
|
134
|
-
}
|
135
|
-
this.appViewSync = new AppViewSync(this);
|
136
|
-
this.sideEffectManager.add(() => () => this.appViewSync?.destroy());
|
137
|
-
}
|
138
|
-
})
|
139
|
-
);
|
140
|
-
this.sideEffectManager.add(() =>
|
141
|
-
emitter.on("memberStateChange", this.onMemberStateChange)
|
142
|
-
);
|
143
|
-
}
|
144
|
-
|
145
|
-
public fireMemberStateChange = () => {
|
146
|
-
if (this.manager.room) {
|
147
|
-
this.onMemberStateChange(this.manager.room.state.memberState);
|
148
|
-
}
|
149
|
-
}
|
150
|
-
|
151
|
-
private onMemberStateChange = (memberState: MemberState) => {
|
152
|
-
// clicker 教具把事件穿透给下层
|
153
|
-
const needPointerEventsNone = memberState.currentApplianceName === "clicker";
|
154
|
-
if (needPointerEventsNone) {
|
155
|
-
if (this.appContext?._viewWrapper) {
|
156
|
-
this.appContext._viewWrapper.style.pointerEvents = "none";
|
157
|
-
}
|
158
|
-
} else {
|
159
|
-
if (this.appContext?._viewWrapper) {
|
160
|
-
this.appContext._viewWrapper.style.pointerEvents = "auto";
|
161
|
-
}
|
162
|
-
}
|
163
|
-
}
|
164
|
-
|
165
|
-
public createAppDir() {
|
166
|
-
const scenePath = this.scenePath || this.appScenePath;
|
167
|
-
const sceneNode = this._pageState.createSceneNode(scenePath);
|
168
|
-
if (!sceneNode) {
|
169
|
-
putScenes(this.manager.room, scenePath, [{ name: "1" }]);
|
170
|
-
this._pageState.createSceneNode(scenePath);
|
171
|
-
this.setSceneIndex(0);
|
172
|
-
}
|
173
|
-
this.scenes = entireScenes(this.manager.displayer)[scenePath];
|
174
|
-
const view = this.createView();
|
175
|
-
this._pageState.setView(view);
|
176
|
-
return view;
|
177
85
|
}
|
178
86
|
|
179
87
|
private initScenes() {
|
@@ -189,7 +97,7 @@ export class AppProxy implements PageRemoveService {
|
|
189
97
|
}
|
190
98
|
|
191
99
|
public get view(): View | undefined {
|
192
|
-
return this.
|
100
|
+
return this.manager.viewManager.getView(this.id);
|
193
101
|
}
|
194
102
|
|
195
103
|
public get viewIndex(): number | undefined {
|
@@ -224,7 +132,7 @@ export class AppProxy implements PageRemoveService {
|
|
224
132
|
}
|
225
133
|
|
226
134
|
public setFullPath(path: string) {
|
227
|
-
this.
|
135
|
+
this.manager.safeUpdateAttributes(["apps", this.id, Fields.FullPath], path);
|
228
136
|
}
|
229
137
|
|
230
138
|
public async baseInsertApp(skipUpdate = false): Promise<{ appId: string; app: NetlessApp }> {
|
@@ -245,7 +153,7 @@ export class AppProxy implements PageRemoveService {
|
|
245
153
|
} else {
|
246
154
|
throw new Error(`[WindowManager]: app load failed ${params.kind} ${params.src}`);
|
247
155
|
}
|
248
|
-
|
156
|
+
internalEmitter.emit("updateManagerRect");
|
249
157
|
return {
|
250
158
|
appId: this.id,
|
251
159
|
app: appImpl,
|
@@ -253,7 +161,7 @@ export class AppProxy implements PageRemoveService {
|
|
253
161
|
}
|
254
162
|
|
255
163
|
public get box(): ReadonlyTeleBox | undefined {
|
256
|
-
return this.
|
164
|
+
return this.boxManager?.getBox(this.id);
|
257
165
|
}
|
258
166
|
|
259
167
|
private async setupApp(
|
@@ -270,7 +178,7 @@ export class AppProxy implements PageRemoveService {
|
|
270
178
|
const context = new AppContext(this.manager, this.boxManager, appId, this, appOptions);
|
271
179
|
this.appContext = context;
|
272
180
|
try {
|
273
|
-
|
181
|
+
internalEmitter.once(`${appId}${Events.WindowCreated}` as any).then(async () => {
|
274
182
|
let boxInitState: AppInitState | undefined;
|
275
183
|
if (!skipUpdate) {
|
276
184
|
boxInitState = this.getAppInitState(appId);
|
@@ -281,22 +189,28 @@ export class AppProxy implements PageRemoveService {
|
|
281
189
|
this.setViewFocusScenePath();
|
282
190
|
setTimeout(async () => {
|
283
191
|
// 延迟执行 setup, 防止初始化的属性没有更新成功
|
192
|
+
console.log("setup app", app);
|
284
193
|
const result = await app.setup(context);
|
285
194
|
this.appResult = result;
|
286
195
|
appRegister.notifyApp(this.kind, "created", { appId, result });
|
196
|
+
this.afterSetupApp(boxInitState);
|
287
197
|
this.fixMobileSize();
|
198
|
+
callbacks.emit("onAppSetup", appId);
|
288
199
|
}, SETUP_APP_DELAY);
|
289
200
|
});
|
290
|
-
|
201
|
+
this.boxManager?.createBox({
|
291
202
|
appId: appId,
|
292
203
|
app,
|
293
204
|
options,
|
294
205
|
canOperate: this.manager.canOperate,
|
295
206
|
smartPosition: this.isAddApp,
|
296
207
|
});
|
297
|
-
this.box$.setValue(box);
|
298
208
|
if (this.isAddApp && this.box) {
|
299
209
|
this.store.updateAppState(appId, AppAttributes.ZIndex, this.box.zIndex);
|
210
|
+
this.store.updateAppState(appId, AppAttributes.Size, {
|
211
|
+
width: this.box.intrinsicWidth,
|
212
|
+
height: this.box.intrinsicHeight,
|
213
|
+
});
|
300
214
|
this.boxManager.focusBox({ appId }, false);
|
301
215
|
}
|
302
216
|
} catch (error: any) {
|
@@ -318,6 +232,14 @@ export class AppProxy implements PageRemoveService {
|
|
318
232
|
}
|
319
233
|
}
|
320
234
|
|
235
|
+
private afterSetupApp(boxInitState: AppInitState | undefined): void {
|
236
|
+
if (boxInitState) {
|
237
|
+
if (!boxInitState?.x || !boxInitState.y) {
|
238
|
+
this.boxManager?.setBoxInitState(this.id);
|
239
|
+
}
|
240
|
+
}
|
241
|
+
}
|
242
|
+
|
321
243
|
public async onSeek(time: number) {
|
322
244
|
this.appEmitter.emit("seek", time).catch(err => {
|
323
245
|
console.log(`[WindowManager]: emit seek error: ${err.message}`);
|
@@ -452,6 +374,7 @@ export class AppProxy implements PageRemoveService {
|
|
452
374
|
const appState = this.appAttributes?.state;
|
453
375
|
if (appState?.zIndex > 0 && appState.zIndex !== this.box?.zIndex) {
|
454
376
|
this.boxManager?.setZIndex(appId, appState.zIndex);
|
377
|
+
this.boxManager?.focusBox({ appId });
|
455
378
|
}
|
456
379
|
});
|
457
380
|
});
|
@@ -459,9 +382,9 @@ export class AppProxy implements PageRemoveService {
|
|
459
382
|
return autorun(() => {
|
460
383
|
const fullPath = this.appAttributes?.fullPath;
|
461
384
|
this.setFocusScenePathHandler(fullPath);
|
462
|
-
if (this.
|
385
|
+
if (this._prevFullPath !== fullPath) {
|
463
386
|
this.notifyPageStateChange();
|
464
|
-
this.fullPath
|
387
|
+
this._prevFullPath = fullPath;
|
465
388
|
}
|
466
389
|
});
|
467
390
|
});
|
@@ -470,6 +393,7 @@ export class AppProxy implements PageRemoveService {
|
|
470
393
|
private setFocusScenePathHandler = debounce((fullPath: string | undefined) => {
|
471
394
|
if (this.view && fullPath && fullPath !== this.view?.focusScenePath) {
|
472
395
|
setViewFocusScenePath(this.view, fullPath);
|
396
|
+
callbacks.emit("onAppScenePathChange", { appId: this.id, view: this.view });
|
473
397
|
}
|
474
398
|
}, 50);
|
475
399
|
|
@@ -489,17 +413,14 @@ export class AppProxy implements PageRemoveService {
|
|
489
413
|
return fullPath;
|
490
414
|
}
|
491
415
|
|
492
|
-
private createView(): View {
|
493
|
-
const view = this.viewManager.createView(this.id);
|
494
|
-
this.view$.setValue(view);
|
416
|
+
private async createView(): Promise<View> {
|
417
|
+
const view = await this.viewManager.createView(this.id);
|
495
418
|
this.setViewFocusScenePath();
|
496
419
|
return view;
|
497
420
|
}
|
498
421
|
|
499
422
|
public notifyPageStateChange = debounce(() => {
|
500
|
-
|
501
|
-
this.appEmitter.emit("pageStateChange", this.pageState);
|
502
|
-
}
|
423
|
+
this.appEmitter.emit("pageStateChange", this.pageState);
|
503
424
|
}, 50);
|
504
425
|
|
505
426
|
public get pageState(): PageState {
|
@@ -509,7 +430,7 @@ export class AppProxy implements PageRemoveService {
|
|
509
430
|
// PageRemoveService
|
510
431
|
public async removeSceneByIndex(index: number) {
|
511
432
|
const scenePath = this._pageState.getFullPath(index);
|
512
|
-
if (scenePath
|
433
|
+
if (scenePath) {
|
513
434
|
const nextIndex = calculateNextIndex(index, this.pageState);
|
514
435
|
// 只修改 focus path 不修改 FullPath
|
515
436
|
this.setSceneIndexWithoutSync(nextIndex);
|
@@ -545,22 +466,6 @@ export class AppProxy implements PageRemoveService {
|
|
545
466
|
}
|
546
467
|
}
|
547
468
|
|
548
|
-
public storeCamera = (camera: ICamera) => {
|
549
|
-
this.store.updateAppAttributes(this.id, Fields.Camera, camera);
|
550
|
-
};
|
551
|
-
|
552
|
-
public storeSize = (size: ISize) => {
|
553
|
-
this.store.updateAppAttributes(this.id, Fields.Size, size);
|
554
|
-
};
|
555
|
-
|
556
|
-
public moveCamera = (camera: Camera) => {
|
557
|
-
if (!this.camera$.value) {
|
558
|
-
return;
|
559
|
-
}
|
560
|
-
const nextCamera = { ...this.camera$.value, ...camera };
|
561
|
-
this.storeCamera(nextCamera);
|
562
|
-
};
|
563
|
-
|
564
469
|
public async destroy(
|
565
470
|
needCloseBox: boolean,
|
566
471
|
cleanAttrs: boolean,
|
@@ -576,8 +481,7 @@ export class AppProxy implements PageRemoveService {
|
|
576
481
|
console.error("[WindowManager]: notifyApp error", error.message, error.stack);
|
577
482
|
}
|
578
483
|
this.appEmitter.clearListeners();
|
579
|
-
this.
|
580
|
-
emitter.emit(`destroy-${this.id}` as any, { error });
|
484
|
+
internalEmitter.emit(`destroy-${this.id}` as any, { error });
|
581
485
|
if (needCloseBox) {
|
582
486
|
this.boxManager?.closeBox(this.id, skipUpdate);
|
583
487
|
}
|
@@ -588,43 +492,14 @@ export class AppProxy implements PageRemoveService {
|
|
588
492
|
}
|
589
493
|
}
|
590
494
|
this.appProxies.delete(this.id);
|
495
|
+
this._pageState.destroy();
|
591
496
|
|
592
497
|
this.viewManager.destroyView(this.id);
|
593
498
|
this.manager.appStatus.delete(this.id);
|
594
499
|
this.manager.refresher.remove(this.id);
|
595
500
|
this.manager.refresher.remove(this.stateKey);
|
596
501
|
this.manager.refresher.remove(`${this.id}-fullPath`);
|
597
|
-
this.
|
598
|
-
}
|
599
|
-
|
600
|
-
private addCameraReaction = () => {
|
601
|
-
this.sideEffectManager.add(() =>
|
602
|
-
this.manager.refresher.add(`${this.id}-camera`, () =>
|
603
|
-
reaction(
|
604
|
-
() => this.appAttributes?.camera,
|
605
|
-
camera => {
|
606
|
-
if (camera && camera.id !== this.uid) {
|
607
|
-
this.camera$.setValue(toJS(camera));
|
608
|
-
}
|
609
|
-
}
|
610
|
-
)
|
611
|
-
)
|
612
|
-
, "camera");
|
613
|
-
}
|
614
|
-
|
615
|
-
private addSizeReaction = () => {
|
616
|
-
this.sideEffectManager.add(() =>
|
617
|
-
this.manager.refresher.add(`${this.id}-size`, () =>
|
618
|
-
reaction(
|
619
|
-
() => this.appAttributes?.size,
|
620
|
-
size => {
|
621
|
-
if (size && size.id !== this.uid) {
|
622
|
-
this.size$.setValue(toJS(size));
|
623
|
-
}
|
624
|
-
}
|
625
|
-
)
|
626
|
-
)
|
627
|
-
, "size");
|
502
|
+
this._prevFullPath = undefined;
|
628
503
|
}
|
629
504
|
|
630
505
|
public close(): Promise<void> {
|
@@ -1,68 +1,68 @@
|
|
1
1
|
import type {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
MagixEventListenerOptions as WhiteMagixListenerOptions,
|
3
|
+
Event as WhiteEvent,
|
4
|
+
EventPhase as WhiteEventPhase,
|
5
|
+
Scope as WhiteScope,
|
6
6
|
} from "white-web-sdk";
|
7
7
|
|
8
8
|
export interface MagixEventListenerOptions extends WhiteMagixListenerOptions {
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
9
|
+
/**
|
10
|
+
* Rapid emitted callbacks will be slowed down to this interval (in ms).
|
11
|
+
*/
|
12
|
+
fireInterval?: number;
|
13
|
+
/**
|
14
|
+
* If `true`, sent events will reach self-listeners after committed to server.
|
15
|
+
* Otherwise the events will reach self-listeners immediately.
|
16
|
+
*/
|
17
|
+
fireSelfEventAfterCommit?: boolean;
|
18
18
|
}
|
19
19
|
|
20
20
|
export interface MagixEventMessage<
|
21
|
-
|
22
|
-
|
21
|
+
TPayloads = any,
|
22
|
+
TEvent extends MagixEventTypes<TPayloads> = MagixEventTypes<TPayloads>
|
23
23
|
> extends Omit<WhiteEvent, "scope" | "phase"> {
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
24
|
+
/** Event name */
|
25
|
+
event: TEvent;
|
26
|
+
/** Event Payload */
|
27
|
+
payload: TPayloads[TEvent];
|
28
|
+
/** Whiteboard ID of the client who dispatched the event. It will be AdminObserverId for system events. */
|
29
|
+
authorId: number;
|
30
|
+
scope: `${WhiteScope}`;
|
31
|
+
phase: `${WhiteEventPhase}`;
|
32
32
|
}
|
33
33
|
|
34
34
|
export type MagixEventTypes<TPayloads = any> = Extract<keyof TPayloads, string>;
|
35
35
|
|
36
36
|
export type MagixEventPayload<
|
37
|
-
|
38
|
-
|
37
|
+
TPayloads = any,
|
38
|
+
TEvent extends MagixEventTypes<TPayloads> = MagixEventTypes<TPayloads>
|
39
39
|
> = TPayloads[TEvent];
|
40
40
|
|
41
41
|
export type MagixEventDispatcher<TPayloads = any> = <
|
42
|
-
|
42
|
+
TEvent extends MagixEventTypes<TPayloads> = MagixEventTypes<TPayloads>
|
43
43
|
>(
|
44
|
-
|
45
|
-
|
44
|
+
event: TEvent,
|
45
|
+
payload: TPayloads[TEvent]
|
46
46
|
) => void;
|
47
47
|
|
48
48
|
export type MagixEventHandler<
|
49
|
-
|
50
|
-
|
49
|
+
TPayloads = any,
|
50
|
+
TEvent extends MagixEventTypes<TPayloads> = MagixEventTypes<TPayloads>
|
51
51
|
> = (message: MagixEventMessage<TPayloads, TEvent>) => void;
|
52
52
|
|
53
|
-
export type MagixEventListenerDisposer = () => void
|
53
|
+
export type MagixEventListenerDisposer = () => void;
|
54
54
|
|
55
55
|
export type MagixEventAddListener<TPayloads = any> = <
|
56
|
-
|
56
|
+
TEvent extends MagixEventTypes<TPayloads> = MagixEventTypes<TPayloads>
|
57
57
|
>(
|
58
|
-
|
59
|
-
|
60
|
-
|
58
|
+
event: TEvent,
|
59
|
+
handler: MagixEventHandler<TPayloads, TEvent>,
|
60
|
+
options?: MagixEventListenerOptions | undefined
|
61
61
|
) => MagixEventListenerDisposer;
|
62
62
|
|
63
63
|
export type MagixEventRemoveListener<TPayloads = any> = <
|
64
|
-
|
64
|
+
TEvent extends MagixEventTypes<TPayloads> = MagixEventTypes<TPayloads>
|
65
65
|
>(
|
66
|
-
|
67
|
-
|
66
|
+
event: TEvent,
|
67
|
+
handler?: MagixEventHandler<TPayloads, TEvent>
|
68
68
|
) => void;
|
@@ -1,21 +1,21 @@
|
|
1
1
|
export type StorageEventListener<T> = (event: T) => void;
|
2
2
|
|
3
3
|
export class StorageEvent<TMessage> {
|
4
|
-
|
4
|
+
listeners = new Set<StorageEventListener<TMessage>>();
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
get length(): number {
|
7
|
+
return this.listeners.size;
|
8
|
+
}
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
dispatch(message: TMessage): void {
|
11
|
+
this.listeners.forEach(callback => callback(message));
|
12
|
+
}
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
addListener(listener: StorageEventListener<TMessage>): void {
|
15
|
+
this.listeners.add(listener);
|
16
|
+
}
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
removeListener(listener: StorageEventListener<TMessage>): void {
|
19
|
+
this.listeners.delete(listener);
|
20
|
+
}
|
21
21
|
}
|