@contentful/field-editor-shared 1.4.9 → 1.5.1

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.
@@ -121,6 +121,7 @@ class FieldConnector extends (_React_Component = _react.Component) {
121
121
  _define_property(this, "unsubscribeErrors", null);
122
122
  _define_property(this, "unsubscribeDisabled", null);
123
123
  _define_property(this, "unsubscribeValue", null);
124
+ _define_property(this, "getDebounceDuration", ()=>'debounce' in this.props ? this.props.debounce : this.props.throttle);
124
125
  _define_property(this, "setValue", async (value)=>{
125
126
  if (this.props.isEmptyValue(value ?? null)) {
126
127
  this.setState({
@@ -131,7 +132,7 @@ class FieldConnector extends (_React_Component = _react.Component) {
131
132
  value
132
133
  });
133
134
  }
134
- if (this.props.debounce === 0) {
135
+ if (this.getDebounceDuration() === 0) {
135
136
  await this.triggerSetValueCallbacks(value);
136
137
  } else {
137
138
  await this.debouncedTriggerSetValueCallbacks(value);
@@ -146,7 +147,7 @@ class FieldConnector extends (_React_Component = _react.Component) {
146
147
  }
147
148
  });
148
149
  });
149
- _define_property(this, "debouncedTriggerSetValueCallbacks", (0, _debounce.default)(this.triggerSetValueCallbacks, this.props.debounce));
150
+ _define_property(this, "debouncedTriggerSetValueCallbacks", (0, _debounce.default)(this.triggerSetValueCallbacks, this.getDebounceDuration()));
150
151
  const initialValue = props.field.getValue();
151
152
  this.state = {
152
153
  isLocalValueChange: false,
@@ -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';
@@ -65,6 +65,7 @@ export class FieldConnector extends (_React_Component = React.Component) {
65
65
  _define_property(this, "unsubscribeErrors", null);
66
66
  _define_property(this, "unsubscribeDisabled", null);
67
67
  _define_property(this, "unsubscribeValue", null);
68
+ _define_property(this, "getDebounceDuration", ()=>'debounce' in this.props ? this.props.debounce : this.props.throttle);
68
69
  _define_property(this, "setValue", async (value)=>{
69
70
  if (this.props.isEmptyValue(value ?? null)) {
70
71
  this.setState({
@@ -75,7 +76,7 @@ export class FieldConnector extends (_React_Component = React.Component) {
75
76
  value
76
77
  });
77
78
  }
78
- if (this.props.debounce === 0) {
79
+ if (this.getDebounceDuration() === 0) {
79
80
  await this.triggerSetValueCallbacks(value);
80
81
  } else {
81
82
  await this.debouncedTriggerSetValueCallbacks(value);
@@ -90,7 +91,7 @@ export class FieldConnector extends (_React_Component = React.Component) {
90
91
  }
91
92
  });
92
93
  });
93
- _define_property(this, "debouncedTriggerSetValueCallbacks", debounce(this.triggerSetValueCallbacks, this.props.debounce));
94
+ _define_property(this, "debouncedTriggerSetValueCallbacks", debounce(this.triggerSetValueCallbacks, this.getDebounceDuration()));
94
95
  const initialValue = props.field.getValue();
95
96
  this.state = {
96
97
  isLocalValueChange: false,
@@ -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';
@@ -19,15 +19,19 @@ interface FieldConnectorState<ValueType> {
19
19
  disabled: boolean;
20
20
  errors: ValidationError[];
21
21
  }
22
- interface FieldConnectorProps<ValueType> {
22
+ type FieldConnectorProps<ValueType> = {
23
23
  field: FieldAPI;
24
24
  isInitiallyDisabled: boolean;
25
25
  isDisabled?: boolean;
26
26
  children: (state: FieldConnectorChildProps<ValueType>) => React.ReactNode;
27
27
  isEmptyValue: (value: ValueType | null) => boolean;
28
28
  isEqualValues: (value1: ValueType | Nullable, value2: ValueType | Nullable) => boolean;
29
+ } & ({
29
30
  debounce: number;
30
- }
31
+ } | {
32
+ /** @deprecated: Please use `debounce` instead */
33
+ throttle: number;
34
+ });
31
35
  export declare class FieldConnector<ValueType> extends React.Component<FieldConnectorProps<ValueType>, FieldConnectorState<ValueType>> {
32
36
  static defaultProps: {
33
37
  children: () => null;
@@ -39,6 +43,7 @@ export declare class FieldConnector<ValueType> extends React.Component<FieldConn
39
43
  unsubscribeErrors: Function | null;
40
44
  unsubscribeDisabled: Function | null;
41
45
  unsubscribeValue: Function | null;
46
+ getDebounceDuration: () => number;
42
47
  setValue: (value: ValueType | Nullable) => Promise<void>;
43
48
  triggerSetValueCallbacks: (value: ValueType | Nullable) => Promise<unknown>;
44
49
  debouncedTriggerSetValueCallbacks: import("lodash").DebouncedFunc<(value: ValueType | Nullable) => Promise<unknown>>;
@@ -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.1",
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": "60fd3c2f5a58f4d42886b5f952ce3cc1aec71833"
55
55
  }