@automattic/jetpack-shared-extension-utils 0.12.4 → 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,14 @@ 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
|
+
|
|
12
|
+
## [0.12.5] - 2023-11-03
|
|
13
|
+
### Changed
|
|
14
|
+
- Update dependencies.
|
|
15
|
+
|
|
8
16
|
## [0.12.4] - 2023-10-19
|
|
9
17
|
### Changed
|
|
10
18
|
- Updated package dependencies. [#33687]
|
|
@@ -272,6 +280,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
272
280
|
### Changed
|
|
273
281
|
- Core: prepare utility for release
|
|
274
282
|
|
|
283
|
+
[0.12.6]: https://github.com/Automattic/jetpack-shared-extension-utils/compare/0.12.5...0.12.6
|
|
284
|
+
[0.12.5]: https://github.com/Automattic/jetpack-shared-extension-utils/compare/0.12.4...0.12.5
|
|
275
285
|
[0.12.4]: https://github.com/Automattic/jetpack-shared-extension-utils/compare/0.12.3...0.12.4
|
|
276
286
|
[0.12.3]: https://github.com/Automattic/jetpack-shared-extension-utils/compare/0.12.2...0.12.3
|
|
277
287
|
[0.12.2]: https://github.com/Automattic/jetpack-shared-extension-utils/compare/0.12.1...0.12.2
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@automattic/jetpack-shared-extension-utils",
|
|
3
|
-
"version": "0.12.
|
|
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": {
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@automattic/jetpack-analytics": "^0.1.27",
|
|
21
|
-
"@automattic/jetpack-components": "^0.44.
|
|
22
|
-
"@automattic/jetpack-connection": "^0.30.
|
|
21
|
+
"@automattic/jetpack-components": "^0.44.4",
|
|
22
|
+
"@automattic/jetpack-connection": "^0.30.5",
|
|
23
23
|
"@wordpress/api-fetch": "6.41.0",
|
|
24
24
|
"@wordpress/compose": "6.21.0",
|
|
25
25
|
"@wordpress/element": "5.21.0",
|
|
@@ -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
|
+
}
|