@code0-tech/pictor 0.11.0 → 0.12.0

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 (28) hide show
  1. package/dist/assets/components/avatar/Avatar.style.css +1 -1
  2. package/dist/assets/components/card/Card.style.css +1 -1
  3. package/dist/assets/components/context-menu/ContextMenu.style.css +1 -1
  4. package/dist/assets/components/data-table/DataTable.style.css +1 -1
  5. package/dist/assets/components/form/Input.style.css +1 -1
  6. package/dist/assets/components/menu/Menu.style.css +1 -1
  7. package/dist/assets/components/scroll-area/ScrollArea.style.css +1 -1
  8. package/dist/assets/components/tooltip/Tooltip.style.css +1 -1
  9. package/dist/components/avatar/Avatar.js +17 -16
  10. package/dist/components/card/Card.d.ts +1 -0
  11. package/dist/components/card/Card.js +25 -23
  12. package/dist/components/context-menu/ContextMenu.js +109 -90
  13. package/dist/components/data-table/DataTable.d.ts +4 -1
  14. package/dist/components/data-table/DataTable.js +53 -31
  15. package/dist/components/data-table/DataTableHeader.d.ts +14 -0
  16. package/dist/components/data-table/DataTableHeader.js +39 -0
  17. package/dist/components/data-table/DataTablePagination.d.ts +30 -0
  18. package/dist/components/data-table/DataTablePagination.js +75 -0
  19. package/dist/components/data-table/index.d.ts +2 -0
  20. package/dist/components/data-table/index.js +16 -5
  21. package/dist/components/form/PinInput.js +44 -47
  22. package/dist/components/form/useForm.js +61 -46
  23. package/dist/components/menu/Menu.js +112 -93
  24. package/dist/components/scroll-area/ScrollArea.d.ts +8 -0
  25. package/dist/components/scroll-area/ScrollArea.js +70 -39
  26. package/dist/components/tooltip/Tooltip.js +53 -43
  27. package/dist/index.js +203 -191
  28. package/package.json +11 -11
@@ -1,42 +1,64 @@
1
- import { jsxs as _, jsx as p } from "react/jsx-runtime";
2
- import g from "react";
1
+ import { jsxs as x, jsx as y } from "react/jsx-runtime";
2
+ import c from "react";
3
3
  import '../../assets/components/data-table/DataTable.style.css';/* empty css */
4
4
  import "../../utils/contextStore.js";
5
- import { mergeComponentProps as h } from "../../utils/component.js";
5
+ import { mergeComponentProps as E } from "../../utils/component.js";
6
6
  import "js-md5";
