storybook-addon-sdc 0.0.19 → 0.1.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 +9 -17
- package/dist/preset.js +53 -53
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -151,36 +151,28 @@ thirdPartySettings:
|
|
|
151
151
|
stories:
|
|
152
152
|
preview:
|
|
153
153
|
title: Preview
|
|
154
|
-
|
|
154
|
+
props:
|
|
155
155
|
html_tag: "div"
|
|
156
|
+
slots:
|
|
156
157
|
content:
|
|
157
158
|
- type: component
|
|
158
159
|
component: "umami:title"
|
|
159
|
-
|
|
160
|
+
props:
|
|
160
161
|
label: test
|
|
161
162
|
- type: component
|
|
162
163
|
component: "umami:read-more"
|
|
163
|
-
|
|
164
|
+
slots:
|
|
164
165
|
text: test
|
|
165
|
-
url: '#'
|
|
166
166
|
preview2:
|
|
167
|
-
title:
|
|
168
|
-
|
|
167
|
+
title: Preview2
|
|
168
|
+
props:
|
|
169
169
|
html_tag: "div"
|
|
170
|
+
slots:
|
|
170
171
|
content:
|
|
171
172
|
- type: component
|
|
172
173
|
component: "umami:title"
|
|
173
|
-
|
|
174
|
-
label:
|
|
175
|
-
extra_classes:
|
|
176
|
-
- 'card__title'
|
|
177
|
-
- type: component
|
|
178
|
-
component: "umami:read-more"
|
|
179
|
-
args:
|
|
180
|
-
text: test
|
|
181
|
-
url: '#'
|
|
182
|
-
extra_classes:
|
|
183
|
-
- 'card__read-more'
|
|
174
|
+
props:
|
|
175
|
+
label: test2
|
|
184
176
|
```
|
|
185
177
|
|
|
186
178
|
|
package/dist/preset.js
CHANGED
|
@@ -5478,7 +5478,7 @@ init_esm_shims();
|
|
|
5478
5478
|
// src/vite-plugin-storybook-yaml-stories.ts
|
|
5479
5479
|
init_esm_shims();
|
|
5480
5480
|
var import_yaml = __toESM(require_yaml(), 1);
|
|
5481
|
-
import { readdirSync, readFileSync } from "fs";
|
|
5481
|
+
import { readdirSync, readFileSync, existsSync } from "fs";
|
|
5482
5482
|
import { dirname, extname, relative, resolve, join } from "path";
|
|
5483
5483
|
|
|
5484
5484
|
// src/argsGenerator.ts
|
|
@@ -5529,59 +5529,55 @@ var argTypesGenerator_default = (content) => {
|
|
|
5529
5529
|
init_esm_shims();
|
|
5530
5530
|
var storiesGenerator_default = (stories) => {
|
|
5531
5531
|
const generatedStories = [];
|
|
5532
|
-
const
|
|
5532
|
+
const extractArgsAndSlots = (input) => {
|
|
5533
|
+
const args = {};
|
|
5533
5534
|
const slots = {};
|
|
5534
|
-
for (const key in
|
|
5535
|
-
|
|
5536
|
-
|
|
5535
|
+
for (const key in input) {
|
|
5536
|
+
const value = input[key];
|
|
5537
|
+
if (Array.isArray(value)) {
|
|
5538
|
+
value.forEach((item) => {
|
|
5537
5539
|
if (item.type === "component") {
|
|
5538
5540
|
const componentName = item.component.split(":").pop();
|
|
5539
|
-
const kebabCaseName = componentName.replace(
|
|
5540
|
-
const
|
|
5541
|
-
item.
|
|
5542
|
-
|
|
5543
|
-
|
|
5544
|
-
|
|
5545
|
-
|
|
5546
|
-
slots[key] += componentContent;
|
|
5547
|
-
}
|
|
5541
|
+
const kebabCaseName = componentName.replace(/-/g, "");
|
|
5542
|
+
const componentProps = {
|
|
5543
|
+
...item.props || {},
|
|
5544
|
+
...item.slots || {}
|
|
5545
|
+
};
|
|
5546
|
+
const componentContent = `\${${kebabCaseName}.component(${JSON.stringify(componentProps)})}`;
|
|
5547
|
+
slots[key] = (slots[key] || "") + componentContent;
|
|
5548
5548
|
} else {
|
|
5549
|
-
|
|
5550
|
-
if (!slots[key]) {
|
|
5551
|
-
slots[key] = `${slotContent}`;
|
|
5552
|
-
} else {
|
|
5553
|
-
slots[key] += `${slotContent}`;
|
|
5554
|
-
}
|
|
5549
|
+
slots[key] = (slots[key] || "") + `${item}`;
|
|
5555
5550
|
}
|
|
5556
5551
|
});
|
|
5557
|
-
} else if (typeof
|
|
5558
|
-
const
|
|
5559
|
-
Object.
|
|
5560
|
-
|
|
5561
|
-
|
|
5562
|
-
} else {
|
|
5563
|
-
slots[nestedSlot] += nestedContent;
|
|
5564
|
-
}
|
|
5552
|
+
} else if (typeof value === "object" && value !== null) {
|
|
5553
|
+
const nested = extractArgsAndSlots(value);
|
|
5554
|
+
Object.assign(args, nested.args);
|
|
5555
|
+
Object.entries(nested.slots).forEach(([nestedKey, nestedContent]) => {
|
|
5556
|
+
slots[nestedKey] = (slots[nestedKey] || "") + nestedContent;
|
|
5565
5557
|
});
|
|
5566
5558
|
} else {
|
|
5567
|
-
|
|
5559
|
+
args[key] = value;
|
|
5568
5560
|
}
|
|
5569
5561
|
}
|
|
5570
|
-
return slots;
|
|
5562
|
+
return { args, slots };
|
|
5571
5563
|
};
|
|
5572
5564
|
Object.entries(stories).forEach(([storyKey, story]) => {
|
|
5573
|
-
const slots =
|
|
5574
|
-
|
|
5575
|
-
|
|
5576
|
-
|
|
5565
|
+
const { args, slots } = extractArgsAndSlots(story);
|
|
5566
|
+
Object.entries(slots).forEach(([slotName, content]) => {
|
|
5567
|
+
args[slotName] = `${content}`;
|
|
5568
|
+
});
|
|
5569
|
+
generatedStories.push(`
|
|
5570
|
+
export const ${storyKey} = {
|
|
5577
5571
|
args: {
|
|
5578
|
-
${
|
|
5572
|
+
${Object.entries(args).map(
|
|
5573
|
+
([key, value]) => key === "content" ? `"${key}": \`${value}\`` : `"${key}": ${JSON.stringify(value)}`
|
|
5574
|
+
).join(",\n")}
|
|
5579
5575
|
},
|
|
5580
5576
|
play: async ({ canvasElement }) => {
|
|
5581
5577
|
Drupal.attachBehaviors(canvasElement, window.drupalSettings);
|
|
5582
5578
|
},
|
|
5583
|
-
}
|
|
5584
|
-
);
|
|
5579
|
+
};
|
|
5580
|
+
`);
|
|
5585
5581
|
});
|
|
5586
5582
|
return generatedStories.join("\n");
|
|
5587
5583
|
};
|
|
@@ -5598,19 +5594,22 @@ var resolveComponentPath = (namespace, component) => {
|
|
|
5598
5594
|
...getSubdirectories(baseComponentDir)
|
|
5599
5595
|
];
|
|
5600
5596
|
const possiblePaths = componentDirectories.map(
|
|
5601
|
-
(dir) =>
|
|
5597
|
+
(dir) => join(dir, component, `${component}.component.yml`)
|
|
5602
5598
|
);
|
|
5603
|
-
return possiblePaths.find((path) =>
|
|
5599
|
+
return possiblePaths.find((path) => existsSync(path));
|
|
5604
5600
|
};
|
|
5605
5601
|
var generateImports = (directory) => {
|
|
5606
5602
|
const assets = readdirSync(directory);
|
|
5607
5603
|
return assets.reduce((imports, asset) => {
|
|
5608
5604
|
const assetPath = `./${asset}`;
|
|
5609
|
-
|
|
5610
|
-
|
|
5605
|
+
const extension = extname(asset);
|
|
5606
|
+
if ([".css", ".js"].includes(extension)) {
|
|
5607
|
+
return `${imports} import '${assetPath}';
|
|
5608
|
+
`;
|
|
5611
5609
|
}
|
|
5612
|
-
if (
|
|
5613
|
-
return `${imports} import COMPONENT from '${assetPath}'
|
|
5610
|
+
if (extension === ".twig") {
|
|
5611
|
+
return `${imports} import COMPONENT from '${assetPath}';
|
|
5612
|
+
`;
|
|
5614
5613
|
}
|
|
5615
5614
|
return imports;
|
|
5616
5615
|
}, "");
|
|
@@ -5619,24 +5618,25 @@ var dynamicImports = (stories) => {
|
|
|
5619
5618
|
const imports = /* @__PURE__ */ new Set();
|
|
5620
5619
|
const findComponentArgs = (args) => {
|
|
5621
5620
|
for (const key in args) {
|
|
5622
|
-
|
|
5623
|
-
|
|
5621
|
+
const value = args[key];
|
|
5622
|
+
if (Array.isArray(value)) {
|
|
5623
|
+
value.forEach((item) => {
|
|
5624
5624
|
if (item.type === "component") {
|
|
5625
5625
|
const [namespace, componentName] = item.component.split(":");
|
|
5626
5626
|
const resolvedPath = resolveComponentPath(namespace, componentName);
|
|
5627
5627
|
if (resolvedPath) {
|
|
5628
|
-
const kebabCaseName = componentName.replace(/
|
|
5628
|
+
const kebabCaseName = componentName.replace(/[-]/g, "");
|
|
5629
5629
|
imports.add(`import ${kebabCaseName} from '${resolvedPath}';`);
|
|
5630
5630
|
}
|
|
5631
5631
|
}
|
|
5632
5632
|
});
|
|
5633
|
-
} else if (typeof
|
|
5634
|
-
findComponentArgs(
|
|
5633
|
+
} else if (typeof value === "object" && value !== null) {
|
|
5634
|
+
findComponentArgs(value);
|
|
5635
5635
|
}
|
|
5636
5636
|
}
|
|
5637
5637
|
};
|
|
5638
5638
|
Object.entries(stories).forEach(([_, story]) => {
|
|
5639
|
-
findComponentArgs(story.
|
|
5639
|
+
findComponentArgs(story.slots || {});
|
|
5640
5640
|
});
|
|
5641
5641
|
return Array.from(imports).join("\n");
|
|
5642
5642
|
};
|
|
@@ -5645,7 +5645,7 @@ var vite_plugin_storybook_yaml_stories_default = async ({ jsonSchemaFakerOptions
|
|
|
5645
5645
|
name: "vite-plugin-storybook-yaml-stories",
|
|
5646
5646
|
async load(id) {
|
|
5647
5647
|
if (!id.endsWith("component.yml")) return;
|
|
5648
|
-
const content =
|
|
5648
|
+
const content = readCDC(id);
|
|
5649
5649
|
const imports = generateImports(dirname(id));
|
|
5650
5650
|
const storiesImports = dynamicImports(
|
|
5651
5651
|
content.thirdPartySettings?.sdcStorybook?.stories || {}
|
|
@@ -5664,7 +5664,7 @@ var vite_plugin_storybook_yaml_stories_default = async ({ jsonSchemaFakerOptions
|
|
|
5664
5664
|
},
|
|
5665
5665
|
...argsGenerator_default(content, jsonSchemaFakerOptions)
|
|
5666
5666
|
};
|
|
5667
|
-
const stories = content.thirdPartySettings?.sdcStorybook
|
|
5667
|
+
const stories = content.thirdPartySettings?.sdcStorybook?.stories ? storiesGenerator_default(content.thirdPartySettings.sdcStorybook.stories) : "";
|
|
5668
5668
|
return `
|
|
5669
5669
|
${imports}
|
|
5670
5670
|
${storiesImports}
|
|
@@ -5689,7 +5689,7 @@ ${stories}
|
|
|
5689
5689
|
var yamlStoriesIndexer = {
|
|
5690
5690
|
test: /component\.yml$/,
|
|
5691
5691
|
createIndex: async (fileName, { makeTitle }) => {
|
|
5692
|
-
const content =
|
|
5692
|
+
const content = readCDC(fileName);
|
|
5693
5693
|
const baseTitle = makeTitle(`SDC/${content.name}`);
|
|
5694
5694
|
const storiesIndex = [
|
|
5695
5695
|
{
|
|
@@ -5701,7 +5701,7 @@ var yamlStoriesIndexer = {
|
|
|
5701
5701
|
];
|
|
5702
5702
|
const stories = content.thirdPartySettings?.sdcStorybook?.stories;
|
|
5703
5703
|
if (stories) {
|
|
5704
|
-
Object.entries(stories).forEach(([storyKey,
|
|
5704
|
+
Object.entries(stories).forEach(([storyKey, _]) => {
|
|
5705
5705
|
storiesIndex.push({
|
|
5706
5706
|
type: "story",
|
|
5707
5707
|
importPath: fileName,
|