@contentful/field-editor-shared 1.4.9 → 1.5.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.
@@ -160,7 +160,7 @@ function getEntryTitle({ entry, contentType, localeCode, defaultLocaleCode, defa
160
160
  }
161
161
  return titleOrDefault(title, defaultTitle);
162
162
  }
163
- function getEntryStatus(sys) {
163
+ function getEntryStatus(sys, localeCodes) {
164
164
  if (!sys || sys.type !== 'Entry' && sys.type !== 'Asset') {
165
165
  throw new TypeError('Invalid entity metadata object');
166
166
  }
@@ -168,6 +168,26 @@ function getEntryStatus(sys) {
168
168
  return 'deleted';
169
169
  } else if (sys.archivedVersion) {
170
170
  return 'archived';
171
+ } else if (sys.fieldStatus) {
172
+ let status = 'draft';
173
+ const condition = (locale)=>{
174
+ if (Array.isArray(localeCodes)) {
175
+ return localeCodes.includes(locale);
176
+ }
177
+ return localeCodes ? localeCodes === locale : true;
178
+ };
179
+ Object.entries(sys.fieldStatus['*']).forEach(([localeCode, fieldStatus])=>{
180
+ if (condition(localeCode)) {
181
+ if (fieldStatus === 'changed') {
182
+ status = fieldStatus;
183
+ return;
184
+ }
185
+ if (fieldStatus === 'published') {
186
+ status = fieldStatus;
187
+ }
188
+ }
189
+ });
190
+ return status;
171
191
  } else if (sys.publishedVersion) {
172
192
  if (sys.version > sys.publishedVersion + 1) {
173
193
  return 'changed';
@@ -116,7 +116,7 @@ export function getEntryTitle({ entry, contentType, localeCode, defaultLocaleCod
116
116
  }
117
117
  return titleOrDefault(title, defaultTitle);
118
118
  }
119
- export function getEntryStatus(sys) {
119
+ export function getEntryStatus(sys, localeCodes) {
120
120
  if (!sys || sys.type !== 'Entry' && sys.type !== 'Asset') {
121
121
  throw new TypeError('Invalid entity metadata object');
122
122
  }
@@ -124,6 +124,26 @@ export function getEntryStatus(sys) {
124
124
  return 'deleted';
125
125
  } else if (sys.archivedVersion) {
126
126
  return 'archived';
127
+ } else if (sys.fieldStatus) {
128
+ let status = 'draft';
129
+ const condition = (locale)=>{
130
+ if (Array.isArray(localeCodes)) {
131
+ return localeCodes.includes(locale);
132
+ }
133
+ return localeCodes ? localeCodes === locale : true;
134
+ };
135
+ Object.entries(sys.fieldStatus['*']).forEach(([localeCode, fieldStatus])=>{
136
+ if (condition(localeCode)) {
137
+ if (fieldStatus === 'changed') {
138
+ status = fieldStatus;
139
+ return;
140
+ }
141
+ if (fieldStatus === 'published') {
142
+ status = fieldStatus;
143
+ }
144
+ }
145
+ });
146
+ return status;
127
147
  } else if (sys.publishedVersion) {
128
148
  if (sys.version > sys.publishedVersion + 1) {
129
149
  return 'changed';
@@ -55,7 +55,13 @@ export declare function getEntryTitle({ entry, contentType, localeCode, defaultL
55
55
  defaultLocaleCode: string;
56
56
  defaultTitle: string;
57
57
  }): string;
58
- export declare function getEntryStatus(sys: Entry['sys']): "deleted" | "archived" | "changed" | "published" | "draft";
58
+ type AsyncPublishStatus = 'draft' | 'published' | 'changed';
59
+ type FieldStatus = {
60
+ '*': Record<string, AsyncPublishStatus>;
61
+ };
62
+ export declare function getEntryStatus(sys: Entry['sys'] & {
63
+ fieldStatus?: FieldStatus;
64
+ }, localeCodes?: string | string[]): "draft" | "published" | "changed" | "deleted" | "archived";
59
65
  /**
60
66
  * Gets a promise resolving with a localized asset image field representing a
61
67
  * given entities file. The promise may resolve with null.
@@ -66,3 +72,4 @@ export declare const getEntryImage: ({ entry, contentType, localeCode, }: {
66
72
  localeCode: string;
67
73
  defaultLocaleCode: string;
68
74
  }, getAsset: (assetId: string) => Promise<unknown>) => Promise<null | File>;
75
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/field-editor-shared",
3
- "version": "1.4.9",
3
+ "version": "1.5.0",
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": "29cf5fb16a8d61f6c23678dad618c61aceec320d"
54
+ "gitHead": "843655f104af6fb8c116869d59cd9f20e6f1ab14"
55
55
  }