import { createElement, Fragment, Component, useCallback, 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, Button } from '@wordpress/components' import { handleMetaboxValueChange, mountSync } from './editor/sync' import ctEvents from 'ct-events' import { __, sprintf } from 'ct-i18n' import { OptionsPanel, getValueFromInput, PanelLevel, DeviceManagerProvider, } from 'blocksy-options' import { SVG, Path } from '@wordpress/primitives' const closeSmall = ( ) const starEmpty = ( ) const starFilled = ( ) 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]) const handleChange = ({ id: key, value: v }) => { const futureValue = { ...(values || getValueFromInput(options, value || {})), [key]: v, } handleMetaboxValueChange(key, v) onChange(futureValue) setValues(futureValue) } useEffect(() => { ctEvents.on('ct:metabox:options:trigger-change', handleChange) return () => { ctEvents.off('ct:metabox:options:trigger-change', handleChange) } }, []) return ( {sprintf( __('%s Page Settings', 'blocksy'), ct_localizations.product_name )} } className="ct-components-panel" title={sprintf( __('%s Page Settings', 'blocksy'), ct_localizations.product_name )}>
{sprintf( __('%s Page Settings', 'blocksy'), ct_localizations.product_name )} {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: () => , }) }