decap-cms-widget-object 3.3.0 → 3.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.
- package/CHANGELOG.md +10 -0
- package/dist/decap-cms-widget-object.js +3 -3
- package/dist/decap-cms-widget-object.js.map +1 -1
- package/dist/esm/ObjectControl.js +72 -69
- package/dist/esm/index.js +4 -8
- package/package.json +3 -3
- package/src/ObjectControl.js +11 -1
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
2
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
3
|
-
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
4
1
|
import React from 'react';
|
|
5
2
|
import PropTypes from 'prop-types';
|
|
6
3
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
@@ -24,54 +21,44 @@ const styleStrings = {
|
|
|
24
21
|
`
|
|
25
22
|
};
|
|
26
23
|
export default class ObjectControl extends React.Component {
|
|
24
|
+
childRefs = {};
|
|
25
|
+
processControlRef = ref => {
|
|
26
|
+
if (!ref) return;
|
|
27
|
+
const name = ref.props.field.get('name');
|
|
28
|
+
this.childRefs[name] = ref;
|
|
29
|
+
this.props.controlRef?.(ref);
|
|
30
|
+
};
|
|
31
|
+
static propTypes = {
|
|
32
|
+
onChangeObject: PropTypes.func.isRequired,
|
|
33
|
+
onValidateObject: PropTypes.func,
|
|
34
|
+
value: PropTypes.oneOfType([PropTypes.node, PropTypes.object, PropTypes.bool]),
|
|
35
|
+
field: PropTypes.object,
|
|
36
|
+
forID: PropTypes.string,
|
|
37
|
+
classNameWrapper: PropTypes.string.isRequired,
|
|
38
|
+
forList: PropTypes.bool,
|
|
39
|
+
controlRef: PropTypes.func,
|
|
40
|
+
editorControl: PropTypes.elementType.isRequired,
|
|
41
|
+
resolveWidget: PropTypes.func.isRequired,
|
|
42
|
+
clearFieldErrors: PropTypes.func.isRequired,
|
|
43
|
+
fieldsErrors: ImmutablePropTypes.map,
|
|
44
|
+
hasError: PropTypes.bool,
|
|
45
|
+
t: PropTypes.func,
|
|
46
|
+
locale: PropTypes.string,
|
|
47
|
+
collapsed: PropTypes.bool
|
|
48
|
+
};
|
|
49
|
+
static defaultProps = {
|
|
50
|
+
value: Map()
|
|
51
|
+
};
|
|
27
52
|
constructor(props) {
|
|
28
53
|
super(props);
|
|
29
|
-
_defineProperty(this, "childRefs", {});
|
|
30
|
-
_defineProperty(this, "processControlRef", ref => {
|
|
31
|
-
var _this$props$controlRe, _this$props;
|
|
32
|
-
if (!ref) return;
|
|
33
|
-
const name = ref.props.field.get('name');
|
|
34
|
-
this.childRefs[name] = ref;
|
|
35
|
-
(_this$props$controlRe = (_this$props = this.props).controlRef) === null || _this$props$controlRe === void 0 ? void 0 : _this$props$controlRe.call(_this$props, ref);
|
|
36
|
-
});
|
|
37
|
-
_defineProperty(this, "validate", () => {
|
|
38
|
-
const {
|
|
39
|
-
field
|
|
40
|
-
} = this.props;
|
|
41
|
-
let fields = field.get('field') || field.get('fields');
|
|
42
|
-
fields = List.isList(fields) ? fields : List([fields]);
|
|
43
|
-
fields.forEach(field => {
|
|
44
|
-
var _control$validate;
|
|
45
|
-
if (field.get('widget') === 'hidden') return;
|
|
46
|
-
const name = field.get('name');
|
|
47
|
-
const control = this.childRefs[name];
|
|
48
|
-
control === null || control === void 0 ? void 0 : (_control$validate = control.validate) === null || _control$validate === void 0 ? void 0 : _control$validate.call(control);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
_defineProperty(this, "handleCollapseToggle", () => {
|
|
52
|
-
this.setState({
|
|
53
|
-
collapsed: !this.state.collapsed
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
_defineProperty(this, "renderFields", (multiFields, singleField) => {
|
|
57
|
-
if (multiFields) {
|
|
58
|
-
return multiFields.map((f, idx) => this.controlFor(f, idx));
|
|
59
|
-
}
|
|
60
|
-
return this.controlFor(singleField);
|
|
61
|
-
});
|
|
62
|
-
_defineProperty(this, "objectLabel", () => {
|
|
63
|
-
const {
|
|
64
|
-
value,
|
|
65
|
-
field
|
|
66
|
-
} = this.props;
|
|
67
|
-
const label = field.get('label', field.get('name'));
|
|
68
|
-
const summary = field.get('summary');
|
|
69
|
-
return summary ? stringTemplate.compileStringTemplate(summary, null, '', value) : label;
|
|
70
|
-
});
|
|
71
54
|
this.state = {
|
|
72
55
|
collapsed: props.field.get('collapsed', false)
|
|
73
56
|
};
|
|
74
57
|
}
|
|
58
|
+
componentDidMount() {
|
|
59
|
+
// Manually validate PropTypes - React 19 breaking change
|
|
60
|
+
PropTypes.checkPropTypes(ObjectControl.propTypes, this.props, 'prop', 'ObjectControl');
|
|
61
|
+
}
|
|
75
62
|
|
|
76
63
|
/*
|
|
77
64
|
* Always update so that each nested widget has the option to update. This is
|
|
@@ -82,6 +69,23 @@ export default class ObjectControl extends React.Component {
|
|
|
82
69
|
shouldComponentUpdate() {
|
|
83
70
|
return true;
|
|
84
71
|
}
|
|
72
|
+
validate = () => {
|
|
73
|
+
const {
|
|
74
|
+
field
|
|
75
|
+
} = this.props;
|
|
76
|
+
let fields = field.get('field') || field.get('fields');
|
|
77
|
+
fields = List.isList(fields) ? fields : List([fields]);
|
|
78
|
+
fields.forEach(field => {
|
|
79
|
+
if (field.get('widget') === 'hidden') return;
|
|
80
|
+
const name = field.get('name');
|
|
81
|
+
const control = this.childRefs[name];
|
|
82
|
+
if (control?.innerWrappedControl?.validate) {
|
|
83
|
+
control.innerWrappedControl.validate();
|
|
84
|
+
} else {
|
|
85
|
+
control?.validate?.();
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
};
|
|
85
89
|
controlFor(field, key) {
|
|
86
90
|
const {
|
|
87
91
|
value,
|
|
@@ -124,6 +128,11 @@ export default class ObjectControl extends React.Component {
|
|
|
124
128
|
isParentListCollapsed: collapsed
|
|
125
129
|
});
|
|
126
130
|
}
|
|
131
|
+
handleCollapseToggle = () => {
|
|
132
|
+
this.setState({
|
|
133
|
+
collapsed: !this.state.collapsed
|
|
134
|
+
});
|
|
135
|
+
};
|
|
127
136
|
focus(path) {
|
|
128
137
|
if (this.state.collapsed) {
|
|
129
138
|
this.setState({
|
|
@@ -132,7 +141,7 @@ export default class ObjectControl extends React.Component {
|
|
|
132
141
|
if (path) {
|
|
133
142
|
const [fieldName, ...remainingPath] = path.split('.');
|
|
134
143
|
const field = this.childRefs[fieldName];
|
|
135
|
-
if (field
|
|
144
|
+
if (field?.focus) {
|
|
136
145
|
field.focus(remainingPath.join('.'));
|
|
137
146
|
}
|
|
138
147
|
}
|
|
@@ -140,11 +149,26 @@ export default class ObjectControl extends React.Component {
|
|
|
140
149
|
} else if (path) {
|
|
141
150
|
const [fieldName, ...remainingPath] = path.split('.');
|
|
142
151
|
const field = this.childRefs[fieldName];
|
|
143
|
-
if (field
|
|
152
|
+
if (field?.focus) {
|
|
144
153
|
field.focus(remainingPath.join('.'));
|
|
145
154
|
}
|
|
146
155
|
}
|
|
147
156
|
}
|
|
157
|
+
renderFields = (multiFields, singleField) => {
|
|
158
|
+
if (multiFields) {
|
|
159
|
+
return multiFields.map((f, idx) => this.controlFor(f, idx));
|
|
160
|
+
}
|
|
161
|
+
return this.controlFor(singleField);
|
|
162
|
+
};
|
|
163
|
+
objectLabel = () => {
|
|
164
|
+
const {
|
|
165
|
+
value,
|
|
166
|
+
field
|
|
167
|
+
} = this.props;
|
|
168
|
+
const label = field.get('label', field.get('name'));
|
|
169
|
+
const summary = field.get('summary');
|
|
170
|
+
return summary ? stringTemplate.compileStringTemplate(summary, null, '', value) : label;
|
|
171
|
+
};
|
|
148
172
|
render() {
|
|
149
173
|
const {
|
|
150
174
|
field,
|
|
@@ -189,25 +213,4 @@ export default class ObjectControl extends React.Component {
|
|
|
189
213
|
}
|
|
190
214
|
return ___EmotionJSX("h3", null, "No field(s) defined for this widget");
|
|
191
215
|
}
|
|
192
|
-
}
|
|
193
|
-
_defineProperty(ObjectControl, "propTypes", {
|
|
194
|
-
onChangeObject: PropTypes.func.isRequired,
|
|
195
|
-
onValidateObject: PropTypes.func,
|
|
196
|
-
value: PropTypes.oneOfType([PropTypes.node, PropTypes.object, PropTypes.bool]),
|
|
197
|
-
field: PropTypes.object,
|
|
198
|
-
forID: PropTypes.string,
|
|
199
|
-
classNameWrapper: PropTypes.string.isRequired,
|
|
200
|
-
forList: PropTypes.bool,
|
|
201
|
-
controlRef: PropTypes.func,
|
|
202
|
-
editorControl: PropTypes.elementType.isRequired,
|
|
203
|
-
resolveWidget: PropTypes.func.isRequired,
|
|
204
|
-
clearFieldErrors: PropTypes.func.isRequired,
|
|
205
|
-
fieldsErrors: ImmutablePropTypes.map,
|
|
206
|
-
hasError: PropTypes.bool,
|
|
207
|
-
t: PropTypes.func,
|
|
208
|
-
locale: PropTypes.string,
|
|
209
|
-
collapsed: PropTypes.bool
|
|
210
|
-
});
|
|
211
|
-
_defineProperty(ObjectControl, "defaultProps", {
|
|
212
|
-
value: Map()
|
|
213
|
-
});
|
|
216
|
+
}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
2
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
3
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
4
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
5
|
-
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
6
1
|
import controlComponent from './ObjectControl';
|
|
7
2
|
import previewComponent from './ObjectPreview';
|
|
8
3
|
import schema from './schema';
|
|
9
4
|
function Widget(opts = {}) {
|
|
10
|
-
return
|
|
5
|
+
return {
|
|
11
6
|
name: 'object',
|
|
12
7
|
controlComponent,
|
|
13
8
|
previewComponent,
|
|
14
|
-
schema
|
|
15
|
-
|
|
9
|
+
schema,
|
|
10
|
+
...opts
|
|
11
|
+
};
|
|
16
12
|
}
|
|
17
13
|
export const DecapCmsWidgetObject = {
|
|
18
14
|
Widget,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "decap-cms-widget-object",
|
|
3
3
|
"description": "Widget for displaying an object of fields for Decap CMS.",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.4.0",
|
|
5
5
|
"homepage": "https://www.decapcms.org/docs/widgets/#object",
|
|
6
6
|
"repository": "https://github.com/decaporg/decap-cms/tree/main/packages/decap-cms-widget-object",
|
|
7
7
|
"bugs": "https://github.com/decaporg/decap-cms/issues",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"immutable": "^3.7.6",
|
|
29
29
|
"lodash": "^4.17.11",
|
|
30
30
|
"prop-types": "^15.7.2",
|
|
31
|
-
"react": "^
|
|
31
|
+
"react": "^19.1.0",
|
|
32
32
|
"react-immutable-proptypes": "^2.1.0"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "ed7e99318007b83f4c57f3237bf92b931676820a"
|
|
35
35
|
}
|
package/src/ObjectControl.js
CHANGED
|
@@ -61,6 +61,11 @@ export default class ObjectControl extends React.Component {
|
|
|
61
61
|
};
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
+
componentDidMount() {
|
|
65
|
+
// Manually validate PropTypes - React 19 breaking change
|
|
66
|
+
PropTypes.checkPropTypes(ObjectControl.propTypes, this.props, 'prop', 'ObjectControl');
|
|
67
|
+
}
|
|
68
|
+
|
|
64
69
|
/*
|
|
65
70
|
* Always update so that each nested widget has the option to update. This is
|
|
66
71
|
* required because ControlHOC provides a default `shouldComponentUpdate`
|
|
@@ -79,7 +84,12 @@ export default class ObjectControl extends React.Component {
|
|
|
79
84
|
if (field.get('widget') === 'hidden') return;
|
|
80
85
|
const name = field.get('name');
|
|
81
86
|
const control = this.childRefs[name];
|
|
82
|
-
|
|
87
|
+
|
|
88
|
+
if (control?.innerWrappedControl?.validate) {
|
|
89
|
+
control.innerWrappedControl.validate();
|
|
90
|
+
} else {
|
|
91
|
+
control?.validate?.();
|
|
92
|
+
}
|
|
83
93
|
});
|
|
84
94
|
};
|
|
85
95
|
|