@wordpress/block-library 8.9.0 → 8.11.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 (502) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/build/block/edit.native.js +17 -10
  3. package/build/block/edit.native.js.map +1 -1
  4. package/build/code/index.js +1 -0
  5. package/build/code/index.js.map +1 -1
  6. package/build/column/index.js +1 -1
  7. package/build/columns/transforms.js +1 -5
  8. package/build/columns/transforms.js.map +1 -1
  9. package/build/comment-author-name/edit.js +1 -1
  10. package/build/comment-author-name/edit.js.map +1 -1
  11. package/build/comment-edit-link/edit.js +1 -1
  12. package/build/comment-edit-link/edit.js.map +1 -1
  13. package/build/cover/edit/inspector-controls.js +1 -1
  14. package/build/cover/edit/inspector-controls.js.map +1 -1
  15. package/build/cover/edit/resizable-cover-popover.js +3 -3
  16. package/build/cover/edit/resizable-cover-popover.js.map +1 -1
  17. package/build/cover/index.js +1 -1
  18. package/build/cover/variations.js +1 -1
  19. package/build/cover/variations.js.map +1 -1
  20. package/build/details/edit.js +19 -5
  21. package/build/details/edit.js.map +1 -1
  22. package/build/details/index.js +14 -10
  23. package/build/details/index.js.map +1 -1
  24. package/build/details/save.js +4 -1
  25. package/build/details/save.js.map +1 -1
  26. package/build/embed/variations.js +2 -2
  27. package/build/embed/variations.js.map +1 -1
  28. package/build/file/interactivity.js +19 -0
  29. package/build/file/interactivity.js.map +1 -0
  30. package/build/file/{utils.js → utils/index.js} +1 -1
  31. package/build/file/utils/index.js.map +1 -0
  32. package/build/file/view.js +1 -1
  33. package/build/file/view.js.map +1 -1
  34. package/build/freeform/modal.js +20 -17
  35. package/build/freeform/modal.js.map +1 -1
  36. package/build/gallery/edit.js +2 -8
  37. package/build/gallery/edit.js.map +1 -1
  38. package/build/gallery/v1/edit.js +1 -7
  39. package/build/gallery/v1/edit.js.map +1 -1
  40. package/build/gallery/v1/gallery-image.native.js +1 -3
  41. package/build/gallery/v1/gallery-image.native.js.map +1 -1
  42. package/build/group/transforms.js +0 -5
  43. package/build/group/transforms.js.map +1 -1
  44. package/build/image/deprecated.js +2 -4
  45. package/build/image/deprecated.js.map +1 -1
  46. package/build/image/edit.js +13 -11
  47. package/build/image/edit.js.map +1 -1
  48. package/build/image/image.js +7 -12
  49. package/build/image/image.js.map +1 -1
  50. package/build/image/index.js +3 -0
  51. package/build/image/index.js.map +1 -1
  52. package/build/image/interactivity.js +102 -0
  53. package/build/image/interactivity.js.map +1 -0
  54. package/build/image/save.js +2 -4
  55. package/build/image/save.js.map +1 -1
  56. package/build/image/utils.js +10 -18
  57. package/build/image/utils.js.map +1 -1
  58. package/build/index.js +0 -6
  59. package/build/index.js.map +1 -1
  60. package/build/index.native.js +1 -1
  61. package/build/index.native.js.map +1 -1
  62. package/build/latest-posts/edit.native.js +1 -3
  63. package/build/latest-posts/edit.native.js.map +1 -1
  64. package/build/list/edit.js +1 -1
  65. package/build/list/edit.js.map +1 -1
  66. package/build/list-item/edit.native.js +1 -1
  67. package/build/list-item/edit.native.js.map +1 -1
  68. package/build/list-item/transforms.js +4 -1
  69. package/build/list-item/transforms.js.map +1 -1
  70. package/build/list-item/utils.js +5 -1
  71. package/build/list-item/utils.js.map +1 -1
  72. package/build/loginout/index.js +11 -1
  73. package/build/loginout/index.js.map +1 -1
  74. package/build/media-text/deprecated.js +4 -6
  75. package/build/media-text/deprecated.js.map +1 -1
  76. package/build/media-text/edit.js +13 -11
  77. package/build/media-text/edit.js.map +1 -1
  78. package/build/media-text/media-container.js +3 -3
  79. package/build/media-text/media-container.js.map +1 -1
  80. package/build/media-text/save.js +1 -3
  81. package/build/media-text/save.js.map +1 -1
  82. package/build/navigation/constants.js +15 -0
  83. package/build/navigation/constants.js.map +1 -0
  84. package/build/navigation/edit/index.js +16 -26
  85. package/build/navigation/edit/index.js.map +1 -1
  86. package/build/navigation/edit/inner-blocks.js +5 -7
  87. package/build/navigation/edit/inner-blocks.js.map +1 -1
  88. package/build/navigation/edit/leaf-more-menu.js +148 -0
  89. package/build/navigation/edit/leaf-more-menu.js.map +1 -0
  90. package/build/navigation/edit/menu-inspector-controls.js +53 -8
  91. package/build/navigation/edit/menu-inspector-controls.js.map +1 -1
  92. package/build/navigation/edit/navigation-menu-delete-control.js +6 -6
  93. package/build/navigation/edit/navigation-menu-delete-control.js.map +1 -1
  94. package/build/navigation/edit/unsaved-inner-blocks.js +12 -25
  95. package/build/navigation/edit/unsaved-inner-blocks.js.map +1 -1
  96. package/build/navigation/edit/use-convert-classic-menu-to-block-menu.js +1 -1
  97. package/build/navigation/edit/use-convert-classic-menu-to-block-menu.js.map +1 -1
  98. package/build/navigation/interactivity.js +157 -0
  99. package/build/navigation/interactivity.js.map +1 -0
  100. package/build/navigation-link/edit.js +7 -5
  101. package/build/navigation-link/edit.js.map +1 -1
  102. package/build/navigation-link/update-attributes.js +5 -5
  103. package/build/navigation-link/update-attributes.js.map +1 -1
  104. package/build/navigation-submenu/edit.js +7 -5
  105. package/build/navigation-submenu/edit.js.map +1 -1
  106. package/build/paragraph/index.js +5 -1
  107. package/build/paragraph/index.js.map +1 -1
  108. package/build/paragraph/transforms.js +5 -1
  109. package/build/paragraph/transforms.js.map +1 -1
  110. package/build/pattern/edit.js +42 -8
  111. package/build/pattern/edit.js.map +1 -1
  112. package/build/pattern/index.js +12 -5
  113. package/build/pattern/index.js.map +1 -1
  114. package/build/pattern/v1/edit.js +57 -0
  115. package/build/pattern/v1/edit.js.map +1 -0
  116. package/build/post-author-name/edit.js +1 -1
  117. package/build/post-author-name/edit.js.map +1 -1
  118. package/build/post-featured-image/edit.js +1 -2
  119. package/build/post-featured-image/edit.js.map +1 -1
  120. package/build/post-featured-image/overlay.js +5 -0
  121. package/build/post-featured-image/overlay.js.map +1 -1
  122. package/build/post-title/edit.js +24 -7
  123. package/build/post-title/edit.js.map +1 -1
  124. package/build/preformatted/edit.native.js +3 -2
  125. package/build/preformatted/edit.native.js.map +1 -1
  126. package/build/quote/transforms.js +23 -37
  127. package/build/quote/transforms.js.map +1 -1
  128. package/build/read-more/edit.js +1 -1
  129. package/build/read-more/edit.js.map +1 -1
  130. package/build/search/edit.js +9 -1
  131. package/build/search/edit.js.map +1 -1
  132. package/build/site-title/edit/index.js +1 -1
  133. package/build/site-title/edit/index.js.map +1 -1
  134. package/build/social-link/edit.js +21 -4
  135. package/build/social-link/edit.js.map +1 -1
  136. package/build/social-links/edit.js +2 -2
  137. package/build/social-links/edit.js.map +1 -1
  138. package/build/template-part/edit/index.js +1 -7
  139. package/build/template-part/edit/index.js.map +1 -1
  140. package/build/template-part/edit/utils/hooks.js +2 -2
  141. package/build/template-part/edit/utils/hooks.js.map +1 -1
  142. package/build/utils/interactivity/constants.js +9 -0
  143. package/build/utils/interactivity/constants.js.map +1 -0
  144. package/build/utils/interactivity/directives.js +236 -0
  145. package/build/utils/interactivity/directives.js.map +1 -0
  146. package/build/utils/interactivity/hooks.js +176 -0
  147. package/build/utils/interactivity/hooks.js.map +1 -0
  148. package/build/utils/interactivity/hydration.js +34 -0
  149. package/build/utils/interactivity/hydration.js.map +1 -0
  150. package/build/utils/interactivity/index.js +34 -0
  151. package/build/utils/interactivity/index.js.map +1 -0
  152. package/build/utils/interactivity/portals.js +108 -0
  153. package/build/utils/interactivity/portals.js.map +1 -0
  154. package/build/utils/interactivity/store.js +67 -0
  155. package/build/utils/interactivity/store.js.map +1 -0
  156. package/build/utils/interactivity/utils.js +87 -0
  157. package/build/utils/interactivity/utils.js.map +1 -0
  158. package/build/utils/interactivity/vdom.js +109 -0
  159. package/build/utils/interactivity/vdom.js.map +1 -0
  160. package/build-module/block/edit.native.js +7 -1
  161. package/build-module/block/edit.native.js.map +1 -1
  162. package/build-module/code/index.js +1 -0
  163. package/build-module/code/index.js.map +1 -1
  164. package/build-module/column/index.js +1 -1
  165. package/build-module/columns/transforms.js +1 -5
  166. package/build-module/columns/transforms.js.map +1 -1
  167. package/build-module/comment-author-name/edit.js +1 -1
  168. package/build-module/comment-author-name/edit.js.map +1 -1
  169. package/build-module/comment-edit-link/edit.js +1 -1
  170. package/build-module/comment-edit-link/edit.js.map +1 -1
  171. package/build-module/cover/edit/inspector-controls.js +1 -1
  172. package/build-module/cover/edit/inspector-controls.js.map +1 -1
  173. package/build-module/cover/edit/resizable-cover-popover.js +3 -3
  174. package/build-module/cover/edit/resizable-cover-popover.js.map +1 -1
  175. package/build-module/cover/index.js +1 -1
  176. package/build-module/cover/variations.js +1 -1
  177. package/build-module/cover/variations.js.map +1 -1
  178. package/build-module/details/edit.js +20 -6
  179. package/build-module/details/edit.js.map +1 -1
  180. package/build-module/details/index.js +14 -10
  181. package/build-module/details/index.js.map +1 -1
  182. package/build-module/details/save.js +5 -2
  183. package/build-module/details/save.js.map +1 -1
  184. package/build-module/embed/variations.js +2 -2
  185. package/build-module/embed/variations.js.map +1 -1
  186. package/build-module/file/interactivity.js +15 -0
  187. package/build-module/file/interactivity.js.map +1 -0
  188. package/build-module/file/{utils.js → utils/index.js} +1 -1
  189. package/build-module/file/utils/index.js.map +1 -0
  190. package/build-module/file/view.js +1 -1
  191. package/build-module/file/view.js.map +1 -1
  192. package/build-module/freeform/modal.js +19 -18
  193. package/build-module/freeform/modal.js.map +1 -1
  194. package/build-module/gallery/edit.js +2 -8
  195. package/build-module/gallery/edit.js.map +1 -1
  196. package/build-module/gallery/v1/edit.js +1 -6
  197. package/build-module/gallery/v1/edit.js.map +1 -1
  198. package/build-module/gallery/v1/gallery-image.native.js +1 -2
  199. package/build-module/gallery/v1/gallery-image.native.js.map +1 -1
  200. package/build-module/group/transforms.js +0 -5
  201. package/build-module/group/transforms.js.map +1 -1
  202. package/build-module/image/deprecated.js +2 -3
  203. package/build-module/image/deprecated.js.map +1 -1
  204. package/build-module/image/edit.js +12 -11
  205. package/build-module/image/edit.js.map +1 -1
  206. package/build-module/image/image.js +7 -11
  207. package/build-module/image/image.js.map +1 -1
  208. package/build-module/image/index.js +3 -0
  209. package/build-module/image/index.js.map +1 -1
  210. package/build-module/image/interactivity.js +99 -0
  211. package/build-module/image/interactivity.js.map +1 -0
  212. package/build-module/image/save.js +2 -3
  213. package/build-module/image/save.js.map +1 -1
  214. package/build-module/image/utils.js +10 -17
  215. package/build-module/image/utils.js.map +1 -1
  216. package/build-module/index.js +0 -4
  217. package/build-module/index.js.map +1 -1
  218. package/build-module/index.native.js +1 -1
  219. package/build-module/index.native.js.map +1 -1
  220. package/build-module/latest-posts/edit.native.js +1 -2
  221. package/build-module/latest-posts/edit.native.js.map +1 -1
  222. package/build-module/list/edit.js +1 -1
  223. package/build-module/list/edit.js.map +1 -1
  224. package/build-module/list-item/edit.native.js +1 -1
  225. package/build-module/list-item/edit.native.js.map +1 -1
  226. package/build-module/list-item/transforms.js +5 -2
  227. package/build-module/list-item/transforms.js.map +1 -1
  228. package/build-module/list-item/utils.js +5 -1
  229. package/build-module/list-item/utils.js.map +1 -1
  230. package/build-module/loginout/index.js +11 -1
  231. package/build-module/loginout/index.js.map +1 -1
  232. package/build-module/media-text/deprecated.js +4 -5
  233. package/build-module/media-text/deprecated.js.map +1 -1
  234. package/build-module/media-text/edit.js +13 -12
  235. package/build-module/media-text/edit.js.map +1 -1
  236. package/build-module/media-text/media-container.js +3 -3
  237. package/build-module/media-text/media-container.js.map +1 -1
  238. package/build-module/media-text/save.js +1 -2
  239. package/build-module/media-text/save.js.map +1 -1
  240. package/build-module/navigation/constants.js +6 -0
  241. package/build-module/navigation/constants.js.map +1 -0
  242. package/build-module/navigation/edit/index.js +18 -27
  243. package/build-module/navigation/edit/index.js.map +1 -1
  244. package/build-module/navigation/edit/inner-blocks.js +2 -4
  245. package/build-module/navigation/edit/inner-blocks.js.map +1 -1
  246. package/build-module/navigation/edit/leaf-more-menu.js +132 -0
  247. package/build-module/navigation/edit/leaf-more-menu.js.map +1 -0
  248. package/build-module/navigation/edit/menu-inspector-controls.js +52 -9
  249. package/build-module/navigation/edit/menu-inspector-controls.js.map +1 -1
  250. package/build-module/navigation/edit/navigation-menu-delete-control.js +7 -7
  251. package/build-module/navigation/edit/navigation-menu-delete-control.js.map +1 -1
  252. package/build-module/navigation/edit/unsaved-inner-blocks.js +9 -20
  253. package/build-module/navigation/edit/unsaved-inner-blocks.js.map +1 -1
  254. package/build-module/navigation/edit/use-convert-classic-menu-to-block-menu.js +1 -1
  255. package/build-module/navigation/edit/use-convert-classic-menu-to-block-menu.js.map +1 -1
  256. package/build-module/navigation/interactivity.js +154 -0
  257. package/build-module/navigation/interactivity.js.map +1 -0
  258. package/build-module/navigation-link/edit.js +7 -5
  259. package/build-module/navigation-link/edit.js.map +1 -1
  260. package/build-module/navigation-link/update-attributes.js +4 -4
  261. package/build-module/navigation-link/update-attributes.js.map +1 -1
  262. package/build-module/navigation-submenu/edit.js +7 -5
  263. package/build-module/navigation-submenu/edit.js.map +1 -1
  264. package/build-module/paragraph/index.js +5 -1
  265. package/build-module/paragraph/index.js.map +1 -1
  266. package/build-module/paragraph/transforms.js +5 -1
  267. package/build-module/paragraph/transforms.js.map +1 -1
  268. package/build-module/pattern/edit.js +42 -9
  269. package/build-module/pattern/edit.js.map +1 -1
  270. package/build-module/pattern/index.js +12 -3
  271. package/build-module/pattern/index.js.map +1 -1
  272. package/build-module/pattern/v1/edit.js +48 -0
  273. package/build-module/pattern/v1/edit.js.map +1 -0
  274. package/build-module/post-author-name/edit.js +1 -1
  275. package/build-module/post-author-name/edit.js.map +1 -1
  276. package/build-module/post-featured-image/edit.js +1 -2
  277. package/build-module/post-featured-image/edit.js.map +1 -1
  278. package/build-module/post-featured-image/overlay.js +5 -0
  279. package/build-module/post-featured-image/overlay.js.map +1 -1
  280. package/build-module/post-title/edit.js +23 -7
  281. package/build-module/post-title/edit.js.map +1 -1
  282. package/build-module/preformatted/edit.native.js +3 -2
  283. package/build-module/preformatted/edit.native.js.map +1 -1
  284. package/build-module/quote/transforms.js +23 -37
  285. package/build-module/quote/transforms.js.map +1 -1
  286. package/build-module/read-more/edit.js +1 -1
  287. package/build-module/read-more/edit.js.map +1 -1
  288. package/build-module/search/edit.js +9 -1
  289. package/build-module/search/edit.js.map +1 -1
  290. package/build-module/site-title/edit/index.js +1 -1
  291. package/build-module/site-title/edit/index.js.map +1 -1
  292. package/build-module/social-link/edit.js +20 -5
  293. package/build-module/social-link/edit.js.map +1 -1
  294. package/build-module/social-links/edit.js +2 -2
  295. package/build-module/social-links/edit.js.map +1 -1
  296. package/build-module/template-part/edit/index.js +1 -6
  297. package/build-module/template-part/edit/index.js.map +1 -1
  298. package/build-module/template-part/edit/utils/hooks.js +1 -1
  299. package/build-module/template-part/edit/utils/hooks.js.map +1 -1
  300. package/build-module/utils/interactivity/constants.js +2 -0
  301. package/build-module/utils/interactivity/constants.js.map +1 -0
  302. package/build-module/utils/interactivity/directives.js +220 -0
  303. package/build-module/utils/interactivity/directives.js.map +1 -0
  304. package/build-module/utils/interactivity/hooks.js +162 -0
  305. package/build-module/utils/interactivity/hooks.js.map +1 -0
  306. package/build-module/utils/interactivity/hydration.js +21 -0
  307. package/build-module/utils/interactivity/hydration.js.map +1 -0
  308. package/build-module/utils/interactivity/index.js +17 -0
  309. package/build-module/utils/interactivity/index.js.map +1 -0
  310. package/build-module/utils/interactivity/portals.js +100 -0
  311. package/build-module/utils/interactivity/portals.js.map +1 -0
  312. package/build-module/utils/interactivity/store.js +56 -0
  313. package/build-module/utils/interactivity/store.js.map +1 -0
  314. package/build-module/utils/interactivity/utils.js +75 -0
  315. package/build-module/utils/interactivity/utils.js.map +1 -0
  316. package/build-module/utils/interactivity/vdom.js +97 -0
  317. package/build-module/utils/interactivity/vdom.js.map +1 -0
  318. package/build-style/common-rtl.css +1 -1
  319. package/build-style/common.css +1 -1
  320. package/build-style/cover/style-rtl.css +3 -2
  321. package/build-style/cover/style.css +3 -2
  322. package/build-style/{details-summary → details}/editor-rtl.css +1 -1
  323. package/build-style/{details-summary → details}/editor.css +1 -1
  324. package/build-style/details/style-rtl.css +14 -0
  325. package/build-style/details/style.css +14 -0
  326. package/build-style/editor-rtl.css +71 -5
  327. package/build-style/editor.css +71 -5
  328. package/build-style/file/editor-rtl.css +3 -0
  329. package/build-style/file/editor.css +3 -0
  330. package/build-style/freeform/editor-rtl.css +29 -0
  331. package/build-style/freeform/editor.css +29 -0
  332. package/build-style/gallery/editor-rtl.css +0 -4
  333. package/build-style/gallery/editor.css +0 -4
  334. package/build-style/gallery/style-rtl.css +2 -4
  335. package/build-style/gallery/style.css +2 -4
  336. package/build-style/image/style-rtl.css +98 -0
  337. package/build-style/image/style.css +98 -0
  338. package/build-style/navigation/editor-rtl.css +36 -0
  339. package/build-style/navigation/editor.css +36 -0
  340. package/build-style/post-comments-form/style-rtl.css +1 -1
  341. package/build-style/post-comments-form/style.css +1 -1
  342. package/build-style/search/editor-rtl.css +1 -0
  343. package/build-style/search/editor.css +1 -0
  344. package/build-style/site-logo/editor-rtl.css +1 -0
  345. package/build-style/site-logo/editor.css +1 -0
  346. package/build-style/style-rtl.css +116 -10
  347. package/build-style/style.css +116 -10
  348. package/build-style/video/style-rtl.css +1 -2
  349. package/build-style/video/style.css +1 -2
  350. package/package.json +37 -33
  351. package/src/block/edit.native.js +18 -4
  352. package/src/buttons/test/edit.native.js +0 -9
  353. package/src/code/block.json +1 -0
  354. package/src/column/block.json +1 -1
  355. package/src/columns/test/__snapshots__/transforms.native.js.snap +1 -1
  356. package/src/columns/test/transforms.native.js +3 -5
  357. package/src/columns/transforms.js +2 -8
  358. package/src/comment-author-name/edit.js +1 -1
  359. package/src/comment-edit-link/edit.js +1 -1
  360. package/src/comment-template/index.php +8 -7
  361. package/src/comments/index.php +1 -6
  362. package/src/cover/block.json +1 -1
  363. package/src/cover/edit/inspector-controls.js +56 -54
  364. package/src/cover/edit/resizable-cover-popover.js +2 -1
  365. package/src/cover/style.scss +5 -0
  366. package/src/cover/test/edit.js +56 -2
  367. package/src/cover/variations.js +1 -3
  368. package/src/details/block.json +8 -6
  369. package/src/details/edit.js +27 -5
  370. package/src/details/editor.scss +3 -0
  371. package/src/details/index.js +10 -5
  372. package/src/details/save.js +5 -1
  373. package/src/details/style.scss +16 -0
  374. package/src/editor.scss +1 -1
  375. package/src/embed/variations.js +2 -2
  376. package/src/file/editor.scss +4 -0
  377. package/src/file/interactivity.js +15 -0
  378. package/src/file/view.js +4 -1
  379. package/src/freeform/editor.scss +45 -0
  380. package/src/freeform/modal.js +22 -19
  381. package/src/gallery/edit.js +5 -8
  382. package/src/gallery/editor.scss +0 -6
  383. package/src/gallery/test/index.native.js +48 -3
  384. package/src/gallery/v1/edit.js +1 -6
  385. package/src/gallery/v1/gallery-image.native.js +1 -2
  386. package/src/group/test/__snapshots__/transforms.native.js.snap +1 -1
  387. package/src/group/test/transforms.native.js +3 -5
  388. package/src/group/transforms.js +0 -7
  389. package/src/image/block.json +3 -0
  390. package/src/image/deprecated.js +2 -3
  391. package/src/image/edit.js +18 -18
  392. package/src/image/image.js +8 -11
  393. package/src/image/index.php +75 -2
  394. package/src/image/interactivity.js +113 -0
  395. package/src/image/save.js +4 -3
  396. package/src/image/style.scss +113 -0
  397. package/src/image/test/edit.native.js +38 -16
  398. package/src/image/utils.js +11 -18
  399. package/src/index.js +0 -4
  400. package/src/index.native.js +1 -0
  401. package/src/latest-posts/edit.native.js +1 -4
  402. package/src/list/edit.js +1 -1
  403. package/src/list/test/edit.native.js +80 -1
  404. package/src/list-item/edit.native.js +1 -1
  405. package/src/list-item/transforms.js +4 -2
  406. package/src/loginout/block.json +11 -1
  407. package/src/media-text/deprecated.js +4 -5
  408. package/src/media-text/edit.js +12 -10
  409. package/src/media-text/media-container.js +3 -3
  410. package/src/media-text/save.js +1 -2
  411. package/src/navigation/constants.js +21 -0
  412. package/src/navigation/edit/index.js +71 -83
  413. package/src/navigation/edit/inner-blocks.js +6 -16
  414. package/src/navigation/edit/leaf-more-menu.js +170 -0
  415. package/src/navigation/edit/menu-inspector-controls.js +78 -10
  416. package/src/navigation/edit/navigation-menu-delete-control.js +29 -29
  417. package/src/navigation/edit/unsaved-inner-blocks.js +12 -40
  418. package/src/navigation/edit/use-convert-classic-menu-to-block-menu.js +1 -1
  419. package/src/navigation/editor.scss +10 -0
  420. package/src/navigation/index.php +213 -204
  421. package/src/navigation/interactivity.js +151 -0
  422. package/src/navigation-link/edit.js +9 -3
  423. package/src/navigation-link/update-attributes.js +2 -2
  424. package/src/navigation-submenu/edit.js +9 -3
  425. package/src/paragraph/block.json +5 -1
  426. package/src/pattern/block.json +4 -0
  427. package/src/pattern/edit.js +53 -16
  428. package/src/pattern/index.js +5 -4
  429. package/src/pattern/index.php +14 -1
  430. package/src/pattern/v1/edit.js +57 -0
  431. package/src/post-author-name/edit.js +1 -1
  432. package/src/post-comments-form/style.scss +3 -1
  433. package/src/post-featured-image/edit.js +1 -1
  434. package/src/post-featured-image/index.php +1 -1
  435. package/src/post-featured-image/overlay.js +4 -0
  436. package/src/post-terms/index.php +2 -2
  437. package/src/post-title/edit.js +57 -44
  438. package/src/preformatted/edit.native.js +1 -3
  439. package/src/quote/test/__snapshots__/transforms.native.js.snap +1 -1
  440. package/src/quote/test/transforms.native.js +3 -5
  441. package/src/quote/transforms.js +9 -19
  442. package/src/read-more/edit.js +1 -1
  443. package/src/search/edit.js +9 -4
  444. package/src/search/editor.scss +1 -0
  445. package/src/site-logo/editor.scss +2 -1
  446. package/src/site-title/edit/index.js +1 -1
  447. package/src/social-link/edit.js +51 -26
  448. package/src/social-links/edit.js +33 -31
  449. package/src/style.scss +0 -1
  450. package/src/template-part/edit/index.js +4 -6
  451. package/src/template-part/edit/utils/hooks.js +1 -1
  452. package/src/template-part/index.php +22 -7
  453. package/src/utils/interactivity/constants.js +1 -0
  454. package/src/utils/interactivity/directives.js +200 -0
  455. package/src/utils/interactivity/hooks.js +145 -0
  456. package/src/utils/interactivity/hydration.js +22 -0
  457. package/src/utils/interactivity/index.js +17 -0
  458. package/src/utils/interactivity/portals.js +98 -0
  459. package/src/utils/interactivity/store.js +45 -0
  460. package/src/utils/interactivity/utils.js +66 -0
  461. package/src/utils/interactivity/vdom.js +94 -0
  462. package/tsconfig.json +1 -0
  463. package/tsconfig.tsbuildinfo +1 -1
  464. package/build/details-content/edit.js +0 -34
  465. package/build/details-content/edit.js.map +0 -1
  466. package/build/details-content/index.js +0 -94
  467. package/build/details-content/index.js.map +0 -1
  468. package/build/details-content/save.js +0 -20
  469. package/build/details-content/save.js.map +0 -1
  470. package/build/details-summary/edit.js +0 -42
  471. package/build/details-summary/edit.js.map +0 -1
  472. package/build/details-summary/index.js +0 -97
  473. package/build/details-summary/index.js.map +0 -1
  474. package/build/details-summary/save.js +0 -24
  475. package/build/details-summary/save.js.map +0 -1
  476. package/build/file/utils.js.map +0 -1
  477. package/build-module/details-content/edit.js +0 -23
  478. package/build-module/details-content/edit.js.map +0 -1
  479. package/build-module/details-content/index.js +0 -76
  480. package/build-module/details-content/index.js.map +0 -1
  481. package/build-module/details-content/save.js +0 -11
  482. package/build-module/details-content/save.js.map +0 -1
  483. package/build-module/details-summary/edit.js +0 -30
  484. package/build-module/details-summary/edit.js.map +0 -1
  485. package/build-module/details-summary/index.js +0 -79
  486. package/build-module/details-summary/index.js.map +0 -1
  487. package/build-module/details-summary/save.js +0 -16
  488. package/build-module/details-summary/save.js.map +0 -1
  489. package/build-module/file/utils.js.map +0 -1
  490. package/build-style/details-summary/style-rtl.css +0 -91
  491. package/build-style/details-summary/style.css +0 -91
  492. package/src/details-content/block.json +0 -50
  493. package/src/details-content/edit.js +0 -29
  494. package/src/details-content/index.js +0 -23
  495. package/src/details-content/save.js +0 -12
  496. package/src/details-summary/block.json +0 -53
  497. package/src/details-summary/edit.js +0 -27
  498. package/src/details-summary/editor.scss +0 -3
  499. package/src/details-summary/index.js +0 -23
  500. package/src/details-summary/save.js +0 -13
  501. package/src/details-summary/style.scss +0 -3
  502. /package/src/file/{utils.js → utils/index.js} +0 -0
