@apia/validations 5.0.0 → 5.0.3

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, useUnmount, useMount, PropsSelectorUndefinedObject, formatMessage, toBoolean, EventEmitter, StatefulEmitter, useSubscription, getLabel, getValueByPath } from '@apia/util';
2
+ import { customEvents, usePropsSelector, propsStore, getLabel, useUnmount, useMount, PropsSelectorUndefinedObject, formatMessage, EventEmitter, StatefulEmitter, useSubscription, getLabelTooltip, getLabelName, ChangeEvent, 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
  {}
@@ -147,6 +147,7 @@ async function initValidations() {
147
147
  return;
148
148
  const code = document.documentElement.lang ?? "es";
149
149
  langDefinition = (await __variableDynamicImportRuntime2__(
150
+ /* @vite-ignore */
150
151
  /* webpackChunkName: "val-lang-[request]" */
151
152
  `./lang/${code}.ts`
152
153
  ).catch((error) => {
@@ -234,20 +235,20 @@ function getValidations(outerValidation) {
234
235
  };
235
236
  }
236
237
 
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);
238
+ var __defProp$f = Object.defineProperty;
239
+ var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
240
+ var __publicField$f = (obj, key, value) => {
241
+ __defNormalProp$f(obj, typeof key !== "symbol" ? key + "" : key, value);
241
242
  return value;
242
243
  };
243
244
  const validationsStore = new class {
244
245
  constructor() {
245
- __publicField$a(this, "activeForms", []);
246
- __publicField$a(this, "timeouts", {});
247
- __publicField$a(this, "existsField", (formName, fieldName) => {
246
+ __publicField$f(this, "activeForms", []);
247
+ __publicField$f(this, "timeouts", {});
248
+ __publicField$f(this, "existsField", (formName, fieldName) => {
248
249
  return !!this.getFormStore(formName)?.fields?.includes(fieldName);
249
250
  });
250
- __publicField$a(this, "registerField", (formName, registerData, options = { registerIfExists: true }) => {
251
+ __publicField$f(this, "registerField", (formName, registerData, options = { registerIfExists: true }) => {
251
252
  const formProps = this.getFormStore(formName);
252
253
  if (formProps === void 0)
253
254
  this.registerForm(formName);
@@ -259,25 +260,18 @@ const validationsStore = new class {
259
260
  ]
260
261
  });
261
262
  const existsInStore = this.getFieldStore(formName, registerData.name);
262
- if ((formProps?.avoidFieldsOverride || !options.registerIfExists) && existsInStore) {
263
- const { value, ...updateData } = registerData;
264
- this.updateField(formName, updateData, {
263
+ if (!existsInStore || options.registerIfExists || !formProps?.avoidFieldsOverride && existsInStore && options.registerIfExists !== false) {
264
+ this.updateField(formName, registerData, {
265
265
  markFormAsTouched: false,
266
266
  avoidPropagation: options.avoidPropagation
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 } };
@@ -470,7 +464,7 @@ const validationsStore = new class {
470
464
  if (existsErrors) {
471
465
  if (!hasFiredFocus) {
472
466
  notify({
473
- message: window.MSG_WRONG_VALIDATION_NO_FOCUSED_FILE,
467
+ message: getLabel("msgWrngVldNoFoc").text,
474
468
  type: "danger"
475
469
  });
476
470
  console.error("Campos que fallaron la validaci\xF3n", fieldsWithError);
@@ -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);
@@ -890,7 +884,7 @@ const FieldWrapper = ({
890
884
  );
891
885
  }
892
886
  if (!label) {
893
- return /* @__PURE__ */ jsxs(Box, { className: "fieldWrapper", as: "span", children: [
887
+ return /* @__PURE__ */ jsxs(Box, { className: `fieldWrapper ${className ?? ""}`, as: "span", children: [
894
888
  children,
895
889
  /* @__PURE__ */ jsx(ValidationError, { name })
896
890
  ] });
@@ -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
  {
@@ -1023,7 +1018,7 @@ const Checkbox = React.forwardRef(
1023
1018
  native,
1024
1019
  "aria-label": props["aria-label"] ?? label,
1025
1020
  onChange: (ev) => {
1026
- onChange(ev.target.checked);
1021
+ onChange(ev.value);
1027
1022
  if (outerOnChange)
1028
1023
  outerOnChange(ev);
1029
1024
  },
@@ -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
  {
@@ -1261,12 +1258,16 @@ const Input = React.memo(
1261
1258
  });
1262
1259
  const handleOnChange = React.useCallback(
1263
1260
  (ev) => {
1264
- onChange(ev || "");
1265
- outerOnChange?.({
1266
- target: ref
1267
- });
1261
+ onChange(ev);
1262
+ if (typeof ev === "string") {
1263
+ outerOnChange?.(
1264
+ ev
1265
+ );
1266
+ } else {
1267
+ outerOnChange?.(ev);
1268
+ }
1268
1269
  },
1269
- [onChange, outerOnChange, ref]
1270
+ [onChange, outerOnChange]
1270
1271
  );
1271
1272
  const stateClassName = useFieldStatesClassNames(name);
1272
1273
  return /* @__PURE__ */ jsx(
@@ -1276,6 +1277,7 @@ const Input = React.memo(
1276
1277
  label,
1277
1278
  className: `input ${className ?? ""}`,
1278
1279
  avoidSemicolon,
1280
+ title: props.title,
1279
1281
  children: type === "date" ? /* @__PURE__ */ jsx(
1280
1282
  DateInput,
1281
1283
  {
@@ -1284,7 +1286,15 @@ const Input = React.memo(
1284
1286
  onError: void 0,
1285
1287
  onChange: handleOnChange,
1286
1288
  value: validationProps.value ?? "",
1287
- className: stateClassName
1289
+ className: stateClassName,
1290
+ id: validationProps.name,
1291
+ onBlur: (date) => {
1292
+ if (props.onBlur) {
1293
+ props.onBlur(
1294
+ date
1295
+ );
1296
+ }
1297
+ }
1288
1298
  }
1289
1299
  ) : /* @__PURE__ */ jsx(
1290
1300
  Input$1,
@@ -1294,10 +1304,7 @@ const Input = React.memo(
1294
1304
  ...validationProps,
1295
1305
  "aria-label": props["aria-label"] ?? label,
1296
1306
  ref,
1297
- onChange: (ev) => {
1298
- onChange(ev);
1299
- outerOnChange?.(ev);
1300
- },
1307
+ onChange: handleOnChange,
1301
1308
  value: validationProps.value ?? "",
1302
1309
  className: stateClassName
1303
1310
  }
@@ -1389,6 +1396,7 @@ const NumberInputf = React.memo(
1389
1396
  ),
1390
1397
  className: `input ${className ?? ""}`,
1391
1398
  avoidSemicolon,
1399
+ title: props.title,
1392
1400
  children: /* @__PURE__ */ jsx(
1393
1401
  NumberInput,
1394
1402
  {
@@ -1462,6 +1470,7 @@ const Radio = React.forwardRef(
1462
1470
  className: `radio ${className ?? ""}`,
1463
1471
  avoidSemicolon,
1464
1472
  as: "ul",
1473
+ title: props.title,
1465
1474
  children: options?.map((option) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs(Label, { title: option.label, className: "radio-label", children: [
1466
1475
  /* @__PURE__ */ jsx(
1467
1476
  Radio$1,
@@ -1523,6 +1532,7 @@ const Select = React.forwardRef(
1523
1532
  validationFunction: actualValidationFunction,
1524
1533
  validationRules: actualValidationRules
1525
1534
  });
1535
+ const stateClassName = useFieldStatesClassNames(name);
1526
1536
  return /* @__PURE__ */ jsx(
1527
1537
  FieldWrapper,
1528
1538
  {
@@ -1530,12 +1540,14 @@ const Select = React.forwardRef(
1530
1540
  label,
1531
1541
  className: `select ${className ?? ""}`,
1532
1542
  avoidSemicolon,
1543
+ title: props.title,
1533
1544
  children: /* @__PURE__ */ jsxs(
1534
1545
  Select$1,
1535
1546
  {
1536
1547
  ...getVariant("forms.select"),
1537
1548
  ...props,
1538
1549
  ...inputProps,
1550
+ className: stateClassName,
1539
1551
  onChange: React.useCallback(
1540
1552
  (ev) => {
1541
1553
  if (props.multiple) {
@@ -1573,7 +1585,6 @@ const Switchbox = React.forwardRef(
1573
1585
  label,
1574
1586
  onChange: outerOnChange,
1575
1587
  type,
1576
- reverse = false,
1577
1588
  avoidRegisterIfExists,
1578
1589
  formName,
1579
1590
  initialValue,
@@ -1593,23 +1604,31 @@ const Switchbox = React.forwardRef(
1593
1604
  validationFunction,
1594
1605
  validationRules
1595
1606
  });
1596
- const { onChange, updateValidations, isTouched, ...inputProps } = useField({
1607
+ const {
1608
+ value: innerValue,
1609
+ onChange,
1610
+ updateValidations,
1611
+ isTouched,
1612
+ ...inputProps
1613
+ } = useField({
1597
1614
  avoidRegisterIfExists,
1598
1615
  formName,
1599
1616
  name,
1600
- initialValue: (initialValue ?? "off") === "on" || toBoolean(initialValue) ? "on" : "off",
1617
+ initialValue,
1601
1618
  removeOnUnmount,
1602
1619
  submitValueParser,
1603
1620
  validationFunction: actualValidationFunction,
1604
1621
  validationRules: actualValidationRules
1605
1622
  });
1623
+ const putValue = useRef(false);
1606
1624
  return /* @__PURE__ */ jsx(
1607
1625
  FieldWrapper,
1608
1626
  {
1609
1627
  name,
1610
1628
  label,
1611
- className: `switchbox ${className ?? ""}`,
1629
+ className: `checkbox ${className ?? ""}`,
1612
1630
  avoidSemicolon,
1631
+ title: props.title,
1613
1632
  children: /* @__PURE__ */ jsx(
1614
1633
  Switch,
1615
1634
  {
@@ -1617,13 +1636,21 @@ const Switchbox = React.forwardRef(
1617
1636
  ...inputProps,
1618
1637
  "aria-label": props["aria-label"] ?? label,
1619
1638
  onChange: (ev) => {
1620
- onChange(ev.target.checked !== reverse ? "on" : "off");
1639
+ onChange(ev.target.checked);
1621
1640
  if (outerOnChange) {
1622
1641
  outerOnChange(ev);
1623
1642
  }
1624
1643
  },
1625
- checked: (inputProps.value ?? "off") === "on" !== reverse,
1626
- 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
+ }
1627
1654
  }
1628
1655
  )
1629
1656
  }
@@ -1686,6 +1713,7 @@ const Textarea = React.forwardRef(
1686
1713
  label,
1687
1714
  className: `textarea ${className ?? ""}`,
1688
1715
  avoidSemicolon,
1716
+ title: props.title,
1689
1717
  children: /* @__PURE__ */ jsx(
1690
1718
  Textarea$1,
1691
1719
  {
@@ -1703,10 +1731,10 @@ const Textarea = React.forwardRef(
1703
1731
  );
1704
1732
  Textarea.displayName = "Textarea";
1705
1733
 
1706
- var __defProp$9 = Object.defineProperty;
1707
- var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1708
- var __publicField$9 = (obj, key, value) => {
1709
- __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);
1710
1738
  return value;
1711
1739
  };
1712
1740
  var __accessCheck$2 = (obj, member, msg) => {
@@ -1731,17 +1759,17 @@ class CollectorField extends EventEmitter {
1731
1759
  __privateAdd$2(this, _emitter, new StatefulEmitter({
1732
1760
  isHidden: false
1733
1761
  }));
1734
- __publicField$9(this, "collector", {});
1735
- __publicField$9(this, "isHidden", () => __privateGet$2(this, _emitter).getState("isHidden"));
1736
- __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) => {
1737
1765
  __privateGet$2(this, _emitter).emit("isHidden", isHidden);
1738
1766
  });
1739
- __publicField$9(this, "properties", {});
1740
- __publicField$9(this, "setProperties", (newProps) => {
1741
- this.properties = newProps;
1767
+ __publicField$e(this, "properties", {});
1768
+ __publicField$e(this, "setProperties", (newProps) => {
1769
+ this.properties = { ...this.properties, ...newProps };
1742
1770
  this.emit("propsUpdate", { ...this.properties });
1743
1771
  });
1744
- __publicField$9(this, "useProperties", () => {
1772
+ __publicField$e(this, "useProperties", () => {
1745
1773
  return useSubscription({
1746
1774
  getInitialState: () => this.properties,
1747
1775
  makeSubscription: (setProps) => this.on("propsUpdate", setProps)
@@ -1751,7 +1779,7 @@ class CollectorField extends EventEmitter {
1751
1779
  * Este componente se utiliza para controlar propiedades comunes a todos los
1752
1780
  * campos.
1753
1781
  */
1754
- __publicField$9(this, "SuperComponent", () => {
1782
+ __publicField$e(this, "SuperComponent", () => {
1755
1783
  if (__privateGet$2(this, _emitter).useState("isHidden"))
1756
1784
  return null;
1757
1785
  return /* @__PURE__ */ jsx(Box, { className: `collector__field ${this.type}`, children: /* @__PURE__ */ jsx(this.Component, {}) });
@@ -1760,13 +1788,19 @@ class CollectorField extends EventEmitter {
1760
1788
  this.properties = properties;
1761
1789
  }
1762
1790
  }
1791
+ get collector() {
1792
+ return this._collector;
1793
+ }
1794
+ set collector(c) {
1795
+ this._collector = c;
1796
+ }
1763
1797
  }
1764
1798
  _emitter = new WeakMap();
1765
1799
 
1766
- var __defProp$8 = Object.defineProperty;
1767
- var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1768
- var __publicField$8 = (obj, key, value) => {
1769
- __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);
1770
1804
  return value;
1771
1805
  };
1772
1806
  class ValidatedCollectorField extends CollectorField {
@@ -1775,21 +1809,24 @@ class ValidatedCollectorField extends CollectorField {
1775
1809
  this.name = name;
1776
1810
  this.label = label;
1777
1811
  this.config = config;
1778
- __publicField$8(this, "setInitialValue", (newValue) => {
1812
+ __publicField$d(this, "setInitialValue", (newValue) => {
1779
1813
  this.config.initialValue = newValue;
1780
1814
  });
1781
- __publicField$8(this, "setValidationFunction", (newFunction) => {
1815
+ __publicField$d(this, "setValidationFunction", (newFunction) => {
1782
1816
  this.config.validationFunction = newFunction;
1783
1817
  this.emit("functionUpdate", this.config.validationFunction);
1784
1818
  });
1785
- __publicField$8(this, "setValidationRules", (newRules) => {
1819
+ __publicField$d(this, "setValidationRules", (newRules) => {
1786
1820
  this.config.validationRules = newRules;
1787
1821
  this.emit("rulesUpdate", { ...this.config.validationRules });
1788
1822
  });
1789
- __publicField$8(this, "setValue", (newValue) => {
1790
- 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;
1791
1828
  });
1792
- __publicField$8(this, "useValidationFunction", () => {
1829
+ __publicField$d(this, "useValidationFunction", () => {
1793
1830
  return useSubscription({
1794
1831
  getInitialState: () => () => this.config.validationFunction,
1795
1832
  makeSubscription: (setValidationFunction) => {
@@ -1797,7 +1834,7 @@ class ValidatedCollectorField extends CollectorField {
1797
1834
  }
1798
1835
  });
1799
1836
  });
1800
- __publicField$8(this, "useValidationRules", () => {
1837
+ __publicField$d(this, "useValidationRules", () => {
1801
1838
  return useSubscription({
1802
1839
  getInitialState: () => this.config.validationRules,
1803
1840
  makeSubscription: (setValidationRules) => {
@@ -1806,25 +1843,37 @@ class ValidatedCollectorField extends CollectorField {
1806
1843
  });
1807
1844
  });
1808
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
+ }
1809
1855
  get initialValue() {
1810
1856
  return this.config.initialValue;
1811
1857
  }
1812
1858
  get value() {
1813
- 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);
1814
1863
  }
1815
1864
  }
1816
1865
 
1817
- var __defProp$7 = Object.defineProperty;
1818
- var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1819
- var __publicField$7 = (obj, key, value) => {
1820
- __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);
1821
1870
  return value;
1822
1871
  };
1823
1872
  class CollectorCheckbox extends ValidatedCollectorField {
1824
1873
  constructor() {
1825
1874
  super(...arguments);
1826
- __publicField$7(this, "type", "checkbox");
1827
- __publicField$7(this, "Component", () => {
1875
+ __publicField$c(this, "type", "checkbox");
1876
+ __publicField$c(this, "Component", () => {
1828
1877
  const rules = this.useValidationRules();
1829
1878
  const validationFunction = this.useValidationFunction();
1830
1879
  const props = this.useProperties();
@@ -1835,26 +1884,29 @@ class CollectorCheckbox extends ValidatedCollectorField {
1835
1884
  initialValue: this.config.initialValue,
1836
1885
  validationFunction,
1837
1886
  name: this.name,
1838
- label: this.label,
1887
+ label: getLabelName(this.label),
1888
+ title: getLabelTooltip(this.label),
1839
1889
  validationRules: rules,
1840
- avoidSemicolon: true
1890
+ avoidSemicolon: true,
1891
+ removeOnUnmount: false,
1892
+ avoidRegisterIfExists: true
1841
1893
  }
1842
1894
  );
1843
1895
  });
1844
1896
  }
1845
1897
  }
1846
1898
 
1847
- var __defProp$6 = Object.defineProperty;
1848
- var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1849
- var __publicField$6 = (obj, key, value) => {
1850
- __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);
1851
1903
  return value;
1852
1904
  };
1853
1905
  class CollectorInput extends ValidatedCollectorField {
1854
1906
  constructor() {
1855
1907
  super(...arguments);
1856
- __publicField$6(this, "type", "input");
1857
- __publicField$6(this, "Component", () => {
1908
+ __publicField$b(this, "type", "input");
1909
+ __publicField$b(this, "Component", () => {
1858
1910
  const rules = this.useValidationRules();
1859
1911
  const validationFunction = this.useValidationFunction();
1860
1912
  const props = this.useProperties();
@@ -1865,18 +1917,20 @@ class CollectorInput extends ValidatedCollectorField {
1865
1917
  initialValue: this.config.initialValue,
1866
1918
  validationFunction,
1867
1919
  name: this.name,
1868
- label: this.label,
1869
- validationRules: rules
1920
+ label: getLabelName(this.label),
1921
+ title: getLabelTooltip(this.label),
1922
+ validationRules: rules,
1923
+ avoidRegisterIfExists: true
1870
1924
  }
1871
1925
  );
1872
1926
  });
1873
1927
  }
1874
1928
  }
1875
1929
 
1876
- var __defProp$5 = Object.defineProperty;
1877
- var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1878
- var __publicField$5 = (obj, key, value) => {
1879
- __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);
1880
1934
  return value;
1881
1935
  };
1882
1936
  var __accessCheck$1 = (obj, member, msg) => {
@@ -1903,13 +1957,13 @@ class CollectorSelect extends ValidatedCollectorField {
1903
1957
  super(_name, label, config);
1904
1958
  this._name = _name;
1905
1959
  this.label = label;
1906
- __publicField$5(this, "type", "select");
1960
+ __publicField$a(this, "type", "select");
1907
1961
  __privateAdd$1(this, _options, []);
1908
- __publicField$5(this, "addOption", (newOption) => {
1962
+ __publicField$a(this, "addOption", (newOption) => {
1909
1963
  __privateSet(this, _options, [...__privateGet$1(this, _options), newOption]);
1910
1964
  this.emit("optionsUpdate", __privateGet$1(this, _options));
1911
1965
  });
1912
- __publicField$5(this, "setOptions", (newOptions) => {
1966
+ __publicField$a(this, "setOptions", (newOptions) => {
1913
1967
  __privateSet(this, _options, [...newOptions]);
1914
1968
  this.emit("optionsUpdate", __privateGet$1(this, _options));
1915
1969
  });
@@ -1920,7 +1974,7 @@ class CollectorSelect extends ValidatedCollectorField {
1920
1974
  });
1921
1975
  return options;
1922
1976
  });
1923
- __publicField$5(this, "Component", () => {
1977
+ __publicField$a(this, "Component", () => {
1924
1978
  const rules = this.useValidationRules();
1925
1979
  const validationFunction = this.useValidationFunction();
1926
1980
  const options = __privateGet$1(this, _useOptions).call(this);
@@ -1932,9 +1986,12 @@ class CollectorSelect extends ValidatedCollectorField {
1932
1986
  initialValue: this.config.initialValue,
1933
1987
  validationFunction,
1934
1988
  name: this.name,
1935
- label: this.label,
1989
+ label: getLabelName(this.label),
1990
+ title: getLabelTooltip(this.label),
1936
1991
  validationRules: rules,
1937
- options
1992
+ options,
1993
+ removeOnUnmount: false,
1994
+ avoidRegisterIfExists: true
1938
1995
  }
1939
1996
  );
1940
1997
  });
@@ -1946,17 +2003,17 @@ class CollectorSelect extends ValidatedCollectorField {
1946
2003
  _options = new WeakMap();
1947
2004
  _useOptions = new WeakMap();
1948
2005
 
1949
- var __defProp$4 = Object.defineProperty;
1950
- var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1951
- var __publicField$4 = (obj, key, value) => {
1952
- __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);
1953
2010
  return value;
1954
2011
  };
1955
2012
  class CollectorTextarea extends ValidatedCollectorField {
1956
2013
  constructor() {
1957
2014
  super(...arguments);
1958
- __publicField$4(this, "type", "textarea");
1959
- __publicField$4(this, "Component", () => {
2015
+ __publicField$9(this, "type", "textarea");
2016
+ __publicField$9(this, "Component", () => {
1960
2017
  const rules = this.useValidationRules();
1961
2018
  const validationFunction = this.useValidationFunction();
1962
2019
  const props = this.useProperties();
@@ -1968,38 +2025,39 @@ class CollectorTextarea extends ValidatedCollectorField {
1968
2025
  name: this.name,
1969
2026
  validationFunction,
1970
2027
  validationRules: rules,
1971
- label: this.label
2028
+ label: getLabelName(this.label),
2029
+ title: getLabelTooltip(this.label),
2030
+ removeOnUnmount: false,
2031
+ avoidRegisterIfExists: true
1972
2032
  }
1973
2033
  );
1974
2034
  });
1975
2035
  }
1976
2036
  }
1977
2037
 
1978
- var __defProp$3 = Object.defineProperty;
1979
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1980
- var __publicField$3 = (obj, key, value) => {
1981
- __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);
1982
2042
  return value;
1983
2043
  };
1984
2044
  const _CollectorLabel = class _CollectorLabel extends CollectorField {
1985
2045
  constructor(label, kind = "label") {
1986
2046
  super(`label${_CollectorLabel.maxId++}`, label);
1987
2047
  this.kind = kind;
1988
- __publicField$3(this, "type", "label");
1989
- __publicField$3(this, "Component", () => {
1990
- if (this.kind === "label")
1991
- return /* @__PURE__ */ jsx(Box, { as: this.kind, children: this.label });
1992
- 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) });
1993
2051
  });
1994
2052
  }
1995
2053
  };
1996
- __publicField$3(_CollectorLabel, "maxId", 0);
2054
+ __publicField$8(_CollectorLabel, "maxId", 0);
1997
2055
  let CollectorLabel = _CollectorLabel;
1998
2056
 
1999
- var __defProp$2 = Object.defineProperty;
2000
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2001
- var __publicField$2 = (obj, key, value) => {
2002
- __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);
2003
2061
  return value;
2004
2062
  };
2005
2063
  let i = 0;
@@ -2007,18 +2065,250 @@ class CollectorButton extends CollectorField {
2007
2065
  constructor(label, properties) {
2008
2066
  super(`Button${i++}`, label, properties);
2009
2067
  this.label = label;
2010
- __publicField$2(this, "type", "button");
2011
- __publicField$2(this, "Component", () => {
2068
+ __publicField$7(this, "type", "button");
2069
+ __publicField$7(this, "Component", () => {
2012
2070
  const props = this.useProperties();
2013
- return /* @__PURE__ */ jsx(SimpleButton, { ...props, children: this.label });
2071
+ return /* @__PURE__ */ jsx(SimpleButton, { ...props, children: getLabelName(this.label) });
2014
2072
  });
2015
2073
  }
2016
2074
  }
2017
2075
 
2018
- var __defProp$1 = Object.defineProperty;
2019
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2020
- var __publicField$1 = (obj, key, value) => {
2021
- __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);
2022
2312
  return value;
2023
2313
  };
2024
2314
  var __accessCheck = (obj, member, msg) => {
@@ -2027,14 +2317,14 @@ var __accessCheck = (obj, member, msg) => {
2027
2317
  };
2028
2318
  var __privateGet = (obj, member, getter) => {
2029
2319
  __accessCheck(obj, member, "read from private field");
2030
- return getter ? getter.call(obj) : member.get(obj);
2320
+ return member.get(obj);
2031
2321
  };
2032
2322
  var __privateAdd = (obj, member, value) => {
2033
2323
  if (member.has(obj))
2034
2324
  throw TypeError("Cannot add the same private member more than once");
2035
2325
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
2036
2326
  };
2037
- var _fields, _Component;
2327
+ var _Component;
2038
2328
  try {
2039
2329
  void initValidations().catch(() => {
2040
2330
  });
@@ -2044,7 +2334,8 @@ try {
2044
2334
  let maxId = 0;
2045
2335
  class Collector {
2046
2336
  constructor() {
2047
- __publicField$1(this, "fields", {
2337
+ __publicField$2(this, "fields", {
2338
+ autogrowTextarea: CollectorAutogrowTextarea,
2048
2339
  button: CollectorButton,
2049
2340
  checkbox: CollectorCheckbox,
2050
2341
  input: CollectorInput,
@@ -2054,21 +2345,15 @@ class Collector {
2054
2345
  */
2055
2346
  label: CollectorLabel,
2056
2347
  select: CollectorSelect,
2057
- textarea: CollectorTextarea
2058
- });
2059
- __publicField$1(this, "private__id", `Collector${maxId++}`);
2060
- __publicField$1(this, "modal", null);
2061
- __privateAdd(this, _fields, {});
2062
- __publicField$1(this, "add", (...fields) => {
2063
- fields.forEach((field) => {
2064
- __privateGet(this, _fields)[field.name] = field;
2065
- field.collector = this;
2066
- });
2067
- return this;
2068
- });
2069
- __publicField$1(this, "forEach", (cb) => {
2070
- Object.values(__privateGet(this, _fields)).forEach(cb);
2348
+ separator: CollectorSeparator,
2349
+ switch: CollectorSwitch,
2350
+ textarea: CollectorTextarea,
2351
+ title: CollectorTitle,
2352
+ switchMultiple: CollectorSwitchMultiple
2071
2353
  });
2354
+ __publicField$2(this, "private__id", `Collector${maxId++}`);
2355
+ __publicField$2(this, "modal", null);
2356
+ __publicField$2(this, "fieldsStore", {});
2072
2357
  __privateAdd(this, _Component, ({
2073
2358
  hideConfirm,
2074
2359
  resolve
@@ -2076,7 +2361,7 @@ class Collector {
2076
2361
  const modal = useModalContext();
2077
2362
  return /* @__PURE__ */ jsx(this.Render, { resolve, hideConfirm, modal });
2078
2363
  });
2079
- __publicField$1(this, "Render", ({
2364
+ __publicField$2(this, "Render", ({
2080
2365
  hideConfirm,
2081
2366
  modal,
2082
2367
  resolve,
@@ -2091,6 +2376,7 @@ class Collector {
2091
2376
  children: /* @__PURE__ */ jsxs(
2092
2377
  Form,
2093
2378
  {
2379
+ unregisterOnUnmount: true,
2094
2380
  name: this.private__id,
2095
2381
  onValidate: (result) => {
2096
2382
  if (hasSucceedFormValidation(result)) {
@@ -2101,7 +2387,7 @@ class Collector {
2101
2387
  }
2102
2388
  },
2103
2389
  children: [
2104
- /* @__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) => {
2105
2391
  if (current instanceof ValidatedCollectorField)
2106
2392
  hasValidated = true;
2107
2393
  return /* @__PURE__ */ jsx(current.SuperComponent, {}, current.name);
@@ -2113,52 +2399,114 @@ class Collector {
2113
2399
  }
2114
2400
  );
2115
2401
  });
2116
- __publicField$1(this, "show", (modalProps) => {
2117
- const { onConfirm, ...actualModalProps } = modalProps ?? {};
2118
- return new Promise((resolve) => {
2119
- const C = __privateGet(this, _Component);
2120
- const modal = ApiaUtil.instance.modals.open({
2121
- onExited: () => {
2122
- {
2123
- this.modal = null;
2124
- resolve(null);
2125
- }
2126
- },
2127
- children: /* @__PURE__ */ jsx(
2128
- C,
2129
- {
2130
- hideConfirm: modalProps?.hideConfirm,
2131
- resolve: (values) => {
2132
- if (onConfirm) {
2133
- const confirmResult = onConfirm(values);
2134
- if (!confirmResult) {
2135
- return false;
2136
- }
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;
2137
2442
  }
2138
- resolve(values);
2139
- return true;
2140
2443
  }
2444
+ resolve(values);
2445
+ return true;
2141
2446
  }
2142
- ),
2143
- variant: "layout.util.collector.modal",
2144
- initialFocusGetter(modalInnerRef) {
2145
- return modalInnerRef.querySelector(
2146
- "input,textarea,select,button:not(.modal__closeButton)"
2147
- );
2148
- },
2149
- ...actualModalProps
2150
- });
2151
- 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
2152
2456
  });
2457
+ this.modal = modal;
2153
2458
  });
2154
2459
  }
2155
- get id() {
2156
- return this.private__id;
2157
- }
2158
2460
  }
2159
- _fields = new WeakMap();
2160
2461
  _Component = new WeakMap();
2161
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
+
2162
2510
  const ValidableContext = createContext(
2163
2511
  void 0
2164
2512
  );
@@ -2229,7 +2577,7 @@ const ValidableInput = makeValidableField(
2229
2577
  ({ type, context, label, path, onChange, ...props }) => {
2230
2578
  const handleChange = (event) => {
2231
2579
  context.setValue(path, event.target.value);
2232
- onChange?.(event);
2580
+ onChange?.(new ChangeEvent(event.target.value));
2233
2581
  };
2234
2582
  return /* @__PURE__ */ jsx(
2235
2583
  ValidableField,
@@ -2256,7 +2604,7 @@ const ValidableInput = makeValidableField(
2256
2604
  const ValidableSelect = makeValidableField(({ context, label, path, onChange, options, ...props }) => {
2257
2605
  const handleChange = (event) => {
2258
2606
  context.setValue(path, event.target.value);
2259
- onChange?.(event);
2607
+ onChange?.(new ChangeEvent(event.target.value));
2260
2608
  };
2261
2609
  return /* @__PURE__ */ jsx(
2262
2610
  ValidableField,
@@ -2292,7 +2640,7 @@ const ValidableTextarea = makeValidableField(
2292
2640
  ({ context, label, path, onChange, ...props }) => {
2293
2641
  const handleChange = (event) => {
2294
2642
  context.setValue(path, event.target.value);
2295
- onChange?.(event);
2643
+ onChange?.(new ChangeEvent(event));
2296
2644
  };
2297
2645
  return /* @__PURE__ */ jsx(
2298
2646
  ValidableField,
@@ -2318,7 +2666,7 @@ const ValidableTextarea = makeValidableField(
2318
2666
  const ValidableCheck = makeValidableField(
2319
2667
  ({ context, label, path, onChange, ...props }) => {
2320
2668
  const handleChange = (event) => {
2321
- context.setValue(path, event.target.value);
2669
+ context.setValue(path, event.value);
2322
2670
  onChange?.(event);
2323
2671
  };
2324
2672
  return /* @__PURE__ */ jsx(
@@ -2412,5 +2760,5 @@ class Validable {
2412
2760
  }
2413
2761
  }
2414
2762
 
2415
- 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, CollectorField, 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 };
2416
2764
  //# sourceMappingURL=index.js.map