@wordpress/block-library 8.12.6 → 8.14.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 (305) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/build/archives/index.js +5 -1
  3. package/build/archives/index.js.map +1 -1
  4. package/build/audio/index.js +5 -1
  5. package/build/audio/index.js.map +1 -1
  6. package/build/block/edit.native.js +2 -2
  7. package/build/block/edit.native.js.map +1 -1
  8. package/build/categories/index.js +5 -1
  9. package/build/categories/index.js.map +1 -1
  10. package/build/code/index.js +5 -1
  11. package/build/code/index.js.map +1 -1
  12. package/build/column/index.js +1 -0
  13. package/build/column/index.js.map +1 -1
  14. package/build/comments/index.js +1 -0
  15. package/build/comments/index.js.map +1 -1
  16. package/build/cover/edit/inspector-controls.js +2 -1
  17. package/build/cover/edit/inspector-controls.js.map +1 -1
  18. package/build/cover/index.js +1 -0
  19. package/build/cover/index.js.map +1 -1
  20. package/build/details/index.js +5 -1
  21. package/build/details/index.js.map +1 -1
  22. package/build/embed/util.js +9 -8
  23. package/build/embed/util.js.map +1 -1
  24. package/build/file/index.js +2 -1
  25. package/build/file/index.js.map +1 -1
  26. package/build/file/view.js +15 -1
  27. package/build/file/view.js.map +1 -1
  28. package/build/gallery/index.js +3 -1
  29. package/build/gallery/index.js.map +1 -1
  30. package/build/group/index.js +1 -0
  31. package/build/group/index.js.map +1 -1
  32. package/build/heading/index.js +5 -1
  33. package/build/heading/index.js.map +1 -1
  34. package/build/heading/transforms.js +5 -1
  35. package/build/heading/transforms.js.map +1 -1
  36. package/build/image/deprecated.js +453 -175
  37. package/build/image/deprecated.js.map +1 -1
  38. package/build/image/image.js +1 -1
  39. package/build/image/image.js.map +1 -1
  40. package/build/image/save.js +3 -1
  41. package/build/image/save.js.map +1 -1
  42. package/build/image/{interactivity.js → view-interactivity.js} +86 -44
  43. package/build/image/view-interactivity.js.map +1 -0
  44. package/build/index.js +12 -3
  45. package/build/index.js.map +1 -1
  46. package/build/list/index.js +5 -1
  47. package/build/list/index.js.map +1 -1
  48. package/build/list-item/utils.js +6 -1
  49. package/build/list-item/utils.js.map +1 -1
  50. package/build/media-text/index.js +1 -0
  51. package/build/media-text/index.js.map +1 -1
  52. package/build/missing/edit.js +22 -8
  53. package/build/missing/edit.js.map +1 -1
  54. package/build/navigation/index.js +3 -2
  55. package/build/navigation/index.js.map +1 -1
  56. package/build/navigation/view.js +174 -50
  57. package/build/navigation/view.js.map +1 -1
  58. package/build/page-list/convert-to-links-modal.js +3 -3
  59. package/build/page-list/convert-to-links-modal.js.map +1 -1
  60. package/build/page-list/edit.js +34 -39
  61. package/build/page-list/edit.js.map +1 -1
  62. package/build/page-list/use-convert-to-navigation-links.js +2 -15
  63. package/build/page-list/use-convert-to-navigation-links.js.map +1 -1
  64. package/build/paragraph/index.js +1 -0
  65. package/build/paragraph/index.js.map +1 -1
  66. package/build/paragraph/transforms.js +1 -0
  67. package/build/paragraph/transforms.js.map +1 -1
  68. package/build/post-comments-form/index.js +1 -0
  69. package/build/post-comments-form/index.js.map +1 -1
  70. package/build/post-navigation-link/index.js +1 -0
  71. package/build/post-navigation-link/index.js.map +1 -1
  72. package/build/post-time-to-read/index.js +5 -1
  73. package/build/post-time-to-read/index.js.map +1 -1
  74. package/build/quote/index.js +1 -0
  75. package/build/quote/index.js.map +1 -1
  76. package/build/site-logo/index.js +5 -1
  77. package/build/site-logo/index.js.map +1 -1
  78. package/build/site-tagline/index.js +5 -1
  79. package/build/site-tagline/index.js.map +1 -1
  80. package/build/site-title/index.js +5 -1
  81. package/build/site-title/index.js.map +1 -1
  82. package/build/social-links/index.js +3 -1
  83. package/build/social-links/index.js.map +1 -1
  84. package/build/table/index.js +5 -1
  85. package/build/table/index.js.map +1 -1
  86. package/build/term-description/index.js +1 -0
  87. package/build/term-description/index.js.map +1 -1
  88. package/build/verse/index.js +5 -1
  89. package/build/verse/index.js.map +1 -1
  90. package/build/video/deprecated.js +5 -1
  91. package/build/video/deprecated.js.map +1 -1
  92. package/build/video/index.js +5 -1
  93. package/build/video/index.js.map +1 -1
  94. package/build-module/archives/index.js +5 -1
  95. package/build-module/archives/index.js.map +1 -1
  96. package/build-module/audio/index.js +5 -1
  97. package/build-module/audio/index.js.map +1 -1
  98. package/build-module/block/edit.native.js +2 -2
  99. package/build-module/block/edit.native.js.map +1 -1
  100. package/build-module/categories/index.js +5 -1
  101. package/build-module/categories/index.js.map +1 -1
  102. package/build-module/code/index.js +5 -1
  103. package/build-module/code/index.js.map +1 -1
  104. package/build-module/column/index.js +1 -0
  105. package/build-module/column/index.js.map +1 -1
  106. package/build-module/comments/index.js +1 -0
  107. package/build-module/comments/index.js.map +1 -1
  108. package/build-module/cover/edit/inspector-controls.js +2 -1
  109. package/build-module/cover/edit/inspector-controls.js.map +1 -1
  110. package/build-module/cover/index.js +1 -0
  111. package/build-module/cover/index.js.map +1 -1
  112. package/build-module/details/index.js +5 -1
  113. package/build-module/details/index.js.map +1 -1
  114. package/build-module/embed/util.js +6 -6
  115. package/build-module/embed/util.js.map +1 -1
  116. package/build-module/file/index.js +2 -1
  117. package/build-module/file/index.js.map +1 -1
  118. package/build-module/file/view.js +15 -2
  119. package/build-module/file/view.js.map +1 -1
  120. package/build-module/gallery/index.js +3 -1
  121. package/build-module/gallery/index.js.map +1 -1
  122. package/build-module/group/index.js +1 -0
  123. package/build-module/group/index.js.map +1 -1
  124. package/build-module/heading/index.js +5 -1
  125. package/build-module/heading/index.js.map +1 -1
  126. package/build-module/heading/transforms.js +5 -1
  127. package/build-module/heading/transforms.js.map +1 -1
  128. package/build-module/image/deprecated.js +454 -176
  129. package/build-module/image/deprecated.js.map +1 -1
  130. package/build-module/image/image.js +1 -1
  131. package/build-module/image/image.js.map +1 -1
  132. package/build-module/image/save.js +3 -1
  133. package/build-module/image/save.js.map +1 -1
  134. package/build-module/image/{interactivity.js → view-interactivity.js} +86 -44
  135. package/build-module/image/view-interactivity.js.map +1 -0
  136. package/build-module/index.js +12 -3
  137. package/build-module/index.js.map +1 -1
  138. package/build-module/list/index.js +5 -1
  139. package/build-module/list/index.js.map +1 -1
  140. package/build-module/list-item/utils.js +6 -1
  141. package/build-module/list-item/utils.js.map +1 -1
  142. package/build-module/media-text/index.js +1 -0
  143. package/build-module/media-text/index.js.map +1 -1
  144. package/build-module/missing/edit.js +22 -8
  145. package/build-module/missing/edit.js.map +1 -1
  146. package/build-module/navigation/index.js +3 -2
  147. package/build-module/navigation/index.js.map +1 -1
  148. package/build-module/navigation/view.js +173 -50
  149. package/build-module/navigation/view.js.map +1 -1
  150. package/build-module/page-list/convert-to-links-modal.js +3 -3
  151. package/build-module/page-list/convert-to-links-modal.js.map +1 -1
  152. package/build-module/page-list/edit.js +34 -39
  153. package/build-module/page-list/edit.js.map +1 -1
  154. package/build-module/page-list/use-convert-to-navigation-links.js +3 -16
  155. package/build-module/page-list/use-convert-to-navigation-links.js.map +1 -1
  156. package/build-module/paragraph/index.js +1 -0
  157. package/build-module/paragraph/index.js.map +1 -1
  158. package/build-module/paragraph/transforms.js +1 -0
  159. package/build-module/paragraph/transforms.js.map +1 -1
  160. package/build-module/post-comments-form/index.js +1 -0
  161. package/build-module/post-comments-form/index.js.map +1 -1
  162. package/build-module/post-navigation-link/index.js +1 -0
  163. package/build-module/post-navigation-link/index.js.map +1 -1
  164. package/build-module/post-time-to-read/index.js +5 -1
  165. package/build-module/post-time-to-read/index.js.map +1 -1
  166. package/build-module/quote/index.js +1 -0
  167. package/build-module/quote/index.js.map +1 -1
  168. package/build-module/site-logo/index.js +5 -1
  169. package/build-module/site-logo/index.js.map +1 -1
  170. package/build-module/site-tagline/index.js +5 -1
  171. package/build-module/site-tagline/index.js.map +1 -1
  172. package/build-module/site-title/index.js +5 -1
  173. package/build-module/site-title/index.js.map +1 -1
  174. package/build-module/social-links/index.js +3 -1
  175. package/build-module/social-links/index.js.map +1 -1
  176. package/build-module/table/index.js +5 -1
  177. package/build-module/table/index.js.map +1 -1
  178. package/build-module/term-description/index.js +1 -0
  179. package/build-module/term-description/index.js.map +1 -1
  180. package/build-module/verse/index.js +5 -1
  181. package/build-module/verse/index.js.map +1 -1
  182. package/build-module/video/deprecated.js +5 -1
  183. package/build-module/video/deprecated.js.map +1 -1
  184. package/build-module/video/index.js +5 -1
  185. package/build-module/video/index.js.map +1 -1
  186. package/build-style/image/style-rtl.css +16 -2
  187. package/build-style/image/style.css +16 -2
  188. package/build-style/style-rtl.css +16 -2
  189. package/build-style/style.css +16 -2
  190. package/package.json +33 -38
  191. package/src/archives/block.json +5 -1
  192. package/src/audio/block.json +5 -1
  193. package/src/block/edit.native.js +2 -2
  194. package/src/block/test/edit.native.js +4 -4
  195. package/src/categories/block.json +5 -1
  196. package/src/code/block.json +5 -1
  197. package/src/column/block.json +1 -0
  198. package/src/comments/block.json +1 -0
  199. package/src/cover/block.json +1 -0
  200. package/src/cover/edit/inspector-controls.js +1 -0
  201. package/src/details/block.json +5 -1
  202. package/src/embed/util.js +4 -6
  203. package/src/file/block.json +2 -1
  204. package/src/file/index.php +0 -17
  205. package/src/file/view.js +14 -5
  206. package/src/gallery/block.json +3 -1
  207. package/src/group/block.json +1 -0
  208. package/src/heading/block.json +5 -1
  209. package/src/heading/test/index.native.js +18 -0
  210. package/src/image/deprecated.js +597 -320
  211. package/src/image/image.js +2 -1
  212. package/src/image/save.js +2 -0
  213. package/src/image/style.scss +15 -2
  214. package/src/image/{interactivity.js → view-interactivity.js} +99 -50
  215. package/src/index.js +18 -1
  216. package/src/list/block.json +5 -1
  217. package/src/media-text/block.json +1 -0
  218. package/src/missing/edit.js +31 -11
  219. package/src/navigation/block.json +3 -2
  220. package/src/navigation/index.php +15 -20
  221. package/src/navigation/view.js +189 -67
  222. package/src/navigation-submenu/index.php +0 -10
  223. package/src/page-list/convert-to-links-modal.js +3 -3
  224. package/src/page-list/edit.js +65 -62
  225. package/src/page-list/use-convert-to-navigation-links.js +3 -20
  226. package/src/paragraph/block.json +1 -0
  227. package/src/post-comments-form/block.json +1 -0
  228. package/src/post-navigation-link/block.json +1 -0
  229. package/src/post-time-to-read/block.json +5 -1
  230. package/src/quote/block.json +1 -0
  231. package/src/site-logo/block.json +5 -1
  232. package/src/site-tagline/block.json +5 -1
  233. package/src/site-title/block.json +5 -1
  234. package/src/social-links/block.json +3 -1
  235. package/src/table/block.json +5 -1
  236. package/src/term-description/block.json +1 -0
  237. package/src/verse/block.json +5 -1
  238. package/src/video/block.json +5 -1
  239. package/build/file/interactivity.js +0 -19
  240. package/build/file/interactivity.js.map +0 -1
  241. package/build/heading/heading-level-icon.js +0 -61
  242. package/build/heading/heading-level-icon.js.map +0 -1
  243. package/build/image/interactivity.js.map +0 -1
  244. package/build/navigation/interactivity.js +0 -167
  245. package/build/navigation/interactivity.js.map +0 -1
  246. package/build/navigation/view-modal.js +0 -64
  247. package/build/navigation/view-modal.js.map +0 -1
  248. package/build/utils/interactivity/constants.js +0 -9
  249. package/build/utils/interactivity/constants.js.map +0 -1
  250. package/build/utils/interactivity/directives.js +0 -222
  251. package/build/utils/interactivity/directives.js.map +0 -1
  252. package/build/utils/interactivity/hooks.js +0 -159
  253. package/build/utils/interactivity/hooks.js.map +0 -1
  254. package/build/utils/interactivity/hydration.js +0 -34
  255. package/build/utils/interactivity/hydration.js.map +0 -1
  256. package/build/utils/interactivity/index.js +0 -32
  257. package/build/utils/interactivity/index.js.map +0 -1
  258. package/build/utils/interactivity/portals.js +0 -108
  259. package/build/utils/interactivity/portals.js.map +0 -1
  260. package/build/utils/interactivity/store.js +0 -66
  261. package/build/utils/interactivity/store.js.map +0 -1
  262. package/build/utils/interactivity/utils.js +0 -87
  263. package/build/utils/interactivity/utils.js.map +0 -1
  264. package/build/utils/interactivity/vdom.js +0 -119
  265. package/build/utils/interactivity/vdom.js.map +0 -1
  266. package/build-module/file/interactivity.js +0 -15
  267. package/build-module/file/interactivity.js.map +0 -1
  268. package/build-module/heading/heading-level-icon.js +0 -53
  269. package/build-module/heading/heading-level-icon.js.map +0 -1
  270. package/build-module/image/interactivity.js.map +0 -1
  271. package/build-module/navigation/interactivity.js +0 -164
  272. package/build-module/navigation/interactivity.js.map +0 -1
  273. package/build-module/navigation/view-modal.js +0 -58
  274. package/build-module/navigation/view-modal.js.map +0 -1
  275. package/build-module/utils/interactivity/constants.js +0 -2
  276. package/build-module/utils/interactivity/constants.js.map +0 -1
  277. package/build-module/utils/interactivity/directives.js +0 -209
  278. package/build-module/utils/interactivity/directives.js.map +0 -1
  279. package/build-module/utils/interactivity/hooks.js +0 -145
  280. package/build-module/utils/interactivity/hooks.js.map +0 -1
  281. package/build-module/utils/interactivity/hydration.js +0 -21
  282. package/build-module/utils/interactivity/hydration.js.map +0 -1
  283. package/build-module/utils/interactivity/index.js +0 -15
  284. package/build-module/utils/interactivity/index.js.map +0 -1
  285. package/build-module/utils/interactivity/portals.js +0 -100
  286. package/build-module/utils/interactivity/portals.js.map +0 -1
  287. package/build-module/utils/interactivity/store.js +0 -55
  288. package/build-module/utils/interactivity/store.js.map +0 -1
  289. package/build-module/utils/interactivity/utils.js +0 -75
  290. package/build-module/utils/interactivity/utils.js.map +0 -1
  291. package/build-module/utils/interactivity/vdom.js +0 -107
  292. package/build-module/utils/interactivity/vdom.js.map +0 -1
  293. package/src/file/interactivity.js +0 -15
  294. package/src/heading/heading-level-icon.js +0 -48
  295. package/src/navigation/interactivity.js +0 -169
  296. package/src/navigation/view-modal.js +0 -78
  297. package/src/utils/interactivity/constants.js +0 -1
  298. package/src/utils/interactivity/directives.js +0 -200
  299. package/src/utils/interactivity/hooks.js +0 -145
  300. package/src/utils/interactivity/hydration.js +0 -22
  301. package/src/utils/interactivity/index.js +0 -15
  302. package/src/utils/interactivity/portals.js +0 -98
  303. package/src/utils/interactivity/store.js +0 -45
  304. package/src/utils/interactivity/utils.js +0 -66
  305. package/src/utils/interactivity/vdom.js +0 -111
