@panneau/data 4.0.8 → 4.0.14

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.
@@ -0,0 +1,460 @@
1
+ import * as _tanstack_react_query from '@tanstack/react-query';
2
+ import { QueryClient } from '@tanstack/react-query';
3
+ import * as _tanstack_query_core from '@tanstack/query-core';
4
+ import * as react_jsx_runtime from 'react/jsx-runtime';
5
+ import { ReactNode } from 'react';
6
+
7
+ declare function useData(loadData: any, { initialData, autoload }?: {
8
+ initialData?: any;
9
+ autoload?: boolean;
10
+ }): {
11
+ data: any;
12
+ load: (...args: any[]) => any;
13
+ loading: boolean;
14
+ error: boolean;
15
+ };
16
+
17
+ declare function useItems$1({ store, url, paginated: initialPaginated, query: initialQuery, onQueryChange, queryConfig, keepData, ...oldProps }: {
18
+ [x: string]: any;
19
+ store: any;
20
+ url: any;
21
+ paginated?: boolean;
22
+ query?: any;
23
+ onQueryChange: any;
24
+ queryConfig?: any;
25
+ keepData?: boolean;
26
+ }): {
27
+ items: any;
28
+ allItems: any;
29
+ pages: any;
30
+ pageItems: any;
31
+ pagination: {
32
+ page: any;
33
+ lastPage: any;
34
+ total: any;
35
+ };
36
+ total: any;
37
+ lastPage: any;
38
+ loaded: boolean;
39
+ allLoaded: boolean;
40
+ loading: boolean;
41
+ loadNextPage: () => void;
42
+ loadPage: (newPage: any) => void;
43
+ reloadPage: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<unknown, Error>>;
44
+ reload: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<unknown, Error>>;
45
+ reset: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<unknown, Error>>;
46
+ updateItem: (item: any) => void;
47
+ status: "error" | "success";
48
+ error: Error;
49
+ isError: true;
50
+ isPending: false;
51
+ isLoadingError: false;
52
+ isRefetchError: true;
53
+ isSuccess: false;
54
+ isPlaceholderData: false;
55
+ dataUpdatedAt: number;
56
+ errorUpdatedAt: number;
57
+ failureCount: number;
58
+ failureReason: Error;
59
+ errorUpdateCount: number;
60
+ isFetchedAfterMount: boolean;
61
+ isInitialLoading: boolean;
62
+ isPaused: boolean;
63
+ isStale: boolean;
64
+ isEnabled: boolean;
65
+ fetchStatus: _tanstack_react_query.FetchStatus;
66
+ promise: Promise<unknown>;
67
+ } | {
68
+ items: any;
69
+ allItems: any;
70
+ pages: any;
71
+ pageItems: any;
72
+ pagination: {
73
+ page: any;
74
+ lastPage: any;
75
+ total: any;
76
+ };
77
+ total: any;
78
+ lastPage: any;
79
+ loaded: boolean;
80
+ allLoaded: boolean;
81
+ loading: boolean;
82
+ loadNextPage: () => void;
83
+ loadPage: (newPage: any) => void;
84
+ reloadPage: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<unknown, Error>>;
85
+ reload: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<unknown, Error>>;
86
+ reset: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<unknown, Error>>;
87
+ updateItem: (item: any) => void;
88
+ status: "error" | "success";
89
+ error: Error;
90
+ isError: false;
91
+ isPending: false;
92
+ isLoadingError: false;
93
+ isRefetchError: false;
94
+ isSuccess: true;
95
+ isPlaceholderData: false;
96
+ dataUpdatedAt: number;
97
+ errorUpdatedAt: number;
98
+ failureCount: number;
99
+ failureReason: Error;
100
+ errorUpdateCount: number;
101
+ isFetchedAfterMount: boolean;
102
+ isInitialLoading: boolean;
103
+ isPaused: boolean;
104
+ isStale: boolean;
105
+ isEnabled: boolean;
106
+ fetchStatus: _tanstack_react_query.FetchStatus;
107
+ promise: Promise<unknown>;
108
+ };
109
+
110
+ declare function useItems({ getPage, getItems, page, count, items: providedItems, pages: initialPages, getPageFromResponse, getItemsFromResponse, onItemsLoaded, onPageLoaded, onLoaded, onError, }: {
111
+ getPage?: any;
112
+ getItems?: any;
113
+ page?: any;
114
+ count?: number;
115
+ items?: any;
116
+ pages?: any;
117
+ getPageFromResponse?: ({ pagination: { page: currentPage, last_page: lastPage, total, per_page: perPage }, data: items, }: {
118
+ pagination: {
119
+ page: any;
120
+ last_page: any;
121
+ total: any;
122
+ per_page: any;
123
+ };
124
+ data: any;
125
+ }) => {
126
+ page: number;
127
+ lastPage: number;
128
+ total: number;
129
+ count: number;
130
+ items: any;
131
+ };
132
+ getItemsFromResponse?: (data: any) => any;
133
+ onItemsLoaded?: any;
134
+ onPageLoaded?: any;
135
+ onLoaded?: any;
136
+ onError?: any;
137
+ }): {
138
+ items: any;
139
+ pages: any;
140
+ pageItems: any;
141
+ total: any;
142
+ lastPage: any;
143
+ loaded: boolean;
144
+ allLoaded: boolean;
145
+ loading: boolean;
146
+ loadNextPage: () => any;
147
+ loadPage: (pageToLoad: any) => any;
148
+ reloadPage: () => any;
149
+ reload: () => any;
150
+ reset: () => void;
151
+ updateItem: (newItem: any) => void;
152
+ };
153
+
154
+ declare function useItemsStore(store: any, { url, getPage, getItems, getPageFromResponse, getItemsFromResponse, page: initialPage, count: initialCount, query, onQueryChange, queryConfig, keepData, }: {
155
+ url?: any;
156
+ getPage?: any;
157
+ getItems?: any;
158
+ getPageFromResponse?: any;
159
+ getItemsFromResponse?: any;
160
+ page?: any;
161
+ count?: any;
162
+ query?: any;
163
+ onQueryChange?: any;
164
+ queryConfig?: any;
165
+ keepData?: boolean;
166
+ }): {
167
+ isLoading: false;
168
+ isFetching: boolean;
169
+ isRefetching: boolean;
170
+ isFetched: boolean;
171
+ items: any;
172
+ pages: any;
173
+ allItems: any;
174
+ loading: boolean;
175
+ loaded: boolean;
176
+ reload: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<unknown, Error>>;
177
+ loadPage: (newPage: any) => void;
178
+ loadNextPage: () => void;
179
+ updateItem: (item: any) => void;
180
+ pagination: {
181
+ page: any;
182
+ lastPage: any;
183
+ total: any;
184
+ };
185
+ error: Error;
186
+ isError: true;
187
+ isPending: false;
188
+ isLoadingError: false;
189
+ isRefetchError: true;
190
+ isSuccess: false;
191
+ isPlaceholderData: false;
192
+ status: "error";
193
+ dataUpdatedAt: number;
194
+ errorUpdatedAt: number;
195
+ failureCount: number;
196
+ failureReason: Error;
197
+ errorUpdateCount: number;
198
+ isFetchedAfterMount: boolean;
199
+ isInitialLoading: boolean;
200
+ isPaused: boolean;
201
+ isStale: boolean;
202
+ isEnabled: boolean;
203
+ fetchStatus: _tanstack_react_query.FetchStatus;
204
+ promise: Promise<unknown>;
205
+ } | {
206
+ isLoading: false;
207
+ isFetching: boolean;
208
+ isRefetching: boolean;
209
+ isFetched: boolean;
210
+ items: any;
211
+ pages: any;
212
+ allItems: any;
213
+ loading: boolean;
214
+ loaded: boolean;
215
+ reload: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<unknown, Error>>;
216
+ loadPage: (newPage: any) => void;
217
+ loadNextPage: () => void;
218
+ updateItem: (item: any) => void;
219
+ pagination: {
220
+ page: any;
221
+ lastPage: any;
222
+ total: any;
223
+ };
224
+ error: null;
225
+ isError: false;
226
+ isPending: false;
227
+ isLoadingError: false;
228
+ isRefetchError: false;
229
+ isSuccess: true;
230
+ isPlaceholderData: false;
231
+ status: "success";
232
+ dataUpdatedAt: number;
233
+ errorUpdatedAt: number;
234
+ failureCount: number;
235
+ failureReason: Error;
236
+ errorUpdateCount: number;
237
+ isFetchedAfterMount: boolean;
238
+ isInitialLoading: boolean;
239
+ isPaused: boolean;
240
+ isStale: boolean;
241
+ isEnabled: boolean;
242
+ fetchStatus: _tanstack_react_query.FetchStatus;
243
+ promise: Promise<unknown>;
244
+ };
245
+
246
+ declare function useResourceDestroy(resource: any, id?: any): {
247
+ destroy: (providedId: any) => any;
248
+ loading: boolean;
249
+ };
250
+
251
+ declare function useResourceItem(resource: any, id: any, opts: any): {
252
+ load: (...args: any[]) => any;
253
+ loading: boolean;
254
+ error: boolean;
255
+ item: any;
256
+ };
257
+
258
+ declare function useResourceItems(resource: any, query?: any, page?: any, count?: any, opts?: any): {
259
+ isLoading: false;
260
+ isFetching: boolean;
261
+ isRefetching: boolean;
262
+ isFetched: boolean;
263
+ pages: any;
264
+ allItems: any;
265
+ loading: boolean;
266
+ loaded: boolean;
267
+ reload: (options?: _tanstack_query_core.RefetchOptions) => Promise<_tanstack_query_core.QueryObserverResult<unknown, Error>>;
268
+ loadPage: (newPage: any) => void;
269
+ loadNextPage: () => void;
270
+ updateItem: (item: any) => void;
271
+ pagination: {
272
+ page: any;
273
+ lastPage: any;
274
+ total: any;
275
+ };
276
+ error: Error;
277
+ isError: true;
278
+ isPending: false;
279
+ isLoadingError: false;
280
+ isRefetchError: true;
281
+ isSuccess: false;
282
+ isPlaceholderData: false;
283
+ status: "error";
284
+ dataUpdatedAt: number;
285
+ errorUpdatedAt: number;
286
+ failureCount: number;
287
+ failureReason: Error;
288
+ errorUpdateCount: number;
289
+ isFetchedAfterMount: boolean;
290
+ isInitialLoading: boolean;
291
+ isPaused: boolean;
292
+ isStale: boolean;
293
+ isEnabled: boolean;
294
+ fetchStatus: _tanstack_query_core.FetchStatus;
295
+ promise: Promise<unknown>;
296
+ items: any;
297
+ } | {
298
+ isLoading: false;
299
+ isFetching: boolean;
300
+ isRefetching: boolean;
301
+ isFetched: boolean;
302
+ pages: any;
303
+ allItems: any;
304
+ loading: boolean;
305
+ loaded: boolean;
306
+ reload: (options?: _tanstack_query_core.RefetchOptions) => Promise<_tanstack_query_core.QueryObserverResult<unknown, Error>>;
307
+ loadPage: (newPage: any) => void;
308
+ loadNextPage: () => void;
309
+ updateItem: (item: any) => void;
310
+ pagination: {
311
+ page: any;
312
+ lastPage: any;
313
+ total: any;
314
+ };
315
+ error: null;
316
+ isError: false;
317
+ isPending: false;
318
+ isLoadingError: false;
319
+ isRefetchError: false;
320
+ isSuccess: true;
321
+ isPlaceholderData: false;
322
+ status: "success";
323
+ dataUpdatedAt: number;
324
+ errorUpdatedAt: number;
325
+ failureCount: number;
326
+ failureReason: Error;
327
+ errorUpdateCount: number;
328
+ isFetchedAfterMount: boolean;
329
+ isInitialLoading: boolean;
330
+ isPaused: boolean;
331
+ isStale: boolean;
332
+ isEnabled: boolean;
333
+ fetchStatus: _tanstack_query_core.FetchStatus;
334
+ promise: Promise<unknown>;
335
+ items: any;
336
+ };
337
+
338
+ declare function useResourceCreate(resource: any): {
339
+ store: (data: any) => any;
340
+ loading: boolean;
341
+ };
342
+
343
+ declare function useResourceUpdate(resource: any, id: any): {
344
+ update: (data: any) => any;
345
+ loading: boolean;
346
+ };
347
+
348
+ declare function useResourceClone(resource: any, id?: any): {
349
+ clone: (providedId: any) => any;
350
+ loading: boolean;
351
+ };
352
+
353
+ declare function useResourceRestore(resource: any, id?: any): {
354
+ restore: (providedId: any) => any;
355
+ loading: boolean;
356
+ };
357
+
358
+ declare class Base {
359
+ constructor(opts?: {});
360
+ options: {
361
+ baseUrl: any;
362
+ onUnauthorized: any;
363
+ routes: {};
364
+ generateUrl: any;
365
+ };
366
+ requestGet(path: any, query?: any, opts?: any): any;
367
+ requestPost(path: any, data: any, opts?: any): any;
368
+ requestPut(path: any, data: any, opts?: any): any;
369
+ requestPatch(path: any, data: any, opts?: any): any;
370
+ requestDelete(path: any): any;
371
+ route(route: any, params: any): any;
372
+ getFullUrl(path: any): any;
373
+ onError(err: any): any;
374
+ }
375
+
376
+ declare class AuthApi {
377
+ constructor(api: any, opts: any);
378
+ api: any;
379
+ options: any;
380
+ check(): any;
381
+ login(email: any, password: any): any;
382
+ register(data: any): any;
383
+ logout(): Promise<Response>;
384
+ requestPassword(email: any): any;
385
+ resetPassword(data: any): any;
386
+ }
387
+
388
+ declare class AccountApi {
389
+ constructor(api: any, opts: any);
390
+ api: any;
391
+ options: any;
392
+ update(data: any): any;
393
+ updatePassword(data: any): any;
394
+ updateTaxes(data: any): any;
395
+ delete(data: any): any;
396
+ }
397
+
398
+ declare class MediasApi extends Base {
399
+ find(id: any): any;
400
+ get(query?: {}, page?: number, count?: number): any;
401
+ getTrashed(query?: {}, page?: number, count?: number): any;
402
+ getTags(query?: {}, count?: number): any;
403
+ create(data: any): any;
404
+ update(id: any, data: any): any;
405
+ trash(id: any): any;
406
+ restore(id: any): any;
407
+ delete(id: any): any;
408
+ replace(id: any, data: any): any;
409
+ }
410
+
411
+ declare class ResourcesApi {
412
+ constructor(api: any);
413
+ api: any;
414
+ resourceRoute({ id, has_routes: hasRoutes }: {
415
+ id: any;
416
+ has_routes?: boolean;
417
+ }, route: any, params: any): any;
418
+ find(resource: any, id: any): any;
419
+ get(resource: any, query?: {}, page?: number, count?: number): any;
420
+ store(resource: any, data: any): any;
421
+ update(resource: any, id: any, data: any): any;
422
+ destroy(resource: any, id: any): any;
423
+ clone(resource: any, id: any, data?: any): any;
424
+ restore(resource: any, id: any, data?: any): any;
425
+ }
426
+
427
+ declare class Api extends Base {
428
+ auth: AuthApi;
429
+ account: AccountApi;
430
+ medias: MediasApi;
431
+ resources: ResourcesApi;
432
+ }
433
+
434
+ interface ApiProviderProps {
435
+ api?: Api | null;
436
+ baseUrl?: string;
437
+ onUnauthorized?: (() => void) | null;
438
+ children: ReactNode;
439
+ }
440
+ declare const useApi: () => Api;
441
+ declare const ApiProvider: ({ api: initialApi, baseUrl, onUnauthorized, children, }: ApiProviderProps) => react_jsx_runtime.JSX.Element;
442
+
443
+ type QueryInitialData = Record<string, unknown> | Array<Record<string, unknown>>;
444
+ interface QueryProviderProps {
445
+ config?: Record<string, unknown> | null;
446
+ initialKey?: string[] | null;
447
+ initialData?: QueryInitialData | null;
448
+ children: ReactNode;
449
+ }
450
+ declare const useQueryContext: () => QueryClient;
451
+ declare const QueryProvider: ({ config: initialConfig, initialKey, initialData, children, }: QueryProviderProps) => react_jsx_runtime.JSX.Element;
452
+
453
+ interface DataProviderProps {
454
+ api?: Api | null;
455
+ apiBaseUrl?: string;
456
+ children?: ReactNode;
457
+ }
458
+ declare function DataProvider({ api, apiBaseUrl, children }: DataProviderProps): react_jsx_runtime.JSX.Element;
459
+
460
+ export { Api, ApiProvider, Base as BaseApi, DataProvider, QueryProvider, useApi, useData, useItems$1 as useItems, useItems as useItemsLegacy, useItemsStore, useQueryContext, useResourceClone, useResourceDestroy, useResourceItem, useResourceItems, useResourceRestore, useResourceCreate as useResourceStore, useResourceUpdate };
@@ -1,5 +1,4 @@
1
- import PropTypes from 'prop-types';
2
- import { useState, useCallback, useEffect, useMemo, useRef, useContext, createContext } from 'react';
1
+ import { useState, useCallback, useEffect, useMemo, useRef, use, createContext } from 'react';
3
2
  import { useUrlGenerator } from '@panneau/core/contexts';
