@volverjs/ui-vue 0.0.9-beta.17 → 0.0.9-beta.18

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.
@@ -1,11 +1,11 @@
1
- import { unref, inject, computed, toRef, toRefs, defineComponent, useAttrs, ref, openBlock, createElementBlock, normalizeClass, createElementVNode, withModifiers, renderSlot, normalizeProps, guardReactiveProps, createTextVNode, toDisplayString, isRef, provide, watchEffect, watch, Fragment, renderList, createBlock, mergeProps, withCtx, resolveDynamicComponent, createCommentVNode, useSlots, h, onMounted, withDirectives, vModelCheckbox, createVNode, createSlots, nextTick, Transition, toHandlers, normalizeStyle, vShow, vModelSelect, vModelText, vModelDynamic, vModelRadio } from "vue";
1
+ import { unref, inject, computed, toRef, toRefs, defineComponent, useAttrs, ref, openBlock, createElementBlock, normalizeClass, createElementVNode, withModifiers, renderSlot, normalizeProps, guardReactiveProps, createTextVNode, toDisplayString, isRef, provide, watchEffect, watch, Fragment, renderList, createBlock, mergeProps, withCtx, resolveDynamicComponent, createCommentVNode, useSlots, h, onMounted, withDirectives, vModelCheckbox, createVNode, createSlots, nextTick, Transition, toHandlers, normalizeStyle, vShow, vModelSelect, vModelText, vModelRadio } from "vue";
2
2
  import { nanoid } from "nanoid";
3
3
  import { useToggle, useStorage, useVModel, useMutationObserver, onClickOutside, useFocusWithin, onKeyStroke, useElementHover, useFocus, useElementVisibility, refDebounced, computedAsync } from "@vueuse/core";
4
4
  import { iconExists, Icon, addIcon } from "@iconify/vue";
5
5
  import { get } from "ts-dot-prop";
6
6
  import { autoPlacement, flip, shift, size, offset, arrow, useFloating, autoUpdate } from "@floating-ui/vue";
7
7
  import mitt from "mitt";
