@justanarthur/modo-ui 2.4.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.
Files changed (62) hide show
  1. package/blocks/desktop-shell/index.tsx +3 -2
  2. package/components/data-display/diff/index.tsx +5 -4
  3. package/components/data-display/markdown/index.tsx +6 -6
  4. package/components/navigation/sidebar/index.tsx +48 -1
  5. package/components/navigation/tabs/list.tsx +1 -5
  6. package/dist/blocks/desktop-shell/index.js +5 -5
  7. package/dist/blocks/sidebar-app/index.js +6 -6
  8. package/dist/components/containers/accordion/index.js +2 -2
  9. package/dist/components/containers/card/index.js +2 -2
  10. package/dist/components/data-display/diff/index.d.ts +2 -1
  11. package/dist/components/data-display/diff/index.js +3 -2
  12. package/dist/components/data-display/markdown/index.js +5 -5
  13. package/dist/components/data-display/table/index.js +2 -2
  14. package/dist/components/inputs/combobox/index.js +3 -2
  15. package/dist/components/inputs/search/index.js +4 -3
  16. package/dist/components/inputs/select/index.js +3 -2
  17. package/dist/components/inputs/textarea/index.js +3 -3
  18. package/dist/components/navigation/breadcrumb/index.js +4 -4
  19. package/dist/components/navigation/sidebar/index.js +3 -3
  20. package/dist/components/navigation/tabs/index.js +1 -1
  21. package/dist/components/overlays/command/index.js +3 -2
  22. package/dist/components/overlays/context-menu/index.js +4 -4
  23. package/dist/components/overlays/dropdown/index.js +3 -3
  24. package/dist/docs/index.js +4 -4
  25. package/dist/index.d.ts +15 -7
  26. package/dist/index.js +22 -22
  27. package/dist/lib/use-autosize-textarea.d.ts +6 -4
  28. package/dist/lib/use-autosize-textarea.js +1 -1
  29. package/dist/primitives/content/code/index.d.ts +3 -1
  30. package/dist/primitives/content/code/index.js +3 -2
  31. package/dist/primitives/layout/resizable/index.js +1 -1
  32. package/dist/primitives/layout/scroll-area/index.d.ts +4 -1
  33. package/dist/primitives/layout/scroll-area/index.js +2 -1
  34. package/dist/shared/{components-8xe4h118.js → components-3fg6vabb.js} +1 -4
  35. package/dist/shared/{components-esy5nsvc.js → components-5fet4gqt.js} +71 -7
  36. package/dist/shared/{components-y4gsk1jt.js → components-60tf8tfa.js} +10 -6
  37. package/dist/shared/components-7v6ncqfc.js +80 -0
  38. package/dist/shared/{components-sh8j39z3.js → components-8swhfkqn.js} +1 -1
  39. package/dist/shared/{components-pwsqp2np.js → components-94vd4ck1.js} +1 -1
  40. package/dist/shared/{components-rgdspnth.js → components-9c3m65ft.js} +1 -1
  41. package/dist/shared/{components-xq8j9c2f.js → components-a8bcq2yc.js} +1 -1
  42. package/dist/shared/{components-cc9kfhkb.js → components-bkg1k36x.js} +46 -11
  43. package/dist/shared/{components-qmkfpcw0.js → components-faym1xm6.js} +1 -1
  44. package/dist/shared/{components-gr82tz50.js → components-fbs2602j.js} +4 -3
  45. package/dist/shared/{components-ypxst3cn.js → components-ftvy33w9.js} +1 -1
  46. package/dist/shared/{components-0bvxny7s.js → components-hhwv5mcm.js} +5 -4
  47. package/dist/shared/{components-pw6gzev8.js → components-s0c8gngv.js} +6 -6
  48. package/dist/shared/{components-fv9y76b0.js → components-swh0v27s.js} +4 -2
  49. package/dist/shared/{components-s0megs1g.js → components-whfr55xn.js} +3 -3
  50. package/dist/shared/{components-greka6z2.js → components-z6wx8fzj.js} +1 -1
  51. package/dist/shared/{components-hjdv4y8d.js → components-zjeh9zk2.js} +1 -1
  52. package/dist/styles.css +2 -1
  53. package/lib/use-autosize-textarea.ts +65 -18
  54. package/package.json +6 -1
  55. package/primitives/content/code/index.tsx +11 -6
  56. package/primitives/layout/resizable/index.tsx +15 -6
  57. package/primitives/layout/scroll-area/examples.mdx +16 -0
  58. package/primitives/layout/scroll-area/index.tsx +89 -9
  59. package/dist/shared/components-vpkh6j83.js +0 -42
  60. /package/dist/shared/{components-v1zzr668.js → components-arg4h26d.js} +0 -0
  61. /package/dist/shared/{components-0ep66sg9.js → components-dx8f797z.js} +0 -0
  62. /package/dist/shared/{components-rtwfh1gc.js → components-fzmjcn38.js} +0 -0
