storybook-addon-sdc 0.14.2 → 0.15.2

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
@@ -19,10 +19,10 @@ This addon streamlines the integration of Drupal Single Directory Components (SD
19
19
  - [Configuration Options](#configuration-options)
20
20
  - [Setting Default Values](#setting-default-values)
21
21
  - [Story Configuration via thirdPartySettings.sdcStorybook](#story-configuration-via-thirdpartysettingssdcstorybook)
22
+ - [UI Patterns](#ui-patterns)
22
23
  - [Why Choose SDC Storybook Over Alternatives?](#why-choose-sdc-storybook-over-alternatives)
23
24
  - [Dependencies](#dependencies)
24
25
  - [Known Issues](#known-issues)
25
- - [UI Patterns](#ui-patterns)
26
26
 
27
27
  ---
28
28
 
@@ -637,6 +637,14 @@ thirdPartySettings:
637
637
 
638
638
  This configuration creates an additional story named **Preview**, rendered using the provided `args` and `parameters`.
639
639
 
640
+ ## UI Patterns
641
+
642
+ Addon supports UI Patterns `library_wrapper` [for wrapping stories](https://project.pages.drupalcode.org/ui_patterns/2-authors/1-stories-and-library/#library-wrappers) in a specific HTML structure.
643
+
644
+ ---
645
+
646
+ - Custom Twig filters and functions are not supported ([UI Patterns TwigExtension](https://git.drupalcode.org/project/ui_patterns/-/blob/8.x-1.x/src/Template/TwigExtension.php)).
647
+
640
648
  ## Why Choose SDC Storybook Over Alternatives?
641
649
 
642
650
  While solutions like [SDC Styleguide](https://www.drupal.org/project/sdc_styleguide) and [Drupal Storybook](https://www.drupal.org/project/storybook) are valuable, the SDC Storybook addon offers distinct advantages:
@@ -690,8 +698,3 @@ While using Drupal to render components offers tighter integration, there are st
690
698
  ## Known Issues
691
699
 
692
700
  - The addon relies on [Experimental indexers](https://storybook.js.org/docs/api/main-config/main-config-indexers).
693
-
694
- ## UI Patterns
695
-
696
- - Variants are partially supported ([Issue 3390712](https://www.drupal.org/project/drupal/issues/3390712)).
697
- - Custom Twig filters and functions are not supported ([UI Patterns TwigExtension](https://git.drupalcode.org/project/ui_patterns/-/blob/8.x-1.x/src/Template/TwigExtension.php)).
package/dist/preset.js CHANGED
@@ -161,7 +161,8 @@ var storiesGenerator_default = (stories) => Object.entries(stories).map(
161
161
  slots = {},
162
162
  variants = {},
163
163
  description = "",
164
- name = void 0
164
+ name = void 0,
165
+ library_wrapper = ""
165
166
  }
166
167
  ]) => `
167
168
  export const ${capitalize(storyKey)} = {
@@ -173,6 +174,16 @@ export const ${capitalize(storyKey)} = {
173
174
  ${generateArgs2(slots, true)}
174
175
  ${generateVariants(variants)}
175
176
  },
177
+ ${library_wrapper ? `decorators: [
178
+ (Story) => {
179
+ const wrapper = ${JSON.stringify(library_wrapper)};
180
+ if (!wrapper) return Story();
181
+
182
+ // Replace {{ _story }} with the actual story component
183
+ const wrappedHtml = wrapper.replace('{{ _story }}', Story());
184
+ return wrappedHtml;
185
+ }
186
+ ],` : ""}
176
187
  play: async ({ canvasElement }) => {
177
188
  Drupal.attachBehaviors(canvasElement, window.drupalSettings);
178
189
  },
@@ -243,7 +254,6 @@ import { readdirSync, existsSync } from "fs";
243
254
  import { basename, join, resolve, sep as sep2, relative as relative2 } from "path";
244
255
  import { cwd as cwd2 } from "process";
245
256
  import { normalizePath } from "vite";
246
- var getSubdirectories = (baseDir) => readdirSync(baseDir, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => join(baseDir, entry.name));
247
257
  var getProjectName = (p) => {
248
258
  const fullPath = resolve(p);
249
259
  const parts = fullPath.split(sep2);
@@ -253,13 +263,40 @@ var getProjectName = (p) => {
253
263
  }
254
264
  return parts[i - 1];
255
265
  };
266
+ var getAllSubdirectoriesRecursive = (baseDir) => {
267
+ const result = [];
268
+ const scan = (dir) => {
269
+ try {
270
+ const entries = readdirSync(dir, { withFileTypes: true });
271
+ for (const entry of entries) {
272
+ if (entry.isDirectory()) {
273
+ const fullPath = join(dir, entry.name);
274
+ result.push(fullPath);
275
+ scan(fullPath);
276
+ }
277
+ }
278
+ } catch (error) {
279
+ }
280
+ };
281
+ scan(baseDir);
282
+ return result;
283
+ };
256
284
  var resolveComponentPath = (namespace, component, namespaces) => {
257
285
  const baseDir = namespaces.findPath(namespace);
258
- const directories = [baseDir, ...getSubdirectories(baseDir)];
259
- const possiblePaths = directories.map(
260
- (dir) => join(dir, component, `${component}.component.yml`)
261
- );
262
- return possiblePaths.find(existsSync);
286
+ if (!baseDir) return void 0;
287
+ const componentFileName = `${component}.component.yml`;
288
+ const directPath = join(baseDir, "components", component, componentFileName);
289
+ if (existsSync(directPath)) return directPath;
290
+ const componentsDir = join(baseDir, "components");
291
+ const directories = [
292
+ componentsDir,
293
+ ...getAllSubdirectoriesRecursive(componentsDir)
294
+ ];
295
+ for (const dir of directories) {
296
+ const possiblePath = join(dir, component, componentFileName);
297
+ if (existsSync(possiblePath)) return possiblePath;
298
+ }
299
+ return void 0;
263
300
  };
264
301
  var Namespaces = class {
265
302
  namespaces;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "storybook-addon-sdc",
3
- "version": "0.14.2",
3
+ "version": "0.15.2",
4
4
  "description": "Drupal Single Directory Components as stories",
5
5
  "keywords": [
6
6
  "SDC",