@pallasoft/ps-core-components 2.46.1 → 2.47.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-data-boundary.d.ts +2 -1
- package/dist/components/ps-data-boundary.js +2 -2
- package/dist/components/ps-empty-value.d.ts +5 -0
- package/dist/components/ps-empty-value.js +8 -0
- package/dist/components/ps-image.d.ts +14 -0
- package/dist/components/ps-image.js +29 -0
- package/dist/components/ps-signed-value.d.ts +6 -0
- package/dist/components/ps-signed-value.js +9 -0
- package/dist/constants/ps-empty-value-config.d.ts +4 -0
- package/dist/constants/ps-empty-value-config.js +7 -0
- package/dist/constants/ps-image-config.d.ts +7 -0
- package/dist/constants/ps-image-config.js +10 -0
- package/dist/constants/ps-image-fit.d.ts +7 -0
- package/dist/constants/ps-image-fit.js +11 -0
- package/dist/constants/ps-image-status.d.ts +5 -0
- package/dist/constants/ps-image-status.js +9 -0
- package/dist/constants/ps-signed-value-classes.d.ts +2 -0
- package/dist/constants/ps-signed-value-classes.js +9 -0
- package/dist/esm/components/ps-data-boundary.js +2 -2
- package/dist/esm/components/ps-empty-value.js +4 -0
- package/dist/esm/components/ps-image.js +25 -0
- package/dist/esm/components/ps-signed-value.js +5 -0
- package/dist/esm/constants/ps-empty-value-config.js +4 -0
- package/dist/esm/constants/ps-image-config.js +7 -0
- package/dist/esm/constants/ps-image-fit.js +8 -0
- package/dist/esm/constants/ps-image-status.js +6 -0
- package/dist/esm/constants/ps-signed-value-classes.js +6 -0
- package/dist/esm/hooks/use-ps-cursor-pages.js +82 -0
- package/dist/esm/hooks/use-ps-draft-state.js +18 -0
- package/dist/esm/hooks/use-ps-optimistic-fetcher.js +2 -4
- package/dist/esm/hooks/use-ps-optimistic-save.js +1 -1
- package/dist/esm/hooks/use-ps-remote-read.js +31 -0
- package/dist/esm/hooks/use-ps-text-param.js +16 -0
- package/dist/esm/index.js +32 -12
- package/dist/esm/models/ps-image-state-data.js +1 -0
- package/dist/esm/models/ps-remote-read-state.js +1 -0
- package/dist/esm/models/ps-remote-settled-data.js +1 -0
- package/dist/esm/models/ps-text-param-data.js +1 -0
- package/dist/esm/models/ps-text-param-options.js +1 -0
- package/dist/esm/services/ps-cursor-pages-service.js +14 -0
- package/dist/esm/services/ps-draft-state-service.js +11 -0
- package/dist/esm/services/ps-image-service.js +11 -0
- package/dist/esm/services/ps-remote-read-service.js +19 -0
- package/dist/esm/services/ps-signed-value-service.js +13 -0
- package/dist/hooks/use-ps-cursor-pages.d.ts +3 -0
- package/dist/hooks/use-ps-cursor-pages.js +86 -0
- package/dist/hooks/use-ps-draft-state.d.ts +3 -0
- package/dist/hooks/use-ps-draft-state.js +22 -0
- package/dist/hooks/use-ps-optimistic-fetcher.js +7 -9
- package/dist/hooks/use-ps-optimistic-save.js +4 -4
- package/dist/hooks/use-ps-remote-read.d.ts +3 -0
- package/dist/hooks/use-ps-remote-read.js +35 -0
- package/dist/hooks/use-ps-text-param.d.ts +4 -0
- package/dist/hooks/use-ps-text-param.js +20 -0
- package/dist/index.d.ts +32 -12
- package/dist/index.js +39 -12
- package/dist/interfaces/ps-cursor-pages-input.d.ts +8 -0
- package/dist/interfaces/ps-cursor-pages-result.d.ts +7 -0
- package/dist/interfaces/ps-draft-state-options.d.ts +3 -0
- package/dist/interfaces/ps-draft-state-result.d.ts +7 -0
- package/dist/interfaces/ps-optimistic-failure.d.ts +1 -1
- package/dist/interfaces/ps-optimistic-save-input.d.ts +1 -1
- package/dist/interfaces/ps-remote-read-input.d.ts +5 -0
- package/dist/interfaces/ps-remote-read-result.d.ts +5 -0
- package/dist/models/ps-cursor-pages-state.d.ts +8 -0
- package/dist/models/ps-draft-state-data.d.ts +4 -0
- package/dist/models/ps-image-state-data.d.ts +5 -0
- package/dist/models/ps-image-state-data.js +2 -0
- package/dist/models/ps-remote-read-state.d.ts +6 -0
- package/dist/models/ps-remote-read-state.js +2 -0
- package/dist/models/ps-remote-settled-data.d.ts +4 -0
- package/dist/models/ps-remote-settled-data.js +2 -0
- package/dist/models/ps-text-param-data.d.ts +5 -0
- package/dist/models/ps-text-param-data.js +2 -0
- package/dist/models/ps-text-param-options.d.ts +5 -0
- package/dist/models/ps-text-param-options.js +2 -0
- package/dist/services/ps-cursor-pages-service.d.ts +6 -0
- package/dist/services/ps-cursor-pages-service.js +18 -0
- package/dist/services/ps-draft-state-service.d.ts +6 -0
- package/dist/services/ps-draft-state-service.js +15 -0
- package/dist/services/ps-image-service.d.ts +6 -0
- package/dist/services/ps-image-service.js +15 -0
- package/dist/services/ps-remote-read-service.d.ts +8 -0
- package/dist/services/ps-remote-read-service.js +23 -0
- package/dist/services/ps-signed-value-service.d.ts +5 -0
- package/dist/services/ps-signed-value-service.js +17 -0
- package/package.json +2 -2
- package/dist/constants/ps-optimistic-config.d.ts +0 -5
- package/dist/constants/ps-optimistic-config.js +0 -8
- package/dist/esm/constants/ps-optimistic-config.js +0 -5
- package/dist/esm/hooks/use-ps-change-queue.js +0 -36
- package/dist/esm/hooks/use-ps-debounced-value.js +0 -11
- package/dist/esm/hooks/use-ps-optimistic-rows.js +0 -29
- package/dist/esm/services/ps-deep-equal-service.js +0 -31
- package/dist/esm/services/ps-optimistic-fetcher-service.js +0 -12
- package/dist/esm/services/ps-optimistic-release-service.js +0 -38
- package/dist/esm/services/ps-optimistic-save-service.js +0 -64
- package/dist/hooks/use-ps-change-queue.d.ts +0 -3
- package/dist/hooks/use-ps-change-queue.js +0 -40
- package/dist/hooks/use-ps-debounced-value.d.ts +0 -1
- package/dist/hooks/use-ps-debounced-value.js +0 -15
- package/dist/hooks/use-ps-optimistic-rows.d.ts +0 -3
- package/dist/hooks/use-ps-optimistic-rows.js +0 -33
- package/dist/interfaces/ps-change-queue-input.d.ts +0 -5
- package/dist/interfaces/ps-change-queue-result.d.ts +0 -3
- package/dist/interfaces/ps-optimistic-changes.d.ts +0 -7
- package/dist/interfaces/ps-optimistic-failure-reason.d.ts +0 -1
- package/dist/interfaces/ps-optimistic-outcome.d.ts +0 -5
- package/dist/interfaces/ps-optimistic-rows-input.d.ts +0 -6
- package/dist/interfaces/ps-optimistic-rows-result.d.ts +0 -6
- package/dist/interfaces/ps-optimistic-save-spec.d.ts +0 -11
- package/dist/services/ps-deep-equal-service.d.ts +0 -5
- package/dist/services/ps-deep-equal-service.js +0 -35
- package/dist/services/ps-optimistic-fetcher-service.d.ts +0 -6
- package/dist/services/ps-optimistic-fetcher-service.js +0 -16
- package/dist/services/ps-optimistic-release-service.d.ts +0 -5
- package/dist/services/ps-optimistic-release-service.js +0 -42
- package/dist/services/ps-optimistic-save-service.d.ts +0 -11
- package/dist/services/ps-optimistic-save-service.js +0 -68
- /package/dist/esm/interfaces/{ps-change-queue-input.js → ps-cursor-pages-input.js} +0 -0
- /package/dist/esm/interfaces/{ps-change-queue-result.js → ps-cursor-pages-result.js} +0 -0
- /package/dist/esm/interfaces/{ps-optimistic-changes.js → ps-draft-state-options.js} +0 -0
- /package/dist/esm/interfaces/{ps-optimistic-failure-reason.js → ps-draft-state-result.js} +0 -0
- /package/dist/esm/interfaces/{ps-optimistic-outcome.js → ps-remote-read-input.js} +0 -0
- /package/dist/esm/interfaces/{ps-optimistic-rows-input.js → ps-remote-read-result.js} +0 -0
- /package/dist/esm/{interfaces/ps-optimistic-rows-result.js → models/ps-cursor-pages-state.js} +0 -0
- /package/dist/esm/{interfaces/ps-optimistic-save-spec.js → models/ps-draft-state-data.js} +0 -0
- /package/dist/interfaces/{ps-change-queue-input.js → ps-cursor-pages-input.js} +0 -0
- /package/dist/interfaces/{ps-change-queue-result.js → ps-cursor-pages-result.js} +0 -0
- /package/dist/interfaces/{ps-optimistic-changes.js → ps-draft-state-options.js} +0 -0
- /package/dist/interfaces/{ps-optimistic-failure-reason.js → ps-draft-state-result.js} +0 -0
- /package/dist/interfaces/{ps-optimistic-outcome.js → ps-remote-read-input.js} +0 -0
- /package/dist/interfaces/{ps-optimistic-rows-input.js → ps-remote-read-result.js} +0 -0
- /package/dist/{interfaces/ps-optimistic-rows-result.js → models/ps-cursor-pages-state.js} +0 -0
- /package/dist/{interfaces/ps-optimistic-save-spec.js → models/ps-draft-state-data.js} +0 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Client } from '@pallasoft/ps-utilities';
|
|
2
|
+
export class PsRemoteReadService {
|
|
3
|
+
static initialState() {
|
|
4
|
+
return { data: null, error: null, settled: null };
|
|
5
|
+
}
|
|
6
|
+
static isPending(settled, url, reloadKey) {
|
|
7
|
+
if (url === null)
|
|
8
|
+
return false;
|
|
9
|
+
return settled === null || settled.url !== url || !Object.is(settled.reloadKey, reloadKey);
|
|
10
|
+
}
|
|
11
|
+
static async read(url, parse, signal) {
|
|
12
|
+
const response = await PsRemoteReadService.client.get(url, {
|
|
13
|
+
responseType: 'json',
|
|
14
|
+
signal,
|
|
15
|
+
});
|
|
16
|
+
return parse(response.data);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
PsRemoteReadService.client = Client.HttpService.createApiClient();
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AmountDirection, Common } from '@pallasoft/ps-utilities';
|
|
2
|
+
export class PsSignedValueService {
|
|
3
|
+
static direction(value) {
|
|
4
|
+
const sign = Common.DecimalStringService.sign(value);
|
|
5
|
+
if (sign > 0)
|
|
6
|
+
return AmountDirection.In;
|
|
7
|
+
return sign < 0 ? AmountDirection.Out : AmountDirection.Neutral;
|
|
8
|
+
}
|
|
9
|
+
static text(value, format) {
|
|
10
|
+
const body = format === undefined ? value : format(value);
|
|
11
|
+
return Common.DecimalStringService.sign(value) > 0 ? `+${body}` : body;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.usePsCursorPages = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const ps_cursor_pages_service_1 = require("../services/ps-cursor-pages-service");
|
|
6
|
+
const ps_remote_read_service_1 = require("../services/ps-remote-read-service");
|
|
7
|
+
const usePsCursorPages = (input) => {
|
|
8
|
+
const { reloadKey } = input;
|
|
9
|
+
const firstUrl = input.url(null);
|
|
10
|
+
const [state, setState] = (0, react_1.useState)(() => ps_cursor_pages_service_1.PsCursorPagesService.initialState());
|
|
11
|
+
const inputRef = (0, react_1.useRef)(input);
|
|
12
|
+
const stateRef = (0, react_1.useRef)(state);
|
|
13
|
+
const inflight = (0, react_1.useRef)(null);
|
|
14
|
+
inputRef.current = input;
|
|
15
|
+
stateRef.current = state;
|
|
16
|
+
(0, react_1.useEffect)(() => {
|
|
17
|
+
setState((current) => (current.isLoadingMore ? { ...current, isLoadingMore: false } : current));
|
|
18
|
+
if (firstUrl === null)
|
|
19
|
+
return;
|
|
20
|
+
const controller = new AbortController();
|
|
21
|
+
inflight.current = controller;
|
|
22
|
+
ps_remote_read_service_1.PsRemoteReadService.read(firstUrl, inputRef.current.parse, controller.signal).then((page) => {
|
|
23
|
+
if (controller.signal.aborted)
|
|
24
|
+
return;
|
|
25
|
+
inflight.current = null;
|
|
26
|
+
setState({
|
|
27
|
+
error: null,
|
|
28
|
+
hasMore: ps_cursor_pages_service_1.PsCursorPagesService.hasMore(page.length, inputRef.current.pageSize),
|
|
29
|
+
isLoadingMore: false,
|
|
30
|
+
rows: page,
|
|
31
|
+
settled: { reloadKey, url: firstUrl },
|
|
32
|
+
});
|
|
33
|
+
}, (failure) => {
|
|
34
|
+
if (controller.signal.aborted)
|
|
35
|
+
return;
|
|
36
|
+
inflight.current = null;
|
|
37
|
+
setState({
|
|
38
|
+
error: failure,
|
|
39
|
+
hasMore: false,
|
|
40
|
+
isLoadingMore: false,
|
|
41
|
+
rows: [],
|
|
42
|
+
settled: { reloadKey, url: firstUrl },
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
return () => {
|
|
46
|
+
controller.abort();
|
|
47
|
+
inflight.current = null;
|
|
48
|
+
};
|
|
49
|
+
}, [firstUrl, reloadKey]);
|
|
50
|
+
const loadMore = (0, react_1.useCallback)(() => {
|
|
51
|
+
const current = stateRef.current;
|
|
52
|
+
const latest = inputRef.current;
|
|
53
|
+
if (!current.hasMore || inflight.current !== null)
|
|
54
|
+
return;
|
|
55
|
+
const nextUrl = latest.url(latest.cursorOf(current.rows));
|
|
56
|
+
if (nextUrl === null)
|
|
57
|
+
return;
|
|
58
|
+
const controller = new AbortController();
|
|
59
|
+
inflight.current = controller;
|
|
60
|
+
setState((existing) => ({ ...existing, error: null, isLoadingMore: true }));
|
|
61
|
+
ps_remote_read_service_1.PsRemoteReadService.read(nextUrl, latest.parse, controller.signal).then((page) => {
|
|
62
|
+
if (controller.signal.aborted)
|
|
63
|
+
return;
|
|
64
|
+
inflight.current = null;
|
|
65
|
+
setState((existing) => ({
|
|
66
|
+
...existing,
|
|
67
|
+
hasMore: ps_cursor_pages_service_1.PsCursorPagesService.hasMore(page.length, inputRef.current.pageSize),
|
|
68
|
+
isLoadingMore: false,
|
|
69
|
+
rows: ps_cursor_pages_service_1.PsCursorPagesService.append(existing.rows, page, inputRef.current.keyOf),
|
|
70
|
+
}));
|
|
71
|
+
}, (failure) => {
|
|
72
|
+
if (controller.signal.aborted)
|
|
73
|
+
return;
|
|
74
|
+
inflight.current = null;
|
|
75
|
+
setState((existing) => ({ ...existing, error: failure, isLoadingMore: false }));
|
|
76
|
+
});
|
|
77
|
+
}, []);
|
|
78
|
+
return {
|
|
79
|
+
error: state.error,
|
|
80
|
+
hasMore: state.hasMore,
|
|
81
|
+
isLoading: ps_remote_read_service_1.PsRemoteReadService.isPending(state.settled, firstUrl, reloadKey) || state.isLoadingMore,
|
|
82
|
+
loadMore,
|
|
83
|
+
rows: state.rows,
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
exports.usePsCursorPages = usePsCursorPages;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { PsDraftStateOptions } from '../interfaces/ps-draft-state-options';
|
|
2
|
+
import type { PsDraftStateResult } from '../interfaces/ps-draft-state-result';
|
|
3
|
+
export declare const usePsDraftState: <Value>(initial: Value, options?: PsDraftStateOptions<Value>) => PsDraftStateResult<Value>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.usePsDraftState = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const ps_draft_state_service_1 = require("../services/ps-draft-state-service");
|
|
6
|
+
const usePsDraftState = (initial, options) => {
|
|
7
|
+
const [state, setState] = (0, react_1.useState)(() => ps_draft_state_service_1.PsDraftStateService.fresh(initial));
|
|
8
|
+
const isCurrent = ps_draft_state_service_1.PsDraftStateService.isEqual(initial, state.baseline, options);
|
|
9
|
+
if (!isCurrent)
|
|
10
|
+
setState(ps_draft_state_service_1.PsDraftStateService.fresh(initial));
|
|
11
|
+
const setValue = (0, react_1.useCallback)((next) => setState((current) => ({ ...current, value: next })), []);
|
|
12
|
+
const update = (0, react_1.useCallback)((updater) => setState((current) => ({ ...current, value: updater(current.value) })), []);
|
|
13
|
+
const reset = (0, react_1.useCallback)(() => setState((current) => ({ ...current, value: structuredClone(current.baseline) })), []);
|
|
14
|
+
return {
|
|
15
|
+
isDirty: !ps_draft_state_service_1.PsDraftStateService.isEqual(state.value, state.baseline, options),
|
|
16
|
+
reset,
|
|
17
|
+
setValue,
|
|
18
|
+
update,
|
|
19
|
+
value: state.value,
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
exports.usePsDraftState = usePsDraftState;
|
|
@@ -2,10 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.usePsOptimisticFetcher = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const use_ps_change_queue_1 = require("./use-ps-change-queue");
|
|
8
|
-
const use_ps_optimistic_rows_1 = require("./use-ps-optimistic-rows");
|
|
5
|
+
const ps_utilities_1 = require("@pallasoft/ps-utilities");
|
|
6
|
+
const react_2 = require("@pallasoft/ps-utilities/react");
|
|
9
7
|
const usePsOptimisticFetcher = ({ apply, fetcher, isHolding = false, isSuccess, merge, onError, revalidator, rows, }) => {
|
|
10
8
|
const [isUnsettled, setIsUnsettled] = (0, react_1.useState)(false);
|
|
11
9
|
const submitted = (0, react_1.useRef)(0);
|
|
@@ -14,7 +12,7 @@ const usePsOptimisticFetcher = ({ apply, fetcher, isHolding = false, isSuccess,
|
|
|
14
12
|
const dataBefore = (0, react_1.useRef)(fetcher.data);
|
|
15
13
|
const dataSeen = (0, react_1.useRef)(fetcher.data);
|
|
16
14
|
const failure = (0, react_1.useRef)(null);
|
|
17
|
-
const { forgetLast, remember, rows: shown, } = (0,
|
|
15
|
+
const { forgetLast, remember, rows: shown, } = (0, react_2.usePsOptimisticRows)({
|
|
18
16
|
apply,
|
|
19
17
|
isHolding,
|
|
20
18
|
isSaving: isUnsettled || fetcher.state !== 'idle' || revalidator.state !== 'idle',
|
|
@@ -33,7 +31,7 @@ const usePsOptimisticFetcher = ({ apply, fetcher, isHolding = false, isSuccess,
|
|
|
33
31
|
const done = settle.current;
|
|
34
32
|
settle.current = null;
|
|
35
33
|
sawBusy.current = false;
|
|
36
|
-
done(
|
|
34
|
+
done(ps_utilities_1.PsOptimisticFetcherService.outcome(fetcher.data, dataBefore.current));
|
|
37
35
|
}, [fetcher.data, fetcher.state]);
|
|
38
36
|
(0, react_1.useEffect)(() => () => {
|
|
39
37
|
if (settle.current === null)
|
|
@@ -49,7 +47,7 @@ const usePsOptimisticFetcher = ({ apply, fetcher, isHolding = false, isSuccess,
|
|
|
49
47
|
settle.current = null;
|
|
50
48
|
resolve(outcome);
|
|
51
49
|
};
|
|
52
|
-
const timer = setTimeout(() => finish({ data: undefined, reason: 'timeout' }),
|
|
50
|
+
const timer = setTimeout(() => finish({ data: undefined, reason: 'timeout' }), ps_utilities_1.PsOptimisticConfig.submitTimeoutMs);
|
|
53
51
|
settle.current = finish;
|
|
54
52
|
sawBusy.current = false;
|
|
55
53
|
dataBefore.current = dataSeen.current;
|
|
@@ -64,7 +62,7 @@ const usePsOptimisticFetcher = ({ apply, fetcher, isHolding = false, isSuccess,
|
|
|
64
62
|
failure.current = null;
|
|
65
63
|
for (const submission of merge === undefined ? queued : merge(queued)) {
|
|
66
64
|
const outcome = await submitOne(submission);
|
|
67
|
-
const reason =
|
|
65
|
+
const reason = ps_utilities_1.PsOptimisticFetcherService.failureReason(outcome, isSuccess);
|
|
68
66
|
if (reason !== null) {
|
|
69
67
|
failure.current = { data: outcome.data, reason };
|
|
70
68
|
throw new Error(reason);
|
|
@@ -94,7 +92,7 @@ const usePsOptimisticFetcher = ({ apply, fetcher, isHolding = false, isSuccess,
|
|
|
94
92
|
}
|
|
95
93
|
onError({ ...cause, changes: [...failed, ...dropped] });
|
|
96
94
|
}, [forgetLast, onError]);
|
|
97
|
-
const queue = (0,
|
|
95
|
+
const queue = (0, react_2.usePsChangeQueue)({
|
|
98
96
|
onDrained: revalidate,
|
|
99
97
|
onFailed: forgetFailed,
|
|
100
98
|
send,
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.usePsOptimisticSave = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
|
-
const
|
|
5
|
+
const ps_utilities_1 = require("@pallasoft/ps-utilities");
|
|
6
6
|
const use_ps_optimistic_fetcher_1 = require("./use-ps-optimistic-fetcher");
|
|
7
7
|
const usePsOptimisticSave = ({ fetcher, isSuccess, onError, revalidator, rows, scopeId, spec, }) => {
|
|
8
|
-
const apply = (0, react_1.useCallback)((base, changes) =>
|
|
8
|
+
const apply = (0, react_1.useCallback)((base, changes) => ps_utilities_1.PsOptimisticSaveService.apply(base, changes, spec), [spec]);
|
|
9
9
|
const optimistic = (0, use_ps_optimistic_fetcher_1.usePsOptimisticFetcher)({
|
|
10
10
|
apply,
|
|
11
11
|
fetcher,
|
|
@@ -15,8 +15,8 @@ const usePsOptimisticSave = ({ fetcher, isSuccess, onError, revalidator, rows, s
|
|
|
15
15
|
rows,
|
|
16
16
|
});
|
|
17
17
|
const { submit } = optimistic;
|
|
18
|
-
const save = (0, react_1.useCallback)((values, existingId) => submit(
|
|
19
|
-
const remove = (0, react_1.useCallback)((ids) => submit(
|
|
18
|
+
const save = (0, react_1.useCallback)((values, existingId) => submit(ps_utilities_1.PsOptimisticSaveService.saveValues(spec, values, existingId, scopeId)), [scopeId, spec, submit]);
|
|
19
|
+
const remove = (0, react_1.useCallback)((ids) => submit(ps_utilities_1.PsOptimisticSaveService.removeValues(spec, ids)), [spec, submit]);
|
|
20
20
|
return { remove, rows: optimistic.rows, save };
|
|
21
21
|
};
|
|
22
22
|
exports.usePsOptimisticSave = usePsOptimisticSave;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { PsRemoteReadInput } from '../interfaces/ps-remote-read-input';
|
|
2
|
+
import type { PsRemoteReadResult } from '../interfaces/ps-remote-read-result';
|
|
3
|
+
export declare const usePsRemoteRead: <Data>({ parse, reloadKey, url, }: PsRemoteReadInput<Data>) => PsRemoteReadResult<Data>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.usePsRemoteRead = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const ps_remote_read_service_1 = require("../services/ps-remote-read-service");
|
|
6
|
+
const usePsRemoteRead = ({ parse, reloadKey, url, }) => {
|
|
7
|
+
const [state, setState] = (0, react_1.useState)(() => ps_remote_read_service_1.PsRemoteReadService.initialState());
|
|
8
|
+
const parseRef = (0, react_1.useRef)(parse);
|
|
9
|
+
parseRef.current = parse;
|
|
10
|
+
(0, react_1.useEffect)(() => {
|
|
11
|
+
if (url === null)
|
|
12
|
+
return;
|
|
13
|
+
const controller = new AbortController();
|
|
14
|
+
ps_remote_read_service_1.PsRemoteReadService.read(url, parseRef.current, controller.signal).then((data) => {
|
|
15
|
+
if (controller.signal.aborted)
|
|
16
|
+
return;
|
|
17
|
+
setState({ data, error: null, settled: { reloadKey, url } });
|
|
18
|
+
}, (failure) => {
|
|
19
|
+
if (controller.signal.aborted)
|
|
20
|
+
return;
|
|
21
|
+
setState((current) => ({
|
|
22
|
+
data: current.data,
|
|
23
|
+
error: failure,
|
|
24
|
+
settled: { reloadKey, url },
|
|
25
|
+
}));
|
|
26
|
+
});
|
|
27
|
+
return () => controller.abort();
|
|
28
|
+
}, [reloadKey, url]);
|
|
29
|
+
return {
|
|
30
|
+
data: state.data,
|
|
31
|
+
error: state.error,
|
|
32
|
+
isLoading: ps_remote_read_service_1.PsRemoteReadService.isPending(state.settled, url, reloadKey),
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
exports.usePsRemoteRead = usePsRemoteRead;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { PsSearchParamsState } from '../models/ps-search-params-state';
|
|
2
|
+
import type { PsTextParamData } from '../models/ps-text-param-data';
|
|
3
|
+
import type { PsTextParamOptions } from '../models/ps-text-param-options';
|
|
4
|
+
export declare const usePsTextParam: ([searchParams, setSearchParams]: PsSearchParamsState, { debounceMs, name, resetParams }: PsTextParamOptions) => PsTextParamData;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.usePsTextParam = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const react_2 = require("@pallasoft/ps-utilities/react");
|
|
6
|
+
const ps_query_param_config_1 = require("../constants/ps-query-param-config");
|
|
7
|
+
const ps_query_param_service_1 = require("../services/ps-query-param-service");
|
|
8
|
+
const usePsTextParam = ([searchParams, setSearchParams], { debounceMs, name, resetParams }) => {
|
|
9
|
+
const raw = searchParams.get(name);
|
|
10
|
+
const committed = raw === null ? '' : raw;
|
|
11
|
+
const [value, setValue] = (0, react_1.useState)(committed);
|
|
12
|
+
const settled = (0, react_2.usePsDebouncedValue)(value, debounceMs);
|
|
13
|
+
(0, react_1.useEffect)(() => {
|
|
14
|
+
if (settled === committed)
|
|
15
|
+
return;
|
|
16
|
+
setSearchParams((current) => ps_query_param_service_1.PsQueryParamService.withChoice(current, name, settled, '', resetParams), ps_query_param_config_1.PsQueryParamConfig.setOptions);
|
|
17
|
+
}, [settled]);
|
|
18
|
+
return { committed, onChange: setValue, value };
|
|
19
|
+
};
|
|
20
|
+
exports.usePsTextParam = usePsTextParam;
|
package/dist/index.d.ts
CHANGED
|
@@ -90,21 +90,13 @@ export * from './interfaces/ps-component-props';
|
|
|
90
90
|
export * from './models/ps-element-size';
|
|
91
91
|
export * from './models/ps-voice-orb';
|
|
92
92
|
export * from './models/ps-navigation-progress';
|
|
93
|
-
export * from './hooks/use-ps-debounced-value';
|
|
94
|
-
export * from './hooks/use-ps-change-queue';
|
|
95
|
-
export * from './interfaces/ps-change-queue-input';
|
|
96
|
-
export * from './interfaces/ps-change-queue-result';
|
|
97
93
|
export * from './hooks/use-ps-live';
|
|
98
94
|
export * from './hooks/use-ps-debounced-revalidate';
|
|
99
|
-
export * from './hooks/use-ps-optimistic-rows';
|
|
100
95
|
export * from './hooks/use-ps-optimistic-fetcher';
|
|
101
96
|
export * from './hooks/use-ps-optimistic-save';
|
|
102
|
-
export * from './constants/ps-optimistic-config';
|
|
103
97
|
export * from './interfaces/ps-optimistic-save-input';
|
|
104
98
|
export * from './interfaces/ps-optimistic-save-result';
|
|
105
|
-
export * from './interfaces/ps-optimistic-save-spec';
|
|
106
99
|
export * from './interfaces/ps-revalidation-args';
|
|
107
|
-
export * from './services/ps-optimistic-save-service';
|
|
108
100
|
export * from './services/ps-client-param-revalidation-service';
|
|
109
101
|
export * from './interfaces/ps-fetcher-like';
|
|
110
102
|
export * from './interfaces/ps-fetcher-submit-options';
|
|
@@ -114,10 +106,7 @@ export * from './interfaces/ps-live-open-options';
|
|
|
114
106
|
export * from './interfaces/ps-optimistic-fetcher-input';
|
|
115
107
|
export * from './interfaces/ps-optimistic-fetcher-result';
|
|
116
108
|
export * from './interfaces/ps-optimistic-failure';
|
|
117
|
-
export * from './interfaces/ps-optimistic-failure-reason';
|
|
118
109
|
export * from './interfaces/ps-revalidator-like';
|
|
119
|
-
export * from './interfaces/ps-optimistic-rows-input';
|
|
120
|
-
export * from './interfaces/ps-optimistic-rows-result';
|
|
121
110
|
export * from './hooks/use-ps-navigation-progress';
|
|
122
111
|
export * from './models/ps-draggable-grid';
|
|
123
112
|
export * from './constants/ps-draggable-grid';
|
|
@@ -132,7 +121,6 @@ export * from './constants/ps-data-boundary-variant';
|
|
|
132
121
|
export * from './hooks/use-ps-retained-promise';
|
|
133
122
|
export * from './hooks/use-ps-promise-value';
|
|
134
123
|
export * from './interfaces/ps-retained-promise-data';
|
|
135
|
-
export * from './services/ps-deep-equal-service';
|
|
136
124
|
export * from './components/ps-faq-answer';
|
|
137
125
|
export * from './components/ps-feature-grid';
|
|
138
126
|
export * from './components/ps-feature-card';
|
|
@@ -228,3 +216,35 @@ export * from './hooks/use-ps-choice-param';
|
|
|
228
216
|
export * from './hooks/use-ps-flag-param';
|
|
229
217
|
export * from './constants/ps-rerender-config';
|
|
230
218
|
export * from './hooks/use-ps-rerender-at';
|
|
219
|
+
export * from './models/ps-remote-settled-data';
|
|
220
|
+
export * from './models/ps-remote-read-state';
|
|
221
|
+
export * from './interfaces/ps-remote-read-input';
|
|
222
|
+
export * from './interfaces/ps-remote-read-result';
|
|
223
|
+
export * from './services/ps-remote-read-service';
|
|
224
|
+
export * from './hooks/use-ps-remote-read';
|
|
225
|
+
export * from './interfaces/ps-cursor-pages-input';
|
|
226
|
+
export * from './interfaces/ps-cursor-pages-result';
|
|
227
|
+
export * from './models/ps-cursor-pages-state';
|
|
228
|
+
export * from './services/ps-cursor-pages-service';
|
|
229
|
+
export * from './hooks/use-ps-cursor-pages';
|
|
230
|
+
export * from './models/ps-text-param-options';
|
|
231
|
+
export * from './models/ps-text-param-data';
|
|
232
|
+
export * from './hooks/use-ps-text-param';
|
|
233
|
+
export * from './interfaces/ps-draft-state-options';
|
|
234
|
+
export * from './interfaces/ps-draft-state-result';
|
|
235
|
+
export * from './models/ps-draft-state-data';
|
|
236
|
+
export * from './services/ps-draft-state-service';
|
|
237
|
+
export * from './hooks/use-ps-draft-state';
|
|
238
|
+
export * from './constants/ps-empty-value-config';
|
|
239
|
+
export * from './components/ps-empty-value';
|
|
240
|
+
export * from './constants/ps-signed-value-classes';
|
|
241
|
+
export * from './services/ps-signed-value-service';
|
|
242
|
+
export * from './components/ps-signed-value';
|
|
243
|
+
export * from './constants/ps-image-status';
|
|
244
|
+
export * from './constants/ps-image-fit';
|
|
245
|
+
export * from './constants/ps-image-config';
|
|
246
|
+
export * from './models/ps-image-state-data';
|
|
247
|
+
export * from './services/ps-image-service';
|
|
248
|
+
export * from './components/ps-image';
|
|
249
|
+
export { PsDeepEqualService, PsOptimisticConfig, PsOptimisticSaveService, type PsOptimisticFailureReason, type PsOptimisticSaveSpec, } from '@pallasoft/ps-utilities';
|
|
250
|
+
export { usePsChangeQueue, usePsDebouncedValue, usePsOptimisticRows, type PsChangeQueueInput, type PsChangeQueueResult, type PsOptimisticRowsInput, type PsOptimisticRowsResult, } from '@pallasoft/ps-utilities/react';
|
package/dist/index.js
CHANGED
|
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.usePsOptimisticRows = exports.usePsDebouncedValue = exports.usePsChangeQueue = exports.PsOptimisticSaveService = exports.PsOptimisticConfig = exports.PsDeepEqualService = void 0;
|
|
17
18
|
__exportStar(require("./components/ps-layer"), exports);
|
|
18
19
|
__exportStar(require("./components/ps-accordion"), exports);
|
|
19
20
|
__exportStar(require("./components/ps-action-tile"), exports);
|
|
@@ -106,21 +107,13 @@ __exportStar(require("./interfaces/ps-component-props"), exports);
|
|
|
106
107
|
__exportStar(require("./models/ps-element-size"), exports);
|
|
107
108
|
__exportStar(require("./models/ps-voice-orb"), exports);
|
|
108
109
|
__exportStar(require("./models/ps-navigation-progress"), exports);
|
|
109
|
-
__exportStar(require("./hooks/use-ps-debounced-value"), exports);
|
|
110
|
-
__exportStar(require("./hooks/use-ps-change-queue"), exports);
|
|
111
|
-
__exportStar(require("./interfaces/ps-change-queue-input"), exports);
|
|
112
|
-
__exportStar(require("./interfaces/ps-change-queue-result"), exports);
|
|
113
110
|
__exportStar(require("./hooks/use-ps-live"), exports);
|
|
114
111
|
__exportStar(require("./hooks/use-ps-debounced-revalidate"), exports);
|
|
115
|
-
__exportStar(require("./hooks/use-ps-optimistic-rows"), exports);
|
|
116
112
|
__exportStar(require("./hooks/use-ps-optimistic-fetcher"), exports);
|
|
117
113
|
__exportStar(require("./hooks/use-ps-optimistic-save"), exports);
|
|
118
|
-
__exportStar(require("./constants/ps-optimistic-config"), exports);
|
|
119
114
|
__exportStar(require("./interfaces/ps-optimistic-save-input"), exports);
|
|
120
115
|
__exportStar(require("./interfaces/ps-optimistic-save-result"), exports);
|
|
121
|
-
__exportStar(require("./interfaces/ps-optimistic-save-spec"), exports);
|
|
122
116
|
__exportStar(require("./interfaces/ps-revalidation-args"), exports);
|
|
123
|
-
__exportStar(require("./services/ps-optimistic-save-service"), exports);
|
|
124
117
|
__exportStar(require("./services/ps-client-param-revalidation-service"), exports);
|
|
125
118
|
__exportStar(require("./interfaces/ps-fetcher-like"), exports);
|
|
126
119
|
__exportStar(require("./interfaces/ps-fetcher-submit-options"), exports);
|
|
@@ -130,10 +123,7 @@ __exportStar(require("./interfaces/ps-live-open-options"), exports);
|
|
|
130
123
|
__exportStar(require("./interfaces/ps-optimistic-fetcher-input"), exports);
|
|
131
124
|
__exportStar(require("./interfaces/ps-optimistic-fetcher-result"), exports);
|
|
132
125
|
__exportStar(require("./interfaces/ps-optimistic-failure"), exports);
|
|
133
|
-
__exportStar(require("./interfaces/ps-optimistic-failure-reason"), exports);
|
|
134
126
|
__exportStar(require("./interfaces/ps-revalidator-like"), exports);
|
|
135
|
-
__exportStar(require("./interfaces/ps-optimistic-rows-input"), exports);
|
|
136
|
-
__exportStar(require("./interfaces/ps-optimistic-rows-result"), exports);
|
|
137
127
|
__exportStar(require("./hooks/use-ps-navigation-progress"), exports);
|
|
138
128
|
__exportStar(require("./models/ps-draggable-grid"), exports);
|
|
139
129
|
__exportStar(require("./constants/ps-draggable-grid"), exports);
|
|
@@ -148,7 +138,6 @@ __exportStar(require("./constants/ps-data-boundary-variant"), exports);
|
|
|
148
138
|
__exportStar(require("./hooks/use-ps-retained-promise"), exports);
|
|
149
139
|
__exportStar(require("./hooks/use-ps-promise-value"), exports);
|
|
150
140
|
__exportStar(require("./interfaces/ps-retained-promise-data"), exports);
|
|
151
|
-
__exportStar(require("./services/ps-deep-equal-service"), exports);
|
|
152
141
|
__exportStar(require("./components/ps-faq-answer"), exports);
|
|
153
142
|
__exportStar(require("./components/ps-feature-grid"), exports);
|
|
154
143
|
__exportStar(require("./components/ps-feature-card"), exports);
|
|
@@ -244,3 +233,41 @@ __exportStar(require("./hooks/use-ps-choice-param"), exports);
|
|
|
244
233
|
__exportStar(require("./hooks/use-ps-flag-param"), exports);
|
|
245
234
|
__exportStar(require("./constants/ps-rerender-config"), exports);
|
|
246
235
|
__exportStar(require("./hooks/use-ps-rerender-at"), exports);
|
|
236
|
+
__exportStar(require("./models/ps-remote-settled-data"), exports);
|
|
237
|
+
__exportStar(require("./models/ps-remote-read-state"), exports);
|
|
238
|
+
__exportStar(require("./interfaces/ps-remote-read-input"), exports);
|
|
239
|
+
__exportStar(require("./interfaces/ps-remote-read-result"), exports);
|
|
240
|
+
__exportStar(require("./services/ps-remote-read-service"), exports);
|
|
241
|
+
__exportStar(require("./hooks/use-ps-remote-read"), exports);
|
|
242
|
+
__exportStar(require("./interfaces/ps-cursor-pages-input"), exports);
|
|
243
|
+
__exportStar(require("./interfaces/ps-cursor-pages-result"), exports);
|
|
244
|
+
__exportStar(require("./models/ps-cursor-pages-state"), exports);
|
|
245
|
+
__exportStar(require("./services/ps-cursor-pages-service"), exports);
|
|
246
|
+
__exportStar(require("./hooks/use-ps-cursor-pages"), exports);
|
|
247
|
+
__exportStar(require("./models/ps-text-param-options"), exports);
|
|
248
|
+
__exportStar(require("./models/ps-text-param-data"), exports);
|
|
249
|
+
__exportStar(require("./hooks/use-ps-text-param"), exports);
|
|
250
|
+
__exportStar(require("./interfaces/ps-draft-state-options"), exports);
|
|
251
|
+
__exportStar(require("./interfaces/ps-draft-state-result"), exports);
|
|
252
|
+
__exportStar(require("./models/ps-draft-state-data"), exports);
|
|
253
|
+
__exportStar(require("./services/ps-draft-state-service"), exports);
|
|
254
|
+
__exportStar(require("./hooks/use-ps-draft-state"), exports);
|
|
255
|
+
__exportStar(require("./constants/ps-empty-value-config"), exports);
|
|
256
|
+
__exportStar(require("./components/ps-empty-value"), exports);
|
|
257
|
+
__exportStar(require("./constants/ps-signed-value-classes"), exports);
|
|
258
|
+
__exportStar(require("./services/ps-signed-value-service"), exports);
|
|
259
|
+
__exportStar(require("./components/ps-signed-value"), exports);
|
|
260
|
+
__exportStar(require("./constants/ps-image-status"), exports);
|
|
261
|
+
__exportStar(require("./constants/ps-image-fit"), exports);
|
|
262
|
+
__exportStar(require("./constants/ps-image-config"), exports);
|
|
263
|
+
__exportStar(require("./models/ps-image-state-data"), exports);
|
|
264
|
+
__exportStar(require("./services/ps-image-service"), exports);
|
|
265
|
+
__exportStar(require("./components/ps-image"), exports);
|
|
266
|
+
var ps_utilities_1 = require("@pallasoft/ps-utilities");
|
|
267
|
+
Object.defineProperty(exports, "PsDeepEqualService", { enumerable: true, get: function () { return ps_utilities_1.PsDeepEqualService; } });
|
|
268
|
+
Object.defineProperty(exports, "PsOptimisticConfig", { enumerable: true, get: function () { return ps_utilities_1.PsOptimisticConfig; } });
|
|
269
|
+
Object.defineProperty(exports, "PsOptimisticSaveService", { enumerable: true, get: function () { return ps_utilities_1.PsOptimisticSaveService; } });
|
|
270
|
+
var react_1 = require("@pallasoft/ps-utilities/react");
|
|
271
|
+
Object.defineProperty(exports, "usePsChangeQueue", { enumerable: true, get: function () { return react_1.usePsChangeQueue; } });
|
|
272
|
+
Object.defineProperty(exports, "usePsDebouncedValue", { enumerable: true, get: function () { return react_1.usePsDebouncedValue; } });
|
|
273
|
+
Object.defineProperty(exports, "usePsOptimisticRows", { enumerable: true, get: function () { return react_1.usePsOptimisticRows; } });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import type { PsOptimisticSaveSpec } from '@pallasoft/ps-utilities';
|
|
1
2
|
import type { PsFetcherLike } from './ps-fetcher-like';
|
|
2
3
|
import type { PsOptimisticFailure } from './ps-optimistic-failure';
|
|
3
|
-
import type { PsOptimisticSaveSpec } from './ps-optimistic-save-spec';
|
|
4
4
|
import type { PsRevalidatorLike } from './ps-revalidator-like';
|
|
5
5
|
export interface PsOptimisticSaveInput<Row, Values, Data> {
|
|
6
6
|
fetcher: PsFetcherLike<Data>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { PsCursorPagesState } from '../models/ps-cursor-pages-state';
|
|
2
|
+
export declare class PsCursorPagesService {
|
|
3
|
+
static append<Row>(existing: Row[], page: Row[], keyOf?: (row: Row) => string): Row[];
|
|
4
|
+
static hasMore(pageLength: number, pageSize: number): boolean;
|
|
5
|
+
static initialState<Row>(): PsCursorPagesState<Row>;
|
|
6
|
+
}
|