@contentful/field-editor-shared 1.5.1 → 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,24 +163,26 @@ function getEntryTitle({ entry, contentType, localeCode, defaultLocaleCode, defa
160
163
  }
161
164
  return titleOrDefault(title, defaultTitle);
162
165
  }
163
- function getEntryStatus(sys, localeCodes) {
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
  }
167
170
  if (sys.deletedVersion) {
168
171
  return 'deleted';
169
- } else if (sys.archivedVersion) {
172
+ }
173
+ if (sys.archivedVersion) {
170
174
  return 'archived';
171
- } else if (sys.fieldStatus) {
175
+ }
176
+ if (sys.fieldStatus && localeCodes) {
172
177
  let status = 'draft';
173
- const condition = (locale)=>{
178
+ const isMatchingLocale = (locale)=>{
174
179
  if (Array.isArray(localeCodes)) {
175
180
  return localeCodes.includes(locale);
176
181
  }
177
182
  return localeCodes ? localeCodes === locale : true;
178
183
  };
179
184
  Object.entries(sys.fieldStatus['*']).forEach(([localeCode, fieldStatus])=>{
180
- if (condition(localeCode)) {
185
+ if (isMatchingLocale(localeCode)) {
181
186
  if (fieldStatus === 'changed') {
182
187
  status = fieldStatus;
183
188
  return;
@@ -188,15 +193,18 @@ function getEntryStatus(sys, localeCodes) {
188
193
  }
189
194
  });
190
195
  return status;
191
- } else if (sys.publishedVersion) {
196
+ }
197
+ if (sys.publishedVersion) {
192
198
  if (sys.version > sys.publishedVersion + 1) {
193
199
  return 'changed';
194
200
  } else {
195
201
  return 'published';
196
202
  }
197
- } else {
198
- return 'draft';
199
203
  }
204
+ return 'draft';
205
+ }
206
+ function getEntryStatus(sys, localeCodes) {
207
+ return getEntityStatus(sys, localeCodes);
200
208
  }
201
209
  const getEntryImage = async ({ entry, contentType, localeCode }, getAsset)=>{
202
210
  if (!contentType) {
@@ -116,24 +116,26 @@ export function getEntryTitle({ entry, contentType, localeCode, defaultLocaleCod
116
116
  }
117
117
  return titleOrDefault(title, defaultTitle);
118
118
  }
119
- export function getEntryStatus(sys, localeCodes) {
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
  }
123
123
  if (sys.deletedVersion) {
124
124
  return 'deleted';
125
- } else if (sys.archivedVersion) {
125
+ }
126
+ if (sys.archivedVersion) {
126
127
  return 'archived';
127
- } else if (sys.fieldStatus) {
128
+ }
129
+ if (sys.fieldStatus && localeCodes) {
128
130
  let status = 'draft';
129
- const condition = (locale)=>{
131
+ const isMatchingLocale = (locale)=>{
130
132
  if (Array.isArray(localeCodes)) {
131
133
  return localeCodes.includes(locale);
132
134
  }
133
135
  return localeCodes ? localeCodes === locale : true;
134
136
  };
135
137
  Object.entries(sys.fieldStatus['*']).forEach(([localeCode, fieldStatus])=>{
136
- if (condition(localeCode)) {
138
+ if (isMatchingLocale(localeCode)) {
137
139
  if (fieldStatus === 'changed') {
138
140
  status = fieldStatus;
139
141
  return;
@@ -144,15 +146,18 @@ export function getEntryStatus(sys, localeCodes) {
144
146
  }
145
147
  });
146
148
  return status;
147
- } else if (sys.publishedVersion) {
149
+ }
150
+ if (sys.publishedVersion) {
148
151
  if (sys.version > sys.publishedVersion + 1) {
149
152
  return 'changed';
150
153
  } else {
151
154
  return 'published';
152
155
  }
153
- } else {
154
- return 'draft';
155
156
  }
157
+ return 'draft';
158
+ }
159
+ export function getEntryStatus(sys, localeCodes) {
160
+ return getEntityStatus(sys, localeCodes);
156
161
  }
157
162
  export const getEntryImage = async ({ entry, contentType, localeCode }, getAsset)=>{
158
163
  if (!contentType) {
@@ -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.1",
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": "60fd3c2f5a58f4d42886b5f952ce3cc1aec71833"
54
+ "gitHead": "6287e6c00cd65f5f3625526707551c213d58d3e3"
55
55
  }