@lvce-editor/api 8.55.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;
@@ -470,7 +470,14 @@ export const dispatchViewEvent = async (uid, event) => {
470
470
  const instanceUids = instanceUidsByView[contextViewIds[uid]];
471
471
  instanceUids.delete(uid);
472
472
  instanceUids.add(uid);
473
- if (typeof instance.handleEvent === 'function') {
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') {
474
481
  await instance.handleEvent(event);
475
482
  }
476
483
  const result = await renderPatches(uid, instance);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/api",
3
- "version": "8.55.0",
3
+ "version": "8.56.0",
4
4
  "description": "Tree-shakeable extension API for Lvce Editor extensions.",
5
5
  "keywords": [
6
6
  "lvce-editor",