Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: svelte v5 (without components migration) #548

Draft
wants to merge 36 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
3ab0034
build: svelte v5 (without components migration)
peterpeterparker Dec 10, 2024
0405477
Updating formatting
github-actions[bot] Dec 10, 2024
87896d2
test: adapt for svelte v5 and bump testing library
peterpeterparker Dec 10, 2024
6d22e36
Merge remote-tracking branch 'origin/build/svelte-v5-libs' into build…
peterpeterparker Dec 10, 2024
0e492dd
test: mock resize observer and element.animate
peterpeterparker Dec 10, 2024
7bc3ef1
test: adapt for svelte v5
peterpeterparker Dec 10, 2024
1e16823
build: peer v5
peterpeterparker Dec 10, 2024
04902bc
test: rename to use rune
peterpeterparker Dec 10, 2024
537b43e
Updating formatting
github-actions[bot] Dec 10, 2024
3472bc6
chore: no dev
peterpeterparker Dec 10, 2024
8bf4cc1
chore: no dev
peterpeterparker Dec 10, 2024
b530bfe
Merge branch 'main' into build/svelte-v5-libs
peterpeterparker Dec 11, 2024
964cd27
fix: pass props
peterpeterparker Dec 11, 2024
2a1ecf4
test: adapt $on
peterpeterparker Dec 11, 2024
4b93e3d
test: adapt to svelte v5
peterpeterparker Dec 11, 2024
390eb61
chore: remove inspect
peterpeterparker Dec 11, 2024
4d6f14b
chore: lint
peterpeterparker Dec 11, 2024
638466d
🤖 update snapshots
github-actions[bot] Dec 11, 2024
7632aa6
fix: npm audit
peterpeterparker Dec 12, 2024
a39bf01
feat: ComponentType to Component
peterpeterparker Dec 17, 2024
f87b8d8
docs: add callback keyword in comment
peterpeterparker Dec 17, 2024
e1d437b
chore: merge main
peterpeterparker Dec 17, 2024
b3dd629
test: adapt for svelte v5
peterpeterparker Dec 17, 2024
63ba4a7
Merge branch 'main' into build/svelte-v5-libs
peterpeterparker Jan 27, 2025
6377f13
build: bump latest
peterpeterparker Jan 27, 2025
6753fe1
chore: merge main
peterpeterparker Jan 27, 2025
68d694d
chore: bump playwright as on main
peterpeterparker Jan 27, 2025
43b9076
Merge branch 'main' into build/svelte-v5-libs
peterpeterparker Jan 27, 2025
1067d0e
🤖 update snapshots
github-actions[bot] Jan 27, 2025
1d7e0e7
chore: merge main
peterpeterparker Feb 4, 2025
e44b9e3
Merge branch 'main' into build/svelte-v5-libs
peterpeterparker Feb 4, 2025
a68a25d
Merge branch 'main' into build/svelte-v5-libs
peterpeterparker Feb 4, 2025
7b2db90
chore: no dev
peterpeterparker Feb 10, 2025
40e5ac7
chore: merge main
peterpeterparker Feb 10, 2025
91ddc5c
Merge branch 'main' into build/svelte-v5-libs
peterpeterparker Feb 12, 2025
1517362
Merge branch 'main' into build/svelte-v5-libs
peterpeterparker Feb 12, 2025
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3,315 changes: 1,220 additions & 2,095 deletions package-lock.json

Large diffs are not rendered by default.

27 changes: 14 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"build": "npm run i18n && vite build",
"staging": "npm run i18n && vite build --mode staging",
"package": "svelte-kit sync && svelte-package",
"prepare": "svelte-kit sync",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
Expand Down Expand Up @@ -42,19 +43,19 @@
"devDependencies": {
"@junobuild/config": "^0.0.14",
"@playwright/test": "^1.50.0",
"@sveltejs/adapter-static": "^3.0.5",
"@sveltejs/kit": "^2.5.28",
"@sveltejs/package": "^2.3.5",
"@sveltejs/vite-plugin-svelte": "^3.1.2",
"@testing-library/jest-dom": "^6.5.0",
"@testing-library/svelte": "^5.2.1",
"@sveltejs/adapter-static": "^3.0.8",
"@sveltejs/kit": "^2.16.1",
"@sveltejs/package": "^2.3.9",
"@sveltejs/vite-plugin-svelte": "^5.0.3",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/svelte": "^5.2.6",
"@types/dompurify": "^3.0.5",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"autoprefixer": "^10.4.20",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-svelte": "^2.35.1",
"eslint-plugin-svelte": "^2.46.1",
"jest-environment-jsdom": "^29.7.0",
"mdsvex": "^0.12.3",
"node-fetch": "^3.3.2",
Expand All @@ -63,13 +64,13 @@
"prettier-plugin-organize-imports": "^4.0.0",
"prettier-plugin-svelte": "^3.2.6",
"sass": "^1.79.1",
"svelte-check": "^4.0.2",
"svelte-preprocess": "^6.0.2",
"svelte2tsx": "^0.7.19",
"svelte-check": "^4.1.4",
"svelte-preprocess": "^6.0.3",
"svelte2tsx": "^0.7.34",
"typescript": "^5.3.3",
"user-agent-data-types": "^0.4.2",
"vite": "^5.4.6",
"vitest": "^2.1.9"
"vite": "^6.0.11",
"vitest": "^3.0.4"
},
"dependencies": {
"dompurify": "^3.1.6",
Expand All @@ -87,7 +88,7 @@
],
"peerDependencies": {
"@dfinity/utils": "*",
"svelte": "^4.2.1"
"svelte": "^5"
},
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/Card.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import IconCheckCircle from "$lib/icons/IconCheckCircle.svelte";
import { nonNullish } from "@dfinity/utils";
import { createEventDispatcher } from "svelte";
import type { ComponentType } from "svelte";
import type { Component } from "svelte";

