storybook-addon-sdc 0.7.6 → 0.7.8

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/README.md CHANGED
@@ -14,6 +14,7 @@ This addon streamlines the integration of Drupal Single Directory Components (SD
14
14
  - [Configuration](#configuration)
15
15
  - [Setting Default Values](#setting-default-values)
16
16
  - [Creating Experimental Stories](#creating-experimental-stories)
17
+ - [Support for Single Story Files (\*.story.yml)](#support-for-single-story-files-storyyml)
17
18
  - [Regular Storybook](#regular-storybook)
18
19
  - [Configuration Options](#configuration-options)
19
20
  - [Dependencies](#dependencies)
@@ -244,6 +245,39 @@ The addon dynamically renders the components and stories as defined:
244
245
 
245
246
  [![Stories](https://i.gyazo.com/7212a3f44052ebde34b59a1555d96afe.png)](https://gyazo.com/7212a3f44052ebde34b59a1555d96afe)
246
247
 
248
+ ## Support for Single Story Files (`*.story.yml`)
249
+
250
+ In addition to stories defined inside `*.component.yml` files, the addon now supports standalone story files with the `.story.yml` extension.
251
+
252
+ This means you can create independent stories for your components by simply adding a `.story.yml` file in your component directory. These files are automatically discovered and indexed by Storybook, allowing you to organize and share stories outside of the main component YAML.
253
+
254
+ **Example:**
255
+
256
+ ```yaml
257
+ # components/slider/slider.badges.story.yml
258
+ name: Badges
259
+ props:
260
+ slides:
261
+ - type: component
262
+ component: 'umami:badge'
263
+ props:
264
+ icon: timer
265
+ slots:
266
+ text: Hola
267
+ - type: component
268
+ component: 'umami:badge'
269
+ props:
270
+ icon: serves
271
+ slots:
272
+ text: Bonjour
273
+ - type: component
274
+ component: 'umami:badge'
275
+ props:
276
+ icon: difficulty
277
+ slots:
278
+ text: Ciao
279
+ ```
280
+
247
281
  ### Why stories experimental?
248
282
 
249
283
  The [community will have to decide](https://docs.google.com/document/d/1wCQLXrK1lrV2gYlqmqD2pybTql6_H1dByWIKB5xQFcQ/edit?tab=t.0#heading=h.3949vjfiqczr) what format the YAML stories should be.
package/dist/preset.js CHANGED
@@ -1,7 +1,8 @@
1
1
  // src/vite-plugin-storybook-yaml-stories.ts
2
2
  import { readdirSync as readdirSync2, readFileSync } from "fs";
3
3
  import { parse as parseYaml } from "yaml";
4
- import { basename, dirname as dirname2, extname } from "path";
4
+ import { join as join2, basename, dirname as dirname2, extname } from "path";
5
+ import { globSync } from "glob";
5
6
 
6
7
  // src/argsGenerator.ts
7
8
  import { JSONSchemaFaker } from "json-schema-faker";
@@ -180,7 +181,9 @@ var readSDC = (filePath, defs, validate) => {
180
181
  }
181
182
  return sdcSchema;
182
183
  };
183
- var generateImports = (directory) => readdirSync2(directory).filter((file) => [".css", ".js", ".mjs", ".twig"].includes(extname(file))).map((file) => {
184
+ var generateImports = (directory) => readdirSync2(directory).filter(
185
+ (file) => [".css", ".js", ".mjs", ".twig", ".yml"].includes(extname(file))
186
+ ).map((file) => {
184
187
  const filePath = `./${file}`;
185
188
  return extname(file) === ".twig" ? `import COMPONENT from '${filePath}';` : `import '${filePath}';`;
186
189
  }).join("\n");
@@ -239,13 +242,18 @@ var vite_plugin_storybook_yaml_stories_default = ({
239
242
  }) => ({
240
243
  name: "vite-plugin-storybook-yaml-stories",
241
244
  async load(id) {
245
+ if (id.endsWith("story.yml")) {
246
+ return "";
247
+ }
242
248
  if (!id.endsWith("component.yml")) return;
243
249
  try {
244
250
  const content = readSDC(id, globalDefs, sdcStorybookOptions.validate);
245
251
  const imports = generateImports(dirname2(id));
246
- const storiesImports = dynamicImports(
247
- content.thirdPartySettings?.sdcStorybook?.stories || {}
248
- );
252
+ const previewsStories = {
253
+ ...content.thirdPartySettings?.sdcStorybook?.stories || {},
254
+ ...loadStoryFilesSync(id)
255
+ };
256
+ const storiesImports = dynamicImports(previewsStories);
249
257
  const metadata = componentMetadata_default(id, content);
250
258
  const argTypes = {
251
259
  componentMetadata: { table: { disable: true } },
@@ -272,7 +280,7 @@ var vite_plugin_storybook_yaml_stories_default = ({
272
280
  ...generateStorybookArgs(content, jsonSchemaFakerOptions)
273
281
  };
274
282
  const basicArgs = { ...args };
275
- const stories = content.thirdPartySettings?.sdcStorybook?.stories ? storiesGenerator_default(content.thirdPartySettings.sdcStorybook.stories) : "";
283
+ const stories = previewsStories ? storiesGenerator_default(previewsStories) : "";
276
284
  return `
277
285
  ${imports}
278
286
  ${storiesImports}
@@ -305,13 +313,30 @@ var yamlStoriesIndexer = {
305
313
  const content = readSDC(fileName);
306
314
  const baseTitle = makeTitle(`SDC/${content.name}`);
307
315
  const stories = content.thirdPartySettings?.sdcStorybook?.stories;
308
- return createStoryIndex(fileName, baseTitle, stories);
316
+ const storiesContent = loadStoryFilesSync(fileName);
317
+ const mergedStories = { ...stories, ...storiesContent };
318
+ return createStoryIndex(fileName, baseTitle, mergedStories);
309
319
  } catch (error) {
310
320
  console.error(`Error creating index for YAML file: ${fileName}`, error);
311
321
  throw error;
312
322
  }
313
323
  }
314
324
  };
325
+ var loadStoryFilesSync = (fileName) => {
326
+ const folderPath = dirname2(fileName);
327
+ const storyFiles = globSync(join2(folderPath, "*.story.yml"));
328
+ return storyFiles.reduce(
329
+ (acc, file) => {
330
+ const content = readFileSync(file, "utf8");
331
+ const key = basename(file).split(".")[1];
332
+ return {
333
+ ...acc,
334
+ [key]: parseYaml(content)
335
+ };
336
+ },
337
+ {}
338
+ );
339
+ };
315
340
 
316
341
  // src/preset.ts
317
342
  import twig from "vite-plugin-twig-drupal";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "storybook-addon-sdc",
3
- "version": "0.7.6",
3
+ "version": "0.7.8",
4
4
  "description": "Drupal Single Directory Components as stories",
5
5
  "keywords": [
6
6
  "SDC",