@netless/window-manager 0.4.6 → 0.4.8
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 +4 -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 +7 -1
- 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 +2 -2
- package/docs/migrate.md +6 -3
- package/package.json +3 -3
- 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/Register/index.ts +1 -0
- package/src/View/MainView.ts +11 -0
- package/src/index.ts +11 -6
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/Register/index.ts
CHANGED
@@ -15,6 +15,7 @@ class AppRegister {
|
|
15
15
|
public appClasses: Map<string, () => Promise<NetlessApp>> = new Map();
|
16
16
|
|
17
17
|
public async register(params: RegisterParams): Promise<void> {
|
18
|
+
this.appClassesCache.delete(params.kind);
|
18
19
|
this.registered.set(params.kind, params);
|
19
20
|
|
20
21
|
const srcOrAppOrFunction = params.src;
|
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
@@ -138,6 +138,9 @@ export type EmitterEvent = {
|
|
138
138
|
onReconnected: void;
|
139
139
|
removeScenes: string;
|
140
140
|
cursorMove: CursorMovePayload;
|
141
|
+
updateManagerRect: undefined;
|
142
|
+
focusedChange: { focused: string | undefined, prev: string | undefined };
|
143
|
+
rootDirRemoved: undefined;
|
141
144
|
};
|
142
145
|
|
143
146
|
export type EmitterType = Emittery<EmitterEvent>;
|
@@ -180,7 +183,7 @@ export const callbacks: CallbacksType = new Emittery();
|
|
180
183
|
export const reconnectRefresher = new ReconnectRefresher({ emitter });
|
181
184
|
|
182
185
|
export type AddPageParams = {
|
183
|
-
|
186
|
+
after?: boolean;
|
184
187
|
scene?: SceneDefinition;
|
185
188
|
}
|
186
189
|
|
@@ -374,7 +377,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
374
377
|
}
|
375
378
|
}
|
376
379
|
}
|
377
|
-
|
380
|
+
emitter.emit("updateManagerRect");
|
378
381
|
this.appManager?.refresh();
|
379
382
|
this.appManager?.resetMaximized();
|
380
383
|
this.appManager?.resetMinimized();
|
@@ -519,11 +522,13 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
519
522
|
|
520
523
|
public async addPage(params?: AddPageParams): Promise<void> {
|
521
524
|
if (this.appManager) {
|
522
|
-
const
|
523
|
-
|
524
|
-
|
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);
|
525
530
|
} else {
|
526
|
-
this.room.putScenes(ROOT_DIR, [
|
531
|
+
this.room.putScenes(ROOT_DIR, [scene || {}]);
|
527
532
|
}
|
528
533
|
}
|
529
534
|
}
|