@netless/window-manager 0.3.18 → 0.4.0-canary.11

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 (75) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +4 -43
  3. package/dist/App/MagixEvent/index.d.ts +28 -0
  4. package/dist/App/Storage/StorageEvent.d.ts +8 -0
  5. package/dist/App/Storage/index.d.ts +38 -0
  6. package/dist/App/Storage/typings.d.ts +21 -0
  7. package/dist/App/Storage/utils.d.ts +5 -0
  8. package/dist/AppContext.d.ts +42 -17
  9. package/dist/AppListener.d.ts +2 -2
  10. package/dist/AppManager.d.ts +18 -14
  11. package/dist/AppProxy.d.ts +5 -3
  12. package/dist/AttributesDelegate.d.ts +19 -11
  13. package/dist/Base/Context.d.ts +0 -1
  14. package/dist/Base/index.d.ts +1 -2
  15. package/dist/BoxManager.d.ts +24 -7
  16. package/dist/BuiltinApps.d.ts +6 -0
  17. package/dist/ContainerResizeObserver.d.ts +10 -0
  18. package/dist/Cursor/Cursor.d.ts +2 -3
  19. package/dist/Cursor/index.d.ts +9 -5
  20. package/dist/Helper.d.ts +6 -0
  21. package/dist/ReconnectRefresher.d.ts +9 -3
  22. package/dist/Utils/Common.d.ts +3 -1
  23. package/dist/Utils/Reactive.d.ts +1 -1
  24. package/dist/Utils/RoomHacker.d.ts +2 -2
  25. package/dist/Utils/error.d.ts +3 -0
  26. package/dist/{MainView.d.ts → View/MainView.d.ts} +3 -4
  27. package/dist/View/ViewManager.d.ts +13 -0
  28. package/dist/constants.d.ts +3 -7
  29. package/dist/index.d.ts +25 -27
  30. package/dist/index.es.js +1 -1
  31. package/dist/index.es.js.map +1 -1
  32. package/dist/index.umd.js +1 -1
  33. package/dist/index.umd.js.map +1 -1
  34. package/dist/style.css +1 -1
  35. package/dist/typings.d.ts +3 -2
  36. package/docs/api.md +17 -0
  37. package/docs/migrate.md +42 -0
  38. package/package.json +6 -4
  39. package/src/App/MagixEvent/index.ts +66 -0
  40. package/src/App/Storage/StorageEvent.ts +21 -0
  41. package/src/App/Storage/index.ts +284 -0
  42. package/src/App/Storage/typings.ts +21 -0
  43. package/src/App/Storage/utils.ts +17 -0
  44. package/src/AppContext.ts +61 -21
  45. package/src/AppListener.ts +15 -11
  46. package/src/AppManager.ts +141 -95
  47. package/src/AppProxy.ts +49 -52
  48. package/src/AttributesDelegate.ts +76 -49
  49. package/src/Base/Context.ts +2 -6
  50. package/src/Base/index.ts +2 -2
  51. package/src/BoxManager.ts +89 -31
  52. package/src/BuiltinApps.ts +24 -0
  53. package/src/ContainerResizeObserver.ts +62 -0
  54. package/src/Cursor/Cursor.ts +35 -39
  55. package/src/Cursor/index.ts +79 -43
  56. package/src/Helper.ts +30 -0
  57. package/src/ReconnectRefresher.ts +25 -10
  58. package/src/Utils/Common.ts +35 -13
  59. package/src/Utils/Reactive.ts +9 -3
  60. package/src/Utils/RoomHacker.ts +20 -5
  61. package/src/Utils/error.ts +6 -1
  62. package/src/{MainView.ts → View/MainView.ts} +19 -27
  63. package/src/View/ViewManager.ts +53 -0
  64. package/src/constants.ts +2 -3
  65. package/src/index.ts +144 -171
  66. package/src/shim.d.ts +4 -0
  67. package/src/style.css +7 -1
  68. package/src/typings.ts +3 -2
  69. package/vite.config.js +4 -1
  70. package/dist/Utils/CameraStore.d.ts +0 -15
  71. package/dist/ViewManager.d.ts +0 -29
  72. package/dist/sdk.d.ts +0 -14
  73. package/src/Utils/CameraStore.ts +0 -72
  74. package/src/sdk.ts +0 -39
  75. package/src/viewManager.ts +0 -177
