@vizejs/vite-plugin-musea 0.434.0 → 0.439.0
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/a11y/index.d.mts +1 -1
- package/dist/cli/index.d.mts +1 -1
- package/dist/gallery/assets/{MonacoEditor-CnzIyKMy.js → MonacoEditor-DMGQGixL.js} +2 -2
- package/dist/gallery/assets/{cssMode-DZ_me5CG.js → cssMode-Chlc2oby.js} +1 -1
- package/dist/gallery/assets/{editor.api-CjD4Hpms.js → editor.api-B0CSOuX7.js} +1 -1
- package/dist/gallery/assets/{freemarker2-F7z49Hfe.js → freemarker2-UuwRuSuB.js} +1 -1
- package/dist/gallery/assets/{handlebars-Dt4eGgf-.js → handlebars-JBK-IQdb.js} +1 -1
- package/dist/gallery/assets/{html-B1zmbcur.js → html-Ysiq-32p.js} +1 -1
- package/dist/gallery/assets/{htmlMode-DmDwpA4v.js → htmlMode-xYeJY9wj.js} +1 -1
- package/dist/gallery/assets/index-BCvwNnuC.css +1 -0
- package/dist/gallery/assets/{index-vJ3ftuqF.js → index-MXXeE4aD.js} +25 -25
- package/dist/gallery/assets/{javascript-CLKbyvz8.js → javascript-Ccrslpma.js} +1 -1
- package/dist/gallery/assets/{jsonMode-sms9-L2I.js → jsonMode-v3sPHB9W.js} +1 -1
- package/dist/gallery/assets/{liquid-CesACmVT.js → liquid-Dd_z8h_B.js} +1 -1
- package/dist/gallery/assets/{lspLanguageFeatures-C8BR-41u.js → lspLanguageFeatures-D9U1Gq1J.js} +1 -1
- package/dist/gallery/assets/{mdx-Cd93KUo_.js → mdx-BV9KJmeU.js} +1 -1
- package/dist/gallery/assets/{python-8gi7tgMv.js → python-DpUI9NMf.js} +1 -1
- package/dist/gallery/assets/{razor-sOyhBXSy.js → razor-RzAxmhn_.js} +1 -1
- package/dist/gallery/assets/{register-C-_4TcWq.js → register-CFx1KSfO.js} +2 -2
- package/dist/gallery/assets/{toggleHighContrast-BCHobRx5.js → toggleHighContrast-CSv0sacK.js} +1 -1
- package/dist/gallery/assets/{tsMode-BkQQD7P8.js → tsMode-DpHP6oFd.js} +1 -1
- package/dist/gallery/assets/{typescript-XiwOdN8G.js → typescript-B-VbgG33.js} +1 -1
- package/dist/gallery/assets/{vs-Coo3fK7w.js → vs-CzdsC1b2.js} +3 -3
- package/dist/gallery/assets/{workers-Cypb28_F.js → workers-HbLkgrxn.js} +1 -1
- package/dist/gallery/assets/{xml-CN1ixSLs.js → xml-CxjWwj-4.js} +1 -1
- package/dist/gallery/assets/{yaml-l30MdsZA.js → yaml-q-dG9Lkk.js} +1 -1
- package/dist/gallery/index.html +2 -2
- package/dist/{gallery-CIcrB07g.mjs → gallery-CLe_4-XW.mjs} +5 -4
- package/dist/{gallery-CIcrB07g.mjs.map → gallery-CLe_4-XW.mjs.map} +1 -1
- package/dist/index-CtvsGVFJ.d.mts +22132 -0
- package/dist/index-CtvsGVFJ.d.mts.map +1 -0
- package/dist/{index-C5evpfmF.d.mts → index-GkKsNzkf.d.mts} +3 -3
- package/dist/{index-C5evpfmF.d.mts.map → index-GkKsNzkf.d.mts.map} +1 -1
- package/dist/index.d.mts +4 -6
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +127 -47
- package/dist/index.mjs.map +1 -1
- package/dist/{template-DDl7rsgo.mjs → template-BgBSA10_.mjs} +5 -3
- package/dist/template-BgBSA10_.mjs.map +1 -0
- package/dist/{vrt-6iDBfqNg.d.mts → vrt-DNNAFYv1.d.mts} +3 -65
- package/dist/vrt-DNNAFYv1.d.mts.map +1 -0
- package/dist/vrt.d.mts +1 -1
- package/package.json +4 -4
- package/dist/api-gMwahZKm.d.mts +0 -112
- package/dist/api-gMwahZKm.d.mts.map +0 -1
- package/dist/gallery/assets/index-C4vm-yqv.css +0 -1
- package/dist/plugin-DkFXWcCD.d.mts +0 -268
- package/dist/plugin-DkFXWcCD.d.mts.map +0 -1
- package/dist/template-DDl7rsgo.mjs.map +0 -1
- package/dist/vrt-3T_e4bJ3.d.mts +0 -95
- package/dist/vrt-3T_e4bJ3.d.mts.map +0 -1
- package/dist/vrt-6iDBfqNg.d.mts.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { b as A11yOptions, t as ArtFileInfo, x as A11yResult } from "./index-CtvsGVFJ.mjs";
|
|
2
|
+
import { r as MuseaVrtRunner } from "./vrt-DNNAFYv1.mjs";
|
|
3
3
|
import { Page } from "playwright";
|
|
4
4
|
|
|
5
5
|
//#region src/a11y/report.d.ts
|
|
@@ -78,4 +78,4 @@ declare class MuseaA11yRunner {
|
|
|
78
78
|
}
|
|
79
79
|
//#endregion
|
|
80
80
|
export { generateA11yHtmlReport as a, computeA11ySummary as i, MuseaA11yRunner as n, generateA11yJsonReport as o, resolveAxeSource as r, A11ySummary as t };
|
|
81
|
-
//# sourceMappingURL=index-
|
|
81
|
+
//# sourceMappingURL=index-GkKsNzkf.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-
|
|
1
|
+
{"version":3,"file":"index-GkKsNzkf.d.mts","names":[],"sources":["../src/a11y/report.ts","../src/a11y/index.ts"],"mappings":";;;;;;;;iBAegB,kBAAA,CAAmB,OAAA,EAAS,UAAA,KAAe,WAAW;;AAAA;AAmBtE;iBAAgB,sBAAA,CAAuB,OAAA,EAAS,UAAA,IAAc,OAAA,EAAS,WAAW;;;;iBAqKlE,sBAAA,CAAuB,OAAqB,EAAZ,UAAU;;;;;;UC/KzC,WAAA;EACf,eAAA;EACA,aAAA;EDQc;ECNd,eAAA;EACA,eAAA;EACA,aAAA;EACA,YAAA;EACA,aAAA;EACA,UAAA;AAAA;;ADCgF;AAqKlF;;;;AAA4D;;;;AC/K5D;iBAuBsB,gBAAA,IAAoB,OAAO;;;;cAyBpC,eAAA;EAAA,QACH,OAAA;cAEI,OAAA,GAAS,WAAA;EA7CrB;;;;EA0DM,SAAA,CACJ,QAAA,EAAU,WAAA,IACV,OAAA,UACA,SAAA,GAAY,cAAA,GACX,OAAA,CAAQ,UAAA;EA3DD;AAcZ;;EAqGQ,SAAA,CAAU,IAAA,EAAM,IAAA,EAAM,OAAA,UAAiB,WAAA,WAAsB,OAAA,CAAQ,UAAA;EArG5B;AAAA;AAyBjD;EAyHE,UAAA,CAAW,OAAA,EAAS,UAAA,KAAe,WAAA;;;;EAOnC,kBAAA,CAAmB,OAAA,EAAS,UAAA;EA5GjB;;;EAoHX,kBAAA,CAAmB,OAAA,EAAS,UAAA;EA5DuC;;;EAAA,QAmE3D,eAAA;EAAA,QAqCA,eAAA;AAAA"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { c as VrtSummary, d as ArtVariant, f as CsfOutput, l as ArtFileInfo, n as generateVrtReport, r as MuseaVrtRunner, s as VrtResult, t as generateVrtJsonReport, u as ArtMetadata } from "./vrt-6iDBfqNg.mjs";
|
|
5
|
-
import { n as MuseaA11yRunner, t as A11ySummary } from "./index-C5evpfmF.mjs";
|
|
1
|
+
import { A as MuseaGlobals, C as PaletteApiResponse, D as ViewportConfig, E as ComparisonConfig, M as MuseaToolbarOption, O as VrtOptions, S as AnalysisApiResponse, T as CiConfig, _ as StyleDictionaryOutput, a as MuseaOptions, b as A11yOptions, c as MuseaThemeColors, d as MuseaTokenPreviewKind, f as MuseaTokenPreviewRule, g as StyleDictionaryConfig, h as DesignToken, i as CsfOutput, j as MuseaToolbarControl, k as MuseaGlobalValue, l as MuseaVrtOptions, m as resolveTokenPreview, n as ArtMetadata, o as MuseaPreviewContext, p as ResolvedTokenPreview, r as ArtVariant, s as MuseaTheme, t as ArtFileInfo, u as MuseaTokenPreviewConfig, v as TokenCategory, w as CaptureConfig, x as A11yResult, y as parseTokens } from "./index-CtvsGVFJ.mjs";
|
|
2
|
+
import { c as VrtSummary, n as generateVrtReport, r as MuseaVrtRunner, s as VrtResult, t as generateVrtJsonReport } from "./vrt-DNNAFYv1.mjs";
|
|
3
|
+
import { n as MuseaA11yRunner, t as A11ySummary } from "./index-GkKsNzkf.mjs";
|
|
6
4
|
import { AutogenOptions, AutogenOutput, GeneratedVariant, PropDefinition, generateArtFile, writeArtFile } from "./autogen/index.mjs";
|
|
7
5
|
import { Plugin } from "vite";
|
|
8
6
|
|
|
@@ -67,5 +65,5 @@ declare function generateTokensMarkdown(categories: TokenCategory[]): string;
|
|
|
67
65
|
*/
|
|
68
66
|
declare function processStyleDictionary(config: StyleDictionaryConfig): Promise<StyleDictionaryOutput>;
|
|
69
67
|
//#endregion
|
|
70
|
-
export { type A11yOptions, type A11yResult, type A11ySummary, type AnalysisApiResponse, type ArtFileInfo, type ArtMetadata, type ArtVariant, type AutogenOptions, type AutogenOutput, type CaptureConfig, type CiConfig, type ComparisonConfig, type CsfOutput, type DesignToken, type GeneratedVariant, MuseaA11yRunner, type MuseaOptions, type MuseaTheme, type MuseaThemeColors, type MuseaTokenPreviewConfig, type MuseaTokenPreviewKind, type MuseaTokenPreviewRule, type MuseaVrtOptions, MuseaVrtRunner, type PaletteApiResponse, type PropDefinition, type ResolvedTokenPreview, type StyleDictionaryConfig, type StyleDictionaryOutput, type TokenCategory, type TokenUsageMap, type ViewportConfig, type VrtOptions, type VrtResult, type VrtSummary, buildTokenMap, musea as default, musea, generateArtFile, generateTokensHtml, generateTokensMarkdown, generateVrtJsonReport, generateVrtReport, parseTokens, processStyleDictionary, resolveReferences, resolveTokenPreview, scanTokenUsage, writeArtFile };
|
|
68
|
+
export { type A11yOptions, type A11yResult, type A11ySummary, type AnalysisApiResponse, type ArtFileInfo, type ArtMetadata, type ArtVariant, type AutogenOptions, type AutogenOutput, type CaptureConfig, type CiConfig, type ComparisonConfig, type CsfOutput, type DesignToken, type GeneratedVariant, MuseaA11yRunner, type MuseaGlobalValue, type MuseaGlobals, type MuseaOptions, type MuseaPreviewContext, type MuseaTheme, type MuseaThemeColors, type MuseaTokenPreviewConfig, type MuseaTokenPreviewKind, type MuseaTokenPreviewRule, type MuseaToolbarControl, type MuseaToolbarOption, type MuseaVrtOptions, MuseaVrtRunner, type PaletteApiResponse, type PropDefinition, type ResolvedTokenPreview, type StyleDictionaryConfig, type StyleDictionaryOutput, type TokenCategory, type TokenUsageMap, type ViewportConfig, type VrtOptions, type VrtResult, type VrtSummary, buildTokenMap, musea as default, musea, generateArtFile, generateTokensHtml, generateTokensMarkdown, generateVrtJsonReport, generateVrtReport, parseTokens, processStyleDictionary, resolveReferences, resolveTokenPreview, scanTokenUsage, writeArtFile };
|
|
71
69
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/plugin/index.ts","../src/tokens/usage.ts","../src/tokens/resolver.ts","../src/tokens/generator.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/plugin/index.ts","../src/tokens/usage.ts","../src/tokens/resolver.ts","../src/tokens/generator.ts"],"mappings":";;;;;;;iBA2CgB,KAAA,CAAM,OAAA,GAAS,YAAA,GAAoB,MAAM;;;AAAA;;;AAAA,iBCHzC,cAAA,CACd,QAAA,EAAU,GAAA;EAAc,IAAA;EAAc,QAAA;IAAY,KAAA;IAAe,QAAA;EAAA;AAAA,IACjE,QAAA,EAAU,MAAA,SAAe,WAAA,IACxB,aAAA;;;;;;UCtBc,eAAA;EACf,IAAA;EACA,WAAA;EACA,QAAA;AAAA;;;;UAMe,eAAA;EACf,OAAA;EACA,QAAA;EACA,WAAA;EACA,OAAA,EAAS,eAAe;AAAA;;;;KAMd,aAAA,GAAgB,MAAM,SAAS,eAAA;;;;iBAqB3B,aAAA,CAAc,UAAA,EAAY,aAAA,KAAkB,MAAA,SAAe,WAAA;;;;iBAO3D,iBAAA,CACd,UAAA,EAAY,aAAA,IACZ,SAAA,EAAW,MAAA,SAAe,WAAA;;;AF3B5B;;;AAAA,iBGJgB,kBAAA,CAAmB,UAA2B,EAAf,aAAa;;;;iBAgI5C,sBAAA,CAAuB,UAA2B,EAAf,aAAa;AH5HP;;;;AAAA,iBGoInC,sBAAA,CACpB,MAAA,EAAQ,qBAAA,GACP,OAAA,CAAQ,qBAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { C as resolveUrlPathInside, E as loadNative, S as resolveTrustedSourcePath, T as analyzeSfcFallback, _ as assertVueSourcePath, a as scanArtFiles, b as resolveInside, c as buildThemeConfig, d as createDevSessionToken, f as parseJsonBody, h as assertArtVueSourcePath, i as resolveScanRoots, m as validateDevApiRequest, n as generateStorybookFiles, o as shouldProcess, p as serializeScriptValue, r as matchGlob, s as toPascalCase, t as escapeHtml, u as collectRequestBody, v as decodeUrlComponent, w as HttpError, x as resolveInsideAny, y as isVueSourcePath } from "./utils-DeMLVlNS.mjs";
|
|
2
2
|
import { a as parseScriptSetupForArt, c as resolveArtComponent, d as resolveReadableArtPath, i as generateArtModule, l as allowedSourceRoots, o as rewriteRelativeImportStatement, r as processMuseaArtFile, s as expandSelfTag, t as attachMuseaOptions, u as resolveComponentSourcePath } from "./options-CZYdDtTW.mjs";
|
|
3
|
-
import { a as generateGalleryGlobalsScript, i as generateDevGlobalsScript, n as generateGalleryScript, r as generateGalleryModule, t as generateGalleryBody } from "./template-
|
|
3
|
+
import { a as generateGalleryGlobalsScript, i as generateDevGlobalsScript, n as generateGalleryScript, r as generateGalleryModule, t as generateGalleryBody } from "./template-BgBSA10_.mjs";
|
|
4
4
|
import { i as MuseaVrtRunner, n as generateVrtJsonReport, r as generateVrtReport } from "./vrt-VuGK9wTX.mjs";
|
|
5
5
|
import { t as MuseaA11yRunner } from "./a11y-BbFK942j.mjs";
|
|
6
6
|
import { n as writeArtFile, t as generateArtFile } from "./autogen-B-N0cJbZ.mjs";
|
|
@@ -13,6 +13,82 @@ import ts from "typescript";
|
|
|
13
13
|
import { VIZE_CONFIG_FILE_ENV, loadConfig } from "@vizejs/vite-plugin";
|
|
14
14
|
import { getResolvedVizeConfigRegistration } from "@vizejs/vite-plugin/internal/config-bridge";
|
|
15
15
|
import * as vite from "vite";
|
|
16
|
+
//#region src/toolbar.ts
|
|
17
|
+
function normalizeToolbar(toolbar = []) {
|
|
18
|
+
const ids = /* @__PURE__ */ new Set();
|
|
19
|
+
return toolbar.map((control) => {
|
|
20
|
+
const fail = (reason) => {
|
|
21
|
+
throw new Error(`[musea] Invalid toolbar control ${JSON.stringify(control.id)}: ${reason}`);
|
|
22
|
+
};
|
|
23
|
+
if (!/^[a-zA-Z][\w-]*$/.test(control.id) || ids.has(control.id)) fail("ids must be unique and start with a letter");
|
|
24
|
+
ids.add(control.id);
|
|
25
|
+
if (!control.title?.trim()) fail("title is required");
|
|
26
|
+
if (control.type !== "select" && control.type !== "toggle") fail("unknown control type");
|
|
27
|
+
if (!Array.isArray(control.options) || control.options.length === 0) fail("options are required");
|
|
28
|
+
if (control.type === "toggle" && control.options.length !== 2) fail("toggles need two options");
|
|
29
|
+
const values = /* @__PURE__ */ new Set();
|
|
30
|
+
const options = control.options.map((option) => {
|
|
31
|
+
const item = typeof option === "string" ? {
|
|
32
|
+
value: option,
|
|
33
|
+
label: option
|
|
34
|
+
} : option;
|
|
35
|
+
if (!item || ![
|
|
36
|
+
"string",
|
|
37
|
+
"boolean",
|
|
38
|
+
"number"
|
|
39
|
+
].includes(typeof item.value) || typeof item.value === "number" && !Number.isFinite(item.value) || typeof item.label !== "string" || !item.label.trim() || item.icon !== void 0 && typeof item.icon !== "string") fail("options require a finite primitive value and a label");
|
|
40
|
+
if (values.has(item.value)) fail("option values must be unique");
|
|
41
|
+
values.add(item.value);
|
|
42
|
+
return {
|
|
43
|
+
value: item.value,
|
|
44
|
+
label: item.label,
|
|
45
|
+
...item.icon ? { icon: item.icon } : {}
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
if (!values.has(control.default)) fail("default must match an option value");
|
|
49
|
+
return {
|
|
50
|
+
id: control.id,
|
|
51
|
+
title: control.title,
|
|
52
|
+
type: control.type,
|
|
53
|
+
options,
|
|
54
|
+
default: control.default
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region src/preview/globals.ts
|
|
60
|
+
/** Generated only for configured controls; the default preview stays unchanged. */
|
|
61
|
+
function generatePreviewGlobals(toolbar) {
|
|
62
|
+
if (toolbar.length === 0) return "";
|
|
63
|
+
return `
|
|
64
|
+
const __museaToolbar = ${JSON.stringify(toolbar)};
|
|
65
|
+
function __museaResolveGlobals(input) {
|
|
66
|
+
const record = input && typeof input === 'object' ? input : {};
|
|
67
|
+
return Object.fromEntries(__museaToolbar.map((control) => {
|
|
68
|
+
const value = Object.hasOwn(record, control.id) ? record[control.id] : undefined;
|
|
69
|
+
return [control.id, control.options.some((option) => option.value === value) ? value : control.default];
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
let __museaInitialGlobals;
|
|
73
|
+
try {
|
|
74
|
+
__museaInitialGlobals = JSON.parse(new URL(window.location.href).searchParams.get('museaGlobals'));
|
|
75
|
+
} catch {}
|
|
76
|
+
const __museaGlobals = __museaCreateGlobalsRef(__museaResolveGlobals(__museaInitialGlobals));
|
|
77
|
+
function __museaUpdateGlobals(event) {
|
|
78
|
+
if (event.origin !== window.location.origin || event.source !== window.parent) return;
|
|
79
|
+
if (event.data?.type !== 'musea:set-globals') return;
|
|
80
|
+
const next = __museaResolveGlobals(event.data.payload);
|
|
81
|
+
if (__museaToolbar.some((control) => next[control.id] !== __museaGlobals.value[control.id])) {
|
|
82
|
+
__museaGlobals.value = next;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
window.addEventListener('message', __museaUpdateGlobals);
|
|
86
|
+
window.addEventListener('pagehide', (event) => {
|
|
87
|
+
if (!event.persisted) window.removeEventListener('message', __museaUpdateGlobals);
|
|
88
|
+
});
|
|
89
|
+
`;
|
|
90
|
+
}
|
|
91
|
+
//#endregion
|
|
16
92
|
//#region src/preview/addons.ts
|
|
17
93
|
/**
|
|
18
94
|
* Addon initialization code for Musea preview iframes.
|
|
@@ -454,22 +530,25 @@ function generatePreviewHtml(art, variant, _basePath, viteBase) {
|
|
|
454
530
|
}
|
|
455
531
|
//#endregion
|
|
456
532
|
//#region src/preview/index.ts
|
|
457
|
-
function generatePreviewModule(art, variantComponentName, variantName, cssImports = [], previewSetup = null, vueVersion = 3) {
|
|
533
|
+
function generatePreviewModule(art, variantComponentName, variantName, cssImports = [], previewSetup = null, vueVersion = 3, toolbar = []) {
|
|
458
534
|
const artModuleId = `virtual:musea-art:${art.path}`;
|
|
459
535
|
const artModuleIdLiteral = JSON.stringify(artModuleId);
|
|
460
536
|
const variantNameLiteral = JSON.stringify(variantName);
|
|
461
537
|
const variantComponentNameLiteral = JSON.stringify(variantComponentName);
|
|
462
538
|
const cssImportStatements = cssImports.map((cssPath) => `import ${JSON.stringify(cssPath)};`).join("\n");
|
|
463
539
|
const setupImport = previewSetup ? `import __museaPreviewSetup from ${JSON.stringify(previewSetup)};` : "";
|
|
464
|
-
const
|
|
540
|
+
const globals = toolbar.length > 0;
|
|
541
|
+
const setupCall = previewSetup ? `await __museaPreviewSetup(app${globals ? ", { globals: __museaGlobals }" : ""});` : "";
|
|
465
542
|
const actionEvents = JSON.stringify(art.metadata.actionEvents ?? []);
|
|
466
543
|
const artStyleId = `musea-art-styles-${art.path.replace(/[^\w-]+/g, "_")}`;
|
|
467
544
|
const artStyleIdLiteral = JSON.stringify(artStyleId);
|
|
468
545
|
const legacyVue = isLegacyVueVersion(vueVersion);
|
|
469
|
-
const vueImport = legacyVue ?
|
|
546
|
+
const vueImport = legacyVue ? `import Vue, { reactive${globals ? ", ref as __museaCreateGlobalsRef" : ""} } from 'vue';` : `import { createApp, reactive, h${globals ? ", ref as __museaCreateGlobalsRef" : ""} } from 'vue';`;
|
|
470
547
|
const destroyCurrentApp = legacyVue ? "currentApp.$destroy();" : "currentApp.unmount();";
|
|
471
548
|
const mountInitialApp = legacyVue ? "const app = new Vue({ render: (h) => h(VariantComponent) });" : "const app = createApp(VariantComponent);";
|
|
472
549
|
const mountCurrentApp = legacyVue ? "mountVue2App(app);" : "app.mount(container);\n currentApp = app;";
|
|
550
|
+
const mountHelper = legacyVue ? vue2MountHelperSnippet() : "";
|
|
551
|
+
const remountApp = legacyVue ? vue2RemountAppSnippet() : vue3RemountAppSnippet();
|
|
473
552
|
return `
|
|
474
553
|
${cssImportStatements}
|
|
475
554
|
${setupImport}
|
|
@@ -478,7 +557,7 @@ import * as artModule from ${artModuleIdLiteral};
|
|
|
478
557
|
|
|
479
558
|
const container = document.getElementById('app');
|
|
480
559
|
|
|
481
|
-
${MUSEA_ADDONS_INIT_CODE}
|
|
560
|
+
${MUSEA_ADDONS_INIT_CODE}${generatePreviewGlobals(toolbar)}
|
|
482
561
|
|
|
483
562
|
let currentApp = null;
|
|
484
563
|
const propsOverride = reactive({});
|
|
@@ -526,7 +605,7 @@ function renderError(title, error) {
|
|
|
526
605
|
container.appendChild(root);
|
|
527
606
|
}
|
|
528
607
|
|
|
529
|
-
${
|
|
608
|
+
${mountHelper}
|
|
530
609
|
|
|
531
610
|
window.__museaSetProps = (props) => {
|
|
532
611
|
// Clear old keys
|
|
@@ -590,7 +669,7 @@ async function remountWithProps(Component) {
|
|
|
590
669
|
if (currentApp) {
|
|
591
670
|
${destroyCurrentApp}
|
|
592
671
|
}
|
|
593
|
-
${
|
|
672
|
+
${remountApp}
|
|
594
673
|
ensureArtStyles(artModule.__styles__);
|
|
595
674
|
${setupCall}
|
|
596
675
|
container.innerHTML = '';
|
|
@@ -640,7 +719,7 @@ function vue3RemountAppSnippet() {
|
|
|
640
719
|
}
|
|
641
720
|
});`;
|
|
642
721
|
}
|
|
643
|
-
function generatePreviewModuleWithProps(art, variantComponentName, variantName, propsOverride, cssImports = [], previewSetup = null, vueVersion = 3) {
|
|
722
|
+
function generatePreviewModuleWithProps(art, variantComponentName, variantName, propsOverride, cssImports = [], previewSetup = null, vueVersion = 3, toolbar = []) {
|
|
644
723
|
const artModuleId = `virtual:musea-art:${art.path}`;
|
|
645
724
|
const artModuleIdLiteral = JSON.stringify(artModuleId);
|
|
646
725
|
const variantNameLiteral = JSON.stringify(variantName);
|
|
@@ -648,21 +727,34 @@ function generatePreviewModuleWithProps(art, variantComponentName, variantName,
|
|
|
648
727
|
const propsJson = JSON.stringify(propsOverride);
|
|
649
728
|
const cssImportStatements = cssImports.map((cssPath) => `import ${JSON.stringify(cssPath)};`).join("\n");
|
|
650
729
|
const setupImport = previewSetup ? `import __museaPreviewSetup from ${JSON.stringify(previewSetup)};` : "";
|
|
651
|
-
const
|
|
730
|
+
const globals = toolbar.length > 0;
|
|
731
|
+
const setupCall = previewSetup ? `await __museaPreviewSetup(app${globals ? ", { globals: __museaGlobals }" : ""});` : "";
|
|
652
732
|
const actionEvents = JSON.stringify(art.metadata.actionEvents ?? []);
|
|
653
733
|
const artStyleId = `musea-art-styles-${art.path.replace(/[^\w-]+/g, "_")}`;
|
|
654
734
|
const artStyleIdLiteral = JSON.stringify(artStyleId);
|
|
655
735
|
const legacyVue = isLegacyVueVersion(vueVersion);
|
|
736
|
+
const vueImport = legacyVue ? `import Vue${globals ? ", { ref as __museaCreateGlobalsRef }" : ""} from 'vue';` : `import { createApp, h${globals ? ", ref as __museaCreateGlobalsRef" : ""} } from 'vue';`;
|
|
737
|
+
const wrappedComponent = legacyVue ? `const WrappedComponent = {
|
|
738
|
+
render(h) {
|
|
739
|
+
return h(VariantComponent, { props: propsOverride });
|
|
740
|
+
}
|
|
741
|
+
};` : `const WrappedComponent = {
|
|
742
|
+
render() {
|
|
743
|
+
return h(VariantComponent, propsOverride);
|
|
744
|
+
}
|
|
745
|
+
};`;
|
|
746
|
+
const appCreate = legacyVue ? "const app = new Vue(WrappedComponent);" : "const app = createApp(WrappedComponent);";
|
|
747
|
+
const appMount = legacyVue ? "const mountPoint = document.createElement('div');\n container.appendChild(mountPoint);\n app.$mount(mountPoint);" : "app.mount(container);";
|
|
656
748
|
return `
|
|
657
749
|
${cssImportStatements}
|
|
658
750
|
${setupImport}
|
|
659
|
-
${
|
|
751
|
+
${vueImport}
|
|
660
752
|
import * as artModule from ${artModuleIdLiteral};
|
|
661
753
|
|
|
662
754
|
const container = document.getElementById('app');
|
|
663
755
|
const propsOverride = ${propsJson};
|
|
664
756
|
|
|
665
|
-
${MUSEA_ADDONS_INIT_CODE}
|
|
757
|
+
${MUSEA_ADDONS_INIT_CODE}${generatePreviewGlobals(toolbar)}
|
|
666
758
|
|
|
667
759
|
function ensureArtStyles(styles) {
|
|
668
760
|
const styleId = ${artStyleIdLiteral};
|
|
@@ -706,22 +798,14 @@ async function mount() {
|
|
|
706
798
|
throw new Error('Variant component ' + ${variantComponentNameLiteral} + ' not found');
|
|
707
799
|
}
|
|
708
800
|
|
|
709
|
-
${
|
|
710
|
-
render(h) {
|
|
711
|
-
return h(VariantComponent, { props: propsOverride });
|
|
712
|
-
}
|
|
713
|
-
};` : `const WrappedComponent = {
|
|
714
|
-
render() {
|
|
715
|
-
return h(VariantComponent, propsOverride);
|
|
716
|
-
}
|
|
717
|
-
};`}
|
|
801
|
+
${wrappedComponent}
|
|
718
802
|
|
|
719
|
-
${
|
|
803
|
+
${appCreate}
|
|
720
804
|
ensureArtStyles(artModule.__styles__);
|
|
721
805
|
${setupCall}
|
|
722
806
|
container.innerHTML = '';
|
|
723
807
|
container.className = 'musea-variant';
|
|
724
|
-
${
|
|
808
|
+
${appMount}
|
|
725
809
|
console.log('[musea-preview] Mounted variant with props override:', ${variantNameLiteral});
|
|
726
810
|
__museaInitAddons(container, ${variantNameLiteral}, ${actionEvents});
|
|
727
811
|
} catch (error) {
|
|
@@ -754,7 +838,7 @@ function resolveGallerySourceDir() {
|
|
|
754
838
|
function toViteFsPath(filePath) {
|
|
755
839
|
return encodeURI(`/@fs${filePath.split(path.sep).join("/")}`);
|
|
756
840
|
}
|
|
757
|
-
async function tryLoadSourceGalleryHtml(devServer, url, basePath, devSessionToken, themeConfig, tokenPreviewConfig) {
|
|
841
|
+
async function tryLoadSourceGalleryHtml(devServer, url, basePath, devSessionToken, themeConfig, tokenPreviewConfig, toolbar) {
|
|
758
842
|
const gallerySourceDir = resolveGallerySourceDir();
|
|
759
843
|
const indexHtmlPath = path.join(gallerySourceDir, "index.html");
|
|
760
844
|
try {
|
|
@@ -765,12 +849,12 @@ async function tryLoadSourceGalleryHtml(devServer, url, basePath, devSessionToke
|
|
|
765
849
|
const sourceEntryPath = toViteFsPath(path.join(gallerySourceDir, "main.ts"));
|
|
766
850
|
let html = await fs.promises.readFile(indexHtmlPath, "utf-8");
|
|
767
851
|
html = html.replace("src=\"./main.ts\"", `src="${sourceEntryPath}"`);
|
|
768
|
-
html = html.replace("</head>", `<script>${generateDevGlobalsScript(basePath, devSessionToken, themeConfig, tokenPreviewConfig)}<\/script></head>`);
|
|
852
|
+
html = html.replace("</head>", `<script>${generateDevGlobalsScript(basePath, devSessionToken, themeConfig, tokenPreviewConfig, toolbar)}<\/script></head>`);
|
|
769
853
|
return devServer.transformIndexHtml(url, html);
|
|
770
854
|
}
|
|
771
|
-
async function generateFallbackGalleryHtml(basePath, devSessionToken, themeConfig, tokenPreviewConfig) {
|
|
772
|
-
const { generateGalleryHtml } = await import("./gallery-
|
|
773
|
-
return generateGalleryHtml(basePath, devSessionToken, themeConfig, tokenPreviewConfig);
|
|
855
|
+
async function generateFallbackGalleryHtml(basePath, devSessionToken, themeConfig, tokenPreviewConfig, toolbar) {
|
|
856
|
+
const { generateGalleryHtml } = await import("./gallery-CLe_4-XW.mjs");
|
|
857
|
+
return generateGalleryHtml(basePath, devSessionToken, themeConfig, tokenPreviewConfig, toolbar);
|
|
774
858
|
}
|
|
775
859
|
async function serveGalleryAsset(galleryDistDir, requestUrl, res) {
|
|
776
860
|
try {
|
|
@@ -791,19 +875,8 @@ async function serveGalleryAsset(galleryDistDir, requestUrl, res) {
|
|
|
791
875
|
return false;
|
|
792
876
|
}
|
|
793
877
|
}
|
|
794
|
-
/**
|
|
795
|
-
* Register all Musea middleware on the given dev server.
|
|
796
|
-
*
|
|
797
|
-
* This sets up:
|
|
798
|
-
* - Gallery SPA route (serves built SPA or inline HTML fallback)
|
|
799
|
-
* - Gallery static assets (/assets/)
|
|
800
|
-
* - axe-core vendor script
|
|
801
|
-
* - Preview module route
|
|
802
|
-
* - VRT preview route
|
|
803
|
-
* - Art module route
|
|
804
|
-
*/
|
|
805
878
|
function registerMiddleware(devServer, ctx) {
|
|
806
|
-
const { basePath, devSessionToken, themeConfig, tokenPreviewConfig, artFiles } = ctx;
|
|
879
|
+
const { basePath, devSessionToken, themeConfig, tokenPreviewConfig, toolbar, artFiles } = ctx;
|
|
807
880
|
devServer.middlewares.use(basePath, async (req, res, next) => {
|
|
808
881
|
const url = req.url || "/";
|
|
809
882
|
if (url === "/" || url === "/index.html" || url.startsWith("/tokens") || url.startsWith("/component/") || url.startsWith("/tests")) {
|
|
@@ -812,18 +885,18 @@ function registerMiddleware(devServer, ctx) {
|
|
|
812
885
|
try {
|
|
813
886
|
await fs.promises.access(indexHtmlPath);
|
|
814
887
|
let html = await fs.promises.readFile(indexHtmlPath, "utf-8");
|
|
815
|
-
html = html.replace("</head>", `<script>${generateDevGlobalsScript(basePath, devSessionToken, themeConfig, tokenPreviewConfig)}<\/script></head>`);
|
|
888
|
+
html = html.replace("</head>", `<script>${generateDevGlobalsScript(basePath, devSessionToken, themeConfig, tokenPreviewConfig, toolbar)}<\/script></head>`);
|
|
816
889
|
res.setHeader("Content-Type", "text/html");
|
|
817
890
|
res.end(html);
|
|
818
891
|
return;
|
|
819
892
|
} catch {
|
|
820
|
-
const sourceHtml = await tryLoadSourceGalleryHtml(devServer, url, basePath, devSessionToken, themeConfig, tokenPreviewConfig);
|
|
893
|
+
const sourceHtml = await tryLoadSourceGalleryHtml(devServer, url, basePath, devSessionToken, themeConfig, tokenPreviewConfig, toolbar);
|
|
821
894
|
if (sourceHtml) {
|
|
822
895
|
res.setHeader("Content-Type", "text/html");
|
|
823
896
|
res.end(sourceHtml);
|
|
824
897
|
return;
|
|
825
898
|
}
|
|
826
|
-
const html = await generateFallbackGalleryHtml(basePath, devSessionToken, themeConfig, tokenPreviewConfig);
|
|
899
|
+
const html = await generateFallbackGalleryHtml(basePath, devSessionToken, themeConfig, tokenPreviewConfig, toolbar);
|
|
827
900
|
res.setHeader("Content-Type", "text/html");
|
|
828
901
|
res.end(html);
|
|
829
902
|
return;
|
|
@@ -867,7 +940,7 @@ function registerMiddleware(devServer, ctx) {
|
|
|
867
940
|
res.end("Variant not found");
|
|
868
941
|
return;
|
|
869
942
|
}
|
|
870
|
-
const moduleCode = generatePreviewModule(art, toPascalCase(variant.name), variant.name, ctx.resolvedPreviewCss, ctx.resolvedPreviewSetup);
|
|
943
|
+
const moduleCode = generatePreviewModule(art, toPascalCase(variant.name), variant.name, ctx.resolvedPreviewCss, ctx.resolvedPreviewSetup, 3, ctx.toolbar);
|
|
871
944
|
try {
|
|
872
945
|
const result = await devServer.transformRequest(`virtual:musea-preview:${artPath}:${variantName}`);
|
|
873
946
|
if (result) {
|
|
@@ -2402,7 +2475,7 @@ function handlePreviewWithProps(ctx, body, res, sendJson, sendError) {
|
|
|
2402
2475
|
sendError("Variant not found", 404);
|
|
2403
2476
|
return;
|
|
2404
2477
|
}
|
|
2405
|
-
const moduleCode = generatePreviewModuleWithProps(art, toPascalCase(variant.name), variant.name, propsOverride, ctx.resolvedPreviewCss, ctx.resolvedPreviewSetup);
|
|
2478
|
+
const moduleCode = generatePreviewModuleWithProps(art, toPascalCase(variant.name), variant.name, propsOverride, ctx.resolvedPreviewCss, ctx.resolvedPreviewSetup, 3, ctx.toolbar);
|
|
2406
2479
|
res.setHeader("Content-Type", "application/javascript");
|
|
2407
2480
|
res.end(moduleCode);
|
|
2408
2481
|
} catch (e) {
|
|
@@ -2819,7 +2892,7 @@ function createLoad(state) {
|
|
|
2819
2892
|
const artPath = rest.slice(0, lastColonIndex);
|
|
2820
2893
|
const variantName = rest.slice(lastColonIndex + 1);
|
|
2821
2894
|
const art = state.artFiles.get(artPath);
|
|
2822
|
-
if (art) return generatePreviewModule(art, toPascalCase(variantName), variantName, state.resolvedPreviewCss, state.resolvedPreviewSetup, state.getVueVersion());
|
|
2895
|
+
if (art) return generatePreviewModule(art, toPascalCase(variantName), variantName, state.resolvedPreviewCss, state.resolvedPreviewSetup, state.getVueVersion(), state.toolbar);
|
|
2823
2896
|
}
|
|
2824
2897
|
}
|
|
2825
2898
|
if (id.startsWith("\0musea-shared:")) {
|
|
@@ -3151,7 +3224,8 @@ function injectStaticGlobals(html, ctx, payload) {
|
|
|
3151
3224
|
basePath: ctx.basePath,
|
|
3152
3225
|
staticPreviews: payload.previews,
|
|
3153
3226
|
themeConfig: ctx.themeConfig,
|
|
3154
|
-
tokenPreviewConfig: ctx.tokenPreviewConfig
|
|
3227
|
+
tokenPreviewConfig: ctx.tokenPreviewConfig,
|
|
3228
|
+
toolbar: ctx.toolbar
|
|
3155
3229
|
})}<\/script>`;
|
|
3156
3230
|
return html.includes("</head>") ? html.replace("</head>", `${script}</head>`) : `${script}${html}`;
|
|
3157
3231
|
}
|
|
@@ -3428,6 +3502,7 @@ function musea(options = {}) {
|
|
|
3428
3502
|
const themeConfig = buildThemeConfig(options.theme);
|
|
3429
3503
|
const previewCss = options.previewCss ?? [];
|
|
3430
3504
|
const previewSetup = options.previewSetup;
|
|
3505
|
+
const toolbar = normalizeToolbar(options.toolbar);
|
|
3431
3506
|
let vueVersion = options.vueVersion;
|
|
3432
3507
|
const devSessionToken = createDevSessionToken();
|
|
3433
3508
|
let config;
|
|
@@ -3445,6 +3520,7 @@ function musea(options = {}) {
|
|
|
3445
3520
|
artFiles,
|
|
3446
3521
|
resolvedPreviewCss,
|
|
3447
3522
|
resolvedPreviewSetup,
|
|
3523
|
+
toolbar,
|
|
3448
3524
|
getConfigRoot: () => config.root,
|
|
3449
3525
|
getScanRoots: () => scanRoots,
|
|
3450
3526
|
getVueVersion: () => vueVersion,
|
|
@@ -3484,6 +3560,7 @@ function musea(options = {}) {
|
|
|
3484
3560
|
if (options.tokenPreviews === void 0 && mc.tokenPreviews !== void 0) tokenPreviewConfig = mc.tokenPreviews;
|
|
3485
3561
|
}
|
|
3486
3562
|
vueVersion = resolveStaticPreviewVueVersion(vueVersion, resolvedConfig.plugins);
|
|
3563
|
+
if (toolbar.length > 0 && vueVersion !== 3 && vueVersion !== "2.7") throw new Error("[musea] Global toolbar controls require Vue 3 or Vue 2.7");
|
|
3487
3564
|
staticBuildEnabled = shouldEmitMuseaStaticGallery(resolvedConfig.command, storybookCompat);
|
|
3488
3565
|
virtualState.basePath = basePath;
|
|
3489
3566
|
resolvedPreviewCss = previewCss.map((cssPath) => resolvePreviewCssPath(resolvedConfig.root, cssPath));
|
|
@@ -3502,7 +3579,8 @@ function musea(options = {}) {
|
|
|
3502
3579
|
artFiles,
|
|
3503
3580
|
scanRoots,
|
|
3504
3581
|
resolvedPreviewCss,
|
|
3505
|
-
resolvedPreviewSetup
|
|
3582
|
+
resolvedPreviewSetup,
|
|
3583
|
+
toolbar
|
|
3506
3584
|
});
|
|
3507
3585
|
devServer.middlewares.use(`${basePath}/api`, createApiMiddleware({
|
|
3508
3586
|
config,
|
|
@@ -3513,6 +3591,7 @@ function musea(options = {}) {
|
|
|
3513
3591
|
basePath,
|
|
3514
3592
|
resolvedPreviewCss,
|
|
3515
3593
|
resolvedPreviewSetup,
|
|
3594
|
+
toolbar,
|
|
3516
3595
|
devSessionToken,
|
|
3517
3596
|
processArtFile,
|
|
3518
3597
|
getDevServerPort: () => devServer.config.server.port || 5173
|
|
@@ -3595,6 +3674,7 @@ function musea(options = {}) {
|
|
|
3595
3674
|
basePath,
|
|
3596
3675
|
resolvedPreviewCss,
|
|
3597
3676
|
resolvedPreviewSetup,
|
|
3677
|
+
toolbar,
|
|
3598
3678
|
devSessionToken,
|
|
3599
3679
|
themeConfig,
|
|
3600
3680
|
tokenPreviewConfig
|