@contentful/field-editor-shared 1.3.1 → 1.4.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.
@@ -9,8 +9,8 @@ Object.defineProperty(exports, "FieldConnector", {
9
9
  }
10
10
  });
11
11
  const _react = _interop_require_wildcard(require("react"));
12
+ const _debounce = _interop_require_default(require("lodash/debounce"));
12
13
  const _isEqual = _interop_require_default(require("lodash/isEqual"));
13
- const _throttle = _interop_require_default(require("lodash/throttle"));
14
14
  function _define_property(obj, key, value) {
15
15
  if (key in obj) {
16
16
  Object.defineProperty(obj, key, {
@@ -129,9 +129,13 @@ class FieldConnector extends (_React_Component = _react.Component) {
129
129
  value
130
130
  });
131
131
  }
132
- await this.triggerSetValueCallbacks(value);
132
+ if (this.props.debounce === 0) {
133
+ await this.triggerSetValueCallbacks(value);
134
+ } else {
135
+ await this.debouncedTriggerSetValueCallbacks(value);
136
+ }
133
137
  });
134
- _define_property(this, "triggerSetValueCallbacks", (0, _throttle.default)((value)=>{
138
+ _define_property(this, "triggerSetValueCallbacks", (value)=>{
135
139
  return new Promise((resolve, reject)=>{
136
140
  if (this.props.isEmptyValue(value ?? null)) {
137
141
  this.props.field.removeValue().then(resolve).catch(reject);
@@ -139,9 +143,8 @@ class FieldConnector extends (_React_Component = _react.Component) {
139
143
  this.props.field.setValue(value).then(resolve).catch(reject);
140
144
  }
141
145
  });
142
- }, this.props.throttle, {
143
- leading: this.props.throttle === 0
144
- }));
146
+ });
147
+ _define_property(this, "debouncedTriggerSetValueCallbacks", (0, _debounce.default)(this.triggerSetValueCallbacks, this.props.debounce));
145
148
  const initialValue = props.field.getValue();
146
149
  this.state = {
147
150
  isLocalValueChange: false,
@@ -163,5 +166,5 @@ _define_property(FieldConnector, "defaultProps", {
163
166
  isEqualValues: (value1, value2)=>{
164
167
  return (0, _isEqual.default)(value1, value2);
165
168
  },
166
- throttle: 300
169
+ debounce: 300
167
170
  });
@@ -67,7 +67,7 @@ it('does not rerender with outdated value after calling setValue', ()=>{
67
67
  isInitiallyDisabled: false,
68
68
  children: jest.fn().mockImplementation(()=>null),
69
69
  field,
70
- throttle: 0
70
+ debounce: 0
71
71
  };
72
72
  (0, _react1.render)(_react.createElement(_FieldConnector.FieldConnector, props));
73
73
  let child = getChild();
@@ -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 debounce from 'lodash/debounce';
15
16
  import isEqual from 'lodash/isEqual';
16
- import throttle from 'lodash/throttle';
17
17
  var _React_Component;
18
18
  export class FieldConnector extends (_React_Component = React.Component) {
19
19
  componentDidMount() {
@@ -75,9 +75,13 @@ export class FieldConnector extends (_React_Component = React.Component) {
75
75
  value
76
76
  });
77
77
  }
78
- await this.triggerSetValueCallbacks(value);
78
+ if (this.props.debounce === 0) {
79
+ await this.triggerSetValueCallbacks(value);
80
+ } else {
81
+ await this.debouncedTriggerSetValueCallbacks(value);
82
+ }
79
83
  });
80
- _define_property(this, "triggerSetValueCallbacks", throttle((value)=>{
84
+ _define_property(this, "triggerSetValueCallbacks", (value)=>{
81
85
  return new Promise((resolve, reject)=>{
82
86
  if (this.props.isEmptyValue(value ?? null)) {
83
87
  this.props.field.removeValue().then(resolve).catch(reject);
@@ -85,9 +89,8 @@ export class FieldConnector extends (_React_Component = React.Component) {
85
89
  this.props.field.setValue(value).then(resolve).catch(reject);
86
90
  }
87
91
  });
88
- }, this.props.throttle, {
89
- leading: this.props.throttle === 0
90
- }));
92
+ });
93
+ _define_property(this, "debouncedTriggerSetValueCallbacks", debounce(this.triggerSetValueCallbacks, this.props.debounce));
91
94
  const initialValue = props.field.getValue();
92
95
  this.state = {
93
96
  isLocalValueChange: false,
@@ -109,5 +112,5 @@ _define_property(FieldConnector, "defaultProps", {
109
112
  isEqualValues: (value1, value2)=>{
110
113
  return isEqual(value1, value2);
111
114
  },
112
- throttle: 300
115
+ debounce: 300
113
116
  });
@@ -19,7 +19,7 @@ it('does not rerender with outdated value after calling setValue', ()=>{
19
19
  isInitiallyDisabled: false,
20
20
  children: jest.fn().mockImplementation(()=>null),
21
21
  field,
22
- throttle: 0
22
+ debounce: 0
23
23
  };
24
24
  render(React.createElement(FieldConnector, props));
25
25
  let child = getChild();
@@ -26,21 +26,22 @@ interface FieldConnectorProps<ValueType> {
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
- throttle: number;
29
+ debounce: number;
30
30
  }
31
31
  export declare class FieldConnector<ValueType> extends React.Component<FieldConnectorProps<ValueType>, FieldConnectorState<ValueType>> {
32
32
  static defaultProps: {
33
33
  children: () => null;
34
34
  isEmptyValue: (value: any | Nullable) => boolean;
35
35
  isEqualValues: (value1: any | Nullable, value2: any | Nullable) => boolean;
36
- throttle: number;
36
+ debounce: number;
37
37
  };
38
38
  constructor(props: FieldConnectorProps<ValueType>);
39
39
  unsubscribeErrors: Function | null;
40
40
  unsubscribeDisabled: Function | null;
41
41
  unsubscribeValue: Function | null;
42
42
  setValue: (value: ValueType | Nullable) => Promise<void>;
43
- triggerSetValueCallbacks: import("lodash").DebouncedFunc<(value: ValueType | Nullable) => Promise<unknown>>;
43
+ triggerSetValueCallbacks: (value: ValueType | Nullable) => Promise<unknown>;
44
+ debouncedTriggerSetValueCallbacks: import("lodash").DebouncedFunc<(value: ValueType | Nullable) => Promise<unknown>>;
44
45
  componentDidMount(): void;
45
46
  componentWillUnmount(): void;
46
47
  render(): React.ReactNode;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/field-editor-shared",
3
- "version": "1.3.1",
3
+ "version": "1.4.0",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -48,5 +48,5 @@
48
48
  "@contentful/app-sdk": "^4.2.0",
49
49
  "react": ">=16.8.0"
50
50
  },
51
- "gitHead": "ca904b19ca794a2c40d82e1f7ede9e0be3560f22"
51
+ "gitHead": "2db95226af0417c42aae8d1be85796fc8774e283"
52
52
  }