@wordpress/block-editor 10.4.0 → 10.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 (254) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +0 -1
  3. package/build/components/block-lock/menu-item.js +1 -1
  4. package/build/components/block-lock/menu-item.js.map +1 -1
  5. package/build/components/block-lock/modal.js +16 -9
  6. package/build/components/block-lock/modal.js.map +1 -1
  7. package/build/components/block-styles/utils.js +3 -3
  8. package/build/components/block-styles/utils.js.map +1 -1
  9. package/build/components/block-switcher/index.js +19 -4
  10. package/build/components/block-switcher/index.js.map +1 -1
  11. package/build/components/block-tools/selected-block-popover.js +27 -4
  12. package/build/components/block-tools/selected-block-popover.js.map +1 -1
  13. package/build/components/colors/with-colors.js +4 -3
  14. package/build/components/colors/with-colors.js.map +1 -1
  15. package/build/components/font-sizes/fluid-utils.js +24 -40
  16. package/build/components/font-sizes/fluid-utils.js.map +1 -1
  17. package/build/components/font-sizes/with-font-sizes.js +7 -5
  18. package/build/components/font-sizes/with-font-sizes.js.map +1 -1
  19. package/build/components/index.js +9 -0
  20. package/build/components/index.js.map +1 -1
  21. package/build/components/inner-blocks/index.js +5 -3
  22. package/build/components/inner-blocks/index.js.map +1 -1
  23. package/build/components/inserter/reusable-blocks-tab.js +4 -1
  24. package/build/components/inserter/reusable-blocks-tab.js.map +1 -1
  25. package/build/components/link-control/index.js +18 -34
  26. package/build/components/link-control/index.js.map +1 -1
  27. package/build/components/link-control/search-input.js +1 -1
  28. package/build/components/link-control/search-input.js.map +1 -1
  29. package/build/components/link-control/use-internal-input-value.js +26 -0
  30. package/build/components/link-control/use-internal-input-value.js.map +1 -0
  31. package/build/components/list-view/block.js +5 -3
  32. package/build/components/list-view/block.js.map +1 -1
  33. package/build/components/list-view/branch.js +9 -3
  34. package/build/components/list-view/branch.js.map +1 -1
  35. package/build/components/off-canvas-editor/block-contents.js +100 -0
  36. package/build/components/off-canvas-editor/block-contents.js.map +1 -0
  37. package/build/components/off-canvas-editor/block-select-button.js +119 -0
  38. package/build/components/off-canvas-editor/block-select-button.js.map +1 -0
  39. package/build/components/off-canvas-editor/block.js +292 -0
  40. package/build/components/off-canvas-editor/block.js.map +1 -0
  41. package/build/components/off-canvas-editor/branch.js +181 -0
  42. package/build/components/off-canvas-editor/branch.js.map +1 -0
  43. package/build/components/off-canvas-editor/context.js +19 -0
  44. package/build/components/off-canvas-editor/context.js.map +1 -0
  45. package/build/components/off-canvas-editor/drop-indicator.js +118 -0
  46. package/build/components/off-canvas-editor/drop-indicator.js.map +1 -0
  47. package/build/components/off-canvas-editor/expander.js +41 -0
  48. package/build/components/off-canvas-editor/expander.js.map +1 -0
  49. package/build/components/off-canvas-editor/index.js +204 -0
  50. package/build/components/off-canvas-editor/index.js.map +1 -0
  51. package/build/components/off-canvas-editor/leaf.js +60 -0
  52. package/build/components/off-canvas-editor/leaf.js.map +1 -0
  53. package/build/components/off-canvas-editor/use-block-selection.js +139 -0
  54. package/build/components/off-canvas-editor/use-block-selection.js.map +1 -0
  55. package/build/components/off-canvas-editor/use-list-view-client-ids.js +33 -0
  56. package/build/components/off-canvas-editor/use-list-view-client-ids.js.map +1 -0
  57. package/build/components/off-canvas-editor/use-list-view-drop-zone.js +235 -0
  58. package/build/components/off-canvas-editor/use-list-view-drop-zone.js.map +1 -0
  59. package/build/components/off-canvas-editor/use-list-view-expand-selected-item.js +60 -0
  60. package/build/components/off-canvas-editor/use-list-view-expand-selected-item.js.map +1 -0
  61. package/build/components/off-canvas-editor/utils.js +60 -0
  62. package/build/components/off-canvas-editor/utils.js.map +1 -0
  63. package/build/components/url-popover/index.js +31 -2
  64. package/build/components/url-popover/index.js.map +1 -1
  65. package/build/components/use-setting/index.js +1 -1
  66. package/build/components/use-setting/index.js.map +1 -1
  67. package/build/hooks/color-panel.js +17 -1
  68. package/build/hooks/color-panel.js.map +1 -1
  69. package/build/hooks/color.js +1 -1
  70. package/build/hooks/color.js.map +1 -1
  71. package/build/hooks/content-lock-ui.js +13 -6
  72. package/build/hooks/content-lock-ui.js.map +1 -1
  73. package/build/hooks/dimensions.js +44 -13
  74. package/build/hooks/dimensions.js.map +1 -1
  75. package/build/hooks/layout.js +2 -2
  76. package/build/hooks/layout.js.map +1 -1
  77. package/build/hooks/margin.js +4 -2
  78. package/build/hooks/margin.js.map +1 -1
  79. package/build/hooks/min-height.js +145 -0
  80. package/build/hooks/min-height.js.map +1 -0
  81. package/build/hooks/padding.js +4 -2
  82. package/build/hooks/padding.js.map +1 -1
  83. package/build/hooks/style.js +3 -2
  84. package/build/hooks/style.js.map +1 -1
  85. package/build/layouts/flex.js +22 -21
  86. package/build/layouts/flex.js.map +1 -1
  87. package/build/store/actions.js +26 -0
  88. package/build/store/actions.js.map +1 -1
  89. package/build/store/reducer.js +46 -14
  90. package/build/store/reducer.js.map +1 -1
  91. package/build/store/selectors.js +16 -2
  92. package/build/store/selectors.js.map +1 -1
  93. package/build-module/components/block-lock/menu-item.js +2 -2
  94. package/build-module/components/block-lock/menu-item.js.map +1 -1
  95. package/build-module/components/block-lock/modal.js +17 -10
  96. package/build-module/components/block-lock/modal.js.map +1 -1
  97. package/build-module/components/block-styles/utils.js +3 -3
  98. package/build-module/components/block-styles/utils.js.map +1 -1
  99. package/build-module/components/block-switcher/index.js +19 -4
  100. package/build-module/components/block-switcher/index.js.map +1 -1
  101. package/build-module/components/block-tools/selected-block-popover.js +27 -5
  102. package/build-module/components/block-tools/selected-block-popover.js.map +1 -1
  103. package/build-module/components/colors/with-colors.js +5 -4
  104. package/build-module/components/colors/with-colors.js.map +1 -1
  105. package/build-module/components/font-sizes/fluid-utils.js +24 -40
  106. package/build-module/components/font-sizes/fluid-utils.js.map +1 -1
  107. package/build-module/components/font-sizes/with-font-sizes.js +8 -6
  108. package/build-module/components/font-sizes/with-font-sizes.js.map +1 -1
  109. package/build-module/components/index.js +1 -0
  110. package/build-module/components/index.js.map +1 -1
  111. package/build-module/components/inner-blocks/index.js +5 -3
  112. package/build-module/components/inner-blocks/index.js.map +1 -1
  113. package/build-module/components/inserter/reusable-blocks-tab.js +3 -1
  114. package/build-module/components/inserter/reusable-blocks-tab.js.map +1 -1
  115. package/build-module/components/link-control/index.js +17 -34
  116. package/build-module/components/link-control/index.js.map +1 -1
  117. package/build-module/components/link-control/search-input.js +1 -1
  118. package/build-module/components/link-control/search-input.js.map +1 -1
  119. package/build-module/components/link-control/use-internal-input-value.js +18 -0
  120. package/build-module/components/link-control/use-internal-input-value.js.map +1 -0
  121. package/build-module/components/list-view/block.js +5 -3
  122. package/build-module/components/list-view/block.js.map +1 -1
  123. package/build-module/components/list-view/branch.js +9 -3
  124. package/build-module/components/list-view/branch.js.map +1 -1
  125. package/build-module/components/off-canvas-editor/block-contents.js +85 -0
  126. package/build-module/components/off-canvas-editor/block-contents.js.map +1 -0
  127. package/build-module/components/off-canvas-editor/block-select-button.js +101 -0
  128. package/build-module/components/off-canvas-editor/block-select-button.js.map +1 -0
  129. package/build-module/components/off-canvas-editor/block.js +268 -0
  130. package/build-module/components/off-canvas-editor/block.js.map +1 -0
  131. package/build-module/components/off-canvas-editor/branch.js +165 -0
  132. package/build-module/components/off-canvas-editor/branch.js.map +1 -0
  133. package/build-module/components/off-canvas-editor/context.js +7 -0
  134. package/build-module/components/off-canvas-editor/context.js.map +1 -0
  135. package/build-module/components/off-canvas-editor/drop-indicator.js +111 -0
  136. package/build-module/components/off-canvas-editor/drop-indicator.js.map +1 -0
  137. package/build-module/components/off-canvas-editor/expander.js +32 -0
  138. package/build-module/components/off-canvas-editor/expander.js.map +1 -0
  139. package/build-module/components/off-canvas-editor/index.js +181 -0
  140. package/build-module/components/off-canvas-editor/index.js.map +1 -0
  141. package/build-module/components/off-canvas-editor/leaf.js +45 -0
  142. package/build-module/components/off-canvas-editor/leaf.js.map +1 -0
  143. package/build-module/components/off-canvas-editor/use-block-selection.js +124 -0
  144. package/build-module/components/off-canvas-editor/use-block-selection.js.map +1 -0
  145. package/build-module/components/off-canvas-editor/use-list-view-client-ids.js +24 -0
  146. package/build-module/components/off-canvas-editor/use-list-view-client-ids.js.map +1 -0
  147. package/build-module/components/off-canvas-editor/use-list-view-drop-zone.js +220 -0
  148. package/build-module/components/off-canvas-editor/use-list-view-drop-zone.js.map +1 -0
  149. package/build-module/components/off-canvas-editor/use-list-view-expand-selected-item.js +50 -0
  150. package/build-module/components/off-canvas-editor/use-list-view-expand-selected-item.js.map +1 -0
  151. package/build-module/components/off-canvas-editor/utils.js +44 -0
  152. package/build-module/components/off-canvas-editor/utils.js.map +1 -0
  153. package/build-module/components/url-popover/index.js +30 -3
  154. package/build-module/components/url-popover/index.js.map +1 -1
  155. package/build-module/components/use-setting/index.js +1 -1
  156. package/build-module/components/use-setting/index.js.map +1 -1
  157. package/build-module/hooks/color-panel.js +17 -1
  158. package/build-module/hooks/color-panel.js.map +1 -1
  159. package/build-module/hooks/color.js +1 -1
  160. package/build-module/hooks/color.js.map +1 -1
  161. package/build-module/hooks/content-lock-ui.js +15 -8
  162. package/build-module/hooks/content-lock-ui.js.map +1 -1
  163. package/build-module/hooks/dimensions.js +39 -12
  164. package/build-module/hooks/dimensions.js.map +1 -1
  165. package/build-module/hooks/layout.js +2 -2
  166. package/build-module/hooks/layout.js.map +1 -1
  167. package/build-module/hooks/margin.js +4 -2
  168. package/build-module/hooks/margin.js.map +1 -1
  169. package/build-module/hooks/min-height.js +122 -0
  170. package/build-module/hooks/min-height.js.map +1 -0
  171. package/build-module/hooks/padding.js +4 -2
  172. package/build-module/hooks/padding.js.map +1 -1
  173. package/build-module/hooks/style.js +4 -3
  174. package/build-module/hooks/style.js.map +1 -1
  175. package/build-module/layouts/flex.js +23 -22
  176. package/build-module/layouts/flex.js.map +1 -1
  177. package/build-module/store/actions.js +22 -0
  178. package/build-module/store/actions.js.map +1 -1
  179. package/build-module/store/reducer.js +44 -14
  180. package/build-module/store/reducer.js.map +1 -1
  181. package/build-module/store/selectors.js +13 -2
  182. package/build-module/store/selectors.js.map +1 -1
  183. package/build-style/style-rtl.css +39 -26
  184. package/build-style/style.css +39 -26
  185. package/package.json +28 -28
  186. package/src/components/alignment-control/README.md +1 -1
  187. package/src/components/block-alignment-control/test/index.native.js +4 -4
  188. package/src/components/block-draggable/test/helpers.native.js +3 -3
  189. package/src/components/block-draggable/test/index.native.js +27 -27
  190. package/src/components/block-list/style.scss +10 -5
  191. package/src/components/block-lock/menu-item.js +5 -2
  192. package/src/components/block-lock/modal.js +19 -36
  193. package/src/components/block-lock/style.scss +8 -17
  194. package/src/components/block-mover/style.scss +0 -1
  195. package/src/components/block-popover/style.scss +1 -1
  196. package/src/components/block-styles/utils.js +3 -3
  197. package/src/components/block-switcher/index.js +19 -4
  198. package/src/components/block-tools/selected-block-popover.js +80 -34
  199. package/src/components/block-tools/style.scss +15 -0
  200. package/src/components/colors/with-colors.js +13 -23
  201. package/src/components/default-block-appender/style.scss +1 -0
  202. package/src/components/font-sizes/fluid-utils.js +37 -64
  203. package/src/components/font-sizes/test/fluid-utils.js +5 -5
  204. package/src/components/font-sizes/with-font-sizes.js +14 -11
  205. package/src/components/index.js +1 -0
  206. package/src/components/inner-blocks/index.js +7 -4
  207. package/src/components/inserter/reusable-blocks-tab.js +4 -2
  208. package/src/components/inserter/style.scss +8 -7
  209. package/src/components/inserter/test/reusable-blocks-tab.js +14 -57
  210. package/src/components/link-control/index.js +23 -39
  211. package/src/components/link-control/search-input.js +1 -1
  212. package/src/components/link-control/test/index.js +272 -241
  213. package/src/components/link-control/use-internal-input-value.js +22 -0
  214. package/src/components/list-view/block.js +4 -3
  215. package/src/components/list-view/branch.js +11 -6
  216. package/src/components/off-canvas-editor/README.md +5 -0
  217. package/src/components/off-canvas-editor/block-contents.js +89 -0
  218. package/src/components/off-canvas-editor/block-select-button.js +113 -0
  219. package/src/components/off-canvas-editor/block.js +335 -0
  220. package/src/components/off-canvas-editor/branch.js +210 -0
  221. package/src/components/off-canvas-editor/context.js +8 -0
  222. package/src/components/off-canvas-editor/drop-indicator.js +126 -0
  223. package/src/components/off-canvas-editor/expander.js +26 -0
  224. package/src/components/off-canvas-editor/index.js +216 -0
  225. package/src/components/off-canvas-editor/leaf.js +48 -0
  226. package/src/components/off-canvas-editor/style.scss +397 -0
  227. package/src/components/off-canvas-editor/test/utils.js +50 -0
  228. package/src/components/off-canvas-editor/use-block-selection.js +169 -0
  229. package/src/components/off-canvas-editor/use-list-view-client-ids.js +29 -0
  230. package/src/components/off-canvas-editor/use-list-view-drop-zone.js +260 -0
  231. package/src/components/off-canvas-editor/use-list-view-expand-selected-item.js +58 -0
  232. package/src/components/off-canvas-editor/utils.js +58 -0
  233. package/src/components/responsive-block-control/test/index.js +69 -92
  234. package/src/components/url-popover/README.md +12 -3
  235. package/src/components/url-popover/index.js +33 -3
  236. package/src/components/use-setting/index.js +7 -1
  237. package/src/hooks/color-panel.js +13 -1
  238. package/src/hooks/color.js +2 -0
  239. package/src/hooks/content-lock-ui.js +46 -34
  240. package/src/hooks/dimensions.js +76 -16
  241. package/src/hooks/layout.js +2 -3
  242. package/src/hooks/margin.js +4 -3
  243. package/src/hooks/min-height.js +121 -0
  244. package/src/hooks/padding.js +4 -3
  245. package/src/hooks/style.js +10 -2
  246. package/src/hooks/test/style.js +4 -0
  247. package/src/hooks/test/use-typography-props.js +1 -1
  248. package/src/layouts/flex.js +43 -38
  249. package/src/store/actions.js +22 -0
  250. package/src/store/reducer.js +50 -40
  251. package/src/store/selectors.js +16 -9
  252. package/src/store/test/actions.js +18 -0
  253. package/src/store/test/reducer.js +40 -0
  254. package/src/store/test/selectors.js +19 -0
