@dragonmastery/zinia-forms-core 0.3.16 → 0.3.17

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.d.ts CHANGED
@@ -1516,7 +1516,7 @@ declare function useForm<T extends z.ZodObject<any>, CalcType = (values: z.infer
1516
1516
  timestamp: number;
1517
1517
  timeoutId?: number;
1518
1518
  }[]>;
1519
- fieldsMetadata: Record<string, FieldMetadata>;
1519
+ readonly fieldsMetadata: Record<string, FieldMetadata>;
1520
1520
  validate: (options?: {
1521
1521
  markErrorsAsTouched: boolean;
1522
1522
  }) => boolean;
package/dist/index.js CHANGED
@@ -651,6 +651,12 @@ var SchemaCache = class {
651
651
  if (debug) {
652
652
  console.log(`[SchemaCache] More segments remaining, continuing to next segment`);
653
653
  }
654
+ if (!(currentSchema instanceof z.ZodObject)) {
655
+ if (debug) {
656
+ console.log(`[SchemaCache] ERROR: Element schema is not a ZodObject after unwrap, cannot access nested fields`);
657
+ }
658
+ return null;
659
+ }
654
660
  continue;
655
661
  }
656
662
  if (debug) {
@@ -1058,6 +1064,11 @@ function extractFieldMetadata(schema, path = "", parentSchema, schemaId) {
1058
1064
  metadata.isArray = true;
1059
1065
  if (schema._def.minLength) {
1060
1066
  metadata.min = schema._def.minLength.value;
1067
+ if (schema._def.minLength.value > 0) ; else {
1068
+ metadata.isRequired = false;
1069
+ }
1070
+ } else {
1071
+ metadata.isRequired = false;
1061
1072
  }
1062
1073
  if (schema._def.maxLength) {
1063
1074
  metadata.max = schema._def.maxLength.value;
@@ -1174,9 +1185,7 @@ function extractFieldMetadata(schema, path = "", parentSchema, schemaId) {
1174
1185
  } else if (customMetadata.options) {
1175
1186
  metadata.options = customMetadata.options;
1176
1187
  } else {
1177
- metadata.options = [
1178
- { value: "", label: "Select an option" }
1179
- ];
1188
+ metadata.options = [{ value: "", label: "Select an option" }];
1180
1189
  }
1181
1190
  }
1182
1191
  }
@@ -1815,6 +1824,83 @@ function useFormValidation(schema, formState, options) {
1815
1824
  validateField: validateField2
1816
1825
  };
1817
1826
  }
1827
+
1828
+ // src/metadata/resolveMetadataPath.ts
1829
+ function resolveMetadataPath(fieldsMetadata, path) {
1830
+ if (path in fieldsMetadata) {
1831
+ return fieldsMetadata[path];
1832
+ }
1833
+ return resolveMetadataPathRecursive(fieldsMetadata, path.split("."), 0);
1834
+ }
1835
+ function resolveMetadataPathRecursive(fieldsMetadata, segments, startIndex, currentMetadata) {
1836
+ if (startIndex >= segments.length) {
1837
+ return void 0;
1838
+ }
1839
+ if (currentMetadata) {
1840
+ const segment = segments[startIndex];
1841
+ if (!isNaN(Number(segment))) {
1842
+ if (currentMetadata.arrayOf) {
1843
+ return resolveMetadataPathRecursive(fieldsMetadata, segments, startIndex + 1, currentMetadata.arrayOf);
1844
+ }
1845
+ return void 0;
1846
+ } else {
1847
+ if (currentMetadata.children) {
1848
+ const childMetadata = currentMetadata.children[segment];
1849
+ if (childMetadata) {
1850
+ if (startIndex + 1 < segments.length) {
1851
+ return resolveMetadataPathRecursive(fieldsMetadata, segments, startIndex + 1, childMetadata);
1852
+ }
1853
+ return {
1854
+ ...childMetadata,
1855
+ path: segments.join(".")
1856
+ };
1857
+ }
1858
+ }
1859
+ return void 0;
1860
+ }
1861
+ } else {
1862
+ const segment = segments[startIndex];
1863
+ const rootMetadata = fieldsMetadata[segment];
1864
+ if (!rootMetadata) {
1865
+ return void 0;
1866
+ }
1867
+ if (startIndex + 1 < segments.length) {
1868
+ return resolveMetadataPathRecursive(fieldsMetadata, segments, startIndex + 1, rootMetadata);
1869
+ }
1870
+ return {
1871
+ ...rootMetadata,
1872
+ path: segments.join(".")
1873
+ };
1874
+ }
1875
+ }
1876
+ function createMetadataProxy(fieldsMetadata) {
1877
+ return new Proxy(fieldsMetadata, {
1878
+ get(target, prop) {
1879
+ if (typeof prop !== "string") {
1880
+ return Reflect.get(target, prop);
1881
+ }
1882
+ return resolveMetadataPath(fieldsMetadata, prop);
1883
+ },
1884
+ has(target, prop) {
1885
+ if (typeof prop !== "string") {
1886
+ return prop in target;
1887
+ }
1888
+ if (prop in target) {
1889
+ return true;
1890
+ }
1891
+ return resolveMetadataPath(fieldsMetadata, prop) !== void 0;
1892
+ },
1893
+ ownKeys(target) {
1894
+ return Reflect.ownKeys(target);
1895
+ },
1896
+ getOwnPropertyDescriptor(target, prop) {
1897
+ if (prop in target) {
1898
+ return Reflect.getOwnPropertyDescriptor(target, prop);
1899
+ }
1900
+ return void 0;
1901
+ }
1902
+ });
1903
+ }
1818
1904
  function setupLocalStoragePersistence(formData, options) {
1819
1905
  const { storeName, enabled = true, initialValues = {}, debug = false } = options;
1820
1906
  const logger = Logger.getLogger("LocalStoragePersistence");
@@ -2059,7 +2145,11 @@ function useForm(schema, options) {
2059
2145
  get pendingOperations() {
2060
2146
  return formState.state.pendingOperations;
2061
2147
  },
2062
- fieldsMetadata,
2148
+ // Create a Proxy for fieldsMetadata that automatically resolves nested array paths
2149
+ // This allows fieldsMetadata[path] to work for nested array paths like "items.0.fieldName"
2150
+ get fieldsMetadata() {
2151
+ return createMetadataProxy(fieldsMetadata);
2152
+ },
2063
2153
  // Form methods
2064
2154
  validate: validation.validate,
2065
2155
  validateField: validation.validateField,