@wordpress/components 23.6.0 → 23.8.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 (484) hide show
  1. package/CHANGELOG.md +43 -4
  2. package/build/angle-picker-control/angle-circle.js +1 -4
  3. package/build/angle-picker-control/angle-circle.js.map +1 -1
  4. package/build/angle-picker-control/index.js +10 -22
  5. package/build/angle-picker-control/index.js.map +1 -1
  6. package/build/angle-picker-control/styles/angle-picker-control-styles.js +24 -15
  7. package/build/angle-picker-control/styles/angle-picker-control-styles.js.map +1 -1
  8. package/build/animate/index.js +27 -19
  9. package/build/animate/index.js.map +1 -1
  10. package/build/animate/types.js.map +1 -0
  11. package/build/box-control/axial-input-controls.js.map +1 -1
  12. package/build/color-picker/color-input.js +0 -4
  13. package/build/color-picker/color-input.js.map +1 -1
  14. package/build/color-picker/component.js +5 -4
  15. package/build/color-picker/component.js.map +1 -1
  16. package/build/color-picker/hex-input.js.map +1 -1
  17. package/build/color-picker/hsl-input.js.map +1 -1
  18. package/build/color-picker/input-with-slider.js.map +1 -1
  19. package/build/color-picker/legacy-adapter.js.map +1 -1
  20. package/build/color-picker/picker.js.map +1 -1
  21. package/build/color-picker/rgb-input.js.map +1 -1
  22. package/build/color-picker/use-deprecated-props.js.map +1 -1
  23. package/build/custom-gradient-picker/constants.js +1 -1
  24. package/build/custom-gradient-picker/constants.js.map +1 -1
  25. package/build/custom-gradient-picker/gradient-bar/constants.js.map +1 -1
  26. package/build/custom-gradient-picker/gradient-bar/control-points.js +9 -5
  27. package/build/custom-gradient-picker/gradient-bar/control-points.js.map +1 -1
  28. package/build/custom-gradient-picker/gradient-bar/index.js +14 -9
  29. package/build/custom-gradient-picker/gradient-bar/index.js.map +1 -1
  30. package/build/custom-gradient-picker/gradient-bar/utils.js +34 -54
  31. package/build/custom-gradient-picker/gradient-bar/utils.js.map +1 -1
  32. package/build/custom-gradient-picker/index.js +45 -16
  33. package/build/custom-gradient-picker/index.js.map +1 -1
  34. package/build/custom-gradient-picker/serializer.js +10 -4
  35. package/build/custom-gradient-picker/serializer.js.map +1 -1
  36. package/build/custom-gradient-picker/styles/custom-gradient-picker-styles.js +6 -6
  37. package/build/custom-gradient-picker/styles/custom-gradient-picker-styles.js.map +1 -1
  38. package/build/custom-gradient-picker/types.js +6 -0
  39. package/build/custom-gradient-picker/types.js.map +1 -0
  40. package/build/custom-gradient-picker/utils.js +17 -12
  41. package/build/custom-gradient-picker/utils.js.map +1 -1
  42. package/build/drop-zone/index.js +8 -8
  43. package/build/drop-zone/index.js.map +1 -1
  44. package/build/{color-list-picker → duotone-picker/color-list-picker}/index.js +5 -5
  45. package/build/duotone-picker/color-list-picker/index.js.map +1 -0
  46. package/build/duotone-picker/color-list-picker/types.js +6 -0
  47. package/build/duotone-picker/color-list-picker/types.js.map +1 -0
  48. package/build/duotone-picker/custom-duotone-bar.js.map +1 -1
  49. package/build/duotone-picker/duotone-picker.js +39 -2
  50. package/build/duotone-picker/duotone-picker.js.map +1 -1
  51. package/build/duotone-picker/duotone-swatch.js.map +1 -1
  52. package/build/duotone-picker/index.js.map +1 -1
  53. package/build/duotone-picker/types.js +6 -0
  54. package/build/duotone-picker/types.js.map +1 -0
  55. package/build/duotone-picker/utils.js +13 -11
  56. package/build/duotone-picker/utils.js.map +1 -1
  57. package/build/form-token-field/index.js +9 -3
  58. package/build/form-token-field/index.js.map +1 -1
  59. package/build/gradient-picker/index.js +61 -9
  60. package/build/gradient-picker/index.js.map +1 -1
  61. package/build/gradient-picker/types.js +6 -0
  62. package/build/gradient-picker/types.js.map +1 -0
  63. package/build/index.js.map +1 -1
  64. package/build/mobile/keyboard-aware-flat-list/index.android.js +0 -4
  65. package/build/mobile/keyboard-aware-flat-list/index.android.js.map +1 -1
  66. package/build/mobile/keyboard-aware-flat-list/index.ios.js +100 -55
  67. package/build/mobile/keyboard-aware-flat-list/index.ios.js.map +1 -1
  68. package/build/mobile/keyboard-aware-flat-list/use-keyboard-offset.native.js +82 -0
  69. package/build/mobile/keyboard-aware-flat-list/use-keyboard-offset.native.js.map +1 -0
  70. package/build/mobile/keyboard-aware-flat-list/use-scroll-to-text-input.native.js +85 -0
  71. package/build/mobile/keyboard-aware-flat-list/use-scroll-to-text-input.native.js.map +1 -0
  72. package/build/mobile/keyboard-aware-flat-list/use-text-input-caret-position.native.js +44 -0
  73. package/build/mobile/keyboard-aware-flat-list/use-text-input-caret-position.native.js.map +1 -0
  74. package/build/mobile/keyboard-aware-flat-list/use-text-input-offset.native.js +53 -0
  75. package/build/mobile/keyboard-aware-flat-list/use-text-input-offset.native.js.map +1 -0
  76. package/build/navigator/navigator-provider/component.js +4 -2
  77. package/build/navigator/navigator-provider/component.js.map +1 -1
  78. package/build/navigator/navigator-screen/component.js +4 -3
  79. package/build/navigator/navigator-screen/component.js.map +1 -1
  80. package/build/palette-edit/index.js +1 -2
  81. package/build/palette-edit/index.js.map +1 -1
  82. package/build/private-apis.js.map +1 -1
  83. package/build/query-controls/author-select.js +2 -1
  84. package/build/query-controls/author-select.js.map +1 -1
  85. package/build/query-controls/category-select.js +3 -1
  86. package/build/query-controls/category-select.js.map +1 -1
  87. package/build/query-controls/index.js +7 -1
  88. package/build/query-controls/index.js.map +1 -1
  89. package/build/resizable-box/resize-tooltip/utils.js.map +1 -1
  90. package/build/sandbox/index.native.js +129 -93
  91. package/build/sandbox/index.native.js.map +1 -1
  92. package/build/tab-panel/index.js +1 -1
  93. package/build/tab-panel/index.js.map +1 -1
  94. package/build/tools-panel/tools-panel/hook.js +45 -6
  95. package/build/tools-panel/tools-panel/hook.js.map +1 -1
  96. package/build/utils/input/input-control.js +1 -1
  97. package/build/utils/input/input-control.js.map +1 -1
  98. package/build-module/angle-picker-control/angle-circle.js +1 -4
  99. package/build-module/angle-picker-control/angle-circle.js.map +1 -1
  100. package/build-module/angle-picker-control/index.js +12 -21
  101. package/build-module/angle-picker-control/index.js.map +1 -1
  102. package/build-module/angle-picker-control/styles/angle-picker-control-styles.js +20 -13
  103. package/build-module/angle-picker-control/styles/angle-picker-control-styles.js.map +1 -1
  104. package/build-module/animate/index.js +25 -17
  105. package/build-module/animate/index.js.map +1 -1
  106. package/build-module/box-control/axial-input-controls.js.map +1 -1
  107. package/build-module/color-picker/color-input.js +0 -4
  108. package/build-module/color-picker/color-input.js.map +1 -1
  109. package/build-module/color-picker/component.js +3 -3
  110. package/build-module/color-picker/component.js.map +1 -1
  111. package/build-module/color-picker/hex-input.js.map +1 -1
  112. package/build-module/color-picker/hsl-input.js.map +1 -1
  113. package/build-module/color-picker/input-with-slider.js.map +1 -1
  114. package/build-module/color-picker/legacy-adapter.js.map +1 -1
  115. package/build-module/color-picker/picker.js +4 -0
  116. package/build-module/color-picker/picker.js.map +1 -1
  117. package/build-module/color-picker/rgb-input.js.map +1 -1
  118. package/build-module/color-picker/use-deprecated-props.js.map +1 -1
  119. package/build-module/custom-gradient-picker/constants.js +1 -1
  120. package/build-module/custom-gradient-picker/constants.js.map +1 -1
  121. package/build-module/custom-gradient-picker/gradient-bar/constants.js.map +1 -1
  122. package/build-module/custom-gradient-picker/gradient-bar/control-points.js +9 -4
  123. package/build-module/custom-gradient-picker/gradient-bar/control-points.js.map +1 -1
  124. package/build-module/custom-gradient-picker/gradient-bar/index.js +14 -8
  125. package/build-module/custom-gradient-picker/gradient-bar/index.js.map +1 -1
  126. package/build-module/custom-gradient-picker/gradient-bar/utils.js +34 -54
  127. package/build-module/custom-gradient-picker/gradient-bar/utils.js.map +1 -1
  128. package/build-module/custom-gradient-picker/index.js +44 -17
  129. package/build-module/custom-gradient-picker/index.js.map +1 -1
  130. package/build-module/custom-gradient-picker/serializer.js +10 -4
  131. package/build-module/custom-gradient-picker/serializer.js.map +1 -1
  132. package/build-module/custom-gradient-picker/styles/custom-gradient-picker-styles.js +6 -6
  133. package/build-module/custom-gradient-picker/styles/custom-gradient-picker-styles.js.map +1 -1
  134. package/build-module/custom-gradient-picker/types.js +2 -0
  135. package/build-module/custom-gradient-picker/utils.js +17 -12
  136. package/build-module/custom-gradient-picker/utils.js.map +1 -1
  137. package/build-module/drop-zone/index.js +8 -8
  138. package/build-module/drop-zone/index.js.map +1 -1
  139. package/build-module/{color-list-picker → duotone-picker/color-list-picker}/index.js +5 -5
  140. package/build-module/duotone-picker/color-list-picker/index.js.map +1 -0
  141. package/build-module/duotone-picker/color-list-picker/types.js +2 -0
  142. package/build-module/duotone-picker/color-list-picker/types.js.map +1 -0
  143. package/build-module/duotone-picker/custom-duotone-bar.js.map +1 -1
  144. package/build-module/duotone-picker/duotone-picker.js +38 -2
  145. package/build-module/duotone-picker/duotone-picker.js.map +1 -1
  146. package/build-module/duotone-picker/duotone-swatch.js.map +1 -1
  147. package/build-module/duotone-picker/index.js.map +1 -1
  148. package/build-module/duotone-picker/types.js +2 -0
  149. package/build-module/duotone-picker/types.js.map +1 -0
  150. package/build-module/duotone-picker/utils.js +17 -11
  151. package/build-module/duotone-picker/utils.js.map +1 -1
  152. package/build-module/form-token-field/index.js +9 -4
  153. package/build-module/form-token-field/index.js.map +1 -1
  154. package/build-module/gradient-picker/index.js +61 -10
  155. package/build-module/gradient-picker/index.js.map +1 -1
  156. package/build-module/gradient-picker/types.js +2 -0
  157. package/build-module/gradient-picker/types.js.map +1 -0
  158. package/build-module/index.js.map +1 -1
  159. package/build-module/mobile/keyboard-aware-flat-list/index.android.js +0 -4
  160. package/build-module/mobile/keyboard-aware-flat-list/index.android.js.map +1 -1
  161. package/build-module/mobile/keyboard-aware-flat-list/index.ios.js +97 -54
  162. package/build-module/mobile/keyboard-aware-flat-list/index.ios.js.map +1 -1
  163. package/build-module/mobile/keyboard-aware-flat-list/use-keyboard-offset.native.js +73 -0
  164. package/build-module/mobile/keyboard-aware-flat-list/use-keyboard-offset.native.js.map +1 -0
  165. package/build-module/mobile/keyboard-aware-flat-list/use-scroll-to-text-input.native.js +76 -0
  166. package/build-module/mobile/keyboard-aware-flat-list/use-scroll-to-text-input.native.js.map +1 -0
  167. package/build-module/mobile/keyboard-aware-flat-list/use-text-input-caret-position.native.js +33 -0
  168. package/build-module/mobile/keyboard-aware-flat-list/use-text-input-caret-position.native.js.map +1 -0
  169. package/build-module/mobile/keyboard-aware-flat-list/use-text-input-offset.native.js +40 -0
  170. package/build-module/mobile/keyboard-aware-flat-list/use-text-input-offset.native.js.map +1 -0
  171. package/build-module/navigator/navigator-provider/component.js +4 -2
  172. package/build-module/navigator/navigator-provider/component.js.map +1 -1
  173. package/build-module/navigator/navigator-screen/component.js +4 -3
  174. package/build-module/navigator/navigator-screen/component.js.map +1 -1
  175. package/build-module/palette-edit/index.js +1 -2
  176. package/build-module/palette-edit/index.js.map +1 -1
  177. package/build-module/private-apis.js.map +1 -1
  178. package/build-module/query-controls/author-select.js +2 -1
  179. package/build-module/query-controls/author-select.js.map +1 -1
  180. package/build-module/query-controls/category-select.js +3 -1
  181. package/build-module/query-controls/category-select.js.map +1 -1
  182. package/build-module/query-controls/index.js +7 -2
  183. package/build-module/query-controls/index.js.map +1 -1
  184. package/build-module/resizable-box/resize-tooltip/utils.js.map +1 -1
  185. package/build-module/sandbox/index.native.js +121 -87
  186. package/build-module/sandbox/index.native.js.map +1 -1
  187. package/build-module/tab-panel/index.js +2 -2
  188. package/build-module/tab-panel/index.js.map +1 -1
  189. package/build-module/tools-panel/tools-panel/hook.js +45 -6
  190. package/build-module/tools-panel/tools-panel/hook.js.map +1 -1
  191. package/build-module/utils/input/input-control.js +1 -1
  192. package/build-module/utils/input/input-control.js.map +1 -1
  193. package/build-style/style-rtl.css +41 -29
  194. package/build-style/style.css +43 -29
  195. package/build-types/angle-picker-control/angle-circle.d.ts.map +1 -1
  196. package/build-types/angle-picker-control/index.d.ts.map +1 -1
  197. package/build-types/angle-picker-control/styles/angle-picker-control-styles.d.ts +6 -1
  198. package/build-types/angle-picker-control/styles/angle-picker-control-styles.d.ts.map +1 -1
  199. package/build-types/animate/index.d.ts +27 -22
  200. package/build-types/animate/index.d.ts.map +1 -1
  201. package/build-types/animate/stories/index.d.ts +18 -0
  202. package/build-types/animate/stories/index.d.ts.map +1 -0
  203. package/build-types/animate/types.d.ts +30 -0
  204. package/build-types/animate/types.d.ts.map +1 -0
  205. package/build-types/border-box-control/border-box-control/hook.d.ts +2 -2
  206. package/build-types/border-box-control/border-box-control-linked-button/hook.d.ts +2 -2
  207. package/build-types/border-box-control/border-box-control-split-controls/hook.d.ts +2 -2
  208. package/build-types/border-box-control/border-box-control-visualizer/hook.d.ts +2 -2
  209. package/build-types/border-control/border-control/hook.d.ts +2 -2
  210. package/build-types/border-control/border-control-dropdown/hook.d.ts +2 -2
  211. package/build-types/border-control/border-control-style-picker/hook.d.ts +2 -2
  212. package/build-types/box-control/styles/box-control-styles.d.ts +5 -5
  213. package/build-types/button/deprecated.d.ts +2 -2
  214. package/build-types/card/card/hook.d.ts +2 -2
  215. package/build-types/card/card-body/hook.d.ts +2 -2
  216. package/build-types/card/card-divider/hook.d.ts +2 -2
  217. package/build-types/card/card-footer/hook.d.ts +2 -2
  218. package/build-types/card/card-header/hook.d.ts +2 -2
  219. package/build-types/card/card-media/hook.d.ts +2 -2
  220. package/build-types/color-palette/styles.d.ts +1 -1
  221. package/build-types/color-picker/color-input.d.ts +1 -11
  222. package/build-types/color-picker/color-input.d.ts.map +1 -1
  223. package/build-types/color-picker/component.d.ts +8 -9
  224. package/build-types/color-picker/component.d.ts.map +1 -1
  225. package/build-types/color-picker/hex-input.d.ts +1 -10
  226. package/build-types/color-picker/hex-input.d.ts.map +1 -1
  227. package/build-types/color-picker/hsl-input.d.ts +1 -10
  228. package/build-types/color-picker/hsl-input.d.ts.map +1 -1
  229. package/build-types/color-picker/input-with-slider.d.ts +1 -9
  230. package/build-types/color-picker/input-with-slider.d.ts.map +1 -1
  231. package/build-types/color-picker/legacy-adapter.d.ts +1 -3
  232. package/build-types/color-picker/legacy-adapter.d.ts.map +1 -1
  233. package/build-types/color-picker/picker.d.ts +4 -7
  234. package/build-types/color-picker/picker.d.ts.map +1 -1
  235. package/build-types/color-picker/rgb-input.d.ts +1 -10
  236. package/build-types/color-picker/rgb-input.d.ts.map +1 -1
  237. package/build-types/color-picker/stories/index.d.ts +19 -0
  238. package/build-types/color-picker/stories/index.d.ts.map +1 -0
  239. package/build-types/color-picker/styles.d.ts +5 -5
  240. package/build-types/color-picker/test/index.d.ts +2 -0
  241. package/build-types/color-picker/test/index.d.ts.map +1 -0
  242. package/build-types/color-picker/types.d.ts +105 -1
  243. package/build-types/color-picker/types.d.ts.map +1 -1
  244. package/build-types/color-picker/use-deprecated-props.d.ts +1 -44
  245. package/build-types/color-picker/use-deprecated-props.d.ts.map +1 -1
  246. package/build-types/combobox-control/styles.d.ts +1 -1
  247. package/build-types/custom-gradient-picker/constants.d.ts +8 -8
  248. package/build-types/custom-gradient-picker/constants.d.ts.map +1 -1
  249. package/build-types/custom-gradient-picker/gradient-bar/constants.d.ts +7 -7
  250. package/build-types/custom-gradient-picker/gradient-bar/constants.d.ts.map +1 -1
  251. package/build-types/custom-gradient-picker/gradient-bar/control-points.d.ts +5 -22
  252. package/build-types/custom-gradient-picker/gradient-bar/control-points.d.ts.map +1 -1
  253. package/build-types/custom-gradient-picker/gradient-bar/index.d.ts +3 -9
  254. package/build-types/custom-gradient-picker/gradient-bar/index.d.ts.map +1 -1
  255. package/build-types/custom-gradient-picker/gradient-bar/test/utils.d.ts +2 -0
  256. package/build-types/custom-gradient-picker/gradient-bar/test/utils.d.ts.map +1 -0
  257. package/build-types/custom-gradient-picker/gradient-bar/utils.d.ts +44 -92
  258. package/build-types/custom-gradient-picker/gradient-bar/utils.d.ts.map +1 -1
  259. package/build-types/custom-gradient-picker/index.d.ts +27 -6
  260. package/build-types/custom-gradient-picker/index.d.ts.map +1 -1
  261. package/build-types/custom-gradient-picker/serializer.d.ts +9 -16
  262. package/build-types/custom-gradient-picker/serializer.d.ts.map +1 -1
  263. package/build-types/custom-gradient-picker/stories/index.d.ts +12 -0
  264. package/build-types/custom-gradient-picker/stories/index.d.ts.map +1 -0
  265. package/build-types/custom-gradient-picker/styles/custom-gradient-picker-styles.d.ts +3 -2
  266. package/build-types/custom-gradient-picker/styles/custom-gradient-picker-styles.d.ts.map +1 -1
  267. package/build-types/custom-gradient-picker/test/serializer.d.ts +2 -0
  268. package/build-types/custom-gradient-picker/test/serializer.d.ts.map +1 -0
  269. package/build-types/custom-gradient-picker/types.d.ts +118 -0
  270. package/build-types/custom-gradient-picker/types.d.ts.map +1 -0
  271. package/build-types/custom-gradient-picker/utils.d.ts +12 -4
  272. package/build-types/custom-gradient-picker/utils.d.ts.map +1 -1
  273. package/build-types/date-time/date/styles.d.ts +2 -2
  274. package/build-types/date-time/date-time/styles.d.ts +1 -1
  275. package/build-types/date-time/time/styles.d.ts +8 -8
  276. package/build-types/drop-zone/index.d.ts.map +1 -1
  277. package/build-types/duotone-picker/color-list-picker/index.d.ts.map +1 -0
  278. package/build-types/{color-list-picker → duotone-picker/color-list-picker}/types.d.ts +2 -2
  279. package/build-types/duotone-picker/color-list-picker/types.d.ts.map +1 -0
  280. package/build-types/duotone-picker/custom-duotone-bar.d.ts +6 -0
  281. package/build-types/duotone-picker/custom-duotone-bar.d.ts.map +1 -0
  282. package/build-types/duotone-picker/duotone-picker.d.ts +38 -0
  283. package/build-types/duotone-picker/duotone-picker.d.ts.map +1 -0
  284. package/build-types/duotone-picker/duotone-swatch.d.ts +5 -0
  285. package/build-types/duotone-picker/duotone-swatch.d.ts.map +1 -0
  286. package/build-types/duotone-picker/index.d.ts +3 -0
  287. package/build-types/duotone-picker/index.d.ts.map +1 -0
  288. package/build-types/duotone-picker/stories/duotone-picker.d.ts +12 -0
  289. package/build-types/duotone-picker/stories/duotone-picker.d.ts.map +1 -0
  290. package/build-types/duotone-picker/stories/duotone-swatch.d.ts +14 -0
  291. package/build-types/duotone-picker/stories/duotone-swatch.d.ts.map +1 -0
  292. package/build-types/duotone-picker/types.d.ts +60 -0
  293. package/build-types/duotone-picker/types.d.ts.map +1 -0
  294. package/build-types/duotone-picker/utils.d.ts +52 -0
  295. package/build-types/duotone-picker/utils.d.ts.map +1 -0
  296. package/build-types/elevation/hook.d.ts +2 -2
  297. package/build-types/external-link/styles/external-link-styles.d.ts +1 -1
  298. package/build-types/flex/flex/hook.d.ts +2 -2
  299. package/build-types/flex/flex-block/hook.d.ts +2 -2
  300. package/build-types/flex/flex-item/hook.d.ts +2 -2
  301. package/build-types/focal-point-picker/styles/focal-point-picker-style.d.ts +2 -2
  302. package/build-types/form-token-field/index.d.ts.map +1 -1
  303. package/build-types/form-token-field/styles.d.ts +1 -1
  304. package/build-types/form-token-field/types.d.ts +6 -0
  305. package/build-types/form-token-field/types.d.ts.map +1 -1
  306. package/build-types/gradient-picker/index.d.ts +49 -11
  307. package/build-types/gradient-picker/index.d.ts.map +1 -1
  308. package/build-types/gradient-picker/stories/index.d.ts +14 -0
  309. package/build-types/gradient-picker/stories/index.d.ts.map +1 -0
  310. package/build-types/gradient-picker/types.d.ts +87 -0
  311. package/build-types/gradient-picker/types.d.ts.map +1 -0
  312. package/build-types/grid/hook.d.ts +2 -2
  313. package/build-types/h-stack/hook.d.ts +2 -2
  314. package/build-types/heading/hook.d.ts +2 -2
  315. package/build-types/index.d.ts +128 -0
  316. package/build-types/index.d.ts.map +1 -0
  317. package/build-types/input-control/styles/input-control-styles.d.ts +2 -2
  318. package/build-types/item-group/item/hook.d.ts +2 -2
  319. package/build-types/item-group/item-group/hook.d.ts +2 -2
  320. package/build-types/navigation/styles/navigation-styles.d.ts +2 -2
  321. package/build-types/navigator/navigator-back-button/hook.d.ts +2 -2
  322. package/build-types/navigator/navigator-button/hook.d.ts +2 -2
  323. package/build-types/navigator/navigator-provider/component.d.ts.map +1 -1
  324. package/build-types/navigator/navigator-screen/component.d.ts +1 -1
  325. package/build-types/navigator/navigator-screen/component.d.ts.map +1 -1
  326. package/build-types/navigator/stories/index.d.ts +1 -0
  327. package/build-types/navigator/stories/index.d.ts.map +1 -1
  328. package/build-types/navigator/types.d.ts +2 -2
  329. package/build-types/navigator/types.d.ts.map +1 -1
  330. package/build-types/number-control/index.d.ts +2 -2
  331. package/build-types/number-control/stories/index.d.ts +2 -2
  332. package/build-types/palette-edit/index.d.ts.map +1 -1
  333. package/build-types/palette-edit/styles.d.ts +3 -3
  334. package/build-types/popover/index.d.ts +1 -1
  335. package/build-types/popover/stories/e2e/index.d.ts +1 -1
  336. package/build-types/private-apis.d.ts +2 -3
  337. package/build-types/private-apis.d.ts.map +1 -1
  338. package/build-types/query-controls/author-select.d.ts.map +1 -1
  339. package/build-types/query-controls/category-select.d.ts.map +1 -1
  340. package/build-types/query-controls/index.d.ts.map +1 -1
  341. package/build-types/range-control/index.d.ts +1 -1
  342. package/build-types/range-control/styles/range-control-styles.d.ts +2 -2
  343. package/build-types/resizable-box/index.d.ts +1 -1
  344. package/build-types/resizable-box/resize-tooltip/index.d.ts +1 -1
  345. package/build-types/resizable-box/resize-tooltip/utils.d.ts +1 -1
  346. package/build-types/resizable-box/resize-tooltip/utils.d.ts.map +1 -1
  347. package/build-types/resizable-box/stories/index.d.ts +2 -2
  348. package/build-types/scrollable/hook.d.ts +2 -2
  349. package/build-types/search-control/index.d.ts +1 -1
  350. package/build-types/search-control/stories/index.d.ts +2 -2
  351. package/build-types/spacer/hook.d.ts +2 -2
  352. package/build-types/spinner/index.d.ts +1 -1
  353. package/build-types/surface/hook.d.ts +2 -2
  354. package/build-types/tab-panel/index.d.ts.map +1 -1
  355. package/build-types/text/hook.d.ts +2 -2
  356. package/build-types/text-control/index.d.ts +1 -1
  357. package/build-types/toolbar/toolbar-button/index.d.ts +2 -2
  358. package/build-types/tools-panel/tools-panel/hook.d.ts +2 -2
  359. package/build-types/tools-panel/tools-panel/hook.d.ts.map +1 -1
  360. package/build-types/tools-panel/tools-panel-header/hook.d.ts +2 -2
  361. package/build-types/tools-panel/tools-panel-item/hook.d.ts +2 -2
  362. package/build-types/tools-panel/types.d.ts +1 -0
  363. package/build-types/tools-panel/types.d.ts.map +1 -1
  364. package/build-types/truncate/hook.d.ts +2 -2
  365. package/build-types/ui/control-group/hook.d.ts +2 -2
  366. package/build-types/ui/control-label/hook.d.ts +2 -2
  367. package/build-types/ui/form-group/form-group.d.ts +2 -2
  368. package/build-types/ui/form-group/use-form-group.d.ts +2 -2
  369. package/build-types/unit-control/index.d.ts +1 -1
  370. package/build-types/unit-control/styles/unit-control-styles.d.ts +2 -2
  371. package/build-types/utils/input/input-control.d.ts.map +1 -1
  372. package/build-types/v-stack/hook.d.ts +2 -2
  373. package/package.json +20 -19
  374. package/src/angle-picker-control/angle-circle.tsx +0 -1
  375. package/src/angle-picker-control/index.tsx +14 -27
  376. package/src/angle-picker-control/styles/angle-picker-control-styles.tsx +16 -9
  377. package/src/animate/index.tsx +75 -0
  378. package/src/animate/stories/index.tsx +102 -0
  379. package/src/animate/types.ts +32 -0
  380. package/src/border-box-control/stories/index.tsx +1 -1
  381. package/src/box-control/axial-input-controls.tsx +1 -1
  382. package/src/circular-option-picker/style.scss +10 -0
  383. package/src/color-indicator/style.scss +1 -0
  384. package/src/color-picker/README.md +2 -2
  385. package/src/color-picker/color-input.tsx +1 -12
  386. package/src/color-picker/component.tsx +9 -18
  387. package/src/color-picker/hex-input.tsx +2 -7
  388. package/src/color-picker/hsl-input.tsx +2 -7
  389. package/src/color-picker/input-with-slider.tsx +1 -9
  390. package/src/color-picker/legacy-adapter.tsx +1 -2
  391. package/src/color-picker/picker.tsx +5 -6
  392. package/src/color-picker/rgb-input.tsx +2 -7
  393. package/src/color-picker/stories/index.tsx +51 -0
  394. package/src/color-picker/test/{index.js → index.tsx} +36 -18
  395. package/src/color-picker/types.ts +128 -1
  396. package/src/color-picker/use-deprecated-props.ts +2 -53
  397. package/src/combobox-control/stories/index.tsx +1 -1
  398. package/src/custom-gradient-picker/{constants.js → constants.ts} +2 -2
  399. package/src/custom-gradient-picker/gradient-bar/{control-points.js → control-points.tsx} +171 -134
  400. package/src/custom-gradient-picker/gradient-bar/{index.js → index.tsx} +32 -10
  401. package/src/custom-gradient-picker/gradient-bar/test/{utils.js → utils.ts} +58 -31
  402. package/src/custom-gradient-picker/gradient-bar/utils.ts +193 -0
  403. package/src/custom-gradient-picker/{index.js → index.tsx} +63 -22
  404. package/src/custom-gradient-picker/serializer.ts +78 -0
  405. package/src/custom-gradient-picker/stories/index.tsx +45 -0
  406. package/src/custom-gradient-picker/style.scss +25 -4
  407. package/src/custom-gradient-picker/test/{serializer.js → serializer.ts} +39 -33
  408. package/src/custom-gradient-picker/types.ts +119 -0
  409. package/src/custom-gradient-picker/{utils.js → utils.ts} +37 -22
  410. package/src/custom-select-control/test/index.js +6 -4
  411. package/src/drop-zone/index.tsx +12 -8
  412. package/src/drop-zone/style.scss +1 -1
  413. package/src/{color-list-picker → duotone-picker/color-list-picker}/index.tsx +7 -6
  414. package/src/{color-list-picker → duotone-picker/color-list-picker}/types.ts +2 -2
  415. package/src/duotone-picker/{custom-duotone-bar.js → custom-duotone-bar.tsx} +7 -1
  416. package/src/duotone-picker/{duotone-picker.js → duotone-picker.tsx} +39 -2
  417. package/src/duotone-picker/{duotone-swatch.js → duotone-swatch.tsx} +2 -1
  418. package/src/duotone-picker/stories/{duotone-picker.js → duotone-picker.tsx} +15 -8
  419. package/src/duotone-picker/stories/{duotone-swatch.js → duotone-swatch.tsx} +9 -3
  420. package/src/duotone-picker/types.ts +61 -0
  421. package/src/duotone-picker/{utils.js → utils.ts} +29 -14
  422. package/src/flex/flex-item/README.md +1 -1
  423. package/src/form-token-field/README.md +1 -0
  424. package/src/form-token-field/index.tsx +10 -3
  425. package/src/form-token-field/style.scss +0 -7
  426. package/src/form-token-field/test/index.tsx +1 -0
  427. package/src/form-token-field/types.ts +6 -0
  428. package/src/gradient-picker/README.md +16 -23
  429. package/src/gradient-picker/{index.js → index.tsx} +70 -16
  430. package/src/gradient-picker/stories/{index.js → index.tsx} +19 -8
  431. package/src/gradient-picker/types.ts +89 -0
  432. package/src/item-group/test/index.js +5 -3
  433. package/src/mobile/keyboard-aware-flat-list/index.android.js +0 -4
  434. package/src/mobile/keyboard-aware-flat-list/index.ios.js +118 -67
  435. package/src/mobile/keyboard-aware-flat-list/test/use-keyboard-offset.native.js +203 -0
  436. package/src/mobile/keyboard-aware-flat-list/test/use-scroll-to-text-input.native.js +140 -0
  437. package/src/mobile/keyboard-aware-flat-list/test/use-text-input-caret-position.native.js +82 -0
  438. package/src/mobile/keyboard-aware-flat-list/test/use-text-input-offset.native.js +147 -0
  439. package/src/mobile/keyboard-aware-flat-list/use-keyboard-offset.native.js +87 -0
  440. package/src/mobile/keyboard-aware-flat-list/use-scroll-to-text-input.native.js +105 -0
  441. package/src/mobile/keyboard-aware-flat-list/use-text-input-caret-position.native.js +36 -0
  442. package/src/mobile/keyboard-aware-flat-list/use-text-input-offset.native.js +54 -0
  443. package/src/navigator/navigator-provider/component.tsx +2 -0
  444. package/src/navigator/navigator-screen/component.tsx +5 -2
  445. package/src/navigator/stories/index.tsx +68 -0
  446. package/src/navigator/test/index.tsx +52 -0
  447. package/src/navigator/types.ts +2 -1
  448. package/src/palette-edit/index.tsx +4 -5
  449. package/src/query-controls/author-select.tsx +1 -0
  450. package/src/query-controls/category-select.tsx +1 -0
  451. package/src/query-controls/index.tsx +4 -2
  452. package/src/resizable-box/resize-tooltip/utils.ts +1 -1
  453. package/src/sandbox/index.native.js +139 -112
  454. package/src/slot-fill/test/slot.js +8 -6
  455. package/src/style.scss +1 -1
  456. package/src/tab-panel/index.tsx +7 -2
  457. package/src/tools-panel/test/index.tsx +86 -0
  458. package/src/tools-panel/tools-panel/hook.ts +44 -4
  459. package/src/tools-panel/types.ts +1 -0
  460. package/src/tooltip/test/index.js +251 -301
  461. package/src/utils/input/input-control.js +1 -0
  462. package/tsconfig.json +1 -3
  463. package/tsconfig.tsbuildinfo +1 -1
  464. package/build/color-list-picker/index.js.map +0 -1
  465. package/build-module/color-list-picker/index.js.map +0 -1
  466. package/build-types/color-list-picker/index.d.ts.map +0 -1
  467. package/build-types/color-list-picker/types.d.ts.map +0 -1
  468. package/src/animate/index.js +0 -60
  469. package/src/animate/stories/index.js +0 -53
  470. package/src/color-picker/stories/index.js +0 -41
  471. package/src/custom-gradient-picker/gradient-bar/utils.js +0 -189
  472. package/src/custom-gradient-picker/serializer.js +0 -48
  473. package/src/custom-gradient-picker/stories/index.js +0 -33
  474. /package/build/{color-list-picker → animate}/types.js +0 -0
  475. /package/build-module/{color-list-picker → animate}/types.js +0 -0
  476. /package/build-module/{color-list-picker → animate}/types.js.map +0 -0
  477. /package/{build/color-list-picker → build-module/custom-gradient-picker}/types.js.map +0 -0
  478. /package/build-types/{color-list-picker → duotone-picker/color-list-picker}/index.d.ts +0 -0
  479. /package/src/custom-gradient-picker/gradient-bar/{constants.js → constants.ts} +0 -0
  480. /package/src/custom-gradient-picker/styles/{custom-gradient-picker-styles.js → custom-gradient-picker-styles.tsx} +0 -0
  481. /package/src/{color-list-picker → duotone-picker/color-list-picker}/style.scss +0 -0
  482. /package/src/duotone-picker/{index.js → index.ts} +0 -0
  483. /package/src/{index.js → index.ts} +0 -0
  484. /package/src/{private-apis.js → private-apis.ts} +0 -0
