Browse Source

web: mark internal and experimental api in web-core (#1077)

Co-authored-by: Oleksandr Karpovich <oleksandr.karpovich@jetbrains.com>
pull/1083/head
Oleksandr Karpovich 3 years ago committed by GitHub
parent
commit
d2d4971f28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      web/core/src/jsMain/kotlin/org/jetbrains/compose/web/DomApplier.kt
  2. 4
      web/core/src/jsMain/kotlin/org/jetbrains/compose/web/ExperimentalComposeWebApi.kt
  3. 8
      web/core/src/jsMain/kotlin/org/jetbrains/compose/web/attributes/AttrsBuilder.kt
  4. 2
      web/core/src/jsMain/kotlin/org/jetbrains/compose/web/attributes/EventsListenerBuilder.kt
  5. 50
      web/core/src/jsMain/kotlin/org/jetbrains/compose/web/elements/Base.kt
  6. 2
      web/core/src/jsMain/kotlin/org/jetbrains/compose/web/elements/ElementScope.kt
  7. 8
      web/core/src/jsMain/kotlin/org/jetbrains/compose/web/elements/Elements.kt
  8. 8
      web/core/src/jsMain/kotlin/org/jetbrains/compose/web/elements/Style.kt
  9. 4
      web/core/src/jsTest/kotlin/elements/ElementsTests.kt

6
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/DomApplier.kt

@ -11,7 +11,7 @@ import org.w3c.dom.HTMLElement
import org.w3c.dom.Node
import org.w3c.dom.get
class DomApplier(
internal class DomApplier(
root: DomNodeWrapper
) : AbstractApplier<DomNodeWrapper>(root) {
@ -43,7 +43,7 @@ external interface EventListenerOptions {
var capture: Boolean
}
open class DomNodeWrapper(open val node: Node) {
internal open class DomNodeWrapper(open val node: Node) {
private var currentListeners = emptyList<SyntheticEventListener<*>>()
fun updateEventListeners(list: List<SyntheticEventListener<*>>) {
@ -92,7 +92,7 @@ open class DomNodeWrapper(open val node: Node) {
}
class DomElementWrapper(override val node: HTMLElement): DomNodeWrapper(node) {
internal class DomElementWrapper(override val node: HTMLElement): DomNodeWrapper(node) {
private var currentAttrs: Map<String, String>? = null
fun updateAttrs(attrs: Map<String, String>) {

4
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/ExperimentalComposeWebApi.kt

@ -0,0 +1,4 @@
package org.jetbrains.compose.web
@RequiresOptIn("This API is experimental and is likely to change in the future.")
annotation class ExperimentalComposeWebApi

8
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/attributes/AttrsBuilder.kt

@ -21,8 +21,8 @@ open class AttrsBuilder<TElement : Element> : EventsListenerBuilder() {
internal val attributesMap = mutableMapOf<String, String>()
val styleBuilder = StyleBuilderImpl()
val propertyUpdates = mutableListOf<Pair<(Element, Any) -> Unit, Any>>()
var refEffect: (DisposableEffectScope.(TElement) -> DisposableEffectResult)? = null
internal val propertyUpdates = mutableListOf<Pair<(Element, Any) -> Unit, Any>>()
internal var refEffect: (DisposableEffectScope.(TElement) -> DisposableEffectResult)? = null
/**
* [style] add inline CSS-style properties to the element via [StyleBuilder] context
@ -103,7 +103,7 @@ open class AttrsBuilder<TElement : Element> : EventsListenerBuilder() {
propertyUpdates.add((update to value) as Pair<(Element, Any) -> Unit, Any>)
}
fun collect(): Map<String, String> {
internal fun collect(): Map<String, String> {
return attributesMap
}
@ -131,6 +131,6 @@ open class AttrsBuilder<TElement : Element> : EventsListenerBuilder() {
}
}
val setClassList: (HTMLElement, Array<out String>) -> Unit = { e, classList ->
private val setClassList: (HTMLElement, Array<out String>) -> Unit = { e, classList ->
e.classList.add(*classList)
}

2
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/attributes/EventsListenerBuilder.kt

@ -188,7 +188,7 @@ open class EventsListenerBuilder {
listeners.add(SyntheticEventListener(SCROLL, options, listener))
}
fun collectListeners(): List<SyntheticEventListener<*>> = listeners
internal fun collectListeners(): List<SyntheticEventListener<*>> = listeners
/**
* [addEventListener] used for adding arbitrary events to the element. It resembles the standard DOM addEventListener method

50
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/elements/Base.kt

@ -13,54 +13,9 @@ import androidx.compose.runtime.remember
import org.jetbrains.compose.web.DomApplier
import org.jetbrains.compose.web.DomElementWrapper
import org.jetbrains.compose.web.attributes.AttrsBuilder
import kotlinx.browser.document
import org.w3c.dom.Audio
import org.jetbrains.compose.web.ExperimentalComposeWebApi
import org.w3c.dom.Element
import org.w3c.dom.HTMLAnchorElement
import org.w3c.dom.HTMLAreaElement
import org.w3c.dom.HTMLAudioElement
import org.w3c.dom.HTMLBRElement
import org.w3c.dom.HTMLButtonElement
import org.w3c.dom.HTMLDataListElement
import org.w3c.dom.HTMLDivElement
import org.w3c.dom.HTMLElement
import org.w3c.dom.HTMLEmbedElement
import org.w3c.dom.HTMLFieldSetElement
import org.w3c.dom.HTMLFormElement
import org.w3c.dom.HTMLHRElement
import org.w3c.dom.HTMLHeadingElement
import org.w3c.dom.HTMLIFrameElement
import org.w3c.dom.HTMLImageElement
import org.w3c.dom.HTMLInputElement
import org.w3c.dom.HTMLLIElement
import org.w3c.dom.HTMLLabelElement
import org.w3c.dom.HTMLLegendElement
import org.w3c.dom.HTMLMapElement
import org.w3c.dom.HTMLMeterElement
import org.w3c.dom.HTMLOListElement
import org.w3c.dom.HTMLObjectElement
import org.w3c.dom.HTMLOptGroupElement
import org.w3c.dom.HTMLOptionElement
import org.w3c.dom.HTMLOutputElement
import org.w3c.dom.HTMLParagraphElement
import org.w3c.dom.HTMLParamElement
import org.w3c.dom.HTMLPictureElement
import org.w3c.dom.HTMLPreElement
import org.w3c.dom.HTMLProgressElement
import org.w3c.dom.HTMLSelectElement
import org.w3c.dom.HTMLSourceElement
import org.w3c.dom.HTMLSpanElement
import org.w3c.dom.HTMLStyleElement
import org.w3c.dom.HTMLTableCaptionElement
import org.w3c.dom.HTMLTableCellElement
import org.w3c.dom.HTMLTableColElement
import org.w3c.dom.HTMLTableElement
import org.w3c.dom.HTMLTableRowElement
import org.w3c.dom.HTMLTableSectionElement
import org.w3c.dom.HTMLTextAreaElement
import org.w3c.dom.HTMLTrackElement
import org.w3c.dom.HTMLUListElement
import org.w3c.dom.HTMLVideoElement
@OptIn(ComposeCompilerApi::class)
@Composable
@ -89,7 +44,7 @@ inline fun <TScope, T, reified E : Applier<*>> ComposeDomNode(
currentComposer.endNode()
}
class DisposableEffectHolder<TElement: Element>(
class DisposableEffectHolder<TElement : Element>(
var effect: (DisposableEffectScope.(TElement) -> DisposableEffectResult)? = null
)
@ -135,6 +90,7 @@ fun <TElement : Element> TagElement(
}
@Composable
@ExperimentalComposeWebApi
fun <TElement : Element> TagElement(
tagName: String,
applyAttrs: AttrsBuilder<TElement>.() -> Unit,

2
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/elements/ElementScope.kt

@ -113,7 +113,7 @@ abstract class ElementScopeBase<out TElement : Element> : ElementScope<TElement>
}
}
open class ElementScopeImpl<TElement : Element> : ElementScopeBase<TElement>() {
internal open class ElementScopeImpl<TElement : Element> : ElementScopeBase<TElement>() {
public override lateinit var element: TElement
}

8
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/elements/Elements.kt

@ -883,8 +883,8 @@ fun Tfoot(
* Usually, it's [androidx.compose.web.css.StyleSheet] instance
*/
@Composable
inline fun Style(
noinline applyAttrs: (AttrsBuilder<HTMLStyleElement>.() -> Unit)? = null,
fun Style(
applyAttrs: (AttrsBuilder<HTMLStyleElement>.() -> Unit)? = null,
cssRules: CSSRuleDeclarationList
) {
TagElement(
@ -912,8 +912,8 @@ inline fun Style(
* @param rulesBuild allows to define the style rules using [StyleSheetBuilder]
*/
@Composable
inline fun Style(
noinline applyAttrs: (AttrsBuilder<HTMLStyleElement>.() -> Unit)? = null,
fun Style(
applyAttrs: (AttrsBuilder<HTMLStyleElement>.() -> Unit)? = null,
rulesBuild: StyleSheetBuilder.() -> Unit
) {
val builder = StyleSheetBuilderImpl()

8
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/elements/Style.kt

@ -7,13 +7,13 @@ import org.w3c.dom.css.CSSStyleRule
import org.jetbrains.compose.web.css.*
import org.w3c.dom.css.CSSStyleSheet
fun clearCSSRules(sheet: CSSStyleSheet) {
internal fun clearCSSRules(sheet: CSSStyleSheet) {
repeat(sheet.cssRules.length) {
sheet.deleteRule(0)
}
}
fun setCSSRules(sheet: CSSStyleSheet, cssRules: CSSRuleDeclarationList) {
internal fun setCSSRules(sheet: CSSStyleSheet, cssRules: CSSRuleDeclarationList) {
cssRules.forEach { cssRule ->
sheet.addRule(cssRule)
}
@ -81,7 +81,7 @@ private fun fillRule(
}
}
fun setProperty(
internal fun setProperty(
style: CSSStyleDeclaration,
name: String,
value: StylePropertyValue
@ -89,7 +89,7 @@ fun setProperty(
style.setProperty(name, value.toString())
}
fun setVariable(
internal fun setVariable(
style: CSSStyleDeclaration,
name: String,
value: StylePropertyValue

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

@ -6,6 +6,7 @@
package org.jetbrains.compose.web.core.tests.elements
import androidx.compose.runtime.Composable
import org.jetbrains.compose.web.ExperimentalComposeWebApi
import org.jetbrains.compose.web.attributes.AttrsBuilder
import org.jetbrains.compose.web.core.tests.runTest
import org.jetbrains.compose.web.dom.*
@ -65,7 +66,7 @@ class ElementsTests {
Pair({ Ol() }, "OL"),
Pair({ Li() }, "LI"),
Pair({ Img(src="whatever") }, "IMG"),
Pair({ Img(src = "whatever") }, "IMG"),
Pair({ Form() }, "FORM"),
Pair({ Select() }, "SELECT"),
@ -106,6 +107,7 @@ class ElementsTests {
}
@Test
@OptIn(ExperimentalComposeWebApi::class)
fun rawCreation() = runTest {
@Composable
fun CustomElement(

Loading…
Cancel
Save