@wordpress/api-fetch
Advanced tools
Comparing version 6.46.0 to 6.47.0
/** | ||
* WordPress dependencies | ||
*/ | ||
import { addQueryArgs, hasQueryArg } from '@wordpress/url'; | ||
import { addQueryArgs, getQueryArg, removeQueryArgs } from '@wordpress/url'; | ||
@@ -10,2 +10,5 @@ /** | ||
* | ||
* If the REST API request URL has contained the `wp_theme_preview` parameter as `''`, | ||
* then bypass this middleware. | ||
* | ||
* @param {Record<string, any>} themePath | ||
@@ -15,11 +18,21 @@ * @return {import('../types').APIFetchMiddleware} Preloading middleware. | ||
const createThemePreviewMiddleware = themePath => (options, next) => { | ||
if (typeof options.url === 'string' && !hasQueryArg(options.url, 'wp_theme_preview')) { | ||
options.url = addQueryArgs(options.url, { | ||
wp_theme_preview: themePath | ||
}); | ||
if (typeof options.url === 'string') { | ||
const wpThemePreview = getQueryArg(options.url, 'wp_theme_preview'); | ||
if (wpThemePreview === undefined) { | ||
options.url = addQueryArgs(options.url, { | ||
wp_theme_preview: themePath | ||
}); | ||
} else if (wpThemePreview === '') { | ||
options.url = removeQueryArgs(options.url, 'wp_theme_preview'); | ||
} | ||
} | ||
if (typeof options.path === 'string' && !hasQueryArg(options.path, 'wp_theme_preview')) { | ||
options.path = addQueryArgs(options.path, { | ||
wp_theme_preview: themePath | ||
}); | ||
if (typeof options.path === 'string') { | ||
const wpThemePreview = getQueryArg(options.path, 'wp_theme_preview'); | ||
if (wpThemePreview === undefined) { | ||
options.path = addQueryArgs(options.path, { | ||
wp_theme_preview: themePath | ||
}); | ||
} else if (wpThemePreview === '') { | ||
options.path = removeQueryArgs(options.path, 'wp_theme_preview'); | ||
} | ||
} | ||
@@ -26,0 +39,0 @@ return next(options); |
@@ -6,2 +6,5 @@ export default createThemePreviewMiddleware; | ||
* | ||
* If the REST API request URL has contained the `wp_theme_preview` parameter as `''`, | ||
* then bypass this middleware. | ||
* | ||
* @param {Record<string, any>} themePath | ||
@@ -8,0 +11,0 @@ * @return {import('../types').APIFetchMiddleware} Preloading middleware. |
@@ -16,2 +16,5 @@ "use strict"; | ||
* | ||
* If the REST API request URL has contained the `wp_theme_preview` parameter as `''`, | ||
* then bypass this middleware. | ||
* | ||
* @param {Record<string, any>} themePath | ||
@@ -21,11 +24,21 @@ * @return {import('../types').APIFetchMiddleware} Preloading middleware. | ||
const createThemePreviewMiddleware = themePath => (options, next) => { | ||
if (typeof options.url === 'string' && !(0, _url.hasQueryArg)(options.url, 'wp_theme_preview')) { | ||
options.url = (0, _url.addQueryArgs)(options.url, { | ||
wp_theme_preview: themePath | ||
}); | ||
if (typeof options.url === 'string') { | ||
const wpThemePreview = (0, _url.getQueryArg)(options.url, 'wp_theme_preview'); | ||
if (wpThemePreview === undefined) { | ||
options.url = (0, _url.addQueryArgs)(options.url, { | ||
wp_theme_preview: themePath | ||
}); | ||
} else if (wpThemePreview === '') { | ||
options.url = (0, _url.removeQueryArgs)(options.url, 'wp_theme_preview'); | ||
} | ||
} | ||
if (typeof options.path === 'string' && !(0, _url.hasQueryArg)(options.path, 'wp_theme_preview')) { | ||
options.path = (0, _url.addQueryArgs)(options.path, { | ||
wp_theme_preview: themePath | ||
}); | ||
if (typeof options.path === 'string') { | ||
const wpThemePreview = (0, _url.getQueryArg)(options.path, 'wp_theme_preview'); | ||
if (wpThemePreview === undefined) { | ||
options.path = (0, _url.addQueryArgs)(options.path, { | ||
wp_theme_preview: themePath | ||
}); | ||
} else if (wpThemePreview === '') { | ||
options.path = (0, _url.removeQueryArgs)(options.path, 'wp_theme_preview'); | ||
} | ||
} | ||
@@ -32,0 +45,0 @@ return next(options); |
@@ -5,2 +5,4 @@ <!-- Learn how to maintain this file at https://github.com/WordPress/gutenberg/tree/HEAD/packages#maintaining-changelogs. --> | ||
## 6.47.0 (2024-01-24) | ||
## 6.46.0 (2024-01-10) | ||
@@ -7,0 +9,0 @@ |
{ | ||
"name": "@wordpress/api-fetch", | ||
"version": "6.46.0", | ||
"version": "6.47.0", | ||
"description": "Utility to make WordPress REST API requests.", | ||
@@ -31,4 +31,4 @@ "author": "The WordPress Contributors", | ||
"@babel/runtime": "^7.16.0", | ||
"@wordpress/i18n": "^4.49.0", | ||
"@wordpress/url": "^3.50.0" | ||
"@wordpress/i18n": "^4.50.0", | ||
"@wordpress/url": "^3.51.0" | ||
}, | ||
@@ -38,3 +38,3 @@ "publishConfig": { | ||
}, | ||
"gitHead": "5e6f9caa205d3bfdbac131952b7bf9c6ec60569b" | ||
"gitHead": "45de2cb4212fed7f2763e95f10300d1ff9d0ec08" | ||
} |
/** | ||
* WordPress dependencies | ||
*/ | ||
import { addQueryArgs, hasQueryArg } from '@wordpress/url'; | ||
import { addQueryArgs, getQueryArg, removeQueryArgs } from '@wordpress/url'; | ||
@@ -10,2 +10,5 @@ /** | ||
* | ||
* If the REST API request URL has contained the `wp_theme_preview` parameter as `''`, | ||
* then bypass this middleware. | ||
* | ||
* @param {Record<string, any>} themePath | ||
@@ -15,18 +18,22 @@ * @return {import('../types').APIFetchMiddleware} Preloading middleware. | ||
const createThemePreviewMiddleware = ( themePath ) => ( options, next ) => { | ||
if ( | ||
typeof options.url === 'string' && | ||
! hasQueryArg( options.url, 'wp_theme_preview' ) | ||
) { | ||
options.url = addQueryArgs( options.url, { | ||
wp_theme_preview: themePath, | ||
} ); | ||
if ( typeof options.url === 'string' ) { | ||
const wpThemePreview = getQueryArg( options.url, 'wp_theme_preview' ); | ||
if ( wpThemePreview === undefined ) { | ||
options.url = addQueryArgs( options.url, { | ||
wp_theme_preview: themePath, | ||
} ); | ||
} else if ( wpThemePreview === '' ) { | ||
options.url = removeQueryArgs( options.url, 'wp_theme_preview' ); | ||
} | ||
} | ||
if ( | ||
typeof options.path === 'string' && | ||
! hasQueryArg( options.path, 'wp_theme_preview' ) | ||
) { | ||
options.path = addQueryArgs( options.path, { | ||
wp_theme_preview: themePath, | ||
} ); | ||
if ( typeof options.path === 'string' ) { | ||
const wpThemePreview = getQueryArg( options.path, 'wp_theme_preview' ); | ||
if ( wpThemePreview === undefined ) { | ||
options.path = addQueryArgs( options.path, { | ||
wp_theme_preview: themePath, | ||
} ); | ||
} else if ( wpThemePreview === '' ) { | ||
options.path = removeQueryArgs( options.path, 'wp_theme_preview' ); | ||
} | ||
} | ||
@@ -33,0 +40,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
249006
3041
Updated@wordpress/i18n@^4.50.0
Updated@wordpress/url@^3.51.0