@volverjs/ui-vue 0.0.10-beta.40 → 0.0.10-beta.41

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.
Files changed (35) hide show
  1. package/dist/components/VvCheckboxGroup/VvCheckboxGroup.es.js +12 -3
  2. package/dist/components/VvCheckboxGroup/VvCheckboxGroup.umd.js +1 -1
  3. package/dist/components/VvCombobox/VvCombobox.es.js +183 -125
  4. package/dist/components/VvCombobox/VvCombobox.umd.js +1 -1
  5. package/dist/components/VvCombobox/VvCombobox.vue.d.ts +6 -0
  6. package/dist/components/VvCombobox/index.d.ts +54 -22
  7. package/dist/components/VvRadioGroup/VvRadioGroup.es.js +12 -3
  8. package/dist/components/VvRadioGroup/VvRadioGroup.umd.js +1 -1
  9. package/dist/components/VvSelect/VvSelect.es.js +79 -46
  10. package/dist/components/VvSelect/VvSelect.umd.js +1 -1
  11. package/dist/components/VvSelect/VvSelect.vue.d.ts +3 -0
  12. package/dist/components/VvSelect/index.d.ts +14 -0
  13. package/dist/components/index.es.js +183 -122
  14. package/dist/components/index.umd.js +1 -1
  15. package/dist/icons.es.js +3 -3
  16. package/dist/icons.umd.js +1 -1
  17. package/dist/stories/Combobox/Combobox.stories.d.ts +1 -0
  18. package/dist/stories/Combobox/ComboboxMultiple.stories.d.ts +1 -0
  19. package/dist/stories/Select/Select.stories.d.ts +1 -0
  20. package/package.json +18 -18
  21. package/src/assets/icons/detailed.json +1 -1
  22. package/src/assets/icons/normal.json +1 -1
  23. package/src/assets/icons/simple.json +1 -1
  24. package/src/components/VvCombobox/VvCombobox.vue +105 -97
  25. package/src/components/VvCombobox/index.ts +19 -2
  26. package/src/components/VvSelect/VvSelect.vue +66 -46
  27. package/src/components/VvSelect/index.ts +8 -1
  28. package/src/composables/useOptions.ts +12 -11
  29. package/src/stories/Combobox/Combobox.settings.ts +18 -3
  30. package/src/stories/Combobox/Combobox.stories.ts +8 -0
  31. package/src/stories/Combobox/Combobox.test.ts +6 -4
  32. package/src/stories/Combobox/ComboboxMultiple.stories.ts +9 -0
  33. package/src/stories/Combobox/ComboboxOptions.stories.ts +9 -13
  34. package/src/stories/Select/Select.stories.ts +8 -0
  35. package/src/stories/Select/Select.test.ts +5 -3
@@ -1,7 +1,7 @@
1
1
  import { inject, computed, unref, defineComponent, mergeDefaults, ref, toRefs, openBlock, createBlock, mergeProps, createCommentVNode, isRef, h, watch, useSlots, createElementBlock, normalizeClass, toDisplayString, createElementVNode, renderSlot, normalizeProps, guardReactiveProps, withDirectives, Fragment, renderList, vModelSelect, createVNode, createSlots, withCtx } from "vue";
2
2
  import { iconExists, Icon, addIcon } from "@iconify/vue";
3
- import { uid } from "uid";
4
3
  import { useFocus, useElementVisibility } from "@vueuse/core";
4
+ import { uid } from "uid";
5
5
  import { get } from "ts-dot-prop";
6
6
  const VvIconPropsDefaults = {
7
7
  prefix: "normal"
@@ -193,9 +193,6 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
193
193
  };
194
194
  }
195
195
  });
196
- function isEmpty(value) {
197
- return ((value2) => value2 === null || value2 === void 0 || value2 === "" || Array.isArray(value2) && value2.length === 0 || !(value2 instanceof Date) && typeof value2 === "object" && Object.keys(value2).length === 0)(unref(value));
198
- }
199
196
  function isString(value) {
200
197
  return typeof value === "string" || value instanceof String;
201
198
  }
@@ -715,6 +712,13 @@ const VvSelectProps = {
715
712
  type: [String, Number, Boolean, Object, Array],
716
713
  default: void 0
717
714
  },
715
+ /**
716
+ * Select first option automatically
717
+ */
718
+ autoselectFirst: {
719
+ type: Boolean,
720
+ default: false
721
+ },
718
722
  /**
719
723
  * Select placeholder
720
724
  */
@@ -783,9 +787,6 @@ function useDefaults(componentName, propsDefinition, props) {
783
787
  }, {});
784
788
  });
785
789
  }
