@eeacms/volto-group-block 10.0.2 → 10.0.3

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,15 @@ 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
+ ### [10.0.3](https://github.com/eea/volto-group-block/compare/10.0.2...10.0.3) - 21 April 2026
8
+
9
+ #### :bug: Bug Fixes
10
+
11
+ - fix(sections): deep‑clone blocks on copy/paste, ref #302532 [Miu Razvan - [`66b0820`](https://github.com/eea/volto-group-block/commit/66b0820a68cf2650dd9d8fd500b4608aaf898a62)]
12
+
13
+ #### :hammer_and_wrench: Others
14
+
15
+ - add tests for utils [Miu Razvan - [`6c01680`](https://github.com/eea/volto-group-block/commit/6c01680aa43157926062a5b18721500d0abb5d13)]
7
16
  ### [10.0.2](https://github.com/eea/volto-group-block/compare/10.0.1...10.0.2) - 15 April 2026
8
17
 
9
18
  ### [10.0.1](https://github.com/eea/volto-group-block/compare/10.0.0...10.0.1) - 9 April 2026
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eeacms/volto-group-block",
3
- "version": "10.0.2",
3
+ "version": "10.0.3",
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",
package/src/index.js CHANGED
@@ -8,6 +8,8 @@ import {
8
8
  import codeSVG from '@plone/volto/icons/row.svg';
9
9
  import { defineMessages } from 'react-intl';
10
10
 
11
+ import { cloneData } from './utils';
12
+
11
13
  defineMessages({
12
14
  sectionGroup: {
13
15
  id: 'Section (Group)',
@@ -64,6 +66,7 @@ const applyConfig = (config) => {
64
66
  schema: schema,
65
67
  restricted: false,
66
68
  mostUsed: false,
69
+ cloneData,
67
70
  blockHasOwnFocusManagement: true,
68
71
  sidebarTab: 1,
69
72
  security: {
package/src/utils.js ADDED
@@ -0,0 +1,51 @@
1
+ import { v4 as uuid } from 'uuid';
2
+ import {
3
+ getBlocksFieldname,
4
+ getBlocksLayoutFieldname,
5
+ getBlocks,
6
+ hasBlocksData,
7
+ } from '@plone/volto/helpers/Blocks/Blocks';
8
+ import config from '@plone/volto/registry';
9
+
10
+ /* Inline deep‑clone helpers – used only by the Group block */
11
+ function deepCloneFormData(formData) {
12
+ const blocksField = getBlocksFieldname(formData);
13
+ const layoutField = getBlocksLayoutFieldname(formData);
14
+ const childBlocks = getBlocks(formData);
15
+
16
+ const cloned = childBlocks
17
+ .map(([_, child]) => {
18
+ const childCfg = config.blocks.blocksConfig[child['@type']] || {};
19
+ if (childCfg.cloneData) {
20
+ return childCfg.cloneData(child);
21
+ }
22
+ return hasBlocksData(child) ? deepCloneFormData(child) : [uuid(), child];
23
+ })
24
+ .filter(Boolean);
25
+
26
+ const newData = {
27
+ ...formData,
28
+ [blocksField]: {
29
+ ...Object.fromEntries(cloned.map(([newId, data]) => [newId, data])),
30
+ },
31
+ [layoutField]: {
32
+ items: cloned.map(([newId]) => newId),
33
+ },
34
+ };
35
+
36
+ // Return a fresh UUID for the *parent* block and its cloned content
37
+ return [uuid(), newData];
38
+ }
39
+
40
+ export function cloneData(blockData) {
41
+ const columnsData = blockData.data;
42
+ const cloneWithIds = deepCloneFormData(columnsData);
43
+ const [id, newBlockData] = cloneWithIds;
44
+ return [
45
+ id,
46
+ {
47
+ ...blockData,
48
+ data: newBlockData,
49
+ },
50
+ ];
51
+ }
@@ -0,0 +1,113 @@
1
+ import { v4 as uuid } from 'uuid';
2
+ import { getBlocks } from '@plone/volto/helpers/Blocks/Blocks';
3
+ import config from '@plone/volto/registry';
4
+ import { cloneData } from './utils';
5
+
6
+ jest.mock('@plone/volto/helpers/Blocks/Blocks', () => ({
7
+ getBlocks: jest.fn(),
8
+ getBlocksFieldname: jest.fn(() => 'blocks'),
9
+ getBlocksLayoutFieldname: jest.fn(() => 'blocks_layout'),
10
+ hasBlocksData: jest.fn((block) => !!block.blocks),
11
+ }));
12
+
13
+ describe('cloneData', () => {
14
+ it('should clone the blockData with calling cloneData directly', () => {
15
+ const blockId = uuid();
16
+ const mockBlockData = {
17
+ data: {
18
+ '@type': 'group',
19
+ blocks: {
20
+ [blockId]: {
21
+ '@type': 'test',
22
+ },
23
+ },
24
+ blocks_layout: {
25
+ items: [blockId],
26
+ },
27
+ },
28
+ };
29
+
30
+ getBlocks.mockReturnValue([[blockId, mockBlockData.data.blocks[blockId]]]);
31
+
32
+ const [id, clonedBlockData] = cloneData(mockBlockData);
33
+ const clonedBlockId = clonedBlockData.data.blocks_layout.items[0];
34
+ const clonedBlock = clonedBlockData.data.blocks[clonedBlockId];
35
+ expect(clonedBlock).toBeDefined();
36
+ expect(clonedBlockId).not.toEqual(blockId);
37
+ expect(clonedBlock).toEqual(mockBlockData.data.blocks[blockId]);
38
+ expect(id).not.toBeNull();
39
+ });
40
+
41
+ it('should clone the blockData with calling cloneData from block config', () => {
42
+ const blockId = uuid();
43
+ const mockBlockData = {
44
+ data: {
45
+ '@type': 'group',
46
+ blocks: {
47
+ [blockId]: {
48
+ '@type': 'test',
49
+ blocks: {},
50
+ },
51
+ },
52
+ blocks_layout: {
53
+ items: [blockId],
54
+ },
55
+ },
56
+ };
57
+
58
+ getBlocks.mockReturnValue([[blockId, mockBlockData.data.blocks[blockId]]]);
59
+
60
+ config.blocks.blocksConfig = {
61
+ test: {
62
+ cloneData: jest.fn(() => [
63
+ 'test_uuid',
64
+ mockBlockData.data.blocks[blockId],
65
+ ]),
66
+ },
67
+ };
68
+ const [id, clonedBlockData] = cloneData(mockBlockData);
69
+ expect(id).not.toEqual('test_uuid');
70
+ expect(clonedBlockData.data.blocks['test_uuid']).toEqual(
71
+ mockBlockData.data.blocks[blockId],
72
+ );
73
+ });
74
+
75
+ it('should recursively clone nested blocks', () => {
76
+ const outerBlockId = uuid();
77
+ const innerBlockId = uuid();
78
+ const innerBlock = {
79
+ '@type': 'inner',
80
+ blocks: {
81
+ [innerBlockId]: { '@type': 'leaf' },
82
+ },
83
+ blocks_layout: { items: [innerBlockId] },
84
+ };
85
+ const mockBlockData = {
86
+ data: {
87
+ '@type': 'group',
88
+ blocks: {
89
+ [outerBlockId]: innerBlock,
90
+ },
91
+ blocks_layout: {
92
+ items: [outerBlockId],
93
+ },
94
+ },
95
+ };
96
+
97
+ getBlocks
98
+ .mockReturnValueOnce([[outerBlockId, innerBlock]])
99
+ .mockReturnValueOnce([[innerBlockId, innerBlock.blocks[innerBlockId]]]);
100
+
101
+ const [id, clonedBlockData] = cloneData(mockBlockData);
102
+ const newOuterId = clonedBlockData.data.blocks_layout.items[0];
103
+ expect(newOuterId).not.toEqual(outerBlockId);
104
+ expect(id).not.toBeNull();
105
+ const newOuterBlock = clonedBlockData.data.blocks[newOuterId];
106
+ expect(newOuterBlock).toBeDefined();
107
+ const newInnerId = newOuterBlock.blocks_layout.items[0];
108
+ expect(newInnerId).not.toEqual(innerBlockId);
109
+ expect(newOuterBlock.blocks[newInnerId]).toEqual(
110
+ innerBlock.blocks[innerBlockId],
111
+ );
112
+ });
113
+ });