@ioca/react 1.4.75 → 1.4.76

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/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
2
2
  import classNames from 'classnames';
3
3
  import { debounce, uid, throttle, title } from 'radash';
4
- import { useState, useRef, useEffect, useMemo, Children, cloneElement, createElement, isValidElement, Fragment as Fragment$1, useTransition, createContext, useContext, useLayoutEffect, useImperativeHandle } from 'react';
4
+ import { useState, useRef, useEffect, useMemo, Children, cloneElement, createElement, isValidElement, Fragment as Fragment$1, useTransition, forwardRef, useLayoutEffect, useImperativeHandle, createContext, useContext } from 'react';
5
5
  import { SkipPreviousRound, CloseRound, MinusRound, PlusRound, InboxTwotone, ClearAllRound, UndoRound, RedoRound, StrikethroughSRound, FormatUnderlinedRound, FormatItalicRound, FormatBoldRound, PlayArrowRound, PauseRound, StopRound, VolumeDownRound, VolumeOffRound, FullscreenRound, FullscreenExitRound, FeedOutlined, AspectRatioRound, OpenInNewRound, FileDownloadOutlined, RotateRightRound, RotateLeftRound, KeyboardArrowLeftRound, KeyboardArrowRightRound, KeyboardDoubleArrowUpRound, SyncAltRound, VisibilityRound, VisibilityOffRound, MoreHorizRound, SearchRound, CheckRound, UnfoldMoreRound, CalendarMonthTwotone, AccessTimeRound, InfoOutlined, KeyboardArrowDownRound, ListAltRound, DriveFolderUploadOutlined, PlusSharp } from '@ricons/material';
6
6
  import { createRoot } from 'react-dom/client';
7
7
  import { createPortal } from 'react-dom';
@@ -132,9 +132,6 @@ function useKeydown(listener, options) {
132
132
  };
133
133
  }, []);
134
134
  }
