@lvce-editor/api 8.54.0 → 8.56.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.
|
@@ -8,6 +8,8 @@ export interface ViewContext {
|
|
|
8
8
|
readonly viewId: string;
|
|
9
9
|
}
|
|
10
10
|
export interface ViewEvent {
|
|
11
|
+
readonly args?: readonly unknown[];
|
|
12
|
+
readonly handler?: string;
|
|
11
13
|
readonly name?: string;
|
|
12
14
|
readonly type: string;
|
|
13
15
|
readonly value?: unknown;
|
|
@@ -44,6 +46,7 @@ export interface DomEventListener {
|
|
|
44
46
|
export interface VirtualDomViewInstance {
|
|
45
47
|
readonly dispose?: () => unknown;
|
|
46
48
|
readonly getContext?: () => Readonly<Record<string, boolean>>;
|
|
49
|
+
readonly getCss?: () => string | Promise<string>;
|
|
47
50
|
readonly getMenuEntries?: (menuId: string) => readonly MenuEntry[] | Promise<readonly MenuEntry[]>;
|
|
48
51
|
readonly handleEvent?: (event: ViewEvent) => unknown;
|
|
49
52
|
readonly render: () => readonly VirtualDomNode[] | Promise<readonly VirtualDomNode[]>;
|
|
@@ -79,6 +82,7 @@ export interface ViewRegistrySnapshot {
|
|
|
79
82
|
readonly views: readonly RegisteredView[];
|
|
80
83
|
}
|
|
81
84
|
export interface ViewRenderResultDom {
|
|
85
|
+
readonly css?: string;
|
|
82
86
|
readonly dom: readonly VirtualDomNode[];
|
|
83
87
|
readonly focusSelector?: string;
|
|
84
88
|
readonly scrollPosition?: ViewScrollPosition;
|
|
@@ -87,6 +91,7 @@ export interface ViewRenderResultDom {
|
|
|
87
91
|
readonly type: 'setDom';
|
|
88
92
|
}
|
|
89
93
|
export interface ViewRenderResultPatches {
|
|
94
|
+
readonly css?: string;
|
|
90
95
|
readonly focusSelector?: string;
|
|
91
96
|
readonly patches: readonly unknown[];
|
|
92
97
|
readonly scrollPosition?: ViewScrollPosition;
|
|
@@ -362,6 +362,19 @@ const withFocusSelector = async (result, instance, contextChange) => {
|
|
|
362
362
|
focusSelector,
|
|
363
363
|
};
|
|
364
364
|
};
|
|
365
|
+
const withCss = async (result, instance) => {
|
|
366
|
+
if (typeof instance.getCss !== 'function') {
|
|
367
|
+
return result;
|
|
368
|
+
}
|
|
369
|
+
const css = await instance.getCss();
|
|
370
|
+
if (typeof css !== 'string') {
|
|
371
|
+
throw new ExtensionApiError('view getCss result must be a string');
|
|
372
|
+
}
|
|
373
|
+
return {
|
|
374
|
+
...result,
|
|
375
|
+
css,
|
|
376
|
+
};
|
|
377
|
+
};
|
|
365
378
|
const withTitle = async (result, instance) => {
|
|
366
379
|
if (typeof instance.renderTitle !== 'function') {
|
|
367
380
|
return result;
|
|
@@ -402,7 +415,8 @@ const withScrollPosition = async (result, instance) => {
|
|
|
402
415
|
};
|
|
403
416
|
};
|
|
404
417
|
const withRenderMetadata = async (result, instance, contextChange) => {
|
|
405
|
-
const
|
|
418
|
+
const resultWithCss = await withCss(result, instance);
|
|
419
|
+
const resultWithFocus = await withFocusSelector(resultWithCss, instance, contextChange);
|
|
406
420
|
const resultWithSelections = await withSelections(resultWithFocus, instance);
|
|
407
421
|
const resultWithScrollPosition = await withScrollPosition(resultWithSelections, instance);
|
|
408
422
|
return withTitle(resultWithScrollPosition, instance);
|
|
@@ -456,7 +470,14 @@ export const dispatchViewEvent = async (uid, event) => {
|
|
|
456
470
|
const instanceUids = instanceUidsByView[contextViewIds[uid]];
|
|
457
471
|
instanceUids.delete(uid);
|
|
458
472
|
instanceUids.add(uid);
|
|
459
|
-
if (
|
|
473
|
+
if (event.handler) {
|
|
474
|
+
const handler = instance[event.handler];
|
|
475
|
+
if (typeof handler !== 'function') {
|
|
476
|
+
throw new TypeError(`view event handler ${event.handler} is not a function`);
|
|
477
|
+
}
|
|
478
|
+
await Reflect.apply(handler, instance, event.args || []);
|
|
479
|
+
}
|
|
480
|
+
else if (typeof instance.handleEvent === 'function') {
|
|
460
481
|
await instance.handleEvent(event);
|
|
461
482
|
}
|
|
462
483
|
const result = await renderPatches(uid, instance);
|