@netless/window-manager 0.4.25 → 0.4.27
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 +10 -0
- package/dist/App/AppContext.d.ts +2 -1
- package/dist/App/AppProxy.d.ts +7 -3
- package/dist/AppListener.d.ts +1 -0
- package/dist/AppManager.d.ts +2 -0
- package/dist/InternalEmitter.d.ts +7 -2
- package/dist/Page/PageController.d.ts +5 -0
- package/dist/Page/index.d.ts +2 -0
- package/dist/Utils/Common.d.ts +2 -1
- package/dist/Utils/error.d.ts +3 -0
- package/dist/View/MainView.d.ts +2 -0
- package/dist/constants.d.ts +1 -0
- package/dist/index.cjs.js +12 -12
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +233 -56
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +12 -12
- package/dist/index.umd.js.map +1 -1
- package/dist/typings.d.ts +1 -0
- package/docs/advanced.md +17 -0
- package/docs/api.md +9 -0
- package/docs/app-context.md +149 -100
- package/package.json +1 -1
- package/src/App/AppContext.ts +20 -11
- package/src/App/AppProxy.ts +61 -5
- package/src/App/Storage/index.ts +14 -8
- package/src/AppListener.ts +22 -0
- package/src/AppManager.ts +57 -24
- package/src/InternalEmitter.ts +6 -2
- package/src/Page/PageController.ts +6 -0
- package/src/Page/index.ts +17 -0
- package/src/PageState.ts +2 -1
- package/src/ReconnectRefresher.ts +4 -1
- package/src/Utils/Common.ts +14 -2
- package/src/Utils/RoomHacker.ts +2 -2
- package/src/Utils/error.ts +4 -0
- package/src/View/MainView.ts +24 -5
- package/src/constants.ts +1 -0
- package/src/index.ts +16 -0
- package/src/typings.ts +1 -0
package/dist/index.d.ts
CHANGED
@@ -144,6 +144,7 @@ export declare class WindowManager extends InvisiblePlugin<WindowMangerAttribute
|
|
144
144
|
nextPage(): Promise<boolean>;
|
145
145
|
prevPage(): Promise<boolean>;
|
146
146
|
addPage(params?: AddPageParams): Promise<void>;
|
147
|
+
removePage(index: number): Promise<boolean>;
|
147
148
|
/**
|
148
149
|
* 返回 mainView 的 ScenePath
|
149
150
|
*/
|
package/dist/index.es.js
CHANGED
@@ -36,6 +36,7 @@ var Events = /* @__PURE__ */ ((Events2) => {
|
|
36
36
|
Events2["WindowCreated"] = "WindowCreated";
|
37
37
|
Events2["SetMainViewScenePath"] = "SetMainViewScenePath";
|
38
38
|
Events2["SetMainViewSceneIndex"] = "SetMainViewSceneIndex";
|
39
|
+
Events2["SetAppFocusIndex"] = "SetAppFocusIndex";
|
39
40
|
Events2["SwitchViewsToFreedom"] = "SwitchViewsToFreedom";
|
40
41
|
Events2["MoveCamera"] = "MoveCamera";
|
41
42
|
Events2["MoveCameraToContain"] = "MoveCameraToContain";
|
@@ -369,11 +370,11 @@ const getScenePath = (room, dir, index) => {
|
|
369
370
|
}
|
370
371
|
}
|
371
372
|
};
|
372
|
-
const removeScenes = (room, scenePath) => {
|
373
|
+
const removeScenes = (room, scenePath, index) => {
|
373
374
|
if (room) {
|
374
375
|
const type = room.scenePathType(scenePath);
|
375
376
|
if (type !== ScenePathType.None) {
|
376
|
-
room.removeScenes(scenePath);
|
377
|
+
room.removeScenes(scenePath, index);
|
377
378
|
}
|
378
379
|
}
|
379
380
|
};
|
@@ -427,6 +428,15 @@ const getVersionNumber = (version) => {
|
|
427
428
|
return parseInt(versionString);
|
428
429
|
};
|
429
430
|
const wait = (time2) => new Promise((resolve) => setTimeout(resolve, time2));
|
431
|
+
const isRootDirPage = (scenePath) => {
|
432
|
+
const delimiterCount = scenePath.split("").reduce((prev, cur) => {
|
433
|
+
if (cur === ROOT_DIR) {
|
434
|
+
prev += 1;
|
435
|
+
}
|
436
|
+
return prev;
|
437
|
+
}, 0);
|
438
|
+
return delimiterCount === 1;
|
439
|
+
};
|
430
440
|
class AppListeners {
|
431
441
|
constructor(manager) {
|
432
442
|
this.manager = manager;
|
@@ -475,6 +485,10 @@ class AppListeners {
|
|
475
485
|
this.initMainViewCameraHandler();
|
476
486
|
break;
|
477
487
|
}
|
488
|
+
case Events.SetAppFocusIndex: {
|
489
|
+
this.setAppFocusViewIndexHandler(data.payload);
|
490
|
+
break;
|
491
|
+
}
|
478
492
|
}
|
479
493
|
}
|
480
494
|
};
|
@@ -516,6 +530,16 @@ class AppListeners {
|
|
516
530
|
this.initMainViewCameraHandler = () => {
|
517
531
|
this.manager.mainViewProxy.addCameraReaction();
|
518
532
|
};
|
533
|
+
this.setAppFocusViewIndexHandler = (payload) => {
|
534
|
+
if (payload.type === "main") {
|
535
|
+
this.manager.setSceneIndexWithoutSync(payload.index);
|
536
|
+
} else if (payload.type === "app" && payload.appID) {
|
537
|
+
const app = this.manager.appProxies.get(payload.appID);
|
538
|
+
if (app) {
|
539
|
+
app.setSceneIndexWithoutSync(payload.index);
|
540
|
+
}
|
541
|
+
}
|
542
|
+
};
|
519
543
|
}
|
520
544
|
get boxManager() {
|
521
545
|
return this.manager.boxManager;
|
@@ -533,6 +557,11 @@ class AppCreateError extends Error {
|
|
533
557
|
this.message = "[WindowManager]: app duplicate exists and cannot be created again";
|
534
558
|
}
|
535
559
|
}
|
560
|
+
class AppNotRegisterError extends Error {
|
561
|
+
constructor(kind2) {
|
562
|
+
super(`[WindowManager]: app ${kind2} need register or provide src`);
|
563
|
+
}
|
564
|
+
}
|
536
565
|
class AppManagerNotInitError extends Error {
|
537
566
|
constructor() {
|
538
567
|
super(...arguments);
|
@@ -568,6 +597,12 @@ class BoxManagerNotFoundError extends Error {
|
|
568
597
|
this.message = "[WindowManager]: boxManager not found";
|
569
598
|
}
|
570
599
|
}
|
600
|
+
class BindContainerRoomPhaseInvalidError extends Error {
|
601
|
+
constructor() {
|
602
|
+
super(...arguments);
|
603
|
+
this.message = "[WindowManager]: room phase only Connected can be bindContainer";
|
604
|
+
}
|
605
|
+
}
|
571
606
|
const onObjectByEvent = (event) => {
|
572
607
|
return (object, func) => {
|
573
608
|
if (object === void 0)
|
@@ -652,15 +687,21 @@ class Storage {
|
|
652
687
|
this.id = id2 || null;
|
653
688
|
this._state = {};
|
654
689
|
const rawState = this._getRawState(this._state);
|
655
|
-
if (this.
|
656
|
-
if (
|
657
|
-
if (
|
658
|
-
this.
|
690
|
+
if (this._context.getIsWritable()) {
|
691
|
+
if (this.id === null) {
|
692
|
+
if (context.isAddApp && defaultState) {
|
693
|
+
this.setState(defaultState);
|
694
|
+
}
|
695
|
+
} else {
|
696
|
+
if (rawState === this._state || !isObject(rawState)) {
|
697
|
+
if (!get(this._context.getAttributes(), [STORAGE_NS])) {
|
698
|
+
this._context.updateAttributes([STORAGE_NS], {});
|
699
|
+
}
|
700
|
+
this._context.updateAttributes([STORAGE_NS, this.id], this._state);
|
701
|
+
if (defaultState) {
|
702
|
+
this.setState(defaultState);
|
703
|
+
}
|
659
704
|
}
|
660
|
-
this._context.updateAttributes([STORAGE_NS, this.id], this._state);
|
661
|
-
}
|
662
|
-
if (defaultState) {
|
663
|
-
this.setState(defaultState);
|
664
705
|
}
|
665
706
|
}
|
666
707
|
plainObjectKeys(rawState).forEach((key) => {
|
@@ -885,6 +926,16 @@ class AppContext {
|
|
885
926
|
this.getView = () => {
|
886
927
|
return this.appProxy.view;
|
887
928
|
};
|
929
|
+
this.mountView = (dom) => {
|
930
|
+
const view = this.getView();
|
931
|
+
if (view) {
|
932
|
+
view.divElement = dom;
|
933
|
+
setTimeout(() => {
|
934
|
+
var _a;
|
935
|
+
(_a = this.getRoom()) == null ? void 0 : _a.refreshViewSize();
|
936
|
+
}, 1e3);
|
937
|
+
}
|
938
|
+
};
|
888
939
|
this.getInitScenePath = () => {
|
889
940
|
return this.manager.getAppInitPath(this.appId);
|
890
941
|
};
|
@@ -917,16 +968,6 @@ class AppContext {
|
|
917
968
|
this.appProxy.setFullPath(scenePath);
|
918
969
|
(_a = this.getRoom()) == null ? void 0 : _a.setScenePath(scenePath);
|
919
970
|
};
|
920
|
-
this.mountView = (dom) => {
|
921
|
-
const view = this.getView();
|
922
|
-
if (view) {
|
923
|
-
view.divElement = dom;
|
924
|
-
setTimeout(() => {
|
925
|
-
var _a;
|
926
|
-
(_a = this.getRoom()) == null ? void 0 : _a.refreshViewSize();
|
927
|
-
}, 1e3);
|
928
|
-
}
|
929
|
-
};
|
930
971
|
this.getAppOptions = () => {
|
931
972
|
return typeof this.appOptions === "function" ? this.appOptions() : this.appOptions;
|
932
973
|
};
|
@@ -979,6 +1020,14 @@ class AppContext {
|
|
979
1020
|
putScenes(this.manager.room, scenePath, [scene || {}]);
|
980
1021
|
}
|
981
1022
|
};
|
1023
|
+
this.removePage = async (index) => {
|
1024
|
+
if (index < 0 || index >= this.pageState.length) {
|
1025
|
+
console.warn(`[WindowManager]: page index ${index} out of range`);
|
1026
|
+
return false;
|
1027
|
+
}
|
1028
|
+
this.appProxy.removeSceneByIndex(index);
|
1029
|
+
return true;
|
1030
|
+
};
|
982
1031
|
this.emitter = appProxy.appEmitter;
|
983
1032
|
this.isAddApp = appProxy.isAddApp;
|
984
1033
|
}
|
@@ -1203,6 +1252,20 @@ const log = (...args) => {
|
|
1203
1252
|
console.log(`[WindowManager]:`, ...args);
|
1204
1253
|
}
|
1205
1254
|
};
|
1255
|
+
const calculateNextIndex = (index, pageState) => {
|
1256
|
+
let nextIndex = 0;
|
1257
|
+
const maxIndex = pageState.length - 1;
|
1258
|
+
if (index === pageState.index) {
|
1259
|
+
if (index === maxIndex) {
|
1260
|
+
nextIndex = index - 1;
|
1261
|
+
} else {
|
1262
|
+
nextIndex = pageState.index + 1;
|
1263
|
+
}
|
1264
|
+
} else {
|
1265
|
+
nextIndex = pageState.index;
|
1266
|
+
}
|
1267
|
+
return nextIndex;
|
1268
|
+
};
|
1206
1269
|
class AppProxy {
|
1207
1270
|
constructor(params, manager, appId, isAddApp) {
|
1208
1271
|
var _a;
|
@@ -1264,7 +1327,10 @@ class AppProxy {
|
|
1264
1327
|
var _a3;
|
1265
1328
|
const fullPath = (_a3 = this.appAttributes) == null ? void 0 : _a3.fullPath;
|
1266
1329
|
this.setFocusScenePathHandler(fullPath);
|
1267
|
-
this.
|
1330
|
+
if (this._prevFullPath !== fullPath) {
|
1331
|
+
this.notifyPageStateChange();
|
1332
|
+
this._prevFullPath = fullPath;
|
1333
|
+
}
|
1268
1334
|
});
|
1269
1335
|
});
|
1270
1336
|
};
|
@@ -1274,9 +1340,9 @@ class AppProxy {
|
|
1274
1340
|
setViewFocusScenePath(this.view, fullPath);
|
1275
1341
|
}
|
1276
1342
|
}, 50);
|
1277
|
-
this.notifyPageStateChange = () => {
|
1343
|
+
this.notifyPageStateChange = debounce(() => {
|
1278
1344
|
this.appEmitter.emit("pageStateChange", this.pageState);
|
1279
|
-
};
|
1345
|
+
}, 50);
|
1280
1346
|
this.kind = params.kind;
|
1281
1347
|
this.id = appId;
|
1282
1348
|
this.stateKey = `${this.id}_state`;
|
@@ -1444,6 +1510,23 @@ class AppProxy {
|
|
1444
1510
|
await appProxy.baseInsertApp(true);
|
1445
1511
|
(_a = this.boxManager) == null ? void 0 : _a.updateBoxState(currentAppState);
|
1446
1512
|
}
|
1513
|
+
async onRemoveScene(scenePath) {
|
1514
|
+
if (this.scenePath && scenePath.startsWith(this.scenePath + "/")) {
|
1515
|
+
let nextIndex = this.pageState.index;
|
1516
|
+
let fullPath = this._pageState.getFullPath(nextIndex);
|
1517
|
+
if (!fullPath) {
|
1518
|
+
nextIndex = 0;
|
1519
|
+
fullPath = this._pageState.getFullPath(nextIndex);
|
1520
|
+
}
|
1521
|
+
if (fullPath) {
|
1522
|
+
this.setFullPath(fullPath);
|
1523
|
+
}
|
1524
|
+
this.setViewFocusScenePath();
|
1525
|
+
if (this.view) {
|
1526
|
+
this.view.focusSceneIndex = nextIndex;
|
1527
|
+
}
|
1528
|
+
}
|
1529
|
+
}
|
1447
1530
|
emitAppSceneStateChange(sceneState) {
|
1448
1531
|
this.appEmitter.emit("sceneStateChange", sceneState);
|
1449
1532
|
}
|
@@ -1517,6 +1600,32 @@ class AppProxy {
|
|
1517
1600
|
get pageState() {
|
1518
1601
|
return this._pageState.toObject();
|
1519
1602
|
}
|
1603
|
+
async removeSceneByIndex(index) {
|
1604
|
+
const scenePath = this._pageState.getFullPath(index);
|
1605
|
+
if (scenePath) {
|
1606
|
+
if (this.pageState.length <= 1) {
|
1607
|
+
return false;
|
1608
|
+
}
|
1609
|
+
const nextIndex = calculateNextIndex(index, this.pageState);
|
1610
|
+
this.setSceneIndexWithoutSync(nextIndex);
|
1611
|
+
this.manager.dispatchInternalEvent(Events.SetAppFocusIndex, {
|
1612
|
+
type: "app",
|
1613
|
+
appID: this.id,
|
1614
|
+
index: nextIndex
|
1615
|
+
});
|
1616
|
+
setTimeout(() => {
|
1617
|
+
removeScenes(this.manager.room, scenePath, index);
|
1618
|
+
}, 100);
|
1619
|
+
return true;
|
1620
|
+
} else {
|
1621
|
+
return false;
|
1622
|
+
}
|
1623
|
+
}
|
1624
|
+
setSceneIndexWithoutSync(index) {
|
1625
|
+
if (this.view) {
|
1626
|
+
this.view.focusSceneIndex = index;
|
1627
|
+
}
|
1628
|
+
}
|
1520
1629
|
setSceneIndex(index) {
|
1521
1630
|
if (this.view) {
|
1522
1631
|
this.view.focusSceneIndex = index;
|
@@ -1555,6 +1664,7 @@ class AppProxy {
|
|
1555
1664
|
(_b = this.manager.refresher) == null ? void 0 : _b.remove(this.id);
|
1556
1665
|
(_c = this.manager.refresher) == null ? void 0 : _c.remove(this.stateKey);
|
1557
1666
|
(_d = this.manager.refresher) == null ? void 0 : _d.remove(`${this.id}-fullPath`);
|
1667
|
+
this._prevFullPath = void 0;
|
1558
1668
|
}
|
1559
1669
|
close() {
|
1560
1670
|
return this.destroy(true, true, false);
|
@@ -1683,6 +1793,11 @@ class MainViewProxy {
|
|
1683
1793
|
this.sideEffectManager.add(() => {
|
1684
1794
|
return emitter.on("containerSizeRatioUpdate", this.onUpdateContainerSizeRatio);
|
1685
1795
|
});
|
1796
|
+
this.sideEffectManager.add(() => {
|
1797
|
+
return emitter.on("startReconnect", () => {
|
1798
|
+
this.mainView.release();
|
1799
|
+
});
|
1800
|
+
});
|
1686
1801
|
}
|
1687
1802
|
ensureCameraAndSize() {
|
1688
1803
|
if (!this.mainViewCamera || !this.mainViewSize) {
|
@@ -1696,6 +1811,9 @@ class MainViewProxy {
|
|
1696
1811
|
get mainViewSize() {
|
1697
1812
|
return this.store.getMainViewSize();
|
1698
1813
|
}
|
1814
|
+
get didRelease() {
|
1815
|
+
return get(this.view, ["didRelease"]);
|
1816
|
+
}
|
1699
1817
|
moveCameraSizeByAttributes() {
|
1700
1818
|
this.moveCameraToContian(this.mainViewSize);
|
1701
1819
|
this.moveCamera(this.mainViewCamera);
|
@@ -1728,16 +1846,25 @@ class MainViewProxy {
|
|
1728
1846
|
return mainView;
|
1729
1847
|
}
|
1730
1848
|
onReconnect() {
|
1731
|
-
|
1732
|
-
|
1733
|
-
|
1849
|
+
if (this.didRelease) {
|
1850
|
+
this.rebind();
|
1851
|
+
} else {
|
1852
|
+
const mainViewScenePath = this.store.getMainViewScenePath();
|
1853
|
+
this.setFocusScenePath(mainViewScenePath);
|
1854
|
+
}
|
1855
|
+
}
|
1856
|
+
setFocusScenePath(path) {
|
1857
|
+
if (path) {
|
1858
|
+
return setViewFocusScenePath(this.view, path);
|
1734
1859
|
}
|
1735
1860
|
}
|
1736
1861
|
rebind() {
|
1737
1862
|
const divElement = this.mainView.divElement;
|
1738
1863
|
const disableCameraTransform = this.mainView.disableCameraTransform;
|
1739
1864
|
this.stop();
|
1740
|
-
this.
|
1865
|
+
if (!this.didRelease) {
|
1866
|
+
this.mainView.release();
|
1867
|
+
}
|
1741
1868
|
this.removeMainViewListener();
|
1742
1869
|
this.mainView = this.createMainView();
|
1743
1870
|
this.mainView.disableCameraTransform = disableCameraTransform;
|
@@ -1889,19 +2016,29 @@ class AppManager {
|
|
1889
2016
|
this.sideEffectManager = new SideEffectManager();
|
1890
2017
|
this.sceneState = null;
|
1891
2018
|
this.rootDirRemoving = false;
|
1892
|
-
this.onRemoveScenes = async (
|
1893
|
-
var _a;
|
2019
|
+
this.onRemoveScenes = async (params) => {
|
2020
|
+
var _a, _b;
|
2021
|
+
const { scenePath } = params;
|
1894
2022
|
if (scenePath === ROOT_DIR) {
|
1895
2023
|
await this.onRootDirRemoved();
|
1896
2024
|
this.dispatchInternalEvent(Events.RootDirRemoved);
|
1897
2025
|
return;
|
1898
2026
|
}
|
1899
|
-
|
1900
|
-
|
1901
|
-
|
1902
|
-
|
1903
|
-
|
2027
|
+
if (isRootDirPage(scenePath)) {
|
2028
|
+
let nextIndex = this.mainView.focusSceneIndex || 0;
|
2029
|
+
let sceneName = (_a = this.callbacksNode) == null ? void 0 : _a.scenes[nextIndex];
|
2030
|
+
if (!sceneName) {
|
2031
|
+
nextIndex = 0;
|
2032
|
+
sceneName = (_b = this.callbacksNode) == null ? void 0 : _b.scenes[nextIndex];
|
1904
2033
|
}
|
2034
|
+
if (sceneName) {
|
2035
|
+
this.setMainViewScenePath(`${ROOT_DIR}${sceneName}`);
|
2036
|
+
}
|
2037
|
+
await this.setMainViewSceneIndex(nextIndex);
|
2038
|
+
} else {
|
2039
|
+
this.appProxies.forEach((app) => {
|
2040
|
+
app.onRemoveScene(scenePath);
|
2041
|
+
});
|
1905
2042
|
}
|
1906
2043
|
};
|
1907
2044
|
this.onReadonlyChanged = () => {
|
@@ -1936,6 +2073,26 @@ class AppManager {
|
|
1936
2073
|
}
|
1937
2074
|
}
|
1938
2075
|
};
|
2076
|
+
this.removeSceneByIndex = async (index) => {
|
2077
|
+
const nextIndex = calculateNextIndex(index, this.windowManger.pageState);
|
2078
|
+
this.setSceneIndexWithoutSync(nextIndex);
|
2079
|
+
this.dispatchInternalEvent(Events.SetAppFocusIndex, { type: "main", index: nextIndex });
|
2080
|
+
setTimeout(() => {
|
2081
|
+
var _a;
|
2082
|
+
const scene = (_a = this.callbacksNode) == null ? void 0 : _a.scenes[index];
|
2083
|
+
if (scene) {
|
2084
|
+
removeScenes(this.room, `${ROOT_DIR}${scene}`, index);
|
2085
|
+
}
|
2086
|
+
}, 100);
|
2087
|
+
return true;
|
2088
|
+
};
|
2089
|
+
this.setSceneIndexWithoutSync = (index) => {
|
2090
|
+
var _a;
|
2091
|
+
const sceneName = (_a = this.callbacksNode) == null ? void 0 : _a.scenes[index];
|
2092
|
+
if (sceneName) {
|
2093
|
+
this.mainViewProxy.setFocusScenePath(`${ROOT_DIR}${sceneName}`);
|
2094
|
+
}
|
2095
|
+
};
|
1939
2096
|
this.onSceneChange = (node) => {
|
1940
2097
|
this.mainViewScenesLength = node.scenes.length;
|
1941
2098
|
this.updateSceneState(node);
|
@@ -1947,7 +2104,10 @@ class AppManager {
|
|
1947
2104
|
};
|
1948
2105
|
this.updateSceneState = (node) => {
|
1949
2106
|
const currentIndex = this.store.getMainViewSceneIndex() || 0;
|
1950
|
-
|
2107
|
+
let sceneName = node.scenes[currentIndex];
|
2108
|
+
if (!sceneName) {
|
2109
|
+
sceneName = node.scenes[this.mainView.focusSceneIndex || 0];
|
2110
|
+
}
|
1951
2111
|
this.sceneState = {
|
1952
2112
|
scenePath: `${ROOT_DIR}${sceneName}`,
|
1953
2113
|
contextPath: node.path,
|
@@ -2331,10 +2491,11 @@ class AppManager {
|
|
2331
2491
|
emitter.emit("mainViewMounted");
|
2332
2492
|
}
|
2333
2493
|
setMainViewFocusPath(scenePath) {
|
2494
|
+
var _a;
|
2334
2495
|
const focusScenePath = scenePath || this.store.getMainViewScenePath();
|
2335
2496
|
if (focusScenePath) {
|
2336
|
-
|
2337
|
-
return (
|
2497
|
+
setViewFocusScenePath(this.mainView, focusScenePath);
|
2498
|
+
return ((_a = this.mainView) == null ? void 0 : _a.focusScenePath) === focusScenePath;
|
2338
2499
|
}
|
2339
2500
|
}
|
2340
2501
|
resetScenePath(scenePath) {
|
@@ -2434,23 +2595,21 @@ class AppManager {
|
|
2434
2595
|
}
|
2435
2596
|
}
|
2436
2597
|
async setMainViewSceneIndex(index) {
|
2598
|
+
var _a;
|
2437
2599
|
if (this.room) {
|
2438
2600
|
if (this.store.getMainViewSceneIndex() === index)
|
2439
2601
|
return;
|
2440
|
-
const
|
2441
|
-
|
2442
|
-
|
2443
|
-
const
|
2444
|
-
if (
|
2445
|
-
|
2446
|
-
|
2447
|
-
|
2448
|
-
this.safeSetAttributes({ _mainSceneIndex: index });
|
2449
|
-
this.dispatchSetMainViewScenePath(scenePath);
|
2450
|
-
}
|
2451
|
-
} else {
|
2452
|
-
throw new Error(`[WindowManager]: ${sceneDir}: ${index} not valid index`);
|
2602
|
+
const sceneName = (_a = this.callbacksNode) == null ? void 0 : _a.scenes[index];
|
2603
|
+
const scenePath = `${ROOT_DIR}${sceneName}`;
|
2604
|
+
if (sceneName) {
|
2605
|
+
const success = this.setMainViewFocusPath(scenePath);
|
2606
|
+
if (success) {
|
2607
|
+
this.store.setMainViewScenePath(scenePath);
|
2608
|
+
this.safeSetAttributes({ _mainSceneIndex: index });
|
2609
|
+
this.dispatchSetMainViewScenePath(scenePath);
|
2453
2610
|
}
|
2611
|
+
} else {
|
2612
|
+
throw new Error(`[WindowManager]: ${index} not valid index`);
|
2454
2613
|
}
|
2455
2614
|
}
|
2456
2615
|
}
|
@@ -5561,8 +5720,9 @@ class PageStateImpl {
|
|
5561
5720
|
return ((_a = this.manager) == null ? void 0 : _a.mainViewScenesLength) || 0;
|
5562
5721
|
}
|
5563
5722
|
toObject() {
|
5723
|
+
const index = this.index >= this.length ? this.length - 1 : this.index;
|
5564
5724
|
return {
|
5565
|
-
index
|
5725
|
+
index,
|
5566
5726
|
length: this.length
|
5567
5727
|
};
|
5568
5728
|
}
|
@@ -5573,6 +5733,9 @@ class ReconnectRefresher {
|
|
5573
5733
|
this.reactors = /* @__PURE__ */ new Map();
|
5574
5734
|
this.disposers = /* @__PURE__ */ new Map();
|
5575
5735
|
this.onPhaseChanged = (phase) => {
|
5736
|
+
if (phase === RoomPhase.Reconnecting) {
|
5737
|
+
this.ctx.emitter.emit("startReconnect");
|
5738
|
+
}
|
5576
5739
|
if (phase === RoomPhase.Connected && this.phase === RoomPhase.Reconnecting) {
|
5577
5740
|
this.onReconnected();
|
5578
5741
|
}
|
@@ -5589,7 +5752,7 @@ class ReconnectRefresher {
|
|
5589
5752
|
this.disposers.set(id2, func());
|
5590
5753
|
}
|
5591
5754
|
});
|
5592
|
-
this.ctx.emitter.emit("onReconnected"
|
5755
|
+
this.ctx.emitter.emit("onReconnected");
|
5593
5756
|
};
|
5594
5757
|
}
|
5595
5758
|
setRoom(room) {
|
@@ -5695,13 +5858,13 @@ const replaceRoomFunction = (room, manager) => {
|
|
5695
5858
|
};
|
5696
5859
|
const delegateRemoveScenes = (room, manager) => {
|
5697
5860
|
const originRemoveScenes = room.removeScenes;
|
5698
|
-
room.removeScenes = (scenePath) => {
|
5861
|
+
room.removeScenes = (scenePath, index) => {
|
5699
5862
|
var _a;
|
5700
5863
|
if (scenePath === ROOT_DIR) {
|
5701
5864
|
(_a = manager.appManager) == null ? void 0 : _a.updateRootDirRemoving(true);
|
5702
5865
|
}
|
5703
5866
|
const result = originRemoveScenes.call(room, scenePath);
|
5704
|
-
emitter.emit("removeScenes", scenePath);
|
5867
|
+
emitter.emit("removeScenes", { scenePath, index });
|
5705
5868
|
return result;
|
5706
5869
|
};
|
5707
5870
|
};
|
@@ -14884,7 +15047,7 @@ const reconnectRefresher = new ReconnectRefresher({ emitter });
|
|
14884
15047
|
const _WindowManager = class extends InvisiblePlugin {
|
14885
15048
|
constructor(context) {
|
14886
15049
|
super(context);
|
14887
|
-
this.version = "0.4.
|
15050
|
+
this.version = "0.4.27";
|
14888
15051
|
this.dependencies = { "dependencies": { "@juggle/resize-observer": "^3.3.1", "@netless/telebox-insider": "0.2.26", "emittery": "^0.9.2", "lodash": "^4.17.21", "p-retry": "^4.6.1", "side-effect-manager": "^0.1.5", "uuid": "^7.0.3", "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", "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.12.4", "white-web-sdk": "2.16.10" } };
|
14889
15052
|
this.emitter = callbacks$1;
|
14890
15053
|
this.viewMode = ViewMode.Broadcaster;
|
@@ -15001,6 +15164,9 @@ const _WindowManager = class extends InvisiblePlugin {
|
|
15001
15164
|
}
|
15002
15165
|
bindContainer(container) {
|
15003
15166
|
var _a, _b, _c, _d, _e2, _f;
|
15167
|
+
if (this.room.phase !== RoomPhase.Connected) {
|
15168
|
+
throw new BindContainerRoomPhaseInvalidError();
|
15169
|
+
}
|
15004
15170
|
if (_WindowManager.isCreated && _WindowManager.container) {
|
15005
15171
|
if (_WindowManager.container.firstChild) {
|
15006
15172
|
container.appendChild(_WindowManager.container.firstChild);
|
@@ -15181,6 +15347,17 @@ const _WindowManager = class extends InvisiblePlugin {
|
|
15181
15347
|
}
|
15182
15348
|
}
|
15183
15349
|
}
|
15350
|
+
async removePage(index) {
|
15351
|
+
if (this.appManager) {
|
15352
|
+
if (index < 0 || index >= this.pageState.length) {
|
15353
|
+
console.warn(`[WindowManager]: index ${index} out of range`);
|
15354
|
+
return false;
|
15355
|
+
}
|
15356
|
+
return this.appManager.removeSceneByIndex(index);
|
15357
|
+
} else {
|
15358
|
+
return false;
|
15359
|
+
}
|
15360
|
+
}
|
15184
15361
|
getMainViewScenePath() {
|
15185
15362
|
var _a;
|
15186
15363
|
return (_a = this.appManager) == null ? void 0 : _a.store.getMainViewScenePath();
|
@@ -15532,5 +15709,5 @@ WindowManager.debug = false;
|
|
15532
15709
|
WindowManager.containerSizeRatio = DEFAULT_CONTAINER_RATIO;
|
15533
15710
|
WindowManager.isCreated = false;
|
15534
15711
|
setupBuiltin();
|
15535
|
-
export { BuiltinApps, WindowManager, reconnectRefresher };
|
15712
|
+
export { AppCreateError, AppManagerNotInitError, AppNotRegisterError, BindContainerRoomPhaseInvalidError, BoxManagerNotFoundError, BoxNotCreatedError, BuiltinApps, InvalidScenePath, ParamsInvalidError, WhiteWebSDKInvalidError, WindowManager, calculateNextIndex, reconnectRefresher };
|
15536
15713
|
//# sourceMappingURL=index.es.js.map
|