@poveste/shared 0.6.1 → 0.7.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.
Files changed (49) hide show
  1. package/dist/codegen/const.d.ts +0 -1
  2. package/dist/codegen/index.d.ts +0 -1
  3. package/dist/codegen/serialize-js.d.ts +0 -1
  4. package/dist/codegen/util.d.ts +0 -1
  5. package/dist/index.d.ts +0 -1
  6. package/dist/setup.d.ts +0 -1
  7. package/dist/state.d.ts +0 -1
  8. package/dist/story.d.ts +0 -1
  9. package/dist/type-utils.d.ts +0 -1
  10. package/dist/types/command.d.ts +0 -1
  11. package/dist/types/config.d.ts +0 -1
  12. package/dist/types/index.d.ts +0 -1
  13. package/dist/types/plugin.d.ts +0 -1
  14. package/dist/types/prompt.d.ts +0 -1
  15. package/dist/types/story.d.ts +0 -1
  16. package/package.json +14 -4
  17. package/dist/codegen/const.d.ts.map +0 -1
  18. package/dist/codegen/index.d.ts.map +0 -1
  19. package/dist/codegen/serialize-js.d.ts.map +0 -1
  20. package/dist/codegen/util.d.ts.map +0 -1
  21. package/dist/index.d.ts.map +0 -1
  22. package/dist/setup.d.ts.map +0 -1
  23. package/dist/state.d.ts.map +0 -1
  24. package/dist/story.d.ts.map +0 -1
  25. package/dist/type-utils.d.ts.map +0 -1
  26. package/dist/types/command.d.ts.map +0 -1
  27. package/dist/types/config.d.ts.map +0 -1
  28. package/dist/types/index.d.ts.map +0 -1
  29. package/dist/types/plugin.d.ts.map +0 -1
  30. package/dist/types/prompt.d.ts.map +0 -1
  31. package/dist/types/story.d.ts.map +0 -1
  32. package/src/__tests__/setup.spec.ts +0 -60
  33. package/src/__tests__/state.spec.ts +0 -353
  34. package/src/codegen/const.ts +0 -17
  35. package/src/codegen/index.ts +0 -3
  36. package/src/codegen/serialize-js.ts +0 -143
  37. package/src/codegen/util.ts +0 -77
  38. package/src/index.ts +0 -6
  39. package/src/setup.ts +0 -29
  40. package/src/state.ts +0 -374
  41. package/src/story.ts +0 -10
  42. package/src/type-utils.ts +0 -1
  43. package/src/types/command.ts +0 -38
  44. package/src/types/config.ts +0 -288
  45. package/src/types/index.ts +0 -5
  46. package/src/types/plugin.ts +0 -135
  47. package/src/types/prompt.ts +0 -25
  48. package/src/types/story.ts +0 -221
  49. package/tsconfig.json +0 -51
