@varlet/ui 3.4.0 → 3.5.0-alpha.1726249557629

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.
@@ -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
  };
@@ -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(),
@@ -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.1726249557629'
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.1726249557629'
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(),
@@ -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,