tabler-react-2 0.1.158-alpha.0 → 0.1.158-alpha.2
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.
- package/dist/table-v2/index.js +40 -103
- package/package.json +1 -1
package/dist/table-v2/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
@@ -11,16 +10,15 @@ var _reactTable = require("@tanstack/react-table");
|
|
|
11
10
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
12
11
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
13
12
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
|
14
|
-
function
|
|
15
|
-
function
|
|
16
|
-
function
|
|
17
|
-
function
|
|
18
|
-
function
|
|
19
|
-
function
|
|
13
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
14
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
15
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
16
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
17
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
18
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } // TableV2.jsx
|
|
20
19
|
// TanStack Table v8 styled like the Original component's Tabler look.
|
|
21
|
-
// Adds `dense` mode
|
|
22
|
-
//
|
|
23
|
-
// ES modules, named exports, arrow functions only.
|
|
20
|
+
// Adds `dense` mode for a compact layout.
|
|
21
|
+
// Controlled (server-side) pagination & sorting. ES modules, named exports, arrow functions only.
|
|
24
22
|
/** Small utilities */
|
|
25
23
|
|
|
26
24
|
var SortIcon = exports.SortIcon = function SortIcon(_ref) {
|
|
@@ -113,13 +111,12 @@ var isEmptyRender = function isEmptyRender(node) {
|
|
|
113
111
|
};
|
|
114
112
|
var renderCellWithFallback = function renderCellWithFallback(cell) {
|
|
115
113
|
var _cell$getValue;
|
|
116
|
-
var fallbackText = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "—";
|
|
117
114
|
var rendered = (0, _reactTable.flexRender)(cell.column.columnDef.cell, cell.getContext());
|
|
118
115
|
var finalNode = isEmptyRender(rendered) ? (_cell$getValue = cell.getValue) === null || _cell$getValue === void 0 ? void 0 : _cell$getValue.call(cell) : rendered;
|
|
119
116
|
if (finalNode === null || finalNode === undefined || typeof finalNode === "string" && finalNode.trim() === "") {
|
|
120
117
|
return /*#__PURE__*/_react["default"].createElement("span", {
|
|
121
118
|
className: "text-muted"
|
|
122
|
-
},
|
|
119
|
+
}, "\u2014");
|
|
123
120
|
}
|
|
124
121
|
return finalNode;
|
|
125
122
|
};
|
|
@@ -162,82 +159,38 @@ var TableV2 = exports.TableV2 = function TableV2(_ref5) {
|
|
|
162
159
|
_ref5$pageSizeOptions = _ref5.pageSizeOptions,
|
|
163
160
|
pageSizeOptions = _ref5$pageSizeOptions === void 0 ? [10, 25, 50, 100] : _ref5$pageSizeOptions,
|
|
164
161
|
_ref5$fallbackText = _ref5.fallbackText,
|
|
165
|
-
fallbackText = _ref5$fallbackText === void 0 ? "—" : _ref5$fallbackText
|
|
166
|
-
_ref5$enableRowSelect = _ref5.enableRowSelection,
|
|
167
|
-
enableRowSelection = _ref5$enableRowSelect === void 0 ? true : _ref5$enableRowSelect,
|
|
168
|
-
_ref5$enableMultiRowS = _ref5.enableMultiRowSelection,
|
|
169
|
-
enableMultiRowSelection = _ref5$enableMultiRowS === void 0 ? true : _ref5$enableMultiRowS,
|
|
170
|
-
_ref5$showSelectionCo = _ref5.showSelectionColumn,
|
|
171
|
-
showSelectionColumn = _ref5$showSelectionCo === void 0 ? false : _ref5$showSelectionCo,
|
|
172
|
-
_ref5$rowClickToSelec = _ref5.rowClickToSelect,
|
|
173
|
-
rowClickToSelect = _ref5$rowClickToSelec === void 0 ? false : _ref5$rowClickToSelec;
|
|
174
|
-
// Build columns with optional selection checkbox column
|
|
175
|
-
var materializedColumns = (0, _react.useMemo)(function () {
|
|
176
|
-
if (!showSelectionColumn) return columns;
|
|
177
|
-
var selectCol = {
|
|
178
|
-
id: "_select",
|
|
179
|
-
header: function header(_ref6) {
|
|
180
|
-
var _table$getIsAllPageRo, _table$getIsAllPageRo2, _table$getIsSomePageR, _table$getIsSomePageR2, _table$getToggleAllPa, _table$getToggleAllPa2;
|
|
181
|
-
var table = _ref6.table;
|
|
182
|
-
var all = (_table$getIsAllPageRo = (_table$getIsAllPageRo2 = table.getIsAllPageRowsSelected) === null || _table$getIsAllPageRo2 === void 0 ? void 0 : _table$getIsAllPageRo2.call(table)) !== null && _table$getIsAllPageRo !== void 0 ? _table$getIsAllPageRo : table.getIsAllRowsSelected();
|
|
183
|
-
var some = (_table$getIsSomePageR = (_table$getIsSomePageR2 = table.getIsSomePageRowsSelected) === null || _table$getIsSomePageR2 === void 0 ? void 0 : _table$getIsSomePageR2.call(table)) !== null && _table$getIsSomePageR !== void 0 ? _table$getIsSomePageR : table.getIsSomeRowsSelected();
|
|
184
|
-
return /*#__PURE__*/_react["default"].createElement("input", {
|
|
185
|
-
type: "checkbox",
|
|
186
|
-
"aria-label": "Select all rows on this page",
|
|
187
|
-
checked: !!all,
|
|
188
|
-
ref: function ref(el) {
|
|
189
|
-
if (el) el.indeterminate = !!some && !all;
|
|
190
|
-
},
|
|
191
|
-
onChange: (_table$getToggleAllPa = (_table$getToggleAllPa2 = table.getToggleAllPageRowsSelectedHandler) === null || _table$getToggleAllPa2 === void 0 ? void 0 : _table$getToggleAllPa2.call(table)) !== null && _table$getToggleAllPa !== void 0 ? _table$getToggleAllPa : table.getToggleAllRowsSelectedHandler()
|
|
192
|
-
});
|
|
193
|
-
},
|
|
194
|
-
cell: function cell(_ref7) {
|
|
195
|
-
var row = _ref7.row;
|
|
196
|
-
return /*#__PURE__*/_react["default"].createElement("input", {
|
|
197
|
-
type: "checkbox",
|
|
198
|
-
"aria-label": "Select row",
|
|
199
|
-
checked: row.getIsSelected(),
|
|
200
|
-
onChange: row.getToggleSelectedHandler(),
|
|
201
|
-
onClick: function onClick(e) {
|
|
202
|
-
return e.stopPropagation();
|
|
203
|
-
} // don’t let row click toggle twice
|
|
204
|
-
});
|
|
205
|
-
},
|
|
206
|
-
enableSorting: false,
|
|
207
|
-
size: 36,
|
|
208
|
-
className: dense ? "py-1" : ""
|
|
209
|
-
};
|
|
210
|
-
return [selectCol].concat(_toConsumableArray(columns));
|
|
211
|
-
}, [columns, showSelectionColumn, dense]);
|
|
212
|
-
|
|
213
|
-
// Default getRowId if not provided: uses id/_id or index
|
|
214
|
-
var safeGetRowId = getRowId || function (row, idx) {
|
|
215
|
-
var _ref8, _row$id;
|
|
216
|
-
var key = (_ref8 = (_row$id = row.id) !== null && _row$id !== void 0 ? _row$id : row._id) !== null && _ref8 !== void 0 ? _ref8 : idx;
|
|
217
|
-
return String(key);
|
|
218
|
-
};
|
|
162
|
+
fallbackText = _ref5$fallbackText === void 0 ? "—" : _ref5$fallbackText;
|
|
219
163
|
var table = (0, _reactTable.useReactTable)({
|
|
220
164
|
data: data,
|
|
221
|
-
columns:
|
|
222
|
-
state: {
|
|
223
|
-
sorting: sorting
|
|
224
|
-
|
|
225
|
-
|
|
165
|
+
columns: columns,
|
|
166
|
+
state: _objectSpread({
|
|
167
|
+
sorting: sorting
|
|
168
|
+
}, rowSelection !== undefined ? {
|
|
169
|
+
rowSelection: rowSelection
|
|
170
|
+
} : {}),
|
|
226
171
|
getCoreRowModel: (0, _reactTable.getCoreRowModel)(),
|
|
227
172
|
manualSorting: true,
|
|
228
173
|
enableSortingRemoval: false,
|
|
174
|
+
/** Selection essentials */
|
|
175
|
+
enableRowSelection: true,
|
|
176
|
+
onRowSelectionChange: onRowSelectionChange,
|
|
177
|
+
getRowId: getRowId,
|
|
178
|
+
// IMPORTANT: provide a stable id (e.g., row => row.id) when paginating
|
|
179
|
+
autoResetRowSelection: false,
|
|
229
180
|
onSortingChange: onSortingChange,
|
|
230
|
-
|
|
231
|
-
//
|
|
232
|
-
enableRowSelection: enableRowSelection,
|
|
233
|
-
enableMultiRowSelection: enableMultiRowSelection,
|
|
234
|
-
onRowSelectionChange: onRowSelectionChange || function () {},
|
|
181
|
+
// Note: renderFallbackValue triggers only when a renderer returns `undefined`.
|
|
182
|
+
// We still handle null/"" ourselves in renderCellWithFallback.
|
|
235
183
|
renderFallbackValue: /*#__PURE__*/_react["default"].createElement("span", {
|
|
236
184
|
className: "text-muted"
|
|
237
185
|
}, fallbackText)
|
|
238
186
|
});
|
|
239
|
-
|
|
240
|
-
|
|
187
|
+
|
|
188
|
+
/** Make memoization responsive to internal table state, not just the instance ref */
|
|
189
|
+
var _table$getState = table.getState(),
|
|
190
|
+
rs = _table$getState.rowSelection,
|
|
191
|
+
currentSorting = _table$getState.sorting;
|
|
192
|
+
var headerCell = function headerCell(_ref6) {
|
|
193
|
+
var header = _ref6.header;
|
|
241
194
|
var canSort = header.column.getCanSort();
|
|
242
195
|
var sortState = header.column.getIsSorted();
|
|
243
196
|
var handleSort = function handleSort() {
|
|
@@ -269,7 +222,6 @@ var TableV2 = exports.TableV2 = function TableV2(_ref5) {
|
|
|
269
222
|
state: sortState || false
|
|
270
223
|
}));
|
|
271
224
|
};
|
|
272
|
-
var total = totalRows !== null && totalRows !== void 0 ? totalRows : 0;
|
|
273
225
|
var content = (0, _react.useMemo)(function () {
|
|
274
226
|
if (!loading && data.length === 0) {
|
|
275
227
|
return /*#__PURE__*/_react["default"].createElement("tr", null, /*#__PURE__*/_react["default"].createElement("td", {
|
|
@@ -278,26 +230,19 @@ var TableV2 = exports.TableV2 = function TableV2(_ref5) {
|
|
|
278
230
|
}, typeof emptyState === "function" ? emptyState() : emptyState));
|
|
279
231
|
}
|
|
280
232
|
return table.getRowModel().rows.map(function (row) {
|
|
281
|
-
var rowCls = [row.getIsSelected() ? "table-active" : "", dense ? "align-middle" : "", rowClickToSelect ? "cursor-pointer" : ""].filter(Boolean).join(" ");
|
|
282
|
-
var onRowClick = rowClickToSelect ? function (e) {
|
|
283
|
-
// Avoid toggling when clicking on interactive elements inside
|
|
284
|
-
if (e.target instanceof HTMLElement && (e.target.closest("button") || e.target.closest("a") || e.target.closest("input") || e.target.closest("label") || e.target.closest("[data-no-row-toggle]"))) {
|
|
285
|
-
return;
|
|
286
|
-
}
|
|
287
|
-
row.toggleSelected();
|
|
288
|
-
} : undefined;
|
|
289
233
|
return /*#__PURE__*/_react["default"].createElement("tr", {
|
|
290
234
|
key: row.id,
|
|
291
|
-
className:
|
|
292
|
-
onClick: onRowClick
|
|
235
|
+
className: [row.getIsSelected() ? "table-active" : "", dense ? "align-middle" : ""].filter(Boolean).join(" ")
|
|
293
236
|
}, row.getVisibleCells().map(function (cell) {
|
|
294
237
|
return /*#__PURE__*/_react["default"].createElement("td", {
|
|
295
238
|
key: cell.id,
|
|
296
239
|
className: [cell.column.columnDef.className || "", dense ? "py-1" : ""].filter(Boolean).join(" ")
|
|
297
|
-
}, renderCellWithFallback(cell
|
|
240
|
+
}, renderCellWithFallback(cell));
|
|
298
241
|
}));
|
|
299
242
|
});
|
|
300
|
-
|
|
243
|
+
// Depend on internal table state so selection/sorting changes trigger re-render
|
|
244
|
+
}, [data, loading, emptyState, dense, table, rs, currentSorting]);
|
|
245
|
+
var total = totalRows !== null && totalRows !== void 0 ? totalRows : 0;
|
|
301
246
|
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
302
247
|
className: parentClassName
|
|
303
248
|
}, /*#__PURE__*/_react["default"].createElement("div", {
|
|
@@ -399,17 +344,13 @@ TableV2.propTypes = {
|
|
|
399
344
|
loading: _propTypes["default"].bool,
|
|
400
345
|
showPagination: _propTypes["default"].bool,
|
|
401
346
|
pageSizeOptions: _propTypes["default"].arrayOf(_propTypes["default"].number),
|
|
402
|
-
dense: _propTypes["default"].bool
|
|
403
|
-
enableRowSelection: _propTypes["default"].bool,
|
|
404
|
-
enableMultiRowSelection: _propTypes["default"].bool,
|
|
405
|
-
showSelectionColumn: _propTypes["default"].bool,
|
|
406
|
-
rowClickToSelect: _propTypes["default"].bool
|
|
347
|
+
dense: _propTypes["default"].bool
|
|
407
348
|
};
|
|
408
349
|
|
|
409
350
|
/** Usage (server-side)
|
|
410
351
|
*
|
|
411
352
|
* <TableV2
|
|
412
|
-
* dense
|
|
353
|
+
* dense // compact mode
|
|
413
354
|
* columns={columns}
|
|
414
355
|
* data={data}
|
|
415
356
|
* totalRows={total}
|
|
@@ -419,13 +360,9 @@ TableV2.propTypes = {
|
|
|
419
360
|
* onSizeChange={(n)=>{ setPage(1); setSize(n); }}
|
|
420
361
|
* sorting={sorting}
|
|
421
362
|
* onSortingChange={(next)=>{ setPage(1); setSorting(next); }}
|
|
422
|
-
* //
|
|
423
|
-
* rowSelection={rowSelection}
|
|
363
|
+
* rowSelection={rowSelection} // { [rowId]: true }
|
|
424
364
|
* onRowSelectionChange={setRowSelection}
|
|
425
|
-
*
|
|
426
|
-
* rowClickToSelect
|
|
427
|
-
* // Provide a stable id if your data doesn't have `id`:
|
|
428
|
-
* // getRowId={(row)=>row.personId}
|
|
365
|
+
* getRowId={(row) => row.id} // <<< stable id across pages
|
|
429
366
|
* loading={loading}
|
|
430
367
|
* nowrap
|
|
431
368
|
* stickyHeader
|