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

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,54 @@
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
+ status?: 'success' | 'error';
31
+ getFieldset: () => {
32
+ [Key in UnionKeyof<Schema>]: FieldMetadata<UnionKeyType<Schema, Key>, Error, Schema>;
33
+ };
24
34
  onSubmit: (event: React.FormEvent<HTMLFormElement>) => ReturnType<Form<Schema>['submit']>;
25
35
  onReset: (event: React.FormEvent<HTMLFormElement>) => void;
26
36
  noValidate: boolean;
27
37
  };
28
- export type FieldMetadata<Schema> = BaseMetadata<Schema> & {
29
- formId: string;
38
+ export type FieldMetadata<Schema = unknown, Error = unknown, FormSchema extends Record<string, any> = Record<string, unknown>> = Metadata<Schema, Error> & {
39
+ formId: FormId<FormSchema, Error>;
30
40
  name: FieldName<Schema>;
31
41
  constraint?: Constraint;
42
+ getFieldset: unknown extends Schema ? () => unknown : Schema extends Primitive | Array<any> ? never : () => {
43
+ [Key in UnionKeyof<Schema>]: FieldMetadata<UnionKeyType<Schema, Key>, Error>;
44
+ };
45
+ getFieldList: unknown extends Schema ? () => unknown : Schema extends Array<infer Item> ? () => Array<FieldMetadata<Item, Error>> : never;
32
46
  };
33
47
  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;
48
+ 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>;
49
+ export declare function useFormState<Error>(form: Form<any, Error>, subjectRef?: MutableRefObject<SubscriptionSubject>): FormState<Error>;
36
50
  export declare function FormProvider(props: {
37
- context: Form;
51
+ context: Form<any, any, any>;
38
52
  children: ReactNode;
39
53
  }): ReactElement;
40
54
  export declare function FormStateInput(props: {
@@ -45,12 +59,7 @@ export declare function FormStateInput(props: {
45
59
  context: Form;
46
60
  }): React.ReactElement;
47
61
  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>;
62
+ export declare function updateSubjectRef(ref: MutableRefObject<SubscriptionSubject>, name: string, subject: keyof SubscriptionSubject, scope: keyof SubscriptionScope): void;
63
+ 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>;
64
+ 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>;
65
+ 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,96 @@ 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 : '';
56
- 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)
52
+ function updateSubjectRef(ref, name, subject, scope) {
53
+ if (subject === 'status') {
54
+ ref.current[subject] = true;
55
+ } else {
56
+ var _ref$current$subject$, _ref$current$subject;
57
+ ref.current[subject] = _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, ref.current[subject]), {}, {
58
+ [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)
61
59
  });
62
- };
60
+ }
61
+ }
62
+ function getMetadata(formId, state, subjectRef) {
63
+ var name = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '';
64
+ var id = name ? "".concat(formId, "-").concat(name) : formId;
63
65
  return new Proxy({
64
66
  id,
65
67
  errorId: "".concat(id, "-error"),
66
68
  descriptionId: "".concat(id, "-description"),
67
- initialValue: context.initialValue[name],
68
- value: context.value[name],
69
- errors: context.error[name],
69
+ initialValue: state.initialValue[name],
70
+ value: state.value[name],
71
+ error: state.error[name],
70
72
  get key() {
71
- return context.state.key[name];
73
+ return state.key[name];
72
74
  },
73
75
  get valid() {
74
- return context.state.valid[name];
76
+ return state.valid[name];
75
77
  },
76
78
  get dirty() {
77
- return context.state.dirty[name];
79
+ return state.dirty[name];
78
80
  },
79
81
  get allValid() {
80
- var keys = Object.keys(context.error);
82
+ var keys = Object.keys(state.error);
81
83
  if (name === '') {
82
84
  return keys.length === 0;
83
85
  }
84
- for (var key of Object.keys(context.error)) {
85
- if (dom.isPrefix(key, name) && !context.state.valid[key]) {
86
+ for (var key of Object.keys(state.error)) {
87
+ if (dom.isPrefix(key, name) && !state.valid[key]) {
86
88
  return false;
87
89
  }
88
90
  }
89
91
  return true;
90
92
  },
91
- get allErrors() {
93
+ get allError() {
92
94
  if (name === '') {
93
- return context.error;
95
+ return state.error;
94
96
  }
95
97
  var result = {};
96
- for (var [key, errors] of Object.entries(context.error)) {
98
+ for (var [key, error] of Object.entries(state.error)) {
97
99
  if (dom.isPrefix(key, name)) {
98
- result[key] = errors;
100
+ result[key] = error;
99
101
  }
100
102
  }
101
103
  return result;
104
+ },
105
+ get getFieldset() {
106
+ return () => new Proxy({}, {
107
+ get(target, key, receiver) {
108
+ if (typeof key === 'string') {
109
+ return getFieldMetadata(formId, state, subjectRef, name, key);
110
+ }
111
+ return Reflect.get(target, key, receiver);
112
+ }
113
+ });
102
114
  }
103
115
  }, {
104
116
  get(target, key, receiver) {
105
117
  switch (key) {
106
118
  case 'key':
107
- case 'errors':
119
+ case 'error':
108
120
  case 'initialValue':
109
121
  case 'value':
110
122
  case 'valid':
111
123
  case 'dirty':
112
- updateSubject(key === 'errors' ? 'error' : key, 'name');
124
+ updateSubjectRef(subjectRef, name, key, 'name');
113
125
  break;
114
- case 'allErrors':
115
- updateSubject('error', 'prefix');
126
+ case 'allError':
127
+ updateSubjectRef(subjectRef, name, 'error', 'prefix');
116
128
  break;
117
129
  case 'allValid':
118
- updateSubject('valid', 'prefix');
130
+ updateSubjectRef(subjectRef, name, 'valid', 'prefix');
119
131
  break;
120
132
  }
121
133
  return Reflect.get(target, key, receiver);
122
134
  }
123
135
  });
124
136
  }
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
- });
137
+ function getFieldMetadata(formId, state, subjectRef) {
138
+ var prefix = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '';
139
+ var key = arguments.length > 4 ? arguments[4] : undefined;
140
+ var name = typeof key === 'undefined' ? prefix : dom.formatPaths([...dom.getPaths(prefix), key]);
141
+ var metadata = getMetadata(formId, state, subjectRef, name);
132
142
  return new Proxy(metadata, {
133
143
  get(target, key, receiver) {
134
144
  switch (key) {
@@ -137,7 +147,43 @@ function getFieldMetadata(formId, context, options) {
137
147
  case 'name':
138
148
  return name;
139
149
  case 'constraint':
140
- return context.constraint[name];
150
+ return state.constraint[name];
151
+ case 'getFieldList':
152
+ {
153
+ return () => {
154
+ var _state$initialValue$n;
155
+ var initialValue = (_state$initialValue$n = state.initialValue[name]) !== null && _state$initialValue$n !== void 0 ? _state$initialValue$n : [];
156
+ updateSubjectRef(subjectRef, name, 'initialValue', 'name');
157
+ if (!Array.isArray(initialValue)) {
158
+ throw new Error('The initial value at the given name is not a list');
159
+ }
160
+ return Array(initialValue.length).fill(0).map((_, index) => getFieldMetadata(formId, state, subjectRef, name, index));
161
+ };
162
+ }
163
+ }
164
+ return Reflect.get(target, key, receiver);
165
+ }
166
+ });
167
+ }
168
+ function getFormMetadata(formId, state, subjectRef, form, noValidate) {
169
+ var metadata = getMetadata(formId, state, subjectRef);
170
+ return new Proxy(metadata, {
171
+ get(target, key, receiver) {
172
+ switch (key) {
173
+ case 'context':
174
+ return form;
175
+ case 'status':
176
+ return state.submissionStatus;
177
+ case 'onSubmit':
178
+ return event => {
179
+ var submitEvent = event.nativeEvent;
180
+ form.submit(submitEvent);
181
+ if (submitEvent.defaultPrevented) {
182
+ event.preventDefault();
183
+ }
184
+ };
185
+ case 'noValidate':
186
+ return noValidate;
141
187
  }
142
188
  return Reflect.get(target, key, receiver);
143
189
  }
@@ -147,8 +193,10 @@ function getFieldMetadata(formId, context, options) {
147
193
  exports.FormProvider = FormProvider;
148
194
  exports.FormStateInput = FormStateInput;
149
195
  exports.Registry = Registry;
150
- exports.getBaseMetadata = getBaseMetadata;
151
196
  exports.getFieldMetadata = getFieldMetadata;
152
- exports.useFormContext = useFormContext;
153
- exports.useFormStore = useFormStore;
197
+ exports.getFormMetadata = getFormMetadata;
198
+ exports.getMetadata = getMetadata;
199
+ exports.updateSubjectRef = updateSubjectRef;
200
+ exports.useFormState = useFormState;
201
+ exports.useRegistry = useRegistry;
154
202
  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,96 @@ 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 : '';
52
- 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)
48
+ function updateSubjectRef(ref, name, subject, scope) {
49
+ if (subject === 'status') {
50
+ ref.current[subject] = true;
51
+ } else {
52
+ var _ref$current$subject$, _ref$current$subject;
53
+ ref.current[subject] = _objectSpread2(_objectSpread2({}, ref.current[subject]), {}, {
54
+ [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)
57
55
  });
58
- };
56
+ }
57
+ }
58
+ function getMetadata(formId, state, subjectRef) {
59
+ var name = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '';
60
+ var id = name ? "".concat(formId, "-").concat(name) : formId;
59
61
  return new Proxy({
60
62
  id,
61
63
  errorId: "".concat(id, "-error"),
62
64
  descriptionId: "".concat(id, "-description"),
63
- initialValue: context.initialValue[name],
64
- value: context.value[name],
65
- errors: context.error[name],
65
+ initialValue: state.initialValue[name],
66
+ value: state.value[name],
67
+ error: state.error[name],
66
68
  get key() {
67
- return context.state.key[name];
69
+ return state.key[name];
68
70
  },
69
71
  get valid() {
70
- return context.state.valid[name];
72
+ return state.valid[name];
71
73
  },
72
74
  get dirty() {
73
- return context.state.dirty[name];
75
+ return state.dirty[name];
74
76
  },
75
77
  get allValid() {
76
- var keys = Object.keys(context.error);
78
+ var keys = Object.keys(state.error);
77
79
  if (name === '') {
78
80
  return keys.length === 0;
79
81
  }
80
- for (var key of Object.keys(context.error)) {
81
- if (isPrefix(key, name) && !context.state.valid[key]) {
82
+ for (var key of Object.keys(state.error)) {
83
+ if (isPrefix(key, name) && !state.valid[key]) {
82
84
  return false;
83
85
  }
84
86
  }
85
87
  return true;
86
88
  },
87
- get allErrors() {
89
+ get allError() {
88
90
  if (name === '') {
89
- return context.error;
91
+ return state.error;
90
92
  }
91
93
  var result = {};
92
- for (var [key, errors] of Object.entries(context.error)) {
94
+ for (var [key, error] of Object.entries(state.error)) {
93
95
  if (isPrefix(key, name)) {
94
- result[key] = errors;
96
+ result[key] = error;
95
97
  }
96
98
  }
97
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
+ });
98
110
  }
99
111
  }, {
100
112
  get(target, key, receiver) {
101
113
  switch (key) {
102
114
  case 'key':
103
- case 'errors':
115
+ case 'error':
104
116
  case 'initialValue':
105
117
  case 'value':
106
118
  case 'valid':
107
119
  case 'dirty':
108
- updateSubject(key === 'errors' ? 'error' : key, 'name');
120
+ updateSubjectRef(subjectRef, name, key, 'name');
109
121
  break;
110
- case 'allErrors':
111
- updateSubject('error', 'prefix');
122
+ case 'allError':
123
+ updateSubjectRef(subjectRef, name, 'error', 'prefix');
112
124
  break;
113
125
  case 'allValid':
114
- updateSubject('valid', 'prefix');
126
+ updateSubjectRef(subjectRef, name, 'valid', 'prefix');
115
127
  break;
116
128
  }
117
129
  return Reflect.get(target, key, receiver);
118
130
  }
119
131
  });
120
132
  }
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
- });
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 : formatPaths([...getPaths(prefix), key]);
137
+ var metadata = getMetadata(formId, state, subjectRef, name);
128
138
  return new Proxy(metadata, {
129
139
  get(target, key, receiver) {
130
140
  switch (key) {
@@ -133,11 +143,47 @@ function getFieldMetadata(formId, context, options) {
133
143
  case 'name':
134
144
  return name;
135
145
  case 'constraint':
136
- 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 'status':
172
+ return state.submissionStatus;
173
+ case 'onSubmit':
174
+ return event => {
175
+ var submitEvent = event.nativeEvent;
176
+ form.submit(submitEvent);
177
+ if (submitEvent.defaultPrevented) {
178
+ event.preventDefault();
179
+ }
180
+ };
181
+ case 'noValidate':
182
+ return noValidate;
137
183
  }
138
184
  return Reflect.get(target, key, receiver);
139
185
  }
140
186
  });
141
187
  }
142
188
 
143
- export { FormProvider, FormStateInput, Registry, getBaseMetadata, getFieldMetadata, useFormContext, useFormStore, useSubjectRef };
189
+ export { FormProvider, FormStateInput, Registry, getFieldMetadata, getFormMetadata, getMetadata, updateSubjectRef, useFormState, useRegistry, useSubjectRef };