@@ -9,76 +9,91 @@ import { WebView } from 'react-native-webview';
9
9
  * WordPress dependencies
10
10
  */
11
11
 
12
- import { Platform, renderToString, memo, useRef, useState, useEffect } from '@wordpress/element';
12
+ import { Platform, renderToString, memo, useRef, useState, useEffect, forwardRef, useCallback } from '@wordpress/element';
13
13
  import { usePreferredColorScheme } from '@wordpress/compose';
14
14
  /**
15
15
  * Internal dependencies
16
16
  */
17
17
 
18
18
  import sandboxStyles from './style.scss';
19
+ const observeAndResizeJS = `
20
+ (function() {
21
+ const { MutationObserver } = window;
19
22
 
20
- const observeAndResizeJS = function () {
21
- // Hermes requires a special directive to preserve the original source code
22
- // when using `Function.prototype.toString()` below.
23
- // https://github.com/facebook/hermes/issues/114#issuecomment-887106990
24
- 'show source';
23
+ if ( ! MutationObserver || ! document.body || ! window.parent ) {
24
+ return;
25
+ }
25
26
 
26
- const {
27
- MutationObserver
28
- } = window;
27
+ function sendResize() {
28
+ const clientBoundingRect = document.body.getBoundingClientRect();
29
29
 
30
- if (!MutationObserver || !document.body || !window.parent) {
31
- return;
32
- }
30
+ // The function postMessage is exposed by the react-native-webview library
31
+ // to communicate between React Native and the WebView, in this case,
32
+ // we use it for notifying resize changes.
33
+ window.ReactNativeWebView.postMessage(
34
+ JSON.stringify( {
35
+ action: 'resize',
36
+ width: clientBoundingRect.width,
37
+ height: clientBoundingRect.height,
38
+ } )
39
+ );
40
+ }
33
41
 
34
- function sendResize() {
35
- const clientBoundingRect = document.body.getBoundingClientRect(); // The function postMessage is exposed by the react-native-webview library
36
- // to communicate between React Native and the WebView, in this case,
37
- // we use it for notifying resize changes.
42
+ const observer = new MutationObserver( sendResize );
43
+ observer.observe( document.body, {
44
+ attributes: true,
45
+ attributeOldValue: false,
46
+ characterData: true,
47
+ characterDataOldValue: false,
48
+ childList: true,
49
+ subtree: true,
50
+ } );
38
51
 
39
- window.ReactNativeWebView.postMessage(JSON.stringify({
40
- action: 'resize',
41
- width: clientBoundingRect.width,
42
- height: clientBoundingRect.height
43
- }));
44
- }
52
+ window.addEventListener( 'load', sendResize, true );
45
53
 
46
- const observer = new MutationObserver(sendResize);
47
- observer.observe(document.body, {
48
- attributes: true,
49
- attributeOldValue: false,
50
- characterData: true,
51
- characterDataOldValue: false,
52
- childList: true,
53
- subtree: true
54
- });
55
- window.addEventListener('load', sendResize, true); // Hack: Remove viewport unit styles, as these are relative
56
- // the iframe root and interfere with our mechanism for
57
- // determining the unconstrained page bounds.
58
-
59
- function removeViewportStyles(ruleOrNode) {
60
- if (ruleOrNode.style) {
61
- ['width', 'height', 'minHeight', 'maxHeight'].forEach(function (style) {
62
- if (/^\\d+(vmin|vmax|vh|vw)$/.test(ruleOrNode.style[style])) {
63
- ruleOrNode.style[style] = '';
64
- }
65
- });
66
- }
67
- }
54
+ // Hack: Remove viewport unit styles, as these are relative
55
+ // the iframe root and interfere with our mechanism for
56
+ // determining the unconstrained page bounds.
57
+ function removeViewportStyles( ruleOrNode ) {
58
+ if ( ruleOrNode.style ) {
59
+ [ 'width', 'height', 'minHeight', 'maxHeight' ].forEach( function (
60
+ style
61
+ ) {
62
+ if (
63
+ /^\\d+(vmin|vmax|vh|vw)$/.test( ruleOrNode.style[ style ] )
64
+ ) {
65
+ ruleOrNode.style[ style ] = '';
66
+ }
67
+ } );
68
+ }
69
+ }
68
70
 
69
- Array.prototype.forEach.call(document.querySelectorAll('[style]'), removeViewportStyles);
70
- Array.prototype.forEach.call(document.styleSheets, function (stylesheet) {
71
- Array.prototype.forEach.call(stylesheet.cssRules || stylesheet.rules, removeViewportStyles);
72
- });
73
- document.body.style.position = 'absolute';
74
- document.body.style.width = '100%';
75
- document.body.setAttribute('data-resizable-iframe-connected', '');
76
- sendResize(); // Resize events can change the width of elements with 100% width, but we don't
77
- // get an DOM mutations for that, so do the resize when the window is resized, too.
71
+ Array.prototype.forEach.call(
72
+ document.querySelectorAll( '[style]' ),
73
+ removeViewportStyles
74
+ );
75
+ Array.prototype.forEach.call(
76
+ document.styleSheets,
77
+ function ( stylesheet ) {
78
+ Array.prototype.forEach.call(
79
+ stylesheet.cssRules || stylesheet.rules,
80
+ removeViewportStyles
81
+ );
82
+ }
83
+ );
78
84
 
79
- window.addEventListener('resize', sendResize, true);
80
- };
85
+ document.body.style.position = 'absolute';
86
+ document.body.style.width = '100%';
87
+ document.body.setAttribute( 'data-resizable-iframe-connected', '' );
81
88
 
89
+ sendResize();
90
+
91
+ // Resize events can change the width of elements with 100% width, but we don't
92
+ // get an DOM mutations for that, so do the resize when the window is resized, too.
93
+ window.addEventListener( 'resize', sendResize, true );
94
+ window.addEventListener( 'orientationchange', sendResize, true );
95
+ })();
96
+ `;
82
97
  const style = `
83
98
  body {
84
99
  margin: 0;
@@ -146,8 +161,7 @@ const style = `
146
161
  }
