@qiaopeng/tanstack-query-plus 0.5.9 → 0.5.10
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/README.md +86 -55
- package/dist/{types/base.d.ts → base-CHnwqfyz.d.cts} +12 -14
- package/dist/base-CHnwqfyz.d.ts +52 -0
- package/dist/chunk-52ZO6Y67.cjs +1121 -0
- package/dist/chunk-52ZO6Y67.cjs.map +1 -0
- package/dist/chunk-5J6OXSLW.cjs +36 -0
- package/dist/chunk-5J6OXSLW.cjs.map +1 -0
- package/dist/chunk-6MAYHLTE.cjs +310 -0
- package/dist/chunk-6MAYHLTE.cjs.map +1 -0
- package/dist/chunk-ADS2QTMP.js +144 -0
- package/dist/chunk-ADS2QTMP.js.map +1 -0
- package/dist/chunk-APXNNHBD.cjs +374 -0
- package/dist/chunk-APXNNHBD.cjs.map +1 -0
- package/dist/chunk-AXMWOGNX.js +134 -0
- package/dist/chunk-AXMWOGNX.js.map +1 -0
- package/dist/chunk-B4KO3K3E.cjs +521 -0
- package/dist/chunk-B4KO3K3E.cjs.map +1 -0
- package/dist/chunk-BK3OTIBD.cjs +15 -0
- package/dist/chunk-BK3OTIBD.cjs.map +1 -0
- package/dist/chunk-BYAOQALW.js +13 -0
- package/dist/chunk-BYAOQALW.js.map +1 -0
- package/dist/chunk-CRTVS7VI.cjs +162 -0
- package/dist/chunk-CRTVS7VI.cjs.map +1 -0
- package/dist/chunk-EXITP7QO.js +288 -0
- package/dist/chunk-EXITP7QO.js.map +1 -0
- package/dist/chunk-GMO3PRZZ.js +565 -0
- package/dist/chunk-GMO3PRZZ.js.map +1 -0
- package/dist/chunk-HRO2DWKZ.js +12 -0
- package/dist/chunk-HRO2DWKZ.js.map +1 -0
- package/dist/chunk-JHDKUQSB.js +1069 -0
- package/dist/chunk-JHDKUQSB.js.map +1 -0
- package/dist/chunk-JN2Y6RSY.js +23 -0
- package/dist/chunk-JN2Y6RSY.js.map +1 -0
- package/dist/chunk-JRJSKRZW.cjs +29 -0
- package/dist/chunk-JRJSKRZW.cjs.map +1 -0
- package/dist/chunk-KC62H4VJ.js +123 -0
- package/dist/chunk-KC62H4VJ.js.map +1 -0
- package/dist/chunk-LHEHSLD5.js +31 -0
- package/dist/chunk-LHEHSLD5.js.map +1 -0
- package/dist/chunk-N4264P7N.cjs +156 -0
- package/dist/chunk-N4264P7N.cjs.map +1 -0
- package/dist/chunk-NF5QYPYC.cjs +133 -0
- package/dist/chunk-NF5QYPYC.cjs.map +1 -0
- package/dist/chunk-OFLCHKKE.cjs +28 -0
- package/dist/chunk-OFLCHKKE.cjs.map +1 -0
- package/dist/chunk-PCNSWVA5.cjs +602 -0
- package/dist/chunk-PCNSWVA5.cjs.map +1 -0
- package/dist/chunk-STOMAA2X.js +85 -0
- package/dist/chunk-STOMAA2X.js.map +1 -0
- package/dist/chunk-UVF5S6LX.cjs +15 -0
- package/dist/chunk-UVF5S6LX.cjs.map +1 -0
- package/dist/chunk-WEIXCDCA.cjs +90 -0
- package/dist/chunk-WEIXCDCA.cjs.map +1 -0
- package/dist/chunk-X3ZTSLBQ.js +355 -0
- package/dist/chunk-X3ZTSLBQ.js.map +1 -0
- package/dist/chunk-YEV73J4J.js +504 -0
- package/dist/chunk-YEV73J4J.js.map +1 -0
- package/dist/chunk-YW5PNTRU.cjs +14 -0
- package/dist/chunk-YW5PNTRU.cjs.map +1 -0
- package/dist/chunk-ZNXSWUIS.js +12 -0
- package/dist/chunk-ZNXSWUIS.js.map +1 -0
- package/dist/chunk-ZUEMBY4W.js +21 -0
- package/dist/chunk-ZUEMBY4W.js.map +1 -0
- package/dist/components/index.cjs +60 -0
- package/dist/components/index.cjs.map +1 -0
- package/dist/components/index.d.cts +43 -0
- package/dist/components/index.d.ts +43 -4
- package/dist/components/index.js +3 -4
- package/dist/components/index.js.map +1 -0
- package/dist/core/devtools.cjs +25 -0
- package/dist/core/devtools.cjs.map +1 -0
- package/dist/core/devtools.d.cts +17 -0
- package/dist/core/devtools.d.ts +9 -7
- package/dist/core/devtools.js +4 -16
- package/dist/core/devtools.js.map +1 -0
- package/dist/core/index.cjs +220 -0
- package/dist/core/index.cjs.map +1 -0
- package/dist/core/index.d.cts +196 -0
- package/dist/core/index.d.ts +196 -9
- package/dist/core/index.js +7 -8
- package/dist/core/index.js.map +1 -0
- package/dist/features/index.cjs +76 -0
- package/dist/features/index.cjs.map +1 -0
- package/dist/features/index.d.cts +86 -0
- package/dist/features/index.d.ts +86 -4
- package/dist/features/index.js +7 -3
- package/dist/features/index.js.map +1 -0
- package/dist/hooks/index.cjs +209 -0
- package/dist/hooks/index.cjs.map +1 -0
- package/dist/hooks/index.d.cts +377 -0
- package/dist/hooks/index.d.ts +377 -10
- package/dist/hooks/index.js +8 -9
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/useInViewPrefetch.cjs +33 -0
- package/dist/hooks/useInViewPrefetch.cjs.map +1 -0
- package/dist/hooks/useInViewPrefetch.d.cts +12 -0
- package/dist/hooks/useInViewPrefetch.d.ts +6 -4
- package/dist/hooks/useInViewPrefetch.js +30 -20
- package/dist/hooks/useInViewPrefetch.js.map +1 -0
- package/dist/index.cjs +811 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +36 -0
- package/dist/index.d.ts +36 -8
- package/dist/index.js +89 -7
- package/dist/index.js.map +1 -0
- package/dist/{types/offline.d.ts → offline-DVPtgoAS.d.ts} +15 -13
- package/dist/offline-xxeA_-6V.d.cts +99 -0
- package/dist/persistence-MRtkmhqq.d.cts +216 -0
- package/dist/persistence-tIrEb0pR.d.ts +216 -0
- package/dist/react-query/index.cjs +52 -0
- package/dist/react-query/index.cjs.map +1 -0
- package/dist/react-query/index.d.cts +1 -0
- package/dist/react-query/index.d.ts +1 -3
- package/dist/react-query/index.js +3 -1
- package/dist/react-query/index.js.map +1 -0
- package/dist/types/index.cjs +43 -0
- package/dist/types/index.cjs.map +1 -0
- package/dist/types/index.d.cts +157 -0
- package/dist/types/index.d.ts +116 -12
- package/dist/types/index.js +6 -8
- package/dist/types/index.js.map +1 -0
- package/dist/utils/index.cjs +234 -0
- package/dist/utils/index.cjs.map +1 -0
- package/dist/utils/index.d.cts +272 -0
- package/dist/utils/index.d.ts +272 -10
- package/dist/utils/index.js +9 -9
- package/dist/utils/index.js.map +1 -0
- package/package.json +13 -3
- package/dist/PersistQueryClientProvider.d.ts +0 -22
- package/dist/PersistQueryClientProvider.d.ts.map +0 -1
- package/dist/PersistQueryClientProvider.js +0 -57
- package/dist/components/LoadingFallback.d.ts +0 -16
- package/dist/components/LoadingFallback.d.ts.map +0 -1
- package/dist/components/LoadingFallback.js +0 -27
- package/dist/components/QueryErrorBoundary.d.ts +0 -12
- package/dist/components/QueryErrorBoundary.d.ts.map +0 -1
- package/dist/components/QueryErrorBoundary.js +0 -9
- package/dist/components/SuspenseWrapper.d.ts +0 -14
- package/dist/components/SuspenseWrapper.d.ts.map +0 -1
- package/dist/components/SuspenseWrapper.js +0 -9
- package/dist/components/index.d.ts.map +0 -1
- package/dist/components/internal/ErrorBoundary.d.ts +0 -27
- package/dist/components/internal/ErrorBoundary.d.ts.map +0 -1
- package/dist/components/internal/ErrorBoundary.js +0 -37
- package/dist/core/config.d.ts +0 -80
- package/dist/core/config.d.ts.map +0 -1
- package/dist/core/config.js +0 -327
- package/dist/core/devtools.d.ts.map +0 -1
- package/dist/core/env.d.ts +0 -4
- package/dist/core/env.d.ts.map +0 -1
- package/dist/core/env.js +0 -26
- package/dist/core/focusManager.d.ts +0 -33
- package/dist/core/focusManager.d.ts.map +0 -1
- package/dist/core/focusManager.js +0 -122
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/keys.d.ts +0 -59
- package/dist/core/keys.d.ts.map +0 -1
- package/dist/core/keys.js +0 -107
- package/dist/core/queryOptions.d.ts +0 -19
- package/dist/core/queryOptions.d.ts.map +0 -1
- package/dist/core/queryOptions.js +0 -32
- package/dist/features/index.d.ts.map +0 -1
- package/dist/features/offline.d.ts +0 -49
- package/dist/features/offline.d.ts.map +0 -1
- package/dist/features/offline.js +0 -300
- package/dist/features/persistence.d.ts +0 -36
- package/dist/features/persistence.d.ts.map +0 -1
- package/dist/features/persistence.js +0 -187
- package/dist/hooks/batchQueries.d.ts +0 -129
- package/dist/hooks/batchQueries.d.ts.map +0 -1
- package/dist/hooks/batchQueries.js +0 -301
- package/dist/hooks/index.d.ts.map +0 -1
- package/dist/hooks/useDataGuardMutation.d.ts +0 -39
- package/dist/hooks/useDataGuardMutation.d.ts.map +0 -1
- package/dist/hooks/useDataGuardMutation.js +0 -137
- package/dist/hooks/useDataGuardQuery.d.ts +0 -28
- package/dist/hooks/useDataGuardQuery.d.ts.map +0 -1
- package/dist/hooks/useDataGuardQuery.js +0 -71
- package/dist/hooks/useFocusManager.d.ts +0 -41
- package/dist/hooks/useFocusManager.d.ts.map +0 -1
- package/dist/hooks/useFocusManager.js +0 -109
- package/dist/hooks/useInViewPrefetch.d.ts.map +0 -1
- package/dist/hooks/useInfiniteQuery.d.ts +0 -33
- package/dist/hooks/useInfiniteQuery.d.ts.map +0 -1
- package/dist/hooks/useInfiniteQuery.js +0 -61
- package/dist/hooks/useMutation.d.ts +0 -25
- package/dist/hooks/useMutation.d.ts.map +0 -1
- package/dist/hooks/useMutation.js +0 -180
- package/dist/hooks/usePrefetch.d.ts +0 -54
- package/dist/hooks/usePrefetch.d.ts.map +0 -1
- package/dist/hooks/usePrefetch.js +0 -229
- package/dist/hooks/useQuery.d.ts +0 -21
- package/dist/hooks/useQuery.d.ts.map +0 -1
- package/dist/hooks/useQuery.js +0 -46
- package/dist/hooks/useSuspenseQuery.d.ts +0 -11
- package/dist/hooks/useSuspenseQuery.d.ts.map +0 -1
- package/dist/hooks/useSuspenseQuery.js +0 -19
- package/dist/index.d.ts.map +0 -1
- package/dist/react-query/index.d.ts.map +0 -1
- package/dist/types/base.d.ts.map +0 -1
- package/dist/types/base.js +0 -26
- package/dist/types/dataGuard.d.ts +0 -69
- package/dist/types/dataGuard.d.ts.map +0 -1
- package/dist/types/dataGuard.js +0 -10
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/infinite.d.ts +0 -39
- package/dist/types/infinite.d.ts.map +0 -1
- package/dist/types/infinite.js +0 -1
- package/dist/types/offline.d.ts.map +0 -1
- package/dist/types/offline.js +0 -8
- package/dist/types/optimistic.d.ts +0 -126
- package/dist/types/optimistic.d.ts.map +0 -1
- package/dist/types/optimistic.js +0 -7
- package/dist/types/persistence.d.ts +0 -9
- package/dist/types/persistence.d.ts.map +0 -1
- package/dist/types/persistence.js +0 -1
- package/dist/types/selectors.d.ts +0 -11
- package/dist/types/selectors.d.ts.map +0 -1
- package/dist/types/selectors.js +0 -1
- package/dist/types/suspense.d.ts +0 -67
- package/dist/types/suspense.d.ts.map +0 -1
- package/dist/types/suspense.js +0 -1
- package/dist/utils/dataGuard.d.ts +0 -37
- package/dist/utils/dataGuard.d.ts.map +0 -1
- package/dist/utils/dataGuard.js +0 -251
- package/dist/utils/fieldMapper.d.ts +0 -9
- package/dist/utils/fieldMapper.d.ts.map +0 -1
- package/dist/utils/fieldMapper.js +0 -27
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/network.d.ts +0 -9
- package/dist/utils/network.d.ts.map +0 -1
- package/dist/utils/network.js +0 -43
- package/dist/utils/optimisticUtils.d.ts +0 -45
- package/dist/utils/optimisticUtils.d.ts.map +0 -1
- package/dist/utils/optimisticUtils.js +0 -116
- package/dist/utils/placeholderData.d.ts +0 -3
- package/dist/utils/placeholderData.d.ts.map +0 -1
- package/dist/utils/placeholderData.js +0 -28
- package/dist/utils/prefetchManager.d.ts +0 -111
- package/dist/utils/prefetchManager.d.ts.map +0 -1
- package/dist/utils/prefetchManager.js +0 -246
- package/dist/utils/queryKey.d.ts +0 -26
- package/dist/utils/queryKey.d.ts.map +0 -1
- package/dist/utils/queryKey.js +0 -89
- package/dist/utils/selectors.d.ts +0 -30
- package/dist/utils/selectors.d.ts.map +0 -1
- package/dist/utils/selectors.js +0 -18
- package/dist/utils/storage.d.ts +0 -7
- package/dist/utils/storage.d.ts.map +0 -1
- package/dist/utils/storage.js +0 -84
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,10 +1,272 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { QueryClient, QueryKey, QueryFunction } from '@tanstack/react-query';
|
|
2
|
+
export { keepPreviousData } from '@tanstack/react-query';
|
|
3
|
+
import { N as NetworkInformation, S as StorageType } from '../base-CHnwqfyz.js';
|
|
4
|
+
import { s as EntityWithId, O as OptimisticUpdateConfig, g as ListOperationType, L as ListOperationConfig, P as PaginatedData, q as StorageInfo, V as VersionedEntity, a as VersionedPaginatedResponse, c as DataGuardOptions, D as DataGuardStrategy } from '../persistence-tIrEb0pR.js';
|
|
5
|
+
|
|
6
|
+
interface FieldMappingConfig {
|
|
7
|
+
nameField: string;
|
|
8
|
+
configKey: string;
|
|
9
|
+
}
|
|
10
|
+
declare function createFieldEnricher<T = any>(queryKey: any, mappings: Record<string, FieldMappingConfig>): (data: T, queryClient: QueryClient) => T;
|
|
11
|
+
declare function createTempId(prefix?: string): string;
|
|
12
|
+
declare function createOptimisticBase(customFields?: Record<string, any>): Record<string, any>;
|
|
13
|
+
|
|
14
|
+
interface NavigatorWithConnection extends Navigator {
|
|
15
|
+
connection?: NetworkInformation;
|
|
16
|
+
}
|
|
17
|
+
declare function isSlowNetwork(): boolean;
|
|
18
|
+
declare function getNetworkInfo(): NetworkInformation | null;
|
|
19
|
+
declare function isFastNetwork(): boolean;
|
|
20
|
+
declare function getNetworkSpeed(): "fast" | "medium" | "slow" | "unknown";
|
|
21
|
+
|
|
22
|
+
declare const listUpdater: {
|
|
23
|
+
add: <T extends EntityWithId>(items: T[] | undefined, newItem: T) => T[];
|
|
24
|
+
update: <T extends EntityWithId>(items: T[] | undefined, updatedItem: Partial<T> & {
|
|
25
|
+
id: T["id"];
|
|
26
|
+
}) => T[];
|
|
27
|
+
remove: <T extends EntityWithId>(items: T[] | undefined, itemId: T["id"]) => T[];
|
|
28
|
+
};
|
|
29
|
+
declare function createAddItemConfig<T extends EntityWithId>(queryKey: QueryKey, options?: {
|
|
30
|
+
addToTop?: boolean;
|
|
31
|
+
onRollback?: (error: Error) => void;
|
|
32
|
+
}): OptimisticUpdateConfig<T[], T>;
|
|
33
|
+
declare function createUpdateItemConfig<T extends EntityWithId>(queryKey: QueryKey, options?: {
|
|
34
|
+
onRollback?: (error: Error) => void;
|
|
35
|
+
}): OptimisticUpdateConfig<T[], Partial<T> & {
|
|
36
|
+
id: T["id"];
|
|
37
|
+
}>;
|
|
38
|
+
declare function createRemoveItemConfig<T extends EntityWithId>(queryKey: QueryKey, options?: {
|
|
39
|
+
onRollback?: (error: Error) => void;
|
|
40
|
+
}): OptimisticUpdateConfig<T[], T["id"]>;
|
|
41
|
+
type ListOperationVariables<T extends EntityWithId, TOperation extends ListOperationType> = TOperation extends ListOperationType.ADD ? T : TOperation extends ListOperationType.UPDATE ? Partial<T> & {
|
|
42
|
+
id: T["id"];
|
|
43
|
+
} : TOperation extends ListOperationType.REMOVE ? T["id"] : never;
|
|
44
|
+
declare function createListOperationConfig<T extends EntityWithId, TOperation extends ListOperationType = ListOperationType>(config: ListOperationConfig<T>): OptimisticUpdateConfig<T[], ListOperationVariables<T, TOperation>>;
|
|
45
|
+
declare function batchUpdateItems<T extends EntityWithId>(items: T[] | undefined | null, updates: Array<Partial<T> & {
|
|
46
|
+
id: T["id"];
|
|
47
|
+
}>): T[];
|
|
48
|
+
declare function batchRemoveItems<T extends EntityWithId>(items: T[] | undefined | null, itemIds: Array<T["id"]>): T[];
|
|
49
|
+
declare function reorderItems<T extends EntityWithId>(items: T[] | undefined | null, fromIndex: number, toIndex: number): T[];
|
|
50
|
+
declare function conditionalUpdateItems<T extends EntityWithId>(items: T[] | undefined | null, predicate: (item: T) => boolean, updater: (item: T) => Partial<T>): T[];
|
|
51
|
+
|
|
52
|
+
declare function stableListPlaceholder<T = any>(previousData: T | undefined): T | undefined;
|
|
53
|
+
|
|
54
|
+
interface PrefetchConfig {
|
|
55
|
+
priority?: "high" | "medium" | "low";
|
|
56
|
+
delay?: number;
|
|
57
|
+
staleTime?: number;
|
|
58
|
+
allowSlowNetwork?: boolean;
|
|
59
|
+
}
|
|
60
|
+
interface PrefetchTask {
|
|
61
|
+
queryKey: QueryKey;
|
|
62
|
+
queryFn: QueryFunction<any>;
|
|
63
|
+
config: PrefetchConfig;
|
|
64
|
+
timestamp: number;
|
|
65
|
+
id: string;
|
|
66
|
+
predictionScore?: number;
|
|
67
|
+
}
|
|
68
|
+
type NetworkSpeed = "slow" | "medium" | "fast" | "unknown";
|
|
69
|
+
interface PrefetchStats {
|
|
70
|
+
queueSize: number;
|
|
71
|
+
historySize: number;
|
|
72
|
+
networkSpeed: NetworkSpeed;
|
|
73
|
+
isProcessing: boolean;
|
|
74
|
+
totalPrefetches: number;
|
|
75
|
+
successfulPrefetches: number;
|
|
76
|
+
failedPrefetches: number;
|
|
77
|
+
averagePrefetchTime: number;
|
|
78
|
+
skippedPrefetches: number;
|
|
79
|
+
}
|
|
80
|
+
interface InteractionRecord {
|
|
81
|
+
queryKey: QueryKey;
|
|
82
|
+
timestamp: number;
|
|
83
|
+
type: "view" | "hover" | "click" | "focus";
|
|
84
|
+
}
|
|
85
|
+
interface PredictionResult {
|
|
86
|
+
queryKey: QueryKey;
|
|
87
|
+
score: number;
|
|
88
|
+
reason: string;
|
|
89
|
+
}
|
|
90
|
+
declare class SmartPrefetchManager {
|
|
91
|
+
private queryClient;
|
|
92
|
+
private prefetchQueue;
|
|
93
|
+
private prefetchHistory;
|
|
94
|
+
private networkSpeed;
|
|
95
|
+
private isProcessing;
|
|
96
|
+
private maxQueueSize;
|
|
97
|
+
private maxHistorySize;
|
|
98
|
+
private totalPrefetches;
|
|
99
|
+
private successfulPrefetches;
|
|
100
|
+
private failedPrefetches;
|
|
101
|
+
private skippedPrefetches;
|
|
102
|
+
private prefetchTimes;
|
|
103
|
+
private maxPrefetchTimesSize;
|
|
104
|
+
private interactionHistory;
|
|
105
|
+
private maxInteractionHistorySize;
|
|
106
|
+
private queryAccessCounts;
|
|
107
|
+
private querySequences;
|
|
108
|
+
private maxSequenceSize;
|
|
109
|
+
private networkCleanup?;
|
|
110
|
+
constructor(queryClient: QueryClient);
|
|
111
|
+
private initNetworkMonitoring;
|
|
112
|
+
private updateNetworkSpeed;
|
|
113
|
+
getNetworkSpeed(): NetworkSpeed;
|
|
114
|
+
isSlowNetwork(): boolean;
|
|
115
|
+
shouldPrefetch(queryKey: QueryKey, config?: PrefetchConfig): boolean;
|
|
116
|
+
addPrefetchTask(queryKey: QueryKey, queryFn: QueryFunction<any>, config?: PrefetchConfig): boolean;
|
|
117
|
+
private processQueue;
|
|
118
|
+
private getSortedTasks;
|
|
119
|
+
prefetchNow<TData = unknown>(queryKey: QueryKey, queryFn: QueryFunction<TData>, config?: PrefetchConfig): Promise<void>;
|
|
120
|
+
private addToHistory;
|
|
121
|
+
clearHistory(): void;
|
|
122
|
+
clearQueue(): void;
|
|
123
|
+
reset(): void;
|
|
124
|
+
destroy(): void;
|
|
125
|
+
recordInteraction(queryKey: QueryKey, type?: "view" | "hover" | "click" | "focus"): void;
|
|
126
|
+
getPredictions(currentQueryKey?: QueryKey, limit?: number): PredictionResult[];
|
|
127
|
+
prefetchPredicted(currentQueryKey: QueryKey | undefined, queryFnMap: Map<string, QueryFunction<any>>, config?: PrefetchConfig): Promise<void>;
|
|
128
|
+
clearInteractionHistory(): void;
|
|
129
|
+
private recordPrefetchTime;
|
|
130
|
+
private getAveragePrefetchTime;
|
|
131
|
+
getStats(): PrefetchStats;
|
|
132
|
+
getPerformanceReport(): {
|
|
133
|
+
stats: PrefetchStats;
|
|
134
|
+
successRate: number;
|
|
135
|
+
predictions: {
|
|
136
|
+
totalInteractions: number;
|
|
137
|
+
uniqueQueries: number;
|
|
138
|
+
sequencePatterns: number;
|
|
139
|
+
};
|
|
140
|
+
queue: {
|
|
141
|
+
size: number;
|
|
142
|
+
byPriority: {
|
|
143
|
+
high: number;
|
|
144
|
+
medium: number;
|
|
145
|
+
low: number;
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
resetStats(): void;
|
|
150
|
+
private getQueryKeyString;
|
|
151
|
+
private delay;
|
|
152
|
+
setMaxQueueSize(size: number): void;
|
|
153
|
+
setMaxHistorySize(size: number): void;
|
|
154
|
+
getQueuedTasks(): PrefetchTask[];
|
|
155
|
+
removeTask(queryKey: QueryKey): boolean;
|
|
156
|
+
hasTask(queryKey: QueryKey): boolean;
|
|
157
|
+
updateTaskPriority(queryKey: QueryKey, priority: "high" | "medium" | "low"): boolean;
|
|
158
|
+
pauseQueue(): void;
|
|
159
|
+
resumeQueue(): void;
|
|
160
|
+
}
|
|
161
|
+
declare function getPrefetchManager(queryClient: QueryClient): SmartPrefetchManager;
|
|
162
|
+
declare function resetPrefetchManager(): void;
|
|
163
|
+
|
|
164
|
+
interface NormalizeConfig<T = any> {
|
|
165
|
+
required?: (keyof T)[];
|
|
166
|
+
defaults?: Partial<T>;
|
|
167
|
+
sortKeys?: boolean;
|
|
168
|
+
removeEmpty?: boolean;
|
|
169
|
+
}
|
|
170
|
+
declare function normalizeQueryParams<T extends Record<string, any>>(params: T | undefined, config?: NormalizeConfig<T>): Record<string, any>;
|
|
171
|
+
interface QueryKeyFactoryConfig<TParams = any> {
|
|
172
|
+
namespace: string;
|
|
173
|
+
normalizeConfig?: NormalizeConfig<TParams>;
|
|
174
|
+
}
|
|
175
|
+
interface QueryKeyFactory<TParams = any> {
|
|
176
|
+
all: () => readonly [string];
|
|
177
|
+
lists: () => readonly [string, string];
|
|
178
|
+
list: (params?: TParams) => readonly [string, string, Record<string, any>];
|
|
179
|
+
details: () => readonly [string, string];
|
|
180
|
+
detail: (id: string) => readonly [string, string, string];
|
|
181
|
+
custom: (queryName: string, params?: any) => readonly [string, string, string, any?];
|
|
182
|
+
}
|
|
183
|
+
declare function createQueryKeyFactory<TParams = any>(config: QueryKeyFactoryConfig<TParams>): QueryKeyFactory<TParams>;
|
|
184
|
+
declare function createSimpleQueryKeyFactory(namespace: string): QueryKeyFactory;
|
|
185
|
+
declare function isQueryKeyEqual(key1: readonly any[], key2: readonly any[]): boolean;
|
|
186
|
+
declare function extractParamsFromKey(queryKey: readonly any[]): Record<string, any> | undefined;
|
|
187
|
+
declare function startsWithKeyPrefix(key: QueryKey, prefix: QueryKey): boolean;
|
|
188
|
+
declare function deriveFamilyKey(queryKey: QueryKey): QueryKey;
|
|
189
|
+
declare function isListFamilyKey(queryKey: QueryKey): boolean;
|
|
190
|
+
|
|
191
|
+
declare function selectById<T extends EntityWithId>(id: T["id"]): (data: T[] | undefined) => T | undefined;
|
|
192
|
+
declare function selectByIds<T extends EntityWithId>(ids: T["id"][]): (data: T[] | undefined) => T[];
|
|
193
|
+
declare function selectFirst<T>(data: T[] | undefined): T | undefined;
|
|
194
|
+
declare function selectLast<T>(data: T[] | undefined): T | undefined;
|
|
195
|
+
declare function selectCount<T>(data: T[] | undefined): number;
|
|
196
|
+
declare function selectTotal<T extends {
|
|
197
|
+
total?: number;
|
|
198
|
+
}>(data: T | undefined): number;
|
|
199
|
+
declare function selectItems<TItem, T extends PaginatedData<TItem>>(data: T | undefined): TItem[];
|
|
200
|
+
declare function selectWhere<T>(predicate: (item: T) => boolean): (data: T[] | undefined) => T[];
|
|
201
|
+
declare function selectMap<T, R>(mapper: (item: T) => R): (data: T[] | undefined) => R[];
|
|
202
|
+
declare function selectField<T, K extends keyof T>(field: K): (data: T | undefined) => T[K] | undefined;
|
|
203
|
+
declare function selectFields<T, K extends keyof T>(fields: K[]): (data: T | undefined) => Pick<T, K> | undefined;
|
|
204
|
+
declare function compose<T, R1, R2>(selector1: (data: T) => R1, selector2: (data: R1) => R2): (data: T) => R2;
|
|
205
|
+
declare const selectors: {
|
|
206
|
+
byId: typeof selectById;
|
|
207
|
+
byIds: typeof selectByIds;
|
|
208
|
+
first: typeof selectFirst;
|
|
209
|
+
last: typeof selectLast;
|
|
210
|
+
count: typeof selectCount;
|
|
211
|
+
total: typeof selectTotal;
|
|
212
|
+
items: typeof selectItems;
|
|
213
|
+
where: typeof selectWhere;
|
|
214
|
+
map: typeof selectMap;
|
|
215
|
+
field: typeof selectField;
|
|
216
|
+
fields: typeof selectFields;
|
|
217
|
+
compose: typeof compose;
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
declare function isStorageAvailable(storageType: StorageType): boolean;
|
|
221
|
+
declare function getStorageUsage(storageType: StorageType): StorageInfo;
|
|
222
|
+
declare function formatBytes(bytes: number): string;
|
|
223
|
+
declare function deepClone<T>(obj: T): T;
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* 计算对象的哈希值(键排序后计算,确保一致性)
|
|
227
|
+
*/
|
|
228
|
+
declare function hashObject(obj: any): string;
|
|
229
|
+
/**
|
|
230
|
+
* 自适应数据防护:根据数据特征自动选择最佳防护策略
|
|
231
|
+
*
|
|
232
|
+
* 策略优先级:
|
|
233
|
+
* 1. version(版本号)- 最可靠
|
|
234
|
+
* 2. updatedAt(时间戳)- 次优
|
|
235
|
+
* 3. hash(内容哈希)- 兜底
|
|
236
|
+
*/
|
|
237
|
+
declare function applyDataGuard<T extends VersionedEntity>(newData: VersionedPaginatedResponse<T>, cached: VersionedPaginatedResponse<T> | undefined, queryKey: QueryKey, options?: DataGuardOptions): {
|
|
238
|
+
shouldReject: boolean;
|
|
239
|
+
reason: string;
|
|
240
|
+
strategy: DataGuardStrategy;
|
|
241
|
+
guardDetails: any;
|
|
242
|
+
};
|
|
243
|
+
/**
|
|
244
|
+
* 为查询数据添加哈希标记
|
|
245
|
+
*/
|
|
246
|
+
declare function addHashToData<T extends VersionedEntity>(data: VersionedPaginatedResponse<T>): VersionedPaginatedResponse<T>;
|
|
247
|
+
/**
|
|
248
|
+
* 标记最近更新的项
|
|
249
|
+
*/
|
|
250
|
+
declare function markRecentlyUpdated<T extends VersionedEntity>(data: VersionedPaginatedResponse<T>, updatedId: string | number): VersionedPaginatedResponse<T>;
|
|
251
|
+
/**
|
|
252
|
+
* 清理最近更新的标记
|
|
253
|
+
*/
|
|
254
|
+
declare function clearRecentlyUpdated<T extends VersionedEntity>(data: VersionedPaginatedResponse<T>, updatedId: string | number): VersionedPaginatedResponse<T>;
|
|
255
|
+
/**
|
|
256
|
+
* 更新所有家族缓存的元数据(版本号、时间戳、哈希)
|
|
257
|
+
*/
|
|
258
|
+
declare function updateFamilyMetadata<T extends VersionedEntity>(queryClient: QueryClient, familyKey: QueryKey, response: Partial<VersionedPaginatedResponse<T>>): void;
|
|
259
|
+
|
|
260
|
+
interface BatchTask {
|
|
261
|
+
queryKey: QueryKey;
|
|
262
|
+
data?: any;
|
|
263
|
+
exact?: boolean;
|
|
264
|
+
}
|
|
265
|
+
declare function invalidateQueriesBatch(queryClient: QueryClient, tasks: BatchTask[] | QueryKey[]): void;
|
|
266
|
+
declare function cancelQueriesBatch(queryClient: QueryClient, tasks: BatchTask[] | QueryKey[]): void;
|
|
267
|
+
declare function setQueryDataBatch(queryClient: QueryClient, tasks: {
|
|
268
|
+
queryKey: QueryKey;
|
|
269
|
+
data: any;
|
|
270
|
+
}[]): void;
|
|
271
|
+
|
|
272
|
+
export { type BatchTask, type FieldMappingConfig, type InteractionRecord, type ListOperationVariables, type NavigatorWithConnection, type NetworkSpeed, type NormalizeConfig, type PredictionResult, type PrefetchConfig, type PrefetchStats, type PrefetchTask, type QueryKeyFactory, type QueryKeyFactoryConfig, SmartPrefetchManager, addHashToData, applyDataGuard, batchRemoveItems, batchUpdateItems, cancelQueriesBatch, clearRecentlyUpdated, compose, conditionalUpdateItems, createAddItemConfig, createFieldEnricher, createListOperationConfig, createOptimisticBase, createQueryKeyFactory, createRemoveItemConfig, createSimpleQueryKeyFactory, createTempId, createUpdateItemConfig, deepClone, deriveFamilyKey, extractParamsFromKey, formatBytes, getNetworkInfo, getNetworkSpeed, getPrefetchManager, getStorageUsage, hashObject, invalidateQueriesBatch, isFastNetwork, isListFamilyKey, isQueryKeyEqual, isSlowNetwork, isStorageAvailable, listUpdater, markRecentlyUpdated, normalizeQueryParams, reorderItems, resetPrefetchManager, selectById, selectByIds, selectCount, selectField, selectFields, selectFirst, selectItems, selectLast, selectMap, selectTotal, selectWhere, selectors, setQueryDataBatch, stableListPlaceholder, startsWithKeyPrefix, updateFamilyMetadata };
|
package/dist/utils/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export { createFieldEnricher, createOptimisticBase, createTempId } from
|
|
2
|
-
|
|
3
|
-
export {
|
|
4
|
-
|
|
5
|
-
export {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
export { SmartPrefetchManager, batchRemoveItems, batchUpdateItems, cancelQueriesBatch, compose, conditionalUpdateItems, createAddItemConfig, createFieldEnricher, createListOperationConfig, createOptimisticBase, createRemoveItemConfig, createTempId, createUpdateItemConfig, getPrefetchManager, invalidateQueriesBatch, keepPreviousData, listUpdater, reorderItems, resetPrefetchManager, selectById, selectByIds, selectCount, selectField, selectFields, selectFirst, selectItems, selectLast, selectMap, selectTotal, selectWhere, selectors, setQueryDataBatch, stableListPlaceholder } from '../chunk-GMO3PRZZ.js';
|
|
2
|
+
import '../chunk-ZNXSWUIS.js';
|
|
3
|
+
export { deepClone, formatBytes, getStorageUsage, isStorageAvailable } from '../chunk-STOMAA2X.js';
|
|
4
|
+
import '../chunk-LHEHSLD5.js';
|
|
5
|
+
export { addHashToData, applyDataGuard, clearRecentlyUpdated, createQueryKeyFactory, createSimpleQueryKeyFactory, deriveFamilyKey, extractParamsFromKey, getNetworkInfo, getNetworkSpeed, hashObject, isFastNetwork, isListFamilyKey, isQueryKeyEqual, isSlowNetwork, markRecentlyUpdated, normalizeQueryParams, startsWithKeyPrefix, updateFamilyMetadata } from '../chunk-X3ZTSLBQ.js';
|
|
6
|
+
import '../chunk-EXITP7QO.js';
|
|
7
|
+
import '../chunk-JN2Y6RSY.js';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qiaopeng/tanstack-query-plus",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.10",
|
|
4
4
|
"description": "Enhanced TanStack Query toolkit: defaults, hooks, persistence, offline, data guard, utils",
|
|
5
5
|
"author": "qiaopeng",
|
|
6
6
|
"license": "MIT",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
},
|
|
14
14
|
"homepage": "https://github.com/qiaopengg/qiaopeng-tanstack-query-plus#readme",
|
|
15
15
|
"type": "module",
|
|
16
|
-
"main": "./dist/index.
|
|
16
|
+
"main": "./dist/index.cjs",
|
|
17
17
|
"module": "./dist/index.js",
|
|
18
18
|
"types": "./dist/index.d.ts",
|
|
19
19
|
"sideEffects": false,
|
|
@@ -33,42 +33,52 @@
|
|
|
33
33
|
"exports": {
|
|
34
34
|
".": {
|
|
35
35
|
"import": "./dist/index.js",
|
|
36
|
+
"require": "./dist/index.cjs",
|
|
36
37
|
"types": "./dist/index.d.ts"
|
|
37
38
|
},
|
|
38
39
|
"./react-query": {
|
|
39
40
|
"import": "./dist/react-query/index.js",
|
|
41
|
+
"require": "./dist/react-query/index.cjs",
|
|
40
42
|
"types": "./dist/react-query/index.d.ts"
|
|
41
43
|
},
|
|
42
44
|
"./core": {
|
|
43
45
|
"import": "./dist/core/index.js",
|
|
46
|
+
"require": "./dist/core/index.cjs",
|
|
44
47
|
"types": "./dist/core/index.d.ts"
|
|
45
48
|
},
|
|
46
49
|
"./core/devtools": {
|
|
47
50
|
"import": "./dist/core/devtools.js",
|
|
51
|
+
"require": "./dist/core/devtools.cjs",
|
|
48
52
|
"types": "./dist/core/devtools.d.ts"
|
|
49
53
|
},
|
|
50
54
|
"./hooks": {
|
|
51
55
|
"import": "./dist/hooks/index.js",
|
|
56
|
+
"require": "./dist/hooks/index.cjs",
|
|
52
57
|
"types": "./dist/hooks/index.d.ts"
|
|
53
58
|
},
|
|
54
59
|
"./hooks/inview": {
|
|
55
60
|
"import": "./dist/hooks/useInViewPrefetch.js",
|
|
61
|
+
"require": "./dist/hooks/useInViewPrefetch.cjs",
|
|
56
62
|
"types": "./dist/hooks/useInViewPrefetch.d.ts"
|
|
57
63
|
},
|
|
58
64
|
"./features": {
|
|
59
65
|
"import": "./dist/features/index.js",
|
|
66
|
+
"require": "./dist/features/index.cjs",
|
|
60
67
|
"types": "./dist/features/index.d.ts"
|
|
61
68
|
},
|
|
62
69
|
"./components": {
|
|
63
70
|
"import": "./dist/components/index.js",
|
|
71
|
+
"require": "./dist/components/index.cjs",
|
|
64
72
|
"types": "./dist/components/index.d.ts"
|
|
65
73
|
},
|
|
66
74
|
"./types": {
|
|
67
75
|
"import": "./dist/types/index.js",
|
|
76
|
+
"require": "./dist/types/index.cjs",
|
|
68
77
|
"types": "./dist/types/index.d.ts"
|
|
69
78
|
},
|
|
70
79
|
"./utils": {
|
|
71
80
|
"import": "./dist/utils/index.js",
|
|
81
|
+
"require": "./dist/utils/index.cjs",
|
|
72
82
|
"types": "./dist/utils/index.d.ts"
|
|
73
83
|
}
|
|
74
84
|
},
|
|
@@ -108,7 +118,7 @@
|
|
|
108
118
|
"typescript": "^5.4.0"
|
|
109
119
|
},
|
|
110
120
|
"scripts": {
|
|
111
|
-
"build": "
|
|
121
|
+
"build": "tsup",
|
|
112
122
|
"typecheck": "tsc -p ./tsconfig.json --noEmit",
|
|
113
123
|
"prepublishOnly": "npm run typecheck && npm run build"
|
|
114
124
|
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { QueryClient } from "@tanstack/react-query";
|
|
2
|
-
import type { ReactNode } from "react";
|
|
3
|
-
export interface PersistQueryClientProviderProps {
|
|
4
|
-
children: ReactNode;
|
|
5
|
-
client: QueryClient;
|
|
6
|
-
cacheKey?: string;
|
|
7
|
-
enablePersistence?: boolean;
|
|
8
|
-
enableOfflineSupport?: boolean;
|
|
9
|
-
onPersistError?: (error: Error) => void;
|
|
10
|
-
onPersistRestore?: () => void;
|
|
11
|
-
}
|
|
12
|
-
export declare function PersistQueryClientProvider({ children, client, cacheKey, enablePersistence, enableOfflineSupport, onPersistError: _onPersistError, onPersistRestore }: PersistQueryClientProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
13
|
-
export declare function usePersistenceStatus(): {
|
|
14
|
-
isOnline: boolean;
|
|
15
|
-
isOffline: boolean;
|
|
16
|
-
};
|
|
17
|
-
export declare function usePersistenceManager(): {
|
|
18
|
-
clearCache: (cacheKey?: string) => void;
|
|
19
|
-
getOnlineStatus: () => boolean;
|
|
20
|
-
};
|
|
21
|
-
export default PersistQueryClientProvider;
|
|
22
|
-
//# sourceMappingURL=PersistQueryClientProvider.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PersistQueryClientProvider.d.ts","sourceRoot":"","sources":["../src/PersistQueryClientProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAQvC,MAAM,WAAW,+BAA+B;IAC9C,QAAQ,EAAE,SAAS,CAAC;IACpB,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACxC,gBAAgB,CAAC,EAAE,MAAM,IAAI,CAAC;CAC/B;AAED,wBAAgB,0BAA0B,CAAC,EACzC,QAAQ,EACR,MAAM,EACN,QAAiC,EACjC,iBAAwB,EACxB,oBAA2B,EAC3B,cAAc,EAAE,eAAe,EAC/B,gBAAgB,EACjB,EAAE,+BAA+B,2CAmCjC;AAED,wBAAgB,oBAAoB;;;EASnC;AAED,wBAAgB,qBAAqB;;;EAWpC;AAED,eAAe,0BAA0B,CAAC"}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { QueryClientProvider } from "@tanstack/react-query";
|
|
3
|
-
import { PersistQueryClientProvider as TanStackPersistProvider } from "@tanstack/react-query-persist-client";
|
|
4
|
-
import { useEffect, useMemo, useState } from "react";
|
|
5
|
-
import { TIME_CONSTANTS } from "./core/config.js";
|
|
6
|
-
import { isOnline, setupOnlineManager, subscribeToOnlineStatus } from "./features/offline.js";
|
|
7
|
-
import { clearCache, createPersister } from "./features/persistence.js";
|
|
8
|
-
export function PersistQueryClientProvider({ children, client, cacheKey = "tanstack-query-cache", enablePersistence = true, enableOfflineSupport = true, onPersistError: _onPersistError, onPersistRestore }) {
|
|
9
|
-
useEffect(() => {
|
|
10
|
-
if (enableOfflineSupport) {
|
|
11
|
-
setupOnlineManager();
|
|
12
|
-
}
|
|
13
|
-
}, [enableOfflineSupport]);
|
|
14
|
-
const persister = useMemo(() => {
|
|
15
|
-
if (!enablePersistence)
|
|
16
|
-
return null;
|
|
17
|
-
return createPersister(cacheKey, undefined, _onPersistError);
|
|
18
|
-
}, [cacheKey, enablePersistence, _onPersistError]);
|
|
19
|
-
const persistOptions = useMemo(() => {
|
|
20
|
-
if (!persister)
|
|
21
|
-
return null;
|
|
22
|
-
return {
|
|
23
|
-
persister,
|
|
24
|
-
maxAge: TIME_CONSTANTS.ONE_DAY
|
|
25
|
-
};
|
|
26
|
-
}, [persister]);
|
|
27
|
-
if (enablePersistence) {
|
|
28
|
-
if (!persistOptions) {
|
|
29
|
-
return _jsx(QueryClientProvider, { client: client, children: children });
|
|
30
|
-
}
|
|
31
|
-
return (_jsx(TanStackPersistProvider, { client: client, persistOptions: persistOptions, onSuccess: onPersistRestore, children: children }));
|
|
32
|
-
}
|
|
33
|
-
return _jsx(QueryClientProvider, { client: client, children: children });
|
|
34
|
-
}
|
|
35
|
-
export function usePersistenceStatus() {
|
|
36
|
-
const [online, setOnline] = useState(isOnline());
|
|
37
|
-
useEffect(() => {
|
|
38
|
-
return subscribeToOnlineStatus(setOnline);
|
|
39
|
-
}, []);
|
|
40
|
-
return {
|
|
41
|
-
isOnline: online,
|
|
42
|
-
isOffline: !online
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
export function usePersistenceManager() {
|
|
46
|
-
const clearPersistenceCache = (cacheKey = "tanstack-query-cache") => {
|
|
47
|
-
clearCache(cacheKey);
|
|
48
|
-
};
|
|
49
|
-
const getOnlineStatus = () => {
|
|
50
|
-
return isOnline();
|
|
51
|
-
};
|
|
52
|
-
return {
|
|
53
|
-
clearCache: clearPersistenceCache,
|
|
54
|
-
getOnlineStatus
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
export default PersistQueryClientProvider;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export declare function DefaultLoadingFallback(): import("react/jsx-runtime").JSX.Element;
|
|
2
|
-
export declare function TextSkeletonFallback({ lines }: {
|
|
3
|
-
lines?: number;
|
|
4
|
-
}): import("react/jsx-runtime").JSX.Element;
|
|
5
|
-
export declare function CardSkeletonFallback(): import("react/jsx-runtime").JSX.Element;
|
|
6
|
-
export declare function ListSkeletonFallback({ items }: {
|
|
7
|
-
items?: number;
|
|
8
|
-
}): import("react/jsx-runtime").JSX.Element;
|
|
9
|
-
export declare function PageSkeletonFallback(): import("react/jsx-runtime").JSX.Element;
|
|
10
|
-
export declare function SmallLoadingIndicator({ size }: {
|
|
11
|
-
size?: "sm" | "md" | "lg";
|
|
12
|
-
}): import("react/jsx-runtime").JSX.Element;
|
|
13
|
-
export declare function FullScreenLoading({ message }: {
|
|
14
|
-
message?: string;
|
|
15
|
-
}): import("react/jsx-runtime").JSX.Element;
|
|
16
|
-
//# sourceMappingURL=LoadingFallback.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LoadingFallback.d.ts","sourceRoot":"","sources":["../../src/components/LoadingFallback.tsx"],"names":[],"mappings":"AAAA,wBAAgB,sBAAsB,4CASrC;AACD,wBAAgB,oBAAoB,CAAC,EAAE,KAAS,EAAE,EAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,2CAWrE;AACD,wBAAgB,oBAAoB,4CAWnC;AACD,wBAAgB,oBAAoB,CAAC,EAAE,KAAS,EAAE,EAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,2CAcrE;AACD,wBAAgB,oBAAoB,4CAyBnC;AACD,wBAAgB,qBAAqB,CAAC,EAAE,IAAW,EAAE,EAAE;IAAE,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAAA;CAAE,2CAOnF;AACD,wBAAgB,iBAAiB,CAAC,EAAE,OAAkB,EAAE,EAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,2CAS7E"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
export function DefaultLoadingFallback() {
|
|
3
|
-
return (_jsx("div", { className: "flex items-center justify-center p-6", children: _jsxs("div", { className: "text-center", children: [_jsx("div", { className: "w-12 h-12 mx-auto mb-3 border-4 border-primary/20 border-t-primary rounded-full animate-spin" }), _jsx("p", { className: "text-sm text-muted-foreground", children: "\u52A0\u8F7D\u4E2D..." })] }) }));
|
|
4
|
-
}
|
|
5
|
-
export function TextSkeletonFallback({ lines = 3 }) {
|
|
6
|
-
return (_jsx("div", { className: "space-y-3 p-4", children: Array.from({ length: lines }).map((_, i) => (_jsxs("div", { className: "animate-pulse", children: [_jsx("div", { className: "h-4 bg-input rounded w-3/4 mb-2" }), _jsx("div", { className: "h-4 bg-input rounded w-1/2" })] }, i))) }));
|
|
7
|
-
}
|
|
8
|
-
export function CardSkeletonFallback() {
|
|
9
|
-
return (_jsxs("div", { className: "border border-border rounded-lg p-4 animate-pulse bg-card", children: [_jsx("div", { className: "h-6 bg-input rounded w-1/2 mb-4" }), _jsxs("div", { className: "space-y-2", children: [_jsx("div", { className: "h-4 bg-input rounded" }), _jsx("div", { className: "h-4 bg-input rounded w-5/6" }), _jsx("div", { className: "h-4 bg-input rounded w-4/6" })] })] }));
|
|
10
|
-
}
|
|
11
|
-
export function ListSkeletonFallback({ items = 3 }) {
|
|
12
|
-
return (_jsx("div", { className: "space-y-4 p-4", children: Array.from({ length: items }).map((_, i) => (_jsxs("div", { className: "flex items-center space-x-4 animate-pulse", children: [_jsx("div", { className: "w-12 h-12 bg-input rounded-full shrink-0" }), _jsxs("div", { className: "flex-1 space-y-2", children: [_jsx("div", { className: "h-4 bg-input rounded w-3/4" }), _jsx("div", { className: "h-3 bg-input rounded w-1/2" })] })] }, i))) }));
|
|
13
|
-
}
|
|
14
|
-
export function PageSkeletonFallback() {
|
|
15
|
-
return (_jsxs("div", { className: "w-full p-6 space-y-6", children: [_jsxs("div", { className: "animate-pulse", children: [_jsx("div", { className: "h-8 bg-input rounded w-1/3 mb-2" }), _jsx("div", { className: "h-4 bg-input rounded w-1/2" })] }), _jsxs("div", { className: "grid grid-cols-1 md:grid-cols-3 gap-6", children: [_jsxs("div", { className: "md:col-span-2 space-y-4", children: [_jsx(CardSkeletonFallback, {}), _jsx(CardSkeletonFallback, {})] }), _jsx("div", { className: "space-y-4", children: _jsxs("div", { className: "border border-border rounded-lg p-4 animate-pulse bg-card", children: [_jsx("div", { className: "h-4 bg-input rounded w-2/3 mb-3" }), _jsxs("div", { className: "space-y-2", children: [_jsx("div", { className: "h-3 bg-input rounded" }), _jsx("div", { className: "h-3 bg-input rounded w-5/6" }), _jsx("div", { className: "h-3 bg-input rounded w-4/6" })] })] }) })] })] }));
|
|
16
|
-
}
|
|
17
|
-
export function SmallLoadingIndicator({ size = "md" }) {
|
|
18
|
-
const sizeClasses = {
|
|
19
|
-
sm: "w-4 h-4 border-2",
|
|
20
|
-
md: "w-6 h-6 border-2",
|
|
21
|
-
lg: "w-8 h-8 border-3"
|
|
22
|
-
};
|
|
23
|
-
return _jsx("div", { className: `${sizeClasses[size]} border-primary/20 border-t-primary rounded-full animate-spin` });
|
|
24
|
-
}
|
|
25
|
-
export function FullScreenLoading({ message = "加载中..." }) {
|
|
26
|
-
return (_jsx("div", { className: "fixed inset-0 bg-background/90 flex items-center justify-center z-50", children: _jsxs("div", { className: "text-center", children: [_jsx("div", { className: "w-16 h-16 mx-auto mb-4 border-4 border-primary/20 border-t-primary rounded-full animate-spin" }), _jsx("p", { className: "text-lg text-foreground", children: message })] }) }));
|
|
27
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { ReactNode } from "react";
|
|
2
|
-
export interface QueryErrorBoundaryProps {
|
|
3
|
-
children: ReactNode;
|
|
4
|
-
fallback?: (error: Error, resetErrorBoundary: () => void) => ReactNode;
|
|
5
|
-
onError?: (error: Error, errorInfo: {
|
|
6
|
-
componentStack: string;
|
|
7
|
-
}) => void;
|
|
8
|
-
resetKeys?: Array<string | number>;
|
|
9
|
-
}
|
|
10
|
-
export declare function QueryErrorBoundary({ children, fallback, onError, resetKeys, ...props }: QueryErrorBoundaryProps): import("react/jsx-runtime").JSX.Element;
|
|
11
|
-
export declare function QueryErrorFallback(error: Error, resetErrorBoundary: () => void): import("react/jsx-runtime").JSX.Element;
|
|
12
|
-
//# sourceMappingURL=QueryErrorBoundary.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"QueryErrorBoundary.d.ts","sourceRoot":"","sources":["../../src/components/QueryErrorBoundary.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAIvC,MAAM,WAAW,uBAAuB;IACtC,QAAQ,EAAE,SAAS,CAAC;IACpB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,kBAAkB,EAAE,MAAM,IAAI,KAAK,SAAS,CAAC;IACvE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE;QAAE,cAAc,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IACxE,SAAS,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;CACpC;AAED,wBAAgB,kBAAkB,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,KAAK,EAAE,EAAE,uBAAuB,2CAU/G;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,KAAK,EAAE,kBAAkB,EAAE,MAAM,IAAI,2CAwB9E"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { QueryErrorResetBoundary } from "@tanstack/react-query";
|
|
3
|
-
import { ErrorBoundary } from "./internal/ErrorBoundary.js";
|
|
4
|
-
export function QueryErrorBoundary({ children, fallback, onError, resetKeys, ...props }) {
|
|
5
|
-
return (_jsx(QueryErrorResetBoundary, { children: ({ reset }) => (_jsx(ErrorBoundary, { fallback: fallback || QueryErrorFallback, onError: onError, onReset: reset, resetKeys: resetKeys, ...props, children: children })) }));
|
|
6
|
-
}
|
|
7
|
-
export function QueryErrorFallback(error, resetErrorBoundary) {
|
|
8
|
-
return (_jsx("div", { className: "flex items-center justify-center p-6", children: _jsxs("div", { className: "text-center max-w-md", children: [_jsx("div", { className: "mb-4", children: _jsx("div", { className: "w-12 h-12 mx-auto mb-3 bg-orange-100 rounded-full flex items-center justify-center", children: _jsx("svg", { className: "w-6 h-6 text-orange-600", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: _jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" }) }) }) }), _jsx("h3", { className: "text-lg font-semibold text-foreground mb-2", children: "\u67E5\u8BE2\u5931\u8D25" }), _jsx("p", { className: "text-sm text-muted-foreground mb-4", children: error.message || "数据加载失败,请稍后重试" }), _jsxs("div", { className: "space-x-2", children: [_jsx("button", { onClick: resetErrorBoundary, className: "px-4 py-2 bg-primary text-primary-foreground rounded-md", children: "\u91CD\u65B0\u52A0\u8F7D" }), _jsx("button", { onClick: () => window.location.reload(), className: "px-4 py-2 bg-muted text-foreground rounded-md", children: "\u5237\u65B0\u9875\u9762" })] })] }) }));
|
|
9
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { ReactNode } from "react";
|
|
2
|
-
interface SuspenseWrapperProps {
|
|
3
|
-
children: ReactNode;
|
|
4
|
-
fallback?: ReactNode;
|
|
5
|
-
errorFallback?: (error: Error, resetErrorBoundary: () => void) => ReactNode;
|
|
6
|
-
onError?: (error: Error, errorInfo: {
|
|
7
|
-
componentStack: string;
|
|
8
|
-
}) => void;
|
|
9
|
-
resetKeys?: Array<string | number>;
|
|
10
|
-
}
|
|
11
|
-
export declare function SuspenseWrapper({ children, fallback, errorFallback, onError, resetKeys }: SuspenseWrapperProps): import("react/jsx-runtime").JSX.Element;
|
|
12
|
-
export declare function QuerySuspenseWrapper({ children, fallback, errorFallback, onError, resetKeys }: SuspenseWrapperProps): import("react/jsx-runtime").JSX.Element;
|
|
13
|
-
export type { SuspenseWrapperProps };
|
|
14
|
-
//# sourceMappingURL=SuspenseWrapper.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SuspenseWrapper.d.ts","sourceRoot":"","sources":["../../src/components/SuspenseWrapper.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAIvC,UAAU,oBAAoB;IAC5B,QAAQ,EAAE,SAAS,CAAC;IACpB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,kBAAkB,EAAE,MAAM,IAAI,KAAK,SAAS,CAAC;IAC5E,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE;QAAE,cAAc,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IACxE,SAAS,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;CACpC;AAED,wBAAgB,eAAe,CAAC,EAAE,QAAQ,EAAE,QAAgC,EAAE,aAAa,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,oBAAoB,2CAMtI;AAED,wBAAgB,oBAAoB,CAAC,EAAE,QAAQ,EAAE,QAAsC,EAAE,aAAa,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,oBAAoB,2CAMjJ;AAED,YAAY,EAAE,oBAAoB,EAAE,CAAC"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { Suspense } from "react";
|
|
3
|
-
import { QueryErrorBoundary } from "./QueryErrorBoundary.js";
|
|
4
|
-
export function SuspenseWrapper({ children, fallback = _jsx("div", { children: "Loading..." }), errorFallback, onError, resetKeys }) {
|
|
5
|
-
return (_jsx(QueryErrorBoundary, { fallback: errorFallback, onError: onError, resetKeys: resetKeys, children: _jsx(Suspense, { fallback: fallback, children: children }) }));
|
|
6
|
-
}
|
|
7
|
-
export function QuerySuspenseWrapper({ children, fallback = _jsx("div", { children: "Loading query..." }), errorFallback, onError, resetKeys }) {
|
|
8
|
-
return (_jsx(SuspenseWrapper, { fallback: fallback, errorFallback: errorFallback, onError: onError, resetKeys: resetKeys, children: children }));
|
|
9
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,iBAAiB,EACjB,oBAAoB,EACpB,oBAAoB,EACpB,qBAAqB,EACrB,oBAAoB,EACrB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,kBAAkB,EAAE,KAAK,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAC3F,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { ReactNode } from "react";
|
|
2
|
-
import { Component } from "react";
|
|
3
|
-
export interface ErrorBoundaryProps {
|
|
4
|
-
children: ReactNode;
|
|
5
|
-
fallback?: (error: Error, resetErrorBoundary: () => void) => ReactNode;
|
|
6
|
-
onError?: (error: Error, errorInfo: {
|
|
7
|
-
componentStack: string;
|
|
8
|
-
}) => void;
|
|
9
|
-
onReset?: () => void;
|
|
10
|
-
resetKeys?: Array<string | number>;
|
|
11
|
-
}
|
|
12
|
-
interface ErrorBoundaryState {
|
|
13
|
-
hasError: boolean;
|
|
14
|
-
error?: Error;
|
|
15
|
-
}
|
|
16
|
-
export declare class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
|
|
17
|
-
constructor(props: ErrorBoundaryProps);
|
|
18
|
-
static getDerivedStateFromError(error: Error): ErrorBoundaryState;
|
|
19
|
-
componentDidCatch(error: Error, errorInfo: {
|
|
20
|
-
componentStack: string;
|
|
21
|
-
}): void;
|
|
22
|
-
componentDidUpdate(prevProps: ErrorBoundaryProps): void;
|
|
23
|
-
resetErrorBoundary: () => void;
|
|
24
|
-
render(): string | number | boolean | Iterable<ReactNode> | import("react/jsx-runtime").JSX.Element | null | undefined;
|
|
25
|
-
}
|
|
26
|
-
export {};
|
|
27
|
-
//# sourceMappingURL=ErrorBoundary.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ErrorBoundary.d.ts","sourceRoot":"","sources":["../../../src/components/internal/ErrorBoundary.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,SAAS,CAAC;IACpB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,kBAAkB,EAAE,MAAM,IAAI,KAAK,SAAS,CAAC;IACvE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE;QAAE,cAAc,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IACxE,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,SAAS,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;CACpC;AAED,UAAU,kBAAkB;IAC1B,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,KAAK,CAAC;CACf;AAED,qBAAa,aAAc,SAAQ,SAAS,CAAC,kBAAkB,EAAE,kBAAkB,CAAC;gBACtE,KAAK,EAAE,kBAAkB;IAIrC,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,KAAK,GAAG,kBAAkB;IAGjE,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE;QAAE,cAAc,EAAE,MAAM,CAAA;KAAE;IAGrE,kBAAkB,CAAC,SAAS,EAAE,kBAAkB;IAShD,kBAAkB,aAGhB;IACF,MAAM;CAmBP"}
|