786
- function useUniqueId(id) {
787
- return computed(() => String((id == null ? void 0 : id.value) || uid()));
788
- }
789
790
  function useComponentFocus(inputTemplateRef, emit) {
790
791
  const { focused } = useFocus(inputTemplateRef);
791
792
  watch(focused, (newValue) => {
@@ -795,6 +796,9 @@ function useComponentFocus(inputTemplateRef, emit) {
795
796
  focused
796
797
  };
797
798
  }
799
+ function useUniqueId(id) {
800
+ return computed(() => String((id == null ? void 0 : id.value) || uid()));
801
+ }
798
802
  function useComponentIcon(icon, iconPosition) {
799
803
  const hasIcon = computed(() => {
800
804
  if (typeof (icon == null ? void 0 : icon.value) === "string") {
@@ -836,21 +840,30 @@ function useOptions(props) {
836
840
  if (typeof option === "string") {
837
841
  return option;
838
842
  }
843
+ if (typeof labelKey.value === "function") {
844
+ return labelKey.value(option);
845
+ }
839
846
  return String(
840
- typeof labelKey.value === "function" ? labelKey.value(option) : get(option, labelKey.value)
847
+ labelKey.value ? get(option, labelKey.value) : option
841
848
  );
842
849
  };
843
850
  const getOptionValue = (option) => {
844
851
  if (typeof option === "string") {
845
852
  return option;
846
853
  }
847
- return typeof valueKey.value === "function" ? valueKey.value(option) : get(option, valueKey.value);
854
+ if (typeof valueKey.value === "function") {
855
+ return valueKey.value(option);
856
+ }
857
+ return valueKey.value ? get(option, valueKey.value) : option;
848
858
  };
849
859
  const isOptionDisabled = (option) => {
850
860
  if (typeof option === "string") {
851
861
  return false;
852
862
  }
853
- return typeof disabledKey.value === "function" ? disabledKey.value(option) : get(option, disabledKey.value);
863
+ if (typeof disabledKey.value === "function") {
864
+ return disabledKey.value(option);
865
+ }
866
+ return disabledKey.value ? get(option, disabledKey.value) : false;
854
867
  };
855
868
  const getOptionGrouped = (option) => {
856
869
  if (typeof option == "string") {
@@ -902,13 +915,21 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
902
915
  VvSelectProps2,
903
916
  props
904
917
  );
905
- const select = ref();
918
+ const selectEl = ref();
906
919
  const {
907
920
  HintSlot,
908
921
  hasHintLabelOrSlot,
909
922
  hasInvalidLabelOrSlot,
910
923
  hintSlotScope
911
924
  } = HintSlotFactory(propsDefaults, slots);
925
+ const { focused } = useComponentFocus(selectEl, emit);
926
+ function isGroup(option) {
927
+ var _a;
928
+ if (typeof option === "string") {
929
+ return false;
930
+ }
931
+ return (_a = option.options) == null ? void 0 : _a.length;
932
+ }
912
933
  const {
913
934
  id,
914
935
  modifiers,
@@ -924,19 +945,38 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
924
945
  } = toRefs(props);
925
946
  const hasId = useUniqueId(id);
926
947
  const hasHintId = computed(() => `${hasId.value}-hint`);
927
- const { focused } = useComponentFocus(select, emit);
928
- const isVisible = useElementVisibility(select);
948
+ const isDisabledOrReadonly = computed(() => props.disabled || props.readonly);
949
+ const hasTabindex = computed(() => {
950
+ return isDisabledOrReadonly.value ? -1 : props.tabindex;
951
+ });
952
+ const localModelValue = computed({
953
+ get: () => {
954
+ return props.modelValue;
955
+ },
956
+ set: (newValue) => {
957
+ if (Array.isArray(newValue)) {
958
+ newValue = newValue.filter((item) => item !== void 0);
959
+ if (newValue.length === 0 && !props.unselectable) {
960
+ selectEl.value.value = props.modelValue;
961
+ return;
962
+ }
963
+ }
964
+ emit("update:modelValue", newValue);
965
+ }
966
+ });
967
+ const isDirty = computed(() => {
968
+ if (Array.isArray(localModelValue.value)) {
969
+ return localModelValue.value.length > 0;
970
+ }
971
+ return localModelValue.value !== void 0 && localModelValue.value !== null;
972
+ });
973
+ const isVisible = useElementVisibility(selectEl);
929
974
  watch(isVisible, (newValue) => {
930
975
  if (newValue && props.autofocus) {
931
976
  focused.value = true;
932
977
  }
933
978
  });
934
979
  const { hasIconBefore, hasIconAfter } = useComponentIcon(icon, iconPosition);
935
- const isDirty = computed(() => !isEmpty(props.modelValue));
936
- const isDisabled = computed(() => props.disabled || props.readonly);
937
- const hasTabindex = computed(() => {
938
- return isDisabled.value ? -1 : props.tabindex;
939
- });
940
980
  const isInvalid = computed(() => {
941
981
  if (props.invalid === true) {
942
982
  return true;
@@ -963,11 +1003,27 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
963
1003
  "multiple": multiple.value
964
1004
  }))
965
1005
  );
1006
+ const {
1007
+ getOptionLabel,
1008
+ getOptionValue,
1009
+ isOptionDisabled,
1010
+ getOptionGrouped
1011
+ } = useOptions(props);
1012
+ watch(
1013
+ () => props.options,
1014
+ (newValue) => {
1015
+ if ((newValue == null ? void 0 : newValue.length) && props.autoselectFirst && !isDirty.value) {
1016
+ const firstOptionValue = getOptionValue(newValue[0]);
1017
+ localModelValue.value = props.multiple ? [firstOptionValue] : firstOptionValue;
1018
+ }
1019
+ },
1020
+ { immediate: true }
1021
+ );
966
1022
  const hasAttrs = computed(() => {
967
1023
  return {
968
1024
  "name": props.name,
969
1025
  "tabindex": hasTabindex.value,
970
- "disabled": isDisabled.value,
1026
+ "disabled": isDisabledOrReadonly.value,
971
1027
  "required": props.required,
972
1028
  "size": props.size,
973
1029
  "autocomplete": props.autocomplete,
@@ -982,30 +1038,6 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
982
1038
  invalid: props.invalid,
983
1039
  modelValue: props.modelValue
984
1040
  }));
985
- const {
986
- getOptionLabel,
987
- getOptionValue,
988
- isOptionDisabled,
989
- getOptionGrouped
990
- } = useOptions(props);
991
- const localModelValue = computed({
992
- get: () => {
993
- return props.modelValue;
994
- },
995
- set: (newValue) => {
996
- if (Array.isArray(newValue)) {
997
- newValue = newValue.filter((item) => item !== void 0);
998
- }
999
- emit("update:modelValue", newValue);
1000
- }
1001
- });
1002
- function isGroup(option) {
1003
- var _a;
1004
- if (typeof option === "string") {
1005
- return false;
1006
- }
1007
- return (_a = option.options) == null ? void 0 : _a.length;
1008
- }
1009
1041
  return (_ctx, _cache) => {
1010
1042
  return openBlock(), createElementBlock(
1011
1043
  "div",
@@ -1031,10 +1063,11 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
1031
1063
  )) : createCommentVNode("v-if", true),
1032
1064
  withDirectives(createElementVNode("select", mergeProps({
1033
1065
  id: unref(hasId),
1034
- ref_key: "select",
1035
- ref: select,
1066
+ ref_key: "selectEl",
1067
+ ref: selectEl
1068
+ }, unref(hasAttrs), {
1036
1069
  "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => isRef(localModelValue) ? localModelValue.value = $event : null)
1037
- }, unref(hasAttrs)), [
1070
+ }), [
1038
1071
  _ctx.placeholder ? (openBlock(), createElementBlock("option", {
1039
1072
  key: 0,
1040
1073
  value: void 0,
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("vue"),require("@iconify/vue"),require("uid"),require("@vueuse/core"),require("ts-dot-prop")):"function"==typeof define&&define.amd?define(["vue","@iconify/vue","uid","@vueuse/core","ts-dot-prop"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).VvSelect=t(e.vue,e.vue$1,e.uid,e.core,e.tsDotProp)}(this,(function(e,t,l,o,n){"use strict";const a={prefix:"normal"};var i=(e=>(e.local="local",e.session="session",e))(i||{}),r=(e=>(e.left="left",e.right="right",e.top="top",e.bottom="bottom",e))(r||{}),u=(e=>(e.before="before",e.after="after",e))(u||{}),d=(e=>(e.button="button",e.submit="submit",e.reset="reset",e))(d||{}),s=(e=>(e.nuxtLink="nuxt-link",e.routerLink="router-link",e.a="a",e.button="button",e))(s||{});const c=Symbol.for("volver");function v(){return e.inject(c)}function f(t,l,o){return e.computed((()=>{const n={[t]:!0},a="string"==typeof(null==l?void 0:l.value)?l.value.split(" "):null==l?void 0:l.value;return a&&Array.isArray(a)&&a.forEach((e=>{e&&(n[`${t}--${e}`]=!0)})),o&&Object.keys(o.value).forEach((l=>{n[`${t}--${l}`]=e.unref(o.value[l])})),n}))}const p=e.defineComponent({name:"VvIcon",props:e.mergeDefaults({name:{},color:{},width:{},height:{},provider:{},prefix:{},src:{},horizontalFlip:{type:Boolean},verticalFlip:{type:Boolean},flip:{},mode:{},inline:{type:Boolean},rotate:{},onLoad:{type:Function},svg:{},modifiers:{}},a),setup(l){const o=l,n=e.computed((()=>"string"==typeof o.rotate?Number.parseFloat(o.rotate):o.rotate)),a=e.ref(!0),i=v(),{modifiers:r}=e.toRefs(o),u=f("vv-icon",r),d=e.computed((()=>o.provider||(null==i?void 0:i.iconsProvider))),s=e.computed((()=>{const e=o.name??"",l=`@${d.value}:${o.prefix}:${e}`;if(t.iconExists(l))return l;const n=null==i?void 0:i.iconsCollections.find((l=>{const o=`@${d.value}:${l.prefix}:${e}`;return t.iconExists(o)}));return n?`@${d.value}:${n.prefix}:${e}`:e}));function c(e){const l=function(e){let t;if("undefined"==typeof window){const{JSDOM:e}=require("jsdom");t=(new e).window}return(t?new t.DOMParser:new window.DOMParser).parseFromString(e,"text/html").querySelector("svg")}(e),n=(null==l?void 0:l.innerHTML.trim())||"";l&&n&&t.addIcon(`@${d.value}:${o.prefix}:${o.name}`,{body:n,height:l.viewBox.baseVal.height,width:l.viewBox.baseVal.width})}return i&&o.src&&!t.iconExists(`@${d.value}:${o.prefix}:${o.name}`)&&(a.value=!1,i.fetchIcon(o.src).then((e=>{e&&(c(e),a.value=!0)})).catch((e=>{throw new Error(`Error during fetch icon: ${null==e?void 0:e.message}`)}))),o.svg&&c(o.svg),(l,o)=>e.unref(a)?(e.openBlock(),e.createBlock(e.unref(t.Icon),e.mergeProps({key:0,class:e.unref(u)},{inline:l.inline,width:l.width,height:l.height,horizontalFlip:l.horizontalFlip,verticalFlip:l.verticalFlip,flip:l.flip,rotate:e.unref(n),color:l.color,onLoad:l.onLoad,icon:e.unref(s)}),null,16,["class"])):e.createCommentVNode("v-if",!0)}});function m(e){return Array.isArray(e)?e.filter((e=>{return"string"==typeof(t=e)||t instanceof String;var t})).join(" "):e}const b={valid:{type:Boolean,default:!1},validLabel:{type:[String,Array],default:void 0}},g={invalid:{type:Boolean,default:!1},invalidLabel:{type:[String,Array],default:void 0}},h={loading:{type:Boolean,default:!1},loadingLabel:{type:String,default:"Loading..."}},y={disabled:{type:Boolean,default:!1}},S=(Boolean,Boolean,Boolean,{label:{type:[String,Number],default:void 0}}),B={readonly:{type:Boolean,default:!1}},k={modifiers:{type:[String,Array],default:void 0}},L={hintLabel:{type:String,default:""}},$={options:{type:Array,default:()=>[]},labelKey:{type:[String,Function],default:"label"},valueKey:{type:[String,Function],default:"value"},disabledKey:{type:[String,Function],default:"disabled"}},V={icon:{type:[String,Object],default:void 0},iconPosition:{type:String,default:u.before,validation:e=>Object.values(u).includes(e)}},O={tabindex:{type:[String,Number],default:0}},w={floating:{type:Boolean,default:!1}},x={unselectable:{type:Boolean,default:!0}},E={id:[String,Number]};r.bottom,Boolean,Boolean,Boolean,Boolean,Boolean,Boolean,Boolean,Boolean;const P={...E,name:{type:String,required:!0}},N={autofocus:{type:Boolean,default:!1}},A={autocomplete:{type:String,default:"off"}};d.button,s.button,i.local;const I={...P,...N,...A,...O,...b,...g,...L,...h,...y,...B,...k,...$,...V,...w,...x,...S,multiple:Boolean,required:Boolean,size:[String,Number],modelValue:{type:[String,Number,Boolean,Object,Array],default:void 0},placeholder:String};function _(){return{...I,options:{...I.options,type:Array,default:()=>[]}}}const C=["for"],F={class:"vv-select__wrapper"},j={key:0,class:"vv-select__input-before"},z={class:"vv-select__inner"},D=["id"],R=["disabled","hidden"],q=["disabled","value"],H=["disabled","label"],K=["disabled","value"],M={key:1,class:"vv-select__input-after"};return e.defineComponent({name:"VvSelect",props:_(),emits:["update:modelValue","focus","blur"],setup(t,{emit:a}){const i=t,d=a,s=e.useSlots(),c=function(t,l,o){const n=v(),a=e.computed((()=>{var e;if(n&&(null==(e=n.defaults.value)?void 0:e[t]))return n.defaults.value[t]}));return e.computed((()=>{if(void 0===a.value)return o;const e=a.value,t=l,n=o;return Object.keys(t).reduce(((l,o)=>{const a=n[o];if(l[o]=a,o in e){if(Array.isArray(t[o])){const n=t[o];n.length&&n[0]===a&&(l[o]=e[o])}if("function"==typeof t[o]&&(0,t[o])()===a&&(l[o]=e[o]),"object"==typeof t[o]){let n=t[o].default;"function"==typeof n&&(n=n()),"object"==typeof n?JSON.stringify(n)===JSON.stringify(a)&&(l[o]=e[o]):n===a&&(l[o]=e[o])}}return l}),{})}))}("VvSelect",_(),i),b=e.ref(),{HintSlot:g,hasHintLabelOrSlot:h,hasInvalidLabelOrSlot:y,hintSlotScope:S}=function(t,l){const o=e.computed((()=>e.isRef(t)?t.value:t)),n=e.computed((()=>m(o.value.invalidLabel))),a=e.computed((()=>m(o.value.validLabel))),i=e.computed((()=>o.value.loadingLabel)),r=e.computed((()=>o.value.hintLabel)),u=e.computed((()=>Boolean(o.value.loading&&(l.loading||i.value)))),d=e.computed((()=>!u.value&&Boolean(o.value.invalid&&(l.invalid||n.value)))),s=e.computed((()=>!u.value&&!d.value&&Boolean(o.value.valid&&(l.valid||a.value)))),c=e.computed((()=>!u.value&&!d.value&&!s.value&&Boolean(l.hint||r.value))),v=e.computed((()=>d.value||s.value||u.value||c.value)),f=e.computed((()=>({modelValue:o.value.modelValue,valid:o.value.valid,invalid:o.value.invalid,loading:o.value.loading}))),p=e.defineComponent({name:"HintSlot",props:{tag:{type:String,default:"small"}},setup:()=>({isVisible:v,invalidLabel:n,validLabel:a,loadingLabel:i,hintLabel:r,hasInvalidLabelOrSlot:d,hasValidLabelOrSlot:s,hasLoadingLabelOrSlot:u,hasHintLabelOrSlot:c}),render(){var t,l,o,n,a,i,r,u;if(this.isVisible){let d;return this.hasInvalidLabelOrSlot&&(d="alert"),this.hasValidLabelOrSlot&&(d="status"),this.hasLoadingLabelOrSlot?e.h(this.tag,{role:d},(null==(l=(t=this.$slots).loading)?void 0:l.call(t))??this.loadingLabel):this.hasInvalidLabelOrSlot?e.h(this.tag,{role:d},(null==(n=(o=this.$slots).invalid)?void 0:n.call(o))??this.$slots.invalid??this.invalidLabel):this.hasValidLabelOrSlot?e.h(this.tag,{role:d},(null==(i=(a=this.$slots).valid)?void 0:i.call(a))??this.validLabel):e.h(this.tag,{role:d},(null==(u=(r=this.$slots).hint)?void 0:u.call(r))??this.$slots.hint??this.hintLabel)}return null}});return{hasInvalidLabelOrSlot:d,hasHintLabelOrSlot:c,hasValidLabelOrSlot:s,hasLoadingLabelOrSlot:u,hintSlotScope:f,HintSlot:p}}(c,s),{id:B,modifiers:k,disabled:L,readonly:$,loading:V,icon:O,iconPosition:w,invalid:x,valid:E,floating:P,multiple:N}=e.toRefs(i),A=function(t){return e.computed((()=>String((null==t?void 0:t.value)||l.uid())))}(B),I=e.computed((()=>`${A.value}-hint`)),{focused:T}=function(t,l){const{focused:n}=o.useFocus(t);return e.watch(n,(o=>{l(o?"focus":"blur",e.unref(t))})),{focused:n}}(b,d),J=o.useElementVisibility(b);e.watch(J,(e=>{e&&i.autofocus&&(T.value=!0)}));const{hasIconBefore:G,hasIconAfter:U}=function(t,l){const o=e.computed((()=>"string"==typeof(null==t?void 0:t.value)?{name:null==t?void 0:t.value}:null==t?void 0:t.value)),n=e.computed((()=>(null==l?void 0:l.value)===u.before?o.value:void 0)),a=e.computed((()=>(null==l?void 0:l.value)===u.after?o.value:void 0)),i=e.computed((()=>(null==l?void 0:l.value)===r.left?o.value:void 0)),d=e.computed((()=>(null==l?void 0:l.value)===r.right?o.value:void 0)),s=e.computed((()=>(null==l?void 0:l.value)===r.top?o.value:void 0)),c=e.computed((()=>(null==l?void 0:l.value)===r.bottom?o.value:void 0));return{hasIcon:o,hasIconLeft:i,hasIconRight:d,hasIconTop:s,hasIconBottom:c,hasIconBefore:n,hasIconAfter:a}}(O,w),Q=e.computed((()=>{return t=i.modelValue,!(null==(l=e.unref(t))||""===l||Array.isArray(l)&&0===l.length||!(l instanceof Date)&&"object"==typeof l&&0===Object.keys(l).length);var t,l})),W=e.computed((()=>i.disabled||i.readonly)),X=e.computed((()=>W.value?-1:i.tabindex)),Y=e.computed((()=>!0===i.invalid||!0!==i.valid&&void 0)),Z=f("vv-select",k,e.computed((()=>({valid:E.value,invalid:x.value,loading:V.value,disabled:L.value,readonly:$.value,"icon-before":void 0!==G.value,"icon-after":void 0!==U.value,dirty:Q.value,focus:T.value,floating:P.value,multiple:N.value})))),ee=e.computed((()=>({name:i.name,tabindex:X.value,disabled:W.value,required:i.required,size:i.size,autocomplete:i.autocomplete,multiple:i.multiple,"aria-invalid":Y.value,"aria-describedby":h.value?I.value:void 0,"aria-errormessage":y.value?I.value:void 0}))),te=e.computed((()=>({valid:i.valid,invalid:i.invalid,modelValue:i.modelValue}))),{getOptionLabel:le,getOptionValue:oe,isOptionDisabled:ne,getOptionGrouped:ae}=function(t){const{options:l,labelKey:o,valueKey:a,disabledKey:i}=e.toRefs(t);return{options:l,getOptionLabel:e=>"string"==typeof e?e:String("function"==typeof o.value?o.value(e):n.get(e,o.value)),getOptionValue:e=>"string"==typeof e?e:"function"==typeof a.value?a.value(e):n.get(e,a.value),isOptionDisabled:e=>"string"!=typeof e&&("function"==typeof i.value?i.value(e):n.get(e,i.value)),getOptionGrouped:e=>"string"==typeof e?[]:"object"==typeof e&&e&&"options"in e?e.options:[]}}(i),ie=e.computed({get:()=>i.modelValue,set:e=>{Array.isArray(e)&&(e=e.filter((e=>void 0!==e))),d("update:modelValue",e)}});function re(e){var t;return"string"!=typeof e&&(null==(t=e.options)?void 0:t.length)}return(t,l)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(e.unref(Z))},[t.label?(e.openBlock(),e.createElementBlock("label",{key:0,for:e.unref(A)},e.toDisplayString(t.label),9,C)):e.createCommentVNode("v-if",!0),e.createElementVNode("div",F,[t.$slots.before?(e.openBlock(),e.createElementBlock("div",j,[e.renderSlot(t.$slots,"before",e.normalizeProps(e.guardReactiveProps(e.unref(te))))])):e.createCommentVNode("v-if",!0),e.createElementVNode("div",z,[e.unref(G)?(e.openBlock(),e.createBlock(p,e.mergeProps({key:0},e.unref(G),{class:"vv-select__icon"}),null,16)):e.createCommentVNode("v-if",!0),e.withDirectives(e.createElementVNode("select",e.mergeProps({id:e.unref(A),ref_key:"select",ref:b,"onUpdate:modelValue":l[0]||(l[0]=t=>e.isRef(ie)?ie.value=t:null)},e.unref(ee)),[t.placeholder?(e.openBlock(),e.createElementBlock("option",{key:0,value:void 0,disabled:!t.unselectable,hidden:!t.unselectable},e.toDisplayString(t.placeholder),9,R)):e.createCommentVNode("v-if",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.options,((t,l)=>(e.openBlock(),e.createElementBlock(e.Fragment,null,[re(t)?(e.openBlock(),e.createElementBlock("optgroup",{key:`group-${l}`,disabled:e.unref(ne)(t),label:e.unref(le)(t)},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(ae)(t),((t,o)=>(e.openBlock(),e.createElementBlock("option",{key:`group-${l}-item-${o}`,disabled:e.unref(ne)(t),value:e.unref(oe)(t)},e.toDisplayString(e.unref(le)(t)),9,K)))),128))],8,H)):(e.openBlock(),e.createElementBlock("option",{key:l,disabled:e.unref(ne)(t),value:e.unref(oe)(t)},e.toDisplayString(e.unref(le)(t)),9,q))],64)))),256))],16,D),[[e.vModelSelect,e.unref(ie)]]),e.unref(U)?(e.openBlock(),e.createBlock(p,e.mergeProps({key:1},e.unref(U),{class:"vv-select__icon vv-select__icon-after"}),null,16)):e.createCommentVNode("v-if",!0)]),t.$slots.after?(e.openBlock(),e.createElementBlock("div",M,[e.renderSlot(t.$slots,"after",e.normalizeProps(e.guardReactiveProps(e.unref(te))))])):e.createCommentVNode("v-if",!0)]),e.createVNode(e.unref(g),{id:e.unref(I),class:"vv-select__hint"},e.createSlots({_:2},[t.$slots.hint?{name:"hint",fn:e.withCtx((()=>[e.renderSlot(t.$slots,"hint",e.normalizeProps(e.guardReactiveProps(e.unref(S))))])),key:"0"}:void 0,t.$slots.loading?{name:"loading",fn:e.withCtx((()=>[e.renderSlot(t.$slots,"loading",e.normalizeProps(e.guardReactiveProps(e.unref(S))))])),key:"1"}:void 0,t.$slots.valid?{name:"valid",fn:e.withCtx((()=>[e.renderSlot(t.$slots,"valid",e.normalizeProps(e.guardReactiveProps(e.unref(S))))])),key:"2"}:void 0,t.$slots.invalid?{name:"invalid",fn:e.withCtx((()=>[e.renderSlot(t.$slots,"invalid",e.normalizeProps(e.guardReactiveProps(e.unref(S))))])),key:"3"}:void 0]),1032,["id"])],2))}})}));
1
+ !function(e,l){"object"==typeof exports&&"undefined"!=typeof module?module.exports=l(require("vue"),require("@iconify/vue"),require("@vueuse/core"),require("uid"),require("ts-dot-prop")):"function"==typeof define&&define.amd?define(["vue","@iconify/vue","@vueuse/core","uid","ts-dot-prop"],l):(e="undefined"!=typeof globalThis?globalThis:e||self).VvSelect=l(e.vue,e.vue$1,e.core,e.uid,e.tsDotProp)}(this,(function(e,l,t,o,a){"use strict";const n={prefix:"normal"};var i=(e=>(e.local="local",e.session="session",e))(i||{}),r=(e=>(e.left="left",e.right="right",e.top="top",e.bottom="bottom",e))(r||{}),u=(e=>(e.before="before",e.after="after",e))(u||{}),d=(e=>(e.button="button",e.submit="submit",e.reset="reset",e))(d||{}),s=(e=>(e.nuxtLink="nuxt-link",e.routerLink="router-link",e.a="a",e.button="button",e))(s||{});const c=Symbol.for("volver");function v(){return e.inject(c)}function p(l,t,o){return e.computed((()=>{const a={[l]:!0},n="string"==typeof(null==t?void 0:t.value)?t.value.split(" "):null==t?void 0:t.value;return n&&Array.isArray(n)&&n.forEach((e=>{e&&(a[`${l}--${e}`]=!0)})),o&&Object.keys(o.value).forEach((t=>{a[`${l}--${t}`]=e.unref(o.value[t])})),a}))}const f=e.defineComponent({name:"VvIcon",props:e.mergeDefaults({name:{},color:{},width:{},height:{},provider:{},prefix:{},src:{},horizontalFlip:{type:Boolean},verticalFlip:{type:Boolean},flip:{},mode:{},inline:{type:Boolean},rotate:{},onLoad:{type:Function},svg:{},modifiers:{}},n),setup(t){const o=t,a=e.computed((()=>"string"==typeof o.rotate?Number.parseFloat(o.rotate):o.rotate)),n=e.ref(!0),i=v(),{modifiers:r}=e.toRefs(o),u=p("vv-icon",r),d=e.computed((()=>o.provider||(null==i?void 0:i.iconsProvider))),s=e.computed((()=>{const e=o.name??"",t=`@${d.value}:${o.prefix}:${e}`;if(l.iconExists(t))return t;const a=null==i?void 0:i.iconsCollections.find((t=>{const o=`@${d.value}:${t.prefix}:${e}`;return l.iconExists(o)}));return a?`@${d.value}:${a.prefix}:${e}`:e}));function c(e){const t=function(e){let l;if("undefined"==typeof window){const{JSDOM:e}=require("jsdom");l=(new e).window}return(l?new l.DOMParser:new window.DOMParser).parseFromString(e,"text/html").querySelector("svg")}(e),a=(null==t?void 0:t.innerHTML.trim())||"";t&&a&&l.addIcon(`@${d.value}:${o.prefix}:${o.name}`,{body:a,height:t.viewBox.baseVal.height,width:t.viewBox.baseVal.width})}return i&&o.src&&!l.iconExists(`@${d.value}:${o.prefix}:${o.name}`)&&(n.value=!1,i.fetchIcon(o.src).then((e=>{e&&(c(e),n.value=!0)})).catch((e=>{throw new Error(`Error during fetch icon: ${null==e?void 0:e.message}`)}))),o.svg&&c(o.svg),(t,o)=>e.unref(n)?(e.openBlock(),e.createBlock(e.unref(l.Icon),e.mergeProps({key:0,class:e.unref(u)},{inline:t.inline,width:t.width,height:t.height,horizontalFlip:t.horizontalFlip,verticalFlip:t.verticalFlip,flip:t.flip,rotate:e.unref(a),color:t.color,onLoad:t.onLoad,icon:e.unref(s)}),null,16,["class"])):e.createCommentVNode("v-if",!0)}});function m(e){return Array.isArray(e)?e.filter((e=>{return"string"==typeof(l=e)||l instanceof String;var l})).join(" "):e}const b={valid:{type:Boolean,default:!1},validLabel:{type:[String,Array],default:void 0}},g={invalid:{type:Boolean,default:!1},invalidLabel:{type:[String,Array],default:void 0}},h={loading:{type:Boolean,default:!1},loadingLabel:{type:String,default:"Loading..."}},y={disabled:{type:Boolean,default:!1}},S=(Boolean,Boolean,Boolean,{label:{type:[String,Number],default:void 0}}),B={readonly:{type:Boolean,default:!1}},k={modifiers:{type:[String,Array],default:void 0}},L={hintLabel:{type:String,default:""}},$={options:{type:Array,default:()=>[]},labelKey:{type:[String,Function],default:"label"},valueKey:{type:[String,Function],default:"value"},disabledKey:{type:[String,Function],default:"disabled"}},V={icon:{type:[String,Object],default:void 0},iconPosition:{type:String,default:u.before,validation:e=>Object.values(u).includes(e)}},O={tabindex:{type:[String,Number],default:0}},w={floating:{type:Boolean,default:!1}},x={unselectable:{type:Boolean,default:!0}},E={id:[String,Number]};r.bottom,Boolean,Boolean,Boolean,Boolean,Boolean,Boolean,Boolean,Boolean;const P={...E,name:{type:String,required:!0}},N={autofocus:{type:Boolean,default:!1}},A={autocomplete:{type:String,default:"off"}};d.button,s.button,i.local;const F={...P,...N,...A,...O,...b,...g,...L,...h,...y,...B,...k,...$,...V,...w,...x,...S,multiple:Boolean,required:Boolean,size:[String,Number],modelValue:{type:[String,Number,Boolean,Object,Array],default:void 0},autoselectFirst:{type:Boolean,default:!1},placeholder:String};function I(){return{...F,options:{...F.options,type:Array,default:()=>[]}}}const _=["for"],C={class:"vv-select__wrapper"},z={key:0,class:"vv-select__input-before"},j={class:"vv-select__inner"},D=["id"],R=["disabled","hidden"],q=["disabled","value"],H=["disabled","label"],K=["disabled","value"],M={key:1,class:"vv-select__input-after"};return e.defineComponent({name:"VvSelect",props:I(),emits:["update:modelValue","focus","blur"],setup(l,{emit:n}){const i=l,d=n,s=e.useSlots(),c=function(l,t,o){const a=v(),n=e.computed((()=>{var e;if(a&&(null==(e=a.defaults.value)?void 0:e[l]))return a.defaults.value[l]}));return e.computed((()=>{if(void 0===n.value)return o;const e=n.value,l=t,a=o;return Object.keys(l).reduce(((t,o)=>{const n=a[o];if(t[o]=n,o in e){if(Array.isArray(l[o])){const a=l[o];a.length&&a[0]===n&&(t[o]=e[o])}if("function"==typeof l[o]&&(0,l[o])()===n&&(t[o]=e[o]),"object"==typeof l[o]){let a=l[o].default;"function"==typeof a&&(a=a()),"object"==typeof a?JSON.stringify(a)===JSON.stringify(n)&&(t[o]=e[o]):a===n&&(t[o]=e[o])}}return t}),{})}))}("VvSelect",I(),i),b=e.ref(),{HintSlot:g,hasHintLabelOrSlot:h,hasInvalidLabelOrSlot:y,hintSlotScope:S}=function(l,t){const o=e.computed((()=>e.isRef(l)?l.value:l)),a=e.computed((()=>m(o.value.invalidLabel))),n=e.computed((()=>m(o.value.validLabel))),i=e.computed((()=>o.value.loadingLabel)),r=e.computed((()=>o.value.hintLabel)),u=e.computed((()=>Boolean(o.value.loading&&(t.loading||i.value)))),d=e.computed((()=>!u.value&&Boolean(o.value.invalid&&(t.invalid||a.value)))),s=e.computed((()=>!u.value&&!d.value&&Boolean(o.value.valid&&(t.valid||n.value)))),c=e.computed((()=>!u.value&&!d.value&&!s.value&&Boolean(t.hint||r.value))),v=e.computed((()=>d.value||s.value||u.value||c.value)),p=e.computed((()=>({modelValue:o.value.modelValue,valid:o.value.valid,invalid:o.value.invalid,loading:o.value.loading}))),f=e.defineComponent({name:"HintSlot",props:{tag:{type:String,default:"small"}},setup:()=>({isVisible:v,invalidLabel:a,validLabel:n,loadingLabel:i,hintLabel:r,hasInvalidLabelOrSlot:d,hasValidLabelOrSlot:s,hasLoadingLabelOrSlot:u,hasHintLabelOrSlot:c}),render(){var l,t,o,a,n,i,r,u;if(this.isVisible){let d;return this.hasInvalidLabelOrSlot&&(d="alert"),this.hasValidLabelOrSlot&&(d="status"),this.hasLoadingLabelOrSlot?e.h(this.tag,{role:d},(null==(t=(l=this.$slots).loading)?void 0:t.call(l))??this.loadingLabel):this.hasInvalidLabelOrSlot?e.h(this.tag,{role:d},(null==(a=(o=this.$slots).invalid)?void 0:a.call(o))??this.$slots.invalid??this.invalidLabel):this.hasValidLabelOrSlot?e.h(this.tag,{role:d},(null==(i=(n=this.$slots).valid)?void 0:i.call(n))??this.validLabel):e.h(this.tag,{role:d},(null==(u=(r=this.$slots).hint)?void 0:u.call(r))??this.$slots.hint??this.hintLabel)}return null}});return{hasInvalidLabelOrSlot:d,hasHintLabelOrSlot:c,hasValidLabelOrSlot:s,hasLoadingLabelOrSlot:u,hintSlotScope:p,HintSlot:f}}(c,s),{focused:B}=function(l,o){const{focused:a}=t.useFocus(l);return e.watch(a,(t=>{o(t?"focus":"blur",e.unref(l))})),{focused:a}}(b,d);function k(e){var l;return"string"!=typeof e&&(null==(l=e.options)?void 0:l.length)}const{id:L,modifiers:$,disabled:V,readonly:O,loading:w,icon:x,iconPosition:E,invalid:P,valid:N,floating:A,multiple:F}=e.toRefs(i),T=function(l){return e.computed((()=>String((null==l?void 0:l.value)||o.uid())))}(L),J=e.computed((()=>`${T.value}-hint`)),G=e.computed((()=>i.disabled||i.readonly)),U=e.computed((()=>G.value?-1:i.tabindex)),Q=e.computed({get:()=>i.modelValue,set:e=>{!Array.isArray(e)||0!==(e=e.filter((e=>void 0!==e))).length||i.unselectable?d("update:modelValue",e):b.value.value=i.modelValue}}),W=e.computed((()=>Array.isArray(Q.value)?Q.value.length>0:void 0!==Q.value&&null!==Q.value)),X=t.useElementVisibility(b);e.watch(X,(e=>{e&&i.autofocus&&(B.value=!0)}));const{hasIconBefore:Y,hasIconAfter:Z}=function(l,t){const o=e.computed((()=>"string"==typeof(null==l?void 0:l.value)?{name:null==l?void 0:l.value}:null==l?void 0:l.value)),a=e.computed((()=>(null==t?void 0:t.value)===u.before?o.value:void 0)),n=e.computed((()=>(null==t?void 0:t.value)===u.after?o.value:void 0)),i=e.computed((()=>(null==t?void 0:t.value)===r.left?o.value:void 0)),d=e.computed((()=>(null==t?void 0:t.value)===r.right?o.value:void 0)),s=e.computed((()=>(null==t?void 0:t.value)===r.top?o.value:void 0)),c=e.computed((()=>(null==t?void 0:t.value)===r.bottom?o.value:void 0));return{hasIcon:o,hasIconLeft:i,hasIconRight:d,hasIconTop:s,hasIconBottom:c,hasIconBefore:a,hasIconAfter:n}}(x,E),ee=e.computed((()=>!0===i.invalid||!0!==i.valid&&void 0)),le=p("vv-select",$,e.computed((()=>({valid:N.value,invalid:P.value,loading:w.value,disabled:V.value,readonly:O.value,"icon-before":void 0!==Y.value,"icon-after":void 0!==Z.value,dirty:W.value,focus:B.value,floating:A.value,multiple:F.value})))),{getOptionLabel:te,getOptionValue:oe,isOptionDisabled:ae,getOptionGrouped:ne}=function(l){const{options:t,labelKey:o,valueKey:n,disabledKey:i}=e.toRefs(l);return{options:t,getOptionLabel:e=>"string"==typeof e?e:"function"==typeof o.value?o.value(e):String(o.value?a.get(e,o.value):e),getOptionValue:e=>"string"==typeof e?e:"function"==typeof n.value?n.value(e):n.value?a.get(e,n.value):e,isOptionDisabled:e=>"string"!=typeof e&&("function"==typeof i.value?i.value(e):!!i.value&&a.get(e,i.value)),getOptionGrouped:e=>"string"==typeof e?[]:"object"==typeof e&&e&&"options"in e?e.options:[]}}(i);e.watch((()=>i.options),(e=>{if((null==e?void 0:e.length)&&i.autoselectFirst&&!W.value){const l=oe(e[0]);Q.value=i.multiple?[l]:l}}),{immediate:!0});const ie=e.computed((()=>({name:i.name,tabindex:U.value,disabled:G.value,required:i.required,size:i.size,autocomplete:i.autocomplete,multiple:i.multiple,"aria-invalid":ee.value,"aria-describedby":h.value?J.value:void 0,"aria-errormessage":y.value?J.value:void 0}))),re=e.computed((()=>({valid:i.valid,invalid:i.invalid,modelValue:i.modelValue})));return(l,t)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(e.unref(le))},[l.label?(e.openBlock(),e.createElementBlock("label",{key:0,for:e.unref(T)},e.toDisplayString(l.label),9,_)):e.createCommentVNode("v-if",!0),e.createElementVNode("div",C,[l.$slots.before?(e.openBlock(),e.createElementBlock("div",z,[e.renderSlot(l.$slots,"before",e.normalizeProps(e.guardReactiveProps(e.unref(re))))])):e.createCommentVNode("v-if",!0),e.createElementVNode("div",j,[e.unref(Y)?(e.openBlock(),e.createBlock(f,e.mergeProps({key:0},e.unref(Y),{class:"vv-select__icon"}),null,16)):e.createCommentVNode("v-if",!0),e.withDirectives(e.createElementVNode("select",e.mergeProps({id:e.unref(T),ref_key:"selectEl",ref:b},e.unref(ie),{"onUpdate:modelValue":t[0]||(t[0]=l=>e.isRef(Q)?Q.value=l:null)}),[l.placeholder?(e.openBlock(),e.createElementBlock("option",{key:0,value:void 0,disabled:!l.unselectable,hidden:!l.unselectable},e.toDisplayString(l.placeholder),9,R)):e.createCommentVNode("v-if",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(l.options,((l,t)=>(e.openBlock(),e.createElementBlock(e.Fragment,null,[k(l)?(e.openBlock(),e.createElementBlock("optgroup",{key:`group-${t}`,disabled:e.unref(ae)(l),label:e.unref(te)(l)},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(ne)(l),((l,o)=>(e.openBlock(),e.createElementBlock("option",{key:`group-${t}-item-${o}`,disabled:e.unref(ae)(l),value:e.unref(oe)(l)},e.toDisplayString(e.unref(te)(l)),9,K)))),128))],8,H)):(e.openBlock(),e.createElementBlock("option",{key:t,disabled:e.unref(ae)(l),value:e.unref(oe)(l)},e.toDisplayString(e.unref(te)(l)),9,q))],64)))),256))],16,D),[[e.vModelSelect,e.unref(Q)]]),e.unref(Z)?(e.openBlock(),e.createBlock(f,e.mergeProps({key:1},e.unref(Z),{class:"vv-select__icon vv-select__icon-after"}),null,16)):e.createCommentVNode("v-if",!0)]),l.$slots.after?(e.openBlock(),e.createElementBlock("div",M,[e.renderSlot(l.$slots,"after",e.normalizeProps(e.guardReactiveProps(e.unref(re))))])):e.createCommentVNode("v-if",!0)]),e.createVNode(e.unref(g),{id:e.unref(J),class:"vv-select__hint"},e.createSlots({_:2},[l.$slots.hint?{name:"hint",fn:e.withCtx((()=>[e.renderSlot(l.$slots,"hint",e.normalizeProps(e.guardReactiveProps(e.unref(S))))])),key:"0"}:void 0,l.$slots.loading?{name:"loading",fn:e.withCtx((()=>[e.renderSlot(l.$slots,"loading",e.normalizeProps(e.guardReactiveProps(e.unref(S))))])),key:"1"}:void 0,l.$slots.valid?{name:"valid",fn:e.withCtx((()=>[e.renderSlot(l.$slots,"valid",e.normalizeProps(e.guardReactiveProps(e.unref(S))))])),key:"2"}:void 0,l.$slots.invalid?{name:"invalid",fn:e.withCtx((()=>[e.renderSlot(l.$slots,"invalid",e.normalizeProps(e.guardReactiveProps(e.unref(S))))])),key:"3"}:void 0]),1032,["id"])],2))}})}));
@@ -29,6 +29,7 @@ declare const _default: <T extends string | Option>(__VLS_props: {
29
29
  valueKey?: string | Function | undefined;
30
30
  disabledKey?: string | Function | undefined;
31
31
  "onUpdate:modelValue"?: ((args_0: any) => any) | undefined;
32
+ autoselectFirst?: boolean | undefined;
32
33
  readonly placeholder?: string | undefined;
33
34
  autocomplete?: string | undefined;
34
35
  autofocus?: boolean | undefined;
@@ -102,6 +103,7 @@ declare const _default: <T extends string | Option>(__VLS_props: {
102
103
  valueKey?: string | Function | undefined;
103
104
  disabledKey?: string | Function | undefined;
104
105
  "onUpdate:modelValue"?: ((args_0: any) => any) | undefined;
106
+ autoselectFirst?: boolean | undefined;
105
107
  readonly placeholder?: string | undefined;
106
108
  autocomplete?: string | undefined;
107
109
  autofocus?: boolean | undefined;
@@ -179,6 +181,7 @@ declare const _default: <T extends string | Option>(__VLS_props: {
179
181
  valueKey?: string | Function | undefined;
180
182
  disabledKey?: string | Function | undefined;
181
183
  "onUpdate:modelValue"?: ((args_0: any) => any) | undefined;
184
+ autoselectFirst?: boolean | undefined;
182
185
  readonly placeholder?: string | undefined;
183
186
  autocomplete?: string | undefined;
184
187
  autofocus?: boolean | undefined;
@@ -32,6 +32,13 @@ export declare const VvSelectProps: {
32
32
  type: (ObjectConstructor | ArrayConstructor | BooleanConstructor | StringConstructor | NumberConstructor)[];
33
33
  default: undefined;
34
34
  };
35
+ /**
36
+ * Select first option automatically
37
+ */
38
+ autoselectFirst: {
39
+ type: BooleanConstructor;
40
+ default: boolean;
41
+ };
35
42
  /**
36
43
  * Select placeholder
37
44
  */
@@ -162,6 +169,13 @@ export declare function useVvSelectProps<T extends Option | string>(): {
162
169
  type: (ObjectConstructor | ArrayConstructor | BooleanConstructor | StringConstructor | NumberConstructor)[];
163
170
  default: undefined;
164
171
  };
172
+ /**
173
+ * Select first option automatically
174
+ */
175
+ autoselectFirst: {
176
+ type: BooleanConstructor;
177
+ default: boolean;
178
+ };
165
179
  /**
166
180
  * Select placeholder
167
181
  */