This commit is contained in:
2025-07-23 18:28:00 +03:00
parent 7c7e0db426
commit ebd3a93cb2
21 changed files with 185 additions and 377 deletions

View File

@@ -0,0 +1,39 @@
import { Input } from '@/component/ui/input'
import { ElementDefinition } from '@/entitiy/element/model/interface'
import { ExtraSettingsBadge } from '@/entitiy/element/ui/extraSettingsBadge'
import { Calendar } from 'lucide-react'
interface DateConfig {
required?: boolean
targetCells: any[]
}
export const dateDefinition: ElementDefinition<DateConfig, string> = {
type: 'date',
label: 'Дата',
icon: <Calendar className="h-4 w-4" />,
version: 1,
defaultConfig: {
required: false,
targetCells: [],
},
mapToCells: config => config.targetCells || [],
mapToCellValues: (config, value) => {
const cells = config.targetCells || []
return cells.map(target => ({ target, value: value || '' }))
},
Editor: () => <ExtraSettingsBadge />,
Preview: () => (
<div className="space-y-3">
<Input type="date" className="w-full" />
</div>
),
Render: ({ config, value, onChange }) => (
<Input
type="date"
value={value || ''}
onChange={e => onChange?.(e.target.value)}
required={config.required}
/>
),
}

View File

@@ -1,13 +1,10 @@
import { textDefinition } from '@/component/BasicElements'
import { calibrationConditionsDefinition } from '@/component/BasicElements/CalibrationConditionsElement'
import { checkboxDefinition } from '@/component/BasicElements/CheckboxElement'
import { dateDefinition } from '@/component/BasicElements/DateElement'
import { numberDefinition } from '@/component/BasicElements/NumberElement'
import { radioDefinition } from '@/component/BasicElements/RadioElement'
import { selectDefinition } from '@/component/BasicElements/SelectElement'
import { textareaDefinition } from '@/component/BasicElements/TextareaElement'
import { standardsDefinition } from '@/component/StandardsElement/definition'
import { buttonGroupDefinition } from '@/entitiy/element/model/implementations/ButtonGroup'
import { dateDefinition } from '@/entitiy/element/model/implementations/DateElement'
import { CellTarget } from '@/type/template'
import { ReactNode } from 'react'
@@ -66,10 +63,7 @@ export function getElementDefinition(
export const elementDefinitions = {
text: textDefinition,
select: selectDefinition,
radio: radioDefinition,
checkbox: checkboxDefinition,
number: numberDefinition,
textarea: textareaDefinition,
date: dateDefinition,
standards: standardsDefinition,
calibration_conditions: calibrationConditionsDefinition,
@@ -79,17 +73,11 @@ export const elementDefinitions = {
export type ElementType = keyof typeof elementDefinitions
export function initializeElementRegistry() {
// Базовые элементы
registerElement('text', textDefinition)
registerElement('select', selectDefinition)
registerElement('number', numberDefinition)
registerElement('date', dateDefinition)
registerElement('textarea', textareaDefinition)
registerElement('checkbox', checkboxDefinition)
registerElement('radio', radioDefinition)
registerElement('button_group', buttonGroupDefinition)
registerElement('calibration_conditions', calibrationConditionsDefinition)
// Специальные элементы
registerElement('standards', standardsDefinition)
}