fastapi-rtk 0.2.6 → 0.2.8

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.
Files changed (90) hide show
  1. package/dist/.bundled/jsonforms/cjs/packages/jsonforms/src/hooks/useContextProps.cjs +1 -1
  2. package/dist/.bundled/jsonforms/cjs/packages/jsonforms/src/layouts/MantineCategorizationLayoutRenderer.cjs +63 -0
  3. package/dist/.bundled/jsonforms/cjs/packages/jsonforms/src/layouts/MantineGroupLayoutRenderer.cjs +3 -3
  4. package/dist/.bundled/jsonforms/cjs/packages/jsonforms/src/layouts/MantineHotizontalLayoutRenderer.cjs +2 -2
  5. package/dist/.bundled/jsonforms/cjs/packages/jsonforms/src/layouts/MantineVerticalLayoutRenderer.cjs +3 -3
  6. package/dist/.bundled/jsonforms/cjs/packages/jsonforms/src/renderers/mantineRenderers.cjs +2 -0
  7. package/dist/.bundled/jsonforms/esm/packages/jsonforms/src/hooks/useContextProps.mjs +1 -1
  8. package/dist/.bundled/jsonforms/esm/packages/jsonforms/src/layouts/MantineCategorizationLayoutRenderer.mjs +63 -0
  9. package/dist/.bundled/jsonforms/esm/packages/jsonforms/src/layouts/MantineGroupLayoutRenderer.mjs +3 -3
  10. package/dist/.bundled/jsonforms/esm/packages/jsonforms/src/layouts/MantineHotizontalLayoutRenderer.mjs +2 -2
  11. package/dist/.bundled/jsonforms/esm/packages/jsonforms/src/layouts/MantineVerticalLayoutRenderer.mjs +3 -3
  12. package/dist/.bundled/jsonforms/esm/packages/jsonforms/src/renderers/mantineRenderers.mjs +2 -0
  13. package/dist/core/cjs/Tables/NextGenDataGrid/NextGenDataGrid.cjs +1 -2
  14. package/dist/core/cjs/Tables/NextGenDataGrid/hooks/useColumns/Body.cjs +4 -5
  15. package/dist/core/cjs/Tables/NextGenDataGrid/hooks/useColumns/ColumnHeaderFilterInput/ColumnHeaderFilterInput.cjs +1 -2
  16. package/dist/core/cjs/Tables/NextGenDataGrid/hooks/useColumns/FilterModeDescription.cjs +2 -2
  17. package/dist/core/cjs/Tables/NextGenDataGrid/hooks/useColumns/useColumns.cjs +9 -9
  18. package/dist/core/cjs/Tables/NextGenDataGrid/utils.cjs +0 -3
  19. package/dist/core/cjs/Wrappers/ApiProvider/ApiProvider.cjs +1 -1
  20. package/dist/core/cjs/Wrappers/ApiProvider/Contexts/ApiContext.cjs +4 -40
  21. package/dist/core/cjs/Wrappers/ApiProvider/Contexts/BulkActionsContext.cjs +6 -11
  22. package/dist/core/cjs/Wrappers/ApiProvider/Contexts/FormContext.cjs +11 -38
  23. package/dist/core/cjs/Wrappers/Provider/Contexts/AuthContext.cjs +4 -19
  24. package/dist/core/cjs/Wrappers/Provider/Contexts/InfoContext.cjs +4 -14
  25. package/dist/core/cjs/Wrappers/Provider/Provider.cjs +1 -1
  26. package/dist/core/cjs/hooks/api/useApi.cjs +1 -8
  27. package/dist/core/cjs/hooks/api/useBulkActions.cjs +1 -8
  28. package/dist/core/cjs/hooks/api/useForms.cjs +4 -8
  29. package/dist/core/cjs/hooks/auth/useAuth.cjs +1 -4
  30. package/dist/core/cjs/hooks/auth/useInfo.cjs +1 -4
  31. package/dist/core/esm/Tables/NextGenDataGrid/NextGenDataGrid.mjs +2 -3
  32. package/dist/core/esm/Tables/NextGenDataGrid/hooks/useColumns/Body.mjs +2 -3
  33. package/dist/core/esm/Tables/NextGenDataGrid/hooks/useColumns/ColumnHeaderFilterInput/ColumnHeaderFilterInput.mjs +2 -3
  34. package/dist/core/esm/Tables/NextGenDataGrid/hooks/useColumns/FilterModeDescription.mjs +2 -2
  35. package/dist/core/esm/Tables/NextGenDataGrid/hooks/useColumns/useColumns.mjs +5 -5
  36. package/dist/core/esm/Tables/NextGenDataGrid/utils.mjs +1 -4
  37. package/dist/core/esm/Wrappers/ApiProvider/ApiProvider.mjs +4 -4
  38. package/dist/core/esm/Wrappers/ApiProvider/Contexts/ApiContext.mjs +4 -40
  39. package/dist/core/esm/Wrappers/ApiProvider/Contexts/BulkActionsContext.mjs +6 -11
  40. package/dist/core/esm/Wrappers/ApiProvider/Contexts/FormContext.mjs +11 -38
  41. package/dist/core/esm/Wrappers/Provider/Contexts/AuthContext.mjs +4 -19
  42. package/dist/core/esm/Wrappers/Provider/Contexts/InfoContext.mjs +4 -14
  43. package/dist/core/esm/Wrappers/Provider/Provider.mjs +3 -3
  44. package/dist/core/esm/hooks/api/useApi.mjs +2 -9
  45. package/dist/core/esm/hooks/api/useBulkActions.mjs +2 -9
  46. package/dist/core/esm/hooks/api/useForms.mjs +5 -9
  47. package/dist/core/esm/hooks/auth/useAuth.mjs +2 -5
  48. package/dist/core/esm/hooks/auth/useInfo.mjs +2 -5
  49. package/dist/core/lib/Tables/NextGenDataGrid/hooks/useData.d.ts +1 -1
  50. package/dist/core/lib/Tables/NextGenDataGrid/utils.d.ts +0 -1
  51. package/dist/core/lib/Wrappers/ApiProvider/Contexts/ApiContext.d.ts +4 -131
  52. package/dist/core/lib/Wrappers/ApiProvider/Contexts/BulkActionsContext.d.ts +4 -27
  53. package/dist/core/lib/Wrappers/ApiProvider/Contexts/FormContext.d.ts +8 -28
  54. package/dist/core/lib/Wrappers/Provider/Contexts/AuthContext.d.ts +4 -28
  55. package/dist/core/lib/Wrappers/Provider/Contexts/InfoContext.d.ts +4 -21
  56. package/dist/core/lib/hooks/api/useApi.d.ts +415 -61
  57. package/dist/core/lib/hooks/api/useBulkActions.d.ts +25 -8
  58. package/dist/core/lib/hooks/api/useForms.d.ts +72 -13
  59. package/dist/core/lib/hooks/auth/useAuth.d.ts +80 -17
  60. package/dist/core/lib/hooks/auth/useInfo.d.ts +51 -9
  61. package/dist/jsonforms/cjs/hooks/useContextProps.cjs +1 -1
  62. package/dist/jsonforms/cjs/layouts/MantineCategorizationLayoutRenderer.cjs +63 -0
  63. package/dist/jsonforms/cjs/layouts/MantineGroupLayoutRenderer.cjs +3 -3
  64. package/dist/jsonforms/cjs/layouts/MantineHotizontalLayoutRenderer.cjs +2 -2
  65. package/dist/jsonforms/cjs/layouts/MantineVerticalLayoutRenderer.cjs +3 -3
  66. package/dist/jsonforms/cjs/renderers/mantineRenderers.cjs +2 -0
  67. package/dist/jsonforms/esm/hooks/useContextProps.mjs +1 -1
  68. package/dist/jsonforms/esm/layouts/MantineCategorizationLayoutRenderer.mjs +63 -0
  69. package/dist/jsonforms/esm/layouts/MantineGroupLayoutRenderer.mjs +3 -3
  70. package/dist/jsonforms/esm/layouts/MantineHotizontalLayoutRenderer.mjs +2 -2
  71. package/dist/jsonforms/esm/layouts/MantineVerticalLayoutRenderer.mjs +3 -3
  72. package/dist/jsonforms/esm/renderers/mantineRenderers.mjs +2 -0
  73. package/dist/jsonforms/lib/layouts/MantineCategorizationLayoutRenderer.d.ts +2 -0
  74. package/dist/jsonforms/lib/renderers/mantineRenderers.d.ts +3 -9
  75. package/dist/utils/cjs/createSafeContext/createSafeContext.cjs +17 -0
  76. package/dist/utils/cjs/getByPath/getByPath.cjs +4 -0
  77. package/dist/utils/cjs/index.cjs +6 -0
  78. package/dist/utils/cjs/mergeProps/mergeProps.cjs +6 -0
  79. package/dist/utils/esm/createSafeContext/createSafeContext.mjs +17 -0
  80. package/dist/utils/esm/getByPath/getByPath.mjs +4 -0
  81. package/dist/utils/esm/index.mjs +6 -0
  82. package/dist/utils/esm/mergeProps/mergeProps.mjs +6 -0
  83. package/dist/utils/lib/createSafeContext/createSafeContext.d.ts +14 -0
  84. package/dist/utils/lib/createSafeContext/index.d.ts +1 -0
  85. package/dist/utils/lib/getByPath/getByPath.d.ts +1 -0
  86. package/dist/utils/lib/getByPath/index.d.ts +1 -0
  87. package/dist/utils/lib/index.d.ts +3 -0
  88. package/dist/utils/lib/mergeProps/index.d.ts +1 -0
  89. package/dist/utils/lib/mergeProps/mergeProps.d.ts +1 -0
  90. package/package.json +1 -1
