@wordpress/server-side-render 1.20.8-next.645224df70.0 → 1.20.10
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.
|
@@ -34,8 +34,6 @@ var _url = require("@wordpress/url");
|
|
|
34
34
|
|
|
35
35
|
var _components = require("@wordpress/components");
|
|
36
36
|
|
|
37
|
-
var _blocks = require("@wordpress/blocks");
|
|
38
|
-
|
|
39
37
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
|
|
40
38
|
|
|
41
39
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
|
@@ -112,15 +110,14 @@ var ServerSideRender = /*#__PURE__*/function (_Component) {
|
|
|
112
110
|
_props$httpMethod = props.httpMethod,
|
|
113
111
|
httpMethod = _props$httpMethod === void 0 ? 'GET' : _props$httpMethod,
|
|
114
112
|
_props$urlQueryArgs = props.urlQueryArgs,
|
|
115
|
-
urlQueryArgs = _props$urlQueryArgs === void 0 ? {} : _props$urlQueryArgs;
|
|
116
|
-
var sanitizedAttributes = attributes && (0, _blocks.__experimentalSanitizeBlockAttributes)(block, attributes); // If httpMethod is 'POST', send the attributes in the request body instead of the URL.
|
|
113
|
+
urlQueryArgs = _props$urlQueryArgs === void 0 ? {} : _props$urlQueryArgs; // If httpMethod is 'POST', send the attributes in the request body instead of the URL.
|
|
117
114
|
// This allows sending a larger attributes object than in a GET request, where the attributes are in the URL.
|
|
118
115
|
|
|
119
116
|
var isPostRequest = 'POST' === httpMethod;
|
|
120
|
-
var urlAttributes = isPostRequest ? null :
|
|
117
|
+
var urlAttributes = isPostRequest ? null : attributes;
|
|
121
118
|
var path = rendererPath(block, urlAttributes, urlQueryArgs);
|
|
122
119
|
var data = isPostRequest ? {
|
|
123
|
-
attributes:
|
|
120
|
+
attributes: attributes
|
|
124
121
|
} : null; // Store the latest fetch request so that when we process it, we can
|
|
125
122
|
// check if it is the current request, to avoid race conditions on slow networks.
|
|
126
123
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/server-side-render/src/server-side-render.js"],"names":["rendererPath","block","attributes","urlQueryArgs","context","ServerSideRender","props","state","response","isStillMounted","fetch","prevProps","setState","httpMethod","
|
|
1
|
+
{"version":3,"sources":["@wordpress/server-side-render/src/server-side-render.js"],"names":["rendererPath","block","attributes","urlQueryArgs","context","ServerSideRender","props","state","response","isStillMounted","fetch","prevProps","setState","httpMethod","isPostRequest","urlAttributes","path","data","fetchRequest","currentFetchRequest","method","then","rendered","catch","error","errorMsg","message","className","EmptyResponsePlaceholder","ErrorResponsePlaceholder","LoadingResponsePlaceholder","Component","defaultProps","errorMessage"],"mappings":";;;;;;;;;;AAQA;;;;;;;;;;;;;;;;AALA;;AAMA;;AACA;;AACA;;AACA;;;;;;;;;;AAEO,SAASA,YAAT,CAAuBC,KAAvB,EAAqE;AAAA,MAAvCC,UAAuC,uEAA1B,IAA0B;AAAA,MAApBC,YAAoB,uEAAL,EAAK;AAC3E,SAAO,uDAAwCF,KAAxC;AACNG,IAAAA,OAAO,EAAE;AADH,KAED,SAASF,UAAT,GAAsB;AAAEA,IAAAA,UAAU,EAAVA;AAAF,GAAtB,GAAuC,EAFtC,GAGHC,YAHG,EAAP;AAKA;;IAEYE,gB;;;;;AACZ,4BAAaC,KAAb,EAAqB;AAAA;;AAAA;AACpB,8BAAOA,KAAP;AACA,UAAKC,KAAL,GAAa;AACZC,MAAAA,QAAQ,EAAE;AADE,KAAb;AAFoB;AAKpB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;AAED,aACC,4BAAC,gBAAD;AAAS,QAAA,GAAG,EAAC,MAAb;AAAoB,QAAA,SAAS,EAAGqB;AAAhC,SACGnB,QADH,CADD;AAKA;;;EApHoCuB,kB;;;AAuHtC1B,gBAAgB,CAAC2B,YAAjB,GAAgC;AAC/BJ,EAAAA,wBAAwB,EAAE;AAAA,QAAID,SAAJ,QAAIA,SAAJ;AAAA,WACzB,4BAAC,uBAAD;AAAa,MAAA,SAAS,EAAGA;AAAzB,OACG,cAAI,0BAAJ,CADH,CADyB;AAAA,GADK;AAM/BE,EAAAA,wBAAwB,EAAE,yCAA+B;AAAA,QAA3BrB,QAA2B,SAA3BA,QAA2B;AAAA,QAAjBmB,SAAiB,SAAjBA,SAAiB;AACxD,QAAMM,YAAY,GAAG,oBACpB;AACA,kBAAI,yBAAJ,CAFoB,EAGpBzB,QAAQ,CAACiB,QAHW,CAArB;AAKA,WACC,4BAAC,uBAAD;AAAa,MAAA,SAAS,EAAGE;AAAzB,OAAuCM,YAAvC,CADD;AAGA,GAf8B;AAgB/BH,EAAAA,0BAA0B,EAAE,2CAAqB;AAAA,QAAjBH,SAAiB,SAAjBA,SAAiB;AAChD,WACC,4BAAC,uBAAD;AAAa,MAAA,SAAS,EAAGA;AAAzB,OACC,4BAAC,mBAAD,OADD,CADD;AAKA;AAtB8B,CAAhC;eAyBetB,gB","sourcesContent":["/**\n * External dependencies\n */\nimport { isEqual, debounce } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { Component, RawHTML } 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';\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\nexport class ServerSideRender extends Component {\n\tconstructor( props ) {\n\t\tsuper( props );\n\t\tthis.state = {\n\t\t\tresponse: null,\n\t\t};\n\t}\n\n\tcomponentDidMount() {\n\t\tthis.isStillMounted = true;\n\t\tthis.fetch( this.props );\n\t\t// Only debounce once the initial fetch occurs to ensure that the first\n\t\t// renders show data as soon as possible.\n\t\tthis.fetch = debounce( this.fetch, 500 );\n\t}\n\n\tcomponentWillUnmount() {\n\t\tthis.isStillMounted = false;\n\t}\n\n\tcomponentDidUpdate( prevProps ) {\n\t\tif ( ! isEqual( prevProps, this.props ) ) {\n\t\t\tthis.fetch( this.props );\n\t\t}\n\t}\n\n\tfetch( props ) {\n\t\tif ( ! this.isStillMounted ) {\n\t\t\treturn;\n\t\t}\n\t\tif ( null !== this.state.response ) {\n\t\t\tthis.setState( { response: null } );\n\t\t}\n\t\tconst {\n\t\t\tblock,\n\t\t\tattributes = null,\n\t\t\thttpMethod = 'GET',\n\t\t\turlQueryArgs = {},\n\t\t} = props;\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 ? null : attributes;\n\t\tconst path = rendererPath( block, urlAttributes, urlQueryArgs );\n\t\tconst data = isPostRequest ? { attributes } : 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 = ( this.currentFetchRequest = apiFetch( {\n\t\t\tpath,\n\t\t\tdata,\n\t\t\tmethod: isPostRequest ? 'POST' : 'GET',\n\t\t} )\n\t\t\t.then( ( response ) => {\n\t\t\t\tif (\n\t\t\t\t\tthis.isStillMounted &&\n\t\t\t\t\tfetchRequest === this.currentFetchRequest &&\n\t\t\t\t\tresponse\n\t\t\t\t) {\n\t\t\t\t\tthis.setState( { response: response.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\tthis.isStillMounted &&\n\t\t\t\t\tfetchRequest === this.currentFetchRequest\n\t\t\t\t) {\n\t\t\t\t\tthis.setState( {\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\terror: true,\n\t\t\t\t\t\t\terrorMsg: error.message,\n\t\t\t\t\t\t},\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t} ) );\n\t\treturn fetchRequest;\n\t}\n\n\trender() {\n\t\tconst response = this.state.response;\n\t\tconst {\n\t\t\tclassName,\n\t\t\tEmptyResponsePlaceholder,\n\t\t\tErrorResponsePlaceholder,\n\t\t\tLoadingResponsePlaceholder,\n\t\t} = this.props;\n\n\t\tif ( response === '' ) {\n\t\t\treturn (\n\t\t\t\t<EmptyResponsePlaceholder\n\t\t\t\t\tresponse={ response }\n\t\t\t\t\t{ ...this.props }\n\t\t\t\t/>\n\t\t\t);\n\t\t} else if ( ! response ) {\n\t\t\treturn (\n\t\t\t\t<LoadingResponsePlaceholder\n\t\t\t\t\tresponse={ response }\n\t\t\t\t\t{ ...this.props }\n\t\t\t\t/>\n\t\t\t);\n\t\t} else if ( response.error ) {\n\t\t\treturn (\n\t\t\t\t<ErrorResponsePlaceholder\n\t\t\t\t\tresponse={ response }\n\t\t\t\t\t{ ...this.props }\n\t\t\t\t/>\n\t\t\t);\n\t\t}\n\n\t\treturn (\n\t\t\t<RawHTML key=\"html\" className={ className }>\n\t\t\t\t{ response }\n\t\t\t</RawHTML>\n\t\t);\n\t}\n}\n\nServerSideRender.defaultProps = {\n\tEmptyResponsePlaceholder: ( { className } ) => (\n\t\t<Placeholder className={ className }>\n\t\t\t{ __( 'Block rendered as empty.' ) }\n\t\t</Placeholder>\n\t),\n\tErrorResponsePlaceholder: ( { response, className } ) => {\n\t\tconst errorMessage = sprintf(\n\t\t\t// translators: %s: error message describing the problem\n\t\t\t__( 'Error loading block: %s' ),\n\t\t\tresponse.errorMsg\n\t\t);\n\t\treturn (\n\t\t\t<Placeholder className={ className }>{ errorMessage }</Placeholder>\n\t\t);\n\t},\n\tLoadingResponsePlaceholder: ( { className } ) => {\n\t\treturn (\n\t\t\t<Placeholder className={ className }>\n\t\t\t\t<Spinner />\n\t\t\t</Placeholder>\n\t\t);\n\t},\n};\n\nexport default ServerSideRender;\n"]}
|
|
@@ -28,7 +28,6 @@ import { __, sprintf } from '@wordpress/i18n';
|
|
|
28
28
|
import apiFetch from '@wordpress/api-fetch';
|
|
29
29
|
import { addQueryArgs } from '@wordpress/url';
|
|
30
30
|
import { Placeholder, Spinner } from '@wordpress/components';
|
|
31
|
-
import { __experimentalSanitizeBlockAttributes } from '@wordpress/blocks';
|
|
32
31
|
export function rendererPath(block) {
|
|
33
32
|
var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
34
33
|
var urlQueryArgs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
@@ -97,17 +96,14 @@ export var ServerSideRender = /*#__PURE__*/function (_Component) {
|
|
|
97
96
|
_props$httpMethod = props.httpMethod,
|
|
98
97
|
httpMethod = _props$httpMethod === void 0 ? 'GET' : _props$httpMethod,
|
|
99
98
|
_props$urlQueryArgs = props.urlQueryArgs,
|
|
100
|
-
urlQueryArgs = _props$urlQueryArgs === void 0 ? {} : _props$urlQueryArgs;
|
|
101
|
-
|
|
102
|
-
var sanitizedAttributes = attributes && __experimentalSanitizeBlockAttributes(block, attributes); // If httpMethod is 'POST', send the attributes in the request body instead of the URL.
|
|
99
|
+
urlQueryArgs = _props$urlQueryArgs === void 0 ? {} : _props$urlQueryArgs; // If httpMethod is 'POST', send the attributes in the request body instead of the URL.
|
|
103
100
|
// This allows sending a larger attributes object than in a GET request, where the attributes are in the URL.
|
|
104
101
|
|
|
105
|
-
|
|
106
102
|
var isPostRequest = 'POST' === httpMethod;
|
|
107
|
-
var urlAttributes = isPostRequest ? null :
|
|
103
|
+
var urlAttributes = isPostRequest ? null : attributes;
|
|
108
104
|
var path = rendererPath(block, urlAttributes, urlQueryArgs);
|
|
109
105
|
var data = isPostRequest ? {
|
|
110
|
-
attributes:
|
|
106
|
+
attributes: attributes
|
|
111
107
|
} : null; // Store the latest fetch request so that when we process it, we can
|
|
112
108
|
// check if it is the current request, to avoid race conditions on slow networks.
|
|
113
109
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/server-side-render/src/server-side-render.js"],"names":["isEqual","debounce","Component","RawHTML","__","sprintf","apiFetch","addQueryArgs","Placeholder","Spinner","
|
|
1
|
+
{"version":3,"sources":["@wordpress/server-side-render/src/server-side-render.js"],"names":["isEqual","debounce","Component","RawHTML","__","sprintf","apiFetch","addQueryArgs","Placeholder","Spinner","rendererPath","block","attributes","urlQueryArgs","context","ServerSideRender","props","state","response","isStillMounted","fetch","prevProps","setState","httpMethod","isPostRequest","urlAttributes","path","data","fetchRequest","currentFetchRequest","method","then","rendered","catch","error","errorMsg","message","className","EmptyResponsePlaceholder","ErrorResponsePlaceholder","LoadingResponsePlaceholder","defaultProps","errorMessage"],"mappings":";;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA,SAASA,OAAT,EAAkBC,QAAlB,QAAkC,QAAlC;AAEA;AACA;AACA;;AACA,SAASC,SAAT,EAAoBC,OAApB,QAAmC,oBAAnC;AACA,SAASC,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,OAAOC,QAAP,MAAqB,sBAArB;AACA,SAASC,YAAT,QAA6B,gBAA7B;AACA,SAASC,WAAT,EAAsBC,OAAtB,QAAqC,uBAArC;AAEA,OAAO,SAASC,YAAT,CAAuBC,KAAvB,EAAqE;AAAA,MAAvCC,UAAuC,uEAA1B,IAA0B;AAAA,MAApBC,YAAoB,uEAAL,EAAK;AAC3E,SAAON,YAAY,iCAA4BI,KAA5B;AAClBG,IAAAA,OAAO,EAAE;AADS,KAEb,SAASF,UAAT,GAAsB;AAAEA,IAAAA,UAAU,EAAVA;AAAF,GAAtB,GAAuC,EAF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port { isEqual, debounce } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { Component, RawHTML } 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';\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\nexport class ServerSideRender extends Component {\n\tconstructor( props ) {\n\t\tsuper( props );\n\t\tthis.state = {\n\t\t\tresponse: null,\n\t\t};\n\t}\n\n\tcomponentDidMount() {\n\t\tthis.isStillMounted = true;\n\t\tthis.fetch( this.props );\n\t\t// Only debounce once the initial fetch occurs to ensure that the first\n\t\t// renders show data as soon as possible.\n\t\tthis.fetch = debounce( this.fetch, 500 );\n\t}\n\n\tcomponentWillUnmount() {\n\t\tthis.isStillMounted = false;\n\t}\n\n\tcomponentDidUpdate( prevProps ) {\n\t\tif ( ! isEqual( prevProps, this.props ) ) {\n\t\t\tthis.fetch( this.props );\n\t\t}\n\t}\n\n\tfetch( props ) {\n\t\tif ( ! this.isStillMounted ) {\n\t\t\treturn;\n\t\t}\n\t\tif ( null !== this.state.response ) {\n\t\t\tthis.setState( { response: null } );\n\t\t}\n\t\tconst {\n\t\t\tblock,\n\t\t\tattributes = null,\n\t\t\thttpMethod = 'GET',\n\t\t\turlQueryArgs = {},\n\t\t} = props;\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 ? null : attributes;\n\t\tconst path = rendererPath( block, urlAttributes, urlQueryArgs );\n\t\tconst data = isPostRequest ? { attributes } : 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 = ( this.currentFetchRequest = apiFetch( {\n\t\t\tpath,\n\t\t\tdata,\n\t\t\tmethod: isPostRequest ? 'POST' : 'GET',\n\t\t} )\n\t\t\t.then( ( response ) => {\n\t\t\t\tif (\n\t\t\t\t\tthis.isStillMounted &&\n\t\t\t\t\tfetchRequest === this.currentFetchRequest &&\n\t\t\t\t\tresponse\n\t\t\t\t) {\n\t\t\t\t\tthis.setState( { response: response.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\tthis.isStillMounted &&\n\t\t\t\t\tfetchRequest === this.currentFetchRequest\n\t\t\t\t) {\n\t\t\t\t\tthis.setState( {\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\terror: true,\n\t\t\t\t\t\t\terrorMsg: error.message,\n\t\t\t\t\t\t},\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t} ) );\n\t\treturn fetchRequest;\n\t}\n\n\trender() {\n\t\tconst response = this.state.response;\n\t\tconst {\n\t\t\tclassName,\n\t\t\tEmptyResponsePlaceholder,\n\t\t\tErrorResponsePlaceholder,\n\t\t\tLoadingResponsePlaceholder,\n\t\t} = this.props;\n\n\t\tif ( response === '' ) {\n\t\t\treturn (\n\t\t\t\t<EmptyResponsePlaceholder\n\t\t\t\t\tresponse={ response }\n\t\t\t\t\t{ ...this.props }\n\t\t\t\t/>\n\t\t\t);\n\t\t} else if ( ! response ) {\n\t\t\treturn (\n\t\t\t\t<LoadingResponsePlaceholder\n\t\t\t\t\tresponse={ response }\n\t\t\t\t\t{ ...this.props }\n\t\t\t\t/>\n\t\t\t);\n\t\t} else if ( response.error ) {\n\t\t\treturn (\n\t\t\t\t<ErrorResponsePlaceholder\n\t\t\t\t\tresponse={ response }\n\t\t\t\t\t{ ...this.props }\n\t\t\t\t/>\n\t\t\t);\n\t\t}\n\n\t\treturn (\n\t\t\t<RawHTML key=\"html\" className={ className }>\n\t\t\t\t{ response }\n\t\t\t</RawHTML>\n\t\t);\n\t}\n}\n\nServerSideRender.defaultProps = {\n\tEmptyResponsePlaceholder: ( { className } ) => (\n\t\t<Placeholder className={ className }>\n\t\t\t{ __( 'Block rendered as empty.' ) }\n\t\t</Placeholder>\n\t),\n\tErrorResponsePlaceholder: ( { response, className } ) => {\n\t\tconst errorMessage = sprintf(\n\t\t\t// translators: %s: error message describing the problem\n\t\t\t__( 'Error loading block: %s' ),\n\t\t\tresponse.errorMsg\n\t\t);\n\t\treturn (\n\t\t\t<Placeholder className={ className }>{ errorMessage }</Placeholder>\n\t\t);\n\t},\n\tLoadingResponsePlaceholder: ( { className } ) => {\n\t\treturn (\n\t\t\t<Placeholder className={ className }>\n\t\t\t\t<Spinner />\n\t\t\t</Placeholder>\n\t\t);\n\t},\n};\n\nexport default ServerSideRender;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/server-side-render",
|
|
3
|
-
"version": "1.20.
|
|
3
|
+
"version": "1.20.10",
|
|
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",
|
|
@@ -24,18 +24,17 @@
|
|
|
24
24
|
"react-native": "src/index",
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@babel/runtime": "^7.12.5",
|
|
27
|
-
"@wordpress/api-fetch": "^3.21.6
|
|
28
|
-
"@wordpress/
|
|
29
|
-
"@wordpress/
|
|
30
|
-
"@wordpress/
|
|
31
|
-
"@wordpress/
|
|
32
|
-
"@wordpress/
|
|
33
|
-
"@wordpress/
|
|
34
|
-
"@wordpress/url": "^2.21.3-next.645224df70.0",
|
|
27
|
+
"@wordpress/api-fetch": "^3.21.6",
|
|
28
|
+
"@wordpress/components": "^12.0.9",
|
|
29
|
+
"@wordpress/data": "^4.26.9",
|
|
30
|
+
"@wordpress/deprecated": "^2.11.1",
|
|
31
|
+
"@wordpress/element": "^2.19.1",
|
|
32
|
+
"@wordpress/i18n": "^3.18.0",
|
|
33
|
+
"@wordpress/url": "^2.21.3",
|
|
35
34
|
"lodash": "^4.17.19"
|
|
36
35
|
},
|
|
37
36
|
"publishConfig": {
|
|
38
37
|
"access": "public"
|
|
39
38
|
},
|
|
40
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "14a64efc7cf32f4d37400902a7c1cbb822bc5c2f"
|
|
41
40
|
}
|
|
@@ -11,7 +11,6 @@ import { __, sprintf } from '@wordpress/i18n';
|
|
|
11
11
|
import apiFetch from '@wordpress/api-fetch';
|
|
12
12
|
import { addQueryArgs } from '@wordpress/url';
|
|
13
13
|
import { Placeholder, Spinner } from '@wordpress/components';
|
|
14
|
-
import { __experimentalSanitizeBlockAttributes } from '@wordpress/blocks';
|
|
15
14
|
|
|
16
15
|
export function rendererPath( block, attributes = null, urlQueryArgs = {} ) {
|
|
17
16
|
return addQueryArgs( `/wp/v2/block-renderer/${ block }`, {
|
|
@@ -61,16 +60,12 @@ export class ServerSideRender extends Component {
|
|
|
61
60
|
urlQueryArgs = {},
|
|
62
61
|
} = props;
|
|
63
62
|
|
|
64
|
-
const sanitizedAttributes =
|
|
65
|
-
attributes &&
|
|
66
|
-
__experimentalSanitizeBlockAttributes( block, attributes );
|
|
67
|
-
|
|
68
63
|
// If httpMethod is 'POST', send the attributes in the request body instead of the URL.
|
|
69
64
|
// This allows sending a larger attributes object than in a GET request, where the attributes are in the URL.
|
|
70
65
|
const isPostRequest = 'POST' === httpMethod;
|
|
71
|
-
const urlAttributes = isPostRequest ? null :
|
|
66
|
+
const urlAttributes = isPostRequest ? null : attributes;
|
|
72
67
|
const path = rendererPath( block, urlAttributes, urlQueryArgs );
|
|
73
|
-
const data = isPostRequest ? { attributes
|
|
68
|
+
const data = isPostRequest ? { attributes } : null;
|
|
74
69
|
|
|
75
70
|
// Store the latest fetch request so that when we process it, we can
|
|
76
71
|
// check if it is the current request, to avoid race conditions on slow networks.
|