@justanarthur/modo-ui 2.3.0 → 2.5.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/components/data-display/diff/index.tsx +19 -3
- package/components/inputs/choice-list/index.tsx +4 -3
- package/components/navigation/sidebar/index.tsx +48 -1
- package/components/navigation/sidebar/menu-scope.tsx +142 -53
- package/components/navigation/sidebar/sidebar-menu-actions.tsx +5 -5
- package/components/navigation/sidebar/sidebar-menu-button.tsx +4 -7
- package/components/navigation/sidebar/sidebar-menu-item.tsx +39 -36
- package/components/navigation/sidebar/sidebar-menu-sub.tsx +3 -2
- package/components/overlays/command/index.tsx +70 -12
- package/components/overlays/dropdown/menu-popup.tsx +11 -2
- package/components/overlays/tooltip/index.tsx +9 -1
- package/dist/blocks/desktop-shell/index.js +11 -11
- package/dist/blocks/sidebar-app/index.js +14 -14
- package/dist/components/actions/copy/index.js +3 -3
- package/dist/components/containers/accordion/index.js +5 -5
- package/dist/components/containers/card/index.js +4 -4
- package/dist/components/data-display/diff/index.d.ts +1 -1
- package/dist/components/data-display/diff/index.js +2 -2
- package/dist/components/data-display/markdown/index.js +7 -7
- package/dist/components/data-display/table/index.js +4 -4
- package/dist/components/inputs/checkbox/index.js +6 -6
- package/dist/components/inputs/choice-list/index.js +5 -5
- package/dist/components/inputs/color-picker/index.js +7 -7
- package/dist/components/inputs/combobox/index.js +7 -7
- package/dist/components/inputs/date-time/calendar/index.js +5 -5
- package/dist/components/inputs/date-time/date-picker/index.js +12 -12
- package/dist/components/inputs/date-time/date-range-picker/index.js +12 -12
- package/dist/components/inputs/date-time/duration-picker/index.js +11 -11
- package/dist/components/inputs/date-time/month-picker/index.js +10 -10
- package/dist/components/inputs/date-time/time-picker/index.js +11 -11
- package/dist/components/inputs/input/index.js +2 -2
- package/dist/components/inputs/key-value/index.js +3 -3
- package/dist/components/inputs/number-input/index.js +3 -3
- package/dist/components/inputs/radio/index.js +5 -5
- package/dist/components/inputs/search/index.js +8 -8
- package/dist/components/inputs/select/index.js +7 -7
- package/dist/components/inputs/switch/index.js +4 -4
- package/dist/components/navigation/breadcrumb/index.js +9 -9
- package/dist/components/navigation/navigation-menu/index.js +6 -6
- package/dist/components/navigation/pagination/index.js +5 -5
- package/dist/components/navigation/sidebar/index.js +10 -10
- package/dist/components/navigation/tabs/index.js +4 -4
- package/dist/components/navigation/tree/index.js +5 -5
- package/dist/components/overlays/alert-dialog/index.js +3 -3
- package/dist/components/overlays/command/index.d.ts +6 -3
- package/dist/components/overlays/command/index.js +7 -7
- package/dist/components/overlays/context-menu/index.js +9 -9
- package/dist/components/overlays/dialog/index.js +2 -2
- package/dist/components/overlays/dropdown/index.js +8 -8
- package/dist/components/overlays/popover/index.js +2 -2
- package/dist/components/overlays/preview-card/index.js +2 -2
- package/dist/components/overlays/sheet/index.js +3 -3
- package/dist/components/overlays/tooltip/index.js +2 -2
- package/dist/docs/index.js +11 -11
- package/dist/index.d.ts +12 -6
- package/dist/index.js +55 -55
- package/dist/lib/fluid-hover-highlight.js +3 -2
- package/dist/lib/focus-ring.d.ts +5 -2
- package/dist/lib/focus-ring.js +2 -1
- package/dist/lib/goo-indicator.d.ts +5 -2
- package/dist/lib/goo-indicator.js +2 -1
- package/dist/lib/overlay.d.ts +8 -1
- package/dist/lib/overlay.js +3 -1
- package/dist/lib/scroll-column.js +4 -4
- package/dist/lib/use-fluid-hover.d.ts +3 -1
- package/dist/lib/use-fluid-hover.js +3 -1
- package/dist/lib/use-merge-split.js +3 -2
- package/dist/primitives/content/code/index.js +2 -2
- package/dist/primitives/layout/scroll-area/index.js +1 -1
- package/dist/primitives/systems/fluid-hover/index.js +4 -4
- package/dist/shared/{components-7xc2dne4.js → components-0ep66sg9.js} +5 -5
- package/dist/shared/{components-agjpst9b.js → components-0v4jxw7z.js} +1 -1
- package/dist/shared/{components-a3brpprb.js → components-1qw8hqwq.js} +7 -7
- package/dist/shared/{components-7c4a0egq.js → components-21hcwp85.js} +78 -43
- package/dist/shared/{components-fjg4j430.js → components-2c22zpm2.js} +2 -2
- package/dist/shared/{components-kz6ak6kj.js → components-3qcgeay1.js} +2 -2
- package/dist/shared/{components-8ybvpebx.js → components-4d0v8nzm.js} +59 -19
- package/dist/shared/{components-e52xgvd9.js → components-4fay97sm.js} +7 -7
- package/dist/shared/{components-fxw1122w.js → components-4fhjk3jz.js} +2 -2
- package/dist/shared/{components-czvraaw9.js → components-4m9stj7d.js} +10 -10
- package/dist/shared/{components-y4gsk1jt.js → components-5w7hxa1n.js} +1 -1
- package/dist/shared/{components-c515d6xr.js → components-5wykqxph.js} +6 -1
- package/dist/shared/{components-7g2q2ccp.js → components-66aw235e.js} +6 -6
- package/dist/shared/{components-z87sanbc.js → components-766w1xcw.js} +4 -4
- package/dist/shared/{components-8e0fjgm9.js → components-7rn454aq.js} +11 -2
- package/dist/shared/{components-2tw25pk6.js → components-895m1f3s.js} +7 -7
- package/dist/shared/{components-h8v9nh5r.js → components-8dgrpegd.js} +16 -4
- package/dist/shared/{components-m7d7r3r8.js → components-8hzwz162.js} +2 -2
- package/dist/shared/{components-b7p1pjcm.js → components-8m5e493q.js} +1 -1
- package/dist/shared/{components-rzy6h7s4.js → components-8nnhzeb3.js} +5 -5
- package/dist/shared/{components-1hga6pkn.js → components-8xe4h118.js} +5 -5
- package/dist/shared/{components-83jn0raj.js → components-9am5511q.js} +3 -3
- package/dist/shared/{components-g35n8tzm.js → components-9b2m90st.js} +1 -1
- package/dist/shared/{components-2bq4ng4d.js → components-9yrajpy0.js} +1 -1
- package/dist/shared/{components-mvwf8ckh.js → components-ac0x7zpq.js} +2 -2
- package/dist/shared/{components-q7zk70tx.js → components-af44r4y9.js} +1 -1
- package/dist/shared/{components-2v4mmw1s.js → components-b2fag579.js} +212 -121
- package/dist/shared/{components-ex2xtqv7.js → components-br6t88cb.js} +1 -1
- package/dist/shared/{components-z0kz9rxj.js → components-bxqmbcz2.js} +6 -2
- package/dist/shared/{components-e7zxwja1.js → components-d4gkhy26.js} +1 -1
- package/dist/shared/{components-w1ysefg1.js → components-eawe4nxm.js} +1 -1
- package/dist/shared/{components-1sbnbq6a.js → components-fpgfs01m.js} +1 -1
- package/dist/shared/{components-tcm3k3wj.js → components-ft5dgjg6.js} +9 -2
- package/dist/shared/{components-6g8a5nrs.js → components-fymenepq.js} +7 -7
- package/dist/shared/{components-k2gg1agj.js → components-gzve0nkp.js} +4 -4
- package/dist/shared/{components-k25zw9g8.js → components-hjk6dwsp.js} +1 -1
- package/dist/shared/{components-6xtntksc.js → components-jnjw9j2z.js} +9 -9
- package/dist/shared/{components-9rebr89j.js → components-k8awpmbn.js} +2 -2
- package/dist/shared/{components-4fswe4kh.js → components-mb80a9wg.js} +1 -1
- package/dist/shared/{components-nh05qz8b.js → components-mzdbtgvz.js} +8 -8
- package/dist/shared/{components-x5v7e0fz.js → components-nmbcfwx8.js} +7 -7
- package/dist/shared/{components-01e24999.js → components-pfwjhxd8.js} +21 -11
- package/dist/shared/{components-nred2e6g.js → components-q28xct6t.js} +2 -2
- package/dist/shared/{components-etgpz4zk.js → components-qrtcc8aw.js} +3 -3
- package/dist/shared/{components-esy5nsvc.js → components-resqc2d2.js} +12 -0
- package/dist/shared/{components-gnsvnejm.js → components-rtwfh1gc.js} +2 -2
- package/dist/shared/{components-vykcfb5r.js → components-v1zzr668.js} +3 -3
- package/dist/shared/{components-5vezp3e5.js → components-vcmky8ns.js} +6 -6
- package/dist/shared/{components-27fatggq.js → components-y9se9mx5.js} +3 -3
- package/dist/shared/{components-9ca0c92a.js → components-yfx0skxc.js} +1 -1
- package/dist/shared/{components-eebf7f9c.js → components-z14s3avn.js} +9 -9
- package/dist/shared/{components-ta4e10mx.js → components-zckgawt6.js} +5 -5
- package/dist/styles.css +2 -1
- package/lib/focus-ring.tsx +15 -8
- package/lib/goo-indicator.tsx +20 -8
- package/lib/overlay.tsx +22 -1
- package/lib/use-fluid-hover.ts +96 -72
- package/package.json +1 -1
- package/primitives/layout/scroll-area/index.tsx +20 -0
package/lib/focus-ring.tsx
CHANGED
|
@@ -6,10 +6,11 @@
|
|
|
6
6
|
'use client'
|
|
7
7
|
|
|
8
8
|
import { AnimatePresence, motion } from 'motion/react'
|
|
9
|
+
import { memo } from 'react'
|
|
9
10
|
import { useReduceMotion } from './reduced-motion'
|
|
10
11
|
import { useShape } from './shape-context'
|
|
11
12
|
import { spring } from './springs'
|
|
12
|
-
import type
|
|
13
|
+
import { type ItemRect, sameRect } from './use-fluid-hover'
|
|
13
14
|
import { cn } from './utils'
|
|
14
15
|
|
|
15
16
|
interface FocusRingProps {
|
|
@@ -21,13 +22,7 @@ interface FocusRingProps {
|
|
|
21
22
|
className?: string
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
* A 1px `focus-ring` border drawn 2px outside the focused row. It springs
|
|
26
|
-
* between rows on `spring.fast` (jumps under reduced motion) and fades out
|
|
27
|
-
* when focus leaves. Render it inside the rows' `relative` container, above
|
|
28
|
-
* the hover highlight.
|
|
29
|
-
*/
|
|
30
|
-
export function FocusRing({ rect, instant = false, className }: FocusRingProps) {
|
|
25
|
+
function FocusRingBase({ rect, instant = false, className }: FocusRingProps) {
|
|
31
26
|
const shape = useShape()
|
|
32
27
|
const reduceMotion = useReduceMotion()
|
|
33
28
|
const jump = instant || reduceMotion
|
|
@@ -47,3 +42,15 @@ export function FocusRing({ rect, instant = false, className }: FocusRingProps)
|
|
|
47
42
|
</AnimatePresence>
|
|
48
43
|
)
|
|
49
44
|
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* A 1px `focus-ring` border drawn 2px outside the focused row. It springs
|
|
48
|
+
* between rows on `spring.fast` (jumps under reduced motion) and fades out
|
|
49
|
+
* when focus leaves. Render it inside the rows' `relative` container, above
|
|
50
|
+
* the hover highlight. Skips the render while its box and props hold (rects
|
|
51
|
+
* are fresh objects on every list render).
|
|
52
|
+
*/
|
|
53
|
+
export const FocusRing = memo(
|
|
54
|
+
FocusRingBase,
|
|
55
|
+
(a, b) => sameRect(a.rect, b.rect) && a.instant === b.instant && a.className === b.className,
|
|
56
|
+
)
|
package/lib/goo-indicator.tsx
CHANGED
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
'use client'
|
|
23
23
|
|
|
24
24
|
import { animate, motion, type Transition, useMotionValue, type ValueAnimationTransition } from 'motion/react'
|
|
25
|
-
import { type ReactNode, useId, useLayoutEffect, useRef, useState } from 'react'
|
|
25
|
+
import { memo, type ReactNode, useId, useLayoutEffect, useRef, useState } from 'react'
|
|
26
26
|
import { useReduceMotion } from './reduced-motion'
|
|
27
27
|
import { spring } from './springs'
|
|
28
|
-
import type
|
|
28
|
+
import { type ItemRect, sameRect } from './use-fluid-hover'
|
|
29
29
|
import { GOO_BLUR_RATIO, GOO_MATRIX } from './use-morph'
|
|
30
30
|
import { cn } from './utils'
|
|
31
31
|
|
|
@@ -161,12 +161,7 @@ interface GooIndicatorProps {
|
|
|
161
161
|
opacity?: number
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
-
|
|
165
|
-
* An indicator that travels between items with a liquid neck. Render it in the
|
|
166
|
-
* items' `relative` container, beneath them: the items' text stays above it,
|
|
167
|
-
* unfiltered.
|
|
168
|
-
*/
|
|
169
|
-
export function GooIndicator({
|
|
164
|
+
function GooIndicatorBase({
|
|
170
165
|
rect,
|
|
171
166
|
from,
|
|
172
167
|
className,
|
|
@@ -259,5 +254,22 @@ export function GooIndicator({
|
|
|
259
254
|
)
|
|
260
255
|
}
|
|
261
256
|
|
|
257
|
+
/**
|
|
258
|
+
* An indicator that travels between items with a liquid neck. Render it in the
|
|
259
|
+
* items' `relative` container, beneath them: the items' text stays above it,
|
|
260
|
+
* unfiltered. Its list re-renders on every hover; an indicator whose box did
|
|
261
|
+
* not move skips the render (rects are fresh objects each time).
|
|
262
|
+
*/
|
|
263
|
+
export const GooIndicator = memo(
|
|
264
|
+
GooIndicatorBase,
|
|
265
|
+
(a, b) =>
|
|
266
|
+
sameRect(a.rect, b.rect) &&
|
|
267
|
+
sameRect(a.from, b.from) &&
|
|
268
|
+
a.className === b.className &&
|
|
269
|
+
a.shadow === b.shadow &&
|
|
270
|
+
a.transition === b.transition &&
|
|
271
|
+
a.opacity === b.opacity,
|
|
272
|
+
)
|
|
273
|
+
|
|
262
274
|
export type { GooIndicatorProps, GooLayerProps }
|
|
263
275
|
export { union }
|
package/lib/overlay.tsx
CHANGED
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
useCallback,
|
|
20
20
|
useContext,
|
|
21
21
|
useMemo,
|
|
22
|
+
useState,
|
|
22
23
|
} from 'react'
|
|
23
24
|
import { useControllableState } from './use-controllable-state'
|
|
24
25
|
import { inPlaceOffset, type MorphOrigin, type MorphProps, opensInPlace, useMorphOrigin } from './use-morph'
|
|
@@ -110,6 +111,18 @@ function useOverlay(part: string): OverlayState {
|
|
|
110
111
|
return state
|
|
111
112
|
}
|
|
112
113
|
|
|
114
|
+
/**
|
|
115
|
+
* False until `open` first turns true, then true for good. Content that
|
|
116
|
+
* mounts its machinery (the morph, a fluid hover, the portal) behind it costs
|
|
117
|
+
* nothing in a list of triggers until one opens, and stays mounted after, for
|
|
118
|
+
* its close and the next open.
|
|
119
|
+
*/
|
|
120
|
+
function useOpenedOnce(open: boolean) {
|
|
121
|
+
const [opened, setOpened] = useState(open)
|
|
122
|
+
if (open && !opened) setOpened(true)
|
|
123
|
+
return opened || open
|
|
124
|
+
}
|
|
125
|
+
|
|
113
126
|
/**
|
|
114
127
|
* Base UI `Positioner` props for an anchored overlay: the content's
|
|
115
128
|
* anchoring props over the overlay's defaults, pulled back over the trigger
|
|
@@ -159,4 +172,12 @@ function usePortalContainer(container?: HTMLElement | null) {
|
|
|
159
172
|
}
|
|
160
173
|
|
|
161
174
|
export type { Align, AnchorProps, CollisionProps, OpenChangeDetails, OverlayRootProps, OverlayState, Side }
|
|
162
|
-
export {
|
|
175
|
+
export {
|
|
176
|
+
OverlayContext,
|
|
177
|
+
PortalContainer,
|
|
178
|
+
positionerProps,
|
|
179
|
+
useOpenedOnce,
|
|
180
|
+
useOverlay,
|
|
181
|
+
useOverlayRoot,
|
|
182
|
+
usePortalContainer,
|
|
183
|
+
}
|
package/lib/use-fluid-hover.ts
CHANGED
|
@@ -26,6 +26,12 @@ export interface ItemRect {
|
|
|
26
26
|
width: number
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
/** Two rects with the same box (either may be missing). */
|
|
30
|
+
export function sameRect(a: ItemRect | null | undefined, b: ItemRect | null | undefined) {
|
|
31
|
+
if (!a || !b) return a === b
|
|
32
|
+
return a.top === b.top && a.left === b.left && a.width === b.width && a.height === b.height
|
|
33
|
+
}
|
|
34
|
+
|
|
29
35
|
export interface UseFluidHoverOptions {
|
|
30
36
|
/**
|
|
31
37
|
* Which direction to resolve the nearest item along.
|
|
@@ -204,14 +210,6 @@ function resolveActivator(element: HTMLElement): HTMLElement {
|
|
|
204
210
|
return element.querySelector<HTMLElement>(ACTIVATOR_SELECTOR) ?? element
|
|
205
211
|
}
|
|
206
212
|
|
|
207
|
-
/**
|
|
208
|
-
* How many frames the coalesced remeasure retries while the registered items
|
|
209
|
-
* still have no layout box. A popup can be in the DOM one frame before it is
|
|
210
|
-
* laid out; retrying beats publishing zeroed rects, and the cap keeps a list
|
|
211
|
-
* that stays hidden for good from spinning frames forever.
|
|
212
|
-
*/
|
|
213
|
-
const measurementAttempts = 3
|
|
214
|
-
|
|
215
213
|
export function useFluidHover<T extends HTMLElement>(
|
|
216
214
|
containerRef: RefObject<T | null>,
|
|
217
215
|
options: UseFluidHoverOptions = {},
|
|
@@ -300,12 +298,7 @@ export function useFluidHover<T extends HTMLElement>(
|
|
|
300
298
|
// compare) so redundant remeasures don't churn re-renders.
|
|
301
299
|
const prev = itemRectsRef.current
|
|
302
300
|
let changed = prev.length !== rects.length
|
|
303
|
-
for (let i = 0; !changed && i < rects.length; i++)
|
|
304
|
-
const p = prev[i]
|
|
305
|
-
const r = rects[i]
|
|
306
|
-
if (p === r) continue // both undefined (sparse slot)
|
|
307
|
-
changed = !p || !r || p.top !== r.top || p.left !== r.left || p.width !== r.width || p.height !== r.height
|
|
308
|
-
}
|
|
301
|
+
for (let i = 0; !changed && i < rects.length; i++) changed = !sameRect(prev[i], rects[i])
|
|
309
302
|
if (changed) {
|
|
310
303
|
itemRectsRef.current = rects
|
|
311
304
|
setItemRects(rects)
|
|
@@ -318,58 +311,92 @@ export function useFluidHover<T extends HTMLElement>(
|
|
|
318
311
|
}, [runMeasurement])
|
|
319
312
|
|
|
320
313
|
/**
|
|
321
|
-
* The hook's single measurement pass
|
|
322
|
-
*
|
|
323
|
-
*
|
|
324
|
-
*
|
|
314
|
+
* The hook's single measurement pass, read right after the browser's own
|
|
315
|
+
* layout: every trigger (registration, `remeasure`, an item or the
|
|
316
|
+
* container resizing) lands in one ResizeObserver callback, where reading
|
|
317
|
+
* offsets costs no extra layout. Re-observing the container is the trigger
|
|
318
|
+
* (`observe` reports a laid-out target once), and a container without a box
|
|
319
|
+
* (a popup not laid out yet) reports when it gets one. It is the only place
|
|
320
|
+
* readiness turns true, so `isMeasured` can never be true while a pass is
|
|
321
|
+
* still queued.
|
|
325
322
|
*/
|
|
326
|
-
const
|
|
327
|
-
(
|
|
328
|
-
|
|
329
|
-
|
|
323
|
+
const onObserved = useCallback(() => {
|
|
324
|
+
if (runMeasurement()) setIsMeasured(true)
|
|
325
|
+
}, [runMeasurement])
|
|
326
|
+
|
|
327
|
+
const roRef = useRef<ResizeObserver | null>(null)
|
|
328
|
+
const observedContainerRef = useRef<HTMLElement | null>(null)
|
|
329
|
+
const getRo = useCallback(() => {
|
|
330
|
+
if (roRef.current === null && typeof ResizeObserver !== 'undefined') {
|
|
331
|
+
roRef.current = new ResizeObserver(onObserved)
|
|
332
|
+
}
|
|
333
|
+
return roRef.current
|
|
334
|
+
}, [onObserved])
|
|
335
|
+
|
|
336
|
+
// Re-observing the container makes the observer report it after the next
|
|
337
|
+
// layout. Deferred to a microtask: registrations run in the commit before
|
|
338
|
+
// the container's own ref attaches. Without ResizeObserver (tests), a frame.
|
|
339
|
+
const queuedRef = useRef(false)
|
|
340
|
+
const scheduleMeasurement = useCallback(() => {
|
|
341
|
+
if (queuedRef.current) return
|
|
342
|
+
queuedRef.current = true
|
|
343
|
+
queueMicrotask(() => {
|
|
344
|
+
queuedRef.current = false
|
|
345
|
+
const ro = getRo()
|
|
346
|
+
const container = containerRef.current
|
|
347
|
+
if (!ro || !container) {
|
|
348
|
+
if (remeasureRafIdRef.current !== null) cancelAnimationFrame(remeasureRafIdRef.current)
|
|
349
|
+
remeasureRafIdRef.current = requestAnimationFrame(() => {
|
|
350
|
+
remeasureRafIdRef.current = null
|
|
351
|
+
onObserved()
|
|
352
|
+
})
|
|
353
|
+
return
|
|
330
354
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
},
|
|
340
|
-
[runMeasurement],
|
|
341
|
-
)
|
|
355
|
+
if (observedContainerRef.current && observedContainerRef.current !== container) {
|
|
356
|
+
ro.unobserve(observedContainerRef.current)
|
|
357
|
+
}
|
|
358
|
+
observedContainerRef.current = container
|
|
359
|
+
ro.unobserve(container)
|
|
360
|
+
ro.observe(container, { box: 'border-box' })
|
|
361
|
+
})
|
|
362
|
+
}, [containerRef, getRo, onObserved])
|
|
342
363
|
|
|
343
364
|
const remeasure = useCallback(() => {
|
|
344
365
|
// Readiness drops first: until the pass below settles, the published rects
|
|
345
366
|
// may not describe what is on screen, and an overlay positioned from them
|
|
346
367
|
// would be corrected after mounting — which animates as a slide.
|
|
347
368
|
setIsMeasured(false)
|
|
348
|
-
scheduleMeasurement(
|
|
369
|
+
scheduleMeasurement()
|
|
349
370
|
}, [scheduleMeasurement])
|
|
350
371
|
|
|
351
|
-
//
|
|
352
|
-
//
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
372
|
+
// How many indices hold each element: a row that moves to another index
|
|
373
|
+
// within one batch must stay observed.
|
|
374
|
+
const observedRef = useRef(new Map<HTMLElement, number>())
|
|
375
|
+
const track = useCallback(
|
|
376
|
+
(element: HTMLElement, by: 1 | -1) => {
|
|
377
|
+
const count = (observedRef.current.get(element) ?? 0) + by
|
|
378
|
+
if (count > 0) observedRef.current.set(element, count)
|
|
379
|
+
else observedRef.current.delete(element)
|
|
380
|
+
// Border box: a row whose padding animates (actions revealed on hover)
|
|
381
|
+
// keeps its rect, so it must not remeasure the list every frame.
|
|
382
|
+
if (by === 1 && count === 1) getRo()?.observe(element, { box: 'border-box' })
|
|
383
|
+
if (count === 0) roRef.current?.unobserve(element)
|
|
384
|
+
},
|
|
385
|
+
[getRo],
|
|
386
|
+
)
|
|
363
387
|
|
|
364
388
|
const registerItem = useCallback(
|
|
365
389
|
(index: number, element: HTMLElement | null) => {
|
|
390
|
+
const previous = itemsRef.current.get(index)
|
|
391
|
+
// The same element at the same index (a parent re-registering its whole
|
|
392
|
+
// set) changes nothing.
|
|
393
|
+
if (element && previous === element) return
|
|
394
|
+
if (previous) track(previous, -1)
|
|
366
395
|
if (element) {
|
|
367
396
|
itemsRef.current.set(index, element)
|
|
368
|
-
|
|
397
|
+
track(element, 1)
|
|
369
398
|
if (index === activeIndexRef.current) element.setAttribute(ACTIVE_ATTR, '')
|
|
370
399
|
} else {
|
|
371
|
-
const previous = itemsRef.current.get(index)
|
|
372
|
-
if (previous) itemRoRef.current?.unobserve(previous)
|
|
373
400
|
// The mark leaves with the element: a row that only moved to another
|
|
374
401
|
// index (a filtering list re-ordering) must not carry it there.
|
|
375
402
|
previous?.removeAttribute(ACTIVE_ATTR)
|
|
@@ -382,13 +409,12 @@ export function useFluidHover<T extends HTMLElement>(
|
|
|
382
409
|
setActiveIndex(current => (current === index && !itemsRef.current.has(index) ? null : current))
|
|
383
410
|
}
|
|
384
411
|
}
|
|
385
|
-
//
|
|
386
|
-
//
|
|
387
|
-
//
|
|
388
|
-
// container's children swap.
|
|
412
|
+
// Coalesced: a list remounting its rows (an AnimatePresence swap) runs
|
|
413
|
+
// one pass, after layout, so consumers don't call measureItems after
|
|
414
|
+
// the container's children swap.
|
|
389
415
|
remeasure()
|
|
390
416
|
},
|
|
391
|
-
[remeasure,
|
|
417
|
+
[remeasure, track],
|
|
392
418
|
)
|
|
393
419
|
|
|
394
420
|
const handleMouseMove = useCallback(
|
|
@@ -474,30 +500,28 @@ export function useFluidHover<T extends HTMLElement>(
|
|
|
474
500
|
[isItemDisabled, gapClick, gapClickMaxDistance],
|
|
475
501
|
)
|
|
476
502
|
|
|
477
|
-
//
|
|
478
|
-
//
|
|
479
|
-
// stale. Coalesced through the same rAF as register/unregister. Readiness is
|
|
480
|
-
// deliberately not dropped: the item set is unchanged, so the published rects
|
|
503
|
+
// The container resizing reflows the items even though the set is
|
|
504
|
+
// unchanged. Readiness is deliberately not dropped: the published rects
|
|
481
505
|
// stay usable, and hiding overlays on every reflow would flicker them.
|
|
482
506
|
useEffect(() => {
|
|
483
507
|
const container = containerRef.current
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
508
|
+
const ro = getRo()
|
|
509
|
+
if (!container || !ro) return
|
|
510
|
+
observedContainerRef.current = container
|
|
511
|
+
ro.observe(container, { box: 'border-box' })
|
|
512
|
+
return () => {
|
|
513
|
+
ro.unobserve(container)
|
|
514
|
+
if (observedContainerRef.current === container) observedContainerRef.current = null
|
|
515
|
+
}
|
|
516
|
+
}, [containerRef, getRo])
|
|
489
517
|
|
|
490
|
-
// Clean up rAF and the item observer on unmount
|
|
491
518
|
useEffect(() => {
|
|
492
519
|
return () => {
|
|
493
|
-
if (rafIdRef.current !== null)
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
}
|
|
499
|
-
itemRoRef.current?.disconnect()
|
|
500
|
-
itemRoRef.current = null
|
|
520
|
+
if (rafIdRef.current !== null) cancelAnimationFrame(rafIdRef.current)
|
|
521
|
+
if (remeasureRafIdRef.current !== null) cancelAnimationFrame(remeasureRafIdRef.current)
|
|
522
|
+
roRef.current?.disconnect()
|
|
523
|
+
roRef.current = null
|
|
524
|
+
observedRef.current.clear()
|
|
501
525
|
}
|
|
502
526
|
}, [])
|
|
503
527
|
|
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.5.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": [
|
|
@@ -22,6 +22,26 @@ import { useShape } from '../../../lib/shape-context'
|
|
|
22
22
|
import { useTouchPrimary } from '../../../lib/use-touch-primary'
|
|
23
23
|
import { cn } from '../../../lib/utils'
|
|
24
24
|
|
|
25
|
+
// Base UI writes the edge distances (`--scroll-area-overflow-*`) on the
|
|
26
|
+
// viewport at every scroll event and registers them non-inherited, except in
|
|
27
|
+
// WebKit, where an inherited var re-styles every descendant per event: a long
|
|
28
|
+
// list recalculated thousands of elements a frame. Only the viewport reads
|
|
29
|
+
// them (`scroll-fade`), so they are registered for WebKit too.
|
|
30
|
+
if (typeof CSS !== 'undefined' && 'registerProperty' in CSS) {
|
|
31
|
+
for (const edge of ['x-start', 'x-end', 'y-start', 'y-end']) {
|
|
32
|
+
try {
|
|
33
|
+
CSS.registerProperty({
|
|
34
|
+
name: `--scroll-area-overflow-${edge}`,
|
|
35
|
+
syntax: '<length>',
|
|
36
|
+
inherits: false,
|
|
37
|
+
initialValue: '0px',
|
|
38
|
+
})
|
|
39
|
+
} catch {
|
|
40
|
+
// Already registered.
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
25
45
|
// Touch-primary devices get native overflow scrolling (momentum,
|
|
26
46
|
// rubber-banding); the exported ScrollBar no-ops there.
|
|
27
47
|
const ScrollAreaContext = createContext<boolean>(false)
|