The soma `id` module conflated two concerns: `createId` (wraps Svelte
`$props.id()` for SSR/ARIA element ids — ~200 soma importers, intrinsic to
the headless layer) and `useId` (a generic monotonic counter — 6 importers).
Only the counter is a cross-layer utility.
Move `useId` to a new `$active-uix/id` subpath (mirroring the existing
`$active-uix/prefs` that soma already imports), so any UIX layer — soma,
eidos, demos, apps — can mint client-only ids from a cheap, collision-free
counter without coupling to soma. `createId` stays in soma (its domain).
+ src/uix/active-uix/id/index.ts (useId)
~ soma/id now exports createId only
~ 6 useId importers repointed to $active-uix/id
(floating, toaster, date-field, time-field, accordion-item, internal/arrow)
Output format unchanged (`soma-{component}-{n}`) -> zero behavior change.
`npm run check` 0 errors; toast/accordion/popover verified in browser.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
active-uix
parent
f8056f438b
commit
9f007a84f7
@ -0,0 +1,24 @@
|
|||||||
|
/**
|
||||||
|
* Process-unique client-side id counter.
|
||||||
|
*
|
||||||
|
* `useId()` returns the next value of a monotonic module-level counter —
|
||||||
|
* cheaper than `Date.now()` and, unlike a timestamp, collision-free. Use it
|
||||||
|
* for client-only ephemeral ids (list keys, generated handles).
|
||||||
|
*
|
||||||
|
* NOT for SSR / ARIA element ids derived from the component tree — those use
|
||||||
|
* soma's `createId`, which wraps Svelte's `$props.id()` for hydration-stable
|
||||||
|
* output. A global counter would desync between server and client renders.
|
||||||
|
*
|
||||||
|
* Lives in active-uix (not soma) so any UIX layer — soma, eidos, demos,
|
||||||
|
* apps — can mint ids without coupling to soma. Imported by subpath
|
||||||
|
* (`$active-uix/id`), mirroring `$active-uix/prefs`, so it never pulls the
|
||||||
|
* runtime barrel. The `soma-` prefix is the shared UIX id convention (same
|
||||||
|
* shape `createId` emits), not a marker of where this lives.
|
||||||
|
*/
|
||||||
|
|
||||||
|
let counter = 0
|
||||||
|
|
||||||
|
export function useId(component = ''): string {
|
||||||
|
const id = ++counter
|
||||||
|
return component ? `soma-${component}-${id}` : `soma-${id}`
|
||||||
|
}
|
||||||
@ -1 +1 @@
|
|||||||
export { createId, useId } from './create-id';
|
export { createId } from './create-id';
|
||||||
|
|||||||
Loading…
Reference in new issue