@poveste/shared 0.19.1 → 0.20.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.
@@ -1,6 +1,7 @@
1
1
  import type { MarkdownIt } from 'markdown-it';
2
2
  import type { UseHeadInput } from 'unhead/types';
3
3
  import type { UserConfig as ViteConfig, ConfigEnv as ViteConfigEnv } from 'vite';
4
+ import type { AutoDocsOptions } from './docgen.js';
4
5
  import type { Plugin } from './plugin.js';
5
6
  import type { ServerTreeFile, StoryProps } from './story.js';
6
7
  export interface SupportMatchPattern {
@@ -89,6 +90,13 @@ export interface PovesteConfig {
89
90
  * in iframes. Set to false to restore pre-1.0 behavior. See guide/css.md.
90
91
  */
91
92
  isolateStyles?: boolean;
93
+ /**
94
+ * Auto-docs: a props, slots and events table read from each component's types.
95
+ * Extraction starts the first time a reader opens a story's docs, in a worker,
96
+ * and only for the components that story imports; it holds a type checker while
97
+ * it runs. Set to false to turn it off. Default: on.
98
+ */
99
+ autoDocs?: boolean | AutoDocsOptions;
92
100
  /**
93
101
  * CSS files loaded into the main app (not into stories). Wrapped in
94
102
  * @layer poveste-user-globals — lower priority than chrome.
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Auto-docs: what a framework extractor reads off a component, and the contract
3
+ * between it and the shell that decides when it runs (#159, #1159).
4
+ */
5
+ export interface DocTag {
6
+ name: string;
7
+ text?: string;
8
+ }
9
+ export interface DocProp {
10
+ name: string;
11
+ description?: string;
12
+ type: string;
13
+ required: boolean;
14
+ /** The default the code applies, which wins over the tag when both exist. */
15
+ default?: string;
16
+ /** The default a `@default` or `@defaultValue` tag states. */
17
+ defaultTag?: string;
18
+ /** Both defaults exist and say different things: the code's is shown, and this flags it. */
19
+ defaultConflict?: boolean;
20
+ tags: DocTag[];
21
+ }
22
+ export interface DocSlot {
23
+ name: string;
24
+ description?: string;
25
+ type?: string;
26
+ tags: DocTag[];
27
+ }
28
+ export interface DocEvent {
29
+ name: string;
30
+ description?: string;
31
+ type?: string;
32
+ tags: DocTag[];
33
+ }
34
+ export interface ComponentDoc {
35
+ props: DocProp[];
36
+ slots: DocSlot[];
37
+ events: DocEvent[];
38
+ }
39
+ /**
40
+ * One framework's extractor, created inside the docgen worker the first time a
41
+ * component of its kind is asked for. It may hold a type checker, which is the
42
+ * memory this whole design is about: `dispose` must let it go.
43
+ */
44
+ export interface DocgenExtractor {
45
+ extract: (file: string) => ComponentDoc | undefined | Promise<ComponentDoc | undefined>;
46
+ /** A file changed on disk. Called for any file, not only components. */
47
+ update?: (file: string) => void | Promise<void>;
48
+ /**
49
+ * The files its program read, outside `node_modules`. The dev server watches
50
+ * them: a types file the browser never loads, or one outside the book's root,
51
+ * is otherwise never seen to change (#1190).
52
+ */
53
+ sources?: () => string[] | Promise<string[]>;
54
+ dispose: () => void | Promise<void>;
55
+ }
56
+ export interface DocgenExtractorContext {
57
+ /** The book's root. */
58
+ root: string;
59
+ /** Whatever the plugin passed as `docgen.options`. */
60
+ options: unknown;
61
+ }
62
+ /** The shape of the module a plugin names in `docgen.module`. */
63
+ export interface DocgenExtractorModule {
64
+ createExtractor: (context: DocgenExtractorContext) => DocgenExtractor | Promise<DocgenExtractor>;
65
+ }
66
+ export interface PluginDocgen {
67
+ /** Whether a resolved file is a component this plugin documents. */
68
+ match: (file: string) => boolean;
69
+ /**
70
+ * An absolute path or `file:` URL to a module exporting `createExtractor`. It is
71
+ * imported in a worker thread, so it travels as a specifier rather than a function.
72
+ */
73
+ module: string;
74
+ /** Passed to `createExtractor`; it has to survive a structured clone. */
75
+ options?: unknown;
76
+ /**
77
+ * Why this plugin cannot document the book at `root`, or nothing when it can.
78
+ * With a reason, auto-docs is off for this plugin and the reason is logged once,
79
+ * in place of an error under every component (#1382).
80
+ */
81
+ unavailable?: (root: string) => string | undefined;
82
+ }
83
+ /** `autoDocs` in the config, when it is more than on or off. */
84
+ export interface AutoDocsOptions {
85
+ /**
86
+ * Packages whose props are documented although they are declared under
87
+ * `node_modules`: a design system a library builds on, such as `reka-ui`.
88
+ */
89
+ allow?: string[];
90
+ /** Component files to leave out, matched as substrings of the path. */
91
+ exclude?: string[];
92
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Auto-docs: what a framework extractor reads off a component, and the contract
3
+ * between it and the shell that decides when it runs (#159, #1159).
4
+ */
5
+ export {};
@@ -1,5 +1,6 @@
1
1
  export * from './command.js';
2
2
  export * from './config.js';
3
+ export * from './docgen.js';
3
4
  export * from './plugin.js';
4
5
  export * from './prompt.js';
5
6
  export * from './story.js';
@@ -1,5 +1,6 @@
1
1
  export * from './command.js';
2
2
  export * from './config.js';
3
+ export * from './docgen.js';
3
4
  export * from './plugin.js';
4
5
  export * from './prompt.js';
5
6
  export * from './story.js';
@@ -6,6 +6,7 @@ import type { InlineConfig as ViteInlineConfig, Plugin as VitePlugin } from 'vit
6
6
  import type { Awaitable } from '../type-utils.js';
7
7
  import type { PluginCommand } from './command.js';
8
8
  import type { ConfigMode, PovesteConfig } from './config.js';
9
+ import type { PluginDocgen } from './docgen.js';
9
10
  import type { ServerStory, ServerStoryFile, ServerVariant, Variant } from './story.js';
10
11
  /**
11
12
  * A framework's collection strategy: how a story file written for that framework
@@ -233,6 +234,11 @@ export interface Plugin {
233
234
  * Handle a custom event from the client in development mode.
234
235
  */
235
236
  onDevEvent?: (api: PluginApiDevEvent) => Awaitable<any>;
237
+ /**
238
+ * Auto-docs for this framework's components: which files it documents, and the
239
+ * module that extracts them, run lazily in a worker (#1159).
240
+ */
241
+ docgen?: PluginDocgen;
236
242
  /**
237
243
  * Use this hook to manipulate Vite plugins before they are passed to Vite.
238
244
  */
@@ -67,7 +67,12 @@ export interface Story {
67
67
  docsOnly?: boolean;
68
68
  file?: StoryFile;
69
69
  lastSelectedVariant?: Variant;
70
- slots?: () => any;
70
+ /** The story's own slots. Any of the three can be absent: a story may define none. */
71
+ slots?: () => {
72
+ default?: any;
73
+ controls?: any;
74
+ source?: any;
75
+ };
71
76
  meta?: StoryMeta;
72
77
  }
73
78
  export interface VariantMeta extends CommonMeta {
@@ -78,10 +83,11 @@ export interface Variant {
78
83
  icon?: string | undefined;
79
84
  iconColor?: string | undefined;
80
85
  setupApp?: ((payload: any) => unknown) | undefined;
86
+ /** The variant's own slots. Any of the three can be absent: a variant may define none. */
81
87
  slots?: (() => {
82
- default: any;
83
- controls: any;
84
- source: any;
88
+ default?: any;
89
+ controls?: any;
90
+ source?: any;
85
91
  }) | undefined;
86
92
  state: any;
87
93
  source?: string | undefined;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@poveste/shared",
3
3
  "type": "module",
4
- "version": "0.19.1",
4
+ "version": "0.20.0",
5
5
  "description": "Shared utilities for Poveste",
6
6
  "author": {
7
7
  "name": "Sorin Gitlan",
@@ -39,20 +39,20 @@
39
39
  "vite": "^8.0.0"
40
40
  },
41
41
  "dependencies": {
42
- "@poveste/vendors": "^0.19.1",
42
+ "@poveste/vendors": "^0.20.0",
43
43
  "@types/fs-extra": "^11.0.4",
44
44
  "chokidar": "^5.0.0",
45
- "markdown-it": "^15.0.2",
45
+ "markdown-it": "^15.0.3",
46
46
  "pathe": "^2.0.3",
47
47
  "picocolors": "^1.1.1",
48
- "unhead": "^3.4.1"
48
+ "unhead": "^3.4.3"
49
49
  },
50
50
  "devDependencies": {
51
- "@types/node": "^26.6.3",
51
+ "@types/node": "^26.6.5",
52
52
  "typescript": "6.0.3",
53
- "vite": "^8.3.1",
54
- "vitest": "^5.0.2",
55
- "vue-router": "^5.3.1"
53
+ "vite": "^8.3.4",
54
+ "vitest": "^5.0.4",
55
+ "vue-router": "^5.4.0"
56
56
  },
57
57
  "scripts": {
58
58
  "build": "rimraf dist && tsc",