@contentful/field-editor-shared 1.5.2 → 1.5.3
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.
|
@@ -15,6 +15,9 @@ _export(exports, {
|
|
|
15
15
|
getEntityDescription: function() {
|
|
16
16
|
return getEntityDescription;
|
|
17
17
|
},
|
|
18
|
+
getEntityStatus: function() {
|
|
19
|
+
return getEntityStatus;
|
|
20
|
+
},
|
|
18
21
|
getEntryImage: function() {
|
|
19
22
|
return getEntryImage;
|
|
20
23
|
},
|
|
@@ -160,7 +163,7 @@ function getEntryTitle({ entry, contentType, localeCode, defaultLocaleCode, defa
|
|
|
160
163
|
}
|
|
161
164
|
return titleOrDefault(title, defaultTitle);
|
|
162
165
|
}
|
|
163
|
-
function
|
|
166
|
+
function getEntityStatus(sys, localeCodes) {
|
|
164
167
|
if (!sys || sys.type !== 'Entry' && sys.type !== 'Asset') {
|
|
165
168
|
throw new TypeError('Invalid entity metadata object');
|
|
166
169
|
}
|
|
@@ -170,6 +173,27 @@ function getEntryStatus(sys, localeCodes) {
|
|
|
170
173
|
if (sys.archivedVersion) {
|
|
171
174
|
return 'archived';
|
|
172
175
|
}
|
|
176
|
+
if (sys.fieldStatus && localeCodes) {
|
|
177
|
+
let status = 'draft';
|
|
178
|
+
const isMatchingLocale = (locale)=>{
|
|
179
|
+
if (Array.isArray(localeCodes)) {
|
|
180
|
+
return localeCodes.includes(locale);
|
|
181
|
+
}
|
|
182
|
+
return localeCodes ? localeCodes === locale : true;
|
|
183
|
+
};
|
|
184
|
+
Object.entries(sys.fieldStatus['*']).forEach(([localeCode, fieldStatus])=>{
|
|
185
|
+
if (isMatchingLocale(localeCode)) {
|
|
186
|
+
if (fieldStatus === 'changed') {
|
|
187
|
+
status = fieldStatus;
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
if (fieldStatus === 'published') {
|
|
191
|
+
status = fieldStatus;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
return status;
|
|
196
|
+
}
|
|
173
197
|
if (sys.publishedVersion) {
|
|
174
198
|
if (sys.version > sys.publishedVersion + 1) {
|
|
175
199
|
return 'changed';
|
|
@@ -179,6 +203,9 @@ function getEntryStatus(sys, localeCodes) {
|
|
|
179
203
|
}
|
|
180
204
|
return 'draft';
|
|
181
205
|
}
|
|
206
|
+
function getEntryStatus(sys, localeCodes) {
|
|
207
|
+
return getEntityStatus(sys, localeCodes);
|
|
208
|
+
}
|
|
182
209
|
const getEntryImage = async ({ entry, contentType, localeCode }, getAsset)=>{
|
|
183
210
|
if (!contentType) {
|
|
184
211
|
return null;
|
|
@@ -116,7 +116,7 @@ export function getEntryTitle({ entry, contentType, localeCode, defaultLocaleCod
|
|
|
116
116
|
}
|
|
117
117
|
return titleOrDefault(title, defaultTitle);
|
|
118
118
|
}
|
|
119
|
-
export function
|
|
119
|
+
export function getEntityStatus(sys, localeCodes) {
|
|
120
120
|
if (!sys || sys.type !== 'Entry' && sys.type !== 'Asset') {
|
|
121
121
|
throw new TypeError('Invalid entity metadata object');
|
|
122
122
|
}
|
|
@@ -126,6 +126,27 @@ export function getEntryStatus(sys, localeCodes) {
|
|
|
126
126
|
if (sys.archivedVersion) {
|
|
127
127
|
return 'archived';
|
|
128
128
|
}
|
|
129
|
+
if (sys.fieldStatus && localeCodes) {
|
|
130
|
+
let status = 'draft';
|
|
131
|
+
const isMatchingLocale = (locale)=>{
|
|
132
|
+
if (Array.isArray(localeCodes)) {
|
|
133
|
+
return localeCodes.includes(locale);
|
|
134
|
+
}
|
|
135
|
+
return localeCodes ? localeCodes === locale : true;
|
|
136
|
+
};
|
|
137
|
+
Object.entries(sys.fieldStatus['*']).forEach(([localeCode, fieldStatus])=>{
|
|
138
|
+
if (isMatchingLocale(localeCode)) {
|
|
139
|
+
if (fieldStatus === 'changed') {
|
|
140
|
+
status = fieldStatus;
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
if (fieldStatus === 'published') {
|
|
144
|
+
status = fieldStatus;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
return status;
|
|
149
|
+
}
|
|
129
150
|
if (sys.publishedVersion) {
|
|
130
151
|
if (sys.version > sys.publishedVersion + 1) {
|
|
131
152
|
return 'changed';
|
|
@@ -135,6 +156,9 @@ export function getEntryStatus(sys, localeCodes) {
|
|
|
135
156
|
}
|
|
136
157
|
return 'draft';
|
|
137
158
|
}
|
|
159
|
+
export function getEntryStatus(sys, localeCodes) {
|
|
160
|
+
return getEntityStatus(sys, localeCodes);
|
|
161
|
+
}
|
|
138
162
|
export const getEntryImage = async ({ entry, contentType, localeCode }, getAsset)=>{
|
|
139
163
|
if (!contentType) {
|
|
140
164
|
return null;
|
|
@@ -59,6 +59,19 @@ type AsyncPublishStatus = 'draft' | 'published' | 'changed';
|
|
|
59
59
|
type FieldStatus = {
|
|
60
60
|
'*': Record<string, AsyncPublishStatus>;
|
|
61
61
|
};
|
|
62
|
+
/**
|
|
63
|
+
* Returns the status of the entry/asset
|
|
64
|
+
* If a locale code(s) is provided it will pick up the most advanced state for these locale(s)
|
|
65
|
+
* - deleted
|
|
66
|
+
* - archived
|
|
67
|
+
* - changed
|
|
68
|
+
* - published
|
|
69
|
+
* - draft
|
|
70
|
+
*/
|
|
71
|
+
export declare function getEntityStatus(sys: (Entry['sys'] | Asset['sys']) & {
|
|
72
|
+
fieldStatus?: FieldStatus;
|
|
73
|
+
}, localeCodes?: string | string[]): "draft" | "published" | "changed" | "deleted" | "archived";
|
|
74
|
+
/**@deprecated use `getEntityStatus` */
|
|
62
75
|
export declare function getEntryStatus(sys: Entry['sys'] & {
|
|
63
76
|
fieldStatus?: FieldStatus;
|
|
64
77
|
}, localeCodes?: string | string[]): "draft" | "published" | "changed" | "deleted" | "archived";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/field-editor-shared",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.3",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"publishConfig": {
|
|
52
52
|
"registry": "https://npm.pkg.github.com/"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "6287e6c00cd65f5f3625526707551c213d58d3e3"
|
|
55
55
|
}
|