@netless/window-manager 0.4.0-canary.6 → 0.4.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/.idea/inspectionProfiles/Project_Default.xml +7 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/.idea/window-manager.iml +12 -0
- package/.vscode/settings.json +1 -0
- package/CHANGELOG.md +39 -2
- package/README.md +3 -0
- package/dist/App/MagixEvent/index.d.ts +29 -0
- package/dist/App/Storage/index.d.ts +19 -6
- package/dist/App/Storage/typings.d.ts +4 -0
- package/dist/AppContext.d.ts +39 -17
- package/dist/AppListener.d.ts +2 -1
- package/dist/AppManager.d.ts +25 -11
- package/dist/AppProxy.d.ts +7 -8
- package/dist/AttributesDelegate.d.ts +2 -2
- package/dist/BoxManager.d.ts +6 -3
- package/dist/BuiltinApps.d.ts +5 -0
- package/dist/ContainerResizeObserver.d.ts +10 -0
- package/dist/Cursor/Cursor.d.ts +10 -12
- package/dist/Cursor/index.d.ts +6 -16
- package/dist/Helper.d.ts +7 -0
- package/dist/Register/storage.d.ts +5 -1
- package/dist/Utils/AppCreateQueue.d.ts +11 -0
- package/dist/Utils/Common.d.ts +7 -2
- package/dist/Utils/RoomHacker.d.ts +3 -3
- package/dist/{MainView.d.ts → View/MainView.d.ts} +5 -6
- package/dist/View/ViewManager.d.ts +13 -0
- package/dist/constants.d.ts +5 -7
- package/dist/index.d.ts +35 -16
- package/dist/index.es.js +41 -1
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +41 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/typings.d.ts +3 -2
- package/docs/advanced.md +39 -0
- package/docs/api.md +69 -6
- package/docs/concept.md +9 -0
- package/docs/replay.md +40 -0
- package/package.json +7 -6
- package/src/App/MagixEvent/index.ts +68 -0
- package/src/App/Storage/index.ts +90 -44
- package/src/App/Storage/typings.ts +8 -0
- package/src/AppContext.ts +61 -25
- package/src/AppListener.ts +28 -16
- package/src/AppManager.ts +260 -81
- package/src/AppProxy.ts +53 -64
- package/src/AttributesDelegate.ts +2 -2
- package/src/BoxManager.ts +40 -24
- package/src/BuiltinApps.ts +23 -0
- package/src/ContainerResizeObserver.ts +62 -0
- package/src/Cursor/Cursor.svelte +25 -21
- package/src/Cursor/Cursor.ts +25 -38
- package/src/Cursor/icons.ts +2 -0
- package/src/Cursor/index.ts +45 -139
- package/src/Helper.ts +41 -0
- package/src/Register/index.ts +25 -16
- package/src/Register/loader.ts +2 -2
- package/src/Register/storage.ts +6 -1
- package/src/Utils/AppCreateQueue.ts +54 -0
- package/src/Utils/Common.ts +69 -14
- package/src/Utils/RoomHacker.ts +44 -14
- package/src/{MainView.ts → View/MainView.ts} +25 -36
- package/src/View/ViewManager.ts +52 -0
- package/src/constants.ts +6 -4
- package/src/image/laser-pointer-cursor.svg +17 -0
- package/src/index.ts +164 -99
- package/src/shim.d.ts +5 -0
- package/src/style.css +12 -1
- package/src/typings.ts +3 -2
- package/vite.config.js +8 -2
- package/dist/Base/Context.d.ts +0 -13
- package/dist/Base/index.d.ts +0 -7
- package/dist/Utils/CameraStore.d.ts +0 -15
- package/dist/ViewManager.d.ts +0 -29
- package/dist/sdk.d.ts +0 -14
- package/src/Base/Context.ts +0 -49
- package/src/Base/index.ts +0 -10
- package/src/Utils/CameraStore.ts +0 -72
- package/src/sdk.ts +0 -39
- package/src/viewManager.ts +0 -177
package/src/index.ts
CHANGED
@@ -1,26 +1,26 @@
|
|
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 { checkVersion, setupWrapper } from "./Helper";
|
6
|
+
import { ContainerResizeObserver } from "./ContainerResizeObserver";
|
7
7
|
import { createBoxManager } from "./BoxManager";
|
8
8
|
import { CursorManager } from "./Cursor";
|
9
|
-
import { DEFAULT_CONTAINER_RATIO, Events
|
9
|
+
import { DEFAULT_CONTAINER_RATIO, Events } from "./constants";
|
10
10
|
import { Fields } from "./AttributesDelegate";
|
11
11
|
import { initDb } from "./Register/storage";
|
12
|
-
import {
|
12
|
+
import { InvisiblePlugin, isPlayer, isRoom, RoomPhase, ViewMode } from "white-web-sdk";
|
13
|
+
import { isEqual, isNull, isObject, omit } from "lodash";
|
13
14
|
import { log } from "./Utils/log";
|
15
|
+
import { ReconnectRefresher } from "./ReconnectRefresher";
|
14
16
|
import { replaceRoomFunction } from "./Utils/RoomHacker";
|
15
|
-
import {
|
16
|
-
import { setupWrapper } from "./ViewManager";
|
17
|
+
import { setupBuiltin } from "./BuiltinApps";
|
17
18
|
import "./style.css";
|
18
19
|
import "@netless/telebox-insider/dist/style.css";
|
19
|
-
import "@netless/app-docs-viewer/dist/style.css";
|
20
20
|
import {
|
21
21
|
addEmitterOnceListener,
|
22
22
|
ensureValidScenePath,
|
23
|
-
|
23
|
+
entireScenes,
|
24
24
|
isValidScenePath,
|
25
25
|
wait,
|
26
26
|
} from "./Utils/Common";
|
@@ -30,17 +30,8 @@ import {
|
|
30
30
|
AppManagerNotInitError,
|
31
31
|
InvalidScenePath,
|
32
32
|
ParamsInvalidError,
|
33
|
-
WhiteWebSDKInvalidError,
|
34
33
|
} from "./Utils/error";
|
35
|
-
import type { Apps } from "./AttributesDelegate";
|
36
|
-
import {
|
37
|
-
InvisiblePlugin,
|
38
|
-
isPlayer,
|
39
|
-
isRoom,
|
40
|
-
RoomPhase,
|
41
|
-
ViewMode,
|
42
|
-
WhiteVersion,
|
43
|
-
} from "white-web-sdk";
|
34
|
+
import type { Apps, Position } from "./AttributesDelegate";
|
44
35
|
import type {
|
45
36
|
Displayer,
|
46
37
|
SceneDefinition,
|
@@ -54,14 +45,12 @@ import type {
|
|
54
45
|
Rectangle,
|
55
46
|
ViewVisionMode,
|
56
47
|
CameraState,
|
48
|
+
Player,
|
57
49
|
} from "white-web-sdk";
|
58
50
|
import type { AppListeners } from "./AppListener";
|
59
51
|
import type { NetlessApp, RegisterParams } from "./typings";
|
60
52
|
import type { TeleBoxColorScheme, TeleBoxState } from "@netless/telebox-insider";
|
61
53
|
import type { AppProxy } from "./AppProxy";
|
62
|
-
import { ReconnectRefresher } from "./ReconnectRefresher";
|
63
|
-
|
64
|
-
const ResizeObserver = window.ResizeObserver || ResizeObserverPolyfill;
|
65
54
|
|
66
55
|
export type WindowMangerAttributes = {
|
67
56
|
modelValue?: string;
|
@@ -128,6 +117,8 @@ export type AppInitState = {
|
|
128
117
|
zIndex?: number;
|
129
118
|
};
|
130
119
|
|
120
|
+
export type CursorMovePayload = { uid: string; state?: "leave"; position: Position };
|
121
|
+
|
131
122
|
export type EmitterEvent = {
|
132
123
|
onCreated: undefined;
|
133
124
|
InitReplay: AppInitState;
|
@@ -142,6 +133,8 @@ export type EmitterEvent = {
|
|
142
133
|
boxStateChange: string;
|
143
134
|
playgroundSizeChange: DOMRect;
|
144
135
|
onReconnected: void;
|
136
|
+
removeScenes: string;
|
137
|
+
cursorMove: CursorMovePayload;
|
145
138
|
};
|
146
139
|
|
147
140
|
export type EmitterType = Emittery<EmitterEvent>;
|
@@ -153,10 +146,16 @@ export type PublicEvent = {
|
|
153
146
|
darkModeChange: boolean;
|
154
147
|
prefersColorSchemeChange: TeleBoxColorScheme;
|
155
148
|
cameraStateChange: CameraState;
|
149
|
+
mainViewScenePathChange: string;
|
150
|
+
mainViewSceneIndexChange: number;
|
151
|
+
focusedChange: string | undefined;
|
152
|
+
mainViewScenesLengthChange: number;
|
153
|
+
canRedoStepsChange: number;
|
154
|
+
canUndoStepsChange: number;
|
156
155
|
};
|
157
156
|
|
158
157
|
export type MountParams = {
|
159
|
-
room: Room;
|
158
|
+
room: Room | Player;
|
160
159
|
container?: HTMLElement;
|
161
160
|
/** 白板高宽比例, 默认为 9 / 16 */
|
162
161
|
containerSizeRatio?: number;
|
@@ -186,7 +185,8 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
186
185
|
public static containerSizeRatio = DEFAULT_CONTAINER_RATIO;
|
187
186
|
private static isCreated = false;
|
188
187
|
|
189
|
-
public version =
|
188
|
+
public version = __APP_VERSION__;
|
189
|
+
public dependencies = __APP_DEPENDENCIES__;
|
190
190
|
|
191
191
|
public appListeners?: AppListeners;
|
192
192
|
|
@@ -200,9 +200,12 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
200
200
|
private boxManager?: BoxManager;
|
201
201
|
private static params?: MountParams;
|
202
202
|
|
203
|
+
private containerResizeObserver?: ContainerResizeObserver;
|
204
|
+
|
203
205
|
constructor(context: InvisiblePluginContext) {
|
204
206
|
super(context);
|
205
207
|
WindowManager.displayer = context.displayer;
|
208
|
+
(window as any).NETLESS_DEPS = __APP_DEPENDENCIES__;
|
206
209
|
}
|
207
210
|
|
208
211
|
public static async mount(params: MountParams): Promise<WindowManager> {
|
@@ -214,20 +217,23 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
214
217
|
const cursor = params.cursor;
|
215
218
|
WindowManager.params = params;
|
216
219
|
|
217
|
-
|
220
|
+
checkVersion();
|
221
|
+
let manager: WindowManager | undefined = undefined;
|
218
222
|
if (isRoom(room)) {
|
219
223
|
if (room.phase !== RoomPhase.Connected) {
|
220
224
|
throw new Error("[WindowManager]: Room only Connected can be mount");
|
221
225
|
}
|
226
|
+
if (room.phase === RoomPhase.Connected && room.isWritable) {
|
227
|
+
// redo undo 需要设置这个属性
|
228
|
+
room.disableSerialization = false;
|
229
|
+
}
|
230
|
+
manager = await this.initManager(room);
|
222
231
|
}
|
223
232
|
if (WindowManager.isCreated) {
|
224
233
|
throw new Error("[WindowManager]: Already created cannot be created again");
|
225
234
|
}
|
226
|
-
|
235
|
+
|
227
236
|
this.debug = Boolean(debug);
|
228
|
-
if (this.debug) {
|
229
|
-
setOptions({ verbose: true });
|
230
|
-
}
|
231
237
|
log("Already insert room", manager);
|
232
238
|
|
233
239
|
if (isRoom(this.displayer)) {
|
@@ -237,7 +243,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
237
243
|
} else {
|
238
244
|
await pRetry(
|
239
245
|
async count => {
|
240
|
-
manager = await
|
246
|
+
manager = (await room.getInvisiblePlugin(WindowManager.kind)) as WindowManager;
|
241
247
|
if (!manager) {
|
242
248
|
log(`manager is empty. retrying ${count}`);
|
243
249
|
throw new Error();
|
@@ -247,16 +253,17 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
247
253
|
);
|
248
254
|
}
|
249
255
|
|
256
|
+
if (!manager) {
|
257
|
+
throw new Error("[WindowManager]: create manager failed");
|
258
|
+
}
|
259
|
+
|
250
260
|
if (containerSizeRatio) {
|
251
261
|
WindowManager.containerSizeRatio = containerSizeRatio;
|
252
262
|
}
|
253
263
|
await manager.ensureAttributes();
|
254
264
|
|
255
265
|
manager.appManager = new AppManager(manager);
|
256
|
-
|
257
|
-
if (cursor) {
|
258
|
-
manager.cursorManager = new CursorManager(manager.appManager);
|
259
|
-
}
|
266
|
+
manager.cursorManager = new CursorManager(manager.appManager, Boolean(cursor));
|
260
267
|
|
261
268
|
if (params.container) {
|
262
269
|
manager.bindContainer(params.container);
|
@@ -321,7 +328,12 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
321
328
|
style.textContent = overwriteStyles;
|
322
329
|
playground.appendChild(style);
|
323
330
|
}
|
324
|
-
manager.
|
331
|
+
manager.containerResizeObserver = ContainerResizeObserver.create(
|
332
|
+
playground,
|
333
|
+
sizer,
|
334
|
+
wrapper,
|
335
|
+
emitter
|
336
|
+
);
|
325
337
|
WindowManager.wrapper = wrapper;
|
326
338
|
return mainViewElement;
|
327
339
|
}
|
@@ -357,6 +369,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
357
369
|
this.appManager?.refresh();
|
358
370
|
this.appManager?.resetMaximized();
|
359
371
|
this.appManager?.resetMinimized();
|
372
|
+
this.appManager?.displayerWritableListener(!this.room.isWritable);
|
360
373
|
WindowManager.container = container;
|
361
374
|
}
|
362
375
|
|
@@ -420,6 +433,12 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
420
433
|
const appScenePath = appManager.store.getAppScenePath(appId);
|
421
434
|
if (appScenePath && appScenePath === scenePath) {
|
422
435
|
console.warn(`[WindowManager]: ScenePath ${scenePath} Already opened`);
|
436
|
+
if (this.boxManager) {
|
437
|
+
const topBox = this.boxManager.getTopBox();
|
438
|
+
if (topBox) {
|
439
|
+
this.boxManager.setZIndex(appId, topBox.zIndex + 1, false);
|
440
|
+
}
|
441
|
+
}
|
423
442
|
return;
|
424
443
|
}
|
425
444
|
}
|
@@ -427,11 +446,11 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
427
446
|
if (scenePath && scenes && scenes.length > 0) {
|
428
447
|
if (this.isDynamicPPT(scenes)) {
|
429
448
|
isDynamicPPT = true;
|
430
|
-
if (!this.displayer
|
449
|
+
if (!entireScenes(this.displayer)[scenePath]) {
|
431
450
|
this.room?.putScenes(scenePath, scenes);
|
432
451
|
}
|
433
452
|
} else {
|
434
|
-
if (!this.displayer
|
453
|
+
if (!entireScenes(this.displayer)[scenePath]) {
|
435
454
|
this.room?.putScenes(scenePath, [{ name: scenes[0].name }]);
|
436
455
|
}
|
437
456
|
}
|
@@ -464,7 +483,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
464
483
|
/**
|
465
484
|
* 返回 mainView 的 ScenePath
|
466
485
|
*/
|
467
|
-
public getMainViewScenePath(): string {
|
486
|
+
public getMainViewScenePath(): string | undefined {
|
468
487
|
return this.appManager?.store.getMainViewScenePath();
|
469
488
|
}
|
470
489
|
|
@@ -512,6 +531,35 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
512
531
|
this.viewMode = mode;
|
513
532
|
}
|
514
533
|
|
534
|
+
public setBoxState(boxState: TeleBoxState): void {
|
535
|
+
if (!this.canOperate) return;
|
536
|
+
switch (boxState) {
|
537
|
+
case "normal":
|
538
|
+
this.setMaximized(false);
|
539
|
+
this.setMinimized(false);
|
540
|
+
break;
|
541
|
+
case "maximized":
|
542
|
+
this.setMaximized(true);
|
543
|
+
this.setMinimized(false);
|
544
|
+
break;
|
545
|
+
case "minimized":
|
546
|
+
this.setMinimized(true);
|
547
|
+
break;
|
548
|
+
default:
|
549
|
+
break;
|
550
|
+
}
|
551
|
+
}
|
552
|
+
|
553
|
+
public setMaximized(maximized: boolean): void {
|
554
|
+
if (!this.canOperate) return;
|
555
|
+
this.boxManager?.setMaximized(maximized, false);
|
556
|
+
}
|
557
|
+
|
558
|
+
public setMinimized(minimized: boolean): void {
|
559
|
+
if (!this.canOperate) return;
|
560
|
+
this.boxManager?.setMinimized(minimized, false);
|
561
|
+
}
|
562
|
+
|
515
563
|
public get mainView(): View {
|
516
564
|
if (this.appManager) {
|
517
565
|
return this.appManager.mainViewProxy.view;
|
@@ -560,6 +608,48 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
560
608
|
}
|
561
609
|
}
|
562
610
|
|
611
|
+
public get focused(): string | undefined {
|
612
|
+
return this.attributes.focus;
|
613
|
+
}
|
614
|
+
|
615
|
+
public get mainViewSceneIndex(): number {
|
616
|
+
return this.appManager?.store.getMainViewSceneIndex();
|
617
|
+
}
|
618
|
+
|
619
|
+
public get mainViewSceneDir(): string {
|
620
|
+
if (this.appManager) {
|
621
|
+
return this.appManager?.getMainViewSceneDir();
|
622
|
+
} else {
|
623
|
+
throw new AppManagerNotInitError();
|
624
|
+
}
|
625
|
+
}
|
626
|
+
|
627
|
+
public get topApp(): string | undefined {
|
628
|
+
return this.boxManager?.getTopBox()?.id;
|
629
|
+
}
|
630
|
+
|
631
|
+
public get mainViewScenesLength(): number {
|
632
|
+
return this.appManager?.mainViewScenesLength || 0;
|
633
|
+
}
|
634
|
+
|
635
|
+
public get canRedoSteps(): number {
|
636
|
+
const focused = this.focused;
|
637
|
+
if (focused) {
|
638
|
+
return this.appManager?.focusApp?.view?.canRedoSteps || 0;
|
639
|
+
} else {
|
640
|
+
return this.mainView.canRedoSteps;
|
641
|
+
}
|
642
|
+
}
|
643
|
+
|
644
|
+
public get canUndoSteps(): number {
|
645
|
+
const focused = this.focused;
|
646
|
+
if (focused) {
|
647
|
+
return this.appManager?.focusApp?.view?.canUndoSteps || 0;
|
648
|
+
} else {
|
649
|
+
return this.mainView.canUndoSteps;
|
650
|
+
}
|
651
|
+
}
|
652
|
+
|
563
653
|
/**
|
564
654
|
* 查询所有的 App
|
565
655
|
*/
|
@@ -584,7 +674,14 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
584
674
|
public moveCamera(
|
585
675
|
camera: Partial<Camera> & { animationMode?: AnimationMode | undefined }
|
586
676
|
): void {
|
677
|
+
const pureCamera = omit(camera, ["animationMode"]);
|
678
|
+
const mainViewCamera = { ...this.mainView.camera };
|
679
|
+
if (isEqual({ ...mainViewCamera, ...pureCamera }, mainViewCamera)) return;
|
587
680
|
this.mainView.moveCamera(camera);
|
681
|
+
this.appManager?.dispatchInternalEvent(Events.MoveCamera, camera);
|
682
|
+
setTimeout(() => {
|
683
|
+
this.appManager?.mainViewProxy.setCameraAndSize();
|
684
|
+
}, 100);
|
588
685
|
}
|
589
686
|
|
590
687
|
public moveCameraToContain(
|
@@ -597,7 +694,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
597
694
|
this.appManager?.dispatchInternalEvent(Events.MoveCameraToContain, rectangle);
|
598
695
|
setTimeout(() => {
|
599
696
|
this.appManager?.mainViewProxy.setCameraAndSize();
|
600
|
-
},
|
697
|
+
}, 100);
|
601
698
|
}
|
602
699
|
|
603
700
|
public convertToPointInWorld(point: Point): Point {
|
@@ -668,18 +765,38 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
668
765
|
this.appManager?.boxManager?.setPrefersColorScheme(scheme);
|
669
766
|
}
|
670
767
|
|
671
|
-
|
672
|
-
const
|
673
|
-
|
768
|
+
public cleanCurrentScene(): void {
|
769
|
+
const focused = this.focused;
|
770
|
+
if (focused) {
|
771
|
+
this.appManager?.focusApp?.view?.cleanCurrentScene();
|
772
|
+
} else {
|
773
|
+
this.mainView.cleanCurrentScene();
|
774
|
+
}
|
674
775
|
}
|
675
776
|
|
676
|
-
|
677
|
-
const
|
678
|
-
if (
|
679
|
-
|
777
|
+
public redo(): number {
|
778
|
+
const focused = this.focused;
|
779
|
+
if (focused) {
|
780
|
+
return this.appManager?.focusApp?.view?.redo() || 0;
|
781
|
+
} else {
|
782
|
+
return this.mainView.redo();
|
783
|
+
}
|
784
|
+
}
|
785
|
+
|
786
|
+
public undo(): number {
|
787
|
+
const focused = this.focused;
|
788
|
+
if (focused) {
|
789
|
+
return this.appManager?.focusApp?.view?.undo() || 0;
|
790
|
+
} else {
|
791
|
+
return this.mainView.undo();
|
680
792
|
}
|
681
793
|
}
|
682
794
|
|
795
|
+
private isDynamicPPT(scenes: SceneDefinition[]) {
|
796
|
+
const sceneSrc = scenes[0]?.ppt?.src;
|
797
|
+
return sceneSrc?.startsWith("pptx://");
|
798
|
+
}
|
799
|
+
|
683
800
|
private async ensureAttributes() {
|
684
801
|
if (isNull(this.attributes)) {
|
685
802
|
await wait(50);
|
@@ -700,62 +817,10 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
700
817
|
}
|
701
818
|
}
|
702
819
|
}
|
703
|
-
|
704
|
-
private containerResizeObserver?: ResizeObserver;
|
705
|
-
|
706
|
-
private observePlaygroundSize(
|
707
|
-
container: HTMLElement,
|
708
|
-
sizer: HTMLElement,
|
709
|
-
wrapper: HTMLDivElement
|
710
|
-
) {
|
711
|
-
this.updateSizer(container.getBoundingClientRect(), sizer, wrapper);
|
712
|
-
|
713
|
-
this.containerResizeObserver = new ResizeObserver(entries => {
|
714
|
-
const containerRect = entries[0]?.contentRect;
|
715
|
-
if (containerRect) {
|
716
|
-
this.updateSizer(containerRect, sizer, wrapper);
|
717
|
-
this.cursorManager?.updateContainerRect();
|
718
|
-
this.boxManager?.updateManagerRect();
|
719
|
-
emitter.emit("playgroundSizeChange", containerRect);
|
720
|
-
}
|
721
|
-
});
|
722
|
-
|
723
|
-
this.containerResizeObserver.observe(container);
|
724
|
-
}
|
725
|
-
|
726
|
-
private updateSizer(
|
727
|
-
{ width, height }: DOMRectReadOnly,
|
728
|
-
sizer: HTMLElement,
|
729
|
-
wrapper: HTMLDivElement
|
730
|
-
) {
|
731
|
-
if (width && height) {
|
732
|
-
if (height / width > WindowManager.containerSizeRatio) {
|
733
|
-
height = width * WindowManager.containerSizeRatio;
|
734
|
-
sizer.classList.toggle("netless-window-manager-sizer-horizontal", true);
|
735
|
-
} else {
|
736
|
-
width = height / WindowManager.containerSizeRatio;
|
737
|
-
sizer.classList.toggle("netless-window-manager-sizer-horizontal", false);
|
738
|
-
}
|
739
|
-
wrapper.style.width = `${width}px`;
|
740
|
-
wrapper.style.height = `${height}px`;
|
741
|
-
}
|
742
|
-
}
|
743
820
|
}
|
744
821
|
|
745
|
-
|
746
|
-
kind: AppDocsViewer.kind,
|
747
|
-
src: AppDocsViewer,
|
748
|
-
});
|
749
|
-
WindowManager.register({
|
750
|
-
kind: AppMediaPlayer.kind,
|
751
|
-
src: AppMediaPlayer,
|
752
|
-
});
|
753
|
-
|
754
|
-
export const BuiltinApps = {
|
755
|
-
DocsViewer: AppDocsViewer.kind as string,
|
756
|
-
MediaPlayer: AppMediaPlayer.kind as string,
|
757
|
-
};
|
822
|
+
setupBuiltin();
|
758
823
|
|
759
824
|
export * from "./typings";
|
760
825
|
|
761
|
-
export {
|
826
|
+
export { BuiltinApps } from "./BuiltinApps";
|
package/src/shim.d.ts
CHANGED
package/src/style.css
CHANGED
@@ -122,7 +122,7 @@
|
|
122
122
|
left: 0;
|
123
123
|
top: 0;
|
124
124
|
will-change: transform;
|
125
|
-
transition: transform 0.
|
125
|
+
transition: transform 0.1s;
|
126
126
|
transform-origin: 0 0;
|
127
127
|
user-select: none;
|
128
128
|
}
|
@@ -153,6 +153,11 @@
|
|
153
153
|
margin-top: 12px;
|
154
154
|
}
|
155
155
|
|
156
|
+
.netless-window-manager-cursor-laserPointer-image {
|
157
|
+
margin-left: -22px;
|
158
|
+
margin-top: 3px;
|
159
|
+
}
|
160
|
+
|
156
161
|
.netless-window-manager-cursor-name {
|
157
162
|
width: 100%;
|
158
163
|
height: 48px;
|
@@ -167,3 +172,9 @@
|
|
167
172
|
display: flex;
|
168
173
|
justify-content: center;
|
169
174
|
}
|
175
|
+
|
176
|
+
.telebox-collector {
|
177
|
+
position: absolute;
|
178
|
+
right: 10px;
|
179
|
+
bottom: 15px;
|
180
|
+
}
|
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,19 @@
|
|
1
1
|
import path from "path";
|
2
2
|
import { defineConfig } from "vite";
|
3
3
|
import { svelte } from "@sveltejs/vite-plugin-svelte";
|
4
|
-
import { dependencies ,
|
4
|
+
import { dependencies, peerDependencies, version, devDependencies } 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
|
+
__APP_DEPENDENCIES__: JSON.stringify({
|
14
|
+
dependencies, peerDependencies, devDependencies
|
15
|
+
}),
|
16
|
+
},
|
11
17
|
plugins: [
|
12
18
|
svelte({
|
13
19
|
emitCss: false,
|
@@ -20,7 +26,7 @@ export default defineConfig(({ mode }) => {
|
|
20
26
|
lib: {
|
21
27
|
// eslint-disable-next-line no-undef
|
22
28
|
entry: path.resolve(__dirname, "src/index.ts"),
|
23
|
-
formats: ["es","umd"], // TODO cjs 版本待修复
|
29
|
+
formats: ["es", "umd"], // TODO cjs 版本待修复
|
24
30
|
name: "WindowManager",
|
25
31
|
fileName: "index"
|
26
32
|
},
|
package/dist/Base/Context.d.ts
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
import type { AppManager } from "../AppManager";
|
2
|
-
export declare class Context {
|
3
|
-
private manager;
|
4
|
-
observerId: number;
|
5
|
-
constructor(manager: AppManager);
|
6
|
-
get uid(): string;
|
7
|
-
findMember: (memberId: number) => import("white-web-sdk").RoomMember | undefined;
|
8
|
-
findMemberByUid: (uid: string) => import("white-web-sdk").RoomMember | undefined;
|
9
|
-
updateManagerRect(): void;
|
10
|
-
blurFocusBox(): void;
|
11
|
-
switchAppToWriter(id: string): void;
|
12
|
-
}
|
13
|
-
export declare const createContext: (manager: AppManager) => Context;
|
package/dist/Base/index.d.ts
DELETED
@@ -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 {};
|
package/src/Base/Context.ts
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
import { emitter } from "../index";
|
2
|
-
import type { AppManager } from "../AppManager";
|
3
|
-
|
4
|
-
export class Context {
|
5
|
-
public observerId: number;
|
6
|
-
|
7
|
-
constructor(private manager: AppManager) {
|
8
|
-
this.observerId = manager.displayer.observerId;
|
9
|
-
|
10
|
-
emitter.on("observerIdChange", id => {
|
11
|
-
this.observerId = id;
|
12
|
-
});
|
13
|
-
};
|
14
|
-
|
15
|
-
public get uid() {
|
16
|
-
return this.manager.room?.uid || "";
|
17
|
-
}
|
18
|
-
|
19
|
-
public findMember = (memberId: number) => {
|
20
|
-
const roomMembers = this.manager.room?.state.roomMembers;
|
21
|
-
return roomMembers?.find(member => member.memberId === memberId);
|
22
|
-
}
|
23
|
-
|
24
|
-
public findMemberByUid = (uid: string) => {
|
25
|
-
const roomMembers = this.manager.room?.state.roomMembers;
|
26
|
-
return roomMembers?.find(member => member.payload?.uid === uid);
|
27
|
-
}
|
28
|
-
|
29
|
-
public updateManagerRect() {
|
30
|
-
this.manager.boxManager?.updateManagerRect();
|
31
|
-
}
|
32
|
-
|
33
|
-
public blurFocusBox() {
|
34
|
-
this.manager.boxManager?.blurAllBox();
|
35
|
-
}
|
36
|
-
|
37
|
-
public switchAppToWriter(id: string) {
|
38
|
-
this.manager.viewManager.switchAppToWriter(id);
|
39
|
-
}
|
40
|
-
}
|
41
|
-
|
42
|
-
let context: Context;
|
43
|
-
|
44
|
-
export const createContext = (manager: AppManager) => {
|
45
|
-
if (!context) {
|
46
|
-
context = new Context(manager);
|
47
|
-
}
|
48
|
-
return context;
|
49
|
-
};
|