@repobuddy/storybook 2.19.1 → 2.20.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 +2 -2
- package/esm/index.js +3 -2
- package/package.json +5 -1
- package/src/decorators/show_doc_source.tsx +7 -6
package/esm/index.d.ts
CHANGED
|
@@ -110,12 +110,12 @@ declare function StoryCard({
|
|
|
110
110
|
* @param options - Options for the showDocSource decorator
|
|
111
111
|
* @param options.showOriginalSource - Whether to show the original source code in a card
|
|
112
112
|
* @param options.className - Class name to apply to the card
|
|
113
|
-
* @param options.source - Source code to show
|
|
113
|
+
* @param options.source - Source code to show. Can be a string, or a function `(originalSource) => string` that receives the story's original source and returns the code to display.
|
|
114
114
|
* @param options.placement - Where to show the source code relative to the story.
|
|
115
115
|
* @returns A decorator function that shows the source code of a story above or below the rendered story
|
|
116
116
|
*/
|
|
117
117
|
declare function showDocSource<TRenderer extends Renderer = Renderer, TArgs = Args>(options?: Pick<StoryCardProps, 'className'> & {
|
|
118
|
-
source?: string | undefined;
|
|
118
|
+
source?: ((source: string | undefined) => string) | string | undefined;
|
|
119
119
|
showOriginalSource?: boolean | undefined;
|
|
120
120
|
/**
|
|
121
121
|
* Where to show the source code relative to the story.
|
package/esm/index.js
CHANGED
|
@@ -168,7 +168,7 @@ const channel = addons.getChannel();
|
|
|
168
168
|
* @param options - Options for the showDocSource decorator
|
|
169
169
|
* @param options.showOriginalSource - Whether to show the original source code in a card
|
|
170
170
|
* @param options.className - Class name to apply to the card
|
|
171
|
-
* @param options.source - Source code to show
|
|
171
|
+
* @param options.source - Source code to show. Can be a string, or a function `(originalSource) => string` that receives the story's original source and returns the code to display.
|
|
172
172
|
* @param options.placement - Where to show the source code relative to the story.
|
|
173
173
|
* @returns A decorator function that shows the source code of a story above or below the rendered story
|
|
174
174
|
*/
|
|
@@ -181,7 +181,8 @@ function showDocSource(options) {
|
|
|
181
181
|
channel.on("DARK_MODE", setIsDark);
|
|
182
182
|
return () => channel.off("DARK_MODE", setIsDark);
|
|
183
183
|
}, []);
|
|
184
|
-
const
|
|
184
|
+
const originalSource = options?.showOriginalSource ? docs?.source?.originalSource : docs?.source?.code ?? docs?.source?.originalSource;
|
|
185
|
+
const code = typeof options?.source === "function" ? options?.source(originalSource) : options?.source ?? originalSource;
|
|
185
186
|
const language = code === docs?.source?.originalSource ? void 0 : docs?.source?.language;
|
|
186
187
|
const isOriginalSource = code === docs?.source?.originalSource;
|
|
187
188
|
const sourceContent = /* @__PURE__ */ jsx(SyntaxHighlighter, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@repobuddy/storybook",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.20.0",
|
|
4
4
|
"description": "Storybook repo buddy",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"storybook",
|
|
@@ -100,12 +100,16 @@
|
|
|
100
100
|
"peerDependencies": {
|
|
101
101
|
"@storybook-community/storybook-dark-mode": "^7.0.0",
|
|
102
102
|
"@storybook/addon-docs": "^10.2.4",
|
|
103
|
+
"@types/react": ">= 16",
|
|
103
104
|
"storybook-addon-tag-badges": "^3.0.2"
|
|
104
105
|
},
|
|
105
106
|
"peerDependenciesMeta": {
|
|
106
107
|
"@storybook-community/storybook-dark-mode": {
|
|
107
108
|
"optional": true
|
|
108
109
|
},
|
|
110
|
+
"@types/react": {
|
|
111
|
+
"optional": true
|
|
112
|
+
},
|
|
109
113
|
"storybook-addon-tag-badges": {
|
|
110
114
|
"optional": true
|
|
111
115
|
}
|
|
@@ -16,13 +16,13 @@ const channel = addons.getChannel()
|
|
|
16
16
|
* @param options - Options for the showDocSource decorator
|
|
17
17
|
* @param options.showOriginalSource - Whether to show the original source code in a card
|
|
18
18
|
* @param options.className - Class name to apply to the card
|
|
19
|
-
* @param options.source - Source code to show
|
|
19
|
+
* @param options.source - Source code to show. Can be a string, or a function `(originalSource) => string` that receives the story's original source and returns the code to display.
|
|
20
20
|
* @param options.placement - Where to show the source code relative to the story.
|
|
21
21
|
* @returns A decorator function that shows the source code of a story above or below the rendered story
|
|
22
22
|
*/
|
|
23
23
|
export function showDocSource<TRenderer extends Renderer = Renderer, TArgs = Args>(
|
|
24
24
|
options?: Pick<StoryCardProps, 'className'> & {
|
|
25
|
-
source?: string | undefined
|
|
25
|
+
source?: ((source: string | undefined) => string) | string | undefined
|
|
26
26
|
showOriginalSource?: boolean | undefined
|
|
27
27
|
/**
|
|
28
28
|
* Where to show the source code relative to the story.
|
|
@@ -44,11 +44,12 @@ export function showDocSource<TRenderer extends Renderer = Renderer, TArgs = Arg
|
|
|
44
44
|
return () => channel.off('DARK_MODE', setIsDark)
|
|
45
45
|
}, [])
|
|
46
46
|
|
|
47
|
+
const originalSource = options?.showOriginalSource
|
|
48
|
+
? docs?.source?.originalSource
|
|
49
|
+
: (docs?.source?.code ?? docs?.source?.originalSource)
|
|
50
|
+
|
|
47
51
|
const code =
|
|
48
|
-
options?.source ??
|
|
49
|
-
(options?.showOriginalSource
|
|
50
|
-
? docs?.source?.originalSource
|
|
51
|
-
: (docs?.source?.code ?? docs?.source?.originalSource))
|
|
52
|
+
typeof options?.source === 'function' ? options?.source(originalSource) : (options?.source ?? originalSource)
|
|
52
53
|
|
|
53
54
|
const language = code === docs?.source?.originalSource ? undefined : docs?.source?.language
|
|
54
55
|
|