@plone/volto 18.24.0 → 18.25.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.
Files changed (140) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +0 -1
  3. package/cypress/support/commands.js +8 -6
  4. package/locales/af/LC_MESSAGES/volto.po +10 -0
  5. package/locales/af.json +1 -1
  6. package/locales/ar/LC_MESSAGES/volto.po +10 -0
  7. package/locales/ar.json +1 -1
  8. package/locales/bg/LC_MESSAGES/volto.po +10 -0
  9. package/locales/bg.json +1 -1
  10. package/locales/bn/LC_MESSAGES/volto.po +10 -0
  11. package/locales/bn.json +1 -1
  12. package/locales/ca/LC_MESSAGES/volto.po +10 -0
  13. package/locales/ca.json +1 -1
  14. package/locales/cs/LC_MESSAGES/volto.po +10 -0
  15. package/locales/cs.json +1 -1
  16. package/locales/cy/LC_MESSAGES/volto.po +10 -0
  17. package/locales/cy.json +1 -1
  18. package/locales/da/LC_MESSAGES/volto.po +10 -0
  19. package/locales/da.json +1 -1
  20. package/locales/de/LC_MESSAGES/volto.po +10 -0
  21. package/locales/de.json +1 -1
  22. package/locales/el/LC_MESSAGES/volto.po +10 -0
  23. package/locales/el.json +1 -1
  24. package/locales/en/LC_MESSAGES/volto.po +10 -0
  25. package/locales/en.json +1 -1
  26. package/locales/en_AU/LC_MESSAGES/volto.po +10 -0
  27. package/locales/en_AU.json +1 -1
  28. package/locales/en_GB/LC_MESSAGES/volto.po +10 -0
  29. package/locales/en_GB.json +1 -1
  30. package/locales/eo/LC_MESSAGES/volto.po +10 -0
  31. package/locales/eo.json +1 -1
  32. package/locales/es/LC_MESSAGES/volto.po +10 -0
  33. package/locales/es.json +1 -1
  34. package/locales/et/LC_MESSAGES/volto.po +10 -0
  35. package/locales/et.json +1 -1
  36. package/locales/eu/LC_MESSAGES/volto.po +10 -0
  37. package/locales/eu.json +1 -1
  38. package/locales/fa/LC_MESSAGES/volto.po +10 -0
  39. package/locales/fa.json +1 -1
  40. package/locales/fi/LC_MESSAGES/volto.po +10 -0
  41. package/locales/fi.json +1 -1
  42. package/locales/fr/LC_MESSAGES/volto.po +10 -0
  43. package/locales/fr.json +1 -1
  44. package/locales/fu/LC_MESSAGES/volto.po +10 -0
  45. package/locales/fu.json +1 -1
  46. package/locales/gl/LC_MESSAGES/volto.po +10 -0
  47. package/locales/gl.json +1 -1
  48. package/locales/he/LC_MESSAGES/volto.po +10 -0
  49. package/locales/he.json +1 -1
  50. package/locales/hi/LC_MESSAGES/volto.po +10 -0
  51. package/locales/hi.json +1 -1
  52. package/locales/hr/LC_MESSAGES/volto.po +10 -0
  53. package/locales/hr.json +1 -1
  54. package/locales/hu/LC_MESSAGES/volto.po +10 -0
  55. package/locales/hu.json +1 -1
  56. package/locales/hy/LC_MESSAGES/volto.po +10 -0
  57. package/locales/hy.json +1 -1
  58. package/locales/id/LC_MESSAGES/volto.po +10 -0
  59. package/locales/id.json +1 -1
  60. package/locales/it/LC_MESSAGES/volto.po +10 -0
  61. package/locales/it.json +1 -1
  62. package/locales/ja/LC_MESSAGES/volto.po +10 -0
  63. package/locales/ja.json +1 -1
  64. package/locales/ka/LC_MESSAGES/volto.po +10 -0
  65. package/locales/ka.json +1 -1
  66. package/locales/kn/LC_MESSAGES/volto.po +10 -0
  67. package/locales/kn.json +1 -1
  68. package/locales/ko/LC_MESSAGES/volto.po +10 -0
  69. package/locales/ko.json +1 -1
  70. package/locales/lt/LC_MESSAGES/volto.po +10 -0
  71. package/locales/lt.json +1 -1
  72. package/locales/lv/LC_MESSAGES/volto.po +10 -0
  73. package/locales/lv.json +1 -1
  74. package/locales/mi/LC_MESSAGES/volto.po +10 -0
  75. package/locales/mi.json +1 -1
  76. package/locales/mk/LC_MESSAGES/volto.po +10 -0
  77. package/locales/mk.json +1 -1
  78. package/locales/my/LC_MESSAGES/volto.po +10 -0
  79. package/locales/my.json +1 -1
  80. package/locales/nb_NO/LC_MESSAGES/volto.po +10 -0
  81. package/locales/nb_NO.json +1 -1
  82. package/locales/nl/LC_MESSAGES/volto.po +10 -0
  83. package/locales/nl.json +1 -1
  84. package/locales/nn/LC_MESSAGES/volto.po +10 -0
  85. package/locales/nn.json +1 -1
  86. package/locales/pl/LC_MESSAGES/volto.po +10 -0
  87. package/locales/pl.json +1 -1
  88. package/locales/pt/LC_MESSAGES/volto.po +10 -0
  89. package/locales/pt.json +1 -1
  90. package/locales/pt_BR/LC_MESSAGES/volto.po +10 -0
  91. package/locales/pt_BR.json +1 -1
  92. package/locales/rm/LC_MESSAGES/volto.po +10 -0
  93. package/locales/rm.json +1 -1
  94. package/locales/ro/LC_MESSAGES/volto.po +10 -0
  95. package/locales/ro.json +1 -1
  96. package/locales/ru/LC_MESSAGES/volto.po +10 -0
  97. package/locales/ru.json +1 -1
  98. package/locales/sk/LC_MESSAGES/volto.po +10 -0
  99. package/locales/sk.json +1 -1
  100. package/locales/sl/LC_MESSAGES/volto.po +10 -0
  101. package/locales/sl.json +1 -1
  102. package/locales/sm/LC_MESSAGES/volto.po +10 -0
  103. package/locales/sm.json +1 -1
  104. package/locales/sq/LC_MESSAGES/volto.po +10 -0
  105. package/locales/sq.json +1 -1
  106. package/locales/sr/LC_MESSAGES/volto.po +10 -0
  107. package/locales/sr.json +1 -1
  108. package/locales/sr@cyrl/LC_MESSAGES/volto.po +10 -0
  109. package/locales/sr@cyrl.json +1 -1
  110. package/locales/sr@latn/LC_MESSAGES/volto.po +10 -0
  111. package/locales/sr@latn.json +1 -1
  112. package/locales/sv/LC_MESSAGES/volto.po +10 -0
  113. package/locales/sv.json +1 -1
  114. package/locales/ta/LC_MESSAGES/volto.po +10 -0
  115. package/locales/ta.json +1 -1
  116. package/locales/te/LC_MESSAGES/volto.po +10 -0
  117. package/locales/te.json +1 -1
  118. package/locales/th/LC_MESSAGES/volto.po +10 -0
  119. package/locales/th.json +1 -1
  120. package/locales/to/LC_MESSAGES/volto.po +10 -0
  121. package/locales/to.json +1 -1
  122. package/locales/tr/LC_MESSAGES/volto.po +10 -0
  123. package/locales/tr.json +1 -1
  124. package/locales/uk/LC_MESSAGES/volto.po +10 -0
  125. package/locales/uk.json +1 -1
  126. package/locales/vi/LC_MESSAGES/volto.po +10 -0
  127. package/locales/vi.json +1 -1
  128. package/locales/volto.pot +10 -0
  129. package/locales/zh_CN/LC_MESSAGES/volto.po +10 -0
  130. package/locales/zh_CN.json +1 -1
  131. package/locales/zh_Hant/LC_MESSAGES/volto.po +10 -0
  132. package/locales/zh_Hant.json +1 -1
  133. package/locales/zh_Hant_HK/LC_MESSAGES/volto.po +10 -0
  134. package/locales/zh_Hant_HK.json +1 -1
  135. package/package.json +5 -5
  136. package/src/components/manage/Blocks/Image/Edit.jsx +5 -1
  137. package/src/components/manage/Widgets/ImageWidget.jsx +159 -33
  138. package/src/components/manage/Widgets/RegistryImageWidget.test.jsx +1 -1
  139. package/theme/themes/pastanaga/extras/blocks.less +19 -0
  140. package/types/components/manage/Widgets/ImageWidget.d.ts +41 -1
