@netless/window-manager 0.4.0-canary.0 → 0.4.0-canary.12
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/App/MagixEvent/index.d.ts +28 -0
- package/dist/App/Storage/StorageEvent.d.ts +8 -0
- package/dist/App/Storage/index.d.ts +38 -0
- package/dist/App/Storage/typings.d.ts +21 -0
- package/dist/App/Storage/utils.d.ts +5 -0
- package/dist/AppContext.d.ts +40 -16
- package/dist/AppListener.d.ts +1 -1
- package/dist/AppManager.d.ts +8 -7
- package/dist/AppProxy.d.ts +4 -4
- package/dist/Base/Context.d.ts +0 -1
- package/dist/BoxManager.d.ts +1 -0
- package/dist/BuiltinApps.d.ts +6 -0
- package/dist/ContainerResizeObserver.d.ts +10 -0
- package/dist/Cursor/Cursor.d.ts +2 -3
- package/dist/Cursor/index.d.ts +7 -4
- package/dist/Helper.d.ts +6 -0
- package/dist/ReconnectRefresher.d.ts +8 -3
- package/dist/Utils/Common.d.ts +3 -1
- package/dist/Utils/Reactive.d.ts +1 -1
- package/dist/{MainView.d.ts → View/MainView.d.ts} +3 -4
- package/dist/View/ViewManager.d.ts +13 -0
- package/dist/constants.d.ts +3 -7
- package/dist/index.d.ts +14 -14
- 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/dist/typings.d.ts +3 -2
- package/package.json +7 -5
- package/src/App/MagixEvent/index.ts +66 -0
- package/src/App/Storage/StorageEvent.ts +21 -0
- package/src/App/Storage/index.ts +284 -0
- package/src/App/Storage/typings.ts +21 -0
- package/src/App/Storage/utils.ts +17 -0
- package/src/AppContext.ts +61 -19
- package/src/AppListener.ts +9 -8
- package/src/AppManager.ts +71 -36
- package/src/AppProxy.ts +39 -48
- package/src/Base/Context.ts +0 -4
- package/src/BoxManager.ts +9 -8
- package/src/BuiltinApps.ts +24 -0
- package/src/ContainerResizeObserver.ts +62 -0
- package/src/Cursor/Cursor.ts +23 -34
- package/src/Cursor/index.ts +70 -41
- package/src/Helper.ts +30 -0
- package/src/ReconnectRefresher.ts +15 -4
- package/src/Utils/Common.ts +35 -13
- package/src/Utils/Reactive.ts +9 -3
- package/src/Utils/RoomHacker.ts +15 -0
- package/src/{MainView.ts → View/MainView.ts} +19 -27
- package/src/View/ViewManager.ts +53 -0
- package/src/constants.ts +2 -3
- package/src/index.ts +81 -117
- package/src/shim.d.ts +4 -0
- package/src/style.css +6 -0
- package/src/typings.ts +3 -2
- package/vite.config.js +4 -1
- package/dist/Utils/CameraStore.d.ts +0 -15
- package/dist/ViewManager.d.ts +0 -29
- package/dist/sdk.d.ts +0 -14
- package/src/Utils/CameraStore.ts +0 -72
- package/src/sdk.ts +0 -39
- package/src/viewManager.ts +0 -177
@@ -1,27 +1,29 @@
|
|
1
|
-
import { AnimationMode, reaction
|
2
|
-
import { Base } from "
|
3
|
-
import { callbacks, emitter } from "
|
1
|
+
import { AnimationMode, reaction } from "white-web-sdk";
|
2
|
+
import { Base } from "../Base";
|
3
|
+
import { callbacks, emitter } from "../index";
|
4
4
|
import { createView } from "./ViewManager";
|
5
5
|
import { debounce, isEmpty, isEqual } from "lodash";
|
6
|
-
import { Fields } from "
|
7
|
-
import {
|
6
|
+
import { Fields } from "../AttributesDelegate";
|
7
|
+
import { setViewFocusScenePath } from "../Utils/Common";
|
8
|
+
import { SideEffectManager } from "side-effect-manager";
|
8
9
|
import type { Camera, Size, View } from "white-web-sdk";
|
9
|
-
import type { AppManager } from "
|
10
|
+
import type { AppManager } from "../AppManager";
|
10
11
|
|
11
12
|
export class MainViewProxy extends Base {
|
12
13
|
private scale?: number;
|
13
|
-
private cameraStore = this.manager.cameraStore;
|
14
14
|
private started = false;
|
15
15
|
private mainViewIsAddListener = false;
|
16
16
|
private mainView: View;
|
17
17
|
private viewId = "mainView";
|
18
18
|
|
19
|
+
private sideEffectManager = new SideEffectManager();
|
20
|
+
|
19
21
|
constructor(manager: AppManager) {
|
20
22
|
super(manager);
|
21
23
|
this.mainView = this.createMainView();
|
22
24
|
this.moveCameraSizeByAttributes();
|
23
|
-
this.cameraStore.register(this.viewId, this.mainView);
|
24
25
|
emitter.once("mainViewMounted").then(() => {
|
26
|
+
this.addMainViewListener();
|
25
27
|
setTimeout(() => {
|
26
28
|
this.start();
|
27
29
|
if (!this.mainViewCamera || !this.mainViewSize) {
|
@@ -29,8 +31,12 @@ export class MainViewProxy extends Base {
|
|
29
31
|
}
|
30
32
|
}, 200); // 等待 mainView 挂载完毕再进行监听,否则会触发不必要的 onSizeUpdated
|
31
33
|
});
|
32
|
-
|
34
|
+
const playgroundSizeChangeListener = () => {
|
33
35
|
this.sizeChangeHandler(this.mainViewSize);
|
36
|
+
};
|
37
|
+
this.sideEffectManager.add(() => {
|
38
|
+
emitter.on("playgroundSizeChange", playgroundSizeChangeListener);
|
39
|
+
return () => emitter.off("playgroundSizeChange", playgroundSizeChangeListener);
|
34
40
|
});
|
35
41
|
}
|
36
42
|
|
@@ -75,7 +81,7 @@ export class MainViewProxy extends Base {
|
|
75
81
|
);
|
76
82
|
};
|
77
83
|
|
78
|
-
private sizeChangeHandler =
|
84
|
+
private sizeChangeHandler = debounce((size: Size) => {
|
79
85
|
if (size) {
|
80
86
|
this.moveCameraToContian(size);
|
81
87
|
this.moveCamera(this.mainViewCamera);
|
@@ -96,15 +102,12 @@ export class MainViewProxy extends Base {
|
|
96
102
|
if (mainViewScenePath) {
|
97
103
|
setViewFocusScenePath(mainView, mainViewScenePath);
|
98
104
|
}
|
99
|
-
if (!this.store.focus) {
|
100
|
-
this.switchViewModeToWriter();
|
101
|
-
}
|
102
105
|
return mainView;
|
103
106
|
}
|
104
107
|
|
105
108
|
private onCameraUpdatedByDevice = (camera: Camera) => {
|
106
109
|
this.store.setMainViewCamera({ ...camera, id: this.context.uid });
|
107
|
-
if (!isEqual(this.mainViewSize, {...this.mainView.size, id: this.context.uid})) {
|
110
|
+
if (!isEqual(this.mainViewSize, { ...this.mainView.size, id: this.context.uid })) {
|
108
111
|
this.setMainViewSize(this.view.size);
|
109
112
|
}
|
110
113
|
};
|
@@ -131,7 +134,6 @@ export class MainViewProxy extends Base {
|
|
131
134
|
|
132
135
|
public async mainViewClickHandler(): Promise<void> {
|
133
136
|
if (!this.manager.canOperate) return;
|
134
|
-
if (this.view.mode === ViewVisionMode.Writable) return;
|
135
137
|
this.store.cleanFocus();
|
136
138
|
this.context.blurFocusBox();
|
137
139
|
}
|
@@ -156,17 +158,6 @@ export class MainViewProxy extends Base {
|
|
156
158
|
callbacks.emit("cameraStateChange", this.cameraState);
|
157
159
|
};
|
158
160
|
|
159
|
-
public switchViewModeToWriter(): void {
|
160
|
-
if (!this.manager.canOperate) return;
|
161
|
-
if (this.view) {
|
162
|
-
if (this.view.mode === ViewVisionMode.Writable) return;
|
163
|
-
this.cameraStore.switchView(this.viewId, this.mainView, () => {
|
164
|
-
notifyMainViewModeChange(callbacks, ViewVisionMode.Writable);
|
165
|
-
setViewMode(this.view, ViewVisionMode.Writable);
|
166
|
-
});
|
167
|
-
}
|
168
|
-
}
|
169
|
-
|
170
161
|
public moveCameraToContian(size: Size): void {
|
171
162
|
if (!isEmpty(size)) {
|
172
163
|
this.view.moveCameraToContain({
|
@@ -195,6 +186,7 @@ export class MainViewProxy extends Base {
|
|
195
186
|
}
|
196
187
|
|
197
188
|
public stop() {
|
189
|
+
this.removeMainViewListener();
|
198
190
|
this.removeCameraListener();
|
199
191
|
this.manager.refresher?.remove(Fields.MainViewCamera);
|
200
192
|
this.manager.refresher?.remove(Fields.MainViewSize);
|
@@ -203,6 +195,6 @@ export class MainViewProxy extends Base {
|
|
203
195
|
|
204
196
|
public destroy() {
|
205
197
|
this.stop();
|
206
|
-
this.
|
198
|
+
this.sideEffectManager.flushAll();
|
207
199
|
}
|
208
200
|
}
|
@@ -0,0 +1,53 @@
|
|
1
|
+
import type { View , Displayer} from "white-web-sdk";
|
2
|
+
|
3
|
+
export class ViewManager {
|
4
|
+
public views: Map<string, View> = new Map();
|
5
|
+
|
6
|
+
constructor(private displayer: Displayer) {}
|
7
|
+
|
8
|
+
public createView(id: string): View {
|
9
|
+
const view = createView(this.displayer);
|
10
|
+
this.views.set(id, view);
|
11
|
+
return view;
|
12
|
+
}
|
13
|
+
|
14
|
+
public getView(id: string): View | undefined {
|
15
|
+
return this.views.get(id);
|
16
|
+
}
|
17
|
+
|
18
|
+
public destroyView(id: string): void {
|
19
|
+
const view = this.views.get(id);
|
20
|
+
if (view) {
|
21
|
+
view.release();
|
22
|
+
this.views.delete(id);
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
public setViewScenePath(id: string, scenePath: string): void {
|
27
|
+
const view = this.views.get(id);
|
28
|
+
if (view) {
|
29
|
+
view.focusScenePath = scenePath;
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
public destroy() {
|
34
|
+
this.views.forEach(view => {
|
35
|
+
view.release();
|
36
|
+
});
|
37
|
+
this.views.clear();
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
|
42
|
+
export const createView = (displayer: Displayer): View => {
|
43
|
+
const view = displayer.views.createView();
|
44
|
+
setDefaultCameraBound(view);
|
45
|
+
return view;
|
46
|
+
};
|
47
|
+
|
48
|
+
export const setDefaultCameraBound = (view: View) => {
|
49
|
+
view.setCameraBound({
|
50
|
+
maxContentMode: () => 10,
|
51
|
+
minContentMode: () => 0.1,
|
52
|
+
});
|
53
|
+
};
|
package/src/constants.ts
CHANGED
@@ -10,6 +10,7 @@ export enum Events {
|
|
10
10
|
SetMainViewScenePath = "SetMainViewScenePath",
|
11
11
|
SetMainViewSceneIndex = "SetMainViewSceneIndex",
|
12
12
|
SwitchViewsToFreedom = "SwitchViewsToFreedom",
|
13
|
+
MoveCameraToContain = "MoveCameraToContain"
|
13
14
|
}
|
14
15
|
|
15
16
|
export const MagixEventName = "__WindowManger";
|
@@ -36,13 +37,11 @@ export enum CursorState {
|
|
36
37
|
Normal = "normal",
|
37
38
|
}
|
38
39
|
|
39
|
-
export const REQUIRE_VERSION = "2.
|
40
|
+
export const REQUIRE_VERSION = "2.16.0";
|
40
41
|
|
41
42
|
export const MIN_WIDTH = 340 / 720;
|
42
43
|
export const MIN_HEIGHT = 340 / 720;
|
43
44
|
|
44
45
|
export const SET_SCENEPATH_DELAY = 100; // 设置 scenePath 的延迟事件
|
45
46
|
|
46
|
-
export const DEFAULT_COLLECTOR_STYLE = { right: "10px", bottom: "15px", position: "absolute" };
|
47
|
-
|
48
47
|
export const DEFAULT_CONTAINER_RATIO = 9 / 16;
|
package/src/index.ts
CHANGED
@@ -1,19 +1,19 @@
|
|
1
|
-
import AppDocsViewer from "@netless/app-docs-viewer";
|
2
|
-
import AppMediaPlayer, { setOptions } from "@netless/app-media-player";
|
3
1
|
import Emittery from "emittery";
|
4
2
|
import pRetry from "p-retry";
|
5
3
|
import { AppManager } from "./AppManager";
|
6
4
|
import { appRegister } from "./Register";
|
5
|
+
import { ContainerResizeObserver } from "./ContainerResizeObserver";
|
7
6
|
import { createBoxManager } from "./BoxManager";
|
8
7
|
import { CursorManager } from "./Cursor";
|
9
|
-
import { DEFAULT_CONTAINER_RATIO, REQUIRE_VERSION } from "./constants";
|
8
|
+
import { DEFAULT_CONTAINER_RATIO, Events, REQUIRE_VERSION } from "./constants";
|
10
9
|
import { Fields } from "./AttributesDelegate";
|
11
10
|
import { initDb } from "./Register/storage";
|
12
11
|
import { isNull, isObject } from "lodash";
|
13
12
|
import { log } from "./Utils/log";
|
13
|
+
import { ReconnectRefresher } from "./ReconnectRefresher";
|
14
14
|
import { replaceRoomFunction } from "./Utils/RoomHacker";
|
15
|
-
import {
|
16
|
-
import { setupWrapper } from "./
|
15
|
+
import { setupBuiltin } from "./BuiltinApps";
|
16
|
+
import { setupWrapper } from "./Helper";
|
17
17
|
import "./style.css";
|
18
18
|
import "@netless/telebox-insider/dist/style.css";
|
19
19
|
import {
|
@@ -59,8 +59,6 @@ import type { NetlessApp, RegisterParams } from "./typings";
|
|
59
59
|
import type { TeleBoxColorScheme, TeleBoxState } from "@netless/telebox-insider";
|
60
60
|
import type { AppProxy } from "./AppProxy";
|
61
61
|
|
62
|
-
const ResizeObserver = window.ResizeObserver || ResizeObserverPolyfill;
|
63
|
-
|
64
62
|
export type WindowMangerAttributes = {
|
65
63
|
modelValue?: string;
|
66
64
|
boxState: TELE_BOX_STATE;
|
@@ -81,14 +79,14 @@ export type AddAppOptions = {
|
|
81
79
|
|
82
80
|
export type setAppOptions = AddAppOptions & { appOptions?: any };
|
83
81
|
|
84
|
-
export type AddAppParams = {
|
82
|
+
export type AddAppParams<TAttributes = any> = {
|
85
83
|
kind: string;
|
86
84
|
// app 地址(本地 app 不需要传)
|
87
85
|
src?: string;
|
88
86
|
// 窗口配置
|
89
87
|
options?: AddAppOptions;
|
90
88
|
// 初始化 attributes
|
91
|
-
attributes?:
|
89
|
+
attributes?: TAttributes;
|
92
90
|
};
|
93
91
|
|
94
92
|
export type BaseInsertParams = {
|
@@ -139,6 +137,7 @@ export type EmitterEvent = {
|
|
139
137
|
observerIdChange: number;
|
140
138
|
boxStateChange: string;
|
141
139
|
playgroundSizeChange: DOMRect;
|
140
|
+
onReconnected: void;
|
142
141
|
};
|
143
142
|
|
144
143
|
export type EmitterType = Emittery<EmitterEvent>;
|
@@ -150,6 +149,9 @@ export type PublicEvent = {
|
|
150
149
|
darkModeChange: boolean;
|
151
150
|
prefersColorSchemeChange: TeleBoxColorScheme;
|
152
151
|
cameraStateChange: CameraState;
|
152
|
+
mainViewScenePathChange: string;
|
153
|
+
mainViewSceneIndexChange: number;
|
154
|
+
focusedChange: string | undefined;
|
153
155
|
};
|
154
156
|
|
155
157
|
export type MountParams = {
|
@@ -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 =
|
188
|
+
public version = __APP_VERSION__;
|
185
189
|
|
186
190
|
public appListeners?: AppListeners;
|
187
191
|
|
@@ -195,6 +199,8 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
195
199
|
private boxManager?: BoxManager;
|
196
200
|
private static params?: MountParams;
|
197
201
|
|
202
|
+
private containerResizeObserver?: ContainerResizeObserver;
|
203
|
+
|
198
204
|
constructor(context: InvisiblePluginContext) {
|
199
205
|
super(context);
|
200
206
|
WindowManager.displayer = context.displayer;
|
@@ -214,15 +220,16 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
214
220
|
if (room.phase !== RoomPhase.Connected) {
|
215
221
|
throw new Error("[WindowManager]: Room only Connected can be mount");
|
216
222
|
}
|
223
|
+
if (room.phase === RoomPhase.Connected && room.isWritable) {
|
224
|
+
// redo undo 需要设置这个属性
|
225
|
+
room.disableSerialization = false;
|
226
|
+
}
|
217
227
|
}
|
218
228
|
if (WindowManager.isCreated) {
|
219
229
|
throw new Error("[WindowManager]: Already created cannot be created again");
|
220
230
|
}
|
221
231
|
let manager = await this.initManager(room);
|
222
232
|
this.debug = Boolean(debug);
|
223
|
-
if (this.debug) {
|
224
|
-
setOptions({ verbose: true });
|
225
|
-
}
|
226
233
|
log("Already insert room", manager);
|
227
234
|
|
228
235
|
if (isRoom(this.displayer)) {
|
@@ -254,7 +261,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
254
261
|
}
|
255
262
|
|
256
263
|
if (params.container) {
|
257
|
-
manager.bindContainer(params.container
|
264
|
+
manager.bindContainer(params.container);
|
258
265
|
}
|
259
266
|
|
260
267
|
replaceRoomFunction(room, manager);
|
@@ -316,33 +323,56 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
316
323
|
style.textContent = overwriteStyles;
|
317
324
|
playground.appendChild(style);
|
318
325
|
}
|
319
|
-
manager.
|
326
|
+
manager.containerResizeObserver = ContainerResizeObserver.create(
|
327
|
+
playground,
|
328
|
+
sizer,
|
329
|
+
wrapper,
|
330
|
+
emitter
|
331
|
+
);
|
332
|
+
WindowManager.wrapper = wrapper;
|
320
333
|
return mainViewElement;
|
321
334
|
}
|
322
335
|
|
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
|
-
|
336
|
+
public bindContainer(container: HTMLElement) {
|
337
|
+
if (WindowManager.isCreated && WindowManager.container) {
|
338
|
+
if (WindowManager.container.firstChild) {
|
339
|
+
container.appendChild(WindowManager.container.firstChild);
|
340
|
+
}
|
341
|
+
} else {
|
342
|
+
if (WindowManager.params) {
|
343
|
+
const params = WindowManager.params;
|
344
|
+
const mainViewElement = WindowManager.initContainer(
|
345
|
+
this,
|
346
|
+
container,
|
347
|
+
params.chessboard,
|
348
|
+
params.overwriteStyles
|
349
|
+
);
|
350
|
+
const boxManager = createBoxManager(this, callbacks, emitter, {
|
351
|
+
collectorContainer: params.collectorContainer,
|
352
|
+
collectorStyles: params.collectorStyles,
|
353
|
+
prefersColorScheme: params.prefersColorScheme,
|
354
|
+
});
|
355
|
+
this.boxManager = boxManager;
|
356
|
+
this.appManager?.setBoxManager(boxManager);
|
357
|
+
this.bindMainView(mainViewElement, params.disableCameraTransform);
|
358
|
+
if (WindowManager.wrapper) {
|
359
|
+
this.cursorManager?.setupWrapper(WindowManager.wrapper);
|
360
|
+
}
|
361
|
+
}
|
362
|
+
}
|
363
|
+
this.boxManager?.updateManagerRect();
|
364
|
+
this.appManager?.refresh();
|
365
|
+
this.appManager?.resetMaximized();
|
366
|
+
this.appManager?.resetMinimized();
|
367
|
+
WindowManager.container = container;
|
368
|
+
}
|
369
|
+
|
370
|
+
public bindCollectorContainer(container: HTMLElement) {
|
371
|
+
if (WindowManager.isCreated && this.boxManager) {
|
372
|
+
this.boxManager.setCollectorContainer(container);
|
373
|
+
} else {
|
374
|
+
if (WindowManager.params) {
|
375
|
+
WindowManager.params.collectorContainer = container;
|
346
376
|
}
|
347
377
|
}
|
348
378
|
}
|
@@ -356,30 +386,10 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
356
386
|
return appRegister.register(params);
|
357
387
|
}
|
358
388
|
|
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
389
|
/**
|
380
390
|
* 创建一个 app 至白板
|
381
391
|
*/
|
382
|
-
public async addApp(params: AddAppParams): Promise<string | undefined> {
|
392
|
+
public async addApp<T = any>(params: AddAppParams<T>): Promise<string | undefined> {
|
383
393
|
if (this.appManager) {
|
384
394
|
if (!params.kind || typeof params.kind !== "string") {
|
385
395
|
throw new ParamsInvalidError();
|
@@ -476,10 +486,8 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
476
486
|
* 设置所有 app 的 readonly 模式
|
477
487
|
*/
|
478
488
|
public setReadonly(readonly: boolean): void {
|
479
|
-
|
480
|
-
|
481
|
-
this.appManager?.boxManager?.setReadonly(readonly);
|
482
|
-
}
|
489
|
+
this.readonly = readonly;
|
490
|
+
this.boxManager?.setReadonly(readonly);
|
483
491
|
}
|
484
492
|
|
485
493
|
/**
|
@@ -559,6 +567,10 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
559
567
|
}
|
560
568
|
}
|
561
569
|
|
570
|
+
public get focused(): string | undefined {
|
571
|
+
return this.attributes.focus;
|
572
|
+
}
|
573
|
+
|
562
574
|
/**
|
563
575
|
* 查询所有的 App
|
564
576
|
*/
|
@@ -593,6 +605,10 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
593
605
|
}>
|
594
606
|
): void {
|
595
607
|
this.mainView.moveCameraToContain(rectangle);
|
608
|
+
this.appManager?.dispatchInternalEvent(Events.MoveCameraToContain, rectangle);
|
609
|
+
setTimeout(() => {
|
610
|
+
this.appManager?.mainViewProxy.setCameraAndSize();
|
611
|
+
}, 1000);
|
596
612
|
}
|
597
613
|
|
598
614
|
public convertToPointInWorld(point: Point): Point {
|
@@ -695,62 +711,10 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
695
711
|
}
|
696
712
|
}
|
697
713
|
}
|
698
|
-
|
699
|
-
private containerResizeObserver?: ResizeObserver;
|
700
|
-
|
701
|
-
private observePlaygroundSize(
|
702
|
-
container: HTMLElement,
|
703
|
-
sizer: HTMLElement,
|
704
|
-
wrapper: HTMLDivElement
|
705
|
-
) {
|
706
|
-
this.updateSizer(container.getBoundingClientRect(), sizer, wrapper);
|
707
|
-
|
708
|
-
this.containerResizeObserver = new ResizeObserver(entries => {
|
709
|
-
const containerRect = entries[0]?.contentRect;
|
710
|
-
if (containerRect) {
|
711
|
-
this.updateSizer(containerRect, sizer, wrapper);
|
712
|
-
this.cursorManager?.updateContainerRect();
|
713
|
-
this.boxManager?.updateManagerRect();
|
714
|
-
emitter.emit("playgroundSizeChange", containerRect);
|
715
|
-
}
|
716
|
-
});
|
717
|
-
|
718
|
-
this.containerResizeObserver.observe(container);
|
719
|
-
}
|
720
|
-
|
721
|
-
private updateSizer(
|
722
|
-
{ width, height }: DOMRectReadOnly,
|
723
|
-
sizer: HTMLElement,
|
724
|
-
wrapper: HTMLDivElement
|
725
|
-
) {
|
726
|
-
if (width && height) {
|
727
|
-
if (height / width > WindowManager.containerSizeRatio) {
|
728
|
-
height = width * WindowManager.containerSizeRatio;
|
729
|
-
sizer.classList.toggle("netless-window-manager-sizer-horizontal", true);
|
730
|
-
} else {
|
731
|
-
width = height / WindowManager.containerSizeRatio;
|
732
|
-
sizer.classList.toggle("netless-window-manager-sizer-horizontal", false);
|
733
|
-
}
|
734
|
-
wrapper.style.width = `${width}px`;
|
735
|
-
wrapper.style.height = `${height}px`;
|
736
|
-
}
|
737
|
-
}
|
738
714
|
}
|
739
715
|
|
740
|
-
|
741
|
-
kind: AppDocsViewer.kind,
|
742
|
-
src: AppDocsViewer,
|
743
|
-
});
|
744
|
-
WindowManager.register({
|
745
|
-
kind: AppMediaPlayer.kind,
|
746
|
-
src: AppMediaPlayer,
|
747
|
-
});
|
748
|
-
|
749
|
-
export const BuiltinApps = {
|
750
|
-
DocsViewer: AppDocsViewer.kind as string,
|
751
|
-
MediaPlayer: AppMediaPlayer.kind as string,
|
752
|
-
};
|
716
|
+
setupBuiltin();
|
753
717
|
|
754
718
|
export * from "./typings";
|
755
719
|
|
756
|
-
export {
|
720
|
+
export { BuiltinApps } from "./BuiltinApps";
|
package/src/shim.d.ts
CHANGED
package/src/style.css
CHANGED
package/src/typings.ts
CHANGED
@@ -12,7 +12,7 @@ import type {
|
|
12
12
|
import type { AppContext } from "./AppContext";
|
13
13
|
import type { ReadonlyTeleBox, TeleBoxRect } from "@netless/telebox-insider";
|
14
14
|
|
15
|
-
export interface NetlessApp<Attributes = any,
|
15
|
+
export interface NetlessApp<Attributes = any, MagixEventPayloads = any, AppOptions = any, SetupResult = any> {
|
16
16
|
kind: string;
|
17
17
|
config?: {
|
18
18
|
/** Box width relative to whiteboard. 0~1. Default 0.5. */
|
@@ -28,7 +28,7 @@ export interface NetlessApp<Attributes = any, SetupResult = any, AppOptions = an
|
|
28
28
|
/** App only single instance. */
|
29
29
|
singleton?: boolean;
|
30
30
|
};
|
31
|
-
setup: (context: AppContext<Attributes, AppOptions>) => SetupResult;
|
31
|
+
setup: (context: AppContext<Attributes, MagixEventPayloads, AppOptions>) => SetupResult;
|
32
32
|
}
|
33
33
|
|
34
34
|
export type AppEmitterEvent<T = any> = {
|
@@ -76,3 +76,4 @@ export type AppListenerKeys = keyof AppEmitterEvent;
|
|
76
76
|
export type { AppContext } from "./AppContext";
|
77
77
|
export type { ReadonlyTeleBox, TeleBoxRect };
|
78
78
|
export type { SceneState, SceneDefinition, View, AnimationMode, Displayer, Room, Player };
|
79
|
+
export type { Storage, StorageStateChangedEvent, StorageStateChangedListener } from "./App/Storage";
|
package/vite.config.js
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
import path from "path";
|
2
2
|
import { defineConfig } from "vite";
|
3
3
|
import { svelte } from "@sveltejs/vite-plugin-svelte";
|
4
|
-
import { dependencies ,peerDependencies } from "./package.json"
|
4
|
+
import { dependencies ,peerDependencies, version } from "./package.json"
|
5
5
|
|
6
6
|
|
7
7
|
export default defineConfig(({ mode }) => {
|
8
8
|
const isProd = mode === "production";
|
9
9
|
|
10
10
|
return {
|
11
|
+
define: {
|
12
|
+
__APP_VERSION__: JSON.stringify(version),
|
13
|
+
},
|
11
14
|
plugins: [
|
12
15
|
svelte({
|
13
16
|
emitCss: false,
|
@@ -1,15 +0,0 @@
|
|
1
|
-
import type { Camera, View } from "white-web-sdk";
|
2
|
-
export declare class CameraStore {
|
3
|
-
private cameras;
|
4
|
-
private listeners;
|
5
|
-
setCamera(id: string, camera: Camera): void;
|
6
|
-
getCamera(id: string): Camera | undefined;
|
7
|
-
deleteCamera(id: string): void;
|
8
|
-
recoverCamera(id: string, view?: View): void;
|
9
|
-
register(id: string, view: View): void;
|
10
|
-
unregister(id: string, view?: View): void;
|
11
|
-
private onListener;
|
12
|
-
private offListener;
|
13
|
-
switchView(id: string, view: View | undefined, callback: () => void): Promise<void>;
|
14
|
-
private getOrCreateListener;
|
15
|
-
}
|
package/dist/ViewManager.d.ts
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
import { Base } from "./Base";
|
2
|
-
import type { View, Displayer } from "white-web-sdk";
|
3
|
-
import type { AppManager } from "./AppManager";
|
4
|
-
export declare class ViewManager extends Base {
|
5
|
-
private views;
|
6
|
-
private timer?;
|
7
|
-
private appTimer?;
|
8
|
-
private mainViewProxy;
|
9
|
-
private displayer;
|
10
|
-
constructor(manager: AppManager);
|
11
|
-
get currentScenePath(): string;
|
12
|
-
get mainView(): View;
|
13
|
-
createView(appId: string): View;
|
14
|
-
destroyView(appId: string): void;
|
15
|
-
private releaseView;
|
16
|
-
getView(appId: string): View | undefined;
|
17
|
-
switchMainViewToWriter(): Promise<boolean> | undefined;
|
18
|
-
freedomAllViews(): void;
|
19
|
-
switchAppToWriter(id: string): void;
|
20
|
-
destroy(): void;
|
21
|
-
}
|
22
|
-
export declare const createView: (displayer: Displayer) => View;
|
23
|
-
export declare const setDefaultCameraBound: (view: View) => void;
|
24
|
-
export declare const setupWrapper: (root: HTMLElement) => {
|
25
|
-
playground: HTMLDivElement;
|
26
|
-
wrapper: HTMLDivElement;
|
27
|
-
sizer: HTMLDivElement;
|
28
|
-
mainViewElement: HTMLDivElement;
|
29
|
-
};
|
package/dist/sdk.d.ts
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
import { WindowManager } from './index';
|
2
|
-
import type { MountParams } from "./index";
|
3
|
-
import type { WhiteWebSdkConfiguration, JoinRoomParams } from "white-web-sdk";
|
4
|
-
declare type WhiteWindowSDKConfiguration = Omit<WhiteWebSdkConfiguration, "useMobXState">;
|
5
|
-
declare type WindowJoinRoomParams = {
|
6
|
-
joinRoomParams: Omit<JoinRoomParams, "useMultiViews" | "disableMagixEventDispatchLimit">;
|
7
|
-
mountParams: Omit<MountParams, "room">;
|
8
|
-
};
|
9
|
-
export declare class WhiteWindowSDK {
|
10
|
-
private sdk;
|
11
|
-
constructor(params: WhiteWindowSDKConfiguration);
|
12
|
-
mount(params: WindowJoinRoomParams): Promise<WindowManager>;
|
13
|
-
}
|
14
|
-
export {};
|