@payloadcms/ui 4.0.0-canary.35 → 4.0.0-canary.36

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.
Files changed (180) hide show
  1. package/dist/css/app.css +1 -0
  2. package/dist/css/preflight.css +1 -0
  3. package/dist/css/spacing.css +3 -0
  4. package/dist/elements/AppHeader/index.css +3 -0
  5. package/dist/elements/BulkUpload/ActionsBar/index.css +1 -0
  6. package/dist/elements/BulkUpload/AddingFilesView/index.css +2 -4
  7. package/dist/elements/BulkUpload/FileSidebar/index.css +1 -0
  8. package/dist/elements/BulkUpload/FormsManager/index.d.ts.map +1 -1
  9. package/dist/elements/BulkUpload/FormsManager/index.js +12 -7
  10. package/dist/elements/BulkUpload/FormsManager/index.js.map +1 -1
  11. package/dist/elements/BulkUpload/index.css +2 -0
  12. package/dist/elements/Collapsible/index.css +1 -0
  13. package/dist/elements/DatePicker/index.css +2 -0
  14. package/dist/elements/Dialog/index.css +1 -0
  15. package/dist/elements/DocumentControls/index.css +1 -0
  16. package/dist/elements/DocumentFields/index.css +2 -0
  17. package/dist/elements/DocumentHeader/Tabs/index.css +1 -0
  18. package/dist/elements/DocumentHeader/index.css +1 -0
  19. package/dist/elements/EditUpload/index.css +1 -1
  20. package/dist/elements/FieldDiffContainer/index.css +1 -0
  21. package/dist/elements/FieldDiffLabel/index.css +1 -0
  22. package/dist/elements/FileDetails/StaticFileDetails/index.css +2 -0
  23. package/dist/elements/HTMLDiff/index.css +1 -0
  24. package/dist/elements/ItemsDrawer/index.css +3 -0
  25. package/dist/elements/ListControls/index.css +1 -0
  26. package/dist/elements/ListControls/index.d.ts.map +1 -1
  27. package/dist/elements/ListControls/index.js +7 -1
  28. package/dist/elements/ListControls/index.js.map +1 -1
  29. package/dist/elements/ListControls/types.d.ts +3 -1
  30. package/dist/elements/ListControls/types.d.ts.map +1 -1
  31. package/dist/elements/ListControls/types.js.map +1 -1
  32. package/dist/elements/ListControlsBar/index.css +1 -0
  33. package/dist/elements/ListHeader/TitleActions/ListEmptyTrashButton.js +1 -1
  34. package/dist/elements/ListHeader/TitleActions/ListEmptyTrashButton.js.map +1 -1
  35. package/dist/elements/LivePreview/Window/index.css +1 -0
  36. package/dist/elements/Nav/index.css +2 -0
  37. package/dist/elements/PageControls/index.css +1 -0
  38. package/dist/elements/PillSelector/index.css +1 -0
  39. package/dist/elements/PreviewSizes/index.css +2 -0
  40. package/dist/elements/PublishButton/index.css +1 -0
  41. package/dist/elements/QueryPresets/fields/Heading/index.css +1 -0
  42. package/dist/elements/RenderTitle/index.css +1 -0
  43. package/dist/elements/Table/index.css +1 -0
  44. package/dist/elements/TableSection/index.css +1 -0
  45. package/dist/elements/Tabs/index.css +1 -0
  46. package/dist/elements/Thumbnail/index.css +1 -0
  47. package/dist/elements/TimezonePicker/index.css +1 -0
  48. package/dist/elements/Tooltip/index.css +7 -0
  49. package/dist/elements/WhereBuilder/Condition/index.css +1 -0
  50. package/dist/elements/WhereBuilder/index.css +2 -0
  51. package/dist/fields/Array/index.css +1 -0
  52. package/dist/fields/Blocks/index.css +1 -0
  53. package/dist/fields/Group/index.css +1 -0
  54. package/dist/fields/Row/index.css +2 -0
  55. package/dist/fields/Tabs/index.css +1 -0
  56. package/dist/forms/RenderFields/index.css +1 -0
  57. package/dist/hooks/useControllableState.js +3 -3
  58. package/dist/hooks/useControllableState.js.map +1 -1
  59. package/dist/providers/DocumentInfo/index.d.ts.map +1 -1
  60. package/dist/providers/DocumentInfo/index.js +30 -19
  61. package/dist/providers/DocumentInfo/index.js.map +1 -1
  62. package/dist/providers/Locale/index.d.ts.map +1 -1
  63. package/dist/providers/Locale/index.js +6 -7
  64. package/dist/providers/Locale/index.js.map +1 -1
  65. package/dist/styles.css +5 -1
  66. package/dist/templates/Default/Wrapper/index.css +2 -0
  67. package/dist/templates/Default/index.css +1 -0
  68. package/dist/utilities/handleAuthRedirect.d.ts.map +1 -1
  69. package/dist/utilities/handleAuthRedirect.js +4 -1
  70. package/dist/utilities/handleAuthRedirect.js.map +1 -1
  71. package/dist/utilities/isPathMatchingRoute.d.ts.map +1 -1
  72. package/dist/utilities/isPathMatchingRoute.js +7 -5
  73. package/dist/utilities/isPathMatchingRoute.js.map +1 -1
  74. package/dist/views/API/index.css +1 -0
  75. package/dist/views/Dashboard/Default/ModularDashboard/index.css +2 -0
  76. package/dist/views/Edit/index.css +1 -0
  77. package/dist/views/HierarchyList/HierarchyTable/SlotTable.css +1 -0
  78. package/dist/views/HierarchyList/index.css +1 -0
  79. package/dist/views/List/ListHeader/index.css +1 -0
  80. package/dist/views/List/ListHeader/index.d.ts +0 -1
  81. package/dist/views/List/ListHeader/index.d.ts.map +1 -1
  82. package/dist/views/List/ListHeader/index.js +2 -6
  83. package/dist/views/List/ListHeader/index.js.map +1 -1
  84. package/dist/views/List/index.client.d.ts.map +1 -1
  85. package/dist/views/List/index.client.js +3 -2
  86. package/dist/views/List/index.client.js.map +1 -1
  87. package/dist/views/List/index.css +2 -0
  88. package/dist/views/Root/index.d.ts.map +1 -1
  89. package/dist/views/Root/index.js +26 -19
  90. package/dist/views/Root/index.js.map +1 -1
  91. package/dist/views/Version/Default/index.css +2 -0
  92. package/dist/views/Version/RenderFieldsToDiff/fields/Date/index.css +8 -0
  93. package/dist/views/Version/RenderFieldsToDiff/fields/Relationship/index.css +1 -0
  94. package/dist/views/Version/RenderFieldsToDiff/fields/Upload/index.css +1 -0
  95. package/dist/views/Version/RenderFieldsToDiff/index.css +2 -0
  96. package/dist/views/Version/Restore/index.d.ts.map +1 -1
  97. package/dist/views/Version/Restore/index.js +9 -6
  98. package/dist/views/Version/Restore/index.js.map +1 -1
  99. package/dist/views/Versions/VersionPillLabel/index.css +1 -0
  100. package/dist/views/Versions/index.css +1 -0
  101. package/dist/widgets/CollectionCards/index.css +4 -0
  102. package/package.json +5 -5
  103. package/dist/elements/ClipboardAction/clipboardUtilities.spec.js +0 -120
  104. package/dist/elements/ClipboardAction/clipboardUtilities.spec.js.map +0 -1
  105. package/dist/elements/ClipboardAction/isClipboardDataValid.spec.js +0 -144
  106. package/dist/elements/ClipboardAction/isClipboardDataValid.spec.js.map +0 -1
  107. package/dist/elements/ClipboardAction/mergeFormStateFromClipboard.spec.js +0 -885
  108. package/dist/elements/ClipboardAction/mergeFormStateFromClipboard.spec.js.map +0 -1
  109. package/dist/elements/ColumnSelection/matchesColumnSearch.spec.js +0 -87
  110. package/dist/elements/ColumnSelection/matchesColumnSearch.spec.js.map +0 -1
  111. package/dist/elements/CommandPalette/buildActions.spec.js +0 -158
  112. package/dist/elements/CommandPalette/buildActions.spec.js.map +0 -1
  113. package/dist/elements/CommandPalette/highlightLabel.spec.js +0 -78
  114. package/dist/elements/CommandPalette/highlightLabel.spec.js.map +0 -1
  115. package/dist/elements/FieldSelect/reduceFieldOptions.spec.js +0 -143
  116. package/dist/elements/FieldSelect/reduceFieldOptions.spec.js.map +0 -1
  117. package/dist/elements/Toasts/fieldErrors.spec.js +0 -46
  118. package/dist/elements/Toasts/fieldErrors.spec.js.map +0 -1
  119. package/dist/elements/WhereBuilder/Condition/Relationship/optionsReducer.spec.js +0 -152
  120. package/dist/elements/WhereBuilder/Condition/Relationship/optionsReducer.spec.js.map +0 -1
  121. package/dist/elements/WhereBuilder/conditionValue.spec.js +0 -65
  122. package/dist/elements/WhereBuilder/conditionValue.spec.js.map +0 -1
  123. package/dist/fields/Upload/Input.spec.js +0 -242
  124. package/dist/fields/Upload/Input.spec.js.map +0 -1
  125. package/dist/forms/fieldSchemasToFormState/fieldSchemasToFormState.spec.d.ts +0 -2
  126. package/dist/forms/fieldSchemasToFormState/fieldSchemasToFormState.spec.d.ts.map +0 -1
  127. package/dist/forms/fieldSchemasToFormState/fieldSchemasToFormState.spec.js +0 -67
  128. package/dist/forms/fieldSchemasToFormState/fieldSchemasToFormState.spec.js.map +0 -1
  129. package/dist/forms/fieldSchemasToFormState/serverFunctions/renderFieldServerFn.spec.js +0 -150
  130. package/dist/forms/fieldSchemasToFormState/serverFunctions/renderFieldServerFn.spec.js.map +0 -1
  131. package/dist/layouts/Root/index.spec.js +0 -20
  132. package/dist/layouts/Root/index.spec.js.map +0 -1
  133. package/dist/providers/Auth/authSessionRequests.spec.js +0 -121
  134. package/dist/providers/Auth/authSessionRequests.spec.js.map +0 -1
  135. package/dist/providers/Auth/sessionActivity.spec.js +0 -44
  136. package/dist/providers/Auth/sessionActivity.spec.js.map +0 -1
  137. package/dist/providers/Auth/tabSessionSync/index.spec.js +0 -463
  138. package/dist/providers/Auth/tabSessionSync/index.spec.js.map +0 -1
  139. package/dist/providers/Auth/useAuthSessionTimers.spec.js +0 -311
  140. package/dist/providers/Auth/useAuthSessionTimers.spec.js.map +0 -1
  141. package/dist/providers/RouteTransition/ProgressBar/index.spec.js +0 -44
  142. package/dist/providers/RouteTransition/ProgressBar/index.spec.js.map +0 -1
  143. package/dist/providers/TableColumns/buildColumnState/index.spec.js +0 -40
  144. package/dist/providers/TableColumns/buildColumnState/index.spec.js.map +0 -1
  145. package/dist/utilities/appendCacheTag.spec.js +0 -34
  146. package/dist/utilities/appendCacheTag.spec.js.map +0 -1
  147. package/dist/utilities/formatAbsoluteURL.spec.js +0 -27
  148. package/dist/utilities/formatAbsoluteURL.spec.js.map +0 -1
  149. package/dist/utilities/formatMetadata.spec.js +0 -83
  150. package/dist/utilities/formatMetadata.spec.js.map +0 -1
  151. package/dist/utilities/fuzzyMatch.spec.js +0 -38
  152. package/dist/utilities/fuzzyMatch.spec.js.map +0 -1
  153. package/dist/utilities/initReq.spec.js +0 -226
  154. package/dist/utilities/initReq.spec.js.map +0 -1
  155. package/dist/utilities/isAbsoluteURL.spec.js +0 -11
  156. package/dist/utilities/isAbsoluteURL.spec.js.map +0 -1
  157. package/dist/utilities/isCustomAdminView.spec.js +0 -90
  158. package/dist/utilities/isCustomAdminView.spec.js.map +0 -1
  159. package/dist/utilities/isHttpURL.spec.js +0 -25
  160. package/dist/utilities/isHttpURL.spec.js.map +0 -1
  161. package/dist/utilities/isPathMatchingRoute.spec.js +0 -178
  162. package/dist/utilities/isPathMatchingRoute.spec.js.map +0 -1
  163. package/dist/utilities/isPublicAdminRoute.spec.js +0 -34
  164. package/dist/utilities/isPublicAdminRoute.spec.js.map +0 -1
  165. package/dist/utilities/normalizeRelationshipValue.spec.js +0 -373
  166. package/dist/utilities/normalizeRelationshipValue.spec.js.map +0 -1
  167. package/dist/utilities/recentlyViewed.spec.js +0 -92
  168. package/dist/utilities/recentlyViewed.spec.js.map +0 -1
  169. package/dist/views/Root/getCustomCollectionViewByRoute.spec.js +0 -168
  170. package/dist/views/Root/getCustomCollectionViewByRoute.spec.js.map +0 -1
  171. package/dist/views/Version/RenderFieldsToDiff/buildVersionFields.spec.js +0 -258
  172. package/dist/views/Version/RenderFieldsToDiff/buildVersionFields.spec.js.map +0 -1
  173. package/dist/views/Version/RenderFieldsToDiff/utilities/countChangedFields.spec.js +0 -915
  174. package/dist/views/Version/RenderFieldsToDiff/utilities/countChangedFields.spec.js.map +0 -1
  175. package/dist/views/Version/RenderFieldsToDiff/utilities/fieldHasChanges.spec.js +0 -47
  176. package/dist/views/Version/RenderFieldsToDiff/utilities/fieldHasChanges.spec.js.map +0 -1
  177. package/dist/views/Version/RenderFieldsToDiff/utilities/getFieldsForRowComparison.spec.js +0 -125
  178. package/dist/views/Version/RenderFieldsToDiff/utilities/getFieldsForRowComparison.spec.js.map +0 -1
  179. package/dist/widgets/CollectionQuery/getCollectionFieldPaths.spec.js +0 -100
  180. package/dist/widgets/CollectionQuery/getCollectionFieldPaths.spec.js.map +0 -1
