some things working

This commit is contained in:
Julian 2025-06-06 22:41:28 +02:00
parent a555247467
commit c76d6cbb39
12 changed files with 118 additions and 157 deletions

2
.scalafmt.conf Normal file
View file

@ -0,0 +1,2 @@
version = "3.7.15"
runner.dialect = scala3

View file

@ -25,4 +25,5 @@ lazy val fahrtenbuch = project.in(file("."))
* It provides static types for the browser DOM APIs. * It provides static types for the browser DOM APIs.
*/ */
libraryDependencies += "org.scala-js" %%% "scalajs-dom" % "2.8.0", libraryDependencies += "org.scala-js" %%% "scalajs-dom" % "2.8.0",
libraryDependencies += "com.raquo" %%% "laminar" % "17.2.1"
) )

View file

@ -2,12 +2,11 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title> <title>Vite App</title>
</head> </head>
<body> <body>
<div id="app"></div>
<script type="module" src="/main.js"></script> <script type="module" src="/main.js"></script>
<div id="app"></div>
</body> </body>
</html> </html>

View file

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="32" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path fill="#F7DF1E" d="M0 0h256v256H0V0Z"></path><path d="m67.312 213.932l19.59-11.856c3.78 6.701 7.218 12.371 15.465 12.371c7.905 0 12.89-3.092 12.89-15.12v-81.798h24.057v82.138c0 24.917-14.606 36.259-35.916 36.259c-19.245 0-30.416-9.967-36.087-21.996m85.07-2.576l19.588-11.341c5.157 8.421 11.859 14.607 23.715 14.607c9.969 0 16.325-4.984 16.325-11.858c0-8.248-6.53-11.17-17.528-15.98l-6.013-2.58c-17.357-7.387-28.87-16.667-28.87-36.257c0-18.044 13.747-31.792 35.228-31.792c15.294 0 26.292 5.328 34.196 19.247l-18.732 12.03c-4.125-7.389-8.591-10.31-15.465-10.31c-7.046 0-11.514 4.468-11.514 10.31c0 7.217 4.468 10.14 14.778 14.608l6.014 2.577c20.45 8.765 31.963 17.7 31.963 37.804c0 21.654-17.012 33.51-39.867 33.51c-22.339 0-36.774-10.654-43.819-24.574"></path></svg>

Before

Width:  |  Height:  |  Size: 995 B

23
main.js
View file

@ -1,23 +1,2 @@
import './style.css' import './style.css'
import javascriptLogo from './javascript.svg' import 'scalajs:main.js'
import { setupCounter } from './counter.js'
document.querySelector('#app').innerHTML = `
<div>
<a href="https://vitejs.dev" target="_blank">
<img src="/vite.svg" class="logo" alt="Vite logo" />
</a>
<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript" target="_blank">
<img src="${javascriptLogo}" class="logo vanilla" alt="JavaScript logo" />
</a>
<h1>Hello Vite!</h1>
<div class="card">
<button id="counter" type="button"></button>
</div>
<p class="read-the-docs">
Click on the Vite logo to learn more
</p>
</div>
`
setupCounter(document.querySelector('#counter'))

34
package-lock.json generated
View file

@ -7,7 +7,13 @@
"": { "": {
"name": "fahrtenbuch", "name": "fahrtenbuch",
"version": "0.0.0", "version": "0.0.0",
"dependencies": {
"@material-design-icons/font": "^0.14.15",
"@mdi/font": "^7.4.47",
"bulma": "^1.0.4"
},
"devDependencies": { "devDependencies": {
"@scala-js/vite-plugin-scalajs": "^1.0.0",
"vite": "^4.1.0" "vite": "^4.1.0"
} }
}, },
@ -385,6 +391,34 @@
"node": ">=12" "node": ">=12"
} }
}, },
"node_modules/@material-design-icons/font": {
"version": "0.14.15",
"resolved": "https://registry.npmjs.org/@material-design-icons/font/-/font-0.14.15.tgz",
"integrity": "sha512-h4YFZnYxNuciEKR0jAOekaQmIg2UGUSxbnoyzo4OdE42gy9QB3UnrjLcASiDy9ra8fqrcHy+NqxTHx7F86BH0A==",
"license": "Apache-2.0"
},
"node_modules/@mdi/font": {
"version": "7.4.47",
"resolved": "https://registry.npmjs.org/@mdi/font/-/font-7.4.47.tgz",
"integrity": "sha512-43MtGpd585SNzHZPcYowu/84Vz2a2g31TvPMTm9uTiCSWzaheQySUcSyUH/46fPnuPQWof2yd0pGBtzee/IQWw==",
"license": "Apache-2.0"
},
"node_modules/@scala-js/vite-plugin-scalajs": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/@scala-js/vite-plugin-scalajs/-/vite-plugin-scalajs-1.0.0.tgz",
"integrity": "sha512-QqeOXFWiwZyl4LrtAg7ZMeoShVWTD+4qcmuv0M7QNCu8QYzf+h3ysozbmyWYJKVpxJYMLnuSZZSiygD8Tzh+eg==",
"dev": true,
"license": "Apache-2.0",
"dependencies": {
"vite": "^4.1.4"
}
},
"node_modules/bulma": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/bulma/-/bulma-1.0.4.tgz",
"integrity": "sha512-Ffb6YGXDiZYX3cqvSbHWqQ8+LkX6tVoTcZuVB3lm93sbAVXlO0D6QlOTMnV6g18gILpAXqkG2z9hf9z4hCjz2g==",
"license": "MIT"
},
"node_modules/esbuild": { "node_modules/esbuild": {
"version": "0.18.20", "version": "0.18.20",
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.18.20.tgz", "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.18.20.tgz",

View file

@ -9,6 +9,12 @@
"preview": "vite preview" "preview": "vite preview"
}, },
"devDependencies": { "devDependencies": {
"@scala-js/vite-plugin-scalajs": "^1.0.0",
"vite": "^4.1.0" "vite": "^4.1.0"
},
"dependencies": {
"@material-design-icons/font": "^0.14.15",
"@mdi/font": "^7.4.47",
"bulma": "^1.0.4"
} }
} }

