@netless/window-manager 0.4.30 → 0.4.33
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/CHANGELOG.md +8 -0
- package/dist/AppManager.d.ts +5 -1
- package/dist/BoxEmitter.d.ts +34 -0
- package/dist/BoxManager.d.ts +3 -1
- package/dist/Cursor/index.d.ts +3 -1
- package/dist/Helper.d.ts +2 -0
- package/dist/InternalEmitter.d.ts +0 -18
- package/dist/Utils/AppCreateQueue.d.ts +2 -3
- package/dist/index.cjs.js +12 -12
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.es.js +99 -79
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +12 -12
- package/dist/index.umd.js.map +1 -1
- package/dist/typings.d.ts +2 -1
- package/docs/api.md +1 -1
- package/docs/app-context.md +127 -36
- package/docs/develop-app.md +1 -1
- package/package.json +3 -2
- package/pnpm-lock.yaml +66 -36
- package/src/App/AppProxy.ts +2 -1
- package/src/AppManager.ts +67 -59
- package/src/BoxEmitter.ts +19 -0
- package/src/BoxManager.ts +10 -6
- package/src/Cursor/Cursor.ts +3 -3
- package/src/Cursor/index.ts +8 -2
- package/src/Helper.ts +17 -1
- package/src/InternalEmitter.ts +0 -4
- package/src/ReconnectRefresher.ts +9 -3
- package/src/Utils/AppCreateQueue.ts +2 -3
- package/src/index.ts +27 -37
- package/src/typings.ts +3 -0
- package/dist/ScenePath/index.d.ts +0 -12
- package/src/ScenePath/index.ts +0 -47
package/src/index.ts
CHANGED
@@ -2,7 +2,7 @@ import pRetry from "p-retry";
|
|
2
2
|
import { AppManager } from "./AppManager";
|
3
3
|
import { appRegister } from "./Register";
|
4
4
|
import { callbacks } from "./callback";
|
5
|
-
import { checkVersion, setupWrapper } from "./Helper";
|
5
|
+
import { checkVersion, createInvisiblePlugin, setupWrapper } from "./Helper";
|
6
6
|
import { ContainerResizeObserver } from "./ContainerResizeObserver";
|
7
7
|
import { createBoxManager } from "./BoxManager";
|
8
8
|
import { CursorManager } from "./Cursor";
|
@@ -29,13 +29,7 @@ import {
|
|
29
29
|
wait,
|
30
30
|
} from "./Utils/Common";
|
31
31
|
import type { TELE_BOX_STATE, BoxManager } from "./BoxManager";
|
32
|
-
import
|
33
|
-
AppCreateError,
|
34
|
-
AppManagerNotInitError,
|
35
|
-
BindContainerRoomPhaseInvalidError,
|
36
|
-
InvalidScenePath,
|
37
|
-
ParamsInvalidError,
|
38
|
-
} from "./Utils/error";
|
32
|
+
import * as Errors from "./Utils/error";
|
39
33
|
import type { Apps, Position } from "./AttributesDelegate";
|
40
34
|
import type {
|
41
35
|
Displayer,
|
@@ -54,12 +48,13 @@ import type {
|
|
54
48
|
SceneState,
|
55
49
|
} from "white-web-sdk";
|
56
50
|
import type { AppListeners } from "./AppListener";
|
57
|
-
import type { NetlessApp, RegisterParams } from "./typings";
|
51
|
+
import type { ApplianceIcons, NetlessApp, RegisterParams } from "./typings";
|
58
52
|
import type { TeleBoxColorScheme, TeleBoxState } from "@netless/telebox-insider";
|
59
53
|
import type { AppProxy } from "./App";
|
60
54
|
import type { PublicEvent } from "./callback";
|
61
55
|
import type Emittery from "emittery";
|
62
56
|
import type { PageController, AddPageParams, PageState } from "./Page";
|
57
|
+
import { boxEmitter } from "./BoxEmitter";
|
63
58
|
|
64
59
|
export type WindowMangerAttributes = {
|
65
60
|
modelValue?: string;
|
@@ -142,6 +137,7 @@ export type MountParams = {
|
|
142
137
|
debug?: boolean;
|
143
138
|
disableCameraTransform?: boolean;
|
144
139
|
prefersColorScheme?: TeleBoxColorScheme;
|
140
|
+
applianceIcons?: ApplianceIcons;
|
145
141
|
};
|
146
142
|
|
147
143
|
export const reconnectRefresher = new ReconnectRefresher({ emitter });
|
@@ -237,7 +233,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
|
|
237
233
|
|
238
234
|
manager.appManager = new AppManager(manager);
|
239
235
|
manager._pageState = new PageStateImpl(manager.appManager);
|
240
|
-
manager.cursorManager = new CursorManager(manager.appManager, Boolean(cursor));
|
236
|
+
manager.cursorManager = new CursorManager(manager.appManager, Boolean(cursor), params.applianceIcons);
|
241
237
|
if (containerSizeRatio) {
|
242
238
|
manager.containerSizeRatio = containerSizeRatio;
|
243
239
|
}
|
@@ -258,8 +254,8 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
|
|
258
254
|
return manager;
|
259
255
|
}
|
260
256
|
|
261
|
-
private static async initManager(room: Room): Promise<WindowManager> {
|
262
|
-
let manager = room.getInvisiblePlugin(WindowManager.kind) as WindowManager;
|
257
|
+
private static async initManager(room: Room): Promise<WindowManager | undefined> {
|
258
|
+
let manager = room.getInvisiblePlugin(WindowManager.kind) as WindowManager | undefined;
|
263
259
|
if (!manager) {
|
264
260
|
if (isRoom(room)) {
|
265
261
|
if (room.isWritable === false) {
|
@@ -268,18 +264,12 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
|
|
268
264
|
} catch (error) {
|
269
265
|
throw new Error("[WindowManger]: room must be switched to be writable");
|
270
266
|
}
|
271
|
-
manager =
|
272
|
-
|
273
|
-
{}
|
274
|
-
)) as WindowManager;
|
275
|
-
manager.ensureAttributes();
|
267
|
+
manager = await createInvisiblePlugin(room);
|
268
|
+
manager?.ensureAttributes();
|
276
269
|
await wait(500);
|
277
270
|
await room.setWritable(false);
|
278
271
|
} else {
|
279
|
-
manager =
|
280
|
-
WindowManager,
|
281
|
-
{}
|
282
|
-
)) as WindowManager;
|
272
|
+
manager = await createInvisiblePlugin(room);
|
283
273
|
}
|
284
274
|
}
|
285
275
|
}
|
@@ -320,8 +310,8 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
|
|
320
310
|
}
|
321
311
|
|
322
312
|
public bindContainer(container: HTMLElement) {
|
323
|
-
if (this.room.phase !== RoomPhase.Connected) {
|
324
|
-
throw new BindContainerRoomPhaseInvalidError();
|
313
|
+
if (isRoom(this.displayer) && this.room.phase !== RoomPhase.Connected) {
|
314
|
+
throw new Errors.BindContainerRoomPhaseInvalidError();
|
325
315
|
}
|
326
316
|
if (WindowManager.isCreated && WindowManager.container) {
|
327
317
|
if (WindowManager.container.firstChild) {
|
@@ -339,7 +329,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
|
|
339
329
|
if (this.boxManager) {
|
340
330
|
this.boxManager.destroy();
|
341
331
|
}
|
342
|
-
const boxManager = createBoxManager(this, callbacks, emitter, {
|
332
|
+
const boxManager = createBoxManager(this, callbacks, emitter, boxEmitter, {
|
343
333
|
collectorContainer: params.collectorContainer,
|
344
334
|
collectorStyles: params.collectorStyles,
|
345
335
|
prefersColorScheme: params.prefersColorScheme,
|
@@ -407,19 +397,19 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
|
|
407
397
|
return this._addApp(params);
|
408
398
|
}
|
409
399
|
} else {
|
410
|
-
throw new AppManagerNotInitError();
|
400
|
+
throw new Errors.AppManagerNotInitError();
|
411
401
|
}
|
412
402
|
}
|
413
403
|
|
414
404
|
private async _addApp<T = any>(params: AddAppParams<T>): Promise<string | undefined> {
|
415
405
|
if (this.appManager) {
|
416
406
|
if (!params.kind || typeof params.kind !== "string") {
|
417
|
-
throw new ParamsInvalidError();
|
407
|
+
throw new Errors.ParamsInvalidError();
|
418
408
|
}
|
419
409
|
const appImpl = await appRegister.appClasses.get(params.kind)?.();
|
420
410
|
if (appImpl && appImpl.config?.singleton) {
|
421
411
|
if (this.appManager.appProxies.has(params.kind)) {
|
422
|
-
throw new AppCreateError();
|
412
|
+
throw new Errors.AppCreateError();
|
423
413
|
}
|
424
414
|
}
|
425
415
|
const isDynamicPPT = this.setupScenePath(params, this.appManager);
|
@@ -432,7 +422,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
|
|
432
422
|
const appId = await this.appManager.addApp(params, Boolean(isDynamicPPT));
|
433
423
|
return appId;
|
434
424
|
} else {
|
435
|
-
throw new AppManagerNotInitError();
|
425
|
+
throw new Errors.AppManagerNotInitError();
|
436
426
|
}
|
437
427
|
}
|
438
428
|
|
@@ -442,7 +432,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
|
|
442
432
|
const { scenePath, scenes } = params.options;
|
443
433
|
if (scenePath) {
|
444
434
|
if (!isValidScenePath(scenePath)) {
|
445
|
-
throw new InvalidScenePath();
|
435
|
+
throw new Errors.InvalidScenePath();
|
446
436
|
}
|
447
437
|
const apps = Object.keys(this.apps || {});
|
448
438
|
for (const appId of apps) {
|
@@ -645,7 +635,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
|
|
645
635
|
if (this.appManager) {
|
646
636
|
return this.appManager.mainViewProxy.view;
|
647
637
|
} else {
|
648
|
-
throw new AppManagerNotInitError();
|
638
|
+
throw new Errors.AppManagerNotInitError();
|
649
639
|
}
|
650
640
|
}
|
651
641
|
|
@@ -653,7 +643,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
|
|
653
643
|
if (this.appManager) {
|
654
644
|
return this.appManager.mainViewProxy.view.camera;
|
655
645
|
} else {
|
656
|
-
throw new AppManagerNotInitError();
|
646
|
+
throw new Errors.AppManagerNotInitError();
|
657
647
|
}
|
658
648
|
}
|
659
649
|
|
@@ -661,7 +651,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
|
|
661
651
|
if (this.appManager) {
|
662
652
|
return this.appManager.mainViewProxy.cameraState;
|
663
653
|
} else {
|
664
|
-
throw new AppManagerNotInitError();
|
654
|
+
throw new Errors.AppManagerNotInitError();
|
665
655
|
}
|
666
656
|
}
|
667
657
|
|
@@ -673,7 +663,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
|
|
673
663
|
if (this.appManager) {
|
674
664
|
return this.appManager.boxManager?.boxState;
|
675
665
|
} else {
|
676
|
-
throw new AppManagerNotInitError();
|
666
|
+
throw new Errors.AppManagerNotInitError();
|
677
667
|
}
|
678
668
|
}
|
679
669
|
|
@@ -685,7 +675,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
|
|
685
675
|
if (this.appManager) {
|
686
676
|
return this.appManager.boxManager?.prefersColorScheme;
|
687
677
|
} else {
|
688
|
-
throw new AppManagerNotInitError();
|
678
|
+
throw new Errors.AppManagerNotInitError();
|
689
679
|
}
|
690
680
|
}
|
691
681
|
|
@@ -705,7 +695,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
|
|
705
695
|
if (this.appManager) {
|
706
696
|
return this.appManager?.getMainViewSceneDir();
|
707
697
|
} else {
|
708
|
-
throw new AppManagerNotInitError();
|
698
|
+
throw new Errors.AppManagerNotInitError();
|
709
699
|
}
|
710
700
|
}
|
711
701
|
|
@@ -730,7 +720,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
|
|
730
720
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
731
721
|
return this.appManager.sceneState!;
|
732
722
|
} else {
|
733
|
-
throw new AppManagerNotInitError();
|
723
|
+
throw new Errors.AppManagerNotInitError();
|
734
724
|
}
|
735
725
|
}
|
736
726
|
|
@@ -738,7 +728,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
|
|
738
728
|
if (this._pageState) {
|
739
729
|
return this._pageState.toObject();
|
740
730
|
} else {
|
741
|
-
throw new AppManagerNotInitError();
|
731
|
+
throw new Errors.AppManagerNotInitError();
|
742
732
|
}
|
743
733
|
}
|
744
734
|
|
package/src/typings.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import type Emittery from "emittery";
|
2
2
|
import type {
|
3
3
|
AnimationMode,
|
4
|
+
ApplianceNames,
|
4
5
|
Displayer,
|
5
6
|
DisplayerState,
|
6
7
|
Player,
|
@@ -75,6 +76,8 @@ export type RegisterParams<AppOptions = any, SetupResult = any, Attributes = any
|
|
75
76
|
|
76
77
|
export type AppListenerKeys = keyof AppEmitterEvent;
|
77
78
|
|
79
|
+
export type ApplianceIcons = Partial<Record<ApplianceNames, string>>;
|
80
|
+
|
78
81
|
export type { AppContext } from "./App/AppContext";
|
79
82
|
export type { ReadonlyTeleBox, TeleBoxRect };
|
80
83
|
export type { SceneState, SceneDefinition, View, AnimationMode, Displayer, Room, Player };
|
@@ -1,12 +0,0 @@
|
|
1
|
-
import type { ScenesCallbacks, ScenesCallbacksNode } from "white-web-sdk";
|
2
|
-
import type { AppManager } from "../AppManager";
|
3
|
-
export declare class ScenesCallbackManager {
|
4
|
-
private manager;
|
5
|
-
private nodes;
|
6
|
-
constructor(manager: AppManager);
|
7
|
-
createNode(path: string, callbacks?: Partial<ScenesCallbacks>): ScenesCallbacksNode | null;
|
8
|
-
getScenes(path: string): readonly string[] | undefined;
|
9
|
-
getScenesOnce(path: string): readonly string[] | undefined;
|
10
|
-
removeNode(path: string): void;
|
11
|
-
destroy(): void;
|
12
|
-
}
|
package/src/ScenePath/index.ts
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
import type { ScenesCallbacks, ScenesCallbacksNode } from "white-web-sdk";
|
2
|
-
import type { AppManager } from "../AppManager";
|
3
|
-
|
4
|
-
export class ScenesCallbackManager {
|
5
|
-
|
6
|
-
private nodes: Map<string, ScenesCallbacksNode> = new Map();
|
7
|
-
|
8
|
-
constructor(private manager: AppManager) {}
|
9
|
-
|
10
|
-
public createNode(path: string, callbacks?: Partial<ScenesCallbacks>): ScenesCallbacksNode | null {
|
11
|
-
const node = this.manager.displayer.createScenesCallback(path, callbacks);
|
12
|
-
if (node) {
|
13
|
-
this.nodes.set(path, node);
|
14
|
-
}
|
15
|
-
return node;
|
16
|
-
}
|
17
|
-
|
18
|
-
public getScenes(path: string) {
|
19
|
-
const node = this.nodes.get(path);
|
20
|
-
return node?.scenes;
|
21
|
-
}
|
22
|
-
|
23
|
-
public getScenesOnce(path: string) {
|
24
|
-
let node = this.nodes.get(path);
|
25
|
-
if (!node) {
|
26
|
-
const created = this.createNode(path);
|
27
|
-
if (created) {
|
28
|
-
node = created;
|
29
|
-
}
|
30
|
-
}
|
31
|
-
const scenes = node?.scenes;
|
32
|
-
this.removeNode(path);
|
33
|
-
return scenes;
|
34
|
-
}
|
35
|
-
|
36
|
-
public removeNode(path: string) {
|
37
|
-
const node = this.nodes.get(path);
|
38
|
-
if (node) {
|
39
|
-
node.dispose();
|
40
|
-
this.nodes.delete(path);
|
41
|
-
}
|
42
|
-
}
|
43
|
-
|
44
|
-
public destroy(): void {
|
45
|
-
this.nodes.forEach(node => node.dispose());
|
46
|
-
}
|
47
|
-
}
|