decap-cms-core 3.6.3 → 3.7.1
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/decap-cms-core.js +25 -25
- package/dist/decap-cms-core.js.LICENSE.txt +14 -8
- package/dist/decap-cms-core.js.map +1 -1
- package/dist/esm/actions/config.js +57 -49
- package/dist/esm/actions/editorialWorkflow.js +4 -4
- package/dist/esm/actions/entries.js +8 -14
- package/dist/esm/actions/mediaLibrary.js +6 -11
- package/dist/esm/actions/search.js +2 -2
- package/dist/esm/actions/status.js +2 -8
- package/dist/esm/backend.js +70 -79
- package/dist/esm/bootstrap.js +3 -2
- package/dist/esm/components/App/App.js +28 -34
- package/dist/esm/components/App/Header.js +32 -39
- package/dist/esm/components/Collection/Collection.js +45 -48
- package/dist/esm/components/Collection/CollectionSearch.js +76 -81
- package/dist/esm/components/Collection/CollectionTop.js +1 -2
- package/dist/esm/components/Collection/Entries/Entries.js +2 -4
- package/dist/esm/components/Collection/Entries/EntriesCollection.js +25 -29
- package/dist/esm/components/Collection/Entries/EntriesSearch.js +34 -38
- package/dist/esm/components/Collection/Entries/EntryCard.js +8 -13
- package/dist/esm/components/Collection/Entries/EntryListing.js +72 -76
- package/dist/esm/components/Collection/FilterControl.js +1 -1
- package/dist/esm/components/Collection/GroupControl.js +1 -1
- package/dist/esm/components/Collection/NestedCollection.js +50 -53
- package/dist/esm/components/Collection/Sidebar.js +35 -38
- package/dist/esm/components/Collection/SortControl.js +3 -3
- package/dist/esm/components/Collection/ViewStyleControl.js +1 -2
- package/dist/esm/components/Editor/Editor.js +197 -201
- package/dist/esm/components/Editor/EditorControlPane/EditorControl.js +79 -87
- package/dist/esm/components/Editor/EditorControlPane/EditorControlPane.js +75 -86
- package/dist/esm/components/Editor/EditorControlPane/Widget.js +226 -228
- package/dist/esm/components/Editor/EditorInterface.js +69 -80
- package/dist/esm/components/Editor/EditorPreviewPane/EditorPreview.js +1 -2
- package/dist/esm/components/Editor/EditorPreviewPane/EditorPreviewContent.js +20 -28
- package/dist/esm/components/Editor/EditorPreviewPane/EditorPreviewPane.js +163 -161
- package/dist/esm/components/Editor/EditorPreviewPane/PreviewHOC.js +4 -8
- package/dist/esm/components/Editor/EditorToolbar.js +335 -347
- package/dist/esm/components/Editor/withWorkflow.js +5 -6
- package/dist/esm/components/MediaLibrary/MediaLibrary.js +304 -294
- package/dist/esm/components/MediaLibrary/MediaLibraryButtons.js +40 -46
- package/dist/esm/components/MediaLibrary/MediaLibraryCard.js +1 -2
- package/dist/esm/components/MediaLibrary/MediaLibraryCardGrid.js +8 -13
- package/dist/esm/components/MediaLibrary/MediaLibraryModal.js +3 -3
- package/dist/esm/components/MediaLibrary/MediaLibrarySearch.js +1 -2
- package/dist/esm/components/MediaLibrary/MediaLibraryTop.js +3 -6
- package/dist/esm/components/UI/DragDrop.js +15 -23
- package/dist/esm/components/UI/ErrorBoundary.js +23 -25
- package/dist/esm/components/UI/Modal.js +10 -12
- package/dist/esm/components/UI/Notifications.js +4 -8
- package/dist/esm/components/UI/SettingsDropdown.js +4 -8
- package/dist/esm/components/Workflow/Workflow.js +19 -20
- package/dist/esm/components/Workflow/WorkflowCard.js +2 -4
- package/dist/esm/components/Workflow/WorkflowList.js +105 -113
- package/dist/esm/constants/configSchema.js +18 -16
- package/dist/esm/formats/formats.js +11 -12
- package/dist/esm/formats/frontmatter.js +17 -21
- package/dist/esm/formats/toml.js +2 -2
- package/dist/esm/formats/yaml.js +2 -6
- package/dist/esm/index.js +3 -7
- package/dist/esm/integrations/providers/algolia/implementation.js +12 -14
- package/dist/esm/integrations/providers/assetStore/implementation.js +10 -12
- package/dist/esm/lib/formatters.js +13 -17
- package/dist/esm/lib/i18n.js +35 -33
- package/dist/esm/lib/phrases.js +2 -2
- package/dist/esm/lib/polyfill.js +8 -0
- package/dist/esm/lib/registry.js +35 -35
- package/dist/esm/lib/serializeEntryValues.js +3 -3
- package/dist/esm/lib/stega.js +142 -0
- package/dist/esm/lib/urlHelper.js +16 -18
- package/dist/esm/mediaLibrary.js +3 -4
- package/dist/esm/reducers/collections.js +26 -42
- package/dist/esm/reducers/combinedReducer.js +3 -6
- package/dist/esm/reducers/config.js +3 -7
- package/dist/esm/reducers/editorialWorkflow.js +5 -9
- package/dist/esm/reducers/entries.js +33 -35
- package/dist/esm/reducers/entryDraft.js +2 -2
- package/dist/esm/reducers/integrations.js +8 -14
- package/dist/esm/reducers/mediaLibrary.js +18 -20
- package/dist/esm/reducers/notifications.js +4 -8
- package/dist/esm/types/immutable.js +7 -1
- package/dist/esm/valueObjects/AssetProxy.js +1 -9
- package/dist/esm/valueObjects/EditorComponent.js +18 -25
- package/dist/esm/valueObjects/Entry.js +2 -2
- package/index.d.ts +2 -0
- package/package.json +14 -11
- package/src/actions/__tests__/config.spec.js +3 -3
- package/src/actions/config.ts +3 -1
- package/src/actions/editorialWorkflow.ts +1 -1
- package/src/actions/entries.ts +1 -1
- package/src/actions/search.ts +1 -1
- package/src/backend.ts +8 -1
- package/src/bootstrap.js +1 -0
- package/src/components/App/App.js +5 -0
- package/src/components/App/Header.js +3 -0
- package/src/components/Collection/Collection.js +5 -0
- package/src/components/Collection/CollectionSearch.js +5 -0
- package/src/components/Collection/Entries/EntriesCollection.js +4 -1
- package/src/components/Collection/Entries/EntriesSearch.js +4 -1
- package/src/components/Collection/Entries/EntryListing.js +5 -0
- package/src/components/Collection/Entries/__tests__/__snapshots__/EntriesCollection.spec.js.snap +0 -4
- package/src/components/Collection/NestedCollection.js +6 -1
- package/src/components/Collection/Sidebar.js +5 -0
- package/src/components/Editor/Editor.js +4 -1
- package/src/components/Editor/EditorControlPane/EditorControl.js +7 -1
- package/src/components/Editor/EditorControlPane/Widget.js +5 -0
- package/src/components/Editor/EditorPreviewPane/EditorPreviewPane.js +1 -1
- package/src/components/Editor/EditorToolbar.js +3 -0
- package/src/components/Editor/__tests__/Editor.spec.js +3 -4
- package/src/components/Editor/__tests__/__snapshots__/Editor.spec.js.snap +5 -5
- package/src/components/Editor/__tests__/__snapshots__/EditorToolbar.spec.js.snap +708 -393
- package/src/components/MediaLibrary/MediaLibrary.js +5 -1
- package/src/components/MediaLibrary/MediaLibraryModal.js +1 -1
- package/src/components/UI/ErrorBoundary.js +6 -1
- package/src/components/UI/Modal.js +3 -0
- package/src/components/Workflow/Workflow.js +3 -0
- package/src/components/Workflow/WorkflowList.js +5 -0
- package/src/constants/__tests__/configSchema.spec.js +1 -1
- package/src/formats/formats.ts +1 -1
- package/src/formats/toml.ts +2 -2
- package/src/integrations/providers/algolia/implementation.js +2 -2
- package/src/integrations/providers/assetStore/implementation.js +2 -1
- package/src/lib/formatters.ts +4 -1
- package/src/lib/i18n.ts +3 -1
- package/src/lib/phrases.js +1 -1
- package/src/lib/polyfill.js +9 -0
- package/src/lib/serializeEntryValues.js +1 -1
- package/src/lib/stega.ts +145 -0
- package/src/lib/urlHelper.ts +4 -1
- package/src/mediaLibrary.ts +1 -1
- package/src/reducers/collections.ts +2 -1
- package/src/reducers/editorialWorkflow.ts +1 -1
- package/src/reducers/entries.ts +6 -1
- package/src/reducers/entryDraft.js +1 -1
- package/src/types/immutable.ts +10 -0
- package/src/types/redux.ts +2 -0
- package/src/valueObjects/EditorComponent.js +1 -1
- package/src/valueObjects/Entry.ts +1 -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 PropTypes from 'prop-types';
|
|
5
2
|
import React, { Component } from 'react';
|
|
6
3
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
@@ -17,180 +14,56 @@ function isEmpty(value) {
|
|
|
17
14
|
return value === null || value === undefined || Object.prototype.hasOwnProperty.call(value, 'length') && value.length === 0 || value.constructor === Object && Object.keys(value).length === 0 || List.isList(value) && value.size === 0;
|
|
18
15
|
}
|
|
19
16
|
export default class Widget extends Component {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const wrappedError = this.validateWrappedControl(field);
|
|
71
|
-
if (wrappedError.error) errors.push(wrappedError.error);
|
|
72
|
-
}
|
|
73
|
-
this.props.onValidate(errors);
|
|
74
|
-
});
|
|
75
|
-
_defineProperty(this, "validatePresence", (field, value) => {
|
|
76
|
-
const {
|
|
77
|
-
t,
|
|
78
|
-
parentIds
|
|
79
|
-
} = this.props;
|
|
80
|
-
const isRequired = field.get('required', true);
|
|
81
|
-
if (isRequired && isEmpty(value)) {
|
|
82
|
-
const error = {
|
|
83
|
-
type: ValidationErrorTypes.PRESENCE,
|
|
84
|
-
parentIds,
|
|
85
|
-
message: t('editor.editorControlPane.widget.required', {
|
|
86
|
-
fieldLabel: field.get('label', field.get('name'))
|
|
87
|
-
})
|
|
88
|
-
};
|
|
89
|
-
return {
|
|
90
|
-
error
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
return {
|
|
94
|
-
error: false
|
|
95
|
-
};
|
|
96
|
-
});
|
|
97
|
-
_defineProperty(this, "validatePattern", (field, value) => {
|
|
98
|
-
const {
|
|
99
|
-
t,
|
|
100
|
-
parentIds
|
|
101
|
-
} = this.props;
|
|
102
|
-
const pattern = field.get('pattern', false);
|
|
103
|
-
if (isEmpty(value)) {
|
|
104
|
-
return {
|
|
105
|
-
error: false
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
if (pattern && !RegExp(pattern.first()).test(value)) {
|
|
109
|
-
const error = {
|
|
110
|
-
type: ValidationErrorTypes.PATTERN,
|
|
111
|
-
parentIds,
|
|
112
|
-
message: t('editor.editorControlPane.widget.regexPattern', {
|
|
113
|
-
fieldLabel: field.get('label', field.get('name')),
|
|
114
|
-
pattern: pattern.last()
|
|
115
|
-
})
|
|
116
|
-
};
|
|
117
|
-
return {
|
|
118
|
-
error
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
return {
|
|
122
|
-
error: false
|
|
123
|
-
};
|
|
124
|
-
});
|
|
125
|
-
_defineProperty(this, "validateWrappedControl", field => {
|
|
126
|
-
const {
|
|
127
|
-
t,
|
|
128
|
-
parentIds
|
|
129
|
-
} = this.props;
|
|
130
|
-
if (typeof this.wrappedControlValid !== 'function') {
|
|
131
|
-
throw new Error(oneLine`
|
|
132
|
-
this.wrappedControlValid is not a function. Are you sure widget
|
|
133
|
-
"${field.get('widget')}" is registered?
|
|
134
|
-
`);
|
|
135
|
-
}
|
|
136
|
-
const response = this.wrappedControlValid();
|
|
137
|
-
if (typeof response === 'boolean') {
|
|
138
|
-
const isValid = response;
|
|
139
|
-
return {
|
|
140
|
-
error: !isValid
|
|
141
|
-
};
|
|
142
|
-
} else if (Object.prototype.hasOwnProperty.call(response, 'error')) {
|
|
143
|
-
return response;
|
|
144
|
-
} else if (response instanceof Promise) {
|
|
145
|
-
response.then(() => {
|
|
146
|
-
this.validate({
|
|
147
|
-
error: false
|
|
148
|
-
});
|
|
149
|
-
}, err => {
|
|
150
|
-
const error = {
|
|
151
|
-
type: ValidationErrorTypes.CUSTOM,
|
|
152
|
-
message: `${field.get('label', field.get('name'))} - ${err}.`
|
|
153
|
-
};
|
|
154
|
-
this.validate({
|
|
155
|
-
error
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
const error = {
|
|
159
|
-
type: ValidationErrorTypes.CUSTOM,
|
|
160
|
-
parentIds,
|
|
161
|
-
message: t('editor.editorControlPane.widget.processing', {
|
|
162
|
-
fieldLabel: field.get('label', field.get('name'))
|
|
163
|
-
})
|
|
164
|
-
};
|
|
165
|
-
return {
|
|
166
|
-
error
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
return {
|
|
170
|
-
error: false
|
|
171
|
-
};
|
|
172
|
-
});
|
|
173
|
-
/**
|
|
174
|
-
* In case the `onChangeObject` function is frozen by a child widget implementation,
|
|
175
|
-
* e.g. when debounced, always get the latest object value instead of using
|
|
176
|
-
* `this.props.value` directly.
|
|
177
|
-
*/
|
|
178
|
-
_defineProperty(this, "getObjectValue", () => this.props.value || Map());
|
|
179
|
-
/**
|
|
180
|
-
* Change handler for fields that are nested within another field.
|
|
181
|
-
*/
|
|
182
|
-
_defineProperty(this, "onChangeObject", (field, newValue, newMetadata) => {
|
|
183
|
-
const newObjectValue = this.getObjectValue().set(field.get('name'), newValue);
|
|
184
|
-
return this.props.onChange(newObjectValue, newMetadata && {
|
|
185
|
-
[this.props.field.get('name')]: newMetadata
|
|
186
|
-
});
|
|
187
|
-
});
|
|
188
|
-
_defineProperty(this, "setInactiveStyle", () => {
|
|
189
|
-
this.props.setInactiveStyle();
|
|
190
|
-
if (this.props.field.has('pattern') && !isEmpty(this.getValidateValue())) {
|
|
191
|
-
this.validate();
|
|
192
|
-
}
|
|
193
|
-
});
|
|
17
|
+
static propTypes = {
|
|
18
|
+
controlComponent: PropTypes.func.isRequired,
|
|
19
|
+
field: ImmutablePropTypes.map.isRequired,
|
|
20
|
+
hasActiveStyle: PropTypes.bool,
|
|
21
|
+
setActiveStyle: PropTypes.func.isRequired,
|
|
22
|
+
setInactiveStyle: PropTypes.func.isRequired,
|
|
23
|
+
classNameWrapper: PropTypes.string.isRequired,
|
|
24
|
+
classNameWidget: PropTypes.string.isRequired,
|
|
25
|
+
classNameWidgetActive: PropTypes.string.isRequired,
|
|
26
|
+
classNameLabel: PropTypes.string.isRequired,
|
|
27
|
+
classNameLabelActive: PropTypes.string.isRequired,
|
|
28
|
+
value: PropTypes.oneOfType([PropTypes.node, PropTypes.object, PropTypes.string, PropTypes.bool]),
|
|
29
|
+
mediaPaths: ImmutablePropTypes.map.isRequired,
|
|
30
|
+
metadata: ImmutablePropTypes.map,
|
|
31
|
+
fieldsErrors: ImmutablePropTypes.map,
|
|
32
|
+
onChange: PropTypes.func.isRequired,
|
|
33
|
+
onValidate: PropTypes.func,
|
|
34
|
+
controlRef: PropTypes.func,
|
|
35
|
+
onOpenMediaLibrary: PropTypes.func.isRequired,
|
|
36
|
+
onClearMediaControl: PropTypes.func.isRequired,
|
|
37
|
+
onRemoveMediaControl: PropTypes.func.isRequired,
|
|
38
|
+
onPersistMedia: PropTypes.func.isRequired,
|
|
39
|
+
onAddAsset: PropTypes.func.isRequired,
|
|
40
|
+
onRemoveInsertedMedia: PropTypes.func.isRequired,
|
|
41
|
+
getAsset: PropTypes.func.isRequired,
|
|
42
|
+
resolveWidget: PropTypes.func.isRequired,
|
|
43
|
+
widget: PropTypes.object.isRequired,
|
|
44
|
+
getEditorComponents: PropTypes.func.isRequired,
|
|
45
|
+
isFetching: PropTypes.bool,
|
|
46
|
+
query: PropTypes.func.isRequired,
|
|
47
|
+
clearSearch: PropTypes.func.isRequired,
|
|
48
|
+
clearFieldErrors: PropTypes.func.isRequired,
|
|
49
|
+
queryHits: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
|
|
50
|
+
editorControl: PropTypes.elementType.isRequired,
|
|
51
|
+
uniqueFieldId: PropTypes.string.isRequired,
|
|
52
|
+
loadEntry: PropTypes.func.isRequired,
|
|
53
|
+
t: PropTypes.func.isRequired,
|
|
54
|
+
onValidateObject: PropTypes.func,
|
|
55
|
+
isEditorComponent: PropTypes.bool,
|
|
56
|
+
isNewEditorComponent: PropTypes.bool,
|
|
57
|
+
entry: ImmutablePropTypes.map.isRequired,
|
|
58
|
+
isDisabled: PropTypes.bool,
|
|
59
|
+
isFieldDuplicate: PropTypes.func,
|
|
60
|
+
isFieldHidden: PropTypes.func,
|
|
61
|
+
locale: PropTypes.string,
|
|
62
|
+
isParentListCollapsed: PropTypes.bool
|
|
63
|
+
};
|
|
64
|
+
componentDidMount() {
|
|
65
|
+
// Manually validate PropTypes - React 19 breaking change
|
|
66
|
+
PropTypes.checkPropTypes(Widget.propTypes, this.props, 'prop', 'Widget');
|
|
194
67
|
}
|
|
195
68
|
shouldComponentUpdate(nextProps) {
|
|
196
69
|
/**
|
|
@@ -205,15 +78,40 @@ export default class Widget extends Component {
|
|
|
205
78
|
}
|
|
206
79
|
return this.props.value !== nextProps.value || this.props.classNameWrapper !== nextProps.classNameWrapper || this.props.hasActiveStyle !== nextProps.hasActiveStyle;
|
|
207
80
|
}
|
|
81
|
+
processInnerControlRef = ref => {
|
|
82
|
+
if (!ref) return;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* If the widget is a container that receives state updates from the store,
|
|
86
|
+
* we'll need to get the ref of the actual control via the `react-redux`
|
|
87
|
+
* `getWrappedInstance` method. Note that connected widgets must pass
|
|
88
|
+
* `withRef: true` to `connect` in the options object.
|
|
89
|
+
*/
|
|
90
|
+
this.innerWrappedControl = ref.getWrappedInstance ? ref.getWrappedInstance() : ref;
|
|
91
|
+
this.wrappedControlValid = this.innerWrappedControl.isValid || truthy;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Get the `shouldComponentUpdate` method from the wrapped control, and
|
|
95
|
+
* provide the control instance is the `this` binding.
|
|
96
|
+
*/
|
|
97
|
+
const {
|
|
98
|
+
shouldComponentUpdate: scu
|
|
99
|
+
} = this.innerWrappedControl;
|
|
100
|
+
this.wrappedControlShouldComponentUpdate = scu && scu.bind(this.innerWrappedControl);
|
|
101
|
+
|
|
102
|
+
// Call the control ref if provided, passing this Widget instance
|
|
103
|
+
if (this.props.controlRef) {
|
|
104
|
+
this.props.controlRef(this);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
208
107
|
focus(path) {
|
|
209
|
-
var _this$innerWrappedCon3;
|
|
210
108
|
// Try widget's custom focus method first
|
|
211
|
-
if (
|
|
109
|
+
if (this.innerWrappedControl?.focus) {
|
|
212
110
|
this.innerWrappedControl.focus(path);
|
|
213
111
|
} else {
|
|
214
112
|
// Fall back to focusing by ID for simple widgets
|
|
215
113
|
const element = document.getElementById(this.props.uniqueFieldId);
|
|
216
|
-
element
|
|
114
|
+
element?.focus();
|
|
217
115
|
}
|
|
218
116
|
// After focusing, ensure the element is visible
|
|
219
117
|
const label = document.querySelector(`label[for="${this.props.uniqueFieldId}"]`);
|
|
@@ -224,6 +122,153 @@ export default class Widget extends Component {
|
|
|
224
122
|
});
|
|
225
123
|
}
|
|
226
124
|
}
|
|
125
|
+
getValidateValue = () => {
|
|
126
|
+
let value = this.innerWrappedControl?.getValidateValue?.() || this.props.value;
|
|
127
|
+
// Convert list input widget value to string for validation test
|
|
128
|
+
List.isList(value) && (value = value.join(','));
|
|
129
|
+
return value;
|
|
130
|
+
};
|
|
131
|
+
validate = (skipWrapped = false) => {
|
|
132
|
+
const value = this.getValidateValue();
|
|
133
|
+
const field = this.props.field;
|
|
134
|
+
const errors = [];
|
|
135
|
+
const validations = [this.validatePresence, this.validatePattern];
|
|
136
|
+
if (field.get('meta')) {
|
|
137
|
+
validations.push(this.props.validateMetaField);
|
|
138
|
+
}
|
|
139
|
+
validations.forEach(func => {
|
|
140
|
+
const response = func(field, value, this.props.t);
|
|
141
|
+
if (response.error) errors.push(response.error);
|
|
142
|
+
});
|
|
143
|
+
if (skipWrapped) {
|
|
144
|
+
if (skipWrapped.error) errors.push(skipWrapped.error);
|
|
145
|
+
} else {
|
|
146
|
+
const wrappedError = this.validateWrappedControl(field);
|
|
147
|
+
if (wrappedError.error) errors.push(wrappedError.error);
|
|
148
|
+
}
|
|
149
|
+
this.props.onValidate(errors);
|
|
150
|
+
};
|
|
151
|
+
validatePresence = (field, value) => {
|
|
152
|
+
const {
|
|
153
|
+
t,
|
|
154
|
+
parentIds
|
|
155
|
+
} = this.props;
|
|
156
|
+
const isRequired = field.get('required', true);
|
|
157
|
+
if (isRequired && isEmpty(value)) {
|
|
158
|
+
const error = {
|
|
159
|
+
type: ValidationErrorTypes.PRESENCE,
|
|
160
|
+
parentIds,
|
|
161
|
+
message: t('editor.editorControlPane.widget.required', {
|
|
162
|
+
fieldLabel: field.get('label', field.get('name'))
|
|
163
|
+
})
|
|
164
|
+
};
|
|
165
|
+
return {
|
|
166
|
+
error
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
return {
|
|
170
|
+
error: false
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
validatePattern = (field, value) => {
|
|
174
|
+
const {
|
|
175
|
+
t,
|
|
176
|
+
parentIds
|
|
177
|
+
} = this.props;
|
|
178
|
+
const pattern = field.get('pattern', false);
|
|
179
|
+
if (isEmpty(value)) {
|
|
180
|
+
return {
|
|
181
|
+
error: false
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
if (pattern && !RegExp(pattern.first()).test(value)) {
|
|
185
|
+
const error = {
|
|
186
|
+
type: ValidationErrorTypes.PATTERN,
|
|
187
|
+
parentIds,
|
|
188
|
+
message: t('editor.editorControlPane.widget.regexPattern', {
|
|
189
|
+
fieldLabel: field.get('label', field.get('name')),
|
|
190
|
+
pattern: pattern.last()
|
|
191
|
+
})
|
|
192
|
+
};
|
|
193
|
+
return {
|
|
194
|
+
error
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
return {
|
|
198
|
+
error: false
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
validateWrappedControl = field => {
|
|
202
|
+
const {
|
|
203
|
+
t,
|
|
204
|
+
parentIds
|
|
205
|
+
} = this.props;
|
|
206
|
+
if (typeof this.wrappedControlValid !== 'function') {
|
|
207
|
+
throw new Error(oneLine`
|
|
208
|
+
this.wrappedControlValid is not a function. Are you sure widget
|
|
209
|
+
"${field.get('widget')}" is registered?
|
|
210
|
+
`);
|
|
211
|
+
}
|
|
212
|
+
const response = this.wrappedControlValid();
|
|
213
|
+
if (typeof response === 'boolean') {
|
|
214
|
+
const isValid = response;
|
|
215
|
+
return {
|
|
216
|
+
error: !isValid
|
|
217
|
+
};
|
|
218
|
+
} else if (Object.prototype.hasOwnProperty.call(response, 'error')) {
|
|
219
|
+
return response;
|
|
220
|
+
} else if (response instanceof Promise) {
|
|
221
|
+
response.then(() => {
|
|
222
|
+
this.validate({
|
|
223
|
+
error: false
|
|
224
|
+
});
|
|
225
|
+
}, err => {
|
|
226
|
+
const error = {
|
|
227
|
+
type: ValidationErrorTypes.CUSTOM,
|
|
228
|
+
message: `${field.get('label', field.get('name'))} - ${err}.`
|
|
229
|
+
};
|
|
230
|
+
this.validate({
|
|
231
|
+
error
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
const error = {
|
|
235
|
+
type: ValidationErrorTypes.CUSTOM,
|
|
236
|
+
parentIds,
|
|
237
|
+
message: t('editor.editorControlPane.widget.processing', {
|
|
238
|
+
fieldLabel: field.get('label', field.get('name'))
|
|
239
|
+
})
|
|
240
|
+
};
|
|
241
|
+
return {
|
|
242
|
+
error
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
return {
|
|
246
|
+
error: false
|
|
247
|
+
};
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* In case the `onChangeObject` function is frozen by a child widget implementation,
|
|
252
|
+
* e.g. when debounced, always get the latest object value instead of using
|
|
253
|
+
* `this.props.value` directly.
|
|
254
|
+
*/
|
|
255
|
+
getObjectValue = () => this.props.value || Map();
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Change handler for fields that are nested within another field.
|
|
259
|
+
*/
|
|
260
|
+
onChangeObject = (field, newValue, newMetadata) => {
|
|
261
|
+
const newObjectValue = this.getObjectValue().set(field.get('name'), newValue);
|
|
262
|
+
return this.props.onChange(newObjectValue, newMetadata && {
|
|
263
|
+
[this.props.field.get('name')]: newMetadata
|
|
264
|
+
});
|
|
265
|
+
};
|
|
266
|
+
setInactiveStyle = () => {
|
|
267
|
+
this.props.setInactiveStyle();
|
|
268
|
+
if (this.props.field.has('pattern') && !isEmpty(this.getValidateValue())) {
|
|
269
|
+
this.validate();
|
|
270
|
+
}
|
|
271
|
+
};
|
|
227
272
|
render() {
|
|
228
273
|
const {
|
|
229
274
|
controlComponent,
|
|
@@ -326,51 +371,4 @@ export default class Widget extends Component {
|
|
|
326
371
|
isParentListCollapsed
|
|
327
372
|
});
|
|
328
373
|
}
|
|
329
|
-
}
|
|
330
|
-
_defineProperty(Widget, "propTypes", {
|
|
331
|
-
controlComponent: PropTypes.func.isRequired,
|
|
332
|
-
field: ImmutablePropTypes.map.isRequired,
|
|
333
|
-
hasActiveStyle: PropTypes.bool,
|
|
334
|
-
setActiveStyle: PropTypes.func.isRequired,
|
|
335
|
-
setInactiveStyle: PropTypes.func.isRequired,
|
|
336
|
-
classNameWrapper: PropTypes.string.isRequired,
|
|
337
|
-
classNameWidget: PropTypes.string.isRequired,
|
|
338
|
-
classNameWidgetActive: PropTypes.string.isRequired,
|
|
339
|
-
classNameLabel: PropTypes.string.isRequired,
|
|
340
|
-
classNameLabelActive: PropTypes.string.isRequired,
|
|
341
|
-
value: PropTypes.oneOfType([PropTypes.node, PropTypes.object, PropTypes.string, PropTypes.bool]),
|
|
342
|
-
mediaPaths: ImmutablePropTypes.map.isRequired,
|
|
343
|
-
metadata: ImmutablePropTypes.map,
|
|
344
|
-
fieldsErrors: ImmutablePropTypes.map,
|
|
345
|
-
onChange: PropTypes.func.isRequired,
|
|
346
|
-
onValidate: PropTypes.func,
|
|
347
|
-
controlRef: PropTypes.func,
|
|
348
|
-
onOpenMediaLibrary: PropTypes.func.isRequired,
|
|
349
|
-
onClearMediaControl: PropTypes.func.isRequired,
|
|
350
|
-
onRemoveMediaControl: PropTypes.func.isRequired,
|
|
351
|
-
onPersistMedia: PropTypes.func.isRequired,
|
|
352
|
-
onAddAsset: PropTypes.func.isRequired,
|
|
353
|
-
onRemoveInsertedMedia: PropTypes.func.isRequired,
|
|
354
|
-
getAsset: PropTypes.func.isRequired,
|
|
355
|
-
resolveWidget: PropTypes.func.isRequired,
|
|
356
|
-
widget: PropTypes.object.isRequired,
|
|
357
|
-
getEditorComponents: PropTypes.func.isRequired,
|
|
358
|
-
isFetching: PropTypes.bool,
|
|
359
|
-
query: PropTypes.func.isRequired,
|
|
360
|
-
clearSearch: PropTypes.func.isRequired,
|
|
361
|
-
clearFieldErrors: PropTypes.func.isRequired,
|
|
362
|
-
queryHits: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
|
|
363
|
-
editorControl: PropTypes.elementType.isRequired,
|
|
364
|
-
uniqueFieldId: PropTypes.string.isRequired,
|
|
365
|
-
loadEntry: PropTypes.func.isRequired,
|
|
366
|
-
t: PropTypes.func.isRequired,
|
|
367
|
-
onValidateObject: PropTypes.func,
|
|
368
|
-
isEditorComponent: PropTypes.bool,
|
|
369
|
-
isNewEditorComponent: PropTypes.bool,
|
|
370
|
-
entry: ImmutablePropTypes.map.isRequired,
|
|
371
|
-
isDisabled: PropTypes.bool,
|
|
372
|
-
isFieldDuplicate: PropTypes.func,
|
|
373
|
-
isFieldHidden: PropTypes.func,
|
|
374
|
-
locale: PropTypes.string,
|
|
375
|
-
isParentListCollapsed: PropTypes.bool
|
|
376
|
-
});
|
|
374
|
+
}
|