react-resizable-panels 2.0.23 → 2.1.1

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 (30) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +16 -0
  3. package/dist/declarations/src/index.d.ts +3 -1
  4. package/dist/declarations/src/utils/csp.d.ts +2 -0
  5. package/dist/declarations/src/utils/cursor.d.ts +7 -0
  6. package/dist/react-resizable-panels.browser.cjs.js +27 -2
  7. package/dist/react-resizable-panels.browser.cjs.mjs +4 -1
  8. package/dist/react-resizable-panels.browser.development.cjs.js +27 -2
  9. package/dist/react-resizable-panels.browser.development.cjs.mjs +4 -1
  10. package/dist/react-resizable-panels.browser.development.esm.js +25 -3
  11. package/dist/react-resizable-panels.browser.esm.js +25 -3
  12. package/dist/react-resizable-panels.cjs.js +27 -2
  13. package/dist/react-resizable-panels.cjs.mjs +4 -1
  14. package/dist/react-resizable-panels.development.cjs.js +27 -2
  15. package/dist/react-resizable-panels.development.cjs.mjs +4 -1
  16. package/dist/react-resizable-panels.development.esm.js +25 -3
  17. package/dist/react-resizable-panels.development.node.cjs.js +27 -2
  18. package/dist/react-resizable-panels.development.node.cjs.mjs +4 -1
  19. package/dist/react-resizable-panels.development.node.esm.js +25 -3
  20. package/dist/react-resizable-panels.esm.js +25 -3
  21. package/dist/react-resizable-panels.node.cjs.js +27 -2
  22. package/dist/react-resizable-panels.node.cjs.mjs +4 -1
  23. package/dist/react-resizable-panels.node.esm.js +25 -3
  24. package/package.json +1 -1
  25. package/src/PanelGroup.ts +1 -1
  26. package/src/PanelResizeHandle.test.tsx +21 -2
  27. package/src/PanelResizeHandleRegistry.ts +1 -1
  28. package/src/index.ts +10 -0
  29. package/src/utils/csp.ts +9 -0
  30. package/src/utils/cursor.ts +19 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.1.1
