storybook-addon-dependency-previews 0.1.2 → 0.3.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.
Files changed (110) hide show
  1. package/README.md +327 -24
  2. package/dist/_virtual/{_rolldown/runtime.cjs → rolldown_runtime.cjs} +7 -11
  3. package/dist/addon/index.cjs +6 -1
  4. package/dist/addon/index.cjs.map +1 -1
  5. package/dist/addon/index.d.cts +2 -1
  6. package/dist/addon/index.d.mts +2 -1
  7. package/dist/addon/index.mjs +4 -1
  8. package/dist/addon/index.mjs.map +1 -1
  9. package/dist/addon/preset.cjs +0 -1
  10. package/dist/addon/preset.cjs.map +1 -1
  11. package/dist/addon/preset.mjs.map +1 -1
  12. package/dist/addon/vitePlugin.cjs +3 -2
  13. package/dist/addon/vitePlugin.cjs.map +1 -1
  14. package/dist/blocks/DependencyPreviews.cjs +3 -2
  15. package/dist/blocks/DependencyPreviews.cjs.map +1 -1
  16. package/dist/blocks/DependencyPreviews.d.cts +2 -2
  17. package/dist/blocks/DependencyPreviews.d.mts +2 -2
  18. package/dist/cli/sb-deps.cjs +464 -31
  19. package/dist/cli/sb-deps.cjs.map +1 -1
  20. package/dist/cli/sb-deps.mjs +455 -27
  21. package/dist/cli/sb-deps.mjs.map +1 -1
  22. package/dist/cli/scripts/depcruise.config.cjs.map +1 -1
  23. package/dist/cli/scripts/depcruise.config.mjs.map +1 -1
  24. package/dist/cli/scripts/postprocess.cjs +16 -6
  25. package/dist/cli/scripts/postprocess.cjs.map +1 -1
  26. package/dist/cli/scripts/postprocess.mjs +10 -3
  27. package/dist/cli/scripts/postprocess.mjs.map +1 -1
  28. package/dist/components/ComponentSourceLink.cjs +3 -2
  29. package/dist/components/ComponentSourceLink.cjs.map +1 -1
  30. package/dist/components/CopyButton.cjs +4 -2
  31. package/dist/components/CopyButton.cjs.map +1 -1
  32. package/dist/components/Expandable.cjs +4 -2
  33. package/dist/components/Expandable.cjs.map +1 -1
  34. package/dist/components/FullParityStory.cjs +6 -5
  35. package/dist/components/FullParityStory.cjs.map +1 -1
  36. package/dist/components/PathCopyMolecule.cjs +3 -2
  37. package/dist/components/PathCopyMolecule.cjs.map +1 -1
  38. package/dist/components/PrimaryPreview.cjs +3 -1
  39. package/dist/components/PrimaryPreview.cjs.map +1 -1
  40. package/dist/components/SbHeading.cjs +4 -4
  41. package/dist/components/SbHeading.cjs.map +1 -1
  42. package/dist/components/SbHeading.mjs +1 -2
  43. package/dist/components/SbHeading.mjs.map +1 -1
  44. package/dist/components/StoryLink.cjs +6 -4
  45. package/dist/components/StoryLink.cjs.map +1 -1
  46. package/dist/components/TooltipTrigger.cjs +4 -2
  47. package/dist/components/TooltipTrigger.cjs.map +1 -1
  48. package/dist/components/icons/ArrowToRectangleIcon.cjs +2 -1
  49. package/dist/components/icons/ArrowToRectangleIcon.cjs.map +1 -1
  50. package/dist/components/icons/BuildIcon.cjs +2 -1
  51. package/dist/components/icons/BuildIcon.cjs.map +1 -1
  52. package/dist/components/icons/CopyIcon.cjs +2 -1
  53. package/dist/components/icons/CopyIcon.cjs.map +1 -1
  54. package/dist/components/icons/CubeIcon.cjs +2 -1
  55. package/dist/components/icons/CubeIcon.cjs.map +1 -1
  56. package/dist/components/icons/DoubleChevronDown.cjs +2 -1
  57. package/dist/components/icons/DoubleChevronDown.cjs.map +1 -1
  58. package/dist/components/icons/ExternalLinkIcon.cjs +2 -1
  59. package/dist/components/icons/ExternalLinkIcon.cjs.map +1 -1
  60. package/dist/components/icons/EyeOpen.cjs +2 -1
  61. package/dist/components/icons/EyeOpen.cjs.map +1 -1
  62. package/dist/components/icons/LoadingRipples.cjs +2 -1
  63. package/dist/components/icons/LoadingRipples.cjs.map +1 -1
  64. package/dist/components/icons/SquaresPlus.cjs +2 -1
  65. package/dist/components/icons/SquaresPlus.cjs.map +1 -1
  66. package/dist/components/icons/Svg.cjs +3 -2
  67. package/dist/components/icons/Svg.cjs.map +1 -1
  68. package/dist/components/icons/Svg.mjs +1 -1
  69. package/dist/components/icons/Svg.mjs.map +1 -1
  70. package/dist/components/icons/X.cjs +2 -1
  71. package/dist/components/icons/X.cjs.map +1 -1
  72. package/dist/config.cjs +9 -0
  73. package/dist/config.cjs.map +1 -0
  74. package/dist/config.d.cts +107 -0
  75. package/dist/config.d.mts +107 -0
  76. package/dist/config.mjs +8 -0
  77. package/dist/config.mjs.map +1 -0
  78. package/dist/hooks/useDependencyGraph.cjs +4 -2
  79. package/dist/hooks/useDependencyGraph.cjs.map +1 -1
  80. package/dist/hooks/useDependencyGraph.mjs +1 -1
  81. package/dist/hooks/useDependencyGraph.mjs.map +1 -1
  82. package/dist/hooks/useDynamicStory.cjs +2 -1
  83. package/dist/hooks/useDynamicStory.cjs.map +1 -1
  84. package/dist/hooks/useDynamicStory.mjs.map +1 -1
  85. package/dist/hooks/useStoryParams.cjs +4 -3
  86. package/dist/hooks/useStoryParams.cjs.map +1 -1
  87. package/dist/index.cjs +0 -1
  88. package/dist/index.d.cts +4 -2
  89. package/dist/index.d.mts +4 -2
  90. package/dist/manager.cjs +4 -1
  91. package/dist/manager.cjs.map +1 -1
  92. package/dist/panels/DefaultAutoDocsLayout.cjs +10 -8
  93. package/dist/panels/DefaultAutoDocsLayout.cjs.map +1 -1
  94. package/dist/panels/DefaultAutoDocsLayout.d.cts +3 -2
  95. package/dist/panels/DefaultAutoDocsLayout.d.mts +3 -2
  96. package/dist/panels/DefaultAutoDocsLayout.mjs.map +1 -1
  97. package/dist/panels/GraphView.cjs +3 -1
  98. package/dist/panels/GraphView.cjs.map +1 -1
  99. package/dist/panels/GraphView.d.cts +2 -2
  100. package/dist/panels/GraphView.d.mts +2 -2
  101. package/dist/panels/GraphView.mjs.map +1 -1
  102. package/dist/preview.cjs +7 -11
  103. package/dist/preview.cjs.map +1 -1
  104. package/dist/preview.d.cts +2 -3
  105. package/dist/preview.d.mts +2 -3
  106. package/dist/preview.mjs +6 -10
  107. package/dist/preview.mjs.map +1 -1
  108. package/dist/types.d.cts +14 -1
  109. package/dist/types.d.mts +14 -1
  110. package/package.json +12 -7
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Storybook Add On - Dependency Previews
2
2
 
