@netless/window-manager 0.4.0-canary.5 → 0.4.0-canary.9

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.
Files changed (57) hide show
  1. package/dist/App/Storage/StorageEvent.d.ts +8 -0
  2. package/dist/App/Storage/index.d.ts +26 -0
  3. package/dist/App/Storage/typings.d.ts +21 -0
  4. package/dist/App/Storage/utils.d.ts +5 -0
  5. package/dist/AppContext.d.ts +3 -1
  6. package/dist/AppListener.d.ts +0 -1
  7. package/dist/AppManager.d.ts +5 -5
  8. package/dist/AppProxy.d.ts +2 -3
  9. package/dist/Base/Context.d.ts +0 -1
  10. package/dist/BoxManager.d.ts +2 -1
  11. package/dist/BuiltinApps.d.ts +6 -0
  12. package/dist/ContainerResizeObserver.d.ts +10 -0
  13. package/dist/Helper.d.ts +6 -0
  14. package/dist/Utils/Common.d.ts +3 -1
  15. package/dist/Utils/Reactive.d.ts +1 -1
  16. package/dist/{MainView.d.ts → View/MainView.d.ts} +2 -4
  17. package/dist/View/ViewManager.d.ts +13 -0
  18. package/dist/constants.d.ts +1 -6
  19. package/dist/index.d.ts +5 -10
  20. package/dist/index.es.js +1 -1
  21. package/dist/index.es.js.map +1 -1
  22. package/dist/index.umd.js +1 -1
  23. package/dist/index.umd.js.map +1 -1
  24. package/dist/style.css +1 -1
  25. package/dist/typings.d.ts +1 -0
  26. package/package.json +3 -3
  27. package/src/App/Storage/StorageEvent.ts +21 -0
  28. package/src/App/Storage/index.ts +243 -0
  29. package/src/App/Storage/typings.ts +21 -0
  30. package/src/App/Storage/utils.ts +17 -0
  31. package/src/AppContext.ts +10 -2
  32. package/src/AppListener.ts +1 -8
  33. package/src/AppManager.ts +45 -27
  34. package/src/AppProxy.ts +14 -36
  35. package/src/Base/Context.ts +0 -4
  36. package/src/BoxManager.ts +9 -7
  37. package/src/BuiltinApps.ts +24 -0
  38. package/src/ContainerResizeObserver.ts +62 -0
  39. package/src/Helper.ts +30 -0
  40. package/src/ReconnectRefresher.ts +0 -1
  41. package/src/Utils/Common.ts +35 -13
  42. package/src/Utils/Reactive.ts +9 -3
  43. package/src/Utils/RoomHacker.ts +15 -0
  44. package/src/{MainView.ts → View/MainView.ts} +7 -25
  45. package/src/View/ViewManager.ts +53 -0
  46. package/src/constants.ts +1 -3
  47. package/src/index.ts +19 -71
  48. package/src/shim.d.ts +4 -0
  49. package/src/style.css +6 -0
  50. package/src/typings.ts +1 -0
  51. package/vite.config.js +4 -1
  52. package/dist/Utils/CameraStore.d.ts +0 -15
  53. package/dist/ViewManager.d.ts +0 -29
  54. package/dist/sdk.d.ts +0 -14
  55. package/src/Utils/CameraStore.ts +0 -72
  56. package/src/sdk.ts +0 -39
  57. package/src/viewManager.ts +0 -177
