storybook-addon-sdc 0.24.7 → 0.24.9
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 +54 -16
- package/package.json +1 -1
package/dist/preset.js
CHANGED
|
@@ -254,9 +254,12 @@ ${globalsBlock}
|
|
|
254
254
|
const wrapper = ${JSON.stringify(library_wrapper)};
|
|
255
255
|
if (!wrapper) return Story();
|
|
256
256
|
|
|
257
|
-
|
|
258
|
-
const
|
|
259
|
-
|
|
257
|
+
const placeholder = '___SDC_STORY___';
|
|
258
|
+
const rendered = _sdcRenderInline(
|
|
259
|
+
wrapper.replace(/\\{\\{\\s*_story\\s*\\}\\}/g, placeholder),
|
|
260
|
+
{}
|
|
261
|
+
);
|
|
262
|
+
return rendered.split(placeholder).join(Story());
|
|
260
263
|
}
|
|
261
264
|
],` : ""}
|
|
262
265
|
play: async ({ canvasElement }) => {
|
|
@@ -487,7 +490,7 @@ var toNamespaces = (namespaceDefinition) => {
|
|
|
487
490
|
return new Namespaces(namespaceDefinition ?? {});
|
|
488
491
|
};
|
|
489
492
|
|
|
490
|
-
// src/vite-plugin-sdc-
|
|
493
|
+
// src/vite-plugin-sdc-twig-runtime.ts
|
|
491
494
|
import { existsSync as existsSync3, readdirSync as readdirSync3, readFileSync as readFileSync2 } from "fs";
|
|
492
495
|
import { join as join3 } from "path";
|
|
493
496
|
import { parse as parseYaml2 } from "yaml";
|
|
@@ -690,7 +693,7 @@ async function fetchRemoteSprite(pack, fetchSvg) {
|
|
|
690
693
|
return content;
|
|
691
694
|
}
|
|
692
695
|
|
|
693
|
-
// src/vite-plugin-sdc-
|
|
696
|
+
// src/vite-plugin-sdc-twig-runtime.ts
|
|
694
697
|
var remoteSvgCache = /* @__PURE__ */ new Map();
|
|
695
698
|
async function fetchSvgFromUrl(url) {
|
|
696
699
|
if (remoteSvgCache.has(url)) return remoteSvgCache.get(url) ?? null;
|
|
@@ -734,9 +737,9 @@ function readNamespaceYamlData(namespaces) {
|
|
|
734
737
|
}
|
|
735
738
|
return out;
|
|
736
739
|
}
|
|
737
|
-
var VIRTUAL_TWIG = "virtual:sdc-
|
|
740
|
+
var VIRTUAL_TWIG = "virtual:sdc-twig-runtime:twig";
|
|
738
741
|
var RESOLVED_TWIG = "\0" + VIRTUAL_TWIG;
|
|
739
|
-
var VIRTUAL_TWING = "virtual:sdc-
|
|
742
|
+
var VIRTUAL_TWING = "virtual:sdc-twig-runtime:twing";
|
|
740
743
|
var RESOLVED_TWING = "\0" + VIRTUAL_TWING;
|
|
741
744
|
var PACK_PREFIX = "\0icons-pack:";
|
|
742
745
|
var SHARED_HELPERS = (
|
|
@@ -824,7 +827,19 @@ export function renderIcon(packId, iconId, settings) {
|
|
|
824
827
|
}
|
|
825
828
|
}
|
|
826
829
|
|
|
827
|
-
|
|
830
|
+
// Render an inline Twig template string (e.g. a story library_wrapper) so
|
|
831
|
+
// {{ include(...) }} and other Twig works; {{ _story }} comes from context.
|
|
832
|
+
export function renderInline(template, context) {
|
|
833
|
+
if (!_sdcTwig || !template) return template || '';
|
|
834
|
+
try {
|
|
835
|
+
return _sdcTwig.twig({ data: template }).render(context || {});
|
|
836
|
+
} catch (e) {
|
|
837
|
+
console.error('[SDC] renderInline error:', e);
|
|
838
|
+
return template;
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
export function registerSdcRuntime(Twig) {
|
|
828
843
|
_sdcTwig = Twig;
|
|
829
844
|
if (Twig.__sdcIconRegistered) return;
|
|
830
845
|
Twig.__sdcIconRegistered = true;
|
|
@@ -868,7 +883,30 @@ export function renderIcon(packId, iconId, settings) {
|
|
|
868
883
|
}
|
|
869
884
|
}
|
|
870
885
|
|
|
871
|
-
|
|
886
|
+
// Render an inline Twig template string (e.g. a story library_wrapper) through
|
|
887
|
+
// the captured SDC environment, so {{ include(...) }} resolves against the same
|
|
888
|
+
// loader and Twig works; {{ _story }} comes from context.
|
|
889
|
+
var _sdcInlineNames = {};
|
|
890
|
+
var _sdcInlineSeq = 0;
|
|
891
|
+
export function renderInline(template, context) {
|
|
892
|
+
if (!_sdcIconEnv || !template) return template || '';
|
|
893
|
+
var loader = _sdcIconEnv.loader;
|
|
894
|
+
if (!loader || typeof loader.setTemplate !== 'function') return template;
|
|
895
|
+
var name = _sdcInlineNames[template];
|
|
896
|
+
if (!name) {
|
|
897
|
+
name = '_sdc_inline_' + (_sdcInlineSeq++);
|
|
898
|
+
_sdcInlineNames[template] = name;
|
|
899
|
+
}
|
|
900
|
+
try {
|
|
901
|
+
loader.setTemplate(name, template);
|
|
902
|
+
return _sdcIconEnv.render(name, context || {});
|
|
903
|
+
} catch (e) {
|
|
904
|
+
console.error('[SDC] renderInline error:', e);
|
|
905
|
+
return template;
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
export function registerSdcRuntime(env) {
|
|
872
910
|
_sdcIconEnv = env;
|
|
873
911
|
// Register icon templates into the existing loader so env.render() finds them.
|
|
874
912
|
// createSynchronousArrayLoader (used by vite-plugin-twing-drupal's SDC loader)
|
|
@@ -910,10 +948,10 @@ var TWIG_JS_MARKER = "from 'drupal-twig-extensions/twig'";
|
|
|
910
948
|
var TWIG_JS_INJECT_AFTER = "addDrupalExtensions(Twig);";
|
|
911
949
|
var TWING_MARKER = "createSynchronousEnvironment";
|
|
912
950
|
var TWING_INJECT_AFTER = "addDrupalExtensions(env);";
|
|
913
|
-
var INJECTED_GUARD = "
|
|
914
|
-
function
|
|
951
|
+
var INJECTED_GUARD = "_sdcRegisterRuntime";
|
|
952
|
+
function sdcTwigRuntimePlugin(namespaces, resolveIconSource) {
|
|
915
953
|
return {
|
|
916
|
-
name: "vite-plugin-sdc-
|
|
954
|
+
name: "vite-plugin-sdc-twig-runtime",
|
|
917
955
|
resolveId(id) {
|
|
918
956
|
if (id === VIRTUAL_TWIG) return RESOLVED_TWIG;
|
|
919
957
|
if (id === VIRTUAL_TWING) return RESOLVED_TWING;
|
|
@@ -984,7 +1022,7 @@ if (typeof document !== 'undefined') {
|
|
|
984
1022
|
if (code.includes(INJECTED_GUARD)) return null;
|
|
985
1023
|
if (code.includes(TWING_MARKER) && code.includes(TWING_INJECT_AFTER)) {
|
|
986
1024
|
return {
|
|
987
|
-
code: `import {
|
|
1025
|
+
code: `import { registerSdcRuntime as ${INJECTED_GUARD} } from '${VIRTUAL_TWING}';
|
|
988
1026
|
` + code.replace(
|
|
989
1027
|
TWING_INJECT_AFTER,
|
|
990
1028
|
`${TWING_INJECT_AFTER}
|
|
@@ -995,7 +1033,7 @@ ${INJECTED_GUARD}(env);`
|
|
|
995
1033
|
}
|
|
996
1034
|
if (code.includes(TWIG_JS_MARKER) && code.includes(TWIG_JS_INJECT_AFTER)) {
|
|
997
1035
|
return {
|
|
998
|
-
code: `import {
|
|
1036
|
+
code: `import { registerSdcRuntime as ${INJECTED_GUARD} } from '${VIRTUAL_TWIG}';
|
|
999
1037
|
` + code.replace(
|
|
1000
1038
|
TWIG_JS_INJECT_AFTER,
|
|
1001
1039
|
`${TWIG_JS_INJECT_AFTER}
|
|
@@ -1227,7 +1265,7 @@ var vite_plugin_storybook_yaml_stories_default = ({
|
|
|
1227
1265
|
import COMPONENT from '${namespace}/${componentBaseName}.twig';
|
|
1228
1266
|
void import.meta.glob('./*.css', { eager: true });
|
|
1229
1267
|
import { injectAssets } from '${VIRTUAL_ASSET_INJECTOR}';
|
|
1230
|
-
import { renderIcon as _sdcRenderIcon } from '${iconModule}';
|
|
1268
|
+
import { renderIcon as _sdcRenderIcon, renderInline as _sdcRenderInline } from '${iconModule}';
|
|
1231
1269
|
${storiesImports}
|
|
1232
1270
|
${twigImports}
|
|
1233
1271
|
${assetInjection}
|
|
@@ -1470,7 +1508,7 @@ async function viteFinal(config, options) {
|
|
|
1470
1508
|
}),
|
|
1471
1509
|
...twigPlugin ? [twigPlugin] : [],
|
|
1472
1510
|
vite_plugin_storybook_yaml_stories_default({ ...options, globalDefs, namespaces }),
|
|
1473
|
-
|
|
1511
|
+
sdcTwigRuntimePlugin(namespaces, sdcStorybookOptions.resolveIconSource),
|
|
1474
1512
|
...headTags.length > 0 ? [{ name: "vite-plugin-sdc-head", transformIndexHtml: () => headTags }] : []
|
|
1475
1513
|
],
|
|
1476
1514
|
optimizeDeps: {
|