import React, { useState } from 'react' import type { WObject } from '@/lib/wysiwyg/schema' export type PropsPanelProps = { object: WObject onChange?: (next: WObject) => void } function num(v: string, fallback: number) { const n = Number(v) return Number.isFinite(n) ? n : fallback } function isImage(o: WObject): o is Extract { return o.type === 'image' } export function PropsPanel({ object, onChange }: PropsPanelProps) { const [model, setModel] = useState(object) const emit = (next: WObject) => { setModel(next) onChange?.(next) } const update = (patch: Partial>): void => { const next: WObject = { ...model, ...patch } emit(next) } const updateImageProps = (patch: Partial<{ src: string; alt?: string }>): void => { if (!isImage(model)) return const next: WObject = { ...model, props: { ...model.props, ...patch } } emit(next) } return (
{isImage(model) && (
)}
) }