impact-nova 1.7.31 → 1.7.33

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.
@@ -1,87 +1,85 @@
1
- import { jsx as x } from "react/jsx-runtime";
2
- import { useState as N, useRef as C, useCallback as b, useEffect as F } from "react";
3
- import { useDataTable as X } from "./data-table-context.js";
4
- import { NestedList as Y } from "../nested-list/nested-list.js";
5
- import { SelectionMode as Z } from "../types/nested-list.types.js";
6
- import { mergePartialOrderedColumnState as ee } from "./data-table-column-state.js";
7
- import { useImpactNovaI18n as te } from "../../../i18n/ImpactNovaI18nContext.js";
8
- const de = ({
9
- enableApplyDiscard: v = !1,
10
- showSearch: q = !0,
11
- showSelectAll: j = !0,
12
- showCollapse: K = !0
1
+ import { jsx as w } from "react/jsx-runtime";
2
+ import { useState as A, useRef as _, useCallback as k, useEffect as F } from "react";
3
+ import { useDataTable as J } from "./data-table-context.js";
4
+ import { NestedList as Q } from "../nested-list/nested-list.js";
5
+ import { SelectionMode as X } from "../types/nested-list.types.js";
6
+ import { mergePartialOrderedColumnState as Z } from "./data-table-column-state.js";
7
+ import { useImpactNovaI18n as ee } from "../../../i18n/ImpactNovaI18nContext.js";
8
+ const te = 300, M = 100, de = ({
9
+ enableApplyDiscard: R = !1,
10
+ showSearch: U = !0,
11
+ showSelectAll: q = !0,
12
+ showCollapse: W = !0
13
13
  }) => {
14
- const { gridApi: l } = X(), { t: p } = te(), [V, w] = N([]), [W, B] = N(!1), f = C(!1), T = C(null), y = C(0), z = C({}), [O, P] = N(!1), L = C(/* @__PURE__ */ new Map()), g = b(() => {
15
- if (!l || f.current) return;
16
- const r = l.getColumnState(), s = new Map(r.map((t) => [t.colId, t]));
17
- L.current = s;
18
- const c = l.getColumns() || [], i = new Map(c.map((t) => [t.getColId(), t])), n = [], e = [], k = /* @__PURE__ */ new Map(), D = /* @__PURE__ */ new Map(), J = (t, a) => {
19
- const o = t.getGroupId(), u = `${o}::${a === n ? "f" : "s"}`, d = k.get(u);
20
- if (d && d.list === a && a[a.length - 1] === d.node)
21
- return d.node;
22
- const m = D.get(u) || 0;
23
- D.set(u, m + 1);
24
- const I = t.getColGroupDef(), h = a === n ? "f" : "s", R = {
25
- id: m === 0 ? `${o}__${h}` : `${o}__${h}__${m}`,
26
- label: I?.headerName || o,
14
+ const { gridApi: e } = J(), { t: T } = ee(), [K, O] = A([]), [V, B] = A(!1), v = _(!1), x = _(null), E = _(0), z = _({}), [L, $] = A(!1), D = k(() => {
15
+ if (!e || v.current) return;
16
+ const r = e.getColumnState(), u = e.getColumns() || [], c = new Map(u.map((t) => [t.getColId(), t])), a = [], i = [], l = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map(), g = (t, o) => {
17
+ const n = t.getGroupId(), d = `${n}::${o === a ? "f" : "s"}`, p = l.get(d);
18
+ if (p && p.list === o && o[o.length - 1] === p.node)
19
+ return p.node;
20
+ const S = h.get(d) || 0;
21
+ h.set(d, S + 1);
22
+ const G = t.getColGroupDef(), y = o === a ? "f" : "s", N = {
23
+ id: S === 0 ? `${n}__${y}` : `${n}__${y}__${S}`,
24
+ label: G?.headerName || n,
27
25
  checked: !0,
28
26
  children: [],
29
27
  category: "group"
30
28
  };
31
- return a.push(R), k.set(u, { list: a, node: R }), R;
29
+ return o.push(N), l.set(d, { list: o, node: N }), N;
32
30
  };
33
- let E = 0, $ = 0, G = 0, A = 0;
31
+ let f = 0, C = 0, m = 0, s = 0;
34
32
  r.forEach((t) => {
35
- const a = i.get(t.colId);
36
- if (!a) return;
37
- let o = l.getDisplayNameForColumn(a, "header");
38
- if (o === "") return;
39
- if (o == null) {
40
- const h = a.getColDef();
41
- if (h.headerName === "") return;
42
- o = h.headerName || h.field || t.colId;
33
+ const o = c.get(t.colId);
34
+ if (!o) return;
35
+ let n = e.getDisplayNameForColumn(o, "header");
36
+ if (n === "") return;
37
+ if (n == null) {
38
+ const y = o.getColDef();
39
+ if (y.headerName === "") return;
40
+ n = y.headerName || y.field || t.colId;
43
41
  }
44
- if (!o || o.trim() === "")
42
+ if (!n || n.trim() === "")
45
43
  return;
46
- const u = !t.hide, d = {
44
+ const d = !t.hide, p = {
47
45
  id: t.colId,
48
- label: o,
49
- checked: u
46
+ label: n,
47
+ checked: d
50
48
  };
51
- t.pinned ? (E++, u && $++) : (G++, u && A++);
52
- const m = t.pinned ? n : e, I = a.getOriginalParent();
53
- I?.getColGroupDef()?.children ? J(I, m).children.push(d) : m.push(d);
49
+ t.pinned ? (f++, d && C++) : (m++, d && s++);
50
+ const S = t.pinned ? a : i, G = o.getOriginalParent();
51
+ G?.getColGroupDef()?.children ? g(G, S).children.push(p) : S.push(p);
54
52
  });
55
- const M = (t) => {
56
- let a = t.length > 0;
57
- for (const o of t)
58
- o.children && (o.checked = M(o.children)), o.checked || (a = !1);
59
- return a;
53
+ const I = (t) => {
54
+ let o = t.length > 0;
55
+ for (const n of t)
56
+ n.children && (n.checked = I(n.children)), n.checked || (o = !1);
57
+ return o;
60
58
  };
61
- M(n), M(e);
62
- const Q = [
59
+ I(a), I(i);
60
+ const b = [
63
61
  {
64
62
  id: "root-frozen",
65
- label: p("dataTable.frozenColumns"),
66
- checked: E > 0 && $ === E,
67
- children: n,
63
+ label: T("dataTable.frozenColumns"),
64
+ checked: f > 0 && C === f,
65
+ children: a,
68
66
  category: "structure",
69
67
  isDragDisabled: !0
70
68
  },
71
69
  {
72
70
  id: "root-scrollable",
73
- label: p("dataTable.scrollableColumns"),
74
- checked: G > 0 && A === G,
75
- children: e,
71
+ label: T("dataTable.scrollableColumns"),
72
+ checked: m > 0 && s === m,
73
+ children: i,
76
74
  category: "structure",
77
75
  isDragDisabled: !0
78
76
  }
79
77
  ];
80
- w(Q), B(!0);
81
- }, [l, p]);
78
+ O(b), B(!0);
79
+ }, [e, T]);
82
80
  F(() => {
83
- if (!l) return;
84
- const r = setTimeout(() => g(), 0), s = [
81
+ if (!e) return;
82
+ const r = setTimeout(() => D(), 0), u = [
85
83
  "columnVisible",
86
84
  "columnPinned",
87
85
  "columnMoved",
@@ -96,89 +94,111 @@ const de = ({
96
94
  "displayedColumnsChanged"
97
95
  ];
98
96
  let c = null;
99
- const i = () => {
97
+ const a = () => {
100
98
  c && clearTimeout(c), c = setTimeout(() => {
101
- c = null;
102
- const n = !f.current;
103
- f.current = !1, g(), n && P((e) => !e);
99
+ c = null, !v.current && (D(), $((i) => !i));
104
100
  }, 150);
105
101
  };
106
- return l.isDestroyed() || s.forEach((n) => l.addEventListener(n, i)), () => {
107
- clearTimeout(r), c && clearTimeout(c), l.isDestroyed() || s.forEach((n) => l.removeEventListener(n, i));
102
+ return e.isDestroyed() || u.forEach((i) => e.addEventListener(i, a)), () => {
103
+ clearTimeout(r), c && clearTimeout(c), e.isDestroyed() || u.forEach((i) => e.removeEventListener(i, a));
108
104
  };
109
- }, [l, g]), F(() => {
110
- if (y.current === 0) return;
105
+ }, [e, D]), F(() => {
106
+ if (E.current === 0) return;
111
107
  const r = requestAnimationFrame(() => {
112
- const s = T.current?.querySelector('[data-component="nested-list"] .overflow-y-auto');
113
- s && (s.scrollTop = y.current, y.current = 0);
108
+ const u = x.current?.querySelector('[data-component="nested-list"] .overflow-y-auto');
109
+ u && (u.scrollTop = E.current, E.current = 0);
114
110
  });
115
111
  return () => cancelAnimationFrame(r);
116
- }, [O]);
117
- const _ = b((r) => {
118
- const s = [], c = (i, n) => {
119
- i.forEach((e) => {
120
- if (e.id === "root-frozen") {
121
- e.children && c(e.children, "left");
112
+ }, [L]);
113
+ const j = k((r) => {
114
+ const u = [], c = (a, i) => {
115
+ a.forEach((l) => {
116
+ if (l.id === "root-frozen") {
117
+ l.children && c(l.children, "left");
122
118
  return;
123
119
  }
124
- if (e.id === "root-scrollable") {
125
- e.children && c(e.children, null);
120
+ if (l.id === "root-scrollable") {
121
+ l.children && c(l.children, null);
126
122
  return;
127
123
  }
128
- e.category === "group" || e.children && e.children.length > 0 ? e.children && c(e.children, n) : l?.getColumn(e.id) && s.push({
129
- colId: e.id,
130
- pinned: n,
131
- hide: !e.checked
124
+ l.category === "group" || l.children && l.children.length > 0 ? l.children && c(l.children, i) : e?.getColumn(l.id) && u.push({
125
+ colId: l.id,
126
+ pinned: i,
127
+ hide: !l.checked
132
128
  });
133
129
  });
134
130
  };
135
- return c(r, null), s;
136
- }, [l]), S = b((r) => {
137
- if (!l) return;
138
- f.current = !0;
139
- const s = _(r);
140
- if (s.length === 0) {
131
+ return c(r, null), u;
132
+ }, [e]), P = k((r) => {
133
+ if (!e) return;
134
+ v.current = !0;
135
+ const u = j(r);
136
+ if (u.length === 0) {
141
137
  setTimeout(() => {
142
- f.current = !1;
143
- }, 300);
138
+ v.current = !1;
139
+ }, M);
144
140
  return;
145
141
  }
146
- const c = l.getColumnState(), i = ee(c, s);
147
- l.applyColumnState({
148
- state: i,
149
- applyOrder: !0
150
- }), setTimeout(() => {
151
- f.current = !1;
152
- const n = T.current?.querySelector('[data-component="nested-list"] .overflow-y-auto');
153
- n && (y.current = n.scrollTop), g(), P((e) => !e);
154
- }, 300);
155
- }, [l, _, g]), U = b((r) => {
156
- S(r);
157
- }, [S]), H = b((r) => {
158
- v || S(r), w(r);
159
- }, [v, S]);
160
- return W ? /* @__PURE__ */ x("div", { ref: T, className: "flex flex-col h-full bg-canvas-elevated", children: /* @__PURE__ */ x(
161
- Y,
142
+ const c = e.getColumnState(), a = Z(c, u), i = new Set(c.filter((s) => s.pinned).map((s) => s.colId)), l = a.filter((s) => s.pinned && !i.has(s.colId)), h = new Set(l.map((s) => s.colId));
143
+ e.applyColumnState({ state: a, applyOrder: !0 });
144
+ const g = () => {
145
+ v.current = !1;
146
+ const s = x.current?.querySelector('[data-component="nested-list"] .overflow-y-auto');
147
+ s && (E.current = s.scrollTop), D(), $((I) => !I);
148
+ };
149
+ if (h.size === 0) {
150
+ setTimeout(g, M);
151
+ return;
152
+ }
153
+ let f = !1, C = null;
154
+ const m = () => {
155
+ if (f || e.isDestroyed()) return;
156
+ const s = e.getColumnState();
157
+ if (l.filter((b) => {
158
+ const t = s.find((o) => o.colId === b.colId);
159
+ return t && !t.pinned;
160
+ }).length > 0) {
161
+ f = !0, C && clearTimeout(C), e.removeEventListener("columnPinned", m);
162
+ const b = a.filter((t) => t.pinned && !h.has(t.colId));
163
+ if (b.length > 0) {
164
+ const t = b[0], o = a.map(
165
+ (n) => n.colId === t.colId ? { ...n, pinned: null } : n
166
+ );
167
+ e.applyColumnState({ state: o, applyOrder: !0 });
168
+ }
169
+ setTimeout(g, M);
170
+ }
171
+ };
172
+ e.addEventListener("columnPinned", m), C = setTimeout(() => {
173
+ e.removeEventListener("columnPinned", m), f || g();
174
+ }, te);
175
+ }, [e, j, D]), Y = k((r) => {
176
+ P(r);
177
+ }, [P]), H = k((r) => {
178
+ R || P(r), O(r);
179
+ }, [R, P]);
180
+ return V ? /* @__PURE__ */ w("div", { ref: x, className: "flex flex-col h-full bg-canvas-elevated", children: /* @__PURE__ */ w(
181
+ Q,
162
182
  {
163
- items: V,
183
+ items: K,
164
184
  onChange: H,
165
- onSubmit: U,
166
- enableApplyDiscard: v,
167
- enableSearch: q,
168
- enableSelectAll: j,
185
+ onSubmit: Y,
186
+ enableApplyDiscard: R,
187
+ enableSearch: U,
188
+ enableSelectAll: q,
169
189
  enableDragDrop: !0,
170
190
  enableCollapse: !0,
171
- enableGlobalCollapse: K,
172
- selectionMode: Z.CASCADE_DOWN,
173
- searchPlaceholder: p("dataTable.searchColumnsPlaceholder"),
191
+ enableGlobalCollapse: W,
192
+ selectionMode: X.CASCADE_DOWN,
193
+ searchPlaceholder: T("dataTable.searchColumnsPlaceholder"),
174
194
  className: "h-full",
175
195
  initialCollapsedItems: z.current,
176
196
  onCollapseChange: (r) => {
177
197
  z.current = r;
178
198
  }
179
199
  },
180
- O ? "sync-a" : "sync-b"
181
- ) }) : /* @__PURE__ */ x("div", { className: "p-4 text-[13px] text-content-placeholder", children: p("dataTable.loadingColumns") });
200
+ L ? "sync-a" : "sync-b"
201
+ ) }) : /* @__PURE__ */ w("div", { className: "p-4 text-[13px] text-content-placeholder", children: T("dataTable.loadingColumns") });
182
202
  };
183
203
  export {
184
204
  de as DataTableColumnList