rhf-dynamic-forms 1.1.0 → 1.2.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.
package/README.md CHANGED
@@ -50,17 +50,17 @@ Dynamic Forms enables rapid deployment of data collection forms by defining form
50
50
  ## Installation
51
51
 
52
52
  ```bash
53
- npm install dynamic-forms
53
+ npm install rhf-dynamic-forms
54
54
  # or
55
- pnpm add dynamic-forms
55
+ pnpm add rhf-dynamic-forms
56
56
  # or
57
- yarn add dynamic-forms
57
+ yarn add rhf-dynamic-forms
58
58
  ```
59
59
 
60
60
  **Peer Dependencies:**
61
61
 
62
62
  ```bash
63
- npm install react react-dom
63
+ npm install react@^19 react-dom@^19
64
64
  ```
65
65
 
66
66
  ## Quick Start
@@ -407,9 +407,6 @@ interface DynamicFormProps {
407
407
  fieldComponents: FieldComponentRegistry; // Component implementations
408
408
  onSubmit: (data: FormData) => void; // Submit handler
409
409
 
410
- // Optional - Validation (priority order: resolver > schema > config-driven)
411
- resolver?: Resolver<FormData>; // Custom react-hook-form resolver (Yup, Joi, etc.)
412
- schema?: ZodSchema; // External Zod schema (wrapped with visibility-aware resolver)
413
410
 
414
411
  // Optional - Components
415
412
  initialData?: FormData; // Pre-fill form values
@@ -432,6 +429,7 @@ interface DynamicFormProps {
432
429
  style?: CSSProperties;
433
430
  id?: string;
434
431
  children?: React.ReactNode; // Submit button, etc.
432
+ ref?: React.Ref<DynamicFormRef>;
435
433
  }
436
434
  ```
437
435
 
@@ -479,31 +477,42 @@ interface BaseFieldProps {
479
477
  ### Exports
480
478
 
481
479
  ```typescript
482
- // Components
483
- export { DynamicForm } from 'dynamic-forms';
480
+ // Components & Context
481
+ export { DynamicForm, DynamicFormContext } from 'rhf-dynamic-forms';
484
482
 
485
483
  // Hooks
486
- export { useDynamicFormContext, useDynamicFormContextSafe } from 'dynamic-forms';
484
+ export { useDynamicFormContext, useDynamicFormContextSafe } from 'rhf-dynamic-forms';
487
485
 
488
486
  // Custom Components
489
487
  export {
490
488
  defineCustomComponent, // Type-safe component definition helper
489
+ } from 'rhf-dynamic-forms';
490
+
491
+ // Parser
492
+ export {
493
+ parseConfiguration,
494
+ safeParseConfiguration,
491
495
  ConfigurationError, // Error class for invalid configurations
492
- } from 'dynamic-forms';
496
+ } from 'rhf-dynamic-forms';
493
497
 
494
498
  // Types
495
499
  export type {
500
+ // Core configuration types
496
501
  FormConfiguration,
497
502
  FormElement,
498
503
  FieldElement,
499
504
  ContainerElement,
500
505
  ColumnElement,
501
506
  ValidationConfig,
507
+ FormData,
508
+ // Component props
509
+ DynamicFormProps,
510
+ DynamicFormRef,
511
+ DynamicFormContextValue,
512
+ // Registry types
502
513
  FieldComponentRegistry,
503
514
  CustomComponentRegistry,
504
515
  CustomContainerRegistry,
505
- FormData,
506
- ZodSchema,
507
516
  // Custom component types
508
517
  CustomComponentDefinition,
509
518
  CustomComponentRenderProps,
@@ -520,26 +529,27 @@ export type {
520
529
  SelectFieldElement,
521
530
  ArrayFieldElement,
522
531
  SelectOption,
523
- } from 'dynamic-forms';
532
+ } from 'rhf-dynamic-forms';
524
533
 
525
534
  // Utilities
