@vizejs/vite-plugin-musea 0.212.0 → 0.213.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.
Files changed (26) hide show
  1. package/dist/gallery/assets/{MonacoEditor-B2IJhz0Y.js → MonacoEditor-DDaVVCDS.js} +2 -2
  2. package/dist/gallery/assets/{cssMode-Wf2sPjo8.js → cssMode-CKViSGi9.js} +1 -1
  3. package/dist/gallery/assets/{editor.api2-BqfVxaLn.js → editor.api2-JLPIid3z.js} +1 -1
  4. package/dist/gallery/assets/{editor.main-D0q_EY2R.js → editor.main-Bq_ctcW5.js} +2 -2
  5. package/dist/gallery/assets/{freemarker2-B9IYORwa.js → freemarker2-Ch47yFcF.js} +1 -1
  6. package/dist/gallery/assets/{handlebars-CtmQAyr9.js → handlebars-FXhbY-x_.js} +1 -1
  7. package/dist/gallery/assets/{html-DjlePv7f.js → html-C0HtpPJN.js} +1 -1
  8. package/dist/gallery/assets/{htmlMode-CKqPNIWJ.js → htmlMode-CG2rAkzX.js} +1 -1
  9. package/dist/gallery/assets/{index-DGDOzWKX.js → index-BiffEg37.js} +21 -21
  10. package/dist/gallery/assets/{javascript-t8XpHDSo.js → javascript-jKsG4cGd.js} +1 -1
  11. package/dist/gallery/assets/{jsonMode-C9VGEvKg.js → jsonMode-C5r8Zpre.js} +1 -1
  12. package/dist/gallery/assets/{liquid-B1SQ490s.js → liquid-DmBC_f_t.js} +1 -1
  13. package/dist/gallery/assets/{lspLanguageFeatures-BtMEaqrF.js → lspLanguageFeatures-CG46WfMo.js} +1 -1
  14. package/dist/gallery/assets/{mdx-BcRzkdPF.js → mdx-B5QE5lNU.js} +1 -1
  15. package/dist/gallery/assets/{monaco.contribution-JsWDXWUd.js → monaco.contribution-B3jBCkTa.js} +2 -2
  16. package/dist/gallery/assets/{python-DrL7J2F1.js → python-BvMcq-jA.js} +1 -1
  17. package/dist/gallery/assets/{razor-DnIM76SH.js → razor-DSc3s6wR.js} +1 -1
  18. package/dist/gallery/assets/{tsMode-D0BSp2Hl.js → tsMode-CLuaQ4mz.js} +1 -1
  19. package/dist/gallery/assets/{typescript-CIlbt26G.js → typescript-Cv22HOTq.js} +1 -1
  20. package/dist/gallery/assets/{workers-BOfCFwI1.js → workers-asCHrC9z.js} +1 -1
  21. package/dist/gallery/assets/{xml-ChCK-qRB.js → xml-8-9t-9Fe.js} +1 -1
  22. package/dist/gallery/assets/{yaml-j7nYrnzD.js → yaml-Cbg_VNtl.js} +1 -1
  23. package/dist/gallery/index.html +1 -1
  24. package/dist/index.mjs +111 -44
  25. package/dist/index.mjs.map +1 -1
  26. package/package.json +4 -4
package/dist/index.mjs CHANGED
@@ -2080,56 +2080,123 @@ async function handleArtPalette(ctx, match, sendJson, sendError) {
2080
2080
  json: "{}",
2081
2081
  typescript: ""
2082
2082
  };
