@netless/window-manager 1.0.0-canary.18 → 1.0.0-canary.20

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.
@@ -0,0 +1,28 @@
1
+ ## 迁移至 `@netless/window-manager@1.0`
2
+
3
+ ### 样式
4
+
5
+ 1.0 之前
6
+
7
+ ```html
8
+ <div class="netless-window-manager-playground">
9
+ <div class="netless-window-manager-sizer">
10
+ <div class="netless-window-manager-wrapper">
11
+ <div class="netless-window-manager-main-view"></div>
12
+ </div>
13
+ </div>
14
+ </div>
15
+ ```
16
+
17
+ 1.0 之后
18
+
19
+ ```html
20
+ <div class="netless-window-manager-playground">
21
+ <div class="netless-window-manager-main-view"></div>
22
+ </div>
23
+ ```
24
+
25
+
26
+ ### `APP` 迁移
27
+
28
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netless/window-manager",
3
- "version": "1.0.0-canary.18",
3
+ "version": "1.0.0-canary.20",
4
4
  "description": "",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.es.js",
@@ -125,7 +125,7 @@ export class AppContext<TAttributes = any, TMagixEventPayloads = any, TAppOption
125
125
  }
126
126
 
127
127
  public getInitScenePath = () => {
128
- return this.manager.getAppInitPath(this.appId);
128
+ return this.appProxy.scenePath;
129
129
  };
130
130
 
131
131
  /** Get App writable status. */
@@ -30,11 +30,12 @@ import type {
30
30
  setAppOptions,
31
31
  AppListenerKeys,
32
32
  } from "../index";
33
- import type { SceneState, View, SceneDefinition, Camera , MemberState} from "white-web-sdk";
33
+ import type { SceneState, View, SceneDefinition, MemberState} from "white-web-sdk";
34
34
  import type { AppManager } from "../AppManager";
35
35
  import type { NetlessApp } from "../typings";
36
36
  import type { ReadonlyTeleBox, TeleBoxRect } from "@netless/telebox-insider";
37
37
  import type { PageRemoveService, PageState } from "../Page";
38
+ import { createValSync } from "../Utils/Reactive";
38
39
 
39
40
  export type AppEmitter = Emittery<AppEmitterEvent>;
40
41
 
