@wordpress/block-editor 9.1.0 → 9.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.
Files changed (170) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/block-draggable/draggable-chip.native.js +2 -1
  3. package/build/components/block-draggable/draggable-chip.native.js.map +1 -1
  4. package/build/components/block-draggable/index.native.js +7 -3
  5. package/build/components/block-draggable/index.native.js.map +1 -1
  6. package/build/components/block-list/block.native.js +2 -1
  7. package/build/components/block-list/block.native.js.map +1 -1
  8. package/build/components/block-list/index.js +34 -32
  9. package/build/components/block-list/index.js.map +1 -1
  10. package/build/components/block-mobile-toolbar/index.native.js +2 -1
  11. package/build/components/block-mobile-toolbar/index.native.js.map +1 -1
  12. package/build/components/block-popover/inbetween.js +9 -6
  13. package/build/components/block-popover/inbetween.js.map +1 -1
  14. package/build/components/block-popover/index.js +2 -1
  15. package/build/components/block-popover/index.js.map +1 -1
  16. package/build/components/block-tools/block-selection-button.js +1 -0
  17. package/build/components/block-tools/block-selection-button.js.map +1 -1
  18. package/build/components/block-variation-transforms/index.js +16 -2
  19. package/build/components/block-variation-transforms/index.js.map +1 -1
  20. package/build/components/colors-gradients/dropdown.js +70 -94
  21. package/build/components/colors-gradients/dropdown.js.map +1 -1
  22. package/build/components/colors-gradients/panel-color-gradient-settings.js +35 -60
  23. package/build/components/colors-gradients/panel-color-gradient-settings.js.map +1 -1
  24. package/build/components/convert-to-group-buttons/toolbar.js +22 -5
  25. package/build/components/convert-to-group-buttons/toolbar.js.map +1 -1
  26. package/build/components/index.js +9 -0
  27. package/build/components/index.js.map +1 -1
  28. package/build/components/media-placeholder/index.js +0 -2
  29. package/build/components/media-placeholder/index.js.map +1 -1
  30. package/build/components/media-replace-flow/index.js +0 -2
  31. package/build/components/media-replace-flow/index.js.map +1 -1
  32. package/build/components/media-upload/index.native.js +10 -4
  33. package/build/components/media-upload/index.native.js.map +1 -1
  34. package/build/components/plain-text/index.native.js +62 -7
  35. package/build/components/plain-text/index.native.js.map +1 -1
  36. package/build/components/publish-date-time-picker/index.js +55 -0
  37. package/build/components/publish-date-time-picker/index.js.map +1 -0
  38. package/build/components/rich-text/index.js +1 -1
  39. package/build/components/rich-text/index.js.map +1 -1
  40. package/build/components/rich-text/index.native.js +5 -1
  41. package/build/components/rich-text/index.native.js.map +1 -1
  42. package/build/components/writing-flow/use-input.js +15 -0
  43. package/build/components/writing-flow/use-input.js.map +1 -1
  44. package/build/elements/index.js +9 -0
  45. package/build/elements/index.js.map +1 -0
  46. package/build/hooks/color.js +8 -88
  47. package/build/hooks/color.js.map +1 -1
  48. package/build/hooks/dimensions.js +14 -4
  49. package/build/hooks/dimensions.js.map +1 -1
  50. package/build/index.js +14 -0
  51. package/build/index.js.map +1 -1
  52. package/build/layouts/flex.js +5 -2
  53. package/build/layouts/flex.js.map +1 -1
  54. package/build/store/actions.js +14 -0
  55. package/build/store/actions.js.map +1 -1
  56. package/build/store/reducer.js +17 -2
  57. package/build/store/reducer.js.map +1 -1
  58. package/build/store/selectors.js +29 -1
  59. package/build/store/selectors.js.map +1 -1
  60. package/build-module/components/block-draggable/draggable-chip.native.js +2 -1
  61. package/build-module/components/block-draggable/draggable-chip.native.js.map +1 -1
  62. package/build-module/components/block-draggable/index.native.js +7 -3
  63. package/build-module/components/block-draggable/index.native.js.map +1 -1
  64. package/build-module/components/block-list/block.native.js +2 -1
  65. package/build-module/components/block-list/block.native.js.map +1 -1
  66. package/build-module/components/block-list/index.js +35 -33
  67. package/build-module/components/block-list/index.js.map +1 -1
  68. package/build-module/components/block-mobile-toolbar/index.native.js +2 -1
  69. package/build-module/components/block-mobile-toolbar/index.native.js.map +1 -1
  70. package/build-module/components/block-popover/inbetween.js +9 -6
  71. package/build-module/components/block-popover/inbetween.js.map +1 -1
  72. package/build-module/components/block-popover/index.js +2 -1
  73. package/build-module/components/block-popover/index.js.map +1 -1
  74. package/build-module/components/block-tools/block-selection-button.js +1 -0
  75. package/build-module/components/block-tools/block-selection-button.js.map +1 -1
  76. package/build-module/components/block-variation-transforms/index.js +13 -2
  77. package/build-module/components/block-variation-transforms/index.js.map +1 -1
  78. package/build-module/components/colors-gradients/dropdown.js +72 -96
  79. package/build-module/components/colors-gradients/dropdown.js.map +1 -1
  80. package/build-module/components/colors-gradients/panel-color-gradient-settings.js +36 -64
  81. package/build-module/components/colors-gradients/panel-color-gradient-settings.js.map +1 -1
  82. package/build-module/components/convert-to-group-buttons/toolbar.js +23 -6
  83. package/build-module/components/convert-to-group-buttons/toolbar.js.map +1 -1
  84. package/build-module/components/index.js +1 -0
  85. package/build-module/components/index.js.map +1 -1
  86. package/build-module/components/media-placeholder/index.js +0 -2
  87. package/build-module/components/media-placeholder/index.js.map +1 -1
  88. package/build-module/components/media-replace-flow/index.js +0 -2
  89. package/build-module/components/media-replace-flow/index.js.map +1 -1
  90. package/build-module/components/media-upload/index.native.js +8 -3
  91. package/build-module/components/media-upload/index.native.js.map +1 -1
  92. package/build-module/components/plain-text/index.native.js +63 -8
  93. package/build-module/components/plain-text/index.native.js.map +1 -1
  94. package/build-module/components/publish-date-time-picker/index.js +42 -0
  95. package/build-module/components/publish-date-time-picker/index.js.map +1 -0
  96. package/build-module/components/rich-text/index.js +1 -1
  97. package/build-module/components/rich-text/index.js.map +1 -1
  98. package/build-module/components/rich-text/index.native.js +5 -1
  99. package/build-module/components/rich-text/index.native.js.map +1 -1
  100. package/build-module/components/writing-flow/use-input.js +15 -0
  101. package/build-module/components/writing-flow/use-input.js.map +1 -1
  102. package/build-module/elements/index.js +2 -0
  103. package/build-module/elements/index.js.map +1 -0
  104. package/build-module/hooks/color.js +8 -88
  105. package/build-module/hooks/color.js.map +1 -1
  106. package/build-module/hooks/dimensions.js +14 -4
  107. package/build-module/hooks/dimensions.js.map +1 -1
  108. package/build-module/index.js +1 -0
  109. package/build-module/index.js.map +1 -1
  110. package/build-module/layouts/flex.js +4 -2
  111. package/build-module/layouts/flex.js.map +1 -1
  112. package/build-module/store/actions.js +12 -0
  113. package/build-module/store/actions.js.map +1 -1
  114. package/build-module/store/reducer.js +17 -2
  115. package/build-module/store/reducer.js.map +1 -1
  116. package/build-module/store/selectors.js +23 -0
  117. package/build-module/store/selectors.js.map +1 -1
  118. package/build-style/style-rtl.css +37 -34
  119. package/build-style/style.css +37 -34
  120. package/package.json +30 -30
  121. package/src/components/block-draggable/draggable-chip.native.js +1 -1
  122. package/src/components/block-draggable/index.native.js +4 -0
  123. package/src/components/block-draggable/test/__snapshots__/index.native.js.snap +73 -0
  124. package/src/components/block-draggable/test/helpers.native.js +183 -0
  125. package/src/components/block-draggable/test/index.native.js +496 -0
  126. package/src/components/block-list/block.native.js +1 -0
  127. package/src/components/block-list/index.js +44 -44
  128. package/src/components/block-mobile-toolbar/index.native.js +1 -0
  129. package/src/components/block-mover/test/__snapshots__/index.native.js.snap +4 -0
  130. package/src/components/block-popover/inbetween.js +12 -7
  131. package/src/components/block-popover/index.js +1 -0
  132. package/src/components/block-tools/block-selection-button.js +1 -0
  133. package/src/components/block-variation-transforms/index.js +6 -2
  134. package/src/components/colors-gradients/dropdown.js +35 -61
  135. package/src/components/colors-gradients/panel-color-gradient-settings.js +30 -76
  136. package/src/components/colors-gradients/style.scss +11 -37
  137. package/src/components/convert-to-group-buttons/toolbar.js +30 -13
  138. package/src/components/index.js +1 -0
  139. package/src/components/media-placeholder/index.js +0 -2
  140. package/src/components/media-replace-flow/index.js +0 -2
  141. package/src/components/media-upload/index.native.js +6 -2
  142. package/src/components/media-upload/test/index.native.js +31 -6
  143. package/src/components/plain-text/index.native.js +64 -8
  144. package/src/components/publish-date-time-picker/README.md +52 -0
  145. package/src/components/publish-date-time-picker/index.js +50 -0
  146. package/src/components/publish-date-time-picker/style.scss +20 -0
  147. package/src/components/rich-text/index.js +2 -0
  148. package/src/components/rich-text/index.native.js +4 -0
  149. package/src/components/writing-flow/use-input.js +12 -0
  150. package/src/elements/index.js +1 -0
  151. package/src/hooks/color.js +5 -74
  152. package/src/hooks/color.scss +9 -0
  153. package/src/hooks/dimensions.js +11 -3
  154. package/src/index.js +1 -0
  155. package/src/layouts/flex.js +11 -3
  156. package/src/store/actions.js +12 -0
  157. package/src/store/reducer.js +14 -1
  158. package/src/store/selectors.js +28 -0
  159. package/src/store/test/reducer.js +5 -0
  160. package/src/style.scss +1 -0
  161. package/build/components/colors/color-panel.js +0 -82
  162. package/build/components/colors/color-panel.js.map +0 -1
  163. package/build/components/colors/color-panel.native.js +0 -11
  164. package/build/components/colors/color-panel.native.js.map +0 -1
  165. package/build-module/components/colors/color-panel.js +0 -70
  166. package/build-module/components/colors/color-panel.js.map +0 -1
  167. package/build-module/components/colors/color-panel.native.js +0 -4
  168. package/build-module/components/colors/color-panel.native.js.map +0 -1
  169. package/src/components/colors/color-panel.js +0 -91
  170. package/src/components/colors/color-panel.native.js +0 -3
