@prunellejs/ui 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/llms.txt +4 -4
- package/package.json +3 -3
- package/src/CommandPalette.tsx +27 -29
- package/src/DataTable.tsx +64 -68
- package/src/Dialog.tsx +5 -4
- package/src/Menu.tsx +3 -5
- package/src/Select.tsx +33 -17
- package/src/Tabs.tsx +8 -9
- package/src/Toaster.tsx +4 -3
- package/src/labels/dialog.ts +7 -3
- package/src/labels/en/dialog.ts +11 -0
- package/src/labels/en/palette.ts +21 -0
- package/src/labels/en/select.ts +7 -0
- package/src/labels/en/table.ts +31 -0
- package/src/labels/en/toaster.ts +7 -0
- package/src/labels/fr/dialog.ts +7 -3
- package/src/labels/fr/palette.ts +12 -8
- package/src/labels/fr/select.ts +5 -1
- package/src/labels/fr/table.ts +17 -13
- package/src/labels/fr/toaster.ts +5 -1
- package/src/labels/palette.ts +7 -8
- package/src/labels/select.ts +7 -1
- package/src/labels/table.ts +7 -13
- package/src/labels/toaster.ts +7 -1
- package/src/locale.ts +15 -0
- package/src/platform-fallback.ts +7 -5
- package/src/plugin.ts +29 -10
- package/src/primitives.tsx +40 -41
- package/src/static.tsx +56 -10
- package/src/styles/bare.css +1 -1
- package/src/styles/base.css +3 -3
- package/src/styles/components/accordion.css +1 -1
- package/src/styles/components/badge.css +1 -1
- package/src/styles/components/button.css +1 -1
- package/src/styles/components/card.css +1 -1
- package/src/styles/components/checkbox.css +1 -1
- package/src/styles/components/command.css +1 -1
- package/src/styles/components/consent.css +1 -1
- package/src/styles/components/datatable.css +1 -1
- package/src/styles/components/dialog.css +1 -1
- package/src/styles/components/drawer.css +1 -1
- package/src/styles/components/field.css +1 -1
- package/src/styles/components/layout.css +1 -8
- package/src/styles/components/menu.css +1 -1
- package/src/styles/components/notice.css +1 -1
- package/src/styles/components/popover.css +1 -1
- package/src/styles/components/progress.css +1 -1
- package/src/styles/components/radio-group.css +1 -1
- package/src/styles/components/select.css +1 -1
- package/src/styles/components/switch.css +1 -1
- package/src/styles/components/tabs.css +1 -1
- package/src/styles/components/toast.css +1 -1
- package/src/styles/grammars/console.css +1 -1
- package/src/styles/grammars/editorial.css +1 -1
- package/src/styles/grammars/orbit.css +1 -1
- package/src/styles/grammars/prunelle.css +1 -1
- package/src/styles/grammars/soft.css +1 -1
- package/src/styles/grammars/workshop.css +1 -1
- package/src/styles/scan.ts +1 -0
- package/src/styles/split.ts +10 -10
- package/src/styles/theme.css +1 -1
- package/src/styles/themed/accordion.css +1 -1
- package/src/styles/themed/badge.css +1 -1
- package/src/styles/themed/button.css +1 -1
- package/src/styles/themed/card.css +1 -1
- package/src/styles/themed/checkbox.css +1 -1
- package/src/styles/themed/command.css +1 -1
- package/src/styles/themed/consent.css +1 -1
- package/src/styles/themed/datatable.css +1 -1
- package/src/styles/themed/dialog.css +1 -1
- package/src/styles/themed/drawer.css +1 -1
- package/src/styles/themed/field.css +1 -1
- package/src/styles/themed/menu.css +1 -1
- package/src/styles/themed/notice.css +1 -1
- package/src/styles/themed/popover.css +1 -1
- package/src/styles/themed/radio-group.css +1 -1
- package/src/styles/themed/select.css +1 -1
- package/src/styles/themed/switch.css +1 -1
- package/src/styles/themed/tabs.css +1 -1
- package/src/styles/themed/toast.css +1 -1
- package/src/table-state.ts +11 -5
package/src/static.tsx
CHANGED
|
@@ -47,11 +47,14 @@ export interface ButtonProps {
|
|
|
47
47
|
[attr: string]: unknown
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
function restProps(props: Record<string, unknown>, skip: readonly string[]): Record<string, unknown> {
|
|
50
|
+
export function restProps(props: Record<string, unknown>, skip: readonly string[]): Record<string, unknown> {
|
|
51
51
|
const out: Record<string, unknown> = {}
|
|
52
52
|
for (const k of Object.keys(props)) {
|
|
53
|
-
if (k !== 'children' && !skip.includes(k))
|
|
54
|
-
|
|
53
|
+
if (k !== 'children' && !skip.includes(k)) {
|
|
54
|
+
const desc = Object.getOwnPropertyDescriptor(props, k)
|
|
55
|
+
if (desc !== undefined)
|
|
56
|
+
Object.defineProperty(out, k, desc)
|
|
57
|
+
}
|
|
55
58
|
}
|
|
56
59
|
return out
|
|
57
60
|
}
|
|
@@ -140,8 +143,8 @@ function wireFieldHtml(html: string, wiring: FieldControlWiring): string {
|
|
|
140
143
|
let attrs = target.rawAttrs
|
|
141
144
|
if (!/\bid\s*=/i.test(attrs))
|
|
142
145
|
attrs += ` id="${escAttr(wiring.id)}"`
|
|
143
|
-
else if (/\bid\s*=\s*"
|
|
144
|
-
attrs = attrs.replace(/\bid\s*=\s*"
|
|
146
|
+
else if (/\bid\s*=\s*"pru-[^"]*"/i.test(attrs))
|
|
147
|
+
attrs = attrs.replace(/\bid\s*=\s*"pru-[^"]*"/i, `id="${escAttr(wiring.id)}"`)
|
|
145
148
|
|
|
146
149
|
if (wiring.describedBy) {
|
|
147
150
|
const descRe = /(\baria-describedby\s*=\s*")([^"]*)(")/i
|
|
@@ -182,7 +185,7 @@ function syncFieldAria(el: Element, id: string, err: string | undefined, hint: s
|
|
|
182
185
|
|
|
183
186
|
function wireFieldElement(el: Element, wiring: FieldControlWiring, err: string | undefined, hint: string | undefined): void {
|
|
184
187
|
const curId = el.getAttribute('id')
|
|
185
|
-
if (!curId || curId.startsWith('
|
|
188
|
+
if (!curId || curId.startsWith('pru-'))
|
|
186
189
|
el.setAttribute('id', wiring.id)
|
|
187
190
|
syncFieldAria(el, wiring.id, err, hint, false)
|
|
188
191
|
if (wiring.required) {
|
|
@@ -290,16 +293,59 @@ export type SpaceValue = SpaceToken | (string & {})
|
|
|
290
293
|
export type TrackValue = TrackSize | (string & {})
|
|
291
294
|
|
|
292
295
|
const SPACE_TOKENS = new Set<string>(['none', '2xs', 'xs', 'sm', 'md', 'lg', 'xl', '2xl'])
|
|
296
|
+
const UNSAFE_CSS_VALUE_RE = /[;{}\r\n\f\\"'`<>]|\/\*|\*\/|(?:^|[^\w-])(?:url|expression|image-set)\s*\(/i
|
|
293
297
|
|
|
294
298
|
const isSpaceToken = (v: string | undefined): boolean => v !== undefined && SPACE_TOKENS.has(v)
|
|
295
299
|
|
|
300
|
+
/** Validates a custom CSS length/track value so inline custom properties reject `;`, `url(`, `expression(`, or unbalanced parens. */
|
|
301
|
+
export function safeCssLength(value: string | undefined): string | undefined {
|
|
302
|
+
if (value === undefined)
|
|
303
|
+
return undefined
|
|
304
|
+
const trimmed = value.trim()
|
|
305
|
+
if (trimmed === '' || UNSAFE_CSS_VALUE_RE.test(trimmed))
|
|
306
|
+
return undefined
|
|
307
|
+
let depth = 0
|
|
308
|
+
for (let i = 0; i < trimmed.length; i++) {
|
|
309
|
+
if (trimmed[i] === '(')
|
|
310
|
+
depth++
|
|
311
|
+
else if (trimmed[i] === ')' && --depth < 0)
|
|
312
|
+
return undefined
|
|
313
|
+
}
|
|
314
|
+
return depth === 0 ? trimmed : undefined
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
type StyleProp = string | Record<string, string | number | undefined> | undefined
|
|
318
|
+
|
|
319
|
+
/** Merges validated layout CSS custom properties (`--ui-gap`, `--ui-min`, `--ui-side`) with a caller's `style` prop. */
|
|
320
|
+
export function layoutStyle(
|
|
321
|
+
vars: Record<string, string | undefined>,
|
|
322
|
+
userStyle: unknown,
|
|
323
|
+
): StyleProp {
|
|
324
|
+
const entries: Array<[string, string]> = []
|
|
325
|
+
for (const [k, raw] of Object.entries(vars)) {
|
|
326
|
+
const safe = safeCssLength(raw)
|
|
327
|
+
if (safe !== undefined)
|
|
328
|
+
entries.push([k, safe])
|
|
329
|
+
}
|
|
330
|
+
if (entries.length === 0)
|
|
331
|
+
return userStyle as StyleProp
|
|
332
|
+
if (typeof userStyle === 'string') {
|
|
333
|
+
const prefix = entries.map(([k, v]) => `${k}:${v}`).join(';')
|
|
334
|
+
const trimmed = userStyle.trim()
|
|
335
|
+
return trimmed === '' ? `${prefix};` : `${prefix};${trimmed}`
|
|
336
|
+
}
|
|
337
|
+
if (userStyle !== null && typeof userStyle === 'object')
|
|
338
|
+
return { ...Object.fromEntries(entries), ...(userStyle as Record<string, string | number | undefined>) }
|
|
339
|
+
return `${entries.map(([k, v]) => `${k}:${v}`).join(';')};`
|
|
340
|
+
}
|
|
341
|
+
|
|
296
342
|
export function Stack(props: BoxProps & { gap?: SpaceValue | undefined }) {
|
|
297
|
-
const rest = restProps(props, ['gap', 'class'])
|
|
343
|
+
const rest = restProps(props, ['gap', 'class', 'style'])
|
|
298
344
|
return (
|
|
299
345
|
<div
|
|
300
346
|
data-layout="stack"
|
|
301
347
|
data-gap={isSpaceToken(props.gap) ? props.gap : undefined}
|
|
302
|
-
|
|
348
|
+
style={layoutStyle({ '--ui-gap': isSpaceToken(props.gap) ? undefined : props.gap }, props.style)}
|
|
303
349
|
class={props.class}
|
|
304
350
|
{...rest}
|
|
305
351
|
>
|
|
@@ -309,12 +355,12 @@ export function Stack(props: BoxProps & { gap?: SpaceValue | undefined }) {
|
|
|
309
355
|
}
|
|
310
356
|
|
|
311
357
|
export function Cluster(props: BoxProps & { gap?: SpaceValue | undefined }) {
|
|
312
|
-
const rest = restProps(props, ['gap', 'class'])
|
|
358
|
+
const rest = restProps(props, ['gap', 'class', 'style'])
|
|
313
359
|
return (
|
|
314
360
|
<div
|
|
315
361
|
data-layout="cluster"
|
|
316
362
|
data-gap={isSpaceToken(props.gap) ? props.gap : undefined}
|
|
317
|
-
|
|
363
|
+
style={layoutStyle({ '--ui-gap': isSpaceToken(props.gap) ? undefined : props.gap }, props.style)}
|
|
318
364
|
class={props.class}
|
|
319
365
|
{...rest}
|
|
320
366
|
>
|
package/src/styles/bare.css
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* @prunellejs/ui bare floor: behavior, layout primitives, accessibility & top-layer positioning only.
|
|
2
|
-
* Everything sits inside @layer
|
|
2
|
+
* Everything sits inside @layer pru-ui so Tailwind utilities and user CSS always win without !important. */
|
|
3
3
|
|
|
4
4
|
@import './base.css';
|
|
5
5
|
@import './components/layout.css';
|
package/src/styles/base.css
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/* @prunellejs/ui base floor: box-sizing, screen-reader utility, single focus indicator, reduced motion & [hidden].
|
|
2
|
-
* Everything sits inside @layer
|
|
2
|
+
* Everything sits inside @layer pru-ui so Tailwind utilities and user CSS always win without !important. */
|
|
3
3
|
|
|
4
|
-
@layer
|
|
4
|
+
@layer pru-ui {
|
|
5
5
|
[data-ui] *,
|
|
6
6
|
[data-ui] *::before,
|
|
7
7
|
[data-ui] *::after {
|
|
8
8
|
box-sizing: border-box;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
.
|
|
11
|
+
.pru-sr-only {
|
|
12
12
|
position: absolute;
|
|
13
13
|
width: 1px;
|
|
14
14
|
height: 1px;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
@layer
|
|
1
|
+
@layer pru-ui {
|
|
2
2
|
[data-ui="datatable"] { display: flex; flex-direction: column; gap: var(--ui-table-gap, 0.75rem); }
|
|
3
3
|
[data-ui="datatable"] [data-part="scroll"] { overflow-x: auto; }
|
|
4
4
|
[data-ui="datatable"] [data-part="search"] { min-block-size: var(--ui-touch-min, auto); font-size: var(--ui-input-floor, inherit); }
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
@layer
|
|
1
|
+
@layer pru-ui {
|
|
2
2
|
/* Every Layout primitives (0 KB JS) */
|
|
3
3
|
[data-layout="stack"] {
|
|
4
4
|
display: flex;
|
|
@@ -59,11 +59,4 @@
|
|
|
59
59
|
[data-layout="sidebar"][data-side="md"] { --ui-side: 16rem; }
|
|
60
60
|
[data-layout="sidebar"][data-side="lg"] { --ui-side: 20rem; }
|
|
61
61
|
[data-layout="sidebar"][data-side="xl"] { --ui-side: 24rem; }
|
|
62
|
-
|
|
63
|
-
/* Progressive CSS Values 5 attr() support for custom CSS lengths without inline style attributes */
|
|
64
|
-
@supports (gap: attr(data-gap-value type(<length-percentage>))) {
|
|
65
|
-
[data-layout][data-gap-value] { --ui-gap: attr(data-gap-value type(<length-percentage>)); }
|
|
66
|
-
[data-layout="grid"][data-min-value] { --ui-min: attr(data-min-value type(<length-percentage>)); }
|
|
67
|
-
[data-layout="sidebar"][data-side-value] { --ui-side: attr(data-side-value type(<length-percentage>)); }
|
|
68
|
-
}
|
|
69
62
|
}
|
package/src/styles/scan.ts
CHANGED
|
@@ -35,6 +35,7 @@ const DATA_UI_ALIASES: Readonly<Record<string, readonly UiComponentPart[]>> = {
|
|
|
35
35
|
const PRUNELLE_EXPORT_TO_PARTS: Readonly<Record<string, readonly UiComponentPart[]>> = {
|
|
36
36
|
ConsentBanner: ['consent', 'button'],
|
|
37
37
|
ConsentPreferences: ['consent', 'button'],
|
|
38
|
+
CookieTable: ['datatable'],
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
function isUiImportSource(specifier: string): boolean {
|
package/src/styles/split.ts
CHANGED
|
@@ -245,11 +245,11 @@ function scanTopBlocks(css: string): RawBlock[] {
|
|
|
245
245
|
return blocks
|
|
246
246
|
}
|
|
247
247
|
|
|
248
|
-
function
|
|
248
|
+
function unwrapLayerPruUi(css: string): string {
|
|
249
249
|
const blocks = scanTopBlocks(css)
|
|
250
250
|
const inner: string[] = []
|
|
251
251
|
for (const b of blocks) {
|
|
252
|
-
if (/^@layer\s+
|
|
252
|
+
if (/^@layer\s+pru-ui\b/.test(b.prelude)) {
|
|
253
253
|
const open = b.full.indexOf('{')
|
|
254
254
|
const close = b.full.lastIndexOf('}')
|
|
255
255
|
if (open !== -1 && close > open)
|
|
@@ -269,14 +269,14 @@ const cachedGrammars = new Map<GrammarName, ParsedGrammar>()
|
|
|
269
269
|
|
|
270
270
|
function readBaseBody(): string {
|
|
271
271
|
if (cachedBaseBody === undefined)
|
|
272
|
-
cachedBaseBody =
|
|
272
|
+
cachedBaseBody = unwrapLayerPruUi(readFileSync(join(STYLES_DIR, 'base.css'), 'utf8'))
|
|
273
273
|
return cachedBaseBody
|
|
274
274
|
}
|
|
275
275
|
|
|
276
276
|
function readComponentBody(part: UiComponentPart): string {
|
|
277
277
|
let body = cachedComponentBodies.get(part)
|
|
278
278
|
if (body === undefined) {
|
|
279
|
-
body =
|
|
279
|
+
body = unwrapLayerPruUi(readFileSync(join(STYLES_DIR, 'components', `${part}.css`), 'utf8'))
|
|
280
280
|
cachedComponentBodies.set(part, body)
|
|
281
281
|
}
|
|
282
282
|
return body
|
|
@@ -286,7 +286,7 @@ function readThemedBody(part: UiComponentPart): string | null {
|
|
|
286
286
|
let body = cachedThemedBodies.get(part)
|
|
287
287
|
if (body === undefined) {
|
|
288
288
|
const file = join(STYLES_DIR, 'themed', `${part}.css`)
|
|
289
|
-
body = existsSync(file) ?
|
|
289
|
+
body = existsSync(file) ? unwrapLayerPruUi(readFileSync(file, 'utf8')) : null
|
|
290
290
|
cachedThemedBodies.set(part, body)
|
|
291
291
|
}
|
|
292
292
|
return body
|
|
@@ -310,7 +310,7 @@ function parseGrammar(grammar: GrammarName): ParsedGrammar {
|
|
|
310
310
|
const partBlocks: TaggedBlock[] = []
|
|
311
311
|
|
|
312
312
|
for (const top of scanTopBlocks(raw)) {
|
|
313
|
-
if (/^@layer\s+
|
|
313
|
+
if (/^@layer\s+pru-ui\b/.test(top.prelude)) {
|
|
314
314
|
const open = top.full.indexOf('{')
|
|
315
315
|
const close = top.full.lastIndexOf('}')
|
|
316
316
|
if (open === -1 || close <= open)
|
|
@@ -358,11 +358,11 @@ export function renderGrammarBaseCss(grammar: GrammarName): string {
|
|
|
358
358
|
out.push(rule.css)
|
|
359
359
|
}
|
|
360
360
|
const layerBody = [readBaseBody(), ...parsed.baseBlocks].filter(Boolean).join('\n\n')
|
|
361
|
-
out.push(`@layer
|
|
361
|
+
out.push(`@layer pru-ui {\n${layerBody}\n}`)
|
|
362
362
|
return `${out.join('\n\n')}\n`
|
|
363
363
|
}
|
|
364
364
|
|
|
365
|
-
/** Returns ONLY the component CSS (structural + tokenized + grammar overrides) for `parts`, in deterministic cascade order inside `@layer
|
|
365
|
+
/** Returns ONLY the component CSS (structural + tokenized + grammar overrides) for `parts`, in deterministic cascade order inside `@layer pru-ui`. */
|
|
366
366
|
export function renderGrammarPartsCss(grammar: GrammarName, parts: Iterable<UiComponentPart>): string {
|
|
367
367
|
const wanted = new Set<UiComponentPart>()
|
|
368
368
|
for (const p of parts) {
|
|
@@ -397,7 +397,7 @@ export function renderGrammarPartsCss(grammar: GrammarName, parts: Iterable<UiCo
|
|
|
397
397
|
}
|
|
398
398
|
}
|
|
399
399
|
|
|
400
|
-
out.push(`@layer
|
|
400
|
+
out.push(`@layer pru-ui {\n${layerChunks.filter(Boolean).join('\n\n')}\n}`)
|
|
401
401
|
return `${out.join('\n\n')}\n`
|
|
402
402
|
}
|
|
403
403
|
|
|
@@ -424,6 +424,6 @@ export function renderGrammarCss(grammar: GrammarName): string {
|
|
|
424
424
|
layerChunks.push(blk.css)
|
|
425
425
|
}
|
|
426
426
|
|
|
427
|
-
out.push(`@layer
|
|
427
|
+
out.push(`@layer pru-ui {\n${layerChunks.filter(Boolean).join('\n\n')}\n}`)
|
|
428
428
|
return `${out.join('\n\n')}\n`
|
|
429
429
|
}
|
package/src/styles/theme.css
CHANGED
package/src/table-state.ts
CHANGED
|
@@ -39,13 +39,18 @@ export function createDataTable<T>(options: DataTableOptions<T>): DataTableState
|
|
|
39
39
|
const rawPage = signal(1)
|
|
40
40
|
const selected = signal<Set<string | number>>(new Set())
|
|
41
41
|
const rowSelected = new Map<string | number, Signal<boolean>>()
|
|
42
|
-
const pageSize = options.pageSize ?? 25
|
|
42
|
+
const pageSize = () => options.pageSize ?? 25
|
|
43
43
|
let collator: Intl.Collator | undefined
|
|
44
|
+
let collatorLocale: string | undefined
|
|
44
45
|
|
|
45
46
|
const compare = (a: unknown, b: unknown): number => {
|
|
46
47
|
if (typeof a === 'number' && typeof b === 'number')
|
|
47
48
|
return a - b
|
|
48
|
-
|
|
49
|
+
const loc = options.locale ?? (typeof document === 'undefined' ? undefined : document.documentElement.lang || undefined)
|
|
50
|
+
if (collator === undefined || collatorLocale !== loc) {
|
|
51
|
+
collatorLocale = loc
|
|
52
|
+
collator = new Intl.Collator(loc, { numeric: true, sensitivity: 'base' })
|
|
53
|
+
}
|
|
49
54
|
return collator.compare(String(a), String(b))
|
|
50
55
|
}
|
|
51
56
|
|
|
@@ -75,7 +80,7 @@ export function createDataTable<T>(options: DataTableOptions<T>): DataTableState
|
|
|
75
80
|
return list
|
|
76
81
|
})
|
|
77
82
|
|
|
78
|
-
const totalPages = computed(() => Math.max(1, Math.ceil(filtered.value.length / pageSize)))
|
|
83
|
+
const totalPages = computed(() => Math.max(1, Math.ceil(filtered.value.length / pageSize())))
|
|
79
84
|
const clampedPage = computed(() => Math.min(Math.max(1, rawPage.value), totalPages.value))
|
|
80
85
|
const page: Signal<number> = {
|
|
81
86
|
get value() { return clampedPage.value },
|
|
@@ -84,8 +89,9 @@ export function createDataTable<T>(options: DataTableOptions<T>): DataTableState
|
|
|
84
89
|
}
|
|
85
90
|
|
|
86
91
|
const visible = computed<T[]>(() => {
|
|
87
|
-
const
|
|
88
|
-
|
|
92
|
+
const size = pageSize()
|
|
93
|
+
const start = (clampedPage.value - 1) * size
|
|
94
|
+
return filtered.value.slice(start, start + size)
|
|
89
95
|
})
|
|
90
96
|
|
|
91
97
|
const setSelected = (keys: Iterable<string | number>, on: boolean) => {
|