@volverjs/ui-vue 0.0.9-beta.16 → 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
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
@@ -4491,6 +4485,13 @@ const VvInputTextProps = {
4491
4485
  */
4492
4486
  unit: {
4493
4487
  type: String
4488
+ },
4489
+ /**
4490
+ * Select input text on focus
4491
+ */
4492
+ selectOnFocus: {
4493
+ type: Boolean,
4494
+ default: false
4494
4495
  }
4495
4496
  };
4496
4497
  const VvInputPasswordAction = defineComponent({
@@ -4815,9 +4816,6 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
4815
4816
  VvInputTextProps,
4816
4817
  props
4817
4818
  );
4818
- const inputEl = ref();
4819
- const innerEl = ref();
4820
- __expose({ $inner: innerEl });
4821
4819
  const {
4822
4820
  id,
4823
4821
  icon,
@@ -4827,39 +4825,99 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
4827
4825
  count,
4828
4826
  valid,
4829
4827
  invalid,
4830
- loading
4828
+ loading,
4829
+ debounce,
4830
+ maxlength,
4831
+ minlength,
4832
+ type,
4833
+ iMask,
4834
+ step
4831
4835
  } = toRefs(props);
4832
4836
  const hasId = useUniqueId(id);
4833
4837
  const hasHintId = computed(() => `${hasId.value}-hint`);
4834
4838
  const inputTextPlaceholder = computed(
4835
4839
  () => props.floating && isEmpty(props.placeholder) ? " " : props.placeholder
4836
4840
  );
4837
- const localModelValue = useDebouncedInput(
4838
- modelValue,
4839
- emit,
4840
- 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
+ ),
4841
4848
  {
4842
- getter: (value) => {
4843
- if (mask.value) {
4844
- return mask.value.masked(value ?? "");
4849
+ emit,
4850
+ onAccept: () => {
4851
+ if (!maskReady.value) {
4852
+ return;
4845
4853
  }
4846
- return value;
4847
- },
4848
- setter: (value) => {
4849
- if (mask.value) {
4850
- 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;
4851
4862
  }
4852
- if (props.type === INPUT_TYPES.NUMBER) {
4853
- 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;
4870
+ }
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;
4854
4878
  }
4855
- return value;
4879
+ localModelValue.value = unmasked.value;
4880
+ }
4881
+ }
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;
4856
4895
  }
4857
4896
  }
4858
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
+ );
4859
4912
  const { focused } = useComponentFocus(inputEl, emit);
4860
4913
  const isFocused = computed(
4861
4914
  () => focused.value && !props.disabled && !props.readonly
4862
4915
  );
4916
+ watch(isFocused, (newValue) => {
4917
+ if (newValue && propsDefaults.value.selectOnFocus && inputEl.value) {
4918
+ inputEl.value.select();
4919
+ }
4920
+ });
4863
4921
  const isVisible = useElementVisibility(inputEl);
4864
4922
  watch(isVisible, (newValue) => {
4865
4923
  if (newValue && props.autofocus && !props.disabled && !props.readonly) {
@@ -4877,19 +4935,27 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
4877
4935
  const isNumber = computed(() => props.type === INPUT_TYPES.NUMBER);
4878
4936
  const onStepUp = () => {
4879
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
+ }
4880
4942
  inputEl.value.stepUp();
4881
4943
  localModelValue.value = unref(inputEl).value;
4882
4944
  }
4883
4945
  };
4884
4946
  const onStepDown = () => {
4885
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
+ }
4886
4952
  inputEl.value.stepDown();
4887
4953
  localModelValue.value = unref(inputEl).value;
4888
4954
  }
4889
4955
  };
4890
4956
  const isSearch = computed(() => props.type === INPUT_TYPES.SEARCH);
4891
4957
  const onClear = () => {
4892
- localModelValue.value = void 0;
4958
+ localModelValue.value = "";
4893
4959
  };
4894
4960
  const { hasIcon, hasIconBefore, hasIconAfter } = useComponentIcon(
4895
4961
  icon,
@@ -4911,9 +4977,9 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
4911
4977
  }
4912
4978
  });
4913
4979
  const { formatted: countFormatted } = useTextCount(localModelValue, {
4914
- mode: props.count,
4915
- upperLimit: Number(props.maxlength),
4916
- 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)
4917
4983
  });
4918
4984
  const isClickable = computed(() => !props.disabled && !props.readonly);
4919
4985
  const hasTabindex = computed(
@@ -4948,17 +5014,20 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
4948
5014
  }))
4949
5015
  );
4950
5016
  const hasAttrs = computed(() => {
4951
- const type = (() => {
5017
+ const type2 = (() => {
4952
5018
  if (isPassword.value && showPassword.value) {
4953
5019
  return INPUT_TYPES.TEXT;
4954
5020
  }
4955
5021
  if (isDateTime.value && !isDirty.value && !focused.value) {
4956
5022
  return INPUT_TYPES.TEXT;
4957
5023
  }
5024
+ if (iMask == null ? void 0 : iMask.value) {
5025
+ return INPUT_TYPES.TEXT;
5026
+ }
4958
5027
  return props.type;
4959
5028
  })();
4960
5029
  const toReturn = {
4961
- type,
5030
+ type: type2,
4962
5031
  name: props.name,
4963
5032
  tabindex: hasTabindex.value,
4964
5033
  disabled: props.disabled,
@@ -4969,20 +5038,20 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
4969
5038
  "aria-describedby": hasHintLabelOrSlot.value ? hasHintId.value : void 0,
4970
5039
  "aria-errormessage": hasInvalidLabelOrSlot.value ? hasHintId.value : void 0
4971
5040
  };
4972
- 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) {
4973
5042
  toReturn.step = props.step;
4974
5043
  toReturn.max = props.max !== void 0 ? String(props.max) : void 0;
4975
5044
  toReturn.min = props.min !== void 0 ? String(props.min) : void 0;
4976
5045
  }
4977
- 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) {
4978
5047
  toReturn.placeholder = inputTextPlaceholder.value;
4979
5048
  }
4980
- 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) {
4981
5050
  toReturn.minlength = props.minlength;
4982
5051
  toReturn.maxlength = props.maxlength;
4983
5052
  toReturn.pattern = props.pattern;
4984
5053
  }
4985
- if (type === INPUT_TYPES.EMAIL) {
5054
+ if (type2 === INPUT_TYPES.EMAIL) {
4986
5055
  toReturn.multiple = props.multiple;
4987
5056
  }
4988
5057
  return toReturn;
@@ -5014,31 +5083,6 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
5014
5083
  INPUT_TYPES.SEARCH,
5015
5084
  props
5016
5085
  );
5017
- const mask = ref();
5018
- watch(
5019
- [
5020
- () => props.mask,
5021
- () => props.type,
5022
- () => props.maskEager,
5023
- () => props.maskReversed,
5024
- () => props.maskTokens,
5025
- () => props.maskTokensReplace
5026
- ],
5027
- ([newMask, newType, eager, reversed, tokens, tokensReplace]) => {
5028
- if (newMask && newType === INPUT_TYPES.TEXT) {
5029
- mask.value = new Mask({
5030
- mask: newMask,
5031
- eager,
5032
- reversed,
5033
- tokens,
5034
- tokensReplace
5035
- });
5036
- return;
5037
- }
5038
- mask.value = void 0;
5039
- },
5040
- { immediate: true }
5041
- );
5042
5086
  const onClickInner = () => {
5043
5087
  if (isClickable.value) {
5044
5088
  focused.value = true;
@@ -5052,6 +5096,23 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
5052
5096
  width: localModelValue.value !== void 0 ? `${String(localModelValue.value).length + 1}ch` : void 0
5053
5097
  };
5054
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
+ };
5055
5116
  return (_ctx, _cache) => {
5056
5117
  return openBlock(), createElementBlock("div", {
5057
5118
  class: normalizeClass(unref(bemCssClasses))
@@ -5075,17 +5136,16 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
5075
5136
  key: 0,
5076
5137
  class: "vv-input-text__icon"
5077
5138
  }, unref(hasIcon)), null, 16)) : createCommentVNode("", true),
5078
- withDirectives(createElementVNode("input", mergeProps({
5139
+ createElementVNode("input", mergeProps({
5079
5140
  id: unref(hasId),
5080
5141
  ref_key: "inputEl",
5081
- ref: inputEl,
5082
- "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => isRef(localModelValue) ? localModelValue.value = $event : null)
5142
+ ref: inputEl
5083
5143
  }, unref(hasAttrs), {
5084
5144
  style: unref(hasStyle),
5085
- onKeyup: _cache[1] || (_cache[1] = ($event) => emit("keyup", $event))
5086
- }), null, 16, _hoisted_5$1), [
5087
- [vModelDynamic, unref(localModelValue)]
5088
- ]),
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),
5089
5149
  (_ctx.unit || _ctx.$slots.unit) && unref(isDirty) ? (openBlock(), createElementBlock("div", _hoisted_6$1, [
5090
5150
  renderSlot(_ctx.$slots, "default", normalizeProps(guardReactiveProps(unref(slotProps))), () => [
5091
5151
  createTextVNode(toDisplayString(_ctx.unit), 1)
@@ -5680,14 +5740,17 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
5680
5740
  valid,
5681
5741
  invalid,
5682
5742
  loading,
5683
- modifiers
5743
+ modifiers,
5744
+ debounce,
5745
+ minlength,
5746
+ maxlength
5684
5747
  } = toRefs(props);
5685
5748
  const hasId = useUniqueId(id);
5686
5749
  const hasHintId = computed(() => `${hasId.value}-hint`);
5687
5750
  const hasPlaceholder = computed(
5688
5751
  () => props.floating && isEmpty(props.placeholder) ? " " : props.placeholder
5689
5752
  );
5690
- const localModelValue = useDebouncedInput(modelValue, emit, props.debounce);
5753
+ const localModelValue = useDebouncedInput(modelValue, emit, debounce == null ? void 0 : debounce.value);
5691
5754
  const { hasIcon, hasIconBefore, hasIconAfter } = useComponentIcon(
5692
5755
  icon,
5693
5756
  iconPosition
@@ -5700,9 +5763,9 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
5700
5763
  }
5701
5764
  });
5702
5765
  const { formatted: countFormatted } = useTextCount(localModelValue, {
5703
- mode: props.count,
5704
- upperLimit: Number(props.maxlength),
5705
- 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)
5706
5769
  });
5707
5770
  const isClickable = computed(() => !props.disabled && !props.readonly);
5708
5771
  const hasTabindex = computed(