@netless/window-manager 1.0.0-canary.52 → 1.0.0-canary.54

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 (44) hide show
  1. package/dist/index.cjs.js +389 -445
  2. package/dist/index.es.js +434 -490
  3. package/dist/index.umd.js +389 -446
  4. package/dist/src/App/AppContext.d.ts +8 -8
  5. package/dist/src/AppManager.d.ts +5 -1
  6. package/dist/src/Cursor/index.d.ts +1 -0
  7. package/dist/src/Utils/Reactive.d.ts +1 -1
  8. package/dist/src/View/CameraSynchronizer.d.ts +4 -3
  9. package/dist/src/View/ScrollMode.d.ts +32 -0
  10. package/dist/src/View/ViewSync.d.ts +4 -2
  11. package/dist/src/callback.d.ts +3 -0
  12. package/dist/src/constants.d.ts +2 -0
  13. package/dist/src/index.d.ts +21 -11
  14. package/dist/src/storage.d.ts +7 -0
  15. package/dist/src/typings.d.ts +5 -4
  16. package/dist/style.css +2 -1
  17. package/docs/api.md +10 -0
  18. package/package.json +4 -3
  19. package/pnpm-lock.yaml +28 -73
  20. package/src/App/AppContext.ts +19 -8
  21. package/src/App/WhiteboardView.ts +4 -2
  22. package/src/AppListener.ts +1 -10
  23. package/src/AppManager.ts +19 -1
  24. package/src/Cursor/index.ts +6 -2
  25. package/src/Utils/Reactive.ts +2 -1
  26. package/src/View/CameraSynchronizer.ts +35 -23
  27. package/src/View/MainView.ts +1 -0
  28. package/src/View/ScrollMode.ts +229 -0
  29. package/src/View/ViewSync.ts +31 -18
  30. package/src/callback.ts +3 -0
  31. package/src/constants.ts +3 -0
  32. package/src/index.ts +56 -63
  33. package/src/storage.ts +15 -0
  34. package/src/style.css +1 -1
  35. package/src/typings.ts +6 -3
  36. package/vite.config.js +1 -1
  37. package/dist/src/App/Storage/StorageEvent.d.ts +0 -8
  38. package/dist/src/App/Storage/index.d.ts +0 -39
  39. package/dist/src/App/Storage/typings.d.ts +0 -22
  40. package/dist/src/App/Storage/utils.d.ts +0 -5
  41. package/src/App/Storage/StorageEvent.ts +0 -21
  42. package/src/App/Storage/index.ts +0 -295
  43. package/src/App/Storage/typings.ts +0 -23
  44. package/src/App/Storage/utils.ts +0 -17
@@ -1,5 +1,5 @@
1
- import { Storage } from "./Storage";
2
1
  import { autorun, listenDisposed, listenUpdated, reaction, unlistenDisposed, unlistenUpdated, toJS } from "white-web-sdk";
2
+ import { Storage } from "@netless/synced-store";
3
3
  import type { Room, SceneDefinition, View } from "white-web-sdk";
4
4
  import type { ReadonlyTeleBox } from "@netless/telebox-insider";
5
5
  import type Emittery from "emittery";
@@ -12,7 +12,7 @@ export declare type CreateWhiteBoardViewParams = {
12
12
  size?: number;
13
13
  syncCamera?: boolean;
14
14
  };
