@cognitap/radiant 0.0.61 → 0.0.63
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/CHANGELOG.md +13 -0
- package/dist/library/Autocomplete.d.ts +3 -2
- package/dist/library/Autocomplete.d.ts.map +1 -1
- package/dist/library/Autocomplete.js +1 -1
- package/dist/library/Autocomplete.js.map +1 -1
- package/dist/library/CodeBlock.d.ts +2 -7
- package/dist/library/CodeBlock.d.ts.map +1 -1
- package/dist/library/CodeBlock.js.map +1 -1
- package/dist/library/Combobox.d.ts +14 -24
- package/dist/library/Combobox.d.ts.map +1 -1
- package/dist/library/Combobox.js +15 -14
- package/dist/library/Combobox.js.map +1 -1
- package/dist/library/Command.d.ts.map +1 -1
- package/dist/library/Command.js +2 -2
- package/dist/library/Command.js.map +1 -1
- package/dist/library/Dialog.d.ts +2 -9
- package/dist/library/Dialog.d.ts.map +1 -1
- package/dist/library/Dialog.js.map +1 -1
- package/dist/library/Menu.d.ts +2 -2
- package/dist/library/Menu.d.ts.map +1 -1
- package/dist/library/Menu.js.map +1 -1
- package/dist/library/MultiSelect.d.ts +4 -5
- package/dist/library/MultiSelect.d.ts.map +1 -1
- package/dist/library/MultiSelect.js +2 -2
- package/dist/library/MultiSelect.js.map +1 -1
- package/dist/library/Popover.d.ts +2 -2
- package/dist/library/Popover.d.ts.map +1 -1
- package/dist/library/Popover.js.map +1 -1
- package/dist/library/Resizable.d.ts +56 -0
- package/dist/library/Resizable.d.ts.map +1 -0
- package/dist/library/Resizable.js +345 -0
- package/dist/library/Resizable.js.map +1 -0
- package/dist/library/Separator.d.ts +6 -1
- package/dist/library/Separator.d.ts.map +1 -1
- package/dist/library/Separator.js +11 -3
- package/dist/library/Separator.js.map +1 -1
- package/dist/library/TagsInput.d.ts +2 -2
- package/dist/library/TagsInput.d.ts.map +1 -1
- package/dist/library/TagsInput.js +1 -1
- package/dist/library/TagsInput.js.map +1 -1
- package/dist/library/Toast.d.ts +2 -2
- package/dist/library/Toast.d.ts.map +1 -1
- package/dist/library/Toast.js.map +1 -1
- package/dist/library/cn.d.ts.map +1 -1
- package/dist/library/cn.js +4 -0
- package/dist/library/cn.js.map +1 -1
- package/dist/library/index.d.ts +3 -2
- package/dist/library/index.d.ts.map +1 -1
- package/dist/library/index.js +1 -0
- package/dist/library/index.js.map +1 -1
- package/dist/library/internal/decimal.d.ts +3 -0
- package/dist/library/internal/decimal.d.ts.map +1 -0
- package/dist/library/internal/decimal.js +15 -0
- package/dist/library/internal/decimal.js.map +1 -0
- package/dist/library/internal/numberField.d.ts +1 -1
- package/dist/library/internal/numberField.d.ts.map +1 -1
- package/dist/library/internal/numberField.js +3 -13
- package/dist/library/internal/numberField.js.map +1 -1
- package/dist/library/internal/resizable.d.ts +15 -0
- package/dist/library/internal/resizable.d.ts.map +1 -0
- package/dist/library/internal/resizable.js +86 -0
- package/dist/library/internal/resizable.js.map +1 -0
- package/dist/library/internal/types.d.ts +9 -0
- package/dist/library/internal/types.d.ts.map +1 -1
- package/dist/library/styles.css +1 -1
- package/dist/library/themes/components.d.ts +10 -0
- package/dist/library/themes/components.d.ts.map +1 -1
- package/dist/library/themes/components.js +10 -0
- package/dist/library/themes/components.js.map +1 -1
- package/docs/architecture.md +5 -6
- package/package.json +1 -1
- package/src/Autocomplete.tsx +4 -2
- package/src/CodeBlock.tsx +2 -7
- package/src/Combobox.tsx +55 -41
- package/src/Command.tsx +0 -2
- package/src/Dialog.tsx +2 -10
- package/src/Menu.tsx +2 -5
- package/src/MultiSelect.tsx +7 -7
- package/src/Popover.tsx +2 -5
- package/src/Resizable.tsx +581 -0
- package/src/Separator.tsx +22 -5
- package/src/TagsInput.tsx +5 -5
- package/src/Toast.tsx +2 -5
- package/src/cn.ts +4 -0
- package/src/index.ts +17 -2
- package/src/internal/decimal.ts +17 -0
- package/src/internal/numberField.ts +4 -16
- package/src/internal/resizable.ts +115 -0
- package/src/internal/types.ts +10 -0
- package/src/themes/components.ts +10 -0
package/src/cn.ts
CHANGED
|
@@ -69,6 +69,7 @@ export const cn: CnFunction = createCn({
|
|
|
69
69
|
'text-(--rad-tabs-font-size)'
|
|
70
70
|
],
|
|
71
71
|
h: [
|
|
72
|
+
'h-(--rad-resizable-handle-size)',
|
|
72
73
|
'h-(--rad-meter-height)',
|
|
73
74
|
'h-(--rad-native-select-height)',
|
|
74
75
|
'h-(--rad-drawer-size)',
|
|
@@ -82,6 +83,7 @@ export const cn: CnFunction = createCn({
|
|
|
82
83
|
'h-(--rad-slider-length)'
|
|
83
84
|
],
|
|
84
85
|
w: [
|
|
86
|
+
'w-(--rad-resizable-handle-size)',
|
|
85
87
|
'w-(--rad-otp-field-slot-size)',
|
|
86
88
|
'w-(--rad-drawer-size)',
|
|
87
89
|
'w-(--rad-context-menu-width)',
|
|
@@ -292,6 +294,7 @@ export const cn: CnFunction = createCn({
|
|
|
292
294
|
'[corner-shape:var(--rad-tabs-corner-shape)]'
|
|
293
295
|
],
|
|
294
296
|
'outline-w': [
|
|
297
|
+
'outline-(--rad-resizable-focus-width)',
|
|
295
298
|
'outline-(--rad-nav-link-focus-width)',
|
|
296
299
|
'outline-(--rad-native-select-focus-width)',
|
|
297
300
|
'outline-(--rad-input-group-focus-width)',
|
|
@@ -302,6 +305,7 @@ export const cn: CnFunction = createCn({
|
|
|
302
305
|
'outline-(--rad-tabs-focus-width)'
|
|
303
306
|
],
|
|
304
307
|
'outline-offset': [
|
|
308
|
+
'outline-offset-(--rad-resizable-focus-offset)',
|
|
305
309
|
'outline-offset-(--rad-nav-link-focus-offset)',
|
|
306
310
|
'outline-offset-(--rad-native-select-focus-offset)',
|
|
307
311
|
'outline-offset-(--rad-input-group-focus-offset)',
|
package/src/index.ts
CHANGED
|
@@ -55,7 +55,8 @@ export type {
|
|
|
55
55
|
ComboboxClearProps,
|
|
56
56
|
ComboboxContentProps,
|
|
57
57
|
ComboboxItemProps,
|
|
58
|
-
ComboboxStatusProps
|
|
58
|
+
ComboboxStatusProps,
|
|
59
|
+
ComboboxRenderProps
|
|
59
60
|
} from './Combobox.js'
|
|
60
61
|
export { Button } from './Button.js'
|
|
61
62
|
export { Tooltip, TooltipTrigger, TooltipContent, TooltipPortal, useTooltip } from './Tooltip.js'
|
|
@@ -613,7 +614,8 @@ export {
|
|
|
613
614
|
type AutocompletePortalProps,
|
|
614
615
|
type AutocompleteContentProps,
|
|
615
616
|
type AutocompleteItemProps,
|
|
616
|
-
type AutocompleteStatusProps
|
|
617
|
+
type AutocompleteStatusProps,
|
|
618
|
+
type AutocompleteRenderProps
|
|
617
619
|
} from './Autocomplete.js'
|
|
618
620
|
|
|
619
621
|
export {
|
|
@@ -672,3 +674,16 @@ export {
|
|
|
672
674
|
} from './CodeBlock.js'
|
|
673
675
|
|
|
674
676
|
export { NumberField, type NumberFieldProps, type NumberFieldFormatOptions } from './NumberField.js'
|
|
677
|
+
|
|
678
|
+
export {
|
|
679
|
+
Resizable,
|
|
680
|
+
ResizablePanel,
|
|
681
|
+
ResizableHandle,
|
|
682
|
+
useResizable,
|
|
683
|
+
type ResizableProps,
|
|
684
|
+
type ResizablePanelProps,
|
|
685
|
+
type ResizableHandleProps,
|
|
686
|
+
type ResizableState,
|
|
687
|
+
type ResizablePanelState,
|
|
688
|
+
type ResizableItem
|
|
689
|
+
} from './Resizable.js'
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Add finite JavaScript numbers through decimal coefficients before conversion. */
|
|
2
|
+
export function addDecimal(left: number, right: number) {
|
|
3
|
+
const parts = (value: number) => {
|
|
4
|
+
const [mantissa, exponent = '0'] = value.toString().split('e')
|
|
5
|
+
return {
|
|
6
|
+
coefficient: BigInt(mantissa!.replace('.', '')),
|
|
7
|
+
exponent: Number(exponent) - (mantissa!.split('.')[1]?.length ?? 0)
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
const a = parts(left),
|
|
11
|
+
b = parts(right),
|
|
12
|
+
exponent = Math.min(a.exponent, b.exponent)
|
|
13
|
+
const coefficient =
|
|
14
|
+
a.coefficient * 10n ** BigInt(a.exponent - exponent) +
|
|
15
|
+
b.coefficient * 10n ** BigInt(b.exponent - exponent)
|
|
16
|
+
return Number(coefficient.toString() + 'e' + exponent)
|
|
17
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { addDecimal } from './decimal.js'
|
|
2
|
+
|
|
1
3
|
/** A bounded editable decimal adapter; Intl supplies display and locale symbols. */
|
|
2
4
|
export type NumberFieldFormatOptions = {
|
|
3
5
|
style?: 'decimal' | 'percent' | 'currency'
|
|
@@ -172,22 +174,8 @@ export function requireFiniteNumber(name: string, value: unknown, nullable = fal
|
|
|
172
174
|
}
|
|
173
175
|
export const clampNumber = (value: number, min?: number, max?: number) =>
|
|
174
176
|
Math.min(max ?? Infinity, Math.max(min ?? -Infinity, value))
|
|
175
|
-
/** Add decimal
|
|
177
|
+
/** Add a decimal step, respecting the public finite-number range. */
|
|
176
178
|
export function addNumberStep(value: number, amount: number, min?: number, max?: number) {
|
|
177
|
-
const
|
|
178
|
-
const [mantissa, exponent = '0'] = number.toString().split('e')
|
|
179
|
-
const fraction = mantissa!.split('.')[1]?.length ?? 0
|
|
180
|
-
return {
|
|
181
|
-
coefficient: BigInt(mantissa!.replace('.', '')),
|
|
182
|
-
exponent: Number(exponent) - fraction
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
const a = parts(value),
|
|
186
|
-
b = parts(amount),
|
|
187
|
-
exponent = Math.min(a.exponent, b.exponent)
|
|
188
|
-
const coefficient =
|
|
189
|
-
a.coefficient * 10n ** BigInt(a.exponent - exponent) +
|
|
190
|
-
b.coefficient * 10n ** BigInt(b.exponent - exponent)
|
|
191
|
-
const next = clampNumber(Number(coefficient.toString() + 'e' + exponent), min, max)
|
|
179
|
+
const next = clampNumber(addDecimal(value, amount), min, max)
|
|
192
180
|
return Number.isFinite(next) ? next : value
|
|
193
181
|
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { addDecimal } from './decimal.js'
|
|
2
|
+
export type ResizableItem = { value: string; min?: number; max?: number; collapsible?: boolean }
|
|
3
|
+
export type ResizableRange = readonly [number, number]
|
|
4
|
+
const finite = (value: unknown): value is number =>
|
|
5
|
+
typeof value === 'number' && Number.isFinite(value)
|
|
6
|
+
export const sameResizableValue = (a: number[], b: number[]) =>
|
|
7
|
+
a.length === b.length && a.every((value, index) => value === b[index])
|
|
8
|
+
export function checkResizableItems(items: readonly ResizableItem[]) {
|
|
9
|
+
if (!Array.isArray(items) || items.length < 2)
|
|
10
|
+
throw new TypeError('Resizable requires at least two items.')
|
|
11
|
+
const seen = new Set<string>()
|
|
12
|
+
for (const item of items) {
|
|
13
|
+
if (!item || typeof item.value !== 'string' || !item.value.trim() || seen.has(item.value))
|
|
14
|
+
throw new TypeError('Resizable panel keys must be unique nonempty strings.')
|
|
15
|
+
seen.add(item.value)
|
|
16
|
+
const min = item.min ?? 0,
|
|
17
|
+
max = item.max ?? 100
|
|
18
|
+
if (!finite(min) || !finite(max) || min < 0 || max > 100 || min > max)
|
|
19
|
+
throw new TypeError('Resizable bounds must be percentages with 0 <= min <= max <= 100.')
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export function checkResizableValue(
|
|
23
|
+
items: readonly ResizableItem[],
|
|
24
|
+
value: unknown
|
|
25
|
+
): asserts value is number[] {
|
|
26
|
+
if (
|
|
27
|
+
!Array.isArray(value) ||
|
|
28
|
+
value.length !== items.length ||
|
|
29
|
+
!value.every(
|
|
30
|
+
(size, index) =>
|
|
31
|
+
finite(size) &&
|
|
32
|
+
((size === 0 && items[index]!.collapsible) ||
|
|
33
|
+
(size >= (items[index]!.min ?? 0) && size <= (items[index]!.max ?? 100)))
|
|
34
|
+
)
|
|
35
|
+
)
|
|
36
|
+
throw new TypeError('Resizable needs one finite size per panel within its bounds.')
|
|
37
|
+
if (Math.abs(value.reduce(addDecimal, 0) - 100) > 1e-7)
|
|
38
|
+
throw new TypeError('Resizable sizes must total 100.')
|
|
39
|
+
}
|
|
40
|
+
export function resizableIndex(items: readonly ResizableItem[], value: string) {
|
|
41
|
+
const index = items.findIndex(item => item.value === value)
|
|
42
|
+
if (index < 0) throw new TypeError('Unknown Resizable panel: ' + value)
|
|
43
|
+
return index
|
|
44
|
+
}
|
|
45
|
+
export const resizableNeighbor = (items: readonly ResizableItem[], index: number) =>
|
|
46
|
+
index === items.length - 1 ? index - 1 : index + 1
|
|
47
|
+
const ranges = (item: ResizableItem): ResizableRange[] =>
|
|
48
|
+
item.collapsible
|
|
49
|
+
? [
|
|
50
|
+
[0, 0],
|
|
51
|
+
[item.min ?? 0, item.max ?? 100]
|
|
52
|
+
]
|
|
53
|
+
: [[item.min ?? 0, item.max ?? 100]]
|
|
54
|
+
/** Recover exact constraint endpoints after a few floating-point operations. */
|
|
55
|
+
function snapBoundary(value: number, endpoints: readonly number[], scale: number) {
|
|
56
|
+
const closest = endpoints.reduce(
|
|
57
|
+
(best, point) => (Math.abs(value - point) < Math.abs(value - best) ? point : best),
|
|
58
|
+
endpoints[0]!
|
|
59
|
+
)
|
|
60
|
+
return Math.abs(value - closest) <= Number.EPSILON * 8 * Math.max(1, Math.abs(scale))
|
|
61
|
+
? closest
|
|
62
|
+
: value
|
|
63
|
+
}
|
|
64
|
+
export function resizableRanges(
|
|
65
|
+
items: readonly ResizableItem[],
|
|
66
|
+
value: number[],
|
|
67
|
+
index: number
|
|
68
|
+
): ResizableRange[] {
|
|
69
|
+
const neighbor = resizableNeighbor(items, index),
|
|
70
|
+
sum = addDecimal(value[index]!, value[neighbor]!)
|
|
71
|
+
return ranges(items[index]!)
|
|
72
|
+
.flatMap(a =>
|
|
73
|
+
ranges(items[neighbor]!).flatMap(b => {
|
|
74
|
+
const min = snapBoundary(Math.max(a[0], addDecimal(sum, -b[1])), a, sum),
|
|
75
|
+
max = snapBoundary(Math.min(a[1], addDecimal(sum, -b[0])), a, sum)
|
|
76
|
+
return min <= max ? [[min, max] as const] : []
|
|
77
|
+
})
|
|
78
|
+
)
|
|
79
|
+
.sort((a, b) => a[0] - b[0])
|
|
80
|
+
}
|
|
81
|
+
export function resizePanel(
|
|
82
|
+
items: readonly ResizableItem[],
|
|
83
|
+
value: number[],
|
|
84
|
+
index: number,
|
|
85
|
+
size: number,
|
|
86
|
+
directional = true
|
|
87
|
+
) {
|
|
88
|
+
if (!finite(size)) throw new TypeError('Resizable sizes must be finite.')
|
|
89
|
+
const intervals = resizableRanges(items, value, index)
|
|
90
|
+
if (!intervals.length) return value
|
|
91
|
+
const current = value[index]!
|
|
92
|
+
let next = intervals[0]![0],
|
|
93
|
+
distance = Infinity
|
|
94
|
+
for (const [min, max] of intervals) {
|
|
95
|
+
const candidate = Math.max(min, Math.min(max, size)),
|
|
96
|
+
difference = Math.abs(candidate - size)
|
|
97
|
+
if (difference < distance) {
|
|
98
|
+
next = candidate
|
|
99
|
+
distance = difference
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (directional && next === current && size !== current) {
|
|
103
|
+
if (size > current) next = intervals.find(range => range[0] > current)?.[0] ?? next
|
|
104
|
+
else next = [...intervals].reverse().find(range => range[1] < current)?.[1] ?? next
|
|
105
|
+
}
|
|
106
|
+
if (next === current) return value
|
|
107
|
+
const neighbor = resizableNeighbor(items, index),
|
|
108
|
+
result = [...value]
|
|
109
|
+
result[index] = next
|
|
110
|
+
const sum = addDecimal(value[index]!, value[neighbor]!),
|
|
111
|
+
peer = items[neighbor]!
|
|
112
|
+
result[neighbor] = snapBoundary(addDecimal(sum, -next), ranges(peer).flat(), sum)
|
|
113
|
+
checkResizableValue(items, result)
|
|
114
|
+
return result
|
|
115
|
+
}
|
package/src/internal/types.ts
CHANGED
|
@@ -2,3 +2,13 @@
|
|
|
2
2
|
export type DistributiveOmit<Value, Keys extends PropertyKey> = Value extends unknown
|
|
3
3
|
? Omit<Value, Keys>
|
|
4
4
|
: never
|
|
5
|
+
|
|
6
|
+
type NoToggle = {
|
|
7
|
+
pressed?: never
|
|
8
|
+
defaultPressed?: never
|
|
9
|
+
onPressedChange?: never
|
|
10
|
+
'aria-pressed'?: never
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Openers and actions are not toggles; `?: never` still lets callers pass `undefined`. */
|
|
14
|
+
export type WithoutToggle<Props> = DistributiveOmit<Props, keyof NoToggle> & NoToggle
|
package/src/themes/components.ts
CHANGED
|
@@ -63,6 +63,16 @@ export const componentRegistry = {
|
|
|
63
63
|
focusWidth: 'css',
|
|
64
64
|
focusOffset: 'css'
|
|
65
65
|
},
|
|
66
|
+
resizable: {
|
|
67
|
+
handleSize: 'css',
|
|
68
|
+
handleColor: 'css',
|
|
69
|
+
handleBackground: 'css',
|
|
70
|
+
handleHoverBackground: 'css',
|
|
71
|
+
handleActiveBackground: 'css',
|
|
72
|
+
focusColor: 'css',
|
|
73
|
+
focusWidth: 'css',
|
|
74
|
+
focusOffset: 'css'
|
|
75
|
+
},
|
|
66
76
|
numberField: { gap: 'css' },
|
|
67
77
|
passwordInput: { gap: 'css' },
|
|
68
78
|
meter: {
|