This commit is contained in:
2025-09-19 14:25:20 +08:00
parent 269893a435
commit fbf3f77229
24949 changed files with 2839404 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
export { useContainer } from './useContainer';
export { useResize } from './useResize';
export { useSize, isPct, isPx, getPct, getPx } from './useSize';

View File

@@ -0,0 +1,18 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var useContainer = require('./useContainer.js');
var useResize = require('./useResize.js');
var useSize = require('./useSize.js');
exports.useContainer = useContainer.useContainer;
exports.useResize = useResize.useResize;
exports.getPct = useSize.getPct;
exports.getPx = useSize.getPx;
exports.isPct = useSize.isPct;
exports.isPx = useSize.isPx;
exports.useSize = useSize.useSize;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;"}

View File

@@ -0,0 +1,5 @@
import type { Ref } from 'vue';
export declare function useContainer(layout: Ref<'horizontal' | 'vertical'>): {
containerEl: Ref<HTMLDivElement | undefined>;
containerSize: import("vue").ComputedRef<number>;
};

View File

@@ -0,0 +1,18 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var vue = require('vue');
var core = require('@vueuse/core');
function useContainer(layout) {
const containerEl = vue.ref();
const { width, height } = core.useElementSize(containerEl);
const containerSize = vue.computed(() => {
return layout.value === "horizontal" ? width.value : height.value;
});
return { containerEl, containerSize };
}
exports.useContainer = useContainer;
//# sourceMappingURL=useContainer.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"useContainer.js","sources":["../../../../../../../packages/components/splitter/src/hooks/useContainer.ts"],"sourcesContent":["import { computed, ref } from 'vue'\nimport { useElementSize } from '@vueuse/core'\n\nimport type { Ref } from 'vue'\n\nexport function useContainer(layout: Ref<'horizontal' | 'vertical'>) {\n const containerEl = ref<HTMLDivElement>()\n const { width, height } = useElementSize(containerEl)\n\n const containerSize = computed(() => {\n return layout.value === 'horizontal' ? width.value : height.value\n })\n\n return { containerEl, containerSize }\n}\n"],"names":["ref","useElementSize","computed"],"mappings":";;;;;;;AAEO,SAAS,YAAY,CAAC,MAAM,EAAE;AACrC,EAAE,MAAM,WAAW,GAAGA,OAAG,EAAE,CAAC;AAC5B,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAGC,mBAAc,CAAC,WAAW,CAAC,CAAC;AACxD,EAAE,MAAM,aAAa,GAAGC,YAAQ,CAAC,MAAM;AACvC,IAAI,OAAO,MAAM,CAAC,KAAK,KAAK,YAAY,GAAG,KAAK,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;AACtE,GAAG,CAAC,CAAC;AACL,EAAE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,CAAC;AACxC;;;;"}

View File

@@ -0,0 +1,9 @@
import type { PanelItemState } from '../type';
export declare function getCollapsible(collapsible: boolean | {
start?: boolean;
end?: boolean;
}): {
start?: boolean;
end?: boolean;
};
export declare function isCollapsible(panel: PanelItemState | null | undefined, size: number, nextPanel: PanelItemState | null | undefined, nextSize: number): boolean;

View File

