@netless/window-manager 0.4.23 → 0.4.26
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 +13 -0
- package/__mocks__/white-web-sdk.ts +41 -0
- package/dist/App/AppProxy.d.ts +1 -0
- package/dist/ContainerResizeObserver.d.ts +2 -1
- package/dist/InternalEmitter.d.ts +3 -1
- package/dist/View/MainView.d.ts +3 -1
- package/dist/index.cjs.js +47 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +57 -12
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +10 -10
- package/dist/index.umd.js.map +1 -1
- package/docs/advanced.md +12 -4
- package/docs/api.md +9 -0
- package/package.json +6 -10
- package/pnpm-lock.yaml +793 -2690
- package/src/App/AppProxy.ts +6 -1
- package/src/ContainerResizeObserver.ts +12 -1
- package/src/InternalEmitter.ts +3 -1
- package/src/ReconnectRefresher.ts +4 -1
- package/src/View/MainView.ts +33 -8
- package/src/index.ts +10 -1
- package/vite.config.js +10 -2
package/src/App/AppProxy.ts
CHANGED
@@ -48,6 +48,7 @@ export class AppProxy {
|
|
48
48
|
private status: "normal" | "destroyed" = "normal";
|
49
49
|
private stateKey: string;
|
50
50
|
private _pageState: AppPageStateImpl;
|
51
|
+
private _prevFullPath: string | undefined;
|
51
52
|
|
52
53
|
public appResult?: NetlessApp<any>;
|
53
54
|
public appContext?: AppContext<any, any>;
|
@@ -348,7 +349,10 @@ export class AppProxy {
|
|
348
349
|
return autorun(() => {
|
349
350
|
const fullPath = this.appAttributes?.fullPath;
|
350
351
|
this.setFocusScenePathHandler(fullPath);
|
351
|
-
this.
|
352
|
+
if (this._prevFullPath !== fullPath) {
|
353
|
+
this.notifyPageStateChange();
|
354
|
+
this._prevFullPath = fullPath;
|
355
|
+
}
|
352
356
|
});
|
353
357
|
});
|
354
358
|
};
|
@@ -432,6 +436,7 @@ export class AppProxy {
|
|
432
436
|
this.manager.refresher?.remove(this.id);
|
433
437
|
this.manager.refresher?.remove(this.stateKey);
|
434
438
|
this.manager.refresher?.remove(`${this.id}-fullPath`);
|
439
|
+
this._prevFullPath = undefined;
|
435
440
|
}
|
436
441
|
|
437
442
|
public close(): Promise<void> {
|
@@ -1,11 +1,14 @@
|
|
1
1
|
import { ResizeObserver as ResizeObserverPolyfill } from "@juggle/resize-observer";
|
2
|
+
import { isFunction } from "lodash";
|
2
3
|
import { WindowManager } from "./index";
|
3
4
|
import type { EmitterType } from "./InternalEmitter";
|
5
|
+
import type { UnsubscribeFn } from "emittery";
|
4
6
|
|
5
7
|
const ResizeObserver = window.ResizeObserver || ResizeObserverPolyfill;
|
6
8
|
|
7
9
|
export class ContainerResizeObserver {
|
8
10
|
private containerResizeObserver?: ResizeObserver;
|
11
|
+
private disposer?: UnsubscribeFn;
|
9
12
|
|
10
13
|
constructor(private emitter: EmitterType) {}
|
11
14
|
|
@@ -35,10 +38,14 @@ export class ContainerResizeObserver {
|
|
35
38
|
}
|
36
39
|
});
|
37
40
|
|
41
|
+
this.disposer = this.emitter.on("containerSizeRatioUpdate", () => {
|
42
|
+
this.updateSizer(container.getBoundingClientRect(), sizer, wrapper);
|
43
|
+
});
|
44
|
+
|
38
45
|
this.containerResizeObserver.observe(container);
|
39
46
|
}
|
40
47
|
|
41
|
-
|
48
|
+
public updateSizer(
|
42
49
|
{ width, height }: DOMRectReadOnly,
|
43
50
|
sizer: HTMLElement,
|
44
51
|
wrapper: HTMLDivElement
|
@@ -58,5 +65,9 @@ export class ContainerResizeObserver {
|
|
58
65
|
|
59
66
|
public disconnect() {
|
60
67
|
this.containerResizeObserver?.disconnect();
|
68
|
+
if (isFunction(this.disposer)) {
|
69
|
+
this.disposer();
|
70
|
+
this.disposer = undefined;
|
71
|
+
}
|
61
72
|
}
|
62
73
|
}
|
package/src/InternalEmitter.ts
CHANGED
@@ -16,7 +16,8 @@ export type EmitterEvent = {
|
|
16
16
|
observerIdChange: number;
|
17
17
|
boxStateChange: string;
|
18
18
|
playgroundSizeChange: DOMRect;
|
19
|
-
|
19
|
+
startReconnect: undefined;
|
20
|
+
onReconnected: undefined;
|
20
21
|
removeScenes: string;
|
21
22
|
cursorMove: CursorMovePayload;
|
22
23
|
updateManagerRect: undefined;
|
@@ -25,6 +26,7 @@ export type EmitterEvent = {
|
|
25
26
|
setReadonly: boolean;
|
26
27
|
changePageState: undefined;
|
27
28
|
writableChange: boolean;
|
29
|
+
containerSizeRatioUpdate: number;
|
28
30
|
};
|
29
31
|
|
30
32
|
export type EmitterType = Emittery<EmitterEvent>;
|
@@ -29,6 +29,9 @@ export class ReconnectRefresher {
|
|
29
29
|
}
|
30
30
|
|
31
31
|
private onPhaseChanged = (phase: RoomPhase) => {
|
32
|
+
if (phase === RoomPhase.Reconnecting) {
|
33
|
+
this.ctx.emitter.emit("startReconnect");
|
34
|
+
}
|
32
35
|
if (phase === RoomPhase.Connected && this.phase === RoomPhase.Reconnecting) {
|
33
36
|
this.onReconnected();
|
34
37
|
}
|
@@ -47,7 +50,7 @@ export class ReconnectRefresher {
|
|
47
50
|
this.disposers.set(id, func());
|
48
51
|
}
|
49
52
|
});
|
50
|
-
this.ctx.emitter.emit("onReconnected"
|
53
|
+
this.ctx.emitter.emit("onReconnected");
|
51
54
|
}
|
52
55
|
|
53
56
|
private releaseDisposers() {
|
package/src/View/MainView.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { AnimationMode, reaction } from "white-web-sdk";
|
2
2
|
import { callbacks } from "../callback";
|
3
3
|
import { createView } from "./ViewManager";
|
4
|
-
import { debounce, isEmpty, isEqual } from "lodash";
|
4
|
+
import { debounce, get, isEmpty, isEqual } from "lodash";
|
5
5
|
import { emitter } from "../InternalEmitter";
|
6
6
|
import { Fields } from "../AttributesDelegate";
|
7
7
|
import { setViewFocusScenePath } from "../Utils/Common";
|
@@ -32,8 +32,15 @@ export class MainViewProxy {
|
|
32
32
|
this.sizeChangeHandler(this.mainViewSize);
|
33
33
|
};
|
34
34
|
this.sideEffectManager.add(() => {
|
35
|
-
emitter.on("playgroundSizeChange", playgroundSizeChangeListener);
|
36
|
-
|
35
|
+
return emitter.on("playgroundSizeChange", playgroundSizeChangeListener);
|
36
|
+
});
|
37
|
+
this.sideEffectManager.add(() => {
|
38
|
+
return emitter.on("containerSizeRatioUpdate", this.onUpdateContainerSizeRatio);
|
39
|
+
});
|
40
|
+
this.sideEffectManager.add(() => {
|
41
|
+
return emitter.on("startReconnect", () => {
|
42
|
+
this.mainView.release();
|
43
|
+
});
|
37
44
|
});
|
38
45
|
}
|
39
46
|
|
@@ -62,6 +69,10 @@ export class MainViewProxy {
|
|
62
69
|
return this.store.getMainViewSize();
|
63
70
|
}
|
64
71
|
|
72
|
+
private get didRelease(): boolean {
|
73
|
+
return get(this.view, ["didRelease"]);
|
74
|
+
}
|
75
|
+
|
65
76
|
private moveCameraSizeByAttributes() {
|
66
77
|
this.moveCameraToContian(this.mainViewSize);
|
67
78
|
this.moveCamera(this.mainViewCamera);
|
@@ -98,13 +109,21 @@ export class MainViewProxy {
|
|
98
109
|
);
|
99
110
|
};
|
100
111
|
|
101
|
-
|
112
|
+
public sizeChangeHandler = debounce((size: Size) => {
|
102
113
|
if (size) {
|
103
114
|
this.moveCameraToContian(size);
|
104
115
|
this.moveCamera(this.mainViewCamera);
|
105
116
|
}
|
106
117
|
}, 30);
|
107
118
|
|
119
|
+
public onUpdateContainerSizeRatio = () => {
|
120
|
+
const size = this.store.getMainViewSize();
|
121
|
+
this.sizeChangeHandler(size);
|
122
|
+
if (size.id === this.manager.uid) {
|
123
|
+
this.setCameraAndSize();
|
124
|
+
}
|
125
|
+
}
|
126
|
+
|
108
127
|
public get view(): View {
|
109
128
|
return this.mainView;
|
110
129
|
}
|
@@ -123,9 +142,13 @@ export class MainViewProxy {
|
|
123
142
|
}
|
124
143
|
|
125
144
|
public onReconnect(): void {
|
126
|
-
|
127
|
-
|
128
|
-
|
145
|
+
if (this.didRelease) {
|
146
|
+
this.rebind();
|
147
|
+
} else {
|
148
|
+
const mainViewScenePath = this.store.getMainViewScenePath();
|
149
|
+
if (mainViewScenePath) {
|
150
|
+
setViewFocusScenePath(this.view, mainViewScenePath);
|
151
|
+
}
|
129
152
|
}
|
130
153
|
}
|
131
154
|
|
@@ -133,7 +156,9 @@ export class MainViewProxy {
|
|
133
156
|
const divElement = this.mainView.divElement;
|
134
157
|
const disableCameraTransform = this.mainView.disableCameraTransform;
|
135
158
|
this.stop();
|
136
|
-
this.
|
159
|
+
if (!this.didRelease) {
|
160
|
+
this.mainView.release();
|
161
|
+
}
|
137
162
|
this.removeMainViewListener();
|
138
163
|
this.mainView = this.createMainView();
|
139
164
|
this.mainView.disableCameraTransform = disableCameraTransform;
|
package/src/index.ts
CHANGED
@@ -11,7 +11,7 @@ import { emitter } from "./InternalEmitter";
|
|
11
11
|
import { Fields } from "./AttributesDelegate";
|
12
12
|
import { initDb } from "./Register/storage";
|
13
13
|
import { InvisiblePlugin, isPlayer, isRoom, RoomPhase, ViewMode } from "white-web-sdk";
|
14
|
-
import { isEqual, isNull, isObject, omit } from "lodash";
|
14
|
+
import { isEqual, isNull, isObject, omit, isNumber } from "lodash";
|
15
15
|
import { log } from "./Utils/log";
|
16
16
|
import { PageStateImpl } from "./PageState";
|
17
17
|
import { ReconnectRefresher } from "./ReconnectRefresher";
|
@@ -893,6 +893,15 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> imple
|
|
893
893
|
this.appManager?.refresher?.refresh();
|
894
894
|
}
|
895
895
|
|
896
|
+
public setContainerSizeRatio(ratio: number) {
|
897
|
+
if (!isNumber(ratio)) {
|
898
|
+
throw new Error(`[WindowManager]: updateContainerSizeRatio error, ratio must be a number. but got ${ratio}`);
|
899
|
+
}
|
900
|
+
WindowManager.containerSizeRatio = ratio;
|
901
|
+
this.containerSizeRatio = ratio;
|
902
|
+
emitter.emit("containerSizeRatioUpdate", ratio);
|
903
|
+
}
|
904
|
+
|
896
905
|
private isDynamicPPT(scenes: SceneDefinition[]) {
|
897
906
|
const sceneSrc = scenes[0]?.ppt?.src;
|
898
907
|
return sceneSrc?.startsWith("pptx://");
|
package/vite.config.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import path from "path";
|
2
|
-
import { defineConfig } from
|
2
|
+
import { defineConfig } from 'vitest/config'
|
3
3
|
import { svelte } from "@sveltejs/vite-plugin-svelte";
|
4
4
|
import { dependencies, peerDependencies, version, devDependencies } from "./package.json"
|
5
5
|
import { omit } from "lodash";
|
@@ -8,6 +8,14 @@ export default defineConfig(({ mode }) => {
|
|
8
8
|
const isProd = mode === "production";
|
9
9
|
|
10
10
|
return {
|
11
|
+
test: {
|
12
|
+
environment: "jsdom",
|
13
|
+
deps: {
|
14
|
+
inline: [
|
15
|
+
"@juggle/resize-observer"
|
16
|
+
]
|
17
|
+
}
|
18
|
+
},
|
11
19
|
define: {
|
12
20
|
__APP_VERSION__: JSON.stringify(version),
|
13
21
|
__APP_DEPENDENCIES__: JSON.stringify({
|
@@ -26,7 +34,7 @@ export default defineConfig(({ mode }) => {
|
|
26
34
|
lib: {
|
27
35
|
// eslint-disable-next-line no-undef
|
28
36
|
entry: path.resolve(__dirname, "src/index.ts"),
|
29
|
-
formats: ["es", "umd"
|
37
|
+
formats: ["es", "umd", "cjs"],
|
30
38
|
name: "WindowManager",
|
31
39
|
fileName: "index"
|
32
40
|
},
|