@justanarthur/modo-ui 2.5.0 → 2.6.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/blocks/desktop-shell/index.tsx +3 -2
- package/components/data-display/diff/index.tsx +5 -4
- package/components/data-display/markdown/index.tsx +6 -6
- package/components/navigation/tabs/list.tsx +1 -5
- package/dist/blocks/desktop-shell/index.js +5 -5
- package/dist/blocks/sidebar-app/index.js +6 -6
- package/dist/components/containers/accordion/index.js +2 -2
- package/dist/components/containers/card/index.js +2 -2
- package/dist/components/data-display/diff/index.d.ts +2 -1
- package/dist/components/data-display/diff/index.js +3 -2
- package/dist/components/data-display/markdown/index.js +5 -5
- package/dist/components/data-display/table/index.js +2 -2
- package/dist/components/inputs/combobox/index.js +3 -2
- package/dist/components/inputs/search/index.js +4 -3
- package/dist/components/inputs/select/index.js +3 -2
- package/dist/components/inputs/textarea/index.js +3 -3
- package/dist/components/navigation/breadcrumb/index.js +4 -4
- package/dist/components/navigation/sidebar/index.js +3 -3
- package/dist/components/navigation/tabs/index.js +1 -1
- package/dist/components/overlays/command/index.js +3 -2
- package/dist/components/overlays/context-menu/index.js +4 -4
- package/dist/components/overlays/dropdown/index.js +3 -3
- package/dist/docs/index.js +4 -4
- package/dist/index.d.ts +15 -7
- package/dist/index.js +22 -22
- package/dist/lib/use-autosize-textarea.d.ts +6 -4
- package/dist/lib/use-autosize-textarea.js +1 -1
- package/dist/primitives/content/code/index.d.ts +3 -1
- package/dist/primitives/content/code/index.js +3 -2
- package/dist/primitives/layout/resizable/index.js +1 -1
- package/dist/primitives/layout/scroll-area/index.d.ts +4 -1
- package/dist/primitives/layout/scroll-area/index.js +2 -1
- package/dist/shared/{components-8xe4h118.js → components-3fg6vabb.js} +1 -4
- package/dist/shared/{components-resqc2d2.js → components-5fet4gqt.js} +59 -7
- package/dist/shared/{components-5w7hxa1n.js → components-60tf8tfa.js} +10 -6
- package/dist/shared/components-7v6ncqfc.js +80 -0
- package/dist/shared/{components-66aw235e.js → components-8swhfkqn.js} +1 -1
- package/dist/shared/{components-pfwjhxd8.js → components-94vd4ck1.js} +1 -1
- package/dist/shared/{components-q28xct6t.js → components-9c3m65ft.js} +1 -1
- package/dist/shared/{components-jnjw9j2z.js → components-a8bcq2yc.js} +1 -1
- package/dist/shared/{components-b2fag579.js → components-bkg1k36x.js} +4 -4
- package/dist/shared/{components-z14s3avn.js → components-faym1xm6.js} +1 -1
- package/dist/shared/{components-gr82tz50.js → components-fbs2602j.js} +4 -3
- package/dist/shared/{components-ypxst3cn.js → components-ftvy33w9.js} +1 -1
- package/dist/shared/{components-8hzwz162.js → components-hhwv5mcm.js} +5 -4
- package/dist/shared/{components-k8awpmbn.js → components-s0c8gngv.js} +6 -6
- package/dist/shared/{components-8dgrpegd.js → components-swh0v27s.js} +4 -2
- package/dist/shared/{components-766w1xcw.js → components-whfr55xn.js} +3 -3
- package/dist/shared/{components-4d0v8nzm.js → components-z6wx8fzj.js} +1 -1
- package/dist/shared/{components-2c22zpm2.js → components-zjeh9zk2.js} +1 -1
- package/dist/styles.css +1 -1
- package/lib/use-autosize-textarea.ts +65 -18
- package/package.json +6 -1
- package/primitives/content/code/index.tsx +11 -6
- package/primitives/layout/resizable/index.tsx +15 -6
- package/primitives/layout/scroll-area/examples.mdx +16 -0
- package/primitives/layout/scroll-area/index.tsx +69 -9
- package/dist/shared/components-vpkh6j83.js +0 -42
- /package/dist/shared/{components-v1zzr668.js → components-arg4h26d.js} +0 -0
- /package/dist/shared/{components-0ep66sg9.js → components-dx8f797z.js} +0 -0
- /package/dist/shared/{components-rtwfh1gc.js → components-fzmjcn38.js} +0 -0
|
@@ -8,10 +8,10 @@ import {
|
|
|
8
8
|
} from "./components-xnp09586.js";
|
|
9
9
|
import {
|
|
10
10
|
Code2
|
|
11
|
-
} from "./components-
|
|
11
|
+
} from "./components-60tf8tfa.js";
|
|
12
12
|
import {
|
|
13
13
|
table_default
|
|
14
|
-
} from "./components-
|
|
14
|
+
} from "./components-dx8f797z.js";
|
|
15
15
|
|
|
16
16
|
// components/data-display/markdown/index.tsx
|
|
17
17
|
import { Lexer } from "marked";
|
|
@@ -236,12 +236,12 @@ function MarkdownProse2({ children, className }) {
|
|
|
236
236
|
});
|
|
237
237
|
}
|
|
238
238
|
var Markdown2 = Object.assign(function Markdown({ children, streaming = false, className }) {
|
|
239
|
-
const
|
|
239
|
+
const blocks = useMemo(() => /* @__PURE__ */ jsx(Blocks, {
|
|
240
|
+
tokens: Lexer.lex(streaming ? settle(children) : children)
|
|
241
|
+
}), [children, streaming]);
|
|
240
242
|
return /* @__PURE__ */ jsx(MarkdownProse2, {
|
|
241
243
|
className,
|
|
242
|
-
children:
|
|
243
|
-
tokens
|
|
244
|
-
})
|
|
244
|
+
children: blocks
|
|
245
245
|
});
|
|
246
246
|
}, { Prose: MarkdownProse2 });
|
|
247
247
|
var markdown_default = Markdown2;
|
|
@@ -14,9 +14,10 @@ import {
|
|
|
14
14
|
} from "./components-xnp09586.js";
|
|
15
15
|
import {
|
|
16
16
|
scroll_area_default
|
|
17
|
-
} from "./components-
|
|
17
|
+
} from "./components-5fet4gqt.js";
|
|
18
18
|
|
|
19
19
|
// components/data-display/diff/index.tsx
|
|
20
|
+
import { useMemo } from "react";
|
|
20
21
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
21
22
|
var ROW = {
|
|
22
23
|
add: "bg-status-success/16",
|
|
@@ -70,7 +71,7 @@ function parsePatch2(patch) {
|
|
|
70
71
|
function Diff2({ patch, path, lineNumbers = true, wrap = false, actions, className }) {
|
|
71
72
|
const level = useLift2(1);
|
|
72
73
|
const FileIcon = useIcon2("file-diff");
|
|
73
|
-
const lines = parsePatch2(patch);
|
|
74
|
+
const lines = useMemo(() => parsePatch2(patch), [patch]);
|
|
74
75
|
const added = lines.filter((l) => l.kind === "add").length;
|
|
75
76
|
const removed = lines.filter((l) => l.kind === "remove").length;
|
|
76
77
|
const body = /* @__PURE__ */ jsx("div", {
|
|
@@ -144,6 +145,7 @@ function Diff2({ patch, path, lineNumbers = true, wrap = false, actions, classNa
|
|
|
144
145
|
]
|
|
145
146
|
}),
|
|
146
147
|
wrap ? body : /* @__PURE__ */ jsx(scroll_area_default, {
|
|
148
|
+
native: true,
|
|
147
149
|
orientation: "horizontal",
|
|
148
150
|
viewportClassName: "scroll-fade-x",
|
|
149
151
|
children: body
|
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
SidebarInput2,
|
|
23
23
|
SidebarTrigger2,
|
|
24
24
|
sidebar_default
|
|
25
|
-
} from "./components-
|
|
25
|
+
} from "./components-bkg1k36x.js";
|
|
26
26
|
import {
|
|
27
27
|
tooltip_default
|
|
28
28
|
} from "./components-7rn454aq.js";
|
|
@@ -31,10 +31,10 @@ import {
|
|
|
31
31
|
DropdownMenu2,
|
|
32
32
|
DropdownTrigger2,
|
|
33
33
|
DropdownContent2
|
|
34
|
-
} from "./components-
|
|
34
|
+
} from "./components-94vd4ck1.js";
|
|
35
35
|
import {
|
|
36
36
|
card_default
|
|
37
|
-
} from "./components-
|
|
37
|
+
} from "./components-fzmjcn38.js";
|
|
38
38
|
import {
|
|
39
39
|
badge_default
|
|
40
40
|
} from "./components-jw45ck66.js";
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
DropdownSubTrigger2,
|
|
19
19
|
DropdownSubContent2,
|
|
20
20
|
DropdownSeparator2
|
|
21
|
-
} from "./components-
|
|
21
|
+
} from "./components-94vd4ck1.js";
|
|
22
22
|
|
|
23
23
|
// components/overlays/context-menu/index.tsx
|
|
24
24
|
import { ContextMenu as ContextMenuPrimitive } from "@base-ui/react/context-menu";
|
package/dist/styles.css
CHANGED
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
}
|
|
63
63
|
/* layer: theme */
|
|
64
64
|
@layer theme{
|
|
65
|
-
:root, :host { --spacing: 0.25rem; --
|
|
65
|
+
:root, :host { --spacing: 0.25rem; --default-transition-timingFunction: cubic-bezier(0.4, 0, 0.2, 1); --default-transition-duration: 150ms; --font-mono: ui-monospace, 'SF Mono', SFMono-Regular, Menlo, Consolas, monospace; --container-sm: 24rem; --ease-out: cubic-bezier(0, 0, 0.2, 1); --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1); --radius-xl: 0.75rem; --leading-relaxed: 1.625; --radius-none: 0; --font-sans: 'Inter Variable', ui-sans-serif, system-ui, sans-serif; --radius-md: 0.375rem; --radius-DEFAULT: 0.25rem; --radius-3xl: 1.5rem; --leading-tight: 1.25; --ease-DEFAULT: cubic-bezier(0.4, 0, 0.2, 1); --radius-xs: 0.125rem; --leading-snug: 1.375; --leading-normal: 1.5; --radius-sm: 0.25rem; --radius-2xl: 1rem; --radius-lg: 0.5rem; --leading-none: 1; --container-2xl: 42rem; --default-font-family: var(--font-sans); --default-monoFont-family: var(--font-mono); }
|
|
66
66
|
}
|
|
67
67
|
/* layer: base */
|
|
68
68
|
@layer base{
|
|
@@ -15,50 +15,97 @@ interface AutosizeRows {
|
|
|
15
15
|
maxRows: number
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
// `field-sizing: content` (WebKit 26, Chromium 123) sizes the box inside the
|
|
19
|
+
// browser's own layout: no measure, no observer.
|
|
20
|
+
const nativeSizing = typeof CSS !== 'undefined' && CSS.supports('field-sizing', 'content')
|
|
21
|
+
|
|
18
22
|
function lineHeightOf(el: HTMLElement) {
|
|
19
23
|
const style = getComputedStyle(el)
|
|
20
24
|
// `line-height: normal` computes to the keyword, which parses to NaN.
|
|
21
25
|
return Number.parseFloat(style.lineHeight) || Number.parseFloat(style.fontSize) * 1.2
|
|
22
26
|
}
|
|
23
27
|
|
|
28
|
+
function fit(el: HTMLTextAreaElement, height: number, max: number) {
|
|
29
|
+
const next = `${Math.min(height, max)}px`
|
|
30
|
+
const overflow = height > max ? 'auto' : 'hidden'
|
|
31
|
+
if (el.style.height !== next) el.style.height = next
|
|
32
|
+
if (el.style.overflowY !== overflow) el.style.overflowY = overflow
|
|
33
|
+
}
|
|
34
|
+
|
|
24
35
|
/**
|
|
25
36
|
* Sizes the textarea to its content between `minRows` and `maxRows`, then
|
|
26
|
-
* scrolls.
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
37
|
+
* scrolls. Where the browser supports `field-sizing: content`, the box sizes
|
|
38
|
+
* itself between a `min-height` and `max-height` in line units. Elsewhere it
|
|
39
|
+
* measures before paint whenever `deps` change (pass the value and anything
|
|
40
|
+
* else that changes the text's height, such as the size step), and when the
|
|
41
|
+
* textarea's width changes. Returns the measure, for a caller that changes
|
|
42
|
+
* the content outside React.
|
|
30
43
|
*/
|
|
31
44
|
export function useAutosizeTextarea(
|
|
32
45
|
ref: RefObject<HTMLTextAreaElement | null>,
|
|
33
46
|
{ minRows, maxRows }: AutosizeRows,
|
|
34
47
|
deps: DependencyList,
|
|
35
48
|
) {
|
|
36
|
-
|
|
49
|
+
// `grow` reads the text's height off the current box, which only holds
|
|
50
|
+
// while the text is at least as tall as the box.
|
|
51
|
+
const measure = useCallback(
|
|
52
|
+
(grow: boolean) => {
|
|
53
|
+
const el = ref.current
|
|
54
|
+
if (!el || nativeSizing) return
|
|
55
|
+
const line = lineHeightOf(el)
|
|
56
|
+
const floor = line * minRows
|
|
57
|
+
const max = line * Math.max(maxRows, minRows)
|
|
58
|
+
// An empty box is one line at most: the floor holds it unmeasured.
|
|
59
|
+
if (el.value === '' && minRows >= 1) return fit(el, floor, max)
|
|
60
|
+
if (!grow) el.style.height = 'auto'
|
|
61
|
+
fit(el, Math.max(el.scrollHeight, floor), max)
|
|
62
|
+
},
|
|
63
|
+
[ref, minRows, maxRows],
|
|
64
|
+
)
|
|
65
|
+
const resize = useCallback(() => measure(false), [measure])
|
|
66
|
+
|
|
67
|
+
useIsoLayoutEffect(() => {
|
|
37
68
|
const el = ref.current
|
|
38
|
-
if (!el) return
|
|
39
|
-
el.style.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
el.style.
|
|
43
|
-
el.style.overflowY = el.scrollHeight > max ? 'auto' : 'hidden'
|
|
69
|
+
if (!el || !nativeSizing) return
|
|
70
|
+
el.style.setProperty('field-sizing', 'content')
|
|
71
|
+
el.style.minHeight = `${minRows}lh`
|
|
72
|
+
el.style.maxHeight = `${Math.max(maxRows, minRows)}lh`
|
|
73
|
+
el.style.overflowY = 'auto'
|
|
44
74
|
}, [ref, minRows, maxRows])
|
|
45
75
|
|
|
46
76
|
useIsoLayoutEffect(resize, [resize, ...deps])
|
|
47
77
|
|
|
48
78
|
// The first measure can run while an ancestor is still at (near-)zero
|
|
49
|
-
// width
|
|
79
|
+
// width, and a pane drag changes the width every frame. Narrower text can
|
|
80
|
+
// only grow, which the box's own scrollHeight shows without a re-layout;
|
|
81
|
+
// wider text may shrink, which needs the full measure, once per frame.
|
|
82
|
+
// Gated on width, so the observer never loops on its own height writes.
|
|
50
83
|
useEffect(() => {
|
|
51
84
|
const el = ref.current
|
|
52
|
-
if (!el) return
|
|
85
|
+
if (!el || nativeSizing) return
|
|
53
86
|
let width = el.offsetWidth
|
|
87
|
+
let frame = 0
|
|
54
88
|
const observer = new ResizeObserver(() => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
89
|
+
const next = el.offsetWidth
|
|
90
|
+
const wider = next > width
|
|
91
|
+
if (next === width) return
|
|
92
|
+
width = next
|
|
93
|
+
if (el.value === '') return
|
|
94
|
+
if (!wider) {
|
|
95
|
+
if (el.scrollHeight > el.clientHeight) measure(true)
|
|
96
|
+
return
|
|
97
|
+
}
|
|
98
|
+
frame ||= requestAnimationFrame(() => {
|
|
99
|
+
frame = 0
|
|
100
|
+
resize()
|
|
101
|
+
})
|
|
58
102
|
})
|
|
59
103
|
observer.observe(el)
|
|
60
|
-
return () =>
|
|
61
|
-
|
|
104
|
+
return () => {
|
|
105
|
+
observer.disconnect()
|
|
106
|
+
cancelAnimationFrame(frame)
|
|
107
|
+
}
|
|
108
|
+
}, [ref, measure, resize])
|
|
62
109
|
|
|
63
110
|
return resize
|
|
64
111
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@justanarthur/modo-ui",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.6.0",
|
|
5
5
|
"description": "Fluid Functionalism (Base UI flavor, MIT © 2026 Micka Touillaud) ported to UnoCSS: motion springs, fluid hover, a two-step size ladder and an eight-level elevated surface system. Documented with modo.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"keywords": [
|
|
@@ -50,6 +50,11 @@
|
|
|
50
50
|
"engines": {
|
|
51
51
|
"node": ">=20"
|
|
52
52
|
},
|
|
53
|
+
"sideEffects": [
|
|
54
|
+
"**/*.css",
|
|
55
|
+
"**/*.ts",
|
|
56
|
+
"**/*.tsx"
|
|
57
|
+
],
|
|
53
58
|
"module": "./dist/index.js",
|
|
54
59
|
"types": "./dist/index.d.ts",
|
|
55
60
|
"exports": {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
|
|
3
|
-
import { Fragment } from 'react'
|
|
3
|
+
import { Fragment, useMemo } from 'react'
|
|
4
4
|
import type { TokenType } from 'sugar-high'
|
|
5
5
|
import { parse } from 'sugar-high/core'
|
|
6
6
|
import { type Language, lang, languages } from 'sugar-high/lang'
|
|
@@ -45,7 +45,9 @@ function highlight(source: string, language: Language['id']) {
|
|
|
45
45
|
*
|
|
46
46
|
* sugar-high tokenizes; each token type takes a `--syntax-*` token from
|
|
47
47
|
* tokens/colors.css, so code follows light and dark like everything else.
|
|
48
|
-
* Long lines scroll sideways under a fading edge instead of wrapping
|
|
48
|
+
* Long lines scroll sideways under a fading edge instead of wrapping, on the
|
|
49
|
+
* platform's own scrollbar (ScrollArea's `native`), so hundreds of blocks
|
|
50
|
+
* cost nothing while their column resizes. It is
|
|
49
51
|
* also the docs chrome's Code slot: every example's source and every fenced
|
|
50
52
|
* block on these pages renders through it.
|
|
51
53
|
*
|
|
@@ -64,17 +66,20 @@ export default function Code({
|
|
|
64
66
|
className?: string
|
|
65
67
|
}) {
|
|
66
68
|
const level = useLift(1)
|
|
67
|
-
const source = children.trim()
|
|
68
69
|
const id = lang(language)
|
|
70
|
+
// The same element on every render, so React skips the token spans.
|
|
71
|
+
const code = useMemo(() => {
|
|
72
|
+
const source = children.trim()
|
|
73
|
+
return <code>{id && id !== 'plaintext' ? highlight(source, id) : source}</code>
|
|
74
|
+
}, [children, id])
|
|
69
75
|
return (
|
|
70
76
|
<ScrollArea
|
|
77
|
+
native
|
|
71
78
|
orientation="horizontal"
|
|
72
79
|
viewportClassName="scroll-fade-x"
|
|
73
80
|
className={cn('rounded-xl', SURFACE_BG[level], className)}
|
|
74
81
|
>
|
|
75
|
-
<pre className="m-0 w-max min-w-full p-4 font-mono text-caption leading-relaxed text-foreground">
|
|
76
|
-
<code>{id && id !== 'plaintext' ? highlight(source, id) : source}</code>
|
|
77
|
-
</pre>
|
|
82
|
+
<pre className="m-0 w-max min-w-full p-4 font-mono text-caption leading-relaxed text-foreground">{code}</pre>
|
|
78
83
|
</ScrollArea>
|
|
79
84
|
)
|
|
80
85
|
}
|
|
@@ -312,16 +312,25 @@ const Resizable = forwardRef<HTMLDivElement, ResizableProps>(
|
|
|
312
312
|
const panels = items.filter(
|
|
313
313
|
(child): child is ReactElement<ResizablePanelProps> => isValidElement(child) && child.type === ResizablePanel,
|
|
314
314
|
)
|
|
315
|
-
const
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
315
|
+
const limitKey = panels.map(({ props }) => `${props.minSize}:${props.maxSize}:${props.collapsible}`).join()
|
|
316
|
+
const limits = useMemo(
|
|
317
|
+
() =>
|
|
318
|
+
panels.map(({ props }) => ({
|
|
319
|
+
min: props.minSize ?? 0,
|
|
320
|
+
max: props.maxSize ?? 100,
|
|
321
|
+
collapsible: props.collapsible ?? false,
|
|
322
|
+
})),
|
|
323
|
+
[limitKey],
|
|
324
|
+
)
|
|
320
325
|
const sizeKey = panels.map(({ props }) => props.defaultSize).join()
|
|
321
326
|
const defaults = useMemo(() => defaultSizes(panels.map(({ props }) => props.defaultSize)), [sizeKey])
|
|
322
327
|
const [current, setCurrent] = useControllableState(sizes, defaults, onSizesChange)
|
|
323
328
|
const [dragging, setDragging] = useState(false)
|
|
324
|
-
|
|
329
|
+
// A new context value walks the whole subtree for consumers, so it changes only with what it holds.
|
|
330
|
+
const group = useMemo(
|
|
331
|
+
() => ({ id, direction, sizes: current, limits, defaults, step, setSizes: setCurrent, dragging, setDragging }),
|
|
332
|
+
[id, direction, current, limits, defaults, step, setCurrent, dragging],
|
|
333
|
+
)
|
|
325
334
|
|
|
326
335
|
let panel = -1
|
|
327
336
|
const indexed = items.map(child => {
|
|
@@ -31,6 +31,22 @@ content keep its natural width instead of squeezing in.
|
|
|
31
31
|
</div>
|
|
32
32
|
</ScrollArea>
|
|
33
33
|
|
|
34
|
+
# Native
|
|
35
|
+
|
|
36
|
+
`native` scrolls on the platform's own scrollbar (an overlay one on macOS)
|
|
37
|
+
with no observers behind it, for scrollers that come by the hundred: every
|
|
38
|
+
Code block is one. The fade stays the same.
|
|
39
|
+
|
|
40
|
+
<ScrollArea native orientation="horizontal" viewportClassName="scroll-fade-x" className="w-full">
|
|
41
|
+
<div className="flex gap-2 p-3 w-max">
|
|
42
|
+
{['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'].map((month) => (
|
|
43
|
+
<div key={month} className="flex items-center justify-center h-20 w-28 shrink-0 border border-border rounded-lg text-body text-foreground">
|
|
44
|
+
{month}
|
|
45
|
+
</div>
|
|
46
|
+
))}
|
|
47
|
+
</div>
|
|
48
|
+
</ScrollArea>
|
|
49
|
+
|
|
34
50
|
# Double overflow
|
|
35
51
|
|
|
36
52
|
A grid taller and wider than its box. `orientation="both"` adds both
|
|
@@ -17,8 +17,10 @@ import {
|
|
|
17
17
|
type ReactNode,
|
|
18
18
|
type RefAttributes,
|
|
19
19
|
useContext,
|
|
20
|
+
useRef,
|
|
20
21
|
} from 'react'
|
|
21
22
|
import { useShape } from '../../../lib/shape-context'
|
|
23
|
+
import { useIsoLayoutEffect } from '../../../lib/use-iso-layout-effect'
|
|
22
24
|
import { useTouchPrimary } from '../../../lib/use-touch-primary'
|
|
23
25
|
import { cn } from '../../../lib/utils'
|
|
24
26
|
|
|
@@ -42,10 +44,56 @@ if (typeof CSS !== 'undefined' && 'registerProperty' in CSS) {
|
|
|
42
44
|
}
|
|
43
45
|
}
|
|
44
46
|
|
|
45
|
-
// Touch-primary devices get native overflow scrolling
|
|
46
|
-
// rubber-banding); the exported ScrollBar no-ops there.
|
|
47
|
+
// Touch-primary devices and `native` areas get native overflow scrolling
|
|
48
|
+
// (momentum, rubber-banding); the exported ScrollBar no-ops there.
|
|
47
49
|
const ScrollAreaContext = createContext<boolean>(false)
|
|
48
50
|
|
|
51
|
+
// A native viewport writes the same `--scroll-area-overflow-*` edges Base UI
|
|
52
|
+
// does, so `scroll-fade` reads them instead of running a scroll-driven
|
|
53
|
+
// animation per area (WebKit ticks every one each frame). One observer serves
|
|
54
|
+
// every native area, and a var is written only when its edge moved.
|
|
55
|
+
const viewportOf = new WeakMap<Element, HTMLElement>()
|
|
56
|
+
let edgeObserver: ResizeObserver | undefined
|
|
57
|
+
|
|
58
|
+
function setEdge(viewport: HTMLElement, edge: string, distance: number) {
|
|
59
|
+
const name = `--scroll-area-overflow-${edge}`
|
|
60
|
+
const value = `${Math.max(0, Math.round(distance))}px`
|
|
61
|
+
if (viewport.style.getPropertyValue(name) !== value) viewport.style.setProperty(name, value)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function writeEdges(viewport: HTMLElement) {
|
|
65
|
+
const { scrollLeft, scrollTop, scrollWidth, scrollHeight, clientWidth, clientHeight } = viewport
|
|
66
|
+
setEdge(viewport, 'x-start', scrollLeft)
|
|
67
|
+
setEdge(viewport, 'x-end', scrollWidth - clientWidth - scrollLeft)
|
|
68
|
+
setEdge(viewport, 'y-start', scrollTop)
|
|
69
|
+
setEdge(viewport, 'y-end', scrollHeight - clientHeight - scrollTop)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function trackEdges(viewport: HTMLElement) {
|
|
73
|
+
edgeObserver ??= new ResizeObserver(entries => {
|
|
74
|
+
const seen = new Set<HTMLElement>()
|
|
75
|
+
for (const { target } of entries) {
|
|
76
|
+
const area = viewportOf.get(target)
|
|
77
|
+
if (!area || seen.has(area)) continue
|
|
78
|
+
seen.add(area)
|
|
79
|
+
writeEdges(area)
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
const observer = edgeObserver
|
|
83
|
+
// The viewport for its own size, its children for the content's.
|
|
84
|
+
const targets = [viewport, ...viewport.children]
|
|
85
|
+
for (const target of targets) {
|
|
86
|
+
viewportOf.set(target, viewport)
|
|
87
|
+
observer.observe(target)
|
|
88
|
+
}
|
|
89
|
+
const onScroll = () => writeEdges(viewport)
|
|
90
|
+
viewport.addEventListener('scroll', onScroll, { passive: true })
|
|
91
|
+
return () => {
|
|
92
|
+
for (const target of targets) observer.unobserve(target)
|
|
93
|
+
viewport.removeEventListener('scroll', onScroll)
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
49
97
|
type Orientation = 'vertical' | 'horizontal' | 'both'
|
|
50
98
|
|
|
51
99
|
interface ScrollAreaProps extends ComponentPropsWithoutRef<'div'> {
|
|
@@ -53,6 +101,8 @@ interface ScrollAreaProps extends ComponentPropsWithoutRef<'div'> {
|
|
|
53
101
|
viewportClassName?: string
|
|
54
102
|
/** Which axes get scrollbars. Defaults to `"vertical"`. */
|
|
55
103
|
orientation?: Orientation
|
|
104
|
+
/** Native overflow scrolling with the platform's own scrollbar (an overlay one on macOS), as on touch: no observers and no re-render on resize, for scrollers that come by the hundred, such as code blocks. Defaults to `false`. */
|
|
105
|
+
native?: boolean
|
|
56
106
|
/** Classes for the outer container — set the height/width constraint here. */
|
|
57
107
|
className?: string
|
|
58
108
|
/** The scrolling content. Give it an intrinsic size (`w-max`, `whitespace-nowrap`) to overflow horizontally. */
|
|
@@ -75,7 +125,8 @@ type ScrollAreaComponent = ForwardRefExoticComponent<ScrollAreaProps & RefAttrib
|
|
|
75
125
|
* goes on the inner scrolling viewport, where the `scroll-fade` (or
|
|
76
126
|
* `scroll-fade-x`) utility dissolves the edges that have more to scroll. On
|
|
77
127
|
* touch-primary devices the whole thing steps aside for native overflow
|
|
78
|
-
* scrolling
|
|
128
|
+
* scrolling, and `native` does the same anywhere: the fade stays (it is
|
|
129
|
+
* CSS), the drawn thumb gives way to the platform's. Built on Base UI's ScrollArea; scrollbar machinery adapted from
|
|
79
130
|
* Lina (https://lina.sameer.sh).
|
|
80
131
|
*
|
|
81
132
|
* Statics:
|
|
@@ -87,12 +138,19 @@ type ScrollAreaComponent = ForwardRefExoticComponent<ScrollAreaProps & RefAttrib
|
|
|
87
138
|
* @license MIT © 2026 Micka Touillaud
|
|
88
139
|
*/
|
|
89
140
|
const ScrollArea = forwardRef<HTMLDivElement, ScrollAreaProps>(
|
|
90
|
-
({ className, children, viewportClassName, orientation = 'vertical', ...props }, ref) => {
|
|
91
|
-
const
|
|
141
|
+
({ className, children, viewportClassName, orientation = 'vertical', native = false, ...props }, ref) => {
|
|
142
|
+
const isNative = useTouchPrimary() || native
|
|
143
|
+
const viewportRef = useRef<HTMLDivElement>(null)
|
|
144
|
+
|
|
145
|
+
// Re-tracked when the children change, so new content is observed.
|
|
146
|
+
useIsoLayoutEffect(() => {
|
|
147
|
+
const viewport = viewportRef.current
|
|
148
|
+
if (isNative && viewport) return trackEdges(viewport)
|
|
149
|
+
}, [isNative, children])
|
|
92
150
|
|
|
93
151
|
return (
|
|
94
|
-
<ScrollAreaContext.Provider value={
|
|
95
|
-
{
|
|
152
|
+
<ScrollAreaContext.Provider value={isNative}>
|
|
153
|
+
{isNative ? (
|
|
96
154
|
// biome-ignore lint/a11y/useSemanticElements: a scroll container, not a form group
|
|
97
155
|
<div
|
|
98
156
|
ref={ref}
|
|
@@ -103,7 +161,9 @@ const ScrollArea = forwardRef<HTMLDivElement, ScrollAreaProps>(
|
|
|
103
161
|
{...props}
|
|
104
162
|
>
|
|
105
163
|
<div
|
|
164
|
+
ref={viewportRef}
|
|
106
165
|
data-slot="scroll-area-viewport"
|
|
166
|
+
data-scroll-edges=""
|
|
107
167
|
className={cn(
|
|
108
168
|
'size-full rounded-[inherit]',
|
|
109
169
|
orientation === 'vertical' && 'overflow-y-auto',
|
|
@@ -148,10 +208,10 @@ const ScrollBar = forwardRef<
|
|
|
148
208
|
ComponentRef<typeof ScrollAreaPrimitive.Scrollbar>,
|
|
149
209
|
ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.Scrollbar>
|
|
150
210
|
>(({ className, orientation = 'vertical', ...props }, ref) => {
|
|
151
|
-
const
|
|
211
|
+
const isNative = useContext(ScrollAreaContext)
|
|
152
212
|
const shape = useShape()
|
|
153
213
|
|
|
154
|
-
if (
|
|
214
|
+
if (isNative) return null
|
|
155
215
|
|
|
156
216
|
return (
|
|
157
217
|
<ScrollAreaPrimitive.Scrollbar
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
useIsoLayoutEffect2
|
|
5
|
-
} from "./components-v2j3jx89.js";
|
|
6
|
-
|
|
7
|
-
// lib/use-autosize-textarea.ts
|
|
8
|
-
import { useCallback, useEffect } from "react";
|
|
9
|
-
function lineHeightOf(el) {
|
|
10
|
-
const style = getComputedStyle(el);
|
|
11
|
-
return Number.parseFloat(style.lineHeight) || Number.parseFloat(style.fontSize) * 1.2;
|
|
12
|
-
}
|
|
13
|
-
function useAutosizeTextarea2(ref, { minRows, maxRows }, deps) {
|
|
14
|
-
const resize = useCallback(() => {
|
|
15
|
-
const el = ref.current;
|
|
16
|
-
if (!el)
|
|
17
|
-
return;
|
|
18
|
-
el.style.height = "auto";
|
|
19
|
-
const line = lineHeightOf(el);
|
|
20
|
-
const max = line * Math.max(maxRows, minRows);
|
|
21
|
-
el.style.height = `${Math.min(Math.max(el.scrollHeight, line * minRows), max)}px`;
|
|
22
|
-
el.style.overflowY = el.scrollHeight > max ? "auto" : "hidden";
|
|
23
|
-
}, [ref, minRows, maxRows]);
|
|
24
|
-
useIsoLayoutEffect2(resize, [resize, ...deps]);
|
|
25
|
-
useEffect(() => {
|
|
26
|
-
const el = ref.current;
|
|
27
|
-
if (!el)
|
|
28
|
-
return;
|
|
29
|
-
let width = el.offsetWidth;
|
|
30
|
-
const observer = new ResizeObserver(() => {
|
|
31
|
-
if (el.offsetWidth === width)
|
|
32
|
-
return;
|
|
33
|
-
width = el.offsetWidth;
|
|
34
|
-
resize();
|
|
35
|
-
});
|
|
36
|
-
observer.observe(el);
|
|
37
|
-
return () => observer.disconnect();
|
|
38
|
-
}, [ref, resize]);
|
|
39
|
-
return resize;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export { useAutosizeTextarea2 };
|
|
File without changes
|
|
File without changes
|
|
File without changes
|