@plone/volto 18.18.0 → 18.20.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.
- package/.eslintignore +1 -1
- package/CHANGELOG.md +28 -0
- package/locales/ca/LC_MESSAGES/volto.po +1 -5
- package/locales/ca.json +1 -1
- package/locales/de/LC_MESSAGES/volto.po +1 -5
- package/locales/de.json +1 -1
- package/locales/en/LC_MESSAGES/volto.po +1 -5
- package/locales/en.json +1 -1
- package/locales/es/LC_MESSAGES/volto.po +1 -5
- package/locales/es.json +1 -1
- package/locales/eu/LC_MESSAGES/volto.po +1 -5
- package/locales/eu.json +1 -1
- package/locales/fi/LC_MESSAGES/volto.po +1 -5
- package/locales/fi.json +1 -1
- package/locales/fr/LC_MESSAGES/volto.po +1 -5
- package/locales/fr.json +1 -1
- package/locales/hi/LC_MESSAGES/volto.po +1 -5
- package/locales/hi.json +1 -1
- package/locales/it/LC_MESSAGES/volto.po +1 -5
- package/locales/it.json +1 -1
- package/locales/ja/LC_MESSAGES/volto.po +1 -5
- package/locales/ja.json +1 -1
- package/locales/nl/LC_MESSAGES/volto.po +1 -5
- package/locales/nl.json +1 -1
- package/locales/pt/LC_MESSAGES/volto.po +1 -5
- package/locales/pt.json +1 -1
- package/locales/pt_BR/LC_MESSAGES/volto.po +1 -5
- package/locales/pt_BR.json +1 -1
- package/locales/ro/LC_MESSAGES/volto.po +1 -5
- package/locales/ro.json +1 -1
- package/locales/ru/LC_MESSAGES/volto.po +1 -5
- package/locales/ru.json +1 -1
- package/locales/volto.pot +2 -6
- package/locales/zh_CN/LC_MESSAGES/volto.po +1 -5
- package/locales/zh_CN.json +1 -1
- package/package.json +4 -4
- package/src/components/manage/ConditionalLink/ConditionalLink.test.tsx +109 -0
- package/src/components/manage/ConditionalLink/ConditionalLink.tsx +36 -0
- package/src/components/manage/Contents/ContentsDeleteModal.jsx +1 -1
- package/src/components/manage/UniversalLink/UniversalLink.test.jsx +195 -13
- package/src/components/manage/UniversalLink/UniversalLink.tsx +214 -0
- package/tsconfig.declarations.json +11 -1
- package/tsconfig.json +7 -24
- package/types/components/manage/ConditionalLink/ConditionalLink.d.ts +11 -15
- package/types/components/manage/UniversalLink/UniversalLink.d.ts +54 -20
- package/types/react-router-hash-link.d.ts +12 -0
- package/src/components/manage/ConditionalLink/ConditionalLink.jsx +0 -27
- package/src/components/manage/ConditionalLink/ConditionalLink.test.jsx +0 -30
- package/src/components/manage/UniversalLink/UniversalLink.jsx +0 -154
|
@@ -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;
|