+ * element) that is compatible with most third party widget scripts. By not
+ * using React for this, we ensure that we have complete contorl over the DOM
+ * and do not accidentally remove any elements that a third party widget script
+ * has attached an event listener to.
+ *
+ * @property {Element} element The control's DOM element.
+ */
+
+class control_Control {
+ /**
+ * Creates and loads a new control.
+ *
+ * @access public
+ * @param {Object} params
+ * @param {string} params.id
+ * @param {string} params.idBase
+ * @param {Object} params.instance
+ * @param {Function} params.onChangeInstance
+ * @param {Function} params.onChangeHasPreview
+ * @param {Function} params.onError
+ */
+ constructor({
+ id,
+ idBase,
+ instance,
+ onChangeInstance,
+ onChangeHasPreview,
+ onError
+ }) {
+ this.id = id;
+ this.idBase = idBase;
+ this._instance = instance;
+ this._hasPreview = null;
+ this.onChangeInstance = onChangeInstance;
+ this.onChangeHasPreview = onChangeHasPreview;
+ this.onError = onError; // We can't use the real widget number as this is calculated by the
+ // server and we may not ever *actually* save this widget. Instead, use
+ // a fake but unique number.
+
+ this.number = ++lastNumber;
+ this.handleFormChange = Object(external_lodash_["debounce"])(this.saveForm.bind(this), 200);
+ this.handleFormSubmit = this.handleFormSubmit.bind(this);
+ this.initDOM();
+ this.bindEvents();
+ this.loadContent();
+ }
+ /**
+ * Clean up the control so that it can be garabge collected.
+ *
+ * @access public
+ */
+
+
+ destroy() {
+ this.unbindEvents();
+ this.element.remove(); // TODO: How do we make third party widget scripts remove their event
+ // listeners?
+ }
+ /**
+ * Creates the control's DOM structure.
+ *
+ * @access private
+ */
+
+
+ initDOM() {
+ var _this$id, _this$idBase;
+
+ this.element = el('div', {
+ class: 'widget open'
+ }, [el('div', {
+ class: 'widget-inside'
+ }, [this.form = el('form', {
+ class: 'form',
+ method: 'post'
+ }, [// These hidden form inputs are what most widgets' scripts
+ // use to access data about the widget.
+ el('input', {
+ class: 'widget-id',
+ type: 'hidden',
+ name: 'widget-id',
+ value: (_this$id = this.id) !== null && _this$id !== void 0 ? _this$id : `${this.idBase}-${this.number}`
+ }), el('input', {
+ class: 'id_base',
+ type: 'hidden',
+ name: 'id_base',
+ value: (_this$idBase = this.idBase) !== null && _this$idBase !== void 0 ? _this$idBase : this.id
+ }), el('input', {
+ class: 'widget-width',
+ type: 'hidden',
+ name: 'widget-width',
+ value: '250'
+ }), el('input', {
+ class: 'widget-height',
+ type: 'hidden',
+ name: 'widget-height',
+ value: '200'
+ }), el('input', {
+ class: 'widget_number',
+ type: 'hidden',
+ name: 'widget_number',
+ value: this.idBase ? this.number.toString() : ''
+ }), this.content = el('div', {
+ class: 'widget-content'
+ }), // Non-multi widgets can be saved via a Save button.
+ this.id && el('button', {
+ class: 'button is-primary',
+ type: 'submit'
+ }, Object(external_wp_i18n_["__"])('Save'))])])]);
+ }
+ /**
+ * Adds the control's event listeners.
+ *
+ * @access private
+ */
+
+
+ bindEvents() {
+ // Prefer jQuery 'change' event instead of the native 'change' event
+ // because many widgets use jQuery's event bus to trigger an update.
+ if (window.jQuery) {
+ const {
+ jQuery: $
+ } = window;
+ $(this.form).on('change', null, this.handleFormChange);
+ $(this.form).on('input', null, this.handleFormChange);
+ $(this.form).on('submit', this.handleFormSubmit);
+ } else {
+ this.form.addEventListener('change', this.handleFormChange);
+ this.form.addEventListener('input', this.handleFormChange);
+ this.form.addEventListener('submit', this.handleFormSubmit);
+ }
+ }
+ /**
+ * Removes the control's event listeners.
+ *
+ * @access private
+ */
+
+
+ unbindEvents() {
+ if (window.jQuery) {
+ const {
+ jQuery: $
+ } = window;
+ $(this.form).off('change', null, this.handleFormChange);
+ $(this.form).off('input', null, this.handleFormChange);
+ $(this.form).off('submit', this.handleFormSubmit);
+ } else {
+ this.form.removeEventListener('change', this.handleFormChange);
+ this.form.removeEventListener('input', this.handleFormChange);
+ this.form.removeEventListener('submit', this.handleFormSubmit);
+ }
+ }
+ /**
+ * Fetches the widget's form HTML from the REST API and loads it into the
+ * control's form.
+ *
+ * @access private
+ */
+
+
+ async loadContent() {
+ try {
+ if (this.id) {
+ const {
+ form
+ } = await saveWidget(this.id);
+ this.content.innerHTML = form;
+ } else if (this.idBase) {
+ const {
+ form,
+ preview
+ } = await encodeWidget({
+ idBase: this.idBase,
+ instance: this.instance,
+ number: this.number
+ });
+ this.content.innerHTML = form;
+ this.hasPreview = !isEmptyHTML(preview); // If we don't have an instance, perform a save right away. This
+ // happens when creating a new Legacy Widget block.
+
+ if (!this.instance.hash) {
+ const {
+ instance
+ } = await encodeWidget({
+ idBase: this.idBase,
+ instance: this.instance,
+ number: this.number,
+ formData: serializeForm(this.form)
+ });
+ this.instance = instance;
+ }
+ } // Trigger 'widget-added' when widget is ready. This event is what
+ // widgets' scripts use to initialize, attach events, etc. The event
+ // must be fired using jQuery's event bus as this is what widget
+ // scripts expect. If jQuery is not loaded, do nothing - some
+ // widgets will still work regardless.
+
+
+ if (window.jQuery) {
+ const {
+ jQuery: $
+ } = window;
+ $(document).trigger('widget-added', [$(this.element)]);
+ }
+ } catch (error) {
+ this.onError(error);
+ }
+ }
+ /**
+ * Perform a save when the control's form is manually submitted.
+ *
+ * @access private
+ * @param {Event} event
+ */
+
+
+ handleFormSubmit(event) {
+ event.preventDefault();
+ this.saveForm();
+ }
+ /**
+ * Serialize the control's form, send it to the REST API, and update the
+ * instance with the encoded instance that the REST API returns.
+ *
+ * @access private
+ */
+
+
+ async saveForm() {
+ const formData = serializeForm(this.form);
+
+ try {
+ if (this.id) {
+ const {
+ form
+ } = await saveWidget(this.id, formData);
+ this.content.innerHTML = form;
+
+ if (window.jQuery) {
+ const {
+ jQuery: $
+ } = window;
+ $(document).trigger('widget-updated', [$(this.element)]);
+ }
+ } else if (this.idBase) {
+ const {
+ instance,
+ preview
+ } = await encodeWidget({
+ idBase: this.idBase,
+ instance: this.instance,
+ number: this.number,
+ formData
+ });
+ this.instance = instance;
+ this.hasPreview = !isEmptyHTML(preview);
+ }
+ } catch (error) {
+ this.onError(error);
+ }
+ }
+ /**
+ * The widget's instance object.
+ *
+ * @access private
+ */
+
+
+ get instance() {
+ return this._instance;
+ }
+ /**
+ * The widget's instance object.
+ *
+ * @access private
+ */
+
+
+ set instance(instance) {
+ if (this._instance !== instance) {
+ this._instance = instance;
+ this.onChangeInstance(instance);
+ }
+ }
+ /**
+ * Whether or not the widget can be previewed.
+ *
+ * @access public
+ */
+
+
+ get hasPreview() {
+ return this._hasPreview;
+ }
+ /**
+ * Whether or not the widget can be previewed.
+ *
+ * @access private
+ */
+
+
+ set hasPreview(hasPreview) {
+ if (this._hasPreview !== hasPreview) {
+ this._hasPreview = hasPreview;
+ this.onChangeHasPreview(hasPreview);
+ }
+ }
+
+}
+let lastNumber = 0;
+
+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) {
+ if (child) {
+ element.appendChild(child);
+ }
+ }
+ } else if (typeof content === 'string') {
+ element.innerText = content;
+ }
+
+ return element;
+}
+
+async function saveWidget(id, formData = null) {
+ let widget;
+
+ if (formData) {
+ widget = await external_wp_apiFetch_default()({
+ path: `/wp/v2/widgets/${id}?context=edit`,
+ method: 'PUT',
+ data: {
+ form_data: formData
+ }
+ });
+ } else {
+ widget = await external_wp_apiFetch_default()({
+ path: `/wp/v2/widgets/${id}?context=edit`,
+ method: 'GET'
+ });
+ }
+
+ return {
+ form: widget.rendered_form
+ };
+}
+
+async function encodeWidget({
+ idBase,
+ instance,
+ number,
+ formData = null
+}) {
+ const response = await external_wp_apiFetch_default()({
+ path: `/wp/v2/widget-types/${idBase}/encode`,
+ method: 'POST',
+ data: {
+ instance,
+ number,
+ form_data: formData
+ }
+ });
+ return {
+ instance: response.instance,
+ form: response.form,
+ preview: response.preview
+ };
+}
+
+function isEmptyHTML(html) {
+ const element = document.createElement('div');
+ element.innerHTML = html;
+ return element.innerText.trim() === '';
+}
+
+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
+
+
+/**
+ * External dependencies
+ */
+
+/**
+ * WordPress dependencies
+ */
+
+
+
+
+
+
+
+/**
+ * Internal dependencies
+ */
+
+
+function Form({
+ title,
+ isVisible,
+ id,
+ idBase,
+ instance,
+ isWide,
+ onChangeInstance,
+ onChangeHasPreview
+}) {
+ const ref = Object(external_wp_element_["useRef"])();
+ const isMediumLargeViewport = Object(external_wp_compose_["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
+ // ignore those.
+
+ const outgoingInstances = Object(external_wp_element_["useRef"])(new Set());
+ const incomingInstances = Object(external_wp_element_["useRef"])(new Set());
+ const {
+ createNotice
+ } = Object(external_wp_data_["useDispatch"])(external_wp_notices_["store"]);
+ Object(external_wp_element_["useEffect"])(() => {
+ if (incomingInstances.current.has(instance)) {
+ incomingInstances.current.delete(instance);
+ return;
+ }
+
+ const control = new control_Control({
+ id,
+ idBase,
+ instance,
+
+ onChangeInstance(nextInstance) {
+ outgoingInstances.current.add(instance);
+ incomingInstances.current.add(nextInstance);
+ onChangeInstance(nextInstance);
+ },
+
+ onChangeHasPreview,
+
+ onError(error) {
+ var _error$message;
+
+ createNotice('error', (_error$message = error === null || error === void 0 ? void 0 : error.message) !== null && _error$message !== void 0 ? _error$message : Object(external_wp_i18n_["__"])('An error occured while fetching or updating the widget.'));
+ }
+
+ });
+ ref.current.appendChild(control.element);
+ return () => {
+ if (outgoingInstances.current.has(instance)) {
+ outgoingInstances.current.delete(instance);
+ return;
+ }
+
+ control.destroy();
+ };
+ }, [id, idBase, instance, onChangeInstance, onChangeHasPreview, isMediumLargeViewport]);
+
+ if (isWide && isMediumLargeViewport) {
+ return Object(external_wp_element_["createElement"])("div", {
+ className: classnames_default()({
+ 'wp-block-legacy-widget__container': isVisible
+ })
+ }, isVisible && Object(external_wp_element_["createElement"])("h3", {
+ className: "wp-block-legacy-widget__edit-form-title"
+ }, title), Object(external_wp_element_["createElement"])(external_wp_components_["Popover"], {
+ focusOnMount: false,
+ position: "middle right",
+ __unstableForceXAlignment: true
+ }, Object(external_wp_element_["createElement"])("div", {
+ ref: ref,
+ className: "wp-block-legacy-widget__edit-form",
+ hidden: !isVisible
+ })));
+ }
+
+ return Object(external_wp_element_["createElement"])("div", {
+ ref: ref,
+ className: "wp-block-legacy-widget__edit-form",
+ hidden: !isVisible
+ }, Object(external_wp_element_["createElement"])("h3", {
+ className: "wp-block-legacy-widget__edit-form-title"
+ }, title));
+}
+
+// EXTERNAL MODULE: external ["wp","url"]
+var external_wp_url_ = __webpack_require__("Mmq9");
+
+// CONCATENATED MODULE: ./node_modules/@wordpress/widgets/build-module/blocks/legacy-widget/edit/preview.js
+
+
+/**
+ * External dependencies
+ */
+
+/**
+ * WordPress dependencies
+ */
+
+
+
+
+
+
+function Preview({
+ idBase,
+ instance,
+ isVisible
+}) {
+ const [iframeHeight, setIframeHeight] = Object(external_wp_element_["useState"])(); // Resize the iframe on either the load event, or when the iframe becomes visible.
+
+ const ref = Object(external_wp_compose_["useRefEffect"])(iframe => {
+ function onChange() {
+ var _iframe$contentDocume, _iframe$contentDocume2;
+
+ const boundingRect = iframe === null || iframe === void 0 ? void 0 : (_iframe$contentDocume = iframe.contentDocument) === null || _iframe$contentDocume === void 0 ? void 0 : (_iframe$contentDocume2 = _iframe$contentDocume.body) === null || _iframe$contentDocume2 === void 0 ? void 0 : _iframe$contentDocume2.getBoundingClientRect();
+
+ if (boundingRect) {
+ // Include `top` in the height calculation to avoid the bottom
+ // of widget previews being cut-off. Most widgets have a
+ // heading at the top that has top margin, and the `height`
+ // alone doesn't take that margin into account.
+ setIframeHeight(boundingRect.top + boundingRect.height);
+ }
+ }
+
+ const {
+ IntersectionObserver
+ } = 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(onChange, {
+ threshold: 1
+ });
+ intersectionObserver.observe(iframe);
+ iframe.addEventListener('load', onChange);
+ return () => {
+ iframe.removeEventListener('load', onChange);
+ };
+ }, []);
+ return Object(external_wp_element_["createElement"])(external_wp_element_["Fragment"], null, isVisible && iframeHeight === null && Object(external_wp_element_["createElement"])(external_wp_components_["Placeholder"], null, Object(external_wp_element_["createElement"])(external_wp_components_["Spinner"], null)), Object(external_wp_element_["createElement"])("div", {
+ className: classnames_default()('wp-block-legacy-widget__edit-preview', {
+ 'is-offscreen': !isVisible || iframeHeight === null
+ })
+ }, Object(external_wp_element_["createElement"])(external_wp_components_["Disabled"], null, Object(external_wp_element_["createElement"])("iframe", {
+ ref: ref,
+ className: "wp-block-legacy-widget__edit-preview-iframe",
+ title: Object(external_wp_i18n_["__"])('Legacy Widget Preview') // TODO: This chokes when the query param is too big.
+ // Ideally, we'd render a
. Maybe by
+ // rendering one in an iframe via a portal.
+ ,
+ src: Object(external_wp_url_["addQueryArgs"])('widgets.php', {
+ 'legacy-widget-preview': {
+ idBase,
+ instance
+ }
+ }),
+ height: iframeHeight || 100
+ }))));
+}
+
+// CONCATENATED MODULE: ./node_modules/@wordpress/widgets/build-module/blocks/legacy-widget/edit/no-preview.js
+
+
+/**
+ * WordPress dependencies
+ */
+
+function NoPreview({
+ name
+}) {
+ return Object(external_wp_element_["createElement"])("div", {
+ className: "wp-block-legacy-widget__edit-no-preview"
+ }, name && Object(external_wp_element_["createElement"])("h3", null, name), Object(external_wp_element_["createElement"])("p", null, Object(external_wp_i18n_["__"])('No preview available.')));
+}
+
+// CONCATENATED MODULE: ./node_modules/@wordpress/widgets/build-module/blocks/legacy-widget/edit/convert-to-blocks-button.js
+
+
+/**
+ * WordPress dependencies
+ */
+
+
+
+
+
+function ConvertToBlocksButton({
+ clientId,
+ rawInstance
+}) {
+ const {
+ replaceBlocks
+ } = Object(external_wp_data_["useDispatch"])(external_wp_blockEditor_["store"]);
+ return Object(external_wp_element_["createElement"])(external_wp_components_["ToolbarButton"], {
+ onClick: () => {
+ if (rawInstance.title) {
+ replaceBlocks(clientId, [Object(external_wp_blocks_["createBlock"])('core/heading', {
+ content: rawInstance.title
+ }), ...Object(external_wp_blocks_["rawHandler"])({
+ HTML: rawInstance.text
+ })]);
+ } else {
+ replaceBlocks(clientId, Object(external_wp_blocks_["rawHandler"])({
+ HTML: rawInstance.text
+ }));
+ }
+ }
+ }, Object(external_wp_i18n_["__"])('Convert to blocks'));
+}
+
+// CONCATENATED MODULE: ./node_modules/@wordpress/widgets/build-module/blocks/legacy-widget/edit/index.js
+
+
+/**
+ * External dependencies
+ */
+
+/**
+ * WordPress dependencies
+ */
+
+
+
+
+
+
+
+
+/**
+ * Internal dependencies
+ */
+
+
+
+
+
+
+
+function Edit(props) {
+ const {
+ id,
+ idBase
+ } = props.attributes;
+ const {
+ isWide = false
+ } = props;
+ const blockProps = Object(external_wp_blockEditor_["useBlockProps"])({
+ className: classnames_default()({
+ 'is-wide-widget': isWide
+ })
+ });
+ return Object(external_wp_element_["createElement"])("div", blockProps, !id && !idBase ? Object(external_wp_element_["createElement"])(Empty, props) : Object(external_wp_element_["createElement"])(NotEmpty, props));
+}
+
+function Empty({
+ attributes: {
+ id,
+ idBase
+ },
+ setAttributes
+}) {
+ return Object(external_wp_element_["createElement"])(external_wp_components_["Placeholder"], {
+ icon: Object(external_wp_element_["createElement"])(external_wp_blockEditor_["BlockIcon"], {
+ icon: library_brush
+ }),
+ label: Object(external_wp_i18n_["__"])('Legacy Widget')
+ }, Object(external_wp_element_["createElement"])(WidgetTypeSelector, {
+ selectedId: id !== null && id !== void 0 ? id : idBase,
+ onSelect: ({
+ selectedId,
+ isMulti
+ }) => {
+ if (!selectedId) {
+ setAttributes({
+ id: null,
+ idBase: null,
+ instance: null
+ });
+ } else if (isMulti) {
+ setAttributes({
+ id: null,
+ idBase: selectedId,
+ instance: {}
+ });
+ } else {
+ setAttributes({
+ id: selectedId,
+ idBase: null,
+ instance: null
+ });
+ }
+ }
+ }));
+}
+
+function NotEmpty({
+ attributes: {
+ id,
+ idBase,
+ instance
+ },
+ setAttributes,
+ clientId,
+ isSelected,
+ isWide = false
+}) {
+ const [hasPreview, setHasPreview] = Object(external_wp_element_["useState"])(null);
+ const {
+ widgetType,
+ hasResolvedWidgetType,
+ isWidgetTypeHidden,
+ isNavigationMode
+ } = Object(external_wp_data_["useSelect"])(select => {
+ var _select$getSettings$w, _select$getSettings;
+
+ const widgetTypeId = id !== null && id !== void 0 ? id : idBase;
+ const hiddenIds = (_select$getSettings$w = (_select$getSettings = select(external_wp_blockEditor_["store"]).getSettings()) === null || _select$getSettings === void 0 ? void 0 : _select$getSettings.widgetTypesToHideFromLegacyWidgetBlock) !== null && _select$getSettings$w !== void 0 ? _select$getSettings$w : [];
+ return {
+ widgetType: select(external_wp_coreData_["store"]).getWidgetType(widgetTypeId),
+ hasResolvedWidgetType: select(external_wp_coreData_["store"]).hasFinishedResolution('getWidgetType', [widgetTypeId]),
+ isWidgetTypeHidden: hiddenIds.includes(widgetTypeId),
+ isNavigationMode: select(external_wp_blockEditor_["store"]).isNavigationMode()
+ };
+ }, [id, idBase]);
+ const setInstance = Object(external_wp_element_["useCallback"])(nextInstance => {
+ setAttributes({
+ instance: nextInstance
+ });
+ }, []);
+
+ if (!widgetType && hasResolvedWidgetType) {
+ return Object(external_wp_element_["createElement"])(external_wp_components_["Placeholder"], {
+ icon: Object(external_wp_element_["createElement"])(external_wp_blockEditor_["BlockIcon"], {
+ icon: library_brush
+ }),
+ label: Object(external_wp_i18n_["__"])('Legacy Widget')
+ }, Object(external_wp_i18n_["__"])('Widget is missing.'));
+ }
+
+ if (!hasResolvedWidgetType) {
+ return Object(external_wp_element_["createElement"])(external_wp_components_["Placeholder"], null, Object(external_wp_element_["createElement"])(external_wp_components_["Spinner"], null));
+ }
+
+ const mode = isNavigationMode || !isSelected ? 'preview' : 'edit';
+ return Object(external_wp_element_["createElement"])(external_wp_element_["Fragment"], null, !isWidgetTypeHidden && Object(external_wp_element_["createElement"])(external_wp_blockEditor_["BlockControls"], {
+ group: "block"
+ }, Object(external_wp_element_["createElement"])(external_wp_components_["ToolbarButton"], {
+ label: Object(external_wp_i18n_["__"])('Change widget'),
+ icon: library_update,
+ onClick: () => setAttributes({
+ id: null,
+ idBase: null,
+ instance: null
+ })
+ })), idBase === 'text' && Object(external_wp_element_["createElement"])(external_wp_blockEditor_["BlockControls"], {
+ group: "other"
+ }, Object(external_wp_element_["createElement"])(ConvertToBlocksButton, {
+ clientId: clientId,
+ rawInstance: instance.raw
+ })), Object(external_wp_element_["createElement"])(external_wp_blockEditor_["InspectorControls"], null, Object(external_wp_element_["createElement"])(InspectorCard, {
+ name: widgetType.name,
+ description: widgetType.description
+ })), Object(external_wp_element_["createElement"])(Form, {
+ title: widgetType.name,
+ isVisible: mode === 'edit',
+ id: id,
+ idBase: idBase,
+ instance: instance,
+ isWide: isWide,
+ onChangeInstance: setInstance,
+ onChangeHasPreview: setHasPreview
+ }), idBase && Object(external_wp_element_["createElement"])(external_wp_element_["Fragment"], null, hasPreview === null && mode === 'preview' && Object(external_wp_element_["createElement"])(external_wp_components_["Placeholder"], null, Object(external_wp_element_["createElement"])(external_wp_components_["Spinner"], null)), hasPreview === true && Object(external_wp_element_["createElement"])(Preview, {
+ idBase: idBase,
+ instance: instance,
+ isVisible: mode === 'preview'
+ }), hasPreview === false && mode === 'preview' && Object(external_wp_element_["createElement"])(NoPreview, {
+ name: widgetType.name
+ })));
+}
+
+// CONCATENATED MODULE: ./node_modules/@wordpress/widgets/build-module/blocks/legacy-widget/transforms.js
+/**
+ * WordPress dependencies
+ */
+
+const legacyWidgetTransforms = [{
+ block: 'core/calendar',
+ widget: 'calendar'
+}, {
+ block: 'core/search',
+ widget: 'search'
+}, {
+ block: 'core/html',
+ widget: 'html',
+ transform: ({
+ content
+ }) => ({
+ content
+ })
+}, {
+ block: 'core/archives',
+ widget: 'archives',
+ transform: ({
+ count,
+ dropdown
+ }) => {
+ return {
+ displayAsDropdown: !!dropdown,
+ showPostCounts: !!count
+ };
+ }
+}, {
+ block: 'core/latest-posts',
+ widget: 'recent-posts',
+ transform: ({
+ show_date: displayPostDate,
+ number
+ }) => {
+ return {
+ displayPostDate: !!displayPostDate,
+ postsToShow: number
+ };
+ }
+}, {
+ block: 'core/latest-comments',
+ widget: 'recent-comments',
+ transform: ({
+ number
+ }) => {
+ return {
+ commentsToShow: number
+ };
+ }
+}, {
+ block: 'core/tag-cloud',
+ widget: 'tag_cloud',
+ transform: ({
+ taxonomy,
+ count
+ }) => {
+ return {
+ showTagCounts: !!count,
+ taxonomy
+ };
+ }
+}, {
+ block: 'core/categories',
+ widget: 'categories',
+ transform: ({
+ count,
+ dropdown,
+ hierarchical
+ }) => {
+ return {
+ displayAsDropdown: !!dropdown,
+ showPostCounts: !!count,
+ showHierarchy: !!hierarchical
+ };
+ }
+}, {
+ block: 'core/audio',
+ widget: 'media_audio',
+ transform: ({
+ url,
+ preload,
+ loop,
+ attachment_id: id
+ }) => {
+ return {
+ src: url,
+ id,
+ preload,
+ loop
+ };
+ }
+}, {
+ block: 'core/video',
+ widget: 'media_video',
+ transform: ({
+ url,
+ preload,
+ loop,
+ attachment_id: id
+ }) => {
+ return {
+ src: url,
+ id,
+ preload,
+ loop
+ };
+ }
+}, {
+ block: 'core/image',
+ widget: 'media_image',
+ transform: ({
+ alt,
+ attachment_id: id,
+ caption,
+ height,
+ link_classes: linkClass,
+ link_rel: rel,
+ link_target_blank: targetBlack,
+ link_type: linkDestination,
+ link_url: link,
+ size: sizeSlug,
+ url,
+ width
+ }) => {
+ return {
+ alt,
+ caption,
+ height,
+ id,
+ link,
+ linkClass,
+ linkDestination,
+ linkTarget: targetBlack ? '_blank' : undefined,
+ rel,
+ sizeSlug,
+ url,
+ width
+ };
+ }
+}, {
+ block: 'core/gallery',
+ widget: 'media_gallery',
+ transform: ({
+ ids,
+ link_type: linkTo,
+ size,
+ number
+ }) => {
+ return {
+ ids,
+ columns: number,
+ linkTo,
+ sizeSlug: size,
+ images: ids.map(id => ({
+ id
+ }))
+ };
+ }
+}, {
+ block: 'core/rss',
+ widget: 'rss',
+ transform: ({
+ url,
+ show_author: displayAuthor,
+ show_date: displayDate,
+ show_summary: displayExcerpt,
+ items
+ }) => {
+ return {
+ feedURL: url,
+ displayAuthor: !!displayAuthor,
+ displayDate: !!displayDate,
+ displayExcerpt: !!displayExcerpt,
+ itemsToShow: items
+ };
+ }
+}].map(({
+ block,
+ widget,
+ transform
+}) => {
+ return {
+ type: 'block',
+ blocks: [block],
+ isMatch: ({
+ idBase,
+ instance
+ }) => {
+ return idBase === widget && !!(instance !== null && instance !== void 0 && instance.raw);
+ },
+ transform: ({
+ instance
+ }) => {
+ var _instance$raw;
+
+ const transformedBlock = Object(external_wp_blocks_["createBlock"])(block, transform ? transform(instance.raw) : undefined);
+
+ if (!((_instance$raw = instance.raw) !== null && _instance$raw !== void 0 && _instance$raw.title)) {
+ return transformedBlock;
+ }
+
+ return [Object(external_wp_blocks_["createBlock"])('core/heading', {
+ content: instance.raw.title
+ }), transformedBlock];
+ }
+ };
+});
+const transforms = {
+ to: legacyWidgetTransforms
+};
+/* harmony default export */ var legacy_widget_transforms = (transforms);
+
+// CONCATENATED MODULE: ./node_modules/@wordpress/widgets/build-module/blocks/legacy-widget/index.js
+/**
+ * WordPress dependencies
+ */
+
+/**
+ * Internal dependencies
+ */
+
+const legacy_widget_metadata = {
+ apiVersion: 2,
+ name: "core/legacy-widget",
+ title: "Legacy Widget",
+ category: "widgets",
+ description: "Display a legacy widget.",
+ textdomain: "default",
+ attributes: {
+ id: {
+ type: "string",
+ "default": null
+ },
+ idBase: {
+ type: "string",
+ "default": null
+ },
+ instance: {
+ type: "object",
+ "default": null
+ }
+ },
+ supports: {
+ html: false,
+ customClassName: false,
+ reusable: false
+ },
+ editorStyle: "wp-block-legacy-widget-editor"
+};
+
+
+const {
+ name: legacy_widget_name
+} = legacy_widget_metadata;
+
+const legacy_widget_settings = {
+ icon: library_widget,
+ edit: Edit,
+ transforms: legacy_widget_transforms
+};
// CONCATENATED MODULE: ./node_modules/@wordpress/icons/build-module/library/move-to.js
@@ -173,14 +1395,38 @@ function MoveToWidgetArea({
// CONCATENATED MODULE: ./node_modules/@wordpress/widgets/build-module/components/index.js
-// EXTERNAL MODULE: external ["wp","data"]
-var external_wp_data_ = __webpack_require__("1ZqX");
+// CONCATENATED MODULE: ./node_modules/@wordpress/widgets/build-module/utils.js
+// @ts-check
-// EXTERNAL MODULE: external ["wp","coreData"]
-var external_wp_coreData_ = __webpack_require__("jZUy");
+/**
+ * Get the internal widget id from block.
+ *
+ * @typedef {Object} Attributes
+ * @property {string} __internalWidgetId The internal widget id.
+ * @typedef {Object} Block
+ * @property {Attributes} attributes The attributes of the block.
+ *
+ * @param {Block} block The block.
+ * @return {string} The internal widget id.
+ */
+function getWidgetIdFromBlock(block) {
+ return block.attributes.__internalWidgetId;
+}
+/**
+ * Add internal widget id to block's attributes.
+ *
+ * @param {Block} block The block.
+ * @param {string} widgetId The widget id.
+ * @return {Block} The updated block.
+ */
-// EXTERNAL MODULE: external ["wp","blocks"]
-var external_wp_blocks_ = __webpack_require__("HSyU");
+function addWidgetIdToBlock(block, widgetId) {
+ return { ...block,
+ attributes: { ...(block.attributes || {}),
+ __internalWidgetId: widgetId
+ }
+ };
+}
// CONCATENATED MODULE: ./node_modules/@wordpress/widgets/build-module/register-legacy-widget-variations.js
/**
@@ -215,42 +1461,38 @@ function registerLegacyWidgetVariations(settings) {
});
}
-// CONCATENATED MODULE: ./node_modules/@wordpress/widgets/build-module/utils.js
-// @ts-check
-
+// CONCATENATED MODULE: ./node_modules/@wordpress/widgets/build-module/index.js
/**
- * Get the internal widget id from block.
- *
- * @typedef {Object} Attributes
- * @property {string} __internalWidgetId The internal widget id.
- * @typedef {Object} Block
- * @property {Attributes} attributes The attributes of the block.
- *
- * @param {Block} block The block.
- * @return {string} The internal widget id.
+ * WordPress dependencies
*/
-function getWidgetIdFromBlock(block) {
- return block.attributes.__internalWidgetId;
-}
+
/**
- * Add internal widget id to block's attributes.
- *
- * @param {Block} block The block.
- * @param {string} widgetId The widget id.
- * @return {Block} The updated block.
+ * Internal dependencies
*/
-function addWidgetIdToBlock(block, widgetId) {
- return { ...block,
- attributes: { ...(block.attributes || {}),
- __internalWidgetId: widgetId
- }
- };
-}
-// CONCATENATED MODULE: ./node_modules/@wordpress/widgets/build-module/index.js
+/**
+ * Registers the Legacy Widget block.
+ *
+ * Note that for the block to be useful, any scripts required by a widget must
+ * be loaded into the page.
+ *
+ * @see https://developer.wordpress.org/block-editor/how-to-guides/widgets/legacy-widget-block/
+ */
+
+function registerLegacyWidgetBlock() {
+ const {
+ metadata,
+ settings,
+ name
+ } = legacy_widget_namespaceObject;
+ Object(external_wp_blocks_["registerBlockType"])({
+ name,
+ ...metadata
+ }, settings);
+}
@@ -268,6 +1510,84 @@ function addWidgetIdToBlock(block, widgetId) {
(function() { module.exports = window["wp"]["blocks"]; }());
+/***/ }),
+
+/***/ "K9lf":
+/***/ (function(module, exports) {
+
+(function() { module.exports = window["wp"]["compose"]; }());
+
+/***/ }),
+
+/***/ "Mmq9":
+/***/ (function(module, exports) {
+
+(function() { module.exports = window["wp"]["url"]; }());
+
+/***/ }),
+
+/***/ "TSYQ":
+/***/ (function(module, exports, __webpack_require__) {
+
+var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/*!
+ Copyright (c) 2018 Jed Watson.
+ Licensed under the MIT License (MIT), see
+ http://jedwatson.github.io/classnames
+*/
+/* global define */
+
+(function () {
+ 'use strict';
+
+ var hasOwn = {}.hasOwnProperty;
+
+ function classNames() {
+ var classes = [];
+
+ for (var i = 0; i < arguments.length; i++) {
+ var arg = arguments[i];
+ if (!arg) continue;
+
+ var argType = typeof arg;
+
+ if (argType === 'string' || argType === 'number') {
+ classes.push(arg);
+ } else if (Array.isArray(arg)) {
+ if (arg.length) {
+ var inner = classNames.apply(null, arg);
+ if (inner) {
+ classes.push(inner);
+ }
+ }
+ } else if (argType === 'object') {
+ if (arg.toString === Object.prototype.toString) {
+ for (var key in arg) {
+ if (hasOwn.call(arg, key) && arg[key]) {
+ classes.push(key);
+ }
+ }
+ } else {
+ classes.push(arg.toString());
+ }
+ }
+ }
+
+ return classes.join(' ');
+ }
+
+ if ( true && module.exports) {
+ classNames.default = classNames;
+ module.exports = classNames;
+ } else if (true) {
+ // register as 'classnames', consistent with npm package name
+ !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = (function () {
+ return classNames;
+ }).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__),
+ __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
+ } else {}
+}());
+
+
/***/ }),
/***/ "Tqx9":
@@ -277,6 +1597,20 @@ function addWidgetIdToBlock(block, widgetId) {
/***/ }),
+/***/ "YLtl":
+/***/ (function(module, exports) {
+
+(function() { module.exports = window["lodash"]; }());
+
+/***/ }),
+
+/***/ "axFQ":
+/***/ (function(module, exports) {
+
+(function() { module.exports = window["wp"]["blockEditor"]; }());
+
+/***/ }),
+
/***/ "jZUy":
/***/ (function(module, exports) {
@@ -291,11 +1625,25 @@ function addWidgetIdToBlock(block, widgetId) {
/***/ }),
+/***/ "onLe":
+/***/ (function(module, exports) {
+
+(function() { module.exports = window["wp"]["notices"]; }());
+
+/***/ }),
+
/***/ "tI+e":
/***/ (function(module, exports) {
(function() { module.exports = window["wp"]["components"]; }());
+/***/ }),
+
+/***/ "ywyh":
+/***/ (function(module, exports) {
+
+(function() { module.exports = window["wp"]["apiFetch"]; }());
+
/***/ })
/******/ });
\ No newline at end of file
diff --git a/wp-includes/js/dist/widgets.min.js b/wp-includes/js/dist/widgets.min.js
index 632331ae12e1..a26d4f767fae 100644
--- a/wp-includes/js/dist/widgets.min.js
+++ b/wp-includes/js/dist/widgets.min.js
@@ -1,2 +1,7 @@
/*! This file is auto-generated */
-this.wp=this.wp||{},this.wp.widgets=function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s="4g8P")}({"1ZqX":function(e,t){e.exports=window.wp.data},"4g8P":function(e,t,n){"use strict";n.r(t),n.d(t,"MoveToWidgetArea",(function(){return l})),n.d(t,"registerLegacyWidgetVariations",(function(){return p})),n.d(t,"getWidgetIdFromBlock",(function(){return f})),n.d(t,"addWidgetIdToBlock",(function(){return b}));var r=n("GRId"),o=n("tI+e"),i=n("l3Sj"),c=n("Tqx9");var u=Object(r.createElement)(c.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},Object(r.createElement)(c.Path,{d:"M19.75 9c0-1.257-.565-2.197-1.39-2.858-.797-.64-1.827-1.017-2.815-1.247-1.802-.42-3.703-.403-4.383-.396L11 4.5V6l.177-.001c.696-.006 2.416-.02 4.028.356.887.207 1.67.518 2.216.957.52.416.829.945.829 1.688 0 .592-.167.966-.407 1.23-.255.281-.656.508-1.236.674-1.19.34-2.82.346-4.607.346h-.077c-1.692 0-3.527 0-4.942.404-.732.209-1.424.545-1.935 1.108-.526.579-.796 1.33-.796 2.238 0 1.257.565 2.197 1.39 2.858.797.64 1.827 1.017 2.815 1.247 1.802.42 3.703.403 4.383.396L13 19.5h.714V22L18 18.5 13.714 15v3H13l-.177.001c-.696.006-2.416.02-4.028-.356-.887-.207-1.67-.518-2.216-.957-.52-.416-.829-.945-.829-1.688 0-.592.167-.966.407-1.23.255-.281.656-.508 1.237-.674 1.189-.34 2.819-.346 4.606-.346h.077c1.692 0 3.527 0 4.941-.404.732-.209 1.425-.545 1.936-1.108.526-.579.796-1.33.796-2.238z"}));function l({currentWidgetAreaId:e,widgetAreas:t,onSelect:n}){return Object(r.createElement)(o.ToolbarGroup,null,Object(r.createElement)(o.ToolbarItem,null,c=>Object(r.createElement)(o.DropdownMenu,{icon:u,label:Object(i.__)("Move to widget area"),toggleProps:c},({onClose:c})=>Object(r.createElement)(o.MenuGroup,{label:Object(i.__)("Move to")},Object(r.createElement)(o.MenuItemsChoice,{choices:t.map(e=>({value:e.id,label:e.name,info:e.description})),value:e,onSelect:e=>{n(e),c()}})))))}var d=n("1ZqX"),a=n("jZUy"),s=n("HSyU");function p(e){const t=Object(d.subscribe)(()=>{var n,r;const o=null!==(n=null==e?void 0:e.widgetTypesToHideFromLegacyWidgetBlock)&&void 0!==n?n:[],i=null===(r=Object(d.select)(a.store).getWidgetTypes({per_page:-1}))||void 0===r?void 0:r.filter(e=>!o.includes(e.id));i&&(t(),Object(d.dispatch)(s.store).addBlockVariations("core/legacy-widget",i.map(e=>({name:e.id,title:e.name,description:e.description,attributes:e.is_multi?{idBase:e.id,instance:{}}:{id:e.id}}))))})}function f(e){return e.attributes.__internalWidgetId}function b(e,t){return{...e,attributes:{...e.attributes||{},__internalWidgetId:t}}}},GRId:function(e,t){e.exports=window.wp.element},HSyU:function(e,t){e.exports=window.wp.blocks},Tqx9:function(e,t){e.exports=window.wp.primitives},jZUy:function(e,t){e.exports=window.wp.coreData},l3Sj:function(e,t){e.exports=window.wp.i18n},"tI+e":function(e,t){e.exports=window.wp.components}});
\ No newline at end of file
+this.wp=this.wp||{},this.wp.widgets=function(e){var t={};function n(i){if(t[i])return t[i].exports;var r=t[i]={i:i,l:!1,exports:{}};return e[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(i,r,function(t){return e[t]}.bind(null,r));return i},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s="4g8P")}({"1ZqX":function(e,t){e.exports=window.wp.data},"4g8P":function(e,t,n){"use strict";n.r(t),n.d(t,"MoveToWidgetArea",(function(){return Q})),n.d(t,"getWidgetIdFromBlock",(function(){return R})),n.d(t,"addWidgetIdToBlock",(function(){return G})),n.d(t,"registerLegacyWidgetBlock",(function(){return q})),n.d(t,"registerLegacyWidgetVariations",(function(){return U}));var i={};n.r(i),n.d(i,"metadata",(function(){return D})),n.d(i,"name",(function(){return A})),n.d(i,"settings",(function(){return N}));var r=n("HSyU"),o=n("GRId"),a=n("Tqx9");var s=Object(o.createElement)(a.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},Object(o.createElement)(a.Path,{d:"M7 11h2v2H7v-2zm14-5v14l-2 2H5l-2-2V6l2-2h1V2h2v2h8V2h2v2h1l2 2zM5 8h14V6H5v2zm14 12V10H5v10h14zm-4-7h2v-2h-2v2zm-4 0h2v-2h-2v2z"})),c=n("TSYQ"),l=n.n(c),d=n("axFQ"),u=n("tI+e");var m=Object(o.createElement)(a.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},Object(o.createElement)(a.Path,{d:"M4 20h8v-1.5H4V20zM18.9 3.5c-.6-.6-1.5-.6-2.1 0l-7.2 7.2c-.4-.1-.7 0-1.1.1-.5.2-1.5.7-1.9 2.2-.4 1.7-.8 2.2-1.1 2.7-.1.1-.2.3-.3.4l-.6 1.1H6c2 0 3.4-.4 4.7-1.4.8-.6 1.2-1.4 1.3-2.3 0-.3 0-.5-.1-.7L19 5.7c.5-.6.5-1.6-.1-2.2zM9.7 14.7c-.7.5-1.5.8-2.4 1 .2-.5.5-1.2.8-2.3.2-.6.4-1 .8-1.1.5-.1 1 .1 1.3.3.2.2.3.5.2.8 0 .3-.1.9-.7 1.3z"}));var h=Object(o.createElement)(a.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"-2 -2 24 24"},Object(o.createElement)(a.Path,{d:"M10.2 3.28c3.53 0 6.43 2.61 6.92 6h2.08l-3.5 4-3.5-4h2.32c-.45-1.97-2.21-3.45-4.32-3.45-1.45 0-2.73.71-3.54 1.78L4.95 5.66C6.23 4.2 8.11 3.28 10.2 3.28zm-.4 13.44c-3.52 0-6.43-2.61-6.92-6H.8l3.5-4c1.17 1.33 2.33 2.67 3.5 4H5.48c.45 1.97 2.21 3.45 4.32 3.45 1.45 0 2.73-.71 3.54-1.78l1.71 1.95c-1.28 1.46-3.15 2.38-5.25 2.38z"})),w=n("l3Sj"),g=n("1ZqX"),b=n("jZUy");function p({selectedId:e,onSelect:t}){const n=Object(g.useSelect)(e=>{var t,n,i;const r=null!==(t=null===(n=e(d.store).getSettings())||void 0===n?void 0:n.widgetTypesToHideFromLegacyWidgetBlock)&&void 0!==t?t:[];return null===(i=e(b.store).getWidgetTypes({per_page:-1}))||void 0===i?void 0:i.filter(e=>!r.includes(e.id))},[]);return n?0===n.length?Object(w.__)("There are no widgets available."):Object(o.createElement)(u.SelectControl,{label:Object(w.__)("Select a legacy widget to display:"),value:null!=e?e:"",options:[{value:"",label:Object(w.__)("Select widget")},...n.map(e=>({value:e.id,label:e.name}))],onChange:e=>{if(e){const i=n.find(t=>t.id===e);t({selectedId:i.id,isMulti:i.is_multi})}else t({selectedId:null})}}):Object(o.createElement)(u.Spinner,null)}function f({name:e,description:t}){return Object(o.createElement)("div",{className:"wp-block-legacy-widget-inspector-card"},Object(o.createElement)("h3",{className:"wp-block-legacy-widget-inspector-card__name"},e),Object(o.createElement)("span",null,t))}var v=n("onLe"),j=n("K9lf"),y=n("YLtl"),O=n("ywyh"),_=n.n(O);class E{constructor({id:e,idBase:t,instance:n,onChangeInstance:i,onChangeHasPreview:r,onError:o}){this.id=e,this.idBase=t,this._instance=n,this._hasPreview=null,this.onChangeInstance=i,this.onChangeHasPreview=r,this.onError=o,this.number=++k,this.handleFormChange=Object(y.debounce)(this.saveForm.bind(this),200),this.handleFormSubmit=this.handleFormSubmit.bind(this),this.initDOM(),this.bindEvents(),this.loadContent()}destroy(){this.unbindEvents(),this.element.remove()}initDOM(){var e,t;this.element=S("div",{class:"widget open"},[S("div",{class:"widget-inside"},[this.form=S("form",{class:"form",method:"post"},[S("input",{class:"widget-id",type:"hidden",name:"widget-id",value:null!==(e=this.id)&&void 0!==e?e:`${this.idBase}-${this.number}`}),S("input",{class:"id_base",type:"hidden",name:"id_base",value:null!==(t=this.idBase)&&void 0!==t?t:this.id}),S("input",{class:"widget-width",type:"hidden",name:"widget-width",value:"250"}),S("input",{class:"widget-height",type:"hidden",name:"widget-height",value:"200"}),S("input",{class:"widget_number",type:"hidden",name:"widget_number",value:this.idBase?this.number.toString():""}),this.content=S("div",{class:"widget-content"}),this.id&&S("button",{class:"button is-primary",type:"submit"},Object(w.__)("Save"))])])])}bindEvents(){if(window.jQuery){const{jQuery:e}=window;e(this.form).on("change",null,this.handleFormChange),e(this.form).on("input",null,this.handleFormChange),e(this.form).on("submit",this.handleFormSubmit)}else this.form.addEventListener("change",this.handleFormChange),this.form.addEventListener("input",this.handleFormChange),this.form.addEventListener("submit",this.handleFormSubmit)}unbindEvents(){if(window.jQuery){const{jQuery:e}=window;e(this.form).off("change",null,this.handleFormChange),e(this.form).off("input",null,this.handleFormChange),e(this.form).off("submit",this.handleFormSubmit)}else this.form.removeEventListener("change",this.handleFormChange),this.form.removeEventListener("input",this.handleFormChange),this.form.removeEventListener("submit",this.handleFormSubmit)}async loadContent(){try{if(this.id){const{form:e}=await B(this.id);this.content.innerHTML=e}else if(this.idBase){const{form:e,preview:t}=await T({idBase:this.idBase,instance:this.instance,number:this.number});if(this.content.innerHTML=e,this.hasPreview=!x(t),!this.instance.hash){const{instance:e}=await T({idBase:this.idBase,instance:this.instance,number:this.number,formData:C(this.form)});this.instance=e}}if(window.jQuery){const{jQuery:e}=window;e(document).trigger("widget-added",[e(this.element)])}}catch(e){this.onError(e)}}handleFormSubmit(e){e.preventDefault(),this.saveForm()}async saveForm(){const e=C(this.form);try{if(this.id){const{form:t}=await B(this.id,e);if(this.content.innerHTML=t,window.jQuery){const{jQuery:e}=window;e(document).trigger("widget-updated",[e(this.element)])}}else if(this.idBase){const{instance:t,preview:n}=await T({idBase:this.idBase,instance:this.instance,number:this.number,formData:e});this.instance=t,this.hasPreview=!x(n)}}catch(e){this.onError(e)}}get instance(){return this._instance}set instance(e){this._instance!==e&&(this._instance=e,this.onChangeInstance(e))}get hasPreview(){return this._hasPreview}set hasPreview(e){this._hasPreview!==e&&(this._hasPreview=e,this.onChangeHasPreview(e))}}let k=0;function S(e,t={},n=null){const i=document.createElement(e);for(const[e,n]of Object.entries(t))i.setAttribute(e,n);if(Array.isArray(n))for(const e of n)e&&i.appendChild(e);else"string"==typeof n&&(i.innerText=n);return i}async function B(e,t=null){let n;return n=t?await _()({path:`/wp/v2/widgets/${e}?context=edit`,method:"PUT",data:{form_data:t}}):await _()({path:`/wp/v2/widgets/${e}?context=edit`,method:"GET"}),{form:n.rendered_form}}async function T({idBase:e,instance:t,number:n,formData:i=null}){const r=await _()({path:`/wp/v2/widget-types/${e}/encode`,method:"POST",data:{instance:t,number:n,form_data:i}});return{instance:r.instance,form:r.form,preview:r.preview}}function x(e){const t=document.createElement("div");return t.innerHTML=e,""===t.innerText.trim()}function C(e){return new window.URLSearchParams(Array.from(new window.FormData(e))).toString()}function P({title:e,isVisible:t,id:n,idBase:i,instance:r,isWide:a,onChangeInstance:s,onChangeHasPreview:c}){const d=Object(o.useRef)(),m=Object(j.useViewportMatch)("small"),h=Object(o.useRef)(new Set),b=Object(o.useRef)(new Set),{createNotice:p}=Object(g.useDispatch)(v.store);return Object(o.useEffect)(()=>{if(b.current.has(r))return void b.current.delete(r);const e=new E({id:n,idBase:i,instance:r,onChangeInstance(e){h.current.add(r),b.current.add(e),s(e)},onChangeHasPreview:c,onError(e){var t;p("error",null!==(t=null==e?void 0:e.message)&&void 0!==t?t:Object(w.__)("An error occured while fetching or updating the widget."))}});return d.current.appendChild(e.element),()=>{h.current.has(r)?h.current.delete(r):e.destroy()}},[n,i,r,s,c,m]),a&&m?Object(o.createElement)("div",{className:l()({"wp-block-legacy-widget__container":t})},t&&Object(o.createElement)("h3",{className:"wp-block-legacy-widget__edit-form-title"},e),Object(o.createElement)(u.Popover,{focusOnMount:!1,position:"middle right",__unstableForceXAlignment:!0},Object(o.createElement)("div",{ref:d,className:"wp-block-legacy-widget__edit-form",hidden:!t}))):Object(o.createElement)("div",{ref:d,className:"wp-block-legacy-widget__edit-form",hidden:!t},Object(o.createElement)("h3",{className:"wp-block-legacy-widget__edit-form-title"},e))}var M=n("Mmq9");function L({idBase:e,instance:t,isVisible:n}){const[i,r]=Object(o.useState)(),a=Object(j.useRefEffect)(e=>{function t(){var t,n;const i=null==e||null===(t=e.contentDocument)||void 0===t||null===(n=t.body)||void 0===n?void 0:n.getBoundingClientRect();i&&r(i.top+i.height)}const{IntersectionObserver:n}=e.ownerDocument.defaultView;return new n(t,{threshold:1}).observe(e),e.addEventListener("load",t),()=>{e.removeEventListener("load",t)}},[]);return Object(o.createElement)(o.Fragment,null,n&&null===i&&Object(o.createElement)(u.Placeholder,null,Object(o.createElement)(u.Spinner,null)),Object(o.createElement)("div",{className:l()("wp-block-legacy-widget__edit-preview",{"is-offscreen":!n||null===i})},Object(o.createElement)(u.Disabled,null,Object(o.createElement)("iframe",{ref:a,className:"wp-block-legacy-widget__edit-preview-iframe",title:Object(w.__)("Legacy Widget Preview"),src:Object(M.addQueryArgs)("widgets.php",{"legacy-widget-preview":{idBase:e,instance:t}}),height:i||100}))))}function F({name:e}){return Object(o.createElement)("div",{className:"wp-block-legacy-widget__edit-no-preview"},e&&Object(o.createElement)("h3",null,e),Object(o.createElement)("p",null,Object(w.__)("No preview available.")))}function H({clientId:e,rawInstance:t}){const{replaceBlocks:n}=Object(g.useDispatch)(d.store);return Object(o.createElement)(u.ToolbarButton,{onClick:()=>{t.title?n(e,[Object(r.createBlock)("core/heading",{content:t.title}),...Object(r.rawHandler)({HTML:t.text})]):n(e,Object(r.rawHandler)({HTML:t.text}))}},Object(w.__)("Convert to blocks"))}function I({attributes:{id:e,idBase:t},setAttributes:n}){return Object(o.createElement)(u.Placeholder,{icon:Object(o.createElement)(d.BlockIcon,{icon:m}),label:Object(w.__)("Legacy Widget")},Object(o.createElement)(p,{selectedId:null!=e?e:t,onSelect:({selectedId:e,isMulti:t})=>{n(e?t?{id:null,idBase:e,instance:{}}:{id:e,idBase:null,instance:null}:{id:null,idBase:null,instance:null})}}))}function W({attributes:{id:e,idBase:t,instance:n},setAttributes:i,clientId:r,isSelected:a,isWide:s=!1}){const[c,l]=Object(o.useState)(null),{widgetType:p,hasResolvedWidgetType:v,isWidgetTypeHidden:j,isNavigationMode:y}=Object(g.useSelect)(n=>{var i,r;const o=null!=e?e:t,a=null!==(i=null===(r=n(d.store).getSettings())||void 0===r?void 0:r.widgetTypesToHideFromLegacyWidgetBlock)&&void 0!==i?i:[];return{widgetType:n(b.store).getWidgetType(o),hasResolvedWidgetType:n(b.store).hasFinishedResolution("getWidgetType",[o]),isWidgetTypeHidden:a.includes(o),isNavigationMode:n(d.store).isNavigationMode()}},[e,t]),O=Object(o.useCallback)(e=>{i({instance:e})},[]);if(!p&&v)return Object(o.createElement)(u.Placeholder,{icon:Object(o.createElement)(d.BlockIcon,{icon:m}),label:Object(w.__)("Legacy Widget")},Object(w.__)("Widget is missing."));if(!v)return Object(o.createElement)(u.Placeholder,null,Object(o.createElement)(u.Spinner,null));const _=y||!a?"preview":"edit";return Object(o.createElement)(o.Fragment,null,!j&&Object(o.createElement)(d.BlockControls,{group:"block"},Object(o.createElement)(u.ToolbarButton,{label:Object(w.__)("Change widget"),icon:h,onClick:()=>i({id:null,idBase:null,instance:null})})),"text"===t&&Object(o.createElement)(d.BlockControls,{group:"other"},Object(o.createElement)(H,{clientId:r,rawInstance:n.raw})),Object(o.createElement)(d.InspectorControls,null,Object(o.createElement)(f,{name:p.name,description:p.description})),Object(o.createElement)(P,{title:p.name,isVisible:"edit"===_,id:e,idBase:t,instance:n,isWide:s,onChangeInstance:O,onChangeHasPreview:l}),t&&Object(o.createElement)(o.Fragment,null,null===c&&"preview"===_&&Object(o.createElement)(u.Placeholder,null,Object(o.createElement)(u.Spinner,null)),!0===c&&Object(o.createElement)(L,{idBase:t,instance:n,isVisible:"preview"===_}),!1===c&&"preview"===_&&Object(o.createElement)(F,{name:p.name})))}var V={to:[{block:"core/calendar",widget:"calendar"},{block:"core/search",widget:"search"},{block:"core/html",widget:"html",transform:({content:e})=>({content:e})},{block:"core/archives",widget:"archives",transform:({count:e,dropdown:t})=>({displayAsDropdown:!!t,showPostCounts:!!e})},{block:"core/latest-posts",widget:"recent-posts",transform:({show_date:e,number:t})=>({displayPostDate:!!e,postsToShow:t})},{block:"core/latest-comments",widget:"recent-comments",transform:({number:e})=>({commentsToShow:e})},{block:"core/tag-cloud",widget:"tag_cloud",transform:({taxonomy:e,count:t})=>({showTagCounts:!!t,taxonomy:e})},{block:"core/categories",widget:"categories",transform:({count:e,dropdown:t,hierarchical:n})=>({displayAsDropdown:!!t,showPostCounts:!!e,showHierarchy:!!n})},{block:"core/audio",widget:"media_audio",transform:({url:e,preload:t,loop:n,attachment_id:i})=>({src:e,id:i,preload:t,loop:n})},{block:"core/video",widget:"media_video",transform:({url:e,preload:t,loop:n,attachment_id:i})=>({src:e,id:i,preload:t,loop:n})},{block:"core/image",widget:"media_image",transform:({alt:e,attachment_id:t,caption:n,height:i,link_classes:r,link_rel:o,link_target_blank:a,link_type:s,link_url:c,size:l,url:d,width:u})=>({alt:e,caption:n,height:i,id:t,link:c,linkClass:r,linkDestination:s,linkTarget:a?"_blank":void 0,rel:o,sizeSlug:l,url:d,width:u})},{block:"core/gallery",widget:"media_gallery",transform:({ids:e,link_type:t,size:n,number:i})=>({ids:e,columns:i,linkTo:t,sizeSlug:n,images:e.map(e=>({id:e}))})},{block:"core/rss",widget:"rss",transform:({url:e,show_author:t,show_date:n,show_summary:i,items:r})=>({feedURL:e,displayAuthor:!!t,displayDate:!!n,displayExcerpt:!!i,itemsToShow:r})}].map(({block:e,widget:t,transform:n})=>({type:"block",blocks:[e],isMatch:({idBase:e,instance:n})=>e===t&&!(null==n||!n.raw),transform:({instance:t})=>{var i;const o=Object(r.createBlock)(e,n?n(t.raw):void 0);return null!==(i=t.raw)&&void 0!==i&&i.title?[Object(r.createBlock)("core/heading",{content:t.raw.title}),o]:o}}))};const D={apiVersion:2,name:"core/legacy-widget",title:"Legacy Widget",category:"widgets",description:"Display a legacy widget.",textdomain:"default",attributes:{id:{type:"string",default:null},idBase:{type:"string",default:null},instance:{type:"object",default:null}},supports:{html:!1,customClassName:!1,reusable:!1},editorStyle:"wp-block-legacy-widget-editor"},{name:A}=D,N={icon:s,edit:function(e){const{id:t,idBase:n}=e.attributes,{isWide:i=!1}=e,r=Object(d.useBlockProps)({className:l()({"is-wide-widget":i})});return Object(o.createElement)("div",r,t||n?Object(o.createElement)(W,e):Object(o.createElement)(I,e))},transforms:V};var z=Object(o.createElement)(a.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},Object(o.createElement)(a.Path,{d:"M19.75 9c0-1.257-.565-2.197-1.39-2.858-.797-.64-1.827-1.017-2.815-1.247-1.802-.42-3.703-.403-4.383-.396L11 4.5V6l.177-.001c.696-.006 2.416-.02 4.028.356.887.207 1.67.518 2.216.957.52.416.829.945.829 1.688 0 .592-.167.966-.407 1.23-.255.281-.656.508-1.236.674-1.19.34-2.82.346-4.607.346h-.077c-1.692 0-3.527 0-4.942.404-.732.209-1.424.545-1.935 1.108-.526.579-.796 1.33-.796 2.238 0 1.257.565 2.197 1.39 2.858.797.64 1.827 1.017 2.815 1.247 1.802.42 3.703.403 4.383.396L13 19.5h.714V22L18 18.5 13.714 15v3H13l-.177.001c-.696.006-2.416.02-4.028-.356-.887-.207-1.67-.518-2.216-.957-.52-.416-.829-.945-.829-1.688 0-.592.167-.966.407-1.23.255-.281.656-.508 1.237-.674 1.189-.34 2.819-.346 4.606-.346h.077c1.692 0 3.527 0 4.941-.404.732-.209 1.425-.545 1.936-1.108.526-.579.796-1.33.796-2.238z"}));function Q({currentWidgetAreaId:e,widgetAreas:t,onSelect:n}){return Object(o.createElement)(u.ToolbarGroup,null,Object(o.createElement)(u.ToolbarItem,null,i=>Object(o.createElement)(u.DropdownMenu,{icon:z,label:Object(w.__)("Move to widget area"),toggleProps:i},({onClose:i})=>Object(o.createElement)(u.MenuGroup,{label:Object(w.__)("Move to")},Object(o.createElement)(u.MenuItemsChoice,{choices:t.map(e=>({value:e.id,label:e.name,info:e.description})),value:e,onSelect:e=>{n(e),i()}})))))}function R(e){return e.attributes.__internalWidgetId}function G(e,t){return{...e,attributes:{...e.attributes||{},__internalWidgetId:t}}}function U(e){const t=Object(g.subscribe)(()=>{var n,i;const o=null!==(n=null==e?void 0:e.widgetTypesToHideFromLegacyWidgetBlock)&&void 0!==n?n:[],a=null===(i=Object(g.select)(b.store).getWidgetTypes({per_page:-1}))||void 0===i?void 0:i.filter(e=>!o.includes(e.id));a&&(t(),Object(g.dispatch)(r.store).addBlockVariations("core/legacy-widget",a.map(e=>({name:e.id,title:e.name,description:e.description,attributes:e.is_multi?{idBase:e.id,instance:{}}:{id:e.id}}))))})}function q(){const{metadata:e,settings:t,name:n}=i;Object(r.registerBlockType)({name:n,...e},t)}},GRId:function(e,t){e.exports=window.wp.element},HSyU:function(e,t){e.exports=window.wp.blocks},K9lf:function(e,t){e.exports=window.wp.compose},Mmq9:function(e,t){e.exports=window.wp.url},TSYQ:function(e,t,n){var i;
+/*!
+ Copyright (c) 2018 Jed Watson.
+ Licensed under the MIT License (MIT), see
+ http://jedwatson.github.io/classnames
+*/!function(){"use strict";var n={}.hasOwnProperty;function r(){for(var e=[],t=0;t array( 'wp-components' ),
'reusable-blocks' => array( 'wp-components' ),
'nux' => array( 'wp-components' ),
- 'edit-widgets' => array(
+ 'widgets' => array(
'wp-components',
+ ),
+ 'edit-widgets' => array(
+ 'wp-widgets',
'wp-block-editor',
'wp-edit-blocks',
'wp-block-library',
'wp-reusable-blocks',
),
'customize-widgets' => array(
- 'wp-components',
+ 'wp-widgets',
'wp-block-editor',
'wp-edit-blocks',
'wp-block-library',
@@ -1622,12 +1625,15 @@ function wp_default_styles( $styles ) {
'wp-block-library',
'wp-block-directory',
'wp-components',
+ 'wp-customize-widgets',
'wp-edit-post',
+ 'wp-edit-widgets',
'wp-editor',
'wp-format-library',
'wp-list-reusable-blocks',
'wp-reusable-blocks',
'wp-nux',
+ 'wp-widgets',
// Deprecated CSS.
'deprecated-media',
'farbtastic',
diff --git a/wp-includes/theme-templates.php b/wp-includes/theme-templates.php
index f5e03c5786fc..6c9da23b1b5b 100644
--- a/wp-includes/theme-templates.php
+++ b/wp-includes/theme-templates.php
@@ -76,10 +76,16 @@ function wp_filter_wp_template_unique_post_slug( $override_slug, $slug, $post_ID
*/
function the_block_template_skip_link() {
- // Early exit if not an FSE theme.
+ // Early exit if not a block theme.
if ( ! current_theme_supports( 'block-templates' ) ) {
return;
}
+
+ // Early exit if not a block template.
+ global $_wp_current_template_content;
+ if ( ! $_wp_current_template_content ) {
+ return;
+ }
?>