index.d.ts 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. import * as _storybook_types from '@storybook/types';
  2. import { StrictArgTypes, Renderer, StoryContextForEnhancers, Options } from '@storybook/types';
  3. interface JsDocParam {
  4. name: string;
  5. description?: string;
  6. }
  7. interface JsDocReturns {
  8. description?: string;
  9. }
  10. interface JsDocTags {
  11. params?: JsDocParam[];
  12. returns?: JsDocReturns;
  13. }
  14. interface PropSummaryValue {
  15. summary: string;
  16. detail?: string;
  17. }
  18. type PropType = PropSummaryValue;
  19. type PropDefaultValue = PropSummaryValue;
  20. interface PropDef {
  21. name: string;
  22. type: PropType;
  23. sbType?: any;
  24. required: boolean;
  25. description?: string;
  26. defaultValue?: PropDefaultValue;
  27. jsDocTags?: JsDocTags;
  28. }
  29. type Component = any;
  30. type PropsExtractor = (component: Component) => {
  31. rows?: PropDef[];
  32. } | null;
  33. type ArgTypesExtractor = (component: Component) => StrictArgTypes | null;
  34. interface DocgenType {
  35. name: string;
  36. description?: string;
  37. required?: boolean;
  38. value?: any;
  39. }
  40. interface DocgenPropType extends DocgenType {
  41. value?: any;
  42. raw?: string;
  43. computed?: boolean;
  44. }
  45. interface DocgenFlowType extends DocgenType {
  46. type?: string;
  47. raw?: string;
  48. signature?: any;
  49. elements?: any[];
  50. }
  51. interface DocgenTypeScriptType extends DocgenType {
  52. raw?: string;
  53. }
  54. interface DocgenPropDefaultValue {
  55. value: string;
  56. computed?: boolean;
  57. func?: boolean;
  58. }
  59. interface DocgenInfo {
  60. type?: DocgenPropType;
  61. flowType?: DocgenFlowType;
  62. tsType?: DocgenTypeScriptType;
  63. required: boolean;
  64. description?: string;
  65. defaultValue?: DocgenPropDefaultValue;
  66. }
  67. declare enum TypeSystem {
  68. JAVASCRIPT = "JavaScript",
  69. FLOW = "Flow",
  70. TYPESCRIPT = "TypeScript",
  71. UNKNOWN = "Unknown"
  72. }
  73. declare const convert: (docgenInfo: DocgenInfo) => any;
  74. declare function isDefaultValueBlacklisted(value: string): boolean;
  75. declare const str: (obj: any) => string;
  76. declare function hasDocgen(component: Component): boolean;
  77. declare function isValidDocgenSection(docgenSection: any): boolean;
  78. declare function getDocgenSection(component: Component, section: string): any;
  79. declare function getDocgenDescription(component: Component): string;
  80. interface ExtractedJsDocParam {
  81. name: string;
  82. type?: any;
  83. description?: string;
  84. getPrettyName: () => string;
  85. getTypeName: () => string;
  86. }
  87. interface ExtractedJsDocReturns {
  88. type?: any;
  89. description?: string;
  90. getTypeName: () => string;
  91. }
  92. interface ExtractedJsDoc {
  93. params?: ExtractedJsDocParam[];
  94. deprecated?: string;
  95. returns?: ExtractedJsDocReturns;
  96. ignore: boolean;
  97. }
  98. interface JsDocParsingOptions {
  99. tags?: string[];
  100. }
  101. interface JsDocParsingResult {
  102. includesJsDoc: boolean;
  103. ignore: boolean;
  104. description?: string;
  105. extractedTags?: ExtractedJsDoc;
  106. }
  107. type ParseJsDoc = (value?: string, options?: JsDocParsingOptions) => JsDocParsingResult;
  108. declare const parseJsDoc: ParseJsDoc;
  109. interface ExtractedProp {
  110. propDef: PropDef;
  111. docgenInfo: DocgenInfo;
  112. jsDocTags: ExtractedJsDoc;
  113. typeSystem: TypeSystem;
  114. }
  115. type ExtractProps = (component: Component, section: string) => ExtractedProp[];
  116. declare const extractComponentSectionArray: (docgenSection: any) => any;
  117. declare const extractComponentSectionObject: (docgenSection: any) => ExtractedProp[];
  118. declare const extractComponentProps: ExtractProps;
  119. declare function extractComponentDescription(component?: Component): string;
  120. declare const MAX_TYPE_SUMMARY_LENGTH = 90;
  121. declare const MAX_DEFAULT_VALUE_SUMMARY_LENGTH = 50;
  122. declare function isTooLongForTypeSummary(value: string): boolean;
  123. declare function isTooLongForDefaultValueSummary(value: string): boolean;
  124. declare function createSummaryValue(summary: string, detail?: string): PropSummaryValue;
  125. declare const normalizeNewlines: (string: string) => string;
  126. declare const enhanceArgTypes: <TRenderer extends Renderer>(context: StoryContextForEnhancers<TRenderer, _storybook_types.Args>) => _storybook_types.StrictArgTypes<_storybook_types.Args>;
  127. declare const ADDON_ID = "storybook/docs";
  128. declare const PANEL_ID = "storybook/docs/panel";
  129. declare const PARAM_KEY = "docs";
  130. declare const SNIPPET_RENDERED = "storybook/docs/snippet-rendered";
  131. declare enum SourceType {
  132. /**
  133. * AUTO is the default
  134. *
  135. * Use the CODE logic if:
  136. * - the user has set a custom source snippet in `docs.source.code` story parameter
  137. * - the story is not an args-based story
  138. *
  139. * Use the DYNAMIC rendered snippet if the story is an args story
  140. */
  141. AUTO = "auto",
  142. /**
  143. * Render the code extracted by source-loader
  144. */
  145. CODE = "code",
  146. /**
  147. * Render dynamically-rendered source snippet from the story's virtual DOM (currently React only)
  148. */
  149. DYNAMIC = "dynamic"
  150. }
  151. declare const hasDocsOrControls: (options: Options) => boolean;
  152. export { ADDON_ID, ArgTypesExtractor, Component, DocgenFlowType, DocgenInfo, DocgenPropDefaultValue, DocgenPropType, DocgenType, DocgenTypeScriptType, ExtractProps, ExtractedJsDoc, ExtractedJsDocParam, ExtractedJsDocReturns, ExtractedProp, JsDocParam, JsDocParsingOptions, JsDocParsingResult, JsDocReturns, JsDocTags, MAX_DEFAULT_VALUE_SUMMARY_LENGTH, MAX_TYPE_SUMMARY_LENGTH, PANEL_ID, PARAM_KEY, ParseJsDoc, PropDef, PropDefaultValue, PropSummaryValue, PropType, PropsExtractor, SNIPPET_RENDERED, SourceType, TypeSystem, convert, createSummaryValue, enhanceArgTypes, extractComponentDescription, extractComponentProps, extractComponentSectionArray, extractComponentSectionObject, getDocgenDescription, getDocgenSection, hasDocgen, hasDocsOrControls, isDefaultValueBlacklisted, isTooLongForDefaultValueSummary, isTooLongForTypeSummary, isValidDocgenSection, normalizeNewlines, parseJsDoc, str };