import { createElement, Component, useEffect, useRef } from '@wordpress/element' const WidgetArea = ({ value, option, option: { sidebarId = 'ct-footer-sidebar-1' }, onChange }) => { const parentEl = useRef() useEffect(() => { const sectionId = `widgetAreaSection-${sidebarId}` const widgetsToMove = Object.keys(wp.customize.control._value).filter( id => { if (id.indexOf('widget_') !== 0) { return false } return ( wp.customize.control(id).section() === `sidebar-widgets-${sidebarId}` ) } ) const Section = wp.customize.Section.extend({ containerParent: jQuery(parentEl.current), // containerPaneParent: parentEl.current collapse: function () {}, embed: function () { var section = this section.containerParent = wp.customize.ensure( section.containerParent ) var parentContainer = wp.customize.ensure( section.containerPaneParent ) if ( !section.contentContainer.parent().is(section.headContainer) ) { section.containerParent.append(section.contentContainer) section.contentContainer[0].classList.add('open') section.contentContainer[0] .querySelector( '.customize-section-description-container' ) .remove() } section.deferred.embedded.resolve() setTimeout(() => { widgetsToMove.map(control => { wp.customize.control(control).embedWidgetControl() setTimeout(() => { wp.customize .control(control) .container.one( 'click.toggle-widget-expanded', function toggleWidgetExpanded() { const widgetControl = wp.customHtmlWidgets.widgetControls[ control .replace('widget_', '') .replace(']', '') .replace('[', '-') ] if (widgetControl) { widgetControl.updateFields() wp.customize .control(control) .container.find('textarea') .change() } } ) const widgetControl = wp.customHtmlWidgets.widgetControls[ control .replace('widget_', '') .replace(']', '') .replace('[', '-') ] if (widgetControl) { widgetControl.updateFields() wp.customize .control(control) .container.find('textarea') .change() } jQuery(document).trigger('widget-added', [ wp.customize .control(control) .container.find('.widget:first') ]) }, 50) }) }) } }) const section = new Section(sectionId, {}) wp.customize.section.add(section) const control = new wp.customize.controlConstructor.sidebar_widgets( 'checkcheck', { params: { sidebar_id: sidebarId, priority: 999, section: section.id, setting: `sidebars_widgets[${sidebarId}]`, content: `