135
- function useCreation(factory, deps) {
136
- return useMemo(factory, deps);
137
- }
138
135
  function useReactive(initialState) {
139
136
  const [, setFlag] = useState(0);
140
137
  const scheduledRef = useRef(false);
@@ -1328,16 +1325,10 @@ const List$1 = (props) => {
1328
1325
  };
1329
1326
  List$1.Item = Item$4;
1330
1327
 
1331
- const ModalContext = createContext(false);
1332
-
1333
- const Content$2 = (props) => {
1334
- const { ref, getContainer = (trigger) => {
1335
- if (typeof document === "undefined")
1336
- return null;
1337
- return trigger?.offsetParent ?? document.body;
1338
- }, trigger, arrow, arrowProps = {}, className, children, ...restProps } = props;
1328
+ const Content$2 = forwardRef((props, ref) => {
1329
+ const { arrow, arrowProps = {}, className, children, ...restProps } = props;
1339
1330
  const arrowCSS = useMemo(() => {
1340
- let { left, top, pos } = arrowProps;
1331
+ let { left = 0, top = 0, pos } = arrowProps;
1341
1332
  let transform = "";
1342
1333
  switch (pos) {
1343
1334
  case "left":
@@ -1364,153 +1355,324 @@ const Content$2 = (props) => {
1364
1355
  };
1365
1356
  }, [arrowProps]);
1366
1357
  const content = (jsxs("div", { ref: ref, className: classNames("i-popup", className), ...restProps, children: [arrow && (jsx("svg", { xmlns: 'http://www.w3.org/2000/svg', className: 'i-popup-arrow', style: arrowCSS, children: jsx("path", { d: 'M0.5 0L1.5 0C1.5 4, 3 5.5, 5 7.5S8,10 8,12S7 14.5, 5 16.5S1.5,20 1.5,24L0.5 24L0.5 0z' }) })), children] }));
1367
- const container = getContainer(trigger);
1358
+ const container = typeof document === "undefined" ? null : document.body;
1368
1359
  if (!container)
1369
1360
  return null;
1370
1361
  return createPortal(content, container);
1371
- };
1362
+ });
1372
1363
 
1373
1364
  function Popup(props) {
1374
- const { visible = false, content, trigger = "hover", gap = 12, offset = 8, fixed, position = "top", showDelay = 16, hideDelay = 12, touchable, arrow = true, align, fitSize, watchResize, clickOutside = true, disabled, style, className, getContainer, children, onVisibleChange, } = props;
1365
+ const { visible = false, content, trigger = "hover", gap = 12, offset = 8, position = "top", showDelay = 16, hideDelay = 12, touchable, arrow = true, align = "center", fitSize, disabled, style, className, children, onVisibleChange, } = props;
1375
1366
  const triggerRef = useRef(null);
1376
1367
  const contentRef = useRef(null);
1377
1368
  const timerRef = useRef(null);
1378
- const statusRef = useRef("");
1379
- const isInModal = useContext(ModalContext);
1380
- const refWindow = isInModal || fixed;
1381
- const state = useReactive({
1382
- show: false,
1383
- style: { position: refWindow ? "fixed" : "absolute" },
1384
- arrowProps: {},
1385
- });
1386
- useMouseUp((e) => {
1387
- if (!triggerRef.current || !contentRef.current || !clickOutside)
1388
- return;
1389
- const tar = e.target;
1390
- const isContain = triggerRef.current.contains(tar) ||
1391
- contentRef.current.contains(tar);
1392
- if (!state.show || isContain)
1393
- return;
1394
- handleToggle(false);
1369
+ const afterHideTimerRef = useRef(null);
1370
+ const rafRef = useRef(null);
1371
+ const [show, setShow] = useState(false);
1372
+ const showRef = useRef(false);
1373
+ showRef.current = show;
1374
+ const latestRef = useRef({
1375
+ disabled,
1376
+ trigger,
1377
+ touchable,
1378
+ showDelay,
1379
+ hideDelay,
1380
+ position,
1381
+ gap,
1382
+ offset,
1383
+ align,
1384
+ fitSize,
1385
+ onVisibleChange,
1395
1386
  });
1387
+ latestRef.current = {
1388
+ disabled,
1389
+ trigger,
1390
+ touchable,
1391
+ showDelay,
1392
+ hideDelay,
1393
+ position,
1394
+ gap,
1395
+ offset,
1396
+ align,
1397
+ fitSize,
1398
+ onVisibleChange,
1399
+ };
1400
+ const phaseRef = useRef("");
1401
+ const lastPosRef = useRef(null);
1402
+ const lastArrowRef = useRef(null);
1403
+ const arrowElRef = useRef(null);
1404
+ const pointRef = useRef(null);
1396
1405
  const clearTimer = () => {
1397
1406
  if (!timerRef.current)
1398
1407
  return;
1399
1408
  clearTimeout(timerRef.current);
1400
1409
  timerRef.current = null;
1401
- statusRef.current = "";
1410
+ phaseRef.current = "";
1411
+ };
1412
+ const clearAllTimers = () => {
1413
+ clearTimer();
1414
+ if (afterHideTimerRef.current) {
1415
+ clearTimeout(afterHideTimerRef.current);
1416
+ afterHideTimerRef.current = null;
1417
+ }
1418
+ if (rafRef.current !== null) {
1419
+ cancelAnimationFrame(rafRef.current);
1420
+ rafRef.current = null;
1421
+ }
1422
+ };
1423
+ const setContentVisible = (visible) => {
1424
+ const el = contentRef.current;
1425
+ if (!el)
1426
+ return;
1427
+ el.style.opacity = visible ? "1" : "0";
1428
+ el.style.transform = visible ? "none" : "translate(0, 2px)";
1429
+ };
1430
+ const ensureBaseStyle = () => {
1431
+ const el = contentRef.current;
1432
+ if (!el)
1433
+ return;
1434
+ const pos = "fixed";
1435
+ if (el.style.position !== pos)
1436
+ el.style.position = pos;
1437
+ };
1438
+ const applyFitSize = () => {
1439
+ const o = latestRef.current;
1440
+ const triggerEl = triggerRef.current;
1441
+ const contentEl = contentRef.current;
1442
+ if (!triggerEl || !contentEl)
1443
+ return;
1444
+ const vertical = ["top", "bottom"].includes(o.position);
1445
+ const key = vertical ? "width" : "height";
1446
+ if (!o.fitSize) {
1447
+ contentEl.style[key] = "";
1448
+ return;
1449
+ }
1450
+ const size = triggerEl[vertical ? "offsetWidth" : "offsetHeight"];
1451
+ contentEl.style[key] =
1452
+ typeof size === "number" ? `${size}px` : "";
1453
+ };
1454
+ const applyArrow = (arrowX, arrowY, arrowPos) => {
1455
+ const contentEl = contentRef.current;
1456
+ if (!contentEl)
1457
+ return;
1458
+ const arrowEl = arrowElRef.current ??
1459
+ contentEl.querySelector(".i-popup-arrow");
1460
+ arrowElRef.current = arrowEl;
1461
+ if (!arrowEl)
1462
+ return;
1463
+ let left = arrowX ?? 0;
1464
+ let top = arrowY ?? 0;
1465
+ let transform = "";
1466
+ switch (arrowPos) {
1467
+ case "left":
1468
+ left += 2;
1469
+ transform = `translate(-100%, -50%) rotate(180deg)`;
1470
+ break;
1471
+ case "right":
1472
+ left -= 2;
1473
+ transform = `translate(0, -50%)`;
1474
+ break;
1475
+ case "top":
1476
+ top -= 2;
1477
+ transform = `translate(-50%, -50%) rotate(-90deg)`;
1478
+ break;
1479
+ case "bottom":
1480
+ top += 2;
1481
+ transform = `translate(-50%, -50%) rotate(90deg)`;
1482
+ break;
1483
+ }
1484
+ const prev = lastArrowRef.current;
1485
+ if (prev &&
1486
+ prev.left === left &&
1487
+ prev.top === top &&
1488
+ prev.transform === transform) {
1489
+ return;
1490
+ }
1491
+ lastArrowRef.current = { left, top, transform };
1492
+ arrowEl.style.left = `${left}px`;
1493
+ arrowEl.style.top = `${top}px`;
1494
+ arrowEl.style.transform = transform;
1495
+ };
1496
+ const applyLeftTop = (left, top) => {
1497
+ const contentEl = contentRef.current;
1498
+ if (!contentEl)
1499
+ return;
1500
+ const prev = lastPosRef.current;
1501
+ if (prev && prev.left === left && prev.top === top)
1502
+ return;
1503
+ lastPosRef.current = { left, top };
1504
+ contentEl.style.left = `${left}px`;
1505
+ contentEl.style.top = `${top}px`;
1506
+ };
1507
+ const computeRelativePosition = () => {
1508
+ const triggerEl = triggerRef.current;
1509
+ const contentEl = contentRef.current;
1510
+ if (!triggerEl || !contentEl)
1511
+ return;
1512
+ const o = latestRef.current;
1513
+ applyFitSize();
1514
+ const [left, top, { arrowX, arrowY, arrowPos }] = getPosition(triggerEl, contentEl, {
1515
+ position: o.position,
1516
+ gap: o.gap,
1517
+ offset: o.offset,
1518
+ align: o.align,
1519
+ refWindow: true,
1520
+ });
1521
+ applyLeftTop(left, top);
1522
+ applyArrow(arrowX, arrowY, arrowPos);
1523
+ };
1524
+ const computePointPosition = () => {
1525
+ const contentEl = contentRef.current;
1526
+ if (!contentEl)
1527
+ return;
1528
+ const point = pointRef.current;
1529
+ if (!point)
1530
+ return;
1531
+ const [left, top] = getPointPosition(point, contentEl);
1532
+ applyLeftTop(left, top);
1533
+ };
1534
+ const scheduleComputePosition = () => {
1535
+ if (!showRef.current)
1536
+ return;
1537
+ if (rafRef.current !== null)
1538
+ return;
1539
+ rafRef.current = requestAnimationFrame(() => {
1540
+ rafRef.current = null;
1541
+ if (!showRef.current)
1542
+ return;
1543
+ ensureBaseStyle();
1544
+ if (latestRef.current.trigger === "contextmenu") {
1545
+ computePointPosition();
1546
+ return;
1547
+ }
1548
+ computeRelativePosition();
1549
+ });
1402
1550
  };
1403
1551
  const handleShow = () => {
1404
- if (disabled)
1552
+ const opts = latestRef.current;
1553
+ if (opts.disabled)
1405
1554
  return;
1406
- if (state.show &&
1407
- (trigger !== "hover" || (trigger === "hover" && !touchable))) {
1555
+ clearAllTimers();
1556
+ if (showRef.current &&
1557
+ (opts.trigger !== "hover" ||
1558
+ (opts.trigger === "hover" && !opts.touchable))) {
1559
+ ensureBaseStyle();
1560
+ computeRelativePosition();
1561
+ setContentVisible(true);
1408
1562
  return;
1409
1563
  }
1410
- statusRef.current = "showing";
1411
- state.show = true;
1564
+ phaseRef.current = "showing";
1565
+ if (!showRef.current) {
1566
+ lastPosRef.current = null;
1567
+ lastArrowRef.current = null;
1568
+ arrowElRef.current = null;
1569
+ setShow(true);
1570
+ }
1412
1571
  timerRef.current = setTimeout(() => {
1413
- if (statusRef.current !== "showing")
1572
+ if (phaseRef.current !== "showing")
1414
1573
  return;
1415
- requestAnimationFrame(() => {
1416
- if (statusRef.current !== "showing")
1574
+ rafRef.current = requestAnimationFrame(() => {
1575
+ rafRef.current = null;
1576
+ if (phaseRef.current !== "showing")
1417
1577
  return;
1418
- const [left, top, { arrowX, arrowY, arrowPos }] = getPosition(triggerRef.current, contentRef.current, {
1419
- position,
1420
- gap,
1421
- offset,
1422
- align,
1423
- refWindow,
1424
- });
1425
- state.style = {
1426
- ...state.style,
1427
- opacity: 1,
1428
- transform: "none",
1429
- left,
1430
- top,
1431
- };
1432
- state.arrowProps = {
1433
- left: arrowX,
1434
- top: arrowY,
1435
- pos: arrowPos,
1436
- };
1437
- onVisibleChange?.(true);
1578
+ if (!contentRef.current)
1579
+ return;
1580
+ ensureBaseStyle();
1581
+ if (opts.trigger === "contextmenu") {
1582
+ computePointPosition();
1583
+ }
1584
+ else {
1585
+ computeRelativePosition();
1586
+ }
1587
+ setContentVisible(true);
1588
+ opts.onVisibleChange?.(true);
1438
1589
  clearTimer();
1439
- statusRef.current = "";
1590
+ phaseRef.current = "";
1440
1591
  });
1441
- }, showDelay);
1592
+ }, opts.showDelay);
1442
1593
  };
1443
1594
  const handleHide = () => {
1444
- if (!state.show)
1595
+ if (!showRef.current)
1445
1596
  return;
1446
- statusRef.current = "hiding";
1597
+ clearAllTimers();
1598
+ phaseRef.current = "hiding";
1447
1599
  timerRef.current = setTimeout(() => {
1448
- if (statusRef.current !== "hiding") {
1600
+ if (phaseRef.current !== "hiding") {
1449
1601
  clearTimer();
1450
1602
  return;
1451
1603
  }
1452
- state.style = {
1453
- ...state.style,
1454
- opacity: 0,
1455
- transform: "translate(0, 2px)",
1456
- };
1457
- setTimeout(() => {
1458
- state.show = false;
1459
- clearTimer();
1460
- onVisibleChange?.(false);
1461
- statusRef.current = "";
1604
+ setContentVisible(false);
1605
+ afterHideTimerRef.current = setTimeout(() => {
1606
+ afterHideTimerRef.current = null;
1607
+ setShow(false);
1608
+ clearAllTimers();
1609
+ latestRef.current.onVisibleChange?.(false);
1610
+ phaseRef.current = "";
1462
1611
  }, 160);
1463
- }, hideDelay);
1612
+ }, latestRef.current.hideDelay);
1464
1613
  };
1465
1614
  const handleToggle = (action) => {
1466
1615
  if (action !== undefined) {
1467
1616
  action ? handleShow() : handleHide();
1468
1617
  return;
1469
1618
  }
1470
- state.show ? handleHide() : handleShow();
1471
- };
1472
- const eventMaps = useCreation(() => ({
1473
- click: {
1474
- onClick: () => handleToggle(true),
1475
- },
1476
- hover: {
1477
- onMouseEnter: () => handleToggle(true),
1478
- onMouseLeave: () => handleToggle(false),
1479
- },
1480
- focus: {
1481
- onFocus: () => handleToggle(true),
1482
- onBlur: () => handleToggle(false),
1483
- },
1484
- contextmenu: {
1485
- onContextMenu: (e) => {
1486
- e.preventDefault();
1487
- e.stopPropagation();
1488
- if (state.show) {
1489
- const [left, top] = getPointPosition(e, contentRef.current);
1490
- state.style = {
1491
- ...state.style,
1492
- left,
1493
- top,
1494
- };
1495
- return;
1496
- }
1497
- state.show = true;
1498
- timerRef.current = setTimeout(() => {
1499
- const [left, top] = getPointPosition(e, contentRef.current);
1500
- state.style = {
1501
- ...state.style,
1502
- opacity: 1,
1503
- transform: "none",
1504
- left,
1505
- top,
1619
+ showRef.current ? handleHide() : handleShow();
1620
+ };
1621
+ const hideRef = useRef(handleHide);
1622
+ const toggleRef = useRef(handleToggle);
1623
+ hideRef.current = handleHide;
1624
+ toggleRef.current = handleToggle;
1625
+ const doHide = useMemo(() => () => hideRef.current(), []);
1626
+ const doToggle = useMemo(() => (action) => toggleRef.current(action), []);
1627
+ const eventMaps = useMemo(() => {
1628
+ return {
1629
+ click: {
1630
+ onClick: () => doToggle(true),
1631
+ },
1632
+ hover: {
1633
+ onMouseEnter: () => doToggle(true),
1634
+ onMouseLeave: () => doToggle(false),
1635
+ },
1636
+ focus: {
1637
+ onFocus: () => doToggle(true),
1638
+ onBlur: () => doToggle(false),
1639
+ },
1640
+ contextmenu: {
1641
+ onContextMenu: (e) => {
1642
+ e.preventDefault();
1643
+ e.stopPropagation();
1644
+ pointRef.current = {
1645
+ pageX: e.pageX,
1646
+ pageY: e.pageY,
1506
1647
  };
1507
- clearTimer();
1508
- onVisibleChange?.(true);
1509
- }, showDelay);
1648
+ if (showRef.current) {
1649
+ ensureBaseStyle();
1650
+ computePointPosition();
1651
+ return;
1652
+ }
1653
+ clearAllTimers();
1654
+ phaseRef.current = "showing";
1655
+ lastPosRef.current = null;
1656
+ lastArrowRef.current = null;
1657
+ arrowElRef.current = null;
1658
+ setShow(true);
1659
+ timerRef.current = setTimeout(() => {
1660
+ if (phaseRef.current !== "showing")
1661
+ return;
1662
+ if (!contentRef.current)
1663
+ return;
1664
+ ensureBaseStyle();
1665
+ computePointPosition();
1666
+ setContentVisible(true);
1667
+ clearTimer();
1668
+ latestRef.current.onVisibleChange?.(true);
1669
+ phaseRef.current = "";
1670
+ }, latestRef.current.showDelay);
1671
+ },
1510
1672
  },
1511
- },
1512
- none: {},
1513
- }), []);
1673
+ none: {},
1674
+ };
1675
+ }, [doToggle]);
1514
1676
  const contentTouch = useMemo(() => {
1515
1677
  if (!touchable)
1516
1678
  return {};
@@ -1523,72 +1685,132 @@ function Popup(props) {
1523
1685
  }
1524
1686
  return events;
1525
1687
  }, [touchable, trigger]);
1526
- const computePosition = () => {
1527
- if (!state.show)
1528
- return;
1529
- const [left, top, { arrowX, arrowY, arrowPos }] = getPosition(triggerRef.current, contentRef.current, {
1530
- position,
1531
- gap,
1532
- offset,
1533
- align,
1534
- refWindow,
1535
- });
1536
- Object.assign(state, {
1537
- style: { ...state.style, left, top },
1538
- arrowProps: { left: arrowX, top: arrowY, pos: arrowPos },
1539
- });
1540
- };
1541
1688
  const { observe, unobserve, disconnect } = useResizeObserver();
1542
1689
  useEffect(() => {
1543
- if (trigger === "contextmenu" || !observe)
1544
- return;
1545
- triggerRef.current && observe(triggerRef.current, computePosition);
1546
- if (!watchResize || !contentRef.current)
1547
- return;
1548
- observe(contentRef.current, computePosition);
1690
+ if (!observe)
1691
+ return;
1692
+ const triggerEl = triggerRef.current;
1693
+ const contentEl = contentRef.current;
1694
+ if (triggerEl)
1695
+ observe(triggerEl, scheduleComputePosition);
1696
+ if (contentEl)
1697
+ observe(contentEl, scheduleComputePosition);
1549
1698
  return () => {
1550
- if (!watchResize || !contentRef.current)
1551
- return;
1552
- unobserve(contentRef.current);
1553
- triggerRef.current && unobserve(triggerRef.current);
1699
+ if (contentEl)
1700
+ unobserve(contentEl);
1701
+ if (triggerEl)
1702
+ unobserve(triggerEl);
1554
1703
  disconnect();
1555
1704
  };
1556
- }, [watchResize, contentRef.current, triggerRef.current]);
1705
+ }, [trigger, observe, unobserve, disconnect, show]);
1557
1706
  useLayoutEffect(() => {
1558
- if (!fitSize || !state.show)
1707
+ if (!show)
1559
1708
  return;
1560
- const vertical = ["top", "bottom"].includes(position);
1561
- const size = triggerRef.current?.[vertical ? "offsetWidth" : "offsetHeight"];
1562
- state.style = { ...state.style, [vertical ? "width" : "height"]: size };
1563
- }, [state.show, fitSize]);
1709
+ ensureBaseStyle();
1710
+ if (latestRef.current.trigger === "contextmenu") {
1711
+ computePointPosition();
1712
+ }
1713
+ else {
1714
+ computeRelativePosition();
1715
+ }
1716
+ }, [show]);
1564
1717
  useLayoutEffect(() => {
1565
- handleToggle(visible);
1718
+ doToggle(visible);
1566
1719
  }, [visible]);
1567
1720
  useEffect(() => {
1568
1721
  return () => {
1569
- clearTimer();
1722
+ clearAllTimers();
1570
1723
  };
1571
1724
  }, []);
1572
- return (jsxs(Fragment, { children: [Children.map(children, (child) => {
1573
- if (!isValidElement(child))
1574
- return;
1575
- const { className, ...restProps } = child.props;
1576
- Object.keys(eventMaps[trigger]).map((evt) => {
1577
- if (!restProps[evt])
1578
- return;
1579
- const fn = eventMaps[trigger][evt];
1580
- eventMaps[trigger][evt] = (e) => {
1581
- fn();
1582
- restProps[evt](e);
1583
- };
1584
- });
1585
- return cloneElement(child, {
1586
- ref: triggerRef,
1587
- className,
1588
- ...restProps,
1589
- ...eventMaps[trigger],
1725
+ const mouseUpHandlerRef = useRef(() => { });
1726
+ mouseUpHandlerRef.current = (e) => {
1727
+ if (!showRef.current)
1728
+ return;
1729
+ const triggerEl = triggerRef.current;
1730
+ const contentEl = contentRef.current;
1731
+ if (!triggerEl || !contentEl)
1732
+ return;
1733
+ const tar = e.target;
1734
+ if (triggerEl.contains(tar) || contentEl.contains(tar))
1735
+ return;
1736
+ doHide();
1737
+ };
1738
+ const onGlobalMouseUp = useMemo(() => (e) => mouseUpHandlerRef.current(e), []);
1739
+ useMouseUp(onGlobalMouseUp);
1740
+ useEffect(() => {
1741
+ if (!show)
1742
+ return;
1743
+ if (typeof window === "undefined")
1744
+ return;
1745
+ const onScrollOrResize = debounce({ delay: 160 }, () => {
1746
+ scheduleComputePosition();
1747
+ });
1748
+ window.addEventListener("scroll", onScrollOrResize, {
1749
+ passive: true,
1750
+ capture: true,
1751
+ });
1752
+ return () => {
1753
+ window.removeEventListener("scroll", onScrollOrResize, true);
1754
+ };
1755
+ }, [show]);
1756
+ const mergeRefs = (...refs) => {
1757
+ return (node) => {
1758
+ for (const ref of refs) {
1759
+ if (!ref)
1760
+ continue;
1761
+ if (typeof ref === "function") {
1762
+ ref(node);
1763
+ }
1764
+ else {
1765
+ ref.current = node;
1766
+ }
1767
+ }
1768
+ };
1769
+ };
1770
+ return (jsxs(Fragment, { children: [(() => {
1771
+ const events = eventMaps[trigger];
1772
+ const items = Children.toArray(children);
1773
+ const canAttachRef = (el) => {
1774
+ if (!isValidElement(el))
1775
+ return false;
1776
+ const t = el.type;
1777
+ if (typeof t === "string")
1778
+ return true;
1779
+ if (t?.prototype?.isReactComponent)
1780
+ return true;
1781
+ if (t?.$$typeof === Symbol.for("react.forward_ref"))
1782
+ return true;
1783
+ return false;
1784
+ };
1785
+ if (items.length !== 1) {
1786
+ return (jsx("div", { ref: triggerRef, ...events, className: 'i-popup-trigger', style: { display: "inline-block" }, children: children }));
1787
+ }
1788
+ const only = items[0];
1789
+ if (!isValidElement(only) || !canAttachRef(only)) {
1790
+ return (jsx("div", { ref: triggerRef, ...events, className: 'i-popup-trigger', style: { display: "inline-block" }, children: only }));
1791
+ }
1792
+ const { className: childClassName, ...restProps } = only.props;
1793
+ const nextProps = { ...restProps };
1794
+ for (const evt of Object.keys(events)) {
1795
+ const theirs = restProps[evt];
1796
+ const ours = events[evt];
1797
+ nextProps[evt] =
1798
+ typeof theirs === "function"
1799
+ ? (e) => {
1800
+ ours(e);
1801
+ theirs(e);
1802
+ }
1803
+ : ours;
1804
+ }
1805
+ return cloneElement(only, {
1806
+ ref: mergeRefs(only.ref, triggerRef),
1807
+ className: childClassName,
1808
+ ...nextProps,
1590
1809
  });
1591
- }), state.show && (jsx(Content$2, { ref: contentRef, arrow: arrow && trigger !== "contextmenu", style: { ...style, ...state.style }, arrowProps: state.arrowProps, className: className, ...contentTouch, trigger: triggerRef.current, getContainer: getContainer, children: content }))] }));
1810
+ })(), show && (jsx(Content$2, { ref: contentRef, arrow: arrow && trigger !== "contextmenu", style: {
1811
+ ...style,
1812
+ position: "fixed",
1813
+ }, className: className, ...contentTouch, trigger: triggerRef.current, children: content }))] }));
1592
1814
  }
1593
1815
 
1594
1816
  const { Item: ListItem } = List$1;
@@ -2087,6 +2309,8 @@ function Content$1(props) {
2087
2309
  return (jsxs(Fragment, { children: [showHeader && (jsxs("header", { className: 'i-modal-header', children: [title && jsx("b", { children: title }), jsx(Helpericon, { active: !hideCloseButton, className: 'i-modal-close', onClick: onClose })] })), jsx("div", { className: 'i-modal-content', children: children }), jsx("footer", { className: 'i-modal-footer', children: renderFooter })] }));
2088
2310
  }
2089
2311
 
2312
+ const ModalContext = createContext(false);
2313
+
2090
2314
  function useModal() {
2091
2315
  const ref = useRef(null);
2092
2316
  const handleOpen = (props) => {
@@ -3683,7 +3907,7 @@ const Datepicker = (props) => {
3683
3907
  useEffect(() => {
3684
3908
  setInputValue(value);
3685
3909
  }, [value]);
3686
- return (jsx(Popup, { visible: active, trigger: 'click', position: 'bottom', arrow: false, align: 'start', onVisibleChange: handleVisibleChange, watchResize: true, content: jsx(Panel$1, { value: dayJsValue, weeks: weeks, renderDate: renderDate, renderMonth: renderMonth, renderYear: renderYear, disabledDate: disabledDate, onDateClick: handleDateClick }), ...popupProps, children: jsx(Input, { value: inputValue, append: jsx(Icon, { icon: jsx(CalendarMonthTwotone, {}), className: 'i-datepicker-icon', size: '1em' }), placeholder: placeholder, onChange: handleChange, onBlur: handleBlur, onEnter: handleSetDate, className: classNames("i-datepicker-label", className), ...restProps }) }));
3910
+ return (jsx(Popup, { visible: active, trigger: 'click', position: 'bottom', arrow: false, align: 'start', onVisibleChange: handleVisibleChange, content: jsx(Panel$1, { value: dayJsValue, weeks: weeks, renderDate: renderDate, renderMonth: renderMonth, renderYear: renderYear, disabledDate: disabledDate, onDateClick: handleDateClick }), ...popupProps, children: jsx(Input, { value: inputValue, append: jsx(Icon, { icon: jsx(CalendarMonthTwotone, {}), className: 'i-datepicker-icon', size: '1em' }), placeholder: placeholder, onChange: handleChange, onBlur: handleBlur, onEnter: handleSetDate, className: classNames("i-datepicker-label", className), ...restProps }) }));
3687
3911
  };
3688
3912
 
3689
3913
  function Items(props) {
@@ -3818,7 +4042,7 @@ function TimePicker(props) {
3818
4042
  useEffect(() => {
3819
4043
  setTimeValue(value);
3820
4044
  }, [value]);
3821
- return (jsx(Popup, { visible: active, trigger: 'click', position: 'bottom', arrow: false, align: 'start', watchResize: true, ...popupProps, onVisibleChange: handleVisibleChange, content: jsx(Panel, { value: timeValue, format: format, periods: periods, renderItem: renderItem, onChange: handleChange, onFallback: handleFallback }), children: jsx(Input, { value: timeValue, placeholder: placeholder, append: jsx(Icon, { icon: jsx(AccessTimeRound, {}), className: 'i-timepicker-icon', size: '1em' }), onChange: handleChange, onBlur: handleBlur, className: classNames("i-timepicker-label", className), ...restProps }) }));
4045
+ return (jsx(Popup, { visible: active, trigger: 'click', position: 'bottom', arrow: false, align: 'start', ...popupProps, onVisibleChange: handleVisibleChange, content: jsx(Panel, { value: timeValue, format: format, periods: periods, renderItem: renderItem, onChange: handleChange, onFallback: handleFallback }), children: jsx(Input, { value: timeValue, placeholder: placeholder, append: jsx(Icon, { icon: jsx(AccessTimeRound, {}), className: 'i-timepicker-icon', size: '1em' }), onChange: handleChange, onBlur: handleBlur, className: classNames("i-timepicker-label", className), ...restProps }) }));
3822
4046
  }
3823
4047
 
3824
4048
  const defaultOk = {
@@ -3829,7 +4053,7 @@ const defaultCancel = {
3829
4053
  secondary: true,
3830
4054
  };
3831
4055
  const Popconfirm = (props) => {
3832
- const { trigger = "click", visible, icon = jsx(Icon, { icon: jsx(InfoOutlined, {}), className: 'error', size: '1.2em' }), content, okButtonProps, cancelButtonProps, children, align = "end", position = "top", offset = 12, extra, onOk, onClose, ...restProps } = props;
4056
+ const { trigger = "click", visible, icon = jsx(Icon, { icon: jsx(InfoOutlined, {}), className: 'error', size: '1.2em' }), content, okButtonProps, cancelButtonProps, children, align, position = "top", offset = 12, extra, onOk, onClose, ...restProps } = props;
3833
4057
  const state = useReactive({
3834
4058
  loading: false,
3835
4059
  visible,