@sdata/web-vue 1.4.1 → 1.6.0

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.
@@ -0,0 +1,170 @@
1
+ import { getPrefixCls } from "../_utils/global-config.js";
2
+ import { isObject } from "../_utils/is.js";
3
+ import resize_observer_v2_default from "../_components/resize-observer-v2.js";
4
+ import { _asyncToGenerator } from "../_virtual/_@oxc-project_runtime@0.124.0/helpers/asyncToGenerator.js";
5
+ import Tooltip from "../tooltip/index.js";
6
+ import { _objectWithoutProperties } from "../_virtual/_@oxc-project_runtime@0.124.0/helpers/objectWithoutProperties.js";
7
+ import { computed, defineComponent, nextTick, onMounted, onUpdated, ref, watch } from "vue";
8
+ //#region components/ellipsis/ellipsis.vue?vue&type=script&lang.ts
9
+ var _excluded = ["disabled"];
10
+ var ellipsis_vue_vue_type_script_lang_default = defineComponent({
11
+ name: "Ellipsis",
12
+ components: {
13
+ ResizeObserver: resize_observer_v2_default,
14
+ Tooltip
15
+ },
16
+ inheritAttrs: false,
17
+ props: {
18
+ lineClamp: {
19
+ type: [Number, String],
20
+ default: void 0
21
+ },
22
+ expandTrigger: {
23
+ type: String,
24
+ default: void 0
25
+ },
26
+ tooltip: {
27
+ type: [Boolean, Object],
28
+ default: true
29
+ }
30
+ },
31
+ setup(props) {
32
+ const prefixCls = getPrefixCls("ellipsis");
33
+ const triggerRef = ref();
34
+ const contentRef = ref();
35
+ const text = ref("");
36
+ const isEllipsis = ref(false);
37
+ const expanded = ref(false);
38
+ const isLineClamp = computed(() => props.lineClamp !== void 0);
39
+ const componentTag = computed(() => isLineClamp.value ? "div" : "span");
40
+ const tooltipConfig = computed(() => {
41
+ if (isObject(props.tooltip)) return props.tooltip;
42
+ return {};
43
+ });
44
+ const tooltipBindings = computed(() => {
45
+ const _tooltipConfig$value = tooltipConfig.value, { disabled: _disabled } = _tooltipConfig$value;
46
+ return _objectWithoutProperties(_tooltipConfig$value, _excluded);
47
+ });
48
+ const enableTooltip = computed(() => props.tooltip !== false);
49
+ const tooltipDisabled = computed(() => !isEllipsis.value || expanded.value || Boolean(tooltipConfig.value.disabled));
50
+ const isExpandable = computed(() => props.expandTrigger === "click" && (isEllipsis.value || expanded.value));
51
+ const rootCls = computed(() => [prefixCls, {
52
+ [`${prefixCls}--single-line`]: !isLineClamp.value && !expanded.value,
53
+ [`${prefixCls}--line-clamp`]: isLineClamp.value,
54
+ [`${prefixCls}--expandable`]: isExpandable.value,
55
+ [`${prefixCls}--expanded`]: expanded.value
56
+ }]);
57
+ const rootStyle = computed(() => {
58
+ if (isLineClamp.value) {
59
+ if (expanded.value) return {
60
+ overflow: "visible",
61
+ textOverflow: "clip",
62
+ display: "block",
63
+ whiteSpace: "normal",
64
+ WebkitLineClamp: "unset",
65
+ WebkitBoxOrient: "vertical"
66
+ };
67
+ return {
68
+ overflow: "hidden",
69
+ textOverflow: "ellipsis",
70
+ display: "-webkit-box",
71
+ whiteSpace: "normal",
72
+ WebkitLineClamp: String(props.lineClamp),
73
+ WebkitBoxOrient: "vertical"
74
+ };
75
+ }
76
+ if (expanded.value) return {
77
+ overflow: "visible",
78
+ textOverflow: "clip",
79
+ whiteSpace: "normal"
80
+ };
81
+ return {
82
+ overflow: "hidden",
83
+ textOverflow: "ellipsis",
84
+ whiteSpace: "nowrap"
85
+ };
86
+ });
87
+ const nativeTitle = computed(() => {
88
+ if ((!enableTooltip.value || Boolean(tooltipConfig.value.disabled)) && isEllipsis.value) return text.value;
89
+ });
90
+ const buttonRole = computed(() => isExpandable.value ? "button" : void 0);
91
+ const buttonTabIndex = computed(() => isExpandable.value ? 0 : void 0);
92
+ const ariaExpanded = computed(() => props.expandTrigger === "click" ? String(expanded.value) : void 0);
93
+ const syncText = () => {
94
+ var _triggerRef$value$tex, _triggerRef$value;
95
+ const nextText = (_triggerRef$value$tex = (_triggerRef$value = triggerRef.value) === null || _triggerRef$value === void 0 || (_triggerRef$value = _triggerRef$value.textContent) === null || _triggerRef$value === void 0 ? void 0 : _triggerRef$value.trim()) !== null && _triggerRef$value$tex !== void 0 ? _triggerRef$value$tex : "";
96
+ if (nextText !== text.value) text.value = nextText;
97
+ };
98
+ const calculateEllipsis = () => {
99
+ syncText();
100
+ const triggerElement = triggerRef.value;
101
+ if (!triggerElement || expanded.value) return;
102
+ let nextEllipsis = false;
103
+ if (isLineClamp.value) nextEllipsis = triggerElement.scrollHeight > triggerElement.offsetHeight + 1 || triggerElement.scrollWidth > triggerElement.clientWidth + 1;
104
+ else {
105
+ var _contentRef$value$scr, _contentRef$value, _contentRef$value$off, _contentRef$value2;
106
+ nextEllipsis = Math.max((_contentRef$value$scr = (_contentRef$value = contentRef.value) === null || _contentRef$value === void 0 ? void 0 : _contentRef$value.scrollWidth) !== null && _contentRef$value$scr !== void 0 ? _contentRef$value$scr : 0, (_contentRef$value$off = (_contentRef$value2 = contentRef.value) === null || _contentRef$value2 === void 0 ? void 0 : _contentRef$value2.offsetWidth) !== null && _contentRef$value$off !== void 0 ? _contentRef$value$off : 0) > triggerElement.clientWidth + 1 || triggerElement.scrollWidth > triggerElement.clientWidth + 1;
107
+ }
108
+ if (nextEllipsis !== isEllipsis.value) isEllipsis.value = nextEllipsis;
109
+ };
110
+ const handleResize = () => {
111
+ calculateEllipsis();
112
+ };
113
+ const handleClick = function() {
114
+ var _ref = _asyncToGenerator(function* () {
115
+ if (props.expandTrigger !== "click") return;
116
+ if (!expanded.value) calculateEllipsis();
117
+ if (!isEllipsis.value && !expanded.value) return;
118
+ expanded.value = !expanded.value;
119
+ yield nextTick();
120
+ if (!expanded.value) calculateEllipsis();
121
+ });
122
+ return function handleClick() {
123
+ return _ref.apply(this, arguments);
124
+ };
125
+ }();
126
+ const handleKeydown = function() {
127
+ var _ref2 = _asyncToGenerator(function* (ev) {
128
+ if (!isExpandable.value) return;
129
+ if (ev.key === "Enter" || ev.key === " ") {
130
+ ev.preventDefault();
131
+ yield handleClick();
132
+ }
133
+ });
134
+ return function handleKeydown(_x) {
135
+ return _ref2.apply(this, arguments);
136
+ };
137
+ }();
138
+ onMounted(() => {
139
+ nextTick(() => calculateEllipsis());
140
+ });
141
+ onUpdated(() => {
142
+ nextTick(() => calculateEllipsis());
143
+ });
144
+ watch(() => props.lineClamp, () => {
145
+ if (expanded.value) expanded.value = false;
146
+ nextTick(() => calculateEllipsis());
147
+ });
148
+ return {
149
+ prefixCls,
150
+ triggerRef,
151
+ contentRef,
152
+ componentTag,
153
+ isLineClamp,
154
+ enableTooltip,
155
+ tooltipBindings,
156
+ tooltipDisabled,
157
+ rootCls,
158
+ rootStyle,
159
+ nativeTitle,
160
+ buttonRole,
161
+ buttonTabIndex,
162
+ ariaExpanded,
163
+ handleResize,
164
+ handleClick,
165
+ handleKeydown
166
+ };
167
+ }
168
+ });
169
+ //#endregion
170
+ export { ellipsis_vue_vue_type_script_lang_default as default };