package/src/AppProxy.ts CHANGED
@@ -2,16 +2,15 @@ import Emittery from "emittery";
2
2
  import { AppAttributes, AppEvents, Events } from "./constants";
3
3
  import { AppContext } from "./AppContext";
4
4
  import { appRegister } from "./Register";
5
- import { autorun, ViewVisionMode } from "white-web-sdk";
6
- import { callbacks, emitter } from "./index";
5
+ import { autorun } from "white-web-sdk";
6
+ import { emitter } from "./index";
7
7
  import { Fields } from "./AttributesDelegate";
8
8
  import { get } from "lodash";
9
9
  import { log } from "./Utils/log";
10
10
  import {
11
- notifyMainViewModeChange,
12
11
  setScenePath,
13
12
  setViewFocusScenePath,
14
- setViewMode,
13
+ getScenePath
15
14
  } from "./Utils/Common";
16
15
  import type {
17
16
  AppEmitterEvent,
@@ -25,6 +24,7 @@ import type { AppManager } from "./AppManager";
25
24
  import type { NetlessApp } from "./typings";
26
25
  import type { ReadonlyTeleBox } from "@netless/telebox-insider";
27
26
  import { Base } from "./Base";
27
+ import { BoxManagerNotFoundError } from "./Utils/error";
28
28
 
29
29
  export class AppProxy extends Base {
30
30
  public id: string;
@@ -36,10 +36,12 @@ export class AppProxy extends Base {
36
36
  private boxManager = this.manager.boxManager;
37
37
  private appProxies = this.manager.appProxies;
38
38
  private viewManager = this.manager.viewManager;
39
- private cameraStore = this.manager.cameraStore;
40
39
  private kind: string;
41
40
  public isAddApp: boolean;
42
41
  private status: "normal" | "destroyed" = "normal";
42
+ private stateKey: string;
43
+ private appResult?: NetlessApp<any>;
44
+ private appContext?: AppContext<any, any>;
43
45
 
44
46
  constructor(
45
47
  private params: BaseInsertParams,
@@ -50,6 +52,7 @@ export class AppProxy extends Base {
50
52
  super(manager);
51
53
  this.kind = params.kind;
52
54
  this.id = appId;
55
+ this.stateKey = `${this.id}_state`;
53
56
  this.appProxies.set(this.id, this);
54
57
  this.appEmitter = new Emittery();
55
58
  this.appListener = this.makeAppEventListener(this.id);
@@ -93,17 +96,25 @@ export class AppProxy extends Base {
93
96
 
94
97
  public getFullScenePath(): string | undefined {
95
98
  if (this.scenePath) {
96
- return get(this.appAttributes, [Fields.FullPath], this.scenePath);
99
+ return get(this.appAttributes, [Fields.FullPath], this.getFullScenePathFromScenes());
97
100
  }
98
101
  }
99
102
 
103
+ private getFullScenePathFromScenes() {
104
+ const sceneIndex = get(this.appAttributes, ["state", "SceneIndex"], 0);
105
+ const fullPath = getScenePath(this.manager.room, this.scenePath, sceneIndex);
106
+ if (fullPath) {
107
+ this.setFullPath(fullPath);
108
+ }
109
+ return fullPath;
110
+ }
111
+
100
112
  public setFullPath(path: string) {
101
113
  this.manager.safeUpdateAttributes(["apps", this.id, Fields.FullPath], path);
102
114
  }
103
115
 
104
116
  public async baseInsertApp(
105
117
  skipUpdate = false,
106
- focus?: boolean
107
118
  ): Promise<{ appId: string; app: NetlessApp }> {
108
119
  const params = this.params;
109
120
  if (!params.kind) {
@@ -117,9 +128,6 @@ export class AppProxy extends Base {
117
128
  throw new Error(`[WindowManager]: app load failed ${params.kind} ${params.src}`);
118
129
  }
119
130
  this.context.updateManagerRect();
120
- if (focus) {
121
- this.focusApp();
122
- }
123
131
  return {
124
132
  appId: this.id,
125
133
  app: appImpl,
@@ -128,16 +136,15 @@ export class AppProxy extends Base {
128
136
 
129
137
  private focusApp() {
130
138
  this.focusBox();
131
- this.context.switchAppToWriter(this.id);
132
- this.store.setMainViewFocusPath();
139
+ this.store.setMainViewFocusPath(this.manager.mainView);
133
140
  }
134
141
 
135
142
  public get box(): ReadonlyTeleBox | undefined {
136
- return this.boxManager.getBox(this.id);
143
+ return this.boxManager?.getBox(this.id);
137
144
  }
138
145
 
139
146
  public focusBox() {
140
- this.boxManager.focusBox({ appId: this.id });
147
+ this.boxManager?.focusBox({ appId: this.id });
141
148
  }
142
149
 
143
150
  private async setupApp(
@@ -148,13 +155,17 @@ export class AppProxy extends Base {
148
155
  appOptions?: any
149
156
  ) {
150
157
  log("setupApp", appId, app, options);
151
- const context = new AppContext(this.manager, appId, this, appOptions);
158
+ if (!this.boxManager) {
159
+ throw new BoxManagerNotFoundError();
160
+ }
161
+ const context = new AppContext(this.manager, this.boxManager, appId, this, appOptions);
162
+ this.appContext = context;
152
163
  try {
153
164
  emitter.once(`${appId}${Events.WindowCreated}` as any).then(async () => {
154
165
  let boxInitState: AppInitState | undefined;
155
166
  if (!skipUpdate) {
156
167
  boxInitState = this.getAppInitState(appId);
157
- this.boxManager.updateBoxState(boxInitState);
168
+ this.boxManager?.updateBoxState(boxInitState);
158
169
  }
159
170
  this.appEmitter.onAny(this.appListener);
160
171
  this.appAttributesUpdateListener(appId);
@@ -162,12 +173,13 @@ export class AppProxy extends Base {
162
173
  setTimeout(async () => {
163
174
  // 延迟执行 setup, 防止初始化的属性没有更新成功
164
175
  const result = await app.setup(context);
176
+ this.appResult = result;
165
177
  appRegister.notifyApp(app.kind, "created", { appId, result });
166
178
  this.afterSetupApp(boxInitState);
167
179
  this.fixMobileSize();
168
180
  }, 50);
169
181
  });
170
- this.boxManager.createBox({
182
+ this.boxManager?.createBox({
171
183
  appId: appId,
172
184
  app,
173
185
  options,
@@ -182,9 +194,9 @@ export class AppProxy extends Base {
182
194
 
183
195
  // 兼容移动端创建时会出现 PPT 不适配的问题
184
196
  private fixMobileSize() {
185
- const box = this.boxManager.getBox(this.id);
197
+ const box = this.boxManager?.getBox(this.id);
186
198
  if (box) {
187
- this.boxManager.resizeBox({
199
+ this.boxManager?.resizeBox({
188
200
  appId: this.id,
189
201
  width: box.intrinsicWidth + 0.001,
190
202
  height: box.intrinsicHeight + 0.001,
@@ -195,11 +207,8 @@ export class AppProxy extends Base {
195
207
 
196
208
  private afterSetupApp(boxInitState: AppInitState | undefined): void {
197
209
  if (boxInitState) {
198
- if (boxInitState.focus && this.scenePath) {
199
- this.context.switchAppToWriter(this.id);
200
- }
201
210
  if (!boxInitState?.x || !boxInitState.y) {
202
- this.boxManager.setBoxInitState(this.id);
211
+ this.boxManager?.setBoxInitState(this.id);
203
212
  }
204
213
  }
205
214
  }
@@ -207,7 +216,7 @@ export class AppProxy extends Base {
207
216
  public onSeek(time: number) {
208
217
  this.appEmitter.emit("seek", time);
209
218
  const boxInitState = this.getAppInitState(this.id);
210
- this.boxManager.updateBoxState(boxInitState);
219
+ this.boxManager?.updateBoxState(boxInitState);
211
220
  }
212
221
 
213
222
  public async onReconnected() {
@@ -216,27 +225,8 @@ export class AppProxy extends Base {
216
225
  await this.destroy(true, false, true);
217
226
  const params = this.params;
218
227
  const appProxy = new AppProxy(params, this.manager, this.id, this.isAddApp);
219
- await appProxy.baseInsertApp(true, this.store.focus === this.id);
220
- this.boxManager.updateBoxState(currentAppState);
221
- }
222
-
223
- public switchToWritable() {
224
- appRegister.notifyApp(this.kind, "focus", { appId: this.id });
225
- this.cameraStore.switchView(this.id, this.view, () => {
226
- if (this.view) {
227
- if (this.view.mode === ViewVisionMode.Writable) return;
228
- try {
229
- if (this.manager.mainView.mode === ViewVisionMode.Writable) {
230
- this.store.setMainViewFocusPath();
231
- notifyMainViewModeChange(callbacks, ViewVisionMode.Freedom);
232
- setViewMode(this.manager.mainView, ViewVisionMode.Freedom);
233
- }
234
- setViewMode(this.view, ViewVisionMode.Writable);
235
- } catch (error) {
236
- log("switch view failed", error);
237
- }
238
- }
239
- });
228
+ await appProxy.baseInsertApp(true);
229
+ this.boxManager?.updateBoxState(currentAppState);
240
230
  }
241
231
 
242
232
  public getAppInitState = (id: string) => {
@@ -278,7 +268,7 @@ export class AppProxy extends Base {
278
268
  if (!this.manager.canOperate) return;
279
269
  switch (eventName) {
280
270
  case "setBoxSize": {
281
- this.boxManager.resizeBox({
271
+ this.boxManager?.resizeBox({
282
272
  appId,
283
273
  width: data.width,
284
274
  height: data.height,
@@ -287,7 +277,7 @@ export class AppProxy extends Base {
287
277
  break;
288
278
  }
289
279
  case "setBoxMinSize": {
290
- this.boxManager.setBoxMinSize({
280
+ this.boxManager?.setBoxMinSize({
291
281
  appId,
292
282
  minWidth: data.minwidth,
293
283
  minHeight: data.minheight,
@@ -295,7 +285,7 @@ export class AppProxy extends Base {
295
285
  break;
296
286
  }
297
287
  case "setBoxTitle": {
298
- this.boxManager.setBoxTitle({ appId, title: data.title });
288
+ this.boxManager?.setBoxTitle({ appId, title: data.title });
299
289
  break;
300
290
  }
301
291
  case AppEvents.destroy: {
@@ -307,7 +297,7 @@ export class AppProxy extends Base {
307
297
  break;
308
298
  }
309
299
  case "focus": {
310
- this.boxManager.focusBox({ appId: this.id });
300
+ this.boxManager?.focusBox({ appId: this.id });
311
301
  emitter.emit("focus", { appId: this.id });
312
302
  break;
313
303
  }
@@ -327,6 +317,14 @@ export class AppProxy extends Base {
327
317
  }
328
318
  });
329
319
  });
320
+ this.manager.refresher?.add(this.stateKey,() => {
321
+ return autorun(() => {
322
+ const appState = this.appAttributes?.state;
323
+ if (appState?.zIndex > 0 && appState.zIndex !== this.box?.zIndex) {
324
+ this.boxManager?.setZIndex(appId, appState.zIndex);
325
+ }
326
+ });
327
+ });
330
328
  };
331
329
 
332
330
  public setScenePath(): void {
@@ -346,7 +344,6 @@ export class AppProxy extends Base {
346
344
 
347
345
  private async createView(): Promise<View> {
348
346
  const view = await this.viewManager.createView(this.id);
349
- this.cameraStore.register(this.id, view);
350
347
  this.setViewFocusScenePath();
351
348
  return view;
352
349
  }
@@ -364,17 +361,17 @@ export class AppProxy extends Base {
364
361
  this.appEmitter.clearListeners();
365
362
  emitter.emit(`destroy-${this.id}` as any, { error });
366
363
  if (needCloseBox) {
367
- this.boxManager.closeBox(this.id, skipUpdate);
364
+ this.boxManager?.closeBox(this.id, skipUpdate);
368
365
  }
369
366
  if (cleanAttrs) {
370
367
  this.store.cleanAppAttributes(this.id);
371
368
  }
372
369
  this.appProxies.delete(this.id);
373
- this.cameraStore.unregister(this.id, this.view);
374
370
 
375
371
  this.viewManager.destroyView(this.id);
376
372
  this.manager.appStatus.delete(this.id);
377
373
  this.manager.refresher?.remove(this.id);
374
+ this.manager.refresher?.remove(this.stateKey);
378
375
  }
379
376
 
380
377
  public close(): Promise<void> {
@@ -2,8 +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 } from "white-web-sdk";
6
- import type { AppManager } from "./AppManager";
5
+ import type { Camera, Size, View } from "white-web-sdk";
7
6
  import type { Cursor } from "./Cursor/Cursor";
8
7
 
9
8
  export enum Fields {
@@ -17,7 +16,7 @@ export enum Fields {
17
16
  Cursors = "cursors",
18
17
  Position = "position",
19
18
  CursorState = "cursorState",
20
- FullPath = "fullPath"
19
+ FullPath = "fullPath",
21
20
  }
22
21
 
23
22
  export type Apps = {
@@ -33,15 +32,29 @@ export type Position = {
33
32
 
34
33
  export type PositionType = "main" | "app";
35
34
 
35
+ export type StoreContext = {
36
+ getAttributes: () => any;
37
+ safeUpdateAttributes: (keys: string[], value: any) => void;
38
+ safeSetAttributes: (attributes: any) => void;
39
+ }
36
40
  export class AttributesDelegate {
37
- constructor(private manager: AppManager) {}
41
+
42
+ constructor(private context: StoreContext) {}
43
+
44
+ public setContext(context: StoreContext) {
45
+ this.context = context;
46
+ }
47
+
48
+ public get attributes() {
49
+ return this.context.getAttributes();
50
+ }
38
51
 
39
52
  public apps(): Apps {
40
- return get(this.manager.attributes, [Fields.Apps]);
53
+ return get(this.attributes, [Fields.Apps]);
41
54
  }
42
55
 
43
56
  public get focus(): string | undefined {
44
- return get(this.manager.attributes, [Fields.Focus]);
57
+ return get(this.attributes, [Fields.Focus]);
45
58
  }
46
59
 
47
60
  public getAppAttributes(id: string): AppSyncAttributes {
@@ -53,13 +66,17 @@ export class AttributesDelegate {
53
66
  }
54
67
 
55
68
  public getMaximized() {
56
- return get(this.manager.attributes, ["maximized"])
69
+ return get(this.attributes, ["maximized"]);
70
+ }
71
+
72
+ public getMinimized() {
73
+ return get(this.attributes, ["minimized"]);
57
74
  }
58
75
 
59
76
  public setupAppAttributes(params: AddAppParams, id: string, isDynamicPPT: boolean) {
60
- const attributes = this.manager.attributes;
77
+ const attributes = this.attributes;
61
78
  if (!attributes.apps) {
62
- this.manager.safeSetAttributes({ apps: {} });
79
+ this.context.safeSetAttributes({ apps: {} });
63
80
  }
64
81
  const attrNames = ["scenePath", "title"];
65
82
  if (!isDynamicPPT) {
@@ -70,32 +87,32 @@ export class AttributesDelegate {
70
87
  if (typeof params.src === "string") {
71
88
  attrs.src = params.src;
72
89
  }
73
- this.manager.safeUpdateAttributes([Fields.Apps, id], attrs);
74
- this.manager.safeUpdateAttributes([Fields.Apps, id, Fields.State], {
90
+ attrs.createdAt = Date.now();
91
+ this.context.safeUpdateAttributes([Fields.Apps, id], attrs);
92
+ this.context.safeUpdateAttributes([Fields.Apps, id, Fields.State], {
75
93
  [AppAttributes.Size]: {},
76
94
  [AppAttributes.Position]: {},
77
95
  [AppAttributes.SceneIndex]: 0,
78
- [AppAttributes.ZIndex]: 100,
79
96
  });
80
97
  }
81
98
 
82
99
  public updateAppState(appId: string, stateName: AppAttributes, state: any) {
83
- if (get(this.manager.attributes, [Fields.Apps, appId, Fields.State])) {
84
- this.manager.safeUpdateAttributes([Fields.Apps, appId, Fields.State, stateName], state);
100
+ if (get(this.attributes, [Fields.Apps, appId, Fields.State])) {
101
+ this.context.safeUpdateAttributes([Fields.Apps, appId, Fields.State, stateName], state);
85
102
  }
86
103
  }
87
104
 
88
105
  public cleanAppAttributes(id: string) {
89
- this.manager.safeUpdateAttributes([Fields.Apps, id], undefined);
90
- this.manager.safeSetAttributes({ [id]: undefined });
91
- const focus = this.manager.attributes[Fields.Focus];
106
+ this.context.safeUpdateAttributes([Fields.Apps, id], undefined);
107
+ this.context.safeSetAttributes({ [id]: undefined });
108
+ const focus = this.attributes[Fields.Focus];
92
109
  if (focus === id) {
93
110
  this.cleanFocus();
94
111
  }
95
112
  }
96
113
 
97
114
  public cleanFocus() {
98
- this.manager.safeSetAttributes({ [Fields.Focus]: undefined });
115
+ this.context.safeSetAttributes({ [Fields.Focus]: undefined });
99
116
  }
100
117
 
101
118
  public getAppSceneIndex(id: string) {
@@ -107,82 +124,79 @@ export class AttributesDelegate {
107
124
  }
108
125
 
109
126
  public getMainViewScenePath() {
110
- return this.manager.attributes["_mainScenePath"];
127
+ return this.attributes["_mainScenePath"];
111
128
  }
112
129
 
113
130
  public getMainViewSceneIndex() {
114
- return this.manager.attributes["_mainSceneIndex"];
131
+ return this.attributes["_mainSceneIndex"];
115
132
  }
116
133
 
117
134
  public getBoxState() {
118
- return this.manager.attributes[Fields.BoxState];
135
+ return this.attributes[Fields.BoxState];
119
136
  }
120
137
 
121
138
  public setMainViewScenePath(scenePath: string) {
122
- this.manager.safeSetAttributes({ _mainScenePath: scenePath });
139
+ this.context.safeSetAttributes({ _mainScenePath: scenePath });
123
140
  }
124
141
 
125
142
  public setMainViewSceneIndex(index: number) {
126
- this.manager.safeSetAttributes({ _mainSceneIndex: index });
143
+ this.context.safeSetAttributes({ _mainSceneIndex: index });
127
144
  }
128
145
 
129
146
  public getMainViewCamera(): MainViewCamera {
130
- return get(this.manager.attributes, [Fields.MainViewCamera]);
147
+ return get(this.attributes, [Fields.MainViewCamera]);
131
148
  }
132
149
 
133
150
  public getMainViewSize(): MainViewSize {
134
- return get(this.manager.attributes, [Fields.MainViewSize]);
151
+ return get(this.attributes, [Fields.MainViewSize]);
135
152
  }
136
153
 
137
- public setMainViewCamera(camera: Camera & { id: string } | undefined) {
138
- this.manager.safeSetAttributes({ [Fields.MainViewCamera]: { ...camera } });
154
+ public setMainViewCamera(camera: (Camera & { id: string }) | undefined) {
155
+ this.context.safeSetAttributes({ [Fields.MainViewCamera]: { ...camera } });
139
156
  }
140
157
 
141
- public setMainViewSize(size: Size & { id: string } | undefined) {
142
- this.manager.safeSetAttributes({ [Fields.MainViewSize]: { ...size } });
158
+ public setMainViewSize(size: (Size & { id: string }) | undefined) {
159
+ this.context.safeSetAttributes({ [Fields.MainViewSize]: { ...size } });
143
160
  }
144
161
 
145
162
  public setAppFocus(appId: string, focus: boolean) {
146
163
  if (focus) {
147
- this.manager.safeSetAttributes({ [Fields.Focus]: appId });
164
+ this.context.safeSetAttributes({ [Fields.Focus]: appId });
148
165
  } else {
149
- this.manager.safeSetAttributes({ [Fields.Focus]: undefined });
166
+ this.context.safeSetAttributes({ [Fields.Focus]: undefined });
150
167
  }
151
168
  }
152
169
 
153
170
  public updateCursor(uid: string, position: Position) {
154
- if (!get(this.manager.attributes, [Fields.Cursors])) {
155
- this.manager.safeUpdateAttributes([Fields.Cursors], {});
171
+ if (!get(this.attributes, [Fields.Cursors])) {
172
+ this.context.safeUpdateAttributes([Fields.Cursors], {});
156
173
  }
157
- if (!get(this.manager.attributes, [Fields.Cursors, uid])) {
158
- this.manager.safeUpdateAttributes([Fields.Cursors, uid], {});
174
+ if (!get(this.attributes, [Fields.Cursors, uid])) {
175
+ this.context.safeUpdateAttributes([Fields.Cursors, uid], {});
159
176
  }
160
- this.manager.safeUpdateAttributes([Fields.Cursors, uid, Fields.Position], position);
177
+ this.context.safeUpdateAttributes([Fields.Cursors, uid, Fields.Position], position);
161
178
  }
162
179
 
163
180
  public updateCursorState(uid: string, cursorState: string | undefined) {
164
- if (!get(this.manager.attributes, [Fields.Cursors, uid])) {
165
- this.manager.safeUpdateAttributes([Fields.Cursors, uid], {});
181
+ if (!get(this.attributes, [Fields.Cursors, uid])) {
182
+ this.context.safeUpdateAttributes([Fields.Cursors, uid], {});
166
183
  }
167
- this.manager.safeUpdateAttributes(
168
- [Fields.Cursors, uid, Fields.CursorState],
169
- cursorState
170
- );
184
+ this.context.safeUpdateAttributes([Fields.Cursors, uid, Fields.CursorState], cursorState);
171
185
  }
172
186
 
173
187
  public getCursorState(uid: string) {
174
- return get(this.manager.attributes, [Fields.Cursors, uid, Fields.CursorState]);
188
+ return get(this.attributes, [Fields.Cursors, uid, Fields.CursorState]);
175
189
  }
176
190
 
177
191
  public cleanCursor(uid: string) {
178
- this.manager.safeUpdateAttributes([Fields.Cursors, uid], undefined);
192
+ this.context.safeUpdateAttributes([Fields.Cursors, uid], undefined);
179
193
  }
180
194
 
181
195
  // TODO 状态中保存一个 SceneName 优化性能
182
- public setMainViewFocusPath() {
196
+ public setMainViewFocusPath(mainView: View) {
183
197
  const scenePath = this.getMainViewScenePath();
184
198
  if (scenePath) {
185
- setViewFocusScenePath(this.manager.mainView, scenePath);
199
+ setViewFocusScenePath(mainView, scenePath);
186
200
  }
187
201
  }
188
202
  }
@@ -191,15 +205,28 @@ export type MainViewSize = {
191
205
  id: string;
192
206
  width: number;
193
207
  height: number;
194
- }
208
+ };
195
209
 
196
210
  export type MainViewCamera = {
197
211
  id: string;
198
212
  centerX: number;
199
213
  centerY: number;
200
214
  scale: number;
201
- }
215
+ };
202
216
 
203
217
  export type Cursors = {
204
218
  [key: string]: Cursor;
205
- }
219
+ };
220
+
221
+
222
+ export const store = new AttributesDelegate({
223
+ getAttributes: () => {
224
+ throw new Error("getAttributes not implemented")
225
+ },
226
+ safeSetAttributes: () => {
227
+ throw new Error("safeSetAttributes not implemented")
228
+ },
229
+ safeUpdateAttributes: () => {
230
+ throw new Error("safeUpdateAttributes not implemented")
231
+ },
232
+ });
@@ -27,15 +27,11 @@ export class Context {
27
27
  }
28
28
 
29
29
  public updateManagerRect() {
30
- this.manager.boxManager.updateManagerRect();
30
+ this.manager.boxManager?.updateManagerRect();
31
31
  }
32
32
 
33
33
  public blurFocusBox() {
34
- this.manager.boxManager.blurAllBox();
35
- }
36
-
37
- public switchAppToWriter(id: string) {
38
- this.manager.viewManager.switchAppToWriter(id);
34
+ this.manager.boxManager?.blurAllBox();
39
35
  }
40
36
  }
41
37
 
package/src/Base/index.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import type { AppManager } from "../AppManager";
2
- import { AttributesDelegate } from "../AttributesDelegate";
2
+ import { store } from "../AttributesDelegate";
3
3
  import { createContext } from "./Context";
4
4
 
5
5
  export class Base {
6
- public store = new AttributesDelegate(this.manager);
6
+ public store = store;
7
7
  public context = createContext(this.manager);
8
8
 
9
9
  constructor(public manager: AppManager) {}