You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

439 lines
14 KiB

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