@eeacms/volto-group-block 8.1.1 → 9.0.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,12 @@ 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
+ ### [9.0.0](https://github.com/eea/volto-group-block/compare/8.1.1...9.0.0) - 10 February 2026
8
+
9
+ #### :rocket: New Features
10
+
11
+ - feat: Persist charCount to block data and add maxCharsOverflowPercent - refs #294806 [Alin Voinea - [`b5bbd75`](https://github.com/eea/volto-group-block/commit/b5bbd7516cb8cb6bcff8541d711fd9fa74a4d92c)]
12
+
7
13
  ### [8.1.1](https://github.com/eea/volto-group-block/compare/8.1.0...8.1.1) - 26 January 2026
8
14
 
9
15
  #### :hammer_and_wrench: Others
@@ -23,16 +29,9 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
23
29
 
24
30
  #### :house: Internal changes
25
31
 
26
- - chore: [JENKINS] fix sonarqube tags [valentinab25 - [`6dbeeb3`](https://github.com/eea/volto-group-block/commit/6dbeeb3b42ee1e69692dcb466bbff921a54ddabb)]
27
32
 
28
33
  #### :hammer_and_wrench: Others
29
34
 
30
- - Add Sonarqube tag using clms-frontend addons list [EEA Jenkins - [`8e153d3`](https://github.com/eea/volto-group-block/commit/8e153d34ef330adeb5b1ef7d96b2ff433ecec5ff)]
31
- - Add Sonarqube tag using clms-frontend addons list [EEA Jenkins - [`405738f`](https://github.com/eea/volto-group-block/commit/405738f8f13a236ad89f5f9870316322b1522518)]
32
- - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`84d6509`](https://github.com/eea/volto-group-block/commit/84d6509edf1b0821bd8709cf603f1025f99d18ff)]
33
- - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`ffb8602`](https://github.com/eea/volto-group-block/commit/ffb860257444d9ca05412111081a1320def9ee78)]
34
- - Add Sonarqube tag using clms-frontend addons list [EEA Jenkins - [`4bd723a`](https://github.com/eea/volto-group-block/commit/4bd723a108b4c9d6e78cc7c1ceec58573c57abf2)]
35
- - Add Sonarqube tag using ied-frontend addons list [EEA Jenkins - [`4f803d3`](https://github.com/eea/volto-group-block/commit/4f803d38efffcdc87f0dc0173b4142d9398bd2db)]
36
35
  ### [7.1.1](https://github.com/eea/volto-group-block/compare/7.1.0...7.1.1) - 30 January 2025
37
36
 
38
37
  #### :house: Internal changes
@@ -60,9 +59,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
60
59
 
61
60
  #### :hammer_and_wrench: Others
62
61
 
63
- - Add Sonarqube tag using insitu-frontend addons list [EEA Jenkins - [`e727ac6`](https://github.com/eea/volto-group-block/commit/e727ac6a8c1882b4e77a08fd0c5bb0a401cd3bdb)]
64
- - Add Sonarqube tag using clms-frontend addons list [EEA Jenkins - [`75c2946`](https://github.com/eea/volto-group-block/commit/75c29460dc6c42bbb799c13a5a6ef2bb8f26ed5a)]
65
- - Add Sonarqube tag using insitu-frontend addons list [EEA Jenkins - [`96f3133`](https://github.com/eea/volto-group-block/commit/96f31335cdda925daf3e5824f0a23121b0c9b3ef)]
66
62
  ### [6.4.0](https://github.com/eea/volto-group-block/compare/6.3.5...6.4.0) - 17 January 2024
67
63
 
68
64
  #### :rocket: New Features
@@ -77,7 +73,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
77
73
 
78
74
  #### :house: Internal changes
79
75
 
80
- - chore: [JENKINS] Refactor automated testing [valentinab25 - [`616f6eb`](https://github.com/eea/volto-group-block/commit/616f6ebe0385d82a827c6679eabdcf4e92a18c11)]
81
76
 
82
77
  #### :hammer_and_wrench: Others
83
78
 
@@ -90,11 +85,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
90
85
  - Prettier [kreafox - [`0c5d2d1`](https://github.com/eea/volto-group-block/commit/0c5d2d1a494489663cc97c5dc0f4ad13c4b67c8d)]
91
86
  - test: mock useLocation [kreafox - [`746887f`](https://github.com/eea/volto-group-block/commit/746887fa0e778f2d4cbe86661fc8c38c8a4bafb5)]
92
87
  - test: mock useLocation [kreafox - [`a360401`](https://github.com/eea/volto-group-block/commit/a360401b8ee05e9cb54b253b0e605d0a040c8f78)]
93
- - test: [JENKINS] Use java17 for sonarqube scanner [valentinab25 - [`25030fb`](https://github.com/eea/volto-group-block/commit/25030fbd69108f90df02130e5010e56398941ad2)]
94
- - test: [JENKINS] Run cypress in started frontend container [valentinab25 - [`1517dbb`](https://github.com/eea/volto-group-block/commit/1517dbb81cf9128752d835ae59dc22b251f4b035)]
95
- - test: [JENKINS] Add cpu limit on cypress docker [valentinab25 - [`b0ba5f9`](https://github.com/eea/volto-group-block/commit/b0ba5f9c6d37526411a7a984595ac624401f8ac5)]
96
- - test: [JENKINS] Increase shm-size to cypress docker [valentinab25 - [`8dbdfeb`](https://github.com/eea/volto-group-block/commit/8dbdfeb89fe53c6dc2f476b183a53c9266ab2bdf)]
97
- - test: [JENKINS] Improve cypress time [valentinab25 - [`d0324f4`](https://github.com/eea/volto-group-block/commit/d0324f4aad6d94233ca8ce3645ca5162f39d9834)]
98
88
  ### [6.3.4](https://github.com/eea/volto-group-block/compare/6.3.3...6.3.4) - 22 October 2023
99
89
 
100
90
  ### [6.3.3](https://github.com/eea/volto-group-block/compare/6.3.2...6.3.3) - 17 October 2023
@@ -142,7 +132,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
142
132
 
143
133
  - Release #39 from eea/develop [ichim-david - [`283e1e8`](https://github.com/eea/volto-group-block/commit/283e1e8dd1047415bae054cfd502d1691deaeb59)]
144
134
  - Release 6.3.0 [Alin Voinea - [`3d74bb5`](https://github.com/eea/volto-group-block/commit/3d74bb5342e3882e0ddee1aa8edab7e90949def6)]
145
- - test: Fix eslint and yarn i18n [Alin Voinea - [`763f764`](https://github.com/eea/volto-group-block/commit/763f76448625e05b53a2bde86ca48dda0cb263cb)]
146
135
  - i18n: Add en [Alin Voinea - [`f3385cd`](https://github.com/eea/volto-group-block/commit/f3385cd33bfbe3efe514fd82fd140d17e33051e1)]
147
136
  - test: Update Makefile and docker-compose to align it with Jenkinsfile [valentinab25 - [`3aa996b`](https://github.com/eea/volto-group-block/commit/3aa996b4c115da6f37ca771f07f10d58fbfa33e8)]
148
137
  - fix eslint warnings [nileshgulia1 - [`cfdf2e9`](https://github.com/eea/volto-group-block/commit/cfdf2e900bcc456fa5a24ce7b03859170ad024ba)]
@@ -173,7 +162,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
173
162
 
174
163
  #### :house: Internal changes
175
164
 
176
- - chore: [JENKINS] Deprecate circularity website [valentinab25 - [`ad30e83`](https://github.com/eea/volto-group-block/commit/ad30e832bb869b67dc4e64ed99590b51cb80ab75)]
177
165
 
178
166
  #### :hammer_and_wrench: Others
179
167
 
@@ -190,19 +178,12 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
190
178
 
191
179
  #### :hammer_and_wrench: Others
192
180
 
193
- - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`37ffae5`](https://github.com/eea/volto-group-block/commit/37ffae512967b36af22cbed208a3ec9e1ddc392b)]
194
181
  ## [6.0.0](https://github.com/eea/volto-group-block/compare/5.0.1...6.0.0) - 24 March 2023
195
182
 
196
183
  #### :hammer_and_wrench: Others
197
184
 
198
185
  - (feat): Possibility to copy/cut/paste blocks within section group block - refs #157469 [dobri1408 - [`e9fc098`](https://github.com/eea/volto-group-block/commit/e9fc09825ba2ae258feb77864491d97d94c585b4)]
199
- - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`db4b09a`](https://github.com/eea/volto-group-block/commit/db4b09a6c14a8b271dec0c766886ffbcc3fe205e)]
200
- - Add Sonarqube tag using advisory-board-frontend addons list [EEA Jenkins - [`b8c2bf4`](https://github.com/eea/volto-group-block/commit/b8c2bf471868bb0394b2dbbf75ccb7917a9ef0bf)]
201
- - Add Sonarqube tag using advisory-board-frontend addons list [EEA Jenkins - [`b343119`](https://github.com/eea/volto-group-block/commit/b3431196931fd568476fa8bf6fbc508e086229ae)]
202
186
  - test(Jenkins): Run tests and cypress with latest canary @plone/volto [Alin Voinea - [`2f42e7c`](https://github.com/eea/volto-group-block/commit/2f42e7c19a1da5a9c6a883cb4f101e8fa224ff94)]
203
- - Add Sonarqube tag using cca-frontend addons list [EEA Jenkins - [`73afcc2`](https://github.com/eea/volto-group-block/commit/73afcc2f417797cedaa78cceefb007001d6c2406)]
204
- - yarn 3 [Alin Voinea - [`3c00ccc`](https://github.com/eea/volto-group-block/commit/3c00ccc7110bbf12a4d268182313418fb46b1a5d)]
205
- - Add Sonarqube tag using demo-kitkat-frontend addons list [EEA Jenkins - [`9b9662b`](https://github.com/eea/volto-group-block/commit/9b9662bda1da70ba0c3a7b4b05cebf130ed89e9e)]
206
187
  ### [5.0.1](https://github.com/eea/volto-group-block/compare/5.0.0...5.0.1) - 16 November 2022
207
188
 
208
189
  #### :nail_care: Enhancements
@@ -219,8 +200,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
219
200
 
220
201
  - Prepare 5.0.0 release [Miu Razvan - [`88c0ddd`](https://github.com/eea/volto-group-block/commit/88c0ddd569aeda7ee34d1eadea6a087f4e7dc257)]
221
202
  - Update dependencies [Alin Voinea - [`c8405af`](https://github.com/eea/volto-group-block/commit/c8405afb830cdf62e7877bf30b619933519e1d71)]
222
- - Add Sonarqube tag using marine-frontend addons list [EEA Jenkins - [`18e26c6`](https://github.com/eea/volto-group-block/commit/18e26c6939706d572ab8574e9b1826b9abc76314)]
223
- - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`8ed6d21`](https://github.com/eea/volto-group-block/commit/8ed6d21d8489911cc4cb471e3f8823c35f4adc50)]
224
203
  ### [4.3.8](https://github.com/eea/volto-group-block/compare/4.3.7...4.3.8) - 26 August 2022
225
204
 
226
205
  ### [4.3.7](https://github.com/eea/volto-group-block/compare/4.3.6...4.3.7) - 22 August 2022
@@ -233,9 +212,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
233
212
 
234
213
  #### :hammer_and_wrench: Others
235
214
 
236
- - Add Sonarqube tag using circularity-frontend addons list [EEA Jenkins - [`4e73f8b`](https://github.com/eea/volto-group-block/commit/4e73f8be3c73559557efadc410cb56abc055d82d)]
237
- - Add Sonarqube tag using clms-frontend addons list [EEA Jenkins - [`3040335`](https://github.com/eea/volto-group-block/commit/3040335002c63b50208c95918413bc958150e7a9)]
238
- - Add Sonarqube tag using eea-website-frontend addons list [EEA Jenkins - [`386f730`](https://github.com/eea/volto-group-block/commit/386f730ed65f73fe1468b9b77351c97fb70edcc5)]
239
215
  ### [4.3.5](https://github.com/eea/volto-group-block/compare/4.3.4...4.3.5) - 4 January 2022
240
216
 
241
217
  ### [4.3.4](https://github.com/eea/volto-group-block/compare/4.3.3...4.3.4) - 3 January 2022
@@ -244,23 +220,15 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
244
220
 
245
221
  #### :hammer_and_wrench: Others
246
222
 
247
- - Add Sonarqube tag using freshwater-frontend addons list [EEA Jenkins - [`3e62d79`](https://github.com/eea/volto-group-block/commit/3e62d79a7ed37d10d623bc845d43e1144f8080f7)]
248
223
  ### [4.3.2](https://github.com/eea/volto-group-block/compare/4.3.1...4.3.2) - 10 December 2021
249
224
 
250
225
  #### :hammer_and_wrench: Others
251
226
 
252
227
  - Refs #142010 - Optimize Volto-addons gitflow pipelines [valentinab25 - [`bc36cf5`](https://github.com/eea/volto-group-block/commit/bc36cf58c39e2b43c2fbf5189df6ddefc1260857)]
253
- - Add Sonarqube tag using industry-frontend addons list [EEA Jenkins - [`8038e78`](https://github.com/eea/volto-group-block/commit/8038e783c1e8ddd71e21f72070fdfa8e7e098993)]
254
- - Add Sonarqube tag using clms-frontend addons list [EEA Jenkins - [`daccdbc`](https://github.com/eea/volto-group-block/commit/daccdbc733e47be7d6536eb67f8f2eea038dc94b)]
255
228
  ### [4.3.1](https://github.com/eea/volto-group-block/compare/4.3.0...4.3.1) - 11 October 2021
256
229
 
257
230
  #### :hammer_and_wrench: Others
258
231
 
259
- - Add Sonarqube tag using bise-frontend addons list [EEA Jenkins - [`b0092e4`](https://github.com/eea/volto-group-block/commit/b0092e4f78a1a0184e22e32bb9806cd57417dfb2)]
260
- - Add Sonarqube tag using sustainability-frontend addons list [EEA Jenkins - [`ff8889c`](https://github.com/eea/volto-group-block/commit/ff8889cb7b0761b1df43b201984ce40b14e1561b)]
261
- - Add Sonarqube tag using climate-energy-frontend addons list [EEA Jenkins - [`0375c28`](https://github.com/eea/volto-group-block/commit/0375c28ed1ffe9186a4790b454795c0ca8039f72)]
262
- - Add Sonarqube tag using ims-frontend addons list [EEA Jenkins - [`c392190`](https://github.com/eea/volto-group-block/commit/c392190f044f5d9397bd2fb8c3d6a357f84960d0)]
263
- - Add Sonarqube tag using frontend addons list [EEA Jenkins - [`9694501`](https://github.com/eea/volto-group-block/commit/9694501141e6780eba89464d36406e3c93629fd8)]
264
232
  ### [4.3.0](https://github.com/eea/volto-group-block/compare/4.2.3...4.3.0) - 24 June 2021
265
233
 
266
234
  #### :hammer_and_wrench: Others
@@ -376,7 +344,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
376
344
  - Release 1.0.0 [Alin Voinea - [`b6ef873`](https://github.com/eea/volto-group-block/commit/b6ef873cb6f61e17db66fdd4de1d9d4902a66fc6)]
377
345
  - Update package meta info [Alin Voinea - [`143b7d4`](https://github.com/eea/volto-group-block/commit/143b7d44438d7afa5e346a9d21a85352df4e925f)]
378
346
  - Add Jenkinkins pipeline [Alin Voinea - [`866a4e1`](https://github.com/eea/volto-group-block/commit/866a4e14ea1eb8f5adb01222e576e5ab6dc73a70)]
379
- - yarn prettier [Alin Voinea - [`e3fe0a3`](https://github.com/eea/volto-group-block/commit/e3fe0a36b89878769341b45198d6c9e2f2584d15)]
380
347
  ### [0.1.3](https://github.com/eea/volto-group-block/compare/0.1.2...0.1.3) - 9 November 2020
381
348
 
382
349
  #### :hammer_and_wrench: Others
@@ -416,5 +383,4 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
416
383
  - Render meta block [Alin Voinea - [`0d44560`](https://github.com/eea/volto-group-block/commit/0d4456011ca56454068a54c610250b02df4ccb3b)]
417
384
  - Implement meta block allowedBlocks settings [Alin Voinea - [`f24feb1`](https://github.com/eea/volto-group-block/commit/f24feb1a1751f04841c21c7cd52a517fb02074ba)]
418
385
  - Edit meta block [Alin Voinea - [`236d291`](https://github.com/eea/volto-group-block/commit/236d29156fa835a7aa54eecdb4f120de0d64b271)]
419
- - yarn bootstrap [Alin Voinea - [`e009dfb`](https://github.com/eea/volto-group-block/commit/e009dfb6b9b74d101a6722f0982a5359fc522b6b)]
420
386
  - Initial commit [Alin Voinea - [`6a7b0de`](https://github.com/eea/volto-group-block/commit/6a7b0deb8f873d1462fd6a9c61edfc1562b3aace)]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eeacms/volto-group-block",
3
- "version": "8.1.1",
3
+ "version": "9.0.0",
4
4
  "description": "volto-group-block: Volto block to be used to group other blocks",
5
5
  "main": "src/index.js",
6
6
  "author": "European Environment Agency: IDM2 A-Team",
@@ -56,7 +56,7 @@ const countTextInEachBlock =
56
56
  : countCharsWithSpaces(foundText);
57
57
  };
58
58
 
59
- const countTextInBlocks = (blocksObject, ignoreSpaces, maxChars) => {
59
+ export const countTextInBlocks = (blocksObject, ignoreSpaces, maxChars) => {
60
60
  const { countTextIn, skipBlocksInGroups = [] } =
61
61
  config.blocks?.blocksConfig?.group || {};
62
62
  // use obj ref to update value - if you send number it will not be updated
@@ -82,12 +82,21 @@ const countTextInBlocks = (blocksObject, ignoreSpaces, maxChars) => {
82
82
  };
83
83
 
84
84
  const CounterComponent = ({ data, setSidebarTab, setSelectedBlock }) => {
85
- const { maxChars, ignoreSpaces } = data;
86
- const charCount = countTextInBlocks(data?.data, ignoreSpaces, maxChars);
85
+ const maxChars = parseInt(data.maxChars) || 0;
86
+ const maxCharsOverflowPercent = parseInt(data.maxCharsOverflowPercent) || 0;
87
+ const { ignoreSpaces } = data;
88
+ const charCount =
89
+ data.charCount ?? countTextInBlocks(data?.data, ignoreSpaces, maxChars);
90
+
91
+ const overflowLimit =
92
+ maxCharsOverflowPercent > 0
93
+ ? Math.ceil((maxChars * (100 + maxCharsOverflowPercent)) / 100)
94
+ : maxChars;
95
+
87
96
  const counterClass =
88
97
  charCount < Math.ceil(maxChars / 1.05)
89
98
  ? 'info'
90
- : charCount < maxChars
99
+ : charCount <= overflowLimit
91
100
  ? 'warning'
92
101
  : 'danger';
93
102
 
@@ -231,4 +231,119 @@ describe('CounterComponent', () => {
231
231
  expect(setSidebarTab).toHaveBeenCalledWith(1);
232
232
  expect(setSelectedBlock).toHaveBeenCalled();
233
233
  });
234
+
235
+ it('should render warning class when chars are within overflow zone (maxCharsOverflowPercent=10)', () => {
236
+ const { container, getByText } = render(
237
+ <CounterComponent
238
+ data={{
239
+ maxChars: 100,
240
+ maxCharsOverflowPercent: 10,
241
+ data: {
242
+ blocks: {
243
+ block1: { '@type': 'text', plaintext: 'a'.repeat(105) },
244
+ },
245
+ blocks_layout: {
246
+ items: ['block1'],
247
+ },
248
+ },
249
+ }}
250
+ setSidebarTab={setSidebarTab}
251
+ setSelectedBlock={setSelectedBlock}
252
+ />,
253
+ );
254
+ expect(getByText('5 characters over the limit')).toBeInTheDocument();
255
+ expect(container.querySelector('.counter.warning')).toBeInTheDocument();
256
+ });
257
+
258
+ it('should render danger class when chars exceed overflow zone (maxCharsOverflowPercent=10)', () => {
259
+ const { container, getByText } = render(
260
+ <CounterComponent
261
+ data={{
262
+ maxChars: 100,
263
+ maxCharsOverflowPercent: 10,
264
+ data: {
265
+ blocks: {
266
+ block1: { '@type': 'text', plaintext: 'a'.repeat(111) },
267
+ },
268
+ blocks_layout: {
269
+ items: ['block1'],
270
+ },
271
+ },
272
+ }}
273
+ setSidebarTab={setSidebarTab}
274
+ setSelectedBlock={setSelectedBlock}
275
+ />,
276
+ );
277
+ expect(getByText('11 characters over the limit')).toBeInTheDocument();
278
+ expect(container.querySelector('.counter.danger')).toBeInTheDocument();
279
+ });
280
+
281
+ it('should render warning class when chars equal maxChars with no overflow percent', () => {
282
+ const { container, getByText } = render(
283
+ <CounterComponent
284
+ data={{
285
+ maxChars: 100,
286
+ data: {
287
+ blocks: {
288
+ block1: { '@type': 'text', plaintext: 'a'.repeat(100) },
289
+ },
290
+ blocks_layout: {
291
+ items: ['block1'],
292
+ },
293
+ },
294
+ }}
295
+ setSidebarTab={setSidebarTab}
296
+ setSelectedBlock={setSelectedBlock}
297
+ />,
298
+ );
299
+ expect(getByText('0 characters remaining out of 100')).toBeInTheDocument();
300
+ expect(container.querySelector('.counter.warning')).toBeInTheDocument();
301
+ });
302
+
303
+ it('should render danger class when negative overflow percent falls back to maxChars', () => {
304
+ const { container, getByText } = render(
305
+ <CounterComponent
306
+ data={{
307
+ maxChars: 100,
308
+ maxCharsOverflowPercent: -5,
309
+ data: {
310
+ blocks: {
311
+ block1: { '@type': 'text', plaintext: 'a'.repeat(104) },
312
+ },
313
+ blocks_layout: {
314
+ items: ['block1'],
315
+ },
316
+ },
317
+ }}
318
+ setSidebarTab={setSidebarTab}
319
+ setSelectedBlock={setSelectedBlock}
320
+ />,
321
+ );
322
+ expect(getByText('4 characters over the limit')).toBeInTheDocument();
323
+ expect(container.querySelector('.counter.danger')).toBeInTheDocument();
324
+ });
325
+
326
+ it('should use persisted charCount from data instead of recomputing', () => {
327
+ const { container, getByText } = render(
328
+ <CounterComponent
329
+ data={{
330
+ maxChars: 100,
331
+ charCount: 42,
332
+ data: {
333
+ blocks: {
334
+ block1: { '@type': 'text', plaintext: 'a'.repeat(90) },
335
+ },
336
+ blocks_layout: {
337
+ items: ['block1'],
338
+ },
339
+ },
340
+ }}
341
+ setSidebarTab={setSidebarTab}
342
+ setSelectedBlock={setSelectedBlock}
343
+ />,
344
+ );
345
+ // Should use charCount=42 from data, not 90 from blocks
346
+ expect(getByText('58 characters remaining out of 100')).toBeInTheDocument();
347
+ expect(container.querySelector('.counter.info')).toBeInTheDocument();
348
+ });
234
349
  });
@@ -1,6 +1,7 @@
1
1
  import { Button } from 'semantic-ui-react';
2
2
  import { BlocksForm, Icon, RenderBlocks } from '@plone/volto/components';
3
3
  import EditBlockWrapper from './EditBlockWrapper';
4
+ import { countTextInBlocks } from './CounterComponent';
4
5
  import { useLocation } from 'react-router-dom';
5
6
 
6
7
  import helpSVG from '@plone/volto/icons/help.svg';
@@ -48,21 +49,38 @@ const GroupBlockDefaultBody = (props) => {
48
49
  onSelectBlock(id, isMultipleSelection, e, selectedBlock);
49
50
  }}
50
51
  onChangeFormData={(newFormData) => {
51
- onChangeBlock(block, {
52
+ const newData = {
52
53
  ...data,
53
54
  data: newFormData,
54
- });
55
+ };
56
+ if (data.maxChars) {
57
+ newData.charCount = countTextInBlocks(
58
+ newFormData,
59
+ data.ignoreSpaces,
60
+ data.maxChars,
61
+ );
62
+ }
63
+ onChangeBlock(block, newData);
55
64
  }}
56
65
  onChangeField={(id, value) => {
57
66
  if (['blocks', 'blocks_layout'].indexOf(id) > -1) {
58
67
  blockState[id] = value;
59
- onChangeBlock(block, {
68
+ const newChildData = {
69
+ ...data.data,
70
+ ...blockState,
71
+ };
72
+ const newData = {
60
73
  ...data,
61
- data: {
62
- ...data.data,
63
- ...blockState,
64
- },
65
- });
74
+ data: newChildData,
75
+ };
76
+ if (data.maxChars) {
77
+ newData.charCount = countTextInBlocks(
78
+ newChildData,
79
+ data.ignoreSpaces,
80
+ data.maxChars,
81
+ );
82
+ }
83
+ onChangeBlock(block, newData);
66
84
  } else {
67
85
  onChangeField(id, value);
68
86
  }
@@ -18,7 +18,7 @@ import PropTypes from 'prop-types';
18
18
  import { Segment } from 'semantic-ui-react';
19
19
  import EditSchema from './EditSchema';
20
20
 
21
- import CounterComponent from './CounterComponent';
21
+ import CounterComponent, { countTextInBlocks } from './CounterComponent';
22
22
  import './editor.less';
23
23
  import { defineMessages, injectIntl } from 'react-intl';
24
24
  import { compose } from 'redux';
@@ -115,20 +115,29 @@ const Edit = (props) => {
115
115
  });
116
116
  const selectedIndex =
117
117
  data.data.blocks_layout.items.indexOf(selectedBlock) + 1;
118
- onChangeBlock(block, {
119
- ...data,
120
- data: {
121
- ...data?.data,
122
- ...newBlockData,
123
- blocks_layout: {
124
- items: [
125
- ...data.data.blocks_layout.items.slice(0, selectedIndex),
126
- ...pastedBlocks,
127
- ...data.data.blocks_layout.items.slice(selectedIndex),
128
- ],
129
- },
118
+ const newChildData = {
119
+ ...data?.data,
120
+ ...newBlockData,
121
+ blocks_layout: {
122
+ items: [
123
+ ...data.data.blocks_layout.items.slice(0, selectedIndex),
124
+ ...pastedBlocks,
125
+ ...data.data.blocks_layout.items.slice(selectedIndex),
126
+ ],
130
127
  },
131
- });
128
+ };
129
+ const newData = {
130
+ ...data,
131
+ data: newChildData,
132
+ };
133
+ if (data.maxChars) {
134
+ newData.charCount = countTextInBlocks(
135
+ newChildData,
136
+ data.ignoreSpaces,
137
+ data.maxChars,
138
+ );
139
+ }
140
+ onChangeBlock(block, newData);
132
141
  };
133
142
 
134
143
  React.useEffect(() => {
@@ -137,10 +146,14 @@ const Edit = (props) => {
137
146
  childBlocksForm.blocks_layout.items[0] !== selectedBlock
138
147
  ) {
139
148
  setSelectedBlock(childBlocksForm.blocks_layout.items[0]);
140
- onChangeBlock(block, {
149
+ const newData = {
141
150
  ...data,
142
151
  data: childBlocksForm,
143
- });
152
+ };
153
+ if (data.maxChars) {
154
+ newData.charCount = 0;
155
+ }
156
+ onChangeBlock(block, newData);
144
157
  }
145
158
  }, [onChangeBlock, childBlocksForm, selectedBlock, block, data, data_blocks]);
146
159
 
@@ -218,10 +231,24 @@ const Edit = (props) => {
218
231
  title={props.intl.formatMessage(messages.sectionGroupSettings)}
219
232
  formData={data}
220
233
  onChangeField={(id, value) => {
221
- props.onChangeBlock(props.block, {
234
+ const newData = {
222
235
  ...props.data,
223
236
  [id]: value,
224
- });
237
+ };
238
+ const effectiveMaxChars =
239
+ id === 'maxChars' ? value : props.data.maxChars;
240
+ const effectiveIgnoreSpaces =
241
+ id === 'ignoreSpaces' ? value : props.data.ignoreSpaces;
242
+ if (effectiveMaxChars) {
243
+ newData.charCount = countTextInBlocks(
244
+ props.data?.data,
245
+ effectiveIgnoreSpaces,
246
+ effectiveMaxChars,
247
+ );
248
+ } else {
249
+ delete newData.charCount;
250
+ }
251
+ props.onChangeBlock(props.block, newData);
225
252
  }}
226
253
  />
227
254
  )}
@@ -11,6 +11,7 @@ const Schema = {
11
11
  'allowedBlocks',
12
12
  'as',
13
13
  'maxChars',
14
+ 'maxCharsOverflowPercent',
14
15
  'ignoreSpaces',
15
16
  'readOnlySettings',
16
17
  'disableInnerButtons',
@@ -68,6 +69,13 @@ const Schema = {
68
69
  type: 'integer',
69
70
  factory: 'Integer',
70
71
  },
72
+ maxCharsOverflowPercent: {
73
+ title: 'Maximum Characters Overflow Percent',
74
+ description:
75
+ 'The percentage of characters that can overflow the maximum characters limit before showing a warning: 0-100',
76
+ type: 'integer',
77
+ factory: 'Integer',
78
+ },
71
79
  ignoreSpaces: {
72
80
  title: 'Ignore spaces',
73
81
  description: 'Ignore spaces while calculating maximum characters',