mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-25 08:06:51 +00:00
Add map node and refactor defaults
This commit is contained in:
@@ -4,13 +4,11 @@ import { TreeView } from '../view/TreeView'
|
||||
import { Path } from '../model/Path'
|
||||
import { IObject } from './ObjectNode'
|
||||
|
||||
|
||||
|
||||
export class ListNode extends AbstractNode<IObject[]> {
|
||||
protected children: INode<any>
|
||||
|
||||
constructor(values: INode<any>, mods?: NodeMods<IObject[]>) {
|
||||
super(mods)
|
||||
super(mods, () => [])
|
||||
this.children = values
|
||||
}
|
||||
|
||||
@@ -18,18 +16,18 @@ export class ListNode extends AbstractNode<IObject[]> {
|
||||
model.set(path, el.querySelector('select')?.value)
|
||||
}
|
||||
|
||||
render(path: Path, value: IObject[], view: TreeView) {
|
||||
renderRaw(path: Path, value: IObject[], view: TreeView) {
|
||||
value = value || []
|
||||
const button = view.registerClick(el => {
|
||||
view.model.set(path, [...value, this.children.default()])
|
||||
})
|
||||
return this.wrap(path, view, `<label>${path.last()}:</label>
|
||||
return `<label>${path.last()}:</label>
|
||||
<button data-id="${button}">Add</button>
|
||||
<div style="padding-left:8px">
|
||||
${value.map((obj, index) => {
|
||||
return this.renderEntry(path.push(index), obj, view)
|
||||
}).join('')}
|
||||
</div>`)
|
||||
</div>`
|
||||
}
|
||||
|
||||
private renderEntry(path: Path, value: IObject, view: TreeView) {
|
||||
|
||||
Reference in New Issue
Block a user