@netless/window-manager 1.0.0-canary.6 → 1.0.0-canary.60

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 (111) hide show
  1. package/README.md +30 -6
  2. package/dist/index.js +13539 -0
  3. package/dist/index.mjs +13536 -0
  4. package/dist/index.umd.js +13534 -46
  5. package/dist/{App → src/App}/AppContext.d.ts +16 -14
  6. package/dist/{App → src/App}/AppPageStateImpl.d.ts +0 -0
  7. package/dist/{App → src/App}/AppProxy.d.ts +30 -11
  8. package/dist/{App → src/App}/MagixEvent/index.d.ts +0 -0
  9. package/dist/src/App/WhiteboardView.d.ts +27 -0
  10. package/dist/{App → src/App}/index.d.ts +1 -0
  11. package/dist/src/App/type.d.ts +21 -0
  12. package/dist/{AppListener.d.ts → src/AppListener.d.ts} +2 -2
  13. package/dist/{AppManager.d.ts → src/AppManager.d.ts} +11 -6
  14. package/dist/{AttributesDelegate.d.ts → src/AttributesDelegate.d.ts} +5 -2
  15. package/dist/{BoxEmitter.d.ts → src/BoxEmitter.d.ts} +0 -0
  16. package/dist/{BoxManager.d.ts → src/BoxManager.d.ts} +12 -6
  17. package/dist/{BuiltinApps.d.ts → src/BuiltinApps.d.ts} +3 -0
  18. package/dist/{Cursor → src/Cursor}/Cursor.d.ts +0 -0
  19. package/dist/{Cursor → src/Cursor}/icons.d.ts +0 -0
  20. package/dist/{Cursor → src/Cursor}/index.d.ts +4 -3
  21. package/dist/{Helper.d.ts → src/Helper.d.ts} +4 -8
  22. package/dist/{InternalEmitter.d.ts → src/InternalEmitter.d.ts} +1 -4
  23. package/dist/{Page → src/Page}/PageController.d.ts +2 -1
  24. package/dist/{Page → src/Page}/index.d.ts +0 -0
  25. package/dist/{PageState.d.ts → src/PageState.d.ts} +0 -0
  26. package/dist/{ReconnectRefresher.d.ts → src/ReconnectRefresher.d.ts} +0 -0
  27. package/dist/{RedoUndo.d.ts → src/RedoUndo.d.ts} +0 -0
  28. package/dist/{Register → src/Register}/index.d.ts +4 -2
  29. package/dist/{Register → src/Register}/loader.d.ts +1 -1
  30. package/dist/src/Register/storage.d.ts +11 -0
  31. package/dist/{Utils → src/Utils}/AppCreateQueue.d.ts +0 -0
  32. package/dist/{Utils → src/Utils}/Common.d.ts +0 -0
  33. package/dist/{Utils → src/Utils}/Reactive.d.ts +1 -1
  34. package/dist/{Utils → src/Utils}/RoomHacker.d.ts +0 -0
  35. package/dist/{Utils → src/Utils}/error.d.ts +1 -1
  36. package/dist/{Utils → src/Utils}/log.d.ts +0 -0
  37. package/dist/src/View/CameraSynchronizer.d.ts +20 -0
  38. package/dist/{View → src/View}/MainView.d.ts +18 -7
  39. package/dist/src/View/ScrollMode.d.ts +32 -0
  40. package/dist/{View → src/View}/ViewManager.d.ts +0 -0
  41. package/dist/src/View/ViewSync.d.ts +32 -0
  42. package/dist/{callback.d.ts → src/callback.d.ts} +13 -1
  43. package/dist/{constants.d.ts → src/constants.d.ts} +12 -5
  44. package/dist/src/image.d.ts +19 -0
  45. package/dist/{index.d.ts → src/index.d.ts} +66 -17
  46. package/dist/src/shim.d.ts +11 -0
  47. package/dist/src/storage.d.ts +7 -0
  48. package/dist/{typings.d.ts → src/typings.d.ts} +18 -8
  49. package/dist/style.css +810 -1
  50. package/docs/api.md +10 -0
  51. package/docs/app-context.md +155 -27
  52. package/docs/mirgrate-to-1.0.md +68 -0
  53. package/package.json +27 -22
  54. package/playwright.config.ts +29 -0
  55. package/pnpm-lock.yaml +3141 -4483
  56. package/src/App/AppContext.ts +81 -46
  57. package/src/App/AppProxy.ts +249 -139
  58. package/src/App/WhiteboardView.ts +38 -14
  59. package/src/App/index.ts +1 -0
  60. package/src/App/type.ts +22 -0
  61. package/src/AppListener.ts +21 -21
  62. package/src/AppManager.ts +84 -43
  63. package/src/AttributesDelegate.ts +6 -3
  64. package/src/BoxManager.ts +76 -38
  65. package/src/BuiltinApps.ts +9 -8
  66. package/src/Cursor/Cursor.svelte +6 -2
  67. package/src/Cursor/Cursor.ts +16 -5
  68. package/src/Cursor/icons.ts +6 -0
  69. package/src/Cursor/index.ts +13 -10
  70. package/src/Helper.ts +25 -7
  71. package/src/InternalEmitter.ts +1 -4
  72. package/src/Page/PageController.ts +2 -1
  73. package/src/PageState.ts +1 -1
  74. package/src/ReconnectRefresher.ts +6 -2
  75. package/src/Register/index.ts +36 -14
  76. package/src/Register/loader.ts +20 -9
  77. package/src/Register/storage.ts +26 -5
  78. package/src/Utils/Common.ts +3 -0
  79. package/src/Utils/Reactive.ts +29 -27
  80. package/src/Utils/RoomHacker.ts +3 -0
  81. package/src/Utils/error.ts +2 -2
  82. package/src/View/CameraSynchronizer.ts +52 -37
  83. package/src/View/MainView.ts +118 -76
  84. package/src/View/ScrollMode.ts +239 -0
  85. package/src/View/ViewSync.ts +139 -6
  86. package/src/callback.ts +9 -1
  87. package/src/constants.ts +11 -3
  88. package/src/image/pencil-eraser-1.svg +3 -0
  89. package/src/image/pencil-eraser-2.svg +3 -0
  90. package/src/image/pencil-eraser-3.svg +3 -0
  91. package/src/index.ts +202 -58
  92. package/src/storage.ts +15 -0
  93. package/src/style.css +18 -47
  94. package/src/typings.ts +21 -7
  95. package/vite.config.js +12 -7
  96. package/dist/App/AppViewSync.d.ts +0 -11
  97. package/dist/App/Storage/StorageEvent.d.ts +0 -8
  98. package/dist/App/Storage/index.d.ts +0 -39
  99. package/dist/App/Storage/typings.d.ts +0 -22
  100. package/dist/App/Storage/utils.d.ts +0 -5
  101. package/dist/App/WhiteboardView.d.ts +0 -21
  102. package/dist/Register/storage.d.ts +0 -8
  103. package/dist/View/CameraSynchronizer.d.ts +0 -17
  104. package/dist/View/ViewSync.d.ts +0 -7
  105. package/dist/index.cjs.js +0 -46
  106. package/dist/index.es.js +0 -16159
  107. package/src/App/AppViewSync.ts +0 -68
  108. package/src/App/Storage/StorageEvent.ts +0 -21
  109. package/src/App/Storage/index.ts +0 -295
  110. package/src/App/Storage/typings.ts +0 -23
  111. package/src/App/Storage/utils.ts +0 -17
