// src/withInspectorControl.tsx import { createHigherOrderComponent } from '@wordpress/compose'; import { InspectorControls } from '@wordpress/block-editor'; import { PanelBody } from '@wordpress/components'; import { Fragment, useState } from '@wordpress/element'; import { StyleControl } from './StyleControl'; import { LayoutControl } from './LayoutControl'; import { MediaControl } from './MediaControl'; import { MotionControl } from './MotionControl'; import CubeIcon from 'blockbite-icons/dist/Cube'; import LayoutIcon from 'blockbite-icons/dist/Layout'; import DimensionsIcon from 'blockbite-icons/dist/Dimensions'; import ImageIcon from 'blockbite-icons/dist/Image'; import TokenIcon from 'blockbite-icons/dist/Tokens'; import LightningBoltIcon from 'blockbite-icons/dist/LightningBolt'; import { Icon } from '@components/ui/Icon'; import { useDynamicBlockSupportHook } from '@components/Settings/BlockSupport/BlockSupportHooks'; import DynamicBlockSupport from '@components/Settings/BlockSupport/DynamicBlockSupport'; import { useBlockSupportStore } from '@components/Settings/BlockSupport/BlockSupportStore'; import { allowedBlockbiteBlock, isLayoutVisualBlock, useIsSelectedOrChild, } from './ControlHelpers'; import { useDefaultPreset } from '@components/PresetPanel/useDefaultPreset'; import PresetPanel from '@components/PresetPanel/PresetPanel'; import { TabsWrapper, TabsList, TabsContent } from '@components/ui/Tabs'; import { StyleInspector } from './StyleInspector'; import { InteractionControl } from './InteractionControl'; interface WithInspectorControlProps { name: string; attributes: { [key: string]: any }; setAttributes: (attributes: { [key: string]: any }) => void; isSelected: boolean; clientId: string; } export const BiteStyleControl = createHigherOrderComponent((BlockEdit: any) => { return (props: WithInspectorControlProps) => { const { name, isSelected, clientId } = props; const [inspectorViewTab, setInspectorViewTab] = useState('design'); const [currentPresetId] = useState(null); /* * Check if block is dynamic and if it is allowed */ const blockDynamicSupport = useDynamicBlockSupportHook(name); const hasSupport = !blockDynamicSupport.is_dynamic || blockDynamicSupport.is_allowed; const isLayoutVisual = isLayoutVisualBlock(name); const isSelectedOrChild = useIsSelectedOrChild(clientId, isSelected); useDefaultPreset({ props, isLayoutVisual, isSelectedOrChild, currentPresetId, }); const handleStyleInspectorOpen = () => { wp.data.dispatch('core/edit-post').openGeneralSidebar('edit-post/block'); setInspectorViewTab('current'); }; if (!allowedBlockbiteBlock(name)) { return ( ); } else { return ( {isSelected && ( , }, ] : []), ...(isLayoutVisual.layout ? [ { name: 'layout', title: 'Layout', icon: , }, ] : []), ...(isLayoutVisual.visual ? [ { name: 'media', title: 'Media', icon: , }, ] : []), ...(hasSupport ? [ { name: 'motion', title: 'Motion', icon: , }, ] : []), ...(hasSupport ? [ { name: 'library', title: 'Library', icon: , }, ] : []), ...(hasSupport ? [ { name: 'interaction', title: 'Interaction', icon: , }, ] : []), ]} /> {hasSupport && ( )} {isLayoutVisual.layout && ( )} {isLayoutVisual.visual && ( )} {hasSupport && ( )} {hasSupport && ( )} {hasSupport && ( )} {!hasSupport && ( { const { setAllowedDynamic } = useBlockSupportStore.getState(); setAllowedDynamic(dynamic_blocks); }} /> )} )} ); } }; }, 'withInspectorControl');