@netless/window-manager 0.4.0-canary.0 → 0.4.0-canary.4
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 +6 -0
- package/dist/AppListener.d.ts +1 -0
- package/dist/AppManager.d.ts +2 -2
- package/dist/AppProxy.d.ts +1 -1
- package/dist/Cursor/Cursor.d.ts +2 -3
- package/dist/Cursor/index.d.ts +7 -4
- package/dist/MainView.d.ts +1 -0
- package/dist/ReconnectRefresher.d.ts +8 -3
- package/dist/constants.d.ts +2 -1
- package/dist/index.d.ts +8 -6
- 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/package.json +3 -2
- package/src/AppListener.ts +8 -0
- package/src/AppManager.ts +13 -10
- package/src/AppProxy.ts +2 -2
- package/src/BoxManager.ts +0 -1
- package/src/Cursor/Cursor.ts +23 -34
- package/src/Cursor/index.ts +70 -41
- package/src/MainView.ts +11 -3
- package/src/ReconnectRefresher.ts +16 -4
- package/src/constants.ts +1 -0
- package/src/index.ts +55 -49
package/src/index.ts
CHANGED
@@ -6,7 +6,7 @@ import { AppManager } from "./AppManager";
|
|
6
6
|
import { appRegister } from "./Register";
|
7
7
|
import { createBoxManager } from "./BoxManager";
|
8
8
|
import { CursorManager } from "./Cursor";
|
9
|
-
import { DEFAULT_CONTAINER_RATIO, REQUIRE_VERSION } from "./constants";
|
9
|
+
import { DEFAULT_CONTAINER_RATIO, Events, REQUIRE_VERSION } from "./constants";
|
10
10
|
import { Fields } from "./AttributesDelegate";
|
11
11
|
import { initDb } from "./Register/storage";
|
12
12
|
import { isNull, isObject } from "lodash";
|
@@ -58,6 +58,7 @@ import type { AppListeners } from "./AppListener";
|
|
58
58
|
import type { NetlessApp, RegisterParams } from "./typings";
|
59
59
|
import type { TeleBoxColorScheme, TeleBoxState } from "@netless/telebox-insider";
|
60
60
|
import type { AppProxy } from "./AppProxy";
|
61
|
+
import { ReconnectRefresher } from "./ReconnectRefresher";
|
61
62
|
|
62
63
|
const ResizeObserver = window.ResizeObserver || ResizeObserverPolyfill;
|
63
64
|
|
@@ -81,14 +82,14 @@ export type AddAppOptions = {
|
|
81
82
|
|
82
83
|
export type setAppOptions = AddAppOptions & { appOptions?: any };
|
83
84
|
|
84
|
-
export type AddAppParams = {
|
85
|
+
export type AddAppParams<TAttributes = any> = {
|
85
86
|
kind: string;
|
86
87
|
// app 地址(本地 app 不需要传)
|
87
88
|
src?: string;
|
88
89
|
// 窗口配置
|
89
90
|
options?: AddAppOptions;
|
90
91
|
// 初始化 attributes
|
91
|
-
attributes?:
|
92
|
+
attributes?: TAttributes;
|
92
93
|
};
|
93
94
|
|
94
95
|
export type BaseInsertParams = {
|
@@ -139,6 +140,7 @@ export type EmitterEvent = {
|
|
139
140
|
observerIdChange: number;
|
140
141
|
boxStateChange: string;
|
141
142
|
playgroundSizeChange: DOMRect;
|
143
|
+
onReconnected: void;
|
142
144
|
};
|
143
145
|
|
144
146
|
export type EmitterType = Emittery<EmitterEvent>;
|
@@ -171,6 +173,8 @@ export type MountParams = {
|
|
171
173
|
export type CallbacksType = Emittery<PublicEvent>;
|
172
174
|
export const callbacks: CallbacksType = new Emittery();
|
173
175
|
|
176
|
+
export const reconnectRefresher = new ReconnectRefresher({ emitter });
|
177
|
+
|
174
178
|
export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
175
179
|
public static kind = "WindowManager";
|
176
180
|
public static displayer: Displayer;
|
@@ -181,7 +185,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
181
185
|
public static containerSizeRatio = DEFAULT_CONTAINER_RATIO;
|
182
186
|
private static isCreated = false;
|
183
187
|
|
184
|
-
public version = "0.4.0-canary.
|
188
|
+
public version = "0.4.0-canary.4";
|
185
189
|
|
186
190
|
public appListeners?: AppListeners;
|
187
191
|
|
@@ -254,7 +258,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
254
258
|
}
|
255
259
|
|
256
260
|
if (params.container) {
|
257
|
-
manager.bindContainer(params.container
|
261
|
+
manager.bindContainer(params.container);
|
258
262
|
}
|
259
263
|
|
260
264
|
replaceRoomFunction(room, manager);
|
@@ -317,32 +321,50 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
317
321
|
playground.appendChild(style);
|
318
322
|
}
|
319
323
|
manager.observePlaygroundSize(playground, sizer, wrapper);
|
324
|
+
WindowManager.wrapper = wrapper;
|
320
325
|
return mainViewElement;
|
321
326
|
}
|
322
327
|
|
323
|
-
public bindContainer(container: HTMLElement
|
324
|
-
if (WindowManager.
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
params.
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
328
|
+
public bindContainer(container: HTMLElement) {
|
329
|
+
if (WindowManager.isCreated && WindowManager.container) {
|
330
|
+
if (WindowManager.container.firstChild) {
|
331
|
+
container.appendChild(WindowManager.container.firstChild);
|
332
|
+
}
|
333
|
+
} else {
|
334
|
+
if (WindowManager.params) {
|
335
|
+
const params = WindowManager.params;
|
336
|
+
const mainViewElement = WindowManager.initContainer(
|
337
|
+
this,
|
338
|
+
container,
|
339
|
+
params.chessboard,
|
340
|
+
params.overwriteStyles
|
341
|
+
);
|
342
|
+
const boxManager = createBoxManager(this, callbacks, emitter, {
|
343
|
+
collectorContainer: params.collectorContainer,
|
344
|
+
collectorStyles: params.collectorStyles,
|
345
|
+
prefersColorScheme: params.prefersColorScheme,
|
346
|
+
});
|
347
|
+
this.boxManager = boxManager;
|
348
|
+
this.appManager?.setBoxManager(boxManager);
|
349
|
+
this.bindMainView(mainViewElement, params.disableCameraTransform);
|
350
|
+
if (WindowManager.wrapper) {
|
351
|
+
this.cursorManager?.setupWrapper(WindowManager.wrapper);
|
352
|
+
}
|
353
|
+
}
|
354
|
+
}
|
355
|
+
this.boxManager?.updateManagerRect();
|
356
|
+
this.appManager?.refresh();
|
357
|
+
this.appManager?.resetMaximized();
|
358
|
+
this.appManager?.resetMinimized();
|
359
|
+
WindowManager.container = container;
|
360
|
+
}
|
361
|
+
|
362
|
+
public bindCollectorContainer(container: HTMLElement) {
|
363
|
+
if (WindowManager.isCreated && this.boxManager) {
|
364
|
+
this.boxManager.setCollectorContainer(container);
|
365
|
+
} else {
|
366
|
+
if (WindowManager.params) {
|
367
|
+
WindowManager.params.collectorContainer = container;
|
346
368
|
}
|
347
369
|
}
|
348
370
|
}
|
@@ -356,30 +378,10 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
356
378
|
return appRegister.register(params);
|
357
379
|
}
|
358
380
|
|
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
|
-
|
379
381
|
/**
|
380
382
|
* 创建一个 app 至白板
|
381
383
|
*/
|
382
|
-
public async addApp(params: AddAppParams): Promise<string | undefined> {
|
384
|
+
public async addApp<T = any>(params: AddAppParams<T>): Promise<string | undefined> {
|
383
385
|
if (this.appManager) {
|
384
386
|
if (!params.kind || typeof params.kind !== "string") {
|
385
387
|
throw new ParamsInvalidError();
|
@@ -593,6 +595,10 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
593
595
|
}>
|
594
596
|
): void {
|
595
597
|
this.mainView.moveCameraToContain(rectangle);
|
598
|
+
this.appManager?.dispatchInternalEvent(Events.MoveCameraToContain, rectangle);
|
599
|
+
setTimeout(() => {
|
600
|
+
this.appManager?.mainViewProxy.setCameraAndSize();
|
601
|
+
}, 1000);
|
596
602
|
}
|
597
603
|
|
598
604
|
public convertToPointInWorld(point: Point): Point {
|