@@ -9,11 +9,14 @@ import { compose } from 'redux';
9
9
  import { toast } from 'react-toastify';
10
10
  import useLinkEditor from '@plone/volto/components/manage/AnchorPlugin/useLinkEditor';
11
11
  import withObjectBrowser from '@plone/volto/components/manage/Sidebar/ObjectBrowser';
12
+ import config from '@plone/volto/registry';
12
13
 
13
14
  import {
14
15
  flattenToAppURL,
15
16
  getBaseUrl,
16
17
  isInternalURL,
18
+ normalizeUrl,
19
+ removeProtocol,
17
20
  } from '@plone/volto/helpers/Url/Url';
18
21
  import { validateFileUploadSize } from '@plone/volto/helpers/FormValidation/FormValidation';
19
22
  import { usePrevious } from '@plone/volto/helpers/Utils/usePrevious';
@@ -28,6 +31,9 @@ import clearSVG from '@plone/volto/icons/clear.svg';
28
31
  import navTreeSVG from '@plone/volto/icons/nav.svg';
29
32
  import linkSVG from '@plone/volto/icons/link.svg';
30
33
  import uploadSVG from '@plone/volto/icons/upload.svg';
34
+ import Image from '../../theme/Image/Image';
35
+ import { urlValidator } from '@plone/volto/helpers/FormValidation/validators';
36
+ import { searchContent } from '@plone/volto/actions/search/search';
31
37
 
