@kong-ui-public/table-data-grid 0.9.0 → 0.9.1-pr.4063.f9e4f8cdb.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.
@@ -1,722 +1,642 @@
1
- import { computed as m, watch as A, ref as M, shallowRef as q, readonly as X, shallowReadonly as pe, defineComponent as ue, onMounted as ce, onUnmounted as he, nextTick as ye, resolveComponent as de, openBlock as K, createElementBlock as B, normalizeClass as ve, createElementVNode as j, createBlock as te, resolveDynamicComponent as le, withCtx as ne, createVNode as ae, toDisplayString as re, createCommentVNode as J, normalizeStyle as be, h as Se, renderSlot as Y, useSlots as ke, useTemplateRef as we, onBeforeUnmount as De, toRef as L, unref as D } from "vue";
2
- import { AgGridVue as Re } from "ag-grid-vue3";
3
- import { ModuleRegistry as Oe, AllCommunityModule as Te, ClientSideRowModelModule as Ee, InfiniteRowModelModule as xe, themeQuartz as Ke } from "ag-grid-community";
4
- import { createI18n as Ie, i18nTComponent as Fe } from "@kong-ui-public/i18n";
5
- var Q = /* @__PURE__ */ ((e) => (e.PENDING = "PENDING", e.LOADING = "LOADING", e.SUCCESS = "SUCCESS", e.ERROR = "ERROR", e))(Q || {});
6
- const Ge = (e) => !!e?.length;
7
- function ze(e, a, t, l = Ge) {
8
- const o = m(() => l(e.value)), n = m(() => {
9
- const u = e.value !== void 0, r = a.value !== void 0 && a.value !== null;
10
- return t.value ? "LOADING" : o.value ? "SUCCESS" : r ? "ERROR" : u ? "SUCCESS" : "PENDING";
11
- });
12
- return {
13
- fetchState: Q,
14
- hasData: o,
15
- state: n
16
- };
1
+ import { computed as e, createBlock as t, createCommentVNode as n, createElementBlock as r, createElementVNode as i, createVNode as a, defineComponent as o, h as s, nextTick as c, normalizeClass as l, normalizeStyle as u, onBeforeUnmount as d, onMounted as f, onUnmounted as p, openBlock as m, readonly as h, ref as g, renderSlot as _, resolveComponent as v, resolveDynamicComponent as y, shallowReadonly as b, shallowRef as x, toDisplayString as S, toRef as C, unref as w, useSlots as T, useTemplateRef as E, watch as D, withCtx as O } from "vue";
2
+ import { AgGridVue as k } from "ag-grid-vue3";
3
+ import { AllCommunityModule as A, ClientSideRowModelModule as j, InfiniteRowModelModule as M, ModuleRegistry as N, themeQuartz as P } from "ag-grid-community";
4
+ import { createI18n as F, i18nTComponent as I } from "@kong-ui-public/i18n";
5
+ // src/composables/useFetchState.ts
6
+ var L = /* @__PURE__ */ function(e) {
7
+ return e.PENDING = "PENDING", e.LOADING = "LOADING", e.SUCCESS = "SUCCESS", e.ERROR = "ERROR", e;
8
+ }({}), R = (e) => !!e?.length;
9
+ function ee(t, n, r, i = R) {
10
+ let a = e(() => i(t.value));
11
+ return {
12
+ fetchState: L,
13
+ hasData: a,
14
+ state: e(() => {
15
+ let e = t.value !== void 0, i = n.value !== void 0 && n.value !== null;
16
+ return r.value ? "LOADING" : a.value ? "SUCCESS" : i ? "ERROR" : e ? "SUCCESS" : "PENDING";
17
+ })
18
+ };
17
19
  }
18
- const Ne = ({
19
- emitState: e,
20
- fetchLifecycleState: a,
21
- hasData: t
22
- }) => {
23
- A(
24
- () => ({
25
- hasData: t.value,
26
- state: a.value
27
- }),
28
- ({ hasData: l, state: o }) => {
29
- if (o !== Q.PENDING) {
30
- if (o === Q.LOADING) {
31
- e({
32
- hasData: l,
33
- state: "loading"
34
- });
35
- return;
36
- }
37
- if (o === Q.ERROR) {
38
- e({
39
- hasData: l,
40
- state: "error"
41
- });
42
- return;
43
- }
44
- e({
45
- hasData: l,
46
- state: "success"
47
- });
48
- }
49
- }
50
- );
51
- }, _e = ({ startRow: e, endRow: a }) => {
52
- const t = a - e;
53
- return {
54
- blockIndex: t > 0 ? Math.floor(e / t) : 0,
55
- pageSize: t
56
- };
57
- }, Be = ({
58
- startRow: e,
59
- rowsLength: a,
60
- pageSize: t,
61
- total: l,
62
- hasMore: o
63
- }) => {
64
- if (typeof l == "number")
65
- return l;
66
- if (o !== !0 && (o === !1 || a < t))
67
- return e + a;
68
- }, Me = ({
69
- fetcher: e,
70
- resetKey: a,
71
- sort: t
72
- }) => {
73
- const l = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), n = M(0), g = M(0), u = q(), r = q(), f = q(), b = M(0), w = M(!1);
74
- let p, R, V = t?.value?.sortColumnKey, s = t?.value?.sortColumnOrder;
75
- const v = (c) => c === n.value && p === e.value && R === a?.value, S = (c, d) => v(c) && d === g.value && V === t?.value?.sortColumnKey && s === t?.value?.sortColumnOrder, $ = (c) => {
76
- if (!t)
77
- return !0;
78
- const d = t.value;
79
- return !d?.sortColumnKey || !d.sortColumnOrder ? c.length === 0 : c.length === 1 && c[0].colId === d.sortColumnKey && c[0].sort === d.sortColumnOrder;
80
- }, T = () => {
81
- w.value = b.value > 0;
82
- }, E = () => {
83
- g.value += 1, V = t?.value?.sortColumnKey, s = t?.value?.sortColumnOrder;
84
- for (const c of o.values())
85
- c.resolve(!1);
86
- l.clear(), o.clear(), r.value = void 0, f.value = void 0, b.value = 0, T();
87
- }, I = () => {
88
- f.value = void 0, b.value += 1, T();
89
- }, P = () => {
90
- b.value = Math.max(0, b.value - 1), T();
91
- }, F = (c) => {
92
- const d = o.get(c);
93
- if (d)
94
- return d;
95
- let C;
96
- const y = {
97
- promise: new Promise((k) => {
98
- C = k;
99
- }),
100
- resolve: (k) => C(k)
101
- };
102
- return o.set(c, y), y;
103
- }, O = (c, d) => {
104
- d.resolve(!1), o.get(c) === d && o.delete(c);
105
- }, U = async ({
106
- blockIndex: c,
107
- currentBlockCompletion: d,
108
- datasourceId: C,
109
- requestGeneration: y
110
- }) => {
111
- if (c === 0)
112
- return "ready";
113
- const k = o.get(c - 1);
114
- if (!k)
115
- return O(c, d), "failed";
116
- const z = await k.promise;
117
- return S(C, y) ? z ? "ready" : (O(c, d), "failed") : (O(c, d), "stale");
118
- }, h = ({
119
- blockIndex: c,
120
- currentBlockCompletion: d,
121
- getRowsParams: C,
122
- pageSize: y,
123
- result: k
124
- }) => {
125
- k.cursor !== void 0 && l.set(c, k.cursor), C.successCallback(k.data, Be({
126
- startRow: C.startRow,
127
- rowsLength: k.data.length,
128
- pageSize: y,
129
- total: k.total,
130
- hasMore: k.hasMore
131
- })), C.startRow === 0 && (r.value = k.data), d.resolve(!0);
132
- }, x = ({
133
- blockIndex: c,
134
- currentBlockCompletion: d,
135
- fetchError: C,
136
- getRowsParams: y
137
- }) => {
138
- f.value = C, y.failCallback(), O(c, d);
139
- }, G = () => {
140
- const c = e.value;
141
- if (!c)
142
- throw new Error("TableDataGrid requires a fetcher in infinite mode");
143
- p = c, R = a?.value;
144
- const d = n.value + 1;
145
- return n.value = d, E(), {
146
- async getRows(C) {
147
- if (!v(d) || !$(C.sortModel)) {
148
- C.failCallback();
149
- return;
150
- }
151
- const {
152
- blockIndex: y,
153
- pageSize: k
154
- } = _e({
155
- startRow: C.startRow,
156
- endRow: C.endRow
157
- });
158
- y === 0 && o.has(0) && E();
159
- const z = g.value, N = F(y);
160
- if (await U({
161
- blockIndex: y,
162
- currentBlockCompletion: N,
163
- datasourceId: d,
164
- requestGeneration: z
165
- }) !== "ready" || !S(d, z)) {
166
- C.failCallback(), O(y, N);
167
- return;
168
- }
169
- I();
170
- try {
171
- const i = y > 0 ? l.get(y - 1) : void 0, _ = await c({
172
- mode: "infinite",
173
- pageSize: k,
174
- cursor: i,
175
- // Always read the latest sort, not a stale one.
176
- sort: t?.value
177
- });
178
- if (!S(d, z)) {
179
- C.failCallback(), O(y, N);
180
- return;
181
- }
182
- h({
183
- blockIndex: y,
184
- currentBlockCompletion: N,
185
- getRowsParams: C,
186
- pageSize: k,
187
- result: _
188
- });
189
- } catch (i) {
190
- if (!S(d, z)) {
191
- C.failCallback(), O(y, N);
192
- return;
193
- }
194
- x({
195
- blockIndex: y,
196
- currentBlockCompletion: N,
197
- fetchError: i,
198
- getRowsParams: C
199
- });
200
- } finally {
201
- S(d, z) && P();
202
- }
203
- }
204
- };
205
- }, W = () => {
206
- u.value = G();
207
- };
208
- return A(
209
- [e, () => a?.value],
210
- () => {
211
- W();
212
- },
213
- { immediate: !0 }
214
- ), A(
215
- [() => t?.value?.sortColumnKey, () => t?.value?.sortColumnOrder],
216
- () => E()
217
- ), {
218
- datasource: X(u),
219
- data: pe(r),
220
- error: X(f),
221
- isFetching: X(w)
222
- };
223
- }, Ae = { title: "No Data", message: "There is no data to display." }, Ve = { title: "An error occurred", message: "Data cannot be displayed due to an error." }, $e = {
224
- emptyState: Ae,
225
- errorState: Ve
20
+ // src/composables/useEmitState.ts
21
+ var te = ({ emitState: e, fetchLifecycleState: t, hasData: n }) => {
22
+ D(() => ({
23
+ hasData: n.value,
24
+ state: t.value
25
+ }), ({ hasData: t, state: n }) => {
26
+ n !== L.PENDING && (n === L.LOADING ? e({
27
+ hasData: t,
28
+ state: "loading"
29
+ }) : n === L.ERROR ? e({
30
+ hasData: t,
31
+ state: "error"
32
+ }) : e({
33
+ hasData: t,
34
+ state: "success"
35
+ }));
36
+ });
37
+ }, z = ({ startRow: e, endRow: t }) => {
38
+ let n = t - e;
39
+ return {
40
+ blockIndex: n > 0 ? Math.floor(e / n) : 0,
41
+ pageSize: n
42
+ };
43
+ }, B = ({ startRow: e, rowsLength: t, pageSize: n, total: r, hasMore: i }) => {
44
+ if (typeof r == "number") return r;
45
+ if (i !== !0 && (i === !1 || t < n)) return e + t;
46
+ }, V = ({ fetcher: e, resetKey: t, sort: n }) => {
47
+ let r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), a = g(0), o = g(0), s = x(), c = x(), l = x(), u = g(0), d = g(!1), f, p, m = n?.value?.sortColumnKey, _ = n?.value?.sortColumnOrder, v = (n) => n === a.value && f === e.value && p === t?.value, y = (e, t) => v(e) && t === o.value && m === n?.value?.sortColumnKey && _ === n?.value?.sortColumnOrder, S = (e) => {
48
+ if (!n) return !0;
49
+ let t = n.value;
50
+ return !t?.sortColumnKey || !t.sortColumnOrder ? e.length === 0 : e.length === 1 && e[0].colId === t.sortColumnKey && e[0].sort === t.sortColumnOrder;
51
+ }, C = () => {
52
+ d.value = u.value > 0;
53
+ }, w = () => {
54
+ o.value += 1, m = n?.value?.sortColumnKey, _ = n?.value?.sortColumnOrder;
55
+ for (let e of i.values()) e.resolve(!1);
56
+ r.clear(), i.clear(), c.value = void 0, l.value = void 0, u.value = 0, C();
57
+ }, T = () => {
58
+ l.value = void 0, u.value += 1, C();
59
+ }, E = () => {
60
+ u.value = Math.max(0, u.value - 1), C();
61
+ }, O = (e) => {
62
+ let t = i.get(e);
63
+ if (t) return t;
64
+ let n, r = {
65
+ promise: new Promise((e) => {
66
+ n = e;
67
+ }),
68
+ resolve: (e) => n(e)
69
+ };
70
+ return i.set(e, r), r;
71
+ }, k = (e, t) => {
72
+ t.resolve(!1), i.get(e) === t && i.delete(e);
73
+ }, A = async ({ blockIndex: e, currentBlockCompletion: t, datasourceId: n, requestGeneration: r }) => {
74
+ if (e === 0) return "ready";
75
+ let a = i.get(e - 1);
76
+ if (!a) return k(e, t), "failed";
77
+ let o = await a.promise;
78
+ return y(n, r) ? o ? "ready" : (k(e, t), "failed") : (k(e, t), "stale");
79
+ }, j = ({ blockIndex: e, currentBlockCompletion: t, getRowsParams: n, pageSize: i, result: a }) => {
80
+ a.cursor !== void 0 && r.set(e, a.cursor), n.successCallback(a.data, B({
81
+ startRow: n.startRow,
82
+ rowsLength: a.data.length,
83
+ pageSize: i,
84
+ total: a.total,
85
+ hasMore: a.hasMore
86
+ })), n.startRow === 0 && (c.value = a.data), t.resolve(!0);
87
+ }, M = ({ blockIndex: e, currentBlockCompletion: t, fetchError: n, getRowsParams: r }) => {
88
+ l.value = n, r.failCallback(), k(e, t);
89
+ }, N = () => {
90
+ let s = e.value;
91
+ if (!s) throw Error("TableDataGrid requires a fetcher in infinite mode");
92
+ f = s, p = t?.value;
93
+ let c = a.value + 1;
94
+ return a.value = c, w(), { async getRows(e) {
95
+ if (!v(c) || !S(e.sortModel)) {
96
+ e.failCallback();
97
+ return;
98
+ }
99
+ let { blockIndex: t, pageSize: a } = z({
100
+ startRow: e.startRow,
101
+ endRow: e.endRow
102
+ });
103
+ t === 0 && i.has(0) && w();
104
+ let l = o.value, u = O(t);
105
+ if (await A({
106
+ blockIndex: t,
107
+ currentBlockCompletion: u,
108
+ datasourceId: c,
109
+ requestGeneration: l
110
+ }) !== "ready" || !y(c, l)) e.failCallback(), k(t, u);
111
+ else {
112
+ T();
113
+ try {
114
+ let i = t > 0 ? r.get(t - 1) : void 0, o = await s({
115
+ mode: "infinite",
116
+ pageSize: a,
117
+ cursor: i,
118
+ sort: n?.value
119
+ });
120
+ if (!y(c, l)) {
121
+ e.failCallback(), k(t, u);
122
+ return;
123
+ }
124
+ j({
125
+ blockIndex: t,
126
+ currentBlockCompletion: u,
127
+ getRowsParams: e,
128
+ pageSize: a,
129
+ result: o
130
+ });
131
+ } catch (n) {
132
+ if (!y(c, l)) {
133
+ e.failCallback(), k(t, u);
134
+ return;
135
+ }
136
+ M({
137
+ blockIndex: t,
138
+ currentBlockCompletion: u,
139
+ fetchError: n,
140
+ getRowsParams: e
141
+ });
142
+ } finally {
143
+ y(c, l) && E();
144
+ }
145
+ }
146
+ } };
147
+ }, P = () => {
148
+ s.value = N();
149
+ };
150
+ return D([e, () => t?.value], () => {
151
+ P();
152
+ }, { immediate: !0 }), D([() => n?.value?.sortColumnKey, () => n?.value?.sortColumnOrder], () => w()), {
153
+ datasource: h(s),
154
+ data: b(c),
155
+ error: h(l),
156
+ isFetching: h(d)
157
+ };
158
+ }, H = {
159
+ emptyState: {
160
+ title: "No Data",
161
+ message: "There is no data to display."
162
+ },
163
+ errorState: {
164
+ title: "An error occurred",
165
+ message: "Data cannot be displayed due to an error."
166
+ }
226
167
  };