147
162
  `;
148
163
  const EMPTY_ARRAY = [];
149
-
150
- function Sandbox(_ref) {
164
+ const Sandbox = forwardRef(function Sandbox(_ref, ref) {
151
165
  let {
152
166
  containerStyle,
153
167
  customJS,
@@ -158,10 +172,10 @@ function Sandbox(_ref) {
158
172
  styles = EMPTY_ARRAY,
159
173
  title = '',
160
174
  type,
161
- url
175
+ url,
176
+ onWindowEvents = {}
162
177
  } = _ref;
163
178
  const colorScheme = usePreferredColorScheme();
164
- const ref = useRef();
165
179
  const [height, setHeight] = useState(0);
166
180
  const [contentHtml, setContentHtml] = useState(getHtmlDoc());
167
181
  const windowSize = Dimensions.get('window');
@@ -202,11 +216,6 @@ function Sandbox(_ref) {
202
216
  dangerouslySetInnerHTML: {
203
217
  __html: html
204
218
  }
205
- }), createElement("script", {
206
- type: "text/javascript",
207
- dangerouslySetInnerHTML: {
208
- __html: customJS || `(${observeAndResizeJS.toString()})();`
209
- }
210
219
  }), scripts.map(src => createElement("script", {
211
220
  key: src,
212
221
  src: src
@@ -214,6 +223,19 @@ function Sandbox(_ref) {
214
223
  return '<!DOCTYPE html>' + renderToString(htmlDoc);
215
224
  }
216
225
 
226
+ const getInjectedJavaScript = useCallback(() => {
227
+ // Allow parent to override the resize observers with prop.customJS (legacy support)
228
+ let injectedJS = customJS || observeAndResizeJS; // Add any event listeners that were passed in.
229
+
230
+ Object.keys(onWindowEvents).forEach(eventType => {
231
+ injectedJS += `
232
+ window.addEventListener( '${eventType}', function( event ) {
233
+ window.ReactNativeWebView.postMessage( JSON.stringify( { type: '${eventType}', ...event.data } ) );
234
+ });`;
235
+ });
236
+ return injectedJS;
237
+ }, [customJS, onWindowEvents]);
238
+
217
239
  function updateContentHtml() {
218
240
  let forceRerender = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
219
241
  const newContentHtml = getHtmlDoc();
@@ -229,25 +251,6 @@ function Sandbox(_ref) {
229
251
  }
230
252
  }
231
253
 
232
- function checkMessageForResize(event) {
233
- // Attempt to parse the message data as JSON if passed as string.
234
- let data = event.nativeEvent.data || {};
235
-
236
- if ('string' === typeof data) {
237
- try {
238
- data = JSON.parse(data);
239
- } catch (e) {}
240
- } // Update the state only if the message is formatted as we expect,
241
- // i.e. as an object with a 'resize' action.
242
-
243
-
244
- if ('resize' !== data.action) {
245
- return;
246
- }
247
-
248
- setHeight(data.height);
249
- }
250
-
251
254
  function getSizeStyle() {
252
255
  const contentHeight = Math.ceil(height);
253
256
  return contentHeight ? {
@@ -261,6 +264,36 @@ function Sandbox(_ref) {
261
264
  setIsLandscape(dimensions.window.width >= dimensions.window.height);
262
265
  }
263
266
 
267
+ const onMessage = useCallback(message => {
268
+ var _message$nativeEvent, _data;
269
+
270
+ let data = message === null || message === void 0 ? void 0 : (_message$nativeEvent = message.nativeEvent) === null || _message$nativeEvent === void 0 ? void 0 : _message$nativeEvent.data;
271
+
272
+ try {
273
+ data = JSON.parse(data);
274
+ } catch (e) {
275
+ return;
276
+ } // check for resize event
277
+
278
+
279
+ if ('resize' === ((_data = data) === null || _data === void 0 ? void 0 : _data.action)) {
280
+ setHeight(data.height);
281
+ } // Forward the event to parent event listeners
282
+
283
+
284
+ Object.keys(onWindowEvents).forEach(eventType => {
285
+ var _data2;
286
+
287
+ if (((_data2 = data) === null || _data2 === void 0 ? void 0 : _data2.type) === eventType) {
288
+ try {
289
+ onWindowEvents[eventType](data);
290
+ } catch (e) {
291
+ // eslint-disable-next-line no-console
292
+ console.warn(`Error handling event ${eventType}`, e);
293
+ }
294
+ }
295
+ });
296
+ }, [onWindowEvents]);
264
297
  useEffect(() => {
265
298
  const dimensionsChangeSubscription = Dimensions.addEventListener('change', onChangeDimensions);
266
299
  return () => {
@@ -283,6 +316,7 @@ function Sandbox(_ref) {
283
316
  }, [isLandscape]);
284
317
  return createElement(WebView, {
285
318
  containerStyle: [sandboxStyles['sandbox-webview__container'], containerStyle],
319
+ injectedJavaScript: getInjectedJavaScript(),
286
320
  key: key,
287
321
  ref: ref,
288
322
  source: {
@@ -293,14 +327,14 @@ function Sandbox(_ref) {
293
327
  ,
294
328
  originWhitelist: ['*'],
295
329
  style: [sandboxStyles['sandbox-webview__content'], getSizeStyle(), Platform.isAndroid && workaroundStyles.webView],
296
- onMessage: checkMessageForResize,
330
+ onMessage: onMessage,
297
331
  scrollEnabled: false,
298
332
  setBuiltInZoomControls: false,
299
333
  showsHorizontalScrollIndicator: false,
300
- showsVerticalScrollIndicator: false
334
+ showsVerticalScrollIndicator: false,
335
+ mediaPlaybackRequiresUserAction: false
301
336
  });
302
- }
303
-
337
+ });
304
338
  const workaroundStyles = StyleSheet.create({
305
339
  webView: {
306
340
  /**
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/components/src/sandbox/index.native.js"],"names":["Dimensions","StyleSheet","WebView","Platform","renderToString","memo","useRef","useState","useEffect","usePreferredColorScheme","sandboxStyles","observeAndResizeJS","MutationObserver","window","document","body","parent","sendResize","clientBoundingRect","getBoundingClientRect","ReactNativeWebView","postMessage","JSON","stringify","action","width","height","observer","observe","attributes","attributeOldValue","characterData","characterDataOldValue","childList","subtree","addEventListener","removeViewportStyles","ruleOrNode","style","forEach","test","Array","prototype","call","querySelectorAll","styleSheets","stylesheet","cssRules","rules","position","setAttribute","EMPTY_ARRAY","Sandbox","containerStyle","customJS","html","lang","providerUrl","scripts","styles","title","type","url","colorScheme","ref","setHeight","contentHtml","setContentHtml","getHtmlDoc","windowSize","get","isLandscape","setIsLandscape","wasLandscape","key","select","android","ios","htmlDoc","__html","map","i","toString","src","updateContentHtml","forceRerender","newContentHtml","setImmediate","checkMessageForResize","event","data","nativeEvent","parse","e","getSizeStyle","contentHeight","Math","ceil","aspectRatio","onChangeDimensions","dimensions","dimensionsChangeSubscription","remove","current","baseUrl","isAndroid","workaroundStyles","webView","create","opacity"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,UAAT,EAAqBC,UAArB,QAAuC,cAAvC;AACA,SAASC,OAAT,QAAwB,sBAAxB;AAEA;AACA;AACA;;AACA,SACCC,QADD,EAECC,cAFD,EAGCC,IAHD,EAICC,MAJD,EAKCC,QALD,EAMCC,SAND,QAOO,oBAPP;AAQA,SAAS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AE,MAAM;AAChB;AACA;AACA,QAAKiE,YAAY,CAAC8B,OAAb,KAAyBhC,WAA9B,EAA4C;AAC3CN,MAAAA,SAAS,CAAE,CAAF,CAAT;AACA;;AACDQ,IAAAA,YAAY,CAAC8B,OAAb,GAAuBhC,WAAvB;AACA,GAPQ,EAON,CAAEA,WAAF,CAPM,CAAT;AASA,SACC,cAAC,OAAD;AACC,IAAA,cAAc,EAAG,CAChB7D,aAAa,CAAE,4BAAF,CADG,EAEhB2C,cAFgB,CADlB;AAKC,IAAA,GAAG,EAAGqB,GALP;AAMC,IAAA,GAAG,EAAGV,GANP;AAOC,IAAA,MAAM,EAAG;AAAEwC,MAAAA,OAAO,EAAE/C,WAAX;AAAwBF,MAAAA,IAAI,EAAEW;AAA9B,KAPV,CAQC;AACA;AATD;AAUC,IAAA,eAAe,EAAG,CAAE,GAAF,CAVnB;AAWC,IAAA,KAAK,EAAG,CACPxD,aAAa,CAAE,0BAAF,CADN,EAEPoF,YAAY,EAFL,EAGP3F,QAAQ,CAACsG,SAAT,IAAsBC,gBAAgB,CAACC,OAHhC,CAXT;AAgBC,IAAA,SAAS,EAAGnB,qBAhBb;AAiBC,IAAA,aAAa,EAAG,KAjBjB;AAkBC,IAAA,sBAAsB,EAAG,KAlB1B;AAmBC,IAAA,8BAA8B,EAAG,KAnBlC;AAoBC,IAAA,4BAA4B,EAAG;AApBhC,IADD;AAwBA;;AAED,MAAMkB,gBAAgB,GAAGzG,UAAU,CAAC2G,MAAX,CAAmB;AAC3CD,EAAAA,OAAO,EAAE;AACR;AACF;AACA;AACA;AACA;AACEE,IAAAA,OAAO,EAAE;AAND;AADkC,CAAnB,CAAzB;AAWA,eAAexG,IAAI,CAAE+C,OAAF,CAAnB","sourcesContent":["/**\n * External dependencies\n */\nimport { Dimensions, StyleSheet } from 'react-native';\nimport { WebView } from 'react-native-webview';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tPlatform,\n\trenderToString,\n\tmemo,\n\tuseRef,\n\tuseState,\n\tuseEffect,\n} from '@wordpress/element';\nimport { usePreferredColorScheme } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport sandboxStyles from './style.scss';\n\nconst observeAndResizeJS = function () {\n\t// Hermes requires a special directive to preserve the original source code\n\t// when using `Function.prototype.toString()` below.\n\t// https://github.com/facebook/hermes/issues/114#issuecomment-887106990\n\t'show source';\n\tconst { MutationObserver } = window;\n\n\tif ( ! MutationObserver || ! document.body || ! window.parent ) {\n\t\treturn;\n\t}\n\n\tfunction sendResize() {\n\t\tconst clientBoundingRect = document.body.getBoundingClientRect();\n\n\t\t// The function postMessage is exposed by the react-native-webview library\n\t\t// to communicate between React Native and the WebView, in this case,\n\t\t// we use it for notifying resize changes.\n\t\twindow.ReactNativeWebView.postMessage(\n\t\t\tJSON.stringify( {\n\t\t\t\taction: 'resize',\n\t\t\t\twidth: clientBoundingRect.width,\n\t\t\t\theight: clientBoundingRect.height,\n\t\t\t} )\n\t\t);\n\t}\n\n\tconst observer = new MutationObserver( sendResize );\n\tobserver.observe( document.body, {\n\t\tattributes: true,\n\t\tattributeOldValue: false,\n\t\tcharacterData: true,\n\t\tcharacterDataOldValue: false,\n\t\tchildList: true,\n\t\tsubtree: true,\n\t} );\n\n\twindow.addEventListener( 'load', sendResize, true );\n\n\t// Hack: Remove viewport unit styles, as these are relative\n\t// the iframe root and interfere with our mechanism for\n\t// determining the unconstrained page bounds.\n\tfunction removeViewportStyles( ruleOrNode ) {\n\t\tif ( ruleOrNode.style ) {\n\t\t\t[ 'width', 'height', 'minHeight', 'maxHeight' ].forEach( function (\n\t\t\t\tstyle\n\t\t\t) {\n\t\t\t\tif (\n\t\t\t\t\t/^\\\\d+(vmin|vmax|vh|vw)$/.test( ruleOrNode.style[ style ] )\n\t\t\t\t) {\n\t\t\t\t\truleOrNode.style[ style ] = '';\n\t\t\t\t}\n\t\t\t} );\n\t\t}\n\t}\n\n\tArray.prototype.forEach.call(\n\t\tdocument.querySelectorAll( '[style]' ),\n\t\tremoveViewportStyles\n\t);\n\tArray.prototype.forEach.call(\n\t\tdocument.styleSheets,\n\t\tfunction ( stylesheet ) {\n\t\t\tArray.prototype.forEach.call(\n\t\t\t\tstylesheet.cssRules || stylesheet.rules,\n\t\t\t\tremoveViewportStyles\n\t\t\t);\n\t\t}\n\t);\n\n\tdocument.body.style.position = 'absolute';\n\tdocument.body.style.width = '100%';\n\tdocument.body.setAttribute( 'data-resizable-iframe-connected', '' );\n\n\tsendResize();\n\n\t// Resize events can change the width of elements with 100% width, but we don't\n\t// get an DOM mutations for that, so do the resize when the window is resized, too.\n\twindow.addEventListener( 'resize', sendResize, true );\n};\n\nconst style = `\n\tbody {\n\t\tmargin: 0;\n\t}\n\thtml,\n\tbody,\n\tbody > div,\n\tbody > div iframe {\n\t\twidth: 100%;\n\t}\n\tbody > div > * {\n\t\tmargin-top: 0 !important; /* Has to have !important to override inline styles. */\n\t\tmargin-bottom: 0 !important;\n\t}\n\n\t.wp-block-embed__wrapper {\n\t\tposition: relative;\n\t}\n\n\tbody.wp-has-aspect-ratio > div iframe {\n\t\theight: 100%;\n\t\toverflow: hidden; /* If it has an aspect ratio, it shouldn't scroll. */\n\t}\n\n\t/**\n\t * Add responsiveness to embeds with aspect ratios.\n\t *\n\t * These styles have been copied from the web version (https://github.com/WordPress/gutenberg/blob/7901895ca20cf61e402925e31571d659dab64721/packages/block-library/src/embed/style.scss#L42-L89) and\n\t * adapted for the native version.\n\t */\n\t.wp-has-aspect-ratio.wp-block-embed__wrapper::before {\n\t\tcontent: \"\";\n\t\tdisplay: block;\n\t\tpadding-top: 50%; // Default to 2:1 aspect ratio.\n\t}\n\t.wp-has-aspect-ratio iframe {\n\t\tposition: absolute;\n\t\ttop: 0;\n\t\tright: 0;\n\t\tbottom: 0;\n\t\tleft: 0;\n\t\theight: 100%;\n\t\twidth: 100%;\n\t}\n\t.wp-embed-aspect-21-9.wp-block-embed__wrapper::before {\n\t\tpadding-top: 42.85%; // 9 / 21 * 100\n\t}\n\t.wp-embed-aspect-18-9.wp-block-embed__wrapper::before {\n\t\tpadding-top: 50%; // 9 / 18 * 100\n\t}\n\t.wp-embed-aspect-16-9.wp-block-embed__wrapper::before {\n\t\tpadding-top: 56.25%; // 9 / 16 * 100\n\t}\n\t.wp-embed-aspect-4-3.wp-block-embed__wrapper::before {\n\t\tpadding-top: 75%; // 3 / 4 * 100\n\t}\n\t.wp-embed-aspect-1-1.wp-block-embed__wrapper::before {\n\t\tpadding-top: 100%; // 1 / 1 * 100\n\t}\n\t.wp-embed-aspect-9-16.wp-block-embed__wrapper::before {\n\t\tpadding-top: 177.77%; // 16 / 9 * 100\n\t}\n\t.wp-embed-aspect-1-2.wp-block-embed__wrapper::before {\n\t\tpadding-top: 200%; // 2 / 1 * 100\n\t}\n`;\n\nconst EMPTY_ARRAY = [];\n\nfunction Sandbox( {\n\tcontainerStyle,\n\tcustomJS,\n\thtml = '',\n\tlang = 'en',\n\tproviderUrl = '',\n\tscripts = EMPTY_ARRAY,\n\tstyles = EMPTY_ARRAY,\n\ttitle = '',\n\ttype,\n\turl,\n} ) {\n\tconst colorScheme = usePreferredColorScheme();\n\tconst ref = useRef();\n\tconst [ height, setHeight ] = useState( 0 );\n\tconst [ contentHtml, setContentHtml ] = useState( getHtmlDoc() );\n\n\tconst windowSize = Dimensions.get( 'window' );\n\tconst [ isLandscape, setIsLandscape ] = useState(\n\t\twindowSize.width >= windowSize.height\n\t);\n\tconst wasLandscape = useRef( isLandscape );\n\t// On Android, we need to recreate the WebView on any of the following actions, otherwise it disappears:\n\t// - Device rotation\n\t// - Light/dark mode changes\n\t// For this purpose, the key prop used in the WebView will be updated with the value of the actions.\n\tconst key = Platform.select( {\n\t\tandroid: `${ url }-${\n\t\t\tisLandscape ? 'landscape' : 'portrait'\n\t\t}-${ colorScheme }`,\n\t\tios: url,\n\t} );\n\n\tfunction getHtmlDoc() {\n\t\t// Put the html snippet into a html document, and update the state to refresh the WebView,\n\t\t// we can use this in the future to inject custom styles or scripts.\n\t\t// Scripts go into the body rather than the head, to support embedded content such as Instagram\n\t\t// that expect the scripts to be part of the body.\n\t\tconst htmlDoc = (\n\t\t\t<html lang={ lang }>\n\t\t\t\t<head>\n\t\t\t\t\t<title>{ title }</title>\n\t\t\t\t\t<meta\n\t\t\t\t\t\tname=\"viewport\"\n\t\t\t\t\t\tcontent=\"width=device-width, initial-scale=1\"\n\t\t\t\t\t></meta>\n\t\t\t\t\t<style dangerouslySetInnerHTML={ { __html: style } } />\n\t\t\t\t\t{ styles.map( ( rules, i ) => (\n\t\t\t\t\t\t<style\n\t\t\t\t\t\t\tkey={ i }\n\t\t\t\t\t\t\tdangerouslySetInnerHTML={ { __html: rules } }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) ) }\n\t\t\t\t</head>\n\t\t\t\t<body\n\t\t\t\t\tdata-resizable-iframe-connected=\"data-resizable-iframe-connected\"\n\t\t\t\t\tclassName={ type }\n\t\t\t\t>\n\t\t\t\t\t<div dangerouslySetInnerHTML={ { __html: html } } />\n\t\t\t\t\t<script\n\t\t\t\t\t\ttype=\"text/javascript\"\n\t\t\t\t\t\tdangerouslySetInnerHTML={ {\n\t\t\t\t\t\t\t__html:\n\t\t\t\t\t\t\t\tcustomJS ||\n\t\t\t\t\t\t\t\t`(${ observeAndResizeJS.toString() })();`,\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t\t{ scripts.map( ( src ) => (\n\t\t\t\t\t\t<script key={ src } src={ src } />\n\t\t\t\t\t) ) }\n\t\t\t\t</body>\n\t\t\t</html>\n\t\t);\n\t\treturn '<!DOCTYPE html>' + renderToString( htmlDoc );\n\t}\n\n\tfunction updateContentHtml( forceRerender = false ) {\n\t\tconst newContentHtml = getHtmlDoc();\n\n\t\tif ( forceRerender && contentHtml === newContentHtml ) {\n\t\t\t// The re-render is forced by updating the state with empty HTML,\n\t\t\t// waiting for the JS code to be executed with \"setImmediate\" and then\n\t\t\t// setting the content HTML again.\n\t\t\tsetContentHtml( '' );\n\t\t\tsetImmediate( () => setContentHtml( newContentHtml ) );\n\t\t} else {\n\t\t\tsetContentHtml( newContentHtml );\n\t\t}\n\t}\n\n\tfunction checkMessageForResize( event ) {\n\t\t// Attempt to parse the message data as JSON if passed as string.\n\t\tlet data = event.nativeEvent.data || {};\n\n\t\tif ( 'string' === typeof data ) {\n\t\t\ttry {\n\t\t\t\tdata = JSON.parse( data );\n\t\t\t} catch ( e ) {}\n\t\t}\n\n\t\t// Update the state only if the message is formatted as we expect,\n\t\t// i.e. as an object with a 'resize' action.\n\t\tif ( 'resize' !== data.action ) {\n\t\t\treturn;\n\t\t}\n\n\t\tsetHeight( data.height );\n\t}\n\n\tfunction getSizeStyle() {\n\t\tconst contentHeight = Math.ceil( height );\n\n\t\treturn contentHeight ? { height: contentHeight } : { aspectRatio: 1 };\n\t}\n\n\tfunction onChangeDimensions( dimensions ) {\n\t\tsetIsLandscape( dimensions.window.width >= dimensions.window.height );\n\t}\n\n\tuseEffect( () => {\n\t\tconst dimensionsChangeSubscription = Dimensions.addEventListener(\n\t\t\t'change',\n\t\t\tonChangeDimensions\n\t\t);\n\t\treturn () => {\n\t\t\tdimensionsChangeSubscription.remove();\n\t\t};\n\t}, [] );\n\n\tuseEffect( () => {\n\t\tupdateContentHtml();\n\t\t// Disable reason: deferring this refactor to the native team.\n\t\t// see https://github.com/WordPress/gutenberg/pull/41166\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t}, [ html, title, type, styles, scripts ] );\n\n\tuseEffect( () => {\n\t\t// When device orientation changes we have to recalculate the size,\n\t\t// for this purpose we reset the current size value.\n\t\tif ( wasLandscape.current !== isLandscape ) {\n\t\t\tsetHeight( 0 );\n\t\t}\n\t\twasLandscape.current = isLandscape;\n\t}, [ isLandscape ] );\n\n\treturn (\n\t\t<WebView\n\t\t\tcontainerStyle={ [\n\t\t\t\tsandboxStyles[ 'sandbox-webview__container' ],\n\t\t\t\tcontainerStyle,\n\t\t\t] }\n\t\t\tkey={ key }\n\t\t\tref={ ref }\n\t\t\tsource={ { baseUrl: providerUrl, html: contentHtml } }\n\t\t\t// Wildcard value is required for static HTML\n\t\t\t// Reference: https://github.com/react-native-webview/react-native-webview/blob/master/docs/Reference.md#source\n\t\t\toriginWhitelist={ [ '*' ] }\n\t\t\tstyle={ [\n\t\t\t\tsandboxStyles[ 'sandbox-webview__content' ],\n\t\t\t\tgetSizeStyle(),\n\t\t\t\tPlatform.isAndroid && workaroundStyles.webView,\n\t\t\t] }\n\t\t\tonMessage={ checkMessageForResize }\n\t\t\tscrollEnabled={ false }\n\t\t\tsetBuiltInZoomControls={ false }\n\t\t\tshowsHorizontalScrollIndicator={ false }\n\t\t\tshowsVerticalScrollIndicator={ false }\n\t\t/>\n\t);\n}\n\nconst workaroundStyles = StyleSheet.create( {\n\twebView: {\n\t\t/**\n\t\t * The slight opacity below is a workaround for an Android crash caused from combining Android\n\t\t * 12's new scroll overflow behavior and webviews.\n\t\t * https://github.com/react-native-webview/react-native-webview/issues/1915#issuecomment-808869253\n\t\t */\n\t\topacity: 0.99,\n\t},\n} );\n\nexport default memo( Sandbox );\n"]}
1
+ {"version":3,"sources":["@wordpress/components/src/sandbox/index.native.js"],"names":["Dimensions","StyleSheet","WebView","Platform","renderToString","memo","useRef","useState","useEffect","forwardRef","useCallback","usePreferredColorScheme","sandboxStyles","observeAndResizeJS","style","EMPTY_ARRAY","Sandbox","ref","containerStyle","customJS","html","lang","providerUrl","scripts","styles","title","type","url","onWindowEvents","colorScheme","height","setHeight","contentHtml","setContentHtml","getHtmlDoc","windowSize","get","isLandscape","setIsLandscape","width","wasLandscape","key","select","android","ios","htmlDoc","__html","map","rules","i","src","getInjectedJavaScript","injectedJS","Object","keys","forEach","eventType","updateContentHtml","forceRerender","newContentHtml","setImmediate","getSizeStyle","contentHeight","Math","ceil","aspectRatio","onChangeDimensions","dimensions","window","onMessage","message","data","nativeEvent","JSON","parse","e","action","console","warn","dimensionsChangeSubscription","addEventListener","remove","current","baseUrl","isAndroid","workaroundStyles","webView","create","opacity"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,UAAT,EAAqBC,UAArB,QAAuC,cAAvC;AACA,SAASC,OAAT,QAAwB,sBAAxB;AAEA;AACA;AACA;;AACA,SACCC,QADD,EAECC,cAFD,EAGCC,IAHD,EAICC,MAJD,EAKCC,QALD,EAMCC,SAND,EAOCC,UAPD,EAQCC,WARD,QASO,oBATP;AAUA,SAASC,uBAAT,QAAwC,oBAAxC;AAEA;AACA;AACA;;AACA,OAAOC,aAAP,MAA0B,cAA1B;AAEA,MAAMC,kBAAkB,GAAI;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CA7EA;AA+EA,MAAMC,KAAK,GAAI;AACf;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAjEA;AAmEA,MAAMC,WAAW,GAAG,EAApB;AAEA,MAAMC,OAAO,GAAGP,UAAU,CAAE,SAASO,OAAT,OAc3BC,GAd2B,EAe1B;AAAA,MAdD;AACCC,IAAAA,cADD;AAECC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,sBAAsB,EAAG,KAnB1B;AAoBC,IAAA,8BAA8B,EAAG,KApBlC;AAqBC,IAAA,4BAA4B,EAAG,KArBhC;AAsBC,IAAA,+BAA+B,EAAG;AAtBnC,IADD;AA0BA,CAnMyB,CAA1B;AAqMA,MAAMgB,gBAAgB,GAAGpF,UAAU,CAACsF,MAAX,CAAmB;AAC3CD,EAAAA,OAAO,EAAE;AACR;AACF;AACA;AACA;AACA;AACEE,IAAAA,OAAO,EAAE;AAND;AADkC,CAAnB,CAAzB;AAWA,eAAenF,IAAI,CAAEW,OAAF,CAAnB","sourcesContent":["/**\n * External dependencies\n */\nimport { Dimensions, StyleSheet } from 'react-native';\nimport { WebView } from 'react-native-webview';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tPlatform,\n\trenderToString,\n\tmemo,\n\tuseRef,\n\tuseState,\n\tuseEffect,\n\tforwardRef,\n\tuseCallback,\n} from '@wordpress/element';\nimport { usePreferredColorScheme } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport sandboxStyles from './style.scss';\n\nconst observeAndResizeJS = `\n\t(function() {\n\t\tconst { MutationObserver } = window;\n\n\t\tif ( ! MutationObserver || ! document.body || ! window.parent ) {\n\t\t\treturn;\n\t\t}\n\n\t\tfunction sendResize() {\n\t\t\tconst clientBoundingRect = document.body.getBoundingClientRect();\n\n\t\t\t// The function postMessage is exposed by the react-native-webview library\n\t\t\t// to communicate between React Native and the WebView, in this case,\n\t\t\t// we use it for notifying resize changes.\n\t\t\twindow.ReactNativeWebView.postMessage(\n\t\t\t\tJSON.stringify( {\n\t\t\t\t\taction: 'resize',\n\t\t\t\t\twidth: clientBoundingRect.width,\n\t\t\t\t\theight: clientBoundingRect.height,\n\t\t\t\t} )\n\t\t\t);\n\t\t}\n\n\t\tconst observer = new MutationObserver( sendResize );\n\t\tobserver.observe( document.body, {\n\t\t\tattributes: true,\n\t\t\tattributeOldValue: false,\n\t\t\tcharacterData: true,\n\t\t\tcharacterDataOldValue: false,\n\t\t\tchildList: true,\n\t\t\tsubtree: true,\n\t\t} );\n\n\t\twindow.addEventListener( 'load', sendResize, true );\n\n\t\t// Hack: Remove viewport unit styles, as these are relative\n\t\t// the iframe root and interfere with our mechanism for\n\t\t// determining the unconstrained page bounds.\n\t\tfunction removeViewportStyles( ruleOrNode ) {\n\t\t\tif ( ruleOrNode.style ) {\n\t\t\t\t[ 'width', 'height', 'minHeight', 'maxHeight' ].forEach( function (\n\t\t\t\t\tstyle\n\t\t\t\t) {\n\t\t\t\t\tif (\n\t\t\t\t\t\t/^\\\\d+(vmin|vmax|vh|vw)$/.test( ruleOrNode.style[ style ] )\n\t\t\t\t\t) {\n\t\t\t\t\t\truleOrNode.style[ style ] = '';\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t}\n\t\t}\n\n\t\tArray.prototype.forEach.call(\n\t\t\tdocument.querySelectorAll( '[style]' ),\n\t\t\tremoveViewportStyles\n\t\t);\n\t\tArray.prototype.forEach.call(\n\t\t\tdocument.styleSheets,\n\t\t\tfunction ( stylesheet ) {\n\t\t\t\tArray.prototype.forEach.call(\n\t\t\t\t\tstylesheet.cssRules || stylesheet.rules,\n\t\t\t\t\tremoveViewportStyles\n\t\t\t\t);\n\t\t\t}\n\t\t);\n\n\t\tdocument.body.style.position = 'absolute';\n\t\tdocument.body.style.width = '100%';\n\t\tdocument.body.setAttribute( 'data-resizable-iframe-connected', '' );\n\n\t\tsendResize();\n\n\t\t// Resize events can change the width of elements with 100% width, but we don't\n\t\t// get an DOM mutations for that, so do the resize when the window is resized, too.\n\t\twindow.addEventListener( 'resize', sendResize, true );\n\t\twindow.addEventListener( 'orientationchange', sendResize, true );\n\t})();\n`;\n\nconst style = `\n\tbody {\n\t\tmargin: 0;\n\t}\n\thtml,\n\tbody,\n\tbody > div,\n\tbody > div iframe {\n\t\twidth: 100%;\n\t}\n\tbody > div > * {\n\t\tmargin-top: 0 !important; /* Has to have !important to override inline styles. */\n\t\tmargin-bottom: 0 !important;\n\t}\n\n\t.wp-block-embed__wrapper {\n\t\tposition: relative;\n\t}\n\n\tbody.wp-has-aspect-ratio > div iframe {\n\t\theight: 100%;\n\t\toverflow: hidden; /* If it has an aspect ratio, it shouldn't scroll. */\n\t}\n\n\t/**\n\t * Add responsiveness to embeds with aspect ratios.\n\t *\n\t * These styles have been copied from the web version (https://github.com/WordPress/gutenberg/blob/7901895ca20cf61e402925e31571d659dab64721/packages/block-library/src/embed/style.scss#L42-L89) and\n\t * adapted for the native version.\n\t */\n\t.wp-has-aspect-ratio.wp-block-embed__wrapper::before {\n\t\tcontent: \"\";\n\t\tdisplay: block;\n\t\tpadding-top: 50%; // Default to 2:1 aspect ratio.\n\t}\n\t.wp-has-aspect-ratio iframe {\n\t\tposition: absolute;\n\t\ttop: 0;\n\t\tright: 0;\n\t\tbottom: 0;\n\t\tleft: 0;\n\t\theight: 100%;\n\t\twidth: 100%;\n\t}\n\t.wp-embed-aspect-21-9.wp-block-embed__wrapper::before {\n\t\tpadding-top: 42.85%; // 9 / 21 * 100\n\t}\n\t.wp-embed-aspect-18-9.wp-block-embed__wrapper::before {\n\t\tpadding-top: 50%; // 9 / 18 * 100\n\t}\n\t.wp-embed-aspect-16-9.wp-block-embed__wrapper::before {\n\t\tpadding-top: 56.25%; // 9 / 16 * 100\n\t}\n\t.wp-embed-aspect-4-3.wp-block-embed__wrapper::before {\n\t\tpadding-top: 75%; // 3 / 4 * 100\n\t}\n\t.wp-embed-aspect-1-1.wp-block-embed__wrapper::before {\n\t\tpadding-top: 100%; // 1 / 1 * 100\n\t}\n\t.wp-embed-aspect-9-16.wp-block-embed__wrapper::before {\n\t\tpadding-top: 177.77%; // 16 / 9 * 100\n\t}\n\t.wp-embed-aspect-1-2.wp-block-embed__wrapper::before {\n\t\tpadding-top: 200%; // 2 / 1 * 100\n\t}\n`;\n\nconst EMPTY_ARRAY = [];\n\nconst Sandbox = forwardRef( function Sandbox(\n\t{\n\t\tcontainerStyle,\n\t\tcustomJS,\n\t\thtml = '',\n\t\tlang = 'en',\n\t\tproviderUrl = '',\n\t\tscripts = EMPTY_ARRAY,\n\t\tstyles = EMPTY_ARRAY,\n\t\ttitle = '',\n\t\ttype,\n\t\turl,\n\t\tonWindowEvents = {},\n\t},\n\tref\n) {\n\tconst colorScheme = usePreferredColorScheme();\n\tconst [ height, setHeight ] = useState( 0 );\n\tconst [ contentHtml, setContentHtml ] = useState( getHtmlDoc() );\n\n\tconst windowSize = Dimensions.get( 'window' );\n\tconst [ isLandscape, setIsLandscape ] = useState(\n\t\twindowSize.width >= windowSize.height\n\t);\n\tconst wasLandscape = useRef( isLandscape );\n\t// On Android, we need to recreate the WebView on any of the following actions, otherwise it disappears:\n\t// - Device rotation\n\t// - Light/dark mode changes\n\t// For this purpose, the key prop used in the WebView will be updated with the value of the actions.\n\tconst key = Platform.select( {\n\t\tandroid: `${ url }-${\n\t\t\tisLandscape ? 'landscape' : 'portrait'\n\t\t}-${ colorScheme }`,\n\t\tios: url,\n\t} );\n\n\tfunction getHtmlDoc() {\n\t\t// Put the html snippet into a html document, and update the state to refresh the WebView,\n\t\t// we can use this in the future to inject custom styles or scripts.\n\t\t// Scripts go into the body rather than the head, to support embedded content such as Instagram\n\t\t// that expect the scripts to be part of the body.\n\t\tconst htmlDoc = (\n\t\t\t<html lang={ lang }>\n\t\t\t\t<head>\n\t\t\t\t\t<title>{ title }</title>\n\t\t\t\t\t<meta\n\t\t\t\t\t\tname=\"viewport\"\n\t\t\t\t\t\tcontent=\"width=device-width, initial-scale=1\"\n\t\t\t\t\t></meta>\n\t\t\t\t\t<style dangerouslySetInnerHTML={ { __html: style } } />\n\t\t\t\t\t{ styles.map( ( rules, i ) => (\n\t\t\t\t\t\t<style\n\t\t\t\t\t\t\tkey={ i }\n\t\t\t\t\t\t\tdangerouslySetInnerHTML={ { __html: rules } }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) ) }\n\t\t\t\t</head>\n\t\t\t\t<body\n\t\t\t\t\tdata-resizable-iframe-connected=\"data-resizable-iframe-connected\"\n\t\t\t\t\tclassName={ type }\n\t\t\t\t>\n\t\t\t\t\t<div dangerouslySetInnerHTML={ { __html: html } } />\n\t\t\t\t\t{ scripts.map( ( src ) => (\n\t\t\t\t\t\t<script key={ src } src={ src } />\n\t\t\t\t\t) ) }\n\t\t\t\t</body>\n\t\t\t</html>\n\t\t);\n\t\treturn '<!DOCTYPE html>' + renderToString( htmlDoc );\n\t}\n\n\tconst getInjectedJavaScript = useCallback( () => {\n\t\t// Allow parent to override the resize observers with prop.customJS (legacy support)\n\t\tlet injectedJS = customJS || observeAndResizeJS;\n\n\t\t// Add any event listeners that were passed in.\n\t\tObject.keys( onWindowEvents ).forEach( ( eventType ) => {\n\t\t\tinjectedJS += `\n\t\t\t\twindow.addEventListener( '${ eventType }', function( event ) {\n\t\t\t\t\twindow.ReactNativeWebView.postMessage( JSON.stringify( { type: '${ eventType }', ...event.data } ) );\n\t\t\t\t});`;\n\t\t} );\n\n\t\treturn injectedJS;\n\t}, [ customJS, onWindowEvents ] );\n\n\tfunction updateContentHtml( forceRerender = false ) {\n\t\tconst newContentHtml = getHtmlDoc();\n\n\t\tif ( forceRerender && contentHtml === newContentHtml ) {\n\t\t\t// The re-render is forced by updating the state with empty HTML,\n\t\t\t// waiting for the JS code to be executed with \"setImmediate\" and then\n\t\t\t// setting the content HTML again.\n\t\t\tsetContentHtml( '' );\n\t\t\tsetImmediate( () => setContentHtml( newContentHtml ) );\n\t\t} else {\n\t\t\tsetContentHtml( newContentHtml );\n\t\t}\n\t}\n\n\tfunction getSizeStyle() {\n\t\tconst contentHeight = Math.ceil( height );\n\n\t\treturn contentHeight ? { height: contentHeight } : { aspectRatio: 1 };\n\t}\n\n\tfunction onChangeDimensions( dimensions ) {\n\t\tsetIsLandscape( dimensions.window.width >= dimensions.window.height );\n\t}\n\n\tconst onMessage = useCallback(\n\t\t( message ) => {\n\t\t\tlet data = message?.nativeEvent?.data;\n\n\t\t\ttry {\n\t\t\t\tdata = JSON.parse( data );\n\t\t\t} catch ( e ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// check for resize event\n\t\t\tif ( 'resize' === data?.action ) {\n\t\t\t\tsetHeight( data.height );\n\t\t\t}\n\n\t\t\t// Forward the event to parent event listeners\n\t\t\tObject.keys( onWindowEvents ).forEach( ( eventType ) => {\n\t\t\t\tif ( data?.type === eventType ) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tonWindowEvents[ eventType ]( data );\n\t\t\t\t\t} catch ( e ) {\n\t\t\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t\t`Error handling event ${ eventType }`,\n\t\t\t\t\t\t\te\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} );\n\t\t},\n\t\t[ onWindowEvents ]\n\t);\n\n\tuseEffect( () => {\n\t\tconst dimensionsChangeSubscription = Dimensions.addEventListener(\n\t\t\t'change',\n\t\t\tonChangeDimensions\n\t\t);\n\t\treturn () => {\n\t\t\tdimensionsChangeSubscription.remove();\n\t\t};\n\t}, [] );\n\n\tuseEffect( () => {\n\t\tupdateContentHtml();\n\t\t// Disable reason: deferring this refactor to the native team.\n\t\t// see https://github.com/WordPress/gutenberg/pull/41166\n\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t}, [ html, title, type, styles, scripts ] );\n\n\tuseEffect( () => {\n\t\t// When device orientation changes we have to recalculate the size,\n\t\t// for this purpose we reset the current size value.\n\t\tif ( wasLandscape.current !== isLandscape ) {\n\t\t\tsetHeight( 0 );\n\t\t}\n\t\twasLandscape.current = isLandscape;\n\t}, [ isLandscape ] );\n\n\treturn (\n\t\t<WebView\n\t\t\tcontainerStyle={ [\n\t\t\t\tsandboxStyles[ 'sandbox-webview__container' ],\n\t\t\t\tcontainerStyle,\n\t\t\t] }\n\t\t\tinjectedJavaScript={ getInjectedJavaScript() }\n\t\t\tkey={ key }\n\t\t\tref={ ref }\n\t\t\tsource={ { baseUrl: providerUrl, html: contentHtml } }\n\t\t\t// Wildcard value is required for static HTML\n\t\t\t// Reference: https://github.com/react-native-webview/react-native-webview/blob/master/docs/Reference.md#source\n\t\t\toriginWhitelist={ [ '*' ] }\n\t\t\tstyle={ [\n\t\t\t\tsandboxStyles[ 'sandbox-webview__content' ],\n\t\t\t\tgetSizeStyle(),\n\t\t\t\tPlatform.isAndroid && workaroundStyles.webView,\n\t\t\t] }\n\t\t\tonMessage={ onMessage }\n\t\t\tscrollEnabled={ false }\n\t\t\tsetBuiltInZoomControls={ false }\n\t\t\tshowsHorizontalScrollIndicator={ false }\n\t\t\tshowsVerticalScrollIndicator={ false }\n\t\t\tmediaPlaybackRequiresUserAction={ false }\n\t\t/>\n\t);\n} );\n\nconst workaroundStyles = StyleSheet.create( {\n\twebView: {\n\t\t/**\n\t\t * The slight opacity below is a workaround for an Android crash caused from combining Android\n\t\t * 12's new scroll overflow behavior and webviews.\n\t\t * https://github.com/react-native-webview/react-native-webview/issues/1915#issuecomment-808869253\n\t\t */\n\t\topacity: 0.99,\n\t},\n} );\n\nexport default memo( Sandbox );\n"]}
@@ -9,7 +9,7 @@ import classnames from 'classnames';
9
9
  * WordPress dependencies
10
10
  */
11
11
 
12
- import { useState, useEffect, useCallback } from '@wordpress/element';
12
+ import { useState, useEffect, useLayoutEffect, useCallback } from '@wordpress/element';
13
13
  import { useInstanceId } from '@wordpress/compose';
14
14
  /**
15
15
  * Internal dependencies
@@ -104,7 +104,7 @@ export function TabPanel(_ref2) {
104
104
  });
105
105
  const selectedId = `${instanceId}-${(_selectedTab$name = selectedTab === null || selectedTab === void 0 ? void 0 : selectedTab.name) !== null && _selectedTab$name !== void 0 ? _selectedTab$name : 'none'}`; // Handle selecting the initial tab.
106
106
 
107
- useEffect(() => {
107
+ useLayoutEffect(() => {
108
108
  // If there's a selected tab, don't override it.
109
109
  if (selectedTab) {
110
110
  return;
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/components/src/tab-panel/index.tsx"],"names":["classnames","useState","useEffect","useCallback","useInstanceId","NavigableMenu","Button","TabButton","tabId","children","selected","rest","undefined","TabPanel","className","tabs","selectOnMove","initialTabName","orientation","activeClass","onSelect","instanceId","setSelected","handleTabSelection","tabKey","activateTabAutomatically","_childIndex","child","click","selectedTab","find","name","selectedId","initialTab","tab","disabled","firstEnabledTab","map","icon","title"],"mappings":";;;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SAASC,QAAT,EAAmBC,SAAnB,EAA8BC,WAA9B,QAAiD,oBAAjD;AACA,SAASC,aAAT,QAA8B,oBAA9B;AAEA;AACA;AACA;;AACA,SAASC,aAAT,QAA8B,wBAA9B;AACA,OAAOC,MAAP,MAAmB,WAAnB;;AAIA,MAAMC,SAAS,GAAG;AAAA,MAAE;AACnBC,IAAAA,KADmB;AAEnBC,IAAAA,QAFmB;AAGnBC,IAAAA,QAHmB;AAInB,OAAGC;AAJgB,GAAF;AAAA,SAMjB,cAAC,MAAD;AACC,IAAA,IAAI,EAAC,KADN;AAEC,IAAA,QAAQ,EAAGD,QAAQ,GAAGE,SAAH,GAAe,CAAC,CAFpC;AAGC,qBAAgBF,QAHjB;AAIC,IAAA,EAAE,EAAGF,KAJN;AAKC,IAAA,yBAAyB;AAL1B,KAMMG,IANN,GAQGF,QARH,CANiB;AAAA,CAAlB;AAkBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,OAAO,SAASI,QAAT,QASqD;AAAA;;AAAA,MATlC;AACzBC,IAAAA,SADyB;AAEzBL,IAAAA,QAFyB;AAGzBM,IAAAA,IAHyB;AAIzBC,IAAAA,YAAY,GAAG,IAJU;AAKzBC,IAAAA,cALyB;AAMzBC,IAAAA,WAAW,GAAG,YANW;AAO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BAAiB,GAAGV,UAAY,IAAIa,GAAG,CAACH,IAAM,OAT/C;AAUC,IAAA,QAAQ,EAAGG,GAAG,CAACH,IAAJ,KAAarB,QAVzB;AAWC,IAAA,GAAG,EAAGwB,GAAG,CAACH,IAXX;AAYC,IAAA,OAAO,EAAG,MAAMR,kBAAkB,CAAEW,GAAG,CAACH,IAAN,CAZnC;AAaC,IAAA,QAAQ,EAAGG,GAAG,CAACC,QAbhB;AAcC,IAAA,KAAK,EAAGD,GAAG,CAACI,IAAJ,IAAYJ,GAAG,CAACK,KAdzB;AAeC,IAAA,IAAI,EAAGL,GAAG,CAACI,IAfZ;AAgBC,IAAA,WAAW,EAAG,CAAC,CAAEJ,GAAG,CAACI;AAhBtB,KAkBG,CAAEJ,GAAG,CAACI,IAAN,IAAcJ,GAAG,CAACK,KAlBrB,CADC,CARH,CADD,EAgCGV,WAAW,IACZ;AACC,IAAA,GAAG,EAAGG,UADP;AAEC,uBAAkBA,UAFnB;AAGC,IAAA,IAAI,EAAC,UAHN;AAIC,IAAA,EAAE,EAAI,GAAGA,UAAY,OAJtB;AAKC,IAAA,SAAS,EAAC;AALX,KAOGvB,QAAQ,CAAEoB,WAAF,CAPX,CAjCF,CADD;AA8CA;AAED,eAAehB,QAAf","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useState, useEffect, useCallback } from '@wordpress/element';\nimport { useInstanceId } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { NavigableMenu } from '../navigable-container';\nimport Button from '../button';\nimport type { TabButtonProps, TabPanelProps } from './types';\nimport type { WordPressComponentProps } from '../ui/context';\n\nconst TabButton = ( {\n\ttabId,\n\tchildren,\n\tselected,\n\t...rest\n}: TabButtonProps ) => (\n\t<Button\n\t\trole=\"tab\"\n\t\ttabIndex={ selected ? undefined : -1 }\n\t\taria-selected={ selected }\n\t\tid={ tabId }\n\t\t__experimentalIsFocusable\n\t\t{ ...rest }\n\t>\n\t\t{ children }\n\t</Button>\n);\n\n/**\n * TabPanel is an ARIA-compliant tabpanel.\n *\n * TabPanels organize content across different screens, data sets, and interactions.\n * It has two sections: a list of tabs, and the view to show when tabs are chosen.\n *\n * ```jsx\n * import { TabPanel } from '@wordpress/components';\n *\n * const onSelect = ( tabName ) => {\n * console.log( 'Selecting tab', tabName );\n * };\n *\n * const MyTabPanel = () => (\n * <TabPanel\n * className=\"my-tab-panel\"\n * activeClass=\"active-tab\"\n * onSelect={ onSelect }\n * tabs={ [\n * {\n * name: 'tab1',\n * title: 'Tab 1',\n * className: 'tab-one',\n * },\n * {\n * name: 'tab2',\n * title: 'Tab 2',\n * className: 'tab-two',\n * },\n * ] }\n * >\n * { ( tab ) => <p>{ tab.title }</p> }\n * </TabPanel>\n * );\n * ```\n */\nexport function TabPanel( {\n\tclassName,\n\tchildren,\n\ttabs,\n\tselectOnMove = true,\n\tinitialTabName,\n\torientation = 'horizontal',\n\tactiveClass = 'is-active',\n\tonSelect,\n}: WordPressComponentProps< TabPanelProps, 'div', false > ) {\n\tconst instanceId = useInstanceId( TabPanel, 'tab-panel' );\n\tconst [ selected, setSelected ] = useState< string >();\n\n\tconst handleTabSelection = useCallback(\n\t\t( tabKey: string ) => {\n\t\t\tsetSelected( tabKey );\n\t\t\tonSelect?.( tabKey );\n\t\t},\n\t\t[ onSelect ]\n\t);\n\n\t// Simulate a click on the newly focused tab, which causes the component\n\t// to show the `tab-panel` associated with the clicked tab.\n\tconst activateTabAutomatically = (\n\t\t_childIndex: number,\n\t\tchild: HTMLButtonElement\n\t) => {\n\t\tchild.click();\n\t};\n\tconst selectedTab = tabs.find( ( { name } ) => name === selected );\n\tconst selectedId = `${ instanceId }-${ selectedTab?.name ?? 'none' }`;\n\n\t// Handle selecting the initial tab.\n\tuseEffect( () => {\n\t\t// If there's a selected tab, don't override it.\n\t\tif ( selectedTab ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst initialTab = tabs.find( ( tab ) => tab.name === initialTabName );\n\n\t\t// Wait for the denoted initial tab to be declared before making a\n\t\t// selection. This ensures that if a tab is declared lazily it can\n\t\t// still receive initial selection.\n\t\tif ( initialTabName && ! initialTab ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( initialTab && ! initialTab.disabled ) {\n\t\t\t// Select the initial tab if it's not disabled.\n\t\t\thandleTabSelection( initialTab.name );\n\t\t} else {\n\t\t\t// Fallback to the first enabled tab when the initial is disabled.\n\t\t\tconst firstEnabledTab = tabs.find( ( tab ) => ! tab.disabled );\n\t\t\tif ( firstEnabledTab ) handleTabSelection( firstEnabledTab.name );\n\t\t}\n\t}, [ tabs, selectedTab, initialTabName, handleTabSelection ] );\n\n\t// Handle the currently selected tab becoming disabled.\n\tuseEffect( () => {\n\t\t// This effect only runs when the selected tab is defined and becomes disabled.\n\t\tif ( ! selectedTab?.disabled ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst firstEnabledTab = tabs.find( ( tab ) => ! tab.disabled );\n\n\t\t// If the currently selected tab becomes disabled, select the first enabled tab.\n\t\t// (if there is one).\n\t\tif ( firstEnabledTab ) {\n\t\t\thandleTabSelection( firstEnabledTab.name );\n\t\t}\n\t}, [ tabs, selectedTab?.disabled, handleTabSelection ] );\n\n\treturn (\n\t\t<div className={ className }>\n\t\t\t<NavigableMenu\n\t\t\t\trole=\"tablist\"\n\t\t\t\torientation={ orientation }\n\t\t\t\tonNavigate={\n\t\t\t\t\tselectOnMove ? activateTabAutomatically : undefined\n\t\t\t\t}\n\t\t\t\tclassName=\"components-tab-panel__tabs\"\n\t\t\t>\n\t\t\t\t{ tabs.map( ( tab ) => (\n\t\t\t\t\t<TabButton\n\t\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t\t'components-tab-panel__tabs-item',\n\t\t\t\t\t\t\ttab.className,\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t[ activeClass ]: tab.name === selected,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t) }\n\t\t\t\t\t\ttabId={ `${ instanceId }-${ tab.name }` }\n\t\t\t\t\t\taria-controls={ `${ instanceId }-${ tab.name }-view` }\n\t\t\t\t\t\tselected={ tab.name === selected }\n\t\t\t\t\t\tkey={ tab.name }\n\t\t\t\t\t\tonClick={ () => handleTabSelection( tab.name ) }\n\t\t\t\t\t\tdisabled={ tab.disabled }\n\t\t\t\t\t\tlabel={ tab.icon && tab.title }\n\t\t\t\t\t\ticon={ tab.icon }\n\t\t\t\t\t\tshowTooltip={ !! tab.icon }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ ! tab.icon && tab.title }\n\t\t\t\t\t</TabButton>\n\t\t\t\t) ) }\n\t\t\t</NavigableMenu>\n\t\t\t{ selectedTab && (\n\t\t\t\t<div\n\t\t\t\t\tkey={ selectedId }\n\t\t\t\t\taria-labelledby={ selectedId }\n\t\t\t\t\trole=\"tabpanel\"\n\t\t\t\t\tid={ `${ selectedId }-view` }\n\t\t\t\t\tclassName=\"components-tab-panel__tab-content\"\n\t\t\t\t>\n\t\t\t\t\t{ children( selectedTab ) }\n\t\t\t\t</div>\n\t\t\t) }\n\t\t</div>\n\t);\n}\n\nexport default TabPanel;\n"]}
1
+ {"version":3,"sources":["@wordpress/components/src/tab-panel/index.tsx"],"names":["classnames","useState","useEffect","useLayoutEffect","useCallback","useInstanceId","NavigableMenu","Button","TabButton","tabId","children","selected","rest","undefined","TabPanel","className","tabs","selectOnMove","initialTabName","orientation","activeClass","onSelect","instanceId","setSelected","handleTabSelection","tabKey","activateTabAutomatically","_childIndex","child","click","selectedTab","find","name","selectedId","initialTab","tab","disabled","firstEnabledTab","map","icon","title"],"mappings":";;;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SACCC,QADD,EAECC,SAFD,EAGCC,eAHD,EAICC,WAJD,QAKO,oBALP;AAMA,SAASC,aAAT,QAA8B,oBAA9B;AAEA;AACA;AACA;;AACA,SAASC,aAAT,QAA8B,wBAA9B;AACA,OA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hBtB,KAkBG,CAAEJ,GAAG,CAACI,IAAN,IAAcJ,GAAG,CAACK,KAlBrB,CADC,CARH,CADD,EAgCGV,WAAW,IACZ;AACC,IAAA,GAAG,EAAGG,UADP;AAEC,uBAAkBA,UAFnB;AAGC,IAAA,IAAI,EAAC,UAHN;AAIC,IAAA,EAAE,EAAI,GAAGA,UAAY,OAJtB;AAKC,IAAA,SAAS,EAAC;AALX,KAOGvB,QAAQ,CAAEoB,WAAF,CAPX,CAjCF,CADD;AA8CA;AAED,eAAehB,QAAf","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tuseState,\n\tuseEffect,\n\tuseLayoutEffect,\n\tuseCallback,\n} from '@wordpress/element';\nimport { useInstanceId } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { NavigableMenu } from '../navigable-container';\nimport Button from '../button';\nimport type { TabButtonProps, TabPanelProps } from './types';\nimport type { WordPressComponentProps } from '../ui/context';\n\nconst TabButton = ( {\n\ttabId,\n\tchildren,\n\tselected,\n\t...rest\n}: TabButtonProps ) => (\n\t<Button\n\t\trole=\"tab\"\n\t\ttabIndex={ selected ? undefined : -1 }\n\t\taria-selected={ selected }\n\t\tid={ tabId }\n\t\t__experimentalIsFocusable\n\t\t{ ...rest }\n\t>\n\t\t{ children }\n\t</Button>\n);\n\n/**\n * TabPanel is an ARIA-compliant tabpanel.\n *\n * TabPanels organize content across different screens, data sets, and interactions.\n * It has two sections: a list of tabs, and the view to show when tabs are chosen.\n *\n * ```jsx\n * import { TabPanel } from '@wordpress/components';\n *\n * const onSelect = ( tabName ) => {\n * console.log( 'Selecting tab', tabName );\n * };\n *\n * const MyTabPanel = () => (\n * <TabPanel\n * className=\"my-tab-panel\"\n * activeClass=\"active-tab\"\n * onSelect={ onSelect }\n * tabs={ [\n * {\n * name: 'tab1',\n * title: 'Tab 1',\n * className: 'tab-one',\n * },\n * {\n * name: 'tab2',\n * title: 'Tab 2',\n * className: 'tab-two',\n * },\n * ] }\n * >\n * { ( tab ) => <p>{ tab.title }</p> }\n * </TabPanel>\n * );\n * ```\n */\nexport function TabPanel( {\n\tclassName,\n\tchildren,\n\ttabs,\n\tselectOnMove = true,\n\tinitialTabName,\n\torientation = 'horizontal',\n\tactiveClass = 'is-active',\n\tonSelect,\n}: WordPressComponentProps< TabPanelProps, 'div', false > ) {\n\tconst instanceId = useInstanceId( TabPanel, 'tab-panel' );\n\tconst [ selected, setSelected ] = useState< string >();\n\n\tconst handleTabSelection = useCallback(\n\t\t( tabKey: string ) => {\n\t\t\tsetSelected( tabKey );\n\t\t\tonSelect?.( tabKey );\n\t\t},\n\t\t[ onSelect ]\n\t);\n\n\t// Simulate a click on the newly focused tab, which causes the component\n\t// to show the `tab-panel` associated with the clicked tab.\n\tconst activateTabAutomatically = (\n\t\t_childIndex: number,\n\t\tchild: HTMLButtonElement\n\t) => {\n\t\tchild.click();\n\t};\n\tconst selectedTab = tabs.find( ( { name } ) => name === selected );\n\tconst selectedId = `${ instanceId }-${ selectedTab?.name ?? 'none' }`;\n\n\t// Handle selecting the initial tab.\n\tuseLayoutEffect( () => {\n\t\t// If there's a selected tab, don't override it.\n\t\tif ( selectedTab ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst initialTab = tabs.find( ( tab ) => tab.name === initialTabName );\n\n\t\t// Wait for the denoted initial tab to be declared before making a\n\t\t// selection. This ensures that if a tab is declared lazily it can\n\t\t// still receive initial selection.\n\t\tif ( initialTabName && ! initialTab ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( initialTab && ! initialTab.disabled ) {\n\t\t\t// Select the initial tab if it's not disabled.\n\t\t\thandleTabSelection( initialTab.name );\n\t\t} else {\n\t\t\t// Fallback to the first enabled tab when the initial is disabled.\n\t\t\tconst firstEnabledTab = tabs.find( ( tab ) => ! tab.disabled );\n\t\t\tif ( firstEnabledTab ) handleTabSelection( firstEnabledTab.name );\n\t\t}\n\t}, [ tabs, selectedTab, initialTabName, handleTabSelection ] );\n\n\t// Handle the currently selected tab becoming disabled.\n\tuseEffect( () => {\n\t\t// This effect only runs when the selected tab is defined and becomes disabled.\n\t\tif ( ! selectedTab?.disabled ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst firstEnabledTab = tabs.find( ( tab ) => ! tab.disabled );\n\n\t\t// If the currently selected tab becomes disabled, select the first enabled tab.\n\t\t// (if there is one).\n\t\tif ( firstEnabledTab ) {\n\t\t\thandleTabSelection( firstEnabledTab.name );\n\t\t}\n\t}, [ tabs, selectedTab?.disabled, handleTabSelection ] );\n\n\treturn (\n\t\t<div className={ className }>\n\t\t\t<NavigableMenu\n\t\t\t\trole=\"tablist\"\n\t\t\t\torientation={ orientation }\n\t\t\t\tonNavigate={\n\t\t\t\t\tselectOnMove ? activateTabAutomatically : undefined\n\t\t\t\t}\n\t\t\t\tclassName=\"components-tab-panel__tabs\"\n\t\t\t>\n\t\t\t\t{ tabs.map( ( tab ) => (\n\t\t\t\t\t<TabButton\n\t\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t\t'components-tab-panel__tabs-item',\n\t\t\t\t\t\t\ttab.className,\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t[ activeClass ]: tab.name === selected,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t) }\n\t\t\t\t\t\ttabId={ `${ instanceId }-${ tab.name }` }\n\t\t\t\t\t\taria-controls={ `${ instanceId }-${ tab.name }-view` }\n\t\t\t\t\t\tselected={ tab.name === selected }\n\t\t\t\t\t\tkey={ tab.name }\n\t\t\t\t\t\tonClick={ () => handleTabSelection( tab.name ) }\n\t\t\t\t\t\tdisabled={ tab.disabled }\n\t\t\t\t\t\tlabel={ tab.icon && tab.title }\n\t\t\t\t\t\ticon={ tab.icon }\n\t\t\t\t\t\tshowTooltip={ !! tab.icon }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ ! tab.icon && tab.title }\n\t\t\t\t\t</TabButton>\n\t\t\t\t) ) }\n\t\t\t</NavigableMenu>\n\t\t\t{ selectedTab && (\n\t\t\t\t<div\n\t\t\t\t\tkey={ selectedId }\n\t\t\t\t\taria-labelledby={ selectedId }\n\t\t\t\t\trole=\"tabpanel\"\n\t\t\t\t\tid={ `${ selectedId }-view` }\n\t\t\t\t\tclassName=\"components-tab-panel__tab-content\"\n\t\t\t\t>\n\t\t\t\t\t{ children( selectedTab ) }\n\t\t\t\t</div>\n\t\t\t) }\n\t\t</div>\n\t);\n}\n\nexport default TabPanel;\n"]}
@@ -15,8 +15,13 @@ const generateMenuItems = _ref => {
15
15
  let {
16
16
  panelItems,
17
17
  shouldReset,
18
- currentMenuItems
18
+ currentMenuItems,
19
+ menuItemOrder
19
20
  } = _ref;
21
+ const newMenuItems = {
22
+ default: {},
23
+ optional: {}
24
+ };
20
25
  const menuItems = {
21
26
  default: {},
22
27
  optional: {}
@@ -35,7 +40,28 @@ const generateMenuItems = _ref => {
35
40
 
36
41
  const existingItemValue = currentMenuItems === null || currentMenuItems === void 0 ? void 0 : (_currentMenuItems$gro = currentMenuItems[group]) === null || _currentMenuItems$gro === void 0 ? void 0 : _currentMenuItems$gro[label];
37
42
  const value = existingItemValue ? existingItemValue : hasValue();
38
- menuItems[group][label] = shouldReset ? false : value;
43
+ newMenuItems[group][label] = shouldReset ? false : value;
44
+ }); // Loop the known, previously registered items first to maintain menu order.
45
+
46
+ menuItemOrder.forEach(key => {
47
+ if (newMenuItems.default.hasOwnProperty(key)) {
48
+ menuItems.default[key] = newMenuItems.default[key];
49
+ }
50
+
51
+ if (newMenuItems.optional.hasOwnProperty(key)) {
52
+ menuItems.optional[key] = newMenuItems.optional[key];
53
+ }
54
+ }); // Loop newMenuItems object adding any that aren't in the known items order.
55
+
56
+ Object.keys(newMenuItems.default).forEach(key => {
57
+ if (!menuItems.default.hasOwnProperty(key)) {
58
+ menuItems.default[key] = newMenuItems.default[key];
59
+ }
60
+ });
61
+ Object.keys(newMenuItems.optional).forEach(key => {
62
+ if (!menuItems.optional.hasOwnProperty(key)) {
63
+ menuItems.optional[key] = newMenuItems.optional[key];
64
+ }
39
65
  });
40
66
  return menuItems;
41
67
  };
@@ -67,8 +93,10 @@ export function useToolsPanel(props) {
67
93
  }, [wasResetting]); // Allow panel items to register themselves.
68
94
 
69
95
  const [panelItems, setPanelItems] = useState([]);
96
+ const [menuItemOrder, setMenuItemOrder] = useState([]);
70
97
  const [resetAllFilters, setResetAllFilters] = useState([]);
71
98
  const registerPanelItem = useCallback(item => {
99
+ // Add item to panel items.
72
100
  setPanelItems(items => {
73
101
  const newItems = [...items]; // If an item with this label has already been registered, remove it
74
102
  // first. This can happen when an item is moved between the default
@@ -81,8 +109,17 @@ export function useToolsPanel(props) {
81
109
  }
82
110
 
83
111
  return [...newItems, item];
112
+ }); // Track the initial order of item registration. This is used for
113
+ // maintaining menu item order later.
114
+
115
+ setMenuItemOrder(items => {
116
+ if (items.includes(item.label)) {
117
+ return items;
118
+ }
119
+
120
+ return [...items, item.label];
84
121
  });
85
- }, [setPanelItems]); // Panels need to deregister on unmount to avoid orphans in menu state.
122
+ }, [setPanelItems, setMenuItemOrder]); // Panels need to deregister on unmount to avoid orphans in menu state.
86
123
  // This is an issue when panel items are being injected via SlotFills.