32
38
  const Dropzone = loadable(() => import('react-dropzone'));
33
39
 
@@ -70,6 +76,14 @@ const messages = defineMessages({
70
76
  id: 'imageUploadErrorMessage',
71
77
  defaultMessage: 'Please upload an image instead.',
72
78
  },
79
+ externalURLsNotAllowed: {
80
+ id: 'externalURLsNotAllowed',
81
+ defaultMessage: 'External URLs are not allowed in this field.',
82
+ },
83
+ internalImageNotFoundErrorMessage: {
84
+ id: 'internalImageNotFoundErrorMessage',
85
+ defaultMessage: 'No image was found in the internal path you provided.',
86
+ },
73
87
  });
74
88
 
75
89
  const UnconnectedImageInput = (props) => {
@@ -89,7 +103,7 @@ const UnconnectedImageInput = (props) => {
89
103
  placeholderLinkInput = '',
90
104
  onSelectItem,
91
105
  } = props;
92
- const imageValue = value?.[0]?.['@id'] || value;
106
+ const imageValue = value?.[0]?.['@id'] || value?.['@id'] || value;
93
107
 
94
108
  const intl = useIntl();
95
109
  const linkEditor = useLinkEditor();
@@ -109,16 +123,34 @@ const UnconnectedImageInput = (props) => {
109
123
  const imageId = content?.['@id'];
110
124
  const image = content?.image;
111
125
  let loading = false;
126
+ const isRelationChoice = props.factory === 'Relation Choice';
112
127
 
113
128
  useEffect(() => {
114
129
  if (uploading && loading && loaded) {
115
130
  setUploading(false);
116
- onChange(id, imageId, {
117
- image_field: 'image',
118
- image_scales: { image: [image] },
119
- });
131
+ if (isRelationChoice) {
132
+ onChange(id, content, {
133
+ image_field: 'image',
134
+ image_scales: { image: [image] },
135
+ });
136
+ } else {
137
+ onChange(id, imageId, {
138
+ image_field: 'image',
139
+ image_scales: { image: [image] },
140
+ });
141
+ }
120
142
  }
121
- }, [loading, loaded, uploading, imageId, image, id, onChange]); // Explicitly list all dependencies
143
+ }, [
144
+ loading,
145
+ loaded,
146
+ uploading,
147
+ imageId,
148
+ image,
149
+ id,
150
+ content,
151
+ isRelationChoice,
152
+ onChange,
153
+ ]);
122
154
 
