storybook-addon-sdc 0.15.3 → 0.16.1

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 (3) hide show
  1. package/README.md +25 -7
  2. package/dist/preset.js +66 -40
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -599,7 +599,8 @@ thirdPartySettings:
599
599
  sdcStorybook:
600
600
  tags:
601
601
  - autodocs
602
- disableBasicStory: true
602
+ disabledStories:
603
+ - basic
603
604
  parameters:
604
605
  layout: 'centered'
605
606
  stories:
@@ -615,12 +616,29 @@ thirdPartySettings:
615
616
 
616
617
  Below is a list of all available configuration options for `thirdPartySettings.sdcStorybook`:
617
618
 
618
- | Key | Type | Description |
619
- | ------------------- | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
620
- | `tags` | `array` | Optional. Adds additional [Storybook tags](https://storybook.js.org/docs/writing-docs/autodocs) (e.g. `autodocs`). |
621
- | `disableBasicStory` | `boolean` | When set to `true`, disables the automatically generated “Basic” story. |
622
- | `parameters` | `object` | Global [Storybook parameters](https://storybook.js.org/docs/writing-stories/parameters) applied to all generated stories. |
623
- | `stories` | `object` | Allows defining or overriding specific stories. Each key (e.g. `preview`) represents a story. Within each story, you can define `args`, `parameters`, and other Storybook options. |
619
+ | Key | Type | Description |
620
+ | ----------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
621
+ | `tags` | `array` | Optional. Adds additional [Storybook tags](https://storybook.js.org/docs/writing-docs/autodocs) (e.g. `autodocs`). |
622
+ | `disabledStories` | `array` | Optional. Array of story names to disable. Supports `basic`, `preview`, or any custom story name. Use `all` to disable all stories. **Note:** `disableBasicStory` is deprecated in favor of `disabledStories: ['basic']`. |
623
+ | `parameters` | `object` | Global [Storybook parameters](https://storybook.js.org/docs/writing-stories/parameters) applied to all generated stories. |
624
+ | `stories` | `object` | Allows defining or overriding specific stories. Each key (e.g. `preview`) represents a story. Within each story, you can define `args`, `parameters`, and other Storybook options. |
625
+
626
+ ### Disabled Stories Examples
627
+
628
+ ```yaml
629
+ # Disable only the basic story
630
+ disabledStories:
631
+ - basic
632
+
633
+ # Disable basic and preview stories
634
+ disabledStories:
635
+ - basic
636
+ - preview
637
+
638
+ # Disable all stories
639
+ disabledStories:
640
+ - all
641
+ ```
624
642
 
625
643
  ### Example: Custom Preview Story
626
644
 
package/dist/preset.js CHANGED
@@ -15,6 +15,36 @@ var logger = pino({
15
15
  }
16
16
  });
17
17
 
18
+ // src/utils.ts
19
+ import { dirname, sep } from "path";
20
+ var capitalize = (str) => str[0].toUpperCase() + str.slice(1);
21
+ var convertToKebabCase = (str) => str.replace(/[-:]/g, "");
22
+ var toAttributes = (attrs) => {
23
+ if (!attrs) return "";
24
+ return " " + Object.entries(attrs).map(([key, value]) => {
25
+ if (Array.isArray(value)) {
26
+ value = value.join(" ");
27
+ }
28
+ return `${key}="${value}"`;
29
+ }).join(" ");
30
+ };
31
+ var deriveGroupFromPath = (fileName) => {
32
+ const dir = dirname(fileName);
33
+ const parts = dir.split(sep).filter(Boolean);
34
+ const lower = parts.map((p) => p.toLowerCase());
35
+ const index = lower.lastIndexOf("components");
36
+ if (index !== -1 && parts[index + 2]) {
37
+ return parts[index + 1];
38
+ }
39
+ return "SDC";
40
+ };
41
+ var sanitizeStoryKey = (key) => {
42
+ if (/^\d/.test(key)) {
43
+ return `_${key}`;
44
+ }
45
+ return key;
46
+ };
47
+
18
48
  // src/argsGenerator.ts
19
49
  import { JSONSchemaFaker } from "json-schema-faker";
20
50
  var generateArgs = (schema, defs) => {
@@ -62,30 +92,6 @@ var argTypesGenerator_default = (content) => {
62
92
  return generated;
63
93
  };
64
94
 
65
- // src/utils.ts
66
- import { dirname, sep } from "path";
67
- var capitalize = (str) => str[0].toUpperCase() + str.slice(1);
68
- var convertToKebabCase = (str) => str.replace(/[-:]/g, "");
69
- var toAttributes = (attrs) => {
70
- if (!attrs) return "";
71
- return " " + Object.entries(attrs).map(([key, value]) => {
72
- if (Array.isArray(value)) {
73
- value = value.join(" ");
74
- }
75
- return `${key}="${value}"`;
76
- }).join(" ");
77
- };
78
- var deriveGroupFromPath = (fileName) => {
79
- const dir = dirname(fileName);
80
- const parts = dir.split(sep).filter(Boolean);
81
- const lower = parts.map((p) => p.toLowerCase());
82
- const index = lower.lastIndexOf("components");
83
- if (index !== -1 && parts[index + 2]) {
84
- return parts[index + 1];
85
- }
86
- return "SDC";
87
- };
88
-
89
95
  // src/storyNodeRender.ts
90
96
  var generateArgs2 = (args, isSlot = false) => Object.entries(args).map(([key, value]) => `${key}: ${formatArgValue(value, isSlot)},`).join("\n");
91
97
  var formatArgValue = (value, isSlot) => {
@@ -170,7 +176,7 @@ export const ${capitalize(storyKey)} = {
170
176
  name: ${JSON.stringify(name ?? capitalize(storyKey), null, 2)},
171
177
  args: {
172
178
  ...Basic.baseArgs,
173
- ${generateArgs2(props, false)}
179
+ ${processPropsAttributes(props)}
174
180
  ${generateArgs2(slots, true)}
175
181
  ${generateVariants(variants)}
176
182
  },
@@ -195,6 +201,15 @@ var generateVariants = (variants) => {
195
201
  ([variantKey, variantValue]) => `${variantKey}: ${JSON.stringify(variantValue.title)},`
196
202
  ).join("\n");
197
203
  };
204
+ var processPropsAttributes = (props) => {
205
+ if (!props || !props.attributes || Object.keys(props.attributes).length === 0) {
206
+ return generateArgs2(props, false);
207
+ }
208
+ const { attributes, ...otherProps } = props;
209
+ const propsArgs = generateArgs2(otherProps, false);
210
+ const attributeEntries = Object.entries(attributes).map(([key, value]) => `['${key}', ${JSON.stringify(value)}]`).join(", ");
211
+ return propsArgs + (propsArgs ? "\n" : "") + `defaultAttributes: [...Basic.baseArgs.defaultAttributes || [], ${attributeEntries}],`;
212
+ };
198
213
 
199
214
  // src/componentMetadata.ts
200
215
  import { dirname as dirname2, relative } from "path";
@@ -454,9 +469,10 @@ var dynamicImports = (stories, namespaces) => {
454
469
  );
455
470
  return Array.from(imports).join("\n");
456
471
  };
457
- var createStoryIndex = (fileName, baseTitle, stories, disableBasicStory, tags) => {
472
+ var createStoryIndex = (fileName, baseTitle, stories, disabledStories, tags) => {
458
473
  const storiesIndex = [];
459
- if (disableBasicStory === false) {
474
+ const isAllDisabled = disabledStories.includes("all");
475
+ if (!isAllDisabled && !disabledStories.includes("basic")) {
460
476
  storiesIndex.push({
461
477
  type: "story",
462
478
  importPath: fileName,
@@ -465,15 +481,17 @@ var createStoryIndex = (fileName, baseTitle, stories, disableBasicStory, tags) =
465
481
  tags
466
482
  });
467
483
  }
468
- if (stories) {
484
+ if (stories && !isAllDisabled) {
469
485
  Object.keys(stories).forEach((storyKey) => {
470
- storiesIndex.push({
471
- type: "story",
472
- importPath: fileName,
473
- exportName: storyKey,
474
- title: baseTitle,
475
- tags
476
- });
486
+ if (!disabledStories.includes(storyKey)) {
487
+ storiesIndex.push({
488
+ type: "story",
489
+ importPath: fileName,
490
+ exportName: storyKey,
491
+ title: baseTitle,
492
+ tags
493
+ });
494
+ }
477
495
  });
478
496
  }
479
497
  return storiesIndex;
@@ -544,9 +562,9 @@ export default {
544
562
  };
545
563
 
546
564
  export const Basic = {
547
-
565
+
548
566
  args: ${JSON.stringify(basicArgs, null, 2)},
549
- baseArgs: ${JSON.stringify(args, null, 2)},
567
+ baseArgs: ${JSON.stringify(args, null, 2)},
550
568
  play: async ({ canvasElement }) => {
551
569
  Drupal.attachBehaviors(canvasElement, window.drupalSettings);
552
570
  },
@@ -572,12 +590,19 @@ var yamlStoriesIndexer = {
572
590
  const storiesContent = loadStoryFilesSync(fileName);
573
591
  const mergedStories = { ...stories, ...storiesContent };
574
592
  const tags = content?.thirdPartySettings?.sdcStorybook?.tags ?? [];
575
- const disableBasicStory = content.thirdPartySettings?.sdcStorybook?.disableBasicStory ?? false;
593
+ const oldDisableBasicStory = content.thirdPartySettings?.sdcStorybook?.disableBasicStory;
594
+ const newDisabledStories = content.thirdPartySettings?.sdcStorybook?.disabledStories;
595
+ let disabledStories = [];
596
+ if (oldDisableBasicStory === true) {
597
+ disabledStories = ["basic"];
598
+ } else if (newDisabledStories) {
599
+ disabledStories = newDisabledStories;
600
+ }
576
601
  return createStoryIndex(
577
602
  fileName,
578
603
  baseTitle,
579
604
  mergedStories,
580
- disableBasicStory,
605
+ disabledStories,
581
606
  tags
582
607
  );
583
608
  } catch (error) {
@@ -592,7 +617,8 @@ var loadStoryFilesSync = (fileName) => {
592
617
  return storyFiles.reduce(
593
618
  (acc, file) => {
594
619
  const content = readFileSync(file, "utf8");
595
- const key = basename2(file).split(".")[1];
620
+ const rawKey = basename2(file).split(".")[1];
621
+ const key = sanitizeStoryKey(rawKey);
596
622
  return {
597
623
  ...acc,
598
624
  [key]: parseYaml(content)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "storybook-addon-sdc",
3
- "version": "0.15.3",
3
+ "version": "0.16.1",
4
4
  "description": "Drupal Single Directory Components as stories",
5
5
  "keywords": [
6
6
  "SDC",