design-comuni-plone-theme 11.20.0 → 11.20.2

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.
@@ -1,308 +0,0 @@
1
- /**
2
- * backport https://github.com/plone/volto/pull/4854
3
- *
4
- * View container.
5
- * @module components/theme/View/View
6
- */
7
-
8
- import React, { Component } from 'react';
9
- import PropTypes from 'prop-types';
10
- import { connect } from 'react-redux';
11
- import { compose } from 'redux';
12
- import { Redirect } from 'react-router-dom';
13
- import { Portal } from 'react-portal';
14
- import { injectIntl } from 'react-intl';
15
- import qs from 'query-string';
16
-
17
- import {
18
- ContentMetadataTags,
19
- Comments,
20
- Tags,
21
- Toolbar,
22
- } from '@plone/volto/components';
23
- import { listActions, getContent } from '@plone/volto/actions';
24
- import {
25
- BodyClass,
26
- getBaseUrl,
27
- flattenToAppURL,
28
- getLayoutFieldname,
29
- hasApiExpander,
30
- } from '@plone/volto/helpers';
31
-
32
- import config from '@plone/volto/registry';
33
-
34
- /**
35
- * View container class.
36
- * @class View
37
- * @extends Component
38
- */
39
- class View extends Component {
40
- /**
41
- * Property types.
42
- * @property {Object} propTypes Property types.
43
- * @static
44
- */
45
- static propTypes = {
46
- actions: PropTypes.shape({
47
- object: PropTypes.arrayOf(PropTypes.object),
48
- object_buttons: PropTypes.arrayOf(PropTypes.object),
49
- user: PropTypes.arrayOf(PropTypes.object),
50
- }),
51
- listActions: PropTypes.func.isRequired,
52
- /**
53
- * Action to get the content
54
- */
55
- getContent: PropTypes.func.isRequired,
56
- /**
57
- * Pathname of the object
58
- */
59
- pathname: PropTypes.string.isRequired,
60
- location: PropTypes.shape({
61
- search: PropTypes.string,
62
- pathname: PropTypes.string,
63
- }).isRequired,
64
- /**
65
- * Version id of the object
66
- */
67
- versionId: PropTypes.string,
68
- /**
69
- * Content of the object
70
- */
71
- content: PropTypes.shape({
72
- /**
73
- * Layout of the object
74
- */
75
- layout: PropTypes.string,
76
- /**
77
- * Allow discussion of the object
78
- */
79
- allow_discussion: PropTypes.bool,
80
- /**
81
- * Title of the object
82
- */
83
- title: PropTypes.string,
84
- /**
85
- * Description of the object
86
- */
87
- description: PropTypes.string,
88
- /**
89
- * Type of the object
90
- */
91
- '@type': PropTypes.string,
92
- /**
93
- * Subjects of the object
94
- */
95
- subjects: PropTypes.arrayOf(PropTypes.string),
96
- is_folderish: PropTypes.bool,
97
- }),
98
- error: PropTypes.shape({
99
- /**
100
- * Error type
101
- */
102
- status: PropTypes.number,
103
- }),
104
- };
105
-
106
- /**
107
- * Default properties.
108
- * @property {Object} defaultProps Default properties.
109
- * @static
110
- */
111
- static defaultProps = {
112
- actions: null,
113
- content: null,
114
- versionId: null,
115
- error: null,
116
- };
117
-
118
- state = {
119
- hasObjectButtons: null,
120
- isClient: false,
121
- };
122
-
123
- componentDidMount() {
124
- // Do not trigger the actions action if the expander is present
125
- if (!hasApiExpander('actions', getBaseUrl(this.props.pathname))) {
126
- this.props.listActions(getBaseUrl(this.props.pathname));
127
- }
128
- this.props.getContent(
129
- getBaseUrl(this.props.pathname),
130
- this.props.versionId,
131
- );
132
- this.setState({ isClient: true });
133
- }
134
-
135
- /**
136
- * Component will receive props
137
- * @method componentWillReceiveProps
138
- * @param {Object} nextProps Next properties
139
- * @returns {undefined}
140
- */
141
- UNSAFE_componentWillReceiveProps(nextProps) {
142
- if (nextProps.pathname !== this.props.pathname) {
143
- // Do not trigger the actions action if the expander is present
144
- if (!hasApiExpander('actions', getBaseUrl(nextProps.pathname))) {
145
- this.props.listActions(getBaseUrl(nextProps.pathname));
146
- }
147
- this.props.getContent(
148
- getBaseUrl(nextProps.pathname),
149
- this.props.versionId,
150
- );
151
- }
152
-
153
- if (nextProps.actions.object_buttons) {
154
- const objectButtons = nextProps.actions.object_buttons;
155
- this.setState({
156
- hasObjectButtons: !!objectButtons.length,
157
- });
158
- }
159
- }
160
-
161
- /**
162
- * Default fallback view
163
- * @method getViewDefault
164
- * @returns {string} Markup for component.
165
- */
166
- getViewDefault = () => config.views.defaultView;
167
-
168
- /**
169
- * Get view by content type
170
- * @method getViewByType
171
- * @returns {string} Markup for component.
172
- */
173
- getViewByType = () =>
174
- config.views.contentTypesViews[this.props.content['@type']] || null;
175
-
176
- /**
177
- * Get view by content layout property
178
- * @method getViewByLayout
179
- * @returns {string} Markup for component.
180
- */
181
- getViewByLayout = () =>
182
- config.views.layoutViews[
183
- this.props.content[getLayoutFieldname(this.props.content)]
184
- ] || null;
185
-
186
- /**
187
- * Cleans the component displayName (specially for connected components)
188
- * which have the Connect(componentDisplayName)
189
- * @method cleanViewName
190
- * @param {string} dirtyDisplayName The displayName
191
- * @returns {string} Clean displayName (no Connect(...)).
192
- */
193
- cleanViewName = (dirtyDisplayName) =>
194
- dirtyDisplayName
195
- .replace('Connect(', '')
196
- .replace('injectIntl(', '')
197
- .replace(')', '')
198
- .replace('connect(', '')
199
- .toLowerCase();
200
-
201
- /**
202
- * Render method.
203
- * @method render
204
- * @returns {string} Markup for the component.
205
- */
206
- render() {
207
- const { views } = config;
208
- const status = __SERVER__
209
- ? this.props.error?.status
210
- : this.props.error?.code;
211
- // Checking to see if it's a 3XX HTTP status code. error.status only works on the server
212
- if (['301', '302', '307', '308'].includes(status?.toString())) {
213
- const redirectUrl = __SERVER__
214
- ? this.props.error.response.headers.location
215
- : this.props.error.url;
216
- let redirect = flattenToAppURL(redirectUrl);
217
- // We can hit situations where we end up being redirected to an api route. We don't want that so lets remove ++api++.
218
- redirect = redirect.replace('/++api++', '');
219
- return <Redirect to={`${redirect}${this.props.location.search}`} />;
220
- } else if (this.props.error && !this.props.connectionRefused) {
221
- let FoundView;
222
- if (this.props.error.status === undefined) {
223
- // For some reason, while development and if CORS is in place and the
224
- // requested resource is 404, it returns undefined as status, then the
225
- // next statement will fail
226
- FoundView = views.errorViews.corsError;
227
- } else {
228
- FoundView = views.errorViews[this.props.error.status.toString()];
229
- }
230
- if (!FoundView) {
231
- FoundView = views.errorViews['404']; // default to 404
232
- }
233
- return (
234
- <div id="view">
235
- <FoundView {...this.props} />
236
- </div>
237
- );
238
- }
239
- if (!this.props.content) {
240
- return <span />;
241
- }
242
- const RenderedView =
243
- this.getViewByLayout() || this.getViewByType() || this.getViewDefault();
244
-
245
- return (
246
- <div id="view">
247
- <ContentMetadataTags content={this.props.content} />
248
- {/* Body class if displayName in component is set */}
249
- <BodyClass
250
- className={
251
- RenderedView.displayName
252
- ? `view-${this.cleanViewName(RenderedView.displayName)}`
253
- : null
254
- }
255
- />
256
- <RenderedView
257
- key={this.props.content['@id']}
258
- content={this.props.content}
259
- location={this.props.location}
260
- token={this.props.token}
261
- history={this.props.history}
262
- />
263
- {config.settings.showTags &&
264
- this.props.content.subjects &&
265
- this.props.content.subjects.length > 0 && (
266
- <Tags tags={this.props.content.subjects} />
267
- )}
268
- {/* Add opt-in social sharing if required, disabled by default */}
269
- {/* In the future this might be parameterized from the app config */}
270
- {/* <SocialSharing
271
- url={typeof window === 'undefined' ? '' : window.location.href}
272
- title={this.props.content.title}
273
- description={this.props.content.description || ''}
274
- /> */}
275
- {this.props.content.allow_discussion && (
276
- <Comments pathname={this.props.pathname} />
277
- )}
278
- {this.state.isClient && (
279
- <Portal node={document.getElementById('toolbar')}>
280
- <Toolbar pathname={this.props.pathname} inner={<span />} />
281
- </Portal>
282
- )}
283
- </div>
284
- );
285
- }
286
- }
287
-
288
- export default compose(
289
- injectIntl,
290
- connect(
291
- (state, props) => ({
292
- actions: state.actions.actions,
293
- token: state.userSession.token,
294
- content: state.content.data,
295
- error: state.content.get.error,
296
- apiError: state.apierror.error,
297
- connectionRefused: state.apierror.connectionRefused,
298
- pathname: props.location.pathname,
299
- versionId:
300
- qs.parse(props.location.search) &&
301
- qs.parse(props.location.search).version,
302
- }),
303
- {
304
- listActions,
305
- getContent,
306
- },
307
- ),
308
- )(View);
@@ -1,131 +0,0 @@
1
- /**
2
- * backport https://github.com/plone/volto/pull/4854
3
- *
4
- * Api helper.
5
- * @module helpers/Api
6
- */
7
-
8
- import superagent from 'superagent';
9
- import Cookies from 'universal-cookie';
10
- import config from '@plone/volto/registry';
11
- import { addHeadersFactory } from '@plone/volto/helpers/Proxy/Proxy';
12
- import { stripQuerystring } from '@plone/volto/helpers';
13
-
14
- const methods = ['get', 'post', 'put', 'patch', 'del'];
15
-
16
- /**
17
- * Format the url.
18
- * @function formatUrl
19
- * @param {string} path Path (or URL) to be formatted.
20
- * @returns {string} Formatted path.
21
- */
22
- function formatUrl(path) {
23
- const { settings } = config;
24
- const APISUFIX = settings.legacyTraverse ? '' : '/++api++';
25
-
26
- if (path.startsWith('http://') || path.startsWith('https://')) return path;
27
-
28
- const adjustedPath = path[0] !== '/' ? `/${path}` : path;
29
- let apiPath = '';
30
- if (settings.internalApiPath && __SERVER__) {
31
- apiPath = settings.internalApiPath;
32
- } else if (settings.apiPath) {
33
- apiPath = settings.apiPath;
34
- }
35
-
36
- return `${apiPath}${APISUFIX}${adjustedPath}`;
37
- }
38
-
39
- /**
40
- * Api class.
41
- * @class Api
42
- */
43
- class Api {
44
- /**
45
- * Constructor
46
- * @method constructor
47
- * @constructs Api
48
- */
49
- constructor(req) {
50
- const cookies = new Cookies();
51
-
52
- methods.forEach((method) => {
53
- this[method] = (
54
- path,
55
- { params, data, type, headers = {}, checkUrl = false } = {},
56
- ) => {
57
- let request;
58
- let promise = new Promise((resolve, reject) => {
59
- request = superagent[method](formatUrl(path));
60
-
61
- if (params) {
62
- request.query(params);
63
- }
64
-
65
- let authToken;
66
- if (req) {
67
- // We are in SSR
68
- authToken = req.universalCookies.get('auth_token');
69
- request.use(addHeadersFactory(req));
70
- } else {
71
- authToken = cookies.get('auth_token');
72
- }
73
- if (authToken) {
74
- request.set('Authorization', `Bearer ${authToken}`);
75
- }
76
-
77
- request.set('Accept', 'application/json');
78
-
79
- if (type) {
80
- request.type(type);
81
- }
82
-
83
- Object.keys(headers).forEach((key) => request.set(key, headers[key]));
84
-
85
- if (__SERVER__ && checkUrl && ['get', 'head'].includes(method)) {
86
- request.redirects(0);
87
- }
88
-
89
- if (data) {
90
- request.send(data);
91
- }
92
-
93
- request.end((err, response) => {
94
- if (
95
- checkUrl &&
96
- request.url &&
97
- request.xhr &&
98
- encodeURI(stripQuerystring(request.url)) !==
99
- stripQuerystring(request.xhr.responseURL)
100
- ) {
101
- if (request.xhr.responseURL?.length === 0) {
102
- return reject({
103
- code: 408,
104
- status: 408,
105
- url: request.xhr.responseURL,
106
- });
107
- }
108
- return reject({
109
- code: 301,
110
- url: request.xhr.responseURL,
111
- });
112
- }
113
-
114
- if (['301', '302', '307', '308'].includes(err?.status)) {
115
- return reject({
116
- code: err.status,
117
- url: err.response.headers.location,
118
- });
119
- }
120
-
121
- return err ? reject(err) : resolve(response.body || response.text);
122
- });
123
- });
124
- promise.request = request;
125
- return promise;
126
- };
127
- });
128
- }
129
- }
130
-
131
- export default Api;