@linzjs/lui 21.25.0 → 21.26.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.
- package/CHANGELOG.md +14 -0
- package/dist/components/Splitter/Separator/Separator.d.ts +3 -0
- package/dist/components/Splitter/Splitter.d.ts +33 -19
- package/dist/components/Splitter/Stories/RangeAsPx.d.ts +9 -0
- package/dist/components/Splitter/Stories/Section.d.ts +5 -0
- package/dist/components/Splitter/helpers/dataBoundary.d.ts +18 -0
- package/dist/components/Splitter/helpers/getGridTemplate.d.ts +14 -0
- package/dist/components/Splitter/helpers/getSeparatorAttributes.d.ts +1 -0
- package/dist/components/Splitter/helpers/transition.d.ts +5 -0
- package/dist/components/Splitter/helpers/useBoundary.d.ts +13 -0
- package/dist/components/Splitter/helpers/useValueSeparator.d.ts +6 -2
- package/dist/components/Splitter/helpers/useValueSeparatorEffects.d.ts +4 -1
- package/dist/index.js +298 -47
- package/dist/index.js.map +1 -1
- package/dist/lui.esm.js +298 -47
- package/dist/lui.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -58450,6 +58450,56 @@ var useForkRef = function (forwardedRef) {
|
|
|
58450
58450
|
return forwardedRef || localRef;
|
|
58451
58451
|
};
|
|
58452
58452
|
|
|
58453
|
+
var attrBoundary = 'data-boundary';
|
|
58454
|
+
var dataBoundary = function (_a) {
|
|
58455
|
+
var min = _a.min, max = _a.max;
|
|
58456
|
+
if (typeof min === 'undefined' && typeof max !== 'undefined') {
|
|
58457
|
+
if (typeof max === 'string') {
|
|
58458
|
+
return parseInt(max) < 0 ? 'keep-secondary' : 'keep-primary';
|
|
58459
|
+
}
|
|
58460
|
+
}
|
|
58461
|
+
if (typeof max === 'undefined' && typeof min !== 'undefined') {
|
|
58462
|
+
if (typeof min === 'string') {
|
|
58463
|
+
return parseInt(min) < 0 ? 'keep-secondary' : 'keep-primary';
|
|
58464
|
+
}
|
|
58465
|
+
}
|
|
58466
|
+
if (typeof max === 'string' && typeof min === 'string') {
|
|
58467
|
+
if (parseInt(max) > 0 && parseInt(min) > 0) {
|
|
58468
|
+
return 'keep-primary';
|
|
58469
|
+
}
|
|
58470
|
+
if (parseInt(max) < 0 && parseInt(min) < 0) {
|
|
58471
|
+
return 'keep-secondary';
|
|
58472
|
+
}
|
|
58473
|
+
}
|
|
58474
|
+
return 'keep-both';
|
|
58475
|
+
};
|
|
58476
|
+
/**
|
|
58477
|
+
* Given boundaries passed as prop, it defines how the grid column/row template will be arranged.
|
|
58478
|
+
* and whether the separator will be positioned using right or left absolute values (top or bottom for horizontal).
|
|
58479
|
+
* It will use a data- attribute to store this prop derived information for later processing.
|
|
58480
|
+
*/
|
|
58481
|
+
var setDataBoundary = function (props) {
|
|
58482
|
+
var _a;
|
|
58483
|
+
return (_a = {},
|
|
58484
|
+
_a[attrBoundary] = dataBoundary(props),
|
|
58485
|
+
_a);
|
|
58486
|
+
};
|
|
58487
|
+
/**
|
|
58488
|
+
* Util to get what grid arrangement needs to be used to avoid jumps/flashes.
|
|
58489
|
+
* The return value is derived from the Splitter props, and stored in a data- attribute.
|
|
58490
|
+
*/
|
|
58491
|
+
var getDataBoundary = function (separator) {
|
|
58492
|
+
var boundaryType = separator === null || separator === void 0 ? void 0 : separator.getAttribute(attrBoundary);
|
|
58493
|
+
switch (boundaryType) {
|
|
58494
|
+
case 'keep-primary':
|
|
58495
|
+
case 'keep-secondary':
|
|
58496
|
+
case 'keep-both':
|
|
58497
|
+
return boundaryType;
|
|
58498
|
+
default:
|
|
58499
|
+
return undefined;
|
|
58500
|
+
}
|
|
58501
|
+
};
|
|
58502
|
+
|
|
58453
58503
|
/**
|
|
58454
58504
|
* Given a ref/element if finds the Separator and returns the most useful attributes
|
|
58455
58505
|
*/
|
|
@@ -58465,7 +58515,8 @@ var getValues = function (el) {
|
|
|
58465
58515
|
valueMin: parseValue(el === null || el === void 0 ? void 0 : el.getAttribute('aria-valuemin')),
|
|
58466
58516
|
valueMax: parseValue(el === null || el === void 0 ? void 0 : el.getAttribute('aria-valuemax')),
|
|
58467
58517
|
orientation: parseOrientation(el === null || el === void 0 ? void 0 : el.getAttribute('aria-orientation')),
|
|
58468
|
-
thickness: getSeparatorThickness(el)
|
|
58518
|
+
thickness: getSeparatorThickness(el),
|
|
58519
|
+
boundary: getDataBoundary(el)
|
|
58469
58520
|
};
|
|
58470
58521
|
};
|
|
58471
58522
|
var parseValue = function (val) {
|
|
@@ -58543,6 +58594,9 @@ var Control = React.forwardRef(function (props, forwardRef) {
|
|
|
58543
58594
|
React.useEffect(function () {
|
|
58544
58595
|
var callback = function () {
|
|
58545
58596
|
var control = ref.current;
|
|
58597
|
+
if (!control) {
|
|
58598
|
+
return;
|
|
58599
|
+
}
|
|
58546
58600
|
var _a = getButtonProps(ref, side), hide = _a.hide, offset = _a.offset, orientation = _a.orientation;
|
|
58547
58601
|
var vertical = orientation === 'vertical';
|
|
58548
58602
|
control.style.left = vertical ? "".concat(offset, "px") : '50%';
|
|
@@ -58555,7 +58609,14 @@ var Control = React.forwardRef(function (props, forwardRef) {
|
|
|
58555
58609
|
var separator = ref.current.closest('[role="separator"]');
|
|
58556
58610
|
callback();
|
|
58557
58611
|
var observer = new MutationObserver(callback);
|
|
58558
|
-
observer.observe(separator, {
|
|
58612
|
+
observer.observe(separator, {
|
|
58613
|
+
attributeFilter: [
|
|
58614
|
+
'aria-valuenow',
|
|
58615
|
+
'aria-valuemin',
|
|
58616
|
+
'aria-valuemax',
|
|
58617
|
+
'aria-orientation',
|
|
58618
|
+
]
|
|
58619
|
+
});
|
|
58559
58620
|
return function () { return observer.disconnect(); };
|
|
58560
58621
|
}, [ref, side]);
|
|
58561
58622
|
return (React__default["default"].createElement(LuiButton, __assign({ ref: ref, level: "primary", type: "button" }, rest, { style: __assign(__assign({}, rest === null || rest === void 0 ? void 0 : rest.style), { width: squareButtonSide, height: squareButtonSide, borderRadius: '50%' }), className: clsx('Control', 'lui-button-icon-only', 'lui-box-shadow', rest === null || rest === void 0 ? void 0 : rest.className) }), (rest === null || rest === void 0 ? void 0 : rest.children) || React__default["default"].createElement(ControlIcon, { parent: ref, side: side })));
|
|
@@ -58620,6 +58681,29 @@ var getSeparatorPosition = function (separatorRef, drag) {
|
|
|
58620
58681
|
return clampSeparator({ value: value });
|
|
58621
58682
|
};
|
|
58622
58683
|
|
|
58684
|
+
var transitionFactory = function (attrs, ms) {
|
|
58685
|
+
return attrs.map(function (key) { return "".concat(key, " ").concat(ms, "ms"); }).join(', ');
|
|
58686
|
+
};
|
|
58687
|
+
var barTransition = function (ms) {
|
|
58688
|
+
return transitionFactory(['left', 'top', 'right', 'bottom'], ms);
|
|
58689
|
+
};
|
|
58690
|
+
var gridTransition = function (ms) {
|
|
58691
|
+
return transitionFactory(['grid-template-columns', 'grid-template-rows'], ms);
|
|
58692
|
+
};
|
|
58693
|
+
var transition = function (separator) {
|
|
58694
|
+
var _a;
|
|
58695
|
+
var splitter = (_a = separator.current) === null || _a === void 0 ? void 0 : _a.parentElement;
|
|
58696
|
+
var delay = function (ms) {
|
|
58697
|
+
if (splitter) {
|
|
58698
|
+
separator.current.style.transition = barTransition(ms);
|
|
58699
|
+
splitter.style.transition = gridTransition(ms);
|
|
58700
|
+
}
|
|
58701
|
+
};
|
|
58702
|
+
var stop = function () { return delay(0); };
|
|
58703
|
+
var resume = function () { return delay(300); };
|
|
58704
|
+
return { stop: stop, resume: resume };
|
|
58705
|
+
};
|
|
58706
|
+
|
|
58623
58707
|
/**
|
|
58624
58708
|
* It captures window events to report a new position.
|
|
58625
58709
|
* Provides necessary handlers for separator.
|
|
@@ -58663,8 +58747,7 @@ var animateSeparator = function (separatorRef, animate) {
|
|
|
58663
58747
|
var splitter = separator === null || separator === void 0 ? void 0 : separator.parentElement;
|
|
58664
58748
|
if (separator && splitter) {
|
|
58665
58749
|
if (animate === 'clear-transition') {
|
|
58666
|
-
|
|
58667
|
-
splitter.style.transition = '';
|
|
58750
|
+
transition(separatorRef).stop();
|
|
58668
58751
|
splitter.style.cursor =
|
|
58669
58752
|
separator.getAttribute('aria-orientation') === 'vertical'
|
|
58670
58753
|
? 'col-resize'
|
|
@@ -58672,9 +58755,7 @@ var animateSeparator = function (separatorRef, animate) {
|
|
|
58672
58755
|
splitter.classList.add('resizing');
|
|
58673
58756
|
}
|
|
58674
58757
|
else {
|
|
58675
|
-
|
|
58676
|
-
splitter.style.transition =
|
|
58677
|
-
'grid-template-columns 300ms, grid-template-rows 300ms';
|
|
58758
|
+
transition(separatorRef).resume();
|
|
58678
58759
|
splitter.style.cursor = '';
|
|
58679
58760
|
splitter.classList.remove('resizing');
|
|
58680
58761
|
}
|
|
@@ -58684,33 +58765,84 @@ var animateSeparator = function (separatorRef, animate) {
|
|
|
58684
58765
|
/**
|
|
58685
58766
|
* Moves separator as per ratio changes. Centers on first render if ratio is undefined.
|
|
58686
58767
|
*/
|
|
58687
|
-
var useRatioEffect = function (setValueNow, ratio) {
|
|
58768
|
+
var useRatioEffect = function (setValueNow, separator, ratio, startAt) {
|
|
58688
58769
|
var firstRun = React.useRef(true);
|
|
58770
|
+
var _a = getSeparatorAttributes({ ref: separator }), valueMax = _a.valueMax, valueMin = _a.valueMin;
|
|
58771
|
+
var isCalculating = valueMax === Infinity || valueMin === -Infinity;
|
|
58689
58772
|
React.useEffect(function () {
|
|
58690
|
-
if (firstRun.current || ratio !== undefined) {
|
|
58773
|
+
if (firstRun.current || ratio !== undefined || isCalculating) {
|
|
58691
58774
|
firstRun.current = false;
|
|
58692
58775
|
// If ratio is undefined, setValueNow will place the separator in the middle as a starting point.
|
|
58693
58776
|
// Whatever value is `the middle` will be determined by setValueNow
|
|
58694
|
-
setValueNow(ratio);
|
|
58777
|
+
setValueNow(ratio !== null && ratio !== void 0 ? ratio : startAt);
|
|
58695
58778
|
}
|
|
58696
|
-
}, [setValueNow, ratio, firstRun]);
|
|
58779
|
+
}, [setValueNow, ratio, firstRun, startAt]);
|
|
58697
58780
|
};
|
|
58698
58781
|
/**
|
|
58699
58782
|
* Re-arranges the splitter if the limits or orientation change.
|
|
58700
58783
|
*/
|
|
58701
58784
|
var useConfigEffect = function (setValueNow, separator) {
|
|
58785
|
+
var _a = React.useState(0), count = _a[0], setCount = _a[1];
|
|
58786
|
+
React.useEffect(function () { return transition(separator).resume(); }, [count]);
|
|
58702
58787
|
React.useEffect(function () {
|
|
58703
|
-
var callback = function () {
|
|
58704
|
-
|
|
58705
|
-
|
|
58788
|
+
var callback = function (attr) {
|
|
58789
|
+
return function (_a) {
|
|
58790
|
+
var record = _a[0];
|
|
58791
|
+
var target = record.target;
|
|
58792
|
+
var values = getSeparatorAttributes({ separator: target });
|
|
58793
|
+
var oldValue = Number(record.oldValue);
|
|
58794
|
+
var valueMax = values.valueMax, valueMin = values.valueMin, valueNow = values.valueNow;
|
|
58795
|
+
var newValue = attr === 'min' ? valueMin : valueMax;
|
|
58796
|
+
// Determine if separator was collapsed/expanded fully
|
|
58797
|
+
var wasInBoundary = oldValue === valueNow;
|
|
58798
|
+
// To remain collapsed/expanded, it is necessary to call setValueNow with the latest boundaries.
|
|
58799
|
+
// The useBoundaries hook haven't yet reflected the change, and it would cause an unwanted flash.
|
|
58800
|
+
// In such case, the newValueNow is moved along with the delimiter.
|
|
58801
|
+
var newValueNow = !wasInBoundary ? valueNow : newValue;
|
|
58802
|
+
if (wasInBoundary || valueMax < valueNow || valueMin > valueNow) {
|
|
58803
|
+
transition(separator).stop();
|
|
58804
|
+
setValueNow(newValueNow, { min: valueMin, max: valueMax });
|
|
58805
|
+
setCount(function (p) { return p + 1; });
|
|
58806
|
+
}
|
|
58807
|
+
else {
|
|
58808
|
+
var dim = values.orientation === 'vertical' ? 'width' : 'height';
|
|
58809
|
+
var gap = target.getBoundingClientRect()[dim];
|
|
58810
|
+
var offset = gap / 2;
|
|
58811
|
+
var splitterEl = target.parentElement;
|
|
58812
|
+
var primaryEl = splitterEl.childNodes[0];
|
|
58813
|
+
var splitterRect = splitterEl.getBoundingClientRect();
|
|
58814
|
+
var primaryRect = primaryEl.getBoundingClientRect();
|
|
58815
|
+
var container = splitterRect[dim];
|
|
58816
|
+
var primary = primaryRect[dim];
|
|
58817
|
+
var seconday = container - primary - gap;
|
|
58818
|
+
if (primary === 0 || seconday === 0) {
|
|
58819
|
+
return;
|
|
58820
|
+
}
|
|
58821
|
+
var newVal = ((primary + offset) / container) * 100;
|
|
58822
|
+
if (Math.abs(newVal - valueNow) >= 0.01) {
|
|
58823
|
+
setValueNow(newVal, { min: valueMin, max: valueMax });
|
|
58824
|
+
}
|
|
58825
|
+
}
|
|
58826
|
+
};
|
|
58706
58827
|
};
|
|
58707
|
-
|
|
58708
|
-
|
|
58709
|
-
|
|
58710
|
-
|
|
58828
|
+
var config = function (attr) { return ({
|
|
58829
|
+
attributeFilter: ["aria-value".concat(attr)],
|
|
58830
|
+
attributeOldValue: true
|
|
58831
|
+
}); };
|
|
58832
|
+
var minObserver = new MutationObserver(callback('min'));
|
|
58833
|
+
var maxObserver = new MutationObserver(callback('max'));
|
|
58834
|
+
var orientationObserver = new MutationObserver(function () { return setValueNow(); });
|
|
58835
|
+
minObserver.observe(separator.current, config('min'));
|
|
58836
|
+
maxObserver.observe(separator.current, config('max'));
|
|
58837
|
+
orientationObserver.observe(separator.current, {
|
|
58838
|
+
attributeFilter: ['aria-orientation']
|
|
58711
58839
|
});
|
|
58712
|
-
return function () {
|
|
58713
|
-
|
|
58840
|
+
return function () {
|
|
58841
|
+
minObserver.disconnect();
|
|
58842
|
+
maxObserver.disconnect();
|
|
58843
|
+
orientationObserver.disconnect();
|
|
58844
|
+
};
|
|
58845
|
+
}, [separator]);
|
|
58714
58846
|
};
|
|
58715
58847
|
/**
|
|
58716
58848
|
* Broadcasts changes if separator aria-valuenow was altered.
|
|
@@ -58734,12 +58866,53 @@ var useValueNowEffect = function (setValueNow, separator) {
|
|
|
58734
58866
|
/**
|
|
58735
58867
|
* Calls setValueNow when the separator attributes change.
|
|
58736
58868
|
*/
|
|
58737
|
-
var useValueSeparatorEffects = function (setValueNow, separator, ratio) {
|
|
58738
|
-
useRatioEffect(setValueNow, ratio);
|
|
58869
|
+
var useValueSeparatorEffects = function (setValueNow, separator, ratio, startAt) {
|
|
58870
|
+
useRatioEffect(setValueNow, separator, ratio, startAt);
|
|
58739
58871
|
useConfigEffect(setValueNow, separator);
|
|
58740
58872
|
useValueNowEffect(setValueNow, separator);
|
|
58741
58873
|
};
|
|
58742
58874
|
|
|
58875
|
+
/**
|
|
58876
|
+
* It will calculate the best grid arrangement, based on the min/max props passed to the Splitter.
|
|
58877
|
+
* All grid options work. The preference `1fr XXpx` over `(width - XXpx) 1fr` depends on the type of boundary
|
|
58878
|
+
* to avoid calculation of position when the window is being resized while trying to retain the collapsed state
|
|
58879
|
+
* on a min/max value fixed in pixels (e.g. 200px). Such calculation adds unnecessary lagging on the separator
|
|
58880
|
+
* to catch up. This function aims to avoid such lagging during resizing.
|
|
58881
|
+
* primary relates to top/left
|
|
58882
|
+
* secondary relates to right/bottom
|
|
58883
|
+
*/
|
|
58884
|
+
var getGridTemplate = function (separator) {
|
|
58885
|
+
var _a = getSeparatorAttributes({ separator: separator }), valueNow = _a.valueNow, gap = _a.thickness, boundary = _a.boundary, orientation = _a.orientation;
|
|
58886
|
+
var rect = separator.parentElement.getBoundingClientRect();
|
|
58887
|
+
var dimension = orientation === 'horizontal' ? 'height' : 'width';
|
|
58888
|
+
var seperatorAbsolutePx = (rect[dimension] / 100) * valueNow;
|
|
58889
|
+
var offset = gap / 2;
|
|
58890
|
+
var clamp = function (val, type) {
|
|
58891
|
+
return "clamp(".concat(offset, "px, ").concat(val).concat(type, ", calc(100% - ").concat(offset, "px))");
|
|
58892
|
+
};
|
|
58893
|
+
if (boundary === 'keep-primary') {
|
|
58894
|
+
var grid = Math.max(seperatorAbsolutePx - offset, 0);
|
|
58895
|
+
return {
|
|
58896
|
+
grid: "".concat(grid, "px 1fr"),
|
|
58897
|
+
primary: clamp(seperatorAbsolutePx, 'px'),
|
|
58898
|
+
secondary: ''
|
|
58899
|
+
};
|
|
58900
|
+
}
|
|
58901
|
+
if (boundary === 'keep-secondary') {
|
|
58902
|
+
var grid = Math.max(rect[dimension] - seperatorAbsolutePx - offset, 0);
|
|
58903
|
+
return {
|
|
58904
|
+
grid: "1fr ".concat(grid, "px"),
|
|
58905
|
+
primary: '',
|
|
58906
|
+
secondary: clamp(rect[dimension] - seperatorAbsolutePx, 'px')
|
|
58907
|
+
};
|
|
58908
|
+
}
|
|
58909
|
+
return {
|
|
58910
|
+
grid: "min(calc(".concat(valueNow, "% - ").concat(gap / 2, "px), calc(100% - ").concat(gap, "px)) 1fr"),
|
|
58911
|
+
primary: clamp(valueNow, '%'),
|
|
58912
|
+
secondary: "calc(100% - ".concat(clamp(valueNow, '%'), ")")
|
|
58913
|
+
};
|
|
58914
|
+
};
|
|
58915
|
+
|
|
58743
58916
|
/**
|
|
58744
58917
|
* Ensures valueNow is set to a valid value within its allowed boundaries.
|
|
58745
58918
|
* If boundaries and/or initialRatio are not specified, they will be defaulted.
|
|
@@ -58747,19 +58920,24 @@ var useValueSeparatorEffects = function (setValueNow, separator, ratio) {
|
|
|
58747
58920
|
* This multiple calls are expected, and setValueNow will resize only once.
|
|
58748
58921
|
*/
|
|
58749
58922
|
var useValueSeparator = function (_a) {
|
|
58750
|
-
var separator = _a.separator, ratio = _a.ratio, onResized = _a.onResized, _b = _a.boundaries,
|
|
58923
|
+
var separator = _a.separator, ratio = _a.ratio, onResized = _a.onResized, _b = _a.boundaries, minProp = _b.min, maxProp = _b.max, startAt = _a.startAt;
|
|
58751
58924
|
var prev = React.useRef(null);
|
|
58752
|
-
var setValueNow = React.useCallback(function (val) {
|
|
58925
|
+
var setValueNow = React.useCallback(function (val, config) {
|
|
58926
|
+
var _a, _b;
|
|
58753
58927
|
var valueNow = getSeparatorAttributes({ ref: separator }).valueNow;
|
|
58928
|
+
// Prioritize min/max from callback, they are updated before the boundaries prop.
|
|
58929
|
+
var min = (_a = config === null || config === void 0 ? void 0 : config.min) !== null && _a !== void 0 ? _a : minProp;
|
|
58930
|
+
var max = (_b = config === null || config === void 0 ? void 0 : config.max) !== null && _b !== void 0 ? _b : maxProp;
|
|
58754
58931
|
var value = val !== null && val !== void 0 ? val : (valueNow || min + (max - min) / 2);
|
|
58755
58932
|
var newValue = clampSeparator({ value: value, max: max, min: min });
|
|
58933
|
+
var isCalculating = min === -Infinity || max === Infinity;
|
|
58756
58934
|
resize(separator, newValue);
|
|
58757
|
-
if (prev.current !== newValue) {
|
|
58935
|
+
if (prev.current !== newValue && !isCalculating) {
|
|
58758
58936
|
prev.current = newValue;
|
|
58759
58937
|
onResized === null || onResized === void 0 ? void 0 : onResized(newValue);
|
|
58760
58938
|
}
|
|
58761
|
-
}, [onResized,
|
|
58762
|
-
useValueSeparatorEffects(setValueNow, separator, ratio);
|
|
58939
|
+
}, [onResized, minProp, maxProp, prev]);
|
|
58940
|
+
useValueSeparatorEffects(setValueNow, separator, ratio, startAt);
|
|
58763
58941
|
return { setValueNow: setValueNow };
|
|
58764
58942
|
};
|
|
58765
58943
|
var resize = function (separator, value) {
|
|
@@ -58775,12 +58953,8 @@ var resize = function (separator, value) {
|
|
|
58775
58953
|
separator.current.setAttribute('aria-valuenow', newValue);
|
|
58776
58954
|
}
|
|
58777
58955
|
var panels = (_a = separator.current.parentElement.childNodes.length) !== null && _a !== void 0 ? _a : 0;
|
|
58778
|
-
var
|
|
58779
|
-
var
|
|
58780
|
-
var absolute = "clamp(".concat(offset, "px, ").concat(valueNow, "%, calc(100% - ").concat(offset, "px))");
|
|
58781
|
-
var gridTemplate = panels === 1
|
|
58782
|
-
? '1fr'
|
|
58783
|
-
: "min(calc(".concat(valueNow, "% - ").concat(gap / 2, "px), calc(100% - ").concat(gap, "px)) 1fr");
|
|
58956
|
+
var _d = getGridTemplate(separator.current), grid = _d.grid, primary = _d.primary, secondary = _d.secondary;
|
|
58957
|
+
var gridTemplate = panels === 1 ? '1fr' : grid;
|
|
58784
58958
|
var splitter = (_b = separator.current) === null || _b === void 0 ? void 0 : _b.parentElement;
|
|
58785
58959
|
if (splitter) {
|
|
58786
58960
|
splitter.style.opacity = '1';
|
|
@@ -58788,25 +58962,29 @@ var resize = function (separator, value) {
|
|
|
58788
58962
|
splitter.style.columnGap = "".concat(gap, "px");
|
|
58789
58963
|
splitter.style.gridTemplateColumns = gridTemplate;
|
|
58790
58964
|
separator.current.style.width = "".concat(gap, "px");
|
|
58791
|
-
separator.current.style.left =
|
|
58965
|
+
separator.current.style.left = primary;
|
|
58966
|
+
separator.current.style.right = secondary;
|
|
58792
58967
|
separator.current.style.height = '100%';
|
|
58793
|
-
separator.current.style.transform =
|
|
58968
|
+
separator.current.style.transform = "translateX(".concat(primary && '-', "50%)");
|
|
58794
58969
|
separator.current.style.cursor = 'col-resize';
|
|
58795
58970
|
splitter.style.rowGap = '';
|
|
58796
58971
|
splitter.style.gridTemplateRows = '';
|
|
58797
58972
|
separator.current.style.top = '';
|
|
58973
|
+
separator.current.style.bottom = '';
|
|
58798
58974
|
}
|
|
58799
58975
|
else {
|
|
58800
58976
|
splitter.style.rowGap = "".concat(gap, "px");
|
|
58801
58977
|
splitter.style.gridTemplateRows = gridTemplate;
|
|
58802
58978
|
separator.current.style.height = "".concat(gap, "px");
|
|
58803
|
-
separator.current.style.top =
|
|
58979
|
+
separator.current.style.top = primary;
|
|
58980
|
+
separator.current.style.bottom = secondary;
|
|
58804
58981
|
separator.current.style.width = '100%';
|
|
58805
|
-
separator.current.style.transform =
|
|
58982
|
+
separator.current.style.transform = "translateY(".concat(primary && '-', "50%)");
|
|
58806
58983
|
separator.current.style.cursor = 'row-resize';
|
|
58807
58984
|
splitter.style.columnGap = '';
|
|
58808
58985
|
splitter.style.gridTemplateColumns = '';
|
|
58809
58986
|
separator.current.style.left = '';
|
|
58987
|
+
separator.current.style.right = '';
|
|
58810
58988
|
}
|
|
58811
58989
|
}
|
|
58812
58990
|
};
|
|
@@ -58890,6 +59068,62 @@ var getNewValueNow = function (_a, valueNow, pixelUnit) {
|
|
|
58890
59068
|
return valueNow;
|
|
58891
59069
|
};
|
|
58892
59070
|
|
|
59071
|
+
var isPxProps = function (_a) {
|
|
59072
|
+
var min = _a.min, max = _a.max;
|
|
59073
|
+
var isPercentage = typeof max === 'number' || typeof min === 'number';
|
|
59074
|
+
var isNull = min === undefined && max === undefined;
|
|
59075
|
+
return !isPercentage && !isNull;
|
|
59076
|
+
};
|
|
59077
|
+
/**
|
|
59078
|
+
* Maps min and max values if they are provided in 'XXXpx' format.
|
|
59079
|
+
*/
|
|
59080
|
+
var useBoundary = function (separator, boundaries) {
|
|
59081
|
+
var _a = React.useState({ min: -Infinity, max: Infinity }), mapped = _a[0], setMapped = _a[1];
|
|
59082
|
+
var isPx = isPxProps(boundaries);
|
|
59083
|
+
var min = boundaries.min, max = boundaries.max;
|
|
59084
|
+
React.useEffect(function () {
|
|
59085
|
+
var _a;
|
|
59086
|
+
var element = (_a = separator === null || separator === void 0 ? void 0 : separator.current) === null || _a === void 0 ? void 0 : _a.parentElement;
|
|
59087
|
+
var shouldMap = element && isPx;
|
|
59088
|
+
var observer = new ResizeObserver(function (_a) {
|
|
59089
|
+
var rect = _a[0].contentRect;
|
|
59090
|
+
var _b = getSeparatorAttributes({
|
|
59091
|
+
ref: separator
|
|
59092
|
+
}), thickness = _b.thickness, orientation = _b.orientation;
|
|
59093
|
+
var halfThickness = thickness / 2;
|
|
59094
|
+
var length = orientation === 'vertical' ? rect.width : rect.height;
|
|
59095
|
+
var parse = function (boundary) {
|
|
59096
|
+
if (typeof boundary === 'number') {
|
|
59097
|
+
return boundary;
|
|
59098
|
+
}
|
|
59099
|
+
var boundaryAsNumber = parseFloat(boundary);
|
|
59100
|
+
var offset = boundaryAsNumber > 0
|
|
59101
|
+
? boundaryAsNumber + halfThickness
|
|
59102
|
+
: length - Math.abs(boundaryAsNumber) - halfThickness;
|
|
59103
|
+
return (offset / length) * 100;
|
|
59104
|
+
};
|
|
59105
|
+
setMapped({ min: parse(min !== null && min !== void 0 ? min : 0), max: parse(max !== null && max !== void 0 ? max : 100) });
|
|
59106
|
+
});
|
|
59107
|
+
if (shouldMap) {
|
|
59108
|
+
observer.observe(element);
|
|
59109
|
+
}
|
|
59110
|
+
return function () {
|
|
59111
|
+
if (shouldMap) {
|
|
59112
|
+
observer.disconnect();
|
|
59113
|
+
}
|
|
59114
|
+
};
|
|
59115
|
+
}, [separator, max, min, isPx]);
|
|
59116
|
+
if (isPx) {
|
|
59117
|
+
return mapped;
|
|
59118
|
+
}
|
|
59119
|
+
else {
|
|
59120
|
+
return {
|
|
59121
|
+
min: Math.max(Number(min !== null && min !== void 0 ? min : 0), 0),
|
|
59122
|
+
max: Math.min(Number(max !== null && max !== void 0 ? max : 100), 100)
|
|
59123
|
+
};
|
|
59124
|
+
}
|
|
59125
|
+
};
|
|
59126
|
+
|
|
58893
59127
|
var canceEvent = function (e) {
|
|
58894
59128
|
if (e.currentTarget !== e.target) {
|
|
58895
59129
|
e.preventDefault();
|
|
@@ -58898,21 +59132,19 @@ var canceEvent = function (e) {
|
|
|
58898
59132
|
};
|
|
58899
59133
|
var Separator = React.forwardRef(function (_a, forwardRef) {
|
|
58900
59134
|
var _b;
|
|
58901
|
-
var parts = _a.parts, ratio = _a.ratio, onResized = _a.onResized, props = __rest(_a, ["parts", "ratio", "onResized"]);
|
|
59135
|
+
var parts = _a.parts, ratio = _a.ratio, onResized = _a.onResized, min = _a.min, max = _a.max, startAt = _a.startAt, props = __rest(_a, ["parts", "ratio", "onResized", "min", "max", "startAt"]);
|
|
58902
59136
|
var separator = useForkRef(forwardRef);
|
|
58903
|
-
var boundaries = {
|
|
58904
|
-
min: props['aria-valuemin'],
|
|
58905
|
-
max: props['aria-valuemax']
|
|
58906
|
-
};
|
|
59137
|
+
var boundaries = useBoundary(separator, { min: min, max: max });
|
|
58907
59138
|
var setValueNow = useValueSeparator({
|
|
58908
59139
|
ratio: ratio,
|
|
58909
59140
|
separator: separator,
|
|
58910
59141
|
onResized: onResized,
|
|
58911
|
-
boundaries: boundaries
|
|
59142
|
+
boundaries: boundaries,
|
|
59143
|
+
startAt: startAt
|
|
58912
59144
|
}).setValueNow;
|
|
58913
59145
|
useShowSeparator(separator);
|
|
58914
59146
|
var values = function () { return getSeparatorAttributes({ ref: separator }); };
|
|
58915
|
-
return (React__default["default"].createElement("div", __assign({ ref: separator }, props, useMoveSeparator(separator, setValueNow), { onKeyDown: function (e) {
|
|
59147
|
+
return (React__default["default"].createElement("div", __assign({ ref: separator, "aria-valuemin": boundaries.min, "aria-valuemax": boundaries.max }, props, useMoveSeparator(separator, setValueNow), { onKeyDown: function (e) {
|
|
58916
59148
|
var _a;
|
|
58917
59149
|
var newValueNow = keyDownHandler(e);
|
|
58918
59150
|
if (values().valueNow !== newValueNow) {
|
|
@@ -58962,12 +59194,31 @@ styleInject(css_248z);
|
|
|
58962
59194
|
*/
|
|
58963
59195
|
var Splitter = React.forwardRef(function (props, ref) {
|
|
58964
59196
|
if (props === void 0) { props = {}; }
|
|
58965
|
-
var parts = props.parts, ratio = props.ratio, onResized = props.onResized, min = props.min, max = props.max, children = props.children, _a = props.orientation, orientation = _a === void 0 ? 'vertical' : _a, rest = __rest(props, ["parts", "ratio", "onResized", "min", "max", "children", "orientation"]);
|
|
59197
|
+
var parts = props.parts, ratio = props.ratio, onResized = props.onResized, min = props.min, max = props.max, children = props.children, _a = props.orientation, orientation = _a === void 0 ? 'vertical' : _a, startAt = props.startAt, rest = __rest(props, ["parts", "ratio", "onResized", "min", "max", "children", "orientation", "startAt"]);
|
|
58966
59198
|
return (React__default["default"].createElement("div", __assign({ ref: ref }, rest, { className: clsx('Splitter', rest === null || rest === void 0 ? void 0 : rest.className) }),
|
|
58967
59199
|
children,
|
|
58968
|
-
React__default["default"].createElement(Separator, __assign({}, parts === null || parts === void 0 ? void 0 : parts.separator, { tabIndex: 0,
|
|
59200
|
+
React__default["default"].createElement(Separator, __assign({}, parts === null || parts === void 0 ? void 0 : parts.separator, { tabIndex: 0, min: min, max: max, role: "separator", "aria-orientation": orientation, ratio: ratio, onResized: onResized, parts: parts === null || parts === void 0 ? void 0 : parts.controls, startAt: mapStartAt({ ratio: ratio, startAt: startAt }) }, setDataBoundary({ min: min, max: max })))));
|
|
58969
59201
|
});
|
|
58970
|
-
Splitter.displayName = 'Splitter';
|
|
59202
|
+
Splitter.displayName = 'Splitter';
|
|
59203
|
+
var mapStartAt = function (props) {
|
|
59204
|
+
var _a;
|
|
59205
|
+
if (typeof props.ratio === 'number') {
|
|
59206
|
+
// Only consider startAt value when Splitter is uncontrolled (ratio is undefined)
|
|
59207
|
+
return undefined;
|
|
59208
|
+
}
|
|
59209
|
+
// Words describe better intent than numbers.
|
|
59210
|
+
// However, 0 & 100 are figurative numbers.
|
|
59211
|
+
// If there are boundaries, these will be respected.
|
|
59212
|
+
switch (props.startAt) {
|
|
59213
|
+
case '1st-collapsed':
|
|
59214
|
+
return 0;
|
|
59215
|
+
case '2nd-collapsed':
|
|
59216
|
+
return 100;
|
|
59217
|
+
default:
|
|
59218
|
+
// Can be started at any other number between 0 and 100.
|
|
59219
|
+
return (_a = props.startAt) !== null && _a !== void 0 ? _a : 50;
|
|
59220
|
+
}
|
|
59221
|
+
};
|
|
58971
59222
|
|
|
58972
59223
|
var getSeparator = function (splitter) {
|
|
58973
59224
|
var _a;
|