@wordpress/block-editor 8.0.17 → 8.1.2-next.f435e9e01b.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 (496) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/LICENSE.md +1 -1
  3. package/README.md +19 -6
  4. package/build/components/block-caption/index.native.js +14 -3
  5. package/build/components/block-caption/index.native.js.map +1 -1
  6. package/build/components/block-edit/index.js +9 -0
  7. package/build/components/block-edit/index.js.map +1 -1
  8. package/build/components/block-inspector/index.js +14 -19
  9. package/build/components/block-inspector/index.js.map +1 -1
  10. package/build/components/block-list-appender/index.js +3 -11
  11. package/build/components/block-list-appender/index.js.map +1 -1
  12. package/build/components/block-media-update-progress/index.native.js +2 -1
  13. package/build/components/block-media-update-progress/index.native.js.map +1 -1
  14. package/build/components/block-preview/auto.js +10 -2
  15. package/build/components/block-preview/auto.js.map +1 -1
  16. package/build/components/block-settings/container.native.js +2 -1
  17. package/build/components/block-settings/container.native.js.map +1 -1
  18. package/build/components/block-styles/index.js +110 -134
  19. package/build/components/block-styles/index.js.map +1 -1
  20. package/build/components/block-styles/menu-items.js +63 -0
  21. package/build/components/block-styles/menu-items.js.map +1 -0
  22. package/build/components/block-styles/preview-panel.js +45 -0
  23. package/build/components/block-styles/preview-panel.js.map +1 -0
  24. package/build/components/block-styles/preview.native.js +2 -2
  25. package/build/components/block-styles/preview.native.js.map +1 -1
  26. package/build/components/block-styles/use-styles-for-block.js +119 -0
  27. package/build/components/block-styles/use-styles-for-block.js.map +1 -0
  28. package/build/components/block-styles/utils.js +39 -0
  29. package/build/components/block-styles/utils.js.map +1 -1
  30. package/build/components/block-switcher/block-styles-menu.js +3 -23
  31. package/build/components/block-switcher/block-styles-menu.js.map +1 -1
  32. package/build/components/block-tools/back-compat.js +2 -1
  33. package/build/components/block-tools/back-compat.js.map +1 -1
  34. package/build/components/block-tools/block-selection-button.js +5 -1
  35. package/build/components/block-tools/block-selection-button.js.map +1 -1
  36. package/build/components/block-tools/insertion-point.js +11 -1
  37. package/build/components/block-tools/insertion-point.js.map +1 -1
  38. package/build/components/block-types-list/index.native.js +2 -2
  39. package/build/components/block-types-list/index.native.js.map +1 -1
  40. package/build/components/button-block-appender/index.js +2 -1
  41. package/build/components/button-block-appender/index.js.map +1 -1
  42. package/build/components/colors-gradients/dropdown.js +1 -1
  43. package/build/components/colors-gradients/dropdown.js.map +1 -1
  44. package/build/components/colors-gradients/panel-color-gradient-settings.native.js +6 -3
  45. package/build/components/colors-gradients/panel-color-gradient-settings.native.js.map +1 -1
  46. package/build/components/colors-gradients/tools-panel-color-dropdown.js +89 -0
  47. package/build/components/colors-gradients/tools-panel-color-dropdown.js.map +1 -0
  48. package/build/components/contrast-checker/index.js +80 -44
  49. package/build/components/contrast-checker/index.js.map +1 -1
  50. package/build/components/contrast-checker/index.native.js +108 -0
  51. package/build/components/contrast-checker/index.native.js.map +1 -0
  52. package/build/components/default-block-appender/index.js +16 -19
  53. package/build/components/default-block-appender/index.js.map +1 -1
  54. package/build/components/default-style-picker/index.js +18 -3
  55. package/build/components/default-style-picker/index.js.map +1 -1
  56. package/build/components/iframe/index.js +4 -5
  57. package/build/components/iframe/index.js.map +1 -1
  58. package/build/components/index.js +18 -18
  59. package/build/components/index.js.map +1 -1
  60. package/build/components/index.native.js +18 -0
  61. package/build/components/index.native.js.map +1 -1
  62. package/build/components/inner-blocks/default-block-appender.js +2 -4
  63. package/build/components/inner-blocks/default-block-appender.js.map +1 -1
  64. package/build/components/inner-blocks/use-nested-settings-update.js +16 -14
  65. package/build/components/inner-blocks/use-nested-settings-update.js.map +1 -1
  66. package/build/components/inserter/index.js +61 -3
  67. package/build/components/inserter/index.js.map +1 -1
  68. package/build/components/inserter/index.native.js +1 -1
  69. package/build/components/inserter/index.native.js.map +1 -1
  70. package/build/components/inserter/library.js +5 -3
  71. package/build/components/inserter/library.js.map +1 -1
  72. package/build/components/inserter/menu.js +11 -3
  73. package/build/components/inserter/menu.js.map +1 -1
  74. package/build/components/inserter/search-items.js +3 -1
  75. package/build/components/inserter/search-items.js.map +1 -1
  76. package/build/components/inserter/tabs.native.js +7 -4
  77. package/build/components/inserter/tabs.native.js.map +1 -1
  78. package/build/components/inspector-controls/block-support-slot-container.js +2 -1
  79. package/build/components/inspector-controls/block-support-slot-container.js.map +1 -1
  80. package/build/components/inspector-controls/block-support-tools-panel.js +14 -44
  81. package/build/components/inspector-controls/block-support-tools-panel.js.map +1 -1
  82. package/build/components/inspector-controls/fill.native.js +3 -5
  83. package/build/components/inspector-controls/fill.native.js.map +1 -1
  84. package/build/components/inspector-controls/groups.js +4 -0
  85. package/build/components/inspector-controls/groups.js.map +1 -1
  86. package/build/components/inspector-controls/slot.js +1 -3
  87. package/build/components/inspector-controls/slot.js.map +1 -1
  88. package/build/components/letter-spacing-control/index.js +6 -6
  89. package/build/components/letter-spacing-control/index.js.map +1 -1
  90. package/build/components/line-height-control/index.native.js +3 -2
  91. package/build/components/line-height-control/index.native.js.map +1 -1
  92. package/build/components/link-control/link-preview.js +1 -1
  93. package/build/components/link-control/link-preview.js.map +1 -1
  94. package/build/components/link-control/search-item.js +11 -1
  95. package/build/components/link-control/search-item.js.map +1 -1
  96. package/build/components/link-control/search-results.js +2 -1
  97. package/build/components/link-control/search-results.js.map +1 -1
  98. package/build/components/link-control/use-search-handler.js +18 -5
  99. package/build/components/link-control/use-search-handler.js.map +1 -1
  100. package/build/components/list-view/block-contents.js +3 -1
  101. package/build/components/list-view/block-contents.js.map +1 -1
  102. package/build/components/list-view/block-select-button.js +26 -4
  103. package/build/components/list-view/block-select-button.js.map +1 -1
  104. package/build/components/list-view/block.js +10 -1
  105. package/build/components/list-view/block.js.map +1 -1
  106. package/build/components/media-placeholder/index.js +3 -11
  107. package/build/components/media-placeholder/index.js.map +1 -1
  108. package/build/components/media-replace-flow/index.js +32 -6
  109. package/build/components/media-replace-flow/index.js.map +1 -1
  110. package/build/components/media-replace-flow/index.native.js +13 -0
  111. package/build/components/media-replace-flow/index.native.js.map +1 -0
  112. package/build/components/media-upload-progress/index.native.js +2 -1
  113. package/build/components/media-upload-progress/index.native.js.map +1 -1
  114. package/build/components/panel-color-settings/index.js +7 -3
  115. package/build/components/panel-color-settings/index.js.map +1 -1
  116. package/build/components/provider/block-refs-provider.js +4 -1
  117. package/build/components/provider/block-refs-provider.js.map +1 -1
  118. package/build/components/rich-text/file-paste-handler.js +1 -1
  119. package/build/components/rich-text/file-paste-handler.js.map +1 -1
  120. package/build/components/rich-text/index.js +2 -1
  121. package/build/components/rich-text/index.js.map +1 -1
  122. package/build/components/rich-text/index.native.js +2 -1
  123. package/build/components/rich-text/index.native.js.map +1 -1
  124. package/build/components/rich-text/prevent-event-discovery.js +33 -0
  125. package/build/components/rich-text/prevent-event-discovery.js.map +1 -0
  126. package/build/components/rich-text/use-input-rules.js +3 -1
  127. package/build/components/rich-text/use-input-rules.js.map +1 -1
  128. package/build/components/rich-text/use-paste-handler.js +14 -5
  129. package/build/components/rich-text/use-paste-handler.js.map +1 -1
  130. package/build/components/rich-text/utils.js +2 -1
  131. package/build/components/rich-text/utils.js.map +1 -1
  132. package/build/components/selection-scroll-into-view/index.js +2 -1
  133. package/build/components/selection-scroll-into-view/index.js.map +1 -1
  134. package/build/components/use-display-block-controls/index.native.js +45 -0
  135. package/build/components/use-display-block-controls/index.native.js.map +1 -0
  136. package/build/components/use-on-block-drop/index.js +7 -3
  137. package/build/components/use-on-block-drop/index.js.map +1 -1
  138. package/build/components/writing-flow/use-multi-selection.js +3 -1
  139. package/build/components/writing-flow/use-multi-selection.js.map +1 -1
  140. package/build/hooks/border-color.js +63 -5
  141. package/build/hooks/border-color.js.map +1 -1
  142. package/build/hooks/border-radius.js +47 -0
  143. package/build/hooks/border-radius.js.map +1 -1
  144. package/build/hooks/border-style.js +41 -0
  145. package/build/hooks/border-style.js.map +1 -1
  146. package/build/hooks/border-width.js +70 -31
  147. package/build/hooks/border-width.js.map +1 -1
  148. package/build/hooks/border.js +81 -11
  149. package/build/hooks/border.js.map +1 -1
  150. package/build/hooks/color-panel.js +25 -16
  151. package/build/hooks/color-panel.js.map +1 -1
  152. package/build/hooks/color-panel.native.js +77 -0
  153. package/build/hooks/color-panel.native.js.map +1 -0
  154. package/build/hooks/color.js +179 -12
  155. package/build/hooks/color.js.map +1 -1
  156. package/build/hooks/font-size.js +14 -0
  157. package/build/hooks/font-size.js.map +1 -1
  158. package/build/hooks/index.native.js +2 -0
  159. package/build/hooks/index.native.js.map +1 -1
  160. package/build/hooks/layout.native.js +20 -0
  161. package/build/hooks/layout.native.js.map +1 -0
  162. package/build/hooks/letter-spacing.js +1 -1
  163. package/build/hooks/letter-spacing.js.map +1 -1
  164. package/build/hooks/typography.js +1 -1
  165. package/build/hooks/typography.js.map +1 -1
  166. package/build/hooks/typography.native.js +2 -4
  167. package/build/hooks/typography.native.js.map +1 -1
  168. package/build/hooks/utils.js +55 -0
  169. package/build/hooks/utils.js.map +1 -1
  170. package/build/store/actions.js +1 -2
  171. package/build/store/actions.js.map +1 -1
  172. package/build/store/defaults.js +5 -2
  173. package/build/store/defaults.js.map +1 -1
  174. package/build/store/defaults.native.js +2 -6
  175. package/build/store/defaults.native.js.map +1 -1
  176. package/build/store/selectors.js +10 -5
  177. package/build/store/selectors.js.map +1 -1
  178. package/build/utils/get-paste-event-data.js +1 -1
  179. package/build/utils/get-paste-event-data.js.map +1 -1
  180. package/build/utils/parse-css-unit-to-px.js +1 -1
  181. package/build/utils/parse-css-unit-to-px.js.map +1 -1
  182. package/build-module/components/block-caption/index.native.js +13 -3
  183. package/build-module/components/block-caption/index.native.js.map +1 -1
  184. package/build-module/components/block-edit/index.js +9 -0
  185. package/build-module/components/block-edit/index.js.map +1 -1
  186. package/build-module/components/block-inspector/index.js +14 -19
  187. package/build-module/components/block-inspector/index.js.map +1 -1
  188. package/build-module/components/block-list-appender/index.js +3 -10
  189. package/build-module/components/block-list-appender/index.js.map +1 -1
  190. package/build-module/components/block-media-update-progress/index.native.js +2 -1
  191. package/build-module/components/block-media-update-progress/index.native.js.map +1 -1
  192. package/build-module/components/block-preview/auto.js +10 -2
  193. package/build-module/components/block-preview/auto.js.map +1 -1
  194. package/build-module/components/block-settings/container.native.js +2 -1
  195. package/build-module/components/block-settings/container.native.js.map +1 -1
  196. package/build-module/components/block-styles/index.js +112 -133
  197. package/build-module/components/block-styles/index.js.map +1 -1
  198. package/build-module/components/block-styles/menu-items.js +50 -0
  199. package/build-module/components/block-styles/menu-items.js.map +1 -0
  200. package/build-module/components/block-styles/preview-panel.js +35 -0
  201. package/build-module/components/block-styles/preview-panel.js.map +1 -0
  202. package/build-module/components/block-styles/preview.native.js +2 -2
  203. package/build-module/components/block-styles/preview.native.js.map +1 -1
  204. package/build-module/components/block-styles/use-styles-for-block.js +107 -0
  205. package/build-module/components/block-styles/use-styles-for-block.js.map +1 -0
  206. package/build-module/components/block-styles/utils.js +34 -0
  207. package/build-module/components/block-styles/utils.js.map +1 -1
  208. package/build-module/components/block-switcher/block-styles-menu.js +3 -21
  209. package/build-module/components/block-switcher/block-styles-menu.js.map +1 -1
  210. package/build-module/components/block-tools/back-compat.js +2 -1
  211. package/build-module/components/block-tools/back-compat.js.map +1 -1
  212. package/build-module/components/block-tools/block-selection-button.js +5 -1
  213. package/build-module/components/block-tools/block-selection-button.js.map +1 -1
  214. package/build-module/components/block-tools/insertion-point.js +11 -1
  215. package/build-module/components/block-tools/insertion-point.js.map +1 -1
  216. package/build-module/components/block-types-list/index.native.js +2 -2
  217. package/build-module/components/block-types-list/index.native.js.map +1 -1
  218. package/build-module/components/button-block-appender/index.js +2 -1
  219. package/build-module/components/button-block-appender/index.js.map +1 -1
  220. package/build-module/components/colors-gradients/dropdown.js +1 -1
  221. package/build-module/components/colors-gradients/dropdown.js.map +1 -1
  222. package/build-module/components/colors-gradients/panel-color-gradient-settings.native.js +7 -4
  223. package/build-module/components/colors-gradients/panel-color-gradient-settings.native.js.map +1 -1
  224. package/build-module/components/colors-gradients/tools-panel-color-dropdown.js +75 -0
  225. package/build-module/components/colors-gradients/tools-panel-color-dropdown.js.map +1 -0
  226. package/build-module/components/contrast-checker/index.js +80 -45
  227. package/build-module/components/contrast-checker/index.js.map +1 -1
  228. package/build-module/components/contrast-checker/index.native.js +90 -0
  229. package/build-module/components/contrast-checker/index.native.js.map +1 -0
  230. package/build-module/components/default-block-appender/index.js +15 -18
  231. package/build-module/components/default-block-appender/index.js.map +1 -1
  232. package/build-module/components/default-style-picker/index.js +17 -3
  233. package/build-module/components/default-style-picker/index.js.map +1 -1
  234. package/build-module/components/iframe/index.js +4 -5
  235. package/build-module/components/iframe/index.js.map +1 -1
  236. package/build-module/components/index.js +2 -2
  237. package/build-module/components/index.js.map +1 -1
  238. package/build-module/components/index.native.js +2 -0
  239. package/build-module/components/index.native.js.map +1 -1
  240. package/build-module/components/inner-blocks/default-block-appender.js +2 -4
  241. package/build-module/components/inner-blocks/default-block-appender.js.map +1 -1
  242. package/build-module/components/inner-blocks/use-nested-settings-update.js +16 -14
  243. package/build-module/components/inner-blocks/use-nested-settings-update.js.map +1 -1
  244. package/build-module/components/inserter/index.js +61 -3
  245. package/build-module/components/inserter/index.js.map +1 -1
  246. package/build-module/components/inserter/index.native.js +2 -2
  247. package/build-module/components/inserter/index.native.js.map +1 -1
  248. package/build-module/components/inserter/library.js +5 -3
  249. package/build-module/components/inserter/library.js.map +1 -1
  250. package/build-module/components/inserter/menu.js +11 -4
  251. package/build-module/components/inserter/menu.js.map +1 -1
  252. package/build-module/components/inserter/search-items.js +3 -1
  253. package/build-module/components/inserter/search-items.js.map +1 -1
  254. package/build-module/components/inserter/tabs.native.js +7 -4
  255. package/build-module/components/inserter/tabs.native.js.map +1 -1
  256. package/build-module/components/inspector-controls/block-support-slot-container.js +2 -1
  257. package/build-module/components/inspector-controls/block-support-slot-container.js.map +1 -1
  258. package/build-module/components/inspector-controls/block-support-tools-panel.js +15 -44
  259. package/build-module/components/inspector-controls/block-support-tools-panel.js.map +1 -1
  260. package/build-module/components/inspector-controls/fill.native.js +3 -5
  261. package/build-module/components/inspector-controls/fill.native.js.map +1 -1
  262. package/build-module/components/inspector-controls/groups.js +4 -0
  263. package/build-module/components/inspector-controls/groups.js.map +1 -1
  264. package/build-module/components/inspector-controls/slot.js +1 -3
  265. package/build-module/components/inspector-controls/slot.js.map +1 -1
  266. package/build-module/components/letter-spacing-control/index.js +6 -6
  267. package/build-module/components/letter-spacing-control/index.js.map +1 -1
  268. package/build-module/components/line-height-control/index.native.js +3 -2
  269. package/build-module/components/line-height-control/index.native.js.map +1 -1
  270. package/build-module/components/link-control/link-preview.js +1 -1
  271. package/build-module/components/link-control/link-preview.js.map +1 -1
  272. package/build-module/components/link-control/search-item.js +11 -1
  273. package/build-module/components/link-control/search-item.js.map +1 -1
  274. package/build-module/components/link-control/search-results.js +2 -1
  275. package/build-module/components/link-control/search-results.js.map +1 -1
  276. package/build-module/components/link-control/use-search-handler.js +18 -5
  277. package/build-module/components/link-control/use-search-handler.js.map +1 -1
  278. package/build-module/components/list-view/block-contents.js +3 -1
  279. package/build-module/components/list-view/block-contents.js.map +1 -1
  280. package/build-module/components/list-view/block-select-button.js +25 -4
  281. package/build-module/components/list-view/block-select-button.js.map +1 -1
  282. package/build-module/components/list-view/block.js +8 -1
  283. package/build-module/components/list-view/block.js.map +1 -1
  284. package/build-module/components/media-placeholder/index.js +3 -10
  285. package/build-module/components/media-placeholder/index.js.map +1 -1
  286. package/build-module/components/media-replace-flow/index.js +32 -6
  287. package/build-module/components/media-replace-flow/index.js.map +1 -1
  288. package/build-module/components/media-replace-flow/index.native.js +4 -0
  289. package/build-module/components/media-replace-flow/index.native.js.map +1 -0
  290. package/build-module/components/media-upload-progress/index.native.js +2 -1
  291. package/build-module/components/media-upload-progress/index.native.js.map +1 -1
  292. package/build-module/components/panel-color-settings/index.js +7 -3
  293. package/build-module/components/panel-color-settings/index.js.map +1 -1
  294. package/build-module/components/provider/block-refs-provider.js +4 -1
  295. package/build-module/components/provider/block-refs-provider.js.map +1 -1
  296. package/build-module/components/rich-text/file-paste-handler.js +1 -1
  297. package/build-module/components/rich-text/file-paste-handler.js.map +1 -1
  298. package/build-module/components/rich-text/index.js +2 -1
  299. package/build-module/components/rich-text/index.js.map +1 -1
  300. package/build-module/components/rich-text/index.native.js +2 -1
  301. package/build-module/components/rich-text/index.native.js.map +1 -1
  302. package/build-module/components/rich-text/prevent-event-discovery.js +25 -0
  303. package/build-module/components/rich-text/prevent-event-discovery.js.map +1 -0
  304. package/build-module/components/rich-text/use-input-rules.js +2 -1
  305. package/build-module/components/rich-text/use-input-rules.js.map +1 -1
  306. package/build-module/components/rich-text/use-paste-handler.js +14 -5
  307. package/build-module/components/rich-text/use-paste-handler.js.map +1 -1
  308. package/build-module/components/rich-text/utils.js +2 -1
  309. package/build-module/components/rich-text/utils.js.map +1 -1
  310. package/build-module/components/selection-scroll-into-view/index.js +2 -1
  311. package/build-module/components/selection-scroll-into-view/index.js.map +1 -1
  312. package/build-module/components/use-display-block-controls/index.native.js +34 -0
  313. package/build-module/components/use-display-block-controls/index.native.js.map +1 -0
  314. package/build-module/components/use-on-block-drop/index.js +7 -3
  315. package/build-module/components/use-on-block-drop/index.js.map +1 -1
  316. package/build-module/components/writing-flow/use-multi-selection.js +3 -4
  317. package/build-module/components/writing-flow/use-multi-selection.js.map +1 -1
  318. package/build-module/hooks/border-color.js +61 -7
  319. package/build-module/hooks/border-color.js.map +1 -1
  320. package/build-module/hooks/border-radius.js +42 -0
  321. package/build-module/hooks/border-radius.js.map +1 -1
  322. package/build-module/hooks/border-style.js +36 -0
  323. package/build-module/hooks/border-style.js.map +1 -1
  324. package/build-module/hooks/border-width.js +66 -32
  325. package/build-module/hooks/border-width.js.map +1 -1
  326. package/build-module/hooks/border.js +80 -12
  327. package/build-module/hooks/border.js.map +1 -1
  328. package/build-module/hooks/color-panel.js +24 -14
  329. package/build-module/hooks/color-panel.js.map +1 -1
  330. package/build-module/hooks/color-panel.native.js +62 -0
  331. package/build-module/hooks/color-panel.native.js.map +1 -0
  332. package/build-module/hooks/color.js +177 -13
  333. package/build-module/hooks/color.js.map +1 -1
  334. package/build-module/hooks/font-size.js +12 -1
  335. package/build-module/hooks/font-size.js.map +1 -1
  336. package/build-module/hooks/index.native.js +1 -0
  337. package/build-module/hooks/index.native.js.map +1 -1
  338. package/build-module/hooks/layout.native.js +16 -0
  339. package/build-module/hooks/layout.native.js.map +1 -0
  340. package/build-module/hooks/letter-spacing.js +1 -1
  341. package/build-module/hooks/letter-spacing.js.map +1 -1
  342. package/build-module/hooks/typography.js +1 -1
  343. package/build-module/hooks/typography.js.map +1 -1
  344. package/build-module/hooks/typography.native.js +2 -4
  345. package/build-module/hooks/typography.native.js.map +1 -1
  346. package/build-module/hooks/utils.js +52 -1
  347. package/build-module/hooks/utils.js.map +1 -1
  348. package/build-module/store/actions.js +1 -2
  349. package/build-module/store/actions.js.map +1 -1
  350. package/build-module/store/defaults.js +5 -2
  351. package/build-module/store/defaults.js.map +1 -1
  352. package/build-module/store/defaults.native.js +2 -5
  353. package/build-module/store/defaults.native.js.map +1 -1
  354. package/build-module/store/selectors.js +10 -5
  355. package/build-module/store/selectors.js.map +1 -1
  356. package/build-module/utils/get-paste-event-data.js +1 -1
  357. package/build-module/utils/get-paste-event-data.js.map +1 -1
  358. package/build-module/utils/parse-css-unit-to-px.js +1 -1
  359. package/build-module/utils/parse-css-unit-to-px.js.map +1 -1
  360. package/build-style/style-rtl.css +256 -191
  361. package/build-style/style.css +256 -191
  362. package/package.json +30 -30
  363. package/src/components/block-caption/index.native.js +22 -4
  364. package/src/components/block-card/README.md +1 -1
  365. package/src/components/block-edit/index.js +8 -0
  366. package/src/components/block-edit/test/edit.native.js +10 -9
  367. package/src/components/block-inspector/index.js +18 -16
  368. package/src/components/block-list-appender/index.js +5 -21
  369. package/src/components/block-media-update-progress/index.native.js +1 -1
  370. package/src/components/block-media-update-progress/test/index.native.js +136 -93
  371. package/src/components/block-mover/test/__snapshots__/index.native.js.snap +108 -47
  372. package/src/components/block-mover/test/index.native.js +5 -5
  373. package/src/components/block-preview/README.md +14 -26
  374. package/src/components/block-preview/auto.js +7 -2
  375. package/src/components/block-preview/test/index.js +2 -0
  376. package/src/components/block-settings/container.native.js +1 -0
  377. package/src/components/block-styles/index.js +125 -145
  378. package/src/components/block-styles/menu-items.js +49 -0
  379. package/src/components/block-styles/preview-panel.js +36 -0
  380. package/src/components/block-styles/preview.native.js +5 -2
  381. package/src/components/block-styles/style.scss +59 -51
  382. package/src/components/block-styles/test/{index.js → utils.js} +60 -1
  383. package/src/components/block-styles/use-styles-for-block.js +99 -0
  384. package/src/components/block-styles/utils.js +39 -0
  385. package/src/components/block-switcher/block-styles-menu.js +3 -38
  386. package/src/components/block-tools/back-compat.js +1 -0
  387. package/src/components/block-tools/block-selection-button.js +7 -1
  388. package/src/components/block-tools/insertion-point.js +10 -1
  389. package/src/components/block-types-list/index.native.js +5 -2
  390. package/src/components/border-radius-control/style.scss +1 -1
  391. package/src/components/border-style-control/style.scss +0 -1
  392. package/src/components/button-block-appender/index.js +1 -0
  393. package/src/components/color-palette/test/__snapshots__/control.js.snap +9 -5
  394. package/src/components/colors-gradients/dropdown.js +48 -43
  395. package/src/components/colors-gradients/panel-color-gradient-settings.native.js +13 -2
  396. package/src/components/colors-gradients/style.scss +10 -5
  397. package/src/components/colors-gradients/tools-panel-color-dropdown.js +85 -0
  398. package/src/components/contrast-checker/README.md +3 -1
  399. package/src/components/contrast-checker/index.js +107 -64
  400. package/src/components/contrast-checker/index.native.js +113 -0
  401. package/src/components/contrast-checker/style.native.scss +26 -0
  402. package/src/components/contrast-checker/test/index.js +236 -2
  403. package/src/components/default-block-appender/index.js +17 -24
  404. package/src/components/default-block-appender/style.scss +4 -0
  405. package/src/components/default-block-appender/test/__snapshots__/index.js.snap +12 -24
  406. package/src/components/default-block-appender/test/index.js +4 -14
  407. package/src/components/default-style-picker/index.js +18 -6
  408. package/src/components/iframe/index.js +7 -3
  409. package/src/components/index.js +2 -2
  410. package/src/components/index.native.js +2 -0
  411. package/src/components/inner-blocks/README.md +2 -0
  412. package/src/components/inner-blocks/default-block-appender.js +2 -7
  413. package/src/components/inner-blocks/use-nested-settings-update.js +16 -14
  414. package/src/components/inserter/index.js +77 -5
  415. package/src/components/inserter/index.native.js +2 -2
  416. package/src/components/inserter/library.js +17 -12
  417. package/src/components/inserter/menu.js +31 -13
  418. package/src/components/inserter/search-items.js +3 -1
  419. package/src/components/inserter/tabs.native.js +5 -4
  420. package/src/components/inserter/test/block-types-tab.native.js +9 -10
  421. package/src/components/inserter/test/index.native.js +3 -7
  422. package/src/components/inserter/test/reusable-blocks-tab.native.js +8 -10
  423. package/src/components/inspector-controls/block-support-slot-container.js +3 -1
  424. package/src/components/inspector-controls/block-support-tools-panel.js +41 -58
  425. package/src/components/inspector-controls/fill.native.js +4 -3
  426. package/src/components/inspector-controls/groups.js +4 -0
  427. package/src/components/inspector-controls/slot.js +2 -7
  428. package/src/components/letter-spacing-control/index.js +6 -6
  429. package/src/components/line-height-control/index.native.js +2 -1
  430. package/src/components/link-control/README.md +1 -1
  431. package/src/components/link-control/link-preview.js +1 -1
  432. package/src/components/link-control/search-item.js +11 -2
  433. package/src/components/link-control/search-results.js +1 -0
  434. package/src/components/link-control/style.scss +5 -10
  435. package/src/components/link-control/test/index.js +4 -0
  436. package/src/components/link-control/use-search-handler.js +25 -4
  437. package/src/components/list-view/block-contents.js +2 -0
  438. package/src/components/list-view/block-select-button.js +22 -1
  439. package/src/components/list-view/block.js +11 -0
  440. package/src/components/media-placeholder/index.js +3 -10
  441. package/src/components/media-replace-flow/index.js +35 -5
  442. package/src/components/media-replace-flow/index.native.js +3 -0
  443. package/src/components/media-upload/test/index.native.js +28 -47
  444. package/src/components/media-upload-progress/index.native.js +1 -0
  445. package/src/components/media-upload-progress/test/index.native.js +60 -47
  446. package/src/components/panel-color-settings/index.js +8 -4
  447. package/src/components/provider/block-refs-provider.js +4 -1
  448. package/src/components/rich-text/file-paste-handler.js +3 -1
  449. package/src/components/rich-text/index.js +1 -0
  450. package/src/components/rich-text/index.native.js +1 -0
  451. package/src/components/rich-text/prevent-event-discovery.js +23 -0
  452. package/src/components/rich-text/use-input-rules.js +2 -1
  453. package/src/components/rich-text/use-paste-handler.js +16 -3
  454. package/src/components/rich-text/utils.js +1 -0
  455. package/src/components/selection-scroll-into-view/index.js +1 -0
  456. package/src/components/url-input/README.md +5 -0
  457. package/src/components/use-display-block-controls/index.native.js +38 -0
  458. package/src/components/use-on-block-drop/index.js +7 -3
  459. package/src/components/writing-flow/test/use-multi-selection.js +36 -0
  460. package/src/components/writing-flow/use-multi-selection.js +12 -9
  461. package/src/hooks/border-color.js +55 -3
  462. package/src/hooks/border-radius.js +32 -0
  463. package/src/hooks/border-style.js +26 -0
  464. package/src/hooks/border-width.js +56 -32
  465. package/src/hooks/border.js +115 -20
  466. package/src/hooks/border.scss +3 -17
  467. package/src/hooks/color-panel.js +25 -19
  468. package/src/hooks/color-panel.native.js +63 -0
  469. package/src/hooks/color.js +182 -12
  470. package/src/hooks/color.scss +85 -0
  471. package/src/hooks/font-size.js +29 -1
  472. package/src/hooks/index.native.js +1 -0
  473. package/src/hooks/layout.native.js +23 -0
  474. package/src/hooks/letter-spacing.js +1 -1
  475. package/src/hooks/typography.js +1 -1
  476. package/src/hooks/typography.native.js +1 -3
  477. package/src/hooks/utils.js +69 -1
  478. package/src/store/actions.js +1 -2
  479. package/src/store/defaults.js +2 -1
  480. package/src/store/defaults.native.js +2 -6
  481. package/src/store/selectors.js +10 -5
  482. package/src/style.scss +4 -3
  483. package/src/utils/get-paste-event-data.js +1 -1
  484. package/src/utils/parse-css-unit-to-px.js +1 -1
  485. package/src/utils/test/parse-css-unit-to-px.js +3 -0
  486. package/tsconfig.tsbuildinfo +1 -1
  487. package/build/components/preserve-scroll-in-reorder/index.js +0 -22
  488. package/build/components/preserve-scroll-in-reorder/index.js.map +0 -1
  489. package/build/components/use-canvas-click-redirect/index.js +0 -66
  490. package/build/components/use-canvas-click-redirect/index.js.map +0 -1
  491. package/build-module/components/preserve-scroll-in-reorder/index.js +0 -12
  492. package/build-module/components/preserve-scroll-in-reorder/index.js.map +0 -1
  493. package/build-module/components/use-canvas-click-redirect/index.js +0 -54
  494. package/build-module/components/use-canvas-click-redirect/index.js.map +0 -1
  495. package/src/components/preserve-scroll-in-reorder/index.js +0 -12
  496. package/src/components/use-canvas-click-redirect/index.js +0 -57