@@ -0,0 +1,28 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var shared = require('@vue/shared');
function getCollapsible(collapsible) {
if (collapsible && shared.isObject(collapsible)) {
return collapsible;
}
return {
start: !!collapsible,
end: !!collapsible
};
}
function isCollapsible(panel, size, nextPanel, nextSize) {
if ((panel == null ? void 0 : panel.collapsible.end) && size > 0) {
return true;
}
if ((nextPanel == null ? void 0 : nextPanel.collapsible.start) && nextSize === 0 && size > 0) {
return true;
}
return false;
}
exports.getCollapsible = getCollapsible;
exports.isCollapsible = isCollapsible;
//# sourceMappingURL=usePanel.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"usePanel.js","sources":["../../../../../../../packages/components/splitter/src/hooks/usePanel.ts"],"sourcesContent":["import { isObject } from '@element-plus/utils'\n\nimport type { PanelItemState } from '../type'\n\nexport function getCollapsible(\n collapsible: boolean | { start?: boolean; end?: boolean }\n) {\n if (collapsible && isObject(collapsible)) {\n return collapsible\n }\n return {\n start: !!collapsible,\n end: !!collapsible,\n }\n}\n\nexport function isCollapsible(\n panel: PanelItemState | null | undefined,\n size: number,\n nextPanel: PanelItemState | null | undefined,\n nextSize: number\n) {\n // If the current panel is collapsible and has size, then it can be collapsed\n if (panel?.collapsible.end && size > 0) {\n return true\n }\n\n // If the next panel is collapsible and has no size, but the current panel has size, then it can be collapsed\n if (nextPanel?.collapsible.start && nextSize === 0 && size > 0) {\n return true\n }\n\n return false\n}\n"],"names":["isObject"],"mappings":";;;;;;AACO,SAAS,cAAc,CAAC,WAAW,EAAE;AAC5C,EAAE,IAAI,WAAW,IAAIA,eAAQ,CAAC,WAAW,CAAC,EAAE;AAC5C,IAAI,OAAO,WAAW,CAAC;AACvB,GAAG;AACH,EAAE,OAAO;AACT,IAAI,KAAK,EAAE,CAAC,CAAC,WAAW;AACxB,IAAI,GAAG,EAAE,CAAC,CAAC,WAAW;AACtB,GAAG,CAAC;AACJ,CAAC;AACM,SAAS,aAAa,CAAC,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE;AAChE,EAAE,IAAI,CAAC,KAAK,IAAI,IAAI,GAAG,KAAK,CAAC,GAAG,KAAK,CAAC,WAAW,CAAC,GAAG,KAAK,IAAI,GAAG,CAAC,EAAE;AACpE,IAAI,OAAO,IAAI,CAAC;AAChB,GAAG;AACH,EAAE,IAAI,CAAC,SAAS,IAAI,IAAI,GAAG,KAAK,CAAC,GAAG,SAAS,CAAC,WAAW,CAAC,KAAK,KAAK,QAAQ,KAAK,CAAC,IAAI,IAAI,GAAG,CAAC,EAAE;AAChG,IAAI,OAAO,IAAI,CAAC;AAChB,GAAG;AACH,EAAE,OAAO,KAAK,CAAC;AACf;;;;;"}

View File

@@ -0,0 +1,13 @@
import type { ComputedRef, Ref } from 'vue';
import type { PanelItemState } from '../type';
export declare function useResize(panels: Ref<PanelItemState[]>, containerSize: ComputedRef<number>, pxSizes: ComputedRef<number[]>, lazy: Ref<boolean>): {
lazyOffset: Ref<number>;
onMoveStart: (index: number) => void;
onMoving: (index: number, offset: number) => void;
onMoveEnd: () => void;
movingIndex: Ref<{
index: number;
confirmed: boolean;
} | null>;
onCollapse: (index: number, type: "start" | "end") => void;
};

View File

