@uniform-ts/core 0.0.1 → 0.0.3

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/index.mjs CHANGED
@@ -61,25 +61,30 @@ function introspectSchema(schema, name = "", parentPath = "") {
61
61
  let maxItems;
62
62
  try {
63
63
  if (kind === "string") {
64
- type = "string";
65
- const defFormat = def.format;
66
- if (defFormat === "email") {
67
- mergedMeta["inputType"] = "email";
68
- } else if (defFormat === "url") {
69
- mergedMeta["inputType"] = "url";
70
- } else if (defFormat === "uuid") {
71
- mergedMeta["inputType"] = "uuid";
64
+ if (mergedMeta.component === "select" && Array.isArray(mergedMeta.options) && mergedMeta.options.length > 0) {
65
+ type = "select";
66
+ options = mergedMeta.options;
72
67
  } else {
73
- const checks = def.checks ?? [];
74
- const hasFormat = (fmt) => checks.some(
75
- (c) => c._zod.def.check === "string_format" && c._zod.def.format === fmt
76
- );
77
- if (hasFormat("email")) {
68
+ type = "string";
69
+ const defFormat = def.format;
70
+ if (defFormat === "email") {
78
71
  mergedMeta["inputType"] = "email";
79
- } else if (hasFormat("url")) {
72
+ } else if (defFormat === "url") {
80
73
  mergedMeta["inputType"] = "url";
81
- } else if (hasFormat("uuid")) {
74
+ } else if (defFormat === "uuid") {
82
75
  mergedMeta["inputType"] = "uuid";
76
+ } else {
77
+ const checks = def.checks ?? [];
78
+ const hasFormat = (fmt) => checks.some(
79
+ (c) => c._zod.def.check === "string_format" && c._zod.def.format === fmt
80
+ );
81
+ if (hasFormat("email")) {
82
+ mergedMeta["inputType"] = "email";
83
+ } else if (hasFormat("url")) {
84
+ mergedMeta["inputType"] = "url";
85
+ } else if (hasFormat("uuid")) {
86
+ mergedMeta["inputType"] = "uuid";
87
+ }
83
88
  }
84
89
  }
85
90
  } else if (kind === "number") {
@@ -116,15 +121,24 @@ function introspectSchema(schema, name = "", parentPath = "") {
116
121
  }
117
122
  }
118
123
  } else if (def.type === "union") {
119
- type = "union";
120
124
  const unionDef = def;
125
+ const variants = unionDef.options;
121
126
  if ("discriminator" in unionDef) {
127
+ type = "union";
122
128
  discriminatorKey = unionDef.discriminator;
129
+ unionVariants = variants.map(
130
+ (variant, i) => introspectSchema(variant, String(i), path)
131
+ );
132
+ } else {
133
+ const collapsed = introspectSchema(variants[0], name, parentPath);
134
+ return {
135
+ ...collapsed,
136
+ name: path,
137
+ label,
138
+ meta: { ...collapsed.meta, ...mergedMeta },
139
+ schema: inner
140
+ };
123
141
  }
124
- const variants = unionDef.options;
125
- unionVariants = variants.map(
126
- (variant, i) => introspectSchema(variant, String(i), path)
127
- );
128
142
  }
129
143
  } catch {
130
144
  type = "unknown";
@@ -135,6 +149,7 @@ function introspectSchema(schema, name = "", parentPath = "") {
135
149
  label,
136
150
  required,
137
151
  meta: mergedMeta,
152
+ schema: inner,
138
153
  ...options !== void 0 && { options },
139
154
  ...children !== void 0 && { children },
140
155
  ...itemConfig !== void 0 && { itemConfig },
@@ -173,6 +188,7 @@ function parseDiscriminatedUnionMeta(schema) {
173
188
  label: deriveLabel(discriminatorKey),
174
189
  required: true,
175
190
  meta: {},
191
+ schema,
176
192
  options: discriminatorOptions
177
193
  };
178
194
  return {
@@ -360,9 +376,10 @@ function DefaultFormWrapper({ children }) {
360
376
  }
361
377
  function DefaultSectionWrapper({
362
378
  children,
363
- title
379
+ title,
380
+ className
364
381
  }) {
365
- return /* @__PURE__ */ jsxs("fieldset", { children: [
382
+ return /* @__PURE__ */ jsxs("fieldset", { className, children: [
366
383
  /* @__PURE__ */ jsx("legend", { children: title }),
367
384
  children
368
385
  ] });
@@ -473,7 +490,7 @@ function ScalarField({
473
490
  onChange: (value) => {
474
491
  const coerced = coerceValue(field.type, value, coercions);
475
492
  rhfField.onChange(coerced);
476
- field.meta.onChange?.(coerced, formMethods);
493
+ void field.meta.onChange?.(coerced, formMethods);
477
494
  },
478
495
  onBlur: rhfField.onBlur,
479
496
  ref: rhfField.ref,
@@ -483,7 +500,9 @@ function ScalarField({
483
500
  error: fieldState.error?.message,
484
501
  required: field.required,
485
502
  disabled: field.meta.disabled || contextDisabled,
486
- meta: field.meta
503
+ options: field.meta.options,
504
+ meta: field.meta,
505
+ schema: field.schema
487
506
  }
488
507
  )
489
508
  }
@@ -515,7 +534,7 @@ function BooleanField({
515
534
  value: rhfField.value ?? false,
516
535
  onChange: (value) => {
517
536
  rhfField.onChange(value);
518
- field.meta.onChange?.(value, formMethods);
537
+ void field.meta.onChange?.(value, formMethods);
519
538
  },
520
539
  onBlur: rhfField.onBlur,
521
540
  ref: rhfField.ref,
@@ -525,7 +544,8 @@ function BooleanField({
525
544
  error: fieldState.error?.message,
526
545
  required: field.required,
527
546
  disabled: field.meta.disabled || rhfField.disabled || contextDisabled,
528
- meta: field.meta
547
+ meta: field.meta,
548
+ schema: field.schema
529
549
  }
530
550
  )
531
551
  }
@@ -557,7 +577,7 @@ function SelectField({
557
577
  value: rhfField.value ?? "",
558
578
  onChange: (value) => {
559
579
  rhfField.onChange(value);
560
- field.meta.onChange?.(value, formMethods);
580
+ void field.meta.onChange?.(value, formMethods);
561
581
  },
562
582
  onBlur: rhfField.onBlur,
563
583
  ref: rhfField.ref,
@@ -568,7 +588,8 @@ function SelectField({
568
588
  required: field.required,
569
589
  disabled: field.meta.disabled || contextDisabled,
570
590
  options: field.options,
571
- meta: field.meta
591
+ meta: field.meta,
592
+ schema: field.schema
572
593
  }
573
594
  )
574
595
  }
@@ -1483,7 +1504,17 @@ function AutoForm(props) {
1483
1504
  if (section.title === null) {
1484
1505
  return /* @__PURE__ */ jsx(React3.Fragment, { children: renderedFields }, "__ungrouped");
1485
1506
  }
1486
- return /* @__PURE__ */ jsx(SectionWrapper, { title: section.title, children: renderedFields }, section.title);
1507
+ const sectionConfig = layout?.sections?.[section.title];
1508
+ const PerSectionWrapper = sectionConfig?.component ?? SectionWrapper;
1509
+ return /* @__PURE__ */ jsx(
1510
+ PerSectionWrapper,
1511
+ {
1512
+ title: section.title,
1513
+ className: sectionConfig?.className,
1514
+ children: renderedFields
1515
+ },
1516
+ section.title
1517
+ );
1487
1518
  }),
1488
1519
  /* @__PURE__ */ jsx(
1489
1520
  SubmitButton,
@@ -1503,7 +1534,11 @@ function createAutoForm(config) {
1503
1534
  [props.components]
1504
1535
  );
1505
1536
  const mergedLayout = React3.useMemo(
1506
- () => ({ ...config.layout, ...props.layout }),
1537
+ () => ({
1538
+ ...config.layout,
1539
+ ...props.layout,
1540
+ sections: config.layout?.sections || props.layout?.sections ? { ...config.layout?.sections, ...props.layout?.sections } : void 0
1541
+ }),
1507
1542
  [props.layout]
1508
1543
  );
1509
1544
  const mergedClassNames = React3.useMemo(