def test_make_vdom_constructor(): elmt = make_vdom_constructor("some-tag") assert elmt({"data": 1}, [elmt()]) == { "tagName": "some-tag", "children": [{"tagName": "some-tag"}], "attributes": {"data": 1}, } no_children = make_vdom_constructor("no-children", allow_children=False) with pytest.raises(TypeError, match="cannot have children"): no_children([1, 2, 3]) assert no_children() == {"tagName": "no-children"}
def __init__( self, module: str, name: str, has_children: bool = True, fallback: Optional[str] = "", ) -> None: self._constructor = make_vdom_constructor(name, has_children) self._import_source = ImportSourceDict(source=module, fallback=fallback)
def _make_export( web_module: WebModule, name: str, fallback: Optional[Any], allow_children: bool, ) -> VdomDictConstructor: return partial( make_vdom_constructor( name, allow_children=allow_children, ), import_source=ImportSourceDict( source=web_module.source, sourceType=web_module.source_type, fallback=(fallback or web_module.default_fallback), unmountBeforeUpdate=web_module.unmount_before_update, ), )
def __init__(self) -> None: # External sources self.link = make_vdom_constructor("link", allow_children=False) # Content sectioning self.style = make_vdom_constructor("style") self.address = make_vdom_constructor("address") self.article = make_vdom_constructor("article") self.aside = make_vdom_constructor("aside") self.footer = make_vdom_constructor("footer") self.h1 = make_vdom_constructor("h1") self.h2 = make_vdom_constructor("h2") self.h3 = make_vdom_constructor("h3") self.h4 = make_vdom_constructor("h4") self.h5 = make_vdom_constructor("h5") self.h6 = make_vdom_constructor("h6") self.header = make_vdom_constructor("header") self.hgroup = make_vdom_constructor("hgroup") self.nav = make_vdom_constructor("nav") self.section = make_vdom_constructor("section") # Text content self.blockquote = make_vdom_constructor("blockquote") self.dd = make_vdom_constructor("dd") self.div = make_vdom_constructor("div") self.dl = make_vdom_constructor("dl") self.dt = make_vdom_constructor("dt") self.figcaption = make_vdom_constructor("figcaption") self.figure = make_vdom_constructor("figure") self.hr = make_vdom_constructor("hr", allow_children=False) self.li = make_vdom_constructor("li") self.ol = make_vdom_constructor("ol") self.p = make_vdom_constructor("p") self.pre = make_vdom_constructor("pre") self.ul = make_vdom_constructor("ul") # Inline text semantics self.a = make_vdom_constructor("a") self.abbr = make_vdom_constructor("abbr") self.b = make_vdom_constructor("b") self.br = make_vdom_constructor("br", allow_children=False) self.cite = make_vdom_constructor("cite") self.code = make_vdom_constructor("code") self.data = make_vdom_constructor("data") self.em = make_vdom_constructor("em") self.i = make_vdom_constructor("i") self.kbd = make_vdom_constructor("kbd") self.mark = make_vdom_constructor("mark") self.q = make_vdom_constructor("q") self.s = make_vdom_constructor("s") self.samp = make_vdom_constructor("samp") self.small = make_vdom_constructor("small") self.span = make_vdom_constructor("span") self.strong = make_vdom_constructor("strong") self.sub = make_vdom_constructor("sub") self.sup = make_vdom_constructor("sup") self.time = make_vdom_constructor("time") self.u = make_vdom_constructor("u") self.var = make_vdom_constructor("var") # Image and video self.img = make_vdom_constructor("img", allow_children=False) self.audio = make_vdom_constructor("audio") self.video = make_vdom_constructor("video") self.source = make_vdom_constructor("source", allow_children=False) # Table content self.caption = make_vdom_constructor("caption") self.col = make_vdom_constructor("col") self.colgroup = make_vdom_constructor("colgroup") self.table = make_vdom_constructor("table") self.tbody = make_vdom_constructor("tbody") self.td = make_vdom_constructor("td") self.tfoot = make_vdom_constructor("tfoot") self.th = make_vdom_constructor("th") self.thead = make_vdom_constructor("thead") self.tr = make_vdom_constructor("tr") # Forms self.meter = make_vdom_constructor("meter") self.output = make_vdom_constructor("output") self.progress = make_vdom_constructor("progress") self.input = make_vdom_constructor("input", allow_children=False) self.button = make_vdom_constructor("button") self.label = make_vdom_constructor("label") self.fieldset = make_vdom_constructor("fieldset") self.legend = make_vdom_constructor("legend") # Interactive elements self.details = make_vdom_constructor("details") self.dialog = make_vdom_constructor("dialog") self.menu = make_vdom_constructor("menu") self.menuitem = make_vdom_constructor("menuitem") self.summary = make_vdom_constructor("summary")
def __getattr__(self, tag: str) -> VdomDictConstructor: return make_vdom_constructor(tag)
"progress", "input", "button", "label", "fieldset", "legend", # Interactive elements "details", "dialog", "menu", "menuitem", "summary", ] # External sources link = make_vdom_constructor("link", allow_children=False) # Content sectioning style = make_vdom_constructor("style") address = make_vdom_constructor("address") article = make_vdom_constructor("article") aside = make_vdom_constructor("aside") footer = make_vdom_constructor("footer") h1 = make_vdom_constructor("h1") h2 = make_vdom_constructor("h2") h3 = make_vdom_constructor("h3") h4 = make_vdom_constructor("h4") h5 = make_vdom_constructor("h5") h6 = make_vdom_constructor("h6") header = make_vdom_constructor("header") hgroup = make_vdom_constructor("hgroup")