import { InspectorControls, FontSizePicker } from "@wordpress/block-editor"; import { __ } from "@wordpress/i18n"; import { PanelBody, SelectControl, Button, PanelRow, BaseControl, } from "@wordpress/components"; import { ColorControl, SizeControl, SpacingControlSingle, } from "@tableberg/components"; import { useTableStore } from "../../store"; import { DynamicDataPanel } from "../../components/DynamicDataPanel"; import LockedControl from "../../components/LockedControl"; import { ListElementAttributes, listAttrDefaults } from "./element"; import { CellKey } from "../../attributes"; import { ElementBindings } from "../../dynamic-data/types"; import { isProAvailable } from "../../pro-status"; interface ListElementControlsProps { attributes: ListElementAttributes; bindings?: ElementBindings; cellCoords: CellKey; elementIndex: number; allowListTypeSwitch?: boolean; // Injected by the pro plugin; null when pro is not installed. ProListIconSettings?: React.ReactNode; // Native block edits inject a setAttributes-based updater; store-backed // element renderers use the table-store fallback. updateAttrs?: (attrs: Partial) => void; } export function ListElementControls({ attributes, bindings, cellCoords, elementIndex, allowListTypeSwitch = true, updateAttrs, ProListIconSettings = null, }: ListElementControlsProps) { const isPro = isProAvailable(); const updateCellElement = useTableStore(state => state.updateCellElement); const applyAttrs = updateAttrs ?? ((attrs: Partial) => updateCellElement(cellCoords, elementIndex, { attributes: attrs, })); const updateListType = (listType: "basic" | "styled") => { applyAttrs({ listType }); }; const updateListStyle = (listStyle: ListElementAttributes["listStyle"]) => { applyAttrs({ listStyle }); }; const updateStyle = ( key: K, value: ListElementAttributes["styles"][K] ) => { applyAttrs({ styles: { ...attributes.styles, [key]: value, }, }); }; return ( <> {allowListTypeSwitch && isPro && ( { updateListType(value as "basic" | "styled"); }} /> )} {allowListTypeSwitch && !isPro && ( null} /> )} {attributes.listType === "basic" && ( { updateListStyle( value as ListElementAttributes["listStyle"] ); }} /> )} updateStyle("itemSpacing", value)} /> {/* * Icon markers are a pro feature: pro hands the whole Icon * Settings panel down. Free has no icon implementation. */} {attributes.listType === "styled" && ProListIconSettings} { if (!value) { return; } updateStyle("fontSize", String(value)); }} /> updateStyle("iconColor", value)} onDeselect={() => updateStyle( "iconColor", listAttrDefaults.styles.iconColor ) } /> updateStyle("textColor", value)} onDeselect={() => updateStyle( "textColor", listAttrDefaults.styles.textColor ) } /> updateStyle("linkColor", value)} onDeselect={() => updateStyle( "linkColor", listAttrDefaults.styles.linkColor ) } /> updateStyle("backgroundColor", value)} onDeselect={() => updateStyle( "backgroundColor", listAttrDefaults.styles.backgroundColor ) } /> ); }