@jirawatpyk/aura-react 4.5.0 → 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.
@@ -7,98 +7,114 @@ 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,39 +237,45 @@ 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
281
  return !!props.resizable && c.resizable !== false && c.width != null;
@@ -257,9 +284,9 @@ const DataTable = React.forwardRef(function DataTable2(props, ref) {
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,24 +467,26 @@ const DataTable = React.forwardRef(function DataTable2(props, ref) {
391
467
  }
392
468
  }
393
469
  function onGridKey(e) {
394
- var target = e.target;
470
+ const target = e.target;
395
471
  if (!gridRef.current || !gridRef.current.contains(target)) return;
396
- var rc = target.getAttribute && target.getAttribute("data-rc");
472
+ const rc = target.getAttribute && target.getAttribute("data-rc");
397
473
  if (!rc) {
398
- var cell = e.key === "Escape" && target.closest && target.closest("[data-rc]");
474
+ const cell = e.key === "Escape" && target.closest && target.closest("[data-rc]");
399
475
  if (cell) {
400
476
  e.preventDefault();
401
477
  cell.focus();
402
478
  }
403
479
  return;
404
480
  }
405
- var p = rc.split(":"), r = +p[0], c = +p[1], k = e.key, col = colAt(c);
406
- var row = r > 0 ? pageRows[r - 1] : null;
407
- var handled = true;
408
- 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);
409
486
  else if (r === 0 && col && e.ctrlKey && e.shiftKey && (k === "ArrowLeft" || k === "ArrowRight") && reorderable) {
410
487
  if (moveCol(col.key, k === "ArrowLeft" ? -1 : 1)) pending.current = { r: 0, key: col.key, c };
411
- } else if (r === 0 && col && (e.altKey && k === "ArrowDown" || k === "ContextMenu" || e.shiftKey && k === "F10") && controls) openMenu("col", col.key, 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 });
412
490
  else if (k === "ArrowRight") focusCell(r, c + 1);
413
491
  else if (k === "ArrowLeft") focusCell(r, c - 1);
414
492
  else if (k === "ArrowDown") {
@@ -428,7 +506,7 @@ const DataTable = React.forwardRef(function DataTable2(props, ref) {
428
506
  if (goPage(page - 1, { r: 1, c })) activeState[1]({ r: 1, c });
429
507
  } else focusCell(Math.max(1, r - visibleRows), c);
430
508
  } else if (k === "F2" && r > 0) {
431
- var inner = target.querySelector("button, a[href], input, select, textarea");
509
+ const inner = target.querySelector("button, a[href], input, select, textarea");
432
510
  if (inner) inner.focus();
433
511
  else handled = false;
434
512
  } else if (k === " " || k === "Enter") {
@@ -437,7 +515,8 @@ const DataTable = React.forwardRef(function DataTable2(props, ref) {
437
515
  setSort(nextSort(col.key));
438
516
  goPage(1);
439
517
  } else if (r > 0 && k === " " && selectable) toggle(row[rowKey], !selSet[row[rowKey]]);
440
- else if (r > 0 && k === "Enter" && target.querySelector("button, a[href], input, select, textarea")) 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();
441
520
  else if (r > 0 && k === "Enter" && props.onRowActivate) props.onRowActivate(row);
442
521
  else handled = false;
443
522
  } else handled = false;
@@ -446,83 +525,91 @@ const DataTable = React.forwardRef(function DataTable2(props, ref) {
446
525
  e.stopPropagation();
447
526
  }
448
527
  }
449
- var head = [h("span", { key: "__gl", className: "aura-table__gutter", "aria-hidden": true })];
450
- if (selectable) head.push(h("span", {
451
- key: "__sel",
452
- role: "columnheader",
453
- "aria-colindex": 1,
454
- className: cx("aura-table__sel", nPinned && "is-pinned"),
455
- tabIndex: tabFor(0, 0),
456
- "data-rc": "0:0",
457
- "aria-label": t.selectRows,
458
- onFocus: function() {
459
- activeState[1]({ r: 0, c: 0 });
460
- }
461
- }, nRows ? h(Checkbox, {
462
- checked: all,
463
- indeterminate: nSel > 0 && !all,
464
- tabIndex: -1,
465
- label: all ? t.deselectAllRows : t.selectAllRows,
466
- onChange: toggleAll
467
- }) : null));
468
- vis.forEach(function(c, i2) {
469
- var ci = i2 + (selectable ? 1 : 0);
470
- var isSorted = sort && sort.key === c.key;
471
- var canSort = c.sortable && rows.length > 1 && !loading;
472
- var ariaSort = isSorted && canSort ? sort.dir === "desc" ? "descending" : "ascending" : canSort ? "none" : void 0;
473
- var pin = isPinned(c), edge = pin && i2 === nPinned - 1;
474
- head.push(h(
475
- "span",
476
- {
477
- key: c.key,
478
- role: "columnheader",
479
- "aria-sort": ariaSort,
480
- "aria-colindex": ci + 1,
481
- style: cellStyle(c, i2),
482
- tabIndex: tabFor(0, ci),
483
- "data-rc": "0:" + ci,
484
- className: cx(
485
- "aura-table__th",
486
- pin && "is-pinned",
487
- edge && "is-pin-edge",
488
- drag && drag.over === c.key && (drag.after ? "is-drop-after" : "is-drop-before"),
489
- drag && drag.key === c.key && "is-dragging"
490
- ),
491
- draggable: reorderable && !loading ? true : void 0,
492
- onFocus: function(e) {
493
- 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
+ }
494
544
  },
495
- onDragStart: function(e) {
496
- if (resizing.current) {
497
- e.preventDefault();
498
- 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
499
553
  }
500
- e.dataTransfer.effectAllowed = "move";
501
- try {
502
- e.dataTransfer.setData("text/plain", c.key);
503
- } 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);
504
610
  }
505
- setDrag({ key: c.key });
506
611
  },
507
- onDragOver: function(e) {
508
- if (!drag || drag.key === c.key || isPinned(byKey[drag.key]) !== pin) return;
509
- e.preventDefault();
510
- var b = e.currentTarget.getBoundingClientRect(), after = e.clientX > b.left + b.width / 2;
511
- if (drag.over !== c.key || drag.after !== after) setDrag({ key: drag.key, over: c.key, after });
512
- },
513
- onDrop: function(e) {
514
- e.preventDefault();
515
- if (drag && drag.over) dropCol(drag.key, drag.over, drag.after);
516
- setDrag(null);
517
- },
518
- onDragEnd: function() {
519
- setDrag(null);
520
- }
521
- },
522
- h(
523
- "span",
524
- { className: "aura-table__th-inner" },
525
- canSort ? h(
612
+ /* @__PURE__ */ React.createElement("span", { className: "aura-table__th-inner" }, canSort ? /* @__PURE__ */ React.createElement(
526
613
  "button",
527
614
  {
528
615
  type: "button",
@@ -535,10 +622,8 @@ const DataTable = React.forwardRef(function DataTable2(props, ref) {
535
622
  }
536
623
  },
537
624
  c.label,
538
- h(Icon, { name: isSorted ? sort.dir === "desc" ? "arrow-down" : "arrow-up" : "arrow-up-down", size: 12 })
539
- ) : h("span", { className: cx("aura-table__th-label", !c.label && "aura-sr-only") }, c.label || (c.actions ? t.actions : c.key)),
540
- pin ? h(Icon, { name: "pin", size: 12, className: "aura-table__pin-icon", label: t.pinned }) : null,
541
- 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(
542
627
  "button",
543
628
  {
544
629
  type: "button",
@@ -552,190 +637,232 @@ const DataTable = React.forwardRef(function DataTable2(props, ref) {
552
637
  openMenu("col", c.key, e.currentTarget, { r: 0, c: ci });
553
638
  }
554
639
  },
555
- 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
+ }
556
659
  ) : null
557
- ),
558
- canResize(c) ? h("span", {
559
- className: "aura-table__resize",
560
- role: "separator",
561
- "aria-orientation": "vertical",
562
- "aria-hidden": true,
563
- onPointerDown: function(e) {
564
- startResize(c, e);
565
- },
566
- onClick: function(e) {
567
- e.stopPropagation();
568
- },
569
- onDoubleClick: function() {
570
- setW(c, c.width, true);
571
- }
572
- }) : null
573
- ));
660
+ )
661
+ );
574
662
  });
575
- head.push(h("span", { key: "__gr", className: cx("aura-table__gutter aura-table__gutter--end", controls && "has-picker"), "aria-hidden": true }));
576
- function rowCells(r, i2, k, isSel) {
577
- var ri2 = i2 + 1;
578
- var cells = [h("span", { key: "__gl", className: "aura-table__gutter", "aria-hidden": true })];
579
- if (selectable) cells.push(h("span", {
580
- key: "__sel",
581
- role: "gridcell",
582
- "aria-colindex": 1,
583
- className: cx("aura-table__sel", nPinned && "is-pinned"),
584
- tabIndex: tabFor(ri2, 0),
585
- "data-rc": ri2 + ":0",
586
- "aria-label": t.selectRow(k),
587
- onFocus: function(e) {
588
- 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
589
670
  }
590
- }, h(Checkbox, { checked: isSel, tabIndex: -1, label: t.selectRow(k), onChange: function(on) {
591
- toggle(k, on);
592
- } })));
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
+ );
593
705
  vis.forEach(function(c, j) {
594
- var ci = j + (selectable ? 1 : 0), v = r[c.key], pin = isPinned(c);
595
- cells.push(h("span", {
596
- key: c.key,
597
- role: "gridcell",
598
- "aria-colindex": ci + 1,
599
- tabIndex: tabFor(ri2, ci),
600
- "data-rc": ri2 + ":" + ci,
601
- className: cx("aura-table__td", c.mono && "aura-table__mono", pin && "is-pinned", pin && j === nPinned - 1 && "is-pin-edge"),
602
- style: cellStyle(c, j),
603
- onFocus: function() {
604
- if (activeState[0].r !== ri2 || activeState[0].c !== ci) activeState[1]({ r: ri2, c: ci });
605
- }
606
- }, 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
+ );
607
730
  });
608
- 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
+ );
609
741
  return cells;
610
742
  }
