Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/purple-kiwis-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@compai/css-gui': patch
---

Select outer root when html editor mounts
102 changes: 56 additions & 46 deletions packages/gui/src/components/html/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,36 @@ type ElementPath = number[]
* An HTML tree-based editor that lets you add HTML nodes and mess around with their styles
*/
export function HtmlEditor({ value, onChange }: EditorProps) {
const [selected, setSelected] = useState<ElementPath | null>(null)
const [selected, setSelected] = useState<ElementPath | null>(
value ? [0] : null
)
return (
<div sx={{
display: 'flex',
width: 'auto',
}}>
<div sx={{
pt: 3,
pb: 3,
borderColor: 'border',
borderRightWidth: '1px',
borderRightStyle: 'solid',
borderBottomWidth: '1px',
borderBottomStyle: 'solid',
overflowX: 'auto',
resize: 'horizontal',
}}>
<TreeNode
value={value}
onSelect={setSelected}
path={[]}
onChange={onChange}
/>
</div>
<div
sx={{
display: 'flex',
width: 'auto',
}}
>
<div
sx={{
pt: 3,
pb: 3,
borderColor: 'border',
borderRightWidth: '1px',
borderRightStyle: 'solid',
borderBottomWidth: '1px',
borderBottomStyle: 'solid',
overflowX: 'auto',
resize: 'horizontal',
}}
>
<TreeNode
value={value}
onSelect={setSelected}
path={[]}
onChange={onChange}
/>
</div>
{selected && (
<NodeEditor
value={getChildAtPath(value, selected)}
Expand All @@ -84,17 +90,19 @@ interface TagEditorProps extends EditorProps {
function NodeEditor({ value, onChange, onRemove }: TagEditorProps) {
const nodeType = typeof value === 'string' ? 'text' : 'tag'
return (
<div sx={{
resize: 'horizontal',
overflowX: 'auto',
p: 3,
borderRightWidth: '1px',
borderRightStyle: 'solid',
borderBottomWidth: '1px',
borderBottomStyle: 'solid',
borderColor: 'border',
}}>
<div sx={{ mb: 2, display: 'flex', alignItems: 'flex-end'}}>
<div
sx={{
resize: 'horizontal',
overflowX: 'auto',
p: 3,
borderRightWidth: '1px',
borderRightStyle: 'solid',
borderBottomWidth: '1px',
borderBottomStyle: 'solid',
borderColor: 'border',
}}
>
<div sx={{ mb: 2, display: 'flex', alignItems: 'flex-end' }}>
<SelectInput
label="Type"
value={nodeType}
Expand Down Expand Up @@ -134,12 +142,14 @@ function NodeSwitch({ value, onChange }: EditorProps) {

return (
<div>
<article sx={{
borderBottomWidth: '1px',
borderBottomStyle: 'solid',
borderBottomColor: 'border',
mb: 3,
}}>
<article
sx={{
borderBottomWidth: '1px',
borderBottomStyle: 'solid',
borderBottomColor: 'border',
mb: 3,
}}
>
<div sx={{ mb: 2 }}>
<Label>Tag name</Label>{' '}
<Combobox
Expand All @@ -152,7 +162,7 @@ function NodeSwitch({ value, onChange }: EditorProps) {
onChange({
...value,
tagName: selectedItem,
style: mergedStyles
style: mergedStyles,
})
}}
items={HTML_TAGS}
Expand All @@ -172,11 +182,11 @@ function NodeSwitch({ value, onChange }: EditorProps) {
<div>
<Label> 🎨 Styles</Label>
<div sx={{ mt: 2 }}>
<Editor
styles={value.style ?? {}}
onChange={(newStyles) => onChange({ ...value, style: newStyles })}
showAddProperties
/>
<Editor
styles={value.style ?? {}}
onChange={(newStyles) => onChange({ ...value, style: newStyles })}
showAddProperties
/>
</div>
</div>
</div>
Expand Down