15
- export declare class AppContext<TAttributes = any, TMagixEventPayloads = any, TAppOptions = any> {
15
+ export declare class AppContext<TAttributes extends Record<string, any> = any, TMagixEventPayloads = any, TAppOptions = any> {
16
16
  private manager;
17
17
  appId: string;
18
18
  private appProxy;
@@ -64,12 +64,12 @@ export declare class AppContext<TAttributes = any, TMagixEventPayloads = any, TA
64
64
  /** Main Storage for attributes. */
65
65
  get storage(): Storage<TAttributes>;
66
66
  /**
67
- * Create separated storages for flexible state management.
68
- * @param storeId Namespace for the storage. Storages of the same namespace share the same data.
69
- * @param defaultState Default state for initial storage creation.
70
- * @returns
71
- */
72
- createStorage: <TState>(storeId: string, defaultState?: TState | undefined) => Storage<TState>;
67
+ * Create separated storages for flexible state management.
68
+ * @param namespace Namespace for the storage. Storages of the same namespace share the same data.
69
+ * @param defaultState Default state for initial storage creation.
70
+ * @returns
71
+ */
72
+ createStorage: <TState extends Record<string, any>>(namespace: string, defaultState?: TState | undefined) => Storage<TState>;
73
73
  /** Dispatch events to other clients (and self). */
74
74
  dispatchMagixEvent: MagixEventDispatcher<TMagixEventPayloads>;
75
75
  /** Listen to events from others clients (and self messages). */
@@ -6,9 +6,10 @@ import { ViewManager } from "./View/ViewManager";
6
6
  import { Val } from "value-enhancer";
7
7
  import type { ReconnectRefresher } from "./ReconnectRefresher";
8
8
  import type { BoxManager } from "./BoxManager";
9
- import type { Displayer, Room, SceneState } from "white-web-sdk";
9
+ import type { Displayer, Room, SceneState, Size } from "white-web-sdk";
10
10
  import type { AddAppParams, TeleBoxRect } from "./index";
11
11
  import type { Member } from "./Helper";
12
+ import { ScrollMode } from "./View/ScrollMode";
12
13
  export declare class AppManager {
13
14
  windowManger: WindowManager;
14
15
  displayer: Displayer;
@@ -22,11 +23,14 @@ export declare class AppManager {
22
23
  mainViewScenesLength: number;
23
24
  private appListeners;
24
25
  boxManager?: BoxManager;
26
+ scrollMode?: ScrollMode;
27
+ scrollBaseSize$: Val<Size | null, any>;
25
28
  private callbacksNode;
26
29
  private appCreateQueue;
27
30
  private sceneIndex$;
28
31
  private focused$;
29
32
  members$: Val<Member[], any>;
33
+ isWritable$: Val<boolean, any>;
30
34
  private sideEffectManager;
31
35
  sceneState: SceneState | null;
32
36
  rootDirRemoving: boolean;
@@ -23,6 +23,7 @@ export declare class CursorManager {
23
23
  private sideEffectManager;
24
24
  private store;
25
25
  applianceIcons: ApplianceIcons;
26
+ get playground$(): import("value-enhancer").Val<HTMLElement | undefined, any>;
26
27
  constructor(manager: AppManager, enableCursor: boolean, applianceIcons?: ApplianceIcons);
27
28
  private onCursorMove;
28
29
  private initCursorInstance;
@@ -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>, onDestroyed?: ((props: unknown) => void) | undefined) => () => void;
4
+ export declare const safeListenPropsUpdated: <T extends Object>(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,5 +1,5 @@
1
1
  import type { TeleBoxRect } from "@netless/telebox-insider";
2
- import type { View, Size } from "white-web-sdk";
2
+ import type { View } from "white-web-sdk";
3
3
  import type { ICamera, ISize } from "../AttributesDelegate";
4
4
  export declare type SaveCamera = (camera: ICamera) => void;
5
5
  export declare class CameraSynchronizer {
@@ -8,12 +8,13 @@ export declare class CameraSynchronizer {
8
8
  remoteSize?: ISize;
9
9
  protected rect?: TeleBoxRect;
10
10
  protected view?: View;
11
+ protected scale: number;
11
12
  constructor(saveCamera: SaveCamera);
12
- setRect: (rect: TeleBoxRect) => void;
13
+ setRect: (rect: TeleBoxRect, updateCamera?: boolean) => void;
13
14
  setView(view: View): void;
14
15
  onRemoteUpdate: import("lodash").DebouncedFunc<(camera: ICamera, size: ISize) => void>;
15
16
  onRemoteSizeUpdate(size: ISize): void;
16
17
  onLocalCameraUpdate(camera: ICamera): void;
18
+ private moveCameraToContian;
17
19
  private moveCamera;
18
20
  }
19
- export declare const computedMinScale: (remoteSize: Size, currentSize: Size) => number;
@@ -0,0 +1,32 @@
1
+ import { SideEffectManager } from "side-effect-manager";
2
+ import type { ReadonlyVal } from "value-enhancer";
3
+ import type { AppManager } from "../AppManager";
4
+ import type { ScrollStorage } from "../storage";
5
+ export declare type ScrollState = {
6
+ scrollTop: number;
7
+ page: number;
8
+ maxScrollPage: number;
9
+ };
10
+ export declare class ScrollMode {
11
+ private manager;
12
+ readonly sideEffect: SideEffectManager;
13
+ private readonly _root$;
14
+ private readonly _whiteboard$;
15
+ private readonly _scrollTop$;
16
+ readonly _page$: ReadonlyVal<number>;
17
+ private readonly _scale$;
18
+ private readonly _size$;
19
+ private readonly _mainView$;
20
+ private baseWidth;
21
+ private baseHeight;
22
+ scrollStorage: ScrollStorage;
23
+ readonly scrollState$: ReadonlyVal<ScrollState>;
24
+ setRoot(root: HTMLElement): void;
25
+ constructor(manager: AppManager);
26
+ private initScroll;
27
+ private updateScroll;
28
+ private updateBound;
29
+ dispose(): void;
30
+ private getWhiteboardElement;
31
+ private onWheel;
32
+ }
@@ -1,14 +1,14 @@
1
- import { ViewMode } from "white-web-sdk";
2
1
  import type { View } from "white-web-sdk";
3
2
  import type { Val, ReadonlyVal } from "value-enhancer";
4
3
  import type { ICamera, ISize } from "../AttributesDelegate";
5
4
  import type { TeleBoxRect } from "@netless/telebox-insider";
5
+ import type { ManagerViewMode } from "../typings";
6
6
  export declare type ViewSyncContext = {
7
7
  uid: string;
8
8
  camera$: Val<ICamera | undefined, boolean>;
9
9
  size$: Val<ISize | undefined>;
10
10
  stageRect$: ReadonlyVal<TeleBoxRect>;
11
- viewMode$?: Val<ViewMode>;
11
+ viewMode$?: Val<ManagerViewMode>;
12
12
  storeCamera: (camera: ICamera) => void;
13
13
  storeSize: (size: ISize) => void;
14
14
  view$: Val<View | undefined>;
@@ -17,7 +17,9 @@ export declare class ViewSync {
17
17
  private context;
18
18
  private sem;
19
19
  private synchronizer;
20
+ private needRecoverCamera$?;
20
21
  constructor(context: ViewSyncContext);
22
+ private get isBroadcastMode();
21
23
  private createSynchronizer;
22
24
  private subscribeView;
23
25
  private subscribeCamera;
@@ -4,6 +4,7 @@ import type { CameraState, SceneState, ViewVisionMode } from "white-web-sdk";
4
4
  import type { LoadAppEvent } from "./Register";
5
5
  import type { PageState } from "./Page";
6
6
  import type { ICamera, ISize } from "./AttributesDelegate";
7
+ import type { ScrollState } from "./View/ScrollMode";
7
8
  export declare type PublicEvent = {
8
9
  mainViewModeChange: ViewVisionMode;
9
10
  boxStateChange: `${TELE_BOX_STATE}`;
@@ -28,6 +29,8 @@ export declare type PublicEvent = {
28
29
  baseCameraChange: ICamera;
29
30
  baseSizeChange: ISize;
30
31
  fullscreenChange: TeleBoxFullscreen;
32
+ userScroll: undefined;
33
+ scrollStateChange: ScrollState;
31
34
  };
32
35
  export declare type CallbacksType = Emittery<PublicEvent>;
33
36
  export declare const callbacks: CallbacksType;
@@ -52,3 +52,5 @@ export declare const ROOT_DIR = "/";
52
52
  export declare const INIT_DIR = "/init";
53
53
  export declare const SETUP_APP_DELAY = 50;
54
54
  export declare const MAX_PAGE_SIZE = 500;
55
+ export declare const SCROLL_MODE_BASE_WIDTH = 1600;
56
+ export declare const SCROLL_MODE_BASE_HEIGHT: number;
@@ -1,23 +1,25 @@
1
1
  import { AppManager } from "./AppManager";
2
2
  import { CursorManager } from "./Cursor";
3
- import { AnimationMode, InvisiblePlugin, ViewMode } from "white-web-sdk";
3
+ import { InvisiblePlugin } from "white-web-sdk";
4
4
  import { ReconnectRefresher } from "./ReconnectRefresher";
5
5
  import { Val } from "value-enhancer";
6
6
  import type { TELE_BOX_STATE } from "./BoxManager";
7
7
  import type { Apps, Position, ICamera, ISize } from "./AttributesDelegate";
8
- import type { Displayer, SceneDefinition, View, Room, InvisiblePluginContext, Camera, CameraBound, Point, CameraState, Player, ImageInformation, SceneState, Size } from "white-web-sdk";
8
+ import type { Displayer, SceneDefinition, View, Room, InvisiblePluginContext, Camera, CameraBound, Point, CameraState, Player, ImageInformation, SceneState, Size, AnimationMode, Rectangle } from "white-web-sdk";
9
9
  import type { AppListeners } from "./AppListener";
10
- import type { ApplianceIcons, NetlessApp, RegisterParams } from "./typings";
10
+ import type { ApplianceIcons, ManagerViewMode, NetlessApp, RegisterParams } from "./typings";
11
11
  import type { TeleBoxColorScheme, TeleBoxFullscreen, TeleBoxManager, TeleBoxManagerThemeConfig, TeleBoxState } from "@netless/telebox-insider";
12
12
  import type { AppProxy } from "./App";
13
13
  import type { PublicEvent } from "./callback";
14
14
  import type Emittery from "emittery";
15
15
  import type { PageController, AddPageParams, PageState } from "./Page";
16
+ import type { ScrollState } from "./View/ScrollMode";
16
17
  export declare type WindowMangerAttributes = {
17
18
  modelValue?: string;
18
19
  boxState: TELE_BOX_STATE;
19
20
  maximized?: boolean;
20
21
  minimized?: boolean;
22
+ scrollTop?: number;
21
23
  [key: string]: any;
22
24
  };
23
25
  export declare type apps = {
@@ -103,9 +105,14 @@ export declare type MountParams = {
103
105
  defaultBoxStageStyle?: string | null;
104
106
  /** Theme variable */
105
107
  theme?: TeleBoxManagerThemeConfig;
108
+ /** ScrollMode BaseWidth */
109
+ scrollModeWidth?: number;
110
+ /** ScrollMode BaseHeight */
111
+ scrollModeHeight?: number;
112
+ viewMode?: ManagerViewMode;
106
113
  };
107
114
  export declare const reconnectRefresher: ReconnectRefresher;
108
- export declare class WindowManager extends InvisiblePlugin<WindowMangerAttributes> implements PageController {
115
+ export declare class WindowManager extends InvisiblePlugin<WindowMangerAttributes, any> implements PageController {
109
116
  static kind: string;
110
117
  static displayer: Displayer;
111
118
  static playground?: HTMLElement;
@@ -121,14 +128,13 @@ export declare class WindowManager extends InvisiblePlugin<WindowMangerAttribute
121
128
  emitter: Emittery<PublicEvent>;
122
129
  appManager?: AppManager;
123
130
  cursorManager?: CursorManager;
124
- viewMode: ViewMode;
125
- viewMode$: Val<ViewMode, any>;
131
+ viewMode: ManagerViewMode;
132
+ viewMode$: Val<ManagerViewMode, any>;
133
+ playground$: Val<HTMLElement | undefined, any>;
126
134
  isReplay: boolean;
127
135
  private _pageState?;
128
136
  private boxManager?;
129
137
  private static params?;
130
- private cameraUpdating;
131
- private nextCamera;
132
138
  containerSizeRatio: number;
133
139
  constructor(context: InvisiblePluginContext);
134
140
  static mount(params: MountParams): Promise<WindowManager>;
@@ -140,7 +146,7 @@ export declare class WindowManager extends InvisiblePlugin<WindowMangerAttribute
140
146
  /**
141
147
  * 注册插件
142
148
  */
143
- static register<AppOptions = any, SetupResult = any, Attributes = any>(params: RegisterParams<AppOptions, SetupResult, Attributes>): Promise<void>;
149
+ static register<AppOptions = any, SetupResult = any, Attributes extends Record<string, any> = any>(params: RegisterParams<AppOptions, SetupResult, Attributes>): Promise<void>;
144
150
  /**
145
151
  * 注销插件
146
152
  */
@@ -192,7 +198,7 @@ export declare class WindowManager extends InvisiblePlugin<WindowMangerAttribute
192
198
  /**
193
199
  * 设置 ViewMode
194
200
  */
195
- setViewMode(mode: ViewMode): void;
201
+ setViewMode(mode: ManagerViewMode): void;
196
202
  setBoxState(boxState: TeleBoxState): void;
197
203
  setMaximized(maximized: boolean): void;
198
204
  setMinimized(minimized: boolean): void;
@@ -221,6 +227,7 @@ export declare class WindowManager extends InvisiblePlugin<WindowMangerAttribute
221
227
  get canUndoSteps(): number;
222
228
  get sceneState(): SceneState;
223
229
  get pageState(): PageState;
230
+ get scrollState(): ScrollState | undefined;
224
231
  get teleboxManager(): TeleBoxManager;
225
232
  /**
226
233
  * 查询所有的 App
@@ -237,7 +244,10 @@ export declare class WindowManager extends InvisiblePlugin<WindowMangerAttribute
237
244
  moveCamera: (camera: Partial<Camera> & {
238
245
  animationMode?: AnimationMode;
239
246
  }) => void;
240
- private onCameraUpdated;
247
+ moveCameraToContain(rectangle: Rectangle & Readonly<{
248
+ animationMode?: AnimationMode;
249
+ }>): void;
250
+ private debouncedStoreCamera;
241
251
  convertToPointInWorld(point: Point): Point;
242
252
  setCameraBound(cameraBound: CameraBound): void;
243
253
  onDestroy(): void;
@@ -0,0 +1,7 @@
1
+ import { Storage } from "@netless/synced-store";
2
+ import type { AppManager } from "./AppManager";
3
+ export declare type ScrollStorageState = {
4
+ scrollTop: number;
5
+ };
6
+ export declare type ScrollStorage = Storage<ScrollStorageState>;
7
+ export declare const createScrollStorage: (manager: AppManager) => Storage<ScrollStorageState>;
@@ -1,10 +1,10 @@
1
1
  import type Emittery from "emittery";
2
- import type { AnimationMode, ApplianceNames, Displayer, DisplayerState, Player, Room, SceneDefinition, SceneState, View } from "white-web-sdk";
2
+ import type { AnimationMode, ApplianceNames, Displayer, DisplayerState, Player, Room, SceneDefinition, SceneState, View, ViewMode } from "white-web-sdk";
3
3
  import type { AppContext } from "./App";
4
4
  import type { ReadonlyTeleBox, TeleBoxRect, TeleBoxFullscreen } from "@netless/telebox-insider";
5
5
  import type { PageState } from "./Page";
6
6
  import type { Member } from "./Helper";
7
- export interface NetlessApp<Attributes = any, MagixEventPayloads = any, AppOptions = any, SetupResult = any> {
7
+ export interface NetlessApp<Attributes extends Record<string, any> = any, MagixEventPayloads = any, AppOptions = any, SetupResult = any> {
8
8
  kind: string;
9
9
  config?: {
10
10
  /** Box width relative to whiteboard. 0~1. Default 0.5. */
@@ -64,7 +64,7 @@ export declare type RegisterEvents<SetupResult = any> = {
64
64
  destroy: RegisterEventData;
65
65
  focus: RegisterEventData;
66
66
  };
67
- export declare type RegisterParams<AppOptions = any, SetupResult = any, Attributes = any> = {
67
+ export declare type RegisterParams<AppOptions = any, SetupResult = any, Attributes extends Record<string, any> = any> = {
68
68
  kind: string;
69
69
  src: NetlessApp<Attributes, SetupResult> | string | (() => Promise<NetlessApp<Attributes, SetupResult>>) | (() => Promise<{
70
70
  default: NetlessApp<Attributes, SetupResult>;
@@ -80,12 +80,13 @@ export declare type ApplianceIcons = Partial<Record<ApplianceNames, string>>;
80
80
  export declare type Writeable<T> = {
81
81
  -readonly [P in keyof T]: T[P];
82
82
  };
83
+ export declare type ManagerViewMode = `${ViewMode}` | "scroll";
83
84
  export type { AppContext } from "./App/AppContext";
84
85
  export type { WhiteBoardView } from "./App";
85
86
  export type { ReadonlyTeleBox, TeleBoxRect, TeleBoxFullscreen };
86
87
  export type { SceneState, SceneDefinition, View, AnimationMode, Displayer, Room, Player };
87
- export type { Storage, StorageStateChangedEvent, StorageStateChangedListener } from "./App/Storage";
88
88
  export * from "./Page";
89
89
  export * from "./Utils/error";
90
90
  export type { Member } from "./Helper";
91
91
  export type { TeleBoxManager, TeleBoxManagerQueryConfig } from "@netless/telebox-insider";
92
+ export type { Storage, StorageConfig } from "@netless/synced-store";
package/dist/style.css CHANGED
@@ -143,7 +143,8 @@
143
143
  .window-manager-view-wrapper {
144
144
  position: absolute;
145
145
  z-index: 10;
146
- }.tele-fancy-scrollbar {
146
+ }
147
+ .tele-fancy-scrollbar {
147
148
  overscroll-behavior: contain;
148
149
  overflow: auto;
149
150
  overflow-y: scroll;
package/docs/api.md CHANGED
@@ -283,6 +283,8 @@ manager.callbacks.on(events, listener)
283
283
  | ready | undefined | | 当所有 APP 创建完毕时触发 |
284
284
  | sceneStateChange | SceneState | | 当 sceneState 修改时触发 |
285
285
  | pageStateChange | PageState | | |
286
+ | scrollStateChange | ScrollState | | 当在 `ScrollState` 变化时触发 |
287
+ | userScroll | void | | 当用户主动滚动时触发 |
286
288
 
287
289
  ```ts
288
290
  type LoadAppEvent = {
@@ -297,4 +299,12 @@ type PageState = {
297
299
  index: number;
298
300
  length: number;
299
301
  }
302
+ ```
303
+
304
+ ```ts
305
+ type ScrollState = {
306
+ scrollTop: number;
307
+ page: number;
308
+ maxScrollPage: number;
309
+ };
300
310
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netless/window-manager",
3
- "version": "1.0.0-canary.52",
3
+ "version": "1.0.0-canary.54",
4
4
  "description": "",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.es.js",
@@ -25,11 +25,12 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "@juggle/resize-observer": "^3.3.1",
28
+ "@netless/synced-store": "^2.0.7",
28
29
  "@netless/telebox-insider": "1.0.0-alpha.37",
29
30
  "emittery": "^0.11.0",
30
31
  "lodash": "^4.17.21",
31
32
  "p-retry": "^4.6.2",
32
- "side-effect-manager": "^1.1.1",
33
+ "side-effect-manager": "^1.2.1",
33
34
  "uuid": "^7.0.3",
34
35
  "value-enhancer": "^1.3.2"
35
36
  },
@@ -66,6 +67,6 @@
66
67
  "vite": "^2.5.3",
67
68
  "vite-plugin-dts": "^1.2.1",
68
69
  "vitest": "^0.18.0",
69
- "white-web-sdk": "2.16.26"
70
+ "white-web-sdk": "^2.16.35"
70
71
  }
71
72
  }