@contentful/field-editor-shared 1.3.0 → 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,7 +9,7 @@ Object.defineProperty(exports, "FieldConnector", {
|
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
const _react = _interop_require_wildcard(require("react"));
|
|
12
|
-
const
|
|
12
|
+
const _debounce = _interop_require_default(require("lodash/debounce"));
|
|
13
13
|
const _isEqual = _interop_require_default(require("lodash/isEqual"));
|
|
14
14
|
function _define_property(obj, key, value) {
|
|
15
15
|
if (key in obj) {
|
|
@@ -129,9 +129,13 @@ class FieldConnector extends (_React_Component = _react.Component) {
|
|
|
129
129
|
value
|
|
130
130
|
});
|
|
131
131
|
}
|
|
132
|
-
|
|
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", (
|
|
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
|
-
}
|
|
143
|
-
|
|
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
|
-
|
|
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
|
-
|
|
70
|
+
debounce: 0
|
|
71
71
|
};
|
|
72
72
|
(0, _react1.render)(_react.createElement(_FieldConnector.FieldConnector, props));
|
|
73
73
|
let child = getChild();
|
|
@@ -12,7 +12,7 @@ function _define_property(obj, key, value) {
|
|
|
12
12
|
return obj;
|
|
13
13
|
}
|
|
14
14
|
import * as React from 'react';
|
|
15
|
-
import
|
|
15
|
+
import debounce from 'lodash/debounce';
|
|
16
16
|
import isEqual from 'lodash/isEqual';
|
|
17
17
|
var _React_Component;
|
|
18
18
|
export class FieldConnector extends (_React_Component = React.Component) {
|
|
@@ -75,9 +75,13 @@ export class FieldConnector extends (_React_Component = React.Component) {
|
|
|
75
75
|
value
|
|
76
76
|
});
|
|
77
77
|
}
|
|
78
|
-
|
|
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",
|
|
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
|
-
}
|
|
89
|
-
|
|
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
|
-
|
|
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
|
-
|
|
22
|
+
debounce: 0
|
|
23
23
|
};
|
|
24
24
|
render(React.createElement(FieldConnector, props));
|
|
25
25
|
let child = getChild();
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="lodash" />
|
|
1
2
|
import * as React from 'react';
|
|
2
3
|
import { FieldAPI, ValidationError } from '@contentful/app-sdk';
|
|
3
4
|
type Nullable = null | undefined;
|
|
@@ -25,21 +26,22 @@ interface FieldConnectorProps<ValueType> {
|
|
|
25
26
|
children: (state: FieldConnectorChildProps<ValueType>) => React.ReactNode;
|
|
26
27
|
isEmptyValue: (value: ValueType | null) => boolean;
|
|
27
28
|
isEqualValues: (value1: ValueType | Nullable, value2: ValueType | Nullable) => boolean;
|
|
28
|
-
|
|
29
|
+
debounce: number;
|
|
29
30
|
}
|
|
30
31
|
export declare class FieldConnector<ValueType> extends React.Component<FieldConnectorProps<ValueType>, FieldConnectorState<ValueType>> {
|
|
31
32
|
static defaultProps: {
|
|
32
33
|
children: () => null;
|
|
33
34
|
isEmptyValue: (value: any | Nullable) => boolean;
|
|
34
35
|
isEqualValues: (value1: any | Nullable, value2: any | Nullable) => boolean;
|
|
35
|
-
|
|
36
|
+
debounce: number;
|
|
36
37
|
};
|
|
37
38
|
constructor(props: FieldConnectorProps<ValueType>);
|
|
38
39
|
unsubscribeErrors: Function | null;
|
|
39
40
|
unsubscribeDisabled: Function | null;
|
|
40
41
|
unsubscribeValue: Function | null;
|
|
41
42
|
setValue: (value: ValueType | Nullable) => Promise<void>;
|
|
42
|
-
triggerSetValueCallbacks:
|
|
43
|
+
triggerSetValueCallbacks: (value: ValueType | Nullable) => Promise<unknown>;
|
|
44
|
+
debouncedTriggerSetValueCallbacks: import("lodash").DebouncedFunc<(value: ValueType | Nullable) => Promise<unknown>>;
|
|
43
45
|
componentDidMount(): void;
|
|
44
46
|
componentWillUnmount(): void;
|
|
45
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
|
+
"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",
|
|
@@ -36,18 +36,17 @@
|
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@contentful/app-sdk": "^4.2.0",
|
|
39
|
-
"@contentful/field-editor-test-utils": "^1.4.
|
|
39
|
+
"@contentful/field-editor-test-utils": "^1.4.1"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@contentful/f36-note": "^4.2.8",
|
|
43
43
|
"@contentful/f36-tokens": "^4.0.0",
|
|
44
44
|
"emotion": "^10.0.17",
|
|
45
|
-
"lodash": "^4.17.15"
|
|
46
|
-
"lodash-es": "^4.17.21"
|
|
45
|
+
"lodash": "^4.17.15"
|
|
47
46
|
},
|
|
48
47
|
"peerDependencies": {
|
|
49
48
|
"@contentful/app-sdk": "^4.2.0",
|
|
50
49
|
"react": ">=16.8.0"
|
|
51
50
|
},
|
|
52
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "2db95226af0417c42aae8d1be85796fc8774e283"
|
|
53
52
|
}
|