@lvce-editor/api 8.43.1 → 8.44.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/index.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export { executeSourceControlAcceptInput, executeSourceControlAdd, executeSource
|
|
|
13
13
|
export { createViewInstance, dispatchViewEvent, disposeViewInstance, executeViewProvider, getViewRegistrySnapshot, renderViewInstance, registerView, resetViewRegistry, saveViewInstanceState, } from './parts/ViewRegistry/ViewRegistry.ts';
|
|
14
14
|
export { createOutputChannel, getOutputChannelRegistrySnapshot, resetOutputChannelRegistry } from './parts/OutputChannel/OutputChannel.ts';
|
|
15
15
|
export { getStatusBarItemProviderRegistrySnapshot, registerStatusBarItemProvider, resetStatusBarItemProviderRegistry, } from './parts/StatusBar/StatusBar.ts';
|
|
16
|
-
export type { RegisteredView, View, ViewAction, ViewCommand, ViewContext, ViewEvent, ViewKind, MenuEntry, ViewRegistrySnapshot, ViewRenderResult, VirtualDomViewInstance, } from './parts/View/View.ts';
|
|
16
|
+
export type { RegisteredView, View, ViewAction, ViewCommand, ViewContext, ViewEvent, ViewKind, MenuEntry, ViewRegistrySnapshot, ViewRenderResult, ViewSelection, VirtualDomViewInstance, } from './parts/View/View.ts';
|
|
17
17
|
export { handleExtensionManagementMessagePort } from './parts/HandleExtensionManagementMessagePort/HandleExtensionManagementMessagePort.ts';
|
|
18
18
|
export { createNodeRpc, createRpc } from './parts/Rpc/Rpc.ts';
|
|
19
19
|
export type { Command } from './parts/Command/Command.ts';
|
|
@@ -26,6 +26,11 @@ export interface ViewAction {
|
|
|
26
26
|
readonly icon: string;
|
|
27
27
|
readonly title: string;
|
|
28
28
|
}
|
|
29
|
+
export interface ViewSelection {
|
|
30
|
+
readonly end: number;
|
|
31
|
+
readonly name: string;
|
|
32
|
+
readonly start: number;
|
|
33
|
+
}
|
|
29
34
|
export interface DomEventListener {
|
|
30
35
|
readonly capture?: boolean;
|
|
31
36
|
readonly name: string | number;
|
|
@@ -42,6 +47,7 @@ export interface VirtualDomViewInstance {
|
|
|
42
47
|
readonly render: () => readonly VirtualDomNode[] | Promise<readonly VirtualDomNode[]>;
|
|
43
48
|
readonly renderActions?: () => readonly ViewAction[] | Promise<readonly ViewAction[]>;
|
|
44
49
|
readonly renderFocus?: (oldContext: Readonly<Record<string, boolean>>, newContext: Readonly<Record<string, boolean>>) => string | Promise<string>;
|
|
50
|
+
readonly renderSelections?: () => readonly ViewSelection[] | Promise<readonly ViewSelection[]>;
|
|
45
51
|
readonly renderTitle?: () => string | Promise<string>;
|
|
46
52
|
readonly saveState?: () => unknown;
|
|
47
53
|
}
|
|
@@ -72,12 +78,14 @@ export interface ViewRegistrySnapshot {
|
|
|
72
78
|
export interface ViewRenderResultDom {
|
|
73
79
|
readonly dom: readonly VirtualDomNode[];
|
|
74
80
|
readonly focusSelector?: string;
|
|
81
|
+
readonly selections?: readonly ViewSelection[];
|
|
75
82
|
readonly title?: string;
|
|
76
83
|
readonly type: 'setDom';
|
|
77
84
|
}
|
|
78
85
|
export interface ViewRenderResultPatches {
|
|
79
86
|
readonly focusSelector?: string;
|
|
80
87
|
readonly patches: readonly unknown[];
|
|
88
|
+
readonly selections?: readonly ViewSelection[];
|
|
81
89
|
readonly title?: string;
|
|
82
90
|
readonly type: 'setPatches';
|
|
83
91
|
}
|
|
@@ -237,6 +237,26 @@ const normalizeViewActions = (actions) => {
|
|
|
237
237
|
}
|
|
238
238
|
return actions.map(normalizeViewAction);
|
|
239
239
|
};
|
|
240
|
+
const normalizeViewSelection = (selection, index) => {
|
|
241
|
+
if (!selection || typeof selection !== 'object' || Array.isArray(selection)) {
|
|
242
|
+
throw new ExtensionApiError(`view selection ${index} must be an object`);
|
|
243
|
+
}
|
|
244
|
+
const viewSelection = selection;
|
|
245
|
+
assertString(viewSelection.name, `view selection ${index} is missing name`);
|
|
246
|
+
assertNumber(viewSelection.start, `view selection ${index} is missing start`);
|
|
247
|
+
assertNumber(viewSelection.end, `view selection ${index} is missing end`);
|
|
248
|
+
return {
|
|
249
|
+
end: viewSelection.end,
|
|
250
|
+
name: viewSelection.name,
|
|
251
|
+
start: viewSelection.start,
|
|
252
|
+
};
|
|
253
|
+
};
|
|
254
|
+
const normalizeViewSelections = (selections) => {
|
|
255
|
+
if (!Array.isArray(selections)) {
|
|
256
|
+
throw new ExtensionApiError('view selections must be an array');
|
|
257
|
+
}
|
|
258
|
+
return selections.map(normalizeViewSelection);
|
|
259
|
+
};
|
|
240
260
|
const renderPatches = async (uid, instance) => {
|
|
241
261
|
const oldDom = renderedDoms[uid] || [];
|
|
242
262
|
const newDom = await renderDom(instance);
|
|
@@ -336,9 +356,23 @@ const withTitle = async (result, instance) => {
|
|
|
336
356
|
title,
|
|
337
357
|
};
|
|
338
358
|
};
|
|
359
|
+
const withSelections = async (result, instance) => {
|
|
360
|
+
if (typeof instance.renderSelections !== 'function') {
|
|
361
|
+
return result;
|
|
362
|
+
}
|
|
363
|
+
const selections = normalizeViewSelections(await instance.renderSelections());
|
|
364
|
+
if (selections.length === 0) {
|
|
365
|
+
return result;
|
|
366
|
+
}
|
|
367
|
+
return {
|
|
368
|
+
...result,
|
|
369
|
+
selections,
|
|
370
|
+
};
|
|
371
|
+
};
|
|
339
372
|
const withRenderMetadata = async (result, instance, contextChange) => {
|
|
340
373
|
const resultWithFocus = await withFocusSelector(result, instance, contextChange);
|
|
341
|
-
|
|
374
|
+
const resultWithSelections = await withSelections(resultWithFocus, instance);
|
|
375
|
+
return withTitle(resultWithSelections, instance);
|
|
342
376
|
};
|
|
343
377
|
const maybeClearContext = async (uid, viewId) => {
|
|
344
378
|
if (!contexts[uid]) {
|