@eeacms/volto-clms-theme 1.0.159 → 1.0.160

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,11 @@ 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.0.160](https://github.com/eea/volto-clms-theme/compare/1.0.159...1.0.160) - 22 December 2022
8
+
9
+ #### :hammer_and_wrench: Others
10
+
11
+ - clean up duplicate SlateContextToolbar buttons [bipoza - [`9e5b2f6`](https://github.com/eea/volto-clms-theme/commit/9e5b2f6b6e98fba35faf0203a2ee6b3e5a0e5001)]
7
12
  ### [1.0.159](https://github.com/eea/volto-clms-theme/compare/1.0.158...1.0.159) - 22 December 2022
8
13
 
9
14
  #### :hammer_and_wrench: Others
package/README.md CHANGED
@@ -53,6 +53,12 @@
53
53
 
54
54
  1. Happy editing!
55
55
 
56
+ ## Things to keep in mind before migrating to Volto 16
57
+ 1. Remove the volto-slate override. This override is a patch to clean up duplicate SlateContextToolbar buttons. This is not necessary in Volto 16.
58
+
59
+ ````bash
60
+ rm -rf src/customizations/volto-slate
61
+ ````
56
62
  ## Release
57
63
 
58
64
  ### Automatic release using Jenkins
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eeacms/volto-clms-theme",
3
- "version": "1.0.159",
3
+ "version": "1.0.160",
4
4
  "description": "volto-clms-theme: Volto theme for CLMS site",
5
5
  "main": "src/index.js",
6
6
  "author": "CodeSyntax for the European Environment Agency",
@@ -0,0 +1,73 @@
1
+ import React from 'react'; // , useState
2
+ import SlateToolbar from 'volto-slate/editor/ui/SlateToolbar';
3
+ import SlateContextToolbar from 'volto-slate/editor/ui/SlateContextToolbar';
4
+ import config from '@plone/volto/registry';
5
+ import { hasRangeSelection } from 'volto-slate/utils';
6
+ import { ReactEditor } from 'slate-react';
7
+ import cx from 'classnames';
8
+
9
+ /**
10
+ * The main Slate toolbar. All the others are just wrappers, UI or used here
11
+ * This override is a patch to clean up duplicate SlateContextToolbar buttons. This is not necessary in Volto 16.
12
+ */
13
+ const InlineToolbar = (props) => {
14
+ const {
15
+ editor,
16
+ className,
17
+ showExpandedToolbar,
18
+ setShowExpandedToolbar,
19
+ } = props;
20
+
21
+ const { slate } = config.settings;
22
+ const [showMainToolbar, setShowMainToolbar] = React.useState(
23
+ !!(editor.selection && hasRangeSelection(editor)),
24
+ );
25
+
26
+ React.useEffect(() => {
27
+ let el;
28
+ try {
29
+ el = ReactEditor.toDOMNode(editor, editor);
30
+ } catch {
31
+ return;
32
+ }
33
+ const toggleToolbar = () => {
34
+ const selection = window.getSelection();
35
+ const { activeElement } = window.document;
36
+ if (activeElement !== el) return;
37
+ if (!selection.isCollapsed && !showMainToolbar) {
38
+ setShowMainToolbar(true);
39
+ } else if (selection.isCollapsed && showMainToolbar) {
40
+ setShowMainToolbar(false);
41
+ }
42
+ };
43
+ window.document.addEventListener('selectionchange', toggleToolbar);
44
+ return () => document.removeEventListener('selectionchange', toggleToolbar);
45
+ }, [editor, showMainToolbar]);
46
+
47
+ const showContextToolbar =
48
+ slate.contextToolbarButtons.map((plug) => plug(editor)).filter((c) => !!c)
49
+ .length > 0;
50
+ return (
51
+ <>
52
+ <SlateToolbar
53
+ className={cx(className, {
54
+ upper: showContextToolbar,
55
+ })}
56
+ selected={true}
57
+ enableExpando={slate.enableExpandedToolbar}
58
+ showExpandedToolbar={showExpandedToolbar}
59
+ setShowExpandedToolbar={setShowExpandedToolbar}
60
+ show={showMainToolbar}
61
+ />
62
+ <SlateContextToolbar
63
+ editor={editor}
64
+ plugins={slate.contextToolbarButtons.filter((obj, pos, arr) => {
65
+ return arr.map((mapObj) => mapObj.name).indexOf(obj.name) === pos;
66
+ })}
67
+ show={showContextToolbar}
68
+ />
69
+ </>
70
+ );
71
+ };
72
+
73
+ export default InlineToolbar;