@panneau/data 4.0.38 → 4.0.40-alpha.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/dist/index.d.ts +69 -286
- package/dist/index.js +1202 -1420
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,1057 +1,662 @@
|
|
|
1
|
-
import { useState,
|
|
2
|
-
import { useUrlGenerator } from '@panneau/core/contexts';
|
|
3
|
-
import _createClass from '@babel/runtime/helpers/createClass';
|
|
4
|
-
import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
|
|
5
|
-
import _callSuper from '@babel/runtime/helpers/callSuper';
|
|
6
|
-
import _inherits from '@babel/runtime/helpers/inherits';
|
|
7
|
-
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
1
|
+
import { useState, useMemo, use, createContext } from 'react';
|
|
2
|
+
import { useUrlGenerator, usePanneauResource, useResource } from '@panneau/core/contexts';
|
|
8
3
|
import { getJSON, getCSRFHeaders, postJSON } from '@folklore/fetch';
|
|
9
4
|
import { generatePath } from '@folklore/routes';
|
|
10
5
|
import queryString from 'query-string';
|
|
11
6
|
import { jsx } from 'react/jsx-runtime';
|
|
12
|
-
import { useQuery, keepPreviousData, QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
import
|
|
7
|
+
import { useQuery, keepPreviousData, useMutation, QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
8
|
+
import { c } from 'react/compiler-runtime';
|
|
9
|
+
import isArray from 'lodash/isArray';
|
|
10
|
+
import isObject from 'lodash/isObject';
|
|
11
|
+
import { isObject as isObject$1 } from 'lodash';
|
|
12
|
+
import isString from 'lodash/isString';
|
|
18
13
|
|
|
19
|
-
function
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
setLoading(true);
|
|
40
|
-
var promise = loadData.apply(void 0, arguments).then(function (newData) {
|
|
41
|
-
if (!canceled) {
|
|
42
|
-
setData(newData);
|
|
43
|
-
setLoading(false);
|
|
44
|
-
}
|
|
45
|
-
return newData;
|
|
46
|
-
})["catch"](function (newError) {
|
|
47
|
-
setError(newError);
|
|
48
|
-
setLoading(false);
|
|
49
|
-
});
|
|
50
|
-
promise.cancel = function () {
|
|
51
|
-
canceled = true;
|
|
52
|
-
setLoading(false);
|
|
14
|
+
function useItem(scope, id, loader, t0) {
|
|
15
|
+
const $ = c(15);
|
|
16
|
+
const opts = t0 === undefined ? null : t0;
|
|
17
|
+
let t1;
|
|
18
|
+
if ($[0] !== id || $[1] !== scope) {
|
|
19
|
+
t1 = [scope, id];
|
|
20
|
+
$[0] = id;
|
|
21
|
+
$[1] = scope;
|
|
22
|
+
$[2] = t1;
|
|
23
|
+
} else {
|
|
24
|
+
t1 = $[2];
|
|
25
|
+
}
|
|
26
|
+
let t2;
|
|
27
|
+
if ($[3] !== loader) {
|
|
28
|
+
t2 = t3 => {
|
|
29
|
+
const {
|
|
30
|
+
queryKey: t4
|
|
31
|
+
} = t3;
|
|
32
|
+
const [, idParam] = t4;
|
|
33
|
+
return loader(idParam);
|
|
53
34
|
};
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
35
|
+
$[3] = loader;
|
|
36
|
+
$[4] = t2;
|
|
37
|
+
} else {
|
|
38
|
+
t2 = $[4];
|
|
39
|
+
}
|
|
40
|
+
let t3;
|
|
41
|
+
if ($[5] !== opts || $[6] !== t1 || $[7] !== t2) {
|
|
42
|
+
t3 = {
|
|
43
|
+
queryKey: t1,
|
|
44
|
+
queryFn: t2,
|
|
45
|
+
...opts
|
|
46
|
+
};
|
|
47
|
+
$[5] = opts;
|
|
48
|
+
$[6] = t1;
|
|
49
|
+
$[7] = t2;
|
|
50
|
+
$[8] = t3;
|
|
51
|
+
} else {
|
|
52
|
+
t3 = $[8];
|
|
53
|
+
}
|
|
54
|
+
const t4 = useQuery(t3);
|
|
55
|
+
let request;
|
|
56
|
+
let t5;
|
|
57
|
+
if ($[9] !== t4) {
|
|
58
|
+
({
|
|
59
|
+
data: t5,
|
|
60
|
+
...request
|
|
61
|
+
} = t4);
|
|
62
|
+
$[9] = t4;
|
|
63
|
+
$[10] = request;
|
|
64
|
+
$[11] = t5;
|
|
65
|
+
} else {
|
|
66
|
+
request = $[10];
|
|
67
|
+
t5 = $[11];
|
|
68
|
+
}
|
|
69
|
+
const data = t5 === undefined ? null : t5;
|
|
70
|
+
let t6;
|
|
71
|
+
if ($[12] !== data || $[13] !== request) {
|
|
72
|
+
t6 = {
|
|
73
|
+
item: data,
|
|
74
|
+
...request
|
|
65
75
|
};
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
76
|
+
$[12] = data;
|
|
77
|
+
$[13] = request;
|
|
78
|
+
$[14] = t6;
|
|
79
|
+
} else {
|
|
80
|
+
t6 = $[14];
|
|
81
|
+
}
|
|
82
|
+
return t6;
|
|
73
83
|
}
|
|
74
84
|
|
|
75
|
-
|
|
76
|
-
_excluded2$1 = ["page", "count"],
|
|
77
|
-
_excluded3 = ["data", "refetch", "isLoading", "isFetching", "isRefetching", "isFetched", "status", "error"];
|
|
78
|
-
|
|
79
|
-
// For backwards compatibility
|
|
85
|
+
// The new, better version
|
|
80
86
|
|
|
81
|
-
function useItems
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
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
|
+
}
|
|
123
|
+
const url = t1 === undefined ? null : t1;
|
|
124
|
+
const getItems = t2 === undefined ? null : t2;
|
|
125
|
+
const initialPage = t3 === undefined ? null : t3;
|
|
126
|
+
const initialCount = t4 === undefined ? null : t4;
|
|
127
|
+
const query = t5 === undefined ? null : t5;
|
|
128
|
+
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;
|
|
157
|
+
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 => {
|
|
172
|
+
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;
|
|
179
|
+
return getItems !== null ? getItems(queryParam, pageParam, countParam) : getJSON(`${url}?${queryString.stringify({
|
|
180
|
+
...(isObject(queryParam) ? queryParam : {}),
|
|
181
|
+
...(pageParam !== null ? {
|
|
182
|
+
page: pageParam
|
|
183
|
+
} : null),
|
|
184
|
+
...(countParam !== null ? {
|
|
185
|
+
count: countParam
|
|
186
|
+
} : null)
|
|
187
|
+
}, {
|
|
188
|
+
arrayFormat: "bracket"
|
|
189
|
+
})}`);
|
|
190
|
+
};
|
|
191
|
+
$[19] = getItems;
|
|
192
|
+
$[20] = url;
|
|
193
|
+
$[21] = t11;
|
|
194
|
+
} else {
|
|
195
|
+
t11 = $[21];
|
|
196
|
+
}
|
|
197
|
+
let t12;
|
|
198
|
+
if ($[22] !== keepData) {
|
|
199
|
+
t12 = keepData ? {
|
|
191
200
|
placeholderData: keepPreviousData
|
|
192
|
-
} : null
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
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) ? {
|
|
263
|
+
data
|
|
264
|
+
} : data || {};
|
|
265
|
+
$[37] = data;
|
|
266
|
+
$[38] = t16;
|
|
267
|
+
} else {
|
|
268
|
+
t16 = $[38];
|
|
269
|
+
}
|
|
270
|
+
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;
|
|
280
|
+
} else {
|
|
281
|
+
t20 = $[40];
|
|
282
|
+
}
|
|
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;
|
|
292
|
+
} else {
|
|
293
|
+
t21 = $[43];
|
|
294
|
+
}
|
|
295
|
+
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;
|
|
307
|
+
} else {
|
|
308
|
+
t25 = $[44];
|
|
309
|
+
}
|
|
310
|
+
const [updatedItems, setUpdatedItems] = useState(t25);
|
|
311
|
+
let t26;
|
|
312
|
+
if ($[45] !== updatedItems) {
|
|
313
|
+
t26 = item => {
|
|
314
|
+
const {
|
|
315
|
+
id: t27
|
|
316
|
+
} = item || {};
|
|
317
|
+
const itemId = t27 === undefined ? null : t27;
|
|
318
|
+
if (itemId !== null) {
|
|
319
|
+
setUpdatedItems([...(updatedItems || []).filter(t28 => {
|
|
320
|
+
const {
|
|
321
|
+
id: t29
|
|
322
|
+
} = t28 === undefined ? {} : t28;
|
|
323
|
+
const id = t29 === undefined ? null : t29;
|
|
324
|
+
return id !== itemId;
|
|
325
|
+
}), item]);
|
|
299
326
|
}
|
|
300
|
-
|
|
301
|
-
|
|
327
|
+
};
|
|
328
|
+
$[45] = updatedItems;
|
|
329
|
+
$[46] = t26;
|
|
330
|
+
} else {
|
|
331
|
+
t26 = $[46];
|
|
332
|
+
}
|
|
333
|
+
const updateItem = t26;
|
|
334
|
+
let t27;
|
|
335
|
+
if ($[47] !== updatedItems) {
|
|
336
|
+
t27 = currentItems => {
|
|
337
|
+
if (currentItems === null || updatedItems === null || updatedItems.length === 0) {
|
|
338
|
+
return currentItems;
|
|
302
339
|
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
340
|
+
return (currentItems || []).map(item_0 => {
|
|
341
|
+
const {
|
|
342
|
+
id: t28
|
|
343
|
+
} = item_0 || {};
|
|
344
|
+
const itemId_0 = t28 === undefined ? null : t28;
|
|
345
|
+
const updated = (updatedItems || []).find(t29 => {
|
|
346
|
+
const {
|
|
347
|
+
id: t30
|
|
348
|
+
} = t29 === undefined ? {} : t29;
|
|
349
|
+
const id_0 = t30 === undefined ? null : t30;
|
|
350
|
+
return id_0 === itemId_0;
|
|
351
|
+
}) || null;
|
|
352
|
+
if (updated !== null) {
|
|
353
|
+
return updated;
|
|
354
|
+
}
|
|
355
|
+
return item_0;
|
|
356
|
+
}, []);
|
|
357
|
+
};
|
|
358
|
+
$[47] = updatedItems;
|
|
359
|
+
$[48] = t27;
|
|
360
|
+
} else {
|
|
361
|
+
t27 = $[48];
|
|
362
|
+
}
|
|
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;
|
|
370
|
+
} else {
|
|
371
|
+
t28 = $[51];
|
|
372
|
+
}
|
|
373
|
+
const finalItems = t28;
|
|
374
|
+
let t29;
|
|
375
|
+
if ($[52] === Symbol.for("react.memo_cache_sentinel")) {
|
|
376
|
+
t29 = {};
|
|
377
|
+
$[52] = t29;
|
|
378
|
+
} else {
|
|
379
|
+
t29 = $[52];
|
|
380
|
+
}
|
|
381
|
+
const [pages, setPages] = useState(t29);
|
|
382
|
+
if (isFetched && page !== null && data !== null && typeof pages[page] === "undefined") {
|
|
383
|
+
setPages({
|
|
384
|
+
...pages,
|
|
385
|
+
[page]: data
|
|
386
|
+
});
|
|
387
|
+
}
|
|
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;
|
|
395
|
+
} else {
|
|
396
|
+
t30 = $[56];
|
|
397
|
+
}
|
|
398
|
+
const allItems = t30;
|
|
399
|
+
const finalLoading = isLoading || isFetching || isRefetching;
|
|
400
|
+
let t31;
|
|
401
|
+
if ($[57] !== currentPage || $[58] !== lastPage || $[59] !== paginated || $[60] !== total) {
|
|
402
|
+
t31 = paginated ? {
|
|
325
403
|
page: currentPage,
|
|
326
|
-
lastPage
|
|
327
|
-
total
|
|
328
|
-
} : null
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
404
|
+
lastPage,
|
|
405
|
+
total
|
|
406
|
+
} : null;
|
|
407
|
+
$[57] = currentPage;
|
|
408
|
+
$[58] = lastPage;
|
|
409
|
+
$[59] = paginated;
|
|
410
|
+
$[60] = total;
|
|
411
|
+
$[61] = t31;
|
|
412
|
+
} else {
|
|
413
|
+
t31 = $[61];
|
|
414
|
+
}
|
|
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 = {
|
|
418
|
+
...otherProps,
|
|
419
|
+
isLoading,
|
|
420
|
+
isFetching,
|
|
421
|
+
isRefetching,
|
|
422
|
+
isFetched,
|
|
423
|
+
items: finalItems,
|
|
424
|
+
pages,
|
|
425
|
+
allItems,
|
|
426
|
+
loading: finalLoading,
|
|
427
|
+
loaded: isFetched,
|
|
428
|
+
reload,
|
|
429
|
+
updateItem,
|
|
430
|
+
pagination: t31
|
|
431
|
+
};
|
|
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;
|
|
344
449
|
}
|
|
345
450
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
page = _ref$page === void 0 ? null : _ref$page,
|
|
353
|
-
_ref$count = _ref.count,
|
|
354
|
-
count = _ref$count === void 0 ? 10 : _ref$count,
|
|
355
|
-
_ref$items = _ref.items,
|
|
356
|
-
providedItems = _ref$items === void 0 ? null : _ref$items,
|
|
357
|
-
_ref$pages = _ref.pages,
|
|
358
|
-
initialPages = _ref$pages === void 0 ? null : _ref$pages,
|
|
359
|
-
_ref$getPageFromRespo = _ref.getPageFromResponse,
|
|
360
|
-
getPageFromResponse = _ref$getPageFromRespo === void 0 ? function (_ref2) {
|
|
361
|
-
var _ref2$pagination = _ref2.pagination,
|
|
362
|
-
currentPage = _ref2$pagination.page,
|
|
363
|
-
lastPage = _ref2$pagination.last_page,
|
|
364
|
-
total = _ref2$pagination.total,
|
|
365
|
-
perPage = _ref2$pagination.per_page,
|
|
366
|
-
items = _ref2.data;
|
|
367
|
-
return {
|
|
368
|
-
page: parseInt(currentPage, 10),
|
|
369
|
-
lastPage: parseInt(lastPage, 10),
|
|
370
|
-
total: parseInt(total, 10),
|
|
371
|
-
count: parseInt(perPage, 10),
|
|
372
|
-
items: items
|
|
373
|
-
};
|
|
374
|
-
} : _ref$getPageFromRespo,
|
|
375
|
-
_ref$getItemsFromResp = _ref.getItemsFromResponse,
|
|
376
|
-
getItemsFromResponse = _ref$getItemsFromResp === void 0 ? function (data) {
|
|
377
|
-
return data;
|
|
378
|
-
} : _ref$getItemsFromResp,
|
|
379
|
-
_ref$onItemsLoaded = _ref.onItemsLoaded,
|
|
380
|
-
onItemsLoaded = _ref$onItemsLoaded === void 0 ? null : _ref$onItemsLoaded,
|
|
381
|
-
_ref$onPageLoaded = _ref.onPageLoaded,
|
|
382
|
-
onPageLoaded = _ref$onPageLoaded === void 0 ? null : _ref$onPageLoaded,
|
|
383
|
-
_ref$onLoaded = _ref.onLoaded,
|
|
384
|
-
onLoaded = _ref$onLoaded === void 0 ? null : _ref$onLoaded,
|
|
385
|
-
_ref$onError = _ref.onError,
|
|
386
|
-
onError = _ref$onError === void 0 ? null : _ref$onError;
|
|
387
|
-
var isPaginated = getPage !== null || initialPages !== null;
|
|
388
|
-
var lastState = useRef(null);
|
|
389
|
-
var initialState = useMemo(function () {
|
|
390
|
-
var finalInitialPages = initialPages !== null ? initialPages.map(function (it) {
|
|
391
|
-
return getPageFromResponse(it);
|
|
392
|
-
}) : null;
|
|
393
|
-
return {
|
|
394
|
-
lastPage: finalInitialPages !== null ? finalInitialPages.reduce(function (currentLastPage, _ref3) {
|
|
395
|
-
var initialLastPage = _ref3.lastPage;
|
|
396
|
-
return initialLastPage > currentLastPage ? initialLastPage : currentLastPage;
|
|
397
|
-
}, -1) : -1,
|
|
398
|
-
total: finalInitialPages !== null ? finalInitialPages[0].total : (providedItems || []).length,
|
|
399
|
-
loaded: providedItems !== null,
|
|
400
|
-
loading: false,
|
|
401
|
-
pages: finalInitialPages !== null ? finalInitialPages : null,
|
|
402
|
-
items: null
|
|
451
|
+
class AccountApi {
|
|
452
|
+
constructor(api, opts) {
|
|
453
|
+
this.api = api;
|
|
454
|
+
this.options = {
|
|
455
|
+
withCredentials: false,
|
|
456
|
+
...opts
|
|
403
457
|
};
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
stateItems = state.items,
|
|
413
|
-
pages = state.pages,
|
|
414
|
-
total = state.total;
|
|
415
|
-
var items = providedItems || (isPaginated && pages !== null ? pages.reduce(function (pagesItems, _ref4) {
|
|
416
|
-
var pageItems = _ref4.items;
|
|
417
|
-
return pagesItems.concat(pageItems);
|
|
418
|
-
}, []) : stateItems) || null;
|
|
419
|
-
var updateState = function updateState(update) {
|
|
420
|
-
return setState(_objectSpread(_objectSpread({}, state), update));
|
|
421
|
-
};
|
|
422
|
-
var updateFromResponse = function updateFromResponse(response) {
|
|
423
|
-
var error = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
424
|
-
var reset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
425
|
-
if (error !== null) {
|
|
426
|
-
updateState({
|
|
427
|
-
loaded: false,
|
|
428
|
-
loading: false
|
|
429
|
-
});
|
|
430
|
-
throw error;
|
|
431
|
-
}
|
|
432
|
-
if (isPaginated) {
|
|
433
|
-
var newPage = getPageFromResponse(response);
|
|
434
|
-
var newPages = (reset ? [newPage] : [].concat(_toConsumableArray((pages || []).filter(function (it) {
|
|
435
|
-
return it.page !== newPage.page;
|
|
436
|
-
})), [newPage])).sort(function (a, b) {
|
|
437
|
-
if (a === b) {
|
|
438
|
-
return 0;
|
|
439
|
-
}
|
|
440
|
-
return a > b ? 1 : -1;
|
|
441
|
-
});
|
|
442
|
-
updateState({
|
|
443
|
-
loaded: true,
|
|
444
|
-
loading: false,
|
|
445
|
-
lastPage: newPage.lastPage,
|
|
446
|
-
total: newPage.total,
|
|
447
|
-
pages: newPages
|
|
448
|
-
});
|
|
449
|
-
return newPage;
|
|
450
|
-
}
|
|
451
|
-
var newItems = _toConsumableArray(getItemsFromResponse(response));
|
|
452
|
-
updateState({
|
|
453
|
-
loaded: true,
|
|
454
|
-
loading: false,
|
|
455
|
-
items: newItems,
|
|
456
|
-
total: newItems.length
|
|
457
|
-
});
|
|
458
|
-
return newItems;
|
|
459
|
-
};
|
|
460
|
-
var getNextPage = function getNextPage() {
|
|
461
|
-
var allPages = lastPage !== -1 ? Array.call.apply(Array, [null].concat(_toConsumableArray(Array(lastPage)))).map(function (it, index) {
|
|
462
|
-
return index + 1;
|
|
463
|
-
}) : [];
|
|
464
|
-
var remainingPages = allPages.filter(function (pageNumber) {
|
|
465
|
-
return pages.findIndex(function (it) {
|
|
466
|
-
return it.page === pageNumber;
|
|
467
|
-
}) === -1;
|
|
458
|
+
}
|
|
459
|
+
update(data) {
|
|
460
|
+
const {
|
|
461
|
+
withCredentials
|
|
462
|
+
} = this.options;
|
|
463
|
+
return this.api.requestPost(this.api.route('account'), data, {
|
|
464
|
+
withSession: !withCredentials,
|
|
465
|
+
withCredentials
|
|
468
466
|
});
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
467
|
+
}
|
|
468
|
+
updatePassword(data) {
|
|
469
|
+
const {
|
|
470
|
+
withCredentials
|
|
471
|
+
} = this.options;
|
|
472
|
+
return this.api.requestPost(this.api.route('account.password'), data, {
|
|
473
|
+
withSession: !withCredentials,
|
|
474
|
+
withCredentials
|
|
475
475
|
});
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
onPageLoaded(response);
|
|
485
|
-
} else if (!isPaginated && onItemsLoaded !== null) {
|
|
486
|
-
onItemsLoaded(response);
|
|
487
|
-
}
|
|
488
|
-
if (onLoaded !== null) {
|
|
489
|
-
onLoaded(response);
|
|
490
|
-
}
|
|
491
|
-
return response;
|
|
492
|
-
})["catch"](function (error) {
|
|
493
|
-
if (!canceled && onError !== null) {
|
|
494
|
-
onError(error);
|
|
495
|
-
}
|
|
476
|
+
}
|
|
477
|
+
updateTaxes(data) {
|
|
478
|
+
const {
|
|
479
|
+
withCredentials
|
|
480
|
+
} = this.options;
|
|
481
|
+
return this.api.requestPost(this.api.route('account.taxes'), data, {
|
|
482
|
+
withSession: !withCredentials,
|
|
483
|
+
withCredentials
|
|
496
484
|
});
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
}
|
|
506
|
-
if (pages.find(function (it) {
|
|
507
|
-
return it.page === pageToLoad;
|
|
508
|
-
}) !== -1) {
|
|
509
|
-
return Promise.reject();
|
|
510
|
-
}
|
|
511
|
-
return loadItems(pageToLoad);
|
|
512
|
-
};
|
|
513
|
-
var loadNextPage = function loadNextPage() {
|
|
514
|
-
if (loading) {
|
|
515
|
-
return Promise.reject();
|
|
516
|
-
}
|
|
517
|
-
var nextPage = getNextPage();
|
|
518
|
-
return nextPage !== null ? loadItems(nextPage) : Promise.resolve();
|
|
519
|
-
};
|
|
520
|
-
var reloadPage = function reloadPage() {
|
|
521
|
-
if (loading) {
|
|
522
|
-
return Promise.reject();
|
|
523
|
-
}
|
|
524
|
-
return loadItems(page);
|
|
525
|
-
};
|
|
526
|
-
var reload = function reload() {
|
|
527
|
-
if (loading) {
|
|
528
|
-
return Promise.reject();
|
|
529
|
-
}
|
|
530
|
-
return loadItems();
|
|
531
|
-
};
|
|
532
|
-
var reset = useCallback(function () {
|
|
533
|
-
setState({
|
|
534
|
-
loaded: false,
|
|
535
|
-
loading: false,
|
|
536
|
-
lastPage: -1,
|
|
537
|
-
total: 0,
|
|
538
|
-
pages: null,
|
|
539
|
-
items: null
|
|
485
|
+
}
|
|
486
|
+
delete(data) {
|
|
487
|
+
const {
|
|
488
|
+
withCredentials
|
|
489
|
+
} = this.options;
|
|
490
|
+
return this.api.requestPost(this.api.route('account.delete'), data, {
|
|
491
|
+
withSession: !withCredentials,
|
|
492
|
+
withCredentials
|
|
540
493
|
});
|
|
541
|
-
}
|
|
542
|
-
var updateItem = function updateItem(newItem) {
|
|
543
|
-
if (loading) {
|
|
544
|
-
return;
|
|
545
|
-
}
|
|
546
|
-
if (isPaginated) {
|
|
547
|
-
var currentPages = pages || [];
|
|
548
|
-
updateState({
|
|
549
|
-
pages: currentPages.map(function (pageData) {
|
|
550
|
-
var pageItems = pageData.items || [];
|
|
551
|
-
if (pageItems.findIndex(function (_ref5) {
|
|
552
|
-
var id = _ref5.id;
|
|
553
|
-
return id === newItem.id;
|
|
554
|
-
}) !== -1) {
|
|
555
|
-
return _objectSpread(_objectSpread({}, pageData), {}, {
|
|
556
|
-
items: pageItems.map(function (it) {
|
|
557
|
-
return it.id === newItem.id ? newItem : it;
|
|
558
|
-
})
|
|
559
|
-
});
|
|
560
|
-
}
|
|
561
|
-
return pageData;
|
|
562
|
-
})
|
|
563
|
-
});
|
|
564
|
-
} else {
|
|
565
|
-
var currentItems = items || [];
|
|
566
|
-
updateState({
|
|
567
|
-
items: currentItems.map(function (it) {
|
|
568
|
-
return it.id === newItem.id ? newItem : it;
|
|
569
|
-
})
|
|
570
|
-
});
|
|
571
|
-
}
|
|
572
|
-
};
|
|
573
|
-
useEffect(function () {
|
|
574
|
-
var hadState = lastState.current !== null;
|
|
575
|
-
lastState.current = initialState;
|
|
576
|
-
if (hadState) {
|
|
577
|
-
setState(initialState);
|
|
578
|
-
}
|
|
579
|
-
}, [initialState]);
|
|
580
|
-
useEffect(function () {
|
|
581
|
-
if (getPage === null && getItems === null || providedItems !== null) {
|
|
582
|
-
return function () {};
|
|
583
|
-
}
|
|
584
|
-
var loadPromise = null;
|
|
585
|
-
var pageToLoad = isPaginated && initialPages === null && page === null ? 1 : page;
|
|
586
|
-
if (!isPaginated || pageToLoad !== null) {
|
|
587
|
-
loadPromise = loadItems(pageToLoad);
|
|
588
|
-
}
|
|
589
|
-
return function () {
|
|
590
|
-
if (loadPromise !== null) {
|
|
591
|
-
loadPromise.cancel();
|
|
592
|
-
}
|
|
593
|
-
};
|
|
594
|
-
}, [getPage, getItems, page]);
|
|
595
|
-
var currentPage = isPaginated && pages !== null ? pages.find(function (_ref6) {
|
|
596
|
-
var pageNumber = _ref6.page;
|
|
597
|
-
return parseInt(pageNumber, 10) === parseInt(page, 10);
|
|
598
|
-
}) || null : null;
|
|
599
|
-
return {
|
|
600
|
-
items: items,
|
|
601
|
-
pages: pages,
|
|
602
|
-
pageItems: currentPage !== null ? currentPage.items : null,
|
|
603
|
-
total: total,
|
|
604
|
-
lastPage: lastPage,
|
|
605
|
-
loaded: loaded,
|
|
606
|
-
allLoaded: !isPaginated && loaded || lastPage !== -1 && isPaginated && pages.length === lastPage,
|
|
607
|
-
loading: loading,
|
|
608
|
-
loadNextPage: loadNextPage,
|
|
609
|
-
loadPage: loadPage,
|
|
610
|
-
reloadPage: reloadPage,
|
|
611
|
-
reload: reload,
|
|
612
|
-
reset: reset,
|
|
613
|
-
updateItem: updateItem
|
|
614
|
-
};
|
|
494
|
+
}
|
|
615
495
|
}
|
|
616
496
|
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
// The new, better version
|
|
621
|
-
|
|
622
|
-
var useItemsStore = function useItemsStore(store, _ref) {
|
|
623
|
-
var _ref$url = _ref.url,
|
|
624
|
-
url = _ref$url === void 0 ? null : _ref$url,
|
|
625
|
-
_ref$getPage = _ref.getPage,
|
|
626
|
-
getPage = _ref$getPage === void 0 ? null : _ref$getPage,
|
|
627
|
-
_ref$getItems = _ref.getItems,
|
|
628
|
-
getItems = _ref$getItems === void 0 ? null : _ref$getItems,
|
|
629
|
-
_ref$getPageFromRespo = _ref.getPageFromResponse,
|
|
630
|
-
getPageFromResponse = _ref$getPageFromRespo === void 0 ? null : _ref$getPageFromRespo,
|
|
631
|
-
_ref$getItemsFromResp = _ref.getItemsFromResponse,
|
|
632
|
-
getItemsFromResponse = _ref$getItemsFromResp === void 0 ? null : _ref$getItemsFromResp,
|
|
633
|
-
_ref$page = _ref.page,
|
|
634
|
-
initialPage = _ref$page === void 0 ? null : _ref$page,
|
|
635
|
-
_ref$count = _ref.count,
|
|
636
|
-
initialCount = _ref$count === void 0 ? null : _ref$count,
|
|
637
|
-
_ref$query = _ref.query,
|
|
638
|
-
query = _ref$query === void 0 ? null : _ref$query,
|
|
639
|
-
_ref$onQueryChange = _ref.onQueryChange,
|
|
640
|
-
onQueryChange = _ref$onQueryChange === void 0 ? null : _ref$onQueryChange,
|
|
641
|
-
_ref$queryConfig = _ref.queryConfig,
|
|
642
|
-
queryConfig = _ref$queryConfig === void 0 ? null : _ref$queryConfig,
|
|
643
|
-
_ref$keepData = _ref.keepData,
|
|
644
|
-
keepData = _ref$keepData === void 0 ? true : _ref$keepData;
|
|
645
|
-
var _ref2 = query || {},
|
|
646
|
-
_ref2$page = _ref2.page,
|
|
647
|
-
page = _ref2$page === void 0 ? initialPage : _ref2$page,
|
|
648
|
-
_ref2$count = _ref2.count,
|
|
649
|
-
count = _ref2$count === void 0 ? initialCount : _ref2$count,
|
|
650
|
-
queryWithoutPage = _objectWithoutProperties(_ref2, _excluded$2);
|
|
651
|
-
var paginated = page !== null;
|
|
652
|
-
var queryKey = useMemo(function () {
|
|
653
|
-
return paginated ? [store, page || 1, count || 12, queryWithoutPage] : [store, query];
|
|
654
|
-
}, [paginated, store, page, count, query]);
|
|
655
|
-
var _useQuery = useQuery(_objectSpread(_objectSpread(_objectSpread({
|
|
656
|
-
queryKey: queryKey,
|
|
657
|
-
queryFn: function queryFn(_ref3) {
|
|
658
|
-
var _ref3$queryKey = _ref3.queryKey,
|
|
659
|
-
key = _ref3$queryKey === void 0 ? null : _ref3$queryKey;
|
|
660
|
-
if (paginated && getPage !== null) {
|
|
661
|
-
var _key = _slicedToArray(key, 4),
|
|
662
|
-
_key$ = _key[1],
|
|
663
|
-
p = _key$ === void 0 ? null : _key$,
|
|
664
|
-
_key$2 = _key[2],
|
|
665
|
-
c = _key$2 === void 0 ? null : _key$2,
|
|
666
|
-
_key$3 = _key[3],
|
|
667
|
-
_q = _key$3 === void 0 ? null : _key$3;
|
|
668
|
-
return getPage(p, c, _q);
|
|
669
|
-
}
|
|
670
|
-
if (!paginated && getItems !== null) {
|
|
671
|
-
var _key2 = _slicedToArray(key, 2),
|
|
672
|
-
_key2$ = _key2[1],
|
|
673
|
-
_q2 = _key2$ === void 0 ? null : _key2$;
|
|
674
|
-
return getItems(_q2);
|
|
675
|
-
}
|
|
676
|
-
var _key3 = _slicedToArray(key, 2),
|
|
677
|
-
_key3$ = _key3[1],
|
|
678
|
-
q = _key3$ === void 0 ? null : _key3$;
|
|
679
|
-
return getJSON("".concat(url).concat(!isEmpty(q) ? "?".concat(queryString.stringify(q, {
|
|
680
|
-
arrayFormat: 'bracket'
|
|
681
|
-
})) : ''));
|
|
682
|
-
}
|
|
683
|
-
}, keepData ? {
|
|
684
|
-
placeholderData: keepPreviousData
|
|
685
|
-
} : null), queryConfig), {}, {
|
|
686
|
-
refetchOnMount: 'always'
|
|
687
|
-
})),
|
|
688
|
-
_useQuery$data = _useQuery.data,
|
|
689
|
-
data = _useQuery$data === void 0 ? null : _useQuery$data,
|
|
690
|
-
reload = _useQuery.refetch,
|
|
691
|
-
isLoading = _useQuery.isLoading,
|
|
692
|
-
isFetching = _useQuery.isFetching,
|
|
693
|
-
isRefetching = _useQuery.isRefetching,
|
|
694
|
-
isFetched = _useQuery.isFetched,
|
|
695
|
-
otherProps = _objectWithoutProperties(_useQuery, _excluded2);
|
|
696
|
-
var _ref4 = data || {},
|
|
697
|
-
_ref4$data = _ref4.data,
|
|
698
|
-
items = _ref4$data === void 0 ? [] : _ref4$data,
|
|
699
|
-
_ref4$pagination = _ref4.pagination,
|
|
700
|
-
pagination = _ref4$pagination === void 0 ? null : _ref4$pagination,
|
|
701
|
-
_ref4$meta = _ref4.meta,
|
|
702
|
-
meta = _ref4$meta === void 0 ? null : _ref4$meta;
|
|
703
|
-
var _ref5 = pagination || meta || {},
|
|
704
|
-
_ref5$page = _ref5.page,
|
|
705
|
-
currentPage = _ref5$page === void 0 ? null : _ref5$page,
|
|
706
|
-
_ref5$last_page = _ref5.last_page,
|
|
707
|
-
lastPage = _ref5$last_page === void 0 ? 0 : _ref5$last_page,
|
|
708
|
-
_ref5$total = _ref5.total,
|
|
709
|
-
total = _ref5$total === void 0 ? null : _ref5$total;
|
|
710
|
-
var loadNextPage = useCallback(function () {
|
|
711
|
-
if (onQueryChange !== null && paginated && page !== null && page < lastPage) {
|
|
712
|
-
onQueryChange(_objectSpread(_objectSpread({}, query), {}, {
|
|
713
|
-
page: page + 1
|
|
714
|
-
}));
|
|
715
|
-
}
|
|
716
|
-
}, [paginated, pagination, page]);
|
|
717
|
-
var loadPage = useCallback(function (newPage) {
|
|
718
|
-
if (onQueryChange !== null && newPage !== null) {
|
|
719
|
-
onQueryChange(_objectSpread(_objectSpread({}, query), {}, {
|
|
720
|
-
page: newPage
|
|
721
|
-
}));
|
|
722
|
-
}
|
|
723
|
-
}, [query, onQueryChange]);
|
|
724
|
-
|
|
725
|
-
// Keep a list of updated items
|
|
726
|
-
var _useState = useState([]),
|
|
727
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
728
|
-
updatedItems = _useState2[0],
|
|
729
|
-
setUpdatedItems = _useState2[1];
|
|
730
|
-
var updateItem = useCallback(function (item) {
|
|
731
|
-
var _ref6 = item || {},
|
|
732
|
-
_ref6$id = _ref6.id,
|
|
733
|
-
itemId = _ref6$id === void 0 ? null : _ref6$id;
|
|
734
|
-
if (itemId !== null) {
|
|
735
|
-
setUpdatedItems([].concat(_toConsumableArray((updatedItems || []).filter(function () {
|
|
736
|
-
var _ref7 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
737
|
-
_ref7$id = _ref7.id,
|
|
738
|
-
id = _ref7$id === void 0 ? null : _ref7$id;
|
|
739
|
-
return id !== itemId;
|
|
740
|
-
})), [item]));
|
|
741
|
-
}
|
|
742
|
-
}, [updatedItems, setUpdatedItems]);
|
|
743
|
-
var replaceUpdatedItems = useCallback(function (currentItems) {
|
|
744
|
-
if (currentItems === null || updatedItems === null || updatedItems.length === 0) {
|
|
745
|
-
return currentItems;
|
|
746
|
-
}
|
|
747
|
-
return (currentItems || []).map(function (item) {
|
|
748
|
-
var _ref8 = item || {},
|
|
749
|
-
_ref8$id = _ref8.id,
|
|
750
|
-
itemId = _ref8$id === void 0 ? null : _ref8$id;
|
|
751
|
-
var updated = (updatedItems || []).find(function () {
|
|
752
|
-
var _ref9 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
753
|
-
_ref9$id = _ref9.id,
|
|
754
|
-
id = _ref9$id === void 0 ? null : _ref9$id;
|
|
755
|
-
return id === itemId;
|
|
756
|
-
}) || null;
|
|
757
|
-
if (updated !== null) {
|
|
758
|
-
return updated;
|
|
759
|
-
}
|
|
760
|
-
return item;
|
|
761
|
-
}, []);
|
|
762
|
-
}, [updatedItems]);
|
|
763
|
-
var partialItems = useMemo(function () {
|
|
764
|
-
if (data === null) {
|
|
765
|
-
return data;
|
|
766
|
-
}
|
|
767
|
-
if (paginated) {
|
|
768
|
-
if (getPageFromResponse !== null) {
|
|
769
|
-
return getPageFromResponse(items);
|
|
770
|
-
}
|
|
771
|
-
return items;
|
|
772
|
-
}
|
|
773
|
-
if (getItemsFromResponse !== null) {
|
|
774
|
-
return getItemsFromResponse(data);
|
|
775
|
-
}
|
|
776
|
-
return data;
|
|
777
|
-
}, [items, data, paginated, getPageFromResponse, getItemsFromResponse, updatedItems]);
|
|
778
|
-
var finalItems = replaceUpdatedItems(partialItems);
|
|
779
|
-
|
|
780
|
-
// Keep a list of pages, useEffect wont work here because delayed
|
|
781
|
-
var pages = useRef(null);
|
|
782
|
-
if (isFetched && page !== null && data !== null) {
|
|
783
|
-
pages.current = _objectSpread(_objectSpread({}, pages.current), {}, _defineProperty({}, page, data));
|
|
784
|
-
}
|
|
785
|
-
var allItems = pages.current !== null ? replaceUpdatedItems(Object.keys(pages.current).flatMap(function (k) {
|
|
786
|
-
var _pages$current$k;
|
|
787
|
-
return (_pages$current$k = pages.current[k]) === null || _pages$current$k === void 0 ? void 0 : _pages$current$k.data;
|
|
788
|
-
})) : finalItems;
|
|
789
|
-
var finalLoading = isLoading || isFetching || isRefetching;
|
|
790
|
-
return _objectSpread(_objectSpread({}, otherProps), {}, {
|
|
791
|
-
isLoading: isLoading,
|
|
792
|
-
isFetching: isFetching,
|
|
793
|
-
isRefetching: isRefetching,
|
|
794
|
-
isFetched: isFetched,
|
|
795
|
-
items: finalItems,
|
|
796
|
-
pages: pages.current,
|
|
797
|
-
allItems: allItems,
|
|
798
|
-
loading: finalLoading,
|
|
799
|
-
loaded: isFetched,
|
|
800
|
-
reload: reload,
|
|
801
|
-
loadPage: loadPage,
|
|
802
|
-
loadNextPage: loadNextPage,
|
|
803
|
-
updateItem: updateItem,
|
|
804
|
-
pagination: paginated ? {
|
|
805
|
-
page: currentPage,
|
|
806
|
-
lastPage: lastPage,
|
|
807
|
-
total: total
|
|
808
|
-
} : null
|
|
809
|
-
});
|
|
810
|
-
};
|
|
811
|
-
|
|
812
|
-
var AccountApi = /*#__PURE__*/function () {
|
|
813
|
-
function AccountApi(api, opts) {
|
|
814
|
-
_classCallCheck(this, AccountApi);
|
|
497
|
+
class AuthApi {
|
|
498
|
+
constructor(api, opts) {
|
|
815
499
|
this.api = api;
|
|
816
|
-
this.options =
|
|
817
|
-
withCredentials:
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
}
|
|
829
|
-
}
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
}
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
}
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
withCredentials: withCredentials
|
|
886
|
-
});
|
|
887
|
-
}
|
|
888
|
-
}, {
|
|
889
|
-
key: "register",
|
|
890
|
-
value: function register(data) {
|
|
891
|
-
var withCredentials = this.options.withCredentials;
|
|
892
|
-
return this.api.requestPost(this.api.route('auth.register'), data, {
|
|
893
|
-
withSession: !withCredentials,
|
|
894
|
-
withCredentials: withCredentials
|
|
895
|
-
});
|
|
896
|
-
}
|
|
897
|
-
}, {
|
|
898
|
-
key: "logout",
|
|
899
|
-
value: function logout() {
|
|
900
|
-
var url = this.api.getFullUrl(this.api.route('auth.logout'));
|
|
901
|
-
return fetch(url, {
|
|
902
|
-
method: 'POST',
|
|
903
|
-
headers: _objectSpread({}, getCSRFHeaders()),
|
|
904
|
-
credentials: 'include'
|
|
905
|
-
})["catch"](function (err) {
|
|
906
|
-
console.log('logout err', err); // eslint-disable-line
|
|
907
|
-
throw err;
|
|
908
|
-
});
|
|
909
|
-
}
|
|
910
|
-
}, {
|
|
911
|
-
key: "requestPassword",
|
|
912
|
-
value: function requestPassword(email) {
|
|
913
|
-
var withCredentials = this.options.withCredentials;
|
|
914
|
-
return this.api.requestPost(this.api.route('auth.password.email'), {
|
|
915
|
-
email: email
|
|
916
|
-
}, {
|
|
917
|
-
withSession: !withCredentials,
|
|
918
|
-
withCredentials: withCredentials
|
|
919
|
-
});
|
|
920
|
-
}
|
|
921
|
-
}, {
|
|
922
|
-
key: "resetPassword",
|
|
923
|
-
value: function resetPassword(data) {
|
|
924
|
-
var withCredentials = this.options.withCredentials;
|
|
925
|
-
return this.api.requestPost(this.api.route('auth.password.update'), data, {
|
|
926
|
-
withSession: !withCredentials,
|
|
927
|
-
withCredentials: withCredentials
|
|
928
|
-
});
|
|
929
|
-
}
|
|
930
|
-
}]);
|
|
931
|
-
}();
|
|
500
|
+
this.options = {
|
|
501
|
+
withCredentials: true,
|
|
502
|
+
...opts
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
check() {
|
|
506
|
+
const {
|
|
507
|
+
withCredentials
|
|
508
|
+
} = this.options;
|
|
509
|
+
return this.api.requestGet(this.api.route('auth.check'), null, {
|
|
510
|
+
withSession: !withCredentials,
|
|
511
|
+
withCredentials
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
login(email, password) {
|
|
515
|
+
const {
|
|
516
|
+
withCredentials
|
|
517
|
+
} = this.options;
|
|
518
|
+
return this.api.requestPost(this.api.route('auth.login'), {
|
|
519
|
+
email,
|
|
520
|
+
password
|
|
521
|
+
}, {
|
|
522
|
+
withSession: !withCredentials,
|
|
523
|
+
withCredentials
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
register(data) {
|
|
527
|
+
const {
|
|
528
|
+
withCredentials
|
|
529
|
+
} = this.options;
|
|
530
|
+
return this.api.requestPost(this.api.route('auth.register'), data, {
|
|
531
|
+
withSession: !withCredentials,
|
|
532
|
+
withCredentials
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
logout() {
|
|
536
|
+
const url = this.api.getFullUrl(this.api.route('auth.logout'));
|
|
537
|
+
return fetch(url, {
|
|
538
|
+
method: 'POST',
|
|
539
|
+
headers: {
|
|
540
|
+
...getCSRFHeaders()
|
|
541
|
+
},
|
|
542
|
+
credentials: 'include'
|
|
543
|
+
}).catch(err => {
|
|
544
|
+
console.log('logout err', err); // eslint-disable-line
|
|
545
|
+
throw err;
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
requestPassword(email) {
|
|
549
|
+
const {
|
|
550
|
+
withCredentials
|
|
551
|
+
} = this.options;
|
|
552
|
+
return this.api.requestPost(this.api.route('auth.password.email'), {
|
|
553
|
+
email
|
|
554
|
+
}, {
|
|
555
|
+
withSession: !withCredentials,
|
|
556
|
+
withCredentials
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
resetPassword(data) {
|
|
560
|
+
const {
|
|
561
|
+
withCredentials
|
|
562
|
+
} = this.options;
|
|
563
|
+
return this.api.requestPost(this.api.route('auth.password.update'), data, {
|
|
564
|
+
withSession: !withCredentials,
|
|
565
|
+
withCredentials
|
|
566
|
+
});
|
|
567
|
+
}
|
|
568
|
+
}
|
|
932
569
|
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
_classCallCheck(this, Base);
|
|
937
|
-
this.options = _objectSpread(_objectSpread({
|
|
570
|
+
class Base {
|
|
571
|
+
constructor(opts = {}) {
|
|
572
|
+
this.options = {
|
|
938
573
|
routes: {},
|
|
939
|
-
generateUrl: null
|
|
940
|
-
|
|
574
|
+
generateUrl: null,
|
|
575
|
+
...opts,
|
|
941
576
|
baseUrl: opts.baseUrl,
|
|
942
577
|
onUnauthorized: opts.onUnauthorized || null
|
|
943
|
-
}
|
|
578
|
+
};
|
|
944
579
|
}
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
}
|
|
961
|
-
}
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
}
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
}
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
return generateUrl(_route, params);
|
|
1020
|
-
}
|
|
1021
|
-
return generatePath(routes[_route] || _route, params);
|
|
1022
|
-
}
|
|
1023
|
-
}, {
|
|
1024
|
-
key: "getFullUrl",
|
|
1025
|
-
value: function getFullUrl(path) {
|
|
1026
|
-
var _this$options$baseUrl = this.options.baseUrl,
|
|
1027
|
-
baseUrl = _this$options$baseUrl === void 0 ? null : _this$options$baseUrl;
|
|
1028
|
-
var hasProtocol = path.indexOf('://') !== -1;
|
|
1029
|
-
return baseUrl !== null && !hasProtocol ? "".concat(baseUrl.replace(/\/$/, ''), "/").concat(path.replace(/^\//, '')) : path;
|
|
1030
|
-
}
|
|
1031
|
-
}, {
|
|
1032
|
-
key: "onError",
|
|
1033
|
-
value: function onError(err) {
|
|
1034
|
-
var onUnauthorized = this.options.onUnauthorized;
|
|
1035
|
-
var _ref = err || {},
|
|
1036
|
-
_ref$status = _ref.status,
|
|
1037
|
-
status = _ref$status === void 0 ? null : _ref$status;
|
|
1038
|
-
var statusCode = parseInt(status, 10);
|
|
1039
|
-
// If status is refused and callback exists
|
|
1040
|
-
if ((statusCode === 401 || statusCode === 419) && onUnauthorized !== null) {
|
|
1041
|
-
return onUnauthorized();
|
|
1042
|
-
}
|
|
1043
|
-
throw err;
|
|
1044
|
-
}
|
|
1045
|
-
}]);
|
|
1046
|
-
}();
|
|
580
|
+
requestGet(path, query = null, opts = null) {
|
|
581
|
+
const finalQuery = query !== null ? queryString.stringify(query, {
|
|
582
|
+
arrayFormat: 'bracket'
|
|
583
|
+
}) : null;
|
|
584
|
+
return getJSON(`${this.getFullUrl(path)}${finalQuery !== null && finalQuery.length > 0 ? `?${finalQuery}` : ''}`, {
|
|
585
|
+
credentials: 'include',
|
|
586
|
+
headers: getCSRFHeaders(),
|
|
587
|
+
...opts
|
|
588
|
+
}).catch(error => this.onError(error));
|
|
589
|
+
}
|
|
590
|
+
requestPost(path, data, opts = null) {
|
|
591
|
+
return postJSON(this.getFullUrl(path), data, {
|
|
592
|
+
credentials: 'include',
|
|
593
|
+
headers: getCSRFHeaders(),
|
|
594
|
+
...opts
|
|
595
|
+
}).catch(error => this.onError(error));
|
|
596
|
+
}
|
|
597
|
+
requestPut(path, data, opts = null) {
|
|
598
|
+
return postJSON(this.getFullUrl(path), {
|
|
599
|
+
_method: 'PUT',
|
|
600
|
+
...data
|
|
601
|
+
}, {
|
|
602
|
+
credentials: 'include',
|
|
603
|
+
headers: getCSRFHeaders(),
|
|
604
|
+
...opts
|
|
605
|
+
}).catch(error => this.onError(error));
|
|
606
|
+
}
|
|
607
|
+
requestPatch(path, data, opts = null) {
|
|
608
|
+
return postJSON(this.getFullUrl(path), {
|
|
609
|
+
_method: 'PATCH',
|
|
610
|
+
...data
|
|
611
|
+
}, {
|
|
612
|
+
credentials: 'include',
|
|
613
|
+
headers: getCSRFHeaders(),
|
|
614
|
+
...opts
|
|
615
|
+
}).catch(error => this.onError(error));
|
|
616
|
+
}
|
|
617
|
+
requestDelete(path) {
|
|
618
|
+
return this.requestPost(this.getFullUrl(path), {
|
|
619
|
+
_method: 'DELETE'
|
|
620
|
+
}).catch(error => this.onError(error));
|
|
621
|
+
}
|
|
622
|
+
route(route, params) {
|
|
623
|
+
const {
|
|
624
|
+
routes,
|
|
625
|
+
generateUrl = null
|
|
626
|
+
} = this.options;
|
|
627
|
+
if (generateUrl !== null) {
|
|
628
|
+
return generateUrl(route, params);
|
|
629
|
+
}
|
|
630
|
+
return generatePath(routes[route] || route, params);
|
|
631
|
+
}
|
|
632
|
+
getFullUrl(path) {
|
|
633
|
+
const {
|
|
634
|
+
baseUrl = null
|
|
635
|
+
} = this.options;
|
|
636
|
+
const hasProtocol = path.indexOf('://') !== -1;
|
|
637
|
+
return baseUrl !== null && !hasProtocol ? `${baseUrl.replace(/\/$/, '')}/${path.replace(/^\//, '')}` : path;
|
|
638
|
+
}
|
|
639
|
+
onError(err) {
|
|
640
|
+
const {
|
|
641
|
+
onUnauthorized
|
|
642
|
+
} = this.options;
|
|
643
|
+
const {
|
|
644
|
+
status = null
|
|
645
|
+
} = err || {};
|
|
646
|
+
const statusCode = parseInt(status, 10);
|
|
647
|
+
// If status is refused and callback exists
|
|
648
|
+
if ((statusCode === 401 || statusCode === 419) && onUnauthorized !== null) {
|
|
649
|
+
return onUnauthorized();
|
|
650
|
+
}
|
|
651
|
+
throw err;
|
|
652
|
+
}
|
|
653
|
+
}
|
|
1047
654
|
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
_classCallCheck(this, MediasApi);
|
|
1052
|
-
return _callSuper(this, MediasApi, [{
|
|
655
|
+
class MediasApi extends Base {
|
|
656
|
+
constructor(opts = {}) {
|
|
657
|
+
super({
|
|
1053
658
|
baseUrl: opts.baseUrl ? opts.baseUrl : null,
|
|
1054
|
-
routes:
|
|
659
|
+
routes: {
|
|
1055
660
|
index: 'medias',
|
|
1056
661
|
trashed: 'medias/trash',
|
|
1057
662
|
tags: 'medias/tags',
|
|
@@ -1060,442 +665,590 @@ var MediasApi = /*#__PURE__*/function (_Base) {
|
|
|
1060
665
|
update: 'medias/:media',
|
|
1061
666
|
trash: 'medias/trash/:media',
|
|
1062
667
|
restore: 'medias/restore/:media',
|
|
1063
|
-
|
|
1064
|
-
replace: 'medias/replace/:media'
|
|
1065
|
-
|
|
1066
|
-
}]);
|
|
1067
|
-
}
|
|
1068
|
-
_inherits(MediasApi, _Base);
|
|
1069
|
-
return _createClass(MediasApi, [{
|
|
1070
|
-
key: "find",
|
|
1071
|
-
value: function find(id) {
|
|
1072
|
-
return this.requestGet(this.route('show', {
|
|
1073
|
-
media: id
|
|
1074
|
-
}));
|
|
1075
|
-
}
|
|
1076
|
-
}, {
|
|
1077
|
-
key: "get",
|
|
1078
|
-
value: function get() {
|
|
1079
|
-
var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1080
|
-
var page = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
1081
|
-
var count = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 10;
|
|
1082
|
-
var finalQuery = _objectSpread({}, query);
|
|
1083
|
-
if (page !== null) {
|
|
1084
|
-
finalQuery.page = page;
|
|
1085
|
-
}
|
|
1086
|
-
if (count !== null) {
|
|
1087
|
-
finalQuery.count = count;
|
|
1088
|
-
}
|
|
1089
|
-
return this.requestGet(this.route('index'), finalQuery);
|
|
1090
|
-
}
|
|
1091
|
-
}, {
|
|
1092
|
-
key: "getTrashed",
|
|
1093
|
-
value: function getTrashed() {
|
|
1094
|
-
var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1095
|
-
var page = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
1096
|
-
var count = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 10;
|
|
1097
|
-
var finalQuery = _objectSpread({}, query);
|
|
1098
|
-
if (page !== null) {
|
|
1099
|
-
finalQuery.page = page;
|
|
1100
|
-
}
|
|
1101
|
-
if (count !== null) {
|
|
1102
|
-
finalQuery.count = count;
|
|
668
|
+
delete: 'medias/:media',
|
|
669
|
+
replace: 'medias/replace/:media',
|
|
670
|
+
...(opts.routes || null)
|
|
1103
671
|
}
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
}, {
|
|
1118
|
-
key: "create",
|
|
1119
|
-
value: function create(data) {
|
|
1120
|
-
return this.requestPost(this.route('store'), data);
|
|
1121
|
-
}
|
|
1122
|
-
}, {
|
|
1123
|
-
key: "update",
|
|
1124
|
-
value: function update(id, data) {
|
|
1125
|
-
return this.requestPut(this.route('update', {
|
|
1126
|
-
media: id
|
|
1127
|
-
}), data);
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
find(id) {
|
|
675
|
+
return this.requestGet(this.route('show', {
|
|
676
|
+
media: id
|
|
677
|
+
}));
|
|
678
|
+
}
|
|
679
|
+
get(query = {}, page = 1, count = 10) {
|
|
680
|
+
const finalQuery = {
|
|
681
|
+
...query
|
|
682
|
+
};
|
|
683
|
+
if (page !== null) {
|
|
684
|
+
finalQuery.page = page;
|
|
1128
685
|
}
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
value: function trash(id) {
|
|
1132
|
-
return this.requestDelete(this.route('trash', {
|
|
1133
|
-
media: id
|
|
1134
|
-
}));
|
|
686
|
+
if (count !== null) {
|
|
687
|
+
finalQuery.count = count;
|
|
1135
688
|
}
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
689
|
+
return this.requestGet(this.route('index'), finalQuery);
|
|
690
|
+
}
|
|
691
|
+
getTrashed(query = {}, page = 1, count = 10) {
|
|
692
|
+
const finalQuery = {
|
|
693
|
+
...query
|
|
694
|
+
};
|
|
695
|
+
if (page !== null) {
|
|
696
|
+
finalQuery.page = page;
|
|
1142
697
|
}
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
value: function _delete(id) {
|
|
1146
|
-
return this.requestDelete(this.route('delete', {
|
|
1147
|
-
media: id
|
|
1148
|
-
}));
|
|
698
|
+
if (count !== null) {
|
|
699
|
+
finalQuery.count = count;
|
|
1149
700
|
}
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
701
|
+
return this.requestGet(this.route('trashed'), finalQuery);
|
|
702
|
+
}
|
|
703
|
+
getTags(query = {}, count = 10) {
|
|
704
|
+
const finalQuery = {
|
|
705
|
+
...query
|
|
706
|
+
};
|
|
707
|
+
if (count !== null) {
|
|
708
|
+
finalQuery.count = count;
|
|
1156
709
|
}
|
|
1157
|
-
|
|
1158
|
-
}
|
|
710
|
+
return this.requestGet(this.route('tags'), finalQuery);
|
|
711
|
+
}
|
|
712
|
+
create(data) {
|
|
713
|
+
return this.requestPost(this.route('store'), data);
|
|
714
|
+
}
|
|
715
|
+
update(id, data) {
|
|
716
|
+
return this.requestPut(this.route('update', {
|
|
717
|
+
media: id
|
|
718
|
+
}), data);
|
|
719
|
+
}
|
|
720
|
+
trash(id) {
|
|
721
|
+
return this.requestDelete(this.route('trash', {
|
|
722
|
+
media: id
|
|
723
|
+
}));
|
|
724
|
+
}
|
|
725
|
+
restore(id) {
|
|
726
|
+
return this.requestPost(this.route('restore', {
|
|
727
|
+
media: id
|
|
728
|
+
}));
|
|
729
|
+
}
|
|
730
|
+
delete(id) {
|
|
731
|
+
return this.requestDelete(this.route('delete', {
|
|
732
|
+
media: id
|
|
733
|
+
}));
|
|
734
|
+
}
|
|
735
|
+
replace(id, data) {
|
|
736
|
+
return this.requestPost(this.route('replace', {
|
|
737
|
+
media: id
|
|
738
|
+
}), data);
|
|
739
|
+
}
|
|
740
|
+
}
|
|
1159
741
|
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
_classCallCheck(this, ResourcesApi);
|
|
742
|
+
class ResourcesApi {
|
|
743
|
+
constructor(api) {
|
|
1163
744
|
this.api = api;
|
|
1164
745
|
}
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1189
|
-
var page = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
1190
|
-
var count = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 12;
|
|
1191
|
-
var finalQuery = _objectSpread({}, query);
|
|
1192
|
-
if (page !== null) {
|
|
1193
|
-
finalQuery.page = page;
|
|
1194
|
-
}
|
|
1195
|
-
if (count !== null) {
|
|
1196
|
-
finalQuery.count = count;
|
|
1197
|
-
}
|
|
1198
|
-
return this.api.requestGet(this.resourceRoute(resource, 'index'), finalQuery, {
|
|
1199
|
-
withCredentials: true
|
|
1200
|
-
});
|
|
1201
|
-
}
|
|
1202
|
-
}, {
|
|
1203
|
-
key: "store",
|
|
1204
|
-
value: function store(resource, data) {
|
|
1205
|
-
return this.api.requestPost(this.resourceRoute(resource, 'store'), data, {
|
|
1206
|
-
withCredentials: true
|
|
1207
|
-
});
|
|
1208
|
-
}
|
|
1209
|
-
}, {
|
|
1210
|
-
key: "update",
|
|
1211
|
-
value: function update(resource, id, data) {
|
|
1212
|
-
return this.api.requestPatch(this.resourceRoute(resource, 'update', {
|
|
1213
|
-
id: id
|
|
1214
|
-
}), data, {
|
|
1215
|
-
withCredentials: true
|
|
1216
|
-
});
|
|
1217
|
-
}
|
|
1218
|
-
}, {
|
|
1219
|
-
key: "destroy",
|
|
1220
|
-
value: function destroy(resource, id) {
|
|
1221
|
-
return this.api.requestDelete(this.resourceRoute(resource, 'destroy', {
|
|
1222
|
-
id: id
|
|
1223
|
-
}), null, {
|
|
1224
|
-
withCredentials: true
|
|
1225
|
-
});
|
|
746
|
+
resourceRoute({
|
|
747
|
+
id,
|
|
748
|
+
has_routes: hasRoutes = false
|
|
749
|
+
}, route, params) {
|
|
750
|
+
const routePrefix = hasRoutes ? `resources.${id}` : 'resources';
|
|
751
|
+
return this.api.route(`${routePrefix}.${route}`, hasRoutes ? params : {
|
|
752
|
+
resource: id,
|
|
753
|
+
...params
|
|
754
|
+
});
|
|
755
|
+
}
|
|
756
|
+
find(resource, id) {
|
|
757
|
+
return this.api.requestGet(this.resourceRoute(resource, 'show', {
|
|
758
|
+
id
|
|
759
|
+
}), null, {
|
|
760
|
+
withCredentials: true
|
|
761
|
+
});
|
|
762
|
+
}
|
|
763
|
+
get(resource, query = {}, page = 1, count = 12) {
|
|
764
|
+
const finalQuery = {
|
|
765
|
+
...query
|
|
766
|
+
};
|
|
767
|
+
if (page !== null) {
|
|
768
|
+
finalQuery.page = page;
|
|
1226
769
|
}
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
value: function clone(resource, id) {
|
|
1230
|
-
var data = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
1231
|
-
return this.api.requestPost(this.resourceRoute(resource, 'clone', {
|
|
1232
|
-
id: id
|
|
1233
|
-
}), data, {
|
|
1234
|
-
withCredentials: true
|
|
1235
|
-
});
|
|
770
|
+
if (count !== null) {
|
|
771
|
+
finalQuery.count = count;
|
|
1236
772
|
}
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
773
|
+
return this.api.requestGet(this.resourceRoute(resource, 'index'), finalQuery, {
|
|
774
|
+
withCredentials: true
|
|
775
|
+
});
|
|
776
|
+
}
|
|
777
|
+
store(resource, data) {
|
|
778
|
+
return this.api.requestPost(this.resourceRoute(resource, 'store'), data, {
|
|
779
|
+
withCredentials: true
|
|
780
|
+
});
|
|
781
|
+
}
|
|
782
|
+
update(resource, id, data) {
|
|
783
|
+
return this.api.requestPatch(this.resourceRoute(resource, 'update', {
|
|
784
|
+
id
|
|
785
|
+
}), data, {
|
|
786
|
+
withCredentials: true
|
|
787
|
+
});
|
|
788
|
+
}
|
|
789
|
+
destroy(resource, id) {
|
|
790
|
+
return this.api.requestDelete(this.resourceRoute(resource, 'destroy', {
|
|
791
|
+
id
|
|
792
|
+
}), null, {
|
|
793
|
+
withCredentials: true
|
|
794
|
+
});
|
|
795
|
+
}
|
|
796
|
+
clone(resource, id, data = null) {
|
|
797
|
+
return this.api.requestPost(this.resourceRoute(resource, 'clone', {
|
|
798
|
+
id
|
|
799
|
+
}), data, {
|
|
800
|
+
withCredentials: true
|
|
801
|
+
});
|
|
802
|
+
}
|
|
803
|
+
restore(resource, id, data = null) {
|
|
804
|
+
return this.api.requestPost(this.resourceRoute(resource, 'restore', {
|
|
805
|
+
id
|
|
806
|
+
}), data, {
|
|
807
|
+
withCredentials: true
|
|
808
|
+
});
|
|
809
|
+
}
|
|
810
|
+
}
|
|
1249
811
|
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
_classCallCheck(this, Api);
|
|
1255
|
-
_this = _callSuper(this, Api, [opts]);
|
|
1256
|
-
_this.auth = new AuthApi(_this, {
|
|
812
|
+
class Api extends Base {
|
|
813
|
+
constructor(opts = {}) {
|
|
814
|
+
super(opts);
|
|
815
|
+
this.auth = new AuthApi(this, {
|
|
1257
816
|
withCredentials: true
|
|
1258
817
|
});
|
|
1259
|
-
|
|
818
|
+
this.account = new AccountApi(this, {
|
|
1260
819
|
withCredentials: true
|
|
1261
820
|
});
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
return _this;
|
|
821
|
+
this.medias = new MediasApi(opts);
|
|
822
|
+
this.resources = new ResourcesApi(this);
|
|
1265
823
|
}
|
|
1266
|
-
|
|
1267
|
-
return _createClass(Api);
|
|
1268
|
-
}(Base);
|
|
824
|
+
}
|
|
1269
825
|
|
|
1270
826
|
/* eslint-disable react/jsx-props-no-spreading */
|
|
1271
827
|
|
|
1272
|
-
|
|
828
|
+
const ApiContext = /*#__PURE__*/createContext(null);
|
|
1273
829
|
function useApi() {
|
|
1274
830
|
return use(ApiContext);
|
|
1275
831
|
}
|
|
1276
|
-
function ApiProvider(
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
generateUrl: generateUrl,
|
|
1290
|
-
onUnauthorized: onUnauthorized
|
|
1291
|
-
});
|
|
1292
|
-
}, [previousApi, initialApi, baseUrl]);
|
|
832
|
+
function ApiProvider({
|
|
833
|
+
api: initialApi = null,
|
|
834
|
+
baseUrl = undefined,
|
|
835
|
+
onUnauthorized = null,
|
|
836
|
+
children
|
|
837
|
+
}) {
|
|
838
|
+
const generateUrl = useUrlGenerator();
|
|
839
|
+
const previousApi = useApi();
|
|
840
|
+
const api = useMemo(() => initialApi || previousApi || new Api({
|
|
841
|
+
baseUrl,
|
|
842
|
+
generateUrl,
|
|
843
|
+
onUnauthorized
|
|
844
|
+
}), [previousApi, initialApi, baseUrl]);
|
|
1293
845
|
return /*#__PURE__*/jsx(ApiContext, {
|
|
1294
846
|
value: api,
|
|
1295
847
|
children: children
|
|
1296
848
|
});
|
|
1297
849
|
}
|
|
1298
850
|
|
|
1299
|
-
function useResourceDestroy(
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
851
|
+
function useResourceDestroy(t0, t1, t2) {
|
|
852
|
+
const $ = c(19);
|
|
853
|
+
const resource = t0 === undefined ? null : t0;
|
|
854
|
+
const id = t1 === undefined ? null : t1;
|
|
855
|
+
let t3;
|
|
856
|
+
if ($[0] !== t2) {
|
|
857
|
+
t3 = t2 === undefined ? {} : t2;
|
|
858
|
+
$[0] = t2;
|
|
859
|
+
$[1] = t3;
|
|
860
|
+
} else {
|
|
861
|
+
t3 = $[1];
|
|
862
|
+
}
|
|
863
|
+
const options = t3;
|
|
864
|
+
const providedResource = usePanneauResource(id !== null && !isObject$1(id) ? resource : null);
|
|
865
|
+
const contextResource = useResource();
|
|
866
|
+
const finalResource = providedResource || contextResource;
|
|
867
|
+
const finalId = providedResource !== null ? id : resource;
|
|
868
|
+
const api = useApi();
|
|
869
|
+
let t4;
|
|
870
|
+
if ($[2] !== api || $[3] !== finalId || $[4] !== finalResource) {
|
|
871
|
+
t4 = providedId => api.resources.destroy(finalResource, providedId || finalId);
|
|
872
|
+
$[2] = api;
|
|
873
|
+
$[3] = finalId;
|
|
874
|
+
$[4] = finalResource;
|
|
875
|
+
$[5] = t4;
|
|
876
|
+
} else {
|
|
877
|
+
t4 = $[5];
|
|
878
|
+
}
|
|
879
|
+
let t5;
|
|
880
|
+
if ($[6] !== options || $[7] !== t4) {
|
|
881
|
+
t5 = {
|
|
882
|
+
mutationFn: t4,
|
|
883
|
+
...options
|
|
884
|
+
};
|
|
885
|
+
$[6] = options;
|
|
886
|
+
$[7] = t4;
|
|
887
|
+
$[8] = t5;
|
|
888
|
+
} else {
|
|
889
|
+
t5 = $[8];
|
|
890
|
+
}
|
|
891
|
+
const t6 = useMutation(t5);
|
|
892
|
+
let isPending;
|
|
893
|
+
let mutate;
|
|
894
|
+
let mutateAsync;
|
|
895
|
+
let other;
|
|
896
|
+
if ($[9] !== t6) {
|
|
897
|
+
({
|
|
898
|
+
mutate,
|
|
899
|
+
mutateAsync,
|
|
900
|
+
isPending,
|
|
901
|
+
...other
|
|
902
|
+
} = t6);
|
|
903
|
+
$[9] = t6;
|
|
904
|
+
$[10] = isPending;
|
|
905
|
+
$[11] = mutate;
|
|
906
|
+
$[12] = mutateAsync;
|
|
907
|
+
$[13] = other;
|
|
908
|
+
} else {
|
|
909
|
+
isPending = $[10];
|
|
910
|
+
mutate = $[11];
|
|
911
|
+
mutateAsync = $[12];
|
|
912
|
+
other = $[13];
|
|
913
|
+
}
|
|
914
|
+
let t7;
|
|
915
|
+
if ($[14] !== isPending || $[15] !== mutate || $[16] !== mutateAsync || $[17] !== other) {
|
|
916
|
+
t7 = {
|
|
917
|
+
destroy: mutate,
|
|
918
|
+
destroyAsync: mutateAsync,
|
|
919
|
+
loading: isPending,
|
|
920
|
+
mutate,
|
|
921
|
+
mutateAsync,
|
|
922
|
+
isPending,
|
|
923
|
+
...other
|
|
924
|
+
};
|
|
925
|
+
$[14] = isPending;
|
|
926
|
+
$[15] = mutate;
|
|
927
|
+
$[16] = mutateAsync;
|
|
928
|
+
$[17] = other;
|
|
929
|
+
$[18] = t7;
|
|
930
|
+
} else {
|
|
931
|
+
t7 = $[18];
|
|
932
|
+
}
|
|
933
|
+
return t7;
|
|
1320
934
|
}
|
|
1321
935
|
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
}
|
|
936
|
+
function useResourceItem(resource, t0, t1) {
|
|
937
|
+
const $ = c(17);
|
|
938
|
+
const id = t0 === undefined ? null : t0;
|
|
939
|
+
const opts = t1 === undefined ? null : t1;
|
|
940
|
+
const api = useApi();
|
|
941
|
+
const providedResource = usePanneauResource(id !== null && !isObject$1(id) ? resource : null);
|
|
942
|
+
const contextResource = useResource();
|
|
943
|
+
const finalResource = providedResource || contextResource;
|
|
944
|
+
const finalId = providedResource !== null ? id : resource;
|
|
945
|
+
const {
|
|
946
|
+
id: resourceId
|
|
947
|
+
} = finalResource;
|
|
948
|
+
let t2;
|
|
949
|
+
if ($[0] !== finalId || $[1] !== resourceId) {
|
|
950
|
+
t2 = [resourceId, finalId];
|
|
951
|
+
$[0] = finalId;
|
|
952
|
+
$[1] = resourceId;
|
|
953
|
+
$[2] = t2;
|
|
954
|
+
} else {
|
|
955
|
+
t2 = $[2];
|
|
956
|
+
}
|
|
957
|
+
let t3;
|
|
958
|
+
if ($[3] !== api || $[4] !== finalId || $[5] !== finalResource) {
|
|
959
|
+
t3 = () => api.resources.find(finalResource, finalId);
|
|
960
|
+
$[3] = api;
|
|
961
|
+
$[4] = finalId;
|
|
962
|
+
$[5] = finalResource;
|
|
963
|
+
$[6] = t3;
|
|
964
|
+
} else {
|
|
965
|
+
t3 = $[6];
|
|
966
|
+
}
|
|
967
|
+
let t4;
|
|
968
|
+
if ($[7] !== opts || $[8] !== t2 || $[9] !== t3) {
|
|
969
|
+
t4 = {
|
|
970
|
+
queryKey: t2,
|
|
971
|
+
queryFn: t3,
|
|
972
|
+
...opts
|
|
973
|
+
};
|
|
974
|
+
$[7] = opts;
|
|
975
|
+
$[8] = t2;
|
|
976
|
+
$[9] = t3;
|
|
977
|
+
$[10] = t4;
|
|
978
|
+
} else {
|
|
979
|
+
t4 = $[10];
|
|
980
|
+
}
|
|
981
|
+
const t5 = useQuery(t4);
|
|
982
|
+
let request;
|
|
983
|
+
let t6;
|
|
984
|
+
if ($[11] !== t5) {
|
|
985
|
+
({
|
|
986
|
+
data: t6,
|
|
987
|
+
...request
|
|
988
|
+
} = t5);
|
|
989
|
+
$[11] = t5;
|
|
990
|
+
$[12] = request;
|
|
991
|
+
$[13] = t6;
|
|
992
|
+
} else {
|
|
993
|
+
request = $[12];
|
|
994
|
+
t6 = $[13];
|
|
995
|
+
}
|
|
996
|
+
const data = t6 === undefined ? null : t6;
|
|
997
|
+
let t7;
|
|
998
|
+
if ($[14] !== data || $[15] !== request) {
|
|
999
|
+
t7 = {
|
|
1000
|
+
item: data,
|
|
1001
|
+
...request
|
|
1002
|
+
};
|
|
1003
|
+
$[14] = data;
|
|
1004
|
+
$[15] = request;
|
|
1005
|
+
$[16] = t7;
|
|
1006
|
+
} else {
|
|
1007
|
+
t7 = $[16];
|
|
1008
|
+
}
|
|
1009
|
+
return t7;
|
|
1334
1010
|
}
|
|
1335
1011
|
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
}
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1012
|
+
function useResourceItems(t0, t1, t2, t3, t4) {
|
|
1013
|
+
const $ = c(11);
|
|
1014
|
+
const resource = t0 === undefined ? null : t0;
|
|
1015
|
+
const query = t1 === undefined ? null : t1;
|
|
1016
|
+
const page = t2 === undefined ? null : t2;
|
|
1017
|
+
const count = t3 === undefined ? null : t3;
|
|
1018
|
+
const opts = t4 === undefined ? null : t4;
|
|
1019
|
+
const api = useApi();
|
|
1020
|
+
const providedResource = usePanneauResource(isString(resource) || isObject(resource) ? resource : null);
|
|
1021
|
+
const firstIsResource = (isString(resource) || isObject(resource)) && providedResource !== null;
|
|
1022
|
+
const contextResource = useResource();
|
|
1023
|
+
const finalResource = providedResource || contextResource;
|
|
1024
|
+
let t5;
|
|
1025
|
+
if ($[0] !== finalResource) {
|
|
1026
|
+
t5 = finalResource || {};
|
|
1027
|
+
$[0] = finalResource;
|
|
1028
|
+
$[1] = t5;
|
|
1029
|
+
} else {
|
|
1030
|
+
t5 = $[1];
|
|
1031
|
+
}
|
|
1032
|
+
const {
|
|
1033
|
+
id: t6
|
|
1034
|
+
} = t5;
|
|
1035
|
+
const resourceId = t6 === undefined ? null : t6;
|
|
1036
|
+
const finalQuery = firstIsResource ? query : resource;
|
|
1037
|
+
const finalPage = firstIsResource ? page : query;
|
|
1038
|
+
const finalCount = firstIsResource ? count : page;
|
|
1039
|
+
const finalOpts = firstIsResource ? opts : count;
|
|
1040
|
+
let t7;
|
|
1041
|
+
if ($[2] !== api || $[3] !== finalResource) {
|
|
1042
|
+
t7 = (query_0, t8, t9) => {
|
|
1043
|
+
const requestedPage = t8 === undefined ? null : t8;
|
|
1044
|
+
const count_0 = t9 === undefined ? null : t9;
|
|
1045
|
+
return api.resources.get(finalResource, query_0, requestedPage, count_0);
|
|
1046
|
+
};
|
|
1047
|
+
$[2] = api;
|
|
1048
|
+
$[3] = finalResource;
|
|
1049
|
+
$[4] = t7;
|
|
1050
|
+
} else {
|
|
1051
|
+
t7 = $[4];
|
|
1052
|
+
}
|
|
1053
|
+
const getItems = t7;
|
|
1054
|
+
let t8;
|
|
1055
|
+
if ($[5] !== finalCount || $[6] !== finalOpts || $[7] !== finalPage || $[8] !== finalQuery || $[9] !== getItems) {
|
|
1056
|
+
t8 = {
|
|
1057
|
+
getItems,
|
|
1058
|
+
query: finalQuery,
|
|
1059
|
+
page: finalPage,
|
|
1060
|
+
count: finalCount,
|
|
1061
|
+
...finalOpts
|
|
1062
|
+
};
|
|
1063
|
+
$[5] = finalCount;
|
|
1064
|
+
$[6] = finalOpts;
|
|
1065
|
+
$[7] = finalPage;
|
|
1066
|
+
$[8] = finalQuery;
|
|
1067
|
+
$[9] = getItems;
|
|
1068
|
+
$[10] = t8;
|
|
1069
|
+
} else {
|
|
1070
|
+
t8 = $[10];
|
|
1071
|
+
}
|
|
1072
|
+
return useItems(resourceId, t8);
|
|
1387
1073
|
}
|
|
1388
1074
|
|
|
1389
1075
|
function useResourceCreate(resource) {
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
}
|
|
1076
|
+
const $ = c(6);
|
|
1077
|
+
const [loading, setLoading] = useState(false);
|
|
1078
|
+
const api = useApi();
|
|
1079
|
+
let t0;
|
|
1080
|
+
if ($[0] !== api || $[1] !== resource) {
|
|
1081
|
+
t0 = data => {
|
|
1082
|
+
setLoading(true);
|
|
1083
|
+
return api.resources.store(resource, data).then(response => {
|
|
1084
|
+
setLoading(false);
|
|
1085
|
+
return response;
|
|
1086
|
+
}).catch(e => {
|
|
1087
|
+
setLoading(false);
|
|
1088
|
+
throw e;
|
|
1089
|
+
});
|
|
1090
|
+
};
|
|
1091
|
+
$[0] = api;
|
|
1092
|
+
$[1] = resource;
|
|
1093
|
+
$[2] = t0;
|
|
1094
|
+
} else {
|
|
1095
|
+
t0 = $[2];
|
|
1096
|
+
}
|
|
1097
|
+
const store = t0;
|
|
1098
|
+
let t1;
|
|
1099
|
+
if ($[3] !== loading || $[4] !== store) {
|
|
1100
|
+
t1 = {
|
|
1101
|
+
store,
|
|
1102
|
+
loading
|
|
1103
|
+
};
|
|
1104
|
+
$[3] = loading;
|
|
1105
|
+
$[4] = store;
|
|
1106
|
+
$[5] = t1;
|
|
1107
|
+
} else {
|
|
1108
|
+
t1 = $[5];
|
|
1109
|
+
}
|
|
1110
|
+
return t1;
|
|
1409
1111
|
}
|
|
1410
1112
|
|
|
1411
1113
|
function useResourceUpdate(resource, id) {
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1114
|
+
const $ = c(7);
|
|
1115
|
+
const [loading, setLoading] = useState(false);
|
|
1116
|
+
const api = useApi();
|
|
1117
|
+
let t0;
|
|
1118
|
+
if ($[0] !== api || $[1] !== id || $[2] !== resource) {
|
|
1119
|
+
t0 = data => {
|
|
1120
|
+
setLoading(true);
|
|
1121
|
+
return api.resources.update(resource, id, data).then(response => {
|
|
1122
|
+
setLoading(false);
|
|
1123
|
+
return response;
|
|
1124
|
+
}).catch(e => {
|
|
1125
|
+
setLoading(false);
|
|
1126
|
+
throw e;
|
|
1127
|
+
});
|
|
1128
|
+
};
|
|
1129
|
+
$[0] = api;
|
|
1130
|
+
$[1] = id;
|
|
1131
|
+
$[2] = resource;
|
|
1132
|
+
$[3] = t0;
|
|
1133
|
+
} else {
|
|
1134
|
+
t0 = $[3];
|
|
1135
|
+
}
|
|
1136
|
+
const update = t0;
|
|
1137
|
+
let t1;
|
|
1138
|
+
if ($[4] !== loading || $[5] !== update) {
|
|
1139
|
+
t1 = {
|
|
1140
|
+
update,
|
|
1141
|
+
loading
|
|
1142
|
+
};
|
|
1143
|
+
$[4] = loading;
|
|
1144
|
+
$[5] = update;
|
|
1145
|
+
$[6] = t1;
|
|
1146
|
+
} else {
|
|
1147
|
+
t1 = $[6];
|
|
1148
|
+
}
|
|
1149
|
+
return t1;
|
|
1431
1150
|
}
|
|
1432
1151
|
|
|
1433
|
-
function useResourceClone(resource) {
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1152
|
+
function useResourceClone(resource, t0) {
|
|
1153
|
+
const $ = c(7);
|
|
1154
|
+
const id = t0 === undefined ? null : t0;
|
|
1155
|
+
const [loading, setLoading] = useState(false);
|
|
1156
|
+
const api = useApi();
|
|
1157
|
+
let t1;
|
|
1158
|
+
if ($[0] !== api || $[1] !== id || $[2] !== resource) {
|
|
1159
|
+
t1 = providedId => {
|
|
1160
|
+
setLoading(true);
|
|
1161
|
+
return api.resources.clone(resource, providedId || id).then(response => {
|
|
1162
|
+
setLoading(false);
|
|
1163
|
+
return response;
|
|
1164
|
+
}).catch(e => {
|
|
1165
|
+
setLoading(false);
|
|
1166
|
+
throw e;
|
|
1167
|
+
});
|
|
1168
|
+
};
|
|
1169
|
+
$[0] = api;
|
|
1170
|
+
$[1] = id;
|
|
1171
|
+
$[2] = resource;
|
|
1172
|
+
$[3] = t1;
|
|
1173
|
+
} else {
|
|
1174
|
+
t1 = $[3];
|
|
1175
|
+
}
|
|
1176
|
+
const clone = t1;
|
|
1177
|
+
let t2;
|
|
1178
|
+
if ($[4] !== clone || $[5] !== loading) {
|
|
1179
|
+
t2 = {
|
|
1180
|
+
clone,
|
|
1181
|
+
loading
|
|
1182
|
+
};
|
|
1183
|
+
$[4] = clone;
|
|
1184
|
+
$[5] = loading;
|
|
1185
|
+
$[6] = t2;
|
|
1186
|
+
} else {
|
|
1187
|
+
t2 = $[6];
|
|
1188
|
+
}
|
|
1189
|
+
return t2;
|
|
1454
1190
|
}
|
|
1455
1191
|
|
|
1456
|
-
function useResourceRestore(resource) {
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1192
|
+
function useResourceRestore(resource, t0) {
|
|
1193
|
+
const $ = c(7);
|
|
1194
|
+
const id = t0 === undefined ? null : t0;
|
|
1195
|
+
const [loading, setLoading] = useState(false);
|
|
1196
|
+
const api = useApi();
|
|
1197
|
+
let t1;
|
|
1198
|
+
if ($[0] !== api || $[1] !== id || $[2] !== resource) {
|
|
1199
|
+
t1 = providedId => {
|
|
1200
|
+
setLoading(true);
|
|
1201
|
+
return api.resources.restore(resource, providedId || id).then(response => {
|
|
1202
|
+
setLoading(false);
|
|
1203
|
+
return response;
|
|
1204
|
+
}).catch(e => {
|
|
1205
|
+
setLoading(false);
|
|
1206
|
+
throw e;
|
|
1207
|
+
});
|
|
1208
|
+
};
|
|
1209
|
+
$[0] = api;
|
|
1210
|
+
$[1] = id;
|
|
1211
|
+
$[2] = resource;
|
|
1212
|
+
$[3] = t1;
|
|
1213
|
+
} else {
|
|
1214
|
+
t1 = $[3];
|
|
1215
|
+
}
|
|
1216
|
+
const restore = t1;
|
|
1217
|
+
let t2;
|
|
1218
|
+
if ($[4] !== loading || $[5] !== restore) {
|
|
1219
|
+
t2 = {
|
|
1220
|
+
restore,
|
|
1221
|
+
loading
|
|
1222
|
+
};
|
|
1223
|
+
$[4] = loading;
|
|
1224
|
+
$[5] = restore;
|
|
1225
|
+
$[6] = t2;
|
|
1226
|
+
} else {
|
|
1227
|
+
t2 = $[6];
|
|
1228
|
+
}
|
|
1229
|
+
return t2;
|
|
1477
1230
|
}
|
|
1478
1231
|
|
|
1479
|
-
|
|
1232
|
+
/* eslint-disable react/jsx-props-no-spreading */
|
|
1233
|
+
const QueryContext = /*#__PURE__*/createContext(null);
|
|
1480
1234
|
function useQueryContext() {
|
|
1481
1235
|
return use(QueryContext);
|
|
1482
1236
|
}
|
|
1483
|
-
function QueryProvider(
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
var queryClient = useMemo(function () {
|
|
1492
|
-
var client = new QueryClient(_objectSpread({
|
|
1237
|
+
function QueryProvider({
|
|
1238
|
+
config: initialConfig = null,
|
|
1239
|
+
initialKey = null,
|
|
1240
|
+
initialData = null,
|
|
1241
|
+
children
|
|
1242
|
+
}) {
|
|
1243
|
+
const queryClient = useMemo(() => {
|
|
1244
|
+
const client = new QueryClient({
|
|
1493
1245
|
defaultOptions: {
|
|
1494
1246
|
queries: {
|
|
1495
1247
|
staleTime: Infinity
|
|
1496
1248
|
}
|
|
1497
|
-
}
|
|
1498
|
-
|
|
1249
|
+
},
|
|
1250
|
+
...initialConfig
|
|
1251
|
+
});
|
|
1499
1252
|
if (initialKey !== null && initialData !== null) {
|
|
1500
1253
|
client.setQueryData(initialKey, initialData);
|
|
1501
1254
|
}
|
|
@@ -1507,18 +1260,47 @@ function QueryProvider(_ref) {
|
|
|
1507
1260
|
});
|
|
1508
1261
|
}
|
|
1509
1262
|
|
|
1510
|
-
function DataProvider(
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
apiBaseUrl
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1263
|
+
function DataProvider(t0) {
|
|
1264
|
+
const $ = c(7);
|
|
1265
|
+
const {
|
|
1266
|
+
api: t1,
|
|
1267
|
+
apiBaseUrl: t2,
|
|
1268
|
+
children: t3
|
|
1269
|
+
} = t0;
|
|
1270
|
+
const api = t1 === undefined ? null : t1;
|
|
1271
|
+
const apiBaseUrl = t2 === undefined ? undefined : t2;
|
|
1272
|
+
const children = t3 === undefined ? null : t3;
|
|
1273
|
+
const [client] = useState(_temp);
|
|
1274
|
+
let t4;
|
|
1275
|
+
if ($[0] !== api || $[1] !== apiBaseUrl || $[2] !== children) {
|
|
1276
|
+
t4 = /*#__PURE__*/jsx(ApiProvider, {
|
|
1277
|
+
api: api,
|
|
1278
|
+
baseUrl: apiBaseUrl,
|
|
1279
|
+
children: children
|
|
1280
|
+
});
|
|
1281
|
+
$[0] = api;
|
|
1282
|
+
$[1] = apiBaseUrl;
|
|
1283
|
+
$[2] = children;
|
|
1284
|
+
$[3] = t4;
|
|
1285
|
+
} else {
|
|
1286
|
+
t4 = $[3];
|
|
1287
|
+
}
|
|
1288
|
+
let t5;
|
|
1289
|
+
if ($[4] !== client || $[5] !== t4) {
|
|
1290
|
+
t5 = /*#__PURE__*/jsx(QueryClientProvider, {
|
|
1291
|
+
client: client,
|
|
1292
|
+
children: t4
|
|
1293
|
+
});
|
|
1294
|
+
$[4] = client;
|
|
1295
|
+
$[5] = t4;
|
|
1296
|
+
$[6] = t5;
|
|
1297
|
+
} else {
|
|
1298
|
+
t5 = $[6];
|
|
1299
|
+
}
|
|
1300
|
+
return t5;
|
|
1301
|
+
}
|
|
1302
|
+
function _temp() {
|
|
1303
|
+
return new QueryClient();
|
|
1522
1304
|
}
|
|
1523
1305
|
|
|
1524
|
-
export { Api, ApiProvider, Base as BaseApi, DataProvider, QueryProvider, useApi,
|
|
1306
|
+
export { Api, ApiProvider, Base as BaseApi, DataProvider, QueryProvider, useApi, useItem, useItems, useQueryContext, useResourceClone, useResourceDestroy, useResourceItem, useResourceItems, useResourceRestore, useResourceCreate as useResourceStore, useResourceUpdate };
|