@contentful/field-editor-shared 2.17.1-alpha.0 → 2.17.1-canary.59
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 +94 -0
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/queryClient.js +15 -5
- package/dist/cjs/queryKeys.js +94 -0
- package/dist/esm/hooks/useContentTypes.js +73 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/queryClient.js +15 -5
- package/dist/esm/queryKeys.js +64 -0
- package/dist/types/hooks/useContentTypes.d.ts +24 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/queryClient.d.ts +5 -3
- package/dist/types/queryKeys.d.ts +76 -0
- package/package.json +2 -2
|
@@ -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
|
+
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 queryParams = (0, _react.useMemo)(()=>({
|
|
47
|
+
limit: 1000
|
|
48
|
+
}), []);
|
|
49
|
+
const { data: contentTypes = [] } = (0, _queryClient.useQuery)((0, _queryKeys.createGetManyContentTypesKey)(spaceId, environmentId, queryParams), async ()=>{
|
|
50
|
+
const allContentTypes = [];
|
|
51
|
+
const limit = 1000;
|
|
52
|
+
let skip = 0;
|
|
53
|
+
let total = 0;
|
|
54
|
+
do {
|
|
55
|
+
const response = await cma.contentType.getMany({
|
|
56
|
+
query: {
|
|
57
|
+
limit,
|
|
58
|
+
skip
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
allContentTypes.push(...response.items);
|
|
62
|
+
total = response.total;
|
|
63
|
+
skip += response.items.length;
|
|
64
|
+
}while (skip < total)
|
|
65
|
+
return allContentTypes;
|
|
66
|
+
}, {
|
|
67
|
+
staleTime: Infinity,
|
|
68
|
+
refetchOnMount: false
|
|
69
|
+
});
|
|
70
|
+
(0, _react.useEffect)(()=>{
|
|
71
|
+
if (!navigator?.onSlideInNavigation) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const unsubscribe = navigator.onSlideInNavigation(({ oldSlideLevel, newSlideLevel })=>{
|
|
75
|
+
if (oldSlideLevel > newSlideLevel) {
|
|
76
|
+
void queryClient.invalidateQueries((0, _queryKeys.createGetManyContentTypesKey)(spaceId, environmentId, queryParams));
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
return unsubscribe;
|
|
80
|
+
}, [
|
|
81
|
+
navigator,
|
|
82
|
+
queryClient,
|
|
83
|
+
spaceId,
|
|
84
|
+
environmentId,
|
|
85
|
+
queryParams
|
|
86
|
+
]);
|
|
87
|
+
const invalidate = ()=>{
|
|
88
|
+
return queryClient.invalidateQueries((0, _queryKeys.createGetManyContentTypesKey)(spaceId, environmentId, queryParams));
|
|
89
|
+
};
|
|
90
|
+
return {
|
|
91
|
+
contentTypes,
|
|
92
|
+
invalidate
|
|
93
|
+
};
|
|
94
|
+
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -117,12 +117,14 @@ _export_star(require("./types"), exports);
|
|
|
117
117
|
_export_star(require("./hooks/useActiveLocales"), exports);
|
|
118
118
|
_export_star(require("./hooks/useReleaseStatus"), exports);
|
|
119
119
|
_export_star(require("./hooks/useLocalePublishStatus"), exports);
|
|
120
|
+
_export_star(require("./hooks/useContentTypes"), exports);
|
|
120
121
|
_export_star(require("./LocalePublishingEntityStatusBadge"), exports);
|
|
121
122
|
_export_star(require("./ReleaseEntityStatusBadge"), exports);
|
|
122
123
|
_export_star(require("./utils/determineReleaseAction"), exports);
|
|
123
124
|
_export_star(require("./utils/getEntityReleaseStatus"), exports);
|
|
124
125
|
_export_star(require("./utils/getReleaseStatusBadgeConfig"), exports);
|
|
125
126
|
const _queryClient = require("./queryClient");
|
|
127
|
+
_export_star(require("./queryKeys"), exports);
|
|
126
128
|
function _export_star(from, to) {
|
|
127
129
|
Object.keys(from).forEach(function(k) {
|
|
128
130
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
package/dist/cjs/queryClient.js
CHANGED
|
@@ -61,12 +61,12 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
61
61
|
}
|
|
62
62
|
return newObj;
|
|
63
63
|
}
|
|
64
|
-
let
|
|
64
|
+
let RQQueryClient;
|
|
65
65
|
let useRQ;
|
|
66
66
|
let useHostQueryClient = ()=>undefined;
|
|
67
67
|
try {
|
|
68
68
|
const rq = require('@tanstack/react-query');
|
|
69
|
-
|
|
69
|
+
RQQueryClient = rq.QueryClient;
|
|
70
70
|
useRQ = rq.useQuery;
|
|
71
71
|
useHostQueryClient = rq.useQueryClient;
|
|
72
72
|
} catch {}
|
|
@@ -86,7 +86,10 @@ function useQueryClient() {
|
|
|
86
86
|
return client;
|
|
87
87
|
}
|
|
88
88
|
if (hostClient) return hostClient;
|
|
89
|
-
|
|
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({
|
|
90
93
|
defaultOptions: {
|
|
91
94
|
queries: {
|
|
92
95
|
useErrorBoundary: false,
|
|
@@ -104,13 +107,20 @@ function useQueryClient() {
|
|
|
104
107
|
]);
|
|
105
108
|
}
|
|
106
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
|
+
}
|
|
107
113
|
return useRQ(queryKey, queryFn, {
|
|
108
114
|
...options,
|
|
109
115
|
context: clientContext
|
|
110
116
|
});
|
|
111
117
|
}
|
|
112
|
-
function SharedQueryClientProvider({ children }) {
|
|
113
|
-
const
|
|
118
|
+
function SharedQueryClientProvider({ children, client: providedClient }) {
|
|
119
|
+
const internalClient = useQueryClient();
|
|
120
|
+
const client = _react.useMemo(()=>providedClient ?? internalClient, [
|
|
121
|
+
providedClient,
|
|
122
|
+
internalClient
|
|
123
|
+
]);
|
|
114
124
|
return /*#__PURE__*/ _react.createElement(clientContext.Provider, {
|
|
115
125
|
value: client
|
|
116
126
|
}, 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,73 @@
|
|
|
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 queryParams = useMemo(()=>({
|
|
26
|
+
limit: 1000
|
|
27
|
+
}), []);
|
|
28
|
+
const { data: contentTypes = [] } = useQuery(createGetManyContentTypesKey(spaceId, environmentId, queryParams), async ()=>{
|
|
29
|
+
const allContentTypes = [];
|
|
30
|
+
const limit = 1000;
|
|
31
|
+
let skip = 0;
|
|
32
|
+
let total = 0;
|
|
33
|
+
do {
|
|
34
|
+
const response = await cma.contentType.getMany({
|
|
35
|
+
query: {
|
|
36
|
+
limit,
|
|
37
|
+
skip
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
allContentTypes.push(...response.items);
|
|
41
|
+
total = response.total;
|
|
42
|
+
skip += response.items.length;
|
|
43
|
+
}while (skip < total)
|
|
44
|
+
return allContentTypes;
|
|
45
|
+
}, {
|
|
46
|
+
staleTime: Infinity,
|
|
47
|
+
refetchOnMount: false
|
|
48
|
+
});
|
|
49
|
+
useEffect(()=>{
|
|
50
|
+
if (!navigator?.onSlideInNavigation) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const unsubscribe = navigator.onSlideInNavigation(({ oldSlideLevel, newSlideLevel })=>{
|
|
54
|
+
if (oldSlideLevel > newSlideLevel) {
|
|
55
|
+
void queryClient.invalidateQueries(createGetManyContentTypesKey(spaceId, environmentId, queryParams));
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
return unsubscribe;
|
|
59
|
+
}, [
|
|
60
|
+
navigator,
|
|
61
|
+
queryClient,
|
|
62
|
+
spaceId,
|
|
63
|
+
environmentId,
|
|
64
|
+
queryParams
|
|
65
|
+
]);
|
|
66
|
+
const invalidate = ()=>{
|
|
67
|
+
return queryClient.invalidateQueries(createGetManyContentTypesKey(spaceId, environmentId, queryParams));
|
|
68
|
+
};
|
|
69
|
+
return {
|
|
70
|
+
contentTypes,
|
|
71
|
+
invalidate
|
|
72
|
+
};
|
|
73
|
+
}
|
package/dist/esm/index.js
CHANGED
|
@@ -12,9 +12,11 @@ export * from './types';
|
|
|
12
12
|
export * from './hooks/useActiveLocales';
|
|
13
13
|
export * from './hooks/useReleaseStatus';
|
|
14
14
|
export * from './hooks/useLocalePublishStatus';
|
|
15
|
+
export * from './hooks/useContentTypes';
|
|
15
16
|
export * from './LocalePublishingEntityStatusBadge';
|
|
16
17
|
export * from './ReleaseEntityStatusBadge';
|
|
17
18
|
export * from './utils/determineReleaseAction';
|
|
18
19
|
export * from './utils/getEntityReleaseStatus';
|
|
19
20
|
export * from './utils/getReleaseStatusBadgeConfig';
|
|
20
21
|
export { SharedQueryClientProvider, useQueryClient, useQuery } from './queryClient';
|
|
22
|
+
export * from './queryKeys';
|
package/dist/esm/queryClient.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
let
|
|
2
|
+
let RQQueryClient;
|
|
3
3
|
let useRQ;
|
|
4
4
|
let useHostQueryClient = ()=>undefined;
|
|
5
5
|
try {
|
|
6
6
|
const rq = require('@tanstack/react-query');
|
|
7
|
-
|
|
7
|
+
RQQueryClient = rq.QueryClient;
|
|
8
8
|
useRQ = rq.useQuery;
|
|
9
9
|
useHostQueryClient = rq.useQueryClient;
|
|
10
10
|
} catch {}
|
|
@@ -24,7 +24,10 @@ export function useQueryClient() {
|
|
|
24
24
|
return client;
|
|
25
25
|
}
|
|
26
26
|
if (hostClient) return hostClient;
|
|
27
|
-
|
|
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({
|
|
28
31
|
defaultOptions: {
|
|
29
32
|
queries: {
|
|
30
33
|
useErrorBoundary: false,
|
|
@@ -42,13 +45,20 @@ export function useQueryClient() {
|
|
|
42
45
|
]);
|
|
43
46
|
}
|
|
44
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
|
+
}
|
|
45
51
|
return useRQ(queryKey, queryFn, {
|
|
46
52
|
...options,
|
|
47
53
|
context: clientContext
|
|
48
54
|
});
|
|
49
55
|
}
|
|
50
|
-
export function SharedQueryClientProvider({ children }) {
|
|
51
|
-
const
|
|
56
|
+
export function SharedQueryClientProvider({ children, client: providedClient }) {
|
|
57
|
+
const internalClient = useQueryClient();
|
|
58
|
+
const client = React.useMemo(()=>providedClient ?? internalClient, [
|
|
59
|
+
providedClient,
|
|
60
|
+
internalClient
|
|
61
|
+
]);
|
|
52
62
|
return /*#__PURE__*/ React.createElement(clientContext.Provider, {
|
|
53
63
|
value: client
|
|
54
64
|
}, 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
|
@@ -14,9 +14,11 @@ export * from './types';
|
|
|
14
14
|
export * from './hooks/useActiveLocales';
|
|
15
15
|
export * from './hooks/useReleaseStatus';
|
|
16
16
|
export * from './hooks/useLocalePublishStatus';
|
|
17
|
+
export * from './hooks/useContentTypes';
|
|
17
18
|
export * from './LocalePublishingEntityStatusBadge';
|
|
18
19
|
export * from './ReleaseEntityStatusBadge';
|
|
19
20
|
export * from './utils/determineReleaseAction';
|
|
20
21
|
export * from './utils/getEntityReleaseStatus';
|
|
21
22
|
export * from './utils/getReleaseStatusBadgeConfig';
|
|
22
23
|
export { SharedQueryClientProvider, useQueryClient, useQuery } from './queryClient';
|
|
24
|
+
export * from './queryKeys';
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import type { QueryClient
|
|
3
|
-
export declare function useQueryClient():
|
|
2
|
+
import type { QueryClient, UseQueryOptions, UseQueryResult, QueryKey, QueryFunction } from '@tanstack/react-query';
|
|
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
8
|
*/
|
|
9
|
-
export declare function SharedQueryClientProvider({ children }: React.PropsWithChildren<{
|
|
9
|
+
export declare function SharedQueryClientProvider({ children, client: providedClient, }: React.PropsWithChildren<{
|
|
10
|
+
client?: QueryClient;
|
|
11
|
+
}>): React.JSX.Element;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Query key factories matching user_interface repository structure.
|
|
3
|
+
*
|
|
4
|
+
* IMPORTANT: These must stay in sync with user_interface to enable cache sharing.
|
|
5
|
+
* When updating, check the corresponding file in user_interface repository.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Creates a query key for fetching a single entry.
|
|
9
|
+
* Matches the structure used in user_interface for cache sharing.
|
|
10
|
+
*
|
|
11
|
+
* Source: https://github.com/contentful/user_interface/blob/main/src/javascripts/core/react-query/cma/entry/useGetEntry.ts
|
|
12
|
+
*
|
|
13
|
+
* @param spaceId - The space ID
|
|
14
|
+
* @param environmentId - The environment ID
|
|
15
|
+
* @param entryId - The entry ID to fetch
|
|
16
|
+
* @returns Query key array for React Query
|
|
17
|
+
*/
|
|
18
|
+
export declare const createGetEntryKey: (spaceId: string, environmentId: string, entryId: string) => string[];
|
|
19
|
+
/**
|
|
20
|
+
* Creates a query key for fetching a single asset.
|
|
21
|
+
* Matches the structure used in user_interface for cache sharing.
|
|
22
|
+
*
|
|
23
|
+
* Source: https://github.com/contentful/user_interface/blob/main/src/javascripts/core/react-query/cma/asset/useGetAsset.ts
|
|
24
|
+
*
|
|
25
|
+
* @param spaceId - The space ID
|
|
26
|
+
* @param environmentId - The environment ID
|
|
27
|
+
* @param assetId - The asset ID to fetch
|
|
28
|
+
* @returns Query key array for React Query
|
|
29
|
+
*/
|
|
30
|
+
export declare const createGetAssetKey: (spaceId: string, environmentId: string, assetId: string) => string[];
|
|
31
|
+
/**
|
|
32
|
+
* Creates a query key for fetching a single space.
|
|
33
|
+
* Matches the structure used in user_interface for cache sharing.
|
|
34
|
+
*
|
|
35
|
+
* Source: https://github.com/contentful/user_interface/blob/main/src/javascripts/core/react-query/cma/space/useGetSpace.ts
|
|
36
|
+
*
|
|
37
|
+
* @param spaceId - The space ID to fetch
|
|
38
|
+
* @returns Query key array for React Query
|
|
39
|
+
*/
|
|
40
|
+
export declare const createGetSpaceKey: (spaceId: string) => string[];
|
|
41
|
+
/**
|
|
42
|
+
* Creates a query key for fetching multiple locales.
|
|
43
|
+
* Matches the structure used in user_interface for cache sharing.
|
|
44
|
+
*
|
|
45
|
+
* Source: https://github.com/contentful/user_interface/blob/main/src/javascripts/core/react-query/cma/locale/useGetManyLocales.ts
|
|
46
|
+
*
|
|
47
|
+
* @param spaceId - The space ID
|
|
48
|
+
* @param environmentId - The environment ID
|
|
49
|
+
* @param params - Optional query parameters
|
|
50
|
+
* @returns Query key array for React Query
|
|
51
|
+
*/
|
|
52
|
+
export declare const createGetManyLocalesKey: (spaceId: string, environmentId: string, params?: Record<string, unknown>) => (string | Record<string, unknown>)[];
|
|
53
|
+
/**
|
|
54
|
+
* Creates a query key for fetching a single content type.
|
|
55
|
+
* Matches the structure used in user_interface for cache sharing.
|
|
56
|
+
*
|
|
57
|
+
* Source: https://github.com/contentful/user_interface/blob/main/src/javascripts/core/react-query/cma/contentType/useGetContentType.ts
|
|
58
|
+
*
|
|
59
|
+
* @param spaceId - The space ID
|
|
60
|
+
* @param environmentId - The environment ID
|
|
61
|
+
* @param contentTypeId - The content type ID to fetch
|
|
62
|
+
* @returns Query key array for React Query
|
|
63
|
+
*/
|
|
64
|
+
export declare const createGetContentTypeKey: (spaceId: string, environmentId: string, contentTypeId: string) => string[];
|
|
65
|
+
/**
|
|
66
|
+
* Creates a query key for fetching multiple content types.
|
|
67
|
+
* Matches the structure used in user_interface for cache sharing.
|
|
68
|
+
*
|
|
69
|
+
* Source: https://github.com/contentful/user_interface/blob/main/src/javascripts/core/react-query/cma/contentType/useGetManyContentTypes.ts
|
|
70
|
+
*
|
|
71
|
+
* @param spaceId - The space ID
|
|
72
|
+
* @param environmentId - The environment ID
|
|
73
|
+
* @param params - Optional query parameters (e.g., { limit: 1000 })
|
|
74
|
+
* @returns Query key array for React Query
|
|
75
|
+
*/
|
|
76
|
+
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.1-canary.59+54b401aa",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
"publishConfig": {
|
|
68
68
|
"registry": "https://npm.pkg.github.com/"
|
|
69
69
|
},
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "54b401aa9908c8380c3801bf25fa38e23dff72d2"
|
|
71
71
|
}
|