3
- [![Dependency Previews logo](https://github.com/Dan503/storybook-addon-dependency-previews/raw/main/storybook-addon-package/readme-images/dependency-previews-logo.png)](https://dependency-previews-storybook.netlify.app/?path=/docs/04-templates-home-template--docs)
3
+ [![Dependency Previews logo](https://github.com/Dan503/storybook-addon-dependency-previews/raw/main/storybook-addon-package/readme-images/dependency-previews-logo.png)](https://dependency-previews-storybook-react.netlify.app/?path=/docs/04-templates-home-template--docs)
4
4
 
5
5
  ## What is this?
6
6
 
@@ -8,6 +8,8 @@
8
8
 
9
9
  A plugin for [Storybook](https://storybook.js.org/) that shows the full dependency tree in both directions (built with and used by) the components in your application.
10
10
 
11
+ Currently works with **React**, **Svelte**, and **Angular**.
12
+
11
13
  This is what you will see in Storybook after Dependency Previews have been installed and configured:
12
14
 
13
15
  ![Dependency Previews - all closed](https://github.com/Dan503/storybook-addon-dependency-previews/raw/main/storybook-addon-package/readme-images/all-closed.png)
@@ -16,11 +18,25 @@ The below image demonstrates what you will see when you open up some of the depe
16
18
 
17
19
  ![Dependency Previews - all open](https://github.com/Dan503/storybook-addon-dependency-previews/raw/main/storybook-addon-package/readme-images/all-open.png)
18
20
 
19
- See the dependency previews add on in action at the [Storybook addon demo site](https://dependency-previews-storybook.netlify.app/?path=/docs/04-templates-home-template--docs).
21
+ ### Demos
22
+
23
+ #### React demos
24
+
25
+ - [React Storybook demo site](https://dependency-previews-storybook-react.netlify.app/?path=/docs/04-templates-home-template--docs)
26
+ - [React rendered example website](https://dependency-previews-demo-site-react.netlify.app/)
27
+ - [React demo source code](https://github.com/Dan503/storybook-addon-dependency-previews/tree/main/example-site/react)
28
+
29
+ #### Svelte demos
20
30
 
21
- You can also [visit the example website](https://dependency-previews-demo-site.netlify.app/) that the Storybook demo is built for.
31
+ - [Svelte Storybook demo site](https://dependency-previews-storybook-svelte.netlify.app/)
32
+ - [Svelte rendered example website](https://dependency-previews-demo-site-svelte.netlify.app/)
33
+ - [Svelte demo source code](https://github.com/Dan503/storybook-addon-dependency-previews/tree/main/example-site/svelte)
22
34
 
23
- Also [visit the npm page](https://www.npmjs.com/package/storybook-addon-dependency-previews) if you are reading this on GitHub
35
+ #### Angular demos
36
+
37
+ - [Angular Storybook demo site](https://dependency-previews-storybook-angular.netlify.app/?path=/docs/04-templates-home-template--docs)
38
+ - [Angular rendered example website](https://dependency-previews-demo-site-angular.netlify.app/)
39
+ - [Angular demo source code](https://github.com/Dan503/storybook-addon-dependency-previews/tree/main/example-site/angular)
24
40
 
25
41
  <!-- TODO: Provide a video/gif of the addon in action -->
26
42
 
@@ -28,18 +44,18 @@ Also [visit the npm page](https://www.npmjs.com/package/storybook-addon-dependen
28
44
 
29
45
  ### Package download
30
46
 
31
- First you will need to install the plugin via npm
47
+ First you will need to install the plugin via npm as well as [dependency-cruiser](https://www.npmjs.com/package/dependency-cruiser)
32
48
 
33
49
  ```
34
- npm install storybook-addon-dependency-previews
50
+ npm install -D storybook-addon-dependency-previews dependency-cruiser
35
51
  ```
36
52
 
37
53
  <details>
38
54
  <summary>Other package managers</summary>
39
- <p><pre><code>pnpm add storybook-addon-dependency-previews</code></pre></p>
40
- <p><pre><code>yarn add storybook-addon-dependency-previews</code></pre></p>
41
- <p><pre><code>bun add storybook-addon-dependency-previews</code></pre></p>
42
- <p><pre><code>deno add npm:storybook-addon-dependency-previews</code></pre></p>
55
+ <p><pre><code>pnpm add -D storybook-addon-dependency-previews dependency-cruiser</code></pre></p>
56
+ <p><pre><code>yarn add -D storybook-addon-dependency-previews dependency-cruiser</code></pre></p>
57
+ <p><pre><code>bun add -D storybook-addon-dependency-previews dependency-cruiser</code></pre></p>
58
+ <p><pre><code>deno add --dev npm:storybook-addon-dependency-previews npm:dependency-cruiser</code></pre></p>
43
59
  </details>
44
60
 
45
61
  ### Register the add-on
@@ -48,12 +64,13 @@ From your root folder, open your `.storybook/main.ts` file.
48
64
 
49
65
  Edit the `main.ts` to contain the following values or copy/paste the below to replace the full contents of the main.ts file.
50
66
 
67
+ #### Register with React
68
+
51
69
  ```ts
52
- import { StorybookConfig } from '@storybook/react-vite'
70
+ import type { StorybookConfig } from '@storybook/react-vite'
53
71
 
54
72
  const config: StorybookConfig = {
55
- // tells storybook what files to look for when it goes searching for story files
56
- stories: ['../src/**/*.stories.@(ts|tsx|mdx|svelte|vue)'],
73
+ stories: ['../src/**/*.stories.@(ts|tsx|mdx)'],
57
74
  addons: [
58
75
  // autodocs is required for this addon to work
59
76
  '@storybook/addon-docs',
@@ -61,8 +78,6 @@ const config: StorybookConfig = {
61
78
  'storybook-addon-dependency-previews/addon',
62
79
  ],
63
80
  framework: {
64
- // The framework that storybook uses to read story components
65
- // Use @storybook/*-vite for your framework of choice
66
81
  name: '@storybook/react-vite',
67
82
  options: {},
68
83
  },
@@ -71,14 +86,122 @@ const config: StorybookConfig = {
71
86
  export default config
72
87
  ```
73
88
 
89
+ #### Register with Svelte
90
+
91
+ ```ts
92
+ import type { StorybookConfig } from '@storybook/sveltekit'
93
+
94
+ const config: StorybookConfig = {
95
+ stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|ts|svelte)'],
96
+ addons: [
97
+ // autodocs is required for this addon to work
98
+ '@storybook/addon-docs',
99
+ // required for .stories.svelte CSF format
100
+ '@storybook/addon-svelte-csf',
101
+ // the storybook dependency previews addon registration
102
+ 'storybook-addon-dependency-previews/addon',
103
+ ],
104
+ framework: '@storybook/sveltekit',
105
+ }
106
+
107
+ export default config
108
+ ```
109
+
110
+ #### Register with Angular
111
+
112
+ `@storybook/angular` uses webpack5 exclusively. The addon requires two webpack additions in `webpackFinal`: a `DefinePlugin` to inject `__PROJECT_ROOT__` (needed for the VS Code "open file" feature), and a `NormalModuleFactory` plugin to handle the addon's CSS modules correctly.
113
+
114
+ You will also need a `css-modules-loader.cjs` file alongside your `.storybook/main.ts`. Copy it from the [Angular example source](https://github.com/Dan503/storybook-addon-dependency-previews/blob/main/example-site/angular/.storybook/css-modules-loader.cjs).
115
+
116
+ ```ts
117
+ import type { StorybookConfig } from '@storybook/angular'
118
+ import { createRequire } from 'module'
119
+ import { fileURLToPath } from 'url'
120
+ import path from 'path'
121
+
122
+ const require = createRequire(import.meta.url)
123
+
124
+ const config: StorybookConfig = {
125
+ stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
126
+ addons: [
127
+ // autodocs is required for this addon to work
128
+ '@storybook/addon-docs',
129
+ // the storybook dependency previews addon registration
130
+ 'storybook-addon-dependency-previews/addon',
131
+ ],
132
+ framework: {
133
+ name: '@storybook/angular',
134
+ options: {},
135
+ },
136
+ webpackFinal: async (config) => {
137
+ const sbAngularRequire = createRequire(
138
+ import.meta.resolve('@storybook/angular'),
139
+ )
140
+ const webpack = sbAngularRequire('webpack') as any
141
+
142
+ // Path to the css-modules-loader.cjs file (copy from the Angular example source)
143
+ const cssModulesLoader = fileURLToPath(
144
+ new URL('./css-modules-loader.cjs', import.meta.url),
145
+ )
146
+
147
+ config.plugins = config.plugins ?? []
148
+
149
+ // Inject __PROJECT_ROOT__ so preview.ts can pass it to projectRootPath
150
+ config.plugins.push(
151
+ new webpack.DefinePlugin({
152
+ __PROJECT_ROOT__: JSON.stringify(
153
+ path.resolve(fileURLToPath(new URL('..', import.meta.url))),
154
+ ),
155
+ }),
156
+ )
157
+
158
+ // Handle CSS modules for the addon's dist files
159
+ config.plugins.push({
160
+ apply(compiler: any) {
161
+ compiler.hooks.normalModuleFactory.tap(
162
+ 'AddonCssModules',
163
+ (factory: any) => {
164
+ factory.hooks.afterResolve.tap(
165
+ 'AddonCssModules',
166
+ (resolveData: any) => {
167
+ const resource: string =
168
+ resolveData.createData?.resource ?? ''
169
+ if (
170
+ resource.endsWith('.module.css') &&
171
+ resource.includes(
172
+ 'storybook-addon-dependency-previews',
173
+ )
174
+ ) {
175
+ resolveData.createData.loaders = [
176
+ {
177
+ loader: cssModulesLoader,
178
+ options: {},
179
+ },
180
+ ]
181
+ }
182
+ },
183
+ )
184
+ },
185
+ )
186
+ },
187
+ })
188
+
189
+ return config
190
+ },
191
+ }
192
+ export default config
193
+ ```
194
+
74
195
  ### Bare minimum storybook story example
75
196
 
76
197
  Get a story ready so you have something to test with.
77
198
 
78
199
  Below is the bare minimum needed to generate a viable story that is compatible with the add-on.
79
200
 
201
+ #### React `.stories.tsx` file example
202
+
80
203
  ```ts
81
- import type { Meta } from '@storybook/react-vite'
204
+ import type { Meta, StoryObj } from '@storybook/react-vite'
82
205
  import { ComponentName } from './ComponentName'
83
206
 
84
207
  const meta: Meta<typeof ComponentName> = {
@@ -104,6 +227,56 @@ export const Primary: Story = {
104
227
  }
105
228
  ```
106
229
 
230
+ #### Svelte `.stories.svelte` file using [Svelte CSF](https://github.com/storybookjs/addon-svelte-csf)
231
+
232
+ ```svelte
233
+ <script module>
234
+ import { defineMeta } from '@storybook/addon-svelte-csf'
235
+ import ComponentName from './ComponentName.svelte'
236
+
237
+ const { Story } = defineMeta({
238
+ title: 'Component Name',
239
+ component: ComponentName,
240
+ // autodocs tag is required
241
+ tags: ['autodocs'],
242
+ // The `__filePath` property must be applied to every story file
243
+ parameters: {
244
+ __filePath: import.meta.url,
245
+ },
246
+ })
247
+ </script>
248
+
249
+ <Story name="Primary" />
250
+ ```
251
+
252
+ #### Angular `.stories.ts` file example
253
+
254
+ ```ts
255
+ import type { Meta, StoryObj } from '@storybook/angular'
256
+ import type { StoryParameters } from 'storybook-addon-dependency-previews'
257
+ import { ComponentName } from './ComponentName.component'
258
+
259
+ const meta: Meta<ComponentName> = {
260
+ // You can use spaces here to make the title of the story page more human readable
261
+ title: 'Component Name',
262
+ component: ComponentName,
263
+ // autodocs tag is required
264
+ tags: ['autodocs'],
265
+ // The `__filePath` property must be applied to every story file
266
+ // for the addon to track dependencies effectively
267
+ // `import.meta.url` is a webpack feature available in Angular Storybook
268
+ parameters: {
269
+ __filePath: import.meta.url,
270
+ } satisfies StoryParameters,
271
+ }
272
+
273
+ export default meta
274
+
275
+ type Story = StoryObj<ComponentName>
276
+
277
+ export const Primary: Story = {}
278
+ ```
279
+
107
280
  ### package.json scripts
108
281
 
109
282
  You will need the following scripts in your `package.json` file:
@@ -133,18 +306,27 @@ Don't run any of these yet, you are not finished with the installation.
133
306
 
134
307
  `npm run sb:alt-port` (optional) will run storybook in watch mode and run it using a specific port number.
135
308
 
136
- ### Create the preview.tsx file
309
+ #### Angular projects
310
+
311
+ `@storybook/angular@10+` requires Storybook to be launched through the Angular CLI builder rather than the default `storybook dev` command. Pass the Angular CLI target as an argument to `--run-storybook`:
312
+
313
+ ```json
314
+ "sb": "sb-deps --watch --run-storybook \"ng run <project-name>:storybook\""
315
+ ```
316
+
317
+ Replace `<project-name>` with the name of your Angular project as defined in `angular.json`.
318
+
319
+ ### Create the preview file
137
320
 
138
321
  First run `npm run sb:deps` to generate a fresh `dependency-previews.json` file in the `.storybook` folder.
139
322
 
140
323
  Make sure that the `"resolveJsonModule"` tsConfig.json setting is set to `true` to import this file.
141
324
 
142
- Now create a `preview.tsx` file in the `.storybook` folder with the following content:
325
+ Now create a `.storybook/preview.ts` file (or `preview.tsx` if your framework requires JSX) with the following content:
143
326
 
144
- ```tsx
327
+ ```ts
145
328
  /// <reference types="vite/client" />
146
329
 
147
- import * as React from 'react'
148
330
  import {
149
331
  defaultPreviewParameters,
150
332
  dependencyPreviewDecorators,
@@ -154,7 +336,7 @@ import {
154
336
  // Import the generated dependency-previews.json file
155
337
  import dependenciesJson from './dependency-previews.json'
156
338
 
157
- // Global styles are imported here
339
+ // Global styles are imported here (optional)
158
340
  import '../src/styles.css'
159
341
 
160
342
  const previewConfig: StorybookPreviewConfig = {
@@ -167,10 +349,10 @@ const previewConfig: StorybookPreviewConfig = {
167
349
  '/src/**/*.stories.@(tsx|ts|jsx|js|svelte)',
168
350
  { eager: false },
169
351
  ),
170
- // Replace this with the base url of your git repository
171
- // This enables the addon to link to the source code of the component
352
+ // Replace this with the URL to your src folder in your git repository.
353
+ // This enables the addon to link to the source code of the component.
172
354
  sourceRootUrl:
173
- 'https://github.com/Dan503/storybook-addon-dependency-previews/blob/main/example-site',
355
+ 'https://github.com/your-org/your-repo/blob/main/src',
174
356
  // This allows Source File Path to open the
175
357
  // component file directly in VS Code when
176
358
  // running in a local host environment.
@@ -183,6 +365,43 @@ const previewConfig: StorybookPreviewConfig = {
183
365
  export default previewConfig
184
366
  ```
185
367
 
368
+ #### Angular `preview.ts`
369
+
370
+ Angular uses webpack, so `import.meta.glob` and Vite-specific APIs are not available. Use the `__PROJECT_ROOT__` value injected via `DefinePlugin` in `main.ts` instead:
371
+
372
+ ```ts
373
+ import type { Preview } from '@storybook/angular'
374
+ import {
375
+ defaultPreviewParameters,
376
+ dependencyPreviewDecorators,
377
+ } from 'storybook-addon-dependency-previews'
378
+ import dependenciesJson from './dependency-previews.json'
379
+
380
+ declare const __PROJECT_ROOT__: string
381
+
382
+ const preview: Preview = {
383
+ parameters: {
384
+ ...defaultPreviewParameters,
385
+ dependencyPreviews: {
386
+ dependenciesJson,
387
+ // Replace this with the URL to your src folder in your git repository.
388
+ // This enables the addon to link to the source code of the component.
389
+ sourceRootUrl:
390
+ 'https://github.com/your-org/your-repo/blob/main/src',
391
+ // __PROJECT_ROOT__ is injected by DefinePlugin in main.ts.
392
+ // This allows Source File Path to open the component file
393
+ // directly in VS Code when running in a local host environment.
394
+ projectRootPath: __PROJECT_ROOT__,
395
+ },
396
+ },
397
+ decorators: [...dependencyPreviewDecorators],
398
+ }
399
+
400
+ export default preview
401
+ ```
402
+
403
+ > **Note:** Angular does not use `storyModules` (no `import.meta.glob`). The addon still generates the full dependency tree via the CLI — only the VS Code "open file" shortcut needs `projectRootPath`.
404
+
186
405
  ### Run it!
187
406
 
188
407
  You should be all set now.
@@ -192,3 +411,87 @@ Try running `npm run sb` to boot up storybook, leave it running as you work.
192
411
  As you create new component files, the component will be auto-scaffolded for you and a matching story file will be created for it automatically. The dependency previews json file will also be auto-updated.
193
412
 
194
413
  This workflow allows you to focus on what matters instead of having to waste time writing lots of boilerplate code every time you want to create a new component.
414
+
415
+ ## Configuration file (optional)
416
+
417
+ The `sb-deps` CLI can be customized via a `sb-deps.config.mjs` file in your project root (alongside `package.json`). Supported formats: `.mjs`, `.js`, or `.cjs`.
418
+
419
+ Use the `defineSbDepsConfig` helper from `storybook-addon-dependency-previews/config` for type safety and editor autocomplete:
420
+
421
+ ```js
422
+ // sb-deps.config.mjs
423
+ import { defineSbDepsConfig } from 'storybook-addon-dependency-previews/config'
424
+
425
+ export default defineSbDepsConfig({
426
+ // options go here
427
+ })
428
+ ```
429
+
430
+ ### `angularSelectorPrefix`
431
+
432
+ _(Angular only)_ The prefix prepended to Angular component selectors when auto-scaffolding new components.
433
+
434
+ **Default:** `'app-'`
435
+
436
+ | Value | Resulting selector |
437
+ | ------------------ | ------------------ |
438
+ | `'app-'` (default) | `app-button-atom` |
439
+ | `'my-'` | `my-button-atom` |
440
+ | `''` | `button-atom` |
441
+
442
+ ```js
443
+ // sb-deps.config.mjs
444
+ import { defineSbDepsConfig } from 'storybook-addon-dependency-previews/config'
445
+
446
+ export default defineSbDepsConfig({
447
+ angularSelectorPrefix: '', // no prefix
448
+ })
449
+ ```
450
+
451
+ ### `scaffold`
452
+
453
+ Override the templates used when `sb-deps` auto-scaffolds new component and story files. Each template function receives a context object with relevant variables and must return the full file content as a string.
454
+
455
+ ```js
456
+ // sb-deps.config.mjs
457
+ import { defineSbDepsConfig } from 'storybook-addon-dependency-previews/config'
458
+
459
+ export default defineSbDepsConfig({
460
+ scaffold: {
461
+ react: {
462
+ /** Customize the generated .tsx component file */
463
+ component: ({ componentName, propsName }) =>
464
+ `export interface ${propsName} {}
465
+
466
+ export function ${componentName}({}: ${propsName}) {
467
+ return <div>${componentName}</div>
468
+ }
469
+ `,
470
+ /** Customize the generated .stories.tsx file */
471
+ story: ({ componentName, propsName, title, tags, base }) => '...',
472
+ },
473
+ svelte: {
474
+ /** Customize the generated .svelte component file */
475
+ component: ({ componentName }) => '...',
476
+ /** Customize the generated .stories.svelte file */
477
+ story: ({ componentName, title, tags }) => '...',
478
+ },
479
+ angular: {
480
+ /** Customize the generated .component.ts file */
481
+ component: ({
482
+ componentName,
483
+ className,
484
+ selector,
485
+ base,
486
+ templateLocation,
487
+ }) => '...',
488
+ /** Customize the generated .component.html file (external templates only) */
489
+ componentHtml: ({ componentName }) => '...',
490
+ /** Customize the generated .stories.ts file */
491
+ story: ({ componentName, className, base, title, tags }) => '...',
492
+ },
493
+ },
494
+ })
495
+ ```
496
+
497
+ All scaffold options are optional — omit any key to keep the default template for that file type.
@@ -1,4 +1,4 @@
1
- //#region \0rolldown/runtime.js
1
+ //#region rolldown:runtime
2
2
  var __create = Object.create;
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -6,16 +6,12 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
8
  var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") {
10
- for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
- key = keys[i];
12
- if (!__hasOwnProp.call(to, key) && key !== except) {
13
- __defProp(to, key, {
14
- get: ((k) => from[k]).bind(null, key),
15
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
- });
17
- }
18
- }
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
19
15
  }
20
16
  return to;
21
17
  };
@@ -1,12 +1,17 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
2
  const require_addon_vitePlugin = require('./vitePlugin.cjs');
3
+ let module$1 = require("module");
4
+ module$1 = require_rolldown_runtime.__toESM(module$1);
3
5
 
4
6
  //#region src/addon/index.ts
7
+ const require$1 = (0, module$1.createRequire)(require("url").pathToFileURL(__filename).href);
8
+ const managerEntries = [require$1.resolve("../manager.mjs")];
5
9
  async function viteFinal(config) {
6
10
  config.plugins = [...config.plugins ?? [], require_addon_vitePlugin.sbDepsVitePlugin()];
7
11
  return config;
8
12
  }
9
13
 
10
14
  //#endregion
15
+ exports.managerEntries = managerEntries;
11
16
  exports.viteFinal = viteFinal;
12
17
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["sbDepsVitePlugin"],"sources":["../../src/addon/index.ts"],"sourcesContent":["import { sbDepsVitePlugin } from './vitePlugin'\n\nexport async function viteFinal(config: any) {\n\tconfig.plugins = [...(config.plugins ?? []), sbDepsVitePlugin()]\n\treturn config\n}\n"],"mappings":";;;;AAEA,eAAsB,UAAU,QAAa;AAC5C,QAAO,UAAU,CAAC,GAAI,OAAO,WAAW,EAAE,EAAGA,2CAAkB,CAAC;AAChE,QAAO"}
1
+ {"version":3,"file":"index.cjs","names":["require","sbDepsVitePlugin"],"sources":["../../src/addon/index.ts"],"sourcesContent":["import { createRequire } from 'module'\nimport { sbDepsVitePlugin } from './vitePlugin'\n\nconst require = createRequire(import.meta.url)\n\nexport const managerEntries = [require.resolve('../manager.mjs')]\n\nexport async function viteFinal(config: any) {\n\tconfig.plugins = [...(config.plugins ?? []), sbDepsVitePlugin()]\n\treturn config\n}\n"],"mappings":";;;;;;AAGA,MAAMA,sFAAwC;AAE9C,MAAa,iBAAiB,CAACA,UAAQ,QAAQ,iBAAiB,CAAC;AAEjE,eAAsB,UAAU,QAAa;AAC5C,QAAO,UAAU,CAAC,GAAI,OAAO,WAAW,EAAE,EAAGC,2CAAkB,CAAC;AAChE,QAAO"}
@@ -1,5 +1,6 @@
1
1
  //#region src/addon/index.d.ts
2
+ declare const managerEntries: string[];
2
3
  declare function viteFinal(config: any): Promise<any>;
3
4
  //#endregion
4
- export { viteFinal };
5
+ export { managerEntries, viteFinal };
5
6
  //# sourceMappingURL=index.d.cts.map
@@ -1,5 +1,6 @@
1
1
  //#region src/addon/index.d.ts
2
+ declare const managerEntries: string[];
2
3
  declare function viteFinal(config: any): Promise<any>;
3
4
  //#endregion
4
- export { viteFinal };
5
+ export { managerEntries, viteFinal };
5
6
  //# sourceMappingURL=index.d.mts.map
@@ -1,11 +1,14 @@
1
1
  import { sbDepsVitePlugin } from "./vitePlugin.mjs";
2
+ import { createRequire } from "module";
2
3
 
3
4
  //#region src/addon/index.ts
5
+ const require = createRequire(import.meta.url);
6
+ const managerEntries = [require.resolve("../manager.mjs")];
4
7
  async function viteFinal(config) {
5
8
  config.plugins = [...config.plugins ?? [], sbDepsVitePlugin()];
6
9
  return config;
7
10
  }
8
11
 
9
12
  //#endregion
10
- export { viteFinal };
13
+ export { managerEntries, viteFinal };
11
14
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../src/addon/index.ts"],"sourcesContent":["import { sbDepsVitePlugin } from './vitePlugin'\n\nexport async function viteFinal(config: any) {\n\tconfig.plugins = [...(config.plugins ?? []), sbDepsVitePlugin()]\n\treturn config\n}\n"],"mappings":";;;AAEA,eAAsB,UAAU,QAAa;AAC5C,QAAO,UAAU,CAAC,GAAI,OAAO,WAAW,EAAE,EAAG,kBAAkB,CAAC;AAChE,QAAO"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../src/addon/index.ts"],"sourcesContent":["import { createRequire } from 'module'\nimport { sbDepsVitePlugin } from './vitePlugin'\n\nconst require = createRequire(import.meta.url)\n\nexport const managerEntries = [require.resolve('../manager.mjs')]\n\nexport async function viteFinal(config: any) {\n\tconfig.plugins = [...(config.plugins ?? []), sbDepsVitePlugin()]\n\treturn config\n}\n"],"mappings":";;;;AAGA,MAAM,UAAU,cAAc,OAAO,KAAK,IAAI;AAE9C,MAAa,iBAAiB,CAAC,QAAQ,QAAQ,iBAAiB,CAAC;AAEjE,eAAsB,UAAU,QAAa;AAC5C,QAAO,UAAU,CAAC,GAAI,OAAO,WAAW,EAAE,EAAG,kBAAkB,CAAC;AAChE,QAAO"}
@@ -1,4 +1,3 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
1
 
3
2
  //#region src/addon/preset.ts
4
3
  const addons = ["@storybook/addon-docs", "@storybook/addon-links"];
@@ -1 +1 @@
1
- {"version":3,"file":"preset.cjs","names":[],"sources":["../../src/addon/preset.ts"],"sourcesContent":["export const addons: Array<string> = [\n\t'@storybook/addon-docs',\n\t'@storybook/addon-links',\n]\n"],"mappings":";;;AAAA,MAAa,SAAwB,CACpC,yBACA,yBACA"}
1
+ {"version":3,"file":"preset.cjs","names":["addons: Array<string>"],"sources":["../../src/addon/preset.ts"],"sourcesContent":["export const addons: Array<string> = [\n\t'@storybook/addon-docs',\n\t'@storybook/addon-links',\n]\n"],"mappings":";;AAAA,MAAaA,SAAwB,CACpC,yBACA,yBACA"}
@@ -1 +1 @@
1
- {"version":3,"file":"preset.mjs","names":[],"sources":["../../src/addon/preset.ts"],"sourcesContent":["export const addons: Array<string> = [\n\t'@storybook/addon-docs',\n\t'@storybook/addon-links',\n]\n"],"mappings":";AAAA,MAAa,SAAwB,CACpC,yBACA,yBACA"}
1
+ {"version":3,"file":"preset.mjs","names":["addons: Array<string>"],"sources":["../../src/addon/preset.ts"],"sourcesContent":["export const addons: Array<string> = [\n\t'@storybook/addon-docs',\n\t'@storybook/addon-links',\n]\n"],"mappings":";AAAA,MAAaA,SAAwB,CACpC,yBACA,yBACA"}
@@ -1,7 +1,8 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
3
2
  let node_fs = require("node:fs");
3
+ node_fs = require_rolldown_runtime.__toESM(node_fs);
4
4
  let node_path = require("node:path");
5
+ node_path = require_rolldown_runtime.__toESM(node_path);
5
6
 
6
7
  //#region src/addon/vitePlugin.ts
7
8
  function sbDepsVitePlugin() {
@@ -1 +1 @@
1
- {"version":3,"file":"vitePlugin.cjs","names":[],"sources":["../../src/addon/vitePlugin.ts"],"sourcesContent":["import { readFileSync, existsSync } from 'node:fs'\nimport { resolve } from 'node:path'\n\nexport function sbDepsVitePlugin() {\n\tconst virtId = 'virtual:dependency-previews-json'\n\tconst resolved = '\\0' + virtId\n\treturn {\n\t\tname: 'sb-deps',\n\t\tresolveId(id: string) {\n\t\t\treturn id === virtId ? resolved : null\n\t\t},\n\t\tload(id: string) {\n\t\t\tif (id !== resolved) return null\n\t\t\tconst jsonPath = resolve(\n\t\t\t\tprocess.cwd(),\n\t\t\t\t'.storybook/dependency-previews.json',\n\t\t\t)\n\t\t\tconst json = existsSync(jsonPath)\n\t\t\t\t? readFileSync(jsonPath, 'utf8')\n\t\t\t\t: '{}'\n\t\t\treturn `export default ${json};`\n\t\t},\n\t}\n}\n"],"mappings":";;;;;;AAGA,SAAgB,mBAAmB;CAClC,MAAM,SAAS;CACf,MAAM,WAAW,OAAO;AACxB,QAAO;EACN,MAAM;EACN,UAAU,IAAY;AACrB,UAAO,OAAO,SAAS,WAAW;;EAEnC,KAAK,IAAY;AAChB,OAAI,OAAO,SAAU,QAAO;GAC5B,MAAM,kCACL,QAAQ,KAAK,EACb,sCACA;GACD,MAAM,+BAAkB,SAAS,6BACjB,UAAU,OAAO,GAC9B;AACH,UAAO,kBAAkB,KAAK;;EAE/B"}
1
+ {"version":3,"file":"vitePlugin.cjs","names":[],"sources":["../../src/addon/vitePlugin.ts"],"sourcesContent":["import { readFileSync, existsSync } from 'node:fs'\nimport { resolve } from 'node:path'\n\nexport function sbDepsVitePlugin() {\n\tconst virtId = 'virtual:dependency-previews-json'\n\tconst resolved = '\\0' + virtId\n\treturn {\n\t\tname: 'sb-deps',\n\t\tresolveId(id: string) {\n\t\t\treturn id === virtId ? resolved : null\n\t\t},\n\t\tload(id: string) {\n\t\t\tif (id !== resolved) return null\n\t\t\tconst jsonPath = resolve(\n\t\t\t\tprocess.cwd(),\n\t\t\t\t'.storybook/dependency-previews.json',\n\t\t\t)\n\t\t\tconst json = existsSync(jsonPath)\n\t\t\t\t? readFileSync(jsonPath, 'utf8')\n\t\t\t\t: '{}'\n\t\t\treturn `export default ${json};`\n\t\t},\n\t}\n}\n"],"mappings":";;;;;;;AAGA,SAAgB,mBAAmB;CAClC,MAAM,SAAS;CACf,MAAM,WAAW,OAAO;AACxB,QAAO;EACN,MAAM;EACN,UAAU,IAAY;AACrB,UAAO,OAAO,SAAS,WAAW;;EAEnC,KAAK,IAAY;AAChB,OAAI,OAAO,SAAU,QAAO;GAC5B,MAAM,kCACL,QAAQ,KAAK,EACb,sCACA;GACD,MAAM,+BAAkB,SAAS,6BACjB,UAAU,OAAO,GAC9B;AACH,UAAO,kBAAkB,KAAK;;EAE/B"}
@@ -1,4 +1,4 @@
1
- const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
2
  const require_PrimaryPreview = require('../components/PrimaryPreview.cjs');
3
3
  const require_StoryLink = require('../components/StoryLink.cjs');
4
4
  const require_useDependencyGraph = require('../hooks/useDependencyGraph.cjs');
@@ -12,8 +12,9 @@ const require_CubeIcon = require('../components/icons/CubeIcon.cjs');
12
12
  const require_PathCopyMolecule = require('../components/PathCopyMolecule.cjs');
13
13
  const require_SbHeading = require('../components/SbHeading.cjs');
14
14
  let react_jsx_runtime = require("react/jsx-runtime");
15
+ react_jsx_runtime = require_rolldown_runtime.__toESM(react_jsx_runtime);
15
16
  let src_blocks_DependencyPreviews_module_css = require("./DependencyPreviews.module.css");
16
- src_blocks_DependencyPreviews_module_css = require_runtime.__toESM(src_blocks_DependencyPreviews_module_css);
17
+ src_blocks_DependencyPreviews_module_css = require_rolldown_runtime.__toESM(src_blocks_DependencyPreviews_module_css);
17
18
 
18
19
  //#region src/blocks/DependencyPreviews.tsx
19
20
  function DependencyPreviews() {
@@ -1 +1 @@
1
- {"version":3,"file":"DependencyPreviews.cjs","names":["DependencyGraphProvider","useDependencyGraph","s","SbHeading","filterOutStoryAndNonComponentFiles","Expandable","EyeOpen","PrimaryPreview","ArrowToRectangle","PathCopyMolecule","ComponentSourceLink","StoryLink","BuildIcon","SquaresPlus","CubeIcon"],"sources":["../../src/blocks/DependencyPreviews.tsx"],"sourcesContent":["import { PrimaryPreview } from '../components/PrimaryPreview'\nimport { StoryLink } from '../components/StoryLink'\nimport {\n\tDependencyGraphProvider,\n\tfilterOutStoryAndNonComponentFiles,\n\tuseDependencyGraph,\n} from '../hooks/useDependencyGraph'\nimport type { StoryInfo } from '../types'\n\nimport { ComponentSourceLink } from '../components/ComponentSourceLink'\nimport { Expandable } from '../components/Expandable'\nimport { BuildIcon } from '../components/icons/BuildIcon'\nimport { EyeOpen } from '../components/icons/EyeOpen'\nimport { SquaresPlus } from '../components/icons/SquaresPlus'\n\nimport { ArrowToRectangle } from '../components/icons/ArrowToRectangleIcon'\nimport { CubeIcon } from '../components/icons/CubeIcon'\nimport { PathCopyMolecule } from '../components/PathCopyMolecule'\nimport { SbHeading } from '../components/SbHeading'\nimport s from './DependencyPreviews.module.css'\n\nexport function DependencyPreviews() {\n\treturn (\n\t\t<DependencyGraphProvider>\n\t\t\t<TopLevelDependencyPreviews />\n\t\t</DependencyGraphProvider>\n\t)\n}\n\nfunction TopLevelDependencyPreviews() {\n\tconst { node } = useDependencyGraph()\n\tif (!node) return <div>No dependency previews for this component.</div>\n\n\treturn (\n\t\t<div className={s.topLevelWrapper}>\n\t\t\t<SbHeading>Dependency previews</SbHeading>\n\t\t\t<DepsPreviewContent storyInfo={node} enablePreview={false} />\n\t\t</div>\n\t)\n}\n\ninterface PropsForDepsPreviewContent {\n\tstoryInfo: StoryInfo\n\tenablePreview?: boolean\n}\nfunction DepsPreviewContent({\n\tstoryInfo,\n\tenablePreview = true,\n}: PropsForDepsPreviewContent) {\n\tconst { graph } = useDependencyGraph()\n\tconst { builtWith, usedIn } = graph![storyInfo.componentPath]\n\tconst filteredBuiltWith = filterOutStoryAndNonComponentFiles(builtWith)\n\tconst filteredUsedIn = filterOutStoryAndNonComponentFiles(usedIn)\n\n\treturn (\n\t\t<div>\n\t\t\t{enablePreview && (\n\t\t\t\t<Expandable\n\t\t\t\t\tHeader={`Preview ${storyInfo.storyTitle} component`}\n\t\t\t\t\tIcon={EyeOpen}\n\t\t\t\t>\n\t\t\t\t\t<PrimaryPreview storyInfo={storyInfo} />\n\t\t\t\t</Expandable>\n\t\t\t)}\n\n\t\t\t<Expandable\n\t\t\t\tHeader={`Paths to ${storyInfo.storyTitle} component`}\n\t\t\t\tIcon={ArrowToRectangle}\n\t\t\t>\n\t\t\t\t<div className={s.pathData}>\n\t\t\t\t\t<PathCopyMolecule\n\t\t\t\t\t\tlabel=\"Source File Path\"\n\t\t\t\t\t\tcopyContent={storyInfo.componentPath}\n\t\t\t\t\t>\n\t\t\t\t\t\t<ComponentSourceLink storyInfo={storyInfo} />\n\t\t\t\t\t</PathCopyMolecule>\n\n\t\t\t\t\t<PathCopyMolecule\n\t\t\t\t\t\tlabel=\"Story Title Path\"\n\t\t\t\t\t\tcopyContent={storyInfo.storyTitlePath!}\n\t\t\t\t\t>\n\t\t\t\t\t\t<StoryLink info={storyInfo}>\n\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\tdangerouslySetInnerHTML={{\n\t\t\t\t\t\t\t\t\t// allow line breaks on slashes\n\t\t\t\t\t\t\t\t\t__html: storyInfo.storyTitlePath!.replaceAll(\n\t\t\t\t\t\t\t\t\t\t'/',\n\t\t\t\t\t\t\t\t\t\t'/<wbr/>',\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</StoryLink>\n\t\t\t\t\t</PathCopyMolecule>\n\n\t\t\t\t\t<PathCopyMolecule\n\t\t\t\t\t\tlabel=\"Story Page ID\"\n\t\t\t\t\t\tcopyContent={storyInfo.storyId!}\n\t\t\t\t\t>\n\t\t\t\t\t\t<StoryLink info={storyInfo}>\n\t\t\t\t\t\t\t{storyInfo.storyId}\n\t\t\t\t\t\t</StoryLink>\n\t\t\t\t\t</PathCopyMolecule>\n\t\t\t\t</div>\n\t\t\t</Expandable>\n\n\t\t\t{filteredBuiltWith.length > 0 && (\n\t\t\t\t<Expandable\n\t\t\t\t\tHeader={`Built with ${\n\t\t\t\t\t\tfilteredBuiltWith.length\n\t\t\t\t\t} component${plural(filteredBuiltWith)}`}\n\t\t\t\t\tIcon={BuildIcon}\n\t\t\t\t>\n\t\t\t\t\t<ul>\n\t\t\t\t\t\t{filterOutStoryAndNonComponentFiles(builtWith).map(\n\t\t\t\t\t\t\t(info) => (\n\t\t\t\t\t\t\t\t<DepsPreviewItem\n\t\t\t\t\t\t\t\t\tstoryInfo={info}\n\t\t\t\t\t\t\t\t\tkey={info.componentPath}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t)}\n\t\t\t\t\t</ul>\n\t\t\t\t</Expandable>\n\t\t\t)}\n\t\t\t{filteredUsedIn.length > 0 && (\n\t\t\t\t<Expandable\n\t\t\t\t\tHeader={`Used in ${filteredUsedIn.length} component${plural(\n\t\t\t\t\t\tfilteredUsedIn,\n\t\t\t\t\t)}`}\n\t\t\t\t\tIcon={SquaresPlus}\n\t\t\t\t>\n\t\t\t\t\t<ul>\n\t\t\t\t\t\t{filterOutStoryAndNonComponentFiles(usedIn).map(\n\t\t\t\t\t\t\t(info) => (\n\t\t\t\t\t\t\t\t<DepsPreviewItem\n\t\t\t\t\t\t\t\t\tstoryInfo={info}\n\t\t\t\t\t\t\t\t\tkey={info.componentPath}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t)}\n\t\t\t\t\t</ul>\n\t\t\t\t</Expandable>\n\t\t\t)}\n\t\t</div>\n\t)\n}\n\ninterface PropsForDepsPreviewItem {\n\tstoryInfo: StoryInfo\n}\n\nfunction DepsPreviewItem({ storyInfo }: PropsForDepsPreviewItem) {\n\treturn (\n\t\t<li key={storyInfo.componentPath}>\n\t\t\t{storyInfo.storyId ? (\n\t\t\t\t<Expandable\n\t\t\t\t\tIcon={CubeIcon}\n\t\t\t\t\tHeader={\n\t\t\t\t\t\t<StoryLink info={storyInfo} tooltipPosition=\"right\" />\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t<DepsPreviewContent storyInfo={storyInfo} />\n\t\t\t\t</Expandable>\n\t\t\t) : (\n\t\t\t\t<StoryLink info={storyInfo} />\n\t\t\t)}\n\t\t</li>\n\t)\n}\n\nfunction plural(arr: Array<any>) {\n\treturn arr.length === 1 ? '' : 's'\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAqBA,SAAgB,qBAAqB;AACpC,QACC,2CAACA,gEACA,2CAAC,+BAA6B,GACL;;AAI5B,SAAS,6BAA6B;CACrC,MAAM,EAAE,SAASC,+CAAoB;AACrC,KAAI,CAAC,KAAM,QAAO,2CAAC,mBAAI,+CAAgD;AAEvE,QACC,4CAAC;EAAI,WAAWC,iDAAE;aACjB,2CAACC,yCAAU,wBAA+B,EAC1C,2CAAC;GAAmB,WAAW;GAAM,eAAe;IAAS;GACxD;;AAQR,SAAS,mBAAmB,EAC3B,WACA,gBAAgB,QACc;CAC9B,MAAM,EAAE,UAAUF,+CAAoB;CACtC,MAAM,EAAE,WAAW,WAAW,MAAO,UAAU;CAC/C,MAAM,oBAAoBG,8DAAmC,UAAU;CACvE,MAAM,iBAAiBA,8DAAmC,OAAO;AAEjE,QACC,4CAAC;EACC,iBACA,2CAACC;GACA,QAAQ,WAAW,UAAU,WAAW;GACxC,MAAMC;aAEN,2CAACC,yCAA0B,YAAa;IAC5B;EAGd,2CAACF;GACA,QAAQ,YAAY,UAAU,WAAW;GACzC,MAAMG;aAEN,4CAAC;IAAI,WAAWN,iDAAE;;KACjB,2CAACO;MACA,OAAM;MACN,aAAa,UAAU;gBAEvB,2CAACC,mDAA+B,YAAa;OAC3B;KAEnB,2CAACD;MACA,OAAM;MACN,aAAa,UAAU;gBAEvB,2CAACE;OAAU,MAAM;iBAChB,2CAAC,UACA,yBAAyB,EAExB,QAAQ,UAAU,eAAgB,WACjC,KACA,UACA,EACD,GACA;QACS;OACM;KAEnB,2CAACF;MACA,OAAM;MACN,aAAa,UAAU;gBAEvB,2CAACE;OAAU,MAAM;iBACf,UAAU;QACA;OACM;;KACd;IACM;EAEZ,kBAAkB,SAAS,KAC3B,2CAACN;GACA,QAAQ,cACP,kBAAkB,OAClB,YAAY,OAAO,kBAAkB;GACtC,MAAMO;aAEN,2CAAC,kBACCR,8DAAmC,UAAU,CAAC,KAC7C,SACA,2CAAC,mBACA,WAAW,QACN,KAAK,cACT,CAEH,GACG;IACO;EAEb,eAAe,SAAS,KACxB,2CAACC;GACA,QAAQ,WAAW,eAAe,OAAO,YAAY,OACpD,eACA;GACD,MAAMQ;aAEN,2CAAC,kBACCT,8DAAmC,OAAO,CAAC,KAC1C,SACA,2CAAC,mBACA,WAAW,QACN,KAAK,cACT,CAEH,GACG;IACO;KAET;;AAQR,SAAS,gBAAgB,EAAE,aAAsC;AAChE,QACC,2CAAC,kBACC,UAAU,UACV,2CAACC;EACA,MAAMS;EACN,QACC,2CAACH;GAAU,MAAM;GAAW,iBAAgB;IAAU;YAGvD,2CAAC,sBAA8B,YAAa;GAChC,GAEb,2CAACA,+BAAU,MAAM,YAAa,IAXvB,UAAU,cAad;;AAIP,SAAS,OAAO,KAAiB;AAChC,QAAO,IAAI,WAAW,IAAI,KAAK"}
1
+ {"version":3,"file":"DependencyPreviews.cjs","names":["DependencyGraphProvider","useDependencyGraph","s","SbHeading","filterOutStoryAndNonComponentFiles","Expandable","EyeOpen","PrimaryPreview","ArrowToRectangle","PathCopyMolecule","ComponentSourceLink","StoryLink","BuildIcon","SquaresPlus","CubeIcon"],"sources":["../../src/blocks/DependencyPreviews.tsx"],"sourcesContent":["import { PrimaryPreview } from '../components/PrimaryPreview'\nimport { StoryLink } from '../components/StoryLink'\nimport {\n\tDependencyGraphProvider,\n\tfilterOutStoryAndNonComponentFiles,\n\tuseDependencyGraph,\n} from '../hooks/useDependencyGraph'\nimport type { StoryInfo } from '../types'\n\nimport { ComponentSourceLink } from '../components/ComponentSourceLink'\nimport { Expandable } from '../components/Expandable'\nimport { BuildIcon } from '../components/icons/BuildIcon'\nimport { EyeOpen } from '../components/icons/EyeOpen'\nimport { SquaresPlus } from '../components/icons/SquaresPlus'\n\nimport { ArrowToRectangle } from '../components/icons/ArrowToRectangleIcon'\nimport { CubeIcon } from '../components/icons/CubeIcon'\nimport { PathCopyMolecule } from '../components/PathCopyMolecule'\nimport { SbHeading } from '../components/SbHeading'\nimport s from './DependencyPreviews.module.css'\n\nexport function DependencyPreviews() {\n\treturn (\n\t\t<DependencyGraphProvider>\n\t\t\t<TopLevelDependencyPreviews />\n\t\t</DependencyGraphProvider>\n\t)\n}\n\nfunction TopLevelDependencyPreviews() {\n\tconst { node } = useDependencyGraph()\n\tif (!node) return <div>No dependency previews for this component.</div>\n\n\treturn (\n\t\t<div className={s.topLevelWrapper}>\n\t\t\t<SbHeading>Dependency previews</SbHeading>\n\t\t\t<DepsPreviewContent storyInfo={node} enablePreview={false} />\n\t\t</div>\n\t)\n}\n\ninterface PropsForDepsPreviewContent {\n\tstoryInfo: StoryInfo\n\tenablePreview?: boolean\n}\nfunction DepsPreviewContent({\n\tstoryInfo,\n\tenablePreview = true,\n}: PropsForDepsPreviewContent) {\n\tconst { graph } = useDependencyGraph()\n\tconst { builtWith, usedIn } = graph![storyInfo.componentPath]\n\tconst filteredBuiltWith = filterOutStoryAndNonComponentFiles(builtWith)\n\tconst filteredUsedIn = filterOutStoryAndNonComponentFiles(usedIn)\n\n\treturn (\n\t\t<div>\n\t\t\t{enablePreview && (\n\t\t\t\t<Expandable\n\t\t\t\t\tHeader={`Preview ${storyInfo.storyTitle} component`}\n\t\t\t\t\tIcon={EyeOpen}\n\t\t\t\t>\n\t\t\t\t\t<PrimaryPreview storyInfo={storyInfo} />\n\t\t\t\t</Expandable>\n\t\t\t)}\n\n\t\t\t<Expandable\n\t\t\t\tHeader={`Paths to ${storyInfo.storyTitle} component`}\n\t\t\t\tIcon={ArrowToRectangle}\n\t\t\t>\n\t\t\t\t<div className={s.pathData}>\n\t\t\t\t\t<PathCopyMolecule\n\t\t\t\t\t\tlabel=\"Source File Path\"\n\t\t\t\t\t\tcopyContent={storyInfo.componentPath}\n\t\t\t\t\t>\n\t\t\t\t\t\t<ComponentSourceLink storyInfo={storyInfo} />\n\t\t\t\t\t</PathCopyMolecule>\n\n\t\t\t\t\t<PathCopyMolecule\n\t\t\t\t\t\tlabel=\"Story Title Path\"\n\t\t\t\t\t\tcopyContent={storyInfo.storyTitlePath!}\n\t\t\t\t\t>\n\t\t\t\t\t\t<StoryLink info={storyInfo}>\n\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\tdangerouslySetInnerHTML={{\n\t\t\t\t\t\t\t\t\t// allow line breaks on slashes\n\t\t\t\t\t\t\t\t\t__html: storyInfo.storyTitlePath!.replaceAll(\n\t\t\t\t\t\t\t\t\t\t'/',\n\t\t\t\t\t\t\t\t\t\t'/<wbr/>',\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</StoryLink>\n\t\t\t\t\t</PathCopyMolecule>\n\n\t\t\t\t\t<PathCopyMolecule\n\t\t\t\t\t\tlabel=\"Story Page ID\"\n\t\t\t\t\t\tcopyContent={storyInfo.storyId!}\n\t\t\t\t\t>\n\t\t\t\t\t\t<StoryLink info={storyInfo}>\n\t\t\t\t\t\t\t{storyInfo.storyId}\n\t\t\t\t\t\t</StoryLink>\n\t\t\t\t\t</PathCopyMolecule>\n\t\t\t\t</div>\n\t\t\t</Expandable>\n\n\t\t\t{filteredBuiltWith.length > 0 && (\n\t\t\t\t<Expandable\n\t\t\t\t\tHeader={`Built with ${\n\t\t\t\t\t\tfilteredBuiltWith.length\n\t\t\t\t\t} component${plural(filteredBuiltWith)}`}\n\t\t\t\t\tIcon={BuildIcon}\n\t\t\t\t>\n\t\t\t\t\t<ul>\n\t\t\t\t\t\t{filterOutStoryAndNonComponentFiles(builtWith).map(\n\t\t\t\t\t\t\t(info) => (\n\t\t\t\t\t\t\t\t<DepsPreviewItem\n\t\t\t\t\t\t\t\t\tstoryInfo={info}\n\t\t\t\t\t\t\t\t\tkey={info.componentPath}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t)}\n\t\t\t\t\t</ul>\n\t\t\t\t</Expandable>\n\t\t\t)}\n\t\t\t{filteredUsedIn.length > 0 && (\n\t\t\t\t<Expandable\n\t\t\t\t\tHeader={`Used in ${filteredUsedIn.length} component${plural(\n\t\t\t\t\t\tfilteredUsedIn,\n\t\t\t\t\t)}`}\n\t\t\t\t\tIcon={SquaresPlus}\n\t\t\t\t>\n\t\t\t\t\t<ul>\n\t\t\t\t\t\t{filterOutStoryAndNonComponentFiles(usedIn).map(\n\t\t\t\t\t\t\t(info) => (\n\t\t\t\t\t\t\t\t<DepsPreviewItem\n\t\t\t\t\t\t\t\t\tstoryInfo={info}\n\t\t\t\t\t\t\t\t\tkey={info.componentPath}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t)}\n\t\t\t\t\t</ul>\n\t\t\t\t</Expandable>\n\t\t\t)}\n\t\t</div>\n\t)\n}\n\ninterface PropsForDepsPreviewItem {\n\tstoryInfo: StoryInfo\n}\n\nfunction DepsPreviewItem({ storyInfo }: PropsForDepsPreviewItem) {\n\treturn (\n\t\t<li key={storyInfo.componentPath}>\n\t\t\t{storyInfo.storyId ? (\n\t\t\t\t<Expandable\n\t\t\t\t\tIcon={CubeIcon}\n\t\t\t\t\tHeader={\n\t\t\t\t\t\t<StoryLink info={storyInfo} tooltipPosition=\"right\" />\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t<DepsPreviewContent storyInfo={storyInfo} />\n\t\t\t\t</Expandable>\n\t\t\t) : (\n\t\t\t\t<StoryLink info={storyInfo} />\n\t\t\t)}\n\t\t</li>\n\t)\n}\n\nfunction plural(arr: Array<any>) {\n\treturn arr.length === 1 ? '' : 's'\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,qBAAqB;AACpC,QACC,2CAACA,gEACA,2CAAC,+BAA6B,GACL;;AAI5B,SAAS,6BAA6B;CACrC,MAAM,EAAE,SAASC,+CAAoB;AACrC,KAAI,CAAC,KAAM,QAAO,2CAAC,mBAAI,+CAAgD;AAEvE,QACC,4CAAC;EAAI,WAAWC,iDAAE;aACjB,2CAACC,yCAAU,wBAA+B,EAC1C,2CAAC;GAAmB,WAAW;GAAM,eAAe;IAAS;GACxD;;AAQR,SAAS,mBAAmB,EAC3B,WACA,gBAAgB,QACc;CAC9B,MAAM,EAAE,UAAUF,+CAAoB;CACtC,MAAM,EAAE,WAAW,WAAW,MAAO,UAAU;CAC/C,MAAM,oBAAoBG,8DAAmC,UAAU;CACvE,MAAM,iBAAiBA,8DAAmC,OAAO;AAEjE,QACC,4CAAC;EACC,iBACA,2CAACC;GACA,QAAQ,WAAW,UAAU,WAAW;GACxC,MAAMC;aAEN,2CAACC,yCAA0B,YAAa;IAC5B;EAGd,2CAACF;GACA,QAAQ,YAAY,UAAU,WAAW;GACzC,MAAMG;aAEN,4CAAC;IAAI,WAAWN,iDAAE;;KACjB,2CAACO;MACA,OAAM;MACN,aAAa,UAAU;gBAEvB,2CAACC,mDAA+B,YAAa;OAC3B;KAEnB,2CAACD;MACA,OAAM;MACN,aAAa,UAAU;gBAEvB,2CAACE;OAAU,MAAM;iBAChB,2CAAC,UACA,yBAAyB,EAExB,QAAQ,UAAU,eAAgB,WACjC,KACA,UACA,EACD,GACA;QACS;OACM;KAEnB,2CAACF;MACA,OAAM;MACN,aAAa,UAAU;gBAEvB,2CAACE;OAAU,MAAM;iBACf,UAAU;QACA;OACM;;KACd;IACM;EAEZ,kBAAkB,SAAS,KAC3B,2CAACN;GACA,QAAQ,cACP,kBAAkB,OAClB,YAAY,OAAO,kBAAkB;GACtC,MAAMO;aAEN,2CAAC,kBACCR,8DAAmC,UAAU,CAAC,KAC7C,SACA,2CAAC,mBACA,WAAW,QACN,KAAK,cACT,CAEH,GACG;IACO;EAEb,eAAe,SAAS,KACxB,2CAACC;GACA,QAAQ,WAAW,eAAe,OAAO,YAAY,OACpD,eACA;GACD,MAAMQ;aAEN,2CAAC,kBACCT,8DAAmC,OAAO,CAAC,KAC1C,SACA,2CAAC,mBACA,WAAW,QACN,KAAK,cACT,CAEH,GACG;IACO;KAET;;AAQR,SAAS,gBAAgB,EAAE,aAAsC;AAChE,QACC,2CAAC,kBACC,UAAU,UACV,2CAACC;EACA,MAAMS;EACN,QACC,2CAACH;GAAU,MAAM;GAAW,iBAAgB;IAAU;YAGvD,2CAAC,sBAA8B,YAAa;GAChC,GAEb,2CAACA,+BAAU,MAAM,YAAa,IAXvB,UAAU,cAad;;AAIP,SAAS,OAAO,KAAiB;AAChC,QAAO,IAAI,WAAW,IAAI,KAAK"}