@gfazioli/mantine-split-pane 1.1.7 → 2.1.0
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.
- package/README.md +4 -2
- package/dist/cjs/Pane/SplitPane.cjs +108 -91
- package/dist/cjs/Pane/SplitPane.cjs.map +1 -1
- package/dist/cjs/Resizer/SplitPaneResizer.cjs +292 -111
- package/dist/cjs/Resizer/SplitPaneResizer.cjs.map +1 -1
- package/dist/cjs/Split.cjs +30 -16
- package/dist/cjs/Split.cjs.map +1 -1
- package/dist/cjs/Split.context.cjs +1 -4
- package/dist/cjs/Split.context.cjs.map +1 -1
- package/dist/cjs/index.cjs +2 -6
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/Pane/SplitPane.mjs +109 -92
- package/dist/esm/Pane/SplitPane.mjs.map +1 -1
- package/dist/esm/Resizer/SplitPaneResizer.mjs +293 -113
- package/dist/esm/Resizer/SplitPaneResizer.mjs.map +1 -1
- package/dist/esm/Split.context.mjs +2 -5
- package/dist/esm/Split.context.mjs.map +1 -1
- package/dist/esm/Split.mjs +31 -17
- package/dist/esm/Split.mjs.map +1 -1
- package/dist/esm/index.mjs +1 -3
- package/dist/esm/index.mjs.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/styles.layer.css +1 -1
- package/dist/types/Pane/SplitPane.d.ts +40 -6
- package/dist/types/Resizer/SplitPaneResizer.d.ts +35 -21
- package/dist/types/Split.context.d.ts +4 -2
- package/dist/types/Split.d.ts +5 -3
- package/dist/types/index.d.mts +4 -6
- package/dist/types/index.d.ts +4 -6
- package/package.json +1 -1
- package/dist/cjs/Split.errors.cjs +0 -8
- package/dist/cjs/Split.errors.cjs.map +0 -1
- package/dist/esm/Split.errors.mjs +0 -6
- package/dist/esm/Split.errors.mjs.map +0 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import React, { useRef } from 'react';
|
|
3
|
-
import { createVarsResolver,
|
|
3
|
+
import { createVarsResolver, getSize, getRadius, parseThemeColor, getGradient, factory, useProps, useStyles, UnstyledButton } from '@mantine/core';
|
|
4
|
+
import { useSplitContext } from '../Split.context.mjs';
|
|
4
5
|
import classes from './SplitPaneResizer.module.css.mjs';
|
|
5
6
|
|
|
6
7
|
const varsResolver = createVarsResolver(
|
|
@@ -20,40 +21,35 @@ const varsResolver = createVarsResolver(
|
|
|
20
21
|
spacing,
|
|
21
22
|
variant,
|
|
22
23
|
cursorVertical,
|
|
23
|
-
cursorHorizontal
|
|
24
|
+
cursorHorizontal,
|
|
25
|
+
gradient,
|
|
26
|
+
hoverGradient
|
|
24
27
|
}) => {
|
|
25
|
-
const colorDarkParsed = parseThemeColor({
|
|
26
|
-
color: color || "dark.5",
|
|
27
|
-
theme
|
|
28
|
-
});
|
|
29
|
-
const colorLightParsed = parseThemeColor({
|
|
30
|
-
color: color || "gray.3",
|
|
31
|
-
theme
|
|
32
|
-
});
|
|
33
|
-
const hoverColorDarkParsed = parseThemeColor({
|
|
34
|
-
color: hoverColor || "dark.3",
|
|
35
|
-
theme
|
|
36
|
-
});
|
|
37
|
-
const hoverColorLightParsed = parseThemeColor({
|
|
38
|
-
color: hoverColor || "gray.4",
|
|
39
|
-
theme
|
|
40
|
-
});
|
|
41
28
|
const knobVariant = variant === "dotted" || variant === "dashed";
|
|
29
|
+
const forceKnobOpacityValue = withKnob && knobAlwaysOn && !knobVariant ? knobOpacity : "0";
|
|
30
|
+
const colors = variantColorResolver({
|
|
31
|
+
color,
|
|
32
|
+
hover: hoverColor,
|
|
33
|
+
knob: knobColor,
|
|
34
|
+
hoverKnob: knobHoverColor,
|
|
35
|
+
theme,
|
|
36
|
+
gradient,
|
|
37
|
+
hoverGradient,
|
|
38
|
+
variant: variant || "filled"
|
|
39
|
+
});
|
|
42
40
|
return {
|
|
43
41
|
root: {
|
|
44
42
|
"--split-resizer-size": getSize(size, "split-resizer-size"),
|
|
45
|
-
"--split-resizer-color":
|
|
46
|
-
"--split-resizer-color
|
|
47
|
-
"--split-resizer-color-dark": rgba(colorDarkParsed.value, Number(opacity)),
|
|
48
|
-
"--split-resizer-hover-color-light": rgba(hoverColorLightParsed.value, 1),
|
|
49
|
-
"--split-resizer-hover-color-dark": rgba(hoverColorDarkParsed.value, 1),
|
|
43
|
+
"--split-resizer-color": colors.color,
|
|
44
|
+
"--split-resizer-hover-color": colors.hover,
|
|
50
45
|
"--split-resizer-radius": getRadius(radius),
|
|
46
|
+
"--split-resizer-opacity": opacity !== void 0 ? opacity : "1",
|
|
51
47
|
"--split-resizer-knob-size": getSize(knobSize, "split-resizer-knob-size"),
|
|
52
|
-
"--split-resizer-knob-opacity":
|
|
48
|
+
"--split-resizer-knob-opacity": forceKnobOpacityValue,
|
|
53
49
|
"--split-resizer-knob-hover-opacity": withKnob || knobVariant ? "1" : "0",
|
|
54
50
|
"--split-resizer-knob-radius": getRadius(knobRadius),
|
|
55
|
-
"--split-resizer-knob-color":
|
|
56
|
-
"--split-resizer-knob-hover-color":
|
|
51
|
+
"--split-resizer-knob-color": colors.knob,
|
|
52
|
+
"--split-resizer-knob-hover-color": colors.hoverKnob,
|
|
57
53
|
"--split-resizer-spacing": getSize(spacing, "split-resizer-spacing"),
|
|
58
54
|
"--split-resizer-cursor-vertical": cursorVertical || "col-resize",
|
|
59
55
|
"--split-resizer-cursor-horizontal": cursorHorizontal || "row-resize"
|
|
@@ -61,56 +57,79 @@ const varsResolver = createVarsResolver(
|
|
|
61
57
|
};
|
|
62
58
|
}
|
|
63
59
|
);
|
|
60
|
+
const variantColorResolver = ({
|
|
61
|
+
color,
|
|
62
|
+
hover,
|
|
63
|
+
knob,
|
|
64
|
+
hoverKnob,
|
|
65
|
+
theme,
|
|
66
|
+
variant,
|
|
67
|
+
gradient,
|
|
68
|
+
hoverGradient
|
|
69
|
+
}) => {
|
|
70
|
+
const parsedColor = color ? parseThemeColor({ color, theme }).value : void 0;
|
|
71
|
+
const parsedHover = hover ? parseThemeColor({ color: hover, theme }).value : void 0;
|
|
72
|
+
const parsedKnob = knob ? parseThemeColor({ color: knob, theme }).value : void 0;
|
|
73
|
+
const parsedHoverKnob = hoverKnob ? parseThemeColor({ color: hoverKnob, theme }).value : void 0;
|
|
74
|
+
const colors = {
|
|
75
|
+
color: parsedColor,
|
|
76
|
+
hover: parsedHover,
|
|
77
|
+
knob: parsedKnob,
|
|
78
|
+
hoverKnob: parsedHoverKnob
|
|
79
|
+
};
|
|
80
|
+
if (variant === "gradient") {
|
|
81
|
+
colors.color = getGradient(gradient, theme);
|
|
82
|
+
colors.hover = getGradient(hoverGradient || gradient, theme);
|
|
83
|
+
}
|
|
84
|
+
return colors;
|
|
85
|
+
};
|
|
64
86
|
const defaultProps = {
|
|
65
|
-
|
|
87
|
+
orientation: "vertical",
|
|
66
88
|
opacity: 0.8,
|
|
89
|
+
size: "sm",
|
|
67
90
|
radius: "xs",
|
|
68
|
-
|
|
91
|
+
withKnob: false,
|
|
92
|
+
knobAlwaysOn: true,
|
|
69
93
|
knobSize: "sm",
|
|
70
94
|
knobOpacity: 0.5,
|
|
71
95
|
knobRadius: "sm",
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
paneRef: { current: null },
|
|
76
|
-
variant: "default",
|
|
77
|
-
withKnob: false,
|
|
78
|
-
knobAlwaysOn: true,
|
|
96
|
+
knobColor: "white",
|
|
97
|
+
knobHoverColor: "white",
|
|
98
|
+
spacing: "xs",
|
|
79
99
|
step: 8,
|
|
80
100
|
shiftStep: 64,
|
|
81
101
|
cursorVertical: "col-resize",
|
|
82
102
|
cursorHorizontal: "row-resize"
|
|
83
103
|
};
|
|
84
|
-
const SplitPaneResizer = factory((_props,
|
|
85
|
-
const
|
|
104
|
+
const SplitPaneResizer = factory((_props, _) => {
|
|
105
|
+
const ctx = useSplitContext();
|
|
106
|
+
const props = useProps("SplitPaneResizer", { ...defaultProps, ...ctx }, _props);
|
|
86
107
|
const {
|
|
87
|
-
|
|
108
|
+
orientation,
|
|
88
109
|
opacity,
|
|
110
|
+
size,
|
|
89
111
|
radius,
|
|
90
|
-
|
|
91
|
-
|
|
112
|
+
withKnob,
|
|
113
|
+
knobAlwaysOn,
|
|
92
114
|
knobSize,
|
|
93
115
|
knobOpacity,
|
|
94
116
|
knobRadius,
|
|
95
117
|
knobColor,
|
|
96
118
|
knobHoverColor,
|
|
97
|
-
minWidth,
|
|
98
|
-
minHeight,
|
|
99
|
-
maxWidth,
|
|
100
|
-
maxHeight,
|
|
101
|
-
orientation,
|
|
102
|
-
onResizeStart,
|
|
103
|
-
onResizing,
|
|
104
|
-
onResizeEnd,
|
|
105
|
-
paneRef,
|
|
106
|
-
variant,
|
|
107
|
-
withKnob,
|
|
108
|
-
knobAlwaysOn,
|
|
109
119
|
spacing,
|
|
110
120
|
step,
|
|
111
121
|
shiftStep,
|
|
112
122
|
cursorVertical,
|
|
113
123
|
cursorHorizontal,
|
|
124
|
+
color,
|
|
125
|
+
hoverColor,
|
|
126
|
+
variant,
|
|
127
|
+
onResizeStart,
|
|
128
|
+
onResizing,
|
|
129
|
+
onResizeEnd,
|
|
130
|
+
onDoubleClick,
|
|
131
|
+
__beforeRef: beforeRef,
|
|
132
|
+
__afterRef: afterRef,
|
|
114
133
|
className,
|
|
115
134
|
style,
|
|
116
135
|
classNames,
|
|
@@ -118,7 +137,7 @@ const SplitPaneResizer = factory((_props, ref) => {
|
|
|
118
137
|
unstyled,
|
|
119
138
|
vars,
|
|
120
139
|
mod,
|
|
121
|
-
...
|
|
140
|
+
...rest
|
|
122
141
|
} = props;
|
|
123
142
|
const getStyles = useStyles({
|
|
124
143
|
name: "SplitPaneResizer",
|
|
@@ -133,6 +152,150 @@ const SplitPaneResizer = factory((_props, ref) => {
|
|
|
133
152
|
varsResolver
|
|
134
153
|
});
|
|
135
154
|
const containerRef = useRef(null);
|
|
155
|
+
const processVerticalSize = (deltaX = 0) => {
|
|
156
|
+
const minBeforeWidth = beforeRef.current.getMinWidth();
|
|
157
|
+
const maxBeforeWidth = beforeRef.current.getMaxWidth();
|
|
158
|
+
const minAfterWidth = afterRef.current.getMinWidth();
|
|
159
|
+
const maxAfterWidth = afterRef.current.getMaxWidth();
|
|
160
|
+
const beforePane = beforeRef.current.splitPane;
|
|
161
|
+
const afterPane = afterRef.current.splitPane;
|
|
162
|
+
let beforeWidth = beforePane.getBoundingClientRect().width;
|
|
163
|
+
let afterWidth = afterPane.getBoundingClientRect().width;
|
|
164
|
+
const isBeforeWidthMaxExceeded = maxBeforeWidth && beforeWidth + deltaX > maxBeforeWidth;
|
|
165
|
+
const isAfterWidthMaxExceeded = maxAfterWidth && afterWidth - deltaX > maxAfterWidth;
|
|
166
|
+
const isBeforeWidthMinExceeded = minBeforeWidth && beforeWidth + deltaX < minBeforeWidth;
|
|
167
|
+
const isAfterWidthMinExceeded = minAfterWidth && afterWidth - deltaX < minAfterWidth;
|
|
168
|
+
const isBeforeWidthNegative = beforeWidth + deltaX < 0;
|
|
169
|
+
const isAfterWidthNegative = afterWidth - deltaX < 0;
|
|
170
|
+
function setVerticalSize() {
|
|
171
|
+
const beforeWidthString = `${beforeWidth}px`;
|
|
172
|
+
const afterWidthString = `${afterWidth}px`;
|
|
173
|
+
const beforePaneSizes = {
|
|
174
|
+
width: beforeWidth,
|
|
175
|
+
height: beforePane.getBoundingClientRect().height
|
|
176
|
+
};
|
|
177
|
+
const afterPaneSizes = {
|
|
178
|
+
width: afterWidth,
|
|
179
|
+
height: afterPane.getBoundingClientRect().height
|
|
180
|
+
};
|
|
181
|
+
beforeRef.current.onResizing?.(beforePaneSizes);
|
|
182
|
+
afterRef.current.onResizing?.(afterPaneSizes);
|
|
183
|
+
onResizing?.({
|
|
184
|
+
beforePane: beforePaneSizes,
|
|
185
|
+
afterPane: afterPaneSizes
|
|
186
|
+
});
|
|
187
|
+
beforePane.style.width = beforeWidthString;
|
|
188
|
+
afterPane.style.width = afterWidthString;
|
|
189
|
+
}
|
|
190
|
+
if (!isAfterWidthMaxExceeded && isBeforeWidthMinExceeded) {
|
|
191
|
+
afterWidth += beforeWidth - minBeforeWidth;
|
|
192
|
+
beforeWidth = minBeforeWidth;
|
|
193
|
+
return setVerticalSize();
|
|
194
|
+
}
|
|
195
|
+
if (!isAfterWidthMaxExceeded && isBeforeWidthNegative) {
|
|
196
|
+
afterWidth += beforeWidth;
|
|
197
|
+
beforeWidth = 0;
|
|
198
|
+
return setVerticalSize();
|
|
199
|
+
}
|
|
200
|
+
if (!isAfterWidthMinExceeded && !isAfterWidthNegative && isBeforeWidthMaxExceeded) {
|
|
201
|
+
afterWidth -= maxBeforeWidth - beforeWidth;
|
|
202
|
+
beforeWidth = maxBeforeWidth;
|
|
203
|
+
return setVerticalSize();
|
|
204
|
+
}
|
|
205
|
+
if (!isBeforeWidthMaxExceeded && isAfterWidthMinExceeded) {
|
|
206
|
+
beforeWidth += afterWidth - minAfterWidth;
|
|
207
|
+
afterWidth = minAfterWidth;
|
|
208
|
+
return setVerticalSize();
|
|
209
|
+
}
|
|
210
|
+
if (!isBeforeWidthMaxExceeded && isAfterWidthNegative) {
|
|
211
|
+
beforeWidth += afterWidth;
|
|
212
|
+
afterWidth = 0;
|
|
213
|
+
return setVerticalSize();
|
|
214
|
+
}
|
|
215
|
+
if (!isBeforeWidthMinExceeded && !isBeforeWidthNegative && isAfterWidthMaxExceeded) {
|
|
216
|
+
beforeWidth -= maxAfterWidth - afterWidth;
|
|
217
|
+
afterWidth = maxAfterWidth;
|
|
218
|
+
return setVerticalSize();
|
|
219
|
+
}
|
|
220
|
+
if (isBeforeWidthNegative || isAfterWidthNegative || isBeforeWidthMaxExceeded || isAfterWidthMaxExceeded || isBeforeWidthMinExceeded || isAfterWidthMinExceeded) {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
beforeWidth += deltaX;
|
|
224
|
+
afterWidth -= deltaX;
|
|
225
|
+
setVerticalSize();
|
|
226
|
+
};
|
|
227
|
+
const processHorizontalSize = (deltaY = 0) => {
|
|
228
|
+
const minBeforeHeight = beforeRef.current.getMinHeight();
|
|
229
|
+
const maxBeforeHeight = beforeRef.current.getMaxHeight();
|
|
230
|
+
const minAfterHeight = afterRef.current.getMinHeight();
|
|
231
|
+
const maxAfterHeight = afterRef.current.getMaxHeight();
|
|
232
|
+
const beforePane = beforeRef.current.splitPane;
|
|
233
|
+
const afterPane = afterRef.current.splitPane;
|
|
234
|
+
let beforeHeight = beforePane.getBoundingClientRect().height;
|
|
235
|
+
let afterHeight = afterPane.getBoundingClientRect().height;
|
|
236
|
+
const isBeforeHeightMaxExceeded = maxBeforeHeight && beforeHeight + deltaY > maxBeforeHeight;
|
|
237
|
+
const isAfterHeightMaxExceeded = maxAfterHeight && afterHeight - deltaY > maxAfterHeight;
|
|
238
|
+
const isBeforeHeightMinExceeded = minBeforeHeight && beforeHeight + deltaY < minBeforeHeight;
|
|
239
|
+
const isAfterHeightMinExceeded = minAfterHeight && afterHeight - deltaY < minAfterHeight;
|
|
240
|
+
const isBeforeHeightNegative = beforeHeight + deltaY < 0;
|
|
241
|
+
const isAfterHeightNegative = afterHeight - deltaY < 0;
|
|
242
|
+
function setHorizontalSize() {
|
|
243
|
+
const beforeHeightString = `${beforeHeight}px`;
|
|
244
|
+
const afterHeightString = `${afterHeight}px`;
|
|
245
|
+
const beforePaneSizes = {
|
|
246
|
+
width: beforePane.getBoundingClientRect().width,
|
|
247
|
+
height: beforeHeight
|
|
248
|
+
};
|
|
249
|
+
const afterPaneSizes = {
|
|
250
|
+
width: afterPane.getBoundingClientRect().width,
|
|
251
|
+
height: afterHeight
|
|
252
|
+
};
|
|
253
|
+
onResizing?.({
|
|
254
|
+
beforePane: beforePaneSizes,
|
|
255
|
+
afterPane: afterPaneSizes
|
|
256
|
+
});
|
|
257
|
+
beforeRef.current.onResizing?.(beforePaneSizes);
|
|
258
|
+
afterRef.current.onResizing?.(afterPaneSizes);
|
|
259
|
+
beforePane.style.height = beforeHeightString;
|
|
260
|
+
afterPane.style.height = afterHeightString;
|
|
261
|
+
}
|
|
262
|
+
if (!isAfterHeightMaxExceeded && isBeforeHeightMinExceeded) {
|
|
263
|
+
afterHeight += beforeHeight - minBeforeHeight;
|
|
264
|
+
beforeHeight = minBeforeHeight;
|
|
265
|
+
return setHorizontalSize();
|
|
266
|
+
}
|
|
267
|
+
if (!isAfterHeightMaxExceeded && isBeforeHeightNegative) {
|
|
268
|
+
afterHeight += beforeHeight;
|
|
269
|
+
beforeHeight = 0;
|
|
270
|
+
return setHorizontalSize();
|
|
271
|
+
}
|
|
272
|
+
if (!isAfterHeightMinExceeded && !isAfterHeightNegative && isBeforeHeightMaxExceeded) {
|
|
273
|
+
afterHeight -= maxBeforeHeight - beforeHeight;
|
|
274
|
+
beforeHeight = maxBeforeHeight;
|
|
275
|
+
return setHorizontalSize();
|
|
276
|
+
}
|
|
277
|
+
if (!isBeforeHeightMaxExceeded && isAfterHeightMinExceeded) {
|
|
278
|
+
beforeHeight += afterHeight - minAfterHeight;
|
|
279
|
+
afterHeight = minAfterHeight;
|
|
280
|
+
return setHorizontalSize();
|
|
281
|
+
}
|
|
282
|
+
if (!isBeforeHeightMaxExceeded && isAfterHeightNegative) {
|
|
283
|
+
beforeHeight += afterHeight;
|
|
284
|
+
afterHeight = 0;
|
|
285
|
+
return setHorizontalSize();
|
|
286
|
+
}
|
|
287
|
+
if (!isBeforeHeightMinExceeded && !isBeforeHeightNegative && isAfterHeightMaxExceeded) {
|
|
288
|
+
beforeHeight -= maxAfterHeight - afterHeight;
|
|
289
|
+
afterHeight = maxAfterHeight;
|
|
290
|
+
return setHorizontalSize();
|
|
291
|
+
}
|
|
292
|
+
if (isBeforeHeightNegative || isAfterHeightNegative || isBeforeHeightMaxExceeded || isAfterHeightMaxExceeded || isBeforeHeightMinExceeded || isAfterHeightMinExceeded) {
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
beforeHeight += deltaY;
|
|
296
|
+
afterHeight -= deltaY;
|
|
297
|
+
setHorizontalSize();
|
|
298
|
+
};
|
|
136
299
|
const handleStart = (event) => {
|
|
137
300
|
event.preventDefault();
|
|
138
301
|
event.stopPropagation();
|
|
@@ -147,115 +310,132 @@ const SplitPaneResizer = factory((_props, ref) => {
|
|
|
147
310
|
document.addEventListener("touchend", handleTouchEnd);
|
|
148
311
|
}
|
|
149
312
|
onResizeStart?.();
|
|
150
|
-
|
|
313
|
+
beforeRef.current.onResizeStart?.();
|
|
314
|
+
afterRef.current.onResizeStart?.();
|
|
315
|
+
document.body.style.cursor = orientation === "vertical" ? cursorVertical : cursorHorizontal;
|
|
151
316
|
};
|
|
152
317
|
const handleMove = (event) => {
|
|
153
|
-
if (!
|
|
318
|
+
if (!beforeRef.current || !afterRef.current) {
|
|
319
|
+
throw new Error("beforeRef or afterRef is not defined");
|
|
320
|
+
}
|
|
154
321
|
event.preventDefault();
|
|
155
322
|
event.stopPropagation();
|
|
156
323
|
const computedStyle = window.getComputedStyle(containerRef.current);
|
|
157
|
-
const clientX = "clientX" in event ? event.clientX : event.touches[0].clientX;
|
|
158
|
-
const clientY = "clientY" in event ? event.clientY : event.touches[0].clientY;
|
|
159
324
|
if (orientation === "vertical") {
|
|
160
|
-
const
|
|
161
|
-
const
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
paneRef.current.style.width = widthString;
|
|
171
|
-
} else {
|
|
172
|
-
const margin = parseFloat(computedStyle.getPropertyValue("margin-top")) + 1;
|
|
173
|
-
const delta = clientY - paneRef.current.getBoundingClientRect().bottom - margin;
|
|
174
|
-
const height = paneRef.current.getBoundingClientRect().height + delta;
|
|
175
|
-
const heightString = `${height}px`;
|
|
176
|
-
if (minHeight && height < minHeight) return;
|
|
177
|
-
if (maxHeight && height > maxHeight) return;
|
|
178
|
-
onResizing?.({
|
|
179
|
-
width: paneRef.current.style.width,
|
|
180
|
-
height: heightString
|
|
181
|
-
});
|
|
182
|
-
paneRef.current.style.height = heightString;
|
|
325
|
+
const size2 = parseFloat(computedStyle.getPropertyValue("width"));
|
|
326
|
+
const clientX = "clientX" in event ? event.clientX : event.touches[0].clientX;
|
|
327
|
+
const deltaX = clientX - containerRef.current.getBoundingClientRect().left - size2 / 2;
|
|
328
|
+
return processVerticalSize(deltaX);
|
|
329
|
+
}
|
|
330
|
+
if (orientation === "horizontal") {
|
|
331
|
+
const size2 = parseFloat(computedStyle.getPropertyValue("height"));
|
|
332
|
+
const clientY = "clientY" in event ? event.clientY : event.touches[0].clientY;
|
|
333
|
+
const deltaY = clientY - containerRef.current.getBoundingClientRect().top - size2 / 2;
|
|
334
|
+
return processHorizontalSize(deltaY);
|
|
183
335
|
}
|
|
184
336
|
};
|
|
185
337
|
const handleMouseUp = () => {
|
|
186
|
-
if (!
|
|
338
|
+
if (!beforeRef.current || !afterRef.current) {
|
|
339
|
+
throw new Error("beforeRef or afterRef is not defined");
|
|
340
|
+
}
|
|
187
341
|
document.body.style.userSelect = "initial";
|
|
188
342
|
document.body.style.webkitUserSelect = "initial";
|
|
189
343
|
document.removeEventListener("mousemove", handleMove);
|
|
190
344
|
document.removeEventListener("mouseup", handleMouseUp);
|
|
191
345
|
document.body.style.cursor = "initial";
|
|
192
|
-
const
|
|
193
|
-
|
|
346
|
+
const beforePane = beforeRef.current.splitPane;
|
|
347
|
+
const afterPane = afterRef.current.splitPane;
|
|
348
|
+
const beforePaneSizes = {
|
|
349
|
+
width: beforePane.getBoundingClientRect().width,
|
|
350
|
+
height: beforePane.getBoundingClientRect().height
|
|
351
|
+
};
|
|
352
|
+
const afterPaneSizes = {
|
|
353
|
+
width: afterPane.getBoundingClientRect().width,
|
|
354
|
+
height: afterPane.getBoundingClientRect().height
|
|
355
|
+
};
|
|
356
|
+
onResizeEnd?.({
|
|
357
|
+
beforePane: beforePaneSizes,
|
|
358
|
+
afterPane: afterPaneSizes
|
|
359
|
+
});
|
|
360
|
+
beforeRef.current.onResizeEnd?.(beforePaneSizes);
|
|
361
|
+
afterRef.current.onResizeEnd?.(afterPaneSizes);
|
|
194
362
|
};
|
|
195
363
|
const handleTouchEnd = () => {
|
|
196
|
-
if (!
|
|
364
|
+
if (!beforeRef.current || !afterRef.current) {
|
|
365
|
+
throw new Error("beforeRef or afterRef is not defined");
|
|
366
|
+
}
|
|
197
367
|
document.removeEventListener("touchmove", handleMove);
|
|
198
368
|
document.removeEventListener("touchend", handleTouchEnd);
|
|
199
369
|
document.body.style.cursor = "initial";
|
|
200
|
-
const
|
|
201
|
-
|
|
370
|
+
const beforePane = beforeRef.current.splitPane;
|
|
371
|
+
const afterPane = afterRef.current.splitPane;
|
|
372
|
+
const beforePaneSizes = {
|
|
373
|
+
width: beforePane.getBoundingClientRect().width,
|
|
374
|
+
height: beforePane.getBoundingClientRect().height
|
|
375
|
+
};
|
|
376
|
+
const afterPaneSizes = {
|
|
377
|
+
width: afterPane.getBoundingClientRect().width,
|
|
378
|
+
height: afterPane.getBoundingClientRect().height
|
|
379
|
+
};
|
|
380
|
+
onResizeEnd?.({
|
|
381
|
+
beforePane: beforePaneSizes,
|
|
382
|
+
afterPane: afterPaneSizes
|
|
383
|
+
});
|
|
384
|
+
beforeRef.current.onResizeEnd?.(beforePaneSizes);
|
|
385
|
+
afterRef.current.onResizeEnd?.(afterPaneSizes);
|
|
202
386
|
};
|
|
203
387
|
const handleKeyUp = (event) => {
|
|
204
388
|
if (containerRef.current !== document.activeElement) {
|
|
205
389
|
return;
|
|
206
390
|
}
|
|
391
|
+
const code = event.nativeEvent.code;
|
|
392
|
+
const arrowLeftRight = code === "ArrowRight" || code === "ArrowLeft";
|
|
393
|
+
const arrowUpDown = code === "ArrowUp" || code === "ArrowDown";
|
|
207
394
|
const delta = event.shiftKey ? shiftStep : step;
|
|
208
|
-
if (orientation === "vertical" &&
|
|
395
|
+
if (orientation === "vertical" && arrowLeftRight) {
|
|
209
396
|
event.preventDefault();
|
|
210
397
|
event.stopPropagation();
|
|
211
|
-
const deltaSign =
|
|
212
|
-
const
|
|
213
|
-
|
|
214
|
-
if (minWidth && width < minWidth) return;
|
|
215
|
-
if (maxWidth && width > maxWidth) return;
|
|
216
|
-
onResizing?.({
|
|
217
|
-
width: widthString,
|
|
218
|
-
height: paneRef.current.style.height
|
|
219
|
-
});
|
|
220
|
-
paneRef.current.style.width = widthString;
|
|
398
|
+
const deltaSign = code === "ArrowRight" ? 1 : -1;
|
|
399
|
+
const deltaX = delta * deltaSign;
|
|
400
|
+
return processVerticalSize(deltaX);
|
|
221
401
|
}
|
|
222
|
-
if (orientation === "horizontal" &&
|
|
402
|
+
if (orientation === "horizontal" && arrowUpDown) {
|
|
223
403
|
event.preventDefault();
|
|
224
404
|
event.stopPropagation();
|
|
225
|
-
const deltaSign =
|
|
226
|
-
const
|
|
227
|
-
|
|
228
|
-
if (minHeight && height < minHeight) return;
|
|
229
|
-
if (maxHeight && height > maxHeight) return;
|
|
230
|
-
onResizing?.({
|
|
231
|
-
width: paneRef.current.style.width,
|
|
232
|
-
height: heightString
|
|
233
|
-
});
|
|
234
|
-
paneRef.current.style.height = heightString;
|
|
405
|
+
const deltaSign = code === "ArrowDown" ? 1 : -1;
|
|
406
|
+
const deltaY = delta * deltaSign;
|
|
407
|
+
return processHorizontalSize(deltaY);
|
|
235
408
|
}
|
|
236
|
-
if (
|
|
409
|
+
if (code === "Escape") {
|
|
237
410
|
event.preventDefault();
|
|
238
411
|
event.stopPropagation();
|
|
239
412
|
containerRef.current.blur();
|
|
240
413
|
}
|
|
241
414
|
};
|
|
415
|
+
const handleDoubleClick = (e) => {
|
|
416
|
+
e.preventDefault();
|
|
417
|
+
e.stopPropagation();
|
|
418
|
+
beforeRef.current.resetInitialSize(e);
|
|
419
|
+
afterRef.current.resetInitialSize(e);
|
|
420
|
+
onDoubleClick?.(e);
|
|
421
|
+
};
|
|
242
422
|
return /* @__PURE__ */ React.createElement(
|
|
243
423
|
UnstyledButton,
|
|
244
424
|
{
|
|
245
|
-
onDoubleClick: props?.onDoubleClick,
|
|
246
425
|
ref: containerRef,
|
|
247
426
|
mod: { orientation },
|
|
248
427
|
onMouseDown: handleStart,
|
|
249
428
|
onKeyDown: handleKeyUp,
|
|
250
429
|
onTouchStart: handleStart,
|
|
430
|
+
onDoubleClick: handleDoubleClick,
|
|
251
431
|
"aria-label": "Resize",
|
|
252
|
-
...getStyles("root", { variant }),
|
|
253
|
-
...
|
|
432
|
+
...getStyles("root", { variant: variant || "default" }),
|
|
433
|
+
...rest
|
|
254
434
|
}
|
|
255
435
|
);
|
|
256
436
|
});
|
|
257
437
|
SplitPaneResizer.classes = classes;
|
|
258
438
|
SplitPaneResizer.displayName = "SplitPaneResizer";
|
|
259
439
|
|
|
260
|
-
export { SplitPaneResizer };
|
|
440
|
+
export { SplitPaneResizer, defaultProps };
|
|
261
441
|
//# sourceMappingURL=SplitPaneResizer.mjs.map
|