@pallasoft/ps-table-components 1.17.1 → 1.18.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-table-export-button.d.ts +5 -0
- package/dist/components/ps-table-export-button.js +7 -0
- package/dist/constants/ps-table-download-config.d.ts +4 -0
- package/dist/constants/ps-table-download-config.js +7 -0
- package/dist/esm/components/ps-table-export-button.js +3 -0
- package/dist/esm/constants/ps-table-download-config.js +4 -0
- package/dist/esm/hooks/use-ps-streamed-rows.js +4 -2
- package/dist/esm/index.js +3 -0
- package/dist/esm/services/ps-table-download-service.js +12 -0
- package/dist/esm/services/ps-table-stream-service.js +3 -0
- package/dist/hooks/use-ps-streamed-rows.d.ts +1 -1
- package/dist/hooks/use-ps-streamed-rows.js +4 -2
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/interfaces/table-stream-input.d.ts +1 -0
- package/dist/interfaces/table-stream-state.d.ts +1 -0
- package/dist/services/ps-table-download-service.d.ts +3 -0
- package/dist/services/ps-table-download-service.js +16 -0
- package/dist/services/ps-table-stream-service.d.ts +1 -0
- package/dist/services/ps-table-stream-service.js +3 -0
- package/package.json +1 -1
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PsTableExportButton = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const ps_icons_1 = require("@pallasoft/ps-icons");
|
|
6
|
+
const PsTableExportButton = ({ label, onExport }) => ((0, jsx_runtime_1.jsxs)("button", { className: 'ps-focus-ring ps-liquid ps-liquid-control inline-flex min-h-10 min-w-10 items-center justify-center gap-2 rounded-full px-3 text-sm font-semibold text-ink transition-colors hover:border-primary/40 sm:px-4', onClick: onExport, type: 'button', children: [(0, jsx_runtime_1.jsx)(ps_icons_1.PsIcon, { "aria-hidden": 'true', className: 'block h-4 w-4', iconKey: ps_icons_1.PsIconKey.Download }), (0, jsx_runtime_1.jsx)("span", { className: 'sr-only sm:not-sr-only', children: label })] }));
|
|
7
|
+
exports.PsTableExportButton = PsTableExportButton;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { PsIcon, PsIconKey } from '@pallasoft/ps-icons';
|
|
3
|
+
export const PsTableExportButton = ({ label, onExport }) => (_jsxs("button", { className: 'ps-focus-ring ps-liquid ps-liquid-control inline-flex min-h-10 min-w-10 items-center justify-center gap-2 rounded-full px-3 text-sm font-semibold text-ink transition-colors hover:border-primary/40 sm:px-4', onClick: onExport, type: 'button', children: [_jsx(PsIcon, { "aria-hidden": 'true', className: 'block h-4 w-4', iconKey: PsIconKey.Download }), _jsx("span", { className: 'sr-only sm:not-sr-only', children: label })] }));
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
2
2
|
import { PsTableStreamService } from '../services/ps-table-stream-service';
|
|
3
|
-
export const usePsStreamedRows = ({ first, getRowId, loadPage, pageSize, total, }) => {
|
|
3
|
+
export const usePsStreamedRows = ({ first, getRowId, loadPage, pageSize, scope, total, }) => {
|
|
4
4
|
const [stream, setStream] = useState({
|
|
5
5
|
first,
|
|
6
6
|
hasFailed: false,
|
|
7
7
|
previous: [],
|
|
8
8
|
rows: first,
|
|
9
|
+
scope,
|
|
9
10
|
});
|
|
10
11
|
const rowId = useRef(getRowId);
|
|
11
12
|
const load = useRef(loadPage);
|
|
@@ -16,8 +17,9 @@ export const usePsStreamedRows = ({ first, getRowId, loadPage, pageSize, total,
|
|
|
16
17
|
setStream({
|
|
17
18
|
first,
|
|
18
19
|
hasFailed: false,
|
|
19
|
-
previous: PsTableStreamService.
|
|
20
|
+
previous: PsTableStreamService.carried(stream.rows, stream.previous, getRowId, total, stream.scope === scope),
|
|
20
21
|
rows: first,
|
|
22
|
+
scope,
|
|
21
23
|
});
|
|
22
24
|
const nextPage = stream.hasFailed
|
|
23
25
|
? null
|
package/dist/esm/index.js
CHANGED
|
@@ -26,3 +26,6 @@ export * from './services/ps-table-group-service';
|
|
|
26
26
|
export * from './services/ps-table-query-service';
|
|
27
27
|
export * from './services/ps-table-search-service';
|
|
28
28
|
export * from './services/ps-table-stream-service';
|
|
29
|
+
export * from './components/ps-table-export-button';
|
|
30
|
+
export * from './constants/ps-table-download-config';
|
|
31
|
+
export * from './services/ps-table-download-service';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PsTableDownloadConfig } from '../constants/ps-table-download-config';
|
|
2
|
+
export class PsTableDownloadService {
|
|
3
|
+
static downloadCsv(fileName, content) {
|
|
4
|
+
const blob = new Blob([content], { type: PsTableDownloadConfig.csvMimeType });
|
|
5
|
+
const url = URL.createObjectURL(blob);
|
|
6
|
+
const link = document.createElement('a');
|
|
7
|
+
link.href = url;
|
|
8
|
+
link.download = `${fileName}${PsTableDownloadConfig.csvExtension}`;
|
|
9
|
+
link.click();
|
|
10
|
+
URL.revokeObjectURL(url);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -6,6 +6,9 @@ export class PsTableStreamService {
|
|
|
6
6
|
const freshIds = new Set(fresh.map(getRowId));
|
|
7
7
|
return [...fresh, ...previous.filter((row) => !freshIds.has(getRowId(row)))].slice(0, total);
|
|
8
8
|
}
|
|
9
|
+
static carried(rows, previous, getRowId, total, isSameScope) {
|
|
10
|
+
return isSameScope ? PsTableStreamService.merge(rows, previous, getRowId, total) : [];
|
|
11
|
+
}
|
|
9
12
|
static append(rows, page, getRowId) {
|
|
10
13
|
const seen = new Set(rows.map(getRowId));
|
|
11
14
|
return [...rows, ...page.filter((row) => !seen.has(getRowId(row)))];
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { PsTableStreamInput } from '../interfaces/table-stream-input';
|
|
2
2
|
import type { PsTableStreamResult } from '../interfaces/table-stream-result';
|
|
3
|
-
export declare const usePsStreamedRows: <RowData>({ first, getRowId, loadPage, pageSize, total, }: PsTableStreamInput<RowData>) => PsTableStreamResult<RowData>;
|
|
3
|
+
export declare const usePsStreamedRows: <RowData>({ first, getRowId, loadPage, pageSize, scope, total, }: PsTableStreamInput<RowData>) => PsTableStreamResult<RowData>;
|
|
@@ -3,12 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.usePsStreamedRows = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
const ps_table_stream_service_1 = require("../services/ps-table-stream-service");
|
|
6
|
-
const usePsStreamedRows = ({ first, getRowId, loadPage, pageSize, total, }) => {
|
|
6
|
+
const usePsStreamedRows = ({ first, getRowId, loadPage, pageSize, scope, total, }) => {
|
|
7
7
|
const [stream, setStream] = (0, react_1.useState)({
|
|
8
8
|
first,
|
|
9
9
|
hasFailed: false,
|
|
10
10
|
previous: [],
|
|
11
11
|
rows: first,
|
|
12
|
+
scope,
|
|
12
13
|
});
|
|
13
14
|
const rowId = (0, react_1.useRef)(getRowId);
|
|
14
15
|
const load = (0, react_1.useRef)(loadPage);
|
|
@@ -19,8 +20,9 @@ const usePsStreamedRows = ({ first, getRowId, loadPage, pageSize, total, }) => {
|
|
|
19
20
|
setStream({
|
|
20
21
|
first,
|
|
21
22
|
hasFailed: false,
|
|
22
|
-
previous: ps_table_stream_service_1.PsTableStreamService.
|
|
23
|
+
previous: ps_table_stream_service_1.PsTableStreamService.carried(stream.rows, stream.previous, getRowId, total, stream.scope === scope),
|
|
23
24
|
rows: first,
|
|
25
|
+
scope,
|
|
24
26
|
});
|
|
25
27
|
const nextPage = stream.hasFailed
|
|
26
28
|
? null
|
package/dist/index.d.ts
CHANGED
|
@@ -26,3 +26,6 @@ export * from './services/ps-table-group-service';
|
|
|
26
26
|
export * from './services/ps-table-query-service';
|
|
27
27
|
export * from './services/ps-table-search-service';
|
|
28
28
|
export * from './services/ps-table-stream-service';
|
|
29
|
+
export * from './components/ps-table-export-button';
|
|
30
|
+
export * from './constants/ps-table-download-config';
|
|
31
|
+
export * from './services/ps-table-download-service';
|
package/dist/index.js
CHANGED
|
@@ -42,3 +42,6 @@ __exportStar(require("./services/ps-table-group-service"), exports);
|
|
|
42
42
|
__exportStar(require("./services/ps-table-query-service"), exports);
|
|
43
43
|
__exportStar(require("./services/ps-table-search-service"), exports);
|
|
44
44
|
__exportStar(require("./services/ps-table-stream-service"), exports);
|
|
45
|
+
__exportStar(require("./components/ps-table-export-button"), exports);
|
|
46
|
+
__exportStar(require("./constants/ps-table-download-config"), exports);
|
|
47
|
+
__exportStar(require("./services/ps-table-download-service"), exports);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PsTableDownloadService = void 0;
|
|
4
|
+
const ps_table_download_config_1 = require("../constants/ps-table-download-config");
|
|
5
|
+
class PsTableDownloadService {
|
|
6
|
+
static downloadCsv(fileName, content) {
|
|
7
|
+
const blob = new Blob([content], { type: ps_table_download_config_1.PsTableDownloadConfig.csvMimeType });
|
|
8
|
+
const url = URL.createObjectURL(blob);
|
|
9
|
+
const link = document.createElement('a');
|
|
10
|
+
link.href = url;
|
|
11
|
+
link.download = `${fileName}${ps_table_download_config_1.PsTableDownloadConfig.csvExtension}`;
|
|
12
|
+
link.click();
|
|
13
|
+
URL.revokeObjectURL(url);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.PsTableDownloadService = PsTableDownloadService;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export declare class PsTableStreamService {
|
|
2
2
|
static nextPage(loaded: number, total: number, pageSize: number): number | null;
|
|
3
3
|
static merge<RowData>(fresh: RowData[], previous: RowData[], getRowId: (row: RowData) => string, total: number): RowData[];
|
|
4
|
+
static carried<RowData>(rows: RowData[], previous: RowData[], getRowId: (row: RowData) => string, total: number, isSameScope: boolean): RowData[];
|
|
4
5
|
static append<RowData>(rows: RowData[], page: RowData[], getRowId: (row: RowData) => string): RowData[];
|
|
5
6
|
}
|
|
@@ -9,6 +9,9 @@ class PsTableStreamService {
|
|
|
9
9
|
const freshIds = new Set(fresh.map(getRowId));
|
|
10
10
|
return [...fresh, ...previous.filter((row) => !freshIds.has(getRowId(row)))].slice(0, total);
|
|
11
11
|
}
|
|
12
|
+
static carried(rows, previous, getRowId, total, isSameScope) {
|
|
13
|
+
return isSameScope ? PsTableStreamService.merge(rows, previous, getRowId, total) : [];
|
|
14
|
+
}
|
|
12
15
|
static append(rows, page, getRowId) {
|
|
13
16
|
const seen = new Set(rows.map(getRowId));
|
|
14
17
|
return [...rows, ...page.filter((row) => !seen.has(getRowId(row)))];
|