@wordpress/block-library 8.26.0 → 8.27.1

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 (275) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/avatar/edit.js +2 -2
  3. package/build/avatar/edit.js.map +1 -1
  4. package/build/block/edit.js +76 -13
  5. package/build/block/edit.js.map +1 -1
  6. package/build/block/{v1/edit.native.js → edit.native.js} +4 -4
  7. package/build/block/edit.native.js.map +1 -0
  8. package/build/block/index.js +5 -3
  9. package/build/block/index.js.map +1 -1
  10. package/build/button/edit.js +24 -6
  11. package/build/button/edit.js.map +1 -1
  12. package/build/button/index.js +1 -0
  13. package/build/button/index.js.map +1 -1
  14. package/build/button/save.js +3 -1
  15. package/build/button/save.js.map +1 -1
  16. package/build/cover/edit/index.js +2 -1
  17. package/build/cover/edit/index.js.map +1 -1
  18. package/build/cover/edit/inspector-controls.js +13 -1
  19. package/build/cover/edit/inspector-controls.js.map +1 -1
  20. package/build/cover/edit.native.js +1 -0
  21. package/build/cover/edit.native.js.map +1 -1
  22. package/build/cover/index.js +3 -0
  23. package/build/cover/index.js.map +1 -1
  24. package/build/embed/edit.js +3 -2
  25. package/build/embed/edit.js.map +1 -1
  26. package/build/file/index.js +0 -1
  27. package/build/file/index.js.map +1 -1
  28. package/build/footnotes/edit.js +2 -1
  29. package/build/footnotes/edit.js.map +1 -1
  30. package/build/footnotes/format.js +17 -19
  31. package/build/footnotes/format.js.map +1 -1
  32. package/build/group/index.js +1 -0
  33. package/build/group/index.js.map +1 -1
  34. package/build/heading/edit.js +2 -1
  35. package/build/heading/edit.js.map +1 -1
  36. package/build/heading/edit.native.js +141 -0
  37. package/build/heading/edit.native.js.map +1 -0
  38. package/build/heading/index.js +1 -0
  39. package/build/heading/index.js.map +1 -1
  40. package/build/image/edit.js +8 -4
  41. package/build/image/edit.js.map +1 -1
  42. package/build/image/image.js +33 -7
  43. package/build/image/image.js.map +1 -1
  44. package/build/image/index.js +6 -3
  45. package/build/image/index.js.map +1 -1
  46. package/build/more/index.js +4 -0
  47. package/build/more/index.js.map +1 -1
  48. package/build/navigation/edit/index.js +2 -2
  49. package/build/navigation/edit/index.js.map +1 -1
  50. package/build/navigation/index.js +0 -1
  51. package/build/navigation/index.js.map +1 -1
  52. package/build/paragraph/edit.js +2 -1
  53. package/build/paragraph/edit.js.map +1 -1
  54. package/build/paragraph/index.js +1 -2
  55. package/build/paragraph/index.js.map +1 -1
  56. package/build/paragraph/transforms.js +1 -2
  57. package/build/paragraph/transforms.js.map +1 -1
  58. package/build/post-content/edit.js +2 -2
  59. package/build/post-content/edit.js.map +1 -1
  60. package/build/post-date/edit.js +1 -1
  61. package/build/post-date/edit.js.map +1 -1
  62. package/build/post-navigation-link/edit.js +43 -2
  63. package/build/post-navigation-link/edit.js.map +1 -1
  64. package/build/post-navigation-link/index.js +8 -0
  65. package/build/post-navigation-link/index.js.map +1 -1
  66. package/build/pullquote/index.js +4 -0
  67. package/build/pullquote/index.js.map +1 -1
  68. package/build/query/edit/inspector-controls/index.js +3 -3
  69. package/build/query/edit/inspector-controls/index.js.map +1 -1
  70. package/build/query/edit/query-content.js +2 -2
  71. package/build/query/edit/query-content.js.map +1 -1
  72. package/build/query/edit/query-placeholder.js +6 -7
  73. package/build/query/edit/query-placeholder.js.map +1 -1
  74. package/build/query/index.js +1 -2
  75. package/build/query/index.js.map +1 -1
  76. package/build/query/variations.js +8 -1
  77. package/build/query/variations.js.map +1 -1
  78. package/build/query/view.js +31 -12
  79. package/build/query/view.js.map +1 -1
  80. package/build/search/index.js +0 -1
  81. package/build/search/index.js.map +1 -1
  82. package/build/table-of-contents/hooks.js +2 -2
  83. package/build/table-of-contents/hooks.js.map +1 -1
  84. package/build/template-part/edit/advanced-controls.js +1 -4
  85. package/build/template-part/edit/advanced-controls.js.map +1 -1
  86. package/build/template-part/edit/index.js +39 -17
  87. package/build/template-part/edit/index.js.map +1 -1
  88. package/build/video/edit.native.js +7 -2
  89. package/build/video/edit.native.js.map +1 -1
  90. package/build/video/transforms.js +17 -0
  91. package/build/video/transforms.js.map +1 -1
  92. package/build-module/avatar/edit.js +2 -2
  93. package/build-module/avatar/edit.js.map +1 -1
  94. package/build-module/block/edit.js +76 -13
  95. package/build-module/block/edit.js.map +1 -1
  96. package/build-module/block/{v1/edit.native.js → edit.native.js} +3 -3
  97. package/build-module/block/edit.native.js.map +1 -0
  98. package/build-module/block/index.js +5 -3
  99. package/build-module/block/index.js.map +1 -1
  100. package/build-module/button/edit.js +25 -7
  101. package/build-module/button/edit.js.map +1 -1
  102. package/build-module/button/index.js +1 -0
  103. package/build-module/button/index.js.map +1 -1
  104. package/build-module/button/save.js +4 -2
  105. package/build-module/button/save.js.map +1 -1
  106. package/build-module/cover/edit/index.js +2 -1
  107. package/build-module/cover/edit/index.js.map +1 -1
  108. package/build-module/cover/edit/inspector-controls.js +14 -2
  109. package/build-module/cover/edit/inspector-controls.js.map +1 -1
  110. package/build-module/cover/edit.native.js +1 -0
  111. package/build-module/cover/edit.native.js.map +1 -1
  112. package/build-module/cover/index.js +3 -0
  113. package/build-module/cover/index.js.map +1 -1
  114. package/build-module/embed/edit.js +3 -2
  115. package/build-module/embed/edit.js.map +1 -1
  116. package/build-module/file/index.js +0 -1
  117. package/build-module/file/index.js.map +1 -1
  118. package/build-module/footnotes/edit.js +2 -1
  119. package/build-module/footnotes/edit.js.map +1 -1
  120. package/build-module/footnotes/format.js +17 -19
  121. package/build-module/footnotes/format.js.map +1 -1
  122. package/build-module/group/index.js +1 -0
  123. package/build-module/group/index.js.map +1 -1
  124. package/build-module/heading/edit.js +3 -2
  125. package/build-module/heading/edit.js.map +1 -1
  126. package/build-module/heading/edit.native.js +132 -0
  127. package/build-module/heading/edit.native.js.map +1 -0
  128. package/build-module/heading/index.js +1 -0
  129. package/build-module/heading/index.js.map +1 -1
  130. package/build-module/image/edit.js +9 -5
  131. package/build-module/image/edit.js.map +1 -1
  132. package/build-module/image/image.js +33 -7
  133. package/build-module/image/image.js.map +1 -1
  134. package/build-module/image/index.js +6 -3
  135. package/build-module/image/index.js.map +1 -1
  136. package/build-module/more/index.js +4 -0
  137. package/build-module/more/index.js.map +1 -1
  138. package/build-module/navigation/edit/index.js +1 -1
  139. package/build-module/navigation/edit/index.js.map +1 -1
  140. package/build-module/navigation/index.js +0 -1
  141. package/build-module/navigation/index.js.map +1 -1
  142. package/build-module/paragraph/edit.js +3 -2
  143. package/build-module/paragraph/edit.js.map +1 -1
  144. package/build-module/paragraph/index.js +1 -2
  145. package/build-module/paragraph/index.js.map +1 -1
  146. package/build-module/paragraph/transforms.js +1 -2
  147. package/build-module/paragraph/transforms.js.map +1 -1
  148. package/build-module/post-content/edit.js +1 -1
  149. package/build-module/post-content/edit.js.map +1 -1
  150. package/build-module/post-date/edit.js +1 -1
  151. package/build-module/post-date/edit.js.map +1 -1
  152. package/build-module/post-navigation-link/edit.js +44 -3
  153. package/build-module/post-navigation-link/edit.js.map +1 -1
  154. package/build-module/post-navigation-link/index.js +8 -0
  155. package/build-module/post-navigation-link/index.js.map +1 -1
  156. package/build-module/pullquote/index.js +4 -0
  157. package/build-module/pullquote/index.js.map +1 -1
  158. package/build-module/query/edit/inspector-controls/index.js +4 -4
  159. package/build-module/query/edit/inspector-controls/index.js.map +1 -1
  160. package/build-module/query/edit/query-content.js +2 -2
  161. package/build-module/query/edit/query-content.js.map +1 -1
  162. package/build-module/query/edit/query-placeholder.js +7 -8
  163. package/build-module/query/edit/query-placeholder.js.map +1 -1
  164. package/build-module/query/index.js +1 -2
  165. package/build-module/query/index.js.map +1 -1
  166. package/build-module/query/variations.js +8 -1
  167. package/build-module/query/variations.js.map +1 -1
  168. package/build-module/query/view.js +30 -9
  169. package/build-module/query/view.js.map +1 -1
  170. package/build-module/search/index.js +0 -1
  171. package/build-module/search/index.js.map +1 -1
  172. package/build-module/table-of-contents/hooks.js +2 -2
  173. package/build-module/table-of-contents/hooks.js.map +1 -1
  174. package/build-module/template-part/edit/advanced-controls.js +1 -4
  175. package/build-module/template-part/edit/advanced-controls.js.map +1 -1
  176. package/build-module/template-part/edit/index.js +38 -16
  177. package/build-module/template-part/edit/index.js.map +1 -1
  178. package/build-module/video/edit.native.js +7 -2
  179. package/build-module/video/edit.native.js.map +1 -1
  180. package/build-module/video/transforms.js +17 -0
  181. package/build-module/video/transforms.js.map +1 -1
  182. package/build-style/common-rtl.css +4 -2
  183. package/build-style/common.css +4 -2
  184. package/build-style/cover/style-rtl.css +2 -4
  185. package/build-style/cover/style.css +2 -4
  186. package/build-style/editor-rtl.css +6 -4
  187. package/build-style/editor.css +6 -4
  188. package/build-style/gallery/style-rtl.css +2 -4
  189. package/build-style/gallery/style.css +2 -4
  190. package/build-style/image/editor-rtl.css +6 -0
  191. package/build-style/image/editor.css +6 -0
  192. package/build-style/page-list/editor-rtl.css +0 -4
  193. package/build-style/page-list/editor.css +0 -4
  194. package/build-style/pullquote/style-rtl.css +10 -1
  195. package/build-style/pullquote/style.css +10 -1
  196. package/build-style/search/style-rtl.css +2 -1
  197. package/build-style/search/style.css +2 -1
  198. package/build-style/style-rtl.css +20 -13
  199. package/build-style/style.css +20 -13
  200. package/build-style/video/style-rtl.css +1 -2
  201. package/build-style/video/style.css +1 -2
  202. package/package.json +34 -32
  203. package/src/avatar/edit.js +16 -18
  204. package/src/block/block.json +3 -0
  205. package/src/block/edit.js +102 -20
  206. package/src/block/{v1/edit.native.js → edit.native.js} +4 -4
  207. package/src/block/index.js +2 -3
  208. package/src/block/index.php +3 -31
  209. package/src/button/block.json +1 -0
  210. package/src/button/edit.js +76 -43
  211. package/src/button/save.js +3 -0
  212. package/src/buttons/test/__snapshots__/edit.native.js.snap +6 -0
  213. package/src/buttons/test/edit.native.js +49 -0
  214. package/src/cover/block.json +3 -0
  215. package/src/cover/edit/index.js +2 -1
  216. package/src/cover/edit/inspector-controls.js +14 -1
  217. package/src/cover/edit.native.js +1 -0
  218. package/src/cover/style.scss +2 -3
  219. package/src/embed/edit.js +3 -2
  220. package/src/file/block.json +0 -1
  221. package/src/file/index.php +11 -57
  222. package/src/footnotes/edit.js +2 -1
  223. package/src/footnotes/format.js +34 -31
  224. package/src/footnotes/index.php +20 -11
  225. package/src/gallery/index.php +0 -3
  226. package/src/group/block.json +1 -0
  227. package/src/heading/block.json +1 -0
  228. package/src/heading/edit.js +18 -14
  229. package/src/heading/edit.native.js +144 -0
  230. package/src/image/block.json +7 -3
  231. package/src/image/edit.js +19 -6
  232. package/src/image/editor.scss +6 -1
  233. package/src/image/image.js +101 -42
  234. package/src/image/index.js +6 -0
  235. package/src/image/index.php +14 -51
  236. package/src/more/index.js +6 -0
  237. package/src/navigation/block.json +0 -1
  238. package/src/navigation/edit/index.js +2 -2
  239. package/src/navigation/index.php +777 -28
  240. package/src/navigation-link/index.php +78 -16
  241. package/src/page-list/editor.scss +0 -4
  242. package/src/paragraph/block.json +1 -2
  243. package/src/paragraph/edit.js +23 -19
  244. package/src/post-content/edit.js +2 -2
  245. package/src/post-date/edit.js +38 -33
  246. package/src/post-navigation-link/block.json +8 -0
  247. package/src/post-navigation-link/edit.js +63 -1
  248. package/src/post-navigation-link/index.php +17 -3
  249. package/src/post-terms/index.php +13 -4
  250. package/src/pullquote/block.json +4 -0
  251. package/src/pullquote/style.scss +13 -1
  252. package/src/query/block.json +1 -2
  253. package/src/query/edit/inspector-controls/index.js +137 -146
  254. package/src/query/edit/query-content.js +9 -7
  255. package/src/query/edit/query-placeholder.js +11 -11
  256. package/src/query/index.php +33 -71
  257. package/src/query/variations.js +4 -0
  258. package/src/query/view.js +24 -19
  259. package/src/search/block.json +0 -1
  260. package/src/search/index.php +18 -36
  261. package/src/table-of-contents/hooks.js +2 -2
  262. package/src/template-part/edit/advanced-controls.js +2 -3
  263. package/src/template-part/edit/index.js +77 -50
  264. package/src/template-part/index.php +2 -2
  265. package/src/video/edit.native.js +5 -2
  266. package/src/video/test/edit.native.js +38 -0
  267. package/src/video/transforms.js +32 -0
  268. package/tsconfig.json +1 -0
  269. package/build/block/v1/edit.js +0 -116
  270. package/build/block/v1/edit.js.map +0 -1
  271. package/build/block/v1/edit.native.js.map +0 -1
  272. package/build-module/block/v1/edit.js +0 -108
  273. package/build-module/block/v1/edit.js.map +0 -1
  274. package/build-module/block/v1/edit.native.js.map +0 -1
  275. package/src/block/v1/edit.js +0 -163