@@ -1,75 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import { useRef, useEffect } from 'preact/hooks';
5
- import { effect } from '@preact/signals';
6
-
7
- function afterNextFrame(callback) {
8
- const done = () => {
9
- window.cancelAnimationFrame(raf);
10
- setTimeout(callback);
11
- };
12
-
13
- const raf = window.requestAnimationFrame(done);
14
- } // Using the mangled properties:
15
- // this.c: this._callback
16
- // this.x: this._compute
17
- // https://github.com/preactjs/signals/blob/main/mangle.json
18
-
19
-
20
- function createFlusher(compute, notify) {
21
- let flush;
22
- const dispose = effect(function () {
23
- flush = this.c.bind(this);
24
- this.x = compute;
25
- this.c = notify;
26
- return compute();
27
- });
28
- return {
29
- flush,
30
- dispose
31
- };
32
- } // Version of `useSignalEffect` with a `useEffect`-like execution. This hook
33
- // implementation comes from this PR:
34
- // https://github.com/preactjs/signals/pull/290.
35
- //
36
- // We need to include it here in this repo until the mentioned PR is merged.
37
-
38
-
39
- export function useSignalEffect(cb) {
40
- const callback = useRef(cb);
41
- callback.current = cb;
42
- useEffect(() => {
43
- const execute = () => callback.current();
44
-
45
- const notify = () => afterNextFrame(eff.flush);
46
-
47
- const eff = createFlusher(execute, notify);
48
- return eff.dispose;
49
- }, []);
50
- } // For wrapperless hydration.
51
- // See https://gist.github.com/developit/f4c67a2ede71dc2fab7f357f39cff28c
52
-
53
- export const createRootFragment = (parent, replaceNode) => {
54
- replaceNode = [].concat(replaceNode);
55
- const s = replaceNode[replaceNode.length - 1].nextSibling;
56
-
57
- function insert(c, r) {
58
- parent.insertBefore(c, r || s);
59
- }
60
-
61
- return parent.__k = {
62
- nodeType: 1,
63
- parentNode: parent,
64
- firstChild: replaceNode[0],
65
- childNodes: replaceNode,
66
- insertBefore: insert,
67
- appendChild: insert,
68
-
69
- removeChild(c) {
70
- parent.removeChild(c);
71
- }
72
-
73
- };
74
- };
75
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["@wordpress/block-library/src/utils/interactivity/utils.js"],"names":["useRef","useEffect","effect","afterNextFrame","callback","done","window","cancelAnimationFrame","raf","setTimeout","requestAnimationFrame","createFlusher","compute","notify","flush","dispose","c","bind","x","useSignalEffect","cb","current","execute","eff","createRootFragment","parent","replaceNode","concat","s","length","nextSibling","insert","r","insertBefore","__k","nodeType","parentNode","firstChild","childNodes","appendChild","removeChild"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,MAAT,EAAiBC,SAAjB,QAAkC,cAAlC;AACA,SAASC,MAAT,QAAuB,iBAAvB;;AAEA,SAASC,cAAT,CAAyBC,QAAzB,EAAoC;AACnC,QAAMC,IAAI,GAAG,MAAM;AAClBC,IAAAA,MAAM,CAACC,oBAAP,CAA6BC,GAA7B;AACAC,IAAAA,UAAU,CAAEL,QAAF,CAAV;AACA,GAHD;;AAIA,QAAMI,GAAG,GAAGF,MAAM,CAACI,qBAAP,CAA8BL,IAA9B,CAAZ;AACA,C,CAED;AACA;AACA;AACA;;;AACA,SAASM,aAAT,CAAwBC,OAAxB,EAAiCC,MAAjC,EAA0C;AACzC,MAAIC,KAAJ;AACA,QAAMC,OAAO,GAAGb,MAAM,CAAE,YAAY;AACnCY,IAAAA,KAAK,GAAG,KAAKE,CAAL,CAAOC,IAAP,CAAa,IAAb,CAAR;AACA,SAAKC,CAAL,GAASN,OAAT;AACA,SAAKI,CAAL,GAASH,MAAT;AACA,WAAOD,OAAO,EAAd;AACA,GALqB,CAAtB;AAMA,SAAO;AAAEE,IAAAA,KAAF;AAASC,IAAAA;AAAT,GAAP;AACA,C,CAED;AACA;AACA;AACA;AACA;;;AACA,OAAO,SAASI,eAAT,CAA0BC,EAA1B,EAA+B;AACrC,QAAMhB,QAAQ,GAAGJ,MAAM,CAAEoB,EAAF,CAAvB;AACAhB,EAAAA,QAAQ,CAACiB,OAAT,GAAmBD,EAAnB;AAEAnB,EAAAA,SAAS,CAAE,MAAM;AAChB,UAAMqB,OAAO,GAAG,MAAMlB,QAAQ,CAACiB,OAAT,EAAtB;;AACA,UAAMR,MAAM,GAAG,MAAMV,cAAc,CAAEoB,GAAG,CAACT,KAAN,CAAnC;;AACA,UAAMS,GAAG,GAAGZ,aAAa,CAAEW,OAAF,EAAWT,MAAX,CAAzB;AACA,WAAOU,GAAG,CAACR,OAAX;AACA,GALQ,EAKN,EALM,CAAT;AAMA,C,CAED;AACA;;AACA,OAAO,MAAMS,kBAAkB,GAAG,CAAEC,MAAF,EAAUC,WAAV,KAA2B;AAC5DA,EAAAA,WAAW,GAAG,GAAGC,MAAH,CAAWD,WAAX,CAAd;AACA,QAAME,CAAC,GAAGF,WAAW,CAAEA,WAAW,CAACG,MAAZ,GAAqB,CAAvB,CAAX,CAAsCC,WAAhD;;AACA,WAASC,MAAT,CAAiBf,CAAjB,EAAoBgB,CAApB,EAAwB;AACvBP,IAAAA,MAAM,CAACQ,YAAP,CAAqBjB,CAArB,EAAwBgB,CAAC,IAAIJ,CAA7B;AACA;;AACD,SAASH,MAAM,CAACS,GAAP,GAAa;AACrBC,IAAAA,QAAQ,EAAE,CADW;AAErBC,IAAAA,UAAU,EAAEX,MAFS;AAGrBY,IAAAA,UAAU,EAAEX,WAAW,CAAE,CAAF,CAHF;AAIrBY,IAAAA,UAAU,EAAEZ,WAJS;AAKrBO,IAAAA,YAAY,EAAEF,MALO;AAMrBQ,IAAAA,WAAW,EAAER,MANQ;;AAOrBS,IAAAA,WAAW,CAAExB,CAAF,EAAM;AAChBS,MAAAA,MAAM,CAACe,WAAP,CAAoBxB,CAApB;AACA;;AAToB,GAAtB;AAWA,CAjBM","sourcesContent":["/**\n * External dependencies\n */\nimport { useRef, useEffect } from 'preact/hooks';\nimport { effect } from '@preact/signals';\n\nfunction afterNextFrame( callback ) {\n\tconst done = () => {\n\t\twindow.cancelAnimationFrame( raf );\n\t\tsetTimeout( callback );\n\t};\n\tconst raf = window.requestAnimationFrame( done );\n}\n\n// Using the mangled properties:\n// this.c: this._callback\n// this.x: this._compute\n// https://github.com/preactjs/signals/blob/main/mangle.json\nfunction createFlusher( compute, notify ) {\n\tlet flush;\n\tconst dispose = effect( function () {\n\t\tflush = this.c.bind( this );\n\t\tthis.x = compute;\n\t\tthis.c = notify;\n\t\treturn compute();\n\t} );\n\treturn { flush, dispose };\n}\n\n// Version of `useSignalEffect` with a `useEffect`-like execution. This hook\n// implementation comes from this PR:\n// https://github.com/preactjs/signals/pull/290.\n//\n// We need to include it here in this repo until the mentioned PR is merged.\nexport function useSignalEffect( cb ) {\n\tconst callback = useRef( cb );\n\tcallback.current = cb;\n\n\tuseEffect( () => {\n\t\tconst execute = () => callback.current();\n\t\tconst notify = () => afterNextFrame( eff.flush );\n\t\tconst eff = createFlusher( execute, notify );\n\t\treturn eff.dispose;\n\t}, [] );\n}\n\n// For wrapperless hydration.\n// See https://gist.github.com/developit/f4c67a2ede71dc2fab7f357f39cff28c\nexport const createRootFragment = ( parent, replaceNode ) => {\n\treplaceNode = [].concat( replaceNode );\n\tconst s = replaceNode[ replaceNode.length - 1 ].nextSibling;\n\tfunction insert( c, r ) {\n\t\tparent.insertBefore( c, r || s );\n\t}\n\treturn ( parent.__k = {\n\t\tnodeType: 1,\n\t\tparentNode: parent,\n\t\tfirstChild: replaceNode[ 0 ],\n\t\tchildNodes: replaceNode,\n\t\tinsertBefore: insert,\n\t\tappendChild: insert,\n\t\tremoveChild( c ) {\n\t\t\tparent.removeChild( c );\n\t\t},\n\t} );\n};\n"]}
@@ -1,107 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import { h } from 'preact';
5
- /**
6
- * Internal dependencies
7
- */
8
-
9
- import { directivePrefix as p } from './constants';
10
- const ignoreAttr = `data-${p}-ignore`;
11
- const islandAttr = `data-${p}-interactive`;
12
- const fullPrefix = `data-${p}-`; // Regular expression for directive parsing.
13
-
14
- const directiveParser = new RegExp(`^data-${p}-` + // ${p} must be a prefix string, like 'wp'.
15
- // Match alphanumeric characters including hyphen-separated
16
- // segments. It excludes underscore intentionally to prevent confusion.
17
- // E.g., "custom-directive".
18
- '([a-z0-9]+(?:-[a-z0-9]+)*)' + // (Optional) Match '--' followed by any alphanumeric charachters. It
19
- // excludes underscore intentionally to prevent confusion, but it can
20
- // contain multiple hyphens. E.g., "--custom-prefix--with-more-info".
21
- '(?:--([a-z0-9][a-z0-9-]+))?$', 'i' // Case insensitive.
22
- );
23
- export const hydratedIslands = new WeakSet(); // Recursive function that transforms a DOM tree into vDOM.
24
-
25
- export function toVdom(root) {
26
- const treeWalker = document.createTreeWalker(root, 205 // ELEMENT + TEXT + COMMENT + CDATA_SECTION + PROCESSING_INSTRUCTION
27
- );
28
-
29
- function walk(node) {
30
- const {
31
- attributes,
32
- nodeType
33
- } = node;
34
- if (nodeType === 3) return [node.data];
35
-
36
- if (nodeType === 4) {
37
- const next = treeWalker.nextSibling();
38
- node.replaceWith(new window.Text(node.nodeValue));
39
- return [node.nodeValue, next];
40
- }
41
-
42
- if (nodeType === 8 || nodeType === 7) {
43
- const next = treeWalker.nextSibling();
44
- node.remove();
45
- return [null, next];
46
- }
47
-
48
- const props = {};
49
- const children = [];
50
- const directives = {};
51
- let hasDirectives = false;
52
- let ignore = false;
53
- let island = false;
54
-
55
- for (let i = 0; i < attributes.length; i++) {
56
- const n = attributes[i].name;
57
-
58
- if (n[fullPrefix.length] && n.slice(0, fullPrefix.length) === fullPrefix) {
59
- if (n === ignoreAttr) {
60
- ignore = true;
61
- } else if (n === islandAttr) {
62
- island = true;
63
- } else {
64
- hasDirectives = true;
65
- let val = attributes[i].value;
66
-
67
- try {
68
- val = JSON.parse(val);
69
- } catch (e) {}
70
-
71
- const [, prefix, suffix] = directiveParser.exec(n);
72
- directives[prefix] = directives[prefix] || {};
73
- directives[prefix][suffix || 'default'] = val;
74
- }
75
- } else if (n === 'ref') {
76
- continue;
77
- }
78
-
79
- props[n] = attributes[i].value;
80
- }
81
-
82
- if (ignore && !island) return [h(node.localName, { ...props,
83
- innerHTML: node.innerHTML,
84
- __directives: {
85
- ignore: true
86
- }
87
- })];
88
- if (island) hydratedIslands.add(node);
89
- if (hasDirectives) props.__directives = directives;
90
- let child = treeWalker.firstChild();
91
-
92
- if (child) {
93
- while (child) {
94
- const [vnode, nextChild] = walk(child);
95
- if (vnode) children.push(vnode);
96
- child = nextChild || treeWalker.nextSibling();
97
- }
98
-
99
- treeWalker.parentNode();
100
- }
101
-
102
- return [h(node.localName, props, children)];
103
- }
104
-
105
- return walk(treeWalker.currentNode);
106
- }
107
- //# sourceMappingURL=vdom.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["@wordpress/block-library/src/utils/interactivity/vdom.js"],"names":["h","directivePrefix","p","ignoreAttr","islandAttr","fullPrefix","directiveParser","RegExp","hydratedIslands","WeakSet","toVdom","root","treeWalker","document","createTreeWalker","walk","node","attributes","nodeType","data","next","nextSibling","replaceWith","window","Text","nodeValue","remove","props","children","directives","hasDirectives","ignore","island","i","length","n","name","slice","val","value","JSON","parse","e","prefix","suffix","exec","localName","innerHTML","__directives","add","child","firstChild","vnode","nextChild","push","parentNode","currentNode"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,CAAT,QAAkB,QAAlB;AACA;AACA;AACA;;AACA,SAASC,eAAe,IAAIC,CAA5B,QAAqC,aAArC;AAEA,MAAMC,UAAU,GAAI,QAAQD,CAAG,SAA/B;AACA,MAAME,UAAU,GAAI,QAAQF,CAAG,cAA/B;AACA,MAAMG,UAAU,GAAI,QAAQH,CAAG,GAA/B,C,CAEA;;AACA,MAAMI,eAAe,GAAG,IAAIC,MAAJ,CACtB,SAASL,CAAG,GAAb,GAAkB;AACjB;AACA;AACA;AACA,4BAJD,GAKC;AACA;AACA;AACA,8BATsB,EAUvB,GAVuB,CAUnB;AAVmB,CAAxB;AAaA,OAAO,MAAMM,eAAe,GAAG,IAAIC,OAAJ,EAAxB,C,CAEP;;AACA,OAAO,SAASC,MAAT,CAAiBC,IAAjB,EAAwB;AAC9B,QAAMC,UAAU,GAAGC,QAAQ,CAACC,gBAAT,CAClBH,IADkB,EAElB,GAFkB,CAEd;AAFc,GAAnB;;AAKA,WAASI,IAAT,CAAeC,IAAf,EAAsB;AACrB,UAAM;AAAEC,MAAAA,UAAF;AAAcC,MAA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EAAaxB,QAAQ,CAAC0B,IAAT,CAAeF,KAAf;AACbF,QAAAA,KAAK,GAAGG,SAAS,IAAIzC,UAAU,CAACS,WAAX,EAArB;AACA;;AACDT,MAAAA,UAAU,CAAC2C,UAAX;AACA;;AAED,WAAO,CAAEvD,CAAC,CAAEgB,IAAI,CAAC8B,SAAP,EAAkBnB,KAAlB,EAAyBC,QAAzB,CAAH,CAAP;AACA;;AAED,SAAOb,IAAI,CAAEH,UAAU,CAAC4C,WAAb,CAAX;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { h } from 'preact';\n/**\n * Internal dependencies\n */\nimport { directivePrefix as p } from './constants';\n\nconst ignoreAttr = `data-${ p }-ignore`;\nconst islandAttr = `data-${ p }-interactive`;\nconst fullPrefix = `data-${ p }-`;\n\n// Regular expression for directive parsing.\nconst directiveParser = new RegExp(\n\t`^data-${ p }-` + // ${p} must be a prefix string, like 'wp'.\n\t\t// Match alphanumeric characters including hyphen-separated\n\t\t// segments. It excludes underscore intentionally to prevent confusion.\n\t\t// E.g., \"custom-directive\".\n\t\t'([a-z0-9]+(?:-[a-z0-9]+)*)' +\n\t\t// (Optional) Match '--' followed by any alphanumeric charachters. It\n\t\t// excludes underscore intentionally to prevent confusion, but it can\n\t\t// contain multiple hyphens. E.g., \"--custom-prefix--with-more-info\".\n\t\t'(?:--([a-z0-9][a-z0-9-]+))?$',\n\t'i' // Case insensitive.\n);\n\nexport const hydratedIslands = new WeakSet();\n\n// Recursive function that transforms a DOM tree into vDOM.\nexport function toVdom( root ) {\n\tconst treeWalker = document.createTreeWalker(\n\t\troot,\n\t\t205 // ELEMENT + TEXT + COMMENT + CDATA_SECTION + PROCESSING_INSTRUCTION\n\t);\n\n\tfunction walk( node ) {\n\t\tconst { attributes, nodeType } = node;\n\n\t\tif ( nodeType === 3 ) return [ node.data ];\n\t\tif ( nodeType === 4 ) {\n\t\t\tconst next = treeWalker.nextSibling();\n\t\t\tnode.replaceWith( new window.Text( node.nodeValue ) );\n\t\t\treturn [ node.nodeValue, next ];\n\t\t}\n\t\tif ( nodeType === 8 || nodeType === 7 ) {\n\t\t\tconst next = treeWalker.nextSibling();\n\t\t\tnode.remove();\n\t\t\treturn [ null, next ];\n\t\t}\n\n\t\tconst props = {};\n\t\tconst children = [];\n\t\tconst directives = {};\n\t\tlet hasDirectives = false;\n\t\tlet ignore = false;\n\t\tlet island = false;\n\n\t\tfor ( let i = 0; i < attributes.length; i++ ) {\n\t\t\tconst n = attributes[ i ].name;\n\t\t\tif (\n\t\t\t\tn[ fullPrefix.length ] &&\n\t\t\t\tn.slice( 0, fullPrefix.length ) === fullPrefix\n\t\t\t) {\n\t\t\t\tif ( n === ignoreAttr ) {\n\t\t\t\t\tignore = true;\n\t\t\t\t} else if ( n === islandAttr ) {\n\t\t\t\t\tisland = true;\n\t\t\t\t} else {\n\t\t\t\t\thasDirectives = true;\n\t\t\t\t\tlet val = attributes[ i ].value;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tval = JSON.parse( val );\n\t\t\t\t\t} catch ( e ) {}\n\t\t\t\t\tconst [ , prefix, suffix ] = directiveParser.exec( n );\n\t\t\t\t\tdirectives[ prefix ] = directives[ prefix ] || {};\n\t\t\t\t\tdirectives[ prefix ][ suffix || 'default' ] = val;\n\t\t\t\t}\n\t\t\t} else if ( n === 'ref' ) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tprops[ n ] = attributes[ i ].value;\n\t\t}\n\n\t\tif ( ignore && ! island )\n\t\t\treturn [\n\t\t\t\th( node.localName, {\n\t\t\t\t\t...props,\n\t\t\t\t\tinnerHTML: node.innerHTML,\n\t\t\t\t\t__directives: { ignore: true },\n\t\t\t\t} ),\n\t\t\t];\n\t\tif ( island ) hydratedIslands.add( node );\n\n\t\tif ( hasDirectives ) props.__directives = directives;\n\n\t\tlet child = treeWalker.firstChild();\n\t\tif ( child ) {\n\t\t\twhile ( child ) {\n\t\t\t\tconst [ vnode, nextChild ] = walk( child );\n\t\t\t\tif ( vnode ) children.push( vnode );\n\t\t\t\tchild = nextChild || treeWalker.nextSibling();\n\t\t\t}\n\t\t\ttreeWalker.parentNode();\n\t\t}\n\n\t\treturn [ h( node.localName, props, children ) ];\n\t}\n\n\treturn walk( treeWalker.currentNode );\n}\n"]}
@@ -1,15 +0,0 @@
1
- /**
2
- * Internal dependencies
3
- */
4
- import { store } from '../utils/interactivity';
5
- import { browserSupportsPdfs as hasPdfPreview } from './utils';
6
-
7
- store( {
8
- selectors: {
9
- core: {
10
- file: {
11
- hasPdfPreview,
12
- },
13
- },
14
- },
15
- } );
@@ -1,48 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { Path, SVG } from '@wordpress/components';
5
-
6
- /** @typedef {import('@wordpress/element').WPComponent} WPComponent */
7
-
8
- /**
9
- * HeadingLevelIcon props.
10
- *
11
- * @typedef WPHeadingLevelIconProps
12
- *
13
- * @property {number} level The heading level to show an icon for.
14
- * @property {?boolean} isPressed Whether or not the icon should appear pressed; default: false.
15
- */
16
-
17
- /**
18
- * Heading level icon.
19
- *
20
- * @param {WPHeadingLevelIconProps} props Component props.
21
- *
22
- * @return {?WPComponent} The icon.
23
- */
24
- export default function HeadingLevelIcon( { level, isPressed = false } ) {
25
- const levelToPath = {
26
- 1: 'M9 5h2v10H9v-4H5v4H3V5h2v4h4V5zm6.6 0c-.6.9-1.5 1.7-2.6 2v1h2v7h2V5h-1.4z',
27
- 2: 'M7 5h2v10H7v-4H3v4H1V5h2v4h4V5zm8 8c.5-.4.6-.6 1.1-1.1.4-.4.8-.8 1.2-1.3.3-.4.6-.8.9-1.3.2-.4.3-.8.3-1.3 0-.4-.1-.9-.3-1.3-.2-.4-.4-.7-.8-1-.3-.3-.7-.5-1.2-.6-.5-.2-1-.2-1.5-.2-.4 0-.7 0-1.1.1-.3.1-.7.2-1 .3-.3.1-.6.3-.9.5-.3.2-.6.4-.8.7l1.2 1.2c.3-.3.6-.5 1-.7.4-.2.7-.3 1.2-.3s.9.1 1.3.4c.3.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-.2.4-.5.8-.9 1.1-.4.3-.8.5-1.3.7-.5.2-1 .3-1.5.3-.8 0-1.6-.1-2.3-.4-.6-.2-1.1-.6-1.6-1-.1-.1 1-1.5 1-1.5zM9 15H7v-4H3v4H1V5h2v4h4V5h2v10z',
31
- 6: 'M9 15H7v-4H3v4H1V5h2v4h4V5h2v10zm8.6-7.5c-.2-.2-.5-.4-.8-.5-.6-.2-1.3-.2-1.9 0-.3.1-.6.3-.8.5l-.6.9c-.2.5-.2.9-.2 1.4.4-.3.8-.6 1.2-.8.4-.2.8-.3 1.3-.3.4 0 .8 0 1.2.2.4.1.7.3 1 .6.3.3.5.6.7.9.2.4.3.8.3 1.3s-.1.9-.3 1.4c-.2.4-.5.7-.8 1-.4.3-.8.5-1.2.6-1 .3-2 .3-3 0-.5-.2-1-.5-1.4-.9-.4-.4-.8-.9-1-1.5-.2-.6-.3-1.3-.3-2.1s.1-1.6.4-2.3c.2-.6.6-1.2 1-1.6.4-.4.9-.7 1.4-.9.6-.3 1.1-.4 1.7-.4.7 0 1.4.1 2 .3.5.2 1 .5 1.4.8 0 .1-1.3 1.4-1.3 1.4zm-2.4 5.8c.2 0 .4 0 .6-.1.2 0 .4-.1.5-.2.1-.1.3-.3.4-.5.1-.2.1-.5.1-.7 0-.4-.1-.8-.4-1.1-.3-.2-.7-.3-1.1-.3-.3 0-.7.1-1 .2-.4.2-.7.4-1 .7 0 .3.1.7.3 1 .1.2.3.4.4.6.2.1.3.3.5.3.2.1.5.2.7.1z',
32
- };
33
- if ( ! levelToPath.hasOwnProperty( level ) ) {
34
- return null;
35
- }
36
-
37
- return (
38
- <SVG
39
- width="24"
40
- height="24"
41
- viewBox="0 0 20 20"
42
- xmlns="http://www.w3.org/2000/svg"
43
- isPressed={ isPressed }
44
- >
45
- <Path d={ levelToPath[ level ] } />
46
- </SVG>
47
- );
48
- }
@@ -1,169 +0,0 @@
1
- /**
2
- * Internal dependencies
3
- */
4
- import { store } from '../utils/interactivity';
5
-
6
- const focusableSelectors = [
7
- 'a[href]',
8
- 'area[href]',
9
- 'input:not([disabled]):not([type="hidden"]):not([aria-hidden])',
10
- 'select:not([disabled]):not([aria-hidden])',
11
- 'textarea:not([disabled]):not([aria-hidden])',
12
- 'button:not([disabled]):not([aria-hidden])',
13
- 'iframe',
14
- 'object',
15
- 'embed',
16
- '[contenteditable]',
17
- '[tabindex]:not([tabindex^="-"])',
18
- ];
19
-
20
- const openMenu = ( { context, ref }, menuOpenedOn ) => {
21
- context.core.navigation.isMenuOpen[ menuOpenedOn ] = true;
22
- context.core.navigation.previousFocus = ref;
23
- if ( context.core.navigation.overlay ) {
24
- // Add a `has-modal-open` class to the <html> root.
25
- document.documentElement.classList.add( 'has-modal-open' );
26
- }
27
- };
28
-
29
- const closeMenu = ( { context, selectors }, menuClosedOn ) => {
30
- context.core.navigation.isMenuOpen[ menuClosedOn ] = false;
31
- // Check if the menu is still open or not.
32
- if ( ! selectors.core.navigation.isMenuOpen( { context } ) ) {
33
- if (
34
- context.core.navigation.modal.contains(
35
- window.document.activeElement
36
- )
37
- ) {
38
- context.core.navigation.previousFocus.focus();
39
- }
40
- context.core.navigation.modal = null;
41
- context.core.navigation.previousFocus = null;
42
- if ( context.core.navigation.overlay ) {
43
- document.documentElement.classList.remove( 'has-modal-open' );
44
- }
45
- }
46
- };
47
-
48
- store( {
49
- effects: {
50
- core: {
51
- navigation: {
52
- initMenu: ( { context, selectors, ref } ) => {
53
- if ( selectors.core.navigation.isMenuOpen( { context } ) ) {
54
- const focusableElements =
55
- ref.querySelectorAll( focusableSelectors );
56
- context.core.navigation.modal = ref;
57
- context.core.navigation.firstFocusableElement =
58
- focusableElements[ 0 ];
59
- context.core.navigation.lastFocusableElement =
60
- focusableElements[ focusableElements.length - 1 ];
61
- }
62
- },
63
- focusFirstElement: ( { context, selectors, ref } ) => {
64
- if ( selectors.core.navigation.isMenuOpen( { context } ) ) {
65
- ref.querySelector(
66
- '.wp-block-navigation-item > *:first-child'
67
- ).focus();
68
- }
69
- },
70
- },
71
- },
72
- },
73
- selectors: {
74
- core: {
75
- navigation: {
76
- roleAttribute: ( { context, selectors } ) =>
77
- context.core.navigation.overlay &&
78
- selectors.core.navigation.isMenuOpen( { context } )
79
- ? 'dialog'
80
- : '',
81
- isMenuOpen: ( { context } ) =>
82
- // The menu is opened if either `click` or `hover` is true.
83
- Object.values( context.core.navigation.isMenuOpen ).filter(
84
- Boolean
85
- ).length > 0,
86
- },
87
- },
88
- },
89
- actions: {
90
- core: {
91
- navigation: {
92
- openMenuOnHover( args ) {
93
- openMenu( args, 'hover' );
94
- },
95
- closeMenuOnHover( args ) {
96
- closeMenu( args, 'hover' );
97
- },
98
- openMenuOnClick( args ) {
99
- openMenu( args, 'click' );
100
- },
101
- closeMenuOnClick( args ) {
102
- closeMenu( args, 'click' );
103
- },
104
- toggleMenuOnClick: ( args ) => {
105
- const { context } = args;
106
- if ( context.core.navigation.isMenuOpen.click ) {
107
- closeMenu( args, 'click' );
108
- } else {
109
- openMenu( args, 'click' );
110
- }
111
- },
112
- handleMenuKeydown: ( args ) => {
113
- const { context, event } = args;
114
- if ( context.core.navigation.isMenuOpen.click ) {
115
- // If Escape close the menu
116
- if (
117
- event?.key === 'Escape' ||
118
- event?.keyCode === 27
119
- ) {
120
- closeMenu( args, 'click' );
121
- return;
122
- }
123
-
124
- // Trap focus if it is an overlay (main menu)
125
- if (
126
- context.core.navigation.overlay &&
127
- ( event.key === 'Tab' || event.keyCode === 9 )
128
- ) {
129
- // If shift + tab it change the direction
130
- if (
131
- event.shiftKey &&
132
- window.document.activeElement ===
133
- context.core.navigation
134
- .firstFocusableElement
135
- ) {
136
- event.preventDefault();
137
- context.core.navigation.lastFocusableElement.focus();
138
- } else if (
139
- ! event.shiftKey &&
140
- window.document.activeElement ===
141
- context.core.navigation.lastFocusableElement
142
- ) {
143
- event.preventDefault();
144
- context.core.navigation.firstFocusableElement.focus();
145
- }
146
- }
147
- }
148
- },
149
- handleMenuFocusout: ( args ) => {
150
- const { context, event } = args;
151
- // If focus is outside modal, and in the document, close menu
152
- // event.target === The element losing focus
153
- // event.relatedTarget === The element receiving focus (if any)
154
- // When focusout is outsite the document,
155
- // `window.document.activeElement` doesn't change
156
- if (
157
- context.core.navigation.isMenuOpen.click &&
158
- ! context.core.navigation.modal.contains(
159
- event.relatedTarget
160
- ) &&
161
- event.target !== window.document.activeElement
162
- ) {
163
- closeMenu( args, 'click' );
164
- }
165
- },
166
- },
167
- },
168
- },
169
- } );
@@ -1,78 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import MicroModal from 'micromodal';
5
-
6
- // Responsive navigation toggle.
7
- function navigationToggleModal( modal ) {
8
- const dialogContainer = modal.querySelector(
9
- `.wp-block-navigation__responsive-dialog`
10
- );
11
-
12
- const isHidden = 'true' === modal.getAttribute( 'aria-hidden' );
13
-
14
- modal.classList.toggle( 'has-modal-open', ! isHidden );
15
- dialogContainer.toggleAttribute( 'aria-modal', ! isHidden );
16
-
17
- if ( isHidden ) {
18
- dialogContainer.removeAttribute( 'role' );
19
- dialogContainer.removeAttribute( 'aria-modal' );
20
- } else {
21
- dialogContainer.setAttribute( 'role', 'dialog' );
22
- dialogContainer.setAttribute( 'aria-modal', 'true' );
23
- }
24
-
25
- // Add a class to indicate the modal is open.
26
- const htmlElement = document.documentElement;
27
- htmlElement.classList.toggle( 'has-modal-open' );
28
- }
29
-
30
- function isLinkToAnchorOnCurrentPage( node ) {
31
- return (
32
- node.hash &&
33
- node.protocol === window.location.protocol &&
34
- node.host === window.location.host &&
35
- node.pathname === window.location.pathname &&
36
- node.search === window.location.search
37
- );
38
- }
39
-
40
- window.addEventListener( 'load', () => {
41
- MicroModal.init( {
42
- onShow: navigationToggleModal,
43
- onClose: navigationToggleModal,
44
- openClass: 'is-menu-open',
45
- } );
46
-
47
- // Close modal automatically on clicking anchor links inside modal.
48
- const navigationLinks = document.querySelectorAll(
49
- '.wp-block-navigation-item__content'
50
- );
51
-
52
- navigationLinks.forEach( function ( link ) {
53
- // Ignore non-anchor links and anchor links which open on a new tab.
54
- if (
55
- ! isLinkToAnchorOnCurrentPage( link ) ||
56
- link.attributes?.target === '_blank'
57
- ) {
58
- return;
59
- }
60
-
61
- // Find the specific parent modal for this link
62
- // since .close() won't work without an ID if there are
63
- // multiple navigation menus in a post/page.
64
- const modal = link.closest(
65
- '.wp-block-navigation__responsive-container'
66
- );
67
- const modalId = modal?.getAttribute( 'id' );
68
-
69
- link.addEventListener( 'click', () => {
70
- // check if modal exists and is open before trying to close it
71
- // otherwise Micromodal will toggle the `has-modal-open` class
72
- // on the html tag which prevents scrolling
73
- if ( modalId && modal.classList.contains( 'has-modal-open' ) ) {
74
- MicroModal.close( modalId );
75
- }
76
- } );
77
- } );
78
- } );
@@ -1 +0,0 @@
1
- export const directivePrefix = 'wp';