@@ -17,15 +17,83 @@ 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
 
25
- // Touch-primary devices get native overflow scrolling (momentum,
26
- // rubber-banding); the exported ScrollBar no-ops there.
27
+ // Base UI writes the edge distances (`--scroll-area-overflow-*`) on the
28
+ // viewport at every scroll event and registers them non-inherited, except in
29
+ // WebKit, where an inherited var re-styles every descendant per event: a long
30
+ // list recalculated thousands of elements a frame. Only the viewport reads
31
+ // them (`scroll-fade`), so they are registered for WebKit too.
32
+ if (typeof CSS !== 'undefined' && 'registerProperty' in CSS) {
33
+ for (const edge of ['x-start', 'x-end', 'y-start', 'y-end']) {
34
+ try {
35
+ CSS.registerProperty({
36
+ name: `--scroll-area-overflow-${edge}`,
37
+ syntax: '<length>',
38
+ inherits: false,
39
+ initialValue: '0px',
40
+ })
41
+ } catch {
42
+ // Already registered.
43
+ }
44
+ }
45
+ }
46
+
47
+ // Touch-primary devices and `native` areas get native overflow scrolling
48
+ // (momentum, rubber-banding); the exported ScrollBar no-ops there.
27
49
  const ScrollAreaContext = createContext<boolean>(false)
28
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
+
29
97
  type Orientation = 'vertical' | 'horizontal' | 'both'
30
98
 
31
99
  interface ScrollAreaProps extends ComponentPropsWithoutRef<'div'> {
@@ -33,6 +101,8 @@ interface ScrollAreaProps extends ComponentPropsWithoutRef<'div'> {
33
101
  viewportClassName?: string
34
102
  /** Which axes get scrollbars. Defaults to `"vertical"`. */
35
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
36
106
  /** Classes for the outer container — set the height/width constraint here. */
37
107
  className?: string
38
108
  /** The scrolling content. Give it an intrinsic size (`w-max`, `whitespace-nowrap`) to overflow horizontally. */
@@ -55,7 +125,8 @@ type ScrollAreaComponent = ForwardRefExoticComponent<ScrollAreaProps & RefAttrib
55
125
  * goes on the inner scrolling viewport, where the `scroll-fade` (or
56
126
  * `scroll-fade-x`) utility dissolves the edges that have more to scroll. On
57
127
  * touch-primary devices the whole thing steps aside for native overflow
58
- * scrolling. Built on Base UI's ScrollArea; scrollbar machinery adapted from
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
59
130
  * Lina (https://lina.sameer.sh).
60
131
  *
61
132
  * Statics:
@@ -67,12 +138,19 @@ type ScrollAreaComponent = ForwardRefExoticComponent<ScrollAreaProps & RefAttrib
67
138
  * @license MIT © 2026 Micka Touillaud
68
139
  */
69
140
  const ScrollArea = forwardRef<HTMLDivElement, ScrollAreaProps>(
70
- ({ className, children, viewportClassName, orientation = 'vertical', ...props }, ref) => {
71
- const isTouch = useTouchPrimary()
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])
72
150
 
73
151
  return (
74
- <ScrollAreaContext.Provider value={isTouch}>
75
- {isTouch ? (
152
+ <ScrollAreaContext.Provider value={isNative}>
153
+ {isNative ? (
76
154
  // biome-ignore lint/a11y/useSemanticElements: a scroll container, not a form group
77
155
  <div
78
156
  ref={ref}
@@ -83,7 +161,9 @@ const ScrollArea = forwardRef<HTMLDivElement, ScrollAreaProps>(
83
161
  {...props}
84
162
  >
85
163
  <div
164
+ ref={viewportRef}
86
165
  data-slot="scroll-area-viewport"
166
+ data-scroll-edges=""
87
167
  className={cn(
88
168
  'size-full rounded-[inherit]',
89
169
  orientation === 'vertical' && 'overflow-y-auto',
@@ -128,10 +208,10 @@ const ScrollBar = forwardRef<
128
208
  ComponentRef<typeof ScrollAreaPrimitive.Scrollbar>,
129
209
  ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.Scrollbar>
130
210
  >(({ className, orientation = 'vertical', ...props }, ref) => {
131
- const isTouch = useContext(ScrollAreaContext)
211
+ const isNative = useContext(ScrollAreaContext)
132
212
  const shape = useShape()
133
213
 
134
- if (isTouch) return null
214
+ if (isNative) return null
135
215
 
136
216
  return (
137
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 };