@histoire/shared 0.13.2 → 0.14.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.
- package/dist/types/command.d.ts +35 -0
- package/dist/types/command.js +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +2 -0
- package/dist/types/plugin.d.ts +16 -0
- package/dist/types/prompt.d.ts +19 -0
- package/dist/types/prompt.js +1 -0
- package/dist/types/story.d.ts +1 -0
- package/package.json +2 -1
- package/src/types/command.ts +38 -0
- package/src/types/index.ts +2 -0
- package/src/types/plugin.ts +20 -0
- package/src/types/prompt.ts +22 -0
- package/src/types/story.ts +1 -0
- package/tsconfig.json +11 -0
|
@@ -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 {};
|
package/dist/types/index.d.ts
CHANGED
package/dist/types/index.js
CHANGED
package/dist/types/plugin.d.ts
CHANGED
|
@@ -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 {};
|
package/dist/types/story.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@histoire/shared",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
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.0",
|
|
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
|
+
}
|
package/src/types/index.ts
CHANGED
package/src/types/plugin.ts
CHANGED
|
@@ -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
|
package/src/types/story.ts
CHANGED
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"
|