@apia/validations 4.0.58 → 4.0.63

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.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import { jsx, jsxs } from '@apia/theme/jsx-runtime';
2
- import { customEvents, usePropsSelector, propsStore, getLabel, useUnmount, useMount, PropsSelectorUndefinedObject, formatMessage, toBoolean, EventEmitter, StatefulEmitter, useSubscription, getValueByPath } from '@apia/util';
2
+ import { customEvents, usePropsSelector, propsStore, getLabel, useUnmount, useMount, PropsSelectorUndefinedObject, formatMessage, EventEmitter, StatefulEmitter, useSubscription, getLabelTooltip, getLabelName, getValueByPath } from '@apia/util';
3
3
  import uniqueId from 'lodash-es/uniqueId';
4
- import React, { useState, createContext, useContext } from 'react';
4
+ import React, { useRef, useState, createContext, useContext } from 'react';
5
5
  import { Box, getVariant, Input as Input$1, Label, Radio as Radio$1, Select as Select$1, Switch, Textarea as Textarea$1, Button } from '@apia/theme';
6
6
  import { notify } from '@apia/notifications';
7
- import { RequiredMark, Captcha, Checkbox as Checkbox$1, IconButton, getFieldErrorStyles, DateInput, ApiaUtil, NumberInput, SimpleButton, useModalContext, FieldLabel } from '@apia/components';
7
+ import { RequiredMark, Captcha, Checkbox as Checkbox$1, IconButton, getFieldErrorStyles, DateInput, ApiaUtil, NumberInput, SimpleButton, AutogrowTextarea as AutogrowTextarea$1, SwitchMultiple, useModalContext, FieldLabel } from '@apia/components';
8
8
  import { shallowEqual } from 'react-redux';
9
- import { makeObservable, observable } from 'mobx';
10
9
  import { observer } from 'mobx-react-lite';
10
+ import { makeObservable, observable } from 'mobx';
11
11
 
12
12
  const FormContext = React.createContext(
13
13
  {}
@@ -234,20 +234,20 @@ function getValidations(outerValidation) {
234
234
  };
235
235
  }
236
236
 
