@wordpress/components 23.6.0 → 23.7.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 (328) hide show
  1. package/CHANGELOG.md +32 -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 +14 -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/{color-list-picker → duotone-picker/color-list-picker}/index.js +5 -5
  43. package/build/duotone-picker/color-list-picker/index.js.map +1 -0
  44. package/build/duotone-picker/color-list-picker/types.js +6 -0
  45. package/build/duotone-picker/color-list-picker/types.js.map +1 -0
  46. package/build/duotone-picker/custom-duotone-bar.js.map +1 -1
  47. package/build/duotone-picker/duotone-picker.js +39 -2
  48. package/build/duotone-picker/duotone-picker.js.map +1 -1
  49. package/build/duotone-picker/duotone-swatch.js.map +1 -1
  50. package/build/duotone-picker/index.js.map +1 -1
  51. package/build/duotone-picker/types.js +6 -0
  52. package/build/duotone-picker/types.js.map +1 -0
  53. package/build/duotone-picker/utils.js +13 -11
  54. package/build/duotone-picker/utils.js.map +1 -1
  55. package/build/form-token-field/index.js +9 -3
  56. package/build/form-token-field/index.js.map +1 -1
  57. package/build/gradient-picker/index.js +61 -9
  58. package/build/gradient-picker/index.js.map +1 -1
  59. package/build/gradient-picker/types.js +6 -0
  60. package/build/gradient-picker/types.js.map +1 -0
  61. package/build/palette-edit/index.js +1 -2
  62. package/build/palette-edit/index.js.map +1 -1
  63. package/build/resizable-box/resize-tooltip/utils.js.map +1 -1
  64. package/build/sandbox/index.native.js +80 -67
  65. package/build/sandbox/index.native.js.map +1 -1
  66. package/build/tab-panel/index.js +1 -1
  67. package/build/tab-panel/index.js.map +1 -1
  68. package/build/tools-panel/tools-panel/hook.js +45 -6
  69. package/build/tools-panel/tools-panel/hook.js.map +1 -1
  70. package/build/utils/input/input-control.js +1 -1
  71. package/build/utils/input/input-control.js.map +1 -1
  72. package/build-module/angle-picker-control/angle-circle.js +1 -4
  73. package/build-module/angle-picker-control/angle-circle.js.map +1 -1
  74. package/build-module/angle-picker-control/index.js +12 -21
  75. package/build-module/angle-picker-control/index.js.map +1 -1
  76. package/build-module/angle-picker-control/styles/angle-picker-control-styles.js +20 -13
  77. package/build-module/angle-picker-control/styles/angle-picker-control-styles.js.map +1 -1
  78. package/build-module/animate/index.js +25 -17
  79. package/build-module/animate/index.js.map +1 -1
  80. package/build-module/box-control/axial-input-controls.js.map +1 -1
  81. package/build-module/color-picker/color-input.js +0 -4
  82. package/build-module/color-picker/color-input.js.map +1 -1
  83. package/build-module/color-picker/component.js +3 -3
  84. package/build-module/color-picker/component.js.map +1 -1
  85. package/build-module/color-picker/hex-input.js.map +1 -1
  86. package/build-module/color-picker/hsl-input.js.map +1 -1
  87. package/build-module/color-picker/input-with-slider.js.map +1 -1
  88. package/build-module/color-picker/legacy-adapter.js.map +1 -1
  89. package/build-module/color-picker/picker.js +4 -0
  90. package/build-module/color-picker/picker.js.map +1 -1
  91. package/build-module/color-picker/rgb-input.js.map +1 -1
  92. package/build-module/color-picker/use-deprecated-props.js.map +1 -1
  93. package/build-module/custom-gradient-picker/constants.js +1 -1
  94. package/build-module/custom-gradient-picker/constants.js.map +1 -1
  95. package/build-module/custom-gradient-picker/gradient-bar/constants.js.map +1 -1
  96. package/build-module/custom-gradient-picker/gradient-bar/control-points.js +9 -4
  97. package/build-module/custom-gradient-picker/gradient-bar/control-points.js.map +1 -1
  98. package/build-module/custom-gradient-picker/gradient-bar/index.js +14 -8
  99. package/build-module/custom-gradient-picker/gradient-bar/index.js.map +1 -1
  100. package/build-module/custom-gradient-picker/gradient-bar/utils.js +34 -54
  101. package/build-module/custom-gradient-picker/gradient-bar/utils.js.map +1 -1
  102. package/build-module/custom-gradient-picker/index.js +44 -17
  103. package/build-module/custom-gradient-picker/index.js.map +1 -1
  104. package/build-module/custom-gradient-picker/serializer.js +14 -4
  105. package/build-module/custom-gradient-picker/serializer.js.map +1 -1
  106. package/build-module/custom-gradient-picker/styles/custom-gradient-picker-styles.js +6 -6
  107. package/build-module/custom-gradient-picker/styles/custom-gradient-picker-styles.js.map +1 -1
  108. package/build-module/custom-gradient-picker/types.js +2 -0
  109. package/build-module/custom-gradient-picker/utils.js +17 -12
  110. package/build-module/custom-gradient-picker/utils.js.map +1 -1
  111. package/build-module/{color-list-picker → duotone-picker/color-list-picker}/index.js +5 -5
  112. package/build-module/duotone-picker/color-list-picker/index.js.map +1 -0
  113. package/build-module/duotone-picker/color-list-picker/types.js +2 -0
  114. package/build-module/duotone-picker/color-list-picker/types.js.map +1 -0
  115. package/build-module/duotone-picker/custom-duotone-bar.js.map +1 -1
  116. package/build-module/duotone-picker/duotone-picker.js +38 -2
  117. package/build-module/duotone-picker/duotone-picker.js.map +1 -1
  118. package/build-module/duotone-picker/duotone-swatch.js.map +1 -1
  119. package/build-module/duotone-picker/index.js.map +1 -1
  120. package/build-module/duotone-picker/types.js +2 -0
  121. package/build-module/duotone-picker/types.js.map +1 -0
  122. package/build-module/duotone-picker/utils.js +17 -11
  123. package/build-module/duotone-picker/utils.js.map +1 -1
  124. package/build-module/form-token-field/index.js +9 -4
  125. package/build-module/form-token-field/index.js.map +1 -1
  126. package/build-module/gradient-picker/index.js +61 -10
  127. package/build-module/gradient-picker/index.js.map +1 -1
  128. package/build-module/gradient-picker/types.js +2 -0
  129. package/build-module/gradient-picker/types.js.map +1 -0
  130. package/build-module/palette-edit/index.js +1 -2
  131. package/build-module/palette-edit/index.js.map +1 -1
  132. package/build-module/resizable-box/resize-tooltip/utils.js.map +1 -1
  133. package/build-module/sandbox/index.native.js +70 -58
  134. package/build-module/sandbox/index.native.js.map +1 -1
  135. package/build-module/tab-panel/index.js +2 -2
  136. package/build-module/tab-panel/index.js.map +1 -1
  137. package/build-module/tools-panel/tools-panel/hook.js +45 -6
  138. package/build-module/tools-panel/tools-panel/hook.js.map +1 -1
  139. package/build-module/utils/input/input-control.js +1 -1
  140. package/build-module/utils/input/input-control.js.map +1 -1
  141. package/build-style/style-rtl.css +40 -28
  142. package/build-style/style.css +42 -28
  143. package/build-types/angle-picker-control/angle-circle.d.ts.map +1 -1
  144. package/build-types/angle-picker-control/index.d.ts.map +1 -1
  145. package/build-types/angle-picker-control/styles/angle-picker-control-styles.d.ts +5 -0
  146. package/build-types/angle-picker-control/styles/angle-picker-control-styles.d.ts.map +1 -1
  147. package/build-types/animate/index.d.ts +27 -22
  148. package/build-types/animate/index.d.ts.map +1 -1
  149. package/build-types/animate/stories/index.d.ts +18 -0
  150. package/build-types/animate/stories/index.d.ts.map +1 -0
  151. package/build-types/animate/types.d.ts +30 -0
  152. package/build-types/animate/types.d.ts.map +1 -0
  153. package/build-types/color-picker/color-input.d.ts +1 -11
  154. package/build-types/color-picker/color-input.d.ts.map +1 -1
  155. package/build-types/color-picker/component.d.ts +8 -9
  156. package/build-types/color-picker/component.d.ts.map +1 -1
  157. package/build-types/color-picker/hex-input.d.ts +1 -10
  158. package/build-types/color-picker/hex-input.d.ts.map +1 -1
  159. package/build-types/color-picker/hsl-input.d.ts +1 -10
  160. package/build-types/color-picker/hsl-input.d.ts.map +1 -1
  161. package/build-types/color-picker/input-with-slider.d.ts +1 -9
  162. package/build-types/color-picker/input-with-slider.d.ts.map +1 -1
  163. package/build-types/color-picker/legacy-adapter.d.ts +1 -3
  164. package/build-types/color-picker/legacy-adapter.d.ts.map +1 -1
  165. package/build-types/color-picker/picker.d.ts +4 -7
  166. package/build-types/color-picker/picker.d.ts.map +1 -1
  167. package/build-types/color-picker/rgb-input.d.ts +1 -10
  168. package/build-types/color-picker/rgb-input.d.ts.map +1 -1
  169. package/build-types/color-picker/stories/index.d.ts +19 -0
  170. package/build-types/color-picker/stories/index.d.ts.map +1 -0
  171. package/build-types/color-picker/test/index.d.ts +2 -0
  172. package/build-types/color-picker/test/index.d.ts.map +1 -0
  173. package/build-types/color-picker/types.d.ts +105 -1
  174. package/build-types/color-picker/types.d.ts.map +1 -1
  175. package/build-types/color-picker/use-deprecated-props.d.ts +1 -44
  176. package/build-types/color-picker/use-deprecated-props.d.ts.map +1 -1
  177. package/build-types/custom-gradient-picker/constants.d.ts +8 -8
  178. package/build-types/custom-gradient-picker/constants.d.ts.map +1 -1
  179. package/build-types/custom-gradient-picker/gradient-bar/constants.d.ts +7 -7
  180. package/build-types/custom-gradient-picker/gradient-bar/constants.d.ts.map +1 -1
  181. package/build-types/custom-gradient-picker/gradient-bar/control-points.d.ts +5 -22
  182. package/build-types/custom-gradient-picker/gradient-bar/control-points.d.ts.map +1 -1
  183. package/build-types/custom-gradient-picker/gradient-bar/index.d.ts +3 -9
  184. package/build-types/custom-gradient-picker/gradient-bar/index.d.ts.map +1 -1
  185. package/build-types/custom-gradient-picker/gradient-bar/test/utils.d.ts +2 -0
  186. package/build-types/custom-gradient-picker/gradient-bar/test/utils.d.ts.map +1 -0
  187. package/build-types/custom-gradient-picker/gradient-bar/utils.d.ts +44 -92
  188. package/build-types/custom-gradient-picker/gradient-bar/utils.d.ts.map +1 -1
  189. package/build-types/custom-gradient-picker/index.d.ts +27 -6
  190. package/build-types/custom-gradient-picker/index.d.ts.map +1 -1
  191. package/build-types/custom-gradient-picker/serializer.d.ts +13 -16
  192. package/build-types/custom-gradient-picker/serializer.d.ts.map +1 -1
  193. package/build-types/custom-gradient-picker/stories/index.d.ts +12 -0
  194. package/build-types/custom-gradient-picker/stories/index.d.ts.map +1 -0
  195. package/build-types/custom-gradient-picker/styles/custom-gradient-picker-styles.d.ts +3 -2
  196. package/build-types/custom-gradient-picker/styles/custom-gradient-picker-styles.d.ts.map +1 -1
  197. package/build-types/custom-gradient-picker/test/serializer.d.ts +2 -0
  198. package/build-types/custom-gradient-picker/test/serializer.d.ts.map +1 -0
  199. package/build-types/custom-gradient-picker/types.d.ts +120 -0
  200. package/build-types/custom-gradient-picker/types.d.ts.map +1 -0
  201. package/build-types/custom-gradient-picker/utils.d.ts +12 -4
  202. package/build-types/custom-gradient-picker/utils.d.ts.map +1 -1
  203. package/build-types/duotone-picker/color-list-picker/index.d.ts.map +1 -0
  204. package/build-types/{color-list-picker → duotone-picker/color-list-picker}/types.d.ts +2 -2
  205. package/build-types/duotone-picker/color-list-picker/types.d.ts.map +1 -0
  206. package/build-types/duotone-picker/custom-duotone-bar.d.ts +6 -0
  207. package/build-types/duotone-picker/custom-duotone-bar.d.ts.map +1 -0
  208. package/build-types/duotone-picker/duotone-picker.d.ts +38 -0
  209. package/build-types/duotone-picker/duotone-picker.d.ts.map +1 -0
  210. package/build-types/duotone-picker/duotone-swatch.d.ts +5 -0
  211. package/build-types/duotone-picker/duotone-swatch.d.ts.map +1 -0
  212. package/build-types/duotone-picker/index.d.ts +3 -0
  213. package/build-types/duotone-picker/index.d.ts.map +1 -0
  214. package/build-types/duotone-picker/stories/duotone-picker.d.ts +12 -0
  215. package/build-types/duotone-picker/stories/duotone-picker.d.ts.map +1 -0
  216. package/build-types/duotone-picker/stories/duotone-swatch.d.ts +14 -0
  217. package/build-types/duotone-picker/stories/duotone-swatch.d.ts.map +1 -0
  218. package/build-types/duotone-picker/types.d.ts +60 -0
  219. package/build-types/duotone-picker/types.d.ts.map +1 -0
  220. package/build-types/duotone-picker/utils.d.ts +52 -0
  221. package/build-types/duotone-picker/utils.d.ts.map +1 -0
  222. package/build-types/form-token-field/index.d.ts.map +1 -1
  223. package/build-types/form-token-field/types.d.ts +6 -0
  224. package/build-types/form-token-field/types.d.ts.map +1 -1
  225. package/build-types/gradient-picker/index.d.ts +49 -11
  226. package/build-types/gradient-picker/index.d.ts.map +1 -1
  227. package/build-types/gradient-picker/stories/index.d.ts +14 -0
  228. package/build-types/gradient-picker/stories/index.d.ts.map +1 -0
  229. package/build-types/gradient-picker/types.d.ts +87 -0
  230. package/build-types/gradient-picker/types.d.ts.map +1 -0
  231. package/build-types/palette-edit/index.d.ts.map +1 -1
  232. package/build-types/resizable-box/resize-tooltip/utils.d.ts +1 -1
  233. package/build-types/resizable-box/resize-tooltip/utils.d.ts.map +1 -1
  234. package/build-types/tab-panel/index.d.ts.map +1 -1
  235. package/build-types/tools-panel/tools-panel/hook.d.ts.map +1 -1
  236. package/build-types/tools-panel/types.d.ts +1 -0
  237. package/build-types/tools-panel/types.d.ts.map +1 -1
  238. package/build-types/utils/input/input-control.d.ts.map +1 -1
  239. package/package.json +19 -19
  240. package/src/angle-picker-control/angle-circle.tsx +0 -1
  241. package/src/angle-picker-control/index.tsx +14 -27
  242. package/src/angle-picker-control/styles/angle-picker-control-styles.tsx +16 -9
  243. package/src/animate/index.tsx +75 -0
  244. package/src/animate/stories/index.tsx +102 -0
  245. package/src/animate/types.ts +32 -0
  246. package/src/border-box-control/stories/index.tsx +1 -1
  247. package/src/box-control/axial-input-controls.tsx +1 -1
  248. package/src/circular-option-picker/style.scss +10 -0
  249. package/src/color-indicator/style.scss +1 -0
  250. package/src/color-picker/README.md +2 -2
  251. package/src/color-picker/color-input.tsx +1 -12
  252. package/src/color-picker/component.tsx +9 -18
  253. package/src/color-picker/hex-input.tsx +2 -7
  254. package/src/color-picker/hsl-input.tsx +2 -7
  255. package/src/color-picker/input-with-slider.tsx +1 -9
  256. package/src/color-picker/legacy-adapter.tsx +1 -2
  257. package/src/color-picker/picker.tsx +5 -6
  258. package/src/color-picker/rgb-input.tsx +2 -7
  259. package/src/color-picker/stories/index.tsx +51 -0
  260. package/src/color-picker/test/{index.js → index.tsx} +36 -18
  261. package/src/color-picker/types.ts +128 -1
  262. package/src/color-picker/use-deprecated-props.ts +2 -53
  263. package/src/combobox-control/stories/index.tsx +1 -1
  264. package/src/custom-gradient-picker/{constants.js → constants.ts} +2 -2
  265. package/src/custom-gradient-picker/gradient-bar/{control-points.js → control-points.tsx} +171 -134
  266. package/src/custom-gradient-picker/gradient-bar/{index.js → index.tsx} +32 -10
  267. package/src/custom-gradient-picker/gradient-bar/test/{utils.js → utils.ts} +58 -31
  268. package/src/custom-gradient-picker/gradient-bar/utils.ts +193 -0
  269. package/src/custom-gradient-picker/{index.js → index.tsx} +63 -22
  270. package/src/custom-gradient-picker/serializer.ts +82 -0
  271. package/src/custom-gradient-picker/stories/index.tsx +45 -0
  272. package/src/custom-gradient-picker/style.scss +25 -4
  273. package/src/custom-gradient-picker/test/{serializer.js → serializer.ts} +39 -33
  274. package/src/custom-gradient-picker/types.ts +137 -0
  275. package/src/custom-gradient-picker/{utils.js → utils.ts} +37 -22
  276. package/src/custom-select-control/test/index.js +6 -4
  277. package/src/{color-list-picker → duotone-picker/color-list-picker}/index.tsx +7 -6
  278. package/src/{color-list-picker → duotone-picker/color-list-picker}/types.ts +2 -2
  279. package/src/duotone-picker/{custom-duotone-bar.js → custom-duotone-bar.tsx} +7 -1
  280. package/src/duotone-picker/{duotone-picker.js → duotone-picker.tsx} +39 -2
  281. package/src/duotone-picker/{duotone-swatch.js → duotone-swatch.tsx} +2 -1
  282. package/src/duotone-picker/stories/{duotone-picker.js → duotone-picker.tsx} +15 -8
  283. package/src/duotone-picker/stories/{duotone-swatch.js → duotone-swatch.tsx} +9 -3
  284. package/src/duotone-picker/types.ts +61 -0
  285. package/src/duotone-picker/{utils.js → utils.ts} +29 -14
  286. package/src/flex/flex-item/README.md +1 -1
  287. package/src/form-token-field/README.md +1 -0
  288. package/src/form-token-field/index.tsx +10 -3
  289. package/src/form-token-field/style.scss +0 -7
  290. package/src/form-token-field/test/index.tsx +1 -0
  291. package/src/form-token-field/types.ts +6 -0
  292. package/src/gradient-picker/README.md +16 -23
  293. package/src/gradient-picker/{index.js → index.tsx} +70 -16
  294. package/src/gradient-picker/stories/{index.js → index.tsx} +19 -8
  295. package/src/gradient-picker/types.ts +89 -0
  296. package/src/item-group/test/index.js +5 -3
  297. package/src/palette-edit/index.tsx +4 -5
  298. package/src/resizable-box/resize-tooltip/utils.ts +1 -1
  299. package/src/sandbox/index.native.js +71 -78
  300. package/src/slot-fill/test/slot.js +8 -6
  301. package/src/style.scss +1 -1
  302. package/src/tab-panel/index.tsx +7 -2
  303. package/src/tools-panel/test/index.tsx +86 -0
  304. package/src/tools-panel/tools-panel/hook.ts +44 -4
  305. package/src/tools-panel/types.ts +1 -0
  306. package/src/tooltip/test/index.js +251 -301
  307. package/src/utils/input/input-control.js +1 -0
  308. package/tsconfig.json +1 -2
  309. package/tsconfig.tsbuildinfo +1 -1
  310. package/build/color-list-picker/index.js.map +0 -1
  311. package/build-module/color-list-picker/index.js.map +0 -1
  312. package/build-types/color-list-picker/index.d.ts.map +0 -1
  313. package/build-types/color-list-picker/types.d.ts.map +0 -1
  314. package/src/animate/index.js +0 -60
  315. package/src/animate/stories/index.js +0 -53
  316. package/src/color-picker/stories/index.js +0 -41
  317. package/src/custom-gradient-picker/gradient-bar/utils.js +0 -189
  318. package/src/custom-gradient-picker/serializer.js +0 -48
  319. package/src/custom-gradient-picker/stories/index.js +0 -33
  320. /package/build/{color-list-picker → animate}/types.js +0 -0
  321. /package/build-module/{color-list-picker → animate}/types.js +0 -0
  322. /package/build-module/{color-list-picker → animate}/types.js.map +0 -0
  323. /package/{build/color-list-picker → build-module/custom-gradient-picker}/types.js.map +0 -0
  324. /package/build-types/{color-list-picker → duotone-picker/color-list-picker}/index.d.ts +0 -0
  325. /package/src/custom-gradient-picker/gradient-bar/{constants.js → constants.ts} +0 -0
  326. /package/src/custom-gradient-picker/styles/{custom-gradient-picker-styles.js → custom-gradient-picker-styles.tsx} +0 -0
  327. /package/src/{color-list-picker → duotone-picker/color-list-picker}/style.scss +0 -0
  328. /package/src/duotone-picker/{index.js → index.ts} +0 -0
