@contentful/field-editor-shared 2.17.0 → 2.17.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/cjs/index.js CHANGED
@@ -75,6 +75,9 @@ _export(exports, {
75
75
  PredefinedValuesError: function() {
76
76
  return _PredefinedValuesError.PredefinedValuesError;
77
77
  },
78
+ SharedQueryClientProvider: function() {
79
+ return _queryClient.SharedQueryClientProvider;
80
+ },
78
81
  SpaceAPI: function() {
79
82
  return _appsdk.SpaceAPI;
80
83
  },
@@ -92,6 +95,12 @@ _export(exports, {
92
95
  },
93
96
  toLocaleString: function() {
94
97
  return _shortenStorageUnit.toLocaleString;
98
+ },
99
+ useQuery: function() {
100
+ return _queryClient.useQuery;
101
+ },
102
+ useQueryClient: function() {
103
+ return _queryClient.useQueryClient;
95
104
  }
96
105
  });
97
106
  const _ModalDialogLauncher = /*#__PURE__*/ _interop_require_wildcard(require("./ModalDialogLauncher"));
@@ -113,6 +122,7 @@ _export_star(require("./ReleaseEntityStatusBadge"), exports);
113
122
  _export_star(require("./utils/determineReleaseAction"), exports);
114
123
  _export_star(require("./utils/getEntityReleaseStatus"), exports);
115
124
  _export_star(require("./utils/getReleaseStatusBadgeConfig"), exports);
125
+ const _queryClient = require("./queryClient");
116
126
  function _export_star(from, to) {
117
127
  Object.keys(from).forEach(function(k) {
118
128
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ SharedQueryClientProvider: function() {
13
+ return SharedQueryClientProvider;
14
+ },
15
+ useQuery: function() {
16
+ return useQuery;
17
+ },
18
+ useQueryClient: function() {
19
+ return useQueryClient;
20
+ }
21
+ });
22
+ const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
23
+ function _getRequireWildcardCache(nodeInterop) {
24
+ if (typeof WeakMap !== "function") return null;
25
+ var cacheBabelInterop = new WeakMap();
26
+ var cacheNodeInterop = new WeakMap();
27
+ return (_getRequireWildcardCache = function(nodeInterop) {
28
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
29
+ })(nodeInterop);
30
+ }
31
+ function _interop_require_wildcard(obj, nodeInterop) {
32
+ if (!nodeInterop && obj && obj.__esModule) {
33
+ return obj;
34
+ }
35
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
36
+ return {
37
+ default: obj
38
+ };
39
+ }
40
+ var cache = _getRequireWildcardCache(nodeInterop);
41
+ if (cache && cache.has(obj)) {
42
+ return cache.get(obj);
43
+ }
44
+ var newObj = {
45
+ __proto__: null
46
+ };
47
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
48
+ for(var key in obj){
49
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
50
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
51
+ if (desc && (desc.get || desc.set)) {
52
+ Object.defineProperty(newObj, key, desc);
53
+ } else {
54
+ newObj[key] = obj[key];
55
+ }
56
+ }
57
+ }
58
+ newObj.default = obj;
59
+ if (cache) {
60
+ cache.set(obj, newObj);
61
+ }
62
+ return newObj;
63
+ }
64
+ let RQQueryClient;
65
+ let useRQ;
66
+ let useHostQueryClient = ()=>undefined;
67
+ try {
68
+ const rq = require('@tanstack/react-query');
69
+ RQQueryClient = rq.QueryClient;
70
+ useRQ = rq.useQuery;
71
+ useHostQueryClient = rq.useQueryClient;
72
+ } catch {}
73
+ const clientContext = /*#__PURE__*/ _react.createContext(undefined);
74
+ function useMaybeHostQueryClient() {
75
+ try {
76
+ return useHostQueryClient();
77
+ } catch {
78
+ return undefined;
79
+ }
80
+ }
81
+ function useQueryClient() {
82
+ const client = _react.useContext(clientContext);
83
+ const hostClient = useMaybeHostQueryClient();
84
+ return _react.useMemo(()=>{
85
+ if (client) {
86
+ return client;
87
+ }
88
+ if (hostClient) return hostClient;
89
+ if (!RQQueryClient) {
90
+ throw new Error('@tanstack/react-query is required to use QueryClient. Please install it as a dependency: npm install @tanstack/react-query');
91
+ }
92
+ return new RQQueryClient({
93
+ defaultOptions: {
94
+ queries: {
95
+ useErrorBoundary: false,
96
+ refetchOnWindowFocus: false,
97
+ refetchOnReconnect: true,
98
+ refetchOnMount: false,
99
+ staleTime: Infinity,
100
+ retry: false
101
+ }
102
+ }
103
+ });
104
+ }, [
105
+ client,
106
+ hostClient
107
+ ]);
108
+ }
109
+ function useQuery(queryKey, queryFn, options) {
110
+ if (!useRQ) {
111
+ throw new Error('@tanstack/react-query is required to use useQuery. Please install it as a dependency: npm install @tanstack/react-query');
112
+ }
113
+ return useRQ(queryKey, queryFn, {
114
+ ...options,
115
+ context: clientContext
116
+ });
117
+ }
118
+ function SharedQueryClientProvider({ children }) {
119
+ const client = useQueryClient();
120
+ return /*#__PURE__*/ _react.createElement(clientContext.Provider, {
121
+ value: client
122
+ }, children);
123
+ }
package/dist/esm/index.js CHANGED
@@ -17,3 +17,4 @@ export * from './ReleaseEntityStatusBadge';
17
17
  export * from './utils/determineReleaseAction';
