@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.mjs
CHANGED
|
@@ -766,6 +766,9 @@ var BORDER_RADIUS = 8;
|
|
|
766
766
|
var BORDER_WIDTH2 = 1;
|
|
767
767
|
var MENU_PADDING = 4;
|
|
768
768
|
var MENU_SCROLL_MAX_HEIGHT = MENU_MAX_HEIGHT - (BORDER_WIDTH2 + MENU_PADDING) * 2;
|
|
769
|
+
function menuScrollMaxHeight(popoverMaxHeight) {
|
|
770
|
+
return Math.max(0, popoverMaxHeight - (BORDER_WIDTH2 + MENU_PADDING) * 2);
|
|
771
|
+
}
|
|
769
772
|
var MENU_BOX_SHADOW = "0px 2px 8px rgba(0, 0, 0, 0.15)";
|
|
770
773
|
var MENU_VIEWPORT_MARGIN = 8;
|
|
771
774
|
var COMPACT_TRIGGER_MENU_MIN_WIDTH = 160;
|
|
@@ -773,7 +776,18 @@ function resolveMenuMinWidth(menuMinWidth, hasCustomTrigger) {
|
|
|
773
776
|
if (menuMinWidth !== void 0) return menuMinWidth;
|
|
774
777
|
return hasCustomTrigger ? COMPACT_TRIGGER_MENU_MIN_WIDTH : void 0;
|
|
775
778
|
}
|
|
776
|
-
function
|
|
779
|
+
function resolveMenuPlacement(rect, viewportHeight, menuHeight) {
|
|
780
|
+
if (viewportHeight <= 0) return { top: rect.bottom + MENU_TOP_GAP, maxHeight: MENU_MAX_HEIGHT };
|
|
781
|
+
const top = Math.max(MENU_VIEWPORT_MARGIN, rect.bottom + MENU_TOP_GAP);
|
|
782
|
+
const bottom = Math.max(MENU_VIEWPORT_MARGIN, viewportHeight - rect.top + MENU_TOP_GAP);
|
|
783
|
+
const roomBelow = viewportHeight - top - MENU_VIEWPORT_MARGIN;
|
|
784
|
+
const roomAbove = viewportHeight - bottom - MENU_VIEWPORT_MARGIN;
|
|
785
|
+
const fitsBelow = roomBelow >= Math.min(menuHeight, MENU_MAX_HEIGHT);
|
|
786
|
+
const cap = (room) => Math.max(0, Math.min(MENU_MAX_HEIGHT, room));
|
|
787
|
+
if (!fitsBelow && roomAbove > roomBelow) return { bottom, maxHeight: cap(roomAbove) };
|
|
788
|
+
return { top, maxHeight: cap(roomBelow) };
|
|
789
|
+
}
|
|
790
|
+
function buildPortalPopoverStyle(rect, minWidth = 0, viewportWidth = 0, placement = resolveMenuPlacement(rect, 0, MENU_MAX_HEIGHT)) {
|
|
777
791
|
const width = Math.max(rect.width, minWidth);
|
|
778
792
|
let left = rect.left;
|
|
779
793
|
if (viewportWidth > 0) {
|
|
@@ -784,14 +798,13 @@ function buildPortalPopoverStyle(rect, minWidth = 0, viewportWidth = 0) {
|
|
|
784
798
|
// RN's ViewStyle union omits 'fixed', but react-native-web honours it at runtime.
|
|
785
799
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- web-only position value
|
|
786
800
|
position: "fixed",
|
|
787
|
-
|
|
801
|
+
...placement,
|
|
788
802
|
left,
|
|
789
803
|
width,
|
|
790
804
|
zIndex: MENU_Z_INDEX,
|
|
791
805
|
borderWidth: BORDER_WIDTH2,
|
|
792
806
|
borderRadius: BORDER_RADIUS,
|
|
793
807
|
padding: MENU_PADDING,
|
|
794
|
-
maxHeight: MENU_MAX_HEIGHT,
|
|
795
808
|
boxShadow: MENU_BOX_SHADOW,
|
|
796
809
|
elevation: MENU_ELEVATION
|
|
797
810
|
};
|
|
@@ -1070,6 +1083,29 @@ function useMenuKeyboard(params) {
|
|
|
1070
1083
|
}, [containerRef, menuRef, enabled, onClose, params]);
|
|
1071
1084
|
}
|
|
1072
1085
|
var IS_WEB2 = Platform.OS === "web";
|
|
1086
|
+
var UNMEASURED_RECT = { top: 0, bottom: 0 };
|
|
1087
|
+
function readViewportHeight() {
|
|
1088
|
+
return IS_WEB2 && typeof window !== "undefined" ? window.innerHeight : 0;
|
|
1089
|
+
}
|
|
1090
|
+
function useMenuPlacement(rect, menuRef, itemCount) {
|
|
1091
|
+
const [menuHeight, setMenuHeight] = useState(MENU_MAX_HEIGHT);
|
|
1092
|
+
const [viewportHeight, setViewportHeight] = useState(readViewportHeight);
|
|
1093
|
+
useLayoutEffect(() => {
|
|
1094
|
+
const measured = toDomNode(menuRef)?.offsetHeight ?? 0;
|
|
1095
|
+
if (measured > 0) setMenuHeight(measured);
|
|
1096
|
+
}, [menuRef, itemCount]);
|
|
1097
|
+
useLayoutEffect(() => {
|
|
1098
|
+
if (!IS_WEB2) return void 0;
|
|
1099
|
+
const onResize = () => setViewportHeight(readViewportHeight());
|
|
1100
|
+
window.addEventListener("resize", onResize);
|
|
1101
|
+
return () => window.removeEventListener("resize", onResize);
|
|
1102
|
+
}, []);
|
|
1103
|
+
return useMemo(
|
|
1104
|
+
() => resolveMenuPlacement(rect ?? UNMEASURED_RECT, viewportHeight, menuHeight),
|
|
1105
|
+
[rect, viewportHeight, menuHeight]
|
|
1106
|
+
);
|
|
1107
|
+
}
|
|
1108
|
+
var IS_WEB3 = Platform.OS === "web";
|
|
1073
1109
|
var BORDER_RADIUS2 = 8;
|
|
1074
1110
|
var BORDER_WIDTH3 = 1;
|
|
1075
1111
|
var MENU_PADDING2 = 4;
|
|
@@ -1092,7 +1128,8 @@ var styles11 = StyleSheet.create({
|
|
|
1092
1128
|
// The enter/exit fade+scale lives on an INNER wrapper so the outer popover keeps its raw DOM
|
|
1093
1129
|
// node (the `menuRef` outside-click / keyboard logic and the web portal target depend on it).
|
|
1094
1130
|
// `transformOrigin: 'top'` makes the scale grow downward FROM the anchor rather than the centre.
|
|
1095
|
-
animated: { transformOrigin: "top" },
|
|
1131
|
+
animated: { transformOrigin: "top", flexShrink: 1 },
|
|
1132
|
+
animatedAbove: { transformOrigin: "bottom" },
|
|
1096
1133
|
// Exit fade only: the dying popover must not receive the next click. See the file header.
|
|
1097
1134
|
inert: { pointerEvents: "none" },
|
|
1098
1135
|
// Bound the scroll viewport so a list longer than the popover scrolls (with a scrollbar) instead of
|
|
@@ -1118,6 +1155,8 @@ var InlineMenu = ({
|
|
|
1118
1155
|
const { colors } = theme;
|
|
1119
1156
|
const menuRef = useRef(null);
|
|
1120
1157
|
const rect = useAnchorTracking(containerRef, onClose);
|
|
1158
|
+
const placement = useMenuPlacement(rect, menuRef, options.length);
|
|
1159
|
+
const opensAbove = placement.bottom !== void 0;
|
|
1121
1160
|
const selectedIndex = useMemo(
|
|
1122
1161
|
() => Math.max(0, options.findIndex((opt) => opt.value === value)),
|
|
1123
1162
|
[options, value]
|
|
@@ -1153,15 +1192,16 @@ var InlineMenu = ({
|
|
|
1153
1192
|
});
|
|
1154
1193
|
const popoverStyle = useMemo(() => {
|
|
1155
1194
|
const themed = { borderColor: colors.border, backgroundColor: colors.surface };
|
|
1156
|
-
if (
|
|
1195
|
+
if (IS_WEB3) {
|
|
1157
1196
|
const viewportWidth = typeof window !== "undefined" ? window.innerWidth : 0;
|
|
1158
1197
|
return [
|
|
1159
|
-
buildPortalPopoverStyle(rect ?? { left: 0, width: 0, bottom: 0 }, menuMinWidth, viewportWidth),
|
|
1198
|
+
buildPortalPopoverStyle(rect ?? { top: 0, left: 0, width: 0, bottom: 0 }, menuMinWidth, viewportWidth, placement),
|
|
1160
1199
|
themed
|
|
1161
1200
|
];
|
|
1162
1201
|
}
|
|
1163
1202
|
return [styles11.popover, { minWidth: menuMinWidth }, themed];
|
|
1164
|
-
}, [colors.border, colors.surface, menuMinWidth, rect]);
|
|
1203
|
+
}, [colors.border, colors.surface, menuMinWidth, placement, rect]);
|
|
1204
|
+
const scrollStyle = IS_WEB3 ? { maxHeight: menuScrollMaxHeight(placement.maxHeight) } : styles11.scroll;
|
|
1165
1205
|
const menu = /* @__PURE__ */ jsx(
|
|
1166
1206
|
View,
|
|
1167
1207
|
{
|
|
@@ -1175,10 +1215,10 @@ var InlineMenu = ({
|
|
|
1175
1215
|
Animated.View,
|
|
1176
1216
|
{
|
|
1177
1217
|
pointerEvents: isOpen ? "auto" : "none",
|
|
1178
|
-
style: [styles11.animated, animatedStyle, isOpen ? null : styles11.inert],
|
|
1218
|
+
style: [styles11.animated, opensAbove ? styles11.animatedAbove : null, animatedStyle, isOpen ? null : styles11.inert],
|
|
1179
1219
|
children: [
|
|
1180
1220
|
menuHeading !== void 0 ? /* @__PURE__ */ jsx(MenuHeading, { testID, text: menuHeading }) : null,
|
|
1181
|
-
/* @__PURE__ */ jsx(ScrollView, { style:
|
|
1221
|
+
/* @__PURE__ */ jsx(ScrollView, { style: scrollStyle, keyboardShouldPersistTaps: "handled", children: options.map((option, index) => /* @__PURE__ */ jsx(
|
|
1182
1222
|
OptionRow,
|
|
1183
1223
|
{
|
|
1184
1224
|
asMenuItem: true,
|
|
@@ -1196,7 +1236,7 @@ var InlineMenu = ({
|
|
|
1196
1236
|
)
|
|
1197
1237
|
}
|
|
1198
1238
|
);
|
|
1199
|
-
if (
|
|
1239
|
+
if (IS_WEB3) return createPortal(menu, document.body);
|
|
1200
1240
|
return menu;
|
|
1201
1241
|
};
|
|
1202
1242
|
var MENU_BREAKPOINT = LAYOUT_COLLAPSE_BREAKPOINT;
|
|
@@ -1726,7 +1766,10 @@ var styles15 = StyleSheet.create({
|
|
|
1726
1766
|
justifyContent: "space-between"
|
|
1727
1767
|
},
|
|
1728
1768
|
closeButton: {
|
|
1729
|
-
|
|
1769
|
+
minWidth: MIN_TOUCH_TARGET_PX,
|
|
1770
|
+
minHeight: MIN_TOUCH_TARGET_PX,
|
|
1771
|
+
alignItems: "center",
|
|
1772
|
+
justifyContent: "center",
|
|
1730
1773
|
borderRadius: 6
|
|
1731
1774
|
}
|
|
1732
1775
|
});
|
|
@@ -2193,7 +2236,7 @@ function formatUrlForDisplay(value) {
|
|
|
2193
2236
|
return trimmed.length > 0 ? trimmed : value;
|
|
2194
2237
|
}
|
|
2195
2238
|
var UNMEASURED = 0;
|
|
2196
|
-
var
|
|
2239
|
+
var IS_WEB4 = Platform.OS === "web";
|
|
2197
2240
|
function measureParentInnerWidth(node) {
|
|
2198
2241
|
const parent = node.parentElement;
|
|
2199
2242
|
if (parent === null) return UNMEASURED;
|
|
@@ -2205,12 +2248,12 @@ function useAvailableWidth() {
|
|
|
2205
2248
|
const [width, setWidth] = useState(UNMEASURED);
|
|
2206
2249
|
const nodeRef = useRef(null);
|
|
2207
2250
|
const measureRef = useCallback((node) => {
|
|
2208
|
-
if (!
|
|
2251
|
+
if (!IS_WEB4) return;
|
|
2209
2252
|
nodeRef.current = node;
|
|
2210
2253
|
if (nodeRef.current !== null) setWidth(measureParentInnerWidth(nodeRef.current));
|
|
2211
2254
|
}, []);
|
|
2212
2255
|
useEffect(() => {
|
|
2213
|
-
if (!
|
|
2256
|
+
if (!IS_WEB4) return void 0;
|
|
2214
2257
|
const remeasure = () => {
|
|
2215
2258
|
const node = nodeRef.current;
|
|
2216
2259
|
if (node !== null) setWidth(measureParentInnerWidth(node));
|
|
@@ -2219,7 +2262,7 @@ function useAvailableWidth() {
|
|
|
2219
2262
|
return () => window.removeEventListener("resize", remeasure);
|
|
2220
2263
|
}, []);
|
|
2221
2264
|
const onLayout = useCallback((event) => {
|
|
2222
|
-
if (
|
|
2265
|
+
if (IS_WEB4) return;
|
|
2223
2266
|
setWidth(event.nativeEvent.layout.width);
|
|
2224
2267
|
}, []);
|
|
2225
2268
|
return { width, measureRef, onLayout };
|