@pallasoft/ps-table-components 1.16.0 → 1.17.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.
- 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-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 +8 -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/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 +8 -0
- package/dist/index.js +8 -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-stream-service.d.ts +5 -0
- package/dist/services/ps-table-stream-service.js +17 -0
- package/package.json +1 -2
|
@@ -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;
|
|
@@ -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,8 +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';
|
|
16
23
|
export * from './services/ps-table-cell-tooltip-service';
|
|
17
24
|
export * from './services/ps-table-column-size-service';
|
|
18
25
|
export * from './services/ps-table-group-service';
|
|
19
26
|
export * from './services/ps-table-query-service';
|
|
20
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,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,8 +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';
|
|
16
23
|
export * from './services/ps-table-cell-tooltip-service';
|
|
17
24
|
export * from './services/ps-table-column-size-service';
|
|
18
25
|
export * from './services/ps-table-group-service';
|
|
19
26
|
export * from './services/ps-table-query-service';
|
|
20
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,8 +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);
|
|
32
39
|
__exportStar(require("./services/ps-table-cell-tooltip-service"), exports);
|
|
33
40
|
__exportStar(require("./services/ps-table-column-size-service"), exports);
|
|
34
41
|
__exportStar(require("./services/ps-table-group-service"), exports);
|
|
35
42
|
__exportStar(require("./services/ps-table-query-service"), exports);
|
|
36
43
|
__exportStar(require("./services/ps-table-search-service"), exports);
|
|
44
|
+
__exportStar(require("./services/ps-table-stream-service"), exports);
|
|
@@ -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.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
11
|
"types": "./dist/index.d.ts",
|
|
12
|
-
"import": "./dist/esm/index.js",
|
|
13
12
|
"module": "./dist/esm/index.js",
|
|
14
13
|
"require": "./dist/index.js",
|
|
15
14
|
"default": "./dist/index.js"
|