@eeacms/volto-group-block 6.1.2 → 6.2.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,11 +4,19 @@ 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
|
+
### [6.2.0](https://github.com/eea/volto-group-block/compare/6.1.2...6.2.0) - 20 July 2023
|
|
8
|
+
|
|
9
|
+
#### :nail_care: Enhancements
|
|
10
|
+
|
|
11
|
+
- refactor: char-count component refs #253801 [Nilesh - [`1a54719`](https://github.com/eea/volto-group-block/commit/1a54719af523663314190741417bb06142967f68)]
|
|
12
|
+
|
|
13
|
+
#### :hammer_and_wrench: Others
|
|
14
|
+
|
|
15
|
+
- Release 6.2.0 [Alin Voinea - [`e4e254d`](https://github.com/eea/volto-group-block/commit/e4e254da4c109ee1c8c8a9ce42821eeabfae06ef)]
|
|
7
16
|
### [6.1.2](https://github.com/eea/volto-group-block/compare/6.1.1...6.1.2) - 12 June 2023
|
|
8
17
|
|
|
9
18
|
#### :house: Internal changes
|
|
10
19
|
|
|
11
|
-
- chore: [JENKINS] Deprecate circularity website [valentinab25 - [`ad30e83`](https://github.com/eea/volto-group-block/commit/ad30e832bb869b67dc4e64ed99590b51cb80ab75)]
|
|
12
20
|
|
|
13
21
|
#### :hammer_and_wrench: Others
|
|
14
22
|
|
|
@@ -25,19 +33,12 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
25
33
|
|
|
26
34
|
#### :hammer_and_wrench: Others
|
|
27
35
|
|
|
28
|
-
- Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`37ffae5`](https://github.com/eea/volto-group-block/commit/37ffae512967b36af22cbed208a3ec9e1ddc392b)]
|
|
29
36
|
## [6.0.0](https://github.com/eea/volto-group-block/compare/5.0.1...6.0.0) - 24 March 2023
|
|
30
37
|
|
|
31
38
|
#### :hammer_and_wrench: Others
|
|
32
39
|
|
|
33
40
|
- (feat): Possibility to copy/cut/paste blocks within section group block - refs #157469 [dobri1408 - [`e9fc098`](https://github.com/eea/volto-group-block/commit/e9fc09825ba2ae258feb77864491d97d94c585b4)]
|
|
34
|
-
- Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`db4b09a`](https://github.com/eea/volto-group-block/commit/db4b09a6c14a8b271dec0c766886ffbcc3fe205e)]
|
|
35
|
-
- Add Sonarqube tag using advisory-board-frontend addons list [EEA Jenkins - [`b8c2bf4`](https://github.com/eea/volto-group-block/commit/b8c2bf471868bb0394b2dbbf75ccb7917a9ef0bf)]
|
|
36
|
-
- Add Sonarqube tag using advisory-board-frontend addons list [EEA Jenkins - [`b343119`](https://github.com/eea/volto-group-block/commit/b3431196931fd568476fa8bf6fbc508e086229ae)]
|
|
37
41
|
- test(Jenkins): Run tests and cypress with latest canary @plone/volto [Alin Voinea - [`2f42e7c`](https://github.com/eea/volto-group-block/commit/2f42e7c19a1da5a9c6a883cb4f101e8fa224ff94)]
|
|
38
|
-
- Add Sonarqube tag using cca-frontend addons list [EEA Jenkins - [`73afcc2`](https://github.com/eea/volto-group-block/commit/73afcc2f417797cedaa78cceefb007001d6c2406)]
|
|
39
|
-
- yarn 3 [Alin Voinea - [`3c00ccc`](https://github.com/eea/volto-group-block/commit/3c00ccc7110bbf12a4d268182313418fb46b1a5d)]
|
|
40
|
-
- Add Sonarqube tag using demo-kitkat-frontend addons list [EEA Jenkins - [`9b9662b`](https://github.com/eea/volto-group-block/commit/9b9662bda1da70ba0c3a7b4b05cebf130ed89e9e)]
|
|
41
42
|
### [5.0.1](https://github.com/eea/volto-group-block/compare/5.0.0...5.0.1) - 16 November 2022
|
|
42
43
|
|
|
43
44
|
#### :nail_care: Enhancements
|
|
@@ -54,8 +55,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
54
55
|
|
|
55
56
|
- Prepare 5.0.0 release [Miu Razvan - [`88c0ddd`](https://github.com/eea/volto-group-block/commit/88c0ddd569aeda7ee34d1eadea6a087f4e7dc257)]
|
|
56
57
|
- Update dependencies [Alin Voinea - [`c8405af`](https://github.com/eea/volto-group-block/commit/c8405afb830cdf62e7877bf30b619933519e1d71)]
|
|
57
|
-
- Add Sonarqube tag using marine-frontend addons list [EEA Jenkins - [`18e26c6`](https://github.com/eea/volto-group-block/commit/18e26c6939706d572ab8574e9b1826b9abc76314)]
|
|
58
|
-
- Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`8ed6d21`](https://github.com/eea/volto-group-block/commit/8ed6d21d8489911cc4cb471e3f8823c35f4adc50)]
|
|
59
58
|
### [4.3.8](https://github.com/eea/volto-group-block/compare/4.3.7...4.3.8) - 26 August 2022
|
|
60
59
|
|
|
61
60
|
### [4.3.7](https://github.com/eea/volto-group-block/compare/4.3.6...4.3.7) - 22 August 2022
|
|
@@ -68,9 +67,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
68
67
|
|
|
69
68
|
#### :hammer_and_wrench: Others
|
|
70
69
|
|
|
71
|
-
- Add Sonarqube tag using circularity-frontend addons list [EEA Jenkins - [`4e73f8b`](https://github.com/eea/volto-group-block/commit/4e73f8be3c73559557efadc410cb56abc055d82d)]
|
|
72
|
-
- Add Sonarqube tag using clms-frontend addons list [EEA Jenkins - [`3040335`](https://github.com/eea/volto-group-block/commit/3040335002c63b50208c95918413bc958150e7a9)]
|
|
73
|
-
- Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`386f730`](https://github.com/eea/volto-group-block/commit/386f730ed65f73fe1468b9b77351c97fb70edcc5)]
|
|
74
70
|
### [4.3.5](https://github.com/eea/volto-group-block/compare/4.3.4...4.3.5) - 4 January 2022
|
|
75
71
|
|
|
76
72
|
### [4.3.4](https://github.com/eea/volto-group-block/compare/4.3.3...4.3.4) - 3 January 2022
|
|
@@ -79,23 +75,15 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
79
75
|
|
|
80
76
|
#### :hammer_and_wrench: Others
|
|
81
77
|
|
|
82
|
-
- Add Sonarqube tag using freshwater-frontend addons list [EEA Jenkins - [`3e62d79`](https://github.com/eea/volto-group-block/commit/3e62d79a7ed37d10d623bc845d43e1144f8080f7)]
|
|
83
78
|
### [4.3.2](https://github.com/eea/volto-group-block/compare/4.3.1...4.3.2) - 10 December 2021
|
|
84
79
|
|
|
85
80
|
#### :hammer_and_wrench: Others
|
|
86
81
|
|
|
87
82
|
- Refs #142010 - Optimize Volto-addons gitflow pipelines [valentinab25 - [`bc36cf5`](https://github.com/eea/volto-group-block/commit/bc36cf58c39e2b43c2fbf5189df6ddefc1260857)]
|
|
88
|
-
- Add Sonarqube tag using industry-frontend addons list [EEA Jenkins - [`8038e78`](https://github.com/eea/volto-group-block/commit/8038e783c1e8ddd71e21f72070fdfa8e7e098993)]
|
|
89
|
-
- Add Sonarqube tag using clms-frontend addons list [EEA Jenkins - [`daccdbc`](https://github.com/eea/volto-group-block/commit/daccdbc733e47be7d6536eb67f8f2eea038dc94b)]
|
|
90
83
|
### [4.3.1](https://github.com/eea/volto-group-block/compare/4.3.0...4.3.1) - 11 October 2021
|
|
91
84
|
|
|
92
85
|
#### :hammer_and_wrench: Others
|
|
93
86
|
|
|
94
|
-
- Add Sonarqube tag using bise-frontend addons list [EEA Jenkins - [`b0092e4`](https://github.com/eea/volto-group-block/commit/b0092e4f78a1a0184e22e32bb9806cd57417dfb2)]
|
|
95
|
-
- Add Sonarqube tag using sustainability-frontend addons list [EEA Jenkins - [`ff8889c`](https://github.com/eea/volto-group-block/commit/ff8889cb7b0761b1df43b201984ce40b14e1561b)]
|
|
96
|
-
- Add Sonarqube tag using climate-energy-frontend addons list [EEA Jenkins - [`0375c28`](https://github.com/eea/volto-group-block/commit/0375c28ed1ffe9186a4790b454795c0ca8039f72)]
|
|
97
|
-
- Add Sonarqube tag using ims-frontend addons list [EEA Jenkins - [`c392190`](https://github.com/eea/volto-group-block/commit/c392190f044f5d9397bd2fb8c3d6a357f84960d0)]
|
|
98
|
-
- Add Sonarqube tag using frontend addons list [EEA Jenkins - [`9694501`](https://github.com/eea/volto-group-block/commit/9694501141e6780eba89464d36406e3c93629fd8)]
|
|
99
87
|
### [4.3.0](https://github.com/eea/volto-group-block/compare/4.2.3...4.3.0) - 24 June 2021
|
|
100
88
|
|
|
101
89
|
#### :hammer_and_wrench: Others
|
|
@@ -211,7 +199,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
211
199
|
- Release 1.0.0 [Alin Voinea - [`b6ef873`](https://github.com/eea/volto-group-block/commit/b6ef873cb6f61e17db66fdd4de1d9d4902a66fc6)]
|
|
212
200
|
- Update package meta info [Alin Voinea - [`143b7d4`](https://github.com/eea/volto-group-block/commit/143b7d44438d7afa5e346a9d21a85352df4e925f)]
|
|
213
201
|
- Add Jenkinkins pipeline [Alin Voinea - [`866a4e1`](https://github.com/eea/volto-group-block/commit/866a4e14ea1eb8f5adb01222e576e5ab6dc73a70)]
|
|
214
|
-
- yarn prettier [Alin Voinea - [`e3fe0a3`](https://github.com/eea/volto-group-block/commit/e3fe0a36b89878769341b45198d6c9e2f2584d15)]
|
|
215
202
|
### [0.1.3](https://github.com/eea/volto-group-block/compare/0.1.2...0.1.3) - 9 November 2020
|
|
216
203
|
|
|
217
204
|
#### :hammer_and_wrench: Others
|
|
@@ -251,5 +238,4 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
251
238
|
- Render meta block [Alin Voinea - [`0d44560`](https://github.com/eea/volto-group-block/commit/0d4456011ca56454068a54c610250b02df4ccb3b)]
|
|
252
239
|
- Implement meta block allowedBlocks settings [Alin Voinea - [`f24feb1`](https://github.com/eea/volto-group-block/commit/f24feb1a1751f04841c21c7cd52a517fb02074ba)]
|
|
253
240
|
- Edit meta block [Alin Voinea - [`236d291`](https://github.com/eea/volto-group-block/commit/236d29156fa835a7aa54eecdb4f120de0d64b271)]
|
|
254
|
-
- yarn bootstrap [Alin Voinea - [`e009dfb`](https://github.com/eea/volto-group-block/commit/e009dfb6b9b74d101a6722f0982a5359fc522b6b)]
|
|
255
241
|
- Initial commit [Alin Voinea - [`6a7b0de`](https://github.com/eea/volto-group-block/commit/6a7b0deb8f873d1462fd6a9c61edfc1562b3aace)]
|
package/package.json
CHANGED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import cx from 'classnames';
|
|
2
|
+
import isString from 'lodash/isString';
|
|
3
|
+
import isArray from 'lodash/isArray';
|
|
4
|
+
import { Icon } from '@plone/volto/components';
|
|
5
|
+
import config from '@plone/volto/registry';
|
|
6
|
+
import { visitBlocks } from '@plone/volto/helpers/Blocks/Blocks';
|
|
7
|
+
import { serializeNodesToText } from '@plone/volto-slate/editor/render';
|
|
8
|
+
import delightedSVG from '@plone/volto/icons/delighted.svg';
|
|
9
|
+
import dissatisfiedSVG from '@plone/volto/icons/dissatisfied.svg';
|
|
10
|
+
|
|
11
|
+
const CounterComponent = ({ data, setSidebarTab, setSelectedBlock }) => {
|
|
12
|
+
const { maxChars } = data;
|
|
13
|
+
let charCount = 0;
|
|
14
|
+
|
|
15
|
+
const countCharsWithoutSpaces = (paragraph) => {
|
|
16
|
+
const regex = /[^\s\\]/g;
|
|
17
|
+
|
|
18
|
+
return (paragraph.match(regex) || []).length;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const countCharsWithSpaces = (paragraph) => {
|
|
22
|
+
return paragraph?.length || 0;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const countTextInBlocks = (blocksObject) => {
|
|
26
|
+
const { countTextIn } = config.blocks?.blocksConfig?.group;
|
|
27
|
+
let groupCharCount = 0;
|
|
28
|
+
if (!maxChars) {
|
|
29
|
+
return groupCharCount;
|
|
30
|
+
}
|
|
31
|
+
if (!blocksObject) return groupCharCount;
|
|
32
|
+
|
|
33
|
+
visitBlocks(blocksObject, ([id, data]) => {
|
|
34
|
+
let foundText;
|
|
35
|
+
if (data && countTextIn?.includes(data?.['@type'])) {
|
|
36
|
+
if (isString(data?.plaintext)) foundText = data?.plaintext;
|
|
37
|
+
else if (isArray(data?.value) && data?.value !== null)
|
|
38
|
+
foundText = serializeNodesToText(data?.value);
|
|
39
|
+
} else foundText = '';
|
|
40
|
+
|
|
41
|
+
groupCharCount += data?.ignoreSpaces
|
|
42
|
+
? countCharsWithoutSpaces(foundText)
|
|
43
|
+
: countCharsWithSpaces(foundText);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
return groupCharCount;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
charCount = countTextInBlocks(data?.data);
|
|
50
|
+
|
|
51
|
+
const counterClass =
|
|
52
|
+
charCount < Math.ceil(maxChars / 1.05)
|
|
53
|
+
? 'info'
|
|
54
|
+
: charCount < maxChars
|
|
55
|
+
? 'warning'
|
|
56
|
+
: 'danger';
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<p
|
|
60
|
+
className={cx('counter', counterClass)}
|
|
61
|
+
onClick={() => {
|
|
62
|
+
setSelectedBlock();
|
|
63
|
+
setSidebarTab(1);
|
|
64
|
+
}}
|
|
65
|
+
aria-hidden="true"
|
|
66
|
+
>
|
|
67
|
+
{maxChars - charCount < 0 ? (
|
|
68
|
+
<>
|
|
69
|
+
<span>{`${charCount - maxChars} characters over the limit`}</span>
|
|
70
|
+
<Icon name={dissatisfiedSVG} size="24px" />
|
|
71
|
+
</>
|
|
72
|
+
) : (
|
|
73
|
+
<>
|
|
74
|
+
<span>{`${
|
|
75
|
+
maxChars - charCount
|
|
76
|
+
} characters remaining out of ${maxChars}`}</span>
|
|
77
|
+
<Icon name={delightedSVG} size="24px" />
|
|
78
|
+
</>
|
|
79
|
+
)}
|
|
80
|
+
</p>
|
|
81
|
+
);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export default CounterComponent;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useState } from 'react';
|
|
1
|
+
import React, { useState, useCallback } from 'react';
|
|
2
2
|
import { isEmpty, without } from 'lodash';
|
|
3
3
|
import config from '@plone/volto/registry';
|
|
4
4
|
import {
|
|
@@ -12,14 +12,12 @@ import {
|
|
|
12
12
|
emptyBlocksForm,
|
|
13
13
|
getBlocksLayoutFieldname,
|
|
14
14
|
} from '@plone/volto/helpers';
|
|
15
|
-
import delightedSVG from '@plone/volto/icons/delighted.svg';
|
|
16
|
-
import dissatisfiedSVG from '@plone/volto/icons/dissatisfied.svg';
|
|
17
15
|
import PropTypes from 'prop-types';
|
|
18
16
|
import { Button, Segment } from 'semantic-ui-react';
|
|
19
17
|
import EditBlockWrapper from './EditBlockWrapper';
|
|
20
18
|
import EditSchema from './EditSchema';
|
|
19
|
+
import CounterComponent from './CounterComponent';
|
|
21
20
|
import helpSVG from '@plone/volto/icons/help.svg';
|
|
22
|
-
import cx from 'classnames';
|
|
23
21
|
import './editor.less';
|
|
24
22
|
|
|
25
23
|
const Edit = (props) => {
|
|
@@ -43,8 +41,6 @@ const Edit = (props) => {
|
|
|
43
41
|
);
|
|
44
42
|
|
|
45
43
|
const blockState = {};
|
|
46
|
-
let charCount = 0;
|
|
47
|
-
|
|
48
44
|
const handleKeyDown = (
|
|
49
45
|
e,
|
|
50
46
|
index,
|
|
@@ -71,47 +67,48 @@ const Edit = (props) => {
|
|
|
71
67
|
}
|
|
72
68
|
};
|
|
73
69
|
|
|
74
|
-
const onSelectBlock = (
|
|
75
|
-
|
|
76
|
-
|
|
70
|
+
const onSelectBlock = useCallback(
|
|
71
|
+
(id, isMultipleSelection, event, activeBlock) => {
|
|
72
|
+
let newMultiSelected = [];
|
|
73
|
+
let selected = id;
|
|
77
74
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
75
|
+
if (isMultipleSelection) {
|
|
76
|
+
selected = null;
|
|
77
|
+
const blocksLayoutFieldname = getBlocksLayoutFieldname(data?.data);
|
|
78
|
+
const blocks_layout = data?.data[blocksLayoutFieldname].items;
|
|
79
|
+
if (event.shiftKey) {
|
|
80
|
+
const anchor =
|
|
81
|
+
multiSelected.length > 0
|
|
82
|
+
? blocks_layout.indexOf(multiSelected[0])
|
|
83
|
+
: blocks_layout.indexOf(activeBlock);
|
|
84
|
+
const focus = blocks_layout.indexOf(id);
|
|
85
|
+
if (anchor === focus) {
|
|
86
|
+
newMultiSelected = [id];
|
|
87
|
+
} else if (focus > anchor) {
|
|
88
|
+
newMultiSelected = [...blocks_layout.slice(anchor, focus + 1)];
|
|
89
|
+
} else {
|
|
90
|
+
newMultiSelected = [...blocks_layout.slice(focus, anchor + 1)];
|
|
91
|
+
}
|
|
94
92
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
93
|
+
if ((event.ctrlKey || event.metaKey) && !event.shiftKey) {
|
|
94
|
+
if (multiSelected.includes(id)) {
|
|
95
|
+
selected = null;
|
|
96
|
+
newMultiSelected = without(multiSelected, id);
|
|
97
|
+
} else {
|
|
98
|
+
newMultiSelected = [...(multiSelected || []), id];
|
|
99
|
+
}
|
|
102
100
|
}
|
|
103
101
|
}
|
|
104
|
-
}
|
|
105
102
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
103
|
+
setSelectedBlock(selected);
|
|
104
|
+
setMultiSelected(newMultiSelected);
|
|
105
|
+
},
|
|
106
|
+
[data.data, multiSelected],
|
|
107
|
+
);
|
|
109
108
|
|
|
110
109
|
const changeBlockData = (newBlockData) => {
|
|
111
110
|
let pastedBlocks = newBlockData.blocks_layout.items.filter((blockID) => {
|
|
112
|
-
|
|
113
|
-
return false;
|
|
114
|
-
return true;
|
|
111
|
+
return !data?.data?.blocks_layout.items.find((x) => x === blockID);
|
|
115
112
|
});
|
|
116
113
|
const selectedIndex =
|
|
117
114
|
data.data.blocks_layout.items.indexOf(selectedBlock) + 1;
|
|
@@ -144,101 +141,6 @@ const Edit = (props) => {
|
|
|
144
141
|
}
|
|
145
142
|
}, [onChangeBlock, properties, selectedBlock, block, data, data_blocks]);
|
|
146
143
|
|
|
147
|
-
/**
|
|
148
|
-
* Count the number of characters that are anything except using Regex
|
|
149
|
-
* @param {string} paragraph
|
|
150
|
-
* @returns
|
|
151
|
-
*/
|
|
152
|
-
const countCharsWithoutSpaces = (paragraph) => {
|
|
153
|
-
const regex = /[^\s\\]/g;
|
|
154
|
-
|
|
155
|
-
return (paragraph.match(regex) || []).length;
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Count the number of characters
|
|
160
|
-
* @param {string} paragraph
|
|
161
|
-
* @returns
|
|
162
|
-
*/
|
|
163
|
-
const countCharsWithSpaces = (paragraph) => {
|
|
164
|
-
return paragraph?.length || 0;
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Recursively look for any block that contains text or plaintext
|
|
169
|
-
* @param {Object} blocksObject
|
|
170
|
-
* @returns
|
|
171
|
-
*/
|
|
172
|
-
const countTextInBlocks = (blocksObject) => {
|
|
173
|
-
let groupCharCount = 0;
|
|
174
|
-
if (!props.data.maxChars) {
|
|
175
|
-
return groupCharCount;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
Object.keys(blocksObject).forEach((blockId) => {
|
|
179
|
-
const foundText = blocksObject[blockId]?.plaintext
|
|
180
|
-
? blocksObject[blockId]?.plaintext
|
|
181
|
-
: blocksObject[blockId]?.text?.blocks[0]?.text
|
|
182
|
-
? blocksObject[blockId].text.blocks[0].text
|
|
183
|
-
: blocksObject[blockId]?.data?.blocks
|
|
184
|
-
? countTextInBlocks(blocksObject[blockId]?.data?.blocks)
|
|
185
|
-
: blocksObject[blockId]?.blocks
|
|
186
|
-
? countTextInBlocks(blocksObject[blockId]?.blocks)
|
|
187
|
-
: '';
|
|
188
|
-
const resultText =
|
|
189
|
-
typeof foundText === 'string' || foundText instanceof String
|
|
190
|
-
? foundText
|
|
191
|
-
: '';
|
|
192
|
-
|
|
193
|
-
groupCharCount += props.data.ignoreSpaces
|
|
194
|
-
? countCharsWithoutSpaces(resultText)
|
|
195
|
-
: countCharsWithSpaces(resultText);
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
return groupCharCount;
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
const showCharCounter = () => {
|
|
202
|
-
if (data_blocks) {
|
|
203
|
-
charCount = countTextInBlocks(data_blocks);
|
|
204
|
-
}
|
|
205
|
-
};
|
|
206
|
-
showCharCounter();
|
|
207
|
-
|
|
208
|
-
const counterClass =
|
|
209
|
-
charCount < Math.ceil(props.data.maxChars / 1.05)
|
|
210
|
-
? 'info'
|
|
211
|
-
: charCount < props.data.maxChars
|
|
212
|
-
? 'warning'
|
|
213
|
-
: 'danger';
|
|
214
|
-
|
|
215
|
-
const counterComponent = props.data.maxChars ? (
|
|
216
|
-
<p
|
|
217
|
-
className={cx('counter', counterClass)}
|
|
218
|
-
onClick={() => {
|
|
219
|
-
setSelectedBlock();
|
|
220
|
-
props.setSidebarTab(1);
|
|
221
|
-
}}
|
|
222
|
-
aria-hidden="true"
|
|
223
|
-
>
|
|
224
|
-
{props.data.maxChars - charCount < 0 ? (
|
|
225
|
-
<>
|
|
226
|
-
<span>{`${
|
|
227
|
-
charCount - props.data.maxChars
|
|
228
|
-
} characters over the limit`}</span>
|
|
229
|
-
<Icon name={dissatisfiedSVG} size="24px" />
|
|
230
|
-
</>
|
|
231
|
-
) : (
|
|
232
|
-
<>
|
|
233
|
-
<span>{`${
|
|
234
|
-
props.data.maxChars - charCount
|
|
235
|
-
} characters remaining out of ${props.data.maxChars}`}</span>
|
|
236
|
-
<Icon name={delightedSVG} size="24px" />
|
|
237
|
-
</>
|
|
238
|
-
)}
|
|
239
|
-
</p>
|
|
240
|
-
) : null;
|
|
241
|
-
|
|
242
144
|
// Get editing instructions from block settings or props
|
|
243
145
|
let instructions = data?.instructions?.data || data?.instructions;
|
|
244
146
|
if (!instructions || instructions === '<p><br/></p>') {
|
|
@@ -355,7 +257,9 @@ const Edit = (props) => {
|
|
|
355
257
|
)}
|
|
356
258
|
</BlocksForm>
|
|
357
259
|
|
|
358
|
-
{
|
|
260
|
+
{props.data.maxChars && (
|
|
261
|
+
<CounterComponent {...props} setSelectedBlock={setSelectedBlock} />
|
|
262
|
+
)}
|
|
359
263
|
<SidebarPortal selected={selected && !selectedBlock}>
|
|
360
264
|
{instructions && (
|
|
361
265
|
<Segment attached>
|