@netless/window-manager 0.3.18 → 0.4.0-canary.0
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.
- package/README.md +4 -43
- package/dist/AppContext.d.ts +3 -2
- package/dist/AppListener.d.ts +1 -1
- package/dist/AppManager.d.ts +10 -7
- package/dist/AppProxy.d.ts +3 -0
- package/dist/AttributesDelegate.d.ts +19 -11
- package/dist/Base/index.d.ts +1 -2
- package/dist/BoxManager.d.ts +23 -7
- package/dist/Cursor/index.d.ts +2 -1
- package/dist/ReconnectRefresher.d.ts +2 -1
- package/dist/Utils/RoomHacker.d.ts +2 -2
- package/dist/Utils/error.d.ts +3 -0
- package/dist/index.d.ts +14 -16
- package/dist/index.es.js +1 -1
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/style.css +1 -1
- package/docs/api.md +17 -0
- package/docs/migrate.md +42 -0
- package/package.json +2 -2
- package/src/AppContext.ts +2 -2
- package/src/AppListener.ts +6 -3
- package/src/AppManager.ts +82 -68
- package/src/AppProxy.ts +36 -17
- package/src/AttributesDelegate.ts +76 -49
- package/src/Base/Context.ts +2 -2
- package/src/Base/index.ts +2 -2
- package/src/BoxManager.ts +88 -31
- package/src/Cursor/Cursor.ts +12 -5
- package/src/Cursor/index.ts +15 -8
- package/src/ReconnectRefresher.ts +12 -8
- package/src/Utils/RoomHacker.ts +5 -5
- package/src/Utils/error.ts +6 -1
- package/src/index.ts +111 -102
- package/src/style.css +1 -1
- package/src/viewManager.ts +2 -2
package/src/Utils/error.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
|
1
2
|
export class AppCreateError extends Error {
|
2
3
|
override message = "[WindowManager]: app duplicate exists and cannot be created again";
|
3
4
|
}
|
@@ -28,4 +29,8 @@ export class BoxNotCreatedError extends Error {
|
|
28
29
|
|
29
30
|
export class InvalidScenePath extends Error {
|
30
31
|
override message = `[WindowManager]: ScenePath should start with "/"`;
|
31
|
-
}
|
32
|
+
}
|
33
|
+
|
34
|
+
export class BoxManagerNotFoundError extends Error {
|
35
|
+
override message = "[WindowManager]: boxManager not found";
|
36
|
+
}
|
package/src/index.ts
CHANGED
@@ -4,6 +4,7 @@ import Emittery from "emittery";
|
|
4
4
|
import pRetry from "p-retry";
|
5
5
|
import { AppManager } from "./AppManager";
|
6
6
|
import { appRegister } from "./Register";
|
7
|
+
import { createBoxManager } from "./BoxManager";
|
7
8
|
import { CursorManager } from "./Cursor";
|
8
9
|
import { DEFAULT_CONTAINER_RATIO, REQUIRE_VERSION } from "./constants";
|
9
10
|
import { Fields } from "./AttributesDelegate";
|
@@ -22,7 +23,7 @@ import {
|
|
22
23
|
isValidScenePath,
|
23
24
|
wait,
|
24
25
|
} from "./Utils/Common";
|
25
|
-
import type { TELE_BOX_STATE } from "./BoxManager";
|
26
|
+
import type { TELE_BOX_STATE, BoxManager } from "./BoxManager";
|
26
27
|
import {
|
27
28
|
AppCreateError,
|
28
29
|
AppManagerNotInitError,
|
@@ -108,6 +109,7 @@ export type AppSyncAttributes = {
|
|
108
109
|
state?: any;
|
109
110
|
isDynamicPPT?: boolean;
|
110
111
|
fullPath?: string;
|
112
|
+
createdAt?: number;
|
111
113
|
};
|
112
114
|
|
113
115
|
export type AppInitState = {
|
@@ -139,7 +141,8 @@ export type EmitterEvent = {
|
|
139
141
|
playgroundSizeChange: DOMRect;
|
140
142
|
};
|
141
143
|
|
142
|
-
export
|
144
|
+
export type EmitterType = Emittery<EmitterEvent>;
|
145
|
+
export const emitter: EmitterType = new Emittery();
|
143
146
|
|
144
147
|
export type PublicEvent = {
|
145
148
|
mainViewModeChange: ViewVisionMode;
|
@@ -151,7 +154,7 @@ export type PublicEvent = {
|
|
151
154
|
|
152
155
|
export type MountParams = {
|
153
156
|
room: Room;
|
154
|
-
container
|
157
|
+
container?: HTMLElement;
|
155
158
|
/** 白板高宽比例, 默认为 9 / 16 */
|
156
159
|
containerSizeRatio?: number;
|
157
160
|
/** 显示 PS 透明背景,默认 true */
|
@@ -165,7 +168,8 @@ export type MountParams = {
|
|
165
168
|
prefersColorScheme?: TeleBoxColorScheme;
|
166
169
|
};
|
167
170
|
|
168
|
-
export
|
171
|
+
export type CallbacksType = Emittery<PublicEvent>;
|
172
|
+
export const callbacks: CallbacksType = new Emittery();
|
169
173
|
|
170
174
|
export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
171
175
|
public static kind = "WindowManager";
|
@@ -177,7 +181,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
177
181
|
public static containerSizeRatio = DEFAULT_CONTAINER_RATIO;
|
178
182
|
private static isCreated = false;
|
179
183
|
|
180
|
-
public version = "0.
|
184
|
+
public version = "0.4.0-canary.0";
|
181
185
|
|
182
186
|
public appListeners?: AppListeners;
|
183
187
|
|
@@ -188,75 +192,22 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
188
192
|
public viewMode = ViewMode.Broadcaster;
|
189
193
|
public isReplay = isPlayer(this.displayer);
|
190
194
|
|
195
|
+
private boxManager?: BoxManager;
|
196
|
+
private static params?: MountParams;
|
197
|
+
|
191
198
|
constructor(context: InvisiblePluginContext) {
|
192
199
|
super(context);
|
200
|
+
WindowManager.displayer = context.displayer;
|
193
201
|
}
|
194
202
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
options?: {
|
204
|
-
chessboard: boolean;
|
205
|
-
containerSizeRatio: number;
|
206
|
-
collectorStyles?: Partial<CSSStyleDeclaration>;
|
207
|
-
debug?: boolean;
|
208
|
-
overwriteStyles?: string;
|
209
|
-
}
|
210
|
-
): Promise<WindowManager>;
|
211
|
-
|
212
|
-
public static async mount(params: MountParams): Promise<WindowManager>;
|
213
|
-
|
214
|
-
public static async mount(
|
215
|
-
params: MountParams | Room,
|
216
|
-
container?: HTMLElement,
|
217
|
-
collectorContainer?: HTMLElement,
|
218
|
-
options?: {
|
219
|
-
chessboard?: boolean;
|
220
|
-
containerSizeRatio: number;
|
221
|
-
collectorStyles?: Partial<CSSStyleDeclaration>;
|
222
|
-
debug?: boolean;
|
223
|
-
overwriteStyles?: string;
|
224
|
-
disableCameraTransform?: boolean;
|
225
|
-
}
|
226
|
-
): Promise<WindowManager> {
|
227
|
-
let room: Room;
|
228
|
-
let containerSizeRatio: number | undefined;
|
229
|
-
let collectorStyles: Partial<CSSStyleDeclaration> | undefined;
|
230
|
-
let debug: boolean | undefined;
|
231
|
-
let chessboard = true;
|
232
|
-
let overwriteStyles: string | undefined;
|
233
|
-
let cursor: boolean | undefined;
|
234
|
-
let disableCameraTransform = false;
|
235
|
-
let prefersColorScheme: TeleBoxColorScheme | undefined = "light";
|
236
|
-
if ("room" in params) {
|
237
|
-
room = params.room;
|
238
|
-
container = params.container;
|
239
|
-
collectorContainer = params.collectorContainer;
|
240
|
-
containerSizeRatio = params.containerSizeRatio;
|
241
|
-
collectorStyles = params.collectorStyles;
|
242
|
-
debug = params.debug;
|
243
|
-
if (params.chessboard != null) {
|
244
|
-
chessboard = params.chessboard;
|
245
|
-
}
|
246
|
-
overwriteStyles = params.overwriteStyles;
|
247
|
-
cursor = params.cursor;
|
248
|
-
disableCameraTransform = Boolean(params?.disableCameraTransform);
|
249
|
-
prefersColorScheme = params.prefersColorScheme;
|
250
|
-
} else {
|
251
|
-
room = params;
|
252
|
-
containerSizeRatio = options?.containerSizeRatio;
|
253
|
-
collectorStyles = options?.collectorStyles;
|
254
|
-
debug = options?.debug;
|
255
|
-
if (options?.chessboard != null) {
|
256
|
-
chessboard = options.chessboard;
|
257
|
-
}
|
258
|
-
overwriteStyles = options?.overwriteStyles;
|
259
|
-
}
|
203
|
+
public static async mount(params: MountParams): Promise<WindowManager> {
|
204
|
+
const room = params.room;
|
205
|
+
WindowManager.container = params.container;
|
206
|
+
const containerSizeRatio = params.containerSizeRatio;
|
207
|
+
const debug = params.debug;
|
208
|
+
|
209
|
+
const cursor = params.cursor;
|
210
|
+
WindowManager.params = params;
|
260
211
|
|
261
212
|
this.checkVersion();
|
262
213
|
if (isRoom(room)) {
|
@@ -264,9 +215,6 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
264
215
|
throw new Error("[WindowManager]: Room only Connected can be mount");
|
265
216
|
}
|
266
217
|
}
|
267
|
-
if (!container) {
|
268
|
-
throw new Error("[WindowManager]: Container must provide");
|
269
|
-
}
|
270
218
|
if (WindowManager.isCreated) {
|
271
219
|
throw new Error("[WindowManager]: Already created cannot be created again");
|
272
220
|
}
|
@@ -297,29 +245,19 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
297
245
|
if (containerSizeRatio) {
|
298
246
|
WindowManager.containerSizeRatio = containerSizeRatio;
|
299
247
|
}
|
300
|
-
WindowManager.container = container;
|
301
|
-
const { playground, wrapper, sizer, mainViewElement } = setupWrapper(container);
|
302
|
-
WindowManager.playground = playground;
|
303
|
-
if (chessboard) {
|
304
|
-
sizer.classList.add("netless-window-manager-chess-sizer");
|
305
|
-
}
|
306
|
-
if (overwriteStyles) {
|
307
|
-
const style = document.createElement("style");
|
308
|
-
style.textContent = overwriteStyles;
|
309
|
-
playground.appendChild(style);
|
310
|
-
}
|
311
248
|
await manager.ensureAttributes();
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
prefersColorScheme: prefersColorScheme,
|
316
|
-
});
|
317
|
-
manager.observePlaygroundSize(playground, sizer, wrapper);
|
249
|
+
|
250
|
+
manager.appManager = new AppManager(manager);
|
251
|
+
|
318
252
|
if (cursor) {
|
319
253
|
manager.cursorManager = new CursorManager(manager.appManager);
|
320
254
|
}
|
321
|
-
|
322
|
-
|
255
|
+
|
256
|
+
if (params.container) {
|
257
|
+
manager.bindContainer(params.container, params.collectorContainer);
|
258
|
+
}
|
259
|
+
|
260
|
+
replaceRoomFunction(room, manager);
|
323
261
|
emitter.emit("onCreated");
|
324
262
|
WindowManager.isCreated = true;
|
325
263
|
try {
|
@@ -359,6 +297,56 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
359
297
|
return manager;
|
360
298
|
}
|
361
299
|
|
300
|
+
private static initContainer(
|
301
|
+
manager: WindowManager,
|
302
|
+
container: HTMLElement,
|
303
|
+
chessboard: boolean | undefined,
|
304
|
+
overwriteStyles: string | undefined
|
305
|
+
) {
|
306
|
+
if (!WindowManager.container) {
|
307
|
+
WindowManager.container = container;
|
308
|
+
}
|
309
|
+
const { playground, wrapper, sizer, mainViewElement } = setupWrapper(container);
|
310
|
+
WindowManager.playground = playground;
|
311
|
+
if (chessboard) {
|
312
|
+
sizer.classList.add("netless-window-manager-chess-sizer");
|
313
|
+
}
|
314
|
+
if (overwriteStyles) {
|
315
|
+
const style = document.createElement("style");
|
316
|
+
style.textContent = overwriteStyles;
|
317
|
+
playground.appendChild(style);
|
318
|
+
}
|
319
|
+
manager.observePlaygroundSize(playground, sizer, wrapper);
|
320
|
+
return mainViewElement;
|
321
|
+
}
|
322
|
+
|
323
|
+
public bindContainer(container: HTMLElement, collectorContainer?: HTMLElement) {
|
324
|
+
if (WindowManager.params) {
|
325
|
+
const params = WindowManager.params;
|
326
|
+
const mainViewElement = WindowManager.initContainer(
|
327
|
+
this,
|
328
|
+
container,
|
329
|
+
params.chessboard,
|
330
|
+
params.overwriteStyles
|
331
|
+
);
|
332
|
+
const boxManager = createBoxManager(this, callbacks, emitter, {
|
333
|
+
collectorContainer: collectorContainer,
|
334
|
+
collectorStyles: params.collectorStyles,
|
335
|
+
prefersColorScheme: params.prefersColorScheme,
|
336
|
+
});
|
337
|
+
this.boxManager = boxManager;
|
338
|
+
this.appManager?.setBoxManager(boxManager);
|
339
|
+
this.bindMainView(mainViewElement, params.disableCameraTransform);
|
340
|
+
this.boxManager.updateManagerRect();
|
341
|
+
this.appManager?.refresh();
|
342
|
+
this.appManager?.resetMaximized();
|
343
|
+
this.appManager?.resetMinimized();
|
344
|
+
if (WindowManager.wrapper) {
|
345
|
+
this.cursorManager?.setupWrapper(WindowManager.wrapper);
|
346
|
+
}
|
347
|
+
}
|
348
|
+
}
|
349
|
+
|
362
350
|
/**
|
363
351
|
* 注册插件
|
364
352
|
*/
|
@@ -368,6 +356,26 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
368
356
|
return appRegister.register(params);
|
369
357
|
}
|
370
358
|
|
359
|
+
public static setContainer(container: HTMLElement) {
|
360
|
+
if (this.isCreated && WindowManager.container) {
|
361
|
+
if (WindowManager.container.firstChild) {
|
362
|
+
container.appendChild(WindowManager.container.firstChild);
|
363
|
+
}
|
364
|
+
}
|
365
|
+
WindowManager.container = container;
|
366
|
+
}
|
367
|
+
|
368
|
+
public static setCollectorContainer(container: HTMLElement) {
|
369
|
+
const manager = this.displayer.getInvisiblePlugin(this.kind) as WindowManager;
|
370
|
+
if (this.isCreated && manager) {
|
371
|
+
manager.boxManager?.setCollectorContainer(container);
|
372
|
+
} else {
|
373
|
+
if (this.params) {
|
374
|
+
this.params.collectorContainer = container;
|
375
|
+
}
|
376
|
+
}
|
377
|
+
}
|
378
|
+
|
371
379
|
/**
|
372
380
|
* 创建一个 app 至白板
|
373
381
|
*/
|
@@ -470,7 +478,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
470
478
|
public setReadonly(readonly: boolean): void {
|
471
479
|
if (this.room?.isWritable) {
|
472
480
|
this.readonly = readonly;
|
473
|
-
this.appManager?.boxManager
|
481
|
+
this.appManager?.boxManager?.setReadonly(readonly);
|
474
482
|
}
|
475
483
|
}
|
476
484
|
|
@@ -531,21 +539,21 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
531
539
|
return this.appManager?.store.apps();
|
532
540
|
}
|
533
541
|
|
534
|
-
public get boxState(): TeleBoxState {
|
542
|
+
public get boxState(): TeleBoxState | undefined {
|
535
543
|
if (this.appManager) {
|
536
|
-
return this.appManager.boxManager
|
544
|
+
return this.appManager.boxManager?.boxState;
|
537
545
|
} else {
|
538
546
|
throw new AppManagerNotInitError();
|
539
547
|
}
|
540
548
|
}
|
541
549
|
|
542
550
|
public get darkMode(): boolean {
|
543
|
-
return Boolean(this.appManager?.boxManager
|
551
|
+
return Boolean(this.appManager?.boxManager?.darkMode);
|
544
552
|
}
|
545
553
|
|
546
|
-
public get prefersColorScheme(): TeleBoxColorScheme {
|
554
|
+
public get prefersColorScheme(): TeleBoxColorScheme | undefined {
|
547
555
|
if (this.appManager) {
|
548
|
-
return this.appManager.boxManager
|
556
|
+
return this.appManager.boxManager?.prefersColorScheme;
|
549
557
|
} else {
|
550
558
|
throw new AppManagerNotInitError();
|
551
559
|
}
|
@@ -613,12 +621,13 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
613
621
|
if (WindowManager.playground) {
|
614
622
|
WindowManager.playground.parentNode?.removeChild(WindowManager.playground);
|
615
623
|
}
|
624
|
+
WindowManager.params = undefined;
|
616
625
|
log("Destroyed");
|
617
626
|
}
|
618
627
|
|
619
|
-
private bindMainView(divElement: HTMLDivElement, disableCameraTransform: boolean) {
|
628
|
+
private bindMainView(divElement: HTMLDivElement, disableCameraTransform: boolean | undefined) {
|
620
629
|
if (this.appManager) {
|
621
|
-
this.appManager.bindMainView(divElement, disableCameraTransform);
|
630
|
+
this.appManager.bindMainView(divElement, Boolean(disableCameraTransform));
|
622
631
|
this.cursorManager?.setMainViewDivElement(divElement);
|
623
632
|
}
|
624
633
|
}
|
@@ -651,7 +660,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
651
660
|
}
|
652
661
|
|
653
662
|
public setPrefersColorScheme(scheme: TeleBoxColorScheme): void {
|
654
|
-
this.appManager?.boxManager
|
663
|
+
this.appManager?.boxManager?.setPrefersColorScheme(scheme);
|
655
664
|
}
|
656
665
|
|
657
666
|
private isDynamicPPT(scenes: SceneDefinition[]) {
|
@@ -701,7 +710,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
701
710
|
if (containerRect) {
|
702
711
|
this.updateSizer(containerRect, sizer, wrapper);
|
703
712
|
this.cursorManager?.updateContainerRect();
|
704
|
-
this.
|
713
|
+
this.boxManager?.updateManagerRect();
|
705
714
|
emitter.emit("playgroundSizeChange", containerRect);
|
706
715
|
}
|
707
716
|
});
|
package/src/style.css
CHANGED
package/src/viewManager.ts
CHANGED
@@ -103,7 +103,7 @@ export class ViewManager extends Base {
|
|
103
103
|
setViewMode(this.mainView, ViewVisionMode.Freedom);
|
104
104
|
}
|
105
105
|
if (!this.mainView.focusScenePath) {
|
106
|
-
this.store.setMainViewFocusPath();
|
106
|
+
this.store.setMainViewFocusPath(this.mainView);
|
107
107
|
}
|
108
108
|
}
|
109
109
|
|
@@ -116,7 +116,7 @@ export class ViewManager extends Base {
|
|
116
116
|
this.appTimer = setTimeout(() => {
|
117
117
|
const appProxy = this.manager.appProxies.get(id);
|
118
118
|
if (appProxy) {
|
119
|
-
if (this.manager.boxManager
|
119
|
+
if (this.manager.boxManager?.minimized) return;
|
120
120
|
appProxy.setScenePath();
|
121
121
|
appProxy.switchToWritable();
|
122
122
|
appProxy.focusBox();
|