@justanarthur/modo-ui 2.2.0 → 2.4.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/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 +28 -28
- package/dist/blocks/sidebar-app/index.js +38 -38
- package/dist/components/actions/button/index.js +4 -4
- package/dist/components/actions/copy/index.js +12 -12
- package/dist/components/containers/accordion/index.js +17 -17
- package/dist/components/containers/card/index.js +15 -15
- package/dist/components/data-display/avatar/index.js +3 -3
- package/dist/components/data-display/badge/index.js +2 -2
- package/dist/components/data-display/diff/index.d.ts +1 -1
- package/dist/components/data-display/diff/index.js +4 -4
- package/dist/components/data-display/list/index.js +3 -3
- package/dist/components/data-display/log-view/index.js +8 -8
- package/dist/components/data-display/markdown/index.js +16 -16
- package/dist/components/data-display/table/index.js +10 -10
- package/dist/components/feedback/empty-state/index.js +3 -3
- package/dist/components/feedback/meter/index.js +2 -2
- package/dist/components/feedback/progress/index.js +2 -2
- package/dist/components/inputs/checkbox/index.js +14 -14
- package/dist/components/inputs/choice-list/index.js +11 -11
- package/dist/components/inputs/color-picker/index.js +23 -23
- package/dist/components/inputs/combobox/index.js +21 -21
- package/dist/components/inputs/date-time/calendar/index.js +10 -10
- package/dist/components/inputs/date-time/date-picker/index.js +28 -28
- package/dist/components/inputs/date-time/date-range-picker/index.js +28 -28
- package/dist/components/inputs/date-time/duration-picker/index.js +27 -27
- package/dist/components/inputs/date-time/month-picker/index.js +26 -26
- package/dist/components/inputs/date-time/time-picker/index.js +27 -27
- package/dist/components/inputs/editable-text/index.js +2 -2
- package/dist/components/inputs/field/index.js +5 -5
- package/dist/components/inputs/file-dropzone/index.js +8 -8
- package/dist/components/inputs/input/index.js +6 -6
- package/dist/components/inputs/key-value/index.js +12 -12
- package/dist/components/inputs/number-input/index.js +7 -7
- package/dist/components/inputs/radio/index.js +13 -13
- package/dist/components/inputs/search/index.js +24 -24
- package/dist/components/inputs/select/index.js +22 -22
- package/dist/components/inputs/slider/index.js +4 -4
- package/dist/components/inputs/switch/index.js +10 -10
- package/dist/components/inputs/textarea/index.js +4 -4
- package/dist/components/navigation/breadcrumb/index.js +26 -26
- package/dist/components/navigation/navigation-menu/index.js +18 -18
- package/dist/components/navigation/pagination/index.js +17 -17
- package/dist/components/navigation/sidebar/index.js +26 -26
- package/dist/components/navigation/tabs/index.js +14 -14
- package/dist/components/navigation/tree/index.js +10 -10
- package/dist/components/overlays/alert-dialog/index.js +15 -15
- package/dist/components/overlays/command/index.d.ts +6 -3
- package/dist/components/overlays/command/index.js +22 -22
- package/dist/components/overlays/context-menu/index.js +26 -26
- package/dist/components/overlays/dialog/index.js +14 -14
- package/dist/components/overlays/dropdown/index.js +25 -25
- package/dist/components/overlays/lightbox/index.js +12 -12
- package/dist/components/overlays/popover/index.js +10 -10
- package/dist/components/overlays/preview-card/index.js +10 -10
- package/dist/components/overlays/sheet/index.js +15 -15
- package/dist/components/overlays/toast/index.js +11 -11
- package/dist/components/overlays/tooltip/index.js +7 -7
- package/dist/docs/index.js +17 -17
- package/dist/index.d.ts +16 -8
- package/dist/index.js +80 -80
- package/dist/lib/fluid-hover-highlight.js +5 -4
- package/dist/lib/focus-ring.d.ts +5 -2
- package/dist/lib/focus-ring.js +3 -2
- package/dist/lib/goo-indicator.d.ts +5 -2
- package/dist/lib/goo-indicator.js +4 -3
- package/dist/lib/morph-layers.js +4 -4
- package/dist/lib/morph-part.js +2 -2
- package/dist/lib/overlay.d.ts +8 -1
- package/dist/lib/overlay.js +6 -4
- package/dist/lib/popup-rows.js +2 -2
- package/dist/lib/popup-surface.js +7 -7
- package/dist/lib/scroll-column.js +7 -7
- 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 +5 -4
- package/dist/lib/use-morph.js +2 -2
- package/dist/primitives/content/code/index.js +3 -3
- package/dist/primitives/layout/resizable/index.d.ts +4 -2
- package/dist/primitives/layout/resizable/index.js +2 -2
- package/dist/primitives/layout/sortable/index.js +5 -5
- package/dist/primitives/systems/craft/index.js +3 -3
- package/dist/primitives/systems/fluid-hover/index.js +7 -7
- package/dist/primitives/systems/morph/index.js +13 -13
- package/dist/primitives/systems/motion/index.js +6 -6
- package/dist/primitives/systems/sizes/index.js +2 -2
- package/dist/shared/{components-19e2wpxc.js → components-0bvxny7s.js} +5 -5
- package/dist/shared/{components-v3c3madd.js → components-0ep66sg9.js} +6 -6
- package/dist/shared/{components-nd3f803g.js → components-0v4jxw7z.js} +3 -3
- package/dist/shared/{components-9hysh6d3.js → components-1f5624hb.js} +1 -1
- package/dist/shared/{components-8qwbwtv9.js → components-1qw8hqwq.js} +9 -9
- package/dist/shared/{components-7c4a0egq.js → components-21hcwp85.js} +78 -43
- package/dist/shared/{components-qhk2m7fj.js → components-3qcgeay1.js} +2 -2
- package/dist/shared/{components-zk1tj5za.js → components-3rt5c1qt.js} +3 -3
- package/dist/shared/{components-ppc2dmxs.js → components-3sb31vw5.js} +1 -1
- package/dist/shared/{components-qs0cwe8p.js → components-4fay97sm.js} +10 -10
- package/dist/shared/{components-09n5hgmx.js → components-4fhjk3jz.js} +2 -2
- package/dist/shared/{components-vkrp4nb9.js → components-4m9stj7d.js} +11 -11
- package/dist/shared/{components-pgs3p035.js → components-4t2cjav8.js} +1 -1
- package/dist/shared/{components-v1m0xjbw.js → components-5wykqxph.js} +6 -1
- package/dist/shared/{components-w5p7mfb4.js → components-5xs8pkkj.js} +1 -1
- package/dist/shared/{components-rj4nnqkz.js → components-7rn454aq.js} +13 -4
- package/dist/shared/{components-zktkxnzq.js → components-895m1f3s.js} +8 -8
- package/dist/shared/{components-t4eb37vd.js → components-8m5e493q.js} +2 -2
- package/dist/shared/{components-1nqp7wqr.js → components-8nnhzeb3.js} +5 -5
- package/dist/shared/{components-mcnyaaep.js → components-8xe4h118.js} +6 -6
- package/dist/shared/{components-a3edrqpb.js → components-9am5511q.js} +3 -3
- package/dist/shared/{components-95kp19zn.js → components-9b2m90st.js} +1 -1
- package/dist/shared/{components-qd27dvgj.js → components-9yrajpy0.js} +3 -3
- package/dist/shared/{components-ajgwbabq.js → components-abqfs5fh.js} +4 -4
- package/dist/shared/{components-dr5c27yd.js → components-ac0x7zpq.js} +4 -4
- package/dist/shared/{components-y07de1qv.js → components-af44r4y9.js} +2 -2
- package/dist/shared/{components-90y8qwxv.js → components-br6t88cb.js} +5 -5
- package/dist/shared/{components-gvwxswpr.js → components-bxqmbcz2.js} +7 -3
- package/dist/shared/{components-9e5fpy3v.js → components-cc9kfhkb.js} +171 -115
- package/dist/shared/{components-rts2mggt.js → components-d4gkhy26.js} +1 -1
- package/dist/shared/{components-veaxns17.js → components-eawe4nxm.js} +2 -2
- package/dist/shared/{components-qe8yp3vf.js → components-fpgfs01m.js} +3 -3
- package/dist/shared/{components-xvf8jcza.js → components-ft5dgjg6.js} +10 -3
- package/dist/shared/{components-pbx77hzb.js → components-fv9y76b0.js} +15 -3
- package/dist/shared/{components-afj2ajea.js → components-fymenepq.js} +8 -8
- package/dist/shared/{components-rmhdr4g1.js → components-gd8gmr6w.js} +1 -1
- package/dist/shared/{components-k9qbcmaa.js → components-gr82tz50.js} +21 -3
- package/dist/shared/{components-nc8wggew.js → components-greka6z2.js} +59 -19
- package/dist/shared/{components-qkt4h7x4.js → components-gzve0nkp.js} +8 -8
- package/dist/shared/{components-4xd21p2p.js → components-hjdv4y8d.js} +3 -3
- package/dist/shared/{components-v81eejq6.js → components-hjk6dwsp.js} +2 -2
- package/dist/shared/{components-151vndgm.js → components-mb80a9wg.js} +3 -3
- package/dist/shared/{components-gfw4zk8b.js → components-mzdbtgvz.js} +12 -12
- package/dist/shared/{components-9s9vb2w0.js → components-nmbcfwx8.js} +8 -8
- package/dist/shared/{components-90sfqz5t.js → components-nxqrw789.js} +1 -1
- package/dist/shared/{components-2q0m4mxf.js → components-pw6gzev8.js} +2 -2
- package/dist/shared/{components-fqdh9ysk.js → components-pwsqp2np.js} +24 -14
- package/dist/shared/{components-yn8bw8tv.js → components-qmkfpcw0.js} +12 -12
- package/dist/shared/{components-z9gc2weg.js → components-qrtcc8aw.js} +3 -3
- package/dist/shared/{components-jd21f3mb.js → components-rgdspnth.js} +5 -5
- package/dist/shared/{components-r6ejdtpr.js → components-rtwfh1gc.js} +4 -4
- package/dist/shared/{components-16wx5av1.js → components-s0megs1g.js} +6 -6
- package/dist/shared/{components-8qkd3659.js → components-s2pnh8h9.js} +1 -1
- package/dist/shared/{components-2zr49v82.js → components-sh8j39z3.js} +7 -7
- package/dist/shared/{components-7v6869ga.js → components-t0c1rw40.js} +1 -1
- package/dist/shared/{components-mamtvenk.js → components-t4j0r23n.js} +2 -2
- package/dist/shared/{components-qc1fae2s.js → components-v1zzr668.js} +6 -6
- package/dist/shared/{components-vv420geb.js → components-vcmky8ns.js} +7 -7
- package/dist/shared/{components-313rmbxy.js → components-wq9hrera.js} +2 -2
- package/dist/shared/{components-mpx3yq5c.js → components-xq8j9c2f.js} +12 -12
- package/dist/shared/{components-3cvwrzc1.js → components-y9se9mx5.js} +3 -3
- package/dist/shared/{components-nehs80xd.js → components-yfx0skxc.js} +1 -1
- package/dist/shared/{components-s25rehbv.js → components-zckgawt6.js} +5 -5
- package/dist/shared/{components-85dz3xx3.js → components-zv63s4fh.js} +3 -3
- package/dist/styles.css +1 -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/resizable/index.tsx +35 -7
- /package/dist/shared/{components-mp7en54n.js → components-8pnvkrbw.js} +0 -0
- /package/dist/shared/{components-zwgxvktt.js → components-92mvpt9h.js} +0 -0
- /package/dist/shared/{components-02683eqd.js → components-jw45ck66.js} +0 -0
- /package/dist/shared/{components-hbqyf35a.js → components-knryyjme.js} +0 -0
- /package/dist/shared/{components-yy0a9b02.js → components-m3vxpz2z.js} +0 -0
- /package/dist/shared/{components-ffng9rpa.js → components-nz14rwtd.js} +0 -0
- /package/dist/shared/{components-wddr0r6a.js → components-pa43g2r2.js} +0 -0
- /package/dist/shared/{components-6c52v58g.js → components-q0hs5rqn.js} +0 -0
- /package/dist/shared/{components-h9se5cz5.js → components-vx286kq7.js} +0 -0
- /package/dist/shared/{components-fa61vwag.js → components-y4gsk1jt.js} +0 -0
- /package/dist/shared/{components-31pkxwfz.js → components-ycwhrqe1.js} +0 -0
- /package/dist/shared/{components-wqac4434.js → components-ymq8tbq9.js} +0 -0
- /package/dist/shared/{components-sxstx1x7.js → components-ypxst3cn.js} +0 -0
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.4.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": [
|
|
@@ -140,7 +140,14 @@ function ResizableHandle({ label = 'Resize', className }: ResizableHandleProps)
|
|
|
140
140
|
const index = useContext(ResizableIndexContext)
|
|
141
141
|
const reduced = useReduceMotion()
|
|
142
142
|
const [hovered, setHovered] = useState(false)
|
|
143
|
-
const drag = useRef<{
|
|
143
|
+
const drag = useRef<{
|
|
144
|
+
start: number
|
|
145
|
+
sizes: number[]
|
|
146
|
+
next: number[]
|
|
147
|
+
panels: HTMLElement[]
|
|
148
|
+
flex: string[]
|
|
149
|
+
pxPerPercent: number
|
|
150
|
+
} | null>(null)
|
|
144
151
|
const [dragging, setOwnDragging] = useState(false)
|
|
145
152
|
const setDragging = (next: boolean) => {
|
|
146
153
|
setOwnDragging(next)
|
|
@@ -152,15 +159,22 @@ function ResizableHandle({ label = 'Resize', className }: ResizableHandleProps)
|
|
|
152
159
|
|
|
153
160
|
const onPointerDown = (e: PointerEvent<HTMLDivElement>) => {
|
|
154
161
|
if (e.button !== 0) return
|
|
155
|
-
const panels = [...(e.currentTarget.parentElement?.children ?? [])].filter(
|
|
156
|
-
el.hasAttribute('data-resizable-panel'),
|
|
162
|
+
const panels = [...(e.currentTarget.parentElement?.children ?? [])].filter(
|
|
163
|
+
(el): el is HTMLElement => el instanceof HTMLElement && el.hasAttribute('data-resizable-panel'),
|
|
157
164
|
)
|
|
158
165
|
const px = panels.reduce((sum, el) => {
|
|
159
166
|
const rect = el.getBoundingClientRect()
|
|
160
167
|
return sum + (horizontal ? rect.width : rect.height)
|
|
161
168
|
}, 0)
|
|
162
169
|
e.currentTarget.setPointerCapture(e.pointerId)
|
|
163
|
-
drag.current = {
|
|
170
|
+
drag.current = {
|
|
171
|
+
start: horizontal ? e.clientX : e.clientY,
|
|
172
|
+
sizes: group.sizes,
|
|
173
|
+
next: group.sizes,
|
|
174
|
+
panels,
|
|
175
|
+
flex: panels.map(el => el.style.flex),
|
|
176
|
+
pxPerPercent: px / 100,
|
|
177
|
+
}
|
|
164
178
|
setDragging(true)
|
|
165
179
|
e.preventDefault()
|
|
166
180
|
}
|
|
@@ -169,12 +183,24 @@ function ResizableHandle({ label = 'Resize', className }: ResizableHandleProps)
|
|
|
169
183
|
const d = drag.current
|
|
170
184
|
if (!d?.pxPerPercent) return
|
|
171
185
|
const delta = ((horizontal ? e.clientX : e.clientY) - d.start) / d.pxPerPercent
|
|
172
|
-
|
|
186
|
+
d.next = resize(d.sizes, index, delta, group.limits)
|
|
187
|
+
// A drag step re-renders nothing: it writes the panels' flex, and the sizes commit on release.
|
|
188
|
+
d.panels.forEach((el, i) => {
|
|
189
|
+
el.style.flex = `${d.next[i] ?? 0} 1 0px`
|
|
190
|
+
})
|
|
191
|
+
e.currentTarget.setAttribute('aria-valuenow', String(Math.round(d.next[index] ?? 0)))
|
|
173
192
|
}
|
|
174
193
|
|
|
175
194
|
const onPointerUp = () => {
|
|
195
|
+
const d = drag.current
|
|
176
196
|
drag.current = null
|
|
177
197
|
setDragging(false)
|
|
198
|
+
if (!d) return
|
|
199
|
+
// Back to what React rendered, so sizes a controlled parent turns down don't stick.
|
|
200
|
+
d.panels.forEach((el, i) => {
|
|
201
|
+
el.style.flex = d.flex[i] ?? ''
|
|
202
|
+
})
|
|
203
|
+
group.setSizes(d.next)
|
|
178
204
|
}
|
|
179
205
|
|
|
180
206
|
const onKeyDown = (e: KeyboardEvent<HTMLDivElement>) => {
|
|
@@ -245,7 +271,7 @@ interface ResizableProps {
|
|
|
245
271
|
direction?: ResizableDirection
|
|
246
272
|
/** Controlled panel sizes in percent, one per panel in order. Pair with `onSizesChange`. */
|
|
247
273
|
sizes?: number[]
|
|
248
|
-
/** Called with every panel's size
|
|
274
|
+
/** Called with every panel's size when a handle moves: on a drag's release, on each key and on a double-click. */
|
|
249
275
|
onSizesChange?: (sizes: number[]) => void
|
|
250
276
|
/** Percent a handle moves per arrow key. Defaults to `5`. */
|
|
251
277
|
step?: number
|
|
@@ -267,7 +293,9 @@ interface ResizableProps {
|
|
|
267
293
|
* its starting size. A collapsible panel snaps shut when dragged below half
|
|
268
294
|
* its minimum. A drag follows the pointer; every other change of size (a
|
|
269
295
|
* key, a reset, new controlled `sizes`, such as a toggle folding a pane)
|
|
270
|
-
* glides there.
|
|
296
|
+
* glides there. A drag writes the panels' sizes to the DOM and commits them
|
|
297
|
+
* (`onSizesChange`) on release, so it re-renders nothing on the way. Sizes
|
|
298
|
+
* work uncontrolled (each panel's `defaultSize`) or
|
|
271
299
|
* controlled (`sizes` + `onSizesChange`). Groups nest: put a Resizable inside
|
|
272
300
|
* a panel to split it the other way.
|
|
273
301
|
*
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|