@@ -6,11 +6,15 @@ import classNames from 'classnames';
6
6
  /**
7
7
  * WordPress dependencies
8
8
  */
9
+ import { DELETE, BACKSPACE } from '@wordpress/keycodes';
10
+ import { useDispatch } from '@wordpress/data';
11
+
9
12
  import {
10
13
  InspectorControls,
11
14
  URLPopover,
12
15
  URLInput,
13
16
  useBlockProps,
17
+ store as blockEditorStore,
14
18
  } from '@wordpress/block-editor';
15
19
  import { useState } from '@wordpress/element';
16
20
  import {
@@ -32,40 +36,60 @@ const SocialLinkURLPopover = ( {
32
36
  setAttributes,
33
37
  setPopover,
34
38
  popoverAnchor,
35
- } ) => (
36
- <URLPopover anchor={ popoverAnchor } onClose={ () => setPopover( false ) }>
37
- <form
38
- className="block-editor-url-popover__link-editor"
39
- onSubmit={ ( event ) => {
40
- event.preventDefault();
41
- setPopover( false );
42
- } }
39
+ clientId,
40
+ } ) => {
41
+ const { removeBlock } = useDispatch( blockEditorStore );
42
+ return (
43
+ <URLPopover
44
+ anchor={ popoverAnchor }
45
+ onClose={ () => setPopover( false ) }
43
46
  >
44
- <div className="block-editor-url-input">
45
- <URLInput
46
- __nextHasNoMarginBottom
47
- value={ url }
48
- onChange={ ( nextURL ) =>
49
- setAttributes( { url: nextURL } )
50
- }
51
- placeholder={ __( 'Enter address' ) }
52
- disableSuggestions={ true }
47
+ <form
48
+ className="block-editor-url-popover__link-editor"
49
+ onSubmit={ ( event ) => {
50
+ event.preventDefault();
51
+ setPopover( false );
52
+ } }
53
+ >
54
+ <div className="block-editor-url-input">
55
+ <URLInput
56
+ __nextHasNoMarginBottom
57
+ value={ url }
58
+ onChange={ ( nextURL ) =>
59
+ setAttributes( { url: nextURL } )
60
+ }
61
+ placeholder={ __( 'Enter address' ) }
62
+ disableSuggestions={ true }
63
+ onKeyDown={ ( event ) => {
64
+ if (
65
+ !! url ||
66
+ event.defaultPrevented ||
67
+ ! [ BACKSPACE, DELETE ].includes(
68
+ event.keyCode
69
+ )
70
+ ) {
71
+ return;
72
+ }
73
+ removeBlock( clientId );
74
+ } }
75
+ />
76
+ </div>
77
+ <Button
78
+ icon={ keyboardReturn }
79
+ label={ __( 'Apply' ) }
80
+ type="submit"
53
81
  />
54
- </div>
55
- <Button
56
- icon={ keyboardReturn }
57
- label={ __( 'Apply' ) }
58
- type="submit"
59
- />
60
- </form>
61
- </URLPopover>
62
- );
82
+ </form>
83
+ </URLPopover>
84
+ );
85
+ };
63
86
 
