@pallasoft/ps-core-components 2.18.0 → 2.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/esm/hooks/use-ps-optimistic-rows.js +16 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/interfaces/ps-optimistic-changes.js +1 -0
- package/dist/esm/interfaces/ps-optimistic-rows-input.js +1 -0
- package/dist/esm/interfaces/ps-optimistic-rows-result.js +1 -0
- package/dist/hooks/use-ps-optimistic-rows.d.ts +3 -0
- package/dist/hooks/use-ps-optimistic-rows.js +20 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/interfaces/ps-optimistic-changes.d.ts +4 -0
- package/dist/interfaces/ps-optimistic-changes.js +2 -0
- package/dist/interfaces/ps-optimistic-rows-input.d.ts +6 -0
- package/dist/interfaces/ps-optimistic-rows-input.js +2 -0
- package/dist/interfaces/ps-optimistic-rows-result.d.ts +6 -0
- package/dist/interfaces/ps-optimistic-rows-result.js +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useCallback, useMemo, useState } from 'react';
|
|
2
|
+
export const usePsOptimisticRows = ({ apply, isHolding = false, isSaving, rows, }) => {
|
|
3
|
+
const [remembered, setRemembered] = useState({
|
|
4
|
+
base: rows,
|
|
5
|
+
changes: [],
|
|
6
|
+
});
|
|
7
|
+
const changes = remembered.base === rows || isSaving || isHolding ? remembered.changes : [];
|
|
8
|
+
const shown = useMemo(() => (changes.length === 0 ? rows : apply(rows, changes)), [apply, changes, rows]);
|
|
9
|
+
const remember = useCallback((change) => setRemembered((current) => ({
|
|
10
|
+
base: rows,
|
|
11
|
+
changes: [...(current.base === rows ? current.changes : []), change],
|
|
12
|
+
})), [rows]);
|
|
13
|
+
const forgetLast = useCallback(() => setRemembered((current) => ({ base: current.base, changes: current.changes.slice(0, -1) })), []);
|
|
14
|
+
const rollback = useCallback(() => setRemembered({ base: rows, changes: [] }), [rows]);
|
|
15
|
+
return { forgetLast, remember, rollback, rows: shown };
|
|
16
|
+
};
|
package/dist/esm/index.js
CHANGED
|
@@ -54,6 +54,9 @@ export * from './models/ps-element-size';
|
|
|
54
54
|
export * from './models/ps-voice-orb';
|
|
55
55
|
export * from './models/ps-navigation-progress';
|
|
56
56
|
export * from './hooks/use-ps-debounced-value';
|
|
57
|
+
export * from './hooks/use-ps-optimistic-rows';
|
|
58
|
+
export * from './interfaces/ps-optimistic-rows-input';
|
|
59
|
+
export * from './interfaces/ps-optimistic-rows-result';
|
|
57
60
|
export * from './hooks/use-ps-navigation-progress';
|
|
58
61
|
export * from './models/ps-draggable-grid';
|
|
59
62
|
export * from './constants/ps-draggable-grid';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { PsOptimisticRowsInput } from '../interfaces/ps-optimistic-rows-input';
|
|
2
|
+
import type { PsOptimisticRowsResult } from '../interfaces/ps-optimistic-rows-result';
|
|
3
|
+
export declare const usePsOptimisticRows: <Row, Change>({ apply, isHolding, isSaving, rows, }: PsOptimisticRowsInput<Row, Change>) => PsOptimisticRowsResult<Row, Change>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.usePsOptimisticRows = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const usePsOptimisticRows = ({ apply, isHolding = false, isSaving, rows, }) => {
|
|
6
|
+
const [remembered, setRemembered] = (0, react_1.useState)({
|
|
7
|
+
base: rows,
|
|
8
|
+
changes: [],
|
|
9
|
+
});
|
|
10
|
+
const changes = remembered.base === rows || isSaving || isHolding ? remembered.changes : [];
|
|
11
|
+
const shown = (0, react_1.useMemo)(() => (changes.length === 0 ? rows : apply(rows, changes)), [apply, changes, rows]);
|
|
12
|
+
const remember = (0, react_1.useCallback)((change) => setRemembered((current) => ({
|
|
13
|
+
base: rows,
|
|
14
|
+
changes: [...(current.base === rows ? current.changes : []), change],
|
|
15
|
+
})), [rows]);
|
|
16
|
+
const forgetLast = (0, react_1.useCallback)(() => setRemembered((current) => ({ base: current.base, changes: current.changes.slice(0, -1) })), []);
|
|
17
|
+
const rollback = (0, react_1.useCallback)(() => setRemembered({ base: rows, changes: [] }), [rows]);
|
|
18
|
+
return { forgetLast, remember, rollback, rows: shown };
|
|
19
|
+
};
|
|
20
|
+
exports.usePsOptimisticRows = usePsOptimisticRows;
|
package/dist/index.d.ts
CHANGED
|
@@ -54,6 +54,9 @@ export * from './models/ps-element-size';
|
|
|
54
54
|
export * from './models/ps-voice-orb';
|
|
55
55
|
export * from './models/ps-navigation-progress';
|
|
56
56
|
export * from './hooks/use-ps-debounced-value';
|
|
57
|
+
export * from './hooks/use-ps-optimistic-rows';
|
|
58
|
+
export * from './interfaces/ps-optimistic-rows-input';
|
|
59
|
+
export * from './interfaces/ps-optimistic-rows-result';
|
|
57
60
|
export * from './hooks/use-ps-navigation-progress';
|
|
58
61
|
export * from './models/ps-draggable-grid';
|
|
59
62
|
export * from './constants/ps-draggable-grid';
|
package/dist/index.js
CHANGED
|
@@ -70,6 +70,9 @@ __exportStar(require("./models/ps-element-size"), exports);
|
|
|
70
70
|
__exportStar(require("./models/ps-voice-orb"), exports);
|
|
71
71
|
__exportStar(require("./models/ps-navigation-progress"), exports);
|
|
72
72
|
__exportStar(require("./hooks/use-ps-debounced-value"), exports);
|
|
73
|
+
__exportStar(require("./hooks/use-ps-optimistic-rows"), exports);
|
|
74
|
+
__exportStar(require("./interfaces/ps-optimistic-rows-input"), exports);
|
|
75
|
+
__exportStar(require("./interfaces/ps-optimistic-rows-result"), exports);
|
|
73
76
|
__exportStar(require("./hooks/use-ps-navigation-progress"), exports);
|
|
74
77
|
__exportStar(require("./models/ps-draggable-grid"), exports);
|
|
75
78
|
__exportStar(require("./constants/ps-draggable-grid"), exports);
|