@selvajs/selva 4.21.0-beta.21 → 4.21.0-beta.22

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 (45) hide show
  1. package/build/adapter-node.js +1 -1
  2. package/build/client/_app/immutable/chunks/{C6zhj8Tc.js → 4yJQa0sB.js} +3 -3
  3. package/build/client/_app/immutable/chunks/4yJQa0sB.js.br +0 -0
  4. package/build/client/_app/immutable/chunks/{C6zhj8Tc.js.gz → 4yJQa0sB.js.gz} +0 -0
  5. package/build/client/_app/immutable/chunks/D6XUYEYz.js +1 -0
  6. package/build/client/_app/immutable/chunks/D6XUYEYz.js.br +1 -0
  7. package/build/client/_app/immutable/chunks/D6XUYEYz.js.gz +0 -0
  8. package/build/client/_app/immutable/entry/{app.C2KpbBu3.js → app.S4XqZiwS.js} +2 -2
  9. package/build/client/_app/immutable/entry/app.S4XqZiwS.js.br +0 -0
  10. package/build/client/_app/immutable/entry/app.S4XqZiwS.js.gz +0 -0
  11. package/build/client/_app/immutable/nodes/21.CYY9kOE5.js +1 -0
  12. package/build/client/_app/immutable/nodes/21.CYY9kOE5.js.br +0 -0
  13. package/build/client/_app/immutable/nodes/21.CYY9kOE5.js.gz +0 -0
  14. package/build/client/_app/version.json +1 -1
  15. package/build/client/_app/version.json.br +0 -0
  16. package/build/client/_app/version.json.gz +0 -0
  17. package/build/server/.vite/manifest.json +9 -0
  18. package/build/server/chunks/capture.js +1 -1
  19. package/build/server/chunks/dynamic-value-list.js +301 -0
  20. package/build/server/chunks/dynamic-value-list.js.map +1 -0
  21. package/build/server/chunks/instance.js +3 -3
  22. package/build/server/chunks/internal.js +1 -1
  23. package/build/server/chunks/package.js +2 -2
  24. package/build/server/chunks/package.js.map +1 -1
  25. package/build/server/chunks/providers.server.js +1 -1
  26. package/build/server/chunks/providers.server.js.map +1 -1
  27. package/build/server/entries/endpoints/mcp/_server.ts.js +242 -39
  28. package/build/server/entries/endpoints/mcp/_server.ts.js.map +1 -1
  29. package/build/server/entries/pages/library/_guid_/_page.svelte.js +3 -299
  30. package/build/server/entries/pages/library/_guid_/_page.svelte.js.map +1 -1
  31. package/build/server/manifest-full.js +1 -1
  32. package/build/server/manifest.js +1 -1
  33. package/build/server/nodes/21.js +1 -1
  34. package/build/server/server.js +1 -1
  35. package/package.json +9 -9
  36. package/templates/.env.example +3 -2
  37. package/build/client/_app/immutable/chunks/C36Kxzt3.js +0 -1
  38. package/build/client/_app/immutable/chunks/C36Kxzt3.js.br +0 -1
  39. package/build/client/_app/immutable/chunks/C36Kxzt3.js.gz +0 -0
  40. package/build/client/_app/immutable/chunks/C6zhj8Tc.js.br +0 -0
  41. package/build/client/_app/immutable/entry/app.C2KpbBu3.js.br +0 -0
  42. package/build/client/_app/immutable/entry/app.C2KpbBu3.js.gz +0 -0
  43. package/build/client/_app/immutable/nodes/21.C3YDbmsU.js +0 -1
  44. package/build/client/_app/immutable/nodes/21.C3YDbmsU.js.br +0 -0
  45. package/build/client/_app/immutable/nodes/21.C3YDbmsU.js.gz +0 -0
@@ -1,5 +1,6 @@
1
1
  import { a as isDynamicValueListWidget, c as isTextWidget, i as isDropdownWidget, n as isCheckboxWidget, o as isFileWidget, r as isColorWidget, s as isNumberWidget } from "../../../../chunks/schema.js";
2
2
  import { n as getInputItems, r as getLayoutItems, t as getGroups } from "../../../../chunks/traversal.js";
