@netless/window-manager 1.0.0-canary.22 → 1.0.0-canary.25
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/dist/App/AppContext.d.ts +1 -1
- package/dist/BoxManager.d.ts +3 -0
- package/dist/Cursor/index.d.ts +3 -2
- package/dist/Helper.d.ts +2 -0
- package/dist/View/CameraSynchronizer.d.ts +1 -1
- package/dist/index.cjs.js +12 -12
- package/dist/index.es.js +75 -48
- package/dist/index.umd.js +12 -12
- package/dist/style.css +1 -1
- package/docs/app-context.md +154 -26
- package/package.json +2 -2
- package/pnpm-lock.yaml +2 -9
- package/src/App/AppContext.ts +13 -5
- package/src/BoxManager.ts +12 -0
- package/src/Cursor/Cursor.ts +6 -2
- package/src/Cursor/index.ts +5 -5
- package/src/Helper.ts +20 -3
- package/src/View/CameraSynchronizer.ts +17 -26
- package/src/index.ts +8 -12
- package/src/style.css +2 -6
package/dist/index.es.js
CHANGED
@@ -19,7 +19,7 @@ var __spreadValues = (a2, b2) => {
|
|
19
19
|
var __spreadProps = (a2, b2) => __defProps(a2, __getOwnPropDescs(b2));
|
20
20
|
import pRetry from "p-retry";
|
21
21
|
import Emittery from "emittery";
|
22
|
-
import { debounce, isEqual, omit, isObject, has, get, size as size$1, mapValues, noop as noop$1, pick, isBoolean, isNumber, throttle,
|
22
|
+
import { debounce, isEqual, omit, isObject, has, get, size as size$1, mapValues, noop as noop$1, pick, isBoolean, isNumber, throttle, omitBy, isUndefined, isInteger, orderBy, isEmpty, isFunction, isNull } from "lodash";
|
23
23
|
import { ScenePathType, UpdateEventKind, listenUpdated, unlistenUpdated, reaction, WhiteVersion, autorun, toJS, listenDisposed, unlistenDisposed, AnimationMode, ViewMode, isPlayer, isRoom, ApplianceNames, RoomPhase, InvisiblePlugin } from "white-web-sdk";
|
24
24
|
import { v4 } from "uuid";
|
25
25
|
import { genUID, SideEffectManager } from "side-effect-manager";
|
@@ -972,6 +972,11 @@ class WhiteBoardView {
|
|
972
972
|
this.appProxy.updateSize(rect.width, rect.height);
|
973
973
|
}
|
974
974
|
}
|
975
|
+
const log = (...args) => {
|
976
|
+
if (WindowManager.debug) {
|
977
|
+
console.log(`[WindowManager]:`, ...args);
|
978
|
+
}
|
979
|
+
};
|
975
980
|
const setupWrapper = (root) => {
|
976
981
|
const playground = document.createElement("div");
|
977
982
|
playground.className = "netless-window-manager-playground";
|
@@ -1002,6 +1007,19 @@ const serializeRoomMembers = (members) => {
|
|
1002
1007
|
}, member);
|
1003
1008
|
});
|
1004
1009
|
};
|
1010
|
+
const createInvisiblePlugin = async (room) => {
|
1011
|
+
try {
|
1012
|
+
const manager = await room.createInvisiblePlugin(WindowManager, {});
|
1013
|
+
return manager;
|
1014
|
+
} catch (error) {
|
1015
|
+
if (error.message === `invisible plugin "WindowManager" exits`) {
|
1016
|
+
await wait(200);
|
1017
|
+
return room.getInvisiblePlugin(WindowManager.kind);
|
1018
|
+
} else {
|
1019
|
+
log("createInvisiblePlugin failed", error);
|
1020
|
+
}
|
1021
|
+
}
|
1022
|
+
};
|
1005
1023
|
class AppContext {
|
1006
1024
|
constructor(manager, appId, appProxy, appOptions) {
|
1007
1025
|
this.manager = manager;
|
@@ -1056,11 +1074,19 @@ class AppContext {
|
|
1056
1074
|
this.ensurePageSize(params == null ? void 0 : params.size);
|
1057
1075
|
}
|
1058
1076
|
this.whiteBoardView = new WhiteBoardView(view, this, this.appProxy, this.ensurePageSize);
|
1059
|
-
this.appProxy.sideEffectManager.add(() =>
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1077
|
+
this.appProxy.sideEffectManager.add(() => [
|
1078
|
+
this.box._contentStageRect$.subscribe((rect) => {
|
1079
|
+
viewWrapper.style.left = `${rect.x}px`;
|
1080
|
+
viewWrapper.style.top = `${rect.y}px`;
|
1081
|
+
viewWrapper.style.width = `${rect.width}px`;
|
1082
|
+
viewWrapper.style.height = `${rect.height}px`;
|
1083
|
+
}),
|
1084
|
+
() => {
|
1085
|
+
return () => {
|
1086
|
+
this.whiteBoardView = void 0;
|
1087
|
+
};
|
1088
|
+
}
|
1089
|
+
]);
|
1064
1090
|
this.appProxy.whiteBoardViewCreated$.setValue(true);
|
1065
1091
|
return this.whiteBoardView;
|
1066
1092
|
};
|
@@ -1147,7 +1173,7 @@ class AppContext {
|
|
1147
1173
|
get members() {
|
1148
1174
|
return this.manager.members;
|
1149
1175
|
}
|
1150
|
-
get
|
1176
|
+
get currentMember() {
|
1151
1177
|
const self2 = findMemberByUid(this.room, this.manager.uid);
|
1152
1178
|
if (!self2) {
|
1153
1179
|
throw new Error(`Member ${this.manager.uid} not found.`);
|
@@ -1219,13 +1245,14 @@ class AppPageStateImpl {
|
|
1219
1245
|
class CameraSynchronizer {
|
1220
1246
|
constructor(saveCamera) {
|
1221
1247
|
this.saveCamera = saveCamera;
|
1222
|
-
this.setRect =
|
1248
|
+
this.setRect = (rect) => {
|
1223
1249
|
this.rect = rect;
|
1224
1250
|
if (this.remoteCamera && this.remoteSize) {
|
1225
1251
|
this.onRemoteUpdate(this.remoteCamera, this.remoteSize);
|
1226
1252
|
}
|
1227
|
-
}
|
1253
|
+
};
|
1228
1254
|
this.onRemoteUpdate = throttle((camera, size2) => {
|
1255
|
+
var _a;
|
1229
1256
|
this.remoteCamera = camera;
|
1230
1257
|
this.remoteSize = size2;
|
1231
1258
|
if (this.remoteSize && this.rect) {
|
@@ -1236,22 +1263,17 @@ class CameraSynchronizer {
|
|
1236
1263
|
scale2 = this.rect.height / size2.height;
|
1237
1264
|
}
|
1238
1265
|
const nextScale = camera.scale * scale2;
|
1239
|
-
const
|
1240
|
-
|
1241
|
-
|
1242
|
-
scale: nextScale,
|
1243
|
-
animationMode: AnimationMode.Immediately
|
1244
|
-
};
|
1245
|
-
if (camera.centerX !== null) {
|
1246
|
-
config.centerX = camera.centerX;
|
1247
|
-
}
|
1248
|
-
if (camera.centerY !== null) {
|
1249
|
-
config.centerY = camera.centerY;
|
1250
|
-
}
|
1251
|
-
(_a = this.view) == null ? void 0 : _a.moveCamera(config);
|
1266
|
+
const config = {
|
1267
|
+
scale: nextScale,
|
1268
|
+
animationMode: AnimationMode.Immediately
|
1252
1269
|
};
|
1253
|
-
|
1254
|
-
|
1270
|
+
if (camera.centerX !== null) {
|
1271
|
+
config.centerX = camera.centerX;
|
1272
|
+
}
|
1273
|
+
if (camera.centerY !== null) {
|
1274
|
+
config.centerY = camera.centerY;
|
1275
|
+
}
|
1276
|
+
(_a = this.view) == null ? void 0 : _a.moveCamera(config);
|
1255
1277
|
}
|
1256
1278
|
}, 10);
|
1257
1279
|
}
|
@@ -1259,20 +1281,16 @@ class CameraSynchronizer {
|
|
1259
1281
|
this.view = view;
|
1260
1282
|
}
|
1261
1283
|
onRemoteSizeUpdate(size2) {
|
1284
|
+
var _a;
|
1262
1285
|
this.remoteSize = size2;
|
1263
1286
|
const needMoveCamera = !isEqual(pick(this.rect, ["width", "height"]), pick(size2, ["width", "height"]));
|
1264
1287
|
if (this.rect && this.remoteCamera && needMoveCamera) {
|
1265
1288
|
const scale2 = this.rect.width / size2.width;
|
1266
1289
|
const nextScale = this.remoteCamera.scale * scale2;
|
1267
|
-
|
1268
|
-
|
1269
|
-
|
1270
|
-
|
1271
|
-
animationMode: AnimationMode.Immediately
|
1272
|
-
});
|
1273
|
-
};
|
1274
|
-
moveCamera();
|
1275
|
-
delay(moveCamera, 50);
|
1290
|
+
(_a = this.view) == null ? void 0 : _a.moveCamera({
|
1291
|
+
scale: nextScale,
|
1292
|
+
animationMode: AnimationMode.Immediately
|
1293
|
+
});
|
1276
1294
|
}
|
1277
1295
|
}
|
1278
1296
|
onLocalCameraUpdate(camera) {
|
@@ -1545,11 +1563,6 @@ const store = new AttributesDelegate({
|
|
1545
1563
|
throw new Error("safeUpdateAttributes not implemented");
|
1546
1564
|
}
|
1547
1565
|
});
|
1548
|
-
const log = (...args) => {
|
1549
|
-
if (WindowManager.debug) {
|
1550
|
-
console.log(`[WindowManager]:`, ...args);
|
1551
|
-
}
|
1552
|
-
};
|
1553
1566
|
class AppProxy {
|
1554
1567
|
constructor(params, manager, appId, isAddApp) {
|
1555
1568
|
var _a;
|
@@ -4760,6 +4773,15 @@ const createBoxManager = (manager, callbacks2, emitter2, boxEmitter2, options) =
|
|
4760
4773
|
class BoxManager {
|
4761
4774
|
constructor(context, createTeleBoxManagerConfig) {
|
4762
4775
|
this.context = context;
|
4776
|
+
this.mainViewElement$ = new Val(void 0);
|
4777
|
+
this.updateStyle = (element2, rect) => {
|
4778
|
+
if (!element2)
|
4779
|
+
return;
|
4780
|
+
element2.style.width = rect.width + "px";
|
4781
|
+
element2.style.height = rect.height + "px";
|
4782
|
+
element2.style.left = rect.x + "px";
|
4783
|
+
element2.style.top = rect.y + "px";
|
4784
|
+
};
|
4763
4785
|
this.sideEffectManager = new SideEffectManager();
|
4764
4786
|
const { emitter: emitter2, callbacks: callbacks2, boxEmitter: boxEmitter2 } = context;
|
4765
4787
|
this.teleBoxManager = this.setupBoxManager(createTeleBoxManagerConfig);
|
@@ -4828,6 +4850,7 @@ class BoxManager {
|
|
4828
4850
|
this.context.updateAppState(box.id, AppAttributes.ZIndex, box.zIndex);
|
4829
4851
|
}),
|
4830
4852
|
this.teleBoxManager._stageRect$.subscribe((stage) => {
|
4853
|
+
this.updateStyle(this.mainViewElement$.value, stage);
|
4831
4854
|
emitter2.emit("playgroundSizeChange", stage);
|
4832
4855
|
this.context.notifyContainerRectUpdate(stage);
|
4833
4856
|
}),
|
@@ -5636,11 +5659,14 @@ class Cursor {
|
|
5636
5659
|
let translateX = point.x - 2;
|
5637
5660
|
let translateY = point.y - 18;
|
5638
5661
|
if (type === "app") {
|
5639
|
-
const wrapperRect = this.cursorManager.
|
5662
|
+
const wrapperRect = this.cursorManager.playgroundRect;
|
5640
5663
|
if (wrapperRect) {
|
5641
5664
|
translateX = translateX + rect.x - wrapperRect.x;
|
5642
5665
|
translateY = translateY + rect.y - wrapperRect.y;
|
5643
5666
|
}
|
5667
|
+
} else {
|
5668
|
+
translateX = translateX + rect.x;
|
5669
|
+
translateY = translateY + rect.y;
|
5644
5670
|
}
|
5645
5671
|
if (point.x < 0 || point.x > rect.width || point.y < 0 || point.y > rect.height) {
|
5646
5672
|
(_a = this.component) == null ? void 0 : _a.$set({ visible: false, x: translateX, y: translateY });
|
@@ -5871,7 +5897,6 @@ class CursorManager {
|
|
5871
5897
|
wrapper.removeEventListener("pointerleave", this.mouseLeaveListener);
|
5872
5898
|
};
|
5873
5899
|
});
|
5874
|
-
this.wrapperRect = wrapper.getBoundingClientRect();
|
5875
5900
|
}
|
5876
5901
|
setMainViewDivElement(div) {
|
5877
5902
|
this.mainViewElement = div;
|
@@ -5900,8 +5925,9 @@ class CursorManager {
|
|
5900
5925
|
}
|
5901
5926
|
}
|
5902
5927
|
updateContainerRect() {
|
5903
|
-
var _a;
|
5904
|
-
this.wrapperRect = (_a =
|
5928
|
+
var _a, _b;
|
5929
|
+
this.wrapperRect = (_a = this.manager.boxManager) == null ? void 0 : _a.teleBoxManager.stageRect;
|
5930
|
+
this.playgroundRect = (_b = WindowManager.playground) == null ? void 0 : _b.getBoundingClientRect();
|
5905
5931
|
}
|
5906
5932
|
deleteCursor(uid) {
|
5907
5933
|
this.store.cleanCursor(uid);
|
@@ -15647,15 +15673,15 @@ const reconnectRefresher = new ReconnectRefresher({ emitter });
|
|
15647
15673
|
const _WindowManager = class extends InvisiblePlugin {
|
15648
15674
|
constructor(context) {
|
15649
15675
|
super(context);
|
15650
|
-
this.version = "1.0.0-canary.
|
15651
|
-
this.dependencies = { "dependencies": { "@juggle/resize-observer": "^3.3.1", "@netless/telebox-insider": "1.0.0-alpha.18", "emittery": "^0.
|
15676
|
+
this.version = "1.0.0-canary.25";
|
15677
|
+
this.dependencies = { "dependencies": { "@juggle/resize-observer": "^3.3.1", "@netless/telebox-insider": "1.0.0-alpha.18", "emittery": "^0.11.0", "lodash": "^4.17.21", "p-retry": "^4.6.1", "side-effect-manager": "^1.1.0", "uuid": "^7.0.3", "value-enhancer": "^1.3.0", "video.js": ">=7" }, "peerDependencies": { "white-web-sdk": "^2.16.0" }, "devDependencies": { "@netless/app-docs-viewer": "^0.2.9", "@netless/app-media-player": "0.1.0-beta.5", "@rollup/plugin-commonjs": "^20.0.0", "@rollup/plugin-node-resolve": "^13.0.4", "@rollup/plugin-url": "^6.1.0", "@sveltejs/vite-plugin-svelte": "^1.0.0-next.22", "@tsconfig/svelte": "^2.0.1", "@types/debug": "^4.1.7", "@types/lodash": "^4.14.182", "@types/lodash-es": "^4.17.4", "@types/uuid": "^8.3.1", "@typescript-eslint/eslint-plugin": "^4.30.0", "@typescript-eslint/parser": "^4.30.0", "@vitest/ui": "^0.14.1", "cypress": "^8.7.0", "dotenv": "^10.0.0", "eslint": "^7.32.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-svelte3": "^3.2.0", "jsdom": "^19.0.0", "less": "^4.1.1", "prettier": "^2.3.2", "prettier-plugin-svelte": "^2.4.0", "rollup-plugin-analyzer": "^4.0.0", "rollup-plugin-styles": "^3.14.1", "svelte": "^3.42.4", "typescript": "^4.5.5", "vite": "^2.5.3", "vitest": "^0.14.1", "white-web-sdk": "2.16.10" } };
|
15652
15678
|
this.emitter = callbacks$1;
|
15653
15679
|
this.viewMode = ViewMode.Broadcaster;
|
15654
15680
|
this.viewMode$ = new Val(ViewMode.Broadcaster);
|
15655
15681
|
this.isReplay = isPlayer(this.displayer);
|
15656
15682
|
this.containerSizeRatio = _WindowManager.containerSizeRatio;
|
15657
15683
|
_WindowManager.displayer = context.displayer;
|
15658
|
-
window.NETLESS_DEPS = { "dependencies": { "@juggle/resize-observer": "^3.3.1", "@netless/telebox-insider": "1.0.0-alpha.18", "emittery": "^0.
|
15684
|
+
window.NETLESS_DEPS = { "dependencies": { "@juggle/resize-observer": "^3.3.1", "@netless/telebox-insider": "1.0.0-alpha.18", "emittery": "^0.11.0", "lodash": "^4.17.21", "p-retry": "^4.6.1", "side-effect-manager": "^1.1.0", "uuid": "^7.0.3", "value-enhancer": "^1.3.0", "video.js": ">=7" }, "peerDependencies": { "white-web-sdk": "^2.16.0" }, "devDependencies": { "@netless/app-docs-viewer": "^0.2.9", "@netless/app-media-player": "0.1.0-beta.5", "@rollup/plugin-commonjs": "^20.0.0", "@rollup/plugin-node-resolve": "^13.0.4", "@rollup/plugin-url": "^6.1.0", "@sveltejs/vite-plugin-svelte": "^1.0.0-next.22", "@tsconfig/svelte": "^2.0.1", "@types/debug": "^4.1.7", "@types/lodash": "^4.14.182", "@types/lodash-es": "^4.17.4", "@types/uuid": "^8.3.1", "@typescript-eslint/eslint-plugin": "^4.30.0", "@typescript-eslint/parser": "^4.30.0", "@vitest/ui": "^0.14.1", "cypress": "^8.7.0", "dotenv": "^10.0.0", "eslint": "^7.32.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-svelte3": "^3.2.0", "jsdom": "^19.0.0", "less": "^4.1.1", "prettier": "^2.3.2", "prettier-plugin-svelte": "^2.4.0", "rollup-plugin-analyzer": "^4.0.0", "rollup-plugin-styles": "^3.14.1", "svelte": "^3.42.4", "typescript": "^4.5.5", "vite": "^2.5.3", "vitest": "^0.14.1", "white-web-sdk": "2.16.10" } };
|
15659
15685
|
}
|
15660
15686
|
static async mount(params) {
|
15661
15687
|
var _a;
|
@@ -15737,12 +15763,12 @@ const _WindowManager = class extends InvisiblePlugin {
|
|
15737
15763
|
} catch (error) {
|
15738
15764
|
throw new Error("[WindowManger]: room must be switched to be writable");
|
15739
15765
|
}
|
15740
|
-
manager = await
|
15741
|
-
manager.ensureAttributes();
|
15766
|
+
manager = await createInvisiblePlugin(room);
|
15767
|
+
manager == null ? void 0 : manager.ensureAttributes();
|
15742
15768
|
await wait(500);
|
15743
15769
|
await room.setWritable(false);
|
15744
15770
|
} else {
|
15745
|
-
manager = await
|
15771
|
+
manager = await createInvisiblePlugin(room);
|
15746
15772
|
}
|
15747
15773
|
}
|
15748
15774
|
}
|
@@ -15779,6 +15805,7 @@ const _WindowManager = class extends InvisiblePlugin {
|
|
15779
15805
|
const mainViewElement = _WindowManager.initContainer(container, params.overwriteStyles);
|
15780
15806
|
if (this.boxManager && _WindowManager.playground) {
|
15781
15807
|
this.boxManager.setRoot(_WindowManager.playground);
|
15808
|
+
this.boxManager.mainViewElement$.setValue(mainViewElement);
|
15782
15809
|
}
|
15783
15810
|
this.bindMainView(mainViewElement, params.disableCameraTransform);
|
15784
15811
|
if (_WindowManager.playground) {
|