123
155
  loading = usePrevious(props.request?.loading);
124
156
 
@@ -170,6 +202,83 @@ const UnconnectedImageInput = (props) => {
170
202
  }, [restrictFileUpload]);
171
203
  const onDragLeave = React.useCallback(() => setDragging(false), []);
172
204
 
205
+ const validateManualLink = React.useCallback(
206
+ (url) => {
207
+ if (!url.startsWith('/')) {
208
+ const error = urlValidator({
209
+ value: url,
210
+ formatMessage: intl.formatMessage,
211
+ });
212
+ // if (error && url !== '') {
213
+ // this.setState({ errors: [error] });
214
+ // } else {
215
+ // this.setState({ errors: [] });
216
+ // }
217
+ return !Boolean(error);
218
+ } else {
219
+ return isInternalURL(url);
220
+ }
221
+ },
222
+ [intl.formatMessage],
223
+ );
224
+
225
+ const onSubmitURL = React.useCallback(
226
+ (url) => {
227
+ if (validateManualLink(url)) {
228
+ if (isInternalURL(url)) {
229
+ // convert it into an internal on if possible
230
+ props
231
+ .searchContent(
232
+ '/',
233
+ {
234
+ portal_type: config.settings.imageObjects,
235
+ 'path.query': flattenToAppURL(url),
236
+ 'path.depth': '0',
237
+ sort_on: 'getObjPositionInParent',
238
+ metadata_fields: '_all',
239
+ b_size: 1000,
240
+ },
241
+ `${props.block}-${props.mode}`,
242
+ )
243
+ .then((resp) => {
244
+ if (resp.items?.length > 0) {
245
+ onChange(props.id, resp.items[0], {});
246
+ } else {
247
+ toast.error(
248
+ <Toast
249
+ error
250
+ title={intl.formatMessage(messages.Error)}
251
+ content={intl.formatMessage(
252
+ messages.internalImageNotFoundErrorMessage,
253
+ )}
254
+ />,
255
+ );
256
+ }
257
+ });
258
+ } else {
259
+ if (isRelationChoice) {
260
+ toast.error(
261
+ <Toast
262
+ error
263
+ title={intl.formatMessage(messages.Error)}
264
+ content={intl.formatMessage(messages.imageUploadErrorMessage)}
265
+ />,
266
+ );
267
+ } else {
268
+ // if it's an external link, we save it as is
269
+ onChange(props.id, [
270
+ {
271
+ '@id': normalizeUrl(url),
272
+ title: removeProtocol(url),
273
+ },
274
+ ]);
275
+ }
276
+ }
277
+ }
278
+ },
279
+ [validateManualLink, props, intl, isRelationChoice, onChange],
280
+ );
281
+
173
282
  return imageValue ? (
174
283
  <div
175
284
  className="image-upload-widget-image"
@@ -178,15 +287,20 @@ const UnconnectedImageInput = (props) => {
178
287
  role="toolbar"
179
288
  >
180
289
  {selected && <ImageToolbar {...props} />}
181
- <img
182
- className={props.className}
183
- src={
184
- isInternalURL(imageValue)
185
- ? `${flattenToAppURL(imageValue)}/@@images/image/${imageSize}`
186
- : imageValue
187
- }
188
- alt=""
189
- />
290
+ {/* If it's relation choice (preview_image_link) */}
291
+ {isRelationChoice ? (
292
+ <Image item={value} width="fit-content" height="auto" loading="lazy" />
293
+ ) : (
294
+ <img
295
+ className={props.className}
296
+ src={
297
+ isInternalURL(imageValue)
298
+ ? `${flattenToAppURL(imageValue)}/@@images/image/${imageSize}`
299
+ : imageValue
300
+ }
301
+ alt=""
302
+ />
303
+ )}
190
304
  </div>
191
305
  ) : (
192
306
  <div
@@ -242,15 +356,24 @@ const UnconnectedImageInput = (props) => {
242
356
  e.preventDefault();
243
357
  openObjectBrowser({
244
358
  mode: objectBrowserPickerType,
245
- onSelectItem: onSelectItem
246
- ? onSelectItem
247
- : (url, { title, image_field, image_scales }) => {
248
- onChange(props.id, flattenToAppURL(url), {
249
- title,
250
- image_field,
251
- image_scales,
252
- });
253
- },
359
+ onSelectItem: isRelationChoice
360
+ ? (url, item) => {
361
+ // we save the whole item if it's a relation choice
362
+ onChange(props.id, item);
363
+ }
364
+ : onSelectItem
365
+ ? onSelectItem
366
+ : // else we save the url along with the image field and scales
367
+ (
368
+ url,
369
+ { title, image_field, image_scales },
370
+ ) => {
371
+ onChange(props.id, flattenToAppURL(url), {
372
+ title,
373
+ image_field,
374
+ image_scales,
375
+ });
376
+ },
254
377
  currentPath: contextUrl,
255
378
  });
256
379
  }}
@@ -311,13 +434,14 @@ const UnconnectedImageInput = (props) => {
311
434
  intl.formatMessage(messages.linkAnImage)
312
435
  }
313
436
  objectBrowserPickerType={objectBrowserPickerType}
314
- onChange={(_, e) =>
315
- onChange(
316
- props.id,
317
- isInternalURL(e) ? flattenToAppURL(e) : e,
318
- {},
319
- )
320
- }
437
+ onChange={(_, e) => {
438
+ onSubmitURL(e);
439
+ // onChange(
440
+ // props.id,
441
+ // isInternalURL(e) ? flattenToAppURL(e) : e,
442
+ // {},
443
+ // );
444
+ }}
321
445
  id={id}
322
446
  />
323
447
  )}