3
+ import { n as keepHiddenPicks, r as withRowPick, t as buildFormModel } from "../../../../chunks/dynamic-value-list.js";
3
4
  import { _ as subFolderSegments, m as downloadFileDataByRoot, p as decodeBase64ToBinary$1, r as GrasshopperResponseProcessor } from "../../../../chunks/grasshopper.js";
4
5
  import { i as serverSourcedInputIds, n as KEEPALIVE_PREFERENCE, r as raceAbort } from "../../../../chunks/keepalive-DbmLH4v1.js";
5
6
  import { i as outcomeFromComputeMessages, n as decodeOutcome, r as finalizeResult, t as decodeDiagnostic } from "../../../../chunks/outcome-D28FgvFK.js";
@@ -14281,13 +14282,13 @@ function createInitialState(schema, scopeKey, read) {
14281
14282
  * `force` overrides that, and what it solves is every pending edit.
14282
14283
  */
14283
14284
  function applyValueChange(state, id, value, instanceSolve, force = false) {
14284
- if (instanceSolve === false && !force && sameValue$1(state.values[id], value)) return false;
14285
+ if (instanceSolve === false && !force && sameValue(state.values[id], value)) return false;
14285
14286
  state.values[id] = value;
14286
14287
  if (instanceSolve !== false) return true;
14287
14288
  state.hasPendingChanges = !force;
14288
14289
  return force;
14289
14290
  }
14290
- function sameValue$1(a, b) {
14291
+ function sameValue(a, b) {
14291
14292
  if (Object.is(a, b)) return true;
14292
14293
  if (a === null || b === null || typeof a !== "object" || typeof b !== "object") return false;
14293
14294
  return stableInputKey(a) === stableInputKey(b);
@@ -21093,303 +21094,6 @@ function TabContent($$renderer, $$props) {
21093
21094
  }
21094
21095
  });
21095
21096
  }
