@varlet/ui 3.4.0 → 3.5.0-alpha.1726330414687

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.
Files changed (43) hide show
  1. package/es/auto-complete/AutoComplete.mjs +20 -11
  2. package/es/auto-complete/props.mjs +1 -1
  3. package/es/checkbox/props.mjs +1 -1
  4. package/es/checkbox-group/props.mjs +1 -1
  5. package/es/counter/props.mjs +2 -2
  6. package/es/field-decorator/FieldDecorator.mjs +7 -0
  7. package/es/index.bundle.mjs +1 -1
  8. package/es/index.mjs +1 -1
  9. package/es/input/props.mjs +1 -1
  10. package/es/menu-select/MenuSelect.mjs +1 -0
  11. package/es/menu-select/props.mjs +9 -2
  12. package/es/radio/props.mjs +1 -1
  13. package/es/radio-group/props.mjs +1 -1
  14. package/es/select/props.mjs +1 -1
  15. package/es/slider/props.mjs +1 -1
  16. package/es/snackbar/style/index.mjs +1 -1
  17. package/es/swipe/Swipe.mjs +6 -1
  18. package/es/swipe/provide.mjs +26 -2
  19. package/es/switch/props.mjs +1 -1
  20. package/es/tooltip/Tooltip.mjs +5 -1
  21. package/es/tooltip/props.mjs +1 -0
  22. package/es/uploader/props.mjs +1 -1
  23. package/es/utils/components.mjs +30 -9
  24. package/es/varlet.esm.js +5521 -5466
  25. package/highlight/web-types.en-US.json +33 -24
  26. package/highlight/web-types.zh-CN.json +34 -25
  27. package/lib/varlet.cjs.js +137 -72
  28. package/package.json +8 -7
  29. package/types/autoComplete.d.ts +2 -1
  30. package/types/checkbox.d.ts +2 -2
  31. package/types/checkboxGroup.d.ts +2 -1
  32. package/types/counter.d.ts +4 -4
  33. package/types/input.d.ts +9 -2
  34. package/types/radio.d.ts +2 -2
  35. package/types/radioGroup.d.ts +2 -1
  36. package/types/rate.d.ts +2 -2
  37. package/types/select.d.ts +9 -2
  38. package/types/slider.d.ts +2 -1
  39. package/types/switch.d.ts +2 -2
  40. package/types/tooltip.d.ts +1 -0
  41. package/types/uploader.d.ts +2 -2
  42. package/types/varComponent.d.ts +4 -0
  43. package/umd/varlet.js +7 -7
