@panneau/data 4.0.78 → 4.0.84

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 (3) hide show
  1. package/dist/index.d.ts +14 -22
  2. package/dist/index.js +313 -312
  3. package/package.json +2 -2
package/dist/index.d.ts CHANGED
@@ -27,9 +27,8 @@ declare function useItem<T = Item>(scope: any, id: any, loader: (id: any) => Pro
27
27
  isRefetching: boolean;
28
28
  isStale: boolean;
29
29
  isEnabled: boolean;
30
- refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<NoInfer<T>, Error>>;
30
+ refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<T, Error>>;
31
31
  fetchStatus: _tanstack_react_query.FetchStatus;
32
- promise: Promise<NoInfer<T>>;
33
32
  item: T;
34
33
  } | {
35
34
  error: null;
@@ -54,9 +53,8 @@ declare function useItem<T = Item>(scope: any, id: any, loader: (id: any) => Pro
54
53
  isRefetching: boolean;
55
54
  isStale: boolean;
56
55
  isEnabled: boolean;
57
- refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<NoInfer<T>, Error>>;
56
+ refetch: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<T, Error>>;
58
57
  fetchStatus: _tanstack_react_query.FetchStatus;
59
- promise: Promise<NoInfer<T>>;
60
58
  item: T;
61
59
  };
62
60
 
@@ -84,12 +82,13 @@ declare function useItems<T = Item>(scope: string, { url, getItems, page: initia
84
82
  isFetching: boolean;
85
83
  isRefetching: boolean;
86
84
  isFetched: boolean;
85
+ isPlaceholderData: boolean;
87
86
  items: any;
88
87
  pages: {};
89
88
  allItems: any;
90
89
  loading: boolean;
91
90
  loaded: boolean;
92
- reload: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<NoInfer<UseItemsResponse<T>>, Error>>;
91
+ reload: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<UseItemsResponse<T>, Error>>;
93
92
  updateItem: (item: any) => void;
94
93
  pagination: {
95
94
  page: number;
@@ -102,7 +101,6 @@ declare function useItems<T = Item>(scope: string, { url, getItems, page: initia
102
101
  isLoadingError: false;
103
102
  isRefetchError: true;
104
103
  isSuccess: false;
105
- isPlaceholderData: false;
106
104
  status: "error";
107
105
  dataUpdatedAt: number;
108
106
  errorUpdatedAt: number;
@@ -115,18 +113,18 @@ declare function useItems<T = Item>(scope: string, { url, getItems, page: initia
115
113
  isStale: boolean;
116
114
  isEnabled: boolean;
117
115
  fetchStatus: _tanstack_react_query.FetchStatus;
118
- promise: Promise<NoInfer<UseItemsResponse<T>>>;
119
116
  } | {
120
117
  isLoading: boolean;
121
118
  isFetching: boolean;
122
119
  isRefetching: boolean;
123
120
  isFetched: boolean;
121
+ isPlaceholderData: boolean;
124
122
  items: any;
125
123
  pages: {};
126
124
  allItems: any;
127
125
  loading: boolean;
128
126
  loaded: boolean;
129
- reload: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<NoInfer<UseItemsResponse<T>>, Error>>;
127
+ reload: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<UseItemsResponse<T>, Error>>;
130
128
  updateItem: (item: any) => void;
131
129
  pagination: {
132
130
  page: number;
@@ -139,7 +137,6 @@ declare function useItems<T = Item>(scope: string, { url, getItems, page: initia
139
137
  isLoadingError: false;
140
138
  isRefetchError: false;
141
139
  isSuccess: true;
142
- isPlaceholderData: false;
143
140
  status: "success";
144
141
  dataUpdatedAt: number;
145
142
  errorUpdatedAt: number;
@@ -152,18 +149,18 @@ declare function useItems<T = Item>(scope: string, { url, getItems, page: initia
152
149
  isStale: boolean;
153
150
  isEnabled: boolean;
154
151
  fetchStatus: _tanstack_react_query.FetchStatus;
155
- promise: Promise<NoInfer<UseItemsResponse<T>>>;
156
152
  } | {
157
153
  isLoading: boolean;
158
154
  isFetching: boolean;
159
155
  isRefetching: boolean;
160
156
  isFetched: boolean;
157
+ isPlaceholderData: boolean;
161
158
  items: any;
162
159
  pages: {};
163
160
  allItems: any;
164
161
  loading: boolean;
165
162
  loaded: boolean;
166
- reload: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<NoInfer<UseItemsResponse<T>>, Error>>;
163
+ reload: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<UseItemsResponse<T>, Error>>;
167
164
  updateItem: (item: any) => void;
168
165
  pagination: {
169
166
  page: number;
@@ -176,7 +173,6 @@ declare function useItems<T = Item>(scope: string, { url, getItems, page: initia
176
173
  isLoadingError: true;
177
174
  isRefetchError: false;
178
175
  isSuccess: false;
179
- isPlaceholderData: false;
180
176
  status: "error";
181
177
  dataUpdatedAt: number;
182
178
  errorUpdatedAt: number;
@@ -189,18 +185,18 @@ declare function useItems<T = Item>(scope: string, { url, getItems, page: initia
189
185
  isStale: boolean;
190
186
  isEnabled: boolean;
191
187
  fetchStatus: _tanstack_react_query.FetchStatus;
192
- promise: Promise<NoInfer<UseItemsResponse<T>>>;
193
188
  } | {
194
189
  isLoading: boolean;
195
190
  isFetching: boolean;
196
191
  isRefetching: boolean;
197
192
  isFetched: boolean;
193
+ isPlaceholderData: boolean;
198
194
  items: any;
199
195
  pages: {};
200
196
  allItems: any;
201
197
  loading: boolean;
202
198
  loaded: boolean;
203
- reload: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<NoInfer<UseItemsResponse<T>>, Error>>;
199
+ reload: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<UseItemsResponse<T>, Error>>;
204
200
  updateItem: (item: any) => void;
205
201
  pagination: {
206
202
  page: number;
@@ -213,7 +209,6 @@ declare function useItems<T = Item>(scope: string, { url, getItems, page: initia
213
209
  isLoadingError: false;
214
210
  isRefetchError: false;
215
211
  isSuccess: false;
216
- isPlaceholderData: false;
217
212
  status: "pending";
218
213
  dataUpdatedAt: number;
219
214
  errorUpdatedAt: number;
@@ -226,18 +221,18 @@ declare function useItems<T = Item>(scope: string, { url, getItems, page: initia
226
221
  isStale: boolean;
227
222
  isEnabled: boolean;
228
223
  fetchStatus: _tanstack_react_query.FetchStatus;
229
- promise: Promise<NoInfer<UseItemsResponse<T>>>;
230
224
  } | {
231
225
  isLoading: boolean;
232
226
  isFetching: boolean;
233
227
  isRefetching: boolean;
234
228
  isFetched: boolean;
229
+ isPlaceholderData: boolean;
235
230
  items: any;
236
231
  pages: {};
237
232
  allItems: any;
238
233
  loading: boolean;
239
234
  loaded: boolean;
240
- reload: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<NoInfer<UseItemsResponse<T>>, Error>>;
235
+ reload: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<UseItemsResponse<T>, Error>>;
241
236
  updateItem: (item: any) => void;
242
237
  pagination: {
243
238
  page: number;
@@ -250,7 +245,6 @@ declare function useItems<T = Item>(scope: string, { url, getItems, page: initia
250
245
  isLoadingError: false;
251
246
  isRefetchError: false;
252
247
  isSuccess: false;
253
- isPlaceholderData: false;
254
248
  status: "pending";
255
249
  dataUpdatedAt: number;
256
250
  errorUpdatedAt: number;
@@ -263,18 +257,18 @@ declare function useItems<T = Item>(scope: string, { url, getItems, page: initia
263
257
  isStale: boolean;
264
258
  isEnabled: boolean;
265
259
  fetchStatus: _tanstack_react_query.FetchStatus;
266
- promise: Promise<NoInfer<UseItemsResponse<T>>>;
267
260
  } | {
268
261
  isLoading: boolean;
269
262
  isFetching: boolean;
270
263
  isRefetching: boolean;
271
264
  isFetched: boolean;
265
+ isPlaceholderData: boolean;
272
266
  items: any;
273
267
  pages: {};
274
268
  allItems: any;
275
269
  loading: boolean;
276
270
  loaded: boolean;
277
- reload: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<NoInfer<UseItemsResponse<T>>, Error>>;
271
+ reload: (options?: _tanstack_react_query.RefetchOptions) => Promise<_tanstack_react_query.QueryObserverResult<UseItemsResponse<T>, Error>>;
278
272
  updateItem: (item: any) => void;
279
273
  pagination: {
280
274
  page: number;
@@ -287,7 +281,6 @@ declare function useItems<T = Item>(scope: string, { url, getItems, page: initia
287
281
  isLoadingError: false;
288
282
  isRefetchError: false;
289
283
  isSuccess: true;
290
- isPlaceholderData: true;
291
284
  status: "success";
292
285
  dataUpdatedAt: number;
293
286
  errorUpdatedAt: number;
@@ -300,7 +293,6 @@ declare function useItems<T = Item>(scope: string, { url, getItems, page: initia
300
293
  isStale: boolean;
301
294
  isEnabled: boolean;
302
295
  fetchStatus: _tanstack_react_query.FetchStatus;
303
- promise: Promise<NoInfer<UseItemsResponse<T>>>;
304
296
  };
305
297
 
306
298
  declare function useResourceDestroy(resource: Resource | string): any;
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ import { getJSON, getCSRFHeaders, postJSON } from '@folklore/fetch';
5
5
  import { generatePath } from '@folklore/routes';
6
6
  import queryString from 'query-string';
7
7
  import { jsx } from 'react/jsx-runtime';
8
- import { useQuery, keepPreviousData, useMutation, QueryClient, QueryClientProvider } from '@tanstack/react-query';
8
+ import { useQuery, keepPreviousData, hashKey, useMutation, useQueryClient, QueryClient, QueryClientProvider } from '@tanstack/react-query';
9
9
  import isArray from 'lodash-es/isArray';
10
10
  import isObject from 'lodash-es/isObject';
11
11
  import isString from 'lodash-es/isString';
@@ -85,97 +85,40 @@ function useItem(scope, id, loader, t0) {
85
85
  // The new, better version
86
86
 
87
87
  function useItems(scope, t0) {
88
- const $ = c(75);
89
- let queryConfig;
90
- let t1;
91
- let t2;
92
- let t3;
93
- let t4;
94
- let t5;
95
- let t6;
96
- if ($[0] !== t0) {
97
- ({
98
- url: t1,
99
- getItems: t2,
100
- page: t3,
101
- count: t4,
102
- query: t5,
103
- keepData: t6,
104
- ...queryConfig
105
- } = t0);
106
- $[0] = t0;
107
- $[1] = queryConfig;
108
- $[2] = t1;
109
- $[3] = t2;
110
- $[4] = t3;
111
- $[5] = t4;
112
- $[6] = t5;
113
- $[7] = t6;
114
- } else {
115
- queryConfig = $[1];
116
- t1 = $[2];
117
- t2 = $[3];
118
- t3 = $[4];
119
- t4 = $[5];
120
- t5 = $[6];
121
- t6 = $[7];
122
- }
88
+ const $ = c(52);
89
+ const {
90
+ url: t1,
91
+ getItems: t2,
92
+ page: t3,
93
+ count: t4,
94
+ query: t5,
95
+ keepData: t6,
96
+ ...queryConfig
97
+ } = t0;
123
98
  const url = t1 === undefined ? null : t1;
124
99
  const getItems = t2 === undefined ? null : t2;
125
100
  const initialPage = t3 === undefined ? null : t3;
126
101
  const initialCount = t4 === undefined ? null : t4;
127
102
  const query = t5 === undefined ? null : t5;
128
103
  const keepData = t6 === undefined ? true : t6;
129
- let t7;
130
- if ($[8] !== query) {
131
- t7 = query || {};
132
- $[8] = query;
133
- $[9] = t7;
134
- } else {
135
- t7 = $[9];
136
- }
137
- let queryWithoutPage;
138
- let t8;
139
- let t9;
140
- if ($[10] !== t7) {
141
- ({
142
- page: t8,
143
- count: t9,
144
- ...queryWithoutPage
145
- } = t7);
146
- $[10] = t7;
147
- $[11] = queryWithoutPage;
148
- $[12] = t8;
149
- $[13] = t9;
150
- } else {
151
- queryWithoutPage = $[11];
152
- t8 = $[12];
153
- t9 = $[13];
154
- }
155
- const page = t8 === undefined ? initialPage : t8;
156
- const count = t9 === undefined ? initialCount : t9;
104
+ const {
105
+ page: t7,
106
+ count: t8,
107
+ ...queryWithoutPage
108
+ } = query || {};
109
+ const page = t7 === undefined ? initialPage : t7;
110
+ const count = t8 === undefined ? initialCount : t8;
157
111
  const paginated = page !== null;
158
- let t10;
159
- if ($[14] !== count || $[15] !== page || $[16] !== queryWithoutPage || $[17] !== scope) {
160
- t10 = [scope, queryWithoutPage, page, count];
161
- $[14] = count;
162
- $[15] = page;
163
- $[16] = queryWithoutPage;
164
- $[17] = scope;
165
- $[18] = t10;
166
- } else {
167
- t10 = $[18];
168
- }
169
- let t11;
170
- if ($[19] !== getItems || $[20] !== url) {
171
- t11 = t12 => {
112
+ let t9;
113
+ if ($[0] !== getItems || $[1] !== url) {
114
+ t9 = t10 => {
172
115
  const {
173
- queryKey: t13
174
- } = t12;
175
- const [, t14, t15, t16] = t13 === undefined ? [] : t13;
176
- const queryParam = t14 === undefined ? null : t14;
177
- const pageParam = t15 === undefined ? null : t15;
178
- const countParam = t16 === undefined ? null : t16;
116
+ queryKey: t11
117
+ } = t10;
118
+ const [, t12, t13, t14] = t11 === undefined ? [] : t11;
119
+ const queryParam = t12 === undefined ? null : t12;
120
+ const pageParam = t13 === undefined ? null : t13;
121
+ const countParam = t14 === undefined ? null : t14;
179
122
  return getItems !== null ? getItems(queryParam, pageParam, countParam) : getJSON(`${url}?${queryString.stringify({
180
123
  ...(isObject(queryParam) ? queryParam : {}),
181
124
  ...(pageParam !== null ? {
@@ -188,165 +131,121 @@ function useItems(scope, t0) {
188
131
  arrayFormat: "bracket"
189
132
  })}`);
190
133
  };
191
- $[19] = getItems;
192
- $[20] = url;
193
- $[21] = t11;
134
+ $[0] = getItems;
135
+ $[1] = url;
136
+ $[2] = t9;
194
137
  } else {
195
- t11 = $[21];
138
+ t9 = $[2];
196
139
  }
197
- let t12;
198
- if ($[22] !== keepData) {
199
- t12 = keepData ? {
140
+ const {
141
+ data: t10,
142
+ refetch: reload,
143
+ isLoading,
144
+ isFetching,
145
+ isRefetching,
146
+ isFetched,
147
+ isPlaceholderData,
148
+ ...otherProps
149
+ } = useQuery({
150
+ queryKey: [scope, queryWithoutPage, page, count],
151
+ queryFn: t9,
152
+ refetchOnMount: "always",
153
+ ...(keepData ? {
200
154
  placeholderData: keepPreviousData
201
- } : null;
202
- $[22] = keepData;
203
- $[23] = t12;
204
- } else {
205
- t12 = $[23];
206
- }
207
- let t13;
208
- if ($[24] !== queryConfig || $[25] !== t10 || $[26] !== t11 || $[27] !== t12) {
209
- t13 = {
210
- queryKey: t10,
211
- queryFn: t11,
212
- refetchOnMount: "always",
213
- ...t12,
214
- ...queryConfig
215
- };
216
- $[24] = queryConfig;
217
- $[25] = t10;
218
- $[26] = t11;
219
- $[27] = t12;
220
- $[28] = t13;
221
- } else {
222
- t13 = $[28];
223
- }
224
- const t14 = useQuery(t13);
225
- let isFetched;
226
- let isFetching;
227
- let isLoading;
228
- let isRefetching;
229
- let otherProps;
230
- let reload;
231
- let t15;
232
- if ($[29] !== t14) {
233
- ({
234
- data: t15,
235
- refetch: reload,
236
- isLoading,
237
- isFetching,
238
- isRefetching,
239
- isFetched,
240
- ...otherProps
241
- } = t14);
242
- $[29] = t14;
243
- $[30] = isFetched;
244
- $[31] = isFetching;
245
- $[32] = isLoading;
246
- $[33] = isRefetching;
247
- $[34] = otherProps;
248
- $[35] = reload;
249
- $[36] = t15;
250
- } else {
251
- isFetched = $[30];
252
- isFetching = $[31];
253
- isLoading = $[32];
254
- isRefetching = $[33];
255
- otherProps = $[34];
256
- reload = $[35];
257
- t15 = $[36];
258
- }
259
- const data = t15 === undefined ? null : t15;
260
- let t16;
261
- if ($[37] !== data) {
262
- t16 = isArray(data) ? {
155
+ } : null),
156
+ ...queryConfig
157
+ });
158
+ const data = t10 === undefined ? null : t10;
159
+ let t11;
160
+ if ($[3] !== data) {
161
+ t11 = isArray(data) ? {
263
162
  data
264
163
  } : data || {};
265
- $[37] = data;
266
- $[38] = t16;
164
+ $[3] = data;
165
+ $[4] = t11;
267
166
  } else {
268
- t16 = $[38];
167
+ t11 = $[4];
269
168
  }
270
169
  const {
271
- data: t17,
272
- pagination: t18,
273
- meta: t19
274
- } = t16;
275
- let t20;
276
- if ($[39] !== t17) {
277
- t20 = t17 === undefined ? [] : t17;
278
- $[39] = t17;
279
- $[40] = t20;
170
+ data: t12,
171
+ pagination: t13,
172
+ meta: t14
173
+ } = t11;
174
+ let t15;
175
+ if ($[5] !== t12) {
176
+ t15 = t12 === undefined ? [] : t12;
177
+ $[5] = t12;
178
+ $[6] = t15;
280
179
  } else {
281
- t20 = $[40];
180
+ t15 = $[6];
282
181
  }
283
- const items = t20;
284
- const pagination = t18 === undefined ? null : t18;
285
- const meta = t19 === undefined ? null : t19;
286
- let t21;
287
- if ($[41] !== meta || $[42] !== pagination) {
288
- t21 = pagination || meta || {};
289
- $[41] = meta;
290
- $[42] = pagination;
291
- $[43] = t21;
182
+ const items = t15;
183
+ const pagination = t13 === undefined ? null : t13;
184
+ const meta = t14 === undefined ? null : t14;
185
+ let t16;
186
+ if ($[7] !== meta || $[8] !== pagination) {
187
+ t16 = pagination || meta || {};
188
+ $[7] = meta;
189
+ $[8] = pagination;
190
+ $[9] = t16;
292
191
  } else {
293
- t21 = $[43];
192
+ t16 = $[9];
294
193
  }
295
194
  const {
296
- page: t22,
297
- last_page: t23,
298
- total: t24
299
- } = t21;
300
- const currentPage = t22 === undefined ? null : t22;
301
- const lastPage = t23 === undefined ? 0 : t23;
302
- const total = t24 === undefined ? null : t24;
303
- let t25;
304
- if ($[44] === Symbol.for("react.memo_cache_sentinel")) {
305
- t25 = [];
306
- $[44] = t25;
195
+ page: t17,
196
+ last_page: t18,
197
+ total: t19
198
+ } = t16;
199
+ const currentPage = t17 === undefined ? null : t17;
200
+ const lastPage = t18 === undefined ? 0 : t18;
201
+ const total = t19 === undefined ? null : t19;
202
+ let t20;
203
+ if ($[10] === Symbol.for("react.memo_cache_sentinel")) {
204
+ t20 = [];
205
+ $[10] = t20;
307
206
  } else {
308
- t25 = $[44];
207
+ t20 = $[10];
309
208
  }
310
- const [updatedItems, setUpdatedItems] = useState(t25);
311
- let t26;
312
- if ($[45] !== updatedItems) {
313
- t26 = item => {
209
+ const [updatedItems, setUpdatedItems] = useState(t20);
210
+ let t21;
211
+ if ($[11] !== updatedItems) {
212
+ t21 = item => {
314
213
  const {
315
- id: t27
214
+ id: t22
316
215
  } = item || {};
317
- const itemId = t27 === undefined ? null : t27;
216
+ const itemId = t22 === undefined ? null : t22;
318
217
  if (itemId !== null) {
319
- setUpdatedItems([...(updatedItems || []).filter(t28 => {
218
+ setUpdatedItems([...(updatedItems || []).filter(t23 => {
320
219
  const {
321
- id: t29
322
- } = t28 === undefined ? {} : t28;
323
- const id = t29 === undefined ? null : t29;
220
+ id: t24
221
+ } = t23 === undefined ? {} : t23;
222
+ const id = t24 === undefined ? null : t24;
324
223
  return id !== itemId;
325
224
  }), item]);
326
225
  }
327
226
  };
328
- $[45] = updatedItems;
329
- $[46] = t26;
227
+ $[11] = updatedItems;
228
+ $[12] = t21;
330
229
  } else {
331
- t26 = $[46];
230
+ t21 = $[12];
332
231
  }
333
- const updateItem = t26;
334
- let t27;
335
- if ($[47] !== updatedItems) {
336
- t27 = currentItems => {
232
+ const updateItem = t21;
233
+ let t22;
234
+ if ($[13] !== updatedItems) {
235
+ t22 = currentItems => {
337
236
  if (currentItems === null || updatedItems === null || updatedItems.length === 0) {
338
237
  return currentItems;
339
238
  }
340
239
  return (currentItems || []).map(item_0 => {
341
240
  const {
342
- id: t28
241
+ id: t23
343
242
  } = item_0 || {};
344
- const itemId_0 = t28 === undefined ? null : t28;
345
- const updated = (updatedItems || []).find(t29 => {
243
+ const itemId_0 = t23 === undefined ? null : t23;
244
+ const updated = (updatedItems || []).find(t24 => {
346
245
  const {
347
- id: t30
348
- } = t29 === undefined ? {} : t29;
349
- const id_0 = t30 === undefined ? null : t30;
246
+ id: t25
247
+ } = t24 === undefined ? {} : t24;
248
+ const id_0 = t25 === undefined ? null : t25;
350
249
  return id_0 === itemId_0;
351
250
  }) || null;
352
251
  if (updated !== null) {
@@ -355,71 +254,108 @@ function useItems(scope, t0) {
355
254
  return item_0;
356
255
  }, []);
357
256
  };
358
- $[47] = updatedItems;
359
- $[48] = t27;
257
+ $[13] = updatedItems;
258
+ $[14] = t22;
360
259
  } else {
361
- t27 = $[48];
260
+ t22 = $[14];
362
261
  }
363
- const replaceUpdatedItems = t27;
364
- let t28;
365
- if ($[49] !== items || $[50] !== replaceUpdatedItems) {
366
- t28 = replaceUpdatedItems(items);
367
- $[49] = items;
368
- $[50] = replaceUpdatedItems;
369
- $[51] = t28;
262
+ const replaceUpdatedItems = t22;
263
+ let t23;
264
+ if ($[15] !== items || $[16] !== replaceUpdatedItems) {
265
+ t23 = replaceUpdatedItems(items);
266
+ $[15] = items;
267
+ $[16] = replaceUpdatedItems;
268
+ $[17] = t23;
370
269
  } else {
371
- t28 = $[51];
270
+ t23 = $[17];
372
271
  }
373
- const finalItems = t28;
374
- let t29;
375
- if ($[52] === Symbol.for("react.memo_cache_sentinel")) {
376
- t29 = {};
377
- $[52] = t29;
272
+ const finalItems = t23;
273
+ const pagesKey = hashKey([scope, queryWithoutPage, count]);
274
+ let t24;
275
+ if ($[18] === Symbol.for("react.memo_cache_sentinel")) {
276
+ t24 = {};
277
+ $[18] = t24;
278
+ } else {
279
+ t24 = $[18];
280
+ }
281
+ let t25;
282
+ if ($[19] !== pagesKey) {
283
+ t25 = {
284
+ key: pagesKey,
285
+ pages: t24
286
+ };
287
+ $[19] = pagesKey;
288
+ $[20] = t25;
378
289
  } else {
379
- t29 = $[52];
290
+ t25 = $[20];
380
291
  }
381
- const [pages, setPages] = useState(t29);
382
- if (isFetched && page !== null && data !== null && typeof pages[page] === "undefined") {
383
- setPages({
384
- ...pages,
385
- [page]: data
292
+ const [pagesState, setPagesState] = useState(t25);
293
+ let t26;
294
+ if ($[21] !== pagesKey || $[22] !== pagesState.key || $[23] !== pagesState.pages) {
295
+ t26 = pagesState.key === pagesKey ? pagesState.pages : {};
296
+ $[21] = pagesKey;
297
+ $[22] = pagesState.key;
298
+ $[23] = pagesState.pages;
299
+ $[24] = t26;
300
+ } else {
301
+ t26 = $[24];
302
+ }
303
+ const pages = t26;
304
+ if (isFetched && !isPlaceholderData && page !== null && data !== null && typeof pages[page] === "undefined") {
305
+ let t27;
306
+ if ($[25] !== data || $[26] !== page || $[27] !== pages) {
307
+ t27 = {
308
+ ...pages,
309
+ [page]: data
310
+ };
311
+ $[25] = data;
312
+ $[26] = page;
313
+ $[27] = pages;
314
+ $[28] = t27;
315
+ } else {
316
+ t27 = $[28];
317
+ }
318
+ setPagesState({
319
+ key: pagesKey,
320
+ pages: t27
386
321
  });
387
322
  }
388
- let t30;
389
- if ($[53] !== finalItems || $[54] !== pages || $[55] !== replaceUpdatedItems) {
390
- t30 = pages ? replaceUpdatedItems(Object.keys(pages).flatMap(k => pages[k]?.data)) : finalItems;
391
- $[53] = finalItems;
392
- $[54] = pages;
393
- $[55] = replaceUpdatedItems;
394
- $[56] = t30;
323
+ let t27;
324
+ if ($[29] !== finalItems || $[30] !== pages || $[31] !== replaceUpdatedItems) {
325
+ t27 = Object.keys(pages).length > 0 ? replaceUpdatedItems(Object.keys(pages).flatMap(k => pages[k]?.data)) : finalItems;
326
+ $[29] = finalItems;
327
+ $[30] = pages;
328
+ $[31] = replaceUpdatedItems;
329
+ $[32] = t27;
395
330
  } else {
396
- t30 = $[56];
331
+ t27 = $[32];
397
332
  }
398
- const allItems = t30;
333
+ const allItems = t27;
399
334
  const finalLoading = isLoading || isFetching || isRefetching;
400
- let t31;
401
- if ($[57] !== currentPage || $[58] !== lastPage || $[59] !== paginated || $[60] !== total) {
402
- t31 = paginated ? {
335
+ let t28;
336
+ if ($[33] !== currentPage || $[34] !== lastPage || $[35] !== paginated || $[36] !== total) {
337
+ t28 = paginated ? {
403
338
  page: currentPage,
404
339
  lastPage,
405
340
  total
406
341
  } : null;
407
- $[57] = currentPage;
408
- $[58] = lastPage;
409
- $[59] = paginated;
410
- $[60] = total;
411
- $[61] = t31;
342
+ $[33] = currentPage;
343
+ $[34] = lastPage;
344
+ $[35] = paginated;
345
+ $[36] = total;
346
+ $[37] = t28;
412
347
  } else {
413
- t31 = $[61];
348
+ t28 = $[37];
414
349
  }
415
- let t32;
416
- if ($[62] !== allItems || $[63] !== finalItems || $[64] !== finalLoading || $[65] !== isFetched || $[66] !== isFetching || $[67] !== isLoading || $[68] !== isRefetching || $[69] !== otherProps || $[70] !== pages || $[71] !== reload || $[72] !== t31 || $[73] !== updateItem) {
417
- t32 = {
350
+ let t29;
351
+ if ($[38] !== allItems || $[39] !== finalItems || $[40] !== finalLoading || $[41] !== isFetched || $[42] !== isFetching || $[43] !== isLoading || $[44] !== isPlaceholderData || $[45] !== isRefetching || $[46] !== otherProps || $[47] !== pages || $[48] !== reload || $[49] !== t28 || $[50] !== updateItem) {
352
+ t29 = {
418
353
  ...otherProps,
419
354
  isLoading,
420
355
  isFetching,
421
356
  isRefetching,
422
357
  isFetched,
358
+ isPlaceholderData,
423
359
  items: finalItems,
424
360
  pages,
425
361
  allItems,
@@ -427,25 +363,26 @@ function useItems(scope, t0) {
427
363
  loaded: isFetched,
428
364
  reload,
429
365
  updateItem,
430
- pagination: t31
366
+ pagination: t28
431
367
  };
432
- $[62] = allItems;
433
- $[63] = finalItems;
434
- $[64] = finalLoading;
435
- $[65] = isFetched;
436
- $[66] = isFetching;
437
- $[67] = isLoading;
438
- $[68] = isRefetching;
439
- $[69] = otherProps;
440
- $[70] = pages;
441
- $[71] = reload;
442
- $[72] = t31;
443
- $[73] = updateItem;
444
- $[74] = t32;
445
- } else {
446
- t32 = $[74];
447
- }
448
- return t32;
368
+ $[38] = allItems;
369
+ $[39] = finalItems;
370
+ $[40] = finalLoading;
371
+ $[41] = isFetched;
372
+ $[42] = isFetching;
373
+ $[43] = isLoading;
374
+ $[44] = isPlaceholderData;
375
+ $[45] = isRefetching;
376
+ $[46] = otherProps;
377
+ $[47] = pages;
378
+ $[48] = reload;
379
+ $[49] = t28;
380
+ $[50] = updateItem;
381
+ $[51] = t29;
382
+ } else {
383
+ t29 = $[51];
384
+ }
385
+ return t29;
449
386
  }
450
387
 
451
388
  class Base {
@@ -1120,7 +1057,7 @@ function useResourceStore(resource, t0) {
1120
1057
  }
1121
1058
 
1122
1059
  function useResourceUpdate(resource, t0, t1) {
1123
- const $ = c(22);
1060
+ const $ = c(35);
1124
1061
  const id = t0 === undefined ? null : t0;
1125
1062
  let t2;
1126
1063
  if ($[0] !== t1) {
@@ -1145,55 +1082,119 @@ function useResourceUpdate(resource, t0, t1) {
1145
1082
  t3 = $[4];
1146
1083
  }
1147
1084
  const finalOptions = t3;
1148
- const api = useApi();
1149
1085
  let t4;
1150
- if ($[5] !== api || $[6] !== finalId || $[7] !== finalResource) {
1151
- t4 = data => api.resources.update(finalResource, finalId, data);
1152
- $[5] = api;
1153
- $[6] = finalId;
1154
- $[7] = finalResource;
1155
- $[8] = t4;
1086
+ if ($[5] !== finalOptions) {
1087
+ t4 = finalOptions || {};
1088
+ $[5] = finalOptions;
1089
+ $[6] = t4;
1156
1090
  } else {
1157
- t4 = $[8];
1091
+ t4 = $[6];
1158
1092
  }
1093
+ let otherOptions;
1159
1094
  let t5;
1160
- if ($[9] !== finalOptions || $[10] !== t4) {
1161
- t5 = {
1162
- mutationFn: t4,
1163
- ...finalOptions
1095
+ if ($[7] !== t4) {
1096
+ ({
1097
+ onSuccess: t5,
1098
+ ...otherOptions
1099
+ } = t4);
1100
+ $[7] = t4;
1101
+ $[8] = otherOptions;
1102
+ $[9] = t5;
1103
+ } else {
1104
+ otherOptions = $[8];
1105
+ t5 = $[9];
1106
+ }
1107
+ const customOnSuccess = t5 === undefined ? null : t5;
1108
+ let t6;
1109
+ if ($[10] !== finalResource) {
1110
+ t6 = finalResource || {};
1111
+ $[10] = finalResource;
1112
+ $[11] = t6;
1113
+ } else {
1114
+ t6 = $[11];
1115
+ }
1116
+ const {
1117
+ id: t7
1118
+ } = t6;
1119
+ const resourceId = t7 === undefined ? null : t7;
1120
+ const api = useApi();
1121
+ const queryClient = useQueryClient();
1122
+ let t8;
1123
+ if ($[12] !== api || $[13] !== finalId || $[14] !== finalResource) {
1124
+ t8 = data => api.resources.update(finalResource, finalId, data);
1125
+ $[12] = api;
1126
+ $[13] = finalId;
1127
+ $[14] = finalResource;
1128
+ $[15] = t8;
1129
+ } else {
1130
+ t8 = $[15];
1131
+ }
1132
+ let t9;
1133
+ if ($[16] !== customOnSuccess || $[17] !== finalId || $[18] !== queryClient || $[19] !== resourceId) {
1134
+ t9 = (data_0, ...t10) => {
1135
+ const args = t10;
1136
+ queryClient.setQueryData([resourceId, finalId], data_0);
1137
+ queryClient.invalidateQueries({
1138
+ queryKey: [resourceId],
1139
+ predicate: t11 => {
1140
+ const {
1141
+ queryKey
1142
+ } = t11;
1143
+ return String(queryKey[1]) !== String(finalId);
1144
+ }
1145
+ });
1146
+ if (customOnSuccess !== null) {
1147
+ return customOnSuccess(data_0, ...args);
1148
+ }
1164
1149
  };
1165
- $[9] = finalOptions;
1166
- $[10] = t4;
1167
- $[11] = t5;
1150
+ $[16] = customOnSuccess;
1151
+ $[17] = finalId;
1152
+ $[18] = queryClient;
1153
+ $[19] = resourceId;
1154
+ $[20] = t9;
1168
1155
  } else {
1169
- t5 = $[11];
1156
+ t9 = $[20];
1170
1157
  }
1171
- const t6 = useMutation(t5);
1158
+ let t10;
1159
+ if ($[21] !== otherOptions || $[22] !== t8 || $[23] !== t9) {
1160
+ t10 = {
1161
+ mutationFn: t8,
1162
+ onSuccess: t9,
1163
+ ...otherOptions
1164
+ };
1165
+ $[21] = otherOptions;
1166
+ $[22] = t8;
1167
+ $[23] = t9;
1168
+ $[24] = t10;
1169
+ } else {
1170
+ t10 = $[24];
1171
+ }
1172
+ const t11 = useMutation(t10);
1172
1173
  let isPending;
1173
1174
  let mutate;
1174
1175
  let mutateAsync;
1175
1176
  let other;
1176
- if ($[12] !== t6) {
1177
+ if ($[25] !== t11) {
1177
1178
  ({
1178
1179
  mutate,
1179
1180
  mutateAsync,
1180
1181
  isPending,
1181
1182
  ...other
1182
- } = t6);
1183
- $[12] = t6;
1184
- $[13] = isPending;
1185
- $[14] = mutate;
1186
- $[15] = mutateAsync;
1187
- $[16] = other;
1188
- } else {
1189
- isPending = $[13];
1190
- mutate = $[14];
1191
- mutateAsync = $[15];
1192
- other = $[16];
1183
+ } = t11);
1184
+ $[25] = t11;
1185
+ $[26] = isPending;
1186
+ $[27] = mutate;
1187
+ $[28] = mutateAsync;
1188
+ $[29] = other;
1189
+ } else {
1190
+ isPending = $[26];
1191
+ mutate = $[27];
1192
+ mutateAsync = $[28];
1193
+ other = $[29];
1193
1194
  }
1194
- let t7;
1195
- if ($[17] !== isPending || $[18] !== mutate || $[19] !== mutateAsync || $[20] !== other) {
1196
- t7 = {
1195
+ let t12;
1196
+ if ($[30] !== isPending || $[31] !== mutate || $[32] !== mutateAsync || $[33] !== other) {
1197
+ t12 = {
1197
1198
  update: mutate,
1198
1199
  updateAsync: mutateAsync,
1199
1200
  loading: isPending,
@@ -1202,15 +1203,15 @@ function useResourceUpdate(resource, t0, t1) {
1202
1203
  isPending,
1203
1204
  ...other
1204
1205
  };
1205
- $[17] = isPending;
1206
- $[18] = mutate;
1207
- $[19] = mutateAsync;
1208
- $[20] = other;
1209
- $[21] = t7;
1206
+ $[30] = isPending;
1207
+ $[31] = mutate;
1208
+ $[32] = mutateAsync;
1209
+ $[33] = other;
1210
+ $[34] = t12;
1210
1211
  } else {
1211
- t7 = $[21];
1212
+ t12 = $[34];
1212
1213
  }
1213
- return t7;
1214
+ return t12;
1214
1215
  }
1215
1216
 
1216
1217
  function useResourceClone(t0, t1, t2) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@panneau/data",
3
- "version": "4.0.78",
3
+ "version": "4.0.84",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "javascript"
@@ -71,5 +71,5 @@
71
71
  "publishConfig": {
72
72
  "access": "public"
73
73
  },
74
- "gitHead": "669f20a39ca9545acbe0f2279c6d1af23e43ae6e"
74
+ "gitHead": "d037c178f798b04867b02e3b7c142fabee936b39"
75
75
  }