@netless/window-manager 0.4.0-canary.10 → 0.4.0-canary.14
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/dist/App/MagixEvent/index.d.ts +29 -0
- package/dist/App/Storage/index.d.ts +19 -6
- package/dist/App/Storage/typings.d.ts +1 -0
- package/dist/AppContext.d.ts +39 -17
- package/dist/AppManager.d.ts +1 -0
- package/dist/AppProxy.d.ts +1 -0
- package/dist/BoxManager.d.ts +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.es.js +1 -1
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/typings.d.ts +2 -2
- package/package.json +2 -2
- package/src/App/MagixEvent/index.ts +68 -0
- package/src/App/Storage/index.ts +89 -43
- package/src/App/Storage/typings.ts +4 -2
- package/src/AppContext.ts +57 -20
- package/src/AppManager.ts +14 -0
- package/src/AppProxy.ts +24 -11
- package/src/Utils/RoomHacker.ts +1 -0
- package/src/View/ViewManager.ts +1 -2
- package/src/index.ts +6 -1
- package/src/typings.ts +2 -2
@@ -0,0 +1,29 @@
|
|
1
|
+
import type { MagixEventListenerOptions as WhiteMagixListenerOptions, Event as WhiteEvent, EventPhase as WhiteEventPhase, Scope as WhiteScope } from "white-web-sdk";
|
2
|
+
export interface MagixEventListenerOptions extends WhiteMagixListenerOptions {
|
3
|
+
/**
|
4
|
+
* Rapid emitted callbacks will be slowed down to this interval (in ms).
|
5
|
+
*/
|
6
|
+
fireInterval?: number;
|
7
|
+
/**
|
8
|
+
* If `true`, sent events will reach self-listeners after committed to server.
|
9
|
+
* Otherwise the events will reach self-listeners immediately.
|
10
|
+
*/
|
11
|
+
fireSelfEventAfterCommit?: boolean;
|
12
|
+
}
|
13
|
+
export interface MagixEventMessage<TPayloads = any, TEvent extends MagixEventTypes<TPayloads> = MagixEventTypes<TPayloads>> extends Omit<WhiteEvent, "scope" | "phase"> {
|
14
|
+
/** Event name */
|
15
|
+
event: TEvent;
|
16
|
+
/** Event Payload */
|
17
|
+
payload: TPayloads[TEvent];
|
18
|
+
/** Whiteboard ID of the client who dispatched the event. It will be AdminObserverId for system events. */
|
19
|
+
authorId: number;
|
20
|
+
scope: `${WhiteScope}`;
|
21
|
+
phase: `${WhiteEventPhase}`;
|
22
|
+
}
|
23
|
+
export declare type MagixEventTypes<TPayloads = any> = Extract<keyof TPayloads, string>;
|
24
|
+
export declare type MagixEventPayload<TPayloads = any, TEvent extends MagixEventTypes<TPayloads> = MagixEventTypes<TPayloads>> = TPayloads[TEvent];
|
25
|
+
export declare type MagixEventDispatcher<TPayloads = any> = <TEvent extends MagixEventTypes<TPayloads> = MagixEventTypes<TPayloads>>(event: TEvent, payload: TPayloads[TEvent]) => void;
|
26
|
+
export declare type MagixEventHandler<TPayloads = any, TEvent extends MagixEventTypes<TPayloads> = MagixEventTypes<TPayloads>> = (message: MagixEventMessage<TPayloads, TEvent>) => void;
|
27
|
+
export declare type MagixEventListenerDisposer = () => void;
|
28
|
+
export declare type MagixEventAddListener<TPayloads = any> = <TEvent extends MagixEventTypes<TPayloads> = MagixEventTypes<TPayloads>>(event: TEvent, handler: MagixEventHandler<TPayloads, TEvent>, options?: MagixEventListenerOptions | undefined) => MagixEventListenerDisposer;
|
29
|
+
export declare type MagixEventRemoveListener<TPayloads = any> = <TEvent extends MagixEventTypes<TPayloads> = MagixEventTypes<TPayloads>>(event: TEvent, handler?: MagixEventHandler<TPayloads, TEvent>) => void;
|
@@ -1,9 +1,10 @@
|
|
1
1
|
import type { AppContext } from "../../AppContext";
|
2
|
-
import type { Diff } from "./typings";
|
2
|
+
import type { Diff, StorageStateChangedListener, StorageStateChangedListenerDisposer } from "./typings";
|
3
3
|
import { StorageEvent } from "./StorageEvent";
|
4
4
|
export * from './typings';
|
5
|
-
export declare
|
6
|
-
|
5
|
+
export declare const STORAGE_NS = "_WM-STORAGE_";
|
6
|
+
export declare class Storage<TState extends Record<string, any> = any> implements Storage<TState> {
|
7
|
+
readonly id: string | null;
|
7
8
|
private readonly _context;
|
8
9
|
private readonly _sideEffect;
|
9
10
|
private _state;
|
@@ -13,14 +14,26 @@ export declare class Storage<TState = any> implements Storage<TState> {
|
|
13
14
|
* `setState` alters local state immediately before sending to server. This will cache the old value for onStateChanged diffing.
|
14
15
|
*/
|
15
16
|
private _lastValue;
|
16
|
-
constructor(context: AppContext
|
17
|
+
constructor(context: AppContext, id?: string, defaultState?: TState);
|
17
18
|
get state(): Readonly<TState>;
|
18
19
|
readonly onStateChanged: StorageEvent<Diff<TState>>;
|
20
|
+
addStateChangedListener(handler: StorageStateChangedListener<TState>): StorageStateChangedListenerDisposer;
|
19
21
|
ensureState(state: Partial<TState>): void;
|
20
22
|
setState(state: Partial<TState>): void;
|
21
|
-
|
22
|
-
|
23
|
+
/**
|
24
|
+
* Empty storage data.
|
25
|
+
*/
|
26
|
+
emptyStorage(): void;
|
27
|
+
/**
|
28
|
+
* Delete storage index with all of its data and destroy the Storage instance.
|
29
|
+
*/
|
30
|
+
deleteStorage(): void;
|
23
31
|
get destroyed(): boolean;
|
32
|
+
/**
|
33
|
+
* Destroy the Storage instance. The data will be kept.
|
34
|
+
*/
|
24
35
|
destroy(): void;
|
36
|
+
private _getRawState;
|
37
|
+
private _setRawState;
|
25
38
|
private _updateProperties;
|
26
39
|
}
|
@@ -19,3 +19,4 @@ export declare type StorageOnSetStatePayload<TState = unknown> = {
|
|
19
19
|
};
|
20
20
|
export declare type StorageStateChangedEvent<TState = any> = Diff<TState>;
|
21
21
|
export declare type StorageStateChangedListener<TState = any> = StorageEventListener<StorageStateChangedEvent<TState>>;
|
22
|
+
export declare type StorageStateChangedListenerDisposer = () => void;
|
package/dist/AppContext.d.ts
CHANGED
@@ -7,13 +7,14 @@ import type { AppEmitterEvent } from "./index";
|
|
7
7
|
import type { AppManager } from "./AppManager";
|
8
8
|
import type { AppProxy } from "./AppProxy";
|
9
9
|
import { Storage } from './App/Storage';
|
10
|
-
|
10
|
+
import type { MagixEventAddListener, MagixEventDispatcher, MagixEventRemoveListener } from './App/MagixEvent';
|
11
|
+
export declare class AppContext<TAttributes = any, TMagixEventPayloads = any, TAppOptions = any> {
|
11
12
|
private manager;
|
12
13
|
private boxManager;
|
13
14
|
appId: string;
|
14
15
|
private appProxy;
|
15
16
|
private appOptions?;
|
16
|
-
readonly emitter: Emittery<AppEmitterEvent<
|
17
|
+
readonly emitter: Emittery<AppEmitterEvent<TAttributes>>;
|
17
18
|
readonly mobxUtils: {
|
18
19
|
autorun: typeof autorun;
|
19
20
|
reaction: typeof reaction;
|
@@ -28,19 +29,40 @@ export declare class AppContext<TAttrs extends Record<string, any> = any, AppOpt
|
|
28
29
|
private store;
|
29
30
|
readonly isAddApp: boolean;
|
30
31
|
readonly isReplay: boolean;
|
31
|
-
constructor(manager: AppManager, boxManager: BoxManager, appId: string, appProxy: AppProxy, appOptions?:
|
32
|
-
getDisplayer()
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
32
|
+
constructor(manager: AppManager, boxManager: BoxManager, appId: string, appProxy: AppProxy, appOptions?: TAppOptions | (() => TAppOptions) | undefined);
|
33
|
+
getDisplayer: () => import("white-web-sdk").Displayer<import("white-web-sdk").DisplayerCallbacks>;
|
34
|
+
/** @deprecated Use context.storage.state instead. */
|
35
|
+
getAttributes: () => TAttributes | undefined;
|
36
|
+
getScenes: () => SceneDefinition[] | undefined;
|
37
|
+
getView: () => View | undefined;
|
38
|
+
getInitScenePath: () => string | undefined;
|
39
|
+
/** Get App writable status. */
|
40
|
+
getIsWritable: () => boolean;
|
41
|
+
/** Get the App Window UI box. */
|
42
|
+
getBox: () => ReadonlyTeleBox;
|
43
|
+
getRoom: () => Room | undefined;
|
44
|
+
/** @deprecated Use context.storage.setState instead. */
|
45
|
+
setAttributes: (attributes: TAttributes) => void;
|
46
|
+
/** @deprecated Use context.storage.setState instead. */
|
47
|
+
updateAttributes: (keys: string[], value: any) => void;
|
48
|
+
setScenePath: (scenePath: string) => Promise<void>;
|
49
|
+
mountView: (dom: HTMLDivElement) => void;
|
50
|
+
/** Get the local App options. */
|
51
|
+
getAppOptions: () => TAppOptions | undefined;
|
52
|
+
private _storage?;
|
53
|
+
/** Main Storage for attributes. */
|
54
|
+
get storage(): Storage<TAttributes>;
|
55
|
+
/**
|
56
|
+
* Create separated storages for flexible state management.
|
57
|
+
* @param storeId Namespace for the storage. Storages of the same namespace share the same data.
|
58
|
+
* @param defaultState Default state for initial storage creation.
|
59
|
+
* @returns
|
60
|
+
*/
|
61
|
+
createStorage: <TState>(storeId: string, defaultState?: TState | undefined) => Storage<TState>;
|
62
|
+
/** Dispatch events to other clients (and self). */
|
63
|
+
dispatchMagixEvent: MagixEventDispatcher<TMagixEventPayloads>;
|
64
|
+
/** Listen to events from others clients (and self messages). */
|
65
|
+
addMagixEventListener: MagixEventAddListener<TMagixEventPayloads>;
|
66
|
+
/** Remove a Magix event listener. */
|
67
|
+
removeMagixEventListener: MagixEventRemoveListener<TMagixEventPayloads>;
|
46
68
|
}
|
package/dist/AppManager.d.ts
CHANGED
package/dist/AppProxy.d.ts
CHANGED
@@ -47,6 +47,7 @@ export declare class AppProxy extends Base {
|
|
47
47
|
emitAppIsWritableChange(): void;
|
48
48
|
private makeAppEventListener;
|
49
49
|
private appAttributesUpdateListener;
|
50
|
+
private setFocusScenePathHandler;
|
50
51
|
setScenePath(): void;
|
51
52
|
setViewFocusScenePath(): void;
|
52
53
|
private createView;
|
package/dist/BoxManager.d.ts
CHANGED
@@ -59,7 +59,7 @@ export declare class BoxManager {
|
|
59
59
|
private playgroundSizeChangeListener;
|
60
60
|
private get mainView();
|
61
61
|
private get canOperate();
|
62
|
-
get boxState(): "
|
62
|
+
get boxState(): "normal" | "minimized" | "maximized";
|
63
63
|
get maximized(): boolean;
|
64
64
|
get minimized(): boolean;
|
65
65
|
get darkMode(): boolean;
|
package/dist/index.d.ts
CHANGED
@@ -104,6 +104,7 @@ export declare type PublicEvent = {
|
|
104
104
|
cameraStateChange: CameraState;
|
105
105
|
mainViewScenePathChange: string;
|
106
106
|
mainViewSceneIndexChange: number;
|
107
|
+
focusedChange: string | undefined;
|
107
108
|
};
|
108
109
|
export declare type MountParams = {
|
109
110
|
room: Room;
|
@@ -198,6 +199,7 @@ export declare class WindowManager extends InvisiblePlugin<WindowMangerAttribute
|
|
198
199
|
get darkMode(): boolean;
|
199
200
|
get prefersColorScheme(): TeleBoxColorScheme | undefined;
|
200
201
|
get focused(): string | undefined;
|
202
|
+
get mainViewSceneIndex(): number;
|
201
203
|
/**
|
202
204
|
* 查询所有的 App
|
203
205
|
*/
|