@varlet/ui 3.20.6 → 3.20.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.
@@ -14,8 +14,8 @@ var __spreadValues = (a, b) => {
14
14
  }
15
15
  return a;
16
16
  };
17
- import { useVModel } from "@varlet/use";
18
- import { computed, defineComponent } from "vue";
17
+ import { onSmartMounted, useResizeObserver, useVModel } from "@varlet/use";
18
+ import { computed, defineComponent, onUpdated, ref, watch } from "vue";
19
19
  import VarTooltip from "../tooltip/index.mjs";
20
20
  import { createNamespace } from "../utils/components.mjs";
21
21
  import { props } from "./props.mjs";
@@ -25,7 +25,8 @@ const _hoisted_1 = { key: 0 };
25
25
  function __render__(_ctx, _cache) {
26
26
  const _component_var_tooltip = _resolveComponent("var-tooltip");
27
27
  return _openBlock(), _createBlock(_component_var_tooltip, _mergeProps({
28
- class: _ctx.classes(_ctx.n(), [_ctx.lineClamp, _ctx.n("--clamp"), _ctx.n("--line")], [_ctx.expandTrigger, _ctx.n("--cursor")], [_ctx.expanding, _ctx.n("--expand")]),
28
+ ref: "rootRef",
29
+ class: _ctx.classes(_ctx.n(), [_ctx.lineClamp, _ctx.n("--clamp"), _ctx.n("--line")], [_ctx.clickable, _ctx.n("--cursor")], [_ctx.expanding, _ctx.n("--expand")]),
29
30
  "var-ellipsis-cover": "",
30
31
  style: _ctx.rootStyles
31
32
  }, _ctx.tooltipProps, { onClick: _ctx.handleClick }), {
@@ -57,10 +58,16 @@ const __sfc__ = defineComponent({
57
58
  components: { VarTooltip },
58
59
  props,
59
60
  setup(props2) {
61
+ const rootRef = ref(null);
62
+ const truncated = ref(false);
60
63
  const expanding = useVModel(props2, "expand");
64
+ let previousWidth;
65
+ const clickable = computed(
66
+ () => !!props2.expandTrigger && (!props2.expandableOnOverflow || truncated.value || expanding.value)
67
+ );
61
68
  const rootStyles = computed(() => props2.lineClamp ? { "-webkit-line-clamp": props2.lineClamp } : {});
62
69
  const tooltipProps = computed(() => {
63
- if (props2.tooltip === false) {
70
+ if (props2.tooltip === false || props2.tooltipOnOverflow && !truncated.value) {
64
71
  return {
65
72
  disabled: true
66
73
  };
@@ -72,19 +79,53 @@ const __sfc__ = defineComponent({
72
79
  }
73
80
  return __spreadValues({ sameWidth: true }, props2.tooltip);
74
81
  });
82
+ function getRootElement() {
83
+ var _a;
84
+ if (!rootRef.value) {
85
+ return null;
86
+ }
87
+ return (_a = rootRef.value.$el) != null ? _a : rootRef.value;
88
+ }
89
+ function checkTruncated() {
90
+ const element = getRootElement();
91
+ if (!element) {
92
+ return;
93
+ }
94
+ const next = props2.lineClamp ? element.scrollHeight > element.clientHeight : element.scrollWidth > element.clientWidth;
95
+ if (next !== truncated.value) {
96
+ truncated.value = next;
97
+ }
98
+ }
75
99
  function handleClick() {
76
- if (!props2.expandTrigger) {
100
+ if (!clickable.value) {
77
101
  return;
78
102
  }
79
103
  expanding.value = !expanding.value;
80
104
  }
105
+ function handleResize(entries) {
106
+ var _a;
107
+ const width = (_a = entries[0]) == null ? void 0 : _a.contentRect.width;
108
+ if (width !== void 0 && width !== previousWidth && previousWidth !== void 0 && props2.expandableOnOverflow && expanding.value) {
109
+ expanding.value = false;
110
+ }
111
+ previousWidth = width;
112
+ checkTruncated();
113
+ }
114
+ useResizeObserver(getRootElement, handleResize);
115
+ watch(() => props2.lineClamp, checkTruncated);
116
+ onSmartMounted(checkTruncated);
117
+ onUpdated(checkTruncated);
81
118
  return {
119
+ rootRef,
120
+ truncated,
121
+ clickable,
82
122
  tooltipProps,
83
123
  expanding,
84
124
  rootStyles,
85
125
  n,
86
126
  classes,
87
- handleClick
127
+ handleClick,
128
+ handleResize
88
129
  };
89
130
  }
90
131
  });
@@ -2,7 +2,9 @@ import { defineListenerProp } from "../utils/components.mjs";
2
2
  const props = {
3
3
  expand: Boolean,
4
4
  expandTrigger: String,
5
+ expandableOnOverflow: Boolean,
5
6
  lineClamp: [Number, String],
7
+ tooltipOnOverflow: Boolean,
6
8
  tooltip: {
7
9
  type: [Object, Boolean],
8
10
  default: true
@@ -310,7 +310,7 @@ import './tree-menu/style/index.mjs'
310
310
  import './uploader/style/index.mjs'
311
311
  import './watermark/style/index.mjs'
312
312
 
313
- const version = '3.20.6'
313
+ const version = '3.20.8'
314
314
 
315
315
  function install(app) {
316
316
  ActionSheet.install && app.use(ActionSheet)
package/es/index.mjs CHANGED
@@ -206,7 +206,7 @@ export * from './tree-menu/index.mjs'
206
206
  export * from './uploader/index.mjs'
207
207
  export * from './watermark/index.mjs'
208
208
 
209
- const version = '3.20.6'
209
+ const version = '3.20.8'
210
210
 
211
211
  function install(app) {
212
212
  ActionSheet.install && app.use(ActionSheet)
@@ -1,6 +1,6 @@
1
1
  import { call } from "@varlet/shared";
2
2
  import { onSmartMounted } from "@varlet/use";
3
- import { computed, defineComponent, ref, watch } from "vue";
3
+ import { computed, defineComponent, onUnmounted, shallowRef, watch } from "vue";
4
4
  import { useLock } from "../context/lock.mjs";
5
5
  import { useZIndex } from "../context/zIndex.mjs";
6
6
  import VarIcon from "../icon/index.mjs";
@@ -18,6 +18,7 @@ const ICON_TYPE_DICT = {
18
18
  };
19
19
  import { renderSlot as _renderSlot, toDisplayString as _toDisplayString, createTextVNode as _createTextVNode, normalizeClass as _normalizeClass, createElementVNode as _createElementVNode, resolveComponent as _resolveComponent, openBlock as _openBlock, createBlock as _createBlock, createCommentVNode as _createCommentVNode, createElementBlock as _createElementBlock, normalizeStyle as _normalizeStyle, vShow as _vShow, withDirectives as _withDirectives } from "vue";
20
20
  function __render__(_ctx, _cache) {
21
+ var _a;
21
22
  const _component_var_icon = _resolveComponent("var-icon");
22
23
  const _component_var_loading = _resolveComponent("var-loading");
23
24
  return _withDirectives((_openBlock(), _createElementBlock(
@@ -36,6 +37,7 @@ function __render__(_ctx, _cache) {
36
37
  _ctx.n(`wrapper-${_ctx.position}`),
37
38
  _ctx.formatElevation(_ctx.elevation, 4),
38
39
  [_ctx.vertical, _ctx.n("vertical")],
40
+ [_ctx.showProgress, _ctx.n("wrapper--progress")],
39
41
  [_ctx.type && _ctx.SNACKBAR_TYPE.includes(_ctx.type), _ctx.n(`wrapper-${_ctx.type}`)]
40
42
  )
41
43
  ),
@@ -93,6 +95,28 @@ function __render__(_ctx, _cache) {
93
95
  ],
94
96
  2
95
97
  /* CLASS */
98
+ )) : _createCommentVNode("v-if", true),
99
+ _ctx.showProgress ? (_openBlock(), _createElementBlock(
100
+ "div",
101
+ {
102
+ key: (_a = _ctx.countdown) == null ? void 0 : _a.id,
103
+ class: _normalizeClass(_ctx.n("progress")),
104
+ "aria-hidden": "true"
105
+ },
106
+ [
107
+ _createElementVNode(
108
+ "div",
109
+ {
110
+ class: _normalizeClass(_ctx.n("progress-bar")),
111
+ style: _normalizeStyle(_ctx.progressStyle)
112
+ },
113
+ null,
114
+ 6
115
+ /* CLASS, STYLE */
116
+ )
117
+ ],
118
+ 2
119
+ /* CLASS */
96
120
  )) : _createCommentVNode("v-if", true)
97
121
  ],
98
122
  6
@@ -113,7 +137,9 @@ const __sfc__ = defineComponent({
113
137
  },
114
138
  props,
115
139
  setup(props2) {
116
- const timer = ref(null);
140
+ let timer;
141
+ let countdownId = 0;
142
+ const countdown = shallowRef();
117
143
  const { zIndex } = useZIndex(() => props2.show, 1);
118
144
  useLock(
119
145
  () => props2.show,
@@ -124,11 +150,33 @@ const __sfc__ = defineComponent({
124
150
  return type === "loading" || forbidClick;
125
151
  });
126
152
  const iconName = computed(() => !props2.type ? "" : ICON_TYPE_DICT[props2.type]);
153
+ const showProgress = computed(
154
+ () => props2.progress && countdown.value !== void 0 && countdown.value.duration > 0 && Number.isFinite(countdown.value.duration)
155
+ );
156
+ const progressStyle = computed(() => {
157
+ if (!props2.progress || !countdown.value) {
158
+ return;
159
+ }
160
+ const { duration, startedAt } = countdown.value;
161
+ return {
162
+ animationDuration: `${duration}ms`,
163
+ animationDelay: `${-Math.max(0, Date.now() - startedAt)}ms`
164
+ };
165
+ });
166
+ function clearCountdown() {
167
+ clearTimeout(timer);
168
+ timer = void 0;
169
+ countdown.value = void 0;
170
+ }
127
171
  function updateAfterDuration() {
128
- timer.value = setTimeout(() => {
129
- if (props2.type !== "loading") {
130
- call(props2["onUpdate:show"], false);
131
- }
172
+ clearCountdown();
173
+ if (!props2.show || props2.type === "loading") {
174
+ return;
175
+ }
176
+ countdown.value = { id: countdownId++, duration: props2.duration, startedAt: Date.now() };
177
+ timer = setTimeout(() => {
178
+ clearCountdown();
179
+ call(props2["onUpdate:show"], false);
132
180
  }, props2.duration);
133
181
  }
134
182
  watch(
@@ -136,31 +184,27 @@ const __sfc__ = defineComponent({
136
184
  (show) => {
137
185
  if (show) {
138
186
  call(props2.onOpen);
139
- updateAfterDuration();
140
187
  } else {
141
- clearTimeout(timer.value);
142
188
  call(props2.onClose);
143
189
  }
144
190
  }
145
191
  );
146
- watch(
147
- () => props2._update,
148
- () => {
149
- clearTimeout(timer.value);
150
- updateAfterDuration();
151
- }
152
- );
192
+ watch([() => props2.show, () => props2.type === "loading", () => props2._update], updateAfterDuration);
153
193
  onSmartMounted(() => {
154
194
  if (props2.show) {
155
195
  call(props2.onOpen);
156
196
  updateAfterDuration();
157
197
  }
158
198
  });
199
+ onUnmounted(clearCountdown);
159
200
  return {
160
201
  SNACKBAR_TYPE,
161
202
  zIndex,
162
203
  iconName,
163
204
  isForbidClick,
205
+ countdown,
206
+ showProgress,
207
+ progressStyle,
164
208
  n,
165
209
  classes,
166
210
  formatElevation
@@ -34,6 +34,7 @@ const defaultOptionsValue = {
34
34
  action: "",
35
35
  position: "top",
36
36
  duration: 3e3,
37
+ progress: false,
37
38
  elevation: true,
38
39
  vertical: false,
39
40
  contentClass: void 0,
@@ -31,6 +31,7 @@ const props = {
31
31
  type: Number,
32
32
  default: 3e3
33
33
  },
34
+ progress: Boolean,
34
35
  elevation: {
35
36
  type: [Boolean, String, Number],
36
37
  default: true
@@ -1 +1 @@
1
- :root { --snackbar-width: 256px; --snackbar-color: rgba(255, 255, 255, 0.87); --snackbar-border-radius: 4px; --snackbar-background: #333; --snackbar-font-size: var(--font-size-md); --snackbar-margin: 6px 24px; --snackbar-border-color: currentColor; --snackbar-success-background: var(--color-success); --snackbar-info-background: var(--color-info); --snackbar-error-background: var(--color-danger); --snackbar-warning-background: var(--color-warning); --snackbar-content-padding: 14px 16px; --snackbar-action-margin: 0 8px; --snackbar-vertical-action-margin: 0 8px 8px 0; --snackbar-icon-margin: 0 8px;}.var-transition-group { position: fixed; left: 0; right: 0; top: 0; bottom: 0; pointer-events: none;}.var-pointer-auto { pointer-events: auto;}.var-snackbar { display: flex; justify-content: center; align-items: baseline; left: 0; right: 0; bottom: 0; transition: all 0.15s var(--cubic-bezier);}.var-snackbar__transition { top: 0; position: fixed;}.var-snackbar__transition .var-snackbar__wrapper { position: absolute;}.var-snackbar__transition .var-snackbar__wrapper-top { top: 5%;}.var-snackbar__transition .var-snackbar__wrapper-center { top: 45%;}.var-snackbar__transition .var-snackbar__wrapper-bottom { bottom: 5%;}.var-snackbar__wrapper { width: var(--snackbar-width); display: flex; border-radius: var(--snackbar-border-radius); color: var(--snackbar-color); background: var(--snackbar-background); font-size: var(--snackbar-font-size); margin: var(--snackbar-margin); align-items: center; border-color: var(--snackbar-border-color); pointer-events: auto; transition: 0.3s var(--cubic-bezier);}.var-snackbar__wrapper-success { background: var(--snackbar-success-background);}.var-snackbar__wrapper-info { background: var(--snackbar-info-background);}.var-snackbar__wrapper-warning { background: var(--snackbar-warning-background);}.var-snackbar__wrapper-error { background: var(--snackbar-error-background);}.var-snackbar__icon { margin: var(--snackbar-icon-margin);}.var-snackbar__content { flex-grow: 1; word-break: break-all; padding: var(--snackbar-content-padding);}.var-snackbar__action { margin: var(--snackbar-action-margin); display: flex;}.var-snackbar__vertical { flex-direction: column; align-items: flex-start;}.var-snackbar__vertical .var-snackbar__action { align-self: flex-end; margin: var(--snackbar-vertical-action-margin);}.var-snackbar-fade-enter-from,.var-snackbar-fade-leave-to { opacity: 0; transform: translateY(-30px);}
1
+ :root { --snackbar-width: 256px; --snackbar-color: rgba(255, 255, 255, 0.87); --snackbar-border-radius: 4px; --snackbar-background: #333; --snackbar-font-size: var(--font-size-md); --snackbar-margin: 6px 24px; --snackbar-border-color: currentColor; --snackbar-success-background: var(--color-success); --snackbar-info-background: var(--color-info); --snackbar-error-background: var(--color-danger); --snackbar-warning-background: var(--color-warning); --snackbar-content-padding: 14px 16px; --snackbar-action-margin: 0 8px; --snackbar-vertical-action-margin: 0 8px 8px 0; --snackbar-icon-margin: 0 8px; --snackbar-progress-height: 4px; --snackbar-progress-color: currentColor;}.var-transition-group { position: fixed; left: 0; right: 0; top: 0; bottom: 0; pointer-events: none;}.var-pointer-auto { pointer-events: auto;}.var-snackbar { display: flex; justify-content: center; align-items: baseline; left: 0; right: 0; bottom: 0; transition: all 0.15s var(--cubic-bezier);}.var-snackbar__transition { top: 0; position: fixed;}.var-snackbar__transition .var-snackbar__wrapper { position: absolute;}.var-snackbar__transition .var-snackbar__wrapper-top { top: 5%;}.var-snackbar__transition .var-snackbar__wrapper-center { top: 45%;}.var-snackbar__transition .var-snackbar__wrapper-bottom { bottom: 5%;}.var-snackbar__wrapper { width: var(--snackbar-width); display: flex; border-radius: var(--snackbar-border-radius); color: var(--snackbar-color); background: var(--snackbar-background); font-size: var(--snackbar-font-size); margin: var(--snackbar-margin); align-items: center; border-color: var(--snackbar-border-color); pointer-events: auto; transition: 0.3s var(--cubic-bezier);}.var-snackbar__wrapper--progress { position: relative;}.var-snackbar__wrapper-success { background: var(--snackbar-success-background);}.var-snackbar__wrapper-info { background: var(--snackbar-info-background);}.var-snackbar__wrapper-warning { background: var(--snackbar-warning-background);}.var-snackbar__wrapper-error { background: var(--snackbar-error-background);}.var-snackbar__icon { margin: var(--snackbar-icon-margin);}.var-snackbar__progress { position: absolute; right: 0; bottom: 0; left: 0; height: var(--snackbar-progress-height); overflow: hidden; border-radius: 0 0 var(--snackbar-border-radius) var(--snackbar-border-radius); pointer-events: none;}.var-snackbar__progress-bar { height: 100%; background: var(--snackbar-progress-color); opacity: 0.4; transform-origin: left; animation: var-snackbar-progress linear forwards;}.var-snackbar__content { flex-grow: 1; word-break: break-all; padding: var(--snackbar-content-padding);}.var-snackbar__action { margin: var(--snackbar-action-margin); display: flex;}.var-snackbar__vertical { flex-direction: column; align-items: flex-start;}.var-snackbar__vertical .var-snackbar__action { align-self: flex-end; margin: var(--snackbar-vertical-action-margin);}.var-snackbar-fade-enter-from,.var-snackbar-fade-leave-to { opacity: 0; transform: translateY(-30px);}@keyframes var-snackbar-progress { from { transform: scaleX(1); } to { transform: scaleX(0); }}
@@ -1,7 +1,7 @@
1
1
  import '../../styles/common.css'
2
+ import '../SnackbarSfc.css'
2
3
  import '../../styles/elevation.css'
3
4
  import '../../loading/loading.css'
4
5
  import '../../icon/icon.css'
5
6
  import '../snackbar.css'
6
7
  import '../coreSfc.css'
7
- import '../SnackbarSfc.css'