4
+
5
+ - Fix `onDragging` regression (#391)
6
+ - Fix cursor icon behavior in nested panels (#390)
7
+
8
+ ## 2.1.0
9
+
10
+ - Add opt-in support for setting the [`"nonce"` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/nonce) for the global cursor style (#386)
11
+ - Support disabling global cursor styles (#387)
12
+
3
13
  ## 2.0.23
4
14
 
5
15
  - Improve obfuscation for `React.useId` references (#382)
package/README.md CHANGED
@@ -227,3 +227,19 @@ export function ClientComponent({
227
227
  > Be sure to specify a `defaultSize` prop for **every** `Panel` component to avoid layout flicker.
228
228
 
229
229
  A demo of this is available [here](https://github.com/bvaughn/react-resizable-panels-demo-ssr).
230
+
231
+ #### How can I set the [CSP `"nonce"`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/nonce) attribute?
232
+
233
+ ```js
234
+ import { setNonce } from "react-resizable-panels";
235
+
236
+ setNonce("your-nonce-value-here");
237
+ ```
238
+
239
+ #### How can I disable global cursor styles?
240
+
241
+ ```js
242
+ import { disableGlobalCursorStyles } from "react-resizable-panels";
243
+
244
+ disableGlobalCursorStyles();
245
+ ```
@@ -2,6 +2,8 @@ import { Panel } from "./Panel.js";
2
2
  import { PanelGroup } from "./PanelGroup.js";
3
3
  import { PanelResizeHandle } from "./PanelResizeHandle.js";
4
4
  import { assert } from "./utils/assert.js";
5
+ import { setNonce } from "./utils/csp.js";
6
+ import { enableGlobalCursorStyles, disableGlobalCursorStyles } from "./utils/cursor.js";
5
7
  import { getPanelElement } from "./utils/dom/getPanelElement.js";
6
8
  import { getPanelElementsForGroup } from "./utils/dom/getPanelElementsForGroup.js";
7
9
  import { getPanelGroupElement } from "./utils/dom/getPanelGroupElement.js";
@@ -15,4 +17,4 @@ import type { ImperativePanelHandle, PanelOnCollapse, PanelOnExpand, PanelOnResi
15
17
  import type { ImperativePanelGroupHandle, PanelGroupOnLayout, PanelGroupProps, PanelGroupStorage } from "./PanelGroup.js";
16
18
  import type { PanelResizeHandleOnDragging, PanelResizeHandleProps } from "./PanelResizeHandle.js";
17
19
  import type { PointerHitAreaMargins } from "./PanelResizeHandleRegistry.js";
18
- export { ImperativePanelGroupHandle, ImperativePanelHandle, PanelGroupOnLayout, PanelGroupProps, PanelGroupStorage, PanelOnCollapse, PanelOnExpand, PanelOnResize, PanelProps, PanelResizeHandleOnDragging, PanelResizeHandleProps, PointerHitAreaMargins, Panel, PanelGroup, PanelResizeHandle, assert, getIntersectingRectangle, intersects, getPanelElement, getPanelElementsForGroup, getPanelGroupElement, getResizeHandleElement, getResizeHandleElementIndex, getResizeHandleElementsForGroup, getResizeHandlePanelIds, };
20
+ export { ImperativePanelGroupHandle, ImperativePanelHandle, PanelGroupOnLayout, PanelGroupProps, PanelGroupStorage, PanelOnCollapse, PanelOnExpand, PanelOnResize, PanelProps, PanelResizeHandleOnDragging, PanelResizeHandleProps, PointerHitAreaMargins, Panel, PanelGroup, PanelResizeHandle, assert, getIntersectingRectangle, intersects, getPanelElement, getPanelElementsForGroup, getPanelGroupElement, getResizeHandleElement, getResizeHandleElementIndex, getResizeHandleElementsForGroup, getResizeHandlePanelIds, enableGlobalCursorStyles, disableGlobalCursorStyles, setNonce, };
@@ -0,0 +1,2 @@
1
+ export declare function getNonce(): string | null;
2
+ export declare function setNonce(value: string | null): void;
@@ -0,0 +1,7 @@
1
+ type CursorState = "horizontal" | "intersection" | "vertical";
2
+ export declare function disableGlobalCursorStyles(): void;
3
+ export declare function enableGlobalCursorStyles(): void;
4
+ export declare function getCursorStyle(state: CursorState, constraintFlags: number): string;
5
+ export declare function resetGlobalCursorStyle(): void;
6
+ export declare function setGlobalCursorStyle(state: CursorState, constraintFlags: number): void;
7
+ export {};
@@ -201,8 +201,23 @@ const Panel = forwardRef((props, ref) => createElement(PanelWithForwardedRef, {
201
201
  PanelWithForwardedRef.displayName = "Panel";
202
202
  Panel.displayName = "forwardRef(Panel)";
203
203
 
204
+ let nonce;
205
+ function getNonce() {
206
+ return nonce;
207
+ }
208
+ function setNonce(value) {
209
+ nonce = value;
210
+ }
211
+
204
212
  let currentCursorStyle = null;
213
+ let enabled = true;
205
214
  let styleElement = null;
215
+ function disableGlobalCursorStyles() {
216
+ enabled = false;
217
+ }
218
+ function enableGlobalCursorStyles() {
219
+ enabled = true;
220
+ }
206
221
  function getCursorStyle(state, constraintFlags) {
207
222
  if (constraintFlags) {
208
223
  const horizontalMin = (constraintFlags & EXCEEDED_HORIZONTAL_MIN) !== 0;
@@ -248,6 +263,9 @@ function resetGlobalCursorStyle() {
248
263
  }
249
264
  }
250
265
  function setGlobalCursorStyle(state, constraintFlags) {
266
+ if (!enabled) {
267
+ return;
268
+ }
251
269
  const style = getCursorStyle(state, constraintFlags);
252
270
  if (currentCursorStyle === style) {
253
271
  return;
@@ -255,6 +273,10 @@ function setGlobalCursorStyle(state, constraintFlags) {
255
273
  currentCursorStyle = style;
256
274
  if (styleElement === null) {
257
275
  styleElement = document.createElement("style");
276
+ const nonce = getNonce();
277
+ if (nonce) {
278
+ styleElement.setAttribute("nonce", nonce);
279
+ }
258
280
  document.head.appendChild(styleElement);
259
281
  }
260
282
  styleElement.innerHTML = `*{cursor: ${style}!important;}`;
@@ -495,7 +517,7 @@ function handlePointerMove(event) {
495
517
 
496
518
  // Edge case (see #340)
497
519
  // Detect when the pointer has been released outside an iframe on a different domain
498
- if (event.buttons === 0) {
520
+ if (isPointerDown && event.buttons === 0) {
499
521
  isPointerDown = false;
500
522
  updateResizeHandlerStates("up", event);
501
523
  }
@@ -1970,7 +1992,7 @@ function PanelGroupWithForwardedRef({
1970
1992
  // but updating cursor in this scenario would cause a flicker.
1971
1993
  if (prevDeltaRef.current != delta) {
1972
1994
  prevDeltaRef.current = delta;
1973
- if (!layoutChanged) {
1995
+ if (!layoutChanged && delta !== 0) {
1974
1996
  // If the pointer has moved too far to resize the panel any further, note this so we can update the cursor.
1975
1997
  // This mimics VS Code behavior.
1976
1998
  if (isHorizontal) {
@@ -2407,6 +2429,8 @@ exports.Panel = Panel;
2407
2429
  exports.PanelGroup = PanelGroup;
2408
2430
  exports.PanelResizeHandle = PanelResizeHandle;
2409
2431
  exports.assert = assert;
2432
+ exports.disableGlobalCursorStyles = disableGlobalCursorStyles;
2433
+ exports.enableGlobalCursorStyles = enableGlobalCursorStyles;
2410
2434
  exports.getIntersectingRectangle = getIntersectingRectangle;
2411
2435
  exports.getPanelElement = getPanelElement;
2412
2436
  exports.getPanelElementsForGroup = getPanelElementsForGroup;
@@ -2416,3 +2440,4 @@ exports.getResizeHandleElementIndex = getResizeHandleElementIndex;
2416
2440
  exports.getResizeHandleElementsForGroup = getResizeHandleElementsForGroup;
2417
2441
  exports.getResizeHandlePanelIds = getResizeHandlePanelIds;
2418
2442
  exports.intersects = intersects;
2443
+ exports.setNonce = setNonce;
@@ -3,6 +3,8 @@ export {
3
3
  PanelGroup,
4
4
  PanelResizeHandle,
5
5
  assert,
6
+ disableGlobalCursorStyles,
7
+ enableGlobalCursorStyles,
6
8
  getIntersectingRectangle,
7
9
  getPanelElement,
8
10
  getPanelElementsForGroup,
@@ -11,5 +13,6 @@ export {
11
13
  getResizeHandleElementIndex,
12
14
  getResizeHandleElementsForGroup,
13
15
  getResizeHandlePanelIds,
14
- intersects
16
+ intersects,
17
+ setNonce
15
18
  } from "./react-resizable-panels.browser.cjs.js";
@@ -207,8 +207,23 @@ const Panel = forwardRef((props, ref) => createElement(PanelWithForwardedRef, {
207
207
  PanelWithForwardedRef.displayName = "Panel";
208
208
  Panel.displayName = "forwardRef(Panel)";
209
209
 
210
+ let nonce;
211
+ function getNonce() {
212
+ return nonce;
213
+ }
214
+ function setNonce(value) {
215
+ nonce = value;
216
+ }
217
+
210
218
  let currentCursorStyle = null;
219
+ let enabled = true;
211
220
  let styleElement = null;
221
+ function disableGlobalCursorStyles() {
222
+ enabled = false;
223
+ }
224
+ function enableGlobalCursorStyles() {
225
+ enabled = true;
226
+ }
212
227
  function getCursorStyle(state, constraintFlags) {
213
228
  if (constraintFlags) {
214
229
  const horizontalMin = (constraintFlags & EXCEEDED_HORIZONTAL_MIN) !== 0;
@@ -254,6 +269,9 @@ function resetGlobalCursorStyle() {
254
269
  }
255
270
  }
256
271
  function setGlobalCursorStyle(state, constraintFlags) {
272
+ if (!enabled) {
273
+ return;
274
+ }
257
275
  const style = getCursorStyle(state, constraintFlags);
258
276
  if (currentCursorStyle === style) {
259
277
  return;
@@ -261,6 +279,10 @@ function setGlobalCursorStyle(state, constraintFlags) {
261
279
  currentCursorStyle = style;
262
280
  if (styleElement === null) {
263
281
  styleElement = document.createElement("style");
282
+ const nonce = getNonce();
283
+ if (nonce) {
284
+ styleElement.setAttribute("nonce", nonce);
285
+ }
264
286
  document.head.appendChild(styleElement);
265
287
  }
266
288
  styleElement.innerHTML = `*{cursor: ${style}!important;}`;
@@ -501,7 +523,7 @@ function handlePointerMove(event) {
501
523
 
502
524
  // Edge case (see #340)
503
525
  // Detect when the pointer has been released outside an iframe on a different domain
504
- if (event.buttons === 0) {
526
+ if (isPointerDown && event.buttons === 0) {
505
527
  isPointerDown = false;
506
528
  updateResizeHandlerStates("up", event);
507
529
  }
@@ -2076,7 +2098,7 @@ function PanelGroupWithForwardedRef({
2076
2098
  // but updating cursor in this scenario would cause a flicker.
2077
2099
  if (prevDeltaRef.current != delta) {
2078
2100
  prevDeltaRef.current = delta;
2079
- if (!layoutChanged) {
2101
+ if (!layoutChanged && delta !== 0) {
2080
2102
  // If the pointer has moved too far to resize the panel any further, note this so we can update the cursor.
2081
2103
  // This mimics VS Code behavior.
2082
2104
  if (isHorizontal) {
@@ -2513,6 +2535,8 @@ exports.Panel = Panel;
2513
2535
  exports.PanelGroup = PanelGroup;
2514
2536
  exports.PanelResizeHandle = PanelResizeHandle;
2515
2537
  exports.assert = assert;
2538
+ exports.disableGlobalCursorStyles = disableGlobalCursorStyles;
2539
+ exports.enableGlobalCursorStyles = enableGlobalCursorStyles;
2516
2540
  exports.getIntersectingRectangle = getIntersectingRectangle;
2517
2541
  exports.getPanelElement = getPanelElement;
2518
2542
  exports.getPanelElementsForGroup = getPanelElementsForGroup;
@@ -2522,3 +2546,4 @@ exports.getResizeHandleElementIndex = getResizeHandleElementIndex;
2522
2546
  exports.getResizeHandleElementsForGroup = getResizeHandleElementsForGroup;
2523
2547
  exports.getResizeHandlePanelIds = getResizeHandlePanelIds;
2524
2548
  exports.intersects = intersects;
2549
+ exports.setNonce = setNonce;
@@ -3,6 +3,8 @@ export {
3
3
  PanelGroup,
4
4
  PanelResizeHandle,
5
5
  assert,
6
+ disableGlobalCursorStyles,
7
+ enableGlobalCursorStyles,
6
8
  getIntersectingRectangle,
7
9
  getPanelElement,
8
10
  getPanelElementsForGroup,
@@ -11,5 +13,6 @@ export {
11
13
  getResizeHandleElementIndex,
12
14
  getResizeHandleElementsForGroup,
13
15
  getResizeHandlePanelIds,
14
- intersects
16
+ intersects,
17
+ setNonce
15
18
  } from "./react-resizable-panels.browser.development.cjs.js";
@@ -183,8 +183,23 @@ const Panel = forwardRef((props, ref) => createElement(PanelWithForwardedRef, {
183
183
  PanelWithForwardedRef.displayName = "Panel";
184
184
  Panel.displayName = "forwardRef(Panel)";
185
185
 
186
+ let nonce;
187
+ function getNonce() {
188
+ return nonce;
189
+ }
190
+ function setNonce(value) {
191
+ nonce = value;
192
+ }
193
+
186
194
  let currentCursorStyle = null;
195
+ let enabled = true;
187
196
  let styleElement = null;
197
+ function disableGlobalCursorStyles() {
198
+ enabled = false;
199
+ }
200
+ function enableGlobalCursorStyles() {
201
+ enabled = true;
202
+ }
188
203
  function getCursorStyle(state, constraintFlags) {
189
204
  if (constraintFlags) {
190
205
  const horizontalMin = (constraintFlags & EXCEEDED_HORIZONTAL_MIN) !== 0;
@@ -230,6 +245,9 @@ function resetGlobalCursorStyle() {
230
245
  }
231
246
  }
232
247
  function setGlobalCursorStyle(state, constraintFlags) {
248
+ if (!enabled) {
249
+ return;
250
+ }
233
251
  const style = getCursorStyle(state, constraintFlags);
234
252
  if (currentCursorStyle === style) {
235
253
  return;
@@ -237,6 +255,10 @@ function setGlobalCursorStyle(state, constraintFlags) {
237
255
  currentCursorStyle = style;
238
256
  if (styleElement === null) {
239
257
  styleElement = document.createElement("style");
258
+ const nonce = getNonce();
259
+ if (nonce) {
260
+ styleElement.setAttribute("nonce", nonce);
261
+ }
240
262
  document.head.appendChild(styleElement);
241
263
  }
242
264
  styleElement.innerHTML = `*{cursor: ${style}!important;}`;
@@ -477,7 +499,7 @@ function handlePointerMove(event) {
477
499
 
478
500
  // Edge case (see #340)
479
501
  // Detect when the pointer has been released outside an iframe on a different domain
480
- if (event.buttons === 0) {
502
+ if (isPointerDown && event.buttons === 0) {
481
503
  isPointerDown = false;
482
504
  updateResizeHandlerStates("up", event);
483
505
  }
@@ -2052,7 +2074,7 @@ function PanelGroupWithForwardedRef({
2052
2074
  // but updating cursor in this scenario would cause a flicker.
2053
2075
  if (prevDeltaRef.current != delta) {
2054
2076
  prevDeltaRef.current = delta;
2055
- if (!layoutChanged) {
2077
+ if (!layoutChanged && delta !== 0) {
2056
2078
  // If the pointer has moved too far to resize the panel any further, note this so we can update the cursor.
2057
2079
  // This mimics VS Code behavior.
2058
2080
  if (isHorizontal) {
@@ -2485,4 +2507,4 @@ function getIntersectingRectangle(rectOne, rectTwo, strict) {
2485
2507
  };
2486
2508
  }
2487
2509
 
2488
- export { Panel, PanelGroup, PanelResizeHandle, assert, getIntersectingRectangle, getPanelElement, getPanelElementsForGroup, getPanelGroupElement, getResizeHandleElement, getResizeHandleElementIndex, getResizeHandleElementsForGroup, getResizeHandlePanelIds, intersects };
2510
+ export { Panel, PanelGroup, PanelResizeHandle, assert, disableGlobalCursorStyles, enableGlobalCursorStyles, getIntersectingRectangle, getPanelElement, getPanelElementsForGroup, getPanelGroupElement, getResizeHandleElement, getResizeHandleElementIndex, getResizeHandleElementsForGroup, getResizeHandlePanelIds, intersects, setNonce };
@@ -177,8 +177,23 @@ const Panel = forwardRef((props, ref) => createElement(PanelWithForwardedRef, {
177
177
  PanelWithForwardedRef.displayName = "Panel";
178
178
  Panel.displayName = "forwardRef(Panel)";
179
179
 
180
+ let nonce;
181
+ function getNonce() {
182
+ return nonce;
183
+ }
184
+ function setNonce(value) {
185
+ nonce = value;
186
+ }
187
+
180
188
  let currentCursorStyle = null;
189
+ let enabled = true;
181
190
  let styleElement = null;
191
+ function disableGlobalCursorStyles() {
192
+ enabled = false;
193
+ }
194
+ function enableGlobalCursorStyles() {
195
+ enabled = true;
196
+ }
182
197
  function getCursorStyle(state, constraintFlags) {
183
198
  if (constraintFlags) {
184
199
  const horizontalMin = (constraintFlags & EXCEEDED_HORIZONTAL_MIN) !== 0;
@@ -224,6 +239,9 @@ function resetGlobalCursorStyle() {
224
239
  }
225
240
  }
226
241
  function setGlobalCursorStyle(state, constraintFlags) {
242
+ if (!enabled) {
243
+ return;
244
+ }
227
245
  const style = getCursorStyle(state, constraintFlags);
228
246
  if (currentCursorStyle === style) {
229
247
  return;
@@ -231,6 +249,10 @@ function setGlobalCursorStyle(state, constraintFlags) {
231
249
  currentCursorStyle = style;
232
250
  if (styleElement === null) {
233
251
  styleElement = document.createElement("style");
252
+ const nonce = getNonce();
253
+ if (nonce) {
254
+ styleElement.setAttribute("nonce", nonce);
255
+ }
234
256
  document.head.appendChild(styleElement);
235
257
  }
236
258
  styleElement.innerHTML = `*{cursor: ${style}!important;}`;
@@ -471,7 +493,7 @@ function handlePointerMove(event) {
471
493
 
472
494
  // Edge case (see #340)
473
495
  // Detect when the pointer has been released outside an iframe on a different domain
474
- if (event.buttons === 0) {
496
+ if (isPointerDown && event.buttons === 0) {
475
497
  isPointerDown = false;
476
498
  updateResizeHandlerStates("up", event);
477
499
  }
@@ -1946,7 +1968,7 @@ function PanelGroupWithForwardedRef({
1946
1968
  // but updating cursor in this scenario would cause a flicker.
1947
1969
  if (prevDeltaRef.current != delta) {
1948
1970
  prevDeltaRef.current = delta;
1949
- if (!layoutChanged) {
1971
+ if (!layoutChanged && delta !== 0) {
1950
1972
  // If the pointer has moved too far to resize the panel any further, note this so we can update the cursor.
1951
1973
  // This mimics VS Code behavior.
1952
1974
  if (isHorizontal) {
@@ -2379,4 +2401,4 @@ function getIntersectingRectangle(rectOne, rectTwo, strict) {
2379
2401
  };
2380
2402
  }
2381
2403
 
2382
- export { Panel, PanelGroup, PanelResizeHandle, assert, getIntersectingRectangle, getPanelElement, getPanelElementsForGroup, getPanelGroupElement, getResizeHandleElement, getResizeHandleElementIndex, getResizeHandleElementsForGroup, getResizeHandlePanelIds, intersects };
2404
+ export { Panel, PanelGroup, PanelResizeHandle, assert, disableGlobalCursorStyles, enableGlobalCursorStyles, getIntersectingRectangle, getPanelElement, getPanelElementsForGroup, getPanelGroupElement, getResizeHandleElement, getResizeHandleElementIndex, getResizeHandleElementsForGroup, getResizeHandlePanelIds, intersects, setNonce };
@@ -203,8 +203,23 @@ const Panel = forwardRef((props, ref) => createElement(PanelWithForwardedRef, {
203
203
  PanelWithForwardedRef.displayName = "Panel";
204
204
  Panel.displayName = "forwardRef(Panel)";
205
205
 
206
+ let nonce;
207
+ function getNonce() {
208
+ return nonce;
209
+ }
210
+ function setNonce(value) {
211
+ nonce = value;
212
+ }
213
+
206
214
  let currentCursorStyle = null;
215
+ let enabled = true;
207
216
  let styleElement = null;
217
+ function disableGlobalCursorStyles() {
218
+ enabled = false;
219
+ }
220
+ function enableGlobalCursorStyles() {
221
+ enabled = true;
222
+ }
208
223
  function getCursorStyle(state, constraintFlags) {
209
224
  if (constraintFlags) {
210
225
  const horizontalMin = (constraintFlags & EXCEEDED_HORIZONTAL_MIN) !== 0;
@@ -250,6 +265,9 @@ function resetGlobalCursorStyle() {
250
265
  }
251
266
  }
252
267
  function setGlobalCursorStyle(state, constraintFlags) {
268
+ if (!enabled) {
269
+ return;
270
+ }
253
271
  const style = getCursorStyle(state, constraintFlags);
254
272
  if (currentCursorStyle === style) {
255
273
  return;
@@ -257,6 +275,10 @@ function setGlobalCursorStyle(state, constraintFlags) {
257
275
  currentCursorStyle = style;
258
276
  if (styleElement === null) {
259
277
  styleElement = document.createElement("style");
278
+ const nonce = getNonce();
279
+ if (nonce) {
280
+ styleElement.setAttribute("nonce", nonce);
281
+ }
260
282
  document.head.appendChild(styleElement);
261
283
  }
262
284
  styleElement.innerHTML = `*{cursor: ${style}!important;}`;
@@ -497,7 +519,7 @@ function handlePointerMove(event) {
497
519
 
498
520
  // Edge case (see #340)
499
521
  // Detect when the pointer has been released outside an iframe on a different domain
500
- if (event.buttons === 0) {
522
+ if (isPointerDown && event.buttons === 0) {
501
523
  isPointerDown = false;
502
524
  updateResizeHandlerStates("up", event);
503
525
  }
@@ -1972,7 +1994,7 @@ function PanelGroupWithForwardedRef({
1972
1994
  // but updating cursor in this scenario would cause a flicker.
1973
1995
  if (prevDeltaRef.current != delta) {
1974
1996
  prevDeltaRef.current = delta;
1975
- if (!layoutChanged) {
1997
+ if (!layoutChanged && delta !== 0) {
1976
1998
  // If the pointer has moved too far to resize the panel any further, note this so we can update the cursor.
1977
1999
  // This mimics VS Code behavior.
1978
2000
  if (isHorizontal) {
@@ -2409,6 +2431,8 @@ exports.Panel = Panel;
2409
2431
  exports.PanelGroup = PanelGroup;
2410
2432
  exports.PanelResizeHandle = PanelResizeHandle;
2411
2433
  exports.assert = assert;
2434
+ exports.disableGlobalCursorStyles = disableGlobalCursorStyles;
2435
+ exports.enableGlobalCursorStyles = enableGlobalCursorStyles;
2412
2436
  exports.getIntersectingRectangle = getIntersectingRectangle;
2413
2437
  exports.getPanelElement = getPanelElement;
2414
2438
  exports.getPanelElementsForGroup = getPanelElementsForGroup;
@@ -2418,3 +2442,4 @@ exports.getResizeHandleElementIndex = getResizeHandleElementIndex;
2418
2442
  exports.getResizeHandleElementsForGroup = getResizeHandleElementsForGroup;
2419
2443
  exports.getResizeHandlePanelIds = getResizeHandlePanelIds;
2420
2444
  exports.intersects = intersects;
2445
+ exports.setNonce = setNonce;
@@ -3,6 +3,8 @@ export {
3
3
  PanelGroup,
4
4
  PanelResizeHandle,
5
5
  assert,
6
+ disableGlobalCursorStyles,
7
+ enableGlobalCursorStyles,
6
8
  getIntersectingRectangle,
7
9
  getPanelElement,
8
10
  getPanelElementsForGroup,
@@ -11,5 +13,6 @@ export {
11
13
  getResizeHandleElementIndex,
12
14
  getResizeHandleElementsForGroup,
13
15
  getResizeHandlePanelIds,
14
- intersects
16
+ intersects,
17
+ setNonce
15
18
  } from "./react-resizable-panels.cjs.js";
@@ -214,8 +214,23 @@ const Panel = forwardRef((props, ref) => createElement(PanelWithForwardedRef, {
214
214
  PanelWithForwardedRef.displayName = "Panel";
215
215
  Panel.displayName = "forwardRef(Panel)";
216
216
 
217
+ let nonce;
218
+ function getNonce() {
219
+ return nonce;
220
+ }
221
+ function setNonce(value) {
222
+ nonce = value;
223
+ }
224
+
217
225
  let currentCursorStyle = null;
226
+ let enabled = true;
218
227
  let styleElement = null;
228
+ function disableGlobalCursorStyles() {
229
+ enabled = false;
230
+ }
231
+ function enableGlobalCursorStyles() {
232
+ enabled = true;
233
+ }
219
234
  function getCursorStyle(state, constraintFlags) {
220
235
  if (constraintFlags) {
221
236
  const horizontalMin = (constraintFlags & EXCEEDED_HORIZONTAL_MIN) !== 0;
@@ -261,6 +276,9 @@ function resetGlobalCursorStyle() {
261
276
  }
262
277
  }
263
278
  function setGlobalCursorStyle(state, constraintFlags) {
279
+ if (!enabled) {
280
+ return;
281
+ }
264
282
  const style = getCursorStyle(state, constraintFlags);
265
283
  if (currentCursorStyle === style) {
266
284
  return;
@@ -268,6 +286,10 @@ function setGlobalCursorStyle(state, constraintFlags) {
268
286
  currentCursorStyle = style;
269
287
  if (styleElement === null) {
270
288
  styleElement = document.createElement("style");
289
+ const nonce = getNonce();
290
+ if (nonce) {
291
+ styleElement.setAttribute("nonce", nonce);
292
+ }
271
293
  document.head.appendChild(styleElement);
272
294
  }
273
295
  styleElement.innerHTML = `*{cursor: ${style}!important;}`;
@@ -508,7 +530,7 @@ function handlePointerMove(event) {
508
530
 
509
531
  // Edge case (see #340)
510
532
  // Detect when the pointer has been released outside an iframe on a different domain
511
- if (event.buttons === 0) {
533
+ if (isPointerDown && event.buttons === 0) {
512
534
  isPointerDown = false;
513
535
  updateResizeHandlerStates("up", event);
514
536
  }
@@ -2083,7 +2105,7 @@ function PanelGroupWithForwardedRef({
2083
2105
  // but updating cursor in this scenario would cause a flicker.
2084
2106
  if (prevDeltaRef.current != delta) {
2085
2107
  prevDeltaRef.current = delta;
2086
- if (!layoutChanged) {
2108
+ if (!layoutChanged && delta !== 0) {
2087
2109
  // If the pointer has moved too far to resize the panel any further, note this so we can update the cursor.
2088
2110
  // This mimics VS Code behavior.
2089
2111
  if (isHorizontal) {
@@ -2520,6 +2542,8 @@ exports.Panel = Panel;
2520
2542
  exports.PanelGroup = PanelGroup;
2521
2543
  exports.PanelResizeHandle = PanelResizeHandle;
2522
2544
  exports.assert = assert;
2545
+ exports.disableGlobalCursorStyles = disableGlobalCursorStyles;
2546
+ exports.enableGlobalCursorStyles = enableGlobalCursorStyles;
2523
2547
  exports.getIntersectingRectangle = getIntersectingRectangle;
2524
2548
  exports.getPanelElement = getPanelElement;
2525
2549
  exports.getPanelElementsForGroup = getPanelElementsForGroup;
@@ -2529,3 +2553,4 @@ exports.getResizeHandleElementIndex = getResizeHandleElementIndex;
2529
2553
  exports.getResizeHandleElementsForGroup = getResizeHandleElementsForGroup;
2530
2554
  exports.getResizeHandlePanelIds = getResizeHandlePanelIds;
2531
2555
  exports.intersects = intersects;
2556
+ exports.setNonce = setNonce;
@@ -3,6 +3,8 @@ export {
3
3
  PanelGroup,
4
4
  PanelResizeHandle,
5
5
  assert,
6
+ disableGlobalCursorStyles,
7
+ enableGlobalCursorStyles,
6
8
  getIntersectingRectangle,
7
9
  getPanelElement,
8
10
  getPanelElementsForGroup,
@@ -11,5 +13,6 @@ export {
11
13
  getResizeHandleElementIndex,
12
14
  getResizeHandleElementsForGroup,
13
15
  getResizeHandlePanelIds,
14
- intersects
16
+ intersects,
17
+ setNonce
15
18
  } from "./react-resizable-panels.development.cjs.js";
@@ -190,8 +190,23 @@ const Panel = forwardRef((props, ref) => createElement(PanelWithForwardedRef, {
190
190
  PanelWithForwardedRef.displayName = "Panel";
191
191
  Panel.displayName = "forwardRef(Panel)";
192
192
 
193
+ let nonce;
194
+ function getNonce() {
195
+ return nonce;
196
+ }
197
+ function setNonce(value) {
198
+ nonce = value;
199
+ }
200
+
193
201
  let currentCursorStyle = null;
202
+ let enabled = true;
194
203
  let styleElement = null;
204
+ function disableGlobalCursorStyles() {
205
+ enabled = false;
206
+ }
207
+ function enableGlobalCursorStyles() {
208
+ enabled = true;
209
+ }
195
210
  function getCursorStyle(state, constraintFlags) {
196
211
  if (constraintFlags) {
197
212
  const horizontalMin = (constraintFlags & EXCEEDED_HORIZONTAL_MIN) !== 0;
@@ -237,6 +252,9 @@ function resetGlobalCursorStyle() {
237
252
  }
238
253
  }
239
254
  function setGlobalCursorStyle(state, constraintFlags) {
255
+ if (!enabled) {
256
+ return;
257
+ }
240
258
  const style = getCursorStyle(state, constraintFlags);
241
259
  if (currentCursorStyle === style) {
242
260
  return;
@@ -244,6 +262,10 @@ function setGlobalCursorStyle(state, constraintFlags) {
244
262
  currentCursorStyle = style;
245
263
  if (styleElement === null) {
246
264
  styleElement = document.createElement("style");
265
+ const nonce = getNonce();
266
+ if (nonce) {
267
+ styleElement.setAttribute("nonce", nonce);
268
+ }
247
269
  document.head.appendChild(styleElement);
248
270
  }
249
271
  styleElement.innerHTML = `*{cursor: ${style}!important;}`;
@@ -484,7 +506,7 @@ function handlePointerMove(event) {
484
506
 
485
507
  // Edge case (see #340)
486
508
  // Detect when the pointer has been released outside an iframe on a different domain
487
- if (event.buttons === 0) {
509
+ if (isPointerDown && event.buttons === 0) {
488
510
  isPointerDown = false;
489
511
  updateResizeHandlerStates("up", event);
490
512
  }
@@ -2059,7 +2081,7 @@ function PanelGroupWithForwardedRef({
2059
2081
  // but updating cursor in this scenario would cause a flicker.
2060
2082
  if (prevDeltaRef.current != delta) {
2061
2083
  prevDeltaRef.current = delta;
2062
- if (!layoutChanged) {
2084
+ if (!layoutChanged && delta !== 0) {
2063
2085
  // If the pointer has moved too far to resize the panel any further, note this so we can update the cursor.
2064
2086
  // This mimics VS Code behavior.
2065
2087
  if (isHorizontal) {
@@ -2492,4 +2514,4 @@ function getIntersectingRectangle(rectOne, rectTwo, strict) {
2492
2514
  };
2493
2515
  }
2494
2516
 
2495
- export { Panel, PanelGroup, PanelResizeHandle, assert, getIntersectingRectangle, getPanelElement, getPanelElementsForGroup, getPanelGroupElement, getResizeHandleElement, getResizeHandleElementIndex, getResizeHandleElementsForGroup, getResizeHandlePanelIds, intersects };
2517
+ export { Panel, PanelGroup, PanelResizeHandle, assert, disableGlobalCursorStyles, enableGlobalCursorStyles, getIntersectingRectangle, getPanelElement, getPanelElementsForGroup, getPanelGroupElement, getResizeHandleElement, getResizeHandleElementIndex, getResizeHandleElementsForGroup, getResizeHandlePanelIds, intersects, setNonce };
@@ -176,8 +176,23 @@ const Panel = forwardRef((props, ref) => createElement(PanelWithForwardedRef, {
176
176
  PanelWithForwardedRef.displayName = "Panel";
177
177
  Panel.displayName = "forwardRef(Panel)";
178
178
 
179
+ let nonce;
180
+ function getNonce() {
181
+ return nonce;
182
+ }
183
+ function setNonce(value) {
184
+ nonce = value;
185
+ }
186
+
179
187
  let currentCursorStyle = null;
188
+ let enabled = true;
180
189
  let styleElement = null;
190
+ function disableGlobalCursorStyles() {
191
+ enabled = false;
192
+ }
193
+ function enableGlobalCursorStyles() {
194
+ enabled = true;
195
+ }
181
196
  function getCursorStyle(state, constraintFlags) {
182
197
  if (constraintFlags) {
183
198
  const horizontalMin = (constraintFlags & EXCEEDED_HORIZONTAL_MIN) !== 0;
@@ -223,6 +238,9 @@ function resetGlobalCursorStyle() {
223
238
  }
224
239
  }
225
240
  function setGlobalCursorStyle(state, constraintFlags) {
241
+ if (!enabled) {
242
+ return;
243
+ }
226
244
  const style = getCursorStyle(state, constraintFlags);
227
245
  if (currentCursorStyle === style) {
228
246
  return;
@@ -230,6 +248,10 @@ function setGlobalCursorStyle(state, constraintFlags) {
230
248
  currentCursorStyle = style;
231
249
  if (styleElement === null) {
232
250
  styleElement = document.createElement("style");
251
+ const nonce = getNonce();
252
+ if (nonce) {
253
+ styleElement.setAttribute("nonce", nonce);
254
+ }
233
255
  document.head.appendChild(styleElement);
234
256
  }
235
257
  styleElement.innerHTML = `*{cursor: ${style}!important;}`;
@@ -470,7 +492,7 @@ function handlePointerMove(event) {
470
492
 
471
493
  // Edge case (see #340)
472
494
  // Detect when the pointer has been released outside an iframe on a different domain
473
- if (event.buttons === 0) {
495
+ if (isPointerDown && event.buttons === 0) {
474
496
  isPointerDown = false;
475
497
  updateResizeHandlerStates("up", event);
476
498
  }
@@ -1851,7 +1873,7 @@ function PanelGroupWithForwardedRef({
1851
1873
  // but updating cursor in this scenario would cause a flicker.
1852
1874
  if (prevDeltaRef.current != delta) {
1853
1875
  prevDeltaRef.current = delta;
1854
- if (!layoutChanged) {
1876
+ if (!layoutChanged && delta !== 0) {
1855
1877
  // If the pointer has moved too far to resize the panel any further, note this so we can update the cursor.
1856
1878
  // This mimics VS Code behavior.
1857
1879
  if (isHorizontal) {
@@ -2285,6 +2307,8 @@ exports.Panel = Panel;
2285
2307
  exports.PanelGroup = PanelGroup;
2286
2308
  exports.PanelResizeHandle = PanelResizeHandle;
2287
2309
  exports.assert = assert;
2310
+ exports.disableGlobalCursorStyles = disableGlobalCursorStyles;
2311
+ exports.enableGlobalCursorStyles = enableGlobalCursorStyles;
2288
2312
  exports.getIntersectingRectangle = getIntersectingRectangle;
2289
2313
  exports.getPanelElement = getPanelElement;
2290
2314
  exports.getPanelElementsForGroup = getPanelElementsForGroup;
@@ -2294,3 +2318,4 @@ exports.getResizeHandleElementIndex = getResizeHandleElementIndex;
2294
2318
  exports.getResizeHandleElementsForGroup = getResizeHandleElementsForGroup;
2295
2319
  exports.getResizeHandlePanelIds = getResizeHandlePanelIds;
2296
2320
  exports.intersects = intersects;
2321
+ exports.setNonce = setNonce;
@@ -3,6 +3,8 @@ export {
3
3
  PanelGroup,
4
4
  PanelResizeHandle,
5
5
  assert,
6
+ disableGlobalCursorStyles,
7
+ enableGlobalCursorStyles,
6
8
  getIntersectingRectangle,
7
9
  getPanelElement,
8
10
  getPanelElementsForGroup,
@@ -11,5 +13,6 @@ export {
11
13
  getResizeHandleElementIndex,
12
14
  getResizeHandleElementsForGroup,
13
15
  getResizeHandlePanelIds,
14
- intersects
16
+ intersects,
17
+ setNonce
15
18
  } from "./react-resizable-panels.development.node.cjs.js";
@@ -152,8 +152,23 @@ const Panel = forwardRef((props, ref) => createElement(PanelWithForwardedRef, {
152
152
  PanelWithForwardedRef.displayName = "Panel";
153
153
  Panel.displayName = "forwardRef(Panel)";
154
154
 
155
+ let nonce;
156
+ function getNonce() {
157
+ return nonce;
158
+ }
159
+ function setNonce(value) {
160
+ nonce = value;
161
+ }
162
+
155
163
  let currentCursorStyle = null;
164
+ let enabled = true;
156
165
  let styleElement = null;
166
+ function disableGlobalCursorStyles() {
167
+ enabled = false;
168
+ }
169
+ function enableGlobalCursorStyles() {
170
+ enabled = true;
171
+ }
157
172
  function getCursorStyle(state, constraintFlags) {
158
173
  if (constraintFlags) {
159
174
  const horizontalMin = (constraintFlags & EXCEEDED_HORIZONTAL_MIN) !== 0;
@@ -199,6 +214,9 @@ function resetGlobalCursorStyle() {
199
214
  }
200
215
  }
201
216
  function setGlobalCursorStyle(state, constraintFlags) {
217
+ if (!enabled) {
218
+ return;
219
+ }
202
220
  const style = getCursorStyle(state, constraintFlags);
203
221
  if (currentCursorStyle === style) {
204
222
  return;
@@ -206,6 +224,10 @@ function setGlobalCursorStyle(state, constraintFlags) {
206
224
  currentCursorStyle = style;
207
225
  if (styleElement === null) {
208
226
  styleElement = document.createElement("style");
227
+ const nonce = getNonce();
228
+ if (nonce) {
229
+ styleElement.setAttribute("nonce", nonce);
230
+ }
209
231
  document.head.appendChild(styleElement);
210
232
  }
211
233
  styleElement.innerHTML = `*{cursor: ${style}!important;}`;
@@ -446,7 +468,7 @@ function handlePointerMove(event) {
446
468
 
447
469
  // Edge case (see #340)
448
470
  // Detect when the pointer has been released outside an iframe on a different domain
449
- if (event.buttons === 0) {
471
+ if (isPointerDown && event.buttons === 0) {
450
472
  isPointerDown = false;
451
473
  updateResizeHandlerStates("up", event);
452
474
  }
@@ -1827,7 +1849,7 @@ function PanelGroupWithForwardedRef({
1827
1849
  // but updating cursor in this scenario would cause a flicker.
1828
1850
  if (prevDeltaRef.current != delta) {
1829
1851
  prevDeltaRef.current = delta;
1830
- if (!layoutChanged) {
1852
+ if (!layoutChanged && delta !== 0) {
1831
1853
  // If the pointer has moved too far to resize the panel any further, note this so we can update the cursor.
1832
1854
  // This mimics VS Code behavior.
1833
1855
  if (isHorizontal) {
@@ -2257,4 +2279,4 @@ function getIntersectingRectangle(rectOne, rectTwo, strict) {
2257
2279
  };
2258
2280
  }
2259
2281
 
2260
- export { Panel, PanelGroup, PanelResizeHandle, assert, getIntersectingRectangle, getPanelElement, getPanelElementsForGroup, getPanelGroupElement, getResizeHandleElement, getResizeHandleElementIndex, getResizeHandleElementsForGroup, getResizeHandlePanelIds, intersects };
2282
+ export { Panel, PanelGroup, PanelResizeHandle, assert, disableGlobalCursorStyles, enableGlobalCursorStyles, getIntersectingRectangle, getPanelElement, getPanelElementsForGroup, getPanelGroupElement, getResizeHandleElement, getResizeHandleElementIndex, getResizeHandleElementsForGroup, getResizeHandlePanelIds, intersects, setNonce };
@@ -179,8 +179,23 @@ const Panel = forwardRef((props, ref) => createElement(PanelWithForwardedRef, {
179
179
  PanelWithForwardedRef.displayName = "Panel";
180
180
  Panel.displayName = "forwardRef(Panel)";
181
181
 
182
+ let nonce;
183
+ function getNonce() {
184
+ return nonce;
185
+ }
186
+ function setNonce(value) {
187
+ nonce = value;
188
+ }
189
+
182
190
  let currentCursorStyle = null;
191
+ let enabled = true;
183
192
  let styleElement = null;
193
+ function disableGlobalCursorStyles() {
194
+ enabled = false;
195
+ }
196
+ function enableGlobalCursorStyles() {
197
+ enabled = true;
198
+ }
184
199
  function getCursorStyle(state, constraintFlags) {
185
200
  if (constraintFlags) {
186
201
  const horizontalMin = (constraintFlags & EXCEEDED_HORIZONTAL_MIN) !== 0;
@@ -226,6 +241,9 @@ function resetGlobalCursorStyle() {
226
241
  }
227
242
  }
228
243
  function setGlobalCursorStyle(state, constraintFlags) {
244
+ if (!enabled) {
245
+ return;
246
+ }
229
247
  const style = getCursorStyle(state, constraintFlags);
230
248
  if (currentCursorStyle === style) {
231
249
  return;
@@ -233,6 +251,10 @@ function setGlobalCursorStyle(state, constraintFlags) {
233
251
  currentCursorStyle = style;
234
252
  if (styleElement === null) {
235
253
  styleElement = document.createElement("style");
254
+ const nonce = getNonce();
255
+ if (nonce) {
256
+ styleElement.setAttribute("nonce", nonce);
257
+ }
236
258
  document.head.appendChild(styleElement);
237
259
  }
238
260
  styleElement.innerHTML = `*{cursor: ${style}!important;}`;
@@ -473,7 +495,7 @@ function handlePointerMove(event) {
473
495
 
474
496
  // Edge case (see #340)
475
497
  // Detect when the pointer has been released outside an iframe on a different domain
476
- if (event.buttons === 0) {
498
+ if (isPointerDown && event.buttons === 0) {
477
499
  isPointerDown = false;
478
500
  updateResizeHandlerStates("up", event);
479
501
  }
@@ -1948,7 +1970,7 @@ function PanelGroupWithForwardedRef({
1948
1970
  // but updating cursor in this scenario would cause a flicker.
1949
1971
  if (prevDeltaRef.current != delta) {
1950
1972
  prevDeltaRef.current = delta;
1951
- if (!layoutChanged) {
1973
+ if (!layoutChanged && delta !== 0) {
1952
1974
  // If the pointer has moved too far to resize the panel any further, note this so we can update the cursor.
1953
1975
  // This mimics VS Code behavior.
1954
1976
  if (isHorizontal) {
@@ -2381,4 +2403,4 @@ function getIntersectingRectangle(rectOne, rectTwo, strict) {
2381
2403
  };
2382
2404
  }
2383
2405
 
2384
- export { Panel, PanelGroup, PanelResizeHandle, assert, getIntersectingRectangle, getPanelElement, getPanelElementsForGroup, getPanelGroupElement, getResizeHandleElement, getResizeHandleElementIndex, getResizeHandleElementsForGroup, getResizeHandlePanelIds, intersects };
2406
+ export { Panel, PanelGroup, PanelResizeHandle, assert, disableGlobalCursorStyles, enableGlobalCursorStyles, getIntersectingRectangle, getPanelElement, getPanelElementsForGroup, getPanelGroupElement, getResizeHandleElement, getResizeHandleElementIndex, getResizeHandleElementsForGroup, getResizeHandlePanelIds, intersects, setNonce };
@@ -165,8 +165,23 @@ const Panel = forwardRef((props, ref) => createElement(PanelWithForwardedRef, {
165
165
  PanelWithForwardedRef.displayName = "Panel";
166
166
  Panel.displayName = "forwardRef(Panel)";
167
167
 
168
+ let nonce;
169
+ function getNonce() {
170
+ return nonce;
171
+ }
172
+ function setNonce(value) {
173
+ nonce = value;
174
+ }
175
+
168
176
  let currentCursorStyle = null;
177
+ let enabled = true;
169
178
  let styleElement = null;
179
+ function disableGlobalCursorStyles() {
180
+ enabled = false;
181
+ }
182
+ function enableGlobalCursorStyles() {
183
+ enabled = true;
184
+ }
170
185
  function getCursorStyle(state, constraintFlags) {
171
186
  if (constraintFlags) {
172
187
  const horizontalMin = (constraintFlags & EXCEEDED_HORIZONTAL_MIN) !== 0;
@@ -212,6 +227,9 @@ function resetGlobalCursorStyle() {
212
227
  }
213
228
  }
214
229
  function setGlobalCursorStyle(state, constraintFlags) {
230
+ if (!enabled) {
231
+ return;
232
+ }
215
233
  const style = getCursorStyle(state, constraintFlags);
216
234
  if (currentCursorStyle === style) {
217
235
  return;
@@ -219,6 +237,10 @@ function setGlobalCursorStyle(state, constraintFlags) {
219
237
  currentCursorStyle = style;
220
238
  if (styleElement === null) {
221
239
  styleElement = document.createElement("style");
240
+ const nonce = getNonce();
241
+ if (nonce) {
242
+ styleElement.setAttribute("nonce", nonce);
243
+ }
222
244
  document.head.appendChild(styleElement);
223
245
  }
224
246
  styleElement.innerHTML = `*{cursor: ${style}!important;}`;
@@ -459,7 +481,7 @@ function handlePointerMove(event) {
459
481
 
460
482
  // Edge case (see #340)
461
483
  // Detect when the pointer has been released outside an iframe on a different domain
462
- if (event.buttons === 0) {
484
+ if (isPointerDown && event.buttons === 0) {
463
485
  isPointerDown = false;
464
486
  updateResizeHandlerStates("up", event);
465
487
  }
@@ -1750,7 +1772,7 @@ function PanelGroupWithForwardedRef({
1750
1772
  // but updating cursor in this scenario would cause a flicker.
1751
1773
  if (prevDeltaRef.current != delta) {
1752
1774
  prevDeltaRef.current = delta;
1753
- if (!layoutChanged) {
1775
+ if (!layoutChanged && delta !== 0) {
1754
1776
  // If the pointer has moved too far to resize the panel any further, note this so we can update the cursor.
1755
1777
  // This mimics VS Code behavior.
1756
1778
  if (isHorizontal) {
@@ -2184,6 +2206,8 @@ exports.Panel = Panel;
2184
2206
  exports.PanelGroup = PanelGroup;
2185
2207
  exports.PanelResizeHandle = PanelResizeHandle;
2186
2208
  exports.assert = assert;
2209
+ exports.disableGlobalCursorStyles = disableGlobalCursorStyles;
2210
+ exports.enableGlobalCursorStyles = enableGlobalCursorStyles;
2187
2211
  exports.getIntersectingRectangle = getIntersectingRectangle;
2188
2212
  exports.getPanelElement = getPanelElement;
2189
2213
  exports.getPanelElementsForGroup = getPanelElementsForGroup;
@@ -2193,3 +2217,4 @@ exports.getResizeHandleElementIndex = getResizeHandleElementIndex;
2193
2217
  exports.getResizeHandleElementsForGroup = getResizeHandleElementsForGroup;
2194
2218
  exports.getResizeHandlePanelIds = getResizeHandlePanelIds;
2195
2219
  exports.intersects = intersects;
2220
+ exports.setNonce = setNonce;
@@ -3,6 +3,8 @@ export {
3
3
  PanelGroup,
4
4
  PanelResizeHandle,
5
5
  assert,
6
+ disableGlobalCursorStyles,
7
+ enableGlobalCursorStyles,
6
8
  getIntersectingRectangle,
7
9
  getPanelElement,
8
10
  getPanelElementsForGroup,
@@ -11,5 +13,6 @@ export {
11
13
  getResizeHandleElementIndex,
12
14
  getResizeHandleElementsForGroup,
13
15
  getResizeHandlePanelIds,
14
- intersects
16
+ intersects,
17
+ setNonce
15
18
  } from "./react-resizable-panels.node.cjs.js";
@@ -141,8 +141,23 @@ const Panel = forwardRef((props, ref) => createElement(PanelWithForwardedRef, {
141
141
  PanelWithForwardedRef.displayName = "Panel";
142
142
  Panel.displayName = "forwardRef(Panel)";
143
143
 
144
+ let nonce;
145
+ function getNonce() {
146
+ return nonce;
147
+ }
148
+ function setNonce(value) {
149
+ nonce = value;
150
+ }
151
+
144
152
  let currentCursorStyle = null;
153
+ let enabled = true;
145
154
  let styleElement = null;
155
+ function disableGlobalCursorStyles() {
156
+ enabled = false;
157
+ }
158
+ function enableGlobalCursorStyles() {
159
+ enabled = true;
160
+ }
146
161
  function getCursorStyle(state, constraintFlags) {
147
162
  if (constraintFlags) {
148
163
  const horizontalMin = (constraintFlags & EXCEEDED_HORIZONTAL_MIN) !== 0;
@@ -188,6 +203,9 @@ function resetGlobalCursorStyle() {
188
203
  }
189
204
  }
190
205
  function setGlobalCursorStyle(state, constraintFlags) {
206
+ if (!enabled) {
207
+ return;
208
+ }
191
209
  const style = getCursorStyle(state, constraintFlags);
192
210
  if (currentCursorStyle === style) {
193
211
  return;
@@ -195,6 +213,10 @@ function setGlobalCursorStyle(state, constraintFlags) {
195
213
  currentCursorStyle = style;
196
214
  if (styleElement === null) {
197
215
  styleElement = document.createElement("style");
216
+ const nonce = getNonce();
217
+ if (nonce) {
218
+ styleElement.setAttribute("nonce", nonce);
219
+ }
198
220
  document.head.appendChild(styleElement);
199
221
  }
200
222
  styleElement.innerHTML = `*{cursor: ${style}!important;}`;
@@ -435,7 +457,7 @@ function handlePointerMove(event) {
435
457
 
436
458
  // Edge case (see #340)
437
459
  // Detect when the pointer has been released outside an iframe on a different domain
438
- if (event.buttons === 0) {
460
+ if (isPointerDown && event.buttons === 0) {
439
461
  isPointerDown = false;
440
462
  updateResizeHandlerStates("up", event);
441
463
  }
@@ -1726,7 +1748,7 @@ function PanelGroupWithForwardedRef({
1726
1748
  // but updating cursor in this scenario would cause a flicker.
1727
1749
  if (prevDeltaRef.current != delta) {
1728
1750
  prevDeltaRef.current = delta;
1729
- if (!layoutChanged) {
1751
+ if (!layoutChanged && delta !== 0) {
1730
1752
  // If the pointer has moved too far to resize the panel any further, note this so we can update the cursor.
1731
1753
  // This mimics VS Code behavior.
1732
1754
  if (isHorizontal) {
@@ -2156,4 +2178,4 @@ function getIntersectingRectangle(rectOne, rectTwo, strict) {
2156
2178
  };
2157
2179
  }
2158
2180
 
2159
- export { Panel, PanelGroup, PanelResizeHandle, assert, getIntersectingRectangle, getPanelElement, getPanelElementsForGroup, getPanelGroupElement, getResizeHandleElement, getResizeHandleElementIndex, getResizeHandleElementsForGroup, getResizeHandlePanelIds, intersects };
2181
+ export { Panel, PanelGroup, PanelResizeHandle, assert, disableGlobalCursorStyles, enableGlobalCursorStyles, getIntersectingRectangle, getPanelElement, getPanelElementsForGroup, getPanelGroupElement, getResizeHandleElement, getResizeHandleElementIndex, getResizeHandleElementsForGroup, getResizeHandlePanelIds, intersects, setNonce };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-resizable-panels",
3
- "version": "2.0.23",
3
+ "version": "2.1.1",
4
4
  "description": "React components for resizable panel groups/layouts",
5
5
  "author": "Brian Vaughn <brian.david.vaughn@gmail.com>",
6
6
  "license": "MIT",
package/src/PanelGroup.ts CHANGED
@@ -676,7 +676,7 @@ function PanelGroupWithForwardedRef({
676
676
  if (prevDeltaRef.current != delta) {
677
677
  prevDeltaRef.current = delta;
678
678
 
679
- if (!layoutChanged) {
679
+ if (!layoutChanged && delta !== 0) {
680
680
  // If the pointer has moved too far to resize the panel any further, note this so we can update the cursor.
681
681
  // This mimics VS Code behavior.
682
682
  if (isHorizontal) {
@@ -336,13 +336,32 @@ describe("PanelResizeHandle", () => {
336
336
  expect(onDraggingLeft).toHaveBeenCalledWith(true);
337
337
 
338
338
  expect(cursorUtils.resetGlobalCursorStyle).not.toHaveBeenCalled();
339
- expect(cursorUtils.setGlobalCursorStyle).toHaveBeenCalledTimes(1);
339
+ expect(cursorUtils.setGlobalCursorStyle).toHaveBeenCalled();
340
+
341
+ onDraggingLeft.mockReset();
342
+
343
+ act(() => {
344
+ dispatchPointerEvent("pointermove", leftElement);
345
+ });
346
+ expect(onDraggingLeft).not.toHaveBeenCalled();
347
+
348
+ act(() => {
349
+ dispatchPointerEvent("pointerup", leftElement);
350
+ });
351
+ expect(onDraggingLeft).toHaveBeenCalledTimes(1);
352
+ expect(onDraggingLeft).toHaveBeenCalledWith(false);
353
+
354
+ onDraggingLeft.mockReset();
355
+
356
+ act(() => {
357
+ dispatchPointerEvent("pointermove", leftElement);
358
+ });
359
+ expect(onDraggingLeft).not.toHaveBeenCalled();
340
360
 
341
361
  act(() => {
342
362
  root.unmount();
343
363
  });
344
364
 
345
365
  expect(cursorUtils.resetGlobalCursorStyle).toHaveBeenCalled();
346
- expect(cursorUtils.setGlobalCursorStyle).toHaveBeenCalledTimes(1);
347
366
  });
348
367
  });
@@ -109,7 +109,7 @@ function handlePointerMove(event: PointerEvent) {
109
109
 
110
110
  // Edge case (see #340)
111
111
  // Detect when the pointer has been released outside an iframe on a different domain
112
- if (event.buttons === 0) {
112
+ if (isPointerDown && event.buttons === 0) {
113
113
  isPointerDown = false;
114
114
 
115
115
  updateResizeHandlerStates("up", event);
package/src/index.ts CHANGED
@@ -2,6 +2,11 @@ import { Panel } from "./Panel";
2
2
  import { PanelGroup } from "./PanelGroup";
3
3
  import { PanelResizeHandle } from "./PanelResizeHandle";
4
4
  import { assert } from "./utils/assert";
5
+ import { setNonce } from "./utils/csp";
6
+ import {
7
+ enableGlobalCursorStyles,
8
+ disableGlobalCursorStyles,
9
+ } from "./utils/cursor";
5
10
  import { getPanelElement } from "./utils/dom/getPanelElement";
6
11
  import { getPanelElementsForGroup } from "./utils/dom/getPanelElementsForGroup";
7
12
  import { getPanelGroupElement } from "./utils/dom/getPanelGroupElement";
@@ -64,4 +69,9 @@ export {
64
69
  getResizeHandleElementIndex,
65
70
  getResizeHandleElementsForGroup,
66
71
  getResizeHandlePanelIds,
72
+
73
+ // Styles and CSP (see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/nonce)
74
+ enableGlobalCursorStyles,
75
+ disableGlobalCursorStyles,
76
+ setNonce,
67
77
  };
@@ -0,0 +1,9 @@
1
+ let nonce: string | null;
2
+
3
+ export function getNonce(): string | null {
4
+ return nonce;
5
+ }
6
+
7
+ export function setNonce(value: string | null) {
8
+ nonce = value;
9
+ }
@@ -4,12 +4,22 @@ import {
4
4
  EXCEEDED_VERTICAL_MAX,
5
5
  EXCEEDED_VERTICAL_MIN,
6
6
  } from "../PanelResizeHandleRegistry";
7
+ import { getNonce } from "./csp";
7
8
 
8
9
  type CursorState = "horizontal" | "intersection" | "vertical";
9
10
 
10
11
  let currentCursorStyle: string | null = null;
12
+ let enabled: boolean = true;
11
13
  let styleElement: HTMLStyleElement | null = null;
12
14
 
15
+ export function disableGlobalCursorStyles() {
16
+ enabled = false;
17
+ }
18
+
19
+ export function enableGlobalCursorStyles() {
20
+ enabled = true;
21
+ }
22
+
13
23
  export function getCursorStyle(
14
24
  state: CursorState,
15
25
  constraintFlags: number
@@ -66,6 +76,10 @@ export function setGlobalCursorStyle(
66
76
  state: CursorState,
67
77
  constraintFlags: number
68
78
  ) {
79
+ if (!enabled) {
80
+ return;
81
+ }
82
+
69
83
  const style = getCursorStyle(state, constraintFlags);
70
84
 
71
85
  if (currentCursorStyle === style) {
@@ -77,6 +91,11 @@ export function setGlobalCursorStyle(
77
91
  if (styleElement === null) {
78
92
  styleElement = document.createElement("style");
79
93
 
94
+ const nonce = getNonce();
95
+ if (nonce) {
96
+ styleElement.setAttribute("nonce", nonce);
97
+ }
98
+
80
99
  document.head.appendChild(styleElement);
81
100
  }
82
101