@gfazioli/mantine-split-pane 2.7.3 → 4.0.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 +2 -1
- package/dist/cjs/Dynamic/SplitDynamic.cjs.map +1 -1
- package/dist/cjs/Pane/SplitPane.cjs +160 -50
- package/dist/cjs/Pane/SplitPane.cjs.map +1 -1
- package/dist/cjs/Resizer/SplitResizer.cjs +56 -33
- package/dist/cjs/Resizer/SplitResizer.cjs.map +1 -1
- package/dist/cjs/Split.cjs +32 -11
- package/dist/cjs/Split.cjs.map +1 -1
- package/dist/cjs/Split.context.cjs +3 -1
- package/dist/cjs/Split.context.cjs.map +1 -1
- package/dist/cjs/hooks/use-responsive-value.cjs +19 -0
- package/dist/cjs/hooks/use-responsive-value.cjs.map +1 -0
- package/dist/cjs/hooks/use-split-resizer-orientation.cjs +2 -6
- package/dist/cjs/hooks/use-split-resizer-orientation.cjs.map +1 -1
- package/dist/esm/Dynamic/SplitDynamic.mjs.map +1 -1
- package/dist/esm/Pane/SplitPane.mjs +164 -54
- package/dist/esm/Pane/SplitPane.mjs.map +1 -1
- package/dist/esm/Resizer/SplitResizer.mjs +56 -33
- package/dist/esm/Resizer/SplitResizer.mjs.map +1 -1
- package/dist/esm/Split.context.mjs +4 -2
- package/dist/esm/Split.context.mjs.map +1 -1
- package/dist/esm/Split.mjs +33 -12
- package/dist/esm/Split.mjs.map +1 -1
- package/dist/esm/hooks/use-responsive-value.mjs +17 -0
- package/dist/esm/hooks/use-responsive-value.mjs.map +1 -0
- package/dist/esm/hooks/use-split-resizer-orientation.mjs +2 -6
- package/dist/esm/hooks/use-split-resizer-orientation.mjs.map +1 -1
- package/dist/types/Dynamic/SplitDynamic.d.ts +16 -6
- package/dist/types/Pane/SplitPane.d.ts +34 -18
- package/dist/types/Resizer/SplitResizer.d.ts +16 -12
- package/dist/types/Split.context.d.ts +14 -8
- package/dist/types/Split.d.ts +13 -3
- package/dist/types/hooks/use-responsive-value.d.ts +13 -0
- package/dist/types/hooks/use-split-resizer-orientation.d.ts +11 -2
- package/dist/types/index.d.mts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/types.d.ts +3 -0
- package/package.json +1 -1
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
var React = require('react');
|
|
5
5
|
var core = require('@mantine/core');
|
|
6
|
+
var useResponsiveValue = require('../hooks/use-responsive-value.cjs');
|
|
6
7
|
var useSplitResizerOrientation = require('../hooks/use-split-resizer-orientation.cjs');
|
|
7
8
|
var Split_context = require('../Split.context.cjs');
|
|
8
9
|
var SplitResizer_module = require('./SplitResizer.module.css.cjs');
|
|
@@ -104,9 +105,10 @@ const defaultProps = {
|
|
|
104
105
|
cursorVertical: "col-resize",
|
|
105
106
|
cursorHorizontal: "row-resize"
|
|
106
107
|
};
|
|
107
|
-
const SplitResizer = core.factory((_props
|
|
108
|
+
const SplitResizer = core.factory((_props) => {
|
|
108
109
|
const ctx = Split_context.useSplitContext();
|
|
109
|
-
const
|
|
110
|
+
const { containerSize: _containerSize, ...ctxResizerProps } = ctx || {};
|
|
111
|
+
const props = core.useProps("SplitResizer", { ...defaultProps, ...ctxResizerProps }, _props);
|
|
110
112
|
const {
|
|
111
113
|
orientation: propOrientation,
|
|
112
114
|
opacity,
|
|
@@ -144,11 +146,20 @@ const SplitResizer = core.factory((_props, _) => {
|
|
|
144
146
|
mod,
|
|
145
147
|
...rest
|
|
146
148
|
} = props;
|
|
147
|
-
const orientation = useSplitResizerOrientation.useSplitResizerOrientation(propOrientation);
|
|
149
|
+
const orientation = useSplitResizerOrientation.useSplitResizerOrientation(propOrientation ?? "vertical");
|
|
150
|
+
const resolvedSize = useResponsiveValue.useResponsiveValue(size) ?? defaultProps.size;
|
|
151
|
+
const resolvedSpacing = useResponsiveValue.useResponsiveValue(spacing) ?? defaultProps.spacing;
|
|
152
|
+
const resolvedKnobSize = useResponsiveValue.useResponsiveValue(knobSize) ?? defaultProps.knobSize;
|
|
153
|
+
const resolvedProps = {
|
|
154
|
+
...props,
|
|
155
|
+
size: resolvedSize,
|
|
156
|
+
spacing: resolvedSpacing,
|
|
157
|
+
knobSize: resolvedKnobSize
|
|
158
|
+
};
|
|
148
159
|
const getStyles = core.useStyles({
|
|
149
160
|
name: "SplitResizer",
|
|
150
161
|
classes: SplitResizer_module,
|
|
151
|
-
props,
|
|
162
|
+
props: resolvedProps,
|
|
152
163
|
className,
|
|
153
164
|
style,
|
|
154
165
|
classNames,
|
|
@@ -159,12 +170,18 @@ const SplitResizer = core.factory((_props, _) => {
|
|
|
159
170
|
});
|
|
160
171
|
const containerRef = React.useRef(null);
|
|
161
172
|
const processVerticalSize = (deltaX = 0) => {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
const
|
|
173
|
+
if (!beforeRef?.current || !afterRef?.current) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
const minBeforeWidth = beforeRef.current.getMinWidth?.();
|
|
177
|
+
const maxBeforeWidth = beforeRef.current.getMaxWidth?.();
|
|
178
|
+
const minAfterWidth = afterRef.current.getMinWidth?.();
|
|
179
|
+
const maxAfterWidth = afterRef.current.getMaxWidth?.();
|
|
166
180
|
const beforePane = beforeRef.current.splitPane;
|
|
167
181
|
const afterPane = afterRef.current.splitPane;
|
|
182
|
+
if (!beforePane || !afterPane) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
168
185
|
let beforeWidth = beforePane.getBoundingClientRect().width;
|
|
169
186
|
let afterWidth = afterPane.getBoundingClientRect().width;
|
|
170
187
|
const isBeforeWidthMaxExceeded = maxBeforeWidth && beforeWidth + deltaX > maxBeforeWidth;
|
|
@@ -184,8 +201,8 @@ const SplitResizer = core.factory((_props, _) => {
|
|
|
184
201
|
width: afterWidth,
|
|
185
202
|
height: afterPane.getBoundingClientRect().height
|
|
186
203
|
};
|
|
187
|
-
beforeRef
|
|
188
|
-
afterRef
|
|
204
|
+
beforeRef?.current?.onResizing?.(beforePaneSizes);
|
|
205
|
+
afterRef?.current?.onResizing?.(afterPaneSizes);
|
|
189
206
|
onResizing?.({
|
|
190
207
|
beforePane: beforePaneSizes,
|
|
191
208
|
afterPane: afterPaneSizes
|
|
@@ -231,12 +248,18 @@ const SplitResizer = core.factory((_props, _) => {
|
|
|
231
248
|
setVerticalSize();
|
|
232
249
|
};
|
|
233
250
|
const processHorizontalSize = (deltaY = 0) => {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
const
|
|
251
|
+
if (!beforeRef?.current || !afterRef?.current) {
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
const minBeforeHeight = beforeRef.current.getMinHeight?.();
|
|
255
|
+
const maxBeforeHeight = beforeRef.current.getMaxHeight?.();
|
|
256
|
+
const minAfterHeight = afterRef.current.getMinHeight?.();
|
|
257
|
+
const maxAfterHeight = afterRef.current.getMaxHeight?.();
|
|
238
258
|
const beforePane = beforeRef.current.splitPane;
|
|
239
259
|
const afterPane = afterRef.current.splitPane;
|
|
260
|
+
if (!beforePane || !afterPane) {
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
240
263
|
let beforeHeight = beforePane.getBoundingClientRect().height;
|
|
241
264
|
let afterHeight = afterPane.getBoundingClientRect().height;
|
|
242
265
|
const isBeforeHeightMaxExceeded = maxBeforeHeight && beforeHeight + deltaY > maxBeforeHeight;
|
|
@@ -260,8 +283,8 @@ const SplitResizer = core.factory((_props, _) => {
|
|
|
260
283
|
beforePane: beforePaneSizes,
|
|
261
284
|
afterPane: afterPaneSizes
|
|
262
285
|
});
|
|
263
|
-
beforeRef
|
|
264
|
-
afterRef
|
|
286
|
+
beforeRef?.current?.onResizing?.(beforePaneSizes);
|
|
287
|
+
afterRef?.current?.onResizing?.(afterPaneSizes);
|
|
265
288
|
beforePane.style.height = beforeHeightString;
|
|
266
289
|
afterPane.style.height = afterHeightString;
|
|
267
290
|
}
|
|
@@ -316,13 +339,13 @@ const SplitResizer = core.factory((_props, _) => {
|
|
|
316
339
|
document.addEventListener("touchend", handleTouchEnd);
|
|
317
340
|
}
|
|
318
341
|
onResizeStart?.();
|
|
319
|
-
beforeRef
|
|
320
|
-
afterRef
|
|
321
|
-
document.body.style.cursor = orientation === "vertical" ? cursorVertical : cursorHorizontal;
|
|
342
|
+
beforeRef?.current?.onResizeStart?.();
|
|
343
|
+
afterRef?.current?.onResizeStart?.();
|
|
344
|
+
document.body.style.cursor = (orientation === "vertical" ? cursorVertical : cursorHorizontal) ?? "";
|
|
322
345
|
};
|
|
323
346
|
const handleMove = (event) => {
|
|
324
|
-
if (!beforeRef
|
|
325
|
-
|
|
347
|
+
if (!beforeRef?.current || !afterRef?.current) {
|
|
348
|
+
return;
|
|
326
349
|
}
|
|
327
350
|
event.preventDefault();
|
|
328
351
|
event.stopPropagation();
|
|
@@ -341,8 +364,8 @@ const SplitResizer = core.factory((_props, _) => {
|
|
|
341
364
|
}
|
|
342
365
|
};
|
|
343
366
|
const handleMouseUp = () => {
|
|
344
|
-
if (!beforeRef
|
|
345
|
-
|
|
367
|
+
if (!beforeRef?.current || !afterRef?.current) {
|
|
368
|
+
return;
|
|
346
369
|
}
|
|
347
370
|
document.body.style.userSelect = "initial";
|
|
348
371
|
document.body.style.webkitUserSelect = "initial";
|
|
@@ -363,12 +386,12 @@ const SplitResizer = core.factory((_props, _) => {
|
|
|
363
386
|
beforePane: beforePaneSizes,
|
|
364
387
|
afterPane: afterPaneSizes
|
|
365
388
|
});
|
|
366
|
-
beforeRef
|
|
367
|
-
afterRef
|
|
389
|
+
beforeRef?.current?.onResizeEnd?.(beforePaneSizes);
|
|
390
|
+
afterRef?.current?.onResizeEnd?.(afterPaneSizes);
|
|
368
391
|
};
|
|
369
392
|
const handleTouchEnd = () => {
|
|
370
|
-
if (!beforeRef
|
|
371
|
-
|
|
393
|
+
if (!beforeRef?.current || !afterRef?.current) {
|
|
394
|
+
return;
|
|
372
395
|
}
|
|
373
396
|
document.removeEventListener("touchmove", handleMove);
|
|
374
397
|
document.removeEventListener("touchend", handleTouchEnd);
|
|
@@ -387,8 +410,8 @@ const SplitResizer = core.factory((_props, _) => {
|
|
|
387
410
|
beforePane: beforePaneSizes,
|
|
388
411
|
afterPane: afterPaneSizes
|
|
389
412
|
});
|
|
390
|
-
beforeRef
|
|
391
|
-
afterRef
|
|
413
|
+
beforeRef?.current?.onResizeEnd?.(beforePaneSizes);
|
|
414
|
+
afterRef?.current?.onResizeEnd?.(afterPaneSizes);
|
|
392
415
|
};
|
|
393
416
|
const handleKeyUp = (event) => {
|
|
394
417
|
if (containerRef.current !== document.activeElement) {
|
|
@@ -397,7 +420,7 @@ const SplitResizer = core.factory((_props, _) => {
|
|
|
397
420
|
const code = event.nativeEvent.code;
|
|
398
421
|
const arrowLeftRight = code === "ArrowRight" || code === "ArrowLeft";
|
|
399
422
|
const arrowUpDown = code === "ArrowUp" || code === "ArrowDown";
|
|
400
|
-
const delta = event.shiftKey ? shiftStep : step;
|
|
423
|
+
const delta = (event.shiftKey ? shiftStep : step) ?? 8;
|
|
401
424
|
if (orientation === "vertical" && arrowLeftRight) {
|
|
402
425
|
event.preventDefault();
|
|
403
426
|
event.stopPropagation();
|
|
@@ -415,14 +438,14 @@ const SplitResizer = core.factory((_props, _) => {
|
|
|
415
438
|
if (code === "Escape") {
|
|
416
439
|
event.preventDefault();
|
|
417
440
|
event.stopPropagation();
|
|
418
|
-
containerRef.current
|
|
441
|
+
containerRef.current?.blur();
|
|
419
442
|
}
|
|
420
443
|
};
|
|
421
444
|
const handleDoubleClick = (e) => {
|
|
422
445
|
e.preventDefault();
|
|
423
446
|
e.stopPropagation();
|
|
424
|
-
beforeRef
|
|
425
|
-
afterRef
|
|
447
|
+
beforeRef?.current?.resetInitialSize?.(e);
|
|
448
|
+
afterRef?.current?.resetInitialSize?.(e);
|
|
426
449
|
onDoubleClick?.(e);
|
|
427
450
|
};
|
|
428
451
|
return /* @__PURE__ */ React.createElement(
|