@knitui/components 1.2.2 → 1.3.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/lib/commonjs/Avatar/Avatar.js +22 -10
- package/lib/commonjs/Avatar/Avatar.js.map +1 -1
- package/lib/commonjs/Modal/index.js +18 -0
- package/lib/commonjs/Modal/index.js.map +1 -1
- package/lib/commonjs/Modal/modal-base.js +20 -15
- package/lib/commonjs/Modal/modal-base.js.map +1 -1
- package/lib/commonjs/Modal/modal-stack.js +87 -0
- package/lib/commonjs/Modal/modal-stack.js.map +1 -0
- package/lib/commonjs/Portal/OverlayPortal.js +7 -1
- package/lib/commonjs/Portal/OverlayPortal.js.map +1 -1
- package/lib/commonjs/Portal/index.js +19 -0
- package/lib/commonjs/Portal/index.js.map +1 -1
- package/lib/commonjs/Portal/teleported-layer-scope.js +72 -0
- package/lib/commonjs/Portal/teleported-layer-scope.js.map +1 -0
- package/lib/commonjs/ScrollArea/ScrollArea.js +23 -1
- package/lib/commonjs/ScrollArea/ScrollArea.js.map +1 -1
- package/lib/commonjs/ScrollArea/ScrollArea.native.js +70 -61
- package/lib/commonjs/ScrollArea/ScrollArea.native.js.map +1 -1
- package/lib/commonjs/index.js +30 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/Avatar/Avatar.js +22 -10
- package/lib/module/Avatar/Avatar.js.map +1 -1
- package/lib/module/Modal/index.js +1 -0
- package/lib/module/Modal/index.js.map +1 -1
- package/lib/module/Modal/modal-base.js +20 -15
- package/lib/module/Modal/modal-base.js.map +1 -1
- package/lib/module/Modal/modal-stack.js +80 -0
- package/lib/module/Modal/modal-stack.js.map +1 -0
- package/lib/module/Portal/OverlayPortal.js +8 -2
- package/lib/module/Portal/OverlayPortal.js.map +1 -1
- package/lib/module/Portal/index.js +1 -0
- package/lib/module/Portal/index.js.map +1 -1
- package/lib/module/Portal/teleported-layer-scope.js +66 -0
- package/lib/module/Portal/teleported-layer-scope.js.map +1 -0
- package/lib/module/ScrollArea/ScrollArea.js +23 -1
- package/lib/module/ScrollArea/ScrollArea.js.map +1 -1
- package/lib/module/ScrollArea/ScrollArea.native.js +70 -61
- package/lib/module/ScrollArea/ScrollArea.native.js.map +1 -1
- package/lib/module/index.js +2 -2
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/Avatar/Avatar.d.ts +5 -0
- package/lib/typescript/Avatar/Avatar.d.ts.map +1 -1
- package/lib/typescript/Modal/index.d.ts +1 -0
- package/lib/typescript/Modal/index.d.ts.map +1 -1
- package/lib/typescript/Modal/modal-base.d.ts +2 -2
- package/lib/typescript/Modal/modal-base.d.ts.map +1 -1
- package/lib/typescript/Modal/modal-stack.d.ts +45 -0
- package/lib/typescript/Modal/modal-stack.d.ts.map +1 -0
- package/lib/typescript/Portal/OverlayPortal.d.ts.map +1 -1
- package/lib/typescript/Portal/index.d.ts +1 -0
- package/lib/typescript/Portal/index.d.ts.map +1 -1
- package/lib/typescript/Portal/teleported-layer-scope.d.ts +41 -0
- package/lib/typescript/Portal/teleported-layer-scope.d.ts.map +1 -0
- package/lib/typescript/ScrollArea/ScrollArea.d.ts.map +1 -1
- package/lib/typescript/ScrollArea/ScrollArea.native.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +3 -3
- package/lib/typescript/index.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/Avatar/Avatar.tsx +24 -8
- package/src/Modal/index.ts +1 -0
- package/src/Modal/modal-base.tsx +17 -18
- package/src/Modal/modal-stack.ts +100 -0
- package/src/Portal/OverlayPortal.tsx +9 -2
- package/src/Portal/index.ts +6 -0
- package/src/Portal/teleported-layer-scope.tsx +73 -0
- package/src/ScrollArea/ScrollArea.native.tsx +85 -74
- package/src/ScrollArea/ScrollArea.tsx +47 -1
- package/src/index.ts +8 -1
|
@@ -4,9 +4,9 @@ import * as React from "react";
|
|
|
4
4
|
import { createStyledContext, styleable, styled, Theme, withStaticProperties } from "@knitui/core";
|
|
5
5
|
import { Box } from "../Box";
|
|
6
6
|
import { Image } from "../Image";
|
|
7
|
+
import { resolveSizePx } from "../internal/control-metrics";
|
|
7
8
|
import { gradientForVariant, useGradient } from "../internal/gradient";
|
|
8
9
|
import { controlTextColorVariant, fontSizePassthroughVariant, pickVariants, radiusVariant, squareSizeVariantFallthrough, surfaceColorVariant, tableVariant } from "../internal/style-props";
|
|
9
|
-
import { resolveSizePx } from "../internal/control-metrics";
|
|
10
10
|
import { slotStyles } from "../internal/styles";
|
|
11
11
|
import { Text } from "../Text";
|
|
12
12
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
@@ -126,6 +126,7 @@ const AvatarComponent = styleable(AvatarFrame, function Avatar(props, ref) {
|
|
|
126
126
|
children,
|
|
127
127
|
name,
|
|
128
128
|
src,
|
|
129
|
+
fallbackSrc,
|
|
129
130
|
alt,
|
|
130
131
|
size = "md",
|
|
131
132
|
variant = "light",
|
|
@@ -145,12 +146,24 @@ const AvatarComponent = styleable(AvatarFrame, function Avatar(props, ref) {
|
|
|
145
146
|
// `backgroundImage`; native renders the `layer` behind the placeholder.
|
|
146
147
|
const grad = useGradient(gradientForVariant(variant, gradient));
|
|
147
148
|
|
|
148
|
-
//
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
149
|
+
// The images to try, in order: `src`, then `fallbackSrc`; after both fail, the
|
|
150
|
+
// placeholder. The failure count belongs to one pair of sources and resets the
|
|
151
|
+
// moment either changes (during render, so a new `src` never flashes the
|
|
152
|
+
// initials for a frame the way an effect-based reset would).
|
|
153
|
+
const sourceKey = `${src ?? ""}\n${fallbackSrc ?? ""}`;
|
|
154
|
+
const [failures, setFailures] = React.useState({
|
|
155
|
+
key: sourceKey,
|
|
156
|
+
count: 0
|
|
157
|
+
});
|
|
158
|
+
const failed = failures.key === sourceKey ? failures.count : 0;
|
|
159
|
+
const handleImageError = React.useCallback(() => setFailures(f => ({
|
|
160
|
+
key: sourceKey,
|
|
161
|
+
count: (f.key === sourceKey ? f.count : 0) + 1
|
|
162
|
+
})), [sourceKey]);
|
|
163
|
+
const candidates = [src, fallbackSrc].filter(u => !!u);
|
|
164
|
+
const currentSrc = candidates[failed];
|
|
152
165
|
const placeholder = children ?? (name ? getInitials(name) : null);
|
|
153
|
-
const showImage =
|
|
166
|
+
const showImage = currentSrc !== undefined;
|
|
154
167
|
const inner = /*#__PURE__*/_jsxs(AvatarFrame, {
|
|
155
168
|
ref: ref,
|
|
156
169
|
size: size,
|
|
@@ -167,11 +180,10 @@ const AvatarComponent = styleable(AvatarFrame, function Avatar(props, ref) {
|
|
|
167
180
|
...s.get("root"),
|
|
168
181
|
...rest,
|
|
169
182
|
children: [grad.layer, showImage ? /*#__PURE__*/_jsx(Image
|
|
170
|
-
//
|
|
171
|
-
// load-error handler) so the engine's own wiring always wins.
|
|
183
|
+
// A new element per source, so a failed image's state never carries over.
|
|
172
184
|
, {
|
|
173
185
|
...s.merge("image", {
|
|
174
|
-
src,
|
|
186
|
+
src: currentSrc,
|
|
175
187
|
// The frame already carries role="img" + aria-label; an empty alt
|
|
176
188
|
// keeps the photo itself out of the accessibility tree (WCAG 1.1.1:
|
|
177
189
|
// without one some screen readers announce the file name).
|
|
@@ -184,7 +196,7 @@ const AvatarComponent = styleable(AvatarFrame, function Avatar(props, ref) {
|
|
|
184
196
|
} : null),
|
|
185
197
|
onError: handleImageError
|
|
186
198
|
})
|
|
187
|
-
}) : typeof placeholder === "string" ? /*#__PURE__*/_jsx(AvatarText, {
|
|
199
|
+
}, currentSrc) : typeof placeholder === "string" ? /*#__PURE__*/_jsx(AvatarText, {
|
|
188
200
|
size: size,
|
|
189
201
|
variant: variant,
|
|
190
202
|
...s.get("text"),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","createStyledContext","styleable","styled","Theme","withStaticProperties","Box","Image","gradientForVariant","useGradient","controlTextColorVariant","fontSizePassthroughVariant","pickVariants","radiusVariant","squareSizeVariantFallthrough","surfaceColorVariant","tableVariant","
|
|
1
|
+
{"version":3,"names":["React","createStyledContext","styleable","styled","Theme","withStaticProperties","Box","Image","resolveSizePx","gradientForVariant","useGradient","controlTextColorVariant","fontSizePassthroughVariant","pickVariants","radiusVariant","squareSizeVariantFallthrough","surfaceColorVariant","tableVariant","slotStyles","Text","jsx","_jsx","jsxs","_jsxs","getAvatarSize","size","ACCENT_COLORS","hashString","s","h","i","length","charCodeAt","pickColor","name","allowed","AvatarGroupContext","withinGroup","spacing","avatarSpacing","val","marginLeft","AvatarFrame","displayName","context","alignItems","justifyContent","overflow","borderRadius","boxSizing","borderWidth","borderColor","variants","variant","outline","default","radius","true","defaultVariants","AvatarText","userSelect","fontWeight","getInitials","limit","parts","trim","split","slice","toUpperCase","map","word","join","AVATAR_SLOT_KEYS","AvatarComponent","Avatar","props","ref","children","src","fallbackSrc","alt","autoColor","allowedInitialsColors","theme","styles","gradient","rest","grad","sourceKey","failures","setFailures","useState","key","count","failed","handleImageError","useCallback","f","candidates","filter","u","currentSrc","placeholder","showImage","undefined","inner","role","frameProps","get","layer","merge","width","height","fit","onError","colorTheme","AvatarGroupFrame","flexDirection","AvatarGroup","Provider","paddingLeft","Frame","Group"],"sourceRoot":"../../../src","sources":["Avatar/Avatar.tsx"],"mappings":";;AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAE9B,SACEC,mBAAmB,EAEnBC,SAAS,EACTC,MAAM,EACNC,KAAK,EACLC,oBAAoB,QACf,cAAc;AAErB,SAASC,GAAG,QAAQ,QAAQ;AAC5B,SAASC,KAAK,QAAyB,UAAU;AACjD,SAASC,aAAa,QAAQ,6BAA6B;AAC3D,SAASC,kBAAkB,EAAsBC,WAAW,QAAQ,sBAAsB;AAC1F,SACEC,uBAAuB,EAEvBC,0BAA0B,EAC1BC,YAAY,EACZC,aAAa,EAEbC,4BAA4B,EAC5BC,mBAAmB,EACnBC,YAAY,QACP,yBAAyB;AAChC,SAASC,UAAU,QAAyB,oBAAoB;AAChE,SAASC,IAAI,QAAQ,SAAS;AAAC,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ACe,kBAAkB,CAACmF,QAAQ;IAAClF,WAAW;IAACC,OAAO,EAAEA,OAAQ;IAAAuC,QAAA,eACxDxD,IAAA,CAAC+F,gBAAgB;MAACxC,GAAG,EAAEA,GAAI;MAAC4C,WAAW,EAAElF,OAAQ;MAAA,GAAKgD,IAAI;MAAAT,QAAA,EACvDA;IAAQ,CACO;EAAC,CACQ,CAAC;AAElC,CACF,CAAC;AAED,OAAO,MAAMH,MAAM,GAAGrE,oBAAoB,CAACoE,eAAe,EAAE;EAC1DtD,IAAI,EAAEwC,UAAU;EAChBpD,KAAK,EAAEA,KAAK;EACZkH,KAAK,EAAE/E,WAAW;EAClBgF,KAAK,EAAEJ;AACT,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["Modal/index.ts"],"mappings":";;AAAA,cAAc,SAAS","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["hasOpenEscapeLayer","useEscapeLayer"],"sourceRoot":"../../../src","sources":["Modal/index.ts"],"mappings":";;AAAA,cAAc,SAAS;AACvB,SAAkCA,kBAAkB,EAAEC,cAAc,QAAQ,eAAe","ignoreList":[]}
|
|
@@ -8,6 +8,7 @@ import { slotStyles } from "../internal/styles";
|
|
|
8
8
|
import { Overlay } from "../Overlay";
|
|
9
9
|
import { OverlayPortal, useOverlayHost } from "../Portal";
|
|
10
10
|
import { ModalBaseInner } from "./modal-base-inner";
|
|
11
|
+
import { useEscapeLayer } from "./modal-stack";
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* Shared scaffolding for `Modal` and `Drawer` — mirrors Mantine's `ModalBase`.
|
|
@@ -19,8 +20,8 @@ import { ModalBaseInner } from "./modal-base-inner";
|
|
|
19
20
|
* - paints a full-cover `Overlay` scrim BEHIND the content (content frames carry
|
|
20
21
|
* `position:"relative", zIndex:1`; the scrim sits at `zIndex:0`), so a click on
|
|
21
22
|
* the empty area around the content hits the scrim and closes,
|
|
22
|
-
* - wires the web-only side effects: Escape to close
|
|
23
|
-
* return-focus on close.
|
|
23
|
+
* - wires the web-only side effects: Escape to close (top layer of a stack
|
|
24
|
+
* only, see `modal-stack.ts`), body scroll-lock, and return-focus on close.
|
|
24
25
|
*
|
|
25
26
|
* `trapFocus` traps keyboard focus within the content on web via the shared
|
|
26
27
|
* `useFocusTrap` hook (no-op on native — there is no DOM focus model, the same
|
|
@@ -150,23 +151,27 @@ export function ModalBase(props) {
|
|
|
150
151
|
};
|
|
151
152
|
}, [opened]);
|
|
152
153
|
|
|
153
|
-
//
|
|
154
|
-
//
|
|
155
|
-
//
|
|
156
|
-
//
|
|
154
|
+
// Escape: every open layer registers on the shared modal stack, which routes
|
|
155
|
+
// the key to the TOP layer only — a stack of modals unwinds one per press, and
|
|
156
|
+
// focus returns to each layer's own opener via the effect above. Registered
|
|
157
|
+
// regardless of `closeOnEscape` so a non-dismissable top layer swallows Escape
|
|
158
|
+
// rather than letting it close the layer beneath. A descendant that already
|
|
159
|
+
// handled Escape (`defaultPrevented`, e.g. a nested Select closing its own
|
|
160
|
+
// dropdown) is respected. The latest `closeOnEscape` is read at keydown time.
|
|
161
|
+
useEscapeLayer(opened, {
|
|
162
|
+
closeOnEscape,
|
|
163
|
+
onClose: () => onCloseRef.current()
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
// Body scroll-lock (web; inert on native — no body element).
|
|
157
167
|
React.useEffect(() => {
|
|
158
|
-
if (!opened || typeof document === "undefined") return;
|
|
159
|
-
const onKeyDown = event => {
|
|
160
|
-
if (event.key === "Escape" && !event.defaultPrevented) onCloseRef.current();
|
|
161
|
-
};
|
|
162
|
-
if (closeOnEscape) document.addEventListener("keydown", onKeyDown);
|
|
168
|
+
if (!opened || !lockScroll || typeof document === "undefined") return;
|
|
163
169
|
const previousOverflow = document.body.style.overflow;
|
|
164
|
-
|
|
170
|
+
document.body.style.overflow = "hidden";
|
|
165
171
|
return () => {
|
|
166
|
-
|
|
167
|
-
if (lockScroll) document.body.style.overflow = previousOverflow;
|
|
172
|
+
document.body.style.overflow = previousOverflow;
|
|
168
173
|
};
|
|
169
|
-
}, [opened,
|
|
174
|
+
}, [opened, lockScroll]);
|
|
170
175
|
|
|
171
176
|
// The full-cover positioning layer: scrim + the consumer's content frame. The
|
|
172
177
|
// `display` toggle only matters on the `keepMounted` path (where the node never
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","AnimatePresence","isWeb","Theme","useThemeName","useFocusTrap","useMotionPreset","slotStyles","Overlay","OverlayPortal","useOverlayHost","ModalBaseInner","jsx","_jsx","jsxs","_jsxs","MODAL_CHROME_SLOTS","resolveModalChromeSlots","styles","displayName","s","overlay","get","content","header","title","body","closeButton","ModalBase","props","opened","onClose","closeOnEscape","closeOnClickOutside","lockScroll","returnFocus","trapFocus","withinPortal","keepMounted","withOverlay","overlayProps","zIndex","overlayAnimation","children","direction","align","justify","padding","paddingVertical","paddingHorizontal","themeName","overlayHost","trapRef","overlayMotion","onCloseRef","useRef","current","returnFocusRef","wasOpenedRef","previouslyFocusedRef","document","activeElement","useEffect","focus","
|
|
1
|
+
{"version":3,"names":["React","AnimatePresence","isWeb","Theme","useThemeName","useFocusTrap","useMotionPreset","slotStyles","Overlay","OverlayPortal","useOverlayHost","ModalBaseInner","useEscapeLayer","jsx","_jsx","jsxs","_jsxs","MODAL_CHROME_SLOTS","resolveModalChromeSlots","styles","displayName","s","overlay","get","content","header","title","body","closeButton","ModalBase","props","opened","onClose","closeOnEscape","closeOnClickOutside","lockScroll","returnFocus","trapFocus","withinPortal","keepMounted","withOverlay","overlayProps","zIndex","overlayAnimation","children","direction","align","justify","padding","paddingVertical","paddingHorizontal","themeName","overlayHost","trapRef","overlayMotion","onCloseRef","useRef","current","returnFocusRef","wasOpenedRef","previouslyFocusedRef","document","activeElement","useEffect","focus","previousOverflow","style","overflow","layer","name","ref","position","display","pointerEvents","flexDirection","undefined","alignItems","justifyContent","onPress","hostName"],"sourceRoot":"../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AEJ,CAAC,GACd;EAAI,CACO,CAAC;AAEtB","ignoreList":[]}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Module-level stack of the open modal layers (`Modal`, `Drawer`, and a modal
|
|
7
|
+
* `Sheet` through {@link useEscapeLayer}), in open order. One shared `document` keydown listener routes Escape to the TOP entry
|
|
8
|
+
* only, so a stack of modals unwinds one layer per press instead of every open
|
|
9
|
+
* layer closing at once (each layer used to own its own document listener).
|
|
10
|
+
*
|
|
11
|
+
* Every open layer registers, including those with `closeOnEscape={false}`: such
|
|
12
|
+
* a layer still occupies the top, so Escape is swallowed rather than falling
|
|
13
|
+
* through to the layer beneath it.
|
|
14
|
+
*
|
|
15
|
+
* Inert on native (no `document`); the stack still tracks but nothing listens.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const stack = [];
|
|
19
|
+
let counter = 0;
|
|
20
|
+
|
|
21
|
+
/** A fresh, increasing open-order key (see {@link ModalStackEntry.order}). */
|
|
22
|
+
export function nextModalOrder() {
|
|
23
|
+
counter += 1;
|
|
24
|
+
return counter;
|
|
25
|
+
}
|
|
26
|
+
function onKeyDown(event) {
|
|
27
|
+
if (event.key !== "Escape" || event.defaultPrevented) return;
|
|
28
|
+
const top = stack[stack.length - 1];
|
|
29
|
+
if (!top || !top.closeOnEscape()) return;
|
|
30
|
+
// Mark the event handled so any other Escape consumer (and a layer that
|
|
31
|
+
// becomes the top later in this same dispatch) leaves it alone.
|
|
32
|
+
event.preventDefault();
|
|
33
|
+
top.onClose();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Push `entry` onto the stack; returns the matching unregister. */
|
|
37
|
+
export function registerModalLayer(entry) {
|
|
38
|
+
let index = stack.length;
|
|
39
|
+
while (index > 0 && stack[index - 1].order > entry.order) index -= 1;
|
|
40
|
+
stack.splice(index, 0, entry);
|
|
41
|
+
if (stack.length === 1 && typeof document !== "undefined") {
|
|
42
|
+
document.addEventListener("keydown", onKeyDown);
|
|
43
|
+
}
|
|
44
|
+
return () => {
|
|
45
|
+
const index = stack.lastIndexOf(entry);
|
|
46
|
+
if (index !== -1) stack.splice(index, 1);
|
|
47
|
+
if (stack.length === 0 && typeof document !== "undefined") {
|
|
48
|
+
document.removeEventListener("keydown", onKeyDown);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Whether any modal layer is open (so a non-modal surface leaves Escape to it). */
|
|
54
|
+
export function hasOpenEscapeLayer() {
|
|
55
|
+
return stack.length > 0;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Put a modal layer on the shared Escape stack while `opened`: Escape then
|
|
59
|
+
* closes only the topmost open layer, whichever component it belongs to. The
|
|
60
|
+
* open order is taken on the render that opens the layer (see
|
|
61
|
+
* {@link ModalStackEntry.order}); the latest options are read at keydown time.
|
|
62
|
+
* Web only in effect; on native there is no keydown stream.
|
|
63
|
+
*/
|
|
64
|
+
export function useEscapeLayer(opened, options) {
|
|
65
|
+
const optionsRef = React.useRef(options);
|
|
66
|
+
optionsRef.current = options;
|
|
67
|
+
const wasOpenedRef = React.useRef(false);
|
|
68
|
+
const orderRef = React.useRef(0);
|
|
69
|
+
if (opened && !wasOpenedRef.current) orderRef.current = nextModalOrder();
|
|
70
|
+
wasOpenedRef.current = opened;
|
|
71
|
+
React.useEffect(() => {
|
|
72
|
+
if (!opened) return undefined;
|
|
73
|
+
return registerModalLayer({
|
|
74
|
+
order: orderRef.current,
|
|
75
|
+
closeOnEscape: () => optionsRef.current.closeOnEscape ?? true,
|
|
76
|
+
onClose: () => optionsRef.current.onClose()
|
|
77
|
+
});
|
|
78
|
+
}, [opened]);
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=modal-stack.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","stack","counter","nextModalOrder","onKeyDown","event","key","defaultPrevented","top","length","closeOnEscape","preventDefault","onClose","registerModalLayer","entry","index","order","splice","document","addEventListener","lastIndexOf","removeEventListener","hasOpenEscapeLayer","useEscapeLayer","opened","options","optionsRef","useRef","current","wasOpenedRef","orderRef","useEffect","undefined"],"sourceRoot":"../../../src","sources":["Modal/modal-stack.ts"],"mappings":";;AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;;AAE9B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAeA,MAAMC,KAAwB,GAAG,EAAE;AACnC,IAAIC,OAAO,GAAG,CAAC;;AAEf;AACA,OAAO,SAASC,cAAcA,CAAA,EAAW;EACvCD,OAAO,IAAI,CAAC;EACZ,OAAOA,OAAO;AAChB;AAEA,SAASE,SAASA,CAACC,KAAoB,EAAE;EACvC,IAAIA,KAAK,CAACC,GAAG,KAAK,QAAQ,IAAID,KAAK,CAACE,gBAAgB,EAAE;EACtD,MAAMC,GAAG,GAAGP,KAAK,CAACA,KAAK,CAACQ,MAAM,GAAG,CAAC,CAAC;EACnC,IAAI,CAACD,GAAG,IAAI,CAACA,GAAG,CAACE,aAAa,CAAC,CAAC,EAAE;EAClC;EACA;EACAL,KAAK,CAACM,cAAc,CAAC,CAAC;EACtBH,GAAG,CAACI,OAAO,CAAC,CAAC;AACf;;AAEA;AACA,OAAO,SAASC,kBAAkBA,CAACC,KAAsB,EAAc;EACrE,IAAIC,KAAK,GAAGd,KAAK,CAACQ,MAAM;EACxB,OAAOM,KAAK,GAAG,CAAC,IAAId,KAAK,CAACc,KAAK,GAAG,CAAC,CAAC,CAACC,KAAK,GAAGF,KAAK,CAACE,KAAK,EAAED,KAAK,IAAI,CAAC;EACpEd,KAAK,CAACgB,MAAM,CAACF,KAAK,EAAE,CAAC,EAAED,KAAK,CAAC;EAC7B,IAAIb,KAAK,CAACQ,MAAM,KAAK,CAAC,IAAI,OAAOS,QAAQ,KAAK,WAAW,EAAE;IACzDA,QAA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AAMc,UAAU,CAACE,OAAO,CAAChB,OAAO,CAAC;IAC5C,CAAC,CAAC;EACJ,CAAC,EAAE,CAACY,MAAM,CAAC,CAAC;AACd","ignoreList":[]}
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
import * as React from "react";
|
|
4
4
|
import { Portal } from "react-native-teleport";
|
|
5
|
-
import { useScreenFocused } from "@knitui/core";
|
|
5
|
+
import { isWeb, useScreenFocused } from "@knitui/core";
|
|
6
|
+
import { useRegisterTeleportedLayer } from "./teleported-layer-scope";
|
|
6
7
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
8
|
/**
|
|
8
9
|
* The portal the kit's overlays render through: a `Portal` that teleports into
|
|
@@ -20,8 +21,13 @@ export function OverlayPortal({
|
|
|
20
21
|
children
|
|
21
22
|
}) {
|
|
22
23
|
const focused = useScreenFocused();
|
|
24
|
+
const target = focused ? hostName : undefined;
|
|
25
|
+
// Native: while teleported, tell the scrollers this layer sits inside (in
|
|
26
|
+
// React) to stop capturing its first tap to dismiss the keyboard (see
|
|
27
|
+
// `teleported-layer-scope.tsx`). Web has no such capture.
|
|
28
|
+
useRegisterTeleportedLayer(!isWeb && target !== undefined);
|
|
23
29
|
return /*#__PURE__*/_jsx(Portal, {
|
|
24
|
-
hostName:
|
|
30
|
+
hostName: target,
|
|
25
31
|
children: children
|
|
26
32
|
});
|
|
27
33
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","Portal","useScreenFocused","jsx","_jsx","OverlayPortal","hostName","children","focused","undefined"],"sourceRoot":"../../../src","sources":["Portal/OverlayPortal.tsx"],"mappings":";;AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,MAAM,QAAQ,uBAAuB;AAE9C,SAASC,gBAAgB,QAAQ,cAAc;AAAC,SAAAC,GAAA,IAAAC,IAAA;
|
|
1
|
+
{"version":3,"names":["React","Portal","isWeb","useScreenFocused","useRegisterTeleportedLayer","jsx","_jsx","OverlayPortal","hostName","children","focused","target","undefined"],"sourceRoot":"../../../src","sources":["Portal/OverlayPortal.tsx"],"mappings":";;AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,MAAM,QAAQ,uBAAuB;AAE9C,SAASC,KAAK,EAAEC,gBAAgB,QAAQ,cAAc;AAEtD,SAASC,0BAA0B,QAAQ,0BAA0B;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAQtE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,aAAaA,CAAC;EAAEC,QAAQ;EAAEC;AAA6B,CAAC,EAAE;EACxE,MAAMC,OAAO,GAAGP,gBAAgB,CAAC,CAAC;EAClC,MAAMQ,MAAM,GAAGD,OAAO,GAAGF,QAAQ,GAAGI,SAAS;EAC7C;EACA;EACA;EACAR,0BAA0B,CAAC,CAACF,KAAK,IAAIS,MAAM,KAAKC,SAAS,CAAC;EAC1D,oBAAON,IAAA,CAACL,MAAM;IAACO,QAAQ,EAAEG,MAAO;IAAAF,QAAA,EAAEA;EAAQ,CAAS,CAAC;AACtD","ignoreList":[]}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
export { OverlayHost, ROOT_OVERLAY_HOST, useOverlayHost, useTopmostOverlayHost } from "./OverlayHost";
|
|
4
4
|
export { OverlayPortal } from "./OverlayPortal";
|
|
5
|
+
export { resolvePersistTaps, useRegisterTeleportedLayer, useTeleportedLayerScope } from "./teleported-layer-scope";
|
|
5
6
|
/**
|
|
6
7
|
* Portal system — a thin re-export of `react-native-teleport`.
|
|
7
8
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["OverlayHost","ROOT_OVERLAY_HOST","useOverlayHost","useTopmostOverlayHost","OverlayPortal","Portal","PortalHost","PortalProvider","usePortal"],"sourceRoot":"../../../src","sources":["Portal/index.ts"],"mappings":";;AAAA,SACEA,WAAW,EACXC,iBAAiB,EACjBC,cAAc,EACdC,qBAAqB,QAChB,eAAe;AACtB,SAASC,aAAa,QAAiC,iBAAiB;
|
|
1
|
+
{"version":3,"names":["OverlayHost","ROOT_OVERLAY_HOST","useOverlayHost","useTopmostOverlayHost","OverlayPortal","resolvePersistTaps","useRegisterTeleportedLayer","useTeleportedLayerScope","Portal","PortalHost","PortalProvider","usePortal"],"sourceRoot":"../../../src","sources":["Portal/index.ts"],"mappings":";;AAAA,SACEA,WAAW,EACXC,iBAAiB,EACjBC,cAAc,EACdC,qBAAqB,QAChB,eAAe;AACtB,SAASC,aAAa,QAAiC,iBAAiB;AACxE,SACEC,kBAAkB,EAElBC,0BAA0B,EAC1BC,uBAAuB,QAClB,0BAA0B;AAEjC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,MAAM,EAAEC,UAAU,EAAEC,cAAc,EAAEC,SAAS,QAAQ,uBAAuB","ignoreList":[]}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Lets a scroller know that an overlay rendered INSIDE it in React (a `Sheet`,
|
|
7
|
+
* `Modal`, `Drawer` or dropdown teleported on screen through `OverlayPortal`)
|
|
8
|
+
* is currently open.
|
|
9
|
+
*
|
|
10
|
+
* Why (native): teleporting moves the native view, but in React the layer stays
|
|
11
|
+
* where it was rendered, e.g. a comment sheet opened from a row of a feed list.
|
|
12
|
+
* React Native's responder system walks the React tree, so that list's
|
|
13
|
+
* `ScrollView` is an ancestor of every button in the sheet. With the default
|
|
14
|
+
* `keyboardShouldPersistTaps="never"` the ScrollView CAPTURES a touch that starts
|
|
15
|
+
* while the keyboard is up, only to dismiss the keyboard, and the sheet's button
|
|
16
|
+
* never gets the first tap. A descendant cannot outbid an ancestor's capture, so
|
|
17
|
+
* the scroller has to step back: while a layer is registered here it uses
|
|
18
|
+
* `"handled"`, which leaves the tap to the control it lands on and still
|
|
19
|
+
* dismisses the keyboard on a tap nothing handles.
|
|
20
|
+
*
|
|
21
|
+
* Scopes nest: a layer registers with the nearest scroller, which forwards the
|
|
22
|
+
* registration to every scroller above it. Web has no such capture, so
|
|
23
|
+
* `OverlayPortal` only registers on native.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
const TeleportedLayerContext = /*#__PURE__*/React.createContext(null);
|
|
27
|
+
/** Scroller side: open a scope and learn whether a layer inside it is open. */
|
|
28
|
+
export function useTeleportedLayerScope() {
|
|
29
|
+
const parent = React.useContext(TeleportedLayerContext);
|
|
30
|
+
const [count, setCount] = React.useState(0);
|
|
31
|
+
const register = React.useCallback(() => {
|
|
32
|
+
setCount(c => c + 1);
|
|
33
|
+
const releaseParent = parent?.();
|
|
34
|
+
let released = false;
|
|
35
|
+
return () => {
|
|
36
|
+
if (released) return;
|
|
37
|
+
released = true;
|
|
38
|
+
setCount(c => c - 1);
|
|
39
|
+
releaseParent?.();
|
|
40
|
+
};
|
|
41
|
+
}, [parent]);
|
|
42
|
+
return {
|
|
43
|
+
hasOpenLayer: count > 0,
|
|
44
|
+
Provider: TeleportedLayerContext.Provider,
|
|
45
|
+
register
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Layer side: register with the enclosing scroller(s) while `active`. */
|
|
50
|
+
export function useRegisterTeleportedLayer(active) {
|
|
51
|
+
const register = React.useContext(TeleportedLayerContext);
|
|
52
|
+
React.useEffect(() => {
|
|
53
|
+
if (!active || !register) return;
|
|
54
|
+
return register();
|
|
55
|
+
}, [active, register]);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The `keyboardShouldPersistTaps` a native scroller should use: the consumer's
|
|
60
|
+
* explicit value wins; otherwise `"handled"` while a layer inside it is open.
|
|
61
|
+
*/
|
|
62
|
+
export function resolvePersistTaps(explicit, hasOpenLayer) {
|
|
63
|
+
if (explicit !== undefined) return explicit;
|
|
64
|
+
return hasOpenLayer ? "handled" : undefined;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=teleported-layer-scope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","TeleportedLayerContext","createContext","useTeleportedLayerScope","parent","useContext","count","setCount","useState","register","useCallback","c","releaseParent","released","hasOpenLayer","Provider","useRegisterTeleportedLayer","active","useEffect","resolvePersistTaps","explicit","undefined"],"sourceRoot":"../../../src","sources":["Portal/teleported-layer-scope.tsx"],"mappings":";;AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;;AAE9B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,MAAMC,sBAAsB,gBAAGD,KAAK,CAACE,aAAa,CAAuB,IAAI,CAAC;AAU9E;AACA,OAAO,SAASC,uBAAuBA,CAAA,EAAyB;EAC9D,MAAMC,MAAM,GAAGJ,KAAK,CAACK,UAAU,CAACJ,sBAAsB,CAAC;EACvD,MAAM,CAACK,KAAK,EAAEC,QAAQ,CAAC,GAAGP,KAAK,CAACQ,QAAQ,CAAC,CAAC,CAAC;EAC3C,MAAMC,QAAQ,GAAGT,KAAK,CAACU,WAAW,CAAgB,MAAM;IACtDH,QAAQ,CAAEI,CAAC,IAAKA,CAAC,GAAG,CAAC,CAAC;IACtB,MAAMC,aAAa,GAAGR,MAAM,GAAG,CAAC;IAChC,IAAIS,QAAQ,GAAG,KAAK;IACpB,OAAO,MAAM;MACX,IAAIA,QAAQ,EAAE;MACdA,QAAQ,GAAG,IAAI;MACfN,QAAQ,CAAEI,CAAC,IAAKA,CAAC,GAAG,CAAC,CAAC;MACtBC,aAAa,GAAG,CAAC;IACnB,CAAC;EACH,CAAC,EAAE,CAACR,MAAM,CAAC,CAAC;EACZ,OAAO;IAAEU,YAAY,EAAER,KAAK,GAAG,CAAC;IAAES,QAAQ,EAAEd,sBAAsB,CAACc,QAAQ;IAAEN;EAAS,CAAC;AACzF;;AAEA;AACA,OAAO,SAASO,0BAA0BA,CAACC,MAAe,EAAQ;EAChE,MAAMR,QAAQ,GAAGT,KAAK,CAACK,UAAU,CAACJ,sBAAsB,CAAC;EACzDD,KAAK,CAACkB,SAAS,CAAC,MAAM;IACpB,IAAI,CAACD,MAAM,IAAI,CAACR,QAAQ,EAAE;IAC1B,OAAOA,QAAQ,CAAC,CAAC;EACnB,CAAC,EAAE,CAACQ,MAAM,EAAER,QAAQ,CAAC,CAAC;AACxB;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASU,kBAAkBA,CAChCC,QAAuB,EACvBN,YAAqB,EACM;EAC3B,IAAIM,QAAQ,KAAKC,SAAS,EAAE,OAAOD,QAAQ;EAC3C,OAAON,YAAY,GAAG,SAAS,GAAGO,SAAS;AAC7C","ignoreList":[]}
|
|
@@ -127,6 +127,24 @@ const ScrollAreaShadow = styled(Box, {
|
|
|
127
127
|
// `shadowColor` from `ScrollAreaOwnProps` (a plain string) takes precedence, so it
|
|
128
128
|
// is omitted from the frame props to avoid a clashing-member error.
|
|
129
129
|
|
|
130
|
+
/** ARIA roles whose widgets consume Space, Home/End or the arrow keys themselves. */
|
|
131
|
+
const KEY_OWNING_ROLES = new Set(["button", "checkbox", "combobox", "grid", "listbox", "menu", "menubar", "menuitem", "menuitemcheckbox", "menuitemradio", "option", "radio", "radiogroup", "scrollbar", "searchbox", "slider", "spinbutton", "switch", "tab", "tablist", "textbox", "tree", "treegrid"]);
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Whether a keydown target handles the scroll keys itself, so the viewport must
|
|
135
|
+
* not turn them into a scroll: native form controls, editable content, and ARIA
|
|
136
|
+
* widgets. The browser still applies its own default for these keys.
|
|
137
|
+
*/
|
|
138
|
+
function ownsScrollKeys(target) {
|
|
139
|
+
if (!target || typeof target.closest !== "function") return false;
|
|
140
|
+
const el = target;
|
|
141
|
+
if (el.isContentEditable) return true;
|
|
142
|
+
const tag = el.tagName;
|
|
143
|
+
if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT" || tag === "BUTTON") return true;
|
|
144
|
+
const role = el.getAttribute("role");
|
|
145
|
+
return role !== null && KEY_OWNING_ROLES.has(role);
|
|
146
|
+
}
|
|
147
|
+
|
|
130
148
|
/* Local style narrowing for the web-only CSS props on the viewport element. */
|
|
131
149
|
|
|
132
150
|
/** Viewport + content dimensions. Read only on mount/resize — never per scroll
|
|
@@ -739,7 +757,11 @@ const ScrollAreaComponent = /*#__PURE__*/React.forwardRef(function ScrollArea(pr
|
|
|
739
757
|
|
|
740
758
|
const handleKeyDown = React.useCallback(event => {
|
|
741
759
|
const node = viewportNodeRef.current;
|
|
742
|
-
if (!node) return;
|
|
760
|
+
if (!node || event.defaultPrevented) return;
|
|
761
|
+
// Keys bubbling up from a field or widget inside the viewport belong to
|
|
762
|
+
// it (Space types a space, Home/End/arrows move the caret or the widget's
|
|
763
|
+
// selection). Leave them alone; a non-interactive descendant still scrolls.
|
|
764
|
+
if (event.target !== event.currentTarget && ownsScrollKeys(event.target)) return;
|
|
743
765
|
const delta = keyToScrollDelta(event.key, keyStep, node.clientWidth, node.clientHeight, event.shiftKey);
|
|
744
766
|
if (!delta) return;
|
|
745
767
|
// Only intercept the axes we actually scroll.
|