@adiba-banking-cloud/backoffice 0.0.71 → 0.0.73
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/build/index.cjs.js/index.js +11 -1051
- package/build/index.esm.js/index.js +7 -1047
- package/package.json +3 -2
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
2
2
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
3
3
|
import { modals } from '@mantine/modals';
|
|
4
|
-
import React, { useRef, useMemo, useEffect
|
|
5
|
-
import { Center, Image, Space, Popover, Button, Stack, Divider, Group, Text, Menu, Avatar, Badge, NavLink, Card, TextInput, ActionIcon, Box, Title, SegmentedControl, Breadcrumbs, Anchor, ColorSwatch, AspectRatio, Overlay, rem, SimpleGrid, Indicator, Table, createTheme, PinInput, Drawer as Drawer$1, ScrollArea,
|
|
4
|
+
import React, { useRef, useMemo, useEffect } from 'react';
|
|
5
|
+
import { Center, Image, Space, Popover, Button, Stack, Divider, Group, Text, Menu, Avatar, Badge, NavLink, Card, TextInput, ActionIcon, Box, Title, SegmentedControl, Breadcrumbs, Anchor, ColorSwatch, AspectRatio, Overlay, rem, SimpleGrid, Indicator, Table, createTheme, PinInput, Drawer as Drawer$1, ScrollArea, NumberInput, PasswordInput, Textarea, Grid } from '@mantine/core';
|
|
6
6
|
import { DotLottieReact } from '@lottiefiles/dotlottie-react';
|
|
7
7
|
import _extends from '@babel/runtime/helpers/extends';
|
|
8
8
|
import HighchartsReact from 'highcharts-react-official';
|
|
@@ -18,6 +18,7 @@ import '@fontsource/poppins/500.css';
|
|
|
18
18
|
import '@fontsource/poppins/600.css';
|
|
19
19
|
import '@fontsource/poppins/700.css';
|
|
20
20
|
import '@fontsource/poppins/800.css';
|
|
21
|
+
import { useForm } from '@mantine/form';
|
|
21
22
|
|
|
22
23
|
function _mergeNamespaces(n, m) {
|
|
23
24
|
m.forEach(function (e) {
|
|
@@ -13226,1049 +13227,6 @@ const Drawer = _ref => {
|
|
|
13226
13227
|
}, page))));
|
|
13227
13228
|
};
|
|
13228
13229
|
|
|
13229
|
-
function validateFormName(name) {
|
|
13230
|
-
if (!/^[0-9a-zA-Z-]+$/.test(name)) {
|
|
13231
|
-
throw new Error(
|
|
13232
|
-
`[@mantine/use-form] Form name "${name}" is invalid, it should contain only letters, numbers and dashes`
|
|
13233
|
-
);
|
|
13234
|
-
}
|
|
13235
|
-
}
|
|
13236
|
-
const useIsomorphicEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect;
|
|
13237
|
-
function useFormEvent(eventKey, handler) {
|
|
13238
|
-
useIsomorphicEffect(() => {
|
|
13239
|
-
if (eventKey) {
|
|
13240
|
-
window.addEventListener(eventKey, handler);
|
|
13241
|
-
return () => window.removeEventListener(eventKey, handler);
|
|
13242
|
-
}
|
|
13243
|
-
return void 0;
|
|
13244
|
-
}, [eventKey]);
|
|
13245
|
-
}
|
|
13246
|
-
function useFormActions(name, form) {
|
|
13247
|
-
if (name) {
|
|
13248
|
-
validateFormName(name);
|
|
13249
|
-
}
|
|
13250
|
-
useFormEvent(
|
|
13251
|
-
`mantine-form:${name}:set-field-value`,
|
|
13252
|
-
(event) => form.setFieldValue(event.detail.path, event.detail.value)
|
|
13253
|
-
);
|
|
13254
|
-
useFormEvent(
|
|
13255
|
-
`mantine-form:${name}:set-values`,
|
|
13256
|
-
(event) => form.setValues(event.detail)
|
|
13257
|
-
);
|
|
13258
|
-
useFormEvent(
|
|
13259
|
-
`mantine-form:${name}:set-initial-values`,
|
|
13260
|
-
(event) => form.setInitialValues(event.detail)
|
|
13261
|
-
);
|
|
13262
|
-
useFormEvent(
|
|
13263
|
-
`mantine-form:${name}:set-errors`,
|
|
13264
|
-
(event) => form.setErrors(event.detail)
|
|
13265
|
-
);
|
|
13266
|
-
useFormEvent(
|
|
13267
|
-
`mantine-form:${name}:set-field-error`,
|
|
13268
|
-
(event) => form.setFieldError(event.detail.path, event.detail.error)
|
|
13269
|
-
);
|
|
13270
|
-
useFormEvent(
|
|
13271
|
-
`mantine-form:${name}:clear-field-error`,
|
|
13272
|
-
(event) => form.clearFieldError(event.detail)
|
|
13273
|
-
);
|
|
13274
|
-
useFormEvent(`mantine-form:${name}:clear-errors`, form.clearErrors);
|
|
13275
|
-
useFormEvent(`mantine-form:${name}:reset`, form.reset);
|
|
13276
|
-
useFormEvent(`mantine-form:${name}:validate`, form.validate);
|
|
13277
|
-
useFormEvent(
|
|
13278
|
-
`mantine-form:${name}:validate-field`,
|
|
13279
|
-
(event) => form.validateField(event.detail)
|
|
13280
|
-
);
|
|
13281
|
-
useFormEvent(
|
|
13282
|
-
`mantine-form:${name}:reorder-list-item`,
|
|
13283
|
-
(event) => form.reorderListItem(event.detail.path, event.detail.payload)
|
|
13284
|
-
);
|
|
13285
|
-
useFormEvent(
|
|
13286
|
-
`mantine-form:${name}:remove-list-item`,
|
|
13287
|
-
(event) => form.removeListItem(event.detail.path, event.detail.index)
|
|
13288
|
-
);
|
|
13289
|
-
useFormEvent(
|
|
13290
|
-
`mantine-form:${name}:insert-list-item`,
|
|
13291
|
-
(event) => form.insertListItem(event.detail.path, event.detail.item, event.detail.index)
|
|
13292
|
-
);
|
|
13293
|
-
useFormEvent(
|
|
13294
|
-
`mantine-form:${name}:set-dirty`,
|
|
13295
|
-
(event) => form.setDirty(event.detail)
|
|
13296
|
-
);
|
|
13297
|
-
useFormEvent(
|
|
13298
|
-
`mantine-form:${name}:set-touched`,
|
|
13299
|
-
(event) => form.setTouched(event.detail)
|
|
13300
|
-
);
|
|
13301
|
-
useFormEvent(
|
|
13302
|
-
`mantine-form:${name}:reset-dirty`,
|
|
13303
|
-
(event) => form.resetDirty(event.detail)
|
|
13304
|
-
);
|
|
13305
|
-
useFormEvent(`mantine-form:${name}:reset-touched`, form.resetTouched);
|
|
13306
|
-
}
|
|
13307
|
-
|
|
13308
|
-
function getInputOnChange(setValue) {
|
|
13309
|
-
return (val) => {
|
|
13310
|
-
if (!val) {
|
|
13311
|
-
setValue(val);
|
|
13312
|
-
} else if (typeof val === "function") {
|
|
13313
|
-
setValue(val);
|
|
13314
|
-
} else if (typeof val === "object" && "nativeEvent" in val) {
|
|
13315
|
-
const { currentTarget } = val;
|
|
13316
|
-
if (currentTarget instanceof HTMLInputElement) {
|
|
13317
|
-
if (currentTarget.type === "checkbox") {
|
|
13318
|
-
setValue(currentTarget.checked);
|
|
13319
|
-
} else {
|
|
13320
|
-
setValue(currentTarget.value);
|
|
13321
|
-
}
|
|
13322
|
-
} else if (currentTarget instanceof HTMLTextAreaElement || currentTarget instanceof HTMLSelectElement) {
|
|
13323
|
-
setValue(currentTarget.value);
|
|
13324
|
-
}
|
|
13325
|
-
} else {
|
|
13326
|
-
setValue(val);
|
|
13327
|
-
}
|
|
13328
|
-
};
|
|
13329
|
-
}
|
|
13330
|
-
|
|
13331
|
-
function filterErrors(errors) {
|
|
13332
|
-
if (errors === null || typeof errors !== "object") {
|
|
13333
|
-
return {};
|
|
13334
|
-
}
|
|
13335
|
-
return Object.keys(errors).reduce((acc, key) => {
|
|
13336
|
-
const errorValue = errors[key];
|
|
13337
|
-
if (errorValue !== void 0 && errorValue !== null && errorValue !== false) {
|
|
13338
|
-
acc[key] = errorValue;
|
|
13339
|
-
}
|
|
13340
|
-
return acc;
|
|
13341
|
-
}, {});
|
|
13342
|
-
}
|
|
13343
|
-
|
|
13344
|
-
function useFormErrors(initialErrors) {
|
|
13345
|
-
const [errorsState, setErrorsState] = useState(filterErrors(initialErrors));
|
|
13346
|
-
const errorsRef = useRef(errorsState);
|
|
13347
|
-
const setErrors = useCallback((errors) => {
|
|
13348
|
-
setErrorsState((current) => {
|
|
13349
|
-
const newErrors = filterErrors(typeof errors === "function" ? errors(current) : errors);
|
|
13350
|
-
errorsRef.current = newErrors;
|
|
13351
|
-
return newErrors;
|
|
13352
|
-
});
|
|
13353
|
-
}, []);
|
|
13354
|
-
const clearErrors = useCallback(() => setErrors({}), []);
|
|
13355
|
-
const clearFieldError = useCallback(
|
|
13356
|
-
(path) => {
|
|
13357
|
-
if (errorsRef.current[path] === void 0) {
|
|
13358
|
-
return;
|
|
13359
|
-
}
|
|
13360
|
-
setErrors((current) => {
|
|
13361
|
-
const errors = { ...current };
|
|
13362
|
-
delete errors[path];
|
|
13363
|
-
return errors;
|
|
13364
|
-
});
|
|
13365
|
-
},
|
|
13366
|
-
[errorsState]
|
|
13367
|
-
);
|
|
13368
|
-
const setFieldError = useCallback(
|
|
13369
|
-
(path, error) => {
|
|
13370
|
-
if (error == null || error === false) {
|
|
13371
|
-
clearFieldError(path);
|
|
13372
|
-
} else if (errorsRef.current[path] !== error) {
|
|
13373
|
-
setErrors((current) => ({ ...current, [path]: error }));
|
|
13374
|
-
}
|
|
13375
|
-
},
|
|
13376
|
-
[errorsState]
|
|
13377
|
-
);
|
|
13378
|
-
return {
|
|
13379
|
-
errorsState,
|
|
13380
|
-
setErrors,
|
|
13381
|
-
clearErrors,
|
|
13382
|
-
setFieldError,
|
|
13383
|
-
clearFieldError
|
|
13384
|
-
};
|
|
13385
|
-
}
|
|
13386
|
-
|
|
13387
|
-
function clearListState(field, state) {
|
|
13388
|
-
if (state === null || typeof state !== "object") {
|
|
13389
|
-
return {};
|
|
13390
|
-
}
|
|
13391
|
-
const clone = { ...state };
|
|
13392
|
-
Object.keys(state).forEach((errorKey) => {
|
|
13393
|
-
if (errorKey.includes(`${String(field)}.`)) {
|
|
13394
|
-
delete clone[errorKey];
|
|
13395
|
-
}
|
|
13396
|
-
});
|
|
13397
|
-
return clone;
|
|
13398
|
-
}
|
|
13399
|
-
|
|
13400
|
-
function getIndexFromKeyAfterPath(key, path) {
|
|
13401
|
-
const split = key.substring(path.length + 1).split(".")[0];
|
|
13402
|
-
return parseInt(split, 10);
|
|
13403
|
-
}
|
|
13404
|
-
function changeErrorIndices(path, index, errors, change) {
|
|
13405
|
-
if (index === void 0) {
|
|
13406
|
-
return errors;
|
|
13407
|
-
}
|
|
13408
|
-
const pathString = `${String(path)}`;
|
|
13409
|
-
let clearedErrors = errors;
|
|
13410
|
-
if (change === -1) {
|
|
13411
|
-
clearedErrors = clearListState(`${pathString}.${index}`, clearedErrors);
|
|
13412
|
-
}
|
|
13413
|
-
const cloned = { ...clearedErrors };
|
|
13414
|
-
const changedKeys = /* @__PURE__ */ new Set();
|
|
13415
|
-
Object.entries(clearedErrors).filter(([key]) => {
|
|
13416
|
-
if (!key.startsWith(`${pathString}.`)) {
|
|
13417
|
-
return false;
|
|
13418
|
-
}
|
|
13419
|
-
const currIndex = getIndexFromKeyAfterPath(key, pathString);
|
|
13420
|
-
if (Number.isNaN(currIndex)) {
|
|
13421
|
-
return false;
|
|
13422
|
-
}
|
|
13423
|
-
return currIndex >= index;
|
|
13424
|
-
}).forEach(([key, value]) => {
|
|
13425
|
-
const currIndex = getIndexFromKeyAfterPath(key, pathString);
|
|
13426
|
-
const newKey = key.replace(
|
|
13427
|
-
`${pathString}.${currIndex}`,
|
|
13428
|
-
`${pathString}.${currIndex + change}`
|
|
13429
|
-
);
|
|
13430
|
-
cloned[newKey] = value;
|
|
13431
|
-
changedKeys.add(newKey);
|
|
13432
|
-
if (!changedKeys.has(key)) {
|
|
13433
|
-
delete cloned[key];
|
|
13434
|
-
}
|
|
13435
|
-
});
|
|
13436
|
-
return cloned;
|
|
13437
|
-
}
|
|
13438
|
-
|
|
13439
|
-
function reorderErrors(path, { from, to }, errors) {
|
|
13440
|
-
const oldKeyStart = `${path}.${from}`;
|
|
13441
|
-
const newKeyStart = `${path}.${to}`;
|
|
13442
|
-
const clone = { ...errors };
|
|
13443
|
-
const processedKeys = /* @__PURE__ */ new Set();
|
|
13444
|
-
Object.keys(errors).forEach((key) => {
|
|
13445
|
-
if (processedKeys.has(key)) {
|
|
13446
|
-
return;
|
|
13447
|
-
}
|
|
13448
|
-
let oldKey;
|
|
13449
|
-
let newKey;
|
|
13450
|
-
if (key.startsWith(oldKeyStart)) {
|
|
13451
|
-
oldKey = key;
|
|
13452
|
-
newKey = key.replace(oldKeyStart, newKeyStart);
|
|
13453
|
-
} else if (key.startsWith(newKeyStart)) {
|
|
13454
|
-
oldKey = key.replace(newKeyStart, oldKeyStart);
|
|
13455
|
-
newKey = key;
|
|
13456
|
-
}
|
|
13457
|
-
if (oldKey && newKey) {
|
|
13458
|
-
const value1 = clone[oldKey];
|
|
13459
|
-
const value2 = clone[newKey];
|
|
13460
|
-
value2 === void 0 ? delete clone[oldKey] : clone[oldKey] = value2;
|
|
13461
|
-
value1 === void 0 ? delete clone[newKey] : clone[newKey] = value1;
|
|
13462
|
-
processedKeys.add(oldKey);
|
|
13463
|
-
processedKeys.add(newKey);
|
|
13464
|
-
}
|
|
13465
|
-
});
|
|
13466
|
-
return clone;
|
|
13467
|
-
}
|
|
13468
|
-
|
|
13469
|
-
function set(obj, key, val) {
|
|
13470
|
-
if (typeof val.value === 'object') val.value = klona(val.value);
|
|
13471
|
-
if (!val.enumerable || val.get || val.set || !val.configurable || !val.writable || key === '__proto__') {
|
|
13472
|
-
Object.defineProperty(obj, key, val);
|
|
13473
|
-
} else obj[key] = val.value;
|
|
13474
|
-
}
|
|
13475
|
-
|
|
13476
|
-
function klona(x) {
|
|
13477
|
-
if (typeof x !== 'object') return x;
|
|
13478
|
-
|
|
13479
|
-
var i=0, k, list, tmp, str=Object.prototype.toString.call(x);
|
|
13480
|
-
|
|
13481
|
-
if (str === '[object Object]') {
|
|
13482
|
-
tmp = Object.create(x.__proto__ || null);
|
|
13483
|
-
} else if (str === '[object Array]') {
|
|
13484
|
-
tmp = Array(x.length);
|
|
13485
|
-
} else if (str === '[object Set]') {
|
|
13486
|
-
tmp = new Set;
|
|
13487
|
-
x.forEach(function (val) {
|
|
13488
|
-
tmp.add(klona(val));
|
|
13489
|
-
});
|
|
13490
|
-
} else if (str === '[object Map]') {
|
|
13491
|
-
tmp = new Map;
|
|
13492
|
-
x.forEach(function (val, key) {
|
|
13493
|
-
tmp.set(klona(key), klona(val));
|
|
13494
|
-
});
|
|
13495
|
-
} else if (str === '[object Date]') {
|
|
13496
|
-
tmp = new Date(+x);
|
|
13497
|
-
} else if (str === '[object RegExp]') {
|
|
13498
|
-
tmp = new RegExp(x.source, x.flags);
|
|
13499
|
-
} else if (str === '[object DataView]') {
|
|
13500
|
-
tmp = new x.constructor( klona(x.buffer) );
|
|
13501
|
-
} else if (str === '[object ArrayBuffer]') {
|
|
13502
|
-
tmp = x.slice(0);
|
|
13503
|
-
} else if (str.slice(-6) === 'Array]') {
|
|
13504
|
-
// ArrayBuffer.isView(x)
|
|
13505
|
-
// ~> `new` bcuz `Buffer.slice` => ref
|
|
13506
|
-
tmp = new x.constructor(x);
|
|
13507
|
-
}
|
|
13508
|
-
|
|
13509
|
-
if (tmp) {
|
|
13510
|
-
for (list=Object.getOwnPropertySymbols(x); i < list.length; i++) {
|
|
13511
|
-
set(tmp, list[i], Object.getOwnPropertyDescriptor(x, list[i]));
|
|
13512
|
-
}
|
|
13513
|
-
|
|
13514
|
-
for (i=0, list=Object.getOwnPropertyNames(x); i < list.length; i++) {
|
|
13515
|
-
if (Object.hasOwnProperty.call(tmp, k=list[i]) && tmp[k] === x[k]) continue;
|
|
13516
|
-
set(tmp, k, Object.getOwnPropertyDescriptor(x, k));
|
|
13517
|
-
}
|
|
13518
|
-
}
|
|
13519
|
-
|
|
13520
|
-
return tmp || x;
|
|
13521
|
-
}
|
|
13522
|
-
|
|
13523
|
-
function getSplittedPath(path) {
|
|
13524
|
-
if (typeof path !== "string") {
|
|
13525
|
-
return [];
|
|
13526
|
-
}
|
|
13527
|
-
return path.split(".");
|
|
13528
|
-
}
|
|
13529
|
-
|
|
13530
|
-
function getPath(path, values) {
|
|
13531
|
-
const splittedPath = getSplittedPath(path);
|
|
13532
|
-
if (splittedPath.length === 0 || typeof values !== "object" || values === null) {
|
|
13533
|
-
return void 0;
|
|
13534
|
-
}
|
|
13535
|
-
let value = values[splittedPath[0]];
|
|
13536
|
-
for (let i = 1; i < splittedPath.length; i += 1) {
|
|
13537
|
-
if (value == null) {
|
|
13538
|
-
break;
|
|
13539
|
-
}
|
|
13540
|
-
value = value[splittedPath[i]];
|
|
13541
|
-
}
|
|
13542
|
-
return value;
|
|
13543
|
-
}
|
|
13544
|
-
|
|
13545
|
-
function setPath(path, value, values) {
|
|
13546
|
-
const splittedPath = getSplittedPath(path);
|
|
13547
|
-
if (splittedPath.length === 0) {
|
|
13548
|
-
return values;
|
|
13549
|
-
}
|
|
13550
|
-
const cloned = klona(values);
|
|
13551
|
-
if (splittedPath.length === 1) {
|
|
13552
|
-
cloned[splittedPath[0]] = value;
|
|
13553
|
-
return cloned;
|
|
13554
|
-
}
|
|
13555
|
-
let val = cloned[splittedPath[0]];
|
|
13556
|
-
for (let i = 1; i < splittedPath.length - 1; i += 1) {
|
|
13557
|
-
if (val === void 0) {
|
|
13558
|
-
return cloned;
|
|
13559
|
-
}
|
|
13560
|
-
val = val[splittedPath[i]];
|
|
13561
|
-
}
|
|
13562
|
-
val[splittedPath[splittedPath.length - 1]] = value;
|
|
13563
|
-
return cloned;
|
|
13564
|
-
}
|
|
13565
|
-
|
|
13566
|
-
function reorderPath(path, { from, to }, values) {
|
|
13567
|
-
const currentValue = getPath(path, values);
|
|
13568
|
-
if (!Array.isArray(currentValue)) {
|
|
13569
|
-
return values;
|
|
13570
|
-
}
|
|
13571
|
-
const cloned = [...currentValue];
|
|
13572
|
-
const item = currentValue[from];
|
|
13573
|
-
cloned.splice(from, 1);
|
|
13574
|
-
cloned.splice(to, 0, item);
|
|
13575
|
-
return setPath(path, cloned, values);
|
|
13576
|
-
}
|
|
13577
|
-
|
|
13578
|
-
function insertPath(path, value, index, values) {
|
|
13579
|
-
const currentValue = getPath(path, values);
|
|
13580
|
-
if (!Array.isArray(currentValue)) {
|
|
13581
|
-
return values;
|
|
13582
|
-
}
|
|
13583
|
-
const cloned = [...currentValue];
|
|
13584
|
-
cloned.splice(typeof index === "number" ? index : cloned.length, 0, value);
|
|
13585
|
-
return setPath(path, cloned, values);
|
|
13586
|
-
}
|
|
13587
|
-
|
|
13588
|
-
function removePath(path, index, values) {
|
|
13589
|
-
const currentValue = getPath(path, values);
|
|
13590
|
-
if (!Array.isArray(currentValue)) {
|
|
13591
|
-
return values;
|
|
13592
|
-
}
|
|
13593
|
-
return setPath(
|
|
13594
|
-
path,
|
|
13595
|
-
currentValue.filter((_, itemIndex) => itemIndex !== index),
|
|
13596
|
-
values
|
|
13597
|
-
);
|
|
13598
|
-
}
|
|
13599
|
-
|
|
13600
|
-
function replacePath(path, item, index, values) {
|
|
13601
|
-
const currentValue = getPath(path, values);
|
|
13602
|
-
if (!Array.isArray(currentValue)) {
|
|
13603
|
-
return values;
|
|
13604
|
-
}
|
|
13605
|
-
if (currentValue.length <= index) {
|
|
13606
|
-
return values;
|
|
13607
|
-
}
|
|
13608
|
-
const cloned = [...currentValue];
|
|
13609
|
-
cloned[index] = item;
|
|
13610
|
-
return setPath(path, cloned, values);
|
|
13611
|
-
}
|
|
13612
|
-
|
|
13613
|
-
function useFormList({
|
|
13614
|
-
$values,
|
|
13615
|
-
$errors,
|
|
13616
|
-
$status
|
|
13617
|
-
}) {
|
|
13618
|
-
const reorderListItem = useCallback((path, payload) => {
|
|
13619
|
-
$status.clearFieldDirty(path);
|
|
13620
|
-
$errors.setErrors((errs) => reorderErrors(path, payload, errs));
|
|
13621
|
-
$values.setValues({
|
|
13622
|
-
values: reorderPath(path, payload, $values.refValues.current),
|
|
13623
|
-
updateState: true
|
|
13624
|
-
});
|
|
13625
|
-
}, []);
|
|
13626
|
-
const removeListItem = useCallback((path, index) => {
|
|
13627
|
-
$status.clearFieldDirty(path);
|
|
13628
|
-
$errors.setErrors((errs) => changeErrorIndices(path, index, errs, -1));
|
|
13629
|
-
$values.setValues({
|
|
13630
|
-
values: removePath(path, index, $values.refValues.current),
|
|
13631
|
-
updateState: true
|
|
13632
|
-
});
|
|
13633
|
-
}, []);
|
|
13634
|
-
const insertListItem = useCallback((path, item, index) => {
|
|
13635
|
-
$status.clearFieldDirty(path);
|
|
13636
|
-
$errors.setErrors((errs) => changeErrorIndices(path, index, errs, 1));
|
|
13637
|
-
$values.setValues({
|
|
13638
|
-
values: insertPath(path, item, index, $values.refValues.current),
|
|
13639
|
-
updateState: true
|
|
13640
|
-
});
|
|
13641
|
-
}, []);
|
|
13642
|
-
const replaceListItem = useCallback((path, index, item) => {
|
|
13643
|
-
$status.clearFieldDirty(path);
|
|
13644
|
-
$values.setValues({
|
|
13645
|
-
values: replacePath(path, item, index, $values.refValues.current),
|
|
13646
|
-
updateState: true
|
|
13647
|
-
});
|
|
13648
|
-
}, []);
|
|
13649
|
-
return { reorderListItem, removeListItem, insertListItem, replaceListItem };
|
|
13650
|
-
}
|
|
13651
|
-
|
|
13652
|
-
var fastDeepEqual;
|
|
13653
|
-
var hasRequiredFastDeepEqual;
|
|
13654
|
-
function requireFastDeepEqual() {
|
|
13655
|
-
if (hasRequiredFastDeepEqual) return fastDeepEqual;
|
|
13656
|
-
hasRequiredFastDeepEqual = 1;
|
|
13657
|
-
|
|
13658
|
-
// do not edit .js files directly - edit src/index.jst
|
|
13659
|
-
|
|
13660
|
-
fastDeepEqual = function equal(a, b) {
|
|
13661
|
-
if (a === b) return true;
|
|
13662
|
-
if (a && b && typeof a == 'object' && typeof b == 'object') {
|
|
13663
|
-
if (a.constructor !== b.constructor) return false;
|
|
13664
|
-
var length, i, keys;
|
|
13665
|
-
if (Array.isArray(a)) {
|
|
13666
|
-
length = a.length;
|
|
13667
|
-
if (length != b.length) return false;
|
|
13668
|
-
for (i = length; i-- !== 0;) if (!equal(a[i], b[i])) return false;
|
|
13669
|
-
return true;
|
|
13670
|
-
}
|
|
13671
|
-
if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
|
|
13672
|
-
if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
|
|
13673
|
-
if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
|
|
13674
|
-
keys = Object.keys(a);
|
|
13675
|
-
length = keys.length;
|
|
13676
|
-
if (length !== Object.keys(b).length) return false;
|
|
13677
|
-
for (i = length; i-- !== 0;) if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
|
|
13678
|
-
for (i = length; i-- !== 0;) {
|
|
13679
|
-
var key = keys[i];
|
|
13680
|
-
if (!equal(a[key], b[key])) return false;
|
|
13681
|
-
}
|
|
13682
|
-
return true;
|
|
13683
|
-
}
|
|
13684
|
-
|
|
13685
|
-
// true if both NaN, false otherwise
|
|
13686
|
-
return a !== a && b !== b;
|
|
13687
|
-
};
|
|
13688
|
-
return fastDeepEqual;
|
|
13689
|
-
}
|
|
13690
|
-
|
|
13691
|
-
var fastDeepEqualExports = requireFastDeepEqual();
|
|
13692
|
-
var isEqual = /*@__PURE__*/getDefaultExportFromCjs(fastDeepEqualExports);
|
|
13693
|
-
|
|
13694
|
-
function getStatus(status, path) {
|
|
13695
|
-
const paths = Object.keys(status);
|
|
13696
|
-
if (typeof path === "string") {
|
|
13697
|
-
const nestedPaths = paths.filter((statusPath) => statusPath.startsWith(`${path}.`));
|
|
13698
|
-
return status[path] || nestedPaths.some((statusPath) => status[statusPath]) || false;
|
|
13699
|
-
}
|
|
13700
|
-
return paths.some((statusPath) => status[statusPath]);
|
|
13701
|
-
}
|
|
13702
|
-
|
|
13703
|
-
function useFormStatus({
|
|
13704
|
-
initialDirty,
|
|
13705
|
-
initialTouched,
|
|
13706
|
-
mode,
|
|
13707
|
-
$values
|
|
13708
|
-
}) {
|
|
13709
|
-
const [touchedState, setTouchedState] = useState(initialTouched);
|
|
13710
|
-
const [dirtyState, setDirtyState] = useState(initialDirty);
|
|
13711
|
-
const touchedRef = useRef(initialTouched);
|
|
13712
|
-
const dirtyRef = useRef(initialDirty);
|
|
13713
|
-
const setTouched = useCallback((values) => {
|
|
13714
|
-
const resolvedValues = typeof values === "function" ? values(touchedRef.current) : values;
|
|
13715
|
-
touchedRef.current = resolvedValues;
|
|
13716
|
-
if (mode === "controlled") {
|
|
13717
|
-
setTouchedState(resolvedValues);
|
|
13718
|
-
}
|
|
13719
|
-
}, []);
|
|
13720
|
-
const setDirty = useCallback(
|
|
13721
|
-
(values, forceUpdate = false) => {
|
|
13722
|
-
const resolvedValues = typeof values === "function" ? values(dirtyRef.current) : values;
|
|
13723
|
-
dirtyRef.current = resolvedValues;
|
|
13724
|
-
if (mode === "controlled" || forceUpdate) {
|
|
13725
|
-
setDirtyState(resolvedValues);
|
|
13726
|
-
}
|
|
13727
|
-
},
|
|
13728
|
-
[]
|
|
13729
|
-
);
|
|
13730
|
-
const resetTouched = useCallback(() => setTouched({}), []);
|
|
13731
|
-
const resetDirty = useCallback((values) => {
|
|
13732
|
-
const newSnapshot = values ? { ...$values.refValues.current, ...values } : $values.refValues.current;
|
|
13733
|
-
$values.setValuesSnapshot(newSnapshot);
|
|
13734
|
-
setDirty({});
|
|
13735
|
-
}, []);
|
|
13736
|
-
const setFieldTouched = useCallback((path, touched) => {
|
|
13737
|
-
setTouched((currentTouched) => {
|
|
13738
|
-
if (getStatus(currentTouched, path) === touched) {
|
|
13739
|
-
return currentTouched;
|
|
13740
|
-
}
|
|
13741
|
-
return { ...currentTouched, [path]: touched };
|
|
13742
|
-
});
|
|
13743
|
-
}, []);
|
|
13744
|
-
const setFieldDirty = useCallback((path, dirty, forceUpdate) => {
|
|
13745
|
-
setDirty((currentDirty) => {
|
|
13746
|
-
if (getStatus(currentDirty, path) === dirty) {
|
|
13747
|
-
return currentDirty;
|
|
13748
|
-
}
|
|
13749
|
-
return { ...currentDirty, [path]: dirty };
|
|
13750
|
-
}, forceUpdate);
|
|
13751
|
-
}, []);
|
|
13752
|
-
const setCalculatedFieldDirty = useCallback((path, value) => {
|
|
13753
|
-
const currentDirty = getStatus(dirtyRef.current, path);
|
|
13754
|
-
const dirty = !isEqual(getPath(path, $values.getValuesSnapshot()), value);
|
|
13755
|
-
const clearedState = clearListState(path, dirtyRef.current);
|
|
13756
|
-
clearedState[path] = dirty;
|
|
13757
|
-
setDirty(clearedState, currentDirty !== dirty);
|
|
13758
|
-
}, []);
|
|
13759
|
-
const isTouched = useCallback(
|
|
13760
|
-
(path) => getStatus(touchedRef.current, path),
|
|
13761
|
-
[]
|
|
13762
|
-
);
|
|
13763
|
-
const clearFieldDirty = useCallback(
|
|
13764
|
-
(path) => setDirty((current) => {
|
|
13765
|
-
if (typeof path !== "string") {
|
|
13766
|
-
return current;
|
|
13767
|
-
}
|
|
13768
|
-
const result = clearListState(path, current);
|
|
13769
|
-
delete result[path];
|
|
13770
|
-
if (isEqual(result, current)) {
|
|
13771
|
-
return current;
|
|
13772
|
-
}
|
|
13773
|
-
return result;
|
|
13774
|
-
}),
|
|
13775
|
-
[]
|
|
13776
|
-
);
|
|
13777
|
-
const isDirty = useCallback((path) => {
|
|
13778
|
-
if (path) {
|
|
13779
|
-
const overriddenValue = getPath(path, dirtyRef.current);
|
|
13780
|
-
if (typeof overriddenValue === "boolean") {
|
|
13781
|
-
return overriddenValue;
|
|
13782
|
-
}
|
|
13783
|
-
const sliceOfValues = getPath(path, $values.refValues.current);
|
|
13784
|
-
const sliceOfInitialValues = getPath(path, $values.valuesSnapshot.current);
|
|
13785
|
-
return !isEqual(sliceOfValues, sliceOfInitialValues);
|
|
13786
|
-
}
|
|
13787
|
-
const isOverridden = Object.keys(dirtyRef.current).length > 0;
|
|
13788
|
-
if (isOverridden) {
|
|
13789
|
-
return getStatus(dirtyRef.current);
|
|
13790
|
-
}
|
|
13791
|
-
return !isEqual($values.refValues.current, $values.valuesSnapshot.current);
|
|
13792
|
-
}, []);
|
|
13793
|
-
const getDirty = useCallback(() => dirtyRef.current, []);
|
|
13794
|
-
const getTouched = useCallback(() => touchedRef.current, []);
|
|
13795
|
-
return {
|
|
13796
|
-
touchedState,
|
|
13797
|
-
dirtyState,
|
|
13798
|
-
touchedRef,
|
|
13799
|
-
dirtyRef,
|
|
13800
|
-
setTouched,
|
|
13801
|
-
setDirty,
|
|
13802
|
-
resetDirty,
|
|
13803
|
-
resetTouched,
|
|
13804
|
-
isTouched,
|
|
13805
|
-
setFieldTouched,
|
|
13806
|
-
setFieldDirty,
|
|
13807
|
-
setTouchedState,
|
|
13808
|
-
setDirtyState,
|
|
13809
|
-
clearFieldDirty,
|
|
13810
|
-
isDirty,
|
|
13811
|
-
getDirty,
|
|
13812
|
-
getTouched,
|
|
13813
|
-
setCalculatedFieldDirty
|
|
13814
|
-
};
|
|
13815
|
-
}
|
|
13816
|
-
|
|
13817
|
-
function useFormValues({
|
|
13818
|
-
initialValues,
|
|
13819
|
-
onValuesChange,
|
|
13820
|
-
mode
|
|
13821
|
-
}) {
|
|
13822
|
-
const initialized = useRef(false);
|
|
13823
|
-
const [stateValues, setStateValues] = useState(initialValues || {});
|
|
13824
|
-
const refValues = useRef(stateValues);
|
|
13825
|
-
const valuesSnapshot = useRef(stateValues);
|
|
13826
|
-
const setValues = useCallback(
|
|
13827
|
-
({
|
|
13828
|
-
values,
|
|
13829
|
-
subscribers,
|
|
13830
|
-
updateState = true,
|
|
13831
|
-
mergeWithPreviousValues = true
|
|
13832
|
-
}) => {
|
|
13833
|
-
const previousValues = refValues.current;
|
|
13834
|
-
const resolvedValues = values instanceof Function ? values(refValues.current) : values;
|
|
13835
|
-
const updatedValues = mergeWithPreviousValues ? { ...previousValues, ...resolvedValues } : resolvedValues;
|
|
13836
|
-
refValues.current = updatedValues;
|
|
13837
|
-
if (updateState) {
|
|
13838
|
-
setStateValues(updatedValues);
|
|
13839
|
-
if (mode === "uncontrolled") {
|
|
13840
|
-
refValues.current = updatedValues;
|
|
13841
|
-
}
|
|
13842
|
-
}
|
|
13843
|
-
onValuesChange?.(updatedValues, previousValues);
|
|
13844
|
-
subscribers?.filter(Boolean).forEach((subscriber) => subscriber({ updatedValues, previousValues }));
|
|
13845
|
-
},
|
|
13846
|
-
[onValuesChange]
|
|
13847
|
-
);
|
|
13848
|
-
const setFieldValue = useCallback(
|
|
13849
|
-
(payload) => {
|
|
13850
|
-
const currentValue = getPath(payload.path, refValues.current);
|
|
13851
|
-
const updatedValue = payload.value instanceof Function ? payload.value(currentValue) : payload.value;
|
|
13852
|
-
if (currentValue !== updatedValue) {
|
|
13853
|
-
const previousValues = refValues.current;
|
|
13854
|
-
const updatedValues = setPath(payload.path, updatedValue, refValues.current);
|
|
13855
|
-
setValues({ values: updatedValues, updateState: payload.updateState });
|
|
13856
|
-
payload.subscribers?.filter(Boolean).forEach(
|
|
13857
|
-
(subscriber) => subscriber({ path: payload.path, updatedValues, previousValues })
|
|
13858
|
-
);
|
|
13859
|
-
}
|
|
13860
|
-
},
|
|
13861
|
-
[setValues]
|
|
13862
|
-
);
|
|
13863
|
-
const setValuesSnapshot = useCallback((payload) => {
|
|
13864
|
-
valuesSnapshot.current = payload;
|
|
13865
|
-
}, []);
|
|
13866
|
-
const initialize = useCallback(
|
|
13867
|
-
(values, onInitialize) => {
|
|
13868
|
-
if (!initialized.current) {
|
|
13869
|
-
initialized.current = true;
|
|
13870
|
-
setValues({ values, updateState: mode === "controlled" });
|
|
13871
|
-
setValuesSnapshot(values);
|
|
13872
|
-
onInitialize();
|
|
13873
|
-
}
|
|
13874
|
-
},
|
|
13875
|
-
[setValues]
|
|
13876
|
-
);
|
|
13877
|
-
const resetValues = useCallback(() => {
|
|
13878
|
-
setValues({
|
|
13879
|
-
values: valuesSnapshot.current,
|
|
13880
|
-
updateState: true,
|
|
13881
|
-
mergeWithPreviousValues: false
|
|
13882
|
-
});
|
|
13883
|
-
}, [setValues]);
|
|
13884
|
-
const getValues = useCallback(() => refValues.current, []);
|
|
13885
|
-
const getValuesSnapshot = useCallback(() => valuesSnapshot.current, []);
|
|
13886
|
-
const resetField = useCallback(
|
|
13887
|
-
(path, subscribers) => {
|
|
13888
|
-
const snapshotValue = getPath(path, valuesSnapshot.current);
|
|
13889
|
-
if (typeof snapshotValue === "undefined") {
|
|
13890
|
-
return;
|
|
13891
|
-
}
|
|
13892
|
-
setFieldValue({
|
|
13893
|
-
path,
|
|
13894
|
-
value: snapshotValue,
|
|
13895
|
-
updateState: mode === "controlled",
|
|
13896
|
-
subscribers
|
|
13897
|
-
});
|
|
13898
|
-
},
|
|
13899
|
-
[setFieldValue, mode]
|
|
13900
|
-
);
|
|
13901
|
-
return {
|
|
13902
|
-
initialized,
|
|
13903
|
-
stateValues,
|
|
13904
|
-
refValues,
|
|
13905
|
-
valuesSnapshot,
|
|
13906
|
-
setValues,
|
|
13907
|
-
setFieldValue,
|
|
13908
|
-
resetValues,
|
|
13909
|
-
setValuesSnapshot,
|
|
13910
|
-
initialize,
|
|
13911
|
-
getValues,
|
|
13912
|
-
getValuesSnapshot,
|
|
13913
|
-
resetField
|
|
13914
|
-
};
|
|
13915
|
-
}
|
|
13916
|
-
|
|
13917
|
-
function useFormWatch({
|
|
13918
|
-
$status,
|
|
13919
|
-
cascadeUpdates
|
|
13920
|
-
}) {
|
|
13921
|
-
const subscribers = useRef(
|
|
13922
|
-
{}
|
|
13923
|
-
);
|
|
13924
|
-
const watch = useCallback((path, callback) => {
|
|
13925
|
-
useEffect(() => {
|
|
13926
|
-
subscribers.current[path] = subscribers.current[path] || [];
|
|
13927
|
-
subscribers.current[path].push(callback);
|
|
13928
|
-
return () => {
|
|
13929
|
-
subscribers.current[path] = subscribers.current[path].filter((cb) => cb !== callback);
|
|
13930
|
-
};
|
|
13931
|
-
}, [callback]);
|
|
13932
|
-
}, []);
|
|
13933
|
-
const getFieldSubscribers = useCallback((path) => {
|
|
13934
|
-
const result = subscribers.current[path]?.map(
|
|
13935
|
-
(callback) => (input) => callback({
|
|
13936
|
-
previousValue: getPath(path, input.previousValues),
|
|
13937
|
-
value: getPath(path, input.updatedValues),
|
|
13938
|
-
touched: $status.isTouched(path),
|
|
13939
|
-
dirty: $status.isDirty(path)
|
|
13940
|
-
})
|
|
13941
|
-
) ?? [];
|
|
13942
|
-
if (cascadeUpdates) {
|
|
13943
|
-
for (const subscriptionKey in subscribers.current) {
|
|
13944
|
-
if (subscriptionKey.startsWith(`${path}.`) || path.startsWith(`${subscriptionKey}.`)) {
|
|
13945
|
-
result.push(
|
|
13946
|
-
...subscribers.current[subscriptionKey].map(
|
|
13947
|
-
(cb) => (input) => cb({
|
|
13948
|
-
previousValue: getPath(subscriptionKey, input.previousValues),
|
|
13949
|
-
value: getPath(subscriptionKey, input.updatedValues),
|
|
13950
|
-
touched: $status.isTouched(subscriptionKey),
|
|
13951
|
-
dirty: $status.isDirty(subscriptionKey)
|
|
13952
|
-
})
|
|
13953
|
-
)
|
|
13954
|
-
);
|
|
13955
|
-
}
|
|
13956
|
-
}
|
|
13957
|
-
}
|
|
13958
|
-
return result;
|
|
13959
|
-
}, []);
|
|
13960
|
-
return {
|
|
13961
|
-
subscribers,
|
|
13962
|
-
watch,
|
|
13963
|
-
getFieldSubscribers
|
|
13964
|
-
};
|
|
13965
|
-
}
|
|
13966
|
-
|
|
13967
|
-
function getDataPath(formName, fieldPath) {
|
|
13968
|
-
return formName ? `${formName}-${fieldPath.toString()}` : fieldPath.toString();
|
|
13969
|
-
}
|
|
13970
|
-
|
|
13971
|
-
const formRootRule = Symbol("root-rule");
|
|
13972
|
-
function getValidationResults(errors) {
|
|
13973
|
-
const filteredErrors = filterErrors(errors);
|
|
13974
|
-
return { hasErrors: Object.keys(filteredErrors).length > 0, errors: filteredErrors };
|
|
13975
|
-
}
|
|
13976
|
-
function validateRulesRecord(rules, values, path = "", errors = {}) {
|
|
13977
|
-
if (typeof rules !== "object" || rules === null) {
|
|
13978
|
-
return errors;
|
|
13979
|
-
}
|
|
13980
|
-
return Object.keys(rules).reduce((acc, ruleKey) => {
|
|
13981
|
-
const rule = rules[ruleKey];
|
|
13982
|
-
const rulePath = `${path === "" ? "" : `${path}.`}${ruleKey}`;
|
|
13983
|
-
const value = getPath(rulePath, values);
|
|
13984
|
-
let arrayValidation = false;
|
|
13985
|
-
if (typeof rule === "function") {
|
|
13986
|
-
acc[rulePath] = rule(value, values, rulePath);
|
|
13987
|
-
}
|
|
13988
|
-
if (typeof rule === "object" && Array.isArray(value)) {
|
|
13989
|
-
arrayValidation = true;
|
|
13990
|
-
value.forEach(
|
|
13991
|
-
(_item, index) => validateRulesRecord(rule, values, `${rulePath}.${index}`, acc)
|
|
13992
|
-
);
|
|
13993
|
-
if (formRootRule in rule) {
|
|
13994
|
-
acc[rulePath] = rule[formRootRule](value, values, rulePath);
|
|
13995
|
-
}
|
|
13996
|
-
}
|
|
13997
|
-
if (typeof rule === "object" && typeof value === "object" && value !== null) {
|
|
13998
|
-
if (!arrayValidation) {
|
|
13999
|
-
validateRulesRecord(rule, values, rulePath, acc);
|
|
14000
|
-
}
|
|
14001
|
-
if (formRootRule in rule) {
|
|
14002
|
-
acc[rulePath] = rule[formRootRule](value, values, rulePath);
|
|
14003
|
-
}
|
|
14004
|
-
}
|
|
14005
|
-
return acc;
|
|
14006
|
-
}, errors);
|
|
14007
|
-
}
|
|
14008
|
-
function validateValues(validate, values) {
|
|
14009
|
-
if (typeof validate === "function") {
|
|
14010
|
-
return getValidationResults(validate(values));
|
|
14011
|
-
}
|
|
14012
|
-
return getValidationResults(validateRulesRecord(validate, values));
|
|
14013
|
-
}
|
|
14014
|
-
|
|
14015
|
-
function validateFieldValue(path, rules, values) {
|
|
14016
|
-
if (typeof path !== "string") {
|
|
14017
|
-
return { hasError: false, error: null };
|
|
14018
|
-
}
|
|
14019
|
-
const results = validateValues(rules, values);
|
|
14020
|
-
const pathInError = Object.keys(results.errors).find(
|
|
14021
|
-
(errorKey) => path.split(".").every((pathPart, i) => pathPart === errorKey.split(".")[i])
|
|
14022
|
-
);
|
|
14023
|
-
return { hasError: !!pathInError, error: pathInError ? results.errors[pathInError] : null };
|
|
14024
|
-
}
|
|
14025
|
-
|
|
14026
|
-
const FORM_INDEX = "__MANTINE_FORM_INDEX__";
|
|
14027
|
-
|
|
14028
|
-
function shouldValidateOnChange(path, validateInputOnChange) {
|
|
14029
|
-
if (!validateInputOnChange) {
|
|
14030
|
-
return false;
|
|
14031
|
-
}
|
|
14032
|
-
if (typeof validateInputOnChange === "boolean") {
|
|
14033
|
-
return validateInputOnChange;
|
|
14034
|
-
}
|
|
14035
|
-
if (Array.isArray(validateInputOnChange)) {
|
|
14036
|
-
return validateInputOnChange.includes(path.replace(/[.][0-9]+/g, `.${FORM_INDEX}`));
|
|
14037
|
-
}
|
|
14038
|
-
return false;
|
|
14039
|
-
}
|
|
14040
|
-
|
|
14041
|
-
function useForm({
|
|
14042
|
-
name,
|
|
14043
|
-
mode = "controlled",
|
|
14044
|
-
initialValues,
|
|
14045
|
-
initialErrors = {},
|
|
14046
|
-
initialDirty = {},
|
|
14047
|
-
initialTouched = {},
|
|
14048
|
-
clearInputErrorOnChange = true,
|
|
14049
|
-
validateInputOnChange = false,
|
|
14050
|
-
validateInputOnBlur = false,
|
|
14051
|
-
onValuesChange,
|
|
14052
|
-
transformValues = (values) => values,
|
|
14053
|
-
enhanceGetInputProps,
|
|
14054
|
-
validate: rules,
|
|
14055
|
-
onSubmitPreventDefault = "always",
|
|
14056
|
-
touchTrigger = "change",
|
|
14057
|
-
cascadeUpdates = false
|
|
14058
|
-
} = {}) {
|
|
14059
|
-
const $errors = useFormErrors(initialErrors);
|
|
14060
|
-
const $values = useFormValues({ initialValues, onValuesChange, mode });
|
|
14061
|
-
const $status = useFormStatus({ initialDirty, initialTouched, $values, mode });
|
|
14062
|
-
const $list = useFormList({ $values, $errors, $status });
|
|
14063
|
-
const $watch = useFormWatch({ $status, cascadeUpdates });
|
|
14064
|
-
const [formKey, setFormKey] = useState(0);
|
|
14065
|
-
const [fieldKeys, setFieldKeys] = useState({});
|
|
14066
|
-
const [submitting, setSubmitting] = useState(false);
|
|
14067
|
-
const reset = useCallback(() => {
|
|
14068
|
-
$values.resetValues();
|
|
14069
|
-
$errors.clearErrors();
|
|
14070
|
-
$status.resetDirty();
|
|
14071
|
-
$status.resetTouched();
|
|
14072
|
-
mode === "uncontrolled" && setFormKey((key2) => key2 + 1);
|
|
14073
|
-
}, []);
|
|
14074
|
-
const handleValuesChanges = useCallback(
|
|
14075
|
-
(previousValues) => {
|
|
14076
|
-
clearInputErrorOnChange && $errors.clearErrors();
|
|
14077
|
-
mode === "uncontrolled" && setFormKey((key2) => key2 + 1);
|
|
14078
|
-
Object.keys($watch.subscribers.current).forEach((path) => {
|
|
14079
|
-
const value = getPath(path, $values.refValues.current);
|
|
14080
|
-
const previousValue = getPath(path, previousValues);
|
|
14081
|
-
if (value !== previousValue) {
|
|
14082
|
-
$watch.getFieldSubscribers(path).forEach((cb) => cb({ previousValues, updatedValues: $values.refValues.current }));
|
|
14083
|
-
}
|
|
14084
|
-
});
|
|
14085
|
-
},
|
|
14086
|
-
[clearInputErrorOnChange]
|
|
14087
|
-
);
|
|
14088
|
-
const initialize = useCallback(
|
|
14089
|
-
(values) => {
|
|
14090
|
-
const previousValues = $values.refValues.current;
|
|
14091
|
-
$values.initialize(values, () => mode === "uncontrolled" && setFormKey((key2) => key2 + 1));
|
|
14092
|
-
handleValuesChanges(previousValues);
|
|
14093
|
-
},
|
|
14094
|
-
[handleValuesChanges]
|
|
14095
|
-
);
|
|
14096
|
-
const setFieldValue = useCallback(
|
|
14097
|
-
(path, value, options) => {
|
|
14098
|
-
const shouldValidate = shouldValidateOnChange(path, validateInputOnChange);
|
|
14099
|
-
const resolvedValue = value instanceof Function ? value(getPath(path, $values.refValues.current)) : value;
|
|
14100
|
-
$status.setCalculatedFieldDirty(path, resolvedValue);
|
|
14101
|
-
touchTrigger === "change" && $status.setFieldTouched(path, true);
|
|
14102
|
-
!shouldValidate && clearInputErrorOnChange && $errors.clearFieldError(path);
|
|
14103
|
-
$values.setFieldValue({
|
|
14104
|
-
path,
|
|
14105
|
-
value,
|
|
14106
|
-
updateState: mode === "controlled",
|
|
14107
|
-
subscribers: [
|
|
14108
|
-
...$watch.getFieldSubscribers(path),
|
|
14109
|
-
shouldValidate ? (payload) => {
|
|
14110
|
-
const validationResults = validateFieldValue(path, rules, payload.updatedValues);
|
|
14111
|
-
validationResults.hasError ? $errors.setFieldError(path, validationResults.error) : $errors.clearFieldError(path);
|
|
14112
|
-
} : null,
|
|
14113
|
-
options?.forceUpdate !== false && mode !== "controlled" ? () => setFieldKeys((keys) => ({
|
|
14114
|
-
...keys,
|
|
14115
|
-
[path]: (keys[path] || 0) + 1
|
|
14116
|
-
})) : null
|
|
14117
|
-
]
|
|
14118
|
-
});
|
|
14119
|
-
},
|
|
14120
|
-
[onValuesChange, rules]
|
|
14121
|
-
);
|
|
14122
|
-
const setValues = useCallback(
|
|
14123
|
-
(values) => {
|
|
14124
|
-
const previousValues = $values.refValues.current;
|
|
14125
|
-
$values.setValues({ values, updateState: mode === "controlled" });
|
|
14126
|
-
handleValuesChanges(previousValues);
|
|
14127
|
-
},
|
|
14128
|
-
[onValuesChange, handleValuesChanges]
|
|
14129
|
-
);
|
|
14130
|
-
const validate = useCallback(() => {
|
|
14131
|
-
const results = validateValues(rules, $values.refValues.current);
|
|
14132
|
-
$errors.setErrors(results.errors);
|
|
14133
|
-
return results;
|
|
14134
|
-
}, [rules]);
|
|
14135
|
-
const validateField = useCallback(
|
|
14136
|
-
(path) => {
|
|
14137
|
-
const results = validateFieldValue(path, rules, $values.refValues.current);
|
|
14138
|
-
results.hasError ? $errors.setFieldError(path, results.error) : $errors.clearFieldError(path);
|
|
14139
|
-
return results;
|
|
14140
|
-
},
|
|
14141
|
-
[rules]
|
|
14142
|
-
);
|
|
14143
|
-
const getInputProps = (path, { type = "input", withError = true, withFocus = true, ...otherOptions } = {}) => {
|
|
14144
|
-
const onChange = getInputOnChange(
|
|
14145
|
-
(value) => setFieldValue(path, value, { forceUpdate: false })
|
|
14146
|
-
);
|
|
14147
|
-
const payload = { onChange, "data-path": getDataPath(name, path) };
|
|
14148
|
-
if (withError) {
|
|
14149
|
-
payload.error = $errors.errorsState[path];
|
|
14150
|
-
}
|
|
14151
|
-
if (type === "checkbox") {
|
|
14152
|
-
payload[mode === "controlled" ? "checked" : "defaultChecked"] = getPath(
|
|
14153
|
-
path,
|
|
14154
|
-
$values.refValues.current
|
|
14155
|
-
);
|
|
14156
|
-
} else {
|
|
14157
|
-
payload[mode === "controlled" ? "value" : "defaultValue"] = getPath(
|
|
14158
|
-
path,
|
|
14159
|
-
$values.refValues.current
|
|
14160
|
-
);
|
|
14161
|
-
}
|
|
14162
|
-
if (withFocus) {
|
|
14163
|
-
payload.onFocus = () => $status.setFieldTouched(path, true);
|
|
14164
|
-
payload.onBlur = () => {
|
|
14165
|
-
if (shouldValidateOnChange(path, validateInputOnBlur)) {
|
|
14166
|
-
const validationResults = validateFieldValue(path, rules, $values.refValues.current);
|
|
14167
|
-
validationResults.hasError ? $errors.setFieldError(path, validationResults.error) : $errors.clearFieldError(path);
|
|
14168
|
-
}
|
|
14169
|
-
};
|
|
14170
|
-
}
|
|
14171
|
-
return Object.assign(
|
|
14172
|
-
payload,
|
|
14173
|
-
enhanceGetInputProps?.({
|
|
14174
|
-
inputProps: payload,
|
|
14175
|
-
field: path,
|
|
14176
|
-
options: { type, withError, withFocus, ...otherOptions },
|
|
14177
|
-
form
|
|
14178
|
-
})
|
|
14179
|
-
);
|
|
14180
|
-
};
|
|
14181
|
-
const onSubmit = (handleSubmit, handleValidationFailure) => (event) => {
|
|
14182
|
-
if (onSubmitPreventDefault === "always") {
|
|
14183
|
-
event?.preventDefault();
|
|
14184
|
-
}
|
|
14185
|
-
const results = validate();
|
|
14186
|
-
if (results.hasErrors) {
|
|
14187
|
-
if (onSubmitPreventDefault === "validation-failed") {
|
|
14188
|
-
event?.preventDefault();
|
|
14189
|
-
}
|
|
14190
|
-
handleValidationFailure?.(results.errors, $values.refValues.current, event);
|
|
14191
|
-
} else {
|
|
14192
|
-
const submitResult = handleSubmit?.(
|
|
14193
|
-
transformValues($values.refValues.current),
|
|
14194
|
-
event
|
|
14195
|
-
);
|
|
14196
|
-
if (submitResult instanceof Promise) {
|
|
14197
|
-
setSubmitting(true);
|
|
14198
|
-
submitResult.finally(() => setSubmitting(false));
|
|
14199
|
-
}
|
|
14200
|
-
}
|
|
14201
|
-
};
|
|
14202
|
-
const getTransformedValues = (input) => transformValues(input || $values.refValues.current);
|
|
14203
|
-
const onReset = useCallback((event) => {
|
|
14204
|
-
event.preventDefault();
|
|
14205
|
-
reset();
|
|
14206
|
-
}, []);
|
|
14207
|
-
const isValid = useCallback(
|
|
14208
|
-
(path) => path ? !validateFieldValue(path, rules, $values.refValues.current).hasError : !validateValues(rules, $values.refValues.current).hasErrors,
|
|
14209
|
-
[rules]
|
|
14210
|
-
);
|
|
14211
|
-
const key = (path) => `${formKey}-${String(path)}-${fieldKeys[String(path)] || 0}`;
|
|
14212
|
-
const getInputNode = useCallback(
|
|
14213
|
-
(path) => document.querySelector(`[data-path="${getDataPath(name, path)}"]`),
|
|
14214
|
-
[]
|
|
14215
|
-
);
|
|
14216
|
-
const resetField = useCallback(
|
|
14217
|
-
(path) => {
|
|
14218
|
-
$values.resetField(path, [
|
|
14219
|
-
mode !== "controlled" ? () => setFieldKeys((keys) => ({
|
|
14220
|
-
...keys,
|
|
14221
|
-
[path]: (keys[path] || 0) + 1
|
|
14222
|
-
})) : null
|
|
14223
|
-
]);
|
|
14224
|
-
},
|
|
14225
|
-
[$values.resetField, mode, setFieldKeys]
|
|
14226
|
-
);
|
|
14227
|
-
const form = {
|
|
14228
|
-
watch: $watch.watch,
|
|
14229
|
-
initialized: $values.initialized.current,
|
|
14230
|
-
values: mode === "uncontrolled" ? $values.refValues.current : $values.stateValues,
|
|
14231
|
-
getValues: $values.getValues,
|
|
14232
|
-
getInitialValues: $values.getValuesSnapshot,
|
|
14233
|
-
setInitialValues: $values.setValuesSnapshot,
|
|
14234
|
-
resetField,
|
|
14235
|
-
initialize,
|
|
14236
|
-
setValues,
|
|
14237
|
-
setFieldValue,
|
|
14238
|
-
submitting,
|
|
14239
|
-
setSubmitting,
|
|
14240
|
-
errors: $errors.errorsState,
|
|
14241
|
-
setErrors: $errors.setErrors,
|
|
14242
|
-
setFieldError: $errors.setFieldError,
|
|
14243
|
-
clearFieldError: $errors.clearFieldError,
|
|
14244
|
-
clearErrors: $errors.clearErrors,
|
|
14245
|
-
resetDirty: $status.resetDirty,
|
|
14246
|
-
setTouched: $status.setTouched,
|
|
14247
|
-
setDirty: $status.setDirty,
|
|
14248
|
-
isTouched: $status.isTouched,
|
|
14249
|
-
resetTouched: $status.resetTouched,
|
|
14250
|
-
isDirty: $status.isDirty,
|
|
14251
|
-
getTouched: $status.getTouched,
|
|
14252
|
-
getDirty: $status.getDirty,
|
|
14253
|
-
reorderListItem: $list.reorderListItem,
|
|
14254
|
-
insertListItem: $list.insertListItem,
|
|
14255
|
-
removeListItem: $list.removeListItem,
|
|
14256
|
-
replaceListItem: $list.replaceListItem,
|
|
14257
|
-
reset,
|
|
14258
|
-
validate,
|
|
14259
|
-
validateField,
|
|
14260
|
-
getInputProps,
|
|
14261
|
-
onSubmit,
|
|
14262
|
-
onReset,
|
|
14263
|
-
isValid,
|
|
14264
|
-
getTransformedValues,
|
|
14265
|
-
key,
|
|
14266
|
-
getInputNode
|
|
14267
|
-
};
|
|
14268
|
-
useFormActions(name, form);
|
|
14269
|
-
return form;
|
|
14270
|
-
}
|
|
14271
|
-
|
|
14272
13230
|
const _excluded$1 = ["fields", "isEditable", "layout", "hasSubmit", "hasReset"];
|
|
14273
13231
|
function ownKeys$1(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
14274
13232
|
function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$1(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$1(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
@@ -14448,7 +13406,8 @@ const MaskedTilePanel = _ref => {
|
|
|
14448
13406
|
justify: "space-between"
|
|
14449
13407
|
}, /*#__PURE__*/React.createElement(Stack, {
|
|
14450
13408
|
gap: 0,
|
|
14451
|
-
p: 0
|
|
13409
|
+
p: 0,
|
|
13410
|
+
flex: 1
|
|
14452
13411
|
}, /*#__PURE__*/React.createElement(Text, {
|
|
14453
13412
|
fz: "sm",
|
|
14454
13413
|
fw: 300,
|
|
@@ -14486,7 +13445,8 @@ const TilePanel = _ref2 => {
|
|
|
14486
13445
|
justify: "space-between"
|
|
14487
13446
|
}, /*#__PURE__*/React.createElement(Stack, {
|
|
14488
13447
|
gap: 0,
|
|
14489
|
-
p: 0
|
|
13448
|
+
p: 0,
|
|
13449
|
+
flex: 1
|
|
14490
13450
|
}, /*#__PURE__*/React.createElement(Text, {
|
|
14491
13451
|
fz: "sm",
|
|
14492
13452
|
fw: 300,
|