21096
- // ../ui/src/lib/schema/dynamic-value-list.ts
21097
- function isDynamicValueListPayload(value) {
21098
- return typeof value === "object" && value !== null && ("targetInputId" in value || "options" in value);
21099
- }
21100
- /**
21101
- * Normalize a raw output value into a payload object.
21102
- *
21103
- * The local/WebSocket path delivers a real object; the Rhino.Compute path delivers the
21104
- * component's JSON output as a string (possibly double-encoded by the compute layer), so try
21105
- * to parse strings before giving up.
21106
- */
21107
- function coercePayload(value) {
21108
- if (isDynamicValueListPayload(value)) return value;
21109
- let candidate = value;
21110
- for (let i = 0; i < 2 && typeof candidate === "string"; i++) {
21111
- try {
21112
- candidate = JSON.parse(candidate);
21113
- } catch {
21114
- return null;
21115
- }
21116
- if (isDynamicValueListPayload(candidate)) return candidate;
21117
- }
21118
- return null;
21119
- }
21120
- var coerceCache = /* @__PURE__ */ new Map();
21121
- var COERCE_CACHE_MAX = 8;
21122
- function coercePayloadMemo(value) {
21123
- if (typeof value !== "string" || value.length < 1024) return coercePayload(value);
21124
- const hit = coerceCache.get(value);
21125
- if (hit !== void 0 || coerceCache.has(value)) {
21126
- coerceCache.delete(value);
21127
- coerceCache.set(value, hit ?? null);
21128
- return hit ?? null;
21129
- }
21130
- const parseStart = performance.now();
21131
- const parsed = coercePayload(value);
21132
- if (value.length > 262144) {
21133
- const optionCount = parsed?.options ? Object.keys(parsed.options).length : 0;
21134
- console.info(`[DVL] parsed ${(value.length / 1048576).toFixed(1)} MB options payload (${optionCount} options) in ${(performance.now() - parseStart).toFixed(0)}ms — cache miss`);
21135
- }
21136
- if (coerceCache.size >= COERCE_CACHE_MAX) {
21137
- const oldest = coerceCache.keys().next().value;
21138
- if (oldest !== void 0) coerceCache.delete(oldest);
21139
- }
21140
- coerceCache.set(value, parsed);
21141
- return parsed;
21142
- }
21143
- /**
21144
- * Every dynamicValueList output reference in the schema.
21145
- *
21146
- * Canonical location is `schema.outputs[]` — the plugin's SchemaSynchronizer mirrors every
21147
- * dynamicValueList layout item there (`CanonicalizeDynamicValueListOutputs`). The layout scan is
21148
- * back-compat defense for schemas persisted by an older plugin that lacked that invariant; on
21149
- * current schemas it finds nothing new. Deduped by id, `outputs[]` winning so the canonical
21150
- * record's targetInputId takes precedence.
21151
- */
21152
- function collectDynamicValueListSources(schema) {
21153
- const byId = /* @__PURE__ */ new Map();
21154
- for (const item of getLayoutItems(schema)) {
21155
- if (item.type !== "output" || item.widgetType !== "dynamicValueList") continue;
21156
- const dvl = item;
21157
- if (typeof dvl.paramId !== "string") continue;
21158
- byId.set(dvl.paramId, {
21159
- id: dvl.paramId,
21160
- targetInputId: dvl.config?.targetInputId
21161
- });
21162
- }
21163
- for (const output of schema.outputs ?? []) {
21164
- if (output.type !== "dynamicValueList") continue;
21165
- byId.set(output.id, {
21166
- id: output.id,
21167
- targetInputId: output.targetInputId
21168
- });
21169
- }
21170
- return [...byId.values()];
21171
- }
21172
- function findOptionIndex(entries, pick) {
21173
- if (typeof pick !== "string") return -1;
21174
- const wanted = pick.toLowerCase();
21175
- return entries.findIndex(([name, value]) => value.toLowerCase() === wanted || name.toLowerCase() === wanted);
21176
- }
21177
- /**
21178
- * The option value a pick resolves to, as Grasshopper resolves it in the solve: the pick if still
21179
- * offered (by value or name, ignoring case), else the first option. With no options known the
21180
- * pick passes through. `packages/schemas/fixtures/dynamic-value-list-resolution.json` pins both.
21181
- */
21182
- function resolvePick(options, pick) {
21183
- const entries = Object.entries(options ?? {});
21184
- if (entries.length === 0) return typeof pick === "string" ? pick : "";
21185
- return entries[Math.max(0, findOptionIndex(entries, pick))][1];
21186
- }
21187
- /**
21188
- * Checklist: the picks still offered, in pick order; none left gives the first option. Duplicates
21189
- * collapse by option, not by value, so two options sharing a value both stay.
21190
- */
21191
- function resolvePicks(options, picks) {
21192
- const entries = Object.entries(options ?? {});
21193
- if (entries.length === 0) return picks.filter((p) => typeof p === "string");
21194
- const kept = /* @__PURE__ */ new Set();
21195
- for (const pick of picks) {
21196
- const index = findOptionIndex(entries, pick);
21197
- if (index >= 0) kept.add(index);
21198
- }
21199
- return kept.size > 0 ? [...kept].map((i) => entries[i][1]) : [entries[0][1]];
21200
- }
21201
- /**
21202
- * A checklist edit made on the resolved picks, merged back into the stored ones: picks not offered
21203
- * now were never shown, so the edit can't have removed them, and they come back when offered again.
21204
- */
21205
- function keepHiddenPicks(options, stored, edited) {
21206
- const entries = Object.entries(options ?? {});
21207
- if (entries.length === 0 || !Array.isArray(stored)) return edited;
21208
- const hidden = stored.filter((pick) => typeof pick === "string" && findOptionIndex(entries, pick) < 0 && !edited.includes(pick));
21209
- return [...edited, ...hidden];
21210
- }
21211
- /**
21212
- * A repeated input's picks. Its value is one JSON object of row key to pick, so a pick stays with
21213
- * its row when rows come and go, and the value is a plain string on the wire. Anything else reads
21214
- * as no picks.
21215
- */
21216
- function readRowPicks(value) {
21217
- if (typeof value !== "string" || !value.trimStart().startsWith("{")) return {};
21218
- try {
21219
- const parsed = JSON.parse(value);
21220
- if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return {};
21221
- return Object.fromEntries(Object.entries(parsed).filter((entry) => typeof entry[1] === "string"));
21222
- } catch {
21223
- return {};
21224
- }
21225
- }
21226
- /** The repeated input's value with one row's pick set. Picks for rows not shown now are kept. */
21227
- function withRowPick(value, rowKey, pick) {
21228
- return JSON.stringify({
21229
- ...readRowPicks(value),
21230
- [rowKey]: pick
21231
- });
21232
- }
21233
- /** The options each targeted payload gives its input: one set, or the same set for every row. */
21234
- function lookUpOptions(payloads, repeatById, repeatOf) {
21235
- const options = {};
21236
- const rowOptions = {};
21237
- for (const { source, payload } of payloads) {
21238
- const target = payload.targetInputId ?? source.targetInputId;
21239
- if (!target || !payload.options || typeof payload.options !== "object") continue;
21240
- const repeat = repeatById.get(repeatOf[target]);
21241
- const offered = payload.options;
21242
- if (repeat) rowOptions[target] = repeat.rows.map(() => offered);
21243
- else options[target] = offered;
21244
- }
21245
- for (const { source, payload } of payloads) {
21246
- const repeat = repeatById.get(source.id);
21247
- const offered = payload.options;
21248
- if (!repeat || !offered || Object.keys(offered).length === 0) continue;
21249
- for (const member of repeat.members) rowOptions[member] ??= repeat.rows.map(() => offered);
21250
- }
21251
- return {
21252
- options,
21253
- rowOptions
21254
- };
21255
- }
21256
- var tableOptionsCache = /* @__PURE__ */ new WeakMap();
21257
- /**
21258
- * Narrows each pick table as Grasshopper does in the solve: an input offers the values its column
21259
- * has in the rows left by the picks before it, and resolves its own pick against those.
21260
- * `packages/schemas/fixtures/pick-table.json` pins both.
21261
- */
21262
- function narrowPickTables(payloads, values, repeatById, repeatOf) {
21263
- const options = {};
21264
- const rowOptions = {};
21265
- const shown = {};
21266
- for (const { payload } of payloads) {
21267
- const table = payload.pickTable;
21268
- if (!table || !Array.isArray(table.inputs) || !Array.isArray(table.rows)) continue;
21269
- const cache = tableOptionsCache.get(table.rows) ?? /* @__PURE__ */ new Map();
21270
- tableOptionsCache.set(table.rows, cache);
21271
- const by = Array.isArray(table.by) ? table.by : [];
21272
- const held = by.map((id) => {
21273
- const value = values[id];
21274
- return (Array.isArray(value) ? value : [value]).filter((item) => item !== void 0 && item !== null).map(String);
21275
- });
21276
- const start = Array.from({ length: Math.max(1, ...held.map((h) => h.length)) }, (_, i) => {
21277
- const picked = held.map((items) => items[Math.min(i, items.length - 1)]);
21278
- return {
21279
- rows: table.rows.filter((row) => picked.every((item, d) => item === void 0 || row[d]?.toLowerCase() === item.toLowerCase())),
21280
- picked: picked.map((item) => item ?? "")
21281
- };
21282
- });
21283
- const left = [];
21284
- table.inputs.forEach((id, index) => {
21285
- const column = by.length + index;
21286
- const parent = table.parents?.[index] ?? index - 1;
21287
- const before = parent >= 0 && left[parent] ? left[parent] : start;
21288
- const repeat = repeatById.get(repeatOf[id]);
21289
- const rowPicks = repeat ? readRowPicks(values[id]) : void 0;
21290
- const picks = repeat ? repeat.rows.map((row) => rowPicks?.[row.key]) : [values[id]];
21291
- const offeredPerRow = [];
21292
- const resolved = [];
21293
- const after = picks.map((wanted, i) => {
21294
- const { rows, picked } = before[Math.min(i, before.length - 1)];
21295
- const key = JSON.stringify([column, ...picked]);
21296
- let offered = cache.get(key);
21297
- if (!offered) {
21298
- offered = {};
21299
- for (const row of rows) {
21300
- const cell = row[column];
21301
- if (typeof cell === "string" && cell !== "") offered[cell] = cell;
21302
- }
21303
- cache.set(key, offered);
21304
- }
21305
- offeredPerRow.push(offered);
21306
- const pick = resolvePick(offered, wanted);
21307
- resolved.push(pick);
21308
- return {
21309
- rows: rows.filter((row) => row[column] === pick),
21310
- picked: [...picked, `${column}:${pick}`]
21311
- };
21312
- });
21313
- if (repeat) {
21314
- rowOptions[id] = offeredPerRow;
21315
- shown[id] = resolved;
21316
- } else {
21317
- options[id] = offeredPerRow[0];
21318
- shown[id] = resolved[0];
21319
- }
21320
- left[index] = after.length > 0 ? after : before;
21321
- });
21322
- }
21323
- return {
21324
- options,
21325
- rowOptions,
21326
- shown
21327
- };
21328
- }
21329
- /**
21330
- * What the form shows, from the payloads the last solve returned and the values on screen now.
21331
- * A pick table is narrowed by the picks on screen, so changing one updates the lists that depend
21332
- * on it without a solve.
21333
- *
21334
- * Pass the previous model to keep the identity of every array that didn't change: this runs on
21335
- * each value change, and a fresh array re-renders its whole checklist or repeat.
21336
- */
21337
- function buildFormModel(schema, values, previous) {
21338
- const payloads = [];
21339
- for (const source of collectDynamicValueListSources(schema)) {
21340
- const payload = coercePayloadMemo(values[source.id]);
21341
- if (payload) payloads.push({
21342
- source,
21343
- payload
21344
- });
21345
- }
21346
- const repeats = [];
21347
- const repeatOf = {};
21348
- for (const { source, payload } of payloads) {
21349
- if (!Array.isArray(payload.rows) || !Array.isArray(payload.members)) continue;
21350
- const rows = payload.rows.filter((r) => typeof r?.key === "string");
21351
- repeats.push({
21352
- id: source.id,
21353
- rows,
21354
- members: payload.members
21355
- });
21356
- for (const member of payload.members) repeatOf[member] = source.id;
21357
- }
21358
- const repeatById = new Map(repeats.map((r) => [r.id, r]));
21359
- const tables = narrowPickTables(payloads, values, repeatById, repeatOf);
21360
- const lookup = lookUpOptions(payloads, repeatById, repeatOf);
21361
- Object.assign(lookup.options, tables.options);
21362
- Object.assign(lookup.rowOptions, tables.rowOptions);
21363
- const shown = { ...tables.shown };
21364
- for (const { source, payload } of payloads) {
21365
- const target = payload.targetInputId ?? source.targetInputId;
21366
- if (!target || !payload.resolvedInSolve || repeatOf[target]) continue;
21367
- const value = values[target];
21368
- shown[target] = Array.isArray(value) ? resolvePicks(lookup.options[target], value) : resolvePick(lookup.options[target], value);
21369
- }
21370
- for (const repeat of repeats) for (const member of repeat.members) {
21371
- const picks = readRowPicks(values[member]);
21372
- shown[member] = repeat.rows.map((row, i) => resolvePick(lookup.rowOptions[member]?.[i], picks[row.key]));
21373
- }
21374
- if (previous) {
21375
- reuseUnchanged(shown, previous.shown);
21376
- reuseUnchanged(lookup.rowOptions, previous.rowOptions);
21377
- }
21378
- return {
21379
- ...lookup,
21380
- repeats,
21381
- repeatOf,
21382
- shown
21383
- };
21384
- }
21385
- function sameValue(a, b) {
21386
- if (a === b) return true;
21387
- if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) return false;
21388
- return a.every((item, i) => item === b[i]);
21389
- }
21390
- function reuseUnchanged(next, previous) {
21391
- for (const key of Object.keys(next)) if (key in previous && sameValue(next[key], previous[key])) next[key] = previous[key];
21392
- }
21393
21097
  // ../ui/src/lib/components/preview/TabLayout.svelte
21394
21098
  function TabLayout($$renderer, $$props) {
21395
21099
  $$renderer.component(($$renderer) => {