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,7 +109,7 @@ function PanelWithForwardedRef({
114
109
  idIsFromProps: idFromProps !== undefined,
115
110
  order
116
111
  });
117
- const devWarningsRef = useRef({
112
+ const devWarningsRef = React.useRef({
118
113
  didLogMissingDefaultSizeWarning: false
119
114
  });
120
115
 
@@ -128,7 +123,7 @@ function PanelWithForwardedRef({
128
123
  }
129
124
  }
130
125
  }
131
- useImperativeHandle(forwardedRef, () => ({
126
+ React.useImperativeHandle(forwardedRef, () => ({
132
127
  collapse: () => {
133
128
  collapsePanel(panelDataRef.current);
134
129
  },
@@ -152,24 +147,24 @@ function PanelWithForwardedRef({
152
147
  }
153
148
  }), [collapsePanel, expandPanel, getPanelSize, isPanelCollapsed, panelId, resizePanel]);
154
149
  const style = getPanelStyle(panelDataRef.current, defaultSize);
155
- return createElement(Type, {
150
+ return React.createElement(Type, {
156
151
  ...rest,
157
152
  children,
158
153
  className: classNameFromProps,
159
- id: idFromProps,
154
+ id: panelId,
160
155
  style: {
161
156
  ...style,
162
157
  ...styleFromProps
163
158
  },
164
159
  // CSS selectors
165
- "data-panel": "",
166
- "data-panel-collapsible": collapsible || undefined,
167
- "data-panel-group-id": groupId,
168
- "data-panel-id": panelId,
169
- "data-panel-size": parseFloat("" + style.flexGrow).toFixed(1)
160
+ [DATA_ATTRIBUTES.groupId]: groupId,
161
+ [DATA_ATTRIBUTES.panel]: "",
162
+ [DATA_ATTRIBUTES.panelCollapsible]: collapsible || undefined,
163
+ [DATA_ATTRIBUTES.panelId]: panelId,
164
+ [DATA_ATTRIBUTES.panelSize]: parseFloat("" + style.flexGrow).toFixed(1)
170
165
  });
171
166
  }
172
- const Panel = forwardRef((props, ref) => createElement(PanelWithForwardedRef, {
167
+ const Panel = React.forwardRef((props, ref) => React.createElement(PanelWithForwardedRef, {
173
168
  ...props,
174
169
  forwardedRef: ref
175
170
  }));
@@ -186,6 +181,7 @@ function setNonce(value) {
186
181
 
187
182
  let currentCursorStyle = null;
188
183
  let enabled = true;
184
+ let prevRuleIndex = -1;
189
185
  let styleElement = null;
190
186
  function disableGlobalCursorStyles() {
191
187
  enabled = false;
@@ -235,9 +231,11 @@ function resetGlobalCursorStyle() {
235
231
  document.head.removeChild(styleElement);
236
232
  currentCursorStyle = null;
237
233
  styleElement = null;
234
+ prevRuleIndex = -1;
238
235
  }
239
236
  }
240
237
  function setGlobalCursorStyle(state, constraintFlags) {
238
+ var _styleElement$sheet$i, _styleElement$sheet2;
241
239
  if (!enabled) {
242
240
  return;
243
241
  }
@@ -254,7 +252,11 @@ function setGlobalCursorStyle(state, constraintFlags) {
254
252
  }
255
253
  document.head.appendChild(styleElement);
256
254
  }
257
- styleElement.innerHTML = `*{cursor: ${style}!important;}`;
255
+ if (prevRuleIndex >= 0) {
256
+ var _styleElement$sheet;
257
+ (_styleElement$sheet = styleElement.sheet) === null || _styleElement$sheet === void 0 ? void 0 : _styleElement$sheet.removeRule(prevRuleIndex);
258
+ }
259
+ 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;
258
260
  }
259
261
 
260
262
  function isKeyDown(event) {
@@ -485,7 +487,9 @@ function handlePointerDown(event) {
485
487
  if (intersectingHandles.length > 0) {
486
488
  updateResizeHandlerStates("down", event);
487
489
  event.preventDefault();
488
- event.stopPropagation();
490
+ if (!isWithinResizeHandle(target)) {
491
+ event.stopImmediatePropagation();
492
+ }
489
493
  }
490
494
  }
491
495
  function handlePointerMove(event) {
@@ -534,6 +538,9 @@ function handlePointerUp(event) {
534
538
  isPointerDown = false;
535
539
  if (intersectingHandles.length > 0) {
536
540
  event.preventDefault();
541
+ if (!isWithinResizeHandle(target)) {
542
+ event.stopImmediatePropagation();
543
+ }
537
544
  }
538
545
  updateResizeHandlerStates("up", event);
539
546
  recalculateIntersectingHandles({
@@ -544,6 +551,16 @@ function handlePointerUp(event) {
544
551
  updateCursor();
545
552
  updateListeners();
546
553
  }
554
+ function isWithinResizeHandle(element) {
555
+ let currentElement = element;
556
+ while (currentElement) {
557
+ if (currentElement.hasAttribute(DATA_ATTRIBUTES.resizeHandle)) {
558
+ return true;
559
+ }
560
+ currentElement = currentElement.parentElement;
561
+ }
562
+ return false;
563
+ }
547
564
  function recalculateIntersectingHandles({
548
565
  target,
549
566
  x,
@@ -635,47 +652,42 @@ function updateCursor() {
635
652
  resetGlobalCursorStyle();
636
653
  }
637
654
  }
655
+ let listenersAbortController = new AbortController();
638
656
  function updateListeners() {
639
- ownerDocumentCounts.forEach((_, ownerDocument) => {
640
- const {
641
- body
642
- } = ownerDocument;
643
- body.removeEventListener("contextmenu", handlePointerUp);
644
- body.removeEventListener("pointerdown", handlePointerDown);
645
- body.removeEventListener("pointerleave", handlePointerMove);
646
- body.removeEventListener("pointermove", handlePointerMove);
647
- });
648
- window.removeEventListener("pointerup", handlePointerUp);
649
- window.removeEventListener("pointercancel", handlePointerUp);
650
- if (registeredResizeHandlers.size > 0) {
651
- if (isPointerDown) {
652
- if (intersectingHandles.length > 0) {
653
- ownerDocumentCounts.forEach((count, ownerDocument) => {
654
- const {
655
- body
656
- } = ownerDocument;
657
- if (count > 0) {
658
- body.addEventListener("contextmenu", handlePointerUp);
659
- body.addEventListener("pointerleave", handlePointerMove);
660
- body.addEventListener("pointermove", handlePointerMove);
661
- }
662
- });
663
- }
664
- window.addEventListener("pointerup", handlePointerUp);
665
- window.addEventListener("pointercancel", handlePointerUp);
666
- } else {
657
+ listenersAbortController.abort();
658
+ listenersAbortController = new AbortController();
659
+ const options = {
660
+ capture: true,
661
+ signal: listenersAbortController.signal
662
+ };
663
+ if (!registeredResizeHandlers.size) {
664
+ return;
665
+ }
666
+ if (isPointerDown) {
667
+ if (intersectingHandles.length > 0) {
667
668
  ownerDocumentCounts.forEach((count, ownerDocument) => {
668
669
  const {
669
670
  body
670
671
  } = ownerDocument;
671
672
  if (count > 0) {
672
- body.addEventListener("pointerdown", handlePointerDown, {
673
- capture: true
674
- });
675
- body.addEventListener("pointermove", handlePointerMove);
673
+ body.addEventListener("contextmenu", handlePointerUp, options);
674
+ body.addEventListener("pointerleave", handlePointerMove, options);
675
+ body.addEventListener("pointermove", handlePointerMove, options);
676
676
  }
677
677
  });
678
678
  }
679
+ window.addEventListener("pointerup", handlePointerUp, options);
680
+ window.addEventListener("pointercancel", handlePointerUp, options);
681
+ } else {
682
+ ownerDocumentCounts.forEach((count, ownerDocument) => {
683
+ const {
684
+ body
685
+ } = ownerDocument;
686
+ if (count > 0) {
687
+ body.addEventListener("pointerdown", handlePointerDown, options);
688
+ body.addEventListener("pointermove", handlePointerMove, options);
689
+ }
690
+ });
679
691
  }
680
692
  }
681
693
  function updateResizeHandlerStates(action, event) {
@@ -689,8 +701,8 @@ function updateResizeHandlerStates(action, event) {
689
701
  }
690
702
 
691
703
  function useForceUpdate() {
692
- const [_, setCount] = useState(0);
693
- return useCallback(() => setCount(prevCount => prevCount + 1), []);
704
+ const [_, setCount] = React.useState(0);
705
+ return React.useCallback(() => setCount(prevCount => prevCount + 1), []);
694
706
  }
695
707
 
696
708
  function assert(expectedCondition, message) {
@@ -700,8 +712,6 @@ function assert(expectedCondition, message) {
700
712
  }
701
713
  }
702
714
 
703
- const PRECISION = 10;
704
-
705
715
  function fuzzyCompareNumbers(actual, expected, fractionDigits = PRECISION) {
706
716
  if (actual.toFixed(fractionDigits) === expected.toFixed(fractionDigits)) {
707
717
  return 0;
@@ -1006,12 +1016,12 @@ function adjustLayoutByDelta({
1006
1016
  }
1007
1017
 
1008
1018
  function getResizeHandleElementsForGroup(groupId, scope = document) {
1009
- return Array.from(scope.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${groupId}"]`));
1019
+ return Array.from(scope.querySelectorAll(`[${DATA_ATTRIBUTES.resizeHandleId}][data-panel-group-id="${groupId}"]`));
1010
1020
  }
1011
1021
 
1012
1022
  function getResizeHandleElementIndex(groupId, id, scope = document) {
1013
1023
  const handles = getResizeHandleElementsForGroup(groupId, scope);
1014
- const index = handles.findIndex(handle => handle.getAttribute("data-panel-resize-handle-id") === id);
1024
+ const index = handles.findIndex(handle => handle.getAttribute(DATA_ATTRIBUTES.resizeHandleId) === id);
1015
1025
  return index !== null && index !== void 0 ? index : null;
1016
1026
  }
1017
1027
 
@@ -1036,7 +1046,7 @@ function getPanelGroupElement(id, rootElement = document) {
1036
1046
  }
1037
1047
 
1038
1048
  function getResizeHandleElement(id, scope = document) {
1039
- const element = scope.querySelector(`[data-panel-resize-handle-id="${id}"]`);
1049
+ const element = scope.querySelector(`[${DATA_ATTRIBUTES.resizeHandleId}="${id}"]`);
1040
1050
  if (element) {
1041
1051
  return element;
1042
1052
  }
@@ -1064,10 +1074,10 @@ function useWindowSplitterPanelGroupBehavior({
1064
1074
  panelGroupElement,
1065
1075
  setLayout
1066
1076
  }) {
1067
- useRef({
1077
+ React.useRef({
1068
1078
  didWarnAboutMissingResizeHandle: false
1069
1079
  });
1070
- useEffect(() => {
1080
+ React.useEffect(() => {
1071
1081
  if (!panelGroupElement) {
1072
1082
  return;
1073
1083
  }
@@ -1081,7 +1091,7 @@ function useWindowSplitterPanelGroupBehavior({
1081
1091
  const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
1082
1092
  assert(handles, `No resize handles found for group id "${groupId}"`);
1083
1093
  const cleanupFunctions = handles.map(handle => {
1084
- const handleId = handle.getAttribute("data-panel-resize-handle-id");
1094
+ const handleId = handle.getAttribute(DATA_ATTRIBUTES.resizeHandleId);
1085
1095
  assert(handleId, `Resize handle element has no handle id attribute`);
1086
1096
  const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelDataArray, panelGroupElement);
1087
1097
  if (idBefore == null || idAfter == null) {
@@ -1159,7 +1169,7 @@ function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDr
1159
1169
  const isHorizontal = direction === "horizontal";
1160
1170
  const handleElement = getResizeHandleElement(dragHandleId, panelGroupElement);
1161
1171
  assert(handleElement, `No resize handle element found for id "${dragHandleId}"`);
1162
- const groupId = handleElement.getAttribute("data-panel-group-id");
1172
+ const groupId = handleElement.getAttribute(DATA_ATTRIBUTES.groupId);
1163
1173
  assert(groupId, `Resize handle element has no group id attribute`);
1164
1174
  let {
1165
1175
  initialCursorPosition
@@ -1527,14 +1537,14 @@ function PanelGroupWithForwardedRef({
1527
1537
  ...rest
1528
1538
  }) {
1529
1539
  const groupId = useUniqueId(idFromProps);
1530
- const panelGroupElementRef = useRef(null);
1531
- const [dragState, setDragState] = useState(null);
1532
- const [layout, setLayout] = useState([]);
1540
+ const panelGroupElementRef = React.useRef(null);
1541
+ const [dragState, setDragState] = React.useState(null);
1542
+ const [layout, setLayout] = React.useState([]);
1533
1543
  const forceUpdate = useForceUpdate();
1534
- const panelIdToLastNotifiedSizeMapRef = useRef({});
1535
- const panelSizeBeforeCollapseRef = useRef(new Map());
1536
- const prevDeltaRef = useRef(0);
1537
- const committedValuesRef = useRef({
1544
+ const panelIdToLastNotifiedSizeMapRef = React.useRef({});
1545
+ const panelSizeBeforeCollapseRef = React.useRef(new Map());
1546
+ const prevDeltaRef = React.useRef(0);
1547
+ const committedValuesRef = React.useRef({
1538
1548
  autoSaveId,
1539
1549
  direction,
1540
1550
  dragState,
@@ -1543,17 +1553,17 @@ function PanelGroupWithForwardedRef({
1543
1553
  onLayout,
1544
1554
  storage
1545
1555
  });
1546
- const eagerValuesRef = useRef({
1556
+ const eagerValuesRef = React.useRef({
1547
1557
  layout,
1548
1558
  panelDataArray: [],
1549
1559
  panelDataArrayChanged: false
1550
1560
  });
1551
- const devWarningsRef = useRef({
1561
+ const devWarningsRef = React.useRef({
1552
1562
  didLogIdAndOrderWarning: false,
1553
1563
  didLogPanelConstraintsWarning: false,
1554
1564
  prevPanelIds: []
1555
1565
  });
1556
- useImperativeHandle(forwardedRef, () => ({
1566
+ React.useImperativeHandle(forwardedRef, () => ({
1557
1567
  getId: () => committedValuesRef.current.id,
1558
1568
  getLayout: () => {
1559
1569
  const {
@@ -1592,7 +1602,7 @@ function PanelGroupWithForwardedRef({
1592
1602
  setLayout,
1593
1603
  panelGroupElement: panelGroupElementRef.current
1594
1604
  });
1595
- useEffect(() => {
1605
+ React.useEffect(() => {
1596
1606
  const {
1597
1607
  panelDataArray
1598
1608
  } = eagerValuesRef.current;
@@ -1619,7 +1629,7 @@ function PanelGroupWithForwardedRef({
1619
1629
  }, [autoSaveId, layout, storage]);
1620
1630
 
1621
1631
  // DEV warnings
1622
- useEffect(() => {
1632
+ React.useEffect(() => {
1623
1633
  {
1624
1634
  const {
1625
1635
  panelDataArray
@@ -1665,7 +1675,7 @@ function PanelGroupWithForwardedRef({
1665
1675
  });
1666
1676
 
1667
1677
  // External APIs are safe to memoize via committed values ref
1668
- const collapsePanel = useCallback(panelData => {
1678
+ const collapsePanel = React.useCallback(panelData => {
1669
1679
  const {
1670
1680
  onLayout
1671
1681
  } = committedValuesRef.current;
@@ -1708,7 +1718,7 @@ function PanelGroupWithForwardedRef({
1708
1718
  }, []);
1709
1719
 
1710
1720
  // External APIs are safe to memoize via committed values ref
1711
- const expandPanel = useCallback((panelData, minSizeOverride) => {
1721
+ const expandPanel = React.useCallback((panelData, minSizeOverride) => {
1712
1722
  const {
1713
1723
  onLayout
1714
1724
  } = committedValuesRef.current;
@@ -1752,7 +1762,7 @@ function PanelGroupWithForwardedRef({
1752
1762
  }, []);
1753
1763
 
1754
1764
  // External APIs are safe to memoize via committed values ref
1755
- const getPanelSize = useCallback(panelData => {
1765
+ const getPanelSize = React.useCallback(panelData => {
1756
1766
  const {
1757
1767
  layout,
1758
1768
  panelDataArray
@@ -1765,7 +1775,7 @@ function PanelGroupWithForwardedRef({
1765
1775
  }, []);
1766
1776
 
1767
1777
  // This API should never read from committedValuesRef
1768
- const getPanelStyle = useCallback((panelData, defaultSize) => {
1778
+ const getPanelStyle = React.useCallback((panelData, defaultSize) => {
1769
1779
  const {
1770
1780
  panelDataArray
1771
1781
  } = eagerValuesRef.current;
@@ -1780,7 +1790,7 @@ function PanelGroupWithForwardedRef({
1780
1790
  }, [dragState, layout]);
1781
1791
 
1782
1792
  // External APIs are safe to memoize via committed values ref
1783
- const isPanelCollapsed = useCallback(panelData => {
1793
+ const isPanelCollapsed = React.useCallback(panelData => {
1784
1794
  const {
1785
1795
  layout,
1786
1796
  panelDataArray
@@ -1795,7 +1805,7 @@ function PanelGroupWithForwardedRef({
1795
1805
  }, []);
1796
1806
 
1797
1807
  // External APIs are safe to memoize via committed values ref
1798
- const isPanelExpanded = useCallback(panelData => {
1808
+ const isPanelExpanded = React.useCallback(panelData => {
1799
1809
  const {
1800
1810
  layout,
1801
1811
  panelDataArray
@@ -1808,7 +1818,7 @@ function PanelGroupWithForwardedRef({
1808
1818
  assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
1809
1819
  return !collapsible || fuzzyCompareNumbers(panelSize, collapsedSize) > 0;
1810
1820
  }, []);
1811
- const registerPanel = useCallback(panelData => {
1821
+ const registerPanel = React.useCallback(panelData => {
1812
1822
  const {
1813
1823
  panelDataArray
1814
1824
  } = eagerValuesRef.current;
@@ -1829,7 +1839,7 @@ function PanelGroupWithForwardedRef({
1829
1839
  eagerValuesRef.current.panelDataArrayChanged = true;
1830
1840
  forceUpdate();
1831
1841
  }, [forceUpdate]);
1832
- const registerResizeHandle = useCallback(dragHandleId => {
1842
+ const registerResizeHandle = React.useCallback(dragHandleId => {
1833
1843
  let isRTL = false;
1834
1844
  const panelGroupElement = panelGroupElementRef.current;
1835
1845
  if (panelGroupElement) {
@@ -1908,7 +1918,7 @@ function PanelGroupWithForwardedRef({
1908
1918
  }, []);
1909
1919
 
1910
1920
  // External APIs are safe to memoize via committed values ref
1911
- const resizePanel = useCallback((panelData, unsafePanelSize) => {
1921
+ const resizePanel = React.useCallback((panelData, unsafePanelSize) => {
1912
1922
  const {
1913
1923
  onLayout
1914
1924
  } = committedValuesRef.current;
@@ -1941,7 +1951,7 @@ function PanelGroupWithForwardedRef({
1941
1951
  callPanelCallbacks(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
1942
1952
  }
1943
1953
  }, []);
1944
- const reevaluatePanelConstraints = useCallback((panelData, prevConstraints) => {
1954
+ const reevaluatePanelConstraints = React.useCallback((panelData, prevConstraints) => {
1945
1955
  const {
1946
1956
  layout,
1947
1957
  panelDataArray
@@ -1975,7 +1985,7 @@ function PanelGroupWithForwardedRef({
1975
1985
  }, [resizePanel]);
1976
1986
 
1977
1987
  // TODO Multiple drag handles can be active at the same time so this API is a bit awkward now
1978
- const startDragging = useCallback((dragHandleId, event) => {
1988
+ const startDragging = React.useCallback((dragHandleId, event) => {
1979
1989
  const {
1980
1990
  direction
1981
1991
  } = committedValuesRef.current;
@@ -1995,10 +2005,10 @@ function PanelGroupWithForwardedRef({
1995
2005
  initialLayout: layout
1996
2006
  });
1997
2007
  }, []);
1998
- const stopDragging = useCallback(() => {
2008
+ const stopDragging = React.useCallback(() => {
1999
2009
  setDragState(null);
2000
2010
  }, []);
2001
- const unregisterPanel = useCallback(panelData => {
2011
+ const unregisterPanel = React.useCallback(panelData => {
2002
2012
  const {
2003
2013
  panelDataArray
2004
2014
  } = eagerValuesRef.current;
@@ -2015,7 +2025,7 @@ function PanelGroupWithForwardedRef({
2015
2025
  forceUpdate();
2016
2026
  }
2017
2027
  }, [forceUpdate]);
2018
- const context = useMemo(() => ({
2028
+ const context = React.useMemo(() => ({
2019
2029
  collapsePanel,
2020
2030
  direction,
2021
2031
  dragState,
@@ -2041,9 +2051,9 @@ function PanelGroupWithForwardedRef({
2041
2051
  overflow: "hidden",
2042
2052
  width: "100%"
2043
2053
  };
2044
- return createElement(PanelGroupContext.Provider, {
2054
+ return React.createElement(PanelGroupContext.Provider, {
2045
2055
  value: context
2046
- }, createElement(Type, {
2056
+ }, React.createElement(Type, {
2047
2057
  ...rest,
2048
2058
  children,
2049
2059
  className: classNameFromProps,
@@ -2054,12 +2064,12 @@ function PanelGroupWithForwardedRef({
2054
2064
  ...styleFromProps
2055
2065
  },
2056
2066
  // CSS selectors
2057
- "data-panel-group": "",
2058
- "data-panel-group-direction": direction,
2059
- "data-panel-group-id": groupId
2067
+ [DATA_ATTRIBUTES.group]: "",
2068
+ [DATA_ATTRIBUTES.groupDirection]: direction,
2069
+ [DATA_ATTRIBUTES.groupId]: groupId
2060
2070
  }));
2061
2071
  }
2062
- const PanelGroup = forwardRef((props, ref) => createElement(PanelGroupWithForwardedRef, {
2072
+ const PanelGroup = React.forwardRef((props, ref) => React.createElement(PanelGroupWithForwardedRef, {
2063
2073
  ...props,
2064
2074
  forwardedRef: ref
2065
2075
  }));
@@ -2088,7 +2098,7 @@ function useWindowSplitterResizeHandlerBehavior({
2088
2098
  resizeHandler,
2089
2099
  panelGroupElement
2090
2100
  }) {
2091
- useEffect(() => {
2101
+ React.useEffect(() => {
2092
2102
  if (disabled || resizeHandler == null || panelGroupElement == null) {
2093
2103
  return;
2094
2104
  }
@@ -2115,7 +2125,7 @@ function useWindowSplitterResizeHandlerBehavior({
2115
2125
  case "F6":
2116
2126
  {
2117
2127
  event.preventDefault();
2118
- const groupId = handleElement.getAttribute("data-panel-group-id");
2128
+ const groupId = handleElement.getAttribute(DATA_ATTRIBUTES.groupId);
2119
2129
  assert(groupId, `No group element found for id "${groupId}"`);
2120
2130
  const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
2121
2131
  const index = getResizeHandleElementIndex(groupId, handleId, panelGroupElement);
@@ -2141,24 +2151,33 @@ function PanelResizeHandle({
2141
2151
  hitAreaMargins,
2142
2152
  id: idFromProps,
2143
2153
  onBlur,
2154
+ onClick,
2144
2155
  onDragging,
2145
2156
  onFocus,
2157
+ onPointerDown,
2158
+ onPointerUp,
2146
2159
  style: styleFromProps = {},
2147
2160
  tabIndex = 0,
2148
2161
  tagName: Type = "div",
2149
2162
  ...rest
2150
2163
  }) {
2151
2164
  var _hitAreaMargins$coars, _hitAreaMargins$fine;
2152
- const elementRef = useRef(null);
2165
+ const elementRef = React.useRef(null);
2153
2166
 
2154
2167
  // Use a ref to guard against users passing inline props
2155
- const callbacksRef = useRef({
2156
- onDragging
2168
+ const callbacksRef = React.useRef({
2169
+ onClick,
2170
+ onDragging,
2171
+ onPointerDown,
2172
+ onPointerUp
2157
2173
  });
2158
- useEffect(() => {
2174
+ React.useEffect(() => {
2175
+ callbacksRef.current.onClick = onClick;
2159
2176
  callbacksRef.current.onDragging = onDragging;
2177
+ callbacksRef.current.onPointerDown = onPointerDown;
2178
+ callbacksRef.current.onPointerUp = onPointerUp;
2160
2179
  });
2161
- const panelGroupContext = useContext(PanelGroupContext);
2180
+ const panelGroupContext = React.useContext(PanelGroupContext);
2162
2181
  if (panelGroupContext === null) {
2163
2182
  throw Error(`PanelResizeHandle components must be rendered within a PanelGroup container`);
2164
2183
  }
@@ -2171,13 +2190,13 @@ function PanelResizeHandle({
2171
2190
  panelGroupElement
2172
2191
  } = panelGroupContext;
2173
2192
  const resizeHandleId = useUniqueId(idFromProps);
2174
- const [state, setState] = useState("inactive");
2175
- const [isFocused, setIsFocused] = useState(false);
2176
- const [resizeHandler, setResizeHandler] = useState(null);
2177
- const committedValuesRef = useRef({
2193
+ const [state, setState] = React.useState("inactive");
2194
+ const [isFocused, setIsFocused] = React.useState(false);
2195
+ const [resizeHandler, setResizeHandler] = React.useState(null);
2196
+ const committedValuesRef = React.useRef({
2178
2197
  state
2179
2198
  });
2180
- useEffect(() => {
2199
+ React.useEffect(() => {
2181
2200
  if (disabled) {
2182
2201
  setResizeHandler(null);
2183
2202
  } else {
@@ -2190,55 +2209,62 @@ function PanelResizeHandle({
2190
2209
  // so that inline object values won't trigger re-renders
2191
2210
  const coarseHitAreaMargins = (_hitAreaMargins$coars = hitAreaMargins === null || hitAreaMargins === void 0 ? void 0 : hitAreaMargins.coarse) !== null && _hitAreaMargins$coars !== void 0 ? _hitAreaMargins$coars : 15;
2192
2211
  const fineHitAreaMargins = (_hitAreaMargins$fine = hitAreaMargins === null || hitAreaMargins === void 0 ? void 0 : hitAreaMargins.fine) !== null && _hitAreaMargins$fine !== void 0 ? _hitAreaMargins$fine : 5;
2193
- useEffect(() => {
2212
+ React.useEffect(() => {
2194
2213
  if (disabled || resizeHandler == null) {
2195
2214
  return;
2196
2215
  }
2197
2216
  const element = elementRef.current;
2198
2217
  assert(element, "Element ref not attached");
2218
+ let didMove = false;
2199
2219
  const setResizeHandlerState = (action, isActive, event) => {
2200
- if (isActive) {
2201
- switch (action) {
2202
- case "down":
2203
- {
2204
- setState("drag");
2205
- assert(event, 'Expected event to be defined for "down" action');
2206
- startDragging(resizeHandleId, event);
2207
- const {
2208
- onDragging
2209
- } = callbacksRef.current;
2210
- if (onDragging) {
2211
- onDragging(true);
2212
- }
2213
- break;
2214
- }
2215
- case "move":
2216
- {
2217
- const {
2218
- state
2219
- } = committedValuesRef.current;
2220
- if (state !== "drag") {
2221
- setState("hover");
2222
- }
2223
- assert(event, 'Expected event to be defined for "move" action');
2224
- resizeHandler(event);
2225
- break;
2226
- }
2227
- case "up":
2228
- {
2220
+ if (!isActive) {
2221
+ setState("inactive");
2222
+ return;
2223
+ }
2224
+ switch (action) {
2225
+ case "down":
2226
+ {
2227
+ setState("drag");
2228
+ didMove = false;
2229
+ assert(event, 'Expected event to be defined for "down" action');
2230
+ startDragging(resizeHandleId, event);
2231
+ const {
2232
+ onDragging,
2233
+ onPointerDown
2234
+ } = callbacksRef.current;
2235
+ onDragging === null || onDragging === void 0 ? void 0 : onDragging(true);
2236
+ onPointerDown === null || onPointerDown === void 0 ? void 0 : onPointerDown();
2237
+ break;
2238
+ }
2239
+ case "move":
2240
+ {
2241
+ const {
2242
+ state
2243
+ } = committedValuesRef.current;
2244
+ didMove = true;
2245
+ if (state !== "drag") {
2229
2246
  setState("hover");
2230
- stopDragging();
2231
- const {
2232
- onDragging
2233
- } = callbacksRef.current;
2234
- if (onDragging) {
2235
- onDragging(false);
2236
- }
2237
- break;
2238
2247
  }
2239
- }
2240
- } else {
2241
- setState("inactive");
2248
+ assert(event, 'Expected event to be defined for "move" action');
2249
+ resizeHandler(event);
2250
+ break;
2251
+ }
2252
+ case "up":
2253
+ {
2254
+ setState("hover");
2255
+ stopDragging();
2256
+ const {
2257
+ onClick,
2258
+ onDragging,
2259
+ onPointerUp
2260
+ } = callbacksRef.current;
2261
+ onDragging === null || onDragging === void 0 ? void 0 : onDragging(false);
2262
+ onPointerUp === null || onPointerUp === void 0 ? void 0 : onPointerUp();
2263
+ if (!didMove) {
2264
+ onClick === null || onClick === void 0 ? void 0 : onClick();
2265
+ }
2266
+ break;
2267
+ }
2242
2268
  }
2243
2269
  };
2244
2270
  return registerResizeHandle(resizeHandleId, element, direction, {
@@ -2256,7 +2282,7 @@ function PanelResizeHandle({
2256
2282
  touchAction: "none",
2257
2283
  userSelect: "none"
2258
2284
  };
2259
- return createElement(Type, {
2285
+ return React.createElement(Type, {
2260
2286
  ...rest,
2261
2287
  children,
2262
2288
  className: classNameFromProps,
@@ -2277,13 +2303,13 @@ function PanelResizeHandle({
2277
2303
  },
2278
2304
  tabIndex,
2279
2305
  // CSS selectors
2280
- "data-panel-group-direction": direction,
2281
- "data-panel-group-id": groupId,
2282
- "data-resize-handle": "",
2283
- "data-resize-handle-active": state === "drag" ? "pointer" : isFocused ? "keyboard" : undefined,
2284
- "data-resize-handle-state": state,
2285
- "data-panel-resize-handle-enabled": !disabled,
2286
- "data-panel-resize-handle-id": resizeHandleId
2306
+ [DATA_ATTRIBUTES.groupDirection]: direction,
2307
+ [DATA_ATTRIBUTES.groupId]: groupId,
2308
+ [DATA_ATTRIBUTES.resizeHandle]: "",
2309
+ [DATA_ATTRIBUTES.resizeHandleActive]: state === "drag" ? "pointer" : isFocused ? "keyboard" : undefined,
2310
+ [DATA_ATTRIBUTES.resizeHandleEnabled]: !disabled,
2311
+ [DATA_ATTRIBUTES.resizeHandleId]: resizeHandleId,
2312
+ [DATA_ATTRIBUTES.resizeHandleState]: state
2287
2313
  });
2288
2314
  }
2289
2315
  PanelResizeHandle.displayName = "PanelResizeHandle";
@@ -2317,6 +2343,7 @@ function getIntersectingRectangle(rectOne, rectTwo, strict) {
2317
2343
  };
2318
2344
  }
2319
2345
 
2346
+ exports.DATA_ATTRIBUTES = DATA_ATTRIBUTES;
2320
2347
  exports.Panel = Panel;
2321
2348
  exports.PanelGroup = PanelGroup;
2322
2349
  exports.PanelResizeHandle = PanelResizeHandle;