@histoire/shared 0.13.2 → 0.14.1

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.
@@ -0,0 +1,35 @@
1
+ import type { RouteLocationNormalizedLoaded } from 'vue-router';
2
+ import type { Prompt } from './prompt.js';
3
+ import type { Story, Variant } from './story.js';
4
+ export interface CommonCommandOptions {
5
+ icon?: string;
6
+ searchText?: string;
7
+ prompts?: Prompt[];
8
+ }
9
+ export interface Command extends CommonCommandOptions {
10
+ id: string;
11
+ label: string;
12
+ }
13
+ export interface ClientCommandOptions extends CommonCommandOptions {
14
+ showIf?: (ctx: ClientCommandContext) => boolean;
15
+ getParams?: (ctx: ClientCommandContext & {
16
+ answers?: Record<string, any>;
17
+ }) => Record<string, any>;
18
+ clientAction?: (params: Record<string, any>, ctx: ClientCommandContext) => unknown;
19
+ }
20
+ /**
21
+ * A command that can be executed from the search bar.
22
+ */
23
+ export type ClientCommand = Command & ClientCommandOptions;
24
+ export interface ClientCommandContext {
25
+ route: RouteLocationNormalizedLoaded;
26
+ currentStory: Story;
27
+ currentVariant: Variant;
28
+ }
29
+ export interface PluginCommand<TParams = Record<string, any>> extends Command {
30
+ serverAction?: (params: TParams) => unknown;
31
+ clientSetupFile?: string | {
32
+ file: string;
33
+ importName: string;
34
+ };
35
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -119,6 +119,10 @@ export interface HistoireConfig {
119
119
  * Enable persistence of the color scheme in the browser.
120
120
  */
121
121
  storeColorScheme?: boolean;
122
+ /**
123
+ * Class added to the story preview when dark mode is enabled.
124
+ */
125
+ darkClass?: string;
122
126
  };
123
127
  /**
124
128
  * Setup file exporting a default function executed when setting up each story preview.
@@ -165,6 +169,7 @@ export interface HistoireConfig {
165
169
  autoApplyContrastColor?: boolean;
166
170
  /**
167
171
  * Class added to the html root of the story preview when dark mode is enabled.
172
+ * @deprecated use `theme.darkClass` instead
168
173
  */
169
174
  sandboxDarkClass?: string;
170
175
  /**
@@ -1,3 +1,5 @@
1
+ export * from './command.js';
1
2
  export * from './config.js';
2
3
  export * from './plugin.js';
4
+ export * from './prompt.js';
3
5
  export * from './story.js';
@@ -1,3 +1,5 @@
1
+ export * from './command.js';
1
2
  export * from './config.js';
2
3
  export * from './plugin.js';
4
+ export * from './prompt.js';
3
5
  export * from './story.js';
@@ -4,6 +4,8 @@ import type pc from 'picocolors';
4
4
  import type chokidar from 'chokidar';
5
5
  import type { ServerStoryFile, ServerStory, ServerVariant } from './story.js';
6
6
  import type { HistoireConfig, ConfigMode } from './config.js';
7
+ import type { PluginCommand } from './command.js';
8
+ import type { Awaitable } from '../type-utils.js';
7
9
  export interface SupportPlugin {
8
10
  id: string;
9
11
  moduleName: string;
@@ -27,7 +29,9 @@ export interface PluginApiBase {
27
29
  log: (...msg: any[]) => void;
28
30
  warn: (...msg: any[]) => void;
29
31
  error: (...msg: any[]) => void;
32
+ getStories(): ServerStory[];
30
33
  addStoryFile: (file: string) => void;
34
+ getConfig(): HistoireConfig;
31
35
  }
32
36
  export interface PluginApiDev extends PluginApiBase {
33
37
  watcher: typeof chokidar;
@@ -45,6 +49,10 @@ export interface PluginApiBuild extends PluginApiBase {
45
49
  onBuildEnd: (cb: BuildEndCallback) => void;
46
50
  onPreviewStory: (cb: PreviewStoryCallback) => void;
47
51
  }
52
+ export interface PluginApiDevEvent extends PluginApiBase {
53
+ event: string;
54
+ payload: any;
55
+ }
48
56
  export interface Plugin {
49
57
  /**
50
58
  * Name of the plugin
@@ -85,4 +93,12 @@ export interface Plugin {
85
93
  * This plugin exposes a support plugin (example: Vue, Svelte, etc.)
86
94
  */
87
95
  supportPlugin?: SupportPlugin;
96
+ /**
97
+ * This plugin exposes commands that can be executed from the search bar in development mode.
98
+ */
99
+ commands?: PluginCommand[];
100
+ /**
101
+ * Handle a custom event from the client in development mode.
102
+ */
103
+ onDevEvent?: (api: PluginApiDevEvent) => Awaitable<any>;
88
104
  }