package/src/typings.ts CHANGED
@@ -9,13 +9,14 @@ import type {
9
9
  SceneDefinition,
10
10
  SceneState,
11
11
  View,
12
+ ViewMode,
12
13
  } from "white-web-sdk";
13
14
  import type { AppContext } from "./App";
14
- import type { ReadonlyTeleBox, TeleBoxRect } from "@netless/telebox-insider";
15
+ import type { ReadonlyTeleBox, TeleBoxRect, TeleBoxFullscreen } from "@netless/telebox-insider";
15
16
  import type { PageState } from "./Page";
16
17
  import type { Member } from "./Helper";
17
18
 
18
- export interface NetlessApp<Attributes = any, MagixEventPayloads = any, AppOptions = any, SetupResult = any> {
19
+ export interface NetlessApp<Attributes extends Record<string, any> = any, MagixEventPayloads = any, AppOptions = any, SetupResult = any> {
19
20
  kind: string;
20
21
  config?: {
21
22
  /** Box width relative to whiteboard. 0~1. Default 0.5. */
@@ -30,6 +31,9 @@ export interface NetlessApp<Attributes = any, MagixEventPayloads = any, AppOptio
30
31
 
31
32
  /** App only single instance. */
32
33
  singleton?: boolean;
34
+
35
+ /** App box enableShadowDom. Default true */
36
+ enableShadowDOM?: boolean;
33
37
  };
34
38
  setup: (context: AppContext<Attributes, MagixEventPayloads, AppOptions>) => SetupResult;
35
39
  }
@@ -67,24 +71,34 @@ export type RegisterEvents<SetupResult = any> = {
67
71
  focus: RegisterEventData;
68
72
  };
69
73
 
70
- export type RegisterParams<AppOptions = any, SetupResult = any, Attributes = any> = {
74
+ export type RegisterParams<AppOptions = any, SetupResult = any, Attributes extends Record<string, any> = any> = {
71
75
  kind: string;
72
- src: NetlessApp<Attributes, SetupResult> | string | (() => Promise<NetlessApp<Attributes, SetupResult>>);
76
+ src:
77
+ | NetlessApp<Attributes, SetupResult>
78
+ | string
79
+ | (() => Promise<NetlessApp<Attributes, SetupResult>>)
80
+ | (() => Promise<{ default: NetlessApp<Attributes, SetupResult> }>);
73
81
  appOptions?: AppOptions | (() => AppOptions);
74
82
  addHooks?: (emitter: Emittery<RegisterEvents<SetupResult>>) => void;
75
83
  /** dynamic load app package name */
76
84
  name?: string;
85
+ contentStyles?: string;
77
86
  };
78
87
 
79
88
  export type AppListenerKeys = keyof AppEmitterEvent;
80
89
 
81
- export type ApplianceIcons = Partial<Record<ApplianceNames, string>>;
90
+ export type ApplianceIcons = Partial<Record<`${ApplianceNames}` | string, string>>;
91
+
92
+ export type Writeable<T> = { -readonly [P in keyof T]: T[P] };
93
+
94
+ export type ManagerViewMode = `${ViewMode}` | "scroll";
82
95
 
83
96
  export type { AppContext } from "./App/AppContext";
84
97
  export type { WhiteBoardView } from "./App";
85
- export type { ReadonlyTeleBox, TeleBoxRect };
98
+ export type { ReadonlyTeleBox, TeleBoxRect, TeleBoxFullscreen };
86
99
  export type { SceneState, SceneDefinition, View, AnimationMode, Displayer, Room, Player };
87
- export type { Storage, StorageStateChangedEvent, StorageStateChangedListener } from "./App/Storage";
88
100
  export * from "./Page";
89
101
  export * from "./Utils/error";
90
102
  export type { Member } from "./Helper";
103
+ export type { TeleBoxManager, TeleBoxManagerQueryConfig } from "@netless/telebox-insider";
104
+ export type { Storage, StorageConfig } from "@netless/synced-store";
package/vite.config.js CHANGED
@@ -1,11 +1,12 @@
1
1
  import path from "path";
2
+ import dts from 'vite-plugin-dts'
2
3
  import { defineConfig } from 'vitest/config'
3
4
  import { svelte } from "@sveltejs/vite-plugin-svelte";
4
5
  import { dependencies, peerDependencies, version, devDependencies } from "./package.json"
5
6
  import { omit } from "lodash";
6
7
 
7
- export default defineConfig(({ mode }) => {
8
- const isProd = mode === "production";
8
+ export default defineConfig(() => {
9
+ // const isProd = mode === "production";
9
10
 
10
11
  return {
11
12
  test: {
@@ -14,7 +15,9 @@ export default defineConfig(({ mode }) => {
14
15
  inline: [
15
16
  "@juggle/resize-observer"
16
17
  ]
17
- }
18
+ },
19
+ setupFiles: "./test/setup.ts",
20
+ include: ["test/**/*.test.ts"],
18
21
  },
19
22
  define: {
20
23
  __APP_VERSION__: JSON.stringify(version),
@@ -28,7 +31,8 @@ export default defineConfig(({ mode }) => {
28
31
  experimental: {
29
32
  useVitePreprocess: true,
30
33
  },
31
- })
34
+ }),
35
+ dts(),
32
36
  ],
33
37
  build: {
34
38
  lib: {
@@ -36,7 +40,8 @@ export default defineConfig(({ mode }) => {
36
40
  entry: path.resolve(__dirname, "src/index.ts"),
37
41
  formats: ["es", "umd", "cjs"],
38
42
  name: "WindowManager",
39
- fileName: "index"
43
+ fileName: "index",
44
+
40
45
  },
41
46
  outDir: "dist",
42
47
  rollupOptions: {
@@ -45,7 +50,7 @@ export default defineConfig(({ mode }) => {
45
50
  ...peerDependencies,
46
51
  }),
47
52
  },
48
- minify: isProd,
53
+ minify: false
49
54
  },
50
55
  };
51
- });
56
+ })
@@ -1,11 +0,0 @@
1
- import type { View } from "white-web-sdk";
2
- import type { AppProxy } from "./AppProxy";
3
- export declare class AppViewSync {
4
- private appProxy;
5
- private sem;
6
- private synchronizer;
7
- constructor(appProxy: AppProxy);
8
- bindView: (view?: View | undefined) => void;
9
- private onCameraUpdatedByDevice;
10
- destroy(): void;
11
- }
@@ -1,8 +0,0 @@
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
- }
@@ -1,39 +0,0 @@
1
- import type { AppContext } from "../AppContext";
2
- import type { Diff, StorageStateChangedListener, StorageStateChangedListenerDisposer } from "./typings";
3
- import { StorageEvent } from "./StorageEvent";
4
- export * from './typings';
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;
8
- private readonly _context;
9
- private readonly _sideEffect;
10
- private _state;
11
- private _destroyed;
12
- private _refMap;
13
- /**
14
- * `setState` alters local state immediately before sending to server. This will cache the old value for onStateChanged diffing.
15
- */
16
- private _lastValue;
17
- constructor(context: AppContext, id?: string, defaultState?: TState);
18
- get state(): Readonly<TState>;
19
- readonly onStateChanged: StorageEvent<Diff<TState>>;
20
- addStateChangedListener(handler: StorageStateChangedListener<TState>): StorageStateChangedListenerDisposer;
21
- ensureState(state: Partial<TState>): void;
22
- setState(state: Partial<TState>): void;
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;
31
- get destroyed(): boolean;
32
- /**
33
- * Destroy the Storage instance. The data will be kept.
34
- */
35
- destroy(): void;
36
- private _getRawState;
37
- private _setRawState;
38
- private _updateProperties;
39
- }
@@ -1,22 +0,0 @@
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>>;
22
- export declare type StorageStateChangedListenerDisposer = () => void;
@@ -1,5 +0,0 @@
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>;
@@ -1,21 +0,0 @@
1
- import type { ReadonlyVal } from "value-enhancer";
2
- import type { AddPageParams, PageController, PageState } from "../Page";
3
- import type { AppProxy } from "./AppProxy";
4
- import type { AppContext } from "./AppContext";
5
- import type { Camera } from "white-web-sdk";
6
- export declare class WhiteBoardView implements PageController {
7
- protected appContext: AppContext;
8
- protected appProxy: AppProxy;
9
- private removeViewWrapper;
10
- readonly pageState$: ReadonlyVal<PageState>;
11
- constructor(appContext: AppContext, appProxy: AppProxy, removeViewWrapper: () => void);
12
- get view(): import("white-web-sdk").View | undefined;
13
- get pageState(): PageState;
14
- moveCamera(camera: Camera): void;
15
- nextPage: () => Promise<boolean>;
16
- prevPage: () => Promise<boolean>;
17
- jumpPage: (index: number) => Promise<boolean>;
18
- addPage: (params?: AddPageParams | undefined) => Promise<void>;
19
- removePage: (index?: number | undefined) => Promise<boolean>;
20
- destroy(): void;
21
- }
@@ -1,8 +0,0 @@
1
- export declare type Item = {
2
- kind: string;
3
- sourceCode: string;
4
- };
5
- export declare const initDb: () => Promise<void>;
6
- export declare const setItem: (key: string, val: any) => Promise<void> | undefined;
7
- export declare const getItem: (key: string) => Promise<Item | null>;
8
- export declare const removeItem: (key: string) => Promise<void> | undefined;
@@ -1,17 +0,0 @@
1
- import type { TeleBoxRect } from "@netless/telebox-insider";
2
- import type { Camera, View, Size } from "white-web-sdk";
3
- import type { ISize } from "../AttributesDelegate";
4
- export declare type SaveCamera = (camera: Camera) => void;
5
- export declare class CameraSynchronizer {
6
- protected saveCamera: SaveCamera;
7
- protected remoteCamera?: Camera;
8
- protected remoteSize?: ISize;
9
- protected rect?: TeleBoxRect;
10
- protected view?: View;
11
- constructor(saveCamera: SaveCamera);
12
- setRect(rect: TeleBoxRect): void;
13
- setView(view: View): void;
14
- onRemoteUpdate: import("lodash").DebouncedFunc<(camera: Camera, size: ISize) => void>;
15
- onLocalCameraUpdate(camera: Camera): void;
16
- onLocalSizeUpdate: (size: Size) => void;
17
- }
@@ -1,7 +0,0 @@
1
- import type { Camera, Size } from "white-web-sdk";
2
- export interface ViewSync {
3
- readonly camera: Camera;
4
- readonly size: Size;
5
- setCamera: (camera: Camera) => void;
6
- setSize: (size: Size) => void;
7
- }