@contentful/field-editor-shared 1.5.2 → 1.5.4

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.
@@ -9,8 +9,8 @@ Object.defineProperty(exports, "FieldConnector", {
9
9
  }
10
10
  });
11
11
  const _react = _interop_require_wildcard(require("react"));
12
+ const _fastdeepequal = _interop_require_default(require("fast-deep-equal"));
12
13
  const _debounce = _interop_require_default(require("lodash/debounce"));
13
- const _isEqual = _interop_require_default(require("lodash/isEqual"));
14
14
  function _define_property(obj, key, value) {
15
15
  if (key in obj) {
16
16
  Object.defineProperty(obj, key, {
@@ -167,7 +167,7 @@ _define_property(FieldConnector, "defaultProps", {
167
167
  return value === null || value === '';
168
168
  },
169
169
  isEqualValues: (value1, value2)=>{
170
- return (0, _isEqual.default)(value1, value2);
170
+ return (0, _fastdeepequal.default)(value1, value2);
171
171
  },
172
172
  debounce: 300
173
173
  });
@@ -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 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
  }
@@ -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;
@@ -12,8 +12,8 @@ function _define_property(obj, key, value) {
12
12
  return obj;
13
13
  }
14
14
  import * as React from 'react';
15
+ import deepEqual from 'fast-deep-equal';
15
16
  import debounce from 'lodash/debounce';
16
- import isEqual from 'lodash/isEqual';
17
17
  var _React_Component;
18
18
  export class FieldConnector extends (_React_Component = React.Component) {
19
19
  componentDidMount() {
@@ -111,7 +111,7 @@ _define_property(FieldConnector, "defaultProps", {
111
111
  return value === null || value === '';
112
112
  },
113
113
  isEqualValues: (value1, value2)=>{
114
- return isEqual(value1, value2);
114
+ return deepEqual(value1, value2);
115
115
  },
116
116
  debounce: 300
117
117
  });
@@ -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, 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
  }
@@ -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;
@@ -25,7 +25,7 @@ type FieldConnectorProps<ValueType> = {
25
25
  isDisabled?: boolean;
26
26
  children: (state: FieldConnectorChildProps<ValueType>) => React.ReactNode;
27
27
  isEmptyValue: (value: ValueType | null) => boolean;
28
- isEqualValues: (value1: ValueType | Nullable, value2: ValueType | Nullable) => boolean;
28
+ isEqualValues?: (value1: ValueType | Nullable, value2: ValueType | Nullable) => boolean;
29
29
  } & ({
30
30
  debounce: number;
31
31
  } | {
@@ -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.2",
3
+ "version": "1.5.4",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -42,6 +42,7 @@
42
42
  "@contentful/f36-note": "^4.2.8",
43
43
  "@contentful/f36-tokens": "^4.0.0",
44
44
  "emotion": "^10.0.17",
45
+ "fast-deep-equal": "^3.1.3",
45
46
  "lodash": "^4.17.15"
46
47
  },
47
48
  "peerDependencies": {
@@ -51,5 +52,5 @@
51
52
  "publishConfig": {
52
53
  "registry": "https://npm.pkg.github.com/"
53
54
  },
54
- "gitHead": "4ec14a5b5611b2bfa17bfa10b4ac5942c2c25406"
55
+ "gitHead": "f9d4036890841b8d459dd92912f2d410a8ee72f6"
55
56
  }