@jirawatpyk/aura-react 4.4.2 → 4.5.1

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,104 +1,120 @@
1
1
  'use client';
2
2
  import * as React from "react";
3
- import { useStrings, useAuraLocale } from "./locale.js";
4
- import { cx, omit, useMaybeControlled, compare, useIsoLayoutEffect, useMergedRef } from "./internal.js";
3
+ import { useStrings } from "./locale.js";
4
+ import { cx, useMaybeControlled, compare, useIsoLayoutEffect, useMergedRef } from "./internal.js";
5
5
  import { Icon } from "./Icon.js";
6
6
  import { IconButton } from "./IconButton.js";
7
7
  import { Checkbox } from "./Checkbox.js";
8
8
  import { Menu } from "./Menu.js";
9
9
  import { StatusPill, toneFor, TONE_ORDER } from "./StatusPill.js";
10
- const h = React.createElement;
11
- var BP = { sm: 640, md: 768, lg: 1024, xl: 1280 };
12
- var DEFAULT_COLUMNS = [
10
+ const BP = { sm: 640, md: 768, lg: 1024, xl: 1280 };
11
+ const DEFAULT_COLUMNS = [
13
12
  { key: "id", label: "ID", width: 96, mono: true },
14
13
  { key: "name", label: "NAME", width: 160 },
15
14
  { key: "status", label: "STATUS", width: 112, pill: true },
16
15
  { key: "owner", label: "OWNER" }
17
16
  ];
18
- var SKELETON_WIDTHS = ["72%", "56%", "84%", "44%", "64%"];
19
- var ROW_H = 48, OVERSCAN = 8, FLEX_MIN = 160;
17
+ const SKELETON_WIDTHS = ["72%", "56%", "84%", "44%", "64%"];
18
+ const ROW_H = 48, OVERSCAN = 8, FLEX_MIN = 160;
20
19
  const DataTable = React.forwardRef(function DataTable2(props, ref) {
21
- var t = useStrings();
22
- var columns = props.columns || DEFAULT_COLUMNS;
23
- var byKey = {};
20
+ const t = useStrings();
21
+ const columns = props.columns || DEFAULT_COLUMNS;
22
+ const byKey = {};
24
23
  columns.forEach(function(c) {
25
24
  byKey[c.key] = c;
26
25
  });
27
- var rows = props.rows || [];
28
- var rowKey = props.rowKey || columns[0].key;
29
- var loading = !!props.loading;
30
- var selectable = !!props.selectable;
31
- var reorderable = props.reorderable !== false && !!props.columnControls;
32
- var controls = !!props.columnControls;
33
- var sortState = useMaybeControlled(props.sort, props.defaultSort || null, props.onSortChange);
34
- var sort = sortState[0], setSort = sortState[1];
35
- var selState = useMaybeControlled(props.selected, props.defaultSelected || [], props.onSelectionChange);
36
- var selected = selState[0], setSelected = selState[1];
37
- var pageState = useMaybeControlled(props.page, props.defaultPage || 1, props.onPageChange);
38
- var orderState = useMaybeControlled(props.columnOrder, columns.map(function(c) {
39
- return c.key;
40
- }), props.onColumnOrderChange);
41
- var hiddenState = useMaybeControlled(props.hiddenColumns, columns.filter(function(c) {
42
- return c.hidden;
43
- }).map(function(c) {
44
- return c.key;
45
- }), props.onHiddenColumnsChange);
46
- var pinState = useMaybeControlled(props.pinnedColumns, columns.filter(function(c) {
47
- return c.pinned;
48
- }).map(function(c) {
49
- return c.key;
50
- }), props.onPinnedColumnsChange);
51
- var widthState = React.useState({});
52
- var widths = widthState[0], setWidths = widthState[1];
53
- var activeState = React.useState({ r: 1, c: 0 });
54
- var scrollState = React.useState(0);
55
- var scrollTop = scrollState[0], setScrollTop = scrollState[1];
56
- var scrolledX = React.useState(false);
57
- var menuState = React.useState(null);
58
- var menu = menuState[0], setMenu = menuState[1];
59
- var dragState = React.useState(null);
60
- var drag = dragState[0], setDrag = dragState[1];
61
- var gridRef = React.useRef(null);
62
- var wrapRef = React.useRef(null), wrapMerged = useMergedRef(ref, wrapRef);
63
- var boxWidth = React.useState(null);
64
- var measure = !!props.stackBelow || columns.some(function(c) {
26
+ const rows = props.rows || [];
27
+ const rowKey = props.rowKey || columns[0].key;
28
+ const loading = !!props.loading;
29
+ const selectable = !!props.selectable;
30
+ const reorderable = props.reorderable !== false && !!props.columnControls;
31
+ const controls = !!props.columnControls;
32
+ const sortState = useMaybeControlled(props.sort, props.defaultSort || null, props.onSortChange);
33
+ const sort = sortState[0], setSort = sortState[1];
34
+ const selState = useMaybeControlled(props.selected, props.defaultSelected || [], props.onSelectionChange);
35
+ const selected = selState[0], setSelected = selState[1];
36
+ const pageState = useMaybeControlled(props.page, props.defaultPage || 1, props.onPageChange);
37
+ const orderState = useMaybeControlled(
38
+ props.columnOrder,
39
+ columns.map(function(c) {
40
+ return c.key;
41
+ }),
42
+ props.onColumnOrderChange
43
+ );
44
+ const hiddenState = useMaybeControlled(
45
+ props.hiddenColumns,
46
+ columns.filter(function(c) {
47
+ return c.hidden;
48
+ }).map(function(c) {
49
+ return c.key;
50
+ }),
51
+ props.onHiddenColumnsChange
52
+ );
53
+ const pinState = useMaybeControlled(
54
+ props.pinnedColumns,
55
+ columns.filter(function(c) {
56
+ return c.pinned;
57
+ }).map(function(c) {
58
+ return c.key;
59
+ }),
60
+ props.onPinnedColumnsChange
61
+ );
62
+ const widthState = React.useState({});
63
+ const widths = widthState[0], setWidths = widthState[1];
64
+ const activeState = React.useState({ r: 1, c: 0 });
65
+ const scrollState = React.useState(0);
66
+ const scrollTop = scrollState[0], setScrollTop = scrollState[1];
67
+ const scrolledX = React.useState(false);
68
+ const menuState = React.useState(null);
69
+ const menu = menuState[0], setMenu = menuState[1];
70
+ const dragState = React.useState(null);
71
+ const drag = dragState[0], setDrag = dragState[1];
72
+ const gridRef = React.useRef(null);
73
+ const wrapRef = React.useRef(null), wrapMerged = useMergedRef(ref, wrapRef);
74
+ const boxWidth = React.useState(null);
75
+ const measure = !!props.stackBelow || columns.some(function(c) {
65
76
  return c.hideBelow != null;
66
77
  });
67
- React.useEffect(function() {
68
- if (!measure || !wrapRef.current || typeof ResizeObserver === "undefined") return;
69
- var ro = new ResizeObserver(function(en) {
70
- boxWidth[1](en[0].contentRect.width);
71
- });
72
- ro.observe(wrapRef.current);
73
- return function() {
74
- ro.disconnect();
75
- };
76
- }, [measure]);
77
- var stacked = !!props.stackBelow && boxWidth[0] != null && boxWidth[0] < props.stackBelow;
78
+ React.useEffect(
79
+ function() {
80
+ if (!measure || !wrapRef.current || typeof ResizeObserver === "undefined") return;
81
+ const ro = new ResizeObserver(function(en) {
82
+ boxWidth[1](en[0].contentRect.width);
83
+ });
84
+ ro.observe(wrapRef.current);
85
+ return function() {
86
+ ro.disconnect();
87
+ };
88
+ },
89
+ [measure]
90
+ );
91
+ const stacked = !!props.stackBelow && boxWidth[0] != null && boxWidth[0] < props.stackBelow;
78
92
  function tooNarrow(c) {
79
93
  if (c.hideBelow == null || boxWidth[0] == null || stacked) return false;
80
- var px = typeof c.hideBelow === "number" ? c.hideBelow : BP[c.hideBelow];
94
+ const px = typeof c.hideBelow === "number" ? c.hideBelow : BP[c.hideBelow];
81
95
  return px != null && boxWidth[0] < px;
82
96
  }
83
- var scrollRef = React.useRef(null);
84
- var pending = React.useRef(null);
85
- var resizing = React.useRef(false);
97
+ const scrollRef = React.useRef(null);
98
+ const pending = React.useRef(null);
99
+ const resizing = React.useRef(false);
86
100
  useIsoLayoutEffect(function() {
87
101
  if (stacked || !gridRef.current) return;
88
- var els = gridRef.current.querySelectorAll('.aura-table__td button, .aura-table__td a[href], .aura-table__td input, .aura-table__td select, .aura-table__td textarea, .aura-table__td [tabindex="0"]');
89
- for (var i2 = 0; i2 < els.length; i2++) if (els[i2].tabIndex !== -1) els[i2].tabIndex = -1;
102
+ const els = gridRef.current.querySelectorAll(
103
+ '.aura-table__td button, .aura-table__td a[href], .aura-table__td input, .aura-table__td select, .aura-table__td textarea, .aura-table__td [tabindex="0"]'
104
+ );
105
+ for (let i = 0; i < els.length; i++) if (els[i].tabIndex !== -1) els[i].tabIndex = -1;
90
106
  });
91
107
  function widthOf(c) {
92
108
  return widths[c.key] != null ? widths[c.key] : c.width;
93
109
  }
94
- var order = orderState[0].filter(function(k) {
110
+ const order = orderState[0].filter(function(k) {
95
111
  return byKey[k];
96
112
  });
97
113
  columns.forEach(function(c) {
98
114
  if (order.indexOf(c.key) < 0) order.push(c.key);
99
115
  });
100
- var hidden = hiddenState[0], pinnedKeys = pinState[0];
101
- var shown = order.filter(function(k) {
116
+ const hidden = hiddenState[0], pinnedKeys = pinState[0];
117
+ const shown = order.filter(function(k) {
102
118
  return hidden.indexOf(k) < 0;
103
119
  }).map(function(k) {
104
120
  return byKey[k];
@@ -108,84 +124,89 @@ const DataTable = React.forwardRef(function DataTable2(props, ref) {
108
124
  function isPinned(c) {
109
125
  return pinnedKeys.indexOf(c.key) >= 0 && c.width != null;
110
126
  }
111
- var vis = shown.filter(isPinned).concat(shown.filter(function(c) {
112
- return !isPinned(c);
113
- }));
114
- var nPinned = vis.filter(isPinned).length;
115
- var hasFlex = vis.some(function(c) {
127
+ const vis = shown.filter(isPinned).concat(
128
+ shown.filter(function(c) {
129
+ return !isPinned(c);
130
+ })
131
+ );
132
+ const nPinned = vis.filter(isPinned).length;
133
+ const hasFlex = vis.some(function(c) {
116
134
  return widthOf(c) == null;
117
135
  });
118
- var fixedSum = 0;
136
+ let fixedSum = 0;
119
137
  vis.forEach(function(c) {
120
138
  fixedSum += widthOf(c) != null ? widthOf(c) : FLEX_MIN;
121
139
  });
122
- var pinOffsets = {}, acc = 0;
140
+ let pinOffsets = {}, acc = 0;
123
141
  vis.forEach(function(c) {
124
142
  if (isPinned(c)) {
125
143
  pinOffsets[c.key] = acc;
126
144
  acc += widthOf(c);
127
145
  }
128
146
  });
129
- var selW = selectable ? " + var(--aura-table-select-width)" : "";
130
- var gutterR = controls ? "var(--aura-space-12)" : "var(--aura-space-6)";
131
- var rowMinWidth = "calc(" + fixedSum + "px + var(--aura-space-6) + " + gutterR + selW + ")";
132
- function cellStyle(c, i2) {
133
- var w = widthOf(c), s;
147
+ const selW = selectable ? " + var(--aura-table-select-width)" : "";
148
+ const gutterR = controls ? "var(--aura-space-12)" : "var(--aura-space-6)";
149
+ const rowMinWidth = "calc(" + fixedSum + "px + var(--aura-space-6) + " + gutterR + selW + ")";
150
+ function cellStyle(c, i) {
151
+ let w = widthOf(c), s;
134
152
  if (w == null) s = { flex: "1 1 0", minWidth: (c.minWidth || FLEX_MIN) + "px" };
135
- else if (!hasFlex && i2 === vis.length - 1) s = { flex: "1 0 auto", width: w + "px" };
153
+ else if (!hasFlex && i === vis.length - 1) s = { flex: "1 0 auto", width: w + "px" };
136
154
  else s = { width: w + "px", flex: "none" };
137
155
  if (isPinned(c)) s.left = "calc(var(--aura-space-6)" + selW + " + " + pinOffsets[c.key] + "px)";
138
156
  return s;
139
157
  }
140
- var view = React.useMemo(function() {
141
- if (!sort || !sort.key || !byKey[sort.key]) return rows;
142
- var col = byKey[sort.key];
143
- var val = col.sortValue || (col.pill ? function(r) {
144
- return TONE_ORDER[col.tones && col.tones[r[col.key]] || toneFor(r[col.key])];
145
- } : function(r) {
146
- return r[col.key];
147
- });
148
- var dir = sort.dir === "desc" ? -1 : 1;
149
- return rows.map(function(r, i2) {
150
- return [r, i2];
151
- }).sort(function(a, b) {
152
- return compare(val(a[0]), val(b[0])) * dir || a[1] - b[1];
153
- }).map(function(p) {
154
- return p[0];
155
- });
156
- }, [rows, sort && sort.key, sort && sort.dir]);
158
+ const view = React.useMemo(
159
+ function() {
160
+ if (!sort || !sort.key || !byKey[sort.key]) return rows;
161
+ const col = byKey[sort.key];
162
+ const val = col.sortValue || (col.pill ? function(r) {
163
+ return TONE_ORDER[col.tones && col.tones[r[col.key]] || toneFor(r[col.key])];
164
+ } : function(r) {
165
+ return r[col.key];
166
+ });
167
+ const dir = sort.dir === "desc" ? -1 : 1;
168
+ return rows.map(function(r, i) {
169
+ return [r, i];
170
+ }).sort(function(a, b) {
171
+ return compare(val(a[0]), val(b[0])) * dir || a[1] - b[1];
172
+ }).map(function(p) {
173
+ return p[0];
174
+ });
175
+ },
176
+ [rows, sort && sort.key, sort && sort.dir]
177
+ );
157
178
  function nextSort(key) {
158
179
  if (!sort || sort.key !== key) return { key, dir: "asc" };
159
180
  if (sort.dir === "asc") return { key, dir: "desc" };
160
181
  return null;
161
182
  }
162
- var pageSize = props.pageSize || 0;
163
- var pageCount = pageSize ? Math.max(1, Math.ceil(view.length / pageSize)) : 1;
164
- var page = Math.min(Math.max(1, pageState[0] || 1), pageCount);
165
- var first = pageSize ? (page - 1) * pageSize : 0;
166
- var pageRows = pageSize ? view.slice(first, first + pageSize) : view;
183
+ const pageSize = props.pageSize || 0;
184
+ const pageCount = pageSize ? Math.max(1, Math.ceil(view.length / pageSize)) : 1;
185
+ const page = Math.min(Math.max(1, pageState[0] || 1), pageCount);
186
+ const first = pageSize ? (page - 1) * pageSize : 0;
187
+ const pageRows = pageSize ? view.slice(first, first + pageSize) : view;
167
188
  function goPage(p, focus) {
168
- var next = Math.min(Math.max(1, p), pageCount);
189
+ const next = Math.min(Math.max(1, p), pageCount);
169
190
  if (next === page) return false;
170
191
  if (focus) pending.current = focus;
171
192
  pageState[1](next);
172
193
  if (scrollRef.current) scrollRef.current.scrollTop = 0;
173
194
  return true;
174
195
  }
175
- var height = props.height || 0;
176
- var virtual = !!height && !loading && pageRows.length > 0;
177
- var bodyH = Math.max(ROW_H, height - ROW_H);
178
- var start = 0, end = pageRows.length;
196
+ const height = props.height || 0;
197
+ const virtual = !!height && !loading && pageRows.length > 0;
198
+ const bodyH = Math.max(ROW_H, height - ROW_H);
199
+ let start = 0, end = pageRows.length;
179
200
  if (virtual) {
180
201
  start = Math.max(0, Math.floor(scrollTop / ROW_H) - OVERSCAN);
181
202
  end = Math.min(pageRows.length, Math.ceil((scrollTop + bodyH) / ROW_H) + OVERSCAN);
182
203
  }
183
- var visibleRows = Math.max(1, Math.floor(bodyH / ROW_H));
184
- var nCols = vis.length + (selectable ? 1 : 0);
185
- var nRows = loading ? 0 : pageRows.length;
186
- var active = activeState[0];
187
- var ar = Math.min(active.r, nRows), ac = Math.min(active.c, nCols - 1);
188
- var activeRendered = ar === 0 || ar - 1 >= start && ar - 1 < end;
204
+ const visibleRows = Math.max(1, Math.floor(bodyH / ROW_H));
205
+ const nCols = vis.length + (selectable ? 1 : 0);
206
+ const nRows = loading ? 0 : pageRows.length;
207
+ const active = activeState[0];
208
+ const ar = Math.min(active.r, nRows), ac = Math.min(active.c, nCols - 1);
209
+ const activeRendered = ar === 0 || ar - 1 >= start && ar - 1 < end;
189
210
  function colAt(ci) {
190
211
  return selectable ? ci === 0 ? null : vis[ci - 1] : vis[ci];
191
212
  }
@@ -194,17 +215,17 @@ const DataTable = React.forwardRef(function DataTable2(props, ref) {
194
215
  return r === ar && c === ac ? 0 : -1;
195
216
  }
196
217
  React.useEffect(function() {
197
- var p = pending.current;
218
+ const p = pending.current;
198
219
  if (!p || !gridRef.current) return;
199
- var c = p.c;
220
+ let c = p.c;
200
221
  if (p.key) {
201
- var at = -1;
202
- vis.forEach(function(x, i2) {
203
- if (x.key === p.key) at = i2;
222
+ let at = -1;
223
+ vis.forEach(function(x, i) {
224
+ if (x.key === p.key) at = i;
204
225
  });
205
226
  c = at >= 0 ? at + (selectable ? 1 : 0) : Math.min(p.c || 0, nCols - 1);
206
227
  }
207
- var el = gridRef.current.querySelector('[data-rc="' + p.r + ":" + c + '"]');
228
+ const el = gridRef.current.querySelector('[data-rc="' + p.r + ":" + c + '"]');
208
229
  if (el) {
209
230
  pending.current = null;
210
231
  el.focus();
@@ -216,50 +237,56 @@ const DataTable = React.forwardRef(function DataTable2(props, ref) {
216
237
  activeState[1]({ r, c });
217
238
  pending.current = { r, c };
218
239
  if (virtual && r > 0) {
219
- var sc = scrollRef.current, top = (r - 1) * ROW_H;
240
+ const sc = scrollRef.current, top = (r - 1) * ROW_H;
220
241
  if (top < sc.scrollTop) sc.scrollTop = top;
221
242
  else if (top + ROW_H > sc.scrollTop + bodyH) sc.scrollTop = top + ROW_H - bodyH;
222
243
  setScrollTop(sc.scrollTop);
223
244
  }
224
- var el = gridRef.current && gridRef.current.querySelector('[data-rc="' + r + ":" + c + '"]');
245
+ const el = gridRef.current && gridRef.current.querySelector('[data-rc="' + r + ":" + c + '"]');
225
246
  if (el) {
226
247
  pending.current = null;
227
248
  el.focus();
228
249
  }
229
250
  }
230
- var pageKeys = pageRows.map(function(r) {
251
+ const pageKeys = pageRows.map(function(r) {
231
252
  return r[rowKey];
232
253
  });
233
- var selSet = {};
254
+ const selSet = {};
234
255
  selected.forEach(function(k) {
235
256
  selSet[k] = true;
236
257
  });
237
- var nSel = pageKeys.filter(function(k) {
258
+ const nSel = pageKeys.filter(function(k) {
238
259
  return selSet[k];
239
260
  }).length;
240
- var all = nSel > 0 && nSel === pageKeys.length;
261
+ const all = nSel > 0 && nSel === pageKeys.length;
241
262
  function toggle(k, on) {
242
- setSelected(on ? selected.concat([k]) : selected.filter(function(x) {
243
- return x !== k;
244
- }));
263
+ setSelected(
264
+ on ? selected.concat([k]) : selected.filter(function(x) {
265
+ return x !== k;
266
+ })
267
+ );
245
268
  }
246
269
  function toggleAll() {
247
- setSelected(all ? selected.filter(function(k) {
248
- return pageKeys.indexOf(k) < 0;
249
- }) : selected.concat(pageKeys.filter(function(k) {
250
- return !selSet[k];
251
- })));
270
+ setSelected(
271
+ all ? selected.filter(function(k) {
272
+ return pageKeys.indexOf(k) < 0;
273
+ }) : selected.concat(
274
+ pageKeys.filter(function(k) {
275
+ return !selSet[k];
276
+ })
277
+ )
278
+ );
252
279
  }
253
280
  function canResize(c) {
254
- return props.resizable && c.resizable !== false && c.width != null;
281
+ return !!props.resizable && c.resizable !== false && c.width != null;
255
282
  }
256
283
  function clampW(c, w) {
257
284
  return Math.round(Math.min(c.maxWidth || 480, Math.max(c.minWidth || 64, w)));
258
285
  }
259
286
  function setW(c, w, done) {
260
- var nw = clampW(c, w);
287
+ const nw = clampW(c, w);
261
288
  setWidths(function(prev) {
262
- var o = Object.assign({}, prev);
289
+ const o = Object.assign({}, prev);
263
290
  o[c.key] = nw;
264
291
  return o;
265
292
  });
@@ -269,8 +296,8 @@ const DataTable = React.forwardRef(function DataTable2(props, ref) {
269
296
  e.preventDefault();
270
297
  e.stopPropagation();
271
298
  resizing.current = true;
272
- var x0 = e.clientX, w0 = widthOf(c), last = w0;
273
- var el = e.currentTarget;
299
+ let x0 = e.clientX, w0 = widthOf(c), last = w0;
300
+ const el = e.currentTarget;
274
301
  el.classList.add("is-dragging");
275
302
  document.body.style.cursor = "col-resize";
276
303
  function move(ev) {
@@ -291,99 +318,148 @@ const DataTable = React.forwardRef(function DataTable2(props, ref) {
291
318
  window.addEventListener("pointerup", up);
292
319
  }
293
320
  function moveCol(key, delta) {
294
- var c = byKey[key], group = vis.filter(function(x) {
321
+ const c = byKey[key], group = vis.filter(function(x) {
295
322
  return isPinned(x) === isPinned(c);
296
323
  });
297
- var gi = group.indexOf(c), target = group[gi + delta];
324
+ const gi = group.indexOf(c), target = group[gi + delta];
298
325
  if (!target) return false;
299
- var o = order.slice(), from2 = o.indexOf(key), to2 = o.indexOf(target.key);
300
- o.splice(from2, 1);
301
- o.splice(to2, 0, key);
326
+ const o = order.slice(), from = o.indexOf(key), to = o.indexOf(target.key);
327
+ o.splice(from, 1);
328
+ o.splice(to, 0, key);
302
329
  orderState[1](o);
303
330
  return true;
304
331
  }
305
332
  function dropCol(key, targetKey, after) {
306
333
  if (key === targetKey) return;
307
- var a = byKey[key], b = byKey[targetKey];
334
+ const a = byKey[key], b = byKey[targetKey];
308
335
  if (isPinned(a) !== isPinned(b)) return;
309
- var o = order.slice();
336
+ const o = order.slice();
310
337
  o.splice(o.indexOf(key), 1);
311
- var to2 = o.indexOf(targetKey) + (after ? 1 : 0);
312
- o.splice(to2, 0, key);
338
+ const to = o.indexOf(targetKey) + (after ? 1 : 0);
339
+ o.splice(to, 0, key);
313
340
  orderState[1](o);
314
341
  }
315
342
  function togglePin(key) {
316
- pinState[1](pinnedKeys.indexOf(key) >= 0 ? pinnedKeys.filter(function(k) {
317
- return k !== key;
318
- }) : pinnedKeys.concat([key]));
343
+ pinState[1](
344
+ pinnedKeys.indexOf(key) >= 0 ? pinnedKeys.filter(function(k) {
345
+ return k !== key;
346
+ }) : pinnedKeys.concat([key])
347
+ );
319
348
  }
320
349
  function setHidden(key, hide) {
321
350
  if (hide && shown.length <= 1) return;
322
- hiddenState[1](hide ? hidden.concat([key]) : hidden.filter(function(k) {
323
- return k !== key;
324
- }));
351
+ hiddenState[1](
352
+ hide ? hidden.concat([key]) : hidden.filter(function(k) {
353
+ return k !== key;
354
+ })
355
+ );
325
356
  }
326
357
  function resetColumns() {
327
- orderState[1](columns.map(function(c) {
328
- return c.key;
329
- }));
330
- hiddenState[1](columns.filter(function(c) {
331
- return c.hidden;
332
- }).map(function(c) {
333
- return c.key;
334
- }));
335
- pinState[1](columns.filter(function(c) {
336
- return c.pinned;
337
- }).map(function(c) {
338
- return c.key;
339
- }));
358
+ orderState[1](
359
+ columns.map(function(c) {
360
+ return c.key;
361
+ })
362
+ );
363
+ hiddenState[1](
364
+ columns.filter(function(c) {
365
+ return c.hidden;
366
+ }).map(function(c) {
367
+ return c.key;
368
+ })
369
+ );
370
+ pinState[1](
371
+ columns.filter(function(c) {
372
+ return c.pinned;
373
+ }).map(function(c) {
374
+ return c.key;
375
+ })
376
+ );
340
377
  setWidths({});
341
378
  }
342
379
  function columnMenuItems(c) {
343
- var group = vis.filter(function(x) {
380
+ const group = vis.filter(function(x) {
344
381
  return isPinned(x) === isPinned(c);
345
382
  }), gi = group.indexOf(c);
346
- var items = [];
347
- if (c.sortable) items.push(
348
- { label: t.sortAsc, icon: "arrow-up", onSelect: function() {
349
- setSort({ key: c.key, dir: "asc" });
350
- goPage(1);
351
- } },
352
- { label: t.sortDesc, icon: "arrow-down", onSelect: function() {
353
- setSort({ key: c.key, dir: "desc" });
354
- goPage(1);
355
- } },
356
- { separator: true }
357
- );
358
- if (c.width != null) items.push({ label: isPinned(c) ? t.unpin : t.pin, icon: isPinned(c) ? "pin-off" : "pin", onSelect: function() {
359
- togglePin(c.key);
360
- } });
361
- if (reorderable) items.push(
362
- { label: t.moveLeft, icon: "arrow-left", disabled: gi <= 0, onSelect: function() {
363
- moveCol(c.key, -1);
364
- } },
365
- { label: t.moveRight, icon: "arrow-right", disabled: gi >= group.length - 1, onSelect: function() {
366
- moveCol(c.key, 1);
367
- } }
383
+ const items = [];
384
+ if (c.sortable)
385
+ items.push(
386
+ {
387
+ label: t.sortAsc,
388
+ icon: "arrow-up",
389
+ onSelect: function() {
390
+ setSort({ key: c.key, dir: "asc" });
391
+ goPage(1);
392
+ }
393
+ },
394
+ {
395
+ label: t.sortDesc,
396
+ icon: "arrow-down",
397
+ onSelect: function() {
398
+ setSort({ key: c.key, dir: "desc" });
399
+ goPage(1);
400
+ }
401
+ },
402
+ { separator: true }
403
+ );
404
+ if (c.width != null)
405
+ items.push({
406
+ label: isPinned(c) ? t.unpin : t.pin,
407
+ icon: isPinned(c) ? "pin-off" : "pin",
408
+ onSelect: function() {
409
+ togglePin(c.key);
410
+ }
411
+ });
412
+ if (reorderable)
413
+ items.push(
414
+ {
415
+ label: t.moveLeft,
416
+ icon: "arrow-left",
417
+ disabled: gi <= 0,
418
+ onSelect: function() {
419
+ moveCol(c.key, -1);
420
+ }
421
+ },
422
+ {
423
+ label: t.moveRight,
424
+ icon: "arrow-right",
425
+ disabled: gi >= group.length - 1,
426
+ onSelect: function() {
427
+ moveCol(c.key, 1);
428
+ }
429
+ }
430
+ );
431
+ items.push(
432
+ { separator: true },
433
+ {
434
+ label: t.hideColumn,
435
+ icon: "eye-off",
436
+ disabled: shown.length <= 1,
437
+ onSelect: function() {
438
+ setHidden(c.key, true);
439
+ }
440
+ }
368
441
  );
369
- items.push({ separator: true }, { label: t.hideColumn, icon: "eye-off", disabled: shown.length <= 1, onSelect: function() {
370
- setHidden(c.key, true);
371
- } });
372
442
  return items;
373
443
  }
374
444
  function pickerItems() {
375
445
  return order.map(function(k) {
376
- var c = byKey[k], on = hidden.indexOf(k) < 0;
377
- return { label: c.label || (c.actions ? t.actions : c.key), checked: on, keepOpen: true, disabled: on && shown.length <= 1, onSelect: function() {
378
- setHidden(k, on);
379
- } };
446
+ const c = byKey[k], on = hidden.indexOf(k) < 0;
447
+ return {
448
+ label: c.label || (c.actions ? t.actions : c.key),
449
+ checked: on,
450
+ keepOpen: true,
451
+ disabled: on && shown.length <= 1,
452
+ onSelect: function() {
453
+ setHidden(k, on);
454
+ }
455
+ };
380
456
  }).concat([{ separator: true }, { label: t.resetColumns, icon: "rotate-ccw", onSelect: resetColumns }]);
381
457
  }
382
458
  function openMenu(kind, key, anchor, rc) {
383
459
  setMenu({ kind, key, anchor, rc });
384
460
  }
385
461
  function closeMenu(restore) {
386
- var m = menu;
462
+ const m = menu;
387
463
  setMenu(null);
388
464
  if (restore && m) {
389
465
  if (m.kind === "col") pending.current = { r: 0, key: m.key, c: m.rc ? m.rc.c : 0 };
@@ -391,23 +467,26 @@ const DataTable = React.forwardRef(function DataTable2(props, ref) {
391
467
  }
392
468
  }
393
469
  function onGridKey(e) {
394
- if (!gridRef.current || !gridRef.current.contains(e.target)) return;
395
- var rc = e.target.getAttribute && e.target.getAttribute("data-rc");
470
+ const target = e.target;
471
+ if (!gridRef.current || !gridRef.current.contains(target)) return;
472
+ const rc = target.getAttribute && target.getAttribute("data-rc");
396
473
  if (!rc) {
397
- var cell = e.key === "Escape" && e.target.closest && e.target.closest("[data-rc]");
474
+ const cell = e.key === "Escape" && target.closest && target.closest("[data-rc]");
398
475
  if (cell) {
399
476
  e.preventDefault();
400
477
  cell.focus();
401
478
  }
402
479
  return;
403
480
  }
404
- var p = rc.split(":"), r = +p[0], c = +p[1], k = e.key, col = colAt(c);
405
- var row = r > 0 ? pageRows[r - 1] : null;
406
- var handled = true;
407
- if (r === 0 && col && e.altKey && (k === "ArrowLeft" || k === "ArrowRight") && canResize(col)) setW(col, widthOf(col) + (k === "ArrowLeft" ? -1 : 1) * (e.shiftKey ? 48 : 16), true);
481
+ const p = rc.split(":"), r = +p[0], c = +p[1], k = e.key, col = colAt(c);
482
+ const row = r > 0 ? pageRows[r - 1] : null;
483
+ let handled = true;
484
+ if (r === 0 && col && e.altKey && (k === "ArrowLeft" || k === "ArrowRight") && canResize(col))
485
+ setW(col, widthOf(col) + (k === "ArrowLeft" ? -1 : 1) * (e.shiftKey ? 48 : 16), true);
408
486
  else if (r === 0 && col && e.ctrlKey && e.shiftKey && (k === "ArrowLeft" || k === "ArrowRight") && reorderable) {
409
487
  if (moveCol(col.key, k === "ArrowLeft" ? -1 : 1)) pending.current = { r: 0, key: col.key, c };
410
- } else if (r === 0 && col && (e.altKey && k === "ArrowDown" || k === "ContextMenu" || e.shiftKey && k === "F10") && controls) openMenu("col", col.key, e.target, { r: 0, c });
488
+ } else if (r === 0 && col && (e.altKey && k === "ArrowDown" || k === "ContextMenu" || e.shiftKey && k === "F10") && controls)
489
+ openMenu("col", col.key, target, { r: 0, c });
411
490
  else if (k === "ArrowRight") focusCell(r, c + 1);
412
491
  else if (k === "ArrowLeft") focusCell(r, c - 1);
413
492
  else if (k === "ArrowDown") {
@@ -426,13 +505,18 @@ const DataTable = React.forwardRef(function DataTable2(props, ref) {
426
505
  if (pageSize) {
427
506
  if (goPage(page - 1, { r: 1, c })) activeState[1]({ r: 1, c });
428
507
  } else focusCell(Math.max(1, r - visibleRows), c);
508
+ } else if (k === "F2" && r > 0) {
509
+ const inner = target.querySelector("button, a[href], input, select, textarea");
510
+ if (inner) inner.focus();
511
+ else handled = false;
429
512
  } else if (k === " " || k === "Enter") {
430
513
  if (r === 0 && !col && selectable && nRows) toggleAll();
431
514
  else if (r === 0 && col && col.sortable && nRows > 1) {
432
515
  setSort(nextSort(col.key));
433
516
  goPage(1);
434
517
  } else if (r > 0 && k === " " && selectable) toggle(row[rowKey], !selSet[row[rowKey]]);
435
- else if (r > 0 && (k === "Enter" || k === "F2") && e.target.querySelector("button, a[href], input, select, textarea")) e.target.querySelector("button, a[href], input, select, textarea").focus();
518
+ else if (r > 0 && k === "Enter" && target.querySelector("button, a[href], input, select, textarea"))
519
+ target.querySelector("button, a[href], input, select, textarea").focus();
436
520
  else if (r > 0 && k === "Enter" && props.onRowActivate) props.onRowActivate(row);
437
521
  else handled = false;
438
522
  } else handled = false;
@@ -441,83 +525,91 @@ const DataTable = React.forwardRef(function DataTable2(props, ref) {
441
525
  e.stopPropagation();
442
526
  }
443
527
  }
444
- var head = [h("span", { key: "__gl", className: "aura-table__gutter", "aria-hidden": true })];
445
- if (selectable) head.push(h("span", {
446
- key: "__sel",
447
- role: "columnheader",
448
- "aria-colindex": 1,
449
- className: cx("aura-table__sel", nPinned && "is-pinned"),
450
- tabIndex: tabFor(0, 0),
451
- "data-rc": "0:0",
452
- "aria-label": t.selectRows,
453
- onFocus: function() {
454
- activeState[1]({ r: 0, c: 0 });
455
- }
456
- }, nRows ? h(Checkbox, {
457
- checked: all,
458
- indeterminate: nSel > 0 && !all,
459
- tabIndex: -1,
460
- label: all ? t.deselectAllRows : t.selectAllRows,
461
- onChange: toggleAll
462
- }) : null));
463
- vis.forEach(function(c, i2) {
464
- var ci = i2 + (selectable ? 1 : 0);
465
- var isSorted = sort && sort.key === c.key;
466
- var canSort = c.sortable && rows.length > 1 && !loading;
467
- var ariaSort = isSorted && canSort ? sort.dir === "desc" ? "descending" : "ascending" : canSort ? "none" : void 0;
468
- var pin = isPinned(c), edge = pin && i2 === nPinned - 1;
469
- head.push(h(
470
- "span",
471
- {
472
- key: c.key,
473
- role: "columnheader",
474
- "aria-sort": ariaSort,
475
- "aria-colindex": ci + 1,
476
- style: cellStyle(c, i2),
477
- tabIndex: tabFor(0, ci),
478
- "data-rc": "0:" + ci,
479
- className: cx(
480
- "aura-table__th",
481
- pin && "is-pinned",
482
- edge && "is-pin-edge",
483
- drag && drag.over === c.key && (drag.after ? "is-drop-after" : "is-drop-before"),
484
- drag && drag.key === c.key && "is-dragging"
485
- ),
486
- draggable: reorderable && !loading ? true : void 0,
487
- onFocus: function(e) {
488
- if (e.target === e.currentTarget) activeState[1]({ r: 0, c: ci });
528
+ const head = [/* @__PURE__ */ React.createElement("span", { key: "__gl", className: "aura-table__gutter", "aria-hidden": true })];
529
+ if (selectable)
530
+ head.push(
531
+ /* @__PURE__ */ React.createElement(
532
+ "span",
533
+ {
534
+ key: "__sel",
535
+ role: "columnheader",
536
+ "aria-colindex": 1,
537
+ className: cx("aura-table__sel", nPinned && "is-pinned"),
538
+ tabIndex: tabFor(0, 0),
539
+ "data-rc": "0:0",
540
+ "aria-label": t.selectRows,
541
+ onFocus: function() {
542
+ activeState[1]({ r: 0, c: 0 });
543
+ }
489
544
  },
490
- onDragStart: function(e) {
491
- if (resizing.current) {
492
- e.preventDefault();
493
- return;
545
+ nRows ? /* @__PURE__ */ React.createElement(
546
+ Checkbox,
547
+ {
548
+ checked: all,
549
+ indeterminate: nSel > 0 && !all,
550
+ tabIndex: -1,
551
+ label: all ? t.deselectAllRows : t.selectAllRows,
552
+ onChange: toggleAll
494
553
  }
495
- e.dataTransfer.effectAllowed = "move";
496
- try {
497
- e.dataTransfer.setData("text/plain", c.key);
498
- } catch (x) {
554
+ ) : null
555
+ )
556
+ );
557
+ vis.forEach(function(c, i) {
558
+ const ci = i + (selectable ? 1 : 0);
559
+ const isSorted = sort && sort.key === c.key;
560
+ const canSort = c.sortable && rows.length > 1 && !loading;
561
+ const ariaSort = isSorted && canSort ? sort.dir === "desc" ? "descending" : "ascending" : canSort ? "none" : void 0;
562
+ const pin = isPinned(c), edge = pin && i === nPinned - 1;
563
+ head.push(
564
+ /* @__PURE__ */ React.createElement(
565
+ "span",
566
+ {
567
+ key: c.key,
568
+ role: "columnheader",
569
+ "aria-sort": ariaSort,
570
+ "aria-colindex": ci + 1,
571
+ style: cellStyle(c, i),
572
+ tabIndex: tabFor(0, ci),
573
+ "data-rc": "0:" + ci,
574
+ className: cx(
575
+ "aura-table__th",
576
+ pin && "is-pinned",
577
+ edge && "is-pin-edge",
578
+ drag && drag.over === c.key && (drag.after ? "is-drop-after" : "is-drop-before"),
579
+ drag && drag.key === c.key && "is-dragging"
580
+ ),
581
+ draggable: reorderable && !loading ? true : void 0,
582
+ onFocus: function(e) {
583
+ if (e.target === e.currentTarget) activeState[1]({ r: 0, c: ci });
584
+ },
585
+ onDragStart: function(e) {
586
+ if (resizing.current) {
587
+ e.preventDefault();
588
+ return;
589
+ }
590
+ e.dataTransfer.effectAllowed = "move";
591
+ try {
592
+ e.dataTransfer.setData("text/plain", c.key);
593
+ } catch (x) {
594
+ }
595
+ setDrag({ key: c.key });
596
+ },
597
+ onDragOver: function(e) {
598
+ if (!drag || drag.key === c.key || isPinned(byKey[drag.key]) !== pin) return;
599
+ e.preventDefault();
600
+ const b = e.currentTarget.getBoundingClientRect(), after = e.clientX > b.left + b.width / 2;
601
+ if (drag.over !== c.key || drag.after !== after) setDrag({ key: drag.key, over: c.key, after });
602
+ },
603
+ onDrop: function(e) {
604
+ e.preventDefault();
605
+ if (drag && drag.over) dropCol(drag.key, drag.over, drag.after);
606
+ setDrag(null);
607
+ },
608
+ onDragEnd: function() {
609
+ setDrag(null);
499
610
  }
500
- setDrag({ key: c.key });
501
- },
502
- onDragOver: function(e) {
503
- if (!drag || drag.key === c.key || isPinned(byKey[drag.key]) !== pin) return;
504
- e.preventDefault();
505
- var b = e.currentTarget.getBoundingClientRect(), after = e.clientX > b.left + b.width / 2;
506
- if (drag.over !== c.key || drag.after !== after) setDrag({ key: drag.key, over: c.key, after });
507
- },
508
- onDrop: function(e) {
509
- e.preventDefault();
510
- if (drag && drag.over) dropCol(drag.key, drag.over, drag.after);
511
- setDrag(null);
512
611
  },
513
- onDragEnd: function() {
514
- setDrag(null);
515
- }
516
- },
517
- h(
518
- "span",
519
- { className: "aura-table__th-inner" },
520
- canSort ? h(
612
+ /* @__PURE__ */ React.createElement("span", { className: "aura-table__th-inner" }, canSort ? /* @__PURE__ */ React.createElement(
521
613
  "button",
522
614
  {
523
615
  type: "button",
@@ -530,10 +622,8 @@ const DataTable = React.forwardRef(function DataTable2(props, ref) {
530
622
  }
531
623
  },
532
624
  c.label,
533
- h(Icon, { name: isSorted ? sort.dir === "desc" ? "arrow-down" : "arrow-up" : "arrow-up-down", size: 12 })
534
- ) : h("span", { className: cx("aura-table__th-label", !c.label && "aura-sr-only") }, c.label || (c.actions ? t.actions : c.key)),
535
- pin ? h(Icon, { name: "pin", size: 12, className: "aura-table__pin-icon", label: t.pinned }) : null,
536
- controls ? h(
625
+ /* @__PURE__ */ React.createElement(Icon, { name: isSorted ? sort.dir === "desc" ? "arrow-down" : "arrow-up" : "arrow-up-down", size: 12 })
626
+ ) : /* @__PURE__ */ React.createElement("span", { className: cx("aura-table__th-label", !c.label && "aura-sr-only") }, c.label || (c.actions ? t.actions : c.key)), pin ? /* @__PURE__ */ React.createElement(Icon, { name: "pin", size: 12, className: "aura-table__pin-icon", label: t.pinned }) : null, controls ? /* @__PURE__ */ React.createElement(
537
627
  "button",
538
628
  {
539
629
  type: "button",
@@ -547,279 +637,330 @@ const DataTable = React.forwardRef(function DataTable2(props, ref) {
547
637
  openMenu("col", c.key, e.currentTarget, { r: 0, c: ci });
548
638
  }
549
639
  },
550
- h(Icon, { name: "ellipsis" })
640
+ /* @__PURE__ */ React.createElement(Icon, { name: "ellipsis" })
641
+ ) : null),
642
+ canResize(c) ? /* @__PURE__ */ React.createElement(
643
+ "span",
644
+ {
645
+ className: "aura-table__resize",
646
+ role: "separator",
647
+ "aria-orientation": "vertical",
648
+ "aria-hidden": true,
649
+ onPointerDown: function(e) {
650
+ startResize(c, e);
651
+ },
652
+ onClick: function(e) {
653
+ e.stopPropagation();
654
+ },
655
+ onDoubleClick: function() {
656
+ setW(c, c.width, true);
657
+ }
658
+ }
551
659
  ) : null
552
- ),
553
- canResize(c) ? h("span", {
554
- className: "aura-table__resize",
555
- role: "separator",
556
- "aria-orientation": "vertical",
557
- "aria-hidden": true,
558
- onPointerDown: function(e) {
559
- startResize(c, e);
560
- },
561
- onClick: function(e) {
562
- e.stopPropagation();
563
- },
564
- onDoubleClick: function() {
565
- setW(c, c.width, true);
566
- }
567
- }) : null
568
- ));
660
+ )
661
+ );
569
662
  });
570
- head.push(h("span", { key: "__gr", className: cx("aura-table__gutter aura-table__gutter--end", controls && "has-picker"), "aria-hidden": true }));
571
- function rowCells(r, i2, k, isSel) {
572
- var ri2 = i2 + 1;
573
- var cells = [h("span", { key: "__gl", className: "aura-table__gutter", "aria-hidden": true })];
574
- if (selectable) cells.push(h("span", {
575
- key: "__sel",
576
- role: "gridcell",
577
- "aria-colindex": 1,
578
- className: cx("aura-table__sel", nPinned && "is-pinned"),
579
- tabIndex: tabFor(ri2, 0),
580
- "data-rc": ri2 + ":0",
581
- "aria-label": t.selectRow(k),
582
- onFocus: function(e) {
583
- if (e.target === e.currentTarget) activeState[1]({ r: ri2, c: 0 });
663
+ head.push(
664
+ /* @__PURE__ */ React.createElement(
665
+ "span",
666
+ {
667
+ key: "__gr",
668
+ className: cx("aura-table__gutter aura-table__gutter--end", controls && "has-picker"),
669
+ "aria-hidden": true
584
670
  }
585
- }, h(Checkbox, { checked: isSel, tabIndex: -1, label: t.selectRow(k), onChange: function(on) {
586
- toggle(k, on);
587
- } })));
671
+ )
672
+ );
673
+ function rowCells(r, i, k, isSel) {
674
+ const ri = i + 1;
675
+ const cells = [/* @__PURE__ */ React.createElement("span", { key: "__gl", className: "aura-table__gutter", "aria-hidden": true })];
676
+ if (selectable)
677
+ cells.push(
678
+ /* @__PURE__ */ React.createElement(
679
+ "span",
680
+ {
681
+ key: "__sel",
682
+ role: "gridcell",
683
+ "aria-colindex": 1,
684
+ className: cx("aura-table__sel", nPinned && "is-pinned"),
685
+ tabIndex: tabFor(ri, 0),
686
+ "data-rc": ri + ":0",
687
+ "aria-label": t.selectRow(k),
688
+ onFocus: function(e) {
689
+ if (e.target === e.currentTarget) activeState[1]({ r: ri, c: 0 });
690
+ }
691
+ },
692
+ /* @__PURE__ */ React.createElement(
693
+ Checkbox,
694
+ {
695
+ checked: isSel,
696
+ tabIndex: -1,
697
+ label: t.selectRow(k),
698
+ onChange: function(on) {
699
+ toggle(k, on);
700
+ }
701
+ }
702
+ )
703
+ )
704
+ );
588
705
  vis.forEach(function(c, j) {
589
- var ci = j + (selectable ? 1 : 0), v = r[c.key], pin = isPinned(c);
590
- cells.push(h("span", {
591
- key: c.key,
592
- role: "gridcell",
593
- "aria-colindex": ci + 1,
594
- tabIndex: tabFor(ri2, ci),
595
- "data-rc": ri2 + ":" + ci,
596
- className: cx("aura-table__td", c.mono && "aura-table__mono", pin && "is-pinned", pin && j === nPinned - 1 && "is-pin-edge"),
597
- style: cellStyle(c, j),
598
- onFocus: function() {
599
- if (activeState[0].r !== ri2 || activeState[0].c !== ci) activeState[1]({ r: ri2, c: ci });
600
- }
601
- }, c.render ? c.render(r) : c.pill ? h(StatusPill, { tone: c.tones && c.tones[v] }, v) : v));
706
+ const ci = j + (selectable ? 1 : 0), v = r[c.key], pin = isPinned(c);
707
+ cells.push(
708
+ /* @__PURE__ */ React.createElement(
709
+ "span",
710
+ {
711
+ key: c.key,
712
+ role: "gridcell",
713
+ "aria-colindex": ci + 1,
714
+ tabIndex: tabFor(ri, ci),
715
+ "data-rc": ri + ":" + ci,
716
+ className: cx(
717
+ "aura-table__td",
718
+ c.mono && "aura-table__mono",
719
+ pin && "is-pinned",
720
+ pin && j === nPinned - 1 && "is-pin-edge"
721
+ ),
722
+ style: cellStyle(c, j),
723
+ onFocus: function() {
724
+ if (activeState[0].r !== ri || activeState[0].c !== ci) activeState[1]({ r: ri, c: ci });
725
+ }
726
+ },
727
+ c.render ? c.render(r) : c.pill ? /* @__PURE__ */ React.createElement(StatusPill, { ...{ tone: c.tones && c.tones[v] } }, v) : v
728
+ )
729
+ );
602
730
  });
603
- cells.push(h("span", { key: "__gr", className: cx("aura-table__gutter aura-table__gutter--end", controls && "has-picker"), "aria-hidden": true }));
731
+ cells.push(
732
+ /* @__PURE__ */ React.createElement(
733
+ "span",
734
+ {
735
+ key: "__gr",
736
+ className: cx("aura-table__gutter aura-table__gutter--end", controls && "has-picker"),
737
+ "aria-hidden": true
738
+ }
739
+ )
740
+ );
604
741
  return cells;
605
742
  }
606
- var body;
607
- var rowStyle = { minWidth: rowMinWidth };
743
+ let body;
744
+ const rowStyle = { minWidth: rowMinWidth };
608
745
  if (loading) {
609
- var n = pageSize || props.skeletonRows || 5;
610
- body = [];
611
- for (var i = 0; i < n; i++) {
612
- var sk = [h("span", { key: "__gl", className: "aura-table__gutter" })];
613
- if (selectable) sk.push(h("span", { key: "__sel", className: cx("aura-table__sel", nPinned && "is-pinned") }, h("span", { className: "aura-skel aura-skel--box" })));
746
+ const n = pageSize || props.skeletonRows || 5;
747
+ const skRows = body = [];
748
+ for (let i = 0; i < n; i++) {
749
+ const sk = [/* @__PURE__ */ React.createElement("span", { key: "__gl", className: "aura-table__gutter" })];
750
+ if (selectable)
751
+ sk.push(
752
+ /* @__PURE__ */ React.createElement("span", { key: "__sel", className: cx("aura-table__sel", nPinned && "is-pinned") }, /* @__PURE__ */ React.createElement("span", { className: "aura-skel aura-skel--box" }))
753
+ );
614
754
  vis.forEach(function(c, j) {
615
- sk.push(h(
616
- "span",
617
- { key: c.key, className: cx("aura-table__td", isPinned(c) && "is-pinned"), style: cellStyle(c, j) },
618
- h("span", { className: cx("aura-skel", c.pill && "aura-skel--pill"), style: c.pill ? null : { width: SKELETON_WIDTHS[(i + j) % SKELETON_WIDTHS.length] } })
619
- ));
755
+ sk.push(
756
+ /* @__PURE__ */ React.createElement("span", { key: c.key, className: cx("aura-table__td", isPinned(c) && "is-pinned"), style: cellStyle(c, j) }, /* @__PURE__ */ React.createElement(
757
+ "span",
758
+ {
759
+ className: cx("aura-skel", c.pill && "aura-skel--pill"),
760
+ style: c.pill ? void 0 : { width: SKELETON_WIDTHS[(i + j) % SKELETON_WIDTHS.length] }
761
+ }
762
+ ))
763
+ );
620
764
  });
621
- sk.push(h("span", { key: "__gr", className: cx("aura-table__gutter aura-table__gutter--end", controls && "has-picker") }));
622
- body.push(h("div", { key: "sk" + i, className: "aura-table__row aura-table__row--skeleton", "aria-hidden": true, style: rowStyle }, sk));
765
+ sk.push(
766
+ /* @__PURE__ */ React.createElement("span", { key: "__gr", className: cx("aura-table__gutter aura-table__gutter--end", controls && "has-picker") })
767
+ );
768
+ skRows.push(
769
+ /* @__PURE__ */ React.createElement("div", { key: "sk" + i, className: "aura-table__row aura-table__row--skeleton", "aria-hidden": true, style: rowStyle }, sk)
770
+ );
623
771
  }
624
772
  } else if (!rows.length) {
625
- var em = props.empty || {};
626
- body = h(
627
- "div",
628
- { className: "aura-table__empty", role: "row" },
629
- h(
630
- "div",
631
- { role: "gridcell" },
632
- h("span", { className: "aura-table__empty-icon" }, h(Icon, { name: em.icon || "inbox", size: "lg" })),
633
- h("p", { className: "aura-table__empty-title" }, em.title || t.empty),
634
- em.description ? h("p", { className: "aura-table__empty-text" }, em.description) : null,
635
- em.action ? h("div", { className: "aura-table__empty-action" }, em.action) : null
636
- )
637
- );
773
+ const em = props.empty || {};
774
+ body = /* @__PURE__ */ React.createElement("div", { className: "aura-table__empty", role: "row" }, /* @__PURE__ */ React.createElement("div", { role: "gridcell" }, /* @__PURE__ */ React.createElement("span", { className: "aura-table__empty-icon" }, /* @__PURE__ */ React.createElement(Icon, { name: em.icon || "inbox", size: "lg" })), /* @__PURE__ */ React.createElement("p", { className: "aura-table__empty-title" }, em.title || t.empty), em.description ? /* @__PURE__ */ React.createElement("p", { className: "aura-table__empty-text" }, em.description) : null, em.action ? /* @__PURE__ */ React.createElement("div", { className: "aura-table__empty-action" }, em.action) : null));
638
775
  } else {
639
- body = [];
640
- if (virtual && start > 0) body.push(h("div", { key: "__top", style: { height: start * ROW_H + "px" }, "aria-hidden": true }));
641
- for (var ri = start; ri < end; ri++) {
642
- (function(r, i2) {
643
- var k = r[rowKey], isSel = !!selSet[k];
644
- body.push(h("div", {
645
- key: k,
646
- role: "row",
647
- "aria-rowindex": first + i2 + 2,
648
- "aria-selected": selectable ? isSel : void 0,
649
- className: cx("aura-table__row", isSel && "is-selected", props.onRowActivate && "is-actionable"),
650
- style: rowStyle,
651
- onClick: function(e) {
652
- if (e.target.closest && e.target.closest(".aura-check, button, a, input")) return;
653
- if (props.onRowActivate) props.onRowActivate(r);
654
- }
655
- }, rowCells(r, i2, k, isSel)));
776
+ const bodyRows = body = [];
777
+ if (virtual && start > 0)
778
+ bodyRows.push(/* @__PURE__ */ React.createElement("div", { key: "__top", style: { height: start * ROW_H + "px" }, "aria-hidden": true }));
779
+ for (let ri = start; ri < end; ri++) {
780
+ (function(r, i) {
781
+ const k = r[rowKey], isSel = !!selSet[k];
782
+ bodyRows.push(
783
+ /* @__PURE__ */ React.createElement(
784
+ "div",
785
+ {
786
+ key: k,
787
+ role: "row",
788
+ "aria-rowindex": first + i + 2,
789
+ "aria-selected": selectable ? isSel : void 0,
790
+ className: cx("aura-table__row", isSel && "is-selected", props.onRowActivate && "is-actionable"),
791
+ style: rowStyle,
792
+ onClick: function(e) {
793
+ const el = e.target;
794
+ if (el.closest && el.closest(".aura-check, button, a, input")) return;
795
+ if (props.onRowActivate) props.onRowActivate(r);
796
+ }
797
+ },
798
+ rowCells(r, i, k, isSel)
799
+ )
800
+ );
656
801
  })(pageRows[ri], ri);
657
802
  }
658
- if (virtual && end < pageRows.length) body.push(h("div", { key: "__bot", style: { height: (pageRows.length - end) * ROW_H + "px" }, "aria-hidden": true }));
803
+ if (virtual && end < pageRows.length)
804
+ bodyRows.push(/* @__PURE__ */ React.createElement("div", { key: "__bot", style: { height: (pageRows.length - end) * ROW_H + "px" }, "aria-hidden": true }));
659
805
  }
660
- var foot = null;
806
+ let foot = null;
661
807
  if (pageSize && (rows.length || loading)) {
662
- var from = rows.length ? first + 1 : 0, to = Math.min(first + pageSize, view.length);
663
- foot = h(
664
- "div",
665
- { className: "aura-table__foot" },
666
- h("span", { "aria-live": "polite" }, loading ? t.loading : t.range(from, to, view.length)),
667
- h(
668
- "span",
669
- { className: "aura-table__pager" },
670
- h("span", null, t.page(page, pageCount)),
671
- h(IconButton, { icon: "chevron-left", label: t.prevPage, disabled: loading || page <= 1, onClick: function() {
808
+ const from = rows.length ? first + 1 : 0, to = Math.min(first + pageSize, view.length);
809
+ foot = /* @__PURE__ */ React.createElement("div", { className: "aura-table__foot" }, /* @__PURE__ */ React.createElement("span", { "aria-live": "polite" }, loading ? t.loading : t.range(from, to, view.length)), /* @__PURE__ */ React.createElement("span", { className: "aura-table__pager" }, /* @__PURE__ */ React.createElement("span", null, t.page(page, pageCount)), /* @__PURE__ */ React.createElement(
810
+ IconButton,
811
+ {
812
+ icon: "chevron-left",
813
+ label: t.prevPage,
814
+ disabled: loading || page <= 1,
815
+ onClick: function() {
672
816
  goPage(page - 1);
673
- } }),
674
- h(IconButton, { icon: "chevron-right", label: t.nextPage, disabled: loading || page >= pageCount, onClick: function() {
817
+ }
818
+ }
819
+ ), /* @__PURE__ */ React.createElement(
820
+ IconButton,
821
+ {
822
+ icon: "chevron-right",
823
+ label: t.nextPage,
824
+ disabled: loading || page >= pageCount,
825
+ onClick: function() {
675
826
  goPage(page + 1);
676
- } })
677
- )
678
- );
827
+ }
828
+ }
829
+ )));
679
830
  } else if (height && rows.length && !loading) {
680
- foot = h(
681
- "div",
682
- { className: "aura-table__foot" },
683
- h("span", null, t.rowCount(view.length)),
684
- selectable && selected.length ? h("span", null, t.selectedCount(selected.length)) : h("span", null)
685
- );
831
+ foot = /* @__PURE__ */ React.createElement("div", { className: "aura-table__foot" }, /* @__PURE__ */ React.createElement("span", null, t.rowCount(view.length)), selectable && selected.length ? /* @__PURE__ */ React.createElement("span", null, t.selectedCount(selected.length)) : /* @__PURE__ */ React.createElement("span", null));
686
832
  }
687
833
  if (stacked) {
688
- var titleCol = vis[0], pillCol = vis.filter(function(c) {
834
+ const titleCol = vis[0], pillCol = vis.filter(function(c) {
689
835
  return c.pill && c !== titleCol;
690
836
  })[0];
691
- var actionCols = vis.filter(function(c) {
837
+ const actionCols = vis.filter(function(c) {
692
838
  return c.actions && c !== titleCol;
693
839
  });
694
- var rest = vis.filter(function(c) {
840
+ const rest = vis.filter(function(c) {
695
841
  return c !== titleCol && c !== pillCol && !c.actions;
696
842
  });
697
- var cardBody;
843
+ let cardBody;
698
844
  if (loading) {
699
- cardBody = h("ul", { className: "aura-table__cards", "aria-busy": true }, [0, 1, 2].map(function(i2) {
700
- return h(
701
- "li",
702
- { key: i2, className: "aura-table__card", "aria-hidden": true },
703
- h("span", { className: "aura-skel", style: { width: "50%", height: "14px" } }),
704
- h("span", { className: "aura-skel", style: { width: "80%" } }),
705
- h("span", { className: "aura-skel", style: { width: "64%" } })
706
- );
845
+ cardBody = /* @__PURE__ */ React.createElement("ul", { className: "aura-table__cards", "aria-busy": true }, [0, 1, 2].map(function(i) {
846
+ return /* @__PURE__ */ React.createElement("li", { key: i, className: "aura-table__card", "aria-hidden": true }, /* @__PURE__ */ React.createElement("span", { className: "aura-skel", style: { width: "50%", height: "14px" } }), /* @__PURE__ */ React.createElement("span", { className: "aura-skel", style: { width: "80%" } }), /* @__PURE__ */ React.createElement("span", { className: "aura-skel", style: { width: "64%" } }));
707
847
  }));
708
848
  } else if (!rows.length) {
709
- var em2 = props.empty || {};
710
- cardBody = h("div", { className: "aura-table__empty" }, h(
711
- "div",
712
- null,
713
- h("span", { className: "aura-table__empty-icon" }, h(Icon, { name: em2.icon || "inbox", size: "lg" })),
714
- h("p", { className: "aura-table__empty-title" }, em2.title || t.empty),
715
- em2.description ? h("p", { className: "aura-table__empty-text" }, em2.description) : null,
716
- em2.action ? h("div", { className: "aura-table__empty-action" }, em2.action) : null
717
- ));
849
+ const em2 = props.empty || {};
850
+ cardBody = /* @__PURE__ */ React.createElement("div", { className: "aura-table__empty" }, /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement("span", { className: "aura-table__empty-icon" }, /* @__PURE__ */ React.createElement(Icon, { name: em2.icon || "inbox", size: "lg" })), /* @__PURE__ */ React.createElement("p", { className: "aura-table__empty-title" }, em2.title || t.empty), em2.description ? /* @__PURE__ */ React.createElement("p", { className: "aura-table__empty-text" }, em2.description) : null, em2.action ? /* @__PURE__ */ React.createElement("div", { className: "aura-table__empty-action" }, em2.action) : null));
718
851
  } else {
719
- var cellVal = function(c, r) {
720
- var v = r[c.key];
721
- return c.render ? c.render(r) : c.pill ? h(StatusPill, { tone: c.tones && c.tones[v] }, v) : v;
852
+ const cellVal = function(c, r) {
853
+ const v = r[c.key];
854
+ return c.render ? c.render(r) : c.pill ? /* @__PURE__ */ React.createElement(StatusPill, { ...{ tone: c.tones && c.tones[v] } }, v) : v;
722
855
  };
723
- cardBody = h("ul", { className: "aura-table__cards", "aria-label": props.label }, pageRows.map(function(r) {
724
- var k = r[rowKey], isSel = !!selSet[k];
725
- return h(
856
+ cardBody = /* @__PURE__ */ React.createElement("ul", { className: "aura-table__cards", "aria-label": props.label }, pageRows.map(function(r) {
857
+ const k = r[rowKey], isSel = !!selSet[k];
858
+ return /* @__PURE__ */ React.createElement(
726
859
  "li",
727
860
  {
728
861
  key: k,
729
862
  className: cx("aura-table__card", isSel && "is-selected", props.onRowActivate && "is-actionable"),
730
863
  tabIndex: props.onRowActivate ? 0 : void 0,
731
864
  onClick: function(e) {
732
- if (e.target.closest && e.target.closest(".aura-check, button, a, input")) return;
865
+ const el = e.target;
866
+ if (el.closest && el.closest(".aura-check, button, a, input")) return;
733
867
  if (props.onRowActivate) props.onRowActivate(r);
734
868
  },
735
869
  onKeyDown: function(e) {
736
870
  if (e.target === e.currentTarget && e.key === "Enter" && props.onRowActivate) props.onRowActivate(r);
737
871
  }
738
872
  },
739
- h(
740
- "div",
741
- { className: "aura-table__card-head" },
742
- selectable ? h(Checkbox, { checked: isSel, label: t.selectRow(k), onChange: function(on) {
743
- toggle(k, on);
744
- } }) : null,
745
- h("span", { className: cx("aura-table__card-title", titleCol.mono && "aura-table__mono") }, cellVal(titleCol, r)),
746
- pillCol ? cellVal(pillCol, r) : null,
747
- actionCols.map(function(c) {
748
- return h("span", { key: c.key, className: "aura-table__card-actions" }, cellVal(c, r));
749
- })
750
- ),
751
- rest.length ? h("dl", { className: "aura-table__card-fields" }, rest.map(function(c) {
752
- return h("div", { key: c.key }, h("dt", null, c.label), h("dd", { className: c.mono ? "aura-table__mono" : void 0 }, cellVal(c, r)));
873
+ /* @__PURE__ */ React.createElement("div", { className: "aura-table__card-head" }, selectable ? /* @__PURE__ */ React.createElement(
874
+ Checkbox,
875
+ {
876
+ checked: isSel,
877
+ label: t.selectRow(k),
878
+ onChange: function(on) {
879
+ toggle(k, on);
880
+ }
881
+ }
882
+ ) : null, /* @__PURE__ */ React.createElement("span", { className: cx("aura-table__card-title", titleCol.mono && "aura-table__mono") }, cellVal(titleCol, r)), pillCol ? cellVal(pillCol, r) : null, actionCols.map(function(c) {
883
+ return /* @__PURE__ */ React.createElement("span", { key: c.key, className: "aura-table__card-actions" }, cellVal(c, r));
884
+ })),
885
+ rest.length ? /* @__PURE__ */ React.createElement("dl", { className: "aura-table__card-fields" }, rest.map(function(c) {
886
+ return /* @__PURE__ */ React.createElement("div", { key: c.key }, /* @__PURE__ */ React.createElement("dt", null, c.label), /* @__PURE__ */ React.createElement("dd", { className: c.mono ? "aura-table__mono" : void 0 }, cellVal(c, r)));
753
887
  })) : null
754
888
  );
755
889
  }));
756
890
  }
757
- return h(
891
+ return /* @__PURE__ */ React.createElement(
758
892
  "div",
759
- { ref: wrapMerged, className: cx("aura-table aura-table--stacked", props.className), role: "region", "aria-label": props.label, "aria-busy": loading || void 0 },
760
- selectable && pageRows.length && !loading ? h(
761
- "div",
762
- { className: "aura-table__stack-bar" },
763
- h(Checkbox, { checked: all, indeterminate: nSel > 0 && !all, label: all ? t.deselectAllRows : t.selectAllRows, onChange: toggleAll }),
764
- h("span", null, nSel ? t.selectedCount(nSel) : t.selectAll)
765
- ) : null,
893
+ {
894
+ ref: wrapMerged,
895
+ className: cx("aura-table aura-table--stacked", props.className),
896
+ role: "region",
897
+ "aria-label": props.label,
898
+ "aria-busy": loading || void 0
899
+ },
900
+ selectable && pageRows.length && !loading ? /* @__PURE__ */ React.createElement("div", { className: "aura-table__stack-bar" }, /* @__PURE__ */ React.createElement(
901
+ Checkbox,
902
+ {
903
+ checked: all,
904
+ indeterminate: nSel > 0 && !all,
905
+ label: all ? t.deselectAllRows : t.selectAllRows,
906
+ onChange: toggleAll
907
+ }
908
+ ), /* @__PURE__ */ React.createElement("span", null, nSel ? t.selectedCount(nSel) : t.selectAll)) : null,
766
909
  cardBody,
767
910
  foot
768
911
  );
769
912
  }
770
- var scrollStyle = { scrollPaddingLeft: "calc(var(--aura-space-6)" + selW + " + " + acc + "px)", scrollPaddingTop: ROW_H + "px" };
913
+ const scrollStyle = {
914
+ scrollPaddingLeft: "calc(var(--aura-space-6)" + selW + " + " + acc + "px)",
915
+ scrollPaddingTop: ROW_H + "px"
916
+ };
771
917
  if (height) scrollStyle.height = height + "px";
772
- return h(
918
+ return /* @__PURE__ */ React.createElement("div", { ref: wrapMerged, className: cx("aura-table", scrolledX[0] && "is-scrolled-x", props.className) }, /* @__PURE__ */ React.createElement(
773
919
  "div",
774
- { ref: wrapMerged, className: cx("aura-table", scrolledX[0] && "is-scrolled-x", props.className) },
775
- h(
776
- "div",
777
- {
778
- ref: function(el) {
779
- scrollRef.current = el;
780
- gridRef.current = el;
781
- },
782
- className: "aura-table__scroll",
783
- style: scrollStyle,
784
- role: "grid",
785
- "aria-label": props.label,
786
- "aria-busy": loading || void 0,
787
- "aria-rowcount": loading ? -1 : view.length + 1,
788
- "aria-colcount": nCols,
789
- "aria-multiselectable": selectable || void 0,
790
- onKeyDown: onGridKey,
791
- onScroll: function(e) {
792
- var t2 = e.currentTarget;
793
- if (virtual && Math.abs(t2.scrollTop - scrollTop) >= ROW_H / 2) setScrollTop(t2.scrollTop);
794
- else if (virtual && (t2.scrollTop === 0 || t2.scrollTop + t2.clientHeight >= t2.scrollHeight - 1)) setScrollTop(t2.scrollTop);
795
- var sx = t2.scrollLeft > 0;
796
- if (sx !== scrolledX[0]) scrolledX[1](sx);
797
- }
920
+ {
921
+ ref: function(el) {
922
+ scrollRef.current = el;
923
+ gridRef.current = el;
798
924
  },
799
- h("div", { className: "aura-table__head", role: "row", "aria-rowindex": 1, style: rowStyle }, head),
800
- body
801
- ),
802
- loading ? h("span", { className: "aura-sr-only", role: "status" }, t.loadingRows) : null,
803
- controls ? h(
804
- "div",
805
- { className: "aura-table__picker" },
806
- h(IconButton, {
807
- icon: "columns-3",
808
- label: t.showHideColumns,
809
- "aria-haspopup": "menu",
810
- onClick: function(e) {
811
- openMenu("picker", null, e.currentTarget);
812
- }
813
- })
814
- ) : null,
815
- foot,
816
- menu ? h(Menu, {
925
+ className: "aura-table__scroll",
926
+ style: scrollStyle,
927
+ role: "grid",
928
+ "aria-label": props.label,
929
+ "aria-busy": loading || void 0,
930
+ "aria-rowcount": loading ? -1 : view.length + 1,
931
+ "aria-colcount": nCols,
932
+ "aria-multiselectable": selectable || void 0,
933
+ onKeyDown: onGridKey,
934
+ onScroll: function(e) {
935
+ const t2 = e.currentTarget;
936
+ if (virtual && Math.abs(t2.scrollTop - scrollTop) >= ROW_H / 2) setScrollTop(t2.scrollTop);
937
+ else if (virtual && (t2.scrollTop === 0 || t2.scrollTop + t2.clientHeight >= t2.scrollHeight - 1))
938
+ setScrollTop(t2.scrollTop);
939
+ const sx = t2.scrollLeft > 0;
940
+ if (sx !== scrolledX[0]) scrolledX[1](sx);
941
+ }
942
+ },
943
+ /* @__PURE__ */ React.createElement("div", { className: "aura-table__head", role: "row", "aria-rowindex": 1, style: rowStyle }, head),
944
+ body
945
+ ), loading ? /* @__PURE__ */ React.createElement("span", { className: "aura-sr-only", role: "status" }, t.loadingRows) : null, controls ? /* @__PURE__ */ React.createElement("div", { className: "aura-table__picker" }, /* @__PURE__ */ React.createElement(
946
+ IconButton,
947
+ {
948
+ icon: "columns-3",
949
+ label: t.showHideColumns,
950
+ "aria-haspopup": "menu",
951
+ onClick: function(e) {
952
+ openMenu("picker", null, e.currentTarget);
953
+ }
954
+ }
955
+ )) : null, foot, menu ? /* @__PURE__ */ React.createElement(
956
+ Menu,
957
+ {
817
958
  anchor: menu.anchor,
818
959
  onClose: closeMenu,
819
960
  label: menu.kind === "picker" ? t.columns : t.column(byKey[menu.key] && byKey[menu.key].label),
820
961
  items: menu.kind === "picker" ? pickerItems() : byKey[menu.key] ? columnMenuItems(byKey[menu.key]) : []
821
- }) : null
822
- );
962
+ }
963
+ ) : null);
823
964
  });
824
965
  export {
825
966
  DataTable