@@ -1,885 +0,0 @@
1
- import ObjectIdImport from 'bson-objectid';
2
- import { describe, expect, it } from 'vitest';
3
- import { mergeFormStateFromClipboard, reduceFormStateByPath } from './mergeFormStateFromClipboard.js';
4
- const ObjectId = 'default' in ObjectIdImport ? ObjectIdImport.default : ObjectIdImport;
5
- describe('mergeFormStateFromClipboard', () => {
6
- describe('block ID regeneration', () => {
7
- it('should generate new IDs when pasting blocks to prevent duplicates', () => {
8
- const copiedBlockID = new ObjectId().toHexString();
9
- const formState = {
10
- layout: {
11
- valid: true,
12
- value: 0,
13
- initialValue: 0,
14
- rows: []
15
- }
16
- };
17
- const clipboardData = {
18
- type: 'blocks',
19
- path: 'layout',
20
- blocks: [],
21
- data: {
22
- 'layout.0.id': {
23
- value: copiedBlockID,
24
- valid: true
25
- },
26
- 'layout.0.blockType': {
27
- value: 'content',
28
- valid: true
29
- },
30
- 'layout.0.text': {
31
- value: 'test content',
32
- valid: true
33
- }
34
- },
35
- rowIndex: 0
36
- };
37
- const result = mergeFormStateFromClipboard({
38
- dataFromClipboard: clipboardData,
39
- formState,
40
- path: 'layout'
41
- });
42
- // Check that a new ID was generated
43
- expect(result['layout.0.id']).toBeDefined();
44
- expect(result['layout.0.id'].value).toBeDefined();
45
- expect(result['layout.0.id'].value).not.toEqual(copiedBlockID);
46
- expect(ObjectId.isValid(result['layout.0.id'].value)).toBe(true);
47
- // Check that the row metadata also has the new ID
48
- expect(result.layout.rows).toHaveLength(1);
49
- expect(result.layout.rows?.[0]?.id).not.toEqual(copiedBlockID);
50
- expect(result.layout.rows?.[0]?.id).toEqual(result['layout.0.id'].value);
51
- });
52
- it('should generate new IDs for nested blocks', () => {
53
- const copiedBlockID = new ObjectId().toHexString();
54
- const copiedNestedBlockID = new ObjectId().toHexString();
55
- const formState = {
56
- layout: {
57
- valid: true,
58
- value: 0,
59
- initialValue: 0,
60
- rows: []
61
- }
62
- };
63
- const clipboardData = {
64
- type: 'blocks',
65
- path: 'layout',
66
- blocks: [],
67
- data: {
68
- 'layout.0.id': {
69
- value: copiedBlockID,
70
- valid: true
71
- },
72
- 'layout.0.blockType': {
73
- value: 'container',
74
- valid: true
75
- },
76
- 'layout.0.subBlocks': {
77
- value: 1,
78
- valid: true,
79
- rows: [{
80
- id: copiedNestedBlockID
81
- }]
82
- },
83
- 'layout.0.subBlocks.0.id': {
84
- value: copiedNestedBlockID,
85
- valid: true
86
- },
87
- 'layout.0.subBlocks.0.blockType': {
88
- value: 'content',
89
- valid: true
90
- }
91
- },
92
- rowIndex: 0
93
- };
94
- const result = mergeFormStateFromClipboard({
95
- dataFromClipboard: clipboardData,
96
- formState,
97
- path: 'layout'
98
- });
99
- // Check that parent block got new ID
100
- expect(result['layout.0.id'].value).not.toEqual(copiedBlockID);
101
- expect(ObjectId.isValid(result['layout.0.id'].value)).toBe(true);
102
- // Check that nested block got new ID
103
- expect(result['layout.0.subBlocks.0.id'].value).not.toEqual(copiedNestedBlockID);
104
- expect(ObjectId.isValid(result['layout.0.subBlocks.0.id'].value)).toBe(true);
105
- // Check that parent and nested IDs are different
106
- expect(result['layout.0.id'].value).not.toEqual(result['layout.0.subBlocks.0.id'].value);
107
- // Check that parent row metadata has new ID
108
- expect(result.layout.rows?.[0]?.id).toEqual(result['layout.0.id'].value);
109
- // Check that nested row metadata has new ID
110
- expect(result['layout.0.subBlocks'].rows?.[0]?.id).toEqual(result['layout.0.subBlocks.0.id'].value);
111
- });
112
- it('should preserve non-ID field values when pasting', () => {
113
- const copiedBlockID = new ObjectId().toHexString();
114
- const formState = {
115
- layout: {
116
- valid: true,
117
- value: 0,
118
- initialValue: 0,
119
- rows: []
120
- }
121
- };
122
- const clipboardData = {
123
- type: 'blocks',
124
- path: 'layout',
125
- blocks: [],
126
- data: {
127
- 'layout.0.id': {
128
- value: copiedBlockID,
129
- valid: true
130
- },
131
- 'layout.0.blockType': {
132
- value: 'content',
133
- valid: true
134
- },
135
- 'layout.0.text': {
136
- value: 'preserved text content',
137
- valid: true
138
- }
139
- },
140
- rowIndex: 0
141
- };
142
- const result = mergeFormStateFromClipboard({
143
- dataFromClipboard: clipboardData,
144
- formState,
145
- path: 'layout'
146
- });
147
- // Non-ID fields should be preserved
148
- expect(result['layout.0.blockType'].value).toEqual('content');
149
- expect(result['layout.0.text'].value).toEqual('preserved text content');
150
- });
151
- it('should generate new ID when pasting from row to field', () => {
152
- const copiedBlockID = new ObjectId().toHexString();
153
- const formState = {
154
- duplicate: {
155
- valid: true,
156
- value: 0,
157
- initialValue: 0,
158
- rows: []
159
- }
160
- };
161
- // Simulating copying from blocks.1 and pasting into duplicate field
162
- const clipboardData = {
163
- type: 'blocks',
164
- path: 'blocks',
165
- blocks: [],
166
- data: {
167
- 'blocks.1.id': {
168
- value: copiedBlockID,
169
- valid: true
170
- },
171
- 'blocks.1.blockType': {
172
- value: 'number',
173
- valid: true
174
- },
175
- 'blocks.1.number': {
176
- value: 342,
177
- valid: true
178
- }
179
- },
180
- rowIndex: 1
181
- };
182
- const result = mergeFormStateFromClipboard({
183
- dataFromClipboard: clipboardData,
184
- formState,
185
- path: 'duplicate'
186
- });
187
- // Check that a new ID was generated
188
- expect(result['duplicate.0.id']).toBeDefined();
189
- expect(result['duplicate.0.id'].value).toBeDefined();
190
- expect(result['duplicate.0.id'].value).not.toEqual(copiedBlockID);
191
- expect(ObjectId.isValid(result['duplicate.0.id'].value)).toBe(true);
192
- // Check that the row metadata has the new ID (not the copied ID)
193
- expect(result.duplicate.rows).toBeDefined();
194
- expect(result.duplicate.rows).toHaveLength(1);
195
- expect(result.duplicate.rows[0].id).not.toEqual(copiedBlockID);
196
- expect(result.duplicate.rows[0].id).toEqual(result['duplicate.0.id'].value);
197
- // Check that other fields were preserved
198
- expect(result['duplicate.0.number'].value).toEqual(342);
199
- });
200
- });
201
- describe('block row paste with nested array', () => {
202
- it('should regenerate nested array item IDs when pasting a block row', () => {
203
- const copiedBlockID = new ObjectId().toHexString();
204
- const copiedArrayItemID1 = new ObjectId().toHexString();
205
- const copiedArrayItemID2 = new ObjectId().toHexString();
206
- const copiedArrayItemID3 = new ObjectId().toHexString();
207
- const targetBlockID = new ObjectId().toHexString();
208
- // Target form state: block at index 1 with empty buttons array
209
- const formState = {
210
- ctas: {
211
- valid: true,
212
- value: 2,
213
- initialValue: 2,
214
- rows: [{
215
- id: copiedBlockID,
216
- blockType: 'callToAction',
217
- isLoading: false
218
- }, {
219
- id: targetBlockID,
220
- blockType: 'callToAction',
221
- isLoading: false
222
- }]
223
- },
224
- 'ctas.0': {
225
- value: 'callToAction',
226
- valid: true
227
- },
228
- 'ctas.0.id': {
229
- value: copiedBlockID,
230
- valid: true
231
- },
232
- 'ctas.0.buttons': {
233
- valid: true,
234
- value: 3,
235
- rows: [{
236
- id: copiedArrayItemID1,
237
- isLoading: false
238
- }, {
239
- id: copiedArrayItemID2,
240
- isLoading: false
241
- }, {
242
- id: copiedArrayItemID3,
243
- isLoading: false
244
- }]
245
- },
246
- 'ctas.0.buttons.0.id': {
247
- value: copiedArrayItemID1,
248
- valid: true
249
- },
250
- 'ctas.0.buttons.1.id': {
251
- value: copiedArrayItemID2,
252
- valid: true
253
- },
254
- 'ctas.0.buttons.2.id': {
255
- value: copiedArrayItemID3,
256
- valid: true
257
- },
258
- 'ctas.1': {
259
- value: 'callToAction',
260
- valid: true
261
- },
262
- 'ctas.1.id': {
263
- value: targetBlockID,
264
- valid: true
265
- },
266
- 'ctas.1.buttons': {
267
- valid: true,
268
- value: 0,
269
- rows: []
270
- }
271
- };
272
- // Clipboard: block row 0 (source) with 3 buttons
273
- const clipboardData = {
274
- type: 'blocks',
275
- path: 'ctas',
276
- blocks: [],
277
- rowIndex: 0,
278
- data: {
279
- 'ctas.0': {
280
- value: 'callToAction',
281
- valid: true
282
- },
283
- 'ctas.0.id': {
284
- value: copiedBlockID,
285
- valid: true
286
- },
287
- 'ctas.0.buttons': {
288
- valid: true,
289
- value: 3,
290
- rows: [{
291
- id: copiedArrayItemID1,
292
- isLoading: false
293
- }, {
294
- id: copiedArrayItemID2,
295
- isLoading: false
296
- }, {
297
- id: copiedArrayItemID3,
298
- isLoading: false
299
- }]
300
- },
301
- 'ctas.0.buttons.0.id': {
302
- value: copiedArrayItemID1,
303
- valid: true
304
- },
305
- 'ctas.0.buttons.0.label': {
306
- value: 'Button 1',
307
- valid: true
308
- },
309
- 'ctas.0.buttons.1.id': {
310
- value: copiedArrayItemID2,
311
- valid: true
312
- },
313
- 'ctas.0.buttons.1.label': {
314
- value: 'Button 2',
315
- valid: true
316
- },
317
- 'ctas.0.buttons.2.id': {
318
- value: copiedArrayItemID3,
319
- valid: true
320
- },
321
- 'ctas.0.buttons.2.label': {
322
- value: 'Button 3',
323
- valid: true
324
- }
325
- }
326
- };
327
- // Paste into block row 1 (target)
328
- const result = mergeFormStateFromClipboard({
329
- dataFromClipboard: clipboardData,
330
- formState,
331
- path: 'ctas',
332
- rowIndex: 1
333
- });
334
- // Target block ID should NOT be overwritten
335
- expect(result['ctas.1.id'].value).toEqual(targetBlockID);
336
- // Nested array items should have NEW IDs (not the source IDs)
337
- expect(result['ctas.1.buttons.0.id']).toBeDefined();
338
- expect(result['ctas.1.buttons.0.id'].value).not.toEqual(copiedArrayItemID1);
339
- expect(ObjectId.isValid(result['ctas.1.buttons.0.id'].value)).toBe(true);
340
- expect(result['ctas.1.buttons.1.id']).toBeDefined();
341
- expect(result['ctas.1.buttons.1.id'].value).not.toEqual(copiedArrayItemID2);
342
- expect(result['ctas.1.buttons.2.id']).toBeDefined();
343
- expect(result['ctas.1.buttons.2.id'].value).not.toEqual(copiedArrayItemID3);
344
- // The rows metadata in ctas.1.buttons should have the new IDs
345
- expect(result['ctas.1.buttons'].rows).toHaveLength(3);
346
- expect(result['ctas.1.buttons'].rows[0].id).toEqual(result['ctas.1.buttons.0.id'].value);
347
- expect(result['ctas.1.buttons'].rows[1].id).toEqual(result['ctas.1.buttons.1.id'].value);
348
- expect(result['ctas.1.buttons'].rows[2].id).toEqual(result['ctas.1.buttons.2.id'].value);
349
- // Field values should be copied
350
- expect(result['ctas.1.buttons.0.label'].value).toEqual('Button 1');
351
- expect(result['ctas.1.buttons.1.label'].value).toEqual('Button 2');
352
- expect(result['ctas.1.buttons.2.label'].value).toEqual('Button 3');
353
- // Source block should be untouched
354
- expect(result['ctas.0.id'].value).toEqual(copiedBlockID);
355
- expect(result['ctas.0.buttons'].rows).toHaveLength(3);
356
- });
357
- });
358
- describe('array ID regeneration', () => {
359
- it('should generate new IDs when pasting arrays to prevent duplicates', () => {
360
- const copiedArrayID = new ObjectId().toHexString();
361
- const formState = {
362
- items: {
363
- valid: true,
364
- value: 0,
365
- initialValue: 0,
366
- rows: []
367
- }
368
- };
369
- const clipboardData = {
370
- type: 'array',
371
- path: 'items',
372
- fields: [],
373
- data: {
374
- 'items.0.id': {
375
- value: copiedArrayID,
376
- valid: true
377
- },
378
- 'items.0.text': {
379
- value: 'test content',
380
- valid: true
381
- }
382
- },
383
- rowIndex: 0
384
- };
385
- const result = mergeFormStateFromClipboard({
386
- dataFromClipboard: clipboardData,
387
- formState,
388
- path: 'items'
389
- });
390
- // Check that a new ID was generated
391
- expect(result['items.0.id']).toBeDefined();
392
- expect(result['items.0.id'].value).toBeDefined();
393
- expect(result['items.0.id'].value).not.toEqual(copiedArrayID);
394
- expect(ObjectId.isValid(result['items.0.id'].value)).toBe(true);
395
- // Check that the row metadata also has the new ID
396
- expect(result.items.rows).toHaveLength(1);
397
- expect(result.items.rows?.[0]?.id).not.toEqual(copiedArrayID);
398
- expect(result.items.rows?.[0]?.id).toEqual(result['items.0.id'].value);
399
- });
400
- it('should generate new IDs for nested arrays', () => {
401
- const copiedArrayID = new ObjectId().toHexString();
402
- const copiedNestedArrayID = new ObjectId().toHexString();
403
- const formState = {
404
- items: {
405
- valid: true,
406
- value: 0,
407
- initialValue: 0,
408
- rows: []
409
- }
410
- };
411
- const clipboardData = {
412
- type: 'array',
413
- path: 'items',
414
- fields: [],
415
- data: {
416
- 'items.0.id': {
417
- value: copiedArrayID,
418
- valid: true
419
- },
420
- 'items.0.text': {
421
- value: 'parent array',
422
- valid: true
423
- },
424
- 'items.0.subArray': {
425
- value: 1,
426
- valid: true,
427
- rows: [{
428
- id: copiedNestedArrayID
429
- }]
430
- },
431
- 'items.0.subArray.0.id': {
432
- value: copiedNestedArrayID,
433
- valid: true
434
- },
435
- 'items.0.subArray.0.text': {
436
- value: 'nested array',
437
- valid: true
438
- }
439
- },
440
- rowIndex: 0
441
- };
442
- const result = mergeFormStateFromClipboard({
443
- dataFromClipboard: clipboardData,
444
- formState,
445
- path: 'items'
446
- });
447
- // Check that parent array got new ID
448
- expect(result['items.0.id'].value).not.toEqual(copiedArrayID);
449
- expect(ObjectId.isValid(result['items.0.id'].value)).toBe(true);
450
- // Check that nested array got new ID
451
- expect(result['items.0.subArray.0.id'].value).not.toEqual(copiedNestedArrayID);
452
- expect(ObjectId.isValid(result['items.0.subArray.0.id'].value)).toBe(true);
453
- // Check that parent and nested IDs are different
454
- expect(result['items.0.id'].value).not.toEqual(result['items.0.subArray.0.id'].value);
455
- // Check that parent row metadata has new ID
456
- expect(result.items.rows?.[0]?.id).toEqual(result['items.0.id'].value);
457
- // Check that nested row metadata has new ID
458
- expect(result['items.0.subArray'].rows?.[0]?.id).toEqual(result['items.0.subArray.0.id'].value);
459
- });
460
- it('should preserve non-ID field values when pasting arrays', () => {
461
- const copiedArrayID = new ObjectId().toHexString();
462
- const formState = {
463
- items: {
464
- valid: true,
465
- value: 0,
466
- initialValue: 0,
467
- rows: []
468
- }
469
- };
470
- const clipboardData = {
471
- type: 'array',
472
- path: 'items',
473
- fields: [],
474
- data: {
475
- 'items.0.id': {
476
- value: copiedArrayID,
477
- valid: true
478
- },
479
- 'items.0.text': {
480
- value: 'preserved array text',
481
- valid: true
482
- }
483
- },
484
- rowIndex: 0
485
- };
486
- const result = mergeFormStateFromClipboard({
487
- dataFromClipboard: clipboardData,
488
- formState,
489
- path: 'items'
490
- });
491
- // Non-ID fields should be preserved
492
- expect(result['items.0.text'].value).toEqual('preserved array text');
493
- });
494
- it('should generate new ID when pasting from array row to field', () => {
495
- const copiedArrayID = new ObjectId().toHexString();
496
- const formState = {
497
- disableSort: {
498
- valid: true,
499
- value: 0,
500
- initialValue: 0,
501
- rows: []
502
- }
503
- };
504
- // Simulating copying from items.0 and pasting into disableSort field
505
- const clipboardData = {
506
- type: 'array',
507
- path: 'items',
508
- fields: [],
509
- data: {
510
- 'items.0.id': {
511
- value: copiedArrayID,
512
- valid: true
513
- },
514
- 'items.0.text': {
515
- value: 'row one',
516
- valid: true
517
- }
518
- },
519
- rowIndex: 0
520
- };
521
- const result = mergeFormStateFromClipboard({
522
- dataFromClipboard: clipboardData,
523
- formState,
524
- path: 'disableSort'
525
- });
526
- // Check that a new ID was generated
527
- expect(result['disableSort.0.id']).toBeDefined();
528
- expect(result['disableSort.0.id'].value).toBeDefined();
529
- expect(result['disableSort.0.id'].value).not.toEqual(copiedArrayID);
530
- expect(ObjectId.isValid(result['disableSort.0.id'].value)).toBe(true);
531
- // Check that the row metadata has the new ID (not the copied ID)
532
- expect(result.disableSort.rows).toBeDefined();
533
- expect(result.disableSort.rows).toHaveLength(1);
534
- expect(result.disableSort.rows[0].id).not.toEqual(copiedArrayID);
535
- expect(result.disableSort.rows[0].id).toEqual(result['disableSort.0.id'].value);
536
- // Check that other fields were preserved
537
- expect(result['disableSort.0.text'].value).toEqual('row one');
538
- });
539
- });
540
- describe('prefix collision with multi-digit sibling indices', () => {
541
- it('reduceFormStateByPath should not leak siblings whose indices share a digit prefix', () => {
542
- // Array with 13 rows. Copying row 1 must filter out rows 10/11/12, whose
543
- // paths all begin with the substring `children.1`.
544
- const formState = {
545
- children: {
546
- valid: true,
547
- value: 13,
548
- rows: Array.from({
549
- length: 13
550
- }, () => ({
551
- isLoading: false
552
- }))
553
- },
554
- 'children.1.id': {
555
- value: 'id-1',
556
- valid: true
557
- },
558
- 'children.1.title': {
559
- value: 'Row 1',
560
- valid: true
561
- },
562
- 'children.10.id': {
563
- value: 'id-10',
564
- valid: true
565
- },
566
- 'children.10.title': {
567
- value: 'Row 10',
568
- valid: true
569
- },
570
- 'children.11.id': {
571
- value: 'id-11',
572
- valid: true
573
- },
574
- 'children.11.title': {
575
- value: 'Row 11',
576
- valid: true
577
- },
578
- 'children.12.id': {
579
- value: 'id-12',
580
- valid: true
581
- },
582
- 'children.12.title': {
583
- value: 'Row 12',
584
- valid: true
585
- }
586
- };
587
- const filtered = reduceFormStateByPath({
588
- formState,
589
- path: 'children',
590
- rowIndex: 1
591
- });
592
- const filteredKeys = Object.keys(filtered).sort();
593
- expect(filteredKeys).toEqual(['children.1.id', 'children.1.title']);
594
- expect(filtered['children.10.id']).toBeUndefined();
595
- expect(filtered['children.11.id']).toBeUndefined();
596
- expect(filtered['children.12.id']).toBeUndefined();
597
- });
598
- it('reduceFormStateByPath should not leak field-name siblings sharing a textual prefix', () => {
599
- // `children` vs `childrenOther`: loose prefix matching pulls the wrong field's state.
600
- const formState = {
601
- children: {
602
- valid: true,
603
- value: 1,
604
- rows: [{
605
- isLoading: false
606
- }]
607
- },
608
- 'children.0.id': {
609
- value: 'children-row',
610
- valid: true
611
- },
612
- childrenOther: {
613
- valid: true,
614
- value: 1,
615
- rows: [{
616
- isLoading: false
617
- }]
618
- },
619
- 'childrenOther.0.id': {
620
- value: 'other-row',
621
- valid: true
622
- }
623
- };
624
- const filtered = reduceFormStateByPath({
625
- formState,
626
- path: 'children'
627
- });
628
- // The field's own key carries `rows` and `value`, so it must survive the filter.
629
- expect(filtered.children).toBeDefined();
630
- expect(filtered['children.0.id']).toBeDefined();
631
- expect(filtered.childrenOther).toBeUndefined();
632
- expect(filtered['childrenOther.0.id']).toBeUndefined();
633
- });
634
- it('paste should not create out-of-bounds rows from a leaked clipboard payload', () => {
635
- // Simulates the end-to-end Copy/Paste flow against an array with 13 rows. Even if a
636
- // pre-fix clipboard leaked sibling rows (.10/.11/.12) when copying row 1, the merge
637
- // filter must drop them rather than rewriting them to .50/.51/.52 when pasting into
638
- // row 5.
639
- const formState = {
640
- children: {
641
- valid: true,
642
- value: 13,
643
- rows: Array.from({
644
- length: 13
645
- }, () => ({
646
- id: new ObjectId().toHexString(),
647
- isLoading: false
648
- }))
649
- },
650
- 'children.5.id': {
651
- value: new ObjectId().toHexString(),
652
- valid: true
653
- }
654
- };
655
- const sourceID = new ObjectId().toHexString();
656
- const clipboardData = {
657
- type: 'array',
658
- path: 'children',
659
- fields: [],
660
- rowIndex: 1,
661
- data: {
662
- 'children.1.id': {
663
- value: sourceID,
664
- valid: true
665
- },
666
- 'children.1.title': {
667
- value: 'Row 1 title',
668
- valid: true
669
- },
670
- // Leaked siblings — these must be dropped, not rewritten to .50/.51/.52.
671
- 'children.10.id': {
672
- value: new ObjectId().toHexString(),
673
- valid: true
674
- },
675
- 'children.10.title': {
676
- value: 'Leaked Row 10',
677
- valid: true
678
- },
679
- 'children.11.id': {
680
- value: new ObjectId().toHexString(),
681
- valid: true
682
- },
683
- 'children.11.title': {
684
- value: 'Leaked Row 11',
685
- valid: true
686
- },
687
- 'children.12.id': {
688
- value: new ObjectId().toHexString(),
689
- valid: true
690
- },
691
- 'children.12.title': {
692
- value: 'Leaked Row 12',
693
- valid: true
694
- }
695
- }
696
- };
697
- const result = mergeFormStateFromClipboard({
698
- dataFromClipboard: clipboardData,
699
- formState,
700
- path: 'children',
701
- rowIndex: 5
702
- });
703
- // Target row populated from the source row.
704
- expect(result['children.5.title']?.value).toEqual('Row 1 title');
705
- // No phantom out-of-bounds rows. These would correspond to `.10`/`.11`/`.12` being
706
- // rewritten through `String.replace('children.1', 'children.5')`.
707
- expect(result['children.50']).toBeUndefined();
708
- expect(result['children.51']).toBeUndefined();
709
- expect(result['children.52']).toBeUndefined();
710
- expect(result['children.50.id']).toBeUndefined();
711
- expect(result['children.51.id']).toBeUndefined();
712
- expect(result['children.52.id']).toBeUndefined();
713
- expect(result['children.50.title']).toBeUndefined();
714
- expect(result['children.51.title']).toBeUndefined();
715
- expect(result['children.52.title']).toBeUndefined();
716
- });
717
- it('row-to-field cleanup should not delete unrelated fields with a textual prefix collision', () => {
718
- // `path` = 'children', `lastRenderedPath` = 'children.0'. A sibling field
719
- // `childrenOther.0.title` must NOT be deleted by the cleanup loop.
720
- const formState = {
721
- children: {
722
- valid: true,
723
- value: 0,
724
- rows: [{
725
- isLoading: false
726
- }]
727
- },
728
- 'children.0.id': {
729
- value: new ObjectId().toHexString(),
730
- valid: true
731
- },
732
- childrenOther: {
733
- valid: true,
734
- value: 1,
735
- rows: [{
736
- isLoading: false
737
- }]
738
- },
739
- 'childrenOther.0.id': {
740
- value: new ObjectId().toHexString(),
741
- valid: true
742
- },
743
- 'childrenOther.0.title': {
744
- value: 'Unrelated field',
745
- valid: true
746
- }
747
- };
748
- const sourceID = new ObjectId().toHexString();
749
- const clipboardData = {
750
- type: 'array',
751
- path: 'someOtherArray',
752
- fields: [],
753
- rowIndex: 0,
754
- data: {
755
- 'someOtherArray.0.id': {
756
- value: sourceID,
757
- valid: true
758
- },
759
- 'someOtherArray.0.title': {
760
- value: 'Pasted row',
761
- valid: true
762
- }
763
- }
764
- };
765
- const result = mergeFormStateFromClipboard({
766
- dataFromClipboard: clipboardData,
767
- formState,
768
- path: 'children'
769
- });
770
- // Unrelated `childrenOther.*` paths survive the cleanup.
771
- expect(result.childrenOther).toBeDefined();
772
- expect(result['childrenOther.0.id']).toBeDefined();
773
- expect(result['childrenOther.0.title']?.value).toEqual('Unrelated field');
774
- });
775
- });
776
- describe('exact path matches', () => {
777
- // Blocks store the block type under the row key itself (`ctas.1`), with no trailing
778
- // segment. Tightening the prefix check must keep matching that exact key, otherwise
779
- // copy drops the block type and paste never restores it.
780
- it('reduceFormStateByPath should keep the exact row key while filtering digit-prefix siblings', () => {
781
- const formState = {
782
- ctas: {
783
- valid: true,
784
- value: 13,
785
- rows: Array.from({
786
- length: 13
787
- }, () => ({
788
- blockType: 'callToAction',
789
- isLoading: false
790
- }))
791
- },
792
- 'ctas.1': {
793
- value: 'callToAction',
794
- valid: true
795
- },
796
- 'ctas.1.id': {
797
- value: 'id-1',
798
- valid: true
799
- },
800
- 'ctas.10': {
801
- value: 'callToAction',
802
- valid: true
803
- },
804
- 'ctas.10.id': {
805
- value: 'id-10',
806
- valid: true
807
- },
808
- 'ctas.11': {
809
- value: 'callToAction',
810
- valid: true
811
- },
812
- 'ctas.11.id': {
813
- value: 'id-11',
814
- valid: true
815
- }
816
- };
817
- const filtered = reduceFormStateByPath({
818
- formState,
819
- path: 'ctas',
820
- rowIndex: 1
821
- });
822
- const filteredKeys = Object.keys(filtered).sort();
823
- expect(filteredKeys).toEqual(['ctas.1', 'ctas.1.id']);
824
- expect(filtered['ctas.1']?.value).toEqual('callToAction');
825
- });
826
- it('paste should copy the exact row key across to the target row', () => {
827
- const sourceBlockID = new ObjectId().toHexString();
828
- const targetBlockID = new ObjectId().toHexString();
829
- const formState = {
830
- ctas: {
831
- valid: true,
832
- value: 2,
833
- initialValue: 2,
834
- rows: [{
835
- id: sourceBlockID,
836
- blockType: 'callToAction',
837
- isLoading: false
838
- }, {
839
- id: targetBlockID,
840
- blockType: 'content',
841
- isLoading: false
842
- }]
843
- },
844
- 'ctas.1': {
845
- value: 'content',
846
- valid: true
847
- },
848
- 'ctas.1.id': {
849
- value: targetBlockID,
850
- valid: true
851
- }
852
- };
853
- const clipboardData = {
854
- type: 'blocks',
855
- path: 'ctas',
856
- blocks: [],
857
- rowIndex: 0,
858
- data: {
859
- 'ctas.0': {
860
- value: 'callToAction',
861
- valid: true
862
- },
863
- 'ctas.0.id': {
864
- value: sourceBlockID,
865
- valid: true
866
- },
867
- 'ctas.0.label': {
868
- value: 'Source label',
869
- valid: true
870
- }
871
- }
872
- };
873
- const result = mergeFormStateFromClipboard({
874
- dataFromClipboard: clipboardData,
875
- formState,
876
- path: 'ctas',
877
- rowIndex: 1
878
- });
879
- // The block type lives at the exact row key, so pasting must overwrite it.
880
- expect(result['ctas.1']?.value).toEqual('callToAction');
881
- expect(result['ctas.1.label']?.value).toEqual('Source label');
882
- });
883
- });
884
- });
885
- //# sourceMappingURL=mergeFormStateFromClipboard.spec.js.map