@eeacms/volto-eea-website-theme 1.30.0 → 1.32.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/CHANGELOG.md CHANGED
@@ -4,6 +4,36 @@ All notable changes to this project will be documented in this file. Dates are d
4
4
 
5
5
  Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
6
6
 
7
+ ### [1.32.0](https://github.com/eea/volto-eea-website-theme/compare/1.31.0...1.32.0) - 21 March 2024
8
+
9
+ #### :rocket: New Features
10
+
11
+ - feat(slate): add new h3 slate element [Miu Razvan - [`20a7e93`](https://github.com/eea/volto-eea-website-theme/commit/20a7e9316d5c1de279712c38bc05eb775f8bd326)]
12
+ - feat(slate): add h4 in slate toolbar [Miu Razvan - [`2c523ac`](https://github.com/eea/volto-eea-website-theme/commit/2c523acdeb78ed224c4a37285c48dbf4555604e0)]
13
+
14
+ #### :nail_care: Enhancements
15
+
16
+ - change(slate): Use F as icon and renamed title of new heading Slate toolbar button to Figure title [David Ichim - [`7355bb3`](https://github.com/eea/volto-eea-website-theme/commit/7355bb3f3cf527c24fc41a10f72cc854773ab84b)]
17
+ - change(slate): renamed addFormat to addSlateToolbarButton [ichim-david - [`0809c04`](https://github.com/eea/volto-eea-website-theme/commit/0809c040ea9e096c60cbce36e679f9bab23a52a2)]
18
+
19
+ #### :house: Internal changes
20
+
21
+ - style: Automated code fix [eea-jenkins - [`6971349`](https://github.com/eea/volto-eea-website-theme/commit/69713496d601e4e0b2fe3469a4ffcd8d36105040)]
22
+ - style: Automated code fix [eea-jenkins - [`a292700`](https://github.com/eea/volto-eea-website-theme/commit/a292700cd047bad925add1fde4d834f7fd03ec62)]
23
+
24
+ #### :hammer_and_wrench: Others
25
+
26
+ - Update package.json [ichim-david - [`9db96ff`](https://github.com/eea/volto-eea-website-theme/commit/9db96ff3f8e8eedce92c53befe6a1d6e965d8699)]
27
+ - Revert "(fix): In search block on edit, the sort on and sort order are not working (#205)" [David Ichim - [`2045d50`](https://github.com/eea/volto-eea-website-theme/commit/2045d50b3d2f18fab0d6c6794d8030975b1a3f21)]
28
+ ### [1.31.0](https://github.com/eea/volto-eea-website-theme/compare/1.30.0...1.31.0) - 14 March 2024
29
+
30
+ #### :rocket: New Features
31
+
32
+ - feat: Put default alt as the rights field than image title - refs #159551 [dobri1408 - [`4f0e60b`](https://github.com/eea/volto-eea-website-theme/commit/4f0e60b02ce1167d92de3b294e75d2577c892c85)]
33
+
34
+ #### :hammer_and_wrench: Others
35
+
36
+ - Release 1.31.0 [alin - [`36690f7`](https://github.com/eea/volto-eea-website-theme/commit/36690f75e4773e40f5ab4e4ce4b956b650df62b5)]
7
37
  ### [1.30.0](https://github.com/eea/volto-eea-website-theme/compare/1.29.0...1.30.0) - 13 March 2024
8
38
 
9
39
  #### :rocket: New Features
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eeacms/volto-eea-website-theme",
3
- "version": "1.30.0",
3
+ "version": "1.32.0",
4
4
  "description": "@eeacms/volto-eea-website-theme: Volto add-on",
5
5
  "main": "src/index.js",
6
6
  "author": "European Environment Agency: IDM2 A-Team",
@@ -0,0 +1,511 @@
1
+ /* this customization is used to put default alt as the rights field
2
+ */
3
+ import React, { Component } from 'react';
4
+ import PropTypes from 'prop-types';
5
+ import { compose } from 'redux';
6
+ import { connect } from 'react-redux';
7
+ import { defineMessages, FormattedMessage, injectIntl } from 'react-intl';
8
+ import { Input, Segment, Breadcrumb } from 'semantic-ui-react';
9
+
10
+ import { join } from 'lodash';
11
+
12
+ // These absolute imports (without using the corresponding centralized index.js) are required
13
+ // to cut circular import problems, this file should never use them. This is because of
14
+ // the very nature of the functionality of the component and its relationship with others
15
+ import { searchContent } from '@plone/volto/actions/search/search';
16
+ import Icon from '@plone/volto/components/theme/Icon/Icon';
17
+ import { flattenToAppURL, isInternalURL } from '@plone/volto/helpers/Url/Url';
18
+ import config from '@plone/volto/registry';
19
+
20
+ import backSVG from '@plone/volto/icons/back.svg';
21
+ import folderSVG from '@plone/volto/icons/folder.svg';
22
+ import clearSVG from '@plone/volto/icons/clear.svg';
23
+ import searchSVG from '@plone/volto/icons/zoom.svg';
24
+ import linkSVG from '@plone/volto/icons/link.svg';
25
+ import homeSVG from '@plone/volto/icons/home.svg';
26
+
27
+ import ObjectBrowserNav from '@plone/volto/components/manage/Sidebar/ObjectBrowserNav';
28
+
29
+ const messages = defineMessages({
30
+ SearchInputPlaceholder: {
31
+ id: 'Search content',
32
+ defaultMessage: 'Search content',
33
+ },
34
+ SelectedItems: {
35
+ id: 'Selected items',
36
+ defaultMessage: 'Selected items',
37
+ },
38
+ back: {
39
+ id: 'Back',
40
+ defaultMessage: 'Back',
41
+ },
42
+ search: {
43
+ id: 'Search SVG',
44
+ defaultMessage: 'Search SVG',
45
+ },
46
+ of: { id: 'Selected items - x of y', defaultMessage: 'of' },
47
+ });
48
+
49
+ function getParentURL(url) {
50
+ return flattenToAppURL(`${join(url.split('/').slice(0, -1), '/')}`) || '/';
51
+ }
52
+
53
+ /**
54
+ * ObjectBrowserBody container class.
55
+ * @class ObjectBrowserBody
56
+ * @extends Component
57
+ */
58
+ class ObjectBrowserBody extends Component {
59
+ /**
60
+ * Property types.
61
+ * @property {Object} propTypes Property types.
62
+ * @static
63
+ */
64
+ static propTypes = {
65
+ block: PropTypes.string.isRequired,
66
+ mode: PropTypes.string.isRequired,
67
+ data: PropTypes.any.isRequired,
68
+ searchSubrequests: PropTypes.objectOf(PropTypes.any).isRequired,
69
+ searchContent: PropTypes.func.isRequired,
70
+ closeObjectBrowser: PropTypes.func.isRequired,
71
+ onChangeBlock: PropTypes.func.isRequired,
72
+ onSelectItem: PropTypes.func,
73
+ dataName: PropTypes.string,
74
+ maximumSelectionSize: PropTypes.number,
75
+ contextURL: PropTypes.string,
76
+ searchableTypes: PropTypes.arrayOf(PropTypes.string),
77
+ };
78
+
79
+ /**
80
+ * Default properties.
81
+ * @property {Object} defaultProps Default properties.
82
+ * @static
83
+ */
84
+ static defaultProps = {
85
+ image: '',
86
+ href: '',
87
+ onSelectItem: null,
88
+ dataName: null,
89
+ selectableTypes: [],
90
+ searchableTypes: null,
91
+ maximumSelectionSize: null,
92
+ };
93
+
94
+ /**
95
+ * Constructor
96
+ * @method constructor
97
+ * @param {Object} props Component properties
98
+ * @constructs WysiwygEditor
99
+ */
100
+ constructor(props) {
101
+ super(props);
102
+ this.state = {
103
+ currentFolder:
104
+ this.props.mode === 'multiple' ? '/' : this.props.contextURL || '/',
105
+ currentImageFolder:
106
+ this.props.mode === 'multiple'
107
+ ? '/'
108
+ : this.props.mode === 'image' && this.props.data?.url
109
+ ? getParentURL(this.props.data.url)
110
+ : '/',
111
+ currentLinkFolder:
112
+ this.props.mode === 'multiple'
113
+ ? '/'
114
+ : this.props.mode === 'link' && this.props.data?.href
115
+ ? getParentURL(this.props.data.href)
116
+ : '/',
117
+ parentFolder: '',
118
+ selectedImage:
119
+ this.props.mode === 'multiple'
120
+ ? ''
121
+ : this.props.mode === 'image' && this.props.data?.url
122
+ ? flattenToAppURL(this.props.data.url)
123
+ : '',
124
+ selectedHref:
125
+ this.props.mode === 'multiple'
126
+ ? ''
127
+ : this.props.mode === 'link' && this.props.data?.href
128
+ ? flattenToAppURL(this.props.data.href)
129
+ : '',
130
+ showSearchInput: false,
131
+ // In image mode, the searchable types default to the image types which
132
+ // can be overridden with the property if specified.
133
+ searchableTypes:
134
+ this.props.mode === 'image'
135
+ ? this.props.searchableTypes || config.settings.imageObjects
136
+ : this.props.searchableTypes,
137
+ };
138
+ this.searchInputRef = React.createRef();
139
+ }
140
+
141
+ /**
142
+ * Component did mount
143
+ * @method componentDidMount
144
+ * @returns {undefined}
145
+ */
146
+ componentDidMount() {
147
+ this.initialSearch(this.props.mode);
148
+ }
149
+
150
+ initialSearch = (mode) => {
151
+ const currentSelected =
152
+ mode === 'multiple'
153
+ ? ''
154
+ : mode === 'image'
155
+ ? this.state.selectedImage
156
+ : this.state.selectedHref;
157
+ if (currentSelected && isInternalURL(currentSelected)) {
158
+ this.props.searchContent(
159
+ getParentURL(currentSelected),
160
+ {
161
+ 'path.depth': 1,
162
+ sort_on: 'getObjPositionInParent',
163
+ metadata_fields: '_all',
164
+ b_size: 1000,
165
+ },
166
+ `${this.props.block}-${mode}`,
167
+ );
168
+ } else {
169
+ this.props.searchContent(
170
+ this.state.currentFolder,
171
+ {
172
+ 'path.depth': 1,
173
+ sort_on: 'getObjPositionInParent',
174
+ metadata_fields: '_all',
175
+ b_size: 1000,
176
+ },
177
+ `${this.props.block}-${mode}`,
178
+ );
179
+ }
180
+ };
181
+
182
+ navigateTo = (id) => {
183
+ this.props.searchContent(
184
+ id,
185
+ {
186
+ 'path.depth': 1,
187
+ sort_on: 'getObjPositionInParent',
188
+ metadata_fields: '_all',
189
+ b_size: 1000,
190
+ },
191
+ `${this.props.block}-${this.props.mode}`,
192
+ );
193
+ const parent = `${join(id.split('/').slice(0, -1), '/')}` || '/';
194
+ this.setState(() => ({
195
+ parentFolder: parent,
196
+ currentFolder: id || '/',
197
+ }));
198
+ };
199
+
200
+ toggleSearchInput = () =>
201
+ this.setState(
202
+ (prevState) => ({
203
+ showSearchInput: !prevState.showSearchInput,
204
+ }),
205
+ () => {
206
+ if (this.searchInputRef?.current) this.searchInputRef.current.focus();
207
+ },
208
+ );
209
+
210
+ onSearch = (e) => {
211
+ const text = flattenToAppURL(e.target.value);
212
+ if (text.startsWith('/')) {
213
+ this.setState({ currentFolder: text });
214
+ this.props.searchContent(
215
+ text,
216
+ {
217
+ 'path.depth': 1,
218
+ sort_on: 'getObjPositionInParent',
219
+ metadata_fields: '_all',
220
+ portal_type: this.state.searchableTypes,
221
+ },
222
+ `${this.props.block}-${this.props.mode}`,
223
+ );
224
+ } else {
225
+ text.length > 2
226
+ ? this.props.searchContent(
227
+ '/',
228
+ {
229
+ SearchableText: `${text}*`,
230
+ metadata_fields: '_all',
231
+ portal_type: this.state.searchableTypes,
232
+ },
233
+ `${this.props.block}-${this.props.mode}`,
234
+ )
235
+ : this.props.searchContent(
236
+ '/',
237
+ {
238
+ 'path.depth': 1,
239
+ sort_on: 'getObjPositionInParent',
240
+ metadata_fields: '_all',
241
+ portal_type: this.state.searchableTypes,
242
+ },
243
+ `${this.props.block}-${this.props.mode}`,
244
+ );
245
+ }
246
+ };
247
+
248
+ onSelectItem = (item) => {
249
+ const url = item['@id'];
250
+ const { block, data, mode, dataName, onChangeBlock } = this.props;
251
+
252
+ const updateState = (mode) => {
253
+ switch (mode) {
254
+ case 'image':
255
+ this.setState({
256
+ selectedImage: url,
257
+ currentImageFolder: getParentURL(url),
258
+ });
259
+ break;
260
+ case 'link':
261
+ this.setState({
262
+ selectedHref: url,
263
+ currentLinkFolder: getParentURL(url),
264
+ });
265
+ break;
266
+ default:
267
+ break;
268
+ }
269
+ };
270
+
271
+ if (dataName) {
272
+ onChangeBlock(block, {
273
+ ...data,
274
+ [dataName]: url,
275
+ });
276
+ } else if (this.props.onSelectItem) {
277
+ this.props.onSelectItem(url, item);
278
+ } else if (mode === 'image') {
279
+ onChangeBlock(block, {
280
+ ...data,
281
+ url: flattenToAppURL(item.getURL),
282
+ alt: item.title || item.description || '',
283
+ copyright: item.rights || '',
284
+ });
285
+ } else if (mode === 'link') {
286
+ onChangeBlock(block, {
287
+ ...data,
288
+ href: flattenToAppURL(url),
289
+ });
290
+ }
291
+ updateState(mode);
292
+ };
293
+
294
+ onChangeBlockData = (key, value) => {
295
+ this.props.onChangeBlock(this.props.block, {
296
+ ...this.props.data,
297
+ [key]: value,
298
+ });
299
+ };
300
+
301
+ isSelectable = (item) => {
302
+ return this.props.selectableTypes.length > 0
303
+ ? this.props.selectableTypes.indexOf(item['@type']) >= 0
304
+ : true;
305
+ };
306
+
307
+ handleClickOnItem = (item) => {
308
+ if (this.props.mode === 'image') {
309
+ if (item.is_folderish) {
310
+ this.navigateTo(item['@id']);
311
+ }
312
+ if (config.settings.imageObjects.includes(item['@type'])) {
313
+ this.onSelectItem(item);
314
+ }
315
+ } else {
316
+ if (this.isSelectable(item)) {
317
+ if (
318
+ !this.props.maximumSelectionSize ||
319
+ this.props.mode === 'multiple' ||
320
+ !this.props.data ||
321
+ this.props.data.length < this.props.maximumSelectionSize
322
+ ) {
323
+ this.onSelectItem(item);
324
+ let length = this.props.data ? this.props.data.length : 0;
325
+
326
+ let stopSelecting =
327
+ this.props.mode !== 'multiple' ||
328
+ (this.props.maximumSelectionSize > 0 &&
329
+ length + 1 >= this.props.maximumSelectionSize);
330
+
331
+ if (stopSelecting) {
332
+ this.props.closeObjectBrowser();
333
+ }
334
+ } else {
335
+ this.props.closeObjectBrowser();
336
+ }
337
+ } else {
338
+ this.navigateTo(item['@id']);
339
+ }
340
+ }
341
+ };
342
+
343
+ handleDoubleClickOnItem = (item) => {
344
+ if (this.props.mode === 'image') {
345
+ if (item.is_folderish) {
346
+ this.navigateTo(item['@id']);
347
+ }
348
+ if (config.settings.imageObjects.includes(item['@type'])) {
349
+ this.onSelectItem(item);
350
+ this.props.closeObjectBrowser();
351
+ }
352
+ } else {
353
+ if (this.isSelectable(item)) {
354
+ if (this.props.data.length < this.props.maximumSelectionSize) {
355
+ this.onSelectItem(item);
356
+ }
357
+ this.props.closeObjectBrowser();
358
+ } else {
359
+ this.navigateTo(item['@id']);
360
+ }
361
+ }
362
+ };
363
+
364
+ /**
365
+ * Render method.
366
+ * @method render
367
+ * @returns {string} Markup for the component.
368
+ */
369
+ render() {
370
+ return (
371
+ <Segment.Group raised>
372
+ <header className="header pulled">
373
+ <div className="vertical divider" />
374
+ {this.state.currentFolder === '/' ? (
375
+ <>
376
+ {this.props.mode === 'image' ? (
377
+ <Icon name={folderSVG} size="24px" />
378
+ ) : (
379
+ <Icon name={linkSVG} size="24px" />
380
+ )}
381
+ </>
382
+ ) : (
383
+ <button
384
+ aria-label={this.props.intl.formatMessage(messages.back)}
385
+ onClick={() => this.navigateTo(this.state.parentFolder)}
386
+ >
387
+ <Icon name={backSVG} size="24px" />
388
+ </button>
389
+ )}
390
+ {this.state.showSearchInput ? (
391
+ <Input
392
+ className="search"
393
+ ref={this.searchInputRef}
394
+ onChange={this.onSearch}
395
+ placeholder={this.props.intl.formatMessage(
396
+ messages.SearchInputPlaceholder,
397
+ )}
398
+ />
399
+ ) : this.props.mode === 'image' ? (
400
+ <h2>
401
+ <FormattedMessage
402
+ id="Choose Image"
403
+ defaultMessage="Choose Image"
404
+ />
405
+ </h2>
406
+ ) : (
407
+ <h2>
408
+ <FormattedMessage
409
+ id="Choose Target"
410
+ defaultMessage="Choose Target"
411
+ />
412
+ </h2>
413
+ )}
414
+
415
+ <button
416
+ aria-label={this.props.intl.formatMessage(messages.search)}
417
+ onClick={this.toggleSearchInput}
418
+ >
419
+ <Icon name={searchSVG} size="24px" />
420
+ </button>
421
+ <button className="clearSVG" onClick={this.props.closeObjectBrowser}>
422
+ <Icon name={clearSVG} size="24px" />
423
+ </button>
424
+ </header>
425
+ <Segment secondary className="breadcrumbs" vertical>
426
+ <Breadcrumb>
427
+ {this.state.currentFolder !== '/' ? (
428
+ this.state.currentFolder.split('/').map((item, index, items) => {
429
+ return (
430
+ <React.Fragment key={`divider-${item}-${index}`}>
431
+ {index === 0 ? (
432
+ <Breadcrumb.Section onClick={() => this.navigateTo('/')}>
433
+ <Icon
434
+ className="home-icon"
435
+ name={homeSVG}
436
+ size="18px"
437
+ />
438
+ </Breadcrumb.Section>
439
+ ) : (
440
+ <>
441
+ <Breadcrumb.Divider key={`divider-${item.url}`} />
442
+ <Breadcrumb.Section
443
+ onClick={() =>
444
+ this.navigateTo(items.slice(0, index + 1).join('/'))
445
+ }
446
+ >
447
+ {item}
448
+ </Breadcrumb.Section>
449
+ </>
450
+ )}
451
+ </React.Fragment>
452
+ );
453
+ })
454
+ ) : (
455
+ <Breadcrumb.Section onClick={() => this.navigateTo('/')}>
456
+ <Icon className="home-icon" name={homeSVG} size="18px" />
457
+ </Breadcrumb.Section>
458
+ )}
459
+ </Breadcrumb>
460
+ </Segment>
461
+ {this.props.mode === 'multiple' && (
462
+ <Segment className="infos">
463
+ {this.props.intl.formatMessage(messages.SelectedItems)}:{' '}
464
+ {this.props.data?.length}
465
+ {this.props.maximumSelectionSize > 0 && (
466
+ <>
467
+ {' '}
468
+ {this.props.intl.formatMessage(messages.of)}{' '}
469
+ {this.props.maximumSelectionSize}
470
+ </>
471
+ )}
472
+ </Segment>
473
+ )}
474
+ <ObjectBrowserNav
475
+ currentSearchResults={
476
+ this.props.searchSubrequests[
477
+ `${this.props.block}-${this.props.mode}`
478
+ ]
479
+ }
480
+ selected={
481
+ this.props.mode === 'multiple'
482
+ ? this.props.data
483
+ : [
484
+ {
485
+ '@id':
486
+ this.props.mode === 'image'
487
+ ? this.state.selectedImage
488
+ : this.state.selectedHref,
489
+ },
490
+ ]
491
+ }
492
+ handleClickOnItem={this.handleClickOnItem}
493
+ handleDoubleClickOnItem={this.handleDoubleClickOnItem}
494
+ mode={this.props.mode}
495
+ navigateTo={this.navigateTo}
496
+ isSelectable={this.isSelectable}
497
+ />
498
+ </Segment.Group>
499
+ );
500
+ }
501
+ }
502
+
503
+ export default compose(
504
+ injectIntl,
505
+ connect(
506
+ (state) => ({
507
+ searchSubrequests: state.search.subrequests,
508
+ }),
509
+ { searchContent },
510
+ ),
511
+ )(ObjectBrowserBody);
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M6 4H19V6H8V12H18V14H8V21H6V4Z"></path></svg>
package/src/index.js CHANGED
@@ -373,6 +373,7 @@ const applyConfig = (config) => {
373
373
  },
374
374
  ];
375
375
 
376
+ // Install slate
376
377
  config = installSlate(config);
377
378
 
378
379
  // Custom block-style colors
package/src/slate.js CHANGED
@@ -1,6 +1,11 @@
1
1
  import React from 'react';
2
+ import cx from 'classnames';
2
3
  import { List } from 'semantic-ui-react';
3
- import { MarkElementButton, ToolbarButton } from '@plone/volto-slate/editor/ui';
4
+ import {
5
+ MarkElementButton,
6
+ ToolbarButton,
7
+ BlockButton,
8
+ } from '@plone/volto-slate/editor/ui';
4
9
  import installCallout from '@plone/volto-slate/editor/plugins/Callout';
5
10
  import { Icon } from '@plone/volto/components';
6
11
  import { Editor, Transforms, Text } from 'slate';
@@ -14,6 +19,39 @@ import alignJustifyIcon from '@plone/volto/icons/align-justify.svg';
14
19
  import lightIcon from './icons/light.svg';
15
20
  import smallIcon from './icons/small.svg';
16
21
  import clearIcon from './icons/eraser.svg';
22
+ import fontMono from './icons/font-mono.svg';
23
+
24
+ const installSlateToolbarButton = ({
25
+ config,
26
+ key,
27
+ before,
28
+ button,
29
+ element,
30
+ }) => {
31
+ const toolbarButtons = config.settings.slate.toolbarButtons;
32
+ const index = toolbarButtons.indexOf(key);
33
+ const beforeIndex = toolbarButtons.indexOf(before);
34
+ if (index === -1) {
35
+ if (beforeIndex > -1) {
36
+ toolbarButtons.splice(beforeIndex + 1, 0, key);
37
+ } else {
38
+ toolbarButtons.push(key);
39
+ }
40
+ } else if (index > -1 && beforeIndex > -1 && index > beforeIndex + 1) {
41
+ toolbarButtons.splice(index, 1);
42
+ toolbarButtons.splice(beforeIndex + 1, 0, key);
43
+ } else if (index > -1 && index < beforeIndex) {
44
+ toolbarButtons.splice(index, 1);
45
+ toolbarButtons.splice(beforeIndex, 0, key);
46
+ }
47
+ if (button) {
48
+ config.settings.slate.buttons[key] = button;
49
+ }
50
+ if (element) {
51
+ config.settings.slate.elements[key] = element;
52
+ }
53
+ return config;
54
+ };
17
55
 
18
56
  const toggleBlockClassFormat = (editor, format) => {
19
57
  const levels = Array.from(Editor.levels(editor, editor.selection));
@@ -67,20 +105,16 @@ const clearFormatting = (editor) => {
67
105
  Editor.nodes(editor, {
68
106
  mode: 'lowest',
69
107
  match: (n, p) => {
70
- // console.log('node', n, p);
71
108
  return Text.isText(n);
72
109
  },
73
110
  //at: [0], // uncomment if you want everything to be cleared
74
111
  }),
75
112
  );
76
113
 
77
- // console.log('sn', sn);
78
-
79
114
  sn.forEach(([n, at]) => {
80
115
  const toRemove = Object.keys(n).filter((k) => k.startsWith('style-'));
81
116
  if (toRemove.length) {
82
117
  Transforms.unsetNodes(editor, toRemove, { at });
83
- // console.log('unset', n, at, toRemove);
84
118
  }
85
119
  });
86
120
 
@@ -111,9 +145,46 @@ const ClearFormattingButton = ({ icon, ...props }) => {
111
145
 
112
146
  export default function installSlate(config) {
113
147
  if (config.settings.slate) {
148
+ let renderLinkElement;
114
149
  // Callout slate button
115
150
  config = installCallout(config);
116
151
 
152
+ try {
153
+ renderLinkElement = require('@eeacms/volto-anchors/helpers')
154
+ .renderLinkElement;
155
+ } catch {}
156
+
157
+ installSlateToolbarButton({
158
+ config,
159
+ key: 'h3-light',
160
+ before: 'heading-three',
161
+ button: (props) => (
162
+ <BlockButton
163
+ title="Figure title"
164
+ format="h3-light"
165
+ allowedChildren={config.settings.slate.allowedHeadlineElements}
166
+ icon={fontMono}
167
+ {...props}
168
+ />
169
+ ),
170
+ element: renderLinkElement
171
+ ? (opts) => {
172
+ return renderLinkElement('h3')({
173
+ ...opts,
174
+ className: 'subtitle-light',
175
+ });
176
+ }
177
+ : ({ attributes, children }) => (
178
+ <h3
179
+ {...attributes}
180
+ className={cx(attributes.className, 'subtitle-light')}
181
+ >
182
+ {children}
183
+ </h3>
184
+ ),
185
+ });
186
+ config.settings.slate.topLevelTargetElements.push('h3-light');
187
+
117
188
  config.settings.slate.buttons.clearformatting = (props) => (
118
189
  <ClearFormattingButton title="Clear formatting" icon={clearIcon} />
119
190
  );
@@ -1,106 +0,0 @@
1
- //this customization is used for fixing: in the search block, on edit sort on and reversed order doesn't work.
2
- //See here volto pr: https://github.com/plone/volto/pull/5262
3
- import React, { useEffect } from 'react';
4
- import { defineMessages } from 'react-intl';
5
- import { compose } from 'redux';
6
-
7
- import { SidebarPortal, BlockDataForm } from '@plone/volto/components';
8
- import { addExtensionFieldToSchema } from '@plone/volto/helpers/Extensions/withBlockSchemaEnhancer';
9
- import { getBaseUrl } from '@plone/volto/helpers';
10
- import config from '@plone/volto/registry';
11
-
12
- import { SearchBlockViewComponent } from '@plone/volto/components/manage/Blocks/Search/SearchBlockView';
13
- import Schema from '@plone/volto/components/manage/Blocks/Search/schema';
14
- import {
15
- withSearch,
16
- withQueryString,
17
- } from '@plone/volto/components/manage/Blocks/Search/hocs';
18
- import { cloneDeep } from 'lodash';
19
-
20
- const messages = defineMessages({
21
- template: {
22
- id: 'Results template',
23
- defaultMessage: 'Results template',
24
- },
25
- });
26
-
27
- const SearchBlockEdit = (props) => {
28
- const {
29
- block,
30
- onChangeBlock,
31
- data,
32
- selected,
33
- intl,
34
- navRoot,
35
- contentType,
36
- onTriggerSearch,
37
- querystring = {},
38
- } = props;
39
- const { sortable_indexes = {} } = querystring;
40
-
41
- let schema = Schema({ data, intl });
42
-
43
- schema = addExtensionFieldToSchema({
44
- schema,
45
- name: 'listingBodyTemplate',
46
- items: config.blocks.blocksConfig.listing.variations,
47
- intl,
48
- title: { id: intl.formatMessage(messages.template) },
49
- });
50
- const listingVariations = config.blocks.blocksConfig?.listing?.variations;
51
- let activeItem = listingVariations.find(
52
- (item) => item.id === data.listingBodyTemplate,
53
- );
54
- const listingSchemaEnhancer = activeItem?.schemaEnhancer;
55
- if (listingSchemaEnhancer)
56
- schema = listingSchemaEnhancer({
57
- schema: cloneDeep(schema),
58
- data,
59
- intl,
60
- });
61
- schema.properties.sortOnOptions.items = {
62
- choices: Object.keys(sortable_indexes).map((k) => [
63
- k,
64
- sortable_indexes[k].title,
65
- ]),
66
- };
67
-
68
- const { query = {} } = data || {};
69
- // We don't need deep compare here, as this is just json serializable data.
70
- const deepQuery = JSON.stringify(query);
71
- useEffect(() => {
72
- onTriggerSearch(
73
- '',
74
- data?.facets,
75
- data?.query?.sort_on,
76
- data?.query?.sort_order,
77
- );
78
- }, [deepQuery, onTriggerSearch, data]);
79
-
80
- return (
81
- <>
82
- <SearchBlockViewComponent
83
- {...props}
84
- path={getBaseUrl(props.pathname)}
85
- mode="edit"
86
- />
87
- <SidebarPortal selected={selected}>
88
- <BlockDataForm
89
- schema={schema}
90
- onChangeField={(id, value) => {
91
- onChangeBlock(block, {
92
- ...data,
93
- [id]: value,
94
- });
95
- }}
96
- onChangeBlock={onChangeBlock}
97
- formData={data}
98
- navRoot={navRoot}
99
- contentType={contentType}
100
- />
101
- </SidebarPortal>
102
- </>
103
- );
104
- };
105
-
106
- export default compose(withQueryString, withSearch())(SearchBlockEdit);
@@ -1,479 +0,0 @@
1
- //this customization is used for fixing: in the search block, on edit sort on and reversed order doesn't work.
2
- //See here volto pr: https://github.com/plone/volto/pull/5262
3
- import React from 'react';
4
- import { useSelector } from 'react-redux';
5
- import qs from 'query-string';
6
- import { useLocation, useHistory } from 'react-router-dom';
7
-
8
- import { resolveExtension } from '@plone/volto/helpers/Extensions/withBlockExtensions';
9
- import config from '@plone/volto/registry';
10
- import { usePrevious } from '@plone/volto/helpers';
11
- import { isEqual } from 'lodash';
12
-
13
- function getDisplayName(WrappedComponent) {
14
- return WrappedComponent.displayName || WrappedComponent.name || 'Component';
15
- }
16
-
17
- const SEARCH_ENDPOINT_FIELDS = [
18
- 'SearchableText',
19
- 'b_size',
20
- 'limit',
21
- 'sort_on',
22
- 'sort_order',
23
- ];
24
-
25
- const PAQO = 'plone.app.querystring.operation';
26
-
27
- /**
28
- * Based on URL state, gets an initial internal state for the search
29
- *
30
- * @function getInitialState
31
- *
32
- */
33
- function getInitialState(
34
- data,
35
- facets,
36
- urlSearchText,
37
- id,
38
- sortOnParam,
39
- sortOrderParam,
40
- ) {
41
- const {
42
- types: facetWidgetTypes,
43
- } = config.blocks.blocksConfig.search.extensions.facetWidgets;
44
- const facetSettings = data?.facets || [];
45
-
46
- return {
47
- query: [
48
- ...(data.query?.query || []),
49
- ...(facetSettings || [])
50
- .map((facet) => {
51
- if (!facet?.field) return null;
52
-
53
- const { valueToQuery } = resolveExtension(
54
- 'type',
55
- facetWidgetTypes,
56
- facet,
57
- );
58
-
59
- const name = facet.field.value;
60
- const value = facets[name];
61
-
62
- return valueToQuery({ value, facet });
63
- })
64
- .filter((f) => !!f),
65
- ...(urlSearchText
66
- ? [
67
- {
68
- i: 'SearchableText',
69
- o: 'plone.app.querystring.operation.string.contains',
70
- v: urlSearchText,
71
- },
72
- ]
73
- : []),
74
- ],
75
- sort_on: sortOnParam || data.query?.sort_on,
76
- sort_order: sortOrderParam || data.query?.sort_order,
77
- b_size: data.query?.b_size,
78
- limit: data.query?.limit,
79
- block: id,
80
- };
81
- }
82
-
83
- /**
84
- * "Normalizes" the search state to something that's serializable
85
- * (for querying) and used to compute data for the ListingBody
86
- *
87
- * @function normalizeState
88
- *
89
- */
90
- function normalizeState({
91
- query, // base query
92
- facets, // facet values
93
- id, // block id
94
- searchText, // SearchableText
95
- sortOn,
96
- sortOrder,
97
- facetSettings, // data.facets extracted from block data
98
- }) {
99
- const {
100
- types: facetWidgetTypes,
101
- } = config.blocks.blocksConfig.search.extensions.facetWidgets;
102
-
103
- // Here, we are removing the QueryString of the Listing ones, which is present in the Facet
104
- // because we already initialize the facet with those values.
105
- const configuredFacets = facetSettings
106
- ? facetSettings.map((facet) => facet?.field?.value)
107
- : [];
108
-
109
- let copyOfQuery = query.query ? [...query.query] : [];
110
-
111
- const queryWithoutFacet = copyOfQuery.filter((query) => {
112
- return !configuredFacets.includes(query.i);
113
- });
114
-
115
- const params = {
116
- query: [
117
- ...(queryWithoutFacet || []),
118
- ...(facetSettings || []).map((facet) => {
119
- if (!facet?.field) return null;
120
-
121
- const { valueToQuery } = resolveExtension(
122
- 'type',
123
- facetWidgetTypes,
124
- facet,
125
- );
126
-
127
- const name = facet.field.value;
128
- const value = facets[name];
129
-
130
- return valueToQuery({ value, facet });
131
- }),
132
- ].filter((o) => !!o),
133
- sort_on: sortOn || query.sort_on,
134
- sort_order: sortOrder || query.sort_order,
135
- b_size: query.b_size,
136
- limit: query.limit,
137
- block: id,
138
- };
139
-
140
- // Note Ideally the searchtext functionality should be restructured as being just
141
- // another facet. But right now it's the same. This means that if a searchText
142
- // is provided, it will override the SearchableText facet.
143
- // If there is no searchText, the SearchableText in the query remains in effect.
144
- // TODO eventually the searchText should be a distinct facet from SearchableText, and
145
- // the two conditions could be combined, in comparison to the current state, when
146
- // one overrides the other.
147
- if (searchText) {
148
- params.query = params.query.reduce(
149
- // Remove SearchableText from query
150
- (acc, kvp) => (kvp.i === 'SearchableText' ? acc : [...acc, kvp]),
151
- [],
152
- );
153
- params.query.push({
154
- i: 'SearchableText',
155
- o: 'plone.app.querystring.operation.string.contains',
156
- v: searchText,
157
- });
158
- }
159
-
160
- return params;
161
- }
162
-
163
- const getSearchFields = (searchData) => {
164
- return Object.assign(
165
- {},
166
- ...SEARCH_ENDPOINT_FIELDS.map((k) => {
167
- return searchData[k] ? { [k]: searchData[k] } : {};
168
- }),
169
- searchData.query ? { query: serializeQuery(searchData['query']) } : {},
170
- );
171
- };
172
-
173
- /**
174
- * A hook that will mirror the search block state to a hash location
175
- */
176
- const useHashState = () => {
177
- const location = useLocation();
178
- const history = useHistory();
179
-
180
- /**
181
- * Required to maintain parameter compatibility.
182
- With this we will maintain support for receiving hash (#) and search (?) type parameters.
183
- */
184
- const oldState = React.useMemo(() => {
185
- return {
186
- ...qs.parse(location.search),
187
- ...qs.parse(location.hash),
188
- };
189
- }, [location.hash, location.search]);
190
-
191
- // This creates a shallow copy. Why is this needed?
192
- const current = Object.assign(
193
- {},
194
- ...Array.from(Object.keys(oldState)).map((k) => ({ [k]: oldState[k] })),
195
- );
196
-
197
- const setSearchData = React.useCallback(
198
- (searchData) => {
199
- const newParams = qs.parse(location.search);
200
-
201
- let changed = false;
202
-
203
- Object.keys(searchData)
204
- .sort()
205
- .forEach((k) => {
206
- if (searchData[k]) {
207
- newParams[k] = searchData[k];
208
- if (oldState[k] !== searchData[k]) {
209
- changed = true;
210
- }
211
- }
212
- });
213
-
214
- if (changed) {
215
- history.push({
216
- search: qs.stringify(newParams),
217
- });
218
- }
219
- },
220
- [history, oldState, location.search],
221
- );
222
-
223
- return [current, setSearchData];
224
- };
225
-
226
- /**
227
- * A hook to make it possible to switch disable mirroring the search block
228
- * state to the window location. When using the internal state we "start from
229
- * scratch", as it's intended to be used in the edit page.
230
- */
231
- const useSearchBlockState = (uniqueId, isEditMode) => {
232
- const [hashState, setHashState] = useHashState();
233
- const [internalState, setInternalState] = React.useState({});
234
-
235
- return isEditMode
236
- ? [internalState, setInternalState]
237
- : [hashState, setHashState];
238
- };
239
-
240
- // Simple compress/decompress the state in URL by replacing the lengthy string
241
- const deserializeQuery = (q) => {
242
- return JSON.parse(q)?.map((kvp) => ({
243
- ...kvp,
244
- o: kvp.o.replace(/^paqo/, PAQO),
245
- }));
246
- };
247
- const serializeQuery = (q) => {
248
- return JSON.stringify(
249
- q?.map((kvp) => ({ ...kvp, o: kvp.o.replace(PAQO, 'paqo') })),
250
- );
251
- };
252
-
253
- const withSearch = (options) => (WrappedComponent) => {
254
- const { inputDelay = 1000 } = options || {};
255
-
256
- function WithSearch(props) {
257
- const { data, id, editable = false } = props;
258
-
259
- const [locationSearchData, setLocationSearchData] = useSearchBlockState(
260
- id,
261
- editable,
262
- );
263
-
264
- // TODO: Improve the hook dependencies out of the scope of https://github.com/plone/volto/pull/4662
265
- // eslint-disable-next-line react-hooks/exhaustive-deps
266
- const urlQuery = locationSearchData.query
267
- ? deserializeQuery(locationSearchData.query)
268
- : [];
269
- const urlSearchText =
270
- locationSearchData.SearchableText ||
271
- urlQuery.find(({ i }) => i === 'SearchableText')?.v ||
272
- '';
273
-
274
- // TODO: refactor, should use only useLocationStateManager()!!!
275
- const [searchText, setSearchText] = React.useState(urlSearchText);
276
- // TODO: Improve the hook dependencies out of the scope of https://github.com/plone/volto/pull/4662
277
- // eslint-disable-next-line react-hooks/exhaustive-deps
278
- const configuredFacets =
279
- data.facets?.map((facet) => facet?.field?.value) || [];
280
-
281
- // Here we are getting the initial value of the facet if Listing Query contains the same criteria as
282
- // facet.
283
- const queryData = data?.query?.query
284
- ? deserializeQuery(JSON.stringify(data?.query?.query))
285
- : [];
286
-
287
- let intializeFacetWithQueryValue = [];
288
-
289
- for (let value of configuredFacets) {
290
- const queryString = queryData.find((item) => item.i === value);
291
- if (queryString) {
292
- intializeFacetWithQueryValue = [
293
- ...intializeFacetWithQueryValue,
294
- { [queryString.i]: queryString.v },
295
- ];
296
- }
297
- }
298
-
299
- const multiFacets = data.facets
300
- ?.filter((facet) => facet?.multiple)
301
- .map((facet) => facet?.field?.value);
302
- const [facets, setFacets] = React.useState(
303
- Object.assign(
304
- {},
305
- ...urlQuery.map(({ i, v }) => ({ [i]: v })),
306
- // TODO: the 'o' should be kept. This would be a major refactoring of the facets
307
- ...intializeFacetWithQueryValue,
308
- // support for simple filters like ?Subject=something
309
- // TODO: since the move to hash params this is no longer working.
310
- // We'd have to treat the location.search and manage it just like the
311
- // hash, to support it. We can read it, but we'd have to reset it as
312
- // well, so at that point what's the difference to the hash?
313
- ...configuredFacets.map((f) =>
314
- locationSearchData[f]
315
- ? {
316
- [f]:
317
- multiFacets.indexOf(f) > -1
318
- ? [locationSearchData[f]]
319
- : locationSearchData[f],
320
- }
321
- : {},
322
- ),
323
- ),
324
- );
325
- const previousUrlQuery = usePrevious(urlQuery);
326
-
327
- // During first render the previousUrlQuery is undefined and urlQuery
328
- // is empty so it ressetting the facet when you are navigating but during reload we have urlQuery and we need
329
- // to set the facet at first render.
330
- const preventOverrideOfFacetState =
331
- previousUrlQuery === undefined && urlQuery.length === 0;
332
-
333
- React.useEffect(() => {
334
- if (
335
- !isEqual(urlQuery, previousUrlQuery) &&
336
- !preventOverrideOfFacetState
337
- ) {
338
- setFacets(
339
- Object.assign(
340
- {},
341
- ...urlQuery.map(({ i, v }) => ({ [i]: v })), // TODO: the 'o' should be kept. This would be a major refactoring of the facets
342
-
343
- // support for simple filters like ?Subject=something
344
- // TODO: since the move to hash params this is no longer working.
345
- // We'd have to treat the location.search and manage it just like the
346
- // hash, to support it. We can read it, but we'd have to reset it as
347
- // well, so at that point what's the difference to the hash?
348
- ...configuredFacets.map((f) =>
349
- locationSearchData[f]
350
- ? {
351
- [f]:
352
- multiFacets.indexOf(f) > -1
353
- ? [locationSearchData[f]]
354
- : locationSearchData[f],
355
- }
356
- : {},
357
- ),
358
- ),
359
- );
360
- }
361
- }, [
362
- urlQuery,
363
- configuredFacets,
364
- locationSearchData,
365
- multiFacets,
366
- previousUrlQuery,
367
- preventOverrideOfFacetState,
368
- ]);
369
-
370
- const [sortOn, setSortOn] = React.useState(data?.query?.sort_on);
371
- const [sortOrder, setSortOrder] = React.useState(data?.query?.sort_order);
372
-
373
- const [searchData, setSearchData] = React.useState(
374
- getInitialState(data, facets, urlSearchText, id),
375
- );
376
-
377
- const deepFacets = JSON.stringify(facets);
378
- const deepData = JSON.stringify(data);
379
- React.useEffect(() => {
380
- setSearchData(
381
- getInitialState(
382
- JSON.parse(deepData),
383
- JSON.parse(deepFacets),
384
- urlSearchText,
385
- id,
386
- sortOn,
387
- sortOrder,
388
- ),
389
- );
390
- }, [deepData, deepFacets, urlSearchText, id, sortOn, sortOrder]);
391
-
392
- const timeoutRef = React.useRef();
393
- const facetSettings = data?.facets;
394
-
395
- const deepQuery = JSON.stringify(data.query);
396
- const onTriggerSearch = React.useCallback(
397
- (
398
- toSearchText = undefined,
399
- toSearchFacets = undefined,
400
- toSortOn = undefined,
401
- toSortOrder = undefined,
402
- ) => {
403
- if (timeoutRef.current) clearTimeout(timeoutRef.current);
404
- timeoutRef.current = setTimeout(
405
- () => {
406
- const newSearchData = normalizeState({
407
- id,
408
- query: data.query || {},
409
- facets: toSearchFacets || facets,
410
- searchText: toSearchText ? toSearchText.trim() : '',
411
- sortOn: toSortOn || undefined,
412
- sortOrder: toSortOrder || sortOrder,
413
- facetSettings,
414
- });
415
- if (toSearchFacets) setFacets(toSearchFacets);
416
- if (toSortOn) setSortOn(toSortOn || undefined);
417
- if (toSortOrder) setSortOrder(toSortOrder);
418
- setSearchData(newSearchData);
419
- setLocationSearchData(getSearchFields(newSearchData));
420
- },
421
- toSearchFacets ? inputDelay / 3 : inputDelay,
422
- );
423
- },
424
- // eslint-disable-next-line react-hooks/exhaustive-deps
425
- [
426
- // Use deep comparison of data.query
427
- deepQuery,
428
- facets,
429
- id,
430
- setLocationSearchData,
431
- searchText,
432
- sortOn,
433
- sortOrder,
434
- facetSettings,
435
- ],
436
- );
437
-
438
- const removeSearchQuery = () => {
439
- let newSearchData = { ...searchData };
440
- newSearchData.query = searchData.query.reduce(
441
- // Remove SearchableText from query
442
- (acc, kvp) => (kvp.i === 'SearchableText' ? acc : [...acc, kvp]),
443
- [],
444
- );
445
- setSearchData(newSearchData);
446
- setLocationSearchData(getSearchFields(newSearchData));
447
- };
448
-
449
- const querystringResults = useSelector(
450
- (state) => state.querystringsearch.subrequests,
451
- );
452
- const totalItems =
453
- querystringResults[id]?.total || querystringResults[id]?.items?.length;
454
-
455
- return (
456
- <WrappedComponent
457
- {...props}
458
- searchData={searchData}
459
- facets={facets}
460
- setFacets={setFacets}
461
- setSortOn={setSortOn}
462
- setSortOrder={setSortOrder}
463
- sortOn={sortOn}
464
- sortOrder={sortOrder}
465
- searchedText={urlSearchText}
466
- searchText={searchText}
467
- removeSearchQuery={removeSearchQuery}
468
- setSearchText={setSearchText}
469
- onTriggerSearch={onTriggerSearch}
470
- totalItems={totalItems}
471
- />
472
- );
473
- }
474
- WithSearch.displayName = `WithSearch(${getDisplayName(WrappedComponent)})`;
475
-
476
- return WithSearch;
477
- };
478
-
479
- export default withSearch;