@wordpress/block-editor 12.4.0 → 12.5.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 (316) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/README.md +5 -0
  3. package/build/components/block-heading-level-dropdown/heading-level-icon.js +10 -2
  4. package/build/components/block-heading-level-dropdown/heading-level-icon.js.map +1 -1
  5. package/build/components/block-heading-level-dropdown/index.native.js +4 -3
  6. package/build/components/block-heading-level-dropdown/index.native.js.map +1 -1
  7. package/build/components/block-lock/toolbar.js +25 -6
  8. package/build/components/block-lock/toolbar.js.map +1 -1
  9. package/build/components/block-mobile-toolbar/block-actions-menu.native.js +3 -6
  10. package/build/components/block-mobile-toolbar/block-actions-menu.native.js.map +1 -1
  11. package/build/components/block-parent-selector/index.js +8 -5
  12. package/build/components/block-parent-selector/index.js.map +1 -1
  13. package/build/components/block-removal-warning-modal/index.js +18 -25
  14. package/build/components/block-removal-warning-modal/index.js.map +1 -1
  15. package/build/components/block-toolbar/index.js +8 -5
  16. package/build/components/block-toolbar/index.js.map +1 -1
  17. package/build/components/block-tools/block-contextual-toolbar.js +7 -11
  18. package/build/components/block-tools/block-contextual-toolbar.js.map +1 -1
  19. package/build/components/dimensions-tool/aspect-ratio-tool.js +99 -0
  20. package/build/components/dimensions-tool/aspect-ratio-tool.js.map +1 -0
  21. package/build/components/dimensions-tool/index.js +207 -0
  22. package/build/components/dimensions-tool/index.js.map +1 -0
  23. package/build/components/dimensions-tool/scale-tool.js +111 -0
  24. package/build/components/dimensions-tool/scale-tool.js.map +1 -0
  25. package/build/components/dimensions-tool/width-height-tool.js +125 -0
  26. package/build/components/dimensions-tool/width-height-tool.js.map +1 -0
  27. package/build/components/global-styles/color-panel.js +1 -1
  28. package/build/components/global-styles/color-panel.js.map +1 -1
  29. package/build/components/global-styles/filters-panel.js +1 -1
  30. package/build/components/global-styles/filters-panel.js.map +1 -1
  31. package/build/components/global-styles/hooks.js +2 -2
  32. package/build/components/global-styles/hooks.js.map +1 -1
  33. package/build/components/global-styles/typography-panel.js +34 -2
  34. package/build/components/global-styles/typography-panel.js.map +1 -1
  35. package/build/components/image-editor/aspect-ratio-dropdown.js +1 -1
  36. package/build/components/image-editor/aspect-ratio-dropdown.js.map +1 -1
  37. package/build/components/image-editor/use-save-image.js +1 -2
  38. package/build/components/image-editor/use-save-image.js.map +1 -1
  39. package/build/components/image-size-control/index.js +6 -0
  40. package/build/components/image-size-control/index.js.map +1 -1
  41. package/build/components/index.js +19 -1
  42. package/build/components/index.js.map +1 -1
  43. package/build/components/inserter/block-patterns-explorer/patterns-list.js +2 -2
  44. package/build/components/inserter/block-patterns-explorer/patterns-list.js.map +1 -1
  45. package/build/components/inserter/block-patterns-tab.js +7 -35
  46. package/build/components/inserter/block-patterns-tab.js.map +1 -1
  47. package/build/components/inserter/hooks/use-block-types-state.js +3 -4
  48. package/build/components/inserter/hooks/use-block-types-state.js.map +1 -1
  49. package/build/components/inserter/hooks/use-patterns-state.js +9 -3
  50. package/build/components/inserter/hooks/use-patterns-state.js.map +1 -1
  51. package/build/components/inserter/media-tab/hooks.js +2 -21
  52. package/build/components/inserter/media-tab/hooks.js.map +1 -1
  53. package/build/components/inserter/reusable-block-rename-hint.js +62 -0
  54. package/build/components/inserter/reusable-block-rename-hint.js.map +1 -0
  55. package/build/components/inserter/reusable-blocks-tab.js +6 -2
  56. package/build/components/inserter/reusable-blocks-tab.js.map +1 -1
  57. package/build/components/inserter/reusable-blocks-tab.native.js +2 -2
  58. package/build/components/inserter/reusable-blocks-tab.native.js.map +1 -1
  59. package/build/components/inserter/tabs.native.js +1 -1
  60. package/build/components/inserter/tabs.native.js.map +1 -1
  61. package/build/components/inserter-draggable-blocks/index.js +9 -1
  62. package/build/components/inserter-draggable-blocks/index.js.map +1 -1
  63. package/build/components/link-control/constants.js +1 -1
  64. package/build/components/link-control/constants.js.map +1 -1
  65. package/build/components/link-control/index.js +17 -15
  66. package/build/components/link-control/index.js.map +1 -1
  67. package/build/components/link-control/search-create-button.js +5 -21
  68. package/build/components/link-control/search-create-button.js.map +1 -1
  69. package/build/components/link-control/search-input.js +4 -4
  70. package/build/components/link-control/search-input.js.map +1 -1
  71. package/build/components/link-control/search-item.js +13 -30
  72. package/build/components/link-control/search-item.js.map +1 -1
  73. package/build/components/link-control/search-results.js +2 -2
  74. package/build/components/link-control/search-results.js.map +1 -1
  75. package/build/components/link-control/settings-drawer.js +2 -3
  76. package/build/components/link-control/settings-drawer.js.map +1 -1
  77. package/build/components/list-view/appender.js +2 -6
  78. package/build/components/list-view/appender.js.map +1 -1
  79. package/build/components/provider/index.js +5 -2
  80. package/build/components/provider/index.js.map +1 -1
  81. package/build/components/provider/use-block-sync.js +21 -0
  82. package/build/components/provider/use-block-sync.js.map +1 -1
  83. package/build/components/resolution-tool/index.js +55 -0
  84. package/build/components/resolution-tool/index.js.map +1 -0
  85. package/build/components/url-input/index.js +4 -2
  86. package/build/components/url-input/index.js.map +1 -1
  87. package/build/components/writing-flow/use-tab-nav.js +10 -27
  88. package/build/components/writing-flow/use-tab-nav.js.map +1 -1
  89. package/build/components/writing-mode-control/index.js +70 -0
  90. package/build/components/writing-mode-control/index.js.map +1 -0
  91. package/build/hooks/behaviors.js +25 -20
  92. package/build/hooks/behaviors.js.map +1 -1
  93. package/build/hooks/supports.js +7 -1
  94. package/build/hooks/supports.js.map +1 -1
  95. package/build/hooks/typography.js +2 -1
  96. package/build/hooks/typography.js.map +1 -1
  97. package/build/hooks/utils.js +4 -2
  98. package/build/hooks/utils.js.map +1 -1
  99. package/build/private-apis.js +10 -1
  100. package/build/private-apis.js.map +1 -1
  101. package/build/private-apis.native.js +3 -0
  102. package/build/private-apis.native.js.map +1 -1
  103. package/build/store/actions.js +195 -1
  104. package/build/store/actions.js.map +1 -1
  105. package/build/store/defaults.js +1 -0
  106. package/build/store/defaults.js.map +1 -1
  107. package/build/store/index.js +10 -1
  108. package/build/store/index.js.map +1 -1
  109. package/build/store/private-actions.js +46 -40
  110. package/build/store/private-actions.js.map +1 -1
  111. package/build/store/private-selectors.js +3 -3
  112. package/build/store/private-selectors.js.map +1 -1
  113. package/build/store/reducer.js +22 -8
  114. package/build/store/reducer.js.map +1 -1
  115. package/build/store/selectors.js +33 -15
  116. package/build/store/selectors.js.map +1 -1
  117. package/build-module/components/block-heading-level-dropdown/heading-level-icon.js +9 -2
  118. package/build-module/components/block-heading-level-dropdown/heading-level-icon.js.map +1 -1
  119. package/build-module/components/block-heading-level-dropdown/index.native.js +4 -3
  120. package/build-module/components/block-heading-level-dropdown/index.native.js.map +1 -1
  121. package/build-module/components/block-lock/toolbar.js +25 -7
  122. package/build-module/components/block-lock/toolbar.js.map +1 -1
  123. package/build-module/components/block-mobile-toolbar/block-actions-menu.native.js +4 -6
  124. package/build-module/components/block-mobile-toolbar/block-actions-menu.native.js.map +1 -1
  125. package/build-module/components/block-parent-selector/index.js +7 -5
  126. package/build-module/components/block-parent-selector/index.js.map +1 -1
  127. package/build-module/components/block-removal-warning-modal/index.js +20 -24
  128. package/build-module/components/block-removal-warning-modal/index.js.map +1 -1
  129. package/build-module/components/block-toolbar/index.js +8 -5
  130. package/build-module/components/block-toolbar/index.js.map +1 -1
  131. package/build-module/components/block-tools/block-contextual-toolbar.js +8 -11
  132. package/build-module/components/block-tools/block-contextual-toolbar.js.map +1 -1
  133. package/build-module/components/dimensions-tool/aspect-ratio-tool.js +87 -0
  134. package/build-module/components/dimensions-tool/aspect-ratio-tool.js.map +1 -0
  135. package/build-module/components/dimensions-tool/index.js +195 -0
  136. package/build-module/components/dimensions-tool/index.js.map +1 -0
  137. package/build-module/components/dimensions-tool/scale-tool.js +103 -0
  138. package/build-module/components/dimensions-tool/scale-tool.js.map +1 -0
  139. package/build-module/components/dimensions-tool/width-height-tool.js +122 -0
  140. package/build-module/components/dimensions-tool/width-height-tool.js.map +1 -0
  141. package/build-module/components/global-styles/color-panel.js +1 -1
  142. package/build-module/components/global-styles/color-panel.js.map +1 -1
  143. package/build-module/components/global-styles/filters-panel.js +2 -2
  144. package/build-module/components/global-styles/filters-panel.js.map +1 -1
  145. package/build-module/components/global-styles/hooks.js +2 -2
  146. package/build-module/components/global-styles/hooks.js.map +1 -1
  147. package/build-module/components/global-styles/typography-panel.js +33 -2
  148. package/build-module/components/global-styles/typography-panel.js.map +1 -1
  149. package/build-module/components/image-editor/aspect-ratio-dropdown.js +1 -1
  150. package/build-module/components/image-editor/aspect-ratio-dropdown.js.map +1 -1
  151. package/build-module/components/image-editor/use-save-image.js +1 -2
  152. package/build-module/components/image-editor/use-save-image.js.map +1 -1
  153. package/build-module/components/image-size-control/index.js +5 -0
  154. package/build-module/components/image-size-control/index.js.map +1 -1
  155. package/build-module/components/index.js +6 -0
  156. package/build-module/components/index.js.map +1 -1
  157. package/build-module/components/inserter/block-patterns-explorer/patterns-list.js +2 -2
  158. package/build-module/components/inserter/block-patterns-explorer/patterns-list.js.map +1 -1
  159. package/build-module/components/inserter/block-patterns-tab.js +7 -33
  160. package/build-module/components/inserter/block-patterns-tab.js.map +1 -1
  161. package/build-module/components/inserter/hooks/use-block-types-state.js +3 -4
  162. package/build-module/components/inserter/hooks/use-block-types-state.js.map +1 -1
  163. package/build-module/components/inserter/hooks/use-patterns-state.js +9 -3
  164. package/build-module/components/inserter/hooks/use-patterns-state.js.map +1 -1
  165. package/build-module/components/inserter/media-tab/hooks.js +2 -21
  166. package/build-module/components/inserter/media-tab/hooks.js.map +1 -1
  167. package/build-module/components/inserter/reusable-block-rename-hint.js +48 -0
  168. package/build-module/components/inserter/reusable-block-rename-hint.js.map +1 -0
  169. package/build-module/components/inserter/reusable-blocks-tab.js +5 -2
  170. package/build-module/components/inserter/reusable-blocks-tab.js.map +1 -1
  171. package/build-module/components/inserter/reusable-blocks-tab.native.js +2 -2
  172. package/build-module/components/inserter/reusable-blocks-tab.native.js.map +1 -1
  173. package/build-module/components/inserter/tabs.native.js +1 -1
  174. package/build-module/components/inserter/tabs.native.js.map +1 -1
  175. package/build-module/components/inserter-draggable-blocks/index.js +9 -2
  176. package/build-module/components/inserter-draggable-blocks/index.js.map +1 -1
  177. package/build-module/components/link-control/constants.js +1 -1
  178. package/build-module/components/link-control/constants.js.map +1 -1
  179. package/build-module/components/link-control/index.js +17 -15
  180. package/build-module/components/link-control/index.js.map +1 -1
  181. package/build-module/components/link-control/search-create-button.js +7 -20
  182. package/build-module/components/link-control/search-create-button.js.map +1 -1
  183. package/build-module/components/link-control/search-input.js +4 -4
  184. package/build-module/components/link-control/search-input.js.map +1 -1
  185. package/build-module/components/link-control/search-item.js +14 -28
  186. package/build-module/components/link-control/search-item.js.map +1 -1
  187. package/build-module/components/link-control/search-results.js +3 -3
  188. package/build-module/components/link-control/search-results.js.map +1 -1
  189. package/build-module/components/link-control/settings-drawer.js +4 -5
  190. package/build-module/components/link-control/settings-drawer.js.map +1 -1
  191. package/build-module/components/list-view/appender.js +2 -6
  192. package/build-module/components/list-view/appender.js.map +1 -1
  193. package/build-module/components/provider/index.js +5 -2
  194. package/build-module/components/provider/index.js.map +1 -1
  195. package/build-module/components/provider/use-block-sync.js +21 -0
  196. package/build-module/components/provider/use-block-sync.js.map +1 -1
  197. package/build-module/components/resolution-tool/index.js +45 -0
  198. package/build-module/components/resolution-tool/index.js.map +1 -0
  199. package/build-module/components/url-input/index.js +4 -2
  200. package/build-module/components/url-input/index.js.map +1 -1
  201. package/build-module/components/writing-flow/use-tab-nav.js +8 -26
  202. package/build-module/components/writing-flow/use-tab-nav.js.map +1 -1
  203. package/build-module/components/writing-mode-control/index.js +57 -0
  204. package/build-module/components/writing-mode-control/index.js.map +1 -0
  205. package/build-module/hooks/behaviors.js +26 -20
  206. package/build-module/hooks/behaviors.js.map +1 -1
  207. package/build-module/hooks/supports.js +7 -1
  208. package/build-module/hooks/supports.js.map +1 -1
  209. package/build-module/hooks/typography.js +2 -1
  210. package/build-module/hooks/typography.js.map +1 -1
  211. package/build-module/hooks/utils.js +4 -2
  212. package/build-module/hooks/utils.js.map +1 -1
  213. package/build-module/private-apis.js +7 -1
  214. package/build-module/private-apis.js.map +1 -1
  215. package/build-module/private-apis.native.js +2 -0
  216. package/build-module/private-apis.native.js.map +1 -1
  217. package/build-module/store/actions.js +191 -1
  218. package/build-module/store/actions.js.map +1 -1
  219. package/build-module/store/defaults.js +1 -0
  220. package/build-module/store/defaults.js.map +1 -1
  221. package/build-module/store/index.js +10 -1
  222. package/build-module/store/index.js.map +1 -1
  223. package/build-module/store/private-actions.js +45 -36
  224. package/build-module/store/private-actions.js.map +1 -1
  225. package/build-module/store/private-selectors.js +2 -2
  226. package/build-module/store/private-selectors.js.map +1 -1
  227. package/build-module/store/reducer.js +22 -8
  228. package/build-module/store/reducer.js.map +1 -1
  229. package/build-module/store/selectors.js +33 -15
  230. package/build-module/store/selectors.js.map +1 -1
  231. package/build-style/content-rtl.css +3 -0
  232. package/build-style/content.css +3 -0
  233. package/build-style/style-rtl.css +131 -129
  234. package/build-style/style.css +131 -129
  235. package/package.json +32 -31
  236. package/src/components/alignment-control/test/__snapshots__/index.js.snap +6 -6
  237. package/src/components/block-alignment-control/test/__snapshots__/index.js.snap +5 -5
  238. package/src/components/block-draggable/style.scss +1 -0
  239. package/src/components/block-heading-level-dropdown/heading-level-icon.js +6 -1
  240. package/src/components/block-heading-level-dropdown/index.native.js +8 -4
  241. package/src/components/block-inspector/style.scss +2 -1
  242. package/src/components/block-lock/toolbar.js +34 -6
  243. package/src/components/block-mobile-toolbar/block-actions-menu.native.js +4 -8
  244. package/src/components/block-parent-selector/index.js +13 -8
  245. package/src/components/block-removal-warning-modal/index.js +20 -33
  246. package/src/components/block-toolbar/index.js +9 -6
  247. package/src/components/block-tools/block-contextual-toolbar.js +5 -11
  248. package/src/components/block-tools/style.scss +73 -26
  249. package/src/components/default-block-appender/content.scss +11 -0
  250. package/src/components/dimensions-tool/aspect-ratio-tool.js +124 -0
  251. package/src/components/dimensions-tool/index.js +212 -0
  252. package/src/components/dimensions-tool/scale-tool.js +124 -0
  253. package/src/components/dimensions-tool/stories/aspect-ratio-tool.js +52 -0
  254. package/src/components/dimensions-tool/stories/index.js +54 -0
  255. package/src/components/dimensions-tool/stories/scale-tool.js +48 -0
  256. package/src/components/dimensions-tool/stories/width-height-tool.js +54 -0
  257. package/src/components/dimensions-tool/test/index.js +641 -0
  258. package/src/components/dimensions-tool/width-height-tool.js +113 -0
  259. package/src/components/font-family/README.md +71 -0
  260. package/src/components/global-styles/color-panel.js +1 -1
  261. package/src/components/global-styles/filters-panel.js +2 -2
  262. package/src/components/global-styles/hooks.js +2 -0
  263. package/src/components/global-styles/typography-panel.js +40 -0
  264. package/src/components/image-editor/aspect-ratio-dropdown.js +1 -1
  265. package/src/components/image-editor/use-save-image.js +0 -1
  266. package/src/components/image-size-control/index.js +6 -0
  267. package/src/components/index.js +6 -0
  268. package/src/components/inserter/block-patterns-explorer/patterns-list.js +8 -2
  269. package/src/components/inserter/block-patterns-tab.js +8 -56
  270. package/src/components/inserter/hooks/use-block-types-state.js +3 -4
  271. package/src/components/inserter/hooks/use-patterns-state.js +35 -19
  272. package/src/components/inserter/media-tab/hooks.js +2 -22
  273. package/src/components/inserter/reusable-block-rename-hint.js +52 -0
  274. package/src/components/inserter/reusable-blocks-tab.js +5 -1
  275. package/src/components/inserter/reusable-blocks-tab.native.js +2 -2
  276. package/src/components/inserter/style.scss +28 -0
  277. package/src/components/inserter/tabs.native.js +5 -1
  278. package/src/components/inserter-draggable-blocks/index.js +13 -2
  279. package/src/components/link-control/constants.js +1 -1
  280. package/src/components/link-control/index.js +32 -28
  281. package/src/components/link-control/search-create-button.js +8 -26
  282. package/src/components/link-control/search-input.js +4 -3
  283. package/src/components/link-control/search-item.js +21 -43
  284. package/src/components/link-control/search-results.js +48 -46
  285. package/src/components/link-control/settings-drawer.js +6 -5
  286. package/src/components/link-control/style.scss +51 -123
  287. package/src/components/link-control/test/index.js +135 -123
  288. package/src/components/list-view/appender.js +5 -6
  289. package/src/components/list-view/style.scss +1 -2
  290. package/src/components/media-replace-flow/test/index.js +1 -1
  291. package/src/components/panel-color-settings/README.md +98 -0
  292. package/src/components/provider/index.js +9 -2
  293. package/src/components/provider/test/use-block-sync.js +21 -6
  294. package/src/components/provider/use-block-sync.js +19 -0
  295. package/src/components/recursion-provider/README.md +101 -0
  296. package/src/components/resolution-tool/index.js +56 -0
  297. package/src/components/resolution-tool/stories/index.js +48 -0
  298. package/src/components/url-input/index.js +2 -0
  299. package/src/components/writing-flow/use-tab-nav.js +10 -33
  300. package/src/components/writing-mode-control/index.js +68 -0
  301. package/src/components/writing-mode-control/style.scss +18 -0
  302. package/src/hooks/behaviors.js +25 -16
  303. package/src/hooks/supports.js +7 -0
  304. package/src/hooks/typography.js +2 -0
  305. package/src/hooks/utils.js +3 -0
  306. package/src/private-apis.js +6 -0
  307. package/src/private-apis.native.js +2 -0
  308. package/src/store/actions.js +194 -1
  309. package/src/store/defaults.js +1 -0
  310. package/src/store/index.js +10 -0
  311. package/src/store/private-actions.js +39 -39
  312. package/src/store/private-selectors.js +2 -2
  313. package/src/store/reducer.js +22 -8
  314. package/src/store/selectors.js +54 -20
  315. package/src/store/test/actions.js +111 -0
  316. package/src/store/test/private-actions.js +56 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/list-view/appender.js"],"names":["Appender","nestingLevel","blockCount","clientId","props","ref","insertedBlock","setInsertedBlock","instanceId","hideInserter","select","getTemplateLock","__unstableGetEditorMode","blockEditorStore","blockTitle","context","insertedBlockTitle","length","descriptionId","description","maybeInsertedBlock"],"mappings":";;;;;;;;;AAMA;;AAHA;;AACA;;AACA;;AAEA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AAhBA;AACA;AACA;;AAOA;AACA;AACA;AAOO,MAAMA,QAAQ,GAAG,yBACvB,CAAE;AAAEC,EAAAA,YAAF;AAAgBC,EAAAA,UAAhB;AAA4BC,EAAAA,QAA5B;AAAsC,KAAGC;AAAzC,CAAF,EAAoDC,GAApD,KAA6D;AAC5D,QA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AAKC,IAAA,mBAAmB,EAAG,KALvB;AAMC,IAAA,kBAAkB,EAAG,KANtB;AAOC,IAAA,qBAAqB,MAPtB;AAAA,OAQMC,KARN;AASC,IAAA,WAAW,EAAG;AAAE,0BAAoBc;AAAtB,KATf;AAUC,IAAA,eAAe,EAAKE,kBAAF,IAA0B;AAC3C,UAAKA,kBAAkB,EAAEjB,QAAzB,EAAoC;AACnCI,QAAAA,gBAAgB,CAAEa,kBAAF,CAAhB;AACA;AACD;AAdF,IADD,EAiBC,4BAAC,2BAAD;AAAoB,IAAA,EAAE,EAAGF;AAAzB,KACGC,WADH,CAjBD,CADD;AAuBA,CAhFsB,CAAjB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useInstanceId } from '@wordpress/compose';\nimport { speak } from '@wordpress/a11y';\nimport { useSelect } from '@wordpress/data';\nimport { forwardRef, useEffect } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport useBlockDisplayTitle from '../block-title/use-block-display-title';\nimport { useListViewContext } from './context';\nimport Inserter from '../inserter';\nimport AriaReferencedText from './aria-referenced-text';\n\nexport const Appender = forwardRef(\n\t( { nestingLevel, blockCount, clientId, ...props }, ref ) => {\n\t\tconst { insertedBlock, setInsertedBlock } = useListViewContext();\n\n\t\tconst instanceId = useInstanceId( Appender );\n\t\tconst { hideInserter } = useSelect(\n\t\t\t( select ) => {\n\t\t\t\tconst { getTemplateLock, __unstableGetEditorMode } =\n\t\t\t\t\tselect( blockEditorStore );\n\n\t\t\t\treturn {\n\t\t\t\t\thideInserter:\n\t\t\t\t\t\t!! getTemplateLock( clientId ) ||\n\t\t\t\t\t\t__unstableGetEditorMode() === 'zoom-out',\n\t\t\t\t};\n\t\t\t},\n\t\t\t[ clientId ]\n\t\t);\n\n\t\tconst blockTitle = useBlockDisplayTitle( {\n\t\t\tclientId,\n\t\t\tcontext: 'list-view',\n\t\t} );\n\n\t\tconst insertedBlockTitle = useBlockDisplayTitle( {\n\t\t\tclientId: insertedBlock?.clientId,\n\t\t\tcontext: 'list-view',\n\t\t} );\n\n\t\tuseEffect( () => {\n\t\t\tif ( ! insertedBlockTitle?.length ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tspeak(\n\t\t\t\tsprintf(\n\t\t\t\t\t// translators: %s: name of block being inserted (i.e. Paragraph, Image, Group etc)\n\t\t\t\t\t__( '%s block inserted' ),\n\t\t\t\t\tinsertedBlockTitle\n\t\t\t\t),\n\t\t\t\t'assertive'\n\t\t\t);\n\t\t}, [ insertedBlockTitle ] );\n\n\t\tif ( hideInserter ) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst descriptionId = `list-view-appender__${ instanceId }`;\n\t\tconst description = sprintf(\n\t\t\t/* translators: 1: The name of the block. 2: The numerical position of the block. 3: The level of nesting for the block. */\n\t\t\t__( 'Append to %1$s block at position %2$d, Level %3$d' ),\n\t\t\tblockTitle,\n\t\t\tblockCount + 1,\n\t\t\tnestingLevel\n\t\t);\n\n\t\treturn (\n\t\t\t<div className=\"list-view-appender\">\n\t\t\t\t<Inserter\n\t\t\t\t\tref={ ref }\n\t\t\t\t\trootClientId={ clientId }\n\t\t\t\t\tposition=\"bottom right\"\n\t\t\t\t\tisAppender\n\t\t\t\t\tselectBlockOnInsert={ false }\n\t\t\t\t\tshouldDirectInsert={ false }\n\t\t\t\t\t__experimentalIsQuick\n\t\t\t\t\t{ ...props }\n\t\t\t\t\ttoggleProps={ { 'aria-describedby': descriptionId } }\n\t\t\t\t\tonSelectOrClose={ ( maybeInsertedBlock ) => {\n\t\t\t\t\t\tif ( maybeInsertedBlock?.clientId ) {\n\t\t\t\t\t\t\tsetInsertedBlock( maybeInsertedBlock );\n\t\t\t\t\t\t}\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t\t<AriaReferencedText id={ descriptionId }>\n\t\t\t\t\t{ description }\n\t\t\t\t</AriaReferencedText>\n\t\t\t</div>\n\t\t);\n\t}\n);\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/list-view/appender.js"],"names":["Appender","nestingLevel","blockCount","clientId","props","ref","insertedBlock","setInsertedBlock","instanceId","hideInserter","select","getTemplateLock","__unstableGetEditorMode","blockEditorStore","blockTitle","context","insertedBlockTitle","length","descriptionId","description","maybeInsertedBlock"],"mappings":";;;;;;;;;AAMA;;AAHA;;AACA;;AACA;;AAEA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AAhBA;AACA;AACA;;AAOA;AACA;AACA;AAOO,MAAMA,QAAQ,GAAG,yBACvB,CAAE;AAAEC,EAAAA,YAAF;AAAgBC,EAAAA,UAAhB;AAA4BC,EAAAA,QAA5B;AAAsC,KAAGC;AAAzC,CAAF,EAAoDC,GAApD,KAA6D;AAC5D,QAAM;AAAEC,IAAAA,aAAF;AAAiBC,IAAAA;AAAjB,MAAsC,kCAA5C;AAEA,QAAMC,UAAU,GAAG,4BAAeR,QAAf,CAAnB;AACA,QAAMS,YAAY,GAAG,qBAClBC,MAAF,IAAc;AACb,UAAM;AAAEC,MAAAA,eAAF;AAAmBC,MAAAA;AAAnB,QACLF,MAAM,CAAEG,YAAF,CADP;AAGA,WACC,CAAC,CAAEF,eAAe,CAAER,QAAF,CAAlB,IACAS,uBAAuB,OAAO,UAF/B;AAIA,GATmB,EAUpB,CAAET,QAAF,CAVoB,CAArB;AAaA,QAAMW,UAAU,GAAG,mCAAsB;AACxCX,IAAAA,QADwC;AAExCY,IAAAA,OAAO,EAAE;AAF+B,GAAtB,CAAnB;AAKA,QAAMC,kBAAkB,GAAG,mCAAsB;AAChDb,IAAAA,QAAQ,EAAEG,aAAa,EAAEH,QADuB;AAEhDY,IAAAA,OAAO,EAAE;AAFuC,GAAtB,CAA3B;AAKA,0BAAW,MAAM;AAChB,QAAK,CAAEC,kBAAkB,EAAEC,MAA3B,EAAoC;AACnC;AACA;;AAED,qBACC,oBACC;AACA,kBAAI,mBAAJ,CAFD,EAGCD,kBAHD,CADD,EAMC,WAND;AAQA,GAbD,EAaG,CAAEA,kBAAF,CAbH;;AAeA,MAAKP,YAAL,EAAoB;AACnB,WAAO,IAAP;AACA;;AAED,QAAMS,aAAa,GAAI,uBAAuBV,UAAY,EAA1D;AACA,QAAMW,WAAW,GAAG;AACnB;AACA,gBAAI,mDAAJ,CAFmB,EAGnBL,UAHmB,EAInBZ,UAAU,GAAG,CAJM,EAKnBD,YALmB,CAApB;AAQA,SACC;AAAK,IAAA,SAAS,EAAC;AAAf,KACC,4BAAC,iBAAD;AACC,IAAA,GAAG,EAAGI,GADP;AAEC,IAAA,YAAY,EAAGF,QAFhB;AAGC,IAAA,QAAQ,EAAC,cAHV;AAIC,IAAA,UAAU,MAJX;AAKC,IAAA,mBAAmB,EAAG,KALvB;AAMC,IAAA,kBAAkB,EAAG,KANtB;AAOC,IAAA,qBAAqB,MAPtB;AAAA,OAQMC,KARN;AASC,IAAA,WAAW,EAAG;AAAE,0BAAoBc;AAAtB,KATf;AAUC,IAAA,eAAe,EAAKE,kBAAF,IAA0B;AAC3C,UAAKA,kBAAkB,EAAEjB,QAAzB,EAAoC;AACnCI,QAAAA,gBAAgB,CAAEa,kBAAF,CAAhB;AACA;AACD;AAdF,IADD,EAiBC,4BAAC,2BAAD;AAAoB,IAAA,EAAE,EAAGF;AAAzB,KACGC,WADH,CAjBD,CADD;AAuBA,CA/EsB,CAAjB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useInstanceId } from '@wordpress/compose';\nimport { speak } from '@wordpress/a11y';\nimport { useSelect } from '@wordpress/data';\nimport { forwardRef, useEffect } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport useBlockDisplayTitle from '../block-title/use-block-display-title';\nimport { useListViewContext } from './context';\nimport Inserter from '../inserter';\nimport AriaReferencedText from './aria-referenced-text';\n\nexport const Appender = forwardRef(\n\t( { nestingLevel, blockCount, clientId, ...props }, ref ) => {\n\t\tconst { insertedBlock, setInsertedBlock } = useListViewContext();\n\n\t\tconst instanceId = useInstanceId( Appender );\n\t\tconst hideInserter = useSelect(\n\t\t\t( select ) => {\n\t\t\t\tconst { getTemplateLock, __unstableGetEditorMode } =\n\t\t\t\t\tselect( blockEditorStore );\n\n\t\t\t\treturn (\n\t\t\t\t\t!! getTemplateLock( clientId ) ||\n\t\t\t\t\t__unstableGetEditorMode() === 'zoom-out'\n\t\t\t\t);\n\t\t\t},\n\t\t\t[ clientId ]\n\t\t);\n\n\t\tconst blockTitle = useBlockDisplayTitle( {\n\t\t\tclientId,\n\t\t\tcontext: 'list-view',\n\t\t} );\n\n\t\tconst insertedBlockTitle = useBlockDisplayTitle( {\n\t\t\tclientId: insertedBlock?.clientId,\n\t\t\tcontext: 'list-view',\n\t\t} );\n\n\t\tuseEffect( () => {\n\t\t\tif ( ! insertedBlockTitle?.length ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tspeak(\n\t\t\t\tsprintf(\n\t\t\t\t\t// translators: %s: name of block being inserted (i.e. Paragraph, Image, Group etc)\n\t\t\t\t\t__( '%s block inserted' ),\n\t\t\t\t\tinsertedBlockTitle\n\t\t\t\t),\n\t\t\t\t'assertive'\n\t\t\t);\n\t\t}, [ insertedBlockTitle ] );\n\n\t\tif ( hideInserter ) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst descriptionId = `list-view-appender__${ instanceId }`;\n\t\tconst description = sprintf(\n\t\t\t/* translators: 1: The name of the block. 2: The numerical position of the block. 3: The level of nesting for the block. */\n\t\t\t__( 'Append to %1$s block at position %2$d, Level %3$d' ),\n\t\t\tblockTitle,\n\t\t\tblockCount + 1,\n\t\t\tnestingLevel\n\t\t);\n\n\t\treturn (\n\t\t\t<div className=\"list-view-appender\">\n\t\t\t\t<Inserter\n\t\t\t\t\tref={ ref }\n\t\t\t\t\trootClientId={ clientId }\n\t\t\t\t\tposition=\"bottom right\"\n\t\t\t\t\tisAppender\n\t\t\t\t\tselectBlockOnInsert={ false }\n\t\t\t\t\tshouldDirectInsert={ false }\n\t\t\t\t\t__experimentalIsQuick\n\t\t\t\t\t{ ...props }\n\t\t\t\t\ttoggleProps={ { 'aria-describedby': descriptionId } }\n\t\t\t\t\tonSelectOrClose={ ( maybeInsertedBlock ) => {\n\t\t\t\t\t\tif ( maybeInsertedBlock?.clientId ) {\n\t\t\t\t\t\t\tsetInsertedBlock( maybeInsertedBlock );\n\t\t\t\t\t\t}\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t\t<AriaReferencedText id={ descriptionId }>\n\t\t\t\t\t{ description }\n\t\t\t\t</AriaReferencedText>\n\t\t\t</div>\n\t\t);\n\t}\n);\n"]}
@@ -42,8 +42,11 @@ const ExperimentalBlockEditorProvider = (0, _withRegistryProvider.default)(props
42
42
  (0, _element.useEffect)(() => {
43
43
  __experimentalUpdateSettings({ ...settings,
44
44
  __internalIsInitialized: true
45
- }, stripExperimentalSettings);
46
- }, [settings]); // Syncs the entity provider with changes in the block-editor store.
45
+ }, {
46
+ stripExperimentalSettings,
47
+ reset: true
48
+ });
49
+ }, [settings, stripExperimentalSettings, __experimentalUpdateSettings]); // Syncs the entity provider with changes in the block-editor store.
47
50
 
48
51
  (0, _useBlockSync.default)(props);
49
52
  return (0, _element.createElement)(_blockRefsProvider.BlockRefsProvider, null, children);
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/provider/index.js"],"names":["ExperimentalBlockEditorProvider","props","children","settings","stripExperimentalSettings","__experimentalUpdateSettings","blockEditorStore","__internalIsInitialized","BlockEditorProvider"],"mappings":";;;;;;;;;AAIA;;AADA;;AAMA;;AACA;;AACA;;AACA;;AACA;;AAbA;AACA;AACA;;AAIA;AACA;AACA;;AAOA;AAEO,MAAMA,+BAA+B,GAAG,mCAC5CC,KAAF,IAAa;AACZ,QAAM;AAAEC,IAAAA,QAAF;AAAYC,IAAAA,QAAZ;AAAsBC,IAAAA,yBAAyB,GAAG;AAAlD,MAA4DH,KAAlE;AAEA,QAAM;AAAEI,IAAAA;AAAF,MAAmC,wBACxC,uBAAaC,YAAb,CADwC,CAAzC;AAGA,0BAAW,MAAM;AAChBD,IAAAA,4BAA4B,CAC3B,EACC,GAAGF,QADJ;AAECI,MAAAA,uBAAuB,EAAE;AAF1B,KAD2B,EAK3BH,yBAL2B,CAA5B;AAOA,GARD,EAQG,CAAED,QAAF,CARH,EANY,CAgBZ;;AACA,6BAAcF,KAAd;AAEA,SAAO,4BAAC,oCAAD,QAAqBC,QAArB,CAAP;AACA,CArB6C,CAAxC;;;AAwBA,MAAMM,mBAAmB,GAAKP,KAAF,IAAa;AAC/C,SACC,4BAAC,+BAAD,OACMA,KADN;AAEC,IAAA,yBAAyB,EAAG;AAF7B,KAIGA,KAAK,CAACC,QAJT,CADD;AAQA,CATM;;;eAWQM,mB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { useEffect } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport withRegistryProvider from './with-registry-provider';\nimport useBlockSync from './use-block-sync';\nimport { store as blockEditorStore } from '../../store';\nimport { BlockRefsProvider } from './block-refs-provider';\nimport { unlock } from '../../lock-unlock';\n\n/** @typedef {import('@wordpress/data').WPDataRegistry} WPDataRegistry */\n\nexport const ExperimentalBlockEditorProvider = withRegistryProvider(\n\t( props ) => {\n\t\tconst { children, settings, stripExperimentalSettings = false } = props;\n\n\t\tconst { __experimentalUpdateSettings } = unlock(\n\t\t\tuseDispatch( blockEditorStore )\n\t\t);\n\t\tuseEffect( () => {\n\t\t\t__experimentalUpdateSettings(\n\t\t\t\t{\n\t\t\t\t\t...settings,\n\t\t\t\t\t__internalIsInitialized: true,\n\t\t\t\t},\n\t\t\t\tstripExperimentalSettings\n\t\t\t);\n\t\t}, [ settings ] );\n\n\t\t// Syncs the entity provider with changes in the block-editor store.\n\t\tuseBlockSync( props );\n\n\t\treturn <BlockRefsProvider>{ children }</BlockRefsProvider>;\n\t}\n);\n\nexport const BlockEditorProvider = ( props ) => {\n\treturn (\n\t\t<ExperimentalBlockEditorProvider\n\t\t\t{ ...props }\n\t\t\tstripExperimentalSettings={ true }\n\t\t>\n\t\t\t{ props.children }\n\t\t</ExperimentalBlockEditorProvider>\n\t);\n};\n\nexport default BlockEditorProvider;\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/provider/index.js"],"names":["ExperimentalBlockEditorProvider","props","children","settings","stripExperimentalSettings","__experimentalUpdateSettings","blockEditorStore","__internalIsInitialized","reset","BlockEditorProvider"],"mappings":";;;;;;;;;AAIA;;AADA;;AAMA;;AACA;;AACA;;AACA;;AACA;;AAbA;AACA;AACA;;AAIA;AACA;AACA;;AAOA;AAEO,MAAMA,+BAA+B,GAAG,mCAC5CC,KAAF,IAAa;AACZ,QAAM;AAAEC,IAAAA,QAAF;AAAYC,IAAAA,QAAZ;AAAsBC,IAAAA,yBAAyB,GAAG;AAAlD,MAA4DH,KAAlE;AAEA,QAAM;AAAEI,IAAAA;AAAF,MAAmC,wBACxC,uBAAaC,YAAb,CADwC,CAAzC;AAGA,0BAAW,MAAM;AAChBD,IAAAA,4BAA4B,CAC3B,EACC,GAAGF,QADJ;AAECI,MAAAA,uBAAuB,EAAE;AAF1B,KAD2B,EAK3B;AACCH,MAAAA,yBADD;AAECI,MAAAA,KAAK,EAAE;AAFR,KAL2B,CAA5B;AAUA,GAXD,EAWG,CACFL,QADE,EAEFC,yBAFE,EAGFC,4BAHE,CAXH,EANY,CAuBZ;;AACA,6BAAcJ,KAAd;AAEA,SAAO,4BAAC,oCAAD,QAAqBC,QAArB,CAAP;AACA,CA5B6C,CAAxC;;;AA+BA,MAAMO,mBAAmB,GAAKR,KAAF,IAAa;AAC/C,SACC,4BAAC,+BAAD,OACMA,KADN;AAEC,IAAA,yBAAyB,EAAG;AAF7B,KAIGA,KAAK,CAACC,QAJT,CADD;AAQA,CATM;;;eAWQO,mB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { useEffect } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport withRegistryProvider from './with-registry-provider';\nimport useBlockSync from './use-block-sync';\nimport { store as blockEditorStore } from '../../store';\nimport { BlockRefsProvider } from './block-refs-provider';\nimport { unlock } from '../../lock-unlock';\n\n/** @typedef {import('@wordpress/data').WPDataRegistry} WPDataRegistry */\n\nexport const ExperimentalBlockEditorProvider = withRegistryProvider(\n\t( props ) => {\n\t\tconst { children, settings, stripExperimentalSettings = false } = props;\n\n\t\tconst { __experimentalUpdateSettings } = unlock(\n\t\t\tuseDispatch( blockEditorStore )\n\t\t);\n\t\tuseEffect( () => {\n\t\t\t__experimentalUpdateSettings(\n\t\t\t\t{\n\t\t\t\t\t...settings,\n\t\t\t\t\t__internalIsInitialized: true,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tstripExperimentalSettings,\n\t\t\t\t\treset: true,\n\t\t\t\t}\n\t\t\t);\n\t\t}, [\n\t\t\tsettings,\n\t\t\tstripExperimentalSettings,\n\t\t\t__experimentalUpdateSettings,\n\t\t] );\n\n\t\t// Syncs the entity provider with changes in the block-editor store.\n\t\tuseBlockSync( props );\n\n\t\treturn <BlockRefsProvider>{ children }</BlockRefsProvider>;\n\t}\n);\n\nexport const BlockEditorProvider = ( props ) => {\n\treturn (\n\t\t<ExperimentalBlockEditorProvider\n\t\t\t{ ...props }\n\t\t\tstripExperimentalSettings={ true }\n\t\t>\n\t\t\t{ props.children }\n\t\t</ExperimentalBlockEditorProvider>\n\t);\n};\n\nexport default BlockEditorProvider;\n"]}
@@ -141,6 +141,22 @@ function useBlockSync({
141
141
 
142
142
  resetBlocks(controlledBlocks);
143
143
  }
144
+ }; // Clean up the changes made by setControlledBlocks() when the component
145
+ // containing useBlockSync() unmounts.
146
+
147
+
148
+ const unsetControlledBlocks = () => {
149
+ __unstableMarkNextChangeAsNotPersistent();
150
+
151
+ if (clientId) {
152
+ setHasControlledInnerBlocks(clientId, false);
153
+
154
+ __unstableMarkNextChangeAsNotPersistent();
155
+
156
+ replaceInnerBlocks(clientId, []);
157
+ } else {
158
+ resetBlocks([]);
159
+ }
144
160
  }; // Add a subscription to the block-editor registry to detect when changes
145
161
  // have been made. This lets us inform the data source of changes. This
146
162
  // is an effect so that the subscriber can run synchronously without
@@ -269,5 +285,10 @@ function useBlockSync({
269
285
  unsubscribe();
270
286
  };
271
287
  }, [registry, clientId]);
288
+ (0, _element.useEffect)(() => {
289
+ return () => {
290
+ unsetControlledBlocks();
291
+ };
292
+ }, []);
272
293
  }
273
294
  //# sourceMappingURL=use-block-sync.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/provider/use-block-sync.js"],"names":["noop","useBlockSync","clientId","value","controlledBlocks","selection","controlledSelection","onChange","onInput","registry","resetBlocks","resetSelection","replaceInnerBlocks","selectBlock","setHasControlledInnerBlocks","__unstableMarkNextChangeAsNotPersistent","dispatch","blockEditorStore","hasSelectedBlock","getBlockName","getBlocks","getSelectionStart","getSelectionEnd","getBlock","select","isControlled","areInnerBlocksControlled","pendingChanges","incoming","outgoing","subscribed","setControlledBlocks","batch","storeBlocks","map","block","current","onInputRef","onChangeRef","includes","length","hadSelecton","selectionAnchor","selectionFocus","selectionStart","selectionEnd","initialPosition","selectionStillExists","getSelectedBlocksInitialCaretPosition","isLastBlockChangePersistent","__unstableIsLastBlockChangeIgnored","blocks","isPersistent","previousAreBlocksDifferent","unsubscribe","subscribe","isStillControlled","newIsPersistent","newBlocks","areBlocksDifferent","didPersistenceChange","push","updateParent"],"mappings":";;;;;;;AAGA;;AACA;;AACA;;AAKA;;AAVA;AACA;AACA;;AAKA;AACA;AACA;AAGA,MAAMA,IAAI,GAAG,MAAM,CAAE,CAArB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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C,UAAU,CAACD,OAFd;AAGA0B,QAAAA,YAAY,CAAEX,MAAF,EAAU;AACrB9C,UAAAA,SAAS,EAAE;AACVuC,YAAAA,cAAc,EAAEvB,iBAAiB,EADvB;AAEVwB,YAAAA,YAAY,EAAEvB,eAAe,EAFnB;AAGVwB,YAAAA,eAAe,EACdE,qCAAqC;AAJ5B;AADU,SAAV,CAAZ;AAQA;;AACDK,MAAAA,0BAA0B,GAAGM,kBAA7B;AACA,KAnEmB,CAApB;AAqEA,WAAO,MAAM;AACZ7B,MAAAA,UAAU,CAACM,OAAX,GAAqB,KAArB;AACAkB,MAAAA,WAAW;AACX,KAHD;AAIA,GAtFD,EAsFG,CAAE7C,QAAF,EAAYP,QAAZ,CAtFH;AAuFA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useEffect, useRef } from '@wordpress/element';\nimport { useRegistry, useSelect } from '@wordpress/data';\nimport { cloneBlock } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\n\nconst noop = () => {};\n\n/**\n * A function to call when the block value has been updated in the block-editor\n * store.\n *\n * @callback onBlockUpdate\n * @param {Object[]} blocks The updated blocks.\n * @param {Object} options The updated block options, such as selectionStart\n * and selectionEnd.\n */\n\n/**\n * useBlockSync is a side effect which handles bidirectional sync between the\n * block-editor store and a controlling data source which provides blocks. This\n * is most commonly used by the BlockEditorProvider to synchronize the contents\n * of the block-editor store with the root entity, like a post.\n *\n * Another example would be the template part block, which provides blocks from\n * a separate entity data source than a root entity. This hook syncs edits to\n * the template part in the block editor back to the entity and vice-versa.\n *\n * Here are some of its basic functions:\n * - Initalizes the block-editor store for the given clientID to the blocks\n * given via props.\n * - Adds incoming changes (like undo) to the block-editor store.\n * - Adds outgoing changes (like editing content) to the controlling entity,\n * determining if a change should be considered persistent or not.\n * - Handles edge cases and race conditions which occur in those operations.\n * - Ignores changes which happen to other entities (like nested inner block\n * controllers.\n * - Passes selection state from the block-editor store to the controlling entity.\n *\n * @param {Object} props Props for the block sync hook\n * @param {string} props.clientId The client ID of the inner block controller.\n * If none is passed, then it is assumed to be a\n * root controller rather than an inner block\n * controller.\n * @param {Object[]} props.value The control value for the blocks. This value\n * is used to initalize the block-editor store\n * and for resetting the blocks to incoming\n * changes like undo.\n * @param {Object} props.selection The selection state responsible to restore the selection on undo/redo.\n * @param {onBlockUpdate} props.onChange Function to call when a persistent\n * change has been made in the block-editor blocks\n * for the given clientId. For example, after\n * this function is called, an entity is marked\n * dirty because it has changes to save.\n * @param {onBlockUpdate} props.onInput Function to call when a non-persistent\n * change has been made in the block-editor blocks\n * for the given clientId. When this is called,\n * controlling sources do not become dirty.\n */\nexport default function useBlockSync( {\n\tclientId = null,\n\tvalue: controlledBlocks,\n\tselection: controlledSelection,\n\tonChange = noop,\n\tonInput = noop,\n} ) {\n\tconst registry = useRegistry();\n\n\tconst {\n\t\tresetBlocks,\n\t\tresetSelection,\n\t\treplaceInnerBlocks,\n\t\tselectBlock,\n\t\tsetHasControlledInnerBlocks,\n\t\t__unstableMarkNextChangeAsNotPersistent,\n\t} = registry.dispatch( blockEditorStore );\n\tconst {\n\t\thasSelectedBlock,\n\t\tgetBlockName,\n\t\tgetBlocks,\n\t\tgetSelectionStart,\n\t\tgetSelectionEnd,\n\t\tgetBlock,\n\t} = registry.select( blockEditorStore );\n\tconst isControlled = useSelect(\n\t\t( select ) => {\n\t\t\treturn (\n\t\t\t\t! clientId ||\n\t\t\t\tselect( blockEditorStore ).areInnerBlocksControlled( clientId )\n\t\t\t);\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst pendingChanges = useRef( { incoming: null, outgoing: [] } );\n\tconst subscribed = useRef( false );\n\n\tconst setControlledBlocks = () => {\n\t\tif ( ! controlledBlocks ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// We don't need to persist this change because we only replace\n\t\t// controlled inner blocks when the change was caused by an entity,\n\t\t// and so it would already be persisted.\n\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\tif ( clientId ) {\n\t\t\t// It is important to batch here because otherwise,\n\t\t\t// as soon as `setHasControlledInnerBlocks` is called\n\t\t\t// the effect to restore might be triggered\n\t\t\t// before the actual blocks get set properly in state.\n\t\t\tregistry.batch( () => {\n\t\t\t\tsetHasControlledInnerBlocks( clientId, true );\n\t\t\t\tconst storeBlocks = controlledBlocks.map( ( block ) =>\n\t\t\t\t\tcloneBlock( block )\n\t\t\t\t);\n\t\t\t\tif ( subscribed.current ) {\n\t\t\t\t\tpendingChanges.current.incoming = storeBlocks;\n\t\t\t\t}\n\t\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\t\treplaceInnerBlocks( clientId, storeBlocks );\n\t\t\t} );\n\t\t} else {\n\t\t\tif ( subscribed.current ) {\n\t\t\t\tpendingChanges.current.incoming = controlledBlocks;\n\t\t\t}\n\t\t\tresetBlocks( controlledBlocks );\n\t\t}\n\t};\n\n\t// Add a subscription to the block-editor registry to detect when changes\n\t// have been made. This lets us inform the data source of changes. This\n\t// is an effect so that the subscriber can run synchronously without\n\t// waiting for React renders for changes.\n\tconst onInputRef = useRef( onInput );\n\tconst onChangeRef = useRef( onChange );\n\tuseEffect( () => {\n\t\tonInputRef.current = onInput;\n\t\tonChangeRef.current = onChange;\n\t}, [ onInput, onChange ] );\n\n\t// Determine if blocks need to be reset when they change.\n\tuseEffect( () => {\n\t\tif ( pendingChanges.current.outgoing.includes( controlledBlocks ) ) {\n\t\t\t// Skip block reset if the value matches expected outbound sync\n\t\t\t// triggered by this component by a preceding change detection.\n\t\t\t// Only skip if the value matches expectation, since a reset should\n\t\t\t// still occur if the value is modified (not equal by reference),\n\t\t\t// to allow that the consumer may apply modifications to reflect\n\t\t\t// back on the editor.\n\t\t\tif (\n\t\t\t\tpendingChanges.current.outgoing[\n\t\t\t\t\tpendingChanges.current.outgoing.length - 1\n\t\t\t\t] === controlledBlocks\n\t\t\t) {\n\t\t\t\tpendingChanges.current.outgoing = [];\n\t\t\t}\n\t\t} else if ( getBlocks( clientId ) !== controlledBlocks ) {\n\t\t\t// Reset changing value in all other cases than the sync described\n\t\t\t// above. Since this can be reached in an update following an out-\n\t\t\t// bound sync, unset the outbound value to avoid considering it in\n\t\t\t// subsequent renders.\n\t\t\tpendingChanges.current.outgoing = [];\n\t\t\tconst hadSelecton = hasSelectedBlock();\n\t\t\tconst selectionAnchor = getSelectionStart();\n\t\t\tconst selectionFocus = getSelectionEnd();\n\t\t\tsetControlledBlocks();\n\n\t\t\tif ( controlledSelection ) {\n\t\t\t\tresetSelection(\n\t\t\t\t\tcontrolledSelection.selectionStart,\n\t\t\t\t\tcontrolledSelection.selectionEnd,\n\t\t\t\t\tcontrolledSelection.initialPosition\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tconst selectionStillExists = getBlock(\n\t\t\t\t\tselectionAnchor.clientId\n\t\t\t\t);\n\t\t\t\tif ( hadSelecton && ! selectionStillExists ) {\n\t\t\t\t\tselectBlock( clientId );\n\t\t\t\t} else {\n\t\t\t\t\tresetSelection( selectionAnchor, selectionFocus );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}, [ controlledBlocks, clientId ] );\n\n\tuseEffect( () => {\n\t\t// When the block becomes uncontrolled, it means its inner state has been reset\n\t\t// we need to take the blocks again from the external value property.\n\t\tif ( ! isControlled ) {\n\t\t\tpendingChanges.current.outgoing = [];\n\t\t\tsetControlledBlocks();\n\t\t}\n\t}, [ isControlled ] );\n\n\tuseEffect( () => {\n\t\tconst {\n\t\t\tgetSelectedBlocksInitialCaretPosition,\n\t\t\tisLastBlockChangePersistent,\n\t\t\t__unstableIsLastBlockChangeIgnored,\n\t\t\tareInnerBlocksControlled,\n\t\t} = registry.select( blockEditorStore );\n\n\t\tlet blocks = getBlocks( clientId );\n\t\tlet isPersistent = isLastBlockChangePersistent();\n\t\tlet previousAreBlocksDifferent = false;\n\n\t\tsubscribed.current = true;\n\t\tconst unsubscribe = registry.subscribe( () => {\n\t\t\t// Sometimes, when changing block lists, lingering subscriptions\n\t\t\t// might trigger before they are cleaned up. If the block for which\n\t\t\t// the subscription runs is no longer in the store, this would clear\n\t\t\t// its parent entity's block list. To avoid this, we bail out if\n\t\t\t// the subscription is triggering for a block (`clientId !== null`)\n\t\t\t// and its block name can't be found because it's not on the list.\n\t\t\t// (`getBlockName( clientId ) === null`).\n\t\t\tif ( clientId !== null && getBlockName( clientId ) === null )\n\t\t\t\treturn;\n\n\t\t\t// When RESET_BLOCKS on parent blocks get called, the controlled blocks\n\t\t\t// can reset to uncontrolled, in these situations, it means we need to populate\n\t\t\t// the blocks again from the external blocks (the value property here)\n\t\t\t// and we should stop triggering onChange\n\t\t\tconst isStillControlled =\n\t\t\t\t! clientId || areInnerBlocksControlled( clientId );\n\t\t\tif ( ! isStillControlled ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst newIsPersistent = isLastBlockChangePersistent();\n\t\t\tconst newBlocks = getBlocks( clientId );\n\t\t\tconst areBlocksDifferent = newBlocks !== blocks;\n\t\t\tblocks = newBlocks;\n\t\t\tif (\n\t\t\t\tareBlocksDifferent &&\n\t\t\t\t( pendingChanges.current.incoming ||\n\t\t\t\t\t__unstableIsLastBlockChangeIgnored() )\n\t\t\t) {\n\t\t\t\tpendingChanges.current.incoming = null;\n\t\t\t\tisPersistent = newIsPersistent;\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Since we often dispatch an action to mark the previous action as\n\t\t\t// persistent, we need to make sure that the blocks changed on the\n\t\t\t// previous action before committing the change.\n\t\t\tconst didPersistenceChange =\n\t\t\t\tpreviousAreBlocksDifferent &&\n\t\t\t\t! areBlocksDifferent &&\n\t\t\t\tnewIsPersistent &&\n\t\t\t\t! isPersistent;\n\n\t\t\tif ( areBlocksDifferent || didPersistenceChange ) {\n\t\t\t\tisPersistent = newIsPersistent;\n\t\t\t\t// We know that onChange/onInput will update controlledBlocks.\n\t\t\t\t// We need to be aware that it was caused by an outgoing change\n\t\t\t\t// so that we do not treat it as an incoming change later on,\n\t\t\t\t// which would cause a block reset.\n\t\t\t\tpendingChanges.current.outgoing.push( blocks );\n\n\t\t\t\t// Inform the controlling entity that changes have been made to\n\t\t\t\t// the block-editor store they should be aware about.\n\t\t\t\tconst updateParent = isPersistent\n\t\t\t\t\t? onChangeRef.current\n\t\t\t\t\t: onInputRef.current;\n\t\t\t\tupdateParent( blocks, {\n\t\t\t\t\tselection: {\n\t\t\t\t\t\tselectionStart: getSelectionStart(),\n\t\t\t\t\t\tselectionEnd: getSelectionEnd(),\n\t\t\t\t\t\tinitialPosition:\n\t\t\t\t\t\t\tgetSelectedBlocksInitialCaretPosition(),\n\t\t\t\t\t},\n\t\t\t\t} );\n\t\t\t}\n\t\t\tpreviousAreBlocksDifferent = areBlocksDifferent;\n\t\t} );\n\n\t\treturn () => {\n\t\t\tsubscribed.current = false;\n\t\t\tunsubscribe();\n\t\t};\n\t}, [ registry, clientId ] );\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/provider/use-block-sync.js"],"names":["noop","useBlockSync","clientId","value","controlledBlocks","selection","controlledSelection","onChange","onInput","registry","resetBlocks","resetSelection","replaceInnerBlocks","selectBlock","setHasControlledInnerBlocks","__unstableMarkNextChangeAsNotPersistent","dispatch","blockEditorStore","hasSelectedBlock","getBlockName","getBlocks","getSelectionStart","getSelectionEnd","getBlock","select","isControlled","areInnerBlocksControlled","pendingChanges","incoming","outgoing","subscribed","setControlledBlocks","batch","storeBlocks","map","block","current","unsetControlledBlocks","onInputRef","onChangeRef","includes","length","hadSelecton","selectionAnchor","selectionFocus","selectionStart","selectionEnd","initialPosition","selectionStillExists","getSelectedBlocksInitialCaretPosition","isLastBlockChangePersistent","__unstableIsLastBlockChangeIgnored","blocks","isPersistent","previousAreBlocksDifferent","unsubscribe","subscribe","isStillControlled","newIsPersistent","newBlocks","areBlocksDifferent","didPersistenceChange","push","updateParent"],"mappings":";;;;;;;AAGA;;AACA;;AACA;;AAKA;;AAVA;AACA;AACA;;AAKA;AACA;AACA;AAGA,MAA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AACS,OAAf,CAAuBR,QAAvB,GAAkC,IAAlC;AACAyB,QAAAA,YAAY,GAAGK,eAAf;AACA;AACA,OAjC4C,CAmC7C;AACA;AACA;;;AACA,YAAMG,oBAAoB,GACzBP,0BAA0B,IAC1B,CAAEM,kBADF,IAEAF,eAFA,IAGA,CAAEL,YAJH;;AAMA,UAAKO,kBAAkB,IAAIC,oBAA3B,EAAkD;AACjDR,QAAAA,YAAY,GAAGK,eAAf,CADiD,CAEjD;AACA;AACA;AACA;;AACA/B,QAAAA,cAAc,CAACS,OAAf,CAAuBP,QAAvB,CAAgCiC,IAAhC,CAAsCV,MAAtC,EANiD,CAQjD;AACA;;AACA,cAAMW,YAAY,GAAGV,YAAY,GAC9Bd,WAAW,CAACH,OADkB,GAE9BE,UAAU,CAACF,OAFd;AAGA2B,QAAAA,YAAY,CAAEX,MAAF,EAAU;AACrB/C,UAAAA,SAAS,EAAE;AACVwC,YAAAA,cAAc,EAAExB,iBAAiB,EADvB;AAEVyB,YAAAA,YAAY,EAAExB,eAAe,EAFnB;AAGVyB,YAAAA,eAAe,EACdE,qCAAqC;AAJ5B;AADU,SAAV,CAAZ;AAQA;;AACDK,MAAAA,0BAA0B,GAAGM,kBAA7B;AACA,KAnEmB,CAApB;AAqEA,WAAO,MAAM;AACZ9B,MAAAA,UAAU,CAACM,OAAX,GAAqB,KAArB;AACAmB,MAAAA,WAAW;AACX,KAHD;AAIA,GAtFD,EAsFG,CAAE9C,QAAF,EAAYP,QAAZ,CAtFH;AAwFA,0BAAW,MAAM;AAChB,WAAO,MAAM;AACZmC,MAAAA,qBAAqB;AACrB,KAFD;AAGA,GAJD,EAIG,EAJH;AAKA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useEffect, useRef } from '@wordpress/element';\nimport { useRegistry, useSelect } from '@wordpress/data';\nimport { cloneBlock } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\n\nconst noop = () => {};\n\n/**\n * A function to call when the block value has been updated in the block-editor\n * store.\n *\n * @callback onBlockUpdate\n * @param {Object[]} blocks The updated blocks.\n * @param {Object} options The updated block options, such as selectionStart\n * and selectionEnd.\n */\n\n/**\n * useBlockSync is a side effect which handles bidirectional sync between the\n * block-editor store and a controlling data source which provides blocks. This\n * is most commonly used by the BlockEditorProvider to synchronize the contents\n * of the block-editor store with the root entity, like a post.\n *\n * Another example would be the template part block, which provides blocks from\n * a separate entity data source than a root entity. This hook syncs edits to\n * the template part in the block editor back to the entity and vice-versa.\n *\n * Here are some of its basic functions:\n * - Initalizes the block-editor store for the given clientID to the blocks\n * given via props.\n * - Adds incoming changes (like undo) to the block-editor store.\n * - Adds outgoing changes (like editing content) to the controlling entity,\n * determining if a change should be considered persistent or not.\n * - Handles edge cases and race conditions which occur in those operations.\n * - Ignores changes which happen to other entities (like nested inner block\n * controllers.\n * - Passes selection state from the block-editor store to the controlling entity.\n *\n * @param {Object} props Props for the block sync hook\n * @param {string} props.clientId The client ID of the inner block controller.\n * If none is passed, then it is assumed to be a\n * root controller rather than an inner block\n * controller.\n * @param {Object[]} props.value The control value for the blocks. This value\n * is used to initalize the block-editor store\n * and for resetting the blocks to incoming\n * changes like undo.\n * @param {Object} props.selection The selection state responsible to restore the selection on undo/redo.\n * @param {onBlockUpdate} props.onChange Function to call when a persistent\n * change has been made in the block-editor blocks\n * for the given clientId. For example, after\n * this function is called, an entity is marked\n * dirty because it has changes to save.\n * @param {onBlockUpdate} props.onInput Function to call when a non-persistent\n * change has been made in the block-editor blocks\n * for the given clientId. When this is called,\n * controlling sources do not become dirty.\n */\nexport default function useBlockSync( {\n\tclientId = null,\n\tvalue: controlledBlocks,\n\tselection: controlledSelection,\n\tonChange = noop,\n\tonInput = noop,\n} ) {\n\tconst registry = useRegistry();\n\n\tconst {\n\t\tresetBlocks,\n\t\tresetSelection,\n\t\treplaceInnerBlocks,\n\t\tselectBlock,\n\t\tsetHasControlledInnerBlocks,\n\t\t__unstableMarkNextChangeAsNotPersistent,\n\t} = registry.dispatch( blockEditorStore );\n\tconst {\n\t\thasSelectedBlock,\n\t\tgetBlockName,\n\t\tgetBlocks,\n\t\tgetSelectionStart,\n\t\tgetSelectionEnd,\n\t\tgetBlock,\n\t} = registry.select( blockEditorStore );\n\tconst isControlled = useSelect(\n\t\t( select ) => {\n\t\t\treturn (\n\t\t\t\t! clientId ||\n\t\t\t\tselect( blockEditorStore ).areInnerBlocksControlled( clientId )\n\t\t\t);\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst pendingChanges = useRef( { incoming: null, outgoing: [] } );\n\tconst subscribed = useRef( false );\n\n\tconst setControlledBlocks = () => {\n\t\tif ( ! controlledBlocks ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// We don't need to persist this change because we only replace\n\t\t// controlled inner blocks when the change was caused by an entity,\n\t\t// and so it would already be persisted.\n\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\tif ( clientId ) {\n\t\t\t// It is important to batch here because otherwise,\n\t\t\t// as soon as `setHasControlledInnerBlocks` is called\n\t\t\t// the effect to restore might be triggered\n\t\t\t// before the actual blocks get set properly in state.\n\t\t\tregistry.batch( () => {\n\t\t\t\tsetHasControlledInnerBlocks( clientId, true );\n\t\t\t\tconst storeBlocks = controlledBlocks.map( ( block ) =>\n\t\t\t\t\tcloneBlock( block )\n\t\t\t\t);\n\t\t\t\tif ( subscribed.current ) {\n\t\t\t\t\tpendingChanges.current.incoming = storeBlocks;\n\t\t\t\t}\n\t\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\t\treplaceInnerBlocks( clientId, storeBlocks );\n\t\t\t} );\n\t\t} else {\n\t\t\tif ( subscribed.current ) {\n\t\t\t\tpendingChanges.current.incoming = controlledBlocks;\n\t\t\t}\n\t\t\tresetBlocks( controlledBlocks );\n\t\t}\n\t};\n\n\t// Clean up the changes made by setControlledBlocks() when the component\n\t// containing useBlockSync() unmounts.\n\tconst unsetControlledBlocks = () => {\n\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\tif ( clientId ) {\n\t\t\tsetHasControlledInnerBlocks( clientId, false );\n\t\t\t__unstableMarkNextChangeAsNotPersistent();\n\t\t\treplaceInnerBlocks( clientId, [] );\n\t\t} else {\n\t\t\tresetBlocks( [] );\n\t\t}\n\t};\n\n\t// Add a subscription to the block-editor registry to detect when changes\n\t// have been made. This lets us inform the data source of changes. This\n\t// is an effect so that the subscriber can run synchronously without\n\t// waiting for React renders for changes.\n\tconst onInputRef = useRef( onInput );\n\tconst onChangeRef = useRef( onChange );\n\tuseEffect( () => {\n\t\tonInputRef.current = onInput;\n\t\tonChangeRef.current = onChange;\n\t}, [ onInput, onChange ] );\n\n\t// Determine if blocks need to be reset when they change.\n\tuseEffect( () => {\n\t\tif ( pendingChanges.current.outgoing.includes( controlledBlocks ) ) {\n\t\t\t// Skip block reset if the value matches expected outbound sync\n\t\t\t// triggered by this component by a preceding change detection.\n\t\t\t// Only skip if the value matches expectation, since a reset should\n\t\t\t// still occur if the value is modified (not equal by reference),\n\t\t\t// to allow that the consumer may apply modifications to reflect\n\t\t\t// back on the editor.\n\t\t\tif (\n\t\t\t\tpendingChanges.current.outgoing[\n\t\t\t\t\tpendingChanges.current.outgoing.length - 1\n\t\t\t\t] === controlledBlocks\n\t\t\t) {\n\t\t\t\tpendingChanges.current.outgoing = [];\n\t\t\t}\n\t\t} else if ( getBlocks( clientId ) !== controlledBlocks ) {\n\t\t\t// Reset changing value in all other cases than the sync described\n\t\t\t// above. Since this can be reached in an update following an out-\n\t\t\t// bound sync, unset the outbound value to avoid considering it in\n\t\t\t// subsequent renders.\n\t\t\tpendingChanges.current.outgoing = [];\n\t\t\tconst hadSelecton = hasSelectedBlock();\n\t\t\tconst selectionAnchor = getSelectionStart();\n\t\t\tconst selectionFocus = getSelectionEnd();\n\t\t\tsetControlledBlocks();\n\n\t\t\tif ( controlledSelection ) {\n\t\t\t\tresetSelection(\n\t\t\t\t\tcontrolledSelection.selectionStart,\n\t\t\t\t\tcontrolledSelection.selectionEnd,\n\t\t\t\t\tcontrolledSelection.initialPosition\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tconst selectionStillExists = getBlock(\n\t\t\t\t\tselectionAnchor.clientId\n\t\t\t\t);\n\t\t\t\tif ( hadSelecton && ! selectionStillExists ) {\n\t\t\t\t\tselectBlock( clientId );\n\t\t\t\t} else {\n\t\t\t\t\tresetSelection( selectionAnchor, selectionFocus );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}, [ controlledBlocks, clientId ] );\n\n\tuseEffect( () => {\n\t\t// When the block becomes uncontrolled, it means its inner state has been reset\n\t\t// we need to take the blocks again from the external value property.\n\t\tif ( ! isControlled ) {\n\t\t\tpendingChanges.current.outgoing = [];\n\t\t\tsetControlledBlocks();\n\t\t}\n\t}, [ isControlled ] );\n\n\tuseEffect( () => {\n\t\tconst {\n\t\t\tgetSelectedBlocksInitialCaretPosition,\n\t\t\tisLastBlockChangePersistent,\n\t\t\t__unstableIsLastBlockChangeIgnored,\n\t\t\tareInnerBlocksControlled,\n\t\t} = registry.select( blockEditorStore );\n\n\t\tlet blocks = getBlocks( clientId );\n\t\tlet isPersistent = isLastBlockChangePersistent();\n\t\tlet previousAreBlocksDifferent = false;\n\n\t\tsubscribed.current = true;\n\t\tconst unsubscribe = registry.subscribe( () => {\n\t\t\t// Sometimes, when changing block lists, lingering subscriptions\n\t\t\t// might trigger before they are cleaned up. If the block for which\n\t\t\t// the subscription runs is no longer in the store, this would clear\n\t\t\t// its parent entity's block list. To avoid this, we bail out if\n\t\t\t// the subscription is triggering for a block (`clientId !== null`)\n\t\t\t// and its block name can't be found because it's not on the list.\n\t\t\t// (`getBlockName( clientId ) === null`).\n\t\t\tif ( clientId !== null && getBlockName( clientId ) === null )\n\t\t\t\treturn;\n\n\t\t\t// When RESET_BLOCKS on parent blocks get called, the controlled blocks\n\t\t\t// can reset to uncontrolled, in these situations, it means we need to populate\n\t\t\t// the blocks again from the external blocks (the value property here)\n\t\t\t// and we should stop triggering onChange\n\t\t\tconst isStillControlled =\n\t\t\t\t! clientId || areInnerBlocksControlled( clientId );\n\t\t\tif ( ! isStillControlled ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst newIsPersistent = isLastBlockChangePersistent();\n\t\t\tconst newBlocks = getBlocks( clientId );\n\t\t\tconst areBlocksDifferent = newBlocks !== blocks;\n\t\t\tblocks = newBlocks;\n\t\t\tif (\n\t\t\t\tareBlocksDifferent &&\n\t\t\t\t( pendingChanges.current.incoming ||\n\t\t\t\t\t__unstableIsLastBlockChangeIgnored() )\n\t\t\t) {\n\t\t\t\tpendingChanges.current.incoming = null;\n\t\t\t\tisPersistent = newIsPersistent;\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Since we often dispatch an action to mark the previous action as\n\t\t\t// persistent, we need to make sure that the blocks changed on the\n\t\t\t// previous action before committing the change.\n\t\t\tconst didPersistenceChange =\n\t\t\t\tpreviousAreBlocksDifferent &&\n\t\t\t\t! areBlocksDifferent &&\n\t\t\t\tnewIsPersistent &&\n\t\t\t\t! isPersistent;\n\n\t\t\tif ( areBlocksDifferent || didPersistenceChange ) {\n\t\t\t\tisPersistent = newIsPersistent;\n\t\t\t\t// We know that onChange/onInput will update controlledBlocks.\n\t\t\t\t// We need to be aware that it was caused by an outgoing change\n\t\t\t\t// so that we do not treat it as an incoming change later on,\n\t\t\t\t// which would cause a block reset.\n\t\t\t\tpendingChanges.current.outgoing.push( blocks );\n\n\t\t\t\t// Inform the controlling entity that changes have been made to\n\t\t\t\t// the block-editor store they should be aware about.\n\t\t\t\tconst updateParent = isPersistent\n\t\t\t\t\t? onChangeRef.current\n\t\t\t\t\t: onInputRef.current;\n\t\t\t\tupdateParent( blocks, {\n\t\t\t\t\tselection: {\n\t\t\t\t\t\tselectionStart: getSelectionStart(),\n\t\t\t\t\t\tselectionEnd: getSelectionEnd(),\n\t\t\t\t\t\tinitialPosition:\n\t\t\t\t\t\t\tgetSelectedBlocksInitialCaretPosition(),\n\t\t\t\t\t},\n\t\t\t\t} );\n\t\t\t}\n\t\t\tpreviousAreBlocksDifferent = areBlocksDifferent;\n\t\t} );\n\n\t\treturn () => {\n\t\t\tsubscribed.current = false;\n\t\t\tunsubscribe();\n\t\t};\n\t}, [ registry, clientId ] );\n\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tunsetControlledBlocks();\n\t\t};\n\t}, [] );\n}\n"]}
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = ResolutionTool;
7
+
8
+ var _element = require("@wordpress/element");
9
+
10
+ var _components = require("@wordpress/components");
11
+
12
+ var _i18n = require("@wordpress/i18n");
13
+
14
+ /**
15
+ * WordPress dependencies
16
+ */
17
+ const DEFAULT_SIZE_OPTIONS = [{
18
+ label: (0, _i18n._x)('Thumbnail', 'Image size option for resolution control'),
19
+ value: 'thumbnail'
20
+ }, {
21
+ label: (0, _i18n._x)('Medium', 'Image size option for resolution control'),
22
+ value: 'medium'
23
+ }, {
24
+ label: (0, _i18n._x)('Large', 'Image size option for resolution control'),
25
+ value: 'large'
26
+ }, {
27
+ label: (0, _i18n._x)('Full Size', 'Image size option for resolution control'),
28
+ value: 'full'
29
+ }];
30
+
31
+ function ResolutionTool({
32
+ panelId,
33
+ value,
34
+ onChange,
35
+ options = DEFAULT_SIZE_OPTIONS,
36
+ defaultValue = DEFAULT_SIZE_OPTIONS[0].value,
37
+ isShownByDefault = true
38
+ }) {
39
+ const displayValue = value !== null && value !== void 0 ? value : defaultValue;
40
+ return (0, _element.createElement)(_components.__experimentalToolsPanelItem, {
41
+ hasValue: () => displayValue !== defaultValue,
42
+ label: (0, _i18n.__)('Resolution'),
43
+ onDeselect: () => onChange(defaultValue),
44
+ isShownByDefault: isShownByDefault,
45
+ panelId: panelId
46
+ }, (0, _element.createElement)(_components.SelectControl, {
47
+ label: (0, _i18n.__)('Resolution'),
48
+ value: displayValue,
49
+ options: options,
50
+ onChange: onChange,
51
+ help: (0, _i18n.__)('Select the size of the source image.'),
52
+ size: '__unstable-large'
53
+ }));
54
+ }
55
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/resolution-tool/index.js"],"names":["DEFAULT_SIZE_OPTIONS","label","value","ResolutionTool","panelId","onChange","options","defaultValue","isShownByDefault","displayValue"],"mappings":";;;;;;;;;AAGA;;AAIA;;AAPA;AACA;AACA;AAOA,MAAMA,oBAAoB,GAAG,CAC5B;AACCC,EAAAA,KAAK,EAAE,cAAI,WAAJ,EAAiB,0CAAjB,CADR;AAECC,EAAAA,KAAK,EAAE;AAFR,CAD4B,EAK5B;AACCD,EAAAA,KAAK,EAAE,cAAI,QAAJ,EAAc,0CAAd,CADR;AAECC,EAAAA,KAAK,EAAE;AAFR,CAL4B,EAS5B;AACCD,EAAAA,KAAK,EAAE,cAAI,OAAJ,EAAa,0CAAb,CADR;AAECC,EAAAA,KAAK,EAAE;AAFR,CAT4B,EAa5B;AACCD,EAAAA,KAAK,EAAE,cAAI,WAAJ,EAAiB,0CAAjB,CADR;AAECC,EAAAA,KAAK,EAAE;AAFR,CAb4B,CAA7B;;AAmBe,SAASC,cAAT,CAAyB;AACvCC,EAAAA,OADuC;AAEvCF,EAAAA,KAFuC;AAGvCG,EAAAA,QAHuC;AAIvCC,EAAAA,OAAO,GAAGN,oBAJ6B;AAKvCO,EAAAA,YAAY,GAAGP,oBAAoB,CAAE,CAAF,CAApB,CAA0BE,KALF;AAMvCM,EAAAA,gBAAgB,GAAG;AANoB,CAAzB,EAOX;AACH,QAAMC,YAAY,GAAGP,KAAH,aAAGA,KAAH,cAAGA,KAAH,GAAYK,YAA9B;AACA,SACC,4BAAC,wCAAD;AACC,IAAA,QAAQ,EAAG,MAAME,YAAY,KAAKF,YADnC;AAEC,IAAA,KAAK,EAAG,cAAI,YAAJ,CAFT;AAGC,IAAA,UAAU,EAAG,MAAMF,QAAQ,CAAEE,YAAF,CAH5B;AAIC,IAAA,gBAAgB,EAAGC,gBAJpB;AAKC,IAAA,OAAO,EAAGJ;AALX,KAOC,4BAAC,yBAAD;AACC,IAAA,KAAK,EAAG,cAAI,YAAJ,CADT;AAEC,IAAA,KAAK,EAAGK,YAFT;AAGC,IAAA,OAAO,EAAGH,OAHX;AAIC,IAAA,QAAQ,EAAGD,QAJZ;AAKC,IAAA,IAAI,EAAG,cAAI,sCAAJ,CALR;AAMC,IAAA,IAAI,EAAG;AANR,IAPD,CADD;AAkBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tSelectControl,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n} from '@wordpress/components';\nimport { __, _x } from '@wordpress/i18n';\n\nconst DEFAULT_SIZE_OPTIONS = [\n\t{\n\t\tlabel: _x( 'Thumbnail', 'Image size option for resolution control' ),\n\t\tvalue: 'thumbnail',\n\t},\n\t{\n\t\tlabel: _x( 'Medium', 'Image size option for resolution control' ),\n\t\tvalue: 'medium',\n\t},\n\t{\n\t\tlabel: _x( 'Large', 'Image size option for resolution control' ),\n\t\tvalue: 'large',\n\t},\n\t{\n\t\tlabel: _x( 'Full Size', 'Image size option for resolution control' ),\n\t\tvalue: 'full',\n\t},\n];\n\nexport default function ResolutionTool( {\n\tpanelId,\n\tvalue,\n\tonChange,\n\toptions = DEFAULT_SIZE_OPTIONS,\n\tdefaultValue = DEFAULT_SIZE_OPTIONS[ 0 ].value,\n\tisShownByDefault = true,\n} ) {\n\tconst displayValue = value ?? defaultValue;\n\treturn (\n\t\t<ToolsPanelItem\n\t\t\thasValue={ () => displayValue !== defaultValue }\n\t\t\tlabel={ __( 'Resolution' ) }\n\t\t\tonDeselect={ () => onChange( defaultValue ) }\n\t\t\tisShownByDefault={ isShownByDefault }\n\t\t\tpanelId={ panelId }\n\t\t>\n\t\t\t<SelectControl\n\t\t\t\tlabel={ __( 'Resolution' ) }\n\t\t\t\tvalue={ displayValue }\n\t\t\t\toptions={ options }\n\t\t\t\tonChange={ onChange }\n\t\t\t\thelp={ __( 'Select the size of the source image.' ) }\n\t\t\t\tsize={ '__unstable-large' }\n\t\t\t/>\n\t\t</ToolsPanelItem>\n\t);\n}\n"]}
@@ -398,7 +398,8 @@ class URLInput extends _element.Component {
398
398
  instanceId,
399
399
  placeholder = (0, _i18n.__)('Paste URL or type to search'),
400
400
  __experimentalRenderControl: renderControl,
401
- value = ''
401
+ value = '',
402
+ hideLabelFromVision = false
402
403
  } = this.props;
403
404
  const {
404
405
  loading,
@@ -414,7 +415,8 @@ class URLInput extends _element.Component {
414
415
  label,
415
416
  className: (0, _classnames.default)('block-editor-url-input', className, {
416
417
  'is-full-width': isFullWidth
417
- })
418
+ }),
419
+ hideLabelFromVision
418
420
  };
419
421
  const inputProps = {
420
422
  id: inputId,
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/url-input/index.js"],"names":["isFunction","maybeFunc","URLInput","Component","constructor","props","onChange","bind","onFocus","onKeyDown","selectLink","handleOnClick","bindSuggestionNode","autocompleteRef","inputRef","updateSuggestions","suggestionNodes","suggestionsRequest","state","suggestions","showSuggestions","isUpdatingSuggestions","suggestionsValue","selectedSuggestion","suggestionsListboxId","suggestionOptionIdPrefix","componentDidUpdate","prevProps","value","__experimentalShowInitialSuggestions","scrollingIntoView","current","onlyScrollIfNeeded","setTimeout","disableSuggestions","length","componentDidMount","shouldShowInitialSuggestions","componentWillUnmount","cancel","index","ref","__experimentalFetchLinkSuggestions","fetchLinkSuggestions","__experimentalHandleURLSuggestions","handleURLSuggestions","isInitialSuggestions","trim","setState","loading","request","then","debouncedSpeak","catch","event","target","keyCode","UP","selectionStart","preventDefault","setSelectionRange","DOWN","ENTER","onSubmit","suggestion","previousIndex","nextIndex","TAB","speak","url","focus","getDerivedStateFromProps","instanceId","shouldShowSuggestions","hasValue","render","renderControl","renderSuggestions","__nextHasNoMarginBottom","label","className","isFullWidth","placeholder","__experimentalRenderControl","inputId","controlProps","id","inputProps","required","type","role","undefined","since","version","hint","__experimentalRenderSuggestions","suggestionsListProps","buildSuggestionItemProps","tabIndex","isLoading","handleSuggestionClick","currentInputValue","map","title","withSafeTimeout","withSpokenMessages","withInstanceId","select","getSettings","blockEditorStore"],"mappings":";;;;;;;;;AAWA;;AARA;;AACA;;AAKA;;AACA;;AAEA;;AACA;;AAOA;;AAMA;;AACA;;AAKA;;AAhCA;AACA;AACA;;AAIA;AACA;AACA;;AAqBA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,UAAT,CAAqBC,SAArB,EAAiC;AAChC,SAAO,OAAOA,SAAP,KAAqB,UAA5B;AACA;;AAED,MAAMC,QAAN,SAAuBC,kBAAvB,CAAiC;AAChCC,EAAAA,WAAW,CAAEC,KAAF,EAAU;AACpB,UAAOA,KAAP;AAEA,SAAKC,QAAL,GAAgB,KAAKA,QAAL,CAAcC,IAAd,CAAoB,IAApB,CAAhB;AACA,SAAKC,OAAL,GAAe,KAAKA,OAAL,CAAaD,IAAb,CAAmB,IAAnB,CAAf;AACA,SAAKE,SAAL,GAAiB,KAAKA,SAAL,CAAeF,IAAf,CAAqB,IAArB,CAAjB;AACA,SAAKG,UAAL,GAAkB,KAAKA,UAAL,CAAgBH,IAAhB,CAAsB,IAAtB,CAAlB;AACA,SAAKI,aAAL,GAAqB,KAAKA,aAAL,CAAmBJ,IAAnB,CAAyB,IAAzB,CAArB;AACA,SAAKK,kBAAL,GAA0B,KAAKA,kBAAL,CAAwBL,IAAxB,CAA8B,IAA9B,CAA1B;AACA,SAAKM,eAAL,GAAuBR,KAAK,CAACQ,eAAN,IAAyB,yBAAhD;AACA,SAAKC,QAAL,GAAgB,yBAAhB;AACA,SAAKC,iBAAL,GAAyB,uBACxB,KAAKA,iBAAL,CAAuBR,IAAvB,CAA6B,IAA7B,CADwB,EAExB,GAFwB,CAAzB;AAKA,SAAKS,eAAL,GAAuB,EAAvB;AAEA,SAAKC,kBAAL,GAA0B,IAA1B;AAEA,SAAKC,KAAL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D9B;AAEC,MAAA,GAAG,EAAGwB,UAAU,CAACsB,EAFlB;AAGC,MAAA,SAAS,EAAG,yBACX,oCADW,EAEX;AACC,uBAAe9C,KAAK,KAAKjB;AAD1B,OAFW,CAHb;AASC,MAAA,OAAO,EAAG,MAAM,KAAKZ,aAAL,CAAoBqD,UAApB;AATjB,OAWGA,UAAU,CAACuC,KAXd,CADC,CAPH,CADD,CADD;AA2BA;;AAthB+B;AAyhBjC;AACA;AACA;;;eACe,sBACdC,wBADc,EAEdC,8BAFc,EAGdC,uBAHc,EAId,sBAAY,CAAEC,MAAF,EAAUtG,KAAV,KAAqB;AAChC;AACA;AACA,MAAKL,UAAU,CAAEK,KAAK,CAACqC,kCAAR,CAAf,EAA8D;AAC7D;AACA;;AACD,QAAM;AAAEkE,IAAAA;AAAF,MAAkBD,MAAM,CAAEE,YAAF,CAA9B;AACA,SAAO;AACNnE,IAAAA,kCAAkC,EACjCkE,WAAW,GAAGlE;AAFT,GAAP;AAIA,CAXD,CAJc,EAgBZxC,QAhBY,C","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\nimport scrollIntoView from 'dom-scroll-into-view';\n\n/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\nimport { __, sprintf, _n } from '@wordpress/i18n';\nimport { Component, createRef } from '@wordpress/element';\nimport { UP, DOWN, ENTER, TAB } from '@wordpress/keycodes';\nimport {\n\tBaseControl,\n\tButton,\n\tSpinner,\n\twithSpokenMessages,\n\tPopover,\n} from '@wordpress/components';\nimport {\n\tcompose,\n\tdebounce,\n\twithInstanceId,\n\twithSafeTimeout,\n} from '@wordpress/compose';\nimport { withSelect } from '@wordpress/data';\nimport { isURL } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\n\n/**\n * Whether the argument is a function.\n *\n * @param {*} maybeFunc The argument to check.\n * @return {boolean} True if the argument is a function, false otherwise.\n */\nfunction isFunction( maybeFunc ) {\n\treturn typeof maybeFunc === 'function';\n}\n\nclass URLInput extends Component {\n\tconstructor( props ) {\n\t\tsuper( props );\n\n\t\tthis.onChange = this.onChange.bind( this );\n\t\tthis.onFocus = this.onFocus.bind( this );\n\t\tthis.onKeyDown = this.onKeyDown.bind( this );\n\t\tthis.selectLink = this.selectLink.bind( this );\n\t\tthis.handleOnClick = this.handleOnClick.bind( this );\n\t\tthis.bindSuggestionNode = this.bindSuggestionNode.bind( this );\n\t\tthis.autocompleteRef = props.autocompleteRef || createRef();\n\t\tthis.inputRef = createRef();\n\t\tthis.updateSuggestions = debounce(\n\t\t\tthis.updateSuggestions.bind( this ),\n\t\t\t200\n\t\t);\n\n\t\tthis.suggestionNodes = [];\n\n\t\tthis.suggestionsRequest = null;\n\n\t\tthis.state = {\n\t\t\tsuggestions: [],\n\t\t\tshowSuggestions: false,\n\t\t\tisUpdatingSuggestions: false,\n\t\t\tsuggestionsValue: null,\n\t\t\tselectedSuggestion: null,\n\t\t\tsuggestionsListboxId: '',\n\t\t\tsuggestionOptionIdPrefix: '',\n\t\t};\n\t}\n\n\tcomponentDidUpdate( prevProps ) {\n\t\tconst { showSuggestions, selectedSuggestion } = this.state;\n\t\tconst { value, __experimentalShowInitialSuggestions = false } =\n\t\t\tthis.props;\n\n\t\t// Only have to worry about scrolling selected suggestion into view\n\t\t// when already expanded.\n\t\tif (\n\t\t\tshowSuggestions &&\n\t\t\tselectedSuggestion !== null &&\n\t\t\tthis.suggestionNodes[ selectedSuggestion ] &&\n\t\t\t! this.scrollingIntoView\n\t\t) {\n\t\t\tthis.scrollingIntoView = true;\n\t\t\tscrollIntoView(\n\t\t\t\tthis.suggestionNodes[ selectedSuggestion ],\n\t\t\t\tthis.autocompleteRef.current,\n\t\t\t\t{\n\t\t\t\t\tonlyScrollIfNeeded: true,\n\t\t\t\t}\n\t\t\t);\n\n\t\t\tthis.props.setTimeout( () => {\n\t\t\t\tthis.scrollingIntoView = false;\n\t\t\t}, 100 );\n\t\t}\n\n\t\t// Update suggestions when the value changes.\n\t\tif (\n\t\t\tprevProps.value !== value &&\n\t\t\t! this.props.disableSuggestions &&\n\t\t\t! this.state.isUpdatingSuggestions\n\t\t) {\n\t\t\tif ( value?.length ) {\n\t\t\t\t// If the new value is not empty we need to update with suggestions for it.\n\t\t\t\tthis.updateSuggestions( value );\n\t\t\t} else if ( __experimentalShowInitialSuggestions ) {\n\t\t\t\t// If the new value is empty and we can show initial suggestions, then show initial suggestions.\n\t\t\t\tthis.updateSuggestions();\n\t\t\t}\n\t\t}\n\t}\n\n\tcomponentDidMount() {\n\t\tif ( this.shouldShowInitialSuggestions() ) {\n\t\t\tthis.updateSuggestions();\n\t\t}\n\t}\n\n\tcomponentWillUnmount() {\n\t\tthis.suggestionsRequest?.cancel?.();\n\t\tthis.suggestionsRequest = null;\n\t}\n\n\tbindSuggestionNode( index ) {\n\t\treturn ( ref ) => {\n\t\t\tthis.suggestionNodes[ index ] = ref;\n\t\t};\n\t}\n\n\tshouldShowInitialSuggestions() {\n\t\tconst { __experimentalShowInitialSuggestions = false, value } =\n\t\t\tthis.props;\n\t\treturn (\n\t\t\t__experimentalShowInitialSuggestions && ! ( value && value.length )\n\t\t);\n\t}\n\n\tupdateSuggestions( value = '' ) {\n\t\tconst {\n\t\t\t__experimentalFetchLinkSuggestions: fetchLinkSuggestions,\n\t\t\t__experimentalHandleURLSuggestions: handleURLSuggestions,\n\t\t} = this.props;\n\n\t\tif ( ! fetchLinkSuggestions ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Initial suggestions may only show if there is no value\n\t\t// (note: this includes whitespace).\n\t\tconst isInitialSuggestions = ! value?.length;\n\n\t\t// Trim only now we've determined whether or not it originally had a \"length\"\n\t\t// (even if that value was all whitespace).\n\t\tvalue = value.trim();\n\n\t\t// Allow a suggestions request if:\n\t\t// - there are at least 2 characters in the search input (except manual searches where\n\t\t// search input length is not required to trigger a fetch)\n\t\t// - this is a direct entry (eg: a URL)\n\t\tif (\n\t\t\t! isInitialSuggestions &&\n\t\t\t( value.length < 2 || ( ! handleURLSuggestions && isURL( value ) ) )\n\t\t) {\n\t\t\tthis.suggestionsRequest?.cancel?.();\n\t\t\tthis.suggestionsRequest = null;\n\n\t\t\tthis.setState( {\n\t\t\t\tsuggestions: [],\n\t\t\t\tshowSuggestions: false,\n\t\t\t\tsuggestionsValue: value,\n\t\t\t\tselectedSuggestion: null,\n\t\t\t\tloading: false,\n\t\t\t} );\n\n\t\t\treturn;\n\t\t}\n\n\t\tthis.setState( {\n\t\t\tisUpdatingSuggestions: true,\n\t\t\tselectedSuggestion: null,\n\t\t\tloading: true,\n\t\t} );\n\n\t\tconst request = fetchLinkSuggestions( value, {\n\t\t\tisInitialSuggestions,\n\t\t} );\n\n\t\trequest\n\t\t\t.then( ( suggestions ) => {\n\t\t\t\t// A fetch Promise doesn't have an abort option. It's mimicked by\n\t\t\t\t// comparing the request reference in on the instance, which is\n\t\t\t\t// reset or deleted on subsequent requests or unmounting.\n\t\t\t\tif ( this.suggestionsRequest !== request ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tthis.setState( {\n\t\t\t\t\tsuggestions,\n\t\t\t\t\tisUpdatingSuggestions: false,\n\t\t\t\t\tsuggestionsValue: value,\n\t\t\t\t\tloading: false,\n\t\t\t\t\tshowSuggestions: !! suggestions.length,\n\t\t\t\t} );\n\n\t\t\t\tif ( !! suggestions.length ) {\n\t\t\t\t\tthis.props.debouncedSpeak(\n\t\t\t\t\t\tsprintf(\n\t\t\t\t\t\t\t/* translators: %s: number of results. */\n\t\t\t\t\t\t\t_n(\n\t\t\t\t\t\t\t\t'%d result found, use up and down arrow keys to navigate.',\n\t\t\t\t\t\t\t\t'%d results found, use up and down arrow keys to navigate.',\n\t\t\t\t\t\t\t\tsuggestions.length\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tsuggestions.length\n\t\t\t\t\t\t),\n\t\t\t\t\t\t'assertive'\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tthis.props.debouncedSpeak(\n\t\t\t\t\t\t__( 'No results.' ),\n\t\t\t\t\t\t'assertive'\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} )\n\t\t\t.catch( () => {\n\t\t\t\tif ( this.suggestionsRequest !== request ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tthis.setState( {\n\t\t\t\t\tisUpdatingSuggestions: false,\n\t\t\t\t\tloading: false,\n\t\t\t\t} );\n\t\t\t} );\n\n\t\t// Note that this assignment is handled *before* the async search request\n\t\t// as a Promise always resolves on the next tick of the event loop.\n\t\tthis.suggestionsRequest = request;\n\t}\n\n\tonChange( event ) {\n\t\tthis.props.onChange( event.target.value );\n\t}\n\n\tonFocus() {\n\t\tconst { suggestions } = this.state;\n\t\tconst { disableSuggestions, value } = this.props;\n\n\t\t// When opening the link editor, if there's a value present, we want to load the suggestions pane with the results for this input search value\n\t\t// Don't re-run the suggestions on focus if there are already suggestions present (prevents searching again when tabbing between the input and buttons)\n\t\tif (\n\t\t\tvalue &&\n\t\t\t! disableSuggestions &&\n\t\t\t! this.state.isUpdatingSuggestions &&\n\t\t\t! ( suggestions && suggestions.length )\n\t\t) {\n\t\t\t// Ensure the suggestions are updated with the current input value.\n\t\t\tthis.updateSuggestions( value );\n\t\t}\n\t}\n\n\tonKeyDown( event ) {\n\t\tthis.props.onKeyDown?.( event );\n\t\tconst { showSuggestions, selectedSuggestion, suggestions, loading } =\n\t\t\tthis.state;\n\n\t\t// If the suggestions are not shown or loading, we shouldn't handle the arrow keys\n\t\t// We shouldn't preventDefault to allow block arrow keys navigation.\n\t\tif ( ! showSuggestions || ! suggestions.length || loading ) {\n\t\t\t// In the Windows version of Firefox the up and down arrows don't move the caret\n\t\t\t// within an input field like they do for Mac Firefox/Chrome/Safari. This causes\n\t\t\t// a form of focus trapping that is disruptive to the user experience. This disruption\n\t\t\t// only happens if the caret is not in the first or last position in the text input.\n\t\t\t// See: https://github.com/WordPress/gutenberg/issues/5693#issuecomment-436684747\n\t\t\tswitch ( event.keyCode ) {\n\t\t\t\t// When UP is pressed, if the caret is at the start of the text, move it to the 0\n\t\t\t\t// position.\n\t\t\t\tcase UP: {\n\t\t\t\t\tif ( 0 !== event.target.selectionStart ) {\n\t\t\t\t\t\tevent.preventDefault();\n\n\t\t\t\t\t\t// Set the input caret to position 0.\n\t\t\t\t\t\tevent.target.setSelectionRange( 0, 0 );\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\t// When DOWN is pressed, if the caret is not at the end of the text, move it to the\n\t\t\t\t// last position.\n\t\t\t\tcase DOWN: {\n\t\t\t\t\tif (\n\t\t\t\t\t\tthis.props.value.length !== event.target.selectionStart\n\t\t\t\t\t) {\n\t\t\t\t\t\tevent.preventDefault();\n\n\t\t\t\t\t\t// Set the input caret to the last position.\n\t\t\t\t\t\tevent.target.setSelectionRange(\n\t\t\t\t\t\t\tthis.props.value.length,\n\t\t\t\t\t\t\tthis.props.value.length\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\t// Submitting while loading should trigger onSubmit.\n\t\t\t\tcase ENTER: {\n\t\t\t\t\tif ( this.props.onSubmit ) {\n\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\tthis.props.onSubmit( null, event );\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn;\n\t\t}\n\n\t\tconst suggestion =\n\t\t\tthis.state.suggestions[ this.state.selectedSuggestion ];\n\n\t\tswitch ( event.keyCode ) {\n\t\t\tcase UP: {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tconst previousIndex = ! selectedSuggestion\n\t\t\t\t\t? suggestions.length - 1\n\t\t\t\t\t: selectedSuggestion - 1;\n\t\t\t\tthis.setState( {\n\t\t\t\t\tselectedSuggestion: previousIndex,\n\t\t\t\t} );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase DOWN: {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tconst nextIndex =\n\t\t\t\t\tselectedSuggestion === null ||\n\t\t\t\t\tselectedSuggestion === suggestions.length - 1\n\t\t\t\t\t\t? 0\n\t\t\t\t\t\t: selectedSuggestion + 1;\n\t\t\t\tthis.setState( {\n\t\t\t\t\tselectedSuggestion: nextIndex,\n\t\t\t\t} );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase TAB: {\n\t\t\t\tif ( this.state.selectedSuggestion !== null ) {\n\t\t\t\t\tthis.selectLink( suggestion );\n\t\t\t\t\t// Announce a link has been selected when tabbing away from the input field.\n\t\t\t\t\tthis.props.speak( __( 'Link selected.' ) );\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase ENTER: {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tif ( this.state.selectedSuggestion !== null ) {\n\t\t\t\t\tthis.selectLink( suggestion );\n\n\t\t\t\t\tif ( this.props.onSubmit ) {\n\t\t\t\t\t\tthis.props.onSubmit( suggestion, event );\n\t\t\t\t\t}\n\t\t\t\t} else if ( this.props.onSubmit ) {\n\t\t\t\t\tthis.props.onSubmit( null, event );\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tselectLink( suggestion ) {\n\t\tthis.props.onChange( suggestion.url, suggestion );\n\t\tthis.setState( {\n\t\t\tselectedSuggestion: null,\n\t\t\tshowSuggestions: false,\n\t\t} );\n\t}\n\n\thandleOnClick( suggestion ) {\n\t\tthis.selectLink( suggestion );\n\t\t// Move focus to the input field when a link suggestion is clicked.\n\t\tthis.inputRef.current.focus();\n\t}\n\n\tstatic getDerivedStateFromProps(\n\t\t{\n\t\t\tvalue,\n\t\t\tinstanceId,\n\t\t\tdisableSuggestions,\n\t\t\t__experimentalShowInitialSuggestions = false,\n\t\t},\n\t\t{ showSuggestions }\n\t) {\n\t\tlet shouldShowSuggestions = showSuggestions;\n\n\t\tconst hasValue = value && value.length;\n\n\t\tif ( ! __experimentalShowInitialSuggestions && ! hasValue ) {\n\t\t\tshouldShowSuggestions = false;\n\t\t}\n\n\t\tif ( disableSuggestions === true ) {\n\t\t\tshouldShowSuggestions = false;\n\t\t}\n\n\t\treturn {\n\t\t\tshowSuggestions: shouldShowSuggestions,\n\t\t\tsuggestionsListboxId: `block-editor-url-input-suggestions-${ instanceId }`,\n\t\t\tsuggestionOptionIdPrefix: `block-editor-url-input-suggestion-${ instanceId }`,\n\t\t};\n\t}\n\n\trender() {\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ this.renderControl() }\n\t\t\t\t{ this.renderSuggestions() }\n\t\t\t</>\n\t\t);\n\t}\n\n\trenderControl() {\n\t\tconst {\n\t\t\t/** Start opting into the new margin-free styles that will become the default in a future version. */\n\t\t\t__nextHasNoMarginBottom = false,\n\t\t\tlabel = null,\n\t\t\tclassName,\n\t\t\tisFullWidth,\n\t\t\tinstanceId,\n\t\t\tplaceholder = __( 'Paste URL or type to search' ),\n\t\t\t__experimentalRenderControl: renderControl,\n\t\t\tvalue = '',\n\t\t} = this.props;\n\n\t\tconst {\n\t\t\tloading,\n\t\t\tshowSuggestions,\n\t\t\tselectedSuggestion,\n\t\t\tsuggestionsListboxId,\n\t\t\tsuggestionOptionIdPrefix,\n\t\t} = this.state;\n\n\t\tconst inputId = `url-input-control-${ instanceId }`;\n\n\t\tconst controlProps = {\n\t\t\tid: inputId, // Passes attribute to label for the for attribute\n\t\t\tlabel,\n\t\t\tclassName: classnames( 'block-editor-url-input', className, {\n\t\t\t\t'is-full-width': isFullWidth,\n\t\t\t} ),\n\t\t};\n\n\t\tconst inputProps = {\n\t\t\tid: inputId,\n\t\t\tvalue,\n\t\t\trequired: true,\n\t\t\tclassName: 'block-editor-url-input__input',\n\t\t\ttype: 'text',\n\t\t\tonChange: this.onChange,\n\t\t\tonFocus: this.onFocus,\n\t\t\tplaceholder,\n\t\t\tonKeyDown: this.onKeyDown,\n\t\t\trole: 'combobox',\n\t\t\t'aria-label': label ? undefined : __( 'URL' ), // Ensure input always has an accessible label\n\t\t\t'aria-expanded': showSuggestions,\n\t\t\t'aria-autocomplete': 'list',\n\t\t\t'aria-owns': suggestionsListboxId,\n\t\t\t'aria-activedescendant':\n\t\t\t\tselectedSuggestion !== null\n\t\t\t\t\t? `${ suggestionOptionIdPrefix }-${ selectedSuggestion }`\n\t\t\t\t\t: undefined,\n\t\t\tref: this.inputRef,\n\t\t};\n\n\t\tif ( renderControl ) {\n\t\t\treturn renderControl( controlProps, inputProps, loading );\n\t\t}\n\n\t\tif ( ! __nextHasNoMarginBottom ) {\n\t\t\tdeprecated( 'Bottom margin styles for wp.blockEditor.URLInput', {\n\t\t\t\tsince: '6.2',\n\t\t\t\tversion: '6.5',\n\t\t\t\thint: 'Set the `__nextHasNoMarginBottom` prop to true to start opting into the new styles, which will become the default in a future version',\n\t\t\t} );\n\t\t}\n\n\t\treturn (\n\t\t\t<BaseControl\n\t\t\t\t__nextHasNoMarginBottom={ __nextHasNoMarginBottom }\n\t\t\t\t{ ...controlProps }\n\t\t\t>\n\t\t\t\t<input { ...inputProps } />\n\t\t\t\t{ loading && <Spinner /> }\n\t\t\t</BaseControl>\n\t\t);\n\t}\n\n\trenderSuggestions() {\n\t\tconst {\n\t\t\tclassName,\n\t\t\t__experimentalRenderSuggestions: renderSuggestions,\n\t\t} = this.props;\n\n\t\tconst {\n\t\t\tshowSuggestions,\n\t\t\tsuggestions,\n\t\t\tsuggestionsValue,\n\t\t\tselectedSuggestion,\n\t\t\tsuggestionsListboxId,\n\t\t\tsuggestionOptionIdPrefix,\n\t\t\tloading,\n\t\t} = this.state;\n\n\t\tif ( ! showSuggestions || suggestions.length === 0 ) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst suggestionsListProps = {\n\t\t\tid: suggestionsListboxId,\n\t\t\tref: this.autocompleteRef,\n\t\t\trole: 'listbox',\n\t\t};\n\n\t\tconst buildSuggestionItemProps = ( suggestion, index ) => {\n\t\t\treturn {\n\t\t\t\trole: 'option',\n\t\t\t\ttabIndex: '-1',\n\t\t\t\tid: `${ suggestionOptionIdPrefix }-${ index }`,\n\t\t\t\tref: this.bindSuggestionNode( index ),\n\t\t\t\t'aria-selected':\n\t\t\t\t\tindex === selectedSuggestion ? true : undefined,\n\t\t\t};\n\t\t};\n\n\t\tif ( isFunction( renderSuggestions ) ) {\n\t\t\treturn renderSuggestions( {\n\t\t\t\tsuggestions,\n\t\t\t\tselectedSuggestion,\n\t\t\t\tsuggestionsListProps,\n\t\t\t\tbuildSuggestionItemProps,\n\t\t\t\tisLoading: loading,\n\t\t\t\thandleSuggestionClick: this.handleOnClick,\n\t\t\t\tisInitialSuggestions: ! suggestionsValue?.length,\n\t\t\t\tcurrentInputValue: suggestionsValue,\n\t\t\t} );\n\t\t}\n\n\t\treturn (\n\t\t\t<Popover placement=\"bottom\" focusOnMount={ false }>\n\t\t\t\t<div\n\t\t\t\t\t{ ...suggestionsListProps }\n\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t'block-editor-url-input__suggestions',\n\t\t\t\t\t\t`${ className }__suggestions`\n\t\t\t\t\t) }\n\t\t\t\t>\n\t\t\t\t\t{ suggestions.map( ( suggestion, index ) => (\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t{ ...buildSuggestionItemProps( suggestion, index ) }\n\t\t\t\t\t\t\tkey={ suggestion.id }\n\t\t\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t\t\t'block-editor-url-input__suggestion',\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t'is-selected': index === selectedSuggestion,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\tonClick={ () => this.handleOnClick( suggestion ) }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ suggestion.title }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t) ) }\n\t\t\t\t</div>\n\t\t\t</Popover>\n\t\t);\n\t}\n}\n\n/**\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/url-input/README.md\n */\nexport default compose(\n\twithSafeTimeout,\n\twithSpokenMessages,\n\twithInstanceId,\n\twithSelect( ( select, props ) => {\n\t\t// If a link suggestions handler is already provided then\n\t\t// bail.\n\t\tif ( isFunction( props.__experimentalFetchLinkSuggestions ) ) {\n\t\t\treturn;\n\t\t}\n\t\tconst { getSettings } = select( blockEditorStore );\n\t\treturn {\n\t\t\t__experimentalFetchLinkSuggestions:\n\t\t\t\tgetSettings().__experimentalFetchLinkSuggestions,\n\t\t};\n\t} )\n)( URLInput );\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/url-input/index.js"],"names":["isFunction","maybeFunc","URLInput","Component","constructor","props","onChange","bind","onFocus","onKeyDown","selectLink","handleOnClick","bindSuggestionNode","autocompleteRef","inputRef","updateSuggestions","suggestionNodes","suggestionsRequest","state","suggestions","showSuggestions","isUpdatingSuggestions","suggestionsValue","selectedSuggestion","suggestionsListboxId","suggestionOptionIdPrefix","componentDidUpdate","prevProps","value","__experimentalShowInitialSuggestions","scrollingIntoView","current","onlyScrollIfNeeded","setTimeout","disableSuggestions","length","componentDidMount","shouldShowInitialSuggestions","componentWillUnmount","cancel","index","ref","__experimentalFetchLinkSuggestions","fetchLinkSuggestions","__experimentalHandleURLSuggestions","handleURLSuggestions","isInitialSuggestions","trim","setState","loading","request","then","debouncedSpeak","catch","event","target","keyCode","UP","selectionStart","preventDefault","setSelectionRange","DOWN","ENTER","onSubmit","suggestion","previousIndex","nextIndex","TAB","speak","url","focus","getDerivedStateFromProps","instanceId","shouldShowSuggestions","hasValue","render","renderControl","renderSuggestions","__nextHasNoMarginBottom","label","className","isFullWidth","placeholder","__experimentalRenderControl","hideLabelFromVision","inputId","controlProps","id","inputProps","required","type","role","undefined","since","version","hint","__experimentalRenderSuggestions","suggestionsListProps","buildSuggestionItemProps","tabIndex","isLoading","handleSuggestionClick","currentInputValue","map","title","withSafeTimeout","withSpok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lB;AAGC,MAAA,SAAS,EAAG,yBACX,oCADW,EAEX;AACC,uBAAe/C,KAAK,KAAKjB;AAD1B,OAFW,CAHb;AASC,MAAA,OAAO,EAAG,MAAM,KAAKZ,aAAL,CAAoBqD,UAApB;AATjB,OAWGA,UAAU,CAACwC,KAXd,CADC,CAPH,CADD,CADD;AA2BA;;AAxhB+B;AA2hBjC;AACA;AACA;;;eACe,sBACdC,wBADc,EAEdC,8BAFc,EAGdC,uBAHc,EAId,sBAAY,CAAEC,MAAF,EAAUvG,KAAV,KAAqB;AAChC;AACA;AACA,MAAKL,UAAU,CAAEK,KAAK,CAACqC,kCAAR,CAAf,EAA8D;AAC7D;AACA;;AACD,QAAM;AAAEmE,IAAAA;AAAF,MAAkBD,MAAM,CAAEE,YAAF,CAA9B;AACA,SAAO;AACNpE,IAAAA,kCAAkC,EACjCmE,WAAW,GAAGnE;AAFT,GAAP;AAIA,CAXD,CAJc,EAgBZxC,QAhBY,C","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\nimport scrollIntoView from 'dom-scroll-into-view';\n\n/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\nimport { __, sprintf, _n } from '@wordpress/i18n';\nimport { Component, createRef } from '@wordpress/element';\nimport { UP, DOWN, ENTER, TAB } from '@wordpress/keycodes';\nimport {\n\tBaseControl,\n\tButton,\n\tSpinner,\n\twithSpokenMessages,\n\tPopover,\n} from '@wordpress/components';\nimport {\n\tcompose,\n\tdebounce,\n\twithInstanceId,\n\twithSafeTimeout,\n} from '@wordpress/compose';\nimport { withSelect } from '@wordpress/data';\nimport { isURL } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\n\n/**\n * Whether the argument is a function.\n *\n * @param {*} maybeFunc The argument to check.\n * @return {boolean} True if the argument is a function, false otherwise.\n */\nfunction isFunction( maybeFunc ) {\n\treturn typeof maybeFunc === 'function';\n}\n\nclass URLInput extends Component {\n\tconstructor( props ) {\n\t\tsuper( props );\n\n\t\tthis.onChange = this.onChange.bind( this );\n\t\tthis.onFocus = this.onFocus.bind( this );\n\t\tthis.onKeyDown = this.onKeyDown.bind( this );\n\t\tthis.selectLink = this.selectLink.bind( this );\n\t\tthis.handleOnClick = this.handleOnClick.bind( this );\n\t\tthis.bindSuggestionNode = this.bindSuggestionNode.bind( this );\n\t\tthis.autocompleteRef = props.autocompleteRef || createRef();\n\t\tthis.inputRef = createRef();\n\t\tthis.updateSuggestions = debounce(\n\t\t\tthis.updateSuggestions.bind( this ),\n\t\t\t200\n\t\t);\n\n\t\tthis.suggestionNodes = [];\n\n\t\tthis.suggestionsRequest = null;\n\n\t\tthis.state = {\n\t\t\tsuggestions: [],\n\t\t\tshowSuggestions: false,\n\t\t\tisUpdatingSuggestions: false,\n\t\t\tsuggestionsValue: null,\n\t\t\tselectedSuggestion: null,\n\t\t\tsuggestionsListboxId: '',\n\t\t\tsuggestionOptionIdPrefix: '',\n\t\t};\n\t}\n\n\tcomponentDidUpdate( prevProps ) {\n\t\tconst { showSuggestions, selectedSuggestion } = this.state;\n\t\tconst { value, __experimentalShowInitialSuggestions = false } =\n\t\t\tthis.props;\n\n\t\t// Only have to worry about scrolling selected suggestion into view\n\t\t// when already expanded.\n\t\tif (\n\t\t\tshowSuggestions &&\n\t\t\tselectedSuggestion !== null &&\n\t\t\tthis.suggestionNodes[ selectedSuggestion ] &&\n\t\t\t! this.scrollingIntoView\n\t\t) {\n\t\t\tthis.scrollingIntoView = true;\n\t\t\tscrollIntoView(\n\t\t\t\tthis.suggestionNodes[ selectedSuggestion ],\n\t\t\t\tthis.autocompleteRef.current,\n\t\t\t\t{\n\t\t\t\t\tonlyScrollIfNeeded: true,\n\t\t\t\t}\n\t\t\t);\n\n\t\t\tthis.props.setTimeout( () => {\n\t\t\t\tthis.scrollingIntoView = false;\n\t\t\t}, 100 );\n\t\t}\n\n\t\t// Update suggestions when the value changes.\n\t\tif (\n\t\t\tprevProps.value !== value &&\n\t\t\t! this.props.disableSuggestions &&\n\t\t\t! this.state.isUpdatingSuggestions\n\t\t) {\n\t\t\tif ( value?.length ) {\n\t\t\t\t// If the new value is not empty we need to update with suggestions for it.\n\t\t\t\tthis.updateSuggestions( value );\n\t\t\t} else if ( __experimentalShowInitialSuggestions ) {\n\t\t\t\t// If the new value is empty and we can show initial suggestions, then show initial suggestions.\n\t\t\t\tthis.updateSuggestions();\n\t\t\t}\n\t\t}\n\t}\n\n\tcomponentDidMount() {\n\t\tif ( this.shouldShowInitialSuggestions() ) {\n\t\t\tthis.updateSuggestions();\n\t\t}\n\t}\n\n\tcomponentWillUnmount() {\n\t\tthis.suggestionsRequest?.cancel?.();\n\t\tthis.suggestionsRequest = null;\n\t}\n\n\tbindSuggestionNode( index ) {\n\t\treturn ( ref ) => {\n\t\t\tthis.suggestionNodes[ index ] = ref;\n\t\t};\n\t}\n\n\tshouldShowInitialSuggestions() {\n\t\tconst { __experimentalShowInitialSuggestions = false, value } =\n\t\t\tthis.props;\n\t\treturn (\n\t\t\t__experimentalShowInitialSuggestions && ! ( value && value.length )\n\t\t);\n\t}\n\n\tupdateSuggestions( value = '' ) {\n\t\tconst {\n\t\t\t__experimentalFetchLinkSuggestions: fetchLinkSuggestions,\n\t\t\t__experimentalHandleURLSuggestions: handleURLSuggestions,\n\t\t} = this.props;\n\n\t\tif ( ! fetchLinkSuggestions ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Initial suggestions may only show if there is no value\n\t\t// (note: this includes whitespace).\n\t\tconst isInitialSuggestions = ! value?.length;\n\n\t\t// Trim only now we've determined whether or not it originally had a \"length\"\n\t\t// (even if that value was all whitespace).\n\t\tvalue = value.trim();\n\n\t\t// Allow a suggestions request if:\n\t\t// - there are at least 2 characters in the search input (except manual searches where\n\t\t// search input length is not required to trigger a fetch)\n\t\t// - this is a direct entry (eg: a URL)\n\t\tif (\n\t\t\t! isInitialSuggestions &&\n\t\t\t( value.length < 2 || ( ! handleURLSuggestions && isURL( value ) ) )\n\t\t) {\n\t\t\tthis.suggestionsRequest?.cancel?.();\n\t\t\tthis.suggestionsRequest = null;\n\n\t\t\tthis.setState( {\n\t\t\t\tsuggestions: [],\n\t\t\t\tshowSuggestions: false,\n\t\t\t\tsuggestionsValue: value,\n\t\t\t\tselectedSuggestion: null,\n\t\t\t\tloading: false,\n\t\t\t} );\n\n\t\t\treturn;\n\t\t}\n\n\t\tthis.setState( {\n\t\t\tisUpdatingSuggestions: true,\n\t\t\tselectedSuggestion: null,\n\t\t\tloading: true,\n\t\t} );\n\n\t\tconst request = fetchLinkSuggestions( value, {\n\t\t\tisInitialSuggestions,\n\t\t} );\n\n\t\trequest\n\t\t\t.then( ( suggestions ) => {\n\t\t\t\t// A fetch Promise doesn't have an abort option. It's mimicked by\n\t\t\t\t// comparing the request reference in on the instance, which is\n\t\t\t\t// reset or deleted on subsequent requests or unmounting.\n\t\t\t\tif ( this.suggestionsRequest !== request ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tthis.setState( {\n\t\t\t\t\tsuggestions,\n\t\t\t\t\tisUpdatingSuggestions: false,\n\t\t\t\t\tsuggestionsValue: value,\n\t\t\t\t\tloading: false,\n\t\t\t\t\tshowSuggestions: !! suggestions.length,\n\t\t\t\t} );\n\n\t\t\t\tif ( !! suggestions.length ) {\n\t\t\t\t\tthis.props.debouncedSpeak(\n\t\t\t\t\t\tsprintf(\n\t\t\t\t\t\t\t/* translators: %s: number of results. */\n\t\t\t\t\t\t\t_n(\n\t\t\t\t\t\t\t\t'%d result found, use up and down arrow keys to navigate.',\n\t\t\t\t\t\t\t\t'%d results found, use up and down arrow keys to navigate.',\n\t\t\t\t\t\t\t\tsuggestions.length\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tsuggestions.length\n\t\t\t\t\t\t),\n\t\t\t\t\t\t'assertive'\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tthis.props.debouncedSpeak(\n\t\t\t\t\t\t__( 'No results.' ),\n\t\t\t\t\t\t'assertive'\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} )\n\t\t\t.catch( () => {\n\t\t\t\tif ( this.suggestionsRequest !== request ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tthis.setState( {\n\t\t\t\t\tisUpdatingSuggestions: false,\n\t\t\t\t\tloading: false,\n\t\t\t\t} );\n\t\t\t} );\n\n\t\t// Note that this assignment is handled *before* the async search request\n\t\t// as a Promise always resolves on the next tick of the event loop.\n\t\tthis.suggestionsRequest = request;\n\t}\n\n\tonChange( event ) {\n\t\tthis.props.onChange( event.target.value );\n\t}\n\n\tonFocus() {\n\t\tconst { suggestions } = this.state;\n\t\tconst { disableSuggestions, value } = this.props;\n\n\t\t// When opening the link editor, if there's a value present, we want to load the suggestions pane with the results for this input search value\n\t\t// Don't re-run the suggestions on focus if there are already suggestions present (prevents searching again when tabbing between the input and buttons)\n\t\tif (\n\t\t\tvalue &&\n\t\t\t! disableSuggestions &&\n\t\t\t! this.state.isUpdatingSuggestions &&\n\t\t\t! ( suggestions && suggestions.length )\n\t\t) {\n\t\t\t// Ensure the suggestions are updated with the current input value.\n\t\t\tthis.updateSuggestions( value );\n\t\t}\n\t}\n\n\tonKeyDown( event ) {\n\t\tthis.props.onKeyDown?.( event );\n\t\tconst { showSuggestions, selectedSuggestion, suggestions, loading } =\n\t\t\tthis.state;\n\n\t\t// If the suggestions are not shown or loading, we shouldn't handle the arrow keys\n\t\t// We shouldn't preventDefault to allow block arrow keys navigation.\n\t\tif ( ! showSuggestions || ! suggestions.length || loading ) {\n\t\t\t// In the Windows version of Firefox the up and down arrows don't move the caret\n\t\t\t// within an input field like they do for Mac Firefox/Chrome/Safari. This causes\n\t\t\t// a form of focus trapping that is disruptive to the user experience. This disruption\n\t\t\t// only happens if the caret is not in the first or last position in the text input.\n\t\t\t// See: https://github.com/WordPress/gutenberg/issues/5693#issuecomment-436684747\n\t\t\tswitch ( event.keyCode ) {\n\t\t\t\t// When UP is pressed, if the caret is at the start of the text, move it to the 0\n\t\t\t\t// position.\n\t\t\t\tcase UP: {\n\t\t\t\t\tif ( 0 !== event.target.selectionStart ) {\n\t\t\t\t\t\tevent.preventDefault();\n\n\t\t\t\t\t\t// Set the input caret to position 0.\n\t\t\t\t\t\tevent.target.setSelectionRange( 0, 0 );\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\t// When DOWN is pressed, if the caret is not at the end of the text, move it to the\n\t\t\t\t// last position.\n\t\t\t\tcase DOWN: {\n\t\t\t\t\tif (\n\t\t\t\t\t\tthis.props.value.length !== event.target.selectionStart\n\t\t\t\t\t) {\n\t\t\t\t\t\tevent.preventDefault();\n\n\t\t\t\t\t\t// Set the input caret to the last position.\n\t\t\t\t\t\tevent.target.setSelectionRange(\n\t\t\t\t\t\t\tthis.props.value.length,\n\t\t\t\t\t\t\tthis.props.value.length\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\t// Submitting while loading should trigger onSubmit.\n\t\t\t\tcase ENTER: {\n\t\t\t\t\tif ( this.props.onSubmit ) {\n\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\tthis.props.onSubmit( null, event );\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn;\n\t\t}\n\n\t\tconst suggestion =\n\t\t\tthis.state.suggestions[ this.state.selectedSuggestion ];\n\n\t\tswitch ( event.keyCode ) {\n\t\t\tcase UP: {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tconst previousIndex = ! selectedSuggestion\n\t\t\t\t\t? suggestions.length - 1\n\t\t\t\t\t: selectedSuggestion - 1;\n\t\t\t\tthis.setState( {\n\t\t\t\t\tselectedSuggestion: previousIndex,\n\t\t\t\t} );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase DOWN: {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tconst nextIndex =\n\t\t\t\t\tselectedSuggestion === null ||\n\t\t\t\t\tselectedSuggestion === suggestions.length - 1\n\t\t\t\t\t\t? 0\n\t\t\t\t\t\t: selectedSuggestion + 1;\n\t\t\t\tthis.setState( {\n\t\t\t\t\tselectedSuggestion: nextIndex,\n\t\t\t\t} );\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase TAB: {\n\t\t\t\tif ( this.state.selectedSuggestion !== null ) {\n\t\t\t\t\tthis.selectLink( suggestion );\n\t\t\t\t\t// Announce a link has been selected when tabbing away from the input field.\n\t\t\t\t\tthis.props.speak( __( 'Link selected.' ) );\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase ENTER: {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tif ( this.state.selectedSuggestion !== null ) {\n\t\t\t\t\tthis.selectLink( suggestion );\n\n\t\t\t\t\tif ( this.props.onSubmit ) {\n\t\t\t\t\t\tthis.props.onSubmit( suggestion, event );\n\t\t\t\t\t}\n\t\t\t\t} else if ( this.props.onSubmit ) {\n\t\t\t\t\tthis.props.onSubmit( null, event );\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tselectLink( suggestion ) {\n\t\tthis.props.onChange( suggestion.url, suggestion );\n\t\tthis.setState( {\n\t\t\tselectedSuggestion: null,\n\t\t\tshowSuggestions: false,\n\t\t} );\n\t}\n\n\thandleOnClick( suggestion ) {\n\t\tthis.selectLink( suggestion );\n\t\t// Move focus to the input field when a link suggestion is clicked.\n\t\tthis.inputRef.current.focus();\n\t}\n\n\tstatic getDerivedStateFromProps(\n\t\t{\n\t\t\tvalue,\n\t\t\tinstanceId,\n\t\t\tdisableSuggestions,\n\t\t\t__experimentalShowInitialSuggestions = false,\n\t\t},\n\t\t{ showSuggestions }\n\t) {\n\t\tlet shouldShowSuggestions = showSuggestions;\n\n\t\tconst hasValue = value && value.length;\n\n\t\tif ( ! __experimentalShowInitialSuggestions && ! hasValue ) {\n\t\t\tshouldShowSuggestions = false;\n\t\t}\n\n\t\tif ( disableSuggestions === true ) {\n\t\t\tshouldShowSuggestions = false;\n\t\t}\n\n\t\treturn {\n\t\t\tshowSuggestions: shouldShowSuggestions,\n\t\t\tsuggestionsListboxId: `block-editor-url-input-suggestions-${ instanceId }`,\n\t\t\tsuggestionOptionIdPrefix: `block-editor-url-input-suggestion-${ instanceId }`,\n\t\t};\n\t}\n\n\trender() {\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ this.renderControl() }\n\t\t\t\t{ this.renderSuggestions() }\n\t\t\t</>\n\t\t);\n\t}\n\n\trenderControl() {\n\t\tconst {\n\t\t\t/** Start opting into the new margin-free styles that will become the default in a future version. */\n\t\t\t__nextHasNoMarginBottom = false,\n\t\t\tlabel = null,\n\t\t\tclassName,\n\t\t\tisFullWidth,\n\t\t\tinstanceId,\n\t\t\tplaceholder = __( 'Paste URL or type to search' ),\n\t\t\t__experimentalRenderControl: renderControl,\n\t\t\tvalue = '',\n\t\t\thideLabelFromVision = false,\n\t\t} = this.props;\n\n\t\tconst {\n\t\t\tloading,\n\t\t\tshowSuggestions,\n\t\t\tselectedSuggestion,\n\t\t\tsuggestionsListboxId,\n\t\t\tsuggestionOptionIdPrefix,\n\t\t} = this.state;\n\n\t\tconst inputId = `url-input-control-${ instanceId }`;\n\n\t\tconst controlProps = {\n\t\t\tid: inputId, // Passes attribute to label for the for attribute\n\t\t\tlabel,\n\t\t\tclassName: classnames( 'block-editor-url-input', className, {\n\t\t\t\t'is-full-width': isFullWidth,\n\t\t\t} ),\n\t\t\thideLabelFromVision,\n\t\t};\n\n\t\tconst inputProps = {\n\t\t\tid: inputId,\n\t\t\tvalue,\n\t\t\trequired: true,\n\t\t\tclassName: 'block-editor-url-input__input',\n\t\t\ttype: 'text',\n\t\t\tonChange: this.onChange,\n\t\t\tonFocus: this.onFocus,\n\t\t\tplaceholder,\n\t\t\tonKeyDown: this.onKeyDown,\n\t\t\trole: 'combobox',\n\t\t\t'aria-label': label ? undefined : __( 'URL' ), // Ensure input always has an accessible label\n\t\t\t'aria-expanded': showSuggestions,\n\t\t\t'aria-autocomplete': 'list',\n\t\t\t'aria-owns': suggestionsListboxId,\n\t\t\t'aria-activedescendant':\n\t\t\t\tselectedSuggestion !== null\n\t\t\t\t\t? `${ suggestionOptionIdPrefix }-${ selectedSuggestion }`\n\t\t\t\t\t: undefined,\n\t\t\tref: this.inputRef,\n\t\t};\n\n\t\tif ( renderControl ) {\n\t\t\treturn renderControl( controlProps, inputProps, loading );\n\t\t}\n\n\t\tif ( ! __nextHasNoMarginBottom ) {\n\t\t\tdeprecated( 'Bottom margin styles for wp.blockEditor.URLInput', {\n\t\t\t\tsince: '6.2',\n\t\t\t\tversion: '6.5',\n\t\t\t\thint: 'Set the `__nextHasNoMarginBottom` prop to true to start opting into the new styles, which will become the default in a future version',\n\t\t\t} );\n\t\t}\n\n\t\treturn (\n\t\t\t<BaseControl\n\t\t\t\t__nextHasNoMarginBottom={ __nextHasNoMarginBottom }\n\t\t\t\t{ ...controlProps }\n\t\t\t>\n\t\t\t\t<input { ...inputProps } />\n\t\t\t\t{ loading && <Spinner /> }\n\t\t\t</BaseControl>\n\t\t);\n\t}\n\n\trenderSuggestions() {\n\t\tconst {\n\t\t\tclassName,\n\t\t\t__experimentalRenderSuggestions: renderSuggestions,\n\t\t} = this.props;\n\n\t\tconst {\n\t\t\tshowSuggestions,\n\t\t\tsuggestions,\n\t\t\tsuggestionsValue,\n\t\t\tselectedSuggestion,\n\t\t\tsuggestionsListboxId,\n\t\t\tsuggestionOptionIdPrefix,\n\t\t\tloading,\n\t\t} = this.state;\n\n\t\tif ( ! showSuggestions || suggestions.length === 0 ) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst suggestionsListProps = {\n\t\t\tid: suggestionsListboxId,\n\t\t\tref: this.autocompleteRef,\n\t\t\trole: 'listbox',\n\t\t};\n\n\t\tconst buildSuggestionItemProps = ( suggestion, index ) => {\n\t\t\treturn {\n\t\t\t\trole: 'option',\n\t\t\t\ttabIndex: '-1',\n\t\t\t\tid: `${ suggestionOptionIdPrefix }-${ index }`,\n\t\t\t\tref: this.bindSuggestionNode( index ),\n\t\t\t\t'aria-selected':\n\t\t\t\t\tindex === selectedSuggestion ? true : undefined,\n\t\t\t};\n\t\t};\n\n\t\tif ( isFunction( renderSuggestions ) ) {\n\t\t\treturn renderSuggestions( {\n\t\t\t\tsuggestions,\n\t\t\t\tselectedSuggestion,\n\t\t\t\tsuggestionsListProps,\n\t\t\t\tbuildSuggestionItemProps,\n\t\t\t\tisLoading: loading,\n\t\t\t\thandleSuggestionClick: this.handleOnClick,\n\t\t\t\tisInitialSuggestions: ! suggestionsValue?.length,\n\t\t\t\tcurrentInputValue: suggestionsValue,\n\t\t\t} );\n\t\t}\n\n\t\treturn (\n\t\t\t<Popover placement=\"bottom\" focusOnMount={ false }>\n\t\t\t\t<div\n\t\t\t\t\t{ ...suggestionsListProps }\n\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t'block-editor-url-input__suggestions',\n\t\t\t\t\t\t`${ className }__suggestions`\n\t\t\t\t\t) }\n\t\t\t\t>\n\t\t\t\t\t{ suggestions.map( ( suggestion, index ) => (\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t{ ...buildSuggestionItemProps( suggestion, index ) }\n\t\t\t\t\t\t\tkey={ suggestion.id }\n\t\t\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t\t\t'block-editor-url-input__suggestion',\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t'is-selected': index === selectedSuggestion,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\tonClick={ () => this.handleOnClick( suggestion ) }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ suggestion.title }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t) ) }\n\t\t\t\t</div>\n\t\t\t</Popover>\n\t\t);\n\t}\n}\n\n/**\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/url-input/README.md\n */\nexport default compose(\n\twithSafeTimeout,\n\twithSpokenMessages,\n\twithInstanceId,\n\twithSelect( ( select, props ) => {\n\t\t// If a link suggestions handler is already provided then\n\t\t// bail.\n\t\tif ( isFunction( props.__experimentalFetchLinkSuggestions ) ) {\n\t\t\treturn;\n\t\t}\n\t\tconst { getSettings } = select( blockEditorStore );\n\t\treturn {\n\t\t\t__experimentalFetchLinkSuggestions:\n\t\t\t\tgetSettings().__experimentalFetchLinkSuggestions,\n\t\t};\n\t} )\n)( URLInput );\n"]}
@@ -17,6 +17,8 @@ var _compose = require("@wordpress/compose");
17
17
 
18
18
  var _store = require("../../store");
19
19
 
20
+ var _dom2 = require("../../utils/dom");
21
+
20
22
  /**
21
23
  * WordPress dependencies
22
24
  */
@@ -111,43 +113,24 @@ function useTabNav() {
111
113
  // will no longer send focus through the focus capture element.
112
114
  if (event.target === node) setNavigationMode(true);
113
115
  return;
114
- } // We want to constrain the tabbing to the block and its child blocks.
116
+ }
117
+
118
+ const nextTabbable = _dom.focus.tabbable[direction](event.target); // We want to constrain the tabbing to the block and its child blocks.
115
119
  // If the preceding form element is within a different block,
116
120
  // such as two sibling image blocks in the placeholder state,
117
121
  // we want shift + tab from the first form element to move to the image
118
122
  // block toolbar and not the previous image block's form element.
119
- // TODO: Should this become a utility function?
120
-
121
- /**
122
- * Determine whether an element is part of or is the selected block.
123
- *
124
- * @param {Object} selectedBlockElement
125
- * @param {Object} element
126
- * @return {boolean} Whether the element is part of or is the selected block.
127
- */
128
-
129
-
130
- const isElementPartOfSelectedBlock = (selectedBlockElement, element) => {
131
- // Check if the element is or is within the selected block by finding the
132
- // closest element with a data-block attribute and seeing if
133
- // it matches our current selected block ID
134
- const elementBlockId = element.closest('[data-block]')?.getAttribute('data-block');
135
- const isElementSameBlock = elementBlockId === getSelectedBlockClientId(); // Check if the element is a child of the selected block. This could be a
136
- // child block in a group or column block, etc.
137
-
138
- const isElementChildOfBlock = selectedBlockElement.contains(element);
139
- return isElementSameBlock || isElementChildOfBlock;
140
- };
141
-
142
- const nextTabbable = _dom.focus.tabbable[direction](event.target); // Allow tabbing from the block wrapper to a form element,
123
+
124
+
125
+ const currentBlock = event.target.closest('[data-block]');
126
+ const isElementPartOfSelectedBlock = currentBlock && nextTabbable && ((0, _dom2.isInSameBlock)(currentBlock, nextTabbable) || (0, _dom2.isInsideRootBlock)(currentBlock, nextTabbable)); // Allow tabbing from the block wrapper to a form element,
143
127
  // and between form elements rendered in a block and its child blocks,
144
128
  // such as inside a placeholder. Form elements are generally
145
129
  // meant to be UI rather than part of the content. Ideally
146
130
  // these are not rendered in the content and perhaps in the
147
131
  // future they can be rendered in an iframe or shadow DOM.
148
132
 
149
-
150
- if ((0, _dom.isFormElement)(nextTabbable) && isElementPartOfSelectedBlock(event.target.closest('[data-block]'), nextTabbable)) {
133
+ if ((0, _dom.isFormElement)(nextTabbable) && isElementPartOfSelectedBlock) {
151
134
  return;
152
135
  }
153
136
 
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/writing-flow/use-tab-nav.js"],"names":["useTabNav","container","focusCaptureBeforeRef","focusCaptureAfterRef","lastFocus","hasMultiSelection","getSelectedBlockClientId","getBlockCount","blockEditorStore","setNavigationMode","isNavigationMode","select","focusCaptureTabIndex","undefined","noCapture","onFocusCapture","event","current","focus","canvasElement","ownerDocument","target","defaultView","frameElement","isBefore","compareDocumentPosition","DOCUMENT_POSITION_FOLLOWING","tabbables","tabbable","find","length","next","before","after","ref","node","onKeyDown","defaultPrevented","keyCode","ESCAPE","preventDefault","TAB","isShift","shiftKey","direction","isElementPartOfSelectedBlock","selectedBlockElement","element","elementBlockId","closest","getAttribute","isElementSameBlock","isElementChildOfBlock","contains","nextTabbable","preventScroll","onFocusOut","relatedTarget","activeElement","body","preventScrollOnTab","addEventListener","removeEventListener","mergedRefs"],"mappings":";;;;;;;AAOA;;AAJA;;AACA;;AACA;;AAC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B,EAAkCzB,SAAlC;AACAD,IAAAA,IAAI,CAAC0B,gBAAL,CAAuB,UAAvB,EAAmCL,UAAnC;AACA,WAAO,MAAM;AACZlC,MAAAA,WAAW,CAACwC,mBAAZ,CAAiC,SAAjC,EAA4CF,kBAA5C;AACAzB,MAAAA,IAAI,CAAC2B,mBAAL,CAA0B,SAA1B,EAAqC1B,SAArC;AACAD,MAAAA,IAAI,CAAC2B,mBAAL,CAA0B,UAA1B,EAAsCN,UAAtC;AACA,KAJD;AAKA,GAhKW,EAgKT,EAhKS,CAAZ;AAkKA,QAAMO,UAAU,GAAG,2BAAc,CAAE9D,SAAF,EAAaiC,GAAb,CAAd,CAAnB;AAEA,SAAO,CAAEF,MAAF,EAAU+B,UAAV,EAAsB9B,KAAtB,CAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { focus, isFormElement } from '@wordpress/dom';\nimport { TAB, ESCAPE } from '@wordpress/keycodes';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useRefEffect, useMergeRefs } from '@wordpress/compose';\nimport { useRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\n\nexport default function useTabNav() {\n\tconst container = useRef();\n\tconst focusCaptureBeforeRef = useRef();\n\tconst focusCaptureAfterRef = useRef();\n\tconst lastFocus = useRef();\n\tconst { hasMultiSelection, getSelectedBlockClientId, getBlockCount } =\n\t\tuseSelect( blockEditorStore );\n\tconst { setNavigationMode } = useDispatch( blockEditorStore );\n\tconst isNavigationMode = useSelect(\n\t\t( select ) => select( blockEditorStore ).isNavigationMode(),\n\t\t[]\n\t);\n\n\t// Don't allow tabbing to this element in Navigation mode.\n\tconst focusCaptureTabIndex = ! isNavigationMode ? '0' : undefined;\n\n\t// Reference that holds the a flag for enabling or disabling\n\t// capturing on the focus capture elements.\n\tconst noCapture = useRef();\n\n\tfunction onFocusCapture( event ) {\n\t\t// Do not capture incoming focus if set by us in WritingFlow.\n\t\tif ( noCapture.current ) {\n\t\t\tnoCapture.current = null;\n\t\t} else if ( hasMultiSelection() ) {\n\t\t\tcontainer.current.focus();\n\t\t} else if ( getSelectedBlockClientId() ) {\n\t\t\tlastFocus.current.focus();\n\t\t} else {\n\t\t\tsetNavigationMode( true );\n\n\t\t\tconst canvasElement =\n\t\t\t\tcontainer.current.ownerDocument === event.target.ownerDocument\n\t\t\t\t\t? container.current\n\t\t\t\t\t: container.current.ownerDocument.defaultView.frameElement;\n\n\t\t\tconst isBefore =\n\t\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\t\tevent.target.compareDocumentPosition( canvasElement ) &\n\t\t\t\tevent.target.DOCUMENT_POSITION_FOLLOWING;\n\t\t\tconst tabbables = focus.tabbable.find( container.current );\n\n\t\t\tif ( tabbables.length ) {\n\t\t\t\tconst next = isBefore\n\t\t\t\t\t? tabbables[ 0 ]\n\t\t\t\t\t: tabbables[ tabbables.length - 1 ];\n\n\t\t\t\tnext.focus();\n\t\t\t}\n\t\t}\n\t}\n\n\tconst before = (\n\t\t<div\n\t\t\tref={ focusCaptureBeforeRef }\n\t\t\ttabIndex={ focusCaptureTabIndex }\n\t\t\tonFocus={ onFocusCapture }\n\t\t/>\n\t);\n\n\tconst after = (\n\t\t<div\n\t\t\tref={ focusCaptureAfterRef }\n\t\t\ttabIndex={ focusCaptureTabIndex }\n\t\t\tonFocus={ onFocusCapture }\n\t\t/>\n\t);\n\n\tconst ref = useRefEffect( ( node ) => {\n\t\tfunction onKeyDown( event ) {\n\t\t\tif ( event.defaultPrevented ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( event.keyCode === ESCAPE && ! hasMultiSelection() ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tsetNavigationMode( true );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// In Edit mode, Tab should focus the first tabbable element after\n\t\t\t// the content, which is normally the sidebar (with block controls)\n\t\t\t// and Shift+Tab should focus the first tabbable element before the\n\t\t\t// content, which is normally the block toolbar.\n\t\t\t// Arrow keys can be used, and Tab and arrow keys can be used in\n\t\t\t// Navigation mode (press Esc), to navigate through blocks.\n\t\t\tif ( event.keyCode !== TAB ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst isShift = event.shiftKey;\n\t\t\tconst direction = isShift ? 'findPrevious' : 'findNext';\n\n\t\t\tif ( ! hasMultiSelection() && ! getSelectedBlockClientId() ) {\n\t\t\t\t// Preserve the behaviour of entering navigation mode when\n\t\t\t\t// tabbing into the content without a block selection.\n\t\t\t\t// `onFocusCapture` already did this previously, but we need to\n\t\t\t\t// do it again here because after clearing block selection,\n\t\t\t\t// focus land on the writing flow container and pressing Tab\n\t\t\t\t// will no longer send focus through the focus capture element.\n\t\t\t\tif ( event.target === node ) setNavigationMode( true );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// We want to constrain the tabbing to the block and its child blocks.\n\t\t\t// If the preceding form element is within a different block,\n\t\t\t// such as two sibling image blocks in the placeholder state,\n\t\t\t// we want shift + tab from the first form element to move to the image\n\t\t\t// block toolbar and not the previous image block's form element.\n\t\t\t// TODO: Should this become a utility function?\n\t\t\t/**\n\t\t\t * Determine whether an element is part of or is the selected block.\n\t\t\t *\n\t\t\t * @param {Object} selectedBlockElement\n\t\t\t * @param {Object} element\n\t\t\t * @return {boolean} Whether the element is part of or is the selected block.\n\t\t\t */\n\t\t\tconst isElementPartOfSelectedBlock = (\n\t\t\t\tselectedBlockElement,\n\t\t\t\telement\n\t\t\t) => {\n\t\t\t\t// Check if the element is or is within the selected block by finding the\n\t\t\t\t// closest element with a data-block attribute and seeing if\n\t\t\t\t// it matches our current selected block ID\n\t\t\t\tconst elementBlockId = element\n\t\t\t\t\t.closest( '[data-block]' )\n\t\t\t\t\t?.getAttribute( 'data-block' );\n\t\t\t\tconst isElementSameBlock =\n\t\t\t\t\telementBlockId === getSelectedBlockClientId();\n\n\t\t\t\t// Check if the element is a child of the selected block. This could be a\n\t\t\t\t// child block in a group or column block, etc.\n\t\t\t\tconst isElementChildOfBlock =\n\t\t\t\t\tselectedBlockElement.contains( element );\n\n\t\t\t\treturn isElementSameBlock || isElementChildOfBlock;\n\t\t\t};\n\n\t\t\tconst nextTabbable = focus.tabbable[ direction ]( event.target );\n\t\t\t// Allow tabbing from the block wrapper to a form element,\n\t\t\t// and between form elements rendered in a block and its child blocks,\n\t\t\t// such as inside a placeholder. Form elements are generally\n\t\t\t// meant to be UI rather than part of the content. Ideally\n\t\t\t// these are not rendered in the content and perhaps in the\n\t\t\t// future they can be rendered in an iframe or shadow DOM.\n\t\t\tif (\n\t\t\t\tisFormElement( nextTabbable ) &&\n\t\t\t\tisElementPartOfSelectedBlock(\n\t\t\t\t\tevent.target.closest( '[data-block]' ),\n\t\t\t\t\tnextTabbable\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst next = isShift ? focusCaptureBeforeRef : focusCaptureAfterRef;\n\n\t\t\t// Disable focus capturing on the focus capture element, so it\n\t\t\t// doesn't refocus this block and so it allows default behaviour\n\t\t\t// (moving focus to the next tabbable element).\n\t\t\tnoCapture.current = true;\n\n\t\t\t// Focusing the focus capture element, which is located above and\n\t\t\t// below the editor, should not scroll the page all the way up or\n\t\t\t// down.\n\t\t\tnext.current.focus( { preventScroll: true } );\n\t\t}\n\n\t\tfunction onFocusOut( event ) {\n\t\t\tlastFocus.current = event.target;\n\n\t\t\tconst { ownerDocument } = node;\n\n\t\t\t// If focus disappears due to there being no blocks, move focus to\n\t\t\t// the writing flow wrapper.\n\t\t\tif (\n\t\t\t\t! event.relatedTarget &&\n\t\t\t\townerDocument.activeElement === ownerDocument.body &&\n\t\t\t\tgetBlockCount() === 0\n\t\t\t) {\n\t\t\t\tnode.focus();\n\t\t\t}\n\t\t}\n\n\t\t// When tabbing back to an element in block list, this event handler prevents scrolling if the\n\t\t// focus capture divs (before/after) are outside of the viewport. (For example shift+tab back to a paragraph\n\t\t// when focus is on a sidebar element. This prevents the scrollable writing area from jumping either to the\n\t\t// top or bottom of the document.\n\t\t//\n\t\t// Note that it isn't possible to disable scrolling in the onFocus event. We need to intercept this\n\t\t// earlier in the keypress handler, and call focus( { preventScroll: true } ) instead.\n\t\t// https://developer.mozilla.org/en-US/docs/Web/API/HTMLOrForeignElement/focus#parameters\n\t\tfunction preventScrollOnTab( event ) {\n\t\t\tif ( event.keyCode !== TAB ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( event.target?.getAttribute( 'role' ) === 'region' ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( container.current === event.target ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst isShift = event.shiftKey;\n\t\t\tconst direction = isShift ? 'findPrevious' : 'findNext';\n\t\t\tconst target = focus.tabbable[ direction ]( event.target );\n\t\t\t// Only do something when the next tabbable is a focus capture div (before/after)\n\t\t\tif (\n\t\t\t\ttarget === focusCaptureBeforeRef.current ||\n\t\t\t\ttarget === focusCaptureAfterRef.current\n\t\t\t) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\ttarget.focus( { preventScroll: true } );\n\t\t\t}\n\t\t}\n\n\t\tconst { ownerDocument } = node;\n\t\tconst { defaultView } = ownerDocument;\n\t\tdefaultView.addEventListener( 'keydown', preventScrollOnTab );\n\t\tnode.addEventListener( 'keydown', onKeyDown );\n\t\tnode.addEventListener( 'focusout', onFocusOut );\n\t\treturn () => {\n\t\t\tdefaultView.removeEventListener( 'keydown', preventScrollOnTab );\n\t\t\tnode.removeEventListener( 'keydown', onKeyDown );\n\t\t\tnode.removeEventListener( 'focusout', onFocusOut );\n\t\t};\n\t}, [] );\n\n\tconst mergedRefs = useMergeRefs( [ container, ref ] );\n\n\treturn [ before, mergedRefs, after ];\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/writing-flow/use-tab-nav.js"],"names":["useTabNav","container","focusCaptureBeforeRef","focusCaptureAfterRef","lastFocus","hasMultiSelection","getSelectedBlockClientId","getBlockCount","blockEditorStore","setNavigationMode","isNavigationMode","select","focusCaptureTabIndex","undefined","noCapture","onFocusCapture","event","current","focus","canvasElement","ownerDocument","target","defaultView","frameElement","isBefore","compareDocumentPosition","DOCUMENT_POSITION_FOLLOWING","tabbables","tabbable","find","length","next","before","after","ref","node","onKeyDown","defaultPrevented","keyCode","ESCAPE","preventDefault","TAB","isShift","shiftKey","direction","nextTabbable","currentBlock","closest","isElementPartOfSelectedBlock","preventScroll","onFocusOut","relatedTarget","activeElement","body","preventScrollOnTab","getAttribute","addEventListener","removeEventListener","mergedRefs"],"mappings":";;;;;;;AAOA;;AAJA;;AACA;;AACA;;AACA;;AAMA;;AACA;;AAbA;AACA;AACA;;AAOA;AACA;AACA;AAIe,SAASA,SAAT,GAAqB;AACnC,QAAMC,SAAS,GAAG,sBAAlB;AACA,QAAMC,qBAAqB,GAAG,sBAA9B;AACA,QAAMC,oBAAoB,GAAG,sBAA7B;AACA,QAAMC,SAAS,GAAG,sBAAlB;AACA,QAAM;AAAEC,IAAAA,iBAAF;AAAqBC,IAAAA,wBAArB;AAA+CC,IAAAA;AAA/C,MACL,qBAAWC,YAAX,CADD;AAEA,QAAM;AAAEC,IAAAA;AAAF,MAAwB,uBAAaD,YAAb,CAA9B;AACA,QAAME,gBAAgB,GAAG,qBACtBC,MAAF,IAAcA,MAAM,CAAEH,YAAF,CAAN,CAA2BE,gBAA3B,EADU,EAExB,EAFwB,CAAzB,CARmC,CAanC;;AACA,QAAME,oBAAoB,GAAG,CAAEF,gBAAF,GAAqB,GAArB,GAA2BG,SAAxD,CAdmC,CAgBnC;AACA;;AACA,QAAMC,SAAS,GAAG,sBAAlB;;AAEA,WAASC,cAAT,CAAyBC,KAAzB,EAAiC;AAChC;AACA,QAAKF,SAAS,CAACG,OAAf,EAAyB;AACxBH,MAAAA,SAAS,CAACG,OAAV,GAAoB,IAApB;AACA,KAFD,MAEO,IAAKZ,iBAAiB,EAAtB,EAA2B;AACjCJ,MAAAA,SAAS,CAACgB,OA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ACAE,IAAAA,WAAW,CAACkC,gBAAZ,CAA8B,SAA9B,EAAyCF,kBAAzC;AACAnB,IAAAA,IAAI,CAACqB,gBAAL,CAAuB,SAAvB,EAAkCpB,SAAlC;AACAD,IAAAA,IAAI,CAACqB,gBAAL,CAAuB,UAAvB,EAAmCN,UAAnC;AACA,WAAO,MAAM;AACZ5B,MAAAA,WAAW,CAACmC,mBAAZ,CAAiC,SAAjC,EAA4CH,kBAA5C;AACAnB,MAAAA,IAAI,CAACsB,mBAAL,CAA0B,SAA1B,EAAqCrB,SAArC;AACAD,MAAAA,IAAI,CAACsB,mBAAL,CAA0B,UAA1B,EAAsCP,UAAtC;AACA,KAJD;AAKA,GAxIW,EAwIT,EAxIS,CAAZ;AA0IA,QAAMQ,UAAU,GAAG,2BAAc,CAAEzD,SAAF,EAAaiC,GAAb,CAAd,CAAnB;AAEA,SAAO,CAAEF,MAAF,EAAU0B,UAAV,EAAsBzB,KAAtB,CAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { focus, isFormElement } from '@wordpress/dom';\nimport { TAB, ESCAPE } from '@wordpress/keycodes';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useRefEffect, useMergeRefs } from '@wordpress/compose';\nimport { useRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { isInSameBlock, isInsideRootBlock } from '../../utils/dom';\n\nexport default function useTabNav() {\n\tconst container = useRef();\n\tconst focusCaptureBeforeRef = useRef();\n\tconst focusCaptureAfterRef = useRef();\n\tconst lastFocus = useRef();\n\tconst { hasMultiSelection, getSelectedBlockClientId, getBlockCount } =\n\t\tuseSelect( blockEditorStore );\n\tconst { setNavigationMode } = useDispatch( blockEditorStore );\n\tconst isNavigationMode = useSelect(\n\t\t( select ) => select( blockEditorStore ).isNavigationMode(),\n\t\t[]\n\t);\n\n\t// Don't allow tabbing to this element in Navigation mode.\n\tconst focusCaptureTabIndex = ! isNavigationMode ? '0' : undefined;\n\n\t// Reference that holds the a flag for enabling or disabling\n\t// capturing on the focus capture elements.\n\tconst noCapture = useRef();\n\n\tfunction onFocusCapture( event ) {\n\t\t// Do not capture incoming focus if set by us in WritingFlow.\n\t\tif ( noCapture.current ) {\n\t\t\tnoCapture.current = null;\n\t\t} else if ( hasMultiSelection() ) {\n\t\t\tcontainer.current.focus();\n\t\t} else if ( getSelectedBlockClientId() ) {\n\t\t\tlastFocus.current.focus();\n\t\t} else {\n\t\t\tsetNavigationMode( true );\n\n\t\t\tconst canvasElement =\n\t\t\t\tcontainer.current.ownerDocument === event.target.ownerDocument\n\t\t\t\t\t? container.current\n\t\t\t\t\t: container.current.ownerDocument.defaultView.frameElement;\n\n\t\t\tconst isBefore =\n\t\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\t\tevent.target.compareDocumentPosition( canvasElement ) &\n\t\t\t\tevent.target.DOCUMENT_POSITION_FOLLOWING;\n\t\t\tconst tabbables = focus.tabbable.find( container.current );\n\n\t\t\tif ( tabbables.length ) {\n\t\t\t\tconst next = isBefore\n\t\t\t\t\t? tabbables[ 0 ]\n\t\t\t\t\t: tabbables[ tabbables.length - 1 ];\n\n\t\t\t\tnext.focus();\n\t\t\t}\n\t\t}\n\t}\n\n\tconst before = (\n\t\t<div\n\t\t\tref={ focusCaptureBeforeRef }\n\t\t\ttabIndex={ focusCaptureTabIndex }\n\t\t\tonFocus={ onFocusCapture }\n\t\t/>\n\t);\n\n\tconst after = (\n\t\t<div\n\t\t\tref={ focusCaptureAfterRef }\n\t\t\ttabIndex={ focusCaptureTabIndex }\n\t\t\tonFocus={ onFocusCapture }\n\t\t/>\n\t);\n\n\tconst ref = useRefEffect( ( node ) => {\n\t\tfunction onKeyDown( event ) {\n\t\t\tif ( event.defaultPrevented ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( event.keyCode === ESCAPE && ! hasMultiSelection() ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tsetNavigationMode( true );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// In Edit mode, Tab should focus the first tabbable element after\n\t\t\t// the content, which is normally the sidebar (with block controls)\n\t\t\t// and Shift+Tab should focus the first tabbable element before the\n\t\t\t// content, which is normally the block toolbar.\n\t\t\t// Arrow keys can be used, and Tab and arrow keys can be used in\n\t\t\t// Navigation mode (press Esc), to navigate through blocks.\n\t\t\tif ( event.keyCode !== TAB ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst isShift = event.shiftKey;\n\t\t\tconst direction = isShift ? 'findPrevious' : 'findNext';\n\n\t\t\tif ( ! hasMultiSelection() && ! getSelectedBlockClientId() ) {\n\t\t\t\t// Preserve the behaviour of entering navigation mode when\n\t\t\t\t// tabbing into the content without a block selection.\n\t\t\t\t// `onFocusCapture` already did this previously, but we need to\n\t\t\t\t// do it again here because after clearing block selection,\n\t\t\t\t// focus land on the writing flow container and pressing Tab\n\t\t\t\t// will no longer send focus through the focus capture element.\n\t\t\t\tif ( event.target === node ) setNavigationMode( true );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst nextTabbable = focus.tabbable[ direction ]( event.target );\n\n\t\t\t// We want to constrain the tabbing to the block and its child blocks.\n\t\t\t// If the preceding form element is within a different block,\n\t\t\t// such as two sibling image blocks in the placeholder state,\n\t\t\t// we want shift + tab from the first form element to move to the image\n\t\t\t// block toolbar and not the previous image block's form element.\n\t\t\tconst currentBlock = event.target.closest( '[data-block]' );\n\t\t\tconst isElementPartOfSelectedBlock =\n\t\t\t\tcurrentBlock &&\n\t\t\t\tnextTabbable &&\n\t\t\t\t( isInSameBlock( currentBlock, nextTabbable ) ||\n\t\t\t\t\tisInsideRootBlock( currentBlock, nextTabbable ) );\n\n\t\t\t// Allow tabbing from the block wrapper to a form element,\n\t\t\t// and between form elements rendered in a block and its child blocks,\n\t\t\t// such as inside a placeholder. Form elements are generally\n\t\t\t// meant to be UI rather than part of the content. Ideally\n\t\t\t// these are not rendered in the content and perhaps in the\n\t\t\t// future they can be rendered in an iframe or shadow DOM.\n\t\t\tif (\n\t\t\t\tisFormElement( nextTabbable ) &&\n\t\t\t\tisElementPartOfSelectedBlock\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst next = isShift ? focusCaptureBeforeRef : focusCaptureAfterRef;\n\n\t\t\t// Disable focus capturing on the focus capture element, so it\n\t\t\t// doesn't refocus this block and so it allows default behaviour\n\t\t\t// (moving focus to the next tabbable element).\n\t\t\tnoCapture.current = true;\n\n\t\t\t// Focusing the focus capture element, which is located above and\n\t\t\t// below the editor, should not scroll the page all the way up or\n\t\t\t// down.\n\t\t\tnext.current.focus( { preventScroll: true } );\n\t\t}\n\n\t\tfunction onFocusOut( event ) {\n\t\t\tlastFocus.current = event.target;\n\n\t\t\tconst { ownerDocument } = node;\n\n\t\t\t// If focus disappears due to there being no blocks, move focus to\n\t\t\t// the writing flow wrapper.\n\t\t\tif (\n\t\t\t\t! event.relatedTarget &&\n\t\t\t\townerDocument.activeElement === ownerDocument.body &&\n\t\t\t\tgetBlockCount() === 0\n\t\t\t) {\n\t\t\t\tnode.focus();\n\t\t\t}\n\t\t}\n\n\t\t// When tabbing back to an element in block list, this event handler prevents scrolling if the\n\t\t// focus capture divs (before/after) are outside of the viewport. (For example shift+tab back to a paragraph\n\t\t// when focus is on a sidebar element. This prevents the scrollable writing area from jumping either to the\n\t\t// top or bottom of the document.\n\t\t//\n\t\t// Note that it isn't possible to disable scrolling in the onFocus event. We need to intercept this\n\t\t// earlier in the keypress handler, and call focus( { preventScroll: true } ) instead.\n\t\t// https://developer.mozilla.org/en-US/docs/Web/API/HTMLOrForeignElement/focus#parameters\n\t\tfunction preventScrollOnTab( event ) {\n\t\t\tif ( event.keyCode !== TAB ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( event.target?.getAttribute( 'role' ) === 'region' ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( container.current === event.target ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst isShift = event.shiftKey;\n\t\t\tconst direction = isShift ? 'findPrevious' : 'findNext';\n\t\t\tconst target = focus.tabbable[ direction ]( event.target );\n\t\t\t// Only do something when the next tabbable is a focus capture div (before/after)\n\t\t\tif (\n\t\t\t\ttarget === focusCaptureBeforeRef.current ||\n\t\t\t\ttarget === focusCaptureAfterRef.current\n\t\t\t) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\ttarget.focus( { preventScroll: true } );\n\t\t\t}\n\t\t}\n\n\t\tconst { ownerDocument } = node;\n\t\tconst { defaultView } = ownerDocument;\n\t\tdefaultView.addEventListener( 'keydown', preventScrollOnTab );\n\t\tnode.addEventListener( 'keydown', onKeyDown );\n\t\tnode.addEventListener( 'focusout', onFocusOut );\n\t\treturn () => {\n\t\t\tdefaultView.removeEventListener( 'keydown', preventScrollOnTab );\n\t\t\tnode.removeEventListener( 'keydown', onKeyDown );\n\t\t\tnode.removeEventListener( 'focusout', onFocusOut );\n\t\t};\n\t}, [] );\n\n\tconst mergedRefs = useMergeRefs( [ container, ref ] );\n\n\treturn [ before, mergedRefs, after ];\n}\n"]}