@@ -0,0 +1,8 @@
1
+ export declare type StorageEventListener<T> = (event: T) => void;
2
+ export declare class StorageEvent<TMessage> {
3
+ listeners: Set<StorageEventListener<TMessage>>;
4
+ get length(): number;
5
+ dispatch(message: TMessage): void;
6
+ addListener(listener: StorageEventListener<TMessage>): void;
7
+ removeListener(listener: StorageEventListener<TMessage>): void;
8
+ }
@@ -0,0 +1,26 @@
1
+ import type { AppContext } from "../../AppContext";
2
+ import type { Diff } from "./typings";
3
+ import { StorageEvent } from "./StorageEvent";
4
+ export * from './typings';
5
+ export declare class Storage<TState = any> implements Storage<TState> {
6
+ readonly id: string;
7
+ private readonly _context;
8
+ private readonly _sideEffect;
9
+ private _state;
10
+ private _destroyed;
11
+ private _refMap;
12
+ /**
13
+ * `setState` alters local state immediately before sending to server. This will cache the old value for onStateChanged diffing.
14
+ */
15
+ private _lastValue;
16
+ constructor(context: AppContext<any>, id: string, defaultState?: TState);
17
+ get state(): Readonly<TState>;
18
+ readonly onStateChanged: StorageEvent<Diff<TState>>;
19
+ ensureState(state: Partial<TState>): void;
20
+ setState(state: Partial<TState>): void;
21
+ emptyStore(): void;
22
+ deleteStore(): void;
23
+ get destroyed(): boolean;
24
+ destroy(): void;
25
+ private _updateProperties;
26
+ }
@@ -0,0 +1,21 @@
1
+ import type { StorageEventListener } from "./StorageEvent";
2
+ export declare type RefValue<TValue = any> = {
3
+ k: string;
4
+ v: TValue;
5
+ __isRef: true;
6
+ };
7
+ export declare type ExtractRawValue<TValue> = TValue extends RefValue<infer TRefValue> ? TRefValue : TValue;
8
+ export declare type AutoRefValue<TValue> = RefValue<ExtractRawValue<TValue>>;
9
+ export declare type MaybeRefValue<TValue> = TValue | AutoRefValue<TValue>;
10
+ export declare type DiffOne<T> = {
11
+ oldValue?: T;
12
+ newValue?: T;
13
+ };
14
+ export declare type Diff<T> = {
15
+ [K in keyof T]?: DiffOne<T[K]>;
16
+ };
17
+ export declare type StorageOnSetStatePayload<TState = unknown> = {
18
+ [K in keyof TState]?: MaybeRefValue<TState[K]>;
19
+ };
20
+ export declare type StorageStateChangedEvent<TState = any> = Diff<TState>;
21
+ export declare type StorageStateChangedListener<TState = any> = StorageEventListener<StorageStateChangedEvent<TState>>;
@@ -0,0 +1,5 @@
1
+ import type { AutoRefValue, RefValue } from "./typings";
2
+ export declare const plainObjectKeys: <T>(o: T) => Extract<keyof T, string>[];
3
+ export declare function isRef<TValue = unknown>(e: unknown): e is RefValue<TValue>;
4
+ export declare function makeRef<TValue>(v: TValue): RefValue<TValue>;
5
+ export declare function makeAutoRef<TValue>(v: TValue): AutoRefValue<TValue>;
@@ -6,7 +6,8 @@ import type { BoxManager } from "./BoxManager";
6
6
  import type { AppEmitterEvent } from "./index";
7
7
  import type { AppManager } from "./AppManager";
8
8
  import type { AppProxy } from "./AppProxy";