@@ -0,0 +1,19 @@
1
+ import { Awaitable } from '../type-utils.js';
2
+ export interface PromptBase<TValue> {
3
+ field: string;
4
+ label: string;
5
+ required?: boolean;
6
+ defaultValue?: TValue | ((answers: Record<string, any>) => TValue);
7
+ }
8
+ export interface TextPrompt extends PromptBase<string> {
9
+ type: 'text';
10
+ }
11
+ export type SelectPromptOption = string | {
12
+ value: string;
13
+ label: string;
14
+ };
15
+ export interface SelectPrompt extends PromptBase<string> {
16
+ type: 'select';
17
+ options: SelectPromptOption[] | ((search: string, answers: Record<string, any>) => Awaitable<SelectPromptOption[]>);
18
+ }
19
+ export type Prompt<TValue = any> = TextPrompt | SelectPrompt;
@@ -0,0 +1 @@
1
+ export {};
@@ -5,6 +5,7 @@ export interface StoryFile {
5
5
  story: Story;
6
6
  path: string[];
7
7
  filePath: string;
8
+ docsFilePath?: string;
8
9
  source: () => Promise<{
9
10
  default: string;
10
11
  }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@histoire/shared",
3
- "version": "0.13.2",
3
+ "version": "0.14.1",
4
4
  "description": "Shared utilities for Histoire",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -25,6 +25,7 @@
25
25
  "types": "./dist/index.d.ts",
26
26
  "sideEffects": false,
27
27
  "dependencies": {
28
+ "@histoire/vendors": "^0.14.1",
28
29
  "@types/fs-extra": "^9.0.13",
29
30
  "@types/markdown-it": "^12.2.3",
30
31
  "chokidar": "^3.5.3",
@@ -0,0 +1,38 @@
1
+ import type { RouteLocationNormalizedLoaded } from 'vue-router'
2
+ import type { Prompt } from './prompt.js'
3
+ import type { Story, Variant } from './story.js'
4
+
5
+ export interface CommonCommandOptions {
6
+ icon?: string
7
+ searchText?: string
8
+ prompts?: Prompt[]
9
+ }
10
+
11
+ export interface Command extends CommonCommandOptions {
12
+ id: string
13
+ label: string
14
+ }
15
+
16
+ export interface ClientCommandOptions extends CommonCommandOptions {
17
+ showIf?: (ctx: ClientCommandContext) => boolean
18
+ getParams?: (ctx: ClientCommandContext & { answers?: Record<string, any> }) => Record<string, any>
19
+ clientAction?: (params: Record<string, any>, ctx: ClientCommandContext) => unknown
20
+ }
21
+
22
+ /**
23
+ * A command that can be executed from the search bar.
24
+ */
25
+ export type ClientCommand = Command & ClientCommandOptions
26
+
27
+ export interface ClientCommandContext {
28
+ route: RouteLocationNormalizedLoaded
29
+ currentStory: Story
30
+ currentVariant: Variant
31
+ }
32
+
33
+ export interface PluginCommand<
34
+ TParams = Record<string, any>
35
+ > extends Command {
36
+ serverAction?: (params: TParams) => unknown // @TODO ctx
37
+ clientSetupFile?: string | { file: string, importName: string }
38
+ }
@@ -128,6 +128,10 @@ export interface HistoireConfig {
128
128
  * Enable persistence of the color scheme in the browser.
129
129
  */
130
130
  storeColorScheme?: boolean
131
+ /**
132
+ * Class added to the story preview when dark mode is enabled.
133
+ */
134
+ darkClass?: string
131
135
  }
132
136
  /**
133
137
  * Setup file exporting a default function executed when setting up each story preview.
@@ -174,6 +178,7 @@ export interface HistoireConfig {
174
178
  autoApplyContrastColor?: boolean
175
179
  /**
176
180
  * Class added to the html root of the story preview when dark mode is enabled.
181
+ * @deprecated use `theme.darkClass` instead
177
182
  */
178
183
  sandboxDarkClass?: string
179
184
  /**
@@ -1,3 +1,5 @@
1
+ export * from './command.js'
1
2
  export * from './config.js'
2
3
  export * from './plugin.js'
4
+ export * from './prompt.js'
3
5
  export * from './story.js'
@@ -11,6 +11,10 @@ import type {
11
11
  HistoireConfig,
12
12
  ConfigMode,
13
13
  } from './config.js'
14
+ import type {
15
+ PluginCommand,
16
+ } from './command.js'
17
+ import type { Awaitable } from '../type-utils.js'
14
18
 
15
19
  export interface SupportPlugin {
16
20
  id: string
@@ -42,7 +46,10 @@ export interface PluginApiBase {
42
46
  warn: (...msg) => void
43
47
  error: (...msg) => void
44
48
 
49
+ getStories (): ServerStory[]
45
50
  addStoryFile: (file: string) => void
51
+
52
+ getConfig (): HistoireConfig
46
53
  }
47
54
 
48
55
  export interface PluginApiDev extends PluginApiBase {
@@ -60,6 +67,11 @@ export interface PluginApiBuild extends PluginApiBase {
60
67
  onPreviewStory: (cb: PreviewStoryCallback) => void
61
68
  }
62
69
 
70
+ export interface PluginApiDevEvent extends PluginApiBase {
71
+ event: string
72
+ payload: any
73
+ }
74
+
63
75
  export interface Plugin {
64
76
  /**
65
77
  * Name of the plugin
@@ -100,4 +112,12 @@ export interface Plugin {
100
112
  * This plugin exposes a support plugin (example: Vue, Svelte, etc.)
101
113
  */
102
114
  supportPlugin?: SupportPlugin
115
+ /**
116
+ * This plugin exposes commands that can be executed from the search bar in development mode.
117
+ */
118
+ commands?: PluginCommand[]
119
+ /**
120
+ * Handle a custom event from the client in development mode.
121
+ */
122
+ onDevEvent?: (api: PluginApiDevEvent) => Awaitable<any>
103
123
  }
@@ -0,0 +1,22 @@
1
+ import { 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
+ export type Prompt<TValue = any> = TextPrompt
22
+ | SelectPrompt
@@ -5,6 +5,7 @@ export interface StoryFile {
5
5
  story: Story
6
6
  path: string[]
7
7
  filePath: string
8
+ docsFilePath?: string
8
9
  source: () => Promise<{ default: string }>
9
10
  }
10
11
 
package/tsconfig.json CHANGED
@@ -5,6 +5,7 @@
5
5
  "moduleResolution": "node",
6
6
  "outDir": "dist",
7
7
  "rootDir": "src",
8
+ "baseUrl": ".",
8
9
  "allowSyntheticDefaultImports": true,
9
10
  "esModuleInterop": true,
10
11
  "removeComments": false,
@@ -24,6 +25,16 @@
24
25
  "strictFunctionTypes": true,
25
26
  // Volar
26
27
  "jsx": "preserve",
28
+ // Alias
29
+ "paths": {
30
+ "floating-vue": ["node_modules/@histoire/vendors/floating-vue"],
31
+ "@iconify/vue": ["node_modules/@histoire/vendors/iconify"],
32
+ "pinia": ["node_modules/@histoire/vendors/pinia"],
33
+ "scroll-into-view-if-needed": ["node_modules/@histoire/vendors/scroll"],
34
+ "vue-router": ["node_modules/@histoire/vendors/vue-router"],
35
+ "@vueuse/core": ["node_modules/@histoire/vendors/vue-use"],
36
+ "vue": ["node_modules/@histoire/vendors/vue"]
37
+ }
27
38
  },
28
39
  "include": [
29
40
  "src"