forked from tsai/budibase
4 changed files with 0 additions and 63 deletions
@ -1,14 +0,0 @@ |
|||||
import { ComponentBuilder } from "./component-builder" |
|
||||
|
|
||||
export class BlockBuilder { |
|
||||
context |
|
||||
componentCount = 0 |
|
||||
|
|
||||
constructor(context) { |
|
||||
this.context = context |
|
||||
} |
|
||||
|
|
||||
createComponent(type, props) { |
|
||||
return new ComponentBuilder(this, type, props) |
|
||||
} |
|
||||
} |
|
||||
@ -1,49 +0,0 @@ |
|||||
export class ComponentBuilder { |
|
||||
context |
|
||||
|
|
||||
constructor(blockBuilder, type, props) { |
|
||||
this.blockBuilder = blockBuilder |
|
||||
this.type = type |
|
||||
this.id = `${blockBuilder.context.id}-${blockBuilder.componentCount++}` |
|
||||
this.props = props |
|
||||
this.children = [] |
|
||||
this.styles = null |
|
||||
} |
|
||||
|
|
||||
setProp(key, value) { |
|
||||
this.props[key] = value |
|
||||
return this |
|
||||
} |
|
||||
|
|
||||
setProps(props) { |
|
||||
this.props = { |
|
||||
...this.props, |
|
||||
...props, |
|
||||
} |
|
||||
return this |
|
||||
} |
|
||||
|
|
||||
setStyles(styles) { |
|
||||
this.styles = styles |
|
||||
return this |
|
||||
} |
|
||||
|
|
||||
addChild(component) { |
|
||||
this.children.push(component) |
|
||||
return this |
|
||||
} |
|
||||
|
|
||||
build() { |
|
||||
return { |
|
||||
_component: `@budibase/standard-components/${this.type}`, |
|
||||
_id: this.id, |
|
||||
_children: this.children?.map(child => child.build()), |
|
||||
_styles: { |
|
||||
normal: { |
|
||||
...this.styles, |
|
||||
}, |
|
||||
}, |
|
||||
...this.props, |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue