Finishes the move started in 9f007a84, which left the `id` concern split
across TWO folders (createId in soma/id, useId in active-uix/id) — worse
than one library, and the right call you pushed for. Both functions now
live in a single `$active-uix/id`; `soma/id` is deleted.
+ src/uix/active-uix/id/{create-id,use-id,index}.ts (one authority)
~ 441 soma imports repointed: relative ../../id and ../../../id -> $active-uix/id
- src/uix/soma/id/ (removed)
~ COMPONENT_GUIDE / README examples updated
createId (wraps $props.id(), SSR/ARIA ids) and useId (client-only counter)
sit together; any UIX layer — soma, eidos, demos, apps — shares one id
authority without coupling to soma. Output format unchanged
(`soma-{component}-{n}`) -> zero behavior change.
`npm run check` 0 errors; accordion (createId+useId) verified on a fresh
dev server, console clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
active-uix
parent
9f007a84f7
commit
76dd3e9d66
@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Create an id from a Svelte `$props.id()` uid, with optional component context.
|
||||
*
|
||||
* ```ts
|
||||
* createId(uid) // "soma-c12"
|
||||
* createId(uid, 'dialog-trigger') // "soma-dialog-trigger-c12"
|
||||
* ```
|
||||
*
|
||||
* The `uid` comes from the consuming component's `$props.id()`, so the output
|
||||
* is hydration-stable (deterministic per render tree) — use this for SSR / ARIA
|
||||
* element ids. For a generic client-only counter, use `useId` (same module).
|
||||
*
|
||||
* Lives in active-uix (imported by subpath `$active-uix/id`) so every UIX layer
|
||||
* — soma, eidos, demos, apps — shares one id authority without cross-layer
|
||||
* coupling. The `soma-` prefix is the UIX id convention, kept for output
|
||||
* stability across the migration.
|
||||
*/
|
||||
export function createId(uid: string, component?: string): string {
|
||||
return component ? `soma-${component}-${uid}` : `soma-${uid}`
|
||||
}
|
||||
@ -1,24 +1,2 @@
|
||||
/**
|
||||
* 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}`
|
||||
}
|
||||
export { createId } from './create-id'
|
||||
export { useId } from './use-id'
|
||||
|
||||
@ -0,0 +1,18 @@
|
||||
/**
|
||||
* 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
|
||||
* `createId` (same module), which wraps Svelte's `$props.id()` for
|
||||
* hydration-stable output. A global counter would desync server / client.
|
||||
*/
|
||||
|
||||
let counter = 0
|
||||
|
||||
export function useId(component = ''): string {
|
||||
const id = ++counter
|
||||
return component ? `soma-${component}-${id}` : `soma-${id}`
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue