@varlet/ui 2.8.3 → 2.8.4-alpha.1677149602351

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/lib/varlet.cjs.js CHANGED
@@ -13,6 +13,7 @@ const isBoolean = (val) => typeof val === "boolean";
13
13
  const isNumber = (val) => typeof val === "number";
14
14
  const isPlainObject = (val) => Object.prototype.toString.call(val) === "[object Object]";
15
15
  const isObject = (val) => typeof val === "object" && val !== null;
16
+ const isFunction = (val) => typeof val === "function";
16
17
  const isArray = (val) => Array.isArray(val);
17
18
  const isURL = (val) => {
18
19
  if (!val) {
@@ -65,6 +66,7 @@ const throttle = (method, mustRunDelay = 200) => {
65
66
  };
66
67
  const inBrowser = () => typeof window !== "undefined";
67
68
  const uniq = (arr) => [...new Set(arr)];
69
+ const camelize = (s) => s.replace(/-(\w)/g, (_, p) => p.toUpperCase());
68
70
  const kebabCase = (s) => {
69
71
  const ret = s.replace(/([A-Z])/g, " $1").trim();
70
72
  return ret.split(" ").join("-").toLowerCase();
@@ -801,7 +803,7 @@ function forbidRippleTask() {
801
803
  _ripple.tasker && window.clearTimeout(_ripple.tasker);
802
804
  _ripple.tasker = null;
803
805
  }
804
- function mounted$1(el, binding) {
806
+ function mounted$2(el, binding) {
805
807
  var _binding$value, _binding$value$touchm, _binding$value2;
806
808
  el._ripple = _extends$l({
807
809
  tasker: null
@@ -825,14 +827,14 @@ function mounted$1(el, binding) {
825
827
  passive: true
826
828
  });
827
829
  }
828
- function unmounted(el) {
830
+ function unmounted$1(el) {
829
831
  el.removeEventListener("touchstart", createRipple);
830
832
  el.removeEventListener("touchmove", forbidRippleTask);
831
833
  el.removeEventListener("dragstart", removeRipple);
832
834
  document.removeEventListener("touchend", el._ripple.removeRipple);
833
835
  document.removeEventListener("touchcancel", el._ripple.removeRipple);
834
836
  }
835
- function updated$1(el, binding) {
837
+ function updated$2(el, binding) {
836
838
  var _binding$value$touchm2, _binding$value3, _binding$value4, _binding$value5, _el$_ripple, _el$_ripple2, _el$_ripple3;
837
839
  var newBinding = {
838
840
  touchmoveForbid: (_binding$value$touchm2 = (_binding$value3 = binding.value) == null ? void 0 : _binding$value3.touchmoveForbid) != null ? _binding$value$touchm2 : Context.touchmoveForbid,
@@ -849,9 +851,9 @@ function updated$1(el, binding) {
849
851
  }
850
852
  }
851
853
  var Ripple = {
852
- mounted: mounted$1,
853
- unmounted,
854
- updated: updated$1,
854
+ mounted: mounted$2,
855
+ unmounted: unmounted$1,
856
+ updated: updated$2,
855
857
  install(app) {
856
858
  app.directive("ripple", this);
857
859
  }
@@ -2135,7 +2137,7 @@ function diff(el, binding) {
2135
2137
  } = el._lazy;
2136
2138
  return src !== binding.value || arg !== binding.arg;
2137
2139
  }
2138
- function mounted(_x3, _x4) {
2140
+ function mounted$1(_x3, _x4) {
2139
2141
  return _mounted.apply(this, arguments);
2140
2142
  }
2141
2143
  function _mounted() {
@@ -2145,7 +2147,7 @@ function _mounted() {
2145
2147
  });
2146
2148
  return _mounted.apply(this, arguments);
2147
2149
  }
2148
- function updated(_x5, _x6) {
2150
+ function updated$1(_x5, _x6) {
2149
2151
  return _updated.apply(this, arguments);
2150
2152
  }
2151
2153
  function _updated() {
@@ -2154,7 +2156,7 @@ function _updated() {
2154
2156
  lazyElements.includes(el) && (yield check(el));
2155
2157
  return;
2156
2158
  }
2157
- yield mounted(el, binding);
2159
+ yield mounted$1(el, binding);
2158
2160
  });
2159
2161
  return _updated.apply(this, arguments);
2160
2162
  }
@@ -2178,9 +2180,9 @@ function mergeLazyOptions(lazyOptions) {
2178
2180
  defaultLazyOptions.filter = filter;
2179
2181
  }
2180
2182
  var Lazy = {
2181
- mounted,
2183
+ mounted: mounted$1,
2182
2184
  unmounted: clear,
2183
- updated,
2185
+ updated: updated$1,
2184
2186
  install(app, lazyOptions) {
2185
2187
  mergeLazyOptions(lazyOptions);
2186
2188
  checkAllWithThrottle = throttle(checkAll, defaultLazyOptions.throttleWait);
@@ -13208,6 +13210,128 @@ Form.install = function(app) {
13208
13210
  Form.useValidation = useValidation;
13209
13211
  Form.useForm = useForm;
13210
13212
  var _FormComponent = Form;
13213
+ function shouldDisabled(arg) {
13214
+ if (!arg) {
13215
+ return false;
13216
+ }
13217
+ var isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
13218
+ if (arg === "desktop" && isMobile) {
13219
+ return true;
13220
+ }
13221
+ if (arg === "mobile" && !isMobile) {
13222
+ return true;
13223
+ }
13224
+ return false;
13225
+ }
13226
+ function getStyle(element) {
13227
+ var style = element.getAttribute("style");
13228
+ if (!style)
13229
+ return {};
13230
+ return style.split(";").filter(Boolean).reduce((style2, item) => {
13231
+ var [key, value] = item.split(":").map((item2) => item2.trim());
13232
+ style2[camelize(key)] = value;
13233
+ return style2;
13234
+ }, {});
13235
+ }
13236
+ function updateRawStyle(element) {
13237
+ var {
13238
+ value
13239
+ } = element._hover;
13240
+ var style = getStyle(element);
13241
+ Object.keys(value).forEach((key) => {
13242
+ var camelizedKey = camelize(key);
13243
+ var styleValue = value[camelizedKey];
13244
+ if (styleValue != null && style[camelizedKey]) {
13245
+ element._hover.rawStyle[camelizedKey] = style[camelizedKey];
13246
+ }
13247
+ });
13248
+ }
13249
+ function updateStyle(element, styleValue) {
13250
+ Object.keys(styleValue).forEach((key) => {
13251
+ var value = styleValue[key];
13252
+ if (value != null) {
13253
+ element.style[key] = value;
13254
+ }
13255
+ });
13256
+ }
13257
+ function clearStyle(element) {
13258
+ Object.keys(element._hover.value).forEach((key) => {
13259
+ element.style[key] = "";
13260
+ });
13261
+ }
13262
+ function restoreStyle(element) {
13263
+ clearStyle(element);
13264
+ updateStyle(element, element._hover.rawStyle);
13265
+ element._hover.rawStyle = {};
13266
+ }
13267
+ function createHover() {
13268
+ var {
13269
+ value
13270
+ } = this._hover;
13271
+ this._hover.hovering = true;
13272
+ if (isFunction(value)) {
13273
+ value(this._hover.hovering);
13274
+ return;
13275
+ }
13276
+ updateStyle(this, value);
13277
+ }
13278
+ function removeHover() {
13279
+ this._hover.hovering = false;
13280
+ if (isFunction(this._hover.value)) {
13281
+ this._hover.value(this._hover.hovering);
13282
+ return;
13283
+ }
13284
+ restoreStyle(this);
13285
+ }
13286
+ function mounted(element, binding) {
13287
+ var _element$_hover$hover, _element$_hover;
13288
+ var {
13289
+ arg,
13290
+ value
13291
+ } = binding;
13292
+ if (shouldDisabled(arg)) {
13293
+ return;
13294
+ }
13295
+ element._hover = {
13296
+ value,
13297
+ hovering: (_element$_hover$hover = (_element$_hover = element._hover) == null ? void 0 : _element$_hover.hovering) != null ? _element$_hover$hover : false,
13298
+ rawStyle: {}
13299
+ };
13300
+ updateRawStyle(element);
13301
+ element.addEventListener("mouseenter", createHover);
13302
+ element.addEventListener("mouseleave", removeHover);
13303
+ }
13304
+ function unmounted(element, binding) {
13305
+ if (shouldDisabled(binding.arg)) {
13306
+ return;
13307
+ }
13308
+ restoreStyle(element);
13309
+ element.removeEventListener("mouseenter", createHover);
13310
+ element.removeEventListener("mouseleave", removeHover);
13311
+ }
13312
+ function beforeUpdate(element, binding) {
13313
+ unmounted(element, binding);
13314
+ }
13315
+ function shouldUpdateStyle(element, binding) {
13316
+ return !isFunction(binding.value) && element._hover.hovering;
13317
+ }
13318
+ function updated(element, binding) {
13319
+ mounted(element, binding);
13320
+ if (shouldUpdateStyle(element, binding)) {
13321
+ updateStyle(element, binding.value);
13322
+ }
13323
+ }
13324
+ var Hover = {
13325
+ mounted,
13326
+ unmounted,
13327
+ beforeUpdate,
13328
+ updated,
13329
+ install(app) {
13330
+ app.directive("hover", this);
13331
+ }
13332
+ };
13333
+ var _HoverComponent = Hover;
13334
+ const Hover$1 = Hover;
13211
13335
  function fitValidator(fit) {
13212
13336
  return ["fill", "contain", "cover", "none", "scale-down"].includes(fit);
13213
13337
  }
@@ -15260,6 +15384,12 @@ var __sfc__$B = vue.defineComponent({
15260
15384
  var id = vue.ref("var-input-" + vue.getCurrentInstance().uid);
15261
15385
  var el = vue.ref(null);
15262
15386
  var isFocus = vue.ref(false);
15387
+ var type = vue.computed(() => {
15388
+ if (props2.type === "number") {
15389
+ return "text";
15390
+ }
15391
+ return props2.type;
15392
+ });
15263
15393
  var maxlengthText = vue.computed(() => {
15264
15394
  var {
15265
15395
  maxlength,
@@ -15321,6 +15451,9 @@ var __sfc__$B = vue.defineComponent({
15321
15451
  var {
15322
15452
  value
15323
15453
  } = target;
15454
+ if (props2.type === "number") {
15455
+ value = formatNumber(value);
15456
+ }
15324
15457
  value = withMaxlength(withTrim(value));
15325
15458
  target.value = value;
15326
15459
  call(props2["onUpdate:modelValue"], value);
@@ -15332,6 +15465,10 @@ var __sfc__$B = vue.defineComponent({
15332
15465
  var {
15333
15466
  value
15334
15467
  } = target;
15468
+ if (props2.type === "number") {
15469
+ value = toNumber(value).toString();
15470
+ call(props2["onUpdate:modelValue"], value);
15471
+ }
15335
15472
  value = withMaxlength(withTrim(value));
15336
15473
  target.value = value;
15337
15474
  call(props2.onChange, value, e);
@@ -15362,6 +15499,17 @@ var __sfc__$B = vue.defineComponent({
15362
15499
  call(onClick, e);
15363
15500
  validateWithTrigger("onClick");
15364
15501
  };
15502
+ var formatNumber = (value) => {
15503
+ var minusIndex = value.indexOf("-");
15504
+ var dotIndex = value.indexOf(".");
15505
+ if (minusIndex > -1) {
15506
+ value = minusIndex === 0 ? "-" + value.replace(/-/g, "") : value.replace(/-/g, "");
15507
+ }
15508
+ if (dotIndex > -1) {
15509
+ value = value.slice(0, dotIndex + 1) + value.slice(dotIndex).replace(/\./g, "");
15510
+ }
15511
+ return value.replace(/[^-0-9.]/g, "");
15512
+ };
15365
15513
  var withTrim = (value) => props2.modelModifiers.trim ? value.trim() : value;
15366
15514
  var withMaxlength = (value) => props2.maxlength ? value.slice(0, toNumber(props2.maxlength)) : value;
15367
15515
  var handleTouchstart = (e) => {
@@ -15402,6 +15550,7 @@ var __sfc__$B = vue.defineComponent({
15402
15550
  id,
15403
15551
  isFocus,
15404
15552
  errorMessage,
15553
+ type,
15405
15554
  maxlengthText,
15406
15555
  formDisabled: form == null ? void 0 : form.disabled,
15407
15556
  formReadonly: form == null ? void 0 : form.readonly,
@@ -18522,7 +18671,7 @@ var __sfc__$p = vue.defineComponent({
18522
18671
  validate: v,
18523
18672
  resetValidation
18524
18673
  } = useValidation();
18525
- var getStyle = (val) => {
18674
+ var getStyle2 = (val) => {
18526
18675
  var {
18527
18676
  count,
18528
18677
  gap
@@ -18615,7 +18764,7 @@ var __sfc__$p = vue.defineComponent({
18615
18764
  errorMessage,
18616
18765
  formDisabled: form == null ? void 0 : form.disabled,
18617
18766
  formReadonly: form == null ? void 0 : form.readonly,
18618
- getStyle,
18767
+ getStyle: getStyle2,
18619
18768
  getClass,
18620
18769
  getCurrentState,
18621
18770
  handleClick,
@@ -22929,7 +23078,7 @@ var __sfc__$2 = vue.defineComponent({
22929
23078
  }
22930
23079
  return isDisableMinSec(time, true);
22931
23080
  };
22932
- var getStyle = (index, hour, inner2) => {
23081
+ var getStyle2 = (index, hour, inner2) => {
22933
23082
  var rad = 2 * Math.PI / 12 * index - Math.PI / 2;
22934
23083
  var left2 = 50 * (1 + Math.cos(rad));
22935
23084
  var top2 = 50 * (1 + Math.sin(rad));
@@ -23067,7 +23216,7 @@ var __sfc__$2 = vue.defineComponent({
23067
23216
  isActive,
23068
23217
  isDisable,
23069
23218
  getSize,
23070
- getStyle,
23219
+ getStyle: getStyle2,
23071
23220
  activeItemIndex
23072
23221
  };
23073
23222
  }
@@ -24209,7 +24358,7 @@ const TimePickerSfc = "";
24209
24358
  const TooltipSfc = "";
24210
24359
  const uploader = "";
24211
24360
  const UploaderSfc = "";
24212
- const version = "2.8.3";
24361
+ const version = "2.8.4-alpha.1677149602351";
24213
24362
  function install(app) {
24214
24363
  ActionSheet.install && app.use(ActionSheet);
24215
24364
  AppBar.install && app.use(AppBar);
@@ -24240,6 +24389,7 @@ function install(app) {
24240
24389
  Ellipsis.install && app.use(Ellipsis);
24241
24390
  Form.install && app.use(Form);
24242
24391
  FormDetails.install && app.use(FormDetails);
24392
+ Hover$1.install && app.use(Hover$1);
24243
24393
  Icon.install && app.use(Icon);
24244
24394
  Image$1.install && app.use(Image$1);
24245
24395
  ImagePreview.install && app.use(ImagePreview);
@@ -24321,6 +24471,7 @@ const index_bundle = {
24321
24471
  Ellipsis,
24322
24472
  Form,
24323
24473
  FormDetails,
24474
+ Hover: Hover$1,
24324
24475
  Icon,
24325
24476
  Image: Image$1,
24326
24477
  ImagePreview,
@@ -24399,6 +24550,7 @@ exports.Divider = Divider;
24399
24550
  exports.Ellipsis = Ellipsis;
24400
24551
  exports.Form = Form;
24401
24552
  exports.FormDetails = FormDetails;
24553
+ exports.Hover = Hover$1;
24402
24554
  exports.Icon = Icon;
24403
24555
  exports.Image = Image$1;
24404
24556
  exports.ImagePreview = ImagePreview;
@@ -24478,6 +24630,7 @@ exports._DividerComponent = _DividerComponent;
24478
24630
  exports._EllipsisComponent = _EllipsisComponent;
24479
24631
  exports._FormComponent = _FormComponent;
24480
24632
  exports._FormDetailsComponent = _FormDetailsComponent;
24633
+ exports._HoverComponent = _HoverComponent;
24481
24634
  exports._IconComponent = _IconComponent;
24482
24635
  exports._ImageComponent = _ImageComponent;
24483
24636
  exports._ImagePreviewComponent = _ImagePreviewComponent;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@varlet/ui",
3
- "version": "2.8.3",
3
+ "version": "2.8.4-alpha.1677149602351",
4
4
  "description": "A material like components library",
5
5
  "main": "lib/varlet.cjs.js",
6
6
  "module": "es/index.mjs",
@@ -46,8 +46,8 @@
46
46
  "@popperjs/core": "^2.11.6",
47
47
  "dayjs": "^1.10.4",
48
48
  "decimal.js": "^10.2.1",
49
- "@varlet/shared": "2.8.3",
50
- "@varlet/icons": "2.8.3"
49
+ "@varlet/icons": "2.8.4-alpha.1677149602351",
50
+ "@varlet/shared": "2.8.4-alpha.1677149602351"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@types/jest": "^26.0.15",
@@ -62,8 +62,8 @@
62
62
  "typescript": "^4.4.4",
63
63
  "vue": "3.2.25",
64
64
  "vue-router": "4.0.12",
65
- "@varlet/cli": "2.8.3",
66
- "@varlet/touch-emulator": "2.8.3"
65
+ "@varlet/cli": "2.8.4-alpha.1677149602351",
66
+ "@varlet/touch-emulator": "2.8.4-alpha.1677149602351"
67
67
  },
68
68
  "browserslist": [
69
69
  "Chrome >= 54",
@@ -0,0 +1,8 @@
1
+ import { VarDirective } from './varDirective'
2
+ import { StyleValue } from 'vue'
3
+
4
+ export type HoverValue = StyleValue | ((hovering: boolean) => void)
5
+
6
+ export class Hover extends VarDirective<HoverValue> {}
7
+
8
+ export class _HoverComponent extends Hover {}
package/types/index.d.ts CHANGED
@@ -31,6 +31,7 @@ export * from './divider'
31
31
  export * from './ellipsis'
32
32
  export * from './form'
33
33
  export * from './formDetails'
34
+ export * from './hover'
34
35
  export * from './icon'
35
36
  export * from './image'
36
37
  export * from './imagePreview'
@@ -112,6 +113,7 @@ declare module 'vue' {
112
113
  VarEllipsis: typeof import('@varlet/ui')['_EllipsisComponent']
113
114
  VarForm: typeof import('@varlet/ui')['_FormComponent']
114
115
  VarFormDetails: typeof import('@varlet/ui')['_FormDetailsComponent']
116
+ VarHover: typeof import('@varlet/ui')['_HoverComponent']
115
117
  VarIcon: typeof import('@varlet/ui')['_IconComponent']
116
118
  VarImage: typeof import('@varlet/ui')['_ImageComponent']
117
119
  VarImagePreview: typeof import('@varlet/ui')['_ImagePreviewComponent']
package/types/lazy.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { VarDirective } from './varDirective'
2
2
 
3
- export class Lazy extends VarDirective {}
3
+ export class Lazy extends VarDirective<string> {}
4
4
 
5
5
  export class _LazyComponent extends Lazy {}
package/types/ripple.d.ts CHANGED
@@ -1,5 +1,10 @@
1
1
  import { VarDirective } from './varDirective'
2
2
 
3
- export class Ripple extends VarDirective {}
3
+ export interface RippleValue {
4
+ color?: string
5
+ disabled?: boolean
6
+ }
7
+
8
+ export class Ripple extends VarDirective<RippleValue> {}
4
9
 
5
10
  export class _RippleComponent extends Ripple {}
@@ -1,12 +1,12 @@
1
1
  import type { App } from 'vue'
2
2
  import { DirectiveBinding } from 'vue'
3
3
 
4
- export class VarDirective {
4
+ export class VarDirective<V> {
5
5
  static install(app: App): void
6
6
 
7
- static mounted(el: HTMLElement, binding: DirectiveBinding): void
7
+ static mounted(el: HTMLElement, binding: DirectiveBinding<V>): void
8
8
 
9
- static updated(el: HTMLElement, binding: DirectiveBinding): void
9
+ static updated(el: HTMLElement, binding: DirectiveBinding<V>): void
10
10
 
11
- static unmounted(el: HTMLElement, binding: DirectiveBinding): void
11
+ static unmounted(el: HTMLElement, binding: DirectiveBinding<V>): void
12
12
  }