@netless/fastboard-core 1.1.6 → 1.1.7
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/index.d.ts +18 -8
- package/dist/index.js +24 -79
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +24 -79
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
- package/src/fastboard-internal.d.ts +24 -14
- package/src/helpers/docs.ts +18 -86
- package/src/impl/FastboardApp.ts +46 -12
- package/src/impl/FastboardPlayer.ts +1 -1
- package/src/impl/bridge-runtime.ts +5 -4
package/src/helpers/docs.ts
CHANGED
|
@@ -1,20 +1,29 @@
|
|
|
1
|
-
import type { AppResult } from "@netless/app-slide";
|
|
2
1
|
import type { FastboardApp, WindowManager } from "../impl";
|
|
3
2
|
|
|
3
|
+
export type DocsEvent = "prevPage" | "nextPage" | "prevStep" | "nextStep" | "jumpToPage" | "scalePage";
|
|
4
|
+
|
|
4
5
|
export interface DocsEventOptions {
|
|
5
6
|
/** If provided, will dispatch to the specific app. Default to the focused app. */
|
|
6
7
|
appId?: string;
|
|
7
8
|
/** Used by `jumpToPage` event, range from 1 to total pages count. */
|
|
8
9
|
page?: number;
|
|
10
|
+
/** Used by `scalePage` event. Range from 1 to 4, decimals allowed. `1` means default fitted size. */
|
|
11
|
+
scale?: number;
|
|
9
12
|
}
|
|
10
13
|
|
|
14
|
+
type DocsEventManager = WindowManager & {
|
|
15
|
+
dispatchDocsEvent?: (event: DocsEvent, options?: DocsEventOptions) => boolean;
|
|
16
|
+
};
|
|
17
|
+
|
|
11
18
|
/**
|
|
12
|
-
* Send specific command to the
|
|
13
|
-
*
|
|
19
|
+
* Send specific command to the DocsViewer / Presentation / Slide app.
|
|
20
|
+
* This is a compatibility wrapper around `WindowManager.dispatchDocsEvent()`.
|
|
21
|
+
* Works for documents created by `insertDocs()`.
|
|
14
22
|
*
|
|
15
23
|
* Returns false if failed to find the app or not writable.
|
|
16
24
|
*
|
|
17
|
-
* For
|
|
25
|
+
* For DocsViewer and Presentation, `nextPage` equals to `nextStep`, as with
|
|
26
|
+
* `prevPage` and `prevStep`.
|
|
18
27
|
*
|
|
19
28
|
* @example
|
|
20
29
|
* ```js
|
|
@@ -27,91 +36,14 @@ export interface DocsEventOptions {
|
|
|
27
36
|
*/
|
|
28
37
|
export function dispatchDocsEvent(
|
|
29
38
|
fastboard: FastboardApp | WindowManager,
|
|
30
|
-
event:
|
|
39
|
+
event: DocsEvent,
|
|
31
40
|
options: DocsEventOptions = {}
|
|
32
41
|
): boolean {
|
|
33
42
|
const manager = "manager" in fastboard ? fastboard.manager : fastboard;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
console.warn("not found " + (options.appId || "focused app"));
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
let page: number | undefined, input: HTMLInputElement | null;
|
|
42
|
-
|
|
43
|
-
// Click the DOM elements for static docs
|
|
44
|
-
if (appId.startsWith("DocsViewer-")) {
|
|
45
|
-
const dom = manager.queryOne(appId)?.box?.$footer;
|
|
46
|
-
if (!dom) {
|
|
47
|
-
console.warn("not found app with id " + appId);
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const click = (el: Element | null) => {
|
|
52
|
-
el && el.dispatchEvent(new MouseEvent("click"));
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
switch (event) {
|
|
56
|
-
case "prevPage":
|
|
57
|
-
case "prevStep":
|
|
58
|
-
click(dom.querySelector('button[class$="btn-page-back"]'));
|
|
59
|
-
break;
|
|
60
|
-
case "nextPage":
|
|
61
|
-
case "nextStep":
|
|
62
|
-
click(dom.querySelector('button[class$="btn-page-next"]'));
|
|
63
|
-
break;
|
|
64
|
-
case "jumpToPage":
|
|
65
|
-
page = options.page;
|
|
66
|
-
input = dom.querySelector('input[class$="page-number-input"]');
|
|
67
|
-
if (!input || typeof page !== "number") {
|
|
68
|
-
console.warn("failed to jump" + (page ? " to page " + page : ""));
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
input.value = "" + page;
|
|
72
|
-
input.dispatchEvent(new InputEvent("change"));
|
|
73
|
-
break;
|
|
74
|
-
default:
|
|
75
|
-
console.warn("unknown event " + event);
|
|
76
|
-
return false;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return true;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// Check controller for slide docs
|
|
83
|
-
else if (appId.startsWith("Slide-")) {
|
|
84
|
-
const app = manager.queryOne(appId)?.appResult as unknown as AppResult | undefined;
|
|
85
|
-
if (!app) {
|
|
86
|
-
console.warn("not found app with id " + appId);
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
switch (event) {
|
|
91
|
-
case "prevPage":
|
|
92
|
-
return app.prevPage();
|
|
93
|
-
case "nextPage":
|
|
94
|
-
return app.nextPage();
|
|
95
|
-
case "prevStep":
|
|
96
|
-
return app.prevStep();
|
|
97
|
-
case "nextStep":
|
|
98
|
-
return app.nextStep();
|
|
99
|
-
case "jumpToPage":
|
|
100
|
-
page = options.page;
|
|
101
|
-
if (typeof page !== "number") {
|
|
102
|
-
console.warn("failed to jump" + (page ? " to page " + page : ""));
|
|
103
|
-
return false;
|
|
104
|
-
}
|
|
105
|
-
return app.jumpToPage(page);
|
|
106
|
-
default:
|
|
107
|
-
console.warn("unknown event " + event);
|
|
108
|
-
return false;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// No support for any other kind
|
|
113
|
-
else {
|
|
114
|
-
console.warn("not supported app " + appId);
|
|
43
|
+
const dispatchDocsEvent = (manager as DocsEventManager).dispatchDocsEvent;
|
|
44
|
+
if (!dispatchDocsEvent) {
|
|
45
|
+
console.warn("window manager does not support dispatchDocsEvent");
|
|
115
46
|
return false;
|
|
116
47
|
}
|
|
48
|
+
return dispatchDocsEvent.call(manager, event, options);
|
|
117
49
|
}
|
package/src/impl/FastboardApp.ts
CHANGED
|
@@ -208,6 +208,11 @@ export interface InsertDocsDynamic {
|
|
|
208
208
|
|
|
209
209
|
export type InsertDocsParams = InsertDocsStatic | InsertDocsDynamic;
|
|
210
210
|
|
|
211
|
+
export interface InsertDocsOptions {
|
|
212
|
+
/** Renderer for static documents. Dynamic documents always use Slide. @default "docsViewer" */
|
|
213
|
+
readonly staticRenderer?: "docsViewer" | "presentation";
|
|
214
|
+
}
|
|
215
|
+
|
|
211
216
|
export interface ProjectorResponse {
|
|
212
217
|
uuid: string;
|
|
213
218
|
status: "Waiting" | "Converting" | "Finished" | "Fail";
|
|
@@ -602,13 +607,21 @@ export class FastboardApp<TEventData extends Record<string, any> = any> extends
|
|
|
602
607
|
* Insert PDF/PPTX from conversion result.
|
|
603
608
|
* @param status https://developer.netless.link/server-en/home/server-conversion#get-query-task-conversion-progress
|
|
604
609
|
*/
|
|
605
|
-
insertDocs(
|
|
610
|
+
insertDocs(
|
|
611
|
+
filename: string,
|
|
612
|
+
status: ConversionResponse,
|
|
613
|
+
options?: InsertDocsOptions
|
|
614
|
+
): Promise<string | undefined>;
|
|
606
615
|
|
|
607
616
|
/**
|
|
608
617
|
* Insert PDF/PPTX from projector conversion result.
|
|
609
618
|
* @param response https://developer.netless.link/server-zh/home/server-projector#get-%E6%9F%A5%E8%AF%A2%E4%BB%BB%E5%8A%A1%E8%BD%AC%E6%8D%A2%E8%BF%9B%E5%BA%A6
|
|
610
619
|
*/
|
|
611
|
-
insertDocs(
|
|
620
|
+
insertDocs(
|
|
621
|
+
filename: string,
|
|
622
|
+
response: ProjectorResponse,
|
|
623
|
+
options?: InsertDocsOptions
|
|
624
|
+
): Promise<string | undefined>;
|
|
612
625
|
|
|
613
626
|
/**
|
|
614
627
|
* Manual way.
|
|
@@ -620,12 +633,27 @@ export class FastboardApp<TEventData extends Record<string, any> = any> extends
|
|
|
620
633
|
* title: 'Title',
|
|
621
634
|
* })
|
|
622
635
|
*/
|
|
623
|
-
insertDocs(params: InsertDocsParams): Promise<string | undefined>;
|
|
636
|
+
insertDocs(params: InsertDocsParams, options?: InsertDocsOptions): Promise<string | undefined>;
|
|
624
637
|
|
|
625
|
-
insertDocs(
|
|
638
|
+
insertDocs(
|
|
639
|
+
arg1: string | InsertDocsParams,
|
|
640
|
+
arg2?: ConversionResponse | ProjectorResponse | InsertDocsOptions,
|
|
641
|
+
arg3?: InsertDocsOptions
|
|
642
|
+
) {
|
|
643
|
+
const response = typeof arg1 === "string" ? (arg2 as ConversionResponse | ProjectorResponse) : undefined;
|
|
644
|
+
const options = typeof arg1 === "string" ? arg3 : (arg2 as InsertDocsOptions | undefined);
|
|
645
|
+
const staticAppKind = options?.staticRenderer === "presentation" ? "Presentation" : "DocsViewer";
|
|
646
|
+
return this._insertDocs(arg1, response, staticAppKind);
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
private _insertDocs(
|
|
650
|
+
arg1: string | InsertDocsParams,
|
|
651
|
+
arg2: ConversionResponse | ProjectorResponse | undefined,
|
|
652
|
+
staticAppKind: "DocsViewer" | "Presentation"
|
|
653
|
+
) {
|
|
626
654
|
this._assertNotDestroyed();
|
|
627
655
|
if (typeof arg1 === "object" && "fileType" in arg1) {
|
|
628
|
-
return this._insertDocsImpl(arg1);
|
|
656
|
+
return this._insertDocsImpl(arg1, staticAppKind);
|
|
629
657
|
} else if (arg2 && arg2.status !== "Finished") {
|
|
630
658
|
throw new Error("FastboardApp cannot insert a converting doc.");
|
|
631
659
|
} else if (arg2 && "progress" in arg2) {
|
|
@@ -634,9 +662,12 @@ export class FastboardApp<TEventData extends Record<string, any> = any> extends
|
|
|
634
662
|
const scenes1 = arg2.progress.convertedFileList.map(convertedFileToScene);
|
|
635
663
|
const { scenes, taskId, url } = makeSlideParams(scenes1);
|
|
636
664
|
if (taskId && url) {
|
|
637
|
-
return this._insertDocsImpl(
|
|
665
|
+
return this._insertDocsImpl(
|
|
666
|
+
{ fileType: "pptx", scenePath, scenes, title, taskId, url },
|
|
667
|
+
staticAppKind
|
|
668
|
+
);
|
|
638
669
|
} else {
|
|
639
|
-
return this._insertDocsImpl({ fileType: "pdf", scenePath, scenes: scenes1, title });
|
|
670
|
+
return this._insertDocsImpl({ fileType: "pdf", scenePath, scenes: scenes1, title }, staticAppKind);
|
|
640
671
|
}
|
|
641
672
|
} else if (arg2 && arg2.images) {
|
|
642
673
|
const title = arg1;
|
|
@@ -646,25 +677,28 @@ export class FastboardApp<TEventData extends Record<string, any> = any> extends
|
|
|
646
677
|
const { width, height, url } = arg2.images[name];
|
|
647
678
|
scenes.push({ name, ppt: { width, height, src: url } });
|
|
648
679
|
}
|
|
649
|
-
return this._insertDocsImpl({ fileType: "pdf", scenePath, scenes, title });
|
|
680
|
+
return this._insertDocsImpl({ fileType: "pdf", scenePath, scenes, title }, staticAppKind);
|
|
650
681
|
} else if (arg2 && arg2.prefix) {
|
|
651
682
|
const title = arg1;
|
|
652
683
|
const scenePath = `/${arg2.uuid}/${genUID()}`;
|
|
653
684
|
const taskId = arg2.uuid;
|
|
654
685
|
const url = arg2.prefix;
|
|
655
|
-
this._insertDocsImpl({ fileType: "pptx", scenePath, taskId, title, url });
|
|
686
|
+
return this._insertDocsImpl({ fileType: "pptx", scenePath, taskId, title, url }, staticAppKind);
|
|
656
687
|
} else {
|
|
657
688
|
throw new Error("Invalid input: not found 'progress', 'prefix' nor 'images'");
|
|
658
689
|
}
|
|
659
690
|
}
|
|
660
691
|
|
|
661
692
|
/** @internal */
|
|
662
|
-
private _insertDocsImpl(
|
|
693
|
+
private _insertDocsImpl(
|
|
694
|
+
{ fileType, scenePath, title, scenes, ...attributes }: InsertDocsParams,
|
|
695
|
+
staticAppKind: "DocsViewer" | "Presentation"
|
|
696
|
+
) {
|
|
663
697
|
this._assertNotDestroyed();
|
|
664
698
|
switch (fileType) {
|
|
665
699
|
case "pdf":
|
|
666
700
|
return this.manager.addApp({
|
|
667
|
-
kind:
|
|
701
|
+
kind: staticAppKind,
|
|
668
702
|
options: { scenePath, title, scenes },
|
|
669
703
|
});
|
|
670
704
|
case "pptx":
|
|
@@ -794,7 +828,7 @@ export async function createFastboard<TEventData extends Record<string, any> = a
|
|
|
794
828
|
_AppInMainViewPlugin = AppInMainViewPlugin;
|
|
795
829
|
joinRoomParamsWithPlugin.invisiblePlugins = [
|
|
796
830
|
...joinRoomParamsWithPlugin.invisiblePlugins,
|
|
797
|
-
|
|
831
|
+
AppInMainViewPlugin,
|
|
798
832
|
];
|
|
799
833
|
}
|
|
800
834
|
|
|
@@ -269,7 +269,7 @@ export async function replayFastboard<TEventData extends Record<string, any> = a
|
|
|
269
269
|
_AppInMainViewPlugin = AppInMainViewPlugin;
|
|
270
270
|
replayRoomParamsWithPlugin.invisiblePlugins = [
|
|
271
271
|
...replayRoomParamsWithPlugin.invisiblePlugins,
|
|
272
|
-
|
|
272
|
+
AppInMainViewPlugin,
|
|
273
273
|
];
|
|
274
274
|
}
|
|
275
275
|
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import type { WindowManager } from "@netless/window-manager";
|
|
1
|
+
import type { ExtendPlugin, WindowManager } from "@netless/window-manager";
|
|
2
|
+
import type { autorun, toJS } from "white-web-sdk";
|
|
2
3
|
|
|
3
4
|
export interface FastboardBridgeRuntime {
|
|
4
5
|
whiteWebSdk: {
|
|
5
|
-
autorun: typeof
|
|
6
|
-
toJS: typeof
|
|
6
|
+
autorun: typeof autorun;
|
|
7
|
+
toJS: typeof toJS;
|
|
7
8
|
};
|
|
8
9
|
windowManager: {
|
|
9
|
-
ExtendPlugin: typeof
|
|
10
|
+
ExtendPlugin: typeof ExtendPlugin;
|
|
10
11
|
};
|
|
11
12
|
}
|
|
12
13
|
|