@@ -117,8 +118,8 @@ export class AppProxy implements PageRemoveService {
117
118
  if (box && view) {
118
119
  if (!this.camera$.value) {
119
120
  this.storeCamera({
120
- centerX: 0,
121
- centerY: 0,
121
+ centerX: null,
122
+ centerY: null,
122
123
  scale: 1,
123
124
  id: this.uid,
124
125
  });
@@ -151,6 +152,52 @@ export class AppProxy implements PageRemoveService {
151
152
  this.sideEffectManager.add(() =>
152
153
  emitter.on("memberStateChange", this.onMemberStateChange)
153
154
  );
155
+ this.box$.subscribe(box => {
156
+ if (!box) return;
157
+ this.sideEffectManager.add(() => [
158
+ createValSync(
159
+ () => this.appAttributes?.state.visible,
160
+ box._visible$,
161
+ this.isAddApp,
162
+ ),
163
+ createValSync(
164
+ () => this.appAttributes?.state.ratio,
165
+ box._ratio$,
166
+ this.isAddApp,
167
+ ),
168
+ createValSync(
169
+ () => this.appAttributes?.state.stageRatio,
170
+ box._stageRatio$,
171
+ this.isAddApp,
172
+ ),
173
+ createValSync(
174
+ () => this.appAttributes?.state.draggable,
175
+ box._draggable$,
176
+ this.isAddApp,
177
+ ),
178
+ createValSync(
179
+ () => this.appAttributes?.state.resizable,
180
+ box._resizable$,
181
+ this.isAddApp,
182
+ ),
183
+ box._visible$.subscribe(visible => {
184
+ this.store.updateAppState(this.id, AppAttributes.Visible, visible);
185
+ }),
186
+ box._ratio$.subscribe(ratio => {
187
+ this.store.updateAppState(this.id, AppAttributes.Ratio, ratio);
188
+ }),
189
+ box._stageRatio$.subscribe(stageRatio => {
190
+ this.store.updateAppState(this.id, AppAttributes.StageRatio, stageRatio);
191
+ }),
192
+ box._draggable$.subscribe(draggable => {
193
+ this.store.updateAppState(this.id, AppAttributes.Draggable, draggable);
194
+ }),
195
+ box._resizable$.subscribe(resizable => {
196
+ console.log("resizable change", resizable);
197
+ this.store.updateAppState(this.id, AppAttributes.Resizable, resizable);
198
+ }),
199
+ ])
200
+ });
154
201
  }
155
202
 
156
203
  public fireMemberStateChange = () => {
@@ -595,7 +642,7 @@ export class AppProxy implements PageRemoveService {
595
642
  this.size$.setValue(iSize);
596
643
  }
597
644
 
598
- public moveCamera = (camera: Partial<Camera>) => {
645
+ public moveCamera = (camera: Partial<ICamera>) => {
599
646
  if (!this.camera$.value) {
600
647
  return;
601
648
  }
@@ -6,10 +6,11 @@ import type { ReadonlyVal } from "value-enhancer";
6
6
  import type { AddPageParams, PageController, PageState } from "../Page";
7
7
  import type { AppProxy } from "./AppProxy";
8
8
  import type { AppContext } from "./AppContext";
9
- import type { Camera, View } from "white-web-sdk";
9
+ import type { View } from "white-web-sdk";
10
10
  import type { TeleBoxRect } from "@netless/telebox-insider";
11
+ import type { ICamera } from "../AttributesDelegate";
11
12
 
12
- export type WhiteBoardViewCamera = Omit<Camera, "scale">;
13
+ export type WhiteBoardViewCamera = Omit<ICamera, "scale" | "id">;
13
14
 
14
15
  export class WhiteBoardView implements PageController {
15
16
  public readonly pageState$: ReadonlyVal<PageState>;
@@ -2,7 +2,7 @@ import { AppAttributes } from "./constants";
2
2
  import { get, pick } from "lodash";
3
3
  import { setViewFocusScenePath } from "./Utils/Common";
4
4
  import type { AddAppParams, AppSyncAttributes } from "./index";
5
- import type { Camera, Size, View } from "white-web-sdk";
5
+ import type { Size, View } from "white-web-sdk";
6
6
  import type { Cursor } from "./Cursor/Cursor";
7
7
 
8
8
  export enum Fields {
@@ -41,8 +41,11 @@ export type StoreContext = {
41
41
  safeSetAttributes: (attributes: any) => void;
42
42
  }
43
43
 
44
- export type ICamera = Camera & {
44
+ export type ICamera = & {
45
45
  id: string; // room uid
46
+ centerX: number | null,
47
+ centerY: number | null,
48
+ scale: number
46
49
  };
47
50
 
48
51
  export type ISize = Size & {
@@ -1,6 +1,7 @@
1
- import { listenUpdated, unlistenUpdated, reaction, UpdateEventKind } from "white-web-sdk";
2
- import type { AkkoObjectUpdatedProperty , AkkoObjectUpdatedListener } from "white-web-sdk";
3
1
  import { isObject } from "lodash";
2
+ import { listenUpdated, reaction, unlistenUpdated, UpdateEventKind } from "white-web-sdk";
3
+ import type { AkkoObjectUpdatedProperty, AkkoObjectUpdatedListener } from "white-web-sdk";
4
+ import type { Val } from "value-enhancer";
4
5
 
5
6
  // 兼容 13 和 14 版本 SDK
6
7
  export const onObjectByEvent = (event: UpdateEventKind) => {
@@ -12,7 +13,7 @@ export const onObjectByEvent = (event: UpdateEventKind) => {
12
13
  if (kinds.includes(event)) {
13
14
  func();
14
15
  }
15
- }
16
+ };
16
17
  listenUpdated(object, listener);
17
18
  func();
18
19
  return () => unlistenUpdated(object, listener);
@@ -21,43 +22,59 @@ export const onObjectByEvent = (event: UpdateEventKind) => {
21
22
  () => object,
22
23
  () => {
23
24
  func();
24
- }, {
25
+ },
26
+ {
25
27
  fireImmediately: true,
26
28
  }
27
- )
29
+ );
28
30
  }
29
- }
30
- }
31
+ };
32
+ };
31
33
 
32
34
  export const safeListenPropsUpdated = <T>(
33
35
  getProps: () => T,
34
36
  callback: AkkoObjectUpdatedListener<T>,
35
37
  onDestroyed?: (props: unknown) => void
36
- ) => {
38
+ ) => {
37
39
  let disposeListenUpdated: (() => void) | null = null;
38
40
  const disposeReaction = reaction(
39
- getProps,
40
- () => {
41
- if (disposeListenUpdated) {
42
- disposeListenUpdated();
43
- disposeListenUpdated = null;
44
- }
45
- const props = getProps();
46
- if (isObject(props)) {
47
- disposeListenUpdated = () => unlistenUpdated(props, callback);
48
- listenUpdated(props, callback);
49
- } else {
50
- onDestroyed?.(props);
51
- }
52
- },
53
- { fireImmediately: true }
41
+ getProps,
42
+ () => {
43
+ if (disposeListenUpdated) {
44
+ disposeListenUpdated();
45
+ disposeListenUpdated = null;
46
+ }
47
+ const props = getProps();
48
+ if (isObject(props)) {
49
+ disposeListenUpdated = () => unlistenUpdated(props, callback);
50
+ listenUpdated(props, callback);
51
+ } else {
52
+ onDestroyed?.(props);
53
+ }
54
+ },
55
+ { fireImmediately: true }
54
56
  );
55
57
 
56
58
  return () => {
57
- disposeListenUpdated?.();
58
- disposeReaction();
59
+ disposeListenUpdated?.();
60
+ disposeReaction();
59
61
  };
60
- }
62
+ };
61
63
 
62
64
  export const onObjectRemoved = onObjectByEvent(UpdateEventKind.Removed);
63
65
  export const onObjectInserted = onObjectByEvent(UpdateEventKind.Inserted);
66
+
67
+ export const createValSync = <T>(expr: any, Val: Val<T, boolean>, isAddApp: boolean): (() => void) => {
68
+ let skipUpdate = false;
69
+ return reaction(
70
+ expr,
71
+ val => {
72
+ if (isAddApp && !skipUpdate) {
73
+ skipUpdate = true;
74
+ } else {
75
+ Val.setValue(val as T);
76
+ }
77
+ },
78
+ { fireImmediately: true }
79
+ );
80
+ };
@@ -2,12 +2,12 @@ import { AnimationMode } from "white-web-sdk";
2
2
  import { debounce, delay, isEqual, pick, throttle } from "lodash";
3
3
  import type { TeleBoxRect } from "@netless/telebox-insider";
4
4
  import type { Camera, View } from "white-web-sdk";
5
- import type { ISize } from "../AttributesDelegate";
5
+ import type { ICamera, ISize } from "../AttributesDelegate";
6
6
 
7
- export type SaveCamera = (camera: Camera) => void;
7
+ export type SaveCamera = (camera: ICamera) => void;
8
8
 
9
9
  export class CameraSynchronizer {
10
- public remoteCamera?: Camera;
10
+ public remoteCamera?: ICamera;
11
11
  public remoteSize?: ISize;
12
12
  protected rect?: TeleBoxRect;
13
13
  protected view?: View;
@@ -26,7 +26,7 @@ export class CameraSynchronizer {
26
26
  }
27
27
 
28
28
  // 远端 Camera 或者 size 更新
29
- public onRemoteUpdate = throttle((camera: Camera, size: ISize) => {
29
+ public onRemoteUpdate = throttle((camera: ICamera, size: ISize) => {
30
30
  this.remoteCamera = camera;
31
31
  this.remoteSize = size;
32
32
  if (this.remoteSize && this.rect) {
@@ -38,12 +38,17 @@ export class CameraSynchronizer {
38
38
  }
39
39
  const nextScale = camera.scale * scale;
40
40
  const moveCamera = () => {
41
- this.view?.moveCamera({
42
- centerX: camera.centerX,
43
- centerY: camera.centerY,
41
+ const config: Partial<Camera> & { animationMode: AnimationMode } = {
44
42
  scale: nextScale,
45
43
  animationMode: AnimationMode.Immediately,
46
- });
44
+ }
45
+ if (camera.centerX !== null) {
46
+ config.centerX = camera.centerX;
47
+ }
48
+ if (camera.centerY !== null) {
49
+ config.centerY = camera.centerY;
50
+ }
51
+ this.view?.moveCamera(config);
47
52
  }
48
53
  moveCamera();
49
54
  // TODO 直接调用 moveCamera 依然会出现 camera 错误的情况,这里暂时加一个 delay 保证 camera 是对的, 后续需要 SDK 进行修改
@@ -68,7 +73,7 @@ export class CameraSynchronizer {
68
73
  }
69
74
  }
70
75
 
71
- public onLocalCameraUpdate(camera: Camera) {
76
+ public onLocalCameraUpdate(camera: ICamera) {
72
77
  this.saveCamera(camera);
73
78
  this.remoteCamera = camera;
74
79
  }
@@ -31,18 +31,14 @@ export class ViewSync {
31
31
  private synchronizer: CameraSynchronizer;
32
32
 
33
33
  constructor(private context: ViewSyncContext) {
34
- this.synchronizer = new CameraSynchronizer((camera: Camera) => {
35
- const iCamera = {
36
- id: this.context.uid,
37
- ...camera,
38
- };
39
- this.context.camera$.setValue(iCamera, true);
34
+ this.synchronizer = new CameraSynchronizer((camera: ICamera) => {
35
+ this.context.camera$.setValue(camera, true);
40
36
  const notStoreCamera =
41
37
  this.context.viewMode$ && this.context.viewMode$.value === ViewMode.Freedom;
42
38
  if (notStoreCamera) {
43
39
  return;
44
40
  } else {
45
- this.context.storeCamera(iCamera);
41
+ this.context.storeCamera(camera);
46
42
  }
47
43
  });
48
44
  this.bindView(this.context.view$.value);
@@ -103,7 +99,8 @@ export class ViewSync {
103
99
  };
104
100
 
105
101
  private onCameraUpdatedByDevice = (camera: Camera) => {
106
- this.synchronizer.onLocalCameraUpdate(camera);
102
+ if (!camera) return;
103
+ this.synchronizer.onLocalCameraUpdate(Object.assign(camera, { id: this.context.uid }));
107
104
  const stage = this.context.stageRect$.value;
108
105
  if (stage) {
109
106
  const size = { width: stage.width, height: stage.height, id: this.context.uid };
package/src/constants.ts CHANGED
@@ -27,6 +27,11 @@ export enum AppAttributes {
27
27
  Position = "position",
28
28
  SceneIndex = "SceneIndex",
29
29
  ZIndex = "zIndex",
30
+ Visible = "visible",
31
+ Ratio = "ratio",
32
+ StageRatio = "stageRatio",
33
+ Draggable = "draggable",
34
+ Resizable = "resizable",
30
35
  }
31
36
 
32
37
  export enum AppEvents {
package/src/index.ts CHANGED
@@ -121,6 +121,11 @@ export type AppInitState = {
121
121
  sceneIndex?: number;
122
122
  boxState?: TeleBoxState; // 兼容旧版 telebox
123
123
  zIndex?: number;
124
+ visible?: boolean;
125
+ stageRatio?: number;
126
+ resizable?: boolean;
127
+ draggable?: boolean;
128
+ ratio?: number;
124
129
  };
125
130
 
126
131
  export type CursorMovePayload = { uid: string; state?: "leave"; position: Position };
@@ -130,6 +135,8 @@ export type MountParams = {
130
135
  container?: HTMLElement;
131
136
  /** 白板高宽比例, 默认为 9 / 16 */
132
137
  containerSizeRatio?: number;
138
+ /** @deprecated */
139
+ chessboard?: boolean;
133
140
  /** 是否高亮显示同步区域, 默认为 true */
134
141
  highlightStage?: boolean;
135
142
  collectorContainer?: HTMLElement;