storybook-addon-sdc 0.2.6 → 0.2.7
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 +67 -79
- package/package.json +2 -1
package/dist/preset.js
CHANGED
|
@@ -5485,24 +5485,26 @@ init_esm_shims();
|
|
|
5485
5485
|
init_esm_shims();
|
|
5486
5486
|
var import_yaml2 = __toESM(require_yaml(), 1);
|
|
5487
5487
|
import { readdirSync, readFileSync as readFileSync2, existsSync } from "fs";
|
|
5488
|
-
import { dirname as dirname2, extname, resolve as resolve2
|
|
5488
|
+
import { dirname as dirname2, extname, join, resolve as resolve2 } from "path";
|
|
5489
5489
|
|
|
5490
5490
|
// src/argsGenerator.ts
|
|
5491
5491
|
init_esm_shims();
|
|
5492
5492
|
import { JSONSchemaFaker } from "json-schema-faker";
|
|
5493
5493
|
var generateArgs = (schema, defs) => {
|
|
5494
|
-
|
|
5495
|
-
|
|
5496
|
-
|
|
5497
|
-
|
|
5498
|
-
}
|
|
5499
|
-
return generated;
|
|
5494
|
+
return Object.entries(schema).reduce((acc, [key, property]) => {
|
|
5495
|
+
acc[key] = JSONSchemaFaker.generate(property, defs);
|
|
5496
|
+
return acc;
|
|
5497
|
+
}, {});
|
|
5500
5498
|
};
|
|
5501
|
-
var
|
|
5502
|
-
|
|
5503
|
-
|
|
5504
|
-
|
|
5505
|
-
|
|
5499
|
+
var slotsToSchemaProperties = (slots) => {
|
|
5500
|
+
return Object.fromEntries(
|
|
5501
|
+
Object.entries(slots).map(([key, value]) => [
|
|
5502
|
+
key,
|
|
5503
|
+
{ type: "string", ...value }
|
|
5504
|
+
])
|
|
5505
|
+
);
|
|
5506
|
+
};
|
|
5507
|
+
function generateStorybookArgs(content, jsonSchemaFakerOptions) {
|
|
5506
5508
|
JSONSchemaFaker.option({
|
|
5507
5509
|
ignoreMissingRefs: true,
|
|
5508
5510
|
failOnInvalidTypes: false,
|
|
@@ -5510,12 +5512,13 @@ var argsGenerator_default = (content, jsonSchemaFakerOptions) => {
|
|
|
5510
5512
|
useDefaultValue: true,
|
|
5511
5513
|
...jsonSchemaFakerOptions
|
|
5512
5514
|
});
|
|
5515
|
+
const { props, slots, $defs } = content;
|
|
5513
5516
|
const generatedArgs = {
|
|
5514
|
-
...
|
|
5515
|
-
...
|
|
5517
|
+
...props?.properties && generateArgs(props.properties, $defs),
|
|
5518
|
+
...slots && generateArgs(slotsToSchemaProperties(slots), $defs)
|
|
5516
5519
|
};
|
|
5517
5520
|
return generatedArgs;
|
|
5518
|
-
}
|
|
5521
|
+
}
|
|
5519
5522
|
|
|
5520
5523
|
// src/argTypesGenerator.ts
|
|
5521
5524
|
init_esm_shims();
|
|
@@ -5536,43 +5539,34 @@ var argTypesGenerator_default = (content) => {
|
|
|
5536
5539
|
|
|
5537
5540
|
// src/storiesGenerator.ts
|
|
5538
5541
|
init_esm_shims();
|
|
5539
|
-
var storiesGenerator_default = (stories) =>
|
|
5540
|
-
|
|
5541
|
-
|
|
5542
|
-
|
|
5543
|
-
|
|
5544
|
-
|
|
5545
|
-
|
|
5546
|
-
|
|
5547
|
-
|
|
5548
|
-
|
|
5549
|
-
|
|
5550
|
-
},
|
|
5551
|
-
};
|
|
5552
|
-
`
|
|
5553
|
-
).join("\n");
|
|
5542
|
+
var storiesGenerator_default = (stories) => Object.entries(stories).map(
|
|
5543
|
+
([storyKey, { props = {}, slots = {} }]) => `
|
|
5544
|
+
export const ${storyKey} = {
|
|
5545
|
+
args: {
|
|
5546
|
+
...Basic.args,
|
|
5547
|
+
${generateArgs2(props)}
|
|
5548
|
+
${generateArgs2(slots, true)}
|
|
5549
|
+
},
|
|
5550
|
+
play: async ({ canvasElement }) => {
|
|
5551
|
+
Drupal.attachBehaviors(canvasElement, window.drupalSettings);
|
|
5552
|
+
},
|
|
5554
5553
|
};
|
|
5555
|
-
|
|
5556
|
-
|
|
5557
|
-
|
|
5558
|
-
|
|
5559
|
-
|
|
5560
|
-
|
|
5561
|
-
)
|
|
5562
|
-
|
|
5563
|
-
|
|
5564
|
-
|
|
5565
|
-
|
|
5566
|
-
return `${argString},`;
|
|
5567
|
-
}).join("\n");
|
|
5554
|
+
`
|
|
5555
|
+
).join("\n");
|
|
5556
|
+
var generateArgs2 = (args, isSlot = false) => Object.entries(args).map(([key, value]) => `${key}: ${formatArgValue(value, isSlot)},`).join("\n");
|
|
5557
|
+
var formatArgValue = (value, isSlot) => {
|
|
5558
|
+
if (Array.isArray(value)) {
|
|
5559
|
+
const arrayContent = value.map(
|
|
5560
|
+
(item) => item?.type === "component" ? generateComponent(item) : JSON.stringify(item)
|
|
5561
|
+
).join(isSlot ? " + " : ", ");
|
|
5562
|
+
return `[${arrayContent}]`;
|
|
5563
|
+
}
|
|
5564
|
+
return JSON.stringify(value);
|
|
5568
5565
|
};
|
|
5569
5566
|
var generateComponent = (item) => {
|
|
5570
|
-
const componentName = item.component.split(":").pop();
|
|
5567
|
+
const componentName = item.component.split(":").pop() ?? "unknown";
|
|
5571
5568
|
const kebabCaseName = componentName.replace(/-/g, "");
|
|
5572
|
-
const componentProps = {
|
|
5573
|
-
...item.props,
|
|
5574
|
-
...item.slots
|
|
5575
|
-
};
|
|
5569
|
+
const componentProps = { ...item.props, ...item.slots };
|
|
5576
5570
|
return `${kebabCaseName}.component(${JSON.stringify(componentProps)})`;
|
|
5577
5571
|
};
|
|
5578
5572
|
|
|
@@ -5602,52 +5596,46 @@ var componentMetadata_default = (id, content) => {
|
|
|
5602
5596
|
};
|
|
5603
5597
|
|
|
5604
5598
|
// src/vite-plugin-storybook-yaml-stories.ts
|
|
5605
|
-
var readCDC = (
|
|
5606
|
-
var getSubdirectories = (baseDir) => readdirSync(baseDir, { withFileTypes: true }).filter((
|
|
5599
|
+
var readCDC = (filePath) => customRefsTransform_default((0, import_yaml2.parse)(readFileSync2(filePath, "utf8")));
|
|
5600
|
+
var getSubdirectories = (baseDir) => readdirSync(baseDir, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => join(baseDir, entry.name));
|
|
5607
5601
|
var resolveComponentPath = (namespace, component) => {
|
|
5608
|
-
const
|
|
5609
|
-
const directories = [
|
|
5602
|
+
const baseDir = resolve2("./components");
|
|
5603
|
+
const directories = [baseDir, ...getSubdirectories(baseDir)];
|
|
5610
5604
|
const possiblePaths = directories.map(
|
|
5611
5605
|
(dir) => join(dir, component, `${component}.component.yml`)
|
|
5612
5606
|
);
|
|
5613
5607
|
return possiblePaths.find(existsSync);
|
|
5614
5608
|
};
|
|
5615
|
-
var generateImports = (directory) => readdirSync(directory).
|
|
5616
|
-
|
|
5609
|
+
var generateImports = (directory) => readdirSync(directory).filter(
|
|
5610
|
+
(asset) => [".css", ".js", ".mjs", ".twig"].includes(extname(asset))
|
|
5611
|
+
).map((asset) => {
|
|
5617
5612
|
const assetPath = `./${asset}`;
|
|
5618
|
-
|
|
5619
|
-
|
|
5620
|
-
`;
|
|
5621
|
-
} else if (extension === ".twig") {
|
|
5622
|
-
return `${imports}import COMPONENT from '${assetPath}';
|
|
5623
|
-
`;
|
|
5624
|
-
}
|
|
5625
|
-
return imports;
|
|
5626
|
-
}, "");
|
|
5613
|
+
return extname(asset) === ".twig" ? `import COMPONENT from '${assetPath}';` : `import '${assetPath}';`;
|
|
5614
|
+
}).join("\n");
|
|
5627
5615
|
var dynamicImports = (stories) => {
|
|
5628
5616
|
const imports = /* @__PURE__ */ new Set();
|
|
5629
5617
|
const findComponentArgs = (args) => {
|
|
5630
|
-
|
|
5631
|
-
const value = args[key];
|
|
5618
|
+
Object.values(args).forEach((value) => {
|
|
5632
5619
|
if (Array.isArray(value)) {
|
|
5633
5620
|
value.forEach((item) => {
|
|
5634
5621
|
if (item.type === "component") {
|
|
5635
5622
|
const [namespace, componentName] = item.component.split(":");
|
|
5636
5623
|
const resolvedPath = resolveComponentPath(namespace, componentName);
|
|
5637
5624
|
if (resolvedPath) {
|
|
5638
|
-
|
|
5639
|
-
|
|
5625
|
+
imports.add(
|
|
5626
|
+
`import ${componentName.replace(/-/g, "")} from '${resolvedPath}';`
|
|
5627
|
+
);
|
|
5640
5628
|
}
|
|
5641
5629
|
}
|
|
5642
5630
|
});
|
|
5643
|
-
} else if (typeof value === "object"
|
|
5631
|
+
} else if (value && typeof value === "object") {
|
|
5644
5632
|
findComponentArgs(value);
|
|
5645
5633
|
}
|
|
5646
|
-
}
|
|
5634
|
+
});
|
|
5647
5635
|
};
|
|
5648
|
-
Object.values(stories).forEach(
|
|
5649
|
-
findComponentArgs({ ...slots, ...props })
|
|
5650
|
-
|
|
5636
|
+
Object.values(stories).forEach(
|
|
5637
|
+
({ slots = {}, props = {} }) => findComponentArgs({ ...slots, ...props })
|
|
5638
|
+
);
|
|
5651
5639
|
return Array.from(imports).join("\n");
|
|
5652
5640
|
};
|
|
5653
5641
|
var vite_plugin_storybook_yaml_stories_default = ({ jsonSchemaFakerOptions = {} }) => ({
|
|
@@ -5659,19 +5647,16 @@ var vite_plugin_storybook_yaml_stories_default = ({ jsonSchemaFakerOptions = {}
|
|
|
5659
5647
|
const storiesImports = dynamicImports(
|
|
5660
5648
|
content.thirdPartySettings?.sdcStorybook?.stories || {}
|
|
5661
5649
|
);
|
|
5650
|
+
const metadata = componentMetadata_default(id, content);
|
|
5662
5651
|
const argTypes = {
|
|
5663
5652
|
componentMetadata: { table: { disable: true } },
|
|
5664
5653
|
...argTypesGenerator_default(content)
|
|
5665
5654
|
};
|
|
5666
|
-
const metadata = componentMetadata_default(id, content);
|
|
5667
5655
|
const args = {
|
|
5668
5656
|
componentMetadata: metadata,
|
|
5669
|
-
...
|
|
5670
|
-
};
|
|
5671
|
-
const basicArgs = {
|
|
5672
|
-
componentMetadata: metadata,
|
|
5673
|
-
...argsGenerator_default(content, jsonSchemaFakerOptions)
|
|
5657
|
+
...generateStorybookArgs(content, jsonSchemaFakerOptions)
|
|
5674
5658
|
};
|
|
5659
|
+
const basicArgs = { ...args };
|
|
5675
5660
|
const stories = content.thirdPartySettings?.sdcStorybook?.stories ? storiesGenerator_default(content.thirdPartySettings.sdcStorybook.stories) : "";
|
|
5676
5661
|
return `
|
|
5677
5662
|
${imports}
|
|
@@ -5766,7 +5751,10 @@ function viteFinal(config, options) {
|
|
|
5766
5751
|
}
|
|
5767
5752
|
});
|
|
5768
5753
|
}
|
|
5769
|
-
var experimental_indexers = async (existingIndexers) => [
|
|
5754
|
+
var experimental_indexers = async (existingIndexers) => [
|
|
5755
|
+
...existingIndexers || [],
|
|
5756
|
+
yamlStoriesIndexer
|
|
5757
|
+
];
|
|
5770
5758
|
var previewHead = (head) => `
|
|
5771
5759
|
<style>
|
|
5772
5760
|
.visually-hidden {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "storybook-addon-sdc",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
4
4
|
"description": "Drupal Single Directory Components as stories",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"SDC",
|
|
@@ -49,6 +49,7 @@
|
|
|
49
49
|
"@storybook/types": "^8.4.4",
|
|
50
50
|
"@types/json-schema": "^7.0.15",
|
|
51
51
|
"@types/node": "^22.8.7",
|
|
52
|
+
"@types/twig": "^1.12.16",
|
|
52
53
|
"auto": "^11.3.0",
|
|
53
54
|
"boxen": "^8.0.1",
|
|
54
55
|
"dedent": "^1.5.1",
|