Browse Source

Simplify elements internal api by removing Tag interface completely and rely on existing HTMLElement hierarchy (#779)

* Relax upperbound for ElementBuilder to Element

It's still a lie since there's a HTMLElement cast later on but it will
make possible further improvements

* Don't use Tags anywhere in code

* Remove Tags completely
MERGE_HTML_BUILDER
Shagen Ogandzhanian 3 years ago committed by GitHub
parent
commit
60944c87c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 246
      web/core/src/jsMain/kotlin/androidx/compose/web/attributes/Attrs.kt
  2. 4
      web/core/src/jsMain/kotlin/androidx/compose/web/attributes/AttrsBuilder.kt
  3. 12
      web/core/src/jsMain/kotlin/androidx/compose/web/elements/Base.kt
  4. 117
      web/core/src/jsMain/kotlin/androidx/compose/web/elements/Elements.kt
  5. 7
      web/core/src/jsMain/kotlin/androidx/compose/web/elements/Style.kt
  6. 3
      web/core/src/jsTest/kotlin/elements/ElementsTests.kt

246
web/core/src/jsMain/kotlin/androidx/compose/web/attributes/Attrs.kt

@ -1,327 +1,300 @@
package org.jetbrains.compose.web.attributes package org.jetbrains.compose.web.attributes
import org.w3c.dom.HTMLAnchorElement
import org.w3c.dom.HTMLButtonElement
import org.w3c.dom.HTMLFormElement
import org.w3c.dom.HTMLImageElement
import org.w3c.dom.HTMLInputElement import org.w3c.dom.HTMLInputElement
import org.w3c.dom.HTMLLabelElement
interface Tag { import org.w3c.dom.HTMLOptGroupElement
object Div : Tag import org.w3c.dom.HTMLOptionElement
object A : Tag import org.w3c.dom.HTMLSelectElement
object Button : Tag import org.w3c.dom.HTMLTableCellElement
object Form : Tag import org.w3c.dom.HTMLTableColElement
object Input : Tag import org.w3c.dom.HTMLTextAreaElement
object Select : Tag
object Option : Tag fun AttrsBuilder<HTMLAnchorElement>.href(value: String?) =
object OptGroup : Tag
object H : Tag
object Hr : Tag
object Ul : Tag
object Ol : Tag
object Li : Tag
object Img : Tag
object TextArea : Tag
object Nav : Tag
object Span : Tag
object P : Tag
object Br : Tag
object Style : Tag
object Pre : Tag
object Code : Tag
object Label : Tag
object Table : Tag
object Caption : Tag
object Col : Tag
object Colgroup : Tag
object Tr : Tag
object Thead : Tag
object Th : Tag
object Td : Tag
object Tbody : Tag
object Tfoot : Tag
}
/* Anchor <a> attributes */
fun AttrsBuilder<Tag.A>.href(value: String?) =
attr("href", value) attr("href", value)
fun AttrsBuilder<Tag.A>.target(value: ATarget = ATarget.Self) = fun AttrsBuilder<HTMLAnchorElement>.target(value: ATarget = ATarget.Self) =
attr("target", value.targetStr) attr("target", value.targetStr)
fun AttrsBuilder<Tag.A>.ref(value: ARel) = fun AttrsBuilder<HTMLAnchorElement>.ref(value: ARel) =
attr("rel", value.relStr) attr("rel", value.relStr)
fun AttrsBuilder<Tag.A>.ping(value: String) = fun AttrsBuilder<HTMLAnchorElement>.ping(value: String) =
attr("ping", value) attr("ping", value)
fun AttrsBuilder<Tag.A>.ping(vararg urls: String) = fun AttrsBuilder<HTMLAnchorElement>.ping(vararg urls: String) =
attr("ping", urls.joinToString(" ")) attr("ping", urls.joinToString(" "))
fun AttrsBuilder<Tag.A>.hreflang(value: String) = fun AttrsBuilder<HTMLAnchorElement>.hreflang(value: String) =
attr("hreflang", value) attr("hreflang", value)
fun AttrsBuilder<Tag.A>.download(value: String = "") = fun AttrsBuilder<HTMLAnchorElement>.download(value: String = "") =
attr("download", value) attr("download", value)
/* Button attributes */ /* Button attributes */
fun AttrsBuilder<Tag.Button>.autoFocus(value: Boolean = true) = fun AttrsBuilder<HTMLButtonElement>.autoFocus(value: Boolean = true) =
attr("autofocus", if (value) "" else null) attr("autofocus", if (value) "" else null)
fun AttrsBuilder<Tag.Button>.disabled(value: Boolean = true) = fun AttrsBuilder<HTMLButtonElement>.disabled(value: Boolean = true) =
attr("disabled", if (value) "" else null) attr("disabled", if (value) "" else null)
fun AttrsBuilder<Tag.Button>.form(formId: String) = fun AttrsBuilder<HTMLButtonElement>.form(formId: String) =
attr("form", formId) attr("form", formId)
fun AttrsBuilder<Tag.Button>.formAction(url: String) = fun AttrsBuilder<HTMLButtonElement>.formAction(url: String) =
attr("formaction", url) attr("formaction", url)
fun AttrsBuilder<Tag.Button>.formEncType(value: ButtonFormEncType) = fun AttrsBuilder<HTMLButtonElement>.formEncType(value: ButtonFormEncType) =
attr("formenctype", value.typeStr) attr("formenctype", value.typeStr)
fun AttrsBuilder<Tag.Button>.formMethod(value: ButtonFormMethod) = fun AttrsBuilder<HTMLButtonElement>.formMethod(value: ButtonFormMethod) =
attr("formmethod", value.methodStr) attr("formmethod", value.methodStr)
fun AttrsBuilder<Tag.Button>.formNoValidate(value: Boolean = true) = fun AttrsBuilder<HTMLButtonElement>.formNoValidate(value: Boolean = true) =
attr("formnovalidate", if (value) "" else null) attr("formnovalidate", if (value) "" else null)
fun AttrsBuilder<Tag.Button>.formTarget(value: ButtonFormTarget) = fun AttrsBuilder<HTMLButtonElement>.formTarget(value: ButtonFormTarget) =
attr("formtarget", value.targetStr) attr("formtarget", value.targetStr)
fun AttrsBuilder<Tag.Button>.name(value: String) = fun AttrsBuilder<HTMLButtonElement>.name(value: String) =
attr("name", value) attr("name", value)
fun AttrsBuilder<Tag.Button>.type(value: ButtonType) = fun AttrsBuilder<HTMLButtonElement>.type(value: ButtonType) =
attr("type", value.str) attr("type", value.str)
fun AttrsBuilder<Tag.Button>.value(value: String) = fun AttrsBuilder<HTMLButtonElement>.value(value: String) =
attr("value", value) attr("value", value)
/* Form attributes */ /* Form attributes */
fun AttrsBuilder<Tag.Form>.action(value: String) = fun AttrsBuilder<HTMLFormElement>.action(value: String) =
attr("action", value) attr("action", value)
fun AttrsBuilder<Tag.Form>.acceptCharset(value: String) = fun AttrsBuilder<HTMLFormElement>.acceptCharset(value: String) =
attr("accept-charset", value) attr("accept-charset", value)
fun AttrsBuilder<Tag.Form>.autoComplete(value: Boolean) = fun AttrsBuilder<HTMLFormElement>.autoComplete(value: Boolean) =
attr("autocomplete", if (value) "" else null) attr("autocomplete", if (value) "" else null)
fun AttrsBuilder<Tag.Form>.encType(value: FormEncType) = fun AttrsBuilder<HTMLFormElement>.encType(value: FormEncType) =
attr("enctype", value.typeStr) attr("enctype", value.typeStr)
fun AttrsBuilder<Tag.Form>.method(value: FormMethod) = fun AttrsBuilder<HTMLFormElement>.method(value: FormMethod) =
attr("method", value.methodStr) attr("method", value.methodStr)
fun AttrsBuilder<Tag.Form>.noValidate(value: Boolean = true) = fun AttrsBuilder<HTMLFormElement>.noValidate(value: Boolean = true) =
attr("novalidate", if (value) "" else null) attr("novalidate", if (value) "" else null)
fun AttrsBuilder<Tag.Form>.target(value: FormTarget) = fun AttrsBuilder<HTMLFormElement>.target(value: FormTarget) =
attr("target", value.targetStr) attr("target", value.targetStr)
/* Input attributes */ /* Input attributes */
fun AttrsBuilder<Tag.Input>.type(value: InputType) = fun AttrsBuilder<HTMLInputElement>.type(value: InputType) =
attr("type", value.typeStr) attr("type", value.typeStr)
fun AttrsBuilder<Tag.Input>.accept(value: String) = fun AttrsBuilder<HTMLInputElement>.accept(value: String) =
attr("accept", value) // type: file only attr("accept", value) // type: file only
fun AttrsBuilder<Tag.Input>.alt(value: String) = fun AttrsBuilder<HTMLInputElement>.alt(value: String) =
attr("alt", value) // type: image only attr("alt", value) // type: image only
fun AttrsBuilder<Tag.Input>.autoComplete(value: Boolean = true) = fun AttrsBuilder<HTMLInputElement>.autoComplete(value: Boolean = true) =
attr("autocomplete", if (value) "" else null) attr("autocomplete", if (value) "" else null)
fun AttrsBuilder<Tag.Input>.autoFocus(value: Boolean = true) = fun AttrsBuilder<HTMLInputElement>.autoFocus(value: Boolean = true) =
attr("autofocus", if (value) "" else null) attr("autofocus", if (value) "" else null)
fun AttrsBuilder<Tag.Input>.capture(value: String) = fun AttrsBuilder<HTMLInputElement>.capture(value: String) =
attr("capture", value) // type: file only attr("capture", value) // type: file only
fun AttrsBuilder<Tag.Input>.checked(value: Boolean = true) = fun AttrsBuilder<HTMLInputElement>.checked(value: Boolean = true) =
attr("checked", if (value) "" else null) // radio, checkbox attr("checked", if (value) "" else null) // radio, checkbox
fun AttrsBuilder<Tag.Input>.dirName(value: String) = fun AttrsBuilder<HTMLInputElement>.dirName(value: String) =
attr("dirname", value) // text, search attr("dirname", value) // text, search
fun AttrsBuilder<Tag.Input>.disabled(value: Boolean = true) = fun AttrsBuilder<HTMLInputElement>.disabled(value: Boolean = true) =
attr("disabled", if (value) "" else null) attr("disabled", if (value) "" else null)
fun AttrsBuilder<Tag.Input>.form(id: String) = fun AttrsBuilder<HTMLInputElement>.form(id: String) =
attr("form", id) attr("form", id)
fun AttrsBuilder<Tag.Input>.formAction(url: String) = fun AttrsBuilder<HTMLInputElement>.formAction(url: String) =
attr("formaction", url) attr("formaction", url)
fun AttrsBuilder<Tag.Input>.formEncType(value: InputFormEncType) = fun AttrsBuilder<HTMLInputElement>.formEncType(value: InputFormEncType) =
attr("formenctype", value.typeStr) attr("formenctype", value.typeStr)
fun AttrsBuilder<Tag.Input>.formMethod(value: InputFormMethod) = fun AttrsBuilder<HTMLInputElement>.formMethod(value: InputFormMethod) =
attr("formmethod", value.methodStr) attr("formmethod", value.methodStr)
fun AttrsBuilder<Tag.Input>.formNoValidate(value: Boolean = true) = fun AttrsBuilder<HTMLInputElement>.formNoValidate(value: Boolean = true) =
attr("formnovalidate", if (value) "" else null) attr("formnovalidate", if (value) "" else null)
fun AttrsBuilder<Tag.Input>.formTarget(value: InputFormTarget) = fun AttrsBuilder<HTMLInputElement>.formTarget(value: InputFormTarget) =
attr("formtarget", value.targetStr) attr("formtarget", value.targetStr)
fun AttrsBuilder<Tag.Input>.height(value: Int) = fun AttrsBuilder<HTMLInputElement>.height(value: Int) =
attr("height", value.toString()) // image only attr("height", value.toString()) // image only
fun AttrsBuilder<Tag.Input>.width(value: Int) = fun AttrsBuilder<HTMLInputElement>.width(value: Int) =
attr("width", value.toString()) // image only attr("width", value.toString()) // image only
fun AttrsBuilder<Tag.Input>.list(dataListId: String) = fun AttrsBuilder<HTMLInputElement>.list(dataListId: String) =
attr("list", dataListId) attr("list", dataListId)
fun AttrsBuilder<Tag.Input>.max(value: String) = fun AttrsBuilder<HTMLInputElement>.max(value: String) =
attr("max", value) attr("max", value)
fun AttrsBuilder<Tag.Input>.maxLength(value: Int) = fun AttrsBuilder<HTMLInputElement>.maxLength(value: Int) =
attr("maxlength", value.toString()) attr("maxlength", value.toString())
fun AttrsBuilder<Tag.Input>.min(value: String) = fun AttrsBuilder<HTMLInputElement>.min(value: String) =
attr("min", value) attr("min", value)
fun AttrsBuilder<Tag.Input>.minLength(value: Int) = fun AttrsBuilder<HTMLInputElement>.minLength(value: Int) =
attr("minlength", value.toString()) attr("minlength", value.toString())
fun AttrsBuilder<Tag.Input>.multiple(value: Boolean = true) = fun AttrsBuilder<HTMLInputElement>.multiple(value: Boolean = true) =
attr("multiple", if (value) "" else null) attr("multiple", if (value) "" else null)
fun AttrsBuilder<Tag.Input>.name(value: String) = fun AttrsBuilder<HTMLInputElement>.name(value: String) =
attr("name", value) attr("name", value)
fun AttrsBuilder<Tag.Input>.pattern(value: String) = fun AttrsBuilder<HTMLInputElement>.pattern(value: String) =
attr("pattern", value) attr("pattern", value)
fun AttrsBuilder<Tag.Input>.placeholder(value: String) = fun AttrsBuilder<HTMLInputElement>.placeholder(value: String) =
attr("placeholder", value) attr("placeholder", value)
fun AttrsBuilder<Tag.Input>.readOnly(value: Boolean = true) = fun AttrsBuilder<HTMLInputElement>.readOnly(value: Boolean = true) =
attr("readonly", if (value) "" else null) attr("readonly", if (value) "" else null)
fun AttrsBuilder<Tag.Input>.required(value: Boolean = true) = fun AttrsBuilder<HTMLInputElement>.required(value: Boolean = true) =
attr("required", value.toString()) attr("required", value.toString())
fun AttrsBuilder<Tag.Input>.size(value: Int) = fun AttrsBuilder<HTMLInputElement>.size(value: Int) =
attr("size", value.toString()) attr("size", value.toString())
fun AttrsBuilder<Tag.Input>.src(value: String) = fun AttrsBuilder<HTMLInputElement>.src(value: String) =
attr("src", value.toString()) // image only attr("src", value.toString()) // image only
fun AttrsBuilder<Tag.Input>.step(value: Int) = fun AttrsBuilder<HTMLInputElement>.step(value: Int) =
attr("step", value.toString()) // numeric types only attr("step", value.toString()) // numeric types only
fun AttrsBuilder<Tag.Input>.valueAttr(value: String) = fun AttrsBuilder<HTMLInputElement>.valueAttr(value: String) =
attr("value", value) attr("value", value)
fun AttrsBuilder<Tag.Input>.value(value: String): AttrsBuilder<Tag.Input> { fun AttrsBuilder<HTMLInputElement>.value(value: String): AttrsBuilder<HTMLInputElement> {
prop(setInputValue, value) prop(setInputValue, value)
return this return this
} }
/* Option attributes */ /* Option attributes */
fun AttrsBuilder<Tag.Option>.value(value: String) = fun AttrsBuilder<HTMLOptionElement>.value(value: String) =
attr("value", value) attr("value", value)
fun AttrsBuilder<Tag.Option>.disabled(value: Boolean = true) = fun AttrsBuilder<HTMLOptionElement>.disabled(value: Boolean = true) =
attr("disabled", if (value) "" else null) attr("disabled", if (value) "" else null)
fun AttrsBuilder<Tag.Option>.selected(value: Boolean = true) = fun AttrsBuilder<HTMLOptionElement>.selected(value: Boolean = true) =
attr("selected", if (value) "" else null) attr("selected", if (value) "" else null)
fun AttrsBuilder<Tag.Option>.label(value: String) = fun AttrsBuilder<HTMLOptionElement>.label(value: String) =
attr("label", value) attr("label", value)
/* Select attributes */ /* Select attributes */
fun AttrsBuilder<Tag.Select>.autocomplete(value: String) = fun AttrsBuilder<HTMLSelectElement>.autocomplete(value: String) =
attr("autocomplete", value) attr("autocomplete", value)
fun AttrsBuilder<Tag.Select>.autofocus(value: Boolean = true) = fun AttrsBuilder<HTMLSelectElement>.autofocus(value: Boolean = true) =
attr("autofocus", if (value) "" else null) attr("autofocus", if (value) "" else null)
fun AttrsBuilder<Tag.Select>.disabled(value: Boolean = true) = fun AttrsBuilder<HTMLSelectElement>.disabled(value: Boolean = true) =
attr("disabled", if (value) "" else null) attr("disabled", if (value) "" else null)
fun AttrsBuilder<Tag.Select>.form(formId: String) = fun AttrsBuilder<HTMLSelectElement>.form(formId: String) =
attr("form", formId) attr("form", formId)
fun AttrsBuilder<Tag.Select>.multiple(value: Boolean = true) = fun AttrsBuilder<HTMLSelectElement>.multiple(value: Boolean = true) =
attr("multiple", if (value) "" else null) attr("multiple", if (value) "" else null)
fun AttrsBuilder<Tag.Select>.name(value: String) = fun AttrsBuilder<HTMLSelectElement>.name(value: String) =
attr("name", value) attr("name", value)
fun AttrsBuilder<Tag.Select>.required(value: Boolean = true) = fun AttrsBuilder<HTMLSelectElement>.required(value: Boolean = true) =
attr("required", if (value) "" else null) attr("required", if (value) "" else null)
fun AttrsBuilder<Tag.Select>.size(numberOfRows: Int) = fun AttrsBuilder<HTMLSelectElement>.size(numberOfRows: Int) =
attr("size", numberOfRows.toString()) attr("size", numberOfRows.toString())
/* OptGroup attributes */ /* OptGroup attributes */
fun AttrsBuilder<Tag.OptGroup>.label(value: String) = fun AttrsBuilder<HTMLOptGroupElement>.label(value: String) =
attr("label", value) attr("label", value)
fun AttrsBuilder<Tag.OptGroup>.disabled(value: Boolean = true) = fun AttrsBuilder<HTMLOptGroupElement>.disabled(value: Boolean = true) =
attr("disabled", if (value) "" else null) attr("disabled", if (value) "" else null)
/* TextArea attributes */ /* TextArea attributes */
fun AttrsBuilder<Tag.TextArea>.autoComplete(value: Boolean = true) = fun AttrsBuilder<HTMLTextAreaElement>.autoComplete(value: Boolean = true) =
attr("autocomplete", if (value) "on" else "off") attr("autocomplete", if (value) "on" else "off")
fun AttrsBuilder<Tag.TextArea>.autoFocus(value: Boolean = true) = fun AttrsBuilder<HTMLTextAreaElement>.autoFocus(value: Boolean = true) =
attr("autofocus", if (value) "" else null) attr("autofocus", if (value) "" else null)
fun AttrsBuilder<Tag.TextArea>.cols(value: Int) = fun AttrsBuilder<HTMLTextAreaElement>.cols(value: Int) =
attr("cols", value.toString()) attr("cols", value.toString())
fun AttrsBuilder<Tag.TextArea>.disabled(value: Boolean = true) = fun AttrsBuilder<HTMLTextAreaElement>.disabled(value: Boolean = true) =
attr("disabled", if (value) "" else null) attr("disabled", if (value) "" else null)
fun AttrsBuilder<Tag.TextArea>.form(formId: String) = fun AttrsBuilder<HTMLTextAreaElement>.form(formId: String) =
attr("form", formId) attr("form", formId)
fun AttrsBuilder<Tag.TextArea>.maxLength(value: Int) = fun AttrsBuilder<HTMLTextAreaElement>.maxLength(value: Int) =
attr("maxlength", value.toString()) attr("maxlength", value.toString())
fun AttrsBuilder<Tag.TextArea>.minLength(value: Int) = fun AttrsBuilder<HTMLTextAreaElement>.minLength(value: Int) =
attr("minlength", value.toString()) attr("minlength", value.toString())
fun AttrsBuilder<Tag.TextArea>.name(value: String) = fun AttrsBuilder<HTMLTextAreaElement>.name(value: String) =
attr("name", value) attr("name", value)
fun AttrsBuilder<Tag.TextArea>.placeholder(value: String) = fun AttrsBuilder<HTMLTextAreaElement>.placeholder(value: String) =
attr("placeholder", value) attr("placeholder", value)
fun AttrsBuilder<Tag.TextArea>.readOnly(value: Boolean = true) = fun AttrsBuilder<HTMLTextAreaElement>.readOnly(value: Boolean = true) =
attr("readonly", if (value) "" else null) attr("readonly", if (value) "" else null)
fun AttrsBuilder<Tag.TextArea>.required(value: Boolean = true) = fun AttrsBuilder<HTMLTextAreaElement>.required(value: Boolean = true) =
attr("required", if (value) "" else null) attr("required", if (value) "" else null)
fun AttrsBuilder<Tag.TextArea>.rows(value: Int) = fun AttrsBuilder<HTMLTextAreaElement>.rows(value: Int) =
attr("rows", value.toString()) attr("rows", value.toString())
fun AttrsBuilder<Tag.TextArea>.wrap(value: TextAreaWrap) = fun AttrsBuilder<HTMLTextAreaElement>.wrap(value: TextAreaWrap) =
attr("wrap", value.str) attr("wrap", value.str)
fun AttrsBuilder<Tag.TextArea>.value(value: String): AttrsBuilder<Tag.TextArea> { fun AttrsBuilder<HTMLTextAreaElement>.value(value: String): AttrsBuilder<HTMLTextAreaElement> {
prop(setInputValue, value) prop(setInputValue, value)
return this return this
} }
/* Img attributes */ /* Img attributes */
fun AttrsBuilder<Tag.Img>.src(value: String?): AttrsBuilder<Tag.Img> = fun AttrsBuilder<HTMLImageElement>.src(value: String?): AttrsBuilder<HTMLImageElement> =
attr("src", value) attr("src", value)
fun AttrsBuilder<Tag.Img>.alt(value: String?): AttrsBuilder<Tag.Img> = fun AttrsBuilder<HTMLImageElement>.alt(value: String?): AttrsBuilder<HTMLImageElement> =
attr("alt", value) attr("alt", value)
private val setInputValue: (HTMLInputElement, String) -> Unit = { e, v -> private val setInputValue: (HTMLInputElement, String) -> Unit = { e, v ->
@ -329,24 +302,19 @@ private val setInputValue: (HTMLInputElement, String) -> Unit = { e, v ->
} }
/* Img attributes */ /* Img attributes */
fun AttrsBuilder<Tag.Label>.forId(value: String?): AttrsBuilder<Tag.Label> = fun AttrsBuilder<HTMLLabelElement>.forId(value: String?): AttrsBuilder<HTMLLabelElement> =
attr("for", value) attr("for", value)
/* Table attributes */ /* Table attributes */
fun AttrsBuilder<Tag.Th>.scope(value: Scope?): AttrsBuilder<Tag.Th> = fun AttrsBuilder<HTMLTableColElement>.span(value: Int): AttrsBuilder<HTMLTableColElement> =
attr("scope", value?.str)
fun AttrsBuilder<Tag.Col>.span(value: Int): AttrsBuilder<Tag.Col> =
attr("span", value.toString()) attr("span", value.toString())
fun AttrsBuilder<Tag.Th>.colspan(value: Int): AttrsBuilder<Tag.Th> = fun AttrsBuilder<HTMLTableCellElement>.scope(value: Scope?): AttrsBuilder<HTMLTableCellElement> =
attr("colspan", value.toString()) attr("scope", value?.str)
fun AttrsBuilder<Tag.Th>.rowspan(value: Int): AttrsBuilder<Tag.Th> =
attr("rowspan", value.toString())
fun AttrsBuilder<Tag.Td>.colspan(value: Int): AttrsBuilder<Tag.Td> = fun AttrsBuilder<HTMLTableCellElement>.colspan(value: Int): AttrsBuilder<HTMLTableCellElement> =
attr("colspan", value.toString()) attr("colspan", value.toString())
fun AttrsBuilder<Tag.Td>.rowspan(value: Int): AttrsBuilder<Tag.Td> = fun AttrsBuilder<HTMLTableCellElement>.rowspan(value: Int): AttrsBuilder<HTMLTableCellElement> =
attr("rowspan", value.toString()) attr("rowspan", value.toString())

4
web/core/src/jsMain/kotlin/androidx/compose/web/attributes/AttrsBuilder.kt

@ -7,7 +7,7 @@ import org.jetbrains.compose.web.css.StyleBuilderImpl
import org.w3c.dom.Element import org.w3c.dom.Element
import org.w3c.dom.HTMLElement import org.w3c.dom.HTMLElement
class AttrsBuilder<TTag : Tag> : EventsListenerBuilder() { class AttrsBuilder<TElement : Element> : EventsListenerBuilder() {
private val attributesMap = mutableMapOf<String, String>() private val attributesMap = mutableMapOf<String, String>()
val styleBuilder = StyleBuilderImpl() val styleBuilder = StyleBuilderImpl()
@ -34,7 +34,7 @@ class AttrsBuilder<TTag : Tag> : EventsListenerBuilder() {
this.refEffect = effect this.refEffect = effect
} }
fun attr(attr: String, value: String?): AttrsBuilder<TTag> { fun attr(attr: String, value: String?): AttrsBuilder<TElement> {
if (value == null) { if (value == null) {
attributesMap.remove(attr) attributesMap.remove(attr)
} else { } else {

12
web/core/src/jsMain/kotlin/androidx/compose/web/elements/Base.kt

@ -13,7 +13,6 @@ import androidx.compose.runtime.remember
import org.jetbrains.compose.web.DomApplier import org.jetbrains.compose.web.DomApplier
import org.jetbrains.compose.web.DomElementWrapper import org.jetbrains.compose.web.DomElementWrapper
import org.jetbrains.compose.web.attributes.AttrsBuilder import org.jetbrains.compose.web.attributes.AttrsBuilder
import org.jetbrains.compose.web.attributes.Tag
import kotlinx.browser.document import kotlinx.browser.document
import org.w3c.dom.Element import org.w3c.dom.Element
import org.w3c.dom.HTMLAnchorElement import org.w3c.dom.HTMLAnchorElement
@ -23,7 +22,6 @@ import org.w3c.dom.HTMLDivElement
import org.w3c.dom.HTMLElement import org.w3c.dom.HTMLElement
import org.w3c.dom.HTMLFormElement import org.w3c.dom.HTMLFormElement
import org.w3c.dom.HTMLHRElement import org.w3c.dom.HTMLHRElement
import org.w3c.dom.HTMLHeadElement
import org.w3c.dom.HTMLHeadingElement import org.w3c.dom.HTMLHeadingElement
import org.w3c.dom.HTMLImageElement import org.w3c.dom.HTMLImageElement
import org.w3c.dom.HTMLInputElement import org.w3c.dom.HTMLInputElement
@ -151,9 +149,9 @@ interface ElementBuilder<TElement : Element> {
} }
@Composable @Composable
fun <TTag : Tag, TElement : Element> TagElement( fun <TElement : Element> TagElement(
elementBuilder: ElementBuilder<TElement>, elementBuilder: ElementBuilder<TElement>,
applyAttrs: AttrsBuilder<TTag>.() -> Unit, applyAttrs: AttrsBuilder<TElement>.() -> Unit,
content: (@Composable ElementScope<TElement>.() -> Unit)? content: (@Composable ElementScope<TElement>.() -> Unit)?
) { ) {
val scope = remember { ElementScopeImpl<TElement>() } val scope = remember { ElementScopeImpl<TElement>() }
@ -166,7 +164,7 @@ fun <TTag : Tag, TElement : Element> TagElement(
} }
}, },
attrsSkippableUpdate = { attrsSkippableUpdate = {
val attrsApplied = AttrsBuilder<TTag>().also { it.applyAttrs() } val attrsApplied = AttrsBuilder<TElement>().also { it.applyAttrs() }
refEffect.effect = attrsApplied.refEffect refEffect.effect = attrsApplied.refEffect
val attrsCollected = attrsApplied.collect() val attrsCollected = attrsApplied.collect()
val events = attrsApplied.collectListeners() val events = attrsApplied.collectListeners()
@ -188,9 +186,9 @@ fun <TTag : Tag, TElement : Element> TagElement(
} }
@Composable @Composable
fun <TTag : Tag, TElement : Element> TagElement( fun <TElement : Element> TagElement(
tagName: String, tagName: String,
applyAttrs: AttrsBuilder<TTag>.() -> Unit, applyAttrs: AttrsBuilder<TElement>.() -> Unit,
content: (@Composable ElementScope<TElement>.() -> Unit)? content: (@Composable ElementScope<TElement>.() -> Unit)?
) = TagElement( ) = TagElement(
elementBuilder = ElementBuilder.createBuilder(tagName), elementBuilder = ElementBuilder.createBuilder(tagName),

117
web/core/src/jsMain/kotlin/androidx/compose/web/elements/Elements.kt

@ -6,7 +6,6 @@ import org.jetbrains.compose.web.DomApplier
import org.jetbrains.compose.web.DomNodeWrapper import org.jetbrains.compose.web.DomNodeWrapper
import org.jetbrains.compose.web.attributes.AttrsBuilder import org.jetbrains.compose.web.attributes.AttrsBuilder
import org.jetbrains.compose.web.attributes.InputType import org.jetbrains.compose.web.attributes.InputType
import org.jetbrains.compose.web.attributes.Tag
import org.jetbrains.compose.web.attributes.action import org.jetbrains.compose.web.attributes.action
import org.jetbrains.compose.web.attributes.alt import org.jetbrains.compose.web.attributes.alt
import org.jetbrains.compose.web.attributes.forId import org.jetbrains.compose.web.attributes.forId
@ -60,7 +59,7 @@ fun Text(value: String) {
@Composable @Composable
fun Div( fun Div(
attrs: AttrBuilderContext<Tag.Div> = {}, attrs: AttrBuilderContext<HTMLDivElement> = {},
content: ContentBuilder<HTMLDivElement>? = null content: ContentBuilder<HTMLDivElement>? = null
) { ) {
TagElement( TagElement(
@ -73,10 +72,10 @@ fun Div(
@Composable @Composable
fun A( fun A(
href: String? = null, href: String? = null,
attrs: AttrBuilderContext<Tag.A> = {}, attrs: AttrBuilderContext<HTMLAnchorElement> = {},
content: ContentBuilder<HTMLAnchorElement>? = null content: ContentBuilder<HTMLAnchorElement>? = null
) { ) {
TagElement<Tag.A, HTMLAnchorElement>( TagElement(
elementBuilder = ElementBuilder.A, elementBuilder = ElementBuilder.A,
applyAttrs = { applyAttrs = {
href(href) href(href)
@ -90,9 +89,9 @@ fun A(
fun Input( fun Input(
type: InputType = InputType.Text, type: InputType = InputType.Text,
value: String = "", value: String = "",
attrs: AttrBuilderContext<Tag.Input> = {} attrs: AttrBuilderContext<HTMLInputElement> = {}
) { ) {
TagElement<Tag.Input, HTMLInputElement>( TagElement(
elementBuilder = ElementBuilder.Input, elementBuilder = ElementBuilder.Input,
applyAttrs = { applyAttrs = {
type(type) type(type)
@ -105,107 +104,107 @@ fun Input(
@Composable @Composable
fun Button( fun Button(
attrs: AttrBuilderContext<Tag.Button> = {}, attrs: AttrBuilderContext<HTMLButtonElement> = {},
content: ContentBuilder<HTMLButtonElement>? = null content: ContentBuilder<HTMLButtonElement>? = null
) = TagElement(elementBuilder = ElementBuilder.Button, applyAttrs = attrs, content = content) ) = TagElement(elementBuilder = ElementBuilder.Button, applyAttrs = attrs, content = content)
@Composable @Composable
fun H1( fun H1(
attrs: AttrBuilderContext<Tag.H> = {}, attrs: AttrBuilderContext<HTMLHeadingElement> = {},
content: ContentBuilder<HTMLHeadingElement>? = null content: ContentBuilder<HTMLHeadingElement>? = null
) = TagElement(elementBuilder = ElementBuilder.H1, applyAttrs = attrs, content = content) ) = TagElement(elementBuilder = ElementBuilder.H1, applyAttrs = attrs, content = content)
@Composable @Composable
fun H2( fun H2(
attrs: AttrBuilderContext<Tag.H> = {}, attrs: AttrBuilderContext<HTMLHeadingElement> = {},
content: ContentBuilder<HTMLHeadingElement>? = null content: ContentBuilder<HTMLHeadingElement>? = null
) = TagElement(elementBuilder = ElementBuilder.H2, applyAttrs = attrs, content = content) ) = TagElement(elementBuilder = ElementBuilder.H2, applyAttrs = attrs, content = content)
@Composable @Composable
fun H3( fun H3(
attrs: AttrBuilderContext<Tag.H> = {}, attrs: AttrBuilderContext<HTMLHeadingElement> = {},
content: ContentBuilder<HTMLHeadingElement>? = null content: ContentBuilder<HTMLHeadingElement>? = null
) = TagElement(elementBuilder = ElementBuilder.H3, applyAttrs = attrs, content = content) ) = TagElement(elementBuilder = ElementBuilder.H3, applyAttrs = attrs, content = content)
@Composable @Composable
fun H4( fun H4(
attrs: AttrBuilderContext<Tag.H> = {}, attrs: AttrBuilderContext<HTMLHeadingElement> = {},
content: ContentBuilder<HTMLHeadingElement>? = null content: ContentBuilder<HTMLHeadingElement>? = null
) = TagElement(elementBuilder = ElementBuilder.H4, applyAttrs = attrs, content = content) ) = TagElement(elementBuilder = ElementBuilder.H4, applyAttrs = attrs, content = content)
@Composable @Composable
fun H5( fun H5(
attrs: AttrBuilderContext<Tag.H> = {}, attrs: AttrBuilderContext<HTMLHeadingElement> = {},
content: ContentBuilder<HTMLHeadingElement>? = null content: ContentBuilder<HTMLHeadingElement>? = null
) = TagElement(elementBuilder = ElementBuilder.H5, applyAttrs = attrs, content = content) ) = TagElement(elementBuilder = ElementBuilder.H5, applyAttrs = attrs, content = content)
@Composable @Composable
fun H6( fun H6(
attrs: AttrBuilderContext<Tag.H> = {}, attrs: AttrBuilderContext<HTMLHeadingElement> = {},
content: ContentBuilder<HTMLHeadingElement>? = null content: ContentBuilder<HTMLHeadingElement>? = null
) = TagElement(elementBuilder = ElementBuilder.H6, applyAttrs = attrs, content = content) ) = TagElement(elementBuilder = ElementBuilder.H6, applyAttrs = attrs, content = content)
@Composable @Composable
fun P( fun P(
attrs: AttrBuilderContext<Tag.P> = {}, attrs: AttrBuilderContext<HTMLParagraphElement> = {},
content: ContentBuilder<HTMLParagraphElement>? = null content: ContentBuilder<HTMLParagraphElement>? = null
) = TagElement(elementBuilder = ElementBuilder.P, applyAttrs = attrs, content = content) ) = TagElement(elementBuilder = ElementBuilder.P, applyAttrs = attrs, content = content)
@Composable @Composable
fun Em( fun Em(
attrs: AttrBuilderContext<Tag> = {}, attrs: AttrBuilderContext<HTMLElement> = {},
content: ContentBuilder<HTMLElement>? = null content: ContentBuilder<HTMLElement>? = null
) = TagElement(elementBuilder = ElementBuilder.Em, applyAttrs = attrs, content = content) ) = TagElement(elementBuilder = ElementBuilder.Em, applyAttrs = attrs, content = content)
@Composable @Composable
fun I( fun I(
attrs: AttrBuilderContext<Tag> = {}, attrs: AttrBuilderContext<HTMLElement> = {},
content: ContentBuilder<HTMLElement>? = null content: ContentBuilder<HTMLElement>? = null
) = TagElement(elementBuilder = ElementBuilder.I, applyAttrs = attrs, content = content) ) = TagElement(elementBuilder = ElementBuilder.I, applyAttrs = attrs, content = content)
@Composable @Composable
fun B( fun B(
attrs: AttrBuilderContext<Tag> = {}, attrs: AttrBuilderContext<HTMLElement> = {},
content: ContentBuilder<HTMLElement>? = null content: ContentBuilder<HTMLElement>? = null
) = TagElement(elementBuilder = ElementBuilder.B, applyAttrs = attrs, content = content) ) = TagElement(elementBuilder = ElementBuilder.B, applyAttrs = attrs, content = content)
@Composable @Composable
fun Small( fun Small(
attrs: AttrBuilderContext<Tag> = {}, attrs: AttrBuilderContext<HTMLElement> = {},
content: ContentBuilder<HTMLElement>? = null content: ContentBuilder<HTMLElement>? = null
) = TagElement(elementBuilder = ElementBuilder.Small, applyAttrs = attrs, content = content) ) = TagElement(elementBuilder = ElementBuilder.Small, applyAttrs = attrs, content = content)
@Composable @Composable
fun Span( fun Span(
attrs: AttrBuilderContext<Tag.Span> = {}, attrs: AttrBuilderContext<HTMLSpanElement> = {},
content: ContentBuilder<HTMLSpanElement>? = null content: ContentBuilder<HTMLSpanElement>? = null
) = TagElement(elementBuilder = ElementBuilder.Span, applyAttrs = attrs, content = content) ) = TagElement(elementBuilder = ElementBuilder.Span, applyAttrs = attrs, content = content)
@Composable @Composable
fun Br(attrs: AttrBuilderContext<Tag.Br> = {}) = fun Br(attrs: AttrBuilderContext<HTMLBRElement> = {}) =
TagElement<Tag.Br, HTMLBRElement>(elementBuilder = ElementBuilder.Br, applyAttrs = attrs, content = null) TagElement(elementBuilder = ElementBuilder.Br, applyAttrs = attrs, content = null)
@Composable @Composable
fun Ul( fun Ul(
attrs: AttrBuilderContext<Tag.Ul> = {}, attrs: AttrBuilderContext<HTMLUListElement> = {},
content: ContentBuilder<HTMLUListElement>? = null content: ContentBuilder<HTMLUListElement>? = null
) = TagElement(elementBuilder = ElementBuilder.Ul, applyAttrs = attrs, content = content) ) = TagElement(elementBuilder = ElementBuilder.Ul, applyAttrs = attrs, content = content)
@Composable @Composable
fun Ol( fun Ol(
attrs: AttrBuilderContext<Tag.Ol> = {}, attrs: AttrBuilderContext<HTMLOListElement> = {},
content: ContentBuilder<HTMLOListElement>? = null content: ContentBuilder<HTMLOListElement>? = null
) = TagElement(elementBuilder = ElementBuilder.Ol, applyAttrs = attrs, content = content) ) = TagElement(elementBuilder = ElementBuilder.Ol, applyAttrs = attrs, content = content)
@Composable @Composable
fun DOMScope<HTMLOListElement>.Li( fun DOMScope<HTMLOListElement>.Li(
attrs: AttrBuilderContext<Tag.Li> = {}, attrs: AttrBuilderContext<HTMLLIElement> = {},
content: ContentBuilder<HTMLLIElement>? = null content: ContentBuilder<HTMLLIElement>? = null
) = TagElement(elementBuilder = ElementBuilder.Li, applyAttrs = attrs, content = content) ) = TagElement(elementBuilder = ElementBuilder.Li, applyAttrs = attrs, content = content)
@Composable @Composable
fun DOMScope<HTMLUListElement>.Li( fun DOMScope<HTMLUListElement>.Li(
attrs: AttrBuilderContext<Tag.Li> = {}, attrs: AttrBuilderContext<HTMLLIElement> = {},
content: ContentBuilder<HTMLLIElement>? = null content: ContentBuilder<HTMLLIElement>? = null
) = TagElement(elementBuilder = ElementBuilder.Li, applyAttrs = attrs, content = content) ) = TagElement(elementBuilder = ElementBuilder.Li, applyAttrs = attrs, content = content)
@ -213,8 +212,8 @@ fun DOMScope<HTMLUListElement>.Li(
fun Img( fun Img(
src: String, src: String,
alt: String = "", alt: String = "",
attrs: AttrBuilderContext<Tag.Img> = {} attrs: AttrBuilderContext<HTMLImageElement> = {}
) = TagElement<Tag.Img, HTMLImageElement>( ) = TagElement(
elementBuilder = ElementBuilder.Img, elementBuilder = ElementBuilder.Img,
applyAttrs = { applyAttrs = {
src(src).alt(alt) src(src).alt(alt)
@ -226,9 +225,9 @@ fun Img(
@Composable @Composable
fun Form( fun Form(
action: String? = null, action: String? = null,
attrs: AttrBuilderContext<Tag.Form> = {}, attrs: AttrBuilderContext<HTMLFormElement> = {},
content: ContentBuilder<HTMLFormElement>? = null content: ContentBuilder<HTMLFormElement>? = null
) = TagElement<Tag.Form, HTMLFormElement>( ) = TagElement(
elementBuilder = ElementBuilder.Form, elementBuilder = ElementBuilder.Form,
applyAttrs = { applyAttrs = {
if (!action.isNullOrEmpty()) action(action) if (!action.isNullOrEmpty()) action(action)
@ -239,7 +238,7 @@ fun Form(
@Composable @Composable
fun Select( fun Select(
attrs: AttrBuilderContext<Tag.Select> = {}, attrs: AttrBuilderContext<HTMLSelectElement> = {},
content: ContentBuilder<HTMLSelectElement>? = null content: ContentBuilder<HTMLSelectElement>? = null
) = TagElement( ) = TagElement(
elementBuilder = ElementBuilder.Select, elementBuilder = ElementBuilder.Select,
@ -250,9 +249,9 @@ fun Select(
@Composable @Composable
fun Option( fun Option(
value: String, value: String,
attrs: AttrBuilderContext<Tag.Option> = {}, attrs: AttrBuilderContext<HTMLOptionElement> = {},
content: ContentBuilder<HTMLOptionElement>? = null content: ContentBuilder<HTMLOptionElement>? = null
) = TagElement<Tag.Option, HTMLOptionElement>( ) = TagElement(
elementBuilder = ElementBuilder.Option, elementBuilder = ElementBuilder.Option,
applyAttrs = { applyAttrs = {
value(value) value(value)
@ -264,9 +263,9 @@ fun Option(
@Composable @Composable
fun OptGroup( fun OptGroup(
label: String, label: String,
attrs: AttrBuilderContext<Tag.OptGroup> = {}, attrs: AttrBuilderContext<HTMLOptGroupElement> = {},
content: ContentBuilder<HTMLOptGroupElement>? = null content: ContentBuilder<HTMLOptGroupElement>? = null
) = TagElement<Tag.OptGroup, HTMLOptGroupElement>( ) = TagElement(
elementBuilder = ElementBuilder.OptGroup, elementBuilder = ElementBuilder.OptGroup,
applyAttrs = { applyAttrs = {
label(label) label(label)
@ -277,7 +276,7 @@ fun OptGroup(
@Composable @Composable
fun Section( fun Section(
attrs: AttrBuilderContext<Tag> = {}, attrs: AttrBuilderContext<HTMLElement> = {},
content: ContentBuilder<HTMLElement>? = null content: ContentBuilder<HTMLElement>? = null
) = TagElement( ) = TagElement(
elementBuilder = ElementBuilder.Section, elementBuilder = ElementBuilder.Section,
@ -287,9 +286,9 @@ fun Section(
@Composable @Composable
fun TextArea( fun TextArea(
attrs: AttrBuilderContext<Tag.TextArea> = {}, attrs: AttrBuilderContext<HTMLTextAreaElement> = {},
value: String value: String
) = TagElement<Tag.TextArea, HTMLTextAreaElement>( ) = TagElement(
elementBuilder = ElementBuilder.TextArea, elementBuilder = ElementBuilder.TextArea,
applyAttrs = { applyAttrs = {
value(value) value(value)
@ -301,7 +300,7 @@ fun TextArea(
@Composable @Composable
fun Nav( fun Nav(
attrs: AttrBuilderContext<Tag.Nav> = {}, attrs: AttrBuilderContext<HTMLElement> = {},
content: ContentBuilder<HTMLElement>? = null content: ContentBuilder<HTMLElement>? = null
) = TagElement( ) = TagElement(
elementBuilder = ElementBuilder.Nav, elementBuilder = ElementBuilder.Nav,
@ -311,7 +310,7 @@ fun Nav(
@Composable @Composable
fun Pre( fun Pre(
attrs: AttrBuilderContext<Tag.Pre> = {}, attrs: AttrBuilderContext<HTMLPreElement> = {},
content: ContentBuilder<HTMLPreElement>? = null content: ContentBuilder<HTMLPreElement>? = null
) { ) {
TagElement( TagElement(
@ -323,7 +322,7 @@ fun Pre(
@Composable @Composable
fun Code( fun Code(
attrs: AttrBuilderContext<Tag.Code> = {}, attrs: AttrBuilderContext<HTMLElement> = {},
content: ContentBuilder<HTMLElement>? = null content: ContentBuilder<HTMLElement>? = null
) { ) {
TagElement( TagElement(
@ -335,10 +334,10 @@ fun Code(
@Composable @Composable
fun Main( fun Main(
attrs: AttrBuilderContext<Tag.Div> = {}, attrs: AttrBuilderContext<HTMLElement> = {},
content: ContentBuilder<HTMLElement>? = null content: ContentBuilder<HTMLElement>? = null
) { ) {
TagElement<Tag.Div, HTMLElement>( TagElement(
elementBuilder = ElementBuilder.Main, elementBuilder = ElementBuilder.Main,
applyAttrs = attrs, applyAttrs = attrs,
content = content content = content
@ -347,10 +346,10 @@ fun Main(
@Composable @Composable
fun Footer( fun Footer(
attrs: AttrBuilderContext<Tag.Div> = {}, attrs: AttrBuilderContext<HTMLElement> = {},
content: ContentBuilder<HTMLElement>? = null content: ContentBuilder<HTMLElement>? = null
) { ) {
TagElement<Tag.Div, HTMLElement>( TagElement(
elementBuilder = ElementBuilder.Footer, elementBuilder = ElementBuilder.Footer,
applyAttrs = attrs, applyAttrs = attrs,
content = content content = content
@ -359,9 +358,9 @@ fun Footer(
@Composable @Composable
fun Hr( fun Hr(
attrs: AttrBuilderContext<Tag.Hr> = {} attrs: AttrBuilderContext<HTMLHRElement> = {}
) { ) {
TagElement<Tag.Hr, HTMLHRElement>( TagElement(
elementBuilder = ElementBuilder.Hr, elementBuilder = ElementBuilder.Hr,
applyAttrs = attrs, applyAttrs = attrs,
content = null content = null
@ -371,10 +370,10 @@ fun Hr(
@Composable @Composable
fun Label( fun Label(
forId: String? = null, forId: String? = null,
attrs: AttrBuilderContext<Tag.Label> = {}, attrs: AttrBuilderContext<HTMLLabelElement> = {},
content: ContentBuilder<HTMLLabelElement>? = null content: ContentBuilder<HTMLLabelElement>? = null
) { ) {
TagElement<Tag.Label, HTMLLabelElement>( TagElement(
elementBuilder = ElementBuilder.Label, elementBuilder = ElementBuilder.Label,
applyAttrs = { applyAttrs = {
forId(forId) forId(forId)
@ -386,7 +385,7 @@ fun Label(
@Composable @Composable
fun Table( fun Table(
attrs: AttrBuilderContext<Tag.Table> = {}, attrs: AttrBuilderContext<HTMLTableElement> = {},
content: ContentBuilder<HTMLTableElement>? = null content: ContentBuilder<HTMLTableElement>? = null
) { ) {
TagElement( TagElement(
@ -398,7 +397,7 @@ fun Table(
@Composable @Composable
fun Caption( fun Caption(
attrs: AttrBuilderContext<Tag.Caption> = {}, attrs: AttrBuilderContext<HTMLTableCaptionElement> = {},
content: ContentBuilder<HTMLTableCaptionElement>? = null content: ContentBuilder<HTMLTableCaptionElement>? = null
) { ) {
TagElement( TagElement(
@ -410,9 +409,9 @@ fun Caption(
@Composable @Composable
fun Col( fun Col(
attrs: AttrBuilderContext<Tag.Col> = {} attrs: AttrBuilderContext<HTMLTableColElement> = {}
) { ) {
TagElement<Tag.Col, HTMLTableColElement>( TagElement(
elementBuilder = ElementBuilder.Col, elementBuilder = ElementBuilder.Col,
applyAttrs = attrs, applyAttrs = attrs,
content = null content = null
@ -421,7 +420,7 @@ fun Col(
@Composable @Composable
fun Colgroup( fun Colgroup(
attrs: AttrBuilderContext<Tag.Colgroup> = {}, attrs: AttrBuilderContext<HTMLTableColElement> = {},
content: ContentBuilder<HTMLTableColElement>? = null content: ContentBuilder<HTMLTableColElement>? = null
) { ) {
TagElement( TagElement(
@ -433,7 +432,7 @@ fun Colgroup(
@Composable @Composable
fun Tr( fun Tr(
attrs: AttrBuilderContext<Tag.Tr> = {}, attrs: AttrBuilderContext<HTMLTableRowElement> = {},
content: ContentBuilder<HTMLTableRowElement>? = null content: ContentBuilder<HTMLTableRowElement>? = null
) { ) {
TagElement( TagElement(
@ -445,7 +444,7 @@ fun Tr(
@Composable @Composable
fun Thead( fun Thead(
attrs: AttrBuilderContext<Tag.Thead> = {}, attrs: AttrBuilderContext<HTMLTableSectionElement> = {},
content: ContentBuilder<HTMLTableSectionElement>? = null content: ContentBuilder<HTMLTableSectionElement>? = null
) { ) {
TagElement( TagElement(
@ -457,7 +456,7 @@ fun Thead(
@Composable @Composable
fun Th( fun Th(
attrs: AttrBuilderContext<Tag.Th> = {}, attrs: AttrBuilderContext<HTMLTableCellElement> = {},
content: ContentBuilder<HTMLTableCellElement>? = null content: ContentBuilder<HTMLTableCellElement>? = null
) { ) {
TagElement( TagElement(
@ -469,7 +468,7 @@ fun Th(
@Composable @Composable
fun Td( fun Td(
attrs: AttrBuilderContext<Tag.Td> = {}, attrs: AttrBuilderContext<HTMLTableCellElement> = {},
content: ContentBuilder<HTMLTableCellElement>? = null content: ContentBuilder<HTMLTableCellElement>? = null
) { ) {
TagElement( TagElement(
@ -481,7 +480,7 @@ fun Td(
@Composable @Composable
fun Tbody( fun Tbody(
attrs: AttrBuilderContext<Tag.Tbody> = {}, attrs: AttrBuilderContext<HTMLTableSectionElement> = {},
content: ContentBuilder<HTMLTableSectionElement>? = null content: ContentBuilder<HTMLTableSectionElement>? = null
) { ) {
TagElement( TagElement(
@ -493,7 +492,7 @@ fun Tbody(
@Composable @Composable
fun Tfoot( fun Tfoot(
attrs: AttrBuilderContext<Tag.Tfoot> = {}, attrs: AttrBuilderContext<HTMLTableSectionElement> = {},
content: ContentBuilder<HTMLTableSectionElement>? = null content: ContentBuilder<HTMLTableSectionElement>? = null
) { ) {
TagElement( TagElement(

7
web/core/src/jsMain/kotlin/androidx/compose/web/elements/Style.kt

@ -2,7 +2,6 @@ package org.jetbrains.compose.web.dom
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import org.jetbrains.compose.web.attributes.AttrsBuilder import org.jetbrains.compose.web.attributes.AttrsBuilder
import org.jetbrains.compose.web.attributes.Tag
import org.w3c.dom.HTMLStyleElement import org.w3c.dom.HTMLStyleElement
import org.w3c.dom.css.CSSGroupingRule import org.w3c.dom.css.CSSGroupingRule
import org.w3c.dom.css.CSSRule import org.w3c.dom.css.CSSRule
@ -18,7 +17,7 @@ import org.jetbrains.compose.web.css.*
*/ */
@Composable @Composable
inline fun Style( inline fun Style(
crossinline applyAttrs: AttrsBuilder<Tag.Style>.() -> Unit = {}, crossinline applyAttrs: AttrsBuilder<HTMLStyleElement>.() -> Unit = {},
rulesBuild: StyleSheetBuilder.() -> Unit rulesBuild: StyleSheetBuilder.() -> Unit
) { ) {
val builder = StyleSheetBuilderImpl() val builder = StyleSheetBuilderImpl()
@ -34,10 +33,10 @@ inline fun Style(
*/ */
@Composable @Composable
inline fun Style( inline fun Style(
crossinline applyAttrs: AttrsBuilder<Tag.Style>.() -> Unit = {}, crossinline applyAttrs: AttrsBuilder<HTMLStyleElement>.() -> Unit = {},
cssRules: CSSRuleDeclarationList cssRules: CSSRuleDeclarationList
) { ) {
TagElement<Tag.Style, HTMLStyleElement>( TagElement(
elementBuilder = ElementBuilder.Style, elementBuilder = ElementBuilder.Style,
applyAttrs = { applyAttrs = {
applyAttrs() applyAttrs()

3
web/core/src/jsTest/kotlin/elements/ElementsTests.kt

@ -7,7 +7,6 @@ package org.jetbrains.compose.web.core.tests.elements
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import org.jetbrains.compose.web.attributes.AttrsBuilder import org.jetbrains.compose.web.attributes.AttrsBuilder
import org.jetbrains.compose.web.attributes.Tag
import org.jetbrains.compose.web.core.tests.runTest import org.jetbrains.compose.web.core.tests.runTest
import org.jetbrains.compose.web.dom.A import org.jetbrains.compose.web.dom.A
import org.jetbrains.compose.web.dom.B import org.jetbrains.compose.web.dom.B
@ -130,7 +129,7 @@ class ElementsTests {
fun rawCreation() = runTest { fun rawCreation() = runTest {
@Composable @Composable
fun CustomElement( fun CustomElement(
attrs: AttrsBuilder<Tag.Div>.() -> Unit, attrs: AttrsBuilder<HTMLElement>.() -> Unit,
content: ContentBuilder<HTMLElement>? = null content: ContentBuilder<HTMLElement>? = null
) { ) {
TagElement( TagElement(

Loading…
Cancel
Save