@contentful/field-editor-shared 1.5.0 → 1.5.2

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,
@@ -166,37 +166,18 @@ function getEntryStatus(sys, localeCodes) {
166
166
  }
167
167
  if (sys.deletedVersion) {
168
168
  return 'deleted';
169
- } else if (sys.archivedVersion) {
169
+ }
170
+ if (sys.archivedVersion) {
170
171
  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;
191
- } else if (sys.publishedVersion) {
172
+ }
173
+ if (sys.publishedVersion) {
192
174
  if (sys.version > sys.publishedVersion + 1) {
193
175
  return 'changed';
194
176
  } else {
195
177
  return 'published';
196
178
  }
197
- } else {
198
- return 'draft';
199
179
  }
180
+ return 'draft';
200
181
  }
201
182
  const getEntryImage = async ({ entry, contentType, localeCode }, getAsset)=>{
202
183
  if (!contentType) {
@@ -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,
@@ -122,37 +122,18 @@ export function getEntryStatus(sys, localeCodes) {
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
- 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;
147
- } else if (sys.publishedVersion) {
128
+ }
129
+ if (sys.publishedVersion) {
148
130
  if (sys.version > sys.publishedVersion + 1) {
149
131
  return 'changed';
150
132
  } else {
151
133
  return 'published';
152
134
  }
153
- } else {
154
- return 'draft';
155
135
  }
136
+ return 'draft';
156
137
  }
157
138
  export const getEntryImage = async ({ entry, contentType, localeCode }, getAsset)=>{
158
139
  if (!contentType) {
@@ -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>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/field-editor-shared",
3
- "version": "1.5.0",
3
+ "version": "1.5.2",
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": "843655f104af6fb8c116869d59cd9f20e6f1ab14"
54
+ "gitHead": "4ec14a5b5611b2bfa17bfa10b4ac5942c2c25406"
55
55
  }