227
- function me() {
228
- const e = Ie("en-us", $e);
229
- return {
230
- i18n: e,
231
- i18nT: Fe(e)
232
- // Translation component <i18n-t>
233
- };
168
+ // src/composables/useI18n.ts
169
+ function U() {
170
+ let e = F("en-us", H);
171
+ return {
172
+ i18n: e,
173
+ i18nT: I(e)
174
+ };
234
175
  }
235
- const { i18n: Le } = me(), fe = (e, a) => {
236
- const t = Reflect.get(a, e.key);
237
- return e.valueFormatter ? e.valueFormatter(t, a) : String(t ?? "");
238
- }, Z = (e) => typeof e != "number" ? null : Number.isFinite(e) ? e : null, Pe = (e, a) => e.reduce(
239
- (t, l) => {
240
- const o = Z(Reflect.get(l, a.key));
241
- return o === null ? t : {
242
- sum: t.sum + o,
243
- max: Math.max(t.max, o)
244
- };
245
- },
246
- { sum: 0, max: 0 }
247
- ), Ue = (e, a) => {
248
- const t = (a ?? []).filter((n) => Number.isFinite(n.value) && e >= n.value);
249
- if (!t.length)
250
- return;
251
- const l = Math.max(...t.map((n) => n.value));
252
- return t.filter((n) => n.value === l).some((n) => n.type === "error") ? "error" : "warning";
253
- }, We = (e, a, t) => {
254
- if (e === null)
255
- return 0;
256
- const l = t === "relative" ? a.sum : a.max;
257
- return l > 0 ? Math.min(Math.max(e / l, 0), 1) : 0;
258
- }, qe = (e) => {
259
- const a = (t) => Le.formatNumber(t, { maximumFractionDigits: 2 });
260
- return e > 0 && e < 0.01 ? `< ${a(0.01)} %` : `${a(e)} %`;
261
- }, Ce = ({
262
- value: e,
263
- stats: a,
264
- header: t
265
- }) => {
266
- if (e === null || a.sum <= 0)
267
- return;
268
- const l = e / a.sum * 100;
269
- return t.percentageFormatter?.(l) ?? qe(l);
270
- }, se = (e, a) => a !== void 0 && a.length > (e?.length ?? -1) ? a : e, He = ({
271
- rows: e,
272
- header: a,
273
- stats: t
274
- }) => e.reduce(
275
- (l, o) => ({
276
- value: se(l.value, fe(a, o)) ?? "",
277
- relative: a.showPercentage ? se(l.relative, Ce({
278
- value: Z(Reflect.get(o, a.key)),
279
- stats: t,
280
- header: a
281
- })) : void 0
282
- }),
283
- { value: "" }
284
- ), je = ["data-threshold"], Qe = { class: "table-data-grid-cell-label-track" }, Je = { class: "table-data-grid-cell-label" }, Xe = {
285
- key: 0,
286
- class: "table-data-grid-cell-relative",
287
- "data-testid": "table-data-grid-cell-relative"
288
- }, Ye = {
289
- key: 0,
290
- "aria-hidden": "true",
291
- class: "table-data-grid-cell-label table-data-grid-cell-label-sizer"
292
- }, Ze = ["data-text"], et = ["data-text"], tt = ["data-threshold"], at = /* @__PURE__ */ ue({
293
- name: "TableDataGridCellRenderer",
294
- __name: "TableDataGridCellRenderer",
295
- props: {
296
- params: {}
297
- },
298
- setup(e, { expose: a }) {
299
- const t = q(e.params), l = M(null), o = M(!1), n = m(() => t.value.headerDef ?? {
300
- key: "",
301
- label: ""
302
- }), g = m(() => t.value.context?.presentation), u = m(() => t.value.context?.cells?.tooltipTarget?.value ?? "body"), r = m(() => t.value.valueFormatted ?? String(t.value.value ?? "")), f = m(() => t.value.value), b = m(() => Z(f.value)), w = m(() => g.value?.stats[n.value.key]), p = m(() => n.value.showPercentage && w.value ? Ce({
303
- value: b.value,
304
- stats: w.value,
305
- header: n.value
306
- }) : void 0), R = m(() => !!n.value.bar && !!w.value && (b.value !== null || f.value === null || f.value === void 0)), V = m(() => R.value && w.value ? We(b.value, w.value, n.value.bar) * 100 : 0), s = m(() => R.value ? g.value?.labelSizers[n.value.key] : void 0), v = m(() => n.value.thresholds?.length && b.value !== null ? Ue(b.value, n.value.thresholds) : void 0), S = m(() => ({
307
- column: n.value,
308
- refreshCell: () => {
309
- const h = t.value.node;
310
- h && t.value.api.refreshCells({ force: !0, rowNodes: [h] });
311
- },
312
- row: t.value.data ?? {},
313
- rowIndex: t.value.node?.rowIndex ?? 0,
314
- rowValue: t.value.value,
315
- selected: t.value.node?.isSelected() ?? !1
316
- })), $ = (h, { slots: x }) => {
317
- const G = t.value.colDef?.colId, W = t.value.context?.cells?.slots;
318
- return !G || G === "cell-icon" || !W?.[G] ? x.default?.() : Se(
319
- "span",
320
- { class: "table-data-grid-cell-slot-content" },
321
- Y(W, G, S.value, () => x.default?.() ?? [])
322
- );
323
- }, T = () => {
324
- const h = t.value.context?.cells?.slots;
325
- return h?.["cell-icon"] ? Y(h, "cell-icon", S.value) : null;
326
- };
327
- let E, I, P = !1;
328
- const F = () => {
329
- const h = l.value;
330
- o.value = !!h && h.scrollWidth > h.clientWidth;
331
- }, O = () => {
332
- P || (I !== void 0 && cancelAnimationFrame(I), I = requestAnimationFrame(() => {
333
- I = void 0, F();
334
- }));
335
- }, U = (h) => {
336
- if (E?.disconnect(), h) {
337
- E?.observe(h);
338
- const x = h.closest(".ag-cell");
339
- x && E?.observe(x);
340
- }
341
- O();
342
- };
343
- return ce(() => {
344
- E = new ResizeObserver(O), U(l.value);
345
- }), A(l, U), he(() => {
346
- P = !0, E?.disconnect(), I !== void 0 && cancelAnimationFrame(I);
347
- }), a({
348
- refresh(h) {
349
- return t.value = h, ye(O), !0;
350
- }
351
- }), (h, x) => {
352
- const G = de("KTooltip");
353
- return K(), B("span", {
354
- class: ve(["table-data-grid-cell-renderer", {
355
- "table-data-grid-cell-renderer--bar": R.value,
356
- "table-data-grid-cell-renderer--percentage": !!p.value,
357
- [`table-data-grid-cell-renderer--text-${v.value}`]: !R.value && !!v.value
358
- }]),
359
- "data-threshold": v.value
360
- }, [
361
- j("span", Qe, [
362
- j("span", Je, [
363
- (K(), te(le(T))),
364
- (K(), te(le($), null, {
365
- default: ne(() => [
366
- ae(G, {
367
- class: "table-data-grid-cell-tooltip",
368
- disabled: !o.value,
369
- "kpop-attributes": { popoverDelay: 400 },
370
- "max-width": "300",
371
- placement: "bottom-start",
372
- target: u.value,
373
- text: r.value
374
- }, {
375
- default: ne(() => [
376
- j("span", {
377
- ref_key: "contentElement",
378
- ref: l,
379
- class: "table-data-grid-cell-content"
380
- }, re(r.value), 513)
381
- ]),
382
- _: 1
383
- }, 8, ["disabled", "target", "text"])
384
- ]),
385
- _: 1
386
- })),
387
- p.value ? (K(), B("span", Xe, "(" + re(p.value) + ")", 1)) : J("", !0)
388
- ]),
389
- s.value ? (K(), B("span", Ye, [
390
- j("span", {
391
- class: "table-data-grid-cell-sizer-value",
392
- "data-text": s.value.value
393
- }, null, 8, Ze),
394
- s.value.relative ? (K(), B("span", {
395
- key: 0,
396
- class: "table-data-grid-cell-sizer-relative",
397
- "data-text": `(${s.value.relative})`
398
- }, null, 8, et)) : J("", !0)
399
- ])) : J("", !0)
400
- ]),
401
- R.value ? (K(), B("span", {
402
- key: 0,
403
- class: "table-data-grid-cell-bar",
404
- "data-testid": "table-data-grid-cell-bar",
405
- "data-threshold": v.value
406
- }, [
407
- j("span", {
408
- class: "table-data-grid-cell-bar-fill",
409
- "data-testid": "table-data-grid-cell-bar-fill",
410
- style: be({ width: `${V.value}%` })
411
- }, null, 4)
412
- ], 8, tt)) : J("", !0)
413
- ], 10, je);
414
- };
415
- }
416
- }), ot = ({
417
- headers: e,
418
- slots: a,
419
- initialSort: t,
420
- mode: l,
421
- rows: o,
422
- tooltipTarget: n
423
- }) => {
424
- const g = l ?? "infinite", u = /* @__PURE__ */ new Set(), r = (s) => !!(s.showPercentage || s.bar || s.thresholds?.length);
425
- A([e, () => o?.value], () => {
426
- e.value.forEach((s) => {
427
- if (!r(s))
428
- return;
429
- let v;
430
- if (g === "infinite" && (s.showPercentage || s.bar) ? v = "percentage and bar presentation is only supported in unpaginated mode" : g === "unpaginated" && o?.value?.some(($) => {
431
- const T = Reflect.get($, s.key);
432
- return T != null && Z(T) === null;
433
- }) && (v = "contains non-finite or nonnumeric values; numeric presentation skips those values"), !v)
434
- return;
435
- const S = `${s.key}:${v}`;
436
- u.has(S) || (u.add(S), console.warn(`[TableDataGrid] Column "${s.key}" ${v}.`));
437
- });
438
- }, { immediate: !0 });
439
- const b = m(() => {
440
- if (g !== "unpaginated")
441
- return {};
442
- const s = o?.value ?? [];
443
- return Object.fromEntries(
444
- e.value.filter((v) => v.showPercentage || v.bar).map((v) => [v.key, Pe(s, v)])
445
- );
446
- }), w = m(() => {
447
- if (g !== "unpaginated")
448
- return {};
449
- const s = o?.value ?? [];
450
- return Object.fromEntries(
451
- e.value.filter((v) => v.bar).map((v) => [v.key, He({
452
- rows: s,
453
- header: v,
454
- stats: b.value[v.key]
455
- })])
456
- );
457
- }), p = m(() => ({
458
- cells: { slots: a, tooltipTarget: n },
459
- presentation: {
460
- stats: b.value,
461
- labelSizers: w.value
462
- }
463
- })), R = (s) => {
464
- const v = t?.sortColumnKey === s.key;
465
- return {
466
- colId: s.key,
467
- // Columns with no explicit width constraint share remaining space equally.
468
- flex: !s.width && !s.maxWidth ? 1 : void 0,
469
- headerName: s.label,
470
- maxWidth: s.maxWidth,
471
- minWidth: s.minWidth,
472
- sortable: s.sortable ?? !1,
473
- unSortIcon: s.showSortIcon,
474
- ...v ? { initialSort: t?.sortColumnOrder, initialSortIndex: 0 } : {},
475
- valueGetter: (S) => S.data?.[s.key],
476
- valueFormatter: (S) => S.data ? fe(s, S.data) : String(S.value ?? ""),
477
- width: s.width,
478
- cellRenderer: at,
479
- // custom params passed to the cell renderer.
480
- cellRendererParams: { headerDef: s }
481
- };
482
- };
483
- return {
484
- columnDefs: m(() => e.value.map(R)),
485
- gridContext: p
486
- };
487
- }, ee = ({
488
- config: e,
489
- headers: a,
490
- pageSize: t
491
- }) => {
492
- const l = new Set(a.filter((n) => n.sortable).map((n) => n.key)), o = e?.sortColumnKey && l.has(e.sortColumnKey) ? e.sortColumnKey : void 0;
493
- return {
494
- sortColumnKey: o,
495
- sortColumnOrder: o ? e?.sortColumnOrder : void 0,
496
- pageSize: e?.pageSize ?? t,
497
- ...e?.fitToContent !== void 0 ? { fitToContent: e.fitToContent } : {}
498
- };
499
- }, ie = (e, a) => e.sortColumnKey === a.sortColumnKey && e.sortColumnOrder === a.sortColumnOrder && e.pageSize === a.pageSize && e.fitToContent === a.fitToContent, lt = ({
500
- headers: e,
501
- pageSize: a,
502
- tableConfig: t,
503
- emitSort: l,
504
- emitTableConfigUpdate: o,
505
- onExternalConfigChange: n
506
- }) => {
507
- const g = m(() => t.value ? ee({ config: t.value, headers: e.value, pageSize: a.value }) : void 0), u = M(
508
- g.value ?? ee({ config: void 0, headers: e.value, pageSize: a.value })
509
- );
510
- A(g, (w) => {
511
- w && !ie(w, u.value) && (u.value = w, n?.(w));
512
- });
513
- const r = (w) => {
514
- const p = ee({
515
- config: { ...u.value, ...w },
516
- headers: e.value,
517
- pageSize: a.value
518
- });
519
- ie(p, u.value) || ((p.sortColumnKey !== u.value.sortColumnKey || p.sortColumnOrder !== u.value.sortColumnOrder) && l({ sortColumnKey: p.sortColumnKey, sortColumnOrder: p.sortColumnOrder }), u.value = p, o(p));
520
- };
521
- A(e, () => {
522
- t.value || r({});
523
- }, { deep: !0 });
524
- const f = m(() => ({
525
- sortColumnKey: u.value.sortColumnKey,
526
- sortColumnOrder: u.value.sortColumnOrder
527
- })), b = m(() => t.value?.pageSize ?? a.value);
528
- return {
529
- activeTableConfig: X(u),
530
- activeSort: f,
531
- activePageSize: b,
532
- patchTableConfig: r
533
- };
534
- }, nt = ({
535
- cellClick: e,
536
- headers: a,
537
- rowClick: t
538
- }) => {
539
- const l = m(() => new Set(
540
- a.value.filter((r) => r.disableRowClick).map((r) => r.key)
541
- )), o = (r) => {
542
- const f = r.event?.target;
543
- return f instanceof Element ? f.closest(".ag-cell")?.getAttribute("col-id") ?? void 0 : void 0;
544
- }, n = (r) => {
545
- const f = o(r);
546
- return !!(f && l.value.has(f));
547
- };
548
- return {
549
- onCellClick: (r) => {
550
- const f = r.colDef.colId;
551
- !r.data || !f || e({
552
- columnKey: f,
553
- row: r.data,
554
- value: r.value
555
- });
556
- },
557
- onRowClick: (r) => {
558
- r.data && !n(r) && t(r.data, r);
559
- }
560
- };
561
- }, rt = ({
562
- activeSort: e,
563
- patchTableConfig: a
564
- }) => {
565
- const t = (o, n) => {
566
- o.applyColumnState({
567
- state: n.sortColumnKey ? [{ colId: n.sortColumnKey, sort: n.sortColumnOrder ?? null, sortIndex: 0 }] : [],
568
- defaultState: { sort: null, sortIndex: null }
569
- });
570
- };
571
- return { onSortChanged: (o) => {
572
- const n = o.api.getColumnState().filter((r) => r.sort).sort((r, f) => (r.sortIndex ?? 0) - (f.sortIndex ?? 0)), g = n[n.length - 1], u = g ? { sortColumnKey: g.colId, sortColumnOrder: g.sort } : { sortColumnKey: void 0, sortColumnOrder: void 0 };
573
- (u.sortColumnKey !== e.value.sortColumnKey || u.sortColumnOrder !== e.value.sortColumnOrder) && a(u), n.length > 1 && t(o.api, u);
574
- }, applySortToGrid: t };
575
- }, st = {
576
- key: 0,
577
- class: "table-error-state",
578
- "data-testid": "table-error-state"
579
- }, it = {
580
- key: 1,
581
- class: "table-empty-state",
582
- "data-testid": "table-empty-state"
583
- }, ut = /* @__PURE__ */ ue({
584
- __name: "TableDataGrid",
585
- props: {
586
- headers: {},
587
- error: { type: Boolean, default: !1 },
588
- tableConfig: {},
589
- fetcher: { type: Function },
590
- mode: {},
591
- pageSize: { default: 25 },
592
- refreshKey: { type: [String, Number, Boolean] },
593
- rows: {}
594
- },
595
- emits: ["grid:ready", "state", "row:click", "cell:click", "sort", "update:tableConfig"],
596
- setup(e, { emit: a }) {
597
- Oe.registerModules([Te, Ee, xe]);
598
- const t = e.mode ?? "infinite", l = a, { i18n: o } = me(), { t: n } = o, g = ke(), u = q(), r = we("rootElement"), f = q("body"), b = () => {
599
- const i = document.fullscreenElement;
600
- f.value = i instanceof HTMLElement && i.contains(r.value ?? null) ? i : "body";
601
- };
602
- ce(() => {
603
- b(), document.addEventListener("fullscreenchange", b);
604
- }), De(() => {
605
- document.removeEventListener("fullscreenchange", b);
606
- });
607
- const { activeTableConfig: w, activeSort: p, activePageSize: R, patchTableConfig: V } = lt({
608
- headers: L(() => e.headers),
609
- pageSize: L(() => e.pageSize),
610
- tableConfig: L(() => e.tableConfig),
611
- emitSort: (i) => l("sort", i),
612
- emitTableConfigUpdate: (i) => l("update:tableConfig", i),
613
- onExternalConfigChange: (i) => {
614
- u.value && v(u.value, i);
615
- }
616
- }), { onSortChanged: s, applySortToGrid: v } = rt({
617
- activeSort: p,
618
- patchTableConfig: V
619
- }), S = m(() => t === "unpaginated" && !!w.value.fitToContent), $ = Ke.withParams({ autoHeightMinBodyHeight: 0 }), { onCellClick: T, onRowClick: E } = nt({
620
- cellClick: (i) => l("cell:click", i),
621
- headers: L(() => e.headers),
622
- rowClick: (i, _) => l("row:click", i, _)
623
- }), I = {
624
- resizable: !1,
625
- sortable: !1,
626
- suppressMovable: !0
627
- }, P = m(() => [R.value, e.refreshKey]), F = t === "infinite" ? Me({
628
- fetcher: L(() => e.fetcher),
629
- resetKey: P,
630
- sort: p
631
- }) : void 0, O = F?.datasource, U = m(() => F ? F.data.value : e.rows), h = m(() => F?.isFetching.value ?? !1), x = m(() => e.rows ? Array.from(e.rows) : void 0), { columnDefs: G, gridContext: W } = ot({
632
- headers: L(() => e.headers),
633
- mode: t,
634
- rows: x,
635
- slots: g,
636
- tooltipTarget: f,
637
- initialSort: p.value
638
- }), {
639
- fetchState: c,
640
- hasData: d,
641
- state: C
642
- } = ze(
643
- U,
644
- L(() => F?.error.value),
645
- h
646
- ), y = m(() => C.value === c.SUCCESS && !d.value);
647
- F && Ne({
648
- emitState: (i) => l("state", i),
649
- fetchLifecycleState: C,
650
- hasData: d
651
- });
652
- const k = () => {
653
- const i = u.value;
654
- if (!i || i.isDestroyed())
655
- return;
656
- const _ = p.value, H = i.getColumnState().find((ge) => ge.sort);
657
- H?.colId === _.sortColumnKey && (H?.sort ?? void 0) === _.sortColumnOrder || v(i, _);
658
- };
659
- A([u, p], k);
660
- const z = M(!1), N = (i) => {
661
- i.direction === "vertical" && (z.value = i.top > 0);
662
- }, oe = (i) => {
663
- u.value = i.api, l("grid:ready", i.api);
664
- };
665
- return (i, _) => {
666
- const H = de("KEmptyState");
667
- return K(), B("div", {
668
- ref_key: "rootElement",
669
- ref: r,
670
- class: ve(["kong-ui-public-table-data-grid", { "fit-to-content": S.value, "is-scrolled": z.value }]),
671
- "data-testid": "table-data-grid"
672
- }, [
673
- e.error ? (K(), B("div", st, [
674
- Y(i.$slots, "error-state", {}, () => [
675
- ae(H, {
676
- "icon-variant": "error",
677
- message: D(n)("errorState.message"),
678
- title: D(n)("errorState.title")
679
- }, null, 8, ["message", "title"])
680
- ], !0)
681
- ])) : y.value ? (K(), B("div", it, [
682
- Y(i.$slots, "empty-state", {}, () => [
683
- ae(H, {
684
- message: D(n)("emptyState.message"),
685
- title: D(n)("emptyState.title")
686
- }, null, 8, ["message", "title"])
687
- ], !0)
688
- ])) : (K(), te(D(Re), {
689
- key: 2,
690
- "cache-block-size": D(t) === "infinite" ? D(R) : void 0,
691
- class: "table-data-grid-grid",
692
- "column-defs": D(G),
693
- context: D(W),
694
- datasource: D(t) === "infinite" ? D(O) : void 0,
695
- "default-col-def": I,
696
- "dom-layout": S.value ? "autoHeight" : "normal",
697
- "infinite-initial-row-count": D(t) === "infinite" ? 1 : void 0,
698
- loading: h.value,
699
- "row-data": D(t) === "unpaginated" ? x.value : void 0,
700
- "row-model-type": D(t) === "unpaginated" ? "clientSide" : "infinite",
701
- "suppress-cell-focus": !0,
702
- "suppress-multi-sort": !0,
703
- theme: D($),
704
- onBodyScroll: N,
705
- onCellClicked: D(T),
706
- onGridReady: oe,
707
- onNewColumnsLoaded: k,
708
- onRowClicked: D(E),
709
- onSortChanged: D(s)
710
- }, null, 8, ["cache-block-size", "column-defs", "context", "datasource", "dom-layout", "infinite-initial-row-count", "loading", "row-data", "row-model-type", "theme", "onCellClicked", "onRowClicked", "onSortChanged"]))
711
- ], 2);
712
- };
713
- }
714
- }), ct = (e, a) => {
715
- const t = e.__vccOpts || e;
716
- for (const [l, o] of a)
717
- t[l] = o;
718
- return t;
719
- }, Ct = /* @__PURE__ */ ct(ut, [["__scopeId", "data-v-82e410f3"]]);
720
- export {
721
- Ct as TableDataGrid
722
- };
176
+ // src/utils/tableDataGridPresentation.ts
177
+ var { i18n: W } = U(), G = (e, t) => {
178
+ let n = Reflect.get(t, e.key);
179
+ return e.valueFormatter ? e.valueFormatter(n, t) : String(n ?? "");
180
+ }, K = (e) => typeof e == "number" && Number.isFinite(e) ? e : null, ne = (e, t) => e.reduce((e, n) => {
181
+ let r = K(Reflect.get(n, t.key));
182
+ return r === null ? e : {
183
+ sum: e.sum + r,
184
+ max: Math.max(e.max, r)
185
+ };
186
+ }, {
187
+ sum: 0,
188
+ max: 0
189
+ }), q = (e, t) => {
190
+ let n = (t ?? []).filter((t) => Number.isFinite(t.value) && e >= t.value);
191
+ if (!n.length) return;
192
+ let r = Math.max(...n.map((e) => e.value));
193
+ return n.filter((e) => e.value === r).some((e) => e.type === "error") ? "error" : "warning";
194
+ }, re = (e, t, n) => {
195
+ if (e === null) return 0;
196
+ let r = n === "relative" ? t.sum : t.max;
197
+ return r > 0 ? Math.min(Math.max(e / r, 0), 1) : 0;
198
+ }, ie = (e) => {
199
+ let t = (e) => W.formatNumber(e, { maximumFractionDigits: 2 });
200
+ return e > 0 && e < .01 ? `< ${t(.01)} %` : `${t(e)} %`;
201
+ }, J = ({ value: e, stats: t, header: n }) => {
202
+ if (e === null || t.sum <= 0) return;
203
+ let r = e / t.sum * 100;
204
+ return n.percentageFormatter?.(r) ?? ie(r);
205
+ }, Y = (e, t) => t !== void 0 && t.length > (e?.length ?? -1) ? t : e, ae = ({ rows: e, header: t, stats: n }) => e.reduce((e, r) => ({
206
+ value: Y(e.value, G(t, r)) ?? "",
207
+ relative: t.showPercentage ? Y(e.relative, J({
208
+ value: K(Reflect.get(r, t.key)),
209
+ stats: n,
210
+ header: t
211
+ })) : void 0
212
+ }), { value: "" }), oe = ["data-threshold"], se = { class: "table-data-grid-cell-label-track" }, X = { class: "table-data-grid-cell-label" }, Z = {
213
+ key: 0,
214
+ class: "table-data-grid-cell-relative",
215
+ "data-testid": "table-data-grid-cell-relative"
216
+ }, ce = {
217
+ key: 0,
218
+ "aria-hidden": "true",
219
+ class: "table-data-grid-cell-label table-data-grid-cell-label-sizer"
220
+ }, Q = ["data-text"], $ = ["data-text"], le = ["data-threshold"], ue = /* @__PURE__ */ o({
221
+ name: "TableDataGridCellRenderer",
222
+ __name: "TableDataGridCellRenderer",
223
+ props: { params: {} },
224
+ setup(o, { expose: d }) {
225
+ let h = x(o.params), b = g(null), C = g(!1), w = e(() => h.value.headerDef ?? {
226
+ key: "",
227
+ label: ""
228
+ }), T = e(() => h.value.context?.presentation), E = e(() => h.value.context?.cells?.tooltipTarget?.value ?? "body"), k = e(() => h.value.valueFormatted ?? String(h.value.value ?? "")), A = e(() => h.value.value), j = e(() => K(A.value)), M = e(() => T.value?.stats[w.value.key]), N = e(() => w.value.showPercentage && M.value ? J({
229
+ value: j.value,
230
+ stats: M.value,
231
+ header: w.value
232
+ }) : void 0), P = e(() => !!w.value.bar && !!M.value && (j.value !== null || A.value === null || A.value === void 0)), F = e(() => P.value && M.value ? re(j.value, M.value, w.value.bar) * 100 : 0), I = e(() => P.value ? T.value?.labelSizers[w.value.key] : void 0), L = e(() => w.value.thresholds?.length && j.value !== null ? q(j.value, w.value.thresholds) : void 0), R = e(() => ({
233
+ column: w.value,
234
+ refreshCell: () => {
235
+ let e = h.value.node;
236
+ e && h.value.api.refreshCells({
237
+ force: !0,
238
+ rowNodes: [e]
239
+ });
240
+ },
241
+ row: h.value.data ?? {},
242
+ rowIndex: h.value.node?.rowIndex ?? 0,
243
+ rowValue: h.value.value,
244
+ selected: h.value.node?.isSelected() ?? !1
245
+ })), ee = (e, { slots: t }) => {
246
+ let n = h.value.colDef?.colId, r = h.value.context?.cells?.slots;
247
+ return !n || n === "cell-icon" || !r?.[n] ? t.default?.() : s("span", { class: "table-data-grid-cell-slot-content" }, _(r, n, R.value, () => t.default?.() ?? []));
248
+ }, te = () => {
249
+ let e = h.value.context?.cells?.slots;
250
+ return e?.["cell-icon"] ? _(e, "cell-icon", R.value) : null;
251
+ }, z, B, V = !1, H = () => {
252
+ let e = b.value;
253
+ C.value = !!e && e.scrollWidth > e.clientWidth;
254
+ }, U = () => {
255
+ V || (B !== void 0 && cancelAnimationFrame(B), B = requestAnimationFrame(() => {
256
+ B = void 0, H();
257
+ }));
258
+ }, W = (e) => {
259
+ if (z?.disconnect(), e) {
260
+ z?.observe(e);
261
+ let t = e.closest(".ag-cell");
262
+ t && z?.observe(t);
263
+ }
264
+ U();
265
+ };
266
+ return f(() => {
267
+ z = new ResizeObserver(U), W(b.value);
268
+ }), D(b, W), p(() => {
269
+ V = !0, z?.disconnect(), B !== void 0 && cancelAnimationFrame(B);
270
+ }), d({ refresh(e) {
271
+ return h.value = e, c(U), !0;
272
+ } }), (e, o) => {
273
+ let s = v("KTooltip");
274
+ return m(), r("span", {
275
+ class: l(["table-data-grid-cell-renderer", {
276
+ "table-data-grid-cell-renderer--bar": P.value,
277
+ "table-data-grid-cell-renderer--percentage": !!N.value,
278
+ [`table-data-grid-cell-renderer--text-${L.value}`]: !P.value && !!L.value
279
+ }]),
280
+ "data-threshold": L.value
281
+ }, [i("span", se, [i("span", X, [
282
+ (m(), t(y(te))),
283
+ (m(), t(y(ee), null, {
284
+ default: O(() => [a(s, {
285
+ class: "table-data-grid-cell-tooltip",
286
+ disabled: !C.value,
287
+ "kpop-attributes": { popoverDelay: 400 },
288
+ "max-width": "300",
289
+ placement: "bottom-start",
290
+ target: E.value,
291
+ text: k.value
292
+ }, {
293
+ default: O(() => [i("span", {
294
+ ref_key: "contentElement",
295
+ ref: b,
296
+ class: "table-data-grid-cell-content"
297
+ }, S(k.value), 513)]),
298
+ _: 1
299
+ }, 8, [
300
+ "disabled",
301
+ "target",
302
+ "text"
303
+ ])]),
304
+ _: 1
305
+ })),
306
+ N.value ? (m(), r("span", Z, "(" + S(N.value) + ")", 1)) : n("", !0)
307
+ ]), I.value ? (m(), r("span", ce, [i("span", {
308
+ class: "table-data-grid-cell-sizer-value",
309
+ "data-text": I.value.value
310
+ }, null, 8, Q), I.value.relative ? (m(), r("span", {
311
+ key: 0,
312
+ class: "table-data-grid-cell-sizer-relative",
313
+ "data-text": `(${I.value.relative})`
314
+ }, null, 8, $)) : n("", !0)])) : n("", !0)]), P.value ? (m(), r("span", {
315
+ key: 0,
316
+ class: "table-data-grid-cell-bar",
317
+ "data-testid": "table-data-grid-cell-bar",
318
+ "data-threshold": L.value
319
+ }, [i("span", {
320
+ class: "table-data-grid-cell-bar-fill",
321
+ "data-testid": "table-data-grid-cell-bar-fill",
322
+ style: u({ width: `${F.value}%` })
323
+ }, null, 4)], 8, le)) : n("", !0)], 10, oe);
324
+ };
325
+ }
326
+ }), de = ({ headers: t, slots: n, initialSort: r, mode: i, rows: a, tooltipTarget: o }) => {
327
+ let s = i ?? "infinite", c = /* @__PURE__ */ new Set(), l = (e) => !!(e.showPercentage || e.bar || e.thresholds?.length);
328
+ D([t, () => a?.value], () => {
329
+ t.value.forEach((e) => {
330
+ if (!l(e)) return;
331
+ let t;
332
+ if (s === "infinite" && (e.showPercentage || e.bar) ? t = "percentage and bar presentation is only supported in unpaginated mode" : s === "unpaginated" && a?.value?.some((t) => {
333
+ let n = Reflect.get(t, e.key);
334
+ return n != null && K(n) === null;
335
+ }) && (t = "contains non-finite or nonnumeric values; numeric presentation skips those values"), !t) return;
336
+ let n = `${e.key}:${t}`;
337
+ c.has(n) || (c.add(n), console.warn(`[TableDataGrid] Column "${e.key}" ${t}.`));
338
+ });
339
+ }, { immediate: !0 });
340
+ let u = e(() => {
341
+ if (s !== "unpaginated") return {};
342
+ let e = a?.value ?? [];
343
+ return Object.fromEntries(t.value.filter((e) => e.showPercentage || e.bar).map((t) => [t.key, ne(e, t)]));
344
+ }), d = e(() => {
345
+ if (s !== "unpaginated") return {};
346
+ let e = a?.value ?? [];
347
+ return Object.fromEntries(t.value.filter((e) => e.bar).map((t) => [t.key, ae({
348
+ rows: e,
349
+ header: t,
350
+ stats: u.value[t.key]
351
+ })]));
352
+ }), f = e(() => ({
353
+ cells: {
354
+ slots: n,
355
+ tooltipTarget: o
356
+ },
357
+ presentation: {
358
+ stats: u.value,
359
+ labelSizers: d.value
360
+ }
361
+ })), p = (e) => {
362
+ let t = r?.sortColumnKey === e.key;
363
+ return {
364
+ colId: e.key,
365
+ flex: !e.width && !e.maxWidth ? 1 : void 0,
366
+ headerName: e.label,
367
+ maxWidth: e.maxWidth,
368
+ minWidth: e.minWidth,
369
+ sortable: e.sortable ?? !1,
370
+ unSortIcon: e.showSortIcon,
371
+ ...t ? {
372
+ initialSort: r?.sortColumnOrder,
373
+ initialSortIndex: 0
374
+ } : {},
375
+ valueGetter: (t) => t.data?.[e.key],
376
+ valueFormatter: (t) => t.data ? G(e, t.data) : String(t.value ?? ""),
377
+ width: e.width,
378
+ cellRenderer: ue,
379
+ cellRendererParams: { headerDef: e }
380
+ };
381
+ };
382
+ return {
383
+ columnDefs: e(() => t.value.map(p)),
384
+ gridContext: f
385
+ };
386
+ }, fe = ({ config: e, headers: t, pageSize: n }) => {
387
+ let r = new Set(t.filter((e) => e.sortable).map((e) => e.key)), i = e?.sortColumnKey && r.has(e.sortColumnKey) ? e.sortColumnKey : void 0;
388
+ return {
389
+ sortColumnKey: i,
390
+ sortColumnOrder: i ? e?.sortColumnOrder : void 0,
391
+ pageSize: e?.pageSize ?? n,
392
+ ...e?.fitToContent === void 0 ? {} : { fitToContent: e.fitToContent }
393
+ };
394
+ }, pe = (e, t) => e.sortColumnKey === t.sortColumnKey && e.sortColumnOrder === t.sortColumnOrder && e.pageSize === t.pageSize && e.fitToContent === t.fitToContent, me = ({ headers: t, pageSize: n, tableConfig: r, emitSort: i, emitTableConfigUpdate: a, onExternalConfigChange: o }) => {
395
+ let s = e(() => r.value ? fe({
396
+ config: r.value,
397
+ headers: t.value,
398
+ pageSize: n.value
399
+ }) : void 0), c = g(s.value ?? fe({
400
+ config: void 0,
401
+ headers: t.value,
402
+ pageSize: n.value
403
+ }));
404
+ D(s, (e) => {
405
+ e && !pe(e, c.value) && (c.value = e, o?.(e));
406
+ });
407
+ let l = (e) => {
408
+ let r = fe({
409
+ config: {
410
+ ...c.value,
411
+ ...e
412
+ },
413
+ headers: t.value,
414
+ pageSize: n.value
415
+ });
416
+ pe(r, c.value) || ((r.sortColumnKey !== c.value.sortColumnKey || r.sortColumnOrder !== c.value.sortColumnOrder) && i({
417
+ sortColumnKey: r.sortColumnKey,
418
+ sortColumnOrder: r.sortColumnOrder
419
+ }), c.value = r, a(r));
420
+ };
421
+ D(t, () => {
422
+ r.value || l({});
423
+ }, { deep: !0 });
424
+ let u = e(() => ({
425
+ sortColumnKey: c.value.sortColumnKey,
426
+ sortColumnOrder: c.value.sortColumnOrder
427
+ })), d = e(() => r.value?.pageSize ?? n.value);
428
+ return {
429
+ activeTableConfig: h(c),
430
+ activeSort: u,
431
+ activePageSize: d,
432
+ patchTableConfig: l
433
+ };
434
+ }, he = ({ cellClick: t, headers: n, rowClick: r }) => {
435
+ let i = e(() => new Set(n.value.filter((e) => e.disableRowClick).map((e) => e.key))), a = (e) => {
436
+ let t = e.event?.target;
437
+ return t instanceof Element ? t.closest(".ag-cell")?.getAttribute("col-id") ?? void 0 : void 0;
438
+ }, o = (e) => {
439
+ let t = a(e);
440
+ return !!(t && i.value.has(t));
441
+ };
442
+ return {
443
+ onCellClick: (e) => {
444
+ let n = e.colDef.colId;
445
+ e.data && n && t({
446
+ columnKey: n,
447
+ row: e.data,
448
+ value: e.value
449
+ });
450
+ },
451
+ onRowClick: (e) => {
452
+ e.data && !o(e) && r(e.data, e);
453
+ }
454
+ };
455
+ }, ge = ({ activeSort: e, patchTableConfig: t }) => {
456
+ let n = (e, t) => {
457
+ e.applyColumnState({
458
+ state: t.sortColumnKey ? [{
459
+ colId: t.sortColumnKey,
460
+ sort: t.sortColumnOrder ?? null,
461
+ sortIndex: 0
462
+ }] : [],
463
+ defaultState: {
464
+ sort: null,
465
+ sortIndex: null
466
+ }
467
+ });
468
+ };
469
+ return {
470
+ onSortChanged: (r) => {
471
+ let i = r.api.getColumnState().filter((e) => e.sort).sort((e, t) => (e.sortIndex ?? 0) - (t.sortIndex ?? 0)), a = i[i.length - 1], o = a ? {
472
+ sortColumnKey: a.colId,
473
+ sortColumnOrder: a.sort
474
+ } : {
475
+ sortColumnKey: void 0,
476
+ sortColumnOrder: void 0
477
+ };
478
+ (o.sortColumnKey !== e.value.sortColumnKey || o.sortColumnOrder !== e.value.sortColumnOrder) && t(o), i.length > 1 && n(r.api, o);
479
+ },
480
+ applySortToGrid: n
481
+ };
482
+ }, _e = {
483
+ key: 0,
484
+ class: "table-error-state",
485
+ "data-testid": "table-error-state"
486
+ }, ve = {
487
+ key: 1,
488
+ class: "table-empty-state",
489
+ "data-testid": "table-empty-state"
490
+ }, ye = /*#__PURE__*/ ((e, t) => {
491
+ let n = e.__vccOpts || e;
492
+ for (let [e, r] of t) n[e] = r;
493
+ return n;
494
+ })(/* @__PURE__ */ o({
495
+ __name: "TableDataGrid",
496
+ props: {
497
+ headers: {},
498
+ error: {
499
+ type: Boolean,
500
+ default: !1
501
+ },
502
+ tableConfig: {},
503
+ fetcher: { type: Function },
504
+ mode: {},
505
+ pageSize: { default: 25 },
506
+ refreshKey: { type: [
507
+ String,
508
+ Number,
509
+ Boolean
510
+ ] },
511
+ rows: {}
512
+ },
513
+ emits: [
514
+ "grid:ready",
515
+ "state",
516
+ "row:click",
517
+ "cell:click",
518
+ "sort",
519
+ "update:tableConfig"
520
+ ],
521
+ setup(n, { emit: i }) {
522
+ N.registerModules([
523
+ A,
524
+ j,
525
+ M
526
+ ]);
527
+ let o = n.mode ?? "infinite", s = i, { i18n: c } = U(), { t: u } = c, p = T(), h = x(), y = E("rootElement"), b = x("body"), S = () => {
528
+ let e = document.fullscreenElement;
529
+ b.value = e instanceof HTMLElement && e.contains(y.value ?? null) ? e : "body";
530
+ };
531
+ f(() => {
532
+ S(), document.addEventListener("fullscreenchange", S);
533
+ }), d(() => {
534
+ document.removeEventListener("fullscreenchange", S);
535
+ });
536
+ let { activeTableConfig: O, activeSort: F, activePageSize: I, patchTableConfig: L } = me({
537
+ headers: C(() => n.headers),
538
+ pageSize: C(() => n.pageSize),
539
+ tableConfig: C(() => n.tableConfig),
540
+ emitSort: (e) => s("sort", e),
541
+ emitTableConfigUpdate: (e) => s("update:tableConfig", e),
542
+ onExternalConfigChange: (e) => {
543
+ h.value && z(h.value, e);
544
+ }
545
+ }), { onSortChanged: R, applySortToGrid: z } = ge({
546
+ activeSort: F,
547
+ patchTableConfig: L
548
+ }), B = e(() => o === "unpaginated" && !!O.value.fitToContent), H = P.withParams({ autoHeightMinBodyHeight: 0 }), { onCellClick: W, onRowClick: G } = he({
549
+ cellClick: (e) => s("cell:click", e),
550
+ headers: C(() => n.headers),
551
+ rowClick: (e, t) => s("row:click", e, t)
552
+ }), K = {
553
+ resizable: !1,
554
+ sortable: !1,
555
+ suppressMovable: !0
556
+ }, ne = e(() => [I.value, n.refreshKey]), q = o === "infinite" ? V({
557
+ fetcher: C(() => n.fetcher),
558
+ resetKey: ne,
559
+ sort: F
560
+ }) : void 0, re = q?.datasource, ie = e(() => q ? q.data.value : n.rows), J = e(() => q?.isFetching.value ?? !1), Y = e(() => n.rows ? Array.from(n.rows) : void 0), { columnDefs: ae, gridContext: oe } = de({
561
+ headers: C(() => n.headers),
562
+ mode: o,
563
+ rows: Y,
564
+ slots: p,
565
+ tooltipTarget: b,
566
+ initialSort: F.value
567
+ }), { fetchState: se, hasData: X, state: Z } = ee(ie, C(() => q?.error.value), J), ce = e(() => Z.value === se.SUCCESS && !X.value);
568
+ q && te({
569
+ emitState: (e) => s("state", e),
570
+ fetchLifecycleState: Z,
571
+ hasData: X
572
+ });
573
+ let Q = () => {
574
+ let e = h.value;
575
+ if (!e || e.isDestroyed()) return;
576
+ let t = F.value, n = e.getColumnState().find((e) => e.sort);
577
+ (n?.colId !== t.sortColumnKey || (n?.sort ?? void 0) !== t.sortColumnOrder) && z(e, t);
578
+ };
579
+ D([h, F], Q);
580
+ let $ = g(!1), le = (e) => {
581
+ e.direction === "vertical" && ($.value = e.top > 0);
582
+ }, ue = (e) => {
583
+ h.value = e.api, s("grid:ready", e.api);
584
+ };
585
+ return (e, i) => {
586
+ let s = v("KEmptyState");
587
+ return m(), r("div", {
588
+ ref_key: "rootElement",
589
+ ref: y,
590
+ class: l(["kong-ui-public-table-data-grid", {
591
+ "fit-to-content": B.value,
592
+ "is-scrolled": $.value
593
+ }]),
594
+ "data-testid": "table-data-grid"
595
+ }, [n.error ? (m(), r("div", _e, [_(e.$slots, "error-state", {}, () => [a(s, {
596
+ "icon-variant": "error",
597
+ message: w(u)("errorState.message"),
598
+ title: w(u)("errorState.title")
599
+ }, null, 8, ["message", "title"])], !0)])) : ce.value ? (m(), r("div", ve, [_(e.$slots, "empty-state", {}, () => [a(s, {
600
+ message: w(u)("emptyState.message"),
601
+ title: w(u)("emptyState.title")
602
+ }, null, 8, ["message", "title"])], !0)])) : (m(), t(w(k), {
603
+ key: 2,
604
+ "cache-block-size": w(o) === "infinite" ? w(I) : void 0,
605
+ class: "table-data-grid-grid",
606
+ "column-defs": w(ae),
607
+ context: w(oe),
608
+ datasource: w(o) === "infinite" ? w(re) : void 0,
609
+ "default-col-def": K,
610
+ "dom-layout": B.value ? "autoHeight" : "normal",
611
+ "infinite-initial-row-count": w(o) === "infinite" ? 1 : void 0,
612
+ loading: J.value,
613
+ "row-data": w(o) === "unpaginated" ? Y.value : void 0,
614
+ "row-model-type": w(o) === "unpaginated" ? "clientSide" : "infinite",
615
+ "suppress-cell-focus": !0,
616
+ "suppress-multi-sort": !0,
617
+ theme: w(H),
618
+ onBodyScroll: le,
619
+ onCellClicked: w(W),
620
+ onGridReady: ue,
621
+ onNewColumnsLoaded: Q,
622
+ onRowClicked: w(G),
623
+ onSortChanged: w(R)
624
+ }, null, 8, [
625
+ "cache-block-size",
626
+ "column-defs",
627
+ "context",
628
+ "datasource",
629
+ "dom-layout",
630
+ "infinite-initial-row-count",
631
+ "loading",
632
+ "row-data",
633
+ "row-model-type",
634
+ "theme",
635
+ "onCellClicked",
636
+ "onRowClicked",
637
+ "onSortChanged"
638
+ ]))], 2);
639
+ };
640
+ }
641
+ }), [["__scopeId", "data-v-82e410f3"]]);
642
+ export { ye as TableDataGrid };