react-resizable-panels 2.1.7 → 2.1.9

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.
Files changed (27) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +4 -0
  3. package/dist/declarations/src/Panel.d.ts +1 -1
  4. package/dist/declarations/src/PanelGroup.d.ts +1 -1
  5. package/dist/declarations/src/PanelResizeHandle.d.ts +6 -3
  6. package/dist/declarations/src/constants.d.ts +15 -0
  7. package/dist/declarations/src/index.d.ts +3 -2
  8. package/dist/react-resizable-panels.browser.cjs.js +202 -176
  9. package/dist/react-resizable-panels.browser.cjs.mjs +1 -0
  10. package/dist/react-resizable-panels.browser.development.cjs.js +202 -176
  11. package/dist/react-resizable-panels.browser.development.cjs.mjs +1 -0
  12. package/dist/react-resizable-panels.browser.development.esm.js +150 -124
  13. package/dist/react-resizable-panels.browser.esm.js +150 -124
  14. package/dist/react-resizable-panels.cjs.js +202 -176
  15. package/dist/react-resizable-panels.cjs.mjs +1 -0
  16. package/dist/react-resizable-panels.development.cjs.js +202 -176
  17. package/dist/react-resizable-panels.development.cjs.mjs +1 -0
  18. package/dist/react-resizable-panels.development.esm.js +150 -124
  19. package/dist/react-resizable-panels.development.node.cjs.js +201 -174
  20. package/dist/react-resizable-panels.development.node.cjs.mjs +1 -0
  21. package/dist/react-resizable-panels.development.node.esm.js +149 -122
  22. package/dist/react-resizable-panels.esm.js +150 -124
  23. package/dist/react-resizable-panels.node.cjs.js +201 -174
  24. package/dist/react-resizable-panels.node.cjs.mjs +1 -0
  25. package/dist/react-resizable-panels.node.esm.js +149 -122
  26. package/package.json +12 -13
  27. package/dist/declarations/src/vendor/react.d.ts +0 -7
