@conform-to/react 1.0.0-pre.0 → 1.0.0-pre.1

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/context.d.ts CHANGED
@@ -1,40 +1,53 @@
1
- import { type Constraint, type FieldName, type Form, type FormValue, type FormContext, type SubscriptionSubject } from '@conform-to/dom';
1
+ import { type Constraint, type FormId, type FieldName, type Form, type FormValue, type FormState, type SubscriptionScope, type SubscriptionSubject, type UnionKeyof, type UnionKeyType } from '@conform-to/dom';
2
2
  import { type ReactElement, type ReactNode, type MutableRefObject } from 'react';
3
3
  export type Pretty<T> = {
4
4
  [K in keyof T]: T[K];
5
5
  } & {};
6
- export type BaseMetadata<Schema> = {
6
+ export type Primitive = string | number | boolean | Date | File | null | undefined;
7
+ export type FieldProps<FieldSchema, Error = unknown, FormSchema extends Record<string, unknown> = Record<string, unknown>> = {
8
+ formId: FormId<FormSchema, Error>;
9
+ name: FieldName<FieldSchema>;
10
+ } | {
11
+ formId: FieldSchema extends Record<string, unknown> ? FormId<FieldSchema, Error> : never;
12
+ name?: undefined;
13
+ };
14
+ export type Metadata<Schema, Error> = {
7
15
  key?: string;
8
16
  id: string;
9
17
  errorId: string;
10
18
  descriptionId: string;
11
19
  initialValue: FormValue<Schema>;
12
20
  value: FormValue<Schema>;
13
- errors: string[] | undefined;
14
- allErrors: Record<string, string[]>;
21
+ error: Error | undefined;
22
+ allError: Record<string, Error>;
15
23
  allValid: boolean;
16
24
  valid: boolean;
17
25
  dirty: boolean;
18
26
  };
19
- export type Field<Schema> = {
20
- name: FieldName<Schema>;
21
- formId: string;
22
- };
23
- export type FormMetadata<Schema extends Record<string, any>> = BaseMetadata<Schema> & {
27
+ export type FormMetadata<Schema extends Record<string, unknown> = Record<string, unknown>, Error = unknown> = Omit<Metadata<Schema, Error>, 'id'> & {
28
+ id: FormId<Schema, Error>;
29
+ context: Form<Schema, Error>;
30
+ getFieldset: () => {
31
+ [Key in UnionKeyof<Schema>]: FieldMetadata<UnionKeyType<Schema, Key>, Error, Schema>;
32
+ };
24
33
  onSubmit: (event: React.FormEvent<HTMLFormElement>) => ReturnType<Form<Schema>['submit']>;
25
34
  onReset: (event: React.FormEvent<HTMLFormElement>) => void;
26
35
  noValidate: boolean;
27
36
  };
28
- export type FieldMetadata<Schema> = BaseMetadata<Schema> & {
29
- formId: string;
37
+ export type FieldMetadata<Schema = unknown, Error = unknown, FormSchema extends Record<string, any> = Record<string, unknown>> = Metadata<Schema, Error> & {
38
+ formId: FormId<FormSchema, Error>;
30
39
  name: FieldName<Schema>;
31
40
  constraint?: Constraint;
41
+ getFieldset: unknown extends Schema ? () => unknown : Schema extends Primitive | Array<any> ? never : () => {
42
+ [Key in UnionKeyof<Schema>]: FieldMetadata<UnionKeyType<Schema, Key>, Error>;
43
+ };
44
+ getFieldList: unknown extends Schema ? () => unknown : Schema extends Array<infer Item> ? () => Array<FieldMetadata<Item, Error>> : never;
32
45
  };
33
46
  export declare const Registry: import("react").Context<Record<string, Form>>;
34
- export declare function useFormStore(formId: string, context?: Form): Form;
35
- export declare function useFormContext(form: Form, subjectRef?: MutableRefObject<SubscriptionSubject>): FormContext;
47
+ export declare function useRegistry<Schema extends Record<string, any>, Error, Value = Schema>(formId: FormId<Schema, Error>, context?: Form<Schema, Error, Value>): Form<Schema, Error, Value>;
48
+ export declare function useFormState<Error>(form: Form<any, Error>, subjectRef?: MutableRefObject<SubscriptionSubject>): FormState<Error>;
36
49
  export declare function FormProvider(props: {
37
- context: Form;
50
+ context: Form<any, any, any>;
38
51
  children: ReactNode;
39
52
  }): ReactElement;
40
53
  export declare function FormStateInput(props: {
@@ -45,12 +58,7 @@ export declare function FormStateInput(props: {
45
58
  context: Form;
46
59
  }): React.ReactElement;
47
60
  export declare function useSubjectRef(initialSubject?: SubscriptionSubject): MutableRefObject<SubscriptionSubject>;
48
- export declare function getBaseMetadata<Schema>(formId: string, context: FormContext, options: {
49
- name?: string;
50
- subjectRef: MutableRefObject<SubscriptionSubject>;
51
- }): BaseMetadata<Schema>;
52
- export declare function getFieldMetadata<Schema>(formId: string, context: FormContext, options: {
53
- name?: string;
54
- key?: string | number;
55
- subjectRef: MutableRefObject<SubscriptionSubject>;
56
- }): FieldMetadata<Schema>;
61
+ export declare function updateSubjectRef(ref: MutableRefObject<SubscriptionSubject>, name: string, subject: keyof SubscriptionSubject, scope: keyof SubscriptionScope): void;
62
+ export declare function getMetadata<Schema, Error, FormSchema extends Record<string, any>>(formId: FormId<FormSchema, Error>, state: FormState<Error>, subjectRef: MutableRefObject<SubscriptionSubject>, name?: FieldName<Schema>): Metadata<Schema, Error>;
63
+ export declare function getFieldMetadata<Schema, Error, FormSchema extends Record<string, any>>(formId: FormId<FormSchema, Error>, state: FormState<Error>, subjectRef: MutableRefObject<SubscriptionSubject>, prefix?: string, key?: string | number): FieldMetadata<Schema, Error, FormSchema>;
64
+ export declare function getFormMetadata<Schema extends Record<string, any>, Error>(formId: FormId<Schema, Error>, state: FormState<Error>, subjectRef: MutableRefObject<SubscriptionSubject>, form: Form<Schema, Error, any>, noValidate: boolean): FormMetadata<Schema, Error>;
package/context.js CHANGED
@@ -8,7 +8,7 @@ var react = require('react');
8
8
  var jsxRuntime = require('react/jsx-runtime');
9
9
 
10
10
  var Registry = /*#__PURE__*/react.createContext({});
11
- function useFormStore(formId, context) {
11
+ function useRegistry(formId, context) {
12
12
  var registry = react.useContext(Registry);
13
13
  var form = context !== null && context !== void 0 ? context : registry[formId];
14
14
  if (!form) {
@@ -16,10 +16,9 @@ function useFormStore(formId, context) {
16
16
  }
17
17
  return form;
18
18
  }
19
- function useFormContext(form, subjectRef) {
19
+ function useFormState(form, subjectRef) {
20
20
  var subscribe = react.useCallback(callback => form.subscribe(callback, () => subjectRef === null || subjectRef === void 0 ? void 0 : subjectRef.current), [form, subjectRef]);
21
- var result = react.useSyncExternalStore(subscribe, form.getContext, form.getContext);
22
- return result;
21
+ return react.useSyncExternalStore(subscribe, form.getState, form.getState);
23
22
  }
24
23
  function FormProvider(props) {
25
24
  var registry = react.useContext(Registry);
@@ -33,7 +32,7 @@ function FormProvider(props) {
33
32
  }
34
33
  function FormStateInput(props) {
35
34
  var _props$formId;
36
- var form = useFormStore((_props$formId = props.formId) !== null && _props$formId !== void 0 ? _props$formId : props.context.id, props.context);
35
+ var form = useRegistry((_props$formId = props.formId) !== null && _props$formId !== void 0 ? _props$formId : props.context.id, props.context);
37
36
  return /*#__PURE__*/jsxRuntime.jsx("input", {
38
37
  type: "hidden",
39
38
  name: dom.STATE,
@@ -50,85 +49,92 @@ function useSubjectRef() {
50
49
  subjectRef.current = initialSubject;
51
50
  return subjectRef;
52
51
  }
53
- function getBaseMetadata(formId, context, options) {
54
- var _options$name;
55
- var name = (_options$name = options.name) !== null && _options$name !== void 0 ? _options$name : '';
52
+ function updateSubjectRef(ref, name, subject, scope) {
53
+ var _ref$current$subject$, _ref$current$subject;
54
+ ref.current[subject] = _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, ref.current[subject]), {}, {
55
+ [scope]: ((_ref$current$subject$ = (_ref$current$subject = ref.current[subject]) === null || _ref$current$subject === void 0 ? void 0 : _ref$current$subject[scope]) !== null && _ref$current$subject$ !== void 0 ? _ref$current$subject$ : []).concat(name)
56
+ });
57
+ }
58
+ function getMetadata(formId, state, subjectRef) {
59
+ var name = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '';
56
60
  var id = name ? "".concat(formId, "-").concat(name) : formId;
57
- var updateSubject = (subject, scope) => {
58
- var _options$subjectRef$c, _options$subjectRef$c2;
59
- options.subjectRef.current[subject] = _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, options.subjectRef.current[subject]), {}, {
60
- [scope]: ((_options$subjectRef$c = (_options$subjectRef$c2 = options.subjectRef.current[subject]) === null || _options$subjectRef$c2 === void 0 ? void 0 : _options$subjectRef$c2[scope]) !== null && _options$subjectRef$c !== void 0 ? _options$subjectRef$c : []).concat(name)
61
- });
62
- };
63
61
  return new Proxy({
64
62
  id,
65
63
  errorId: "".concat(id, "-error"),
66
64
  descriptionId: "".concat(id, "-description"),
67
- initialValue: context.initialValue[name],
68
- value: context.value[name],
69
- errors: context.error[name],
65
+ initialValue: state.initialValue[name],
66
+ value: state.value[name],
67
+ error: state.error[name],
70
68
  get key() {
71
- return context.state.key[name];
69
+ return state.key[name];
72
70
  },
73
71
  get valid() {
74
- return context.state.valid[name];
72
+ return state.valid[name];
75
73
  },
76
74
  get dirty() {
77
- return context.state.dirty[name];
75
+ return state.dirty[name];
78
76
  },
79
77
  get allValid() {
80
- var keys = Object.keys(context.error);
78
+ var keys = Object.keys(state.error);
81
79
  if (name === '') {
82
80
  return keys.length === 0;
83
81
  }
84
- for (var key of Object.keys(context.error)) {
85
- if (dom.isPrefix(key, name) && !context.state.valid[key]) {
82
+ for (var key of Object.keys(state.error)) {
83
+ if (dom.isPrefix(key, name) && !state.valid[key]) {
86
84
  return false;
87
85
  }
88
86
  }
89
87
  return true;
90
88
  },
91
- get allErrors() {
89
+ get allError() {
92
90
  if (name === '') {
93
- return context.error;
91
+ return state.error;
94
92
  }
95
93
  var result = {};
96
- for (var [key, errors] of Object.entries(context.error)) {
94
+ for (var [key, error] of Object.entries(state.error)) {
97
95
  if (dom.isPrefix(key, name)) {
98
- result[key] = errors;
96
+ result[key] = error;
99
97
  }
100
98
  }
101
99
  return result;
100
+ },
101
+ get getFieldset() {
102
+ return () => new Proxy({}, {
103
+ get(target, key, receiver) {
104
+ if (typeof key === 'string') {
105
+ return getFieldMetadata(formId, state, subjectRef, name, key);
106
+ }
107
+ return Reflect.get(target, key, receiver);
108
+ }
109
+ });
102
110
  }
103
111
  }, {
104
112
  get(target, key, receiver) {
105
113
  switch (key) {
106
114
  case 'key':
107
- case 'errors':
115
+ case 'error':
108
116
  case 'initialValue':
109
117
  case 'value':
110
118
  case 'valid':
111
119
  case 'dirty':
112
- updateSubject(key === 'errors' ? 'error' : key, 'name');
120
+ updateSubjectRef(subjectRef, name, key, 'name');
113
121
  break;
114
- case 'allErrors':
115
- updateSubject('error', 'prefix');
122
+ case 'allError':
123
+ updateSubjectRef(subjectRef, name, 'error', 'prefix');
116
124
  break;
117
125
  case 'allValid':
118
- updateSubject('valid', 'prefix');
126
+ updateSubjectRef(subjectRef, name, 'valid', 'prefix');
119
127
  break;
120
128
  }
121
129
  return Reflect.get(target, key, receiver);
122
130
  }
123
131
  });
124
132
  }
125
- function getFieldMetadata(formId, context, options) {
126
- var _options$name2, _options$name3;
127
- var name = typeof options.key !== 'undefined' ? dom.formatPaths([...dom.getPaths((_options$name2 = options.name) !== null && _options$name2 !== void 0 ? _options$name2 : ''), options.key]) : (_options$name3 = options.name) !== null && _options$name3 !== void 0 ? _options$name3 : '';
128
- var metadata = getBaseMetadata(formId, context, {
129
- subjectRef: options.subjectRef,
130
- name
131
- });
133
+ function getFieldMetadata(formId, state, subjectRef) {
134
+ var prefix = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '';
135
+ var key = arguments.length > 4 ? arguments[4] : undefined;
136
+ var name = typeof key === 'undefined' ? prefix : dom.formatPaths([...dom.getPaths(prefix), key]);
137
+ var metadata = getMetadata(formId, state, subjectRef, name);
132
138
  return new Proxy(metadata, {
133
139
  get(target, key, receiver) {
134
140
  switch (key) {
@@ -137,7 +143,41 @@ function getFieldMetadata(formId, context, options) {
137
143
  case 'name':
138
144
  return name;
139
145
  case 'constraint':
140
- return context.constraint[name];
146
+ return state.constraint[name];
147
+ case 'getFieldList':
148
+ {
149
+ return () => {
150
+ var _state$initialValue$n;
151
+ var initialValue = (_state$initialValue$n = state.initialValue[name]) !== null && _state$initialValue$n !== void 0 ? _state$initialValue$n : [];
152
+ updateSubjectRef(subjectRef, name, 'initialValue', 'name');
153
+ if (!Array.isArray(initialValue)) {
154
+ throw new Error('The initial value at the given name is not a list');
155
+ }
156
+ return Array(initialValue.length).fill(0).map((_, index) => getFieldMetadata(formId, state, subjectRef, name, index));
157
+ };
158
+ }
159
+ }
160
+ return Reflect.get(target, key, receiver);
161
+ }
162
+ });
163
+ }
164
+ function getFormMetadata(formId, state, subjectRef, form, noValidate) {
165
+ var metadata = getMetadata(formId, state, subjectRef);
166
+ return new Proxy(metadata, {
167
+ get(target, key, receiver) {
168
+ switch (key) {
169
+ case 'context':
170
+ return form;
171
+ case 'onSubmit':
172
+ return event => {
173
+ var submitEvent = event.nativeEvent;
174
+ form.submit(submitEvent);
175
+ if (submitEvent.defaultPrevented) {
176
+ event.preventDefault();
177
+ }
178
+ };
179
+ case 'noValidate':
180
+ return noValidate;
141
181
  }
142
182
  return Reflect.get(target, key, receiver);
143
183
  }
@@ -147,8 +187,10 @@ function getFieldMetadata(formId, context, options) {
147
187
  exports.FormProvider = FormProvider;
148
188
  exports.FormStateInput = FormStateInput;
149
189
  exports.Registry = Registry;
150
- exports.getBaseMetadata = getBaseMetadata;
151
190
  exports.getFieldMetadata = getFieldMetadata;
152
- exports.useFormContext = useFormContext;
153
- exports.useFormStore = useFormStore;
191
+ exports.getFormMetadata = getFormMetadata;
192
+ exports.getMetadata = getMetadata;
193
+ exports.updateSubjectRef = updateSubjectRef;
194
+ exports.useFormState = useFormState;
195
+ exports.useRegistry = useRegistry;
154
196
  exports.useSubjectRef = useSubjectRef;
package/context.mjs CHANGED
@@ -1,10 +1,10 @@
1
1
  import { objectSpread2 as _objectSpread2 } from './_virtual/_rollupPluginBabelHelpers.mjs';
2
- import { STATE, isPrefix, formatPaths, getPaths } from '@conform-to/dom';
2
+ import { STATE, formatPaths, getPaths, isPrefix } from '@conform-to/dom';
3
3
  import { useContext, useMemo, createContext, useCallback, useSyncExternalStore, useRef } from 'react';
4
4
  import { jsx } from 'react/jsx-runtime';
5
5
 
6
6
  var Registry = /*#__PURE__*/createContext({});
7
- function useFormStore(formId, context) {
7
+ function useRegistry(formId, context) {
8
8
  var registry = useContext(Registry);
9
9
  var form = context !== null && context !== void 0 ? context : registry[formId];
10
10
  if (!form) {
@@ -12,10 +12,9 @@ function useFormStore(formId, context) {
12
12
  }
13
13
  return form;
14
14
  }
15
- function useFormContext(form, subjectRef) {
15
+ function useFormState(form, subjectRef) {
16
16
  var subscribe = useCallback(callback => form.subscribe(callback, () => subjectRef === null || subjectRef === void 0 ? void 0 : subjectRef.current), [form, subjectRef]);
17
- var result = useSyncExternalStore(subscribe, form.getContext, form.getContext);
18
- return result;
17
+ return useSyncExternalStore(subscribe, form.getState, form.getState);
19
18
  }
20
19
  function FormProvider(props) {
21
20
  var registry = useContext(Registry);
@@ -29,7 +28,7 @@ function FormProvider(props) {
29
28
  }
30
29
  function FormStateInput(props) {
31
30
  var _props$formId;
32
- var form = useFormStore((_props$formId = props.formId) !== null && _props$formId !== void 0 ? _props$formId : props.context.id, props.context);
31
+ var form = useRegistry((_props$formId = props.formId) !== null && _props$formId !== void 0 ? _props$formId : props.context.id, props.context);
33
32
  return /*#__PURE__*/jsx("input", {
34
33
  type: "hidden",
35
34
  name: STATE,
@@ -46,85 +45,92 @@ function useSubjectRef() {
46
45
  subjectRef.current = initialSubject;
47
46
  return subjectRef;
48
47
  }
49
- function getBaseMetadata(formId, context, options) {
50
- var _options$name;
51
- var name = (_options$name = options.name) !== null && _options$name !== void 0 ? _options$name : '';
48
+ function updateSubjectRef(ref, name, subject, scope) {
49
+ var _ref$current$subject$, _ref$current$subject;
50
+ ref.current[subject] = _objectSpread2(_objectSpread2({}, ref.current[subject]), {}, {
51
+ [scope]: ((_ref$current$subject$ = (_ref$current$subject = ref.current[subject]) === null || _ref$current$subject === void 0 ? void 0 : _ref$current$subject[scope]) !== null && _ref$current$subject$ !== void 0 ? _ref$current$subject$ : []).concat(name)
52
+ });
53
+ }
54
+ function getMetadata(formId, state, subjectRef) {
55
+ var name = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '';
52
56
  var id = name ? "".concat(formId, "-").concat(name) : formId;
53
- var updateSubject = (subject, scope) => {
54
- var _options$subjectRef$c, _options$subjectRef$c2;
55
- options.subjectRef.current[subject] = _objectSpread2(_objectSpread2({}, options.subjectRef.current[subject]), {}, {
56
- [scope]: ((_options$subjectRef$c = (_options$subjectRef$c2 = options.subjectRef.current[subject]) === null || _options$subjectRef$c2 === void 0 ? void 0 : _options$subjectRef$c2[scope]) !== null && _options$subjectRef$c !== void 0 ? _options$subjectRef$c : []).concat(name)
57
- });
58
- };
59
57
  return new Proxy({
60
58
  id,
61
59
  errorId: "".concat(id, "-error"),
62
60
  descriptionId: "".concat(id, "-description"),
63
- initialValue: context.initialValue[name],
64
- value: context.value[name],
65
- errors: context.error[name],
61
+ initialValue: state.initialValue[name],
62
+ value: state.value[name],
63
+ error: state.error[name],
66
64
  get key() {
67
- return context.state.key[name];
65
+ return state.key[name];
68
66
  },
69
67
  get valid() {
70
- return context.state.valid[name];
68
+ return state.valid[name];
71
69
  },
72
70
  get dirty() {
73
- return context.state.dirty[name];
71
+ return state.dirty[name];
74
72
  },
75
73
  get allValid() {
76
- var keys = Object.keys(context.error);
74
+ var keys = Object.keys(state.error);
77
75
  if (name === '') {
78
76
  return keys.length === 0;
79
77
  }
80
- for (var key of Object.keys(context.error)) {
81
- if (isPrefix(key, name) && !context.state.valid[key]) {
78
+ for (var key of Object.keys(state.error)) {
79
+ if (isPrefix(key, name) && !state.valid[key]) {
82
80
  return false;
83
81
  }
84
82
  }
85
83
  return true;
86
84
  },
87
- get allErrors() {
85
+ get allError() {
88
86
  if (name === '') {
89
- return context.error;
87
+ return state.error;
90
88
  }
91
89
  var result = {};
92
- for (var [key, errors] of Object.entries(context.error)) {
90
+ for (var [key, error] of Object.entries(state.error)) {
93
91
  if (isPrefix(key, name)) {
94
- result[key] = errors;
92
+ result[key] = error;
95
93
  }
96
94
  }
97
95
  return result;
96
+ },
97
+ get getFieldset() {
98
+ return () => new Proxy({}, {
99
+ get(target, key, receiver) {
100
+ if (typeof key === 'string') {
101
+ return getFieldMetadata(formId, state, subjectRef, name, key);
102
+ }
103
+ return Reflect.get(target, key, receiver);
104
+ }
105
+ });
98
106
  }
99
107
  }, {
100
108
  get(target, key, receiver) {
101
109
  switch (key) {
102
110
  case 'key':
103
- case 'errors':
111
+ case 'error':
104
112
  case 'initialValue':
105
113
  case 'value':
106
114
  case 'valid':
107
115
  case 'dirty':
108
- updateSubject(key === 'errors' ? 'error' : key, 'name');
116
+ updateSubjectRef(subjectRef, name, key, 'name');
109
117
  break;
110
- case 'allErrors':
111
- updateSubject('error', 'prefix');
118
+ case 'allError':
119
+ updateSubjectRef(subjectRef, name, 'error', 'prefix');
112
120
  break;
113
121
  case 'allValid':
114
- updateSubject('valid', 'prefix');
122
+ updateSubjectRef(subjectRef, name, 'valid', 'prefix');
115
123
  break;
116
124
  }
117
125
  return Reflect.get(target, key, receiver);
118
126
  }
119
127
  });
120
128
  }
121
- function getFieldMetadata(formId, context, options) {
122
- var _options$name2, _options$name3;
123
- var name = typeof options.key !== 'undefined' ? formatPaths([...getPaths((_options$name2 = options.name) !== null && _options$name2 !== void 0 ? _options$name2 : ''), options.key]) : (_options$name3 = options.name) !== null && _options$name3 !== void 0 ? _options$name3 : '';
124
- var metadata = getBaseMetadata(formId, context, {
125
- subjectRef: options.subjectRef,
126
- name
127
- });
129
+ function getFieldMetadata(formId, state, subjectRef) {
130
+ var prefix = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '';
131
+ var key = arguments.length > 4 ? arguments[4] : undefined;
132
+ var name = typeof key === 'undefined' ? prefix : formatPaths([...getPaths(prefix), key]);
133
+ var metadata = getMetadata(formId, state, subjectRef, name);
128
134
  return new Proxy(metadata, {
129
135
  get(target, key, receiver) {
130
136
  switch (key) {
@@ -133,11 +139,45 @@ function getFieldMetadata(formId, context, options) {
133
139
  case 'name':
134
140
  return name;
135
141
  case 'constraint':
136
- return context.constraint[name];
142
+ return state.constraint[name];
143
+ case 'getFieldList':
144
+ {
145
+ return () => {
146
+ var _state$initialValue$n;
147
+ var initialValue = (_state$initialValue$n = state.initialValue[name]) !== null && _state$initialValue$n !== void 0 ? _state$initialValue$n : [];
148
+ updateSubjectRef(subjectRef, name, 'initialValue', 'name');
149
+ if (!Array.isArray(initialValue)) {
150
+ throw new Error('The initial value at the given name is not a list');
151
+ }
152
+ return Array(initialValue.length).fill(0).map((_, index) => getFieldMetadata(formId, state, subjectRef, name, index));
153
+ };
154
+ }
155
+ }
156
+ return Reflect.get(target, key, receiver);
157
+ }
158
+ });
159
+ }
160
+ function getFormMetadata(formId, state, subjectRef, form, noValidate) {
161
+ var metadata = getMetadata(formId, state, subjectRef);
162
+ return new Proxy(metadata, {
163
+ get(target, key, receiver) {
164
+ switch (key) {
165
+ case 'context':
166
+ return form;
167
+ case 'onSubmit':
168
+ return event => {
169
+ var submitEvent = event.nativeEvent;
170
+ form.submit(submitEvent);
171
+ if (submitEvent.defaultPrevented) {
172
+ event.preventDefault();
173
+ }
174
+ };
175
+ case 'noValidate':
176
+ return noValidate;
137
177
  }
138
178
  return Reflect.get(target, key, receiver);
139
179
  }
140
180
  });
141
181
  }
142
182
 
143
- export { FormProvider, FormStateInput, Registry, getBaseMetadata, getFieldMetadata, useFormContext, useFormStore, useSubjectRef };
183
+ export { FormProvider, FormStateInput, Registry, getFieldMetadata, getFormMetadata, getMetadata, updateSubjectRef, useFormState, useRegistry, useSubjectRef };