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.

47 lines
1.3 KiB

4 months ago
  1. import type { App } from './api/index.js';
  2. export interface PluginDescriptor {
  3. id: string;
  4. label: string;
  5. app: App;
  6. packageName?: string;
  7. homepage?: string;
  8. componentStateTypes?: string[];
  9. logo?: string;
  10. disableAppScope?: boolean;
  11. disablePluginScope?: boolean;
  12. /**
  13. * Run the plugin setup and expose the api even if the devtools is not opened yet.
  14. * Useful to record timeline events early.
  15. */
  16. enableEarlyProxy?: boolean;
  17. settings?: Record<string, PluginSettingsItem>;
  18. }
  19. export type PluginSettingsItem = {
  20. label: string;
  21. description?: string;
  22. } & ({
  23. type: 'boolean';
  24. defaultValue: boolean;
  25. } | {
  26. type: 'choice';
  27. defaultValue: string | number;
  28. options: {
  29. value: string | number;
  30. label: string;
  31. }[];
  32. component?: 'select' | 'button-group';
  33. } | {
  34. type: 'text';
  35. defaultValue: string;
  36. });
  37. type InferSettingsType<T extends PluginSettingsItem> = [T] extends [{
  38. type: 'boolean';
  39. }] ? boolean : [T] extends [{
  40. type: 'choice';
  41. }] ? T['options'][number]['value'] : [T] extends [{
  42. type: 'text';
  43. }] ? string : unknown;
  44. export type ExtractSettingsTypes<O extends Record<string, PluginSettingsItem>> = {
  45. [K in keyof O]: InferSettingsType<O[K]>;
  46. };
  47. export {};