@netless/window-manager 0.4.5 → 0.4.8-canary.0
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 +10 -0
- package/dist/AppManager.d.ts +9 -8
- package/dist/BoxManager.d.ts +1 -2
- package/dist/Helper.d.ts +2 -0
- package/dist/RedoUndo.d.ts +18 -0
- package/dist/View/MainView.d.ts +1 -0
- package/dist/index.d.ts +14 -0
- 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/dist/style.css +1 -1
- package/docs/api.md +36 -0
- package/docs/migrate.md +18 -0
- package/package.json +4 -4
- package/src/AppManager.ts +60 -72
- package/src/AppProxy.ts +7 -3
- package/src/BoxManager.ts +4 -12
- package/src/Cursor/Cursor.ts +2 -1
- package/src/Helper.ts +6 -0
- package/src/RedoUndo.ts +87 -0
- package/src/Utils/RoomHacker.ts +1 -1
- package/src/View/MainView.ts +11 -0
- package/src/index.ts +52 -2
package/src/RedoUndo.ts
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
import { callbacks, emitter } from "./index";
|
2
|
+
import type { View } from "white-web-sdk";
|
3
|
+
import type { AppProxy } from "./AppProxy";
|
4
|
+
|
5
|
+
export type RedoUndoContext = {
|
6
|
+
mainView: () => View;
|
7
|
+
focus: () => string | undefined;
|
8
|
+
getAppProxy: (id: string) => AppProxy | undefined;
|
9
|
+
};
|
10
|
+
|
11
|
+
export class RedoUndo {
|
12
|
+
constructor(private context: RedoUndoContext) {
|
13
|
+
emitter.on("focusedChange", changed => {
|
14
|
+
this.disposePrevFocusViewRedoUndoListeners(changed.prev);
|
15
|
+
setTimeout(() => {
|
16
|
+
this.addRedoUndoListeners(changed.focused);
|
17
|
+
}, 0);
|
18
|
+
});
|
19
|
+
emitter.on("rootDirRemoved", () => {
|
20
|
+
this.disposePrevFocusViewRedoUndoListeners(context.focus());
|
21
|
+
this.addRedoUndoListeners(context.focus());
|
22
|
+
});
|
23
|
+
this.addRedoUndoListeners(context.focus());
|
24
|
+
}
|
25
|
+
|
26
|
+
private addRedoUndoListeners = (focused: string | undefined) => {
|
27
|
+
if (focused === undefined) {
|
28
|
+
this.addViewCallbacks(
|
29
|
+
this.context.mainView(),
|
30
|
+
this.onCanRedoStepsUpdate,
|
31
|
+
this.onCanUndoStepsUpdate
|
32
|
+
);
|
33
|
+
} else {
|
34
|
+
const focusApp = this.context.getAppProxy(focused);
|
35
|
+
if (focusApp && focusApp.view) {
|
36
|
+
this.addViewCallbacks(
|
37
|
+
focusApp.view,
|
38
|
+
this.onCanRedoStepsUpdate,
|
39
|
+
this.onCanUndoStepsUpdate
|
40
|
+
);
|
41
|
+
}
|
42
|
+
}
|
43
|
+
};
|
44
|
+
|
45
|
+
private addViewCallbacks = (
|
46
|
+
view: View,
|
47
|
+
redoListener: (steps: number) => void,
|
48
|
+
undoListener: (steps: number) => void
|
49
|
+
) => {
|
50
|
+
redoListener(view.canRedoSteps);
|
51
|
+
undoListener(view.canUndoSteps);
|
52
|
+
view.callbacks.on("onCanRedoStepsUpdate", redoListener);
|
53
|
+
view.callbacks.on("onCanUndoStepsUpdate", undoListener);
|
54
|
+
};
|
55
|
+
|
56
|
+
private disposeViewCallbacks = (view: View) => {
|
57
|
+
view.callbacks.off("onCanRedoStepsUpdate", this.onCanRedoStepsUpdate);
|
58
|
+
view.callbacks.off("onCanUndoStepsUpdate", this.onCanUndoStepsUpdate);
|
59
|
+
};
|
60
|
+
|
61
|
+
private onCanRedoStepsUpdate = (steps: number) => {
|
62
|
+
callbacks.emit("canRedoStepsChange", steps);
|
63
|
+
};
|
64
|
+
|
65
|
+
private onCanUndoStepsUpdate = (steps: number) => {
|
66
|
+
callbacks.emit("canUndoStepsChange", steps);
|
67
|
+
};
|
68
|
+
|
69
|
+
private disposePrevFocusViewRedoUndoListeners = (prevFocused: string | undefined) => {
|
70
|
+
let view: View | undefined = undefined;
|
71
|
+
if (prevFocused === undefined) {
|
72
|
+
view = this.context.mainView();
|
73
|
+
} else {
|
74
|
+
const appProxy = this.context.getAppProxy(prevFocused);
|
75
|
+
if (appProxy && appProxy.view) {
|
76
|
+
view = appProxy.view;
|
77
|
+
}
|
78
|
+
}
|
79
|
+
if (view) {
|
80
|
+
this.disposeViewCallbacks(view);
|
81
|
+
}
|
82
|
+
};
|
83
|
+
|
84
|
+
public destroy() {
|
85
|
+
this.disposePrevFocusViewRedoUndoListeners(this.context.focus());
|
86
|
+
}
|
87
|
+
}
|
package/src/Utils/RoomHacker.ts
CHANGED
@@ -33,7 +33,7 @@ export const replaceRoomFunction = (room: Room | Player, manager: WindowManager)
|
|
33
33
|
},
|
34
34
|
});
|
35
35
|
|
36
|
-
room.moveCamera = (camera: Camera) => manager.
|
36
|
+
room.moveCamera = (camera: Camera) => manager.moveCamera(camera);
|
37
37
|
room.moveCameraToContain = (...args) => manager.moveCameraToContain(...args);
|
38
38
|
room.convertToPointInWorld = (...args) => manager.mainView.convertToPointInWorld(...args);
|
39
39
|
room.setCameraBound = (...args) => manager.mainView.setCameraBound(...args);
|
package/src/View/MainView.ts
CHANGED
@@ -110,6 +110,17 @@ export class MainViewProxy {
|
|
110
110
|
}
|
111
111
|
}
|
112
112
|
|
113
|
+
public rebind(): void {
|
114
|
+
const divElement = this.mainView.divElement;
|
115
|
+
const disableCameraTransform = this.mainView.disableCameraTransform;
|
116
|
+
this.stop();
|
117
|
+
this.mainView.release();
|
118
|
+
this.mainView = this.createMainView();
|
119
|
+
this.mainView.disableCameraTransform = disableCameraTransform;
|
120
|
+
this.mainView.divElement = divElement;
|
121
|
+
this.start();
|
122
|
+
}
|
123
|
+
|
113
124
|
private onCameraUpdatedByDevice = (camera: Camera) => {
|
114
125
|
this.store.setMainViewCamera({ ...camera, id: this.manager.uid });
|
115
126
|
if (!isEqual(this.mainViewSize, { ...this.mainView.size, id: this.manager.uid })) {
|
package/src/index.ts
CHANGED
@@ -6,7 +6,7 @@ import { checkVersion, setupWrapper } from "./Helper";
|
|
6
6
|
import { ContainerResizeObserver } from "./ContainerResizeObserver";
|
7
7
|
import { createBoxManager } from "./BoxManager";
|
8
8
|
import { CursorManager } from "./Cursor";
|
9
|
-
import { DEFAULT_CONTAINER_RATIO, Events } from "./constants";
|
9
|
+
import { DEFAULT_CONTAINER_RATIO, Events, ROOT_DIR } from "./constants";
|
10
10
|
import { Fields } from "./AttributesDelegate";
|
11
11
|
import { initDb } from "./Register/storage";
|
12
12
|
import { InvisiblePlugin, isPlayer, isRoom, RoomPhase, ViewMode } from "white-web-sdk";
|
@@ -15,6 +15,7 @@ import { log } from "./Utils/log";
|
|
15
15
|
import { ReconnectRefresher } from "./ReconnectRefresher";
|
16
16
|
import { replaceRoomFunction } from "./Utils/RoomHacker";
|
17
17
|
import { setupBuiltin } from "./BuiltinApps";
|
18
|
+
import "video.js/dist/video-js.css";
|
18
19
|
import "./style.css";
|
19
20
|
import "@netless/telebox-insider/dist/style.css";
|
20
21
|
import type { LoadAppEvent } from "./Register";
|
@@ -137,6 +138,9 @@ export type EmitterEvent = {
|
|
137
138
|
onReconnected: void;
|
138
139
|
removeScenes: string;
|
139
140
|
cursorMove: CursorMovePayload;
|
141
|
+
updateManagerRect: undefined;
|
142
|
+
focusedChange: { focused: string | undefined, prev: string | undefined };
|
143
|
+
rootDirRemoved: undefined;
|
140
144
|
};
|
141
145
|
|
142
146
|
export type EmitterType = Emittery<EmitterEvent>;
|
@@ -178,6 +182,11 @@ export const callbacks: CallbacksType = new Emittery();
|
|
178
182
|
|
179
183
|
export const reconnectRefresher = new ReconnectRefresher({ emitter });
|
180
184
|
|
185
|
+
export type AddPageParams = {
|
186
|
+
after?: boolean;
|
187
|
+
scene?: SceneDefinition;
|
188
|
+
}
|
189
|
+
|
181
190
|
export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
182
191
|
public static kind = "WindowManager";
|
183
192
|
public static displayer: Displayer;
|
@@ -368,7 +377,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
368
377
|
}
|
369
378
|
}
|
370
379
|
}
|
371
|
-
|
380
|
+
emitter.emit("updateManagerRect");
|
372
381
|
this.appManager?.refresh();
|
373
382
|
this.appManager?.resetMaximized();
|
374
383
|
this.appManager?.resetMinimized();
|
@@ -483,6 +492,47 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
483
492
|
}
|
484
493
|
}
|
485
494
|
|
495
|
+
public async nextPage(): Promise<boolean> {
|
496
|
+
if (this.appManager) {
|
497
|
+
const nextIndex = this.mainViewSceneIndex + 1;
|
498
|
+
if (nextIndex >= this.mainViewScenesLength) {
|
499
|
+
console.warn(`[WindowManager]: current page is the last page`);
|
500
|
+
return false;
|
501
|
+
};
|
502
|
+
await this.appManager.setMainViewSceneIndex(nextIndex);
|
503
|
+
return true;
|
504
|
+
} else {
|
505
|
+
return false;
|
506
|
+
}
|
507
|
+
}
|
508
|
+
|
509
|
+
public async prevPage(): Promise<boolean> {
|
510
|
+
if (this.appManager) {
|
511
|
+
const prevIndex = this.mainViewSceneIndex - 1;
|
512
|
+
if (prevIndex < 0) {
|
513
|
+
console.warn(`[WindowManager]: current page is the first page`);
|
514
|
+
return false;
|
515
|
+
};
|
516
|
+
await this.appManager.setMainViewSceneIndex(prevIndex);
|
517
|
+
return true;
|
518
|
+
} else {
|
519
|
+
return false;
|
520
|
+
}
|
521
|
+
}
|
522
|
+
|
523
|
+
public async addPage(params?: AddPageParams): Promise<void> {
|
524
|
+
if (this.appManager) {
|
525
|
+
const after = params?.after;
|
526
|
+
const scene = params?.scene;
|
527
|
+
if (after) {
|
528
|
+
const nextIndex = this.mainViewSceneIndex + 1;
|
529
|
+
this.room.putScenes(ROOT_DIR, [scene || {}], nextIndex);
|
530
|
+
} else {
|
531
|
+
this.room.putScenes(ROOT_DIR, [scene || {}]);
|
532
|
+
}
|
533
|
+
}
|
534
|
+
}
|
535
|
+
|
486
536
|
/**
|
487
537
|
* 返回 mainView 的 ScenePath
|
488
538
|
*/
|