@@ -331,6 +455,8 @@ const UnconnectedImageInput = (props) => {
331
455
  };
332
456
 
333
457
  export const ImageInput = compose(
458
+ // This HOC goes first because it injects block in case that it's not present (not a block, but a DX field)
459
+ withObjectBrowser,
334
460
  connect(
335
461
  (state, ownProps) => {
336
462
  const requestId = `image-upload-${ownProps.id}`;
@@ -339,9 +465,9 @@ export const ImageInput = compose(
339
465
  content: state.content.subrequests[ownProps.block || requestId]?.data,
340
466
  };
341
467
  },
342
- { createContent },
468
+ { createContent, searchContent },
343
469
  ),
344
- )(withObjectBrowser(UnconnectedImageInput));
470
+ )(UnconnectedImageInput);
345
471
 
346
472
  const ImageUploadWidget = (props) => {
347
473
  const { fieldSet, id, title } = props;
@@ -85,7 +85,7 @@ describe('RegistryImageWidget', () => {
85
85
 
86
86
  return dropzone && preview && filename;
87
87
  },
88
- { timeout: 1000 },
88
+ { timeout: 2000 },
89
89
  );
90
90
 
91
91
  expect(container).toMatchSnapshot();
@@ -434,10 +434,18 @@ body.has-toolbar.has-sidebar-collapsed .ui.wrapper > .ui.inner.block.full {
434
434
  top: 1em;
435
435
  right: 1em;
436
436
 
437
+ .sidebar-container & .ui.icon.button:hover {
438
+ background: transparent !important;
439
+ }
440
+
437
441
  .icon.circled {
438
442
  border: 1px solid #e4e8ec;
439
443
  background: #f3f5f7;
440
444
  box-shadow: inset 0 0 0 0.14285714rem transparent !important;
445
+
446
+ &:hover {
447
+ background-color: #e4e8ec;
448
+ }
441
449
  }
442
450
  }
443
451
 
@@ -990,6 +998,17 @@ div.image-upload-widget-image {
990
998
  }
991
999
  }
