@lvce-editor/api 9.13.0 → 9.15.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/dist/parts/Rpc/Rpc.d.ts +10 -3
- package/dist/parts/Rpc/Rpc.js +21 -1
- package/package.json +1 -1
package/dist/parts/Rpc/Rpc.d.ts
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
import { type Rpc } from '@lvce-editor/rpc';
|
|
2
|
-
|
|
2
|
+
interface CreateRpcBaseOptions {
|
|
3
3
|
readonly commandMap?: Record<string, unknown>;
|
|
4
|
-
|
|
4
|
+
}
|
|
5
|
+
interface CreateDeclaredRpcOptions extends CreateRpcBaseOptions {
|
|
6
|
+
readonly id: string;
|
|
7
|
+
}
|
|
8
|
+
interface CreateLegacyRpcOptions extends CreateRpcBaseOptions {
|
|
9
|
+
readonly contentSecurityPolicy?: readonly string[] | string;
|
|
5
10
|
readonly name?: string;
|
|
6
11
|
readonly url: string;
|
|
7
12
|
}
|
|
13
|
+
export type CreateRpcOptions = CreateDeclaredRpcOptions | CreateLegacyRpcOptions;
|
|
8
14
|
export interface CreateNodeRpcOptions {
|
|
9
15
|
readonly id: string;
|
|
10
16
|
readonly legacyName?: string;
|
|
11
17
|
readonly legacyPath?: string;
|
|
12
18
|
}
|
|
13
|
-
export declare const createRpc: (
|
|
19
|
+
export declare const createRpc: (options: CreateRpcOptions) => Promise<Rpc>;
|
|
14
20
|
export declare const createNodeRpc: (options: CreateNodeRpcOptions) => Promise<Rpc>;
|
|
21
|
+
export {};
|
package/dist/parts/Rpc/Rpc.js
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
import { MessagePortRpcParent, WebSocketRpcParent } from '@lvce-editor/rpc';
|
|
2
2
|
import { ExtensionManagementWorker } from '@lvce-editor/rpc-registry';
|
|
3
|
+
const resolveRpcOptions = async (options) => {
|
|
4
|
+
if ('id' in options && options.id) {
|
|
5
|
+
const info = (await ExtensionManagementWorker.invoke('Extensions.getRpcInfo', options.id));
|
|
6
|
+
return {
|
|
7
|
+
contentSecurityPolicy: info.contentSecurityPolicy || '',
|
|
8
|
+
name: info.name || '',
|
|
9
|
+
url: info.url,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
if ('url' in options && options.url) {
|
|
13
|
+
return {
|
|
14
|
+
contentSecurityPolicy: options.contentSecurityPolicy || '',
|
|
15
|
+
name: options.name || '',
|
|
16
|
+
url: options.url,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
throw new TypeError('createRpc requires an id or url');
|
|
20
|
+
};
|
|
3
21
|
const sendMessagePortToWebWorker = async (port, contentSecurityPolicy, name, url) => {
|
|
4
22
|
await ExtensionManagementWorker.invokeAndTransfer('Extensions.createWebViewWorkerRpc2', { contentSecurityPolicy, name, url }, port);
|
|
5
23
|
};
|
|
@@ -14,7 +32,9 @@ const createMessagePortRpc = async (commandMap, send) => {
|
|
|
14
32
|
await send(port1);
|
|
15
33
|
return rpcPromise;
|
|
16
34
|
};
|
|
17
|
-
export const createRpc = async (
|
|
35
|
+
export const createRpc = async (options) => {
|
|
36
|
+
const { commandMap = {} } = options;
|
|
37
|
+
const { contentSecurityPolicy, name, url } = await resolveRpcOptions(options);
|
|
18
38
|
return createMessagePortRpc(commandMap, (port) => sendMessagePortToWebWorker(port, contentSecurityPolicy, name, url));
|
|
19
39
|
};
|
|
20
40
|
const isMissingCommand = (error, command) => {
|