2083
- if (palette.controls.length === 0) {
2084
- const resolvedComponentPath = resolveComponentSourcePath(art, artPath, allowedSourceRoots(ctx.config.root, ctx.scanRoots));
2085
- if (!resolvedComponentPath) {
2086
- sendJson(palette);
2087
- return;
2088
- }
2089
- try {
2090
- const componentSource = await fs.promises.readFile(resolvedComponentPath, "utf-8");
2091
- const analysis = binding.analyzeSfc ? binding.analyzeSfc(componentSource, { filename: resolvedComponentPath }) : analyzeSfcFallback(componentSource, { filename: resolvedComponentPath });
2092
- if (analysis.props.length > 0) {
2093
- palette.controls = analysis.props.map((prop) => {
2094
- let control = "text";
2095
- if (prop.type === "boolean") control = "boolean";
2096
- else if (prop.type === "number") control = "number";
2097
- else if (prop.type.includes("|") && !prop.type.includes("=>")) control = "select";
2098
- const options = [];
2099
- if (control === "select") {
2100
- const optionMatches = prop.type.match(/"([^"]+)"/g);
2101
- if (optionMatches) for (const opt of optionMatches) {
2102
- const val = opt.replace(/"/g, "");
2103
- options.push({
2104
- label: val,
2105
- value: val
2106
- });
2107
- }
2108
- }
2109
- return {
2110
- name: prop.name,
2111
- control,
2112
- default_value: prop.default_value !== void 0 ? prop.default_value === "true" ? true : prop.default_value === "false" ? false : typeof prop.default_value === "string" && prop.default_value.startsWith("\"") ? prop.default_value.replace(/^"|"$/g, "") : prop.default_value : void 0,
2113
- description: void 0,
2114
- required: prop.required,
2115
- options,
2116
- range: void 0,
2117
- group: void 0
2118
- };
2119
- });
2120
- palette.json = JSON.stringify({
2121
- title: palette.title,
2122
- controls: palette.controls
2123
- }, null, 2);
2124
- palette.typescript = `export interface ${palette.title}Props {\n${palette.controls.map((c) => ` ${c.name}${c.required ? "" : "?"}: ${c.control === "boolean" ? "boolean" : c.control === "number" ? "number" : c.control === "select" ? c.options.map((o) => `"${String(o.value)}"`).join(" | ") : "string"};`).join("\n")}\n}\n`;
2125
- }
2126
- } catch {}
2083
+ const resolvedComponentPath = resolveComponentSourcePath(art, artPath, allowedSourceRoots(ctx.config.root, ctx.scanRoots));
2084
+ if (!resolvedComponentPath) {
2085
+ sendJson(palette);
2086
+ return;
2127
2087
  }
2088
+ try {
2089
+ const componentSource = await fs.promises.readFile(resolvedComponentPath, "utf-8");
2090
+ const analysis = binding.analyzeSfc ? binding.analyzeSfc(componentSource, { filename: resolvedComponentPath }) : analyzeSfcFallback(componentSource, { filename: resolvedComponentPath });
2091
+ if (analysis.props.length > 0) mergeSfcPropsIntoPalette(palette, analysis.props);
2092
+ } catch {}
2128
2093
  sendJson(palette);
2129
2094
  } catch (e) {
2130
2095
  sendError(e instanceof Error ? e.message : String(e));
2131
2096
  }
2132
2097
  }
