: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
if (this._instance !== instance) {
this._instance = instance;
this.onChangeInstance(instance);
* Whether or not the widget can be previewed.
* Whether or not the widget can be previewed.
set hasPreview(hasPreview) {
if (this._hasPreview !== hasPreview) {
this._hasPreview = hasPreview;
this.onChangeHasPreview(hasPreview);
function el(tagName, attributes = {}, content = null) {
const element = document.createElement(tagName);
for (const [attribute, value] of Object.entries(attributes)) {
element.setAttribute(attribute, value);
if (Array.isArray(content)) {
for (const child of content) {
element.appendChild(child);
} else if (typeof content === 'string') {
element.innerText = content;
async function saveWidget(id, formData = null) {
widget = await external_wp_apiFetch_default()({
path: `/wp/v2/widgets/${id}?context=edit`,
widget = await external_wp_apiFetch_default()({
path: `/wp/v2/widgets/${id}?context=edit`,
form: widget.rendered_form
async function encodeWidget({
const response = await external_wp_apiFetch_default()({
path: `/wp/v2/widget-types/${idBase}/encode`,
instance: response.instance,
preview: response.preview
function isEmptyHTML(html) {
const element = document.createElement('div');
element.innerHTML = html;
return isEmptyNode(element);
function isEmptyNode(node) {
// Text nodes are empty if it's entirely whitespace.
return node.nodeValue.trim() === '';
// Elements that are "embedded content" are not empty.
// https://dev.w3.org/html5/spec-LC/content-models.html#embedded-content-0
if (['AUDIO', 'CANVAS', 'EMBED', 'IFRAME', 'IMG', 'MATH', 'OBJECT', 'SVG', 'VIDEO'].includes(node.tagName)) {
// Elements with no children are empty.
if (!node.hasChildNodes()) {
// Elements with children are empty if all their children are empty.
return Array.from(node.childNodes).every(isEmptyNode);
function serializeForm(form) {
return new window.URLSearchParams(Array.from(new window.FormData(form))).toString();
;// CONCATENATED MODULE: ./node_modules/@wordpress/widgets/build-module/blocks/legacy-widget/edit/form.js
const ref = (0,external_wp_element_namespaceObject.useRef)();
const isMediumLargeViewport = (0,external_wp_compose_namespaceObject.useViewportMatch)('small');
// We only want to remount the control when the instance changes
// *externally*. For example, if the user performs an undo. To do this, we
// keep track of changes made to instance by the control itself and then
const outgoingInstances = (0,external_wp_element_namespaceObject.useRef)(new Set());
const incomingInstances = (0,external_wp_element_namespaceObject.useRef)(new Set());
} = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_notices_namespaceObject.store);
(0,external_wp_element_namespaceObject.useEffect)(() => {
if (incomingInstances.current.has(instance)) {
incomingInstances.current.delete(instance);
const control = new Control({
onChangeInstance(nextInstance) {
outgoingInstances.current.add(instance);
incomingInstances.current.add(nextInstance);
onChangeInstance(nextInstance);
window.console.error(error);
createNotice('error', (0,external_wp_i18n_namespaceObject.sprintf)( /* translators: %s: the name of the affected block. */
(0,external_wp_i18n_namespaceObject.__)('The "%s" block was affected by errors and may not function properly. Check the developer tools for more details.'), idBase || id));
ref.current.appendChild(control.element);
if (outgoingInstances.current.has(instance)) {
outgoingInstances.current.delete(instance);
}, [id, idBase, instance, onChangeInstance, onChangeHasPreview, isMediumLargeViewport]);
if (isWide && isMediumLargeViewport) {
return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)("div", {
'wp-block-legacy-widget__container': isVisible
children: [isVisible && /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("h3", {
className: "wp-block-legacy-widget__edit-form-title",
}), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Popover, {
children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("div", {
className: "wp-block-legacy-widget__edit-form",
return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("div", {
className: "wp-block-legacy-widget__edit-form",
children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("h3", {
className: "wp-block-legacy-widget__edit-form-title",
;// CONCATENATED MODULE: ./node_modules/@wordpress/widgets/build-module/blocks/legacy-widget/edit/preview.js
const [isLoaded, setIsLoaded] = (0,external_wp_element_namespaceObject.useState)(false);
const [srcDoc, setSrcDoc] = (0,external_wp_element_namespaceObject.useState)('');
(0,external_wp_element_namespaceObject.useEffect)(() => {
const abortController = typeof window.AbortController === 'undefined' ? undefined : new window.AbortController();
async function fetchPreviewHTML() {
const restRoute = `/wp/v2/widget-types/${idBase}/render`;
return await external_wp_apiFetch_default()({
signal: abortController?.signal,
fetchPreviewHTML().then(response => {
setSrcDoc(response.preview);
if ('AbortError' === error.name) {
// We don't want to log aborted requests.
return () => abortController?.abort();
// Resize the iframe on either the load event, or when the iframe becomes visible.
const ref = (0,external_wp_compose_namespaceObject.useRefEffect)(iframe => {
// Only set height if the iframe is loaded,
// or it will grow to an unexpected large height in Safari if it's hidden initially.
// If the preview frame has another origin then this won't work.
// One possible solution is to add custom script to call `postMessage` in the preview frame.
// Or, better yet, we migrate away from iframe.
var _iframe$contentDocume, _iframe$contentDocume2;
// Pick the maximum of these two values to account for margin collapsing.
const height = Math.max((_iframe$contentDocume = iframe.contentDocument.documentElement?.offsetHeight) !== null && _iframe$contentDocume !== void 0 ? _iframe$contentDocume : 0, (_iframe$contentDocume2 = iframe.contentDocument.body?.offsetHeight) !== null && _iframe$contentDocume2 !== void 0 ? _iframe$contentDocume2 : 0);
// Fallback to a height of 100px if the height cannot be determined.
// This ensures the block is still selectable. 100px should hopefully
// be not so big that it's annoying, and not so small that nothing
iframe.style.height = `${height !== 0 ? height : 100}px`;
} = iframe.ownerDocument.defaultView;
// Observe for intersections that might cause a change in the height of
// the iframe, e.g. a Widget Area becoming expanded.
const intersectionObserver = new IntersectionObserver(([entry]) => {
if (entry.isIntersecting) {
intersectionObserver.observe(iframe);
iframe.addEventListener('load', setHeight);
intersectionObserver.disconnect();
iframe.removeEventListener('load', setHeight);
return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_ReactJSXRuntime_namespaceObject.Fragment, {
children: [isVisible && !isLoaded && /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Placeholder, {
children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Spinner, {})
}), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("div", {
className: dist_clsx('wp-block-legacy-widget__edit-preview', {
'is-offscreen': !isVisible || !isLoaded
children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Disabled, {
children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("iframe", {
className: "wp-block-legacy-widget__edit-preview-iframe",
title: (0,external_wp_i18n_namespaceObject.__)('Legacy Widget Preview'),
// To hide the scrollbars of the preview frame for some edge cases,
// such as negative margins in the Gallery Legacy Widget.
// It can't be scrolled anyway.
// TODO: Ideally, this should be fixed in core.
event.target.contentDocument.body.style.overflow = 'hidden';
;// CONCATENATED MODULE: ./node_modules/@wordpress/widgets/build-module/blocks/legacy-widget/edit/no-preview.js
return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)("div", {
className: "wp-block-legacy-widget__edit-no-preview",
children: [name && /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("h3", {
}), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("p", {
children: (0,external_wp_i18n_namespaceObject.__)('No preview available.')
;// CONCATENATED MODULE: ./node_modules/@wordpress/widgets/build-module/blocks/legacy-widget/edit/convert-to-blocks-button.js
function ConvertToBlocksButton({
} = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_blockEditor_namespaceObject.store);
return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.ToolbarButton, {
replaceBlocks(clientId, [(0,external_wp_blocks_namespaceObject.createBlock)('core/heading', {
content: rawInstance.title
}), ...(0,external_wp_blocks_namespaceObject.rawHandler)({
replaceBlocks(clientId, (0,external_wp_blocks_namespaceObject.rawHandler)({
children: (0,external_wp_i18n_namespaceObject.__)('Convert to blocks')
;// CONCATENATED MODULE: ./node_modules/@wordpress/widgets/build-module/blocks/legacy-widget/edit/index.js
const blockProps = (0,external_wp_blockEditor_namespaceObject.useBlockProps)({
return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("div", {
children: !id && !idBase ? /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(Empty, {
}) : /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(NotEmpty, {
return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Placeholder, {
icon: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.BlockIcon, {
label: (0,external_wp_i18n_namespaceObject.__)('Legacy Widget'),
children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Flex, {
children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.FlexBlock, {
children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(WidgetTypeSelector, {
selectedId: id !== null && id !== void 0 ? id : idBase,