@repobuddy/storybook 2.5.0 → 2.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.
- package/esm/index.d.ts +16 -2
- package/esm/index.js +2 -1
- package/package.json +2 -2
- package/src/arg-types/fn-to-arg-types.ts +24 -0
- package/src/decorators/show_doc_source.tsx +7 -3
- package/src/index.ts +1 -0
package/esm/index.d.ts
CHANGED
|
@@ -2,12 +2,24 @@
|
|
|
2
2
|
import { UserConfig } from "htmlfy";
|
|
3
3
|
import { ReactNode } from "react";
|
|
4
4
|
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
5
|
+
import { AnyFunction, CreateTuple, IsStringLiteral, Properties, Tail } from "type-plus";
|
|
5
6
|
import { ClassNameProps, StyleProps } from "@just-web/css";
|
|
6
7
|
import { Args, DecoratorFunction, Renderer } from "storybook/internal/csf";
|
|
7
8
|
import { Decorator, Meta, StoryContext, StoryObj, StrictArgs } from "@storybook/react-vite";
|
|
8
|
-
import { IsStringLiteral } from "type-plus";
|
|
9
9
|
export * from "@repobuddy/test";
|
|
10
10
|
|
|
11
|
+
//#region src/arg-types/fn-to-arg-types.d.ts
|
|
12
|
+
/**
|
|
13
|
+
* Converts a function's parameter types to `Args` type for Storybook.
|
|
14
|
+
* Each name maps to the parameter type at the same index in F.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* type F = (a: number, b: string) => void
|
|
18
|
+
* type R = FnToArgTypes<F, ['x', 'y']> // { x: number; y: string }
|
|
19
|
+
*/
|
|
20
|
+
type FnToArgTypes<F extends AnyFunction, Names extends CreateTuple<Parameters<F>['length'], string> = CreateTuple<Parameters<F>['length'], string>> = Properties<ReduceToRecord<Parameters<F>, Names>>;
|
|
21
|
+
type ReduceToRecord<Params extends Array<any>, Names extends Array<any>> = Names['length'] extends 0 ? unknown : Names['length'] extends 1 ? Names extends [infer K extends string] ? { [I in K]: Params[0] } : never : Names extends [infer K extends string, ...infer Rest] ? { [I in K]: Params[0] } & ReduceToRecord<Tail<Params>, Rest> : never;
|
|
22
|
+
//#endregion
|
|
11
23
|
//#region src/components/show_html.d.ts
|
|
12
24
|
type ShowHtmlProps = ClassNameProps & StyleProps & {
|
|
13
25
|
selector?: string | undefined;
|
|
@@ -67,9 +79,11 @@ type StoryCardProps = {
|
|
|
67
79
|
* @param options - Options for the showDocSource decorator
|
|
68
80
|
* @param options.showOriginalSource - Whether to show the original source code in a card
|
|
69
81
|
* @param options.className - Class name to apply to the card
|
|
82
|
+
* @param options.source - Source code to show if provided.
|
|
70
83
|
* @returns A decorator function that shows the source code of a story above the rendered story
|
|
71
84
|
*/
|
|
72
85
|
declare function showDocSource<TRenderer extends Renderer = Renderer, TArgs = Args>(options?: Pick<StoryCardProps, 'className'> & {
|
|
86
|
+
source?: string | undefined;
|
|
73
87
|
showOriginalSource?: boolean | undefined;
|
|
74
88
|
}): DecoratorFunction<TRenderer, TArgs>;
|
|
75
89
|
//#endregion
|
|
@@ -786,4 +800,4 @@ type ExtendsStoryObj<S extends {
|
|
|
786
800
|
tags?: ExtractStringLiterals<NonNullable<S['tags']>[number]> extends infer MT ? IsStringLiteral<MT> extends true ? Array<(string & {}) | MT | E['tag']> | undefined : Array<(string & {}) | E['tag']> | undefined : never;
|
|
787
801
|
};
|
|
788
802
|
//#endregion
|
|
789
|
-
export { ActionsParam, BackgroundsParam, DocsParam, ExtendMeta, ExtendStoryObj, ExtendsMeta, ExtendsStoryObj, GlobalApiBackgroundsParam, GlobalApiViewportParam, LayoutParam, ShowHtml, ShowHtmlProps, SourceProps, StorySortParam, StorybookBuiltInParams, TestParam, Viewport, ViewportParam, WithStoryCardProps, defineActionsParam, defineBackgroundsParam, defineDocsParam, defineLayoutParam, defineParameters, defineTestParam, defineViewportParam, showDocSource, whenRunningInTest, withStoryCard };
|
|
803
|
+
export { ActionsParam, BackgroundsParam, DocsParam, ExtendMeta, ExtendStoryObj, ExtendsMeta, ExtendsStoryObj, FnToArgTypes, GlobalApiBackgroundsParam, GlobalApiViewportParam, LayoutParam, ShowHtml, ShowHtmlProps, SourceProps, StorySortParam, StorybookBuiltInParams, TestParam, Viewport, ViewportParam, WithStoryCardProps, defineActionsParam, defineBackgroundsParam, defineDocsParam, defineLayoutParam, defineParameters, defineTestParam, defineViewportParam, showDocSource, whenRunningInTest, withStoryCard };
|
package/esm/index.js
CHANGED
|
@@ -81,6 +81,7 @@ const channel = addons.getChannel();
|
|
|
81
81
|
* @param options - Options for the showDocSource decorator
|
|
82
82
|
* @param options.showOriginalSource - Whether to show the original source code in a card
|
|
83
83
|
* @param options.className - Class name to apply to the card
|
|
84
|
+
* @param options.source - Source code to show if provided.
|
|
84
85
|
* @returns A decorator function that shows the source code of a story above the rendered story
|
|
85
86
|
*/
|
|
86
87
|
function showDocSource(options) {
|
|
@@ -92,7 +93,7 @@ function showDocSource(options) {
|
|
|
92
93
|
channel.on("DARK_MODE", setIsDark);
|
|
93
94
|
return () => channel.off("DARK_MODE", setIsDark);
|
|
94
95
|
}, []);
|
|
95
|
-
const code = options?.showOriginalSource ? docs?.source?.originalSource : docs?.source?.code ?? docs?.source?.originalSource;
|
|
96
|
+
const code = options?.source ?? (options?.showOriginalSource ? docs?.source?.originalSource : docs?.source?.code ?? docs?.source?.originalSource);
|
|
96
97
|
const language = code === docs?.source?.originalSource ? void 0 : docs?.source?.language;
|
|
97
98
|
const isOriginalSource = code === docs?.source?.originalSource;
|
|
98
99
|
const content = /* @__PURE__ */ jsx(SyntaxHighlighter, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@repobuddy/storybook",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.0",
|
|
4
4
|
"description": "Storybook repo buddy",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"storybook",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"class-variance-authority": "^0.7.1",
|
|
56
56
|
"htmlfy": "^1.0.0",
|
|
57
57
|
"tailwind-merge": "^3.4.0",
|
|
58
|
-
"type-plus": "8.0.0-beta.
|
|
58
|
+
"type-plus": "8.0.0-beta.8"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@repobuddy/vitest": "^2.0.0",
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { AnyFunction, CreateTuple, Properties, Tail } from 'type-plus'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Converts a function's parameter types to `Args` type for Storybook.
|
|
5
|
+
* Each name maps to the parameter type at the same index in F.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* type F = (a: number, b: string) => void
|
|
9
|
+
* type R = FnToArgTypes<F, ['x', 'y']> // { x: number; y: string }
|
|
10
|
+
*/
|
|
11
|
+
export type FnToArgTypes<
|
|
12
|
+
F extends AnyFunction,
|
|
13
|
+
Names extends CreateTuple<Parameters<F>['length'], string> = CreateTuple<Parameters<F>['length'], string>
|
|
14
|
+
> = Properties<ReduceToRecord<Parameters<F>, Names>>
|
|
15
|
+
|
|
16
|
+
type ReduceToRecord<Params extends Array<any>, Names extends Array<any>> = Names['length'] extends 0
|
|
17
|
+
? unknown
|
|
18
|
+
: Names['length'] extends 1
|
|
19
|
+
? Names extends [infer K extends string]
|
|
20
|
+
? { [I in K]: Params[0] }
|
|
21
|
+
: never
|
|
22
|
+
: Names extends [infer K extends string, ...infer Rest]
|
|
23
|
+
? { [I in K]: Params[0] } & ReduceToRecord<Tail<Params>, Rest>
|
|
24
|
+
: never
|
|
@@ -15,10 +15,12 @@ const channel = addons.getChannel()
|
|
|
15
15
|
* @param options - Options for the showDocSource decorator
|
|
16
16
|
* @param options.showOriginalSource - Whether to show the original source code in a card
|
|
17
17
|
* @param options.className - Class name to apply to the card
|
|
18
|
+
* @param options.source - Source code to show if provided.
|
|
18
19
|
* @returns A decorator function that shows the source code of a story above the rendered story
|
|
19
20
|
*/
|
|
20
21
|
export function showDocSource<TRenderer extends Renderer = Renderer, TArgs = Args>(
|
|
21
22
|
options?: Pick<StoryCardProps, 'className'> & {
|
|
23
|
+
source?: string | undefined
|
|
22
24
|
showOriginalSource?: boolean | undefined
|
|
23
25
|
}
|
|
24
26
|
): DecoratorFunction<TRenderer, TArgs> {
|
|
@@ -34,9 +36,11 @@ export function showDocSource<TRenderer extends Renderer = Renderer, TArgs = Arg
|
|
|
34
36
|
return () => channel.off('DARK_MODE', setIsDark)
|
|
35
37
|
}, [])
|
|
36
38
|
|
|
37
|
-
const code =
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
const code =
|
|
40
|
+
options?.source ??
|
|
41
|
+
(options?.showOriginalSource
|
|
42
|
+
? docs?.source?.originalSource
|
|
43
|
+
: (docs?.source?.code ?? docs?.source?.originalSource))
|
|
40
44
|
|
|
41
45
|
const language = code === docs?.source?.originalSource ? undefined : docs?.source?.language
|
|
42
46
|
|