@@ -0,0 +1,124 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { speak } from '@wordpress/a11y';
5
+ import { __, sprintf } from '@wordpress/i18n';
6
+ import { useDispatch, useSelect } from '@wordpress/data';
7
+ import { useCallback } from '@wordpress/element';
8
+ import { UP, DOWN, HOME, END } from '@wordpress/keycodes';
9
+ import { store as blocksStore } from '@wordpress/blocks';
10
+ /**
11
+ * Internal dependencies
12
+ */
13
+
14
+ import { store as blockEditorStore } from '../../store';
15
+ import { getCommonDepthClientIds } from './utils';
16
+ export default function useBlockSelection() {
17
+ const {
18
+ clearSelectedBlock,
19
+ multiSelect,
20
+ selectBlock
21
+ } = useDispatch(blockEditorStore);
22
+ const {
23
+ getBlockName,
24
+ getBlockParents,
25
+ getBlockSelectionStart,
26
+ getBlockSelectionEnd,
27
+ getSelectedBlockClientIds,
28
+ hasMultiSelection,
29
+ hasSelectedBlock
30
+ } = useSelect(blockEditorStore);
31
+ const {
32
+ getBlockType
33
+ } = useSelect(blocksStore);
34
+ const updateBlockSelection = useCallback(async (event, clientId, destinationClientId) => {
35
+ if (!(event !== null && event !== void 0 && event.shiftKey)) {
36
+ selectBlock(clientId);
37
+ return;
38
+ } // To handle multiple block selection via the `SHIFT` key, prevent
39
+ // the browser default behavior of opening the link in a new window.
40
+
41
+
42
+ event.preventDefault();
43
+ const isKeyPress = event.type === 'keydown' && (event.keyCode === UP || event.keyCode === DOWN || event.keyCode === HOME || event.keyCode === END); // Handle clicking on a block when no blocks are selected, and return early.
44
+
45
+ if (!isKeyPress && !hasSelectedBlock() && !hasMultiSelection()) {
46
+ selectBlock(clientId, null);
47
+ return;
48
+ }
49
+
50
+ const selectedBlocks = getSelectedBlockClientIds();
51
+ const clientIdWithParents = [...getBlockParents(clientId), clientId];
52
+
53
+ if (isKeyPress && !selectedBlocks.some(blockId => clientIdWithParents.includes(blockId))) {
54
+ // Ensure that shift-selecting blocks via the keyboard only
55
+ // expands the current selection if focusing over already
56
+ // selected blocks. Otherwise, clear the selection so that
57
+ // a user can create a new selection entirely by keyboard.
58
+ await clearSelectedBlock();
59
+ }
60
+
61
+ let startTarget = getBlockSelectionStart();
62
+ let endTarget = clientId; // Handle keyboard behavior for selecting multiple blocks.
63
+
64
+ if (isKeyPress) {
65
+ if (!hasSelectedBlock() && !hasMultiSelection()) {
66
+ // Set the starting point of the selection to the currently
67
+ // focused block, if there are no blocks currently selected.
68
+ // This ensures that as the selection is expanded or contracted,
69
+ // the starting point of the selection is anchored to that block.
70
+ startTarget = clientId;
71
+ }
72
+
73
+ if (destinationClientId) {
74
+ // If the user presses UP or DOWN, we want to ensure that the block they're
75
+ // moving to is the target for selection, and not the currently focused one.
76
+ endTarget = destinationClientId;
77
+ }
78
+ }
79
+
80
+ const startParents = getBlockParents(startTarget);
81
+ const endParents = getBlockParents(endTarget);
82
+ const {
83
+ start,
84
+ end
85
+ } = getCommonDepthClientIds(startTarget, endTarget, startParents, endParents);
86
+ await multiSelect(start, end, null); // Announce deselected block, or number of deselected blocks if
87
+ // the total number of blocks deselected is greater than one.
88
+
89
+ const updatedSelectedBlocks = getSelectedBlockClientIds(); // If the selection is greater than 1 and the Home or End keys
90
+ // were used to generate the selection, then skip announcing the
91
+ // deselected blocks.
92
+
93
+ if ((event.keyCode === HOME || event.keyCode === END) && updatedSelectedBlocks.length > 1) {
94
+ return;
95
+ }
96
+
97
+ const selectionDiff = selectedBlocks.filter(blockId => !updatedSelectedBlocks.includes(blockId));
98
+ let label;
99
+
100
+ if (selectionDiff.length === 1) {
101
+ var _getBlockType;
102
+
103
+ const title = (_getBlockType = getBlockType(getBlockName(selectionDiff[0]))) === null || _getBlockType === void 0 ? void 0 : _getBlockType.title;
104
+
105
+ if (title) {
106
+ label = sprintf(
107
+ /* translators: %s: block name */
108
+ __('%s deselected.'), title);
109
+ }
110
+ } else if (selectionDiff.length > 1) {
111
+ label = sprintf(
112
+ /* translators: %s: number of deselected blocks */
113
+ __('%s blocks deselected.'), selectionDiff.length);
114
+ }
115
+
116
+ if (label) {
117
+ speak(label);
118
+ }
119
+ }, [clearSelectedBlock, getBlockName, getBlockType, getBlockParents, getBlockSelectionStart, getBlockSelectionEnd, getSelectedBlockClientIds, hasMultiSelection, hasSelectedBlock, multiSelect, selectBlock]);
120
+ return {
121
+ updateBlockSelection
122
+ };
123
+ }
124
+ //# sourceMappingURL=use-block-selection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/off-canvas-editor/use-block-selection.js"],"names":["speak","__","sprintf","useDispatch","useSelect","useCallback","UP","DOWN","HOME","END","store","blocksStore","blockEditorStore","getCommonDepthClientIds","useBlockSelection","clearSelectedBlock","multiSelect","selectBlock","getBlockName","getBlockParents","getBlockSelectionStart","getBlockSelectionEnd","getSelectedBlockClientIds","hasMultiSelection","hasSelectedBlock","getBlockType","updateBlockSelection","event","clientId","destinationClientId","shiftKey","preventDefault","isKeyPress","type","keyCode","selectedBlocks","clientIdWithParents","some","blockId","includes","startTarget","endTarget","startParents","endParents","start","end","updatedSelectedBlocks","length","selectionDiff","filter","label","title"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,KAAT,QAAsB,iBAAtB;AACA,SAASC,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SAASC,WAAT,EAAsBC,SAAtB,QAAuC,iBAAvC;AACA,SAASC,WAAT,QAA4B,oBAA5B;AACA,SAASC,EAAT,EAAaC,IAAb,EAAmBC,IAAnB,EAAyBC,GAAzB,QAAoC,qBAApC;AACA,SAASC,KAAK,IAAIC,WAAlB,QAAqC,mBAArC;AAEA;AACA;AACA;;AACA,SAASD,KAAK,IAAIE,gBAAlB,QAA0C,aAA1C;AACA,SAASC,uBAAT,QAAwC,SAAxC;AAEA,eAAe,SAASC,iBAAT,GAA6B;AAC3C,QAAM;AAAEC,IAAAA,kBAAF;AAAsBC,IAAAA,WAAtB;AAAmCC,IAAAA;AAAnC,MACLd,WAAW,CAAES,gBAAF,CADZ;AAEA,QAAM;AACLM,IAAAA,YADK;AAELC,IAAAA,eAFK;AAGLC,IAAAA,sBAHK;AAILC,IAAAA,oBAJK;AAKLC,IAAAA,yBALK;AAMLC,IAAAA,iBANK;AAOLC,IAAAA;AAPK,MAQFpB,SAAS,CAAEQ,gBAAF,CARb;AAUA,QAAM;AAAEa,IAAAA;AAAF,MAAmBrB,SAAS,CAAEO,WAAF,CAAlC;AAEA,QAAM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AACD,MAHA,CAAf;AAKA;;AAED,QAAKG,KAAL,EAAa;AACZlD,MAAAA,KAAK,CAAEkD,KAAF,CAAL;AACA;AACD,GAtHsC,EAuHvC,CACCnC,kBADD,EAECG,YAFD,EAGCO,YAHD,EAICN,eAJD,EAKCC,sBALD,EAMCC,oBAND,EAOCC,yBAPD,EAQCC,iBARD,EASCC,gBATD,EAUCR,WAVD,EAWCC,WAXD,CAvHuC,CAAxC;AAsIA,SAAO;AACNS,IAAAA;AADM,GAAP;AAGA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { speak } from '@wordpress/a11y';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useCallback } from '@wordpress/element';\nimport { UP, DOWN, HOME, END } from '@wordpress/keycodes';\nimport { store as blocksStore } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { getCommonDepthClientIds } from './utils';\n\nexport default function useBlockSelection() {\n\tconst { clearSelectedBlock, multiSelect, selectBlock } =\n\t\tuseDispatch( blockEditorStore );\n\tconst {\n\t\tgetBlockName,\n\t\tgetBlockParents,\n\t\tgetBlockSelectionStart,\n\t\tgetBlockSelectionEnd,\n\t\tgetSelectedBlockClientIds,\n\t\thasMultiSelection,\n\t\thasSelectedBlock,\n\t} = useSelect( blockEditorStore );\n\n\tconst { getBlockType } = useSelect( blocksStore );\n\n\tconst updateBlockSelection = useCallback(\n\t\tasync ( event, clientId, destinationClientId ) => {\n\t\t\tif ( ! event?.shiftKey ) {\n\t\t\t\tselectBlock( clientId );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// To handle multiple block selection via the `SHIFT` key, prevent\n\t\t\t// the browser default behavior of opening the link in a new window.\n\t\t\tevent.preventDefault();\n\n\t\t\tconst isKeyPress =\n\t\t\t\tevent.type === 'keydown' &&\n\t\t\t\t( event.keyCode === UP ||\n\t\t\t\t\tevent.keyCode === DOWN ||\n\t\t\t\t\tevent.keyCode === HOME ||\n\t\t\t\t\tevent.keyCode === END );\n\n\t\t\t// Handle clicking on a block when no blocks are selected, and return early.\n\t\t\tif (\n\t\t\t\t! isKeyPress &&\n\t\t\t\t! hasSelectedBlock() &&\n\t\t\t\t! hasMultiSelection()\n\t\t\t) {\n\t\t\t\tselectBlock( clientId, null );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst selectedBlocks = getSelectedBlockClientIds();\n\t\t\tconst clientIdWithParents = [\n\t\t\t\t...getBlockParents( clientId ),\n\t\t\t\tclientId,\n\t\t\t];\n\n\t\t\tif (\n\t\t\t\tisKeyPress &&\n\t\t\t\t! selectedBlocks.some( ( blockId ) =>\n\t\t\t\t\tclientIdWithParents.includes( blockId )\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\t// Ensure that shift-selecting blocks via the keyboard only\n\t\t\t\t// expands the current selection if focusing over already\n\t\t\t\t// selected blocks. Otherwise, clear the selection so that\n\t\t\t\t// a user can create a new selection entirely by keyboard.\n\t\t\t\tawait clearSelectedBlock();\n\t\t\t}\n\n\t\t\tlet startTarget = getBlockSelectionStart();\n\t\t\tlet endTarget = clientId;\n\n\t\t\t// Handle keyboard behavior for selecting multiple blocks.\n\t\t\tif ( isKeyPress ) {\n\t\t\t\tif ( ! hasSelectedBlock() && ! hasMultiSelection() ) {\n\t\t\t\t\t// Set the starting point of the selection to the currently\n\t\t\t\t\t// focused block, if there are no blocks currently selected.\n\t\t\t\t\t// This ensures that as the selection is expanded or contracted,\n\t\t\t\t\t// the starting point of the selection is anchored to that block.\n\t\t\t\t\tstartTarget = clientId;\n\t\t\t\t}\n\t\t\t\tif ( destinationClientId ) {\n\t\t\t\t\t// If the user presses UP or DOWN, we want to ensure that the block they're\n\t\t\t\t\t// moving to is the target for selection, and not the currently focused one.\n\t\t\t\t\tendTarget = destinationClientId;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst startParents = getBlockParents( startTarget );\n\t\t\tconst endParents = getBlockParents( endTarget );\n\n\t\t\tconst { start, end } = getCommonDepthClientIds(\n\t\t\t\tstartTarget,\n\t\t\t\tendTarget,\n\t\t\t\tstartParents,\n\t\t\t\tendParents\n\t\t\t);\n\t\t\tawait multiSelect( start, end, null );\n\n\t\t\t// Announce deselected block, or number of deselected blocks if\n\t\t\t// the total number of blocks deselected is greater than one.\n\t\t\tconst updatedSelectedBlocks = getSelectedBlockClientIds();\n\n\t\t\t// If the selection is greater than 1 and the Home or End keys\n\t\t\t// were used to generate the selection, then skip announcing the\n\t\t\t// deselected blocks.\n\t\t\tif (\n\t\t\t\t( event.keyCode === HOME || event.keyCode === END ) &&\n\t\t\t\tupdatedSelectedBlocks.length > 1\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst selectionDiff = selectedBlocks.filter(\n\t\t\t\t( blockId ) => ! updatedSelectedBlocks.includes( blockId )\n\t\t\t);\n\n\t\t\tlet label;\n\t\t\tif ( selectionDiff.length === 1 ) {\n\t\t\t\tconst title = getBlockType(\n\t\t\t\t\tgetBlockName( selectionDiff[ 0 ] )\n\t\t\t\t)?.title;\n\t\t\t\tif ( title ) {\n\t\t\t\t\tlabel = sprintf(\n\t\t\t\t\t\t/* translators: %s: block name */\n\t\t\t\t\t\t__( '%s deselected.' ),\n\t\t\t\t\t\ttitle\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} else if ( selectionDiff.length > 1 ) {\n\t\t\t\tlabel = sprintf(\n\t\t\t\t\t/* translators: %s: number of deselected blocks */\n\t\t\t\t\t__( '%s blocks deselected.' ),\n\t\t\t\t\tselectionDiff.length\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif ( label ) {\n\t\t\t\tspeak( label );\n\t\t\t}\n\t\t},\n\t\t[\n\t\t\tclearSelectedBlock,\n\t\t\tgetBlockName,\n\t\t\tgetBlockType,\n\t\t\tgetBlockParents,\n\t\t\tgetBlockSelectionStart,\n\t\t\tgetBlockSelectionEnd,\n\t\t\tgetSelectedBlockClientIds,\n\t\t\thasMultiSelection,\n\t\t\thasSelectedBlock,\n\t\t\tmultiSelect,\n\t\t\tselectBlock,\n\t\t]\n\t);\n\n\treturn {\n\t\tupdateBlockSelection,\n\t};\n}\n"]}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { useSelect } from '@wordpress/data';
5
+ /**
6
+ * Internal dependencies
7
+ */
8
+
9
+ import { store as blockEditorStore } from '../../store';
10
+ export default function useListViewClientIds(blocks) {
11
+ return useSelect(select => {
12
+ const {
13
+ getDraggedBlockClientIds,
14
+ getSelectedBlockClientIds,
15
+ __unstableGetClientIdsTree
16
+ } = select(blockEditorStore);
17
+ return {
18
+ selectedClientIds: getSelectedBlockClientIds(),
19
+ draggedClientIds: getDraggedBlockClientIds(),
20
+ clientIdsTree: blocks ? blocks : __unstableGetClientIdsTree()
21
+ };
22
+ }, [blocks]);
23
+ }
24
+ //# sourceMappingURL=use-list-view-client-ids.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/off-canvas-editor/use-list-view-client-ids.js"],"names":["useSelect","store","blockEditorStore","useListViewClientIds","blocks","select","getDraggedBlockClientIds","getSelectedBlockClientIds","__unstableGetClientIdsTree","selectedClientIds","draggedClientIds","clientIdsTree"],"mappings":"AAAA;AACA;AACA;AAEA,SAASA,SAAT,QAA0B,iBAA1B;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AAEA,eAAe,SAASC,oBAAT,CAA+BC,MAA/B,EAAwC;AACtD,SAAOJ,SAAS,CACbK,MAAF,IAAc;AACb,UAAM;AACLC,MAAAA,wBADK;AAELC,MAAAA,yBAFK;AAGLC,MAAAA;AAHK,QAIFH,MAAM,CAAEH,gBAAF,CAJV;AAMA,WAAO;AACNO,MAAAA,iBAAiB,EAAEF,yBAAyB,EADtC;AAENG,MAAAA,gBAAgB,EAAEJ,wBAAwB,EAFpC;AAGNK,MAAAA,aAAa,EAAEP,MAAM,GAAGA,MAAH,GAAYI,0BAA0B;AAHrD,KAAP;AAKA,GAbc,EAcf,CAAEJ,MAAF,CAde,CAAhB;AAgBA","sourcesContent":["/**\n * WordPress dependencies\n */\n\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\n\nexport default function useListViewClientIds( blocks ) {\n\treturn useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetDraggedBlockClientIds,\n\t\t\t\tgetSelectedBlockClientIds,\n\t\t\t\t__unstableGetClientIdsTree,\n\t\t\t} = select( blockEditorStore );\n\n\t\t\treturn {\n\t\t\t\tselectedClientIds: getSelectedBlockClientIds(),\n\t\t\t\tdraggedClientIds: getDraggedBlockClientIds(),\n\t\t\t\tclientIdsTree: blocks ? blocks : __unstableGetClientIdsTree(),\n\t\t\t};\n\t\t},\n\t\t[ blocks ]\n\t);\n}\n"]}
@@ -0,0 +1,220 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { useSelect } from '@wordpress/data';
5
+ import { useState, useCallback } from '@wordpress/element';
6
+ import { useThrottle, __experimentalUseDropZone as useDropZone } from '@wordpress/compose';
7
+ /**
8
+ * Internal dependencies
9
+ */
10
+
11
+ import { getDistanceToNearestEdge, isPointContainedByRect } from '../../utils/math';
12
+ import useOnBlockDrop from '../use-on-block-drop';
13
+ import { store as blockEditorStore } from '../../store';
14
+ /** @typedef {import('../../utils/math').WPPoint} WPPoint */
15
+
16
+ /**
17
+ * The type of a drag event.
18
+ *
19
+ * @typedef {'default'|'file'|'html'} WPDragEventType
20
+ */
21
+
22
+ /**
23
+ * An array representing data for blocks in the DOM used by drag and drop.
24
+ *
25
+ * @typedef {Object} WPListViewDropZoneBlocks
26
+ * @property {string} clientId The client id for the block.
27
+ * @property {string} rootClientId The root client id for the block.
28
+ * @property {number} blockIndex The block's index.
29
+ * @property {Element} element The DOM element representing the block.
30
+ * @property {number} innerBlockCount The number of inner blocks the block has.
31
+ * @property {boolean} isDraggedBlock Whether the block is currently being dragged.
32
+ * @property {boolean} canInsertDraggedBlocksAsSibling Whether the dragged block can be a sibling of this block.
33
+ * @property {boolean} canInsertDraggedBlocksAsChild Whether the dragged block can be a child of this block.
34
+ */
35
+
36
+ /**
37
+ * An object containing details of a drop target.
38
+ *
39
+ * @typedef {Object} WPListViewDropZoneTarget
40
+ * @property {string} blockIndex The insertion index.
41
+ * @property {string} rootClientId The root client id for the block.
42
+ * @property {string|undefined} clientId The client id for the block.
43
+ * @property {'top'|'bottom'|'inside'} dropPosition The position relative to the block that the user is dropping to.
44
+ * 'inside' refers to nesting as an inner block.
45
+ */
46
+
47
+ /**
48
+ * Determines whether the user positioning the dragged block to nest as an
49
+ * inner block.
50
+ *
51
+ * Presently this is determined by whether the cursor is on the right hand side
52
+ * of the block.
53
+ *
54
+ * @param {WPPoint} point The point representing the cursor position when dragging.
55
+ * @param {DOMRect} rect The rectangle.
56
+ */
57
+
58
+ function isNestingGesture(point, rect) {
59
+ const blockCenterX = rect.left + rect.width / 2;
60
+ return point.x > blockCenterX;
61
+ } // Block navigation is always a vertical list, so only allow dropping
62
+ // to the above or below a block.
63
+
64
+
65
+ const ALLOWED_DROP_EDGES = ['top', 'bottom'];
66
+ /**
67
+ * Given blocks data and the cursor position, compute the drop target.
68
+ *
69
+ * @param {WPListViewDropZoneBlocks} blocksData Data about the blocks in list view.
70
+ * @param {WPPoint} position The point representing the cursor position when dragging.
71
+ *
72
+ * @return {WPListViewDropZoneTarget} An object containing data about the drop target.
73
+ */
74
+
75
+ function getListViewDropTarget(blocksData, position) {
76
+ let candidateEdge;
77
+ let candidateBlockData;
78
+ let candidateDistance;
79
+ let candidateRect;
80
+
81
+ for (const blockData of blocksData) {
82
+ if (blockData.isDraggedBlock) {
83
+ continue;
84
+ }
85
+
86
+ const rect = blockData.element.getBoundingClientRect();
87
+ const [distance, edge] = getDistanceToNearestEdge(position, rect, ALLOWED_DROP_EDGES);
88
+ const isCursorWithinBlock = isPointContainedByRect(position, rect);
89
+
90
+ if (candidateDistance === undefined || distance < candidateDistance || isCursorWithinBlock) {
91
+ candidateDistance = distance;
92
+ const index = blocksData.indexOf(blockData);
93
+ const previousBlockData = blocksData[index - 1]; // If dragging near the top of a block and the preceding block
94
+ // is at the same level, use the preceding block as the candidate
95
+ // instead, as later it makes determining a nesting drop easier.
96
+
97
+ if (edge === 'top' && previousBlockData && previousBlockData.rootClientId === blockData.rootClientId && !previousBlockData.isDraggedBlock) {
98
+ candidateBlockData = previousBlockData;
99
+ candidateEdge = 'bottom';
100
+ candidateRect = previousBlockData.element.getBoundingClientRect();
101
+ } else {
102
+ candidateBlockData = blockData;
103
+ candidateEdge = edge;
104
+ candidateRect = rect;
105
+ } // If the mouse position is within the block, break early
106
+ // as the user would intend to drop either before or after
107
+ // this block.
108
+ //
109
+ // This solves an issue where some rows in the list view
110
+ // tree overlap slightly due to sub-pixel rendering.
111
+
112
+
113
+ if (isCursorWithinBlock) {
114
+ break;
115
+ }
116
+ }
117
+ }
118
+
119
+ if (!candidateBlockData) {
120
+ return;
121
+ }
122
+
123
+ const isDraggingBelow = candidateEdge === 'bottom'; // If the user is dragging towards the bottom of the block check whether
124
+ // they might be trying to nest the block as a child.
125
+ // If the block already has inner blocks, this should always be treated
126
+ // as nesting since the next block in the tree will be the first child.
127
+
128
+ if (isDraggingBelow && candidateBlockData.canInsertDraggedBlocksAsChild && (candidateBlockData.innerBlockCount > 0 || isNestingGesture(position, candidateRect))) {
129
+ return {
130
+ rootClientId: candidateBlockData.clientId,
131
+ blockIndex: 0,
132
+ dropPosition: 'inside'
133
+ };
134
+ } // If dropping as a sibling, but block cannot be inserted in
135
+ // this context, return early.
136
+
137
+
138
+ if (!candidateBlockData.canInsertDraggedBlocksAsSibling) {
139
+ return;
140
+ }
141
+
142
+ const offset = isDraggingBelow ? 1 : 0;
143
+ return {
144
+ rootClientId: candidateBlockData.rootClientId,
145
+ clientId: candidateBlockData.clientId,
146
+ blockIndex: candidateBlockData.blockIndex + offset,
147
+ dropPosition: candidateEdge
148
+ };
149
+ }
150
+ /**
151
+ * A react hook for implementing a drop zone in list view.
152
+ *
153
+ * @return {WPListViewDropZoneTarget} The drop target.
154
+ */
155
+
156
+
157
+ export default function useListViewDropZone() {
158
+ const {
159
+ getBlockRootClientId,
160
+ getBlockIndex,
161
+ getBlockCount,
162
+ getDraggedBlockClientIds,
163
+ canInsertBlocks
164
+ } = useSelect(blockEditorStore);
165
+ const [target, setTarget] = useState();
166
+ const {
167
+ rootClientId: targetRootClientId,
168
+ blockIndex: targetBlockIndex
169
+ } = target || {};
170
+ const onBlockDrop = useOnBlockDrop(targetRootClientId, targetBlockIndex);
171
+ const draggedBlockClientIds = getDraggedBlockClientIds();
172
+ const throttled = useThrottle(useCallback((event, currentTarget) => {
173
+ const position = {
174
+ x: event.clientX,
175
+ y: event.clientY
176
+ };
177
+ const isBlockDrag = !!(draggedBlockClientIds !== null && draggedBlockClientIds !== void 0 && draggedBlockClientIds.length);
178
+ const blockElements = Array.from(currentTarget.querySelectorAll('[data-block]'));
179
+ const blocksData = blockElements.map(blockElement => {
180
+ const clientId = blockElement.dataset.block;
181
+ const rootClientId = getBlockRootClientId(clientId);
182
+ return {
183
+ clientId,
184
+ rootClientId,
185
+ blockIndex: getBlockIndex(clientId),
186
+ element: blockElement,
187
+ isDraggedBlock: isBlockDrag ? draggedBlockClientIds.includes(clientId) : false,
188
+ innerBlockCount: getBlockCount(clientId),
189
+ canInsertDraggedBlocksAsSibling: isBlockDrag ? canInsertBlocks(draggedBlockClientIds, rootClientId) : true,
190
+ canInsertDraggedBlocksAsChild: isBlockDrag ? canInsertBlocks(draggedBlockClientIds, clientId) : true
191
+ };
192
+ });
193
+ const newTarget = getListViewDropTarget(blocksData, position);
194
+
195
+ if (newTarget) {
196
+ setTarget(newTarget);
197
+ }
198
+ }, [draggedBlockClientIds]), 200);
199
+ const ref = useDropZone({
200
+ onDrop: onBlockDrop,
201
+
202
+ onDragOver(event) {
203
+ // `currentTarget` is only available while the event is being
204
+ // handled, so get it now and pass it to the thottled function.
205
+ // https://developer.mozilla.org/en-US/docs/Web/API/Event/currentTarget
206
+ throttled(event, event.currentTarget);
207
+ },
208
+
209
+ onDragEnd() {
210
+ throttled.cancel();
211
+ setTarget(null);
212
+ }
213
+
214
+ });
215
+ return {
216
+ ref,
217
+ target
218
+ };
219
+ }
220
+ //# sourceMappingURL=use-list-view-drop-zone.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/off-canvas-editor/use-list-view-drop-zone.js"],"names":["useSelect","useState","useCallback","useThrottle","__experimentalUseDropZone","useDropZone","getDistanceToNearestEdge","isPointContainedByRect","useOnBlockDrop","store","blockEditorStore","isNestingGesture","point","rect","blockCenterX","left","width","x","ALLOWED_DROP_EDGES","getListViewDropTarget","blocksData","position","candidateEdge","candidateBlockData","candidateDistance","candidateRect","blockData","isDraggedBlock","element","getBoundingClientRect","distance","edge","isCursorWithinBlock","undefined","index","indexOf","previousBlockData","rootClientId","isDraggingBelow","canInsertDraggedBlocksAsChild","innerBlockCount","clientId","blockIndex","dropPosition","canInsertDraggedBlocksAsSibling","offset","useListViewDropZone","getBlockRootClientId","getBlockIndex","getBlockCount","getDraggedBlockClientIds","canInsertBlocks","target","setTarget","targetRootClientId","targetBlockIndex","onBlockDrop","draggedBlockClientIds","throttled","event","currentTarget","clientX","y","clientY","isBlockDrag","length","blockElements","Array","from","querySelectorAll","map","blockElement","dataset","block","includes","newTarget","ref","onDrop","onDragOver","onDragEnd","cancel"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,iBAA1B;AACA,SAASC,QAAT,EAAmBC,WAAnB,QAAsC,oBAAtC;AACA,SACCC,WADD,EAECC,yBAAyB,IAAIC,WAF9B,QAGO,oBAHP;AAKA;AACA;AACA;;AACA,SACCC,wBADD,EAECC,sBAFD,QAGO,kBAHP;AAIA,OAAOC,cAAP,MAA2B,sBAA3B;AACA,S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;AAENJ,QAAAA,YAFM;AAGNK,QAAAA,UAAU,EAAEM,aAAa,CAAEP,QAAF,CAHnB;AAINb,QAAAA,OAAO,EAAE2C,YAJH;AAKN5C,QAAAA,cAAc,EAAEqC,WAAW,GACxBP,qBAAqB,CAACiB,QAAtB,CAAgCjC,QAAhC,CADwB,GAExB,KAPG;AAQND,QAAAA,eAAe,EAAES,aAAa,CAAER,QAAF,CARxB;AASNG,QAAAA,+BAA+B,EAAEoB,WAAW,GACzCb,eAAe,CACfM,qBADe,EAEfpB,YAFe,CAD0B,GAKzC,IAdG;AAeNE,QAAAA,6BAA6B,EAAEyB,WAAW,GACvCb,eAAe,CAAEM,qBAAF,EAAyBhB,QAAzB,CADwB,GAEvC;AAjBG,OAAP;AAmBA,KAvBkB,CAAnB;AAyBA,UAAMkC,SAAS,GAAGxD,qBAAqB,CAAEC,UAAF,EAAcC,QAAd,CAAvC;;AAEA,QAAKsD,SAAL,EAAiB;AAChBtB,MAAAA,SAAS,CAAEsB,SAAF,CAAT;AACA;AACD,GAvCS,EAwCV,CAAElB,qBAAF,CAxCU,CADiB,EA2C5B,GA3C4B,CAA7B;AA8CA,QAAMmB,GAAG,GAAGvE,WAAW,CAAE;AACxBwE,IAAAA,MAAM,EAAErB,WADgB;;AAExBsB,IAAAA,UAAU,CAAEnB,KAAF,EAAU;AACnB;AACA;AACA;AACAD,MAAAA,SAAS,CAAEC,KAAF,EAASA,KAAK,CAACC,aAAf,CAAT;AACA,KAPuB;;AAQxBmB,IAAAA,SAAS,GAAG;AACXrB,MAAAA,SAAS,CAACsB,MAAV;AACA3B,MAAAA,SAAS,CAAE,IAAF,CAAT;AACA;;AAXuB,GAAF,CAAvB;AAcA,SAAO;AAAEuB,IAAAA,GAAF;AAAOxB,IAAAA;AAAP,GAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { useState, useCallback } from '@wordpress/element';\nimport {\n\tuseThrottle,\n\t__experimentalUseDropZone as useDropZone,\n} from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport {\n\tgetDistanceToNearestEdge,\n\tisPointContainedByRect,\n} from '../../utils/math';\nimport useOnBlockDrop from '../use-on-block-drop';\nimport { store as blockEditorStore } from '../../store';\n\n/** @typedef {import('../../utils/math').WPPoint} WPPoint */\n\n/**\n * The type of a drag event.\n *\n * @typedef {'default'|'file'|'html'} WPDragEventType\n */\n\n/**\n * An array representing data for blocks in the DOM used by drag and drop.\n *\n * @typedef {Object} WPListViewDropZoneBlocks\n * @property {string} clientId The client id for the block.\n * @property {string} rootClientId The root client id for the block.\n * @property {number} blockIndex The block's index.\n * @property {Element} element The DOM element representing the block.\n * @property {number} innerBlockCount The number of inner blocks the block has.\n * @property {boolean} isDraggedBlock Whether the block is currently being dragged.\n * @property {boolean} canInsertDraggedBlocksAsSibling Whether the dragged block can be a sibling of this block.\n * @property {boolean} canInsertDraggedBlocksAsChild Whether the dragged block can be a child of this block.\n */\n\n/**\n * An object containing details of a drop target.\n *\n * @typedef {Object} WPListViewDropZoneTarget\n * @property {string} blockIndex The insertion index.\n * @property {string} rootClientId The root client id for the block.\n * @property {string|undefined} clientId The client id for the block.\n * @property {'top'|'bottom'|'inside'} dropPosition The position relative to the block that the user is dropping to.\n * 'inside' refers to nesting as an inner block.\n */\n\n/**\n * Determines whether the user positioning the dragged block to nest as an\n * inner block.\n *\n * Presently this is determined by whether the cursor is on the right hand side\n * of the block.\n *\n * @param {WPPoint} point The point representing the cursor position when dragging.\n * @param {DOMRect} rect The rectangle.\n */\nfunction isNestingGesture( point, rect ) {\n\tconst blockCenterX = rect.left + rect.width / 2;\n\treturn point.x > blockCenterX;\n}\n\n// Block navigation is always a vertical list, so only allow dropping\n// to the above or below a block.\nconst ALLOWED_DROP_EDGES = [ 'top', 'bottom' ];\n\n/**\n * Given blocks data and the cursor position, compute the drop target.\n *\n * @param {WPListViewDropZoneBlocks} blocksData Data about the blocks in list view.\n * @param {WPPoint} position The point representing the cursor position when dragging.\n *\n * @return {WPListViewDropZoneTarget} An object containing data about the drop target.\n */\nfunction getListViewDropTarget( blocksData, position ) {\n\tlet candidateEdge;\n\tlet candidateBlockData;\n\tlet candidateDistance;\n\tlet candidateRect;\n\n\tfor ( const blockData of blocksData ) {\n\t\tif ( blockData.isDraggedBlock ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst rect = blockData.element.getBoundingClientRect();\n\t\tconst [ distance, edge ] = getDistanceToNearestEdge(\n\t\t\tposition,\n\t\t\trect,\n\t\t\tALLOWED_DROP_EDGES\n\t\t);\n\n\t\tconst isCursorWithinBlock = isPointContainedByRect( position, rect );\n\t\tif (\n\t\t\tcandidateDistance === undefined ||\n\t\t\tdistance < candidateDistance ||\n\t\t\tisCursorWithinBlock\n\t\t) {\n\t\t\tcandidateDistance = distance;\n\n\t\t\tconst index = blocksData.indexOf( blockData );\n\t\t\tconst previousBlockData = blocksData[ index - 1 ];\n\n\t\t\t// If dragging near the top of a block and the preceding block\n\t\t\t// is at the same level, use the preceding block as the candidate\n\t\t\t// instead, as later it makes determining a nesting drop easier.\n\t\t\tif (\n\t\t\t\tedge === 'top' &&\n\t\t\t\tpreviousBlockData &&\n\t\t\t\tpreviousBlockData.rootClientId === blockData.rootClientId &&\n\t\t\t\t! previousBlockData.isDraggedBlock\n\t\t\t) {\n\t\t\t\tcandidateBlockData = previousBlockData;\n\t\t\t\tcandidateEdge = 'bottom';\n\t\t\t\tcandidateRect =\n\t\t\t\t\tpreviousBlockData.element.getBoundingClientRect();\n\t\t\t} else {\n\t\t\t\tcandidateBlockData = blockData;\n\t\t\t\tcandidateEdge = edge;\n\t\t\t\tcandidateRect = rect;\n\t\t\t}\n\n\t\t\t// If the mouse position is within the block, break early\n\t\t\t// as the user would intend to drop either before or after\n\t\t\t// this block.\n\t\t\t//\n\t\t\t// This solves an issue where some rows in the list view\n\t\t\t// tree overlap slightly due to sub-pixel rendering.\n\t\t\tif ( isCursorWithinBlock ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tif ( ! candidateBlockData ) {\n\t\treturn;\n\t}\n\n\tconst isDraggingBelow = candidateEdge === 'bottom';\n\n\t// If the user is dragging towards the bottom of the block check whether\n\t// they might be trying to nest the block as a child.\n\t// If the block already has inner blocks, this should always be treated\n\t// as nesting since the next block in the tree will be the first child.\n\tif (\n\t\tisDraggingBelow &&\n\t\tcandidateBlockData.canInsertDraggedBlocksAsChild &&\n\t\t( candidateBlockData.innerBlockCount > 0 ||\n\t\t\tisNestingGesture( position, candidateRect ) )\n\t) {\n\t\treturn {\n\t\t\trootClientId: candidateBlockData.clientId,\n\t\t\tblockIndex: 0,\n\t\t\tdropPosition: 'inside',\n\t\t};\n\t}\n\n\t// If dropping as a sibling, but block cannot be inserted in\n\t// this context, return early.\n\tif ( ! candidateBlockData.canInsertDraggedBlocksAsSibling ) {\n\t\treturn;\n\t}\n\n\tconst offset = isDraggingBelow ? 1 : 0;\n\treturn {\n\t\trootClientId: candidateBlockData.rootClientId,\n\t\tclientId: candidateBlockData.clientId,\n\t\tblockIndex: candidateBlockData.blockIndex + offset,\n\t\tdropPosition: candidateEdge,\n\t};\n}\n\n/**\n * A react hook for implementing a drop zone in list view.\n *\n * @return {WPListViewDropZoneTarget} The drop target.\n */\nexport default function useListViewDropZone() {\n\tconst {\n\t\tgetBlockRootClientId,\n\t\tgetBlockIndex,\n\t\tgetBlockCount,\n\t\tgetDraggedBlockClientIds,\n\t\tcanInsertBlocks,\n\t} = useSelect( blockEditorStore );\n\tconst [ target, setTarget ] = useState();\n\tconst { rootClientId: targetRootClientId, blockIndex: targetBlockIndex } =\n\t\ttarget || {};\n\n\tconst onBlockDrop = useOnBlockDrop( targetRootClientId, targetBlockIndex );\n\n\tconst draggedBlockClientIds = getDraggedBlockClientIds();\n\tconst throttled = useThrottle(\n\t\tuseCallback(\n\t\t\t( event, currentTarget ) => {\n\t\t\t\tconst position = { x: event.clientX, y: event.clientY };\n\t\t\t\tconst isBlockDrag = !! draggedBlockClientIds?.length;\n\n\t\t\t\tconst blockElements = Array.from(\n\t\t\t\t\tcurrentTarget.querySelectorAll( '[data-block]' )\n\t\t\t\t);\n\n\t\t\t\tconst blocksData = blockElements.map( ( blockElement ) => {\n\t\t\t\t\tconst clientId = blockElement.dataset.block;\n\t\t\t\t\tconst rootClientId = getBlockRootClientId( clientId );\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tclientId,\n\t\t\t\t\t\trootClientId,\n\t\t\t\t\t\tblockIndex: getBlockIndex( clientId ),\n\t\t\t\t\t\telement: blockElement,\n\t\t\t\t\t\tisDraggedBlock: isBlockDrag\n\t\t\t\t\t\t\t? draggedBlockClientIds.includes( clientId )\n\t\t\t\t\t\t\t: false,\n\t\t\t\t\t\tinnerBlockCount: getBlockCount( clientId ),\n\t\t\t\t\t\tcanInsertDraggedBlocksAsSibling: isBlockDrag\n\t\t\t\t\t\t\t? canInsertBlocks(\n\t\t\t\t\t\t\t\t\tdraggedBlockClientIds,\n\t\t\t\t\t\t\t\t\trootClientId\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t: true,\n\t\t\t\t\t\tcanInsertDraggedBlocksAsChild: isBlockDrag\n\t\t\t\t\t\t\t? canInsertBlocks( draggedBlockClientIds, clientId )\n\t\t\t\t\t\t\t: true,\n\t\t\t\t\t};\n\t\t\t\t} );\n\n\t\t\t\tconst newTarget = getListViewDropTarget( blocksData, position );\n\n\t\t\t\tif ( newTarget ) {\n\t\t\t\t\tsetTarget( newTarget );\n\t\t\t\t}\n\t\t\t},\n\t\t\t[ draggedBlockClientIds ]\n\t\t),\n\t\t200\n\t);\n\n\tconst ref = useDropZone( {\n\t\tonDrop: onBlockDrop,\n\t\tonDragOver( event ) {\n\t\t\t// `currentTarget` is only available while the event is being\n\t\t\t// handled, so get it now and pass it to the thottled function.\n\t\t\t// https://developer.mozilla.org/en-US/docs/Web/API/Event/currentTarget\n\t\t\tthrottled( event, event.currentTarget );\n\t\t},\n\t\tonDragEnd() {\n\t\t\tthrottled.cancel();\n\t\t\tsetTarget( null );\n\t\t},\n\t} );\n\n\treturn { ref, target };\n}\n"]}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { useEffect, useState } from '@wordpress/element';
5
+ import { useSelect } from '@wordpress/data';
6
+ /**
7
+ * Internal dependencies
8
+ */
9
+
10
+ import { store as blockEditorStore } from '../../store';
11
+ export default function useListViewExpandSelectedItem(_ref) {
12
+ let {
13
+ firstSelectedBlockClientId,
14
+ setExpandedState
15
+ } = _ref;
16
+ const [selectedTreeId, setSelectedTreeId] = useState(null);
17
+ const {
18
+ selectedBlockParentClientIds
19
+ } = useSelect(select => {
20
+ const {
21
+ getBlockParents
22
+ } = select(blockEditorStore);
23
+ return {
24
+ selectedBlockParentClientIds: getBlockParents(firstSelectedBlockClientId, false)
25
+ };
26
+ }, [firstSelectedBlockClientId]);
27
+ const parentClientIds = Array.isArray(selectedBlockParentClientIds) && selectedBlockParentClientIds.length ? selectedBlockParentClientIds : null; // Expand tree when a block is selected.
28
+
29
+ useEffect(() => {
30
+ // If the selectedTreeId is the same as the selected block,
31
+ // it means that the block was selected using the block list tree.
32
+ if (selectedTreeId === firstSelectedBlockClientId) {
33
+ return;
34
+ } // If the selected block has parents, get the top-level parent.
35
+
36
+
37
+ if (parentClientIds) {
38
+ // If the selected block has parents,
39
+ // expand the tree branch.
40
+ setExpandedState({
41
+ type: 'expand',
42
+ clientIds: selectedBlockParentClientIds
43
+ });
44
+ }
45
+ }, [firstSelectedBlockClientId]);
46
+ return {
47
+ setSelectedTreeId
48
+ };
49
+ }
50
+ //# sourceMappingURL=use-list-view-expand-selected-item.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/off-canvas-editor/use-list-view-expand-selected-item.js"],"names":["useEffect","useState","useSelect","store","blockEditorStore","useListViewExpandSelectedItem","firstSelectedBlockClientId","setExpandedState","selectedTreeId","setSelectedTreeId","selectedBlockParentClientIds","select","getBlockParents","parentClientIds","Array","isArray","length","type","clientIds"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,EAAoBC,QAApB,QAAoC,oBAApC;AACA,SAASC,SAAT,QAA0B,iBAA1B;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AAEA,eAAe,SAASC,6BAAT,OAGX;AAAA,MAHmD;AACtDC,IAAAA,0BADsD;AAEtDC,IAAAA;AAFsD,GAGnD;AACH,QAAM,CAAEC,cAAF,EAAkBC,iBAAlB,IAAwCR,QAAQ,CAAE,IAAF,CAAtD;AACA,QAAM;AAAES,IAAAA;AAAF,MAAmCR,SAAS,CAC/CS,MAAF,IAAc;AACb,UAAM;AAAEC,MAAAA;AAAF,QAAsBD,MAAM,CAAEP,gBAAF,CAAlC;AACA,WAAO;AACNM,MAAAA,4BAA4B,EAAEE,eAAe,CAC5CN,0BAD4C,EAE5C,KAF4C;AADvC,KAAP;AAMA,GATgD,EAUjD,CAAEA,0BAAF,CAViD,CAAlD;AAaA,QAAMO,eAAe,GACpBC,KAAK,CAACC,OAAN,CAAeL,4BAAf,KACAA,4BAA4B,CAACM,MAD7B,GAEGN,4BAFH,GAGG,IAJJ,CAfG,CAqBH;;AACAV,EAAAA,SAAS,CAAE,MAAM;AAChB;AACA;AACA,QAAKQ,cAAc,KAAKF,0BAAxB,EAAqD;AACpD;AACA,KALe,CAOhB;;;AACA,QAAKO,eAAL,EAAuB;AACtB;AACA;AACAN,MAAAA,gBAAgB,CAAE;AACjBU,QAAAA,IAAI,EAAE,QADW;AAEjBC,QAAAA,SAAS,EAAER;AAFM,OAAF,CAAhB;AAIA;AACD,GAhBQ,EAgBN,CAAEJ,0BAAF,CAhBM,CAAT;AAkBA,SAAO;AACNG,IAAAA;AADM,GAAP;AAGA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useEffect, useState } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\n\nexport default function useListViewExpandSelectedItem( {\n\tfirstSelectedBlockClientId,\n\tsetExpandedState,\n} ) {\n\tconst [ selectedTreeId, setSelectedTreeId ] = useState( null );\n\tconst { selectedBlockParentClientIds } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlockParents } = select( blockEditorStore );\n\t\t\treturn {\n\t\t\t\tselectedBlockParentClientIds: getBlockParents(\n\t\t\t\t\tfirstSelectedBlockClientId,\n\t\t\t\t\tfalse\n\t\t\t\t),\n\t\t\t};\n\t\t},\n\t\t[ firstSelectedBlockClientId ]\n\t);\n\n\tconst parentClientIds =\n\t\tArray.isArray( selectedBlockParentClientIds ) &&\n\t\tselectedBlockParentClientIds.length\n\t\t\t? selectedBlockParentClientIds\n\t\t\t: null;\n\n\t// Expand tree when a block is selected.\n\tuseEffect( () => {\n\t\t// If the selectedTreeId is the same as the selected block,\n\t\t// it means that the block was selected using the block list tree.\n\t\tif ( selectedTreeId === firstSelectedBlockClientId ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// If the selected block has parents, get the top-level parent.\n\t\tif ( parentClientIds ) {\n\t\t\t// If the selected block has parents,\n\t\t\t// expand the tree branch.\n\t\t\tsetExpandedState( {\n\t\t\t\ttype: 'expand',\n\t\t\t\tclientIds: selectedBlockParentClientIds,\n\t\t\t} );\n\t\t}\n\t}, [ firstSelectedBlockClientId ] );\n\n\treturn {\n\t\tsetSelectedTreeId,\n\t};\n}\n"]}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { __, sprintf } from '@wordpress/i18n';
5
+ export const getBlockPositionDescription = (position, siblingCount, level) => sprintf(
6
+ /* translators: 1: The numerical position of the block. 2: The total number of blocks. 3. The level of nesting for the block. */
7
+ __('Block %1$d of %2$d, Level %3$d'), position, siblingCount, level);
8
+ /**
9
+ * Returns true if the client ID occurs within the block selection or multi-selection,
10
+ * or false otherwise.
11
+ *
12
+ * @param {string} clientId Block client ID.
13
+ * @param {string|string[]} selectedBlockClientIds Selected block client ID, or an array of multi-selected blocks client IDs.
14
+ *
15
+ * @return {boolean} Whether the block is in multi-selection set.
16
+ */
17
+
18
+ export const isClientIdSelected = (clientId, selectedBlockClientIds) => Array.isArray(selectedBlockClientIds) && selectedBlockClientIds.length ? selectedBlockClientIds.indexOf(clientId) !== -1 : selectedBlockClientIds === clientId;
19
+ /**
20
+ * From a start and end clientId of potentially different nesting levels,
21
+ * return the nearest-depth ids that have a common level of depth in the
22
+ * nesting hierarchy. For multiple block selection, this ensure that the
23
+ * selection is always at the same nesting level, and not split across
24
+ * separate levels.
25
+ *
26
+ * @param {string} startId The first id of a selection.
27
+ * @param {string} endId The end id of a selection, usually one that has been clicked on.
28
+ * @param {string[]} startParents An array of ancestor ids for the start id, in descending order.
29
+ * @param {string[]} endParents An array of ancestor ids for the end id, in descending order.
30
+ * @return {Object} An object containing the start and end ids.
31
+ */
32
+
33
+ export function getCommonDepthClientIds(startId, endId, startParents, endParents) {
34
+ const startPath = [...startParents, startId];
35
+ const endPath = [...endParents, endId];
36
+ const depth = Math.min(startPath.length, endPath.length) - 1;
37
+ const start = startPath[depth];
38
+ const end = endPath[depth];
39
+ return {
40
+ start,
41
+ end
42
+ };
43
+ }
44
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/off-canvas-editor/utils.js"],"names":["__","sprintf","getBlockPositionDescription","position","siblingCount","level","isClientIdSelected","clientId","selectedBlockClientIds","Array","isArray","length","indexOf","getCommonDepthClientIds","startId","endId","startParents","endParents","startPath","endPath","depth","Math","min","start","end"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AAEA,OAAO,MAAMC,2BAA2B,GAAG,CAAEC,QAAF,EAAYC,YAAZ,EAA0BC,KAA1B,KAC1CJ,OAAO;AACN;AACAD,EAAE,CAAE,gCAAF,CAFI,EAGNG,QAHM,EAINC,YAJM,EAKNC,KALM,CADD;AASP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,kBAAkB,GAAG,CAAEC,QAAF,EAAYC,sBAAZ,KACjCC,KAAK,CAACC,OAAN,CAAeF,sBAAf,KAA2CA,sBAAsB,CAACG,MAAlE,GACGH,sBAAsB,CAACI,OAAvB,CAAgCL,QAAhC,MAA+C,CAAC,CADnD,GAEGC,sBAAsB,KAAKD,QAHxB;AAKP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASM,uBAAT,CACNC,OADM,EAENC,KAFM,EAGNC,YAHM,EAINC,UAJM,EAKL;AACD,QAAMC,SAAS,GAAG,CAAE,GAAGF,YAAL,EAAmBF,OAAnB,CAAlB;AACA,QAAMK,OAAO,GAAG,CAAE,GAAGF,UAAL,EAAiBF,KAAjB,CAAhB;AACA,QAAMK,KAAK,GAAGC,IAAI,CAACC,GAAL,CAAUJ,SAAS,CAACP,MAApB,EAA4BQ,OAAO,CAACR,MAApC,IAA+C,CAA7D;AACA,QAAMY,KAAK,GAAGL,SAAS,CAAEE,KAAF,CAAvB;AACA,QAAMI,GAAG,GAAGL,OAAO,CAAEC,KAAF,CAAnB;AAEA,SAAO;AACNG,IAAAA,KADM;AAENC,IAAAA;AAFM,GAAP;AAIA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\n\nexport const getBlockPositionDescription = ( position, siblingCount, level ) =>\n\tsprintf(\n\t\t/* translators: 1: The numerical position of the block. 2: The total number of blocks. 3. The level of nesting for the block. */\n\t\t__( 'Block %1$d of %2$d, Level %3$d' ),\n\t\tposition,\n\t\tsiblingCount,\n\t\tlevel\n\t);\n\n/**\n * Returns true if the client ID occurs within the block selection or multi-selection,\n * or false otherwise.\n *\n * @param {string} clientId Block client ID.\n * @param {string|string[]} selectedBlockClientIds Selected block client ID, or an array of multi-selected blocks client IDs.\n *\n * @return {boolean} Whether the block is in multi-selection set.\n */\nexport const isClientIdSelected = ( clientId, selectedBlockClientIds ) =>\n\tArray.isArray( selectedBlockClientIds ) && selectedBlockClientIds.length\n\t\t? selectedBlockClientIds.indexOf( clientId ) !== -1\n\t\t: selectedBlockClientIds === clientId;\n\n/**\n * From a start and end clientId of potentially different nesting levels,\n * return the nearest-depth ids that have a common level of depth in the\n * nesting hierarchy. For multiple block selection, this ensure that the\n * selection is always at the same nesting level, and not split across\n * separate levels.\n *\n * @param {string} startId The first id of a selection.\n * @param {string} endId The end id of a selection, usually one that has been clicked on.\n * @param {string[]} startParents An array of ancestor ids for the start id, in descending order.\n * @param {string[]} endParents An array of ancestor ids for the end id, in descending order.\n * @return {Object} An object containing the start and end ids.\n */\nexport function getCommonDepthClientIds(\n\tstartId,\n\tendId,\n\tstartParents,\n\tendParents\n) {\n\tconst startPath = [ ...startParents, startId ];\n\tconst endPath = [ ...endParents, endId ];\n\tconst depth = Math.min( startPath.length, endPath.length ) - 1;\n\tconst start = startPath[ depth ];\n\tconst end = endPath[ depth ];\n\n\treturn {\n\t\tstart,\n\t\tend,\n\t};\n}\n"]}
@@ -6,24 +6,51 @@ import { createElement } from "@wordpress/element";
6
6
  */