2098
+ function mergeSfcPropsIntoPalette(palette, props) {
2099
+ const controlsByName = /* @__PURE__ */ new Map();
2100
+ for (const control of palette.controls) controlsByName.set(normalizePropName(control.name), control);
2101
+ for (const prop of props) {
2102
+ const control = controlsByName.get(normalizePropName(prop.name));
2103
+ if (control) applyPropMetadata(control, prop);
2104
+ else palette.controls.push(controlFromProp(prop));
2105
+ }
2106
+ palette.json = JSON.stringify({
2107
+ title: palette.title,
2108
+ controls: palette.controls
2109
+ }, null, 2);
2110
+ palette.typescript = generateTypescript(palette);
2111
+ }
2112
+ function applyPropMetadata(control, prop) {
2113
+ const inferred = inferControl(prop.type);
2114
+ control.name = prop.name;
2115
+ control.required = prop.required;
2116
+ if (control.default_value === void 0 && prop.default_value !== void 0) control.default_value = parseDefault(prop.default_value);
2117
+ if (inferred.control !== "text" || control.control === "text") control.control = inferred.control;
2118
+ if (inferred.options.length > 0) control.options = inferred.options;
2119
+ }
2120
+ function controlFromProp(prop) {
2121
+ const inferred = inferControl(prop.type);
2122
+ return {
2123
+ name: prop.name,
2124
+ control: inferred.control,
2125
+ default_value: prop.default_value === void 0 ? void 0 : parseDefault(prop.default_value),
2126
+ description: void 0,
2127
+ required: prop.required,
2128
+ options: inferred.options,
2129
+ range: void 0,
2130
+ group: void 0
2131
+ };
2132
+ }
2133
+ function inferControl(type) {
2134
+ const normalized = type.trim();
2135
+ const options = literalOptions(normalized);
2136
+ if (options.length > 0) return {
2137
+ control: "select",
2138
+ options
2139
+ };
2140
+ if (normalized === "boolean") return {
2141
+ control: "boolean",
2142
+ options: []
2143
+ };
2144
+ if (normalized === "number") return {
2145
+ control: "number",
2146
+ options: []
2147
+ };
2148
+ if (normalized.includes("[]") || normalized.startsWith("Array<")) return {
2149
+ control: "array",
2150
+ options: []
2151
+ };
2152
+ if (normalized.startsWith("{") || normalized.startsWith("Record<")) return {
2153
+ control: "object",
2154
+ options: []
2155
+ };
2156
+ return {
2157
+ control: "text",
2158
+ options: []
2159
+ };
2160
+ }
2161
+ function literalOptions(type) {
2162
+ if (!type.includes("|") || type.includes("=>")) return [];
2163
+ return type.split("|").map((part) => part.trim()).map((part) => {
2164
+ const stringMatch = part.match(/^["']([^"']+)["']$/);
2165
+ if (stringMatch) return stringMatch[1];
2166
+ if (part === "true") return true;
2167
+ if (part === "false") return false;
2168
+ const numberValue = Number(part);
2169
+ return Number.isFinite(numberValue) ? numberValue : void 0;
2170
+ }).filter((value) => value !== void 0).map((value) => ({
2171
+ label: String(value),
2172
+ value
2173
+ }));
2174
+ }
2175
+ function parseDefault(value) {
2176
+ if (typeof value !== "string") return value;
2177
+ if (value === "true") return true;
2178
+ if (value === "false") return false;
2179
+ if (/^-?\d+(?:\.\d+)?$/.test(value)) return Number(value);
2180
+ return value.replace(/^["']|["']$/g, "");
2181
+ }
2182
+ function normalizePropName(name) {
2183
+ return name.replace(/[-_]/g, "").toLowerCase();
2184
+ }
2185
+ function generateTypescript(palette) {
2186
+ const fields = palette.controls.map((control) => ` ${control.name}${control.required ? "" : "?"}: ${controlTsType(control)};`).join("\n");
2187
+ return `export interface ${pascalCase(palette.title)}Props {\n${fields}\n}\n`;
2188
+ }
2189
+ function controlTsType(control) {
2190
+ if (control.control === "boolean") return "boolean";
2191
+ if (control.control === "number" || control.control === "range") return "number";
2192
+ if (control.control === "array") return "unknown[]";
2193
+ if (control.control === "object") return "Record<string, unknown>";
2194
+ if (control.control === "select" && control.options.length > 0) return control.options.map((option) => JSON.stringify(option.value)).join(" | ");
2195
+ return "string";
2196
+ }
2197
+ function pascalCase(value) {
2198
+ return value.split(/[^A-Za-z0-9]+/).filter(Boolean).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
2199
+ }
2133
2200
  //#endregion
2134
2201
  //#region src/api-routes/handlers.ts
2135
2202
  /**