9
- export declare class AppContext<TAttrs extends Record<string, any>, AppOptions = any> {
9
+ import { Storage } from './App/Storage';
10
+ export declare class AppContext<TAttrs extends Record<string, any> = any, AppOptions = any> {
10
11
  private manager;
11
12
  private boxManager;
12
13
  appId: string;
@@ -41,4 +42,5 @@ export declare class AppContext<TAttrs extends Record<string, any>, AppOptions =
41
42
  setScenePath(scenePath: string): Promise<void>;
42
43
  mountView(dom: HTMLDivElement): void;
43
44
  getAppOptions(): AppOptions | undefined;
45
+ createStorage<TState>(storeId: string, defaultState?: TState): Storage<TState>;
44
46
  }
@@ -9,7 +9,6 @@ export declare class AppListeners {
9
9
  private mainMagixEventListener;
10
10
  private appMoveHandler;
11
11
  private appResizeHandler;
12
- private switchViewsToFreedomHandler;
13
12
  private boxStateChangeHandler;
14
13
  private setMainViewScenePathHandler;
15
14
  private moveCameraToContainHandler;
@@ -1,9 +1,8 @@
1
1
  import { AppStatus, Events } from "./constants";
2
2
  import { AppProxy } from "./AppProxy";
3
3
  import { WindowManager } from "./index";
4
- import { CameraStore } from "./Utils/CameraStore";
5
- import { MainViewProxy } from "./MainView";
6
- import { ViewManager } from "./ViewManager";
4
+ import { MainViewProxy } from "./View/MainView";
5
+ import { ViewManager } from "./View/ViewManager";
7
6
  import type { ReconnectRefresher } from "./ReconnectRefresher";
8
7
  import type { BoxManager } from "./BoxManager";
9
8
  import type { Displayer, Room } from "white-web-sdk";
@@ -11,7 +10,6 @@ import type { AddAppParams, TeleBoxRect } from "./index";
11
10
  export declare class AppManager {
12
11
  windowManger: WindowManager;
13
12
  displayer: Displayer;
14
- cameraStore: CameraStore;
15
13
  viewManager: ViewManager;
16
14
  appProxies: Map<string, AppProxy>;
17
15
  appStatus: Map<string, AppStatus>;
@@ -21,6 +19,7 @@ export declare class AppManager {
21
19
  isReplay: boolean;
22
20
  private appListeners;
23
21
  boxManager?: BoxManager;
22
+ private _prevSceneIndex;
24
23
  constructor(windowManger: WindowManager);
25
24
  private onCreated;
26
25
  /**
@@ -36,13 +35,14 @@ export declare class AppManager {
36
35
  resetMinimized(): void;
37
36
  private onAppDelete;
38
37
  bindMainView(divElement: HTMLDivElement, disableCameraTransform: boolean): void;
38
+ setMainViewFocusPath(): void;
39
39
  addApp(params: AddAppParams, isDynamicPPT: boolean): Promise<string | undefined>;
40
40
  private beforeAddApp;
41
41
  private afterAddApp;
42
42
  closeApp(appId: string): Promise<void>;
43
43
  private baseInsertApp;
44
44
  private displayerStateListener;
45
- private displayerWritableListener;
45
+ displayerWritableListener: (isReadonly: boolean) => void;
46
46
  private get eventName();
47
47
  get attributes(): import("./index").WindowMangerAttributes;
48
48
  get canOperate(): boolean;
@@ -15,7 +15,6 @@ export declare class AppProxy extends Base {
15
15
  private boxManager;
16
16
  private appProxies;
17
17
  private viewManager;
18
- private cameraStore;
19
18
  private kind;
20
19
  isAddApp: boolean;
21
20
  private status;
@@ -29,8 +28,9 @@ export declare class AppProxy extends Base {
29
28
  get attributes(): any;
30
29
  get appAttributes(): import("./index").AppSyncAttributes;
31
30
  getFullScenePath(): string | undefined;
31
+ private getFullScenePathFromScenes;
32
32
  setFullPath(path: string): void;
33
- baseInsertApp(skipUpdate?: boolean, focus?: boolean): Promise<{
33
+ baseInsertApp(skipUpdate?: boolean): Promise<{
34
34
  appId: string;
35
35
  app: NetlessApp;
36
36
  }>;
@@ -42,7 +42,6 @@ export declare class AppProxy extends Base {
42
42
  private afterSetupApp;
43
43
  onSeek(time: number): void;
44
44
  onReconnected(): Promise<void>;
45
- switchToWritable(): void;
46
45
  getAppInitState: (id: string) => AppInitState | undefined;
47
46
  emitAppSceneStateChange(sceneState: SceneState): void;
48
47
  emitAppIsWritableChange(): void;
@@ -8,6 +8,5 @@ export declare class Context {
8
8
  findMemberByUid: (uid: string) => import("white-web-sdk").RoomMember | undefined;
9
9
  updateManagerRect(): void;
10
10
  blurFocusBox(): void;
11
- switchAppToWriter(id: string): void;
12
11
  }
13
12
  export declare const createContext: (manager: AppManager) => Context;
@@ -56,9 +56,10 @@ export declare class BoxManager {
56
56
  private createTeleBoxManagerConfig?;
57
57
  teleBoxManager: TeleBoxManager;
58
58
  constructor(context: BoxManagerContext, createTeleBoxManagerConfig?: CreateTeleBoxManagerConfig | undefined);
59
+ private playgroundSizeChangeListener;
59
60
  private get mainView();
60
61
  private get canOperate();
61
- get boxState(): "normal" | "minimized" | "maximized";
62
+ get boxState(): "minimized" | "maximized" | "normal";
62
63
  get maximized(): boolean;
63
64
  get minimized(): boolean;
64
65
  get darkMode(): boolean;
@@ -0,0 +1,6 @@
1
+ import "@netless/app-docs-viewer/dist/style.css";
2
+ export declare const setupBuiltin: () => void;
3
+ export declare const BuiltinApps: {
4
+ DocsViewer: string;
5
+ MediaPlayer: string;
6
+ };
@@ -0,0 +1,10 @@
1
+ import type { EmitterType } from "./index";
2
+ export declare class ContainerResizeObserver {
3
+ private emitter;
4
+ private containerResizeObserver?;
5
+ constructor(emitter: EmitterType);
6
+ static create(container: HTMLElement, sizer: HTMLElement, wrapper: HTMLDivElement, emitter: EmitterType): ContainerResizeObserver;
7
+ observePlaygroundSize(container: HTMLElement, sizer: HTMLElement, wrapper: HTMLDivElement): void;
8
+ private updateSizer;
9
+ disconnect(): void;
10
+ }
@@ -0,0 +1,6 @@
1
+ export declare const setupWrapper: (root: HTMLElement) => {
2
+ playground: HTMLDivElement;
3
+ wrapper: HTMLDivElement;
4
+ sizer: HTMLDivElement;
5
+ mainViewElement: HTMLDivElement;
6
+ };
@@ -4,11 +4,13 @@ import type Emittery from "emittery";
4
4
  export declare const genAppId: (kind: string) => Promise<string>;
5
5
  export declare const setViewFocusScenePath: (view: View, focusScenePath: string) => void;
6
6
  export declare const setScenePath: (room: Room | undefined, scenePath: string) => void;
7
+ export declare const getScenePath: (room: Room | undefined, dir: string | undefined, index: number) => string | undefined;
7
8
  export declare const setViewMode: (view: View, mode: ViewVisionMode) => void;
8
9
  export declare const emitError: (error: Error) => void;
9
10
  export declare const addEmitterOnceListener: (event: any, listener: any) => void;
10
11
  export declare const notifyMainViewModeChange: import("lodash").DebouncedFunc<(callbacks: Emittery<PublicEvent>, mode: ViewVisionMode) => void>;
11
- export declare const makeValidScenePath: (displayer: Displayer, scenePath: string) => string;
12
+ export declare const makeValidScenePath: (displayer: Displayer, scenePath: string, index?: number) => string | undefined;
13
+ export declare const entireScenes: (displayer: Displayer) => import("white-web-sdk").SceneMap;
12
14
  export declare const isValidScenePath: (scenePath: string) => boolean;
13
15
  export declare const ensureValidScenePath: (scenePath: string) => string;
14
16
  export declare const getVersionNumber: (version: string) => number;
@@ -1,6 +1,6 @@
1
1
  import { UpdateEventKind } from "white-web-sdk";
2
2
  import type { AkkoObjectUpdatedListener } from "white-web-sdk";
3
3
  export declare const onObjectByEvent: (event: UpdateEventKind) => (object: any, func: () => void) => (() => void) | undefined;
4
- export declare const safeListenPropsUpdated: <T>(getProps: () => T, callback: AkkoObjectUpdatedListener<T>) => () => void;
4
+ export declare const safeListenPropsUpdated: <T>(getProps: () => T, callback: AkkoObjectUpdatedListener<T>, onDestroyed?: ((props: unknown) => void) | undefined) => () => void;
5
5
  export declare const onObjectRemoved: (object: any, func: () => void) => (() => void) | undefined;
6
6
  export declare const onObjectInserted: (object: any, func: () => void) => (() => void) | undefined;
@@ -1,9 +1,8 @@
1
- import { Base } from "./Base";
1
+ import { Base } from "../Base";
2
2
  import type { Camera, Size, View } from "white-web-sdk";
3
- import type { AppManager } from "./AppManager";
3
+ import type { AppManager } from "../AppManager";
4
4
  export declare class MainViewProxy extends Base {
5
5
  private scale?;
6
- private cameraStore;
7
6
  private started;
8
7
  private mainViewIsAddListener;
9
8
  private mainView;
@@ -35,7 +34,6 @@ export declare class MainViewProxy extends Base {
35
34
  private addCameraListener;
36
35
  private removeCameraListener;
37
36
  private onCameraOrSizeUpdated;
38
- switchViewModeToWriter(): void;
39
37
  moveCameraToContian(size: Size): void;
40
38
  moveCamera(camera: Camera): void;
41
39
  stop(): void;
@@ -0,0 +1,13 @@
1
+ import type { View, Displayer } from "white-web-sdk";
2
+ export declare class ViewManager {
3
+ private displayer;
4
+ views: Map<string, View>;
5
+ constructor(displayer: Displayer);
6
+ createView(id: string): View;
7
+ getView(id: string): View | undefined;
8
+ destroyView(id: string): void;
9
+ setViewScenePath(id: string, scenePath: string): void;
10
+ destroy(): void;
11
+ }
12
+ export declare const createView: (displayer: Displayer) => View;
13
+ export declare const setDefaultCameraBound: (view: View) => void;
@@ -31,13 +31,8 @@ export declare enum CursorState {
31
31
  Leave = "leave",
32
32
  Normal = "normal"
33
33
  }
34
- export declare const REQUIRE_VERSION = "2.13.16";
34
+ export declare const REQUIRE_VERSION = "2.16.0";
35
35
  export declare const MIN_WIDTH: number;
36
36
  export declare const MIN_HEIGHT: number;
37
37
  export declare const SET_SCENEPATH_DELAY = 100;
38
- export declare const DEFAULT_COLLECTOR_STYLE: {
39
- right: string;
40
- bottom: string;
41
- position: string;
42
- };
43
38
  export declare const DEFAULT_CONTAINER_RATIO: number;
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import Emittery from "emittery";
2
2
  import { AppManager } from "./AppManager";
3
3
  import { CursorManager } from "./Cursor";
4
+ import { ReconnectRefresher } from "./ReconnectRefresher";
4
5
  import "./style.css";
5
6
  import "@netless/telebox-insider/dist/style.css";
6
- import "@netless/app-docs-viewer/dist/style.css";
7
7
  import type { TELE_BOX_STATE } from "./BoxManager";
8
8
  import type { Apps } from "./AttributesDelegate";
9
9
  import { InvisiblePlugin, ViewMode } from "white-web-sdk";
@@ -12,7 +12,6 @@ import type { AppListeners } from "./AppListener";
12
12
  import type { NetlessApp, RegisterParams } from "./typings";
13
13
  import type { TeleBoxColorScheme, TeleBoxState } from "@netless/telebox-insider";
14
14
  import type { AppProxy } from "./AppProxy";
15
- import { ReconnectRefresher } from "./ReconnectRefresher";
16
15
  export declare type WindowMangerAttributes = {
17
16
  modelValue?: string;
18
17
  boxState: TELE_BOX_STATE;
@@ -103,6 +102,8 @@ export declare type PublicEvent = {
103
102
  darkModeChange: boolean;
104
103
  prefersColorSchemeChange: TeleBoxColorScheme;
105
104
  cameraStateChange: CameraState;
105
+ mainViewScenePathChange: string;
106
+ mainViewSceneIndexChange: number;
106
107
  };
107
108
  export declare type MountParams = {
108
109
  room: Room;
@@ -141,6 +142,7 @@ export declare class WindowManager extends InvisiblePlugin<WindowMangerAttribute
141
142
  isReplay: boolean;
142
143
  private boxManager?;
143
144
  private static params?;
145
+ private containerResizeObserver?;
144
146
  constructor(context: InvisiblePluginContext);
145
147
  static mount(params: MountParams): Promise<WindowManager>;
146
148
  private static initManager;
@@ -227,13 +229,6 @@ export declare class WindowManager extends InvisiblePlugin<WindowMangerAttribute
227
229
  private isDynamicPPT;
228
230
  private static checkVersion;
229
231
  private ensureAttributes;
230
- private containerResizeObserver?;
231
- private observePlaygroundSize;
232
- private updateSizer;
233
232
  }
234
- export declare const BuiltinApps: {
235
- DocsViewer: string;
236
- MediaPlayer: string;
237
- };
238
233
  export * from "./typings";
239
- export { WhiteWindowSDK } from "./sdk";
234
+ export { BuiltinApps } from "./BuiltinApps";