@@ -0,0 +1,496 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import {
5
+ fireEvent,
6
+ getEditorHtml,
7
+ within,
8
+ waitForStoreResolvers,
9
+ withReanimatedTimer,
10
+ } from 'test/helpers';
11
+ import { getByGestureTestId } from 'react-native-gesture-handler/jest-utils';
12
+ import TextInputState from 'react-native/Libraries/Components/TextInput/TextInputState';
13
+
14
+ /**
15
+ * WordPress dependencies
16
+ */
17
+ import { getBlockTypes, unregisterBlockType } from '@wordpress/blocks';
18
+ import { registerCoreBlocks } from '@wordpress/block-library';
19
+ import '@wordpress/jest-console';
20
+
21
+ /**
22
+ * Internal dependencies
23
+ */
24
+ import {
25
+ initializeWithBlocksLayouts,
26
+ fireLongPress,
27
+ firePanGesture,
28
+ TouchEventType,
29
+ getDraggableChip,
30
+ } from './helpers';
31
+
32
+ // Mock throttle to allow updating the dragging position on every "onDragOver" event.
33
+ jest.mock( 'lodash', () => ( {
34
+ ...jest.requireActual( 'lodash' ),
35
+ throttle: ( fn ) => {
36
+ fn.cancel = jest.fn();
37
+ return fn;
38
+ },
39
+ } ) );
40
+
41
+ beforeAll( () => {
42
+ // Register all core blocks
43
+ registerCoreBlocks();
44
+ } );
45
+
46
+ afterAll( () => {
47
+ // Clean up registered blocks
48
+ getBlockTypes().forEach( ( block ) => {
49
+ unregisterBlockType( block.name );
50
+ } );
51
+ } );
52
+
53
+ const TOUCH_EVENT_ID = 1;
54
+ const BLOCKS = [
55
+ {
56
+ name: 'Paragraph',
57
+ html: `
58
+ <!-- wp:paragraph -->
59
+ <p>This is a paragraph.</p>
60
+ <!-- /wp:paragraph -->`,
61
+ layout: { x: 0, y: 0, width: 100, height: 100 },
62
+ },
63
+ {
64
+ name: 'Image',
65
+ html: `
66
+ <!-- wp:image {"sizeSlug":"large"} -->
67
+ <figure class="wp-block-image size-large"><img src="https://cldup.com/cXyG__fTLN.jpg" alt=""/></figure>
68
+ <!-- /wp:image -->`,
69
+ layout: { x: 0, y: 100, width: 100, height: 100 },
70
+ },
71
+ {
72
+ name: 'Spacer',
73
+ html: `
74
+ <!-- wp:spacer -->
75
+ <div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>
76
+ <!-- /wp:spacer -->`,
77
+ layout: { x: 0, y: 200, width: 100, height: 100 },
78
+ },
79
+ {
80
+ name: 'Gallery',
81
+ html: `
82
+ <!-- wp:gallery {"linkTo":"none"} -->
83
+ <figure class="wp-block-gallery has-nested-images columns-default is-cropped"><!-- wp:image {"sizeSlug":"large","linkDestination":"none"} -->
84
+ <figure class="wp-block-image size-large"><img src="https://cldup.com/cXyG__fTLN.jpg" alt=""/></figure>
85
+ <!-- /wp:image -->
86
+
87
+ <!-- wp:image {"sizeSlug":"large","linkDestination":"none"} -->
88
+ <figure class="wp-block-image size-large"><img src="https://cldup.com/cXyG__fTLN.jpg" alt=""/></figure>
89
+ <!-- /wp:image --></figure>
90
+ <!-- /wp:gallery -->`,
91
+ layout: { x: 0, y: 300, width: 100, height: 100 },
92
+ nestedBlocks: [
93
+ { name: 'Image', layout: { x: 0, y: 300, width: 50, height: 50 } },
94
+ { name: 'Image', layout: { x: 50, y: 300, width: 50, height: 50 } },
95
+ ],
96
+ },
97
+ ];
98
+
99
+ describe( 'BlockDraggable', () => {
100
+ describe( 'drag mode', () => {
101
+ describe( 'Text block', () => {
102
+ it( 'enables drag mode when unselected', async () =>
103
+ withReanimatedTimer( async () => {
104
+ const screen = await initializeWithBlocksLayouts( BLOCKS );
105
+ const { getByA11yLabel } = screen;
106
+
107
+ // Start dragging from block's content
108
+ fireLongPress(
109
+ getByA11yLabel( /Paragraph Block\. Row 1/ ),
110
+ 'draggable-trigger-content'
111
+ );
112
+ expect( getDraggableChip( screen ) ).toBeVisible();
113
+
114
+ // "firePanGesture" finishes the dragging gesture
115
+ firePanGesture(
116
+ getByGestureTestId( 'block-draggable-wrapper' )
117
+ );
118
+ expect( getDraggableChip( screen ) ).not.toBeDefined();
119
+ } ) );
120
+
121
+ it( 'enables drag mode when selected', async () =>
122
+ withReanimatedTimer( async () => {
123
+ const screen = await initializeWithBlocksLayouts( BLOCKS );
124
+ const { getByA11yLabel } = screen;
125
+ const blockDraggableWrapper = getByGestureTestId(
126
+ 'block-draggable-wrapper'
127
+ );
128
+
129
+ const paragraphBlock = getByA11yLabel(
130
+ /Paragraph Block\. Row 1/
131
+ );
132
+ fireEvent.press( paragraphBlock );
133
+
134
+ // Start dragging from block's content
135
+ fireLongPress(
136
+ paragraphBlock,
137
+ 'draggable-trigger-content'
138
+ );
139
+ expect( getDraggableChip( screen ) ).toBeVisible();
140
+ // "firePanGesture" finishes the dragging gesture
141
+ firePanGesture( blockDraggableWrapper );
142
+ expect( getDraggableChip( screen ) ).not.toBeDefined();
143
+
144
+ // Start dragging from block's mobile toolbar
145
+ fireLongPress(
146
+ paragraphBlock,
147
+ 'draggable-trigger-mobile-toolbar'
148
+ );
149
+ expect( getDraggableChip( screen ) ).toBeVisible();
150
+ // "firePanGesture" finishes the dragging gesture
151
+ firePanGesture( blockDraggableWrapper );
152
+ expect( getDraggableChip( screen ) ).not.toBeDefined();
153
+ } ) );
154
+
155
+ it( 'does not enable drag mode when selected and editing text', async () =>
156
+ withReanimatedTimer( async () => {
157
+ const screen = await initializeWithBlocksLayouts( BLOCKS );
158
+ const { getByA11yLabel } = screen;
159
+
160
+ const paragraphBlock = getByA11yLabel(
161
+ /Paragraph Block\. Row 1/
162
+ );
163
+
164
+ // Select Paragraph block and start editing text
165
+ fireEvent.press( paragraphBlock );
166
+ fireEvent(
167
+ within( paragraphBlock ).getByPlaceholderText(
168
+ 'Start writing…'
169
+ ),
170
+ 'focus'
171
+ );
172
+
173
+ // Start dragging from block's content
174
+ fireLongPress(
175
+ paragraphBlock,
176
+ 'draggable-trigger-content',
177
+ { failed: true }
178
+ );
179
+ expect( getDraggableChip( screen ) ).not.toBeDefined();
180
+ // Check that no text input has been unfocused to confirm
181
+ // that editing text is still enabled.
182
+ expect(
183
+ TextInputState.blurTextInput
184
+ ).not.toHaveBeenCalled();
185
+ } ) );
186
+
187
+ it( 'finishes editing text and enables drag mode when long-pressing over a different block', async () =>
188
+ withReanimatedTimer( async () => {
189
+ const screen = await initializeWithBlocksLayouts( BLOCKS );
190
+ const { getByA11yLabel } = screen;
191
+
192
+ const paragraphBlock = getByA11yLabel(
193
+ /Paragraph Block\. Row 1/
194
+ );
195
+ const spacerBlock = getByA11yLabel(
196
+ /Spacer Block\. Row 3/
197
+ );
198
+
199
+ // Select Paragraph block and start editing text
200
+ fireEvent.press( paragraphBlock );
201
+ fireEvent(
202
+ within( paragraphBlock ).getByPlaceholderText(
203
+ 'Start writing…'
204
+ ),
205
+ 'focus'
206
+ );
207
+
208
+ // Start dragging from a different block's content
209
+ fireLongPress( spacerBlock, 'draggable-trigger-content' );
210
+ expect( getDraggableChip( screen ) ).toBeVisible();
211
+ // Check that any text input has been unfocused to confirm
212
+ // that editing text finished.
213
+ expect( TextInputState.blurTextInput ).toHaveBeenCalled();
214
+ } ) );
215
+ } );
216
+
217
+ describe( 'Media block', () => {
218
+ it( 'enables drag mode when unselected', async () =>
219
+ withReanimatedTimer( async () => {
220
+ const screen = await initializeWithBlocksLayouts( BLOCKS );
221
+ const { getAllByA11yLabel } = screen;
222
+
223
+ // We select the first Image block as the Gallery block
224
+ // also contains Image blocks.
225
+ const imageBlock = getAllByA11yLabel(
226
+ /Image Block\. Row 2/
227
+ )[ 0 ];
228
+ // Start dragging from block's content
229
+ fireLongPress( imageBlock, 'draggable-trigger-content' );
230
+ expect( getDraggableChip( screen ) ).toBeVisible();
231
+
232
+ // "firePanGesture" finishes the dragging gesture
233
+ firePanGesture(
234
+ getByGestureTestId( 'block-draggable-wrapper' )
235
+ );
236
+ expect( getDraggableChip( screen ) ).not.toBeDefined();
237
+ } ) );
238
+
239
+ it( 'enables drag mode when selected', async () =>
240
+ withReanimatedTimer( async () => {
241
+ const screen = await initializeWithBlocksLayouts( BLOCKS );
242
+ const { getAllByA11yLabel } = screen;
243
+ const blockDraggableWrapper = getByGestureTestId(
244
+ 'block-draggable-wrapper'
245
+ );
246
+
247
+ // We select the first Image block as the Gallery block
248
+ // also contains Image blocks.
249
+ const imageBlock = getAllByA11yLabel(
250
+ /Image Block\. Row 2/
251
+ )[ 0 ];
252
+ fireEvent.press( imageBlock );
253
+
254
+ // Start dragging from block's content
255
+ fireLongPress( imageBlock, 'draggable-trigger-content' );
256
+ expect( getDraggableChip( screen ) ).toBeVisible();
257
+ // "firePanGesture" finishes the dragging gesture
258
+ firePanGesture( blockDraggableWrapper );
259
+ expect( getDraggableChip( screen ) ).not.toBeDefined();
260
+
261
+ // Start dragging from block's mobile toolbar
262
+ fireLongPress(
263
+ imageBlock,
264
+ 'draggable-trigger-mobile-toolbar'
265
+ );
266
+ expect( getDraggableChip( screen ) ).toBeVisible();
267
+ // "firePanGesture" finishes the dragging gesture
268
+ firePanGesture( blockDraggableWrapper );
269
+ expect( getDraggableChip( screen ) ).not.toBeDefined();
270
+ } ) );
271
+ } );
272
+
273
+ describe( 'Nested block', () => {
274
+ it( 'enables drag mode when unselected', async () =>
275
+ withReanimatedTimer( async () => {
276
+ const screen = await initializeWithBlocksLayouts( BLOCKS );
277
+ const { getByA11yLabel } = screen;
278
+
279
+ // Start dragging from block's content, specifically the first
280
+ // trigger index, which corresponds to the Gallery block content.
281
+ fireLongPress(
282
+ getByA11yLabel( /Gallery Block\. Row 4/ ),
283
+ 'draggable-trigger-content',
284
+ { triggerIndex: 0 }
285
+ );
286
+ expect( getDraggableChip( screen ) ).toBeVisible();
287
+
288
+ // "firePanGesture" finishes the dragging gesture
289
+ firePanGesture(
290
+ getByGestureTestId( 'block-draggable-wrapper' )
291
+ );
292
+ expect( getDraggableChip( screen ) ).not.toBeDefined();
293
+ } ) );
294
+
295
+ it( 'enables drag mode when selected', async () =>
296
+ withReanimatedTimer( async () => {
297
+ const screen = await initializeWithBlocksLayouts( BLOCKS );
298
+ const { getByA11yLabel } = screen;
299
+ const blockDraggableWrapper = getByGestureTestId(
300
+ 'block-draggable-wrapper'
301
+ );
302
+
303
+ const galleryBlock = getByA11yLabel(
304
+ /Gallery Block\. Row 4/
305
+ );
306
+ await waitForStoreResolvers( () =>
307
+ fireEvent.press( galleryBlock )
308
+ );
309
+
310
+ // Start dragging from block's content, specifically the first
311
+ // trigger index, which corresponds to the Gallery block content.
312
+ fireLongPress( galleryBlock, 'draggable-trigger-content', {
313
+ triggerIndex: 0,
314
+ } );
315
+ expect( getDraggableChip( screen ) ).toBeVisible();
316
+ // "firePanGesture" finishes the dragging gesture
317
+ firePanGesture( blockDraggableWrapper );
318
+ expect( getDraggableChip( screen ) ).not.toBeDefined();
319
+
320
+ // Start dragging from block's mobile toolbar
321
+ fireLongPress(
322
+ galleryBlock,
323
+ 'draggable-trigger-mobile-toolbar'
324
+ );
325
+ expect( getDraggableChip( screen ) ).toBeVisible();
326
+ // "firePanGesture" finishes the dragging gesture
327
+ firePanGesture( blockDraggableWrapper );
328
+ expect( getDraggableChip( screen ) ).not.toBeDefined();
329
+ } ) );
330
+
331
+ it( 'enables drag mode when nested block is selected', async () =>
332
+ withReanimatedTimer( async () => {
333
+ const screen = await initializeWithBlocksLayouts( BLOCKS );
334
+ const { getByA11yLabel } = screen;
335
+ const blockDraggableWrapper = getByGestureTestId(
336
+ 'block-draggable-wrapper'
337
+ );
338
+
339
+ const galleryBlock = getByA11yLabel(
340
+ /Gallery Block\. Row 4/
341
+ );
342
+ const galleryItem = within( galleryBlock ).getByA11yLabel(
343
+ /Image Block\. Row 2/
344
+ );
345
+ fireEvent.press( galleryBlock );
346
+ fireEvent.press( galleryItem );
347
+
348
+ // Start dragging from nested block's content
349
+ fireLongPress( galleryItem, 'draggable-trigger-content' );
350
+ expect( getDraggableChip( screen ) ).toBeVisible();
351
+ // "firePanGesture" finishes the dragging gesture
352
+ firePanGesture( blockDraggableWrapper );
353
+ expect( getDraggableChip( screen ) ).not.toBeDefined();
354
+
355
+ // After dropping the block, the gallery item gets automatically selected.
356
+ // Hence, we have to select the gallery item again.
357
+ fireEvent.press( galleryItem );
358
+
359
+ // Start dragging from nested block's mobile toolbar
360
+ fireLongPress(
361
+ galleryItem,
362
+ 'draggable-trigger-mobile-toolbar'
363
+ );
364
+ expect( getDraggableChip( screen ) ).toBeVisible();
365
+ // "firePanGesture" finishes the dragging gesture
366
+ firePanGesture( blockDraggableWrapper );
367
+ expect( getDraggableChip( screen ) ).not.toBeDefined();
368
+ } ) );
369
+ } );
370
+
371
+ describe( 'Other block', () => {
372
+ it( 'enables drag mode when unselected', async () =>
373
+ withReanimatedTimer( async () => {
374
+ const screen = await initializeWithBlocksLayouts( BLOCKS );
375
+ const { getByA11yLabel } = screen;
376
+
377
+ // Start dragging from block's content
378
+ fireLongPress(
379
+ getByA11yLabel( /Spacer Block\. Row 3/ ),
380
+ 'draggable-trigger-content'
381
+ );
382
+ expect( getDraggableChip( screen ) ).toBeVisible();
383
+
384
+ // "firePanGesture" finishes the dragging gesture
385
+ firePanGesture(
386
+ getByGestureTestId( 'block-draggable-wrapper' )
387
+ );
388
+ expect( getDraggableChip( screen ) ).not.toBeDefined();
389
+ } ) );
390
+
391
+ it( 'enables drag mode when selected', async () =>
392
+ withReanimatedTimer( async () => {
393
+ const screen = await initializeWithBlocksLayouts( BLOCKS );
394
+ const { getByA11yLabel } = screen;
395
+ const blockDraggableWrapper = getByGestureTestId(
396
+ 'block-draggable-wrapper'
397
+ );
398
+
399
+ const spacerBlock = getByA11yLabel(
400
+ /Spacer Block\. Row 3/
401
+ );
402
+ await waitForStoreResolvers( () =>
403
+ fireEvent.press( spacerBlock )
404
+ );
405
+
406
+ // Start dragging from block's content
407
+ fireLongPress( spacerBlock, 'draggable-trigger-content' );
408
+ expect( getDraggableChip( screen ) ).toBeVisible();
409
+ // "firePanGesture" finishes the dragging gesture
410
+ firePanGesture( blockDraggableWrapper );
411
+ expect( getDraggableChip( screen ) ).not.toBeDefined();
412
+
413
+ // Start dragging from block's mobile toolbar
414
+ fireLongPress(
415
+ spacerBlock,
416
+ 'draggable-trigger-mobile-toolbar'
417
+ );
418
+ expect( getDraggableChip( screen ) ).toBeVisible();
419
+ // "firePanGesture" finishes the dragging gesture
420
+ firePanGesture( blockDraggableWrapper );
421
+ expect( getDraggableChip( screen ) ).not.toBeDefined();
422
+ } ) );
423
+ } );
424
+ } );
425
+
426
+ it( 'moves blocks', async () =>
427
+ withReanimatedTimer( async () => {
428
+ const { getByA11yLabel } = await initializeWithBlocksLayouts(
429
+ BLOCKS
430
+ );
431
+ const blockDraggableWrapper = getByGestureTestId(
432
+ 'block-draggable-wrapper'
433
+ );
434
+
435
+ expect( getEditorHtml() ).toMatchSnapshot( 'Initial order' );
436
+
437
+ // Move Paragraph block from first to second position
438
+ fireLongPress(
439
+ getByA11yLabel( /Paragraph Block\. Row 1/ ),
440
+ 'draggable-trigger-content'
441
+ );
442
+ firePanGesture( blockDraggableWrapper, [
443
+ {
444
+ id: TOUCH_EVENT_ID,
445
+ eventType: TouchEventType.TOUCHES_DOWN,
446
+ x: 0,
447
+ y: 0,
448
+ },
449
+ {
450
+ id: TOUCH_EVENT_ID,
451
+ eventType: TouchEventType.TOUCHES_MOVE,
452
+ x: 0,
453
+ // Dropping position is in the second half of the second block's height.
454
+ y: 180,
455
+ },
456
+ ] );
457
+ // Draggable Pan gesture uses the Gesture state manager to manually
458
+ // activate the gesture. Since this not available in tests, the library
459
+ // displays a warning message.
460
+ expect( console ).toHaveWarnedWith(
461
+ '[react-native-gesture-handler] You have to use react-native-reanimated in order to control the state of the gesture.'
462
+ );
463
+ expect( getEditorHtml() ).toMatchSnapshot(
464
+ 'Paragraph block moved from first to second position'
465
+ );
466
+
467
+ // Move Spacer block from third to first position
468
+ fireLongPress(
469
+ getByA11yLabel( /Spacer Block\. Row 3/ ),
470
+ 'draggable-trigger-content'
471
+ );
472
+ firePanGesture( blockDraggableWrapper, [
473
+ {
474
+ id: TOUCH_EVENT_ID,
475
+ eventType: TouchEventType.TOUCHES_DOWN,
476
+ x: 0,
477
+ y: 250,
478
+ },
479
+ {
480
+ id: TOUCH_EVENT_ID,
481
+ eventType: TouchEventType.TOUCHES_MOVE,
482
+ x: 0,
483
+ y: 0,
484
+ },
485
+ ] );
486
+ // Draggable Pan gesture uses the Gesture state manager to manually
487
+ // activate the gesture. Since this not available in tests, the library
488
+ // displays a warning message.
489
+ expect( console ).toHaveWarnedWith(
490
+ '[react-native-gesture-handler] You have to use react-native-reanimated in order to control the state of the gesture.'
491
+ );
492
+ expect( getEditorHtml() ).toMatchSnapshot(
493
+ 'Spacer block moved from third to first position'
494
+ );
495
+ } ) );
496
+ } );
@@ -263,6 +263,7 @@ class BlockListBlock extends Component {
263
263
  clientId={ clientId }
264
264
  draggingClientId={ draggingClientId }
265
265
  enabled={ draggingEnabled }
266
+ testID="draggable-trigger-content"
266
267
  >
267
268
  { () =>
268
269
  isValid ? (
@@ -6,7 +6,7 @@ import classnames from 'classnames';
6
6
  /**
7
7
  * WordPress dependencies
8
8
  */
9
- import { AsyncModeProvider, useSelect } from '@wordpress/data';
9
+ import { AsyncModeProvider, useSelect, useDispatch } from '@wordpress/data';
10
10
  import { useViewportMatch, useMergeRefs } from '@wordpress/compose';
11
11
  import { createContext, useState, useMemo } from '@wordpress/element';
12
12
 
@@ -48,6 +48,23 @@ function Root( { className, ...settings } ) {
48
48
  },
49
49
  []
50
50
  );
51
+ const { setBlockVisibility } = useDispatch( blockEditorStore );
52
+ const intersectionObserver = useMemo( () => {
53
+ const { IntersectionObserver: Observer } = window;
54
+
55
+ if ( ! Observer ) {
56
+ return;
57
+ }
58
+
59
+ return new Observer( ( entries ) => {
60
+ const updates = {};
61
+ for ( const entry of entries ) {
62
+ const clientId = entry.target.getAttribute( 'data-block' );
63
+ updates[ clientId ] = entry.isIntersecting;
64
+ }
65
+ setBlockVisibility( updates );
66
+ } );
67
+ }, [] );
51
68
  const innerBlocksProps = useInnerBlocksProps(
52
69
  {
53
70
  ref: useMergeRefs( [
@@ -65,7 +82,9 @@ function Root( { className, ...settings } ) {
65
82
  );
66
83
  return (
67
84
  <elementContext.Provider value={ element }>
68
- <div { ...innerBlocksProps } />
85
+ <IntersectionObserver.Provider value={ intersectionObserver }>
86
+ <div { ...innerBlocksProps } />
87
+ </IntersectionObserver.Provider>
69
88
  </elementContext.Provider>
70
89
  );
71
90
  }
@@ -90,34 +109,17 @@ function Items( {
90
109
  __experimentalAppenderTagName,
91
110
  __experimentalLayout: layout = defaultLayout,
92
111
  } ) {
93
- const [ intersectingBlocks, setIntersectingBlocks ] = useState( new Set() );
94
- const intersectionObserver = useMemo( () => {
95
- const { IntersectionObserver: Observer } = window;
96
-
97
- if ( ! Observer ) {
98
- return;
99
- }
100
-
101
- return new Observer( ( entries ) => {
102
- setIntersectingBlocks( ( oldIntersectingBlocks ) => {
103
- const newIntersectingBlocks = new Set( oldIntersectingBlocks );
104
- for ( const entry of entries ) {
105
- const clientId = entry.target.getAttribute( 'data-block' );
106
- const action = entry.isIntersecting ? 'add' : 'delete';
107
- newIntersectingBlocks[ action ]( clientId );
108
- }
109
- return newIntersectingBlocks;
110
- } );
111
- } );
112
- }, [ setIntersectingBlocks ] );
113
- const { order, selectedBlocks } = useSelect(
112
+ const { order, selectedBlocks, visibleBlocks } = useSelect(
114
113
  ( select ) => {
115
- const { getBlockOrder, getSelectedBlockClientIds } = select(
116
- blockEditorStore
117
- );
114
+ const {
115
+ getBlockOrder,
116
+ getSelectedBlockClientIds,
117
+ __unstableGetVisibleBlocks,
118
+ } = select( blockEditorStore );
118
119
  return {
119
120
  order: getBlockOrder( rootClientId ),
120
121
  selectedBlocks: getSelectedBlockClientIds(),
122
+ visibleBlocks: __unstableGetVisibleBlocks(),
121
123
  };
122
124
  },
123
125
  [ rootClientId ]
@@ -125,24 +127,22 @@ function Items( {
125
127
 
126
128
  return (
127
129
  <LayoutProvider value={ layout }>
128
- <IntersectionObserver.Provider value={ intersectionObserver }>
129
- { order.map( ( clientId ) => (
130
- <AsyncModeProvider
131
- key={ clientId }
132
- value={
133
- // Only provide data asynchronously if the block is
134
- // not visible and not selected.
135
- ! intersectingBlocks.has( clientId ) &&
136
- ! selectedBlocks.includes( clientId )
137
- }
138
- >
139
- <BlockListBlock
140
- rootClientId={ rootClientId }
141
- clientId={ clientId }
142
- />
143
- </AsyncModeProvider>
144
- ) ) }
145
- </IntersectionObserver.Provider>
130
+ { order.map( ( clientId ) => (
131
+ <AsyncModeProvider
132
+ key={ clientId }
133
+ value={
134
+ // Only provide data asynchronously if the block is
135
+ // not visible and not selected.
136
+ ! visibleBlocks.has( clientId ) &&
137
+ ! selectedBlocks.includes( clientId )
138
+ }
139
+ >
140
+ <BlockListBlock
141
+ rootClientId={ rootClientId }
142
+ clientId={ clientId }
143
+ />
144
+ </AsyncModeProvider>
145
+ ) ) }
146
146
  { order.length < 1 && placeholder }
147
147
  <BlockListAppender
148
148
  tagName={ __experimentalAppenderTagName }
@@ -78,6 +78,7 @@ const BlockMobileToolbar = ( {
78
78
  <BlockDraggable
79
79
  clientId={ clientId }
80
80
  draggingClientId={ draggingClientId }
81
+ testID="draggable-trigger-mobile-toolbar"
81
82
  >
82
83
  { () => <View style={ styles.spacer } /> }
83
84
  </BlockDraggable>
@@ -35,6 +35,8 @@ Array [
35
35
  >
36
36
  <View
37
37
  collapsable={false}
38
+ handlerTag={3}
39
+ handlerType="LongPressGestureHandler"
38
40
  onGestureHandlerEvent={[Function]}
39
41
  onGestureHandlerStateChange={[Function]}
40
42
  style={
@@ -93,6 +95,8 @@ Array [
93
95
  >
94
96
  <View
95
97
  collapsable={false}
98
+ handlerTag={4}
99
+ handlerType="LongPressGestureHandler"
96
100
  onGestureHandlerEvent={[Function]}
97
101
  onGestureHandlerStateChange={[Function]}
98
102
  style={