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
@@ -26,41 +26,35 @@ var React__namespace = /*#__PURE__*/_interopNamespace(React);
26
26
 
27
27
  const isBrowser = typeof window !== "undefined";
28
28
 
29
- // This module exists to work around Webpack issue https://github.com/webpack/webpack/issues/14814
30
-
31
- // eslint-disable-next-line no-restricted-imports
32
-
33
- const {
34
- createElement,
35
- createContext,
36
- createRef,
37
- forwardRef,
38
- useCallback,
39
- useContext,
40
- useEffect,
41
- useImperativeHandle,
42
- useLayoutEffect,
43
- useMemo,
44
- useRef,
45
- useState
46
- } = React__namespace;
47
-
48
- // `Math.random()` and `.slice(0, 5)` prevents bundlers from trying to `import { useId } from 'react'`
49
- const useId = React__namespace[`useId${Math.random()}`.slice(0, 5)];
50
- const useLayoutEffect_do_not_use_directly = useLayoutEffect;
51
-
52
29
  // The "contextmenu" event is not supported as a PointerEvent in all browsers yet, so MouseEvent still need to be handled
53
30
 
54
- const PanelGroupContext = createContext(null);
31
+ const PanelGroupContext = React.createContext(null);
55
32
  PanelGroupContext.displayName = "PanelGroupContext";
56
33
 
57
- const useIsomorphicLayoutEffect = isBrowser ? useLayoutEffect_do_not_use_directly : () => {};
34
+ const DATA_ATTRIBUTES = {
35
+ group: "data-panel-group",
36
+ groupDirection: "data-panel-group-direction",
37
+ groupId: "data-panel-group-id",
38
+ panel: "data-panel",
39
+ panelCollapsible: "data-panel-collapsible",
40
+ panelId: "data-panel-id",
41
+ panelSize: "data-panel-size",
42
+ resizeHandle: "data-resize-handle",
43
+ resizeHandleActive: "data-resize-handle-active",
44
+ resizeHandleEnabled: "data-panel-resize-handle-enabled",
45
+ resizeHandleId: "data-panel-resize-handle-id",
46
+ resizeHandleState: "data-resize-handle-state"
47
+ };
48
+ const PRECISION = 10;
49
+
50
+ const useIsomorphicLayoutEffect = isBrowser ? React.useLayoutEffect : () => {};
58
51
 
52
+ const useId = React__namespace["useId".toString()];
59
53
  const wrappedUseId = typeof useId === "function" ? useId : () => null;
60
54
  let counter = 0;
