import { createElement, Fragment, Component, useRef, useEffect, useState } from '@wordpress/element' import { registerPlugin, withPluginContext } from '@wordpress/plugins' import { PluginSidebar, PluginSidebarMoreMenuItem } from '@wordpress/edit-post' import { withSelect, withDispatch } from '@wordpress/data' import { compose } from '@wordpress/compose' import { IconButton } from '@wordpress/components' import { handleMetaboxValueChange } from './editor/sync' import { __ } from 'ct-i18n' import { OptionsPanel, getValueFromInput, PanelLevel, DeviceManagerProvider } from 'blocksy-options' const BlocksyOptions = ({ name, value, options, onChange, isActive, isPinnable = true, isPinned, togglePin, toggleSidebar, closeGeneralSidebar }) => { const containerRef = useRef() const parentContainerRef = useRef() const [values, setValues] = useState(null) useEffect(() => { document.body.classList[isActive ? 'add' : 'remove']( 'blocksy-sidebar-active' ) }, [isActive]) return ( {__('Blocksy Page Settings', 'blocksy')} } className="ct-components-panel" title={__('Blocksy Page Settings', 'blocksy')}>
{__('Blocksy Page Settings', 'blocksy')} {isPinnable && ( )}
{ const futureValue = { ...(values || getValueFromInput( options, value || {} )), [key]: v } handleMetaboxValueChange(key, v) onChange(futureValue) setValues(futureValue) }} value={ values || getValueFromInput(options, value || {}) } options={options} />
) } const BlocksyOptionsComposed = compose( withPluginContext((context, { name }) => ({ sidebarName: `${context.name}/${name}` })), withSelect((select, { sidebarName }) => { const value = select('core/editor').getEditedPostAttribute( 'blocksy_meta' ) const { getActiveGeneralSidebarName, isPluginItemPinned } = select( 'core/edit-post' ) return { isActive: getActiveGeneralSidebarName() === sidebarName, isPinned: isPluginItemPinned(sidebarName), value: Array.isArray(value) ? {} : value || {}, options: ct_editor_localizations.post_options } }), withDispatch((dispatch, { sidebarName }) => { const { closeGeneralSidebar, openGeneralSidebar, togglePinnedPluginItem } = dispatch('core/edit-post') return { closeGeneralSidebar, togglePin: () => { togglePinnedPluginItem(sidebarName) }, onChange: blocksy_meta => { dispatch('core/editor').editPost({ blocksy_meta }) } } }) )(BlocksyOptions) if (ct_editor_localizations.post_options) { registerPlugin('blocksy', { render: () => }) }