@varlet/ui 3.7.1 → 3.7.2-alpha.1733245375527

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.
@@ -3,5 +3,5 @@ import '../../icon/icon.css'
3
3
  import '../../ripple/ripple.css'
4
4
  import '../../popup/popup.css'
5
5
  import '../actionSheet.css'
6
- import '../ActionSheetSfc.css'
7
6
  import '../ActionItemSfc.css'
7
+ import '../ActionSheetSfc.css'
@@ -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.1'
283
+ const version = '3.7.2-alpha.1733245375527'
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.1'
189
+ const version = '3.7.2-alpha.1733245375527'
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.hostSize.width)) : void 0
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
- 34
68
- /* CLASS, NEED_HYDRATION */
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
- hostSize,
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
- hostSize,
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
@@ -6,7 +6,7 @@ const props = {
6
6
  type: String,
7
7
  default: "click"
8
8
  },
9
- reference: String,
9
+ reference: [String, Object],
10
10
  placement: {
11
11
  type: String,
12
12
  default: "cover-top-start"
@@ -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, useClickOutside, useEventListener, useVModel } from "@varlet/use";
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 hostSize = ref({ width: 0, height: 0 });
53
+ const referenceSize = ref({ width: 0, height: 0 });
54
54
  const show = useVModel(options, "show", {
55
55
  passive: true,
56
56
  defaultValue: false,
@@ -65,10 +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
70
  let enterHost = false;
70
71
  useEventListener(() => window, "keydown", handleKeydown);
71
- useClickOutside(getReference, "click", handleClickOutside);
72
72
  onWindowResize(resize);
73
73
  watch(() => [options.offsetX, options.offsetY, options.placement, options.strategy], resize);
74
74
  watch(() => options.disabled, close);
@@ -80,19 +80,31 @@ function usePopover(options) {
80
80
  }
81
81
  }
82
82
  );
