storybook-addon-sdc 0.1.3 → 0.1.5
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/dist/preset.js +73 -102
- package/package.json +1 -1
package/dist/preset.js
CHANGED
|
@@ -5528,92 +5528,65 @@ var argTypesGenerator_default = (content) => {
|
|
|
5528
5528
|
// src/storiesGenerator.ts
|
|
5529
5529
|
init_esm_shims();
|
|
5530
5530
|
var storiesGenerator_default = (stories) => {
|
|
5531
|
-
|
|
5532
|
-
const extractArgsAndSlots = (input) => {
|
|
5533
|
-
const args = {};
|
|
5534
|
-
const slots = {};
|
|
5535
|
-
for (const key in input) {
|
|
5536
|
-
const value = input[key];
|
|
5537
|
-
if (Array.isArray(value)) {
|
|
5538
|
-
value.forEach((item) => {
|
|
5539
|
-
if (item.type === "component") {
|
|
5540
|
-
const componentName = item.component.split(":").pop();
|
|
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
|
-
} else {
|
|
5549
|
-
slots[key] = (slots[key] || "") + `${item}`;
|
|
5550
|
-
}
|
|
5551
|
-
});
|
|
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;
|
|
5557
|
-
});
|
|
5558
|
-
} else {
|
|
5559
|
-
args[key] = value;
|
|
5560
|
-
}
|
|
5561
|
-
}
|
|
5562
|
-
return { args, slots };
|
|
5563
|
-
};
|
|
5564
|
-
Object.entries(stories).forEach(([storyKey, story]) => {
|
|
5565
|
-
const { args, slots } = extractArgsAndSlots(story);
|
|
5566
|
-
Object.entries(slots).forEach(([slotName, content]) => {
|
|
5567
|
-
args[slotName] = `${content}`;
|
|
5568
|
-
});
|
|
5569
|
-
generatedStories.push(`
|
|
5531
|
+
return Object.entries(stories).map(([storyKey, { props = {}, slots = {} }]) => `
|
|
5570
5532
|
export const ${storyKey} = {
|
|
5571
5533
|
args: {
|
|
5572
|
-
${
|
|
5573
|
-
|
|
5574
|
-
).join(",\n")}
|
|
5534
|
+
${generateArgs2(props)}
|
|
5535
|
+
${generateArgs2(slots, true)}
|
|
5575
5536
|
},
|
|
5576
5537
|
play: async ({ canvasElement }) => {
|
|
5577
5538
|
Drupal.attachBehaviors(canvasElement, window.drupalSettings);
|
|
5578
5539
|
},
|
|
5579
5540
|
};
|
|
5580
|
-
`);
|
|
5581
|
-
|
|
5582
|
-
|
|
5541
|
+
`).join("\n");
|
|
5542
|
+
};
|
|
5543
|
+
var generateArgs2 = (args, isSlot = false) => {
|
|
5544
|
+
return Object.entries(args).map(([key, value]) => {
|
|
5545
|
+
let argString = `${key}: `;
|
|
5546
|
+
if (Array.isArray(value)) {
|
|
5547
|
+
const arrayContent = value.map(
|
|
5548
|
+
(item) => item?.type === "component" ? generateComponent(item) : JSON.stringify(item)
|
|
5549
|
+
).join(isSlot ? " + " : ", ");
|
|
5550
|
+
argString += `[${arrayContent}]`;
|
|
5551
|
+
} else {
|
|
5552
|
+
argString += JSON.stringify(value);
|
|
5553
|
+
}
|
|
5554
|
+
return `${argString},`;
|
|
5555
|
+
}).join("\n");
|
|
5556
|
+
};
|
|
5557
|
+
var generateComponent = (item) => {
|
|
5558
|
+
const componentName = item.component.split(":").pop();
|
|
5559
|
+
const kebabCaseName = componentName.replace(/-/g, "");
|
|
5560
|
+
const componentProps = {
|
|
5561
|
+
...item.props,
|
|
5562
|
+
...item.slots
|
|
5563
|
+
};
|
|
5564
|
+
return `${kebabCaseName}.component(${JSON.stringify(componentProps)})`;
|
|
5583
5565
|
};
|
|
5584
5566
|
|
|
5585
5567
|
// src/vite-plugin-storybook-yaml-stories.ts
|
|
5586
5568
|
var readCDC = (id) => (0, import_yaml.parse)(readFileSync(id, "utf8"));
|
|
5587
|
-
var getSubdirectories = (baseDir) => {
|
|
5588
|
-
return readdirSync(baseDir, { withFileTypes: true }).filter((dirent) => dirent.isDirectory()).map((dirent) => join(baseDir, dirent.name));
|
|
5589
|
-
};
|
|
5569
|
+
var getSubdirectories = (baseDir) => readdirSync(baseDir, { withFileTypes: true }).filter((dirent) => dirent.isDirectory()).map((dirent) => join(baseDir, dirent.name));
|
|
5590
5570
|
var resolveComponentPath = (namespace, component) => {
|
|
5591
5571
|
const baseComponentDir = resolve("./components");
|
|
5592
|
-
const
|
|
5593
|
-
|
|
5594
|
-
...getSubdirectories(baseComponentDir)
|
|
5595
|
-
];
|
|
5596
|
-
const possiblePaths = componentDirectories.map(
|
|
5572
|
+
const directories = [baseComponentDir, ...getSubdirectories(baseComponentDir)];
|
|
5573
|
+
const possiblePaths = directories.map(
|
|
5597
5574
|
(dir) => join(dir, component, `${component}.component.yml`)
|
|
5598
5575
|
);
|
|
5599
|
-
return possiblePaths.find(
|
|
5576
|
+
return possiblePaths.find(existsSync);
|
|
5600
5577
|
};
|
|
5601
|
-
var generateImports = (directory) => {
|
|
5602
|
-
const
|
|
5603
|
-
|
|
5604
|
-
|
|
5605
|
-
|
|
5606
|
-
if ([".css", ".js", ".mjs"].includes(extension)) {
|
|
5607
|
-
return `${imports} import '${assetPath}';
|
|
5578
|
+
var generateImports = (directory) => readdirSync(directory).reduce((imports, asset) => {
|
|
5579
|
+
const extension = extname(asset);
|
|
5580
|
+
const assetPath = `./${asset}`;
|
|
5581
|
+
if ([".css", ".js", ".mjs"].includes(extension)) {
|
|
5582
|
+
return `${imports}import '${assetPath}';
|
|
5608
5583
|
`;
|
|
5609
|
-
|
|
5610
|
-
|
|
5611
|
-
return `${imports} import COMPONENT from '${assetPath}';
|
|
5584
|
+
} else if (extension === ".twig") {
|
|
5585
|
+
return `${imports}import COMPONENT from '${assetPath}';
|
|
5612
5586
|
`;
|
|
5613
|
-
|
|
5614
|
-
|
|
5615
|
-
|
|
5616
|
-
};
|
|
5587
|
+
}
|
|
5588
|
+
return imports;
|
|
5589
|
+
}, "");
|
|
5617
5590
|
var dynamicImports = (stories) => {
|
|
5618
5591
|
const imports = /* @__PURE__ */ new Set();
|
|
5619
5592
|
const findComponentArgs = (args) => {
|
|
@@ -5625,7 +5598,7 @@ var dynamicImports = (stories) => {
|
|
|
5625
5598
|
const [namespace, componentName] = item.component.split(":");
|
|
5626
5599
|
const resolvedPath = resolveComponentPath(namespace, componentName);
|
|
5627
5600
|
if (resolvedPath) {
|
|
5628
|
-
const kebabCaseName = componentName.replace(
|
|
5601
|
+
const kebabCaseName = componentName.replace(/-/g, "");
|
|
5629
5602
|
imports.add(`import ${kebabCaseName} from '${resolvedPath}';`);
|
|
5630
5603
|
}
|
|
5631
5604
|
}
|
|
@@ -5635,37 +5608,36 @@ var dynamicImports = (stories) => {
|
|
|
5635
5608
|
}
|
|
5636
5609
|
}
|
|
5637
5610
|
};
|
|
5638
|
-
Object.
|
|
5639
|
-
findComponentArgs(
|
|
5611
|
+
Object.values(stories).forEach(({ slots = {}, props = {} }) => {
|
|
5612
|
+
findComponentArgs({ ...slots, ...props });
|
|
5640
5613
|
});
|
|
5641
5614
|
return Array.from(imports).join("\n");
|
|
5642
5615
|
};
|
|
5643
|
-
var vite_plugin_storybook_yaml_stories_default =
|
|
5644
|
-
|
|
5645
|
-
|
|
5646
|
-
|
|
5647
|
-
|
|
5648
|
-
|
|
5649
|
-
|
|
5650
|
-
|
|
5651
|
-
|
|
5652
|
-
|
|
5653
|
-
|
|
5654
|
-
|
|
5655
|
-
|
|
5656
|
-
|
|
5657
|
-
|
|
5658
|
-
|
|
5659
|
-
|
|
5660
|
-
|
|
5661
|
-
|
|
5662
|
-
|
|
5663
|
-
|
|
5664
|
-
|
|
5665
|
-
|
|
5666
|
-
|
|
5667
|
-
|
|
5668
|
-
return `
|
|
5616
|
+
var vite_plugin_storybook_yaml_stories_default = ({ jsonSchemaFakerOptions = {} }) => ({
|
|
5617
|
+
name: "vite-plugin-storybook-yaml-stories",
|
|
5618
|
+
async load(id) {
|
|
5619
|
+
if (!id.endsWith("component.yml")) return;
|
|
5620
|
+
const content = readCDC(id);
|
|
5621
|
+
const imports = generateImports(dirname(id));
|
|
5622
|
+
const storiesImports = dynamicImports(
|
|
5623
|
+
content.thirdPartySettings?.sdcStorybook?.stories || {}
|
|
5624
|
+
);
|
|
5625
|
+
const argTypes = {
|
|
5626
|
+
componentMetadata: { table: { disable: true } },
|
|
5627
|
+
...argTypesGenerator_default(content)
|
|
5628
|
+
};
|
|
5629
|
+
const args = {
|
|
5630
|
+
componentMetadata: {
|
|
5631
|
+
path: relative(process.cwd(), dirname(id)),
|
|
5632
|
+
machineName: id,
|
|
5633
|
+
status: content.status || "stable",
|
|
5634
|
+
name: content.name,
|
|
5635
|
+
group: content.group || "All Components"
|
|
5636
|
+
},
|
|
5637
|
+
...argsGenerator_default(content, jsonSchemaFakerOptions)
|
|
5638
|
+
};
|
|
5639
|
+
const stories = content.thirdPartySettings?.sdcStorybook?.stories ? storiesGenerator_default(content.thirdPartySettings.sdcStorybook.stories) : "";
|
|
5640
|
+
return `
|
|
5669
5641
|
${imports}
|
|
5670
5642
|
${storiesImports}
|
|
5671
5643
|
|
|
@@ -5682,10 +5654,9 @@ export const Basic = {
|
|
|
5682
5654
|
};
|
|
5683
5655
|
|
|
5684
5656
|
${stories}
|
|
5685
|
-
`;
|
|
5686
|
-
|
|
5687
|
-
|
|
5688
|
-
};
|
|
5657
|
+
`;
|
|
5658
|
+
}
|
|
5659
|
+
});
|
|
5689
5660
|
var yamlStoriesIndexer = {
|
|
5690
5661
|
test: /component\.yml$/,
|
|
5691
5662
|
createIndex: async (fileName, { makeTitle }) => {
|
|
@@ -5701,7 +5672,7 @@ var yamlStoriesIndexer = {
|
|
|
5701
5672
|
];
|
|
5702
5673
|
const stories = content.thirdPartySettings?.sdcStorybook?.stories;
|
|
5703
5674
|
if (stories) {
|
|
5704
|
-
Object.
|
|
5675
|
+
Object.keys(stories).forEach((storyKey) => {
|
|
5705
5676
|
storiesIndex.push({
|
|
5706
5677
|
type: "story",
|
|
5707
5678
|
importPath: fileName,
|