@mrpelz/uikit-ish 7.13.1 → 7.26.2
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/dist/components/accordion/style.css +1 -1
- package/dist/components/action-sheet/main.d.ts.map +1 -1
- package/dist/components/action-sheet/main.js +9 -6
- package/dist/components/action-sheet/main.js.map +1 -1
- package/dist/components/action-sheet/props.d.ts +2 -1
- package/dist/components/action-sheet/props.d.ts.map +1 -1
- package/dist/components/alert/main.d.ts.map +1 -1
- package/dist/components/alert/main.js +12 -4
- package/dist/components/alert/main.js.map +1 -1
- package/dist/components/alert/props.d.ts +2 -1
- package/dist/components/alert/props.d.ts.map +1 -1
- package/dist/components/alert/style.css +27 -5
- package/dist/components/button/main.js +1 -1
- package/dist/components/button/main.js.map +1 -1
- package/dist/components/button/props.d.ts +3 -2
- package/dist/components/button/props.d.ts.map +1 -1
- package/dist/components/button/style.css +6 -17
- package/dist/components/card/main.d.ts +53 -0
- package/dist/components/card/main.d.ts.map +1 -0
- package/dist/components/card/main.js +286 -0
- package/dist/components/card/main.js.map +1 -0
- package/dist/components/card/props.d.ts +83 -0
- package/dist/components/card/props.d.ts.map +1 -0
- package/dist/components/card/props.js +2 -0
- package/dist/components/card/props.js.map +1 -0
- package/dist/components/card/style.css +900 -0
- package/dist/components/collapsible/style.css +1 -1
- package/dist/components/color-picker/main.d.ts.map +1 -1
- package/dist/components/color-picker/main.js +20 -33
- package/dist/components/color-picker/main.js.map +1 -1
- package/dist/components/color-picker/style.css +4 -23
- package/dist/components/contextual-menu/main.d.ts +6 -2
- package/dist/components/contextual-menu/main.d.ts.map +1 -1
- package/dist/components/contextual-menu/main.js +67 -43
- package/dist/components/contextual-menu/main.js.map +1 -1
- package/dist/components/contextual-menu/props.d.ts +2 -1
- package/dist/components/contextual-menu/props.d.ts.map +1 -1
- package/dist/components/contextual-menu/style.css +64 -2
- package/dist/components/control-cards/main.d.ts +49 -0
- package/dist/components/control-cards/main.d.ts.map +1 -0
- package/dist/components/control-cards/main.js +835 -0
- package/dist/components/control-cards/main.js.map +1 -0
- package/dist/components/control-cards/props.d.ts +409 -0
- package/dist/components/control-cards/props.d.ts.map +1 -0
- package/dist/components/control-cards/props.js +2 -0
- package/dist/components/control-cards/props.js.map +1 -0
- package/dist/components/control-cards/style.css +492 -0
- package/dist/components/date-picker/main.d.ts.map +1 -1
- package/dist/components/date-picker/main.js +3 -2
- package/dist/components/date-picker/main.js.map +1 -1
- package/dist/components/date-picker/style.css +1 -1
- package/dist/components/drawer/style.css +6 -0
- package/dist/components/edit-menu/main.d.ts +2 -1
- package/dist/components/edit-menu/main.d.ts.map +1 -1
- package/dist/components/edit-menu/main.js +8 -4
- package/dist/components/edit-menu/main.js.map +1 -1
- package/dist/components/glass/backdrop.d.ts +75 -0
- package/dist/components/glass/backdrop.d.ts.map +1 -0
- package/dist/components/glass/backdrop.js +608 -0
- package/dist/components/glass/backdrop.js.map +1 -0
- package/dist/components/glass/gradient.d.ts +17 -0
- package/dist/components/glass/gradient.d.ts.map +1 -0
- package/dist/components/glass/gradient.js +233 -0
- package/dist/components/glass/gradient.js.map +1 -0
- package/dist/components/glass/main.d.ts +60 -6
- package/dist/components/glass/main.d.ts.map +1 -1
- package/dist/components/glass/main.js +100 -122
- package/dist/components/glass/main.js.map +1 -1
- package/dist/components/glass/marker.d.ts +66 -0
- package/dist/components/glass/marker.d.ts.map +1 -0
- package/dist/components/glass/marker.js +268 -0
- package/dist/components/glass/marker.js.map +1 -0
- package/dist/components/glass/props.d.ts +33 -7
- package/dist/components/glass/props.d.ts.map +1 -1
- package/dist/components/glass/style.css +139 -75
- package/dist/components/grid/dashes.d.ts +15 -0
- package/dist/components/grid/dashes.d.ts.map +1 -0
- package/dist/components/grid/dashes.js +37 -0
- package/dist/components/grid/dashes.js.map +1 -0
- package/dist/components/grid/edit.d.ts +11 -0
- package/dist/components/grid/edit.d.ts.map +1 -0
- package/dist/components/grid/edit.js +1066 -0
- package/dist/components/grid/edit.js.map +1 -0
- package/dist/components/grid/handle.d.ts +123 -0
- package/dist/components/grid/handle.d.ts.map +1 -0
- package/dist/components/grid/handle.js +194 -0
- package/dist/components/grid/handle.js.map +1 -0
- package/dist/components/grid/icons.d.ts +40 -0
- package/dist/components/grid/icons.d.ts.map +1 -0
- package/dist/components/grid/icons.js +140 -0
- package/dist/components/grid/icons.js.map +1 -0
- package/dist/components/grid/layout.d.ts +111 -0
- package/dist/components/grid/layout.d.ts.map +1 -0
- package/dist/components/grid/layout.js +1257 -0
- package/dist/components/grid/layout.js.map +1 -0
- package/dist/components/grid/main.d.ts +63 -0
- package/dist/components/grid/main.d.ts.map +1 -0
- package/dist/components/grid/main.js +1894 -0
- package/dist/components/grid/main.js.map +1 -0
- package/dist/components/grid/overlay.d.ts +24 -0
- package/dist/components/grid/overlay.d.ts.map +1 -0
- package/dist/components/grid/overlay.js +312 -0
- package/dist/components/grid/overlay.js.map +1 -0
- package/dist/components/grid/plan.d.ts +78 -0
- package/dist/components/grid/plan.d.ts.map +1 -0
- package/dist/components/grid/plan.js +249 -0
- package/dist/components/grid/plan.js.map +1 -0
- package/dist/components/grid/props.d.ts +509 -0
- package/dist/components/grid/props.d.ts.map +1 -0
- package/dist/components/grid/props.js +2 -0
- package/dist/components/grid/props.js.map +1 -0
- package/dist/components/grid/reshape.d.ts +60 -0
- package/dist/components/grid/reshape.d.ts.map +1 -0
- package/dist/components/grid/reshape.js +214 -0
- package/dist/components/grid/reshape.js.map +1 -0
- package/dist/components/grid/style.css +1293 -0
- package/dist/components/header/main.d.ts.map +1 -1
- package/dist/components/header/main.js +97 -10
- package/dist/components/header/main.js.map +1 -1
- package/dist/components/header/props.d.ts +2 -2
- package/dist/components/header/props.d.ts.map +1 -1
- package/dist/components/header/style.css +28 -43
- package/dist/components/index.d.ts +10 -6
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +5 -1
- package/dist/components/index.js.map +1 -1
- package/dist/components/island/main.d.ts +2 -2
- package/dist/components/island/main.d.ts.map +1 -1
- package/dist/components/island/main.js +193 -41
- package/dist/components/island/main.js.map +1 -1
- package/dist/components/island/props.d.ts +4 -2
- package/dist/components/island/props.d.ts.map +1 -1
- package/dist/components/island/style.css +50 -3
- package/dist/components/layout/main.d.ts +3 -6
- package/dist/components/layout/main.d.ts.map +1 -1
- package/dist/components/layout/main.js +225 -56
- package/dist/components/layout/main.js.map +1 -1
- package/dist/components/layout/props.d.ts +43 -2
- package/dist/components/layout/props.d.ts.map +1 -1
- package/dist/components/layout/style.css +84 -23
- package/dist/components/list/main.d.ts +3 -3
- package/dist/components/list/main.d.ts.map +1 -1
- package/dist/components/list/main.js +90 -19
- package/dist/components/list/main.js.map +1 -1
- package/dist/components/list/props.d.ts +20 -0
- package/dist/components/list/props.d.ts.map +1 -1
- package/dist/components/list/reorder.d.ts +16 -2
- package/dist/components/list/reorder.d.ts.map +1 -1
- package/dist/components/list/reorder.js.map +1 -1
- package/dist/components/list/style.css +60 -3
- package/dist/components/menu/main.d.ts +9 -5
- package/dist/components/menu/main.d.ts.map +1 -1
- package/dist/components/menu/main.js +87 -9
- package/dist/components/menu/main.js.map +1 -1
- package/dist/components/menu/props.d.ts +14 -0
- package/dist/components/menu/props.d.ts.map +1 -1
- package/dist/components/menu/style.css +3 -1
- package/dist/components/page/main.d.ts.map +1 -1
- package/dist/components/page/main.js +6 -3
- package/dist/components/page/main.js.map +1 -1
- package/dist/components/page/props.d.ts +3 -2
- package/dist/components/page/props.d.ts.map +1 -1
- package/dist/components/page/style.css +8 -4
- package/dist/components/page-control/props.d.ts +3 -3
- package/dist/components/popover/main.d.ts +10 -4
- package/dist/components/popover/main.d.ts.map +1 -1
- package/dist/components/popover/main.js +30 -19
- package/dist/components/popover/main.js.map +1 -1
- package/dist/components/popover/props.d.ts +2 -0
- package/dist/components/popover/props.d.ts.map +1 -1
- package/dist/components/popover/style.css +6 -2
- package/dist/components/progress/style.css +2 -2
- package/dist/components/roll/main.d.ts.map +1 -1
- package/dist/components/roll/main.js +5 -3
- package/dist/components/roll/main.js.map +1 -1
- package/dist/components/segmented/main.d.ts.map +1 -1
- package/dist/components/segmented/main.js +4 -4
- package/dist/components/segmented/main.js.map +1 -1
- package/dist/components/segmented/props.d.ts +5 -2
- package/dist/components/segmented/props.d.ts.map +1 -1
- package/dist/components/segmented/style.css +1 -1
- package/dist/components/settings/main.d.ts +13 -0
- package/dist/components/settings/main.d.ts.map +1 -1
- package/dist/components/settings/main.js +16 -0
- package/dist/components/settings/main.js.map +1 -1
- package/dist/components/settings/props.d.ts +1 -0
- package/dist/components/settings/props.d.ts.map +1 -1
- package/dist/components/sheet/main.d.ts.map +1 -1
- package/dist/components/sheet/main.js +156 -45
- package/dist/components/sheet/main.js.map +1 -1
- package/dist/components/sheet/props.d.ts +4 -2
- package/dist/components/sheet/props.d.ts.map +1 -1
- package/dist/components/sheet/snap.d.ts +54 -0
- package/dist/components/sheet/snap.d.ts.map +1 -1
- package/dist/components/sheet/snap.js +253 -23
- package/dist/components/sheet/snap.js.map +1 -1
- package/dist/components/sheet/style.css +126 -20
- package/dist/components/sidebar/main.d.ts +2 -1
- package/dist/components/sidebar/main.d.ts.map +1 -1
- package/dist/components/sidebar/main.js +18 -6
- package/dist/components/sidebar/main.js.map +1 -1
- package/dist/components/sidebar/props.d.ts +2 -1
- package/dist/components/sidebar/props.d.ts.map +1 -1
- package/dist/components/sidebar/style.css +78 -0
- package/dist/components/slider/main.d.ts.map +1 -1
- package/dist/components/slider/main.js +51 -9
- package/dist/components/slider/main.js.map +1 -1
- package/dist/components/slider/props.d.ts +1 -0
- package/dist/components/slider/props.d.ts.map +1 -1
- package/dist/components/slider/style.css +9 -0
- package/dist/components/switch/main.d.ts.map +1 -1
- package/dist/components/switch/main.js +4 -2
- package/dist/components/switch/main.js.map +1 -1
- package/dist/components/symbol/main.d.ts.map +1 -1
- package/dist/components/symbol/main.js +5 -1
- package/dist/components/symbol/main.js.map +1 -1
- package/dist/components/symbol/props.d.ts +10 -0
- package/dist/components/symbol/props.d.ts.map +1 -1
- package/dist/components/symbol/style.css +21 -3
- package/dist/components/tab-bar/main.d.ts.map +1 -1
- package/dist/components/tab-bar/main.js +8 -5
- package/dist/components/tab-bar/main.js.map +1 -1
- package/dist/components/tab-bar/props.d.ts +16 -12
- package/dist/components/tab-bar/props.d.ts.map +1 -1
- package/dist/components/tab-bar/style.css +3 -9
- package/dist/components/text-field/main.d.ts.map +1 -1
- package/dist/components/text-field/main.js +6 -3
- package/dist/components/text-field/main.js.map +1 -1
- package/dist/components/text-field/style.css +1 -1
- package/dist/components/toolbar/main.js +1 -1
- package/dist/components/toolbar/main.js.map +1 -1
- package/dist/components/toolbar/props.d.ts +3 -3
- package/dist/components/toolbar/style.css +1 -1
- package/dist/components/tooltip/main.d.ts +6 -1
- package/dist/components/tooltip/main.d.ts.map +1 -1
- package/dist/components/tooltip/main.js +13 -7
- package/dist/components/tooltip/main.js.map +1 -1
- package/dist/components/utils/main.d.ts +31 -2
- package/dist/components/utils/main.d.ts.map +1 -1
- package/dist/components/utils/main.js +60 -3
- package/dist/components/utils/main.js.map +1 -1
- package/dist/components/viewport/current.d.ts +15 -0
- package/dist/components/viewport/current.d.ts.map +1 -0
- package/dist/components/viewport/current.js +74 -0
- package/dist/components/viewport/current.js.map +1 -0
- package/dist/components/viewport/edge-effect.d.ts.map +1 -1
- package/dist/components/viewport/edge-effect.js +52 -24
- package/dist/components/viewport/edge-effect.js.map +1 -1
- package/dist/components/viewport/edge.d.ts +7 -4
- package/dist/components/viewport/edge.d.ts.map +1 -1
- package/dist/components/viewport/edge.js +21 -7
- package/dist/components/viewport/edge.js.map +1 -1
- package/dist/components/viewport/focus-scroll.d.ts +21 -0
- package/dist/components/viewport/focus-scroll.d.ts.map +1 -0
- package/dist/components/viewport/focus-scroll.js +272 -0
- package/dist/components/viewport/focus-scroll.js.map +1 -0
- package/dist/components/viewport/input.d.ts +39 -1
- package/dist/components/viewport/input.d.ts.map +1 -1
- package/dist/components/viewport/input.js +122 -13
- package/dist/components/viewport/input.js.map +1 -1
- package/dist/components/viewport/main.d.ts +16 -1
- package/dist/components/viewport/main.d.ts.map +1 -1
- package/dist/components/viewport/main.js +243 -49
- package/dist/components/viewport/main.js.map +1 -1
- package/dist/components/viewport/padding.d.ts +1 -1
- package/dist/components/viewport/padding.d.ts.map +1 -1
- package/dist/components/viewport/padding.js +2 -2
- package/dist/components/viewport/props.d.ts +12 -2
- package/dist/components/viewport/props.d.ts.map +1 -1
- package/dist/components/viewport/status-bar.d.ts +9 -0
- package/dist/components/viewport/status-bar.d.ts.map +1 -0
- package/dist/components/viewport/status-bar.js +131 -0
- package/dist/components/viewport/status-bar.js.map +1 -0
- package/dist/components/viewport/style.css +62 -5
- package/dist/styles.css +123 -198
- package/package.json +5 -4
|
@@ -2,12 +2,20 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import './style.css';
|
|
3
3
|
import { createContext, forwardRef, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore, } from 'react';
|
|
4
4
|
import { WheelGestures } from 'wheel-gestures';
|
|
5
|
+
import { useGlassMode } from '../glass/main.js';
|
|
5
6
|
import { cn, useForwardedRef, usePortalContainer, withStyle, } from '../utils/main.js';
|
|
7
|
+
import { currentLayer, subscribeCurrent } from './current.js';
|
|
6
8
|
import { registerScroller, scrollerUnder, subscribeScrollers, useScrollerRegistration, } from './edge.js';
|
|
7
9
|
import { EdgeEffects } from './edge-effect.js';
|
|
10
|
+
import { trackFocusScroll } from './focus-scroll.js';
|
|
11
|
+
import { fixedBottom, fixedProbe, hasKeyboardFocus } from './input.js';
|
|
8
12
|
import { isIos27, ViewportInsetContext } from './ios27.js';
|
|
9
13
|
import { createAnchorHandle, Padding, useAnchorRegistration, useAnchorSize, useOverscrollRoom, usePushedAnchorSize, } from './padding.js';
|
|
14
|
+
import { useStatusBarTaps } from './status-bar.js';
|
|
10
15
|
export { preventFocusShift, preventInputZoom, preventTextActions, useFocusShiftPrevention, useInputZoomPrevention, useTextActionsPrevention, } from './input.js';
|
|
16
|
+
export { useCurrentLayer } from './current.js';
|
|
17
|
+
export { useFocusScroll } from './focus-scroll.js';
|
|
18
|
+
export { trackStatusBarTaps, useStatusBarTaps } from './status-bar.js';
|
|
11
19
|
export { useScrollerRegistration, useViewportEdgeElement } from './edge.js';
|
|
12
20
|
export { EdgeEffects } from './edge-effect.js';
|
|
13
21
|
export { ios27Attribute, isIos27, ViewportInsetContext } from './ios27.js';
|
|
@@ -151,7 +159,13 @@ const readVisual = (screen, box) => {
|
|
|
151
159
|
const isHidden = document.visibilityState === 'hidden';
|
|
152
160
|
const height = viewport?.height ?? window.innerHeight;
|
|
153
161
|
const top = viewport?.offsetTop ?? 0;
|
|
154
|
-
|
|
162
|
+
// (Against the fixed layers' box: not `innerHeight`, which iOS may
|
|
163
|
+
// shrink to the visual viewport, see `fixedBottom`. None without
|
|
164
|
+
// something it's for focused: e.g. resumed, the visual viewport read as
|
|
165
|
+
// shrunk a while, see `hasKeyboardFocus`.)
|
|
166
|
+
const keyboardInset = hasKeyboardFocus()
|
|
167
|
+
? Math.max(0, Math.round(fixedBottom() - height - top))
|
|
168
|
+
: 0;
|
|
155
169
|
if (!screen) {
|
|
156
170
|
return {
|
|
157
171
|
height,
|
|
@@ -180,7 +194,10 @@ const readVisual = (screen, box) => {
|
|
|
180
194
|
/** An element, or a ref's (a portal container's, if it's one). */
|
|
181
195
|
const elementOf = (value) => {
|
|
182
196
|
const element = value && 'current' in value ? value.current : value;
|
|
183
|
-
|
|
197
|
+
// (No DOM, e.g. prerendering: none.)
|
|
198
|
+
return typeof HTMLElement !== 'undefined' && element instanceof HTMLElement
|
|
199
|
+
? element
|
|
200
|
+
: null;
|
|
184
201
|
};
|
|
185
202
|
/**
|
|
186
203
|
* The root's markers (see style.css): the window an app's (its layers in
|
|
@@ -249,7 +266,7 @@ const useScreenHold = (screen) => {
|
|
|
249
266
|
/** A screen's marker: its layers following its box (see `Provider`). */
|
|
250
267
|
const boxDrivenAttribute = 'data-uikit-viewport-box-driven';
|
|
251
268
|
/** Provides the visual viewport and scroll tracking (see above). */
|
|
252
|
-
const Provider = ({ children, screen: ownScreen, scroller, }) => {
|
|
269
|
+
const Provider = ({ children, screen: ownScreen, scroller, scrollsToTop = true, }) => {
|
|
253
270
|
// Its screen: its own, or the provided portal container's (e.g. a
|
|
254
271
|
// device's frame), or none (the window's).
|
|
255
272
|
const screen = usePortalContainer(ownScreen);
|
|
@@ -258,6 +275,28 @@ const Provider = ({ children, screen: ownScreen, scroller, }) => {
|
|
|
258
275
|
// Tracked without a `scroller`: the page filling its screen (see
|
|
259
276
|
// edge.ts), or the document's.
|
|
260
277
|
const [filling, setFilling] = useState(undefined);
|
|
278
|
+
// Its status bar tapped (the window's, see status-bar.ts): the current
|
|
279
|
+
// scroller to its top, smoothly (not the document: its own scroll to its
|
|
280
|
+
// top is the tap's). Not if it tracks the document (the app's own
|
|
281
|
+
// scrolling: iOS's tap scrolls it as it is).
|
|
282
|
+
const isDocumentTracked = !scroller &&
|
|
283
|
+
(filling === undefined ||
|
|
284
|
+
(typeof document !== 'undefined' &&
|
|
285
|
+
filling === document.scrollingElement));
|
|
286
|
+
const latestFilling = useRef(filling);
|
|
287
|
+
useLayoutEffect(() => {
|
|
288
|
+
latestFilling.current = filling;
|
|
289
|
+
});
|
|
290
|
+
useStatusBarTaps(() => {
|
|
291
|
+
const target = currentLayer(null) ?? scroller?.current ?? latestFilling.current;
|
|
292
|
+
if (!target || target === document.scrollingElement)
|
|
293
|
+
return;
|
|
294
|
+
target.scrollTo({ behavior: 'smooth', top: 0 });
|
|
295
|
+
},
|
|
296
|
+
// (The window's: no screen given; not its ref read while rendering.)
|
|
297
|
+
scrollsToTop &&
|
|
298
|
+
(screen === null || screen === undefined) &&
|
|
299
|
+
!isDocumentTracked);
|
|
261
300
|
useLayoutEffect(() => {
|
|
262
301
|
if (scroller)
|
|
263
302
|
return undefined;
|
|
@@ -283,6 +322,10 @@ const Provider = ({ children, screen: ownScreen, scroller, }) => {
|
|
|
283
322
|
// Tracking the window (or a screen): it's an app's.
|
|
284
323
|
useWindowHold(screen);
|
|
285
324
|
useScreenHold(screen);
|
|
325
|
+
// Its text fields kept in view above the keyboard, by their scrollers
|
|
326
|
+
// (see focus-scroll.ts): those in its screen; the window's, those in no
|
|
327
|
+
// provider's screen.
|
|
328
|
+
useEffect(() => trackFocusScroll(elementOf(screen), `[${screenAttribute}]`), [screen]);
|
|
286
329
|
// The visual viewport (once per frame), as custom properties, too: on
|
|
287
330
|
// the root element, or its screen.
|
|
288
331
|
useLayoutEffect(() => {
|
|
@@ -347,15 +390,18 @@ const Provider = ({ children, screen: ownScreen, scroller, }) => {
|
|
|
347
390
|
document.addEventListener('visibilitychange', onVisibility);
|
|
348
391
|
// Its layers' box resized (e.g. their containing block within an app's
|
|
349
392
|
// content layer, resized above the keyboard as it shows): read anew,
|
|
350
|
-
// what the keyboard covers of it now (none, its box above it).
|
|
351
|
-
|
|
352
|
-
|
|
393
|
+
// what the keyboard covers of it now (none, its box above it). The
|
|
394
|
+
// window's (no screen): its fixed layers' box, resized without the
|
|
395
|
+
// visual viewport telling (iOS, after its own scroll to a field, laid
|
|
396
|
+
// out shorter a frame, then back: the keyboard measured short, the
|
|
397
|
+
// bars left too low), read anew too.
|
|
398
|
+
const resizeObserver = new ResizeObserver(box
|
|
399
|
+
? () => {
|
|
353
400
|
isBoxDriven = true;
|
|
354
401
|
update();
|
|
355
|
-
}
|
|
356
|
-
:
|
|
357
|
-
|
|
358
|
-
resizeObserver?.observe(box);
|
|
402
|
+
}
|
|
403
|
+
: update);
|
|
404
|
+
resizeObserver.observe(box ?? fixedProbe());
|
|
359
405
|
const onViewport = () => {
|
|
360
406
|
isBoxDriven = false;
|
|
361
407
|
update();
|
|
@@ -364,6 +410,10 @@ const Provider = ({ children, screen: ownScreen, scroller, }) => {
|
|
|
364
410
|
viewport?.addEventListener('resize', onViewport);
|
|
365
411
|
viewport?.addEventListener('scroll', onViewport);
|
|
366
412
|
window.addEventListener('resize', onViewport);
|
|
413
|
+
// (Focus coming or going: the keyboard's only with it, see
|
|
414
|
+
// `readVisual`.)
|
|
415
|
+
document.addEventListener('focusin', onViewport);
|
|
416
|
+
document.addEventListener('focusout', onViewport);
|
|
367
417
|
// A screen moves with its page (any scroller's).
|
|
368
418
|
if (element) {
|
|
369
419
|
addEventListener('scroll', update, { capture: true, passive: true });
|
|
@@ -371,11 +421,13 @@ const Provider = ({ children, screen: ownScreen, scroller, }) => {
|
|
|
371
421
|
return () => {
|
|
372
422
|
cancelAnimationFrame(frame);
|
|
373
423
|
document.removeEventListener('visibilitychange', onVisibility);
|
|
374
|
-
resizeObserver
|
|
424
|
+
resizeObserver.disconnect();
|
|
375
425
|
clearTimeout(recheck);
|
|
376
426
|
viewport?.removeEventListener('resize', onViewport);
|
|
377
427
|
viewport?.removeEventListener('scroll', onViewport);
|
|
378
428
|
window.removeEventListener('resize', onViewport);
|
|
429
|
+
document.removeEventListener('focusin', onViewport);
|
|
430
|
+
document.removeEventListener('focusout', onViewport);
|
|
379
431
|
if (!element)
|
|
380
432
|
return;
|
|
381
433
|
removeEventListener('scroll', update, { capture: true });
|
|
@@ -590,7 +642,13 @@ const Provider = ({ children, screen: ownScreen, scroller, }) => {
|
|
|
590
642
|
}
|
|
591
643
|
};
|
|
592
644
|
}, [filling, scroll, scroller]);
|
|
593
|
-
const value = useMemo(() => ({
|
|
645
|
+
const value = useMemo(() => ({
|
|
646
|
+
filling,
|
|
647
|
+
screen,
|
|
648
|
+
scroll,
|
|
649
|
+
scroller,
|
|
650
|
+
visual,
|
|
651
|
+
}), [filling, screen, scroll, scroller, visual]);
|
|
594
652
|
return (_jsx(ViewportContext.Provider, { value: value, children: children }));
|
|
595
653
|
};
|
|
596
654
|
// A regular width: the window's, from 768px.
|
|
@@ -610,26 +668,71 @@ const regularQuery = '(width >= 768px)';
|
|
|
610
668
|
// ones) and the page's visibility (shown throughout) tell neither apart.
|
|
611
669
|
// - While hidden, the window still reads as the last snapshot's size, its
|
|
612
670
|
// media queries already the real one's; shown again, it's resized back.
|
|
671
|
+
// In a Safari tab (iPadOS 26, measured on an iPad Air), the second
|
|
672
|
+
// snapshot's `orientationchange` reports the first's orientation again
|
|
673
|
+
// (portrait), its window (585x820-ish, the tab's height) portrait too:
|
|
674
|
+
// matching, though nothing turned. The window's then resized back to its
|
|
675
|
+
// size before them, and the page hidden.
|
|
613
676
|
// So: from an `orientationchange` contradicting the window's shape, the
|
|
614
|
-
// size class held (no remount of a layout by it), until one matching it
|
|
615
|
-
//
|
|
677
|
+
// size class held (no remount of a layout by it), until one matching it
|
|
678
|
+
// in another orientation than the one that started the hold (a real
|
|
679
|
+
// rotation turns it), the window resized back to its size then, or the
|
|
680
|
+
// page shown anew (read anew). No timer. Only on iPadOS (see `isIpadOs`):
|
|
681
|
+
// elsewhere a window's shape contradicts the screen's orientation without
|
|
682
|
+
// any snapshot (e.g. desktop Chrome, reporting a touch point and a portrait
|
|
683
|
+
// screen, its window narrowed), never resized back by itself: held for
|
|
684
|
+
// good.
|
|
616
685
|
let isSnapshot = false;
|
|
686
|
+
/**
|
|
687
|
+
* Whether it's iPadOS (any of its browsers: WebKit's): its own
|
|
688
|
+
* `navigator.standalone`, and a multi-touch screen (an iPhone's never
|
|
689
|
+
* changes size class; a Mac's has no touch points).
|
|
690
|
+
*/
|
|
691
|
+
const isIpadOs = () => typeof navigator.standalone === 'boolean' &&
|
|
692
|
+
navigator.maxTouchPoints > 1;
|
|
617
693
|
let heldSizeClass;
|
|
618
|
-
/**
|
|
619
|
-
|
|
694
|
+
/** The hold's start: its orientation, the window's size before it. */
|
|
695
|
+
let heldFrom;
|
|
696
|
+
/** Whether the screen's orientation is portrait. */
|
|
697
|
+
const isScreenPortrait = () => {
|
|
620
698
|
const { orientation } = window.screen;
|
|
621
|
-
|
|
699
|
+
return typeof orientation === 'object'
|
|
622
700
|
? orientation.type.startsWith('portrait')
|
|
623
701
|
: Math.abs(window.orientation ?? 0) !== 90;
|
|
624
|
-
|
|
702
|
+
};
|
|
703
|
+
/** Whether the screen's orientation is the window's shape. */
|
|
704
|
+
const isOrientationTheWindows = () => isScreenPortrait() === innerHeight >= innerWidth;
|
|
705
|
+
/** The hold released: the size class read anew. */
|
|
706
|
+
const release = () => {
|
|
707
|
+
isSnapshot = false;
|
|
708
|
+
heldFrom = undefined;
|
|
625
709
|
};
|
|
626
710
|
if (typeof window !== 'undefined') {
|
|
627
711
|
window.addEventListener('orientationchange', () => {
|
|
628
|
-
|
|
712
|
+
if (!isIpadOs())
|
|
713
|
+
return;
|
|
714
|
+
const isPortrait = isScreenPortrait();
|
|
715
|
+
if (!isOrientationTheWindows()) {
|
|
716
|
+
if (!isSnapshot) {
|
|
717
|
+
heldFrom = { height: innerHeight, isPortrait, width: innerWidth };
|
|
718
|
+
}
|
|
719
|
+
isSnapshot = true;
|
|
720
|
+
}
|
|
721
|
+
else if (heldFrom?.isPortrait !== isPortrait) {
|
|
722
|
+
release();
|
|
723
|
+
}
|
|
724
|
+
});
|
|
725
|
+
// eslint-disable-next-line unicorn/prefer-observer-apis -- the window's own size (innerWidth/innerHeight), as the snapshots' events report it
|
|
726
|
+
window.addEventListener('resize', () => {
|
|
727
|
+
if (isSnapshot &&
|
|
728
|
+
innerWidth === heldFrom?.width &&
|
|
729
|
+
innerHeight === heldFrom.height) {
|
|
730
|
+
release();
|
|
731
|
+
}
|
|
629
732
|
});
|
|
630
733
|
document.addEventListener('visibilitychange', () => {
|
|
631
734
|
if (document.visibilityState === 'visible')
|
|
632
|
-
|
|
735
|
+
release();
|
|
633
736
|
});
|
|
634
737
|
}
|
|
635
738
|
const readSizeClass = () => {
|
|
@@ -643,13 +746,41 @@ const subscribeRegular = (onChange) => {
|
|
|
643
746
|
query.addEventListener('change', onChange);
|
|
644
747
|
// (Released: read anew, see above.)
|
|
645
748
|
window.addEventListener('orientationchange', onChange);
|
|
749
|
+
window.addEventListener('resize', onChange);
|
|
646
750
|
document.addEventListener('visibilitychange', onChange);
|
|
647
751
|
return () => {
|
|
648
752
|
query.removeEventListener('change', onChange);
|
|
649
753
|
window.removeEventListener('orientationchange', onChange);
|
|
754
|
+
window.removeEventListener('resize', onChange);
|
|
650
755
|
document.removeEventListener('visibilitychange', onChange);
|
|
651
756
|
};
|
|
652
757
|
};
|
|
758
|
+
/**
|
|
759
|
+
* The current scroller: what the user is looking at and would scroll, for
|
|
760
|
+
* the app to scroll for them (e.g. to its top, as its status bar is
|
|
761
|
+
* tapped). An open popover's body or sheet's content (the one opened
|
|
762
|
+
* last); else an island's content scrolled from its start; else the page
|
|
763
|
+
* its `Provider` tracks (the page filling its screen: e.g. a tab's shown).
|
|
764
|
+
* Again as any of that changes. Needs a `Provider`; without, `undefined`.
|
|
765
|
+
*/
|
|
766
|
+
export const useCurrentScroller = () => {
|
|
767
|
+
const context = useContext(ViewportContext);
|
|
768
|
+
const screen = context?.screen;
|
|
769
|
+
const layer = useSyncExternalStore(subscribeCurrent,
|
|
770
|
+
// (Its screen read as it's asked, not while rendering: a ref's set
|
|
771
|
+
// after.)
|
|
772
|
+
() => currentLayer(elementOf(screen)), () => undefined);
|
|
773
|
+
if (!context)
|
|
774
|
+
return undefined;
|
|
775
|
+
// (Else what it tracks: its `scroller`, the page filling its screen, or
|
|
776
|
+
// the document's.)
|
|
777
|
+
return (layer ??
|
|
778
|
+
context.scroller?.current ??
|
|
779
|
+
context.filling ??
|
|
780
|
+
// (No DOM, e.g. prerendering: none.)
|
|
781
|
+
(typeof document === 'undefined' ? undefined : document.scrollingElement) ??
|
|
782
|
+
undefined);
|
|
783
|
+
};
|
|
653
784
|
/**
|
|
654
785
|
* The window's horizontal size class (no `Provider` needed): e.g. a sheet
|
|
655
786
|
* on `compact` (a phone), a popover on `regular` (a tablet); `compact` before
|
|
@@ -851,16 +982,17 @@ const bounceAttribute = (alwaysBounce) => {
|
|
|
851
982
|
* (as padding), or not, by what it holds (`auto`, see style.css). For
|
|
852
983
|
* what's in it (e.g. a map's controls, kept clear of a bar or an island),
|
|
853
984
|
* its scope's anchors' sizes at its block edges, as a padding there makes
|
|
854
|
-
* room for them (beyond the safe area): `--uikit-viewport-anchor-block-start`
|
|
985
|
+
* room for them (beyond the safe area inset): `--uikit-viewport-anchor-block-start`
|
|
855
986
|
* and `-end` (px).
|
|
856
987
|
*/
|
|
857
|
-
const Content = forwardRef(({ alwaysBounce, children, className, keyboard = 'resize', safeArea = 'auto', style, ...props }, forwardedRef) => {
|
|
988
|
+
const Content = forwardRef(({ alwaysBounce, children, className, glass = 'auto', keyboard = 'resize', safeArea = 'auto', style, ...props }, forwardedRef) => {
|
|
858
989
|
const ref = useForwardedRef(forwardedRef);
|
|
859
990
|
useWindowHold(usePortalContainer(undefined));
|
|
860
991
|
useScrollerRegistration(ref);
|
|
992
|
+
const glassMode = useGlassMode(ref, glass, alwaysBounce === true);
|
|
861
993
|
const start = useAnchorSize('block-start');
|
|
862
994
|
const end = useAnchorSize('block-end');
|
|
863
|
-
return (_jsxs("div", { ref: ref, "data-always-bounce": bounceAttribute(alwaysBounce), "data-keyboard": keyboard, "data-safe-area": safeArea, style: withStyle({
|
|
995
|
+
return (_jsxs("div", { ref: ref, "data-always-bounce": bounceAttribute(alwaysBounce), "data-glass": glassMode, "data-keyboard": keyboard, "data-safe-area": safeArea, "data-viewport-focus-scroll": "target", style: withStyle({
|
|
864
996
|
'--uikit-viewport-anchor-block-end': `${String(end)}px`,
|
|
865
997
|
'--uikit-viewport-anchor-block-start': `${String(start)}px`,
|
|
866
998
|
}, style), ...props, className: cn('uikit-viewport-content', className), "data-viewport-part": "content", "data-viewport-scroller": "", children: [children, _jsx(EdgeEffects, { scroller: ref })] }));
|
|
@@ -931,21 +1063,44 @@ const Overscroll = forwardRef(({ anchor, className, edge = 'block-start', open =
|
|
|
931
1063
|
const BlockStart = forwardRef((props, ref) => (_jsx(Anchor, { ref: ref, edge: "block-start", ...props })));
|
|
932
1064
|
/** A bar at the block end (the bottom), above the keyboard (an `Anchor`). */
|
|
933
1065
|
const BlockEnd = forwardRef((props, ref) => (_jsx(Anchor, { ref: ref, edge: "block-end", ...props })));
|
|
1066
|
+
/** Frames an accessory waits at most for what's around it to settle. */
|
|
1067
|
+
const settleFrames = 60;
|
|
1068
|
+
/**
|
|
1069
|
+
* An accessory's bottom without its lift: the lift it shows now (its
|
|
1070
|
+
* translation, also mid-transition), not the one it's moving to.
|
|
1071
|
+
*/
|
|
1072
|
+
const unlifted = (element) => {
|
|
1073
|
+
const [, shown = '0'] = getComputedStyle(element).translate.split(' ');
|
|
1074
|
+
return (element.getBoundingClientRect().bottom - (Number.parseFloat(shown) || 0));
|
|
1075
|
+
};
|
|
934
1076
|
/**
|
|
935
1077
|
* What's typed into, kept above the keyboard (e.g. a field's row, with its
|
|
936
1078
|
* slider): while focus is within it and the keyboard covers it, lifted
|
|
937
1079
|
* (its own box moved up, its place kept) until its end is `gap` above the
|
|
938
1080
|
* keyboard, and above the bar the keyboard pushes up (a bottom anchor of
|
|
939
1081
|
* `keyboard` `push`, e.g. a message field's: on the keyboard, covering it
|
|
940
|
-
* too); back as focus leaves, or the keyboard hides.
|
|
941
|
-
*
|
|
1082
|
+
* too); back as focus leaves, or the keyboard hides. Nested, the innermost
|
|
1083
|
+
* around the focused element lifts, those around it staying (e.g. a color
|
|
1084
|
+
* picker's row in a popover, itself one). Needs a `Provider` (the
|
|
1085
|
+
* keyboard's height); without one, it stays.
|
|
942
1086
|
*/
|
|
943
1087
|
const KeyboardAccessory = forwardRef(({ className, gap = 8, ...props }, forwardedRef) => {
|
|
944
1088
|
const ref = useForwardedRef(forwardedRef);
|
|
945
1089
|
const { keyboardInset } = useVisualViewport();
|
|
946
1090
|
// (The bar on the keyboard, while it shows: covering it too.)
|
|
947
1091
|
const pushed = usePushedAnchorSize();
|
|
1092
|
+
// Focus within it, its own: not within another one in it (that one
|
|
1093
|
+
// lifting instead).
|
|
948
1094
|
const [isFocused, setIsFocused] = useState(false);
|
|
1095
|
+
// (Its screen's keyboard, or the window's: a screen resized above it,
|
|
1096
|
+
// e.g. within an app's resized content layer, has none, its accessory
|
|
1097
|
+
// still covered.)
|
|
1098
|
+
const isKeyboard = useCallback(() => {
|
|
1099
|
+
const { visualViewport: viewport } = window;
|
|
1100
|
+
return (keyboardInset > 0 ||
|
|
1101
|
+
(viewport !== null &&
|
|
1102
|
+
fixedBottom() > viewport.height + viewport.offsetTop));
|
|
1103
|
+
}, [keyboardInset]);
|
|
949
1104
|
// Lifted by what the keyboard covers of it (the visual viewport's bottom,
|
|
950
1105
|
// the window's: where the keyboard's top is, whatever the screen).
|
|
951
1106
|
const update = useCallback(() => {
|
|
@@ -954,40 +1109,68 @@ const KeyboardAccessory = forwardRef(({ className, gap = 8, ...props }, forwarde
|
|
|
954
1109
|
return;
|
|
955
1110
|
const { visualViewport: viewport } = window;
|
|
956
1111
|
let lift = 0;
|
|
957
|
-
|
|
958
|
-
// e.g. within an app's resized content layer, has none, its accessory
|
|
959
|
-
// still covered.)
|
|
960
|
-
const isKeyboard = keyboardInset > 0 ||
|
|
961
|
-
(viewport !== null && innerHeight > viewport.height + viewport.offsetTop);
|
|
962
|
-
if (isFocused && isKeyboard && viewport) {
|
|
963
|
-
// Its box without its lift: the lift it shows now (its translation,
|
|
964
|
-
// also mid-transition), not the one it's moving to.
|
|
965
|
-
const [, shown = '0'] = getComputedStyle(element).translate.split(' ');
|
|
966
|
-
const bottom = element.getBoundingClientRect().bottom -
|
|
967
|
-
(Number.parseFloat(shown) || 0);
|
|
1112
|
+
if (isFocused && isKeyboard() && viewport) {
|
|
968
1113
|
const keyboardTop = viewport.offsetTop + viewport.height - pushed;
|
|
969
|
-
lift = Math.max(0, Math.round(
|
|
1114
|
+
lift = Math.max(0, Math.round(unlifted(element) + gap - keyboardTop));
|
|
970
1115
|
}
|
|
971
1116
|
element.style.setProperty('--uikit-viewport-keyboard-lift', `${String(lift)}px`);
|
|
972
1117
|
element.toggleAttribute('data-lifted', lift > 0);
|
|
973
|
-
}, [gap, isFocused,
|
|
974
|
-
|
|
1118
|
+
}, [gap, isFocused, isKeyboard, pushed, ref]);
|
|
1119
|
+
// As the keyboard shows (or focus moves in; the visual viewport changed,
|
|
1120
|
+
// as the keyboard does): lifted once what's around it has settled
|
|
1121
|
+
// (unmoved for two frames: e.g. a sheet the keyboard lifts itself, moving
|
|
1122
|
+
// it up with it, by as much less: not lifted twice, nor apart). Back down
|
|
1123
|
+
// at once (no keyboard, or focus gone).
|
|
1124
|
+
const frame = useRef(0);
|
|
1125
|
+
const settle = useCallback(() => {
|
|
1126
|
+
cancelAnimationFrame(frame.current);
|
|
1127
|
+
const { current: element } = ref;
|
|
1128
|
+
if (!element || !isFocused || !isKeyboard()) {
|
|
1129
|
+
update();
|
|
1130
|
+
return;
|
|
1131
|
+
}
|
|
1132
|
+
let last = Number.NaN;
|
|
1133
|
+
let stable = 0;
|
|
1134
|
+
let frames = 0;
|
|
1135
|
+
const step = () => {
|
|
1136
|
+
const bottom = Math.round(unlifted(element));
|
|
1137
|
+
stable = bottom === last ? stable + 1 : 0;
|
|
1138
|
+
last = bottom;
|
|
1139
|
+
frames += 1;
|
|
1140
|
+
if (stable >= 2 || frames >= settleFrames) {
|
|
1141
|
+
update();
|
|
1142
|
+
return;
|
|
1143
|
+
}
|
|
1144
|
+
frame.current = requestAnimationFrame(step);
|
|
1145
|
+
};
|
|
1146
|
+
step();
|
|
1147
|
+
}, [isFocused, isKeyboard, ref, update]);
|
|
1148
|
+
useLayoutEffect(() => {
|
|
1149
|
+
settle();
|
|
1150
|
+
return () => {
|
|
1151
|
+
cancelAnimationFrame(frame.current);
|
|
1152
|
+
};
|
|
1153
|
+
}, [settle]);
|
|
975
1154
|
// Focus within it (`focusin`, `focusout`: they bubble, unlike a `focus`
|
|
976
1155
|
// listener's events, e.g. Preact's `onFocus`).
|
|
977
1156
|
useEffect(() => {
|
|
978
1157
|
const { current: element } = ref;
|
|
979
1158
|
if (!element)
|
|
980
1159
|
return undefined;
|
|
981
|
-
|
|
1160
|
+
// (Its own: the focused element's nearest accessory is it.)
|
|
1161
|
+
const isOwn = (target) => target instanceof Element &&
|
|
1162
|
+
element.contains(target) &&
|
|
1163
|
+
target.closest('[data-viewport-part="keyboard-accessory"]') === element;
|
|
1164
|
+
const onFocusIn = ({ target }) => setIsFocused(isOwn(target));
|
|
982
1165
|
const onFocusOut = ({ relatedTarget }) => {
|
|
983
|
-
// (Focus moving within it:
|
|
1166
|
+
// (Focus moving within it: told by its `focusin`.)
|
|
984
1167
|
if (relatedTarget instanceof Node && element.contains(relatedTarget)) {
|
|
985
1168
|
return;
|
|
986
1169
|
}
|
|
987
1170
|
setIsFocused(false);
|
|
988
1171
|
};
|
|
989
1172
|
// (Focused already: e.g. a sheet's initial focus, before this.)
|
|
990
|
-
setIsFocused(
|
|
1173
|
+
setIsFocused(isOwn(document.activeElement));
|
|
991
1174
|
element.addEventListener('focusin', onFocusIn);
|
|
992
1175
|
element.addEventListener('focusout', onFocusOut);
|
|
993
1176
|
return () => {
|
|
@@ -995,25 +1178,36 @@ const KeyboardAccessory = forwardRef(({ className, gap = 8, ...props }, forwarde
|
|
|
995
1178
|
element.removeEventListener('focusout', onFocusOut);
|
|
996
1179
|
};
|
|
997
1180
|
}, [ref]);
|
|
998
|
-
// Moved meanwhile
|
|
1181
|
+
// Moved meanwhile: scrolled, anew at once; the visual viewport changed
|
|
1182
|
+
// (the keyboard), once settled (see above).
|
|
999
1183
|
useEffect(() => {
|
|
1000
1184
|
if (!isFocused)
|
|
1001
1185
|
return undefined;
|
|
1002
1186
|
const { visualViewport: viewport } = window;
|
|
1003
1187
|
const options = { capture: true, passive: true };
|
|
1004
1188
|
addEventListener('scroll', update, options);
|
|
1005
|
-
viewport?.addEventListener('resize',
|
|
1006
|
-
viewport?.addEventListener('scroll',
|
|
1189
|
+
viewport?.addEventListener('resize', settle);
|
|
1190
|
+
viewport?.addEventListener('scroll', settle);
|
|
1007
1191
|
return () => {
|
|
1008
1192
|
removeEventListener('scroll', update, options);
|
|
1009
|
-
viewport?.removeEventListener('resize',
|
|
1010
|
-
viewport?.removeEventListener('scroll',
|
|
1193
|
+
viewport?.removeEventListener('resize', settle);
|
|
1194
|
+
viewport?.removeEventListener('scroll', settle);
|
|
1011
1195
|
};
|
|
1012
|
-
}, [isFocused, update]);
|
|
1013
|
-
return (_jsx("div", { ref: ref, ...props, className: cn('uikit-viewport-keyboard-accessory', className), "data-viewport-part": "keyboard-accessory" }));
|
|
1196
|
+
}, [isFocused, settle, update]);
|
|
1197
|
+
return (_jsx("div", { ref: ref, "data-viewport-focus-scroll": "none", ...props, className: cn('uikit-viewport-keyboard-accessory', className), "data-viewport-part": "keyboard-accessory" }));
|
|
1014
1198
|
});
|
|
1199
|
+
/**
|
|
1200
|
+
* The screen's background (a layer): behind its content layer and all its
|
|
1201
|
+
* other layers, filling its screen (the window, or a provider's screen),
|
|
1202
|
+
* not scrolling, not moved by the keyboard. Its children layered, each
|
|
1203
|
+
* filling it (images and videos covering it): e.g. a picture, a map or a
|
|
1204
|
+
* video, showing where nothing in front paints (e.g. beside a layout's
|
|
1205
|
+
* floating column, or between its columns).
|
|
1206
|
+
*/
|
|
1207
|
+
const Background = forwardRef(({ className, ...props }, ref) => (_jsx("div", { ref: ref, ...props, className: cn('uikit-viewport-background', className), "data-viewport-part": "background" })));
|
|
1015
1208
|
export const Viewport = {
|
|
1016
1209
|
Provider,
|
|
1210
|
+
Background,
|
|
1017
1211
|
Anchor,
|
|
1018
1212
|
Content,
|
|
1019
1213
|
BlockStart,
|