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

feat: upgrade to svelte 5 #163

Merged
merged 4 commits into from
Oct 22, 2024
Merged
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
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,20 @@
},
"devDependencies": {
"@ignatiusmb/styles": "^0.1.1",
"@sveltejs/adapter-vercel": "^5.4.1",
"@sveltejs/kit": "^2.5.18",
"@sveltejs/package": "^2.3.2",
"@sveltejs/vite-plugin-svelte": "^3.1.1",
"@sveltejs/adapter-vercel": "^5.4.5",
"@sveltejs/kit": "^2.7.2",
"@sveltejs/package": "^2.3.5",
"@sveltejs/vite-plugin-svelte": "^4.0.0",
"@types/feather-icons": "^4.29.4",
"aubade": "^0.9.0",
"feather-icons": "^4.29.2",
"prettier": "^3.3.2",
"prettier": "^3.3.3",
"prettier-plugin-sort-package-json": "^0.2.0",
"prettier-plugin-svelte": "^3.2.5",
"svelte": "5.0.0-next.153",
"svelte-check": "^3.8.4",
"svelte2tsx": "^0.7.13",
"typescript": "^5.5.3",
"vite": "^5.3.3"
"prettier-plugin-svelte": "^3.2.7",
"svelte": "^5.0.3",
"svelte-check": "^4.0.5",
"svelte2tsx": "^0.7.22",
"typescript": "^5.6.3",
"vite": "^5.4.9"
}
}
1,061 changes: 557 additions & 504 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/lib/core/Dialog.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@
const elements = FOCUSABLE.join(', ');
async function forward<T extends Event>(event: T) {
if (onclose && !onclose(event.type as 'keydown' | 'pointerdown')) return;
show = !!void setTimeout(() => {
void setTimeout(() => {
document.body.style.removeProperty('padding-right');
document.body.style.removeProperty('overflow');
}, TIME.FLY);
show = false;
}

function sieve(elements: NodeListOf<Element>) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/core/Periodical.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<script context="module">
<script module>
const time = $state({ start: Date.now() });
const reset = () => (time.start = Date.now());
</script>
Expand Down
4 changes: 2 additions & 2 deletions src/lib/core/SearchBar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
placeholder?: string;

icons?: {
search: import('svelte').ComponentProps<Feather>['icon'];
filter: import('svelte').ComponentProps<Feather>['icon'];
search: import('svelte').ComponentProps<typeof Feather>['icon'];
filter: import('svelte').ComponentProps<typeof Feather>['icon'];
};

sieve(utils: {
Expand Down
11 changes: 5 additions & 6 deletions src/lib/core/dialog.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
import type { ComponentProps, ComponentType, SvelteComponent } from 'svelte';
import type { Component, ComponentProps } from 'svelte';
import type { Demand, LazyComponent, SyvOptions } from '../types.js';
import { mount as create, unmount } from 'svelte';

let instance: ReturnType<typeof create>;

// ---- exposed ----

export function mount<T extends SvelteComponent>(
component: ComponentType<T>, // TODO: figure out with the new `Component` type
export function mount<T extends Component<any, any>>(
component: T,
...[demanded]: Demand<SyvOptions & ComponentProps<T>>
) {
instance && unmount(instance); // destroy here so it keeps the out transition

const internal = Object.assign({ 'syv:intro': true }, demanded);
if (demanded) delete demanded['syv:intro'], delete demanded['syv:anchor'];
// @ts-expect-error - not sure what's going on here
instance = create(component, {
intro: internal['syv:intro'],
target: internal['syv:anchor'] || document.body,
props: demanded, // pass the object as-is to preserve reactivity
});
}

export function load<T extends SvelteComponent>(
export function load<T extends Component<any, any>>(
loader: LazyComponent<T> | ReturnType<LazyComponent<T>>,
...[options]: Demand<SyvOptions & ComponentProps<T>>
) {
const loaded = typeof loader !== 'function' ? loader : loader();
// @ts-expect-error - only passing `options` to `mount`
loaded.then(({ default: Component }) => mount(Component, options));
loaded.then(({ default: Comp }) => mount(Comp, options));
}
10 changes: 3 additions & 7 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import type { Flexible } from 'mauss/typings';
import type { SvelteComponent } from 'svelte';

export interface AnyComponent<T extends SvelteComponent = SvelteComponent> {
new (...args: any): T;
}
import type { Component } from 'svelte';

export type Demand<T> = {
[K in keyof T]-?: {} extends { [P in K]: T[K] } ? never : K;
}[keyof T] extends [never]
? [T?]
: [T];

export interface LazyComponent<T extends SvelteComponent> {
(): Promise<{ default: AnyComponent<T> }>;
export interface LazyComponent<T extends Component<any, any>> {
(): Promise<{ default: T }>;
}

// ---- Syv ----
Expand Down