@geowiki/design-system 0.16.9-dev.14 → 0.16.9-dev.16
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.mts +1253 -0
- package/dist/index.d.ts +7 -3
- package/dist/index.js +266 -156
- package/dist/index.mjs +266 -156
- package/dist/styles.css +1 -1
- package/package.json +34 -34
package/dist/index.mjs
CHANGED
|
@@ -1200,48 +1200,48 @@ var isNullOrUndefined = (value) => value == null;
|
|
|
1200
1200
|
var isObjectType = (value) => typeof value === "object";
|
|
1201
1201
|
var isObject = (value) => !isNullOrUndefined(value) && !Array.isArray(value) && isObjectType(value) && !isDateObject(value);
|
|
1202
1202
|
var getEventValue = (event) => isObject(event) && event.target ? isCheckBoxInput(event.target) ? event.target.checked : event.target.value : event;
|
|
1203
|
-
var
|
|
1204
|
-
var isNameInFieldArray = (names, name) => names.has(getNodeParentName(name));
|
|
1203
|
+
var isNameInFieldArray = (names, name) => name.split(".").some((part, index, arr) => !isNaN(Number(part)) && names.has(arr.slice(0, index).join(".")));
|
|
1205
1204
|
var isPlainObject = (tempObject) => {
|
|
1206
1205
|
const prototypeCopy = tempObject.constructor && tempObject.constructor.prototype;
|
|
1207
1206
|
return isObject(prototypeCopy) && prototypeCopy.hasOwnProperty("isPrototypeOf");
|
|
1208
1207
|
};
|
|
1209
1208
|
var isWeb = typeof window !== "undefined" && typeof window.HTMLElement !== "undefined" && typeof document !== "undefined";
|
|
1210
1209
|
function cloneObject(data) {
|
|
1211
|
-
let copy;
|
|
1212
|
-
const isArray = Array.isArray(data);
|
|
1213
1210
|
if (data instanceof Date) {
|
|
1214
|
-
|
|
1215
|
-
}
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
copy = isArray ? [] : {};
|
|
1219
|
-
if (!isArray && !isPlainObject(data)) {
|
|
1220
|
-
copy = data;
|
|
1221
|
-
} else {
|
|
1222
|
-
for (const key in data) {
|
|
1223
|
-
if (data.hasOwnProperty(key)) {
|
|
1224
|
-
copy[key] = cloneObject(data[key]);
|
|
1225
|
-
}
|
|
1226
|
-
}
|
|
1227
|
-
}
|
|
1228
|
-
} else {
|
|
1211
|
+
return new Date(data);
|
|
1212
|
+
}
|
|
1213
|
+
const isFileListInstance = typeof FileList !== "undefined" && data instanceof FileList;
|
|
1214
|
+
if (isWeb && (data instanceof Blob || isFileListInstance)) {
|
|
1229
1215
|
return data;
|
|
1230
1216
|
}
|
|
1217
|
+
const isArray = Array.isArray(data);
|
|
1218
|
+
if (!isArray && !(isObject(data) && isPlainObject(data))) {
|
|
1219
|
+
return data;
|
|
1220
|
+
}
|
|
1221
|
+
const copy = isArray ? [] : Object.create(Object.getPrototypeOf(data));
|
|
1222
|
+
for (const key in data) {
|
|
1223
|
+
if (Object.prototype.hasOwnProperty.call(data, key)) {
|
|
1224
|
+
copy[key] = cloneObject(data[key]);
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1231
1227
|
return copy;
|
|
1232
1228
|
}
|
|
1233
|
-
var
|
|
1229
|
+
var isKey = (value) => /^\w*$/.test(value);
|
|
1234
1230
|
var isUndefined = (val) => val === void 0;
|
|
1231
|
+
var compact = (value) => Array.isArray(value) ? value.filter(Boolean) : [];
|
|
1232
|
+
var stringToPath = (input) => compact(input.replace(/["|']|\]/g, "").split(/\.|\[/));
|
|
1235
1233
|
var get = (object, path, defaultValue) => {
|
|
1236
1234
|
if (!path || !isObject(object)) {
|
|
1237
1235
|
return defaultValue;
|
|
1238
1236
|
}
|
|
1239
|
-
const
|
|
1237
|
+
const paths = isKey(path) ? [path] : stringToPath(path);
|
|
1238
|
+
const result = paths.reduce((result2, key) => {
|
|
1239
|
+
return isNullOrUndefined(result2) ? void 0 : result2[key];
|
|
1240
|
+
}, object);
|
|
1240
1241
|
return isUndefined(result) || result === object ? isUndefined(object[path]) ? defaultValue : object[path] : result;
|
|
1241
1242
|
};
|
|
1242
1243
|
var isBoolean = (value) => typeof value === "boolean";
|
|
1243
|
-
var
|
|
1244
|
-
var stringToPath = (input) => compact(input.replace(/["|']|\]/g, "").split(/\.|\[/));
|
|
1244
|
+
var isFunction = (value) => typeof value === "function";
|
|
1245
1245
|
var set = (object, path, value) => {
|
|
1246
1246
|
let index = -1;
|
|
1247
1247
|
const tempPath = isKey(path) ? [path] : stringToPath(path);
|
|
@@ -1254,18 +1254,20 @@ var set = (object, path, value) => {
|
|
|
1254
1254
|
const objValue = object[key];
|
|
1255
1255
|
newValue = isObject(objValue) || Array.isArray(objValue) ? objValue : !isNaN(+tempPath[index + 1]) ? [] : {};
|
|
1256
1256
|
}
|
|
1257
|
-
if (key === "__proto__") {
|
|
1257
|
+
if (key === "__proto__" || key === "constructor" || key === "prototype") {
|
|
1258
1258
|
return;
|
|
1259
1259
|
}
|
|
1260
1260
|
object[key] = newValue;
|
|
1261
1261
|
object = object[key];
|
|
1262
1262
|
}
|
|
1263
|
-
return object;
|
|
1264
1263
|
};
|
|
1265
1264
|
var EVENTS = {
|
|
1266
1265
|
BLUR: "blur",
|
|
1267
1266
|
FOCUS_OUT: "focusout",
|
|
1268
|
-
CHANGE: "change"
|
|
1267
|
+
CHANGE: "change",
|
|
1268
|
+
SUBMIT: "submit",
|
|
1269
|
+
TRIGGER: "trigger",
|
|
1270
|
+
VALID: "valid"
|
|
1269
1271
|
};
|
|
1270
1272
|
var VALIDATION_MODE = {
|
|
1271
1273
|
onBlur: "onBlur",
|
|
@@ -1274,16 +1276,11 @@ var VALIDATION_MODE = {
|
|
|
1274
1276
|
onTouched: "onTouched",
|
|
1275
1277
|
all: "all"
|
|
1276
1278
|
};
|
|
1277
|
-
var
|
|
1278
|
-
|
|
1279
|
-
var
|
|
1280
|
-
const _a = props, { children } = _a, data = __objRest(_a, ["children"]);
|
|
1281
|
-
return React12.createElement(HookFormContext.Provider, { value: data }, children);
|
|
1282
|
-
};
|
|
1279
|
+
var HookFormControlContext = React12.createContext(null);
|
|
1280
|
+
HookFormControlContext.displayName = "HookFormControlContext";
|
|
1281
|
+
var useFormControlContext = () => React12.useContext(HookFormControlContext);
|
|
1283
1282
|
var getProxyFormState = (formState, control, localProxyFormState, isRoot = true) => {
|
|
1284
|
-
const result = {
|
|
1285
|
-
defaultValues: control._defaultValues
|
|
1286
|
-
};
|
|
1283
|
+
const result = {};
|
|
1287
1284
|
for (const key in formState) {
|
|
1288
1285
|
Object.defineProperty(result, key, {
|
|
1289
1286
|
get: () => {
|
|
@@ -1298,31 +1295,13 @@ var getProxyFormState = (formState, control, localProxyFormState, isRoot = true)
|
|
|
1298
1295
|
}
|
|
1299
1296
|
return result;
|
|
1300
1297
|
};
|
|
1301
|
-
var
|
|
1302
|
-
var shouldRenderFormState = (formStateData, _proxyFormState, updateFormState, isRoot) => {
|
|
1303
|
-
updateFormState(formStateData);
|
|
1304
|
-
const _a = formStateData, { name } = _a, formState = __objRest(_a, ["name"]);
|
|
1305
|
-
return isEmptyObject(formState) || Object.keys(formState).length >= Object.keys(_proxyFormState).length || Object.keys(formState).find((key) => _proxyFormState[key] === (!isRoot || VALIDATION_MODE.all));
|
|
1306
|
-
};
|
|
1307
|
-
var convertToArrayPayload = (value) => Array.isArray(value) ? value : [value];
|
|
1308
|
-
var shouldSubscribeByName = (name, signalName, exact) => !name || !signalName || name === signalName || convertToArrayPayload(name).some((currentName) => currentName && (exact ? currentName === signalName : currentName.startsWith(signalName) || signalName.startsWith(currentName)));
|
|
1309
|
-
function useSubscribe(props) {
|
|
1310
|
-
const _props = React12.useRef(props);
|
|
1311
|
-
_props.current = props;
|
|
1312
|
-
React12.useEffect(() => {
|
|
1313
|
-
const subscription = !props.disabled && _props.current.subject && _props.current.subject.subscribe({
|
|
1314
|
-
next: _props.current.next
|
|
1315
|
-
});
|
|
1316
|
-
return () => {
|
|
1317
|
-
subscription && subscription.unsubscribe();
|
|
1318
|
-
};
|
|
1319
|
-
}, [props.disabled]);
|
|
1320
|
-
}
|
|
1298
|
+
var useIsomorphicLayoutEffect = typeof window !== "undefined" ? React12.useLayoutEffect : React12.useEffect;
|
|
1321
1299
|
function useFormState(props) {
|
|
1322
|
-
const
|
|
1323
|
-
const { control =
|
|
1324
|
-
const [formState, updateFormState] = React12.useState(control._formState)
|
|
1325
|
-
|
|
1300
|
+
const formControl = useFormControlContext();
|
|
1301
|
+
const { control = formControl, disabled, name, exact } = props || {};
|
|
1302
|
+
const [formState, updateFormState] = React12.useState(() => __spreadProps(__spreadValues({}, control._formState), {
|
|
1303
|
+
defaultValues: control._defaultValues
|
|
1304
|
+
}));
|
|
1326
1305
|
const _localProxyFormState = React12.useRef({
|
|
1327
1306
|
isDirty: false,
|
|
1328
1307
|
isLoading: false,
|
|
@@ -1333,21 +1312,20 @@ function useFormState(props) {
|
|
|
1333
1312
|
isValid: false,
|
|
1334
1313
|
errors: false
|
|
1335
1314
|
});
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1315
|
+
useIsomorphicLayoutEffect(() => control._subscribe({
|
|
1316
|
+
name,
|
|
1317
|
+
formState: _localProxyFormState.current,
|
|
1318
|
+
exact,
|
|
1319
|
+
callback: (formState2) => {
|
|
1320
|
+
!disabled && updateFormState(__spreadProps(__spreadValues(__spreadValues({}, control._formState), formState2), {
|
|
1321
|
+
defaultValues: control._defaultValues
|
|
1322
|
+
}));
|
|
1323
|
+
}
|
|
1324
|
+
}), [name, disabled, exact]);
|
|
1343
1325
|
React12.useEffect(() => {
|
|
1344
|
-
|
|
1345
|
-
_localProxyFormState.current.isValid && control._updateValid(true);
|
|
1346
|
-
return () => {
|
|
1347
|
-
_mounted.current = false;
|
|
1348
|
-
};
|
|
1326
|
+
_localProxyFormState.current.isValid && control._setValid(true);
|
|
1349
1327
|
}, [control]);
|
|
1350
|
-
return getProxyFormState(formState, control, _localProxyFormState.current, false);
|
|
1328
|
+
return React12.useMemo(() => getProxyFormState(formState, control, _localProxyFormState.current, false), [formState, control]);
|
|
1351
1329
|
}
|
|
1352
1330
|
var isString = (value) => typeof value === "string";
|
|
1353
1331
|
var generateWatchOutput = (names, _names, formValues, isGlobal, defaultValue) => {
|
|
@@ -1361,129 +1339,261 @@ var generateWatchOutput = (names, _names, formValues, isGlobal, defaultValue) =>
|
|
|
1361
1339
|
isGlobal && (_names.watchAll = true);
|
|
1362
1340
|
return formValues;
|
|
1363
1341
|
};
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1342
|
+
var isPrimitive = (value) => isNullOrUndefined(value) || !isObjectType(value);
|
|
1343
|
+
function deepEqual(object1, object2, visited = /* @__PURE__ */ new WeakSet()) {
|
|
1344
|
+
if (object1 === object2) {
|
|
1345
|
+
return true;
|
|
1346
|
+
}
|
|
1347
|
+
if (isPrimitive(object1) || isPrimitive(object2)) {
|
|
1348
|
+
return Object.is(object1, object2);
|
|
1349
|
+
}
|
|
1350
|
+
if (isDateObject(object1) && isDateObject(object2)) {
|
|
1351
|
+
return Object.is(object1.getTime(), object2.getTime());
|
|
1352
|
+
}
|
|
1353
|
+
const keys1 = Object.keys(object1);
|
|
1354
|
+
const keys2 = Object.keys(object2);
|
|
1355
|
+
if (keys1.length !== keys2.length) {
|
|
1356
|
+
return false;
|
|
1357
|
+
}
|
|
1358
|
+
if (visited.has(object1) || visited.has(object2)) {
|
|
1359
|
+
return true;
|
|
1360
|
+
}
|
|
1361
|
+
visited.add(object1);
|
|
1362
|
+
visited.add(object2);
|
|
1363
|
+
for (const key of keys1) {
|
|
1364
|
+
const val1 = object1[key];
|
|
1365
|
+
if (!(key in object2)) {
|
|
1366
|
+
return false;
|
|
1367
|
+
}
|
|
1368
|
+
if (key !== "ref") {
|
|
1369
|
+
const val2 = object2[key];
|
|
1370
|
+
if (isDateObject(val1) && isDateObject(val2) || (isObject(val1) || Array.isArray(val1)) && (isObject(val2) || Array.isArray(val2)) ? !deepEqual(val1, val2, visited) : !Object.is(val1, val2)) {
|
|
1371
|
+
return false;
|
|
1375
1372
|
}
|
|
1376
1373
|
}
|
|
1374
|
+
}
|
|
1375
|
+
return true;
|
|
1376
|
+
}
|
|
1377
|
+
function useWatch(props) {
|
|
1378
|
+
const formControl = useFormControlContext();
|
|
1379
|
+
const { control = formControl, name, defaultValue, disabled, exact, compute } = props || {};
|
|
1380
|
+
const _defaultValue = React12.useRef(defaultValue);
|
|
1381
|
+
const _compute = React12.useRef(compute);
|
|
1382
|
+
const _computeFormValues = React12.useRef(void 0);
|
|
1383
|
+
const _prevControl = React12.useRef(control);
|
|
1384
|
+
const _prevName = React12.useRef(name);
|
|
1385
|
+
_compute.current = compute;
|
|
1386
|
+
const [value, updateValue] = React12.useState(() => {
|
|
1387
|
+
const defaultValue2 = control._getWatch(name, _defaultValue.current);
|
|
1388
|
+
return _compute.current ? _compute.current(defaultValue2) : defaultValue2;
|
|
1377
1389
|
});
|
|
1378
|
-
const
|
|
1390
|
+
const getCurrentOutput = React12.useCallback((values) => {
|
|
1391
|
+
const formValues = generateWatchOutput(name, control._names, values || control._formValues, false, _defaultValue.current);
|
|
1392
|
+
return _compute.current ? _compute.current(formValues) : formValues;
|
|
1393
|
+
}, [control._formValues, control._names, name]);
|
|
1394
|
+
const refreshValue = React12.useCallback((values) => {
|
|
1395
|
+
if (!disabled) {
|
|
1396
|
+
const formValues = generateWatchOutput(name, control._names, values || control._formValues, false, _defaultValue.current);
|
|
1397
|
+
if (_compute.current) {
|
|
1398
|
+
const computedFormValues = _compute.current(formValues);
|
|
1399
|
+
if (!deepEqual(computedFormValues, _computeFormValues.current)) {
|
|
1400
|
+
updateValue(computedFormValues);
|
|
1401
|
+
_computeFormValues.current = computedFormValues;
|
|
1402
|
+
}
|
|
1403
|
+
} else {
|
|
1404
|
+
updateValue(formValues);
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
}, [control._formValues, control._names, disabled, name]);
|
|
1408
|
+
useIsomorphicLayoutEffect(() => {
|
|
1409
|
+
if (_prevControl.current !== control || !deepEqual(_prevName.current, name)) {
|
|
1410
|
+
_prevControl.current = control;
|
|
1411
|
+
_prevName.current = name;
|
|
1412
|
+
refreshValue();
|
|
1413
|
+
}
|
|
1414
|
+
return control._subscribe({
|
|
1415
|
+
name,
|
|
1416
|
+
formState: {
|
|
1417
|
+
values: true
|
|
1418
|
+
},
|
|
1419
|
+
exact,
|
|
1420
|
+
callback: (formState) => {
|
|
1421
|
+
refreshValue(formState.values);
|
|
1422
|
+
}
|
|
1423
|
+
});
|
|
1424
|
+
}, [control, exact, name, refreshValue]);
|
|
1379
1425
|
React12.useEffect(() => control._removeUnmounted());
|
|
1380
|
-
|
|
1426
|
+
const controlChanged = _prevControl.current !== control;
|
|
1427
|
+
const prevName = _prevName.current;
|
|
1428
|
+
const computedOutput = React12.useMemo(() => {
|
|
1429
|
+
if (disabled) {
|
|
1430
|
+
return null;
|
|
1431
|
+
}
|
|
1432
|
+
const nameChanged = !controlChanged && !deepEqual(prevName, name);
|
|
1433
|
+
const shouldReturnImmediate = controlChanged || nameChanged;
|
|
1434
|
+
return shouldReturnImmediate ? getCurrentOutput() : null;
|
|
1435
|
+
}, [disabled, controlChanged, name, prevName, getCurrentOutput]);
|
|
1436
|
+
return computedOutput !== null ? computedOutput : value;
|
|
1381
1437
|
}
|
|
1382
1438
|
function useController(props) {
|
|
1383
|
-
const
|
|
1384
|
-
const { name, disabled, control =
|
|
1439
|
+
const formControl = useFormControlContext();
|
|
1440
|
+
const { name, disabled, control = formControl, shouldUnregister, defaultValue, exact = true } = props;
|
|
1385
1441
|
const isArrayField = isNameInFieldArray(control._names.array, name);
|
|
1442
|
+
const defaultValueMemo = React12.useMemo(() => get(control._formValues, name, get(control._defaultValues, name, defaultValue)), [control, name, defaultValue]);
|
|
1386
1443
|
const value = useWatch({
|
|
1387
1444
|
control,
|
|
1388
1445
|
name,
|
|
1389
|
-
defaultValue:
|
|
1390
|
-
exact
|
|
1446
|
+
defaultValue: defaultValueMemo,
|
|
1447
|
+
exact
|
|
1391
1448
|
});
|
|
1392
1449
|
const formState = useFormState({
|
|
1393
1450
|
control,
|
|
1394
1451
|
name,
|
|
1395
|
-
exact
|
|
1452
|
+
exact
|
|
1396
1453
|
});
|
|
1454
|
+
const _props = React12.useRef(props);
|
|
1397
1455
|
const _registerProps = React12.useRef(control.register(name, __spreadValues(__spreadProps(__spreadValues({}, props.rules), {
|
|
1398
1456
|
value
|
|
1399
1457
|
}), isBoolean(props.disabled) ? { disabled: props.disabled } : {})));
|
|
1458
|
+
_props.current = props;
|
|
1459
|
+
const fieldState = React12.useMemo(() => Object.defineProperties({}, {
|
|
1460
|
+
invalid: {
|
|
1461
|
+
enumerable: true,
|
|
1462
|
+
get: () => !!get(formState.errors, name)
|
|
1463
|
+
},
|
|
1464
|
+
isDirty: {
|
|
1465
|
+
enumerable: true,
|
|
1466
|
+
get: () => !!get(formState.dirtyFields, name)
|
|
1467
|
+
},
|
|
1468
|
+
isTouched: {
|
|
1469
|
+
enumerable: true,
|
|
1470
|
+
get: () => !!get(formState.touchedFields, name)
|
|
1471
|
+
},
|
|
1472
|
+
isValidating: {
|
|
1473
|
+
enumerable: true,
|
|
1474
|
+
get: () => !!get(formState.validatingFields, name)
|
|
1475
|
+
},
|
|
1476
|
+
error: {
|
|
1477
|
+
enumerable: true,
|
|
1478
|
+
get: () => get(formState.errors, name)
|
|
1479
|
+
}
|
|
1480
|
+
}), [formState, name]);
|
|
1481
|
+
const onChange = React12.useCallback((event) => _registerProps.current.onChange({
|
|
1482
|
+
target: {
|
|
1483
|
+
value: getEventValue(event),
|
|
1484
|
+
name
|
|
1485
|
+
},
|
|
1486
|
+
type: EVENTS.CHANGE
|
|
1487
|
+
}), [name]);
|
|
1488
|
+
const onBlur = React12.useCallback(() => _registerProps.current.onBlur({
|
|
1489
|
+
target: {
|
|
1490
|
+
value: get(control._formValues, name),
|
|
1491
|
+
name
|
|
1492
|
+
},
|
|
1493
|
+
type: EVENTS.BLUR
|
|
1494
|
+
}), [name, control._formValues]);
|
|
1495
|
+
const ref = React12.useCallback((elm) => {
|
|
1496
|
+
const field2 = get(control._fields, name);
|
|
1497
|
+
if (field2 && field2._f && elm) {
|
|
1498
|
+
field2._f.ref = {
|
|
1499
|
+
focus: () => isFunction(elm.focus) && elm.focus(),
|
|
1500
|
+
select: () => isFunction(elm.select) && elm.select(),
|
|
1501
|
+
setCustomValidity: (message) => isFunction(elm.setCustomValidity) && elm.setCustomValidity(message),
|
|
1502
|
+
reportValidity: () => isFunction(elm.reportValidity) && elm.reportValidity()
|
|
1503
|
+
};
|
|
1504
|
+
}
|
|
1505
|
+
}, [control._fields, name]);
|
|
1506
|
+
const field = React12.useMemo(() => __spreadProps(__spreadValues({
|
|
1507
|
+
name,
|
|
1508
|
+
value
|
|
1509
|
+
}, isBoolean(disabled) || formState.disabled ? { disabled: formState.disabled || disabled } : {}), {
|
|
1510
|
+
onChange,
|
|
1511
|
+
onBlur,
|
|
1512
|
+
ref
|
|
1513
|
+
}), [name, disabled, formState.disabled, onChange, onBlur, ref, value]);
|
|
1400
1514
|
React12.useEffect(() => {
|
|
1401
1515
|
const _shouldUnregisterField = control._options.shouldUnregister || shouldUnregister;
|
|
1516
|
+
control.register(name, __spreadValues(__spreadValues({}, _props.current.rules), isBoolean(_props.current.disabled) ? { disabled: _props.current.disabled } : {}));
|
|
1402
1517
|
const updateMounted = (name2, value2) => {
|
|
1403
|
-
const
|
|
1404
|
-
if (
|
|
1405
|
-
|
|
1518
|
+
const field2 = get(control._fields, name2);
|
|
1519
|
+
if (field2 && field2._f) {
|
|
1520
|
+
field2._f.mount = value2;
|
|
1406
1521
|
}
|
|
1407
1522
|
};
|
|
1408
1523
|
updateMounted(name, true);
|
|
1409
1524
|
if (_shouldUnregisterField) {
|
|
1410
|
-
const value2 = cloneObject(get(control._options.defaultValues, name));
|
|
1525
|
+
const value2 = cloneObject(get(control._options.defaultValues, name, _props.current.defaultValue));
|
|
1411
1526
|
set(control._defaultValues, name, value2);
|
|
1412
1527
|
if (isUndefined(get(control._formValues, name))) {
|
|
1413
1528
|
set(control._formValues, name, value2);
|
|
1414
1529
|
}
|
|
1415
1530
|
}
|
|
1531
|
+
!isArrayField && control.register(name);
|
|
1416
1532
|
return () => {
|
|
1417
1533
|
(isArrayField ? _shouldUnregisterField && !control._state.action : _shouldUnregisterField) ? control.unregister(name) : updateMounted(name, false);
|
|
1418
1534
|
};
|
|
1419
1535
|
}, [name, control, isArrayField, shouldUnregister]);
|
|
1420
1536
|
React12.useEffect(() => {
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
name,
|
|
1426
|
-
value: get(control._fields, name)._f.value
|
|
1427
|
-
});
|
|
1428
|
-
}
|
|
1537
|
+
control._setDisabledField({
|
|
1538
|
+
disabled,
|
|
1539
|
+
name
|
|
1540
|
+
});
|
|
1429
1541
|
}, [disabled, name, control]);
|
|
1430
|
-
return {
|
|
1431
|
-
field
|
|
1432
|
-
name,
|
|
1433
|
-
value
|
|
1434
|
-
}, isBoolean(disabled) || formState.disabled ? { disabled: formState.disabled || disabled } : {}), {
|
|
1435
|
-
onChange: React12.useCallback((event) => _registerProps.current.onChange({
|
|
1436
|
-
target: {
|
|
1437
|
-
value: getEventValue(event),
|
|
1438
|
-
name
|
|
1439
|
-
},
|
|
1440
|
-
type: EVENTS.CHANGE
|
|
1441
|
-
}), [name]),
|
|
1442
|
-
onBlur: React12.useCallback(() => _registerProps.current.onBlur({
|
|
1443
|
-
target: {
|
|
1444
|
-
value: get(control._formValues, name),
|
|
1445
|
-
name
|
|
1446
|
-
},
|
|
1447
|
-
type: EVENTS.BLUR
|
|
1448
|
-
}), [name, control]),
|
|
1449
|
-
ref: React12.useCallback((elm) => {
|
|
1450
|
-
const field = get(control._fields, name);
|
|
1451
|
-
if (field && elm) {
|
|
1452
|
-
field._f.ref = {
|
|
1453
|
-
focus: () => elm.focus(),
|
|
1454
|
-
select: () => elm.select(),
|
|
1455
|
-
setCustomValidity: (message) => elm.setCustomValidity(message),
|
|
1456
|
-
reportValidity: () => elm.reportValidity()
|
|
1457
|
-
};
|
|
1458
|
-
}
|
|
1459
|
-
}, [control._fields, name])
|
|
1460
|
-
}),
|
|
1542
|
+
return React12.useMemo(() => ({
|
|
1543
|
+
field,
|
|
1461
1544
|
formState,
|
|
1462
|
-
fieldState
|
|
1463
|
-
|
|
1464
|
-
enumerable: true,
|
|
1465
|
-
get: () => !!get(formState.errors, name)
|
|
1466
|
-
},
|
|
1467
|
-
isDirty: {
|
|
1468
|
-
enumerable: true,
|
|
1469
|
-
get: () => !!get(formState.dirtyFields, name)
|
|
1470
|
-
},
|
|
1471
|
-
isTouched: {
|
|
1472
|
-
enumerable: true,
|
|
1473
|
-
get: () => !!get(formState.touchedFields, name)
|
|
1474
|
-
},
|
|
1475
|
-
isValidating: {
|
|
1476
|
-
enumerable: true,
|
|
1477
|
-
get: () => !!get(formState.validatingFields, name)
|
|
1478
|
-
},
|
|
1479
|
-
error: {
|
|
1480
|
-
enumerable: true,
|
|
1481
|
-
get: () => get(formState.errors, name)
|
|
1482
|
-
}
|
|
1483
|
-
})
|
|
1484
|
-
};
|
|
1545
|
+
fieldState
|
|
1546
|
+
}), [field, formState, fieldState]);
|
|
1485
1547
|
}
|
|
1486
1548
|
var Controller = (props) => props.render(useController(props));
|
|
1549
|
+
var HookFormContext = React12.createContext(null);
|
|
1550
|
+
HookFormContext.displayName = "HookFormContext";
|
|
1551
|
+
var useFormContext = () => React12.useContext(HookFormContext);
|
|
1552
|
+
var FormProvider = (props) => {
|
|
1553
|
+
const { children, watch, getValues, getFieldState, setError, clearErrors, setValue, setValues, trigger, formState, resetField, reset, handleSubmit, unregister, control, register, setFocus, subscribe } = props;
|
|
1554
|
+
const memoizedValue = React12.useMemo(() => ({
|
|
1555
|
+
watch,
|
|
1556
|
+
getValues,
|
|
1557
|
+
getFieldState,
|
|
1558
|
+
setError,
|
|
1559
|
+
clearErrors,
|
|
1560
|
+
setValue,
|
|
1561
|
+
setValues,
|
|
1562
|
+
trigger,
|
|
1563
|
+
formState,
|
|
1564
|
+
resetField,
|
|
1565
|
+
reset,
|
|
1566
|
+
handleSubmit,
|
|
1567
|
+
unregister,
|
|
1568
|
+
control,
|
|
1569
|
+
register,
|
|
1570
|
+
setFocus,
|
|
1571
|
+
subscribe
|
|
1572
|
+
}), [
|
|
1573
|
+
clearErrors,
|
|
1574
|
+
control,
|
|
1575
|
+
formState,
|
|
1576
|
+
getFieldState,
|
|
1577
|
+
getValues,
|
|
1578
|
+
handleSubmit,
|
|
1579
|
+
register,
|
|
1580
|
+
reset,
|
|
1581
|
+
resetField,
|
|
1582
|
+
setError,
|
|
1583
|
+
setFocus,
|
|
1584
|
+
setValue,
|
|
1585
|
+
setValues,
|
|
1586
|
+
subscribe,
|
|
1587
|
+
trigger,
|
|
1588
|
+
unregister,
|
|
1589
|
+
watch
|
|
1590
|
+
]);
|
|
1591
|
+
return React12.createElement(
|
|
1592
|
+
HookFormContext.Provider,
|
|
1593
|
+
{ value: memoizedValue },
|
|
1594
|
+
React12.createElement(HookFormControlContext.Provider, { value: memoizedValue.control }, children)
|
|
1595
|
+
);
|
|
1596
|
+
};
|
|
1487
1597
|
var defaultOptions = {
|
|
1488
1598
|
mode: VALIDATION_MODE.onSubmit,
|
|
1489
1599
|
reValidateMode: VALIDATION_MODE.onChange,
|