@@ -12,10 +12,7 @@ import {
12
12
  __experimentalToolsPanelItem as ToolsPanelItem,
13
13
  } from '@wordpress/components';
14
14
  import { __ } from '@wordpress/i18n';
15
- import {
16
- InspectorControls,
17
- privateApis as blockEditorPrivateApis,
18
- } from '@wordpress/block-editor';
15
+ import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
19
16
  import { debounce } from '@wordpress/compose';
20
17
  import { useEffect, useState, useCallback } from '@wordpress/element';
21
18
 
@@ -138,156 +135,150 @@ export default function QueryInspectorControls( props ) {
138
135
  <CreateNewPostLink { ...props } />
139
136
  </BlockInfo>
140
137
  { showSettingsPanel && (
141
- <InspectorControls>
142
- <PanelBody title={ __( 'Settings' ) }>
143
- { showInheritControl && (
144
- <ToggleControl
145
- __nextHasNoMarginBottom
146
- label={ __( 'Inherit query from template' ) }
147
- help={ __(
148
- 'Toggle to use the global query context that is set with the current template, such as an archive or search. Disable to customize the settings independently.'
149
- ) }
150
- checked={ !! inherit }
151
- onChange={ ( value ) =>
152
- setQuery( { inherit: !! value } )
153
- }
154
- />
155
- ) }
156
- { showPostTypeControl && (
157
- <SelectControl
138
+ <PanelBody title={ __( 'Settings' ) }>
139
+ { showInheritControl && (
140
+ <ToggleControl
141
+ __nextHasNoMarginBottom
142
+ label={ __( 'Inherit query from template' ) }
143
+ help={ __(
144
+ 'Toggle to use the global query context that is set with the current template, such as an archive or search. Disable to customize the settings independently.'
145
+ ) }
146
+ checked={ !! inherit }
147
+ onChange={ ( value ) =>
148
+ setQuery( { inherit: !! value } )
149
+ }
150
+ />
151
+ ) }
152
+ { showPostTypeControl && (
153
+ <SelectControl
154
+ __nextHasNoMarginBottom
155
+ options={ postTypesSelectOptions }
156
+ value={ postType }
157
+ label={ __( 'Post type' ) }
158
+ onChange={ onPostTypeChange }
159
+ help={ __(
160
+ 'WordPress contains different types of content and they are divided into collections called “Post types”. By default there are a few different ones such as blog posts and pages, but plugins could add more.'
161
+ ) }
162
+ />
163
+ ) }
164
+ { showColumnsControl && (
165
+ <>
166
+ <RangeControl
158
167
  __nextHasNoMarginBottom
159
- options={ postTypesSelectOptions }
160
- value={ postType }
161
- label={ __( 'Post type' ) }
162
- onChange={ onPostTypeChange }
163
- help={ __(
164
- 'WordPress contains different types of content and they are divided into collections called “Post types”. By default there are a few different ones such as blog posts and pages, but plugins could add more.'
165
- ) }
166
- />
167
- ) }
168
- { showColumnsControl && (
169
- <>
170
- <RangeControl
171
- __nextHasNoMarginBottom
172
- label={ __( 'Columns' ) }
173
- value={ displayLayout.columns }
174
- onChange={ ( value ) =>
175
- setDisplayLayout( {
176
- columns: value,
177
- } )
178
- }
179
- min={ 2 }
180
- max={ Math.max( 6, displayLayout.columns ) }
181
- />
182
- { displayLayout.columns > 6 && (
183
- <Notice
184
- status="warning"
185
- isDismissible={ false }
186
- >
187
- { __(
188
- 'This column count exceeds the recommended amount and may cause visual breakage.'
189
- ) }
190
- </Notice>
191
- ) }
192
- </>
193
- ) }
194
- { showOrderControl && (
195
- <OrderControl
196
- { ...{ order, orderBy } }
197
- onChange={ setQuery }
198
- />
199
- ) }
200
- { showStickyControl && (
201
- <StickyControl
202
- value={ sticky }
168
+ label={ __( 'Columns' ) }
169
+ value={ displayLayout.columns }
203
170
  onChange={ ( value ) =>
204
- setQuery( { sticky: value } )
171
+ setDisplayLayout( {
172
+ columns: value,
173
+ } )
205
174
  }
175
+ min={ 2 }
176
+ max={ Math.max( 6, displayLayout.columns ) }
206
177
  />
207
- ) }
208
- <EnhancedPaginationControl
209
- enhancedPagination={ enhancedPagination }
210
- setAttributes={ setAttributes }
211
- clientId={ clientId }
178
+ { displayLayout.columns > 6 && (
179
+ <Notice
180
+ status="warning"
181
+ isDismissible={ false }
182
+ >
183
+ { __(
184
+ 'This column count exceeds the recommended amount and may cause visual breakage.'
185
+ ) }
186
+ </Notice>
187
+ ) }
188
+ </>
189
+ ) }
190
+ { showOrderControl && (
191
+ <OrderControl
192
+ { ...{ order, orderBy } }
193
+ onChange={ setQuery }
194
+ />
195
+ ) }
196
+ { showStickyControl && (
197
+ <StickyControl
198
+ value={ sticky }
199
+ onChange={ ( value ) =>
200
+ setQuery( { sticky: value } )
201
+ }
212
202
  />
213
- </PanelBody>
214
- </InspectorControls>
203
+ ) }
204
+ <EnhancedPaginationControl
205
+ enhancedPagination={ enhancedPagination }
206
+ setAttributes={ setAttributes }
207
+ clientId={ clientId }
208
+ />
209
+ </PanelBody>
215
210
  ) }
216
211
  { ! inherit && showFiltersPanel && (
217
- <InspectorControls>
218
- <ToolsPanel
219
- className="block-library-query-toolspanel__filters"
220
- label={ __( 'Filters' ) }
221
- resetAll={ () => {
222
- setQuery( {
223
- author: '',
224
- parents: [],
225
- search: '',
226
- taxQuery: null,
227
- } );
228
- setQuerySearch( '' );
229
- } }
230
- dropdownMenuProps={ TOOLSPANEL_DROPDOWNMENU_PROPS }
231
- >
232
- { showTaxControl && (
233
- <ToolsPanelItem
234
- label={ __( 'Taxonomies' ) }
235
- hasValue={ () =>
236
- Object.values( taxQuery || {} ).some(
237
- ( terms ) => !! terms.length
238
- )
239
- }
240
- onDeselect={ () =>
241
- setQuery( { taxQuery: null } )
242
- }
243
- >
244
- <TaxonomyControls
245
- onChange={ setQuery }
246
- query={ query }
247
- />
248
- </ToolsPanelItem>
249
- ) }
250
- { showAuthorControl && (
251
- <ToolsPanelItem
252
- hasValue={ () => !! authorIds }
253
- label={ __( 'Authors' ) }
254
- onDeselect={ () => setQuery( { author: '' } ) }
255
- >
256
- <AuthorControl
257
- value={ authorIds }
258
- onChange={ setQuery }
259
- />
260
- </ToolsPanelItem>
261
- ) }
262
- { showSearchControl && (
263
- <ToolsPanelItem
264
- hasValue={ () => !! querySearch }
212
+ <ToolsPanel
213
+ className="block-library-query-toolspanel__filters"
214
+ label={ __( 'Filters' ) }
215
+ resetAll={ () => {
216
+ setQuery( {
217
+ author: '',
218
+ parents: [],
219
+ search: '',
220
+ taxQuery: null,
221
+ } );
222
+ setQuerySearch( '' );
223
+ } }
224
+ dropdownMenuProps={ TOOLSPANEL_DROPDOWNMENU_PROPS }
225
+ >
226
+ { showTaxControl && (
227
+ <ToolsPanelItem
228
+ label={ __( 'Taxonomies' ) }
229
+ hasValue={ () =>
230
+ Object.values( taxQuery || {} ).some(
231
+ ( terms ) => !! terms.length
232
+ )
233
+ }
234
+ onDeselect={ () => setQuery( { taxQuery: null } ) }
235
+ >
236
+ <TaxonomyControls
237
+ onChange={ setQuery }
238
+ query={ query }
239
+ />
240
+ </ToolsPanelItem>
241
+ ) }
242
+ { showAuthorControl && (
243
+ <ToolsPanelItem
244
+ hasValue={ () => !! authorIds }
245
+ label={ __( 'Authors' ) }
246
+ onDeselect={ () => setQuery( { author: '' } ) }
247
+ >
248
+ <AuthorControl
249
+ value={ authorIds }
250
+ onChange={ setQuery }
251
+ />
252
+ </ToolsPanelItem>
253
+ ) }
254
+ { showSearchControl && (
255
+ <ToolsPanelItem
256
+ hasValue={ () => !! querySearch }
257
+ label={ __( 'Keyword' ) }
258
+ onDeselect={ () => setQuerySearch( '' ) }
259
+ >
260
+ <TextControl
261
+ __nextHasNoMarginBottom
265
262
  label={ __( 'Keyword' ) }
266
- onDeselect={ () => setQuerySearch( '' ) }
267
- >
268
- <TextControl
269
- __nextHasNoMarginBottom
270
- label={ __( 'Keyword' ) }
271
- value={ querySearch }
272
- onChange={ setQuerySearch }
273
- />
274
- </ToolsPanelItem>
275
- ) }
276
- { showParentControl && (
277
- <ToolsPanelItem
278
- hasValue={ () => !! parents?.length }
279
- label={ __( 'Parents' ) }
280
- onDeselect={ () => setQuery( { parents: [] } ) }
281
- >
282
- <ParentControl
283
- parents={ parents }
284
- postType={ postType }
285
- onChange={ setQuery }
286
- />
287
- </ToolsPanelItem>
288
- ) }
289
- </ToolsPanel>
290
- </InspectorControls>
263
+ value={ querySearch }
264
+ onChange={ setQuerySearch }
265
+ />
266
+ </ToolsPanelItem>
267
+ ) }
268
+ { showParentControl && (
269
+ <ToolsPanelItem
270
+ hasValue={ () => !! parents?.length }
271
+ label={ __( 'Parents' ) }
272
+ onDeselect={ () => setQuery( { parents: [] } ) }
273
+ >
274
+ <ParentControl
275
+ parents={ parents }
276
+ postType={ postType }
277
+ onChange={ setQuery }
278
+ />
279
+ </ToolsPanelItem>
280
+ ) }
281
+ </ToolsPanel>
291
282
  ) }
292
283
  </>
293
284
  );
