@histoire/shared 0.10.2 → 0.10.5

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.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export * from './codegen/index.js';
2
- export * from './types.js';
2
+ export * from './types/index.js';
3
3
  export * from './state.js';
4
4
  export * from './type-utils.js';
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  export * from './codegen/index.js';
2
- export * from './types.js';
2
+ export * from './types/index.js';
3
3
  export * from './state.js';
4
4
  export * from './type-utils.js';
@@ -0,0 +1,173 @@
1
+ import type { UserConfig as ViteConfig, ConfigEnv as ViteConfigEnv } from 'vite';
2
+ import type MarkdownIt from 'markdown-it';
3
+ import type { ServerTreeFile } from './story.js';
4
+ import type { Plugin } from './plugin.js';
5
+ export interface SupportMatchPattern {
6
+ id: string;
7
+ patterns: string[];
8
+ pluginIds: string[];
9
+ }
10
+ export declare type CustomizableColors = 'primary' | 'gray';
11
+ export declare type ColorKeys = '50' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900';
12
+ export declare type GrayColorKeys = ColorKeys | '750' | '850' | '950';
13
+ export interface ResponsivePreset {
14
+ label: string;
15
+ width: number;
16
+ height: number;
17
+ }
18
+ export interface BackgroundPreset {
19
+ label: string;
20
+ color: string;
21
+ }
22
+ export interface TreeGroupConfig {
23
+ title: string;
24
+ id?: string;
25
+ include?: (file: ServerTreeFile) => boolean;
26
+ }
27
+ export interface HistoireConfig {
28
+ plugins: Plugin[];
29
+ /**
30
+ * Output directory.
31
+ */
32
+ outDir: string;
33
+ /**
34
+ * Glob patterns for story files to include.
35
+ */
36
+ storyMatch: string[];
37
+ /**
38
+ * Glob patterns to ignore files while searching for story files.
39
+ */
40
+ storyIgnored: string[];
41
+ /**
42
+ * Patterns to match stories to support plugins automatically.
43
+ */
44
+ supportMatch: SupportMatchPattern[];
45
+ /**
46
+ * How to generate the story tree.
47
+ */
48
+ tree: {
49
+ /**
50
+ * Use `'title'` to create the path from the title of the story, using `/` as the separator.
51
+ *
52
+ * Use `'path'` use the real folder structure on your computer.
53
+ */
54
+ file?: 'title' | 'path' | ((file: ServerTreeFile) => string[]);
55
+ order?: 'asc' | ((a: string, b: string) => number);
56
+ groups?: TreeGroupConfig[];
57
+ };
58
+ /**
59
+ * Customize the look of the histoire book.
60
+ */
61
+ theme: {
62
+ /**
63
+ * Main page title. For example: 'Acme Inc.'
64
+ */
65
+ title?: string;
66
+ /**
67
+ * Custom logo files. Should be import paths (processed by Vite).
68
+ *
69
+ * Example: `'/src/assets/my-logo.svg'`
70
+ */
71
+ logo?: {
72
+ /**
73
+ * Square logo without text.
74
+ */
75
+ square?: string;
76
+ /**
77
+ * Full logo for light theme.
78
+ */
79
+ light?: string;
80
+ /**
81
+ * Full logo for dark theme.
82
+ */
83
+ dark?: string;
84
+ };
85
+ /**
86
+ * Href to the favicon file (**not** processed by Vite). Put the file in the `public` directory.
87
+ *
88
+ * Example: `'/favicon.ico'`
89
+ */
90
+ favicon?: string;
91
+ /**
92
+ * Customize the colors. Each color should be an object with shades as keys.
93
+ *
94
+ * Example: ```{ primary: { 50: '#eef2ff', 100: '#e0e7ff', ..., 900: '#312e81' } }```
95
+ *
96
+ * You can import `defaultColors` from `'histoire'` to use predefined colors or you can create your own colors from scratch.
97
+ */
98
+ colors?: {
99
+ [key in CustomizableColors]?: key extends 'gray' ? {
100
+ [key in GrayColorKeys]?: string;
101
+ } : {
102
+ [key in ColorKeys]?: string;
103
+ };
104
+ };
105
+ /**
106
+ * Add a link to the main logo
107
+ */
108
+ logoHref?: string;
109
+ };
110
+ /**
111
+ * Setup file exporting a default function executed when setting up each story preview.
112
+ *
113
+ * Import custom CSS files from this file.
114
+ *
115
+ * Example: `'/src/histoire-setup.ts'`
116
+ */
117
+ setupFile?: string;
118
+ /**
119
+ * Setup code created by plugins
120
+ */
121
+ setupCode?: string[];
122
+ /**
123
+ * Predefined responsive sizes for story playgrounds.
124
+ */
125
+ responsivePresets?: ResponsivePreset[];
126
+ /**
127
+ * Background color of the story preview.
128
+ */
129
+ backgroundPresets?: BackgroundPreset[];
130
+ /**
131
+ * Class added to the html root of the story preview when dark mode is enabled.
132
+ */
133
+ sandboxDarkClass?: string;
134
+ /**
135
+ * Customize the markdown-it renderer
136
+ */
137
+ markdown?: (md: MarkdownIt) => MarkdownIt | Promise<MarkdownIt>;
138
+ /**
139
+ * Change the router mode.
140
+ * - history: use HTML history with cleaner URLs
141
+ * - hash: use hashtag hack in the URL to support more hosting services
142
+ */
143
+ routerMode?: 'history' | 'hash';
144
+ /**
145
+ * Vite config override
146
+ */
147
+ vite?: ViteConfig | ((config: ViteConfig, env: ViteConfigEnv) => void | ViteConfig | Promise<void | ViteConfig>);
148
+ /**
149
+ * Transpile dependencies when collecting stories on Node.js
150
+ */
151
+ viteNodeInlineDeps?: RegExp[];
152
+ /**
153
+ * Determine the transform method of modules
154
+ */
155
+ viteNodeTransformMode?: {
156
+ /**
157
+ * Use SSR transform pipeline for the specified files.
158
+ * Vite plugins will receive `ssr: true` flag when processing those files.
159
+ *
160
+ * @default [/\.([cm]?[jt]sx?|json)$/]
161
+ */
162
+ ssr?: RegExp[];
163
+ /**
164
+ * First do a normal transform pipeline (targeting browser),
165
+ * then then do a SSR rewrite to run the code in Node.
166
+ * Vite plugins will receive `ssr: false` flag when processing those files.
167
+ *
168
+ * @default other than `ssr`
169
+ */
170
+ web?: RegExp[];
171
+ };
172
+ }
173
+ export declare type ConfigMode = 'build' | 'dev';
File without changes
@@ -0,0 +1,3 @@
1
+ export * from './config.js';
2
+ export * from './plugin.js';
3
+ export * from './story.js';
@@ -0,0 +1,3 @@
1
+ export * from './config.js';
2
+ export * from './plugin.js';
3
+ export * from './story.js';
@@ -0,0 +1,88 @@
1
+ import type path from 'pathe';
2
+ import type fs from 'fs-extra';
3
+ import type pc from 'picocolors';
4
+ import type chokidar from 'chokidar';
5
+ import type { ServerStoryFile, ServerStory, ServerVariant } from './story.js';
6
+ import type { HistoireConfig, ConfigMode } from './config.js';
7
+ export interface SupportPlugin {
8
+ id: string;
9
+ moduleName: string;
10
+ setupFn: string;
11
+ importStoriesPrepend?: string;
12
+ importStoryComponent: (file: ServerStoryFile, index: number) => string;
13
+ }
14
+ export interface FinalSupportPlugin extends SupportPlugin {
15
+ }
16
+ export interface ModuleLoader {
17
+ clearCache: () => void;
18
+ loadModule: (file: string) => Promise<any>;
19
+ destroy: () => void;
20
+ }
21
+ export interface PluginApiBase {
22
+ colors: typeof pc;
23
+ path: typeof path;
24
+ fs: typeof fs;
25
+ moduleLoader: ModuleLoader;
26
+ readonly pluginTempDir: string;
27
+ log: (...msg: any[]) => void;
28
+ warn: (...msg: any[]) => void;
29
+ error: (...msg: any[]) => void;
30
+ addStoryFile: (file: string) => void;
31
+ }
32
+ export interface PluginApiDev extends PluginApiBase {
33
+ watcher: typeof chokidar;
34
+ }
35
+ export declare type BuildEndCallback = () => Promise<void> | void;
36
+ export declare type PreviewStoryCallback = (payload: {
37
+ file: string;
38
+ story: ServerStory;
39
+ variant: ServerVariant;
40
+ url: string;
41
+ }) => Promise<void> | void;
42
+ export interface PluginApiBuild extends PluginApiBase {
43
+ buildEndCallbacks: BuildEndCallback[];
44
+ previewStoryCallbacks: PreviewStoryCallback[];
45
+ onBuildEnd: (cb: BuildEndCallback) => void;
46
+ onPreviewStory: (cb: PreviewStoryCallback) => void;
47
+ }
48
+ export interface Plugin {
49
+ /**
50
+ * Name of the plugin
51
+ */
52
+ name: string;
53
+ /**
54
+ * Modify histoire default config. The hook can either mutate the passed config or
55
+ * return a partial config object that will be deeply merged into the existing
56
+ * config. User config will have higher priority than default config.
57
+ *
58
+ * Note: User plugins are resolved before running this hook so injecting other
59
+ * plugins inside the `config` hook will have no effect.
60
+ */
61
+ defaultConfig?: (defaultConfig: HistoireConfig, mode: ConfigMode) => Partial<HistoireConfig> | null | void | Promise<Partial<HistoireConfig> | null | void>;
62
+ /**
63
+ * Modify histoire config. The hook can either mutate the passed config or
64
+ * return a partial config object that will be deeply merged into the existing
65
+ * config.
66
+ *
67
+ * Note: User plugins are resolved before running this hook so injecting other
68
+ * plugins inside the `config` hook will have no effect.
69
+ */
70
+ config?: (config: HistoireConfig, mode: ConfigMode) => Partial<HistoireConfig> | null | void | Promise<Partial<HistoireConfig> | null | void>;
71
+ /**
72
+ * Use this hook to read and store the final resolved histoire config.
73
+ */
74
+ configResolved?: (config: HistoireConfig) => void | Promise<void>;
75
+ /**
76
+ * Use this hook to do processing during development. The `onCleanup` hook
77
+ * should handle cleanup tasks when development server is closed.
78
+ */
79
+ onDev?: (api: PluginApiDev, onCleanup: (cb: () => void | Promise<void>) => void) => void | Promise<void>;
80
+ /**
81
+ * Use this hook to do processing during production build.
82
+ */
83
+ onBuild?: (api: PluginApiBuild) => void | Promise<void>;
84
+ /**
85
+ * This plugin exposes a support plugin (example: Vue, Svelte, etc.)
86
+ */
87
+ supportPlugin?: SupportPlugin;
88
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -169,12 +169,3 @@ export interface ServerRunPayload {
169
169
  storyData: ServerStory[];
170
170
  el: HTMLElement;
171
171
  }
172
- export interface SupportPlugin {
173
- id: string;
174
- moduleName: string;
175
- setupFn: string;
176
- importStoriesPrepend?: string;
177
- importStoryComponent: (file: ServerStoryFile, index: number) => string;
178
- }
179
- export interface FinalSupportPlugin extends SupportPlugin {
180
- }
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@histoire/shared",
3
- "version": "0.10.2",
3
+ "version": "0.10.5",
4
4
  "description": "Shared utilities for Histoire",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -24,9 +24,19 @@
24
24
  "module": "./dist/index.js",
25
25
  "types": "./dist/index.d.ts",
26
26
  "sideEffects": false,
27
- "dependencies": {},
27
+ "dependencies": {
28
+ "@types/fs-extra": "^9.0.13",
29
+ "@types/markdown-it": "^12.2.3",
30
+ "chokidar": "^3.5.3",
31
+ "pathe": "^0.2.0",
32
+ "picocolors": "^1.0.0"
33
+ },
34
+ "peerDependencies": {
35
+ "vite": "^2.9.0 || ^3.0.0"
36
+ },
28
37
  "devDependencies": {
29
- "typescript": "^4.7.4"
38
+ "typescript": "^4.7.4",
39
+ "vite": "^3.0.5"
30
40
  },
31
41
  "scripts": {
32
42
  "build": "rimraf dist && tsc -d",
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export * from './codegen/index.js'
2
- export * from './types.js'
2
+ export * from './types/index.js'
3
3
  export * from './state.js'
4
4
  export * from './type-utils.js'
@@ -0,0 +1,183 @@
1
+ import type {
2
+ UserConfig as ViteConfig,
3
+ ConfigEnv as ViteConfigEnv,
4
+ } from 'vite'
5
+ import type MarkdownIt from 'markdown-it'
6
+ import type { ServerTreeFile } from './story.js'
7
+ import type { Plugin } from './plugin.js'
8
+
9
+ export interface SupportMatchPattern {
10
+ id: string
11
+ patterns: string[]
12
+ pluginIds: string[]
13
+ }
14
+
15
+ export type CustomizableColors = 'primary' | 'gray'
16
+ export type ColorKeys = '50' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900'
17
+ export type GrayColorKeys = ColorKeys | '750' | '850' | '950'
18
+
19
+ export interface ResponsivePreset {
20
+ label: string
21
+ width: number
22
+ height: number
23
+ }
24
+
25
+ export interface BackgroundPreset {
26
+ label: string
27
+ color: string
28
+ }
29
+
30
+ export interface TreeGroupConfig {
31
+ title: string
32
+ id?: string
33
+ include?: (file: ServerTreeFile) => boolean
34
+ }
35
+
36
+ export interface HistoireConfig {
37
+ plugins: Plugin[]
38
+ /**
39
+ * Output directory.
40
+ */
41
+ outDir: string
42
+ /**
43
+ * Glob patterns for story files to include.
44
+ */
45
+ storyMatch: string[]
46
+ /**
47
+ * Glob patterns to ignore files while searching for story files.
48
+ */
49
+ storyIgnored: string[]
50
+ /**
51
+ * Patterns to match stories to support plugins automatically.
52
+ */
53
+ supportMatch: SupportMatchPattern[]
54
+ /**
55
+ * How to generate the story tree.
56
+ */
57
+ tree: {
58
+ /**
59
+ * Use `'title'` to create the path from the title of the story, using `/` as the separator.
60
+ *
61
+ * Use `'path'` use the real folder structure on your computer.
62
+ */
63
+ file?: 'title' | 'path' | ((file: ServerTreeFile) => string[])
64
+ order?: 'asc' | ((a: string, b: string) => number)
65
+ groups?: TreeGroupConfig[]
66
+ }
67
+ /**
68
+ * Customize the look of the histoire book.
69
+ */
70
+ theme: {
71
+ /**
72
+ * Main page title. For example: 'Acme Inc.'
73
+ */
74
+ title?: string
75
+ /**
76
+ * Custom logo files. Should be import paths (processed by Vite).
77
+ *
78
+ * Example: `'/src/assets/my-logo.svg'`
79
+ */
80
+ logo?: {
81
+ /**
82
+ * Square logo without text.
83
+ */
84
+ square?: string
85
+ /**
86
+ * Full logo for light theme.
87
+ */
88
+ light?: string
89
+ /**
90
+ * Full logo for dark theme.
91
+ */
92
+ dark?: string
93
+ }
94
+ /**
95
+ * Href to the favicon file (**not** processed by Vite). Put the file in the `public` directory.
96
+ *
97
+ * Example: `'/favicon.ico'`
98
+ */
99
+ favicon?: string
100
+ /**
101
+ * Customize the colors. Each color should be an object with shades as keys.
102
+ *
103
+ * Example: ```{ primary: { 50: '#eef2ff', 100: '#e0e7ff', ..., 900: '#312e81' } }```
104
+ *
105
+ * You can import `defaultColors` from `'histoire'` to use predefined colors or you can create your own colors from scratch.
106
+ */
107
+ colors?: {
108
+ [key in CustomizableColors]?: key extends 'gray' ? {
109
+ [key in GrayColorKeys]?: string
110
+ } :{
111
+ [key in ColorKeys]?: string
112
+ }
113
+ }
114
+ /**
115
+ * Add a link to the main logo
116
+ */
117
+ logoHref?: string
118
+ }
119
+ /**
120
+ * Setup file exporting a default function executed when setting up each story preview.
121
+ *
122
+ * Import custom CSS files from this file.
123
+ *
124
+ * Example: `'/src/histoire-setup.ts'`
125
+ */
126
+ setupFile?: string
127
+ /**
128
+ * Setup code created by plugins
129
+ */
130
+ setupCode?: string[]
131
+ /**
132
+ * Predefined responsive sizes for story playgrounds.
133
+ */
134
+ responsivePresets?: ResponsivePreset[]
135
+ /**
136
+ * Background color of the story preview.
137
+ */
138
+ backgroundPresets?: BackgroundPreset[]
139
+ /**
140
+ * Class added to the html root of the story preview when dark mode is enabled.
141
+ */
142
+ sandboxDarkClass?: string
143
+ /**
144
+ * Customize the markdown-it renderer
145
+ */
146
+ markdown?: (md: MarkdownIt) => MarkdownIt | Promise<MarkdownIt>
147
+ /**
148
+ * Change the router mode.
149
+ * - history: use HTML history with cleaner URLs
150
+ * - hash: use hashtag hack in the URL to support more hosting services
151
+ */
152
+ routerMode?: 'history' | 'hash'
153
+ /**
154
+ * Vite config override
155
+ */
156
+ vite?: ViteConfig | ((config: ViteConfig, env: ViteConfigEnv) => void | ViteConfig | Promise<void | ViteConfig>)
157
+ /**
158
+ * Transpile dependencies when collecting stories on Node.js
159
+ */
160
+ viteNodeInlineDeps?: RegExp[]
161
+ /**
162
+ * Determine the transform method of modules
163
+ */
164
+ viteNodeTransformMode?: {
165
+ /**
166
+ * Use SSR transform pipeline for the specified files.
167
+ * Vite plugins will receive `ssr: true` flag when processing those files.
168
+ *
169
+ * @default [/\.([cm]?[jt]sx?|json)$/]
170
+ */
171
+ ssr?: RegExp[]
172
+ /**
173
+ * First do a normal transform pipeline (targeting browser),
174
+ * then then do a SSR rewrite to run the code in Node.
175
+ * Vite plugins will receive `ssr: false` flag when processing those files.
176
+ *
177
+ * @default other than `ssr`
178
+ */
179
+ web?: RegExp[]
180
+ }
181
+ }
182
+
183
+ export type ConfigMode = 'build' | 'dev'
@@ -0,0 +1,3 @@
1
+ export * from './config.js'
2
+ export * from './plugin.js'
3
+ export * from './story.js'
@@ -0,0 +1,103 @@
1
+ import type path from 'pathe'
2
+ import type fs from 'fs-extra'
3
+ import type pc from 'picocolors'
4
+ import type chokidar from 'chokidar'
5
+ import type {
6
+ ServerStoryFile,
7
+ ServerStory,
8
+ ServerVariant,
9
+ } from './story.js'
10
+ import type {
11
+ HistoireConfig,
12
+ ConfigMode,
13
+ } from './config.js'
14
+
15
+ export interface SupportPlugin {
16
+ id: string
17
+ moduleName: string
18
+ setupFn: string
19
+ importStoriesPrepend?: string
20
+ importStoryComponent: (file: ServerStoryFile, index: number) => string
21
+ }
22
+
23
+ export interface FinalSupportPlugin extends SupportPlugin {
24
+ // For now, no additional properties
25
+ }
26
+
27
+ export interface ModuleLoader {
28
+ clearCache: () => void
29
+ loadModule: (file: string) => Promise<any>
30
+ destroy: () => void
31
+ }
32
+
33
+ export interface PluginApiBase {
34
+ colors: typeof pc
35
+ path: typeof path
36
+ fs: typeof fs
37
+ moduleLoader: ModuleLoader
38
+
39
+ readonly pluginTempDir: string
40
+
41
+ log: (...msg) => void
42
+ warn: (...msg) => void
43
+ error: (...msg) => void
44
+
45
+ addStoryFile: (file: string) => void
46
+ }
47
+
48
+ export interface PluginApiDev extends PluginApiBase {
49
+ watcher: typeof chokidar
50
+ }
51
+
52
+ export type BuildEndCallback = () => Promise<void> | void
53
+ export type PreviewStoryCallback = (payload: { file: string, story: ServerStory, variant: ServerVariant, url: string }) => Promise<void> | void
54
+
55
+ export interface PluginApiBuild extends PluginApiBase {
56
+ buildEndCallbacks: BuildEndCallback[]
57
+ previewStoryCallbacks: PreviewStoryCallback[]
58
+
59
+ onBuildEnd: (cb: BuildEndCallback) => void
60
+ onPreviewStory: (cb: PreviewStoryCallback) => void
61
+ }
62
+
63
+ export interface Plugin {
64
+ /**
65
+ * Name of the plugin
66
+ */
67
+ name: string
68
+ /**
69
+ * Modify histoire default config. The hook can either mutate the passed config or
70
+ * return a partial config object that will be deeply merged into the existing
71
+ * config. User config will have higher priority than default config.
72
+ *
73
+ * Note: User plugins are resolved before running this hook so injecting other
74
+ * plugins inside the `config` hook will have no effect.
75
+ */
76
+ defaultConfig?: (defaultConfig: HistoireConfig, mode: ConfigMode) => Partial<HistoireConfig> | null | void | Promise<Partial<HistoireConfig> | null | void>
77
+ /**
78
+ * Modify histoire config. The hook can either mutate the passed config or
79
+ * return a partial config object that will be deeply merged into the existing
80
+ * config.
81
+ *
82
+ * Note: User plugins are resolved before running this hook so injecting other
83
+ * plugins inside the `config` hook will have no effect.
84
+ */
85
+ config?: (config: HistoireConfig, mode: ConfigMode) => Partial<HistoireConfig> | null | void | Promise<Partial<HistoireConfig> | null | void>
86
+ /**
87
+ * Use this hook to read and store the final resolved histoire config.
88
+ */
89
+ configResolved?: (config: HistoireConfig) => void | Promise<void>
90
+ /**
91
+ * Use this hook to do processing during development. The `onCleanup` hook
92
+ * should handle cleanup tasks when development server is closed.
93
+ */
94
+ onDev?: (api: PluginApiDev, onCleanup: (cb: () => void | Promise<void>) => void) => void | Promise<void>
95
+ /**
96
+ * Use this hook to do processing during production build.
97
+ */
98
+ onBuild?: (api: PluginApiBuild) => void | Promise<void>
99
+ /**
100
+ * This plugin exposes a support plugin (example: Vue, Svelte, etc.)
101
+ */
102
+ supportPlugin?: SupportPlugin
103
+ }
@@ -188,15 +188,3 @@ export interface ServerRunPayload {
188
188
  storyData: ServerStory[]
189
189
  el: HTMLElement
190
190
  }
191
-
192
- export interface SupportPlugin {
193
- id: string
194
- moduleName: string
195
- setupFn: string
196
- importStoriesPrepend?: string
197
- importStoryComponent: (file: ServerStoryFile, index: number) => string
198
- }
199
-
200
- export interface FinalSupportPlugin extends SupportPlugin {
201
- // For now, no additional properties
202
- }