@netless/window-manager 0.3.17-canary.2 → 0.4.0-canary.1
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/CHANGELOG.md +16 -0
- package/README.md +4 -43
- package/dist/AppContext.d.ts +3 -2
- package/dist/AppListener.d.ts +2 -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/MainView.d.ts +1 -0
- package/dist/ReconnectRefresher.d.ts +6 -3
- package/dist/Utils/RoomHacker.d.ts +2 -2
- package/dist/Utils/error.d.ts +3 -0
- package/dist/constants.d.ts +2 -1
- package/dist/index.d.ts +13 -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 +3 -2
- package/src/AppContext.ts +2 -2
- package/src/AppListener.ts +14 -3
- package/src/AppManager.ts +87 -69
- 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 +93 -35
- package/src/Cursor/Cursor.ts +12 -5
- package/src/Cursor/index.ts +15 -8
- package/src/MainView.ts +11 -3
- package/src/ReconnectRefresher.ts +17 -10
- package/src/Utils/RoomHacker.ts +5 -5
- package/src/Utils/error.ts +6 -1
- package/src/constants.ts +1 -0
- package/src/index.ts +115 -103
- package/src/style.css +1 -1
- package/src/viewManager.ts +2 -2
- package/yarn-error.log +0 -4285
package/src/index.ts
CHANGED
@@ -4,8 +4,9 @@ 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
|
-
import { DEFAULT_CONTAINER_RATIO, REQUIRE_VERSION } from "./constants";
|
9
|
+
import { DEFAULT_CONTAINER_RATIO, Events, REQUIRE_VERSION } from "./constants";
|
9
10
|
import { Fields } from "./AttributesDelegate";
|
10
11
|
import { initDb } from "./Register/storage";
|
11
12
|
import { isNull, isObject } from "lodash";
|
@@ -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.1";
|
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,64 @@ 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
|
+
WindowManager.wrapper = wrapper;
|
321
|
+
return mainViewElement;
|
322
|
+
}
|
323
|
+
|
324
|
+
public bindContainer(container: HTMLElement, collectorContainer?: HTMLElement) {
|
325
|
+
if (WindowManager.isCreated && WindowManager.container) {
|
326
|
+
if (WindowManager.container.firstChild) {
|
327
|
+
container.appendChild(WindowManager.container.firstChild);
|
328
|
+
}
|
329
|
+
} else {
|
330
|
+
if (WindowManager.params) {
|
331
|
+
const params = WindowManager.params;
|
332
|
+
const mainViewElement = WindowManager.initContainer(
|
333
|
+
this,
|
334
|
+
container,
|
335
|
+
params.chessboard,
|
336
|
+
params.overwriteStyles
|
337
|
+
);
|
338
|
+
const boxManager = createBoxManager(this, callbacks, emitter, {
|
339
|
+
collectorContainer: collectorContainer,
|
340
|
+
collectorStyles: params.collectorStyles,
|
341
|
+
prefersColorScheme: params.prefersColorScheme,
|
342
|
+
});
|
343
|
+
this.boxManager = boxManager;
|
344
|
+
this.appManager?.setBoxManager(boxManager);
|
345
|
+
this.bindMainView(mainViewElement, params.disableCameraTransform);
|
346
|
+
if (WindowManager.wrapper) {
|
347
|
+
this.cursorManager?.setupWrapper(WindowManager.wrapper);
|
348
|
+
}
|
349
|
+
}
|
350
|
+
}
|
351
|
+
this.boxManager?.updateManagerRect();
|
352
|
+
this.appManager?.refresh();
|
353
|
+
this.appManager?.resetMaximized();
|
354
|
+
this.appManager?.resetMinimized();
|
355
|
+
WindowManager.container = container;
|
356
|
+
}
|
357
|
+
|
362
358
|
/**
|
363
359
|
* 注册插件
|
364
360
|
*/
|
@@ -368,6 +364,17 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
368
364
|
return appRegister.register(params);
|
369
365
|
}
|
370
366
|
|
367
|
+
public static setCollectorContainer(container: HTMLElement) {
|
368
|
+
const manager = this.displayer.getInvisiblePlugin(this.kind) as WindowManager;
|
369
|
+
if (this.isCreated && manager) {
|
370
|
+
manager.boxManager?.setCollectorContainer(container);
|
371
|
+
} else {
|
372
|
+
if (this.params) {
|
373
|
+
this.params.collectorContainer = container;
|
374
|
+
}
|
375
|
+
}
|
376
|
+
}
|
377
|
+
|
371
378
|
/**
|
372
379
|
* 创建一个 app 至白板
|
373
380
|
*/
|
@@ -470,7 +477,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
470
477
|
public setReadonly(readonly: boolean): void {
|
471
478
|
if (this.room?.isWritable) {
|
472
479
|
this.readonly = readonly;
|
473
|
-
this.appManager?.boxManager
|
480
|
+
this.appManager?.boxManager?.setReadonly(readonly);
|
474
481
|
}
|
475
482
|
}
|
476
483
|
|
@@ -531,21 +538,21 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
531
538
|
return this.appManager?.store.apps();
|
532
539
|
}
|
533
540
|
|
534
|
-
public get boxState(): TeleBoxState {
|
541
|
+
public get boxState(): TeleBoxState | undefined {
|
535
542
|
if (this.appManager) {
|
536
|
-
return this.appManager.boxManager
|
543
|
+
return this.appManager.boxManager?.boxState;
|
537
544
|
} else {
|
538
545
|
throw new AppManagerNotInitError();
|
539
546
|
}
|
540
547
|
}
|
541
548
|
|
542
549
|
public get darkMode(): boolean {
|
543
|
-
return Boolean(this.appManager?.boxManager
|
550
|
+
return Boolean(this.appManager?.boxManager?.darkMode);
|
544
551
|
}
|
545
552
|
|
546
|
-
public get prefersColorScheme(): TeleBoxColorScheme {
|
553
|
+
public get prefersColorScheme(): TeleBoxColorScheme | undefined {
|
547
554
|
if (this.appManager) {
|
548
|
-
return this.appManager.boxManager
|
555
|
+
return this.appManager.boxManager?.prefersColorScheme;
|
549
556
|
} else {
|
550
557
|
throw new AppManagerNotInitError();
|
551
558
|
}
|
@@ -585,6 +592,10 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
585
592
|
}>
|
586
593
|
): void {
|
587
594
|
this.mainView.moveCameraToContain(rectangle);
|
595
|
+
this.appManager?.dispatchInternalEvent(Events.MoveCameraToContain, rectangle);
|
596
|
+
setTimeout(() => {
|
597
|
+
this.appManager?.mainViewProxy.setCameraAndSize();
|
598
|
+
}, 1000);
|
588
599
|
}
|
589
600
|
|
590
601
|
public convertToPointInWorld(point: Point): Point {
|
@@ -613,12 +624,13 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
613
624
|
if (WindowManager.playground) {
|
614
625
|
WindowManager.playground.parentNode?.removeChild(WindowManager.playground);
|
615
626
|
}
|
627
|
+
WindowManager.params = undefined;
|
616
628
|
log("Destroyed");
|
617
629
|
}
|
618
630
|
|
619
|
-
private bindMainView(divElement: HTMLDivElement, disableCameraTransform: boolean) {
|
631
|
+
private bindMainView(divElement: HTMLDivElement, disableCameraTransform: boolean | undefined) {
|
620
632
|
if (this.appManager) {
|
621
|
-
this.appManager.bindMainView(divElement, disableCameraTransform);
|
633
|
+
this.appManager.bindMainView(divElement, Boolean(disableCameraTransform));
|
622
634
|
this.cursorManager?.setMainViewDivElement(divElement);
|
623
635
|
}
|
624
636
|
}
|
@@ -651,7 +663,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
651
663
|
}
|
652
664
|
|
653
665
|
public setPrefersColorScheme(scheme: TeleBoxColorScheme): void {
|
654
|
-
this.appManager?.boxManager
|
666
|
+
this.appManager?.boxManager?.setPrefersColorScheme(scheme);
|
655
667
|
}
|
656
668
|
|
657
669
|
private isDynamicPPT(scenes: SceneDefinition[]) {
|
@@ -701,7 +713,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
701
713
|
if (containerRect) {
|
702
714
|
this.updateSizer(containerRect, sizer, wrapper);
|
703
715
|
this.cursorManager?.updateContainerRect();
|
704
|
-
this.
|
716
|
+
this.boxManager?.updateManagerRect();
|
705
717
|
emitter.emit("playgroundSizeChange", containerRect);
|
706
718
|
}
|
707
719
|
});
|
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();
|