@m4l/components 9.80.0 → 9.80.1-beta-docs-autocomplete-async-with-add-mf-sync.1

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.
Files changed (58) hide show
  1. package/components/extended/mui/Autocomplete/Autocomplete.d.ts.map +1 -1
  2. package/components/extended/mui/Autocomplete/Autocomplete.js +55 -54
  3. package/components/extended/mui/Autocomplete/hooks/useAutocomplete/useAutocomplete.d.ts.map +1 -1
  4. package/components/extended/mui/Autocomplete/hooks/useAutocomplete/useAutocomplete.js +81 -72
  5. package/components/extended/mui/Autocomplete/types.d.ts +1 -1
  6. package/components/extended/mui/Autocomplete/types.d.ts.map +1 -1
  7. package/components/extended/mui/AutocompleteAsync/AutocompleteAddButton.d.ts +4 -0
  8. package/components/extended/mui/AutocompleteAsync/AutocompleteAddButton.d.ts.map +1 -0
  9. package/components/extended/mui/AutocompleteAsync/AutocompleteAddButton.js +23 -0
  10. package/components/extended/mui/AutocompleteAsync/AutocompleteAsync.d.ts +5 -9
  11. package/components/extended/mui/AutocompleteAsync/AutocompleteAsync.d.ts.map +1 -1
  12. package/components/extended/mui/AutocompleteAsync/AutocompleteAsync.js +87 -56
  13. package/components/extended/mui/AutocompleteAsync/constants.d.ts +4 -1
  14. package/components/extended/mui/AutocompleteAsync/constants.d.ts.map +1 -1
  15. package/components/extended/mui/AutocompleteAsync/constants.js +24 -12
  16. package/components/extended/mui/AutocompleteAsync/hooks/useAutocompleteAdd.d.ts +9 -0
  17. package/components/extended/mui/AutocompleteAsync/hooks/useAutocompleteAdd.d.ts.map +1 -0
  18. package/components/extended/mui/AutocompleteAsync/hooks/useAutocompleteAdd.js +97 -0
  19. package/components/extended/mui/AutocompleteAsync/hooks/useFetchOptions.d.ts.map +1 -1
  20. package/components/extended/mui/AutocompleteAsync/hooks/useFetchOptions.js +47 -46
  21. package/components/extended/mui/AutocompleteAsync/index.d.ts +1 -1
  22. package/components/extended/mui/AutocompleteAsync/index.d.ts.map +1 -1
  23. package/components/extended/mui/AutocompleteAsync/reducer/AutocompleteAsyncReducer.d.ts.map +1 -1
  24. package/components/extended/mui/AutocompleteAsync/reducer/AutocompleteAsyncReducer.js +50 -28
  25. package/components/extended/mui/AutocompleteAsync/slots/addStyled.d.ts +6 -0
  26. package/components/extended/mui/AutocompleteAsync/slots/addStyled.d.ts.map +1 -0
  27. package/components/extended/mui/AutocompleteAsync/slots/addStyled.js +19 -0
  28. package/components/extended/mui/AutocompleteAsync/tests/add/constants.d.ts +5 -0
  29. package/components/extended/mui/AutocompleteAsync/tests/add/constants.d.ts.map +1 -0
  30. package/components/extended/mui/AutocompleteAsync/tests/add/helpers.d.ts +8 -0
  31. package/components/extended/mui/AutocompleteAsync/tests/add/helpers.d.ts.map +1 -0
  32. package/components/extended/mui/AutocompleteAsync/tests/add/types.d.ts +20 -0
  33. package/components/extended/mui/AutocompleteAsync/tests/add/types.d.ts.map +1 -0
  34. package/components/extended/mui/AutocompleteAsync/tests/support/ControlledAsyncField.d.ts +4 -0
  35. package/components/extended/mui/AutocompleteAsync/tests/support/ControlledAsyncField.d.ts.map +1 -0
  36. package/components/extended/mui/AutocompleteAsync/tests/support/constants.d.ts +8 -0
  37. package/components/extended/mui/AutocompleteAsync/tests/support/constants.d.ts.map +1 -0
  38. package/components/extended/mui/AutocompleteAsync/tests/support/createDeferred.d.ts +4 -0
  39. package/components/extended/mui/AutocompleteAsync/tests/support/createDeferred.d.ts.map +1 -0
  40. package/components/extended/mui/AutocompleteAsync/tests/support/mockAutocompleteAnchor.d.ts +3 -0
  41. package/components/extended/mui/AutocompleteAsync/tests/support/mockAutocompleteAnchor.d.ts.map +1 -0
  42. package/components/extended/mui/AutocompleteAsync/tests/support/types.d.ts +21 -0
  43. package/components/extended/mui/AutocompleteAsync/tests/support/types.d.ts.map +1 -0
  44. package/components/extended/mui/AutocompleteAsync/types.d.ts +47 -0
  45. package/components/extended/mui/AutocompleteAsync/types.d.ts.map +1 -1
  46. package/components/extended/mui/AutocompleteAsync/types.js +4 -2
  47. package/components/hook-form/RHFAutocompleteAsync/RHFAutocompleteAsync.d.ts +1 -1
  48. package/components/hook-form/RHFAutocompleteAsync/index.d.ts +1 -0
  49. package/components/hook-form/RHFAutocompleteAsync/index.d.ts.map +1 -1
  50. package/components/hook-form/RHFAutocompleteAsync/tests/addConstants.d.ts +3 -0
  51. package/components/hook-form/RHFAutocompleteAsync/tests/addConstants.d.ts.map +1 -0
  52. package/components/hook-form/RHFAutocompleteAsync/tests/addHelpers.d.ts +4 -0
  53. package/components/hook-form/RHFAutocompleteAsync/tests/addHelpers.d.ts.map +1 -0
  54. package/components/hook-form/RHFAutocompleteAsync/tests/addTypes.d.ts +12 -0
  55. package/components/hook-form/RHFAutocompleteAsync/tests/addTypes.d.ts.map +1 -0
  56. package/components/hook-form/index.d.ts +1 -0
  57. package/components/hook-form/index.d.ts.map +1 -1
  58. package/package.json +9 -9
