@automattic/jetpack-shared-extension-utils 0.18.0 → 0.18.2

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,17 @@ 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.2] - 2025-03-17
9
+ ### Changed
10
+ - Update dependencies. [#42328]
11
+
12
+ ## [0.18.1] - 2025-03-17
13
+ ### Added
14
+ - Add Jetpack editor action utility functions. [#42364]
15
+
16
+ ### Removed
17
+ - Social: Remove the old unused initial state. [#42390]
18
+
8
19
  ## [0.18.0] - 2025-03-12
9
20
  ### Added
10
21
  - Add `shouldUseInternalLinks()`. [#42000]
@@ -558,6 +569,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
558
569
  ### Changed
559
570
  - Core: prepare utility for release
560
571
 
572
+ [0.18.2]: https://github.com/Automattic/jetpack-shared-extension-utils/compare/0.18.1...0.18.2
573
+ [0.18.1]: https://github.com/Automattic/jetpack-shared-extension-utils/compare/0.18.0...0.18.1
561
574
  [0.18.0]: https://github.com/Automattic/jetpack-shared-extension-utils/compare/0.17.5...0.18.0
562
575
  [0.17.5]: https://github.com/Automattic/jetpack-shared-extension-utils/compare/0.17.4...0.17.5
563
576
  [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.0",
3
+ "version": "0.18.2",
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": {
@@ -21,14 +21,15 @@
21
21
  "@automattic/color-studio": "4.0.0",
22
22
  "@automattic/jetpack-analytics": "^0.1.36",
23
23
  "@automattic/jetpack-base-styles": "^0.6.44",
24
- "@automattic/jetpack-components": "^0.68.2",
25
- "@automattic/jetpack-connection": "^0.39.1",
26
- "@automattic/jetpack-script-data": "^0.2.1",
24
+ "@automattic/jetpack-components": "^0.69.0",
25
+ "@automattic/jetpack-connection": "^0.39.2",
26
+ "@automattic/jetpack-script-data": "^0.3.0",
27
27
  "@wordpress/api-fetch": "7.19.0",
28
28
  "@wordpress/block-editor": "14.14.0",
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
+ }
@@ -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
  }