@@ -112,13 +112,15 @@ export default function QueryContent( {
112
112
  setAttributes={ setAttributes }
113
113
  clientId={ clientId }
114
114
  />
115
- <QueryInspectorControls
116
- attributes={ attributes }
117
- setQuery={ updateQuery }
118
- setDisplayLayout={ updateDisplayLayout }
119
- setAttributes={ setAttributes }
120
- clientId={ clientId }
121
- />
115
+ <InspectorControls>
116
+ <QueryInspectorControls
117
+ attributes={ attributes }
118
+ setQuery={ updateQuery }
119
+ setDisplayLayout={ updateDisplayLayout }
120
+ setAttributes={ setAttributes }
121
+ clientId={ clientId }
122
+ />
123
+ </InspectorControls>
122
124
  <BlockControls>
123
125
  <QueryToolbar
124
126
  name={ name }
@@ -11,7 +11,6 @@ import {
11
11
  useBlockProps,
12
12
  store as blockEditorStore,
13
13
  __experimentalBlockVariationPicker,
14
- __experimentalGetMatchingVariation as getMatchingVariation,
15
14
  } from '@wordpress/block-editor';
16
15
  import { Button, Placeholder } from '@wordpress/components';
17
16
  import { __ } from '@wordpress/i18n';
@@ -34,31 +33,32 @@ export default function QueryPlaceholder( {
34
33
  clientId,
35
34
  attributes
36
35
  );
37
-
38
- const { blockType, allVariations, hasPatterns } = useSelect(
36
+ const { blockType, activeBlockVariation, hasPatterns } = useSelect(
39
37
  ( select ) => {
40
- const { getBlockVariations, getBlockType } = select( blocksStore );
38
+ const { getActiveBlockVariation, getBlockType } =
39
+ select( blocksStore );
41
40
  const { getBlockRootClientId, getPatternsByBlockTypes } =
42
41
  select( blockEditorStore );
43
42
  const rootClientId = getBlockRootClientId( clientId );
44
43
  return {
45
44
  blockType: getBlockType( name ),
46
- allVariations: getBlockVariations( name ),
45
+ activeBlockVariation: getActiveBlockVariation(
46
+ name,
47
+ attributes
48
+ ),
47
49
  hasPatterns: !! getPatternsByBlockTypes(
48
50
  blockNameForPatterns,
49
51
  rootClientId
50
52
  ).length,
51
53
  };
52
54
  },
53
- [ name, blockNameForPatterns, clientId ]
55
+ [ name, blockNameForPatterns, clientId, attributes ]
54
56
  );
55
-
56
- const matchingVariation = getMatchingVariation( attributes, allVariations );
57
57
  const icon =
58
- matchingVariation?.icon?.src ||
59
- matchingVariation?.icon ||
58
+ activeBlockVariation?.icon?.src ||
59
+ activeBlockVariation?.icon ||
60
60
  blockType?.icon?.src;
61
- const label = matchingVariation?.title || blockType?.title;
61
+ const label = activeBlockVariation?.title || blockType?.title;
62
62
  if ( isStartingBlank ) {
63
63
  return (
64
64
  <QueryVariationPicker
@@ -17,12 +17,19 @@
17
17
  * @return string Returns the modified output of the query block.
18
18
  */
19
19
  function render_block_core_query( $attributes, $content, $block ) {
20
- if ( $attributes['enhancedPagination'] && isset( $attributes['queryId'] ) ) {
20
+ $is_interactive = isset( $attributes['enhancedPagination'] ) && true === $attributes['enhancedPagination'] && isset( $attributes['queryId'] );
21
+
22
+ // Enqueue the script module and add the necessary directives if the block is
23
+ // interactive.
24
+ if ( $is_interactive ) {
25
+ wp_enqueue_script_module( '@wordpress/block-library/query' );
26
+
21
27
  $p = new WP_HTML_Tag_Processor( $content );
22
28
  if ( $p->next_tag() ) {
23
29
  // Add the necessary directives.
24
30
  $p->set_attribute( 'data-wp-interactive', '{"namespace":"core/query"}' );
25
- $p->set_attribute( 'data-wp-navigation-id', 'query-' . $attributes['queryId'] );
31
+ $p->set_attribute( 'data-wp-router-region', 'query-' . $attributes['queryId'] );
32
+ $p->set_attribute( 'data-wp-init', 'callbacks.setQueryRef' );
26
33
  // Use context to send translated strings.
27
34
  $p->set_attribute(
28
35
  'data-wp-context',
@@ -63,43 +70,17 @@ function render_block_core_query( $attributes, $content, $block ) {
63
70
  }
64
71
  }
65
72
 
66
- $is_gutenberg_plugin = defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN;
67
- $should_load_view_script = $attributes['enhancedPagination'] && isset( $attributes['queryId'] );
68
- $view_asset = 'wp-block-query-view';
69
- $script_handles = $block->block_type->view_script_handles;
70
-
71
- if ( $is_gutenberg_plugin ) {
72
- if ( $should_load_view_script ) {
73
- gutenberg_enqueue_module( '@wordpress/block-library/query' );
74
- }
75
- // Remove the view script because we are using the module.
76
- $block->block_type->view_script_handles = array_diff( $script_handles, array( $view_asset ) );
77
- } else {
78
- if ( ! wp_script_is( $view_asset ) ) {
79
- // If the script is not needed, and it is still in the `view_script_handles`, remove it.
80
- if ( ! $should_load_view_script && in_array( $view_asset, $script_handles, true )
81
- ) {
82
- $block->block_type->view_script_handles = array_diff( $script_handles, array( $view_asset ) );
83
- }
84
- // If the script is needed, but it was previously removed, add it again.
85
- if ( $should_load_view_script && ! in_array( $view_asset, $script_handles, true ) ) {
86
- $block->block_type->view_script_handles = array_merge( $script_handles, array( $view_asset ) );
87
- }
88
- }
89
- }
90
-
73
+ // Add the styles to the block type if the block is interactive and remove
74
+ // them if it's not.
91
75
  $style_asset = 'wp-block-query';
92
76
  if ( ! wp_style_is( $style_asset ) ) {
93
77
  $style_handles = $block->block_type->style_handles;
94
78
  // If the styles are not needed, and they are still in the `style_handles`, remove them.
95
- if (
96
- ( ! $attributes['enhancedPagination'] || ! isset( $attributes['queryId'] ) )
97
- && in_array( $style_asset, $style_handles, true )
98
- ) {
79
+ if ( ! $is_interactive && in_array( $style_asset, $style_handles, true ) ) {
99
80
  $block->block_type->style_handles = array_diff( $style_handles, array( $style_asset ) );
100
81
  }
101
82
  // If the styles are needed, but they were previously removed, add them again.
102
- if ( $attributes['enhancedPagination'] && isset( $attributes['queryId'] ) && ! in_array( $style_asset, $style_handles, true ) ) {
83
+ if ( $is_interactive && ! in_array( $style_asset, $style_handles, true ) ) {
103
84
  $block->block_type->style_handles = array_merge( $style_handles, array( $style_asset ) );
104
85
  }
105
86
  }
@@ -107,25 +88,6 @@ function render_block_core_query( $attributes, $content, $block ) {
107
88
  return $content;
108
89
  }
109
90
 
110
- /**
111
- * Ensure that the view script has the `wp-interactivity` dependency.
112
- *
113
- * @since 6.4.0
114
- *
115
- * @global WP_Scripts $wp_scripts
116
- */
117
- function block_core_query_ensure_interactivity_dependency() {
118
- global $wp_scripts;
119
- if (
120
- isset( $wp_scripts->registered['wp-block-query-view'] ) &&
121
- ! in_array( 'wp-interactivity', $wp_scripts->registered['wp-block-query-view']->deps, true )
122
- ) {
123
- $wp_scripts->registered['wp-block-query-view']->deps[] = 'wp-interactivity';
124
- }
125
- }
126
-
127
- add_action( 'wp_print_scripts', 'block_core_query_ensure_interactivity_dependency' );
128
-
129
91
  /**
130
92
  * Registers the `core/query` block on the server.
131
93
  */
@@ -137,14 +99,21 @@ function register_block_core_query() {
137
99
  )
138
100
  );
139
101
 
140
- if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ) {
141
- gutenberg_register_module(
142
- '@wordpress/block-library/query',
143
- '/wp-content/plugins/gutenberg/build/interactivity/query.min.js',
144
- array( '@wordpress/interactivity' ),
145
- defined( 'GUTENBERG_VERSION' ) ? GUTENBERG_VERSION : get_bloginfo( 'version' )
146
- );
147
- }
102
+ wp_register_script_module(
103
+ '@wordpress/block-library/query',
104
+ defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ? gutenberg_url( '/build/interactivity/query.min.js' ) : includes_url( 'blocks/query/view.min.js' ),
105
+ array(
106
+ array(
107
+ 'id' => '@wordpress/interactivity',
108
+ 'import' => 'static',
109
+ ),
110
+ array(
111
+ 'id' => '@wordpress/interactivity-router',
112
+ 'import' => 'dynamic',
113
+ ),
114
+ ),
115
+ defined( 'GUTENBERG_VERSION' ) ? GUTENBERG_VERSION : get_bloginfo( 'version' )
116
+ );
148
117
  }
149
118
  add_action( 'init', 'register_block_core_query' );
150
119
 
@@ -164,14 +133,10 @@ function block_core_query_disable_enhanced_pagination( $parsed_block ) {
164
133
  static $dirty_enhanced_queries = array();
165
134
  static $render_query_callback = null;
166
135
 
167
- $block_name = $parsed_block['blockName'];
136
+ $is_interactive = isset( $parsed_block['attrs']['enhancedPagination'] ) && true === $parsed_block['attrs']['enhancedPagination'] && isset( $parsed_block['attrs']['queryId'] );
137
+ $block_name = $parsed_block['blockName'];
168
138
 
169
- if (
170
- 'core/query' === $block_name &&
171
- isset( $parsed_block['attrs']['enhancedPagination'] ) &&
172
- true === $parsed_block['attrs']['enhancedPagination'] &&
173
- isset( $parsed_block['attrs']['queryId'] )
174
- ) {
139
+ if ( 'core/query' === $block_name && $is_interactive ) {
175
140
  $enhanced_query_stack[] = $parsed_block['attrs']['queryId'];
176
141
 
177
142
  if ( ! isset( $render_query_callback ) ) {
@@ -186,12 +151,9 @@ function block_core_query_disable_enhanced_pagination( $parsed_block ) {
186
151
  * @return string Returns the modified output of the query block.
187
152
  */
188
153
  $render_query_callback = static function ( $content, $block ) use ( &$enhanced_query_stack, &$dirty_enhanced_queries, &$render_query_callback ) {
189
- $has_enhanced_pagination =
190
- isset( $block['attrs']['enhancedPagination'] ) &&
191
- true === $block['attrs']['enhancedPagination'] &&
192
- isset( $block['attrs']['queryId'] );
154
+ $is_interactive = isset( $block['attrs']['enhancedPagination'] ) && true === $block['attrs']['enhancedPagination'] && isset( $block['attrs']['queryId'] );
193
155
 
194
- if ( ! $has_enhanced_pagination ) {
156
+ if ( ! $is_interactive ) {
195
157
  return $content;
196
158
  }
197
159
 
@@ -39,6 +39,7 @@ const variations = [
39
39
  ),
40
40
  icon: postList,
41
41
  attributes: {
42
+ namespace: 'core/posts-list',
42
43
  query: {
43
44
  perPage: 4,
44
45
  pages: 1,
@@ -53,6 +54,9 @@ const variations = [
53
54
  },
54
55
  },
55
56
  scope: [ 'inserter' ],
57
+ isActive: ( { namespace, query } ) => {
58
+ return namespace === 'core/posts-list' && query.postType === 'post';
59
+ },
56
60
  },
57
61
  {
58
62
  name: 'title-date',
package/src/query/view.js CHANGED
@@ -1,13 +1,7 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
- import {
5
- store,
6
- getContext,
7
- getElement,
8
- navigate,
9
- prefetch,
10
- } from '@wordpress/interactivity';
4
+ import { store, getContext, getElement } from '@wordpress/interactivity';
11
5
 
12
6
  const isValidLink = ( ref ) =>
13
7
  ref &&
@@ -37,22 +31,22 @@ store( 'core/query', {
37
31
  *navigate( event ) {
38
32
  const ctx = getContext();
39
33
  const { ref } = getElement();
40
- const isDisabled = ref.closest( '[data-wp-navigation-id]' )?.dataset
41
- .wpNavigationDisabled;
34
+ const { queryRef } = ctx;
35
+ const isDisabled = queryRef?.dataset.wpNavigationDisabled;
42
36
 
43
37
  if ( isValidLink( ref ) && isValidEvent( event ) && ! isDisabled ) {
44
38
  event.preventDefault();
45
39
 
46
- const id = ref.closest( '[data-wp-navigation-id]' ).dataset
47
- .wpNavigationId;
48
-
49
40
  // Don't announce the navigation immediately, wait 400 ms.
50
41
  const timeout = setTimeout( () => {
51
42
  ctx.message = ctx.loadingText;
52
43
  ctx.animation = 'start';
53
44
  }, 400 );
54
45
 
55
- yield navigate( ref.href );
46
+ const { actions } = yield import(
47
+ '@wordpress/interactivity-router'
48
+ );
49
+ yield actions.navigate( ref.href );
56
50
 
57
51
  // Dismiss loading message if it hasn't been added yet.
58
52
  clearTimeout( timeout );
@@ -68,16 +62,19 @@ store( 'core/query', {
68
62
  ctx.url = ref.href;
69
63
 
70
64
  // Focus the first anchor of the Query block.
71
- const firstAnchor = `[data-wp-navigation-id=${ id }] .wp-block-post-template a[href]`;
72
- document.querySelector( firstAnchor )?.focus();
65
+ const firstAnchor = `.wp-block-post-template a[href]`;
66
+ queryRef.querySelector( firstAnchor )?.focus();
73
67
  }
74
68
  },
75
69
  *prefetch() {
70
+ const { queryRef } = getContext();
76
71
  const { ref } = getElement();
77
- const isDisabled = ref.closest( '[data-wp-navigation-id]' )?.dataset
78
- .wpNavigationDisabled;
72
+ const isDisabled = queryRef?.dataset.wpNavigationDisabled;
79
73
  if ( isValidLink( ref ) && ! isDisabled ) {
80
- yield prefetch( ref.href );
74
+ const { actions } = yield import(
75
+ '@wordpress/interactivity-router'
76
+ );
77
+ yield actions.prefetch( ref.href );
81
78
  }
82
79
  },
83
80
  },
@@ -86,8 +83,16 @@ store( 'core/query', {
86
83
  const { url } = getContext();
87
84
  const { ref } = getElement();
88
85
  if ( url && isValidLink( ref ) ) {
89
- yield prefetch( ref.href );
86
+ const { actions } = yield import(
87
+ '@wordpress/interactivity-router'
88
+ );
89
+ yield actions.prefetch( ref.href );
90
90
  }
91
91
  },
92
+ setQueryRef() {
93
+ const ctx = getContext();
94
+ const { ref } = getElement();
95
+ ctx.queryRef = ref;
96
+ },
92
97
  },
93
98
  } );
@@ -87,7 +87,6 @@
87
87
  },
88
88
  "html": false
89
89
  },
90
- "viewScript": "file:./view.min.js",
91
90
  "editorStyle": "wp-block-search-editor",
92
91
  "style": "wp-block-search"
93
92
  }