diff --git a/frontends/nextjs/src/components/editors/lua/blocks/BlockFields.tsx b/frontends/nextjs/src/components/editors/lua/blocks/BlockFields.tsx new file mode 100644 index 000000000..9a9559bd9 --- /dev/null +++ b/frontends/nextjs/src/components/editors/lua/blocks/BlockFields.tsx @@ -0,0 +1,55 @@ +import { Box, MenuItem, TextField, Typography } from '@mui/material' +import type { BlockDefinition, LuaBlock } from '../types' +import styles from '../LuaBlocksEditor.module.scss' + +interface BlockFieldsProps { + block: LuaBlock + definition: BlockDefinition + onUpdateField: (blockId: string, fieldName: string, value: string) => void +} + +export const BlockFields = ({ block, definition, onUpdateField }: BlockFieldsProps) => { + if (definition.fields.length === 0) return null + + return ( + + {definition.fields.map((field) => ( + + {field.label} + {field.type === 'select' ? ( + onUpdateField(block.id, field.name, event.target.value)} + fullWidth + variant="outlined" + InputProps={{ + sx: { backgroundColor: 'rgba(255,255,255,0.95)' }, + }} + > + {field.options?.map((option) => ( + + {option.label} + + ))} + + ) : ( + onUpdateField(block.id, field.name, event.target.value)} + placeholder={field.placeholder} + fullWidth + variant="outlined" + type={field.type === 'number' ? 'number' : 'text'} + InputProps={{ + sx: { backgroundColor: 'rgba(255,255,255,0.95)' }, + }} + /> + )} + + ))} + + ) +} diff --git a/frontends/nextjs/src/components/editors/lua/blocks/BlockItem.tsx b/frontends/nextjs/src/components/editors/lua/blocks/BlockItem.tsx index 938a26451..f13dc5d8e 100644 --- a/frontends/nextjs/src/components/editors/lua/blocks/BlockItem.tsx +++ b/frontends/nextjs/src/components/editors/lua/blocks/BlockItem.tsx @@ -1,21 +1,9 @@ import type { MouseEvent } from 'react' -import { - Box, - Button, - IconButton, - MenuItem, - TextField, - Tooltip, - Typography, -} from '@mui/material' -import { - Add as AddIcon, - ArrowDownward, - ArrowUpward, - ContentCopy, - Delete as DeleteIcon, -} from '@mui/icons-material' +import { Box, IconButton, Tooltip, Typography } from '@mui/material' +import { ArrowDownward, ArrowUpward, ContentCopy, Delete as DeleteIcon } from '@mui/icons-material' import type { BlockDefinition, BlockSlot, LuaBlock } from '../types' +import { BlockSection } from './BlockSection' +import { BlockFields } from './BlockFields' import styles from '../LuaBlocksEditor.module.scss' interface BlockItemProps { @@ -34,102 +22,6 @@ interface BlockItemProps { renderNestedList: (blocks?: LuaBlock[]) => JSX.Element } -interface BlockSectionProps { - title: string - blocks: LuaBlock[] | undefined - parentId: string - slot: BlockSlot - onRequestAddBlock: ( - event: MouseEvent, - target: { parentId: string | null; slot: BlockSlot } - ) => void - renderNestedList: (blocks?: LuaBlock[]) => JSX.Element -} - -const BlockSection = ({ - title, - blocks, - parentId, - slot, - onRequestAddBlock, - renderNestedList, -}: BlockSectionProps) => ( - - - {title} - - - - {blocks && blocks.length > 0 ? ( - renderNestedList(blocks) - ) : ( - Drop blocks here to build this section. - )} - - -) - -const BlockFields = ({ - block, - definition, - onUpdateField, -}: { - block: LuaBlock - definition: BlockDefinition - onUpdateField: (blockId: string, fieldName: string, value: string) => void -}) => { - if (definition.fields.length === 0) return null - - return ( - - {definition.fields.map((field) => ( - - {field.label} - {field.type === 'select' ? ( - onUpdateField(block.id, field.name, event.target.value)} - fullWidth - variant="outlined" - InputProps={{ - sx: { backgroundColor: 'rgba(255,255,255,0.95)' }, - }} - > - {field.options?.map((option) => ( - - {option.label} - - ))} - - ) : ( - onUpdateField(block.id, field.name, event.target.value)} - placeholder={field.placeholder} - fullWidth - variant="outlined" - type={field.type === 'number' ? 'number' : 'text'} - InputProps={{ - sx: { backgroundColor: 'rgba(255,255,255,0.95)' }, - }} - /> - )} - - ))} - - ) -} - export const BlockItem = ({ block, definition, diff --git a/frontends/nextjs/src/components/editors/lua/blocks/BlockSection.tsx b/frontends/nextjs/src/components/editors/lua/blocks/BlockSection.tsx new file mode 100644 index 000000000..902f35c6e --- /dev/null +++ b/frontends/nextjs/src/components/editors/lua/blocks/BlockSection.tsx @@ -0,0 +1,47 @@ +import type { MouseEvent } from 'react' +import { Box, Button, Typography } from '@mui/material' +import { Add as AddIcon } from '@mui/icons-material' +import type { BlockSlot, LuaBlock } from '../types' +import styles from '../LuaBlocksEditor.module.scss' + +interface BlockSectionProps { + title: string + blocks: LuaBlock[] | undefined + parentId: string + slot: BlockSlot + onRequestAddBlock: ( + event: MouseEvent, + target: { parentId: string | null; slot: BlockSlot } + ) => void + renderNestedList: (blocks?: LuaBlock[]) => JSX.Element +} + +export const BlockSection = ({ + title, + blocks, + parentId, + slot, + onRequestAddBlock, + renderNestedList, +}: BlockSectionProps) => ( + + + {title} + + + + {blocks && blocks.length > 0 ? ( + renderNestedList(blocks) + ) : ( + Drop blocks here to build this section. + )} + + +)