@@ -39,6 +39,8 @@ export function usePasteHandler(props) {
39
39
  propsRef.current = props;
40
40
  return useRefEffect(element => {
41
41
  function _onPaste(event) {
42
+ var _html;
43
+
42
44
  const {
43
45
  isSelected,
44
46
  disableFormats,
@@ -141,11 +143,18 @@ export function usePasteHandler(props) {
141
143
  text: plainText
142
144
  })));
143
145
  return;
144
- } // Only process file if no HTML is present.
145
- // Note: a pasted file may have the URL as plain text.
146
-
147
-
148
- if (files && files.length && !html) {
146
+ } // Process any attached files, unless we detect Microsoft Office as
147
+ // the source.
148
+ //
149
+ // When content is copied from Microsoft Office, an image of the
150
+ // content is rendered and attached to the clipboard along with the
151
+ // plain-text and HTML content. This artifact is a distraction from
152
+ // the relevant clipboard data, so we ignore it.
153
+ //
154
+ // Props https://github.com/pubpub/pubpub/commit/2f933277a15a263a1ab4bbd36b96d3a106544aec
155
+
156
+
157
+ if (files && files.length && !((_html = html) !== null && _html !== void 0 && _html.includes('xmlns:o="urn:schemas-microsoft-com:office:office'))) {
149
158
  const content = pasteHandler({
150
159
  HTML: filePasteHandler(files),
151
160
  mode: 'BLOCKS',
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/rich-text/use-paste-handler.js"],"names":["useRef","useRefEffect","getFilesFromDataTransfer","pasteHandler","isEmpty","insert","create","replace","__UNSTABLE_LINE_SEPARATOR","LINE_SEPARATOR","isURL","filePasteHandler","addActiveFormats","isShortcode","splitValue","adjustLines","value","isMultiline","RegExp","usePasteHandler","props","propsRef","current","element","_onPaste","event","isSelected","disableFormats","onChange","formatTypes","tagName","onReplace","onSplit","onSplitMiddle","__unstableEmbedURLOnPaste","multilineTag","preserveWhiteSpace","pastePlainText","preventDefault","clipboardData","plainText","html","getData","error1","error2","removeWindowsFragments","removeCharsetMetaTag","window","console","log","transformed","reduce","accumlator","__unstablePasteRule","files","isInternal","pastedMultilineTag","undefined","pastedValue","multilineWrapperTags","activeFormats","text","length","content","HTML","mode","pastedBlocks","trim","valueToInsert","addEventListener","removeEventListener","startReg","endReg","metaTag","startsWith","slice"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,MAAT,QAAuB,oBAAvB;AACA,SAASC,YAAT,QAA6B,oBAA7B;AACA,SAASC,wBAAT,QAAyC,gBAAzC;AACA,SAASC,YAAT,QAA6B,mBAA7B;AACA,SACCC,OADD,EAECC,MAFD,EAGCC,MAHD,EAICC,OAJD,EAKCC,yBAAyB,IAAIC,cAL9B,QAMO,sBANP;AAOA,SAASC,KAAT,QAAsB,gBAAtB;AAEA;AACA;AACA;;AACA,SAASC,gBAAT,QAAiC,sBAAjC;AACA,SAASC,gBAAT,EAA2BC,WAA3B,QAA8C,SAA9C;AACA,SAASC,UAAT,QAA2B,eAA3B;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,WAAT,CAAsBC,KAAtB,EAA6BC,WAA7B,EAA2C;AAC1C,MAAKA,WAAL,EAAmB;AAClB,WAAOV,OAAO,CAAES,KAAF,EAAS,MAAT,EAAiBP,cAAjB,CAAd;AACA;;AAED,SAAOF,OAAO,CAAES,KAAF,EAAS,IAAIE,MAAJ,CAAYT,cAAZ,EAA4B,GAA5B,CAAT,EAA4C,IAA5C,CAAd;AACA;;AAED,OAAO,SAASU,eAAT,CAA0BC,KAA1B,EAAkC;AACxC,QAAMC,QAAQ,GAAGrB,MAAM,CAAEoB,KAAF,CAAvB;AACAC,EAAAA,QAAQ,CAACC,OAAT,GAAmBF,KAAnB;AACA,SAAOnB,YAAY,CAAIsB,OAAF,IAAe;AACnC,aAAS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AA6B,OAA7B,EAAsC9C,QAAtC;AACA,KAFD;AAGA,GAzMkB,EAyMhB,EAzMgB,CAAnB;AA0MA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASqB,sBAAT,CAAiCJ,IAAjC,EAAwC;AACvC,QAAM8B,QAAQ,GAAG,yBAAjB;AACA,QAAMC,MAAM,GAAG,uBAAf;AAEA,SAAO/B,IAAI,CAAClC,OAAL,CAAcgE,QAAd,EAAwB,EAAxB,EAA6BhE,OAA7B,CAAsCiE,MAAtC,EAA8C,EAA9C,CAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAAS1B,oBAAT,CAA+BL,IAA/B,EAAsC;AACrC,QAAMgC,OAAO,GAAI,wBAAjB;;AAEA,MAAKhC,IAAI,CAACiC,UAAL,CAAiBD,OAAjB,CAAL,EAAkC;AACjC,WAAOhC,IAAI,CAACkC,KAAL,CAAYF,OAAO,CAACX,MAApB,CAAP;AACA;;AAED,SAAOrB,IAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRef } from '@wordpress/element';\nimport { useRefEffect } from '@wordpress/compose';\nimport { getFilesFromDataTransfer } from '@wordpress/dom';\nimport { pasteHandler } from '@wordpress/blocks';\nimport {\n\tisEmpty,\n\tinsert,\n\tcreate,\n\treplace,\n\t__UNSTABLE_LINE_SEPARATOR as LINE_SEPARATOR,\n} from '@wordpress/rich-text';\nimport { isURL } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { filePasteHandler } from './file-paste-handler';\nimport { addActiveFormats, isShortcode } from './utils';\nimport { splitValue } from './split-value';\n\n/** @typedef {import('@wordpress/rich-text').RichTextValue} RichTextValue */\n\n/**\n * Replaces line separators with line breaks if not multiline.\n * Replaces line breaks with line separators if multiline.\n *\n * @param {RichTextValue} value Value to adjust.\n * @param {boolean} isMultiline Whether to adjust to multiline or not.\n *\n * @return {RichTextValue} Adjusted value.\n */\nfunction adjustLines( value, isMultiline ) {\n\tif ( isMultiline ) {\n\t\treturn replace( value, /\\n+/g, LINE_SEPARATOR );\n\t}\n\n\treturn replace( value, new RegExp( LINE_SEPARATOR, 'g' ), '\\n' );\n}\n\nexport function usePasteHandler( props ) {\n\tconst propsRef = useRef( props );\n\tpropsRef.current = props;\n\treturn useRefEffect( ( element ) => {\n\t\tfunction _onPaste( event ) {\n\t\t\tconst {\n\t\t\t\tisSelected,\n\t\t\t\tdisableFormats,\n\t\t\t\tonChange,\n\t\t\t\tvalue,\n\t\t\t\tformatTypes,\n\t\t\t\ttagName,\n\t\t\t\tonReplace,\n\t\t\t\tonSplit,\n\t\t\t\tonSplitMiddle,\n\t\t\t\t__unstableEmbedURLOnPaste,\n\t\t\t\tmultilineTag,\n\t\t\t\tpreserveWhiteSpace,\n\t\t\t\tpastePlainText,\n\t\t\t} = propsRef.current;\n\n\t\t\tif ( ! isSelected ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst { clipboardData } = event;\n\n\t\t\tlet plainText = '';\n\t\t\tlet html = '';\n\n\t\t\t// IE11 only supports `Text` as an argument for `getData` and will\n\t\t\t// otherwise throw an invalid argument error, so we try the standard\n\t\t\t// arguments first, then fallback to `Text` if they fail.\n\t\t\ttry {\n\t\t\t\tplainText = clipboardData.getData( 'text/plain' );\n\t\t\t\thtml = clipboardData.getData( 'text/html' );\n\t\t\t} catch ( error1 ) {\n\t\t\t\ttry {\n\t\t\t\t\thtml = clipboardData.getData( 'Text' );\n\t\t\t\t} catch ( error2 ) {\n\t\t\t\t\t// Some browsers like UC Browser paste plain text by default and\n\t\t\t\t\t// don't support clipboardData at all, so allow default\n\t\t\t\t\t// behaviour.\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Remove Windows-specific metadata appended within copied HTML text.\n\t\t\thtml = removeWindowsFragments( html );\n\n\t\t\t// Strip meta tag.\n\t\t\thtml = removeCharsetMetaTag( html );\n\n\t\t\tevent.preventDefault();\n\n\t\t\t// Allows us to ask for this information when we get a report.\n\t\t\twindow.console.log( 'Received HTML:\\n\\n', html );\n\t\t\twindow.console.log( 'Received plain text:\\n\\n', plainText );\n\n\t\t\tif ( disableFormats ) {\n\t\t\t\tonChange( insert( value, plainText ) );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst transformed = formatTypes.reduce(\n\t\t\t\t( accumlator, { __unstablePasteRule } ) => {\n\t\t\t\t\t// Only allow one transform.\n\t\t\t\t\tif ( __unstablePasteRule && accumlator === value ) {\n\t\t\t\t\t\taccumlator = __unstablePasteRule( value, {\n\t\t\t\t\t\t\thtml,\n\t\t\t\t\t\t\tplainText,\n\t\t\t\t\t\t} );\n\t\t\t\t\t}\n\n\t\t\t\t\treturn accumlator;\n\t\t\t\t},\n\t\t\t\tvalue\n\t\t\t);\n\n\t\t\tif ( transformed !== value ) {\n\t\t\t\tonChange( transformed );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst files = [ ...getFilesFromDataTransfer( clipboardData ) ];\n\t\t\tconst isInternal = clipboardData.getData( 'rich-text' ) === 'true';\n\n\t\t\t// If the data comes from a rich text instance, we can directly use it\n\t\t\t// without filtering the data. The filters are only meant for externally\n\t\t\t// pasted content and remove inline styles.\n\t\t\tif ( isInternal ) {\n\t\t\t\tconst pastedMultilineTag =\n\t\t\t\t\tclipboardData.getData( 'rich-text-multi-line-tag' ) ||\n\t\t\t\t\tundefined;\n\t\t\t\tlet pastedValue = create( {\n\t\t\t\t\thtml,\n\t\t\t\t\tmultilineTag: pastedMultilineTag,\n\t\t\t\t\tmultilineWrapperTags:\n\t\t\t\t\t\tpastedMultilineTag === 'li'\n\t\t\t\t\t\t\t? [ 'ul', 'ol' ]\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\tpreserveWhiteSpace,\n\t\t\t\t} );\n\t\t\t\tpastedValue = adjustLines( pastedValue, !! multilineTag );\n\t\t\t\taddActiveFormats( pastedValue, value.activeFormats );\n\t\t\t\tonChange( insert( value, pastedValue ) );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( pastePlainText ) {\n\t\t\t\tonChange( insert( value, create( { text: plainText } ) ) );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Only process file if no HTML is present.\n\t\t\t// Note: a pasted file may have the URL as plain text.\n\t\t\tif ( files && files.length && ! html ) {\n\t\t\t\tconst content = pasteHandler( {\n\t\t\t\t\tHTML: filePasteHandler( files ),\n\t\t\t\t\tmode: 'BLOCKS',\n\t\t\t\t\ttagName,\n\t\t\t\t\tpreserveWhiteSpace,\n\t\t\t\t} );\n\n\t\t\t\t// Allows us to ask for this information when we get a report.\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\twindow.console.log( 'Received items:\\n\\n', files );\n\n\t\t\t\tif ( onReplace && isEmpty( value ) ) {\n\t\t\t\t\tonReplace( content );\n\t\t\t\t} else {\n\t\t\t\t\tsplitValue( {\n\t\t\t\t\t\tvalue,\n\t\t\t\t\t\tpastedBlocks: content,\n\t\t\t\t\t\tonReplace,\n\t\t\t\t\t\tonSplit,\n\t\t\t\t\t\tonSplitMiddle,\n\t\t\t\t\t\tmultilineTag,\n\t\t\t\t\t} );\n\t\t\t\t}\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet mode = onReplace && onSplit ? 'AUTO' : 'INLINE';\n\n\t\t\t// Force the blocks mode when the user is pasting\n\t\t\t// on a new line & the content resembles a shortcode.\n\t\t\t// Otherwise it's going to be detected as inline\n\t\t\t// and the shortcode won't be replaced.\n\t\t\tif (\n\t\t\t\tmode === 'AUTO' &&\n\t\t\t\tisEmpty( value ) &&\n\t\t\t\tisShortcode( plainText )\n\t\t\t) {\n\t\t\t\tmode = 'BLOCKS';\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\t__unstableEmbedURLOnPaste &&\n\t\t\t\tisEmpty( value ) &&\n\t\t\t\tisURL( plainText.trim() )\n\t\t\t) {\n\t\t\t\tmode = 'BLOCKS';\n\t\t\t}\n\n\t\t\tconst content = pasteHandler( {\n\t\t\t\tHTML: html,\n\t\t\t\tplainText,\n\t\t\t\tmode,\n\t\t\t\ttagName,\n\t\t\t\tpreserveWhiteSpace,\n\t\t\t} );\n\n\t\t\tif ( typeof content === 'string' ) {\n\t\t\t\tlet valueToInsert = create( { html: content } );\n\n\t\t\t\t// If the content should be multiline, we should process text\n\t\t\t\t// separated by a line break as separate lines.\n\t\t\t\tvalueToInsert = adjustLines( valueToInsert, !! multilineTag );\n\n\t\t\t\taddActiveFormats( valueToInsert, value.activeFormats );\n\t\t\t\tonChange( insert( value, valueToInsert ) );\n\t\t\t} else if ( content.length > 0 ) {\n\t\t\t\tif ( onReplace && isEmpty( value ) ) {\n\t\t\t\t\tonReplace( content, content.length - 1, -1 );\n\t\t\t\t} else {\n\t\t\t\t\tsplitValue( {\n\t\t\t\t\t\tvalue,\n\t\t\t\t\t\tpastedBlocks: content,\n\t\t\t\t\t\tonReplace,\n\t\t\t\t\t\tonSplit,\n\t\t\t\t\t\tonSplitMiddle,\n\t\t\t\t\t\tmultilineTag,\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\telement.addEventListener( 'paste', _onPaste );\n\t\treturn () => {\n\t\t\telement.removeEventListener( 'paste', _onPaste );\n\t\t};\n\t}, [] );\n}\n\n/**\n * Normalizes a given string of HTML to remove the Windows specific \"Fragment\" comments\n * and any preceeding and trailing whitespace.\n *\n * @param {string} html the html to be normalized\n * @return {string} the normalized html\n */\nfunction removeWindowsFragments( html ) {\n\tconst startReg = /.*<!--StartFragment-->/s;\n\tconst endReg = /<!--EndFragment-->.*/s;\n\n\treturn html.replace( startReg, '' ).replace( endReg, '' );\n}\n\n/**\n * Removes the charset meta tag inserted by Chromium.\n * See:\n * - https://github.com/WordPress/gutenberg/issues/33585\n * - https://bugs.chromium.org/p/chromium/issues/detail?id=1264616#c4\n *\n * @param {string} html the html to be stripped of the meta tag.\n * @return {string} the cleaned html\n */\nfunction removeCharsetMetaTag( html ) {\n\tconst metaTag = `<meta charset='utf-8'>`;\n\n\tif ( html.startsWith( metaTag ) ) {\n\t\treturn html.slice( metaTag.length );\n\t}\n\n\treturn html;\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/rich-text/use-paste-handler.js"],"names":["useRef","useRefEffect","getFilesFromDataTransfer","pasteHandler","isEmpty","insert","create","replace","__UNSTABLE_LINE_SEPARATOR","LINE_SEPARATOR","isURL","filePasteHandler","addActiveFormats","isShortcode","splitValue","adjustLines","value","isMultiline","RegExp","usePasteHandler","props","propsRef","current","element","_onPaste","event","isSelected","disableFormats","onChange","formatTypes","tagName","onReplace","onSplit","onSplitMiddle","__unstableEmbedURLOnPaste","multilineTag","preserveWhiteSpace","pastePlainText","preventDefault","clipboardData","plainText","html","getData","error1","error2","removeWindowsFragments","removeCharsetMetaTag","window","console","log","transformed","reduce","accumlator","__unstablePasteRule","files","isInternal","pastedMultilineTag","undefined","pastedValue","multilineWrapperTags","activeFormats","text","length","includes","content","HTML","mode","pastedBlocks","trim","valueToInsert","addEventListener","removeEventListener","startReg","endReg","metaTag","startsWith","slice"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,MAAT,QAAuB,oBAAvB;AACA,SAASC,YAAT,QAA6B,oBAA7B;AACA,SAASC,wBAAT,QAAyC,gBAAzC;AACA,SAASC,YAAT,QAA6B,mBAA7B;AACA,SACCC,OADD,EAECC,MAFD,EAGCC,MAHD,EAICC,OAJD,EAKCC,yBAAyB,IAAIC,cAL9B,QAMO,sBANP;AAOA,SAASC,KAAT,QAAsB,gBAAtB;AAEA;AACA;AACA;;AACA,SAASC,gBAAT,QAAiC,sBAAjC;AACA,SAASC,gBAAT,EAA2BC,WAA3B,QAA8C,SAA9C;AACA,SAASC,UAAT,QAA2B,eAA3B;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,WAAT,CAAsBC,KAAtB,EAA6BC,WAA7B,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C,YAAK/B,SAAS,IAAI3B,OAAO,CAAEY,KAAF,CAAzB,EAAqC;AACpCe,UAAAA,SAAS,CAAEiC,OAAF,EAAWA,OAAO,CAACF,MAAR,GAAiB,CAA5B,EAA+B,CAAC,CAAhC,CAAT;AACA,SAFD,MAEO;AACNhD,UAAAA,UAAU,CAAE;AACXE,YAAAA,KADW;AAEXmD,YAAAA,YAAY,EAAEH,OAFH;AAGXjC,YAAAA,SAHW;AAIXC,YAAAA,OAJW;AAKXC,YAAAA,aALW;AAMXE,YAAAA;AANW,WAAF,CAAV;AAQA;AACD;AACD;;AAEDZ,IAAAA,OAAO,CAAC+C,gBAAR,CAA0B,OAA1B,EAAmC9C,QAAnC;AACA,WAAO,MAAM;AACZD,MAAAA,OAAO,CAACgD,mBAAR,CAA6B,OAA7B,EAAsC/C,QAAtC;AACA,KAFD;AAGA,GAtNkB,EAsNhB,EAtNgB,CAAnB;AAuNA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASqB,sBAAT,CAAiCJ,IAAjC,EAAwC;AACvC,QAAM+B,QAAQ,GAAG,yBAAjB;AACA,QAAMC,MAAM,GAAG,uBAAf;AAEA,SAAOhC,IAAI,CAAClC,OAAL,CAAciE,QAAd,EAAwB,EAAxB,EAA6BjE,OAA7B,CAAsCkE,MAAtC,EAA8C,EAA9C,CAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAAS3B,oBAAT,CAA+BL,IAA/B,EAAsC;AACrC,QAAMiC,OAAO,GAAI,wBAAjB;;AAEA,MAAKjC,IAAI,CAACkC,UAAL,CAAiBD,OAAjB,CAAL,EAAkC;AACjC,WAAOjC,IAAI,CAACmC,KAAL,CAAYF,OAAO,CAACZ,MAApB,CAAP;AACA;;AAED,SAAOrB,IAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRef } from '@wordpress/element';\nimport { useRefEffect } from '@wordpress/compose';\nimport { getFilesFromDataTransfer } from '@wordpress/dom';\nimport { pasteHandler } from '@wordpress/blocks';\nimport {\n\tisEmpty,\n\tinsert,\n\tcreate,\n\treplace,\n\t__UNSTABLE_LINE_SEPARATOR as LINE_SEPARATOR,\n} from '@wordpress/rich-text';\nimport { isURL } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { filePasteHandler } from './file-paste-handler';\nimport { addActiveFormats, isShortcode } from './utils';\nimport { splitValue } from './split-value';\n\n/** @typedef {import('@wordpress/rich-text').RichTextValue} RichTextValue */\n\n/**\n * Replaces line separators with line breaks if not multiline.\n * Replaces line breaks with line separators if multiline.\n *\n * @param {RichTextValue} value Value to adjust.\n * @param {boolean} isMultiline Whether to adjust to multiline or not.\n *\n * @return {RichTextValue} Adjusted value.\n */\nfunction adjustLines( value, isMultiline ) {\n\tif ( isMultiline ) {\n\t\treturn replace( value, /\\n+/g, LINE_SEPARATOR );\n\t}\n\n\treturn replace( value, new RegExp( LINE_SEPARATOR, 'g' ), '\\n' );\n}\n\nexport function usePasteHandler( props ) {\n\tconst propsRef = useRef( props );\n\tpropsRef.current = props;\n\treturn useRefEffect( ( element ) => {\n\t\tfunction _onPaste( event ) {\n\t\t\tconst {\n\t\t\t\tisSelected,\n\t\t\t\tdisableFormats,\n\t\t\t\tonChange,\n\t\t\t\tvalue,\n\t\t\t\tformatTypes,\n\t\t\t\ttagName,\n\t\t\t\tonReplace,\n\t\t\t\tonSplit,\n\t\t\t\tonSplitMiddle,\n\t\t\t\t__unstableEmbedURLOnPaste,\n\t\t\t\tmultilineTag,\n\t\t\t\tpreserveWhiteSpace,\n\t\t\t\tpastePlainText,\n\t\t\t} = propsRef.current;\n\n\t\t\tif ( ! isSelected ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst { clipboardData } = event;\n\n\t\t\tlet plainText = '';\n\t\t\tlet html = '';\n\n\t\t\t// IE11 only supports `Text` as an argument for `getData` and will\n\t\t\t// otherwise throw an invalid argument error, so we try the standard\n\t\t\t// arguments first, then fallback to `Text` if they fail.\n\t\t\ttry {\n\t\t\t\tplainText = clipboardData.getData( 'text/plain' );\n\t\t\t\thtml = clipboardData.getData( 'text/html' );\n\t\t\t} catch ( error1 ) {\n\t\t\t\ttry {\n\t\t\t\t\thtml = clipboardData.getData( 'Text' );\n\t\t\t\t} catch ( error2 ) {\n\t\t\t\t\t// Some browsers like UC Browser paste plain text by default and\n\t\t\t\t\t// don't support clipboardData at all, so allow default\n\t\t\t\t\t// behaviour.\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Remove Windows-specific metadata appended within copied HTML text.\n\t\t\thtml = removeWindowsFragments( html );\n\n\t\t\t// Strip meta tag.\n\t\t\thtml = removeCharsetMetaTag( html );\n\n\t\t\tevent.preventDefault();\n\n\t\t\t// Allows us to ask for this information when we get a report.\n\t\t\twindow.console.log( 'Received HTML:\\n\\n', html );\n\t\t\twindow.console.log( 'Received plain text:\\n\\n', plainText );\n\n\t\t\tif ( disableFormats ) {\n\t\t\t\tonChange( insert( value, plainText ) );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst transformed = formatTypes.reduce(\n\t\t\t\t( accumlator, { __unstablePasteRule } ) => {\n\t\t\t\t\t// Only allow one transform.\n\t\t\t\t\tif ( __unstablePasteRule && accumlator === value ) {\n\t\t\t\t\t\taccumlator = __unstablePasteRule( value, {\n\t\t\t\t\t\t\thtml,\n\t\t\t\t\t\t\tplainText,\n\t\t\t\t\t\t} );\n\t\t\t\t\t}\n\n\t\t\t\t\treturn accumlator;\n\t\t\t\t},\n\t\t\t\tvalue\n\t\t\t);\n\n\t\t\tif ( transformed !== value ) {\n\t\t\t\tonChange( transformed );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst files = [ ...getFilesFromDataTransfer( clipboardData ) ];\n\t\t\tconst isInternal = clipboardData.getData( 'rich-text' ) === 'true';\n\n\t\t\t// If the data comes from a rich text instance, we can directly use it\n\t\t\t// without filtering the data. The filters are only meant for externally\n\t\t\t// pasted content and remove inline styles.\n\t\t\tif ( isInternal ) {\n\t\t\t\tconst pastedMultilineTag =\n\t\t\t\t\tclipboardData.getData( 'rich-text-multi-line-tag' ) ||\n\t\t\t\t\tundefined;\n\t\t\t\tlet pastedValue = create( {\n\t\t\t\t\thtml,\n\t\t\t\t\tmultilineTag: pastedMultilineTag,\n\t\t\t\t\tmultilineWrapperTags:\n\t\t\t\t\t\tpastedMultilineTag === 'li'\n\t\t\t\t\t\t\t? [ 'ul', 'ol' ]\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\tpreserveWhiteSpace,\n\t\t\t\t} );\n\t\t\t\tpastedValue = adjustLines( pastedValue, !! multilineTag );\n\t\t\t\taddActiveFormats( pastedValue, value.activeFormats );\n\t\t\t\tonChange( insert( value, pastedValue ) );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( pastePlainText ) {\n\t\t\t\tonChange( insert( value, create( { text: plainText } ) ) );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Process any attached files, unless we detect Microsoft Office as\n\t\t\t// the source.\n\t\t\t//\n\t\t\t// When content is copied from Microsoft Office, an image of the\n\t\t\t// content is rendered and attached to the clipboard along with the\n\t\t\t// plain-text and HTML content. This artifact is a distraction from\n\t\t\t// the relevant clipboard data, so we ignore it.\n\t\t\t//\n\t\t\t// Props https://github.com/pubpub/pubpub/commit/2f933277a15a263a1ab4bbd36b96d3a106544aec\n\t\t\tif (\n\t\t\t\tfiles &&\n\t\t\t\tfiles.length &&\n\t\t\t\t! html?.includes(\n\t\t\t\t\t'xmlns:o=\"urn:schemas-microsoft-com:office:office'\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tconst content = pasteHandler( {\n\t\t\t\t\tHTML: filePasteHandler( files ),\n\t\t\t\t\tmode: 'BLOCKS',\n\t\t\t\t\ttagName,\n\t\t\t\t\tpreserveWhiteSpace,\n\t\t\t\t} );\n\n\t\t\t\t// Allows us to ask for this information when we get a report.\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\twindow.console.log( 'Received items:\\n\\n', files );\n\n\t\t\t\tif ( onReplace && isEmpty( value ) ) {\n\t\t\t\t\tonReplace( content );\n\t\t\t\t} else {\n\t\t\t\t\tsplitValue( {\n\t\t\t\t\t\tvalue,\n\t\t\t\t\t\tpastedBlocks: content,\n\t\t\t\t\t\tonReplace,\n\t\t\t\t\t\tonSplit,\n\t\t\t\t\t\tonSplitMiddle,\n\t\t\t\t\t\tmultilineTag,\n\t\t\t\t\t} );\n\t\t\t\t}\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet mode = onReplace && onSplit ? 'AUTO' : 'INLINE';\n\n\t\t\t// Force the blocks mode when the user is pasting\n\t\t\t// on a new line & the content resembles a shortcode.\n\t\t\t// Otherwise it's going to be detected as inline\n\t\t\t// and the shortcode won't be replaced.\n\t\t\tif (\n\t\t\t\tmode === 'AUTO' &&\n\t\t\t\tisEmpty( value ) &&\n\t\t\t\tisShortcode( plainText )\n\t\t\t) {\n\t\t\t\tmode = 'BLOCKS';\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\t__unstableEmbedURLOnPaste &&\n\t\t\t\tisEmpty( value ) &&\n\t\t\t\tisURL( plainText.trim() )\n\t\t\t) {\n\t\t\t\tmode = 'BLOCKS';\n\t\t\t}\n\n\t\t\tconst content = pasteHandler( {\n\t\t\t\tHTML: html,\n\t\t\t\tplainText,\n\t\t\t\tmode,\n\t\t\t\ttagName,\n\t\t\t\tpreserveWhiteSpace,\n\t\t\t} );\n\n\t\t\tif ( typeof content === 'string' ) {\n\t\t\t\tlet valueToInsert = create( { html: content } );\n\n\t\t\t\t// If the content should be multiline, we should process text\n\t\t\t\t// separated by a line break as separate lines.\n\t\t\t\tvalueToInsert = adjustLines( valueToInsert, !! multilineTag );\n\n\t\t\t\taddActiveFormats( valueToInsert, value.activeFormats );\n\t\t\t\tonChange( insert( value, valueToInsert ) );\n\t\t\t} else if ( content.length > 0 ) {\n\t\t\t\tif ( onReplace && isEmpty( value ) ) {\n\t\t\t\t\tonReplace( content, content.length - 1, -1 );\n\t\t\t\t} else {\n\t\t\t\t\tsplitValue( {\n\t\t\t\t\t\tvalue,\n\t\t\t\t\t\tpastedBlocks: content,\n\t\t\t\t\t\tonReplace,\n\t\t\t\t\t\tonSplit,\n\t\t\t\t\t\tonSplitMiddle,\n\t\t\t\t\t\tmultilineTag,\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\telement.addEventListener( 'paste', _onPaste );\n\t\treturn () => {\n\t\t\telement.removeEventListener( 'paste', _onPaste );\n\t\t};\n\t}, [] );\n}\n\n/**\n * Normalizes a given string of HTML to remove the Windows specific \"Fragment\" comments\n * and any preceeding and trailing whitespace.\n *\n * @param {string} html the html to be normalized\n * @return {string} the normalized html\n */\nfunction removeWindowsFragments( html ) {\n\tconst startReg = /.*<!--StartFragment-->/s;\n\tconst endReg = /<!--EndFragment-->.*/s;\n\n\treturn html.replace( startReg, '' ).replace( endReg, '' );\n}\n\n/**\n * Removes the charset meta tag inserted by Chromium.\n * See:\n * - https://github.com/WordPress/gutenberg/issues/33585\n * - https://bugs.chromium.org/p/chromium/issues/detail?id=1264616#c4\n *\n * @param {string} html the html to be stripped of the meta tag.\n * @return {string} the cleaned html\n */\nfunction removeCharsetMetaTag( html ) {\n\tconst metaTag = `<meta charset='utf-8'>`;\n\n\tif ( html.startsWith( metaTag ) ) {\n\t\treturn html.slice( metaTag.length );\n\t}\n\n\treturn html;\n}\n"]}
@@ -52,7 +52,8 @@ export function getAllowedFormats(_ref) {
52
52
 
53
53
  deprecated('wp.blockEditor.RichText formattingControls prop', {
54
54
  since: '5.4',
55
- alternative: 'allowedFormats'
55
+ alternative: 'allowedFormats',
56
+ version: '6.2'
56
57
  });
57
58
  return formattingControls.map(name => `core/${name}`);
58
59
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/rich-text/utils.js"],"names":["regexp","deprecated","renderToString","createBlock","addActiveFormats","value","activeFormats","length","index","formats","getMultilineTag","multiline","getAllowedFormats","allowedFormats","formattingControls","disableFormats","EMPTY_ARRAY","since","alternative","map","name","isShortcode","text","test","createLinkInParagraph","url","onReplace","link","content"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,MAAT,QAAuB,sBAAvB;AACA,OAAOC,UAAP,MAAuB,uBAAvB;AACA,SAASC,cAAT,QAA+B,oBAA/B;AACA,SAASC,WAAT,QAA4B,mBAA5B;AAEA,OAAO,SAASC,gBAAT,CAA2BC,KAA3B,EAAkCC,aAAlC,EAAkD;AACxD,MAAKA,aAAL,aAAKA,aAAL,eAAKA,aAAa,CAAEC,MAApB,EAA6B;AAC5B,QAAIC,KAAK,GAAGH,KAAK,CAACI,OAAN,CAAcF,MAA1B;;AAEA,WAAQC,KAAK,EAAb,EAAkB;AACjBH,MAAAA,KAAK,CAACI,OAAN,CAAeD,KAAf,IAAyB,CACxB,GAAGF,aADqB,EAExB,IAAKD,KAAK,CAACI,OAAN,CAAeD,KAAf,KAA0B,EAA/B,CAFwB,CAAzB;AAIA;AACD;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASE,eAAT,CAA0BC,SAA1B,EAAsC;AAC5C,MAAKA,SAAS,KAAK,IAAd,IAAsBA,SAAS,KAAK,GAApC,IAA2CA,SAAS,KAAK,IAA9D,EAAqE;AACpE;AACA;;AAED,SAAOA,SAAS,KAAK,IAAd,GAAqB,GAArB,GAA2BA,SAAlC;AACA;AAED,OAAO,SAASC,iBAAT,OAIH;AAAA,MAJ+B;AAClCC,IAAAA,cADkC;AAElCC,IAAAA,kBAFkC;AAGlCC,IAAAA;AAHkC,GAI/B;;AACH,MAAKA,cAAL,EAAsB;AACrB,WAAOH,iBAAiB,CAACI,WAAzB;AACA;;AAED,MAAK,CAAEH,cAAF,IAAoB,CAAEC,kBAA3B,EAAgD;AAC/C;AACA;;AAED,MAAKD,cAAL,EAAsB;AACrB,WAAOA,cAAP;AACA;;AAEDZ,EAAAA,UAAU,CAAE,iDAAF,EAAqD;AAC9DgB,IAAAA,KAAK,EAAE,KADuD;AAE9DC,IAAAA,WAAW,EAAE;AAFiD,GAArD,CAAV;AAKA,SAAOJ,kBAAkB,CAACK,GAAnB,CAA0BC,IAAF,IAAa,QAAQA,IAAM,EAAnD,CAAP;AACA;AAEDR,iBAAiB,CAACI,WAAlB,GAAgC,EAAhC;AAEA,OAAO,MAAMK,WAAW,GAAKC,IAAF,IAAYtB,MAAM,CAAE,IAAF,CAAN,CAAeuB,IAAf,CAAqBD,IAArB,CAAhC;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASE,qBAAT,CAAgCC,GAAhC,EAAqCC,SAArC,EAAiD;AACvD,QAAMC,IAAI,GAAG;AAAG,IAAA,IAAI,EAAGF;AAAV,KAAkBA,GAAlB,CAAb;AACAC,EAAAA,SAAS,CACRvB,WAAW,CAAE,gBAAF,EAAoB;AAAEyB,IAAAA,OAAO,EAAE1B,cAAc,CAAEyB,IAAF;AAAzB,GAApB,CADH,CAAT;AAGA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { regexp } from '@wordpress/shortcode';\nimport deprecated from '@wordpress/deprecated';\nimport { renderToString } from '@wordpress/element';\nimport { createBlock } from '@wordpress/blocks';\n\nexport function addActiveFormats( value, activeFormats ) {\n\tif ( activeFormats?.length ) {\n\t\tlet index = value.formats.length;\n\n\t\twhile ( index-- ) {\n\t\t\tvalue.formats[ index ] = [\n\t\t\t\t...activeFormats,\n\t\t\t\t...( value.formats[ index ] || [] ),\n\t\t\t];\n\t\t}\n\t}\n}\n\n/**\n * Get the multiline tag based on the multiline prop.\n *\n * @param {?(string|boolean)} multiline The multiline prop.\n *\n * @return {?string} The multiline tag.\n */\nexport function getMultilineTag( multiline ) {\n\tif ( multiline !== true && multiline !== 'p' && multiline !== 'li' ) {\n\t\treturn;\n\t}\n\n\treturn multiline === true ? 'p' : multiline;\n}\n\nexport function getAllowedFormats( {\n\tallowedFormats,\n\tformattingControls,\n\tdisableFormats,\n} ) {\n\tif ( disableFormats ) {\n\t\treturn getAllowedFormats.EMPTY_ARRAY;\n\t}\n\n\tif ( ! allowedFormats && ! formattingControls ) {\n\t\treturn;\n\t}\n\n\tif ( allowedFormats ) {\n\t\treturn allowedFormats;\n\t}\n\n\tdeprecated( 'wp.blockEditor.RichText formattingControls prop', {\n\t\tsince: '5.4',\n\t\talternative: 'allowedFormats',\n\t} );\n\n\treturn formattingControls.map( ( name ) => `core/${ name }` );\n}\n\ngetAllowedFormats.EMPTY_ARRAY = [];\n\nexport const isShortcode = ( text ) => regexp( '.*' ).test( text );\n\n/**\n * Creates a link from pasted URL.\n * Creates a paragraph block containing a link to the URL, and calls `onReplace`.\n *\n * @param {string} url The URL that could not be embedded.\n * @param {Function} onReplace Function to call with the created fallback block.\n */\nexport function createLinkInParagraph( url, onReplace ) {\n\tconst link = <a href={ url }>{ url }</a>;\n\tonReplace(\n\t\tcreateBlock( 'core/paragraph', { content: renderToString( link ) } )\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/rich-text/utils.js"],"names":["regexp","deprecated","renderToString","createBlock","addActiveFormats","value","activeFormats","length","index","formats","getMultilineTag","multiline","getAllowedFormats","allowedFormats","formattingControls","disableFormats","EMPTY_ARRAY","since","alternative","version","map","name","isShortcode","text","test","createLinkInParagraph","url","onReplace","link","content"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,MAAT,QAAuB,sBAAvB;AACA,OAAOC,UAAP,MAAuB,uBAAvB;AACA,SAASC,cAAT,QAA+B,oBAA/B;AACA,SAASC,WAAT,QAA4B,mBAA5B;AAEA,OAAO,SAASC,gBAAT,CAA2BC,KAA3B,EAAkCC,aAAlC,EAAkD;AACxD,MAAKA,aAAL,aAAKA,aAAL,eAAKA,aAAa,CAAEC,MAApB,EAA6B;AAC5B,QAAIC,KAAK,GAAGH,KAAK,CAACI,OAAN,CAAcF,M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C,SAArC,EAAiD;AACvD,QAAMC,IAAI,GAAG;AAAG,IAAA,IAAI,EAAGF;AAAV,KAAkBA,GAAlB,CAAb;AACAC,EAAAA,SAAS,CACRxB,WAAW,CAAE,gBAAF,EAAoB;AAAE0B,IAAAA,OAAO,EAAE3B,cAAc,CAAE0B,IAAF;AAAzB,GAApB,CADH,CAAT;AAGA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { regexp } from '@wordpress/shortcode';\nimport deprecated from '@wordpress/deprecated';\nimport { renderToString } from '@wordpress/element';\nimport { createBlock } from '@wordpress/blocks';\n\nexport function addActiveFormats( value, activeFormats ) {\n\tif ( activeFormats?.length ) {\n\t\tlet index = value.formats.length;\n\n\t\twhile ( index-- ) {\n\t\t\tvalue.formats[ index ] = [\n\t\t\t\t...activeFormats,\n\t\t\t\t...( value.formats[ index ] || [] ),\n\t\t\t];\n\t\t}\n\t}\n}\n\n/**\n * Get the multiline tag based on the multiline prop.\n *\n * @param {?(string|boolean)} multiline The multiline prop.\n *\n * @return {?string} The multiline tag.\n */\nexport function getMultilineTag( multiline ) {\n\tif ( multiline !== true && multiline !== 'p' && multiline !== 'li' ) {\n\t\treturn;\n\t}\n\n\treturn multiline === true ? 'p' : multiline;\n}\n\nexport function getAllowedFormats( {\n\tallowedFormats,\n\tformattingControls,\n\tdisableFormats,\n} ) {\n\tif ( disableFormats ) {\n\t\treturn getAllowedFormats.EMPTY_ARRAY;\n\t}\n\n\tif ( ! allowedFormats && ! formattingControls ) {\n\t\treturn;\n\t}\n\n\tif ( allowedFormats ) {\n\t\treturn allowedFormats;\n\t}\n\n\tdeprecated( 'wp.blockEditor.RichText formattingControls prop', {\n\t\tsince: '5.4',\n\t\talternative: 'allowedFormats',\n\t\tversion: '6.2',\n\t} );\n\n\treturn formattingControls.map( ( name ) => `core/${ name }` );\n}\n\ngetAllowedFormats.EMPTY_ARRAY = [];\n\nexport const isShortcode = ( text ) => regexp( '.*' ).test( text );\n\n/**\n * Creates a link from pasted URL.\n * Creates a paragraph block containing a link to the URL, and calls `onReplace`.\n *\n * @param {string} url The URL that could not be embedded.\n * @param {Function} onReplace Function to call with the created fallback block.\n */\nexport function createLinkInParagraph( url, onReplace ) {\n\tconst link = <a href={ url }>{ url }</a>;\n\tonReplace(\n\t\tcreateBlock( 'core/paragraph', { content: renderToString( link ) } )\n\t);\n}\n"]}
@@ -11,7 +11,8 @@ import deprecated from '@wordpress/deprecated';
11
11
 
12
12
  export function MultiSelectScrollIntoView() {
13
13
  deprecated('wp.blockEditor.MultiSelectScrollIntoView', {
14
- hint: 'This behaviour is now built-in.'
14
+ hint: 'This behaviour is now built-in.',
15
+ since: '5.8'
15
16
  });
16
17
  return null;
17
18
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/selection-scroll-into-view/index.js"],"names":["deprecated","MultiSelectScrollIntoView","hint"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,uBAAvB;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,yBAAT,GAAqC;AAC3CD,EAAAA,UAAU,CAAE,0CAAF,EAA8C;AACvDE,IAAAA,IAAI,EAAE;AADiD,GAA9C,CAAV;AAGA,SAAO,IAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Scrolls the multi block selection end into view if not in view already. This\n * is important to do after selection by keyboard.\n *\n * @deprecated\n */\nexport function MultiSelectScrollIntoView() {\n\tdeprecated( 'wp.blockEditor.MultiSelectScrollIntoView', {\n\t\thint: 'This behaviour is now built-in.',\n\t} );\n\treturn null;\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/selection-scroll-into-view/index.js"],"names":["deprecated","MultiSelectScrollIntoView","hint","since"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,uBAAvB;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,yBAAT,GAAqC;AAC3CD,EAAAA,UAAU,CAAE,0CAAF,EAA8C;AACvDE,IAAAA,IAAI,EAAE,iCADiD;AAEvDC,IAAAA,KAAK,EAAE;AAFgD,GAA9C,CAAV;AAIA,SAAO,IAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Scrolls the multi block selection end into view if not in view already. This\n * is important to do after selection by keyboard.\n *\n * @deprecated\n */\nexport function MultiSelectScrollIntoView() {\n\tdeprecated( 'wp.blockEditor.MultiSelectScrollIntoView', {\n\t\thint: 'This behaviour is now built-in.',\n\t\tsince: '5.8',\n\t} );\n\treturn null;\n}\n"]}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { useSelect } from '@wordpress/data';
5
+ import { hasBlockSupport } from '@wordpress/blocks';
6
+ /**
7
+ * Internal dependencies
8
+ */
9
+
10
+ import { useBlockEditContext } from '../block-edit/context';
11
+ import { store as blockEditorStore } from '../../store';
12
+ export default function useDisplayBlockControls() {
13
+ const {
14
+ isSelected,
15
+ clientId,
16
+ name
17
+ } = useBlockEditContext();
18
+ return useSelect(select => {
19
+ const {
20
+ getBlockName,
21
+ getBlockRootClientId
22
+ } = select(blockEditorStore);
23
+ const parentId = getBlockRootClientId(clientId);
24
+ const parentBlockName = getBlockName(parentId);
25
+ const hideControls = hasBlockSupport(parentBlockName, '__experimentalHideChildBlockControls', false);
26
+
27
+ if (!hideControls && isSelected) {
28
+ return true;
29
+ }
30
+
31
+ return false;
32
+ }, [clientId, isSelected, name]);
33
+ }
34
+ //# sourceMappingURL=index.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/use-display-block-controls/index.native.js"],"names":["useSelect","hasBlockSupport","useBlockEditContext","store","blockEditorStore","useDisplayBlockControls","isSelected","clientId","name","select","getBlockName","getBlockRootClientId","parentId","parentBlockName","hideControls"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,iBAA1B;AACA,SAASC,eAAT,QAAgC,mBAAhC;AAEA;AACA;AACA;;AACA,SAASC,mBAAT,QAAoC,uBAApC;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AAEA,eAAe,SAASC,uBAAT,GAAmC;AACjD,QAAM;AAAEC,IAAAA,UAAF;AAAcC,IAAAA,QAAd;AAAwBC,IAAAA;AAAxB,MAAiCN,mBAAmB,EAA1D;AACA,SAAOF,SAAS,CACbS,MAAF,IAAc;AACb,UAAM;AAAEC,MAAAA,YAAF;AAAgBC,MAAAA;AAAhB,QAAyCF,MAAM,CACpDL,gBADoD,CAArD;AAIA,UAAMQ,QAAQ,GAAGD,oBAAoB,CAAEJ,QAAF,CAArC;AACA,UAAMM,eAAe,GAAGH,YAAY,CAAEE,QAAF,CAApC;AAEA,UAAME,YAAY,GAAGb,eAAe,CACnCY,eADmC,EAEnC,sCAFmC,EAGnC,KAHmC,CAApC;;AAMA,QAAK,CAAEC,YAAF,IAAkBR,UAAvB,EAAoC;AACnC,aAAO,IAAP;AACA;;AAED,WAAO,KAAP;AACA,GApBc,EAqBf,CAAEC,QAAF,EAAYD,UAAZ,EAAwBE,IAAxB,CArBe,CAAhB;AAuBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { hasBlockSupport } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { useBlockEditContext } from '../block-edit/context';\nimport { store as blockEditorStore } from '../../store';\n\nexport default function useDisplayBlockControls() {\n\tconst { isSelected, clientId, name } = useBlockEditContext();\n\treturn useSelect(\n\t\t( select ) => {\n\t\t\tconst { getBlockName, getBlockRootClientId } = select(\n\t\t\t\tblockEditorStore\n\t\t\t);\n\n\t\t\tconst parentId = getBlockRootClientId( clientId );\n\t\t\tconst parentBlockName = getBlockName( parentId );\n\n\t\t\tconst hideControls = hasBlockSupport(\n\t\t\t\tparentBlockName,\n\t\t\t\t'__experimentalHideChildBlockControls',\n\t\t\t\tfalse\n\t\t\t);\n\n\t\t\tif ( ! hideControls && isSelected ) {\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\treturn false;\n\t\t},\n\t\t[ clientId, isSelected, name ]\n\t);\n}\n"]}
@@ -174,11 +174,15 @@ export default function useOnBlockDrop(targetRootClientId, targetBlockIndex) {
174
174
  return event => {
175
175
  const files = getFilesFromDataTransfer(event.dataTransfer);
176
176
  const html = event.dataTransfer.getData('text/html');
177
+ /**
178
+ * From Windows Chrome 96, the `event.dataTransfer` returns both file object and HTML.
179
+ * The order of the checks is important to recognise the HTML drop.
180
+ */
177
181
 
178
- if (files.length) {
179
- _onFilesDrop(files);
180
- } else if (html) {
182
+ if (html) {
181
183
  _onHTMLDrop(html);
184
+ } else if (files.length) {
185
+ _onFilesDrop(files);
182
186
  } else {
183
187
  _onDrop(event);
184
188
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/use-on-block-drop/index.js"],"names":["cloneBlock","findTransform","getBlockTransforms","pasteHandler","useDispatch","useSelect","getFilesFromDataTransfer","store","blockEditorStore","parseDropEvent","event","result","srcRootClientId","srcClientIds","srcIndex","type","blocks","dataTransfer","Object","assign","JSON","parse","getData","err","onBlockDrop","targetRootClientId","targetBlockIndex","getBlockIndex","getClientIdsOfDescendants","moveBlocksToPosition","insertBlocks","clearSelectedBlock","sourceRootClientId","sourceClientIds","dropType","blocksToInsert","map","block","sourceBlockIndex","includes","some","id","isAtSameLevel","draggedBlockCount","length","insertIndex","onFilesDrop","hasUploadPermissions","updateBlockAttributes","canInsertBlockType","files","transformation","transform","blockName","isMatch","onHTMLDrop","HTML","mode","useOnBlockDrop","select","getSettings","mediaUpload","_onDrop","_onFilesDrop","_onHTMLDrop","html"],"mappings":"AAAA;AACA;AACA;AACA,SACCA,UADD,EAECC,aAFD,EAGCC,kBAHD,EAICC,YAJD,QAKO,mBALP;AAMA,SAASC,WAAT,EAAsBC,SAAtB,QAAuC,iBAAvC;AACA,SAASC,wBAA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CAC1BC,kBAD0B,EAE1BC,gBAF0B,EAG1BC,aAH0B,EAI1BC,yBAJ0B,EAK1BC,oBAL0B,EAM1BC,YAN0B,EAO1BC,kBAP0B,CAA3B;;AASA,QAAMgC,YAAY,GAAGjB,WAAW,CAC/BrB,kBAD+B,EAE/BC,gBAF+B,EAG/BqB,oBAH+B,EAI/BC,qBAJ+B,EAK/BC,kBAL+B,EAM/BnB,YAN+B,CAAhC;;AAQA,QAAMkC,WAAW,GAAGT,UAAU,CAC7B9B,kBAD6B,EAE7BC,gBAF6B,EAG7BI,YAH6B,CAA9B;;AAMA,SAASpB,KAAF,IAAa;AACnB,UAAMwC,KAAK,GAAG5C,wBAAwB,CAAEI,KAAK,CAACO,YAAR,CAAtC;AACA,UAAMgD,IAAI,GAAGvD,KAAK,CAACO,YAAN,CAAmBK,OAAnB,CAA4B,WAA5B,CAAb;;AAEA,QAAK4B,KAAK,CAACN,MAAX,EAAoB;AACnBmB,MAAAA,YAAY,CAAEb,KAAF,CAAZ;AACA,KAFD,MAEO,IAAKe,IAAL,EAAY;AAClBD,MAAAA,WAAW,CAAEC,IAAF,CAAX;AACA,KAFM,MAEA;AACNH,MAAAA,OAAO,CAAEpD,KAAF,CAAP;AACA;AACD,GAXD;AAYA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tcloneBlock,\n\tfindTransform,\n\tgetBlockTransforms,\n\tpasteHandler,\n} from '@wordpress/blocks';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { getFilesFromDataTransfer } from '@wordpress/dom';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\n\n/** @typedef {import('@wordpress/element').WPSyntheticEvent} WPSyntheticEvent */\n\n/**\n * Retrieve the data for a block drop event.\n *\n * @param {WPSyntheticEvent} event The drop event.\n *\n * @return {Object} An object with block drag and drop data.\n */\nexport function parseDropEvent( event ) {\n\tlet result = {\n\t\tsrcRootClientId: null,\n\t\tsrcClientIds: null,\n\t\tsrcIndex: null,\n\t\ttype: null,\n\t\tblocks: null,\n\t};\n\n\tif ( ! event.dataTransfer ) {\n\t\treturn result;\n\t}\n\n\ttry {\n\t\tresult = Object.assign(\n\t\t\tresult,\n\t\t\tJSON.parse( event.dataTransfer.getData( 'wp-blocks' ) )\n\t\t);\n\t} catch ( err ) {\n\t\treturn result;\n\t}\n\n\treturn result;\n}\n\n/**\n * A function that returns an event handler function for block drop events.\n *\n * @param {string} targetRootClientId The root client id where the block(s) will be inserted.\n * @param {number} targetBlockIndex The index where the block(s) will be inserted.\n * @param {Function} getBlockIndex A function that gets the index of a block.\n * @param {Function} getClientIdsOfDescendants A function that gets the client ids of descendant blocks.\n * @param {Function} moveBlocksToPosition A function that moves blocks.\n * @param {Function} insertBlocks A function that inserts blocks.\n * @param {Function} clearSelectedBlock A function that clears block selection.\n * @return {Function} The event handler for a block drop event.\n */\nexport function onBlockDrop(\n\ttargetRootClientId,\n\ttargetBlockIndex,\n\tgetBlockIndex,\n\tgetClientIdsOfDescendants,\n\tmoveBlocksToPosition,\n\tinsertBlocks,\n\tclearSelectedBlock\n) {\n\treturn ( event ) => {\n\t\tconst {\n\t\t\tsrcRootClientId: sourceRootClientId,\n\t\t\tsrcClientIds: sourceClientIds,\n\t\t\ttype: dropType,\n\t\t\tblocks,\n\t\t} = parseDropEvent( event );\n\n\t\t// If the user is inserting a block\n\t\tif ( dropType === 'inserter' ) {\n\t\t\tclearSelectedBlock();\n\t\t\tconst blocksToInsert = blocks.map( ( block ) =>\n\t\t\t\tcloneBlock( block )\n\t\t\t);\n\t\t\tinsertBlocks(\n\t\t\t\tblocksToInsert,\n\t\t\t\ttargetBlockIndex,\n\t\t\t\ttargetRootClientId,\n\t\t\t\ttrue,\n\t\t\t\tnull\n\t\t\t);\n\t\t}\n\n\t\t// If the user is moving a block\n\t\tif ( dropType === 'block' ) {\n\t\t\tconst sourceBlockIndex = getBlockIndex( sourceClientIds[ 0 ] );\n\n\t\t\t// If the user is dropping to the same position, return early.\n\t\t\tif (\n\t\t\t\tsourceRootClientId === targetRootClientId &&\n\t\t\t\tsourceBlockIndex === targetBlockIndex\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// If the user is attempting to drop a block within its own\n\t\t\t// nested blocks, return early as this would create infinite\n\t\t\t// recursion.\n\t\t\tif (\n\t\t\t\tsourceClientIds.includes( targetRootClientId ) ||\n\t\t\t\tgetClientIdsOfDescendants( sourceClientIds ).some(\n\t\t\t\t\t( id ) => id === targetRootClientId\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst isAtSameLevel = sourceRootClientId === targetRootClientId;\n\t\t\tconst draggedBlockCount = sourceClientIds.length;\n\n\t\t\t// If the block is kept at the same level and moved downwards,\n\t\t\t// subtract to take into account that the blocks being dragged\n\t\t\t// were removed from the block list above the insertion point.\n\t\t\tconst insertIndex =\n\t\t\t\tisAtSameLevel && sourceBlockIndex < targetBlockIndex\n\t\t\t\t\t? targetBlockIndex - draggedBlockCount\n\t\t\t\t\t: targetBlockIndex;\n\n\t\t\tmoveBlocksToPosition(\n\t\t\t\tsourceClientIds,\n\t\t\t\tsourceRootClientId,\n\t\t\t\ttargetRootClientId,\n\t\t\t\tinsertIndex\n\t\t\t);\n\t\t}\n\t};\n}\n\n/**\n * A function that returns an event handler function for block-related file drop events.\n *\n * @param {string} targetRootClientId The root client id where the block(s) will be inserted.\n * @param {number} targetBlockIndex The index where the block(s) will be inserted.\n * @param {boolean} hasUploadPermissions Whether the user has upload permissions.\n * @param {Function} updateBlockAttributes A function that updates a block's attributes.\n * @param {Function} canInsertBlockType A function that returns checks whether a block type can be inserted.\n * @param {Function} insertBlocks A function that inserts blocks.\n *\n * @return {Function} The event handler for a block-related file drop event.\n */\nexport function onFilesDrop(\n\ttargetRootClientId,\n\ttargetBlockIndex,\n\thasUploadPermissions,\n\tupdateBlockAttributes,\n\tcanInsertBlockType,\n\tinsertBlocks\n) {\n\treturn ( files ) => {\n\t\tif ( ! hasUploadPermissions ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst transformation = findTransform(\n\t\t\tgetBlockTransforms( 'from' ),\n\t\t\t( transform ) =>\n\t\t\t\ttransform.type === 'files' &&\n\t\t\t\tcanInsertBlockType( transform.blockName, targetRootClientId ) &&\n\t\t\t\ttransform.isMatch( files )\n\t\t);\n\n\t\tif ( transformation ) {\n\t\t\tconst blocks = transformation.transform(\n\t\t\t\tfiles,\n\t\t\t\tupdateBlockAttributes\n\t\t\t);\n\t\t\tinsertBlocks( blocks, targetBlockIndex, targetRootClientId );\n\t\t}\n\t};\n}\n\n/**\n * A function that returns an event handler function for block-related HTML drop events.\n *\n * @param {string} targetRootClientId The root client id where the block(s) will be inserted.\n * @param {number} targetBlockIndex The index where the block(s) will be inserted.\n * @param {Function} insertBlocks A function that inserts blocks.\n *\n * @return {Function} The event handler for a block-related HTML drop event.\n */\nexport function onHTMLDrop(\n\ttargetRootClientId,\n\ttargetBlockIndex,\n\tinsertBlocks\n) {\n\treturn ( HTML ) => {\n\t\tconst blocks = pasteHandler( { HTML, mode: 'BLOCKS' } );\n\n\t\tif ( blocks.length ) {\n\t\t\tinsertBlocks( blocks, targetBlockIndex, targetRootClientId );\n\t\t}\n\t};\n}\n\n/**\n * A React hook for handling block drop events.\n *\n * @param {string} targetRootClientId The root client id where the block(s) will be inserted.\n * @param {number} targetBlockIndex The index where the block(s) will be inserted.\n *\n * @return {Object} An object that contains the event handlers `onDrop`, `onFilesDrop` and `onHTMLDrop`.\n */\nexport default function useOnBlockDrop( targetRootClientId, targetBlockIndex ) {\n\tconst hasUploadPermissions = useSelect(\n\t\t( select ) => select( blockEditorStore ).getSettings().mediaUpload,\n\t\t[]\n\t);\n\tconst {\n\t\tcanInsertBlockType,\n\t\tgetBlockIndex,\n\t\tgetClientIdsOfDescendants,\n\t} = useSelect( blockEditorStore );\n\tconst {\n\t\tinsertBlocks,\n\t\tmoveBlocksToPosition,\n\t\tupdateBlockAttributes,\n\t\tclearSelectedBlock,\n\t} = useDispatch( blockEditorStore );\n\n\tconst _onDrop = onBlockDrop(\n\t\ttargetRootClientId,\n\t\ttargetBlockIndex,\n\t\tgetBlockIndex,\n\t\tgetClientIdsOfDescendants,\n\t\tmoveBlocksToPosition,\n\t\tinsertBlocks,\n\t\tclearSelectedBlock\n\t);\n\tconst _onFilesDrop = onFilesDrop(\n\t\ttargetRootClientId,\n\t\ttargetBlockIndex,\n\t\thasUploadPermissions,\n\t\tupdateBlockAttributes,\n\t\tcanInsertBlockType,\n\t\tinsertBlocks\n\t);\n\tconst _onHTMLDrop = onHTMLDrop(\n\t\ttargetRootClientId,\n\t\ttargetBlockIndex,\n\t\tinsertBlocks\n\t);\n\n\treturn ( event ) => {\n\t\tconst files = getFilesFromDataTransfer( event.dataTransfer );\n\t\tconst html = event.dataTransfer.getData( 'text/html' );\n\n\t\tif ( files.length ) {\n\t\t\t_onFilesDrop( files );\n\t\t} else if ( html ) {\n\t\t\t_onHTMLDrop( html );\n\t\t} else {\n\t\t\t_onDrop( event );\n\t\t}\n\t};\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/use-on-block-drop/index.js"],"names":["cloneBlock","findTransform","getBlockTransforms","pasteHandler","useDispatch","useSelect","getFilesFromDataTransfer","store","blockEditorStore","parseDropEvent","event","result","srcRootClientId","srcClientIds","srcIndex","type","blocks","dataTransfer","Object","assign","JSON","parse","getData","err","onBlockDrop","targetRootClientId","targetBlockIndex","getBlockIndex","getClientIdsOfDescendants","moveBlocksToPosition","insertBlocks","clearSelectedBlock","sourceRootClientId","sourceClientIds","dropType","blocksToInsert","map","block","sourceBlockIndex","includes","some","id","isAtSameLevel","draggedBlockCount","length","insertIndex","onFilesDrop","hasUploadPermissions","updateBlockAttributes","canInsertBlockType","files","transformation","transform","blockName","isMatch","onHTMLDrop","HTML","mode","useOnBlockDrop","select","getSettings","mediaUpload","_onDrop","_onFilesDrop","_onHTMLDrop","html"],"mappings":"AAAA;AACA;AACA;AACA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IAAAA,oBAFK;AAGLmB,IAAAA,qBAHK;AAILjB,IAAAA;AAJK,MAKF3B,WAAW,CAAEI,gBAAF,CALf;;AAOA,QAAMsD,OAAO,GAAGtC,WAAW,CAC1BC,kBAD0B,EAE1BC,gBAF0B,EAG1BC,aAH0B,EAI1BC,yBAJ0B,EAK1BC,oBAL0B,EAM1BC,YAN0B,EAO1BC,kBAP0B,CAA3B;;AASA,QAAMgC,YAAY,GAAGjB,WAAW,CAC/BrB,kBAD+B,EAE/BC,gBAF+B,EAG/BqB,oBAH+B,EAI/BC,qBAJ+B,EAK/BC,kBAL+B,EAM/BnB,YAN+B,CAAhC;;AAQA,QAAMkC,WAAW,GAAGT,UAAU,CAC7B9B,kBAD6B,EAE7BC,gBAF6B,EAG7BI,YAH6B,CAA9B;;AAMA,SAASpB,KAAF,IAAa;AACnB,UAAMwC,KAAK,GAAG5C,wBAAwB,CAAEI,KAAK,CAACO,YAAR,CAAtC;AACA,UAAMgD,IAAI,GAAGvD,KAAK,CAACO,YAAN,CAAmBK,OAAnB,CAA4B,WAA5B,CAAb;AAEA;AACF;AACA;AACA;;AACE,QAAK2C,IAAL,EAAY;AACXD,MAAAA,WAAW,CAAEC,IAAF,CAAX;AACA,KAFD,MAEO,IAAKf,KAAK,CAACN,MAAX,EAAoB;AAC1BmB,MAAAA,YAAY,CAAEb,KAAF,CAAZ;AACA,KAFM,MAEA;AACNY,MAAAA,OAAO,CAAEpD,KAAF,CAAP;AACA;AACD,GAfD;AAgBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tcloneBlock,\n\tfindTransform,\n\tgetBlockTransforms,\n\tpasteHandler,\n} from '@wordpress/blocks';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { getFilesFromDataTransfer } from '@wordpress/dom';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\n\n/** @typedef {import('@wordpress/element').WPSyntheticEvent} WPSyntheticEvent */\n\n/**\n * Retrieve the data for a block drop event.\n *\n * @param {WPSyntheticEvent} event The drop event.\n *\n * @return {Object} An object with block drag and drop data.\n */\nexport function parseDropEvent( event ) {\n\tlet result = {\n\t\tsrcRootClientId: null,\n\t\tsrcClientIds: null,\n\t\tsrcIndex: null,\n\t\ttype: null,\n\t\tblocks: null,\n\t};\n\n\tif ( ! event.dataTransfer ) {\n\t\treturn result;\n\t}\n\n\ttry {\n\t\tresult = Object.assign(\n\t\t\tresult,\n\t\t\tJSON.parse( event.dataTransfer.getData( 'wp-blocks' ) )\n\t\t);\n\t} catch ( err ) {\n\t\treturn result;\n\t}\n\n\treturn result;\n}\n\n/**\n * A function that returns an event handler function for block drop events.\n *\n * @param {string} targetRootClientId The root client id where the block(s) will be inserted.\n * @param {number} targetBlockIndex The index where the block(s) will be inserted.\n * @param {Function} getBlockIndex A function that gets the index of a block.\n * @param {Function} getClientIdsOfDescendants A function that gets the client ids of descendant blocks.\n * @param {Function} moveBlocksToPosition A function that moves blocks.\n * @param {Function} insertBlocks A function that inserts blocks.\n * @param {Function} clearSelectedBlock A function that clears block selection.\n * @return {Function} The event handler for a block drop event.\n */\nexport function onBlockDrop(\n\ttargetRootClientId,\n\ttargetBlockIndex,\n\tgetBlockIndex,\n\tgetClientIdsOfDescendants,\n\tmoveBlocksToPosition,\n\tinsertBlocks,\n\tclearSelectedBlock\n) {\n\treturn ( event ) => {\n\t\tconst {\n\t\t\tsrcRootClientId: sourceRootClientId,\n\t\t\tsrcClientIds: sourceClientIds,\n\t\t\ttype: dropType,\n\t\t\tblocks,\n\t\t} = parseDropEvent( event );\n\n\t\t// If the user is inserting a block\n\t\tif ( dropType === 'inserter' ) {\n\t\t\tclearSelectedBlock();\n\t\t\tconst blocksToInsert = blocks.map( ( block ) =>\n\t\t\t\tcloneBlock( block )\n\t\t\t);\n\t\t\tinsertBlocks(\n\t\t\t\tblocksToInsert,\n\t\t\t\ttargetBlockIndex,\n\t\t\t\ttargetRootClientId,\n\t\t\t\ttrue,\n\t\t\t\tnull\n\t\t\t);\n\t\t}\n\n\t\t// If the user is moving a block\n\t\tif ( dropType === 'block' ) {\n\t\t\tconst sourceBlockIndex = getBlockIndex( sourceClientIds[ 0 ] );\n\n\t\t\t// If the user is dropping to the same position, return early.\n\t\t\tif (\n\t\t\t\tsourceRootClientId === targetRootClientId &&\n\t\t\t\tsourceBlockIndex === targetBlockIndex\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// If the user is attempting to drop a block within its own\n\t\t\t// nested blocks, return early as this would create infinite\n\t\t\t// recursion.\n\t\t\tif (\n\t\t\t\tsourceClientIds.includes( targetRootClientId ) ||\n\t\t\t\tgetClientIdsOfDescendants( sourceClientIds ).some(\n\t\t\t\t\t( id ) => id === targetRootClientId\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst isAtSameLevel = sourceRootClientId === targetRootClientId;\n\t\t\tconst draggedBlockCount = sourceClientIds.length;\n\n\t\t\t// If the block is kept at the same level and moved downwards,\n\t\t\t// subtract to take into account that the blocks being dragged\n\t\t\t// were removed from the block list above the insertion point.\n\t\t\tconst insertIndex =\n\t\t\t\tisAtSameLevel && sourceBlockIndex < targetBlockIndex\n\t\t\t\t\t? targetBlockIndex - draggedBlockCount\n\t\t\t\t\t: targetBlockIndex;\n\n\t\t\tmoveBlocksToPosition(\n\t\t\t\tsourceClientIds,\n\t\t\t\tsourceRootClientId,\n\t\t\t\ttargetRootClientId,\n\t\t\t\tinsertIndex\n\t\t\t);\n\t\t}\n\t};\n}\n\n/**\n * A function that returns an event handler function for block-related file drop events.\n *\n * @param {string} targetRootClientId The root client id where the block(s) will be inserted.\n * @param {number} targetBlockIndex The index where the block(s) will be inserted.\n * @param {boolean} hasUploadPermissions Whether the user has upload permissions.\n * @param {Function} updateBlockAttributes A function that updates a block's attributes.\n * @param {Function} canInsertBlockType A function that returns checks whether a block type can be inserted.\n * @param {Function} insertBlocks A function that inserts blocks.\n *\n * @return {Function} The event handler for a block-related file drop event.\n */\nexport function onFilesDrop(\n\ttargetRootClientId,\n\ttargetBlockIndex,\n\thasUploadPermissions,\n\tupdateBlockAttributes,\n\tcanInsertBlockType,\n\tinsertBlocks\n) {\n\treturn ( files ) => {\n\t\tif ( ! hasUploadPermissions ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst transformation = findTransform(\n\t\t\tgetBlockTransforms( 'from' ),\n\t\t\t( transform ) =>\n\t\t\t\ttransform.type === 'files' &&\n\t\t\t\tcanInsertBlockType( transform.blockName, targetRootClientId ) &&\n\t\t\t\ttransform.isMatch( files )\n\t\t);\n\n\t\tif ( transformation ) {\n\t\t\tconst blocks = transformation.transform(\n\t\t\t\tfiles,\n\t\t\t\tupdateBlockAttributes\n\t\t\t);\n\t\t\tinsertBlocks( blocks, targetBlockIndex, targetRootClientId );\n\t\t}\n\t};\n}\n\n/**\n * A function that returns an event handler function for block-related HTML drop events.\n *\n * @param {string} targetRootClientId The root client id where the block(s) will be inserted.\n * @param {number} targetBlockIndex The index where the block(s) will be inserted.\n * @param {Function} insertBlocks A function that inserts blocks.\n *\n * @return {Function} The event handler for a block-related HTML drop event.\n */\nexport function onHTMLDrop(\n\ttargetRootClientId,\n\ttargetBlockIndex,\n\tinsertBlocks\n) {\n\treturn ( HTML ) => {\n\t\tconst blocks = pasteHandler( { HTML, mode: 'BLOCKS' } );\n\n\t\tif ( blocks.length ) {\n\t\t\tinsertBlocks( blocks, targetBlockIndex, targetRootClientId );\n\t\t}\n\t};\n}\n\n/**\n * A React hook for handling block drop events.\n *\n * @param {string} targetRootClientId The root client id where the block(s) will be inserted.\n * @param {number} targetBlockIndex The index where the block(s) will be inserted.\n *\n * @return {Object} An object that contains the event handlers `onDrop`, `onFilesDrop` and `onHTMLDrop`.\n */\nexport default function useOnBlockDrop( targetRootClientId, targetBlockIndex ) {\n\tconst hasUploadPermissions = useSelect(\n\t\t( select ) => select( blockEditorStore ).getSettings().mediaUpload,\n\t\t[]\n\t);\n\tconst {\n\t\tcanInsertBlockType,\n\t\tgetBlockIndex,\n\t\tgetClientIdsOfDescendants,\n\t} = useSelect( blockEditorStore );\n\tconst {\n\t\tinsertBlocks,\n\t\tmoveBlocksToPosition,\n\t\tupdateBlockAttributes,\n\t\tclearSelectedBlock,\n\t} = useDispatch( blockEditorStore );\n\n\tconst _onDrop = onBlockDrop(\n\t\ttargetRootClientId,\n\t\ttargetBlockIndex,\n\t\tgetBlockIndex,\n\t\tgetClientIdsOfDescendants,\n\t\tmoveBlocksToPosition,\n\t\tinsertBlocks,\n\t\tclearSelectedBlock\n\t);\n\tconst _onFilesDrop = onFilesDrop(\n\t\ttargetRootClientId,\n\t\ttargetBlockIndex,\n\t\thasUploadPermissions,\n\t\tupdateBlockAttributes,\n\t\tcanInsertBlockType,\n\t\tinsertBlocks\n\t);\n\tconst _onHTMLDrop = onHTMLDrop(\n\t\ttargetRootClientId,\n\t\ttargetBlockIndex,\n\t\tinsertBlocks\n\t);\n\n\treturn ( event ) => {\n\t\tconst files = getFilesFromDataTransfer( event.dataTransfer );\n\t\tconst html = event.dataTransfer.getData( 'text/html' );\n\n\t\t/**\n\t\t * From Windows Chrome 96, the `event.dataTransfer` returns both file object and HTML.\n\t\t * The order of the checks is important to recognise the HTML drop.\n\t\t */\n\t\tif ( html ) {\n\t\t\t_onHTMLDrop( html );\n\t\t} else if ( files.length ) {\n\t\t\t_onFilesDrop( files );\n\t\t} else {\n\t\t\t_onDrop( event );\n\t\t}\n\t};\n}\n"]}
@@ -14,9 +14,9 @@ import { useSelect } from '@wordpress/data';
14
14
 
15
15
  import { store as blockEditorStore } from '../../store';
16
16
  import { __unstableUseBlockRef as useBlockRef } from '../block-list/use-block-props/use-block-refs';
17
-
18
- function toggleRichText(container, toggle) {
19
- Array.from(container.querySelectorAll('.rich-text')).forEach(node => {
17
+ export function toggleRichText(container, toggle) {
18
+ Array.from(container.querySelectorAll( // Exclude the Post Title from multi-select disable.
19
+ '.rich-text:not( .editor-post-title__input )')).forEach(node => {
20
20
  if (toggle) {
21
21
  node.setAttribute('contenteditable', true);
22
22
  } else {
@@ -32,7 +32,6 @@ function toggleRichText(container, toggle) {
32
32
  * @param {string} type 'start' or 'end'.
33
33
  */
34
34
 
35
-
36
35
  function getDeepestNode(node, type) {
37
36
  const child = type === 'start' ? 'firstChild' : 'lastChild';
38
37
  const sibling = type === 'start' ? 'nextSibling' : 'previousSibling';
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/writing-flow/use-multi-selection.js"],"names":["first","last","useRefEffect","useSelect","store","blockEditorStore","__unstableUseBlockRef","useBlockRef","toggleRichText","container","toggle","Array","from","querySelectorAll","forEach","node","setAttribute","removeAttribute","getDeepestNode","type","child","sibling","nodeType","TEXT_NODE","test","data","selector","select","isMultiSelecting","getMultiSelectedBlockClientIds","hasMultiSelection","getSelectedBlockClientId","multiSelectedBlockClientIds","selectedBlockClientId","useMultiSelection","selectedRef","startRef","endRef","ownerDocument","defaultView","selection","getSelection","rangeCount","isCollapsed","blockNode","current","startContainer","endContainer","getRangeAt","contains","removeAllRanges","length","focus","range","createRange","startNode","endNode","setStartBefore","setEndAfter","addRange"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,KAAT,EAAgBC,IAAhB,QAA4B,QAA5B;AAEA;AACA;AACA;;AACA,SAASC,YAAT,QAA6B,oBAA7B;AACA,SAASC,SAAT,QAA0B,iBAA1B;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AACA,SAASC,qBAAqB,IAAIC,WAAlC,QAAqD,8CAArD;;AAEA,SAASC,cAAT,CAAyBC,SAAzB,EAAoCC,MAApC,EAA6C;AAC5CC,EAAAA,KAAK,CAACC,IAAN,CAAYH,SAAS,CAACI,gBAAV,CAA4B,YAA5B,CAAZ,EAAyDC,OAAzD,CACGC,IAAF,IAAY;AACX,QAAKL,MAAL,EAAc;AACbK,MAAAA,IAAI,CAACC,YAAL,CAAmB,iBAAnB,EAAsC,IAAtC;AACA,K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Z,EAAlB;AACA,UAAMY,KAAK,GAAGf,aAAa,CAACgB,WAAd,EAAd,CA/CW,CAiDX;AACA;AACA;;AACA,UAAMC,SAAS,GAAGrC,cAAc,CAAEkB,QAAQ,CAACS,OAAX,EAAoB,OAApB,CAAhC;AACA,UAAMW,OAAO,GAAGtC,cAAc,CAAEmB,MAAM,CAACQ,OAAT,EAAkB,KAAlB,CAA9B,CArDW,CAuDX;AACA;AACA;;AACArC,IAAAA,cAAc,CAAEO,IAAF,EAAQ,KAAR,CAAd;AAEAsC,IAAAA,KAAK,CAACI,cAAN,CAAsBF,SAAtB;AACAF,IAAAA,KAAK,CAACK,WAAN,CAAmBF,OAAnB;AAEAhB,IAAAA,SAAS,CAACU,eAAV;AACAV,IAAAA,SAAS,CAACmB,QAAV,CAAoBN,KAApB;AACA,GAlEiB,EAmElB,CACCvB,iBADD,EAECF,gBAFD,EAGCI,2BAHD,EAICC,qBAJD,CAnEkB,CAAnB;AA0EA","sourcesContent":["/**\n * External dependencies\n */\nimport { first, last } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useRefEffect } from '@wordpress/compose';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { __unstableUseBlockRef as useBlockRef } from '../block-list/use-block-props/use-block-refs';\n\nfunction toggleRichText( container, toggle ) {\n\tArray.from( container.querySelectorAll( '.rich-text' ) ).forEach(\n\t\t( node ) => {\n\t\t\tif ( toggle ) {\n\t\t\t\tnode.setAttribute( 'contenteditable', true );\n\t\t\t} else {\n\t\t\t\tnode.removeAttribute( 'contenteditable' );\n\t\t\t}\n\t\t}\n\t);\n}\n\n/**\n * Returns for the deepest node at the start or end of a container node. Ignores\n * any text nodes that only contain HTML formatting whitespace.\n *\n * @param {Element} node Container to search.\n * @param {string} type 'start' or 'end'.\n */\nfunction getDeepestNode( node, type ) {\n\tconst child = type === 'start' ? 'firstChild' : 'lastChild';\n\tconst sibling = type === 'start' ? 'nextSibling' : 'previousSibling';\n\n\twhile ( node[ child ] ) {\n\t\tnode = node[ child ];\n\n\t\twhile (\n\t\t\tnode.nodeType === node.TEXT_NODE &&\n\t\t\t/^[ \\t\\n]*$/.test( node.data ) &&\n\t\t\tnode[ sibling ]\n\t\t) {\n\t\t\tnode = node[ sibling ];\n\t\t}\n\t}\n\n\treturn node;\n}\n\nfunction selector( select ) {\n\tconst {\n\t\tisMultiSelecting,\n\t\tgetMultiSelectedBlockClientIds,\n\t\thasMultiSelection,\n\t\tgetSelectedBlockClientId,\n\t} = select( blockEditorStore );\n\n\treturn {\n\t\tisMultiSelecting: isMultiSelecting(),\n\t\tmultiSelectedBlockClientIds: getMultiSelectedBlockClientIds(),\n\t\thasMultiSelection: hasMultiSelection(),\n\t\tselectedBlockClientId: getSelectedBlockClientId(),\n\t};\n}\n\nexport default function useMultiSelection() {\n\tconst {\n\t\tisMultiSelecting,\n\t\tmultiSelectedBlockClientIds,\n\t\thasMultiSelection,\n\t\tselectedBlockClientId,\n\t} = useSelect( selector, [] );\n\tconst selectedRef = useBlockRef( selectedBlockClientId );\n\t// These must be in the right DOM order.\n\tconst startRef = useBlockRef( first( multiSelectedBlockClientIds ) );\n\tconst endRef = useBlockRef( last( multiSelectedBlockClientIds ) );\n\n\t/**\n\t * When the component updates, and there is multi selection, we need to\n\t * select the entire block contents.\n\t */\n\treturn useRefEffect(\n\t\t( node ) => {\n\t\t\tconst { ownerDocument } = node;\n\t\t\tconst { defaultView } = ownerDocument;\n\n\t\t\tif ( ! hasMultiSelection || isMultiSelecting ) {\n\t\t\t\tif ( ! selectedBlockClientId || isMultiSelecting ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst selection = defaultView.getSelection();\n\n\t\t\t\tif ( selection.rangeCount && ! selection.isCollapsed ) {\n\t\t\t\t\tconst blockNode = selectedRef.current;\n\t\t\t\t\tconst {\n\t\t\t\t\t\tstartContainer,\n\t\t\t\t\t\tendContainer,\n\t\t\t\t\t} = selection.getRangeAt( 0 );\n\n\t\t\t\t\tif (\n\t\t\t\t\t\t!! blockNode &&\n\t\t\t\t\t\t( ! blockNode.contains( startContainer ) ||\n\t\t\t\t\t\t\t! blockNode.contains( endContainer ) )\n\t\t\t\t\t) {\n\t\t\t\t\t\tselection.removeAllRanges();\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst { length } = multiSelectedBlockClientIds;\n\n\t\t\tif ( length < 2 ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// The block refs might not be immediately available\n\t\t\t// when dragging blocks into another block.\n\t\t\tif ( ! startRef.current || ! endRef.current ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// For some browsers, like Safari, it is important that focus happens\n\t\t\t// BEFORE selection.\n\t\t\tnode.focus();\n\n\t\t\tconst selection = defaultView.getSelection();\n\t\t\tconst range = ownerDocument.createRange();\n\n\t\t\t// These must be in the right DOM order.\n\t\t\t// The most stable way to select the whole block contents is to start\n\t\t\t// and end at the deepest points.\n\t\t\tconst startNode = getDeepestNode( startRef.current, 'start' );\n\t\t\tconst endNode = getDeepestNode( endRef.current, 'end' );\n\n\t\t\t// While rich text will be disabled with a delay when there is a multi\n\t\t\t// selection, we must do it immediately because it's not possible to set\n\t\t\t// selection across editable hosts.\n\t\t\ttoggleRichText( node, false );\n\n\t\t\trange.setStartBefore( startNode );\n\t\t\trange.setEndAfter( endNode );\n\n\t\t\tselection.removeAllRanges();\n\t\t\tselection.addRange( range );\n\t\t},\n\t\t[\n\t\t\thasMultiSelection,\n\t\t\tisMultiSelecting,\n\t\t\tmultiSelectedBlockClientIds,\n\t\t\tselectedBlockClientId,\n\t\t]\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/writing-flow/use-multi-selection.js"],"names":["first","last","useRefEffect","useSelect","store","blockEditorStore","__unstableUseBlockRef","useBlockRef","toggleRichText","container","toggle","Array","from","querySelectorAll","forEach","node","setAttribute","removeAttribute","getDeepestNode","type","child","sibling","nodeType","TEXT_NODE","test","data","selector","select","isMultiSelecting","getMultiSelectedBlockClientIds","hasMultiSelection","getSelectedBlockClientId","multiSelectedBlockClientIds","selectedBlockClientId","useMultiSelection","selectedRef","startRef","endRef","ownerDocument","defaultView","selection","getSelection","rangeCount","isCollapsed","blockNode","current","startContainer","endContainer","getRangeAt","contains","removeAllRanges","length","focus","range","createRange","startNode","endNode","setStartBefore","setEndAfter","addRange"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,KAAT,EAAgBC,IAAhB,QAA4B,QAA5B;AAEA;AACA;AACA;;AACA,SAASC,YAAT,QAA6B,oBAA7B;AACA,SAASC,SAAT,QAA0B,iBAA1B;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AACA,SAASC,qBAAqB,IAAIC,WAAlC,QAAqD,8CAArD;AAEA,OAAO,SAASC,cAAT,CAAyBC,SAAzB,EAAoCC,MAApC,EAA6C;AACnDC,EAAAA,KAAK,CAACC,IAAN,CACCH,SAAS,CAACI,gBAAV,EACC;AACA,+CAFD,CADD,EAKEC,OALF,CAKaC,IAAF,IAAY;AACtB,QAAKL,MAAL,EAAc;AACbK,MAAAA,IAAI,CAACC,YAAL,CAAmB,iBAAnB,EAAsC,IAAtC;AACA,KAFD,MAEO;AACND,MAAAA,IAAI,CAACE,eAAL,CAAsB,iBAAtB;AACA;AACD,GAXD;AAYA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,cAAT,CAAyBH,IAAzB,EAA+BI,IAA/B,EAAsC;AACrC,QAAMC,KAAK,GAAGD,IAAI,KAAK,OAAT,GAAmB,YAAnB,GAAkC,WAAhD;AACA,QAAME,OAAO,GAAGF,IAAI,KAAK,OAAT,GAAmB,aAAnB,GAAmC,iBAAnD;;AAEA,SAAQJ,IAAI,CAAEK,KAAF,CAAZ,EAAwB;AACvBL,IAAAA,IAAI,GAAGA,IAAI,C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,WAAN,CAAmBF,OAAnB;AAEAhB,IAAAA,SAAS,CAACU,eAAV;AACAV,IAAAA,SAAS,CAACmB,QAAV,CAAoBN,KAApB;AACA,GAlEiB,EAmElB,CACCvB,iBADD,EAECF,gBAFD,EAGCI,2BAHD,EAICC,qBAJD,CAnEkB,CAAnB;AA0EA","sourcesContent":["/**\n * External dependencies\n */\nimport { first, last } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useRefEffect } from '@wordpress/compose';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { __unstableUseBlockRef as useBlockRef } from '../block-list/use-block-props/use-block-refs';\n\nexport function toggleRichText( container, toggle ) {\n\tArray.from(\n\t\tcontainer.querySelectorAll(\n\t\t\t// Exclude the Post Title from multi-select disable.\n\t\t\t'.rich-text:not( .editor-post-title__input )'\n\t\t)\n\t).forEach( ( node ) => {\n\t\tif ( toggle ) {\n\t\t\tnode.setAttribute( 'contenteditable', true );\n\t\t} else {\n\t\t\tnode.removeAttribute( 'contenteditable' );\n\t\t}\n\t} );\n}\n\n/**\n * Returns for the deepest node at the start or end of a container node. Ignores\n * any text nodes that only contain HTML formatting whitespace.\n *\n * @param {Element} node Container to search.\n * @param {string} type 'start' or 'end'.\n */\nfunction getDeepestNode( node, type ) {\n\tconst child = type === 'start' ? 'firstChild' : 'lastChild';\n\tconst sibling = type === 'start' ? 'nextSibling' : 'previousSibling';\n\n\twhile ( node[ child ] ) {\n\t\tnode = node[ child ];\n\n\t\twhile (\n\t\t\tnode.nodeType === node.TEXT_NODE &&\n\t\t\t/^[ \\t\\n]*$/.test( node.data ) &&\n\t\t\tnode[ sibling ]\n\t\t) {\n\t\t\tnode = node[ sibling ];\n\t\t}\n\t}\n\n\treturn node;\n}\n\nfunction selector( select ) {\n\tconst {\n\t\tisMultiSelecting,\n\t\tgetMultiSelectedBlockClientIds,\n\t\thasMultiSelection,\n\t\tgetSelectedBlockClientId,\n\t} = select( blockEditorStore );\n\n\treturn {\n\t\tisMultiSelecting: isMultiSelecting(),\n\t\tmultiSelectedBlockClientIds: getMultiSelectedBlockClientIds(),\n\t\thasMultiSelection: hasMultiSelection(),\n\t\tselectedBlockClientId: getSelectedBlockClientId(),\n\t};\n}\n\nexport default function useMultiSelection() {\n\tconst {\n\t\tisMultiSelecting,\n\t\tmultiSelectedBlockClientIds,\n\t\thasMultiSelection,\n\t\tselectedBlockClientId,\n\t} = useSelect( selector, [] );\n\tconst selectedRef = useBlockRef( selectedBlockClientId );\n\t// These must be in the right DOM order.\n\tconst startRef = useBlockRef( first( multiSelectedBlockClientIds ) );\n\tconst endRef = useBlockRef( last( multiSelectedBlockClientIds ) );\n\n\t/**\n\t * When the component updates, and there is multi selection, we need to\n\t * select the entire block contents.\n\t */\n\treturn useRefEffect(\n\t\t( node ) => {\n\t\t\tconst { ownerDocument } = node;\n\t\t\tconst { defaultView } = ownerDocument;\n\n\t\t\tif ( ! hasMultiSelection || isMultiSelecting ) {\n\t\t\t\tif ( ! selectedBlockClientId || isMultiSelecting ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst selection = defaultView.getSelection();\n\n\t\t\t\tif ( selection.rangeCount && ! selection.isCollapsed ) {\n\t\t\t\t\tconst blockNode = selectedRef.current;\n\t\t\t\t\tconst {\n\t\t\t\t\t\tstartContainer,\n\t\t\t\t\t\tendContainer,\n\t\t\t\t\t} = selection.getRangeAt( 0 );\n\n\t\t\t\t\tif (\n\t\t\t\t\t\t!! blockNode &&\n\t\t\t\t\t\t( ! blockNode.contains( startContainer ) ||\n\t\t\t\t\t\t\t! blockNode.contains( endContainer ) )\n\t\t\t\t\t) {\n\t\t\t\t\t\tselection.removeAllRanges();\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst { length } = multiSelectedBlockClientIds;\n\n\t\t\tif ( length < 2 ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// The block refs might not be immediately available\n\t\t\t// when dragging blocks into another block.\n\t\t\tif ( ! startRef.current || ! endRef.current ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// For some browsers, like Safari, it is important that focus happens\n\t\t\t// BEFORE selection.\n\t\t\tnode.focus();\n\n\t\t\tconst selection = defaultView.getSelection();\n\t\t\tconst range = ownerDocument.createRange();\n\n\t\t\t// These must be in the right DOM order.\n\t\t\t// The most stable way to select the whole block contents is to start\n\t\t\t// and end at the deepest points.\n\t\t\tconst startNode = getDeepestNode( startRef.current, 'start' );\n\t\t\tconst endNode = getDeepestNode( endRef.current, 'end' );\n\n\t\t\t// While rich text will be disabled with a delay when there is a multi\n\t\t\t// selection, we must do it immediately because it's not possible to set\n\t\t\t// selection across editable hosts.\n\t\t\ttoggleRichText( node, false );\n\n\t\t\trange.setStartBefore( startNode );\n\t\t\trange.setEndAfter( endNode );\n\n\t\t\tselection.removeAllRanges();\n\t\t\tselection.addRange( range );\n\t\t},\n\t\t[\n\t\t\thasMultiSelection,\n\t\t\tisMultiSelecting,\n\t\t\tmultiSelectedBlockClientIds,\n\t\t\tselectedBlockClientId,\n\t\t]\n\t);\n}\n"]}
@@ -12,7 +12,7 @@ import classnames from 'classnames';
12
12
  import { addFilter } from '@wordpress/hooks';
13
13
  import { __ } from '@wordpress/i18n';
14
14
  import { createHigherOrderComponent } from '@wordpress/compose';
15
- import { useState } from '@wordpress/element';
15
+ import { useEffect, useState } from '@wordpress/element';
16
16
  /**
17
17
  * Internal dependencies
18
18
  */
@@ -21,7 +21,7 @@ import ColorGradientSettingsDropdown from '../components/colors-gradients/dropdo
21
21
  import useMultipleOriginColorsAndGradients from '../components/colors-gradients/use-multiple-origin-colors-and-gradients';
22
22
  import { getColorClassName, getColorObjectByColorValue, getColorObjectByAttributeValues } from '../components/colors';
23
23
  import useSetting from '../components/use-setting';
24
- import { hasBorderSupport, shouldSkipSerialization } from './border';
24
+ import { hasBorderSupport, removeBorderAttribute, shouldSkipSerialization } from './border';
25
25
  import { cleanEmptyObject } from './utils'; // Defining empty array here instead of inline avoids unnecessary re-renders of
26
26
  // color control.
27
27
 
@@ -50,11 +50,23 @@ export function BorderColorEdit(props) {
50
50
  } = props;
51
51
  const colorGradientSettings = useMultipleOriginColorsAndGradients();
52
52
  const availableColors = colorGradientSettings.colors.reduce((colors, origin) => colors.concat(origin.colors), []);
53
+ const {
54
+ color: customBorderColor
55
+ } = (style === null || style === void 0 ? void 0 : style.border) || {};
53
56
  const [colorValue, setColorValue] = useState(() => {
54
- var _getColorObjectByAttr, _style$border;
57
+ var _getColorObjectByAttr;
55
58
 
56
- return (_getColorObjectByAttr = getColorObjectByAttributeValues(availableColors, borderColor, style === null || style === void 0 ? void 0 : (_style$border = style.border) === null || _style$border === void 0 ? void 0 : _style$border.color)) === null || _getColorObjectByAttr === void 0 ? void 0 : _getColorObjectByAttr.color;
57
- });
59
+ return (_getColorObjectByAttr = getColorObjectByAttributeValues(availableColors, borderColor, customBorderColor)) === null || _getColorObjectByAttr === void 0 ? void 0 : _getColorObjectByAttr.color;
60
+ }); // Detect changes in the color attributes and update the colorValue to keep the
61
+ // UI in sync. This is necessary for situations when border controls interact with
62
+ // each other: eg, setting the border width to zero causes the color and style
63
+ // selections to be cleared.
64
+
65
+ useEffect(() => {
66
+ var _getColorObjectByAttr2;
67
+
68
+ setColorValue((_getColorObjectByAttr2 = getColorObjectByAttributeValues(availableColors, borderColor, customBorderColor)) === null || _getColorObjectByAttr2 === void 0 ? void 0 : _getColorObjectByAttr2.color);
69
+ }, [borderColor, customBorderColor, availableColors]);
58
70
 
59
71
  const onChangeColor = value => {
60
72
  setColorValue(value);
@@ -87,6 +99,48 @@ export function BorderColorEdit(props) {
87
99
  enableAlpha: true
88
100
  }, colorGradientSettings));
89
101
  }
102
+ /**
103
+ * Checks if there is a current value in the border color block support
104
+ * attributes.
105
+ *
106
+ * @param {Object} props Block props.
107
+ * @return {boolean} Whether or not the block has a border color value set.
108
+ */
109
+
110
+ export function hasBorderColorValue(props) {
111
+ var _style$border;
112
+
113
+ const {
114
+ attributes: {
115
+ borderColor,
116
+ style
117
+ }
118
+ } = props;
119
+ return !!borderColor || !!(style !== null && style !== void 0 && (_style$border = style.border) !== null && _style$border !== void 0 && _style$border.color);
120
+ }
121
+ /**
122
+ * Resets the border color block support attributes. This can be used when
123
+ * disabling the border color support controls for a block via a progressive
124
+ * discovery panel.
125
+ *
126
+ * @param {Object} props Block props.
127
+ * @param {Object} props.attributes Block's attributes.
128
+ * @param {Object} props.setAttributes Function to set block's attributes.
129
+ */
130
+
131
+ export function resetBorderColor(_ref) {
132
+ let {
133
+ attributes = {},
134
+ setAttributes
135
+ } = _ref;
136
+ const {
137
+ style
138
+ } = attributes;
139
+ setAttributes({
140
+ borderColor: undefined,
141
+ style: removeBorderAttribute(style, 'color')
142
+ });
143
+ }
90
144
  /**
91
145
  * Filters registered block settings, extending attributes to include
92
146
  * `borderColor` if needed.
@@ -187,7 +241,7 @@ function addEditProps(settings) {
187
241
 
188
242
 
189
243
  export const withBorderColorPaletteStyles = createHigherOrderComponent(BlockListBlock => props => {
190
- var _getColorObjectByAttr2, _props$wrapperProps;
244
+ var _getColorObjectByAttr3, _props$wrapperProps;
191
245
 
192
246
  const {
193
247
  name,
@@ -203,7 +257,7 @@ export const withBorderColorPaletteStyles = createHigherOrderComponent(BlockList
203
257
  }
204
258
 
205
259
  const extraStyles = {
206
- borderColor: borderColor ? (_getColorObjectByAttr2 = getColorObjectByAttributeValues(colors, borderColor)) === null || _getColorObjectByAttr2 === void 0 ? void 0 : _getColorObjectByAttr2.color : undefined
260
+ borderColor: borderColor ? (_getColorObjectByAttr3 = getColorObjectByAttributeValues(colors, borderColor)) === null || _getColorObjectByAttr3 === void 0 ? void 0 : _getColorObjectByAttr3.color : undefined
207
261
  };
208
262
  let wrapperProps = props.wrapperProps;
209
263
  wrapperProps = { ...props.wrapperProps,
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/hooks/border-color.js"],"names":["classnames","addFilter","__","createHigherOrderComponent","useState","ColorGradientSettingsDropdown","useMultipleOriginColorsAndGradients","getColorClassName","getColorObjectByColorValue","getColorObjectByAttributeValues","useSetting","hasBorderSupport","shouldSkipSerialization","cleanEmptyObject","EMPTY_ARRAY","BorderColorEdit","props","attributes","borderColor","style","setAttributes","colorGradientSettings","availableColors","colors","reduce","origin","concat","colorValue","setColorValue","border","color","onChangeColor","value","colorObject","newStyle","slug","undefined","newNamedColor","settings","label","onColorChange","clearable","addAttributes","type","addSaveProps","blockType","borderColorClass","newClassName","className","addEditProps","existingGetEditWrapperProps","getEditWrapperProps","withBorderColorPaletteStyles","BlockListBlock","name","extraStyles","wrapperProps"],"mappings":";;;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SAASC,SAAT,QAA0B,kBAA1B;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,0BAAT,QAA2C,oBAA3C;AACA,SAASC,QAAT,QAAyB,oBAAzB;AAEA;AACA;AACA;;AACA,OAAOC,6BAAP,MAA0C,yCAA1C;AACA,OAAOC,mCAAP,MAAgD,yEAAhD;AACA,SACCC,iBADD,EAECC,0BAFD,EAGCC,+BAHD,QAIO,sBAJP;AAKA,OAAOC,UAAP,MAAuB,2BAAvB;AACA,SAASC,gBAAT,EAA2BC,uBAA3B,QAA0D,UAA1D;AACA,SAASC,gBAAT,QAAiC,SAAjC,C,CAEA;AACA;;AACA,MAAMC,WAAW,GAAG,EAApB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,eAAT,CAA0BC,KAA1B,EAAkC;AACxC,QAAM;AACLC,IAAAA,UAAU,EAAE;AAAEC,MAAAA,WAAF;AAAeC,MAAAA;AAAf,KADP;AAELC,IAAAA;AAFK,MAGFJ,KAHJ;AAIA,QAAMK,qBAAqB,GAAGf,mCAAmC,EAAjE;AACA,QA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0C,IAAF,CAFxB,EAGE;AACD,WAAO,cAAC,cAAD,EAAqBtC,KAArB,CAAP;AACA;;AAED,QAAMuC,WAAW,GAAG;AACnBrC,IAAAA,WAAW,EAAEA,WAAW,6BACrBT,+BAA+B,CAAEc,MAAF,EAAUL,WAAV,CADV,2DACrB,uBAAwDY,KADnC,GAErBM;AAHgB,GAApB;AAMA,MAAIoB,YAAY,GAAGxC,KAAK,CAACwC,YAAzB;AACAA,EAAAA,YAAY,GAAG,EACd,GAAGxC,KAAK,CAACwC,YADK;AAEdrC,IAAAA,KAAK,EAAE,EACN,GAAGoC,WADG;AAEN,iCAAGvC,KAAK,CAACwC,YAAT,wDAAG,oBAAoBrC,KAAvB;AAFM;AAFO,GAAf;AAQA,SAAO,cAAC,cAAD,eAAqBH,KAArB;AAA6B,IAAA,YAAY,EAAGwC;AAA5C,KAAP;AACA,CA7BoE,CAA/D;AAgCPvD,SAAS,CACR,0BADQ,EAER,2BAFQ,EAGRyC,aAHQ,CAAT;AAMAzC,SAAS,CACR,kCADQ,EAER,0BAFQ,EAGR2C,YAHQ,CAAT;AAMA3C,SAAS,CACR,0BADQ,EAER,0BAFQ,EAGRgD,YAHQ,CAAT;AAMAhD,SAAS,CACR,uBADQ,EAER,8CAFQ,EAGRmD,4BAHQ,CAAT","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { __ } from '@wordpress/i18n';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport ColorGradientSettingsDropdown from '../components/colors-gradients/dropdown';\nimport useMultipleOriginColorsAndGradients from '../components/colors-gradients/use-multiple-origin-colors-and-gradients';\nimport {\n\tgetColorClassName,\n\tgetColorObjectByColorValue,\n\tgetColorObjectByAttributeValues,\n} from '../components/colors';\nimport useSetting from '../components/use-setting';\nimport { hasBorderSupport, shouldSkipSerialization } from './border';\nimport { cleanEmptyObject } from './utils';\n\n// Defining empty array here instead of inline avoids unnecessary re-renders of\n// color control.\nconst EMPTY_ARRAY = [];\n\n/**\n * Inspector control panel containing the border color related configuration.\n *\n * There is deliberate overlap between the colors and borders block supports\n * relating to border color. It can be argued the border color controls could\n * be included within either, or both, the colors and borders panels in the\n * inspector controls. If they share the same block attributes it should not\n * matter.\n *\n * @param {Object} props Block properties.\n *\n * @return {WPElement} Border color edit element.\n */\nexport function BorderColorEdit( props ) {\n\tconst {\n\t\tattributes: { borderColor, style },\n\t\tsetAttributes,\n\t} = props;\n\tconst colorGradientSettings = useMultipleOriginColorsAndGradients();\n\tconst availableColors = colorGradientSettings.colors.reduce(\n\t\t( colors, origin ) => colors.concat( origin.colors ),\n\t\t[]\n\t);\n\tconst [ colorValue, setColorValue ] = useState(\n\t\t() =>\n\t\t\tgetColorObjectByAttributeValues(\n\t\t\t\tavailableColors,\n\t\t\t\tborderColor,\n\t\t\t\tstyle?.border?.color\n\t\t\t)?.color\n\t);\n\n\tconst onChangeColor = ( value ) => {\n\t\tsetColorValue( value );\n\n\t\tconst colorObject = getColorObjectByColorValue(\n\t\t\tavailableColors,\n\t\t\tvalue\n\t\t);\n\t\tconst newStyle = {\n\t\t\t...style,\n\t\t\tborder: {\n\t\t\t\t...style?.border,\n\t\t\t\tcolor: colorObject?.slug ? undefined : value,\n\t\t\t},\n\t\t};\n\n\t\t// If empty slug, ensure undefined to remove attribute.\n\t\tconst newNamedColor = colorObject?.slug ? colorObject.slug : undefined;\n\n\t\tsetAttributes( {\n\t\t\tstyle: cleanEmptyObject( newStyle ),\n\t\t\tborderColor: newNamedColor,\n\t\t} );\n\t};\n\n\tconst settings = [\n\t\t{\n\t\t\tlabel: __( 'Color' ),\n\t\t\tonColorChange: onChangeColor,\n\t\t\tcolorValue,\n\t\t\tclearable: false,\n\t\t},\n\t];\n\treturn (\n\t\t<ColorGradientSettingsDropdown\n\t\t\tsettings={ settings }\n\t\t\tdisableCustomColors\n\t\t\tdisableCustomGradients\n\t\t\t__experimentalHasMultipleOrigins\n\t\t\t__experimentalIsRenderedInSidebar\n\t\t\tenableAlpha\n\t\t\t{ ...colorGradientSettings }\n\t\t/>\n\t);\n}\n\n/**\n * Filters registered block settings, extending attributes to include\n * `borderColor` if needed.\n *\n * @param {Object} settings Original block settings.\n *\n * @return {Object} Updated block settings.\n */\nfunction addAttributes( settings ) {\n\tif ( ! hasBorderSupport( settings, 'color' ) ) {\n\t\treturn settings;\n\t}\n\n\t// Allow blocks to specify default value if needed.\n\tif ( settings.attributes.borderColor ) {\n\t\treturn settings;\n\t}\n\n\t// Add new borderColor attribute to block settings.\n\treturn {\n\t\t...settings,\n\t\tattributes: {\n\t\t\t...settings.attributes,\n\t\t\tborderColor: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t},\n\t};\n}\n\n/**\n * Override props assigned to save component to inject border color.\n *\n * @param {Object} props Additional props applied to save element.\n * @param {Object} blockType Block type definition.\n * @param {Object} attributes Block's attributes.\n *\n * @return {Object} Filtered props to apply to save element.\n */\nfunction addSaveProps( props, blockType, attributes ) {\n\tif (\n\t\t! hasBorderSupport( blockType, 'color' ) ||\n\t\tshouldSkipSerialization( blockType )\n\t) {\n\t\treturn props;\n\t}\n\n\tconst { borderColor, style } = attributes;\n\tconst borderColorClass = getColorClassName( 'border-color', borderColor );\n\n\tconst newClassName = classnames( props.className, {\n\t\t'has-border-color': borderColor || style?.border?.color,\n\t\t[ borderColorClass ]: !! borderColorClass,\n\t} );\n\n\t// If we are clearing the last of the previous classes in `className`\n\t// set it to `undefined` to avoid rendering empty DOM attributes.\n\tprops.className = newClassName ? newClassName : undefined;\n\n\treturn props;\n}\n\n/**\n * Filters the registered block settings to apply border color styles and\n * classnames to the block edit wrapper.\n *\n * @param {Object} settings Original block settings.\n *\n * @return {Object} Filtered block settings.\n */\nfunction addEditProps( settings ) {\n\tif (\n\t\t! hasBorderSupport( settings, 'color' ) ||\n\t\tshouldSkipSerialization( settings )\n\t) {\n\t\treturn settings;\n\t}\n\n\tconst existingGetEditWrapperProps = settings.getEditWrapperProps;\n\tsettings.getEditWrapperProps = ( attributes ) => {\n\t\tlet props = {};\n\n\t\tif ( existingGetEditWrapperProps ) {\n\t\t\tprops = existingGetEditWrapperProps( attributes );\n\t\t}\n\n\t\treturn addSaveProps( props, settings, attributes );\n\t};\n\n\treturn settings;\n}\n\n/**\n * This adds inline styles for color palette colors.\n * Ideally, this is not needed and themes should load their palettes on the editor.\n *\n * @param {Function} BlockListBlock Original component.\n *\n * @return {Function} Wrapped component.\n */\nexport const withBorderColorPaletteStyles = createHigherOrderComponent(\n\t( BlockListBlock ) => ( props ) => {\n\t\tconst { name, attributes } = props;\n\t\tconst { borderColor } = attributes;\n\t\tconst colors = useSetting( 'color.palette' ) || EMPTY_ARRAY;\n\n\t\tif (\n\t\t\t! hasBorderSupport( name, 'color' ) ||\n\t\t\tshouldSkipSerialization( name )\n\t\t) {\n\t\t\treturn <BlockListBlock { ...props } />;\n\t\t}\n\n\t\tconst extraStyles = {\n\t\t\tborderColor: borderColor\n\t\t\t\t? getColorObjectByAttributeValues( colors, borderColor )?.color\n\t\t\t\t: undefined,\n\t\t};\n\n\t\tlet wrapperProps = props.wrapperProps;\n\t\twrapperProps = {\n\t\t\t...props.wrapperProps,\n\t\t\tstyle: {\n\t\t\t\t...extraStyles,\n\t\t\t\t...props.wrapperProps?.style,\n\t\t\t},\n\t\t};\n\n\t\treturn <BlockListBlock { ...props } wrapperProps={ wrapperProps } />;\n\t}\n);\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/border/addAttributes',\n\taddAttributes\n);\n\naddFilter(\n\t'blocks.getSaveContent.extraProps',\n\t'core/border/addSaveProps',\n\taddSaveProps\n);\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/border/addEditProps',\n\taddEditProps\n);\n\naddFilter(\n\t'editor.BlockListBlock',\n\t'core/border/with-border-color-palette-styles',\n\twithBorderColorPaletteStyles\n);\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/hooks/border-color.js"],"names":["classnames","addFilter","__","createHigherOrderComponent","useEffect","useState","ColorGradientSettingsDropdown","useMultipleOriginColorsAndGradients","getColorClassName","getColorObjectByColorValue","getColorObjectByAttributeValues","useSetting","hasBorderSupport","removeBorderAttribute","shouldSkipSerialization","cleanEmptyObject","EMPTY_ARRAY","BorderColorEdit","props","attributes","borderColor","style","setAttributes","colorGradientSettings","availableColors","colors","reduce","origin","concat","color","customBorderColor","border","colorValue","setColorValue","onChangeColor","value","colorObject","newStyle","slug","undefined","newNamedColor","settings","label","onColorChange","clearable","hasBorderColorValue","resetBorderColor","addAttributes","type","addSaveProps","blockType","borderColorClass","newClassName","className","addEditProps","existingGetEditWrapperProps","getEditWrapperProps","withBorderColorPaletteStyles","BlockListBlock","name","extraStyles","wrapperProps"],"mappings":";;;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SAASC,SAAT,QAA0B,kBAA1B;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,0BAAT,QAA2C,oBAA3C;AACA,SAASC,SAAT,EAAoBC,QAApB,QAAoC,oBAApC;AAEA;AACA;AACA;;AACA,OAAOC,6BAAP,MAA0C,yCAA1C;AACA,OAAOC,mCAAP,MAAgD,yEAAhD;AACA,SACCC,iBADD,EAECC,0BAFD,EAGCC,+BAHD,QAIO,sBAJP;AAKA,OAAOC,UAAP,MAAuB,2BAAvB;AACA,SACCC,gBADD,EAECC,qBAFD,EAGCC,uBAHD,QAIO,UAJP;AAKA,SAASC,gBAAT,QAAiC,SAAjC,C,CAEA;AACA;;AACA,MAAMC,WAAW,GAAG,EAApB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,eAAT,CAA0BC,KAA1B,EAAkC;AACxC,QAAM;AACLC,IAAAA,UAAU,EAAE;AAAEC,MAAAA,WAAF;AAAeC,M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AAW,6BACrBV,+BAA+B,CAAEe,MAAF,EAAUL,WAAV,CADV,2DACrB,uBAAwDS,KADnC,GAErBU;AAHgB,GAApB;AAMA,MAAIsB,YAAY,GAAG3C,KAAK,CAAC2C,YAAzB;AACAA,EAAAA,YAAY,GAAG,EACd,GAAG3C,KAAK,CAAC2C,YADK;AAEdxC,IAAAA,KAAK,EAAE,EACN,GAAGuC,WADG;AAEN,iCAAG1C,KAAK,CAAC2C,YAAT,wDAAG,oBAAoBxC,KAAvB;AAFM;AAFO,GAAf;AAQA,SAAO,cAAC,cAAD,eAAqBH,KAArB;AAA6B,IAAA,YAAY,EAAG2C;AAA5C,KAAP;AACA,CA7BoE,CAA/D;AAgCP5D,SAAS,CACR,0BADQ,EAER,2BAFQ,EAGR8C,aAHQ,CAAT;AAMA9C,SAAS,CACR,kCADQ,EAER,0BAFQ,EAGRgD,YAHQ,CAAT;AAMAhD,SAAS,CACR,0BADQ,EAER,0BAFQ,EAGRqD,YAHQ,CAAT;AAMArD,SAAS,CACR,uBADQ,EAER,8CAFQ,EAGRwD,4BAHQ,CAAT","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { __ } from '@wordpress/i18n';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { useEffect, useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport ColorGradientSettingsDropdown from '../components/colors-gradients/dropdown';\nimport useMultipleOriginColorsAndGradients from '../components/colors-gradients/use-multiple-origin-colors-and-gradients';\nimport {\n\tgetColorClassName,\n\tgetColorObjectByColorValue,\n\tgetColorObjectByAttributeValues,\n} from '../components/colors';\nimport useSetting from '../components/use-setting';\nimport {\n\thasBorderSupport,\n\tremoveBorderAttribute,\n\tshouldSkipSerialization,\n} from './border';\nimport { cleanEmptyObject } from './utils';\n\n// Defining empty array here instead of inline avoids unnecessary re-renders of\n// color control.\nconst EMPTY_ARRAY = [];\n\n/**\n * Inspector control panel containing the border color related configuration.\n *\n * There is deliberate overlap between the colors and borders block supports\n * relating to border color. It can be argued the border color controls could\n * be included within either, or both, the colors and borders panels in the\n * inspector controls. If they share the same block attributes it should not\n * matter.\n *\n * @param {Object} props Block properties.\n *\n * @return {WPElement} Border color edit element.\n */\nexport function BorderColorEdit( props ) {\n\tconst {\n\t\tattributes: { borderColor, style },\n\t\tsetAttributes,\n\t} = props;\n\tconst colorGradientSettings = useMultipleOriginColorsAndGradients();\n\tconst availableColors = colorGradientSettings.colors.reduce(\n\t\t( colors, origin ) => colors.concat( origin.colors ),\n\t\t[]\n\t);\n\tconst { color: customBorderColor } = style?.border || {};\n\tconst [ colorValue, setColorValue ] = useState(\n\t\t() =>\n\t\t\tgetColorObjectByAttributeValues(\n\t\t\t\tavailableColors,\n\t\t\t\tborderColor,\n\t\t\t\tcustomBorderColor\n\t\t\t)?.color\n\t);\n\n\t// Detect changes in the color attributes and update the colorValue to keep the\n\t// UI in sync. This is necessary for situations when border controls interact with\n\t// each other: eg, setting the border width to zero causes the color and style\n\t// selections to be cleared.\n\tuseEffect( () => {\n\t\tsetColorValue(\n\t\t\tgetColorObjectByAttributeValues(\n\t\t\t\tavailableColors,\n\t\t\t\tborderColor,\n\t\t\t\tcustomBorderColor\n\t\t\t)?.color\n\t\t);\n\t}, [ borderColor, customBorderColor, availableColors ] );\n\n\tconst onChangeColor = ( value ) => {\n\t\tsetColorValue( value );\n\n\t\tconst colorObject = getColorObjectByColorValue(\n\t\t\tavailableColors,\n\t\t\tvalue\n\t\t);\n\t\tconst newStyle = {\n\t\t\t...style,\n\t\t\tborder: {\n\t\t\t\t...style?.border,\n\t\t\t\tcolor: colorObject?.slug ? undefined : value,\n\t\t\t},\n\t\t};\n\n\t\t// If empty slug, ensure undefined to remove attribute.\n\t\tconst newNamedColor = colorObject?.slug ? colorObject.slug : undefined;\n\n\t\tsetAttributes( {\n\t\t\tstyle: cleanEmptyObject( newStyle ),\n\t\t\tborderColor: newNamedColor,\n\t\t} );\n\t};\n\n\tconst settings = [\n\t\t{\n\t\t\tlabel: __( 'Color' ),\n\t\t\tonColorChange: onChangeColor,\n\t\t\tcolorValue,\n\t\t\tclearable: false,\n\t\t},\n\t];\n\treturn (\n\t\t<ColorGradientSettingsDropdown\n\t\t\tsettings={ settings }\n\t\t\tdisableCustomColors\n\t\t\tdisableCustomGradients\n\t\t\t__experimentalHasMultipleOrigins\n\t\t\t__experimentalIsRenderedInSidebar\n\t\t\tenableAlpha\n\t\t\t{ ...colorGradientSettings }\n\t\t/>\n\t);\n}\n\n/**\n * Checks if there is a current value in the border color block support\n * attributes.\n *\n * @param {Object} props Block props.\n * @return {boolean} Whether or not the block has a border color value set.\n */\nexport function hasBorderColorValue( props ) {\n\tconst {\n\t\tattributes: { borderColor, style },\n\t} = props;\n\n\treturn !! borderColor || !! style?.border?.color;\n}\n\n/**\n * Resets the border color block support attributes. This can be used when\n * disabling the border color support controls for a block via a progressive\n * discovery panel.\n *\n * @param {Object} props Block props.\n * @param {Object} props.attributes Block's attributes.\n * @param {Object} props.setAttributes Function to set block's attributes.\n */\nexport function resetBorderColor( { attributes = {}, setAttributes } ) {\n\tconst { style } = attributes;\n\n\tsetAttributes( {\n\t\tborderColor: undefined,\n\t\tstyle: removeBorderAttribute( style, 'color' ),\n\t} );\n}\n\n/**\n * Filters registered block settings, extending attributes to include\n * `borderColor` if needed.\n *\n * @param {Object} settings Original block settings.\n *\n * @return {Object} Updated block settings.\n */\nfunction addAttributes( settings ) {\n\tif ( ! hasBorderSupport( settings, 'color' ) ) {\n\t\treturn settings;\n\t}\n\n\t// Allow blocks to specify default value if needed.\n\tif ( settings.attributes.borderColor ) {\n\t\treturn settings;\n\t}\n\n\t// Add new borderColor attribute to block settings.\n\treturn {\n\t\t...settings,\n\t\tattributes: {\n\t\t\t...settings.attributes,\n\t\t\tborderColor: {\n\t\t\t\ttype: 'string',\n\t\t\t},\n\t\t},\n\t};\n}\n\n/**\n * Override props assigned to save component to inject border color.\n *\n * @param {Object} props Additional props applied to save element.\n * @param {Object} blockType Block type definition.\n * @param {Object} attributes Block's attributes.\n *\n * @return {Object} Filtered props to apply to save element.\n */\nfunction addSaveProps( props, blockType, attributes ) {\n\tif (\n\t\t! hasBorderSupport( blockType, 'color' ) ||\n\t\tshouldSkipSerialization( blockType )\n\t) {\n\t\treturn props;\n\t}\n\n\tconst { borderColor, style } = attributes;\n\tconst borderColorClass = getColorClassName( 'border-color', borderColor );\n\n\tconst newClassName = classnames( props.className, {\n\t\t'has-border-color': borderColor || style?.border?.color,\n\t\t[ borderColorClass ]: !! borderColorClass,\n\t} );\n\n\t// If we are clearing the last of the previous classes in `className`\n\t// set it to `undefined` to avoid rendering empty DOM attributes.\n\tprops.className = newClassName ? newClassName : undefined;\n\n\treturn props;\n}\n\n/**\n * Filters the registered block settings to apply border color styles and\n * classnames to the block edit wrapper.\n *\n * @param {Object} settings Original block settings.\n *\n * @return {Object} Filtered block settings.\n */\nfunction addEditProps( settings ) {\n\tif (\n\t\t! hasBorderSupport( settings, 'color' ) ||\n\t\tshouldSkipSerialization( settings )\n\t) {\n\t\treturn settings;\n\t}\n\n\tconst existingGetEditWrapperProps = settings.getEditWrapperProps;\n\tsettings.getEditWrapperProps = ( attributes ) => {\n\t\tlet props = {};\n\n\t\tif ( existingGetEditWrapperProps ) {\n\t\t\tprops = existingGetEditWrapperProps( attributes );\n\t\t}\n\n\t\treturn addSaveProps( props, settings, attributes );\n\t};\n\n\treturn settings;\n}\n\n/**\n * This adds inline styles for color palette colors.\n * Ideally, this is not needed and themes should load their palettes on the editor.\n *\n * @param {Function} BlockListBlock Original component.\n *\n * @return {Function} Wrapped component.\n */\nexport const withBorderColorPaletteStyles = createHigherOrderComponent(\n\t( BlockListBlock ) => ( props ) => {\n\t\tconst { name, attributes } = props;\n\t\tconst { borderColor } = attributes;\n\t\tconst colors = useSetting( 'color.palette' ) || EMPTY_ARRAY;\n\n\t\tif (\n\t\t\t! hasBorderSupport( name, 'color' ) ||\n\t\t\tshouldSkipSerialization( name )\n\t\t) {\n\t\t\treturn <BlockListBlock { ...props } />;\n\t\t}\n\n\t\tconst extraStyles = {\n\t\t\tborderColor: borderColor\n\t\t\t\t? getColorObjectByAttributeValues( colors, borderColor )?.color\n\t\t\t\t: undefined,\n\t\t};\n\n\t\tlet wrapperProps = props.wrapperProps;\n\t\twrapperProps = {\n\t\t\t...props.wrapperProps,\n\t\t\tstyle: {\n\t\t\t\t...extraStyles,\n\t\t\t\t...props.wrapperProps?.style,\n\t\t\t},\n\t\t};\n\n\t\treturn <BlockListBlock { ...props } wrapperProps={ wrapperProps } />;\n\t}\n);\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/border/addAttributes',\n\taddAttributes\n);\n\naddFilter(\n\t'blocks.getSaveContent.extraProps',\n\t'core/border/addSaveProps',\n\taddSaveProps\n);\n\naddFilter(\n\t'blocks.registerBlockType',\n\t'core/border/addEditProps',\n\taddEditProps\n);\n\naddFilter(\n\t'editor.BlockListBlock',\n\t'core/border/with-border-color-palette-styles',\n\twithBorderColorPaletteStyles\n);\n"]}
@@ -5,6 +5,7 @@ import { createElement } from "@wordpress/element";
5
5
  */
6
6
  import BorderRadiusControl from '../components/border-radius-control';
7
7
  import { cleanEmptyObject } from './utils';
8
+ import { removeBorderAttribute } from './border';
8
9
  /**
9
10
  * Inspector control panel containing the border radius related configuration.
10
11
  *
@@ -44,4 +45,45 @@ export function BorderRadiusEdit(props) {
44
45
  onChange: onChange
45
46
  });
46
47
  }
48
+ /**
49
+ * Checks if there is a current value in the border radius block support
50
+ * attributes.
51
+ *
52
+ * @param {Object} props Block props.
53
+ * @return {boolean} Whether or not the block has a border radius value set.
54
+ */
55
+
56
+ export function hasBorderRadiusValue(props) {
57
+ var _props$attributes$sty, _props$attributes$sty2;
58
+
59
+ const borderRadius = (_props$attributes$sty = props.attributes.style) === null || _props$attributes$sty === void 0 ? void 0 : (_props$attributes$sty2 = _props$attributes$sty.border) === null || _props$attributes$sty2 === void 0 ? void 0 : _props$attributes$sty2.radius;
60
+
61
+ if (typeof borderRadius === 'object') {
62
+ return Object.entries(borderRadius).some(Boolean);
63
+ }
64
+
65
+ return !!borderRadius;
66
+ }
67
+ /**
68
+ * Resets the border radius block support attributes. This can be used when
69
+ * disabling the border radius support controls for a block via a progressive
70
+ * discovery panel.
71
+ *
72
+ * @param {Object} props Block props.
73
+ * @param {Object} props.attributes Block's attributes.
74
+ * @param {Object} props.setAttributes Function to set block's attributes.
75
+ */
76
+
77
+ export function resetBorderRadius(_ref) {
78
+ let {
79
+ attributes = {},
80
+ setAttributes
81
+ } = _ref;
82
+ const {
83
+ style
84
+ } = attributes;
85
+ setAttributes({
86
+ style: removeBorderAttribute(style, 'radius')
87
+ });
88
+ }
47
89
  //# sourceMappingURL=border-radius.js.map