4
3
  import _createClass from '@babel/runtime/helpers/createClass';
5
4
  import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
@@ -15,7 +14,7 @@ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
15
14
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
16
15
  import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
17
16
  import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
18
- import isEmpty from 'lodash-es/isEmpty';
17
+ import isEmpty from 'lodash/isEmpty';
19
18
 
20
19
  var useData = function useData(loadData) {
21
20
  var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
@@ -1269,15 +1268,10 @@ var Api = /*#__PURE__*/function (_Base) {
1269
1268
  }(Base);
1270
1269
 
1271
1270
  /* eslint-disable react/jsx-props-no-spreading */
1271
+
1272
1272
  var ApiContext = /*#__PURE__*/createContext(null);
1273
1273
  var useApi = function useApi() {
1274
- return useContext(ApiContext);
1275
- };
1276
- var propTypes$1 = {
1277
- api: PropTypes.instanceOf(Api),
1278
- baseUrl: PropTypes.string,
1279
- onUnauthorized: PropTypes.func,
1280
- children: PropTypes.node.isRequired
1274
+ return use(ApiContext);
1281
1275
  };
1282
1276
  var ApiProvider = function ApiProvider(_ref) {
1283
1277
  var _ref$api = _ref.api,
@@ -1296,12 +1290,11 @@ var ApiProvider = function ApiProvider(_ref) {
1296
1290
  onUnauthorized: onUnauthorized
1297
1291
  });
1298
1292
  }, [previousApi, initialApi, baseUrl]);
