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.
Files changed (137) hide show
  1. package/dist/decap-cms-core.js +25 -25
  2. package/dist/decap-cms-core.js.LICENSE.txt +14 -8
  3. package/dist/decap-cms-core.js.map +1 -1
  4. package/dist/esm/actions/config.js +57 -49
  5. package/dist/esm/actions/editorialWorkflow.js +4 -4
  6. package/dist/esm/actions/entries.js +8 -14
  7. package/dist/esm/actions/mediaLibrary.js +6 -11
  8. package/dist/esm/actions/search.js +2 -2
  9. package/dist/esm/actions/status.js +2 -8
  10. package/dist/esm/backend.js +70 -79
  11. package/dist/esm/bootstrap.js +3 -2
  12. package/dist/esm/components/App/App.js +28 -34
  13. package/dist/esm/components/App/Header.js +32 -39
  14. package/dist/esm/components/Collection/Collection.js +45 -48
  15. package/dist/esm/components/Collection/CollectionSearch.js +76 -81
  16. package/dist/esm/components/Collection/CollectionTop.js +1 -2
  17. package/dist/esm/components/Collection/Entries/Entries.js +2 -4
  18. package/dist/esm/components/Collection/Entries/EntriesCollection.js +25 -29
  19. package/dist/esm/components/Collection/Entries/EntriesSearch.js +34 -38
  20. package/dist/esm/components/Collection/Entries/EntryCard.js +8 -13
  21. package/dist/esm/components/Collection/Entries/EntryListing.js +72 -76
  22. package/dist/esm/components/Collection/FilterControl.js +1 -1
  23. package/dist/esm/components/Collection/GroupControl.js +1 -1
  24. package/dist/esm/components/Collection/NestedCollection.js +50 -53
  25. package/dist/esm/components/Collection/Sidebar.js +35 -38
  26. package/dist/esm/components/Collection/SortControl.js +3 -3
  27. package/dist/esm/components/Collection/ViewStyleControl.js +1 -2
  28. package/dist/esm/components/Editor/Editor.js +197 -201
  29. package/dist/esm/components/Editor/EditorControlPane/EditorControl.js +79 -87
  30. package/dist/esm/components/Editor/EditorControlPane/EditorControlPane.js +75 -86
  31. package/dist/esm/components/Editor/EditorControlPane/Widget.js +226 -228
  32. package/dist/esm/components/Editor/EditorInterface.js +69 -80
  33. package/dist/esm/components/Editor/EditorPreviewPane/EditorPreview.js +1 -2
  34. package/dist/esm/components/Editor/EditorPreviewPane/EditorPreviewContent.js +20 -28
  35. package/dist/esm/components/Editor/EditorPreviewPane/EditorPreviewPane.js +163 -161
  36. package/dist/esm/components/Editor/EditorPreviewPane/PreviewHOC.js +4 -8
  37. package/dist/esm/components/Editor/EditorToolbar.js +335 -347
  38. package/dist/esm/components/Editor/withWorkflow.js +5 -6
  39. package/dist/esm/components/MediaLibrary/MediaLibrary.js +304 -294
  40. package/dist/esm/components/MediaLibrary/MediaLibraryButtons.js +40 -46
  41. package/dist/esm/components/MediaLibrary/MediaLibraryCard.js +1 -2
  42. package/dist/esm/components/MediaLibrary/MediaLibraryCardGrid.js +8 -13
  43. package/dist/esm/components/MediaLibrary/MediaLibraryModal.js +3 -3
  44. package/dist/esm/components/MediaLibrary/MediaLibrarySearch.js +1 -2
  45. package/dist/esm/components/MediaLibrary/MediaLibraryTop.js +3 -6
  46. package/dist/esm/components/UI/DragDrop.js +15 -23
  47. package/dist/esm/components/UI/ErrorBoundary.js +23 -25
  48. package/dist/esm/components/UI/Modal.js +10 -12
  49. package/dist/esm/components/UI/Notifications.js +4 -8
  50. package/dist/esm/components/UI/SettingsDropdown.js +4 -8
  51. package/dist/esm/components/Workflow/Workflow.js +19 -20
  52. package/dist/esm/components/Workflow/WorkflowCard.js +2 -4
  53. package/dist/esm/components/Workflow/WorkflowList.js +105 -113
  54. package/dist/esm/constants/configSchema.js +18 -16
  55. package/dist/esm/formats/formats.js +11 -12
  56. package/dist/esm/formats/frontmatter.js +17 -21
  57. package/dist/esm/formats/toml.js +2 -2
  58. package/dist/esm/formats/yaml.js +2 -6
  59. package/dist/esm/index.js +3 -7
  60. package/dist/esm/integrations/providers/algolia/implementation.js +12 -14
  61. package/dist/esm/integrations/providers/assetStore/implementation.js +10 -12
  62. package/dist/esm/lib/formatters.js +13 -17
  63. package/dist/esm/lib/i18n.js +35 -33
  64. package/dist/esm/lib/phrases.js +2 -2
  65. package/dist/esm/lib/polyfill.js +8 -0
  66. package/dist/esm/lib/registry.js +35 -35
  67. package/dist/esm/lib/serializeEntryValues.js +3 -3
  68. package/dist/esm/lib/stega.js +142 -0
  69. package/dist/esm/lib/urlHelper.js +16 -18
  70. package/dist/esm/mediaLibrary.js +3 -4
  71. package/dist/esm/reducers/collections.js +26 -42
  72. package/dist/esm/reducers/combinedReducer.js +3 -6
  73. package/dist/esm/reducers/config.js +3 -7
  74. package/dist/esm/reducers/editorialWorkflow.js +5 -9
  75. package/dist/esm/reducers/entries.js +33 -35
  76. package/dist/esm/reducers/entryDraft.js +2 -2
  77. package/dist/esm/reducers/integrations.js +8 -14
  78. package/dist/esm/reducers/mediaLibrary.js +18 -20
  79. package/dist/esm/reducers/notifications.js +4 -8
  80. package/dist/esm/types/immutable.js +7 -1
  81. package/dist/esm/valueObjects/AssetProxy.js +1 -9
  82. package/dist/esm/valueObjects/EditorComponent.js +18 -25
  83. package/dist/esm/valueObjects/Entry.js +2 -2
  84. package/index.d.ts +2 -0
  85. package/package.json +14 -11
  86. package/src/actions/__tests__/config.spec.js +3 -3
  87. package/src/actions/config.ts +3 -1
  88. package/src/actions/editorialWorkflow.ts +1 -1
  89. package/src/actions/entries.ts +1 -1
  90. package/src/actions/search.ts +1 -1
  91. package/src/backend.ts +8 -1
  92. package/src/bootstrap.js +1 -0
  93. package/src/components/App/App.js +5 -0
  94. package/src/components/App/Header.js +3 -0
  95. package/src/components/Collection/Collection.js +5 -0
  96. package/src/components/Collection/CollectionSearch.js +5 -0
  97. package/src/components/Collection/Entries/EntriesCollection.js +4 -1
  98. package/src/components/Collection/Entries/EntriesSearch.js +4 -1
  99. package/src/components/Collection/Entries/EntryListing.js +5 -0
  100. package/src/components/Collection/Entries/__tests__/__snapshots__/EntriesCollection.spec.js.snap +0 -4
  101. package/src/components/Collection/NestedCollection.js +6 -1
  102. package/src/components/Collection/Sidebar.js +5 -0
  103. package/src/components/Editor/Editor.js +4 -1
  104. package/src/components/Editor/EditorControlPane/EditorControl.js +7 -1
  105. package/src/components/Editor/EditorControlPane/Widget.js +5 -0
  106. package/src/components/Editor/EditorPreviewPane/EditorPreviewPane.js +1 -1
  107. package/src/components/Editor/EditorToolbar.js +3 -0
  108. package/src/components/Editor/__tests__/Editor.spec.js +3 -4
  109. package/src/components/Editor/__tests__/__snapshots__/Editor.spec.js.snap +5 -5
  110. package/src/components/Editor/__tests__/__snapshots__/EditorToolbar.spec.js.snap +708 -393
  111. package/src/components/MediaLibrary/MediaLibrary.js +5 -1
  112. package/src/components/MediaLibrary/MediaLibraryModal.js +1 -1
  113. package/src/components/UI/ErrorBoundary.js +6 -1
  114. package/src/components/UI/Modal.js +3 -0
  115. package/src/components/Workflow/Workflow.js +3 -0
  116. package/src/components/Workflow/WorkflowList.js +5 -0
  117. package/src/constants/__tests__/configSchema.spec.js +1 -1
  118. package/src/formats/formats.ts +1 -1
  119. package/src/formats/toml.ts +2 -2
  120. package/src/integrations/providers/algolia/implementation.js +2 -2
  121. package/src/integrations/providers/assetStore/implementation.js +2 -1
  122. package/src/lib/formatters.ts +4 -1
  123. package/src/lib/i18n.ts +3 -1
  124. package/src/lib/phrases.js +1 -1
  125. package/src/lib/polyfill.js +9 -0
  126. package/src/lib/serializeEntryValues.js +1 -1
  127. package/src/lib/stega.ts +145 -0
  128. package/src/lib/urlHelper.ts +4 -1
  129. package/src/mediaLibrary.ts +1 -1
  130. package/src/reducers/collections.ts +2 -1
  131. package/src/reducers/editorialWorkflow.ts +1 -1
  132. package/src/reducers/entries.ts +6 -1
  133. package/src/reducers/entryDraft.js +1 -1
  134. package/src/types/immutable.ts +10 -0
  135. package/src/types/redux.ts +2 -0
  136. package/src/valueObjects/EditorComponent.js +1 -1
  137. 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
