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