@plone/volto 18.0.0-alpha.41 → 18.0.0-alpha.43
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 +114 -0
- package/finalreleasechangelog.py +48 -0
- package/locales/ca/LC_MESSAGES/volto.po +39 -13
- package/locales/ca.json +1 -1
- package/locales/de/LC_MESSAGES/volto.po +40 -14
- package/locales/de.json +1 -1
- package/locales/en/LC_MESSAGES/volto.po +39 -13
- package/locales/en.json +1 -1
- package/locales/es/LC_MESSAGES/volto.po +40 -14
- package/locales/es.json +1 -1
- package/locales/eu/LC_MESSAGES/volto.po +40 -14
- package/locales/eu.json +1 -1
- package/locales/fi/LC_MESSAGES/volto.po +40 -14
- package/locales/fi.json +1 -1
- package/locales/fr/LC_MESSAGES/volto.po +40 -14
- package/locales/fr.json +1 -1
- package/locales/hi/LC_MESSAGES/volto.po +40 -14
- package/locales/hi.json +1 -1
- package/locales/it/LC_MESSAGES/volto.po +40 -14
- package/locales/it.json +1 -1
- package/locales/ja/LC_MESSAGES/volto.po +39 -13
- package/locales/ja.json +1 -1
- package/locales/nl/LC_MESSAGES/volto.po +39 -13
- package/locales/nl.json +1 -1
- package/locales/pt/LC_MESSAGES/volto.po +39 -13
- package/locales/pt.json +1 -1
- package/locales/pt_BR/LC_MESSAGES/volto.po +40 -14
- package/locales/pt_BR.json +1 -1
- package/locales/ro/LC_MESSAGES/volto.po +39 -13
- package/locales/ro.json +1 -1
- package/locales/volto.pot +40 -14
- package/locales/zh_CN/LC_MESSAGES/volto.po +40 -14
- package/locales/zh_CN.json +1 -1
- package/package.json +5 -6
- package/razzle.config.js +3 -3
- package/src/components/index.js +0 -1
- package/src/components/manage/Actions/Actions.stories.jsx +138 -0
- package/src/components/manage/Add/Add.jsx +7 -4
- package/src/components/manage/BlockChooser/BlockChooser.jsx +9 -1
- package/src/components/manage/Blocks/Block/BlocksForm.jsx +5 -0
- package/src/components/manage/Blocks/Block/Edit.jsx +24 -8
- package/src/components/manage/Blocks/Block/EditBlockWrapper.jsx +17 -1
- package/src/components/manage/Blocks/Block/Order/Item.jsx +8 -2
- package/src/components/manage/Blocks/Block/Order/Order.jsx +2 -0
- package/src/components/manage/Blocks/Container/Data.jsx +10 -2
- package/src/components/manage/Blocks/Grid/View.jsx +3 -0
- package/src/components/manage/Blocks/Image/ImageSidebar.jsx +10 -2
- package/src/components/manage/Blocks/LeadImage/Edit.jsx +74 -126
- package/src/components/manage/Blocks/Listing/ListingData.jsx +10 -2
- package/src/components/manage/Blocks/Maps/MapsSidebar.jsx +3 -1
- package/src/components/manage/Blocks/Search/SearchBlockEdit.jsx +2 -0
- package/src/components/manage/Blocks/Search/SearchBlockView.jsx +18 -2
- package/src/components/manage/Blocks/Search/components/SortOn.jsx +82 -55
- package/src/components/manage/Blocks/Search/hocs/withSearch.jsx +1 -1
- package/src/components/manage/Blocks/Search/widgets/SelectMetadataField.jsx +107 -176
- package/src/components/manage/Blocks/Teaser/Data.jsx +10 -2
- package/src/components/manage/Blocks/Teaser/DefaultBody.jsx +15 -8
- package/src/components/manage/Blocks/ToC/Edit.jsx +36 -28
- package/src/components/manage/Blocks/Video/Edit.jsx +105 -172
- package/src/components/manage/Blocks/Video/Edit.stories.jsx +57 -0
- package/src/components/manage/Blocks/Video/VideoSidebar.jsx +3 -1
- package/src/components/manage/Contents/Contents.jsx +4 -1
- package/src/components/manage/Contents/ContentsBreadcrumbs.stories.jsx +46 -0
- package/src/components/manage/Contents/ContentsPropertiesModal.jsx +85 -52
- package/src/components/manage/Contents/ContentsUploadModal.jsx +230 -323
- package/src/components/manage/Contents/ContentsUploadModal.stories.jsx +56 -0
- package/src/components/manage/Controlpanels/AddonsControlpanel.jsx +323 -441
- package/src/components/manage/Controlpanels/Aliases.jsx +452 -580
- package/src/components/manage/Controlpanels/Aliases.stories.jsx +74 -0
- package/src/components/manage/Controlpanels/ContentTypeSchema.jsx +1 -0
- package/src/components/manage/Controlpanels/Controlpanel.jsx +41 -2
- package/src/components/manage/Controlpanels/Controlpanel.test.jsx +55 -24
- package/src/components/manage/Controlpanels/DatabaseInformation.jsx +162 -229
- package/src/components/manage/Controlpanels/Groups/RenderGroups.jsx +74 -122
- package/src/components/manage/Controlpanels/UndoControlpanel.jsx +3 -3
- package/src/components/manage/Controlpanels/Users/UserGroupMembershipListing.jsx +28 -12
- package/src/components/manage/Controlpanels/Users/UserGroupMembershipMatrix.jsx +12 -4
- package/src/components/manage/Display/Display.jsx +92 -148
- package/src/components/manage/Display/Display.stories.jsx +46 -0
- package/src/components/manage/Edit/Edit.jsx +2 -4
- package/src/components/manage/Form/Form.jsx +85 -20
- package/src/components/manage/Form/InlineForm.jsx +2 -4
- package/src/components/manage/Form/ModalForm.jsx +1 -1
- package/src/components/manage/History/History.jsx +1 -1
- package/src/components/manage/Pluggable/Pluggable.test.js +1 -1
- package/src/components/manage/Preferences/ChangePassword.jsx +94 -172
- package/src/components/manage/Preferences/ChangePassword.stories.jsx +41 -0
- package/src/components/manage/Preferences/PersonalInformation.jsx +50 -115
- package/src/components/manage/Preferences/PersonalPreferences.jsx +46 -100
- package/src/components/manage/Preferences/PersonalPreferences.stories.jsx +48 -0
- package/src/components/manage/Toolbar/More.jsx +308 -399
- package/src/components/manage/Toolbar/Toolbar.jsx +1 -1
- package/src/components/manage/Widgets/ArrayWidget.jsx +2 -2
- package/src/components/manage/Widgets/DatetimeWidget.jsx +121 -175
- package/src/components/manage/Widgets/ImageWidget.jsx +6 -5
- package/src/components/manage/Widgets/RecurrenceWidget/EndField.jsx +7 -1
- package/src/components/manage/Widgets/RecurrenceWidget/RecurrenceWidget.jsx +80 -31
- package/src/components/manage/Widgets/ReferenceWidget.jsx +134 -210
- package/src/components/theme/Register/Register.jsx +70 -142
- package/src/components/theme/Register/Register.stories.jsx +49 -0
- package/src/components/theme/Search/Search.jsx +13 -5
- package/src/components/theme/Tags/Tags.jsx +19 -10
- package/src/components/theme/Tags/Tags.test.jsx +9 -11
- package/src/components/theme/View/AlbumView.jsx +122 -167
- package/src/components/theme/View/LinkView.jsx +4 -0
- package/src/components/theme/View/LinkView.test.jsx +2 -0
- package/src/components/theme/View/View.jsx +0 -13
- package/src/components/theme/View/View.test.jsx +0 -3
- package/src/config/ControlPanels.js +49 -43
- package/src/config/Widgets.jsx +1 -1
- package/src/config/config.test.js +1 -0
- package/src/config/index.js +23 -2
- package/src/config/slots.js +12 -0
- package/src/config/validation.ts +155 -0
- package/src/helpers/Blocks/Blocks.js +12 -7
- package/src/helpers/Blocks/Blocks.test.js +15 -0
- package/src/helpers/Blocks/cloneBlocks.ts +1 -1
- package/src/helpers/Extensions/withBlockExtensions.jsx +1 -1
- package/src/helpers/FormValidation/FormValidation.jsx +128 -172
- package/src/helpers/FormValidation/FormValidation.test.js +836 -8
- package/src/helpers/FormValidation/validators.ts +203 -0
- package/src/helpers/MessageLabels/MessageLabels.js +28 -0
- package/src/helpers/Url/Url.test.js +19 -6
- package/src/helpers/Url/urlRegex.js +1 -1
- package/src/helpers/User/User.js +1 -1
- package/src/helpers/index.js +2 -0
- package/src/hooks/client/useClient.js +1 -1
- package/src/middleware/api.js +4 -2
- package/src/middleware/index.js +1 -0
- package/src/middleware/userSessionReset.js +46 -0
- package/src/store.js +2 -0
- package/test-setup-config.jsx +10 -0
- package/theme/themes/default/modules/embed.variables +1 -1
- package/theme/themes/pastanaga/collections/form.overrides +34 -0
- package/theme/themes/pastanaga/extras/blocks.less +6 -0
- package/theme/themes/pastanaga/extras/sidebar.less +4 -0
- package/theme/themes/pastanaga/extras/toolbar.less +10 -3
- package/tsconfig.declarations.json +3 -2
- package/types/components/index.d.ts +0 -1
- package/types/components/manage/Actions/Actions.stories.d.ts +8 -0
- package/types/components/manage/Blocks/Block/Order/Order.d.ts +2 -1
- package/types/components/manage/Blocks/LeadImage/Edit.d.ts +14 -5
- package/types/components/manage/Blocks/Search/widgets/SelectMetadataField.d.ts +0 -5
- package/types/components/manage/Blocks/ToC/Edit.d.ts +1 -6
- package/types/components/manage/Blocks/Video/Edit.d.ts +1 -1
- package/types/components/manage/Blocks/Video/Edit.stories.d.ts +8 -0
- package/types/components/manage/Contents/ContentsBreadcrumbs.stories.d.ts +8 -0
- package/types/components/manage/Contents/ContentsUploadModal.d.ts +14 -2
- package/types/components/manage/Contents/ContentsUploadModal.stories.d.ts +8 -0
- package/types/components/manage/Contents/index.d.ts +1 -1
- package/types/components/manage/Controlpanels/AddonsControlpanel.d.ts +2 -2
- package/types/components/manage/Controlpanels/Aliases.d.ts +2 -2
- package/types/components/manage/Controlpanels/Aliases.stories.d.ts +8 -0
- package/types/components/manage/Controlpanels/DatabaseInformation.d.ts +2 -2
- package/types/components/manage/Controlpanels/Groups/RenderGroups.d.ts +10 -5
- package/types/components/manage/Controlpanels/index.d.ts +4 -4
- package/types/components/manage/Display/Display.stories.d.ts +8 -0
- package/types/components/manage/Preferences/ChangePassword.d.ts +2 -2
- package/types/components/manage/Preferences/ChangePassword.stories.d.ts +8 -0
- package/types/components/manage/Preferences/PersonalInformation.d.ts +7 -2
- package/types/components/manage/Preferences/PersonalPreferences.d.ts +5 -1
- package/types/components/manage/Preferences/PersonalPreferences.stories.d.ts +8 -0
- package/types/components/manage/Toolbar/More.d.ts +8 -5
- package/types/components/manage/Widgets/DatetimeWidget.d.ts +0 -85
- package/types/components/manage/Widgets/DatetimeWidget.stories.d.ts +0 -1
- package/types/components/manage/Widgets/ReferenceWidget.d.ts +27 -2
- package/types/components/manage/Widgets/index.d.ts +1 -1
- package/types/components/theme/Register/Register.d.ts +2 -2
- package/types/components/theme/Register/Register.stories.d.ts +9 -0
- package/types/components/theme/Tags/Tags.d.ts +15 -7
- package/types/components/theme/View/AlbumView.d.ts +3 -17
- package/types/config/ControlPanels.d.ts +8 -0
- package/types/config/RichTextEditor/ToHTML.d.ts +1 -1
- package/types/config/Widgets.d.ts +3 -3
- package/types/config/slots.d.ts +21 -0
- package/types/config/validation.d.ts +3 -0
- package/types/helpers/Blocks/Blocks.d.ts +6 -0
- package/types/helpers/Extensions/withBlockExtensions.d.ts +1 -1
- package/types/helpers/FormValidation/FormValidation.d.ts +2 -0
- package/types/helpers/FormValidation/validators.d.ts +29 -0
- package/types/helpers/MessageLabels/MessageLabels.d.ts +36 -0
- package/types/helpers/User/User.d.ts +1 -1
- package/types/helpers/index.d.ts +2 -2
- package/types/middleware/index.d.ts +1 -0
- package/types/middleware/userSessionReset.d.ts +5 -0
- package/src/components/theme/SocialSharing/SocialSharing.jsx +0 -48
- package/src/components/theme/SocialSharing/SocialSharing.test.jsx +0 -14
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { map,
|
|
2
|
-
import { messages } from '
|
|
1
|
+
import { map, keys, intersection, isEmpty } from 'lodash';
|
|
2
|
+
import { messages } from '@plone/volto/helpers/MessageLabels/MessageLabels';
|
|
3
3
|
import config from '@plone/volto/registry';
|
|
4
4
|
import { toast } from 'react-toastify';
|
|
5
5
|
import Toast from '@plone/volto/components/manage/Toast/Toast';
|
|
@@ -11,7 +11,12 @@ import Toast from '@plone/volto/components/manage/Toast/Toast';
|
|
|
11
11
|
* @param {string | number} valueToCompare can compare '47' < 50
|
|
12
12
|
* @param {Function} intlFunc
|
|
13
13
|
*/
|
|
14
|
-
const validationMessage = (
|
|
14
|
+
export const validationMessage = (
|
|
15
|
+
isValid,
|
|
16
|
+
criterion,
|
|
17
|
+
valueToCompare,
|
|
18
|
+
intlFunc,
|
|
19
|
+
) =>
|
|
15
20
|
!isValid
|
|
16
21
|
? intlFunc(messages[criterion], {
|
|
17
22
|
len: valueToCompare,
|
|
@@ -19,142 +24,7 @@ const validationMessage = (isValid, criterion, valueToCompare, intlFunc) =>
|
|
|
19
24
|
: null;
|
|
20
25
|
|
|
21
26
|
/**
|
|
22
|
-
*
|
|
23
|
-
* @param {string | number} value can compare '47' < 50
|
|
24
|
-
* @param {string | number} valueToCompare can compare '47' < 50
|
|
25
|
-
* @param {string} maxCriterion
|
|
26
|
-
* @param {Function} intlFunc
|
|
27
|
-
*/
|
|
28
|
-
const isMaxPropertyValid = (value, valueToCompare, maxCriterion, intlFunc) => {
|
|
29
|
-
const isValid = valueToCompare !== undefined ? value <= valueToCompare : true;
|
|
30
|
-
return validationMessage(isValid, maxCriterion, valueToCompare, intlFunc);
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Returns if based on the criterion the value is higher or equal
|
|
35
|
-
* @param {string | number} value can compare '47' < 50
|
|
36
|
-
* @param {string | number} valueToCompare can compare '47' < 50
|
|
37
|
-
* @param {string} minCriterion
|
|
38
|
-
* @param {Function} intlFunc
|
|
39
|
-
*/
|
|
40
|
-
const isMinPropertyValid = (value, valueToCompare, minCriterion, intlFunc) => {
|
|
41
|
-
const isValid = valueToCompare !== undefined ? value >= valueToCompare : true;
|
|
42
|
-
return validationMessage(isValid, minCriterion, valueToCompare, intlFunc);
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const widgetValidation = {
|
|
46
|
-
email: {
|
|
47
|
-
isValidEmail: (emailValue, emailObj, intlFunc) => {
|
|
48
|
-
// Email Regex taken from from WHATWG living standard:
|
|
49
|
-
// https://html.spec.whatwg.org/multipage/input.html#e-mail-state-(type=email)
|
|
50
|
-
const emailRegex =
|
|
51
|
-
/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
|
|
52
|
-
const isValid = emailRegex.test(emailValue);
|
|
53
|
-
return !isValid ? intlFunc(messages.isValidEmail) : null;
|
|
54
|
-
},
|
|
55
|
-
minLength: (emailValue, emailObj, intlFunc) =>
|
|
56
|
-
isMinPropertyValid(
|
|
57
|
-
emailValue.length,
|
|
58
|
-
emailObj.minLength,
|
|
59
|
-
'minLength',
|
|
60
|
-
intlFunc,
|
|
61
|
-
),
|
|
62
|
-
maxLength: (emailValue, emailObj, intlFunc) =>
|
|
63
|
-
isMaxPropertyValid(
|
|
64
|
-
emailValue.length,
|
|
65
|
-
emailObj.maxLength,
|
|
66
|
-
'maxLength',
|
|
67
|
-
intlFunc,
|
|
68
|
-
),
|
|
69
|
-
},
|
|
70
|
-
url: {
|
|
71
|
-
isValidURL: (urlValue, urlObj, intlFunc) => {
|
|
72
|
-
var urlRegex = new RegExp(
|
|
73
|
-
'^(https?:\\/\\/)?' + // validate protocol
|
|
74
|
-
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // validate domain name
|
|
75
|
-
'((\\d{1,3}\\.){3}\\d{1,3}))|' + // validate OR ip (v4) address
|
|
76
|
-
'(localhost)' + // validate OR localhost address
|
|
77
|
-
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // validate port and path
|
|
78
|
-
'(\\?[;&a-z\\d%_.~+=-]*)?' + // validate query string
|
|
79
|
-
'(\\#[-a-z\\d_]*)?$', // validate fragment locator
|
|
80
|
-
'i',
|
|
81
|
-
);
|
|
82
|
-
const isValid = urlRegex.test(urlValue);
|
|
83
|
-
return !isValid ? intlFunc(messages.isValidURL) : null;
|
|
84
|
-
},
|
|
85
|
-
minLength: (urlValue, urlObj, intlFunc) =>
|
|
86
|
-
isMinPropertyValid(
|
|
87
|
-
urlValue.length,
|
|
88
|
-
urlObj.minLength,
|
|
89
|
-
'minLength',
|
|
90
|
-
intlFunc,
|
|
91
|
-
),
|
|
92
|
-
maxLength: (urlValue, urlObj, intlFunc) =>
|
|
93
|
-
isMaxPropertyValid(
|
|
94
|
-
urlValue.length,
|
|
95
|
-
urlObj.maxLength,
|
|
96
|
-
'maxLength',
|
|
97
|
-
intlFunc,
|
|
98
|
-
),
|
|
99
|
-
},
|
|
100
|
-
password: {
|
|
101
|
-
minLength: (passwordValue, passwordObj, intlFunc) =>
|
|
102
|
-
isMinPropertyValid(
|
|
103
|
-
passwordValue.length,
|
|
104
|
-
passwordObj.minLength,
|
|
105
|
-
'minLength',
|
|
106
|
-
intlFunc,
|
|
107
|
-
),
|
|
108
|
-
maxLength: (passwordValue, passwordObj, intlFunc) =>
|
|
109
|
-
isMaxPropertyValid(
|
|
110
|
-
passwordValue.length,
|
|
111
|
-
passwordObj.maxLength,
|
|
112
|
-
'maxLength',
|
|
113
|
-
intlFunc,
|
|
114
|
-
),
|
|
115
|
-
},
|
|
116
|
-
string: {
|
|
117
|
-
minLength: (value, itemObj, intlFunc) =>
|
|
118
|
-
isMinPropertyValid(
|
|
119
|
-
value.length,
|
|
120
|
-
itemObj.minLength,
|
|
121
|
-
'minLength',
|
|
122
|
-
intlFunc,
|
|
123
|
-
),
|
|
124
|
-
maxLength: (value, itemObj, intlFunc) =>
|
|
125
|
-
isMaxPropertyValid(
|
|
126
|
-
value.length,
|
|
127
|
-
itemObj.maxLength,
|
|
128
|
-
'maxLength',
|
|
129
|
-
intlFunc,
|
|
130
|
-
),
|
|
131
|
-
},
|
|
132
|
-
number: {
|
|
133
|
-
isNumber: (value, itemObj, intlFunc) => {
|
|
134
|
-
const floatRegex = /^[+-]?\d+(\.\d+)?$/;
|
|
135
|
-
const isValid = !isNaN(value) && floatRegex.test(value);
|
|
136
|
-
return !isValid ? intlFunc(messages.isNumber) : null;
|
|
137
|
-
},
|
|
138
|
-
minimum: (value, itemObj, intlFunc) =>
|
|
139
|
-
isMinPropertyValid(value, itemObj.minimum, 'minimum', intlFunc),
|
|
140
|
-
maximum: (value, itemObj, intlFunc) =>
|
|
141
|
-
isMaxPropertyValid(value, itemObj.maximum, 'maximum', intlFunc),
|
|
142
|
-
},
|
|
143
|
-
integer: {
|
|
144
|
-
isInteger: (value, itemObj, intlFunc) => {
|
|
145
|
-
const intRegex = /^-?[0-9]+$/;
|
|
146
|
-
const isValid = !isNaN(value) && intRegex.test(value);
|
|
147
|
-
return !isValid ? intlFunc(messages.isInteger) : null;
|
|
148
|
-
},
|
|
149
|
-
minimum: (value, itemObj, intlFunc) =>
|
|
150
|
-
isMinPropertyValid(value, itemObj.minimum, 'minimum', intlFunc),
|
|
151
|
-
maximum: (value, itemObj, intlFunc) =>
|
|
152
|
-
isMaxPropertyValid(value, itemObj.maximum, 'maximum', intlFunc),
|
|
153
|
-
},
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* The string that comes my not be a valid JSON
|
|
27
|
+
* The string that comes might not be a valid JSON
|
|
158
28
|
* @param {string} requestItem
|
|
159
29
|
*/
|
|
160
30
|
export const tryParseJSON = (requestItem) => {
|
|
@@ -165,30 +35,19 @@ export const tryParseJSON = (requestItem) => {
|
|
|
165
35
|
try {
|
|
166
36
|
resultObj = JSON.parse(requestItem.replace(/'/g, '"'));
|
|
167
37
|
} catch (e) {
|
|
168
|
-
|
|
38
|
+
try {
|
|
39
|
+
// Treats strings like: `'String "double quotes"'`
|
|
40
|
+
resultObj = JSON.parse(
|
|
41
|
+
requestItem.replace(/"/g, '\\"').replace(/'/g, '"'),
|
|
42
|
+
);
|
|
43
|
+
} catch (e) {
|
|
44
|
+
resultObj = null;
|
|
45
|
+
}
|
|
169
46
|
}
|
|
170
47
|
}
|
|
171
48
|
return resultObj;
|
|
172
49
|
};
|
|
173
50
|
|
|
174
|
-
/**
|
|
175
|
-
* Returns errors if obj has unique Items
|
|
176
|
-
* @param {Object} field
|
|
177
|
-
* @param {*} fieldData
|
|
178
|
-
* @returns {Object[string]} - list of errors
|
|
179
|
-
*/
|
|
180
|
-
const hasUniqueItems = (field, fieldData, formatMessage) => {
|
|
181
|
-
const errors = [];
|
|
182
|
-
if (
|
|
183
|
-
field.uniqueItems &&
|
|
184
|
-
fieldData &&
|
|
185
|
-
uniq(fieldData).length !== fieldData.length
|
|
186
|
-
) {
|
|
187
|
-
errors.push(formatMessage(messages.uniqueItems));
|
|
188
|
-
}
|
|
189
|
-
return errors;
|
|
190
|
-
};
|
|
191
|
-
|
|
192
51
|
/**
|
|
193
52
|
* If required fields are undefined, return list of errors
|
|
194
53
|
* @returns {Object[string]} - list of errors
|
|
@@ -252,35 +111,122 @@ const validateFieldsPerFieldset = (
|
|
|
252
111
|
touchedField,
|
|
253
112
|
);
|
|
254
113
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
const widgetValidationCriteria = widgetValidation[fieldWidgetType]
|
|
258
|
-
? Object.keys(widgetValidation[fieldWidgetType])
|
|
259
|
-
: [];
|
|
260
|
-
let fieldData = formData[fieldId];
|
|
261
|
-
// test each criterion ex maximum, isEmail, isUrl, maxLength etc
|
|
262
|
-
const fieldErrors = widgetValidationCriteria
|
|
114
|
+
function checkFieldErrors(fieldValidationCriteria, field, fieldData) {
|
|
115
|
+
return fieldValidationCriteria
|
|
263
116
|
.map((widgetCriterion) => {
|
|
264
117
|
const errorMessage =
|
|
265
118
|
fieldData === undefined || fieldData === null
|
|
266
119
|
? null
|
|
267
|
-
:
|
|
268
|
-
fieldData,
|
|
120
|
+
: widgetCriterion.method({
|
|
121
|
+
value: fieldData,
|
|
269
122
|
field,
|
|
123
|
+
formData,
|
|
270
124
|
formatMessage,
|
|
271
|
-
);
|
|
125
|
+
});
|
|
272
126
|
return errorMessage;
|
|
273
127
|
})
|
|
274
128
|
.filter((item) => !!item);
|
|
129
|
+
}
|
|
275
130
|
|
|
276
|
-
|
|
277
|
-
|
|
131
|
+
Object.entries(schema.properties).forEach(([fieldId, field]) => {
|
|
132
|
+
let fieldData = formData[fieldId];
|
|
133
|
+
|
|
134
|
+
// Validation per specific validator set (format property)
|
|
135
|
+
const hasSpecificValidator =
|
|
136
|
+
field.widgetOptions?.frontendOptions?.format || field.format;
|
|
137
|
+
let specificFieldErrors = [];
|
|
138
|
+
if (hasSpecificValidator) {
|
|
139
|
+
const specificValidationCriteria = config.getUtilities({
|
|
140
|
+
type: 'validator',
|
|
141
|
+
dependencies: { format: hasSpecificValidator },
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
specificFieldErrors = checkFieldErrors(
|
|
145
|
+
specificValidationCriteria,
|
|
146
|
+
field,
|
|
147
|
+
fieldData,
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Validation per field type
|
|
152
|
+
const fieldType = field.type || 'string'; // defaults to string
|
|
153
|
+
const fieldTypeValidationCriteria = config.getUtilities({
|
|
154
|
+
type: 'validator',
|
|
155
|
+
dependencies: { fieldType },
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
const fieldErrors = checkFieldErrors(
|
|
159
|
+
fieldTypeValidationCriteria,
|
|
160
|
+
field,
|
|
161
|
+
fieldData,
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
// Validation per field widget
|
|
165
|
+
const widgetName =
|
|
166
|
+
field.widgetOptions?.frontendOptions?.widget || field.widget || '';
|
|
167
|
+
|
|
168
|
+
let widgetErrors = [];
|
|
169
|
+
if (widgetName) {
|
|
170
|
+
const widgetNameValidationCriteria = config.getUtilities({
|
|
171
|
+
type: 'validator',
|
|
172
|
+
dependencies: { widget: widgetName },
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
widgetErrors = checkFieldErrors(
|
|
176
|
+
widgetNameValidationCriteria,
|
|
177
|
+
field,
|
|
178
|
+
fieldData,
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Validation per specific behavior and field name (for content types)
|
|
183
|
+
const behaviorName = field.behavior;
|
|
184
|
+
let perBehaviorFieldErrors = [];
|
|
185
|
+
if (behaviorName) {
|
|
186
|
+
const specificPerBehaviorFieldValidationCriteria = config.getUtilities({
|
|
187
|
+
type: 'validator',
|
|
188
|
+
dependencies: { behaviorName, fieldName: fieldId },
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
perBehaviorFieldErrors = checkFieldErrors(
|
|
192
|
+
specificPerBehaviorFieldValidationCriteria,
|
|
193
|
+
field,
|
|
194
|
+
fieldData,
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Validation per block type validator (for blocks)
|
|
199
|
+
const blockType = formData['@type'];
|
|
200
|
+
let blockTypeFieldErrors = [];
|
|
201
|
+
if (blockType) {
|
|
202
|
+
const blockTypeFieldValidationCriteria = config.getUtilities({
|
|
203
|
+
type: 'validator',
|
|
204
|
+
dependencies: { blockType, fieldName: fieldId },
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
blockTypeFieldErrors = checkFieldErrors(
|
|
208
|
+
blockTypeFieldValidationCriteria,
|
|
209
|
+
field,
|
|
210
|
+
fieldData,
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const mergedErrors = [
|
|
215
|
+
...specificFieldErrors,
|
|
216
|
+
...fieldErrors,
|
|
217
|
+
...widgetErrors,
|
|
218
|
+
...perBehaviorFieldErrors,
|
|
219
|
+
...blockTypeFieldErrors,
|
|
220
|
+
];
|
|
278
221
|
|
|
279
222
|
if (mergedErrors.length > 0) {
|
|
280
223
|
errors[fieldId] = [
|
|
281
224
|
...(errors[fieldId] || []),
|
|
225
|
+
...specificFieldErrors,
|
|
282
226
|
...fieldErrors,
|
|
283
|
-
...
|
|
227
|
+
...widgetErrors,
|
|
228
|
+
...perBehaviorFieldErrors,
|
|
229
|
+
...blockTypeFieldErrors,
|
|
284
230
|
];
|
|
285
231
|
}
|
|
286
232
|
});
|
|
@@ -399,3 +345,13 @@ export const validateFileUploadSize = (file, intlFunc) => {
|
|
|
399
345
|
}
|
|
400
346
|
return isValid;
|
|
401
347
|
};
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Extract invariant errors given an array of errors.
|
|
351
|
+
* @param {Array} erros
|
|
352
|
+
*/
|
|
353
|
+
export const extractInvariantErrors = (erros) => {
|
|
354
|
+
return erros
|
|
355
|
+
.filter((errorItem) => !('field' in errorItem))
|
|
356
|
+
.map((errorItem) => errorItem['message']);
|
|
357
|
+
};
|