Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions generator/builder.sc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** Code generator
*
* These classes turn component definitions into Scala code.
*/
*
* These classes turn component definitions into Scala code.
*/

import $file.definition

Expand All @@ -10,20 +10,20 @@ import definition._
case class GitHubRepository(owner: String, repository: String)

class SBTProjectBuilder(
col: WebComponentCollection,
organization: String,
version: String,
publishTo: GitHubRepository
) {
def name = s"laminar-web-components-${col.packageName}"
col: WebComponentCollection,
organization: String,
version: String,
publishTo: GitHubRepository,
) {
def name = s"laminar-web-components-${col.packageName}"

def buildNpmDep(p: NpmPackage) = s"""npmDependencies in Compile += "${p.name}" -> "${p.version}""""
def buildNpmDep(p: NpmPackage) = s"""npmDependencies in Compile += "${p.name}" -> "${p.version}""""

def getNpmDeps(comp: WebComponent): Seq[NpmPackage] = Seq(comp.npmPackage) ++ comp.subComponents.flatMap(getNpmDeps)
def getNpmDeps(comp: WebComponent): Seq[NpmPackage] = Seq(comp.npmPackage) ++ comp.subComponents.flatMap(getNpmDeps)

def buildNPMDeps = col.components.flatMap(getNpmDeps).distinct.map(buildNpmDep).mkString("\n\n")
def buildNPMDeps = col.components.flatMap(getNpmDeps).distinct.map(buildNpmDep).mkString("\n\n")

def build = s"""
def build = s"""
enablePlugins(ScalaJSPlugin)

enablePlugins(ScalaJSBundlerPlugin)
Expand Down Expand Up @@ -98,6 +98,8 @@ class CollectionBuilder(col: WebComponentCollection, organization: String) {
import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

object ElementAsIsCodec extends AsIsCodec[HtmlElement]

${buildStylesObject(col.globalCssProperties, docLink)}

${col.components.map(c => new Builder(c).build).mkString("\n")}
Expand All @@ -115,6 +117,7 @@ class Builder(comp: WebComponent) {
case WebComponentFieldType.Boolean => "Boolean"
case WebComponentFieldType.Number => "Double"
case WebComponentFieldType.String => "String"
case WebComponentFieldType.Element => "HtmlElement"
}

def propCodec(wctype: WebComponentFieldType) =
Expand All @@ -123,6 +126,7 @@ class Builder(comp: WebComponent) {
case WebComponentFieldType.Boolean => "BooleanAsIsCodec"
case WebComponentFieldType.Number => "DoubleAsIsCodec"
case WebComponentFieldType.String => "StringAsIsCodec"
case WebComponentFieldType.Element => "ElementAsIsCodec"
}

def buildMethodSignature(m: Method) = s"""
Expand Down
85 changes: 43 additions & 42 deletions generator/definition.sc
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
/** Web Component Data Model
*
* These case classes describe web components - their tags, properties, etc.
*/
*
* These case classes describe web components - their tags, properties, etc.
*/


case class WebComponentCollection(
packageName: String,
components: Seq[WebComponent],
link: String,
globalCssProperties: Seq[CSSProperty],
)
packageName: String,
components: Seq[WebComponent],
link: String,
globalCssProperties: Seq[CSSProperty],
)

case class WebComponent(
tag: String,
description: String,
link: String,
npmPackage: NpmPackage,
jsImport: String,
slots: Slots = Slots(None, Seq.empty),
properties: Seq[Property] = Seq.empty,
methods: Seq[Method] = Seq.empty,
events: Seq[Event] = Seq.empty,
cssProperties: Seq[CSSProperty] = Seq.empty,
subComponents: Seq[WebComponent] = Seq.empty,
)
tag: String,
description: String,
link: String,
npmPackage: NpmPackage,
jsImport: String,
slots: Slots = Slots(None, Seq.empty),
properties: Seq[Property] = Seq.empty,
methods: Seq[Method] = Seq.empty,
events: Seq[Event] = Seq.empty,
cssProperties: Seq[CSSProperty] = Seq.empty,
subComponents: Seq[WebComponent] = Seq.empty,
)

case class NpmPackage(name: String, version: String)

Expand All @@ -32,41 +32,42 @@ object WebComponentFieldType {
case object String extends WebComponentFieldType
case object Boolean extends WebComponentFieldType
case object Number extends WebComponentFieldType
case object Element extends WebComponentFieldType
case object Any extends WebComponentFieldType
}

case class Property(
name: String,
tpe: WebComponentFieldType,
description: String,
isReadOnly: Boolean = false, // TODO: update definitions to reflect this
)
name: String,
tpe: WebComponentFieldType,
description: String,
isReadOnly: Boolean = false, // TODO: update definitions to reflect this
)

case class Method(
name: String,
description: String,
// TODO: support parameters and return values
)
name: String,
description: String,
// TODO: support parameters and return values
)

case class Event(
name: String,
description: String,
// TODO: support details
)
name: String,
description: String,
// TODO: support details
)

case class Slots(default: Option[DefaultSlot], named: Seq[NamedSlot])

case class NamedSlot(
name: String,
description: String,
)
name: String,
description: String,
)

case class DefaultSlot(
description: String,
)
description: String,
)

case class CSSProperty(
name: String,
description: String,
// TODO: support defaults and maybe types
)
name: String,
description: String,
// TODO: support defaults and maybe types
)
4 changes: 2 additions & 2 deletions generator/material.sc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** Web Component definitions for Google's Material Web Components
*/
*/

import $file.definition

Expand Down Expand Up @@ -1457,7 +1457,7 @@ val componentCollection = WebComponentCollection(
),
Property(
name = "anchor",
tpe = WebComponentFieldType.Any,
tpe = WebComponentFieldType.Element,
description =
"Determines from which element the floating menu should calculate sizing and position offsets. In the default case, both mwc-menu and the anchor should share a parent with position:relative. Changing anchor typically requires absolute or fixed.",
),
Expand Down
Loading