@@ -0,0 +1,129 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var vue = require('vue');
var useSize = require('./useSize.js');
var shared = require('@vue/shared');
function useResize(panels, containerSize, pxSizes, lazy) {
const ptg2px = (ptg) => ptg * containerSize.value || 0;
function getLimitSize(str, defaultLimit) {
if (useSize.isPct(str)) {
return ptg2px(useSize.getPct(str));
} else if (useSize.isPx(str)) {
return useSize.getPx(str);
}
return str != null ? str : defaultLimit;
}
const lazyOffset = vue.ref(0);
const movingIndex = vue.ref(null);
let cachePxSizes = [];
let updatePanelSizes = shared.NOOP;
const limitSizes = vue.computed(() => panels.value.map((item) => [item.min, item.max]));
vue.watch(lazy, () => {
if (lazyOffset.value) {
const mouseup = new MouseEvent("mouseup", { bubbles: true });
window.dispatchEvent(mouseup);
}
});
const onMoveStart = (index) => {
lazyOffset.value = 0;
movingIndex.value = { index, confirmed: false };
cachePxSizes = pxSizes.value;
};
const onMoving = (index, offset) => {
var _a, _b;
let confirmedIndex = null;
if ((!movingIndex.value || !movingIndex.value.confirmed) && offset !== 0) {
if (offset > 0) {
confirmedIndex = index;
movingIndex.value = { index, confirmed: true };
} else {
for (let i = index; i >= 0; i -= 1) {
if (cachePxSizes[i] > 0) {
confirmedIndex = i;
movingIndex.value = { index: i, confirmed: true };
break;
}
}
}
}
const mergedIndex = (_b = confirmedIndex != null ? confirmedIndex : (_a = movingIndex.value) == null ? void 0 : _a.index) != null ? _b : index;
const numSizes = [...cachePxSizes];
const nextIndex = mergedIndex + 1;
const startMinSize = getLimitSize(limitSizes.value[mergedIndex][0], 0);
const endMinSize = getLimitSize(limitSizes.value[nextIndex][0], 0);
const startMaxSize = getLimitSize(limitSizes.value[mergedIndex][1], containerSize.value || 0);
const endMaxSize = getLimitSize(limitSizes.value[nextIndex][1], containerSize.value || 0);
let mergedOffset = offset;
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;
}
numSizes[mergedIndex] += mergedOffset;
numSizes[nextIndex] -= mergedOffset;
lazyOffset.value = mergedOffset;
updatePanelSizes = () => {
panels.value.forEach((panel, index2) => {
panel.size = numSizes[index2];
});
updatePanelSizes = shared.NOOP;
};
if (!lazy.value) {
updatePanelSizes();
}
};
const onMoveEnd = () => {
if (lazy.value) {
updatePanelSizes();
}
lazyOffset.value = 0;
movingIndex.value = null;
cachePxSizes = [];
};
const cacheCollapsedSize = [];
const onCollapse = (index, type) => {
if (!cacheCollapsedSize.length) {
cacheCollapsedSize.push(...pxSizes.value);
}
const currentSizes = pxSizes.value;
const currentIndex = type === "start" ? index : index + 1;
const targetIndex = type === "start" ? index + 1 : index;
const currentSize = currentSizes[currentIndex];
const targetSize = currentSizes[targetIndex];
if (currentSize !== 0 && targetSize !== 0) {
currentSizes[currentIndex] = 0;
currentSizes[targetIndex] += currentSize;
cacheCollapsedSize[index] = currentSize;
} else {
const totalSize = currentSize + targetSize;
const targetCacheCollapsedSize = cacheCollapsedSize[index];
const currentCacheCollapsedSize = totalSize - targetCacheCollapsedSize;
currentSizes[targetIndex] = targetCacheCollapsedSize;
currentSizes[currentIndex] = currentCacheCollapsedSize;
}
panels.value.forEach((panel, index2) => {
panel.size = currentSizes[index2];
});
};
return {
lazyOffset,
onMoveStart,
onMoving,
onMoveEnd,
movingIndex,
onCollapse
};
}
exports.useResize = useResize;
//# sourceMappingURL=useResize.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,10 @@
import type { ComputedRef, Ref } from 'vue';
import type { PanelItemState } from '../type';
export declare function getPct(str: string): number;
export declare function getPx(str: string): number;
export declare function isPct(itemSize: string | number | undefined): itemSize is string;
export declare function isPx(itemSize: string | number | undefined): itemSize is string;
export declare function useSize(panels: Ref<PanelItemState[]>, containerSize: ComputedRef<number>): {
percentSizes: Ref<number[]>;
pxSizes: ComputedRef<number[]>;
};

View File

@@ -0,0 +1,64 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var vue = require('vue');
var shared = require('@vue/shared');
function getPct(str) {
return Number(str.slice(0, -1)) / 100;
}
function getPx(str) {
return Number(str.slice(0, -2));
}
function isPct(itemSize) {
return shared.isString(itemSize) && itemSize.endsWith("%");
}
function isPx(itemSize) {
return shared.isString(itemSize) && itemSize.endsWith("px");
}
function useSize(panels, containerSize) {
const propSizes = vue.computed(() => panels.value.map((i) => i.size));
const panelCounts = vue.computed(() => panels.value.length);
const percentSizes = vue.ref([]);
vue.watch([propSizes, panelCounts, containerSize], () => {
var _a;
let ptgList = [];
let emptyCount = 0;
for (let i = 0; i < panelCounts.value; i += 1) {
const itemSize = (_a = panels.value[i]) == null ? void 0 : _a.size;
if (isPct(itemSize)) {
ptgList[i] = getPct(itemSize);
} else if (isPx(itemSize)) {
ptgList[i] = getPx(itemSize) / containerSize.value;
} else if (itemSize || itemSize === 0) {
const num = Number(itemSize);
if (!Number.isNaN(num)) {
ptgList[i] = num / containerSize.value;
}
} else {
emptyCount += 1;
ptgList[i] = void 0;
}
}
const totalPtg = ptgList.reduce((acc, ptg) => acc + (ptg || 0), 0);
if (totalPtg > 1 || !emptyCount) {
const scale = 1 / totalPtg;
ptgList = ptgList.map((ptg) => ptg === void 0 ? 0 : ptg * scale);
} else {
const avgRest = (1 - totalPtg) / emptyCount;
ptgList = ptgList.map((ptg) => ptg === void 0 ? avgRest : ptg);
}
percentSizes.value = ptgList;
});
const ptg2px = (ptg) => ptg * containerSize.value;
const pxSizes = vue.computed(() => percentSizes.value.map(ptg2px));
return { percentSizes, pxSizes };
}
exports.getPct = getPct;
exports.getPx = getPx;
exports.isPct = isPct;
exports.isPx = isPx;
exports.useSize = useSize;
//# sourceMappingURL=useSize.js.map

File diff suppressed because one or more lines are too long