1299
- return /*#__PURE__*/jsx(ApiContext.Provider, {
1293
+ return /*#__PURE__*/jsx(ApiContext, {
1300
1294
  value: api,
1301
1295
  children: children
1302
1296
  });
1303
1297
  };
1304
- ApiProvider.propTypes = propTypes$1;
1305
1298
 
1306
1299
  var useResourceDestroy = function useResourceDestroy(resource) {
1307
1300
  var id = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
@@ -1485,13 +1478,7 @@ var useResourceRestore = function useResourceRestore(resource) {
1485
1478
 
1486
1479
  var QueryContext = /*#__PURE__*/createContext(null);
1487
1480
  var useQueryContext = function useQueryContext() {
1488
- return useContext(QueryContext);
1489
- };
1490
- var propTypes = {
1491
- config: PropTypes.shape({}),
1492
- initialKey: PropTypes.arrayOf(PropTypes.string),
1493
- initialData: PropTypes.oneOfType([PropTypes.shape({}), PropTypes.arrayOf(PropTypes.shape({}))]),
1494
- children: PropTypes.node.isRequired
1481
+ return use(QueryContext);
1495
1482
  };
1496
1483
  var QueryProvider = function QueryProvider(_ref) {
1497
1484
  var _ref$config = _ref.config,
@@ -1519,7 +1506,6 @@ var QueryProvider = function QueryProvider(_ref) {
1519
1506
  children: children
1520
1507
  });
1521
1508
  };
1522
- QueryProvider.propTypes = propTypes;
1523
1509
 
1524
1510
  function DataProvider(_ref) {
1525
1511
  var _ref$api = _ref.api,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@panneau/data",
3
- "version": "4.0.8",
3
+ "version": "4.0.14",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "javascript"
@@ -34,39 +34,41 @@
34
34
  ],
35
35
  "license": "ISC",
36
36
  "type": "module",
37
- "module": "es/index.js",
37
+ "module": "dist/index.js",
38
+ "types": "dist/index.d.ts",
38
39
  "exports": {
39
- ".": "./es/index.js"
40
+ ".": {
41
+ "default": "./dist/index.js",
42
+ "types": "./dist/index.d.ts"
43
+ }
40
44
  },
41
45
  "files": [
42
- "lib",
43
- "es",
46
+ "dist",
44
47
  "assets"
45
48
  ],
46
49
  "scripts": {
47
50
  "prepublishOnly": "npm run build",
48
- "build": "../../scripts/prepare-package.sh"
51
+ "build": "../../scripts/prepare-package.sh --types"
49
52
  },
50
53
  "devDependencies": {
51
- "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
52
- "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
54
+ "react": "^19.0.0",
55
+ "react-dom": "^19.0.0"
53
56
  },
54
57
  "peerDependencies": {
55
- "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
56
- "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
58
+ "react": "^19.0.0",
59
+ "react-dom": "^19.0.0"
57
60
  },
58
61
  "dependencies": {
59
62
  "@babel/runtime": "^7.12.5",
60
63
  "@folklore/fetch": "^0.1.21",
61
64
  "@folklore/routes": "^0.2.44",
62
- "@panneau/core": "^4.0.8",
65
+ "@panneau/core": "^4.0.14",
63
66
  "@tanstack/react-query": "^5.29.2",
64
- "lodash-es": "^4.17.21",
65
- "prop-types": "^15.7.2",
67
+ "lodash": "^4.17.21",
66
68
  "query-string": "^9.0.0"
67
69
  },
68
70
  "publishConfig": {
69
71
  "access": "public"
70
72
  },
71
- "gitHead": "c9fa22382cc63416e2bfaac780f31794b11c8c64"
73
+ "gitHead": "ce35c2ddb30a7be2efe951882d9826dca577f5d4"
72
74
  }