From fb1cecfebf02164593ceaca3267e5fc3e0ddaf99 Mon Sep 17 00:00:00 2001 From: abdel Date: Fri, 24 Oct 2025 02:12:20 +0800 Subject: [PATCH 1/5] chore: cleanup old code --- src/lib/components/alert/alert-root.svelte | 2 +- src/lib/components/combobox/combobox-trigger.svelte | 5 +---- src/lib/components/datagrid/datagrid-body.svelte | 1 - src/lib/components/dialog/dialog-description.svelte | 8 ++------ src/lib/components/drawer/drawer-root.svelte | 12 +++++------- src/lib/components/portal/portal-root.svelte | 10 ++++------ .../components/scrollable/scrollable-content.svelte | 1 - src/lib/components/scrollable/scrollable-root.svelte | 6 ------ src/lib/components/tree/tree-root.svelte | 5 ----- 9 files changed, 13 insertions(+), 37 deletions(-) diff --git a/src/lib/components/alert/alert-root.svelte b/src/lib/components/alert/alert-root.svelte index 88add26..140e402 100644 --- a/src/lib/components/alert/alert-root.svelte +++ b/src/lib/components/alert/alert-root.svelte @@ -17,7 +17,7 @@ Date: Fri, 24 Oct 2025 02:16:04 +0800 Subject: [PATCH 2/5] fix: update ClassValueFunction type definition and refine cn function input type --- src/lib/utils/index.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/lib/utils/index.ts b/src/lib/utils/index.ts index eee03b7..e2b05a2 100644 --- a/src/lib/utils/index.ts +++ b/src/lib/utils/index.ts @@ -4,10 +4,11 @@ import type { ClassValue as SvelteClassValue } from 'svelte/elements'; import clsx from 'clsx'; import { twMerge } from 'tailwind-merge'; -export type ClassValueFunction = (this: T, ...args: unknown[]) => SvelteClassValue; +export type ClassValueFunction = (bond: T, ...args: unknown[]) => SvelteClassValue; export type ClassValue = SvelteClassValue | ClassValueFunction | undefined; -export function cn(...inputs: SvelteClassValue[]) { +export type Cn = SvelteClassValue | undefined | false; +export function cn(...inputs: Cn[]) { return twMerge(clsx(...inputs)); } From 6f2f4f56c0629ec1a5186495c0278b1a48b8fd84 Mon Sep 17 00:00:00 2001 From: abdel Date: Fri, 24 Oct 2025 02:24:40 +0800 Subject: [PATCH 3/5] fix: update PresetEntry types, preset entry value will be a function --- src/lib/components/atom/html-atom.svelte | 8 +-- src/lib/components/input/input-value.svelte | 4 +- src/lib/context/index.ts | 1 + src/lib/context/preset.svelte.ts | 17 ++++-- src/stories/Theme.svelte | 60 +++++++++++---------- 5 files changed, 53 insertions(+), 37 deletions(-) diff --git a/src/lib/components/atom/html-atom.svelte b/src/lib/components/atom/html-atom.svelte index cbf94b1..b958d72 100644 --- a/src/lib/components/atom/html-atom.svelte +++ b/src/lib/components/atom/html-atom.svelte @@ -21,7 +21,9 @@ ...restProps }: HtmlAtomProps & HTMLAttributes = $props(); - const preset = $derived(presetKey ? getPreset(presetKey as PresetModuleName) : undefined); + const preset = $derived( + presetKey ? getPreset(presetKey as PresetModuleName)?.apply(bond, [bond]) : undefined + ); const _klass = $derived.by(() => { const klasses = Array.isArray(klass) ? klass : [klass]; @@ -33,14 +35,14 @@ if (hasPresetPlaceholder) { return klasses.map((cls) => { if (typeof cls === 'string' && cls.includes('$preset')) { - return cls.replace('$preset', cn(toClassValue.apply(bond, [preset?.class]))); + return cls.replace('$preset', cn(preset?.class)); } return toClassValue.apply(bond, [cls]); }); } - return [preset?.class ?? '', '$preset', klass].map((arg) => toClassValue.apply(bond, [arg])); + return [preset?.class ?? '', toClassValue.apply(bond, [klass])]; }); const _base = $derived(base ?? preset?.base); diff --git a/src/lib/components/input/input-value.svelte b/src/lib/components/input/input-value.svelte index 63b3657..21bdb46 100644 --- a/src/lib/components/input/input-value.svelte +++ b/src/lib/components/input/input-value.svelte @@ -39,7 +39,7 @@ ...restProps }: InputProps = $props(); - const preset = getPreset(presetKey as PresetModuleName); + const preset = getPreset(presetKey as PresetModuleName)?.apply(bond, [bond]); const valueProps = $derived({ ...(bond?.input?.() ?? {}), @@ -96,7 +96,7 @@ } class={[ 'h-full w-full flex-1 bg-transparent px-2 leading-1 outline-none', - toClassValue(bond, preset?.class), + preset?.class, toClassValue(bond, klass) ]} onchange={handleChange} diff --git a/src/lib/context/index.ts b/src/lib/context/index.ts index 1a21314..479b56b 100644 --- a/src/lib/context/index.ts +++ b/src/lib/context/index.ts @@ -1,6 +1,7 @@ export { type PresetModuleName as ModuleName, type Preset, + type PresetEntryRecord, type PresetEntry, getPreset, setPreset diff --git a/src/lib/context/preset.svelte.ts b/src/lib/context/preset.svelte.ts index 4b6d5cf..ac24f8a 100644 --- a/src/lib/context/preset.svelte.ts +++ b/src/lib/context/preset.svelte.ts @@ -1,7 +1,10 @@ import { getContext, setContext } from 'svelte'; +import type { ClassValue } from 'svelte/elements'; import { merge } from 'es-toolkit'; -import type { ClassValue } from '$svelte-atoms/core/utils'; import type { Base } from '$svelte-atoms/core/components/atom'; +import type { Bond } from '../shared'; + +const CONTEXT_KEY = '@svelte-atoms/context/preset'; export type PresetModuleName = | 'accordion' @@ -121,14 +124,20 @@ export type PresetModuleName = | 'radio.group' | 'container'; -export type PresetEntry = { +export type PresetEntryRecord = { + [key: string]: unknown; class?: ClassValue; as?: string; base?: Base; }; -export type Preset = Record; -const CONTEXT_KEY = '@svelte-atoms/context/preset'; +export type PresetEntry = ( + this: Bond | undefined | null, + bond: Bond | undefined | null, + ...args: any[] +) => PresetEntryRecord; + +export type Preset = Record; export function getPreset(key: K): PresetEntry | undefined; export function getPreset(): Partial | undefined; diff --git a/src/stories/Theme.svelte b/src/stories/Theme.svelte index 537ce8d..40b01f0 100644 --- a/src/stories/Theme.svelte +++ b/src/stories/Theme.svelte @@ -1,5 +1,5 @@ From f4b5b8fcbe2bf5af1c4136f0a0043a1f65c2888b Mon Sep 17 00:00:00 2001 From: abdel Date: Fri, 24 Oct 2025 02:30:23 +0800 Subject: [PATCH 4/5] fix: reformat file --- src/lib/components/container/container.stories.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/components/container/container.stories.svelte b/src/lib/components/container/container.stories.svelte index fca2f19..9d5a5b8 100644 --- a/src/lib/components/container/container.stories.svelte +++ b/src/lib/components/container/container.stories.svelte @@ -10,7 +10,7 @@ - +
{#each { length: 5 } as _, i (i)}
From 25f659944f75ad814ba1ec2f5a91e07190b7c203 Mon Sep 17 00:00:00 2001 From: abdel Date: Fri, 24 Oct 2025 03:07:07 +0800 Subject: [PATCH 5/5] bump version to 1.0.0-alpha.19 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index fc7a8a1..a5b4111 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@svelte-atoms/core", - "version": "1.0.0-alpha.18", + "version": "1.0.0-alpha.19", "description": "A modular, accessible, and extensible Svelte UI component library.", "repository": { "type": "git",