@dloizides/ui-layout 1.39.1 → 1.39.3
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/index.js +58 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +58 -15
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -772,6 +772,9 @@ var BORDER_RADIUS = 8;
|
|
|
772
772
|
var BORDER_WIDTH2 = 1;
|
|
773
773
|
var MENU_PADDING = 4;
|
|
774
774
|
var MENU_SCROLL_MAX_HEIGHT = MENU_MAX_HEIGHT - (BORDER_WIDTH2 + MENU_PADDING) * 2;
|
|
775
|
+
function menuScrollMaxHeight(popoverMaxHeight) {
|
|
776
|
+
return Math.max(0, popoverMaxHeight - (BORDER_WIDTH2 + MENU_PADDING) * 2);
|
|
777
|
+
}
|
|
775
778
|
var MENU_BOX_SHADOW = "0px 2px 8px rgba(0, 0, 0, 0.15)";
|
|
776
779
|
var MENU_VIEWPORT_MARGIN = 8;
|
|
777
780
|
var COMPACT_TRIGGER_MENU_MIN_WIDTH = 160;
|
|
@@ -779,7 +782,18 @@ function resolveMenuMinWidth(menuMinWidth, hasCustomTrigger) {
|
|
|
779
782
|
if (menuMinWidth !== void 0) return menuMinWidth;
|
|
780
783
|
return hasCustomTrigger ? COMPACT_TRIGGER_MENU_MIN_WIDTH : void 0;
|
|
781
784
|
}
|
|
782
|
-
function
|
|
785
|
+
function resolveMenuPlacement(rect, viewportHeight, menuHeight) {
|
|
786
|
+
if (viewportHeight <= 0) return { top: rect.bottom + MENU_TOP_GAP, maxHeight: MENU_MAX_HEIGHT };
|
|
787
|
+
const top = Math.max(MENU_VIEWPORT_MARGIN, rect.bottom + MENU_TOP_GAP);
|
|
788
|
+
const bottom = Math.max(MENU_VIEWPORT_MARGIN, viewportHeight - rect.top + MENU_TOP_GAP);
|
|
789
|
+
const roomBelow = viewportHeight - top - MENU_VIEWPORT_MARGIN;
|
|
790
|
+
const roomAbove = viewportHeight - bottom - MENU_VIEWPORT_MARGIN;
|
|
791
|
+
const fitsBelow = roomBelow >= Math.min(menuHeight, MENU_MAX_HEIGHT);
|
|
792
|
+
const cap = (room) => Math.max(0, Math.min(MENU_MAX_HEIGHT, room));
|
|
793
|
+
if (!fitsBelow && roomAbove > roomBelow) return { bottom, maxHeight: cap(roomAbove) };
|
|
794
|
+
return { top, maxHeight: cap(roomBelow) };
|
|
795
|
+
}
|
|
796
|
+
function buildPortalPopoverStyle(rect, minWidth = 0, viewportWidth = 0, placement = resolveMenuPlacement(rect, 0, MENU_MAX_HEIGHT)) {
|
|
783
797
|
const width = Math.max(rect.width, minWidth);
|
|
784
798
|
let left = rect.left;
|
|
785
799
|
if (viewportWidth > 0) {
|
|
@@ -790,14 +804,13 @@ function buildPortalPopoverStyle(rect, minWidth = 0, viewportWidth = 0) {
|
|
|
790
804
|
// RN's ViewStyle union omits 'fixed', but react-native-web honours it at runtime.
|
|
791
805
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- web-only position value
|
|
792
806
|
position: "fixed",
|
|
793
|
-
|
|
807
|
+
...placement,
|
|
794
808
|
left,
|
|
795
809
|
width,
|
|
796
810
|
zIndex: MENU_Z_INDEX,
|
|
797
811
|
borderWidth: BORDER_WIDTH2,
|
|
798
812
|
borderRadius: BORDER_RADIUS,
|
|
799
813
|
padding: MENU_PADDING,
|
|
800
|
-
maxHeight: MENU_MAX_HEIGHT,
|
|
801
814
|
boxShadow: MENU_BOX_SHADOW,
|
|
802
815
|
elevation: MENU_ELEVATION
|
|
803
816
|
};
|
|
@@ -1076,6 +1089,29 @@ function useMenuKeyboard(params) {
|
|
|
1076
1089
|
}, [containerRef, menuRef, enabled, onClose, params]);
|
|
1077
1090
|
}
|
|
1078
1091
|
var IS_WEB2 = reactNative.Platform.OS === "web";
|
|
1092
|
+
var UNMEASURED_RECT = { top: 0, bottom: 0 };
|
|
1093
|
+
function readViewportHeight() {
|
|
1094
|
+
return IS_WEB2 && typeof window !== "undefined" ? window.innerHeight : 0;
|
|
1095
|
+
}
|
|
1096
|
+
function useMenuPlacement(rect, menuRef, itemCount) {
|
|
1097
|
+
const [menuHeight, setMenuHeight] = React13.useState(MENU_MAX_HEIGHT);
|
|
1098
|
+
const [viewportHeight, setViewportHeight] = React13.useState(readViewportHeight);
|
|
1099
|
+
React13.useLayoutEffect(() => {
|
|
1100
|
+
const measured = toDomNode(menuRef)?.offsetHeight ?? 0;
|
|
1101
|
+
if (measured > 0) setMenuHeight(measured);
|
|
1102
|
+
}, [menuRef, itemCount]);
|
|
1103
|
+
React13.useLayoutEffect(() => {
|
|
1104
|
+
if (!IS_WEB2) return void 0;
|
|
1105
|
+
const onResize = () => setViewportHeight(readViewportHeight());
|
|
1106
|
+
window.addEventListener("resize", onResize);
|
|
1107
|
+
return () => window.removeEventListener("resize", onResize);
|
|
1108
|
+
}, []);
|
|
1109
|
+
return React13.useMemo(
|
|
1110
|
+
() => resolveMenuPlacement(rect ?? UNMEASURED_RECT, viewportHeight, menuHeight),
|
|
1111
|
+
[rect, viewportHeight, menuHeight]
|
|
1112
|
+
);
|
|
1113
|
+
}
|
|
1114
|
+
var IS_WEB3 = reactNative.Platform.OS === "web";
|
|
1079
1115
|
var BORDER_RADIUS2 = 8;
|
|
1080
1116
|
var BORDER_WIDTH3 = 1;
|
|
1081
1117
|
var MENU_PADDING2 = 4;
|
|
@@ -1098,7 +1134,8 @@ var styles11 = reactNative.StyleSheet.create({
|
|
|
1098
1134
|
// The enter/exit fade+scale lives on an INNER wrapper so the outer popover keeps its raw DOM
|
|
1099
1135
|
// node (the `menuRef` outside-click / keyboard logic and the web portal target depend on it).
|
|
1100
1136
|
// `transformOrigin: 'top'` makes the scale grow downward FROM the anchor rather than the centre.
|
|
1101
|
-
animated: { transformOrigin: "top" },
|
|
1137
|
+
animated: { transformOrigin: "top", flexShrink: 1 },
|
|
1138
|
+
animatedAbove: { transformOrigin: "bottom" },
|
|
1102
1139
|
// Exit fade only: the dying popover must not receive the next click. See the file header.
|
|
1103
1140
|
inert: { pointerEvents: "none" },
|
|
1104
1141
|
// Bound the scroll viewport so a list longer than the popover scrolls (with a scrollbar) instead of
|
|
@@ -1124,6 +1161,8 @@ var InlineMenu = ({
|
|
|
1124
1161
|
const { colors } = theme;
|
|
1125
1162
|
const menuRef = React13.useRef(null);
|
|
1126
1163
|
const rect = useAnchorTracking(containerRef, onClose);
|
|
1164
|
+
const placement = useMenuPlacement(rect, menuRef, options.length);
|
|
1165
|
+
const opensAbove = placement.bottom !== void 0;
|
|
1127
1166
|
const selectedIndex = React13.useMemo(
|
|
1128
1167
|
() => Math.max(0, options.findIndex((opt) => opt.value === value)),
|
|
1129
1168
|
[options, value]
|
|
@@ -1159,15 +1198,16 @@ var InlineMenu = ({
|
|
|
1159
1198
|
});
|
|
1160
1199
|
const popoverStyle = React13.useMemo(() => {
|
|
1161
1200
|
const themed = { borderColor: colors.border, backgroundColor: colors.surface };
|
|
1162
|
-
if (
|
|
1201
|
+
if (IS_WEB3) {
|
|
1163
1202
|
const viewportWidth = typeof window !== "undefined" ? window.innerWidth : 0;
|
|
1164
1203
|
return [
|
|
1165
|
-
buildPortalPopoverStyle(rect ?? { left: 0, width: 0, bottom: 0 }, menuMinWidth, viewportWidth),
|
|
1204
|
+
buildPortalPopoverStyle(rect ?? { top: 0, left: 0, width: 0, bottom: 0 }, menuMinWidth, viewportWidth, placement),
|
|
1166
1205
|
themed
|
|
1167
1206
|
];
|
|
1168
1207
|
}
|
|
1169
1208
|
return [styles11.popover, { minWidth: menuMinWidth }, themed];
|
|
1170
|
-
}, [colors.border, colors.surface, menuMinWidth, rect]);
|
|
1209
|
+
}, [colors.border, colors.surface, menuMinWidth, placement, rect]);
|
|
1210
|
+
const scrollStyle = IS_WEB3 ? { maxHeight: menuScrollMaxHeight(placement.maxHeight) } : styles11.scroll;
|
|
1171
1211
|
const menu = /* @__PURE__ */ jsxRuntime.jsx(
|
|
1172
1212
|
reactNative.View,
|
|
1173
1213
|
{
|
|
@@ -1181,10 +1221,10 @@ var InlineMenu = ({
|
|
|
1181
1221
|
reactNative.Animated.View,
|
|
1182
1222
|
{
|
|
1183
1223
|
pointerEvents: isOpen ? "auto" : "none",
|
|
1184
|
-
style: [styles11.animated, animatedStyle, isOpen ? null : styles11.inert],
|
|
1224
|
+
style: [styles11.animated, opensAbove ? styles11.animatedAbove : null, animatedStyle, isOpen ? null : styles11.inert],
|
|
1185
1225
|
children: [
|
|
1186
1226
|
menuHeading !== void 0 ? /* @__PURE__ */ jsxRuntime.jsx(MenuHeading, { testID, text: menuHeading }) : null,
|
|
1187
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactNative.ScrollView, { style:
|
|
1227
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactNative.ScrollView, { style: scrollStyle, keyboardShouldPersistTaps: "handled", children: options.map((option, index) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1188
1228
|
OptionRow,
|
|
1189
1229
|
{
|
|
1190
1230
|
asMenuItem: true,
|
|
@@ -1202,7 +1242,7 @@ var InlineMenu = ({
|
|
|
1202
1242
|
)
|
|
1203
1243
|
}
|
|
1204
1244
|
);
|
|
1205
|
-
if (
|
|
1245
|
+
if (IS_WEB3) return reactDom.createPortal(menu, document.body);
|
|
1206
1246
|
return menu;
|
|
1207
1247
|
};
|
|
1208
1248
|
var MENU_BREAKPOINT = LAYOUT_COLLAPSE_BREAKPOINT;
|
|
@@ -1732,7 +1772,10 @@ var styles15 = reactNative.StyleSheet.create({
|
|
|
1732
1772
|
justifyContent: "space-between"
|
|
1733
1773
|
},
|
|
1734
1774
|
closeButton: {
|
|
1735
|
-
|
|
1775
|
+
minWidth: a11y.MIN_TOUCH_TARGET_PX,
|
|
1776
|
+
minHeight: a11y.MIN_TOUCH_TARGET_PX,
|
|
1777
|
+
alignItems: "center",
|
|
1778
|
+
justifyContent: "center",
|
|
1736
1779
|
borderRadius: 6
|
|
1737
1780
|
}
|
|
1738
1781
|
});
|
|
@@ -2199,7 +2242,7 @@ function formatUrlForDisplay(value) {
|
|
|
2199
2242
|
return trimmed.length > 0 ? trimmed : value;
|
|
2200
2243
|
}
|
|
2201
2244
|
var UNMEASURED = 0;
|
|
2202
|
-
var
|
|
2245
|
+
var IS_WEB4 = reactNative.Platform.OS === "web";
|
|
2203
2246
|
function measureParentInnerWidth(node) {
|
|
2204
2247
|
const parent = node.parentElement;
|
|
2205
2248
|
if (parent === null) return UNMEASURED;
|
|
@@ -2211,12 +2254,12 @@ function useAvailableWidth() {
|
|
|
2211
2254
|
const [width, setWidth] = React13.useState(UNMEASURED);
|
|
2212
2255
|
const nodeRef = React13.useRef(null);
|
|
2213
2256
|
const measureRef = React13.useCallback((node) => {
|
|
2214
|
-
if (!
|
|
2257
|
+
if (!IS_WEB4) return;
|
|
2215
2258
|
nodeRef.current = node;
|
|
2216
2259
|
if (nodeRef.current !== null) setWidth(measureParentInnerWidth(nodeRef.current));
|
|
2217
2260
|
}, []);
|
|
2218
2261
|
React13.useEffect(() => {
|
|
2219
|
-
if (!
|
|
2262
|
+
if (!IS_WEB4) return void 0;
|
|
2220
2263
|
const remeasure = () => {
|
|
2221
2264
|
const node = nodeRef.current;
|
|
2222
2265
|
if (node !== null) setWidth(measureParentInnerWidth(node));
|
|
@@ -2225,7 +2268,7 @@ function useAvailableWidth() {
|
|
|
2225
2268
|
return () => window.removeEventListener("resize", remeasure);
|
|
2226
2269
|
}, []);
|
|
2227
2270
|
const onLayout = React13.useCallback((event) => {
|
|
2228
|
-
if (
|
|
2271
|
+
if (IS_WEB4) return;
|
|
2229
2272
|
setWidth(event.nativeEvent.layout.width);
|
|
2230
2273
|
}, []);
|
|
2231
2274
|
return { width, measureRef, onLayout };
|