992
1000
 
1001
+ // In the sidebar, the height is forced on all .ui.input T_T
1002
+ .ui.form .ui.input.input-anchorlink-theme,
1003
+ .ui.form
1004
+ .inline.field
1005
+ .link-form-container
1006
+ .wrapper
1007
+ .ui.input.input-anchorlink-theme
1008
+ input {
1009
+ height: 34px;
1010
+ }
1011
+
993
1012
  .block.image.align.left,
994
1013
  .block.image.align.right {
995
1014
  img {
@@ -5,6 +5,46 @@ export function ImageToolbar({ className, data, id, onChange, selected }: {
5
5
  onChange: any;
6
6
  selected: any;
7
7
  }): import("react/jsx-runtime").JSX.Element;
8
- export const ImageInput: any;
8
+ export const ImageInput: {
9
+ new (): {
10
+ state: {
11
+ isObjectBrowserOpen: boolean;
12
+ };
13
+ openObjectBrowser: ({ mode, onSelectItem, dataName, overlay, propDataName, searchableTypes, selectableTypes, maximumSelectionSize, currentPath, }?: {
14
+ mode: string;
15
+ dataName: string;
16
+ onSelectItem: string;
17
+ overlay: string;
18
+ }) => void;
19
+ closeObjectBrowser: () => void;
20
+ render(): import("react/jsx-runtime").JSX.Element;
21
+ context: unknown;
22
+ setState<K extends string | number | symbol>(state: any, callback?: () => void): void;
23
+ forceUpdate(callback?: () => void): void;
24
+ readonly props: Readonly<any>;
25
+ refs: {
26
+ [key: string]: React.ReactInstance;
27
+ };
28
+ componentDidMount?(): void;
29
+ shouldComponentUpdate?(nextProps: Readonly<any>, nextState: Readonly<any>, nextContext: any): boolean;
30
+ componentWillUnmount?(): void;
31
+ componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
32
+ getSnapshotBeforeUpdate?(prevProps: Readonly<any>, prevState: Readonly<any>): any;
33
+ componentDidUpdate?(prevProps: Readonly<any>, prevState: Readonly<any>, snapshot?: any): void;
34
+ componentWillMount?(): void;
35
+ UNSAFE_componentWillMount?(): void;
36
+ componentWillReceiveProps?(nextProps: Readonly<any>, nextContext: any): void;
37
+ UNSAFE_componentWillReceiveProps?(nextProps: Readonly<any>, nextContext: any): void;
38
+ componentWillUpdate?(nextProps: Readonly<any>, nextState: Readonly<any>, nextContext: any): void;
39
+ UNSAFE_componentWillUpdate?(nextProps: Readonly<any>, nextState: Readonly<any>, nextContext: any): void;
40
+ };
41
+ defaultProps: {
42
+ onChangeBlock: () => void;
43
+ data: {};
44
+ block: string;
45
+ };
46
+ contextType?: React.Context<any> | undefined;
47
+ };
9
48
  export default ImageUploadWidget;
49
+ import React from 'react';
10
50
  declare function ImageUploadWidget(props: any): import("react/jsx-runtime").JSX.Element;