237
- var __defProp$a = Object.defineProperty;
238
- var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
239
- var __publicField$a = (obj, key, value) => {
240
- __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
237
+ var __defProp$f = Object.defineProperty;
238
+ var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
239
+ var __publicField$f = (obj, key, value) => {
240
+ __defNormalProp$f(obj, typeof key !== "symbol" ? key + "" : key, value);
241
241
  return value;
242
242
  };
243
243
  const validationsStore = new class {
244
244
  constructor() {
245
- __publicField$a(this, "activeForms", []);
246
- __publicField$a(this, "timeouts", {});
247
- __publicField$a(this, "existsField", (formName, fieldName) => {
245
+ __publicField$f(this, "activeForms", []);
246
+ __publicField$f(this, "timeouts", {});
247
+ __publicField$f(this, "existsField", (formName, fieldName) => {
248
248
  return !!this.getFormStore(formName)?.fields?.includes(fieldName);
249
249
  });
250
- __publicField$a(this, "registerField", (formName, registerData, options = { registerIfExists: true }) => {
250
+ __publicField$f(this, "registerField", (formName, registerData, options = { registerIfExists: true }) => {
251
251
  const formProps = this.getFormStore(formName);
252
252
  if (formProps === void 0)
253
253
  this.registerForm(formName);
@@ -259,7 +259,7 @@ const validationsStore = new class {
259
259
  ]
260
260
  });
261
261
  const existsInStore = this.getFieldStore(formName, registerData.name);
262
- if ((formProps?.avoidFieldsOverride || !options.registerIfExists) && existsInStore) {
262
+ if (!existsInStore || options.registerIfExists || !formProps?.avoidFieldsOverride && existsInStore && options.registerIfExists !== false) {
263
263
  const { value, ...updateData } = registerData;
264
264
  this.updateField(formName, updateData, {
265
265
  markFormAsTouched: false,
@@ -267,17 +267,11 @@ const validationsStore = new class {
267
267
  });
268
268
  return;
269
269
  }
270
- this.updateFieldStore(
271
- formName,
272
- registerData.name,
273
- registerData,
274
- options.avoidPropagation
275
- );
276
270
  });
277
271
  /**
278
272
  * Inicializa el estado de un nuevo formulario
279
273
  */
280
- __publicField$a(this, "registerForm", (formName, props = { avoidFieldsOverride: false }) => {
274
+ __publicField$f(this, "registerForm", (formName, props = { avoidFieldsOverride: false }) => {
281
275
  props.persistToSessionStorage && this.loadFromSessionStorage(formName);
282
276
  if (this.activeForms.includes(formName)) {
283
277
  this.updateFormStore(
@@ -323,7 +317,7 @@ const validationsStore = new class {
323
317
  * Setea el valor del campo con el nombre provisto. Si el campo no existe
324
318
  * en el formulario lo crea.
325
319
  */
326
- __publicField$a(this, "setFieldValue", (formName, fieldName, newValue, options) => {
320
+ __publicField$f(this, "setFieldValue", (formName, fieldName, newValue, options) => {
327
321
  if (!this.getFieldStore(formName, fieldName))
328
322
  this.registerField(formName, { name: fieldName, value: newValue });
329
323
  else
@@ -339,7 +333,7 @@ const validationsStore = new class {
339
333
  if (this.getFormStore(formName).isValid)
340
334
  this.updateFormStore(formName, { isValid: false });
341
335
  });
342
- __publicField$a(this, "setFormIsTouched", (formName, isTouched = true) => {
336
+ __publicField$f(this, "setFormIsTouched", (formName, isTouched = true) => {
343
337
  this.updateFormStore(formName, { isTouched }, true);
344
338
  });
345
339
  /**
@@ -347,7 +341,7 @@ const validationsStore = new class {
347
341
  * forma cualquier validación que pudiera aplicarse sobre el mismo, ya no se
348
342
  * aplicará.
349
343
  */
350
- __publicField$a(this, "unregisterField", (formName, fieldName) => {
344
+ __publicField$f(this, "unregisterField", (formName, fieldName) => {
351
345
  if (this.getFormStore(formName))
352
346
  this.updateFormStore(formName, {
353
347
  fields: this.getFormStore(formName).fields.filter((current) => {
@@ -360,7 +354,7 @@ const validationsStore = new class {
360
354
  * Elimina un formulario del store de validación junto con todos los campos
361
355
  * asociados al mismo.
362
356
  */
363
- __publicField$a(this, "unregisterForm", (formName) => {
357
+ __publicField$f(this, "unregisterForm", (formName) => {
364
358
  this.getFormStore(formName)?.fields?.forEach((current) => {
365
359
  return propsStore.removeField(this.makeFieldName(formName, current));
366
360
  });
@@ -374,7 +368,7 @@ const validationsStore = new class {
374
368
  * Actualiza las propiedades de un campo, si no existe, lo registra en el
375
369
  * formulario.
376
370
  */
377
- __publicField$a(this, "updateField", (formName, field, options) => {
371
+ __publicField$f(this, "updateField", (formName, field, options) => {
378
372
  const previousValue = this.getFieldStore(formName, field.name)?.value;
379
373
  if (this.getFormStore(formName))
380
374
  this.updateFormStore(formName, { isValid: false }, true);
@@ -402,7 +396,7 @@ const validationsStore = new class {
402
396
  /**
403
397
  * Actualiza múltiples campos al mismo tiempo.
404
398
  */
405
- __publicField$a(this, "updateMultipleFields", (formName, fields, options) => {
399
+ __publicField$f(this, "updateMultipleFields", (formName, fields, options) => {
406
400
  fields.forEach((current) => {
407
401
  return this.updateField(formName, current, options);
408
402
  });
@@ -431,7 +425,7 @@ const validationsStore = new class {
431
425
  * console.error('Validation error', result);
432
426
  * }
433
427
  */
434
- __publicField$a(this, "validateForm", async (formName) => {
428
+ __publicField$f(this, "validateForm", async (formName) => {
435
429
  const state = this.getFormStore(formName);
436
430
  if (!state)
437
431
  return { errors: { form: "No form with name " + formName } };
@@ -709,7 +703,7 @@ function useField(fieldDefinition) {
709
703
  }
710
704
  );
711
705
  const [localValue, setLocalValue] = React.useState(
712
- fieldDefinition.initialValue
706
+ storeValue ?? fieldDefinition.initialValue
713
707
  );
714
708
  React.useEffect(() => {
715
709
  setLocalValue(storeValue);
@@ -1015,6 +1009,7 @@ const Checkbox = React.forwardRef(
1015
1009
  label,
1016
1010
  className: `checkbox ${className ?? ""}`,
1017
1011
  avoidSemicolon,
1012
+ title: props.title,
1018
1013
  children: /* @__PURE__ */ jsx(
1019
1014
  Checkbox$1,
1020
1015
  {
@@ -1106,6 +1101,7 @@ const DeletableInput = React.forwardRef(
1106
1101
  ),
1107
1102
  className: `deletableInput ${className ?? ""}`,
1108
1103
  avoidSemicolon,
1104
+ title: props.title,
1109
1105
  children: [
1110
1106
  /* @__PURE__ */ jsx(
1111
1107
  Input$1,
@@ -1188,6 +1184,7 @@ const FileInput = React.memo(
1188
1184
  label,
1189
1185
  className: `input ${className ?? ""}`,
1190
1186
  avoidSemicolon,
1187
+ title: props.title,
1191
1188
  children: /* @__PURE__ */ jsx(
1192
1189
  Input$1,
1193
1190
  {
@@ -1280,6 +1277,7 @@ const Input = React.memo(
1280
1277
  label,
1281
1278
  className: `input ${className ?? ""}`,
1282
1279
  avoidSemicolon,
1280
+ title: props.title,
1283
1281
  children: type === "date" ? /* @__PURE__ */ jsx(
1284
1282
  DateInput,
1285
1283
  {
@@ -1398,6 +1396,7 @@ const NumberInputf = React.memo(
1398
1396
  ),
1399
1397
  className: `input ${className ?? ""}`,
1400
1398
  avoidSemicolon,
1399
+ title: props.title,
1401
1400
  children: /* @__PURE__ */ jsx(
1402
1401
  NumberInput,
1403
1402
  {
@@ -1471,6 +1470,7 @@ const Radio = React.forwardRef(
1471
1470
  className: `radio ${className ?? ""}`,
1472
1471
  avoidSemicolon,
1473
1472
  as: "ul",
1473
+ title: props.title,
1474
1474
  children: options?.map((option) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs(Label, { title: option.label, className: "radio-label", children: [
1475
1475
  /* @__PURE__ */ jsx(
1476
1476
  Radio$1,
@@ -1540,6 +1540,7 @@ const Select = React.forwardRef(
1540
1540
  label,
1541
1541
  className: `select ${className ?? ""}`,
1542
1542
  avoidSemicolon,
1543
+ title: props.title,
1543
1544
  children: /* @__PURE__ */ jsxs(
1544
1545
  Select$1,
1545
1546
  {
@@ -1584,7 +1585,6 @@ const Switchbox = React.forwardRef(
1584
1585
  label,
1585
1586
  onChange: outerOnChange,
1586
1587
  type,
1587
- reverse = false,
1588
1588
  avoidRegisterIfExists,
1589
1589
  formName,
1590
1590
  initialValue,
@@ -1604,23 +1604,31 @@ const Switchbox = React.forwardRef(
1604
1604
  validationFunction,
1605
1605
  validationRules
1606
1606
  });
1607
- const { onChange, updateValidations, isTouched, ...inputProps } = useField({
1607
+ const {
1608
+ value: innerValue,
1609
+ onChange,
1610
+ updateValidations,
1611
+ isTouched,
1612
+ ...inputProps
1613
+ } = useField({
1608
1614
  avoidRegisterIfExists,
1609
1615
  formName,
1610
1616
  name,
1611
- initialValue: (initialValue ?? "off") === "on" || toBoolean(initialValue) ? "on" : "off",
1617
+ initialValue,
1612
1618
  removeOnUnmount,
1613
1619
  submitValueParser,
1614
1620
  validationFunction: actualValidationFunction,
1615
1621
  validationRules: actualValidationRules
1616
1622
  });
1623
+ const putValue = useRef(false);
1617
1624
  return /* @__PURE__ */ jsx(
1618
1625
  FieldWrapper,
1619
1626
  {
1620
1627
  name,
1621
1628
  label,
1622
- className: `switchbox ${className ?? ""}`,
1629
+ className: `checkbox ${className ?? ""}`,
1623
1630
  avoidSemicolon,
1631
+ title: props.title,
1624
1632
  children: /* @__PURE__ */ jsx(
1625
1633
  Switch,
1626
1634
  {
@@ -1628,13 +1636,21 @@ const Switchbox = React.forwardRef(
1628
1636
  ...inputProps,
1629
1637
  "aria-label": props["aria-label"] ?? label,
1630
1638
  onChange: (ev) => {
1631
- onChange(ev.target.checked !== reverse ? "on" : "off");
1639
+ onChange(ev.target.checked);
1632
1640
  if (outerOnChange) {
1633
1641
  outerOnChange(ev);
1634
1642
  }
1635
1643
  },
1636
- checked: (inputProps.value ?? "off") === "on" !== reverse,
1637
- ref
1644
+ value: innerValue ? "on" : "off",
1645
+ ref: (el) => {
1646
+ ref?.(el);
1647
+ if (el && putValue.current !== innerValue) {
1648
+ putValue.current = innerValue;
1649
+ if (innerValue !== void 0 && innerValue !== null && putValue.current !== el.checked) {
1650
+ el.click();
1651
+ }
1652
+ }
1653
+ }
1638
1654
  }
1639
1655
  )
1640
1656
  }
@@ -1697,6 +1713,7 @@ const Textarea = React.forwardRef(
1697
1713
  label,
1698
1714
  className: `textarea ${className ?? ""}`,
1699
1715
  avoidSemicolon,
1716
+ title: props.title,
1700
1717
  children: /* @__PURE__ */ jsx(
1701
1718
  Textarea$1,
1702
1719
  {
@@ -1714,10 +1731,10 @@ const Textarea = React.forwardRef(
1714
1731
  );
1715
1732
  Textarea.displayName = "Textarea";
1716
1733
 
1717
- var __defProp$9 = Object.defineProperty;
1718
- var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1719
- var __publicField$9 = (obj, key, value) => {
1720
- __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
1734
+ var __defProp$e = Object.defineProperty;
1735
+ var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1736
+ var __publicField$e = (obj, key, value) => {
1737
+ __defNormalProp$e(obj, typeof key !== "symbol" ? key + "" : key, value);
1721
1738
  return value;
1722
1739
  };
1723
1740
  var __accessCheck$2 = (obj, member, msg) => {
@@ -1742,17 +1759,17 @@ class CollectorField extends EventEmitter {
1742
1759
  __privateAdd$2(this, _emitter, new StatefulEmitter({
1743
1760
  isHidden: false
1744
1761
  }));
1745
- __publicField$9(this, "collector", {});
1746
- __publicField$9(this, "isHidden", () => __privateGet$2(this, _emitter).getState("isHidden"));
1747
- __publicField$9(this, "setIsHidden", (isHidden) => {
1762
+ __publicField$e(this, "_collector", {});
1763
+ __publicField$e(this, "isHidden", () => __privateGet$2(this, _emitter).getState("isHidden"));
1764
+ __publicField$e(this, "setIsHidden", (isHidden) => {
1748
1765
  __privateGet$2(this, _emitter).emit("isHidden", isHidden);
1749
1766
  });
1750
- __publicField$9(this, "properties", {});
1751
- __publicField$9(this, "setProperties", (newProps) => {
1752
- this.properties = newProps;
1767
+ __publicField$e(this, "properties", {});
1768
+ __publicField$e(this, "setProperties", (newProps) => {
1769
+ this.properties = { ...this.properties, ...newProps };
1753
1770
  this.emit("propsUpdate", { ...this.properties });
1754
1771
  });
1755
- __publicField$9(this, "useProperties", () => {
1772
+ __publicField$e(this, "useProperties", () => {
1756
1773
  return useSubscription({
1757
1774
  getInitialState: () => this.properties,
1758
1775
  makeSubscription: (setProps) => this.on("propsUpdate", setProps)
@@ -1762,7 +1779,7 @@ class CollectorField extends EventEmitter {
1762
1779
  * Este componente se utiliza para controlar propiedades comunes a todos los
1763
1780
  * campos.
1764
1781
  */
1765
- __publicField$9(this, "SuperComponent", () => {
1782
+ __publicField$e(this, "SuperComponent", () => {
1766
1783
  if (__privateGet$2(this, _emitter).useState("isHidden"))
1767
1784
  return null;
1768
1785
  return /* @__PURE__ */ jsx(Box, { className: `collector__field ${this.type}`, children: /* @__PURE__ */ jsx(this.Component, {}) });
@@ -1771,13 +1788,19 @@ class CollectorField extends EventEmitter {
1771
1788
  this.properties = properties;
1772
1789
  }
1773
1790
  }
1791
+ get collector() {
1792
+ return this._collector;
1793
+ }
1794
+ set collector(c) {
1795
+ this._collector = c;
1796
+ }
1774
1797
  }
1775
1798
  _emitter = new WeakMap();
1776
1799
 
1777
- var __defProp$8 = Object.defineProperty;
1778
- var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1779
- var __publicField$8 = (obj, key, value) => {
1780
- __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
1800
+ var __defProp$d = Object.defineProperty;
1801
+ var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1802
+ var __publicField$d = (obj, key, value) => {
1803
+ __defNormalProp$d(obj, typeof key !== "symbol" ? key + "" : key, value);
1781
1804
  return value;
1782
1805
  };
1783
1806
  class ValidatedCollectorField extends CollectorField {
@@ -1786,21 +1809,24 @@ class ValidatedCollectorField extends CollectorField {
1786
1809
  this.name = name;
1787
1810
  this.label = label;
1788
1811
  this.config = config;
1789
- __publicField$8(this, "setInitialValue", (newValue) => {
1812
+ __publicField$d(this, "setInitialValue", (newValue) => {
1790
1813
  this.config.initialValue = newValue;
1791
1814
  });
1792
- __publicField$8(this, "setValidationFunction", (newFunction) => {
1815
+ __publicField$d(this, "setValidationFunction", (newFunction) => {
1793
1816
  this.config.validationFunction = newFunction;
1794
1817
  this.emit("functionUpdate", this.config.validationFunction);
1795
1818
  });
1796
- __publicField$8(this, "setValidationRules", (newRules) => {
1819
+ __publicField$d(this, "setValidationRules", (newRules) => {
1797
1820
  this.config.validationRules = newRules;
1798
1821
  this.emit("rulesUpdate", { ...this.config.validationRules });
1799
1822
  });
1800
- __publicField$8(this, "setValue", (newValue) => {
1801
- validationsStore.setFieldValue(this.collector.id, this.name, newValue);
1823
+ __publicField$d(this, "toggleRequired", (isReq = this.config?.validationRules?.required ?? false) => {
1824
+ if (!this.config.validationRules) {
1825
+ this.config.validationRules = {};
1826
+ }
1827
+ this.config.validationRules.required = isReq;
1802
1828
  });
1803
- __publicField$8(this, "useValidationFunction", () => {
1829
+ __publicField$d(this, "useValidationFunction", () => {
1804
1830
  return useSubscription({
1805
1831
  getInitialState: () => () => this.config.validationFunction,
1806
1832
  makeSubscription: (setValidationFunction) => {
@@ -1808,7 +1834,7 @@ class ValidatedCollectorField extends CollectorField {
1808
1834
  }
1809
1835
  });
1810
1836
  });
1811
- __publicField$8(this, "useValidationRules", () => {
1837
+ __publicField$d(this, "useValidationRules", () => {
1812
1838
  return useSubscription({
1813
1839
  getInitialState: () => this.config.validationRules,
1814
1840
  makeSubscription: (setValidationRules) => {
@@ -1817,25 +1843,37 @@ class ValidatedCollectorField extends CollectorField {
1817
1843
  });
1818
1844
  });
1819
1845
  }
1846
+ set collector(c) {
1847
+ this._collector = c;
1848
+ validationsStore.registerField(this._collector.id, {
1849
+ name: this.name,
1850
+ validationFunction: this.config.validationFunction,
1851
+ validationRules: this.config.validationRules,
1852
+ value: this.config.initialValue
1853
+ });
1854
+ }
1820
1855
  get initialValue() {
1821
1856
  return this.config.initialValue;
1822
1857
  }
1823
1858
  get value() {
1824
- return validationsStore.getFieldStore(this.collector.id, this.name).value;
1859
+ return validationsStore.getFieldStore(this._collector.id, this.name).value;
1860
+ }
1861
+ setValue(newValue) {
1862
+ validationsStore.setFieldValue(this._collector.id, this.name, newValue);
1825
1863
  }
1826
1864
  }
1827
1865
 
1828
- var __defProp$7 = Object.defineProperty;
1829
- var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1830
- var __publicField$7 = (obj, key, value) => {
1831
- __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
1866
+ var __defProp$c = Object.defineProperty;
1867
+ var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1868
+ var __publicField$c = (obj, key, value) => {
1869
+ __defNormalProp$c(obj, typeof key !== "symbol" ? key + "" : key, value);
1832
1870
  return value;
1833
1871
  };
1834
1872
  class CollectorCheckbox extends ValidatedCollectorField {
1835
1873
  constructor() {
1836
1874
  super(...arguments);
1837
- __publicField$7(this, "type", "checkbox");
1838
- __publicField$7(this, "Component", () => {
1875
+ __publicField$c(this, "type", "checkbox");
1876
+ __publicField$c(this, "Component", () => {
1839
1877
  const rules = this.useValidationRules();
1840
1878
  const validationFunction = this.useValidationFunction();
1841
1879
  const props = this.useProperties();
@@ -1846,26 +1884,29 @@ class CollectorCheckbox extends ValidatedCollectorField {
1846
1884
  initialValue: this.config.initialValue,
1847
1885
  validationFunction,
1848
1886
  name: this.name,
1849
- label: this.label,
1887
+ label: getLabelName(this.label),
1888
+ title: getLabelTooltip(this.label),
1850
1889
  validationRules: rules,
1851
- avoidSemicolon: true
1890
+ avoidSemicolon: true,
1891
+ removeOnUnmount: false,
1892
+ avoidRegisterIfExists: true
1852
1893
  }
1853
1894
  );
1854
1895
  });
1855
1896
  }
1856
1897
  }
1857
1898
 
1858
- var __defProp$6 = Object.defineProperty;
1859
- var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1860
- var __publicField$6 = (obj, key, value) => {
1861
- __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
1899
+ var __defProp$b = Object.defineProperty;
1900
+ var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1901
+ var __publicField$b = (obj, key, value) => {
1902
+ __defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
1862
1903
  return value;
1863
1904
  };
1864
1905
  class CollectorInput extends ValidatedCollectorField {
1865
1906
  constructor() {
1866
1907
  super(...arguments);
1867
- __publicField$6(this, "type", "input");
1868
- __publicField$6(this, "Component", () => {
1908
+ __publicField$b(this, "type", "input");
1909
+ __publicField$b(this, "Component", () => {
1869
1910
  const rules = this.useValidationRules();
1870
1911
  const validationFunction = this.useValidationFunction();
1871
1912
  const props = this.useProperties();
@@ -1876,18 +1917,20 @@ class CollectorInput extends ValidatedCollectorField {
1876
1917
  initialValue: this.config.initialValue,
1877
1918
  validationFunction,
1878
1919
  name: this.name,
1879
- label: this.label,
1880
- validationRules: rules
1920
+ label: getLabelName(this.label),
1921
+ title: getLabelTooltip(this.label),
1922
+ validationRules: rules,
1923
+ avoidRegisterIfExists: true
1881
1924
  }
1882
1925
  );
1883
1926
  });
1884
1927
  }
1885
1928
  }
1886
1929
 
1887
- var __defProp$5 = Object.defineProperty;
1888
- var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1889
- var __publicField$5 = (obj, key, value) => {
1890
- __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
1930
+ var __defProp$a = Object.defineProperty;
1931
+ var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1932
+ var __publicField$a = (obj, key, value) => {
1933
+ __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
1891
1934
  return value;
1892
1935
  };
1893
1936
  var __accessCheck$1 = (obj, member, msg) => {
@@ -1914,13 +1957,13 @@ class CollectorSelect extends ValidatedCollectorField {
1914
1957
  super(_name, label, config);
1915
1958
  this._name = _name;
1916
1959
  this.label = label;
1917
- __publicField$5(this, "type", "select");
1960
+ __publicField$a(this, "type", "select");
1918
1961
  __privateAdd$1(this, _options, []);
1919
- __publicField$5(this, "addOption", (newOption) => {
1962
+ __publicField$a(this, "addOption", (newOption) => {
1920
1963
  __privateSet(this, _options, [...__privateGet$1(this, _options), newOption]);
1921
1964
  this.emit("optionsUpdate", __privateGet$1(this, _options));
1922
1965
  });
1923
- __publicField$5(this, "setOptions", (newOptions) => {
1966
+ __publicField$a(this, "setOptions", (newOptions) => {
1924
1967
  __privateSet(this, _options, [...newOptions]);
1925
1968
  this.emit("optionsUpdate", __privateGet$1(this, _options));
1926
1969
  });
@@ -1931,7 +1974,7 @@ class CollectorSelect extends ValidatedCollectorField {
1931
1974
  });
1932
1975
  return options;
1933
1976
  });
1934
- __publicField$5(this, "Component", () => {
1977
+ __publicField$a(this, "Component", () => {
1935
1978
  const rules = this.useValidationRules();
1936
1979
  const validationFunction = this.useValidationFunction();
1937
1980
  const options = __privateGet$1(this, _useOptions).call(this);
@@ -1943,9 +1986,12 @@ class CollectorSelect extends ValidatedCollectorField {
1943
1986
  initialValue: this.config.initialValue,
1944
1987
  validationFunction,
1945
1988
  name: this.name,
1946
- label: this.label,
1989
+ label: getLabelName(this.label),
1990
+ title: getLabelTooltip(this.label),
1947
1991
  validationRules: rules,
1948
- options
1992
+ options,
1993
+ removeOnUnmount: false,
1994
+ avoidRegisterIfExists: true
1949
1995
  }
1950
1996
  );
1951
1997
  });
@@ -1957,17 +2003,17 @@ class CollectorSelect extends ValidatedCollectorField {
1957
2003
  _options = new WeakMap();
1958
2004
  _useOptions = new WeakMap();
1959
2005
 
1960
- var __defProp$4 = Object.defineProperty;
1961
- var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1962
- var __publicField$4 = (obj, key, value) => {
1963
- __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
2006
+ var __defProp$9 = Object.defineProperty;
2007
+ var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2008
+ var __publicField$9 = (obj, key, value) => {
2009
+ __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
1964
2010
  return value;
1965
2011
  };
1966
2012
  class CollectorTextarea extends ValidatedCollectorField {
1967
2013
  constructor() {
1968
2014
  super(...arguments);
1969
- __publicField$4(this, "type", "textarea");
1970
- __publicField$4(this, "Component", () => {
2015
+ __publicField$9(this, "type", "textarea");
2016
+ __publicField$9(this, "Component", () => {
1971
2017
  const rules = this.useValidationRules();
1972
2018
  const validationFunction = this.useValidationFunction();
1973
2019
  const props = this.useProperties();
@@ -1979,38 +2025,39 @@ class CollectorTextarea extends ValidatedCollectorField {
1979
2025
  name: this.name,
1980
2026
  validationFunction,
1981
2027
  validationRules: rules,
1982
- label: this.label
2028
+ label: getLabelName(this.label),
2029
+ title: getLabelTooltip(this.label),
2030
+ removeOnUnmount: false,
2031
+ avoidRegisterIfExists: true
1983
2032
  }
1984
2033
  );
1985
2034
  });
1986
2035
  }
1987
2036
  }
1988
2037
 
1989
- var __defProp$3 = Object.defineProperty;
1990
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1991
- var __publicField$3 = (obj, key, value) => {
1992
- __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
2038
+ var __defProp$8 = Object.defineProperty;
2039
+ var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2040
+ var __publicField$8 = (obj, key, value) => {
2041
+ __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
1993
2042
  return value;
1994
2043
  };
1995
2044
  const _CollectorLabel = class _CollectorLabel extends CollectorField {
1996
2045
  constructor(label, kind = "label") {
1997
2046
  super(`label${_CollectorLabel.maxId++}`, label);
1998
2047
  this.kind = kind;
1999
- __publicField$3(this, "type", "label");
2000
- __publicField$3(this, "Component", () => {
2001
- if (this.kind === "label")
2002
- return /* @__PURE__ */ jsx(Box, { as: this.kind, children: this.label });
2003
- return /* @__PURE__ */ jsx(Box, { as: this.kind, children: this.label });
2048
+ __publicField$8(this, "type", "label");
2049
+ __publicField$8(this, "Component", () => {
2050
+ return /* @__PURE__ */ jsx(Box, { as: this.kind, children: getLabelName(this.label) });
2004
2051
  });
2005
2052
  }
2006
2053
  };
2007
- __publicField$3(_CollectorLabel, "maxId", 0);
2054
+ __publicField$8(_CollectorLabel, "maxId", 0);
2008
2055
  let CollectorLabel = _CollectorLabel;
2009
2056
 
2010
- var __defProp$2 = Object.defineProperty;
2011
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2012
- var __publicField$2 = (obj, key, value) => {
2013
- __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
2057
+ var __defProp$7 = Object.defineProperty;
2058
+ var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2059
+ var __publicField$7 = (obj, key, value) => {
2060
+ __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
2014
2061
  return value;
2015
2062
  };
2016
2063
  let i = 0;
@@ -2018,18 +2065,250 @@ class CollectorButton extends CollectorField {
2018
2065
  constructor(label, properties) {
2019
2066
  super(`Button${i++}`, label, properties);
2020
2067
  this.label = label;
2021
- __publicField$2(this, "type", "button");
2022
- __publicField$2(this, "Component", () => {
2068
+ __publicField$7(this, "type", "button");
2069
+ __publicField$7(this, "Component", () => {
2023
2070
  const props = this.useProperties();
2024
- return /* @__PURE__ */ jsx(SimpleButton, { ...props, children: this.label });
2071
+ return /* @__PURE__ */ jsx(SimpleButton, { ...props, children: getLabelName(this.label) });
2025
2072
  });
2026
2073
  }
2027
2074
  }
2028
2075
 
2029
- var __defProp$1 = Object.defineProperty;
2030
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2031
- var __publicField$1 = (obj, key, value) => {
2032
- __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
2076
+ var __defProp$6 = Object.defineProperty;
2077
+ var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2078
+ var __publicField$6 = (obj, key, value) => {
2079
+ __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
2080
+ return value;
2081
+ };
2082
+ class CollectorSwitch extends ValidatedCollectorField {
2083
+ constructor() {
2084
+ super(...arguments);
2085
+ __publicField$6(this, "type", "switch");
2086
+ __publicField$6(this, "Component", () => {
2087
+ const rules = this.useValidationRules();
2088
+ const validationFunction = this.useValidationFunction();
2089
+ const props = this.useProperties();
2090
+ return /* @__PURE__ */ jsx(
2091
+ Switchbox,
2092
+ {
2093
+ ...props,
2094
+ initialValue: this.config.initialValue,
2095
+ validationFunction,
2096
+ name: this.name,
2097
+ label: getLabelName(this.label),
2098
+ title: getLabelTooltip(this.label),
2099
+ validationRules: rules,
2100
+ avoidSemicolon: true,
2101
+ removeOnUnmount: false,
2102
+ avoidRegisterIfExists: true
2103
+ }
2104
+ );
2105
+ });
2106
+ }
2107
+ }
2108
+
2109
+ class CollectorTitle extends CollectorLabel {
2110
+ constructor(label, level) {
2111
+ if (level < 1 || level > 6) {
2112
+ throw new Error("Only 1-6 leves allowed");
2113
+ }
2114
+ super(label, `h${level}`);
2115
+ }
2116
+ }
2117
+
2118
+ var __defProp$5 = Object.defineProperty;
2119
+ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2120
+ var __publicField$5 = (obj, key, value) => {
2121
+ __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
2122
+ return value;
2123
+ };
2124
+ const _CollectorSeparator = class _CollectorSeparator extends CollectorField {
2125
+ constructor() {
2126
+ super(`separator${_CollectorSeparator.maxId++}`, "");
2127
+ __publicField$5(this, "type", "label");
2128
+ __publicField$5(this, "Component", () => {
2129
+ return /* @__PURE__ */ jsx(Box, { className: "separator" });
2130
+ });
2131
+ }
2132
+ };
2133
+ __publicField$5(_CollectorSeparator, "maxId", 0);
2134
+ let CollectorSeparator = _CollectorSeparator;
2135
+
2136
+ const AutogrowTextarea = React.forwardRef(
2137
+ ({
2138
+ avoidSemicolon,
2139
+ className,
2140
+ formName,
2141
+ label,
2142
+ onChange: outerOnChange,
2143
+ /**
2144
+ * useField
2145
+ */
2146
+ avoidRegisterIfExists,
2147
+ initialValue,
2148
+ name,
2149
+ removeOnUnmount,
2150
+ submitValueParser,
2151
+ validationClass,
2152
+ validationFunction,
2153
+ validationRules,
2154
+ value,
2155
+ ...props
2156
+ }, ref) => {
2157
+ const { actualValidationFunction, actualValidationRules } = useValidationClass({
2158
+ formName,
2159
+ name,
2160
+ validationClass,
2161
+ validationFunction,
2162
+ validationRules
2163
+ });
2164
+ const { updateValidations, onChange, isTouched, ...inputProps } = useField({
2165
+ avoidRegisterIfExists,
2166
+ formName,
2167
+ initialValue: initialValue ?? value,
2168
+ name,
2169
+ removeOnUnmount,
2170
+ submitValueParser,
2171
+ validationRules: actualValidationRules,
2172
+ validationFunction: actualValidationFunction
2173
+ });
2174
+ const handleOnChange = React.useCallback(
2175
+ (ev) => {
2176
+ onChange(ev);
2177
+ if (outerOnChange) {
2178
+ outerOnChange(ev);
2179
+ }
2180
+ },
2181
+ [onChange, outerOnChange]
2182
+ );
2183
+ return /* @__PURE__ */ jsx(
2184
+ FieldWrapper,
2185
+ {
2186
+ name,
2187
+ label,
2188
+ className: `textarea ${className ?? ""}`,
2189
+ avoidSemicolon,
2190
+ title: props.title,
2191
+ children: /* @__PURE__ */ jsx(
2192
+ AutogrowTextarea$1,
2193
+ {
2194
+ ...props,
2195
+ ...inputProps,
2196
+ error: void 0,
2197
+ "aria-label": props["aria-label"] ?? label,
2198
+ ref,
2199
+ value: inputProps.value ?? "",
2200
+ onChange: handleOnChange
2201
+ }
2202
+ )
2203
+ }
2204
+ );
2205
+ }
2206
+ );
2207
+ AutogrowTextarea.displayName = "Textarea";
2208
+
2209
+ var __defProp$4 = Object.defineProperty;
2210
+ var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2211
+ var __publicField$4 = (obj, key, value) => {
2212
+ __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
2213
+ return value;
2214
+ };
2215
+ class CollectorAutogrowTextarea extends ValidatedCollectorField {
2216
+ constructor() {
2217
+ super(...arguments);
2218
+ __publicField$4(this, "type", "autogrowtextarea");
2219
+ __publicField$4(this, "Component", () => {
2220
+ const rules = this.useValidationRules();
2221
+ const validationFunction = this.useValidationFunction();
2222
+ const props = this.useProperties();
2223
+ return /* @__PURE__ */ jsx(
2224
+ AutogrowTextarea,
2225
+ {
2226
+ ...props,
2227
+ initialValue: this.config.initialValue,
2228
+ name: this.name,
2229
+ validationFunction,
2230
+ validationRules: rules,
2231
+ label: getLabelName(this.label),
2232
+ title: getLabelTooltip(this.label),
2233
+ removeOnUnmount: false,
2234
+ avoidRegisterIfExists: true
2235
+ }
2236
+ );
2237
+ });
2238
+ }
2239
+ }
2240
+
2241
+ const Component = observer(
2242
+ ({
2243
+ name,
2244
+ label,
2245
+ title,
2246
+ options,
2247
+ formName,
2248
+ initialValue,
2249
+ removeOnUnmount,
2250
+ validationFunction,
2251
+ validationRules,
2252
+ onChange: outerOnChange
2253
+ }) => {
2254
+ const { value, onChange } = useField({
2255
+ formName,
2256
+ name,
2257
+ initialValue,
2258
+ removeOnUnmount,
2259
+ validationFunction,
2260
+ validationRules
2261
+ });
2262
+ return /* @__PURE__ */ jsx(FieldWrapper, { name, label, title, children: /* @__PURE__ */ jsx(
2263
+ SwitchMultiple,
2264
+ {
2265
+ defaultValue: initialValue,
2266
+ value,
2267
+ options,
2268
+ onChange: (ev) => {
2269
+ onChange(ev);
2270
+ outerOnChange && outerOnChange(ev);
2271
+ }
2272
+ }
2273
+ ) });
2274
+ }
2275
+ );
2276
+
2277
+ var __defProp$3 = Object.defineProperty;
2278
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2279
+ var __publicField$3 = (obj, key, value) => {
2280
+ __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
2281
+ return value;
2282
+ };
2283
+ class CollectorSwitchMultiple extends ValidatedCollectorField {
2284
+ constructor() {
2285
+ super(...arguments);
2286
+ __publicField$3(this, "type", "switchInput");
2287
+ __publicField$3(this, "Component", () => {
2288
+ const rules = this.useValidationRules();
2289
+ const validationFunction = this.useValidationFunction();
2290
+ const props = this.useProperties();
2291
+ return /* @__PURE__ */ jsx(
2292
+ Component,
2293
+ {
2294
+ ...props,
2295
+ name: this.name,
2296
+ label: getLabelName(this.label),
2297
+ title: getLabelTooltip(this.label),
2298
+ initialValue: props.initialValue,
2299
+ validationRules: rules,
2300
+ validationFunction,
2301
+ options: props.options
2302
+ }
2303
+ );
2304
+ });
2305
+ }
2306
+ }
2307
+
2308
+ var __defProp$2 = Object.defineProperty;
2309
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2310
+ var __publicField$2 = (obj, key, value) => {
2311
+ __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
2033
2312
  return value;
2034
2313
  };
2035
2314
  var __accessCheck = (obj, member, msg) => {
@@ -2038,14 +2317,14 @@ var __accessCheck = (obj, member, msg) => {
2038
2317
  };
2039
2318
  var __privateGet = (obj, member, getter) => {
2040
2319
  __accessCheck(obj, member, "read from private field");
2041
- return getter ? getter.call(obj) : member.get(obj);
2320
+ return member.get(obj);
2042
2321
  };
2043
2322
  var __privateAdd = (obj, member, value) => {
2044
2323
  if (member.has(obj))
2045
2324
  throw TypeError("Cannot add the same private member more than once");
2046
2325
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
2047
2326
  };
2048
- var _fields, _Component;
2327
+ var _Component;
2049
2328
  try {
2050
2329
  void initValidations().catch(() => {
2051
2330
  });
@@ -2055,7 +2334,8 @@ try {
2055
2334
  let maxId = 0;
2056
2335
  class Collector {
2057
2336
  constructor() {
2058
- __publicField$1(this, "fields", {
2337
+ __publicField$2(this, "fields", {
2338
+ autogrowTextarea: CollectorAutogrowTextarea,
2059
2339
  button: CollectorButton,
2060
2340
  checkbox: CollectorCheckbox,
2061
2341
  input: CollectorInput,
@@ -2065,21 +2345,15 @@ class Collector {
2065
2345
  */
2066
2346
  label: CollectorLabel,
2067
2347
  select: CollectorSelect,
2068
- textarea: CollectorTextarea
2069
- });
2070
- __publicField$1(this, "private__id", `Collector${maxId++}`);
2071
- __publicField$1(this, "modal", null);
2072
- __privateAdd(this, _fields, {});
2073
- __publicField$1(this, "add", (...fields) => {
2074
- fields.forEach((field) => {
2075
- __privateGet(this, _fields)[field.name] = field;
2076
- field.collector = this;
2077
- });
2078
- return this;
2079
- });
2080
- __publicField$1(this, "forEach", (cb) => {
2081
- Object.values(__privateGet(this, _fields)).forEach(cb);
2348
+ separator: CollectorSeparator,
2349
+ switch: CollectorSwitch,
2350
+ textarea: CollectorTextarea,
2351
+ title: CollectorTitle,
2352
+ switchMultiple: CollectorSwitchMultiple
2082
2353
  });
2354
+ __publicField$2(this, "private__id", `Collector${maxId++}`);
2355
+ __publicField$2(this, "modal", null);
2356
+ __publicField$2(this, "fieldsStore", {});
2083
2357
  __privateAdd(this, _Component, ({
2084
2358
  hideConfirm,
2085
2359
  resolve
@@ -2087,7 +2361,7 @@ class Collector {
2087
2361
  const modal = useModalContext();
2088
2362
  return /* @__PURE__ */ jsx(this.Render, { resolve, hideConfirm, modal });
2089
2363
  });
2090
- __publicField$1(this, "Render", ({
2364
+ __publicField$2(this, "Render", ({
2091
2365
  hideConfirm,
2092
2366
  modal,
2093
2367
  resolve,
@@ -2102,6 +2376,7 @@ class Collector {
2102
2376
  children: /* @__PURE__ */ jsxs(
2103
2377
  Form,
2104
2378
  {
2379
+ unregisterOnUnmount: true,
2105
2380
  name: this.private__id,
2106
2381
  onValidate: (result) => {
2107
2382
  if (hasSucceedFormValidation(result)) {
@@ -2112,7 +2387,7 @@ class Collector {
2112
2387
  }
2113
2388
  },
2114
2389
  children: [
2115
- /* @__PURE__ */ jsx(Box, { className: "collector__fields", children: Object.values(__privateGet(this, _fields)).map((current) => {
2390
+ /* @__PURE__ */ jsx(Box, { className: "collector__fields", children: Object.values(this.fieldsStore).map((current) => {
2116
2391
  if (current instanceof ValidatedCollectorField)
2117
2392
  hasValidated = true;
2118
2393
  return /* @__PURE__ */ jsx(current.SuperComponent, {}, current.name);
@@ -2124,52 +2399,114 @@ class Collector {
2124
2399
  }
2125
2400
  );
2126
2401
  });
2127
- __publicField$1(this, "show", (modalProps) => {
2128
- const { onConfirm, ...actualModalProps } = modalProps ?? {};
2129
- return new Promise((resolve) => {
2130
- const C = __privateGet(this, _Component);
2131
- const modal = ApiaUtil.instance.modals.open({
2132
- onExited: () => {
2133
- {
2134
- this.modal = null;
2135
- resolve(null);
2136
- }
2137
- },
2138
- children: /* @__PURE__ */ jsx(
2139
- C,
2140
- {
2141
- hideConfirm: modalProps?.hideConfirm,
2142
- resolve: (values) => {
2143
- if (onConfirm) {
2144
- const confirmResult = onConfirm(values);
2145
- if (!confirmResult) {
2146
- return false;
2147
- }
2402
+ }
2403
+ get id() {
2404
+ return this.private__id;
2405
+ }
2406
+ add(...fields) {
2407
+ fields.forEach((field) => {
2408
+ this.fieldsStore[field.name] = field;
2409
+ field.collector = this;
2410
+ if (field instanceof ValidatedCollectorField) {
2411
+ validationsStore.setFieldValue(this.id, field.name, field.initialValue);
2412
+ }
2413
+ });
2414
+ return this;
2415
+ }
2416
+ forEach(cb) {
2417
+ Object.values(this.fieldsStore).forEach(cb);
2418
+ }
2419
+ getByName(name) {
2420
+ return this.fieldsStore[name];
2421
+ }
2422
+ show(modalProps) {
2423
+ const { onConfirm, ...actualModalProps } = modalProps ?? {};
2424
+ return new Promise((resolve) => {
2425
+ const C = __privateGet(this, _Component);
2426
+ const modal = ApiaUtil.instance.modals.open({
2427
+ onExited: () => {
2428
+ {
2429
+ this.modal = null;
2430
+ resolve(null);
2431
+ }
2432
+ },
2433
+ children: /* @__PURE__ */ jsx(
2434
+ C,
2435
+ {
2436
+ hideConfirm: modalProps?.hideConfirm,
2437
+ resolve: (values) => {
2438
+ if (onConfirm) {
2439
+ const confirmResult = onConfirm(values);
2440
+ if (!confirmResult) {
2441
+ return false;
2148
2442
  }
2149
- resolve(values);
2150
- return true;
2151
2443
  }
2444
+ resolve(values);
2445
+ return true;
2152
2446
  }
2153
- ),
2154
- variant: "layout.util.collector.modal",
2155
- initialFocusGetter(modalInnerRef) {
2156
- return modalInnerRef.querySelector(
2157
- "input,textarea,select,button:not(.modal__closeButton)"
2158
- );
2159
- },
2160
- ...actualModalProps
2161
- });
2162
- this.modal = modal;
2447
+ }
2448
+ ),
2449
+ variant: "layout.util.collector.modal",
2450
+ initialFocusGetter(modalInnerRef) {
2451
+ return modalInnerRef.querySelector(
2452
+ "input,textarea,select,button:not(.modal__closeButton)"
2453
+ );
2454
+ },
2455
+ ...actualModalProps
2163
2456
  });
2457
+ this.modal = modal;
2164
2458
  });
2165
2459
  }
2166
- get id() {
2167
- return this.private__id;
2168
- }
2169
2460
  }
2170
- _fields = new WeakMap();
2171
2461
  _Component = new WeakMap();
2172
2462
 
2463
+ var __defProp$1 = Object.defineProperty;
2464
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2465
+ var __publicField$1 = (obj, key, value) => {
2466
+ __defNormalProp$1(obj, key + "" , value);
2467
+ return value;
2468
+ };
2469
+ class WithMemoryCollector extends Collector {
2470
+ constructor(prefix) {
2471
+ super();
2472
+ this.prefix = prefix;
2473
+ __publicField$1(this, "memoized", /* @__PURE__ */ new Set());
2474
+ }
2475
+ getKey(name) {
2476
+ return `[WithMemoryCollector]${this.prefix}__${name}`;
2477
+ }
2478
+ addMemoized(...fields) {
2479
+ for (const f of fields) {
2480
+ let initialValue = void 0;
2481
+ if (f instanceof ValidatedCollectorField) {
2482
+ this.memoized.add(f.name);
2483
+ const stored = localStorage.getItem(this.getKey(f.name));
2484
+ if (stored) {
2485
+ initialValue = JSON.parse(stored);
2486
+ }
2487
+ }
2488
+ super.add(f);
2489
+ if (initialValue !== void 0) {
2490
+ validationsStore.setFieldValue(this.id, f.name, initialValue);
2491
+ }
2492
+ }
2493
+ return this;
2494
+ }
2495
+ async show(modalProps) {
2496
+ const res = await super.show(modalProps);
2497
+ if (res) {
2498
+ for (const f of Object.values(this.fieldsStore)) {
2499
+ if (f instanceof ValidatedCollectorField && this.memoized.has(f.name)) {
2500
+ if (f.value !== void 0) {
2501
+ localStorage.setItem(this.getKey(f.name), JSON.stringify(f.value));
2502
+ }
2503
+ }
2504
+ }
2505
+ }
2506
+ return res;
2507
+ }
2508
+ }
2509
+
2173
2510
  const ValidableContext = createContext(
2174
2511
  void 0
2175
2512
  );
@@ -2423,5 +2760,5 @@ class Validable {
2423
2760
  }
2424
2761
  }
2425
2762
 
2426
- export { InnerCaptcha as Captcha, Checkbox, Collector, CollectorField, DeletableInput, FieldWrapper, FileInput, Form, FormContext, Input, NumberInputf, Radio, Select, Switchbox, Textarea, Validable, ValidableCheck, ValidableContext, ValidableField, ValidableInput, ValidableSelect, ValidableTextarea, ValidatedCollectorField, ValidationError, classToValidate, classToValidationFunction, hasSucceedFieldValidation, hasSucceedFormValidation, initValidations, lang, useField, useFieldSelector, useFieldStatesClassNames, useFieldValue, useFormContext, useFormSelector, useValidableContext, useValidationClass, validate, validationsStore };
2763
+ export { InnerCaptcha as Captcha, Checkbox, Collector, CollectorAutogrowTextarea, CollectorButton, CollectorCheckbox, CollectorField, CollectorInput, CollectorLabel, CollectorSelect, CollectorSeparator, CollectorSwitch, CollectorSwitchMultiple, CollectorTextarea, CollectorTitle, DeletableInput, FieldWrapper, FileInput, Form, FormContext, Input, NumberInputf, Radio, Select, Switchbox, Textarea, Validable, ValidableCheck, ValidableContext, ValidableField, ValidableInput, ValidableSelect, ValidableTextarea, ValidatedCollectorField, ValidationError, WithMemoryCollector, classToValidate, classToValidationFunction, hasSucceedFieldValidation, hasSucceedFormValidation, initValidations, lang, useField, useFieldSelector, useFieldStatesClassNames, useFieldValue, useFormContext, useFormSelector, useValidableContext, useValidationClass, validate, validationsStore };
2427
2764
  //# sourceMappingURL=index.js.map