18
18
  export * from './utils/getEntityReleaseStatus';
19
19
  export * from './utils/getReleaseStatusBadgeConfig';
20
+ export { SharedQueryClientProvider, useQueryClient, useQuery } from './queryClient';
@@ -0,0 +1,61 @@
1
+ import * as React from 'react';
2
+ let RQQueryClient;
3
+ let useRQ;
4
+ let useHostQueryClient = ()=>undefined;
5
+ try {
6
+ const rq = require('@tanstack/react-query');
7
+ RQQueryClient = rq.QueryClient;
8
+ useRQ = rq.useQuery;
9
+ useHostQueryClient = rq.useQueryClient;
10
+ } catch {}
11
+ const clientContext = /*#__PURE__*/ React.createContext(undefined);
12
+ function useMaybeHostQueryClient() {
13
+ try {
14
+ return useHostQueryClient();
15
+ } catch {
16
+ return undefined;
17
+ }
18
+ }
19
+ export function useQueryClient() {
20
+ const client = React.useContext(clientContext);
21
+ const hostClient = useMaybeHostQueryClient();
22
+ return React.useMemo(()=>{
23
+ if (client) {
24
+ return client;
25
+ }
26
+ if (hostClient) return hostClient;
27
+ if (!RQQueryClient) {
28
+ throw new Error('@tanstack/react-query is required to use QueryClient. Please install it as a dependency: npm install @tanstack/react-query');
29
+ }
30
+ return new RQQueryClient({
31
+ defaultOptions: {
32
+ queries: {
33
+ useErrorBoundary: false,
34
+ refetchOnWindowFocus: false,
35
+ refetchOnReconnect: true,
36
+ refetchOnMount: false,
37
+ staleTime: Infinity,
38
+ retry: false
39
+ }
40
+ }
41
+ });
42
+ }, [
43
+ client,
44
+ hostClient
45
+ ]);
46
+ }
47
+ export function useQuery(queryKey, queryFn, options) {
48
+ if (!useRQ) {
49
+ throw new Error('@tanstack/react-query is required to use useQuery. Please install it as a dependency: npm install @tanstack/react-query');
50
+ }
51
+ return useRQ(queryKey, queryFn, {
52
+ ...options,
53
+ context: clientContext
54
+ });
55
+ }
56
+ export function SharedQueryClientProvider({ children }) {
57
+ const client = useQueryClient();
58
+ return /*#__PURE__*/ React.createElement(clientContext.Provider, {
59
+ value: client
60
+ }, children);
61
+ }
@@ -19,3 +19,4 @@ export * from './ReleaseEntityStatusBadge';
19
19
  export * from './utils/determineReleaseAction';
20
20
  export * from './utils/getEntityReleaseStatus';
21
21
  export * from './utils/getReleaseStatusBadgeConfig';
22
+ export { SharedQueryClientProvider, useQueryClient, useQuery } from './queryClient';
@@ -0,0 +1,9 @@
1
+ import * as React from 'react';
2
+ import type { QueryClient, UseQueryOptions, UseQueryResult, QueryKey, QueryFunction } from '@tanstack/react-query';
3
+ export declare function useQueryClient(): QueryClient;
4
+ export declare function useQuery<TQueryFnData = unknown, TError = unknown, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(queryKey: TQueryKey, queryFn: QueryFunction<TQueryFnData, TQueryKey>, options?: Omit<UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'queryKey' | 'queryFn'>): UseQueryResult<TData, TError>;
5
+ /**
6
+ * Provides access to a query client either by sharing an existing client or
7
+ * creating a new one.
8
+ */
9
+ export declare function SharedQueryClientProvider({ children }: React.PropsWithChildren<{}>): React.JSX.Element;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/field-editor-shared",
3
- "version": "2.17.0",
3
+ "version": "2.17.1",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -39,6 +39,7 @@
39
39
  "@contentful/app-sdk": "^4.42.0",
40
40
  "@contentful/field-editor-test-utils": "^1.7.0",
41
41
  "@lingui/core": "5.3.0",
42
+ "@tanstack/react-query": "^4.3.9",
42
43
  "@testing-library/react": "16.3.0"
43
44
  },
44
45
  "dependencies": {
@@ -54,11 +55,17 @@
54
55
  "peerDependencies": {
55
56
  "@contentful/app-sdk": "^4.29.0",
56
57
  "@lingui/core": "^5.3.0",
58
+ "@tanstack/react-query": "^4.3.9",
57
59
  "react": ">=16.8.0",
58
60
  "react-dom": ">=16.8.0"
59
61
  },
62
+ "peerDependenciesMeta": {
63
+ "@tanstack/react-query": {
64
+ "optional": true
65
+ }
66
+ },
60
67
  "publishConfig": {
61
68
  "registry": "https://npm.pkg.github.com/"
62
69
  },
63
- "gitHead": "c85b1e8cd6772eb796ed2b22ebb778c717f4a7f4"
70
+ "gitHead": "c8fbf95fbb880df05fd011b8892523c135c2a5fd"
64
71
  }