@netless/window-manager 0.4.8 → 0.4.9-canary.2
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 +5 -0
- package/README.md +1 -0
- package/dist/AppContext.d.ts +4 -4
- package/dist/AppManager.d.ts +5 -2
- package/dist/BoxManager.d.ts +3 -1
- package/dist/ContainerResizeObserver.d.ts +1 -1
- package/dist/InternalEmitter.d.ts +41 -0
- package/dist/ReconnectRefresher.d.ts +1 -1
- package/dist/Utils/AppCreateQueue.d.ts +2 -0
- package/dist/Utils/Common.d.ts +1 -1
- package/dist/callback.d.ts +22 -0
- package/dist/index.d.ts +5 -58
- package/dist/index.es.js +5 -5
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +5 -5
- package/dist/index.umd.js.map +1 -1
- package/docs/advanced.md +13 -0
- package/docs/api.md +16 -1
- package/docs/develop-app.md +50 -0
- package/package.json +1 -1
- package/src/AppContext.ts +51 -33
- package/src/AppListener.ts +2 -1
- package/src/AppManager.ts +46 -12
- package/src/AppProxy.ts +1 -1
- package/src/BoxManager.ts +3 -1
- package/src/ContainerResizeObserver.ts +1 -1
- package/src/Cursor/index.ts +4 -2
- package/src/InternalEmitter.ts +27 -0
- package/src/ReconnectRefresher.ts +1 -1
- package/src/RedoUndo.ts +2 -1
- package/src/Register/loader.ts +1 -1
- package/src/Utils/AppCreateQueue.ts +10 -0
- package/src/Utils/Common.ts +2 -2
- package/src/Utils/RoomHacker.ts +3 -3
- package/src/View/MainView.ts +2 -1
- package/src/callback.ts +24 -0
- package/src/index.ts +24 -62
package/src/callback.ts
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
import Emittery from "emittery";
|
2
|
+
import type { TeleBoxColorScheme, TELE_BOX_STATE } from "@netless/telebox-insider";
|
3
|
+
import type { CameraState, SceneState, ViewVisionMode } from "white-web-sdk";
|
4
|
+
import type { LoadAppEvent } from "./Register";
|
5
|
+
|
6
|
+
export type PublicEvent = {
|
7
|
+
mainViewModeChange: ViewVisionMode;
|
8
|
+
boxStateChange: `${TELE_BOX_STATE}`;
|
9
|
+
darkModeChange: boolean;
|
10
|
+
prefersColorSchemeChange: TeleBoxColorScheme;
|
11
|
+
cameraStateChange: CameraState;
|
12
|
+
mainViewScenePathChange: string;
|
13
|
+
mainViewSceneIndexChange: number;
|
14
|
+
focusedChange: string | undefined;
|
15
|
+
mainViewScenesLengthChange: number;
|
16
|
+
canRedoStepsChange: number;
|
17
|
+
canUndoStepsChange: number;
|
18
|
+
loadApp: LoadAppEvent;
|
19
|
+
ready: undefined; // 所有 APP 创建完毕时触发
|
20
|
+
sceneStateChange: SceneState;
|
21
|
+
};
|
22
|
+
|
23
|
+
export type CallbacksType = Emittery<PublicEvent>;
|
24
|
+
export const callbacks: CallbacksType = new Emittery();
|
package/src/index.ts
CHANGED
@@ -1,12 +1,13 @@
|
|
1
|
-
import Emittery from "emittery";
|
2
1
|
import pRetry from "p-retry";
|
3
2
|
import { AppManager } from "./AppManager";
|
4
3
|
import { appRegister } from "./Register";
|
4
|
+
import { callbacks } from "./callback";
|
5
5
|
import { checkVersion, setupWrapper } from "./Helper";
|
6
6
|
import { ContainerResizeObserver } from "./ContainerResizeObserver";
|
7
7
|
import { createBoxManager } from "./BoxManager";
|
8
8
|
import { CursorManager } from "./Cursor";
|
9
9
|
import { DEFAULT_CONTAINER_RATIO, Events, ROOT_DIR } from "./constants";
|
10
|
+
import { emitter } from "./InternalEmitter";
|
10
11
|
import { Fields } from "./AttributesDelegate";
|
11
12
|
import { initDb } from "./Register/storage";
|
12
13
|
import { InvisiblePlugin, isPlayer, isRoom, RoomPhase, ViewMode } from "white-web-sdk";
|
@@ -18,7 +19,6 @@ import { setupBuiltin } from "./BuiltinApps";
|
|
18
19
|
import "video.js/dist/video-js.css";
|
19
20
|
import "./style.css";
|
20
21
|
import "@netless/telebox-insider/dist/style.css";
|
21
|
-
import type { LoadAppEvent } from "./Register";
|
22
22
|
import {
|
23
23
|
addEmitterOnceListener,
|
24
24
|
ensureValidScenePath,
|
@@ -45,15 +45,17 @@ import type {
|
|
45
45
|
CameraBound,
|
46
46
|
Point,
|
47
47
|
Rectangle,
|
48
|
-
ViewVisionMode,
|
49
48
|
CameraState,
|
50
49
|
Player,
|
51
50
|
ImageInformation,
|
51
|
+
SceneState,
|
52
52
|
} from "white-web-sdk";
|
53
53
|
import type { AppListeners } from "./AppListener";
|
54
54
|
import type { NetlessApp, RegisterParams } from "./typings";
|
55
55
|
import type { TeleBoxColorScheme, TeleBoxState } from "@netless/telebox-insider";
|
56
56
|
import type { AppProxy } from "./AppProxy";
|
57
|
+
import type { PublicEvent } from "./Callback";
|
58
|
+
import type Emittery from "emittery";
|
57
59
|
|
58
60
|
export type WindowMangerAttributes = {
|
59
61
|
modelValue?: string;
|
@@ -122,45 +124,6 @@ export type AppInitState = {
|
|
122
124
|
|
123
125
|
export type CursorMovePayload = { uid: string; state?: "leave"; position: Position };
|
124
126
|
|
125
|
-
export type EmitterEvent = {
|
126
|
-
onCreated: undefined;
|
127
|
-
InitReplay: AppInitState;
|
128
|
-
move: { appId: string; x: number; y: number };
|
129
|
-
focus: { appId: string };
|
130
|
-
close: { appId: string };
|
131
|
-
resize: { appId: string; width: number; height: number; x?: number; y?: number };
|
132
|
-
error: Error;
|
133
|
-
seek: number;
|
134
|
-
mainViewMounted: undefined;
|
135
|
-
observerIdChange: number;
|
136
|
-
boxStateChange: string;
|
137
|
-
playgroundSizeChange: DOMRect;
|
138
|
-
onReconnected: void;
|
139
|
-
removeScenes: string;
|
140
|
-
cursorMove: CursorMovePayload;
|
141
|
-
updateManagerRect: undefined;
|
142
|
-
focusedChange: { focused: string | undefined, prev: string | undefined };
|
143
|
-
rootDirRemoved: undefined;
|
144
|
-
};
|
145
|
-
|
146
|
-
export type EmitterType = Emittery<EmitterEvent>;
|
147
|
-
export const emitter: EmitterType = new Emittery();
|
148
|
-
|
149
|
-
export type PublicEvent = {
|
150
|
-
mainViewModeChange: ViewVisionMode;
|
151
|
-
boxStateChange: `${TELE_BOX_STATE}`;
|
152
|
-
darkModeChange: boolean;
|
153
|
-
prefersColorSchemeChange: TeleBoxColorScheme;
|
154
|
-
cameraStateChange: CameraState;
|
155
|
-
mainViewScenePathChange: string;
|
156
|
-
mainViewSceneIndexChange: number;
|
157
|
-
focusedChange: string | undefined;
|
158
|
-
mainViewScenesLengthChange: number;
|
159
|
-
canRedoStepsChange: number;
|
160
|
-
canUndoStepsChange: number;
|
161
|
-
loadApp: LoadAppEvent;
|
162
|
-
};
|
163
|
-
|
164
127
|
export type MountParams = {
|
165
128
|
room: Room | Player;
|
166
129
|
container?: HTMLElement;
|
@@ -177,15 +140,12 @@ export type MountParams = {
|
|
177
140
|
prefersColorScheme?: TeleBoxColorScheme;
|
178
141
|
};
|
179
142
|
|
180
|
-
export type CallbacksType = Emittery<PublicEvent>;
|
181
|
-
export const callbacks: CallbacksType = new Emittery();
|
182
|
-
|
183
143
|
export const reconnectRefresher = new ReconnectRefresher({ emitter });
|
184
144
|
|
185
145
|
export type AddPageParams = {
|
186
146
|
after?: boolean;
|
187
147
|
scene?: SceneDefinition;
|
188
|
-
}
|
148
|
+
};
|
189
149
|
|
190
150
|
export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
191
151
|
public static kind = "WindowManager";
|
@@ -350,6 +310,10 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
350
310
|
return mainViewElement;
|
351
311
|
}
|
352
312
|
|
313
|
+
public static get registered() {
|
314
|
+
return appRegister.registered;
|
315
|
+
}
|
316
|
+
|
353
317
|
public bindContainer(container: HTMLElement) {
|
354
318
|
if (WindowManager.isCreated && WindowManager.container) {
|
355
319
|
if (WindowManager.container.firstChild) {
|
@@ -495,10 +459,10 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
495
459
|
public async nextPage(): Promise<boolean> {
|
496
460
|
if (this.appManager) {
|
497
461
|
const nextIndex = this.mainViewSceneIndex + 1;
|
498
|
-
if (nextIndex >= this.mainViewScenesLength)
|
462
|
+
if (nextIndex >= this.mainViewScenesLength) {
|
499
463
|
console.warn(`[WindowManager]: current page is the last page`);
|
500
464
|
return false;
|
501
|
-
}
|
465
|
+
}
|
502
466
|
await this.appManager.setMainViewSceneIndex(nextIndex);
|
503
467
|
return true;
|
504
468
|
} else {
|
@@ -512,7 +476,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
512
476
|
if (prevIndex < 0) {
|
513
477
|
console.warn(`[WindowManager]: current page is the first page`);
|
514
478
|
return false;
|
515
|
-
}
|
479
|
+
}
|
516
480
|
await this.appManager.setMainViewSceneIndex(prevIndex);
|
517
481
|
return true;
|
518
482
|
} else {
|
@@ -690,20 +654,19 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
690
654
|
}
|
691
655
|
|
692
656
|
public get canRedoSteps(): number {
|
693
|
-
|
694
|
-
if (focused) {
|
695
|
-
return this.appManager?.focusApp?.view?.canRedoSteps || 0;
|
696
|
-
} else {
|
697
|
-
return this.mainView.canRedoSteps;
|
698
|
-
}
|
657
|
+
return this.focusedView?.canRedoSteps || 0;
|
699
658
|
}
|
700
659
|
|
701
660
|
public get canUndoSteps(): number {
|
702
|
-
|
703
|
-
|
704
|
-
|
661
|
+
return this.focusedView?.canUndoSteps || 0;
|
662
|
+
}
|
663
|
+
|
664
|
+
public get sceneState(): SceneState {
|
665
|
+
if (this.appManager) {
|
666
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
667
|
+
return this.appManager.sceneState!;
|
705
668
|
} else {
|
706
|
-
|
669
|
+
throw new AppManagerNotInitError();
|
707
670
|
}
|
708
671
|
}
|
709
672
|
|
@@ -886,12 +849,11 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
886
849
|
if (!this.attributes[Fields.Cursors]) {
|
887
850
|
this.safeSetAttributes({ [Fields.Cursors]: {} });
|
888
851
|
}
|
889
|
-
const sceneState = this.displayer.state.sceneState;
|
890
852
|
if (!this.attributes["_mainScenePath"]) {
|
891
|
-
this.safeSetAttributes({ _mainScenePath:
|
853
|
+
this.safeSetAttributes({ _mainScenePath: ROOT_DIR });
|
892
854
|
}
|
893
855
|
if (!this.attributes["_mainSceneIndex"]) {
|
894
|
-
this.safeSetAttributes({ _mainSceneIndex:
|
856
|
+
this.safeSetAttributes({ _mainSceneIndex: 0 });
|
895
857
|
}
|
896
858
|
}
|
897
859
|
}
|