decap-cms-widget-object 3.3.1 → 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.
|
@@ -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,59 +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$innerWrapped;
|
|
45
|
-
if (field.get('widget') === 'hidden') return;
|
|
46
|
-
const name = field.get('name');
|
|
47
|
-
const control = this.childRefs[name];
|
|
48
|
-
if (control !== null && control !== void 0 && (_control$innerWrapped = control.innerWrappedControl) !== null && _control$innerWrapped !== void 0 && _control$innerWrapped.validate) {
|
|
49
|
-
control.innerWrappedControl.validate();
|
|
50
|
-
} else {
|
|
51
|
-
var _control$validate;
|
|
52
|
-
control === null || control === void 0 ? void 0 : (_control$validate = control.validate) === null || _control$validate === void 0 ? void 0 : _control$validate.call(control);
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
_defineProperty(this, "handleCollapseToggle", () => {
|
|
57
|
-
this.setState({
|
|
58
|
-
collapsed: !this.state.collapsed
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
_defineProperty(this, "renderFields", (multiFields, singleField) => {
|
|
62
|
-
if (multiFields) {
|
|
63
|
-
return multiFields.map((f, idx) => this.controlFor(f, idx));
|
|
64
|
-
}
|
|
65
|
-
return this.controlFor(singleField);
|
|
66
|
-
});
|
|
67
|
-
_defineProperty(this, "objectLabel", () => {
|
|
68
|
-
const {
|
|
69
|
-
value,
|
|
70
|
-
field
|
|
71
|
-
} = this.props;
|
|
72
|
-
const label = field.get('label', field.get('name'));
|
|
73
|
-
const summary = field.get('summary');
|
|
74
|
-
return summary ? stringTemplate.compileStringTemplate(summary, null, '', value) : label;
|
|
75
|
-
});
|
|
76
54
|
this.state = {
|
|
77
55
|
collapsed: props.field.get('collapsed', false)
|
|
78
56
|
};
|
|
79
57
|
}
|
|
58
|
+
componentDidMount() {
|
|
59
|
+
// Manually validate PropTypes - React 19 breaking change
|
|
60
|
+
PropTypes.checkPropTypes(ObjectControl.propTypes, this.props, 'prop', 'ObjectControl');
|
|
61
|
+
}
|
|
80
62
|
|
|
81
63
|
/*
|
|
82
64
|
* Always update so that each nested widget has the option to update. This is
|
|
@@ -87,6 +69,23 @@ export default class ObjectControl extends React.Component {
|
|
|
87
69
|
shouldComponentUpdate() {
|
|
88
70
|
return true;
|
|
89
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
|
+
};
|
|
90
89
|
controlFor(field, key) {
|
|
91
90
|
const {
|
|
92
91
|
value,
|
|
@@ -129,6 +128,11 @@ export default class ObjectControl extends React.Component {
|
|
|
129
128
|
isParentListCollapsed: collapsed
|
|
130
129
|
});
|
|
131
130
|
}
|
|
131
|
+
handleCollapseToggle = () => {
|
|
132
|
+
this.setState({
|
|
133
|
+
collapsed: !this.state.collapsed
|
|
134
|
+
});
|
|
135
|
+
};
|
|
132
136
|
focus(path) {
|
|
133
137
|
if (this.state.collapsed) {
|
|
134
138
|
this.setState({
|
|
@@ -137,7 +141,7 @@ export default class ObjectControl extends React.Component {
|
|
|
137
141
|
if (path) {
|
|
138
142
|
const [fieldName, ...remainingPath] = path.split('.');
|
|
139
143
|
const field = this.childRefs[fieldName];
|
|
140
|
-
if (field
|
|
144
|
+
if (field?.focus) {
|
|
141
145
|
field.focus(remainingPath.join('.'));
|
|
142
146
|
}
|
|
143
147
|
}
|
|
@@ -145,11 +149,26 @@ export default class ObjectControl extends React.Component {
|
|
|
145
149
|
} else if (path) {
|
|
146
150
|
const [fieldName, ...remainingPath] = path.split('.');
|
|
147
151
|
const field = this.childRefs[fieldName];
|
|
148
|
-
if (field
|
|
152
|
+
if (field?.focus) {
|
|
149
153
|
field.focus(remainingPath.join('.'));
|
|
150
154
|
}
|
|
151
155
|
}
|
|
152
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
|
+
};
|
|
153
172
|
render() {
|
|
154
173
|
const {
|
|
155
174
|
field,
|
|
@@ -194,25 +213,4 @@ export default class ObjectControl extends React.Component {
|
|
|
194
213
|
}
|
|
195
214
|
return ___EmotionJSX("h3", null, "No field(s) defined for this widget");
|
|
196
215
|
}
|
|
197
|
-
}
|
|
198
|
-
_defineProperty(ObjectControl, "propTypes", {
|
|
199
|
-
onChangeObject: PropTypes.func.isRequired,
|
|
200
|
-
onValidateObject: PropTypes.func,
|
|
201
|
-
value: PropTypes.oneOfType([PropTypes.node, PropTypes.object, PropTypes.bool]),
|
|
202
|
-
field: PropTypes.object,
|
|
203
|
-
forID: PropTypes.string,
|
|
204
|
-
classNameWrapper: PropTypes.string.isRequired,
|
|
205
|
-
forList: PropTypes.bool,
|
|
206
|
-
controlRef: PropTypes.func,
|
|
207
|
-
editorControl: PropTypes.elementType.isRequired,
|
|
208
|
-
resolveWidget: PropTypes.func.isRequired,
|
|
209
|
-
clearFieldErrors: PropTypes.func.isRequired,
|
|
210
|
-
fieldsErrors: ImmutablePropTypes.map,
|
|
211
|
-
hasError: PropTypes.bool,
|
|
212
|
-
t: PropTypes.func,
|
|
213
|
-
locale: PropTypes.string,
|
|
214
|
-
collapsed: PropTypes.bool
|
|
215
|
-
});
|
|
216
|
-
_defineProperty(ObjectControl, "defaultProps", {
|
|
217
|
-
value: Map()
|
|
218
|
-
});
|
|
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`
|