|
|
@ -28,16 +28,6 @@ typealias AttrsBuilder<T> = AttrsScopeBuilder<T> |
|
|
|
* |
|
|
|
* |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
interface AttrsScope<TElement : Element>: EventsListenerScope { |
|
|
|
interface AttrsScope<TElement : Element>: EventsListenerScope { |
|
|
|
@ComposeWebInternalApi |
|
|
|
|
|
|
|
val attributesMap: Map<String, String> |
|
|
|
|
|
|
|
@ComposeWebInternalApi |
|
|
|
|
|
|
|
val styleScope: StyleScope |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ComposeWebInternalApi |
|
|
|
|
|
|
|
val propertyUpdates: List<Pair<(Element, Any) -> Unit, Any>> |
|
|
|
|
|
|
|
@ComposeWebInternalApi |
|
|
|
|
|
|
|
var refEffect: (DisposableEffectScope.(TElement) -> DisposableEffectResult)? |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* [style] add inline CSS-style properties to the element via [StyleScope] context |
|
|
|
* [style] add inline CSS-style properties to the element via [StyleScope] context |
|
|
|
* |
|
|
|
* |
|
|
@ -50,9 +40,7 @@ interface AttrsScope<TElement : Element>: EventsListenerScope { |
|
|
|
* |
|
|
|
* |
|
|
|
* `attr("style", ...)` overrides everything added in `style { }` blocks |
|
|
|
* `attr("style", ...)` overrides everything added in `style { }` blocks |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
fun style(builder: StyleScope.() -> Unit) { |
|
|
|
fun style(builder: StyleScope.() -> Unit) |
|
|
|
styleScope.apply(builder) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* [classes] adds all values passed as params to the element's classList. |
|
|
|
* [classes] adds all values passed as params to the element's classList. |
|
|
@ -105,7 +93,7 @@ interface AttrsScope<TElement : Element>: EventsListenerScope { |
|
|
|
fun attr(attr: String, value: String): AttrsScope<TElement> |
|
|
|
fun attr(attr: String, value: String): AttrsScope<TElement> |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* [prop] allows setting values of element's properties which can't be set by ussing [attr]. |
|
|
|
* [prop] allows setting values of element's properties which can't be set using [attr]. |
|
|
|
* [update] is a lambda with two parameters: `element` and `value`. `element` is a reference to a native element. |
|
|
|
* [update] is a lambda with two parameters: `element` and `value`. `element` is a reference to a native element. |
|
|
|
* Some examples of properties that can set using [prop]: `value`, `checked`, `innerText`. |
|
|
|
* Some examples of properties that can set using [prop]: `value`, `checked`, `innerText`. |
|
|
|
* |
|
|
|
* |
|
|
@ -124,9 +112,6 @@ interface AttrsScope<TElement : Element>: EventsListenerScope { |
|
|
|
@Suppress("UNCHECKED_CAST") |
|
|
|
@Suppress("UNCHECKED_CAST") |
|
|
|
fun <E : HTMLElement, V> prop(update: (E, V) -> Unit, value: V) |
|
|
|
fun <E : HTMLElement, V> prop(update: (E, V) -> Unit, value: V) |
|
|
|
|
|
|
|
|
|
|
|
@ComposeWebInternalApi |
|
|
|
|
|
|
|
fun copyFrom(attrsScope: AttrsScope<TElement>) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
companion object { |
|
|
|
const val CLASS = "class" |
|
|
|
const val CLASS = "class" |
|
|
|
const val ID = "id" |
|
|
|
const val ID = "id" |
|
|
@ -141,13 +126,13 @@ interface AttrsScope<TElement : Element>: EventsListenerScope { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
open class AttrsScopeBuilder<TElement : Element> : AttrsScope<TElement>, EventsListenerScope by EventsListenerScopeBuilder() { |
|
|
|
open class AttrsScopeBuilder<TElement : Element>( |
|
|
|
override val attributesMap = mutableMapOf<String, String>() |
|
|
|
internal val eventsListenerScopeBuilder: EventsListenerScopeBuilder = EventsListenerScopeBuilder() |
|
|
|
override val styleScope: StyleScope = StyleScopeBuilder() |
|
|
|
) : AttrsScope<TElement>, EventsListenerScope by eventsListenerScopeBuilder { |
|
|
|
|
|
|
|
internal val attributesMap = mutableMapOf<String, String>() |
|
|
|
override val propertyUpdates = mutableListOf<Pair<(Element, Any) -> Unit, Any>>() |
|
|
|
internal val styleScope: StyleScopeBuilder = StyleScopeBuilder() |
|
|
|
override var refEffect: (DisposableEffectScope.(TElement) -> DisposableEffectResult)? = null |
|
|
|
internal val propertyUpdates = mutableListOf<Pair<(Element, Any) -> Unit, Any>>() |
|
|
|
|
|
|
|
internal var refEffect: (DisposableEffectScope.(TElement) -> DisposableEffectResult)? = null |
|
|
|
internal val classes: MutableList<String> = mutableListOf() |
|
|
|
internal val classes: MutableList<String> = mutableListOf() |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -160,6 +145,22 @@ open class AttrsScopeBuilder<TElement : Element> : AttrsScope<TElement>, EventsL |
|
|
|
this.classes.addAll(classes) |
|
|
|
this.classes.addAll(classes) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* [style] add inline CSS-style properties to the element via [StyleScope] context |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* Example: |
|
|
|
|
|
|
|
* ``` |
|
|
|
|
|
|
|
* Div({ |
|
|
|
|
|
|
|
* style { maxWidth(5.px) } |
|
|
|
|
|
|
|
* }) |
|
|
|
|
|
|
|
* ``` |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* `attr("style", ...)` overrides everything added in `style { }` blocks |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
override fun style(builder: StyleScope.() -> Unit) { |
|
|
|
|
|
|
|
styleScope.apply(builder) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* [ref] can be used to retrieve a reference to a html element. |
|
|
|
* [ref] can be used to retrieve a reference to a html element. |
|
|
|
* The lambda that `ref` takes in is not Composable. It will be called only once when an element added into a composition. |
|
|
|
* The lambda that `ref` takes in is not Composable. It will be called only once when an element added into a composition. |
|
|
@ -212,14 +213,14 @@ open class AttrsScopeBuilder<TElement : Element> : AttrsScope<TElement>, EventsL |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ComposeWebInternalApi |
|
|
|
@ComposeWebInternalApi |
|
|
|
override fun copyFrom(attrsScope: AttrsScope<TElement>) { |
|
|
|
internal fun copyFrom(attrsScope: AttrsScopeBuilder<TElement>) { |
|
|
|
refEffect = attrsScope.refEffect |
|
|
|
refEffect = attrsScope.refEffect |
|
|
|
styleScope.copyFrom(attrsScope.styleScope) |
|
|
|
styleScope.copyFrom(attrsScope.styleScope) |
|
|
|
|
|
|
|
|
|
|
|
attributesMap.putAll(attrsScope.attributesMap) |
|
|
|
attributesMap.putAll(attrsScope.attributesMap) |
|
|
|
propertyUpdates.addAll(attrsScope.propertyUpdates) |
|
|
|
propertyUpdates.addAll(attrsScope.propertyUpdates) |
|
|
|
|
|
|
|
|
|
|
|
copyListenersFrom(attrsScope) |
|
|
|
eventsListenerScopeBuilder.copyListenersFrom(attrsScope.eventsListenerScopeBuilder) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|