@wordpress/block-library 8.9.0 → 8.10.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 (284) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/comment-author-name/edit.js +1 -1
  3. package/build/comment-author-name/edit.js.map +1 -1
  4. package/build/comment-edit-link/edit.js +1 -1
  5. package/build/comment-edit-link/edit.js.map +1 -1
  6. package/build/cover/edit/inspector-controls.js +1 -1
  7. package/build/cover/edit/inspector-controls.js.map +1 -1
  8. package/build/cover/index.js +1 -1
  9. package/build/cover/variations.js +1 -1
  10. package/build/cover/variations.js.map +1 -1
  11. package/build/details/edit.js +19 -5
  12. package/build/details/edit.js.map +1 -1
  13. package/build/details/index.js +14 -10
  14. package/build/details/index.js.map +1 -1
  15. package/build/details/save.js +4 -1
  16. package/build/details/save.js.map +1 -1
  17. package/build/embed/variations.js +2 -2
  18. package/build/embed/variations.js.map +1 -1
  19. package/build/file/view.js +1 -1
  20. package/build/file/view.js.map +1 -1
  21. package/build/gallery/edit.js +2 -8
  22. package/build/gallery/edit.js.map +1 -1
  23. package/build/index.js +0 -6
  24. package/build/index.js.map +1 -1
  25. package/build/index.native.js +1 -1
  26. package/build/index.native.js.map +1 -1
  27. package/build/list-item/utils.js +5 -1
  28. package/build/list-item/utils.js.map +1 -1
  29. package/build/loginout/index.js +11 -1
  30. package/build/loginout/index.js.map +1 -1
  31. package/build/navigation/constants.js +13 -0
  32. package/build/navigation/constants.js.map +1 -0
  33. package/build/navigation/edit/index.js +16 -26
  34. package/build/navigation/edit/index.js.map +1 -1
  35. package/build/navigation/edit/inner-blocks.js +4 -7
  36. package/build/navigation/edit/inner-blocks.js.map +1 -1
  37. package/build/navigation/edit/unsaved-inner-blocks.js +4 -6
  38. package/build/navigation/edit/unsaved-inner-blocks.js.map +1 -1
  39. package/build/navigation/edit/use-convert-classic-menu-to-block-menu.js +1 -1
  40. package/build/navigation/edit/use-convert-classic-menu-to-block-menu.js.map +1 -1
  41. package/build/navigation/interactivity.js +139 -0
  42. package/build/navigation/interactivity.js.map +1 -0
  43. package/build/navigation-link/edit.js +1 -1
  44. package/build/navigation-link/edit.js.map +1 -1
  45. package/build/navigation-submenu/edit.js +1 -1
  46. package/build/navigation-submenu/edit.js.map +1 -1
  47. package/build/paragraph/index.js +5 -1
  48. package/build/paragraph/index.js.map +1 -1
  49. package/build/paragraph/transforms.js +5 -1
  50. package/build/paragraph/transforms.js.map +1 -1
  51. package/build/post-author-name/edit.js +1 -1
  52. package/build/post-author-name/edit.js.map +1 -1
  53. package/build/post-featured-image/edit.js +1 -2
  54. package/build/post-featured-image/edit.js.map +1 -1
  55. package/build/post-featured-image/overlay.js +5 -0
  56. package/build/post-featured-image/overlay.js.map +1 -1
  57. package/build/post-title/edit.js +14 -4
  58. package/build/post-title/edit.js.map +1 -1
  59. package/build/preformatted/edit.native.js +3 -2
  60. package/build/preformatted/edit.native.js.map +1 -1
  61. package/build/quote/transforms.js +16 -27
  62. package/build/quote/transforms.js.map +1 -1
  63. package/build/read-more/edit.js +1 -1
  64. package/build/read-more/edit.js.map +1 -1
  65. package/build/search/edit.js +9 -1
  66. package/build/search/edit.js.map +1 -1
  67. package/build/site-title/edit/index.js +1 -1
  68. package/build/site-title/edit/index.js.map +1 -1
  69. package/build/social-links/edit.js +2 -2
  70. package/build/social-links/edit.js.map +1 -1
  71. package/build/utils/interactivity/constants.js +9 -0
  72. package/build/utils/interactivity/constants.js.map +1 -0
  73. package/build/utils/interactivity/directives.js +208 -0
  74. package/build/utils/interactivity/directives.js.map +1 -0
  75. package/build/utils/interactivity/hooks.js +112 -0
  76. package/build/utils/interactivity/hooks.js.map +1 -0
  77. package/build/utils/interactivity/hydration.js +34 -0
  78. package/build/utils/interactivity/hydration.js.map +1 -0
  79. package/build/utils/interactivity/index.js +34 -0
  80. package/build/utils/interactivity/index.js.map +1 -0
  81. package/build/utils/interactivity/store.js +67 -0
  82. package/build/utils/interactivity/store.js.map +1 -0
  83. package/build/utils/interactivity/utils.js +87 -0
  84. package/build/utils/interactivity/utils.js.map +1 -0
  85. package/build/utils/interactivity/vdom.js +109 -0
  86. package/build/utils/interactivity/vdom.js.map +1 -0
  87. package/build-module/comment-author-name/edit.js +1 -1
  88. package/build-module/comment-author-name/edit.js.map +1 -1
  89. package/build-module/comment-edit-link/edit.js +1 -1
  90. package/build-module/comment-edit-link/edit.js.map +1 -1
  91. package/build-module/cover/edit/inspector-controls.js +1 -1
  92. package/build-module/cover/edit/inspector-controls.js.map +1 -1
  93. package/build-module/cover/index.js +1 -1
  94. package/build-module/cover/variations.js +1 -1
  95. package/build-module/cover/variations.js.map +1 -1
  96. package/build-module/details/edit.js +20 -6
  97. package/build-module/details/edit.js.map +1 -1
  98. package/build-module/details/index.js +14 -10
  99. package/build-module/details/index.js.map +1 -1
  100. package/build-module/details/save.js +5 -2
  101. package/build-module/details/save.js.map +1 -1
  102. package/build-module/embed/variations.js +2 -2
  103. package/build-module/embed/variations.js.map +1 -1
  104. package/build-module/file/view.js +1 -1
  105. package/build-module/file/view.js.map +1 -1
  106. package/build-module/gallery/edit.js +2 -8
  107. package/build-module/gallery/edit.js.map +1 -1
  108. package/build-module/index.js +0 -4
  109. package/build-module/index.js.map +1 -1
  110. package/build-module/index.native.js +1 -1
  111. package/build-module/index.native.js.map +1 -1
  112. package/build-module/list-item/utils.js +5 -1
  113. package/build-module/list-item/utils.js.map +1 -1
  114. package/build-module/loginout/index.js +11 -1
  115. package/build-module/loginout/index.js.map +1 -1
  116. package/build-module/navigation/constants.js +5 -0
  117. package/build-module/navigation/constants.js.map +1 -0
  118. package/build-module/navigation/edit/index.js +18 -27
  119. package/build-module/navigation/edit/index.js.map +1 -1
  120. package/build-module/navigation/edit/inner-blocks.js +1 -4
  121. package/build-module/navigation/edit/inner-blocks.js.map +1 -1
  122. package/build-module/navigation/edit/unsaved-inner-blocks.js +1 -4
  123. package/build-module/navigation/edit/unsaved-inner-blocks.js.map +1 -1
  124. package/build-module/navigation/edit/use-convert-classic-menu-to-block-menu.js +1 -1
  125. package/build-module/navigation/edit/use-convert-classic-menu-to-block-menu.js.map +1 -1
  126. package/build-module/navigation/interactivity.js +136 -0
  127. package/build-module/navigation/interactivity.js.map +1 -0
  128. package/build-module/navigation-link/edit.js +1 -1
  129. package/build-module/navigation-link/edit.js.map +1 -1
  130. package/build-module/navigation-submenu/edit.js +1 -1
  131. package/build-module/navigation-submenu/edit.js.map +1 -1
  132. package/build-module/paragraph/index.js +5 -1
  133. package/build-module/paragraph/index.js.map +1 -1
  134. package/build-module/paragraph/transforms.js +5 -1
  135. package/build-module/paragraph/transforms.js.map +1 -1
  136. package/build-module/post-author-name/edit.js +1 -1
  137. package/build-module/post-author-name/edit.js.map +1 -1
  138. package/build-module/post-featured-image/edit.js +1 -2
  139. package/build-module/post-featured-image/edit.js.map +1 -1
  140. package/build-module/post-featured-image/overlay.js +5 -0
  141. package/build-module/post-featured-image/overlay.js.map +1 -1
  142. package/build-module/post-title/edit.js +13 -4
  143. package/build-module/post-title/edit.js.map +1 -1
  144. package/build-module/preformatted/edit.native.js +3 -2
  145. package/build-module/preformatted/edit.native.js.map +1 -1
  146. package/build-module/quote/transforms.js +16 -27
  147. package/build-module/quote/transforms.js.map +1 -1
  148. package/build-module/read-more/edit.js +1 -1
  149. package/build-module/read-more/edit.js.map +1 -1
  150. package/build-module/search/edit.js +9 -1
  151. package/build-module/search/edit.js.map +1 -1
  152. package/build-module/site-title/edit/index.js +1 -1
  153. package/build-module/site-title/edit/index.js.map +1 -1
  154. package/build-module/social-links/edit.js +2 -2
  155. package/build-module/social-links/edit.js.map +1 -1
  156. package/build-module/utils/interactivity/constants.js +2 -0
  157. package/build-module/utils/interactivity/constants.js.map +1 -0
  158. package/build-module/utils/interactivity/directives.js +193 -0
  159. package/build-module/utils/interactivity/directives.js.map +1 -0
  160. package/build-module/utils/interactivity/hooks.js +98 -0
  161. package/build-module/utils/interactivity/hooks.js.map +1 -0
  162. package/build-module/utils/interactivity/hydration.js +21 -0
  163. package/build-module/utils/interactivity/hydration.js.map +1 -0
  164. package/build-module/utils/interactivity/index.js +17 -0
  165. package/build-module/utils/interactivity/index.js.map +1 -0
  166. package/build-module/utils/interactivity/store.js +56 -0
  167. package/build-module/utils/interactivity/store.js.map +1 -0
  168. package/build-module/utils/interactivity/utils.js +75 -0
  169. package/build-module/utils/interactivity/utils.js.map +1 -0
  170. package/build-module/utils/interactivity/vdom.js +97 -0
  171. package/build-module/utils/interactivity/vdom.js.map +1 -0
  172. package/build-style/cover/style-rtl.css +2 -0
  173. package/build-style/cover/style.css +2 -0
  174. package/build-style/{details-summary → details}/editor-rtl.css +1 -1
  175. package/build-style/{details-summary → details}/editor.css +1 -1
  176. package/build-style/details/style-rtl.css +14 -0
  177. package/build-style/details/style.css +14 -0
  178. package/build-style/editor-rtl.css +3 -5
  179. package/build-style/editor.css +3 -5
  180. package/build-style/gallery/editor-rtl.css +0 -4
  181. package/build-style/gallery/editor.css +0 -4
  182. package/build-style/search/editor-rtl.css +1 -0
  183. package/build-style/search/editor.css +1 -0
  184. package/build-style/site-logo/editor-rtl.css +1 -0
  185. package/build-style/site-logo/editor.css +1 -0
  186. package/build-style/style-rtl.css +13 -1
  187. package/build-style/style.css +13 -1
  188. package/package.json +36 -32
  189. package/src/comment-author-name/edit.js +1 -1
  190. package/src/comment-edit-link/edit.js +1 -1
  191. package/src/comment-template/index.php +8 -7
  192. package/src/cover/block.json +1 -1
  193. package/src/cover/edit/inspector-controls.js +56 -54
  194. package/src/cover/style.scss +5 -0
  195. package/src/cover/test/edit.js +56 -2
  196. package/src/cover/variations.js +1 -3
  197. package/src/details/block.json +8 -6
  198. package/src/details/edit.js +27 -5
  199. package/src/details/editor.scss +3 -0
  200. package/src/details/index.js +10 -5
  201. package/src/details/save.js +5 -1
  202. package/src/details/style.scss +16 -0
  203. package/src/editor.scss +1 -1
  204. package/src/embed/variations.js +2 -2
  205. package/src/file/view.js +4 -1
  206. package/src/gallery/edit.js +5 -8
  207. package/src/gallery/editor.scss +0 -6
  208. package/src/gallery/test/index.native.js +48 -3
  209. package/src/image/test/edit.native.js +38 -16
  210. package/src/index.js +0 -4
  211. package/src/index.native.js +1 -0
  212. package/src/loginout/block.json +11 -1
  213. package/src/navigation/constants.js +16 -0
  214. package/src/navigation/edit/index.js +71 -83
  215. package/src/navigation/edit/inner-blocks.js +1 -16
  216. package/src/navigation/edit/unsaved-inner-blocks.js +1 -16
  217. package/src/navigation/edit/use-convert-classic-menu-to-block-menu.js +1 -1
  218. package/src/navigation/index.php +209 -203
  219. package/src/navigation/interactivity.js +144 -0
  220. package/src/navigation-link/edit.js +1 -1
  221. package/src/navigation-submenu/edit.js +1 -1
  222. package/src/paragraph/block.json +5 -1
  223. package/src/post-author-name/edit.js +1 -1
  224. package/src/post-featured-image/edit.js +1 -1
  225. package/src/post-featured-image/index.php +1 -1
  226. package/src/post-featured-image/overlay.js +4 -0
  227. package/src/post-terms/index.php +2 -2
  228. package/src/post-title/edit.js +8 -1
  229. package/src/preformatted/edit.native.js +1 -3
  230. package/src/quote/transforms.js +0 -6
  231. package/src/read-more/edit.js +1 -1
  232. package/src/search/edit.js +9 -4
  233. package/src/search/editor.scss +1 -0
  234. package/src/site-logo/editor.scss +2 -1
  235. package/src/site-title/edit/index.js +1 -1
  236. package/src/social-links/edit.js +33 -31
  237. package/src/style.scss +0 -1
  238. package/src/template-part/index.php +20 -5
  239. package/src/utils/interactivity/constants.js +1 -0
  240. package/src/utils/interactivity/directives.js +179 -0
  241. package/src/utils/interactivity/hooks.js +76 -0
  242. package/src/utils/interactivity/hydration.js +22 -0
  243. package/src/utils/interactivity/index.js +17 -0
  244. package/src/utils/interactivity/store.js +45 -0
  245. package/src/utils/interactivity/utils.js +66 -0
  246. package/src/utils/interactivity/vdom.js +94 -0
  247. package/tsconfig.json +1 -0
  248. package/tsconfig.tsbuildinfo +1 -1
  249. package/build/details-content/edit.js +0 -34
  250. package/build/details-content/edit.js.map +0 -1
  251. package/build/details-content/index.js +0 -94
  252. package/build/details-content/index.js.map +0 -1
  253. package/build/details-content/save.js +0 -20
  254. package/build/details-content/save.js.map +0 -1
  255. package/build/details-summary/edit.js +0 -42
  256. package/build/details-summary/edit.js.map +0 -1
  257. package/build/details-summary/index.js +0 -97
  258. package/build/details-summary/index.js.map +0 -1
  259. package/build/details-summary/save.js +0 -24
  260. package/build/details-summary/save.js.map +0 -1
  261. package/build-module/details-content/edit.js +0 -23
  262. package/build-module/details-content/edit.js.map +0 -1
  263. package/build-module/details-content/index.js +0 -76
  264. package/build-module/details-content/index.js.map +0 -1
  265. package/build-module/details-content/save.js +0 -11
  266. package/build-module/details-content/save.js.map +0 -1
  267. package/build-module/details-summary/edit.js +0 -30
  268. package/build-module/details-summary/edit.js.map +0 -1
  269. package/build-module/details-summary/index.js +0 -79
  270. package/build-module/details-summary/index.js.map +0 -1
  271. package/build-module/details-summary/save.js +0 -16
  272. package/build-module/details-summary/save.js.map +0 -1
  273. package/build-style/details-summary/style-rtl.css +0 -91
  274. package/build-style/details-summary/style.css +0 -91
  275. package/src/details-content/block.json +0 -50
  276. package/src/details-content/edit.js +0 -29
  277. package/src/details-content/index.js +0 -23
  278. package/src/details-content/save.js +0 -12
  279. package/src/details-summary/block.json +0 -53
  280. package/src/details-summary/edit.js +0 -27
  281. package/src/details-summary/editor.scss +0 -3
  282. package/src/details-summary/index.js +0 -23
  283. package/src/details-summary/save.js +0 -13
  284. package/src/details-summary/style.scss +0 -3