export let role: "button" | "checkbox" | undefined = undefined;
export let ariaLabel: string | undefined = undefined;
Expand Down Expand Up @@ -39,7 +39,7 @@
dispatch("click", $event?.detail);
};

let iconCmp: ComponentType | undefined = undefined;
let iconCmp: Component | undefined = undefined;

$: (() => {
switch (icon) {
Expand Down
3 changes: 1 addition & 2 deletions src/lib/components/Layout.svelte
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<script lang="ts">
import SplitPane from "$lib/components/SplitPane.svelte";
import Menu from "$lib/components/Menu.svelte";
import type { ComponentType } from "svelte";
import StretchPane from "$lib/components/StretchPane.svelte";
import LogoNNS from "$lib/components/LogoNNS.svelte";
import LogoOnChain from "$lib/components/LogoOnChain.svelte";

export let layout: "split" | "stretch" = "split";

let component: ComponentType;
let component: typeof StretchPane | typeof SplitPane;
$: component = layout === "stretch" ? StretchPane : SplitPane;
</script>

Expand Down
6 changes: 3 additions & 3 deletions src/lib/components/Toast.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
ToastPosition,
ToastTheme,
} from "$lib/types/toast";
import { onDestroy, onMount, type ComponentType } from "svelte";
import { onDestroy, onMount, type Component } from "svelte";
import Spinner from "./Spinner.svelte";
import IconWarning from "$lib/icons/IconWarning.svelte";
import IconClose from "$lib/icons/IconClose.svelte";
Expand All @@ -21,7 +21,7 @@

export let msg: ToastMsg;

const iconMapper = (level: ToastLevel): ComponentType | undefined =>
const iconMapper = (level: ToastLevel): Component | undefined =>
({
["success"]: IconCheckCircle,
["warn"]: IconWarning,
Expand All @@ -38,7 +38,7 @@
let title: string | undefined;
let overflow: "scroll" | "truncate" | "clamp" | undefined;
let position: ToastPosition | undefined;
let icon: ComponentType | undefined;
let icon: Component | undefined;
let theme: ToastTheme | undefined;
let renderAsHtml: boolean | undefined;

Expand Down
4 changes: 2 additions & 2 deletions src/lib/types/toast.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ComponentType } from "svelte";
import type { Component } from "svelte";

export type ToastLevel = "success" | "warn" | "error" | "info" | "custom";

Expand All @@ -15,7 +15,7 @@ export interface ToastMsg {
duration?: number;
position?: ToastPosition;
overflow?: "scroll" | "truncate" | "clamp";
icon?: ComponentType;
icon?: Component;
theme?: ToastTheme;
renderAsHtml?: boolean;
}
4 changes: 2 additions & 2 deletions src/routes/(split)/components/qr-code-generator/+page.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<script lang="ts">
import { browser } from "$app/environment";
import type { ComponentType } from "svelte";
import type { Component } from "svelte";
import { onMount } from "svelte";
import icpRounded from "$docs/assets/icp-rounded.svg";

let QRCode: ComponentType | undefined = undefined;
let QRCode: Component | undefined = undefined;

onMount(async () => {
if (!browser) {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/(split)/components/toasts/+page.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ A toast message can be created with following properties.
| `duration` | A timeout (in milliseconds) after which the toast automatically disappear. | `number` | |
| `position` | The position of the toast. A related `<Toasts />` component should be declared in order to use the position. | `bottom` or `top` | |
| `overflow` | By default, a text content of a toast is scrollbable. This option truncate or clamp the text and title. | `scroll` or `truncate` or `clamp` | |
| `icon` | A custom icon to be displayed before the text of the toast. | `ComponentType` | |
| `icon` | A custom icon to be displayed before the text of the toast. | `Component` | |
| `renderAsHtml` | Whether the `text` should be rendered as HTML. | `boolean` | |

## Showcase
Expand Down
4 changes: 2 additions & 2 deletions src/tests/lib/components/ComponentTest.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import type { ComponentType } from "svelte";
import type { Component } from "svelte";

export let cmp: ComponentType;
export let cmp: Component;
export let testId: string;
</script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,53 +321,51 @@ describe("Input", () => {
testGetAttribute({ container, attribute: "type", expected: "text" });
});

it("should bind value", () =>
new Promise<void>((done) => {
const { container, component } = render(InputValueTest, {
props: {
...props,
inputType: "icp",
},
});
it("should bind value", () => {
const testProps = $state({
...props,
inputType: "icp" as const,
amount: undefined,
});

const input: HTMLInputElement | null = container.querySelector("input");
const { container } = render(InputValueTest, {
props: testProps,
});

const input: HTMLInputElement | null = container.querySelector("input");

if (isNullish(input)) {
throw new Error("No input");
}
if (isNullish(input)) {
throw new Error("No input");
}

fireEvent.input(input, { target: { value: "100" } });
expect(input.value).toBe("100");
fireEvent.input(input, { target: { value: "100" } });
expect(input.value).toBe("100");

component.$on("testAmount", ({ detail }) => {
expect(detail.amount).toBe(100);
done();
});
}));

it("should bind value as string", () =>
new Promise<void>((done) => {
const { container, component } = render(InputValueTest, {
props: {
...props,
inputType: "currency",
decimals: 18,
},
});
expect(testProps.amount).toBe(100);
});

const input: HTMLInputElement | null = container.querySelector("input");
assertNonNullish(input);
it("should bind value as string", () => {
const ethValue = "0.000000094829004242";

const ethValue = "0.000000094829004242";
const testProps = $state({
...props,
inputType: "currency" as const,
decimals: 18,
amount: undefined,
});

fireEvent.input(input, { target: { value: ethValue } });
expect(input.value).toBe(ethValue);
const { container } = render(InputValueTest, {
props: testProps,
});

component.$on("testAmount", ({ detail }) => {
expect(detail.amount).toBe(ethValue);
done();
});
}));
const input: HTMLInputElement | null = container.querySelector("input");
assertNonNullish(input);

fireEvent.input(input, { target: { value: ethValue } });
expect(input.value).toBe(ethValue);

expect(testProps.amount).toBe(ethValue);
});

it("should not accept not icp formatted changed", async () => {
const { container } = render(Input, {
Expand Down Expand Up @@ -400,30 +398,29 @@ describe("Input", () => {
expect(input.value).toBe(".0000001");
});

it('should replace "" with undefined', () =>
new Promise<void>((done) => {
const { container, component } = render(InputValueTest, {
props: {
...props,
value: "0",
inputType: "icp",
},
});
it('should replace "" with undefined', () => {
const testProps = $state({
...props,
value: "0",
inputType: "icp" as const,
amount: undefined,
});

const input: HTMLInputElement | null = container.querySelector("input");
const { container } = render(InputValueTest, {
props: testProps,
});

if (isNullish(input)) {
throw new Error("No input");
}
const input: HTMLInputElement | null = container.querySelector("input");

fireEvent.input(input, { target: { value: "" } });
expect(input.value).toBe("");
if (isNullish(input)) {
throw new Error("No input");
}

component.$on("testAmount", ({ detail }) => {
expect(detail.amount).toBe(undefined);
done();
});
}));
fireEvent.input(input, { target: { value: "" } });
expect(input.value).toBe("");

expect(testProps.amount).toBe(undefined);
});

it("should avoid exponent formatted initial zero in icp mode", () => {
const { container } = render(InputValueTest, {
Expand All @@ -449,12 +446,14 @@ describe("Input", () => {
});

it("should avoid exponent formatted on change in icp mode", async () => {
const { container, component } = render(Input, {
props: {
...props,
value: "",
inputType: "icp",
},
const testProps = $state({
...props,
value: "",
inputType: "icp" as const,
});

const { container } = render(Input, {
props: testProps,
});

const input: HTMLInputElement | null = container.querySelector("input");
Expand All @@ -463,7 +462,7 @@ describe("Input", () => {
throw new Error("No input");
}

component.$set({ value: 0.00000001 });
testProps.value = "0.00000001";

// svelte does not update the dom immediately
expect(input.value).toBe("");
Expand Down Expand Up @@ -518,29 +517,27 @@ describe("Input", () => {
expect(input.value).toBe("0.000000011231232121");
});

it("should not round custom decimals with JS imprecision", () =>
new Promise<void>((done) => {
const { container, component } = render(InputValueTest, {
props: {
...props,
value: "0.12",
inputType: "currency",
decimals: 18,
},
});
it("should not round custom decimals with JS imprecision", () => {
const testProps = $state({
...props,
value: "0.12",
inputType: "currency" as const,
decimals: 18,
amount: undefined,
});

const input: HTMLInputElement | null = container.querySelector("input");
assertNonNullish(input);
const { container } = render(InputValueTest, {
props: testProps,
});

fireEvent.input(input, { target: { value: "0.122" } });
const input: HTMLInputElement | null = container.querySelector("input");
assertNonNullish(input);

component.$on("testAmount", ({ detail }) => {
// Example if the input would be rounded with Number(value).toFixed(18)
expect(detail.amount).not.toBe("0.121999999999999997");
expect(detail.amount).toBe("0.122");
done();
});
}));
fireEvent.input(input, { target: { value: "0.122" } });

expect(testProps.amount).not.toBe("0.121999999999999997");
expect(testProps.amount).toBe("0.122");
});
});

it("should bind input element", async () => {
Expand Down
Loading
Loading