7
7
  import { __ } from '@wordpress/i18n';
8
8
  import { useState } from '@wordpress/element';
9
- import { Button, Popover } from '@wordpress/components';
9
+ import { Button, Popover, __experimentalPopoverPositionToPlacement as positionToPlacement } from '@wordpress/components';
10
10
  import { chevronDown } from '@wordpress/icons';
11
+ import deprecated from '@wordpress/deprecated';
11
12
  /**
12
13
  * Internal dependencies
13
14
  */
14
15
 
15
16
  import LinkViewer from './link-viewer';
16
17
  import LinkEditor from './link-editor';
18
+ const DEFAULT_PLACEMENT = 'bottom';
17
19
 
18
20
  function URLPopover(_ref) {
19
21
  let {
20
22
  additionalControls,
21
23
  children,
22
24
  renderSettings,
23
- position = 'bottom center',
25
+ // The DEFAULT_PLACEMENT value is assigned inside the function's body
26
+ placement,
24
27
  focusOnMount = 'firstElement',
28
+ // Deprecated
29
+ position,
30
+ // Rest
25
31
  ...popoverProps
26
32
  } = _ref;
33
+
34
+ if (position !== undefined) {
35
+ deprecated('`position` prop in wp.blockEditor.URLPopover', {
36
+ since: '6.2',
37
+ alternative: '`placement` prop'
38
+ });
39
+ } // Compute popover's placement:
40
+ // - give priority to `placement` prop, if defined
41
+ // - otherwise, compute it from the legacy `position` prop (if defined)
42
+ // - finally, fallback to the DEFAULT_PLACEMENT.
43
+
44
+
45
+ let computedPlacement;
46
+
47
+ if (placement !== undefined) {
48
+ computedPlacement = placement;
49
+ } else if (position !== undefined) {
50
+ computedPlacement = positionToPlacement(position);
51
+ }
52
+
53
+ computedPlacement = computedPlacement || DEFAULT_PLACEMENT;
27
54
  const [isSettingsExpanded, setIsSettingsExpanded] = useState(false);
28
55
  const showSettings = !!renderSettings && isSettingsExpanded;
29
56
 
@@ -34,7 +61,7 @@ function URLPopover(_ref) {
34
61
  return createElement(Popover, _extends({
35
62
  className: "block-editor-url-popover",
36
63
  focusOnMount: focusOnMount,
37
- position: position,
64
+ placement: computedPlacement,
38
65
  shift: true
39
66
  }, popoverProps), createElement("div", {
40
67
  className: "block-editor-url-popover__input-container"
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/url-popover/index.js"],"names":["__","useState","Button","Popover","chevronDown","LinkViewer","LinkEditor","URLPopover","additionalControls","children","renderSettings","position","focusOnMount","popoverProps","isSettingsExpanded","setIsSettingsExpanded","showSettings","toggleSettingsVisibility"],"mappings":";;;AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AACA,SAASC,QAAT,QAAyB,oBAAzB;AACA,SAASC,MAAT,EAAiBC,OAAjB,QAAgC,uBAAhC;AACA,SAASC,WAAT,QAA4B,kBAA5B;AAEA;AACA;AACA;;AACA,OAAOC,UAAP,MAAuB,eAAvB;AACA,OAAOC,UAAP,MAAuB,eAAvB;;AAEA,SAASC,UAAT,OAOI;AAAA,MAPiB;AACpBC,IAAAA,kBADoB;AAEpBC,IAAAA,QAFoB;AAGpBC,IAAAA,cAHoB;AAIpBC,IAAAA,QAAQ,GAAG,eAJS;AAKpBC,IAAAA,YAAY,GAAG,cALK;AAMpB,OAAGC;AANiB,GAOjB;AACH,QAAM,CAAEC,kBAAF,EAAsBC,qBAAtB,IAAgDd,QAAQ,CAAE,KAAF,CAA9D;AAEA,QAAMe,YAAY,GAAG,CAAC,CAAEN,cAAH,IAAqBI,kBAA1C;;AAEA,QAAMG,wBAAwB,GAAG,MAAM;AACtCF,IAAAA,qBAAqB,CAAE,CAAED,kBAAJ,CAArB;AACA,GAFD;;AAIA,SACC,cAAC,OAAD;AACC,IAAA,SAAS,EAAC,0BADX;AAEC,IAAA,YAAY,EAAGF,YAFhB;AAGC,IAAA,QAAQ,EAAGD,QAHZ;AAIC,IAAA,KAAK;AAJN,KAKME,YALN,GAOC;AAAK,IAAA,SAAS,EAAC;AAAf,KACC;AAAK,IAAA,SAAS,EAAC;AAAf,KACGJ,QADH,EAEG,CAAC,CAAEC,cAAH,IACD,cAAC,MAAD;AACC,IAAA,SAAS,EAAC,2CADX;AAEC,IAAA,IAAI,EAAGN,WAFR;AAGC,IAAA,KAAK,EAAGJ,EAAE,CAAE,eAAF,CAHX;AAIC,IAAA,OAAO,EAAGiB,wBAJX;AAKC,qBAAgBH;AALjB,IAHF,CADD,EAaGE,YAAY,IACb;AAAK,IAAA,SAAS,EAAC;AAAf,KACGN,cAAc,EADjB,CAdF,CAPD,EA0BGF,kBAAkB,IAAI,CAAEQ,YAAxB,IACD;AAAK,IAAA,SAAS,EAAC;AAAf,KACGR,kBADH,CA3BF,CADD;AAkCA;;AAEDD,UAAU,CAACD,UAAX,GAAwBA,UAAxB;AAEAC,UAAU,CAACF,UAAX,GAAwBA,UAAxB;AAEA;AACA;AACA;;AACA,eAAeE,UAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useState } from '@wordpress/element';\nimport { Button, Popover } from '@wordpress/components';\nimport { chevronDown } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport LinkViewer from './link-viewer';\nimport LinkEditor from './link-editor';\n\nfunction URLPopover( {\n\tadditionalControls,\n\tchildren,\n\trenderSettings,\n\tposition = 'bottom center',\n\tfocusOnMount = 'firstElement',\n\t...popoverProps\n} ) {\n\tconst [ isSettingsExpanded, setIsSettingsExpanded ] = useState( false );\n\n\tconst showSettings = !! renderSettings && isSettingsExpanded;\n\n\tconst toggleSettingsVisibility = () => {\n\t\tsetIsSettingsExpanded( ! isSettingsExpanded );\n\t};\n\n\treturn (\n\t\t<Popover\n\t\t\tclassName=\"block-editor-url-popover\"\n\t\t\tfocusOnMount={ focusOnMount }\n\t\t\tposition={ position }\n\t\t\tshift\n\t\t\t{ ...popoverProps }\n\t\t>\n\t\t\t<div className=\"block-editor-url-popover__input-container\">\n\t\t\t\t<div className=\"block-editor-url-popover__row\">\n\t\t\t\t\t{ children }\n\t\t\t\t\t{ !! renderSettings && (\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tclassName=\"block-editor-url-popover__settings-toggle\"\n\t\t\t\t\t\t\ticon={ chevronDown }\n\t\t\t\t\t\t\tlabel={ __( 'Link settings' ) }\n\t\t\t\t\t\t\tonClick={ toggleSettingsVisibility }\n\t\t\t\t\t\t\taria-expanded={ isSettingsExpanded }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t\t{ showSettings && (\n\t\t\t\t\t<div className=\"block-editor-url-popover__row block-editor-url-popover__settings\">\n\t\t\t\t\t\t{ renderSettings() }\n\t\t\t\t\t</div>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t\t{ additionalControls && ! showSettings && (\n\t\t\t\t<div className=\"block-editor-url-popover__additional-controls\">\n\t\t\t\t\t{ additionalControls }\n\t\t\t\t</div>\n\t\t\t) }\n\t\t</Popover>\n\t);\n}\n\nURLPopover.LinkEditor = LinkEditor;\n\nURLPopover.LinkViewer = LinkViewer;\n\n/**\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/url-popover/README.md\n */\nexport default URLPopover;\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/url-popover/index.js"],"names":["__","useState","Button","Popover","__experimentalPopoverPositionToPlacement","positionToPlacement","chevronDown","deprecated","LinkViewer","LinkEditor","DEFAULT_PLACEMENT","URLPopover","additionalControls","children","renderSettings","placement","focusOnMount","position","popoverProps","undefined","since","alternative","computedPlacement","isSettingsExpanded","setIsSettingsExpanded","showSettings","toggleSettingsVisibility"],"mappings":";;;AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AACA,SAASC,QAAT,QAAyB,oBAAzB;AACA,SACCC,MADD,EAECC,OAFD,EAGCC,wCAAwC,IAAIC,mBAH7C,QAIO,uBAJP;AAKA,SAASC,WAAT,QAA4B,kBAA5B;AACA,OAAOC,UAAP,MAAuB,uBAAvB;AAEA;AACA;AACA;;AACA,OAAOC,UAAP,MAAuB,eAAvB;AACA,OAAOC,UAAP,MAAuB,eAAvB;AAEA,MAAMC,iBAAiB,GAAG,QAA1B;;AAEA,SAASC,UAAT,OAWI;AAAA,MAXiB;AACpBC,IAAAA,kBADoB;AAEpBC,IAAAA,QAFoB;AAGpBC,IAAAA,cAHoB;AAIpB;AACAC,IAAAA,SALoB;AAMpBC,IAAAA,YAAY,GAAG,cANK;AAOpB;AACAC,IAAAA,QARoB;AASpB;AACA,OAAGC;AAViB,GAWjB;;AACH,MAAKD,QAAQ,KAAKE,SAAlB,EAA8B;AAC7BZ,IAAAA,UAAU,CAAE,8CAAF,EAAkD;AAC3Da,MAAAA,KAAK,EAAE,KADoD;AAE3DC,MAAAA,WAAW,EAAE;AAF8C,KAAlD,CAAV;AAIA,GANE,CAQH;AACA;AACA;AACA;;;AACA,MAAIC,iBAAJ;;AACA,MAAKP,SAAS,KAAKI,SAAnB,EAA+B;AAC9BG,IAAAA,iBAAiB,GA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port { useState } from '@wordpress/element';\nimport {\n\tButton,\n\tPopover,\n\t__experimentalPopoverPositionToPlacement as positionToPlacement,\n} from '@wordpress/components';\nimport { chevronDown } from '@wordpress/icons';\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport LinkViewer from './link-viewer';\nimport LinkEditor from './link-editor';\n\nconst DEFAULT_PLACEMENT = 'bottom';\n\nfunction URLPopover( {\n\tadditionalControls,\n\tchildren,\n\trenderSettings,\n\t// The DEFAULT_PLACEMENT value is assigned inside the function's body\n\tplacement,\n\tfocusOnMount = 'firstElement',\n\t// Deprecated\n\tposition,\n\t// Rest\n\t...popoverProps\n} ) {\n\tif ( position !== undefined ) {\n\t\tdeprecated( '`position` prop in wp.blockEditor.URLPopover', {\n\t\t\tsince: '6.2',\n\t\t\talternative: '`placement` prop',\n\t\t} );\n\t}\n\n\t// Compute popover's placement:\n\t// - give priority to `placement` prop, if defined\n\t// - otherwise, compute it from the legacy `position` prop (if defined)\n\t// - finally, fallback to the DEFAULT_PLACEMENT.\n\tlet computedPlacement;\n\tif ( placement !== undefined ) {\n\t\tcomputedPlacement = placement;\n\t} else if ( position !== undefined ) {\n\t\tcomputedPlacement = positionToPlacement( position );\n\t}\n\tcomputedPlacement = computedPlacement || DEFAULT_PLACEMENT;\n\n\tconst [ isSettingsExpanded, setIsSettingsExpanded ] = useState( false );\n\n\tconst showSettings = !! renderSettings && isSettingsExpanded;\n\n\tconst toggleSettingsVisibility = () => {\n\t\tsetIsSettingsExpanded( ! isSettingsExpanded );\n\t};\n\n\treturn (\n\t\t<Popover\n\t\t\tclassName=\"block-editor-url-popover\"\n\t\t\tfocusOnMount={ focusOnMount }\n\t\t\tplacement={ computedPlacement }\n\t\t\tshift\n\t\t\t{ ...popoverProps }\n\t\t>\n\t\t\t<div className=\"block-editor-url-popover__input-container\">\n\t\t\t\t<div className=\"block-editor-url-popover__row\">\n\t\t\t\t\t{ children }\n\t\t\t\t\t{ !! renderSettings && (\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tclassName=\"block-editor-url-popover__settings-toggle\"\n\t\t\t\t\t\t\ticon={ chevronDown }\n\t\t\t\t\t\t\tlabel={ __( 'Link settings' ) }\n\t\t\t\t\t\t\tonClick={ toggleSettingsVisibility }\n\t\t\t\t\t\t\taria-expanded={ isSettingsExpanded }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t\t{ showSettings && (\n\t\t\t\t\t<div className=\"block-editor-url-popover__row block-editor-url-popover__settings\">\n\t\t\t\t\t\t{ renderSettings() }\n\t\t\t\t\t</div>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t\t{ additionalControls && ! showSettings && (\n\t\t\t\t<div className=\"block-editor-url-popover__additional-controls\">\n\t\t\t\t\t{ additionalControls }\n\t\t\t\t</div>\n\t\t\t) }\n\t\t</Popover>\n\t);\n}\n\nURLPopover.LinkEditor = LinkEditor;\n\nURLPopover.LinkViewer = LinkViewer;\n\n/**\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/url-popover/README.md\n */\nexport default URLPopover;\n"]}
@@ -14,7 +14,7 @@ import { __EXPERIMENTAL_PATHS_WITH_MERGE as PATHS_WITH_MERGE, hasBlockSupport }
14
14
 
15
15
  import { useBlockEditContext } from '../block-edit';
16
16
  import { store as blockEditorStore } from '../../store';
17
- const blockedPaths = ['color', 'border', 'typography', 'spacing'];
17
+ const blockedPaths = ['color', 'border', 'dimensions', 'typography', 'spacing'];
18
18
  const deprecatedFlags = {
19
19
  'color.palette': settings => settings.colors,
20
20
  'color.gradients': settings => settings.gradients,