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