import { InspectorControls, useBlockProps } from '@wordpress/block-editor'; import { Button, PanelBody, RangeControl, SelectControl, TabPanel, ToggleControl, __experimentalNumberControl as NumberControl } from '@wordpress/components'; import ServerSideRender from '@wordpress/server-side-render'; import { __ } from '@wordpress/i18n'; import Big from 'big.js'; import type { TickerAttributes, TickerPair } from './types'; import { getCurrencies } from '../../currencies'; import { CurrencyRichSelect } from '../shared/CurrencyRichSelect'; import { SourceCurrencyNotice } from '../shared/SourceCurrencyNotice'; import '../shared/editorGlobals'; import { normalizeAmountInput, useAvailableCodes, buildSourceOptions, parseSourceValue, } from '../shared/editorUtils'; type EditProps = { attributes: TickerAttributes; setAttributes: (next: Partial) => void; }; const currencies = getCurrencies(); export const TickerEdit = ({ attributes, setAttributes }: EditProps) => { const blockProps = useBlockProps(); const editorUi = window.crtodayEditorCurrenciesUi ?? {}; const editorLabels = editorUi.labels ?? {}; const availableCodes = useAvailableCodes(attributes.sourceId, attributes.deal); return (
{(tab) => tab.name === 'settings' ? ( <> { if (!value) return; const { sourceId, deal } = parseSourceValue(value); setAttributes({ sourceId, deal }); }} /> { const normalized = normalizeAmountInput(String(value ?? '')); if (normalized === '') return; try { const parsed = new Big(normalized); if (parsed.gt(0)) { setAttributes({ amount: parsed.toString() }); } } catch { return; } }} /> { const parsed = Number(value ?? 0); if (Number.isFinite(parsed)) { setAttributes({ adjustmentPercent: parsed }); } }} /> [p.from, p.to])} /> {attributes.pairs.map((pair: TickerPair, idx: number) => (
))}
) : tab.name === 'ticker' ? ( <> setAttributes({ speed: Number(speed) })} /> setAttributes({ direction: direction as TickerAttributes['direction'] })} /> setAttributes({ pauseOnHover })} /> ) : ( <> setAttributes({ decimals: Number(decimals) })} /> setAttributes({ theme: theme as TickerAttributes['theme'] })} /> setAttributes({ currencyLabelMode: currencyLabelMode as TickerAttributes['currencyLabelMode'] }) } /> setAttributes({ showFlags })} /> setAttributes({ showChange })} /> setAttributes({ attribution })} /> setAttributes({ showTimestamp })} /> setAttributes({ borderY })} /> setAttributes({ borderX })} /> setAttributes({ separator: separator as TickerAttributes['separator'] })} /> ) }
); };