@@ -15,6 +15,7 @@ import {
15
15
  } from '@wordpress/block-editor';
16
16
  import { ToggleControl, TextControl, PanelBody } from '@wordpress/components';
17
17
  import { __ } from '@wordpress/i18n';
18
+ import { createBlock, getDefaultBlockName } from '@wordpress/blocks';
18
19
  import { useEntityProp } from '@wordpress/core-data';
19
20
 
20
21
  /**
@@ -27,6 +28,7 @@ export default function PostTitleEdit( {
27
28
  attributes: { level, textAlign, isLink, rel, linkTarget },
28
29
  setAttributes,
29
30
  context: { postType, postId, queryId },
31
+ insertBlocksAfter,
30
32
  } ) {
31
33
  const TagName = 0 === level ? 'p' : 'h' + level;
32
34
  const isDescendentOfQueryLoop = Number.isFinite( queryId );
@@ -38,6 +40,9 @@ export default function PostTitleEdit( {
38
40
  postId
39
41
  );
40
42
  const [ link ] = useEntityProp( 'postType', postType, 'link', postId );
43
+ const onSplitAtEnd = () => {
44
+ insertBlocksAfter( createBlock( getDefaultBlockName() ) );
45
+ };
41
46
  const blockProps = useBlockProps( {
42
47
  className: classnames( {
43
48
  [ `has-text-align-${ textAlign }` ]: textAlign,
@@ -57,6 +62,7 @@ export default function PostTitleEdit( {
57
62
  value={ rawTitle }
58
63
  onChange={ setTitle }
59
64
  __experimentalVersion={ 2 }
65
+ __unstableOnSplitAtEnd={ onSplitAtEnd }
60
66
  { ...blockProps }
61
67
  />
62
68
  ) : (
@@ -82,6 +88,7 @@ export default function PostTitleEdit( {
82
88
  value={ rawTitle }
83
89
  onChange={ setTitle }
84
90
  __experimentalVersion={ 2 }
91
+ __unstableOnSplitAtEnd={ onSplitAtEnd }
85
92
  />
86
93
  </TagName>
87
94
  ) : (
@@ -116,7 +123,7 @@ export default function PostTitleEdit( {
116
123
  />
117
124
  </BlockControls>
118
125
  <InspectorControls>
119
- <PanelBody title={ __( 'Link settings' ) }>
126
+ <PanelBody title={ __( 'Settings' ) }>
120
127
  <ToggleControl
121
128
  __nextHasNoMarginBottom
122
129
  label={ __( 'Make title a link' ) }
@@ -28,12 +28,10 @@ export default function PreformattedEdit( props ) {
28
28
  ...( style?.fontSize && { fontSize: style.fontSize } ),
29
29
  ...( style?.color && { color: style.color } ),
30
30
  };
31
- const hasBaseColors =
32
- style?.baseColors && Object.entries( style.baseColors ).length !== 0;
33
31
  const containerStyles = [
34
32
  wpBlockPreformatted,
35
33
  style?.backgroundColor && { backgroundColor: style.backgroundColor },
36
- hasBaseColors &&
34
+ style?.baseColors?.color &&
37
35
  ! style?.backgroundColor &&
38
36
  styles[ 'wp-block-preformatted__no-background' ],
39
37
  ];
@@ -21,12 +21,6 @@ const transforms = {
21
21
  );
22
22
  },
23
23
  },
24
- {
25
- type: 'block',
26
- blocks: [ 'core/group' ],
27
- transform: ( { anchor }, innerBlocks ) =>
28
- createBlock( 'core/quote', { anchor }, innerBlocks ),
29
- },
30
24
  {
31
25
  type: 'prefix',
32
26
  prefix: '>',
@@ -19,7 +19,7 @@ export default function ReadMore( {
19
19
  return (
20
20
  <>
21
21
  <InspectorControls>
22
- <PanelBody title={ __( 'Link settings' ) }>
22
+ <PanelBody title={ __( 'Settings' ) }>
23
23
  <ToggleControl
24
24
  __nextHasNoMarginBottom
25
25
  label={ __( 'Open in new tab' ) }
@@ -115,10 +115,15 @@ export default function SearchEdit( {
115
115
 
116
116
  const colorProps = useColorProps( attributes );
117
117
  const fluidTypographySettings = useSetting( 'typography.fluid' );
118
- const typographyProps = useTypographyProps(
119
- attributes,
120
- fluidTypographySettings
121
- );
118
+ const layout = useSetting( 'layout' );
119
+ const typographyProps = useTypographyProps( attributes, {
120
+ typography: {
121
+ fluid: fluidTypographySettings,
122
+ },
123
+ layout: {
124
+ wideSize: layout?.wideSize,
125
+ },
126
+ } );
122
127
  const unitControlInstanceId = useInstanceId( UnitControl );
123
128
  const unitControlInputId = `wp-block-search__width-${ unitControlInstanceId }`;
124
129
  const isButtonPositionInside = 'button-inside' === buttonPosition;
@@ -12,6 +12,7 @@
12
12
  border-radius: initial;
13
13
  display: flex;
14
14
  align-items: center;
15
+ justify-content: center;
15
16
  }
16
17
 
17
18
  &__components-button-group {
@@ -138,7 +138,8 @@
138
138
  }
139
139
 
140
140
  img {
141
- width: $grid-unit-50 * 0.5;
141
+ width: 20px;
142
+ min-width: 20px;
142
143
  aspect-ratio: 1;
143
144
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2);
144
145
  border-radius: 50% !important;
@@ -109,7 +109,7 @@ export default function SiteTitleEdit( {
109
109
  />
110
110
  </BlockControls>
111
111
  <InspectorControls>
112
- <PanelBody title={ __( 'Link settings' ) }>
112
+ <PanelBody title={ __( 'Settings' ) }>
113
113
  <ToggleControl
114
114
  __nextHasNoMarginBottom
115
115
  label={ __( 'Make title link to home' ) }
@@ -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";
@@ -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,179 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import { useContext, useMemo, useEffect } from 'preact/hooks';
5
+ import { deepSignal, peek } from 'deepsignal';
6
+
7
+ /**
8
+ * Internal dependencies
9
+ */
10
+ import { useSignalEffect } from './utils';
11
+ import { directive } from './hooks';
12
+
13
+ const isObject = ( item ) =>
14
+ item && typeof item === 'object' && ! Array.isArray( item );
15
+
16
+ const mergeDeepSignals = ( target, source ) => {
17
+ for ( const k in source ) {
18
+ if ( typeof peek( target, k ) === 'undefined' ) {
19
+ target[ `$${ k }` ] = source[ `$${ k }` ];
20
+ } else if (
21
+ isObject( peek( target, k ) ) &&
22
+ isObject( peek( source, k ) )
23
+ ) {
24
+ mergeDeepSignals(
25
+ target[ `$${ k }` ].peek(),
26
+ source[ `$${ k }` ].peek()
27
+ );
28
+ }
29
+ }
30
+ };
31
+
32
+ export default () => {
33
+ // data-wp-context
34
+ directive(
35
+ 'context',
36
+ ( {
37
+ directives: {
38
+ context: { default: context },
39
+ },
40
+ props: { children },
41
+ context: inherited,
42
+ } ) => {
43
+ const { Provider } = inherited;
44
+ const inheritedValue = useContext( inherited );
45
+ const value = useMemo( () => {
46
+ const localValue = deepSignal( context );
47
+ mergeDeepSignals( localValue, inheritedValue );
48
+ return localValue;
49
+ }, [ context, inheritedValue ] );
50
+
51
+ return <Provider value={ value }>{ children }</Provider>;
52
+ }
53
+ );
54
+
55
+ // data-wp-effect.[name]
56
+ directive( 'effect', ( { directives: { effect }, context, evaluate } ) => {
57
+ const contextValue = useContext( context );
58
+ Object.values( effect ).forEach( ( path ) => {
59
+ useSignalEffect( () => {
60
+ return evaluate( path, { context: contextValue } );
61
+ } );
62
+ } );
63
+ } );
64
+
65
+ // data-wp-init.[name]
66
+ directive( 'init', ( { directives: { init }, context, evaluate } ) => {
67
+ const contextValue = useContext( context );
68
+ Object.values( init ).forEach( ( path ) => {
69
+ useEffect( () => {
70
+ return evaluate( path, { context: contextValue } );
71
+ }, [] );
72
+ } );
73
+ } );
74
+
75
+ // data-wp-on.[event]
76
+ directive( 'on', ( { directives: { on }, element, evaluate, context } ) => {
77
+ const contextValue = useContext( context );
78
+ Object.entries( on ).forEach( ( [ name, path ] ) => {
79
+ element.props[ `on${ name }` ] = ( event ) => {
80
+ evaluate( path, { event, context: contextValue } );
81
+ };
82
+ } );
83
+ } );
84
+
85
+ // data-wp-class.[classname]
86
+ directive(
87
+ 'class',
88
+ ( {
89
+ directives: { class: className },
90
+ element,
91
+ evaluate,
92
+ context,
93
+ } ) => {
94
+ const contextValue = useContext( context );
95
+ Object.keys( className )
96
+ .filter( ( n ) => n !== 'default' )
97
+ .forEach( ( name ) => {
98
+ const result = evaluate( className[ name ], {
99
+ className: name,
100
+ context: contextValue,
101
+ } );
102
+ const currentClass = element.props.class || '';
103
+ const classFinder = new RegExp(
104
+ `(^|\\s)${ name }(\\s|$)`,
105
+ 'g'
106
+ );
107
+ if ( ! result )
108
+ element.props.class = currentClass
109
+ .replace( classFinder, ' ' )
110
+ .trim();
111
+ else if ( ! classFinder.test( currentClass ) )
112
+ element.props.class = currentClass
113
+ ? `${ currentClass } ${ name }`
114
+ : name;
115
+
116
+ useEffect( () => {
117
+ // This seems necessary because Preact doesn't change the class
118
+ // names on the hydration, so we have to do it manually. It doesn't
119
+ // need deps because it only needs to do it the first time.
120
+ if ( ! result ) {
121
+ element.ref.current.classList.remove( name );
122
+ } else {
123
+ element.ref.current.classList.add( name );
124
+ }
125
+ }, [] );
126
+ } );
127
+ }
128
+ );
129
+
130
+ // data-wp-bind.[attribute]
131
+ directive(
132
+ 'bind',
133
+ ( { directives: { bind }, element, context, evaluate } ) => {
134
+ const contextValue = useContext( context );
135
+ Object.entries( bind )
136
+ .filter( ( n ) => n !== 'default' )
137
+ .forEach( ( [ attribute, path ] ) => {
138
+ const result = evaluate( path, {
139
+ context: contextValue,
140
+ } );
141
+ element.props[ attribute ] = result;
142
+
143
+ useEffect( () => {
144
+ // This seems necessary because Preact doesn't change the attributes
145
+ // on the hydration, so we have to do it manually. It doesn't need
146
+ // deps because it only needs to do it the first time.
147
+ if ( result === false ) {
148
+ element.ref.current.removeAttribute( attribute );
149
+ } else {
150
+ element.ref.current.setAttribute(
151
+ attribute,
152
+ result === true ? '' : result
153
+ );
154
+ }
155
+ }, [] );
156
+ } );
157
+ }
158
+ );
159
+
160
+ // data-wp-ignore
161
+ directive(
162
+ 'ignore',
163
+ ( {
164
+ element: {
165
+ type: Type,
166
+ props: { innerHTML, ...rest },
167
+ },
168
+ } ) => {
169
+ // Preserve the initial inner HTML.
170
+ const cached = useMemo( () => innerHTML, [] );
171
+ return (
172
+ <Type
173
+ dangerouslySetInnerHTML={ { __html: cached } }
174
+ { ...rest }
175
+ />
176
+ );
177
+ }
178
+ );
179
+ };
@@ -0,0 +1,76 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import { h, options, createContext } 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
+ export const directive = ( name, cb ) => {
17
+ directiveMap[ name ] = cb;
18
+ };
19
+
20
+ // Resolve the path to some property of the store object.
21
+ const resolve = ( path, ctx ) => {
22
+ // If path starts with !, remove it and save a flag.
23
+ const hasNegationOperator =
24
+ path[ 0 ] === '!' && !! ( path = path.slice( 1 ) );
25
+ let current = { ...store, context: ctx };
26
+ path.split( '.' ).forEach( ( p ) => ( current = current[ p ] ) );
27
+ return hasNegationOperator ? ! current : current;
28
+ };
29
+
30
+ // Generate the evaluate function.
31
+ const getEvaluate =
32
+ ( { ref } = {} ) =>
33
+ ( path, extraArgs = {} ) => {
34
+ const value = resolve( path, extraArgs.context );
35
+ return typeof value === 'function'
36
+ ? value( {
37
+ ref: ref.current,
38
+ ...store,
39
+ ...extraArgs,
40
+ } )
41
+ : value;
42
+ };
43
+
44
+ // Directive wrapper.
45
+ const Directive = ( { type, directives, props: originalProps } ) => {
46
+ const ref = useRef( null );
47
+ const element = h( type, { ...originalProps, ref } );
48
+ const props = { ...originalProps, children: element };
49
+ const evaluate = useMemo( () => getEvaluate( { ref } ), [] );
50
+ const directiveArgs = { directives, props, element, context, evaluate };
51
+
52
+ for ( const d in directives ) {
53
+ const wrapper = directiveMap[ d ]?.( directiveArgs );
54
+ if ( wrapper !== undefined ) props.children = wrapper;
55
+ }
56
+
57
+ return props.children;
58
+ };
59
+
60
+ // Preact Options Hook called each time a vnode is created.
61
+ const old = options.vnode;
62
+ options.vnode = ( vnode ) => {
63
+ if ( vnode.props.__directives ) {
64
+ const props = vnode.props;
65
+ const directives = props.__directives;
66
+ delete props.__directives;
67
+ vnode.props = {
68
+ type: vnode.type,
69
+ directives,
70
+ props,
71
+ };
72
+ vnode.type = Directive;
73
+ }
74
+
75
+ if ( old ) old( vnode );
76
+ };
@@ -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
+ } );
@@ -0,0 +1,45 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import { deepSignal } from 'deepsignal';
5
+
6
+ const isObject = ( item ) =>
7
+ item && typeof item === 'object' && ! Array.isArray( item );
8
+
9
+ const deepMerge = ( target, source ) => {
10
+ if ( isObject( target ) && isObject( source ) ) {
11
+ for ( const key in source ) {
12
+ if ( isObject( source[ key ] ) ) {
13
+ if ( ! target[ key ] ) Object.assign( target, { [ key ]: {} } );
14
+ deepMerge( target[ key ], source[ key ] );
15
+ } else {
16
+ Object.assign( target, { [ key ]: source[ key ] } );
17
+ }
18
+ }
19
+ }
20
+ };
21
+
22
+ const getSerializedState = () => {
23
+ // TODO: change the store tag ID for a better one.
24
+ const storeTag = document.querySelector(
25
+ `script[type="application/json"]#store`
26
+ );
27
+ if ( ! storeTag ) return {};
28
+ try {
29
+ const { state } = JSON.parse( storeTag.textContent );
30
+ if ( isObject( state ) ) return state;
31
+ throw Error( 'Parsed state is not an object' );
32
+ } catch ( e ) {
33
+ // eslint-disable-next-line no-console
34
+ console.log( e );
35
+ }
36
+ return {};
37
+ };
38
+
39
+ const rawState = getSerializedState();
40
+ export const rawStore = { state: deepSignal( rawState ) };
41
+
42
+ export const store = ( { state, ...block } ) => {
43
+ deepMerge( rawStore, block );
44
+ deepMerge( rawState, state );
45
+ };