@@ -22,85 +22,85 @@ import { usePreferredColorScheme } from '@wordpress/compose';
22
22
  */
23
23
  import sandboxStyles from './style.scss';
24
24
 
25
- const observeAndResizeJS = function () {
26
- // Hermes requires a special directive to preserve the original source code
27
- // when using `Function.prototype.toString()` below.
28
- // https://github.com/facebook/hermes/issues/114#issuecomment-887106990
29
- 'show source';
30
- const { MutationObserver } = window;
31
-
32
- if ( ! MutationObserver || ! document.body || ! window.parent ) {
33
- return;
34
- }
25
+ const observeAndResizeJS = `
26
+ (function() {
27
+ const { MutationObserver } = window;
35
28
 
36
- function sendResize() {
37
- const clientBoundingRect = document.body.getBoundingClientRect();
38
-
39
- // The function postMessage is exposed by the react-native-webview library
40
- // to communicate between React Native and the WebView, in this case,
41
- // we use it for notifying resize changes.
42
- window.ReactNativeWebView.postMessage(
43
- JSON.stringify( {
44
- action: 'resize',
45
- width: clientBoundingRect.width,
46
- height: clientBoundingRect.height,
47
- } )
48
- );
49
- }
29
+ if ( ! MutationObserver || ! document.body || ! window.parent ) {
30
+ return;
31
+ }
50
32
 
51
- const observer = new MutationObserver( sendResize );
52
- observer.observe( document.body, {
53
- attributes: true,
54
- attributeOldValue: false,
55
- characterData: true,
56
- characterDataOldValue: false,
57
- childList: true,
58
- subtree: true,
59
- } );
33
+ function sendResize() {
34
+ const clientBoundingRect = document.body.getBoundingClientRect();
35
+
36
+ // The function postMessage is exposed by the react-native-webview library
37
+ // to communicate between React Native and the WebView, in this case,
38
+ // we use it for notifying resize changes.
39
+ window.ReactNativeWebView.postMessage(
40
+ JSON.stringify( {
41
+ action: 'resize',
42
+ width: clientBoundingRect.width,
43
+ height: clientBoundingRect.height,
44
+ } )
45
+ );
46
+ }
60
47
 
61
- window.addEventListener( 'load', sendResize, true );
62
-
63
- // Hack: Remove viewport unit styles, as these are relative
64
- // the iframe root and interfere with our mechanism for
65
- // determining the unconstrained page bounds.
66
- function removeViewportStyles( ruleOrNode ) {
67
- if ( ruleOrNode.style ) {
68
- [ 'width', 'height', 'minHeight', 'maxHeight' ].forEach( function (
69
- style
70
- ) {
71
- if (
72
- /^\\d+(vmin|vmax|vh|vw)$/.test( ruleOrNode.style[ style ] )
48
+ const observer = new MutationObserver( sendResize );
49
+ observer.observe( document.body, {
50
+ attributes: true,
51
+ attributeOldValue: false,
52
+ characterData: true,
53
+ characterDataOldValue: false,
54
+ childList: true,
55
+ subtree: true,
56
+ } );
57
+
58
+ window.addEventListener( 'load', sendResize, true );
59
+
60
+ // Hack: Remove viewport unit styles, as these are relative
61
+ // the iframe root and interfere with our mechanism for
62
+ // determining the unconstrained page bounds.
63
+ function removeViewportStyles( ruleOrNode ) {
64
+ if ( ruleOrNode.style ) {
65
+ [ 'width', 'height', 'minHeight', 'maxHeight' ].forEach( function (
66
+ style
73
67
  ) {
74
- ruleOrNode.style[ style ] = '';
75
- }
76
- } );
68
+ if (
69
+ /^\\d+(vmin|vmax|vh|vw)$/.test( ruleOrNode.style[ style ] )
70
+ ) {
71
+ ruleOrNode.style[ style ] = '';
72
+ }
73
+ } );
74
+ }
77
75
  }
78
- }
79
76
 
80
- Array.prototype.forEach.call(
81
- document.querySelectorAll( '[style]' ),
82
- removeViewportStyles
83
- );
84
- Array.prototype.forEach.call(
85
- document.styleSheets,
86
- function ( stylesheet ) {
87
- Array.prototype.forEach.call(
88
- stylesheet.cssRules || stylesheet.rules,
89
- removeViewportStyles
90
- );
91
- }
92
- );
77
+ Array.prototype.forEach.call(
78
+ document.querySelectorAll( '[style]' ),
79
+ removeViewportStyles
80
+ );
81
+ Array.prototype.forEach.call(
82
+ document.styleSheets,
83
+ function ( stylesheet ) {
84
+ Array.prototype.forEach.call(
85
+ stylesheet.cssRules || stylesheet.rules,
86
+ removeViewportStyles
87
+ );
88
+ }
89
+ );
93
90
 
94
- document.body.style.position = 'absolute';
95
- document.body.style.width = '100%';
96
- document.body.setAttribute( 'data-resizable-iframe-connected', '' );
91
+ document.body.style.position = 'absolute';
92
+ document.body.style.width = '100%';
93
+ document.body.setAttribute( 'data-resizable-iframe-connected', '' );
97
94
 
98
- sendResize();
95
+ sendResize();
99
96
 
100
- // Resize events can change the width of elements with 100% width, but we don't
101
- // get an DOM mutations for that, so do the resize when the window is resized, too.
102
- window.addEventListener( 'resize', sendResize, true );
103
- };
97
+ // Resize events can change the width of elements with 100% width, but we don't
98
+ // get an DOM mutations for that, so do the resize when the window is resized, too.
99
+ window.addEventListener( 'resize', sendResize, true );
100
+ window.addEventListener( 'orientationchange', sendResize, true );
101
+ widow.addEventListener( 'click', sendResize, true );
102
+ })();
103
+ `;
104
104
 
105
105
  const style = `
106
106
  body {
@@ -230,14 +230,6 @@ function Sandbox( {
230
230
  className={ type }
231
231
  >
232
232
  <div dangerouslySetInnerHTML={ { __html: html } } />
233
- <script
234
- type="text/javascript"
235
- dangerouslySetInnerHTML={ {
236
- __html:
237
- customJS ||
238
- `(${ observeAndResizeJS.toString() })();`,
239
- } }
240
- />
241
233
  { scripts.map( ( src ) => (
242
234
  <script key={ src } src={ src } />
243
235
  ) ) }
@@ -322,6 +314,7 @@ function Sandbox( {
322
314
  sandboxStyles[ 'sandbox-webview__container' ],
323
315
  containerStyle,
324
316
  ] }
317
+ injectedJavaScript={ customJS || observeAndResizeJS }
325
318
  key={ key }
326
319
  ref={ ref }
327
320
  source={ { baseUrl: providerUrl, html: contentHtml } }
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import { render, fireEvent, screen } from '@testing-library/react';
4
+ import { render, screen } from '@testing-library/react';
5
+ import userEvent from '@testing-library/user-event';
5
6
 
6
7
  /**
7
8
  * Internal dependencies
@@ -92,9 +93,9 @@ describe( 'Slot', () => {
92
93
  expect( container ).toMatchSnapshot();
93
94
  } );
94
95
 
95
- it( 'calls the functions passed as the Slot’s fillProps in the Fill', () => {
96
+ it( 'calls the functions passed as the Slot’s fillProps in the Fill', async () => {
96
97
  const onClose = jest.fn();
97
-
98
+ const user = userEvent.setup();
98
99
  render(
99
100
  <Provider>
100
101
  <Slot name="chicken" fillProps={ { onClose } } />
@@ -108,7 +109,7 @@ describe( 'Slot', () => {
108
109
  </Provider>
109
110
  );
110
111
 
111
- fireEvent.click( screen.getByText( 'Click me' ) );
112
+ await user.click( screen.getByText( 'Click me' ) );
112
113
 
113
114
  expect( onClose ).toHaveBeenCalledTimes( 1 );
114
115
  } );
@@ -149,7 +150,8 @@ describe( 'Slot', () => {
149
150
  expect( container ).toMatchSnapshot();
150
151
  } );
151
152
 
152
- it( 'should re-render Slot when not bubbling virtually', () => {
153
+ it( 'should re-render Slot when not bubbling virtually', async () => {
154
+ const user = userEvent.setup();
153
155
  const { container } = render(
154
156
  <Provider>
155
157
  <div>
@@ -161,7 +163,7 @@ describe( 'Slot', () => {
161
163
 
162
164
  expect( container ).toMatchSnapshot();
163
165
 
164
- fireEvent.click( screen.getByRole( 'button' ) );
166
+ await user.click( screen.getByRole( 'button' ) );
165
167
 
166
168
  expect( container ).toMatchSnapshot();
167
169
  } );
package/src/style.scss CHANGED
@@ -11,7 +11,6 @@
11
11
  @import "./palette-edit/style.scss";
12
12
  @import "./color-indicator/style.scss";
13
13
  @import "./combobox-control/style.scss";
14
- @import "./color-list-picker/style.scss";
15
14
  @import "./color-palette/style.scss";
16
15
  @import "./custom-gradient-picker/style.scss";
17
16
  @import "./custom-select-control/style.scss";
@@ -21,6 +20,7 @@
21
20
  @import "./dropdown/style.scss";
22
21
  @import "./dropdown-menu/style.scss";
23
22
  @import "./duotone-picker/style.scss";
23
+ @import "./duotone-picker/color-list-picker/style.scss";
24
24
  @import "./form-toggle/style.scss";
25
25
  @import "./form-token-field/style.scss";
26
26
  @import "./guide/style.scss";
@@ -6,7 +6,12 @@ import classnames from 'classnames';
6
6
  /**
7
7
  * WordPress dependencies
8
8
  */
9
- import { useState, useEffect, useCallback } from '@wordpress/element';
9
+ import {
10
+ useState,
11
+ useEffect,
12
+ useLayoutEffect,
13
+ useCallback,
14
+ } from '@wordpress/element';
10
15
  import { useInstanceId } from '@wordpress/compose';
11
16
 
12
17
  /**
@@ -104,7 +109,7 @@ export function TabPanel( {
104
109
  const selectedId = `${ instanceId }-${ selectedTab?.name ?? 'none' }`;
105
110
 
106
111
  // Handle selecting the initial tab.
107
- useEffect( () => {
112
+ useLayoutEffect( () => {
108
113
  // If there's a selected tab, don't override it.
109
114
  if ( selectedTab ) {
110
115
  return;
@@ -954,6 +954,92 @@ describe( 'ToolsPanel', () => {
954
954
  expect( items[ 1 ] ).toHaveTextContent( 'Item 2' );
955
955
  } );
956
956
 
957
+ it( 'should maintain menu item order', async () => {
958
+ const InconsistentItems = () => (
959
+ <ToolsPanelItems>
960
+ <ToolsPanelItem
961
+ label="Item 1"
962
+ hasValue={ () => false }
963
+ isShownByDefault
964
+ >
965
+ <div>Item 1</div>
966
+ </ToolsPanelItem>
967
+ <ToolsPanelItem
968
+ label="Item 2"
969
+ hasValue={ () => false }
970
+ isShownByDefault
971
+ >
972
+ <div>Item 2</div>
973
+ </ToolsPanelItem>
974
+ </ToolsPanelItems>
975
+ );
976
+
977
+ const { rerender } = render(
978
+ <SlotFillProvider>
979
+ <InconsistentItems key="order-test-step-1" />
980
+ <ToolsPanelItems>
981
+ <ToolsPanelItem
982
+ label="Item 3"
983
+ hasValue={ () => false }
984
+ isShownByDefault
985
+ >
986
+ <div>Item 3</div>
987
+ </ToolsPanelItem>
988
+ </ToolsPanelItems>
989
+ <ToolsPanel { ...defaultProps }>
990
+ <Slot />
991
+ </ToolsPanel>
992
+ </SlotFillProvider>
993
+ );
994
+
995
+ // Open dropdown menu.
996
+ const user = userEvent.setup();
997
+ let menuButton = getMenuButton();
998
+ await user.click( menuButton );
999
+
1000
+ // Confirm all the existing menu items are present and in the
1001
+ // expected order.
1002
+ let menuItems = await screen.findAllByRole( 'menuitemcheckbox' );
1003
+
1004
+ expect( menuItems.length ).toEqual( 3 );
1005
+ expect( menuItems[ 0 ] ).toHaveTextContent( 'Item 1' );
1006
+ expect( menuItems[ 1 ] ).toHaveTextContent( 'Item 2' );
1007
+ expect( menuItems[ 2 ] ).toHaveTextContent( 'Item 3' );
1008
+
1009
+ // Close the dropdown menu.
1010
+ await user.click( menuButton );
1011
+
1012
+ rerender(
1013
+ <SlotFillProvider>
1014
+ <InconsistentItems key="order-test-step-2" />
1015
+ <ToolsPanelItems>
1016
+ <ToolsPanelItem
1017
+ label="Item 3"
1018
+ hasValue={ () => false }
1019
+ isShownByDefault
1020
+ >
1021
+ <div>Item 3</div>
1022
+ </ToolsPanelItem>
1023
+ </ToolsPanelItems>
1024
+ <ToolsPanel { ...defaultProps }>
1025
+ <Slot />
1026
+ </ToolsPanel>
1027
+ </SlotFillProvider>
1028
+ );
1029
+
1030
+ // Reopen dropdown menu.
1031
+ menuButton = getMenuButton();
1032
+ await user.click( menuButton );
1033
+
1034
+ // Confirm the menu item order has been maintained.
1035
+ menuItems = await screen.findAllByRole( 'menuitemcheckbox' );
1036
+
1037
+ expect( menuItems.length ).toEqual( 3 );
1038
+ expect( menuItems[ 0 ] ).toHaveTextContent( 'Item 1' );
1039
+ expect( menuItems[ 1 ] ).toHaveTextContent( 'Item 2' );
1040
+ expect( menuItems[ 2 ] ).toHaveTextContent( 'Item 3' );
1041
+ } );
1042
+
957
1043
  it( 'should not trigger callback when fill has not updated yet when panel has', () => {
958
1044
  // Fill provided controls can update independently to the panel.
959
1045
  // A `panelId` prop was added to both panels and items
@@ -30,7 +30,9 @@ const generateMenuItems = ( {
30
30
  panelItems,
31
31
  shouldReset,
32
32
  currentMenuItems,
33
+ menuItemOrder,
33
34
  }: ToolsPanelMenuItemsConfig ) => {
35
+ const newMenuItems: ToolsPanelMenuItems = { default: {}, optional: {} };
34
36
  const menuItems: ToolsPanelMenuItems = { default: {}, optional: {} };
35
37
 
36
38
  panelItems.forEach( ( { hasValue, isShownByDefault, label } ) => {
@@ -42,7 +44,31 @@ const generateMenuItems = ( {
42
44
  const existingItemValue = currentMenuItems?.[ group ]?.[ label ];
43
45
  const value = existingItemValue ? existingItemValue : hasValue();
44
46
 
45
- menuItems[ group ][ label ] = shouldReset ? false : value;
47
+ newMenuItems[ group ][ label ] = shouldReset ? false : value;
48
+ } );
49
+
50
+ // Loop the known, previously registered items first to maintain menu order.
51
+ menuItemOrder.forEach( ( key ) => {
52
+ if ( newMenuItems.default.hasOwnProperty( key ) ) {
53
+ menuItems.default[ key ] = newMenuItems.default[ key ];
54
+ }
55
+
56
+ if ( newMenuItems.optional.hasOwnProperty( key ) ) {
57
+ menuItems.optional[ key ] = newMenuItems.optional[ key ];
58
+ }
59
+ } );
60
+
61
+ // Loop newMenuItems object adding any that aren't in the known items order.
62
+ Object.keys( newMenuItems.default ).forEach( ( key ) => {
63
+ if ( ! menuItems.default.hasOwnProperty( key ) ) {
64
+ menuItems.default[ key ] = newMenuItems.default[ key ];
65
+ }
66
+ } );
67
+
68
+ Object.keys( newMenuItems.optional ).forEach( ( key ) => {
69
+ if ( ! menuItems.optional.hasOwnProperty( key ) ) {
70
+ menuItems.optional[ key ] = newMenuItems.optional[ key ];
71
+ }
46
72
  } );
47
73
 
48
74
  return menuItems;
@@ -82,12 +108,14 @@ export function useToolsPanel(
82
108
 
83
109
  // Allow panel items to register themselves.
84
110
  const [ panelItems, setPanelItems ] = useState< ToolsPanelItem[] >( [] );
111
+ const [ menuItemOrder, setMenuItemOrder ] = useState< string[] >( [] );
85
112
  const [ resetAllFilters, setResetAllFilters ] = useState<
86
113
  ResetAllFilter[]
87
114
  >( [] );
88
115
 
89
116
  const registerPanelItem = useCallback(
90
117
  ( item: ToolsPanelItem ) => {
118
+ // Add item to panel items.
91
119
  setPanelItems( ( items ) => {
92
120
  const newItems = [ ...items ];
93
121
  // If an item with this label has already been registered, remove it
@@ -101,8 +129,18 @@ export function useToolsPanel(
101
129
  }
102
130
  return [ ...newItems, item ];
103
131
  } );
132
+
133
+ // Track the initial order of item registration. This is used for
134
+ // maintaining menu item order later.
135
+ setMenuItemOrder( ( items ) => {
136
+ if ( items.includes( item.label ) ) {
137
+ return items;
138
+ }
139
+
140
+ return [ ...items, item.label ];
141
+ } );
104
142
  },
105
- [ setPanelItems ]
143
+ [ setPanelItems, setMenuItemOrder ]
106
144
  );
107
145
 
108
146
  // Panels need to deregister on unmount to avoid orphans in menu state.
@@ -160,10 +198,11 @@ export function useToolsPanel(
160
198
  panelItems,
161
199
  shouldReset: false,
162
200
  currentMenuItems: prevState,
201
+ menuItemOrder,
163
202
  } );
164
203
  return items;
165
204
  } );
166
- }, [ panelItems, setMenuItems ] );
205
+ }, [ panelItems, setMenuItems, menuItemOrder ] );
167
206
 
168
207
  // Force a menu item to be checked.
169
208
  // This is intended for use with default panel items. They are displayed
@@ -267,10 +306,11 @@ export function useToolsPanel(
267
306
  // Turn off display of all non-default items.
268
307
  const resetMenuItems = generateMenuItems( {
269
308
  panelItems,
309
+ menuItemOrder,
270
310
  shouldReset: true,
271
311
  } );
272
312
  setMenuItems( resetMenuItems );
273
- }, [ panelItems, resetAllFilters, resetAll, setMenuItems ] );
313
+ }, [ panelItems, resetAllFilters, resetAll, setMenuItems, menuItemOrder ] );
274
314
 
275
315
  // Assist ItemGroup styling when there are potentially hidden placeholder
276
316
  // items by identifying first & last items that are toggled on for display.
@@ -187,4 +187,5 @@ export type ToolsPanelMenuItemsConfig = {
187
187
  panelItems: ToolsPanelItem[];
188
188
  shouldReset: boolean;
189
189
  currentMenuItems?: ToolsPanelMenuItems;
190
+ menuItemOrder: string[];
190
191
  };