83
- onMounted(() => {
84
- var _a;
85
- popoverInstance = createPopper((_a = getReference()) != null ? _a : host.value, popover.value, getPopperOptions());
86
- });
87
- onUnmounted(() => {
83
+ onMounted(createPopperInstance);
84
+ onUnmounted(destroyPopperInstance);
85
+ function createPopperInstance() {
86
+ const reference2 = getReference();
87
+ popoverInstance = createPopper(reference2, popover.value, getPopperOptions());
88
+ reference2.addEventListener("mouseenter", handleHostMouseenter);
89
+ reference2.addEventListener("mouseleave", handleHostMouseleave);
90
+ reference2.addEventListener("click", handleReferenceClick);
91
+ document.addEventListener("click", handleClickOutside);
92
+ }
93
+ function destroyPopperInstance() {
94
+ const reference2 = getReference();
88
95
  popoverInstance.destroy();
89
- });
90
- function computeHostSize() {
91
- if (!host.value) {
96
+ reference2.removeEventListener("mouseenter", handleHostMouseenter);
97
+ reference2.removeEventListener("mouseleave", handleHostMouseleave);
98
+ reference2.removeEventListener("click", handleReferenceClick);
99
+ document.removeEventListener("click", handleClickOutside);
100
+ }
101
+ function computeReferenceSize() {
102
+ const reference2 = getReference();
103
+ if (!reference2) {
92
104
  return;
93
105
  }
94
- const { width, height } = getStyle(host.value);
95
- hostSize.value = {
106
+ const { width, height } = getStyle(reference2);
107
+ referenceSize.value = {
96
108
  width: toPxNum(width),
97
109
  height: toPxNum(height)
98
110
  };
@@ -168,7 +180,7 @@ function usePopover(options) {
168
180
  close();
169
181
  });
170
182
  }
171
- function handleHostClick() {
183
+ function handleReferenceClick() {
172
184
  if (options.trigger !== "click") {
173
185
  return;
174
186
  }
@@ -178,15 +190,18 @@ function usePopover(options) {
178
190
  }
179
191
  open();
180
192
  }
181
- function handlePopoverClose() {
182
- close();
183
- }
184
193
  function handleClickOutside(e) {
185
- if (options.trigger !== "click") {
186
- return;
194
+ const reference2 = getReference();
195
+ if (reference2 && !reference2.contains(e.target)) {
196
+ if (options.trigger !== "click") {
197
+ return;
198
+ }
199
+ handlePopoverClose();
200
+ call(options.onClickOutside, e);
187
201
  }
188
- handlePopoverClose();
189
- call(options.onClickOutside, e);
202
+ }
203
+ function handlePopoverClose() {
204
+ close();
190
205
  }
191
206
  function handleClosed() {
192
207
  resize();
@@ -194,7 +209,7 @@ function usePopover(options) {
194
209
  }
195
210
  function getPosition() {
196
211
  const { offsetX, offsetY, placement } = options;
197
- computeHostSize();
212
+ computeReferenceSize();
198
213
  const offset2 = {
199
214
  x: toPxNum(offsetX),
200
215
  y: toPxNum(offsetY)
@@ -204,49 +219,49 @@ function usePopover(options) {
204
219
  return {
205
220
  placement: "bottom",
206
221
  skidding: offset2.x,
207
- distance: offset2.y - hostSize.value.height
222
+ distance: offset2.y - referenceSize.value.height
208
223
  };
209
224
  case "cover-top-start":
210
225
  return {
211
226
  placement: "bottom-start",
212
227
  skidding: offset2.x,
213
- distance: offset2.y - hostSize.value.height
228
+ distance: offset2.y - referenceSize.value.height
214
229
  };
215
230
  case "cover-top-end":
216
231
  return {
217
232
  placement: "bottom-end",
218
233
  skidding: offset2.x,
219
- distance: offset2.y - hostSize.value.height
234
+ distance: offset2.y - referenceSize.value.height
220
235
  };
221
236
  case "cover-bottom":
222
237
  return {
223
238
  placement: "top",
224
239
  skidding: offset2.x,
225
- distance: -offset2.y - hostSize.value.height
240
+ distance: -offset2.y - referenceSize.value.height
226
241
  };
227
242
  case "cover-bottom-start":
228
243
  return {
229
244
  placement: "top-start",
230
245
  skidding: offset2.x,
231
- distance: -offset2.y - hostSize.value.height
246
+ distance: -offset2.y - referenceSize.value.height
232
247
  };
233
248
  case "cover-bottom-end":
234
249
  return {
235
250
  placement: "top-end",
236
251
  skidding: offset2.x,
237
- distance: -offset2.y - hostSize.value.height
252
+ distance: -offset2.y - referenceSize.value.height
238
253
  };
239
254
  case "cover-left":
240
255
  return {
241
256
  placement: "right",
242
257
  skidding: offset2.y,
243
- distance: offset2.x - hostSize.value.width
258
+ distance: offset2.x - referenceSize.value.width
244
259
  };
245
260
  case "cover-right":
246
261
  return {
247
262
  placement: "left",
248
263
  skidding: offset2.y,
249
- distance: -offset2.x - hostSize.value.width
264
+ distance: -offset2.x - referenceSize.value.width
250
265
  };
251
266
  case "left":
252
267
  case "left-start":
@@ -316,7 +331,17 @@ function usePopover(options) {
316
331
  };
317
332
  }
318
333
  function getReference() {
319
- return options.reference ? host.value.querySelector(options.reference) : host.value;
334
+ var _a, _b;
335
+ const targetReference = (_a = reference != null ? reference : options.reference) != null ? _a : host.value;
336
+ if (isString(targetReference)) {
337
+ return (_b = host.value) == null ? void 0 : _b.querySelector(targetReference);
338
+ }
339
+ return targetReference;
340
+ }
341
+ function setReference(newReference) {
342
+ destroyPopperInstance();
343
+ reference = newReference;
344
+ createPopperInstance();
320
345
  }
321
346
  function handleKeydown(event) {
322
347
  const { closeOnKeyEscape = false } = options;
@@ -344,14 +369,12 @@ function usePopover(options) {
344
369
  popover,
345
370
  zIndex,
346
371
  host,
347
- hostSize,
348
- handleHostClick,
349
- handleHostMouseenter,
350
- handleHostMouseleave,
372
+ referenceSize,
351
373
  handlePopoverClose,
352
374
  handlePopoverMouseenter,
353
375
  handlePopoverMouseleave,
354
376
  handleClosed,
377
+ setReference,
355
378
  resize,
356
379
  open,
357
380
  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
  });