View file

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>

Before

Width:  |  Height:  |  Size: 1.5 KiB

View file

@ -0,0 +1,11 @@
package fahrtenbuch
import scala.scalajs.js.Date
case class Entry(startKm: Double, endKm: Double, date: Date, animal: String, paid: Boolean, driver: String):
val distance = endKm - startKm
// 13 cent pro km, 5 cent Abnutzung
def costGas: Double = distance * 0.13
def costWear: Double = distance * 0.05
def costTotal: Double = costGas + costWear

View file

@ -1,44 +1,64 @@
package livechart package fahrtenbuch
import scala.scalajs.js import scala.scalajs.js
import scala.scalajs.js.annotation.* import scala.scalajs.js.annotation.*
import org.scalajs.dom import org.scalajs.dom
import com.raquo.laminar.api.L.{*, given}
import scala.scalajs.js.Date
// import javascriptLogo from "/javascript.svg" // import javascriptLogo from "/javascript.svg"
@js.native @JSImport("/javascript.svg", JSImport.Default) //@js.native @JSImport("/javascript.svg", JSImport.Default)
val javascriptLogo: String = js.native //val javascriptLogo: String = js.native
@main @main
def LiveChart(): Unit = def Fahrtenbuch(): Unit =
dom.document.querySelector("#app").innerHTML = s""" renderOnDomContentLoaded(
<div> dom.document.getElementById("app"),
<a href="https://vitejs.dev" target="_blank"> Main.appElement()
<img src="/vite.svg" class="logo" alt="Vite logo" /> )
</a> println("Hello, Worlds!")
<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript" target="_blank">
<img src="$javascriptLogo" class="logo vanilla" alt="JavaScript logo" />
</a>
<h1>Hello Scala.js!</h1>
<div class="card">
<button id="counter" type="button"></button>
</div>
<p class="read-the-docs">
Click on the Vite logo to learn more
</p>
</div>
"""
setupCounter(dom.document.getElementById("counter")) object Main {
end LiveChart
def setupCounter(element: dom.Element): Unit = val entries = List(
var counter = 0 Entry(100.0, 200.0, new Date(), "🐷", true, "Gesine"),
Entry(200.0, 300.0, new Date(), "Dog", false, "Bob")
)
def setCounter(count: Int): Unit = def appElement(): HtmlElement =
counter = count div(
element.innerHTML = s"count is $counter" cls := "app content",
h1("Fahrtenbuch"),
element.addEventListener("click", e => setCounter(counter + 1)) table(
setCounter(0) cls := "table",
end setupCounter thead(
tr(
th("Date"),
th("Fahrer*in"),
th("Start Km"),
th("Ende Km"),
th("Tier"),
th("Abnutzung"),
th("Gesamtkosten"),
th("Bezahlt")
)
),
tbody(
entries.map(entry =>
tr(
td(entry.date.toDateString()),
td(entry.driver),
td(entry.startKm),
td(entry.endKm),
td(entry.animal),
td(entry.costWear),
td(entry.costTotal),
td(entry.paid),
td(span(cls := "icon", i(cls := "mdi mdi-pencil-box")))
)
)
)
),
button(cls := "button is-primary", "Eintrag hinzufügen")
)
}

View file

@ -1,97 +1,2 @@
:root { @import '@mdi/font';
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif; @import "bulma/css/bulma.css";
line-height: 1.5;
font-weight: 400;
color-scheme: light dark;
color: rgba(255, 255, 255, 0.87);
background-color: #242424;
font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
-webkit-text-size-adjust: 100%;
}
a {
font-weight: 500;
color: #646cff;
text-decoration: inherit;
}
a:hover {
color: #535bf2;
}
body {
margin: 0;
display: flex;
place-items: center;
min-width: 320px;
min-height: 100vh;
}
h1 {
font-size: 3.2em;
line-height: 1.1;
}
#app {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}
.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: filter 300ms;
}
.logo:hover {
filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.vanilla:hover {
filter: drop-shadow(0 0 2em #f7df1eaa);
}
.card {
padding: 2em;
}
.read-the-docs {
color: #888;
}
button {
border-radius: 8px;
border: 1px solid transparent;
padding: 0.6em 1.2em;
font-size: 1em;
font-weight: 500;
font-family: inherit;
background-color: #1a1a1a;
cursor: pointer;
transition: border-color 0.25s;
}
button:hover {
border-color: #646cff;
}
button:focus,
button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
}
@media (prefers-color-scheme: light) {
:root {
color: #213547;
background-color: #ffffff;
}
a:hover {
color: #747bff;
}
button {
background-color: #f9f9f9;
}
}

6
vite.config.js Normal file
View file

@ -0,0 +1,6 @@
import { defineConfig } from "vite";
import scalaJSPlugin from "@scala-js/vite-plugin-scalajs";
export default defineConfig({
plugins: [scalaJSPlugin()],
});