hooks.d.ts 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. import type { ComponentTreeNode, InspectedComponentData, ComponentInstance, ComponentDevtoolsOptions } from './component.js';
  2. import type { App } from './app.js';
  3. import type { CustomInspectorNode, CustomInspectorState, TimelineEvent } from './api.js';
  4. export declare const enum Hooks {
  5. TRANSFORM_CALL = "transformCall",
  6. GET_APP_RECORD_NAME = "getAppRecordName",
  7. GET_APP_ROOT_INSTANCE = "getAppRootInstance",
  8. REGISTER_APPLICATION = "registerApplication",
  9. WALK_COMPONENT_TREE = "walkComponentTree",
  10. VISIT_COMPONENT_TREE = "visitComponentTree",
  11. WALK_COMPONENT_PARENTS = "walkComponentParents",
  12. INSPECT_COMPONENT = "inspectComponent",
  13. GET_COMPONENT_BOUNDS = "getComponentBounds",
  14. GET_COMPONENT_NAME = "getComponentName",
  15. GET_COMPONENT_INSTANCES = "getComponentInstances",
  16. GET_ELEMENT_COMPONENT = "getElementComponent",
  17. GET_COMPONENT_ROOT_ELEMENTS = "getComponentRootElements",
  18. EDIT_COMPONENT_STATE = "editComponentState",
  19. GET_COMPONENT_DEVTOOLS_OPTIONS = "getAppDevtoolsOptions",
  20. GET_COMPONENT_RENDER_CODE = "getComponentRenderCode",
  21. INSPECT_TIMELINE_EVENT = "inspectTimelineEvent",
  22. TIMELINE_CLEARED = "timelineCleared",
  23. GET_INSPECTOR_TREE = "getInspectorTree",
  24. GET_INSPECTOR_STATE = "getInspectorState",
  25. EDIT_INSPECTOR_STATE = "editInspectorState",
  26. SET_PLUGIN_SETTINGS = "setPluginSettings"
  27. }
  28. export interface ComponentBounds {
  29. left: number;
  30. top: number;
  31. width: number;
  32. height: number;
  33. }
  34. export declare type HookPayloads = {
  35. [Hooks.TRANSFORM_CALL]: {
  36. callName: string;
  37. inArgs: any[];
  38. outArgs: any[];
  39. };
  40. [Hooks.GET_APP_RECORD_NAME]: {
  41. app: App;
  42. name: string;
  43. };
  44. [Hooks.GET_APP_ROOT_INSTANCE]: {
  45. app: App;
  46. root: ComponentInstance;
  47. };
  48. [Hooks.REGISTER_APPLICATION]: {
  49. app: App;
  50. };
  51. [Hooks.WALK_COMPONENT_TREE]: {
  52. componentInstance: ComponentInstance;
  53. componentTreeData: ComponentTreeNode[];
  54. maxDepth: number;
  55. filter: string;
  56. };
  57. [Hooks.VISIT_COMPONENT_TREE]: {
  58. app: App;
  59. componentInstance: ComponentInstance;
  60. treeNode: ComponentTreeNode;
  61. filter: string;
  62. };
  63. [Hooks.WALK_COMPONENT_PARENTS]: {
  64. componentInstance: ComponentInstance;
  65. parentInstances: ComponentInstance[];
  66. };
  67. [Hooks.INSPECT_COMPONENT]: {
  68. app: App;
  69. componentInstance: ComponentInstance;
  70. instanceData: InspectedComponentData;
  71. };
  72. [Hooks.GET_COMPONENT_BOUNDS]: {
  73. componentInstance: ComponentInstance;
  74. bounds: ComponentBounds;
  75. };
  76. [Hooks.GET_COMPONENT_NAME]: {
  77. componentInstance: ComponentInstance;
  78. name: string;
  79. };
  80. [Hooks.GET_COMPONENT_INSTANCES]: {
  81. app: App;
  82. componentInstances: ComponentInstance[];
  83. };
  84. [Hooks.GET_ELEMENT_COMPONENT]: {
  85. element: HTMLElement | any;
  86. componentInstance: ComponentInstance;
  87. };
  88. [Hooks.GET_COMPONENT_ROOT_ELEMENTS]: {
  89. componentInstance: ComponentInstance;
  90. rootElements: (HTMLElement | any)[];
  91. };
  92. [Hooks.EDIT_COMPONENT_STATE]: {
  93. app: App;
  94. componentInstance: ComponentInstance;
  95. path: string[];
  96. type: string;
  97. state: EditStatePayload;
  98. set: (object: any, path?: string | (string[]), value?: any, cb?: (object: any, field: string, value: any) => void) => void;
  99. };
  100. [Hooks.GET_COMPONENT_DEVTOOLS_OPTIONS]: {
  101. componentInstance: ComponentInstance;
  102. options: ComponentDevtoolsOptions;
  103. };
  104. [Hooks.GET_COMPONENT_RENDER_CODE]: {
  105. componentInstance: ComponentInstance;
  106. code: string;
  107. };
  108. [Hooks.INSPECT_TIMELINE_EVENT]: {
  109. app: App;
  110. layerId: string;
  111. event: TimelineEvent;
  112. all?: boolean;
  113. data: any;
  114. };
  115. [Hooks.TIMELINE_CLEARED]: Record<string, never>;
  116. [Hooks.GET_INSPECTOR_TREE]: {
  117. app: App;
  118. inspectorId: string;
  119. filter: string;
  120. rootNodes: CustomInspectorNode[];
  121. };
  122. [Hooks.GET_INSPECTOR_STATE]: {
  123. app: App;
  124. inspectorId: string;
  125. nodeId: string;
  126. state: CustomInspectorState;
  127. };
  128. [Hooks.EDIT_INSPECTOR_STATE]: {
  129. app: App;
  130. inspectorId: string;
  131. nodeId: string;
  132. path: string[];
  133. type: string;
  134. state: EditStatePayload;
  135. set: (object: any, path?: string | (string[]), value?: any, cb?: (object: any, field: string, value: any) => void) => void;
  136. };
  137. [Hooks.SET_PLUGIN_SETTINGS]: {
  138. app: App;
  139. pluginId: string;
  140. key: string;
  141. newValue: any;
  142. oldValue: any;
  143. settings: any;
  144. };
  145. };
  146. export declare type EditStatePayload = {
  147. value: any;
  148. newKey?: string | null;
  149. remove?: undefined | false;
  150. } | {
  151. value?: undefined;
  152. newKey?: undefined;
  153. remove: true;
  154. };
  155. export declare type HookHandler<TPayload, TContext> = (payload: TPayload, ctx: TContext) => void | Promise<void>;
  156. export interface Hookable<TContext> {
  157. transformCall(handler: HookHandler<HookPayloads[Hooks.TRANSFORM_CALL], TContext>): any;
  158. getAppRecordName(handler: HookHandler<HookPayloads[Hooks.GET_APP_RECORD_NAME], TContext>): any;
  159. getAppRootInstance(handler: HookHandler<HookPayloads[Hooks.GET_APP_ROOT_INSTANCE], TContext>): any;
  160. registerApplication(handler: HookHandler<HookPayloads[Hooks.REGISTER_APPLICATION], TContext>): any;
  161. walkComponentTree(handler: HookHandler<HookPayloads[Hooks.WALK_COMPONENT_TREE], TContext>): any;
  162. visitComponentTree(handler: HookHandler<HookPayloads[Hooks.VISIT_COMPONENT_TREE], TContext>): any;
  163. walkComponentParents(handler: HookHandler<HookPayloads[Hooks.WALK_COMPONENT_PARENTS], TContext>): any;
  164. inspectComponent(handler: HookHandler<HookPayloads[Hooks.INSPECT_COMPONENT], TContext>): any;
  165. getComponentBounds(handler: HookHandler<HookPayloads[Hooks.GET_COMPONENT_BOUNDS], TContext>): any;
  166. getComponentName(handler: HookHandler<HookPayloads[Hooks.GET_COMPONENT_NAME], TContext>): any;
  167. getComponentInstances(handler: HookHandler<HookPayloads[Hooks.GET_COMPONENT_INSTANCES], TContext>): any;
  168. getElementComponent(handler: HookHandler<HookPayloads[Hooks.GET_ELEMENT_COMPONENT], TContext>): any;
  169. getComponentRootElements(handler: HookHandler<HookPayloads[Hooks.GET_COMPONENT_ROOT_ELEMENTS], TContext>): any;
  170. editComponentState(handler: HookHandler<HookPayloads[Hooks.EDIT_COMPONENT_STATE], TContext>): any;
  171. getComponentDevtoolsOptions(handler: HookHandler<HookPayloads[Hooks.GET_COMPONENT_DEVTOOLS_OPTIONS], TContext>): any;
  172. getComponentRenderCode(handler: HookHandler<HookPayloads[Hooks.GET_COMPONENT_RENDER_CODE], TContext>): any;
  173. inspectTimelineEvent(handler: HookHandler<HookPayloads[Hooks.INSPECT_TIMELINE_EVENT], TContext>): any;
  174. timelineCleared(handler: HookHandler<HookPayloads[Hooks.TIMELINE_CLEARED], TContext>): any;
  175. getInspectorTree(handler: HookHandler<HookPayloads[Hooks.GET_INSPECTOR_TREE], TContext>): any;
  176. getInspectorState(handler: HookHandler<HookPayloads[Hooks.GET_INSPECTOR_STATE], TContext>): any;
  177. editInspectorState(handler: HookHandler<HookPayloads[Hooks.EDIT_INSPECTOR_STATE], TContext>): any;
  178. setPluginSettings(handler: HookHandler<HookPayloads[Hooks.SET_PLUGIN_SETTINGS], TContext>): any;
  179. }