From 3abf9312fa4b10b20296ba60a75c9aa351828b13 Mon Sep 17 00:00:00 2001
From: sverben <59171289+sverben@users.noreply.github.com>
Date: Sat, 7 Dec 2024 20:05:09 +0100
Subject: [PATCH] chore: biome
---
src/app.css | 95 ++++++++++---------
src/lib/components/core/header/Header.svelte | 14 ++-
.../components/core/popups/Renderer.svelte | 2 +-
.../core/popups/popups/About.svelte | 2 +-
.../popups/popups/BrowserNotSupported.svelte | 2 +-
.../core/popups/popups/Connect.svelte | 22 +++--
.../core/popups/popups/Credits.svelte | 2 +-
.../core/popups/popups/DriverInstall.svelte | 2 +-
.../core/popups/popups/Examples.svelte | 2 +-
.../core/popups/popups/Explanation.svelte | 2 +-
.../popups/popups/LanguageSelector.svelte | 4 +-
.../core/popups/popups/Prompt.svelte | 2 +-
.../core/popups/popups/PythonUploader.svelte | 10 +-
.../core/popups/popups/SerialMonitor.svelte | 12 ++-
.../core/popups/popups/UploadLog.svelte | 2 +-
.../core/popups/popups/Uploader.svelte | 11 ++-
.../core/popups/popups/Warning.svelte | 2 +-
.../core/sidepanel/SidePanel.svelte | 2 +-
src/lib/components/start/RobotSelector.svelte | 2 +-
src/lib/components/start/Start.svelte | 44 +++++----
src/lib/components/ui/Button.svelte | 2 +-
src/lib/components/ui/Chart.svelte | 2 +-
src/lib/components/ui/CodeEditor.svelte | 8 +-
.../components/ui/ComponentRenderer.svelte | 10 +-
src/lib/components/ui/Library.svelte | 4 +-
src/lib/components/ui/Tree.svelte | 2 +-
src/lib/components/workspace/Workspace.svelte | 2 +-
.../components/workspace/blocks/Blocks.svelte | 25 +++--
.../components/workspace/python/Python.svelte | 13 ++-
.../workspace/python/Terminal.svelte | 4 +-
src/lib/domain/blockly/blockly.ts | 84 ++++++++--------
src/lib/micropython/index.ts | 4 +-
src/lib/programmers/AvrDude.ts | 4 +-
src/lib/programmers/DFU.ts | 2 +-
src/lib/programmers/Pico.ts | 2 +-
src/lib/state/app.svelte.ts | 16 ++--
src/lib/state/blockly.svelte.ts | 18 ++--
src/lib/state/popup.svelte.ts | 72 +++++++-------
src/lib/state/serial.svelte.ts | 68 ++++++-------
src/lib/state/upload.svelte.ts | 8 +-
src/lib/state/utils.ts | 3 +-
src/lib/state/workspace.svelte.ts | 42 ++++----
42 files changed, 335 insertions(+), 296 deletions(-)
diff --git a/src/app.css b/src/app.css
index d9427d3..a0182c5 100644
--- a/src/app.css
+++ b/src/app.css
@@ -1,78 +1,79 @@
* {
- box-sizing: border-box;
+ box-sizing: border-box;
}
body {
- --shadow-el1: 0 5px 5px -3px #0003, 0 8px 10px 1px #00000024,
- 0 3px 14px 2px #0000001f;
- --shadow-el2: 0px 11px 15px -7px rgba(0, 0, 0, 0.2),
- 0px 24px 38px 3px rgba(0, 0, 0, 0.14),
- 0px 9px 46px 8px rgba(0, 0, 0, 0.12);
+ --shadow-el1: 0 5px 5px -3px #0003, 0 8px 10px 1px #00000024, 0 3px 14px 2px
+ #0000001f;
+ --shadow-el2:
+ 0px 11px 15px -7px rgba(0, 0, 0, 0.2),
+ 0px 24px 38px 3px rgba(0, 0, 0, 0.14),
+ 0px 9px 46px 8px rgba(0, 0, 0, 0.12);
- --full-height: calc(100vh - 64px);
+ --full-height: calc(100vh - 64px);
}
body[data-color-scheme="light"] {
- --background: #fff;
- --robot: #fff;
- --on-background: #000;
- --background-tint: #f1f1f1;
- --primary: #06778f;
- --primary-dark-tint: #035e72;
- --on-primary: #fff;
- --secondary: lightgray;
- --on-secondary: black;
- --on-secondary-muted: rgb(109, 109, 109);
- --accent: #32a5a9;
- --on-accent: #fff;
- --text-muted: #d3d3d3;
- --warning: #ffcc00;
+ --background: #fff;
+ --robot: #fff;
+ --on-background: #000;
+ --background-tint: #f1f1f1;
+ --primary: #06778f;
+ --primary-dark-tint: #035e72;
+ --on-primary: #fff;
+ --secondary: lightgray;
+ --on-secondary: black;
+ --on-secondary-muted: rgb(109, 109, 109);
+ --accent: #32a5a9;
+ --on-accent: #fff;
+ --text-muted: #d3d3d3;
+ --warning: #ffcc00;
}
body[data-color-scheme="dark"] {
- --background: #24242b;
- --robot: #303039;
- --on-background: #fff;
- --background-tint: #22222c;
- --primary: #104d59;
- --primary-dark-tint: #1c798b;
- --on-primary: #fff;
- --secondary: #303039;
- --on-secondary: #fff;
- --on-secondary-muted: rgb(190, 190, 190);
- --accent: #32a5a9;
- --on-accent: #fff;
- --text-muted: #535361;
+ --background: #24242b;
+ --robot: #303039;
+ --on-background: #fff;
+ --background-tint: #22222c;
+ --primary: #104d59;
+ --primary-dark-tint: #1c798b;
+ --on-primary: #fff;
+ --secondary: #303039;
+ --on-secondary: #fff;
+ --on-secondary-muted: rgb(190, 190, 190);
+ --accent: #32a5a9;
+ --on-accent: #fff;
+ --text-muted: #535361;
--warning: #ffcc00;
}
body {
- margin: 0;
- background: var(--background-tint);
- color: var(--on-background);
- font-family: sans-serif;
- overflow: hidden;
+ margin: 0;
+ background: var(--background-tint);
+ color: var(--on-background);
+ font-family: sans-serif;
+ overflow: hidden;
}
.blocklyToolboxCategory {
- margin: 3px 0;
+ margin: 3px 0;
}
.blocklyTreeRow {
- box-sizing: content-box;
+ box-sizing: content-box;
}
.injectionDiv > .blocklyFlyout {
- transform: translate(80px, 0) !important;
+ transform: translate(80px, 0) !important;
}
table,
tr,
td {
- border: none;
- margin: 0;
- border-spacing: 0;
+ border: none;
+ margin: 0;
+ border-spacing: 0;
}
.blocklySvg {
- z-index: 0;
- background-color: transparent !important;
+ z-index: 0;
+ background-color: transparent !important;
}
diff --git a/src/lib/components/core/header/Header.svelte b/src/lib/components/core/header/Header.svelte
index b9287ff..05e5276 100644
--- a/src/lib/components/core/header/Header.svelte
+++ b/src/lib/components/core/header/Header.svelte
@@ -13,8 +13,8 @@ import { robots } from "$domain/robots";
import AppState, { Screen, Theme } from "$state/app.svelte";
import BlocklyState from "$state/blockly.svelte";
import PopupState from "$state/popup.svelte";
+import SerialState, { Prompt } from "$state/serial.svelte";
import WorkspaceState, { Mode } from "$state/workspace.svelte";
-import SerialState, { Prompt } from "$state/serial.svelte"
import {
faComment,
faDownload,
@@ -78,7 +78,9 @@ async function newProject() {
function serialize() {
if (WorkspaceState.Mode === Mode.BLOCKS)
- return JSON.stringify(serialization.workspaces.save(BlocklyState.workspace));
+ return JSON.stringify(
+ serialization.workspaces.save(BlocklyState.workspace),
+ );
return WorkspaceState.code;
}
@@ -129,7 +131,9 @@ async function openProject() {
WorkspaceState.code = await content.text();
} else {
if (WorkspaceState.Mode === Mode.BLOCKS) {
- if (!loadWorkspaceFromString(await content.text(), BlocklyState.workspace)) {
+ if (
+ !loadWorkspaceFromString(await content.text(), BlocklyState.workspace)
+ ) {
return;
}
} else {
@@ -233,7 +237,9 @@ async function blocks() {
}
WorkspaceState.tempSave();
- BlocklyState.restore = JSON.parse(localStorage.getItem(`${WorkspaceState.robot.id}_content`))
+ BlocklyState.restore = JSON.parse(
+ localStorage.getItem(`${WorkspaceState.robot.id}_content`),
+ );
WorkspaceState.Mode = Mode.BLOCKS;
}
diff --git a/src/lib/components/core/popups/Renderer.svelte b/src/lib/components/core/popups/Renderer.svelte
index 1b480dd..341ce69 100644
--- a/src/lib/components/core/popups/Renderer.svelte
+++ b/src/lib/components/core/popups/Renderer.svelte
@@ -4,7 +4,7 @@ import { onMount } from "svelte";
import Popup from "./Popup.svelte";
onMount(async () => {
- await PopupState.setup()
+ await PopupState.setup();
});
diff --git a/src/lib/components/core/popups/popups/About.svelte b/src/lib/components/core/popups/popups/About.svelte
index 52296c8..c48eaca 100644
--- a/src/lib/components/core/popups/popups/About.svelte
+++ b/src/lib/components/core/popups/popups/About.svelte
@@ -1,7 +1,7 @@
diff --git a/src/lib/components/core/popups/popups/Prompt.svelte b/src/lib/components/core/popups/popups/Prompt.svelte
index a2b5ef2..7e89bd5 100644
--- a/src/lib/components/core/popups/popups/Prompt.svelte
+++ b/src/lib/components/core/popups/popups/Prompt.svelte
@@ -1,7 +1,7 @@
diff --git a/src/lib/components/core/popups/popups/Uploader.svelte b/src/lib/components/core/popups/popups/Uploader.svelte
index a1364a5..e8f2610 100644
--- a/src/lib/components/core/popups/popups/Uploader.svelte
+++ b/src/lib/components/core/popups/popups/Uploader.svelte
@@ -4,11 +4,14 @@ import { _ } from "svelte-i18n";
import ErrorPopup from "$components/core/popups/popups/Error.svelte";
import Button from "$components/ui/Button.svelte";
import ProgressBar from "$components/ui/ProgressBar.svelte";
+import AppState from "$state/app.svelte";
import PopupsState, { type PopupState } from "$state/popup.svelte";
+import SerialState, {
+ Prompt,
+ SUPPORTED_VENDOR_IDS,
+} from "$state/serial.svelte";
import USBRequestState from "$state/upload.svelte";
-import AppState from "$state/app.svelte"
import WorkspaceState from "$state/workspace.svelte";
-import SerialState, { Prompt, SUPPORTED_VENDOR_IDS } from "$state/serial.svelte"
import { getContext, onMount } from "svelte";
import { downloadDrivers } from "../../../../drivers";
@@ -45,7 +48,9 @@ async function compile() {
board: WorkspaceState.robot.fqbn,
libraries: [
...WorkspaceState.robot.libraries,
- ...AppState.libraries.installed.map(([name, version]) => `${name}@${version}`),
+ ...AppState.libraries.installed.map(
+ ([name, version]) => `${name}@${version}`,
+ ),
],
}),
});
diff --git a/src/lib/components/core/popups/popups/Warning.svelte b/src/lib/components/core/popups/popups/Warning.svelte
index 3a3d977..74955c2 100644
--- a/src/lib/components/core/popups/popups/Warning.svelte
+++ b/src/lib/components/core/popups/popups/Warning.svelte
@@ -1,6 +1,6 @@
diff --git a/src/lib/components/ui/CodeEditor.svelte b/src/lib/components/ui/CodeEditor.svelte
index 7bd8e8c..1f8dfb0 100644
--- a/src/lib/components/ui/CodeEditor.svelte
+++ b/src/lib/components/ui/CodeEditor.svelte
@@ -1,8 +1,8 @@
diff --git a/src/lib/components/ui/Library.svelte b/src/lib/components/ui/Library.svelte
index 59c6fad..55e3b11 100644
--- a/src/lib/components/ui/Library.svelte
+++ b/src/lib/components/ui/Library.svelte
@@ -17,7 +17,9 @@ const isInstalled = $derived(
function interact() {
if (isInstalled)
- return AppState.libraries.installed = AppState.libraries.installed.filter(([name]) => name !== library.name)
+ return (AppState.libraries.installed = AppState.libraries.installed.filter(
+ ([name]) => name !== library.name,
+ ));
AppState.libraries.installed.push([library.name, version]);
}
diff --git a/src/lib/components/ui/Tree.svelte b/src/lib/components/ui/Tree.svelte
index 06382b3..31f0b51 100644
--- a/src/lib/components/ui/Tree.svelte
+++ b/src/lib/components/ui/Tree.svelte
@@ -6,8 +6,8 @@ import {
faFolder,
} from "@fortawesome/free-solid-svg-icons";
import Fa from "svelte-fa";
+import Tree from "./Tree.svelte";
import type { Tree as TreeType } from "./Tree.types";
-import Tree from "./Tree.svelte"
interface Props {
tree: TreeType;
diff --git a/src/lib/components/workspace/Workspace.svelte b/src/lib/components/workspace/Workspace.svelte
index f18ceeb..c4717a3 100644
--- a/src/lib/components/workspace/Workspace.svelte
+++ b/src/lib/components/workspace/Workspace.svelte
@@ -1,6 +1,7 @@
diff --git a/src/lib/components/workspace/python/Python.svelte b/src/lib/components/workspace/python/Python.svelte
index 0363ebe..31575f0 100644
--- a/src/lib/components/workspace/python/Python.svelte
+++ b/src/lib/components/workspace/python/Python.svelte
@@ -54,15 +54,14 @@ $effect(() => {
WorkspaceState.code = await WorkspaceState.microPythonIO.fs.read("main.py");
WorkspaceState.handle = new PythonHandle("main.py");
- })()
-})
+ })();
+});
$effect(() => {
- if (!(WorkspaceState.handle instanceof FileHandle))
- return
+ if (!(WorkspaceState.handle instanceof FileHandle)) return;
tree = undefined;
-})
+});
async function select(tree: string[]) {
selected = tree;
@@ -75,14 +74,14 @@ async function select(tree: string[]) {
}
async function create(path: string[], type: "file" | "folder") {
- const name = await PopupState.open({
+ const name = (await PopupState.open({
component: Prompt,
data: {
name: type === "file" ? "CREATE_FILE" : "CREATE_FOLDER",
confirm: "OK_VARIABLE",
},
allowInteraction: false,
- }) as string;
+ })) as string;
if (!name) return;
const io = WorkspaceState.microPythonIO;
diff --git a/src/lib/components/workspace/python/Terminal.svelte b/src/lib/components/workspace/python/Terminal.svelte
index b2186e9..77ed4f8 100644
--- a/src/lib/components/workspace/python/Terminal.svelte
+++ b/src/lib/components/workspace/python/Terminal.svelte
@@ -126,7 +126,7 @@ $effect(() => {
render();
});
-})
+});
$effect(() => {
if (!WorkspaceState.microPythonRun) return;
@@ -139,7 +139,7 @@ $effect(() => {
terminal.write(`\x1b[31m${event.data}\x1b[0m`);
});
WorkspaceState.microPythonRun.addEventListener("done", render);
-})
+});
diff --git a/src/lib/domain/blockly/blockly.ts b/src/lib/domain/blockly/blockly.ts
index b984511..7127369 100644
--- a/src/lib/domain/blockly/blockly.ts
+++ b/src/lib/domain/blockly/blockly.ts
@@ -78,9 +78,9 @@ Blockly.dialog.setPrompt(async (_, defaultValue, callback) => {
const play = Blockly.WorkspaceAudio.prototype.play;
Blockly.WorkspaceAudio.prototype.play = function (name, opt_volume) {
- if (!BlocklyState.audio) return
+ if (!BlocklyState.audio) return;
- play.call(this, name, opt_volume)
+ play.call(this, name, opt_volume);
};
export function loadToolbox(robot: RobotDevice): ToolboxDefinition {
@@ -303,49 +303,47 @@ export async function explain(block: Blockly.BlockSvg) {
};
const position = block.pathObject.svgPath.getBoundingClientRect();
- await PopupState.open(
- {
- component: Explanation,
- data: {
- explanation: fetch(`${import.meta.env.VITE_BACKEND_URL}/ai/generate`, {
- method: "post",
- headers: {
- "content-type": "application/json",
- },
- body: JSON.stringify({
- messages: [
- {
- role: "system",
- content: `explain the selected portion of the following pseudo code (SELECT_BEGIN - SELECT_END) in simple terms, the pseudo code is directly generated from a blockly environment to program robots called Leaphy EasyBloqs, you must do this in ${
- locales[get(locale)]
- }`,
- },
- {
- role: "user",
- content: `\`\`\`\n${code}\n\`\`\``,
- },
- {
- role: "system",
- content:
- "please only return the explanation for the given set of code in simple terms, like you're explaining it to someone who has never touched code before, do not explain the code around the given set of code unless directly related, do not talk about or reference the pseudo code directly, you are talking about the selected code almost exclusively, so you do not have to include the **begin_select** and **end_select** tokens in your response, only include your explanation in the response",
- },
- ],
- model: "Llama3-70b-8192",
- }),
- }).then(async (res) => {
- if (!res.ok) throw new Error(res.statusText);
- return JSON.parse(await res.text());
+ await PopupState.open({
+ component: Explanation,
+ data: {
+ explanation: fetch(`${import.meta.env.VITE_BACKEND_URL}/ai/generate`, {
+ method: "post",
+ headers: {
+ "content-type": "application/json",
+ },
+ body: JSON.stringify({
+ messages: [
+ {
+ role: "system",
+ content: `explain the selected portion of the following pseudo code (SELECT_BEGIN - SELECT_END) in simple terms, the pseudo code is directly generated from a blockly environment to program robots called Leaphy EasyBloqs, you must do this in ${
+ locales[get(locale)]
+ }`,
+ },
+ {
+ role: "user",
+ content: `\`\`\`\n${code}\n\`\`\``,
+ },
+ {
+ role: "system",
+ content:
+ "please only return the explanation for the given set of code in simple terms, like you're explaining it to someone who has never touched code before, do not explain the code around the given set of code unless directly related, do not talk about or reference the pseudo code directly, you are talking about the selected code almost exclusively, so you do not have to include the **begin_select** and **end_select** tokens in your response, only include your explanation in the response",
+ },
+ ],
+ model: "Llama3-70b-8192",
}),
- },
- allowInteraction: true,
-
- position: {
- x: position.x + position.width + 10 - window.innerWidth / 2,
- y: position.y + 10 - window.innerHeight / 2,
- },
- anchor: Anchor.TopLeft,
+ }).then(async (res) => {
+ if (!res.ok) throw new Error(res.statusText);
+ return JSON.parse(await res.text());
+ }),
},
- );
+ allowInteraction: true,
+
+ position: {
+ x: position.x + position.width + 10 - window.innerWidth / 2,
+ y: position.y + 10 - window.innerHeight / 2,
+ },
+ anchor: Anchor.TopLeft,
+ });
}
const explainBlockOption: ContextMenuRegistry.RegistryItem = {
diff --git a/src/lib/micropython/index.ts b/src/lib/micropython/index.ts
index f488404..df2fa11 100644
--- a/src/lib/micropython/index.ts
+++ b/src/lib/micropython/index.ts
@@ -1,8 +1,8 @@
import PythonUploader from "$components/core/popups/popups/PythonUploader.svelte";
import type { RobotDevice } from "$domain/robots";
import PopupState from "$state/popup.svelte";
-import SerialState from "$state/serial.svelte"
-import {type LeaphyPort} from "$state/serial.svelte";
+import SerialState from "$state/serial.svelte";
+import type { LeaphyPort } from "$state/serial.svelte";
import base64 from "base64-js";
import { delay } from "../programmers/utils";
import { Commands } from "./commands";
diff --git a/src/lib/programmers/AvrDude.ts b/src/lib/programmers/AvrDude.ts
index c49f528..ce1e269 100644
--- a/src/lib/programmers/AvrDude.ts
+++ b/src/lib/programmers/AvrDude.ts
@@ -1,6 +1,6 @@
-import type {Programmer} from "$domain/robots.types";
+import type { Programmer } from "$domain/robots.types";
+import type { LeaphyPort } from "$state/serial.svelte";
import WorkspaceState from "$state/workspace.svelte";
-import type { LeaphyPort } from "$state/serial.svelte"
import Module from "@leaphy-robotics/avrdude-webassembly/avrdude.js";
declare global {
diff --git a/src/lib/programmers/DFU.ts b/src/lib/programmers/DFU.ts
index 048f401..8996d2d 100644
--- a/src/lib/programmers/DFU.ts
+++ b/src/lib/programmers/DFU.ts
@@ -1,6 +1,6 @@
import type { Programmer } from "$domain/robots.types";
+import SerialState, { type LeaphyPort } from "$state/serial.svelte";
import USBRequestState from "$state/upload.svelte";
-import SerialState, { type LeaphyPort } from "$state/serial.svelte"
import DFUUtil from "@leaphy-robotics/dfu-util-wasm";
import base64 from "base64-js";
import { delay } from "./utils";
diff --git a/src/lib/programmers/Pico.ts b/src/lib/programmers/Pico.ts
index 45fef50..ff4d426 100644
--- a/src/lib/programmers/Pico.ts
+++ b/src/lib/programmers/Pico.ts
@@ -1,6 +1,6 @@
import type { Programmer } from "$domain/robots.types";
+import SerialState, { type LeaphyPort } from "$state/serial.svelte";
import USBRequestState from "$state/upload.svelte";
-import SerialState, { type LeaphyPort } from "$state/serial.svelte"
import PicoTool from "@leaphy-robotics/picotool-wasm";
import base64 from "base64-js";
import { delay } from "./utils";
diff --git a/src/lib/state/app.svelte.ts b/src/lib/state/app.svelte.ts
index 76b2bde..d31b8ed 100644
--- a/src/lib/state/app.svelte.ts
+++ b/src/lib/state/app.svelte.ts
@@ -1,6 +1,6 @@
import Start from "$components/start/Start.svelte";
import Workspace from "$components/workspace/Workspace.svelte";
-import type {Component} from "svelte";
+import type { Component } from "svelte";
export const Screen = {
START: Start as Component,
@@ -24,8 +24,8 @@ if (!["light", "dark"].includes(localStorage.getItem("theme"))) {
}
class LibraryState {
- libraries = $state
([])
- installed = $state<[string, string][]>([])
+ libraries = $state([]);
+ installed = $state<[string, string][]>([]);
async query() {
const res = await fetch(
@@ -57,17 +57,17 @@ class LibraryState {
}
class AppState {
- Screen = $state(Screen.START)
- theme = $state(localStorage.getItem("theme") as Theme)
- libraries = new LibraryState()
+ Screen = $state(Screen.START);
+ theme = $state(localStorage.getItem("theme") as Theme);
+ libraries = new LibraryState();
constructor() {
$effect.root(() => {
$effect(() => {
document.body.setAttribute("data-color-scheme", this.theme);
localStorage.setItem("theme", this.theme);
- })
- })
+ });
+ });
}
}
diff --git a/src/lib/state/blockly.svelte.ts b/src/lib/state/blockly.svelte.ts
index 60d7cf2..66e7d28 100644
--- a/src/lib/state/blockly.svelte.ts
+++ b/src/lib/state/blockly.svelte.ts
@@ -1,22 +1,22 @@
-import type {WorkspaceSvg} from "blockly";
+import type { WorkspaceSvg } from "blockly";
class BlocklyState {
- workspace = $state()
+ workspace = $state();
- restore = $state>()
- willRestore = $state(true)
+ restore = $state>();
+ willRestore = $state(true);
- audio = $state(JSON.parse(localStorage.getItem("audio")) || true)
+ audio = $state(JSON.parse(localStorage.getItem("audio")) || true);
- canUndo = $state(false)
- canRedo = $state(false)
+ canUndo = $state(false);
+ canRedo = $state(false);
constructor() {
$effect.root(() => {
$effect(() => {
localStorage.setItem("audio", JSON.stringify(this.audio));
- })
- })
+ });
+ });
}
}
diff --git a/src/lib/state/popup.svelte.ts b/src/lib/state/popup.svelte.ts
index 8328d9b..f85f4b6 100644
--- a/src/lib/state/popup.svelte.ts
+++ b/src/lib/state/popup.svelte.ts
@@ -14,72 +14,68 @@ interface Popup {
allowInteraction: boolean;
position?: { x: number; y: number };
- anchor?: Anchor
+ anchor?: Anchor;
}
export class PopupState {
- id = $state()
+ id = $state();
- component = $state()
- data = $state>()
- allowInteraction = $state()
+ component = $state();
+ data = $state>();
+ allowInteraction = $state();
- position = $state({ x: 0, y: 0 })
- onclose: () => void = undefined
- anchor = $state(Anchor.Center)
+ position = $state({ x: 0, y: 0 });
+ onclose: () => void = undefined;
+ anchor = $state(Anchor.Center);
constructor(
id: number,
props: Popup,
- public close: (value?: any) => void
+ public close: (value?: any) => void,
) {
- this.id = id
+ this.id = id;
- this.component = props.component
- this.data = props.data
- this.allowInteraction = props.allowInteraction
+ this.component = props.component;
+ this.data = props.data;
+ this.allowInteraction = props.allowInteraction;
- if (props.position) this.position = props.position
- if (props.anchor) this.anchor = props.anchor
+ if (props.position) this.position = props.position;
+ if (props.anchor) this.anchor = props.anchor;
}
}
class PopupsState {
- popups = $state([])
- count = 0
+ popups = $state([]);
+ count = 0;
getID() {
- this.count++
- if (this.count > 1000) this.count = 0
+ this.count++;
+ if (this.count > 1000) this.count = 0;
- return this.count
+ return this.count;
}
open(props: Popup) {
- return new Promise(resolve => {
- if (this.popups.find(popup => popup.component === props.component)) {
- resolve(undefined)
+ return new Promise((resolve) => {
+ if (this.popups.find((popup) => popup.component === props.component)) {
+ resolve(undefined);
}
- const id = this.getID()
- this.popups.push(new PopupState(
- id,
- props,
- (value: any) => {
- this.popups = this.popups.filter(popup => popup.id !== id)
- resolve(value)
- }
- ))
- })
+ const id = this.getID();
+ this.popups.push(
+ new PopupState(id, props, (value: any) => {
+ this.popups = this.popups.filter((popup) => popup.id !== id);
+ resolve(value);
+ }),
+ );
+ });
}
async setup() {
if (!localStorage.getItem("language")) {
await this.open({
component: LanguageSelector,
- data: {
-
- },
+ data: {},
allowInteraction: false,
});
}
@@ -106,8 +102,8 @@ class PopupsState {
}
clear() {
- this.popups = []
+ this.popups = [];
}
}
-export default new PopupsState()
+export default new PopupsState();
diff --git a/src/lib/state/serial.svelte.ts b/src/lib/state/serial.svelte.ts
index 6fbdf91..567a708 100644
--- a/src/lib/state/serial.svelte.ts
+++ b/src/lib/state/serial.svelte.ts
@@ -1,9 +1,9 @@
-import {type RobotDevice, robots} from "$domain/robots";
-import {track} from "$state/utils";
import ErrorPopup from "$components/core/popups/popups/Error.svelte";
-import MockedFTDISerialPort from "@leaphy-robotics/webusb-ftdi";
-import {SerialPort as MockedCDCSerialPort} from "web-serial-polyfill";
+import { type RobotDevice, robots } from "$domain/robots";
import PopupState from "$state/popup.svelte";
+import { track } from "$state/utils";
+import MockedFTDISerialPort from "@leaphy-robotics/webusb-ftdi";
+import { SerialPort as MockedCDCSerialPort } from "web-serial-polyfill";
export type LeaphyPort =
| SerialPort
@@ -26,13 +26,12 @@ export class ConnectionFailedError {}
export const SUPPORTED_VENDOR_IDS = [0x1a86, 9025, 2341, 0x0403, 0x2e8a];
-
class LogState {
- log = $state([])
- charts = $state>({})
+ log = $state([]);
+ charts = $state>({});
- private buffer = ''
- private count = 0
+ private buffer = "";
+ private count = 0;
constructor(private serial: SerialState) {}
@@ -41,13 +40,13 @@ class LogState {
}
clear() {
- this.charts = {}
- this.log = []
+ this.charts = {};
+ this.log = [];
}
getID() {
- if (this.count > 100) this.count = 0
- return `${this.count++}`
+ if (this.count > 100) this.count = 0;
+ return `${this.count++}`;
}
enqueue(content: Uint8Array) {
@@ -56,8 +55,7 @@ class LogState {
const items = this.buffer.split("\n");
for (const item of items) {
const [label, value] = item.split(" = ");
- if (!label || !value || Number.isNaN(Number.parseFloat(value)))
- continue;
+ if (!label || !value || Number.isNaN(Number.parseFloat(value))) continue;
this.point(label, Number.parseFloat(value));
}
@@ -71,7 +69,7 @@ class LogState {
date: new Date(),
content,
})),
- ].slice(-100)
+ ].slice(-100);
}
}
@@ -85,30 +83,32 @@ class LogState {
}
class SerialState {
- port = $state()
- board = $state()
- ready = $state(new Promise((resolve, reject) => {
- this.onReady = resolve
- this.onFailure = reject
- }))
+ port = $state();
+ board = $state();
+ ready = $state(
+ new Promise((resolve, reject) => {
+ this.onReady = resolve;
+ this.onFailure = reject;
+ }),
+ );
- reserved = $state(false)
- reader: ReadableStreamDefaultReader
- writer: WritableStreamDefaultWriter
+ reserved = $state(false);
+ reader: ReadableStreamDefaultReader;
+ writer: WritableStreamDefaultWriter;
- onReady: () => void
- onFailure: () => void
- showFeedback = false
+ onReady: () => void;
+ onFailure: () => void;
+ showFeedback = false;
- log = new LogState(this)
+ log = new LogState(this);
constructor() {
$effect.root(() => {
$effect(() => {
- track(this.port)
- this.initPort().then()
- })
- })
+ track(this.port);
+ this.initPort().then();
+ });
+ });
}
async initPort() {
@@ -289,4 +289,4 @@ class SerialState {
}
}
-export default new SerialState()
+export default new SerialState();
diff --git a/src/lib/state/upload.svelte.ts b/src/lib/state/upload.svelte.ts
index 757ee69..f816c9d 100644
--- a/src/lib/state/upload.svelte.ts
+++ b/src/lib/state/upload.svelte.ts
@@ -1,5 +1,5 @@
class USBRequestState {
- respond = $state void)>(null)
+ respond = $state void)>(null);
async request() {
const [device] = await navigator.usb.getDevices();
@@ -7,9 +7,9 @@ class USBRequestState {
return new Promise((resolve) => {
this.respond = (device: USBDevice) => {
- resolve(device)
- this.respond = null
- }
+ resolve(device);
+ this.respond = null;
+ };
});
}
}
diff --git a/src/lib/state/utils.ts b/src/lib/state/utils.ts
index b3cde7e..508213c 100644
--- a/src/lib/state/utils.ts
+++ b/src/lib/state/utils.ts
@@ -1,3 +1,4 @@
export function track(state: any) {
- if (state) {}
+ if (state) {
+ }
}
diff --git a/src/lib/state/workspace.svelte.ts b/src/lib/state/workspace.svelte.ts
index b71e192..c9d95e6 100644
--- a/src/lib/state/workspace.svelte.ts
+++ b/src/lib/state/workspace.svelte.ts
@@ -2,14 +2,14 @@ import Advanced from "$components/workspace/advanced/Advanced.svelte";
import Blocks from "$components/workspace/blocks/Blocks.svelte";
import Python from "$components/workspace/python/Python.svelte";
import type { Handle } from "$domain/handles";
-import { type RobotDevice } from "$domain/robots";
+import type { RobotDevice } from "$domain/robots";
+import { track } from "$state/utils";
import { serialization } from "blockly";
import type { Component } from "svelte";
import type MicroPythonIO from "../micropython";
import type { IOEventTarget } from "../micropython";
import BlocklyState from "./blockly.svelte";
import PopupState from "./popup.svelte";
-import {track} from "$state/utils";
export const Mode = {
BLOCKS: Blocks as Component,
@@ -18,38 +18,38 @@ export const Mode = {
};
class WorkspaceState {
- uploadLog = $state([])
- handle = $state()
- robot = $state()
- microPythonIO = $state()
- microPythonRun = $state()
+ uploadLog = $state([]);
+ handle = $state();
+ robot = $state();
+ microPythonIO = $state();
+ microPythonRun = $state();
- code = $state('')
- saveState = $state(true)
+ code = $state("");
+ saveState = $state(true);
- SidePanel = $state()
- Mode = $state(Mode.BLOCKS)
+ SidePanel = $state();
+ Mode = $state(Mode.BLOCKS);
constructor() {
window.addEventListener("beforeunload", this.tempSave.bind(this));
$effect.root(() => {
$effect(() => {
- track(this.Mode)
+ track(this.Mode);
- PopupState.clear()
- this.SidePanel = undefined
- })
+ PopupState.clear();
+ this.SidePanel = undefined;
+ });
$effect(() => {
- track(this.code)
+ track(this.code);
- this.saveState = false
- })
- })
+ this.saveState = false;
+ });
+ });
}
toggleSidePanel(panel: Component) {
- this.SidePanel = this.SidePanel === panel ? undefined : panel
+ this.SidePanel = this.SidePanel === panel ? undefined : panel;
}
tempSave() {
@@ -88,4 +88,4 @@ class WorkspaceState {
}
}
-export default new WorkspaceState()
+export default new WorkspaceState();