add Block + Component, add TextComponent with min, max and regex validators and early NumberComponent
This commit is contained in:
42
internal/block/block.go
Normal file
42
internal/block/block.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package block
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Block struct {
|
||||
Components []Component
|
||||
}
|
||||
|
||||
type BlockInstance struct {
|
||||
Components []ComponentInstance
|
||||
}
|
||||
|
||||
func (b *BlockInstance) FromJSON(block *Block, data []byte) error {
|
||||
var raw map[string]json.RawMessage
|
||||
if err := json.Unmarshal(data, &raw); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var components []ComponentInstance
|
||||
|
||||
for _, c := range block.Components {
|
||||
jsonValue, ok := raw[c.Identifier()]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
instance := c.NewInstance()
|
||||
|
||||
if err := instance.FromJSON(c, jsonValue); err != nil {
|
||||
return err
|
||||
}
|
||||
components = append(components, instance)
|
||||
|
||||
fmt.Println(c.Identifier(), instance)
|
||||
}
|
||||
|
||||
b.Components = components
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user