2022-04-11 08:04:30 -04:00
/******/ ( function ( ) { // webpackBootstrap
/******/ "use strict" ;
/******/ // The require scope
/******/ var _ _webpack _require _ _ = { } ;
/******/
/************************************************************************/
/******/ /* webpack/runtime/compat get default export */
/******/ ! function ( ) {
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ _ _webpack _require _ _ . n = function ( module ) {
/******/ var getter = module && module . _ _esModule ?
/******/ function ( ) { return module [ 'default' ] ; } :
/******/ function ( ) { return module ; } ;
/******/ _ _webpack _require _ _ . d ( getter , { a : getter } ) ;
/******/ return getter ;
/******/ } ;
/******/ } ( ) ;
/******/
/******/ /* webpack/runtime/define property getters */
/******/ ! function ( ) {
/******/ // define getter functions for harmony exports
/******/ _ _webpack _require _ _ . d = function ( exports , definition ) {
/******/ for ( var key in definition ) {
/******/ if ( _ _webpack _require _ _ . o ( definition , key ) && ! _ _webpack _require _ _ . o ( exports , key ) ) {
/******/ Object . defineProperty ( exports , key , { enumerable : true , get : definition [ key ] } ) ;
/******/ }
/******/ }
2019-09-19 11:19:18 -04:00
/******/ } ;
2022-04-11 08:04:30 -04:00
/******/ } ( ) ;
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ ! function ( ) {
/******/ _ _webpack _require _ _ . o = function ( obj , prop ) { return Object . prototype . hasOwnProperty . call ( obj , prop ) ; }
/******/ } ( ) ;
/******/
2019-09-19 11:19:18 -04:00
/************************************************************************/
2022-04-11 08:04:30 -04:00
var _ _webpack _exports _ _ = { } ;
2019-09-19 11:19:18 -04:00
2022-04-11 08:04:30 -04:00
// EXPORTS
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , {
"default" : function ( ) { return /* binding */ build _module ; }
} ) ;
2019-09-19 11:19:18 -04:00
2022-04-11 08:04:30 -04:00
; // CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/extends.js
function _extends ( ) {
2022-09-20 11:43:29 -04:00
_extends = Object . assign ? Object . assign . bind ( ) : function ( target ) {
2022-04-11 08:04:30 -04:00
for ( var i = 1 ; i < arguments . length ; i ++ ) {
var source = arguments [ i ] ;
2019-09-19 11:19:18 -04:00
2022-04-11 08:04:30 -04:00
for ( var key in source ) {
if ( Object . prototype . hasOwnProperty . call ( source , key ) ) {
target [ key ] = source [ key ] ;
}
}
}
2019-09-19 11:19:18 -04:00
2022-04-11 08:04:30 -04:00
return target ;
} ;
return _extends . apply ( this , arguments ) ;
}
; // CONCATENATED MODULE: external ["wp","element"]
var external _wp _element _namespaceObject = window [ "wp" ] [ "element" ] ;
; // CONCATENATED MODULE: external ["wp","data"]
var external _wp _data _namespaceObject = window [ "wp" ] [ "data" ] ;
; // CONCATENATED MODULE: external ["wp","deprecated"]
var external _wp _deprecated _namespaceObject = window [ "wp" ] [ "deprecated" ] ;
var external _wp _deprecated _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( external _wp _deprecated _namespaceObject ) ;
; // CONCATENATED MODULE: external "lodash"
var external _lodash _namespaceObject = window [ "lodash" ] ;
; // CONCATENATED MODULE: external ["wp","compose"]
var external _wp _compose _namespaceObject = window [ "wp" ] [ "compose" ] ;
; // CONCATENATED MODULE: external ["wp","i18n"]
var external _wp _i18n _namespaceObject = window [ "wp" ] [ "i18n" ] ;
; // CONCATENATED MODULE: external ["wp","apiFetch"]
var external _wp _apiFetch _namespaceObject = window [ "wp" ] [ "apiFetch" ] ;
var external _wp _apiFetch _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( external _wp _apiFetch _namespaceObject ) ;
; // CONCATENATED MODULE: external ["wp","url"]
var external _wp _url _namespaceObject = window [ "wp" ] [ "url" ] ;
; // CONCATENATED MODULE: external ["wp","components"]
var external _wp _components _namespaceObject = window [ "wp" ] [ "components" ] ;
; // CONCATENATED MODULE: external ["wp","blocks"]
var external _wp _blocks _namespaceObject = window [ "wp" ] [ "blocks" ] ;
; // CONCATENATED MODULE: ./node_modules/@wordpress/server-side-render/build-module/server-side-render.js
2019-09-19 11:19:18 -04:00
/ * *
* External dependencies
* /
/ * *
* WordPress dependencies
* /
2021-04-15 11:19:43 -04:00
2021-11-15 07:50:17 -05:00
function rendererPath ( block ) {
let attributes = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : null ;
let urlQueryArgs = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : { } ;
2022-04-11 08:04:30 -04:00
return ( 0 , external _wp _url _namespaceObject . addQueryArgs ) ( ` /wp/v2/block-renderer/ ${ block } ` , {
2021-05-19 11:09:27 -04:00
context : 'edit' ,
... ( null !== attributes ? {
attributes
} : { } ) ,
... urlQueryArgs
} ) ;
2019-09-19 11:19:18 -04:00
}
2020-06-26 09:33:47 -04:00
2021-11-15 07:50:17 -05:00
function DefaultEmptyResponsePlaceholder ( _ref ) {
let {
className
} = _ref ;
2022-04-11 08:04:30 -04:00
return ( 0 , external _wp _element _namespaceObject . createElement ) ( external _wp _components _namespaceObject . Placeholder , {
2021-04-15 11:19:43 -04:00
className : className
2022-04-11 08:04:30 -04:00
} , ( 0 , external _wp _i18n _namespaceObject . _ _ ) ( 'Block rendered as empty.' ) ) ;
2021-04-15 11:19:43 -04:00
}
2019-09-19 11:19:18 -04:00
2021-11-15 07:50:17 -05:00
function DefaultErrorResponsePlaceholder ( _ref2 ) {
let {
response ,
className
} = _ref2 ;
2022-04-11 08:04:30 -04:00
const errorMessage = ( 0 , external _wp _i18n _namespaceObject . sprintf ) ( // translators: %s: error message describing the problem
( 0 , external _wp _i18n _namespaceObject . _ _ ) ( 'Error loading block: %s' ) , response . errorMsg ) ;
return ( 0 , external _wp _element _namespaceObject . createElement ) ( external _wp _components _namespaceObject . Placeholder , {
2021-04-15 11:19:43 -04:00
className : className
} , errorMessage ) ;
}
2019-09-19 11:19:18 -04:00
2021-11-15 07:50:17 -05:00
function DefaultLoadingResponsePlaceholder ( _ref3 ) {
let {
children ,
showLoader
} = _ref3 ;
2022-04-11 08:04:30 -04:00
return ( 0 , external _wp _element _namespaceObject . createElement ) ( "div" , {
2021-11-08 09:29:21 -05:00
style : {
position : 'relative'
}
2022-04-11 08:04:30 -04:00
} , showLoader && ( 0 , external _wp _element _namespaceObject . createElement ) ( "div" , {
2021-11-08 09:29:21 -05:00
style : {
position : 'absolute' ,
top : '50%' ,
left : '50%' ,
marginTop : '-9px' ,
marginLeft : '-9px'
}
2022-04-11 08:04:30 -04:00
} , ( 0 , external _wp _element _namespaceObject . createElement ) ( external _wp _components _namespaceObject . Spinner , null ) ) , ( 0 , external _wp _element _namespaceObject . createElement ) ( "div" , {
2021-11-08 09:29:21 -05:00
style : {
opacity : showLoader ? '0.3' : 1
}
} , children ) ) ;
2021-04-15 11:19:43 -04:00
}
2019-09-19 11:19:18 -04:00
2021-04-15 11:19:43 -04:00
function ServerSideRender ( props ) {
2021-05-19 11:09:27 -04:00
const {
attributes ,
block ,
className ,
httpMethod = 'GET' ,
urlQueryArgs ,
EmptyResponsePlaceholder = DefaultEmptyResponsePlaceholder ,
ErrorResponsePlaceholder = DefaultErrorResponsePlaceholder ,
LoadingResponsePlaceholder = DefaultLoadingResponsePlaceholder
} = props ;
2022-04-11 08:04:30 -04:00
const isMountedRef = ( 0 , external _wp _element _namespaceObject . useRef ) ( true ) ;
const [ showLoader , setShowLoader ] = ( 0 , external _wp _element _namespaceObject . useState ) ( false ) ;
const fetchRequestRef = ( 0 , external _wp _element _namespaceObject . useRef ) ( ) ;
const [ response , setResponse ] = ( 0 , external _wp _element _namespaceObject . useState ) ( null ) ;
const prevProps = ( 0 , external _wp _compose _namespaceObject . usePrevious ) ( props ) ;
const [ isLoading , setIsLoading ] = ( 0 , external _wp _element _namespaceObject . useState ) ( false ) ;
2021-04-15 11:19:43 -04:00
function fetchData ( ) {
if ( ! isMountedRef . current ) {
return ;
2019-09-19 11:19:18 -04:00
}
2021-04-15 11:19:43 -04:00
2021-11-08 09:29:21 -05:00
setIsLoading ( true ) ;
2019-09-19 11:19:18 -04:00
2022-04-11 08:04:30 -04:00
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.
2021-04-15 11:19:43 -04:00
// This allows sending a larger attributes object than in a GET request, where the attributes are in the URL.
2021-05-19 11:09:27 -04:00
const isPostRequest = 'POST' === httpMethod ;
const urlAttributes = isPostRequest ? null : sanitizedAttributes !== null && sanitizedAttributes !== void 0 ? sanitizedAttributes : null ;
const path = rendererPath ( block , urlAttributes , urlQueryArgs ) ;
const data = isPostRequest ? {
2021-04-15 11:19:43 -04:00
attributes : sanitizedAttributes !== null && sanitizedAttributes !== void 0 ? sanitizedAttributes : null
} : null ; // Store the latest fetch request so that when we process it, we can
// check if it is the current request, to avoid race conditions on slow networks.
2021-05-19 11:09:27 -04:00
const fetchRequest = fetchRequestRef . current = external _wp _apiFetch _default ( ) ( {
path ,
data ,
2021-04-15 11:19:43 -04:00
method : isPostRequest ? 'POST' : 'GET'
2021-05-19 11:09:27 -04:00
} ) . then ( fetchResponse => {
2021-04-15 11:19:43 -04:00
if ( isMountedRef . current && fetchRequest === fetchRequestRef . current && fetchResponse ) {
setResponse ( fetchResponse . rendered ) ;
2019-09-19 11:19:18 -04:00
}
2021-05-19 11:09:27 -04:00
} ) . catch ( error => {
2021-04-15 11:19:43 -04:00
if ( isMountedRef . current && fetchRequest === fetchRequestRef . current ) {
setResponse ( {
error : true ,
errorMsg : error . message
2019-09-19 11:19:18 -04:00
} ) ;
}
2021-11-08 09:29:21 -05:00
} ) . finally ( ( ) => {
if ( isMountedRef . current && fetchRequest === fetchRequestRef . current ) {
setIsLoading ( false ) ;
}
2021-04-15 11:19:43 -04:00
} ) ;
return fetchRequest ;
}
2019-09-19 11:19:18 -04:00
2022-04-11 08:04:30 -04:00
const debouncedFetchData = ( 0 , external _wp _compose _namespaceObject . useDebounce ) ( fetchData , 500 ) ; // When the component unmounts, set isMountedRef to false. This will
2021-04-15 11:19:43 -04:00
// let the async fetch callbacks know when to stop.
2019-09-19 11:19:18 -04:00
2022-04-11 08:04:30 -04:00
( 0 , external _wp _element _namespaceObject . useEffect ) ( ( ) => ( ) => {
2021-05-19 11:09:27 -04:00
isMountedRef . current = false ;
2021-04-15 11:19:43 -04:00
} , [ ] ) ;
2022-04-11 08:04:30 -04:00
( 0 , external _wp _element _namespaceObject . useEffect ) ( ( ) => {
2021-04-15 11:19:43 -04:00
// Don't debounce the first fetch. This ensures that the first render
2022-04-12 11:12:47 -04:00
// shows data as soon as possible.
2021-04-15 11:19:43 -04:00
if ( prevProps === undefined ) {
fetchData ( ) ;
2022-04-11 08:04:30 -04:00
} else if ( ! ( 0 , external _lodash _namespaceObject . isEqual ) ( prevProps , props ) ) {
2021-04-15 11:19:43 -04:00
debouncedFetchData ( ) ;
2019-09-19 11:19:18 -04:00
}
2021-04-15 11:19:43 -04:00
} ) ;
2021-11-08 09:29:21 -05:00
/ * *
* Effect to handle showing the loading placeholder .
* Show it only if there is no previous response or
* the request takes more than one second .
* /
2021-04-15 11:19:43 -04:00
2022-04-11 08:04:30 -04:00
( 0 , external _wp _element _namespaceObject . useEffect ) ( ( ) => {
2021-11-08 09:29:21 -05:00
if ( ! isLoading ) {
return ;
}
const timeout = setTimeout ( ( ) => {
setShowLoader ( true ) ;
} , 1000 ) ;
return ( ) => clearTimeout ( timeout ) ;
} , [ isLoading ] ) ;
const hasResponse = ! ! response ;
const hasEmptyResponse = response === '' ;
const hasError = response === null || response === void 0 ? void 0 : response . error ;
2022-01-04 00:39:28 -05:00
if ( isLoading ) {
2022-04-11 08:04:30 -04:00
return ( 0 , external _wp _element _namespaceObject . createElement ) ( LoadingResponsePlaceholder , _extends ( { } , props , {
2022-01-04 00:39:28 -05:00
showLoader : showLoader
2022-04-11 08:04:30 -04:00
} ) , hasResponse && ( 0 , external _wp _element _namespaceObject . createElement ) ( external _wp _element _namespaceObject . RawHTML , {
2022-01-04 00:39:28 -05:00
className : className
} , response ) ) ;
}
2021-11-08 09:29:21 -05:00
if ( hasEmptyResponse || ! hasResponse ) {
2022-04-11 08:04:30 -04:00
return ( 0 , external _wp _element _namespaceObject . createElement ) ( EmptyResponsePlaceholder , props ) ;
2021-11-08 09:29:21 -05:00
}
if ( hasError ) {
2022-04-11 08:04:30 -04:00
return ( 0 , external _wp _element _namespaceObject . createElement ) ( ErrorResponsePlaceholder , _extends ( {
2021-04-15 11:19:43 -04:00
response : response
} , props ) ) ;
2019-09-19 11:19:18 -04:00
}
2021-04-15 11:19:43 -04:00
2022-04-11 08:04:30 -04:00
return ( 0 , external _wp _element _namespaceObject . createElement ) ( external _wp _element _namespaceObject . RawHTML , {
2021-04-15 11:19:43 -04:00
className : className
} , response ) ;
}
2019-09-19 11:19:18 -04:00
2022-04-11 08:04:30 -04:00
; // CONCATENATED MODULE: ./node_modules/@wordpress/server-side-render/build-module/index.js
2019-09-19 11:19:18 -04:00
/ * *
* WordPress dependencies
* /
/ * *
* Internal dependencies
* /
/ * *
* Constants
* /
2021-05-19 11:09:27 -04:00
const EMPTY _OBJECT = { } ;
2022-04-11 08:04:30 -04:00
const ExportedServerSideRender = ( 0 , external _wp _data _namespaceObject . withSelect ) ( select => {
2021-11-08 09:29:21 -05:00
// FIXME: @wordpress/server-side-render should not depend on @wordpress/editor.
// It is used by blocks that can be loaded into a *non-post* block editor.
// eslint-disable-next-line @wordpress/data-no-store-string-literals
2021-05-19 11:09:27 -04:00
const coreEditorSelect = select ( 'core/editor' ) ;
2019-09-19 11:19:18 -04:00
if ( coreEditorSelect ) {
2021-05-19 11:09:27 -04:00
const currentPostId = coreEditorSelect . getCurrentPostId ( ) ; // For templates and template parts we use a custom ID format.
2021-04-15 11:19:43 -04:00
// Since they aren't real posts, we don't want to use their ID
// for server-side rendering. Since they use a string based ID,
// we can assume real post IDs are numbers.
2019-09-19 11:19:18 -04:00
2021-05-21 06:14:23 -04:00
if ( currentPostId && typeof currentPostId === 'number' ) {
2019-09-19 11:19:18 -04:00
return {
2021-05-19 11:09:27 -04:00
currentPostId
2019-09-19 11:19:18 -04:00
} ;
}
}
return EMPTY _OBJECT ;
2021-11-15 07:50:17 -05:00
} ) ( _ref => {
let {
urlQueryArgs = EMPTY _OBJECT ,
currentPostId ,
... props
} = _ref ;
2022-04-11 08:04:30 -04:00
const newUrlQueryArgs = ( 0 , external _wp _element _namespaceObject . useMemo ) ( ( ) => {
2019-09-19 11:19:18 -04:00
if ( ! currentPostId ) {
return urlQueryArgs ;
}
2021-05-19 11:09:27 -04:00
return {
post _id : currentPostId ,
... urlQueryArgs
} ;
2019-09-19 11:19:18 -04:00
} , [ currentPostId , urlQueryArgs ] ) ;
2022-04-11 08:04:30 -04:00
return ( 0 , external _wp _element _namespaceObject . createElement ) ( ServerSideRender , _extends ( {
2019-09-19 11:19:18 -04:00
urlQueryArgs : newUrlQueryArgs
} , props ) ) ;
} ) ;
if ( window && window . wp && window . wp . components ) {
2022-04-11 08:04:30 -04:00
window . wp . components . ServerSideRender = ( 0 , external _wp _element _namespaceObject . forwardRef ) ( ( props , ref ) => {
2021-01-27 21:04:13 -05:00
external _wp _deprecated _default ( ) ( 'wp.components.ServerSideRender' , {
2022-04-12 11:12:47 -04:00
version : '6.2' ,
2021-04-15 11:19:43 -04:00
since : '5.3' ,
2019-09-19 11:19:18 -04:00
alternative : 'wp.serverSideRender'
} ) ;
2022-04-11 08:04:30 -04:00
return ( 0 , external _wp _element _namespaceObject . createElement ) ( ExportedServerSideRender , _extends ( { } , props , {
2019-09-19 11:19:18 -04:00
ref : ref
} ) ) ;
} ) ;
}
2022-04-11 08:04:30 -04:00
/* harmony default export */ var build _module = ( ExportedServerSideRender ) ;
2019-09-19 11:19:18 -04:00
2022-04-11 08:04:30 -04:00
( window . wp = window . wp || { } ) . serverSideRender = _ _webpack _exports _ _ [ "default" ] ;
/******/ } ) ( )
;