@netless/window-manager 0.4.0-canary.3 → 0.4.0-canary.30
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/.idea/inspectionProfiles/Project_Default.xml +7 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/.idea/window-manager.iml +12 -0
- package/.vscode/settings.json +1 -0
- package/CHANGELOG.md +32 -1
- package/README.md +2 -0
- package/dist/App/MagixEvent/index.d.ts +29 -0
- package/dist/App/Storage/StorageEvent.d.ts +8 -0
- package/dist/App/Storage/index.d.ts +39 -0
- package/dist/App/Storage/typings.d.ts +22 -0
- package/dist/App/Storage/utils.d.ts +5 -0
- package/dist/AppContext.d.ts +40 -16
- package/dist/AppListener.d.ts +1 -1
- package/dist/AppManager.d.ts +26 -12
- package/dist/AppProxy.d.ts +7 -8
- package/dist/AttributesDelegate.d.ts +2 -2
- package/dist/BoxManager.d.ts +6 -3
- package/dist/BuiltinApps.d.ts +5 -0
- package/dist/ContainerResizeObserver.d.ts +10 -0
- package/dist/Cursor/Cursor.d.ts +10 -12
- package/dist/Cursor/index.d.ts +6 -16
- package/dist/Helper.d.ts +7 -0
- package/dist/ReconnectRefresher.d.ts +0 -1
- package/dist/Register/storage.d.ts +5 -1
- package/dist/Utils/AppCreateQueue.d.ts +11 -0
- package/dist/Utils/Common.d.ts +7 -2
- package/dist/Utils/Reactive.d.ts +1 -1
- package/dist/Utils/RoomHacker.d.ts +3 -3
- package/dist/{MainView.d.ts → View/MainView.d.ts} +5 -6
- package/dist/View/ViewManager.d.ts +13 -0
- package/dist/constants.d.ts +4 -7
- package/dist/index.d.ts +36 -14
- package/dist/index.es.js +41 -1
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +41 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/typings.d.ts +3 -2
- package/docs/api.md +69 -6
- package/docs/concept.md +9 -0
- package/docs/replay.md +40 -0
- package/package.json +7 -6
- package/src/App/MagixEvent/index.ts +68 -0
- package/src/App/Storage/StorageEvent.ts +21 -0
- package/src/App/Storage/index.ts +289 -0
- package/src/App/Storage/typings.ts +23 -0
- package/src/App/Storage/utils.ts +17 -0
- package/src/AppContext.ts +69 -24
- package/src/AppListener.ts +15 -14
- package/src/AppManager.ts +261 -83
- package/src/AppProxy.ts +53 -64
- package/src/AttributesDelegate.ts +2 -2
- package/src/BoxManager.ts +40 -24
- package/src/BuiltinApps.ts +23 -0
- package/src/ContainerResizeObserver.ts +62 -0
- package/src/Cursor/Cursor.svelte +25 -21
- package/src/Cursor/Cursor.ts +25 -38
- package/src/Cursor/icons.ts +2 -0
- package/src/Cursor/index.ts +45 -139
- package/src/Helper.ts +41 -0
- package/src/ReconnectRefresher.ts +0 -5
- package/src/Register/index.ts +25 -16
- package/src/Register/loader.ts +2 -2
- package/src/Register/storage.ts +6 -1
- package/src/Utils/AppCreateQueue.ts +54 -0
- package/src/Utils/Common.ts +69 -14
- package/src/Utils/Reactive.ts +9 -3
- package/src/Utils/RoomHacker.ts +44 -14
- package/src/{MainView.ts → View/MainView.ts} +25 -36
- package/src/View/ViewManager.ts +52 -0
- package/src/constants.ts +5 -4
- package/src/image/laser-pointer-cursor.svg +17 -0
- package/src/index.ts +158 -99
- package/src/shim.d.ts +5 -0
- package/src/style.css +7 -1
- package/src/typings.ts +3 -2
- package/vite.config.js +8 -2
- package/dist/Base/Context.d.ts +0 -13
- package/dist/Base/index.d.ts +0 -7
- package/dist/Utils/CameraStore.d.ts +0 -15
- package/dist/ViewManager.d.ts +0 -29
- package/dist/sdk.d.ts +0 -14
- package/src/Base/Context.ts +0 -49
- package/src/Base/index.ts +0 -10
- package/src/Utils/CameraStore.ts +0 -72
- package/src/sdk.ts +0 -39
- package/src/viewManager.ts +0 -177
@@ -0,0 +1,23 @@
|
|
1
|
+
import type { StorageEventListener } from "./StorageEvent";
|
2
|
+
|
3
|
+
export type RefValue<TValue = any> = { k: string; v: TValue; __isRef: true };
|
4
|
+
|
5
|
+
export type ExtractRawValue<TValue> = TValue extends RefValue<infer TRefValue> ? TRefValue : TValue;
|
6
|
+
|
7
|
+
export type AutoRefValue<TValue> = RefValue<ExtractRawValue<TValue>>;
|
8
|
+
|
9
|
+
export type MaybeRefValue<TValue> = TValue | AutoRefValue<TValue>;
|
10
|
+
|
11
|
+
export type DiffOne<T> = { oldValue?: T; newValue?: T };
|
12
|
+
|
13
|
+
export type Diff<T> = { [K in keyof T]?: DiffOne<T[K]> };
|
14
|
+
|
15
|
+
export type StorageOnSetStatePayload<TState = unknown> = {
|
16
|
+
[K in keyof TState]?: MaybeRefValue<TState[K]>;
|
17
|
+
};
|
18
|
+
|
19
|
+
export type StorageStateChangedEvent<TState = any> = Diff<TState>;
|
20
|
+
|
21
|
+
export type StorageStateChangedListener<TState = any> = StorageEventListener<StorageStateChangedEvent<TState>>;
|
22
|
+
|
23
|
+
export type StorageStateChangedListenerDisposer = () => void;
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import { has } from "lodash";
|
2
|
+
import { genUID } from "side-effect-manager";
|
3
|
+
import type { AutoRefValue, ExtractRawValue, RefValue } from "./typings";
|
4
|
+
|
5
|
+
export const plainObjectKeys = Object.keys as <T>(o: T) => Array<Extract<keyof T, string>>;
|
6
|
+
|
7
|
+
export function isRef<TValue = unknown>(e: unknown): e is RefValue<TValue> {
|
8
|
+
return Boolean(has(e, '__isRef'));
|
9
|
+
}
|
10
|
+
|
11
|
+
export function makeRef<TValue>(v: TValue): RefValue<TValue> {
|
12
|
+
return { k: genUID(), v, __isRef: true };
|
13
|
+
}
|
14
|
+
|
15
|
+
export function makeAutoRef<TValue>(v: TValue): AutoRefValue<TValue> {
|
16
|
+
return isRef<ExtractRawValue<TValue>>(v) ? v : makeRef(v as ExtractRawValue<TValue>);
|
17
|
+
}
|
package/src/AppContext.ts
CHANGED
@@ -6,18 +6,20 @@ import {
|
|
6
6
|
unlistenDisposed,
|
7
7
|
unlistenUpdated,
|
8
8
|
toJS
|
9
|
-
|
9
|
+
} from 'white-web-sdk';
|
10
10
|
import { BoxNotCreatedError } from './Utils/error';
|
11
|
-
import type { Room, SceneDefinition, View } from "white-web-sdk";
|
11
|
+
import type { Room, SceneDefinition, View, EventListener as WhiteEventListener } from "white-web-sdk";
|
12
12
|
import type { ReadonlyTeleBox } from "@netless/telebox-insider";
|
13
13
|
import type Emittery from "emittery";
|
14
14
|
import type { BoxManager } from "./BoxManager";
|
15
15
|
import type { AppEmitterEvent } from "./index";
|
16
16
|
import type { AppManager } from "./AppManager";
|
17
17
|
import type { AppProxy } from "./AppProxy";
|
18
|
+
import { Storage } from './App/Storage';
|
19
|
+
import type { MagixEventAddListener, MagixEventDispatcher, MagixEventRemoveListener } from './App/MagixEvent';
|
18
20
|
|
19
|
-
export class AppContext<
|
20
|
-
public readonly emitter: Emittery<AppEmitterEvent<
|
21
|
+
export class AppContext<TAttributes = any, TMagixEventPayloads = any, TAppOptions = any> {
|
22
|
+
public readonly emitter: Emittery<AppEmitterEvent<TAttributes>>;
|
21
23
|
public readonly mobxUtils = {
|
22
24
|
autorun,
|
23
25
|
reaction,
|
@@ -39,45 +41,45 @@ export class AppContext<TAttrs extends Record<string, any>, AppOptions = any> {
|
|
39
41
|
private boxManager: BoxManager,
|
40
42
|
public appId: string,
|
41
43
|
private appProxy: AppProxy,
|
42
|
-
private appOptions?:
|
44
|
+
private appOptions?: TAppOptions | (() => TAppOptions),
|
43
45
|
) {
|
44
46
|
this.emitter = appProxy.appEmitter;
|
45
47
|
this.isAddApp = appProxy.isAddApp;
|
46
48
|
}
|
47
49
|
|
48
|
-
public getDisplayer() {
|
50
|
+
public getDisplayer = () => {
|
49
51
|
return this.manager.displayer;
|
50
52
|
}
|
51
53
|
|
52
|
-
|
54
|
+
/** @deprecated Use context.storage.state instead. */
|
55
|
+
public getAttributes = (): TAttributes | undefined => {
|
53
56
|
return this.appProxy.attributes;
|
54
57
|
}
|
55
58
|
|
56
|
-
public getScenes(): SceneDefinition[] | undefined {
|
59
|
+
public getScenes = (): SceneDefinition[] | undefined => {
|
57
60
|
const appAttr = this.store.getAppAttributes(this.appId);
|
58
61
|
if (appAttr?.isDynamicPPT) {
|
59
|
-
|
60
|
-
if (appProxy) {
|
61
|
-
return appProxy.scenes;
|
62
|
-
}
|
62
|
+
return this.appProxy.scenes;
|
63
63
|
} else {
|
64
64
|
return appAttr?.options["scenes"];
|
65
65
|
}
|
66
66
|
}
|
67
67
|
|
68
|
-
public getView(): View | undefined {
|
68
|
+
public getView = (): View | undefined => {
|
69
69
|
return this.appProxy.view;
|
70
70
|
}
|
71
71
|
|
72
|
-
public getInitScenePath() {
|
72
|
+
public getInitScenePath = () => {
|
73
73
|
return this.manager.getAppInitPath(this.appId);
|
74
74
|
}
|
75
75
|
|
76
|
-
|
76
|
+
/** Get App writable status. */
|
77
|
+
public getIsWritable = (): boolean => {
|
77
78
|
return this.manager.canOperate;
|
78
79
|
}
|
79
80
|
|
80
|
-
|
81
|
+
/** Get the App Window UI box. */
|
82
|
+
public getBox = (): ReadonlyTeleBox => {
|
81
83
|
const box = this.boxManager.getBox(this.appId);
|
82
84
|
if (box) {
|
83
85
|
return box;
|
@@ -86,27 +88,30 @@ export class AppContext<TAttrs extends Record<string, any>, AppOptions = any> {
|
|
86
88
|
}
|
87
89
|
}
|
88
90
|
|
89
|
-
public getRoom(): Room | undefined {
|
91
|
+
public getRoom = (): Room | undefined => {
|
90
92
|
return this.manager.room;
|
91
93
|
}
|
92
94
|
|
93
|
-
|
95
|
+
/** @deprecated Use context.storage.setState instead. */
|
96
|
+
public setAttributes = (attributes: TAttributes) => {
|
94
97
|
this.manager.safeSetAttributes({ [this.appId]: attributes });
|
95
98
|
}
|
96
99
|
|
97
|
-
|
100
|
+
/** @deprecated Use context.storage.setState instead. */
|
101
|
+
public updateAttributes = (keys: string[], value: any) => {
|
98
102
|
if (this.manager.attributes[this.appId]) {
|
99
103
|
this.manager.safeUpdateAttributes([this.appId, ...keys], value);
|
100
104
|
}
|
101
105
|
}
|
102
106
|
|
103
|
-
public async
|
107
|
+
public setScenePath = async (scenePath: string): Promise<void> => {
|
104
108
|
if (!this.appProxy.box) return;
|
105
109
|
this.appProxy.setFullPath(scenePath);
|
106
|
-
|
110
|
+
// 兼容 15 版本 SDK 的切页
|
111
|
+
this.getRoom()?.setScenePath(scenePath);
|
107
112
|
}
|
108
113
|
|
109
|
-
public mountView(dom: HTMLDivElement): void {
|
114
|
+
public mountView = (dom: HTMLDivElement): void => {
|
110
115
|
const view = this.getView();
|
111
116
|
if (view) {
|
112
117
|
view.divElement = dom;
|
@@ -117,7 +122,47 @@ export class AppContext<TAttrs extends Record<string, any>, AppOptions = any> {
|
|
117
122
|
}
|
118
123
|
}
|
119
124
|
|
120
|
-
|
121
|
-
|
125
|
+
/** Get the local App options. */
|
126
|
+
public getAppOptions = (): TAppOptions | undefined => {
|
127
|
+
return typeof this.appOptions === 'function' ? (this.appOptions as () => TAppOptions)() : this.appOptions
|
122
128
|
}
|
129
|
+
|
130
|
+
private _storage?: Storage<TAttributes>
|
131
|
+
|
132
|
+
/** Main Storage for attributes. */
|
133
|
+
public get storage(): Storage<TAttributes> {
|
134
|
+
if (!this._storage) {
|
135
|
+
this._storage = new Storage(this);
|
136
|
+
}
|
137
|
+
return this._storage;
|
138
|
+
}
|
139
|
+
|
140
|
+
/**
|
141
|
+
* Create separated storages for flexible state management.
|
142
|
+
* @param storeId Namespace for the storage. Storages of the same namespace share the same data.
|
143
|
+
* @param defaultState Default state for initial storage creation.
|
144
|
+
* @returns
|
145
|
+
*/
|
146
|
+
public createStorage = <TState>(storeId: string, defaultState?: TState): Storage<TState> => {
|
147
|
+
const storage = new Storage(this, storeId, defaultState);
|
148
|
+
this.emitter.on("destroy", () => {
|
149
|
+
storage.destroy();
|
150
|
+
});
|
151
|
+
return storage;
|
152
|
+
}
|
153
|
+
|
154
|
+
/** Dispatch events to other clients (and self). */
|
155
|
+
public dispatchMagixEvent: MagixEventDispatcher<TMagixEventPayloads> = (...args) => {
|
156
|
+
// can't dispatch events on replay mode
|
157
|
+
return this.manager.room?.dispatchMagixEvent(...args);
|
158
|
+
}
|
159
|
+
|
160
|
+
/** Listen to events from others clients (and self messages). */
|
161
|
+
public addMagixEventListener: MagixEventAddListener<TMagixEventPayloads> = (event, handler, options) => {
|
162
|
+
this.manager.displayer.addMagixEventListener(event, handler as WhiteEventListener, options);
|
163
|
+
return () => this.manager.displayer.removeMagixEventListener(event, handler as WhiteEventListener);
|
164
|
+
}
|
165
|
+
|
166
|
+
/** Remove a Magix event listener. */
|
167
|
+
public removeMagixEventListener = this.manager.displayer.removeMagixEventListener.bind(this.manager.displayer) as MagixEventRemoveListener<TMagixEventPayloads>
|
123
168
|
}
|
package/src/AppListener.ts
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
import { callbacks } from
|
2
|
-
import { Events, MagixEventName } from
|
1
|
+
import { callbacks, emitter } from "./index";
|
2
|
+
import { Events, MagixEventName } from "./constants";
|
3
|
+
import { setViewFocusScenePath } from "./Utils/Common";
|
3
4
|
import type { Event } from "white-web-sdk";
|
4
5
|
import type { AppManager } from "./AppManager";
|
5
6
|
import type { TeleBoxState } from "@netless/telebox-insider";
|
6
|
-
import { setViewFocusScenePath } from './Utils/Common';
|
7
7
|
|
8
8
|
export class AppListeners {
|
9
9
|
private displayer = this.manager.displayer;
|
@@ -34,10 +34,6 @@ export class AppListeners {
|
|
34
34
|
this.appResizeHandler(data.payload);
|
35
35
|
break;
|
36
36
|
}
|
37
|
-
case Events.SwitchViewsToFreedom: {
|
38
|
-
this.switchViewsToFreedomHandler();
|
39
|
-
break;
|
40
|
-
}
|
41
37
|
case Events.AppBoxStateChange: {
|
42
38
|
this.boxStateChangeHandler(data.payload);
|
43
39
|
break;
|
@@ -50,6 +46,10 @@ export class AppListeners {
|
|
50
46
|
this.moveCameraToContainHandler(data.payload);
|
51
47
|
break;
|
52
48
|
}
|
49
|
+
case Events.CursorMove: {
|
50
|
+
this.cursorMoveHandler(data.payload);
|
51
|
+
break;
|
52
|
+
}
|
53
53
|
default:
|
54
54
|
break;
|
55
55
|
}
|
@@ -65,19 +65,20 @@ export class AppListeners {
|
|
65
65
|
this.manager.room?.refreshViewSize();
|
66
66
|
};
|
67
67
|
|
68
|
-
private switchViewsToFreedomHandler = () => {
|
69
|
-
this.manager.viewManager.freedomAllViews();
|
70
|
-
};
|
71
|
-
|
72
68
|
private boxStateChangeHandler = (state: TeleBoxState) => {
|
73
69
|
callbacks.emit("boxStateChange", state);
|
74
|
-
}
|
70
|
+
};
|
75
71
|
|
76
72
|
private setMainViewScenePathHandler = ({ nextScenePath }: { nextScenePath: string }) => {
|
77
73
|
setViewFocusScenePath(this.manager.mainView, nextScenePath);
|
78
|
-
|
74
|
+
callbacks.emit("mainViewScenePathChange", nextScenePath);
|
75
|
+
};
|
79
76
|
|
80
77
|
private moveCameraToContainHandler = (payload: any) => {
|
81
78
|
this.manager.mainView.moveCameraToContain(payload);
|
82
|
-
}
|
79
|
+
};
|
80
|
+
|
81
|
+
private cursorMoveHandler = (payload: any) => {
|
82
|
+
emitter.emit("cursorMove", payload);
|
83
|
+
};
|
83
84
|
}
|