@varlet/ui 3.7.1 → 3.7.2-alpha.1733247317826
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/es/action-sheet/style/index.mjs +1 -1
- package/es/index.bundle.mjs +1 -1
- package/es/index.mjs +1 -1
- package/es/menu/Menu.mjs +11 -17
- package/es/menu/props.mjs +1 -1
- package/es/menu/usePopover.mjs +68 -43
- package/es/menu-select/MenuSelect.mjs +6 -1
- package/es/style.css +1 -1
- package/es/switch/switch.css +1 -1
- package/es/themes/dark/switch.mjs +14 -1
- package/es/themes/md3-dark/switch.mjs +14 -1
- package/es/themes/md3-light/switch.mjs +14 -1
- package/es/tooltip/Tooltip.mjs +11 -17
- package/es/tooltip/props.mjs +1 -1
- package/es/varlet.esm.js +4540 -4496
- package/highlight/web-types.en-US.json +1 -1
- package/highlight/web-types.zh-CN.json +1 -1
- package/lib/style.css +1 -1
- package/lib/varlet.cjs.js +139 -82
- package/package.json +7 -7
- package/types/menu.d.ts +3 -1
- package/types/menuSelect.d.ts +3 -1
- package/types/styleVars.d.ts +13 -0
- package/types/tooltip.d.ts +3 -1
- package/umd/varlet.js +8 -8
package/es/index.bundle.mjs
CHANGED
|
@@ -280,7 +280,7 @@ import './tooltip/style/index.mjs'
|
|
|
280
280
|
import './uploader/style/index.mjs'
|
|
281
281
|
import './watermark/style/index.mjs'
|
|
282
282
|
|
|
283
|
-
const version = '3.7.
|
|
283
|
+
const version = '3.7.2-alpha.1733247317826'
|
|
284
284
|
|
|
285
285
|
function install(app) {
|
|
286
286
|
ActionSheet.install && app.use(ActionSheet)
|
package/es/index.mjs
CHANGED
|
@@ -186,7 +186,7 @@ export * from './tooltip/index.mjs'
|
|
|
186
186
|
export * from './uploader/index.mjs'
|
|
187
187
|
export * from './watermark/index.mjs'
|
|
188
188
|
|
|
189
|
-
const version = '3.7.
|
|
189
|
+
const version = '3.7.2-alpha.1733247317826'
|
|
190
190
|
|
|
191
191
|
function install(app) {
|
|
192
192
|
ActionSheet.install && app.use(ActionSheet)
|
package/es/menu/Menu.mjs
CHANGED
|
@@ -10,10 +10,7 @@ function __render__(_ctx, _cache) {
|
|
|
10
10
|
"div",
|
|
11
11
|
{
|
|
12
12
|
ref: "host",
|
|
13
|
-
class: _normalizeClass(_ctx.classes(_ctx.n(), _ctx.n("$--box")))
|
|
14
|
-
onClick: _cache[3] || (_cache[3] = (...args) => _ctx.handleHostClick && _ctx.handleHostClick(...args)),
|
|
15
|
-
onMouseenter: _cache[4] || (_cache[4] = (...args) => _ctx.handleHostMouseenter && _ctx.handleHostMouseenter(...args)),
|
|
16
|
-
onMouseleave: _cache[5] || (_cache[5] = (...args) => _ctx.handleHostMouseleave && _ctx.handleHostMouseleave(...args))
|
|
13
|
+
class: _normalizeClass(_ctx.classes(_ctx.n(), _ctx.n("$--box")))
|
|
17
14
|
},
|
|
18
15
|
[
|
|
19
16
|
_renderSlot(_ctx.$slots, "default"),
|
|
@@ -34,7 +31,7 @@ function __render__(_ctx, _cache) {
|
|
|
34
31
|
ref: "popover",
|
|
35
32
|
style: _normalizeStyle({
|
|
36
33
|
zIndex: _ctx.zIndex,
|
|
37
|
-
width: _ctx.sameWidth ? _ctx.toSizeUnit(Math.ceil(_ctx.
|
|
34
|
+
width: _ctx.sameWidth ? _ctx.toSizeUnit(Math.ceil(_ctx.referenceSize.width)) : void 0
|
|
38
35
|
}),
|
|
39
36
|
class: _normalizeClass(
|
|
40
37
|
_ctx.classes(
|
|
@@ -64,8 +61,8 @@ function __render__(_ctx, _cache) {
|
|
|
64
61
|
}, 8, ["name", "onAfterEnter", "onAfterLeave"])
|
|
65
62
|
], 8, ["to", "disabled"]))
|
|
66
63
|
],
|
|
67
|
-
|
|
68
|
-
/* CLASS
|
|
64
|
+
2
|
|
65
|
+
/* CLASS */
|
|
69
66
|
);
|
|
70
67
|
}
|
|
71
68
|
const __sfc__ = defineComponent({
|
|
@@ -76,12 +73,9 @@ const __sfc__ = defineComponent({
|
|
|
76
73
|
const {
|
|
77
74
|
popover,
|
|
78
75
|
host,
|
|
79
|
-
|
|
76
|
+
referenceSize,
|
|
80
77
|
show,
|
|
81
78
|
zIndex,
|
|
82
|
-
handleHostClick,
|
|
83
|
-
handleHostMouseenter,
|
|
84
|
-
handleHostMouseleave,
|
|
85
79
|
handlePopoverMouseenter,
|
|
86
80
|
handlePopoverMouseleave,
|
|
87
81
|
handlePopoverClose,
|
|
@@ -91,12 +85,14 @@ const __sfc__ = defineComponent({
|
|
|
91
85
|
// expose
|
|
92
86
|
close,
|
|
93
87
|
// expose
|
|
94
|
-
resize
|
|
88
|
+
resize,
|
|
89
|
+
// expose
|
|
90
|
+
setReference
|
|
95
91
|
} = usePopover(props2);
|
|
96
92
|
return {
|
|
97
93
|
popover,
|
|
98
94
|
host,
|
|
99
|
-
|
|
95
|
+
referenceSize,
|
|
100
96
|
show,
|
|
101
97
|
zIndex,
|
|
102
98
|
teleportDisabled,
|
|
@@ -104,16 +100,14 @@ const __sfc__ = defineComponent({
|
|
|
104
100
|
toSizeUnit,
|
|
105
101
|
n,
|
|
106
102
|
classes,
|
|
107
|
-
handleHostClick,
|
|
108
|
-
handleHostMouseenter,
|
|
109
|
-
handleHostMouseleave,
|
|
110
103
|
handlePopoverMouseenter,
|
|
111
104
|
handlePopoverMouseleave,
|
|
112
105
|
handlePopoverClose,
|
|
113
106
|
handleClosed,
|
|
114
107
|
resize,
|
|
115
108
|
open,
|
|
116
|
-
close
|
|
109
|
+
close,
|
|
110
|
+
setReference
|
|
117
111
|
};
|
|
118
112
|
}
|
|
119
113
|
});
|
package/es/menu/props.mjs
CHANGED
package/es/menu/usePopover.mjs
CHANGED
|
@@ -40,8 +40,8 @@ var __async = (__this, __arguments, generator) => {
|
|
|
40
40
|
import flip from "@popperjs/core/lib/modifiers/flip.js";
|
|
41
41
|
import offset from "@popperjs/core/lib/modifiers/offset.js";
|
|
42
42
|
import computeStyles from "@popperjs/core/lib/modifiers/computeStyles.js";
|
|
43
|
-
import { onWindowResize,
|
|
44
|
-
import { doubleRaf, getStyle, call, preventDefault } from "@varlet/shared";
|
|
43
|
+
import { onWindowResize, useEventListener, useVModel } from "@varlet/use";
|
|
44
|
+
import { doubleRaf, getStyle, call, preventDefault, isString } from "@varlet/shared";
|
|
45
45
|
import { toPxNum } from "../utils/elements.mjs";
|
|
46
46
|
import { onMounted, onUnmounted, ref, watch } from "vue";
|
|
47
47
|
import { createPopper } from "@popperjs/core/lib/popper-lite.js";
|
|
@@ -50,7 +50,7 @@ import { useStack } from "../context/stack.mjs";
|
|
|
50
50
|
function usePopover(options) {
|
|
51
51
|
const host = ref(null);
|
|
52
52
|
const popover = ref(null);
|
|
53
|
-
const
|
|
53
|
+
const referenceSize = ref({ width: 0, height: 0 });
|
|
54
54
|
const show = useVModel(options, "show", {
|
|
55
55
|
passive: true,
|
|
56
56
|
defaultValue: false,
|
|
@@ -65,11 +65,10 @@ function usePopover(options) {
|
|
|
65
65
|
const { zIndex } = useZIndex(() => show.value, 1);
|
|
66
66
|
useStack(() => show.value, zIndex);
|
|
67
67
|
let popoverInstance = null;
|
|
68
|
+
let reference;
|
|
68
69
|
let enterPopover = false;
|
|
69
|
-
let
|
|
70
|
+
let enterReference = false;
|
|
70
71
|
useEventListener(() => window, "keydown", handleKeydown);
|
|
71
|
-
useClickOutside(getReference, "click", handleClickOutside);
|
|
72
|
-
onWindowResize(resize);
|
|
73
72
|
watch(() => [options.offsetX, options.offsetY, options.placement, options.strategy], resize);
|
|
74
73
|
watch(() => options.disabled, close);
|
|
75
74
|
watch(
|
|
@@ -80,19 +79,34 @@ function usePopover(options) {
|
|
|
80
79
|
}
|
|
81
80
|
}
|
|
82
81
|
);
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
82
|
+
onWindowResize(resize);
|
|
83
|
+
onMounted(createPopperInstance);
|
|
84
|
+
onUnmounted(destroyPopperInstance);
|
|
85
|
+
function createPopperInstance() {
|
|
86
|
+
const reference2 = getReference();
|
|
87
|
+
popoverInstance = createPopper(reference2, popover.value, getPopperOptions());
|
|
88
|
+
reference2.addEventListener("mouseenter", handleReferenceMouseenter);
|
|
89
|
+
reference2.addEventListener("mouseleave", handleReferenceMouseleave);
|
|
90
|
+
reference2.addEventListener("click", handleReferenceClick);
|
|
91
|
+
document.addEventListener("click", handleClickOutside);
|
|
92
|
+
}
|
|
93
|
+
function destroyPopperInstance() {
|
|
94
|
+
const reference2 = getReference();
|
|
95
|
+
if (reference2) {
|
|
96
|
+
reference2.removeEventListener("mouseenter", handleReferenceMouseenter);
|
|
97
|
+
reference2.removeEventListener("mouseleave", handleReferenceMouseleave);
|
|
98
|
+
reference2.removeEventListener("click", handleReferenceClick);
|
|
99
|
+
}
|
|
88
100
|
popoverInstance.destroy();
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
101
|
+
document.removeEventListener("click", handleClickOutside);
|
|
102
|
+
}
|
|
103
|
+
function computeReferenceSize() {
|
|
104
|
+
const reference2 = getReference();
|
|
105
|
+
if (!reference2) {
|
|
92
106
|
return;
|
|
93
107
|
}
|
|
94
|
-
const { width, height } = getStyle(
|
|
95
|
-
|
|
108
|
+
const { width, height } = getStyle(reference2);
|
|
109
|
+
referenceSize.value = {
|
|
96
110
|
width: toPxNum(width),
|
|
97
111
|
height: toPxNum(height)
|
|
98
112
|
};
|
|
@@ -129,19 +143,19 @@ function usePopover(options) {
|
|
|
129
143
|
return "left";
|
|
130
144
|
}
|
|
131
145
|
}
|
|
132
|
-
function
|
|
146
|
+
function handleReferenceMouseenter() {
|
|
133
147
|
if (options.trigger !== "hover") {
|
|
134
148
|
return;
|
|
135
149
|
}
|
|
136
|
-
|
|
150
|
+
enterReference = true;
|
|
137
151
|
open();
|
|
138
152
|
}
|
|
139
|
-
function
|
|
153
|
+
function handleReferenceMouseleave() {
|
|
140
154
|
return __async(this, null, function* () {
|
|
141
155
|
if (options.trigger !== "hover") {
|
|
142
156
|
return;
|
|
143
157
|
}
|
|
144
|
-
|
|
158
|
+
enterReference = false;
|
|
145
159
|
yield doubleRaf();
|
|
146
160
|
if (enterPopover) {
|
|
147
161
|
return;
|
|
@@ -162,13 +176,13 @@ function usePopover(options) {
|
|
|
162
176
|
}
|
|
163
177
|
enterPopover = false;
|
|
164
178
|
yield doubleRaf();
|
|
165
|
-
if (
|
|
179
|
+
if (enterReference) {
|
|
166
180
|
return;
|
|
167
181
|
}
|
|
168
182
|
close();
|
|
169
183
|
});
|
|
170
184
|
}
|
|
171
|
-
function
|
|
185
|
+
function handleReferenceClick() {
|
|
172
186
|
if (options.trigger !== "click") {
|
|
173
187
|
return;
|
|
174
188
|
}
|
|
@@ -178,15 +192,18 @@ function usePopover(options) {
|
|
|
178
192
|
}
|
|
179
193
|
open();
|
|
180
194
|
}
|
|
181
|
-
function handlePopoverClose() {
|
|
182
|
-
close();
|
|
183
|
-
}
|
|
184
195
|
function handleClickOutside(e) {
|
|
185
|
-
|
|
186
|
-
|
|
196
|
+
const reference2 = getReference();
|
|
197
|
+
if (reference2 && !reference2.contains(e.target)) {
|
|
198
|
+
if (options.trigger !== "click") {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
handlePopoverClose();
|
|
202
|
+
call(options.onClickOutside, e);
|
|
187
203
|
}
|
|
188
|
-
|
|
189
|
-
|
|
204
|
+
}
|
|
205
|
+
function handlePopoverClose() {
|
|
206
|
+
close();
|
|
190
207
|
}
|
|
191
208
|
function handleClosed() {
|
|
192
209
|
resize();
|
|
@@ -194,7 +211,7 @@ function usePopover(options) {
|
|
|
194
211
|
}
|
|
195
212
|
function getPosition() {
|
|
196
213
|
const { offsetX, offsetY, placement } = options;
|
|
197
|
-
|
|
214
|
+
computeReferenceSize();
|
|
198
215
|
const offset2 = {
|
|
199
216
|
x: toPxNum(offsetX),
|
|
200
217
|
y: toPxNum(offsetY)
|
|
@@ -204,49 +221,49 @@ function usePopover(options) {
|
|
|
204
221
|
return {
|
|
205
222
|
placement: "bottom",
|
|
206
223
|
skidding: offset2.x,
|
|
207
|
-
distance: offset2.y -
|
|
224
|
+
distance: offset2.y - referenceSize.value.height
|
|
208
225
|
};
|
|
209
226
|
case "cover-top-start":
|
|
210
227
|
return {
|
|
211
228
|
placement: "bottom-start",
|
|
212
229
|
skidding: offset2.x,
|
|
213
|
-
distance: offset2.y -
|
|
230
|
+
distance: offset2.y - referenceSize.value.height
|
|
214
231
|
};
|
|
215
232
|
case "cover-top-end":
|
|
216
233
|
return {
|
|
217
234
|
placement: "bottom-end",
|
|
218
235
|
skidding: offset2.x,
|
|
219
|
-
distance: offset2.y -
|
|
236
|
+
distance: offset2.y - referenceSize.value.height
|
|
220
237
|
};
|
|
221
238
|
case "cover-bottom":
|
|
222
239
|
return {
|
|
223
240
|
placement: "top",
|
|
224
241
|
skidding: offset2.x,
|
|
225
|
-
distance: -offset2.y -
|
|
242
|
+
distance: -offset2.y - referenceSize.value.height
|
|
226
243
|
};
|
|
227
244
|
case "cover-bottom-start":
|
|
228
245
|
return {
|
|
229
246
|
placement: "top-start",
|
|
230
247
|
skidding: offset2.x,
|
|
231
|
-
distance: -offset2.y -
|
|
248
|
+
distance: -offset2.y - referenceSize.value.height
|
|
232
249
|
};
|
|
233
250
|
case "cover-bottom-end":
|
|
234
251
|
return {
|
|
235
252
|
placement: "top-end",
|
|
236
253
|
skidding: offset2.x,
|
|
237
|
-
distance: -offset2.y -
|
|
254
|
+
distance: -offset2.y - referenceSize.value.height
|
|
238
255
|
};
|
|
239
256
|
case "cover-left":
|
|
240
257
|
return {
|
|
241
258
|
placement: "right",
|
|
242
259
|
skidding: offset2.y,
|
|
243
|
-
distance: offset2.x -
|
|
260
|
+
distance: offset2.x - referenceSize.value.width
|
|
244
261
|
};
|
|
245
262
|
case "cover-right":
|
|
246
263
|
return {
|
|
247
264
|
placement: "left",
|
|
248
265
|
skidding: offset2.y,
|
|
249
|
-
distance: -offset2.x -
|
|
266
|
+
distance: -offset2.x - referenceSize.value.width
|
|
250
267
|
};
|
|
251
268
|
case "left":
|
|
252
269
|
case "left-start":
|
|
@@ -316,7 +333,17 @@ function usePopover(options) {
|
|
|
316
333
|
};
|
|
317
334
|
}
|
|
318
335
|
function getReference() {
|
|
319
|
-
|
|
336
|
+
var _a, _b;
|
|
337
|
+
const targetReference = (_a = reference != null ? reference : options.reference) != null ? _a : host.value;
|
|
338
|
+
if (isString(targetReference)) {
|
|
339
|
+
return (_b = host.value) == null ? void 0 : _b.querySelector(targetReference);
|
|
340
|
+
}
|
|
341
|
+
return targetReference;
|
|
342
|
+
}
|
|
343
|
+
function setReference(newReference) {
|
|
344
|
+
destroyPopperInstance();
|
|
345
|
+
reference = newReference;
|
|
346
|
+
createPopperInstance();
|
|
320
347
|
}
|
|
321
348
|
function handleKeydown(event) {
|
|
322
349
|
const { closeOnKeyEscape = false } = options;
|
|
@@ -344,14 +371,12 @@ function usePopover(options) {
|
|
|
344
371
|
popover,
|
|
345
372
|
zIndex,
|
|
346
373
|
host,
|
|
347
|
-
|
|
348
|
-
handleHostClick,
|
|
349
|
-
handleHostMouseenter,
|
|
350
|
-
handleHostMouseleave,
|
|
374
|
+
referenceSize,
|
|
351
375
|
handlePopoverClose,
|
|
352
376
|
handlePopoverMouseenter,
|
|
353
377
|
handlePopoverMouseleave,
|
|
354
378
|
handleClosed,
|
|
379
|
+
setReference,
|
|
355
380
|
resize,
|
|
356
381
|
open,
|
|
357
382
|
close
|
|
@@ -137,6 +137,10 @@ const __sfc__ = defineComponent({
|
|
|
137
137
|
var _a;
|
|
138
138
|
(_a = menu.value) == null ? void 0 : _a.resize();
|
|
139
139
|
}
|
|
140
|
+
function setReference(reference) {
|
|
141
|
+
var _a;
|
|
142
|
+
(_a = menu.value) == null ? void 0 : _a.setReference(reference);
|
|
143
|
+
}
|
|
140
144
|
return {
|
|
141
145
|
show,
|
|
142
146
|
menu,
|
|
@@ -146,7 +150,8 @@ const __sfc__ = defineComponent({
|
|
|
146
150
|
formatElevation,
|
|
147
151
|
open,
|
|
148
152
|
close,
|
|
149
|
-
resize
|
|
153
|
+
resize,
|
|
154
|
+
setReference
|
|
150
155
|
};
|
|
151
156
|
}
|
|
152
157
|
});
|