@panneau/data 4.0.60 → 4.0.66
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 -3
- package/dist/index.js +115 -57
- package/package.json +3 -3
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';
|
|
@@ -100,6 +100,7 @@ type UseResourceDestroyResult = UseMutationResult & {
|
|
|
100
100
|
destroyAsync: (id?: string) => Promise<unknown>;
|
|
101
101
|
loading: boolean;
|
|
102
102
|
};
|
|
103
|
+
declare function useResourceDestroy(resource: Resource | string): UseResourceDestroyResult;
|
|
103
104
|
declare function useResourceDestroy(id: string | null): UseResourceDestroyResult;
|
|
104
105
|
declare function useResourceDestroy(id: string | null, options: UseMutationOptions): UseResourceDestroyResult;
|
|
105
106
|
declare function useResourceDestroy(resource: Resource | string, id: string | null): UseResourceDestroyResult;
|
|
@@ -231,7 +232,7 @@ declare function ApiProvider({ api: initialApi, baseUrl, onUnauthorized, childre
|
|
|
231
232
|
|
|
232
233
|
type QueryInitialData = Record<string, unknown> | Array<Record<string, unknown>>;
|
|
233
234
|
interface QueryProviderProps {
|
|
234
|
-
config?:
|
|
235
|
+
config?: QueryClientConfig | null;
|
|
235
236
|
initialKey?: string[] | null;
|
|
236
237
|
initialData?: QueryInitialData | null;
|
|
237
238
|
children: ReactNode;
|
|
@@ -242,9 +243,14 @@ declare function QueryProvider({ config: initialConfig, initialKey, initialData,
|
|
|
242
243
|
interface DataProviderProps {
|
|
243
244
|
api?: Api | null;
|
|
244
245
|
apiBaseUrl?: string;
|
|
246
|
+
baseUrl?: string;
|
|
247
|
+
queryConfig?: QueryClientConfig | null;
|
|
248
|
+
initialQueryKey?: string[] | null;
|
|
249
|
+
initialQueryData?: Record<string, unknown> | Array<Record<string, unknown>> | null;
|
|
250
|
+
onUnauthorized?: (() => void) | null;
|
|
245
251
|
children?: ReactNode;
|
|
246
252
|
}
|
|
247
|
-
declare function DataProvider({ api, apiBaseUrl, children }: DataProviderProps): react.JSX.Element;
|
|
253
|
+
declare function DataProvider({ api, apiBaseUrl, baseUrl, children, queryConfig, initialQueryKey, initialQueryData, onUnauthorized, }: DataProviderProps): react.JSX.Element;
|
|
248
254
|
|
|
249
255
|
export { Api, ApiProvider, Base as BaseApi, DataProvider, QueryProvider, useApi, useItem, useItems, useQueryContext, useResourceClone, useResourceDestroy, useResourceItem, useResourceItems, useResourceRestore, useResourceCreate as useResourceStore, useResourceUpdate };
|
|
250
256
|
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';
|
|
@@ -820,23 +820,49 @@ const ApiContext = /*#__PURE__*/createContext(null);
|
|
|
820
820
|
function useApi() {
|
|
821
821
|
return use(ApiContext);
|
|
822
822
|
}
|
|
823
|
-
function ApiProvider({
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
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;
|
|
829
834
|
const generateUrl = useUrlGenerator();
|
|
830
835
|
const previousApi = useApi();
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
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;
|
|
840
866
|
}
|
|
841
867
|
|
|
842
868
|
function useResourceDestroy(t0, t1, t2) {
|
|
@@ -1220,19 +1246,24 @@ function useResourceRestore(resource, t0) {
|
|
|
1220
1246
|
return t2;
|
|
1221
1247
|
}
|
|
1222
1248
|
|
|
1223
|
-
/* eslint-disable react/jsx-props-no-spreading */
|
|
1224
1249
|
const QueryContext = /*#__PURE__*/createContext(null);
|
|
1225
1250
|
function useQueryContext() {
|
|
1226
1251
|
return use(QueryContext);
|
|
1227
1252
|
}
|
|
1228
|
-
function QueryProvider({
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
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({
|
|
1236
1267
|
defaultOptions: {
|
|
1237
1268
|
queries: {
|
|
1238
1269
|
staleTime: Infinity
|
|
@@ -1243,55 +1274,82 @@ function QueryProvider({
|
|
|
1243
1274
|
if (initialKey !== null && initialData !== null) {
|
|
1244
1275
|
client.setQueryData(initialKey, initialData);
|
|
1245
1276
|
}
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
client
|
|
1250
|
-
|
|
1251
|
-
|
|
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;
|
|
1252
1297
|
}
|
|
1253
1298
|
|
|
1254
1299
|
function DataProvider(t0) {
|
|
1255
|
-
const $ = c(
|
|
1300
|
+
const $ = c(10);
|
|
1256
1301
|
const {
|
|
1257
1302
|
api: t1,
|
|
1258
1303
|
apiBaseUrl: t2,
|
|
1259
|
-
|
|
1304
|
+
baseUrl: t3,
|
|
1305
|
+
children: t4,
|
|
1306
|
+
queryConfig: t5,
|
|
1307
|
+
initialQueryKey: t6,
|
|
1308
|
+
initialQueryData: t7,
|
|
1309
|
+
onUnauthorized: t8
|
|
1260
1310
|
} = t0;
|
|
1261
1311
|
const api = t1 === undefined ? null : t1;
|
|
1262
1312
|
const apiBaseUrl = t2 === undefined ? undefined : t2;
|
|
1263
|
-
const
|
|
1264
|
-
const
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
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, {
|
|
1268
1323
|
api: api,
|
|
1269
|
-
baseUrl:
|
|
1324
|
+
baseUrl: t9,
|
|
1325
|
+
onUnauthorized: onUnauthorized,
|
|
1270
1326
|
children: children
|
|
1271
1327
|
});
|
|
1272
1328
|
$[0] = api;
|
|
1273
|
-
$[1] =
|
|
1274
|
-
$[2] =
|
|
1275
|
-
$[3] =
|
|
1329
|
+
$[1] = children;
|
|
1330
|
+
$[2] = onUnauthorized;
|
|
1331
|
+
$[3] = t9;
|
|
1332
|
+
$[4] = t10;
|
|
1276
1333
|
} else {
|
|
1277
|
-
|
|
1334
|
+
t10 = $[4];
|
|
1278
1335
|
}
|
|
1279
|
-
let
|
|
1280
|
-
if ($[
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
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
|
|
1284
1343
|
});
|
|
1285
|
-
$[
|
|
1286
|
-
$[
|
|
1287
|
-
$[
|
|
1344
|
+
$[5] = initialQueryData;
|
|
1345
|
+
$[6] = initialQueryKey;
|
|
1346
|
+
$[7] = queryConfig;
|
|
1347
|
+
$[8] = t10;
|
|
1348
|
+
$[9] = t11;
|
|
1288
1349
|
} else {
|
|
1289
|
-
|
|
1350
|
+
t11 = $[9];
|
|
1290
1351
|
}
|
|
1291
|
-
return
|
|
1292
|
-
}
|
|
1293
|
-
function _temp() {
|
|
1294
|
-
return new QueryClient();
|
|
1352
|
+
return t11;
|
|
1295
1353
|
}
|
|
1296
1354
|
|
|
1297
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.66",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"javascript"
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"@babel/runtime": "^7.28.6",
|
|
56
56
|
"@folklore/fetch": "^0.1.21",
|
|
57
57
|
"@folklore/routes": "^0.2.44",
|
|
58
|
-
"@panneau/core": "^4.0.
|
|
58
|
+
"@panneau/core": "^4.0.66",
|
|
59
59
|
"@tanstack/react-query": "^5.100.9",
|
|
60
60
|
"lodash": "^4.17.21",
|
|
61
61
|
"query-string": "^9.0.0"
|
|
@@ -71,5 +71,5 @@
|
|
|
71
71
|
"publishConfig": {
|
|
72
72
|
"access": "public"
|
|
73
73
|
},
|
|
74
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "9f89301a517c628efb03ed6f27632c66a03dd146"
|
|
75
75
|
}
|