611
- var body;
612
- var rowStyle = { minWidth: rowMinWidth };
743
+ let body;
744
+ const rowStyle = { minWidth: rowMinWidth };
613
745
  if (loading) {
614
- var n = pageSize || props.skeletonRows || 5;
615
- var skRows = body = [];
616
- for (var i = 0; i < n; i++) {
617
- var sk = [h("span", { key: "__gl", className: "aura-table__gutter" })];
618
- 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
+ );
619
754
  vis.forEach(function(c, j) {
620
- sk.push(h(
621
- "span",
622
- { key: c.key, className: cx("aura-table__td", isPinned(c) && "is-pinned"), style: cellStyle(c, j) },
623
- h("span", { className: cx("aura-skel", c.pill && "aura-skel--pill"), style: c.pill ? null : { width: SKELETON_WIDTHS[(i + j) % SKELETON_WIDTHS.length] } })
624
- ));
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
+ );
625
764
  });
626
- sk.push(h("span", { key: "__gr", className: cx("aura-table__gutter aura-table__gutter--end", controls && "has-picker") }));
627
- skRows.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
+ );
628
771
  }
629
772
  } else if (!rows.length) {
630
- var em = props.empty || {};
631
- body = h(
632
- "div",
633
- { className: "aura-table__empty", role: "row" },
634
- h(
635
- "div",
636
- { role: "gridcell" },
637
- h("span", { className: "aura-table__empty-icon" }, h(Icon, { name: em.icon || "inbox", size: "lg" })),
638
- h("p", { className: "aura-table__empty-title" }, em.title || t.empty),
639
- em.description ? h("p", { className: "aura-table__empty-text" }, em.description) : null,
640
- em.action ? h("div", { className: "aura-table__empty-action" }, em.action) : null
641
- )
642
- );
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));
643
775
  } else {
644
- var bodyRows = body = [];
645
- if (virtual && start > 0) bodyRows.push(h("div", { key: "__top", style: { height: start * ROW_H + "px" }, "aria-hidden": true }));
646
- for (var ri = start; ri < end; ri++) {
647
- (function(r, i2) {
648
- var k = r[rowKey], isSel = !!selSet[k];
649
- bodyRows.push(h("div", {
650
- key: k,
651
- role: "row",
652
- "aria-rowindex": first + i2 + 2,
653
- "aria-selected": selectable ? isSel : void 0,
654
- className: cx("aura-table__row", isSel && "is-selected", props.onRowActivate && "is-actionable"),
655
- style: rowStyle,
656
- onClick: function(e) {
657
- var el = e.target;
658
- if (el.closest && el.closest(".aura-check, button, a, input")) return;
659
- if (props.onRowActivate) props.onRowActivate(r);
660
- }
661
- }, 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
+ );
662
801
  })(pageRows[ri], ri);
663
802
  }
664
- if (virtual && end < pageRows.length) bodyRows.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 }));
665
805
  }
