react-resizable-panels 2.1.6 → 2.1.7

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 (87) hide show
  1. package/dist/react-resizable-panels.browser.cjs.js +7 -7
  2. package/dist/react-resizable-panels.browser.development.cjs.js +7 -7
  3. package/dist/react-resizable-panels.browser.development.esm.js +7 -7
  4. package/dist/react-resizable-panels.browser.esm.js +7 -7
  5. package/dist/react-resizable-panels.cjs.js +7 -7
  6. package/dist/react-resizable-panels.development.cjs.js +7 -7
  7. package/dist/react-resizable-panels.development.esm.js +7 -7
  8. package/dist/react-resizable-panels.development.node.cjs.js +7 -7
  9. package/dist/react-resizable-panels.development.node.esm.js +7 -7
  10. package/dist/react-resizable-panels.esm.js +7 -7
  11. package/dist/react-resizable-panels.node.cjs.js +7 -7
  12. package/dist/react-resizable-panels.node.esm.js +7 -7
  13. package/package.json +7 -1
  14. package/.eslintrc.cjs +0 -27
  15. package/CHANGELOG.md +0 -574
  16. package/jest.config.js +0 -10
  17. package/src/Panel.test.tsx +0 -1084
  18. package/src/Panel.ts +0 -259
  19. package/src/PanelGroup.test.tsx +0 -443
  20. package/src/PanelGroup.ts +0 -999
  21. package/src/PanelGroupContext.ts +0 -42
  22. package/src/PanelResizeHandle.test.tsx +0 -367
  23. package/src/PanelResizeHandle.ts +0 -246
  24. package/src/PanelResizeHandleRegistry.ts +0 -336
  25. package/src/constants.ts +0 -1
  26. package/src/env-conditions/browser.ts +0 -1
  27. package/src/env-conditions/development.ts +0 -1
  28. package/src/env-conditions/node.ts +0 -1
  29. package/src/env-conditions/production.ts +0 -1
  30. package/src/env-conditions/unknown.ts +0 -1
  31. package/src/hooks/useForceUpdate.ts +0 -7
  32. package/src/hooks/useIsomorphicEffect.ts +0 -8
  33. package/src/hooks/useUniqueId.ts +0 -19
  34. package/src/hooks/useWindowSplitterBehavior.ts +0 -90
  35. package/src/hooks/useWindowSplitterPanelGroupBehavior.ts +0 -201
  36. package/src/index.ts +0 -77
  37. package/src/types.ts +0 -5
  38. package/src/utils/adjustLayoutByDelta.test.ts +0 -2061
  39. package/src/utils/adjustLayoutByDelta.ts +0 -308
  40. package/src/utils/arrays.ts +0 -13
  41. package/src/utils/assert.ts +0 -10
  42. package/src/utils/calculateAriaValues.test.ts +0 -106
  43. package/src/utils/calculateAriaValues.ts +0 -45
  44. package/src/utils/calculateDeltaPercentage.ts +0 -63
  45. package/src/utils/calculateDragOffsetPercentage.ts +0 -40
  46. package/src/utils/calculateUnsafeDefaultLayout.test.ts +0 -87
  47. package/src/utils/calculateUnsafeDefaultLayout.ts +0 -50
  48. package/src/utils/callPanelCallbacks.ts +0 -49
  49. package/src/utils/compareLayouts.test.ts +0 -9
  50. package/src/utils/compareLayouts.ts +0 -12
  51. package/src/utils/computePanelFlexBoxStyle.test.ts +0 -123
  52. package/src/utils/computePanelFlexBoxStyle.ts +0 -50
  53. package/src/utils/csp.ts +0 -9
  54. package/src/utils/cursor.ts +0 -103
  55. package/src/utils/debounce.ts +0 -18
  56. package/src/utils/determinePivotIndices.ts +0 -15
  57. package/src/utils/dom/getPanelElement.ts +0 -10
  58. package/src/utils/dom/getPanelElementsForGroup.ts +0 -8
  59. package/src/utils/dom/getPanelGroupElement.ts +0 -21
  60. package/src/utils/dom/getResizeHandleElement.ts +0 -10
  61. package/src/utils/dom/getResizeHandleElementIndex.ts +0 -13
  62. package/src/utils/dom/getResizeHandleElementsForGroup.ts +0 -10
  63. package/src/utils/dom/getResizeHandlePanelIds.ts +0 -19
  64. package/src/utils/events/getResizeEventCoordinates.ts +0 -23
  65. package/src/utils/events/getResizeEventCursorPosition.ts +0 -14
  66. package/src/utils/events/index.ts +0 -13
  67. package/src/utils/getInputType.ts +0 -5
  68. package/src/utils/initializeDefaultStorage.ts +0 -26
  69. package/src/utils/numbers/fuzzyCompareNumbers.test.ts +0 -16
  70. package/src/utils/numbers/fuzzyCompareNumbers.ts +0 -21
  71. package/src/utils/numbers/fuzzyLayoutsEqual.ts +0 -22
  72. package/src/utils/numbers/fuzzyNumbersEqual.ts +0 -9
  73. package/src/utils/rects/getIntersectingRectangle.test.ts +0 -198
  74. package/src/utils/rects/getIntersectingRectangle.ts +0 -28
  75. package/src/utils/rects/intersects.test.ts +0 -197
  76. package/src/utils/rects/intersects.ts +0 -23
  77. package/src/utils/rects/types.ts +0 -6
  78. package/src/utils/resizePanel.test.ts +0 -59
  79. package/src/utils/resizePanel.ts +0 -47
  80. package/src/utils/serialization.ts +0 -87
  81. package/src/utils/test-utils.ts +0 -205
  82. package/src/utils/validatePanelConstraints.test.ts +0 -143
  83. package/src/utils/validatePanelConstraints.ts +0 -69
  84. package/src/utils/validatePanelGroupLayout.test.ts +0 -148
  85. package/src/utils/validatePanelGroupLayout.ts +0 -95
  86. package/src/vendor/react.ts +0 -73
  87. package/src/vendor/stacking-order.ts +0 -139
