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