64
87
  const SocialLinkEdit = ( {
65
88
  attributes,
66
89
  context,
67
90
  isSelected,
68
91
  setAttributes,
92
+ clientId,
69
93
  } ) => {
70
94
  const { url, service, label, rel } = attributes;
71
95
  const { showLabels, iconColorValue, iconBackgroundColorValue } = context;
@@ -143,6 +167,7 @@ const SocialLinkEdit = ( {
143
167
  setAttributes={ setAttributes }
144
168
  setPopover={ setPopover }
145
169
  popoverAnchor={ popoverAnchor }
170
+ clientId={ clientId }
146
171
  />
147
172
  ) }
148
173
  </Button>
@@ -195,7 +195,7 @@ export function SocialLinksEdit( props ) {
195
195
  </ToolbarDropdownMenu>
196
196
  </BlockControls>
197
197
  <InspectorControls>
198
- <PanelBody title={ __( 'Link settings' ) }>
198
+ <PanelBody title={ __( 'Settings' ) }>
199
199
  <ToggleControl
200
200
  __nextHasNoMarginBottom
201
201
  label={ __( 'Open links in new tab' ) }
@@ -214,37 +214,39 @@ export function SocialLinksEdit( props ) {
214
214
  />
215
215
  </PanelBody>
216
216
  </InspectorControls>
217
- <InspectorControls group="color">
218
- { colorSettings.map(
219
- ( { onChange, label, value, resetAllFilter } ) => (
220
- <ColorGradientSettingsDropdown
221
- key={ `social-links-color-${ label }` }
222
- __experimentalIsRenderedInSidebar
223
- settings={ [
224
- {
225
- colorValue: value,
226
- label,
227
- onColorChange: onChange,
228
- isShownByDefault: true,
229
- resetAllFilter,
230
- enableAlpha: true,
231
- },
232
- ] }
233
- panelId={ clientId }
234
- { ...colorGradientSettings }
217
+ { colorGradientSettings.hasColorsOrGradients && (
218
+ <InspectorControls group="color">
219
+ { colorSettings.map(
220
+ ( { onChange, label, value, resetAllFilter } ) => (
221
+ <ColorGradientSettingsDropdown
222
+ key={ `social-links-color-${ label }` }
223
+ __experimentalIsRenderedInSidebar
224
+ settings={ [
225
+ {
226
+ colorValue: value,
227
+ label,
228
+ onColorChange: onChange,
229
+ isShownByDefault: true,
230
+ resetAllFilter,
231
+ enableAlpha: true,
232
+ },
233
+ ] }
234
+ panelId={ clientId }
235
+ { ...colorGradientSettings }
236
+ />
237
+ )
238
+ ) }
239
+ { ! logosOnly && (
240
+ <ContrastChecker
241
+ { ...{
242
+ textColor: iconColorValue,
243
+ backgroundColor: iconBackgroundColorValue,
244
+ } }
245
+ isLargeText={ false }
235
246
  />
236
- )
237
- ) }
238
- { ! logosOnly && (
239
- <ContrastChecker
240
- { ...{
241
- textColor: iconColorValue,
242
- backgroundColor: iconBackgroundColorValue,
243
- } }
244
- isLargeText={ false }
245
- />
246
- ) }
247
- </InspectorControls>
247
+ ) }
248
+ </InspectorControls>
249
+ ) }
248
250
  <ul { ...innerBlocksProps } />
249
251
  </>
250
252
  );
package/src/style.scss CHANGED
@@ -12,7 +12,6 @@
12
12
  @import "./comment-template/style.scss";
13
13
  @import "./cover/style.scss";
14
14
  @import "./details/style.scss";
15
- @import "./details-summary/style.scss";
16
15
  @import "./embed/style.scss";
17
16
  @import "./file/style.scss";
18
17
  @import "./gallery/style.scss";
@@ -1,8 +1,3 @@
1
- /**
2
- * External dependencies
3
- */
4
- import { isEmpty } from 'lodash';
5
-
6
1
  /**
7
2
  * WordPress dependencies
8
3
  */
@@ -75,7 +70,10 @@ export default function TemplatePartEdit( {
75
70
  return {
76
71
  innerBlocks: getBlocks( clientId ),
77
72
  isResolved: hasResolvedEntity,
78
- isMissing: hasResolvedEntity && isEmpty( entityRecord ),
73
+ isMissing:
74
+ hasResolvedEntity &&
75
+ ( ! entityRecord ||
76
+ Object.keys( entityRecord ).length === 0 ),
79
77
  area: _area,
80
78
  };
81
79
  },
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import { kebabCase } from 'lodash';
4
+ import { paramCase as kebabCase } from 'change-case';
5
5
 
6
6
  /**
7
7
  * WordPress dependencies
@@ -143,14 +143,14 @@ function render_block_core_template_part( $attributes ) {
143
143
  }
144
144
 
145
145
  // Run through the actions that are typically taken on the_content.
146
+ $content = shortcode_unautop( $content );
147
+ $content = do_shortcode( $content );
146
148
  $seen_ids[ $template_part_id ] = true;
147
149
  $content = do_blocks( $content );
148
150
  unset( $seen_ids[ $template_part_id ] );
149
151
  $content = wptexturize( $content );
150
152
  $content = convert_smilies( $content );
151
- $content = shortcode_unautop( $content );
152
153
  $content = wp_filter_content_tags( $content, "template_part_{$area}" );
153
- $content = do_shortcode( $content );
154
154
 
155
155
  // Handle embeds for block template parts.
156
156
  global $wp_embed;
@@ -173,21 +173,34 @@ function render_block_core_template_part( $attributes ) {
173
173
  /**
174
174
  * Returns an array of area variation objects for the template part block.
175
175
  *
176
+ * @param array $instance_variations The variations for instances.
177
+ *
176
178
  * @return array Array containing the block variation objects.
177
179
  */
178
- function build_template_part_block_area_variations() {
180
+ function build_template_part_block_area_variations( $instance_variations ) {
179
181
  $variations = array();
180
182
  $defined_areas = get_allowed_block_template_part_areas();
183
+
181
184
  foreach ( $defined_areas as $area ) {
182
185
  if ( 'uncategorized' !== $area['area'] ) {
186
+ $has_instance_for_area = false;
187
+ foreach ( $instance_variations as $variation ) {
188
+ if ( $variation['attributes']['area'] === $area['area'] ) {
189
+ $has_instance_for_area = true;
190
+ break;
191
+ }
192
+ }
193
+
194
+ $scope = $has_instance_for_area ? array() : array( 'inserter' );
195
+
183
196
  $variations[] = array(
184
- 'name' => $area['area'],
197
+ 'name' => 'area_' . $area['area'],
185
198
  'title' => $area['label'],
186
199
  'description' => $area['description'],
187
200
  'attributes' => array(
188
201
  'area' => $area['area'],
189
202
  ),
190
- 'scope' => array( 'inserter' ),
203
+ 'scope' => $scope,
191
204
  'icon' => $area['icon'],
192
205
  );
193
206
  }
@@ -223,7 +236,7 @@ function build_template_part_block_instance_variations() {
223
236
 
224
237
  foreach ( $template_parts as $template_part ) {
225
238
  $variations[] = array(
226
- 'name' => sanitize_title( $template_part->slug ),
239
+ 'name' => 'instance_' . sanitize_title( $template_part->slug ),
227
240
  'title' => $template_part->title,
228
241
  // If there's no description for the template part don't show the
229
242
  // block description. This is a bit hacky, but prevent the fallback
@@ -255,7 +268,9 @@ function build_template_part_block_instance_variations() {
255
268
  * @return array Array containing the block variation objects.
256
269
  */
257
270
  function build_template_part_block_variations() {
258
- return array_merge( build_template_part_block_area_variations(), build_template_part_block_instance_variations() );
271
+ $instance_variations = build_template_part_block_instance_variations();
272
+ $area_variations = build_template_part_block_area_variations( $instance_variations );
273
+ return array_merge( $area_variations, $instance_variations );
259
274
  }
260
275
 
261
276
  /**
@@ -0,0 +1 @@
1
+ export const directivePrefix = 'data-wp-';
@@ -0,0 +1,200 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import { useContext, useMemo, useEffect } from 'preact/hooks';
5
+ import { deepSignal, peek } from 'deepsignal';
6
+ /**
7
+ * Internal dependencies
8
+ */
9
+ import { createPortal } from './portals.js';
10
+
11
+ /**
12
+ * Internal dependencies
13
+ */
14
+ import { useSignalEffect } from './utils';
15
+ import { directive } from './hooks';
16
+
17
+ const isObject = ( item ) =>
18
+ item && typeof item === 'object' && ! Array.isArray( item );
19
+
20
+ const mergeDeepSignals = ( target, source ) => {
21
+ for ( const k in source ) {
22
+ if ( typeof peek( target, k ) === 'undefined' ) {
23
+ target[ `$${ k }` ] = source[ `$${ k }` ];
24
+ } else if (
25
+ isObject( peek( target, k ) ) &&
26
+ isObject( peek( source, k ) )
27
+ ) {
28
+ mergeDeepSignals(
29
+ target[ `$${ k }` ].peek(),
30
+ source[ `$${ k }` ].peek()
31
+ );
32
+ }
33
+ }
34
+ };
35
+
36
+ export default () => {
37
+ // data-wp-context
38
+ directive(
39
+ 'context',
40
+ ( {
41
+ directives: {
42
+ context: { default: context },
43
+ },
44
+ props: { children },
45
+ context: inherited,
46
+ } ) => {
47
+ const { Provider } = inherited;
48
+ const inheritedValue = useContext( inherited );
49
+ const value = useMemo( () => {
50
+ const localValue = deepSignal( context );
51
+ mergeDeepSignals( localValue, inheritedValue );
52
+ return localValue;
53
+ }, [ context, inheritedValue ] );
54
+
55
+ return <Provider value={ value }>{ children }</Provider>;
56
+ },
57
+ { priority: 5 }
58
+ );
59
+
60
+ // data-wp-body
61
+ directive( 'body', ( { props: { children }, context: inherited } ) => {
62
+ const { Provider } = inherited;
63
+ const inheritedValue = useContext( inherited );
64
+ return createPortal(
65
+ <Provider value={ inheritedValue }>{ children }</Provider>,
66
+ document.body
67
+ );
68
+ } );
69
+
70
+ // data-wp-effect.[name]
71
+ directive( 'effect', ( { directives: { effect }, context, evaluate } ) => {
72
+ const contextValue = useContext( context );
73
+ Object.values( effect ).forEach( ( path ) => {
74
+ useSignalEffect( () => {
75
+ return evaluate( path, { context: contextValue } );
76
+ } );
77
+ } );
78
+ } );
79
+
80
+ // data-wp-init.[name]
81
+ directive( 'init', ( { directives: { init }, context, evaluate } ) => {
82
+ const contextValue = useContext( context );
83
+ Object.values( init ).forEach( ( path ) => {
84
+ useEffect( () => {
85
+ return evaluate( path, { context: contextValue } );
86
+ }, [] );
87
+ } );
88
+ } );
89
+
90
+ // data-wp-on.[event]
91
+ directive( 'on', ( { directives: { on }, element, evaluate, context } ) => {
92
+ const contextValue = useContext( context );
93
+ Object.entries( on ).forEach( ( [ name, path ] ) => {
94
+ element.props[ `on${ name }` ] = ( event ) => {
95
+ evaluate( path, { event, context: contextValue } );
96
+ };
97
+ } );
98
+ } );
99
+
100
+ // data-wp-class.[classname]
101
+ directive(
102
+ 'class',
103
+ ( {
104
+ directives: { class: className },
105
+ element,
106
+ evaluate,
107
+ context,
108
+ } ) => {
109
+ const contextValue = useContext( context );
110
+ Object.keys( className )
111
+ .filter( ( n ) => n !== 'default' )
112
+ .forEach( ( name ) => {
113
+ const result = evaluate( className[ name ], {
114
+ className: name,
115
+ context: contextValue,
116
+ } );
117
+ const currentClass = element.props.class || '';
118
+ const classFinder = new RegExp(
119
+ `(^|\\s)${ name }(\\s|$)`,
120
+ 'g'
121
+ );
122
+ if ( ! result )
123
+ element.props.class = currentClass
124
+ .replace( classFinder, ' ' )
125
+ .trim();
126
+ else if ( ! classFinder.test( currentClass ) )
127
+ element.props.class = currentClass
128
+ ? `${ currentClass } ${ name }`
129
+ : name;
130
+
131
+ useEffect( () => {
132
+ // This seems necessary because Preact doesn't change the class
133
+ // names on the hydration, so we have to do it manually. It doesn't
134
+ // need deps because it only needs to do it the first time.
135
+ if ( ! result ) {
136
+ element.ref.current.classList.remove( name );
137
+ } else {
138
+ element.ref.current.classList.add( name );
139
+ }
140
+ }, [] );
141
+ } );
142
+ }
143
+ );
144
+
145
+ // data-wp-bind.[attribute]
146
+ directive(
147
+ 'bind',
148
+ ( { directives: { bind }, element, context, evaluate } ) => {
149
+ const contextValue = useContext( context );
150
+ Object.entries( bind )
151
+ .filter( ( n ) => n !== 'default' )
152
+ .forEach( ( [ attribute, path ] ) => {
153
+ const result = evaluate( path, {
154
+ context: contextValue,
155
+ } );
156
+ element.props[ attribute ] = result;
157
+
158
+ // This seems necessary because Preact doesn't change the attributes
159
+ // on the hydration, so we have to do it manually. It doesn't need
160
+ // deps because it only needs to do it the first time.
161
+ useEffect( () => {
162
+ // aria- and data- attributes have no boolean representation.
163
+ // A `false` value is different from the attribute not being
164
+ // present, so we can't remove it.
165
+ // We follow Preact's logic: https://github.com/preactjs/preact/blob/ea49f7a0f9d1ff2c98c0bdd66aa0cbc583055246/src/diff/props.js#L131C24-L136
166
+ if ( result === false && attribute[ 4 ] !== '-' ) {
167
+ element.ref.current.removeAttribute( attribute );
168
+ } else {
169
+ element.ref.current.setAttribute(
170
+ attribute,
171
+ result === true && attribute[ 4 ] !== '-'
172
+ ? ''
173
+ : result
174
+ );
175
+ }
176
+ }, [] );
177
+ } );
178
+ }
179
+ );
180
+
181
+ // data-wp-ignore
182
+ directive(
183
+ 'ignore',
184
+ ( {
185
+ element: {
186
+ type: Type,
187
+ props: { innerHTML, ...rest },
188
+ },
189
+ } ) => {
190
+ // Preserve the initial inner HTML.
191
+ const cached = useMemo( () => innerHTML, [] );
192
+ return (
193
+ <Type
194
+ dangerouslySetInnerHTML={ { __html: cached } }
195
+ { ...rest }
196
+ />
197
+ );
198
+ }
199
+ );
200
+ };
@@ -0,0 +1,145 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import { h, options, createContext, cloneElement } from 'preact';
5
+ import { useRef, useMemo } from 'preact/hooks';
6
+ /**
7
+ * Internal dependencies
8
+ */
9
+ import { rawStore as store } from './store';
10
+
11
+ // Main context.
12
+ const context = createContext( {} );
13
+
14
+ // WordPress Directives.
15
+ const directiveMap = {};
16
+ const directivePriorities = {};
17
+ export const directive = ( name, cb, { priority = 10 } = {} ) => {
18
+ directiveMap[ name ] = cb;
19
+ directivePriorities[ name ] = priority;
20
+ };
21
+
22
+ // Resolve the path to some property of the store object.
23
+ const resolve = ( path, ctx ) => {
24
+ let current = { ...store, context: ctx };
25
+ path.split( '.' ).forEach( ( p ) => ( current = current[ p ] ) );
26
+ return current;
27
+ };
28
+
29
+ // Generate the evaluate function.
30
+ const getEvaluate =
31
+ ( { ref } = {} ) =>
32
+ ( path, extraArgs = {} ) => {
33
+ // If path starts with !, remove it and save a flag.
34
+ const hasNegationOperator =
35
+ path[ 0 ] === '!' && !! ( path = path.slice( 1 ) );
36
+ const value = resolve( path, extraArgs.context );
37
+ const returnValue =
38
+ typeof value === 'function'
39
+ ? value( {
40
+ ref: ref.current,
41
+ ...store,
42
+ ...extraArgs,
43
+ } )
44
+ : value;
45
+ return hasNegationOperator ? ! returnValue : returnValue;
46
+ };
47
+
48
+ // Separate directives by priority. The resulting array contains objects
49
+ // of directives grouped by same priority, and sorted in ascending order.
50
+ const usePriorityLevels = ( directives ) =>
51
+ useMemo( () => {
52
+ const byPriority = Object.entries( directives ).reduce(
53
+ ( acc, [ name, values ] ) => {
54
+ const priority = directivePriorities[ name ];
55
+ if ( ! acc[ priority ] ) acc[ priority ] = {};
56
+ acc[ priority ][ name ] = values;
57
+
58
+ return acc;
59
+ },
60
+ {}
61
+ );
62
+
63
+ return Object.entries( byPriority )
64
+ .sort( ( [ p1 ], [ p2 ] ) => p1 - p2 )
65
+ .map( ( [ , obj ] ) => obj );
66
+ }, [ directives ] );
67
+
68
+ // Directive wrapper.
69
+ const Directive = ( { type, directives, props: originalProps } ) => {
70
+ const ref = useRef( null );
71
+ const element = h( type, { ...originalProps, ref } );
72
+ const evaluate = useMemo( () => getEvaluate( { ref } ), [] );
73
+
74
+ // Add wrappers recursively for each priority level.
75
+ const byPriorityLevel = usePriorityLevels( directives );
76
+ return (
77
+ <RecursivePriorityLevel
78
+ directives={ byPriorityLevel }
79
+ element={ element }
80
+ evaluate={ evaluate }
81
+ originalProps={ originalProps }
82
+ />
83
+ );
84
+ };
85
+
86
+ // Priority level wrapper.
87
+ const RecursivePriorityLevel = ( {
88
+ directives: [ directives, ...rest ],
89
+ element,
90
+ evaluate,
91
+ originalProps,
92
+ } ) => {
93
+ // This element needs to be a fresh copy so we are not modifying an already
94
+ // rendered element with Preact's internal properties initialized. This
95
+ // prevents an error with changes in `element.props.children` not being
96
+ // reflected in `element.__k`.
97
+ element = cloneElement( element );
98
+
99
+ // Recursively render the wrapper for the next priority level.
100
+ //
101
+ // Note that, even though we're instantiating a vnode with a
102
+ // `RecursivePriorityLevel` here, its render function will not be executed
103
+ // just yet. Actually, it will be delayed until the current render function
104
+ // has finished. That ensures directives in the current priorty level have
105
+ // run (and thus modified the passed `element`) before the next level.
106
+ const children =
107
+ rest.length > 0 ? (
108
+ <RecursivePriorityLevel
109
+ directives={ rest }
110
+ element={ element }
111
+ evaluate={ evaluate }
112
+ originalProps={ originalProps }
113
+ />
114
+ ) : (
115
+ element
116
+ );
117
+
118
+ const props = { ...originalProps, children };
119
+ const directiveArgs = { directives, props, element, context, evaluate };
120
+
121
+ for ( const d in directives ) {
122
+ const wrapper = directiveMap[ d ]?.( directiveArgs );
123
+ if ( wrapper !== undefined ) props.children = wrapper;
124
+ }
125
+
126
+ return props.children;
127
+ };
128
+
129
+ // Preact Options Hook called each time a vnode is created.
130
+ const old = options.vnode;
131
+ options.vnode = ( vnode ) => {
132
+ if ( vnode.props.__directives ) {
133
+ const props = vnode.props;
134
+ const directives = props.__directives;
135
+ delete props.__directives;
136
+ vnode.props = {
137
+ type: vnode.type,
138
+ directives,
139
+ props,
140
+ };
141
+ vnode.type = Directive;
142
+ }
143
+
144
+ if ( old ) old( vnode );
145
+ };
@@ -0,0 +1,22 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import { hydrate } from 'preact';
5
+ /**
6
+ * Internal dependencies
7
+ */
8
+ import { toVdom, hydratedIslands } from './vdom';
9
+ import { createRootFragment } from './utils';
10
+ import { directivePrefix } from './constants';
11
+
12
+ export const init = async () => {
13
+ document
14
+ .querySelectorAll( `[${ directivePrefix }island]` )
15
+ .forEach( ( node ) => {
16
+ if ( ! hydratedIslands.has( node ) ) {
17
+ const fragment = createRootFragment( node.parentNode, node );
18
+ const vdom = toVdom( node );
19
+ hydrate( vdom, fragment );
20
+ }
21
+ } );
22
+ };
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import registerDirectives from './directives';
5
+ import { init } from './hydration';
6
+ export { store } from './store';
7
+
8
+ /**
9
+ * Initialize the Interactivity API.
10
+ */
11
+ registerDirectives();
12
+
13
+ document.addEventListener( 'DOMContentLoaded', async () => {
14
+ await init();
15
+ // eslint-disable-next-line no-console
16
+ console.log( 'Interactivity API started' );
17
+ } );