@@ -24,38 +24,33 @@ function _interopNamespace(e) {
24
24
 
25
25
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
26
26
 
27
- // This module exists to work around Webpack issue https://github.com/webpack/webpack/issues/14814
28
-
29
- // eslint-disable-next-line no-restricted-imports
30
-
31
- const {
32
- createElement,
33
- createContext,
34
- createRef,
35
- forwardRef,
36
- useCallback,
37
- useContext,
38
- useEffect,
39
- useImperativeHandle,
40
- useLayoutEffect,
41
- useMemo,
42
- useRef,
43
- useState
44
- } = React__namespace;
45
-
46
- // `Math.random()` and `.slice(0, 5)` prevents bundlers from trying to `import { useId } from 'react'`
47
- const useId = React__namespace[`useId${Math.random()}`.slice(0, 5)];
48
-
49
27
  // The "contextmenu" event is not supported as a PointerEvent in all browsers yet, so MouseEvent still need to be handled
50
28
 
51
- const PanelGroupContext = createContext(null);
29
+ const PanelGroupContext = React.createContext(null);
52
30
  PanelGroupContext.displayName = "PanelGroupContext";
53
31
 
32
+ const DATA_ATTRIBUTES = {
33
+ group: "data-panel-group",
34
+ groupDirection: "data-panel-group-direction",
35
+ groupId: "data-panel-group-id",
36
+ panel: "data-panel",
37
+ panelCollapsible: "data-panel-collapsible",
38
+ panelId: "data-panel-id",
39
+ panelSize: "data-panel-size",
40
+ resizeHandle: "data-resize-handle",
41
+ resizeHandleActive: "data-resize-handle-active",
42
+ resizeHandleEnabled: "data-panel-resize-handle-enabled",
43
+ resizeHandleId: "data-panel-resize-handle-id",
44
+ resizeHandleState: "data-resize-handle-state"
45
+ };
46
+ const PRECISION = 10;
47
+
48
+ const useId = React__namespace["useId".toString()];
54
49
  const wrappedUseId = typeof useId === "function" ? useId : () => null;
55
50
  let counter = 0;
56
51
  function useUniqueId(idFromParams = null) {
57
52
  const idFromUseId = wrappedUseId();
58
- const idRef = useRef(idFromParams || idFromUseId || null);
53
+ const idRef = React.useRef(idFromParams || idFromUseId || null);
59
54
  if (idRef.current === null) {
60
55
  idRef.current = "" + counter++;
61
56
  }
@@ -80,7 +75,7 @@ function PanelWithForwardedRef({
80
75
  tagName: Type = "div",
81
76
  ...rest
82
77
  }) {
83
- const context = useContext(PanelGroupContext);
78
+ const context = React.useContext(PanelGroupContext);
84
79
  if (context === null) {
85
80
  throw Error(`Panel components must be rendered within a PanelGroup container`);
86
81
  }
@@ -97,7 +92,7 @@ function PanelWithForwardedRef({
97
92
  unregisterPanel
98
93
  } = context;
99
94
  const panelId = useUniqueId(idFromProps);
100
- const panelDataRef = useRef({
95
+ const panelDataRef = React.useRef({
101
96
  callbacks: {
102
97
  onCollapse,
103
98
  onExpand,
@@ -114,10 +109,10 @@ function PanelWithForwardedRef({
114
109
  idIsFromProps: idFromProps !== undefined,
115
110
  order
116
111
  });
117
- useRef({
112
+ React.useRef({
118
113
  didLogMissingDefaultSizeWarning: false
119
114
  });
120
- useImperativeHandle(forwardedRef, () => ({
115
+ React.useImperativeHandle(forwardedRef, () => ({
121
116
  collapse: () => {
122
117
  collapsePanel(panelDataRef.current);
123
118
  },
@@ -141,24 +136,24 @@ function PanelWithForwardedRef({
141
136
  }
142
137
  }), [collapsePanel, expandPanel, getPanelSize, isPanelCollapsed, panelId, resizePanel]);
143
138
  const style = getPanelStyle(panelDataRef.current, defaultSize);
144
- return createElement(Type, {
139
+ return React.createElement(Type, {
145
140
  ...rest,
146
141
  children,
147
142
  className: classNameFromProps,
148
- id: idFromProps,
143
+ id: panelId,
149
144
  style: {
150
145
  ...style,
151
146
  ...styleFromProps
152
147
  },
153
148
  // CSS selectors
154
- "data-panel": "",
155
- "data-panel-collapsible": collapsible || undefined,
156
- "data-panel-group-id": groupId,
157
- "data-panel-id": panelId,
158
- "data-panel-size": parseFloat("" + style.flexGrow).toFixed(1)
149
+ [DATA_ATTRIBUTES.groupId]: groupId,
150
+ [DATA_ATTRIBUTES.panel]: "",
151
+ [DATA_ATTRIBUTES.panelCollapsible]: collapsible || undefined,
152
+ [DATA_ATTRIBUTES.panelId]: panelId,
153
+ [DATA_ATTRIBUTES.panelSize]: parseFloat("" + style.flexGrow).toFixed(1)
159
154
  });
160
155
  }
161
- const Panel = forwardRef((props, ref) => createElement(PanelWithForwardedRef, {
156
+ const Panel = React.forwardRef((props, ref) => React.createElement(PanelWithForwardedRef, {
162
157
  ...props,
163
158
  forwardedRef: ref
164
159
  }));
@@ -175,6 +170,7 @@ function setNonce(value) {
175
170
 
176
171
  let currentCursorStyle = null;
177
172
  let enabled = true;
173
+ let prevRuleIndex = -1;
178
174
  let styleElement = null;
179
175
  function disableGlobalCursorStyles() {
180
176
  enabled = false;
@@ -224,9 +220,11 @@ function resetGlobalCursorStyle() {
224
220
  document.head.removeChild(styleElement);
225
221
  currentCursorStyle = null;
226
222
  styleElement = null;
223
+ prevRuleIndex = -1;
227
224
  }
228
225
  }
229
226
  function setGlobalCursorStyle(state, constraintFlags) {
227
+ var _styleElement$sheet$i, _styleElement$sheet2;
230
228
  if (!enabled) {
231
229
  return;
232
230
  }
@@ -243,7 +241,11 @@ function setGlobalCursorStyle(state, constraintFlags) {
243
241
  }
244
242
  document.head.appendChild(styleElement);
245
243
  }
246
- styleElement.innerHTML = `*{cursor: ${style}!important;}`;
244
+ if (prevRuleIndex >= 0) {
245
+ var _styleElement$sheet;
246
+ (_styleElement$sheet = styleElement.sheet) === null || _styleElement$sheet === void 0 ? void 0 : _styleElement$sheet.removeRule(prevRuleIndex);
247
+ }
248
+ prevRuleIndex = (_styleElement$sheet$i = (_styleElement$sheet2 = styleElement.sheet) === null || _styleElement$sheet2 === void 0 ? void 0 : _styleElement$sheet2.insertRule(`*{cursor: ${style} !important;}`)) !== null && _styleElement$sheet$i !== void 0 ? _styleElement$sheet$i : -1;
247
249
  }
248
250
 
249
251
  function isKeyDown(event) {
@@ -474,7 +476,9 @@ function handlePointerDown(event) {
474
476
  if (intersectingHandles.length > 0) {
475
477
  updateResizeHandlerStates("down", event);
476
478
  event.preventDefault();
477
- event.stopPropagation();
479
+ if (!isWithinResizeHandle(target)) {
480
+ event.stopImmediatePropagation();
481
+ }
478
482
  }
479
483
  }
480
484
  function handlePointerMove(event) {
@@ -523,6 +527,9 @@ function handlePointerUp(event) {
523
527
  isPointerDown = false;
524
528
  if (intersectingHandles.length > 0) {
525
529
  event.preventDefault();
530
+ if (!isWithinResizeHandle(target)) {
531
+ event.stopImmediatePropagation();
532
+ }
526
533
  }
527
534
  updateResizeHandlerStates("up", event);
528
535
  recalculateIntersectingHandles({
@@ -533,6 +540,16 @@ function handlePointerUp(event) {
533
540
  updateCursor();
534
541
  updateListeners();
535
542
  }
543
+ function isWithinResizeHandle(element) {
544
+ let currentElement = element;
545
+ while (currentElement) {
546
+ if (currentElement.hasAttribute(DATA_ATTRIBUTES.resizeHandle)) {
547
+ return true;
548
+ }
549
+ currentElement = currentElement.parentElement;
550
+ }
551
+ return false;
552
+ }
536
553
  function recalculateIntersectingHandles({
537
554
  target,
538
555
  x,
@@ -624,47 +641,42 @@ function updateCursor() {
624
641
  resetGlobalCursorStyle();
625
642
  }
626
643
  }
644
+ let listenersAbortController = new AbortController();
627
645
  function updateListeners() {
628
- ownerDocumentCounts.forEach((_, ownerDocument) => {
629
- const {
630
- body
631
- } = ownerDocument;
632
- body.removeEventListener("contextmenu", handlePointerUp);
633
- body.removeEventListener("pointerdown", handlePointerDown);
634
- body.removeEventListener("pointerleave", handlePointerMove);
635
- body.removeEventListener("pointermove", handlePointerMove);
636
- });
637
- window.removeEventListener("pointerup", handlePointerUp);
638
- window.removeEventListener("pointercancel", handlePointerUp);
639
- if (registeredResizeHandlers.size > 0) {
640
- if (isPointerDown) {
641
- if (intersectingHandles.length > 0) {
642
- ownerDocumentCounts.forEach((count, ownerDocument) => {
643
- const {
644
- body
645
- } = ownerDocument;
646
- if (count > 0) {
647
- body.addEventListener("contextmenu", handlePointerUp);
648
- body.addEventListener("pointerleave", handlePointerMove);
649
- body.addEventListener("pointermove", handlePointerMove);
650
- }
651
- });
652
- }
653
- window.addEventListener("pointerup", handlePointerUp);
654
- window.addEventListener("pointercancel", handlePointerUp);
655
- } else {
646
+ listenersAbortController.abort();
647
+ listenersAbortController = new AbortController();
648
+ const options = {
649
+ capture: true,
650
+ signal: listenersAbortController.signal
651
+ };
652
+ if (!registeredResizeHandlers.size) {
653
+ return;
654
+ }
655
+ if (isPointerDown) {
656
+ if (intersectingHandles.length > 0) {
656
657
  ownerDocumentCounts.forEach((count, ownerDocument) => {
657
658
  const {
658
659
  body
659
660
  } = ownerDocument;
660
661
  if (count > 0) {
661
- body.addEventListener("pointerdown", handlePointerDown, {
662
- capture: true
663
- });
664
- body.addEventListener("pointermove", handlePointerMove);
662
+ body.addEventListener("contextmenu", handlePointerUp, options);
663
+ body.addEventListener("pointerleave", handlePointerMove, options);
664
+ body.addEventListener("pointermove", handlePointerMove, options);
665
665
  }
666
666
  });
667
667
  }
668
+ window.addEventListener("pointerup", handlePointerUp, options);
669
+ window.addEventListener("pointercancel", handlePointerUp, options);
670
+ } else {
671
+ ownerDocumentCounts.forEach((count, ownerDocument) => {
672
+ const {
673
+ body
674
+ } = ownerDocument;
675
+ if (count > 0) {
676
+ body.addEventListener("pointerdown", handlePointerDown, options);
677
+ body.addEventListener("pointermove", handlePointerMove, options);
678
+ }
679
+ });
668
680
  }
669
681
  }
670
682
  function updateResizeHandlerStates(action, event) {
@@ -678,8 +690,8 @@ function updateResizeHandlerStates(action, event) {
678
690
  }
679
691
 
680
692
  function useForceUpdate() {
681
- const [_, setCount] = useState(0);
682
- return useCallback(() => setCount(prevCount => prevCount + 1), []);
693
+ const [_, setCount] = React.useState(0);
694
+ return React.useCallback(() => setCount(prevCount => prevCount + 1), []);
683
695
  }
684
696
 
685
697
  function assert(expectedCondition, message) {
@@ -689,8 +701,6 @@ function assert(expectedCondition, message) {
689
701
  }
690
702
  }
691
703
 
692
- const PRECISION = 10;
693
-
694
704
  function fuzzyCompareNumbers(actual, expected, fractionDigits = PRECISION) {
695
705
  if (actual.toFixed(fractionDigits) === expected.toFixed(fractionDigits)) {
696
706
  return 0;
@@ -995,12 +1005,12 @@ function adjustLayoutByDelta({
995
1005
  }
996
1006
 
997
1007
  function getResizeHandleElementsForGroup(groupId, scope = document) {
998
- return Array.from(scope.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${groupId}"]`));
1008
+ return Array.from(scope.querySelectorAll(`[${DATA_ATTRIBUTES.resizeHandleId}][data-panel-group-id="${groupId}"]`));
999
1009
  }
1000
1010
 
1001
1011
  function getResizeHandleElementIndex(groupId, id, scope = document) {
1002
1012
  const handles = getResizeHandleElementsForGroup(groupId, scope);
1003
- const index = handles.findIndex(handle => handle.getAttribute("data-panel-resize-handle-id") === id);
1013
+ const index = handles.findIndex(handle => handle.getAttribute(DATA_ATTRIBUTES.resizeHandleId) === id);
1004
1014
  return index !== null && index !== void 0 ? index : null;
1005
1015
  }
1006
1016
 
@@ -1025,7 +1035,7 @@ function getPanelGroupElement(id, rootElement = document) {
1025
1035
  }
1026
1036
 
1027
1037
  function getResizeHandleElement(id, scope = document) {
1028
- const element = scope.querySelector(`[data-panel-resize-handle-id="${id}"]`);
1038
+ const element = scope.querySelector(`[${DATA_ATTRIBUTES.resizeHandleId}="${id}"]`);
1029
1039
  if (element) {
1030
1040
  return element;
1031
1041
  }
@@ -1053,10 +1063,10 @@ function useWindowSplitterPanelGroupBehavior({
1053
1063
  panelGroupElement,
1054
1064
  setLayout
1055
1065
  }) {
1056
- useRef({
1066
+ React.useRef({
1057
1067
  didWarnAboutMissingResizeHandle: false
1058
1068
  });
1059
- useEffect(() => {
1069
+ React.useEffect(() => {
1060
1070
  if (!panelGroupElement) {
1061
1071
  return;
1062
1072
  }
@@ -1070,7 +1080,7 @@ function useWindowSplitterPanelGroupBehavior({
1070
1080
  const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
1071
1081
  assert(handles, `No resize handles found for group id "${groupId}"`);
1072
1082
  const cleanupFunctions = handles.map(handle => {
1073
- const handleId = handle.getAttribute("data-panel-resize-handle-id");
1083
+ const handleId = handle.getAttribute(DATA_ATTRIBUTES.resizeHandleId);
1074
1084
  assert(handleId, `Resize handle element has no handle id attribute`);
1075
1085
  const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelDataArray, panelGroupElement);
1076
1086
  if (idBefore == null || idAfter == null) {
@@ -1148,7 +1158,7 @@ function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDr
1148
1158
  const isHorizontal = direction === "horizontal";
1149
1159
  const handleElement = getResizeHandleElement(dragHandleId, panelGroupElement);
1150
1160
  assert(handleElement, `No resize handle element found for id "${dragHandleId}"`);
1151
- const groupId = handleElement.getAttribute("data-panel-group-id");
1161
+ const groupId = handleElement.getAttribute(DATA_ATTRIBUTES.groupId);
1152
1162
  assert(groupId, `Resize handle element has no group id attribute`);
1153
1163
  let {
1154
1164
  initialCursorPosition
@@ -1468,14 +1478,14 @@ function PanelGroupWithForwardedRef({
1468
1478
  ...rest
1469
1479
  }) {
1470
1480
  const groupId = useUniqueId(idFromProps);
1471
- const panelGroupElementRef = useRef(null);
1472
- const [dragState, setDragState] = useState(null);
1473
- const [layout, setLayout] = useState([]);
1481
+ const panelGroupElementRef = React.useRef(null);
1482
+ const [dragState, setDragState] = React.useState(null);
1483
+ const [layout, setLayout] = React.useState([]);
1474
1484
  const forceUpdate = useForceUpdate();
1475
- const panelIdToLastNotifiedSizeMapRef = useRef({});
1476
- const panelSizeBeforeCollapseRef = useRef(new Map());
1477
- const prevDeltaRef = useRef(0);
1478
- const committedValuesRef = useRef({
1485
+ const panelIdToLastNotifiedSizeMapRef = React.useRef({});
1486
+ const panelSizeBeforeCollapseRef = React.useRef(new Map());
1487
+ const prevDeltaRef = React.useRef(0);
1488
+ const committedValuesRef = React.useRef({
1479
1489
  autoSaveId,
1480
1490
  direction,
1481
1491
  dragState,
@@ -1484,17 +1494,17 @@ function PanelGroupWithForwardedRef({
1484
1494
  onLayout,
1485
1495
  storage
1486
1496
  });
1487
- const eagerValuesRef = useRef({
1497
+ const eagerValuesRef = React.useRef({
1488
1498
  layout,
1489
1499
  panelDataArray: [],
1490
1500
  panelDataArrayChanged: false
1491
1501
  });
1492
- useRef({
1502
+ React.useRef({
1493
1503
  didLogIdAndOrderWarning: false,
1494
1504
  didLogPanelConstraintsWarning: false,
1495
1505
  prevPanelIds: []
1496
1506
  });
1497
- useImperativeHandle(forwardedRef, () => ({
1507
+ React.useImperativeHandle(forwardedRef, () => ({
1498
1508
  getId: () => committedValuesRef.current.id,
1499
1509
  getLayout: () => {
1500
1510
  const {
@@ -1533,7 +1543,7 @@ function PanelGroupWithForwardedRef({
1533
1543
  setLayout,
1534
1544
  panelGroupElement: panelGroupElementRef.current
1535
1545
  });
1536
- useEffect(() => {
1546
+ React.useEffect(() => {
1537
1547
  const {
1538
1548
  panelDataArray
1539
1549
  } = eagerValuesRef.current;
@@ -1560,11 +1570,11 @@ function PanelGroupWithForwardedRef({
1560
1570
  }, [autoSaveId, layout, storage]);
1561
1571
 
1562
1572
  // DEV warnings
1563
- useEffect(() => {
1573
+ React.useEffect(() => {
1564
1574
  });
1565
1575
 
1566
1576
  // External APIs are safe to memoize via committed values ref
1567
- const collapsePanel = useCallback(panelData => {
1577
+ const collapsePanel = React.useCallback(panelData => {
1568
1578
  const {
1569
1579
  onLayout
1570
1580
  } = committedValuesRef.current;
@@ -1607,7 +1617,7 @@ function PanelGroupWithForwardedRef({
1607
1617
  }, []);
1608
1618
 
1609
1619
  // External APIs are safe to memoize via committed values ref
1610
- const expandPanel = useCallback((panelData, minSizeOverride) => {
1620
+ const expandPanel = React.useCallback((panelData, minSizeOverride) => {
1611
1621
  const {
1612
1622
  onLayout
1613
1623
  } = committedValuesRef.current;
@@ -1651,7 +1661,7 @@ function PanelGroupWithForwardedRef({
1651
1661
  }, []);
1652
1662
 
1653
1663
  // External APIs are safe to memoize via committed values ref
1654
- const getPanelSize = useCallback(panelData => {
1664
+ const getPanelSize = React.useCallback(panelData => {
1655
1665
  const {
1656
1666
  layout,
1657
1667
  panelDataArray
@@ -1664,7 +1674,7 @@ function PanelGroupWithForwardedRef({
1664
1674
  }, []);
1665
1675
 
1666
1676
  // This API should never read from committedValuesRef
1667
- const getPanelStyle = useCallback((panelData, defaultSize) => {
1677
+ const getPanelStyle = React.useCallback((panelData, defaultSize) => {
1668
1678
  const {
1669
1679
  panelDataArray
1670
1680
  } = eagerValuesRef.current;
@@ -1679,7 +1689,7 @@ function PanelGroupWithForwardedRef({
1679
1689
  }, [dragState, layout]);
1680
1690
 
1681
1691
  // External APIs are safe to memoize via committed values ref
1682
- const isPanelCollapsed = useCallback(panelData => {
1692
+ const isPanelCollapsed = React.useCallback(panelData => {
1683
1693
  const {
1684
1694
  layout,
1685
1695
  panelDataArray
@@ -1694,7 +1704,7 @@ function PanelGroupWithForwardedRef({
1694
1704
  }, []);
1695
1705
 
1696
1706
  // External APIs are safe to memoize via committed values ref
1697
- const isPanelExpanded = useCallback(panelData => {
1707
+ const isPanelExpanded = React.useCallback(panelData => {
1698
1708
  const {
1699
1709
  layout,
1700
1710
  panelDataArray
@@ -1707,7 +1717,7 @@ function PanelGroupWithForwardedRef({
1707
1717
  assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
1708
1718
  return !collapsible || fuzzyCompareNumbers(panelSize, collapsedSize) > 0;
1709
1719
  }, []);
1710
- const registerPanel = useCallback(panelData => {
1720
+ const registerPanel = React.useCallback(panelData => {
1711
1721
  const {
1712
1722
  panelDataArray
1713
1723
  } = eagerValuesRef.current;
@@ -1728,7 +1738,7 @@ function PanelGroupWithForwardedRef({
1728
1738
  eagerValuesRef.current.panelDataArrayChanged = true;
1729
1739
  forceUpdate();
1730
1740
  }, [forceUpdate]);
1731
- const registerResizeHandle = useCallback(dragHandleId => {
1741
+ const registerResizeHandle = React.useCallback(dragHandleId => {
1732
1742
  let isRTL = false;
1733
1743
  const panelGroupElement = panelGroupElementRef.current;
1734
1744
  if (panelGroupElement) {
@@ -1807,7 +1817,7 @@ function PanelGroupWithForwardedRef({
1807
1817
  }, []);
1808
1818
 
1809
1819
  // External APIs are safe to memoize via committed values ref
1810
- const resizePanel = useCallback((panelData, unsafePanelSize) => {
1820
+ const resizePanel = React.useCallback((panelData, unsafePanelSize) => {
1811
1821
  const {
1812
1822
  onLayout
1813
1823
  } = committedValuesRef.current;
@@ -1840,7 +1850,7 @@ function PanelGroupWithForwardedRef({
1840
1850
  callPanelCallbacks(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
1841
1851
  }
1842
1852
  }, []);
1843
- const reevaluatePanelConstraints = useCallback((panelData, prevConstraints) => {
1853
+ const reevaluatePanelConstraints = React.useCallback((panelData, prevConstraints) => {
1844
1854
  const {
1845
1855
  layout,
1846
1856
  panelDataArray
@@ -1874,7 +1884,7 @@ function PanelGroupWithForwardedRef({
1874
1884
  }, [resizePanel]);
1875
1885
 
1876
1886
  // TODO Multiple drag handles can be active at the same time so this API is a bit awkward now
1877
- const startDragging = useCallback((dragHandleId, event) => {
1887
+ const startDragging = React.useCallback((dragHandleId, event) => {
1878
1888
  const {
1879
1889
  direction
1880
1890
  } = committedValuesRef.current;
@@ -1894,10 +1904,10 @@ function PanelGroupWithForwardedRef({
1894
1904
  initialLayout: layout
1895
1905
  });
1896
1906
  }, []);
1897
- const stopDragging = useCallback(() => {
1907
+ const stopDragging = React.useCallback(() => {
1898
1908
  setDragState(null);
1899
1909
  }, []);
1900
- const unregisterPanel = useCallback(panelData => {
1910
+ const unregisterPanel = React.useCallback(panelData => {
1901
1911
  const {
1902
1912
  panelDataArray
1903
1913
  } = eagerValuesRef.current;
@@ -1914,7 +1924,7 @@ function PanelGroupWithForwardedRef({
1914
1924
  forceUpdate();
1915
1925
  }
1916
1926
  }, [forceUpdate]);
1917
- const context = useMemo(() => ({
1927
+ const context = React.useMemo(() => ({
1918
1928
  collapsePanel,
1919
1929
  direction,
1920
1930
  dragState,
@@ -1940,9 +1950,9 @@ function PanelGroupWithForwardedRef({
1940
1950
  overflow: "hidden",
1941
1951
  width: "100%"
1942
1952
  };
1943
- return createElement(PanelGroupContext.Provider, {
1953
+ return React.createElement(PanelGroupContext.Provider, {
1944
1954
  value: context
1945
- }, createElement(Type, {
1955
+ }, React.createElement(Type, {
1946
1956
  ...rest,
1947
1957
  children,
1948
1958
  className: classNameFromProps,
@@ -1953,12 +1963,12 @@ function PanelGroupWithForwardedRef({
1953
1963
  ...styleFromProps
1954
1964
  },
1955
1965
  // CSS selectors
1956
- "data-panel-group": "",
1957
- "data-panel-group-direction": direction,
1958
- "data-panel-group-id": groupId
1966
+ [DATA_ATTRIBUTES.group]: "",
1967
+ [DATA_ATTRIBUTES.groupDirection]: direction,
1968
+ [DATA_ATTRIBUTES.groupId]: groupId
1959
1969
  }));
1960
1970
  }
1961
- const PanelGroup = forwardRef((props, ref) => createElement(PanelGroupWithForwardedRef, {
1971
+ const PanelGroup = React.forwardRef((props, ref) => React.createElement(PanelGroupWithForwardedRef, {
1962
1972
  ...props,
1963
1973
  forwardedRef: ref
1964
1974
  }));
@@ -1987,7 +1997,7 @@ function useWindowSplitterResizeHandlerBehavior({
1987
1997
  resizeHandler,
1988
1998
  panelGroupElement
1989
1999
  }) {
1990
- useEffect(() => {
2000
+ React.useEffect(() => {
1991
2001
  if (disabled || resizeHandler == null || panelGroupElement == null) {
1992
2002
  return;
1993
2003
  }
@@ -2014,7 +2024,7 @@ function useWindowSplitterResizeHandlerBehavior({
2014
2024
  case "F6":
2015
2025
  {
2016
2026
  event.preventDefault();
2017
- const groupId = handleElement.getAttribute("data-panel-group-id");
2027
+ const groupId = handleElement.getAttribute(DATA_ATTRIBUTES.groupId);
2018
2028
  assert(groupId, `No group element found for id "${groupId}"`);
2019
2029
  const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
2020
2030
  const index = getResizeHandleElementIndex(groupId, handleId, panelGroupElement);
@@ -2040,24 +2050,33 @@ function PanelResizeHandle({
2040
2050
  hitAreaMargins,
2041
2051
  id: idFromProps,
2042
2052
  onBlur,
2053
+ onClick,
2043
2054
  onDragging,
2044
2055
  onFocus,
2056
+ onPointerDown,
2057
+ onPointerUp,
2045
2058
  style: styleFromProps = {},
2046
2059
  tabIndex = 0,
2047
2060
  tagName: Type = "div",
2048
2061
  ...rest
2049
2062
  }) {
2050
2063
  var _hitAreaMargins$coars, _hitAreaMargins$fine;
2051
- const elementRef = useRef(null);
2064
+ const elementRef = React.useRef(null);
2052
2065
 
2053
2066
  // Use a ref to guard against users passing inline props
2054
- const callbacksRef = useRef({
2055
- onDragging
2067
+ const callbacksRef = React.useRef({
2068
+ onClick,
2069
+ onDragging,
2070
+ onPointerDown,
2071
+ onPointerUp
2056
2072
  });
2057
- useEffect(() => {
2073
+ React.useEffect(() => {
2074
+ callbacksRef.current.onClick = onClick;
2058
2075
  callbacksRef.current.onDragging = onDragging;
2076
+ callbacksRef.current.onPointerDown = onPointerDown;
2077
+ callbacksRef.current.onPointerUp = onPointerUp;
2059
2078
  });
2060
- const panelGroupContext = useContext(PanelGroupContext);
2079
+ const panelGroupContext = React.useContext(PanelGroupContext);
2061
2080
  if (panelGroupContext === null) {
2062
2081
  throw Error(`PanelResizeHandle components must be rendered within a PanelGroup container`);
2063
2082
  }
@@ -2070,13 +2089,13 @@ function PanelResizeHandle({
2070
2089
  panelGroupElement
2071
2090
  } = panelGroupContext;
2072
2091
  const resizeHandleId = useUniqueId(idFromProps);
2073
- const [state, setState] = useState("inactive");
2074
- const [isFocused, setIsFocused] = useState(false);
2075
- const [resizeHandler, setResizeHandler] = useState(null);
2076
- const committedValuesRef = useRef({
2092
+ const [state, setState] = React.useState("inactive");
2093
+ const [isFocused, setIsFocused] = React.useState(false);
2094
+ const [resizeHandler, setResizeHandler] = React.useState(null);
2095
+ const committedValuesRef = React.useRef({
2077
2096
  state
2078
2097
  });
2079
- useEffect(() => {
2098
+ React.useEffect(() => {
2080
2099
  if (disabled) {
2081
2100
  setResizeHandler(null);
2082
2101
  } else {
@@ -2089,55 +2108,62 @@ function PanelResizeHandle({
2089
2108
  // so that inline object values won't trigger re-renders
2090
2109
  const coarseHitAreaMargins = (_hitAreaMargins$coars = hitAreaMargins === null || hitAreaMargins === void 0 ? void 0 : hitAreaMargins.coarse) !== null && _hitAreaMargins$coars !== void 0 ? _hitAreaMargins$coars : 15;
2091
2110
  const fineHitAreaMargins = (_hitAreaMargins$fine = hitAreaMargins === null || hitAreaMargins === void 0 ? void 0 : hitAreaMargins.fine) !== null && _hitAreaMargins$fine !== void 0 ? _hitAreaMargins$fine : 5;
2092
- useEffect(() => {
2111
+ React.useEffect(() => {
2093
2112
  if (disabled || resizeHandler == null) {
2094
2113
  return;
2095
2114
  }
2096
2115
  const element = elementRef.current;
2097
2116
  assert(element, "Element ref not attached");
2117
+ let didMove = false;
2098
2118
  const setResizeHandlerState = (action, isActive, event) => {
2099
- if (isActive) {
2100
- switch (action) {
2101
- case "down":
2102
- {
2103
- setState("drag");
2104
- assert(event, 'Expected event to be defined for "down" action');
2105
- startDragging(resizeHandleId, event);
2106
- const {
2107
- onDragging
2108
- } = callbacksRef.current;
2109
- if (onDragging) {
2110
- onDragging(true);
2111
- }
2112
- break;
2113
- }
2114
- case "move":
2115
- {
2116
- const {
2117
- state
2118
- } = committedValuesRef.current;
2119
- if (state !== "drag") {
2120
- setState("hover");
2121
- }
2122
- assert(event, 'Expected event to be defined for "move" action');
2123
- resizeHandler(event);
2124
- break;
2125
- }
2126
- case "up":
2127
- {
2119
+ if (!isActive) {
2120
+ setState("inactive");
2121
+ return;
2122
+ }
2123
+ switch (action) {
2124
+ case "down":
2125
+ {
2126
+ setState("drag");
2127
+ didMove = false;
2128
+ assert(event, 'Expected event to be defined for "down" action');
2129
+ startDragging(resizeHandleId, event);
2130
+ const {
2131
+ onDragging,
2132
+ onPointerDown
2133
+ } = callbacksRef.current;
2134
+ onDragging === null || onDragging === void 0 ? void 0 : onDragging(true);
2135
+ onPointerDown === null || onPointerDown === void 0 ? void 0 : onPointerDown();
2136
+ break;
2137
+ }
2138
+ case "move":
2139
+ {
2140
+ const {
2141
+ state
2142
+ } = committedValuesRef.current;
2143
+ didMove = true;
2144
+ if (state !== "drag") {
2128
2145
  setState("hover");
2129
- stopDragging();
2130
- const {
2131
- onDragging
2132
- } = callbacksRef.current;
2133
- if (onDragging) {
2134
- onDragging(false);
2135
- }
2136
- break;
2137
2146
  }
2138
- }
2139
- } else {
2140
- setState("inactive");
2147
+ assert(event, 'Expected event to be defined for "move" action');
2148
+ resizeHandler(event);
2149
+ break;
2150
+ }
2151
+ case "up":
2152
+ {
2153
+ setState("hover");
2154
+ stopDragging();
2155
+ const {
2156
+ onClick,
2157
+ onDragging,
2158
+ onPointerUp
2159
+ } = callbacksRef.current;
2160
+ onDragging === null || onDragging === void 0 ? void 0 : onDragging(false);
2161
+ onPointerUp === null || onPointerUp === void 0 ? void 0 : onPointerUp();
2162
+ if (!didMove) {
2163
+ onClick === null || onClick === void 0 ? void 0 : onClick();
2164
+ }
2165
+ break;
2166
+ }
2141
2167
  }
2142
2168
  };
2143
2169
  return registerResizeHandle(resizeHandleId, element, direction, {
@@ -2155,7 +2181,7 @@ function PanelResizeHandle({
2155
2181
  touchAction: "none",
2156
2182
  userSelect: "none"
2157
2183
  };
2158
- return createElement(Type, {
2184
+ return React.createElement(Type, {
2159
2185
  ...rest,
2160
2186
  children,
2161
2187
  className: classNameFromProps,
@@ -2176,13 +2202,13 @@ function PanelResizeHandle({
2176
2202
  },
2177
2203
  tabIndex,
2178
2204
  // CSS selectors
2179
- "data-panel-group-direction": direction,
2180
- "data-panel-group-id": groupId,
2181
- "data-resize-handle": "",
2182
- "data-resize-handle-active": state === "drag" ? "pointer" : isFocused ? "keyboard" : undefined,
2183
- "data-resize-handle-state": state,
2184
- "data-panel-resize-handle-enabled": !disabled,
2185
- "data-panel-resize-handle-id": resizeHandleId
2205
+ [DATA_ATTRIBUTES.groupDirection]: direction,
2206
+ [DATA_ATTRIBUTES.groupId]: groupId,
2207
+ [DATA_ATTRIBUTES.resizeHandle]: "",
2208
+ [DATA_ATTRIBUTES.resizeHandleActive]: state === "drag" ? "pointer" : isFocused ? "keyboard" : undefined,
2209
+ [DATA_ATTRIBUTES.resizeHandleEnabled]: !disabled,
2210
+ [DATA_ATTRIBUTES.resizeHandleId]: resizeHandleId,
2211
+ [DATA_ATTRIBUTES.resizeHandleState]: state
2186
2212
  });
2187
2213
  }
2188
2214
  PanelResizeHandle.displayName = "PanelResizeHandle";
@@ -2216,6 +2242,7 @@ function getIntersectingRectangle(rectOne, rectTwo, strict) {
2216
2242
  };
2217
2243
  }
2218
2244
 
2245
+ exports.DATA_ATTRIBUTES = DATA_ATTRIBUTES;
2219
2246
  exports.Panel = Panel;
2220
2247
  exports.PanelGroup = PanelGroup;
2221
2248
  exports.PanelResizeHandle = PanelResizeHandle;