najm-kit 2.7.0 → 2.7.2
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/CHANGELOG.md +112 -112
- package/dist/NBrandingContext-dkADu8JS.d.ts +82 -0
- package/dist/{NajmUIProvider-BsCoDjHH.d.ts → NajmUIProvider-ClpHD-55.d.ts} +33 -146
- package/dist/adapters/app.d.ts +58 -5
- package/dist/adapters/app.mjs +55 -19
- package/dist/adapters/next.d.ts +2 -1
- package/dist/adapters/next.mjs +3 -3
- package/dist/{chunk-4DLRXB2W.mjs → chunk-6OOBAEH2.mjs} +2 -7
- package/dist/chunk-7J7DWGKB.mjs +93 -0
- package/dist/{chunk-4MRUJ2ZO.mjs → chunk-IRFFSAO2.mjs} +1 -1
- package/dist/{chunk-YBM5CTE6.mjs → chunk-KVZACF4G.mjs} +6 -1
- package/dist/chunk-QOP7L6RD.mjs +218 -0
- package/dist/{chunk-7F65QM43.mjs → chunk-USZUOJMK.mjs} +89 -10
- package/dist/index.d.ts +193 -28
- package/dist/index.mjs +9 -8
- package/dist/json.mjs +3 -3
- package/dist/pagination-BvukSZir.d.ts +130 -0
- package/dist/paginationLabels-CY2PvbMj.d.ts +143 -0
- package/dist/query.d.ts +299 -0
- package/dist/query.mjs +131 -0
- package/package.json +11 -1
- package/dist/chunk-IGUQGT3G.mjs +0 -24
package/dist/query.d.ts
ADDED
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import * as _tanstack_query_core from '@tanstack/query-core';
|
|
2
|
+
import { d as OffsetPageFetcher, O as OffsetPage, L as ListStrategy, R as ResolvedListMode } from './pagination-BvukSZir.js';
|
|
3
|
+
export { A as ApiPage, C as CardPaginationLabels, a as CardPaginationState, b as DEFAULT_MAX_PAGE_SIZE, c as DEFAULT_PAGE_SIZE, e as OffsetPageOptions, f as OffsetPagination, Q as QueryValue, g as buildCardPaginationLabels, h as cleanQuery, i as createCardPagination, j as createOffsetPagination, k as fetchOffsetPage, l as getPageIndex } from './pagination-BvukSZir.js';
|
|
4
|
+
import './paginationLabels-CY2PvbMj.js';
|
|
5
|
+
import 'react';
|
|
6
|
+
|
|
7
|
+
interface UseOffsetInfiniteQueryOptions<T> {
|
|
8
|
+
enabled?: boolean;
|
|
9
|
+
fetchPage: OffsetPageFetcher<T>;
|
|
10
|
+
queryKey: readonly unknown[];
|
|
11
|
+
/**
|
|
12
|
+
* The size of one *server request*, not of a displayed page.
|
|
13
|
+
*
|
|
14
|
+
* Deliberately decoupled: the display page size is measured from the rendered
|
|
15
|
+
* container and moves as the viewport, column count and card height settle.
|
|
16
|
+
* Tying a request to it would put a network round trip behind every
|
|
17
|
+
* measurement correction, and a second skeleton behind each round trip.
|
|
18
|
+
*/
|
|
19
|
+
windowSize?: number;
|
|
20
|
+
/** The server's `limit` clamp. Defaults to `DEFAULT_MAX_PAGE_SIZE`. */
|
|
21
|
+
maxLimit?: number;
|
|
22
|
+
}
|
|
23
|
+
declare const DEFAULT_ROW_WINDOW_SIZE = 50;
|
|
24
|
+
/**
|
|
25
|
+
* An accumulating row buffer over `fetchOffsetPage`.
|
|
26
|
+
*
|
|
27
|
+
* Every mode of `useResponsiveOffsetList` reads from one of these — numbered
|
|
28
|
+
* pages are a slice of the buffer rather than a request of their own.
|
|
29
|
+
*/
|
|
30
|
+
declare function useOffsetInfiniteQuery<T>({ enabled, fetchPage, queryKey, windowSize, maxLimit, }: UseOffsetInfiniteQueryOptions<T>): {
|
|
31
|
+
rows: T[];
|
|
32
|
+
hasNextPage: boolean;
|
|
33
|
+
total: number;
|
|
34
|
+
data: _tanstack_query_core.InfiniteData<OffsetPage<T>, unknown>;
|
|
35
|
+
error: Error;
|
|
36
|
+
isError: true;
|
|
37
|
+
isPending: false;
|
|
38
|
+
isLoading: false;
|
|
39
|
+
isLoadingError: false;
|
|
40
|
+
isRefetchError: true;
|
|
41
|
+
isSuccess: false;
|
|
42
|
+
isPlaceholderData: false;
|
|
43
|
+
status: "error";
|
|
44
|
+
fetchNextPage: (options?: _tanstack_query_core.FetchNextPageOptions) => Promise<_tanstack_query_core.InfiniteQueryObserverResult<_tanstack_query_core.InfiniteData<OffsetPage<T>, unknown>, Error>>;
|
|
45
|
+
fetchPreviousPage: (options?: _tanstack_query_core.FetchPreviousPageOptions) => Promise<_tanstack_query_core.InfiniteQueryObserverResult<_tanstack_query_core.InfiniteData<OffsetPage<T>, unknown>, Error>>;
|
|
46
|
+
hasPreviousPage: boolean;
|
|
47
|
+
isFetchNextPageError: boolean;
|
|
48
|
+
isFetchingNextPage: boolean;
|
|
49
|
+
isFetchPreviousPageError: boolean;
|
|
50
|
+
isFetchingPreviousPage: boolean;
|
|
51
|
+
dataUpdatedAt: number;
|
|
52
|
+
errorUpdatedAt: number;
|
|
53
|
+
failureCount: number;
|
|
54
|
+
failureReason: Error;
|
|
55
|
+
errorUpdateCount: number;
|
|
56
|
+
isFetched: boolean;
|
|
57
|
+
isFetchedAfterMount: boolean;
|
|
58
|
+
isFetching: boolean;
|
|
59
|
+
isInitialLoading: boolean;
|
|
60
|
+
isPaused: boolean;
|
|
61
|
+
isRefetching: boolean;
|
|
62
|
+
isStale: boolean;
|
|
63
|
+
isEnabled: boolean;
|
|
64
|
+
refetch: (options?: _tanstack_query_core.RefetchOptions) => Promise<_tanstack_query_core.QueryObserverResult<_tanstack_query_core.InfiniteData<OffsetPage<T>, unknown>, Error>>;
|
|
65
|
+
fetchStatus: _tanstack_query_core.FetchStatus;
|
|
66
|
+
promise: Promise<_tanstack_query_core.InfiniteData<OffsetPage<T>, unknown>>;
|
|
67
|
+
} | {
|
|
68
|
+
rows: T[];
|
|
69
|
+
hasNextPage: boolean;
|
|
70
|
+
total: number;
|
|
71
|
+
data: _tanstack_query_core.InfiniteData<OffsetPage<T>, unknown>;
|
|
72
|
+
error: null;
|
|
73
|
+
isError: false;
|
|
74
|
+
isPending: false;
|
|
75
|
+
isLoading: false;
|
|
76
|
+
isLoadingError: false;
|
|
77
|
+
isRefetchError: false;
|
|
78
|
+
isFetchNextPageError: false;
|
|
79
|
+
isFetchPreviousPageError: false;
|
|
80
|
+
isSuccess: true;
|
|
81
|
+
isPlaceholderData: false;
|
|
82
|
+
status: "success";
|
|
83
|
+
fetchNextPage: (options?: _tanstack_query_core.FetchNextPageOptions) => Promise<_tanstack_query_core.InfiniteQueryObserverResult<_tanstack_query_core.InfiniteData<OffsetPage<T>, unknown>, Error>>;
|
|
84
|
+
fetchPreviousPage: (options?: _tanstack_query_core.FetchPreviousPageOptions) => Promise<_tanstack_query_core.InfiniteQueryObserverResult<_tanstack_query_core.InfiniteData<OffsetPage<T>, unknown>, Error>>;
|
|
85
|
+
hasPreviousPage: boolean;
|
|
86
|
+
isFetchingNextPage: boolean;
|
|
87
|
+
isFetchingPreviousPage: boolean;
|
|
88
|
+
dataUpdatedAt: number;
|
|
89
|
+
errorUpdatedAt: number;
|
|
90
|
+
failureCount: number;
|
|
91
|
+
failureReason: Error;
|
|
92
|
+
errorUpdateCount: number;
|
|
93
|
+
isFetched: boolean;
|
|
94
|
+
isFetchedAfterMount: boolean;
|
|
95
|
+
isFetching: boolean;
|
|
96
|
+
isInitialLoading: boolean;
|
|
97
|
+
isPaused: boolean;
|
|
98
|
+
isRefetching: boolean;
|
|
99
|
+
isStale: boolean;
|
|
100
|
+
isEnabled: boolean;
|
|
101
|
+
refetch: (options?: _tanstack_query_core.RefetchOptions) => Promise<_tanstack_query_core.QueryObserverResult<_tanstack_query_core.InfiniteData<OffsetPage<T>, unknown>, Error>>;
|
|
102
|
+
fetchStatus: _tanstack_query_core.FetchStatus;
|
|
103
|
+
promise: Promise<_tanstack_query_core.InfiniteData<OffsetPage<T>, unknown>>;
|
|
104
|
+
} | {
|
|
105
|
+
rows: T[];
|
|
106
|
+
hasNextPage: boolean;
|
|
107
|
+
total: number;
|
|
108
|
+
data: undefined;
|
|
109
|
+
error: Error;
|
|
110
|
+
isError: true;
|
|
111
|
+
isPending: false;
|
|
112
|
+
isLoading: false;
|
|
113
|
+
isLoadingError: true;
|
|
114
|
+
isRefetchError: false;
|
|
115
|
+
isFetchNextPageError: false;
|
|
116
|
+
isFetchPreviousPageError: false;
|
|
117
|
+
isSuccess: false;
|
|
118
|
+
isPlaceholderData: false;
|
|
119
|
+
status: "error";
|
|
120
|
+
fetchNextPage: (options?: _tanstack_query_core.FetchNextPageOptions) => Promise<_tanstack_query_core.InfiniteQueryObserverResult<_tanstack_query_core.InfiniteData<OffsetPage<T>, unknown>, Error>>;
|
|
121
|
+
fetchPreviousPage: (options?: _tanstack_query_core.FetchPreviousPageOptions) => Promise<_tanstack_query_core.InfiniteQueryObserverResult<_tanstack_query_core.InfiniteData<OffsetPage<T>, unknown>, Error>>;
|
|
122
|
+
hasPreviousPage: boolean;
|
|
123
|
+
isFetchingNextPage: boolean;
|
|
124
|
+
isFetchingPreviousPage: boolean;
|
|
125
|
+
dataUpdatedAt: number;
|
|
126
|
+
errorUpdatedAt: number;
|
|
127
|
+
failureCount: number;
|
|
128
|
+
failureReason: Error;
|
|
129
|
+
errorUpdateCount: number;
|
|
130
|
+
isFetched: boolean;
|
|
131
|
+
isFetchedAfterMount: boolean;
|
|
132
|
+
isFetching: boolean;
|
|
133
|
+
isInitialLoading: boolean;
|
|
134
|
+
isPaused: boolean;
|
|
135
|
+
isRefetching: boolean;
|
|
136
|
+
isStale: boolean;
|
|
137
|
+
isEnabled: boolean;
|
|
138
|
+
refetch: (options?: _tanstack_query_core.RefetchOptions) => Promise<_tanstack_query_core.QueryObserverResult<_tanstack_query_core.InfiniteData<OffsetPage<T>, unknown>, Error>>;
|
|
139
|
+
fetchStatus: _tanstack_query_core.FetchStatus;
|
|
140
|
+
promise: Promise<_tanstack_query_core.InfiniteData<OffsetPage<T>, unknown>>;
|
|
141
|
+
} | {
|
|
142
|
+
rows: T[];
|
|
143
|
+
hasNextPage: boolean;
|
|
144
|
+
total: number;
|
|
145
|
+
data: undefined;
|
|
146
|
+
error: null;
|
|
147
|
+
isError: false;
|
|
148
|
+
isPending: true;
|
|
149
|
+
isLoading: true;
|
|
150
|
+
isLoadingError: false;
|
|
151
|
+
isRefetchError: false;
|
|
152
|
+
isFetchNextPageError: false;
|
|
153
|
+
isFetchPreviousPageError: false;
|
|
154
|
+
isSuccess: false;
|
|
155
|
+
isPlaceholderData: false;
|
|
156
|
+
status: "pending";
|
|
157
|
+
fetchNextPage: (options?: _tanstack_query_core.FetchNextPageOptions) => Promise<_tanstack_query_core.InfiniteQueryObserverResult<_tanstack_query_core.InfiniteData<OffsetPage<T>, unknown>, Error>>;
|
|
158
|
+
fetchPreviousPage: (options?: _tanstack_query_core.FetchPreviousPageOptions) => Promise<_tanstack_query_core.InfiniteQueryObserverResult<_tanstack_query_core.InfiniteData<OffsetPage<T>, unknown>, Error>>;
|
|
159
|
+
hasPreviousPage: boolean;
|
|
160
|
+
isFetchingNextPage: boolean;
|
|
161
|
+
isFetchingPreviousPage: boolean;
|
|
162
|
+
dataUpdatedAt: number;
|
|
163
|
+
errorUpdatedAt: number;
|
|
164
|
+
failureCount: number;
|
|
165
|
+
failureReason: Error;
|
|
166
|
+
errorUpdateCount: number;
|
|
167
|
+
isFetched: boolean;
|
|
168
|
+
isFetchedAfterMount: boolean;
|
|
169
|
+
isFetching: boolean;
|
|
170
|
+
isInitialLoading: boolean;
|
|
171
|
+
isPaused: boolean;
|
|
172
|
+
isRefetching: boolean;
|
|
173
|
+
isStale: boolean;
|
|
174
|
+
isEnabled: boolean;
|
|
175
|
+
refetch: (options?: _tanstack_query_core.RefetchOptions) => Promise<_tanstack_query_core.QueryObserverResult<_tanstack_query_core.InfiniteData<OffsetPage<T>, unknown>, Error>>;
|
|
176
|
+
fetchStatus: _tanstack_query_core.FetchStatus;
|
|
177
|
+
promise: Promise<_tanstack_query_core.InfiniteData<OffsetPage<T>, unknown>>;
|
|
178
|
+
} | {
|
|
179
|
+
rows: T[];
|
|
180
|
+
hasNextPage: boolean;
|
|
181
|
+
total: number;
|
|
182
|
+
data: undefined;
|
|
183
|
+
error: null;
|
|
184
|
+
isError: false;
|
|
185
|
+
isPending: true;
|
|
186
|
+
isLoadingError: false;
|
|
187
|
+
isRefetchError: false;
|
|
188
|
+
isFetchNextPageError: false;
|
|
189
|
+
isFetchPreviousPageError: false;
|
|
190
|
+
isSuccess: false;
|
|
191
|
+
isPlaceholderData: false;
|
|
192
|
+
status: "pending";
|
|
193
|
+
fetchNextPage: (options?: _tanstack_query_core.FetchNextPageOptions) => Promise<_tanstack_query_core.InfiniteQueryObserverResult<_tanstack_query_core.InfiniteData<OffsetPage<T>, unknown>, Error>>;
|
|
194
|
+
fetchPreviousPage: (options?: _tanstack_query_core.FetchPreviousPageOptions) => Promise<_tanstack_query_core.InfiniteQueryObserverResult<_tanstack_query_core.InfiniteData<OffsetPage<T>, unknown>, Error>>;
|
|
195
|
+
hasPreviousPage: boolean;
|
|
196
|
+
isFetchingNextPage: boolean;
|
|
197
|
+
isFetchingPreviousPage: boolean;
|
|
198
|
+
dataUpdatedAt: number;
|
|
199
|
+
errorUpdatedAt: number;
|
|
200
|
+
failureCount: number;
|
|
201
|
+
failureReason: Error;
|
|
202
|
+
errorUpdateCount: number;
|
|
203
|
+
isFetched: boolean;
|
|
204
|
+
isFetchedAfterMount: boolean;
|
|
205
|
+
isFetching: boolean;
|
|
206
|
+
isLoading: boolean;
|
|
207
|
+
isInitialLoading: boolean;
|
|
208
|
+
isPaused: boolean;
|
|
209
|
+
isRefetching: boolean;
|
|
210
|
+
isStale: boolean;
|
|
211
|
+
isEnabled: boolean;
|
|
212
|
+
refetch: (options?: _tanstack_query_core.RefetchOptions) => Promise<_tanstack_query_core.QueryObserverResult<_tanstack_query_core.InfiniteData<OffsetPage<T>, unknown>, Error>>;
|
|
213
|
+
fetchStatus: _tanstack_query_core.FetchStatus;
|
|
214
|
+
promise: Promise<_tanstack_query_core.InfiniteData<OffsetPage<T>, unknown>>;
|
|
215
|
+
} | {
|
|
216
|
+
rows: T[];
|
|
217
|
+
hasNextPage: boolean;
|
|
218
|
+
total: number;
|
|
219
|
+
data: _tanstack_query_core.InfiniteData<OffsetPage<T>, unknown>;
|
|
220
|
+
isError: false;
|
|
221
|
+
error: null;
|
|
222
|
+
isPending: false;
|
|
223
|
+
isLoading: false;
|
|
224
|
+
isLoadingError: false;
|
|
225
|
+
isRefetchError: false;
|
|
226
|
+
isSuccess: true;
|
|
227
|
+
isPlaceholderData: true;
|
|
228
|
+
isFetchNextPageError: false;
|
|
229
|
+
isFetchPreviousPageError: false;
|
|
230
|
+
status: "success";
|
|
231
|
+
fetchNextPage: (options?: _tanstack_query_core.FetchNextPageOptions) => Promise<_tanstack_query_core.InfiniteQueryObserverResult<_tanstack_query_core.InfiniteData<OffsetPage<T>, unknown>, Error>>;
|
|
232
|
+
fetchPreviousPage: (options?: _tanstack_query_core.FetchPreviousPageOptions) => Promise<_tanstack_query_core.InfiniteQueryObserverResult<_tanstack_query_core.InfiniteData<OffsetPage<T>, unknown>, Error>>;
|
|
233
|
+
hasPreviousPage: boolean;
|
|
234
|
+
isFetchingNextPage: boolean;
|
|
235
|
+
isFetchingPreviousPage: boolean;
|
|
236
|
+
dataUpdatedAt: number;
|
|
237
|
+
errorUpdatedAt: number;
|
|
238
|
+
failureCount: number;
|
|
239
|
+
failureReason: Error;
|
|
240
|
+
errorUpdateCount: number;
|
|
241
|
+
isFetched: boolean;
|
|
242
|
+
isFetchedAfterMount: boolean;
|
|
243
|
+
isFetching: boolean;
|
|
244
|
+
isInitialLoading: boolean;
|
|
245
|
+
isPaused: boolean;
|
|
246
|
+
isRefetching: boolean;
|
|
247
|
+
isStale: boolean;
|
|
248
|
+
isEnabled: boolean;
|
|
249
|
+
refetch: (options?: _tanstack_query_core.RefetchOptions) => Promise<_tanstack_query_core.QueryObserverResult<_tanstack_query_core.InfiniteData<OffsetPage<T>, unknown>, Error>>;
|
|
250
|
+
fetchStatus: _tanstack_query_core.FetchStatus;
|
|
251
|
+
promise: Promise<_tanstack_query_core.InfiniteData<OffsetPage<T>, unknown>>;
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
interface PaginationState {
|
|
255
|
+
pageIndex: number;
|
|
256
|
+
pageSize: number;
|
|
257
|
+
}
|
|
258
|
+
type PaginationUpdater = PaginationState | ((current: PaginationState) => PaginationState);
|
|
259
|
+
interface UseResponsiveOffsetListOptions<T> {
|
|
260
|
+
enabled?: boolean;
|
|
261
|
+
fetchPage: OffsetPageFetcher<T>;
|
|
262
|
+
pageSize?: number;
|
|
263
|
+
queryKey: readonly unknown[];
|
|
264
|
+
/** Defaults to `"paged"`. See `ListStrategy`. */
|
|
265
|
+
strategy?: ListStrategy;
|
|
266
|
+
/** The server's `limit` clamp. Defaults to `DEFAULT_MAX_PAGE_SIZE`. */
|
|
267
|
+
maxLimit?: number;
|
|
268
|
+
/** Below this width the list continues on scroll. Defaults to `lg`. */
|
|
269
|
+
cardBreakpoint?: number;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* One offset-paginated list, in whichever presentation the viewport calls for.
|
|
273
|
+
*
|
|
274
|
+
* Feeds `NTable` directly: the return value carries `pagination`,
|
|
275
|
+
* `onPaginationChange` and `pageCount` for the page controls, and the fields
|
|
276
|
+
* `createCardPagination` reads for scroll continuation.
|
|
277
|
+
*/
|
|
278
|
+
declare function useResponsiveOffsetList<T>({ enabled, fetchPage, pageSize, queryKey, strategy, maxLimit, cardBreakpoint, }: UseResponsiveOffsetListOptions<T>): {
|
|
279
|
+
cardViewport: boolean;
|
|
280
|
+
mode: ResolvedListMode;
|
|
281
|
+
data: T[];
|
|
282
|
+
/** Rows matching the current filters on the server, or `null` if unknown. */
|
|
283
|
+
total: number;
|
|
284
|
+
error: Error;
|
|
285
|
+
hasNextPage: boolean;
|
|
286
|
+
loading: boolean;
|
|
287
|
+
loadingMore: boolean;
|
|
288
|
+
loadMoreError: Error;
|
|
289
|
+
onLoadMore: () => Promise<_tanstack_query_core.InfiniteQueryObserverResult<_tanstack_query_core.InfiniteData<OffsetPage<T>, unknown>, Error>>;
|
|
290
|
+
onPaginationChange: (updater: PaginationUpdater) => void;
|
|
291
|
+
pageCount: number;
|
|
292
|
+
pagination: {
|
|
293
|
+
pageIndex: number;
|
|
294
|
+
pageSize: number;
|
|
295
|
+
};
|
|
296
|
+
refetch: (options?: _tanstack_query_core.RefetchOptions) => Promise<_tanstack_query_core.QueryObserverResult<_tanstack_query_core.InfiniteData<OffsetPage<T>, unknown>, Error>>;
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
export { DEFAULT_ROW_WINDOW_SIZE, ListStrategy, OffsetPage, OffsetPageFetcher, ResolvedListMode, type UseOffsetInfiniteQueryOptions, type UseResponsiveOffsetListOptions, useOffsetInfiniteQuery, useResponsiveOffsetList };
|
package/dist/query.mjs
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { fetchOffsetPage, useCardViewport, DEFAULT_MAX_PAGE_SIZE } from './chunk-7J7DWGKB.mjs';
|
|
2
|
+
export { DEFAULT_MAX_PAGE_SIZE, DEFAULT_PAGE_SIZE, buildCardPaginationLabels, cleanQuery, createCardPagination, createOffsetPagination, fetchOffsetPage, getPageIndex } from './chunk-7J7DWGKB.mjs';
|
|
3
|
+
import { useInfiniteQuery } from '@tanstack/react-query';
|
|
4
|
+
import { useState, useRef, useEffect, useCallback } from 'react';
|
|
5
|
+
|
|
6
|
+
var DEFAULT_ROW_WINDOW_SIZE = 50;
|
|
7
|
+
function useOffsetInfiniteQuery({
|
|
8
|
+
enabled = true,
|
|
9
|
+
fetchPage,
|
|
10
|
+
queryKey,
|
|
11
|
+
windowSize = DEFAULT_ROW_WINDOW_SIZE,
|
|
12
|
+
maxLimit
|
|
13
|
+
}) {
|
|
14
|
+
const query = useInfiniteQuery({
|
|
15
|
+
enabled,
|
|
16
|
+
initialPageParam: 0,
|
|
17
|
+
queryKey: [...queryKey, "buffer", windowSize],
|
|
18
|
+
queryFn: ({ pageParam }) => fetchOffsetPage(
|
|
19
|
+
fetchPage,
|
|
20
|
+
{ limit: windowSize, offset: Number(pageParam) },
|
|
21
|
+
{ maxLimit }
|
|
22
|
+
),
|
|
23
|
+
getNextPageParam: (lastPage) => lastPage.hasNextPage ? lastPage.nextOffset : void 0
|
|
24
|
+
});
|
|
25
|
+
const pages = query.data?.pages;
|
|
26
|
+
return {
|
|
27
|
+
...query,
|
|
28
|
+
rows: pages?.flatMap((page) => page.rows) ?? [],
|
|
29
|
+
hasNextPage: Boolean(query.hasNextPage),
|
|
30
|
+
// The newest window carries the freshest count. Reading the first page
|
|
31
|
+
// instead would keep reporting a total from before the latest mutation.
|
|
32
|
+
total: pages?.[pages.length - 1]?.total ?? null
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function useResponsiveOffsetList({
|
|
36
|
+
enabled = true,
|
|
37
|
+
fetchPage,
|
|
38
|
+
pageSize = 25,
|
|
39
|
+
queryKey,
|
|
40
|
+
strategy = "paged",
|
|
41
|
+
maxLimit = DEFAULT_MAX_PAGE_SIZE,
|
|
42
|
+
cardBreakpoint
|
|
43
|
+
}) {
|
|
44
|
+
const cardViewport = useCardViewport(cardBreakpoint);
|
|
45
|
+
const queryIdentity = JSON.stringify(queryKey);
|
|
46
|
+
const [paginationState, setPagination] = useState({
|
|
47
|
+
pageIndex: 0,
|
|
48
|
+
pageSize,
|
|
49
|
+
queryIdentity
|
|
50
|
+
});
|
|
51
|
+
const pagination = paginationState.queryIdentity === queryIdentity ? paginationState : { ...paginationState, pageIndex: 0};
|
|
52
|
+
const wantsAll = strategy === "all";
|
|
53
|
+
const wantsInfinite = strategy === "infinite" || strategy === "paged" && cardViewport;
|
|
54
|
+
const buffer = useOffsetInfiniteQuery({
|
|
55
|
+
enabled,
|
|
56
|
+
fetchPage,
|
|
57
|
+
queryKey,
|
|
58
|
+
maxLimit,
|
|
59
|
+
windowSize: wantsAll ? maxLimit : DEFAULT_ROW_WINDOW_SIZE
|
|
60
|
+
});
|
|
61
|
+
const rows = buffer.rows;
|
|
62
|
+
const allDowngraded = wantsAll && buffer.hasNextPage;
|
|
63
|
+
const warnedRef = useRef(false);
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
if (!allDowngraded || warnedRef.current) return;
|
|
66
|
+
warnedRef.current = true;
|
|
67
|
+
if (process.env.NODE_ENV !== "production") {
|
|
68
|
+
console.warn(
|
|
69
|
+
`[najm-kit] List ${queryIdentity} requested strategy "all" but filled the ${maxLimit}-row ceiling, so its bound is not real. Falling back to infinite continuation; give this list a paged or infinite strategy.`
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
}, [allDowngraded, queryIdentity, maxLimit]);
|
|
73
|
+
const mode = wantsAll && !allDowngraded ? "all" : wantsInfinite || allDowngraded ? "infinite" : "paged";
|
|
74
|
+
const start = pagination.pageIndex * pagination.pageSize;
|
|
75
|
+
const data = mode === "paged" ? rows.slice(start, start + pagination.pageSize) : rows;
|
|
76
|
+
const { fetchNextPage, hasNextPage, isFetchingNextPage } = buffer;
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
if (mode !== "paged") return;
|
|
79
|
+
if (!hasNextPage || isFetchingNextPage) return;
|
|
80
|
+
if (rows.length >= start + pagination.pageSize * 2) return;
|
|
81
|
+
void fetchNextPage();
|
|
82
|
+
}, [
|
|
83
|
+
mode,
|
|
84
|
+
hasNextPage,
|
|
85
|
+
isFetchingNextPage,
|
|
86
|
+
rows.length,
|
|
87
|
+
start,
|
|
88
|
+
pagination.pageSize,
|
|
89
|
+
fetchNextPage
|
|
90
|
+
]);
|
|
91
|
+
const onPaginationChange = useCallback(
|
|
92
|
+
(updater) => {
|
|
93
|
+
setPagination((current) => ({
|
|
94
|
+
...typeof updater === "function" ? updater(
|
|
95
|
+
current.queryIdentity === queryIdentity ? { pageIndex: current.pageIndex, pageSize: current.pageSize } : { pageIndex: 0, pageSize: current.pageSize }
|
|
96
|
+
) : updater,
|
|
97
|
+
queryIdentity
|
|
98
|
+
}));
|
|
99
|
+
},
|
|
100
|
+
[queryIdentity]
|
|
101
|
+
);
|
|
102
|
+
const bufferedPages = Math.max(
|
|
103
|
+
1,
|
|
104
|
+
Math.ceil(rows.length / pagination.pageSize)
|
|
105
|
+
);
|
|
106
|
+
const pageCount = buffer.total !== null ? Math.max(1, Math.ceil(buffer.total / pagination.pageSize)) : buffer.hasNextPage ? bufferedPages + 1 : bufferedPages;
|
|
107
|
+
return {
|
|
108
|
+
cardViewport,
|
|
109
|
+
mode,
|
|
110
|
+
data,
|
|
111
|
+
/** Rows matching the current filters on the server, or `null` if unknown. */
|
|
112
|
+
total: buffer.total,
|
|
113
|
+
error: buffer.error,
|
|
114
|
+
hasNextPage: mode === "infinite" && buffer.hasNextPage,
|
|
115
|
+
// A background window extension is not a load. Paged readers keep the rows
|
|
116
|
+
// they are looking at; only having nothing at all is a loading state.
|
|
117
|
+
loading: buffer.isPending,
|
|
118
|
+
loadingMore: mode === "infinite" && buffer.isFetchingNextPage,
|
|
119
|
+
loadMoreError: buffer.isFetchNextPageError ? buffer.error : null,
|
|
120
|
+
onLoadMore: () => buffer.fetchNextPage(),
|
|
121
|
+
onPaginationChange,
|
|
122
|
+
pageCount,
|
|
123
|
+
pagination: {
|
|
124
|
+
pageIndex: pagination.pageIndex,
|
|
125
|
+
pageSize: pagination.pageSize
|
|
126
|
+
},
|
|
127
|
+
refetch: buffer.refetch
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export { DEFAULT_ROW_WINDOW_SIZE, useOffsetInfiniteQuery, useResponsiveOffsetList };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "najm-kit",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Reusable React UI component package for Najm framework",
|
|
@@ -33,6 +33,11 @@
|
|
|
33
33
|
"default": "./dist/adapters/app.mjs"
|
|
34
34
|
},
|
|
35
35
|
"./package.json": "./package.json",
|
|
36
|
+
"./query": {
|
|
37
|
+
"types": "./dist/query.d.ts",
|
|
38
|
+
"import": "./dist/query.mjs",
|
|
39
|
+
"default": "./dist/query.mjs"
|
|
40
|
+
},
|
|
36
41
|
"./json": {
|
|
37
42
|
"types": "./dist/json.d.ts",
|
|
38
43
|
"import": "./dist/json.mjs",
|
|
@@ -60,6 +65,7 @@
|
|
|
60
65
|
"zod": ">=4",
|
|
61
66
|
"next": ">=14",
|
|
62
67
|
"najm-i18n": ">=2",
|
|
68
|
+
"@tanstack/react-query": "^5",
|
|
63
69
|
"@uiw/react-codemirror": "^4.25.0",
|
|
64
70
|
"@codemirror/state": "^6.6.0",
|
|
65
71
|
"@codemirror/view": "^6.42.0",
|
|
@@ -76,6 +82,9 @@
|
|
|
76
82
|
"najm-i18n": {
|
|
77
83
|
"optional": true
|
|
78
84
|
},
|
|
85
|
+
"@tanstack/react-query": {
|
|
86
|
+
"optional": true
|
|
87
|
+
},
|
|
79
88
|
"@uiw/react-codemirror": {
|
|
80
89
|
"optional": true
|
|
81
90
|
},
|
|
@@ -147,6 +156,7 @@
|
|
|
147
156
|
"@hookform/resolvers": "^5",
|
|
148
157
|
"@lezer/highlight": "^1.2.0",
|
|
149
158
|
"@tailwindcss/postcss": "^4",
|
|
159
|
+
"@tanstack/react-query": "^5",
|
|
150
160
|
"@testing-library/react": "^16",
|
|
151
161
|
"@testing-library/user-event": "^14.6.1",
|
|
152
162
|
"@types/culori": "^4.0.1",
|
package/dist/chunk-IGUQGT3G.mjs
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { createContext, useContext, useMemo } from 'react';
|
|
2
|
-
import { jsx } from 'react/jsx-runtime';
|
|
3
|
-
|
|
4
|
-
// src/components/branding/NBrandingContext.tsx
|
|
5
|
-
var NBrandingContext = createContext(null);
|
|
6
|
-
function useNBranding() {
|
|
7
|
-
return useContext(NBrandingContext);
|
|
8
|
-
}
|
|
9
|
-
function NBrandingProvider({
|
|
10
|
-
children,
|
|
11
|
-
appName,
|
|
12
|
-
logoExpanded,
|
|
13
|
-
logoCollapsed,
|
|
14
|
-
logoFallback,
|
|
15
|
-
logoHref
|
|
16
|
-
}) {
|
|
17
|
-
const value = useMemo(
|
|
18
|
-
() => ({ appName, logoExpanded, logoCollapsed, logoFallback, logoHref }),
|
|
19
|
-
[appName, logoExpanded, logoCollapsed, logoFallback, logoHref]
|
|
20
|
-
);
|
|
21
|
-
return /* @__PURE__ */ jsx(NBrandingContext.Provider, { value, children });
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export { NBrandingProvider, useNBranding };
|