import type * as CSS from 'csstype'; import { propPanel as parentPropPanel } from '../text/propPanel.js'; import { Plugin, PropPanelWidgetProps, SchemaForUI } from '@pdfme/common'; import text from '../text/index.js'; import { TextSchema } from '../text/types.js'; import { ChevronDown } from 'lucide'; import { createSvgStr } from '../utils.js'; const selectIcon = createSvgStr(ChevronDown); interface Select extends TextSchema { options: string[]; } const addOptions = (props: PropPanelWidgetProps) => { const { rootElement, changeSchemas, activeSchema, i18n } = props; rootElement.style.width = '100%'; const selectSchema = activeSchema as SchemaForUI & Select; const currentOptions = selectSchema.options ? [...selectSchema.options] : []; const inputStyle = { width: '100%', padding: '6.25px 11px', border: '1px solid #ccc', borderRadius: '4px', }; const buttonStyle = { border: 'none', borderRadius: '4px', cursor: 'pointer' }; const updateSchemas = () => { changeSchemas([ { key: 'options', value: currentOptions, schemaId: activeSchema.id }, { key: 'content', value: currentOptions[0] || '', schemaId: activeSchema.id }, ]); }; const formContainer = document.createElement('div'); Object.assign(formContainer.style, { width: '100%', display: 'flex', alignItems: 'center', marginBottom: '10px', }); const input = document.createElement('input'); input.type = 'text'; input.placeholder = i18n('schemas.select.optionPlaceholder'); Object.assign(input.style, inputStyle, { marginRight: '10px' }); const addButton = document.createElement('button'); addButton.textContent = '+'; Object.assign(addButton.style, buttonStyle, { width: '25px', height: '25px', padding: '4px 8px', }); addButton.addEventListener('click', () => { const newValue = input.value.trim(); if (newValue) { currentOptions.push(newValue); updateSchemas(); renderOptions(); input.value = ''; } }); formContainer.appendChild(input); formContainer.appendChild(addButton); const optionsList = document.createElement('ul'); Object.assign(optionsList.style, { listStyle: 'none', padding: '0' }); const renderOptions = () => { optionsList.innerHTML = ''; currentOptions.forEach((option, index) => { const li = document.createElement('li'); Object.assign(li.style, { display: 'flex', alignItems: 'center', marginBottom: '5px' }); const optionInput = document.createElement('input'); optionInput.type = 'text'; optionInput.value = option; Object.assign(optionInput.style, inputStyle, { marginRight: '10px' }); optionInput.addEventListener('change', () => { currentOptions[index] = optionInput.value; updateSchemas(); }); const removeButton = document.createElement('button'); removeButton.textContent = 'x'; Object.assign(removeButton.style, buttonStyle, { padding: '4px 8px' }); removeButton.addEventListener('click', () => { currentOptions.splice(index, 1); updateSchemas(); renderOptions(); }); li.appendChild(optionInput); li.appendChild(removeButton); optionsList.appendChild(li); }); }; rootElement.appendChild(formContainer); rootElement.appendChild(optionsList); renderOptions(); }; const schema: Plugin