@panneau/data 4.0.58 → 4.0.63
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 +9 -4
- package/dist/index.js +121 -69
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
2
|
-
import { UseQueryOptions, UseQueryResult, UseMutationResult, UseMutationOptions, QueryClient } from '@tanstack/react-query';
|
|
2
|
+
import { UseQueryOptions, UseQueryResult, UseMutationResult, UseMutationOptions, QueryClientConfig, QueryClient } from '@tanstack/react-query';
|
|
3
3
|
import { Item, Pagination, Resource, ResourceItem } from '@panneau/core';
|
|
4
4
|
import * as react from 'react';
|
|
5
5
|
import { ReactNode } from 'react';
|
|
@@ -193,7 +193,7 @@ declare class MediasApi extends Base {
|
|
|
193
193
|
update(id: any, data: any): Promise<unknown>;
|
|
194
194
|
trash(id: any): Promise<unknown>;
|
|
195
195
|
restore(id: any): Promise<unknown>;
|
|
196
|
-
|
|
196
|
+
destroy(id: any): Promise<unknown>;
|
|
197
197
|
replace(id: any, data: any): Promise<unknown>;
|
|
198
198
|
}
|
|
199
199
|
|
|
@@ -231,7 +231,7 @@ declare function ApiProvider({ api: initialApi, baseUrl, onUnauthorized, childre
|
|
|
231
231
|
|
|
232
232
|
type QueryInitialData = Record<string, unknown> | Array<Record<string, unknown>>;
|
|
233
233
|
interface QueryProviderProps {
|
|
234
|
-
config?:
|
|
234
|
+
config?: QueryClientConfig | null;
|
|
235
235
|
initialKey?: string[] | null;
|
|
236
236
|
initialData?: QueryInitialData | null;
|
|
237
237
|
children: ReactNode;
|
|
@@ -242,9 +242,14 @@ declare function QueryProvider({ config: initialConfig, initialKey, initialData,
|
|
|
242
242
|
interface DataProviderProps {
|
|
243
243
|
api?: Api | null;
|
|
244
244
|
apiBaseUrl?: string;
|
|
245
|
+
baseUrl?: string;
|
|
246
|
+
queryConfig?: QueryClientConfig | null;
|
|
247
|
+
initialQueryKey?: string[] | null;
|
|
248
|
+
initialQueryData?: Record<string, unknown> | Array<Record<string, unknown>> | null;
|
|
249
|
+
onUnauthorized?: (() => void) | null;
|
|
245
250
|
children?: ReactNode;
|
|
246
251
|
}
|
|
247
|
-
declare function DataProvider({ api, apiBaseUrl, children }: DataProviderProps): react.JSX.Element;
|
|
252
|
+
declare function DataProvider({ api, apiBaseUrl, baseUrl, children, queryConfig, initialQueryKey, initialQueryData, onUnauthorized, }: DataProviderProps): react.JSX.Element;
|
|
248
253
|
|
|
249
254
|
export { Api, ApiProvider, Base as BaseApi, DataProvider, QueryProvider, useApi, useItem, useItems, useQueryContext, useResourceClone, useResourceDestroy, useResourceItem, useResourceItems, useResourceRestore, useResourceCreate as useResourceStore, useResourceUpdate };
|
|
250
255
|
export type { UseItemsResponse };
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c } from 'react/compiler-runtime';
|
|
2
|
+
import { useState, use, createContext } from 'react';
|
|
2
3
|
import { useUrlGenerator, usePanneauResource, useResource } from '@panneau/core/contexts';
|
|
3
4
|
import { getJSON, getCSRFHeaders, postJSON } from '@folklore/fetch';
|
|
4
5
|
import { generatePath } from '@folklore/routes';
|
|
5
6
|
import queryString from 'query-string';
|
|
6
7
|
import { jsx } from 'react/jsx-runtime';
|
|
7
8
|
import { useQuery, keepPreviousData, useMutation, QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
8
|
-
import { c } from 'react/compiler-runtime';
|
|
9
9
|
import isArray from 'lodash-es/isArray';
|
|
10
10
|
import isObject from 'lodash-es/isObject';
|
|
11
11
|
import isString from 'lodash-es/isString';
|
|
@@ -664,7 +664,7 @@ class MediasApi extends Base {
|
|
|
664
664
|
update: 'medias/:media',
|
|
665
665
|
trash: 'medias/trash/:media',
|
|
666
666
|
restore: 'medias/restore/:media',
|
|
667
|
-
|
|
667
|
+
destroy: 'medias/:media',
|
|
668
668
|
replace: 'medias/replace/:media',
|
|
669
669
|
...(opts.routes || null)
|
|
670
670
|
}
|
|
@@ -688,16 +688,10 @@ class MediasApi extends Base {
|
|
|
688
688
|
return this.requestGet(this.route('index'), finalQuery);
|
|
689
689
|
}
|
|
690
690
|
getTrashed(query = {}, page = 1, count = 10) {
|
|
691
|
-
|
|
691
|
+
return this.get({
|
|
692
|
+
trashed: true,
|
|
692
693
|
...query
|
|
693
|
-
};
|
|
694
|
-
if (page !== null) {
|
|
695
|
-
finalQuery.page = page;
|
|
696
|
-
}
|
|
697
|
-
if (count !== null) {
|
|
698
|
-
finalQuery.count = count;
|
|
699
|
-
}
|
|
700
|
-
return this.requestGet(this.route('trashed'), finalQuery);
|
|
694
|
+
}, page, count);
|
|
701
695
|
}
|
|
702
696
|
getTags(query = {}, count = 10) {
|
|
703
697
|
const finalQuery = {
|
|
@@ -726,8 +720,8 @@ class MediasApi extends Base {
|
|
|
726
720
|
media: id
|
|
727
721
|
}));
|
|
728
722
|
}
|
|
729
|
-
|
|
730
|
-
return this.requestDelete(this.route('
|
|
723
|
+
destroy(id) {
|
|
724
|
+
return this.requestDelete(this.route('destroy', {
|
|
731
725
|
media: id
|
|
732
726
|
}));
|
|
733
727
|
}
|
|
@@ -826,23 +820,49 @@ const ApiContext = /*#__PURE__*/createContext(null);
|
|
|
826
820
|
function useApi() {
|
|
827
821
|
return use(ApiContext);
|
|
828
822
|
}
|
|
829
|
-
function ApiProvider({
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
823
|
+
function ApiProvider(t0) {
|
|
824
|
+
const $ = c(9);
|
|
825
|
+
const {
|
|
826
|
+
api: t1,
|
|
827
|
+
baseUrl: t2,
|
|
828
|
+
onUnauthorized: t3,
|
|
829
|
+
children
|
|
830
|
+
} = t0;
|
|
831
|
+
const initialApi = t1 === undefined ? null : t1;
|
|
832
|
+
const baseUrl = t2 === undefined ? undefined : t2;
|
|
833
|
+
const onUnauthorized = t3 === undefined ? null : t3;
|
|
835
834
|
const generateUrl = useUrlGenerator();
|
|
836
835
|
const previousApi = useApi();
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
836
|
+
let t4;
|
|
837
|
+
if ($[0] !== baseUrl || $[1] !== generateUrl || $[2] !== initialApi || $[3] !== onUnauthorized || $[4] !== previousApi) {
|
|
838
|
+
t4 = initialApi || previousApi || new Api({
|
|
839
|
+
baseUrl,
|
|
840
|
+
generateUrl,
|
|
841
|
+
onUnauthorized
|
|
842
|
+
});
|
|
843
|
+
$[0] = baseUrl;
|
|
844
|
+
$[1] = generateUrl;
|
|
845
|
+
$[2] = initialApi;
|
|
846
|
+
$[3] = onUnauthorized;
|
|
847
|
+
$[4] = previousApi;
|
|
848
|
+
$[5] = t4;
|
|
849
|
+
} else {
|
|
850
|
+
t4 = $[5];
|
|
851
|
+
}
|
|
852
|
+
const api = t4;
|
|
853
|
+
let t5;
|
|
854
|
+
if ($[6] !== api || $[7] !== children) {
|
|
855
|
+
t5 = /*#__PURE__*/jsx(ApiContext, {
|
|
856
|
+
value: api,
|
|
857
|
+
children: children
|
|
858
|
+
});
|
|
859
|
+
$[6] = api;
|
|
860
|
+
$[7] = children;
|
|
861
|
+
$[8] = t5;
|
|
862
|
+
} else {
|
|
863
|
+
t5 = $[8];
|
|
864
|
+
}
|
|
865
|
+
return t5;
|
|
846
866
|
}
|
|
847
867
|
|
|
848
868
|
function useResourceDestroy(t0, t1, t2) {
|
|
@@ -1226,19 +1246,24 @@ function useResourceRestore(resource, t0) {
|
|
|
1226
1246
|
return t2;
|
|
1227
1247
|
}
|
|
1228
1248
|
|
|
1229
|
-
/* eslint-disable react/jsx-props-no-spreading */
|
|
1230
1249
|
const QueryContext = /*#__PURE__*/createContext(null);
|
|
1231
1250
|
function useQueryContext() {
|
|
1232
1251
|
return use(QueryContext);
|
|
1233
1252
|
}
|
|
1234
|
-
function QueryProvider({
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1253
|
+
function QueryProvider(t0) {
|
|
1254
|
+
const $ = c(7);
|
|
1255
|
+
const {
|
|
1256
|
+
config: t1,
|
|
1257
|
+
initialKey: t2,
|
|
1258
|
+
initialData: t3,
|
|
1259
|
+
children
|
|
1260
|
+
} = t0;
|
|
1261
|
+
const initialConfig = t1 === undefined ? null : t1;
|
|
1262
|
+
const initialKey = t2 === undefined ? null : t2;
|
|
1263
|
+
const initialData = t3 === undefined ? null : t3;
|
|
1264
|
+
let client;
|
|
1265
|
+
if ($[0] !== initialConfig || $[1] !== initialData || $[2] !== initialKey) {
|
|
1266
|
+
client = new QueryClient({
|
|
1242
1267
|
defaultOptions: {
|
|
1243
1268
|
queries: {
|
|
1244
1269
|
staleTime: Infinity
|
|
@@ -1249,55 +1274,82 @@ function QueryProvider({
|
|
|
1249
1274
|
if (initialKey !== null && initialData !== null) {
|
|
1250
1275
|
client.setQueryData(initialKey, initialData);
|
|
1251
1276
|
}
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
client
|
|
1256
|
-
|
|
1257
|
-
|
|
1277
|
+
$[0] = initialConfig;
|
|
1278
|
+
$[1] = initialData;
|
|
1279
|
+
$[2] = initialKey;
|
|
1280
|
+
$[3] = client;
|
|
1281
|
+
} else {
|
|
1282
|
+
client = $[3];
|
|
1283
|
+
}
|
|
1284
|
+
let t4;
|
|
1285
|
+
if ($[4] !== children || $[5] !== client) {
|
|
1286
|
+
t4 = /*#__PURE__*/jsx(QueryClientProvider, {
|
|
1287
|
+
client: client,
|
|
1288
|
+
children: children
|
|
1289
|
+
});
|
|
1290
|
+
$[4] = children;
|
|
1291
|
+
$[5] = client;
|
|
1292
|
+
$[6] = t4;
|
|
1293
|
+
} else {
|
|
1294
|
+
t4 = $[6];
|
|
1295
|
+
}
|
|
1296
|
+
return t4;
|
|
1258
1297
|
}
|
|
1259
1298
|
|
|
1260
1299
|
function DataProvider(t0) {
|
|
1261
|
-
const $ = c(
|
|
1300
|
+
const $ = c(10);
|
|
1262
1301
|
const {
|
|
1263
1302
|
api: t1,
|
|
1264
1303
|
apiBaseUrl: t2,
|
|
1265
|
-
|
|
1304
|
+
baseUrl: t3,
|
|
1305
|
+
children: t4,
|
|
1306
|
+
queryConfig: t5,
|
|
1307
|
+
initialQueryKey: t6,
|
|
1308
|
+
initialQueryData: t7,
|
|
1309
|
+
onUnauthorized: t8
|
|
1266
1310
|
} = t0;
|
|
1267
1311
|
const api = t1 === undefined ? null : t1;
|
|
1268
1312
|
const apiBaseUrl = t2 === undefined ? undefined : t2;
|
|
1269
|
-
const
|
|
1270
|
-
const
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1313
|
+
const baseUrl = t3 === undefined ? undefined : t3;
|
|
1314
|
+
const children = t4 === undefined ? null : t4;
|
|
1315
|
+
const queryConfig = t5 === undefined ? null : t5;
|
|
1316
|
+
const initialQueryKey = t6 === undefined ? null : t6;
|
|
1317
|
+
const initialQueryData = t7 === undefined ? null : t7;
|
|
1318
|
+
const onUnauthorized = t8 === undefined ? null : t8;
|
|
1319
|
+
const t9 = baseUrl ?? apiBaseUrl;
|
|
1320
|
+
let t10;
|
|
1321
|
+
if ($[0] !== api || $[1] !== children || $[2] !== onUnauthorized || $[3] !== t9) {
|
|
1322
|
+
t10 = /*#__PURE__*/jsx(ApiProvider, {
|
|
1274
1323
|
api: api,
|
|
1275
|
-
baseUrl:
|
|
1324
|
+
baseUrl: t9,
|
|
1325
|
+
onUnauthorized: onUnauthorized,
|
|
1276
1326
|
children: children
|
|
1277
1327
|
});
|
|
1278
1328
|
$[0] = api;
|
|
1279
|
-
$[1] =
|
|
1280
|
-
$[2] =
|
|
1281
|
-
$[3] =
|
|
1329
|
+
$[1] = children;
|
|
1330
|
+
$[2] = onUnauthorized;
|
|
1331
|
+
$[3] = t9;
|
|
1332
|
+
$[4] = t10;
|
|
1282
1333
|
} else {
|
|
1283
|
-
|
|
1334
|
+
t10 = $[4];
|
|
1284
1335
|
}
|
|
1285
|
-
let
|
|
1286
|
-
if ($[
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1336
|
+
let t11;
|
|
1337
|
+
if ($[5] !== initialQueryData || $[6] !== initialQueryKey || $[7] !== queryConfig || $[8] !== t10) {
|
|
1338
|
+
t11 = /*#__PURE__*/jsx(QueryProvider, {
|
|
1339
|
+
config: queryConfig,
|
|
1340
|
+
initialKey: initialQueryKey,
|
|
1341
|
+
initialData: initialQueryData,
|
|
1342
|
+
children: t10
|
|
1290
1343
|
});
|
|
1291
|
-
$[
|
|
1292
|
-
$[
|
|
1293
|
-
$[
|
|
1344
|
+
$[5] = initialQueryData;
|
|
1345
|
+
$[6] = initialQueryKey;
|
|
1346
|
+
$[7] = queryConfig;
|
|
1347
|
+
$[8] = t10;
|
|
1348
|
+
$[9] = t11;
|
|
1294
1349
|
} else {
|
|
1295
|
-
|
|
1350
|
+
t11 = $[9];
|
|
1296
1351
|
}
|
|
1297
|
-
return
|
|
1298
|
-
}
|
|
1299
|
-
function _temp() {
|
|
1300
|
-
return new QueryClient();
|
|
1352
|
+
return t11;
|
|
1301
1353
|
}
|
|
1302
1354
|
|
|
1303
1355
|
export { Api, ApiProvider, Base as BaseApi, DataProvider, QueryProvider, useApi, useItem, useItems, useQueryContext, useResourceClone, useResourceDestroy, useResourceItem, useResourceItems, useResourceRestore, useResourceCreate as useResourceStore, useResourceUpdate };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@panneau/data",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.63",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"javascript"
|
|
@@ -71,5 +71,5 @@
|
|
|
71
71
|
"publishConfig": {
|
|
72
72
|
"access": "public"
|
|
73
73
|
},
|
|
74
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "5b20f29e0c3cf377ae50b946ac93e037936f961a"
|
|
75
75
|
}
|