61
55
  function useUniqueId(idFromParams = null) {
62
56
  const idFromUseId = wrappedUseId();
63
- const idRef = useRef(idFromParams || idFromUseId || null);
57
+ const idRef = React.useRef(idFromParams || idFromUseId || null);
64
58
  if (idRef.current === null) {
65
59
  idRef.current = "" + counter++;
66
60
  }
@@ -85,7 +79,7 @@ function PanelWithForwardedRef({
85
79
  tagName: Type = "div",
86
80
  ...rest
87
81
  }) {
88
- const context = useContext(PanelGroupContext);
82
+ const context = React.useContext(PanelGroupContext);
89
83
  if (context === null) {
90
84
  throw Error(`Panel components must be rendered within a PanelGroup container`);
91
85
  }
@@ -102,7 +96,7 @@ function PanelWithForwardedRef({
102
96
  unregisterPanel
103
97
  } = context;
104
98
  const panelId = useUniqueId(idFromProps);
105
- const panelDataRef = useRef({
99
+ const panelDataRef = React.useRef({
106
100
  callbacks: {
107
101
  onCollapse,
108
102
  onExpand,
@@ -119,7 +113,7 @@ function PanelWithForwardedRef({
119
113
  idIsFromProps: idFromProps !== undefined,
120
114
  order
121
115
  });
122
- const devWarningsRef = useRef({
116
+ const devWarningsRef = React.useRef({
123
117
  didLogMissingDefaultSizeWarning: false
124
118
  });
125
119
 
@@ -166,7 +160,7 @@ function PanelWithForwardedRef({
166
160
  unregisterPanel(panelData);
167
161
  };
168
162
  }, [order, panelId, registerPanel, unregisterPanel]);
169
- useImperativeHandle(forwardedRef, () => ({
163
+ React.useImperativeHandle(forwardedRef, () => ({
170
164
  collapse: () => {
171
165
  collapsePanel(panelDataRef.current);
172
166
  },
@@ -190,24 +184,24 @@ function PanelWithForwardedRef({
190
184
  }
191
185
  }), [collapsePanel, expandPanel, getPanelSize, isPanelCollapsed, panelId, resizePanel]);
192
186
  const style = getPanelStyle(panelDataRef.current, defaultSize);
193
- return createElement(Type, {
187
+ return React.createElement(Type, {
194
188
  ...rest,
195
189
  children,
196
190
  className: classNameFromProps,
197
- id: idFromProps,
191
+ id: panelId,
198
192
  style: {
199
193
  ...style,
200
194
  ...styleFromProps
201
195
  },
202
196
  // CSS selectors
203
- "data-panel": "",
204
- "data-panel-collapsible": collapsible || undefined,
205
- "data-panel-group-id": groupId,
206
- "data-panel-id": panelId,
207
- "data-panel-size": parseFloat("" + style.flexGrow).toFixed(1)
197
+ [DATA_ATTRIBUTES.groupId]: groupId,
198
+ [DATA_ATTRIBUTES.panel]: "",
199
+ [DATA_ATTRIBUTES.panelCollapsible]: collapsible || undefined,
200
+ [DATA_ATTRIBUTES.panelId]: panelId,
201
+ [DATA_ATTRIBUTES.panelSize]: parseFloat("" + style.flexGrow).toFixed(1)
208
202
  });
209
203
  }
210
- const Panel = forwardRef((props, ref) => createElement(PanelWithForwardedRef, {
204
+ const Panel = React.forwardRef((props, ref) => React.createElement(PanelWithForwardedRef, {
211
205
  ...props,
212
206
  forwardedRef: ref
213
207
  }));
@@ -224,6 +218,7 @@ function setNonce(value) {
224
218
 
225
219
  let currentCursorStyle = null;
226
220
  let enabled = true;
221
+ let prevRuleIndex = -1;
227
222
  let styleElement = null;
228
223
  function disableGlobalCursorStyles() {
229
224
  enabled = false;
@@ -273,9 +268,11 @@ function resetGlobalCursorStyle() {
273
268
  document.head.removeChild(styleElement);
274
269
  currentCursorStyle = null;
275
270
  styleElement = null;
271
+ prevRuleIndex = -1;
276
272
  }
277
273
  }
278
274
  function setGlobalCursorStyle(state, constraintFlags) {
275
+ var _styleElement$sheet$i, _styleElement$sheet2;
279
276
  if (!enabled) {
280
277
  return;
281
278
  }
@@ -292,7 +289,11 @@ function setGlobalCursorStyle(state, constraintFlags) {
292
289
  }
293
290
  document.head.appendChild(styleElement);
294
291
  }
295
- styleElement.innerHTML = `*{cursor: ${style}!important;}`;
292
+ if (prevRuleIndex >= 0) {
293
+ var _styleElement$sheet;
294
+ (_styleElement$sheet = styleElement.sheet) === null || _styleElement$sheet === void 0 ? void 0 : _styleElement$sheet.removeRule(prevRuleIndex);
295
+ }
296
+ 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;
296
297
  }
297
298
 
298
299
  function isKeyDown(event) {
@@ -523,7 +524,9 @@ function handlePointerDown(event) {
523
524
  if (intersectingHandles.length > 0) {
524
525
  updateResizeHandlerStates("down", event);
525
526
  event.preventDefault();
526
- event.stopPropagation();
527
+ if (!isWithinResizeHandle(target)) {
528
+ event.stopImmediatePropagation();
529
+ }
527
530
  }
528
531
  }
529
532
  function handlePointerMove(event) {
@@ -572,6 +575,9 @@ function handlePointerUp(event) {
572
575
  isPointerDown = false;
573
576
  if (intersectingHandles.length > 0) {
574
577
  event.preventDefault();
578
+ if (!isWithinResizeHandle(target)) {
579
+ event.stopImmediatePropagation();
580
+ }
575
581
  }
576
582
  updateResizeHandlerStates("up", event);
577
583
  recalculateIntersectingHandles({
@@ -582,6 +588,16 @@ function handlePointerUp(event) {
582
588
  updateCursor();
583
589
  updateListeners();
584
590
  }
591
+ function isWithinResizeHandle(element) {
592
+ let currentElement = element;
593
+ while (currentElement) {
594
+ if (currentElement.hasAttribute(DATA_ATTRIBUTES.resizeHandle)) {
595
+ return true;
596
+ }
597
+ currentElement = currentElement.parentElement;
598
+ }
599
+ return false;
600
+ }
585
601
  function recalculateIntersectingHandles({
586
602
  target,
587
603
  x,
@@ -673,47 +689,42 @@ function updateCursor() {
673
689
  resetGlobalCursorStyle();
674
690
  }
675
691
  }
692
+ let listenersAbortController = new AbortController();
676
693
  function updateListeners() {
677
- ownerDocumentCounts.forEach((_, ownerDocument) => {
678
- const {
679
- body
680
- } = ownerDocument;
681
- body.removeEventListener("contextmenu", handlePointerUp);
682
- body.removeEventListener("pointerdown", handlePointerDown);
683
- body.removeEventListener("pointerleave", handlePointerMove);
684
- body.removeEventListener("pointermove", handlePointerMove);
685
- });
686
- window.removeEventListener("pointerup", handlePointerUp);
687
- window.removeEventListener("pointercancel", handlePointerUp);
688
- if (registeredResizeHandlers.size > 0) {
689
- if (isPointerDown) {
690
- if (intersectingHandles.length > 0) {
691
- ownerDocumentCounts.forEach((count, ownerDocument) => {
692
- const {
693
- body
694
- } = ownerDocument;
695
- if (count > 0) {
696
- body.addEventListener("contextmenu", handlePointerUp);
697
- body.addEventListener("pointerleave", handlePointerMove);
698
- body.addEventListener("pointermove", handlePointerMove);
699
- }
700
- });
701
- }
702
- window.addEventListener("pointerup", handlePointerUp);
703
- window.addEventListener("pointercancel", handlePointerUp);
704
- } else {
694
+ listenersAbortController.abort();
695
+ listenersAbortController = new AbortController();
696
+ const options = {
697
+ capture: true,
698
+ signal: listenersAbortController.signal
699
+ };
700
+ if (!registeredResizeHandlers.size) {
701
+ return;
702
+ }
703
+ if (isPointerDown) {
704
+ if (intersectingHandles.length > 0) {
705
705
  ownerDocumentCounts.forEach((count, ownerDocument) => {
706
706
  const {
707
707
  body
708
708
  } = ownerDocument;
709
709
  if (count > 0) {
710
- body.addEventListener("pointerdown", handlePointerDown, {
711
- capture: true
712
- });
713
- body.addEventListener("pointermove", handlePointerMove);
710
+ body.addEventListener("contextmenu", handlePointerUp, options);
711
+ body.addEventListener("pointerleave", handlePointerMove, options);
712
+ body.addEventListener("pointermove", handlePointerMove, options);
714
713
  }
715
714
  });
716
715
  }
716
+ window.addEventListener("pointerup", handlePointerUp, options);
717
+ window.addEventListener("pointercancel", handlePointerUp, options);
718
+ } else {
719
+ ownerDocumentCounts.forEach((count, ownerDocument) => {
720
+ const {
721
+ body
722
+ } = ownerDocument;
723
+ if (count > 0) {
724
+ body.addEventListener("pointerdown", handlePointerDown, options);
725
+ body.addEventListener("pointermove", handlePointerMove, options);
726
+ }
727
+ });
717
728
  }
718
729
  }
719
730
  function updateResizeHandlerStates(action, event) {
@@ -727,8 +738,8 @@ function updateResizeHandlerStates(action, event) {
727
738
  }
728
739
 
729
740
  function useForceUpdate() {
730
- const [_, setCount] = useState(0);
731
- return useCallback(() => setCount(prevCount => prevCount + 1), []);
741
+ const [_, setCount] = React.useState(0);
742
+ return React.useCallback(() => setCount(prevCount => prevCount + 1), []);
732
743
  }
733
744
 
734
745
  function assert(expectedCondition, message) {
@@ -738,8 +749,6 @@ function assert(expectedCondition, message) {
738
749
  }
739
750
  }
740
751
 
741
- const PRECISION = 10;
742
-
743
752
  function fuzzyCompareNumbers(actual, expected, fractionDigits = PRECISION) {
744
753
  if (actual.toFixed(fractionDigits) === expected.toFixed(fractionDigits)) {
745
754
  return 0;
@@ -1083,12 +1092,12 @@ function calculateAriaValues({
1083
1092
  }
1084
1093
 
1085
1094
  function getResizeHandleElementsForGroup(groupId, scope = document) {
1086
- return Array.from(scope.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${groupId}"]`));
1095
+ return Array.from(scope.querySelectorAll(`[${DATA_ATTRIBUTES.resizeHandleId}][data-panel-group-id="${groupId}"]`));
1087
1096
  }
1088
1097
 
1089
1098
  function getResizeHandleElementIndex(groupId, id, scope = document) {
1090
1099
  const handles = getResizeHandleElementsForGroup(groupId, scope);
1091
- const index = handles.findIndex(handle => handle.getAttribute("data-panel-resize-handle-id") === id);
1100
+ const index = handles.findIndex(handle => handle.getAttribute(DATA_ATTRIBUTES.resizeHandleId) === id);
1092
1101
  return index !== null && index !== void 0 ? index : null;
1093
1102
  }
1094
1103
 
@@ -1113,7 +1122,7 @@ function getPanelGroupElement(id, rootElement = document) {
1113
1122
  }
1114
1123
 
1115
1124
  function getResizeHandleElement(id, scope = document) {
1116
- const element = scope.querySelector(`[data-panel-resize-handle-id="${id}"]`);
1125
+ const element = scope.querySelector(`[${DATA_ATTRIBUTES.resizeHandleId}="${id}"]`);
1117
1126
  if (element) {
1118
1127
  return element;
1119
1128
  }
@@ -1141,7 +1150,7 @@ function useWindowSplitterPanelGroupBehavior({
1141
1150
  panelGroupElement,
1142
1151
  setLayout
1143
1152
  }) {
1144
- const devWarningsRef = useRef({
1153
+ const devWarningsRef = React.useRef({
1145
1154
  didWarnAboutMissingResizeHandle: false
1146
1155
  });
1147
1156
  useIsomorphicLayoutEffect(() => {
@@ -1188,7 +1197,7 @@ function useWindowSplitterPanelGroupBehavior({
1188
1197
  });
1189
1198
  };
1190
1199
  }, [groupId, layout, panelDataArray, panelGroupElement]);
1191
- useEffect(() => {
1200
+ React.useEffect(() => {
1192
1201
  if (!panelGroupElement) {
1193
1202
  return;
1194
1203
  }
@@ -1202,7 +1211,7 @@ function useWindowSplitterPanelGroupBehavior({
1202
1211
  const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
1203
1212
  assert(handles, `No resize handles found for group id "${groupId}"`);
1204
1213
  const cleanupFunctions = handles.map(handle => {
1205
- const handleId = handle.getAttribute("data-panel-resize-handle-id");
1214
+ const handleId = handle.getAttribute(DATA_ATTRIBUTES.resizeHandleId);
1206
1215
  assert(handleId, `Resize handle element has no handle id attribute`);
1207
1216
  const [idBefore, idAfter] = getResizeHandlePanelIds(groupId, handleId, panelDataArray, panelGroupElement);
1208
1217
  if (idBefore == null || idAfter == null) {
@@ -1280,7 +1289,7 @@ function calculateDragOffsetPercentage(event, dragHandleId, direction, initialDr
1280
1289
  const isHorizontal = direction === "horizontal";
1281
1290
  const handleElement = getResizeHandleElement(dragHandleId, panelGroupElement);
1282
1291
  assert(handleElement, `No resize handle element found for id "${dragHandleId}"`);
1283
- const groupId = handleElement.getAttribute("data-panel-group-id");
1292
+ const groupId = handleElement.getAttribute(DATA_ATTRIBUTES.groupId);
1284
1293
  assert(groupId, `Resize handle element has no group id attribute`);
1285
1294
  let {
1286
1295
  initialCursorPosition
@@ -1695,14 +1704,14 @@ function PanelGroupWithForwardedRef({
1695
1704
  ...rest
1696
1705
  }) {
1697
1706
  const groupId = useUniqueId(idFromProps);
1698
- const panelGroupElementRef = useRef(null);
1699
- const [dragState, setDragState] = useState(null);
1700
- const [layout, setLayout] = useState([]);
1707
+ const panelGroupElementRef = React.useRef(null);
1708
+ const [dragState, setDragState] = React.useState(null);
1709
+ const [layout, setLayout] = React.useState([]);
1701
1710
  const forceUpdate = useForceUpdate();
1702
- const panelIdToLastNotifiedSizeMapRef = useRef({});
1703
- const panelSizeBeforeCollapseRef = useRef(new Map());
1704
- const prevDeltaRef = useRef(0);
1705
- const committedValuesRef = useRef({
1711
+ const panelIdToLastNotifiedSizeMapRef = React.useRef({});
1712
+ const panelSizeBeforeCollapseRef = React.useRef(new Map());
1713
+ const prevDeltaRef = React.useRef(0);
1714
+ const committedValuesRef = React.useRef({
1706
1715
  autoSaveId,
1707
1716
  direction,
1708
1717
  dragState,
@@ -1711,17 +1720,17 @@ function PanelGroupWithForwardedRef({
1711
1720
  onLayout,
1712
1721
  storage
1713
1722
  });
1714
- const eagerValuesRef = useRef({
1723
+ const eagerValuesRef = React.useRef({
1715
1724
  layout,
1716
1725
  panelDataArray: [],
1717
1726
  panelDataArrayChanged: false
1718
1727
  });
1719
- const devWarningsRef = useRef({
1728
+ const devWarningsRef = React.useRef({
1720
1729
  didLogIdAndOrderWarning: false,
1721
1730
  didLogPanelConstraintsWarning: false,
1722
1731
  prevPanelIds: []
1723
1732
  });
1724
- useImperativeHandle(forwardedRef, () => ({
1733
+ React.useImperativeHandle(forwardedRef, () => ({
1725
1734
  getId: () => committedValuesRef.current.id,
1726
1735
  getLayout: () => {
1727
1736
  const {
@@ -1768,7 +1777,7 @@ function PanelGroupWithForwardedRef({
1768
1777
  setLayout,
1769
1778
  panelGroupElement: panelGroupElementRef.current
1770
1779
  });
1771
- useEffect(() => {
1780
+ React.useEffect(() => {
1772
1781
  const {
1773
1782
  panelDataArray
1774
1783
  } = eagerValuesRef.current;
@@ -1795,7 +1804,7 @@ function PanelGroupWithForwardedRef({
1795
1804
  }, [autoSaveId, layout, storage]);
1796
1805
 
1797
1806
  // DEV warnings
1798
- useEffect(() => {
1807
+ React.useEffect(() => {
1799
1808
  {
1800
1809
  const {
1801
1810
  panelDataArray
@@ -1841,7 +1850,7 @@ function PanelGroupWithForwardedRef({
1841
1850
  });
1842
1851
 
1843
1852
  // External APIs are safe to memoize via committed values ref
1844
- const collapsePanel = useCallback(panelData => {
1853
+ const collapsePanel = React.useCallback(panelData => {
1845
1854
  const {
1846
1855
  onLayout
1847
1856
  } = committedValuesRef.current;
@@ -1884,7 +1893,7 @@ function PanelGroupWithForwardedRef({
1884
1893
  }, []);
1885
1894
 
1886
1895
  // External APIs are safe to memoize via committed values ref
1887
- const expandPanel = useCallback((panelData, minSizeOverride) => {
1896
+ const expandPanel = React.useCallback((panelData, minSizeOverride) => {
1888
1897
  const {
1889
1898
  onLayout
1890
1899
  } = committedValuesRef.current;
@@ -1928,7 +1937,7 @@ function PanelGroupWithForwardedRef({
1928
1937
  }, []);
1929
1938
 
1930
1939
  // External APIs are safe to memoize via committed values ref
1931
- const getPanelSize = useCallback(panelData => {
1940
+ const getPanelSize = React.useCallback(panelData => {
1932
1941
  const {
1933
1942
  layout,
1934
1943
  panelDataArray
@@ -1941,7 +1950,7 @@ function PanelGroupWithForwardedRef({
1941
1950
  }, []);
1942
1951
 
1943
1952
  // This API should never read from committedValuesRef
1944
- const getPanelStyle = useCallback((panelData, defaultSize) => {
1953
+ const getPanelStyle = React.useCallback((panelData, defaultSize) => {
1945
1954
  const {
1946
1955
  panelDataArray
1947
1956
  } = eagerValuesRef.current;
@@ -1956,7 +1965,7 @@ function PanelGroupWithForwardedRef({
1956
1965
  }, [dragState, layout]);
1957
1966
 
1958
1967
  // External APIs are safe to memoize via committed values ref
1959
- const isPanelCollapsed = useCallback(panelData => {
1968
+ const isPanelCollapsed = React.useCallback(panelData => {
1960
1969
  const {
1961
1970
  layout,
1962
1971
  panelDataArray
@@ -1971,7 +1980,7 @@ function PanelGroupWithForwardedRef({
1971
1980
  }, []);
1972
1981
 
1973
1982
  // External APIs are safe to memoize via committed values ref
1974
- const isPanelExpanded = useCallback(panelData => {
1983
+ const isPanelExpanded = React.useCallback(panelData => {
1975
1984
  const {
1976
1985
  layout,
1977
1986
  panelDataArray
@@ -1984,7 +1993,7 @@ function PanelGroupWithForwardedRef({
1984
1993
  assert(panelSize != null, `Panel size not found for panel "${panelData.id}"`);
1985
1994
  return !collapsible || fuzzyCompareNumbers(panelSize, collapsedSize) > 0;
1986
1995
  }, []);
1987
- const registerPanel = useCallback(panelData => {
1996
+ const registerPanel = React.useCallback(panelData => {
1988
1997
  const {
1989
1998
  panelDataArray
1990
1999
  } = eagerValuesRef.current;
@@ -2061,7 +2070,7 @@ function PanelGroupWithForwardedRef({
2061
2070
  eagerValues.layout = [];
2062
2071
  };
2063
2072
  }, []);
2064
- const registerResizeHandle = useCallback(dragHandleId => {
2073
+ const registerResizeHandle = React.useCallback(dragHandleId => {
2065
2074
  let isRTL = false;
2066
2075
  const panelGroupElement = panelGroupElementRef.current;
2067
2076
  if (panelGroupElement) {
@@ -2140,7 +2149,7 @@ function PanelGroupWithForwardedRef({
2140
2149
  }, []);
2141
2150
 
2142
2151
  // External APIs are safe to memoize via committed values ref
2143
- const resizePanel = useCallback((panelData, unsafePanelSize) => {
2152
+ const resizePanel = React.useCallback((panelData, unsafePanelSize) => {
2144
2153
  const {
2145
2154
  onLayout
2146
2155
  } = committedValuesRef.current;
@@ -2173,7 +2182,7 @@ function PanelGroupWithForwardedRef({
2173
2182
  callPanelCallbacks(panelDataArray, nextLayout, panelIdToLastNotifiedSizeMapRef.current);
2174
2183
  }
2175
2184
  }, []);
2176
- const reevaluatePanelConstraints = useCallback((panelData, prevConstraints) => {
2185
+ const reevaluatePanelConstraints = React.useCallback((panelData, prevConstraints) => {
2177
2186
  const {
2178
2187
  layout,
2179
2188
  panelDataArray
@@ -2207,7 +2216,7 @@ function PanelGroupWithForwardedRef({
2207
2216
  }, [resizePanel]);
2208
2217
 
2209
2218
  // TODO Multiple drag handles can be active at the same time so this API is a bit awkward now
2210
- const startDragging = useCallback((dragHandleId, event) => {
2219
+ const startDragging = React.useCallback((dragHandleId, event) => {
2211
2220
  const {
2212
2221
  direction
2213
2222
  } = committedValuesRef.current;
@@ -2227,10 +2236,10 @@ function PanelGroupWithForwardedRef({
2227
2236
  initialLayout: layout
2228
2237
  });
2229
2238
  }, []);
2230
- const stopDragging = useCallback(() => {
2239
+ const stopDragging = React.useCallback(() => {
2231
2240
  setDragState(null);
2232
2241
  }, []);
2233
- const unregisterPanel = useCallback(panelData => {
2242
+ const unregisterPanel = React.useCallback(panelData => {
2234
2243
  const {
2235
2244
  panelDataArray
2236
2245
  } = eagerValuesRef.current;
@@ -2247,7 +2256,7 @@ function PanelGroupWithForwardedRef({
2247
2256
  forceUpdate();
2248
2257
  }
2249
2258
  }, [forceUpdate]);
2250
- const context = useMemo(() => ({
2259
+ const context = React.useMemo(() => ({
2251
2260
  collapsePanel,
2252
2261
  direction,
2253
2262
  dragState,
@@ -2273,9 +2282,9 @@ function PanelGroupWithForwardedRef({
2273
2282
  overflow: "hidden",
2274
2283
  width: "100%"
2275
2284
  };
2276
- return createElement(PanelGroupContext.Provider, {
2285
+ return React.createElement(PanelGroupContext.Provider, {
2277
2286
  value: context
2278
- }, createElement(Type, {
2287
+ }, React.createElement(Type, {
2279
2288
  ...rest,
2280
2289
  children,
2281
2290
  className: classNameFromProps,
@@ -2286,12 +2295,12 @@ function PanelGroupWithForwardedRef({
2286
2295
  ...styleFromProps
2287
2296
  },
2288
2297
  // CSS selectors
2289
- "data-panel-group": "",
2290
- "data-panel-group-direction": direction,
2291
- "data-panel-group-id": groupId
2298
+ [DATA_ATTRIBUTES.group]: "",
2299
+ [DATA_ATTRIBUTES.groupDirection]: direction,
2300
+ [DATA_ATTRIBUTES.groupId]: groupId
2292
2301
  }));
2293
2302
  }
2294
- const PanelGroup = forwardRef((props, ref) => createElement(PanelGroupWithForwardedRef, {
2303
+ const PanelGroup = React.forwardRef((props, ref) => React.createElement(PanelGroupWithForwardedRef, {
2295
2304
  ...props,
2296
2305
  forwardedRef: ref
2297
2306
  }));
@@ -2320,7 +2329,7 @@ function useWindowSplitterResizeHandlerBehavior({
2320
2329
  resizeHandler,
2321
2330
  panelGroupElement
2322
2331
  }) {
2323
- useEffect(() => {
2332
+ React.useEffect(() => {
2324
2333
  if (disabled || resizeHandler == null || panelGroupElement == null) {
2325
2334
  return;
2326
2335
  }
@@ -2347,7 +2356,7 @@ function useWindowSplitterResizeHandlerBehavior({
2347
2356
  case "F6":
2348
2357
  {
2349
2358
  event.preventDefault();
2350
- const groupId = handleElement.getAttribute("data-panel-group-id");
2359
+ const groupId = handleElement.getAttribute(DATA_ATTRIBUTES.groupId);
2351
2360
  assert(groupId, `No group element found for id "${groupId}"`);
2352
2361
  const handles = getResizeHandleElementsForGroup(groupId, panelGroupElement);
2353
2362
  const index = getResizeHandleElementIndex(groupId, handleId, panelGroupElement);
@@ -2373,24 +2382,33 @@ function PanelResizeHandle({
2373
2382
  hitAreaMargins,
2374
2383
  id: idFromProps,
2375
2384
  onBlur,
2385
+ onClick,
2376
2386
  onDragging,
2377
2387
  onFocus,
2388
+ onPointerDown,
2389
+ onPointerUp,
2378
2390
  style: styleFromProps = {},
2379
2391
  tabIndex = 0,
2380
2392
  tagName: Type = "div",
2381
2393
  ...rest
2382
2394
  }) {
2383
2395
  var _hitAreaMargins$coars, _hitAreaMargins$fine;
2384
- const elementRef = useRef(null);
2396
+ const elementRef = React.useRef(null);
2385
2397
 
2386
2398
  // Use a ref to guard against users passing inline props
2387
- const callbacksRef = useRef({
2388
- onDragging
2399
+ const callbacksRef = React.useRef({
2400
+ onClick,
2401
+ onDragging,
2402
+ onPointerDown,
2403
+ onPointerUp
2389
2404
  });
2390
- useEffect(() => {
2405
+ React.useEffect(() => {
2406
+ callbacksRef.current.onClick = onClick;
2391
2407
  callbacksRef.current.onDragging = onDragging;
2408
+ callbacksRef.current.onPointerDown = onPointerDown;
2409
+ callbacksRef.current.onPointerUp = onPointerUp;
2392
2410
  });
2393
- const panelGroupContext = useContext(PanelGroupContext);
2411
+ const panelGroupContext = React.useContext(PanelGroupContext);
2394
2412
  if (panelGroupContext === null) {
2395
2413
  throw Error(`PanelResizeHandle components must be rendered within a PanelGroup container`);
2396
2414
  }
@@ -2403,16 +2421,16 @@ function PanelResizeHandle({
2403
2421
  panelGroupElement
2404
2422
  } = panelGroupContext;
2405
2423
  const resizeHandleId = useUniqueId(idFromProps);
2406
- const [state, setState] = useState("inactive");
2407
- const [isFocused, setIsFocused] = useState(false);
2408
- const [resizeHandler, setResizeHandler] = useState(null);
2409
- const committedValuesRef = useRef({
2424
+ const [state, setState] = React.useState("inactive");
2425
+ const [isFocused, setIsFocused] = React.useState(false);
2426
+ const [resizeHandler, setResizeHandler] = React.useState(null);
2427
+ const committedValuesRef = React.useRef({
2410
2428
  state
2411
2429
  });
2412
2430
  useIsomorphicLayoutEffect(() => {
2413
2431
  committedValuesRef.current.state = state;
2414
2432
  });
2415
- useEffect(() => {
2433
+ React.useEffect(() => {
2416
2434
  if (disabled) {
2417
2435
  setResizeHandler(null);
2418
2436
  } else {
@@ -2425,55 +2443,62 @@ function PanelResizeHandle({
2425
2443
  // so that inline object values won't trigger re-renders
2426
2444
  const coarseHitAreaMargins = (_hitAreaMargins$coars = hitAreaMargins === null || hitAreaMargins === void 0 ? void 0 : hitAreaMargins.coarse) !== null && _hitAreaMargins$coars !== void 0 ? _hitAreaMargins$coars : 15;
2427
2445
  const fineHitAreaMargins = (_hitAreaMargins$fine = hitAreaMargins === null || hitAreaMargins === void 0 ? void 0 : hitAreaMargins.fine) !== null && _hitAreaMargins$fine !== void 0 ? _hitAreaMargins$fine : 5;
2428
- useEffect(() => {
2446
+ React.useEffect(() => {
2429
2447
  if (disabled || resizeHandler == null) {
2430
2448
  return;
2431
2449
  }
2432
2450
  const element = elementRef.current;
2433
2451
  assert(element, "Element ref not attached");
2452
+ let didMove = false;
2434
2453
  const setResizeHandlerState = (action, isActive, event) => {
2435
- if (isActive) {
2436
- switch (action) {
2437
- case "down":
2438
- {
2439
- setState("drag");
2440
- assert(event, 'Expected event to be defined for "down" action');
2441
- startDragging(resizeHandleId, event);
2442
- const {
2443
- onDragging
2444
- } = callbacksRef.current;
2445
- if (onDragging) {
2446
- onDragging(true);
2447
- }
2448
- break;
2449
- }
2450
- case "move":
2451
- {
2452
- const {
2453
- state
2454
- } = committedValuesRef.current;
2455
- if (state !== "drag") {
2456
- setState("hover");
2457
- }
2458
- assert(event, 'Expected event to be defined for "move" action');
2459
- resizeHandler(event);
2460
- break;
2461
- }
2462
- case "up":
2463
- {
2454
+ if (!isActive) {
2455
+ setState("inactive");
2456
+ return;
2457
+ }
2458
+ switch (action) {
2459
+ case "down":
2460
+ {
2461
+ setState("drag");
2462
+ didMove = false;
2463
+ assert(event, 'Expected event to be defined for "down" action');
2464
+ startDragging(resizeHandleId, event);
2465
+ const {
2466
+ onDragging,
2467
+ onPointerDown
2468
+ } = callbacksRef.current;
2469
+ onDragging === null || onDragging === void 0 ? void 0 : onDragging(true);
2470
+ onPointerDown === null || onPointerDown === void 0 ? void 0 : onPointerDown();
2471
+ break;
2472
+ }
2473
+ case "move":
2474
+ {
2475
+ const {
2476
+ state
2477
+ } = committedValuesRef.current;
2478
+ didMove = true;
2479
+ if (state !== "drag") {
2464
2480
  setState("hover");
2465
- stopDragging();
2466
- const {
2467
- onDragging
2468
- } = callbacksRef.current;
2469
- if (onDragging) {
2470
- onDragging(false);
2471
- }
2472
- break;
2473
2481
  }
2474
- }
2475
- } else {
2476
- setState("inactive");
2482
+ assert(event, 'Expected event to be defined for "move" action');
2483
+ resizeHandler(event);
2484
+ break;
2485
+ }
2486
+ case "up":
2487
+ {
2488
+ setState("hover");
2489
+ stopDragging();
2490
+ const {
2491
+ onClick,
2492
+ onDragging,
2493
+ onPointerUp
2494
+ } = callbacksRef.current;
2495
+ onDragging === null || onDragging === void 0 ? void 0 : onDragging(false);
2496
+ onPointerUp === null || onPointerUp === void 0 ? void 0 : onPointerUp();
2497
+ if (!didMove) {
2498
+ onClick === null || onClick === void 0 ? void 0 : onClick();
2499
+ }
2500
+ break;
2501
+ }
2477
2502
  }
2478
2503
  };
2479
2504
  return registerResizeHandle(resizeHandleId, element, direction, {
@@ -2491,7 +2516,7 @@ function PanelResizeHandle({
2491
2516
  touchAction: "none",
2492
2517
  userSelect: "none"
2493
2518
  };
2494
- return createElement(Type, {
2519
+ return React.createElement(Type, {
2495
2520
  ...rest,
2496
2521
  children,
2497
2522
  className: classNameFromProps,
@@ -2512,13 +2537,13 @@ function PanelResizeHandle({
2512
2537
  },
2513
2538
  tabIndex,
2514
2539
  // CSS selectors
2515
- "data-panel-group-direction": direction,
2516
- "data-panel-group-id": groupId,
2517
- "data-resize-handle": "",
2518
- "data-resize-handle-active": state === "drag" ? "pointer" : isFocused ? "keyboard" : undefined,
2519
- "data-resize-handle-state": state,
2520
- "data-panel-resize-handle-enabled": !disabled,
2521
- "data-panel-resize-handle-id": resizeHandleId
2540
+ [DATA_ATTRIBUTES.groupDirection]: direction,
2541
+ [DATA_ATTRIBUTES.groupId]: groupId,
2542
+ [DATA_ATTRIBUTES.resizeHandle]: "",
2543
+ [DATA_ATTRIBUTES.resizeHandleActive]: state === "drag" ? "pointer" : isFocused ? "keyboard" : undefined,
2544
+ [DATA_ATTRIBUTES.resizeHandleEnabled]: !disabled,
2545
+ [DATA_ATTRIBUTES.resizeHandleId]: resizeHandleId,
2546
+ [DATA_ATTRIBUTES.resizeHandleState]: state
2522
2547
  });
2523
2548
  }
2524
2549
  PanelResizeHandle.displayName = "PanelResizeHandle";
@@ -2552,6 +2577,7 @@ function getIntersectingRectangle(rectOne, rectTwo, strict) {
2552
2577
  };
2553
2578
  }
2554
2579
 
2580
+ exports.DATA_ATTRIBUTES = DATA_ATTRIBUTES;
2555
2581
  exports.Panel = Panel;
2556
2582
  exports.PanelGroup = PanelGroup;
2557
2583
  exports.PanelResizeHandle = PanelResizeHandle;