@@ -1,50 +0,0 @@
1
- import { PanelData } from "../Panel";
2
- import { assert } from "./assert";
3
-
4
- export function calculateUnsafeDefaultLayout({
5
- panelDataArray,
6
- }: {
7
- panelDataArray: PanelData[];
8
- }): number[] {
9
- const layout = Array<number>(panelDataArray.length);
10
-
11
- const panelConstraintsArray = panelDataArray.map(
12
- (panelData) => panelData.constraints
13
- );
14
-
15
- let numPanelsWithSizes = 0;
16
- let remainingSize = 100;
17
-
18
- // Distribute default sizes first
19
- for (let index = 0; index < panelDataArray.length; index++) {
20
- const panelConstraints = panelConstraintsArray[index];
21
- assert(panelConstraints, `Panel constraints not found for index ${index}`);
22
- const { defaultSize } = panelConstraints;
23
-
24
- if (defaultSize != null) {
25
- numPanelsWithSizes++;
26
- layout[index] = defaultSize;
27
- remainingSize -= defaultSize;
28
- }
29
- }
30
-
31
- // Remaining size should be distributed evenly between panels without default sizes
32
- for (let index = 0; index < panelDataArray.length; index++) {
33
- const panelConstraints = panelConstraintsArray[index];
34
- assert(panelConstraints, `Panel constraints not found for index ${index}`);
35
- const { defaultSize } = panelConstraints;
36
-
37
- if (defaultSize != null) {
38
- continue;
39
- }
40
-
41
- const numRemainingPanels = panelDataArray.length - numPanelsWithSizes;
42
- const size = remainingSize / numRemainingPanels;
43
-
44
- numPanelsWithSizes++;
45
- layout[index] = size;
46
- remainingSize -= size;
47
- }
48
-
49
- return layout;
50
- }
@@ -1,49 +0,0 @@
1
- import { PanelData } from "../Panel";
2
- import { assert } from "./assert";
3
- import { fuzzyNumbersEqual } from "./numbers/fuzzyCompareNumbers";
4
-
5
- // Layout should be pre-converted into percentages
6
- export function callPanelCallbacks(
7
- panelsArray: PanelData[],
8
- layout: number[],
9
- panelIdToLastNotifiedSizeMap: Record<string, number>
10
- ) {
11
- layout.forEach((size, index) => {
12
- const panelData = panelsArray[index];
13
- assert(panelData, `Panel data not found for index ${index}`);
14
-
15
- const { callbacks, constraints, id: panelId } = panelData;
16
- const { collapsedSize = 0, collapsible } = constraints;
17
-
18
- const lastNotifiedSize = panelIdToLastNotifiedSizeMap[panelId];
19
- if (lastNotifiedSize == null || size !== lastNotifiedSize) {
20
- panelIdToLastNotifiedSizeMap[panelId] = size;
21
-
22
- const { onCollapse, onExpand, onResize } = callbacks;
23
-
24
- if (onResize) {
25
- onResize(size, lastNotifiedSize);
26
- }
27
-
28
- if (collapsible && (onCollapse || onExpand)) {
29
- if (
30
- onExpand &&
31
- (lastNotifiedSize == null ||
32
- fuzzyNumbersEqual(lastNotifiedSize, collapsedSize)) &&
33
- !fuzzyNumbersEqual(size, collapsedSize)
34
- ) {
35
- onExpand();
36
- }
37
-
38
- if (
39
- onCollapse &&
40
- (lastNotifiedSize == null ||
41
- !fuzzyNumbersEqual(lastNotifiedSize, collapsedSize)) &&
42
- fuzzyNumbersEqual(size, collapsedSize)
43
- ) {
44
- onCollapse();
45
- }
46
- }
47
- }
48
- });
49
- }
@@ -1,9 +0,0 @@
1
- import { compareLayouts } from "./compareLayouts";
2
-
3
- describe("compareLayouts", () => {
4
- it("should work", () => {
5
- expect(compareLayouts([1, 2], [1])).toBe(false);
6
- expect(compareLayouts([1], [1, 2])).toBe(false);
7
- expect(compareLayouts([1, 2, 3], [1, 2, 3])).toBe(true);
8
- });
9
- });
@@ -1,12 +0,0 @@
1
- export function compareLayouts(a: number[], b: number[]) {
2
- if (a.length !== b.length) {
3
- return false;
4
- } else {
5
- for (let index = 0; index < a.length; index++) {
6
- if (a[index] != b[index]) {
7
- return false;
8
- }
9
- }
10
- }
11
- return true;
12
- }
@@ -1,123 +0,0 @@
1
- import { PanelConstraints, PanelData } from "../Panel";
2
- import { computePanelFlexBoxStyle } from "./computePanelFlexBoxStyle";
3
-
4
- describe("computePanelFlexBoxStyle", () => {
5
- function createPanelData(constraints: PanelConstraints = {}): PanelData {
6
- return {
7
- callbacks: {},
8
- constraints,
9
- id: "fake",
10
- idIsFromProps: false,
11
- order: undefined,
12
- };
13
- }
14
-
15
- it("should observe a panel's default size if group layout has not yet been computed", () => {
16
- expect(
17
- computePanelFlexBoxStyle({
18
- defaultSize: 0.1233456789,
19
- dragState: null,
20
- layout: [],
21
- panelData: [
22
- createPanelData({
23
- defaultSize: 0.1233456789,
24
- }),
25
- createPanelData(),
26
- ],
27
- panelIndex: 0,
28
- precision: 2,
29
- })
30
- ).toMatchInlineSnapshot(`
31
- {
32
- "flexBasis": 0,
33
- "flexGrow": "0.12",
34
- "flexShrink": 1,
35
- "overflow": "hidden",
36
- "pointerEvents": undefined,
37
- }
38
- `);
39
- });
40
-
41
- it("should always fill the full width for single-panel groups", () => {
42
- expect(
43
- computePanelFlexBoxStyle({
44
- defaultSize: undefined,
45
- dragState: null,
46
- layout: [],
47
- panelData: [createPanelData()],
48
- panelIndex: 0,
49
- precision: 2,
50
- })
51
- ).toMatchInlineSnapshot(`
52
- {
53
- "flexBasis": 0,
54
- "flexGrow": "1",
55
- "flexShrink": 1,
56
- "overflow": "hidden",
57
- "pointerEvents": undefined,
58
- }
59
- `);
60
- });
61
-
62
- it("should round sizes to avoid floating point precision errors", () => {
63
- const layout = [0.25435, 0.5758, 0.1698];
64
- const panelData = [createPanelData(), createPanelData(), createPanelData()];
65
-
66
- expect(
67
- computePanelFlexBoxStyle({
68
- defaultSize: undefined,
69
- dragState: null,
70
- layout,
71
- panelData,
72
- panelIndex: 0,
73
- precision: 2,
74
- })
75
- ).toMatchInlineSnapshot(`
76
- {
77
- "flexBasis": 0,
78
- "flexGrow": "0.25",
79
- "flexShrink": 1,
80
- "overflow": "hidden",
81
- "pointerEvents": undefined,
82
- }
83
- `);
84
-
85
- expect(
86
- computePanelFlexBoxStyle({
87
- defaultSize: undefined,
88
- dragState: null,
89
- layout,
90
- panelData,
91
- panelIndex: 1,
92
- precision: 2,
93
- })
94
- ).toMatchInlineSnapshot(`
95
- {
96
- "flexBasis": 0,
97
- "flexGrow": "0.58",
98
- "flexShrink": 1,
99
- "overflow": "hidden",
100
- "pointerEvents": undefined,
101
- }
102
- `);
103
-
104
- expect(
105
- computePanelFlexBoxStyle({
106
- defaultSize: undefined,
107
- dragState: null,
108
- layout,
109
- panelData,
110
- panelIndex: 2,
111
- precision: 2,
112
- })
113
- ).toMatchInlineSnapshot(`
114
- {
115
- "flexBasis": 0,
116
- "flexGrow": "0.17",
117
- "flexShrink": 1,
118
- "overflow": "hidden",
119
- "pointerEvents": undefined,
120
- }
121
- `);
122
- });
123
- });
@@ -1,50 +0,0 @@
1
- // This method returns a number between 1 and 100 representing
2
-
3
- import { PanelData } from "../Panel";
4
- import { DragState } from "../PanelGroupContext";
5
- import { CSSProperties } from "../vendor/react";
6
-
7
- // the % of the group's overall space this panel should occupy.
8
- export function computePanelFlexBoxStyle({
9
- defaultSize,
10
- dragState,
11
- layout,
12
- panelData,
13
- panelIndex,
14
- precision = 3,
15
- }: {
16
- defaultSize: number | undefined;
17
- layout: number[];
18
- dragState: DragState | null;
19
- panelData: PanelData[];
20
- panelIndex: number;
21
- precision?: number;
22
- }): CSSProperties {
23
- const size = layout[panelIndex];
24
-
25
- let flexGrow;
26
- if (size == null) {
27
- // Initial render (before panels have registered themselves)
28
- // In order to support server rendering, fall back to default size if provided
29
- flexGrow =
30
- defaultSize != undefined ? defaultSize.toPrecision(precision) : "1";
31
- } else if (panelData.length === 1) {
32
- // Special case: Single panel group should always fill full width/height
33
- flexGrow = "1";
34
- } else {
35
- flexGrow = size.toPrecision(precision);
36
- }
37
-
38
- return {
39
- flexBasis: 0,
40
- flexGrow,
41
- flexShrink: 1,
42
-
43
- // Without this, Panel sizes may be unintentionally overridden by their content
44
- overflow: "hidden",
45
-
46
- // Disable pointer events inside of a panel during resize
47
- // This avoid edge cases like nested iframes
48
- pointerEvents: dragState !== null ? "none" : undefined,
49
- };
50
- }
package/src/utils/csp.ts DELETED
@@ -1,9 +0,0 @@
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
- }
@@ -1,103 +0,0 @@
1
- import {
2
- EXCEEDED_HORIZONTAL_MAX,
3
- EXCEEDED_HORIZONTAL_MIN,
4
- EXCEEDED_VERTICAL_MAX,
5
- EXCEEDED_VERTICAL_MIN,
6
- } from "../PanelResizeHandleRegistry";
7
- import { getNonce } from "./csp";
8
-
9
- type CursorState = "horizontal" | "intersection" | "vertical";
10
-
11
- let currentCursorStyle: string | null = null;
12
- let enabled: boolean = true;
13
- let styleElement: HTMLStyleElement | null = null;
14
-
15
- export function disableGlobalCursorStyles() {
16
- enabled = false;
17
- }
18
-
19
- export function enableGlobalCursorStyles() {
20
- enabled = true;
21
- }
22
-
23
- export function getCursorStyle(
24
- state: CursorState,
25
- constraintFlags: number
26
- ): string {
27
- if (constraintFlags) {
28
- const horizontalMin = (constraintFlags & EXCEEDED_HORIZONTAL_MIN) !== 0;
29
- const horizontalMax = (constraintFlags & EXCEEDED_HORIZONTAL_MAX) !== 0;
30
- const verticalMin = (constraintFlags & EXCEEDED_VERTICAL_MIN) !== 0;
31
- const verticalMax = (constraintFlags & EXCEEDED_VERTICAL_MAX) !== 0;
32
-
33
- if (horizontalMin) {
34
- if (verticalMin) {
35
- return "se-resize";
36
- } else if (verticalMax) {
37
- return "ne-resize";
38
- } else {
39
- return "e-resize";
40
- }
41
- } else if (horizontalMax) {
42
- if (verticalMin) {
43
- return "sw-resize";
44
- } else if (verticalMax) {
45
- return "nw-resize";
46
- } else {
47
- return "w-resize";
48
- }
49
- } else if (verticalMin) {
50
- return "s-resize";
51
- } else if (verticalMax) {
52
- return "n-resize";
53
- }
54
- }
55
-
56
- switch (state) {
57
- case "horizontal":
58
- return "ew-resize";
59
- case "intersection":
60
- return "move";
61
- case "vertical":
62
- return "ns-resize";
63
- }
64
- }
65
-
66
- export function resetGlobalCursorStyle() {
67
- if (styleElement !== null) {
68
- document.head.removeChild(styleElement);
69
-
70
- currentCursorStyle = null;
71
- styleElement = null;
72
- }
73
- }
74
-
75
- export function setGlobalCursorStyle(
76
- state: CursorState,
77
- constraintFlags: number
78
- ) {
79
- if (!enabled) {
80
- return;
81
- }
82
-
83
- const style = getCursorStyle(state, constraintFlags);
84
-
85
- if (currentCursorStyle === style) {
86
- return;
87
- }
88
-
89
- currentCursorStyle = style;
90
-
91
- if (styleElement === null) {
92
- styleElement = document.createElement("style");
93
-
94
- const nonce = getNonce();
95
- if (nonce) {
96
- styleElement.setAttribute("nonce", nonce);
97
- }
98
-
99
- document.head.appendChild(styleElement);
100
- }
101
-
102
- styleElement.innerHTML = `*{cursor: ${style}!important;}`;
103
- }
@@ -1,18 +0,0 @@
1
- export default function debounce<T extends Function>(
2
- callback: T,
3
- durationMs: number = 10
4
- ) {
5
- let timeoutId: NodeJS.Timeout | null = null;
6
-
7
- let callable = (...args: any) => {
8
- if (timeoutId !== null) {
9
- clearTimeout(timeoutId);
10
- }
11
-
12
- timeoutId = setTimeout(() => {
13
- callback(...args);
14
- }, durationMs);
15
- };
16
-
17
- return callable as unknown as T;
18
- }
@@ -1,15 +0,0 @@
1
- import { getResizeHandleElementIndex } from "../utils/dom/getResizeHandleElementIndex";
2
-
3
- export function determinePivotIndices(
4
- groupId: string,
5
- dragHandleId: string,
6
- panelGroupElement: ParentNode
7
- ): [indexBefore: number, indexAfter: number] {
8
- const index = getResizeHandleElementIndex(
9
- groupId,
10
- dragHandleId,
11
- panelGroupElement
12
- );
13
-
14
- return index != null ? [index, index + 1] : [-1, -1];
15
- }
@@ -1,10 +0,0 @@
1
- export function getPanelElement(
2
- id: string,
3
- scope: ParentNode | HTMLElement = document
4
- ): HTMLElement | null {
5
- const element = scope.querySelector(`[data-panel-id="${id}"]`);
6
- if (element) {
7
- return element as HTMLElement;
8
- }
9
- return null;
10
- }
@@ -1,8 +0,0 @@
1
- export function getPanelElementsForGroup(
2
- groupId: string,
3
- scope: ParentNode | HTMLElement = document
4
- ): HTMLElement[] {
5
- return Array.from(
6
- scope.querySelectorAll(`[data-panel][data-panel-group-id="${groupId}"]`)
7
- );
8
- }
@@ -1,21 +0,0 @@
1
- export function getPanelGroupElement(
2
- id: string,
3
- rootElement: ParentNode | HTMLElement = document
4
- ): HTMLElement | null {
5
- //If the root element is the PanelGroup
6
- if (
7
- rootElement instanceof HTMLElement &&
8
- (rootElement as HTMLElement)?.dataset?.panelGroupId == id
9
- ) {
10
- return rootElement as HTMLElement;
11
- }
12
-
13
- //Else query children
14
- const element = rootElement.querySelector(
15
- `[data-panel-group][data-panel-group-id="${id}"]`
16
- );
17
- if (element) {
18
- return element as HTMLElement;
19
- }
20
- return null;
21
- }
@@ -1,10 +0,0 @@
1
- export function getResizeHandleElement(
2
- id: string,
3
- scope: ParentNode | HTMLElement = document
4
- ): HTMLElement | null {
5
- const element = scope.querySelector(`[data-panel-resize-handle-id="${id}"]`);
6
- if (element) {
7
- return element as HTMLElement;
8
- }
9
- return null;
10
- }
@@ -1,13 +0,0 @@
1
- import { getResizeHandleElementsForGroup } from "./getResizeHandleElementsForGroup";
2
-
3
- export function getResizeHandleElementIndex(
4
- groupId: string,
5
- id: string,
6
- scope: ParentNode | HTMLElement = document
7
- ): number | null {
8
- const handles = getResizeHandleElementsForGroup(groupId, scope);
9
- const index = handles.findIndex(
10
- (handle) => handle.getAttribute("data-panel-resize-handle-id") === id
11
- );
12
- return index ?? null;
13
- }
@@ -1,10 +0,0 @@
1
- export function getResizeHandleElementsForGroup(
2
- groupId: string,
3
- scope: ParentNode | HTMLElement = document
4
- ): HTMLElement[] {
5
- return Array.from(
6
- scope.querySelectorAll(
7
- `[data-panel-resize-handle-id][data-panel-group-id="${groupId}"]`
8
- )
9
- );
10
- }
@@ -1,19 +0,0 @@
1
- import { PanelData } from "../../Panel";
2
- import { getResizeHandleElement } from "./getResizeHandleElement";
3
- import { getResizeHandleElementsForGroup } from "./getResizeHandleElementsForGroup";
4
-
5
- export function getResizeHandlePanelIds(
6
- groupId: string,
7
- handleId: string,
8
- panelsArray: PanelData[],
9
- scope: ParentNode | HTMLElement = document
10
- ): [idBefore: string | null, idAfter: string | null] {
11
- const handle = getResizeHandleElement(handleId, scope);
12
- const handles = getResizeHandleElementsForGroup(groupId, scope);
13
- const index = handle ? handles.indexOf(handle) : -1;
14
-
15
- const idBefore: string | null = panelsArray[index]?.id ?? null;
16
- const idAfter: string | null = panelsArray[index + 1]?.id ?? null;
17
-
18
- return [idBefore, idAfter];
19
- }
@@ -1,23 +0,0 @@
1
- import { ResizeEvent } from "../../types";
2
- import { isMouseEvent, isPointerEvent } from ".";
3
-
4
- export function getResizeEventCoordinates(event: ResizeEvent) {
5
- if (isPointerEvent(event)) {
6
- if (event.isPrimary) {
7
- return {
8
- x: event.clientX,
9
- y: event.clientY,
10
- };
11
- }
12
- } else if (isMouseEvent(event)) {
13
- return {
14
- x: event.clientX,
15
- y: event.clientY,
16
- };
17
- }
18
-
19
- return {
20
- x: Infinity,
21
- y: Infinity,
22
- };
23
- }
@@ -1,14 +0,0 @@
1
- import { ResizeEvent } from "../../PanelGroupContext";
2
- import { Direction } from "../../types";
3
- import { getResizeEventCoordinates } from "./getResizeEventCoordinates";
4
-
5
- export function getResizeEventCursorPosition(
6
- direction: Direction,
7
- event: ResizeEvent
8
- ): number {
9
- const isHorizontal = direction === "horizontal";
10
-
11
- const { x, y } = getResizeEventCoordinates(event);
12
-
13
- return isHorizontal ? x : y;
14
- }
@@ -1,13 +0,0 @@
1
- import { ResizeEvent } from "../../PanelGroupContext";
2
-
3
- export function isKeyDown(event: ResizeEvent): event is KeyboardEvent {
4
- return event.type === "keydown";
5
- }
6
-
7
- export function isPointerEvent(event: ResizeEvent): event is PointerEvent {
8
- return event.type.startsWith("pointer");
9
- }
10
-
11
- export function isMouseEvent(event: ResizeEvent): event is MouseEvent {
12
- return event.type.startsWith("mouse");
13
- }
@@ -1,5 +0,0 @@
1
- export function getInputType(): "coarse" | "fine" | undefined {
2
- if (typeof matchMedia === "function") {
3
- return matchMedia("(pointer:coarse)").matches ? "coarse" : "fine";
4
- }
5
- }
@@ -1,26 +0,0 @@
1
- import { PanelGroupStorage } from "../PanelGroup";
2
-
3
- // PanelGroup might be rendering in a server-side environment where localStorage is not available
4
- // or on a browser with cookies/storage disabled.
5
- // In either case, this function avoids accessing localStorage until needed,
6
- // and avoids throwing user-visible errors.
7
- export function initializeDefaultStorage(storageObject: PanelGroupStorage) {
8
- try {
9
- if (typeof localStorage !== "undefined") {
10
- // Bypass this check for future calls
11
- storageObject.getItem = (name: string) => {
12
- return localStorage.getItem(name);
13
- };
14
- storageObject.setItem = (name: string, value: string) => {
15
- localStorage.setItem(name, value);
16
- };
17
- } else {
18
- throw new Error("localStorage not supported in this environment");
19
- }
20
- } catch (error) {
21
- console.error(error);
22
-
23
- storageObject.getItem = () => null;
24
- storageObject.setItem = () => {};
25
- }
26
- }
@@ -1,16 +0,0 @@
1
- import { fuzzyCompareNumbers } from "./fuzzyCompareNumbers";
2
-
3
- describe("fuzzyCompareNumbers", () => {
4
- it("should return 0 when numbers are equal", () => {
5
- expect(fuzzyCompareNumbers(10.123, 10.123, 5)).toBe(0);
6
- });
7
-
8
- it("should return 0 when numbers are fuzzy equal", () => {
9
- expect(fuzzyCompareNumbers(0.000001, 0.000002, 5)).toBe(0);
10
- });
11
-
12
- it("should return a delta when numbers are not unequal", () => {
13
- expect(fuzzyCompareNumbers(0.000001, 0.000002, 6)).toBe(-1);
14
- expect(fuzzyCompareNumbers(0.000005, 0.000002, 6)).toBe(1);
15
- });
16
- });
@@ -1,21 +0,0 @@
1
- import { PRECISION } from "../../constants";
2
-
3
- export function fuzzyCompareNumbers(
4
- actual: number,
5
- expected: number,
6
- fractionDigits: number = PRECISION
7
- ): number {
8
- if (actual.toFixed(fractionDigits) === expected.toFixed(fractionDigits)) {
9
- return 0;
10
- } else {
11
- return actual > expected ? 1 : -1;
12
- }
13
- }
14
-
15
- export function fuzzyNumbersEqual(
16
- actual: number,
17
- expected: number,
18
- fractionDigits: number = PRECISION
19
- ): boolean {
20
- return fuzzyCompareNumbers(actual, expected, fractionDigits) === 0;
21
- }