526
535
  export {
527
- parseConfiguration,
528
- safeParseConfiguration,
529
536
  generateZodSchema,
530
537
  createVisibilityAwareResolver,
531
538
  calculateVisibility,
532
539
  flattenFields,
533
540
  getFieldNames,
534
541
  mergeDefaults,
542
+ getNestedValue,
543
+ setNestedValue,
535
544
  applyJsonLogic,
536
545
  evaluateCondition,
546
+ // Type guards
537
547
  isFieldElement,
538
548
  isContainerElement,
539
549
  isColumnElement,
540
550
  isCustomFieldElement,
541
551
  isArrayFieldElement,
542
- } from 'dynamic-forms';
552
+ } from 'rhf-dynamic-forms';
543
553
  ```
544
554
 
545
555
  ## Creating Field Components
package/dist/index.cjs CHANGED
@@ -641,12 +641,13 @@ const columnElementSchema = zod.z.object({
641
641
  });
642
642
  /**
643
643
  * Container element schema (for Phase 2).
644
+ * Uses passthrough() to preserve custom properties like containerMeta.
644
645
  */
645
646
  const containerElementSchema = zod.z.object({
646
647
  type: zod.z.literal("container"),
647
648
  columns: zod.z.array(columnElementSchema),
648
649
  visible: jsonLogicRuleSchema.optional()
649
- });
650
+ }).passthrough();
650
651
  /**
651
652
  * Custom component definition schema.
652
653
  */
@@ -1364,16 +1365,16 @@ const setNestedSchema = (shape, path, schema) => {
1364
1365
  }
1365
1366
  const [first, ...rest] = parts;
1366
1367
  const remainingPath = rest.join(".");
1367
- if (!shape[first]) shape[first] = zod.z.object({});
1368
+ if (!shape[first]) shape[first] = zod.z.looseObject({});
1368
1369
  const existingSchema = shape[first];
1369
1370
  if (existingSchema instanceof zod.ZodObject) {
1370
1371
  const innerShape = { ...existingSchema.shape };
1371
1372
  setNestedSchema(innerShape, remainingPath, schema);
1372
- shape[first] = zod.z.object(innerShape);
1373
+ shape[first] = zod.z.looseObject(innerShape);
1373
1374
  } else {
1374
1375
  const innerShape = {};
1375
1376
  setNestedSchema(innerShape, remainingPath, schema);
1376
- shape[first] = zod.z.object(innerShape);
1377
+ shape[first] = zod.z.looseObject(innerShape);
1377
1378
  }
1378
1379
  };
1379
1380
 
@@ -1439,7 +1440,7 @@ const generateZodSchema = (config) => {
1439
1440
  const fieldSchema = buildFieldSchema(field);
1440
1441
  setNestedSchema(schemaShape, field.name, fieldSchema);
1441
1442
  }
1442
- let schema = zod.z.object(schemaShape);
1443
+ let schema = zod.z.looseObject(schemaShape);
1443
1444
  const conditions = collectConditions(fields);
1444
1445
  if (conditions.length > 0) schema = schema.superRefine((data, ctx) => {
1445
1446
  for (const { fieldPath, condition, message } of conditions) if (!evaluateCondition(condition, data)) ctx.addIssue({
package/dist/index.mjs CHANGED
@@ -612,12 +612,13 @@ const columnElementSchema = z.object({
612
612
  });
613
613
  /**
614
614
  * Container element schema (for Phase 2).
615
+ * Uses passthrough() to preserve custom properties like containerMeta.
615
616
  */
616
617
  const containerElementSchema = z.object({
617
618
  type: z.literal("container"),
618
619
  columns: z.array(columnElementSchema),
619
620
  visible: jsonLogicRuleSchema.optional()
620
- });
621
+ }).passthrough();
621
622
  /**
622
623
  * Custom component definition schema.
623
624
  */
@@ -1335,16 +1336,16 @@ const setNestedSchema = (shape, path, schema) => {
1335
1336
  }
1336
1337
  const [first, ...rest] = parts;
1337
1338
  const remainingPath = rest.join(".");
1338
- if (!shape[first]) shape[first] = z.object({});
1339
+ if (!shape[first]) shape[first] = z.looseObject({});
1339
1340
  const existingSchema = shape[first];
1340
1341
  if (existingSchema instanceof ZodObject) {
1341
1342
  const innerShape = { ...existingSchema.shape };
1342
1343
  setNestedSchema(innerShape, remainingPath, schema);
1343
- shape[first] = z.object(innerShape);
1344
+ shape[first] = z.looseObject(innerShape);
1344
1345
  } else {
1345
1346
  const innerShape = {};
1346
1347
  setNestedSchema(innerShape, remainingPath, schema);
1347
- shape[first] = z.object(innerShape);
1348
+ shape[first] = z.looseObject(innerShape);
1348
1349
  }
1349
1350
  };
1350
1351
 
@@ -1410,7 +1411,7 @@ const generateZodSchema = (config) => {
1410
1411
  const fieldSchema = buildFieldSchema(field);
1411
1412
  setNestedSchema(schemaShape, field.name, fieldSchema);
1412
1413
  }
1413
- let schema = z.object(schemaShape);
1414
+ let schema = z.looseObject(schemaShape);
1414
1415
  const conditions = collectConditions(fields);
1415
1416
  if (conditions.length > 0) schema = schema.superRefine((data, ctx) => {
1416
1417
  for (const { fieldPath, condition, message } of conditions) if (!evaluateCondition(condition, data)) ctx.addIssue({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rhf-dynamic-forms",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Configuration-driven form generation library for React",
5
5
  "author": "Oleh Krachun",
6
6
  "license": "MIT",