Skip to content

Commit

Permalink
Reformat with scalafmt 3.8.2
Browse files Browse the repository at this point in the history
Executed command: scalafmt --non-interactive
  • Loading branch information
scala-steward committed Jun 16, 2024
1 parent 6fee6f7 commit e1f7b52
Show file tree
Hide file tree
Showing 149 changed files with 2,462 additions and 1,644 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import org.scalajs.dom
import org.scalajs.dom.raw.MouseEvent

trait JSCallbacks extends Callbacks { self: JSRenderingContext
type Callback = js.Function
type Callback = js.Function
type ClickElement = dom.html.Element
type InputElement = dom.html.Input
type FormElement = dom.html.Form
type FormElement = dom.html.Form

object Callback extends CallbackFactory {
def onClick(f: ClickElement Unit): js.Function = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import org.scalajs.dom.DOMList

trait JSImplicits {
implicit class DOMListIndexedSeq[T](dl: DOMList[T]) extends IndexedSeq[T] {
override def length: Int = dl.length
override def length: Int = dl.length
override def apply(idx: Int): T = dl.apply(idx)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ trait JSReactiveBinds extends ReactiveBinds {

protected type Event = dom.Event

implicit def rxEventListener[EL <: Element, EV <: Event]: ReactiveRead[EL, EventListener[EL, EV]] = new ReactiveRead[EL, EventListener[EL, EV]] {
def bindRead(element: EL, property: EventListener[EL, EV]): Unit = {
val function = js.ThisFunction.fromFunction2 { (el: EL, ev: EV)
property.callback(el, ev)
implicit def rxEventListener[EL <: Element, EV <: Event]: ReactiveRead[EL, EventListener[EL, EV]] =
new ReactiveRead[EL, EventListener[EL, EV]] {
def bindRead(element: EL, property: EventListener[EL, EV]): Unit = {
val function = js.ThisFunction.fromFunction2 { (el: EL, ev: EV)
property.callback(el, ev)
}
element.asInstanceOf[js.Dynamic].addEventListener(property.`type`, function)
}
element.asInstanceOf[js.Dynamic].addEventListener(property.`type`, function)
}
}

implicit def rxModify[E <: Element, T]: ReactiveWrite[E, Modify[E, T]] = new ReactiveWrite[E, Modify[E, T]] {
def bindWrite(element: E, property: Modify[E, T]): Unit = {
Expand All @@ -37,32 +38,39 @@ trait JSReactiveBinds extends ReactiveBinds {
}
}

implicit def rxBindNode[E <: Element, N: Renderable]: ReactiveWrite[E, BindNode[N]] = new ReactiveWrite[E, BindNode[N]] {
def bindWrite(parent: E, property: BindNode[N]): Unit = {
val elRx = property.value.map(identity)
var oldElement = property.value.now.render
elRx.triggerLater({
val element = oldElement
if (isElementAvailable(element) && isElementAvailable(element.parentNode)) {
val newElement = elRx.now.render
oldElement = newElement
element.parentNode.replaceChild(newElement, element)
} else {
elRx.kill()
}
}: Unit)
parent.appendChild(oldElement)
implicit def rxBindNode[E <: Element, N: Renderable]: ReactiveWrite[E, BindNode[N]] =
new ReactiveWrite[E, BindNode[N]] {
def bindWrite(parent: E, property: BindNode[N]): Unit = {
val elRx = property.value.map(identity)
var oldElement = property.value.now.render
elRx.triggerLater({
val element = oldElement
if (isElementAvailable(element) && isElementAvailable(element.parentNode)) {
val newElement = elRx.now.render
oldElement = newElement
element.parentNode.replaceChild(newElement, element)
} else {
elRx.kill()
}
}: Unit)
parent.appendChild(oldElement)
}
}
}

private[this] final case class FormValueRW[E <: Element, T](event: String, read: dom.html.Input T, write: (dom.html.Input, T) Unit)
extends ReactiveRW[E, FormValue[T]] {
private[this] final case class FormValueRW[E <: Element, T](
event: String,
read: dom.html.Input T,
write: (dom.html.Input, T) Unit
) extends ReactiveRW[E, FormValue[T]] {

private[this] def safeRead(e: Element): Try[T] =
Try(read(e.asInstanceOf[Input])).filter(v v != null && !js.isUndefined(v))

def bindRead(element: E, property: FormValue[T]): Unit = {
rxEventListener[E, Event].bindRead(element, EventListener(event, (e, _) safeRead(e).foreach(property.value() = _)))
rxEventListener[E, Event].bindRead(
element,
EventListener(event, (e, _) safeRead(e).foreach(property.value() = _))
)
}

def bindWrite(element: E, property: FormValue[T]): Unit = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ import scalatags.JsDom
import org.scalajs.dom
import org.scalajs.dom.Node

trait JSRenderingContext extends RenderingContext with JSReactiveBinds with JSCallbacks with JSClassModifiers with JSImplicits {
trait JSRenderingContext
extends RenderingContext
with JSReactiveBinds
with JSCallbacks
with JSClassModifiers
with JSImplicits {
type Element = dom.Element
type Output = dom.Element
type FragT = dom.Node
type Output = dom.Element
type FragT = dom.Node

//noinspection TypeAnnotation
// noinspection TypeAnnotation
val scalaTags = JsDom
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import com.karasiq.bootstrap.components.generic.{GenComponent, GenDomComponent,
import com.karasiq.bootstrap.context.RenderingContext

trait BootstrapComponents { self: RenderingContext
final type ModifierFactory = generic.ModifierFactory[Element]
final type BootstrapComponent = generic.BootstrapComponent[Element]
final type BootstrapDomComponent = generic.BootstrapDomComponent[Element, FragT]
final type ModifierFactory = generic.ModifierFactory[Element]
final type BootstrapComponent = generic.BootstrapComponent[Element]
final type BootstrapDomComponent = generic.BootstrapDomComponent[Element, FragT]
final type BootstrapHtmlComponent = generic.BootstrapHtmlComponent[Element, Output, FragT]

implicit def renderBootstrapHtmlComponent[C](bc: C)(implicit ev: C BootstrapHtmlComponent): scalaTags.Tag = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package object generic {
// Context-bound components
trait ModifierFactory[E] extends Modifier[E] {
// Shortcuts
protected type ElementT = E
protected type ElementT = E
protected type ModifierT = Modifier[E]

def createModifier: ModifierT
Expand Down Expand Up @@ -34,7 +34,7 @@ package object generic {
}

final def render(md: ModifierT*): ModifierT = {
renderFrag(md:_*)
renderFrag(md: _*)
}
}

Expand All @@ -44,7 +44,7 @@ package object generic {
def renderTag(md: ModifierT*): TagT

final def renderFrag(md: ModifierT*): FragT = {
renderTag(md:_*)
renderTag(md: _*)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ trait ClassModifiers { self: RenderingContext ⇒
}

case class ClassAdd(className: String) extends ClassModifier {
val classAdded = true
val classRemoved = false
val classAdded = true
val classRemoved = false
def applyTo(t: Element): Unit = addClass(t, className)
}

case class ClassRemove(className: String) extends ClassModifier {
val classAdded = false
val classRemoved = true
val classAdded = false
val classRemoved = true
def applyTo(t: Element): Unit = removeClass(t, className)
}

//noinspection MutatorLikeMethodIsParameterless
// noinspection MutatorLikeMethodIsParameterless
implicit class HtmlClassOps(className: String) {
def addClass: ClassAdd = {
ClassAdd(className)
Expand All @@ -43,13 +43,18 @@ trait ClassModifiers { self: RenderingContext ⇒
}

def classIf(state: Rx[Boolean]): Modifier = {
writeModifier(Modify[Element, Boolean](state, (e, v) {
if (v) {
ClassModifiers.this.addClass(e, className)
} else {
ClassModifiers.this.removeClass(e, className)
}
}))
writeModifier(
Modify[Element, Boolean](
state,
(e, v) {
if (v) {
ClassModifiers.this.addClass(e, className)
} else {
ClassModifiers.this.removeClass(e, className)
}
}
)
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ object ReactiveBinds {
case class Visibility(visible: Rx[Boolean])
}

/**
* Predefined binds
/** Predefined binds
*/
trait ReactiveBinds { self: RenderingContext
protected type Event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ trait ReactiveImplicits { self: RenderingContext ⇒
}

implicit class RxVariableOps[T](value: Var[T]) {
def reactiveRead[EV](event: String, f: (Element, EV) T)(implicit read: ReactiveRead[Element, EventListener[Element, EV]]): Modifier = {
readModifier(EventListener[Element, EV](event, (el, ev) value() = f(el,ev)))
def reactiveRead[EV](event: String, f: (Element, EV) T)(implicit
read: ReactiveRead[Element, EventListener[Element, EV]]
): Modifier = {
readModifier(EventListener[Element, EV](event, (el, ev) value() = f(el, ev)))
}

def reactiveReadWrite[EV](event: String, read: (Element, EV) T, write: (Element, T) Unit)
(implicit rb: ReactiveRead[Element, EventListener[Element, EV]],
wb: ReactiveWrite[Element, Modify[Element, T]]): Modifier = new Modifier {
def reactiveReadWrite[EV](event: String, read: (Element, EV) T, write: (Element, T) Unit)(implicit
rb: ReactiveRead[Element, EventListener[Element, EV]],
wb: ReactiveWrite[Element, Modify[Element, T]]
): Modifier = new Modifier {
override def applyTo(t: Element): Unit = {
writeModifier(ReactiveBinds.Modify(value, write)).applyTo(t)
reactiveRead(event, read).applyTo(t)
Expand All @@ -39,8 +42,10 @@ trait ReactiveImplicits { self: RenderingContext ⇒
readModifier(FormValue(value))
}

def reactiveInput(implicit rb: ReactiveRead[Element, FormValue[T]],
wb: ReactiveWrite[Element, FormValue[T]]): Modifier = new Modifier {
def reactiveInput(implicit
rb: ReactiveRead[Element, FormValue[T]],
wb: ReactiveWrite[Element, FormValue[T]]
): Modifier = new Modifier {
def applyTo(t: Element): Unit = {
writeModifier(FormValue(value)).applyTo(t)
readModifier(FormValue(value)).applyTo(t)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ import scalatags.generic

import com.karasiq.bootstrap.components.BootstrapComponents

trait RenderingContext extends ReactiveBinds with ReactiveImplicits with Callbacks
with BootstrapComponents with ClassModifiers {

trait RenderingContext
extends ReactiveBinds
with ReactiveImplicits
with Callbacks
with BootstrapComponents
with ClassModifiers {

type Element
type Output <: FragT
type FragT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ trait TextCallbacks extends Callbacks { self: RenderingContext ⇒

protected type ClickElement = Any
protected type InputElement = Any
protected type FormElement = Any
protected type FormElement = Any

object Callback extends CallbackFactory {
def onClick(f: ClickElement => Unit): Callback = {
def onClick(f: ClickElement Unit): Callback = {
()
}

def onInput(f: (InputElement) => Unit): Callback = {
def onInput(f: (InputElement) Unit): Callback = {
()
}

def onSubmit(f: (FormElement) => Unit): Callback = {
def onSubmit(f: (FormElement) Unit): Callback = {
()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ trait TextClassModifiers extends ClassModifiers { self: TextRenderingContext ⇒

case classIndex
val (key, value) = e.attrs(classIndex)
val newValue = f(extractClasses(value))
val newValue = f(extractClasses(value))
e.attrs(classIndex) = (key, ClassesValueSource(newValue))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ trait TextReactiveBinds extends ReactiveBinds { self: TextRenderingContext ⇒

private[this] val NO_OP_BIND: ReactiveRW[Element, Nothing] = new ReactiveRW[Element, Nothing] {
def bindWrite(element: Builder, property: Nothing): Unit = ()
def bindRead(element: Builder, property: Nothing): Unit = ()
def bindRead(element: Builder, property: Nothing): Unit = ()
}

implicit def rxEventListener[EL <: Element, EV <: Event]: ReactiveRead[EL, ReactiveBinds.EventListener[EL, EV]] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import scala.language.postfixOps

trait TextRenderingContext extends RenderingContext with TextReactiveBinds with TextCallbacks with TextClassModifiers {
type Element = scalatags.text.Builder
type Output = String
type FragT = String
type Output = String
type FragT = String

val scalaTags = scalatags.Text
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ object BootstrapJQueryContext {
object bootstrap extends js.Object
}

//noinspection ScalaUnusedExpression
// noinspection ScalaUnusedExpression
def useNpmImports(): Unit = {
imports.bootstrap
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ package com.karasiq.bootstrap4

import rx._

/**
* Global context
/** Global context
*/
object Bootstrap {
private[this] lazy val _scalaRxContext = Ctx.Owner.safe()

lazy val js: JSBootstrapBundle = JSBootstrapBundle()(_scalaRxContext)
lazy val text: TextBootstrapBundle = TextBootstrapBundle()(_scalaRxContext)
lazy val js: JSBootstrapBundle = JSBootstrapBundle()(_scalaRxContext)
lazy val text: TextBootstrapBundle = TextBootstrapBundle()(_scalaRxContext)
lazy val default: JSBootstrapBundle = js
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@ import com.karasiq.bootstrap4.popover.JSPopovers
import com.karasiq.bootstrap4.tooltip.JSTooltips

// JS components implementation
trait JSBootstrapBundle extends UniversalBootstrapBundle with JSRenderingContext with JSModals with JSTooltips
with JSPopovers with JSNavigationBars with JSCarousels with BootstrapJQueryContext
trait JSBootstrapBundle
extends UniversalBootstrapBundle
with JSRenderingContext
with JSModals
with JSTooltips
with JSPopovers
with JSNavigationBars
with JSCarousels
with BootstrapJQueryContext

object JSBootstrapBundle {
def apply()(implicit rx: Ctx.Owner): JSBootstrapBundle = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import scala.scalajs.js

@js.native
trait JSCarouselOptions extends js.Object {
var interval: Int = js.native
var pause: String = js.native
var wrap: Boolean = js.native
var interval: Int = js.native
var pause: String = js.native
var wrap: Boolean = js.native
var keyboard: Boolean = js.native
}
Loading

0 comments on commit e1f7b52

Please sign in to comment.