@@ -1,67 +1,421 @@
1
- export function useApi(): {
1
+ export function useApi(options: SafeContextOptions): ApiContext;
2
+ export type APIColumnInfo = {
3
+ /**
4
+ * - The description of the column.
5
+ */
6
+ description: string;
7
+ /**
8
+ * - The label of the column.
9
+ */
10
+ label: string;
11
+ /**
12
+ * - The name of the column.
13
+ */
14
+ name: string;
15
+ /**
16
+ * - Whether the column is required.
17
+ */
18
+ required: boolean;
19
+ /**
20
+ * - The type of the column.
21
+ */
22
+ type: string;
23
+ /**
24
+ * - Whether the column is unique.
25
+ */
26
+ unique: boolean;
27
+ };
28
+ export type APIColumnRelationInfo = {
29
+ /**
30
+ * - The description of the column.
31
+ */
32
+ description: string;
33
+ /**
34
+ * - The label of the column.
35
+ */
36
+ label: string;
37
+ /**
38
+ * - The name of the column.
39
+ */
40
+ name: string;
41
+ /**
42
+ * - Whether the column is required.
43
+ */
44
+ required: boolean;
45
+ /**
46
+ * - The type of the column.
47
+ */
48
+ type: string;
49
+ /**
50
+ * - Whether the column is unique.
51
+ */
52
+ unique: boolean;
53
+ /**
54
+ * - The count of items in the column.
55
+ */
56
+ count: number;
57
+ /**
58
+ * - The values of the column.
59
+ */
60
+ values: {
61
+ id: number | string;
62
+ value: string;
63
+ }[];
64
+ };
65
+ export type APIColumnFilter = {
66
+ /**
67
+ * - The name of the column to filter.
68
+ */
69
+ name: string;
70
+ /**
71
+ * - The operator to use for filtering (e.g., 'eq', 'ne', 'gt', 'lt').
72
+ */
73
+ operator: string;
74
+ };
75
+ export type APIFilter = {
76
+ /**
77
+ * - An array of filters to apply.
78
+ */
79
+ filters: APIColumnFilter[];
80
+ /**
81
+ * - The label for the filter.
82
+ */
83
+ label: string;
84
+ /**
85
+ * - The schema of the filter, containing column information.
86
+ */
87
+ schema: APIColumnInfo | APIColumnRelationInfo;
88
+ };
89
+ export type APIJSONFormsSchema = {
90
+ /**
91
+ * - The type of the schema, typically 'object'.
92
+ */
93
+ type: string;
94
+ /**
95
+ * - The properties of the schema.
96
+ */
97
+ properties: Record<string, any>;
98
+ /**
99
+ * - An array of required properties.
100
+ */
101
+ required?: string[];
102
+ };
103
+ export type APIJSONFormsUISchemaElement = {
104
+ /**
105
+ * - The type of the UI schema element (e.g., 'Control', 'Group', 'List', etc.).
106
+ */
107
+ type: string;
108
+ /**
109
+ * - The JSON pointer to the schema property this element is associated with.
110
+ */
111
+ scope: string;
112
+ /**
113
+ * - The label for the UI schema element.
114
+ */
115
+ label?: string;
116
+ /**
117
+ * - The description for the UI schema element.
118
+ */
119
+ description?: string;
120
+ /**
121
+ * - Additional options for the UI schema element.
122
+ */
123
+ options?: Record<string, any>;
124
+ /**
125
+ * - A rule for conditional rendering of the UI schema element.
126
+ */
127
+ rule?: Record<string, any>;
128
+ };
129
+ export type APIJSONFormsUISchema = {
130
+ /**
131
+ * - The type of the UI schema, typically 'VerticalLayout' or 'HorizontalLayout'.
132
+ */
133
+ type: string;
134
+ /**
135
+ * - An array of UI schema elements.
136
+ */
137
+ elements: Array<APIJSONFormsUISchemaElement | APIJSONFormsUISchema>;
138
+ /**
139
+ * - The label for the UI schema.
140
+ */
141
+ label?: string;
142
+ /**
143
+ * - The description for the UI schema.
144
+ */
145
+ description?: string;
146
+ /**
147
+ * - Additional options for the UI schema.
148
+ */
149
+ options?: Record<string, any>;
150
+ /**
151
+ * - A rule for conditional rendering of the UI schema.
152
+ */
153
+ rule?: Record<string, any>;
154
+ };
155
+ export type APIInfo = {
156
+ /**
157
+ * - The title for the add modal or section.
158
+ */
159
+ add_title: string;
160
+ /**
161
+ * - List of columns that can be added.
162
+ */
163
+ add_columns: Array<APIColumnInfo | APIColumnRelationInfo>;
164
+ /**
165
+ * - JSONForms schema for adding items.
166
+ */
167
+ add_schema: APIJSONFormsSchema;
168
+ /**
169
+ * - JSONForms UI schema for adding items.
170
+ */
171
+ add_uischema?: APIJSONFormsUISchema;
172
+ /**
173
+ * - The title for the edit modal or section.
174
+ */
175
+ edit_title: string;
176
+ /**
177
+ * - List of columns that can be edited.
178
+ */
179
+ edit_columns: Array<APIColumnInfo | APIColumnRelationInfo>;
180
+ /**
181
+ * - JSONForms schema for editing items.
182
+ */
183
+ edit_schema: APIJSONFormsSchema;
184
+ /**
185
+ * - JSONForms UI schema for editing items.
186
+ */
187
+ edit_uischema?: APIJSONFormsUISchema;
188
+ /**
189
+ * - A mapping of filter names to filter definitions.
190
+ */
191
+ filters: Record<string, APIFilter>;
192
+ /**
193
+ * - Additional options for filters specified in the API.
194
+ */
195
+ filter_options?: Record<string, any>;
196
+ /**
197
+ * - List of permissions for the API (e.g., 'can_post', 'can_put', 'can_delete').
198
+ */
199
+ permissions: string[];
200
+ };
201
+ export type APIData = {
202
+ /**
203
+ * - The title of the list.
204
+ */
205
+ list_title: string;
206
+ /**
207
+ * - An array of IDs for the items.
208
+ */
209
+ ids: number[] | string[];
210
+ /**
211
+ * - A mapping of column names to their labels.
212
+ */
213
+ label_columns: Record<string, string>;
214
+ /**
215
+ * - A mapping of column names to their descriptions.
216
+ */
217
+ description_columns: Record<string, string>;
218
+ /**
219
+ * - An array of column names to be displayed in the list.
220
+ */
221
+ list_columns: string[];
222
+ /**
223
+ * - An array of column names to be used for ordering.
224
+ */
225
+ order_columns: string[];
226
+ /**
227
+ * - An array of objects representing the API response data.
228
+ */
229
+ result: Record<string, any>[];
230
+ /**
231
+ * - The API path.
232
+ */
233
+ path: string;
234
+ /**
235
+ * - The query parameters used in the API request.
236
+ */
237
+ queryParams: Record<string, any>;
238
+ };
239
+ export type APIQueryParamsFilter = {
240
+ /**
241
+ * - The column name to filter on.
242
+ */
243
+ col: string;
244
+ /**
245
+ * - The operator to use for filtering (e.g., 'eq', 'ne', 'gt', 'lt').
246
+ */
247
+ opr: string;
248
+ /**
249
+ * - The value to filter by.
250
+ */
251
+ value: any;
252
+ };
253
+ export type APISpecialKey = {
254
+ /**
255
+ * - The key to be used when retrieving general props for `NextGenDataGrid`. Typically `all`. but can be `_all` if `all` is in the list of columns.
256
+ */
257
+ all: string;
258
+ /**
259
+ * - The key to be used when retrieving actions for `NextGenDataGrid`. Typically `actions`, but can be `_actions` if `actions` is in the list of columns.
260
+ */
261
+ actions: string;
262
+ };
263
+ export type APIQueryParams = {
264
+ /**
265
+ * - An array of column names to be included in the response.
266
+ */
267
+ columns: string[];
268
+ /**
269
+ * - An array of filters to apply to the query.
270
+ */
271
+ filters: APIQueryParamsFilter[];
272
+ /**
273
+ * - The column name to order the results by.
274
+ */
275
+ order_column?: string;
276
+ /**
277
+ * - The direction of the order ('asc' or 'desc').
278
+ */
279
+ order_direction?: "asc" | "desc";
280
+ /**
281
+ * - The page number for pagination.
282
+ */
283
+ page: number;
284
+ /**
285
+ * - The number of items per page for pagination.
286
+ */
287
+ page_size: number;
288
+ /**
289
+ * - A global filter string to apply to the query.
290
+ */
291
+ global_filter?: string;
292
+ };
293
+ export type APIStreaming = {
294
+ /**
295
+ * - The streaming data, organized by the page number.
296
+ */
297
+ data: Record<string, Record<string, any>[]>;
298
+ /**
299
+ * - Indicates whether the streaming has ended.
300
+ */
301
+ isEnd: boolean;
302
+ /**
303
+ * - A function to fetch the next page of streaming data.
304
+ */
305
+ fetch: () => void;
306
+ };
307
+ export type APIDownloadOptions = {
308
+ /**
309
+ * - Whether to export the data in basic or detailed mode.
310
+ */
311
+ export_mode?: "basic" | "detailed";
312
+ /**
313
+ * - The delimiter to use in the exported file (e.g., ',', ';'). Default is `,`.
314
+ */
315
+ delimiter?: string;
316
+ /**
317
+ * - The character to use for quoting in the exported file. Default is `"`.
318
+ */
319
+ quotechar?: string;
320
+ };
321
+ export type APIUploadOptions = {
322
+ /**
323
+ * - The delimiter used in the uploaded file (e.g., ',', ';'). Default is `,`.
324
+ */
325
+ delimiter?: string;
326
+ /**
327
+ * - The character used for quoting in the uploaded file. Default is `"`.
328
+ */
329
+ quotechar?: string;
330
+ };
331
+ export type ApiContext = {
332
+ /**
333
+ * - The API path.
334
+ */
2
335
  path: string;
3
- data: {
4
- count: number;
5
- description_columns: Record<string, string>;
6
- ids: number[] | string[];
7
- label_columns: Record<string, string>;
8
- list_columns: string[];
9
- list_title: string;
10
- order_columns: string[];
11
- result: Record<string, any>[];
12
- path: string;
13
- queryParams: Record<string, any>;
14
- } | null;
15
- info: {
16
- add_columns: import('../../Wrappers/ApiProvider/Contexts/ApiContext').ColumnInfo[];
17
- add_title: string;
18
- add_schema: Record<string, any>;
19
- add_uischema: Record<string, any>;
20
- edit_columns: import('../../Wrappers/ApiProvider/Contexts/ApiContext').ColumnInfo[];
21
- edit_title: string;
22
- edit_schema: Record<string, any>;
23
- edit_uischema: Record<string, any>;
24
- filter_options: Record<string, any>;
25
- filters: Record<string, import('../../Wrappers/ApiProvider/Contexts/ApiContext').Filter>;
26
- permissions: string[];
27
- relations: string[] | null;
28
- path: string;
29
- } | null;
30
- queryParams: {
31
- columns: string[];
32
- filters: {
33
- col: string;
34
- opr: string;
35
- value: Any;
36
- }[];
37
- order_column: string | undefined;
38
- order_direction: string | undefined;
39
- page: number;
40
- page_size: number;
41
- global_filter: string | undefined;
42
- } | null;
336
+ /**
337
+ * - Information about the API, including schemas and UI schemas.
338
+ */
339
+ info?: APIInfo;
340
+ /**
341
+ * - The data returned by the API.
342
+ */
343
+ data?: APIData;
344
+ /**
345
+ * - The query parameters used in the API request.
346
+ */
347
+ queryParams?: APIQueryParams;
348
+ /**
349
+ * - Indicates whether the API request is currently loading.
350
+ */
43
351
  loading: boolean;
44
- error: {
352
+ /**
353
+ * - An error object if the API request failed.
354
+ */
355
+ error?: {
45
356
  message: string;
46
357
  originalError: Error;
47
- } | null;
48
- streaming: {
49
- data: Record<string, Record<string, any>[]>;
50
- isEnd: boolean;
51
- fetch: () => void;
52
358
  };
53
- specialKey: {
54
- all: string;
55
- actions: string;
56
- };
57
- setQueryParams: (partialQueryParams: any) => any;
58
- refetch: (options: any) => Promise<any>;
59
- refetchInfo: (options: any) => Promise<any>;
60
- getEntry: (id: any) => Promise<{}>;
61
- addEntry: (item: any) => Promise<{}>;
62
- updateEntry: (id: any, item: any) => Promise<{}>;
63
- deleteEntry: (id: any) => Promise<{}>;
64
- download: (label: any, { export_mode, delimiter, quotechar }?: {}) => Promise<any>;
65
- upload: (file: any, { delimiter, quotechar }?: {}) => Promise<{}>;
66
- resetError: () => any;
359
+ /**
360
+ * - An object containing streaming data and a function to fetch more data. Only available when the `ApiProvider` is configured for streaming.
361
+ */
362
+ streaming: APIStreaming;
363
+ /**
364
+ * - An object containing special keys for the API query, such as 'all' and 'actions'.
365
+ */
366
+ specialKey: APISpecialKey;
367
+ /**
368
+ * - A function to update the query parameters.
369
+ */
370
+ setQueryParams: (partialQueryParams: Partial<APIQueryParams> | ((prev: APIQueryParams) => Partial<APIQueryParams>)) => void;
371
+ /**
372
+ * - A function to refetch the data from the API.
373
+ */
374
+ refetch: (options?: {
375
+ force?: boolean;
376
+ }) => Promise<void>;
377
+ /**
378
+ * - A function to refetch the API information.
379
+ */
380
+ refetchInfo: (options?: {
381
+ force?: boolean;
382
+ }) => Promise<void>;
383
+ /**
384
+ * - A function to retrieve a specific entry by ID.
385
+ */
386
+ getEntry: (id: number | string) => Promise<Record<string, any>>;
387
+ /**
388
+ * - A function to add a new entry to the API.
389
+ */
390
+ addEntry: (item: Record<string, any>) => Promise<Record<string, any>>;
391
+ /**
392
+ * - A function to edit an existing entry in the API.
393
+ */
394
+ updateEntry: (id: number | string, item: Record<string, any>) => Promise<Record<string, any>>;
395
+ /**
396
+ * - A function to delete an entry from the API.
397
+ */
398
+ deleteEntry: (id: number | string) => Promise<Record<string, any>>;
399
+ /**
400
+ * - A function to download data from the API.
401
+ */
402
+ download: (label: string, options?: APIDownloadOptions) => Promise<void>;
403
+ /**
404
+ * - A function to upload a file to the API.
405
+ */
406
+ upload: (file: File, options?: APIUploadOptions) => Promise<Record<string, any>>;
407
+ /**
408
+ * - A function to reset the error state.
409
+ */
410
+ resetError: () => void;
411
+ };
412
+ export type SafeContextOptions = {
413
+ /**
414
+ * - Whether to throw an error if the context is not provided.
415
+ */
416
+ throwOnError?: boolean;
417
+ /**
418
+ * - The default value to return if the context is not provided.
419
+ */
420
+ defaultValue?: any;
67
421
  };
@@ -1,11 +1,28 @@
1
- export function useBulkActions(): {
2
- bulkActions: {
3
- selectedIds: any[];
4
- setSelectedIds: () => any;
5
- };
6
- dispatchBulkActions: (handler: any, data: any) => Promise<void>;
7
- error: {
1
+ export function useBulkActions(options: SafeContextOptions): BulkActionsContext;
2
+ export type SafeContextOptions = {
3
+ /**
4
+ * - Whether to throw an error if the context is not provided.
5
+ */
6
+ throwOnError?: boolean;
7
+ /**
8
+ * - The default value to return if the context is not provided.
9
+ */
10
+ defaultValue?: any;
11
+ };
12
+ export type BulkActionsContext = {
13
+ /**
14
+ * - An array containing the selected IDs and a function to set them.
15
+ */
16
+ bulkActions: [Array<string | number>, () => void | ((prev: Array<string | number>) => void)];
17
+ /**
18
+ * - A function to dispatch bulk actions with a handler and optional data. If data is not provided, it uses the currently selected IDs.
19
+ */
20
+ dispatchBulkActions: (handler: string, data?: Array<string | number>) => Promise<Record<string, any>>;
21
+ /**
22
+ * - An error object if the bulk action failed.
23
+ */
24
+ error?: {
8
25
  message: string;
9
26
  originalError: Error;
10
- } | null;
27
+ };
11
28
  };
@@ -1,15 +1,74 @@
1
- export function useForms(type?: "add" | "edit"): {
1
+ export function useForms(type: any, options: SafeContextOptions): FormsContext;
2
+ export type SafeContextOptions = {
3
+ /**
4
+ * - Whether to throw an error if the context is not provided.
5
+ */
6
+ throwOnError?: boolean;
7
+ /**
8
+ * - The default value to return if the context is not provided.
9
+ */
10
+ defaultValue?: any;
11
+ };
12
+ export type FormsContext = {
13
+ /**
14
+ * - Indicates whether the form is currently opened.
15
+ */
2
16
  opened: boolean;
3
- getOpened: () => never;
4
- setOpened: () => never;
5
- view: number;
6
- getView: () => never;
7
- setView: () => never;
8
- state: any;
9
- getState: () => never;
10
- setState: () => never;
11
- reset: () => never;
12
- item: any;
13
- getItem: () => never;
14
- setItem: () => never;
17
+ /**
18
+ * - A function to get the current opened state of the form.
19
+ */
20
+ getOpened: () => boolean;
21
+ /**
22
+ * - A function to set the opened state of the form.
23
+ */
24
+ setOpened: (newOpened: boolean) => void;
25
+ /**
26
+ * - The current view mode of the form. See `VIEW_MODE` from `@fastapi-rtk/constants` for more details.
27
+ */
28
+ view: "normal" | "fullScreen" | "overlay";
29
+ /**
30
+ * - A function to get the current view mode of the form.
31
+ */
32
+ getView: () => "normal" | "fullScreen" | "overlay";
33
+ /**
34
+ * - A function to set the view mode of the form.
35
+ */
36
+ setView: (newView: "normal" | "fullScreen" | "overlay") => void;
37
+ /**
38
+ * - The current state of the form, including errors and data.
39
+ */
40
+ state: {
41
+ errors: Record<string, any>[];
42
+ data: Record<string, any> | undefined;
43
+ };
44
+ /**
45
+ * - A function to get the current state of the form.
46
+ */
47
+ getState: () => {
48
+ errors: Record<string, any>[];
49
+ data: Record<string, any> | undefined;
50
+ };
51
+ /**
52
+ * - A function to set the state of the form.
53
+ */
54
+ setState: (newState: {
55
+ errors: Record<string, any>[];
56
+ data: Record<string, any> | undefined;
57
+ }) => void;
58
+ /**
59
+ * - A function to reset the form state to its initial state.
60
+ */
61
+ reset: () => void;
62
+ /**
63
+ * - The current item being edited in the form, if applicable.
64
+ */
65
+ item: Record<string, any> | undefined;
66
+ /**
67
+ * - A function to get the current item in the form.
68
+ */
69
+ getItem: () => Record<string, any> | undefined;
70
+ /**
71
+ * - A function to set the current item in the form.
72
+ */
73
+ setItem: (newItem: Record<string, any> | undefined) => void;
15
74
  };