@pallasoft/ps-table-components 1.15.1 → 1.17.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/components/ps-data-table.js +2 -1
- package/dist/components/ps-streamed-rows.d.ts +6 -0
- package/dist/components/ps-streamed-rows.js +11 -0
- package/dist/components/ps-table-stream-status.d.ts +7 -0
- package/dist/components/ps-table-stream-status.js +12 -0
- package/dist/contexts/ps-table-stream-context.d.ts +2 -0
- package/dist/contexts/ps-table-stream-context.js +5 -0
- package/dist/esm/components/ps-data-table.js +2 -1
- package/dist/esm/components/ps-streamed-rows.js +7 -0
- package/dist/esm/components/ps-table-stream-status.js +8 -0
- package/dist/esm/contexts/ps-table-stream-context.js +2 -0
- package/dist/esm/hooks/use-ps-streamed-rows.js +42 -0
- package/dist/esm/hooks/use-ps-table-stream-status.js +3 -0
- package/dist/esm/index.js +9 -0
- package/dist/esm/interfaces/table-stream-input.js +1 -0
- package/dist/esm/interfaces/table-stream-result.js +1 -0
- package/dist/esm/interfaces/table-stream-state.js +1 -0
- package/dist/esm/interfaces/table-stream-status.js +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/services/ps-table-cell-tooltip-service.js +17 -0
- package/dist/esm/services/ps-table-stream-service.js +13 -0
- package/dist/hooks/use-ps-streamed-rows.d.ts +3 -0
- package/dist/hooks/use-ps-streamed-rows.js +46 -0
- package/dist/hooks/use-ps-table-stream-status.d.ts +2 -0
- package/dist/hooks/use-ps-table-stream-status.js +7 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +9 -0
- package/dist/interfaces/table-column.d.ts +2 -0
- package/dist/interfaces/table-stream-input.d.ts +7 -0
- package/dist/interfaces/table-stream-input.js +2 -0
- package/dist/interfaces/table-stream-result.d.ts +5 -0
- package/dist/interfaces/table-stream-result.js +2 -0
- package/dist/interfaces/table-stream-state.d.ts +6 -0
- package/dist/interfaces/table-stream-state.js +2 -0
- package/dist/interfaces/table-stream-status.d.ts +4 -0
- package/dist/interfaces/table-stream-status.js +2 -0
- package/dist/services/ps-table-cell-tooltip-service.d.ts +9 -0
- package/dist/services/ps-table-cell-tooltip-service.js +21 -0
- package/dist/services/ps-table-stream-service.d.ts +5 -0
- package/dist/services/ps-table-stream-service.js +17 -0
- package/package.json +7 -4
|
@@ -8,6 +8,7 @@ const ps_design_system_1 = require("@pallasoft/ps-design-system");
|
|
|
8
8
|
const ps_input_components_1 = require("@pallasoft/ps-input-components");
|
|
9
9
|
const ps_motion_components_1 = require("@pallasoft/ps-motion-components");
|
|
10
10
|
const table_config_1 = require("../constants/table-config");
|
|
11
|
+
const ps_table_cell_tooltip_service_1 = require("../services/ps-table-cell-tooltip-service");
|
|
11
12
|
const ps_table_column_size_service_1 = require("../services/ps-table-column-size-service");
|
|
12
13
|
const ps_table_group_service_1 = require("../services/ps-table-group-service");
|
|
13
14
|
const ps_table_query_service_1 = require("../services/ps-table-query-service");
|
|
@@ -174,7 +175,7 @@ const PsDataTable = ({ caption, className, columns, defaultSort, density = 'norm
|
|
|
174
175
|
: undefined, tabIndex: onRowClick ? 0 : undefined, children: [isSelectable ? ((0, jsx_runtime_1.jsx)("td", { className: 'w-10 pl-4 pr-0', onClick: (event) => event.stopPropagation(), onKeyDown: (event) => event.stopPropagation(), children: (0, jsx_runtime_1.jsx)(ps_input_components_1.PsCheckbox, { isSelected: selectedIds.includes(rowId), label: `Select ${rowLabel}`, onChange: () => toggleRow(rowId) }) })) : null, visibleColumns.map((column) => ((0, jsx_runtime_1.jsx)("td", { className: ps_design_system_1.PallasoftClassNameService.merge(densityClassNames[density].cell, alignClassNames[column.align !== null && column.align !== undefined ? column.align : 'left'], column.wrap ? '' : 'whitespace-nowrap', (layout === 'fixed' && !column.wrap) ||
|
|
175
176
|
ps_table_column_size_service_1.PsTableColumnSizeService.maxWidthOf(column) !== undefined
|
|
176
177
|
? 'truncate'
|
|
177
|
-
: '', 'text-sm text-ink'), style: columnStyle(column), children: column.render(row) }, column.id)))] }), renderExpandedRow ? ((0, jsx_runtime_1.jsx)("tr", { "aria-hidden": !isExpanded, className: isExpanded ? 'border-t-0' : 'border-0', children: (0, jsx_runtime_1.jsx)("td", { className: 'p-0', colSpan: columnCount, children: (0, jsx_runtime_1.jsx)(ps_motion_components_1.PsCollapse, { isOpen: isExpanded, children: (0, jsx_runtime_1.jsx)("div", { className: 'w-0 min-w-full border-l-2 border-primary bg-mist/40 px-4 py-4', children: renderExpandedRow(row) }) }) }) })) : null] }, rowId));
|
|
178
|
+
: '', 'text-sm text-ink'), style: columnStyle(column), title: ps_table_cell_tooltip_service_1.PsTableCellTooltipService.forCell(column, row), children: column.render(row) }, column.id)))] }), renderExpandedRow ? ((0, jsx_runtime_1.jsx)("tr", { "aria-hidden": !isExpanded, className: isExpanded ? 'border-t-0' : 'border-0', children: (0, jsx_runtime_1.jsx)("td", { className: 'p-0', colSpan: columnCount, children: (0, jsx_runtime_1.jsx)(ps_motion_components_1.PsCollapse, { isOpen: isExpanded, children: (0, jsx_runtime_1.jsx)("div", { className: 'w-0 min-w-full border-l-2 border-primary bg-mist/40 px-4 py-4', children: renderExpandedRow(row) }) }) }) })) : null] }, rowId));
|
|
178
179
|
};
|
|
179
180
|
if (isLoading)
|
|
180
181
|
return ((0, jsx_runtime_1.jsx)(ps_core_components_1.PsSkeletonTable, { className: className, columns: visibleColumns.length, hasToolbar: hasToolbar, rows: table_config_1.PsTableConfig.skeletonRows }));
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { PsTableStreamInput } from '../interfaces/table-stream-input';
|
|
3
|
+
export interface PsStreamedRowsProps<RowData> extends PsTableStreamInput<RowData> {
|
|
4
|
+
children: (rows: RowData[]) => ReactNode;
|
|
5
|
+
}
|
|
6
|
+
export declare const PsStreamedRows: <RowData>({ children, ...input }: PsStreamedRowsProps<RowData>) => import("react").JSX.Element;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PsStreamedRows = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const ps_table_stream_context_1 = require("../contexts/ps-table-stream-context");
|
|
6
|
+
const use_ps_streamed_rows_1 = require("../hooks/use-ps-streamed-rows");
|
|
7
|
+
const PsStreamedRows = ({ children, ...input }) => {
|
|
8
|
+
const { rows, status } = (0, use_ps_streamed_rows_1.usePsStreamedRows)(input);
|
|
9
|
+
return ((0, jsx_runtime_1.jsx)(ps_table_stream_context_1.PsTableStreamContext.Provider, { value: status, children: children(rows) }));
|
|
10
|
+
};
|
|
11
|
+
exports.PsStreamedRows = PsStreamedRows;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { PsTableStreamStatusData } from '../interfaces/table-stream-status';
|
|
3
|
+
export interface PsTableStreamStatusProps {
|
|
4
|
+
className?: string;
|
|
5
|
+
children: (status: PsTableStreamStatusData) => ReactNode;
|
|
6
|
+
}
|
|
7
|
+
export declare const PsTableStreamStatus: ({ className, children }: PsTableStreamStatusProps) => import("react").JSX.Element | null;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PsTableStreamStatus = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const use_ps_table_stream_status_1 = require("../hooks/use-ps-table-stream-status");
|
|
6
|
+
const PsTableStreamStatus = ({ className, children }) => {
|
|
7
|
+
const status = (0, use_ps_table_stream_status_1.usePsTableStreamStatus)();
|
|
8
|
+
if (status === null)
|
|
9
|
+
return null;
|
|
10
|
+
return ((0, jsx_runtime_1.jsx)("span", { "aria-live": 'polite', className: className, children: children(status) }));
|
|
11
|
+
};
|
|
12
|
+
exports.PsTableStreamStatus = PsTableStreamStatus;
|
|
@@ -5,6 +5,7 @@ import { PallasoftClassNameService } from '@pallasoft/ps-design-system';
|
|
|
5
5
|
import { PsCheckbox } from '@pallasoft/ps-input-components';
|
|
6
6
|
import { PsCollapse } from '@pallasoft/ps-motion-components';
|
|
7
7
|
import { PsTableConfig } from '../constants/table-config';
|
|
8
|
+
import { PsTableCellTooltipService } from '../services/ps-table-cell-tooltip-service';
|
|
8
9
|
import { PsTableColumnSizeService } from '../services/ps-table-column-size-service';
|
|
9
10
|
import { PsTableGroupService } from '../services/ps-table-group-service';
|
|
10
11
|
import { PsTableQueryService } from '../services/ps-table-query-service';
|
|
@@ -171,7 +172,7 @@ export const PsDataTable = ({ caption, className, columns, defaultSort, density
|
|
|
171
172
|
: undefined, tabIndex: onRowClick ? 0 : undefined, children: [isSelectable ? (_jsx("td", { className: 'w-10 pl-4 pr-0', onClick: (event) => event.stopPropagation(), onKeyDown: (event) => event.stopPropagation(), children: _jsx(PsCheckbox, { isSelected: selectedIds.includes(rowId), label: `Select ${rowLabel}`, onChange: () => toggleRow(rowId) }) })) : null, visibleColumns.map((column) => (_jsx("td", { className: PallasoftClassNameService.merge(densityClassNames[density].cell, alignClassNames[column.align !== null && column.align !== undefined ? column.align : 'left'], column.wrap ? '' : 'whitespace-nowrap', (layout === 'fixed' && !column.wrap) ||
|
|
172
173
|
PsTableColumnSizeService.maxWidthOf(column) !== undefined
|
|
173
174
|
? 'truncate'
|
|
174
|
-
: '', 'text-sm text-ink'), style: columnStyle(column), children: column.render(row) }, column.id)))] }), renderExpandedRow ? (_jsx("tr", { "aria-hidden": !isExpanded, className: isExpanded ? 'border-t-0' : 'border-0', children: _jsx("td", { className: 'p-0', colSpan: columnCount, children: _jsx(PsCollapse, { isOpen: isExpanded, children: _jsx("div", { className: 'w-0 min-w-full border-l-2 border-primary bg-mist/40 px-4 py-4', children: renderExpandedRow(row) }) }) }) })) : null] }, rowId));
|
|
175
|
+
: '', 'text-sm text-ink'), style: columnStyle(column), title: PsTableCellTooltipService.forCell(column, row), children: column.render(row) }, column.id)))] }), renderExpandedRow ? (_jsx("tr", { "aria-hidden": !isExpanded, className: isExpanded ? 'border-t-0' : 'border-0', children: _jsx("td", { className: 'p-0', colSpan: columnCount, children: _jsx(PsCollapse, { isOpen: isExpanded, children: _jsx("div", { className: 'w-0 min-w-full border-l-2 border-primary bg-mist/40 px-4 py-4', children: renderExpandedRow(row) }) }) }) })) : null] }, rowId));
|
|
175
176
|
};
|
|
176
177
|
if (isLoading)
|
|
177
178
|
return (_jsx(PsSkeletonTable, { className: className, columns: visibleColumns.length, hasToolbar: hasToolbar, rows: PsTableConfig.skeletonRows }));
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { PsTableStreamContext } from '../contexts/ps-table-stream-context';
|
|
3
|
+
import { usePsStreamedRows } from '../hooks/use-ps-streamed-rows';
|
|
4
|
+
export const PsStreamedRows = ({ children, ...input }) => {
|
|
5
|
+
const { rows, status } = usePsStreamedRows(input);
|
|
6
|
+
return (_jsx(PsTableStreamContext.Provider, { value: status, children: children(rows) }));
|
|
7
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { usePsTableStreamStatus } from '../hooks/use-ps-table-stream-status';
|
|
3
|
+
export const PsTableStreamStatus = ({ className, children }) => {
|
|
4
|
+
const status = usePsTableStreamStatus();
|
|
5
|
+
if (status === null)
|
|
6
|
+
return null;
|
|
7
|
+
return (_jsx("span", { "aria-live": 'polite', className: className, children: children(status) }));
|
|
8
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { PsTableStreamService } from '../services/ps-table-stream-service';
|
|
3
|
+
export const usePsStreamedRows = ({ first, getRowId, loadPage, pageSize, total, }) => {
|
|
4
|
+
const [stream, setStream] = useState({
|
|
5
|
+
first,
|
|
6
|
+
hasFailed: false,
|
|
7
|
+
previous: [],
|
|
8
|
+
rows: first,
|
|
9
|
+
});
|
|
10
|
+
const rowId = useRef(getRowId);
|
|
11
|
+
const load = useRef(loadPage);
|
|
12
|
+
const requested = useRef(null);
|
|
13
|
+
rowId.current = getRowId;
|
|
14
|
+
load.current = loadPage;
|
|
15
|
+
if (stream.first !== first)
|
|
16
|
+
setStream({
|
|
17
|
+
first,
|
|
18
|
+
hasFailed: false,
|
|
19
|
+
previous: PsTableStreamService.merge(stream.rows, stream.previous, getRowId, total),
|
|
20
|
+
rows: first,
|
|
21
|
+
});
|
|
22
|
+
const nextPage = stream.hasFailed
|
|
23
|
+
? null
|
|
24
|
+
: PsTableStreamService.nextPage(stream.rows.length, total, pageSize);
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (nextPage === null || requested.current === stream.rows)
|
|
27
|
+
return;
|
|
28
|
+
const base = stream.rows;
|
|
29
|
+
requested.current = base;
|
|
30
|
+
load.current(nextPage).then((page) => setStream((current) => current.rows !== base
|
|
31
|
+
? current
|
|
32
|
+
: page.length === 0
|
|
33
|
+
? { ...current, hasFailed: true }
|
|
34
|
+
: { ...current, rows: PsTableStreamService.append(current.rows, page, rowId.current) }), () => setStream((current) => (current.rows !== base ? current : { ...current, hasFailed: true })));
|
|
35
|
+
}, [nextPage, stream.rows]);
|
|
36
|
+
const isStreaming = nextPage !== null;
|
|
37
|
+
const rows = useMemo(() => isStreaming
|
|
38
|
+
? PsTableStreamService.merge(stream.rows, stream.previous, rowId.current, total)
|
|
39
|
+
: stream.rows, [isStreaming, stream.previous, stream.rows, total]);
|
|
40
|
+
const status = useMemo(() => (isStreaming ? { loaded: stream.rows.length, total } : null), [isStreaming, stream.rows.length, total]);
|
|
41
|
+
return { rows, status };
|
|
42
|
+
};
|
package/dist/esm/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export * from './components/ps-data-table';
|
|
2
|
+
export * from './components/ps-streamed-rows';
|
|
3
|
+
export * from './components/ps-table-stream-status';
|
|
2
4
|
export * from './components/ps-table-group-header';
|
|
3
5
|
export * from './components/ps-table-pagination';
|
|
4
6
|
export * from './constants/table-card-role';
|
|
@@ -13,7 +15,14 @@ export * from './interfaces/table-query';
|
|
|
13
15
|
export * from './interfaces/table-row-action';
|
|
14
16
|
export * from './interfaces/table-row-group';
|
|
15
17
|
export * from './interfaces/table-sort';
|
|
18
|
+
export * from './interfaces/table-stream-input';
|
|
19
|
+
export * from './interfaces/table-stream-result';
|
|
20
|
+
export * from './interfaces/table-stream-status';
|
|
21
|
+
export * from './hooks/use-ps-streamed-rows';
|
|
22
|
+
export * from './hooks/use-ps-table-stream-status';
|
|
23
|
+
export * from './services/ps-table-cell-tooltip-service';
|
|
16
24
|
export * from './services/ps-table-column-size-service';
|
|
17
25
|
export * from './services/ps-table-group-service';
|
|
18
26
|
export * from './services/ps-table-query-service';
|
|
19
27
|
export * from './services/ps-table-search-service';
|
|
28
|
+
export * from './services/ps-table-stream-service';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export class PsTableCellTooltipService {
|
|
2
|
+
/**
|
|
3
|
+
* A truncated cell hides the rest of its text, so it carries the full value as a native
|
|
4
|
+
* tooltip. A column can name that text itself; otherwise a string sortValue is already the
|
|
5
|
+
* cell's text in every column that sorts on what it shows.
|
|
6
|
+
*/
|
|
7
|
+
static forCell(column, row) {
|
|
8
|
+
if (column.tooltip) {
|
|
9
|
+
const explicit = column.tooltip(row);
|
|
10
|
+
return explicit === null || explicit === '' ? undefined : explicit;
|
|
11
|
+
}
|
|
12
|
+
if (!column.sortValue)
|
|
13
|
+
return undefined;
|
|
14
|
+
const value = column.sortValue(row);
|
|
15
|
+
return typeof value === 'string' && value !== '' ? value : undefined;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export class PsTableStreamService {
|
|
2
|
+
static nextPage(loaded, total, pageSize) {
|
|
3
|
+
return loaded < total ? Math.floor(loaded / pageSize) + 1 : null;
|
|
4
|
+
}
|
|
5
|
+
static merge(fresh, previous, getRowId, total) {
|
|
6
|
+
const freshIds = new Set(fresh.map(getRowId));
|
|
7
|
+
return [...fresh, ...previous.filter((row) => !freshIds.has(getRowId(row)))].slice(0, total);
|
|
8
|
+
}
|
|
9
|
+
static append(rows, page, getRowId) {
|
|
10
|
+
const seen = new Set(rows.map(getRowId));
|
|
11
|
+
return [...rows, ...page.filter((row) => !seen.has(getRowId(row)))];
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { PsTableStreamInput } from '../interfaces/table-stream-input';
|
|
2
|
+
import type { PsTableStreamResult } from '../interfaces/table-stream-result';
|
|
3
|
+
export declare const usePsStreamedRows: <RowData>({ first, getRowId, loadPage, pageSize, total, }: PsTableStreamInput<RowData>) => PsTableStreamResult<RowData>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.usePsStreamedRows = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const ps_table_stream_service_1 = require("../services/ps-table-stream-service");
|
|
6
|
+
const usePsStreamedRows = ({ first, getRowId, loadPage, pageSize, total, }) => {
|
|
7
|
+
const [stream, setStream] = (0, react_1.useState)({
|
|
8
|
+
first,
|
|
9
|
+
hasFailed: false,
|
|
10
|
+
previous: [],
|
|
11
|
+
rows: first,
|
|
12
|
+
});
|
|
13
|
+
const rowId = (0, react_1.useRef)(getRowId);
|
|
14
|
+
const load = (0, react_1.useRef)(loadPage);
|
|
15
|
+
const requested = (0, react_1.useRef)(null);
|
|
16
|
+
rowId.current = getRowId;
|
|
17
|
+
load.current = loadPage;
|
|
18
|
+
if (stream.first !== first)
|
|
19
|
+
setStream({
|
|
20
|
+
first,
|
|
21
|
+
hasFailed: false,
|
|
22
|
+
previous: ps_table_stream_service_1.PsTableStreamService.merge(stream.rows, stream.previous, getRowId, total),
|
|
23
|
+
rows: first,
|
|
24
|
+
});
|
|
25
|
+
const nextPage = stream.hasFailed
|
|
26
|
+
? null
|
|
27
|
+
: ps_table_stream_service_1.PsTableStreamService.nextPage(stream.rows.length, total, pageSize);
|
|
28
|
+
(0, react_1.useEffect)(() => {
|
|
29
|
+
if (nextPage === null || requested.current === stream.rows)
|
|
30
|
+
return;
|
|
31
|
+
const base = stream.rows;
|
|
32
|
+
requested.current = base;
|
|
33
|
+
load.current(nextPage).then((page) => setStream((current) => current.rows !== base
|
|
34
|
+
? current
|
|
35
|
+
: page.length === 0
|
|
36
|
+
? { ...current, hasFailed: true }
|
|
37
|
+
: { ...current, rows: ps_table_stream_service_1.PsTableStreamService.append(current.rows, page, rowId.current) }), () => setStream((current) => (current.rows !== base ? current : { ...current, hasFailed: true })));
|
|
38
|
+
}, [nextPage, stream.rows]);
|
|
39
|
+
const isStreaming = nextPage !== null;
|
|
40
|
+
const rows = (0, react_1.useMemo)(() => isStreaming
|
|
41
|
+
? ps_table_stream_service_1.PsTableStreamService.merge(stream.rows, stream.previous, rowId.current, total)
|
|
42
|
+
: stream.rows, [isStreaming, stream.previous, stream.rows, total]);
|
|
43
|
+
const status = (0, react_1.useMemo)(() => (isStreaming ? { loaded: stream.rows.length, total } : null), [isStreaming, stream.rows.length, total]);
|
|
44
|
+
return { rows, status };
|
|
45
|
+
};
|
|
46
|
+
exports.usePsStreamedRows = usePsStreamedRows;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.usePsTableStreamStatus = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const ps_table_stream_context_1 = require("../contexts/ps-table-stream-context");
|
|
6
|
+
const usePsTableStreamStatus = () => (0, react_1.useContext)(ps_table_stream_context_1.PsTableStreamContext);
|
|
7
|
+
exports.usePsTableStreamStatus = usePsTableStreamStatus;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export * from './components/ps-data-table';
|
|
2
|
+
export * from './components/ps-streamed-rows';
|
|
3
|
+
export * from './components/ps-table-stream-status';
|
|
2
4
|
export * from './components/ps-table-group-header';
|
|
3
5
|
export * from './components/ps-table-pagination';
|
|
4
6
|
export * from './constants/table-card-role';
|
|
@@ -13,7 +15,14 @@ export * from './interfaces/table-query';
|
|
|
13
15
|
export * from './interfaces/table-row-action';
|
|
14
16
|
export * from './interfaces/table-row-group';
|
|
15
17
|
export * from './interfaces/table-sort';
|
|
18
|
+
export * from './interfaces/table-stream-input';
|
|
19
|
+
export * from './interfaces/table-stream-result';
|
|
20
|
+
export * from './interfaces/table-stream-status';
|
|
21
|
+
export * from './hooks/use-ps-streamed-rows';
|
|
22
|
+
export * from './hooks/use-ps-table-stream-status';
|
|
23
|
+
export * from './services/ps-table-cell-tooltip-service';
|
|
16
24
|
export * from './services/ps-table-column-size-service';
|
|
17
25
|
export * from './services/ps-table-group-service';
|
|
18
26
|
export * from './services/ps-table-query-service';
|
|
19
27
|
export * from './services/ps-table-search-service';
|
|
28
|
+
export * from './services/ps-table-stream-service';
|
package/dist/index.js
CHANGED
|
@@ -15,6 +15,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./components/ps-data-table"), exports);
|
|
18
|
+
__exportStar(require("./components/ps-streamed-rows"), exports);
|
|
19
|
+
__exportStar(require("./components/ps-table-stream-status"), exports);
|
|
18
20
|
__exportStar(require("./components/ps-table-group-header"), exports);
|
|
19
21
|
__exportStar(require("./components/ps-table-pagination"), exports);
|
|
20
22
|
__exportStar(require("./constants/table-card-role"), exports);
|
|
@@ -29,7 +31,14 @@ __exportStar(require("./interfaces/table-query"), exports);
|
|
|
29
31
|
__exportStar(require("./interfaces/table-row-action"), exports);
|
|
30
32
|
__exportStar(require("./interfaces/table-row-group"), exports);
|
|
31
33
|
__exportStar(require("./interfaces/table-sort"), exports);
|
|
34
|
+
__exportStar(require("./interfaces/table-stream-input"), exports);
|
|
35
|
+
__exportStar(require("./interfaces/table-stream-result"), exports);
|
|
36
|
+
__exportStar(require("./interfaces/table-stream-status"), exports);
|
|
37
|
+
__exportStar(require("./hooks/use-ps-streamed-rows"), exports);
|
|
38
|
+
__exportStar(require("./hooks/use-ps-table-stream-status"), exports);
|
|
39
|
+
__exportStar(require("./services/ps-table-cell-tooltip-service"), exports);
|
|
32
40
|
__exportStar(require("./services/ps-table-column-size-service"), exports);
|
|
33
41
|
__exportStar(require("./services/ps-table-group-service"), exports);
|
|
34
42
|
__exportStar(require("./services/ps-table-query-service"), exports);
|
|
35
43
|
__exportStar(require("./services/ps-table-search-service"), exports);
|
|
44
|
+
__exportStar(require("./services/ps-table-stream-service"), exports);
|
|
@@ -16,6 +16,8 @@ export interface PsTableColumn<RowData> {
|
|
|
16
16
|
render: (row: RowData) => ReactNode;
|
|
17
17
|
size?: PsTableColumnSize;
|
|
18
18
|
sortValue?: (row: RowData) => string | number | null;
|
|
19
|
+
/** Text shown on hover when the cell is too narrow. Defaults to the column's string sortValue. */
|
|
20
|
+
tooltip?: (row: RowData) => string | null;
|
|
19
21
|
width?: string;
|
|
20
22
|
wrap?: boolean;
|
|
21
23
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { PsTableColumn } from '../interfaces/table-column';
|
|
2
|
+
export declare class PsTableCellTooltipService {
|
|
3
|
+
/**
|
|
4
|
+
* A truncated cell hides the rest of its text, so it carries the full value as a native
|
|
5
|
+
* tooltip. A column can name that text itself; otherwise a string sortValue is already the
|
|
6
|
+
* cell's text in every column that sorts on what it shows.
|
|
7
|
+
*/
|
|
8
|
+
static forCell<RowData>(column: PsTableColumn<RowData>, row: RowData): string | undefined;
|
|
9
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PsTableCellTooltipService = void 0;
|
|
4
|
+
class PsTableCellTooltipService {
|
|
5
|
+
/**
|
|
6
|
+
* A truncated cell hides the rest of its text, so it carries the full value as a native
|
|
7
|
+
* tooltip. A column can name that text itself; otherwise a string sortValue is already the
|
|
8
|
+
* cell's text in every column that sorts on what it shows.
|
|
9
|
+
*/
|
|
10
|
+
static forCell(column, row) {
|
|
11
|
+
if (column.tooltip) {
|
|
12
|
+
const explicit = column.tooltip(row);
|
|
13
|
+
return explicit === null || explicit === '' ? undefined : explicit;
|
|
14
|
+
}
|
|
15
|
+
if (!column.sortValue)
|
|
16
|
+
return undefined;
|
|
17
|
+
const value = column.sortValue(row);
|
|
18
|
+
return typeof value === 'string' && value !== '' ? value : undefined;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.PsTableCellTooltipService = PsTableCellTooltipService;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare class PsTableStreamService {
|
|
2
|
+
static nextPage(loaded: number, total: number, pageSize: number): number | null;
|
|
3
|
+
static merge<RowData>(fresh: RowData[], previous: RowData[], getRowId: (row: RowData) => string, total: number): RowData[];
|
|
4
|
+
static append<RowData>(rows: RowData[], page: RowData[], getRowId: (row: RowData) => string): RowData[];
|
|
5
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PsTableStreamService = void 0;
|
|
4
|
+
class PsTableStreamService {
|
|
5
|
+
static nextPage(loaded, total, pageSize) {
|
|
6
|
+
return loaded < total ? Math.floor(loaded / pageSize) + 1 : null;
|
|
7
|
+
}
|
|
8
|
+
static merge(fresh, previous, getRowId, total) {
|
|
9
|
+
const freshIds = new Set(fresh.map(getRowId));
|
|
10
|
+
return [...fresh, ...previous.filter((row) => !freshIds.has(getRowId(row)))].slice(0, total);
|
|
11
|
+
}
|
|
12
|
+
static append(rows, page, getRowId) {
|
|
13
|
+
const seen = new Set(rows.map(getRowId));
|
|
14
|
+
return [...rows, ...page.filter((row) => !seen.has(getRowId(row)))];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.PsTableStreamService = PsTableStreamService;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pallasoft/ps-table-components",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.17.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
11
|
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/esm/index.js",
|
|
12
13
|
"module": "./dist/esm/index.js",
|
|
13
14
|
"require": "./dist/index.js",
|
|
14
15
|
"default": "./dist/index.js"
|
|
@@ -19,7 +20,7 @@
|
|
|
19
20
|
],
|
|
20
21
|
"scripts": {
|
|
21
22
|
"husky:prepare": "npx husky",
|
|
22
|
-
"build": "tsc && tsc -p tsconfig.esm.json",
|
|
23
|
+
"build": "tsc && tsc -p tsconfig.esm.json && node -e \"require('fs').writeFileSync('dist/esm/package.json', JSON.stringify({ type: 'module' }))\"",
|
|
23
24
|
"setup:graphify": "sh scripts/graphify-setup.sh",
|
|
24
25
|
"update:graphify": "sh scripts/graphify-update.sh",
|
|
25
26
|
"lint": "npm run lint:eslint",
|
|
@@ -28,7 +29,8 @@
|
|
|
28
29
|
"format:prettier": "npx prettier --write \"src/**/*.{ts,tsx,json,md}\"",
|
|
29
30
|
"lint:eslint": "npx eslint \"src/**/*.{ts,tsx}\"",
|
|
30
31
|
"lint:eslint:fix": "npx eslint --fix \"src/**/*.{ts,tsx}\"",
|
|
31
|
-
"release": "semantic-release"
|
|
32
|
+
"release": "semantic-release",
|
|
33
|
+
"test": "vitest run"
|
|
32
34
|
},
|
|
33
35
|
"peerDependencies": {
|
|
34
36
|
"react": "^18 || ^19"
|
|
@@ -60,7 +62,8 @@
|
|
|
60
62
|
"react-dom": "^19.3.0",
|
|
61
63
|
"semantic-release": "^24.2.0",
|
|
62
64
|
"ts-node": "^10.9.2",
|
|
63
|
-
"typescript": "^5.9.3"
|
|
65
|
+
"typescript": "^5.9.3",
|
|
66
|
+
"vitest": "^3.2.4"
|
|
64
67
|
},
|
|
65
68
|
"publishConfig": {
|
|
66
69
|
"access": "public",
|