@plone/volto 18.17.0 → 18.19.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 (48) hide show
  1. package/.eslintignore +1 -1
  2. package/CHANGELOG.md +28 -0
  3. package/locales/ca/LC_MESSAGES/volto.po +6 -0
  4. package/locales/ca.json +1 -1
  5. package/locales/de/LC_MESSAGES/volto.po +6 -0
  6. package/locales/de.json +1 -1
  7. package/locales/en/LC_MESSAGES/volto.po +6 -0
  8. package/locales/en.json +1 -1
  9. package/locales/es/LC_MESSAGES/volto.po +6 -0
  10. package/locales/es.json +1 -1
  11. package/locales/eu/LC_MESSAGES/volto.po +6 -0
  12. package/locales/eu.json +1 -1
  13. package/locales/fi/LC_MESSAGES/volto.po +6 -0
  14. package/locales/fi.json +1 -1
  15. package/locales/fr/LC_MESSAGES/volto.po +6 -0
  16. package/locales/fr.json +1 -1
  17. package/locales/hi/LC_MESSAGES/volto.po +6 -0
  18. package/locales/hi.json +1 -1
  19. package/locales/it/LC_MESSAGES/volto.po +6 -0
  20. package/locales/it.json +1 -1
  21. package/locales/ja/LC_MESSAGES/volto.po +6 -0
  22. package/locales/ja.json +1 -1
  23. package/locales/nl/LC_MESSAGES/volto.po +6 -0
  24. package/locales/nl.json +1 -1
  25. package/locales/pt/LC_MESSAGES/volto.po +6 -0
  26. package/locales/pt.json +1 -1
  27. package/locales/pt_BR/LC_MESSAGES/volto.po +6 -0
  28. package/locales/pt_BR.json +1 -1
  29. package/locales/ro/LC_MESSAGES/volto.po +6 -0
  30. package/locales/ro.json +1 -1
  31. package/locales/ru/LC_MESSAGES/volto.po +6 -0
  32. package/locales/ru.json +1 -1
  33. package/locales/volto.pot +7 -1
  34. package/locales/zh_CN/LC_MESSAGES/volto.po +6 -0
  35. package/locales/zh_CN.json +1 -1
  36. package/package.json +5 -5
  37. package/src/components/manage/ConditionalLink/ConditionalLink.test.jsx +71 -12
  38. package/src/components/manage/ConditionalLink/ConditionalLink.tsx +34 -0
  39. package/src/components/manage/UniversalLink/UniversalLink.test.jsx +195 -13
  40. package/src/components/manage/UniversalLink/UniversalLink.tsx +214 -0
  41. package/src/components/manage/Widgets/ImageWidget.jsx +31 -3
  42. package/tsconfig.json +7 -24
  43. package/types/components/manage/ConditionalLink/ConditionalLink.d.ts +7 -14
  44. package/types/components/manage/UniversalLink/UniversalLink.d.ts +54 -20
  45. package/types/react-router-hash-link.d.ts +12 -0
  46. package/types/routes.d.ts +4 -0
  47. package/src/components/manage/ConditionalLink/ConditionalLink.jsx +0 -27
  48. package/src/components/manage/UniversalLink/UniversalLink.jsx +0 -154