@@ -1,288 +0,0 @@
1
- import type MarkdownIt from 'markdown-it'
2
- import type { UseHeadInput } from 'unhead/types'
3
- import type {
4
- UserConfig as ViteConfig,
5
- ConfigEnv as ViteConfigEnv,
6
- } from 'vite'
7
- import type { Plugin } from './plugin.js'
8
- import type { ServerTreeFile, StoryProps } from './story.js'
9
-
10
- export interface SupportMatchPattern {
11
- id: string
12
- patterns: string[]
13
- pluginIds: string[]
14
- }
15
-
16
- export type CustomizableColors = 'primary' | 'gray'
17
- export type ColorKeys = '50' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900'
18
- export type GrayColorKeys = ColorKeys | '750' | '850' | '950'
19
-
20
- export interface ResponsivePreset {
21
- label: string
22
- width: number
23
- height?: number
24
- }
25
-
26
- export interface BackgroundPreset {
27
- label: string
28
- color: string
29
- contrastColor?: string
30
- }
31
-
32
- export interface TreeGroupConfig {
33
- title: string
34
- id?: string
35
- include?: (file: ServerTreeFile) => boolean
36
- }
37
-
38
- /**
39
- * @deprecated Use `PovesteConfig` instead. Kept for drop-in compat with histoire.
40
- */
41
- export type HistoireConfig = PovesteConfig
42
-
43
- export interface PovesteConfig {
44
- plugins: Plugin[]
45
- /**
46
- * Output directory.
47
- */
48
- outDir: string
49
- /**
50
- * Glob patterns for story files to include.
51
- */
52
- storyMatch: string[]
53
- /**
54
- * Glob patterns to ignore files while searching for story files.
55
- * Added to the defaults (`node_modules`, `dist`), not a replacement for them.
56
- */
57
- storyIgnored: string[]
58
- /**
59
- * Patterns to match stories to support plugins automatically.
60
- */
61
- supportMatch: SupportMatchPattern[]
62
- /**
63
- * Master switch for CSS isolation between Poveste chrome and user stories.
64
- * When true (default), user CSS imported via poveste.setup is scoped to story
65
- * containers, chrome CSS is scoped away from them, and grid items render
66
- * in iframes. Set to false to restore pre-1.0 behavior. See guide/css.md.
67
- */
68
- isolateStyles?: boolean
69
- /**
70
- * CSS files loaded into the main app (not into stories). Wrapped in
71
- * @layer poveste-user-globals — lower priority than chrome.
72
- * Use for design tokens or anything intentionally global.
73
- */
74
- globalStyles?: string[]
75
- /**
76
- * How to generate the story tree.
77
- */
78
- tree: {
79
- /**
80
- * Use `'title'` to create the path from the title of the story, using `/` as the separator.
81
- *
82
- * Use `'path'` use the real folder structure on your computer.
83
- */
84
- file?: 'title' | 'path' | ((file: ServerTreeFile) => string[])
85
- order?: 'asc' | ((a: string, b: string) => number)
86
- groups?: TreeGroupConfig[]
87
- }
88
- /**
89
- * Customize the look of the histoire book.
90
- */
91
- theme: {
92
- /**
93
- * Main page title. For example: 'Acme Inc.'
94
- */
95
- title?: string
96
- /**
97
- * Custom logo files. Should be import paths (processed by Vite).
98
- *
99
- * Example: `'/src/assets/my-logo.svg'`
100
- */
101
- logo?: {
102
- /**
103
- * Square logo without text.
104
- */
105
- square?: string
106
- /**
107
- * Full logo for light theme.
108
- */
109
- light?: string
110
- /**
111
- * Full logo for dark theme.
112
- */
113
- dark?: string
114
- }
115
- /**
116
- * Href to the favicon file (**not** processed by Vite). Put the file in the `public` directory.
117
- *
118
- * Example: `'/favicon.ico'`
119
- */
120
- favicon?: string
121
- /**
122
- * Customize the colors. Each color should be an object with shades as keys.
123
- *
124
- * Example: ```{ primary: { 50: '#eef2ff', 100: '#e0e7ff', ..., 900: '#312e81' } }```
125
- *
126
- * You can import `defaultColors` from `'poveste'` to use predefined colors or you can create your own colors from scratch.
127
- */
128
- colors?: {
129
- [key in CustomizableColors]?: key extends 'gray' ? {
130
- [key in GrayColorKeys]?: string
131
- } : {
132
- [key in ColorKeys]?: string
133
- }
134
- }
135
- /**
136
- * Add a link to the main logo
137
- */
138
- logoHref?: string
139
- /**
140
- * Default color scheme for the app.
141
- */
142
- defaultColorScheme?: 'light' | 'dark' | 'auto'
143
- /**
144
- * Hides the dark mode button in the toolbar.
145
- */
146
- hideColorSchemeSwitch?: boolean
147
- /**
148
- * Enable persistence of the color scheme in the browser.
149
- */
150
- storeColorScheme?: boolean
151
- /**
152
- * Class added to the story preview when dark mode is enabled.
153
- */
154
- darkClass?: string
155
- }
156
- /**
157
- * Setup file exporting a default function executed when setting up each story preview.
158
- *
159
- * Import custom CSS files from this file.
160
- *
161
- * Example: `'/src/poveste-setup.ts'`
162
- */
163
- setupFile?: string | {
164
- /**
165
- * Only loaded in the browser client.
166
- */
167
- browser: string
168
- } | {
169
- /**
170
- * Only loaded while collecting stories in the node server.
171
- */
172
- server: string
173
- } | {
174
- /**
175
- * Only loaded in the browser client.
176
- */
177
- browser: string
178
- /**
179
- * Only loaded while collecting stories in the node server.
180
- */
181
- server: string
182
- }
183
- /**
184
- * Setup code created by plugins
185
- */
186
- setupCode?: string[]
187
- /**
188
- * Predefined responsive sizes for story playgrounds.
189
- */
190
- responsivePresets?: ResponsivePreset[]
191
- /**
192
- * Background color of the story preview.
193
- */
194
- backgroundPresets?: BackgroundPreset[]
195
- /**
196
- * Initial background color used for story previews before the user picks one.
197
- *
198
- * Should match a `color` from `backgroundPresets` to also highlight the corresponding
199
- * entry in the dropdown; any other value is still applied as a CSS color.
200
- *
201
- * @default 'transparent'
202
- */
203
- defaultBackgroundColor?: string
204
- /**
205
- * Automatically apply the current background preset's contrast color to the story preview text.
206
- */
207
- autoApplyContrastColor?: boolean
208
- /**
209
- * Extra `<head>` tags injected into the Poveste app and the story sandbox.
210
- * Same input shape as Nuxt's `useHead`. Use for global stylesheets, web fonts,
211
- * analytics snippets, or any meta tag that needs to apply in both contexts.
212
- *
213
- * Example: `head: { link: [{ rel: 'stylesheet', href: '...' }] }`
214
- */
215
- head?: UseHeadInput
216
- /**
217
- * Class added to the html root of the story preview when dark mode is enabled.
218
- *
219
- * Applied only when you set it. It has no default, so a book that configures
220
- * `theme.darkClass` alone gets that one class on every render path rather
221
- * than a second, different one (#126).
222
- * @deprecated use `theme.darkClass` instead
223
- */
224
- sandboxDarkClass?: string
225
- /**
226
- * Default props for stories.
227
- */
228
- defaultStoryProps?: Omit<StoryProps, 'id' | 'setupApp' | 'title' | 'source'>
229
- /**
230
- * Customize the markdown-it renderer
231
- */
232
- markdown?: (md: MarkdownIt) => MarkdownIt | Promise<MarkdownIt>
233
- /**
234
- * Change the router mode.
235
- * - history: use HTML history with cleaner URLs
236
- * - hash: use hashtag hack in the URL to support more hosting services
237
- */
238
- routerMode?: 'history' | 'hash'
239
- /**
240
- * Vite config override
241
- */
242
- vite?: ViteConfig | ((config: ViteConfig, env: ViteConfigEnv) => void | ViteConfig | Promise<void | ViteConfig>)
243
- /**
244
- * Remove those plugins from the Vite configuration
245
- */
246
- viteIgnorePlugins?: string[]
247
- /**
248
- * Transpile dependencies when collecting stories on Node.js
249
- */
250
- viteNodeInlineDeps?: (string | RegExp)[]
251
- /**
252
- * Determine the transform method of modules
253
- */
254
- viteNodeTransformMode?: {
255
- /**
256
- * Use SSR transform pipeline for the specified files.
257
- * Vite plugins will receive `ssr: true` flag when processing those files.
258
- *
259
- * @default [/\.([cm]?[jt]sx?|json)$/]
260
- */
261
- ssr?: RegExp[]
262
- /**
263
- * First do a normal transform pipeline (targeting browser),
264
- * then then do a SSR rewrite to run the code in Node.
265
- * Vite plugins will receive `ssr: false` flag when processing those files.
266
- *
267
- * @default other than `ssr`
268
- */
269
- web?: RegExp[]
270
- }
271
- /**
272
- * Maximum number of threads used to collect stories.
273
- * By default based on available number of cores.
274
- */
275
- collectMaxThreads?: number
276
- /**
277
- * Build options
278
- */
279
- build?: {
280
- /**
281
- * By default all dependencies in `node_modules` are bundled into a single 'vendors' file.
282
- * You can use this option to exclude some dependencies from this file.
283
- */
284
- excludeFromVendorsChunk?: (string | RegExp)[]
285
- }
286
- }
287
-
288
- export type ConfigMode = 'build' | 'dev'
@@ -1,5 +0,0 @@
1
- export * from './command.js'
2
- export * from './config.js'
3
- export * from './plugin.js'
4
- export * from './prompt.js'
5
- export * from './story.js'
@@ -1,135 +0,0 @@
1
- import type chokidar from 'chokidar'
2
- import type fs from 'fs-extra'
3
- import type path from 'pathe'
4
- import type pc from 'picocolors'
5
- import type { InlineConfig as ViteInlineConfig, Plugin as VitePlugin } from 'vite'
6
- import type { Awaitable } from '../type-utils.js'
7
- import type {
8
- PluginCommand,
9
- } from './command.js'
10
- import type {
11
- ConfigMode,
12
- PovesteConfig,
13
- } from './config.js'
14
- import type {
15
- ServerStory,
16
- ServerStoryFile,
17
- ServerVariant,
18
- } from './story.js'
19
-
20
- export interface SupportPlugin {
21
- id: string
22
- moduleName: string
23
- setupFn: string | string[]
24
- importStoriesPrepend?: string
25
- importStoryComponent: (file: ServerStoryFile, index: number) => string
26
- }
27
-
28
- export interface FinalSupportPlugin extends SupportPlugin {
29
- // For now, no additional properties
30
- }
31
-
32
- export interface ModuleLoader {
33
- clearCache: () => void
34
- loadModule: (file: string) => Promise<any>
35
- destroy: () => void
36
- }
37
-
38
- export interface PluginApiBase {
39
- colors: typeof pc
40
- path: typeof path
41
- fs: typeof fs
42
- moduleLoader: ModuleLoader
43
-
44
- readonly pluginTempDir: string
45
-
46
- log: (...msg) => void
47
- warn: (...msg) => void
48
- error: (...msg) => void
49
-
50
- getStories: () => ServerStory[]
51
- addStoryFile: (file: string) => void
52
-
53
- getConfig: () => PovesteConfig
54
- }
55
-
56
- export interface PluginApiDev extends PluginApiBase {
57
- watcher: typeof chokidar
58
- }
59
-
60
- export type ChangeViteConfigCallback = (config: ViteInlineConfig) => Awaitable<void>
61
- export type BuildEndCallback = () => Awaitable<void>
62
- export type PreviewStoryCallback = (payload: { file: string, story: ServerStory, variant: ServerVariant, url: string }) => Awaitable<void>
63
-
64
- export interface PluginApiBuild extends PluginApiBase {
65
- changeViteConfigCallbacks: ChangeViteConfigCallback[]
66
- buildEndCallbacks: BuildEndCallback[]
67
- previewStoryCallbacks: PreviewStoryCallback[]
68
-
69
- changeViteConfig: (cb: ChangeViteConfigCallback) => void
70
- onBuildEnd: (cb: BuildEndCallback) => void
71
- onPreviewStory: (cb: PreviewStoryCallback) => void
72
- }
73
-
74
- export interface PluginApiDevEvent extends PluginApiBase {
75
- event: string
76
- payload: any
77
- }
78
-
79
- export interface Plugin {
80
- /**
81
- * Name of the plugin
82
- */
83
- name: string
84
- /**
85
- * Modify histoire default config. The hook can either mutate the passed config or
86
- * return a partial config object that will be deeply merged into the existing
87
- * config. User config will have higher priority than default config.
88
- *
89
- * Note: User plugins are resolved before running this hook so injecting other
90
- * plugins inside the `config` hook will have no effect.
91
- */
92
- defaultConfig?: (defaultConfig: PovesteConfig, mode: ConfigMode) => Partial<PovesteConfig> | null | void | Promise<Partial<PovesteConfig> | null | void>
93
- /**
94
- * Modify histoire config. The hook can either mutate the passed config or
95
- * return a partial config object that will be deeply merged into the existing
96
- * config.
97
- *
98
- * Note: User plugins are resolved before running this hook so injecting other
99
- * plugins inside the `config` hook will have no effect.
100
- */
101
- config?: (config: PovesteConfig, mode: ConfigMode) => Partial<PovesteConfig> | null | void | Promise<Partial<PovesteConfig> | null | void>
102
- /**
103
- * Use this hook to read and store the final resolved histoire config.
104
- */
105
- configResolved?: (config: PovesteConfig) => Awaitable<void>
106
- /**
107
- * Use this hook to do processing during development. The `onCleanup` hook
108
- * should handle cleanup tasks when development server is closed.
109
- */
110
- onDev?: (api: PluginApiDev, onCleanup: (cb: () => Awaitable<void>) => void) => Awaitable<void>
111
- /**
112
- * Use this hook to do processing during production build.
113
- */
114
- onBuild?: (api: PluginApiBuild) => Awaitable<void>
115
- /**
116
- * Use this hook to do processing when preview is started.
117
- */
118
- onPreview?: () => Awaitable<void>
119
- /**
120
- * This plugin exposes a support plugin (example: Vue, Svelte, etc.)
121
- */
122
- supportPlugin?: SupportPlugin
123
- /**
124
- * This plugin exposes commands that can be executed from the search bar in development mode.
125
- */
126
- commands?: PluginCommand[]
127
- /**
128
- * Handle a custom event from the client in development mode.
129
- */
130
- onDevEvent?: (api: PluginApiDevEvent) => Awaitable<any>
131
- /**
132
- * Use this hook to manipulate Vite plugins before they are passed to Vite.
133
- */
134
- vitePlugins?: (plugins: VitePlugin[]) => Awaitable<void>
135
- }
@@ -1,25 +0,0 @@
1
- import type { Awaitable } from '../type-utils.js'
2
-
3
- export interface PromptBase<TValue> {
4
- field: string
5
- label: string
6
- required?: boolean
7
- defaultValue?: TValue | ((answers: Record<string, any>) => TValue)
8
- }
9
-
10
- export interface TextPrompt extends PromptBase<string> {
11
- type: 'text'
12
- }
13
-
14
- export type SelectPromptOption = string | { value: string, label: string }
15
-
16
- export interface SelectPrompt extends PromptBase<string> {
17
- type: 'select'
18
- options: SelectPromptOption[] | ((search: string, answers: Record<string, any>) => Awaitable<SelectPromptOption[]>)
19
- }
20
-
21
- // No type parameter: both members fix their value type to `string` via
22
- // `PromptBase<string>`, so the `<TValue = any>` this used to carry never
23
- // reached anything and no caller ever passed one.
24
- export type Prompt = TextPrompt
25
- | SelectPrompt
@@ -1,221 +0,0 @@
1
- export interface StoryFile {
2
- id: string
3
- supportPluginId: string
4
- component: any
5
- story: Story
6
- path: string[]
7
- filePath: string
8
- docsFilePath?: string
9
- source: () => Promise<{ default: string }>
10
- }
11
-
12
- export type StoryLayout = {
13
- type: 'single'
14
- iframe?: boolean
15
- /**
16
- * Give every render of this story a fresh sandbox document instead of
17
- * reusing a warm one. Style isolation is the same either way; this is for
18
- * stories that leave JS state behind — patched globals, leaked timers —
19
- * that the next occupant of the realm must not see.
20
- */
21
- isolate?: boolean
22
- } | {
23
- type: 'grid'
24
- width?: number | string
25
- iframeGrid?: boolean
26
- /** See the single layout's `isolate`. */
27
- isolate?: boolean
28
- }
29
-
30
- export interface CommonProps {
31
- id?: string
32
- title?: string
33
- icon?: string
34
- iconColor?: string
35
- }
36
-
37
- export interface InheritedProps {
38
- setupApp?: (payload: any) => unknown
39
- source?: string
40
- responsiveDisabled?: boolean
41
- autoPropsDisabled?: boolean
42
- }
43
-
44
- export interface VariantProps extends CommonProps, InheritedProps {
45
- // No additional properties
46
- }
47
-
48
- export interface StoryProps extends CommonProps, InheritedProps {
49
- group?: string
50
- layout?: StoryLayout
51
- docsOnly?: boolean
52
- }
53
-
54
- export interface CommonMeta {}
55
-
56
- export interface StoryMeta extends CommonMeta {
57
- /**
58
- * When set, overrides the global Story Options visibility for this story.
59
- * `true` forces the right pane visible; `false` forces it hidden.
60
- * `undefined` (default) defers to the global layout setting.
61
- */
62
- storyOptions?: boolean
63
- }
64
-
65
- export interface Story {
66
- id: string
67
- title: string
68
- group?: string
69
- variants: Variant[]
70
- layout?: StoryLayout
71
- icon?: string
72
- iconColor?: string
73
- docsOnly?: boolean
74
- file?: StoryFile
75
- lastSelectedVariant?: Variant
76
- slots?: () => any
77
- meta?: StoryMeta
78
- }
79
-
80
- export interface VariantMeta extends CommonMeta {}
81
-
82
- export interface Variant {
83
- id: string
84
- title: string
85
- icon?: string
86
- iconColor?: string
87
- setupApp?: (payload: any) => unknown
88
- slots?: () => { default: any, controls: any, source: any }
89
- state: any
90
- source?: string
91
- responsiveDisabled?: boolean
92
- autoPropsDisabled?: boolean
93
- configReady?: boolean
94
- previewReady?: boolean
95
- meta?: VariantMeta
96
- }
97
-
98
- export interface PropDefinition {
99
- name: string
100
- types?: string[]
101
- required?: boolean
102
- default?: any
103
- }
104
-
105
- export interface AutoPropComponentDefinition {
106
- name: string
107
- index: number
108
- props: PropDefinition[]
109
- }
110
-
111
- /* SERVER */
112
-
113
- export interface ServerStoryFile {
114
- id: string
115
- /**
116
- * Absolute path
117
- */
118
- path: string
119
- /**
120
- * Relative path
121
- */
122
- relativePath: string
123
- /**
124
- * File name without extension
125
- */
126
- fileName: string
127
- /**
128
- * Support plugin (Vue, Svelte, etc.)
129
- */
130
- supportPluginId: string
131
- /**
132
- * Generated path for tree UI
133
- */
134
- treePath?: string[]
135
- /**
136
- * Use the module id in imports to allow HMR
137
- */
138
- moduleId: string
139
- /**
140
- * Resolved story data from story file execution
141
- */
142
- story?: ServerStory
143
- /**
144
- * Data sent to user tree config functions
145
- */
146
- treeFile?: ServerTreeFile
147
- /**
148
- * Is virtual module
149
- */
150
- virtual?: boolean
151
- /**
152
- * Virtual module code
153
- */
154
- moduleCode?: string
155
- /**
156
- * Related markdown docs
157
- */
158
- markdownFile?: ServerMarkdownFile
159
- }
160
-
161
- export interface ServerMarkdownFile {
162
- id: string
163
- relativePath: string
164
- absolutePath: string
165
- isRelatedToStory: boolean
166
- frontmatter?: any
167
- html?: string
168
- content?: string
169
- storyFile?: ServerStoryFile
170
- }
171
-
172
- export interface ServerStory {
173
- id: string
174
- title: string
175
- group?: string
176
- variants: ServerVariant[]
177
- layout?: StoryLayout
178
- icon?: string
179
- iconColor?: string
180
- docsOnly?: boolean
181
- docsText?: string
182
- meta?: StoryMeta
183
- }
184
-
185
- export interface ServerVariant {
186
- id: string
187
- title: string
188
- icon?: string
189
- iconColor?: string
190
- meta?: VariantMeta
191
- }
192
-
193
- export interface ServerTreeFile {
194
- title: string
195
- path: string
196
- }
197
-
198
- export interface ServerTreeLeaf {
199
- title: string
200
- index: number
201
- }
202
-
203
- export interface ServerTreeFolder {
204
- title: string
205
- children: (ServerTreeFolder | ServerTreeLeaf)[]
206
- }
207
-
208
- export interface ServerTreeGroup {
209
- group: true
210
- id: string
211
- title: string
212
- children: (ServerTreeFolder | ServerTreeLeaf)[]
213
- }
214
-
215
- export type ServerTree = (ServerTreeGroup | ServerTreeFolder | ServerTreeLeaf)[]
216
-
217
- export interface ServerRunPayload {
218
- file: ServerStoryFile
219
- storyData: ServerStory[]
220
- el: HTMLElement
221
- }