@automattic/jetpack-shared-extension-utils 0.12.5 → 0.12.6

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.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.12.6] - 2023-11-08
9
+ ### Fixed
10
+ - Mobile: Fix a regression preventing correct block registration on mobile. [#33890]
11
+
8
12
  ## [0.12.5] - 2023-11-03
9
13
  ### Changed
10
14
  - Update dependencies.
@@ -276,6 +280,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
276
280
  ### Changed
277
281
  - Core: prepare utility for release
278
282
 
283
+ [0.12.6]: https://github.com/Automattic/jetpack-shared-extension-utils/compare/0.12.5...0.12.6
279
284
  [0.12.5]: https://github.com/Automattic/jetpack-shared-extension-utils/compare/0.12.4...0.12.5
280
285
  [0.12.4]: https://github.com/Automattic/jetpack-shared-extension-utils/compare/0.12.3...0.12.4
281
286
  [0.12.3]: https://github.com/Automattic/jetpack-shared-extension-utils/compare/0.12.2...0.12.3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automattic/jetpack-shared-extension-utils",
3
- "version": "0.12.5",
3
+ "version": "0.12.6",
4
4
  "description": "Utility functions used by the block editor extensions",
5
5
  "homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/js-packages/shared-extension-utils/#readme",
6
6
  "bugs": {
@@ -0,0 +1,37 @@
1
+ /* eslint-disable jsdoc/no-undefined-types */
2
+ import { SvgXml } from '@wordpress/primitives';
3
+ import getIconColor from './get-icon-color';
4
+
5
+ /**
6
+ * Generate an icon as a React component from the SVG markup defined in a block.json metadata file.
7
+ * This prevents us from duplicating the markup in various places.
8
+ *
9
+ * Note: using an `img` tag and passing the SVG markup as a data URI doesn't allow us to
10
+ * dynamically set the icon color later on.
11
+ *
12
+ * @param {object} metadata - Block.json content
13
+ * @returns {JSX.Element|string} Icon component
14
+ */
15
+ export function getBlockIconComponent( metadata ) {
16
+ // If the SVG has been passed as a string, use SvgXml to correctly parse it.
17
+ if ( typeof metadata.icon === 'string' && metadata.icon.startsWith( '<svg' ) ) {
18
+ return <SvgXml xml={ metadata.icon } />;
19
+ }
20
+ return metadata.icon || '';
21
+ }
22
+
23
+ /**
24
+ * A block icon needs to be redefined on the front end as a React component, since a string - even
25
+ * SVG markup - is interpreted as a dashicon. This function returns the object that must be passed
26
+ * to the `icon` attribute when registering the block in the front end. It also sets the color
27
+ * of the icon.
28
+ *
29
+ * @param {object} metadata - Block.json content
30
+ * @returns {object} Icon property for client registration
31
+ */
32
+ export function getBlockIconProp( metadata ) {
33
+ return {
34
+ src: getBlockIconComponent( metadata ),
35
+ foreground: getIconColor(),
36
+ };
37
+ }