@@ -55,7 +55,8 @@ function __render__(_ctx, _cache) {
55
55
  "popover-class": _ctx.variant === "standard" ? _ctx.n("--standard-menu-margin") : void 0,
56
56
  show: _ctx.isShowMenuSelect,
57
57
  "onUpdate:show": _cache[1] || (_cache[1] = ($event) => _ctx.isShowMenuSelect = $event),
58
- "onUpdate:modelValue": _ctx.handleAutoComplete
58
+ "onUpdate:modelValue": _ctx.handleAutoComplete,
59
+ onKeyEscape: _ctx.handleKeyEscape
59
60
  }, {
60
61
  options: _withCtx(() => [
61
62
  _createElementVNode(
@@ -146,7 +147,7 @@ function __render__(_ctx, _cache) {
146
147
  ]),
147
148
  _: 3
148
149
  /* FORWARDED */
149
- }, 8, ["disabled", "class", "popover-class", "show", "onUpdate:modelValue"]),
150
+ }, 8, ["disabled", "class", "popover-class", "show", "onUpdate:modelValue", "onKeyEscape"]),
150
151
  _createVNode(_component_var_form_details, {
151
152
  "error-message": _ctx.errorMessage,
152
153
  "extra-message": _ctx.maxlengthText
@@ -303,15 +304,22 @@ const __sfc__ = defineComponent({
303
304
  validateWithTrigger("onChange");
304
305
  }
305
306
  function handleAutoComplete(newValue) {
306
- if (props2.maxlength != null) {
307
- newValue = newValue.slice(0, toNumber(props2.maxlength));
308
- }
309
- if (newValue === value.value) {
310
- return;
311
- }
312
- value.value = newValue;
313
- call(props2.onChange, newValue);
314
- validateWithTrigger("onChange");
307
+ return __async(this, null, function* () {
308
+ var _a;
309
+ if (props2.maxlength != null) {
310
+ newValue = newValue.slice(0, toNumber(props2.maxlength));
311
+ }
312
+ if (newValue !== value.value) {
313
+ value.value = newValue;
314
+ call(props2.onChange, newValue);
315
+ validateWithTrigger("onChange");
316
+ }
317
+ yield raf();
318
+ (_a = input.value) == null ? void 0 : _a.focus();
319
+ });
320
+ }
321
+ function handleKeyEscape() {
322
+ input.value.focus();
315
323
  }
316
324
  function getShowMenuSelect(newValue) {
317
325
  if (props2.disabled || props2.readonly || (form == null ? void 0 : form.disabled.value) || (form == null ? void 0 : form.readonly.value)) {
@@ -336,6 +344,7 @@ const __sfc__ = defineComponent({
336
344
  handleClick,
337
345
  handleChange,
338
346
  handleBlur,
347
+ handleKeyEscape,
339
348
  handleAutoComplete,
340
349
  reset,
341
350
  validate,
@@ -38,7 +38,7 @@ const props = __spreadValues({
38
38
  default: () => ["onInput", "onClear", "onChange"]
39
39
  },
40
40
  getShow: Function,
41
- rules: Array,
41
+ rules: [Array, Function, Object],
42
42
  onFocus: defineListenerProp(),
43
43
  onBlur: defineListenerProp(),
44
44
  onInput: defineListenerProp(),
@@ -26,7 +26,7 @@ const props = {
26
26
  type: Array,
27
27
  default: () => ["onChange"]
28
28
  },
29
- rules: Array,
29
+ rules: [Array, Function, Object],
30
30
  onClick: defineListenerProp(),
31
31
  onChange: defineListenerProp(),
32
32
  "onUpdate:modelValue": defineListenerProp(),
@@ -25,7 +25,7 @@ const props = {
25
25
  type: Array,
26
26
  default: () => ["onChange"]
27
27
  },
28
- rules: Array,
28
+ rules: [Array, Function, Object],
29
29
  onChange: defineListenerProp(),
30
30
  "onUpdate:modelValue": defineListenerProp()
31
31
  };
@@ -1,7 +1,7 @@
1
1
  import { defineListenerProp } from "../utils/components.mjs";
2
2
  const props = {
3
3
  modelValue: {
4
- type: [String, Number],
4
+ type: Number,
5
5
  default: 0
6
6
  },
7
7
  min: [String, Number],
@@ -45,7 +45,7 @@ const props = {
45
45
  type: Array,
46
46
  default: () => ["onInputChange", "onLazyChange", "onIncrement", "onDecrement"]
47
47
  },
48
- rules: Array,
48
+ rules: [Array, Function, Object],
49
49
  onBeforeChange: defineListenerProp(),
50
50
  onChange: defineListenerProp(),
51
51
  onIncrement: defineListenerProp(),
@@ -25,6 +25,7 @@ import { isEmpty, getStyle, call, doubleRaf } from "@varlet/shared";
25
25
  import { createNamespace } from "../utils/components.mjs";
26
26
  import { onWindowResize, onSmartMounted } from "@varlet/use";
27
27
  import { usePopup } from "../popup/provide.mjs";
28
+ import { useSwipeResizeDispatcher } from "../swipe/provide.mjs";
28
29
  const { name, n, classes } = createNamespace("field-decorator");
29
30
  import { renderSlot as _renderSlot, normalizeClass as _normalizeClass, createElementVNode as _createElementVNode, toDisplayString as _toDisplayString, normalizeStyle as _normalizeStyle, openBlock as _openBlock, createElementBlock as _createElementBlock, createCommentVNode as _createCommentVNode, resolveComponent as _resolveComponent, createVNode as _createVNode, Teleport as _Teleport, createBlock as _createBlock, Fragment as _Fragment, pushScopeId as _pushScopeId, popScopeId as _popScopeId } from "vue";
30
31
  const _withScopeId = (n2) => (_pushScopeId(""), n2 = n2(), _popScopeId(), n2);
@@ -237,6 +238,7 @@ const __sfc__ = defineComponent({
237
238
  const transitionDisabled = ref(true);
238
239
  const isFloating = computed(() => props2.hint && (!isEmpty(props2.value) || props2.isFocusing));
239
240
  const { popup, bindPopup } = usePopup();
241
+ const { bindSwipeResizeDispatcher } = useSwipeResizeDispatcher();
240
242
  const color = computed(
241
243
  () => !props2.isError ? props2.isFocusing ? props2.focusColor : props2.blurColor : void 0
242
244
  );
@@ -249,6 +251,11 @@ const __sfc__ = defineComponent({
249
251
  });
250
252
  onUpdated(resize);
251
253
  call(bindPopup, null);
254
+ call(bindSwipeResizeDispatcher, {
255
+ onResize() {
256
+ nextTick().then(resize);
257
+ }
258
+ });
252
259
  if (popup) {
253
260
  watch(
254
261
  () => popup.show.value,
@@ -268,7 +268,7 @@ import './tooltip/style/index.mjs'
268
268
  import './uploader/style/index.mjs'
269
269
  import './watermark/style/index.mjs'
270
270
 
271
- const version = '3.4.0'
271
+ const version = '3.5.0-alpha.1726330414687'
272
272
 
273
273
  function install(app) {
274
274
  ActionSheet.install && app.use(ActionSheet)
package/es/index.mjs CHANGED
@@ -178,7 +178,7 @@ export * from './tooltip/index.mjs'
178
178
  export * from './uploader/index.mjs'
179
179
  export * from './watermark/index.mjs'
180
180
 
181
- const version = '3.4.0'
181
+ const version = '3.5.0-alpha.1726330414687'
182
182
 
183
183
  function install(app) {
184
184
  ActionSheet.install && app.use(ActionSheet)
@@ -42,7 +42,7 @@ const props = __spreadProps(__spreadValues({
42
42
  type: Array,
43
43
  default: () => ["onInput", "onClear"]
44
44
  },
45
- rules: Array,
45
+ rules: [Array, Function, Object],
46
46
  enterkeyhint: String,
47
47
  onFocus: defineListenerProp(),
48
48
  onBlur: defineListenerProp(),
@@ -118,6 +118,7 @@ const __sfc__ = defineComponent({
118
118
  if (key === "Escape") {
119
119
  menu.value.$el.focus();
120
120
  close();
121
+ call(props2.onKeyEscape);
121
122
  return;
122
123
  }
123
124
  if (key === "ArrowDown" || key === "ArrowUp") {
@@ -1,4 +1,6 @@
1
1
  var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
2
4
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
4
6
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
@@ -14,9 +16,10 @@ var __spreadValues = (a, b) => {
14
16
  }
15
17
  return a;
16
18
  };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
17
20
  import { menuProps } from "../menu/index.mjs";
18
21
  import { defineListenerProp, pickProps } from "../utils/components.mjs";
19
- const props = __spreadValues({
22
+ const props = __spreadProps(__spreadValues({
20
23
  modelValue: {
21
24
  type: [String, Number, Boolean, Array],
22
25
  default: void 0
@@ -64,7 +67,11 @@ const props = __spreadValues({
64
67
  "onClosed",
65
68
  "onClickOutside",
66
69
  "onUpdate:show"
67
- ]));
70
+ ])), {
71
+ // internal start
72
+ onKeyEscape: defineListenerProp()
73
+ // internal end
74
+ });
68
75
  export {
69
76
  props
70
77
  };
@@ -25,7 +25,7 @@ const props = {
25
25
  type: Array,
26
26
  default: () => ["onChange"]
27
27
  },
28
- rules: Array,
28
+ rules: [Array, Function, Object],
29
29
  onClick: defineListenerProp(),
30
30
  onChange: defineListenerProp(),
31
31
  "onUpdate:modelValue": defineListenerProp()
@@ -24,7 +24,7 @@ const props = {
24
24
  type: Array,
25
25
  default: () => ["onChange"]
26
26
  },
27
- rules: Array,
27
+ rules: [Array, Function, Object],
28
28
  onChange: defineListenerProp(),
29
29
  "onUpdate:modelValue": defineListenerProp()
30
30
  };
@@ -52,7 +52,7 @@ const props = __spreadValues({
52
52
  type: Array,
53
53
  default: () => ["onChange", "onClear", "onClose"]
54
54
  },
55
- rules: Array,
55
+ rules: [Array, Function, Object],
56
56
  onFocus: defineListenerProp(),
57
57
  onBlur: defineListenerProp(),
58
58
  onClose: defineListenerProp(),
@@ -39,7 +39,7 @@ const props = {
39
39
  type: String,
40
40
  default: "horizontal"
41
41
  },
42
- rules: Array,
42
+ rules: [Array, Function, Object],
43
43
  onChange: defineListenerProp(),
44
44
  onStart: defineListenerProp(),
45
45
  onEnd: defineListenerProp(),
@@ -1,7 +1,7 @@
1
1
  import '../../styles/common.css'
2
- import '../SnackbarSfc.css'
3
2
  import '../../styles/elevation.css'
4
3
  import '../../loading/loading.css'
5
4
  import '../../icon/icon.css'
6
5
  import '../snackbar.css'
7
6
  import '../coreSfc.css'
7
+ import '../SnackbarSfc.css'
@@ -22,7 +22,7 @@ import VarButton from "../button/index.mjs";
22
22
  import VarIcon from "../icon/index.mjs";
23
23
  import Hover from "../hover/index.mjs";
24
24
  import { defineComponent, ref, computed, watch, onActivated } from "vue";
25
- import { useSwipeItems } from "./provide.mjs";
25
+ import { useSwipeItems, useSwipeResizeListeners } from "./provide.mjs";
26
26
  import { props } from "./props.mjs";
27
27
  import { clamp, isNumber, toNumber, doubleRaf, preventDefault, call } from "@varlet/shared";
28
28
  import { createNamespace } from "../utils/components.mjs";
@@ -212,6 +212,7 @@ const __sfc__ = defineComponent({
212
212
  const index = ref(0);
213
213
  const hovering = ref(false);
214
214
  const { swipeItems, bindSwipeItems, length } = useSwipeItems();
215
+ const { swipeResizeListeners, bindSwipeResizeListeners } = useSwipeResizeListeners();
215
216
  const { popup, bindPopup } = usePopup();
216
217
  const {
217
218
  deltaX,
@@ -238,6 +239,7 @@ const __sfc__ = defineComponent({
238
239
  bindSwipeItems(swipeProvider);
239
240
  useEventListener(() => window, "keydown", handleKeydown);
240
241
  call(bindPopup, null);
242
+ call(bindSwipeResizeListeners, null);
241
243
  watch(
242
244
  () => length.value,
243
245
  () => __async(this, null, function* () {
@@ -440,6 +442,9 @@ const __sfc__ = defineComponent({
440
442
  setTimeout(() => {
441
443
  lockDuration.value = false;
442
444
  });
445
+ swipeResizeListeners.forEach(({ onResize }) => {
446
+ onResize();
447
+ });
443
448
  }
444
449
  function next(options) {
445
450
  return __async(this, null, function* () {
@@ -1,5 +1,8 @@
1
- import { useChildren } from "@varlet/use";
1
+ import { useChildren, useParent } from "@varlet/use";
2
2
  const SWIPE_BIND_SWIPE_ITEM_KEY = Symbol("SWIPE_BIND_SWIPE_ITEM_KEY");
3
+ const SWIPE_RESIZE_DISPATCHER_BIND_SWIPE_RESIZE_LISTENER_KEY = Symbol(
4
+ "SWIPE_RESIZE_DISPATCHER_BIND_SWIPE_RESIZE_LISTENER_KEY"
5
+ );
3
6
  function useSwipeItems() {
4
7
  const { childProviders, length, bindChildren } = useChildren(
5
8
  SWIPE_BIND_SWIPE_ITEM_KEY
@@ -10,7 +13,28 @@ function useSwipeItems() {
10
13
  bindSwipeItems: bindChildren
11
14
  };
12
15
  }
16
+ function useSwipeResizeListeners() {
17
+ const { childProviders, bindChildren } = useChildren(
18
+ SWIPE_RESIZE_DISPATCHER_BIND_SWIPE_RESIZE_LISTENER_KEY
19
+ );
20
+ return {
21
+ swipeResizeListeners: childProviders,
22
+ bindSwipeResizeListeners: bindChildren
23
+ };
24
+ }
25
+ function useSwipeResizeDispatcher() {
26
+ const { parentProvider, bindParent } = useParent(
27
+ SWIPE_RESIZE_DISPATCHER_BIND_SWIPE_RESIZE_LISTENER_KEY
28
+ );
29
+ return {
30
+ swipeResizeDispatcher: parentProvider,
31
+ bindSwipeResizeDispatcher: bindParent
32
+ };
33
+ }
13
34
  export {
14
35
  SWIPE_BIND_SWIPE_ITEM_KEY,
15
- useSwipeItems
36
+ SWIPE_RESIZE_DISPATCHER_BIND_SWIPE_RESIZE_LISTENER_KEY,
37
+ useSwipeItems,
38
+ useSwipeResizeDispatcher,
39
+ useSwipeResizeListeners
16
40
  };
@@ -18,7 +18,7 @@ const props = {
18
18
  closeColor: String,
19
19
  size: [String, Number],
20
20
  variant: Boolean,
21
- rules: Array,
21
+ rules: [Array, Function, Object],
22
22
  ripple: {
23
23
  type: Boolean,
24
24
  default: true
@@ -43,7 +43,11 @@ function __render__(_ctx, _cache) {
43
43
  _createElementVNode(
44
44
  "div",
45
45
  {
46
- style: _normalizeStyle({ background: _ctx.color, width: _ctx.sameWidth ? _ctx.toSizeUnit(Math.ceil(_ctx.hostSize.width)) : void 0 }),
46
+ style: _normalizeStyle({
47
+ background: _ctx.color,
48
+ color: _ctx.textColor,
49
+ width: _ctx.sameWidth ? _ctx.toSizeUnit(Math.ceil(_ctx.hostSize.width)) : void 0
50
+ }),
47
51
  class: _normalizeClass(_ctx.classes(_ctx.n("content-container"), _ctx.n(`--${_ctx.type}`))),
48
52
  role: "tooltip"
49
53
  },
@@ -5,6 +5,7 @@ const props = {
5
5
  default: "default"
6
6
  },
7
7
  color: String,
8
+ textColor: String,
8
9
  content: String,
9
10
  show: Boolean,
10
11
  disabled: Boolean,
@@ -41,7 +41,7 @@ const props = {
41
41
  type: Array,
42
42
  default: () => ["onChange", "onRemove"]
43
43
  },
44
- rules: Array,
44
+ rules: [Array, Function, Object],
45
45
  hideList: Boolean,
46
46
  preventDefaultPreview: Boolean,
47
47
  onClickAction: defineListenerProp(),
@@ -48,7 +48,15 @@ import {
48
48
  Fragment,
49
49
  defineComponent
50
50
  } from "vue";
51
- import { createNamespaceFn, isArray, isPlainObject, isString } from "@varlet/shared";
51
+ import {
52
+ createNamespaceFn,
53
+ hasOwn,
54
+ isArray,
55
+ isFunction,
56
+ isPlainObject,
57
+ isString,
58
+ normalizeToArray
59
+ } from "@varlet/shared";
52
60
  function pickProps(props, propsKey) {
53
61
  return isArray(propsKey) ? propsKey.reduce((pickedProps, key) => {
54
62
  pickedProps[key] = props[key];
@@ -124,17 +132,28 @@ function flatFragment(vNodes) {
124
132
  });
125
133
  return result;
126
134
  }
135
+ function isZodRule(rule) {
136
+ return isPlainObject(rule) && isFunction(rule.safeParseAsync);
137
+ }
138
+ function isZodResult(result) {
139
+ return isPlainObject(result) && hasOwn(result, "success");
140
+ }
127
141
  function useValidation() {
128
142
  const errorMessage = ref("");
129
- const validate = (rules, value, apis) => __async(this, null, function* () {
130
- if (!isArray(rules) || !rules.length) {
131
- return true;
132
- }
133
- const resArr = yield Promise.all(rules.map((rule) => rule(value, apis)));
143
+ const validate = (ruleOrRules, value, apis) => __async(this, null, function* () {
144
+ const rules = normalizeToArray(ruleOrRules).filter((rule) => isZodRule(rule) || isFunction(rule));
145
+ const results = yield Promise.all(
146
+ rules.map((rule) => isZodRule(rule) ? rule.safeParseAsync(value) : rule(value, apis))
147
+ );
134
148
  resetValidation();
135
- return !resArr.some((res) => {
136
- if (res !== true) {
137
- errorMessage.value = String(res);
149
+ return !results.some((result) => {
150
+ if (isZodResult(result)) {
151
+ if (result.success === false) {
152
+ errorMessage.value = result.error.issues[0].message;
153
+ return true;
154
+ }
155
+ } else if (result !== true) {
156
+ errorMessage.value = String(result);
138
157
  return true;
139
158
  }
140
159
  return false;
@@ -208,6 +227,8 @@ export {
208
227
  defineListenerProp,
209
228
  flatFragment,
210
229
  formatElevation,
230
+ isZodResult,
231
+ isZodRule,
211
232
  mount,
212
233
  mountInstance,
213
234
  pickProps,