87
124
 
88
125
  const deregisterPanelItem = useCallback(label => {
@@ -122,11 +159,12 @@ export function useToolsPanel(props) {
122
159
  const items = generateMenuItems({
123
160
  panelItems,
124
161
  shouldReset: false,
125
- currentMenuItems: prevState
162
+ currentMenuItems: prevState,
163
+ menuItemOrder
126
164
  });
127
165
  return items;
128
166
  });
129
- }, [panelItems, setMenuItems]); // Force a menu item to be checked.
167
+ }, [panelItems, setMenuItems, menuItemOrder]); // Force a menu item to be checked.
130
168
  // This is intended for use with default panel items. They are displayed
131
169
  // separately to optional items and have different display states,
132
170
  // we need to update that when their value is customized.
@@ -189,10 +227,11 @@ export function useToolsPanel(props) {
189
227
 
190
228
  const resetMenuItems = generateMenuItems({
191
229
  panelItems,
230
+ menuItemOrder,
192
231
  shouldReset: true
193
232
  });
194
233
  setMenuItems(resetMenuItems);
195
- }, [panelItems, resetAllFilters, resetAll, setMenuItems]); // Assist ItemGroup styling when there are potentially hidden placeholder
234
+ }, [panelItems, resetAllFilters, resetAll, setMenuItems, menuItemOrder]); // Assist ItemGroup styling when there are potentially hidden placeholder
196
235
  // items by identifying first & last items that are toggled on for display.
197
236
 
198
237
  const getFirstVisibleItemLabel = items => {