@lvce-editor/api 9.17.1 → 9.18.1
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.js
CHANGED
|
@@ -6,6 +6,7 @@ const resolveRpcOptions = async (options) => {
|
|
|
6
6
|
return {
|
|
7
7
|
contentSecurityPolicy: info.contentSecurityPolicy || '',
|
|
8
8
|
name: info.name || '',
|
|
9
|
+
traceId: options.id,
|
|
9
10
|
url: info.url,
|
|
10
11
|
};
|
|
11
12
|
}
|
|
@@ -18,8 +19,8 @@ const resolveRpcOptions = async (options) => {
|
|
|
18
19
|
}
|
|
19
20
|
throw new TypeError('createRpc requires an id or url');
|
|
20
21
|
};
|
|
21
|
-
const sendMessagePortToWebWorker = async (port, contentSecurityPolicy, name, url) => {
|
|
22
|
-
await ExtensionManagementWorker.invokeAndTransfer('Extensions.createWebViewWorkerRpc2', { contentSecurityPolicy, name, url }, port);
|
|
22
|
+
const sendMessagePortToWebWorker = async (port, contentSecurityPolicy, name, traceId, url) => {
|
|
23
|
+
await ExtensionManagementWorker.invokeAndTransfer('Extensions.createWebViewWorkerRpc2', { contentSecurityPolicy, name, ...(traceId && { traceId }), url }, port);
|
|
23
24
|
};
|
|
24
25
|
const createMessagePortRpc = async (commandMap, send) => {
|
|
25
26
|
const { port1, port2 } = new MessageChannel();
|
|
@@ -34,8 +35,8 @@ const createMessagePortRpc = async (commandMap, send) => {
|
|
|
34
35
|
};
|
|
35
36
|
export const createRpc = async (options) => {
|
|
36
37
|
const { commandMap = {} } = options;
|
|
37
|
-
const { contentSecurityPolicy, name, url } = await resolveRpcOptions(options);
|
|
38
|
-
return createMessagePortRpc(commandMap, (port) => sendMessagePortToWebWorker(port, contentSecurityPolicy, name, url));
|
|
38
|
+
const { contentSecurityPolicy, name, traceId, url } = await resolveRpcOptions(options);
|
|
39
|
+
return createMessagePortRpc(commandMap, (port) => sendMessagePortToWebWorker(port, contentSecurityPolicy, name, traceId, url));
|
|
39
40
|
};
|
|
40
41
|
const isMissingCommand = (error, command) => {
|
|
41
42
|
return error instanceof Error && error.message.includes(command) && /command not found|not found/i.test(error.message);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ExtensionManagementWorker } from '@lvce-editor/rpc-registry';
|
|
2
|
-
import { diffTree } from '@lvce-editor/virtual-dom-worker';
|
|
2
|
+
import { diffTree, validate as validateVirtualDom } from '@lvce-editor/virtual-dom-worker';
|
|
3
3
|
import { registerCommand } from "../CommandRegistry/CommandRegistry.js";
|
|
4
4
|
import * as ExtensionApiCommandRegistry from "../ExtensionApiCommandRegistry/ExtensionApiCommandRegistry.js";
|
|
5
5
|
import { ExtensionApiError } from "../ExtensionApiError/ExtensionApiError.js";
|
|
@@ -194,11 +194,14 @@ const getVirtualDomInstance = (uid) => {
|
|
|
194
194
|
}
|
|
195
195
|
return instance;
|
|
196
196
|
};
|
|
197
|
-
const renderDom = async (instance) => {
|
|
197
|
+
const renderDom = async (viewId, instance) => {
|
|
198
198
|
const dom = await instance.render();
|
|
199
199
|
if (!Array.isArray(dom)) {
|
|
200
200
|
throw new ExtensionApiError('view render result must be an array');
|
|
201
201
|
}
|
|
202
|
+
if (!validateVirtualDom(dom)) {
|
|
203
|
+
throw new ExtensionApiError(`view ${viewId} render result must be valid virtual dom`);
|
|
204
|
+
}
|
|
202
205
|
return dom;
|
|
203
206
|
};
|
|
204
207
|
const normalizeMenuEntry = (entry, index) => {
|
|
@@ -285,7 +288,7 @@ const normalizeViewScrollPosition = (scrollPosition) => {
|
|
|
285
288
|
};
|
|
286
289
|
const renderPatches = async (uid, instance) => {
|
|
287
290
|
const oldDom = renderedDoms[uid] || [];
|
|
288
|
-
const newDom = await renderDom(instance);
|
|
291
|
+
const newDom = await renderDom(contextViewIds[uid], instance);
|
|
289
292
|
renderedDoms[uid] = newDom;
|
|
290
293
|
const patches = diffTree(oldDom, newDom);
|
|
291
294
|
return {
|
|
@@ -465,7 +468,7 @@ export const createViewInstance = async (viewId, uid, context) => {
|
|
|
465
468
|
instanceUids.add(uid);
|
|
466
469
|
instanceUidsByView[viewId] = instanceUids;
|
|
467
470
|
contextViewIds[uid] = viewId;
|
|
468
|
-
const dom = await renderDom(instance);
|
|
471
|
+
const dom = await renderDom(viewId, instance);
|
|
469
472
|
renderedDoms[uid] = dom;
|
|
470
473
|
const result = {
|
|
471
474
|
dom,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/api",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.18.1",
|
|
4
4
|
"description": "Tree-shakeable extension API for Lvce Editor extensions.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lvce-editor",
|
|
@@ -30,6 +30,6 @@
|
|
|
30
30
|
"@lvce-editor/command": "^2.0.0",
|
|
31
31
|
"@lvce-editor/rpc": "^6.4.0",
|
|
32
32
|
"@lvce-editor/rpc-registry": "^9.24.0",
|
|
33
|
-
"@lvce-editor/virtual-dom-worker": "^
|
|
33
|
+
"@lvce-editor/virtual-dom-worker": "^11.2.0"
|
|
34
34
|
}
|
|
35
35
|
}
|