7
- const d = (l, m) => m.split(".").reduce((t, f) => {
8
- if (t != null)
9
- return Array.isArray(t) ? t.map((a) => a?.[f]).filter((a) => a !== void 0) : t[f];
10
- }, l), w = (l) => {
7
+ import { Flex as F } from "../flex/Flex.js";
8
+ import { DataTableHeader as R } from "./DataTableHeader.js";
9
+ import { DataTablePaginationContext as v } from "./DataTablePagination.js";
10
+ const C = (u, p) => p.split(".").reduce((n, m) => {
11
+ if (n != null)
12
+ return Array.isArray(n) ? n.map((i) => i?.[m]).filter((i) => i !== void 0) : n[m];
13
+ }, u), U = (u) => {
11
14
  const {
12
- data: m,
13
- sort: t,
14
- filter: f,
15
- loading: a,
16
- loadingComponent: C,
17
- emptyComponent: A,
18
- onSelect: u,
19
- children: O,
20
- ...b
21
- } = l, y = m.filter((i) => Object.entries(f || {}).every(([o, {
22
- operator: n,
23
- value: r
15
+ data: p,
16
+ sort: n,
17
+ filter: m,
18
+ limit: i,
19
+ pagination: A,
20
+ loading: _,
21
+ loadingComponent: z,
22
+ emptyComponent: D,
23
+ onSelect: N,
24
+ children: g,
25
+ ...k
26
+ } = u, [b, P] = c.useState(0), h = Array.isArray(g) ? g : [g], w = h.find((r) => typeof r == "function"), V = h.find((r) => c.isValidElement(r) && r.type === R), S = h.filter((r) => typeof r != "function" && r !== V), O = p.filter((r) => Object.entries(m || {}).every(([o, {
27
+ operator: a,
28
+ value: e
24
29
  }]) => {
25
- const e = d(i, o);
26
- return n === "isOneOf" && !Array.isArray(r) && !Array.isArray(e) ? e === r : n === "isOneOf" && !Array.isArray(r) && Array.isArray(e) ? Array.from(e).includes(r) : n === "isOneOf" && Array.isArray(r) && !Array.isArray(e) ? Array.from(r).some((s) => s === e) : n === "isOneOf" && Array.isArray(r) && Array.isArray(e) ? Array.from(r).some((s) => Array.from(e).includes(s)) : !1;
27
- })), c = g.useMemo(() => t ? [...y].sort((i, o) => {
28
- for (const [n, r] of Object.entries(t)) {
29
- const e = d(i, n), s = d(o, n);
30
- if (e < s) return r === "asc" ? -1 : 1;
31
- if (e > s) return r === "asc" ? 1 : -1;
30
+ const t = C(r, o);
31
+ return a === "isOneOf" && !Array.isArray(e) && !Array.isArray(t) ? t === e : a === "isOneOf" && !Array.isArray(e) && Array.isArray(t) ? Array.from(t).includes(e) : a === "isOneOf" && Array.isArray(e) && !Array.isArray(t) ? Array.from(e).some((l) => l === t) : a === "isOneOf" && Array.isArray(e) && Array.isArray(t) ? Array.from(e).some((l) => Array.from(t).includes(l)) : !1;
32
+ })), f = c.useMemo(() => n ? [...O].sort((r, o) => {
33
+ for (const [a, e] of Object.entries(n)) {
34
+ const t = C(r, a), l = C(o, a);
35
+ if (t < l) return e === "asc" ? -1 : 1;
36
+ if (t > l) return e === "asc" ? 1 : -1;
32
37
  }
33
38
  return 0;
34
- }) : y, [y, t]);
35
- return /* @__PURE__ */ _("table", { ...h("data-table", b), children: [
36
- c.map((i, o) => /* @__PURE__ */ p("tr", { className: "data-table__row", onClick: () => u?.(i), children: O?.(i, o) })),
37
- c.length === 0 && !a && A ? /* @__PURE__ */ p("tr", { className: "data-table__row", onClick: () => u?.(void 0), children: A }) : null
39
+ }) : O, [O, n]), d = typeof i == "number" ? i : 10, j = A ? Math.max(1, Math.ceil(f.length / d)) : 1, s = Math.min(b, j - 1);
40
+ c.useEffect(() => {
41
+ b !== s && P(s);
42
+ }, [b, s]);
43
+ const T = A ? f.slice(s * d, s * d + d) : typeof i == "number" ? f.slice(0, i) : f, M = /* @__PURE__ */ x("table", { ...E("data-table", k), children: [
44
+ V,
45
+ /* @__PURE__ */ x("tbody", { children: [
46
+ T.map((r, o) => /* @__PURE__ */ y("tr", { className: "data-table__row", onClick: () => N?.(r), children: w?.(r, o) })),
47
+ f.length === 0 && !_ && D ? /* @__PURE__ */ y("tr", { className: "data-table__row", onClick: () => N?.(void 0), children: D }) : null
48
+ ] })
38
49
  ] });
50
+ return A ? /* @__PURE__ */ y(v.Provider, { value: {
51
+ page: s,
52
+ pageCount: j,
53
+ setPage: P
54
+ }, children: /* @__PURE__ */ x(F, { style: {
55
+ flexDirection: "column",
56
+ gap: "0.5rem"
57
+ }, children: [
58
+ M,
59
+ S.map((r, o) => /* @__PURE__ */ y(c.Fragment, { children: r }, o))
60
+ ] }) }) : M;
39
61
  };
40
62
  export {
41
- w as DataTable
63
+ U as DataTable
42
64
  };
@@ -0,0 +1,14 @@
1
+ import { default as React } from 'react';
2
+ import { Component } from '../../utils';
3
+ export interface DataTableHeaderProps extends Component<HTMLTableSectionElement> {
4
+ children?: React.ReactNode | React.ReactNode[];
5
+ }
6
+ /**
7
+ * Optional header for a <DataTable/>. Place it as a child (alongside the row renderer) and fill it
8
+ * with <DataTableHeaderColumn/> cells that line up with the columns your row renderer emits.
9
+ */
10
+ export declare const DataTableHeader: React.FC<DataTableHeaderProps>;
11
+ export interface DataTableHeaderColumnProps extends Component<HTMLTableCellElement> {
12
+ children?: React.ReactNode | React.ReactNode[];
13
+ }
14
+ export declare const DataTableHeaderColumn: React.FC<DataTableHeaderColumnProps>;
@@ -0,0 +1,39 @@
1
+ import { jsx as n } from "react/jsx-runtime";
2
+ import { c } from "../../_virtual/compiler-runtime.js";
3
+ import "../../utils/contextStore.js";
4
+ import "react";
5
+ import { mergeComponentProps as m } from "../../utils/component.js";
6
+ import "js-md5";
7
+ const p = (a) => {
8
+ const e = c.c(8);
9
+ let t, r;
10
+ if (e[0] !== a) {
11
+ const {
12
+ children: i,
13
+ ...s
14
+ } = a;
15
+ t = i, r = m("data-table__header", s), e[0] = a, e[1] = t, e[2] = r;
16
+ } else
17
+ t = e[1], r = e[2];
18
+ let l;
19
+ e[3] !== t ? (l = /* @__PURE__ */ n("tr", { className: "data-table__header-row", children: t }), e[3] = t, e[4] = l) : l = e[4];
20
+ let o;
21
+ return e[5] !== r || e[6] !== l ? (o = /* @__PURE__ */ n("thead", { ...r, children: l }), e[5] = r, e[6] = l, e[7] = o) : o = e[7], o;
22
+ }, x = (a) => {
23
+ const e = c.c(6);
24
+ let t, r;
25
+ if (e[0] !== a) {
26
+ const {
27
+ children: o,
28
+ ...i
29
+ } = a;
30
+ t = o, r = m("data-table__header-column", i), e[0] = a, e[1] = t, e[2] = r;
31
+ } else
32
+ t = e[1], r = e[2];
33
+ let l;
34
+ return e[3] !== t || e[4] !== r ? (l = /* @__PURE__ */ n("th", { ...r, children: t }), e[3] = t, e[4] = r, e[5] = l) : l = e[5], l;
35
+ };
36
+ export {
37
+ p as DataTableHeader,
38
+ x as DataTableHeaderColumn
39
+ };
@@ -0,0 +1,30 @@
1
+ import { default as React } from 'react';
2
+ import { Component } from '../../utils';
3
+ export interface DataTablePaginationContextValue {
4
+ page: number;
5
+ pageCount: number;
6
+ setPage: React.Dispatch<React.SetStateAction<number>>;
7
+ }
8
+ export declare const DataTablePaginationContext: React.Context<DataTablePaginationContextValue | null>;
9
+ export declare const useDataTablePagination: () => DataTablePaginationContextValue;
10
+ export interface DataTablePaginationProps extends Component<HTMLDivElement> {
11
+ }
12
+ /**
13
+ * Layout container for the pagination controls. Place it as a child of a paginated
14
+ * <DataTable/>, which creates the context these controls read from. Fully styleable –
15
+ * compose it with <DataTablePaginationValue/>, the triggers and your own <Text/>/<Button/>.
16
+ */
17
+ export declare const DataTablePagination: React.FC<DataTablePaginationProps>;
18
+ /**
19
+ * Renders the 1-indexed current page number. Unstyled – wrap it in your own <Text/> to style it.
20
+ */
21
+ export declare const DataTablePaginationValue: React.FC;
22
+ /**
23
+ * Renders the total number of pages. Unstyled – wrap it in your own <Text/> to style it.
24
+ */
25
+ export declare const DataTableMaxPaginationValue: React.FC;
26
+ export interface DataTablePaginationTriggerProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
27
+ asChild?: boolean;
28
+ }
29
+ export declare const DataTablePaginationForwardTrigger: React.ForwardRefExoticComponent<DataTablePaginationTriggerProps & React.RefAttributes<HTMLButtonElement>>;
30
+ export declare const DataTablePaginationBackwardsTrigger: React.ForwardRefExoticComponent<DataTablePaginationTriggerProps & React.RefAttributes<HTMLButtonElement>>;
@@ -0,0 +1,75 @@
1
+ import { jsx as r, Fragment as f } from "react/jsx-runtime";
2
+ import { c } from "../../_virtual/compiler-runtime.js";
3
+ import i from "react";
4
+ import "../../utils/contextStore.js";
5
+ import { mergeComponentProps as x } from "../../utils/component.js";
6
+ import "js-md5";
7
+ const h = i.createContext(null), d = () => {
8
+ const a = i.useContext(h);
9
+ if (!a)
10
+ throw new Error("DataTablePagination components must be rendered inside a paginated <DataTable/>");
11
+ return a;
12
+ }, V = (a) => {
13
+ const e = c.c(4);
14
+ let t;
15
+ e[0] !== a ? (t = x("data-table__pagination", a), e[0] = a, e[1] = t) : t = e[1];
16
+ let n;
17
+ return e[2] !== t ? (n = /* @__PURE__ */ r("div", { ...t }), e[2] = t, e[3] = n) : n = e[3], n;
18
+ }, y = () => {
19
+ const a = c.c(2), {
20
+ page: e
21
+ } = d(), t = e + 1;
22
+ let n;
23
+ return a[0] !== t ? (n = /* @__PURE__ */ r(f, { children: t }), a[0] = t, a[1] = n) : n = a[1], n;
24
+ }, B = () => {
25
+ const a = c.c(2), {
26
+ pageCount: e
27
+ } = d();
28
+ let t;
29
+ return a[0] !== e ? (t = /* @__PURE__ */ r(f, { children: e }), a[0] = e, a[1] = t) : t = a[1], t;
30
+ }, T = i.forwardRef((a, e) => {
31
+ const {
32
+ page: t,
33
+ pageCount: n,
34
+ setPage: w
35
+ } = d(), {
36
+ direction: g,
37
+ asChild: C,
38
+ onClick: u,
39
+ disabled: P,
40
+ children: l,
41
+ ...p
42
+ } = a, D = g === "forward" ? t >= n - 1 : t <= 0, s = P ?? D, m = () => {
43
+ s || w((o) => g === "forward" ? Math.min(n - 1, o + 1) : Math.max(0, o - 1));
44
+ };
45
+ if (C && i.isValidElement(l)) {
46
+ const o = l;
47
+ return i.cloneElement(o, {
48
+ ref: e,
49
+ disabled: o.props.disabled ?? s,
50
+ onClick: (b) => {
51
+ o.props.onClick?.(b), u?.(b), m();
52
+ }
53
+ });
54
+ }
55
+ return /* @__PURE__ */ r("button", { ...p, ref: e, type: "button", disabled: s, onClick: (o) => {
56
+ u?.(o), m();
57
+ }, children: l });
58
+ }), F = i.forwardRef((a, e) => {
59
+ const t = c.c(3);
60
+ let n;
61
+ return t[0] !== a || t[1] !== e ? (n = /* @__PURE__ */ r(T, { ...a, direction: "forward", ref: e }), t[0] = a, t[1] = e, t[2] = n) : n = t[2], n;
62
+ }), j = i.forwardRef((a, e) => {
63
+ const t = c.c(3);
64
+ let n;
65
+ return t[0] !== a || t[1] !== e ? (n = /* @__PURE__ */ r(T, { ...a, direction: "backward", ref: e }), t[0] = a, t[1] = e, t[2] = n) : n = t[2], n;
66
+ });
67
+ export {
68
+ B as DataTableMaxPaginationValue,
69
+ V as DataTablePagination,
70
+ j as DataTablePaginationBackwardsTrigger,
71
+ h as DataTablePaginationContext,
72
+ F as DataTablePaginationForwardTrigger,
73
+ y as DataTablePaginationValue,
74
+ d as useDataTablePagination
75
+ };
@@ -1,4 +1,6 @@
1
1
  export * from './DataTable';
2
2
  export * from './DataTableColumn';
3
+ export * from './DataTableHeader';
4
+ export * from './DataTablePagination';
3
5
  export * from './DataTableFilterInput';
4
6
  export * from './DataTableFilterSuggestionMenu';
@@ -1,11 +1,22 @@
1
1
  import { DataTable as t } from "./DataTable.js";
2
2
  import { DataTableColumn as o } from "./DataTableColumn.js";
3
- import { DataTableFilterInput as u, createFilterQueryLanguage as m } from "./DataTableFilterInput.js";
4
- import { DataTableFilterSuggestionMenu as p } from "./DataTableFilterSuggestionMenu.js";
3
+ import { DataTableHeader as i, DataTableHeaderColumn as l } from "./DataTableHeader.js";
4
+ import { DataTableMaxPaginationValue as T, DataTablePagination as b, DataTablePaginationBackwardsTrigger as D, DataTablePaginationContext as u, DataTablePaginationForwardTrigger as m, DataTablePaginationValue as x, useDataTablePagination as p } from "./DataTablePagination.js";
5
+ import { DataTableFilterInput as f, createFilterQueryLanguage as d } from "./DataTableFilterInput.js";
6
+ import { DataTableFilterSuggestionMenu as s } from "./DataTableFilterSuggestionMenu.js";
5
7
  export {
6
8
  t as DataTable,
7
9
  o as DataTableColumn,
8
- u as DataTableFilterInput,
9
- p as DataTableFilterSuggestionMenu,
10
- m as createFilterQueryLanguage
10
+ f as DataTableFilterInput,
11
+ s as DataTableFilterSuggestionMenu,
12
+ i as DataTableHeader,
13
+ l as DataTableHeaderColumn,
14
+ T as DataTableMaxPaginationValue,
15
+ b as DataTablePagination,
16
+ D as DataTablePaginationBackwardsTrigger,
17
+ u as DataTablePaginationContext,
18
+ m as DataTablePaginationForwardTrigger,
19
+ x as DataTablePaginationValue,
20
+ d as createFilterQueryLanguage,
21
+ p as useDataTablePagination
11
22
  };
@@ -1,69 +1,66 @@
1
- import { jsx as r, jsxs as F, Fragment as x } from "react/jsx-runtime";
2
- import { c as I } from "../../_virtual/compiler-runtime.js";
3
- import { OneTimePasswordFieldInput as C, OneTimePasswordFieldHiddenInput as M, OneTimePasswordField as T } from "@radix-ui/react-one-time-password-field";
1
+ import { jsx as a, jsxs as v, Fragment as F } from "react/jsx-runtime";
2
+ import { c } from "../../_virtual/compiler-runtime.js";
3
+ import { OneTimePasswordFieldInput as x, OneTimePasswordFieldHiddenInput as C, OneTimePasswordField as M } from "@radix-ui/react-one-time-password-field";
4
4
  import "../../utils/contextStore.js";
5
5
  import "react";
6
6
  import { mergeComponentProps as V } from "../../utils/component.js";
7
7
  import "js-md5";
8
- import { InputLabel as _ } from "./InputLabel.js";
9
- import { InputDescription as $ } from "./InputDescription.js";
10
- import { InputMessage as w } from "./InputMessage.js";
8
+ import { InputLabel as T } from "./InputLabel.js";
9
+ import { InputDescription as _ } from "./InputDescription.js";
10
+ import { InputMessage as $ } from "./InputMessage.js";
11
11
  import '../../assets/components/form/Input.style.css';/* empty css */
12
- const B = (n) => {
13
- const e = I.c(26);
14
- let t, i, d, l, o, s;
12
+ const z = (n) => {
13
+ const e = c.c(20);
14
+ let t, i, s, l, o;
15
15
  if (e[0] !== n) {
16
16
  const {
17
- title: p,
18
- description: c,
19
- disabled: b,
20
- formValidation: P,
21
- ...g
22
- } = n;
23
- i = P === void 0 ? {
17
+ title: u,
18
+ description: f,
19
+ disabled: g,
20
+ formValidation: h,
21
+ ...p
22
+ } = n, P = g === void 0 ? !1 : g;
23
+ i = h === void 0 ? {
24
24
  valid: !0,
25
25
  notValidMessage: null,
26
- setValue: O
27
- } : P, e[7] !== p ? (o = p ? /* @__PURE__ */ r(_, { children: p }) : null, e[7] = p, e[8] = o) : o = e[8], e[9] !== c ? (s = c ? /* @__PURE__ */ r($, { children: c }) : null, e[9] = c, e[10] = s) : s = e[10];
28
- const h = `${i?.valid ? "" : "input--not-valid"}`;
29
- e[11] !== h ? (l = V(h, {}), e[11] = h, e[12] = l) : l = e[12], t = T, d = V("pin-input", {
30
- ...g,
31
- onValueChange: (v) => {
32
- g.onValueChange && g.onValueChange(v), i.setValue?.(v);
26
+ setValue: b
27
+ } : h, e[6] !== u ? (l = u ? /* @__PURE__ */ a(T, { children: u }) : null, e[6] = u, e[7] = l) : l = e[7], e[8] !== f ? (o = f ? /* @__PURE__ */ a(_, { children: f }) : null, e[8] = f, e[9] = o) : o = e[9], t = M, s = V(`pin-input ${i?.valid ? "" : "pin-input--not-valid"}`, {
28
+ ...p,
29
+ disabled: P,
30
+ onValueChange: (I) => {
31
+ p.onValueChange && p.onValueChange(I), i.setValue?.(I);
33
32
  }
34
- }), e[0] = n, e[1] = t, e[2] = i, e[3] = d, e[4] = l, e[5] = o, e[6] = s;
33
+ }), e[0] = n, e[1] = t, e[2] = i, e[3] = s, e[4] = l, e[5] = o;
35
34
  } else
36
- t = e[1], i = e[2], d = e[3], l = e[4], o = e[5], s = e[6];
37
- let a;
38
- e[13] !== t || e[14] !== d ? (a = /* @__PURE__ */ r(t, { ...d }), e[13] = t, e[14] = d, e[15] = a) : a = e[15];
35
+ t = e[1], i = e[2], s = e[3], l = e[4], o = e[5];
36
+ let r;
37
+ e[10] !== t || e[11] !== s ? (r = /* @__PURE__ */ a(t, { ...s }), e[10] = t, e[11] = s, e[12] = r) : r = e[12];
38
+ let d;
39
+ e[13] !== i ? (d = !i?.valid && i?.notValidMessage ? /* @__PURE__ */ a($, { children: i.notValidMessage }) : null, e[13] = i, e[14] = d) : d = e[14];
39
40
  let m;
40
- e[16] !== l || e[17] !== a ? (m = /* @__PURE__ */ r("div", { ...l, children: a }), e[16] = l, e[17] = a, e[18] = m) : m = e[18];
41
- let u;
42
- e[19] !== i ? (u = !i?.valid && i?.notValidMessage ? /* @__PURE__ */ r(w, { children: i.notValidMessage }) : null, e[19] = i, e[20] = u) : u = e[20];
43
- let f;
44
- return e[21] !== o || e[22] !== s || e[23] !== m || e[24] !== u ? (f = /* @__PURE__ */ F(x, { children: [
41
+ return e[15] !== l || e[16] !== o || e[17] !== r || e[18] !== d ? (m = /* @__PURE__ */ v(F, { children: [
42
+ l,
45
43
  o,
46
- s,
47
- m,
48
- u
49
- ] }), e[21] = o, e[22] = s, e[23] = m, e[24] = u, e[25] = f) : f = e[25], f;
50
- }, G = (n) => {
51
- const e = I.c(4);
44
+ r,
45
+ d
46
+ ] }), e[15] = l, e[16] = o, e[17] = r, e[18] = d, e[19] = m) : m = e[19], m;
47
+ }, A = (n) => {
48
+ const e = c.c(4);
52
49
  let t;
53
- e[0] !== n ? (t = V("input pin-input__field", n), e[0] = n, e[1] = t) : t = e[1];
50
+ e[0] !== n ? (t = V("pin-input__field", n), e[0] = n, e[1] = t) : t = e[1];
54
51
  let i;
55
- return e[2] !== t ? (i = /* @__PURE__ */ r(C, { ...t }), e[2] = t, e[3] = i) : i = e[3], i;
56
- }, J = (n) => {
57
- const e = I.c(4);
52
+ return e[2] !== t ? (i = /* @__PURE__ */ a(x, { ...t }), e[2] = t, e[3] = i) : i = e[3], i;
53
+ }, B = (n) => {
54
+ const e = c.c(4);
58
55
  let t;
59
56
  e[0] !== n ? (t = V("pin-input__hidden-field", n), e[0] = n, e[1] = t) : t = e[1];
60
57
  let i;
61
- return e[2] !== t ? (i = /* @__PURE__ */ r(M, { ...t }), e[2] = t, e[3] = i) : i = e[3], i;
58
+ return e[2] !== t ? (i = /* @__PURE__ */ a(C, { ...t }), e[2] = t, e[3] = i) : i = e[3], i;
62
59
  };
63
- function O(n) {
60
+ function b(n) {
64
61
  }
65
62
  export {
66
- B as PinInput,
67
- G as PinInputField,
68
- J as PinInputHiddenField
63
+ z as PinInput,
64
+ A as PinInputField,
65
+ B as PinInputHiddenField
69
66
  };
@@ -1,24 +1,24 @@
1
- import O, { useState as w, useRef as b, useCallback as M, useEffect as F } from "react";
2
- function d(r, e, t) {
3
- return (e = R(e)) in r ? Object.defineProperty(r, e, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : r[e] = t, r;
1
+ import y, { useState as P, useRef as v, useCallback as j, useEffect as I } from "react";
2
+ function h(s, e, t) {
3
+ return (e = _(e)) in s ? Object.defineProperty(s, e, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : s[e] = t, s;
4
4
  }
5
- function R(r) {
6
- var e = _(r, "string");
5
+ function _(s) {
6
+ var e = B(s, "string");
7
7
  return typeof e == "symbol" ? e : e + "";
8
8
  }
9
- function _(r, e) {
10
- if (typeof r != "object" || !r) return r;
11
- var t = r[Symbol.toPrimitive];
9
+ function B(s, e) {
10
+ if (typeof s != "object" || !s) return s;
11
+ var t = s[Symbol.toPrimitive];
12
12
  if (t !== void 0) {
13
- var i = t.call(r, e);
14
- if (typeof i != "object") return i;
13
+ var n = t.call(s, e);
14
+ if (typeof n != "object") return n;
15
15
  throw new TypeError("@@toPrimitive must return a primitive value.");
16
16
  }
17
- return (e === "string" ? String : Number)(r);
17
+ return (e === "string" ? String : Number)(s);
18
18
  }
19
- class p {
20
- constructor(e, t, i, l = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map()) {
21
- d(this, "changeValue", void 0), d(this, "currentValues", void 0), d(this, "currentValidations", void 0), d(this, "shouldValidate", void 0), d(this, "cachedMessages", void 0), this.changeValue = e, this.currentValues = t, this.currentValidations = i, this.shouldValidate = l, this.cachedMessages = s;
19
+ class w {
20
+ constructor(e, t, n, V = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map()) {
21
+ h(this, "changeValue", void 0), h(this, "currentValues", void 0), h(this, "currentValidations", void 0), h(this, "shouldValidate", void 0), h(this, "cachedMessages", void 0), h(this, "cachedSetters", void 0), h(this, "cachedProps", void 0), this.changeValue = e, this.currentValues = t, this.currentValidations = n, this.shouldValidate = V, this.cachedMessages = l, this.cachedSetters = r, this.cachedProps = a;
22
22
  }
23
23
  isValid() {
24
24
  if (!this.currentValidations) return !0;
@@ -30,49 +30,64 @@ class p {
30
30
  return !0;
31
31
  }
32
32
  getInputProps(e) {
33
- const t = this.currentValues[e], i = t ?? null, l = e, s = this.currentValidations && this.currentValidations[e] ? this.currentValidations[e] : (u) => null;
34
- let a = null;
35
- return this.shouldValidate.has(e) ? (a = s(t, this.currentValues), this.cachedMessages.set(e, a)) : a = this.cachedMessages.get(e) ?? null, {
33
+ const t = this.currentValues[e], n = t ?? null, V = e, l = this.currentValidations && this.currentValidations[e] ? this.currentValidations[e] : (d) => null;
34
+ let r = null;
35
+ this.shouldValidate.has(e) ? (r = l(t, this.currentValues), this.cachedMessages.set(e, r)) : r = this.cachedMessages.get(e) ?? null;
36
+ const a = !!(this.currentValidations && this.currentValidations[e]), u = this.cachedProps.get(e);
37
+ if (u && Object.is(u.value, n) && u.message === r && u.required === a)
38
+ return u.props;
39
+ let c = this.cachedSetters.get(e);
40
+ if (!c) {
41
+ const d = this.changeValue;
42
+ c = (o) => {
43
+ d(V, o);
44
+ }, this.cachedSetters.set(e, c);
45
+ }
46
+ const p = {
36
47
  // @ts-ignore – z.B. wenn dein Input `defaultValue` kennt
37
- defaultValue: i ?? void 0,
38
- initialValue: i ?? void 0,
48
+ defaultValue: n ?? void 0,
49
+ initialValue: n ?? void 0,
39
50
  formValidation: {
40
- setValue: (u) => {
41
- this.changeValue(l, u);
42
- },
43
- notValidMessage: a,
44
- valid: a === null
51
+ setValue: c,
52
+ notValidMessage: r,
53
+ valid: r === null
45
54
  },
46
- ...this.currentValidations && this.currentValidations[e] ? {
55
+ ...a ? {
47
56
  required: !0
48
57
  } : {}
49
58
  };
59
+ return this.cachedProps.set(e, {
60
+ value: n,
61
+ message: r,
62
+ required: a,
63
+ props: p
64
+ }), p;
50
65
  }
51
66
  }
52
- const I = (r) => {
67
+ const N = (s) => {
53
68
  const {
54
69
  initialValues: e,
55
70
  validate: t = {},
56
- truthyValidationBeforeSubmit: i = !0,
57
- useInitialValidation: l = !0,
58
- onSubmit: s
59
- } = r, a = O.useMemo(() => e, [e]), [u, v] = w(a), V = b(/* @__PURE__ */ new Map()), c = b(u);
60
- c.current = u;
61
- const h = M((n, f) => {
62
- c.current = {
63
- ...c.current,
64
- [n]: f
65
- }, v(c.current);
66
- }, []), [S, m] = w(() => new p(h, u, t, l ? new Map(Object.keys(a).map((n) => [n, !0])) : /* @__PURE__ */ new Map(), V.current));
67
- F(() => {
68
- c.current = a, v(a), m(new p(h, a, t, l ? new Map(Object.keys(a).map((n) => [n, !0])) : /* @__PURE__ */ new Map(), V.current));
69
- }, [a]);
70
- const j = M((n, f = !0) => {
71
- const o = c.current, y = n && new Set(Object.keys(o)).has(String(n)) ? /* @__PURE__ */ new Map([[n, !0]]) : new Map(Object.keys(o).map((P) => [String(P), !0])), g = new p(h, o, t, y, V.current);
72
- m(g), f && !new Set(Object.keys(o)).has(String(n)) && s && (!i || g.isValid()) && s(o);
73
- }, [h, t, s, i]);
74
- return [S, j, u];
71
+ truthyValidationBeforeSubmit: n = !0,
72
+ useInitialValidation: V = !0,
73
+ onSubmit: l
74
+ } = s, r = y.useMemo(() => e, [e]), [a, u] = P(r), c = v(/* @__PURE__ */ new Map()), p = v(/* @__PURE__ */ new Map()), d = v(/* @__PURE__ */ new Map()), o = v(a);
75
+ o.current = a;
76
+ const g = j((i, m) => {
77
+ o.current = {
78
+ ...o.current,
79
+ [i]: m
80
+ }, u(o.current);
81
+ }, []), [O, M] = P(() => new w(g, a, t, V ? new Map(Object.keys(r).map((i) => [i, !0])) : /* @__PURE__ */ new Map(), c.current, p.current, d.current)), b = v(!1);
82
+ I(() => {
83
+ o.current = r, u(r), b.current && d.current.clear(), b.current = !0, M(new w(g, r, t, V ? new Map(Object.keys(r).map((i) => [i, !0])) : /* @__PURE__ */ new Map(), c.current, p.current, d.current));
84
+ }, [r]);
85
+ const R = j((i, m = !0) => {
86
+ const f = o.current, F = i && new Set(Object.keys(f)).has(String(i)) ? /* @__PURE__ */ new Map([[i, !0]]) : new Map(Object.keys(f).map((q) => [String(q), !0])), S = new w(g, f, t, F, c.current, p.current, d.current);
87
+ M(S), m && !new Set(Object.keys(f)).has(String(i)) && l && (!n || S.isValid()) && l(f);
88
+ }, [g, t, l, n]);
89
+ return [O, R, a];
75
90
  };
76
91
  export {
77
- I as useForm
92
+ N as useForm
78
93
  };