- constructor(...args) {
21
- super(...args);
22
- _defineProperty(this, "processInnerControlRef", ref => {
23
- if (!ref) return;
24
-
25
- /**
26
- * If the widget is a container that receives state updates from the store,
27
- * we'll need to get the ref of the actual control via the `react-redux`
28
- * `getWrappedInstance` method. Note that connected widgets must pass
29
- * `withRef: true` to `connect` in the options object.
30
- */
31
- this.innerWrappedControl = ref.getWrappedInstance ? ref.getWrappedInstance() : ref;
32
- this.wrappedControlValid = this.innerWrappedControl.isValid || truthy;
33
-
34
- /**
35
- * Get the `shouldComponentUpdate` method from the wrapped control, and
36
- * provide the control instance is the `this` binding.
37
- */
38
- const {
39
- shouldComponentUpdate: scu
40
- } = this.innerWrappedControl;
41
- this.wrappedControlShouldComponentUpdate = scu && scu.bind(this.innerWrappedControl);
42
-
43
- // Call the control ref if provided, passing this Widget instance
44
- if (this.props.controlRef) {
45
- this.props.controlRef(this);
46
- }
47
- });
48
- _defineProperty(this, "getValidateValue", () => {
49
- var _this$innerWrappedCon, _this$innerWrappedCon2;
50
- let value = ((_this$innerWrappedCon = this.innerWrappedControl) === null || _this$innerWrappedCon === void 0 ? void 0 : (_this$innerWrappedCon2 = _this$innerWrappedCon.getValidateValue) === null || _this$innerWrappedCon2 === void 0 ? void 0 : _this$innerWrappedCon2.call(_this$innerWrappedCon)) || this.props.value;
51
- // Convert list input widget value to string for validation test
52
- List.isList(value) && (value = value.join(','));
53
- return value;
54
- });
55
- _defineProperty(this, "validate", (skipWrapped = false) => {
56
- const value = this.getValidateValue();
57
- const field = this.props.field;
58
- const errors = [];
59
- const validations = [this.validatePresence, this.validatePattern];
60
- if (field.get('meta')) {
61
- validations.push(this.props.validateMetaField);
62
- }
63
- validations.forEach(func => {
64
- const response = func(field, value, this.props.t);
65
- if (response.error) errors.push(response.error);
66
- });
67
- if (skipWrapped) {
68
- if (skipWrapped.error) errors.push(skipWrapped.error);
69
- } else {
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 ((_this$innerWrappedCon3 = this.innerWrappedControl) !== null && _this$innerWrappedCon3 !== void 0 && _this$innerWrappedCon3.focus) {
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 === null || element === void 0 ? void 0 : element.focus();
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
+ }