1 /******/ (function() { // webpackBootstrap |
1 /******/ (() => { // webpackBootstrap |
2 /******/ "use strict"; |
2 /******/ "use strict"; |
3 /******/ // The require scope |
3 /******/ var __webpack_modules__ = ({ |
4 /******/ var __webpack_require__ = {}; |
4 |
|
5 /***/ 7734: |
|
6 /***/ ((module) => { |
|
7 |
|
8 |
|
9 |
|
10 // do not edit .js files directly - edit src/index.jst |
|
11 |
|
12 |
|
13 var envHasBigInt64Array = typeof BigInt64Array !== 'undefined'; |
|
14 |
|
15 |
|
16 module.exports = function equal(a, b) { |
|
17 if (a === b) return true; |
|
18 |
|
19 if (a && b && typeof a == 'object' && typeof b == 'object') { |
|
20 if (a.constructor !== b.constructor) return false; |
|
21 |
|
22 var length, i, keys; |
|
23 if (Array.isArray(a)) { |
|
24 length = a.length; |
|
25 if (length != b.length) return false; |
|
26 for (i = length; i-- !== 0;) |
|
27 if (!equal(a[i], b[i])) return false; |
|
28 return true; |
|
29 } |
|
30 |
|
31 |
|
32 if ((a instanceof Map) && (b instanceof Map)) { |
|
33 if (a.size !== b.size) return false; |
|
34 for (i of a.entries()) |
|
35 if (!b.has(i[0])) return false; |
|
36 for (i of a.entries()) |
|
37 if (!equal(i[1], b.get(i[0]))) return false; |
|
38 return true; |
|
39 } |
|
40 |
|
41 if ((a instanceof Set) && (b instanceof Set)) { |
|
42 if (a.size !== b.size) return false; |
|
43 for (i of a.entries()) |
|
44 if (!b.has(i[0])) return false; |
|
45 return true; |
|
46 } |
|
47 |
|
48 if (ArrayBuffer.isView(a) && ArrayBuffer.isView(b)) { |
|
49 length = a.length; |
|
50 if (length != b.length) return false; |
|
51 for (i = length; i-- !== 0;) |
|
52 if (a[i] !== b[i]) return false; |
|
53 return true; |
|
54 } |
|
55 |
|
56 |
|
57 if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags; |
|
58 if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf(); |
|
59 if (a.toString !== Object.prototype.toString) return a.toString() === b.toString(); |
|
60 |
|
61 keys = Object.keys(a); |
|
62 length = keys.length; |
|
63 if (length !== Object.keys(b).length) return false; |
|
64 |
|
65 for (i = length; i-- !== 0;) |
|
66 if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false; |
|
67 |
|
68 for (i = length; i-- !== 0;) { |
|
69 var key = keys[i]; |
|
70 |
|
71 if (!equal(a[key], b[key])) return false; |
|
72 } |
|
73 |
|
74 return true; |
|
75 } |
|
76 |
|
77 // true if both NaN, false otherwise |
|
78 return a!==a && b!==b; |
|
79 }; |
|
80 |
|
81 |
|
82 /***/ }) |
|
83 |
|
84 /******/ }); |
|
85 /************************************************************************/ |
|
86 /******/ // The module cache |
|
87 /******/ var __webpack_module_cache__ = {}; |
|
88 /******/ |
|
89 /******/ // The require function |
|
90 /******/ function __webpack_require__(moduleId) { |
|
91 /******/ // Check if module is in cache |
|
92 /******/ var cachedModule = __webpack_module_cache__[moduleId]; |
|
93 /******/ if (cachedModule !== undefined) { |
|
94 /******/ return cachedModule.exports; |
|
95 /******/ } |
|
96 /******/ // Create a new module (and put it into the cache) |
|
97 /******/ var module = __webpack_module_cache__[moduleId] = { |
|
98 /******/ // no module.id needed |
|
99 /******/ // no module.loaded needed |
|
100 /******/ exports: {} |
|
101 /******/ }; |
|
102 /******/ |
|
103 /******/ // Execute the module function |
|
104 /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); |
|
105 /******/ |
|
106 /******/ // Return the exports of the module |
|
107 /******/ return module.exports; |
|
108 /******/ } |
5 /******/ |
109 /******/ |
6 /************************************************************************/ |
110 /************************************************************************/ |
7 /******/ /* webpack/runtime/compat get default export */ |
111 /******/ /* webpack/runtime/compat get default export */ |
8 /******/ !function() { |
112 /******/ (() => { |
9 /******/ // getDefaultExport function for compatibility with non-harmony modules |
113 /******/ // getDefaultExport function for compatibility with non-harmony modules |
10 /******/ __webpack_require__.n = function(module) { |
114 /******/ __webpack_require__.n = (module) => { |
11 /******/ var getter = module && module.__esModule ? |
115 /******/ var getter = module && module.__esModule ? |
12 /******/ function() { return module['default']; } : |
116 /******/ () => (module['default']) : |
13 /******/ function() { return module; }; |
117 /******/ () => (module); |
14 /******/ __webpack_require__.d(getter, { a: getter }); |
118 /******/ __webpack_require__.d(getter, { a: getter }); |
15 /******/ return getter; |
119 /******/ return getter; |
16 /******/ }; |
120 /******/ }; |
17 /******/ }(); |
121 /******/ })(); |
18 /******/ |
122 /******/ |
19 /******/ /* webpack/runtime/define property getters */ |
123 /******/ /* webpack/runtime/define property getters */ |
20 /******/ !function() { |
124 /******/ (() => { |
21 /******/ // define getter functions for harmony exports |
125 /******/ // define getter functions for harmony exports |
22 /******/ __webpack_require__.d = function(exports, definition) { |
126 /******/ __webpack_require__.d = (exports, definition) => { |
23 /******/ for(var key in definition) { |
127 /******/ for(var key in definition) { |
24 /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { |
128 /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { |
25 /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); |
129 /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); |
26 /******/ } |
130 /******/ } |
27 /******/ } |
131 /******/ } |
28 /******/ }; |
132 /******/ }; |
29 /******/ }(); |
133 /******/ })(); |
30 /******/ |
134 /******/ |
31 /******/ /* webpack/runtime/hasOwnProperty shorthand */ |
135 /******/ /* webpack/runtime/hasOwnProperty shorthand */ |
32 /******/ !function() { |
136 /******/ (() => { |
33 /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); } |
137 /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) |
34 /******/ }(); |
138 /******/ })(); |
35 /******/ |
139 /******/ |
36 /************************************************************************/ |
140 /************************************************************************/ |
37 var __webpack_exports__ = {}; |
141 var __webpack_exports__ = {}; |
|
142 // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. |
|
143 (() => { |
38 |
144 |
39 // EXPORTS |
145 // EXPORTS |
40 __webpack_require__.d(__webpack_exports__, { |
146 __webpack_require__.d(__webpack_exports__, { |
41 "default": function() { return /* binding */ build_module; } |
147 "default": () => (/* binding */ build_module) |
42 }); |
148 }); |
43 |
149 |
44 ;// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/extends.js |
|
45 function _extends() { |
|
46 _extends = Object.assign ? Object.assign.bind() : function (target) { |
|
47 for (var i = 1; i < arguments.length; i++) { |
|
48 var source = arguments[i]; |
|
49 |
|
50 for (var key in source) { |
|
51 if (Object.prototype.hasOwnProperty.call(source, key)) { |
|
52 target[key] = source[key]; |
|
53 } |
|
54 } |
|
55 } |
|
56 |
|
57 return target; |
|
58 }; |
|
59 return _extends.apply(this, arguments); |
|
60 } |
|
61 ;// CONCATENATED MODULE: external ["wp","element"] |
150 ;// CONCATENATED MODULE: external ["wp","element"] |
62 var external_wp_element_namespaceObject = window["wp"]["element"]; |
151 const external_wp_element_namespaceObject = window["wp"]["element"]; |
63 ;// CONCATENATED MODULE: external ["wp","data"] |
152 ;// CONCATENATED MODULE: external ["wp","data"] |
64 var external_wp_data_namespaceObject = window["wp"]["data"]; |
153 const external_wp_data_namespaceObject = window["wp"]["data"]; |
65 ;// CONCATENATED MODULE: external ["wp","deprecated"] |
154 // EXTERNAL MODULE: ./node_modules/fast-deep-equal/es6/index.js |
66 var external_wp_deprecated_namespaceObject = window["wp"]["deprecated"]; |
155 var es6 = __webpack_require__(7734); |
67 var external_wp_deprecated_default = /*#__PURE__*/__webpack_require__.n(external_wp_deprecated_namespaceObject); |
156 var es6_default = /*#__PURE__*/__webpack_require__.n(es6); |
68 ;// CONCATENATED MODULE: external "lodash" |
|
69 var external_lodash_namespaceObject = window["lodash"]; |
|
70 ;// CONCATENATED MODULE: external ["wp","compose"] |
157 ;// CONCATENATED MODULE: external ["wp","compose"] |
71 var external_wp_compose_namespaceObject = window["wp"]["compose"]; |
158 const external_wp_compose_namespaceObject = window["wp"]["compose"]; |
72 ;// CONCATENATED MODULE: external ["wp","i18n"] |
159 ;// CONCATENATED MODULE: external ["wp","i18n"] |
73 var external_wp_i18n_namespaceObject = window["wp"]["i18n"]; |
160 const external_wp_i18n_namespaceObject = window["wp"]["i18n"]; |
74 ;// CONCATENATED MODULE: external ["wp","apiFetch"] |
161 ;// CONCATENATED MODULE: external ["wp","apiFetch"] |
75 var external_wp_apiFetch_namespaceObject = window["wp"]["apiFetch"]; |
162 const external_wp_apiFetch_namespaceObject = window["wp"]["apiFetch"]; |
76 var external_wp_apiFetch_default = /*#__PURE__*/__webpack_require__.n(external_wp_apiFetch_namespaceObject); |
163 var external_wp_apiFetch_default = /*#__PURE__*/__webpack_require__.n(external_wp_apiFetch_namespaceObject); |
77 ;// CONCATENATED MODULE: external ["wp","url"] |
164 ;// CONCATENATED MODULE: external ["wp","url"] |
78 var external_wp_url_namespaceObject = window["wp"]["url"]; |
165 const external_wp_url_namespaceObject = window["wp"]["url"]; |
79 ;// CONCATENATED MODULE: external ["wp","components"] |
166 ;// CONCATENATED MODULE: external ["wp","components"] |
80 var external_wp_components_namespaceObject = window["wp"]["components"]; |
167 const external_wp_components_namespaceObject = window["wp"]["components"]; |
81 ;// CONCATENATED MODULE: external ["wp","blocks"] |
168 ;// CONCATENATED MODULE: external ["wp","blocks"] |
82 var external_wp_blocks_namespaceObject = window["wp"]["blocks"]; |
169 const external_wp_blocks_namespaceObject = window["wp"]["blocks"]; |
|
170 ;// CONCATENATED MODULE: external "ReactJSXRuntime" |
|
171 const external_ReactJSXRuntime_namespaceObject = window["ReactJSXRuntime"]; |
83 ;// CONCATENATED MODULE: ./node_modules/@wordpress/server-side-render/build-module/server-side-render.js |
172 ;// CONCATENATED MODULE: ./node_modules/@wordpress/server-side-render/build-module/server-side-render.js |
84 |
|
85 |
|
86 |
|
87 /** |
173 /** |
88 * External dependencies |
174 * External dependencies |
89 */ |
175 */ |
90 |
176 |
|
177 |
91 /** |
178 /** |
92 * WordPress dependencies |
179 * WordPress dependencies |
93 */ |
180 */ |
94 |
181 |
95 |
182 |
97 |
184 |
98 |
185 |
99 |
186 |
100 |
187 |
101 |
188 |
102 function rendererPath(block) { |
189 |
103 let attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; |
190 const EMPTY_OBJECT = {}; |
104 let urlQueryArgs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; |
191 function rendererPath(block, attributes = null, urlQueryArgs = {}) { |
105 return (0,external_wp_url_namespaceObject.addQueryArgs)(`/wp/v2/block-renderer/${block}`, { |
192 return (0,external_wp_url_namespaceObject.addQueryArgs)(`/wp/v2/block-renderer/${block}`, { |
106 context: 'edit', |
193 context: 'edit', |
107 ...(null !== attributes ? { |
194 ...(null !== attributes ? { |
108 attributes |
195 attributes |
109 } : {}), |
196 } : {}), |
110 ...urlQueryArgs |
197 ...urlQueryArgs |
111 }); |
198 }); |
112 } |
199 } |
113 |
200 function removeBlockSupportAttributes(attributes) { |
114 function DefaultEmptyResponsePlaceholder(_ref) { |
201 const { |
115 let { |
202 backgroundColor, |
116 className |
203 borderColor, |
117 } = _ref; |
204 fontFamily, |
118 return (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Placeholder, { |
205 fontSize, |
119 className: className |
206 gradient, |
120 }, (0,external_wp_i18n_namespaceObject.__)('Block rendered as empty.')); |
207 textColor, |
121 } |
208 className, |
122 |
209 ...restAttributes |
123 function DefaultErrorResponsePlaceholder(_ref2) { |
210 } = attributes; |
124 let { |
211 const { |
125 response, |
212 border, |
126 className |
213 color, |
127 } = _ref2; |
214 elements, |
128 const errorMessage = (0,external_wp_i18n_namespaceObject.sprintf)( // translators: %s: error message describing the problem |
215 spacing, |
|
216 typography, |
|
217 ...restStyles |
|
218 } = attributes?.style || EMPTY_OBJECT; |
|
219 return { |
|
220 ...restAttributes, |
|
221 style: restStyles |
|
222 }; |
|
223 } |
|
224 function DefaultEmptyResponsePlaceholder({ |
|
225 className |
|
226 }) { |
|
227 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Placeholder, { |
|
228 className: className, |
|
229 children: (0,external_wp_i18n_namespaceObject.__)('Block rendered as empty.') |
|
230 }); |
|
231 } |
|
232 function DefaultErrorResponsePlaceholder({ |
|
233 response, |
|
234 className |
|
235 }) { |
|
236 const errorMessage = (0,external_wp_i18n_namespaceObject.sprintf)( |
|
237 // translators: %s: error message describing the problem |
129 (0,external_wp_i18n_namespaceObject.__)('Error loading block: %s'), response.errorMsg); |
238 (0,external_wp_i18n_namespaceObject.__)('Error loading block: %s'), response.errorMsg); |
130 return (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Placeholder, { |
239 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Placeholder, { |
131 className: className |
240 className: className, |
132 }, errorMessage); |
241 children: errorMessage |
133 } |
242 }); |
134 |
243 } |
135 function DefaultLoadingResponsePlaceholder(_ref3) { |
244 function DefaultLoadingResponsePlaceholder({ |
136 let { |
245 children, |
137 children, |
246 showLoader |
138 showLoader |
247 }) { |
139 } = _ref3; |
248 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)("div", { |
140 return (0,external_wp_element_namespaceObject.createElement)("div", { |
|
141 style: { |
249 style: { |
142 position: 'relative' |
250 position: 'relative' |
143 } |
251 }, |
144 }, showLoader && (0,external_wp_element_namespaceObject.createElement)("div", { |
252 children: [showLoader && /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("div", { |
145 style: { |
253 style: { |
146 position: 'absolute', |
254 position: 'absolute', |
147 top: '50%', |
255 top: '50%', |
148 left: '50%', |
256 left: '50%', |
149 marginTop: '-9px', |
257 marginTop: '-9px', |
150 marginLeft: '-9px' |
258 marginLeft: '-9px' |
151 } |
259 }, |
152 }, (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Spinner, null)), (0,external_wp_element_namespaceObject.createElement)("div", { |
260 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Spinner, {}) |
153 style: { |
261 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("div", { |
154 opacity: showLoader ? '0.3' : 1 |
262 style: { |
155 } |
263 opacity: showLoader ? '0.3' : 1 |
156 }, children)); |
264 }, |
157 } |
265 children: children |
158 |
266 })] |
|
267 }); |
|
268 } |
159 function ServerSideRender(props) { |
269 function ServerSideRender(props) { |
160 const { |
270 const { |
161 attributes, |
271 attributes, |
162 block, |
272 block, |
163 className, |
273 className, |
164 httpMethod = 'GET', |
274 httpMethod = 'GET', |
165 urlQueryArgs, |
275 urlQueryArgs, |
|
276 skipBlockSupportAttributes = false, |
166 EmptyResponsePlaceholder = DefaultEmptyResponsePlaceholder, |
277 EmptyResponsePlaceholder = DefaultEmptyResponsePlaceholder, |
167 ErrorResponsePlaceholder = DefaultErrorResponsePlaceholder, |
278 ErrorResponsePlaceholder = DefaultErrorResponsePlaceholder, |
168 LoadingResponsePlaceholder = DefaultLoadingResponsePlaceholder |
279 LoadingResponsePlaceholder = DefaultLoadingResponsePlaceholder |
169 } = props; |
280 } = props; |
170 const isMountedRef = (0,external_wp_element_namespaceObject.useRef)(true); |
281 const isMountedRef = (0,external_wp_element_namespaceObject.useRef)(false); |
171 const [showLoader, setShowLoader] = (0,external_wp_element_namespaceObject.useState)(false); |
282 const [showLoader, setShowLoader] = (0,external_wp_element_namespaceObject.useState)(false); |
172 const fetchRequestRef = (0,external_wp_element_namespaceObject.useRef)(); |
283 const fetchRequestRef = (0,external_wp_element_namespaceObject.useRef)(); |
173 const [response, setResponse] = (0,external_wp_element_namespaceObject.useState)(null); |
284 const [response, setResponse] = (0,external_wp_element_namespaceObject.useState)(null); |
174 const prevProps = (0,external_wp_compose_namespaceObject.usePrevious)(props); |
285 const prevProps = (0,external_wp_compose_namespaceObject.usePrevious)(props); |
175 const [isLoading, setIsLoading] = (0,external_wp_element_namespaceObject.useState)(false); |
286 const [isLoading, setIsLoading] = (0,external_wp_element_namespaceObject.useState)(false); |
176 |
|
177 function fetchData() { |
287 function fetchData() { |
|
288 var _sanitizedAttributes, _sanitizedAttributes2; |
178 if (!isMountedRef.current) { |
289 if (!isMountedRef.current) { |
179 return; |
290 return; |
180 } |
291 } |
181 |
|
182 setIsLoading(true); |
292 setIsLoading(true); |
183 |
293 |
184 const sanitizedAttributes = attributes && (0,external_wp_blocks_namespaceObject.__experimentalSanitizeBlockAttributes)(block, attributes); // If httpMethod is 'POST', send the attributes in the request body instead of the URL. |
294 // Schedule showing the Spinner after 1 second. |
|
295 const timeout = setTimeout(() => { |
|
296 setShowLoader(true); |
|
297 }, 1000); |
|
298 let sanitizedAttributes = attributes && (0,external_wp_blocks_namespaceObject.__experimentalSanitizeBlockAttributes)(block, attributes); |
|
299 if (skipBlockSupportAttributes) { |
|
300 sanitizedAttributes = removeBlockSupportAttributes(sanitizedAttributes); |
|
301 } |
|
302 |
|
303 // If httpMethod is 'POST', send the attributes in the request body instead of the URL. |
185 // This allows sending a larger attributes object than in a GET request, where the attributes are in the URL. |
304 // This allows sending a larger attributes object than in a GET request, where the attributes are in the URL. |
186 |
|
187 |
|
188 const isPostRequest = 'POST' === httpMethod; |
305 const isPostRequest = 'POST' === httpMethod; |
189 const urlAttributes = isPostRequest ? null : sanitizedAttributes !== null && sanitizedAttributes !== void 0 ? sanitizedAttributes : null; |
306 const urlAttributes = isPostRequest ? null : (_sanitizedAttributes = sanitizedAttributes) !== null && _sanitizedAttributes !== void 0 ? _sanitizedAttributes : null; |
190 const path = rendererPath(block, urlAttributes, urlQueryArgs); |
307 const path = rendererPath(block, urlAttributes, urlQueryArgs); |
191 const data = isPostRequest ? { |
308 const data = isPostRequest ? { |
192 attributes: sanitizedAttributes !== null && sanitizedAttributes !== void 0 ? sanitizedAttributes : null |
309 attributes: (_sanitizedAttributes2 = sanitizedAttributes) !== null && _sanitizedAttributes2 !== void 0 ? _sanitizedAttributes2 : null |
193 } : null; // Store the latest fetch request so that when we process it, we can |
310 } : null; |
|
311 |
|
312 // Store the latest fetch request so that when we process it, we can |
194 // check if it is the current request, to avoid race conditions on slow networks. |
313 // check if it is the current request, to avoid race conditions on slow networks. |
195 |
|
196 const fetchRequest = fetchRequestRef.current = external_wp_apiFetch_default()({ |
314 const fetchRequest = fetchRequestRef.current = external_wp_apiFetch_default()({ |
197 path, |
315 path, |
198 data, |
316 data, |
199 method: isPostRequest ? 'POST' : 'GET' |
317 method: isPostRequest ? 'POST' : 'GET' |
200 }).then(fetchResponse => { |
318 }).then(fetchResponse => { |
209 }); |
327 }); |
210 } |
328 } |
211 }).finally(() => { |
329 }).finally(() => { |
212 if (isMountedRef.current && fetchRequest === fetchRequestRef.current) { |
330 if (isMountedRef.current && fetchRequest === fetchRequestRef.current) { |
213 setIsLoading(false); |
331 setIsLoading(false); |
|
332 // Cancel the timeout to show the Spinner. |
|
333 setShowLoader(false); |
|
334 clearTimeout(timeout); |
214 } |
335 } |
215 }); |
336 }); |
216 return fetchRequest; |
337 return fetchRequest; |
217 } |
338 } |
218 |
339 const debouncedFetchData = (0,external_wp_compose_namespaceObject.useDebounce)(fetchData, 500); |
219 const debouncedFetchData = (0,external_wp_compose_namespaceObject.useDebounce)(fetchData, 500); // When the component unmounts, set isMountedRef to false. This will |
340 |
|
341 // When the component unmounts, set isMountedRef to false. This will |
220 // let the async fetch callbacks know when to stop. |
342 // let the async fetch callbacks know when to stop. |
221 |
343 (0,external_wp_element_namespaceObject.useEffect)(() => { |
222 (0,external_wp_element_namespaceObject.useEffect)(() => () => { |
344 isMountedRef.current = true; |
223 isMountedRef.current = false; |
345 return () => { |
|
346 isMountedRef.current = false; |
|
347 }; |
224 }, []); |
348 }, []); |
225 (0,external_wp_element_namespaceObject.useEffect)(() => { |
349 (0,external_wp_element_namespaceObject.useEffect)(() => { |
226 // Don't debounce the first fetch. This ensures that the first render |
350 // Don't debounce the first fetch. This ensures that the first render |
227 // shows data as soon as possible. |
351 // shows data as soon as possible. |
228 if (prevProps === undefined) { |
352 if (prevProps === undefined) { |
229 fetchData(); |
353 fetchData(); |
230 } else if (!(0,external_lodash_namespaceObject.isEqual)(prevProps, props)) { |
354 } else if (!es6_default()(prevProps, props)) { |
231 debouncedFetchData(); |
355 debouncedFetchData(); |
232 } |
356 } |
233 }); |
357 }); |
234 /** |
|
235 * Effect to handle showing the loading placeholder. |
|
236 * Show it only if there is no previous response or |
|
237 * the request takes more than one second. |
|
238 */ |
|
239 |
|
240 (0,external_wp_element_namespaceObject.useEffect)(() => { |
|
241 if (!isLoading) { |
|
242 return; |
|
243 } |
|
244 |
|
245 const timeout = setTimeout(() => { |
|
246 setShowLoader(true); |
|
247 }, 1000); |
|
248 return () => clearTimeout(timeout); |
|
249 }, [isLoading]); |
|
250 const hasResponse = !!response; |
358 const hasResponse = !!response; |
251 const hasEmptyResponse = response === ''; |
359 const hasEmptyResponse = response === ''; |
252 const hasError = response === null || response === void 0 ? void 0 : response.error; |
360 const hasError = response?.error; |
253 |
|
254 if (isLoading) { |
361 if (isLoading) { |
255 return (0,external_wp_element_namespaceObject.createElement)(LoadingResponsePlaceholder, _extends({}, props, { |
362 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(LoadingResponsePlaceholder, { |
256 showLoader: showLoader |
363 ...props, |
257 }), hasResponse && (0,external_wp_element_namespaceObject.createElement)(external_wp_element_namespaceObject.RawHTML, { |
364 showLoader: showLoader, |
258 className: className |
365 children: hasResponse && /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_element_namespaceObject.RawHTML, { |
259 }, response)); |
366 className: className, |
260 } |
367 children: response |
261 |
368 }) |
|
369 }); |
|
370 } |
262 if (hasEmptyResponse || !hasResponse) { |
371 if (hasEmptyResponse || !hasResponse) { |
263 return (0,external_wp_element_namespaceObject.createElement)(EmptyResponsePlaceholder, props); |
372 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(EmptyResponsePlaceholder, { |
264 } |
373 ...props |
265 |
374 }); |
|
375 } |
266 if (hasError) { |
376 if (hasError) { |
267 return (0,external_wp_element_namespaceObject.createElement)(ErrorResponsePlaceholder, _extends({ |
377 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(ErrorResponsePlaceholder, { |
268 response: response |
378 response: response, |
269 }, props)); |
379 ...props |
270 } |
380 }); |
271 |
381 } |
272 return (0,external_wp_element_namespaceObject.createElement)(external_wp_element_namespaceObject.RawHTML, { |
382 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_element_namespaceObject.RawHTML, { |
273 className: className |
383 className: className, |
274 }, response); |
384 children: response |
|
385 }); |
275 } |
386 } |
276 |
387 |
277 ;// CONCATENATED MODULE: ./node_modules/@wordpress/server-side-render/build-module/index.js |
388 ;// CONCATENATED MODULE: ./node_modules/@wordpress/server-side-render/build-module/index.js |
278 |
|
279 |
|
280 |
|
281 /** |
389 /** |
282 * WordPress dependencies |
390 * WordPress dependencies |
283 */ |
391 */ |
284 |
392 |
285 |
393 |
291 |
399 |
292 /** |
400 /** |
293 * Constants |
401 * Constants |
294 */ |
402 */ |
295 |
403 |
296 const EMPTY_OBJECT = {}; |
404 const build_module_EMPTY_OBJECT = {}; |
297 const ExportedServerSideRender = (0,external_wp_data_namespaceObject.withSelect)(select => { |
405 const ExportedServerSideRender = (0,external_wp_data_namespaceObject.withSelect)(select => { |
298 // FIXME: @wordpress/server-side-render should not depend on @wordpress/editor. |
406 // FIXME: @wordpress/server-side-render should not depend on @wordpress/editor. |
299 // It is used by blocks that can be loaded into a *non-post* block editor. |
407 // It is used by blocks that can be loaded into a *non-post* block editor. |
300 // eslint-disable-next-line @wordpress/data-no-store-string-literals |
408 // eslint-disable-next-line @wordpress/data-no-store-string-literals |
301 const coreEditorSelect = select('core/editor'); |
409 const coreEditorSelect = select('core/editor'); |
302 |
|
303 if (coreEditorSelect) { |
410 if (coreEditorSelect) { |
304 const currentPostId = coreEditorSelect.getCurrentPostId(); // For templates and template parts we use a custom ID format. |
411 const currentPostId = coreEditorSelect.getCurrentPostId(); |
|
412 // For templates and template parts we use a custom ID format. |
305 // Since they aren't real posts, we don't want to use their ID |
413 // Since they aren't real posts, we don't want to use their ID |
306 // for server-side rendering. Since they use a string based ID, |
414 // for server-side rendering. Since they use a string based ID, |
307 // we can assume real post IDs are numbers. |
415 // we can assume real post IDs are numbers. |
308 |
|
309 if (currentPostId && typeof currentPostId === 'number') { |
416 if (currentPostId && typeof currentPostId === 'number') { |
310 return { |
417 return { |
311 currentPostId |
418 currentPostId |
312 }; |
419 }; |
313 } |
420 } |
314 } |
421 } |
315 |
422 return build_module_EMPTY_OBJECT; |
316 return EMPTY_OBJECT; |
423 })(({ |
317 })(_ref => { |
424 urlQueryArgs = build_module_EMPTY_OBJECT, |
318 let { |
425 currentPostId, |
319 urlQueryArgs = EMPTY_OBJECT, |
426 ...props |
320 currentPostId, |
427 }) => { |
321 ...props |
|
322 } = _ref; |
|
323 const newUrlQueryArgs = (0,external_wp_element_namespaceObject.useMemo)(() => { |
428 const newUrlQueryArgs = (0,external_wp_element_namespaceObject.useMemo)(() => { |
324 if (!currentPostId) { |
429 if (!currentPostId) { |
325 return urlQueryArgs; |
430 return urlQueryArgs; |
326 } |
431 } |
327 |
|
328 return { |
432 return { |
329 post_id: currentPostId, |
433 post_id: currentPostId, |
330 ...urlQueryArgs |
434 ...urlQueryArgs |
331 }; |
435 }; |
332 }, [currentPostId, urlQueryArgs]); |
436 }, [currentPostId, urlQueryArgs]); |
333 return (0,external_wp_element_namespaceObject.createElement)(ServerSideRender, _extends({ |
437 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(ServerSideRender, { |
334 urlQueryArgs: newUrlQueryArgs |
438 urlQueryArgs: newUrlQueryArgs, |
335 }, props)); |
439 ...props |
|
440 }); |
336 }); |
441 }); |
337 |
442 /* harmony default export */ const build_module = (ExportedServerSideRender); |
338 if (window && window.wp && window.wp.components) { |
443 |
339 window.wp.components.ServerSideRender = (0,external_wp_element_namespaceObject.forwardRef)((props, ref) => { |
444 })(); |
340 external_wp_deprecated_default()('wp.components.ServerSideRender', { |
|
341 version: '6.2', |
|
342 since: '5.3', |
|
343 alternative: 'wp.serverSideRender' |
|
344 }); |
|
345 return (0,external_wp_element_namespaceObject.createElement)(ExportedServerSideRender, _extends({}, props, { |
|
346 ref: ref |
|
347 })); |
|
348 }); |
|
349 } |
|
350 |
|
351 /* harmony default export */ var build_module = (ExportedServerSideRender); |
|
352 |
445 |
353 (window.wp = window.wp || {}).serverSideRender = __webpack_exports__["default"]; |
446 (window.wp = window.wp || {}).serverSideRender = __webpack_exports__["default"]; |
354 /******/ })() |
447 /******/ })() |
355 ; |
448 ; |