package/types/routes.d.ts CHANGED
@@ -39,6 +39,10 @@ declare const routes: {
39
39
  path: string;
40
40
  component: any;
41
41
  routes: ({
42
+ path: string;
43
+ component: React.ComponentType;
44
+ exact?: boolean;
45
+ } | {
42
46
  path: string;
43
47
  component: any;
44
48
  exact?: undefined;
@@ -1,27 +0,0 @@
1
- import React from 'react';
2
- import UniversalLink from '@plone/volto/components/manage/UniversalLink/UniversalLink';
3
- import PropTypes from 'prop-types';
4
-
5
- const ConditionalLink = ({ condition, to, item, ...props }) => {
6
- if (condition) {
7
- return (
8
- <UniversalLink href={to} item={item} {...props}>
9
- {props.children}
10
- </UniversalLink>
11
- );
12
- } else {
13
- return <>{props.children}</>;
14
- }
15
- };
16
-
17
- ConditionalLink.propTypes = {
18
- condition: PropTypes.bool,
19
- to: PropTypes.string,
20
- item: PropTypes.shape({
21
- '@id': PropTypes.string,
22
- remoteUrl: PropTypes.string, //of plone @type 'Link'
23
- }),
24
- children: PropTypes.node,
25
- };
26
-
27
- export default ConditionalLink;
@@ -1,154 +0,0 @@
1
- /*
2
- * UniversalLink
3
- * @module components/UniversalLink
4
- */
5
-
6
- import React from 'react';
7
- import PropTypes from 'prop-types';
8
- import { HashLink as Link } from 'react-router-hash-link';
9
- import { useSelector } from 'react-redux';
10
- import {
11
- flattenToAppURL,
12
- isInternalURL,
13
- URLUtils,
14
- } from '@plone/volto/helpers/Url/Url';
15
-
16
- import config from '@plone/volto/registry';
17
- import cx from 'classnames';
18
-
19
- const UniversalLink = ({
20
- href,
21
- item = null,
22
- openLinkInNewTab,
23
- download = false,
24
- children,
25
- className = null,
26
- title = null,
27
- ...props
28
- }) => {
29
- const token = useSelector((state) => state.userSession?.token);
30
-
31
- let url = href;
32
- if (!href && item) {
33
- if (item['@id'] === '') {
34
- url = config.settings.publicURL;
35
- } else if (!item['@id']) {
36
- // eslint-disable-next-line no-console
37
- console.error(
38
- 'Invalid item passed to UniversalLink',
39
- item,
40
- props,
41
- children,
42
- );
43
- url = '#';
44
- } else {
45
- //case: generic item
46
- url = flattenToAppURL(item['@id']);
47
-
48
- //case: item like a Link
49
- let remoteUrl = item.remoteUrl || item.getRemoteUrl;
50
- if (!token && remoteUrl) {
51
- url = remoteUrl;
52
- }
53
-
54
- //case: item of type 'File'
55
- if (
56
- !token &&
57
- config.settings.downloadableObjects.includes(item['@type'])
58
- ) {
59
- url = `${url}/@@download/file`;
60
- }
61
-
62
- if (
63
- !token &&
64
- config.settings.viewableInBrowserObjects.includes(item['@type'])
65
- ) {
66
- url = `${url}/@@display-file/file`;
67
- }
68
- }
69
- }
70
-
71
- const isExternal = !isInternalURL(url);
72
-
73
- const isDownload = (!isExternal && url.includes('@@download')) || download;
74
- const isDisplayFile =
75
- (!isExternal && url.includes('@@display-file')) || false;
76
-
77
- const checkedURL = URLUtils.checkAndNormalizeUrl(url);
78
-
79
- url = checkedURL.url;
80
- let tag = (
81
- <Link
82
- to={flattenToAppURL(url)}
83
- target={openLinkInNewTab ?? false ? '_blank' : null}
84
- title={title}
85
- className={className}
86
- smooth={config.settings.hashLinkSmoothScroll}
87
- {...props}
88
- >
89
- {children}
90
- </Link>
91
- );
92
-
93
- if (isExternal) {
94
- const isTelephoneOrMail = checkedURL.isMail || checkedURL.isTelephone;
95
- tag = (
96
- <a
97
- href={url}
98
- title={title}
99
- target={
100
- !isTelephoneOrMail && !(openLinkInNewTab === false) ? '_blank' : null
101
- }
102
- rel="noopener noreferrer"
103
- className={cx({ external: !isTelephoneOrMail }, className)}
104
- {...props}
105
- >
106
- {children}
107
- </a>
108
- );
109
- } else if (isDownload) {
110
- tag = (
111
- <a
112
- href={flattenToAppURL(url)}
113
- download
114
- title={title}
115
- className={className}
116
- {...props}
117
- >
118
- {children}
119
- </a>
120
- );
121
- } else if (isDisplayFile) {
122
- tag = (
123
- <a
124
- href={flattenToAppURL(url)}
125
- title={title}
126
- target="_blank"
127
- rel="noopener noreferrer"
128
- className={className}
129
- {...props}
130
- >
131
- {children}
132
- </a>
133
- );
134
- }
135
- return tag;
136
- };
137
-
138
- UniversalLink.propTypes = {
139
- href: PropTypes.string,
140
- openLinkInNewTab: PropTypes.bool,
141
- download: PropTypes.bool,
142
- className: PropTypes.string,
143
- title: PropTypes.string,
144
- item: PropTypes.shape({
145
- '@id': PropTypes.string.isRequired,
146
- remoteUrl: PropTypes.string, //of plone @type 'Link'
147
- }),
148
- children: PropTypes.oneOfType([
149
- PropTypes.arrayOf(PropTypes.node),
150
- PropTypes.node,
151
- ]),
152
- };
153
-
154
- export default UniversalLink;