@contentful/field-editor-shared 2.17.1 → 2.17.2-canary.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/hooks/useContentTypes.js +95 -0
- package/dist/cjs/index.js +1 -10
- package/dist/cjs/queryClient.js +24 -30
- package/dist/cjs/queryKeys.js +94 -0
- package/dist/cjs/react-query.js +36 -0
- package/dist/esm/hooks/useContentTypes.js +74 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/queryClient.js +22 -28
- package/dist/esm/queryKeys.js +64 -0
- package/dist/esm/react-query.js +2 -0
- package/dist/types/hooks/useContentTypes.d.ts +24 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/queryClient.d.ts +7 -2
- package/dist/types/queryKeys.d.ts +57 -0
- package/dist/types/react-query.d.ts +2 -0
- package/package.json +9 -3
|
@@ -0,0 +1,95 @@
|
|
|
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
|
+
fetchContentType: function() {
|
|
13
|
+
return fetchContentType;
|
|
14
|
+
},
|
|
15
|
+
useContentType: function() {
|
|
16
|
+
return useContentType;
|
|
17
|
+
},
|
|
18
|
+
useContentTypes: function() {
|
|
19
|
+
return useContentTypes;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const _react = require("react");
|
|
23
|
+
const _queryClient = require("../queryClient");
|
|
24
|
+
const _queryKeys = require("../queryKeys");
|
|
25
|
+
function useContentType(sdk, contentTypeId, options) {
|
|
26
|
+
const spaceId = sdk.ids.space;
|
|
27
|
+
const environmentId = sdk.ids.environmentAlias ?? sdk.ids.environment;
|
|
28
|
+
return (0, _queryClient.useQuery)((0, _queryKeys.createGetContentTypeKey)(spaceId, environmentId, contentTypeId), ()=>sdk.cma.contentType.get({
|
|
29
|
+
contentTypeId
|
|
30
|
+
}), {
|
|
31
|
+
staleTime: Infinity,
|
|
32
|
+
...options
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
async function fetchContentType(sdk, contentTypeId) {
|
|
36
|
+
return sdk.cma.contentType.get({
|
|
37
|
+
contentTypeId
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
function useContentTypes(source) {
|
|
41
|
+
const cma = 'cma' in source ? source.cma : source;
|
|
42
|
+
const navigator = 'navigator' in source ? source.navigator : undefined;
|
|
43
|
+
const queryClient = (0, _queryClient.useQueryClient)();
|
|
44
|
+
const spaceId = 'ids' in source ? source.ids.space : '';
|
|
45
|
+
const environmentId = 'ids' in source ? source.ids.environmentAlias ?? source.ids.environment : '';
|
|
46
|
+
const queryKey = (0, _react.useMemo)(()=>(0, _queryKeys.createGetManyContentTypesKey)(spaceId, environmentId, {
|
|
47
|
+
limit: 1000
|
|
48
|
+
}), [
|
|
49
|
+
spaceId,
|
|
50
|
+
environmentId
|
|
51
|
+
]);
|
|
52
|
+
const { data: contentTypes = [] } = (0, _queryClient.useQuery)(queryKey, async ()=>{
|
|
53
|
+
const allContentTypes = [];
|
|
54
|
+
const limit = 1000;
|
|
55
|
+
let skip = 0;
|
|
56
|
+
let total = 0;
|
|
57
|
+
do {
|
|
58
|
+
const response = await cma.contentType.getMany({
|
|
59
|
+
query: {
|
|
60
|
+
limit,
|
|
61
|
+
skip
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
allContentTypes.push(...response.items);
|
|
65
|
+
total = response.total;
|
|
66
|
+
skip += response.items.length;
|
|
67
|
+
}while (skip < total)
|
|
68
|
+
return allContentTypes;
|
|
69
|
+
}, {
|
|
70
|
+
staleTime: Infinity,
|
|
71
|
+
refetchOnMount: false
|
|
72
|
+
});
|
|
73
|
+
(0, _react.useEffect)(()=>{
|
|
74
|
+
if (!navigator?.onSlideInNavigation) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const unsubscribe = navigator.onSlideInNavigation(({ oldSlideLevel, newSlideLevel })=>{
|
|
78
|
+
if (oldSlideLevel > newSlideLevel) {
|
|
79
|
+
void queryClient.invalidateQueries(queryKey);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
return unsubscribe;
|
|
83
|
+
}, [
|
|
84
|
+
navigator,
|
|
85
|
+
queryClient,
|
|
86
|
+
queryKey
|
|
87
|
+
]);
|
|
88
|
+
const invalidate = ()=>{
|
|
89
|
+
return queryClient.invalidateQueries(queryKey);
|
|
90
|
+
};
|
|
91
|
+
return {
|
|
92
|
+
contentTypes,
|
|
93
|
+
invalidate
|
|
94
|
+
};
|
|
95
|
+
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -75,9 +75,6 @@ _export(exports, {
|
|
|
75
75
|
PredefinedValuesError: function() {
|
|
76
76
|
return _PredefinedValuesError.PredefinedValuesError;
|
|
77
77
|
},
|
|
78
|
-
SharedQueryClientProvider: function() {
|
|
79
|
-
return _queryClient.SharedQueryClientProvider;
|
|
80
|
-
},
|
|
81
78
|
SpaceAPI: function() {
|
|
82
79
|
return _appsdk.SpaceAPI;
|
|
83
80
|
},
|
|
@@ -95,12 +92,6 @@ _export(exports, {
|
|
|
95
92
|
},
|
|
96
93
|
toLocaleString: function() {
|
|
97
94
|
return _shortenStorageUnit.toLocaleString;
|
|
98
|
-
},
|
|
99
|
-
useQuery: function() {
|
|
100
|
-
return _queryClient.useQuery;
|
|
101
|
-
},
|
|
102
|
-
useQueryClient: function() {
|
|
103
|
-
return _queryClient.useQueryClient;
|
|
104
95
|
}
|
|
105
96
|
});
|
|
106
97
|
const _ModalDialogLauncher = /*#__PURE__*/ _interop_require_wildcard(require("./ModalDialogLauncher"));
|
|
@@ -122,7 +113,7 @@ _export_star(require("./ReleaseEntityStatusBadge"), exports);
|
|
|
122
113
|
_export_star(require("./utils/determineReleaseAction"), exports);
|
|
123
114
|
_export_star(require("./utils/getEntityReleaseStatus"), exports);
|
|
124
115
|
_export_star(require("./utils/getReleaseStatusBadgeConfig"), exports);
|
|
125
|
-
|
|
116
|
+
_export_star(require("./queryKeys"), exports);
|
|
126
117
|
function _export_star(from, to) {
|
|
127
118
|
Object.keys(from).forEach(function(k) {
|
|
128
119
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
package/dist/cjs/queryClient.js
CHANGED
|
@@ -20,6 +20,7 @@ _export(exports, {
|
|
|
20
20
|
}
|
|
21
21
|
});
|
|
22
22
|
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
23
|
+
const _reactquery = require("@tanstack/react-query");
|
|
23
24
|
function _getRequireWildcardCache(nodeInterop) {
|
|
24
25
|
if (typeof WeakMap !== "function") return null;
|
|
25
26
|
var cacheBabelInterop = new WeakMap();
|
|
@@ -61,19 +62,11 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
61
62
|
}
|
|
62
63
|
return newObj;
|
|
63
64
|
}
|
|
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
65
|
const clientContext = /*#__PURE__*/ _react.createContext(undefined);
|
|
66
|
+
let sharedQueryClientInstance;
|
|
74
67
|
function useMaybeHostQueryClient() {
|
|
75
68
|
try {
|
|
76
|
-
return
|
|
69
|
+
return (0, _reactquery.useQueryClient)();
|
|
77
70
|
} catch {
|
|
78
71
|
return undefined;
|
|
79
72
|
}
|
|
@@ -86,37 +79,38 @@ function useQueryClient() {
|
|
|
86
79
|
return client;
|
|
87
80
|
}
|
|
88
81
|
if (hostClient) return hostClient;
|
|
89
|
-
if (!
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
retry: false
|
|
82
|
+
if (!sharedQueryClientInstance) {
|
|
83
|
+
sharedQueryClientInstance = new _reactquery.QueryClient({
|
|
84
|
+
defaultOptions: {
|
|
85
|
+
queries: {
|
|
86
|
+
useErrorBoundary: false,
|
|
87
|
+
refetchOnWindowFocus: false,
|
|
88
|
+
refetchOnReconnect: true,
|
|
89
|
+
refetchOnMount: false,
|
|
90
|
+
staleTime: Infinity,
|
|
91
|
+
retry: false
|
|
92
|
+
}
|
|
101
93
|
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
return sharedQueryClientInstance;
|
|
104
97
|
}, [
|
|
105
98
|
client,
|
|
106
99
|
hostClient
|
|
107
100
|
]);
|
|
108
101
|
}
|
|
109
102
|
function useQuery(queryKey, queryFn, options) {
|
|
110
|
-
|
|
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, {
|
|
103
|
+
return (0, _reactquery.useQuery)(queryKey, queryFn, {
|
|
114
104
|
...options,
|
|
115
105
|
context: clientContext
|
|
116
106
|
});
|
|
117
107
|
}
|
|
118
|
-
function SharedQueryClientProvider({ children }) {
|
|
119
|
-
const
|
|
108
|
+
function SharedQueryClientProvider({ children, client: providedClient }) {
|
|
109
|
+
const internalClient = useQueryClient();
|
|
110
|
+
const client = _react.useMemo(()=>providedClient ?? internalClient, [
|
|
111
|
+
providedClient,
|
|
112
|
+
internalClient
|
|
113
|
+
]);
|
|
120
114
|
return /*#__PURE__*/ _react.createElement(clientContext.Provider, {
|
|
121
115
|
value: client
|
|
122
116
|
}, children);
|
|
@@ -0,0 +1,94 @@
|
|
|
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
|
+
createGetAssetKey: function() {
|
|
13
|
+
return createGetAssetKey;
|
|
14
|
+
},
|
|
15
|
+
createGetContentTypeKey: function() {
|
|
16
|
+
return createGetContentTypeKey;
|
|
17
|
+
},
|
|
18
|
+
createGetEntryKey: function() {
|
|
19
|
+
return createGetEntryKey;
|
|
20
|
+
},
|
|
21
|
+
createGetManyContentTypesKey: function() {
|
|
22
|
+
return createGetManyContentTypesKey;
|
|
23
|
+
},
|
|
24
|
+
createGetManyLocalesKey: function() {
|
|
25
|
+
return createGetManyLocalesKey;
|
|
26
|
+
},
|
|
27
|
+
createGetSpaceKey: function() {
|
|
28
|
+
return createGetSpaceKey;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
const createGetEntryKey = (spaceId, environmentId, entryId)=>{
|
|
32
|
+
return [
|
|
33
|
+
'spaces',
|
|
34
|
+
spaceId,
|
|
35
|
+
'environments',
|
|
36
|
+
environmentId,
|
|
37
|
+
'entries',
|
|
38
|
+
'get',
|
|
39
|
+
entryId
|
|
40
|
+
];
|
|
41
|
+
};
|
|
42
|
+
const createGetAssetKey = (spaceId, environmentId, assetId)=>{
|
|
43
|
+
return [
|
|
44
|
+
'spaces',
|
|
45
|
+
spaceId,
|
|
46
|
+
'environments',
|
|
47
|
+
environmentId,
|
|
48
|
+
'assets',
|
|
49
|
+
'get',
|
|
50
|
+
assetId
|
|
51
|
+
];
|
|
52
|
+
};
|
|
53
|
+
const createGetSpaceKey = (spaceId)=>{
|
|
54
|
+
return [
|
|
55
|
+
'spaces',
|
|
56
|
+
'get',
|
|
57
|
+
spaceId
|
|
58
|
+
];
|
|
59
|
+
};
|
|
60
|
+
const createGetManyLocalesKey = (spaceId, environmentId, params = {})=>{
|
|
61
|
+
return [
|
|
62
|
+
'spaces',
|
|
63
|
+
spaceId,
|
|
64
|
+
'environments',
|
|
65
|
+
environmentId,
|
|
66
|
+
'locales',
|
|
67
|
+
params
|
|
68
|
+
];
|
|
69
|
+
};
|
|
70
|
+
const createGetContentTypeKey = (spaceId, environmentId, contentTypeId)=>{
|
|
71
|
+
return [
|
|
72
|
+
'spaces',
|
|
73
|
+
spaceId,
|
|
74
|
+
'environments',
|
|
75
|
+
environmentId,
|
|
76
|
+
'content_types',
|
|
77
|
+
'get',
|
|
78
|
+
contentTypeId
|
|
79
|
+
];
|
|
80
|
+
};
|
|
81
|
+
const createGetManyContentTypesKey = (spaceId, environmentId, params = {})=>{
|
|
82
|
+
const prefix = [
|
|
83
|
+
'spaces',
|
|
84
|
+
spaceId,
|
|
85
|
+
'environments',
|
|
86
|
+
environmentId,
|
|
87
|
+
'content_types',
|
|
88
|
+
'getMany'
|
|
89
|
+
];
|
|
90
|
+
return Object.keys(params).length === 0 ? prefix : [
|
|
91
|
+
...prefix,
|
|
92
|
+
params
|
|
93
|
+
];
|
|
94
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
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 _queryClient.SharedQueryClientProvider;
|
|
14
|
+
},
|
|
15
|
+
useQuery: function() {
|
|
16
|
+
return _queryClient.useQuery;
|
|
17
|
+
},
|
|
18
|
+
useQueryClient: function() {
|
|
19
|
+
return _queryClient.useQueryClient;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const _queryClient = require("./queryClient");
|
|
23
|
+
_export_star(require("./hooks/useContentTypes"), exports);
|
|
24
|
+
function _export_star(from, to) {
|
|
25
|
+
Object.keys(from).forEach(function(k) {
|
|
26
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
27
|
+
Object.defineProperty(to, k, {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
get: function() {
|
|
30
|
+
return from[k];
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
return from;
|
|
36
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { useEffect, useMemo } from 'react';
|
|
2
|
+
import { useQuery, useQueryClient } from '../queryClient';
|
|
3
|
+
import { createGetContentTypeKey, createGetManyContentTypesKey } from '../queryKeys';
|
|
4
|
+
export function useContentType(sdk, contentTypeId, options) {
|
|
5
|
+
const spaceId = sdk.ids.space;
|
|
6
|
+
const environmentId = sdk.ids.environmentAlias ?? sdk.ids.environment;
|
|
7
|
+
return useQuery(createGetContentTypeKey(spaceId, environmentId, contentTypeId), ()=>sdk.cma.contentType.get({
|
|
8
|
+
contentTypeId
|
|
9
|
+
}), {
|
|
10
|
+
staleTime: Infinity,
|
|
11
|
+
...options
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
export async function fetchContentType(sdk, contentTypeId) {
|
|
15
|
+
return sdk.cma.contentType.get({
|
|
16
|
+
contentTypeId
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
export function useContentTypes(source) {
|
|
20
|
+
const cma = 'cma' in source ? source.cma : source;
|
|
21
|
+
const navigator = 'navigator' in source ? source.navigator : undefined;
|
|
22
|
+
const queryClient = useQueryClient();
|
|
23
|
+
const spaceId = 'ids' in source ? source.ids.space : '';
|
|
24
|
+
const environmentId = 'ids' in source ? source.ids.environmentAlias ?? source.ids.environment : '';
|
|
25
|
+
const queryKey = useMemo(()=>createGetManyContentTypesKey(spaceId, environmentId, {
|
|
26
|
+
limit: 1000
|
|
27
|
+
}), [
|
|
28
|
+
spaceId,
|
|
29
|
+
environmentId
|
|
30
|
+
]);
|
|
31
|
+
const { data: contentTypes = [] } = useQuery(queryKey, async ()=>{
|
|
32
|
+
const allContentTypes = [];
|
|
33
|
+
const limit = 1000;
|
|
34
|
+
let skip = 0;
|
|
35
|
+
let total = 0;
|
|
36
|
+
do {
|
|
37
|
+
const response = await cma.contentType.getMany({
|
|
38
|
+
query: {
|
|
39
|
+
limit,
|
|
40
|
+
skip
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
allContentTypes.push(...response.items);
|
|
44
|
+
total = response.total;
|
|
45
|
+
skip += response.items.length;
|
|
46
|
+
}while (skip < total)
|
|
47
|
+
return allContentTypes;
|
|
48
|
+
}, {
|
|
49
|
+
staleTime: Infinity,
|
|
50
|
+
refetchOnMount: false
|
|
51
|
+
});
|
|
52
|
+
useEffect(()=>{
|
|
53
|
+
if (!navigator?.onSlideInNavigation) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const unsubscribe = navigator.onSlideInNavigation(({ oldSlideLevel, newSlideLevel })=>{
|
|
57
|
+
if (oldSlideLevel > newSlideLevel) {
|
|
58
|
+
void queryClient.invalidateQueries(queryKey);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
return unsubscribe;
|
|
62
|
+
}, [
|
|
63
|
+
navigator,
|
|
64
|
+
queryClient,
|
|
65
|
+
queryKey
|
|
66
|
+
]);
|
|
67
|
+
const invalidate = ()=>{
|
|
68
|
+
return queryClient.invalidateQueries(queryKey);
|
|
69
|
+
};
|
|
70
|
+
return {
|
|
71
|
+
contentTypes,
|
|
72
|
+
invalidate
|
|
73
|
+
};
|
|
74
|
+
}
|
package/dist/esm/index.js
CHANGED
|
@@ -17,4 +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
|
|
20
|
+
export * from './queryKeys';
|
package/dist/esm/queryClient.js
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
|
|
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 {}
|
|
2
|
+
import { QueryClient, useQuery as useRQ, useQueryClient as useHostQueryClient } from '@tanstack/react-query';
|
|
11
3
|
const clientContext = /*#__PURE__*/ React.createContext(undefined);
|
|
4
|
+
let sharedQueryClientInstance;
|
|
12
5
|
function useMaybeHostQueryClient() {
|
|
13
6
|
try {
|
|
14
7
|
return useHostQueryClient();
|
|
@@ -24,37 +17,38 @@ export function useQueryClient() {
|
|
|
24
17
|
return client;
|
|
25
18
|
}
|
|
26
19
|
if (hostClient) return hostClient;
|
|
27
|
-
if (!
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
retry: false
|
|
20
|
+
if (!sharedQueryClientInstance) {
|
|
21
|
+
sharedQueryClientInstance = new QueryClient({
|
|
22
|
+
defaultOptions: {
|
|
23
|
+
queries: {
|
|
24
|
+
useErrorBoundary: false,
|
|
25
|
+
refetchOnWindowFocus: false,
|
|
26
|
+
refetchOnReconnect: true,
|
|
27
|
+
refetchOnMount: false,
|
|
28
|
+
staleTime: Infinity,
|
|
29
|
+
retry: false
|
|
30
|
+
}
|
|
39
31
|
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return sharedQueryClientInstance;
|
|
42
35
|
}, [
|
|
43
36
|
client,
|
|
44
37
|
hostClient
|
|
45
38
|
]);
|
|
46
39
|
}
|
|
47
40
|
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
41
|
return useRQ(queryKey, queryFn, {
|
|
52
42
|
...options,
|
|
53
43
|
context: clientContext
|
|
54
44
|
});
|
|
55
45
|
}
|
|
56
|
-
export function SharedQueryClientProvider({ children }) {
|
|
57
|
-
const
|
|
46
|
+
export function SharedQueryClientProvider({ children, client: providedClient }) {
|
|
47
|
+
const internalClient = useQueryClient();
|
|
48
|
+
const client = React.useMemo(()=>providedClient ?? internalClient, [
|
|
49
|
+
providedClient,
|
|
50
|
+
internalClient
|
|
51
|
+
]);
|
|
58
52
|
return /*#__PURE__*/ React.createElement(clientContext.Provider, {
|
|
59
53
|
value: client
|
|
60
54
|
}, children);
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export const createGetEntryKey = (spaceId, environmentId, entryId)=>{
|
|
2
|
+
return [
|
|
3
|
+
'spaces',
|
|
4
|
+
spaceId,
|
|
5
|
+
'environments',
|
|
6
|
+
environmentId,
|
|
7
|
+
'entries',
|
|
8
|
+
'get',
|
|
9
|
+
entryId
|
|
10
|
+
];
|
|
11
|
+
};
|
|
12
|
+
export const createGetAssetKey = (spaceId, environmentId, assetId)=>{
|
|
13
|
+
return [
|
|
14
|
+
'spaces',
|
|
15
|
+
spaceId,
|
|
16
|
+
'environments',
|
|
17
|
+
environmentId,
|
|
18
|
+
'assets',
|
|
19
|
+
'get',
|
|
20
|
+
assetId
|
|
21
|
+
];
|
|
22
|
+
};
|
|
23
|
+
export const createGetSpaceKey = (spaceId)=>{
|
|
24
|
+
return [
|
|
25
|
+
'spaces',
|
|
26
|
+
'get',
|
|
27
|
+
spaceId
|
|
28
|
+
];
|
|
29
|
+
};
|
|
30
|
+
export const createGetManyLocalesKey = (spaceId, environmentId, params = {})=>{
|
|
31
|
+
return [
|
|
32
|
+
'spaces',
|
|
33
|
+
spaceId,
|
|
34
|
+
'environments',
|
|
35
|
+
environmentId,
|
|
36
|
+
'locales',
|
|
37
|
+
params
|
|
38
|
+
];
|
|
39
|
+
};
|
|
40
|
+
export const createGetContentTypeKey = (spaceId, environmentId, contentTypeId)=>{
|
|
41
|
+
return [
|
|
42
|
+
'spaces',
|
|
43
|
+
spaceId,
|
|
44
|
+
'environments',
|
|
45
|
+
environmentId,
|
|
46
|
+
'content_types',
|
|
47
|
+
'get',
|
|
48
|
+
contentTypeId
|
|
49
|
+
];
|
|
50
|
+
};
|
|
51
|
+
export const createGetManyContentTypesKey = (spaceId, environmentId, params = {})=>{
|
|
52
|
+
const prefix = [
|
|
53
|
+
'spaces',
|
|
54
|
+
spaceId,
|
|
55
|
+
'environments',
|
|
56
|
+
environmentId,
|
|
57
|
+
'content_types',
|
|
58
|
+
'getMany'
|
|
59
|
+
];
|
|
60
|
+
return Object.keys(params).length === 0 ? prefix : [
|
|
61
|
+
...prefix,
|
|
62
|
+
params
|
|
63
|
+
];
|
|
64
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ContentType, FieldAppSDK } from '@contentful/app-sdk';
|
|
2
|
+
type SDKWithCMA = Pick<FieldAppSDK, 'cma'>;
|
|
3
|
+
type SDKWithCMAAndNavigator = Pick<FieldAppSDK, 'cma' | 'navigator'>;
|
|
4
|
+
type SDKWithIdsAndCMA = Pick<FieldAppSDK, 'cma' | 'ids'>;
|
|
5
|
+
type CMAClient = SDKWithCMA['cma'];
|
|
6
|
+
/**
|
|
7
|
+
* Hook to fetch a single content type by ID.
|
|
8
|
+
* Uses proper query key for cache sharing with user_interface.
|
|
9
|
+
*/
|
|
10
|
+
export declare function useContentType(sdk: Pick<FieldAppSDK, 'cma' | 'ids'>, contentTypeId: string, options?: {
|
|
11
|
+
enabled?: boolean;
|
|
12
|
+
}): import("@tanstack/react-query").UseQueryResult<ContentType, unknown>;
|
|
13
|
+
/**
|
|
14
|
+
* Simple helper to fetch a single content type by ID.
|
|
15
|
+
* For use in async functions or one-off fetches.
|
|
16
|
+
* For repeated fetches with caching, use the useContentType hook instead.
|
|
17
|
+
*/
|
|
18
|
+
export declare function fetchContentType(sdk: Pick<FieldAppSDK, 'cma'>, contentTypeId: string): Promise<ContentType>;
|
|
19
|
+
export type UseContentTypesResult = {
|
|
20
|
+
contentTypes: ContentType[];
|
|
21
|
+
invalidate: () => void;
|
|
22
|
+
};
|
|
23
|
+
export declare function useContentTypes(source: SDKWithCMAAndNavigator | SDKWithCMA | SDKWithIdsAndCMA | CMAClient): UseContentTypesResult;
|
|
24
|
+
export {};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -19,4 +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
|
|
22
|
+
export * from './queryKeys';
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import { QueryClient, type UseQueryOptions, type UseQueryResult, type QueryKey, type QueryFunction } from '@tanstack/react-query';
|
|
3
3
|
export declare function useQueryClient(): QueryClient;
|
|
4
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
5
|
/**
|
|
6
6
|
* Provides access to a query client either by sharing an existing client or
|
|
7
7
|
* creating a new one.
|
|
8
|
+
*
|
|
9
|
+
* @param client - Optional QueryClient instance. When provided (e.g., in tests),
|
|
10
|
+
* it takes priority over any host client or singleton.
|
|
8
11
|
*/
|
|
9
|
-
export declare function SharedQueryClientProvider({ children }: React.PropsWithChildren<{
|
|
12
|
+
export declare function SharedQueryClientProvider({ children, client: providedClient, }: React.PropsWithChildren<{
|
|
13
|
+
client?: QueryClient;
|
|
14
|
+
}>): React.JSX.Element;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Query key factories for React Query cache management.
|
|
3
|
+
*
|
|
4
|
+
* These factories provide consistent query keys across the application.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Creates a query key for fetching a single entry.
|
|
8
|
+
*
|
|
9
|
+
* @param spaceId - The space ID
|
|
10
|
+
* @param environmentId - The environment ID
|
|
11
|
+
* @param entryId - The entry ID to fetch
|
|
12
|
+
* @returns Query key array for React Query
|
|
13
|
+
*/
|
|
14
|
+
export declare const createGetEntryKey: (spaceId: string, environmentId: string, entryId: string) => string[];
|
|
15
|
+
/**
|
|
16
|
+
* Creates a query key for fetching a single asset.
|
|
17
|
+
*
|
|
18
|
+
* @param spaceId - The space ID
|
|
19
|
+
* @param environmentId - The environment ID
|
|
20
|
+
* @param assetId - The asset ID to fetch
|
|
21
|
+
* @returns Query key array for React Query
|
|
22
|
+
*/
|
|
23
|
+
export declare const createGetAssetKey: (spaceId: string, environmentId: string, assetId: string) => string[];
|
|
24
|
+
/**
|
|
25
|
+
* Creates a query key for fetching a single space.
|
|
26
|
+
*
|
|
27
|
+
* @param spaceId - The space ID to fetch
|
|
28
|
+
* @returns Query key array for React Query
|
|
29
|
+
*/
|
|
30
|
+
export declare const createGetSpaceKey: (spaceId: string) => string[];
|
|
31
|
+
/**
|
|
32
|
+
* Creates a query key for fetching multiple locales.
|
|
33
|
+
*
|
|
34
|
+
* @param spaceId - The space ID
|
|
35
|
+
* @param environmentId - The environment ID
|
|
36
|
+
* @param params - Optional query parameters
|
|
37
|
+
* @returns Query key array for React Query
|
|
38
|
+
*/
|
|
39
|
+
export declare const createGetManyLocalesKey: (spaceId: string, environmentId: string, params?: Record<string, unknown>) => (string | Record<string, unknown>)[];
|
|
40
|
+
/**
|
|
41
|
+
* Creates a query key for fetching a single content type.
|
|
42
|
+
*
|
|
43
|
+
* @param spaceId - The space ID
|
|
44
|
+
* @param environmentId - The environment ID
|
|
45
|
+
* @param contentTypeId - The content type ID to fetch
|
|
46
|
+
* @returns Query key array for React Query
|
|
47
|
+
*/
|
|
48
|
+
export declare const createGetContentTypeKey: (spaceId: string, environmentId: string, contentTypeId: string) => string[];
|
|
49
|
+
/**
|
|
50
|
+
* Creates a query key for fetching multiple content types.
|
|
51
|
+
*
|
|
52
|
+
* @param spaceId - The space ID
|
|
53
|
+
* @param environmentId - The environment ID
|
|
54
|
+
* @param params - Optional query parameters (e.g., { limit: 1000 })
|
|
55
|
+
* @returns Query key array for React Query
|
|
56
|
+
*/
|
|
57
|
+
export declare const createGetManyContentTypesKey: (spaceId: string, environmentId: string, params?: Record<string, unknown>) => (string | Record<string, unknown>)[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/field-editor-shared",
|
|
3
|
-
"version": "2.17.1",
|
|
3
|
+
"version": "2.17.2-canary.1+168bff6f",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
@@ -11,6 +11,12 @@
|
|
|
11
11
|
"import": "./dist/esm/index.js",
|
|
12
12
|
"default": "./dist/cjs/index.js"
|
|
13
13
|
},
|
|
14
|
+
"./react-query": {
|
|
15
|
+
"types": "./dist/types/react-query.d.ts",
|
|
16
|
+
"require": "./dist/cjs/react-query.js",
|
|
17
|
+
"import": "./dist/esm/react-query.js",
|
|
18
|
+
"default": "./dist/cjs/react-query.js"
|
|
19
|
+
},
|
|
14
20
|
"./package.json": "./package.json"
|
|
15
21
|
},
|
|
16
22
|
"files": [
|
|
@@ -37,7 +43,7 @@
|
|
|
37
43
|
},
|
|
38
44
|
"devDependencies": {
|
|
39
45
|
"@contentful/app-sdk": "^4.42.0",
|
|
40
|
-
"@contentful/field-editor-test-utils": "^1.7.
|
|
46
|
+
"@contentful/field-editor-test-utils": "^1.7.1-canary.76+168bff6f",
|
|
41
47
|
"@lingui/core": "5.3.0",
|
|
42
48
|
"@tanstack/react-query": "^4.3.9",
|
|
43
49
|
"@testing-library/react": "16.3.0"
|
|
@@ -67,5 +73,5 @@
|
|
|
67
73
|
"publishConfig": {
|
|
68
74
|
"registry": "https://npm.pkg.github.com/"
|
|
69
75
|
},
|
|
70
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "168bff6f172e483def0432b3095e8f0a2af37b1f"
|
|
71
77
|
}
|