mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-23 23:27:09 +00:00
Add map node and refactor defaults
This commit is contained in:
@@ -1,26 +1,29 @@
|
||||
import { AbstractNode, NodeMods, RenderOptions } from './AbstractNode'
|
||||
import { AbstractNode, NodeMods, RenderOptions, StateNode } from './AbstractNode'
|
||||
import { DataModel } from '../model/DataModel'
|
||||
import { TreeView } from '../view/TreeView'
|
||||
import { Path } from '../model/Path'
|
||||
|
||||
export class EnumNode extends AbstractNode<string> {
|
||||
export class EnumNode extends AbstractNode<string> implements StateNode<string> {
|
||||
protected options: string[]
|
||||
|
||||
constructor(options: string[], mods?: NodeMods<string>) {
|
||||
super(mods)
|
||||
super(mods, () => '')
|
||||
this.options = options
|
||||
}
|
||||
|
||||
updateModel(el: Element, path: Path, model: DataModel) {
|
||||
model.set(path, el.querySelector('select')?.value)
|
||||
getState(el: Element) {
|
||||
return el.querySelector('select')!.value
|
||||
}
|
||||
|
||||
render(path: Path, value: string, view: TreeView, options?: RenderOptions) {
|
||||
updateModel(el: Element, path: Path, model: DataModel) {
|
||||
model.set(path, this.getState(el))
|
||||
}
|
||||
|
||||
renderRaw(path: Path, value: string, view: TreeView, options?: RenderOptions) {
|
||||
const id = view.register(el => (el as HTMLInputElement).value = value)
|
||||
return this.wrap(path, view, `
|
||||
${options?.hideLabel ? `` : `<label>${path.last()}</label>`}
|
||||
return `${options?.hideLabel ? `` : `<label>${path.last()}</label>`}
|
||||
<select data-id=${id}>
|
||||
${this.options.map(o => `<option value="${o}">${o}</option>`).join('')}
|
||||
</select>`)
|
||||
</select>`
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user