author | ymh <ymh.work@gmail.com> |
Mon, 08 Sep 2025 19:44:41 +0200 | |
changeset 23 | 417f20492bf7 |
parent 22 | 8c2e4d02f4ef |
permissions | -rw-r--r-- |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1 |
/******/ (() => { // webpackBootstrap |
19 | 2 |
/******/ "use strict"; |
3 |
/******/ // The require scope |
|
4 |
/******/ var __webpack_require__ = {}; |
|
5 |
/******/ |
|
6 |
/************************************************************************/ |
|
7 |
/******/ /* webpack/runtime/define property getters */ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8 |
/******/ (() => { |
19 | 9 |
/******/ // define getter functions for harmony exports |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
10 |
/******/ __webpack_require__.d = (exports, definition) => { |
19 | 11 |
/******/ for(var key in definition) { |
12 |
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { |
|
13 |
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); |
|
14 |
/******/ } |
|
15 |
/******/ } |
|
9 | 16 |
/******/ }; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
17 |
/******/ })(); |
19 | 18 |
/******/ |
19 |
/******/ /* webpack/runtime/hasOwnProperty shorthand */ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
20 |
/******/ (() => { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
21 |
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
22 |
/******/ })(); |
19 | 23 |
/******/ |
9 | 24 |
/************************************************************************/ |
19 | 25 |
var __webpack_exports__ = {}; |
9 | 26 |
|
19 | 27 |
// EXPORTS |
28 |
__webpack_require__.d(__webpack_exports__, { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
29 |
"default": () => (/* binding */ build_module) |
19 | 30 |
}); |
16 | 31 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
32 |
;// external ["wp","i18n"] |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
33 |
const external_wp_i18n_namespaceObject = window["wp"]["i18n"]; |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
34 |
;// ./node_modules/@wordpress/api-fetch/build-module/middlewares/nonce.js |
18 | 35 |
/** |
36 |
* @param {string} nonce |
|
37 |
* @return {import('../types').APIFetchMiddleware & { nonce: string }} A middleware to enhance a request with a nonce. |
|
38 |
*/ |
|
9 | 39 |
function createNonceMiddleware(nonce) { |
18 | 40 |
/** |
41 |
* @type {import('../types').APIFetchMiddleware & { nonce: string }} |
|
42 |
*/ |
|
43 |
const middleware = (options, next) => { |
|
44 |
const { |
|
45 |
headers = {} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
46 |
} = options; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
47 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
48 |
// If an 'X-WP-Nonce' header (or any case-insensitive variation |
9 | 49 |
// thereof) was specified, no need to add a nonce header. |
18 | 50 |
for (const headerName in headers) { |
51 |
if (headerName.toLowerCase() === 'x-wp-nonce' && headers[headerName] === middleware.nonce) { |
|
9 | 52 |
return next(options); |
53 |
} |
|
54 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
55 |
return next({ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
56 |
...options, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
57 |
headers: { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
58 |
...headers, |
9 | 59 |
'X-WP-Nonce': middleware.nonce |
18 | 60 |
} |
61 |
}); |
|
62 |
}; |
|
9 | 63 |
middleware.nonce = nonce; |
64 |
return middleware; |
|
65 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
66 |
/* harmony default export */ const nonce = (createNonceMiddleware); |
9 | 67 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
68 |
;// ./node_modules/@wordpress/api-fetch/build-module/middlewares/namespace-endpoint.js |
18 | 69 |
/** |
70 |
* @type {import('../types').APIFetchMiddleware} |
|
71 |
*/ |
|
72 |
const namespaceAndEndpointMiddleware = (options, next) => { |
|
73 |
let path = options.path; |
|
74 |
let namespaceTrimmed, endpointTrimmed; |
|
9 | 75 |
if (typeof options.namespace === 'string' && typeof options.endpoint === 'string') { |
76 |
namespaceTrimmed = options.namespace.replace(/^\/|\/$/g, ''); |
|
77 |
endpointTrimmed = options.endpoint.replace(/^\//, ''); |
|
78 |
if (endpointTrimmed) { |
|
79 |
path = namespaceTrimmed + '/' + endpointTrimmed; |
|
80 |
} else { |
|
81 |
path = namespaceTrimmed; |
|
82 |
} |
|
83 |
} |
|
84 |
delete options.namespace; |
|
85 |
delete options.endpoint; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
86 |
return next({ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
87 |
...options, |
18 | 88 |
path |
89 |
}); |
|
9 | 90 |
}; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
91 |
/* harmony default export */ const namespace_endpoint = (namespaceAndEndpointMiddleware); |
9 | 92 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
93 |
;// ./node_modules/@wordpress/api-fetch/build-module/middlewares/root-url.js |
9 | 94 |
/** |
95 |
* Internal dependencies |
|
96 |
*/ |
|
97 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
98 |
|
18 | 99 |
/** |
100 |
* @param {string} rootURL |
|
101 |
* @return {import('../types').APIFetchMiddleware} Root URL middleware. |
|
102 |
*/ |
|
103 |
const createRootURLMiddleware = rootURL => (options, next) => { |
|
104 |
return namespace_endpoint(options, optionsWithPath => { |
|
105 |
let url = optionsWithPath.url; |
|
106 |
let path = optionsWithPath.path; |
|
107 |
let apiRoot; |
|
108 |
if (typeof path === 'string') { |
|
109 |
apiRoot = rootURL; |
|
110 |
if (-1 !== rootURL.indexOf('?')) { |
|
111 |
path = path.replace('?', '&'); |
|
9 | 112 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
113 |
path = path.replace(/^\//, ''); |
9 | 114 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
115 |
// API root may already include query parameter prefix if site is |
18 | 116 |
// configured to use plain permalinks. |
117 |
if ('string' === typeof apiRoot && -1 !== apiRoot.indexOf('?')) { |
|
118 |
path = path.replace('?', '&'); |
|
119 |
} |
|
120 |
url = apiRoot + path; |
|
121 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
122 |
return next({ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
123 |
...optionsWithPath, |
18 | 124 |
url |
9 | 125 |
}); |
18 | 126 |
}); |
9 | 127 |
}; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
128 |
/* harmony default export */ const root_url = (createRootURLMiddleware); |
9 | 129 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
130 |
;// external ["wp","url"] |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
131 |
const external_wp_url_namespaceObject = window["wp"]["url"]; |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
132 |
;// ./node_modules/@wordpress/api-fetch/build-module/middlewares/preloading.js |
16 | 133 |
/** |
19 | 134 |
* WordPress dependencies |
16 | 135 |
*/ |
9 | 136 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
137 |
|
18 | 138 |
/** |
139 |
* @param {Record<string, any>} preloadedData |
|
140 |
* @return {import('../types').APIFetchMiddleware} Preloading middleware. |
|
141 |
*/ |
|
16 | 142 |
function createPreloadingMiddleware(preloadedData) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
143 |
const cache = Object.fromEntries(Object.entries(preloadedData).map(([path, data]) => [(0,external_wp_url_namespaceObject.normalizePath)(path), data])); |
18 | 144 |
return (options, next) => { |
145 |
const { |
|
146 |
parse = true |
|
147 |
} = options; |
|
19 | 148 |
/** @type {string | void} */ |
149 |
let rawPath = options.path; |
|
150 |
if (!rawPath && options.url) { |
|
151 |
const { |
|
152 |
rest_route: pathFromQuery, |
|
153 |
...queryArgs |
|
154 |
} = (0,external_wp_url_namespaceObject.getQueryArgs)(options.url); |
|
155 |
if (typeof pathFromQuery === 'string') { |
|
156 |
rawPath = (0,external_wp_url_namespaceObject.addQueryArgs)(pathFromQuery, queryArgs); |
|
157 |
} |
|
158 |
} |
|
159 |
if (typeof rawPath !== 'string') { |
|
160 |
return next(options); |
|
161 |
} |
|
162 |
const method = options.method || 'GET'; |
|
163 |
const path = (0,external_wp_url_namespaceObject.normalizePath)(rawPath); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
164 |
if ('GET' === method && cache[path]) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
165 |
const cacheData = cache[path]; |
19 | 166 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
167 |
// Unsetting the cache key ensures that the data is only used a single time. |
19 | 168 |
delete cache[path]; |
169 |
return prepareResponse(cacheData, !!parse); |
|
170 |
} else if ('OPTIONS' === method && cache[method] && cache[method][path]) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
171 |
const cacheData = cache[method][path]; |
19 | 172 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
173 |
// Unsetting the cache key ensures that the data is only used a single time. |
19 | 174 |
delete cache[method][path]; |
175 |
return prepareResponse(cacheData, !!parse); |
|
9 | 176 |
} |
177 |
return next(options); |
|
178 |
}; |
|
16 | 179 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
180 |
|
19 | 181 |
/** |
182 |
* This is a helper function that sends a success response. |
|
183 |
* |
|
184 |
* @param {Record<string, any>} responseData |
|
185 |
* @param {boolean} parse |
|
186 |
* @return {Promise<any>} Promise with the response. |
|
187 |
*/ |
|
188 |
function prepareResponse(responseData, parse) { |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
189 |
if (parse) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
190 |
return Promise.resolve(responseData.body); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
191 |
} |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
192 |
try { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
193 |
return Promise.resolve(new window.Response(JSON.stringify(responseData.body), { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
194 |
status: 200, |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
195 |
statusText: 'OK', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
196 |
headers: responseData.headers |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
197 |
})); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
198 |
} catch { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
199 |
// See: https://github.com/WordPress/gutenberg/issues/67358#issuecomment-2621163926. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
200 |
Object.entries(responseData.headers).forEach(([key, value]) => { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
201 |
if (key.toLowerCase() === 'link') { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
202 |
responseData.headers[key] = value.replace(/<([^>]+)>/, (/** @type {any} */_, /** @type {string} */url) => `<${encodeURI(url)}>`); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
203 |
} |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
204 |
}); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
205 |
return Promise.resolve(parse ? responseData.body : new window.Response(JSON.stringify(responseData.body), { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
206 |
status: 200, |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
207 |
statusText: 'OK', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
208 |
headers: responseData.headers |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
209 |
})); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
210 |
} |
19 | 211 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
212 |
/* harmony default export */ const preloading = (createPreloadingMiddleware); |
9 | 213 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
214 |
;// ./node_modules/@wordpress/api-fetch/build-module/middlewares/fetch-all-middleware.js |
9 | 215 |
/** |
216 |
* WordPress dependencies |
|
217 |
*/ |
|
16 | 218 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
219 |
|
16 | 220 |
/** |
221 |
* Internal dependencies |
|
222 |
*/ |
|
223 |
||
18 | 224 |
|
225 |
/** |
|
226 |
* Apply query arguments to both URL and Path, whichever is present. |
|
227 |
* |
|
228 |
* @param {import('../types').APIFetchOptions} props |
|
19 | 229 |
* @param {Record<string, string | number>} queryArgs |
18 | 230 |
* @return {import('../types').APIFetchOptions} The request with the modified query args |
231 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
232 |
const modifyQuery = ({ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
233 |
path, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
234 |
url, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
235 |
...options |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
236 |
}, queryArgs) => ({ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
237 |
...options, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
238 |
url: url && (0,external_wp_url_namespaceObject.addQueryArgs)(url, queryArgs), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
239 |
path: path && (0,external_wp_url_namespaceObject.addQueryArgs)(path, queryArgs) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
240 |
}); |
9 | 241 |
|
18 | 242 |
/** |
243 |
* Duplicates parsing functionality from apiFetch. |
|
244 |
* |
|
245 |
* @param {Response} response |
|
246 |
* @return {Promise<any>} Parsed response json. |
|
247 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
248 |
const parseResponse = response => response.json ? response.json() : Promise.reject(response); |
9 | 249 |
|
18 | 250 |
/** |
251 |
* @param {string | null} linkHeader |
|
252 |
* @return {{ next?: string }} The parsed link header. |
|
253 |
*/ |
|
254 |
const parseLinkHeader = linkHeader => { |
|
9 | 255 |
if (!linkHeader) { |
256 |
return {}; |
|
257 |
} |
|
18 | 258 |
const match = linkHeader.match(/<([^>]+)>; rel="next"/); |
9 | 259 |
return match ? { |
260 |
next: match[1] |
|
261 |
} : {}; |
|
262 |
}; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
263 |
|
18 | 264 |
/** |
265 |
* @param {Response} response |
|
266 |
* @return {string | undefined} The next page URL. |
|
267 |
*/ |
|
268 |
const getNextPageUrl = response => { |
|
269 |
const { |
|
270 |
next |
|
271 |
} = parseLinkHeader(response.headers.get('link')); |
|
9 | 272 |
return next; |
273 |
}; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
274 |
|
18 | 275 |
/** |
276 |
* @param {import('../types').APIFetchOptions} options |
|
277 |
* @return {boolean} True if the request contains an unbounded query. |
|
278 |
*/ |
|
279 |
const requestContainsUnboundedQuery = options => { |
|
280 |
const pathIsUnbounded = !!options.path && options.path.indexOf('per_page=-1') !== -1; |
|
281 |
const urlIsUnbounded = !!options.url && options.url.indexOf('per_page=-1') !== -1; |
|
9 | 282 |
return pathIsUnbounded || urlIsUnbounded; |
18 | 283 |
}; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
284 |
|
18 | 285 |
/** |
286 |
* The REST API enforces an upper limit on the per_page option. To handle large |
|
287 |
* collections, apiFetch consumers can pass `per_page=-1`; this middleware will |
|
288 |
* then recursively assemble a full response array from all available pages. |
|
289 |
* |
|
290 |
* @type {import('../types').APIFetchMiddleware} |
|
291 |
*/ |
|
292 |
const fetchAllMiddleware = async (options, next) => { |
|
293 |
if (options.parse === false) { |
|
294 |
// If a consumer has opted out of parsing, do not apply middleware. |
|
295 |
return next(options); |
|
296 |
} |
|
297 |
if (!requestContainsUnboundedQuery(options)) { |
|
298 |
// If neither url nor path is requesting all items, do not apply middleware. |
|
299 |
return next(options); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
300 |
} |
9 | 301 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
302 |
// Retrieve requested page of results. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
303 |
const response = await build_module({ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
304 |
...modifyQuery(options, { |
18 | 305 |
per_page: 100 |
306 |
}), |
|
307 |
// Ensure headers are returned for page 1. |
|
308 |
parse: false |
|
309 |
}); |
|
310 |
const results = await parseResponse(response); |
|
311 |
if (!Array.isArray(results)) { |
|
312 |
// We have no reliable way of merging non-array results. |
|
313 |
return results; |
|
314 |
} |
|
315 |
let nextPage = getNextPageUrl(response); |
|
316 |
if (!nextPage) { |
|
317 |
// There are no further pages to request. |
|
318 |
return results; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
319 |
} |
18 | 320 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
321 |
// Iteratively fetch all remaining pages until no "next" header is found. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
322 |
let mergedResults = /** @type {any[]} */[].concat(results); |
18 | 323 |
while (nextPage) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
324 |
const nextResponse = await build_module({ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
325 |
...options, |
18 | 326 |
// Ensure the URL for the next page is used instead of any provided path. |
327 |
path: undefined, |
|
328 |
url: nextPage, |
|
329 |
// Ensure we still get headers so we can identify the next page. |
|
330 |
parse: false |
|
331 |
}); |
|
332 |
const nextResults = await parseResponse(nextResponse); |
|
333 |
mergedResults = mergedResults.concat(nextResults); |
|
334 |
nextPage = getNextPageUrl(nextResponse); |
|
335 |
} |
|
336 |
return mergedResults; |
|
337 |
}; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
338 |
/* harmony default export */ const fetch_all_middleware = (fetchAllMiddleware); |
9 | 339 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
340 |
;// ./node_modules/@wordpress/api-fetch/build-module/middlewares/http-v1.js |
9 | 341 |
/** |
342 |
* Set of HTTP methods which are eligible to be overridden. |
|
343 |
* |
|
18 | 344 |
* @type {Set<string>} |
9 | 345 |
*/ |
18 | 346 |
const OVERRIDE_METHODS = new Set(['PATCH', 'PUT', 'DELETE']); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
347 |
|
9 | 348 |
/** |
349 |
* Default request method. |
|
350 |
* |
|
351 |
* "A request has an associated method (a method). Unless stated otherwise it |
|
352 |
* is `GET`." |
|
353 |
* |
|
354 |
* @see https://fetch.spec.whatwg.org/#requests |
|
355 |
* |
|
356 |
* @type {string} |
|
357 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
358 |
const DEFAULT_METHOD = 'GET'; |
9 | 359 |
|
360 |
/** |
|
361 |
* API Fetch middleware which overrides the request method for HTTP v1 |
|
362 |
* compatibility leveraging the REST API X-HTTP-Method-Override header. |
|
363 |
* |
|
18 | 364 |
* @type {import('../types').APIFetchMiddleware} |
9 | 365 |
*/ |
18 | 366 |
const httpV1Middleware = (options, next) => { |
367 |
const { |
|
368 |
method = DEFAULT_METHOD |
|
369 |
} = options; |
|
9 | 370 |
if (OVERRIDE_METHODS.has(method.toUpperCase())) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
371 |
options = { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
372 |
...options, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
373 |
headers: { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
374 |
...options.headers, |
9 | 375 |
'X-HTTP-Method-Override': method, |
376 |
'Content-Type': 'application/json' |
|
18 | 377 |
}, |
9 | 378 |
method: 'POST' |
18 | 379 |
}; |
9 | 380 |
} |
18 | 381 |
return next(options); |
382 |
}; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
383 |
/* harmony default export */ const http_v1 = (httpV1Middleware); |
9 | 384 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
385 |
;// ./node_modules/@wordpress/api-fetch/build-module/middlewares/user-locale.js |
9 | 386 |
/** |
387 |
* WordPress dependencies |
|
388 |
*/ |
|
389 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
390 |
|
18 | 391 |
/** |
392 |
* @type {import('../types').APIFetchMiddleware} |
|
393 |
*/ |
|
394 |
const userLocaleMiddleware = (options, next) => { |
|
19 | 395 |
if (typeof options.url === 'string' && !(0,external_wp_url_namespaceObject.hasQueryArg)(options.url, '_locale')) { |
396 |
options.url = (0,external_wp_url_namespaceObject.addQueryArgs)(options.url, { |
|
9 | 397 |
_locale: 'user' |
398 |
}); |
|
399 |
} |
|
19 | 400 |
if (typeof options.path === 'string' && !(0,external_wp_url_namespaceObject.hasQueryArg)(options.path, '_locale')) { |
401 |
options.path = (0,external_wp_url_namespaceObject.addQueryArgs)(options.path, { |
|
9 | 402 |
_locale: 'user' |
403 |
}); |
|
404 |
} |
|
18 | 405 |
return next(options); |
406 |
}; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
407 |
/* harmony default export */ const user_locale = (userLocaleMiddleware); |
9 | 408 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
409 |
;// ./node_modules/@wordpress/api-fetch/build-module/utils/response.js |
16 | 410 |
/** |
411 |
* WordPress dependencies |
|
412 |
*/ |
|
413 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
414 |
|
16 | 415 |
/** |
416 |
* Parses the apiFetch response. |
|
417 |
* |
|
418 |
* @param {Response} response |
|
419 |
* @param {boolean} shouldParseResponse |
|
420 |
* |
|
18 | 421 |
* @return {Promise<any> | null | Response} Parsed response. |
16 | 422 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
423 |
const response_parseResponse = (response, shouldParseResponse = true) => { |
16 | 424 |
if (shouldParseResponse) { |
425 |
if (response.status === 204) { |
|
426 |
return null; |
|
427 |
} |
|
428 |
return response.json ? response.json() : Promise.reject(response); |
|
429 |
} |
|
430 |
return response; |
|
431 |
}; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
432 |
|
18 | 433 |
/** |
434 |
* Calls the `json` function on the Response, throwing an error if the response |
|
435 |
* doesn't have a json function or if parsing the json itself fails. |
|
436 |
* |
|
437 |
* @param {Response} response |
|
438 |
* @return {Promise<any>} Parsed response. |
|
439 |
*/ |
|
440 |
const parseJsonAndNormalizeError = response => { |
|
441 |
const invalidJsonError = { |
|
16 | 442 |
code: 'invalid_json', |
19 | 443 |
message: (0,external_wp_i18n_namespaceObject.__)('The response is not a valid JSON response.') |
16 | 444 |
}; |
445 |
if (!response || !response.json) { |
|
446 |
throw invalidJsonError; |
|
447 |
} |
|
18 | 448 |
return response.json().catch(() => { |
16 | 449 |
throw invalidJsonError; |
450 |
}); |
|
451 |
}; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
452 |
|
16 | 453 |
/** |
454 |
* Parses the apiFetch response properly and normalize response errors. |
|
455 |
* |
|
456 |
* @param {Response} response |
|
457 |
* @param {boolean} shouldParseResponse |
|
458 |
* |
|
18 | 459 |
* @return {Promise<any>} Parsed response. |
16 | 460 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
461 |
const parseResponseAndNormalizeError = (response, shouldParseResponse = true) => { |
18 | 462 |
return Promise.resolve(response_parseResponse(response, shouldParseResponse)).catch(res => parseAndThrowError(res, shouldParseResponse)); |
16 | 463 |
}; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
464 |
|
18 | 465 |
/** |
466 |
* Parses a response, throwing an error if parsing the response fails. |
|
467 |
* |
|
468 |
* @param {Response} response |
|
19 | 469 |
* @param {boolean} shouldParseResponse |
18 | 470 |
* @return {Promise<any>} Parsed response. |
471 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
472 |
function parseAndThrowError(response, shouldParseResponse = true) { |
16 | 473 |
if (!shouldParseResponse) { |
474 |
throw response; |
|
475 |
} |
|
18 | 476 |
return parseJsonAndNormalizeError(response).then(error => { |
477 |
const unknownError = { |
|
16 | 478 |
code: 'unknown_error', |
19 | 479 |
message: (0,external_wp_i18n_namespaceObject.__)('An unknown error occurred.') |
16 | 480 |
}; |
481 |
throw error || unknownError; |
|
482 |
}); |
|
483 |
} |
|
484 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
485 |
;// ./node_modules/@wordpress/api-fetch/build-module/middlewares/media-upload.js |
9 | 486 |
/** |
487 |
* WordPress dependencies |
|
488 |
*/ |
|
489 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
490 |
|
9 | 491 |
/** |
492 |
* Internal dependencies |
|
493 |
*/ |
|
494 |
||
495 |
||
16 | 496 |
/** |
19 | 497 |
* @param {import('../types').APIFetchOptions} options |
498 |
* @return {boolean} True if the request is for media upload. |
|
499 |
*/ |
|
500 |
function isMediaUploadRequest(options) { |
|
501 |
const isCreateMethod = !!options.method && options.method === 'POST'; |
|
502 |
const isMediaEndpoint = !!options.path && options.path.indexOf('/wp/v2/media') !== -1 || !!options.url && options.url.indexOf('/wp/v2/media') !== -1; |
|
503 |
return isMediaEndpoint && isCreateMethod; |
|
504 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
505 |
|
19 | 506 |
/** |
16 | 507 |
* Middleware handling media upload failures and retries. |
508 |
* |
|
18 | 509 |
* @type {import('../types').APIFetchMiddleware} |
16 | 510 |
*/ |
18 | 511 |
const mediaUploadMiddleware = (options, next) => { |
19 | 512 |
if (!isMediaUploadRequest(options)) { |
18 | 513 |
return next(options); |
16 | 514 |
} |
18 | 515 |
let retries = 0; |
516 |
const maxRetries = 5; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
517 |
|
18 | 518 |
/** |
519 |
* @param {string} attachmentId |
|
520 |
* @return {Promise<any>} Processed post response. |
|
521 |
*/ |
|
522 |
const postProcess = attachmentId => { |
|
16 | 523 |
retries++; |
524 |
return next({ |
|
18 | 525 |
path: `/wp/v2/media/${attachmentId}/post-process`, |
16 | 526 |
method: 'POST', |
527 |
data: { |
|
528 |
action: 'create-image-subsizes' |
|
529 |
}, |
|
530 |
parse: false |
|
18 | 531 |
}).catch(() => { |
16 | 532 |
if (retries < maxRetries) { |
533 |
return postProcess(attachmentId); |
|
534 |
} |
|
535 |
next({ |
|
18 | 536 |
path: `/wp/v2/media/${attachmentId}?force=true`, |
16 | 537 |
method: 'DELETE' |
538 |
}); |
|
539 |
return Promise.reject(); |
|
540 |
}); |
|
541 |
}; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
542 |
return next({ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
543 |
...options, |
16 | 544 |
parse: false |
18 | 545 |
}).catch(response => { |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
546 |
// `response` could actually be an error thrown by `defaultFetchHandler`. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
547 |
if (!response.headers) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
548 |
return Promise.reject(response); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
549 |
} |
18 | 550 |
const attachmentId = response.headers.get('x-wp-upload-attachment-id'); |
16 | 551 |
if (response.status >= 500 && response.status < 600 && attachmentId) { |
18 | 552 |
return postProcess(attachmentId).catch(() => { |
16 | 553 |
if (options.parse !== false) { |
554 |
return Promise.reject({ |
|
555 |
code: 'post_process', |
|
19 | 556 |
message: (0,external_wp_i18n_namespaceObject.__)('Media upload failed. If this is a photo or a large image, please scale it down and try again.') |
16 | 557 |
}); |
558 |
} |
|
559 |
return Promise.reject(response); |
|
560 |
}); |
|
561 |
} |
|
562 |
return parseAndThrowError(response, options.parse); |
|
18 | 563 |
}).then(response => parseResponseAndNormalizeError(response, options.parse)); |
564 |
}; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
565 |
/* harmony default export */ const media_upload = (mediaUploadMiddleware); |
16 | 566 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
567 |
;// ./node_modules/@wordpress/api-fetch/build-module/middlewares/theme-preview.js |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
568 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
569 |
* WordPress dependencies |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
570 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
571 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
572 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
573 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
574 |
* This appends a `wp_theme_preview` parameter to the REST API request URL if |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
575 |
* the admin URL contains a `theme` GET parameter. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
576 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
577 |
* If the REST API request URL has contained the `wp_theme_preview` parameter as `''`, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
578 |
* then bypass this middleware. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
579 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
580 |
* @param {Record<string, any>} themePath |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
581 |
* @return {import('../types').APIFetchMiddleware} Preloading middleware. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
582 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
583 |
const createThemePreviewMiddleware = themePath => (options, next) => { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
584 |
if (typeof options.url === 'string') { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
585 |
const wpThemePreview = (0,external_wp_url_namespaceObject.getQueryArg)(options.url, 'wp_theme_preview'); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
586 |
if (wpThemePreview === undefined) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
587 |
options.url = (0,external_wp_url_namespaceObject.addQueryArgs)(options.url, { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
588 |
wp_theme_preview: themePath |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
589 |
}); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
590 |
} else if (wpThemePreview === '') { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
591 |
options.url = (0,external_wp_url_namespaceObject.removeQueryArgs)(options.url, 'wp_theme_preview'); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
592 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
593 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
594 |
if (typeof options.path === 'string') { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
595 |
const wpThemePreview = (0,external_wp_url_namespaceObject.getQueryArg)(options.path, 'wp_theme_preview'); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
596 |
if (wpThemePreview === undefined) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
597 |
options.path = (0,external_wp_url_namespaceObject.addQueryArgs)(options.path, { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
598 |
wp_theme_preview: themePath |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
599 |
}); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
600 |
} else if (wpThemePreview === '') { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
601 |
options.path = (0,external_wp_url_namespaceObject.removeQueryArgs)(options.path, 'wp_theme_preview'); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
602 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
603 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
604 |
return next(options); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
605 |
}; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
606 |
/* harmony default export */ const theme_preview = (createThemePreviewMiddleware); |
16 | 607 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
608 |
;// ./node_modules/@wordpress/api-fetch/build-module/index.js |
16 | 609 |
/** |
610 |
* WordPress dependencies |
|
611 |
*/ |
|
612 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
613 |
|
16 | 614 |
/** |
615 |
* Internal dependencies |
|
616 |
*/ |
|
617 |
||
618 |
||
619 |
||
620 |
||
9 | 621 |
|
622 |
||
623 |
||
624 |
||
625 |
||
626 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
627 |
|
9 | 628 |
/** |
629 |
* Default set of header values which should be sent with every request unless |
|
630 |
* explicitly provided through apiFetch options. |
|
631 |
* |
|
18 | 632 |
* @type {Record<string, string>} |
9 | 633 |
*/ |
18 | 634 |
const DEFAULT_HEADERS = { |
9 | 635 |
// The backend uses the Accept header as a condition for considering an |
636 |
// incoming request as a REST request. |
|
637 |
// |
|
638 |
// See: https://core.trac.wordpress.org/ticket/44534 |
|
639 |
Accept: 'application/json, */*;q=0.1' |
|
640 |
}; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
641 |
|
9 | 642 |
/** |
643 |
* Default set of fetch option values which should be sent with every request |
|
644 |
* unless explicitly provided through apiFetch options. |
|
645 |
* |
|
646 |
* @type {Object} |
|
647 |
*/ |
|
18 | 648 |
const DEFAULT_OPTIONS = { |
9 | 649 |
credentials: 'include' |
650 |
}; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
651 |
|
18 | 652 |
/** @typedef {import('./types').APIFetchMiddleware} APIFetchMiddleware */ |
653 |
/** @typedef {import('./types').APIFetchOptions} APIFetchOptions */ |
|
654 |
||
655 |
/** |
|
656 |
* @type {import('./types').APIFetchMiddleware[]} |
|
657 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
658 |
const middlewares = [user_locale, namespace_endpoint, http_v1, fetch_all_middleware]; |
18 | 659 |
|
660 |
/** |
|
661 |
* Register a middleware |
|
662 |
* |
|
663 |
* @param {import('./types').APIFetchMiddleware} middleware |
|
664 |
*/ |
|
9 | 665 |
function registerMiddleware(middleware) { |
666 |
middlewares.unshift(middleware); |
|
667 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
668 |
|
18 | 669 |
/** |
670 |
* Checks the status of a response, throwing the Response as an error if |
|
671 |
* it is outside the 200 range. |
|
672 |
* |
|
673 |
* @param {Response} response |
|
674 |
* @return {Response} The response if the status is in the 200 range. |
|
675 |
*/ |
|
676 |
const checkStatus = response => { |
|
16 | 677 |
if (response.status >= 200 && response.status < 300) { |
678 |
return response; |
|
679 |
} |
|
680 |
throw response; |
|
681 |
}; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
682 |
|
18 | 683 |
/** @typedef {(options: import('./types').APIFetchOptions) => Promise<any>} FetchHandler*/ |
16 | 684 |
|
18 | 685 |
/** |
686 |
* @type {FetchHandler} |
|
687 |
*/ |
|
688 |
const defaultFetchHandler = nextOptions => { |
|
689 |
const { |
|
690 |
url, |
|
691 |
path, |
|
692 |
data, |
|
693 |
parse = true, |
|
694 |
...remainingOptions |
|
695 |
} = nextOptions; |
|
696 |
let { |
|
697 |
body, |
|
698 |
headers |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
699 |
} = nextOptions; |
9 | 700 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
701 |
// Merge explicitly-provided headers with default values. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
702 |
headers = { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
703 |
...DEFAULT_HEADERS, |
18 | 704 |
...headers |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
705 |
}; |
9 | 706 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
707 |
// The `data` property is a shorthand for sending a JSON body. |
9 | 708 |
if (data) { |
709 |
body = JSON.stringify(data); |
|
710 |
headers['Content-Type'] = 'application/json'; |
|
711 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
712 |
const responsePromise = window.fetch( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
713 |
// Fall back to explicitly passing `window.location` which is the behavior if `undefined` is passed. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
714 |
url || path || window.location.href, { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
715 |
...DEFAULT_OPTIONS, |
18 | 716 |
...remainingOptions, |
717 |
body, |
|
718 |
headers |
|
719 |
}); |
|
19 | 720 |
return responsePromise.then(value => Promise.resolve(value).then(checkStatus).catch(response => parseAndThrowError(response, parse)).then(response => parseResponseAndNormalizeError(response, parse)), err => { |
721 |
// Re-throw AbortError for the users to handle it themselves. |
|
722 |
if (err && err.name === 'AbortError') { |
|
723 |
throw err; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
724 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
725 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
726 |
// Otherwise, there is most likely no network connection. |
19 | 727 |
// Unfortunately the message might depend on the browser. |
16 | 728 |
throw { |
729 |
code: 'fetch_error', |
|
19 | 730 |
message: (0,external_wp_i18n_namespaceObject.__)('You are probably offline.') |
9 | 731 |
}; |
732 |
}); |
|
733 |
}; |
|
734 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
735 |
/** @type {FetchHandler} */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
736 |
let fetchHandler = defaultFetchHandler; |
18 | 737 |
|
9 | 738 |
/** |
739 |
* Defines a custom fetch handler for making the requests that will override |
|
740 |
* the default one using window.fetch |
|
741 |
* |
|
18 | 742 |
* @param {FetchHandler} newFetchHandler The new fetch handler |
9 | 743 |
*/ |
744 |
function setFetchHandler(newFetchHandler) { |
|
745 |
fetchHandler = newFetchHandler; |
|
746 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
747 |
|
18 | 748 |
/** |
749 |
* @template T |
|
750 |
* @param {import('./types').APIFetchOptions} options |
|
751 |
* @return {Promise<T>} A promise representing the request processed via the registered middlewares. |
|
752 |
*/ |
|
9 | 753 |
function apiFetch(options) { |
18 | 754 |
// creates a nested function chain that calls all middlewares and finally the `fetchHandler`, |
755 |
// converting `middlewares = [ m1, m2, m3 ]` into: |
|
756 |
// ``` |
|
757 |
// opts1 => m1( opts1, opts2 => m2( opts2, opts3 => m3( opts3, fetchHandler ) ) ); |
|
758 |
// ``` |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
759 |
const enhancedHandler = middlewares.reduceRight((/** @type {FetchHandler} */next, middleware) => { |
18 | 760 |
return workingOptions => middleware(workingOptions, next); |
761 |
}, fetchHandler); |
|
762 |
return enhancedHandler(options).catch(error => { |
|
763 |
if (error.code !== 'rest_cookie_invalid_nonce') { |
|
764 |
return Promise.reject(error); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
765 |
} |
16 | 766 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
767 |
// If the nonce is invalid, refresh it and try again. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
768 |
return window |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
769 |
// @ts-ignore |
18 | 770 |
.fetch(apiFetch.nonceEndpoint).then(checkStatus).then(data => data.text()).then(text => { |
771 |
// @ts-ignore |
|
772 |
apiFetch.nonceMiddleware.nonce = text; |
|
773 |
return apiFetch(options); |
|
16 | 774 |
}); |
775 |
}); |
|
9 | 776 |
} |
777 |
apiFetch.use = registerMiddleware; |
|
778 |
apiFetch.setFetchHandler = setFetchHandler; |
|
16 | 779 |
apiFetch.createNonceMiddleware = nonce; |
9 | 780 |
apiFetch.createPreloadingMiddleware = preloading; |
781 |
apiFetch.createRootURLMiddleware = root_url; |
|
782 |
apiFetch.fetchAllMiddleware = fetch_all_middleware; |
|
16 | 783 |
apiFetch.mediaUploadMiddleware = media_upload; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
784 |
apiFetch.createThemePreviewMiddleware = theme_preview; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
785 |
/* harmony default export */ const build_module = (apiFetch); |
9 | 786 |
|
19 | 787 |
(window.wp = window.wp || {}).apiFetch = __webpack_exports__["default"]; |
788 |
/******/ })() |
|
789 |
; |