@yahoo/uds-create-config 4.13.0 → 4.15.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.
@@ -234,6 +234,10 @@ var Converter = class {
234
234
  if (text) props[prop] = text;
235
235
  }
236
236
  }
237
+ if ("value" in declared && props.value === void 0) {
238
+ const field = fieldValue(el, declared.value);
239
+ if (field !== void 0) props.value = field;
240
+ }
237
241
  const loose = [];
238
242
  const looseSelector = renders ? ROOT_LAYER : `${ROOT_LAYER}, svg`;
239
243
  for (const nested of asArray(el.querySelectorAll(looseSelector))) {
@@ -411,6 +415,45 @@ function withinAny(el, layers, root) {
411
415
  function layerOf(root, path, layer) {
412
416
  for (const candidate of asArray(root.querySelectorAll(`[data-uds-component="${path}"][data-uds-layer="${layer}"]`))) if (nearestRoot(candidate) === root) return candidate;
413
417
  }
418
+ /** Field types whose `value` is a submit token rather than what the field shows. */
419
+ const NON_TEXT_INPUT = new Set([
420
+ "checkbox",
421
+ "radio",
422
+ "hidden",
423
+ "submit",
424
+ "button",
425
+ "reset",
426
+ "image",
427
+ "file"
428
+ ]);
429
+ /**
430
+ * What the first form field under `root` shows: an input's `value` attribute, a textarea's text, a
431
+ * select's chosen option. A field inside a nested component belongs to that component. The value is
432
+ * typed by the declaration, so a `number` prop reads `24` rather than `'24'`.
433
+ */
434
+ function fieldValue(root, declaration) {
435
+ for (const field of asArray(root.querySelectorAll("input, textarea, select"))) {
436
+ if (field.closest(ROOT_LAYER) !== root && nearestRoot(field) !== root) continue;
437
+ if (!visible(field) || hiddenBetween(field, root)) continue;
438
+ let raw = null;
439
+ const tag = field.tagName.toLowerCase();
440
+ if (tag === "input") {
441
+ const type = (field.getAttribute("type") ?? "text").toLowerCase();
442
+ if (NON_TEXT_INPUT.has(type)) continue;
443
+ raw = field.getAttribute("value");
444
+ } else if (tag === "textarea") raw = field.textContent;
445
+ else {
446
+ const chosen = asArray(field.querySelectorAll("option")).find((option) => option.hasAttribute("selected"));
447
+ raw = chosen ? chosen.getAttribute("value") ?? chosen.textContent : null;
448
+ }
449
+ if (raw === null || raw === "") return void 0;
450
+ if (declaration?.type === "number") {
451
+ const number = Number(raw);
452
+ return Number.isFinite(number) ? number : void 0;
453
+ }
454
+ return raw;
455
+ }
456
+ }
414
457
  function svgOf(svg) {
415
458
  return {
416
459
  paths: asArray(svg.querySelectorAll("path")).map((p) => p.getAttribute("d") ?? "").filter(Boolean),