@contentful/field-editor-shared 2.17.0 → 2.17.1-alpha.0
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 +10 -0
- package/dist/cjs/queryClient.js +117 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/queryClient.js +55 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/queryClient.d.ts +9 -0
- package/package.json +9 -2
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,117 @@
|
|
|
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 QueryClient;
|
|
65
|
+
let useRQ;
|
|
66
|
+
let useHostQueryClient = ()=>undefined;
|
|
67
|
+
try {
|
|
68
|
+
const rq = require('@tanstack/react-query');
|
|
69
|
+
QueryClient = 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
|
+
return new QueryClient({
|
|
90
|
+
defaultOptions: {
|
|
91
|
+
queries: {
|
|
92
|
+
useErrorBoundary: false,
|
|
93
|
+
refetchOnWindowFocus: false,
|
|
94
|
+
refetchOnReconnect: true,
|
|
95
|
+
refetchOnMount: false,
|
|
96
|
+
staleTime: Infinity,
|
|
97
|
+
retry: false
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}, [
|
|
102
|
+
client,
|
|
103
|
+
hostClient
|
|
104
|
+
]);
|
|
105
|
+
}
|
|
106
|
+
function useQuery(queryKey, queryFn, options) {
|
|
107
|
+
return useRQ(queryKey, queryFn, {
|
|
108
|
+
...options,
|
|
109
|
+
context: clientContext
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
function SharedQueryClientProvider({ children }) {
|
|
113
|
+
const client = useQueryClient();
|
|
114
|
+
return /*#__PURE__*/ _react.createElement(clientContext.Provider, {
|
|
115
|
+
value: client
|
|
116
|
+
}, children);
|
|
117
|
+
}
|
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,55 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
let QueryClient;
|
|
3
|
+
let useRQ;
|
|
4
|
+
let useHostQueryClient = ()=>undefined;
|
|
5
|
+
try {
|
|
6
|
+
const rq = require('@tanstack/react-query');
|
|
7
|
+
QueryClient = 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
|
+
return new QueryClient({
|
|
28
|
+
defaultOptions: {
|
|
29
|
+
queries: {
|
|
30
|
+
useErrorBoundary: false,
|
|
31
|
+
refetchOnWindowFocus: false,
|
|
32
|
+
refetchOnReconnect: true,
|
|
33
|
+
refetchOnMount: false,
|
|
34
|
+
staleTime: Infinity,
|
|
35
|
+
retry: false
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}, [
|
|
40
|
+
client,
|
|
41
|
+
hostClient
|
|
42
|
+
]);
|
|
43
|
+
}
|
|
44
|
+
export function useQuery(queryKey, queryFn, options) {
|
|
45
|
+
return useRQ(queryKey, queryFn, {
|
|
46
|
+
...options,
|
|
47
|
+
context: clientContext
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
export function SharedQueryClientProvider({ children }) {
|
|
51
|
+
const client = useQueryClient();
|
|
52
|
+
return /*#__PURE__*/ React.createElement(clientContext.Provider, {
|
|
53
|
+
value: client
|
|
54
|
+
}, children);
|
|
55
|
+
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -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 as QC, UseQueryOptions, UseQueryResult, QueryKey, QueryFunction } from '@tanstack/react-query';
|
|
3
|
+
export declare function useQueryClient(): QC;
|
|
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-alpha.0",
|
|
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": "
|
|
70
|
+
"gitHead": "447875c5a2ef25eb4552c29b990d90ec40bc6985"
|
|
64
71
|
}
|