@@ -1,53 +1,67 @@
1
- import { jsx as P } from "@emotion/react/jsx-runtime";
2
- import S from "lodash-es/debounce";
3
- import { useRef as b, useReducer as L, useCallback as s, useMemo as Y, useEffect as _ } from "react";
1
+ import { jsx as A, jsxs as T } from "@emotion/react/jsx-runtime";
2
+ import D from "lodash-es/debounce";
3
+ import { forwardRef as H, useRef as y, useReducer as Q, useCallback as f, useEffect as R, useMemo as K } from "react";
4
4
  import { actionsType as i } from "./types.js";
5
- import { autocompleteAsyncReducer as j, getInitialStateAutocompleteAsync as x } from "./reducer/AutocompleteAsyncReducer.js";
6
- import { useFetchOptions as N } from "./hooks/useFetchOptions.js";
7
- import { ASYNC_ONLY_KEYS as T } from "./constants.js";
8
- import { AutocompleteAsyncRootStyled as I } from "./slots/AutocompleteAsyncSlots.js";
9
- function q(l) {
5
+ import { autocompleteAsyncReducer as V, getInitialStateAutocompleteAsync as z } from "./reducer/AutocompleteAsyncReducer.js";
6
+ import { useFetchOptions as G } from "./hooks/useFetchOptions.js";
7
+ import { useAutocompleteAdd as J } from "./hooks/useAutocompleteAdd.js";
8
+ import { AutocompleteAddRoot as W, AutocompleteAddRow as X, AutocompleteAddInput as Z, AutocompleteAddStatusText as $ } from "./slots/addStyled.js";
9
+ import { ASYNC_ONLY_KEYS as ee } from "./constants.js";
10
+ import { AutocompleteAsyncRootStyled as te } from "./slots/AutocompleteAsyncSlots.js";
11
+ function oe(p, b) {
10
12
  const {
11
- endPoint: p,
12
- timeout: u = 5e3,
13
- parms: a,
14
- resultField: f = "data",
15
- isRemote: d = !0,
16
- isExternalUrl: h = !1,
17
- onChangeFilterParms: t,
18
- responseToCamelCase: y,
19
- multiple: C,
20
- shouldFetch: o
21
- } = l, m = b(""), E = Object.fromEntries(
22
- Object.entries(l).filter(([e]) => !T.includes(e))
23
- ), [c, n] = L(
24
- j(t),
25
- x({ parms: a, onChangeFilterParms: t })
13
+ add: E,
14
+ endPoint: x,
15
+ timeout: I = 5e3,
16
+ parms: C,
17
+ resultField: j = "data",
18
+ isRemote: B = !0,
19
+ isExternalUrl: N = !1,
20
+ onChangeFilterParms: o,
21
+ responseToCamelCase: Y,
22
+ multiple: h,
23
+ shouldFetch: e,
24
+ resetKey: m,
25
+ retainSelectedOptions: F = !!E,
26
+ value: c,
27
+ isOptionEqualToValue: g
28
+ } = p, l = J(p), d = l.refreshKey, u = y(""), _ = Object.fromEntries(
29
+ Object.entries(p).filter(([t]) => !ee.includes(t))
30
+ ), [s, n] = Q(
31
+ V(o),
32
+ z({ parms: C, onChangeFilterParms: o })
26
33
  );
27
- if (C && t)
34
+ if (h && o)
28
35
  throw new Error(
29
36
  "multiple cannot be enabled when onChangeFilterParms is defined; define the filter in parms if needed."
30
37
  );
31
- N({
32
- state: c,
38
+ G({
39
+ state: s,
33
40
  dispatch: n,
34
- endPoint: p,
35
- timeout: u,
36
- isExternalUrl: h,
37
- parms: a,
38
- responseToCamelCase: y,
39
- isRemote: d,
40
- resultField: f
41
+ endPoint: x,
42
+ timeout: I,
43
+ isExternalUrl: N,
44
+ parms: C,
45
+ responseToCamelCase: Y,
46
+ isRemote: B,
47
+ resultField: j
41
48
  });
42
- const F = s(() => n({ type: i.REFRESH }), []), A = s(() => {
43
- const e = !o || o(m.current);
44
- n({ type: i.OPEN, noFetch: !e });
45
- }, [o]), R = s(() => n({ type: i.CLOSE }), []), r = Y(
46
- () => S(
47
- (e) => {
49
+ const v = f(() => n({ type: i.REFRESH }), []), S = y(d);
50
+ R(() => {
51
+ S.current !== d && (S.current = d, n({
52
+ type: i.INVALIDATE,
53
+ noFetch: !!(e && !e(u.current))
54
+ }));
55
+ }, [d, e]);
56
+ const w = f(() => {
57
+ const t = !e || e(u.current);
58
+ n({ type: i.OPEN, noFetch: !t });
59
+ }, [e]), q = f(() => n({ type: i.CLOSE }), []), r = K(
60
+ () => D(
61
+ (t) => {
48
62
  n({
49
63
  type: i.SET_QUERY_PARAMS,
50
- payload: e
64
+ payload: t
51
65
  });
52
66
  },
53
67
  300,
@@ -55,31 +69,48 @@ function q(l) {
55
69
  ),
56
70
  [n]
57
71
  );
58
- _(
72
+ R(
59
73
  () => () => {
60
74
  r.cancel();
61
75
  },
62
76
  [r]
63
77
  );
64
- const g = s(
65
- (e, O) => {
66
- m.current = e, t && O === "input" && (!o || o(e)) && r(t(e));
78
+ const O = y(m);
79
+ R(() => {
80
+ O.current !== m && (O.current = m, r.cancel(), n({
81
+ type: i.RESET,
82
+ noFetch: !!(e && !e(u.current)),
83
+ queryParams: o?.(u.current)
84
+ }));
85
+ }, [m, e, o, r]);
86
+ const M = f(
87
+ (t, a) => {
88
+ u.current = t, o && a === "input" && (!e || e(t) ? r(o(t)) : r.cancel());
67
89
  },
68
- [t, r, o]
69
- );
70
- return /* @__PURE__ */ P(
71
- I,
90
+ [o, r, e]
91
+ ), U = K(() => !F || s.options.length === 0 ? s.options : (h ? Array.isArray(c) ? c : [] : c == null ? [] : [c]).reduce((a, L) => a.some((k) => g(k, L)) ? a : [...a, L], s.options), [s.options, h, c, g, F]), P = /* @__PURE__ */ A(
92
+ te,
72
93
  {
73
- ...E,
74
- loading: c.loading,
75
- options: c.options,
76
- onChangeFilterParmsLocal: t ? g : void 0,
77
- refresh: F,
78
- onOpen: A,
79
- onClose: R
94
+ ..._,
95
+ inputRef: b ?? p.inputRef,
96
+ onChange: l.onChange,
97
+ loading: s.loading,
98
+ options: U,
99
+ onChangeFilterParmsLocal: o ? M : void 0,
100
+ refresh: v,
101
+ onOpen: w,
102
+ onClose: q
80
103
  }
81
104
  );
105
+ return E ? /* @__PURE__ */ T(W, { children: [
106
+ /* @__PURE__ */ T(X, { children: [
107
+ /* @__PURE__ */ A(Z, { children: P }),
108
+ l.addButton
109
+ ] }),
110
+ l.status && /* @__PURE__ */ A($, { role: "status", "aria-live": "polite", children: l.status })
111
+ ] }) : P;
82
112
  }
113
+ const de = H(oe);
83
114
  export {
84
- q as AutocompleteAsync
115
+ de as AutocompleteAsync
85
116
  };
@@ -1,3 +1,4 @@
1
+ import { AutocompleteAddStatus } from './types';
1
2
  import { AutocompleteAsyncSlots } from './slots/AutocompleteAsyncEnum';
2
3
  /**
3
4
  * Key to identify the AutocompleteAsync component in the design system.
@@ -9,5 +10,7 @@ export declare const AUTOCOMPLETE_ASYNC_COMBINED_CLASSES: {
9
10
  root: AutocompleteAsyncSlots.root;
10
11
  };
11
12
  export declare const AUTOCOMPLETE_ASYNC_CLASSES: Record<"root", string>;
12
- export declare const ASYNC_ONLY_KEYS: readonly ["endPoint", "timeout", "parms", "resultField", "isRemote", "isExternalUrl", "responseToCamelCase", "onChangeFilterParms", "shouldFetch"];
13
+ export declare const ASYNC_ONLY_KEYS: readonly ["add", "endPoint", "timeout", "parms", "resultField", "isRemote", "isExternalUrl", "responseToCamelCase", "onChangeFilterParms", "shouldFetch", "refreshKey", "resetKey", "retainSelectedOptions"];
14
+ export declare const AUTOCOMPLETE_ADD_MESSAGES: Record<AutocompleteAddStatus, string>;
15
+ export declare const AUTOCOMPLETE_ADD_RECENT_OPERATIONS = 32;
13
16
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/components/src/components/extended/mui/AutocompleteAsync/constants.ts"],"names":[],"mappings":"AACA,OAAO,EAAyC,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAE9G;;;;GAIG;AACH,eAAO,MAAM,gCAAgC,yBAAyB,CAAC;AAEvE,eAAO,MAAM,mCAAmC;;CAG/C,CAAC;AAEF,eAAO,MAAM,0BAA0B,wBAGtC,CAAC;AAEF,eAAO,MAAM,eAAe,oJAUlB,CAAC"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/components/src/components/extended/mui/AutocompleteAsync/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAErD,OAAO,EAAyC,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAE9G;;;;GAIG;AACH,eAAO,MAAM,gCAAgC,yBAAyB,CAAC;AAEvE,eAAO,MAAM,mCAAmC;;CAG/C,CAAC;AAEF,eAAO,MAAM,0BAA0B,wBAGtC,CAAC;AAEF,eAAO,MAAM,eAAe,8MAclB,CAAC;AAGX,eAAO,MAAM,yBAAyB,EAAE,MAAM,CAAC,qBAAqB,EAAE,MAAM,CAM3E,CAAC;AAEF,eAAO,MAAM,kCAAkC,KAAK,CAAC"}
@@ -1,14 +1,15 @@
1
1
  import { getComponentClasses as e } from "../../../../utils/getComponentSlotRoot.js";
2
- import { AutocompleteAsyncComplementaryClasses as o, AutocompleteAsyncSlots as t } from "./slots/AutocompleteAsyncEnum.js";
3
- const s = "M4LAutocompleteAsync", m = {
4
- ...t,
5
- ...o
2
+ import { AutocompleteAsyncComplementaryClasses as t, AutocompleteAsyncSlots as o } from "./slots/AutocompleteAsyncEnum.js";
3
+ const n = "M4LAutocompleteAsync", r = {
4
+ ...o,
5
+ ...t
6
6
  };
7
7
  e(
8
- s,
9
- m
8
+ n,
9
+ r
10
10
  );
11
- const l = [
11
+ const c = [
12
+ "add",
12
13
  "endPoint",
13
14
  "timeout",
14
15
  "parms",
@@ -17,10 +18,21 @@ const l = [
17
18
  "isExternalUrl",
18
19
  "responseToCamelCase",
19
20
  "onChangeFilterParms",
20
- "shouldFetch"
21
- ];
21
+ "shouldFetch",
22
+ "refreshKey",
23
+ "resetKey",
24
+ "retainSelectedOptions"
25
+ ], l = {
26
+ pending: "Waiting for the new record.",
27
+ created: "Record created.",
28
+ cancelled: "Creation cancelled.",
29
+ unavailable: "Record created. Refresh the options to select it when available.",
30
+ error: "Could not complete this action. Try again."
31
+ }, i = 32;
22
32
  export {
23
- l as ASYNC_ONLY_KEYS,
24
- m as AUTOCOMPLETE_ASYNC_COMBINED_CLASSES,
25
- s as AUTOCOMPLETE_ASYNC_KEY_COMPONENT
33
+ c as ASYNC_ONLY_KEYS,
34
+ l as AUTOCOMPLETE_ADD_MESSAGES,
35
+ i as AUTOCOMPLETE_ADD_RECENT_OPERATIONS,
36
+ r as AUTOCOMPLETE_ASYNC_COMBINED_CLASSES,
37
+ n as AUTOCOMPLETE_ASYNC_KEY_COMPONENT
26
38
  };
@@ -0,0 +1,9 @@
1
+ import { AutocompleteAsyncProps } from '../types';
2
+ /** Manage optional creation, correlated invalidation and focus within the existing async selector. */
3
+ export declare function useAutocompleteAdd<T>(props: AutocompleteAsyncProps<T>): {
4
+ refreshKey: string | undefined;
5
+ onChange: (event: import('../..').AutocompleteValueChangeEvent<T> | undefined, value: T | T[] | null, reason: import('@mui/material').AutocompleteChangeReason) => void;
6
+ addButton: import("@emotion/react/jsx-runtime").JSX.Element | null;
7
+ status: string | undefined;
8
+ };
9
+ //# sourceMappingURL=useAutocompleteAdd.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAutocompleteAdd.d.ts","sourceRoot":"","sources":["../../../../../../../../../packages/components/src/components/extended/mui/AutocompleteAsync/hooks/useAutocompleteAdd.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAyB,sBAAsB,EAA0B,MAAM,UAAU,CAAC;AAEtG,sGAAsG;AACtG,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,KAAK,EAAE,sBAAsB,CAAC,CAAC,CAAC;;;;;EAkIrE"}
@@ -0,0 +1,97 @@
1
+ import { jsx as p } from "@emotion/react/jsx-runtime";
2
+ import { deepEqual as w } from "fast-equals";
3
+ import { useRef as d, useState as O, useCallback as _, useEffect as h } from "react";
4
+ import { AutocompleteAddButton as q } from "../AutocompleteAddButton.js";
5
+ import { AUTOCOMPLETE_ADD_RECENT_OPERATIONS as M, AUTOCOMPLETE_ADD_MESSAGES as R } from "../constants.js";
6
+ function B(r) {
7
+ const { add: o, resetKey: s, refreshKey: a } = r, f = d(r);
8
+ f.current = r;
9
+ const u = d({ value: r.value, version: 0 });
10
+ w(u.current.value, r.value) || (u.current = { value: r.value, version: u.current.version + 1 });
11
+ const l = d(null), v = d(null), b = d(!1), [y, m] = O(!1), [g, c] = O(), [C, k] = O({ resetKey: s, key: a }), i = d(new Set(a ? [a] : [])), A = _((e) => {
12
+ i.current.has(e) || (i.current.add(e), i.current.size > M && i.current.delete(i.current.values().next().value), k({ resetKey: f.current.resetKey, key: e }));
13
+ }, []);
14
+ h(() => {
15
+ m(!1), c(void 0);
16
+ const e = f.current.refreshKey;
17
+ return i.current = new Set(e ? [e] : []), k((t) => t.resetKey === s && t.key === e ? t : { resetKey: s, key: e }), () => {
18
+ l.current?.controller.abort(), l.current = null;
19
+ };
20
+ }, [s]), h(() => {
21
+ a && A(a);
22
+ }, [a, A]), h(() => {
23
+ !y && b.current && (b.current = !1, v.current?.isConnected && v.current.focus());
24
+ }, [y]);
25
+ const S = async () => {
26
+ if (!o || r.disabled || r.readOnly || o.disabled || l.current)
27
+ return;
28
+ const e = {
29
+ controller: new AbortController(),
30
+ selectionVersion: u.current.version,
31
+ resetKey: s
32
+ };
33
+ l.current = e, m(!0), c("pending");
34
+ try {
35
+ const t = await o.action({ requestId: crypto.randomUUID(), signal: e.controller.signal });
36
+ if (l.current !== e || e.controller.signal.aborted)
37
+ return;
38
+ const n = f.current;
39
+ if (n.resetKey !== e.resetKey)
40
+ return;
41
+ if (t.status === "cancelled") {
42
+ c("cancelled");
43
+ return;
44
+ }
45
+ if (A(t.operationId), c(t.option === null ? "unavailable" : "created"), t.option === null || n.add?.selectCreated === !1 || n.disabled || n.readOnly || u.current.version !== e.selectionVersion)
46
+ return;
47
+ const E = t.option, K = Array.isArray(n.value) ? n.value : [], P = n.multiple ? K.some((T) => n.isOptionEqualToValue(T, E)) ? K : [...K, E] : E;
48
+ try {
49
+ n.onChange({ target: { value: P } }, P, "selectOption");
50
+ } catch {
51
+ c("unavailable");
52
+ }
53
+ } catch (t) {
54
+ if (l.current !== e || e.controller.signal.aborted)
55
+ return;
56
+ c("error");
57
+ try {
58
+ o.onError?.(t);
59
+ } catch {
60
+ }
61
+ } finally {
62
+ l.current === e && (l.current = null, b.current = !0, m(!1));
63
+ }
64
+ }, D = (e, t, n) => {
65
+ u.current.version += 1, r.onChange(e, t, n);
66
+ };
67
+ return {
68
+ // Without creation, preserve every legacy refresh-key change, including a cleared key.
69
+ refreshKey: o && C.resetKey === s ? C.key : a,
70
+ onChange: D,
71
+ addButton: o && !r.readOnly ? /* @__PURE__ */ p(
72
+ q,
73
+ {
74
+ buttonRef: v,
75
+ type: "button",
76
+ tooltip: o.label,
77
+ "aria-label": o.label,
78
+ "aria-busy": y,
79
+ disabled: r.disabled || o.disabled || y,
80
+ size: r.size,
81
+ onMouseDown: (e) => {
82
+ e.stopPropagation();
83
+ },
84
+ onKeyDown: (e) => {
85
+ (e.key === "Enter" || e.key === " ") && e.stopPropagation();
86
+ },
87
+ onClick: (e) => {
88
+ e.stopPropagation(), S();
89
+ }
90
+ }
91
+ ) : null,
92
+ status: g ? o?.messages?.[g] ?? R[g] : void 0
93
+ };
94
+ }
95
+ export {
96
+ B as useAutocompleteAdd
97
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"useFetchOptions.d.ts","sourceRoot":"","sources":["../../../../../../../../../packages/components/src/components/extended/mui/AutocompleteAsync/hooks/useFetchOptions.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAG7D;;GAEG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,KAAK,EAAE,oBAAoB,CAAC,CAAC,CAAC,QAqFhE"}
1
+ {"version":3,"file":"useFetchOptions.d.ts","sourceRoot":"","sources":["../../../../../../../../../packages/components/src/components/extended/mui/AutocompleteAsync/hooks/useFetchOptions.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAG7D;;GAEG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,KAAK,EAAE,oBAAoB,CAAC,CAAC,CAAC,QAyFhE"}
@@ -1,62 +1,63 @@
1
- import { useRef as h, useEffect as F } from "react";
2
- import { actionsType as n } from "../types.js";
3
- import { useNetwork as A, getPropertyByString as P } from "@m4l/core";
4
- function b(C) {
1
+ import { useRef as o, useEffect as C } from "react";
2
+ import { actionsType as a } from "../types.js";
3
+ import { useNetwork as P, getPropertyByString as S } from "@m4l/core";
4
+ function w(O) {
5
5
  const {
6
- state: t,
7
- dispatch: r,
8
- endPoint: a,
9
- timeout: i,
10
- isExternalUrl: s,
11
- parms: o,
12
- responseToCamelCase: c,
13
- isRemote: u,
14
- resultField: f = "data"
15
- } = C, { networkOperation: l } = A(), e = h(null), p = h(t.fireFetchCount);
16
- F(() => {
17
- r({ type: n.SET_PARAMS, payload: o });
18
- }, [o, r]), F(() => {
19
- let y = !1;
20
- if (p.current !== t.fireFetchCount)
21
- return p.current = t.fireFetchCount, t.fireFetchCount > 0 && (e.current && e.current.abort(), e.current = new AbortController(), l({
6
+ state: r,
7
+ dispatch: e,
8
+ endPoint: s,
9
+ timeout: c,
10
+ isExternalUrl: i,
11
+ parms: u,
12
+ responseToCamelCase: p,
13
+ isRemote: f,
14
+ resultField: l = "data"
15
+ } = O, { networkOperation: m } = P(), y = o(m);
16
+ y.current = m;
17
+ const t = o(null), h = o(r.fireFetchCount);
18
+ C(() => {
19
+ e({ type: a.SET_PARAMS, payload: u });
20
+ }, [u, e]), C(() => {
21
+ let n = !1;
22
+ if (h.current !== r.fireFetchCount)
23
+ return h.current = r.fireFetchCount, r.fireFetchCount > 0 && (t.current && t.current.abort(), t.current = new AbortController(), y.current({
22
24
  method: "GET",
23
- endPoint: a,
24
- timeout: i,
25
- isExternalUrl: s,
26
- parms: { ...o, ...t.queryParams },
27
- responseToCamelCase: c,
28
- isRemote: u,
29
- signal: e.current.signal
30
- }).then((O) => {
31
- if (y)
25
+ endPoint: s,
26
+ timeout: c,
27
+ isExternalUrl: i,
28
+ parms: { ...r.parms, ...r.queryParams },
29
+ responseToCamelCase: p,
30
+ isRemote: f,
31
+ signal: t.current.signal
32
+ }).then((d) => {
33
+ if (n)
32
34
  return;
33
- const m = P(O, f), d = Array.isArray(m) ? m : [];
34
- r({
35
- type: n.FINISH_LOAD_OPTIONS,
36
- payload: { options: d }
35
+ const F = S(d, l), A = Array.isArray(F) ? F : [];
36
+ e({
37
+ type: a.FINISH_LOAD_OPTIONS,
38
+ payload: { options: A }
37
39
  });
38
40
  }).catch(() => {
39
- r({
40
- type: n.FINISH_LOAD_OPTIONS,
41
+ n || e({
42
+ type: a.FINISH_LOAD_OPTIONS,
41
43
  payload: {}
42
44
  });
43
45
  })), () => {
44
- y = !0, e.current && e.current.abort();
46
+ n = !0, t.current && t.current.abort();
45
47
  };
46
48
  }, [
47
- r,
48
- a,
49
+ e,
49
50
  s,
50
- u,
51
- l,
52
- o,
53
- c,
51
+ i,
54
52
  f,
55
- t.fireFetchCount,
56
- t.queryParams,
57
- i
53
+ r.parms,
54
+ p,
55
+ l,
56
+ r.fireFetchCount,
57
+ r.queryParams,
58
+ c
58
59
  ]);
59
60
  }
60
61
  export {
61
- b as useFetchOptions
62
+ w as useFetchOptions
62
63
  };
@@ -1,5 +1,5 @@
1
1
  export { AutocompleteAsync } from './AutocompleteAsync';
2
- export type { AutocompleteAsyncProps } from './types';
2
+ export type { AutocompleteAsyncProps, AutocompleteAddContext, AutocompleteAddResult, AutocompleteAddAction } from './types';
3
3
  export { useFetchOptions } from './hooks/useFetchOptions';
4
4
  export { autocompleteAsyncReducer, getInitialStateAutocompleteAsync } from './reducer/AutocompleteAsyncReducer';
5
5
  export { actionsType } from './types';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/components/src/components/extended/mui/AutocompleteAsync/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,YAAY,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,wBAAwB,EAAE,gCAAgC,EAAE,MAAM,oCAAoC,CAAC;AAChH,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/components/src/components/extended/mui/AutocompleteAsync/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,YAAY,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAC5H,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,wBAAwB,EAAE,gCAAgC,EAAE,MAAM,oCAAoC,CAAC;AAChH,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"AutocompleteAsyncReducer.d.ts","sourceRoot":"","sources":["../../../../../../../../../packages/components/src/components/extended/mui/AutocompleteAsync/reducer/AutocompleteAsyncReducer.ts"],"names":[],"mappings":"AACA,OAAO,EACL,uBAAuB,EAEvB,sBAAsB,EACtB,mBAAmB,EACpB,MAAM,UAAU,CAAC;AAElB,KAAK,oBAAoB,GAAG;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;CAC3C,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,gCAAgC,CAAC,CAAC,EAChD,KAAK,EAAE,oBAAoB,GAC1B,sBAAsB,CAAC,CAAC,CAAC,CAU3B;AAED;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,EACxC,mBAAmB,CAAC,EAAE,mBAAmB,IAGvC,OAAO,sBAAsB,CAAC,CAAC,CAAC,EAChC,QAAQ,uBAAuB,CAAC,CAAC,CAAC,KACjC,sBAAsB,CAAC,CAAC,CAAC,CAgE7B"}
1
+ {"version":3,"file":"AutocompleteAsyncReducer.d.ts","sourceRoot":"","sources":["../../../../../../../../../packages/components/src/components/extended/mui/AutocompleteAsync/reducer/AutocompleteAsyncReducer.ts"],"names":[],"mappings":"AACA,OAAO,EACL,uBAAuB,EAEvB,sBAAsB,EACtB,mBAAmB,EACpB,MAAM,UAAU,CAAC;AAElB,KAAK,oBAAoB,GAAG;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;CAC3C,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,gCAAgC,CAAC,CAAC,EAChD,KAAK,EAAE,oBAAoB,GAC1B,sBAAsB,CAAC,CAAC,CAAC,CAU3B;AAED;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,EACxC,mBAAmB,CAAC,EAAE,mBAAmB,IAGvC,OAAO,sBAAsB,CAAC,CAAC,CAAC,EAChC,QAAQ,uBAAuB,CAAC,CAAC,CAAC,KACjC,sBAAsB,CAAC,CAAC,CAAC,CAsF7B"}
@@ -1,64 +1,86 @@
1
1
  import { deepEqual as i } from "fast-equals";
2
- import { actionsType as u } from "../types.js";
3
- function t(o) {
2
+ import { actionsType as o } from "../types.js";
3
+ function s(u) {
4
4
  return {
5
5
  fireFetchCount: 0,
6
6
  options: [],
7
- parms: o.parms,
7
+ parms: u.parms,
8
8
  loading: !1,
9
- queryParams: o.onChangeFilterParms ? o.onChangeFilterParms("") : {},
9
+ queryParams: u.onChangeFilterParms ? u.onChangeFilterParms("") : {},
10
10
  isOpen: !1,
11
11
  firstOpen: !0
12
12
  };
13
13
  }
14
- function a(o) {
15
- return (r, e) => {
16
- switch (e.type) {
17
- case u.REFRESH:
14
+ function l(u) {
15
+ return (r, n) => {
16
+ switch (n.type) {
17
+ case o.REFRESH:
18
18
  return {
19
19
  ...r,
20
+ loading: !0,
20
21
  fireFetchCount: r.fireFetchCount + 1
21
22
  };
22
- case u.SET_PARAMS:
23
- if (i(r.parms, e.payload))
23
+ case o.INVALIDATE: {
24
+ const e = r.isOpen && !n.noFetch;
25
+ return {
26
+ ...r,
27
+ firstOpen: !e,
28
+ loading: e || r.loading,
29
+ fireFetchCount: r.fireFetchCount + (e ? 1 : 0)
30
+ };
31
+ }
32
+ case o.RESET: {
33
+ const e = r.isOpen && !n.noFetch;
34
+ return {
35
+ ...r,
36
+ options: [],
37
+ queryParams: n.queryParams ?? r.queryParams,
38
+ firstOpen: !e,
39
+ loading: e,
40
+ fireFetchCount: e ? r.fireFetchCount + 1 : 0
41
+ };
42
+ }
43
+ case o.SET_PARAMS:
44
+ if (i(r.parms, n.payload))
24
45
  return r;
25
46
  {
26
- const n = o ? o("") : r.queryParams;
47
+ const e = u ? u("") : r.queryParams;
27
48
  return {
28
49
  ...r,
29
- parms: e.payload,
50
+ parms: n.payload,
30
51
  fireFetchCount: 0,
31
52
  firstOpen: !0,
32
53
  options: [],
33
- queryParams: n
54
+ queryParams: e
34
55
  };
35
56
  }
36
- case u.SET_QUERY_PARAMS:
37
- return i(r.queryParams, e.payload) ? r : {
57
+ case o.SET_QUERY_PARAMS:
58
+ return i(r.queryParams, n.payload) ? r : {
38
59
  ...r,
39
- queryParams: e.payload,
60
+ queryParams: n.payload,
61
+ loading: !0,
40
62
  fireFetchCount: r.fireFetchCount + 1
41
63
  };
42
- case u.FINISH_LOAD_OPTIONS: {
43
- const n = e.payload?.options ?? r.options, p = e.payload?.options ? r.firstOpen : !0;
64
+ case o.FINISH_LOAD_OPTIONS: {
65
+ const e = n.payload?.options ?? r.options, f = n.payload?.options ? r.firstOpen : !0;
44
66
  return {
45
67
  ...r,
46
- options: n,
68
+ options: e,
47
69
  loading: !1,
48
- firstOpen: p
70
+ firstOpen: f
49
71
  };
50
72
  }
51
- case u.OPEN: {
52
- const n = r.firstOpen && !e.noFetch;
73
+ case o.OPEN: {
74
+ const e = r.firstOpen && !n.noFetch;
53
75
  return {
54
76
  ...r,
55
77
  isOpen: !0,
56
- fireFetchCount: n ? r.fireFetchCount + 1 : r.fireFetchCount,
57
- firstOpen: n ? !1 : r.firstOpen,
58
- loading: n ? !0 : r.loading
78
+ fireFetchCount: e ? r.fireFetchCount + 1 : r.fireFetchCount,
79
+ firstOpen: e ? !1 : r.firstOpen,
80
+ loading: e ? !0 : r.loading
59
81
  };
60
82
  }
61
- case u.CLOSE:
83
+ case o.CLOSE:
62
84
  return {
63
85
  ...r,
64
86
  isOpen: !1
@@ -69,6 +91,6 @@ function a(o) {
69
91
  };
70
92
  }
71
93
  export {
72
- a as autocompleteAsyncReducer,
73
- t as getInitialStateAutocompleteAsync
94
+ l as autocompleteAsyncReducer,
95
+ s as getInitialStateAutocompleteAsync
74
96
  };
@@ -0,0 +1,6 @@
1
+ export declare const AutocompleteAddRoot: import('@emotion/styled').StyledComponent<Omit<import('../..').StackProps, "ref"> & import('react').RefAttributes<HTMLDivElement> & import('@mui/system').MUIStyledCommonProps<import('@mui/material').Theme>, {}, {}>;
2
+ export declare const AutocompleteAddRow: import('@emotion/styled').StyledComponent<import('@mui/system').MUIStyledCommonProps<import('@mui/material').Theme>, import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
3
+ export declare const AutocompleteAddInput: import('@emotion/styled').StyledComponent<import('@mui/system').MUIStyledCommonProps<import('@mui/material').Theme>, import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
4
+ export declare const AutocompleteAddIconContainer: import('@emotion/styled').StyledComponent<import('@mui/system').MUIStyledCommonProps<import('@mui/material').Theme>, import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, {}>;
5
+ export declare const AutocompleteAddStatusText: import('@emotion/styled').StyledComponent<Omit<import('@m4l/base').TypographyProps, "ref"> & import('react').RefAttributes<HTMLSpanElement> & import('@mui/system').MUIStyledCommonProps<import('@mui/material').Theme>, {}, {}>;
6
+ //# sourceMappingURL=addStyled.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addStyled.d.ts","sourceRoot":"","sources":["../../../../../../../../../packages/components/src/components/extended/mui/AutocompleteAsync/slots/addStyled.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,mBAAmB,wNAAgD,CAAC;AAEjF,eAAO,MAAM,kBAAkB,6NAM5B,CAAC;AACJ,eAAO,MAAM,oBAAoB,6NAAiD,CAAC;AAEnF,eAAO,MAAM,4BAA4B,+NAA4D,CAAC;AACtG,eAAO,MAAM,yBAAyB,kOAEnC,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { styled as t } from "@mui/material/styles";
2
+ import { Stack as e } from "../../Stack/Stack.js";
3
+ import { Typography as i } from "../../Typography/Typography.js";
4
+ const s = t(e)({ width: "100%", minWidth: 0 }), m = t("div")(({ theme: o }) => ({
5
+ display: "flex",
6
+ alignItems: "center",
7
+ gap: o.vars.size.baseSpacings.sp1,
8
+ width: "100%",
9
+ minWidth: 0
10
+ })), c = t("div")({ flex: "1 1 0%", minWidth: 0 }), a = t("span")({ display: "inline-flex", flexShrink: 0 }), l = t(i)(({ theme: o }) => ({
11
+ marginTop: o.spacing(0.5)
12
+ }));
13
+ export {
14
+ a as AutocompleteAddIconContainer,
15
+ c as AutocompleteAddInput,
16
+ s as AutocompleteAddRoot,
17
+ m as AutocompleteAddRow,
18
+ l as AutocompleteAddStatusText
19
+ };