@raystack/apsara 0.18.5 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -4382,7 +4382,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
4382
4382
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
4383
4383
  PERFORMANCE OF THIS SOFTWARE.
4384
4384
  ***************************************************************************** */
4385
- /* global Reflect, Promise */
4385
+ /* global Reflect, Promise, SuppressedError, Symbol */
4386
4386
 
4387
4387
 
4388
4388
  var __assign = function() {
@@ -4416,7 +4416,12 @@ function __spreadArray(to, from, pack) {
4416
4416
  }
4417
4417
  }
4418
4418
  return to.concat(ar || Array.prototype.slice.call(from));
4419
- }
4419
+ }
4420
+
4421
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
4422
+ var e = new Error(message);
4423
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
4424
+ };
4420
4425
 
4421
4426
  var zeroRightClassName = 'right-scroll-bar-position';
4422
4427
  var fullWidthClassName = 'width-before-scroll-bar';
@@ -32134,7 +32139,7 @@ function Skeleton({ count = 1, wrapper: Wrapper, className: customClassName, con
32134
32139
  : elements));
32135
32140
  }
32136
32141
 
32137
- function DataTableRoot({ columns, data, emptyState, children, parentStyle, isLoading = false, ShouldShowHeader = true, initialState, loaderRow = 5, onRowClick, onStateChange = () => { }, ...props }) {
32142
+ function DataTableRoot({ columns, data, emptyState, children, parentStyle, isLoading = false, ShouldShowHeader = true, initialState, loaderRow = 2, onRowClick, onStateChange = () => { }, onLoadMore, ...props }) {
32138
32143
  const [tableCustomFilter, setTableCustomFilter] = React.useState({});
32139
32144
  const convertedChildren = React.Children.toArray(children);
32140
32145
  const header = convertedChildren.find((child) => child.type === DataTableToolbar) || null;
@@ -32142,18 +32147,15 @@ function DataTableRoot({ columns, data, emptyState, children, parentStyle, isLoa
32142
32147
  const detail = convertedChildren.find((child) => child.type === TableDetailContainer) ||
32143
32148
  null;
32144
32149
  const [tableState, setTableState] = React.useState({});
32145
- const tableData = isLoading
32146
- ? [...new Array(loaderRow)].map((_, i) => ({ id: i }))
32147
- : data;
32150
+ const observerRef = React.useRef(null);
32151
+ const getLoader = (loaderRow, columns) => ([...new Array(loaderRow)].map((_, rowIndex) => (jsxRuntimeExports.jsx(Table.Row, { children: columns.map((_, colIndex) => (jsxRuntimeExports.jsx(Table.Cell, { children: jsxRuntimeExports.jsx(Skeleton, { containerClassName: styles$4.flex1, highlightColor: "var(--background-base)", baseColor: "var(--background-base-hover)" }) }, `col_${colIndex}`))) }, `row_${rowIndex}`))));
32148
32152
  const { filteredColumns, addFilterColumn, removeFilterColumn, resetColumns } = useTableColumn();
32149
32153
  const columnWithCustomFilter = React.useMemo(() => columns.map((col) => {
32150
32154
  const colId = col.id || col?.accessorKey;
32151
32155
  const filterFn = colId && tableCustomFilter.hasOwnProperty(colId)
32152
32156
  ? tableCustomFilter[colId]
32153
32157
  : undefined;
32154
- const cell = isLoading
32155
- ? () => (jsxRuntimeExports.jsx(Skeleton, { containerClassName: styles$4.flex1, highlightColor: "var(--background-base)", baseColor: "var(--background-base-hover)" }))
32156
- : col.cell;
32158
+ const { cell } = col;
32157
32159
  return {
32158
32160
  ...col,
32159
32161
  cell,
@@ -32169,7 +32171,7 @@ function DataTableRoot({ columns, data, emptyState, children, parentStyle, isLoa
32169
32171
  setTableCustomFilter((old) => ({ ...old, [id]: filterFn }));
32170
32172
  };
32171
32173
  const table = useReactTable({
32172
- data: tableData,
32174
+ data,
32173
32175
  columns: columnWithCustomFilter,
32174
32176
  globalFilterFn: "auto",
32175
32177
  enableRowSelection: true,
@@ -32185,6 +32187,25 @@ function DataTableRoot({ columns, data, emptyState, children, parentStyle, isLoa
32185
32187
  initialState,
32186
32188
  state: tableState,
32187
32189
  });
32190
+ const lastRowRef = React.useCallback((node) => {
32191
+ if (isLoading)
32192
+ return;
32193
+ if (observerRef.current)
32194
+ observerRef.current.disconnect();
32195
+ observerRef.current = new IntersectionObserver((entries) => {
32196
+ if (entries[0].isIntersecting && onLoadMore) {
32197
+ onLoadMore();
32198
+ }
32199
+ });
32200
+ if (node)
32201
+ observerRef.current.observe(node);
32202
+ }, [isLoading, onLoadMore]);
32203
+ React.useEffect(() => {
32204
+ return () => {
32205
+ if (observerRef.current)
32206
+ observerRef.current.disconnect();
32207
+ };
32208
+ }, []);
32188
32209
  const tableStyle = {
32189
32210
  ...(table.getRowModel().rows?.length
32190
32211
  ? { width: "100%" }
@@ -32217,11 +32238,13 @@ function DataTableRoot({ columns, data, emptyState, children, parentStyle, isLoa
32217
32238
  }[header.column.getIsSorted()] ?? jsxRuntimeExports.jsx(CaretSortIcon, {})
32218
32239
  : null] }) }, `${header.id}_${index}`));
32219
32240
  }) }, headerGroup.id)))
32220
- : null }), jsxRuntimeExports.jsx(Table.Body, { children: table.getRowModel().rows?.length ? (table.getRowModel().rows.map((row) => (jsxRuntimeExports.jsx(Table.Row, { "data-state": row.getIsSelected() && "selected", onClick: () => onRowClick?.(row.original), className: isLoading
32221
- ? ""
32222
- : `${styles$4.tRow} ${onRowClick ? styles$4.tRowClick : ""}`, children: row.getVisibleCells().map((cell, index) => (jsxRuntimeExports.jsx(Table.Cell, { style: {
32223
- ...(cell.column.columnDef?.meta?.style ?? {}),
32224
- }, children: flexRender(cell.column.columnDef.cell, cell.getContext()) }, `${cell.id}_${index}`))) }, row.id)))) : (jsxRuntimeExports.jsx(Table.Row, { children: jsxRuntimeExports.jsx(Table.Cell, { colSpan: columns.length, children: emptyState || "No results." }) })) })] }), detail] })] }), footer] }) }));
32241
+ : null }), jsxRuntimeExports.jsxs(Table.Body, { children: [table.getRowModel().rows?.length ? (table.getRowModel().rows.map((row, rowIndex) => (jsxRuntimeExports.jsx(Table.Row, { "data-state": row.getIsSelected() && "selected", onClick: () => onRowClick?.(row.original), className: isLoading
32242
+ ? ""
32243
+ : `${styles$4.tRow} ${onRowClick ? styles$4.tRowClick : ""}`, ref: rowIndex === table.getRowModel().rows.length - 1
32244
+ ? lastRowRef
32245
+ : null, children: row.getVisibleCells().map((cell, index) => (jsxRuntimeExports.jsx(Table.Cell, { style: {
32246
+ ...(cell.column.columnDef?.meta?.style ?? {}),
32247
+ }, children: flexRender(cell.column.columnDef.cell, cell.getContext()) }, `${cell.id}_${index}`))) }, row.id)))) : (jsxRuntimeExports.jsx(Table.Row, { children: jsxRuntimeExports.jsx(Table.Cell, { colSpan: columns.length, children: emptyState || "No results." }) })), isLoading && getLoader(loaderRow, columns)] })] }), detail] })] }), footer] }) }));
32225
32248
  }
32226
32249
  const DataTable = Object.assign(DataTableRoot, {
32227
32250
  Toolbar: DataTableToolbar,