@automattic/jetpack-shared-extension-utils 0.18.0 → 0.18.1
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 +8 -0
- package/index.js +1 -0
- package/package.json +2 -1
- package/src/block-editor-actions.js +46 -0
- package/src/get-site-fragment.js +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,13 @@ 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.18.1] - 2025-03-17
|
|
9
|
+
### Added
|
|
10
|
+
- Added jetpack editor action utility functions [#42364]
|
|
11
|
+
|
|
12
|
+
### Removed
|
|
13
|
+
- Social | Removed the old unused initial state [#42390]
|
|
14
|
+
|
|
8
15
|
## [0.18.0] - 2025-03-12
|
|
9
16
|
### Added
|
|
10
17
|
- Add `shouldUseInternalLinks()`. [#42000]
|
|
@@ -558,6 +565,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
558
565
|
### Changed
|
|
559
566
|
- Core: prepare utility for release
|
|
560
567
|
|
|
568
|
+
[0.18.1]: https://github.com/Automattic/jetpack-shared-extension-utils/compare/0.18.0...0.18.1
|
|
561
569
|
[0.18.0]: https://github.com/Automattic/jetpack-shared-extension-utils/compare/0.17.5...0.18.0
|
|
562
570
|
[0.17.5]: https://github.com/Automattic/jetpack-shared-extension-utils/compare/0.17.4...0.17.5
|
|
563
571
|
[0.17.4]: https://github.com/Automattic/jetpack-shared-extension-utils/compare/0.17.3...0.17.4
|
package/index.js
CHANGED
|
@@ -27,3 +27,4 @@ export * from './src/modules-state';
|
|
|
27
27
|
export { default as isMyJetpackAvailable } from './src/is-my-jetpack-available';
|
|
28
28
|
export * from './src/libs';
|
|
29
29
|
export { default as useUpgradeFlow } from './src/hooks/use-upgrade-flow';
|
|
30
|
+
export * from './src/block-editor-actions';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@automattic/jetpack-shared-extension-utils",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.1",
|
|
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": {
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"@wordpress/components": "29.5.0",
|
|
30
30
|
"@wordpress/compose": "7.19.0",
|
|
31
31
|
"@wordpress/data": "10.19.0",
|
|
32
|
+
"@wordpress/dom-ready": "4.19.0",
|
|
32
33
|
"@wordpress/element": "6.19.0",
|
|
33
34
|
"@wordpress/hooks": "4.19.0",
|
|
34
35
|
"@wordpress/i18n": "5.19.0",
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import domReady from '@wordpress/dom-ready';
|
|
2
|
+
|
|
3
|
+
const JETPACK_EDITOR_ACTION = 'jetpack-editor-action';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Get the Jetpack Editor action from the URL.
|
|
7
|
+
*
|
|
8
|
+
* @return {string | null} The Jetpack Editor action.
|
|
9
|
+
*/
|
|
10
|
+
export function getJetpackEditorAction() {
|
|
11
|
+
const url = new URL( window.location.href );
|
|
12
|
+
|
|
13
|
+
return url.searchParams.get( JETPACK_EDITOR_ACTION );
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Remove the Jetpack Editor action from the URL.
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
export function removeJetpackEditorAction() {
|
|
21
|
+
const url = new URL( window.location.href );
|
|
22
|
+
url.searchParams.delete( JETPACK_EDITOR_ACTION );
|
|
23
|
+
window.history.replaceState( null, '', url.toString() );
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Handle a particular Jetpack Editor action.
|
|
28
|
+
*
|
|
29
|
+
* If the callback returns true, the Jetpack Editor action will be removed from the URL.
|
|
30
|
+
*
|
|
31
|
+
* @param {string} action - The action to handle.
|
|
32
|
+
* @param {() => (void|boolean)} callback - The callback to run when the action is handled.
|
|
33
|
+
*/
|
|
34
|
+
export function handleJetpackEditorAction( action, callback ) {
|
|
35
|
+
domReady( () => {
|
|
36
|
+
const actionValue = getJetpackEditorAction();
|
|
37
|
+
if ( action !== actionValue ) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const removeQueryArg = callback();
|
|
41
|
+
|
|
42
|
+
if ( removeQueryArg ) {
|
|
43
|
+
removeJetpackEditorAction();
|
|
44
|
+
}
|
|
45
|
+
} );
|
|
46
|
+
}
|
package/src/get-site-fragment.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { getScriptData } from '@automattic/jetpack-script-data';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Returns the site fragment (slug) in the environment we're running Gutenberg in.
|
|
3
5
|
*
|
|
@@ -13,5 +15,5 @@ export default function getSiteFragment() {
|
|
|
13
15
|
return window.Jetpack_Editor_Initial_State.siteFragment;
|
|
14
16
|
}
|
|
15
17
|
|
|
16
|
-
return null;
|
|
18
|
+
return getScriptData()?.site?.suffix ?? null;
|
|
17
19
|
}
|