@lvce-editor/api 8.41.0 → 8.42.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.
@@ -42,6 +42,7 @@ export interface VirtualDomViewInstance {
42
42
  readonly render: () => readonly VirtualDomNode[] | Promise<readonly VirtualDomNode[]>;
43
43
  readonly renderActions?: () => readonly ViewAction[] | Promise<readonly ViewAction[]>;
44
44
  readonly renderFocus?: (oldContext: Readonly<Record<string, boolean>>, newContext: Readonly<Record<string, boolean>>) => string | Promise<string>;
45
+ readonly renderTitle?: () => string | Promise<string>;
45
46
  readonly saveState?: () => unknown;
46
47
  }
47
48
  export type ViewCommand<State = VirtualDomViewInstance, Args extends readonly any[] = readonly any[]> = (state: State, ...args: Args) => State | Promise<State>;
@@ -71,11 +72,13 @@ export interface ViewRegistrySnapshot {
71
72
  export interface ViewRenderResultDom {
72
73
  readonly dom: readonly VirtualDomNode[];
73
74
  readonly focusSelector?: string;
75
+ readonly title?: string;
74
76
  readonly type: 'setDom';
75
77
  }
76
78
  export interface ViewRenderResultPatches {
77
79
  readonly focusSelector?: string;
78
80
  readonly patches: readonly unknown[];
81
+ readonly title?: string;
79
82
  readonly type: 'setPatches';
80
83
  }
81
84
  export type ViewRenderResult = ViewRenderResultDom | ViewRenderResultPatches;
@@ -323,6 +323,23 @@ const withFocusSelector = async (result, instance, contextChange) => {
323
323
  focusSelector,
324
324
  };
325
325
  };
326
+ const withTitle = async (result, instance) => {
327
+ if (typeof instance.renderTitle !== 'function') {
328
+ return result;
329
+ }
330
+ const title = await instance.renderTitle();
331
+ if (typeof title !== 'string') {
332
+ throw new ExtensionApiError('view renderTitle result must be a string');
333
+ }
334
+ return {
335
+ ...result,
336
+ title,
337
+ };
338
+ };
339
+ const withRenderMetadata = async (result, instance, contextChange) => {
340
+ const resultWithFocus = await withFocusSelector(result, instance, contextChange);
341
+ return withTitle(resultWithFocus, instance);
342
+ };
326
343
  const maybeClearContext = async (uid, viewId) => {
327
344
  if (!contexts[uid]) {
328
345
  return;
@@ -365,7 +382,7 @@ export const createViewInstance = async (viewId, uid, context) => {
365
382
  type: 'setDom',
366
383
  };
367
384
  const contextChange = await maybeNotifyContextChanged(uid, viewId, instance);
368
- return withFocusSelector(result, instance, contextChange);
385
+ return withRenderMetadata(result, instance, contextChange);
369
386
  };
370
387
  export const dispatchViewEvent = async (uid, event) => {
371
388
  const instance = getVirtualDomInstance(uid);
@@ -377,13 +394,13 @@ export const dispatchViewEvent = async (uid, event) => {
377
394
  }
378
395
  const result = await renderPatches(uid, instance);
379
396
  const contextChange = await maybeNotifyContextChanged(uid, contextViewIds[uid], instance);
380
- return withFocusSelector(result, instance, contextChange);
397
+ return withRenderMetadata(result, instance, contextChange);
381
398
  };
382
399
  export const renderViewInstance = async (uid) => {
383
400
  const instance = getVirtualDomInstance(uid);
384
401
  const result = await renderPatches(uid, instance);
385
402
  const contextChange = await maybeNotifyContextChanged(uid, contextViewIds[uid], instance);
386
- return withFocusSelector(result, instance, contextChange);
403
+ return withRenderMetadata(result, instance, contextChange);
387
404
  };
388
405
  export const disposeViewInstance = async (uid) => {
389
406
  const instance = instances[uid];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/api",
3
- "version": "8.41.0",
3
+ "version": "8.42.0",
4
4
  "description": "Tree-shakeable extension API for Lvce Editor extensions.",
5
5
  "keywords": [
6
6
  "lvce-editor",