@marktiderman/genesis-forms 0.5.0 → 0.6.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.
@@ -1,4 +1,4 @@
1
- import { J as Json, F as FormDefinition, a as FieldBlock } from './types-BhYUbLJ-.cjs';
1
+ import { J as Json, F as FormDefinition, a as FieldBlock } from './types-oAckGR_Z.cjs';
2
2
 
3
3
  /**
4
4
  * The contract every destination keeps. A destination sends one checked
@@ -1,4 +1,4 @@
1
- import { J as Json, F as FormDefinition, a as FieldBlock } from './types-BhYUbLJ-.js';
1
+ import { J as Json, F as FormDefinition, a as FieldBlock } from './types-oAckGR_Z.js';
2
2
 
3
3
  /**
4
4
  * The contract every destination keeps. A destination sends one checked
@@ -434,6 +434,57 @@ function summarizeValue(value, field) {
434
434
  if (Array.isArray(value)) return value.join(", ");
435
435
  return String(value);
436
436
  }
437
+ var OPTION_LIMITS = {
438
+ /** Characters in a description. */
439
+ description: 500,
440
+ /** Characters in an image URL. */
441
+ image: 2048,
442
+ /** Attributes on one option. */
443
+ attributes: 20,
444
+ /** Characters in an attribute's name. */
445
+ attributeName: 64,
446
+ /** Characters in one attribute value. */
447
+ attributeValue: 200,
448
+ /** Values in one attribute's list. */
449
+ attributeItems: 50
450
+ };
451
+ function isHttpsUrl(url) {
452
+ return typeof url === "string" && url.length <= OPTION_LIMITS.image && /^https:\/\/[^\s/?#@\\]+(?:[/?#][^\s]*)?$/i.test(url) && // No control characters anywhere (a line break would end a CSV row or an HTML attribute).
453
+ ![...url].some((c) => c.charCodeAt(0) < 32 || c.charCodeAt(0) === 127);
454
+ }
455
+ function attributeName(name) {
456
+ return name.trim() !== "" && name.length <= OPTION_LIMITS.attributeName && !(name in Object.prototype);
457
+ }
458
+ function readAttributes(raw) {
459
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return void 0;
460
+ const out = {};
461
+ let count = 0;
462
+ for (const name of Object.keys(raw)) {
463
+ if (count >= OPTION_LIMITS.attributes) break;
464
+ if (!attributeName(name)) continue;
465
+ const v = raw[name];
466
+ const fits = (x) => typeof x === "string" && x.length <= OPTION_LIMITS.attributeValue;
467
+ if (fits(v)) out[name] = v;
468
+ else if (Array.isArray(v) && v.length <= OPTION_LIMITS.attributeItems && v.every(fits)) out[name] = [...v];
469
+ else continue;
470
+ count++;
471
+ }
472
+ return count ? out : void 0;
473
+ }
474
+ function readOption(raw) {
475
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return null;
476
+ const o = raw;
477
+ if (typeof o.value !== "string") return null;
478
+ const out = { value: o.value };
479
+ if (typeof o.label === "string") out.label = o.label;
480
+ if (typeof o.description === "string" && o.description.trim() && o.description.length <= OPTION_LIMITS.description) {
481
+ out.description = o.description;
482
+ }
483
+ if (isHttpsUrl(o.image)) out.image = o.image;
484
+ const attributes = readAttributes(o.attributes);
485
+ if (attributes) out.attributes = attributes;
486
+ return out;
487
+ }
437
488
  var OTHER_MAX_LENGTH = 200;
438
489
  function otherOption(field) {
439
490
  const other = field.props?.other;
@@ -451,9 +502,10 @@ var typedOther = (field, value) => isOtherValue(field, value) && value.trim() !=
451
502
  function choiceOptions(field) {
452
503
  const raw = field.props?.options;
453
504
  if (!Array.isArray(raw)) return [];
454
- return raw.flatMap(
455
- (o) => o && typeof o === "object" && !Array.isArray(o) && typeof o.value === "string" ? [{ value: o.value, label: typeof o.label === "string" ? o.label : void 0 }] : []
456
- );
505
+ return raw.flatMap((o) => {
506
+ const option = readOption(o);
507
+ return option ? [option] : [];
508
+ });
457
509
  }
458
510
  function optionLabel(field, value) {
459
511
  const option = choiceOptions(field).find((o) => o.value === value);