@wordpress/server-side-render 3.0.5 → 3.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/index.js CHANGED
@@ -49,11 +49,12 @@ const ExportedServerSideRender = (0, _data.withSelect)(select => {
49
49
  }
50
50
 
51
51
  return EMPTY_OBJECT;
52
- })(({
53
- urlQueryArgs = EMPTY_OBJECT,
54
- currentPostId,
55
- ...props
56
- }) => {
52
+ })(_ref => {
53
+ let {
54
+ urlQueryArgs = EMPTY_OBJECT,
55
+ currentPostId,
56
+ ...props
57
+ } = _ref;
57
58
  const newUrlQueryArgs = (0, _element.useMemo)(() => {
58
59
  if (!currentPostId) {
59
60
  return urlQueryArgs;
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/server-side-render/src/index.js"],"names":["EMPTY_OBJECT","ExportedServerSideRender","select","coreEditorSelect","currentPostId","getCurrentPostId","urlQueryArgs","props","newUrlQueryArgs","post_id","window","wp","components","ServerSideRender","ref","since","alternative"],"mappings":";;;;;;;;;AAGA;;;;AACA;;AACA;;AAKA;;AAVA;AACA;AACA;;AAKA;AACA;AACA;;AAGA;AACA;AACA;AACA,MAAMA,YAAY,GAAG,EAArB;AAEA,MAAMC,wBAAwB,GAAG,sBAAcC,MAAF,IAAc;AAC1D;AACA;AACA;AACA,QAAMC,gBAAgB,GAAGD,MAAM,CAAE,aAAF,CAA/B;;AACA,MAAKC,gBAAL,EAAwB;AACvB,UAAMC,aAAa,GAAGD,gBAAgB,CAACE,gBAAjB,EAAtB,CADuB,CAEvB;AACA;AACA;AACA;;AACA,QAAKD,aAAa,IAAI,OAAOA,aAAP,KAAyB,QAA/C,EAA0D;AACzD,aAAO;AACNA,QAAAA;AADM,OAAP;AAGA;AACD;;AACD,SAAOJ,YAAP;AACA,CAlBgC,EAkB5B,CAAE;AAAEM,EAAAA,YAAY,GAAGN,YAAjB;AAA+BI,EAAAA,aAA/B;AAA8C,KAAGG;AAAjD,CAAF,KAAgE;AACpE,QAAMC,eAAe,GAAG,sBAAS,MAAM;AACtC,QAAK,CAAEJ,aAAP,EAAuB;AACtB,aAAOE,YAAP;AACA;;AACD,WAAO;AACNG,MAAAA,OAAO,EAAEL,aADH;AAEN,SAAGE;AAFG,KAAP;AAIA,GARuB,EAQrB,CAAEF,aAAF,EAAiBE,YAAjB,CARqB,CAAxB;AAUA,SAAO,4BAAC,yBAAD;AAAkB,IAAA,YAAY,EAAGE;AAAjC,KAAwDD,KAAxD,EAAP;AACA,CA9BgC,CAAjC;;AAgCA,IAAKG,MAAM,IAAIA,MAAM,CAACC,EAAjB,IAAuBD,MAAM,CAACC,EAAP,CAAUC,UAAtC,EAAmD;AAClDF,EAAAA,MAAM,CAACC,EAAP,CAAUC,UAAV,CAAqBC,gBAArB,GAAwC,yBAAY,CAAEN,KAAF,EAASO,GAAT,KAAkB;AACrE,6BAAY,gCAAZ,EAA8C;AAC7CC,MAAAA,KAAK,EAAE,KADsC;AAE7CC,MAAAA,WAAW,EAAE;AAFgC,KAA9C;AAIA,WAAO,4BAAC,wBAAD,6BAA+BT,KAA/B;AAAuC,MAAA,GAAG,EAAGO;AAA7C,OAAP;AACA,GANuC,CAAxC;AAOA;;eAEcb,wB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo, forwardRef } from '@wordpress/element';\nimport { withSelect } from '@wordpress/data';\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport ServerSideRender from './server-side-render';\n\n/**\n * Constants\n */\nconst EMPTY_OBJECT = {};\n\nconst ExportedServerSideRender = withSelect( ( select ) => {\n\t// FIXME: @wordpress/server-side-render should not depend on @wordpress/editor.\n\t// It is used by blocks that can be loaded into a *non-post* block editor.\n\t// eslint-disable-next-line @wordpress/data-no-store-string-literals\n\tconst coreEditorSelect = select( 'core/editor' );\n\tif ( coreEditorSelect ) {\n\t\tconst currentPostId = coreEditorSelect.getCurrentPostId();\n\t\t// For templates and template parts we use a custom ID format.\n\t\t// Since they aren't real posts, we don't want to use their ID\n\t\t// for server-side rendering. Since they use a string based ID,\n\t\t// we can assume real post IDs are numbers.\n\t\tif ( currentPostId && typeof currentPostId === 'number' ) {\n\t\t\treturn {\n\t\t\t\tcurrentPostId,\n\t\t\t};\n\t\t}\n\t}\n\treturn EMPTY_OBJECT;\n} )( ( { urlQueryArgs = EMPTY_OBJECT, currentPostId, ...props } ) => {\n\tconst newUrlQueryArgs = useMemo( () => {\n\t\tif ( ! currentPostId ) {\n\t\t\treturn urlQueryArgs;\n\t\t}\n\t\treturn {\n\t\t\tpost_id: currentPostId,\n\t\t\t...urlQueryArgs,\n\t\t};\n\t}, [ currentPostId, urlQueryArgs ] );\n\n\treturn <ServerSideRender urlQueryArgs={ newUrlQueryArgs } { ...props } />;\n} );\n\nif ( window && window.wp && window.wp.components ) {\n\twindow.wp.components.ServerSideRender = forwardRef( ( props, ref ) => {\n\t\tdeprecated( 'wp.components.ServerSideRender', {\n\t\t\tsince: '5.3',\n\t\t\talternative: 'wp.serverSideRender',\n\t\t} );\n\t\treturn <ExportedServerSideRender { ...props } ref={ ref } />;\n\t} );\n}\n\nexport default ExportedServerSideRender;\n"]}
1
+ {"version":3,"sources":["@wordpress/server-side-render/src/index.js"],"names":["EMPTY_OBJECT","ExportedServerSideRender","select","coreEditorSelect","currentPostId","getCurrentPostId","urlQueryArgs","props","newUrlQueryArgs","post_id","window","wp","components","ServerSideRender","ref","since","alternative"],"mappings":";;;;;;;;;AAGA;;;;AACA;;AACA;;AAKA;;AAVA;AACA;AACA;;AAKA;AACA;AACA;;AAGA;AACA;AACA;AACA,MAAMA,YAAY,GAAG,EAArB;AAEA,MAAMC,wBAAwB,GAAG,sBAAcC,MAAF,IAAc;AAC1D;AACA;AACA;AACA,QAAMC,gBAAgB,GAAGD,MAAM,CAAE,aAAF,CAA/B;;AACA,MAAKC,gBAAL,EAAwB;AACvB,UAAMC,aAAa,GAAGD,gBAAgB,CAACE,gBAAjB,EAAtB,CADuB,CAEvB;AACA;AACA;AACA;;AACA,QAAKD,aAAa,IAAI,OAAOA,aAAP,KAAyB,QAA/C,EAA0D;AACzD,aAAO;AACNA,QAAAA;AADM,OAAP;AAGA;AACD;;AACD,SAAOJ,YAAP;AACA,CAlBgC,EAkB5B,QAAgE;AAAA,MAA9D;AAAEM,IAAAA,YAAY,GAAGN,YAAjB;AAA+BI,IAAAA,aAA/B;AAA8C,OAAGG;AAAjD,GAA8D;AACpE,QAAMC,eAAe,GAAG,sBAAS,MAAM;AACtC,QAAK,CAAEJ,aAAP,EAAuB;AACtB,aAAOE,YAAP;AACA;;AACD,WAAO;AACNG,MAAAA,OAAO,EAAEL,aADH;AAEN,SAAGE;AAFG,KAAP;AAIA,GARuB,EAQrB,CAAEF,aAAF,EAAiBE,YAAjB,CARqB,CAAxB;AAUA,SAAO,4BAAC,yBAAD;AAAkB,IAAA,YAAY,EAAGE;AAAjC,KAAwDD,KAAxD,EAAP;AACA,CA9BgC,CAAjC;;AAgCA,IAAKG,MAAM,IAAIA,MAAM,CAACC,EAAjB,IAAuBD,MAAM,CAACC,EAAP,CAAUC,UAAtC,EAAmD;AAClDF,EAAAA,MAAM,CAACC,EAAP,CAAUC,UAAV,CAAqBC,gBAArB,GAAwC,yBAAY,CAAEN,KAAF,EAASO,GAAT,KAAkB;AACrE,6BAAY,gCAAZ,EAA8C;AAC7CC,MAAAA,KAAK,EAAE,KADsC;AAE7CC,MAAAA,WAAW,EAAE;AAFgC,KAA9C;AAIA,WAAO,4BAAC,wBAAD,6BAA+BT,KAA/B;AAAuC,MAAA,GAAG,EAAGO;AAA7C,OAAP;AACA,GANuC,CAAxC;AAOA;;eAEcb,wB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo, forwardRef } from '@wordpress/element';\nimport { withSelect } from '@wordpress/data';\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport ServerSideRender from './server-side-render';\n\n/**\n * Constants\n */\nconst EMPTY_OBJECT = {};\n\nconst ExportedServerSideRender = withSelect( ( select ) => {\n\t// FIXME: @wordpress/server-side-render should not depend on @wordpress/editor.\n\t// It is used by blocks that can be loaded into a *non-post* block editor.\n\t// eslint-disable-next-line @wordpress/data-no-store-string-literals\n\tconst coreEditorSelect = select( 'core/editor' );\n\tif ( coreEditorSelect ) {\n\t\tconst currentPostId = coreEditorSelect.getCurrentPostId();\n\t\t// For templates and template parts we use a custom ID format.\n\t\t// Since they aren't real posts, we don't want to use their ID\n\t\t// for server-side rendering. Since they use a string based ID,\n\t\t// we can assume real post IDs are numbers.\n\t\tif ( currentPostId && typeof currentPostId === 'number' ) {\n\t\t\treturn {\n\t\t\t\tcurrentPostId,\n\t\t\t};\n\t\t}\n\t}\n\treturn EMPTY_OBJECT;\n} )( ( { urlQueryArgs = EMPTY_OBJECT, currentPostId, ...props } ) => {\n\tconst newUrlQueryArgs = useMemo( () => {\n\t\tif ( ! currentPostId ) {\n\t\t\treturn urlQueryArgs;\n\t\t}\n\t\treturn {\n\t\t\tpost_id: currentPostId,\n\t\t\t...urlQueryArgs,\n\t\t};\n\t}, [ currentPostId, urlQueryArgs ] );\n\n\treturn <ServerSideRender urlQueryArgs={ newUrlQueryArgs } { ...props } />;\n} );\n\nif ( window && window.wp && window.wp.components ) {\n\twindow.wp.components.ServerSideRender = forwardRef( ( props, ref ) => {\n\t\tdeprecated( 'wp.components.ServerSideRender', {\n\t\t\tsince: '5.3',\n\t\t\talternative: 'wp.serverSideRender',\n\t\t} );\n\t\treturn <ExportedServerSideRender { ...props } ref={ ref } />;\n\t} );\n}\n\nexport default ExportedServerSideRender;\n"]}
@@ -5,8 +5,8 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.rendererPath = rendererPath;
9
8
  exports.default = ServerSideRender;
9
+ exports.rendererPath = rendererPath;
10
10
 
11
11
  var _element = require("@wordpress/element");
12
12
 
@@ -33,7 +33,9 @@ var _blocks = require("@wordpress/blocks");
33
33
  /**
34
34
  * WordPress dependencies
35
35
  */
36
- function rendererPath(block, attributes = null, urlQueryArgs = {}) {
36
+ function rendererPath(block) {
37
+ let attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
38
+ let urlQueryArgs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
37
39
  return (0, _url.addQueryArgs)(`/wp/v2/block-renderer/${block}`, {
38
40
  context: 'edit',
39
41
  ...(null !== attributes ? {
@@ -43,18 +45,20 @@ function rendererPath(block, attributes = null, urlQueryArgs = {}) {
43
45
  });
44
46
  }
45
47
 
46
- function DefaultEmptyResponsePlaceholder({
47
- className
48
- }) {
48
+ function DefaultEmptyResponsePlaceholder(_ref) {
49
+ let {
50
+ className
51
+ } = _ref;
49
52
  return (0, _element.createElement)(_components.Placeholder, {
50
53
  className: className
51
54
  }, (0, _i18n.__)('Block rendered as empty.'));
52
55
  }
53
56
 
54
- function DefaultErrorResponsePlaceholder({
55
- response,
56
- className
57
- }) {
57
+ function DefaultErrorResponsePlaceholder(_ref2) {
58
+ let {
59
+ response,
60
+ className
61
+ } = _ref2;
58
62
  const errorMessage = (0, _i18n.sprintf)( // translators: %s: error message describing the problem
59
63
  (0, _i18n.__)('Error loading block: %s'), response.errorMsg);
60
64
  return (0, _element.createElement)(_components.Placeholder, {
@@ -62,10 +66,11 @@ function DefaultErrorResponsePlaceholder({
62
66
  }, errorMessage);
63
67
  }
64
68
 
65
- function DefaultLoadingResponsePlaceholder({
66
- children,
67
- showLoader
68
- }) {
69
+ function DefaultLoadingResponsePlaceholder(_ref3) {
70
+ let {
71
+ children,
72
+ showLoader
73
+ } = _ref3;
69
74
  return (0, _element.createElement)("div", {
70
75
  style: {
71
76
  position: 'relative'
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/server-side-render/src/server-side-render.js"],"names":["rendererPath","block","attributes","urlQueryArgs","context","DefaultEmptyResponsePlaceholder","className","DefaultErrorResponsePlaceholder","response","errorMessage","errorMsg","DefaultLoadingResponsePlaceholder","children","showLoader","position","top","left","marginTop","marginLeft","opacity","ServerSideRender","props","httpMethod","EmptyResponsePlaceholder","ErrorResponsePlaceholder","LoadingResponsePlaceholder","isMountedRef","setShowLoader","fetchRequestRef","setResponse","prevProps","isLoading","setIsLoading","fetchData","current","sanitizedAttributes","isPostRequest","urlAttributes","path","data","fetchRequest","method","then","fetchResponse","rendered","catch","error","message","finally","debouncedFetchData","undefined","timeout","setTimeout","clearTimeout","hasResponse","hasEmptyResponse","hasError"],"mappings":";;;;;;;;;;AASA;;;;AANA;;AAKA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AAdA;AACA;AACA;;AAGA;AACA;AACA;AASO,SAASA,YAAT,CAAuBC,KAAvB,EAA8BC,UAAU,GAAG,IAA3C,EAAiDC,YAAY,GAAG,EAAhE,EAAqE;AAC3E,SAAO,uBAAe,yBAAyBF,KAAO,EAA/C,EAAkD;AACxDG,IAAAA,OAAO,EAAE,MAD+C;AAExD,QAAK,SAASF,UAAT,GAAsB;AAAEA,MAAAA;AAAF,KAAtB,GAAuC,EAA5C,CAFwD;AAGxD,OAAGC;AAHqD,GAAlD,CAAP;AAKA;;AAED,SAASE,+BAAT,CAA0C;AAAEC,EAAAA;AAAF,CAA1C,EAA0D;AACzD,SACC,4BAAC,uBAAD;AAAa,IAAA,SAAS,EAAGA;AAAzB,KACG,cAAI,0BAAJ,CADH,CADD;AAKA;;AAED,SAASC,+BAAT,CAA0C;AAAEC,EAAAA,QAAF;AAAYF,EAAAA;AAAZ,CAA1C,EAAoE;AACnE,QAAMG,YAAY,GAAG,oBACpB;AACA,gBAAI,yBAAJ,CAFoB,EAGpBD,QAAQ,CAACE,QAHW,CAArB;AAKA,SAAO,4BAAC,uBAAD;AAAa,IAAA,SAAS,EAAGJ;AAAzB,KAAuCG,YAAvC,CAAP;AACA;;AAED,SAASE,iCAAT,CAA4C;AAAEC,EAAAA,QAAF;AAAYC,EAAAA;AAAZ,CAA5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BAAD;AAAS,MAAA,SAAS,EAAGhD;AAArB,OAAmCE,QAAnC,CAFF,CADD;AAOA;;AAED,SAAO,4BAAC,gBAAD;AAAS,IAAA,SAAS,EAAGF;AAArB,KAAmCE,QAAnC,CAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { isEqual } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useDebounce, usePrevious } from '@wordpress/compose';\nimport { RawHTML, useEffect, useRef, useState } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport apiFetch from '@wordpress/api-fetch';\nimport { addQueryArgs } from '@wordpress/url';\nimport { Placeholder, Spinner } from '@wordpress/components';\nimport { __experimentalSanitizeBlockAttributes } from '@wordpress/blocks';\n\nexport function rendererPath( block, attributes = null, urlQueryArgs = {} ) {\n\treturn addQueryArgs( `/wp/v2/block-renderer/${ block }`, {\n\t\tcontext: 'edit',\n\t\t...( null !== attributes ? { attributes } : {} ),\n\t\t...urlQueryArgs,\n\t} );\n}\n\nfunction DefaultEmptyResponsePlaceholder( { className } ) {\n\treturn (\n\t\t<Placeholder className={ className }>\n\t\t\t{ __( 'Block rendered as empty.' ) }\n\t\t</Placeholder>\n\t);\n}\n\nfunction DefaultErrorResponsePlaceholder( { response, className } ) {\n\tconst errorMessage = sprintf(\n\t\t// translators: %s: error message describing the problem\n\t\t__( 'Error loading block: %s' ),\n\t\tresponse.errorMsg\n\t);\n\treturn <Placeholder className={ className }>{ errorMessage }</Placeholder>;\n}\n\nfunction DefaultLoadingResponsePlaceholder( { children, showLoader } ) {\n\treturn (\n\t\t<div style={ { position: 'relative' } }>\n\t\t\t{ showLoader && (\n\t\t\t\t<div\n\t\t\t\t\tstyle={ {\n\t\t\t\t\t\tposition: 'absolute',\n\t\t\t\t\t\ttop: '50%',\n\t\t\t\t\t\tleft: '50%',\n\t\t\t\t\t\tmarginTop: '-9px',\n\t\t\t\t\t\tmarginLeft: '-9px',\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t<Spinner />\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t<div style={ { opacity: showLoader ? '0.3' : 1 } }>\n\t\t\t\t{ children }\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n\nexport default function ServerSideRender( props ) {\n\tconst {\n\t\tattributes,\n\t\tblock,\n\t\tclassName,\n\t\thttpMethod = 'GET',\n\t\turlQueryArgs,\n\t\tEmptyResponsePlaceholder = DefaultEmptyResponsePlaceholder,\n\t\tErrorResponsePlaceholder = DefaultErrorResponsePlaceholder,\n\t\tLoadingResponsePlaceholder = DefaultLoadingResponsePlaceholder,\n\t} = props;\n\n\tconst isMountedRef = useRef( true );\n\tconst [ showLoader, setShowLoader ] = useState( false );\n\tconst fetchRequestRef = useRef();\n\tconst [ response, setResponse ] = useState( null );\n\tconst prevProps = usePrevious( props );\n\tconst [ isLoading, setIsLoading ] = useState( false );\n\n\tfunction fetchData() {\n\t\tif ( ! isMountedRef.current ) {\n\t\t\treturn;\n\t\t}\n\n\t\tsetIsLoading( true );\n\n\t\tconst sanitizedAttributes =\n\t\t\tattributes &&\n\t\t\t__experimentalSanitizeBlockAttributes( block, attributes );\n\n\t\t// If httpMethod is 'POST', send the attributes in the request body instead of the URL.\n\t\t// This allows sending a larger attributes object than in a GET request, where the attributes are in the URL.\n\t\tconst isPostRequest = 'POST' === httpMethod;\n\t\tconst urlAttributes = isPostRequest\n\t\t\t? null\n\t\t\t: sanitizedAttributes ?? null;\n\t\tconst path = rendererPath( block, urlAttributes, urlQueryArgs );\n\t\tconst data = isPostRequest\n\t\t\t? { attributes: sanitizedAttributes ?? null }\n\t\t\t: null;\n\n\t\t// Store the latest fetch request so that when we process it, we can\n\t\t// check if it is the current request, to avoid race conditions on slow networks.\n\t\tconst fetchRequest = ( fetchRequestRef.current = apiFetch( {\n\t\t\tpath,\n\t\t\tdata,\n\t\t\tmethod: isPostRequest ? 'POST' : 'GET',\n\t\t} )\n\t\t\t.then( ( fetchResponse ) => {\n\t\t\t\tif (\n\t\t\t\t\tisMountedRef.current &&\n\t\t\t\t\tfetchRequest === fetchRequestRef.current &&\n\t\t\t\t\tfetchResponse\n\t\t\t\t) {\n\t\t\t\t\tsetResponse( fetchResponse.rendered );\n\t\t\t\t}\n\t\t\t} )\n\t\t\t.catch( ( error ) => {\n\t\t\t\tif (\n\t\t\t\t\tisMountedRef.current &&\n\t\t\t\t\tfetchRequest === fetchRequestRef.current\n\t\t\t\t) {\n\t\t\t\t\tsetResponse( {\n\t\t\t\t\t\terror: true,\n\t\t\t\t\t\terrorMsg: error.message,\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t} )\n\t\t\t.finally( () => {\n\t\t\t\tif (\n\t\t\t\t\tisMountedRef.current &&\n\t\t\t\t\tfetchRequest === fetchRequestRef.current\n\t\t\t\t) {\n\t\t\t\t\tsetIsLoading( false );\n\t\t\t\t}\n\t\t\t} ) );\n\n\t\treturn fetchRequest;\n\t}\n\n\tconst debouncedFetchData = useDebounce( fetchData, 500 );\n\n\t// When the component unmounts, set isMountedRef to false. This will\n\t// let the async fetch callbacks know when to stop.\n\tuseEffect(\n\t\t() => () => {\n\t\t\tisMountedRef.current = false;\n\t\t},\n\t\t[]\n\t);\n\n\tuseEffect( () => {\n\t\t// Don't debounce the first fetch. This ensures that the first render\n\t\t// shows data as soon as possible\n\t\tif ( prevProps === undefined ) {\n\t\t\tfetchData();\n\t\t} else if ( ! isEqual( prevProps, props ) ) {\n\t\t\tdebouncedFetchData();\n\t\t}\n\t} );\n\n\t/**\n\t * Effect to handle showing the loading placeholder.\n\t * Show it only if there is no previous response or\n\t * the request takes more than one second.\n\t */\n\tuseEffect( () => {\n\t\tif ( ! isLoading ) {\n\t\t\treturn;\n\t\t}\n\t\tconst timeout = setTimeout( () => {\n\t\t\tsetShowLoader( true );\n\t\t}, 1000 );\n\t\treturn () => clearTimeout( timeout );\n\t}, [ isLoading ] );\n\n\tconst hasResponse = !! response;\n\tconst hasEmptyResponse = response === '';\n\tconst hasError = response?.error;\n\n\tif ( hasEmptyResponse || ! hasResponse ) {\n\t\treturn <EmptyResponsePlaceholder { ...props } />;\n\t}\n\n\tif ( hasError ) {\n\t\treturn <ErrorResponsePlaceholder response={ response } { ...props } />;\n\t}\n\n\tif ( isLoading ) {\n\t\treturn (\n\t\t\t<LoadingResponsePlaceholder { ...props } showLoader={ showLoader }>\n\t\t\t\t{ hasResponse && (\n\t\t\t\t\t<RawHTML className={ className }>{ response }</RawHTML>\n\t\t\t\t) }\n\t\t\t</LoadingResponsePlaceholder>\n\t\t);\n\t}\n\n\treturn <RawHTML className={ className }>{ response }</RawHTML>;\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/server-side-render/src/server-side-render.js"],"names":["rendererPath","block","attributes","urlQueryArgs","context","DefaultEmptyResponsePlaceholder","className","DefaultErrorResponsePlaceholder","response","errorMessage","errorMsg","DefaultLoadingResponsePlaceholder","children","showLoader","position","top","left","marginTop","marginLeft","opacity","ServerSideRender","props","httpMethod","EmptyResponsePlaceholder","ErrorResponsePlaceholder","LoadingResponsePlaceholder","isMountedRef","setShowLoader","fetchRequestRef","setResponse","prevProps","isLoading","setIsLoading","fetchData","current","sanitizedAttributes","isPostRequest","urlAttributes","path","data","fetchRequest","method","then","fetchResponse","rendered","catch","error","message","finally","debouncedFetchData","undefined","timeout","setTimeout","clearTimeout","hasResponse","hasEmptyResponse","hasError"],"mappings":";;;;;;;;;;AASA;;;;AANA;;AAKA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AAdA;AACA;AACA;;AAGA;AACA;AACA;AASO,SAASA,YAAT,CAAuBC,KAAvB,EAAqE;AAAA,MAAvCC,UAAuC,uEAA1B,IAA0B;AAAA,MAApBC,YAAoB,uEAAL,EAAK;AAC3E,SAAO,uBAAe,yBAAyBF,KAAO,EAA/C,EAAkD;AACxDG,IAAAA,OAAO,EAAE,MAD+C;AAExD,QAAK,SAASF,UAAT,GAAsB;AAAEA,MAAAA;AAAF,KAAtB,GAAuC,EAA5C,CAFwD;A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AQG,CAAEpB,SAAF,CARH;AAUA,QAAMuB,WAAW,GAAG,CAAC,CAAE9C,QAAvB;AACA,QAAM+C,gBAAgB,GAAG/C,QAAQ,KAAK,EAAtC;AACA,QAAMgD,QAAQ,GAAGhD,QAAH,aAAGA,QAAH,uBAAGA,QAAQ,CAAEsC,KAA3B;;AAEA,MAAKS,gBAAgB,IAAI,CAAED,WAA3B,EAAyC;AACxC,WAAO,4BAAC,wBAAD,EAA+BjC,KAA/B,CAAP;AACA;;AAED,MAAKmC,QAAL,EAAgB;AACf,WAAO,4BAAC,wBAAD;AAA0B,MAAA,QAAQ,EAAGhD;AAArC,OAAqDa,KAArD,EAAP;AACA;;AAED,MAAKU,SAAL,EAAiB;AAChB,WACC,4BAAC,0BAAD,6BAAiCV,KAAjC;AAAyC,MAAA,UAAU,EAAGR;AAAtD,QACGyC,WAAW,IACZ,4BAAC,gBAAD;AAAS,MAAA,SAAS,EAAGhD;AAArB,OAAmCE,QAAnC,CAFF,CADD;AAOA;;AAED,SAAO,4BAAC,gBAAD;AAAS,IAAA,SAAS,EAAGF;AAArB,KAAmCE,QAAnC,CAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { isEqual } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useDebounce, usePrevious } from '@wordpress/compose';\nimport { RawHTML, useEffect, useRef, useState } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport apiFetch from '@wordpress/api-fetch';\nimport { addQueryArgs } from '@wordpress/url';\nimport { Placeholder, Spinner } from '@wordpress/components';\nimport { __experimentalSanitizeBlockAttributes } from '@wordpress/blocks';\n\nexport function rendererPath( block, attributes = null, urlQueryArgs = {} ) {\n\treturn addQueryArgs( `/wp/v2/block-renderer/${ block }`, {\n\t\tcontext: 'edit',\n\t\t...( null !== attributes ? { attributes } : {} ),\n\t\t...urlQueryArgs,\n\t} );\n}\n\nfunction DefaultEmptyResponsePlaceholder( { className } ) {\n\treturn (\n\t\t<Placeholder className={ className }>\n\t\t\t{ __( 'Block rendered as empty.' ) }\n\t\t</Placeholder>\n\t);\n}\n\nfunction DefaultErrorResponsePlaceholder( { response, className } ) {\n\tconst errorMessage = sprintf(\n\t\t// translators: %s: error message describing the problem\n\t\t__( 'Error loading block: %s' ),\n\t\tresponse.errorMsg\n\t);\n\treturn <Placeholder className={ className }>{ errorMessage }</Placeholder>;\n}\n\nfunction DefaultLoadingResponsePlaceholder( { children, showLoader } ) {\n\treturn (\n\t\t<div style={ { position: 'relative' } }>\n\t\t\t{ showLoader && (\n\t\t\t\t<div\n\t\t\t\t\tstyle={ {\n\t\t\t\t\t\tposition: 'absolute',\n\t\t\t\t\t\ttop: '50%',\n\t\t\t\t\t\tleft: '50%',\n\t\t\t\t\t\tmarginTop: '-9px',\n\t\t\t\t\t\tmarginLeft: '-9px',\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t<Spinner />\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t<div style={ { opacity: showLoader ? '0.3' : 1 } }>\n\t\t\t\t{ children }\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n\nexport default function ServerSideRender( props ) {\n\tconst {\n\t\tattributes,\n\t\tblock,\n\t\tclassName,\n\t\thttpMethod = 'GET',\n\t\turlQueryArgs,\n\t\tEmptyResponsePlaceholder = DefaultEmptyResponsePlaceholder,\n\t\tErrorResponsePlaceholder = DefaultErrorResponsePlaceholder,\n\t\tLoadingResponsePlaceholder = DefaultLoadingResponsePlaceholder,\n\t} = props;\n\n\tconst isMountedRef = useRef( true );\n\tconst [ showLoader, setShowLoader ] = useState( false );\n\tconst fetchRequestRef = useRef();\n\tconst [ response, setResponse ] = useState( null );\n\tconst prevProps = usePrevious( props );\n\tconst [ isLoading, setIsLoading ] = useState( false );\n\n\tfunction fetchData() {\n\t\tif ( ! isMountedRef.current ) {\n\t\t\treturn;\n\t\t}\n\n\t\tsetIsLoading( true );\n\n\t\tconst sanitizedAttributes =\n\t\t\tattributes &&\n\t\t\t__experimentalSanitizeBlockAttributes( block, attributes );\n\n\t\t// If httpMethod is 'POST', send the attributes in the request body instead of the URL.\n\t\t// This allows sending a larger attributes object than in a GET request, where the attributes are in the URL.\n\t\tconst isPostRequest = 'POST' === httpMethod;\n\t\tconst urlAttributes = isPostRequest\n\t\t\t? null\n\t\t\t: sanitizedAttributes ?? null;\n\t\tconst path = rendererPath( block, urlAttributes, urlQueryArgs );\n\t\tconst data = isPostRequest\n\t\t\t? { attributes: sanitizedAttributes ?? null }\n\t\t\t: null;\n\n\t\t// Store the latest fetch request so that when we process it, we can\n\t\t// check if it is the current request, to avoid race conditions on slow networks.\n\t\tconst fetchRequest = ( fetchRequestRef.current = apiFetch( {\n\t\t\tpath,\n\t\t\tdata,\n\t\t\tmethod: isPostRequest ? 'POST' : 'GET',\n\t\t} )\n\t\t\t.then( ( fetchResponse ) => {\n\t\t\t\tif (\n\t\t\t\t\tisMountedRef.current &&\n\t\t\t\t\tfetchRequest === fetchRequestRef.current &&\n\t\t\t\t\tfetchResponse\n\t\t\t\t) {\n\t\t\t\t\tsetResponse( fetchResponse.rendered );\n\t\t\t\t}\n\t\t\t} )\n\t\t\t.catch( ( error ) => {\n\t\t\t\tif (\n\t\t\t\t\tisMountedRef.current &&\n\t\t\t\t\tfetchRequest === fetchRequestRef.current\n\t\t\t\t) {\n\t\t\t\t\tsetResponse( {\n\t\t\t\t\t\terror: true,\n\t\t\t\t\t\terrorMsg: error.message,\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t} )\n\t\t\t.finally( () => {\n\t\t\t\tif (\n\t\t\t\t\tisMountedRef.current &&\n\t\t\t\t\tfetchRequest === fetchRequestRef.current\n\t\t\t\t) {\n\t\t\t\t\tsetIsLoading( false );\n\t\t\t\t}\n\t\t\t} ) );\n\n\t\treturn fetchRequest;\n\t}\n\n\tconst debouncedFetchData = useDebounce( fetchData, 500 );\n\n\t// When the component unmounts, set isMountedRef to false. This will\n\t// let the async fetch callbacks know when to stop.\n\tuseEffect(\n\t\t() => () => {\n\t\t\tisMountedRef.current = false;\n\t\t},\n\t\t[]\n\t);\n\n\tuseEffect( () => {\n\t\t// Don't debounce the first fetch. This ensures that the first render\n\t\t// shows data as soon as possible\n\t\tif ( prevProps === undefined ) {\n\t\t\tfetchData();\n\t\t} else if ( ! isEqual( prevProps, props ) ) {\n\t\t\tdebouncedFetchData();\n\t\t}\n\t} );\n\n\t/**\n\t * Effect to handle showing the loading placeholder.\n\t * Show it only if there is no previous response or\n\t * the request takes more than one second.\n\t */\n\tuseEffect( () => {\n\t\tif ( ! isLoading ) {\n\t\t\treturn;\n\t\t}\n\t\tconst timeout = setTimeout( () => {\n\t\t\tsetShowLoader( true );\n\t\t}, 1000 );\n\t\treturn () => clearTimeout( timeout );\n\t}, [ isLoading ] );\n\n\tconst hasResponse = !! response;\n\tconst hasEmptyResponse = response === '';\n\tconst hasError = response?.error;\n\n\tif ( hasEmptyResponse || ! hasResponse ) {\n\t\treturn <EmptyResponsePlaceholder { ...props } />;\n\t}\n\n\tif ( hasError ) {\n\t\treturn <ErrorResponsePlaceholder response={ response } { ...props } />;\n\t}\n\n\tif ( isLoading ) {\n\t\treturn (\n\t\t\t<LoadingResponsePlaceholder { ...props } showLoader={ showLoader }>\n\t\t\t\t{ hasResponse && (\n\t\t\t\t\t<RawHTML className={ className }>{ response }</RawHTML>\n\t\t\t\t) }\n\t\t\t</LoadingResponsePlaceholder>\n\t\t);\n\t}\n\n\treturn <RawHTML className={ className }>{ response }</RawHTML>;\n}\n"]}
@@ -37,11 +37,12 @@ const ExportedServerSideRender = withSelect(select => {
37
37
  }
38
38
 
39
39
  return EMPTY_OBJECT;
40
- })(({
41
- urlQueryArgs = EMPTY_OBJECT,
42
- currentPostId,
43
- ...props
44
- }) => {
40
+ })(_ref => {
41
+ let {
42
+ urlQueryArgs = EMPTY_OBJECT,
43
+ currentPostId,
44
+ ...props
45
+ } = _ref;
45
46
  const newUrlQueryArgs = useMemo(() => {
46
47
  if (!currentPostId) {
47
48
  return urlQueryArgs;
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/server-side-render/src/index.js"],"names":["useMemo","forwardRef","withSelect","deprecated","ServerSideRender","EMPTY_OBJECT","ExportedServerSideRender","select","coreEditorSelect","currentPostId","getCurrentPostId","urlQueryArgs","props","newUrlQueryArgs","post_id","window","wp","components","ref","since","alternative"],"mappings":";;;AAAA;AACA;AACA;AACA,SAASA,OAAT,EAAkBC,UAAlB,QAAoC,oBAApC;AACA,SAASC,UAAT,QAA2B,iBAA3B;AACA,OAAOC,UAAP,MAAuB,uBAAvB;AAEA;AACA;AACA;;AACA,OAAOC,gBAAP,MAA6B,sBAA7B;AAEA;AACA;AACA;;AACA,MAAMC,YAAY,GAAG,EAArB;AAEA,MAAMC,wBAAwB,GAAGJ,UAAU,CAAIK,MAAF,IAAc;AAC1D;AACA;AACA;AACA,QAAMC,gBAAgB,GAAGD,MAAM,CAAE,aAAF,CAA/B;;AACA,MAAKC,gBAAL,EAAwB;AACvB,UAAMC,aAAa,GAAGD,gBAAgB,CAACE,gBAAjB,EAAtB,CADuB,CAEvB;AACA;AACA;AACA;;AACA,QAAKD,aAAa,IAAI,OAAOA,aAAP,KAAyB,QAA/C,EAA0D;AACzD,aAAO;AACNA,QAAAA;AADM,OAAP;AAGA;AACD;;AACD,SAAOJ,YAAP;AACA,CAlB0C,CAAV,CAkB5B,CAAE;AAAEM,EAAAA,YAAY,GAAGN,YAAjB;AAA+BI,EAAAA,aAA/B;AAA8C,KAAGG;AAAjD,CAAF,KAAgE;AACpE,QAAMC,eAAe,GAAGb,OAAO,CAAE,MAAM;AACtC,QAAK,CAAES,aAAP,EAAuB;AACtB,aAAOE,YAAP;AACA;;AACD,WAAO;AACNG,MAAAA,OAAO,EAAEL,aADH;AAEN,SAAGE;AAFG,KAAP;AAIA,GAR8B,EAQ5B,CAAEF,aAAF,EAAiBE,YAAjB,CAR4B,CAA/B;AAUA,SAAO,cAAC,gBAAD;AAAkB,IAAA,YAAY,EAAGE;AAAjC,KAAwDD,KAAxD,EAAP;AACA,CA9BgC,CAAjC;;AAgCA,IAAKG,MAAM,IAAIA,MAAM,CAACC,EAAjB,IAAuBD,MAAM,CAACC,EAAP,CAAUC,UAAtC,EAAmD;AAClDF,EAAAA,MAAM,CAACC,EAAP,CAAUC,UAAV,CAAqBb,gBAArB,GAAwCH,UAAU,CAAE,CAAEW,KAAF,EAASM,GAAT,KAAkB;AACrEf,IAAAA,UAAU,CAAE,gCAAF,EAAoC;AAC7CgB,MAAAA,KAAK,EAAE,KADsC;AAE7CC,MAAAA,WAAW,EAAE;AAFgC,KAApC,CAAV;AAIA,WAAO,cAAC,wBAAD,eAA+BR,KAA/B;AAAuC,MAAA,GAAG,EAAGM;AAA7C,OAAP;AACA,GANiD,CAAlD;AAOA;;AAED,eAAeZ,wBAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo, forwardRef } from '@wordpress/element';\nimport { withSelect } from '@wordpress/data';\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport ServerSideRender from './server-side-render';\n\n/**\n * Constants\n */\nconst EMPTY_OBJECT = {};\n\nconst ExportedServerSideRender = withSelect( ( select ) => {\n\t// FIXME: @wordpress/server-side-render should not depend on @wordpress/editor.\n\t// It is used by blocks that can be loaded into a *non-post* block editor.\n\t// eslint-disable-next-line @wordpress/data-no-store-string-literals\n\tconst coreEditorSelect = select( 'core/editor' );\n\tif ( coreEditorSelect ) {\n\t\tconst currentPostId = coreEditorSelect.getCurrentPostId();\n\t\t// For templates and template parts we use a custom ID format.\n\t\t// Since they aren't real posts, we don't want to use their ID\n\t\t// for server-side rendering. Since they use a string based ID,\n\t\t// we can assume real post IDs are numbers.\n\t\tif ( currentPostId && typeof currentPostId === 'number' ) {\n\t\t\treturn {\n\t\t\t\tcurrentPostId,\n\t\t\t};\n\t\t}\n\t}\n\treturn EMPTY_OBJECT;\n} )( ( { urlQueryArgs = EMPTY_OBJECT, currentPostId, ...props } ) => {\n\tconst newUrlQueryArgs = useMemo( () => {\n\t\tif ( ! currentPostId ) {\n\t\t\treturn urlQueryArgs;\n\t\t}\n\t\treturn {\n\t\t\tpost_id: currentPostId,\n\t\t\t...urlQueryArgs,\n\t\t};\n\t}, [ currentPostId, urlQueryArgs ] );\n\n\treturn <ServerSideRender urlQueryArgs={ newUrlQueryArgs } { ...props } />;\n} );\n\nif ( window && window.wp && window.wp.components ) {\n\twindow.wp.components.ServerSideRender = forwardRef( ( props, ref ) => {\n\t\tdeprecated( 'wp.components.ServerSideRender', {\n\t\t\tsince: '5.3',\n\t\t\talternative: 'wp.serverSideRender',\n\t\t} );\n\t\treturn <ExportedServerSideRender { ...props } ref={ ref } />;\n\t} );\n}\n\nexport default ExportedServerSideRender;\n"]}
1
+ {"version":3,"sources":["@wordpress/server-side-render/src/index.js"],"names":["useMemo","forwardRef","withSelect","deprecated","ServerSideRender","EMPTY_OBJECT","ExportedServerSideRender","select","coreEditorSelect","currentPostId","getCurrentPostId","urlQueryArgs","props","newUrlQueryArgs","post_id","window","wp","components","ref","since","alternative"],"mappings":";;;AAAA;AACA;AACA;AACA,SAASA,OAAT,EAAkBC,UAAlB,QAAoC,oBAApC;AACA,SAASC,UAAT,QAA2B,iBAA3B;AACA,OAAOC,UAAP,MAAuB,uBAAvB;AAEA;AACA;AACA;;AACA,OAAOC,gBAAP,MAA6B,sBAA7B;AAEA;AACA;AACA;;AACA,MAAMC,YAAY,GAAG,EAArB;AAEA,MAAMC,wBAAwB,GAAGJ,UAAU,CAAIK,MAAF,IAAc;AAC1D;AACA;AACA;AACA,QAAMC,gBAAgB,GAAGD,MAAM,CAAE,aAAF,CAA/B;;AACA,MAAKC,gBAAL,EAAwB;AACvB,UAAMC,aAAa,GAAGD,gBAAgB,CAACE,gBAAjB,EAAtB,CADuB,CAEvB;AACA;AACA;AACA;;AACA,QAAKD,aAAa,IAAI,OAAOA,aAAP,KAAyB,QAA/C,EAA0D;AACzD,aAAO;AACNA,QAAAA;AADM,OAAP;AAGA;AACD;;AACD,SAAOJ,YAAP;AACA,CAlB0C,CAAV,CAkB5B,QAAgE;AAAA,MAA9D;AAAEM,IAAAA,YAAY,GAAGN,YAAjB;AAA+BI,IAAAA,aAA/B;AAA8C,OAAGG;AAAjD,GAA8D;AACpE,QAAMC,eAAe,GAAGb,OAAO,CAAE,MAAM;AACtC,QAAK,CAAES,aAAP,EAAuB;AACtB,aAAOE,YAAP;AACA;;AACD,WAAO;AACNG,MAAAA,OAAO,EAAEL,aADH;AAEN,SAAGE;AAFG,KAAP;AAIA,GAR8B,EAQ5B,CAAEF,aAAF,EAAiBE,YAAjB,CAR4B,CAA/B;AAUA,SAAO,cAAC,gBAAD;AAAkB,IAAA,YAAY,EAAGE;AAAjC,KAAwDD,KAAxD,EAAP;AACA,CA9BgC,CAAjC;;AAgCA,IAAKG,MAAM,IAAIA,MAAM,CAACC,EAAjB,IAAuBD,MAAM,CAACC,EAAP,CAAUC,UAAtC,EAAmD;AAClDF,EAAAA,MAAM,CAACC,EAAP,CAAUC,UAAV,CAAqBb,gBAArB,GAAwCH,UAAU,CAAE,CAAEW,KAAF,EAASM,GAAT,KAAkB;AACrEf,IAAAA,UAAU,CAAE,gCAAF,EAAoC;AAC7CgB,MAAAA,KAAK,EAAE,KADsC;AAE7CC,MAAAA,WAAW,EAAE;AAFgC,KAApC,CAAV;AAIA,WAAO,cAAC,wBAAD,eAA+BR,KAA/B;AAAuC,MAAA,GAAG,EAAGM;AAA7C,OAAP;AACA,GANiD,CAAlD;AAOA;;AAED,eAAeZ,wBAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo, forwardRef } from '@wordpress/element';\nimport { withSelect } from '@wordpress/data';\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport ServerSideRender from './server-side-render';\n\n/**\n * Constants\n */\nconst EMPTY_OBJECT = {};\n\nconst ExportedServerSideRender = withSelect( ( select ) => {\n\t// FIXME: @wordpress/server-side-render should not depend on @wordpress/editor.\n\t// It is used by blocks that can be loaded into a *non-post* block editor.\n\t// eslint-disable-next-line @wordpress/data-no-store-string-literals\n\tconst coreEditorSelect = select( 'core/editor' );\n\tif ( coreEditorSelect ) {\n\t\tconst currentPostId = coreEditorSelect.getCurrentPostId();\n\t\t// For templates and template parts we use a custom ID format.\n\t\t// Since they aren't real posts, we don't want to use their ID\n\t\t// for server-side rendering. Since they use a string based ID,\n\t\t// we can assume real post IDs are numbers.\n\t\tif ( currentPostId && typeof currentPostId === 'number' ) {\n\t\t\treturn {\n\t\t\t\tcurrentPostId,\n\t\t\t};\n\t\t}\n\t}\n\treturn EMPTY_OBJECT;\n} )( ( { urlQueryArgs = EMPTY_OBJECT, currentPostId, ...props } ) => {\n\tconst newUrlQueryArgs = useMemo( () => {\n\t\tif ( ! currentPostId ) {\n\t\t\treturn urlQueryArgs;\n\t\t}\n\t\treturn {\n\t\t\tpost_id: currentPostId,\n\t\t\t...urlQueryArgs,\n\t\t};\n\t}, [ currentPostId, urlQueryArgs ] );\n\n\treturn <ServerSideRender urlQueryArgs={ newUrlQueryArgs } { ...props } />;\n} );\n\nif ( window && window.wp && window.wp.components ) {\n\twindow.wp.components.ServerSideRender = forwardRef( ( props, ref ) => {\n\t\tdeprecated( 'wp.components.ServerSideRender', {\n\t\t\tsince: '5.3',\n\t\t\talternative: 'wp.serverSideRender',\n\t\t} );\n\t\treturn <ExportedServerSideRender { ...props } ref={ ref } />;\n\t} );\n}\n\nexport default ExportedServerSideRender;\n"]}
@@ -16,7 +16,9 @@ import apiFetch from '@wordpress/api-fetch';
16
16
  import { addQueryArgs } from '@wordpress/url';
17
17
  import { Placeholder, Spinner } from '@wordpress/components';
18
18
  import { __experimentalSanitizeBlockAttributes } from '@wordpress/blocks';
19
- export function rendererPath(block, attributes = null, urlQueryArgs = {}) {
19
+ export function rendererPath(block) {
20
+ let attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
21
+ let urlQueryArgs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
20
22
  return addQueryArgs(`/wp/v2/block-renderer/${block}`, {
21
23
  context: 'edit',
22
24
  ...(null !== attributes ? {
@@ -26,18 +28,20 @@ export function rendererPath(block, attributes = null, urlQueryArgs = {}) {
26
28
  });
27
29
  }
28
30
 
29
- function DefaultEmptyResponsePlaceholder({
30
- className
31
- }) {
31
+ function DefaultEmptyResponsePlaceholder(_ref) {
32
+ let {
33
+ className
34
+ } = _ref;
32
35
  return createElement(Placeholder, {
33
36
  className: className
34
37
  }, __('Block rendered as empty.'));
35
38
  }
36
39
 
37
- function DefaultErrorResponsePlaceholder({
38
- response,
39
- className
40
- }) {
40
+ function DefaultErrorResponsePlaceholder(_ref2) {
41
+ let {
42
+ response,
43
+ className
44
+ } = _ref2;
41
45
  const errorMessage = sprintf( // translators: %s: error message describing the problem
42
46
  __('Error loading block: %s'), response.errorMsg);
43
47
  return createElement(Placeholder, {
@@ -45,10 +49,11 @@ function DefaultErrorResponsePlaceholder({
45
49
  }, errorMessage);
46
50
  }
47
51
 
48
- function DefaultLoadingResponsePlaceholder({
49
- children,
50
- showLoader
51
- }) {
52
+ function DefaultLoadingResponsePlaceholder(_ref3) {
53
+ let {
54
+ children,
55
+ showLoader
56
+ } = _ref3;
52
57
  return createElement("div", {
53
58
  style: {
54
59
  position: 'relative'
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/server-side-render/src/server-side-render.js"],"names":["isEqual","useDebounce","usePrevious","RawHTML","useEffect","useRef","useState","__","sprintf","apiFetch","addQueryArgs","Placeholder","Spinner","__experimentalSanitizeBlockAttributes","rendererPath","block","attributes","urlQueryArgs","context","DefaultEmptyResponsePlaceholder","className","DefaultErrorResponsePlaceholder","response","errorMessage","errorMsg","DefaultLoadingResponsePlaceholder","children","showLoader","position","top","left","marginTop","marginLeft","opacity","ServerSideRender","props","httpMethod","EmptyResponsePlaceholder","ErrorResponsePlaceholder","LoadingResponsePlaceholder","isMountedRef","setShowLoader","fetchRequestRef","setResponse","prevProps","isLoading","setIsLoading","fetchData","current","sanitizedAttributes","isPostRequest","urlAttributes","path","data","fetchRequest","method","then","fetchResponse","rendered","catch","error","message","finally","debouncedFetchData","undefined","timeout","setTimeout","clearTimeout","hasResponse","hasEmptyResponse","hasError"],"mappings":";;;AAAA;AACA;AACA;AACA,SAASA,OAAT,QAAwB,QAAxB;AAEA;AACA;AACA;;AACA,SAASC,WAAT,EAAsBC,WAAtB,QAAyC,oBAAzC;AACA,SAASC,OAAT,EAAkBC,SAAlB,EAA6BC,MAA7B,EAAqCC,QAArC,QAAqD,oBAArD;AACA,SAASC,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,OAAOC,QAAP,MAAqB,sBAArB;AACA,SAASC,YAAT,QAA6B,gBAA7B;AACA,SAASC,WAAT,EAAsBC,OAAtB,QAAqC,uBAArC;AACA,SAASC,qCAAT,QAAsD,mBAAtD;AAEA,OAAO,SAASC,YAAT,CAAuBC,KAAvB,EAA8BC,UAAU,GAAG,IAA3C,EAAiDC,YAAY,GAAG,EAAhE,EAAqE;AAC3E,SAAOP,YAAY,CAAG,yBAAyBK,KAAO,EAAnC,EAAsC;AACxDG,IAAAA,OAAO,EAAE,MAD+C;AAExD,QAAK,SAASF,UAAT,GAAsB;AAAEA,MAAAA;AAAF,KAAtB,GAAuC,EAA5C,CAFwD;AAGxD,OAAGC;AAHqD,GAAtC,CAAnB;AAKA;;AAED,SAASE,+BAAT,CAA0C;AAAEC,EAAAA;AAAF,CAA1C,EAA0D;AACzD,SACC,cAAC,WAAD;AAAa,IAAA,SAAS,EAAGA;AAAzB,KACGb,EAAE,CAAE,0BAAF,CADL,CADD;AAKA;;AAED,SAASc,+BAAT,CAA0C;AAAEC,EAAAA,QAAF;AAAYF,EAAAA;AAAZ,CAA1C,EAAoE;AACnE,QAAMG,YAAY,GAAGf,OAAO,EAC3B;AACAD,EAAAA,EAAE,CAAE,yBAAF,CAFyB,EAG3Be,QAAQ,CAACE,QAHkB,CAA5B;AAKA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,WAA3B,EAAyC;AACxC,WAAO,cAAC,wBAAD,EAA+BjC,KAA/B,CAAP;AACA;;AAED,MAAKmC,QAAL,EAAgB;AACf,WAAO,cAAC,wBAAD;AAA0B,MAAA,QAAQ,EAAGhD;AAArC,OAAqDa,KAArD,EAAP;AACA;;AAED,MAAKU,SAAL,EAAiB;AAChB,WACC,cAAC,0BAAD,eAAiCV,KAAjC;AAAyC,MAAA,UAAU,EAAGR;AAAtD,QACGyC,WAAW,IACZ,cAAC,OAAD;AAAS,MAAA,SAAS,EAAGhD;AAArB,OAAmCE,QAAnC,CAFF,CADD;AAOA;;AAED,SAAO,cAAC,OAAD;AAAS,IAAA,SAAS,EAAGF;AAArB,KAAmCE,QAAnC,CAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { isEqual } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useDebounce, usePrevious } from '@wordpress/compose';\nimport { RawHTML, useEffect, useRef, useState } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport apiFetch from '@wordpress/api-fetch';\nimport { addQueryArgs } from '@wordpress/url';\nimport { Placeholder, Spinner } from '@wordpress/components';\nimport { __experimentalSanitizeBlockAttributes } from '@wordpress/blocks';\n\nexport function rendererPath( block, attributes = null, urlQueryArgs = {} ) {\n\treturn addQueryArgs( `/wp/v2/block-renderer/${ block }`, {\n\t\tcontext: 'edit',\n\t\t...( null !== attributes ? { attributes } : {} ),\n\t\t...urlQueryArgs,\n\t} );\n}\n\nfunction DefaultEmptyResponsePlaceholder( { className } ) {\n\treturn (\n\t\t<Placeholder className={ className }>\n\t\t\t{ __( 'Block rendered as empty.' ) }\n\t\t</Placeholder>\n\t);\n}\n\nfunction DefaultErrorResponsePlaceholder( { response, className } ) {\n\tconst errorMessage = sprintf(\n\t\t// translators: %s: error message describing the problem\n\t\t__( 'Error loading block: %s' ),\n\t\tresponse.errorMsg\n\t);\n\treturn <Placeholder className={ className }>{ errorMessage }</Placeholder>;\n}\n\nfunction DefaultLoadingResponsePlaceholder( { children, showLoader } ) {\n\treturn (\n\t\t<div style={ { position: 'relative' } }>\n\t\t\t{ showLoader && (\n\t\t\t\t<div\n\t\t\t\t\tstyle={ {\n\t\t\t\t\t\tposition: 'absolute',\n\t\t\t\t\t\ttop: '50%',\n\t\t\t\t\t\tleft: '50%',\n\t\t\t\t\t\tmarginTop: '-9px',\n\t\t\t\t\t\tmarginLeft: '-9px',\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t<Spinner />\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t<div style={ { opacity: showLoader ? '0.3' : 1 } }>\n\t\t\t\t{ children }\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n\nexport default function ServerSideRender( props ) {\n\tconst {\n\t\tattributes,\n\t\tblock,\n\t\tclassName,\n\t\thttpMethod = 'GET',\n\t\turlQueryArgs,\n\t\tEmptyResponsePlaceholder = DefaultEmptyResponsePlaceholder,\n\t\tErrorResponsePlaceholder = DefaultErrorResponsePlaceholder,\n\t\tLoadingResponsePlaceholder = DefaultLoadingResponsePlaceholder,\n\t} = props;\n\n\tconst isMountedRef = useRef( true );\n\tconst [ showLoader, setShowLoader ] = useState( false );\n\tconst fetchRequestRef = useRef();\n\tconst [ response, setResponse ] = useState( null );\n\tconst prevProps = usePrevious( props );\n\tconst [ isLoading, setIsLoading ] = useState( false );\n\n\tfunction fetchData() {\n\t\tif ( ! isMountedRef.current ) {\n\t\t\treturn;\n\t\t}\n\n\t\tsetIsLoading( true );\n\n\t\tconst sanitizedAttributes =\n\t\t\tattributes &&\n\t\t\t__experimentalSanitizeBlockAttributes( block, attributes );\n\n\t\t// If httpMethod is 'POST', send the attributes in the request body instead of the URL.\n\t\t// This allows sending a larger attributes object than in a GET request, where the attributes are in the URL.\n\t\tconst isPostRequest = 'POST' === httpMethod;\n\t\tconst urlAttributes = isPostRequest\n\t\t\t? null\n\t\t\t: sanitizedAttributes ?? null;\n\t\tconst path = rendererPath( block, urlAttributes, urlQueryArgs );\n\t\tconst data = isPostRequest\n\t\t\t? { attributes: sanitizedAttributes ?? null }\n\t\t\t: null;\n\n\t\t// Store the latest fetch request so that when we process it, we can\n\t\t// check if it is the current request, to avoid race conditions on slow networks.\n\t\tconst fetchRequest = ( fetchRequestRef.current = apiFetch( {\n\t\t\tpath,\n\t\t\tdata,\n\t\t\tmethod: isPostRequest ? 'POST' : 'GET',\n\t\t} )\n\t\t\t.then( ( fetchResponse ) => {\n\t\t\t\tif (\n\t\t\t\t\tisMountedRef.current &&\n\t\t\t\t\tfetchRequest === fetchRequestRef.current &&\n\t\t\t\t\tfetchResponse\n\t\t\t\t) {\n\t\t\t\t\tsetResponse( fetchResponse.rendered );\n\t\t\t\t}\n\t\t\t} )\n\t\t\t.catch( ( error ) => {\n\t\t\t\tif (\n\t\t\t\t\tisMountedRef.current &&\n\t\t\t\t\tfetchRequest === fetchRequestRef.current\n\t\t\t\t) {\n\t\t\t\t\tsetResponse( {\n\t\t\t\t\t\terror: true,\n\t\t\t\t\t\terrorMsg: error.message,\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t} )\n\t\t\t.finally( () => {\n\t\t\t\tif (\n\t\t\t\t\tisMountedRef.current &&\n\t\t\t\t\tfetchRequest === fetchRequestRef.current\n\t\t\t\t) {\n\t\t\t\t\tsetIsLoading( false );\n\t\t\t\t}\n\t\t\t} ) );\n\n\t\treturn fetchRequest;\n\t}\n\n\tconst debouncedFetchData = useDebounce( fetchData, 500 );\n\n\t// When the component unmounts, set isMountedRef to false. This will\n\t// let the async fetch callbacks know when to stop.\n\tuseEffect(\n\t\t() => () => {\n\t\t\tisMountedRef.current = false;\n\t\t},\n\t\t[]\n\t);\n\n\tuseEffect( () => {\n\t\t// Don't debounce the first fetch. This ensures that the first render\n\t\t// shows data as soon as possible\n\t\tif ( prevProps === undefined ) {\n\t\t\tfetchData();\n\t\t} else if ( ! isEqual( prevProps, props ) ) {\n\t\t\tdebouncedFetchData();\n\t\t}\n\t} );\n\n\t/**\n\t * Effect to handle showing the loading placeholder.\n\t * Show it only if there is no previous response or\n\t * the request takes more than one second.\n\t */\n\tuseEffect( () => {\n\t\tif ( ! isLoading ) {\n\t\t\treturn;\n\t\t}\n\t\tconst timeout = setTimeout( () => {\n\t\t\tsetShowLoader( true );\n\t\t}, 1000 );\n\t\treturn () => clearTimeout( timeout );\n\t}, [ isLoading ] );\n\n\tconst hasResponse = !! response;\n\tconst hasEmptyResponse = response === '';\n\tconst hasError = response?.error;\n\n\tif ( hasEmptyResponse || ! hasResponse ) {\n\t\treturn <EmptyResponsePlaceholder { ...props } />;\n\t}\n\n\tif ( hasError ) {\n\t\treturn <ErrorResponsePlaceholder response={ response } { ...props } />;\n\t}\n\n\tif ( isLoading ) {\n\t\treturn (\n\t\t\t<LoadingResponsePlaceholder { ...props } showLoader={ showLoader }>\n\t\t\t\t{ hasResponse && (\n\t\t\t\t\t<RawHTML className={ className }>{ response }</RawHTML>\n\t\t\t\t) }\n\t\t\t</LoadingResponsePlaceholder>\n\t\t);\n\t}\n\n\treturn <RawHTML className={ className }>{ response }</RawHTML>;\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/server-side-render/src/server-side-render.js"],"names":["isEqual","useDebounce","usePrevious","RawHTML","useEffect","useRef","useState","__","sprintf","apiFetch","addQueryArgs","Placeholder","Spinner","__experimentalSanitizeBlockAttributes","rendererPath","block","attributes","urlQueryArgs","context","DefaultEmptyResponsePlaceholder","className","DefaultErrorResponsePlaceholder","response","errorMessage","errorMsg","DefaultLoadingResponsePlaceholder","children","showLoader","position","top","left","marginTop","marginLeft","opacity","ServerSideRender","props","httpMethod","EmptyResponsePlaceholder","ErrorResponsePlaceholder","LoadingResponsePlaceholder","isMountedRef","setShowLoader","fetchRequestRef","setResponse","prevProps","isLoading","setIsLoading","fetchData","current","sanitizedAttributes","isPostRequest","urlAttributes","path","data","fetchRequest","method","then","fetchResponse","rendered","catch","error","message","finally","debouncedFetchData","undefined","timeout","setTimeout","clearTimeout","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cAAC,wBAAD;AAA0B,MAAA,QAAQ,EAAGhD;AAArC,OAAqDa,KAArD,EAAP;AACA;;AAED,MAAKU,SAAL,EAAiB;AAChB,WACC,cAAC,0BAAD,eAAiCV,KAAjC;AAAyC,MAAA,UAAU,EAAGR;AAAtD,QACGyC,WAAW,IACZ,cAAC,OAAD;AAAS,MAAA,SAAS,EAAGhD;AAArB,OAAmCE,QAAnC,CAFF,CADD;AAOA;;AAED,SAAO,cAAC,OAAD;AAAS,IAAA,SAAS,EAAGF;AAArB,KAAmCE,QAAnC,CAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { isEqual } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useDebounce, usePrevious } from '@wordpress/compose';\nimport { RawHTML, useEffect, useRef, useState } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport apiFetch from '@wordpress/api-fetch';\nimport { addQueryArgs } from '@wordpress/url';\nimport { Placeholder, Spinner } from '@wordpress/components';\nimport { __experimentalSanitizeBlockAttributes } from '@wordpress/blocks';\n\nexport function rendererPath( block, attributes = null, urlQueryArgs = {} ) {\n\treturn addQueryArgs( `/wp/v2/block-renderer/${ block }`, {\n\t\tcontext: 'edit',\n\t\t...( null !== attributes ? { attributes } : {} ),\n\t\t...urlQueryArgs,\n\t} );\n}\n\nfunction DefaultEmptyResponsePlaceholder( { className } ) {\n\treturn (\n\t\t<Placeholder className={ className }>\n\t\t\t{ __( 'Block rendered as empty.' ) }\n\t\t</Placeholder>\n\t);\n}\n\nfunction DefaultErrorResponsePlaceholder( { response, className } ) {\n\tconst errorMessage = sprintf(\n\t\t// translators: %s: error message describing the problem\n\t\t__( 'Error loading block: %s' ),\n\t\tresponse.errorMsg\n\t);\n\treturn <Placeholder className={ className }>{ errorMessage }</Placeholder>;\n}\n\nfunction DefaultLoadingResponsePlaceholder( { children, showLoader } ) {\n\treturn (\n\t\t<div style={ { position: 'relative' } }>\n\t\t\t{ showLoader && (\n\t\t\t\t<div\n\t\t\t\t\tstyle={ {\n\t\t\t\t\t\tposition: 'absolute',\n\t\t\t\t\t\ttop: '50%',\n\t\t\t\t\t\tleft: '50%',\n\t\t\t\t\t\tmarginTop: '-9px',\n\t\t\t\t\t\tmarginLeft: '-9px',\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t<Spinner />\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t<div style={ { opacity: showLoader ? '0.3' : 1 } }>\n\t\t\t\t{ children }\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n\nexport default function ServerSideRender( props ) {\n\tconst {\n\t\tattributes,\n\t\tblock,\n\t\tclassName,\n\t\thttpMethod = 'GET',\n\t\turlQueryArgs,\n\t\tEmptyResponsePlaceholder = DefaultEmptyResponsePlaceholder,\n\t\tErrorResponsePlaceholder = DefaultErrorResponsePlaceholder,\n\t\tLoadingResponsePlaceholder = DefaultLoadingResponsePlaceholder,\n\t} = props;\n\n\tconst isMountedRef = useRef( true );\n\tconst [ showLoader, setShowLoader ] = useState( false );\n\tconst fetchRequestRef = useRef();\n\tconst [ response, setResponse ] = useState( null );\n\tconst prevProps = usePrevious( props );\n\tconst [ isLoading, setIsLoading ] = useState( false );\n\n\tfunction fetchData() {\n\t\tif ( ! isMountedRef.current ) {\n\t\t\treturn;\n\t\t}\n\n\t\tsetIsLoading( true );\n\n\t\tconst sanitizedAttributes =\n\t\t\tattributes &&\n\t\t\t__experimentalSanitizeBlockAttributes( block, attributes );\n\n\t\t// If httpMethod is 'POST', send the attributes in the request body instead of the URL.\n\t\t// This allows sending a larger attributes object than in a GET request, where the attributes are in the URL.\n\t\tconst isPostRequest = 'POST' === httpMethod;\n\t\tconst urlAttributes = isPostRequest\n\t\t\t? null\n\t\t\t: sanitizedAttributes ?? null;\n\t\tconst path = rendererPath( block, urlAttributes, urlQueryArgs );\n\t\tconst data = isPostRequest\n\t\t\t? { attributes: sanitizedAttributes ?? null }\n\t\t\t: null;\n\n\t\t// Store the latest fetch request so that when we process it, we can\n\t\t// check if it is the current request, to avoid race conditions on slow networks.\n\t\tconst fetchRequest = ( fetchRequestRef.current = apiFetch( {\n\t\t\tpath,\n\t\t\tdata,\n\t\t\tmethod: isPostRequest ? 'POST' : 'GET',\n\t\t} )\n\t\t\t.then( ( fetchResponse ) => {\n\t\t\t\tif (\n\t\t\t\t\tisMountedRef.current &&\n\t\t\t\t\tfetchRequest === fetchRequestRef.current &&\n\t\t\t\t\tfetchResponse\n\t\t\t\t) {\n\t\t\t\t\tsetResponse( fetchResponse.rendered );\n\t\t\t\t}\n\t\t\t} )\n\t\t\t.catch( ( error ) => {\n\t\t\t\tif (\n\t\t\t\t\tisMountedRef.current &&\n\t\t\t\t\tfetchRequest === fetchRequestRef.current\n\t\t\t\t) {\n\t\t\t\t\tsetResponse( {\n\t\t\t\t\t\terror: true,\n\t\t\t\t\t\terrorMsg: error.message,\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t} )\n\t\t\t.finally( () => {\n\t\t\t\tif (\n\t\t\t\t\tisMountedRef.current &&\n\t\t\t\t\tfetchRequest === fetchRequestRef.current\n\t\t\t\t) {\n\t\t\t\t\tsetIsLoading( false );\n\t\t\t\t}\n\t\t\t} ) );\n\n\t\treturn fetchRequest;\n\t}\n\n\tconst debouncedFetchData = useDebounce( fetchData, 500 );\n\n\t// When the component unmounts, set isMountedRef to false. This will\n\t// let the async fetch callbacks know when to stop.\n\tuseEffect(\n\t\t() => () => {\n\t\t\tisMountedRef.current = false;\n\t\t},\n\t\t[]\n\t);\n\n\tuseEffect( () => {\n\t\t// Don't debounce the first fetch. This ensures that the first render\n\t\t// shows data as soon as possible\n\t\tif ( prevProps === undefined ) {\n\t\t\tfetchData();\n\t\t} else if ( ! isEqual( prevProps, props ) ) {\n\t\t\tdebouncedFetchData();\n\t\t}\n\t} );\n\n\t/**\n\t * Effect to handle showing the loading placeholder.\n\t * Show it only if there is no previous response or\n\t * the request takes more than one second.\n\t */\n\tuseEffect( () => {\n\t\tif ( ! isLoading ) {\n\t\t\treturn;\n\t\t}\n\t\tconst timeout = setTimeout( () => {\n\t\t\tsetShowLoader( true );\n\t\t}, 1000 );\n\t\treturn () => clearTimeout( timeout );\n\t}, [ isLoading ] );\n\n\tconst hasResponse = !! response;\n\tconst hasEmptyResponse = response === '';\n\tconst hasError = response?.error;\n\n\tif ( hasEmptyResponse || ! hasResponse ) {\n\t\treturn <EmptyResponsePlaceholder { ...props } />;\n\t}\n\n\tif ( hasError ) {\n\t\treturn <ErrorResponsePlaceholder response={ response } { ...props } />;\n\t}\n\n\tif ( isLoading ) {\n\t\treturn (\n\t\t\t<LoadingResponsePlaceholder { ...props } showLoader={ showLoader }>\n\t\t\t\t{ hasResponse && (\n\t\t\t\t\t<RawHTML className={ className }>{ response }</RawHTML>\n\t\t\t\t) }\n\t\t\t</LoadingResponsePlaceholder>\n\t\t);\n\t}\n\n\treturn <RawHTML className={ className }>{ response }</RawHTML>;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/server-side-render",
3
- "version": "3.0.5",
3
+ "version": "3.0.9",
4
4
  "description": "The component used with WordPress to server-side render a preview of dynamic blocks to display in the editor.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -26,20 +26,20 @@
26
26
  "module": "build-module/index.js",
27
27
  "react-native": "src/index",
28
28
  "dependencies": {
29
- "@babel/runtime": "^7.13.10",
30
- "@wordpress/api-fetch": "^5.2.5",
31
- "@wordpress/blocks": "^11.1.3",
32
- "@wordpress/components": "^19.0.1",
33
- "@wordpress/compose": "^5.0.5",
34
- "@wordpress/data": "^6.1.3",
35
- "@wordpress/deprecated": "^3.2.2",
36
- "@wordpress/element": "^4.0.3",
37
- "@wordpress/i18n": "^4.2.3",
38
- "@wordpress/url": "^3.3.0",
29
+ "@babel/runtime": "^7.16.0",
30
+ "@wordpress/api-fetch": "^5.2.6",
31
+ "@wordpress/blocks": "^11.1.4",
32
+ "@wordpress/components": "^19.0.5",
33
+ "@wordpress/compose": "^5.0.6",
34
+ "@wordpress/data": "^6.1.4",
35
+ "@wordpress/deprecated": "^3.2.3",
36
+ "@wordpress/element": "^4.0.4",
37
+ "@wordpress/i18n": "^4.2.4",
38
+ "@wordpress/url": "^3.3.1",
39
39
  "lodash": "^4.17.21"
40
40
  },
41
41
  "publishConfig": {
42
42
  "access": "public"
43
43
  },
44
- "gitHead": "393c2b5533837fd637e998d23f0124c081a10df0"
44
+ "gitHead": "518e7a279a0f596612232c55c83a351460f8816d"
45
45
  }