decap-cms-widget-object 3.1.5-beta.0 → 3.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/CHANGELOG.md +10 -2
- package/dist/decap-cms-widget-object.js +3 -3
- package/dist/decap-cms-widget-object.js.map +1 -1
- package/dist/esm/ObjectControl.js +74 -51
- package/dist/esm/ObjectPreview.js +7 -14
- package/dist/esm/index.js +10 -17
- package/dist/esm/schema.js +1 -7
- package/package.json +3 -3
- package/src/ObjectControl.js +34 -6
|
@@ -1,20 +1,14 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _react = _interopRequireDefault(require("react"));
|
|
8
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
-
var _reactImmutableProptypes = _interopRequireDefault(require("react-immutable-proptypes"));
|
|
10
|
-
var _react2 = require("@emotion/react");
|
|
11
|
-
var _immutable = require("immutable");
|
|
12
|
-
var _decapCmsUiDefault = require("decap-cms-ui-default");
|
|
13
|
-
var _decapCmsLibWidgets = require("decap-cms-lib-widgets");
|
|
14
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
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; }
|
|
16
2
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
17
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
|
+
import React from 'react';
|
|
5
|
+
import PropTypes from 'prop-types';
|
|
6
|
+
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
7
|
+
import { ClassNames } from '@emotion/react';
|
|
8
|
+
import { List, Map } from 'immutable';
|
|
9
|
+
import { colors, lengths, ObjectWidgetTopBar } from 'decap-cms-ui-default';
|
|
10
|
+
import { stringTemplate } from 'decap-cms-lib-widgets';
|
|
11
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
|
18
12
|
const styleStrings = {
|
|
19
13
|
nestedObjectControl: `
|
|
20
14
|
padding: 6px 14px 14px;
|
|
@@ -23,25 +17,35 @@ const styleStrings = {
|
|
|
23
17
|
border-top-right-radius: 0;
|
|
24
18
|
`,
|
|
25
19
|
objectWidgetTopBarContainer: `
|
|
26
|
-
padding: ${
|
|
20
|
+
padding: ${lengths.objectWidgetTopBarContainerPadding};
|
|
27
21
|
`,
|
|
28
22
|
collapsedObjectControl: `
|
|
29
23
|
display: none;
|
|
30
24
|
`
|
|
31
25
|
};
|
|
32
|
-
class ObjectControl extends
|
|
26
|
+
export default class ObjectControl extends React.Component {
|
|
33
27
|
constructor(props) {
|
|
34
28
|
super(props);
|
|
35
|
-
_defineProperty(this, "
|
|
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
|
+
});
|
|
36
37
|
_defineProperty(this, "validate", () => {
|
|
37
38
|
const {
|
|
38
39
|
field
|
|
39
40
|
} = this.props;
|
|
40
41
|
let fields = field.get('field') || field.get('fields');
|
|
41
|
-
fields =
|
|
42
|
+
fields = List.isList(fields) ? fields : List([fields]);
|
|
42
43
|
fields.forEach(field => {
|
|
44
|
+
var _control$validate;
|
|
43
45
|
if (field.get('widget') === 'hidden') return;
|
|
44
|
-
|
|
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);
|
|
45
49
|
});
|
|
46
50
|
});
|
|
47
51
|
_defineProperty(this, "handleCollapseToggle", () => {
|
|
@@ -62,7 +66,7 @@ class ObjectControl extends _react.default.Component {
|
|
|
62
66
|
} = this.props;
|
|
63
67
|
const label = field.get('label', field.get('name'));
|
|
64
68
|
const summary = field.get('summary');
|
|
65
|
-
return summary ?
|
|
69
|
+
return summary ? stringTemplate.compileStringTemplate(summary, null, '', value) : label;
|
|
66
70
|
});
|
|
67
71
|
this.state = {
|
|
68
72
|
collapsed: props.field.get('collapsed', false)
|
|
@@ -87,21 +91,21 @@ class ObjectControl extends _react.default.Component {
|
|
|
87
91
|
metadata,
|
|
88
92
|
fieldsErrors,
|
|
89
93
|
editorControl: EditorControl,
|
|
90
|
-
controlRef,
|
|
91
94
|
parentIds,
|
|
92
95
|
isFieldDuplicate,
|
|
93
96
|
isFieldHidden,
|
|
94
97
|
locale,
|
|
95
|
-
collapsed
|
|
98
|
+
collapsed,
|
|
99
|
+
forID
|
|
96
100
|
} = this.props;
|
|
97
101
|
if (field.get('widget') === 'hidden') {
|
|
98
102
|
return null;
|
|
99
103
|
}
|
|
100
104
|
const fieldName = field.get('name');
|
|
101
|
-
const fieldValue = value &&
|
|
105
|
+
const fieldValue = value && Map.isMap(value) ? value.get(fieldName) : value;
|
|
102
106
|
const isDuplicate = isFieldDuplicate && isFieldDuplicate(field);
|
|
103
107
|
const isHidden = isFieldHidden && isFieldHidden(field);
|
|
104
|
-
return (
|
|
108
|
+
return ___EmotionJSX(EditorControl, {
|
|
105
109
|
key: key,
|
|
106
110
|
field: field,
|
|
107
111
|
value: fieldValue,
|
|
@@ -110,9 +114,8 @@ class ObjectControl extends _react.default.Component {
|
|
|
110
114
|
fieldsMetaData: metadata,
|
|
111
115
|
fieldsErrors: fieldsErrors,
|
|
112
116
|
onValidate: onValidateObject,
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
parentIds: parentIds,
|
|
117
|
+
controlRef: this.processControlRef,
|
|
118
|
+
parentIds: [...parentIds, forID],
|
|
116
119
|
isDisabled: isDuplicate,
|
|
117
120
|
isHidden: isHidden,
|
|
118
121
|
isFieldDuplicate: isFieldDuplicate,
|
|
@@ -121,6 +124,27 @@ class ObjectControl extends _react.default.Component {
|
|
|
121
124
|
isParentListCollapsed: collapsed
|
|
122
125
|
});
|
|
123
126
|
}
|
|
127
|
+
focus(path) {
|
|
128
|
+
if (this.state.collapsed) {
|
|
129
|
+
this.setState({
|
|
130
|
+
collapsed: false
|
|
131
|
+
}, () => {
|
|
132
|
+
if (path) {
|
|
133
|
+
const [fieldName, ...remainingPath] = path.split('.');
|
|
134
|
+
const field = this.childRefs[fieldName];
|
|
135
|
+
if (field !== null && field !== void 0 && field.focus) {
|
|
136
|
+
field.focus(remainingPath.join('.'));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
} else if (path) {
|
|
141
|
+
const [fieldName, ...remainingPath] = path.split('.');
|
|
142
|
+
const field = this.childRefs[fieldName];
|
|
143
|
+
if (field !== null && field !== void 0 && field.focus) {
|
|
144
|
+
field.focus(remainingPath.join('.'));
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
124
148
|
render() {
|
|
125
149
|
const {
|
|
126
150
|
field,
|
|
@@ -134,10 +158,10 @@ class ObjectControl extends _react.default.Component {
|
|
|
134
158
|
const multiFields = field.get('fields');
|
|
135
159
|
const singleField = field.get('field');
|
|
136
160
|
if (multiFields || singleField) {
|
|
137
|
-
return (
|
|
161
|
+
return ___EmotionJSX(ClassNames, null, ({
|
|
138
162
|
css,
|
|
139
163
|
cx
|
|
140
|
-
}) => (
|
|
164
|
+
}) => ___EmotionJSX("div", {
|
|
141
165
|
id: forID,
|
|
142
166
|
className: cx(classNameWrapper, css`
|
|
143
167
|
${styleStrings.objectWidgetTopBarContainer}
|
|
@@ -147,15 +171,15 @@ class ObjectControl extends _react.default.Component {
|
|
|
147
171
|
`]: forList
|
|
148
172
|
}, {
|
|
149
173
|
[css`
|
|
150
|
-
border-color: ${
|
|
174
|
+
border-color: ${colors.textFieldBorder};
|
|
151
175
|
`]: forList ? !hasError : false
|
|
152
176
|
})
|
|
153
|
-
}, forList ? null : (
|
|
177
|
+
}, forList ? null : ___EmotionJSX(ObjectWidgetTopBar, {
|
|
154
178
|
collapsed: collapsed,
|
|
155
179
|
onCollapseToggle: this.handleCollapseToggle,
|
|
156
180
|
heading: collapsed && this.objectLabel(),
|
|
157
181
|
t: t
|
|
158
|
-
}), (
|
|
182
|
+
}), ___EmotionJSX("div", {
|
|
159
183
|
className: cx({
|
|
160
184
|
[css`
|
|
161
185
|
${styleStrings.collapsedObjectControl}
|
|
@@ -163,28 +187,27 @@ class ObjectControl extends _react.default.Component {
|
|
|
163
187
|
})
|
|
164
188
|
}, this.renderFields(multiFields, singleField))));
|
|
165
189
|
}
|
|
166
|
-
return (
|
|
190
|
+
return ___EmotionJSX("h3", null, "No field(s) defined for this widget");
|
|
167
191
|
}
|
|
168
192
|
}
|
|
169
|
-
exports.default = ObjectControl;
|
|
170
193
|
_defineProperty(ObjectControl, "propTypes", {
|
|
171
|
-
onChangeObject:
|
|
172
|
-
onValidateObject:
|
|
173
|
-
value:
|
|
174
|
-
field:
|
|
175
|
-
forID:
|
|
176
|
-
classNameWrapper:
|
|
177
|
-
forList:
|
|
178
|
-
controlRef:
|
|
179
|
-
editorControl:
|
|
180
|
-
resolveWidget:
|
|
181
|
-
clearFieldErrors:
|
|
182
|
-
fieldsErrors:
|
|
183
|
-
hasError:
|
|
184
|
-
t:
|
|
185
|
-
locale:
|
|
186
|
-
collapsed:
|
|
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
|
|
187
210
|
});
|
|
188
211
|
_defineProperty(ObjectControl, "defaultProps", {
|
|
189
|
-
value:
|
|
212
|
+
value: Map()
|
|
190
213
|
});
|
|
@@ -1,20 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _react = _interopRequireDefault(require("react"));
|
|
8
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
-
var _decapCmsUiDefault = require("decap-cms-ui-default");
|
|
10
|
-
var _react2 = require("@emotion/react");
|
|
11
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { WidgetPreviewContainer } from 'decap-cms-ui-default';
|
|
4
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
|
12
5
|
function ObjectPreview({
|
|
13
6
|
field
|
|
14
7
|
}) {
|
|
15
|
-
return (
|
|
8
|
+
return ___EmotionJSX(WidgetPreviewContainer, null, field && field.get('fields') || field.get('field') || null);
|
|
16
9
|
}
|
|
17
10
|
ObjectPreview.propTypes = {
|
|
18
|
-
field:
|
|
11
|
+
field: PropTypes.node
|
|
19
12
|
};
|
|
20
|
-
|
|
13
|
+
export default ObjectPreview;
|
package/dist/esm/index.js
CHANGED
|
@@ -1,29 +1,22 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = exports.DecapCmsWidgetObject = void 0;
|
|
7
|
-
var _ObjectControl = _interopRequireDefault(require("./ObjectControl"));
|
|
8
|
-
var _ObjectPreview = _interopRequireDefault(require("./ObjectPreview"));
|
|
9
|
-
var _schema = _interopRequireDefault(require("./schema"));
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
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; }
|
|
12
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; }
|
|
13
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; }
|
|
14
4
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
15
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
|
+
import controlComponent from './ObjectControl';
|
|
7
|
+
import previewComponent from './ObjectPreview';
|
|
8
|
+
import schema from './schema';
|
|
16
9
|
function Widget(opts = {}) {
|
|
17
10
|
return _objectSpread({
|
|
18
11
|
name: 'object',
|
|
19
|
-
controlComponent
|
|
20
|
-
previewComponent
|
|
21
|
-
schema
|
|
12
|
+
controlComponent,
|
|
13
|
+
previewComponent,
|
|
14
|
+
schema
|
|
22
15
|
}, opts);
|
|
23
16
|
}
|
|
24
|
-
const DecapCmsWidgetObject =
|
|
17
|
+
export const DecapCmsWidgetObject = {
|
|
25
18
|
Widget,
|
|
26
|
-
controlComponent
|
|
27
|
-
previewComponent
|
|
19
|
+
controlComponent,
|
|
20
|
+
previewComponent
|
|
28
21
|
};
|
|
29
|
-
|
|
22
|
+
export default DecapCmsWidgetObject;
|
package/dist/esm/schema.js
CHANGED
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.3.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": "^18.2.0",
|
|
32
32
|
"react-immutable-proptypes": "^2.1.0"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "e2165450e5963b2a8d76d4cf331319bf91f05d45"
|
|
35
35
|
}
|
package/src/ObjectControl.js
CHANGED
|
@@ -22,7 +22,14 @@ const styleStrings = {
|
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
export default class ObjectControl extends React.Component {
|
|
25
|
-
|
|
25
|
+
childRefs = {};
|
|
26
|
+
|
|
27
|
+
processControlRef = ref => {
|
|
28
|
+
if (!ref) return;
|
|
29
|
+
const name = ref.props.field.get('name');
|
|
30
|
+
this.childRefs[name] = ref;
|
|
31
|
+
this.props.controlRef?.(ref);
|
|
32
|
+
};
|
|
26
33
|
|
|
27
34
|
static propTypes = {
|
|
28
35
|
onChangeObject: PropTypes.func.isRequired,
|
|
@@ -70,7 +77,9 @@ export default class ObjectControl extends React.Component {
|
|
|
70
77
|
fields = List.isList(fields) ? fields : List([fields]);
|
|
71
78
|
fields.forEach(field => {
|
|
72
79
|
if (field.get('widget') === 'hidden') return;
|
|
73
|
-
|
|
80
|
+
const name = field.get('name');
|
|
81
|
+
const control = this.childRefs[name];
|
|
82
|
+
control?.validate?.();
|
|
74
83
|
});
|
|
75
84
|
};
|
|
76
85
|
|
|
@@ -83,12 +92,12 @@ export default class ObjectControl extends React.Component {
|
|
|
83
92
|
metadata,
|
|
84
93
|
fieldsErrors,
|
|
85
94
|
editorControl: EditorControl,
|
|
86
|
-
controlRef,
|
|
87
95
|
parentIds,
|
|
88
96
|
isFieldDuplicate,
|
|
89
97
|
isFieldHidden,
|
|
90
98
|
locale,
|
|
91
99
|
collapsed,
|
|
100
|
+
forID,
|
|
92
101
|
} = this.props;
|
|
93
102
|
|
|
94
103
|
if (field.get('widget') === 'hidden') {
|
|
@@ -110,9 +119,8 @@ export default class ObjectControl extends React.Component {
|
|
|
110
119
|
fieldsMetaData={metadata}
|
|
111
120
|
fieldsErrors={fieldsErrors}
|
|
112
121
|
onValidate={onValidateObject}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
parentIds={parentIds}
|
|
122
|
+
controlRef={this.processControlRef}
|
|
123
|
+
parentIds={[...parentIds, forID]}
|
|
116
124
|
isDisabled={isDuplicate}
|
|
117
125
|
isHidden={isHidden}
|
|
118
126
|
isFieldDuplicate={isFieldDuplicate}
|
|
@@ -127,6 +135,26 @@ export default class ObjectControl extends React.Component {
|
|
|
127
135
|
this.setState({ collapsed: !this.state.collapsed });
|
|
128
136
|
};
|
|
129
137
|
|
|
138
|
+
focus(path) {
|
|
139
|
+
if (this.state.collapsed) {
|
|
140
|
+
this.setState({ collapsed: false }, () => {
|
|
141
|
+
if (path) {
|
|
142
|
+
const [fieldName, ...remainingPath] = path.split('.');
|
|
143
|
+
const field = this.childRefs[fieldName];
|
|
144
|
+
if (field?.focus) {
|
|
145
|
+
field.focus(remainingPath.join('.'));
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
} else if (path) {
|
|
150
|
+
const [fieldName, ...remainingPath] = path.split('.');
|
|
151
|
+
const field = this.childRefs[fieldName];
|
|
152
|
+
if (field?.focus) {
|
|
153
|
+
field.focus(remainingPath.join('.'));
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
130
158
|
renderFields = (multiFields, singleField) => {
|
|
131
159
|
if (multiFields) {
|
|
132
160
|
return multiFields.map((f, idx) => this.controlFor(f, idx));
|