import { __ } from '@wordpress/i18n'; import { InspectorControls, MediaUpload, MediaUploadCheck } from '@wordpress/block-editor'; import { BaseControl, ButtonGroup, Button, PanelBody, TabPanel, ToggleControl, SelectControl, TextControl, RangeControl } from '@wordpress/components'; import CodeMirrorControl from './components/CodeMirrorControl'; import { LANGUAGE_OPTIONS, THEME_OPTIONS, CODE_SNIPPET_WRAPPER_MARGIN, CODE_SNIPPET_WRAPPER_PADDING, CODE_SNIPPET_HEADER_PADDING, CODE_SNIPPET_LINE_NUMBERS_PADDING, CODE_SNIPPET_CODE_PADDING, } from './constants'; import { typoPrefix_fileName } from "./typographyPrefixConstants"; import ResponsiveDimensionsControl from "../../../util/dimensions-control-v2"; import ColorControl from "../../../util/color-control"; import TypographyDropdown from "../../../util/typography-control-v2"; import objAttributes from './attributes'; const Inspector = ({attributes, setAttributes}) => { const { codeContent, language, codeVariants = [], showCopyButton, showHeader, showLineNumbers, theme, lineNumberColor, lineNumberBgColor, lineNumberBorderColor, lineNumberBorderWidth, resOption, fileName, showFileIcon, fileIcon, showTrafficLights, wrapperBackgroundColor, wrapperBorderColor, wrapperBorderWidth, wrapperBorderRadius, headerBackgroundColor, headerBorderColor, headerBorderWidth, fileNameColor, copyButtonColor, copyButtonBorderColor, codeBackgroundColor, } = attributes; const resRequiredProps = { setAttributes, resOption, attributes, objAttributes, }; // Additional-language repeater helpers. The primary language/code above is // variant #1; these append to it. When 1+ exist the frontend shows a // language dropdown to switch between them. const addVariant = () => { setAttributes({ codeVariants: [ ...codeVariants, { language: 'php', codeContent: '' }, ], }); }; const updateVariant = (index, key, value) => { const next = codeVariants.map((variant, i) => i === index ? { ...variant, [key]: value } : variant ); setAttributes({ codeVariants: next }); }; const removeVariant = (index) => { setAttributes({ codeVariants: codeVariants.filter((_, i) => i !== index), }); }; return(
{(tab) => (
{tab.name === 'general' && ( <> setAttributes({ language: value })} help={__("Choose language for syntax highlighting.", "betterdocs")} __next40pxDefaultSize __nextHasNoMarginBottom /> setAttributes({ codeContent: value })} placeholder={__("// Paste or type your code here...", "betterdocs")} rows={15} help={__("Enter your code snippet. Use Tab for indentation. Syntax highlighting will appear in the preview.", "betterdocs")} /> {codeVariants.map((variant, index) => (
{__("Language", "betterdocs")} {index + 2}
updateVariant(index, 'language', value)} __next40pxDefaultSize __nextHasNoMarginBottom /> updateVariant(index, 'codeContent', value)} placeholder={__("// Paste or type your code here...", "betterdocs")} rows={10} />
))}
{THEME_OPTIONS.map((option) => ( ))} setAttributes({ showHeader: value })} help={__("Toggle the filename header and copy button.", "betterdocs")} /> {showHeader && ( setAttributes({ showCopyButton: value })} help={__("Show a one-click copy-to-clipboard icon.", "betterdocs")} /> )} help={__("Display a tooltip (‘Copied!’) on copy button hover or click.", "betterdocs")} /> )} setAttributes({ showLineNumbers: value })} help={__("Display line numbers in the code block.", "betterdocs")} /> {showHeader && ( setAttributes({ fileName: value })} placeholder={__("hero-section.tsx", "betterdocs")} help={__("Enter the name to display in header (e.g., hero-section.tsx)", "betterdocs")} __next40pxDefaultSize __nextHasNoMarginBottom /> setAttributes({ showTrafficLights: value })} help={__("Display macOS-style close/minimize/maximize circles.", "betterdocs")} /> setAttributes({ showFileIcon: value })} help={__("Display the default icon for this file type.", "betterdocs")} /> {showFileIcon && ( setAttributes({ fileIcon: media.url })} allowedTypes={['image']} value={fileIcon} render={({ open }) => (
{fileIcon && ( <> {__("File )}
)} />
)}
)} )} {tab.name === 'styles' && (
{ setAttributes({wrapperBackgroundColor: colorValue}) }} /> { setAttributes({wrapperBorderColor: colorValue}) }} /> setAttributes({wrapperBorderWidth: value})} min={0} max={10} step={1} /> setAttributes({wrapperBorderRadius: value})} min={0} max={50} step={1} /> {showHeader && ( { setAttributes({headerBackgroundColor: colorValue}) }} /> { setAttributes({headerBorderColor: colorValue}) }} /> setAttributes({headerBorderWidth: value})} min={0} max={10} step={1} help={__("Controls border bottom width", "betterdocs")} /> { setAttributes({fileNameColor: colorValue}) }} /> { setAttributes({copyButtonColor: colorValue}) }} /> { setAttributes({copyButtonBorderColor: colorValue}) }} /> )} {showLineNumbers && ( { setAttributes({lineNumberColor: colorValue}) }} /> { setAttributes({lineNumberBgColor: colorValue}) }} /> { setAttributes({lineNumberBorderColor: colorValue}) }} /> setAttributes({lineNumberBorderWidth: value})} min={0} max={10} step={1} help={__("Controls border right width", "betterdocs")} /> )} { setAttributes({codeBackgroundColor: colorValue}) }} />
)}
)}
); } export default Inspector;