@netless/window-manager 0.4.0 → 0.4.3
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 +8 -0
- package/dist/Register/index.d.ts +5 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.es.js +5 -5
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +5 -5
- package/dist/index.umd.js.map +1 -1
- package/docs/advanced.md +18 -4
- package/docs/api.md +11 -1
- package/package.json +4 -6
- package/src/App/Storage/index.ts +1 -1
- package/src/Register/index.ts +7 -1
- package/src/Register/loader.ts +26 -11
- package/src/Utils/RoomHacker.ts +4 -0
- package/src/index.ts +47 -5
- package/vite.config.js +2 -2
package/docs/advanced.md
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
## 进阶使用
|
2
2
|
|
3
3
|
- 目录
|
4
|
-
- [撤销重做]
|
4
|
+
- [撤销重做](#redo-undo)
|
5
|
+
- [清屏](#clean-current-scene)
|
5
6
|
|
6
7
|
|
7
|
-
|
8
|
-
<h3>撤销重做</h3>
|
8
|
+
<h3 id="redo-undo">撤销重做</h3>
|
9
9
|
|
10
10
|
> 以下事件和属性都会根据 `focus` 的窗口来进行自动切换应用对象
|
11
11
|
|
12
|
-
|
13
12
|
#### 获取可以撤销/重做的步数
|
14
13
|
|
15
14
|
```ts
|
@@ -37,3 +36,18 @@ manager.undo() //撤销
|
|
37
36
|
manager.redo() // 重做
|
38
37
|
```
|
39
38
|
|
39
|
+
<br>
|
40
|
+
|
41
|
+
<h3 id="clean-current-scene">清屏</h3>
|
42
|
+
|
43
|
+
因为在多窗口模式下有多个白板, 如果想要清除当前 `focus` 的白板只需要调用
|
44
|
+
|
45
|
+
```ts
|
46
|
+
manager.cleanCurrentScene()
|
47
|
+
```
|
48
|
+
|
49
|
+
只想清理主白板的笔迹则需要
|
50
|
+
|
51
|
+
```ts
|
52
|
+
manager.mainView.cleanCurrentScene()
|
53
|
+
```
|
package/docs/api.md
CHANGED
@@ -190,4 +190,14 @@ manager.callbacks.on(events, listener)
|
|
190
190
|
| focusedChange | string, undefined | | 当前 focus 的 appId,主白板时为 undefined |
|
191
191
|
| mainViewScenesLengthChange | number | | mainView scenes 添加或删除时触发 |
|
192
192
|
| canRedoStepsChange | number | | 当前 focus 的 view 可重做步数改变 |
|
193
|
-
| canUndoStepsChange | number | | 当前 focus 的 view 可撤销步数改变 |
|
193
|
+
| canUndoStepsChange | number | | 当前 focus 的 view 可撤销步数改变 |
|
194
|
+
| loadApp | LoadAppEvent | | 加载远程APP 事件 |
|
195
|
+
|
196
|
+
|
197
|
+
```ts
|
198
|
+
type LoadAppEvent = {
|
199
|
+
kind: string;
|
200
|
+
status: "start" | "success" | "failed";
|
201
|
+
reason?: string;
|
202
|
+
}
|
203
|
+
```
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@netless/window-manager",
|
3
|
-
"version": "0.4.
|
3
|
+
"version": "0.4.3",
|
4
4
|
"description": "",
|
5
5
|
"main": "dist/index.es.js",
|
6
6
|
"module": "dist/index.es.js",
|
@@ -18,7 +18,6 @@
|
|
18
18
|
"author": "",
|
19
19
|
"license": "ISC",
|
20
20
|
"peerDependencies": {
|
21
|
-
"video.js": ">=7",
|
22
21
|
"white-web-sdk": "^2.16.0"
|
23
22
|
},
|
24
23
|
"dependencies": {
|
@@ -28,12 +27,12 @@
|
|
28
27
|
"p-retry": "^4.6.1",
|
29
28
|
"side-effect-manager": "^0.1.5",
|
30
29
|
"uuid": "^7.0.3",
|
31
|
-
"video.js": ">=7"
|
30
|
+
"video.js": ">=7",
|
31
|
+
"@netless/telebox-insider": "0.2.22"
|
32
32
|
},
|
33
33
|
"devDependencies": {
|
34
34
|
"@netless/app-docs-viewer": "^0.2.6",
|
35
35
|
"@netless/app-media-player": "0.1.0-beta.5",
|
36
|
-
"@netless/telebox-insider": "0.2.22",
|
37
36
|
"@rollup/plugin-commonjs": "^20.0.0",
|
38
37
|
"@rollup/plugin-node-resolve": "^13.0.4",
|
39
38
|
"@rollup/plugin-url": "^6.1.0",
|
@@ -56,8 +55,7 @@
|
|
56
55
|
"rollup-plugin-styles": "^3.14.1",
|
57
56
|
"svelte": "^3.42.4",
|
58
57
|
"typescript": "^4.3.5",
|
59
|
-
"video.js": "^7.14.3",
|
60
58
|
"vite": "^2.5.3",
|
61
|
-
"white-web-sdk": "
|
59
|
+
"white-web-sdk": "2.16.3"
|
62
60
|
}
|
63
61
|
}
|
package/src/App/Storage/index.ts
CHANGED
@@ -201,7 +201,7 @@ export class Storage<TState extends Record<string, any> = any> implements Storag
|
|
201
201
|
private _getRawState(defaultValue: TState): TState
|
202
202
|
private _getRawState(defaultValue?: TState): TState | undefined {
|
203
203
|
if (this.id === null) {
|
204
|
-
return
|
204
|
+
return this._context.getAttributes() ?? defaultValue;
|
205
205
|
} else {
|
206
206
|
return get(this._context.getAttributes(), [STORAGE_NS, this.id], defaultValue);
|
207
207
|
}
|
package/src/Register/index.ts
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
import Emittery from "emittery";
|
2
|
-
import type { NetlessApp, RegisterEvents, RegisterParams } from "../typings";
|
3
2
|
import { loadApp } from "./loader";
|
3
|
+
import type { NetlessApp, RegisterEvents, RegisterParams } from "../typings";
|
4
|
+
|
5
|
+
export type LoadAppEvent = {
|
6
|
+
kind: string;
|
7
|
+
status: "start" | "success" | "failed";
|
8
|
+
reason?: string;
|
9
|
+
};
|
4
10
|
|
5
11
|
class AppRegister {
|
6
12
|
public kindEmitters: Map<string, Emittery<RegisterEvents>> = new Map();
|
package/src/Register/loader.ts
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
+
import { callbacks } from "../index";
|
1
2
|
import { getItem, setItem } from "./storage";
|
2
3
|
import type { NetlessApp } from "../typings";
|
3
4
|
|
4
5
|
const Prefix = "NetlessApp";
|
5
6
|
|
6
|
-
const TIMEOUT = 10000; // 10 秒超时
|
7
|
+
const TIMEOUT = 10000; // 下载 script 10 秒超时
|
7
8
|
|
8
9
|
export const getScript = async (url: string): Promise<string> => {
|
9
10
|
const item = await getItem(url);
|
@@ -33,19 +34,33 @@ export const loadApp = async (
|
|
33
34
|
name?: string
|
34
35
|
): Promise<NetlessApp | undefined> => {
|
35
36
|
const appName = name || Prefix + key;
|
36
|
-
|
37
|
+
callbacks.emit("loadApp", { kind: key, status: "start" });
|
37
38
|
try {
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
39
|
+
const text = await getScript(url);
|
40
|
+
if (!text || text.length === 0) {
|
41
|
+
callbacks.emit("loadApp", { kind: key, status: "failed", reason: "script is empty." });
|
42
|
+
return;
|
43
|
+
}
|
44
|
+
try {
|
45
|
+
const result = executeScript(text, appName);
|
46
|
+
callbacks.emit("loadApp", { kind: key, status: "success" });
|
47
|
+
return result;
|
48
|
+
} catch (error: any) {
|
49
|
+
if (error.message.includes("Can only have one anonymous define call per script file")) {
|
50
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
51
|
+
// @ts-ignore
|
52
|
+
const define = window.define;
|
53
|
+
if ("function" == typeof define && define.amd) {
|
54
|
+
delete define.amd;
|
55
|
+
}
|
56
|
+
const result = executeScript(text, appName);
|
57
|
+
callbacks.emit("loadApp", { kind: key, status: "success" });
|
58
|
+
return result;
|
46
59
|
}
|
47
|
-
|
60
|
+
callbacks.emit("loadApp", { kind: key, status: "failed", reason: error.message });
|
48
61
|
}
|
62
|
+
} catch (error: any) {
|
63
|
+
callbacks.emit("loadApp", { kind: key, status: "failed", reason: error.message });
|
49
64
|
}
|
50
65
|
};
|
51
66
|
|
package/src/Utils/RoomHacker.ts
CHANGED
@@ -44,6 +44,10 @@ export const replaceRoomFunction = (room: Room | Player, manager: WindowManager)
|
|
44
44
|
room.redo = () => manager.redo();
|
45
45
|
room.undo = () => manager.undo();
|
46
46
|
room.cleanCurrentScene = () => manager.cleanCurrentScene();
|
47
|
+
room.delete = () => manager.delete();
|
48
|
+
room.copy = () => manager.copy();
|
49
|
+
room.paste = () => manager.paste();
|
50
|
+
room.duplicate = () => manager.duplicate();
|
47
51
|
delegateRemoveScenes(room);
|
48
52
|
}
|
49
53
|
};
|
package/src/index.ts
CHANGED
@@ -17,6 +17,7 @@ import { replaceRoomFunction } from "./Utils/RoomHacker";
|
|
17
17
|
import { setupBuiltin } from "./BuiltinApps";
|
18
18
|
import "./style.css";
|
19
19
|
import "@netless/telebox-insider/dist/style.css";
|
20
|
+
import type { LoadAppEvent } from "./Register";
|
20
21
|
import {
|
21
22
|
addEmitterOnceListener,
|
22
23
|
ensureValidScenePath,
|
@@ -152,6 +153,7 @@ export type PublicEvent = {
|
|
152
153
|
mainViewScenesLengthChange: number;
|
153
154
|
canRedoStepsChange: number;
|
154
155
|
canUndoStepsChange: number;
|
156
|
+
loadApp: LoadAppEvent;
|
155
157
|
};
|
156
158
|
|
157
159
|
export type MountParams = {
|
@@ -612,6 +614,10 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
612
614
|
return this.attributes.focus;
|
613
615
|
}
|
614
616
|
|
617
|
+
public get focusedView(): View | undefined {
|
618
|
+
return this.appManager?.focusApp?.view;
|
619
|
+
}
|
620
|
+
|
615
621
|
public get mainViewSceneIndex(): number {
|
616
622
|
return this.appManager?.store.getMainViewSceneIndex();
|
617
623
|
}
|
@@ -681,7 +687,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
681
687
|
this.appManager?.dispatchInternalEvent(Events.MoveCamera, camera);
|
682
688
|
setTimeout(() => {
|
683
689
|
this.appManager?.mainViewProxy.setCameraAndSize();
|
684
|
-
},
|
690
|
+
}, 500);
|
685
691
|
}
|
686
692
|
|
687
693
|
public moveCameraToContain(
|
@@ -694,7 +700,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
694
700
|
this.appManager?.dispatchInternalEvent(Events.MoveCameraToContain, rectangle);
|
695
701
|
setTimeout(() => {
|
696
702
|
this.appManager?.mainViewProxy.setCameraAndSize();
|
697
|
-
},
|
703
|
+
}, 500);
|
698
704
|
}
|
699
705
|
|
700
706
|
public convertToPointInWorld(point: Point): Point {
|
@@ -768,7 +774,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
768
774
|
public cleanCurrentScene(): void {
|
769
775
|
const focused = this.focused;
|
770
776
|
if (focused) {
|
771
|
-
this.
|
777
|
+
this.focusedView?.cleanCurrentScene();
|
772
778
|
} else {
|
773
779
|
this.mainView.cleanCurrentScene();
|
774
780
|
}
|
@@ -777,7 +783,7 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
777
783
|
public redo(): number {
|
778
784
|
const focused = this.focused;
|
779
785
|
if (focused) {
|
780
|
-
return this.
|
786
|
+
return this.focusedView?.redo() || 0;
|
781
787
|
} else {
|
782
788
|
return this.mainView.redo();
|
783
789
|
}
|
@@ -786,12 +792,48 @@ export class WindowManager extends InvisiblePlugin<WindowMangerAttributes> {
|
|
786
792
|
public undo(): number {
|
787
793
|
const focused = this.focused;
|
788
794
|
if (focused) {
|
789
|
-
return this.
|
795
|
+
return this.focusedView?.undo() || 0;
|
790
796
|
} else {
|
791
797
|
return this.mainView.undo();
|
792
798
|
}
|
793
799
|
}
|
794
800
|
|
801
|
+
public delete(): void {
|
802
|
+
const focused = this.focused;
|
803
|
+
if (focused) {
|
804
|
+
this.focusedView?.delete();
|
805
|
+
} else {
|
806
|
+
this.mainView.delete();
|
807
|
+
}
|
808
|
+
}
|
809
|
+
|
810
|
+
public copy(): void {
|
811
|
+
const focused = this.focused;
|
812
|
+
if (focused) {
|
813
|
+
this.focusedView?.copy();
|
814
|
+
} else {
|
815
|
+
this.mainView.copy();
|
816
|
+
}
|
817
|
+
}
|
818
|
+
|
819
|
+
public paste(): void {
|
820
|
+
const focused = this.focused;
|
821
|
+
if (focused) {
|
822
|
+
this.focusedView?.paste();
|
823
|
+
} else {
|
824
|
+
this.mainView.paste();
|
825
|
+
}
|
826
|
+
}
|
827
|
+
|
828
|
+
public duplicate(): void {
|
829
|
+
const focused = this.focused;
|
830
|
+
if (focused) {
|
831
|
+
this.focusedView?.duplicate();
|
832
|
+
} else {
|
833
|
+
this.mainView.duplicate();
|
834
|
+
}
|
835
|
+
}
|
836
|
+
|
795
837
|
private isDynamicPPT(scenes: SceneDefinition[]) {
|
796
838
|
const sceneSrc = scenes[0]?.ppt?.src;
|
797
839
|
return sceneSrc?.startsWith("pptx://");
|
package/vite.config.js
CHANGED
@@ -2,7 +2,7 @@ import path from "path";
|
|
2
2
|
import { defineConfig } from "vite";
|
3
3
|
import { svelte } from "@sveltejs/vite-plugin-svelte";
|
4
4
|
import { dependencies, peerDependencies, version, devDependencies } from "./package.json"
|
5
|
-
|
5
|
+
import { omit } from "lodash";
|
6
6
|
|
7
7
|
export default defineConfig(({ mode }) => {
|
8
8
|
const isProd = mode === "production";
|
@@ -34,7 +34,7 @@ export default defineConfig(({ mode }) => {
|
|
34
34
|
sourcemap: true,
|
35
35
|
rollupOptions: {
|
36
36
|
external: Object.keys({
|
37
|
-
...dependencies,
|
37
|
+
...omit(dependencies, ["@netless/telebox-insider"]),
|
38
38
|
...peerDependencies,
|
39
39
|
}),
|
40
40
|
},
|