@v-c/overflow 0.0.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/LICENSE +21 -0
- package/dist/Item.cjs +111 -0
- package/dist/Item.d.ts +73 -0
- package/dist/Item.js +111 -0
- package/dist/Overflow.cjs +321 -0
- package/dist/Overflow.d.ts +100 -0
- package/dist/Overflow.js +321 -0
- package/dist/RawItem.cjs +47 -0
- package/dist/RawItem.d.ts +15 -0
- package/dist/RawItem.js +47 -0
- package/dist/context.cjs +24 -0
- package/dist/context.d.ts +25 -0
- package/dist/context.js +24 -0
- package/dist/hooks/channelUpdate.cjs +13 -0
- package/dist/hooks/channelUpdate.d.ts +1 -0
- package/dist/hooks/channelUpdate.js +13 -0
- package/dist/hooks/useEffectState.cjs +37 -0
- package/dist/hooks/useEffectState.d.ts +13 -0
- package/dist/hooks/useEffectState.js +37 -0
- package/dist/index.cjs +6 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +6 -0
- package/package.json +36 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 antdv-community
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/Item.cjs
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const vue = require("vue");
|
|
4
|
+
const ResizeObserver = require("@v-c/resize-observer");
|
|
5
|
+
const util = require("@v-c/util");
|
|
6
|
+
function _isSlot(s) {
|
|
7
|
+
return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !vue.isVNode(s);
|
|
8
|
+
}
|
|
9
|
+
const UNDEFINED = void 0;
|
|
10
|
+
const Item = /* @__PURE__ */ vue.defineComponent({
|
|
11
|
+
name: "OverflowItem",
|
|
12
|
+
inheritAttrs: false,
|
|
13
|
+
props: {
|
|
14
|
+
prefixCls: {
|
|
15
|
+
type: String,
|
|
16
|
+
required: true
|
|
17
|
+
},
|
|
18
|
+
item: Object,
|
|
19
|
+
class: {
|
|
20
|
+
type: [String, Object, Array],
|
|
21
|
+
default: void 0
|
|
22
|
+
},
|
|
23
|
+
style: Object,
|
|
24
|
+
renderItem: Function,
|
|
25
|
+
responsive: Boolean,
|
|
26
|
+
responsiveDisabled: Boolean,
|
|
27
|
+
itemKey: [String, Number],
|
|
28
|
+
registerSize: {
|
|
29
|
+
type: Function,
|
|
30
|
+
required: true
|
|
31
|
+
},
|
|
32
|
+
display: Boolean,
|
|
33
|
+
order: {
|
|
34
|
+
type: Number,
|
|
35
|
+
required: true
|
|
36
|
+
},
|
|
37
|
+
component: {
|
|
38
|
+
type: [String, Object, Function],
|
|
39
|
+
default: "div"
|
|
40
|
+
},
|
|
41
|
+
invalidate: Boolean
|
|
42
|
+
},
|
|
43
|
+
setup(props, {
|
|
44
|
+
slots,
|
|
45
|
+
attrs
|
|
46
|
+
}) {
|
|
47
|
+
const mergedHidden = vue.computed(() => props.responsive && !props.display);
|
|
48
|
+
function internalRegisterSize(width) {
|
|
49
|
+
const key = props.itemKey ?? props.order;
|
|
50
|
+
props.registerSize(key, width);
|
|
51
|
+
}
|
|
52
|
+
vue.onUnmounted(() => {
|
|
53
|
+
internalRegisterSize(null);
|
|
54
|
+
});
|
|
55
|
+
return () => {
|
|
56
|
+
const {
|
|
57
|
+
prefixCls,
|
|
58
|
+
invalidate,
|
|
59
|
+
item,
|
|
60
|
+
renderItem,
|
|
61
|
+
responsive,
|
|
62
|
+
responsiveDisabled,
|
|
63
|
+
order,
|
|
64
|
+
component: Component = "div",
|
|
65
|
+
style
|
|
66
|
+
} = props;
|
|
67
|
+
const children = slots.default?.();
|
|
68
|
+
const childNode = renderItem && item !== UNDEFINED ? renderItem(item, {
|
|
69
|
+
index: order
|
|
70
|
+
}) : children;
|
|
71
|
+
let overflowStyle;
|
|
72
|
+
if (!invalidate) {
|
|
73
|
+
overflowStyle = {
|
|
74
|
+
opacity: mergedHidden.value ? 0 : 1,
|
|
75
|
+
height: mergedHidden.value ? 0 : UNDEFINED,
|
|
76
|
+
overflowY: mergedHidden.value ? "hidden" : UNDEFINED,
|
|
77
|
+
order: responsive ? order : UNDEFINED,
|
|
78
|
+
pointerEvents: mergedHidden.value ? "none" : UNDEFINED,
|
|
79
|
+
position: mergedHidden.value ? "absolute" : UNDEFINED
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
const overflowProps = {};
|
|
83
|
+
if (mergedHidden.value) {
|
|
84
|
+
overflowProps["aria-hidden"] = true;
|
|
85
|
+
}
|
|
86
|
+
const itemNode = vue.createVNode(Component, vue.mergeProps({
|
|
87
|
+
"class": util.classNames(!invalidate && prefixCls, props.class),
|
|
88
|
+
"style": {
|
|
89
|
+
...overflowStyle,
|
|
90
|
+
...style
|
|
91
|
+
}
|
|
92
|
+
}, overflowProps, attrs), _isSlot(childNode) ? childNode : {
|
|
93
|
+
default: () => [childNode]
|
|
94
|
+
});
|
|
95
|
+
if (!responsive) {
|
|
96
|
+
return itemNode;
|
|
97
|
+
}
|
|
98
|
+
return vue.createVNode(ResizeObserver, {
|
|
99
|
+
"disabled": responsiveDisabled,
|
|
100
|
+
"onResize": ({
|
|
101
|
+
offsetWidth
|
|
102
|
+
}) => {
|
|
103
|
+
internalRegisterSize(offsetWidth);
|
|
104
|
+
}
|
|
105
|
+
}, {
|
|
106
|
+
default: () => itemNode
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
exports.default = Item;
|
package/dist/Item.d.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Key, VueNode } from '@v-c/util/dist/type';
|
|
2
|
+
import { CSSProperties, PropType } from 'vue';
|
|
3
|
+
declare const _default: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
|
|
4
|
+
prefixCls: {
|
|
5
|
+
type: StringConstructor;
|
|
6
|
+
required: true;
|
|
7
|
+
};
|
|
8
|
+
item: PropType<any>;
|
|
9
|
+
class: {
|
|
10
|
+
type: PropType<any>;
|
|
11
|
+
default: undefined;
|
|
12
|
+
};
|
|
13
|
+
style: PropType<CSSProperties>;
|
|
14
|
+
renderItem: PropType<(item: any, info: {
|
|
15
|
+
index: number;
|
|
16
|
+
}) => VueNode>;
|
|
17
|
+
responsive: BooleanConstructor;
|
|
18
|
+
responsiveDisabled: BooleanConstructor;
|
|
19
|
+
itemKey: PropType<Key>;
|
|
20
|
+
registerSize: {
|
|
21
|
+
type: PropType<(key: Key, width: number | null) => void>;
|
|
22
|
+
required: true;
|
|
23
|
+
};
|
|
24
|
+
display: BooleanConstructor;
|
|
25
|
+
order: {
|
|
26
|
+
type: NumberConstructor;
|
|
27
|
+
required: true;
|
|
28
|
+
};
|
|
29
|
+
component: {
|
|
30
|
+
type: PropType<any>;
|
|
31
|
+
default: string;
|
|
32
|
+
};
|
|
33
|
+
invalidate: BooleanConstructor;
|
|
34
|
+
}>, () => import("vue/jsx-runtime").JSX.Element, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
|
|
35
|
+
prefixCls: {
|
|
36
|
+
type: StringConstructor;
|
|
37
|
+
required: true;
|
|
38
|
+
};
|
|
39
|
+
item: PropType<any>;
|
|
40
|
+
class: {
|
|
41
|
+
type: PropType<any>;
|
|
42
|
+
default: undefined;
|
|
43
|
+
};
|
|
44
|
+
style: PropType<CSSProperties>;
|
|
45
|
+
renderItem: PropType<(item: any, info: {
|
|
46
|
+
index: number;
|
|
47
|
+
}) => VueNode>;
|
|
48
|
+
responsive: BooleanConstructor;
|
|
49
|
+
responsiveDisabled: BooleanConstructor;
|
|
50
|
+
itemKey: PropType<Key>;
|
|
51
|
+
registerSize: {
|
|
52
|
+
type: PropType<(key: Key, width: number | null) => void>;
|
|
53
|
+
required: true;
|
|
54
|
+
};
|
|
55
|
+
display: BooleanConstructor;
|
|
56
|
+
order: {
|
|
57
|
+
type: NumberConstructor;
|
|
58
|
+
required: true;
|
|
59
|
+
};
|
|
60
|
+
component: {
|
|
61
|
+
type: PropType<any>;
|
|
62
|
+
default: string;
|
|
63
|
+
};
|
|
64
|
+
invalidate: BooleanConstructor;
|
|
65
|
+
}>> & Readonly<{}>, {
|
|
66
|
+
responsive: boolean;
|
|
67
|
+
responsiveDisabled: boolean;
|
|
68
|
+
display: boolean;
|
|
69
|
+
invalidate: boolean;
|
|
70
|
+
class: any;
|
|
71
|
+
component: any;
|
|
72
|
+
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
|
|
73
|
+
export default _default;
|
package/dist/Item.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { defineComponent, computed, onUnmounted, createVNode, mergeProps, isVNode } from "vue";
|
|
2
|
+
import ResizeObserver from "@v-c/resize-observer";
|
|
3
|
+
import { classNames } from "@v-c/util";
|
|
4
|
+
function _isSlot(s) {
|
|
5
|
+
return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !isVNode(s);
|
|
6
|
+
}
|
|
7
|
+
const UNDEFINED = void 0;
|
|
8
|
+
const Item = /* @__PURE__ */ defineComponent({
|
|
9
|
+
name: "OverflowItem",
|
|
10
|
+
inheritAttrs: false,
|
|
11
|
+
props: {
|
|
12
|
+
prefixCls: {
|
|
13
|
+
type: String,
|
|
14
|
+
required: true
|
|
15
|
+
},
|
|
16
|
+
item: Object,
|
|
17
|
+
class: {
|
|
18
|
+
type: [String, Object, Array],
|
|
19
|
+
default: void 0
|
|
20
|
+
},
|
|
21
|
+
style: Object,
|
|
22
|
+
renderItem: Function,
|
|
23
|
+
responsive: Boolean,
|
|
24
|
+
responsiveDisabled: Boolean,
|
|
25
|
+
itemKey: [String, Number],
|
|
26
|
+
registerSize: {
|
|
27
|
+
type: Function,
|
|
28
|
+
required: true
|
|
29
|
+
},
|
|
30
|
+
display: Boolean,
|
|
31
|
+
order: {
|
|
32
|
+
type: Number,
|
|
33
|
+
required: true
|
|
34
|
+
},
|
|
35
|
+
component: {
|
|
36
|
+
type: [String, Object, Function],
|
|
37
|
+
default: "div"
|
|
38
|
+
},
|
|
39
|
+
invalidate: Boolean
|
|
40
|
+
},
|
|
41
|
+
setup(props, {
|
|
42
|
+
slots,
|
|
43
|
+
attrs
|
|
44
|
+
}) {
|
|
45
|
+
const mergedHidden = computed(() => props.responsive && !props.display);
|
|
46
|
+
function internalRegisterSize(width) {
|
|
47
|
+
const key = props.itemKey ?? props.order;
|
|
48
|
+
props.registerSize(key, width);
|
|
49
|
+
}
|
|
50
|
+
onUnmounted(() => {
|
|
51
|
+
internalRegisterSize(null);
|
|
52
|
+
});
|
|
53
|
+
return () => {
|
|
54
|
+
const {
|
|
55
|
+
prefixCls,
|
|
56
|
+
invalidate,
|
|
57
|
+
item,
|
|
58
|
+
renderItem,
|
|
59
|
+
responsive,
|
|
60
|
+
responsiveDisabled,
|
|
61
|
+
order,
|
|
62
|
+
component: Component = "div",
|
|
63
|
+
style
|
|
64
|
+
} = props;
|
|
65
|
+
const children = slots.default?.();
|
|
66
|
+
const childNode = renderItem && item !== UNDEFINED ? renderItem(item, {
|
|
67
|
+
index: order
|
|
68
|
+
}) : children;
|
|
69
|
+
let overflowStyle;
|
|
70
|
+
if (!invalidate) {
|
|
71
|
+
overflowStyle = {
|
|
72
|
+
opacity: mergedHidden.value ? 0 : 1,
|
|
73
|
+
height: mergedHidden.value ? 0 : UNDEFINED,
|
|
74
|
+
overflowY: mergedHidden.value ? "hidden" : UNDEFINED,
|
|
75
|
+
order: responsive ? order : UNDEFINED,
|
|
76
|
+
pointerEvents: mergedHidden.value ? "none" : UNDEFINED,
|
|
77
|
+
position: mergedHidden.value ? "absolute" : UNDEFINED
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
const overflowProps = {};
|
|
81
|
+
if (mergedHidden.value) {
|
|
82
|
+
overflowProps["aria-hidden"] = true;
|
|
83
|
+
}
|
|
84
|
+
const itemNode = createVNode(Component, mergeProps({
|
|
85
|
+
"class": classNames(!invalidate && prefixCls, props.class),
|
|
86
|
+
"style": {
|
|
87
|
+
...overflowStyle,
|
|
88
|
+
...style
|
|
89
|
+
}
|
|
90
|
+
}, overflowProps, attrs), _isSlot(childNode) ? childNode : {
|
|
91
|
+
default: () => [childNode]
|
|
92
|
+
});
|
|
93
|
+
if (!responsive) {
|
|
94
|
+
return itemNode;
|
|
95
|
+
}
|
|
96
|
+
return createVNode(ResizeObserver, {
|
|
97
|
+
"disabled": responsiveDisabled,
|
|
98
|
+
"onResize": ({
|
|
99
|
+
offsetWidth
|
|
100
|
+
}) => {
|
|
101
|
+
internalRegisterSize(offsetWidth);
|
|
102
|
+
}
|
|
103
|
+
}, {
|
|
104
|
+
default: () => itemNode
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
export {
|
|
110
|
+
Item as default
|
|
111
|
+
};
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const vue = require("vue");
|
|
4
|
+
const ResizeObserver = require("@v-c/resize-observer");
|
|
5
|
+
const util = require("@v-c/util");
|
|
6
|
+
const context = require("./context.cjs");
|
|
7
|
+
const useEffectState = require("./hooks/useEffectState.cjs");
|
|
8
|
+
const Item = require("./Item.cjs");
|
|
9
|
+
const RawItem = require("./RawItem.cjs");
|
|
10
|
+
function _isSlot(s) {
|
|
11
|
+
return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !vue.isVNode(s);
|
|
12
|
+
}
|
|
13
|
+
const RESPONSIVE = "responsive";
|
|
14
|
+
const INVALIDATE = "invalidate";
|
|
15
|
+
function defaultRenderRest(omittedItems) {
|
|
16
|
+
return `+ ${omittedItems.length} ...`;
|
|
17
|
+
}
|
|
18
|
+
const overflowProps = {
|
|
19
|
+
prefixCls: {
|
|
20
|
+
type: String,
|
|
21
|
+
default: "vc-overflow"
|
|
22
|
+
},
|
|
23
|
+
data: {
|
|
24
|
+
type: Array,
|
|
25
|
+
default: () => []
|
|
26
|
+
},
|
|
27
|
+
renderItem: Function,
|
|
28
|
+
renderRawItem: Function,
|
|
29
|
+
itemKey: [String, Number, Function],
|
|
30
|
+
itemWidth: {
|
|
31
|
+
type: Number,
|
|
32
|
+
default: 10
|
|
33
|
+
},
|
|
34
|
+
maxCount: [Number, String],
|
|
35
|
+
renderRest: [Function, Object],
|
|
36
|
+
renderRawRest: Function,
|
|
37
|
+
prefix: {},
|
|
38
|
+
suffix: {},
|
|
39
|
+
component: [String, Object, Function],
|
|
40
|
+
itemComponent: [String, Object, Function],
|
|
41
|
+
onVisibleChange: Function,
|
|
42
|
+
ssr: String
|
|
43
|
+
};
|
|
44
|
+
const OverflowImpl = /* @__PURE__ */ vue.defineComponent({
|
|
45
|
+
name: "Overflow",
|
|
46
|
+
inheritAttrs: false,
|
|
47
|
+
props: overflowProps,
|
|
48
|
+
emits: ["visibleChange"],
|
|
49
|
+
setup(props, {
|
|
50
|
+
attrs,
|
|
51
|
+
slots,
|
|
52
|
+
emit
|
|
53
|
+
}) {
|
|
54
|
+
const notifyEffectUpdate = useEffectState.useBatcher();
|
|
55
|
+
const [containerWidth, setContainerWidth] = useEffectState.default(notifyEffectUpdate, null);
|
|
56
|
+
const mergedContainerWidth = vue.computed(() => containerWidth.value || 0);
|
|
57
|
+
const [itemWidths, setItemWidths] = useEffectState.default(notifyEffectUpdate, /* @__PURE__ */ new Map());
|
|
58
|
+
const [prevRestWidth, setPrevRestWidth] = useEffectState.default(notifyEffectUpdate, 0);
|
|
59
|
+
const [restWidth, setRestWidth] = useEffectState.default(notifyEffectUpdate, 0);
|
|
60
|
+
const [prefixWidth, setPrefixWidth] = useEffectState.default(notifyEffectUpdate, 0);
|
|
61
|
+
const [suffixWidth, setSuffixWidth] = useEffectState.default(notifyEffectUpdate, 0);
|
|
62
|
+
const suffixFixedStart = vue.ref(null);
|
|
63
|
+
const displayCount = vue.ref(null);
|
|
64
|
+
const mergedDisplayCount = vue.computed(() => {
|
|
65
|
+
if (displayCount.value === null && props.ssr === "full") {
|
|
66
|
+
return Number.MAX_SAFE_INTEGER;
|
|
67
|
+
}
|
|
68
|
+
return displayCount.value || 0;
|
|
69
|
+
});
|
|
70
|
+
const restReady = vue.ref(false);
|
|
71
|
+
const itemPrefixCls = vue.computed(() => `${props.prefixCls}-item`);
|
|
72
|
+
const mergedRestWidth = vue.computed(() => Math.max(prevRestWidth.value, restWidth.value));
|
|
73
|
+
const data = vue.computed(() => props.data ?? []);
|
|
74
|
+
const isResponsive = vue.computed(() => props.maxCount === RESPONSIVE);
|
|
75
|
+
const shouldResponsive = vue.computed(() => data.value.length && isResponsive.value);
|
|
76
|
+
const invalidate = vue.computed(() => props.maxCount === INVALIDATE);
|
|
77
|
+
const showRest = vue.computed(() => shouldResponsive.value || typeof props.maxCount === "number" && data.value.length > props.maxCount);
|
|
78
|
+
const mergedData = vue.computed(() => {
|
|
79
|
+
let items = data.value;
|
|
80
|
+
if (shouldResponsive.value) {
|
|
81
|
+
if (containerWidth.value === null && props.ssr === "full") {
|
|
82
|
+
items = data.value;
|
|
83
|
+
} else {
|
|
84
|
+
const mergedItemWidth = props.itemWidth ?? 10;
|
|
85
|
+
const maxLen = Math.min(data.value.length, mergedContainerWidth.value / mergedItemWidth);
|
|
86
|
+
items = data.value.slice(0, Math.floor(maxLen));
|
|
87
|
+
}
|
|
88
|
+
} else if (typeof props.maxCount === "number") {
|
|
89
|
+
items = data.value.slice(0, props.maxCount);
|
|
90
|
+
}
|
|
91
|
+
return items;
|
|
92
|
+
});
|
|
93
|
+
const omittedItems = vue.computed(() => {
|
|
94
|
+
if (shouldResponsive.value) {
|
|
95
|
+
return data.value.slice(mergedDisplayCount.value + 1);
|
|
96
|
+
}
|
|
97
|
+
return data.value.slice(mergedData.value.length);
|
|
98
|
+
});
|
|
99
|
+
const getKey = (item, index) => {
|
|
100
|
+
const {
|
|
101
|
+
itemKey
|
|
102
|
+
} = props;
|
|
103
|
+
if (typeof itemKey === "function") {
|
|
104
|
+
return itemKey(item);
|
|
105
|
+
}
|
|
106
|
+
if (itemKey != null) {
|
|
107
|
+
return item?.[itemKey] ?? index;
|
|
108
|
+
}
|
|
109
|
+
return index;
|
|
110
|
+
};
|
|
111
|
+
function updateDisplayCount(count, suffixFixedStartVal, notReady) {
|
|
112
|
+
if (displayCount.value === count && (suffixFixedStartVal === void 0 || suffixFixedStartVal === suffixFixedStart.value)) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
displayCount.value = count;
|
|
116
|
+
if (!notReady) {
|
|
117
|
+
restReady.value = count < data.value.length - 1;
|
|
118
|
+
props.onVisibleChange?.(count);
|
|
119
|
+
emit("visibleChange", count);
|
|
120
|
+
}
|
|
121
|
+
if (suffixFixedStartVal !== void 0) {
|
|
122
|
+
suffixFixedStart.value = suffixFixedStartVal;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function onOverflowResize(_, element) {
|
|
126
|
+
setContainerWidth(element.clientWidth);
|
|
127
|
+
}
|
|
128
|
+
function registerSize(key, width) {
|
|
129
|
+
setItemWidths((origin) => {
|
|
130
|
+
const clone = new Map(origin || []);
|
|
131
|
+
if (width === null) {
|
|
132
|
+
clone.delete(key);
|
|
133
|
+
} else {
|
|
134
|
+
clone.set(key, width);
|
|
135
|
+
}
|
|
136
|
+
return clone;
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
function registerOverflowSize(_, width) {
|
|
140
|
+
setRestWidth(width ?? 0);
|
|
141
|
+
setPrevRestWidth(restWidth.value);
|
|
142
|
+
}
|
|
143
|
+
function registerPrefixSize(_, width) {
|
|
144
|
+
setPrefixWidth(width ?? 0);
|
|
145
|
+
}
|
|
146
|
+
function registerSuffixSize(_, width) {
|
|
147
|
+
setSuffixWidth(width ?? 0);
|
|
148
|
+
}
|
|
149
|
+
function getItemWidth(index) {
|
|
150
|
+
const key = getKey(mergedData.value[index], index);
|
|
151
|
+
return itemWidths.value?.get(key);
|
|
152
|
+
}
|
|
153
|
+
vue.watchEffect(() => {
|
|
154
|
+
const container = mergedContainerWidth.value;
|
|
155
|
+
const rest = mergedRestWidth.value;
|
|
156
|
+
const list = mergedData.value;
|
|
157
|
+
if (container && typeof rest === "number" && list) {
|
|
158
|
+
let totalWidth = prefixWidth.value + suffixWidth.value;
|
|
159
|
+
const len = list.length;
|
|
160
|
+
const lastIndex = len - 1;
|
|
161
|
+
if (!len) {
|
|
162
|
+
updateDisplayCount(0, null);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
for (let i = 0; i < len; i += 1) {
|
|
166
|
+
let currentItemWidth = getItemWidth(i);
|
|
167
|
+
if (props.ssr === "full") {
|
|
168
|
+
currentItemWidth = currentItemWidth || 0;
|
|
169
|
+
}
|
|
170
|
+
if (currentItemWidth === void 0) {
|
|
171
|
+
updateDisplayCount(i - 1, void 0, true);
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
totalWidth += currentItemWidth;
|
|
175
|
+
if (
|
|
176
|
+
// Only one means `totalWidth` is the final width
|
|
177
|
+
lastIndex === 0 && totalWidth <= container || i === lastIndex - 1 && totalWidth + (getItemWidth(lastIndex) || 0) <= container
|
|
178
|
+
) {
|
|
179
|
+
updateDisplayCount(lastIndex, null);
|
|
180
|
+
break;
|
|
181
|
+
} else if (totalWidth + rest > container) {
|
|
182
|
+
updateDisplayCount(i - 1, totalWidth - currentItemWidth - suffixWidth.value + restWidth.value);
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if ((props.suffix ?? slots.suffix?.()) && getItemWidth(0) + suffixWidth.value > container) {
|
|
187
|
+
suffixFixedStart.value = null;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}, {
|
|
191
|
+
flush: "post"
|
|
192
|
+
});
|
|
193
|
+
return () => {
|
|
194
|
+
const {
|
|
195
|
+
prefixCls = "vc-overflow",
|
|
196
|
+
component: Component = "div",
|
|
197
|
+
itemComponent
|
|
198
|
+
} = props;
|
|
199
|
+
const renderItem = slots?.renderItem ?? props?.renderItem;
|
|
200
|
+
const renderRawItem = slots?.renderRawItem ?? props?.renderRawItem;
|
|
201
|
+
const renderRest = slots?.renderRest ?? props?.renderRest;
|
|
202
|
+
const renderRawRest = slots?.renderRawRest ?? props?.renderRawRest;
|
|
203
|
+
let prefix = slots?.prefix ?? props?.prefix;
|
|
204
|
+
let suffix = slots?.suffix ?? props?.suffix;
|
|
205
|
+
if (typeof prefix === "function") {
|
|
206
|
+
prefix = prefix();
|
|
207
|
+
}
|
|
208
|
+
if (typeof suffix === "function") {
|
|
209
|
+
suffix = suffix();
|
|
210
|
+
}
|
|
211
|
+
const displayRest = restReady.value && !!omittedItems.value.length;
|
|
212
|
+
let suffixStyle = {};
|
|
213
|
+
if (suffixFixedStart.value !== null && shouldResponsive.value) {
|
|
214
|
+
suffixStyle = {
|
|
215
|
+
position: "absolute",
|
|
216
|
+
left: `${suffixFixedStart.value}px`,
|
|
217
|
+
top: 0
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
const itemSharedProps = {
|
|
221
|
+
prefixCls: itemPrefixCls.value,
|
|
222
|
+
responsive: shouldResponsive.value,
|
|
223
|
+
component: itemComponent,
|
|
224
|
+
invalidate: invalidate.value
|
|
225
|
+
};
|
|
226
|
+
const internalRenderItemNode = (item, index) => {
|
|
227
|
+
const key = getKey(item, index);
|
|
228
|
+
if (renderRawItem) {
|
|
229
|
+
let _slot;
|
|
230
|
+
return vue.createVNode(context.OverflowContextProvider, {
|
|
231
|
+
"key": key,
|
|
232
|
+
"value": {
|
|
233
|
+
...itemSharedProps,
|
|
234
|
+
order: index,
|
|
235
|
+
item,
|
|
236
|
+
itemKey: key,
|
|
237
|
+
registerSize,
|
|
238
|
+
display: index <= mergedDisplayCount.value
|
|
239
|
+
}
|
|
240
|
+
}, _isSlot(_slot = renderRawItem(item, index)) ? _slot : {
|
|
241
|
+
default: () => [_slot]
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
return vue.createVNode(Item.default, vue.mergeProps(itemSharedProps, {
|
|
245
|
+
"order": index,
|
|
246
|
+
"key": key,
|
|
247
|
+
"item": item,
|
|
248
|
+
"renderItem": renderItem,
|
|
249
|
+
"itemKey": key,
|
|
250
|
+
"registerSize": registerSize,
|
|
251
|
+
"display": index <= mergedDisplayCount.value
|
|
252
|
+
}), null);
|
|
253
|
+
};
|
|
254
|
+
const restContextProps = {
|
|
255
|
+
order: displayRest ? mergedDisplayCount.value : Number.MAX_SAFE_INTEGER,
|
|
256
|
+
class: `${itemPrefixCls.value}-rest`,
|
|
257
|
+
registerSize: registerOverflowSize,
|
|
258
|
+
display: displayRest
|
|
259
|
+
};
|
|
260
|
+
const mergedRenderRestFn = renderRest ?? defaultRenderRest;
|
|
261
|
+
const restNode = () => {
|
|
262
|
+
if (renderRawRest) {
|
|
263
|
+
let _slot2;
|
|
264
|
+
return vue.createVNode(context.OverflowContextProvider, {
|
|
265
|
+
"value": {
|
|
266
|
+
...itemSharedProps,
|
|
267
|
+
...restContextProps
|
|
268
|
+
}
|
|
269
|
+
}, _isSlot(_slot2 = renderRawRest(omittedItems.value)) ? _slot2 : {
|
|
270
|
+
default: () => [_slot2]
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
return vue.createVNode(Item.default, vue.mergeProps(itemSharedProps, restContextProps), {
|
|
274
|
+
default: () => typeof mergedRenderRestFn === "function" ? mergedRenderRestFn(omittedItems.value) : mergedRenderRestFn
|
|
275
|
+
});
|
|
276
|
+
};
|
|
277
|
+
const {
|
|
278
|
+
class: classAttr,
|
|
279
|
+
style: styleAttr,
|
|
280
|
+
...restAttrs
|
|
281
|
+
} = attrs;
|
|
282
|
+
const overflowNode = vue.createVNode(Component, vue.mergeProps({
|
|
283
|
+
"class": util.classNames(!invalidate.value && prefixCls, classAttr),
|
|
284
|
+
"style": styleAttr
|
|
285
|
+
}, restAttrs), {
|
|
286
|
+
default: () => [prefix && vue.createVNode(Item.default, vue.mergeProps(itemSharedProps, {
|
|
287
|
+
"responsive": isResponsive.value,
|
|
288
|
+
"responsiveDisabled": !shouldResponsive.value,
|
|
289
|
+
"order": -1,
|
|
290
|
+
"class": `${itemPrefixCls.value}-prefix`,
|
|
291
|
+
"registerSize": registerPrefixSize,
|
|
292
|
+
"display": true
|
|
293
|
+
}), {
|
|
294
|
+
default: () => prefix
|
|
295
|
+
}), mergedData.value.map(internalRenderItemNode), showRest.value ? restNode() : null, suffix && vue.createVNode(Item.default, vue.mergeProps(itemSharedProps, {
|
|
296
|
+
"responsive": isResponsive.value,
|
|
297
|
+
"responsiveDisabled": !shouldResponsive.value,
|
|
298
|
+
"order": mergedDisplayCount.value,
|
|
299
|
+
"class": `${itemPrefixCls.value}-suffix`,
|
|
300
|
+
"registerSize": registerSuffixSize,
|
|
301
|
+
"display": true,
|
|
302
|
+
"style": suffixStyle
|
|
303
|
+
}), {
|
|
304
|
+
default: () => suffix
|
|
305
|
+
}), slots.default?.()]
|
|
306
|
+
});
|
|
307
|
+
return isResponsive.value ? vue.createVNode(ResizeObserver, {
|
|
308
|
+
"onResize": onOverflowResize,
|
|
309
|
+
"disabled": !shouldResponsive.value
|
|
310
|
+
}, _isSlot(overflowNode) ? overflowNode : {
|
|
311
|
+
default: () => [overflowNode]
|
|
312
|
+
}) : overflowNode;
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
const Overflow = OverflowImpl;
|
|
317
|
+
Overflow.Item = RawItem.default;
|
|
318
|
+
Overflow.RESPONSIVE = RESPONSIVE;
|
|
319
|
+
Overflow.INVALIDATE = INVALIDATE;
|
|
320
|
+
exports.OverflowContextProvider = context.OverflowContextProvider;
|
|
321
|
+
exports.default = Overflow;
|