first commit
This commit is contained in:
3
frontend/node_modules/antd/es/splitter/hooks/sizeUtil.d.ts
generated
vendored
Normal file
3
frontend/node_modules/antd/es/splitter/hooks/sizeUtil.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
type SizeUnit = number | undefined;
|
||||
export declare function autoPtgSizes(ptgSizes: SizeUnit[], minPtgSizes: SizeUnit[], maxPtgSizes: SizeUnit[]): number[];
|
||||
export {};
|
||||
68
frontend/node_modules/antd/es/splitter/hooks/sizeUtil.js
generated
vendored
Normal file
68
frontend/node_modules/antd/es/splitter/hooks/sizeUtil.js
generated
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
||||
export function autoPtgSizes(ptgSizes, minPtgSizes, maxPtgSizes) {
|
||||
// Static current data
|
||||
let currentTotalPtg = 0;
|
||||
const undefinedIndexes = [];
|
||||
ptgSizes.forEach((size, index) => {
|
||||
if (size === undefined) {
|
||||
undefinedIndexes.push(index);
|
||||
} else {
|
||||
currentTotalPtg += size;
|
||||
}
|
||||
});
|
||||
const restPtg = 1 - currentTotalPtg;
|
||||
const undefinedCount = undefinedIndexes.length;
|
||||
// If all sizes are defined but don't sum to 1, scale them.
|
||||
if (ptgSizes.length && !undefinedIndexes.length && currentTotalPtg !== 1) {
|
||||
// Handle the case when all sizes are 0
|
||||
if (currentTotalPtg === 0) {
|
||||
const avg = 1 / ptgSizes.length;
|
||||
return ptgSizes.map(() => avg);
|
||||
}
|
||||
const scale = 1 / currentTotalPtg;
|
||||
// We know `size` is a number here because undefinedIndexes is empty.
|
||||
return ptgSizes.map(size => size * scale);
|
||||
}
|
||||
// Fill if exceed
|
||||
if (restPtg < 0) {
|
||||
const scale = 1 / currentTotalPtg;
|
||||
return ptgSizes.map(size => size === undefined ? 0 : size * scale);
|
||||
}
|
||||
// Check if limit exists
|
||||
let sumMin = 0;
|
||||
let sumMax = 0;
|
||||
let limitMin = 0;
|
||||
let limitMax = 1;
|
||||
for (const index of undefinedIndexes) {
|
||||
const min = minPtgSizes[index] || 0;
|
||||
const max = maxPtgSizes[index] || 1;
|
||||
sumMin += min;
|
||||
sumMax += max;
|
||||
limitMin = Math.max(limitMin, min);
|
||||
limitMax = Math.min(limitMax, max);
|
||||
}
|
||||
// Impossible case, just average fill
|
||||
if (sumMin > 1 && sumMax < 1) {
|
||||
const avg = 1 / undefinedCount;
|
||||
return ptgSizes.map(size => size === undefined ? avg : size);
|
||||
}
|
||||
// Quickly fill if can
|
||||
const restAvg = restPtg / undefinedCount;
|
||||
if (limitMin <= restAvg && restAvg <= limitMax) {
|
||||
return ptgSizes.map(size => size === undefined ? restAvg : size);
|
||||
}
|
||||
// Greedy algorithm
|
||||
const result = _toConsumableArray(ptgSizes);
|
||||
let remain = restPtg - sumMin;
|
||||
for (let i = 0; i < undefinedCount; i += 1) {
|
||||
const index = undefinedIndexes[i];
|
||||
const min = minPtgSizes[index] || 0;
|
||||
const max = maxPtgSizes[index] || 1;
|
||||
result[index] = min;
|
||||
const canAdd = max - min;
|
||||
const add = Math.min(canAdd, remain);
|
||||
result[index] += add;
|
||||
remain -= add;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
14
frontend/node_modules/antd/es/splitter/hooks/useItems.d.ts
generated
vendored
Normal file
14
frontend/node_modules/antd/es/splitter/hooks/useItems.d.ts
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
import * as React from 'react';
|
||||
import type { PanelProps } from '../interface';
|
||||
export type ItemType = Omit<PanelProps, 'collapsible'> & {
|
||||
collapsible: {
|
||||
start?: boolean;
|
||||
end?: boolean;
|
||||
showCollapsibleIcon: 'auto' | boolean;
|
||||
};
|
||||
};
|
||||
/**
|
||||
* Convert `children` into `items`.
|
||||
*/
|
||||
declare function useItems(children: React.ReactNode): ItemType[];
|
||||
export default useItems;
|
||||
42
frontend/node_modules/antd/es/splitter/hooks/useItems.js
generated
vendored
Normal file
42
frontend/node_modules/antd/es/splitter/hooks/useItems.js
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
var __rest = this && this.__rest || function (s, e) {
|
||||
var t = {};
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
||||
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
||||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
import * as React from 'react';
|
||||
import toArray from "rc-util/es/Children/toArray";
|
||||
function getCollapsible(collapsible) {
|
||||
if (collapsible && typeof collapsible === 'object') {
|
||||
return Object.assign(Object.assign({}, collapsible), {
|
||||
showCollapsibleIcon: collapsible.showCollapsibleIcon === undefined ? 'auto' : collapsible.showCollapsibleIcon
|
||||
});
|
||||
}
|
||||
const mergedCollapsible = !!collapsible;
|
||||
return {
|
||||
start: mergedCollapsible,
|
||||
end: mergedCollapsible,
|
||||
showCollapsibleIcon: 'auto'
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Convert `children` into `items`.
|
||||
*/
|
||||
function useItems(children) {
|
||||
const items = React.useMemo(() => toArray(children).filter(item => /*#__PURE__*/React.isValidElement(item)).map(node => {
|
||||
const {
|
||||
props
|
||||
} = node;
|
||||
const {
|
||||
collapsible
|
||||
} = props,
|
||||
restProps = __rest(props, ["collapsible"]);
|
||||
return Object.assign(Object.assign({}, restProps), {
|
||||
collapsible: getCollapsible(collapsible)
|
||||
});
|
||||
}), [children]);
|
||||
return items;
|
||||
}
|
||||
export default useItems;
|
||||
10
frontend/node_modules/antd/es/splitter/hooks/useResizable.d.ts
generated
vendored
Normal file
10
frontend/node_modules/antd/es/splitter/hooks/useResizable.d.ts
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import type { ShowCollapsibleIconMode } from '../SplitBar';
|
||||
import type { ItemType } from './useItems';
|
||||
export type ResizableInfo = {
|
||||
resizable: boolean;
|
||||
startCollapsible: boolean;
|
||||
endCollapsible: boolean;
|
||||
showStartCollapsibleIcon: ShowCollapsibleIconMode;
|
||||
showEndCollapsibleIcon: ShowCollapsibleIconMode;
|
||||
};
|
||||
export default function useResizable(items: ItemType[], pxSizes: number[], isRTL: boolean): ResizableInfo[];
|
||||
75
frontend/node_modules/antd/es/splitter/hooks/useResizable.js
generated
vendored
Normal file
75
frontend/node_modules/antd/es/splitter/hooks/useResizable.js
generated
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
import * as React from 'react';
|
||||
function getShowCollapsibleIcon(prev, next) {
|
||||
if (prev.collapsible && next.collapsible) {
|
||||
if (prev.showCollapsibleIcon === true || next.showCollapsibleIcon === true) {
|
||||
return true;
|
||||
}
|
||||
if (prev.showCollapsibleIcon === 'auto' || next.showCollapsibleIcon === 'auto') {
|
||||
return 'auto';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (prev.collapsible) {
|
||||
return prev.showCollapsibleIcon;
|
||||
}
|
||||
if (next.collapsible) {
|
||||
return next.showCollapsibleIcon;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
export default function useResizable(items, pxSizes, isRTL) {
|
||||
return React.useMemo(() => {
|
||||
const resizeInfos = [];
|
||||
for (let i = 0; i < items.length - 1; i += 1) {
|
||||
const prevItem = items[i];
|
||||
const nextItem = items[i + 1];
|
||||
const prevSize = pxSizes[i];
|
||||
const nextSize = pxSizes[i + 1];
|
||||
const {
|
||||
resizable: prevResizable = true,
|
||||
min: prevMin,
|
||||
collapsible: prevCollapsible
|
||||
} = prevItem;
|
||||
const {
|
||||
resizable: nextResizable = true,
|
||||
min: nextMin,
|
||||
collapsible: nextCollapsible
|
||||
} = nextItem;
|
||||
const mergedResizable =
|
||||
// Both need to be resizable
|
||||
prevResizable && nextResizable && (
|
||||
// Prev is not collapsed and limit min size
|
||||
prevSize !== 0 || !prevMin) && (
|
||||
// Next is not collapsed and limit min size
|
||||
nextSize !== 0 || !nextMin);
|
||||
const prevEndCollapsible = !!prevCollapsible.end && prevSize > 0;
|
||||
const nextStartExpandable = !!nextCollapsible.start && nextSize === 0 && prevSize > 0;
|
||||
const startCollapsible = prevEndCollapsible || nextStartExpandable;
|
||||
const nextStartCollapsible = !!nextCollapsible.start && nextSize > 0;
|
||||
const prevEndExpandable = !!prevCollapsible.end && prevSize === 0 && nextSize > 0;
|
||||
const endCollapsible = nextStartCollapsible || prevEndExpandable;
|
||||
const showStartCollapsibleIcon = getShowCollapsibleIcon({
|
||||
collapsible: prevEndCollapsible,
|
||||
showCollapsibleIcon: prevCollapsible.showCollapsibleIcon
|
||||
}, {
|
||||
collapsible: nextStartExpandable,
|
||||
showCollapsibleIcon: nextCollapsible.showCollapsibleIcon
|
||||
});
|
||||
const showEndCollapsibleIcon = getShowCollapsibleIcon({
|
||||
collapsible: nextStartCollapsible,
|
||||
showCollapsibleIcon: nextCollapsible.showCollapsibleIcon
|
||||
}, {
|
||||
collapsible: prevEndExpandable,
|
||||
showCollapsibleIcon: prevCollapsible.showCollapsibleIcon
|
||||
});
|
||||
resizeInfos[i] = {
|
||||
resizable: mergedResizable,
|
||||
startCollapsible: !!(isRTL ? endCollapsible : startCollapsible),
|
||||
endCollapsible: !!(isRTL ? startCollapsible : endCollapsible),
|
||||
showStartCollapsibleIcon: isRTL ? showEndCollapsibleIcon : showStartCollapsibleIcon,
|
||||
showEndCollapsibleIcon: isRTL ? showStartCollapsibleIcon : showEndCollapsibleIcon
|
||||
};
|
||||
}
|
||||
return resizeInfos;
|
||||
}, [pxSizes, items, isRTL]);
|
||||
}
|
||||
6
frontend/node_modules/antd/es/splitter/hooks/useResize.d.ts
generated
vendored
Normal file
6
frontend/node_modules/antd/es/splitter/hooks/useResize.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import type { ItemType } from './useItems';
|
||||
import type { ResizableInfo } from './useResizable';
|
||||
/**
|
||||
* Handle user drag resize logic.
|
||||
*/
|
||||
export default function useResize(items: ItemType[], resizableInfos: ResizableInfo[], percentSizes: number[], containerSize: number | undefined, updateSizes: (sizes: number[]) => void, isRTL: boolean): readonly [(index: number) => void, (index: number, offset: number) => number[], () => void, (index: number, type: "start" | "end") => number[], number | undefined];
|
||||
128
frontend/node_modules/antd/es/splitter/hooks/useResize.js
generated
vendored
Normal file
128
frontend/node_modules/antd/es/splitter/hooks/useResize.js
generated
vendored
Normal file
@@ -0,0 +1,128 @@
|
||||
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
||||
import * as React from 'react';
|
||||
import { getPtg } from './useSizes';
|
||||
/**
|
||||
* Handle user drag resize logic.
|
||||
*/
|
||||
export default function useResize(items, resizableInfos, percentSizes, containerSize, updateSizes, isRTL) {
|
||||
const limitSizes = items.map(item => [item.min, item.max]);
|
||||
const mergedContainerSize = containerSize || 0;
|
||||
const ptg2px = ptg => ptg * mergedContainerSize;
|
||||
// ======================== Resize ========================
|
||||
function getLimitSize(str, defaultLimit) {
|
||||
if (typeof str === 'string') {
|
||||
return ptg2px(getPtg(str));
|
||||
}
|
||||
return str !== null && str !== void 0 ? str : defaultLimit;
|
||||
}
|
||||
// Real px sizes
|
||||
const [cacheSizes, setCacheSizes] = React.useState([]);
|
||||
const cacheCollapsedSize = React.useRef([]);
|
||||
/**
|
||||
* When start drag, check the direct is `start` or `end`.
|
||||
* This will handle when 2 splitter bar are in the same position.
|
||||
*/
|
||||
const [movingIndex, setMovingIndex] = React.useState(null);
|
||||
const getPxSizes = () => percentSizes.map(ptg2px);
|
||||
const onOffsetStart = index => {
|
||||
setCacheSizes(getPxSizes());
|
||||
setMovingIndex({
|
||||
index,
|
||||
confirmed: false
|
||||
});
|
||||
};
|
||||
const onOffsetUpdate = (index, offset) => {
|
||||
var _a;
|
||||
// First time trigger move index update is not sync in the state
|
||||
let confirmedIndex = null;
|
||||
// We need to know what the real index is.
|
||||
if ((!movingIndex || !movingIndex.confirmed) && offset !== 0) {
|
||||
// Search for the real index
|
||||
if (offset > 0) {
|
||||
confirmedIndex = index;
|
||||
setMovingIndex({
|
||||
index,
|
||||
confirmed: true
|
||||
});
|
||||
} else {
|
||||
for (let i = index; i >= 0; i -= 1) {
|
||||
if (cacheSizes[i] > 0 && resizableInfos[i].resizable) {
|
||||
confirmedIndex = i;
|
||||
setMovingIndex({
|
||||
index: i,
|
||||
confirmed: true
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const mergedIndex = (_a = confirmedIndex !== null && confirmedIndex !== void 0 ? confirmedIndex : movingIndex === null || movingIndex === void 0 ? void 0 : movingIndex.index) !== null && _a !== void 0 ? _a : index;
|
||||
const numSizes = _toConsumableArray(cacheSizes);
|
||||
const nextIndex = mergedIndex + 1;
|
||||
// Get boundary
|
||||
const startMinSize = getLimitSize(limitSizes[mergedIndex][0], 0);
|
||||
const endMinSize = getLimitSize(limitSizes[nextIndex][0], 0);
|
||||
const startMaxSize = getLimitSize(limitSizes[mergedIndex][1], mergedContainerSize);
|
||||
const endMaxSize = getLimitSize(limitSizes[nextIndex][1], mergedContainerSize);
|
||||
let mergedOffset = offset;
|
||||
// Align with the boundary
|
||||
if (numSizes[mergedIndex] + mergedOffset < startMinSize) {
|
||||
mergedOffset = startMinSize - numSizes[mergedIndex];
|
||||
}
|
||||
if (numSizes[nextIndex] - mergedOffset < endMinSize) {
|
||||
mergedOffset = numSizes[nextIndex] - endMinSize;
|
||||
}
|
||||
if (numSizes[mergedIndex] + mergedOffset > startMaxSize) {
|
||||
mergedOffset = startMaxSize - numSizes[mergedIndex];
|
||||
}
|
||||
if (numSizes[nextIndex] - mergedOffset > endMaxSize) {
|
||||
mergedOffset = numSizes[nextIndex] - endMaxSize;
|
||||
}
|
||||
// Do offset
|
||||
numSizes[mergedIndex] += mergedOffset;
|
||||
numSizes[nextIndex] -= mergedOffset;
|
||||
updateSizes(numSizes);
|
||||
return numSizes;
|
||||
};
|
||||
const onOffsetEnd = () => {
|
||||
setMovingIndex(null);
|
||||
};
|
||||
// ======================= Collapse =======================
|
||||
const onCollapse = (index, type) => {
|
||||
const currentSizes = getPxSizes();
|
||||
const adjustedType = isRTL ? type === 'start' ? 'end' : 'start' : type;
|
||||
const currentIndex = adjustedType === 'start' ? index : index + 1;
|
||||
const targetIndex = adjustedType === 'start' ? index + 1 : index;
|
||||
const currentSize = currentSizes[currentIndex];
|
||||
const targetSize = currentSizes[targetIndex];
|
||||
if (currentSize !== 0 && targetSize !== 0) {
|
||||
// Collapse directly
|
||||
currentSizes[currentIndex] = 0;
|
||||
currentSizes[targetIndex] += currentSize;
|
||||
cacheCollapsedSize.current[index] = currentSize;
|
||||
} else {
|
||||
const totalSize = currentSize + targetSize;
|
||||
const currentSizeMin = getLimitSize(limitSizes[currentIndex][0], 0);
|
||||
const currentSizeMax = getLimitSize(limitSizes[currentIndex][1], mergedContainerSize);
|
||||
const targetSizeMin = getLimitSize(limitSizes[targetIndex][0], 0);
|
||||
const targetSizeMax = getLimitSize(limitSizes[targetIndex][1], mergedContainerSize);
|
||||
const limitStart = Math.max(currentSizeMin, totalSize - targetSizeMax);
|
||||
const limitEnd = Math.min(currentSizeMax, totalSize - targetSizeMin);
|
||||
const halfOffset = targetSizeMin || (limitEnd - limitStart) / 2;
|
||||
const targetCacheCollapsedSize = cacheCollapsedSize.current[index];
|
||||
const currentCacheCollapsedSize = totalSize - targetCacheCollapsedSize;
|
||||
const shouldUseCache = targetCacheCollapsedSize && targetCacheCollapsedSize <= targetSizeMax && targetCacheCollapsedSize >= targetSizeMin && currentCacheCollapsedSize <= currentSizeMax && currentCacheCollapsedSize >= currentSizeMin;
|
||||
if (shouldUseCache) {
|
||||
currentSizes[targetIndex] = targetCacheCollapsedSize;
|
||||
currentSizes[currentIndex] = currentCacheCollapsedSize;
|
||||
} else {
|
||||
currentSizes[currentIndex] -= halfOffset;
|
||||
currentSizes[targetIndex] += halfOffset;
|
||||
}
|
||||
}
|
||||
updateSizes(currentSizes);
|
||||
return currentSizes;
|
||||
};
|
||||
return [onOffsetStart, onOffsetUpdate, onOffsetEnd, onCollapse, movingIndex === null || movingIndex === void 0 ? void 0 : movingIndex.index];
|
||||
}
|
||||
8
frontend/node_modules/antd/es/splitter/hooks/useSizes.d.ts
generated
vendored
Normal file
8
frontend/node_modules/antd/es/splitter/hooks/useSizes.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import React from 'react';
|
||||
import type { PanelProps } from '../interface';
|
||||
export declare function getPtg(str: string): number;
|
||||
/**
|
||||
* Save the size state.
|
||||
* Align the size into flex percentage base.
|
||||
*/
|
||||
export default function useSizes(items: PanelProps[], containerSize?: number): readonly [(string | number | undefined)[], number[], number[], number[], number[], React.Dispatch<React.SetStateAction<(string | number | undefined)[]>>];
|
||||
68
frontend/node_modules/antd/es/splitter/hooks/useSizes.js
generated
vendored
Normal file
68
frontend/node_modules/antd/es/splitter/hooks/useSizes.js
generated
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
import React from 'react';
|
||||
import { autoPtgSizes } from './sizeUtil';
|
||||
export function getPtg(str) {
|
||||
return Number(str.slice(0, -1)) / 100;
|
||||
}
|
||||
function isPtg(itemSize) {
|
||||
return typeof itemSize === 'string' && itemSize.endsWith('%');
|
||||
}
|
||||
/**
|
||||
* Save the size state.
|
||||
* Align the size into flex percentage base.
|
||||
*/
|
||||
export default function useSizes(items, containerSize) {
|
||||
const propSizes = items.map(item => item.size);
|
||||
const itemsCount = items.length;
|
||||
const mergedContainerSize = containerSize || 0;
|
||||
const ptg2px = ptg => ptg * mergedContainerSize;
|
||||
// We do not need care the size state match the `items` length in `useState`.
|
||||
// It will calculate later.
|
||||
const [innerSizes, setInnerSizes] = React.useState(() => items.map(item => item.defaultSize));
|
||||
const sizes = React.useMemo(() => {
|
||||
var _a;
|
||||
const mergedSizes = [];
|
||||
for (let i = 0; i < itemsCount; i += 1) {
|
||||
mergedSizes[i] = (_a = propSizes[i]) !== null && _a !== void 0 ? _a : innerSizes[i];
|
||||
}
|
||||
return mergedSizes;
|
||||
}, [itemsCount, innerSizes, propSizes]);
|
||||
const postPercentMinSizes = React.useMemo(() => items.map(item => {
|
||||
if (isPtg(item.min)) {
|
||||
return getPtg(item.min);
|
||||
}
|
||||
return (item.min || 0) / mergedContainerSize;
|
||||
}), [items, mergedContainerSize]);
|
||||
const postPercentMaxSizes = React.useMemo(() => items.map(item => {
|
||||
if (isPtg(item.max)) {
|
||||
return getPtg(item.max);
|
||||
}
|
||||
return (item.max || mergedContainerSize) / mergedContainerSize;
|
||||
}), [items, mergedContainerSize]);
|
||||
// Post handle the size. Will do:
|
||||
// 1. Convert all the px into percentage if not empty.
|
||||
// 2. Get rest percentage for exist percentage.
|
||||
// 3. Fill the rest percentage into empty item.
|
||||
const postPercentSizes = React.useMemo(() => {
|
||||
const ptgList = [];
|
||||
// Fill default percentage
|
||||
for (let i = 0; i < itemsCount; i += 1) {
|
||||
const itemSize = sizes[i];
|
||||
if (isPtg(itemSize)) {
|
||||
ptgList[i] = getPtg(itemSize);
|
||||
} else if (itemSize || itemSize === 0) {
|
||||
const num = Number(itemSize);
|
||||
if (!Number.isNaN(num)) {
|
||||
ptgList[i] = num / mergedContainerSize;
|
||||
}
|
||||
} else {
|
||||
ptgList[i] = undefined;
|
||||
}
|
||||
}
|
||||
// Use autoPtgSizes to handle the undefined sizes
|
||||
return autoPtgSizes(ptgList, postPercentMinSizes, postPercentMaxSizes);
|
||||
}, [sizes, mergedContainerSize, postPercentMinSizes, postPercentMaxSizes]);
|
||||
const postPxSizes = React.useMemo(() => postPercentSizes.map(ptg2px), [postPercentSizes, mergedContainerSize]);
|
||||
// If ssr, we will use the size from developer config first.
|
||||
const panelSizes = React.useMemo(() => containerSize ? postPxSizes : sizes, [postPxSizes, containerSize]);
|
||||
return [panelSizes, postPxSizes, postPercentSizes, postPercentMinSizes, postPercentMaxSizes, setInnerSizes];
|
||||
}
|
||||
Reference in New Issue
Block a user