@lvce-editor/extension-host-worker 8.20.0 → 8.25.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/extension-api/index.js +938 -33
- package/dist/extension-api/parts/Activation/Activation.js +4 -2
- package/dist/extension-api/parts/CommandRegistry/CommandRegistry.js +3 -1
- package/dist/extension-api/parts/CompletionProviderRegistry/CompletionProviderRegistry.js +29 -2
- package/dist/extension-api/parts/DiagnosticProviderRegistry/DiagnosticProviderRegistry.js +4 -1
- package/dist/extension-api/parts/ExecuteCommand/ExecuteCommand.js +2 -2
- package/dist/extension-api/parts/ExtensionApiCommandMap/ExtensionApiCommandMap.js +17 -1
- package/dist/extension-api/parts/FormattingProviderRegistry/FormattingProviderRegistry.js +4 -1
- package/dist/extension-api/parts/HoverProviderRegistry/HoverProviderRegistry.js +4 -1
- package/dist/extension-api/parts/NotifyStatusBarChange/NotifyStatusBarChange.js +2 -2
- package/dist/extension-api/parts/OutputChannel/OutputChannel.js +71 -0
- package/dist/extension-api/parts/OutputChannelHandle/OutputChannelHandle.js +0 -0
- package/dist/extension-api/parts/OutputChannelRegistrySnapshot/OutputChannelRegistrySnapshot.js +0 -0
- package/dist/extension-api/parts/QuickPick/QuickPick.js +2 -2
- package/dist/extension-api/parts/RegisteredOutputChannel/RegisteredOutputChannel.js +0 -0
- package/dist/extension-api/parts/StatusBarItemProviderRegistry/StatusBarItemProviderRegistry.js +3 -1
- package/dist/extension-api/parts/View/View.js +0 -0
- package/dist/extension-api/parts/ViewRegistry/ViewRegistry.js +148 -0
- package/dist/extensionHostWorkerMain.js +112 -41
- package/extension-api/dist/index.d.ts +6 -0
- package/extension-api/dist/index.js +2 -0
- package/extension-api/dist/parts/Activation/Activation.js +4 -2
- package/extension-api/dist/parts/CommandMap/CommandMap.d.ts +7 -0
- package/extension-api/dist/parts/CommandRegistry/CommandRegistry.js +3 -1
- package/extension-api/dist/parts/CommandRegistrySnapshot/CommandRegistrySnapshot.d.ts +3 -2
- package/extension-api/dist/parts/CompletionProviderRegistry/CompletionProviderRegistry.js +30 -2
- package/extension-api/dist/parts/CompletionProviderRegistrySnapshot/CompletionProviderRegistrySnapshot.d.ts +4 -2
- package/extension-api/dist/parts/DiagnosticProviderRegistry/DiagnosticProviderRegistry.js +4 -1
- package/extension-api/dist/parts/DiagnosticProviderRegistrySnapshot/DiagnosticProviderRegistrySnapshot.d.ts +4 -2
- package/extension-api/dist/parts/ExecuteCommand/ExecuteCommand.js +2 -2
- package/extension-api/dist/parts/ExtensionApiCommandMap/ExtensionApiCommandMap.d.ts +7 -0
- package/extension-api/dist/parts/ExtensionApiCommandMap/ExtensionApiCommandMap.js +9 -0
- package/extension-api/dist/parts/ExtensionApiWorkerCommandMap/ExtensionApiWorkerCommandMap.d.ts +7 -0
- package/extension-api/dist/parts/FormattingProviderRegistry/FormattingProviderRegistry.js +4 -1
- package/extension-api/dist/parts/FormattingProviderRegistrySnapshot/FormattingProviderRegistrySnapshot.d.ts +4 -2
- package/extension-api/dist/parts/HoverProviderRegistry/HoverProviderRegistry.js +4 -1
- package/extension-api/dist/parts/HoverProviderRegistrySnapshot/HoverProviderRegistrySnapshot.d.ts +4 -2
- package/extension-api/dist/parts/NotifyStatusBarChange/NotifyStatusBarChange.js +2 -2
- package/extension-api/dist/parts/OutputChannel/OutputChannel.d.ts +9 -0
- package/extension-api/dist/parts/OutputChannel/OutputChannel.js +64 -0
- package/extension-api/dist/parts/OutputChannelHandle/OutputChannelHandle.d.ts +6 -0
- package/extension-api/dist/parts/OutputChannelHandle/OutputChannelHandle.js +1 -0
- package/extension-api/dist/parts/OutputChannelRegistrySnapshot/OutputChannelRegistrySnapshot.d.ts +4 -0
- package/extension-api/dist/parts/OutputChannelRegistrySnapshot/OutputChannelRegistrySnapshot.js +1 -0
- package/extension-api/dist/parts/QuickPick/QuickPick.js +2 -2
- package/extension-api/dist/parts/RegisteredOutputChannel/RegisteredOutputChannel.d.ts +3 -0
- package/extension-api/dist/parts/RegisteredOutputChannel/RegisteredOutputChannel.js +1 -0
- package/extension-api/dist/parts/StatusBarItemProviderRegistry/StatusBarItemProviderRegistry.js +3 -1
- package/extension-api/dist/parts/StatusBarItemProviderRegistrySnapshot/StatusBarItemProviderRegistrySnapshot.d.ts +3 -2
- package/extension-api/dist/parts/View/View.d.ts +43 -0
- package/extension-api/dist/parts/View/View.js +1 -0
- package/extension-api/dist/parts/ViewRegistry/ViewRegistry.d.ts +10 -0
- package/extension-api/dist/parts/ViewRegistry/ViewRegistry.js +138 -0
- package/extension-api/package.json +4 -2
- package/extension-api/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/dist/extension-api/parts/Rpc/Rpc.js +0 -14
- package/extension-api/dist/parts/Rpc/Rpc.d.ts +0 -3
- package/extension-api/dist/parts/Rpc/Rpc.js +0 -10
package/extension-api/dist/parts/ExtensionApiWorkerCommandMap/ExtensionApiWorkerCommandMap.d.ts
CHANGED
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
export declare const commandMap: {
|
|
2
2
|
'HandleMessagePort.handleExtensionManagementMessagePort': (port: MessagePort) => Promise<void>;
|
|
3
3
|
initialize(type: string, port: MessagePort): Promise<void>;
|
|
4
|
+
'ExtensionApi.createViewInstance': (viewId: string, uid: number, context?: import("../View/View.ts").ViewContext) => Promise<import("../View/View.ts").ViewRenderResult>;
|
|
5
|
+
'ExtensionApi.dispatchViewEvent': (uid: number, event: import("../View/View.ts").ViewEvent) => Promise<import("../View/View.ts").ViewRenderResult>;
|
|
6
|
+
'ExtensionApi.disposeViewInstance': (uid: number) => Promise<void>;
|
|
4
7
|
'ExtensionApi.executeCommand': (id: string, ...args: readonly unknown[]) => Promise<unknown>;
|
|
5
8
|
'ExtensionApi.executeCompletionProvider': (textDocument: import("../CompletionTextDocument/CompletionTextDocument.ts").TextDocument, offset: number, ...args: readonly unknown[]) => Promise<readonly import("../CompletionItem/CompletionItem.ts").CompletionItem[]>;
|
|
6
9
|
'ExtensionApi.executeDiagnosticProvider': (textDocument: import("../DiagnosticTextDocument/DiagnosticTextDocument.ts").TextDocument, ...args: readonly unknown[]) => Promise<readonly import("../DiagnosticResult/DiagnosticResult.ts").Diagnostic[]>;
|
|
7
10
|
'ExtensionApi.executeFormattingProvider': (textDocument: import("../FormattingTextDocument/FormattingTextDocument.ts").TextDocument, ...args: readonly unknown[]) => Promise<readonly import("../FormattingEdit/FormattingEdit.ts").FormattingEdit[]>;
|
|
8
11
|
'ExtensionApi.executeHoverProvider': (textDocument: import("../HoverTextDocument/HoverTextDocument.ts").TextDocument, offset: number, ...args: readonly unknown[]) => Promise<import("../HoverResult/HoverResult.ts").HoverResult | undefined>;
|
|
9
12
|
'ExtensionApi.executeResolveCompletionItemProvider': (textDocument: import("../CompletionTextDocument/CompletionTextDocument.ts").TextDocument, offset: number, name: string, completionItem: import("../CompletionItem/CompletionItem.ts").CompletionItem, ...args: readonly unknown[]) => Promise<import("../CompletionItem/CompletionItem.ts").CompletionItem | undefined>;
|
|
13
|
+
'ExtensionApi.executeViewProvider': (id: string) => unknown;
|
|
10
14
|
'ExtensionApi.getCommandRegistrySnapshot': () => import("../CommandRegistrySnapshot/CommandRegistrySnapshot.ts").CommandRegistrySnapshot;
|
|
11
15
|
'ExtensionApi.getCompletionProviderRegistrySnapshot': () => import("../CompletionProviderRegistrySnapshot/CompletionProviderRegistrySnapshot.ts").CompletionProviderRegistrySnapshot;
|
|
12
16
|
'ExtensionApi.getDiagnosticProviderRegistrySnapshot': () => import("../DiagnosticProviderRegistrySnapshot/DiagnosticProviderRegistrySnapshot.ts").DiagnosticProviderRegistrySnapshot;
|
|
13
17
|
'ExtensionApi.getFormattingProviderRegistrySnapshot': () => import("../FormattingProviderRegistrySnapshot/FormattingProviderRegistrySnapshot.ts").FormattingProviderRegistrySnapshot;
|
|
14
18
|
'ExtensionApi.getHoverProviderRegistrySnapshot': () => import("../HoverProviderRegistrySnapshot/HoverProviderRegistrySnapshot.ts").HoverProviderRegistrySnapshot;
|
|
19
|
+
'ExtensionApi.getOutputChannelRegistrySnapshot': () => import("../OutputChannelRegistrySnapshot/OutputChannelRegistrySnapshot.ts").OutputChannelRegistrySnapshot;
|
|
15
20
|
'ExtensionApi.getStatusBarItems': () => readonly import("../StatusBarItem/StatusBarItem.ts").StatusBarItem[];
|
|
21
|
+
'ExtensionApi.getViewRegistrySnapshot': () => import("../View/View.ts").ViewRegistrySnapshot;
|
|
22
|
+
'ExtensionApi.saveViewInstanceState': (uid: number) => Promise<unknown>;
|
|
16
23
|
};
|
|
@@ -28,7 +28,10 @@ export const executeFormattingProvider = async (textDocument, ...args) => {
|
|
|
28
28
|
export const getFormattingProviders = registry.getProviders;
|
|
29
29
|
export const getFormattingProviderRegistrySnapshot = () => {
|
|
30
30
|
return {
|
|
31
|
-
providers: registry.getProviders()
|
|
31
|
+
providers: registry.getProviders().map((provider) => ({
|
|
32
|
+
id: provider.id,
|
|
33
|
+
languageId: provider.languageId,
|
|
34
|
+
})),
|
|
32
35
|
};
|
|
33
36
|
};
|
|
34
37
|
export const resetFormattingProviderRegistry = registry.reset;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import type { RegisteredFormattingProvider } from '../RegisteredFormattingProvider/RegisteredFormattingProvider.ts';
|
|
2
1
|
export interface FormattingProviderRegistrySnapshot {
|
|
3
|
-
readonly providers: readonly
|
|
2
|
+
readonly providers: readonly {
|
|
3
|
+
readonly id: string;
|
|
4
|
+
readonly languageId: string;
|
|
5
|
+
}[];
|
|
4
6
|
}
|
|
@@ -50,7 +50,10 @@ export const executeHoverProvider = async (textDocument, offset, ...args) => {
|
|
|
50
50
|
export const getHoverProviders = registry.getProviders;
|
|
51
51
|
export const getHoverProviderRegistrySnapshot = () => {
|
|
52
52
|
return {
|
|
53
|
-
providers: registry.getProviders()
|
|
53
|
+
providers: registry.getProviders().map((provider) => ({
|
|
54
|
+
id: provider.id,
|
|
55
|
+
languageId: provider.languageId,
|
|
56
|
+
})),
|
|
54
57
|
};
|
|
55
58
|
};
|
|
56
59
|
export const resetHoverProviderRegistry = registry.reset;
|
package/extension-api/dist/parts/HoverProviderRegistrySnapshot/HoverProviderRegistrySnapshot.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import type { RegisteredHoverProvider } from '../RegisteredHoverProvider/RegisteredHoverProvider.ts';
|
|
2
1
|
export interface HoverProviderRegistrySnapshot {
|
|
3
|
-
readonly providers: readonly
|
|
2
|
+
readonly providers: readonly {
|
|
3
|
+
readonly id: string;
|
|
4
|
+
readonly languageId: string;
|
|
5
|
+
}[];
|
|
4
6
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ExtensionManagementWorker } from '@lvce-editor/rpc-registry';
|
|
2
2
|
export const notifyStatusBarChange = async (id) => {
|
|
3
|
-
await
|
|
3
|
+
await ExtensionManagementWorker.invoke('StatusBar.handleChange', id);
|
|
4
4
|
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { OutputChannel } from '../OutputChannelHandle/OutputChannelHandle.ts';
|
|
2
|
+
import type { OutputChannelRegistrySnapshot } from '../OutputChannelRegistrySnapshot/OutputChannelRegistrySnapshot.ts';
|
|
3
|
+
export declare const activateOutputChannels: () => void;
|
|
4
|
+
export declare const createOutputChannel: (id: string) => OutputChannel;
|
|
5
|
+
export declare const getOutputChannelRegistrySnapshot: () => OutputChannelRegistrySnapshot;
|
|
6
|
+
export declare const resetOutputChannelRegistry: () => void;
|
|
7
|
+
export type { OutputChannel } from '../OutputChannelHandle/OutputChannelHandle.ts';
|
|
8
|
+
export type { OutputChannelRegistrySnapshot } from '../OutputChannelRegistrySnapshot/OutputChannelRegistrySnapshot.ts';
|
|
9
|
+
export type { RegisteredOutputChannel } from '../RegisteredOutputChannel/RegisteredOutputChannel.ts';
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { ExtensionManagementWorker } from '@lvce-editor/rpc-registry';
|
|
2
|
+
import { ExtensionApiError } from "../ExtensionApiError/ExtensionApiError.js";
|
|
3
|
+
const outputChannels = Object.create(null);
|
|
4
|
+
let isActivated = false;
|
|
5
|
+
const RE_DASH_CASE = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
6
|
+
const assertOutputChannelId = (id) => {
|
|
7
|
+
if (typeof id !== 'string' || id.length === 0) {
|
|
8
|
+
throw new ExtensionApiError('output channel id is required');
|
|
9
|
+
}
|
|
10
|
+
if (!RE_DASH_CASE.test(id)) {
|
|
11
|
+
throw new ExtensionApiError(`output channel id ${id} must be dash-case`);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
const assertCanWrite = (id) => {
|
|
15
|
+
if (!isActivated) {
|
|
16
|
+
throw new ExtensionApiError(`output channel ${id} cannot be written before activate`);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
class ExtensionOutputChannel {
|
|
20
|
+
#id;
|
|
21
|
+
constructor(id) {
|
|
22
|
+
this.#id = id;
|
|
23
|
+
}
|
|
24
|
+
async append(text) {
|
|
25
|
+
assertCanWrite(this.#id);
|
|
26
|
+
await ExtensionManagementWorker.invoke('ExtensionApi.appendOutputChannel', this.#id, text);
|
|
27
|
+
}
|
|
28
|
+
async appendLine(text) {
|
|
29
|
+
assertCanWrite(this.#id);
|
|
30
|
+
await ExtensionManagementWorker.invoke('ExtensionApi.appendOutputChannel', this.#id, `${text}\n`);
|
|
31
|
+
}
|
|
32
|
+
async clear() {
|
|
33
|
+
assertCanWrite(this.#id);
|
|
34
|
+
await ExtensionManagementWorker.invoke('ExtensionApi.clearOutputChannel', this.#id);
|
|
35
|
+
}
|
|
36
|
+
async replace(text) {
|
|
37
|
+
assertCanWrite(this.#id);
|
|
38
|
+
await ExtensionManagementWorker.invoke('ExtensionApi.replaceOutputChannel', this.#id, text);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export const activateOutputChannels = () => {
|
|
42
|
+
isActivated = true;
|
|
43
|
+
};
|
|
44
|
+
export const createOutputChannel = (id) => {
|
|
45
|
+
assertOutputChannelId(id);
|
|
46
|
+
if (id in outputChannels) {
|
|
47
|
+
throw new ExtensionApiError(`output channel ${id} is already created`);
|
|
48
|
+
}
|
|
49
|
+
outputChannels[id] = {
|
|
50
|
+
id,
|
|
51
|
+
};
|
|
52
|
+
return new ExtensionOutputChannel(id);
|
|
53
|
+
};
|
|
54
|
+
export const getOutputChannelRegistrySnapshot = () => {
|
|
55
|
+
return {
|
|
56
|
+
outputChannels: Object.values(outputChannels),
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
export const resetOutputChannelRegistry = () => {
|
|
60
|
+
for (const id of Object.keys(outputChannels)) {
|
|
61
|
+
delete outputChannels[id];
|
|
62
|
+
}
|
|
63
|
+
isActivated = false;
|
|
64
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/extension-api/dist/parts/OutputChannelRegistrySnapshot/OutputChannelRegistrySnapshot.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ExtensionManagementWorker } from '@lvce-editor/rpc-registry';
|
|
2
2
|
export const showQuickPick = async (options) => {
|
|
3
|
-
return
|
|
3
|
+
return ExtensionManagementWorker.invoke('ExtensionHostQuickPick.showQuickPick', options);
|
|
4
4
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/extension-api/dist/parts/StatusBarItemProviderRegistry/StatusBarItemProviderRegistry.js
CHANGED
|
@@ -38,7 +38,9 @@ export const getStatusBarItems = () => {
|
|
|
38
38
|
};
|
|
39
39
|
export const getStatusBarItemProviderRegistrySnapshot = () => {
|
|
40
40
|
return {
|
|
41
|
-
providers: registry.getProviders()
|
|
41
|
+
providers: registry.getProviders().map((provider) => ({
|
|
42
|
+
id: provider.id,
|
|
43
|
+
})),
|
|
42
44
|
};
|
|
43
45
|
};
|
|
44
46
|
export const resetStatusBarItemProviderRegistry = registry.reset;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { RegisteredStatusBarItemProvider } from '../RegisteredStatusBarItemProvider/RegisteredStatusBarItemProvider.ts';
|
|
2
1
|
export interface StatusBarItemProviderRegistrySnapshot {
|
|
3
|
-
readonly providers: readonly
|
|
2
|
+
readonly providers: readonly {
|
|
3
|
+
readonly id: string;
|
|
4
|
+
}[];
|
|
4
5
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { VirtualDomNode } from '@lvce-editor/virtual-dom-worker';
|
|
2
|
+
export type ViewKind = 'virtualDom';
|
|
3
|
+
export interface ViewContext {
|
|
4
|
+
readonly state?: unknown;
|
|
5
|
+
readonly uid: number;
|
|
6
|
+
readonly viewId: string;
|
|
7
|
+
}
|
|
8
|
+
export interface ViewEvent {
|
|
9
|
+
readonly name?: string;
|
|
10
|
+
readonly type: string;
|
|
11
|
+
readonly value?: unknown;
|
|
12
|
+
}
|
|
13
|
+
export interface VirtualDomViewInstance {
|
|
14
|
+
readonly dispose?: () => unknown;
|
|
15
|
+
readonly handleEvent?: (event: ViewEvent) => unknown;
|
|
16
|
+
readonly render: () => readonly VirtualDomNode[] | Promise<readonly VirtualDomNode[]>;
|
|
17
|
+
readonly saveState?: () => unknown;
|
|
18
|
+
}
|
|
19
|
+
export interface View {
|
|
20
|
+
readonly create: (context?: ViewContext) => unknown;
|
|
21
|
+
readonly icon?: string;
|
|
22
|
+
readonly id: string;
|
|
23
|
+
readonly kind?: ViewKind;
|
|
24
|
+
readonly title?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface RegisteredView {
|
|
27
|
+
readonly icon?: string;
|
|
28
|
+
readonly id: string;
|
|
29
|
+
readonly kind?: ViewKind;
|
|
30
|
+
readonly title?: string;
|
|
31
|
+
}
|
|
32
|
+
export interface ViewRegistrySnapshot {
|
|
33
|
+
readonly views: readonly RegisteredView[];
|
|
34
|
+
}
|
|
35
|
+
export interface ViewRenderResultDom {
|
|
36
|
+
readonly dom: readonly VirtualDomNode[];
|
|
37
|
+
readonly type: 'setDom';
|
|
38
|
+
}
|
|
39
|
+
export interface ViewRenderResultPatches {
|
|
40
|
+
readonly patches: readonly unknown[];
|
|
41
|
+
readonly type: 'setPatches';
|
|
42
|
+
}
|
|
43
|
+
export type ViewRenderResult = ViewRenderResultDom | ViewRenderResultPatches;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Disposable } from '../Disposable/Disposable.ts';
|
|
2
|
+
import type { View, ViewContext, ViewEvent, ViewRegistrySnapshot, ViewRenderResult } from '../View/View.ts';
|
|
3
|
+
export declare const registerView: (view: View) => Disposable;
|
|
4
|
+
export declare const executeViewProvider: (id: string) => unknown;
|
|
5
|
+
export declare const createViewInstance: (viewId: string, uid: number, context?: ViewContext) => Promise<ViewRenderResult>;
|
|
6
|
+
export declare const dispatchViewEvent: (uid: number, event: ViewEvent) => Promise<ViewRenderResult>;
|
|
7
|
+
export declare const disposeViewInstance: (uid: number) => Promise<void>;
|
|
8
|
+
export declare const saveViewInstanceState: (uid: number) => Promise<unknown>;
|
|
9
|
+
export declare const getViewRegistrySnapshot: () => ViewRegistrySnapshot;
|
|
10
|
+
export declare const resetViewRegistry: () => void;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { diffTree } from '@lvce-editor/virtual-dom-worker';
|
|
2
|
+
import { ExtensionApiError } from "../ExtensionApiError/ExtensionApiError.js";
|
|
3
|
+
const views = Object.create(null);
|
|
4
|
+
const instances = Object.create(null);
|
|
5
|
+
const renderedDoms = Object.create(null);
|
|
6
|
+
const assertView = (view) => {
|
|
7
|
+
if (!view) {
|
|
8
|
+
throw new ExtensionApiError('view is not defined');
|
|
9
|
+
}
|
|
10
|
+
if (typeof view.id !== 'string' || view.id.length === 0) {
|
|
11
|
+
throw new ExtensionApiError('view is missing id');
|
|
12
|
+
}
|
|
13
|
+
if (typeof view.create !== 'function') {
|
|
14
|
+
throw new ExtensionApiError(`view ${view.id} is missing create function`);
|
|
15
|
+
}
|
|
16
|
+
if (view.id in views) {
|
|
17
|
+
throw new ExtensionApiError(`view ${view.id} is already registered`);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
const toRegisteredView = (view) => {
|
|
21
|
+
const registeredView = {
|
|
22
|
+
icon: view.icon,
|
|
23
|
+
id: view.id,
|
|
24
|
+
title: view.title,
|
|
25
|
+
};
|
|
26
|
+
if (view.kind) {
|
|
27
|
+
return {
|
|
28
|
+
...registeredView,
|
|
29
|
+
kind: view.kind,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
return registeredView;
|
|
33
|
+
};
|
|
34
|
+
export const registerView = (view) => {
|
|
35
|
+
assertView(view);
|
|
36
|
+
views[view.id] = view;
|
|
37
|
+
return {
|
|
38
|
+
dispose() {
|
|
39
|
+
delete views[view.id];
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
export const executeViewProvider = (id) => {
|
|
44
|
+
const view = views[id];
|
|
45
|
+
if (!view) {
|
|
46
|
+
throw new ExtensionApiError(`view ${id} not found`);
|
|
47
|
+
}
|
|
48
|
+
return view.create();
|
|
49
|
+
};
|
|
50
|
+
const assertVirtualDomViewInstance = (id, instance) => {
|
|
51
|
+
if (!instance || typeof instance !== 'object') {
|
|
52
|
+
throw new ExtensionApiError(`view ${id} did not return a view instance`);
|
|
53
|
+
}
|
|
54
|
+
if (typeof instance.render !== 'function') {
|
|
55
|
+
throw new ExtensionApiError(`view ${id} instance is missing render function`);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
const getVirtualDomInstance = (uid) => {
|
|
59
|
+
const instance = instances[uid];
|
|
60
|
+
if (!instance) {
|
|
61
|
+
throw new ExtensionApiError(`view instance ${uid} not found`);
|
|
62
|
+
}
|
|
63
|
+
return instance;
|
|
64
|
+
};
|
|
65
|
+
const renderDom = async (instance) => {
|
|
66
|
+
const dom = await instance.render();
|
|
67
|
+
if (!Array.isArray(dom)) {
|
|
68
|
+
throw new ExtensionApiError('view render result must be an array');
|
|
69
|
+
}
|
|
70
|
+
return dom;
|
|
71
|
+
};
|
|
72
|
+
export const createViewInstance = async (viewId, uid, context) => {
|
|
73
|
+
const view = views[viewId];
|
|
74
|
+
if (!view) {
|
|
75
|
+
throw new ExtensionApiError(`view ${viewId} not found`);
|
|
76
|
+
}
|
|
77
|
+
if (view.kind !== 'virtualDom') {
|
|
78
|
+
throw new ExtensionApiError(`view ${viewId} is not a virtual dom view`);
|
|
79
|
+
}
|
|
80
|
+
const instance = await view.create({
|
|
81
|
+
...context,
|
|
82
|
+
uid,
|
|
83
|
+
viewId,
|
|
84
|
+
});
|
|
85
|
+
assertVirtualDomViewInstance(viewId, instance);
|
|
86
|
+
instances[uid] = instance;
|
|
87
|
+
const dom = await renderDom(instance);
|
|
88
|
+
renderedDoms[uid] = dom;
|
|
89
|
+
return {
|
|
90
|
+
dom,
|
|
91
|
+
type: 'setDom',
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
export const dispatchViewEvent = async (uid, event) => {
|
|
95
|
+
const instance = getVirtualDomInstance(uid);
|
|
96
|
+
if (typeof instance.handleEvent === 'function') {
|
|
97
|
+
await instance.handleEvent(event);
|
|
98
|
+
}
|
|
99
|
+
const oldDom = renderedDoms[uid] || [];
|
|
100
|
+
const newDom = await renderDom(instance);
|
|
101
|
+
renderedDoms[uid] = newDom;
|
|
102
|
+
const patches = diffTree(oldDom, newDom);
|
|
103
|
+
return {
|
|
104
|
+
patches,
|
|
105
|
+
type: 'setPatches',
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
export const disposeViewInstance = async (uid) => {
|
|
109
|
+
const instance = instances[uid];
|
|
110
|
+
if (instance && typeof instance.dispose === 'function') {
|
|
111
|
+
await instance.dispose();
|
|
112
|
+
}
|
|
113
|
+
delete instances[uid];
|
|
114
|
+
delete renderedDoms[uid];
|
|
115
|
+
};
|
|
116
|
+
export const saveViewInstanceState = async (uid) => {
|
|
117
|
+
const instance = getVirtualDomInstance(uid);
|
|
118
|
+
if (typeof instance.saveState !== 'function') {
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
return instance.saveState();
|
|
122
|
+
};
|
|
123
|
+
export const getViewRegistrySnapshot = () => {
|
|
124
|
+
return {
|
|
125
|
+
views: Object.values(views).map(toRegisteredView),
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
export const resetViewRegistry = () => {
|
|
129
|
+
for (const id of Object.keys(views)) {
|
|
130
|
+
delete views[id];
|
|
131
|
+
}
|
|
132
|
+
for (const uid of Object.keys(instances)) {
|
|
133
|
+
delete instances[Number(uid)];
|
|
134
|
+
}
|
|
135
|
+
for (const uid of Object.keys(renderedDoms)) {
|
|
136
|
+
delete renderedDoms[Number(uid)];
|
|
137
|
+
}
|
|
138
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/api",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.25.0",
|
|
4
4
|
"description": "Tree-shakeable extension API for Lvce Editor extensions.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lvce-editor",
|
|
@@ -27,6 +27,8 @@
|
|
|
27
27
|
],
|
|
28
28
|
"sideEffects": false,
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@lvce-editor/rpc": "^6.4.0"
|
|
30
|
+
"@lvce-editor/rpc": "^6.4.0",
|
|
31
|
+
"@lvce-editor/rpc-registry": "^9.24.0",
|
|
32
|
+
"@lvce-editor/virtual-dom-worker": "^10.0.0"
|
|
31
33
|
}
|
|
32
34
|
}
|