@conform-to/react 1.15.0 → 1.16.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 +1 -1
- package/dist/future/dom.js +11 -2
- package/dist/future/dom.mjs +12 -3
- package/dist/future/forms.d.ts +43 -0
- package/dist/future/forms.js +322 -0
- package/dist/future/forms.mjs +318 -0
- package/dist/future/hooks.d.ts +25 -4
- package/dist/future/hooks.js +21 -8
- package/dist/future/hooks.mjs +21 -8
- package/dist/future/index.d.ts +3 -1
- package/dist/future/index.js +4 -0
- package/dist/future/index.mjs +2 -0
- package/dist/future/state.d.ts +28 -13
- package/dist/future/state.js +37 -33
- package/dist/future/state.mjs +39 -35
- package/dist/future/types.d.ts +275 -28
- package/dist/future/util.d.ts +44 -1
- package/dist/future/util.js +67 -5
- package/dist/future/util.mjs +64 -6
- package/dist/integrations.d.ts +3 -3
- package/package.json +2 -2
package/dist/future/state.js
CHANGED
|
@@ -241,7 +241,8 @@ function getConstraint(context, name) {
|
|
|
241
241
|
return constraint;
|
|
242
242
|
}
|
|
243
243
|
function getFormMetadata(context, options) {
|
|
244
|
-
|
|
244
|
+
var _options$extendFormMe, _options$extendFormMe2;
|
|
245
|
+
var metadata = {
|
|
245
246
|
key: context.state.resetKey,
|
|
246
247
|
id: context.formId,
|
|
247
248
|
errorId: "".concat(context.formId, "-form-error"),
|
|
@@ -274,31 +275,41 @@ function getFormMetadata(context, options) {
|
|
|
274
275
|
return getField(context, {
|
|
275
276
|
name,
|
|
276
277
|
serialize: options === null || options === void 0 ? void 0 : options.serialize,
|
|
277
|
-
|
|
278
|
+
extendFieldMetadata: options === null || options === void 0 ? void 0 : options.extendFieldMetadata
|
|
278
279
|
});
|
|
279
280
|
},
|
|
280
281
|
getFieldset(name) {
|
|
281
282
|
return getFieldset(context, {
|
|
282
283
|
name,
|
|
283
284
|
serialize: options === null || options === void 0 ? void 0 : options.serialize,
|
|
284
|
-
|
|
285
|
+
extendFieldMetadata: options === null || options === void 0 ? void 0 : options.extendFieldMetadata
|
|
285
286
|
});
|
|
286
287
|
},
|
|
287
288
|
getFieldList(name) {
|
|
288
289
|
return getFieldList(context, {
|
|
289
290
|
name,
|
|
290
291
|
serialize: options === null || options === void 0 ? void 0 : options.serialize,
|
|
291
|
-
|
|
292
|
+
extendFieldMetadata: options === null || options === void 0 ? void 0 : options.extendFieldMetadata
|
|
292
293
|
});
|
|
293
294
|
}
|
|
294
295
|
};
|
|
296
|
+
var customMetadata = (_options$extendFormMe = options === null || options === void 0 || (_options$extendFormMe2 = options.extendFormMetadata) === null || _options$extendFormMe2 === void 0 ? void 0 : _options$extendFormMe2.call(options, metadata)) !== null && _options$extendFormMe !== void 0 ? _options$extendFormMe : {};
|
|
297
|
+
var descriptors = Object.getOwnPropertyDescriptors(customMetadata);
|
|
298
|
+
var extended = Object.create(metadata);
|
|
299
|
+
Object.defineProperties(extended, descriptors);
|
|
300
|
+
return extended;
|
|
295
301
|
}
|
|
296
302
|
function getField(context, options) {
|
|
303
|
+
var _extendFieldMetadata;
|
|
297
304
|
var {
|
|
298
305
|
key,
|
|
299
306
|
name,
|
|
300
307
|
serialize = future.serialize,
|
|
301
|
-
|
|
308
|
+
extendFieldMetadata,
|
|
309
|
+
form = getFormMetadata(context, {
|
|
310
|
+
serialize,
|
|
311
|
+
extendFieldMetadata
|
|
312
|
+
})
|
|
302
313
|
} = options;
|
|
303
314
|
var id = "".concat(context.formId, "-field-").concat(name.replace(/[^a-zA-Z0-9._-]/g, '_'));
|
|
304
315
|
var constraint = getConstraint(context, name);
|
|
@@ -351,40 +362,27 @@ function getField(context, options) {
|
|
|
351
362
|
return getFieldset(context, {
|
|
352
363
|
name: name,
|
|
353
364
|
serialize,
|
|
354
|
-
|
|
365
|
+
extendFieldMetadata
|
|
355
366
|
});
|
|
356
367
|
},
|
|
368
|
+
// @ts-expect-error The return type includes CustomFieldMetadata which BaseFieldMetadata
|
|
369
|
+
// doesn't account for. This is a type-level limitation; runtime behavior is correct.
|
|
357
370
|
getFieldList() {
|
|
358
371
|
return getFieldList(context, {
|
|
359
|
-
name
|
|
372
|
+
name,
|
|
360
373
|
serialize,
|
|
361
|
-
|
|
374
|
+
extendFieldMetadata
|
|
362
375
|
});
|
|
363
376
|
}
|
|
364
377
|
};
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
return Reflect.get(target, prop, receiver);
|
|
374
|
-
}
|
|
375
|
-
(_customMetadata = customMetadata) !== null && _customMetadata !== void 0 ? _customMetadata : customMetadata = customize(metadata);
|
|
376
|
-
if (Reflect.has(customMetadata, prop)) {
|
|
377
|
-
return Reflect.get(customMetadata, prop, receiver);
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
// Allow React DevTools to inspect the object
|
|
381
|
-
// without throwing errors for internal properties
|
|
382
|
-
if (typeof prop === 'symbol' || prop === '$$typeof') {
|
|
383
|
-
return undefined;
|
|
384
|
-
}
|
|
385
|
-
throw new Error("Property \"".concat(String(prop), "\" does not exist on field metadata. ") + "If you have defined the CustomMetadata interface to include \"".concat(String(prop), "\", make sure to also implement it through the \"defineCustomMetadata\" property on <FormOptionsProvider />."));
|
|
386
|
-
}
|
|
387
|
-
});
|
|
378
|
+
var customMetadata = (_extendFieldMetadata = extendFieldMetadata === null || extendFieldMetadata === void 0 ? void 0 : extendFieldMetadata(metadata, {
|
|
379
|
+
form,
|
|
380
|
+
when: util.when
|
|
381
|
+
})) !== null && _extendFieldMetadata !== void 0 ? _extendFieldMetadata : {};
|
|
382
|
+
var descriptors = Object.getOwnPropertyDescriptors(customMetadata);
|
|
383
|
+
var extended = Object.create(metadata);
|
|
384
|
+
Object.defineProperties(extended, descriptors);
|
|
385
|
+
return extended;
|
|
388
386
|
}
|
|
389
387
|
|
|
390
388
|
/**
|
|
@@ -394,10 +392,16 @@ function getFieldset(context, options) {
|
|
|
394
392
|
return new Proxy({}, {
|
|
395
393
|
get(target, name, receiver) {
|
|
396
394
|
if (typeof name === 'string') {
|
|
395
|
+
var _options$form;
|
|
396
|
+
(_options$form = options.form) !== null && _options$form !== void 0 ? _options$form : options.form = getFormMetadata(context, {
|
|
397
|
+
serialize: options === null || options === void 0 ? void 0 : options.serialize,
|
|
398
|
+
extendFieldMetadata: options === null || options === void 0 ? void 0 : options.extendFieldMetadata
|
|
399
|
+
});
|
|
397
400
|
return getField(context, {
|
|
398
401
|
name: future.appendPathSegment(options === null || options === void 0 ? void 0 : options.name, name),
|
|
399
402
|
serialize: options.serialize,
|
|
400
|
-
|
|
403
|
+
extendFieldMetadata: options.extendFieldMetadata,
|
|
404
|
+
form: options.form
|
|
401
405
|
});
|
|
402
406
|
}
|
|
403
407
|
return Reflect.get(target, name, receiver);
|
|
@@ -414,7 +418,7 @@ function getFieldList(context, options) {
|
|
|
414
418
|
return getField(context, {
|
|
415
419
|
name: future.appendPathSegment(options.name, index),
|
|
416
420
|
serialize: options.serialize,
|
|
417
|
-
|
|
421
|
+
extendFieldMetadata: options.extendFieldMetadata,
|
|
418
422
|
key
|
|
419
423
|
});
|
|
420
424
|
});
|
package/dist/future/state.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { objectSpread2 as _objectSpread2 } from '../_virtual/_rollupPluginBabelHelpers.mjs';
|
|
2
|
-
import { getPathSegments, getRelativePath, appendPathSegment, deepEqual, getValueAtPath, formatPathSegments
|
|
3
|
-
import { generateUniqueKey, merge, getArrayAtPath } from './util.mjs';
|
|
2
|
+
import { getPathSegments, getRelativePath, serialize, appendPathSegment, deepEqual, getValueAtPath, formatPathSegments } from '@conform-to/dom/future';
|
|
3
|
+
import { when, generateUniqueKey, merge, getArrayAtPath } from './util.mjs';
|
|
4
4
|
|
|
5
5
|
function initializeState(options) {
|
|
6
6
|
var _options$resetKey, _options$defaultValue;
|
|
@@ -237,7 +237,8 @@ function getConstraint(context, name) {
|
|
|
237
237
|
return constraint;
|
|
238
238
|
}
|
|
239
239
|
function getFormMetadata(context, options) {
|
|
240
|
-
|
|
240
|
+
var _options$extendFormMe, _options$extendFormMe2;
|
|
241
|
+
var metadata = {
|
|
241
242
|
key: context.state.resetKey,
|
|
242
243
|
id: context.formId,
|
|
243
244
|
errorId: "".concat(context.formId, "-form-error"),
|
|
@@ -270,31 +271,41 @@ function getFormMetadata(context, options) {
|
|
|
270
271
|
return getField(context, {
|
|
271
272
|
name,
|
|
272
273
|
serialize: options === null || options === void 0 ? void 0 : options.serialize,
|
|
273
|
-
|
|
274
|
+
extendFieldMetadata: options === null || options === void 0 ? void 0 : options.extendFieldMetadata
|
|
274
275
|
});
|
|
275
276
|
},
|
|
276
277
|
getFieldset(name) {
|
|
277
278
|
return getFieldset(context, {
|
|
278
279
|
name,
|
|
279
280
|
serialize: options === null || options === void 0 ? void 0 : options.serialize,
|
|
280
|
-
|
|
281
|
+
extendFieldMetadata: options === null || options === void 0 ? void 0 : options.extendFieldMetadata
|
|
281
282
|
});
|
|
282
283
|
},
|
|
283
284
|
getFieldList(name) {
|
|
284
285
|
return getFieldList(context, {
|
|
285
286
|
name,
|
|
286
287
|
serialize: options === null || options === void 0 ? void 0 : options.serialize,
|
|
287
|
-
|
|
288
|
+
extendFieldMetadata: options === null || options === void 0 ? void 0 : options.extendFieldMetadata
|
|
288
289
|
});
|
|
289
290
|
}
|
|
290
291
|
};
|
|
292
|
+
var customMetadata = (_options$extendFormMe = options === null || options === void 0 || (_options$extendFormMe2 = options.extendFormMetadata) === null || _options$extendFormMe2 === void 0 ? void 0 : _options$extendFormMe2.call(options, metadata)) !== null && _options$extendFormMe !== void 0 ? _options$extendFormMe : {};
|
|
293
|
+
var descriptors = Object.getOwnPropertyDescriptors(customMetadata);
|
|
294
|
+
var extended = Object.create(metadata);
|
|
295
|
+
Object.defineProperties(extended, descriptors);
|
|
296
|
+
return extended;
|
|
291
297
|
}
|
|
292
298
|
function getField(context, options) {
|
|
299
|
+
var _extendFieldMetadata;
|
|
293
300
|
var {
|
|
294
301
|
key,
|
|
295
302
|
name,
|
|
296
303
|
serialize: serialize$1 = serialize,
|
|
297
|
-
|
|
304
|
+
extendFieldMetadata,
|
|
305
|
+
form = getFormMetadata(context, {
|
|
306
|
+
serialize: serialize$1,
|
|
307
|
+
extendFieldMetadata
|
|
308
|
+
})
|
|
298
309
|
} = options;
|
|
299
310
|
var id = "".concat(context.formId, "-field-").concat(name.replace(/[^a-zA-Z0-9._-]/g, '_'));
|
|
300
311
|
var constraint = getConstraint(context, name);
|
|
@@ -347,40 +358,27 @@ function getField(context, options) {
|
|
|
347
358
|
return getFieldset(context, {
|
|
348
359
|
name: name,
|
|
349
360
|
serialize: serialize$1,
|
|
350
|
-
|
|
361
|
+
extendFieldMetadata
|
|
351
362
|
});
|
|
352
363
|
},
|
|
364
|
+
// @ts-expect-error The return type includes CustomFieldMetadata which BaseFieldMetadata
|
|
365
|
+
// doesn't account for. This is a type-level limitation; runtime behavior is correct.
|
|
353
366
|
getFieldList() {
|
|
354
367
|
return getFieldList(context, {
|
|
355
|
-
name
|
|
368
|
+
name,
|
|
356
369
|
serialize: serialize$1,
|
|
357
|
-
|
|
370
|
+
extendFieldMetadata
|
|
358
371
|
});
|
|
359
372
|
}
|
|
360
373
|
};
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
return Reflect.get(target, prop, receiver);
|
|
370
|
-
}
|
|
371
|
-
(_customMetadata = customMetadata) !== null && _customMetadata !== void 0 ? _customMetadata : customMetadata = customize(metadata);
|
|
372
|
-
if (Reflect.has(customMetadata, prop)) {
|
|
373
|
-
return Reflect.get(customMetadata, prop, receiver);
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
// Allow React DevTools to inspect the object
|
|
377
|
-
// without throwing errors for internal properties
|
|
378
|
-
if (typeof prop === 'symbol' || prop === '$$typeof') {
|
|
379
|
-
return undefined;
|
|
380
|
-
}
|
|
381
|
-
throw new Error("Property \"".concat(String(prop), "\" does not exist on field metadata. ") + "If you have defined the CustomMetadata interface to include \"".concat(String(prop), "\", make sure to also implement it through the \"defineCustomMetadata\" property on <FormOptionsProvider />."));
|
|
382
|
-
}
|
|
383
|
-
});
|
|
374
|
+
var customMetadata = (_extendFieldMetadata = extendFieldMetadata === null || extendFieldMetadata === void 0 ? void 0 : extendFieldMetadata(metadata, {
|
|
375
|
+
form,
|
|
376
|
+
when
|
|
377
|
+
})) !== null && _extendFieldMetadata !== void 0 ? _extendFieldMetadata : {};
|
|
378
|
+
var descriptors = Object.getOwnPropertyDescriptors(customMetadata);
|
|
379
|
+
var extended = Object.create(metadata);
|
|
380
|
+
Object.defineProperties(extended, descriptors);
|
|
381
|
+
return extended;
|
|
384
382
|
}
|
|
385
383
|
|
|
386
384
|
/**
|
|
@@ -390,10 +388,16 @@ function getFieldset(context, options) {
|
|
|
390
388
|
return new Proxy({}, {
|
|
391
389
|
get(target, name, receiver) {
|
|
392
390
|
if (typeof name === 'string') {
|
|
391
|
+
var _options$form;
|
|
392
|
+
(_options$form = options.form) !== null && _options$form !== void 0 ? _options$form : options.form = getFormMetadata(context, {
|
|
393
|
+
serialize: options === null || options === void 0 ? void 0 : options.serialize,
|
|
394
|
+
extendFieldMetadata: options === null || options === void 0 ? void 0 : options.extendFieldMetadata
|
|
395
|
+
});
|
|
393
396
|
return getField(context, {
|
|
394
397
|
name: appendPathSegment(options === null || options === void 0 ? void 0 : options.name, name),
|
|
395
398
|
serialize: options.serialize,
|
|
396
|
-
|
|
399
|
+
extendFieldMetadata: options.extendFieldMetadata,
|
|
400
|
+
form: options.form
|
|
397
401
|
});
|
|
398
402
|
}
|
|
399
403
|
return Reflect.get(target, name, receiver);
|
|
@@ -410,7 +414,7 @@ function getFieldList(context, options) {
|
|
|
410
414
|
return getField(context, {
|
|
411
415
|
name: appendPathSegment(options.name, index),
|
|
412
416
|
serialize: options.serialize,
|
|
413
|
-
|
|
417
|
+
extendFieldMetadata: options.extendFieldMetadata,
|
|
414
418
|
key
|
|
415
419
|
});
|
|
416
420
|
});
|