storybook-addon-sdc 0.23.2 → 0.24.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 +41 -0
- package/dist/preset.js +155 -59
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,6 +19,7 @@ This addon streamlines the integration of Drupal Single Directory Components (SD
|
|
|
19
19
|
- [Regular Storybook](#regular-storybook)
|
|
20
20
|
- [Configuration Options](#configuration-options)
|
|
21
21
|
- [Setting Default Values](#setting-default-values)
|
|
22
|
+
- [`dependencyMap`](#dependencymap)
|
|
22
23
|
- [Story Configuration via thirdPartySettings.sdcStorybook](#story-configuration-via-thirdpartysettingssdcstorybook)
|
|
23
24
|
- [UI Patterns](#ui-patterns)
|
|
24
25
|
- [Why Choose SDC Storybook Over Alternatives?](#why-choose-sdc-storybook-over-alternatives)
|
|
@@ -50,6 +51,7 @@ The SDC Storybook Addon simplifies the integration of Drupal Single Directory Co
|
|
|
50
51
|
- **Default and Custom Story Rendering**: Use `type: component` to nest components, `type: element` for HTML markup, and `type: image` for images within stories. Or create your own custom renderers.
|
|
51
52
|
- **Namespaces**: Supports multiple namespaces, allowing you to use components from different(parent/sibling) directories or packages.
|
|
52
53
|
- **Drupal Icon API**: Automatically detects `*.icons.yml` files in registered namespaces and makes `{{ icon('pack_id', 'icon_id', settings) }}` available in every Twig template. Supports `svg_sprite`, `svg` (inline), and `path` extractors with no configuration required.
|
|
54
|
+
- **Drupal Library CDN Resolution**: Resolves Drupal library dependencies (e.g. `core/jquery`) to CDN assets via `dependencyMap`. Assets are injected per-component — only when a story uses a component that declares the dependency in `libraryOverrides.dependencies`. Built-in defaults cover the Drupal runtime (`core/drupal`, `core/once`, etc.).
|
|
53
55
|
|
|
54
56
|
## Quickstart Guide
|
|
55
57
|
|
|
@@ -547,6 +549,7 @@ export const Basic = {}
|
|
|
547
549
|
- **externalDefs**: An array of URLs or local file paths to external schema definition files.
|
|
548
550
|
- **validate**: A URL or path to a JSON schema for validating your SDC components.
|
|
549
551
|
- **useBasicArgsForStories**: Boolean. When `true` (default) generated stories inherit `...Basic.args` from the component; set to `false` to prevent automatic spreading of `Basic.args`.
|
|
552
|
+
- **dependencyMap**: Maps Drupal library names to CDN assets. See [`dependencyMap`](#dependencymap).
|
|
550
553
|
|
|
551
554
|
### Twig.js with `vitePluginTwigDrupalOptions`
|
|
552
555
|
|
|
@@ -686,6 +689,44 @@ useBasicArgsForStories: false,
|
|
|
686
689
|
|
|
687
690
|
When set to `false`, the generated stories will not inherit the `Basic.args`, allowing you to define story-specific arguments without the influence of the default `Basic` configuration.
|
|
688
691
|
|
|
692
|
+
### `dependencyMap`
|
|
693
|
+
|
|
694
|
+
Maps Drupal library dependency names to CDN assets to inject into the Storybook preview.
|
|
695
|
+
|
|
696
|
+
The addon ships with a built-in `DEFAULT_DEPENDENCY_MAP` covering the Drupal runtime — these are always injected into every preview page:
|
|
697
|
+
|
|
698
|
+
| Key | Assets |
|
|
699
|
+
| --------------------- | ------------------------------------------------ |
|
|
700
|
+
| `system/base/hidden` | `hidden.module.css` (`.visually-hidden` utility) |
|
|
701
|
+
| `core/drupalSettings` | `drupalSettingsLoader.js` |
|
|
702
|
+
| `core/drupal` | `drupal.js`, `drupal.init.js` |
|
|
703
|
+
| `core/once` | `once.min.js` |
|
|
704
|
+
|
|
705
|
+
User-provided entries are injected **per-component** — only when a component declares that dependency in `libraryOverrides.dependencies`. This means `core/jquery` only loads when a story actually uses a component that needs it.
|
|
706
|
+
|
|
707
|
+
```js
|
|
708
|
+
sdcStorybookOptions: {
|
|
709
|
+
dependencyMap: {
|
|
710
|
+
// Add a new dependency
|
|
711
|
+
'core/jquery': [{ type: 'js', url: 'https://cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js' }],
|
|
712
|
+
// Override a built-in default
|
|
713
|
+
'core/once': [{ type: 'js', url: 'https://cdn.example.com/once@2.min.js' }],
|
|
714
|
+
// Disable a built-in default
|
|
715
|
+
'system/base/hidden': [],
|
|
716
|
+
},
|
|
717
|
+
}
|
|
718
|
+
```
|
|
719
|
+
|
|
720
|
+
In the component YAML, declare the dependency as usual:
|
|
721
|
+
|
|
722
|
+
```yaml
|
|
723
|
+
libraryOverrides:
|
|
724
|
+
dependencies:
|
|
725
|
+
- core/jquery
|
|
726
|
+
```
|
|
727
|
+
|
|
728
|
+
---
|
|
729
|
+
|
|
689
730
|
## Setting Default Values
|
|
690
731
|
|
|
691
732
|
For `json-schema-faker` to generate reliable data, use `default` or `examples` in your SDC schema:
|
package/dist/preset.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// src/preset.ts
|
|
2
|
-
import { existsSync as
|
|
2
|
+
import { existsSync as existsSync5, statSync as statSync2 } from "fs";
|
|
3
3
|
import { join as join5, dirname as dirname5, relative as relative4 } from "path";
|
|
4
4
|
|
|
5
5
|
// src/vite-plugin-storybook-yaml-stories.ts
|
|
6
|
-
import { readdirSync as readdirSync2, readFileSync } from "fs";
|
|
6
|
+
import { readdirSync as readdirSync2, readFileSync, existsSync as existsSync2 } from "fs";
|
|
7
7
|
import { parse as parseYaml } from "yaml";
|
|
8
|
-
import { join as join2, basename as basename2, dirname as dirname3
|
|
8
|
+
import { join as join2, basename as basename2, dirname as dirname3 } from "path";
|
|
9
9
|
|
|
10
10
|
// src/logger.ts
|
|
11
11
|
import pino from "pino";
|
|
@@ -475,28 +475,25 @@ var readSDC = (filePath, defs, validate) => {
|
|
|
475
475
|
}
|
|
476
476
|
return sdcSchema;
|
|
477
477
|
};
|
|
478
|
-
var
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
return `import COMPONENT from '${namespace}/${file}';`;
|
|
478
|
+
var VIRTUAL_ASSET_INJECTOR = "virtual:sdc-asset-injector";
|
|
479
|
+
var VIRTUAL_ASSET_INJECTOR_ID = "\0" + VIRTUAL_ASSET_INJECTOR;
|
|
480
|
+
var assetInjectorModule = `
|
|
481
|
+
export async function injectAssets(assets) {
|
|
482
|
+
if (typeof document === 'undefined') return
|
|
483
|
+
await Promise.all(assets.map((asset) => {
|
|
484
|
+
const sel = asset.type === 'js' ? \`script[src="\${asset.url}"]\` : \`link[href="\${asset.url}"]\`
|
|
485
|
+
if (document.querySelector(sel)) return Promise.resolve()
|
|
486
|
+
return new Promise((res, rej) => {
|
|
487
|
+
if (asset.type === 'js') {
|
|
488
|
+
const s = document.createElement('script'); s.src = asset.url; s.onload = res; s.onerror = rej; document.head.appendChild(s)
|
|
489
|
+
} else {
|
|
490
|
+
const l = document.createElement('link'); l.rel = 'stylesheet'; l.href = asset.url
|
|
491
|
+
if (asset.media) l.media = asset.media; l.onload = res; document.head.appendChild(l)
|
|
493
492
|
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
}).filter(Boolean).join("\n");
|
|
499
|
-
};
|
|
493
|
+
})
|
|
494
|
+
}))
|
|
495
|
+
}
|
|
496
|
+
`;
|
|
500
497
|
var dynamicImports = (stories, namespaces) => {
|
|
501
498
|
const imports = /* @__PURE__ */ new Set();
|
|
502
499
|
const importComponent = (item) => {
|
|
@@ -533,6 +530,54 @@ var dynamicImports = (stories, namespaces) => {
|
|
|
533
530
|
);
|
|
534
531
|
return Array.from(imports).join("\n");
|
|
535
532
|
};
|
|
533
|
+
var CSS_GROUPS = ["base", "layout", "component", "state", "theme"];
|
|
534
|
+
var isExternalUrl = (s) => s.startsWith("http://") || s.startsWith("https://");
|
|
535
|
+
var extractCssAssets = (library) => CSS_GROUPS.flatMap(
|
|
536
|
+
(group) => Object.entries(library.css?.[group] ?? {}).filter(([url]) => isExternalUrl(url)).map(
|
|
537
|
+
([url, opts]) => ({
|
|
538
|
+
type: "css",
|
|
539
|
+
url,
|
|
540
|
+
media: opts.media
|
|
541
|
+
})
|
|
542
|
+
)
|
|
543
|
+
);
|
|
544
|
+
var extractJsAssets = (library) => Object.entries(library.js ?? {}).filter(([url]) => isExternalUrl(url)).map(
|
|
545
|
+
([url, opts]) => ({
|
|
546
|
+
type: "js",
|
|
547
|
+
url,
|
|
548
|
+
attributes: opts.attributes
|
|
549
|
+
})
|
|
550
|
+
);
|
|
551
|
+
var libraryOverridesImports = (content, dependencyMap = {}) => {
|
|
552
|
+
const overrides = content.libraryOverrides;
|
|
553
|
+
if (!overrides) return [];
|
|
554
|
+
return [
|
|
555
|
+
...extractCssAssets(overrides),
|
|
556
|
+
...extractJsAssets(overrides),
|
|
557
|
+
...(overrides.dependencies ?? []).flatMap(
|
|
558
|
+
(dep) => dependencyMap[dep] ?? []
|
|
559
|
+
)
|
|
560
|
+
];
|
|
561
|
+
};
|
|
562
|
+
var twigDependencyImports = (twigFilePath, namespaces) => {
|
|
563
|
+
if (!existsSync2(twigFilePath)) return "";
|
|
564
|
+
const twigContent = readFileSync(twigFilePath, "utf8");
|
|
565
|
+
const imports = /* @__PURE__ */ new Set();
|
|
566
|
+
const pattern = /{%-?\s*(?:include|embed|extends)\s+['"]([a-zA-Z0-9_-]+:[a-zA-Z0-9_/-]+)['"]/g;
|
|
567
|
+
let match;
|
|
568
|
+
while ((match = pattern.exec(twigContent)) !== null) {
|
|
569
|
+
const [namespace, componentName] = match[1].split(":");
|
|
570
|
+
const resolvedPath = resolveComponentPath(
|
|
571
|
+
namespace,
|
|
572
|
+
componentName,
|
|
573
|
+
namespaces
|
|
574
|
+
);
|
|
575
|
+
if (resolvedPath) {
|
|
576
|
+
imports.add(`import '${resolvedPath}';`);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
return Array.from(imports).join("\n");
|
|
580
|
+
};
|
|
536
581
|
var createStoryIndex = (fileName, baseTitle, stories, disabledStories, tags) => {
|
|
537
582
|
const storiesIndex = [];
|
|
538
583
|
const isAllDisabled = disabledStories.includes("all");
|
|
@@ -569,20 +614,31 @@ var vite_plugin_storybook_yaml_stories_default = ({
|
|
|
569
614
|
namespaces = {}
|
|
570
615
|
}) => ({
|
|
571
616
|
name: "vite-plugin-storybook-yaml-stories",
|
|
617
|
+
resolveId(id) {
|
|
618
|
+
if (id === VIRTUAL_ASSET_INJECTOR) return VIRTUAL_ASSET_INJECTOR_ID;
|
|
619
|
+
},
|
|
572
620
|
async load(id) {
|
|
621
|
+
if (id === VIRTUAL_ASSET_INJECTOR_ID) return assetInjectorModule;
|
|
573
622
|
if (id.endsWith("story.yml")) {
|
|
574
623
|
return "";
|
|
575
624
|
}
|
|
576
625
|
if (!id.endsWith("component.yml")) return;
|
|
577
626
|
try {
|
|
578
627
|
const content = readSDC(id, globalDefs, sdcStorybookOptions.validate);
|
|
579
|
-
const
|
|
628
|
+
const externalAssets = libraryOverridesImports(
|
|
629
|
+
content,
|
|
630
|
+
sdcStorybookOptions.dependencyMap ?? {}
|
|
631
|
+
);
|
|
580
632
|
const previewsStories = {
|
|
581
633
|
...content.thirdPartySettings?.sdcStorybook?.stories || {},
|
|
582
634
|
...loadStoryFilesSync(id)
|
|
583
635
|
};
|
|
584
636
|
storyNodeRenderer.register(sdcStorybookOptions.storyNodesRenderer ?? []);
|
|
585
637
|
const storiesImports = dynamicImports(previewsStories, namespaces);
|
|
638
|
+
const componentBaseName = basename2(id, ".component.yml");
|
|
639
|
+
const namespace = namespaces.pathToNamespace(dirname3(id));
|
|
640
|
+
const twigFile = join2(dirname3(id), `${componentBaseName}.twig`);
|
|
641
|
+
const twigImports = twigDependencyImports(twigFile, namespaces);
|
|
586
642
|
const metadata = componentMetadata_default(id, content);
|
|
587
643
|
const componentGlobals = content?.thirdPartySettings?.sdcStorybook?.globals ?? {};
|
|
588
644
|
const argTypes = {
|
|
@@ -609,10 +665,15 @@ var vite_plugin_storybook_yaml_stories_default = ({
|
|
|
609
665
|
const args = sdcStorybookOptions.useBasicArgsForStories ? { ...baseArgs, ...generatedArgs } : baseArgs;
|
|
610
666
|
const basicArgs = sdcStorybookOptions.useBasicArgsForStories ? baseArgs : { ...baseArgs, ...generatedArgs };
|
|
611
667
|
const stories = previewsStories ? storiesGenerator_default(previewsStories, componentGlobals) : "";
|
|
668
|
+
const assetInjection = externalAssets.length > 0 ? `await injectAssets(${JSON.stringify(externalAssets)});` : "";
|
|
612
669
|
return `
|
|
613
|
-
${
|
|
670
|
+
import COMPONENT from '${namespace}/${componentBaseName}.twig';
|
|
671
|
+
void import.meta.glob('./*.css', { eager: true });
|
|
672
|
+
import { injectAssets } from '${VIRTUAL_ASSET_INJECTOR}';
|
|
614
673
|
${storiesImports}
|
|
615
|
-
|
|
674
|
+
${twigImports}
|
|
675
|
+
${assetInjection}
|
|
676
|
+
await Promise.all(Object.values(import.meta.glob('./*.{js,mjs}')).map(fn => fn()));
|
|
616
677
|
class TwigSafeArray extends Array {
|
|
617
678
|
toString() {
|
|
618
679
|
return this.join('');
|
|
@@ -621,7 +682,10 @@ class TwigSafeArray extends Array {
|
|
|
621
682
|
|
|
622
683
|
export default {
|
|
623
684
|
component: COMPONENT,
|
|
624
|
-
parameters:
|
|
685
|
+
parameters: {
|
|
686
|
+
...${JSON.stringify(content?.thirdPartySettings?.sdcStorybook?.parameters ?? {}, null, 2)},
|
|
687
|
+
docs: {description: {component: ${JSON.stringify(content.description, null, 2)}}},
|
|
688
|
+
},
|
|
625
689
|
${Object.keys(componentGlobals).length > 0 ? `globals: ${JSON.stringify(componentGlobals, null, 2)},` : ""}
|
|
626
690
|
argTypes: ${JSON.stringify(argTypes, null, 2)},
|
|
627
691
|
args: ${JSON.stringify(args, null, 2)},
|
|
@@ -745,6 +809,36 @@ async function loadAndMergeDefinitions(externalDefs, customDefs) {
|
|
|
745
809
|
}
|
|
746
810
|
|
|
747
811
|
// src/constants.ts
|
|
812
|
+
var DEFAULT_DEPENDENCY_MAP = {
|
|
813
|
+
"system/base/hidden": [
|
|
814
|
+
{
|
|
815
|
+
type: "css",
|
|
816
|
+
url: "https://cdn.jsdelivr.net/gh/drupal/drupal/core/modules/system/css/components/hidden.module.css"
|
|
817
|
+
}
|
|
818
|
+
],
|
|
819
|
+
"core/drupalSettings": [
|
|
820
|
+
{
|
|
821
|
+
type: "js",
|
|
822
|
+
url: "https://cdn.jsdelivr.net/gh/drupal/drupal/core/misc/drupalSettingsLoader.js"
|
|
823
|
+
}
|
|
824
|
+
],
|
|
825
|
+
"core/drupal": [
|
|
826
|
+
{
|
|
827
|
+
type: "js",
|
|
828
|
+
url: "https://cdn.jsdelivr.net/gh/drupal/drupal/core/misc/drupal.js"
|
|
829
|
+
},
|
|
830
|
+
{
|
|
831
|
+
type: "js",
|
|
832
|
+
url: "https://cdn.jsdelivr.net/gh/drupal/drupal/core/misc/drupal.init.js"
|
|
833
|
+
}
|
|
834
|
+
],
|
|
835
|
+
"core/once": [
|
|
836
|
+
{
|
|
837
|
+
type: "js",
|
|
838
|
+
url: "https://cdn.jsdelivr.net/npm/@drupal/once@1.0.1/dist/once.min.js"
|
|
839
|
+
}
|
|
840
|
+
]
|
|
841
|
+
};
|
|
748
842
|
var DEFAULT_ADDON_OPTIONS = {
|
|
749
843
|
sdcStorybookOptions: {
|
|
750
844
|
useBasicArgsForStories: true,
|
|
@@ -768,12 +862,12 @@ var DEFAULT_ADDON_OPTIONS = {
|
|
|
768
862
|
import { merge as lodashMerge } from "lodash-es";
|
|
769
863
|
|
|
770
864
|
// src/vite-plugin-sdc-icon-packs.ts
|
|
771
|
-
import { existsSync as
|
|
865
|
+
import { existsSync as existsSync4 } from "fs";
|
|
772
866
|
import { join as join4 } from "path";
|
|
773
867
|
|
|
774
868
|
// src/icon-packs.ts
|
|
775
|
-
import { existsSync as
|
|
776
|
-
import { join as join3, resolve as resolve2, basename as basename3, dirname as dirname4, extname
|
|
869
|
+
import { existsSync as existsSync3, readFileSync as readFileSync3, readdirSync as readdirSync3, statSync } from "fs";
|
|
870
|
+
import { join as join3, resolve as resolve2, basename as basename3, dirname as dirname4, extname, relative as relative3 } from "path";
|
|
777
871
|
import { parse as parseYaml2 } from "yaml";
|
|
778
872
|
function parseSvgFile(raw) {
|
|
779
873
|
const attrs = {};
|
|
@@ -802,7 +896,7 @@ function scanDir(dir, baseDir, filterExt) {
|
|
|
802
896
|
if (entry.isDirectory()) {
|
|
803
897
|
results.push(...scanDir(fullPath, baseDir, filterExt));
|
|
804
898
|
} else if (entry.isFile()) {
|
|
805
|
-
const ext =
|
|
899
|
+
const ext = extname(entry.name);
|
|
806
900
|
if (filterExt && ext.toLowerCase() !== filterExt.toLowerCase()) continue;
|
|
807
901
|
results.push({
|
|
808
902
|
absPath: fullPath,
|
|
@@ -823,23 +917,23 @@ function resolveSourceEntry(rawSource, nsRoot) {
|
|
|
823
917
|
const wildcardIdx = rawSource.search(/[*{]/);
|
|
824
918
|
const dirPart = wildcardIdx >= 0 ? rawSource.substring(0, wildcardIdx) : rawSource;
|
|
825
919
|
const baseDir = resolve2(nsRoot, dirPart.replace(/[/\\]$/, ""));
|
|
826
|
-
if (!rawSource.includes("*") && !rawSource.includes("{") &&
|
|
920
|
+
if (!rawSource.includes("*") && !rawSource.includes("{") && existsSync3(absPath)) {
|
|
827
921
|
try {
|
|
828
922
|
if (statSync(absPath).isFile()) {
|
|
829
923
|
return [
|
|
830
|
-
{ absPath, iconId: basename3(absPath,
|
|
924
|
+
{ absPath, iconId: basename3(absPath, extname(absPath)), group: "" }
|
|
831
925
|
];
|
|
832
926
|
}
|
|
833
927
|
} catch {
|
|
834
928
|
}
|
|
835
929
|
}
|
|
836
|
-
if (!
|
|
930
|
+
if (!existsSync3(baseDir)) return [];
|
|
837
931
|
return scanDir(baseDir, baseDir, filterExt);
|
|
838
932
|
}
|
|
839
933
|
function loadIconPackFile(iconsFilePath) {
|
|
840
934
|
const watchFiles = [iconsFilePath];
|
|
841
935
|
const packs = {};
|
|
842
|
-
if (!
|
|
936
|
+
if (!existsSync3(iconsFilePath)) return { packs, watchFiles };
|
|
843
937
|
const nsRoot = dirname4(iconsFilePath);
|
|
844
938
|
const ns = basename3(iconsFilePath, ".icons.yml");
|
|
845
939
|
let raw;
|
|
@@ -867,7 +961,7 @@ function loadIconPackFile(iconsFilePath) {
|
|
|
867
961
|
nsRoot,
|
|
868
962
|
src.replace(/[*{].*$/, "").replace(/[/\\]$/, "")
|
|
869
963
|
);
|
|
870
|
-
const isSpriteFile = extractor === "svg_sprite" &&
|
|
964
|
+
const isSpriteFile = extractor === "svg_sprite" && existsSync3(absFile) && statSync(absFile).isFile();
|
|
871
965
|
const finalAbs = isSpriteFile ? absFile : absBase;
|
|
872
966
|
sources.push(finalAbs);
|
|
873
967
|
sourceUrls.push(toUrl(finalAbs));
|
|
@@ -931,6 +1025,7 @@ var SHARED_HELPERS = (
|
|
|
931
1025
|
/* js */
|
|
932
1026
|
`
|
|
933
1027
|
function _sdcBuildIconContext(DrupalAttribute, pack, iconId, settings) {
|
|
1028
|
+
if (settings instanceof Map) settings = Object.fromEntries(settings);
|
|
934
1029
|
var resolved = {};
|
|
935
1030
|
var packSettings = pack.settings || {};
|
|
936
1031
|
var settingKeys = Object.keys(packSettings);
|
|
@@ -1076,7 +1171,7 @@ function iconPacksPlugin(namespaces) {
|
|
|
1076
1171
|
},
|
|
1077
1172
|
load(id) {
|
|
1078
1173
|
if (id === RESOLVED_TWIG || id === RESOLVED_TWING) {
|
|
1079
|
-
const packFilePaths = namespaces.entries().map(([ns, root]) => join4(root, `${ns}.icons.yml`)).filter((p) =>
|
|
1174
|
+
const packFilePaths = namespaces.entries().map(([ns, root]) => join4(root, `${ns}.icons.yml`)).filter((p) => existsSync4(p));
|
|
1080
1175
|
return id === RESOLVED_TWIG ? generateTwigModule(packFilePaths) : generateTwingModule(packFilePaths);
|
|
1081
1176
|
}
|
|
1082
1177
|
if (id.startsWith(PACK_PREFIX)) {
|
|
@@ -1164,6 +1259,24 @@ async function viteFinal(config, options) {
|
|
|
1164
1259
|
const { default: twig } = await import("vite-plugin-twig-drupal");
|
|
1165
1260
|
twigPlugin = twig(options.vitePluginTwigDrupalOptions);
|
|
1166
1261
|
}
|
|
1262
|
+
const userMap = sdcStorybookOptions.dependencyMap ?? {};
|
|
1263
|
+
const effectiveMap = { ...DEFAULT_DEPENDENCY_MAP, ...userMap };
|
|
1264
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1265
|
+
const headTags = Object.keys(DEFAULT_DEPENDENCY_MAP).flatMap((k) => effectiveMap[k] ?? []).filter((asset) => seen.has(asset.url) ? false : seen.add(asset.url)).map(
|
|
1266
|
+
(asset) => asset.type === "css" ? {
|
|
1267
|
+
tag: "link",
|
|
1268
|
+
attrs: {
|
|
1269
|
+
rel: "stylesheet",
|
|
1270
|
+
href: asset.url,
|
|
1271
|
+
...asset.media ? { media: asset.media } : {}
|
|
1272
|
+
},
|
|
1273
|
+
injectTo: "head"
|
|
1274
|
+
} : {
|
|
1275
|
+
tag: "script",
|
|
1276
|
+
attrs: { src: asset.url },
|
|
1277
|
+
injectTo: "head"
|
|
1278
|
+
}
|
|
1279
|
+
);
|
|
1167
1280
|
return mergeConfig(config, {
|
|
1168
1281
|
plugins: [
|
|
1169
1282
|
nodePolyfills({
|
|
@@ -1171,7 +1284,8 @@ async function viteFinal(config, options) {
|
|
|
1171
1284
|
}),
|
|
1172
1285
|
...twigPlugin ? [twigPlugin] : [],
|
|
1173
1286
|
vite_plugin_storybook_yaml_stories_default({ ...options, globalDefs, namespaces }),
|
|
1174
|
-
iconPacksPlugin(namespaces)
|
|
1287
|
+
iconPacksPlugin(namespaces),
|
|
1288
|
+
...headTags.length > 0 ? [{ name: "vite-plugin-sdc-head", transformIndexHtml: () => headTags }] : []
|
|
1175
1289
|
],
|
|
1176
1290
|
optimizeDeps: {
|
|
1177
1291
|
exclude: ["vite-plugin-twig-drupal", "vite-plugin-twing-drupal"]
|
|
@@ -1191,14 +1305,14 @@ var staticDirs = async (existing, options) => {
|
|
|
1191
1305
|
const iconDirs = [];
|
|
1192
1306
|
for (const [ns, nsRoot] of namespaces.entries()) {
|
|
1193
1307
|
const iconsFile = join5(nsRoot, `${ns}.icons.yml`);
|
|
1194
|
-
if (!
|
|
1308
|
+
if (!existsSync5(iconsFile)) continue;
|
|
1195
1309
|
const { packs } = loadIconPackFile(iconsFile);
|
|
1196
1310
|
const seen = /* @__PURE__ */ new Set();
|
|
1197
1311
|
for (const pack of Object.values(packs)) {
|
|
1198
1312
|
if (pack.extractor === "svg") continue;
|
|
1199
1313
|
for (const src of pack.sources) {
|
|
1200
1314
|
if (src.startsWith("http")) continue;
|
|
1201
|
-
if (!
|
|
1315
|
+
if (!existsSync5(src)) continue;
|
|
1202
1316
|
const dir = statSync2(src).isDirectory() ? src : dirname5(src);
|
|
1203
1317
|
if (seen.has(dir)) continue;
|
|
1204
1318
|
seen.add(dir);
|
|
@@ -1209,26 +1323,8 @@ var staticDirs = async (existing, options) => {
|
|
|
1209
1323
|
}
|
|
1210
1324
|
return [...existing || [], ...iconDirs];
|
|
1211
1325
|
};
|
|
1212
|
-
var previewHead = (head) => `
|
|
1213
|
-
<style>
|
|
1214
|
-
.visually-hidden {
|
|
1215
|
-
position: absolute !important;
|
|
1216
|
-
overflow: hidden;
|
|
1217
|
-
clip: rect(1px, 1px, 1px, 1px);
|
|
1218
|
-
width: 1px;
|
|
1219
|
-
height: 1px;
|
|
1220
|
-
word-wrap: normal;
|
|
1221
|
-
}
|
|
1222
|
-
</style>
|
|
1223
|
-
<script src="https://cdn.jsdelivr.net/gh/drupal/drupal/core/misc/drupalSettingsLoader.js"></script>
|
|
1224
|
-
<script src="https://cdn.jsdelivr.net/gh/drupal/drupal/core/misc/drupal.js"></script>
|
|
1225
|
-
<script src="https://cdn.jsdelivr.net/gh/drupal/drupal/core/misc/drupal.init.js"></script>
|
|
1226
|
-
<script src="https://cdn.jsdelivr.net/npm/@drupal/once@1.0.1/dist/once.min.js"></script>
|
|
1227
|
-
${head}
|
|
1228
|
-
`;
|
|
1229
1326
|
export {
|
|
1230
1327
|
experimental_indexers,
|
|
1231
|
-
previewHead,
|
|
1232
1328
|
staticDirs,
|
|
1233
1329
|
viteFinal
|
|
1234
1330
|
};
|