You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

180 lines
7.3 KiB

2 weeks ago
  1. import type { ComponentDevtoolsOptions, ComponentInstance, ComponentTreeNode, InspectedComponentData } 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 interface 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. recursively: boolean;
  57. };
  58. [Hooks.VISIT_COMPONENT_TREE]: {
  59. app: App;
  60. componentInstance: ComponentInstance;
  61. treeNode: ComponentTreeNode;
  62. filter: string;
  63. };
  64. [Hooks.WALK_COMPONENT_PARENTS]: {
  65. componentInstance: ComponentInstance;
  66. parentInstances: ComponentInstance[];
  67. };
  68. [Hooks.INSPECT_COMPONENT]: {
  69. app: App;
  70. componentInstance: ComponentInstance;
  71. instanceData: InspectedComponentData;
  72. };
  73. [Hooks.GET_COMPONENT_BOUNDS]: {
  74. componentInstance: ComponentInstance;
  75. bounds: ComponentBounds;
  76. };
  77. [Hooks.GET_COMPONENT_NAME]: {
  78. componentInstance: ComponentInstance;
  79. name: string;
  80. };
  81. [Hooks.GET_COMPONENT_INSTANCES]: {
  82. app: App;
  83. componentInstances: ComponentInstance[];
  84. };
  85. [Hooks.GET_ELEMENT_COMPONENT]: {
  86. element: HTMLElement | any;
  87. componentInstance: ComponentInstance;
  88. };
  89. [Hooks.GET_COMPONENT_ROOT_ELEMENTS]: {
  90. componentInstance: ComponentInstance;
  91. rootElements: (HTMLElement | any)[];
  92. };
  93. [Hooks.EDIT_COMPONENT_STATE]: {
  94. app: App;
  95. componentInstance: ComponentInstance;
  96. path: string[];
  97. type: string;
  98. state: EditStatePayload;
  99. set: (object: any, path?: string | (string[]), value?: any, cb?: (object: any, field: string, value: any) => void) => void;
  100. };
  101. [Hooks.GET_COMPONENT_DEVTOOLS_OPTIONS]: {
  102. componentInstance: ComponentInstance;
  103. options: ComponentDevtoolsOptions;
  104. };
  105. [Hooks.GET_COMPONENT_RENDER_CODE]: {
  106. componentInstance: ComponentInstance;
  107. code: string;
  108. };
  109. [Hooks.INSPECT_TIMELINE_EVENT]: {
  110. app: App;
  111. layerId: string;
  112. event: TimelineEvent;
  113. all?: boolean;
  114. data: any;
  115. };
  116. [Hooks.TIMELINE_CLEARED]: Record<string, never>;
  117. [Hooks.GET_INSPECTOR_TREE]: {
  118. app: App;
  119. inspectorId: string;
  120. filter: string;
  121. rootNodes: CustomInspectorNode[];
  122. };
  123. [Hooks.GET_INSPECTOR_STATE]: {
  124. app: App;
  125. inspectorId: string;
  126. nodeId: string;
  127. state: CustomInspectorState;
  128. };
  129. [Hooks.EDIT_INSPECTOR_STATE]: {
  130. app: App;
  131. inspectorId: string;
  132. nodeId: string;
  133. path: string[];
  134. type: string;
  135. state: EditStatePayload;
  136. set: (object: any, path?: string | (string[]), value?: any, cb?: (object: any, field: string, value: any) => void) => void;
  137. };
  138. [Hooks.SET_PLUGIN_SETTINGS]: {
  139. app: App;
  140. pluginId: string;
  141. key: string;
  142. newValue: any;
  143. oldValue: any;
  144. settings: any;
  145. };
  146. }
  147. export type EditStatePayload = {
  148. value: any;
  149. newKey?: string | null;
  150. remove?: undefined | false;
  151. } | {
  152. value?: undefined;
  153. newKey?: undefined;
  154. remove: true;
  155. };
  156. export type HookHandler<TPayload, TContext> = (payload: TPayload, ctx: TContext) => void | Promise<void>;
  157. export interface Hookable<TContext> {
  158. transformCall: (handler: HookHandler<HookPayloads[Hooks.TRANSFORM_CALL], TContext>) => any;
  159. getAppRecordName: (handler: HookHandler<HookPayloads[Hooks.GET_APP_RECORD_NAME], TContext>) => any;
  160. getAppRootInstance: (handler: HookHandler<HookPayloads[Hooks.GET_APP_ROOT_INSTANCE], TContext>) => any;
  161. registerApplication: (handler: HookHandler<HookPayloads[Hooks.REGISTER_APPLICATION], TContext>) => any;
  162. walkComponentTree: (handler: HookHandler<HookPayloads[Hooks.WALK_COMPONENT_TREE], TContext>) => any;
  163. visitComponentTree: (handler: HookHandler<HookPayloads[Hooks.VISIT_COMPONENT_TREE], TContext>) => any;
  164. walkComponentParents: (handler: HookHandler<HookPayloads[Hooks.WALK_COMPONENT_PARENTS], TContext>) => any;
  165. inspectComponent: (handler: HookHandler<HookPayloads[Hooks.INSPECT_COMPONENT], TContext>) => any;
  166. getComponentBounds: (handler: HookHandler<HookPayloads[Hooks.GET_COMPONENT_BOUNDS], TContext>) => any;
  167. getComponentName: (handler: HookHandler<HookPayloads[Hooks.GET_COMPONENT_NAME], TContext>) => any;
  168. getComponentInstances: (handler: HookHandler<HookPayloads[Hooks.GET_COMPONENT_INSTANCES], TContext>) => any;
  169. getElementComponent: (handler: HookHandler<HookPayloads[Hooks.GET_ELEMENT_COMPONENT], TContext>) => any;
  170. getComponentRootElements: (handler: HookHandler<HookPayloads[Hooks.GET_COMPONENT_ROOT_ELEMENTS], TContext>) => any;
  171. editComponentState: (handler: HookHandler<HookPayloads[Hooks.EDIT_COMPONENT_STATE], TContext>) => any;
  172. getComponentDevtoolsOptions: (handler: HookHandler<HookPayloads[Hooks.GET_COMPONENT_DEVTOOLS_OPTIONS], TContext>) => any;
  173. getComponentRenderCode: (handler: HookHandler<HookPayloads[Hooks.GET_COMPONENT_RENDER_CODE], TContext>) => any;
  174. inspectTimelineEvent: (handler: HookHandler<HookPayloads[Hooks.INSPECT_TIMELINE_EVENT], TContext>) => any;
  175. timelineCleared: (handler: HookHandler<HookPayloads[Hooks.TIMELINE_CLEARED], TContext>) => any;
  176. getInspectorTree: (handler: HookHandler<HookPayloads[Hooks.GET_INSPECTOR_TREE], TContext>) => any;
  177. getInspectorState: (handler: HookHandler<HookPayloads[Hooks.GET_INSPECTOR_STATE], TContext>) => any;
  178. editInspectorState: (handler: HookHandler<HookPayloads[Hooks.EDIT_INSPECTOR_STATE], TContext>) => any;
  179. setPluginSettings: (handler: HookHandler<HookPayloads[Hooks.SET_PLUGIN_SETTINGS], TContext>) => any;
  180. }