@panneau/data 4.0.60 → 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 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';
@@ -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?: Record<string, unknown> | null;
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 { useState, useMemo, use, createContext } from 'react';
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
- api: initialApi = null,
825
- baseUrl = undefined,
826
- onUnauthorized = null,
827
- children
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
- const api = useMemo(() => initialApi || previousApi || new Api({
832
- baseUrl,
833
- generateUrl,
834
- onUnauthorized
835
- }), [previousApi, initialApi, baseUrl]);
836
- return /*#__PURE__*/jsx(ApiContext, {
837
- value: api,
838
- children: children
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
- config: initialConfig = null,
1230
- initialKey = null,
1231
- initialData = null,
1232
- children
1233
- }) {
1234
- const queryClient = useMemo(() => {
1235
- const client = new QueryClient({
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
- return client;
1247
- }, [initialConfig]);
1248
- return /*#__PURE__*/jsx(QueryClientProvider, {
1249
- client: queryClient,
1250
- children: children
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(7);
1300
+ const $ = c(10);
1256
1301
  const {
1257
1302
  api: t1,
1258
1303
  apiBaseUrl: t2,
1259
- children: t3
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 children = t3 === undefined ? null : t3;
1264
- const [client] = useState(_temp);
1265
- let t4;
1266
- if ($[0] !== api || $[1] !== apiBaseUrl || $[2] !== children) {
1267
- t4 = /*#__PURE__*/jsx(ApiProvider, {
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: apiBaseUrl,
1324
+ baseUrl: t9,
1325
+ onUnauthorized: onUnauthorized,
1270
1326
  children: children
1271
1327
  });
1272
1328
  $[0] = api;
1273
- $[1] = apiBaseUrl;
1274
- $[2] = children;
1275
- $[3] = t4;
1329
+ $[1] = children;
1330
+ $[2] = onUnauthorized;
1331
+ $[3] = t9;
1332
+ $[4] = t10;
1276
1333
  } else {
1277
- t4 = $[3];
1334
+ t10 = $[4];
1278
1335
  }
1279
- let t5;
1280
- if ($[4] !== client || $[5] !== t4) {
1281
- t5 = /*#__PURE__*/jsx(QueryClientProvider, {
1282
- client: client,
1283
- children: t4
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
- $[4] = client;
1286
- $[5] = t4;
1287
- $[6] = t5;
1344
+ $[5] = initialQueryData;
1345
+ $[6] = initialQueryKey;
1346
+ $[7] = queryConfig;
1347
+ $[8] = t10;
1348
+ $[9] = t11;
1288
1349
  } else {
1289
- t5 = $[6];
1350
+ t11 = $[9];
1290
1351
  }
1291
- return t5;
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.60",
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": "ec24c7cd579c8ff772ae0e751d67091f3bbb5b55"
74
+ "gitHead": "5b20f29e0c3cf377ae50b946ac93e037936f961a"
75
75
  }