@contentful/field-editor-shared 1.2.0 → 1.3.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.
- package/dist/cjs/CharCounter.js +75 -0
- package/dist/cjs/CharValidation.js +60 -0
- package/dist/cjs/FieldConnector.js +167 -0
- package/dist/cjs/FieldConnector.test.js +81 -0
- package/dist/cjs/ModalDialogLauncher.js +132 -0
- package/dist/cjs/PredefinedValuesError.js +57 -0
- package/dist/cjs/index.js +155 -0
- package/dist/cjs/types.js +4 -0
- package/dist/cjs/typesEntity.js +31 -0
- package/dist/cjs/utils/constraints.js +63 -0
- package/dist/cjs/utils/entityHelpers.js +214 -0
- package/dist/cjs/utils/isValidImage.js +26 -0
- package/dist/cjs/utils/shortenStorageUnit.js +55 -0
- package/dist/esm/CharCounter.js +21 -0
- package/dist/esm/CharValidation.js +11 -0
- package/dist/esm/FieldConnector.js +113 -0
- package/dist/esm/FieldConnector.test.js +33 -0
- package/dist/esm/ModalDialogLauncher.js +67 -0
- package/dist/esm/PredefinedValuesError.js +8 -0
- package/dist/esm/index.js +14 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/typesEntity.js +1 -0
- package/dist/esm/utils/constraints.js +40 -0
- package/dist/esm/utils/entityHelpers.js +170 -0
- package/dist/esm/utils/isValidImage.js +16 -0
- package/dist/esm/utils/shortenStorageUnit.js +37 -0
- package/dist/types/CharCounter.d.ts +7 -0
- package/dist/{CharValidation.d.ts → types/CharValidation.d.ts} +7 -7
- package/dist/{FieldConnector.d.ts → types/FieldConnector.d.ts} +47 -48
- package/dist/types/FieldConnector.test.d.ts +1 -0
- package/dist/{ModalDialogLauncher.d.ts → types/ModalDialogLauncher.d.ts} +13 -13
- package/dist/types/PredefinedValuesError.d.ts +2 -0
- package/dist/{index.d.ts → types/index.d.ts} +15 -15
- package/dist/{types.d.ts → types/types.d.ts} +11 -11
- package/dist/{typesEntity.d.ts → types/typesEntity.d.ts} +9 -9
- package/dist/{utils → types/utils}/constraints.d.ts +3 -3
- package/dist/{utils → types/utils}/entityHelpers.d.ts +68 -68
- package/dist/{utils → types/utils}/isValidImage.d.ts +5 -5
- package/dist/{utils → types/utils}/shortenStorageUnit.d.ts +17 -17
- package/package.json +26 -11
- package/CHANGELOG.md +0 -196
- package/dist/CharCounter.d.ts +0 -7
- package/dist/PredefinedValuesError.d.ts +0 -2
- package/dist/field-editor-shared.cjs.development.js +0 -634
- package/dist/field-editor-shared.cjs.development.js.map +0 -1
- package/dist/field-editor-shared.cjs.production.min.js +0 -2
- package/dist/field-editor-shared.cjs.production.min.js.map +0 -1
- package/dist/field-editor-shared.esm.js +0 -619
- package/dist/field-editor-shared.esm.js.map +0 -1
- package/dist/index.js +0 -8
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "CharCounter", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return CharCounter;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _react = _interop_require_wildcard(require("react"));
|
|
12
|
+
const _f36tokens = _interop_require_default(require("@contentful/f36-tokens"));
|
|
13
|
+
const _emotion = require("emotion");
|
|
14
|
+
function _interop_require_default(obj) {
|
|
15
|
+
return obj && obj.__esModule ? obj : {
|
|
16
|
+
default: obj
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
20
|
+
if (typeof WeakMap !== "function") return null;
|
|
21
|
+
var cacheBabelInterop = new WeakMap();
|
|
22
|
+
var cacheNodeInterop = new WeakMap();
|
|
23
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
24
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
25
|
+
})(nodeInterop);
|
|
26
|
+
}
|
|
27
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
28
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
29
|
+
return obj;
|
|
30
|
+
}
|
|
31
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
32
|
+
return {
|
|
33
|
+
default: obj
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
37
|
+
if (cache && cache.has(obj)) {
|
|
38
|
+
return cache.get(obj);
|
|
39
|
+
}
|
|
40
|
+
var newObj = {};
|
|
41
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
42
|
+
for(var key in obj){
|
|
43
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
44
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
45
|
+
if (desc && (desc.get || desc.set)) {
|
|
46
|
+
Object.defineProperty(newObj, key, desc);
|
|
47
|
+
} else {
|
|
48
|
+
newObj[key] = obj[key];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
newObj.default = obj;
|
|
53
|
+
if (cache) {
|
|
54
|
+
cache.set(obj, newObj);
|
|
55
|
+
}
|
|
56
|
+
return newObj;
|
|
57
|
+
}
|
|
58
|
+
const styles = {
|
|
59
|
+
invalid: (0, _emotion.css)({
|
|
60
|
+
color: _f36tokens.default.red600
|
|
61
|
+
})
|
|
62
|
+
};
|
|
63
|
+
function CharCounter(props) {
|
|
64
|
+
let count = 0;
|
|
65
|
+
if (props.value) {
|
|
66
|
+
count = props.value.length;
|
|
67
|
+
}
|
|
68
|
+
const valid = count === 0 || props.checkConstraint(count);
|
|
69
|
+
return _react.createElement("span", {
|
|
70
|
+
"data-status-code": valid ? null : 'invalid-size',
|
|
71
|
+
className: (0, _emotion.cx)({
|
|
72
|
+
[styles.invalid]: !valid
|
|
73
|
+
})
|
|
74
|
+
}, count, " characters");
|
|
75
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "CharValidation", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return CharValidation;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _react = _interop_require_wildcard(require("react"));
|
|
12
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
13
|
+
if (typeof WeakMap !== "function") return null;
|
|
14
|
+
var cacheBabelInterop = new WeakMap();
|
|
15
|
+
var cacheNodeInterop = new WeakMap();
|
|
16
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
17
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
18
|
+
})(nodeInterop);
|
|
19
|
+
}
|
|
20
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
21
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
22
|
+
return obj;
|
|
23
|
+
}
|
|
24
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
25
|
+
return {
|
|
26
|
+
default: obj
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
30
|
+
if (cache && cache.has(obj)) {
|
|
31
|
+
return cache.get(obj);
|
|
32
|
+
}
|
|
33
|
+
var newObj = {};
|
|
34
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
35
|
+
for(var key in obj){
|
|
36
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
37
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
38
|
+
if (desc && (desc.get || desc.set)) {
|
|
39
|
+
Object.defineProperty(newObj, key, desc);
|
|
40
|
+
} else {
|
|
41
|
+
newObj[key] = obj[key];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
newObj.default = obj;
|
|
46
|
+
if (cache) {
|
|
47
|
+
cache.set(obj, newObj);
|
|
48
|
+
}
|
|
49
|
+
return newObj;
|
|
50
|
+
}
|
|
51
|
+
function CharValidation(props) {
|
|
52
|
+
const { constraints } = props;
|
|
53
|
+
if (constraints.type === 'max') {
|
|
54
|
+
return _react.createElement("span", null, "Maximum ", constraints.max, " characters");
|
|
55
|
+
} else if (constraints.type === 'min') {
|
|
56
|
+
return _react.createElement("span", null, "Requires at least ", constraints.min, " characters");
|
|
57
|
+
} else {
|
|
58
|
+
return _react.createElement("span", null, "Requires between ", constraints.min, " and ", constraints.max, " characters");
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "FieldConnector", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return FieldConnector;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _react = _interop_require_wildcard(require("react"));
|
|
12
|
+
const _lodashes = require("lodash-es");
|
|
13
|
+
const _isEqual = _interop_require_default(require("lodash/isEqual"));
|
|
14
|
+
function _define_property(obj, key, value) {
|
|
15
|
+
if (key in obj) {
|
|
16
|
+
Object.defineProperty(obj, key, {
|
|
17
|
+
value: value,
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true
|
|
21
|
+
});
|
|
22
|
+
} else {
|
|
23
|
+
obj[key] = value;
|
|
24
|
+
}
|
|
25
|
+
return obj;
|
|
26
|
+
}
|
|
27
|
+
function _interop_require_default(obj) {
|
|
28
|
+
return obj && obj.__esModule ? obj : {
|
|
29
|
+
default: obj
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
33
|
+
if (typeof WeakMap !== "function") return null;
|
|
34
|
+
var cacheBabelInterop = new WeakMap();
|
|
35
|
+
var cacheNodeInterop = new WeakMap();
|
|
36
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
37
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
38
|
+
})(nodeInterop);
|
|
39
|
+
}
|
|
40
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
41
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
42
|
+
return obj;
|
|
43
|
+
}
|
|
44
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
45
|
+
return {
|
|
46
|
+
default: obj
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
50
|
+
if (cache && cache.has(obj)) {
|
|
51
|
+
return cache.get(obj);
|
|
52
|
+
}
|
|
53
|
+
var newObj = {};
|
|
54
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
55
|
+
for(var key in obj){
|
|
56
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
57
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
58
|
+
if (desc && (desc.get || desc.set)) {
|
|
59
|
+
Object.defineProperty(newObj, key, desc);
|
|
60
|
+
} else {
|
|
61
|
+
newObj[key] = obj[key];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
newObj.default = obj;
|
|
66
|
+
if (cache) {
|
|
67
|
+
cache.set(obj, newObj);
|
|
68
|
+
}
|
|
69
|
+
return newObj;
|
|
70
|
+
}
|
|
71
|
+
var _React_Component;
|
|
72
|
+
class FieldConnector extends (_React_Component = _react.Component) {
|
|
73
|
+
componentDidMount() {
|
|
74
|
+
const { field } = this.props;
|
|
75
|
+
this.unsubscribeErrors = field.onSchemaErrorsChanged((errors)=>{
|
|
76
|
+
this.setState({
|
|
77
|
+
errors: errors || []
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
this.unsubscribeDisabled = field.onIsDisabledChanged((disabled)=>{
|
|
81
|
+
this.setState({
|
|
82
|
+
disabled
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
this.unsubscribeValue = field.onValueChanged((value)=>{
|
|
86
|
+
this.setState((currentState)=>{
|
|
87
|
+
const isLocalValueChange = this.props.isEqualValues(value, currentState.value);
|
|
88
|
+
const lastRemoteValue = isLocalValueChange ? currentState.lastRemoteValue : value;
|
|
89
|
+
const externalReset = currentState.externalReset + (isLocalValueChange ? 0 : 1);
|
|
90
|
+
return {
|
|
91
|
+
value,
|
|
92
|
+
lastRemoteValue,
|
|
93
|
+
isLocalValueChange,
|
|
94
|
+
externalReset
|
|
95
|
+
};
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
componentWillUnmount() {
|
|
100
|
+
if (typeof this.unsubscribeErrors === 'function') {
|
|
101
|
+
this.unsubscribeErrors();
|
|
102
|
+
}
|
|
103
|
+
if (typeof this.unsubscribeDisabled === 'function') {
|
|
104
|
+
this.unsubscribeDisabled();
|
|
105
|
+
}
|
|
106
|
+
if (typeof this.unsubscribeValue === 'function') {
|
|
107
|
+
this.unsubscribeValue();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
render() {
|
|
111
|
+
return this.props.children({
|
|
112
|
+
...this.state,
|
|
113
|
+
setValue: this.setValue,
|
|
114
|
+
disabled: this.props.isDisabled || this.state.disabled
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
constructor(props){
|
|
118
|
+
super(props);
|
|
119
|
+
_define_property(this, "unsubscribeErrors", null);
|
|
120
|
+
_define_property(this, "unsubscribeDisabled", null);
|
|
121
|
+
_define_property(this, "unsubscribeValue", null);
|
|
122
|
+
_define_property(this, "setValue", async (value)=>{
|
|
123
|
+
if (this.props.isEmptyValue(value ?? null)) {
|
|
124
|
+
this.setState({
|
|
125
|
+
value: undefined
|
|
126
|
+
});
|
|
127
|
+
} else {
|
|
128
|
+
this.setState({
|
|
129
|
+
value
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
await this.triggerSetValueCallbacks(value);
|
|
133
|
+
});
|
|
134
|
+
_define_property(this, "triggerSetValueCallbacks", (0, _lodashes.throttle)((value)=>{
|
|
135
|
+
return new Promise((resolve, reject)=>{
|
|
136
|
+
if (this.props.isEmptyValue(value ?? null)) {
|
|
137
|
+
this.props.field.removeValue().then(resolve).catch(reject);
|
|
138
|
+
} else {
|
|
139
|
+
this.props.field.setValue(value).then(resolve).catch(reject);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
}, this.props.throttle, {
|
|
143
|
+
leading: this.props.throttle === 0
|
|
144
|
+
}));
|
|
145
|
+
const initialValue = props.field.getValue();
|
|
146
|
+
this.state = {
|
|
147
|
+
isLocalValueChange: false,
|
|
148
|
+
externalReset: 0,
|
|
149
|
+
value: initialValue,
|
|
150
|
+
lastRemoteValue: initialValue,
|
|
151
|
+
disabled: props.isInitiallyDisabled ?? false,
|
|
152
|
+
errors: []
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
_define_property(FieldConnector, "defaultProps", {
|
|
157
|
+
children: ()=>{
|
|
158
|
+
return null;
|
|
159
|
+
},
|
|
160
|
+
isEmptyValue: (value)=>{
|
|
161
|
+
return value === null || value === '';
|
|
162
|
+
},
|
|
163
|
+
isEqualValues: (value1, value2)=>{
|
|
164
|
+
return (0, _isEqual.default)(value1, value2);
|
|
165
|
+
},
|
|
166
|
+
throttle: 300
|
|
167
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
const _react = _interop_require_wildcard(require("react"));
|
|
6
|
+
const _fieldeditortestutils = require("@contentful/field-editor-test-utils");
|
|
7
|
+
const _react1 = require("@testing-library/react");
|
|
8
|
+
const _noop = _interop_require_default(require("lodash/noop"));
|
|
9
|
+
const _FieldConnector = require("./FieldConnector");
|
|
10
|
+
function _interop_require_default(obj) {
|
|
11
|
+
return obj && obj.__esModule ? obj : {
|
|
12
|
+
default: obj
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
16
|
+
if (typeof WeakMap !== "function") return null;
|
|
17
|
+
var cacheBabelInterop = new WeakMap();
|
|
18
|
+
var cacheNodeInterop = new WeakMap();
|
|
19
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
20
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
21
|
+
})(nodeInterop);
|
|
22
|
+
}
|
|
23
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
24
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
25
|
+
return obj;
|
|
26
|
+
}
|
|
27
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
28
|
+
return {
|
|
29
|
+
default: obj
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
33
|
+
if (cache && cache.has(obj)) {
|
|
34
|
+
return cache.get(obj);
|
|
35
|
+
}
|
|
36
|
+
var newObj = {};
|
|
37
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
38
|
+
for(var key in obj){
|
|
39
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
40
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
41
|
+
if (desc && (desc.get || desc.set)) {
|
|
42
|
+
Object.defineProperty(newObj, key, desc);
|
|
43
|
+
} else {
|
|
44
|
+
newObj[key] = obj[key];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
newObj.default = obj;
|
|
49
|
+
if (cache) {
|
|
50
|
+
cache.set(obj, newObj);
|
|
51
|
+
}
|
|
52
|
+
return newObj;
|
|
53
|
+
}
|
|
54
|
+
it('does not rerender with outdated value after calling setValue', ()=>{
|
|
55
|
+
function getChild() {
|
|
56
|
+
return props.children.mock.calls[props.children.mock.calls.length - 1][0];
|
|
57
|
+
}
|
|
58
|
+
const onSchemaErrorsChanged = jest.fn();
|
|
59
|
+
const [field] = (0, _fieldeditortestutils.createFakeFieldAPI)((field)=>{
|
|
60
|
+
return {
|
|
61
|
+
...field,
|
|
62
|
+
setValue: ()=>new Promise(_noop.default),
|
|
63
|
+
onSchemaErrorsChanged
|
|
64
|
+
};
|
|
65
|
+
}, 'initial value');
|
|
66
|
+
const props = {
|
|
67
|
+
isInitiallyDisabled: false,
|
|
68
|
+
children: jest.fn().mockImplementation(()=>null),
|
|
69
|
+
field,
|
|
70
|
+
throttle: 0
|
|
71
|
+
};
|
|
72
|
+
(0, _react1.render)(_react.createElement(_FieldConnector.FieldConnector, props));
|
|
73
|
+
let child = getChild();
|
|
74
|
+
expect(child.value).toBe('initial value');
|
|
75
|
+
const initialRenderCount = props.children.mock.calls.length;
|
|
76
|
+
child.setValue('new value');
|
|
77
|
+
onSchemaErrorsChanged.mock.calls.forEach(([cb])=>cb([]));
|
|
78
|
+
child = getChild();
|
|
79
|
+
expect(child.value).toBe('new value');
|
|
80
|
+
expect(props.children.mock.calls.length).toBeGreaterThan(initialRenderCount);
|
|
81
|
+
});
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
open: function() {
|
|
13
|
+
return open;
|
|
14
|
+
},
|
|
15
|
+
openDialog: function() {
|
|
16
|
+
return openDialog;
|
|
17
|
+
},
|
|
18
|
+
default: function() {
|
|
19
|
+
return _default;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const _react = _interop_require_wildcard(require("react"));
|
|
23
|
+
const _reactdom = _interop_require_default(require("react-dom"));
|
|
24
|
+
const _f36components = require("@contentful/f36-components");
|
|
25
|
+
const _isNumber = _interop_require_default(require("lodash/isNumber"));
|
|
26
|
+
function _interop_require_default(obj) {
|
|
27
|
+
return obj && obj.__esModule ? obj : {
|
|
28
|
+
default: obj
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
32
|
+
if (typeof WeakMap !== "function") return null;
|
|
33
|
+
var cacheBabelInterop = new WeakMap();
|
|
34
|
+
var cacheNodeInterop = new WeakMap();
|
|
35
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
36
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
37
|
+
})(nodeInterop);
|
|
38
|
+
}
|
|
39
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
40
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
41
|
+
return obj;
|
|
42
|
+
}
|
|
43
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
44
|
+
return {
|
|
45
|
+
default: obj
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
49
|
+
if (cache && cache.has(obj)) {
|
|
50
|
+
return cache.get(obj);
|
|
51
|
+
}
|
|
52
|
+
var newObj = {};
|
|
53
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
54
|
+
for(var key in obj){
|
|
55
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
56
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
57
|
+
if (desc && (desc.get || desc.set)) {
|
|
58
|
+
Object.defineProperty(newObj, key, desc);
|
|
59
|
+
} else {
|
|
60
|
+
newObj[key] = obj[key];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
newObj.default = obj;
|
|
65
|
+
if (cache) {
|
|
66
|
+
cache.set(obj, newObj);
|
|
67
|
+
}
|
|
68
|
+
return newObj;
|
|
69
|
+
}
|
|
70
|
+
function open(componentRenderer) {
|
|
71
|
+
let rootDom = null;
|
|
72
|
+
const getRoot = ()=>{
|
|
73
|
+
if (rootDom === null) {
|
|
74
|
+
rootDom = document.createElement('div');
|
|
75
|
+
rootDom.setAttribute('id', 'field-editor-modal-root');
|
|
76
|
+
document.body.appendChild(rootDom);
|
|
77
|
+
}
|
|
78
|
+
return rootDom;
|
|
79
|
+
};
|
|
80
|
+
return new Promise((resolve)=>{
|
|
81
|
+
let currentConfig = {
|
|
82
|
+
onClose,
|
|
83
|
+
isShown: true
|
|
84
|
+
};
|
|
85
|
+
function render({ onClose , isShown }) {
|
|
86
|
+
_reactdom.default.render(componentRenderer({
|
|
87
|
+
onClose,
|
|
88
|
+
isShown
|
|
89
|
+
}), getRoot());
|
|
90
|
+
}
|
|
91
|
+
function onClose(...args) {
|
|
92
|
+
currentConfig = {
|
|
93
|
+
...currentConfig,
|
|
94
|
+
isShown: false
|
|
95
|
+
};
|
|
96
|
+
render(currentConfig);
|
|
97
|
+
resolve(...args);
|
|
98
|
+
getRoot().remove();
|
|
99
|
+
}
|
|
100
|
+
render(currentConfig);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
function openDialog(options, Component) {
|
|
104
|
+
const key = Date.now();
|
|
105
|
+
const size = (0, _isNumber.default)(options.width) ? `${options.width}px` : options.width;
|
|
106
|
+
return open(({ isShown , onClose })=>{
|
|
107
|
+
const onCloseHandler = ()=>onClose();
|
|
108
|
+
return _react.createElement(_f36components.Modal, {
|
|
109
|
+
key: key,
|
|
110
|
+
shouldCloseOnOverlayClick: options.shouldCloseOnOverlayClick || false,
|
|
111
|
+
shouldCloseOnEscapePress: options.shouldCloseOnEscapePress || false,
|
|
112
|
+
allowHeightOverflow: options.allowHeightOverflow || false,
|
|
113
|
+
position: options.position || 'center',
|
|
114
|
+
isShown: isShown,
|
|
115
|
+
onClose: onCloseHandler,
|
|
116
|
+
size: size || '700px'
|
|
117
|
+
}, ()=>_react.createElement(_react.Fragment, null, options.title && _react.createElement(_f36components.ModalHeader, {
|
|
118
|
+
testId: "dialog-title",
|
|
119
|
+
title: options.title,
|
|
120
|
+
onClose: onCloseHandler
|
|
121
|
+
}), _react.createElement("div", {
|
|
122
|
+
style: {
|
|
123
|
+
minHeight: options.minHeight || 'auto'
|
|
124
|
+
}
|
|
125
|
+
}, _react.createElement(Component, {
|
|
126
|
+
onClose: onClose
|
|
127
|
+
}))));
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
const _default = {
|
|
131
|
+
openDialog
|
|
132
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "PredefinedValuesError", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return PredefinedValuesError;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _react = _interop_require_wildcard(require("react"));
|
|
12
|
+
const _f36note = require("@contentful/f36-note");
|
|
13
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
14
|
+
if (typeof WeakMap !== "function") return null;
|
|
15
|
+
var cacheBabelInterop = new WeakMap();
|
|
16
|
+
var cacheNodeInterop = new WeakMap();
|
|
17
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
18
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
19
|
+
})(nodeInterop);
|
|
20
|
+
}
|
|
21
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
22
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
23
|
+
return obj;
|
|
24
|
+
}
|
|
25
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
26
|
+
return {
|
|
27
|
+
default: obj
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
31
|
+
if (cache && cache.has(obj)) {
|
|
32
|
+
return cache.get(obj);
|
|
33
|
+
}
|
|
34
|
+
var newObj = {};
|
|
35
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
36
|
+
for(var key in obj){
|
|
37
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
38
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
39
|
+
if (desc && (desc.get || desc.set)) {
|
|
40
|
+
Object.defineProperty(newObj, key, desc);
|
|
41
|
+
} else {
|
|
42
|
+
newObj[key] = obj[key];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
newObj.default = obj;
|
|
47
|
+
if (cache) {
|
|
48
|
+
cache.set(obj, newObj);
|
|
49
|
+
}
|
|
50
|
+
return newObj;
|
|
51
|
+
}
|
|
52
|
+
function PredefinedValuesError() {
|
|
53
|
+
return _react.createElement(_f36note.Note, {
|
|
54
|
+
variant: "warning",
|
|
55
|
+
testId: "predefined-values-warning"
|
|
56
|
+
}, "The widget failed to initialize. You can fix the problem by providing predefined values under the validations tab in the field settings.");
|
|
57
|
+
}
|