@yibozhang/pro-table 0.1.7 → 0.1.8
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/bundles/yibozhang-pro-table.umd.js +177 -0
- package/bundles/yibozhang-pro-table.umd.js.map +1 -1
- package/bundles/yibozhang-pro-table.umd.min.js +1 -1
- package/bundles/yibozhang-pro-table.umd.min.js.map +1 -1
- package/esm2015/lib/utils/select-width-detector.js +176 -0
- package/esm2015/public-api.js +2 -1
- package/fesm2015/yibozhang-pro-table.js +177 -1
- package/fesm2015/yibozhang-pro-table.js.map +1 -1
- package/lib/utils/select-width-detector.d.ts +6 -0
- package/lib/utils/select-width-detector.d.ts.map +1 -0
- package/package.json +1 -1
- package/public-api.d.ts +1 -0
- package/public-api.d.ts.map +1 -1
- package/yibozhang-pro-table.metadata.json +1 -1
|
@@ -3594,6 +3594,182 @@
|
|
|
3594
3594
|
});
|
|
3595
3595
|
}
|
|
3596
3596
|
|
|
3597
|
+
/**
|
|
3598
|
+
* 自动检测 nz-select 最近的父元素宽度,并设置给 nz-select
|
|
3599
|
+
* 当父元素宽度变化时,自动更新 nz-select 的宽度
|
|
3600
|
+
*/
|
|
3601
|
+
function initSelectWidthDetector() {
|
|
3602
|
+
if (typeof window === 'undefined' || typeof document === 'undefined') {
|
|
3603
|
+
return;
|
|
3604
|
+
}
|
|
3605
|
+
// 获取最近的父元素(排除自身)
|
|
3606
|
+
function getClosestParent(element) {
|
|
3607
|
+
var parent = element.parentElement;
|
|
3608
|
+
while (parent && parent !== document.body) {
|
|
3609
|
+
// 如果父元素有明确的宽度(非 auto),则返回该父元素
|
|
3610
|
+
var computedStyle = window.getComputedStyle(parent);
|
|
3611
|
+
var width = computedStyle.width;
|
|
3612
|
+
if (width && width !== 'auto' && width !== '0px') {
|
|
3613
|
+
return parent;
|
|
3614
|
+
}
|
|
3615
|
+
parent = parent.parentElement;
|
|
3616
|
+
}
|
|
3617
|
+
// 如果没找到有明确宽度的父元素,返回直接父元素
|
|
3618
|
+
return element.parentElement;
|
|
3619
|
+
}
|
|
3620
|
+
// 找到实际的 select 元素(nz-select 组件渲染后的 DOM 元素)
|
|
3621
|
+
function findActualSelectElement(element) {
|
|
3622
|
+
var _a;
|
|
3623
|
+
// 如果已经是 ant-select 元素,直接返回
|
|
3624
|
+
if ((_a = element.classList) === null || _a === void 0 ? void 0 : _a.contains('ant-select')) {
|
|
3625
|
+
return element;
|
|
3626
|
+
}
|
|
3627
|
+
// 如果是 nz-select 组件标签,查找其渲染后的 ant-select 元素
|
|
3628
|
+
if (element.tagName === 'NZ-SELECT') {
|
|
3629
|
+
var actualSelect_1 = element.querySelector('.ant-select');
|
|
3630
|
+
return actualSelect_1 || element;
|
|
3631
|
+
}
|
|
3632
|
+
// 在子元素中查找 ant-select
|
|
3633
|
+
var actualSelect = element.querySelector('.ant-select');
|
|
3634
|
+
return actualSelect || element;
|
|
3635
|
+
}
|
|
3636
|
+
// 获取原始的 nz-select 组件元素(用于读取 custom-width 属性)
|
|
3637
|
+
function getOriginalSelectElement(element) {
|
|
3638
|
+
// 如果已经是 nz-select 组件标签,直接返回
|
|
3639
|
+
if (element.tagName === 'NZ-SELECT') {
|
|
3640
|
+
return element;
|
|
3641
|
+
}
|
|
3642
|
+
// 向上查找 nz-select 组件标签
|
|
3643
|
+
var parent = element.parentElement;
|
|
3644
|
+
while (parent && parent !== document.body) {
|
|
3645
|
+
if (parent.tagName === 'NZ-SELECT') {
|
|
3646
|
+
return parent;
|
|
3647
|
+
}
|
|
3648
|
+
parent = parent.parentElement;
|
|
3649
|
+
}
|
|
3650
|
+
return null;
|
|
3651
|
+
}
|
|
3652
|
+
// 检查并设置 nz-select 的宽度
|
|
3653
|
+
function setSelectWidth(selectElement) {
|
|
3654
|
+
var actualSelect = findActualSelectElement(selectElement);
|
|
3655
|
+
if (!actualSelect) {
|
|
3656
|
+
return;
|
|
3657
|
+
}
|
|
3658
|
+
// 检查是否有自定义宽度属性
|
|
3659
|
+
var originalSelect = getOriginalSelectElement(selectElement);
|
|
3660
|
+
if (originalSelect) {
|
|
3661
|
+
var customWidth = originalSelect.getAttribute('custom-width');
|
|
3662
|
+
if (customWidth) {
|
|
3663
|
+
// 使用自定义宽度
|
|
3664
|
+
actualSelect.style.width = customWidth;
|
|
3665
|
+
return;
|
|
3666
|
+
}
|
|
3667
|
+
}
|
|
3668
|
+
// 如果没有自定义宽度,使用计算出的父元素宽度
|
|
3669
|
+
var parent = getClosestParent(actualSelect);
|
|
3670
|
+
if (parent) {
|
|
3671
|
+
var parentWidth = parent.offsetWidth;
|
|
3672
|
+
if (parentWidth > 0) {
|
|
3673
|
+
// 设置宽度,可以减去一些 padding/margin 来避免溢出
|
|
3674
|
+
// 这里直接使用父元素宽度,如果需要可以调整
|
|
3675
|
+
actualSelect.style.width = parentWidth + "px";
|
|
3676
|
+
}
|
|
3677
|
+
}
|
|
3678
|
+
}
|
|
3679
|
+
// 使用 MutationObserver 监听 DOM 变化
|
|
3680
|
+
var observer = new MutationObserver(function (mutations) {
|
|
3681
|
+
mutations.forEach(function (mutation) {
|
|
3682
|
+
mutation.addedNodes.forEach(function (node) {
|
|
3683
|
+
var _a, _b, _c;
|
|
3684
|
+
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
3685
|
+
var element_1 = node;
|
|
3686
|
+
// 检查是否是 nz-select 组件标签
|
|
3687
|
+
if (element_1.tagName === 'NZ-SELECT') {
|
|
3688
|
+
// 等待 Angular 组件渲染完成
|
|
3689
|
+
setTimeout(function () {
|
|
3690
|
+
setSelectWidth(element_1);
|
|
3691
|
+
observeResize(element_1);
|
|
3692
|
+
}, 100);
|
|
3693
|
+
}
|
|
3694
|
+
// 检查是否是 ant-select 元素(nz-select 渲染后的实际元素)
|
|
3695
|
+
if ((_a = element_1.classList) === null || _a === void 0 ? void 0 : _a.contains('ant-select')) {
|
|
3696
|
+
setTimeout(function () {
|
|
3697
|
+
setSelectWidth(element_1);
|
|
3698
|
+
observeResize(element_1);
|
|
3699
|
+
}, 0);
|
|
3700
|
+
}
|
|
3701
|
+
// 检查子元素中是否有 nz-select 或 ant-select
|
|
3702
|
+
var nzSelects = (_b = element_1.querySelectorAll) === null || _b === void 0 ? void 0 : _b.call(element_1, 'nz-select');
|
|
3703
|
+
nzSelects === null || nzSelects === void 0 ? void 0 : nzSelects.forEach(function (select) {
|
|
3704
|
+
setTimeout(function () {
|
|
3705
|
+
setSelectWidth(select);
|
|
3706
|
+
observeResize(select);
|
|
3707
|
+
}, 100);
|
|
3708
|
+
});
|
|
3709
|
+
var antSelects = (_c = element_1.querySelectorAll) === null || _c === void 0 ? void 0 : _c.call(element_1, '.ant-select');
|
|
3710
|
+
antSelects === null || antSelects === void 0 ? void 0 : antSelects.forEach(function (select) {
|
|
3711
|
+
setTimeout(function () {
|
|
3712
|
+
setSelectWidth(select);
|
|
3713
|
+
observeResize(select);
|
|
3714
|
+
}, 0);
|
|
3715
|
+
});
|
|
3716
|
+
}
|
|
3717
|
+
});
|
|
3718
|
+
});
|
|
3719
|
+
});
|
|
3720
|
+
// 使用 ResizeObserver 监听父元素尺寸变化
|
|
3721
|
+
var resizeObserverMap = new WeakMap();
|
|
3722
|
+
function observeResize(selectElement) {
|
|
3723
|
+
if (resizeObserverMap.has(selectElement)) {
|
|
3724
|
+
return;
|
|
3725
|
+
}
|
|
3726
|
+
if (typeof window.ResizeObserver !== 'undefined') {
|
|
3727
|
+
var actualSelect = findActualSelectElement(selectElement);
|
|
3728
|
+
if (!actualSelect) {
|
|
3729
|
+
return;
|
|
3730
|
+
}
|
|
3731
|
+
var parent = getClosestParent(actualSelect);
|
|
3732
|
+
if (!parent) {
|
|
3733
|
+
return;
|
|
3734
|
+
}
|
|
3735
|
+
var resizeObserver = new window.ResizeObserver(function () {
|
|
3736
|
+
setSelectWidth(selectElement);
|
|
3737
|
+
});
|
|
3738
|
+
resizeObserver.observe(parent);
|
|
3739
|
+
resizeObserverMap.set(selectElement, resizeObserver);
|
|
3740
|
+
}
|
|
3741
|
+
}
|
|
3742
|
+
// 开始监听 DOM 变化
|
|
3743
|
+
observer.observe(document.body, {
|
|
3744
|
+
childList: true,
|
|
3745
|
+
subtree: true,
|
|
3746
|
+
});
|
|
3747
|
+
// 检查已存在的 nz-select 和 ant-select
|
|
3748
|
+
var checkExistingSelects = function () {
|
|
3749
|
+
// 检查 nz-select 组件标签
|
|
3750
|
+
document.querySelectorAll('nz-select').forEach(function (element) {
|
|
3751
|
+
setTimeout(function () {
|
|
3752
|
+
setSelectWidth(element);
|
|
3753
|
+
observeResize(element);
|
|
3754
|
+
}, 100);
|
|
3755
|
+
});
|
|
3756
|
+
// 检查 ant-select 元素
|
|
3757
|
+
document.querySelectorAll('.ant-select').forEach(function (element) {
|
|
3758
|
+
setTimeout(function () {
|
|
3759
|
+
setSelectWidth(element);
|
|
3760
|
+
observeResize(element);
|
|
3761
|
+
}, 0);
|
|
3762
|
+
});
|
|
3763
|
+
};
|
|
3764
|
+
// 延迟执行,确保 DOM 已完全加载
|
|
3765
|
+
if (document.readyState === 'loading') {
|
|
3766
|
+
document.addEventListener('DOMContentLoaded', checkExistingSelects);
|
|
3767
|
+
}
|
|
3768
|
+
else {
|
|
3769
|
+
checkExistingSelects();
|
|
3770
|
+
}
|
|
3771
|
+
}
|
|
3772
|
+
|
|
3597
3773
|
/*
|
|
3598
3774
|
* Public API Surface of pro-table
|
|
3599
3775
|
*/
|
|
@@ -3616,6 +3792,7 @@
|
|
|
3616
3792
|
exports.TableSearchBarModule = TableSearchBarModule;
|
|
3617
3793
|
exports.TrimInputModule = TrimInputModule;
|
|
3618
3794
|
exports.initModalWidthDetector = initModalWidthDetector;
|
|
3795
|
+
exports.initSelectWidthDetector = initSelectWidthDetector;
|
|
3619
3796
|
exports["ɵ0"] = ɵ0;
|
|
3620
3797
|
exports["ɵ1"] = ɵ1;
|
|
3621
3798
|
exports["ɵ2"] = ɵ2;
|