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

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
4455
+ * iMask options
4456
+ * @see https://imask.js.org/guide.html
4446
4457
  */
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
4462
- */
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,98 @@ 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
+ if (el.value instanceof HTMLInputElement && el.value.type === "date") {
4865
+ localModelValue.value = el.value.value;
4866
+ return;
4867
+ }
4868
+ let date = typed.value;
4869
+ if (!(date instanceof Date)) {
4870
+ date = new Date(date);
4871
+ }
4872
+ localModelValue.value = `${date.getFullYear()}-${("0" + (date.getMonth() + 1)).slice(-2)}-${("0" + date.getDate()).slice(-2)}`;
4873
+ return;
4861
4874
  }
4862
- return value;
4875
+ if (type.value === INPUT_TYPES.DATETIME_LOCAL) {
4876
+ if (el.value instanceof HTMLInputElement && el.value.type === "datetime-local") {
4877
+ localModelValue.value = el.value.value;
4878
+ return;
4879
+ }
4880
+ let date = typed.value;
4881
+ if (!(typed.value instanceof Date)) {
4882
+ date = new Date(date);
4883
+ }
4884
+ 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)}`;
4885
+ return;
4886
+ }
4887
+ localModelValue.value = unmasked.value;
4888
+ }
4889
+ }
4890
+ );
4891
+ onMounted(() => {
4892
+ if (mask.value) {
4893
+ maskReady.value = true;
4894
+ typed.value = localModelValue.value ?? "";
4895
+ }
4896
+ });
4897
+ watch(
4898
+ () => props.modelValue,
4899
+ (newValue) => {
4900
+ var _a;
4901
+ if (mask.value) {
4902
+ typed.value = newValue && ((_a = iMask == null ? void 0 : iMask.value) == null ? void 0 : _a.mask) === Date ? new Date(newValue) : newValue ?? null;
4863
4903
  }
4864
4904
  }
4865
4905
  );
4906
+ watch(
4907
+ () => props.masked,
4908
+ (newValue) => {
4909
+ masked.value = newValue ?? "";
4910
+ }
4911
+ );
4912
+ const inputEl = el;
4913
+ const innerEl = ref();
4914
+ __expose({ $inner: innerEl });
4915
+ const localModelValue = useDebouncedInput(
4916
+ modelValue,
4917
+ emit,
4918
+ (debounce == null ? void 0 : debounce.value) ?? 0
4919
+ );
4866
4920
  const { focused } = useComponentFocus(inputEl, emit);
4867
4921
  const isFocused = computed(
4868
4922
  () => focused.value && !props.disabled && !props.readonly
@@ -4889,19 +4943,27 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
4889
4943
  const isNumber = computed(() => props.type === INPUT_TYPES.NUMBER);
4890
4944
  const onStepUp = () => {
4891
4945
  if (isClickable.value) {
4946
+ if (iMask == null ? void 0 : iMask.value) {
4947
+ typed.value = typed.value + Number((step == null ? void 0 : step.value) ?? 1);
4948
+ return;
4949
+ }
4892
4950
  inputEl.value.stepUp();
4893
4951
  localModelValue.value = unref(inputEl).value;
4894
4952
  }
4895
4953
  };
4896
4954
  const onStepDown = () => {
4897
4955
  if (isClickable.value) {
4956
+ if (iMask == null ? void 0 : iMask.value) {
4957
+ typed.value = typed.value - Number((step == null ? void 0 : step.value) ?? 1);
4958
+ return;
4959
+ }
4898
4960
  inputEl.value.stepDown();
4899
4961
  localModelValue.value = unref(inputEl).value;
4900
4962
  }
4901
4963
  };
4902
4964
  const isSearch = computed(() => props.type === INPUT_TYPES.SEARCH);
4903
4965
  const onClear = () => {
4904
- localModelValue.value = void 0;
4966
+ localModelValue.value = "";
4905
4967
  };
4906
4968
  const { hasIcon, hasIconBefore, hasIconAfter } = useComponentIcon(
4907
4969
  icon,
@@ -4923,9 +4985,9 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
4923
4985
  }
4924
4986
  });
4925
4987
  const { formatted: countFormatted } = useTextCount(localModelValue, {
4926
- mode: props.count,
4927
- upperLimit: Number(props.maxlength),
4928
- lowerLimit: Number(props.minlength)
4988
+ mode: count.value,
4989
+ upperLimit: Number(maxlength == null ? void 0 : maxlength.value),
4990
+ lowerLimit: Number(minlength == null ? void 0 : minlength.value)
4929
4991
  });
4930
4992
  const isClickable = computed(() => !props.disabled && !props.readonly);
4931
4993
  const hasTabindex = computed(
@@ -4960,17 +5022,20 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
4960
5022
  }))
4961
5023
  );
4962
5024
  const hasAttrs = computed(() => {
4963
- const type = (() => {
5025
+ const type2 = (() => {
4964
5026
  if (isPassword.value && showPassword.value) {
4965
5027
  return INPUT_TYPES.TEXT;
4966
5028
  }
4967
5029
  if (isDateTime.value && !isDirty.value && !focused.value) {
4968
5030
  return INPUT_TYPES.TEXT;
4969
5031
  }
5032
+ if (iMask == null ? void 0 : iMask.value) {
5033
+ return INPUT_TYPES.TEXT;
5034
+ }
4970
5035
  return props.type;
4971
5036
  })();
4972
5037
  const toReturn = {
4973
- type,
5038
+ type: type2,
4974
5039
  name: props.name,
4975
5040
  tabindex: hasTabindex.value,
4976
5041
  disabled: props.disabled,
@@ -4981,20 +5046,20 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
4981
5046
  "aria-describedby": hasHintLabelOrSlot.value ? hasHintId.value : void 0,
4982
5047
  "aria-errormessage": hasInvalidLabelOrSlot.value ? hasHintId.value : void 0
4983
5048
  };
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) {
5049
+ 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
5050
  toReturn.step = props.step;
4986
5051
  toReturn.max = props.max !== void 0 ? String(props.max) : void 0;
4987
5052
  toReturn.min = props.min !== void 0 ? String(props.min) : void 0;
4988
5053
  }
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) {
5054
+ 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
5055
  toReturn.placeholder = inputTextPlaceholder.value;
4991
5056
  }
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) {
5057
+ 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
5058
  toReturn.minlength = props.minlength;
4994
5059
  toReturn.maxlength = props.maxlength;
4995
5060
  toReturn.pattern = props.pattern;
4996
5061
  }
4997
- if (type === INPUT_TYPES.EMAIL) {
5062
+ if (type2 === INPUT_TYPES.EMAIL) {
4998
5063
  toReturn.multiple = props.multiple;
4999
5064
  }
5000
5065
  return toReturn;
@@ -5026,31 +5091,6 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
5026
5091
  INPUT_TYPES.SEARCH,
5027
5092
  props
5028
5093
  );
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
5094
  const onClickInner = () => {
5055
5095
  if (isClickable.value) {
5056
5096
  focused.value = true;
@@ -5064,6 +5104,23 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
5064
5104
  width: localModelValue.value !== void 0 ? `${String(localModelValue.value).length + 1}ch` : void 0
5065
5105
  };
5066
5106
  });
5107
+ const onKeyDown = (event) => {
5108
+ switch (event.code) {
5109
+ case "ArrowUp":
5110
+ if (isNumber.value) {
5111
+ onStepUp();
5112
+ event.preventDefault();
5113
+ }
5114
+ break;
5115
+ case "ArrowDown":
5116
+ if (isNumber.value) {
5117
+ onStepDown();
5118
+ event.preventDefault();
5119
+ }
5120
+ break;
5121
+ }
5122
+ emit("keydown", event);
5123
+ };
5067
5124
  return (_ctx, _cache) => {
5068
5125
  return openBlock(), createElementBlock("div", {
5069
5126
  class: normalizeClass(unref(bemCssClasses))
@@ -5087,17 +5144,16 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
5087
5144
  key: 0,
5088
5145
  class: "vv-input-text__icon"
5089
5146
  }, unref(hasIcon)), null, 16)) : createCommentVNode("", true),
5090
- withDirectives(createElementVNode("input", mergeProps({
5147
+ createElementVNode("input", mergeProps({
5091
5148
  id: unref(hasId),
5092
5149
  ref_key: "inputEl",
5093
- ref: inputEl,
5094
- "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => isRef(localModelValue) ? localModelValue.value = $event : null)
5150
+ ref: inputEl
5095
5151
  }, unref(hasAttrs), {
5096
5152
  style: unref(hasStyle),
5097
- onKeyup: _cache[1] || (_cache[1] = ($event) => emit("keyup", $event))
5098
- }), null, 16, _hoisted_5$1), [
5099
- [vModelDynamic, unref(localModelValue)]
5100
- ]),
5153
+ onKeyup: _cache[0] || (_cache[0] = ($event) => emit("keyup", $event)),
5154
+ onKeydown: onKeyDown,
5155
+ onKeypress: _cache[1] || (_cache[1] = ($event) => emit("keypress", $event))
5156
+ }), null, 16, _hoisted_5$1),
5101
5157
  (_ctx.unit || _ctx.$slots.unit) && unref(isDirty) ? (openBlock(), createElementBlock("div", _hoisted_6$1, [
5102
5158
  renderSlot(_ctx.$slots, "default", normalizeProps(guardReactiveProps(unref(slotProps))), () => [
5103
5159
  createTextVNode(toDisplayString(_ctx.unit), 1)
@@ -5692,14 +5748,17 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
5692
5748
  valid,
5693
5749
  invalid,
5694
5750
  loading,
5695
- modifiers
5751
+ modifiers,
5752
+ debounce,
5753
+ minlength,
5754
+ maxlength
5696
5755
  } = toRefs(props);
5697
5756
  const hasId = useUniqueId(id);
5698
5757
  const hasHintId = computed(() => `${hasId.value}-hint`);
5699
5758
  const hasPlaceholder = computed(
5700
5759
  () => props.floating && isEmpty(props.placeholder) ? " " : props.placeholder
5701
5760
  );
5702
- const localModelValue = useDebouncedInput(modelValue, emit, props.debounce);
5761
+ const localModelValue = useDebouncedInput(modelValue, emit, debounce == null ? void 0 : debounce.value);
5703
5762
  const { hasIcon, hasIconBefore, hasIconAfter } = useComponentIcon(
5704
5763
  icon,
5705
5764
  iconPosition
@@ -5712,9 +5771,9 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
5712
5771
  }
5713
5772
  });
5714
5773
  const { formatted: countFormatted } = useTextCount(localModelValue, {
5715
- mode: props.count,
5716
- upperLimit: Number(props.maxlength),
5717
- lowerLimit: Number(props.minlength)
5774
+ mode: count == null ? void 0 : count.value,
5775
+ upperLimit: Number(maxlength == null ? void 0 : maxlength.value),
5776
+ lowerLimit: Number(minlength == null ? void 0 : minlength.value)
5718
5777
  });
5719
5778
  const isClickable = computed(() => !props.disabled && !props.readonly);
5720
5779
  const hasTabindex = computed(