next-data-kit 0.0.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/LICENSE +21 -0
- package/README.md +478 -0
- package/dist/client/components/data-kit-table.d.ts +29 -0
- package/dist/client/components/data-kit.d.ts +19 -0
- package/dist/client/components/index.d.ts +3 -0
- package/dist/client/components/ui/button.d.ts +14 -0
- package/dist/client/components/ui/checkbox.d.ts +5 -0
- package/dist/client/components/ui/dropdown-menu.d.ts +28 -0
- package/dist/client/components/ui/index.d.ts +9 -0
- package/dist/client/components/ui/pagination.d.ts +14 -0
- package/dist/client/components/ui/popover.d.ts +10 -0
- package/dist/client/components/ui/select.d.ts +18 -0
- package/dist/client/components/ui/switch.d.ts +5 -0
- package/dist/client/components/ui/table.d.ts +11 -0
- package/dist/client/context/index.d.ts +22 -0
- package/dist/client/hooks/index.d.ts +7 -0
- package/dist/client/hooks/useDataKit.d.ts +9 -0
- package/dist/client/hooks/usePagination.d.ts +18 -0
- package/dist/client/hooks/useSelection.d.ts +13 -0
- package/dist/client/index.d.ts +11 -0
- package/dist/client/utils/cn.d.ts +10 -0
- package/dist/client/utils/index.d.ts +60 -0
- package/dist/client.d.ts +7 -0
- package/dist/index.d.cts +652 -0
- package/dist/index.d.ts +652 -0
- package/dist/react-data-kit-DmTzxNTc.d.cts +225 -0
- package/dist/react-data-kit-DmTzxNTc.d.ts +225 -0
- package/dist/server.cjs +222 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.cts +68 -0
- package/dist/server.d.ts +68 -0
- package/dist/server.js +216 -0
- package/dist/server.js.map +1 -0
- package/dist/types/component.d.ts +106 -0
- package/dist/types/database/mongo.d.ts +129 -0
- package/dist/types/hook.d.ts +100 -0
- package/dist/types/index.cjs +15 -0
- package/dist/types/index.cjs.map +1 -0
- package/dist/types/index.d.cts +252 -0
- package/dist/types/index.d.ts +12 -0
- package/dist/types/index.js +13 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/react-data-kit.d.ts +95 -0
- package/dist/types/selectable.d.ts +43 -0
- package/package.json +127 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,652 @@
|
|
|
1
|
+
import * as React$1 from 'react';
|
|
2
|
+
import React__default, { ReactNode } from 'react';
|
|
3
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* react-data-kit - Database Types (Mongo)
|
|
7
|
+
*
|
|
8
|
+
* MongoDB-specific types.
|
|
9
|
+
* Consolidated into a single file for simplicity.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Sort order for database queries
|
|
13
|
+
*/
|
|
14
|
+
type TSortOrder = 1 | -1 | 'asc' | 'desc' | 'ascending' | 'descending';
|
|
15
|
+
/**
|
|
16
|
+
* ObjectId placeholder type - compatible with MongoDB ObjectId.
|
|
17
|
+
*/
|
|
18
|
+
type TObjectId = {
|
|
19
|
+
toString(): string;
|
|
20
|
+
toHexString(): string;
|
|
21
|
+
equals(otherId: TObjectId | string): boolean;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Generic document type that represents a database document with an ID.
|
|
25
|
+
*/
|
|
26
|
+
type TDocument<TId = unknown> = {
|
|
27
|
+
_id: TId;
|
|
28
|
+
createdAt?: Date;
|
|
29
|
+
updatedAt?: Date;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Mongo document base (includes common Mongo-only fields).
|
|
33
|
+
*/
|
|
34
|
+
type TMongoDocument = TDocument<string | TObjectId> & {
|
|
35
|
+
__v?: number;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Hydrated document type - represents a document with methods.
|
|
39
|
+
*/
|
|
40
|
+
type THydratedDocument<T, TId = unknown> = T & TDocument<TId>;
|
|
41
|
+
/**
|
|
42
|
+
* Hydrated Mongo document.
|
|
43
|
+
*/
|
|
44
|
+
type TMongoHydratedDocument<T> = T & TMongoDocument & {
|
|
45
|
+
toObject(): T;
|
|
46
|
+
toJSON(): T;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Filter operators for individual fields (Mongo subset)
|
|
50
|
+
*/
|
|
51
|
+
type TMongoFilterOperators<T> = {
|
|
52
|
+
$eq?: T;
|
|
53
|
+
$ne?: T;
|
|
54
|
+
$gt?: T;
|
|
55
|
+
$gte?: T;
|
|
56
|
+
$lt?: T;
|
|
57
|
+
$lte?: T;
|
|
58
|
+
$in?: T[];
|
|
59
|
+
$nin?: T[];
|
|
60
|
+
$exists?: boolean;
|
|
61
|
+
$all?: T extends Array<infer U> ? U[] : never;
|
|
62
|
+
$elemMatch?: T extends Array<infer U> ? TMongoFilterQuery<U> : never;
|
|
63
|
+
$size?: number;
|
|
64
|
+
$regex?: string | RegExp;
|
|
65
|
+
$options?: string;
|
|
66
|
+
$type?: string | number;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Mongo root operators.
|
|
70
|
+
*/
|
|
71
|
+
type TMongoRootFilterOperators<T> = {
|
|
72
|
+
$and?: TMongoFilterQuery<T>[];
|
|
73
|
+
$or?: TMongoFilterQuery<T>[];
|
|
74
|
+
$nor?: TMongoFilterQuery<T>[];
|
|
75
|
+
$not?: TMongoFilterQuery<T>;
|
|
76
|
+
$text?: {
|
|
77
|
+
$search: string;
|
|
78
|
+
$language?: string;
|
|
79
|
+
$caseSensitive?: boolean;
|
|
80
|
+
$diacriticSensitive?: boolean;
|
|
81
|
+
};
|
|
82
|
+
$where?: string | ((this: T) => boolean);
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Mongo filter query type.
|
|
86
|
+
*/
|
|
87
|
+
type TMongoFilterQuery<T> = {
|
|
88
|
+
[P in keyof T]?: T[P] | TMongoFilterOperators<T[P]>;
|
|
89
|
+
} & TMongoRootFilterOperators<T>;
|
|
90
|
+
/**
|
|
91
|
+
* Populate options for query builder.
|
|
92
|
+
*/
|
|
93
|
+
type TPopulateOptions = {
|
|
94
|
+
path: string;
|
|
95
|
+
select?: string | Record<string, 0 | 1>;
|
|
96
|
+
model?: string;
|
|
97
|
+
match?: Record<string, unknown>;
|
|
98
|
+
populate?: TPopulateOptions | TPopulateOptions[];
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Query builder for chaining query operations.
|
|
102
|
+
*/
|
|
103
|
+
type TQueryBuilder<TResult, TQueryHelpers = object> = Promise<TResult> & {
|
|
104
|
+
sort(options: Record<string, TSortOrder>): TQueryBuilder<TResult, TQueryHelpers>;
|
|
105
|
+
limit(count: number): TQueryBuilder<TResult, TQueryHelpers>;
|
|
106
|
+
skip(count: number): TQueryBuilder<TResult, TQueryHelpers>;
|
|
107
|
+
select(fields: string | Record<string, 0 | 1>): TQueryBuilder<TResult, TQueryHelpers>;
|
|
108
|
+
populate(path: string | TPopulateOptions): TQueryBuilder<TResult, TQueryHelpers>;
|
|
109
|
+
lean(): TQueryBuilder<TResult, TQueryHelpers>;
|
|
110
|
+
exec(): Promise<TResult>;
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Generic Model type.
|
|
114
|
+
*/
|
|
115
|
+
type TModel<TRawDocType = unknown, TQueryHelpers = object, TId = unknown, TFilter = unknown> = {
|
|
116
|
+
countDocuments(filter?: TFilter): Promise<number>;
|
|
117
|
+
find(filter?: TFilter): TQueryBuilder<TRawDocType[], TQueryHelpers>;
|
|
118
|
+
findOne(filter?: TFilter): TQueryBuilder<TRawDocType | null, TQueryHelpers>;
|
|
119
|
+
findById(id: TId): TQueryBuilder<TRawDocType | null, TQueryHelpers>;
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Convenience alias for a Mongo-backed model.
|
|
123
|
+
*/
|
|
124
|
+
type TMongoModel<TRawDocType = unknown, TQueryHelpers = object> = TModel<TRawDocType, TQueryHelpers, string | TObjectId, TMongoFilterQuery<TRawDocType>>;
|
|
125
|
+
/**
|
|
126
|
+
* Extract raw document type from a Model
|
|
127
|
+
*/
|
|
128
|
+
type TExtractDocType<M> = M extends TModel<infer TRawDocType, unknown, unknown, unknown> ? TRawDocType : never;
|
|
129
|
+
/**
|
|
130
|
+
* Extract hydrated document type from a Model
|
|
131
|
+
*/
|
|
132
|
+
type TExtractHydratedDoc<M> = M extends TModel<infer TRawDocType, unknown, infer TId, unknown> ? THydratedDocument<TRawDocType, TId> : never;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* react-data-kit - React Data Kit Types
|
|
136
|
+
*
|
|
137
|
+
* Core types for the react-data-kit server action and components.
|
|
138
|
+
*/
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Sort options type that references keys from the item type
|
|
142
|
+
*/
|
|
143
|
+
type TSortOptions<T> = {
|
|
144
|
+
[K in keyof T]?: TSortOrder;
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* Sort entry for array-based sorting
|
|
148
|
+
*/
|
|
149
|
+
type TSortEntry = {
|
|
150
|
+
path: string;
|
|
151
|
+
value: 1 | -1;
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* Filter configuration for automatic filtering
|
|
155
|
+
*/
|
|
156
|
+
type TFilterConfig = {
|
|
157
|
+
[key: string]: {
|
|
158
|
+
type: 'regex' | 'exact';
|
|
159
|
+
field?: string;
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
/**
|
|
163
|
+
* Custom filter configuration
|
|
164
|
+
* Allows defining custom filter functions for specific filter keys
|
|
165
|
+
*/
|
|
166
|
+
type TFilterCustomConfig<T = unknown> = {
|
|
167
|
+
[id: string]: (data: unknown) => TMongoFilterQuery<T>;
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* Variant of TFilterCustomConfig that allows customizing the returned filter shape.
|
|
171
|
+
* Useful for Mongo (operator-based) vs. other ORMs (where clauses) in the future.
|
|
172
|
+
*/
|
|
173
|
+
type TFilterCustomConfigWithFilter<TDoc = unknown, TFilter = TMongoFilterQuery<TDoc>> = {
|
|
174
|
+
[id: string]: (data: unknown) => TFilter;
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* React Data Kit server action input
|
|
178
|
+
*/
|
|
179
|
+
type TDataKitInput<T = unknown> = {
|
|
180
|
+
action?: 'FETCH';
|
|
181
|
+
page?: number;
|
|
182
|
+
limit?: number;
|
|
183
|
+
sort?: TSortOptions<T>;
|
|
184
|
+
sorts?: TSortEntry[];
|
|
185
|
+
query?: Record<string, unknown>;
|
|
186
|
+
filter?: Record<string, unknown>;
|
|
187
|
+
filterConfig?: TFilterConfig;
|
|
188
|
+
filterCustom?: TFilterCustomConfig<T>;
|
|
189
|
+
};
|
|
190
|
+
/**
|
|
191
|
+
* React Data Kit server action result
|
|
192
|
+
*/
|
|
193
|
+
type TDataKitResult<R> = {
|
|
194
|
+
type: 'ITEMS';
|
|
195
|
+
items: R[];
|
|
196
|
+
documentTotal: number;
|
|
197
|
+
};
|
|
198
|
+
/**
|
|
199
|
+
* Pagination info for client-side use
|
|
200
|
+
*/
|
|
201
|
+
type TPaginationInfo = {
|
|
202
|
+
currentPage: number;
|
|
203
|
+
totalPages: number;
|
|
204
|
+
totalItems: number;
|
|
205
|
+
itemsPerPage: number;
|
|
206
|
+
hasNextPage: boolean;
|
|
207
|
+
hasPrevPage: boolean;
|
|
208
|
+
};
|
|
209
|
+
/**
|
|
210
|
+
* Calculate pagination info from react-data-kit result
|
|
211
|
+
*/
|
|
212
|
+
declare const calculatePagination: (page: number, limit: number, total: number) => TPaginationInfo;
|
|
213
|
+
/**
|
|
214
|
+
* React Data Kit Adapter Interface
|
|
215
|
+
* Defines the contract for a database adapter.
|
|
216
|
+
*/
|
|
217
|
+
type TDataKitAdapter<T> = (params: Readonly<{
|
|
218
|
+
filter: Record<string, unknown>;
|
|
219
|
+
sorts: TSortEntry[];
|
|
220
|
+
limit: number;
|
|
221
|
+
page: number;
|
|
222
|
+
skip: number;
|
|
223
|
+
input: TDataKitInput<T>;
|
|
224
|
+
}>) => Promise<{
|
|
225
|
+
items: T[];
|
|
226
|
+
total: number;
|
|
227
|
+
}>;
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* react-data-kit - Hook Types
|
|
231
|
+
*
|
|
232
|
+
* Types for the react-data-kit hooks and state management.
|
|
233
|
+
*/
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* React Data Kit controller state
|
|
237
|
+
*/
|
|
238
|
+
type TDataKitState<T = unknown> = {
|
|
239
|
+
page: number;
|
|
240
|
+
limit: number;
|
|
241
|
+
sorts: TSortEntry[];
|
|
242
|
+
filter: Record<string, unknown>;
|
|
243
|
+
filterConfig?: TFilterConfig;
|
|
244
|
+
query?: Record<string, unknown>;
|
|
245
|
+
isLoading: boolean;
|
|
246
|
+
error: Error | null;
|
|
247
|
+
items: T[];
|
|
248
|
+
total: number;
|
|
249
|
+
};
|
|
250
|
+
/**
|
|
251
|
+
* React Data Kit controller actions
|
|
252
|
+
*/
|
|
253
|
+
type TDataKitActions<T = unknown, R = unknown> = {
|
|
254
|
+
setPage: (page: number) => void;
|
|
255
|
+
setLimit: (limit: number) => void;
|
|
256
|
+
setSort: (path: string, value: 1 | -1 | null, append?: boolean) => void;
|
|
257
|
+
setSorts: (sorts: TSortEntry[]) => void;
|
|
258
|
+
setFilter: (key: string, value: unknown) => void;
|
|
259
|
+
setFilters: (filters: Record<string, unknown>) => void;
|
|
260
|
+
clearFilters: () => void;
|
|
261
|
+
setQuery: (key: string, value: unknown) => void;
|
|
262
|
+
refresh: () => Promise<void>;
|
|
263
|
+
reset: () => void;
|
|
264
|
+
getInput: () => TDataKitInput<T>;
|
|
265
|
+
setItems: (items: R[]) => void;
|
|
266
|
+
setItemAt: (index: number, item: R) => void;
|
|
267
|
+
deleteItemAt: (index: number) => void;
|
|
268
|
+
itemPush: (item: R, position?: 0 | 1) => void;
|
|
269
|
+
deleteBulk: (items: R[]) => void;
|
|
270
|
+
};
|
|
271
|
+
/**
|
|
272
|
+
* Combined react-data-kit controller return type
|
|
273
|
+
*/
|
|
274
|
+
type TUseDataKitReturn<T = unknown, R = unknown> = {
|
|
275
|
+
page: number;
|
|
276
|
+
limit: number;
|
|
277
|
+
sorts: TSortEntry[];
|
|
278
|
+
filter: Record<string, unknown>;
|
|
279
|
+
filterConfig?: TFilterConfig;
|
|
280
|
+
query?: Record<string, unknown>;
|
|
281
|
+
items: R[];
|
|
282
|
+
total: number;
|
|
283
|
+
state: {
|
|
284
|
+
isLoading: boolean;
|
|
285
|
+
error: Error | null;
|
|
286
|
+
};
|
|
287
|
+
actions: TDataKitActions<T, R>;
|
|
288
|
+
};
|
|
289
|
+
/**
|
|
290
|
+
* React Data Kit controller options
|
|
291
|
+
*/
|
|
292
|
+
type TDataKitControllerOptions<T = unknown, R = unknown> = {
|
|
293
|
+
initial?: {
|
|
294
|
+
page?: number;
|
|
295
|
+
limit?: number;
|
|
296
|
+
sorts?: TSortEntry[];
|
|
297
|
+
filter?: Record<string, unknown>;
|
|
298
|
+
query?: Record<string, unknown>;
|
|
299
|
+
};
|
|
300
|
+
state?: 'memory' | 'search-params';
|
|
301
|
+
filterConfig?: TFilterConfig;
|
|
302
|
+
action: (input: TDataKitInput<T>) => Promise<TDataKitResult<R>>;
|
|
303
|
+
onSuccess?: (result: TDataKitResult<R>) => void;
|
|
304
|
+
onError?: (error: Error) => void;
|
|
305
|
+
autoFetch?: boolean;
|
|
306
|
+
debounce?: number;
|
|
307
|
+
};
|
|
308
|
+
/**
|
|
309
|
+
* Column definition for react-data-kit (headless)
|
|
310
|
+
*/
|
|
311
|
+
type TDataKitColumn<T = unknown> = {
|
|
312
|
+
id: string;
|
|
313
|
+
header: string;
|
|
314
|
+
accessor: keyof T | ((item: T) => unknown);
|
|
315
|
+
sortable?: boolean;
|
|
316
|
+
sortPath?: string;
|
|
317
|
+
filterable?: boolean;
|
|
318
|
+
filterKey?: string;
|
|
319
|
+
width?: string | number;
|
|
320
|
+
minWidth?: string | number;
|
|
321
|
+
maxWidth?: string | number;
|
|
322
|
+
align?: 'left' | 'center' | 'right';
|
|
323
|
+
cell?: (value: unknown, item: T, index: number) => React.ReactNode;
|
|
324
|
+
headerCell?: (column: TDataKitColumn<T>) => React.ReactNode;
|
|
325
|
+
hidden?: boolean;
|
|
326
|
+
sticky?: 'left' | 'right';
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* react-data-kit - Selectable Types
|
|
331
|
+
*
|
|
332
|
+
* Types for selectable/multi-select functionality in tables.
|
|
333
|
+
*/
|
|
334
|
+
/**
|
|
335
|
+
* Selection state for a table
|
|
336
|
+
*/
|
|
337
|
+
type TSelectionState<T = string> = {
|
|
338
|
+
selectedIds: Set<T>;
|
|
339
|
+
isAllSelected: boolean;
|
|
340
|
+
isIndeterminate: boolean;
|
|
341
|
+
};
|
|
342
|
+
/**
|
|
343
|
+
* Selection actions for a table
|
|
344
|
+
*/
|
|
345
|
+
type TSelectionActions<T = string> = {
|
|
346
|
+
select: (id: T) => void;
|
|
347
|
+
deselect: (id: T) => void;
|
|
348
|
+
toggle: (id: T) => void;
|
|
349
|
+
selectAll: (ids: T[]) => void;
|
|
350
|
+
deselectAll: () => void;
|
|
351
|
+
toggleAll: (ids: T[]) => void;
|
|
352
|
+
isSelected: (id: T) => boolean;
|
|
353
|
+
getSelectedArray: () => T[];
|
|
354
|
+
};
|
|
355
|
+
/**
|
|
356
|
+
* Combined selection hook return type
|
|
357
|
+
*/
|
|
358
|
+
type TUseSelectionReturn<T = string> = TSelectionState<T> & TSelectionActions<T>;
|
|
359
|
+
/**
|
|
360
|
+
* Selection mode for tables
|
|
361
|
+
*/
|
|
362
|
+
type TSelectionMode = 'single' | 'multiple' | 'none';
|
|
363
|
+
/**
|
|
364
|
+
* Selectable item type
|
|
365
|
+
*/
|
|
366
|
+
type TSelectable = {
|
|
367
|
+
id: string;
|
|
368
|
+
selected?: boolean;
|
|
369
|
+
disabled?: boolean;
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* react-data-kit - Component Types
|
|
374
|
+
*
|
|
375
|
+
* Types for the React Data Kit component and related UI elements.
|
|
376
|
+
*/
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Extract the item type from a TDataKitResult
|
|
380
|
+
*/
|
|
381
|
+
type TExtractDataKitItemFromResult<R> = R extends TDataKitResult<infer I> ? I : R extends {
|
|
382
|
+
items: (infer I)[];
|
|
383
|
+
} ? I : R extends [true, infer Ok] ? Ok extends {
|
|
384
|
+
items: (infer I)[];
|
|
385
|
+
} ? I : never : never;
|
|
386
|
+
/**
|
|
387
|
+
* Extract the item type from an action function's return type
|
|
388
|
+
*/
|
|
389
|
+
type TExtractDataKitItemType<T> = T extends (input: TDataKitInput<unknown>) => infer R ? TExtractDataKitItemFromResult<Awaited<R>> : never;
|
|
390
|
+
/**
|
|
391
|
+
* Column definition for React Data Kit component
|
|
392
|
+
*/
|
|
393
|
+
type TDataKitComponentColumn<TItem, TRowState = unknown> = {
|
|
394
|
+
head: React.ReactNode;
|
|
395
|
+
body: (props: Readonly<{
|
|
396
|
+
item: TItem;
|
|
397
|
+
index: number;
|
|
398
|
+
state: TRowState;
|
|
399
|
+
setState: React.Dispatch<React.SetStateAction<TRowState>>;
|
|
400
|
+
setItem: (item: TItem) => void;
|
|
401
|
+
deleteItem: () => void;
|
|
402
|
+
}>) => React.ReactNode;
|
|
403
|
+
sortable?: {
|
|
404
|
+
path: string;
|
|
405
|
+
default: 1 | -1 | 0;
|
|
406
|
+
};
|
|
407
|
+
};
|
|
408
|
+
/**
|
|
409
|
+
* Base filter item properties
|
|
410
|
+
*/
|
|
411
|
+
type TDataKitFilterItemBase = {
|
|
412
|
+
id: string;
|
|
413
|
+
label: string;
|
|
414
|
+
placeholder?: string;
|
|
415
|
+
};
|
|
416
|
+
/**
|
|
417
|
+
* Text filter item
|
|
418
|
+
*/
|
|
419
|
+
type TDataKitFilterItemText = TDataKitFilterItemBase & {
|
|
420
|
+
type: 'TEXT';
|
|
421
|
+
defaultValue?: string;
|
|
422
|
+
};
|
|
423
|
+
/**
|
|
424
|
+
* Select filter item - dataset is required
|
|
425
|
+
*/
|
|
426
|
+
type TDataKitFilterItemSelect = TDataKitFilterItemBase & {
|
|
427
|
+
type: 'SELECT';
|
|
428
|
+
dataset: {
|
|
429
|
+
id: string;
|
|
430
|
+
name: string;
|
|
431
|
+
label: string;
|
|
432
|
+
}[];
|
|
433
|
+
defaultValue?: string;
|
|
434
|
+
};
|
|
435
|
+
/**
|
|
436
|
+
* Boolean filter item
|
|
437
|
+
*/
|
|
438
|
+
type TDataKitFilterItemBoolean = TDataKitFilterItemBase & {
|
|
439
|
+
type: 'BOOLEAN';
|
|
440
|
+
defaultValue?: boolean;
|
|
441
|
+
};
|
|
442
|
+
/**
|
|
443
|
+
* Filter item configuration - discriminated union for type safety
|
|
444
|
+
*/
|
|
445
|
+
type TDataKitFilterItem = TDataKitFilterItemText | TDataKitFilterItemSelect | TDataKitFilterItemBoolean;
|
|
446
|
+
/**
|
|
447
|
+
* Bulk action definition for selectable tables
|
|
448
|
+
*/
|
|
449
|
+
type TDataKitBulkAction<TItem> = {
|
|
450
|
+
name: string;
|
|
451
|
+
function: (selectedItems: TItem[]) => Promise<[boolean, {
|
|
452
|
+
deselectAll?: boolean;
|
|
453
|
+
updatedItems?: TItem[];
|
|
454
|
+
} | string]>;
|
|
455
|
+
};
|
|
456
|
+
/**
|
|
457
|
+
* Controller for external table manipulation
|
|
458
|
+
*/
|
|
459
|
+
type TDataKitComponentController<TItem> = {
|
|
460
|
+
itemPush: (item: TItem, position?: 0 | 1) => void;
|
|
461
|
+
refetchData: () => void;
|
|
462
|
+
deleteBulk: (items: TItem[]) => void;
|
|
463
|
+
getSelectedItems: () => TItem[];
|
|
464
|
+
clearSelection: () => void;
|
|
465
|
+
};
|
|
466
|
+
/**
|
|
467
|
+
* Item with ID for selection purposes
|
|
468
|
+
*/
|
|
469
|
+
type TDataKitSelectableItem = {
|
|
470
|
+
id: string | number;
|
|
471
|
+
};
|
|
472
|
+
/**
|
|
473
|
+
* State persistence mode
|
|
474
|
+
*/
|
|
475
|
+
type TDataKitStateMode = 'memory' | 'search-params';
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* react-data-kit - Server Action
|
|
479
|
+
*
|
|
480
|
+
* The main server-side function for handling table data fetching
|
|
481
|
+
* with pagination, filtering, and sorting.
|
|
482
|
+
*/
|
|
483
|
+
|
|
484
|
+
type TDataKitServerActionOptions<T, R> = {
|
|
485
|
+
input: TDataKitInput<T>;
|
|
486
|
+
adapter: TDataKitAdapter<T> | TMongoModel<T>;
|
|
487
|
+
item: (item: T) => Promise<R> | R;
|
|
488
|
+
filter?: (filterInput?: Record<string, unknown>) => TMongoFilterQuery<T>;
|
|
489
|
+
filterCustom?: TFilterCustomConfigWithFilter<T, TMongoFilterQuery<T>>;
|
|
490
|
+
defaultSort?: TSortOptions<T>;
|
|
491
|
+
};
|
|
492
|
+
declare const dataKitServerAction: <T, R>(props: Readonly<TDataKitServerActionOptions<T, R>>) => Promise<TDataKitResult<R>>;
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* react-data-kit - Mongoose Adapter
|
|
496
|
+
*
|
|
497
|
+
* Database adapter for Mongoose/MongoDB.
|
|
498
|
+
*/
|
|
499
|
+
|
|
500
|
+
declare const mongooseAdapter: <M extends TMongoModel<unknown, object>, DocType = TExtractDocType<M>>(model: M, options?: Readonly<{
|
|
501
|
+
filter?: (filterInput?: Record<string, unknown>) => TMongoFilterQuery<DocType>;
|
|
502
|
+
filterCustom?: TFilterCustomConfigWithFilter<DocType, TMongoFilterQuery<DocType>>;
|
|
503
|
+
defaultSort?: TSortOptions<DocType>;
|
|
504
|
+
}>) => TDataKitAdapter<DocType>;
|
|
505
|
+
|
|
506
|
+
/**
|
|
507
|
+
* react-data-kit - Memory Adapter
|
|
508
|
+
*
|
|
509
|
+
* In-memory adapter for demos, tests, and local playgrounds.
|
|
510
|
+
* Implements the React Data Kit adapter contract over an array dataset.
|
|
511
|
+
*/
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* Creates an adapter that pages/filters/sorts an in-memory dataset.
|
|
515
|
+
*/
|
|
516
|
+
declare const adapterMemory: <T extends Record<string, unknown>>(dataset: ReadonlyArray<T>, options?: Readonly<{
|
|
517
|
+
/** default behavior for filter keys not present in filterConfig */
|
|
518
|
+
defaultFilterType?: "regex" | "exact";
|
|
519
|
+
}>) => TDataKitAdapter<T>;
|
|
520
|
+
|
|
521
|
+
/**
|
|
522
|
+
* react-data-kit - Server Utilities
|
|
523
|
+
*/
|
|
524
|
+
|
|
525
|
+
/**
|
|
526
|
+
* Helper to escape regex special characters in a string
|
|
527
|
+
*/
|
|
528
|
+
declare const escapeRegex: (str: string) => string;
|
|
529
|
+
/**
|
|
530
|
+
* Create a search filter for multiple fields
|
|
531
|
+
*
|
|
532
|
+
* @example
|
|
533
|
+
* ```typescript
|
|
534
|
+
* filterCustom: {
|
|
535
|
+
* search: createSearchFilter(['name', 'email', 'phone'])
|
|
536
|
+
* }
|
|
537
|
+
* ```
|
|
538
|
+
*/
|
|
539
|
+
declare const createSearchFilter: <T>(fields: (keyof T | string)[]) => (value: unknown) => TMongoFilterQuery<T>;
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* react-data-kit - useDataKit Hook
|
|
543
|
+
*
|
|
544
|
+
* React hook for managing react-data-kit state and actions.
|
|
545
|
+
*/
|
|
546
|
+
|
|
547
|
+
declare const useDataKit: <T = unknown, R = unknown>(props: Readonly<TDataKitControllerOptions<T, R>>) => TUseDataKitReturn<T, R>;
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* react-data-kit - useSelection Hook
|
|
551
|
+
*
|
|
552
|
+
* React hook for managing table row selection.
|
|
553
|
+
*/
|
|
554
|
+
|
|
555
|
+
declare const useSelection: <T = string>(initialSelected?: T[]) => TUseSelectionReturn<T>;
|
|
556
|
+
declare const useSelectionWithTotal: <T = string>(totalItems: T[], initialSelected?: T[]) => Omit<TUseSelectionReturn<T>, "toggleAll"> & {
|
|
557
|
+
isAllSelected: boolean;
|
|
558
|
+
isIndeterminate: boolean;
|
|
559
|
+
toggleAll: () => void;
|
|
560
|
+
};
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* react-data-kit - usePagination Hook
|
|
564
|
+
*
|
|
565
|
+
* React hook for calculating pagination state.
|
|
566
|
+
*/
|
|
567
|
+
|
|
568
|
+
type TUsePaginationReturn = TPaginationInfo & {
|
|
569
|
+
pages: (number | 'ellipsis')[];
|
|
570
|
+
firstPage: number;
|
|
571
|
+
lastPage: number;
|
|
572
|
+
};
|
|
573
|
+
declare const usePagination: (props: Readonly<{
|
|
574
|
+
page: number;
|
|
575
|
+
limit: number;
|
|
576
|
+
total: number;
|
|
577
|
+
siblingCount?: number;
|
|
578
|
+
}>) => TUsePaginationReturn;
|
|
579
|
+
|
|
580
|
+
type TDataKitContextValue<T = unknown, R = unknown> = TUseDataKitReturn<T, R>;
|
|
581
|
+
declare const createDataKitContext: <T = unknown, R = unknown>() => {
|
|
582
|
+
DataKitProvider: (props: Readonly<{
|
|
583
|
+
value: TDataKitContextValue<T, R>;
|
|
584
|
+
children: ReactNode;
|
|
585
|
+
}>) => react_jsx_runtime.JSX.Element;
|
|
586
|
+
useDataKitContext: () => TDataKitContextValue<T, R>;
|
|
587
|
+
Context: React$1.Context<TDataKitContextValue<T, R> | null>;
|
|
588
|
+
};
|
|
589
|
+
declare const DefaultDataKitProvider: (props: Readonly<{
|
|
590
|
+
value: TDataKitContextValue<unknown, unknown>;
|
|
591
|
+
children: ReactNode;
|
|
592
|
+
}>) => react_jsx_runtime.JSX.Element;
|
|
593
|
+
declare const useDefaultDataKitContext: () => TDataKitContextValue<unknown, unknown>;
|
|
594
|
+
declare const DefaultDataKitContext: React$1.Context<TDataKitContextValue<unknown, unknown> | null>;
|
|
595
|
+
|
|
596
|
+
declare const DataKit: <TAction extends (input: TDataKitInput<unknown>) => Promise<TDataKitResult<TDataKitSelectableItem>>>(props: Readonly<{
|
|
597
|
+
action: TAction;
|
|
598
|
+
query?: Record<string, unknown>;
|
|
599
|
+
filterConfig?: TFilterConfig;
|
|
600
|
+
filters?: TDataKitFilterItem[];
|
|
601
|
+
limit?: {
|
|
602
|
+
default: number;
|
|
603
|
+
};
|
|
604
|
+
className?: string;
|
|
605
|
+
autoFetch?: boolean;
|
|
606
|
+
debounce?: number;
|
|
607
|
+
refetchInterval?: number;
|
|
608
|
+
state?: TDataKitStateMode;
|
|
609
|
+
manual?: boolean;
|
|
610
|
+
children: (dataKit: TUseDataKitReturn<unknown, TExtractDataKitItemType<TAction>>) => React__default.ReactNode;
|
|
611
|
+
}>) => react_jsx_runtime.JSX.Element;
|
|
612
|
+
|
|
613
|
+
/**
|
|
614
|
+
* react-data-kit - Utility Functions
|
|
615
|
+
*
|
|
616
|
+
* Helper utilities for client-side operations.
|
|
617
|
+
*/
|
|
618
|
+
|
|
619
|
+
/**
|
|
620
|
+
* Get the value from an item using a column accessor
|
|
621
|
+
*/
|
|
622
|
+
declare const getColumnValue: <T>(item: T, column: TDataKitColumn<T>) => unknown;
|
|
623
|
+
/**
|
|
624
|
+
* Get the sort value for a column
|
|
625
|
+
*/
|
|
626
|
+
declare const getSortValue: (sorts: TSortEntry[], path: string) => 1 | -1 | null;
|
|
627
|
+
/**
|
|
628
|
+
* Get the next sort value in the cycle: null -> 1 -> -1 -> null
|
|
629
|
+
*/
|
|
630
|
+
declare const getNextSortValue: (current: 1 | -1 | null) => 1 | -1 | null;
|
|
631
|
+
/**
|
|
632
|
+
* Format a number with commas
|
|
633
|
+
*/
|
|
634
|
+
declare const formatNumber: (num: number) => string;
|
|
635
|
+
/**
|
|
636
|
+
* Debounce a function
|
|
637
|
+
*/
|
|
638
|
+
declare const debounce: <T extends (...args: unknown[]) => unknown>(fn: T, delay: number) => ((...args: Parameters<T>) => void);
|
|
639
|
+
/**
|
|
640
|
+
* Throttle a function
|
|
641
|
+
*/
|
|
642
|
+
declare const throttle: <T extends (...args: unknown[]) => unknown>(fn: T, limit: number) => ((...args: Parameters<T>) => void);
|
|
643
|
+
/**
|
|
644
|
+
* Create a stable object key from sort entries
|
|
645
|
+
*/
|
|
646
|
+
declare const sortEntriesToKey: (sorts: TSortEntry[]) => string;
|
|
647
|
+
/**
|
|
648
|
+
* Parse a sort key back to sort entries
|
|
649
|
+
*/
|
|
650
|
+
declare const keyToSortEntries: (key: string) => TSortEntry[];
|
|
651
|
+
|
|
652
|
+
export { DataKit, DefaultDataKitContext as DataKitContext, DefaultDataKitProvider as DataKitProvider, type TDataKitActions, type TDataKitAdapter, type TDataKitBulkAction, type TDataKitColumn, type TDataKitComponentColumn, type TDataKitComponentController, type TDataKitContextValue, type TDataKitControllerOptions, type TDataKitFilterItem, type TDataKitInput, type TDataKitResult, type TDataKitSelectableItem, type TDataKitServerActionOptions, type TDataKitState, type TDataKitStateMode, type TDocument, type TExtractDataKitItemType, type TExtractDocType, type TExtractHydratedDoc, type TFilterConfig, type TFilterCustomConfig, type TFilterCustomConfigWithFilter, type THydratedDocument, type TModel, type TMongoDocument, type TMongoFilterOperators, type TMongoFilterQuery, type TMongoHydratedDocument, type TMongoModel, type TMongoRootFilterOperators, type TObjectId, type TPaginationInfo, type TPopulateOptions, type TQueryBuilder, type TSelectable, type TSelectionActions, type TSelectionMode, type TSelectionState, type TSortEntry, type TSortOptions, type TSortOrder, type TUseDataKitReturn, type TUsePaginationReturn, type TUseSelectionReturn, adapterMemory, calculatePagination, createDataKitContext, createSearchFilter, dataKitServerAction, debounce, escapeRegex, formatNumber, getColumnValue, getNextSortValue, getSortValue, keyToSortEntries, mongooseAdapter, sortEntriesToKey, throttle, useDataKit, useDefaultDataKitContext as useDataKitContext, usePagination, useSelection, useSelectionWithTotal };
|