8
- import { Mask } from "maska";
8
+ import { useIMask } from "vue-imask";
9
9
  var Side = /* @__PURE__ */ ((Side2) => {
10
10
  Side2["left"] = "left";
11
11
  Side2["right"] = "right";
@@ -3648,7 +3648,7 @@ const _sfc_main$9 = /* @__PURE__ */ defineComponent({
3648
3648
  const searchText = ref("");
3649
3649
  const debouncedSearchText = refDebounced(
3650
3650
  searchText,
3651
- Number(props.debounceSearch)
3651
+ computed(() => Number(props.debounceSearch))
3652
3652
  );
3653
3653
  watch(
3654
3654
  debouncedSearchText,
@@ -3765,12 +3765,15 @@ const _sfc_main$9 = /* @__PURE__ */ defineComponent({
3765
3765
  } else if (props.modelValue) {
3766
3766
  selectedValues = [props.modelValue];
3767
3767
  }
3768
- const options = props.options.reduce((acc, value) => {
3769
- if (isGroup(value)) {
3770
- return [...acc, ...getOptionGrouped(value)];
3771
- }
3772
- return [...acc, value];
3773
- }, []);
3768
+ const options = props.options.reduce(
3769
+ (acc, value) => {
3770
+ if (isGroup(value)) {
3771
+ return [...acc, ...getOptionGrouped(value)];
3772
+ }
3773
+ return [...acc, value];
3774
+ },
3775
+ []
3776
+ );
3774
3777
  return options.filter((option) => {
3775
3778
  if (isGroup(option)) {
3776
3779
  return getOptionGrouped(option).some(
@@ -4326,7 +4329,23 @@ const TYPES_ICON = {
4326
4329
  COLOR: "color",
4327
4330
  SEARCH: "close"
4328
4331
  };
4329
- const VvInputTextEvents = ["update:modelValue", "focus", "blur", "keyup"];
4332
+ const VvInputTextEvents = [
4333
+ "update:modelValue",
4334
+ "update:masked",
4335
+ "accept",
4336
+ "accept:typed",
4337
+ "accept:masked",
4338
+ "accept:unmasked",
4339
+ "complete",
4340
+ "complete:typed",
4341
+ "complete:masked",
4342
+ "complete:unmasked",
4343
+ "focus",
4344
+ "blur",
4345
+ "keyup",
4346
+ "keydown",
4347
+ "keypress"
4348
+ ];
4330
4349
  const VvInputTextProps = {
4331
4350
  ...InputTextareaProps,
4332
4351
  /**
@@ -4433,44 +4452,19 @@ const VvInputTextProps = {
4433
4452
  default: "Clear"
4434
4453
  },
4435
4454
  /**
4436
- * Input mask, only for text type
4437
- * @see https://beholdr.github.io/maska/
4438
- */
4439
- mask: {
4440
- type: String,
4441
- default: void 0
4442
- },
4443
- /**
4444
- * Show mask before typing
4445
- * @see https://beholdr.github.io/maska/#/?id=maskinput-options
4446
- */
4447
- maskEager: {
4448
- type: Boolean,
4449
- default: false
4450
- },
4451
- /**
4452
- * Write values reverse (ex. for numbers)
4453
- * @see https://beholdr.github.io/maska/#/?id=maskinput-options
4454
- */
4455
- maskReversed: {
4456
- type: Boolean,
4457
- default: false
4458
- },
4459
- /**
4460
- * Add mask custom tokens
4461
- * @see https://beholdr.github.io/maska/#/?id=custom-tokens
4455
+ * iMask options
4456
+ * @see https://imask.js.org/guide.html
4462
4457
  */
4463
- maskTokens: {
4458
+ iMask: {
4464
4459
  type: Object,
4465
4460
  default: void 0
4466
4461
  },
4467
4462
  /**
4468
- * Replace default tokens
4469
- * @see https://beholdr.github.io/maska/#/?id=custom-tokens
4463
+ * Masked value
4470
4464
  */
4471
- maskTokensReplace: {
4472
- type: Boolean,
4473
- default: false
4465
+ masked: {
4466
+ type: String,
4467
+ default: void 0
4474
4468
  },
4475
4469
  /**
4476
4470
  * Adjust input width to content
@@ -4822,9 +4816,6 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
4822
4816
  VvInputTextProps,
4823
4817
  props
4824
4818
  );
4825
- const inputEl = ref();
4826
- const innerEl = ref();
4827
- __expose({ $inner: innerEl });
4828
4819
  const {
4829
4820
  id,
4830
4821
  icon,
@@ -4834,35 +4825,90 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
4834
4825
  count,
4835
4826
  valid,
4836
4827
  invalid,
4837
- loading
4828
+ loading,
4829
+ debounce,
4830
+ maxlength,
4831
+ minlength,
4832
+ type,
4833
+ iMask,
4834
+ step
4838
4835
  } = toRefs(props);
4839
4836
  const hasId = useUniqueId(id);
4840
4837
  const hasHintId = computed(() => `${hasId.value}-hint`);
4841
4838
  const inputTextPlaceholder = computed(
4842
4839
  () => props.floating && isEmpty(props.placeholder) ? " " : props.placeholder
4843
4840
  );
4844
- const localModelValue = useDebouncedInput(
4845
- modelValue,
4846
- emit,
4847
- props.debounce,
4841
+ const maskReady = ref(false);
4842
+ const { el, mask, typed, masked, unmasked } = useIMask(
4843
+ computed(
4844
+ () => (iMask == null ? void 0 : iMask.value) ?? {
4845
+ mask: /./
4846
+ }
4847
+ ),
4848
4848
  {
4849
- getter: (value) => {
4850
- if (mask.value) {
4851
- return mask.value.masked(value ?? "");
4849
+ emit,
4850
+ onAccept: () => {
4851
+ if (!maskReady.value) {
4852
+ return;
4852
4853
  }
4853
- return value;
4854
- },
4855
- setter: (value) => {
4856
- if (mask.value) {
4857
- value = mask.value.unmasked(value);
4854
+ emit("update:masked", masked.value);
4855
+ if (type.value === INPUT_TYPES.NUMBER) {
4856
+ if (typeof typed.value !== "number") {
4857
+ localModelValue.value = Number(typed.value);
4858
+ return;
4859
+ }
4860
+ localModelValue.value = typed.value;
4861
+ return;
4858
4862
  }
4859
- if (props.type === INPUT_TYPES.NUMBER) {
4860
- return Number(value);
4863
+ if (type.value === INPUT_TYPES.DATE) {
4864
+ let date = typed.value;
4865
+ if (!(date instanceof Date)) {
4866
+ date = new Date(date);
4867
+ }
4868
+ localModelValue.value = `${date.getFullYear()}-${("0" + (date.getMonth() + 1)).slice(-2)}-${("0" + date.getDate()).slice(-2)}`;
4869
+ return;
4861
4870
  }
4862
- return value;
4871
+ if (type.value === INPUT_TYPES.DATETIME_LOCAL) {
4872
+ let date = typed.value;
4873
+ if (!(typed.value instanceof Date)) {
4874
+ date = new Date(date);
4875
+ }
4876
+ localModelValue.value = `${date.getFullYear()}-${("0" + (date.getMonth() + 1)).slice(-2)}-${("0" + date.getDate()).slice(-2)}T${("0" + date.getHours()).slice(-2)}:${("0" + date.getMinutes()).slice(-2)}`;
4877
+ return;
4878
+ }
4879
+ localModelValue.value = unmasked.value;
4863
4880
  }
4864
4881
  }
4865
4882
  );
4883
+ onMounted(() => {
4884
+ if (mask.value) {
4885
+ maskReady.value = true;
4886
+ typed.value = localModelValue.value ?? "";
4887
+ }
4888
+ });
4889
+ watch(
4890
+ () => props.modelValue,
4891
+ (newValue) => {
4892
+ var _a;
4893
+ if (mask.value) {
4894
+ typed.value = newValue && ((_a = iMask == null ? void 0 : iMask.value) == null ? void 0 : _a.mask) === Date ? new Date(newValue) : newValue ?? null;
4895
+ }
4896
+ }
4897
+ );
4898
+ watch(
4899
+ () => props.masked,
4900
+ (newValue) => {
4901
+ masked.value = newValue ?? "";
4902
+ }
4903
+ );
4904
+ const inputEl = el;
4905
+ const innerEl = ref();
4906
+ __expose({ $inner: innerEl });
4907
+ const localModelValue = useDebouncedInput(
4908
+ modelValue,
4909
+ emit,
4910
+ (debounce == null ? void 0 : debounce.value) ?? 0
4911
+ );
4866
4912
  const { focused } = useComponentFocus(inputEl, emit);
4867
4913
  const isFocused = computed(
4868
4914
  () => focused.value && !props.disabled && !props.readonly
@@ -4889,19 +4935,27 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
4889
4935
  const isNumber = computed(() => props.type === INPUT_TYPES.NUMBER);
4890
4936
  const onStepUp = () => {
4891
4937
  if (isClickable.value) {
4938
+ if (iMask == null ? void 0 : iMask.value) {
4939
+ typed.value = typed.value + Number((step == null ? void 0 : step.value) ?? 1);
4940
+ return;
4941
+ }
4892
4942
  inputEl.value.stepUp();
4893
4943
  localModelValue.value = unref(inputEl).value;
4894
4944
  }
4895
4945
  };
4896
4946
  const onStepDown = () => {
4897
4947
  if (isClickable.value) {
4948
+ if (iMask == null ? void 0 : iMask.value) {
4949
+ typed.value = typed.value - Number((step == null ? void 0 : step.value) ?? 1);
4950
+ return;
4951
+ }
4898
4952
  inputEl.value.stepDown();
4899
4953
  localModelValue.value = unref(inputEl).value;
4900
4954
  }
4901
4955
  };
4902
4956
  const isSearch = computed(() => props.type === INPUT_TYPES.SEARCH);
4903
4957
  const onClear = () => {
4904
- localModelValue.value = void 0;
4958
+ localModelValue.value = "";
4905
4959
  };
4906
4960
  const { hasIcon, hasIconBefore, hasIconAfter } = useComponentIcon(
4907
4961
  icon,
@@ -4923,9 +4977,9 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
4923
4977
  }
4924
4978
  });
4925
4979
  const { formatted: countFormatted } = useTextCount(localModelValue, {
4926
- mode: props.count,
4927
- upperLimit: Number(props.maxlength),
4928
- lowerLimit: Number(props.minlength)
4980
+ mode: count.value,
4981
+ upperLimit: Number(maxlength == null ? void 0 : maxlength.value),
4982
+ lowerLimit: Number(minlength == null ? void 0 : minlength.value)
4929
4983
  });
4930
4984
  const isClickable = computed(() => !props.disabled && !props.readonly);
4931
4985
  const hasTabindex = computed(
@@ -4960,17 +5014,20 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
4960
5014
  }))
4961
5015
  );
4962
5016
  const hasAttrs = computed(() => {
4963
- const type = (() => {
5017
+ const type2 = (() => {
4964
5018
  if (isPassword.value && showPassword.value) {
4965
5019
  return INPUT_TYPES.TEXT;
4966
5020
  }
4967
5021
  if (isDateTime.value && !isDirty.value && !focused.value) {
4968
5022
  return INPUT_TYPES.TEXT;
4969
5023
  }
5024
+ if (iMask == null ? void 0 : iMask.value) {
5025
+ return INPUT_TYPES.TEXT;
5026
+ }
4970
5027
  return props.type;
4971
5028
  })();
4972
5029
  const toReturn = {
4973
- type,
5030
+ type: type2,
4974
5031
  name: props.name,
4975
5032
  tabindex: hasTabindex.value,
4976
5033
  disabled: props.disabled,
@@ -4981,20 +5038,20 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
4981
5038
  "aria-describedby": hasHintLabelOrSlot.value ? hasHintId.value : void 0,
4982
5039
  "aria-errormessage": hasInvalidLabelOrSlot.value ? hasHintId.value : void 0
4983
5040
  };
4984
- if (type === INPUT_TYPES.DATE || type === INPUT_TYPES.MONTH || type === INPUT_TYPES.WEEK || type === INPUT_TYPES.TIME || type === INPUT_TYPES.DATETIME_LOCAL || type === INPUT_TYPES.NUMBER) {
5041
+ if (type2 === INPUT_TYPES.DATE || type2 === INPUT_TYPES.MONTH || type2 === INPUT_TYPES.WEEK || type2 === INPUT_TYPES.TIME || type2 === INPUT_TYPES.DATETIME_LOCAL || type2 === INPUT_TYPES.NUMBER) {
4985
5042
  toReturn.step = props.step;
4986
5043
  toReturn.max = props.max !== void 0 ? String(props.max) : void 0;
4987
5044
  toReturn.min = props.min !== void 0 ? String(props.min) : void 0;
4988
5045
  }
4989
- if (type === INPUT_TYPES.TEXT || type === INPUT_TYPES.SEARCH || type === INPUT_TYPES.URL || type === INPUT_TYPES.TEL || type === INPUT_TYPES.EMAIL || type === INPUT_TYPES.PASSWORD || type === INPUT_TYPES.NUMBER) {
5046
+ if (type2 === INPUT_TYPES.TEXT || type2 === INPUT_TYPES.SEARCH || type2 === INPUT_TYPES.URL || type2 === INPUT_TYPES.TEL || type2 === INPUT_TYPES.EMAIL || type2 === INPUT_TYPES.PASSWORD || type2 === INPUT_TYPES.NUMBER) {
4990
5047
  toReturn.placeholder = inputTextPlaceholder.value;
4991
5048
  }
4992
- if (type === INPUT_TYPES.TEXT || type === INPUT_TYPES.SEARCH || type === INPUT_TYPES.URL || type === INPUT_TYPES.TEL || type === INPUT_TYPES.EMAIL || type === INPUT_TYPES.PASSWORD) {
5049
+ if (type2 === INPUT_TYPES.TEXT || type2 === INPUT_TYPES.SEARCH || type2 === INPUT_TYPES.URL || type2 === INPUT_TYPES.TEL || type2 === INPUT_TYPES.EMAIL || type2 === INPUT_TYPES.PASSWORD) {
4993
5050
  toReturn.minlength = props.minlength;
4994
5051
  toReturn.maxlength = props.maxlength;
4995
5052
  toReturn.pattern = props.pattern;
4996
5053
  }
4997
- if (type === INPUT_TYPES.EMAIL) {
5054
+ if (type2 === INPUT_TYPES.EMAIL) {
4998
5055
  toReturn.multiple = props.multiple;
4999
5056
  }
5000
5057
  return toReturn;
@@ -5026,31 +5083,6 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
5026
5083
  INPUT_TYPES.SEARCH,
5027
5084
  props
5028
5085
  );
5029
- const mask = ref();
5030
- watch(
5031
- [
5032
- () => props.mask,
5033
- () => props.type,
5034
- () => props.maskEager,
5035
- () => props.maskReversed,
5036
- () => props.maskTokens,
5037
- () => props.maskTokensReplace
5038
- ],
5039
- ([newMask, newType, eager, reversed, tokens, tokensReplace]) => {
5040
- if (newMask && newType === INPUT_TYPES.TEXT) {
5041
- mask.value = new Mask({
5042
- mask: newMask,
5043
- eager,
5044
- reversed,
5045
- tokens,
5046
- tokensReplace
5047
- });
5048
- return;
5049
- }
5050
- mask.value = void 0;
5051
- },
5052
- { immediate: true }
5053
- );
5054
5086
  const onClickInner = () => {
5055
5087
  if (isClickable.value) {
5056
5088
  focused.value = true;
@@ -5064,6 +5096,23 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
5064
5096
  width: localModelValue.value !== void 0 ? `${String(localModelValue.value).length + 1}ch` : void 0
5065
5097
  };
5066
5098
  });
5099
+ const onKeyDown = (event) => {
5100
+ switch (event.code) {
5101
+ case "ArrowUp":
5102
+ if (isNumber.value) {
5103
+ onStepUp();
5104
+ event.preventDefault();
5105
+ }
5106
+ break;
5107
+ case "ArrowDown":
5108
+ if (isNumber.value) {
5109
+ onStepDown();
5110
+ event.preventDefault();
5111
+ }
5112
+ break;
5113
+ }
5114
+ emit("keydown", event);
5115
+ };
5067
5116
  return (_ctx, _cache) => {
5068
5117
  return openBlock(), createElementBlock("div", {
5069
5118
  class: normalizeClass(unref(bemCssClasses))
@@ -5087,17 +5136,16 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
5087
5136
  key: 0,
5088
5137
  class: "vv-input-text__icon"
5089
5138
  }, unref(hasIcon)), null, 16)) : createCommentVNode("", true),
5090
- withDirectives(createElementVNode("input", mergeProps({
5139
+ createElementVNode("input", mergeProps({
5091
5140
  id: unref(hasId),
5092
5141
  ref_key: "inputEl",
5093
- ref: inputEl,
5094
- "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => isRef(localModelValue) ? localModelValue.value = $event : null)
5142
+ ref: inputEl
5095
5143
  }, unref(hasAttrs), {
5096
5144
  style: unref(hasStyle),
5097
- onKeyup: _cache[1] || (_cache[1] = ($event) => emit("keyup", $event))
5098
- }), null, 16, _hoisted_5$1), [
5099
- [vModelDynamic, unref(localModelValue)]
5100
- ]),
5145
+ onKeyup: _cache[0] || (_cache[0] = ($event) => emit("keyup", $event)),
5146
+ onKeydown: onKeyDown,
5147
+ onKeypress: _cache[1] || (_cache[1] = ($event) => emit("keypress", $event))
5148
+ }), null, 16, _hoisted_5$1),
5101
5149
  (_ctx.unit || _ctx.$slots.unit) && unref(isDirty) ? (openBlock(), createElementBlock("div", _hoisted_6$1, [
5102
5150
  renderSlot(_ctx.$slots, "default", normalizeProps(guardReactiveProps(unref(slotProps))), () => [
5103
5151
  createTextVNode(toDisplayString(_ctx.unit), 1)
@@ -5692,14 +5740,17 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
5692
5740
  valid,
5693
5741
  invalid,
5694
5742
  loading,
5695
- modifiers
5743
+ modifiers,
5744
+ debounce,
5745
+ minlength,
5746
+ maxlength
5696
5747
  } = toRefs(props);
5697
5748
  const hasId = useUniqueId(id);
5698
5749
  const hasHintId = computed(() => `${hasId.value}-hint`);
5699
5750
  const hasPlaceholder = computed(
5700
5751
  () => props.floating && isEmpty(props.placeholder) ? " " : props.placeholder
5701
5752
  );
5702
- const localModelValue = useDebouncedInput(modelValue, emit, props.debounce);
5753
+ const localModelValue = useDebouncedInput(modelValue, emit, debounce == null ? void 0 : debounce.value);
5703
5754
  const { hasIcon, hasIconBefore, hasIconAfter } = useComponentIcon(
5704
5755
  icon,
5705
5756
  iconPosition
@@ -5712,9 +5763,9 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
5712
5763
  }
5713
5764
  });
5714
5765
  const { formatted: countFormatted } = useTextCount(localModelValue, {
5715
- mode: props.count,
5716
- upperLimit: Number(props.maxlength),
5717
- lowerLimit: Number(props.minlength)
5766
+ mode: count == null ? void 0 : count.value,
5767
+ upperLimit: Number(maxlength == null ? void 0 : maxlength.value),
5768
+ lowerLimit: Number(minlength == null ? void 0 : minlength.value)
5718
5769
  });
5719
5770
  const isClickable = computed(() => !props.disabled && !props.readonly);
5720
5771
  const hasTabindex = computed(