666
- var foot = null;
806
+ let foot = null;
667
807
  if (pageSize && (rows.length || loading)) {
668
- var from = rows.length ? first + 1 : 0, to = Math.min(first + pageSize, view.length);
669
- foot = h(
670
- "div",
671
- { className: "aura-table__foot" },
672
- h("span", { "aria-live": "polite" }, loading ? t.loading : t.range(from, to, view.length)),
673
- h(
674
- "span",
675
- { className: "aura-table__pager" },
676
- h("span", null, t.page(page, pageCount)),
677
- 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() {
678
816
  goPage(page - 1);
679
- } }),
680
- 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() {
681
826
  goPage(page + 1);
682
- } })
683
- )
684
- );
827
+ }
828
+ }
829
+ )));
685
830
  } else if (height && rows.length && !loading) {
686
- foot = h(
687
- "div",
688
- { className: "aura-table__foot" },
689
- h("span", null, t.rowCount(view.length)),
690
- selectable && selected.length ? h("span", null, t.selectedCount(selected.length)) : h("span", null)
691
- );
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));
692
832
  }
693
833
  if (stacked) {
694
- var titleCol = vis[0], pillCol = vis.filter(function(c) {
834
+ const titleCol = vis[0], pillCol = vis.filter(function(c) {
695
835
  return c.pill && c !== titleCol;
696
836
  })[0];
697
- var actionCols = vis.filter(function(c) {
837
+ const actionCols = vis.filter(function(c) {
698
838
  return c.actions && c !== titleCol;
699
839
  });
700
- var rest = vis.filter(function(c) {
840
+ const rest = vis.filter(function(c) {
701
841
  return c !== titleCol && c !== pillCol && !c.actions;
702
842
  });
703
- var cardBody;
843
+ let cardBody;
704
844
  if (loading) {
705
- cardBody = h("ul", { className: "aura-table__cards", "aria-busy": true }, [0, 1, 2].map(function(i2) {
706
- return h(
707
- "li",
708
- { key: i2, className: "aura-table__card", "aria-hidden": true },
709
- h("span", { className: "aura-skel", style: { width: "50%", height: "14px" } }),
710
- h("span", { className: "aura-skel", style: { width: "80%" } }),
711
- h("span", { className: "aura-skel", style: { width: "64%" } })
712
- );
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%" } }));
713
847
  }));
714
848
  } else if (!rows.length) {
715
- var em2 = props.empty || {};
716
- cardBody = h("div", { className: "aura-table__empty" }, h(
717
- "div",
718
- null,
719
- h("span", { className: "aura-table__empty-icon" }, h(Icon, { name: em2.icon || "inbox", size: "lg" })),
720
- h("p", { className: "aura-table__empty-title" }, em2.title || t.empty),
721
- em2.description ? h("p", { className: "aura-table__empty-text" }, em2.description) : null,
722
- em2.action ? h("div", { className: "aura-table__empty-action" }, em2.action) : null
723
- ));
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));
724
851
  } else {
725
- var cellVal = function(c, r) {
726
- var v = r[c.key];
727
- 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;
728
855
  };
729
- cardBody = h("ul", { className: "aura-table__cards", "aria-label": props.label }, pageRows.map(function(r) {
730
- var k = r[rowKey], isSel = !!selSet[k];
731
- 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(
732
859
  "li",
733
860
  {
734
861
  key: k,
735
862
  className: cx("aura-table__card", isSel && "is-selected", props.onRowActivate && "is-actionable"),
736
863
  tabIndex: props.onRowActivate ? 0 : void 0,
737
864
  onClick: function(e) {
738
- var el = e.target;
865
+ const el = e.target;
739
866
  if (el.closest && el.closest(".aura-check, button, a, input")) return;
740
867
  if (props.onRowActivate) props.onRowActivate(r);
741
868
  },
@@ -743,90 +870,97 @@ const DataTable = React.forwardRef(function DataTable2(props, ref) {
743
870
  if (e.target === e.currentTarget && e.key === "Enter" && props.onRowActivate) props.onRowActivate(r);
744
871
  }
745
872
  },
746
- h(
747
- "div",
748
- { className: "aura-table__card-head" },
749
- selectable ? h(Checkbox, { checked: isSel, label: t.selectRow(k), onChange: function(on) {
750
- toggle(k, on);
751
- } }) : null,
752
- h("span", { className: cx("aura-table__card-title", titleCol.mono && "aura-table__mono") }, cellVal(titleCol, r)),
753
- pillCol ? cellVal(pillCol, r) : null,
754
- actionCols.map(function(c) {
755
- return h("span", { key: c.key, className: "aura-table__card-actions" }, cellVal(c, r));
756
- })
757
- ),
758
- rest.length ? h("dl", { className: "aura-table__card-fields" }, rest.map(function(c) {
759
- 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)));
760
887
  })) : null
761
888
  );
762
889
  }));
763
890
  }
764
- return h(
891
+ return /* @__PURE__ */ React.createElement(
765
892
  "div",
766
- { ref: wrapMerged, className: cx("aura-table aura-table--stacked", props.className), role: "region", "aria-label": props.label, "aria-busy": loading || void 0 },
767
- selectable && pageRows.length && !loading ? h(
768
- "div",
769
- { className: "aura-table__stack-bar" },
770
- h(Checkbox, { checked: all, indeterminate: nSel > 0 && !all, label: all ? t.deselectAllRows : t.selectAllRows, onChange: toggleAll }),
771
- h("span", null, nSel ? t.selectedCount(nSel) : t.selectAll)
772
- ) : 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,
773
909
  cardBody,
774
910
  foot
775
911
  );
776
912
  }
777
- 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
+ };
778
917
  if (height) scrollStyle.height = height + "px";
779
- return h(
918
+ return /* @__PURE__ */ React.createElement("div", { ref: wrapMerged, className: cx("aura-table", scrolledX[0] && "is-scrolled-x", props.className) }, /* @__PURE__ */ React.createElement(
780
919
  "div",
781
- { ref: wrapMerged, className: cx("aura-table", scrolledX[0] && "is-scrolled-x", props.className) },
782
- h(
783
- "div",
784
- {
785
- ref: function(el) {
786
- scrollRef.current = el;
787
- gridRef.current = el;
788
- },
789
- className: "aura-table__scroll",
790
- style: scrollStyle,
791
- role: "grid",
792
- "aria-label": props.label,
793
- "aria-busy": loading || void 0,
794
- "aria-rowcount": loading ? -1 : view.length + 1,
795
- "aria-colcount": nCols,
796
- "aria-multiselectable": selectable || void 0,
797
- onKeyDown: onGridKey,
798
- onScroll: function(e) {
799
- var t2 = e.currentTarget;
800
- if (virtual && Math.abs(t2.scrollTop - scrollTop) >= ROW_H / 2) setScrollTop(t2.scrollTop);
801
- else if (virtual && (t2.scrollTop === 0 || t2.scrollTop + t2.clientHeight >= t2.scrollHeight - 1)) setScrollTop(t2.scrollTop);
802
- var sx = t2.scrollLeft > 0;
803
- if (sx !== scrolledX[0]) scrolledX[1](sx);
804
- }
920
+ {
921
+ ref: function(el) {
922
+ scrollRef.current = el;
923
+ gridRef.current = el;
805
924
  },
806
- h("div", { className: "aura-table__head", role: "row", "aria-rowindex": 1, style: rowStyle }, head),
807
- body
808
- ),
809
- loading ? h("span", { className: "aura-sr-only", role: "status" }, t.loadingRows) : null,
810
- controls ? h(
811
- "div",
812
- { className: "aura-table__picker" },
813
- h(IconButton, {
814
- icon: "columns-3",
815
- label: t.showHideColumns,
816
- "aria-haspopup": "menu",
817
- onClick: function(e) {
818
- openMenu("picker", null, e.currentTarget);
819
- }
820
- })
821
- ) : null,
822
- foot,
823
- 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
+ {
824
958
  anchor: menu.anchor,
825
959
  onClose: closeMenu,
826
960
  label: menu.kind === "picker" ? t.columns : t.column(byKey[menu.key] && byKey[menu.key].label),
827
961
  items: menu.kind === "picker" ? pickerItems() : byKey[menu.key] ? columnMenuItems(byKey[menu.key]) : []
828
- }) : null
829
- );
962
+ }
963
+ ) : null);
830
964
  });
831
965
  export {
832
966
  DataTable