@tagplus/components 5.2.19 → 5.3.1

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 (146) hide show
  1. package/dist/es/_virtual/_plugin-vue_export-helper.mjs +10 -0
  2. package/dist/es/components.css +2391 -0
  3. package/dist/es/node_modules/@element-plus/icons-vue/dist/index.mjs +148 -0
  4. package/dist/es/node_modules/@popperjs/core/lib/enums.mjs +22 -0
  5. package/dist/es/node_modules/@vue/shared/dist/shared.esm-bundler.mjs +28 -0
  6. package/dist/es/node_modules/@vueuse/core/index.mjs +172 -0
  7. package/dist/es/node_modules/@vueuse/shared/index.mjs +68 -0
  8. package/dist/es/node_modules/element-plus/es/constants/size.mjs +4 -0
  9. package/dist/es/node_modules/element-plus/es/hooks/use-focus-controller/index.mjs +64 -0
  10. package/dist/es/node_modules/element-plus/es/hooks/use-id/index.mjs +30 -0
  11. package/dist/es/node_modules/element-plus/es/hooks/use-locale/index.mjs +29 -0
  12. package/dist/es/node_modules/element-plus/es/hooks/use-namespace/index.mjs +79 -0
  13. package/dist/es/node_modules/element-plus/es/hooks/use-prop/index.mjs +11 -0
  14. package/dist/es/node_modules/element-plus/es/hooks/use-size/index.mjs +20 -0
  15. package/dist/es/node_modules/element-plus/es/locale/lang/en.mjs +182 -0
  16. package/dist/es/node_modules/element-plus/es/utils/error.mjs +16 -0
  17. package/dist/es/node_modules/element-plus/es/utils/types.mjs +9 -0
  18. package/dist/es/node_modules/element-plus/es/utils/vue/props/runtime.mjs +42 -0
  19. package/dist/es/src/components/Autosuggest/Autosuggest.vue.mjs +446 -0
  20. package/dist/es/src/components/Autosuggest/Multisuggest.vue.mjs +17 -0
  21. package/dist/es/src/components/Autosuggest/autosuggest-props.mjs +204 -0
  22. package/dist/es/src/components/Autosuggest/core.mjs +56 -0
  23. package/dist/es/src/components/Autosuggest/multisuggest-props.mjs +11 -0
  24. package/dist/es/src/components/Autosuggest/option.vue.mjs +118 -0
  25. package/dist/es/src/components/Autosuggest/select-dropdown.vue.mjs +62 -0
  26. package/dist/es/src/components/Autosuggest/useOption.mjs +93 -0
  27. package/dist/es/src/components/Autosuggest/useSelect.mjs +803 -0
  28. package/dist/es/src/components/Inline/Inline.vue.mjs +125 -0
  29. package/dist/es/src/components/Inline/index.mjs +4 -0
  30. package/dist/es/src/components/InputNumber/InputNumber.vue.mjs +360 -0
  31. package/dist/es/src/components/InputNumber/index.mjs +4 -0
  32. package/dist/es/src/components/InputNumber/input-number.mjs +128 -0
  33. package/dist/es/src/components/Loader/Loader.vue.mjs +59 -0
  34. package/dist/es/src/components/Loader/index.mjs +4 -0
  35. package/dist/es/src/components/Money/Money.vue.mjs +72 -0
  36. package/dist/es/src/components/Money/index.mjs +4 -0
  37. package/dist/es/src/components/Multisuggest/index.mjs +4 -0
  38. package/dist/es/src/components/OptionsList/OptionsList.vue.mjs +28 -0
  39. package/dist/es/src/components/OptionsList/index.mjs +4 -0
  40. package/dist/es/src/components/OptionsListItem/OptionsListItem.vue.mjs +96 -0
  41. package/dist/es/src/components/OptionsListItem/index.mjs +4 -0
  42. package/dist/es/src/components/Percent/Percent.vue.mjs +73 -0
  43. package/dist/es/src/components/Percent/index.mjs +4 -0
  44. package/dist/es/src/components/Skeleton/Skeleton.vue.mjs +79 -0
  45. package/dist/es/src/components/Skeleton/index.mjs +4 -0
  46. package/dist/es/src/components/Step/Step.vue.mjs +206 -0
  47. package/dist/es/src/components/Step/index.mjs +4 -0
  48. package/dist/es/src/components/Steps/Steps.vue.mjs +15 -0
  49. package/dist/es/src/components/Steps/index.mjs +4 -0
  50. package/dist/es/src/components/Tip/Tip.vue.mjs +160 -0
  51. package/dist/es/src/components/Tip/index.mjs +4 -0
  52. package/dist/es/src/components/index.mjs +32 -0
  53. package/dist/es/src/locale/i18nCreator.mjs +93 -0
  54. package/dist/es/src/locale/lang/pt-br.mjs +21 -0
  55. package/dist/es/src/main.mjs +17 -0
  56. package/dist/es/src/mixins/floatFormatter.mjs +42 -0
  57. package/dist/es/src/plugins/currency.mjs +69 -0
  58. package/dist/es/src/utils/constants.mjs +6 -0
  59. package/dist/es/src/utils/error.mjs +22 -0
  60. package/dist/es/src/utils/i18n.mjs +4 -0
  61. package/dist/es/src/utils/icon.mjs +9 -0
  62. package/dist/es/src/utils/index.mjs +11 -0
  63. package/dist/es/src/utils/runtime.mjs +50 -0
  64. package/dist/es/src/utils/scroll.mjs +28 -0
  65. package/dist/es/src/utils/strings.mjs +4 -0
  66. package/dist/es/src/utils/types.mjs +9 -0
  67. package/dist/es/src/utils/use-derived-namespace.mjs +15 -0
  68. package/dist/es/src/utils/use-form-common-props.mjs +25 -0
  69. package/dist/es/src/utils/use-form-item.mjs +61 -0
  70. package/dist/es/src/utils/use-id.mjs +35 -0
  71. package/dist/es/src/utils/use-input.mjs +31 -0
  72. package/dist/lib/_virtual/_plugin-vue_export-helper.js +10 -0
  73. package/dist/lib/components.css +2391 -0
  74. package/dist/lib/node_modules/@element-plus/icons-vue/dist/index.js +148 -0
  75. package/dist/lib/node_modules/@popperjs/core/lib/enums.js +22 -0
  76. package/dist/lib/node_modules/@vue/shared/dist/shared.esm-bundler.js +28 -0
  77. package/dist/lib/node_modules/@vueuse/core/index.js +170 -0
  78. package/dist/lib/node_modules/@vueuse/shared/index.js +68 -0
  79. package/dist/lib/node_modules/element-plus/es/constants/size.js +4 -0
  80. package/dist/lib/node_modules/element-plus/es/hooks/use-focus-controller/index.js +64 -0
  81. package/dist/lib/node_modules/element-plus/es/hooks/use-id/index.js +30 -0
  82. package/dist/lib/node_modules/element-plus/es/hooks/use-locale/index.js +29 -0
  83. package/dist/lib/node_modules/element-plus/es/hooks/use-namespace/index.js +79 -0
  84. package/dist/lib/node_modules/element-plus/es/hooks/use-prop/index.js +11 -0
  85. package/dist/lib/node_modules/element-plus/es/hooks/use-size/index.js +20 -0
  86. package/dist/lib/node_modules/element-plus/es/locale/lang/en.js +182 -0
  87. package/dist/lib/node_modules/element-plus/es/utils/error.js +16 -0
  88. package/dist/lib/node_modules/element-plus/es/utils/types.js +9 -0
  89. package/dist/lib/node_modules/element-plus/es/utils/vue/props/runtime.js +42 -0
  90. package/dist/lib/src/components/Autosuggest/Autosuggest.vue.js +446 -0
  91. package/dist/lib/src/components/Autosuggest/Multisuggest.vue.js +17 -0
  92. package/dist/lib/src/components/Autosuggest/autosuggest-props.js +204 -0
  93. package/dist/lib/src/components/Autosuggest/core.js +56 -0
  94. package/dist/lib/src/components/Autosuggest/multisuggest-props.js +11 -0
  95. package/dist/lib/src/components/Autosuggest/option.vue.js +118 -0
  96. package/dist/lib/src/components/Autosuggest/select-dropdown.vue.js +62 -0
  97. package/dist/lib/src/components/Autosuggest/useOption.js +93 -0
  98. package/dist/lib/src/components/Autosuggest/useSelect.js +803 -0
  99. package/dist/lib/src/components/Inline/Inline.vue.js +125 -0
  100. package/dist/lib/src/components/Inline/index.js +4 -0
  101. package/dist/lib/src/components/InputNumber/InputNumber.vue.js +360 -0
  102. package/dist/lib/src/components/InputNumber/index.js +4 -0
  103. package/dist/lib/src/components/InputNumber/input-number.js +128 -0
  104. package/dist/lib/src/components/Loader/Loader.vue.js +59 -0
  105. package/dist/lib/src/components/Loader/index.js +4 -0
  106. package/dist/lib/src/components/Money/Money.vue.js +72 -0
  107. package/dist/lib/src/components/Money/index.js +4 -0
  108. package/dist/lib/src/components/Multisuggest/index.js +4 -0
  109. package/dist/lib/src/components/OptionsList/OptionsList.vue.js +28 -0
  110. package/dist/lib/src/components/OptionsList/index.js +4 -0
  111. package/dist/lib/src/components/OptionsListItem/OptionsListItem.vue.js +96 -0
  112. package/dist/lib/src/components/OptionsListItem/index.js +4 -0
  113. package/dist/lib/src/components/Percent/Percent.vue.js +73 -0
  114. package/dist/lib/src/components/Percent/index.js +4 -0
  115. package/dist/lib/src/components/Skeleton/Skeleton.vue.js +79 -0
  116. package/dist/lib/src/components/Skeleton/index.js +4 -0
  117. package/dist/lib/src/components/Step/Step.vue.js +206 -0
  118. package/dist/lib/src/components/Step/index.js +4 -0
  119. package/dist/lib/src/components/Steps/Steps.vue.js +15 -0
  120. package/dist/lib/src/components/Steps/index.js +4 -0
  121. package/dist/lib/src/components/Tip/Tip.vue.js +160 -0
  122. package/dist/lib/src/components/Tip/index.js +4 -0
  123. package/dist/lib/src/components/index.js +32 -0
  124. package/dist/lib/src/locale/i18nCreator.js +93 -0
  125. package/dist/lib/src/locale/lang/pt-br.js +21 -0
  126. package/dist/lib/src/main.js +17 -0
  127. package/dist/lib/src/mixins/floatFormatter.js +42 -0
  128. package/dist/lib/src/plugins/currency.js +69 -0
  129. package/dist/lib/src/utils/constants.js +6 -0
  130. package/dist/lib/src/utils/error.js +22 -0
  131. package/dist/lib/src/utils/i18n.js +4 -0
  132. package/dist/lib/src/utils/icon.js +9 -0
  133. package/dist/lib/src/utils/index.js +14 -0
  134. package/dist/lib/src/utils/runtime.js +50 -0
  135. package/dist/lib/src/utils/scroll.js +28 -0
  136. package/dist/lib/src/utils/strings.js +4 -0
  137. package/dist/lib/src/utils/types.js +12 -0
  138. package/dist/lib/src/utils/use-derived-namespace.js +15 -0
  139. package/dist/lib/src/utils/use-form-common-props.js +25 -0
  140. package/dist/lib/src/utils/use-form-item.js +61 -0
  141. package/dist/lib/src/utils/use-id.js +35 -0
  142. package/dist/lib/src/utils/use-input.js +31 -0
  143. package/package.json +18 -15
  144. package/dist/main.bundle.js +0 -2
  145. package/dist/main.bundle.js.LICENSE.txt +0 -15
  146. package/dist/main.css +0 -11
@@ -0,0 +1,803 @@
1
+ import { reactive, ref, computed, getCurrentInstance, watch, watchEffect, nextTick, onMounted } from "vue";
2
+ import { isArray, isFunction, toRawType, isObject, isString } from "../../../node_modules/@vue/shared/dist/shared.esm-bundler.mjs";
3
+ import { isEqual, get, debounce, findLastIndex } from "lodash-es";
4
+ import { useResizeObserver } from "../../../node_modules/@vueuse/core/index.mjs";
5
+ import { isNumber } from "../../utils/types.mjs";
6
+ import { debugWarn } from "../../utils/error.mjs";
7
+ import { ValidateComponentsMap } from "../../utils/icon.mjs";
8
+ import { scrollIntoView } from "../../utils/scroll.mjs";
9
+ import { useInput } from "../../utils/use-input.mjs";
10
+ import { useFormItem, useFormItemInputId } from "../../utils/use-form-item.mjs";
11
+ import { useFormSize } from "../../utils/use-form-common-props.mjs";
12
+ import { useLocale } from "../../../node_modules/element-plus/es/hooks/use-locale/index.mjs";
13
+ import { useId } from "../../../node_modules/element-plus/es/hooks/use-id/index.mjs";
14
+ import { useNamespace } from "../../../node_modules/element-plus/es/hooks/use-namespace/index.mjs";
15
+ import { useFocusController } from "../../../node_modules/element-plus/es/hooks/use-focus-controller/index.mjs";
16
+ import { isClient } from "../../../node_modules/@vueuse/shared/index.mjs";
17
+ const UPDATE_MODEL_EVENT = "update:modelValue";
18
+ const CHANGE_EVENT = "change";
19
+ const EVENT_CODE = {
20
+ delete: "Delete"
21
+ };
22
+ const MINIMUM_INPUT_WIDTH = 11;
23
+ const useSelect = (props, { emit }) => {
24
+ const { t } = useLocale();
25
+ const contentId = useId();
26
+ const nsSelect = useNamespace("select");
27
+ const nsInput = useNamespace("input");
28
+ const states = reactive({
29
+ inputValue: "",
30
+ options: /* @__PURE__ */ new Map(),
31
+ cachedOptions: /* @__PURE__ */ new Map(),
32
+ disabledOptions: /* @__PURE__ */ new Map(),
33
+ optionValues: [],
34
+ // sorted value of options
35
+ selected: props.multiple ? [] : {},
36
+ selectionWidth: 0,
37
+ calculatorWidth: 0,
38
+ collapseItemWidth: 0,
39
+ selectedLabel: "",
40
+ hoveringIndex: -1,
41
+ previousQuery: null,
42
+ inputHovering: false,
43
+ menuVisibleOnFocus: false,
44
+ isBeforeHide: false
45
+ });
46
+ const selectRef = ref(null);
47
+ const selectionRef = ref(null);
48
+ const tooltipRef = ref(null);
49
+ const inputRef = ref(null);
50
+ const calculatorRef = ref(null);
51
+ const suffixRef = ref(null);
52
+ const menuRef = ref(null);
53
+ const collapseItemRef = ref(null);
54
+ const scrollbarRef = ref(null);
55
+ const { wrapperRef, isFocused, handleFocus, handleBlur } = useFocusController(
56
+ inputRef,
57
+ {
58
+ afterFocus() {
59
+ if (props.automaticDropdown && !expanded.value) {
60
+ expanded.value = true;
61
+ states.menuVisibleOnFocus = true;
62
+ }
63
+ },
64
+ beforeBlur(event) {
65
+ var _a;
66
+ return (_a = tooltipRef.value) == null ? void 0 : _a.isFocusInsideContent(event);
67
+ },
68
+ afterBlur() {
69
+ expanded.value = false;
70
+ states.menuVisibleOnFocus = false;
71
+ }
72
+ }
73
+ );
74
+ const expanded = ref(false);
75
+ const hoverOption = ref();
76
+ const { form, formItem } = useFormItem();
77
+ const { inputId } = useFormItemInputId(props, {
78
+ formItemContext: formItem
79
+ });
80
+ const selectDisabled = computed(() => props.disabled || (form == null ? void 0 : form.disabled));
81
+ const hasModelValue = computed(() => {
82
+ return props.multiple ? isArray(props.modelValue) && props.modelValue.length > 0 : props.modelValue !== void 0 && props.modelValue !== null && props.modelValue !== "";
83
+ });
84
+ const showClose = computed(() => {
85
+ const criteria = props.clearable && !selectDisabled.value && hasModelValue.value;
86
+ return criteria;
87
+ });
88
+ const iconReverse = computed(() => {
89
+ return expanded.value ? "is-reverse" : "";
90
+ });
91
+ const formattedValue = computed(() => {
92
+ let newVal = "";
93
+ if (typeof props.modelValue === "boolean") {
94
+ newVal = "";
95
+ } else if (Array.isArray(props.modelValue)) {
96
+ newVal = props.modelValue;
97
+ } else if (props.modelValue && typeof props.modelValue === "object") {
98
+ if (!Object.keys(newVal).length) {
99
+ return {};
100
+ }
101
+ if (!props.modelValue[props.valueKey] && props.modelValue[props.valueKey] !== "") {
102
+ if (process.env.DEBUG === "true") {
103
+ const instance = getCurrentInstance();
104
+ console.error(`Componente '${instance.type.componentName}' option doesn't have a valueKey '${props.valueKey}' key`);
105
+ }
106
+ } else {
107
+ newVal = props.modelValue[props.valueKey];
108
+ }
109
+ }
110
+ return newVal;
111
+ });
112
+ const validateState = computed(() => (formItem == null ? void 0 : formItem.validateState) || "");
113
+ const validateIcon = computed(
114
+ () => ValidateComponentsMap[validateState.value]
115
+ );
116
+ const debounce$1 = 300;
117
+ const emptyText = computed(() => {
118
+ if (props.loading) {
119
+ return props.loadingText || t("el.select.loading");
120
+ } else {
121
+ if (!states.inputValue && states.options.size === 0)
122
+ return false;
123
+ if (states.inputValue && states.options.size > 0 && filteredOptionsCount.value === 0) {
124
+ return props.noMatchText || t("el.select.noMatch");
125
+ }
126
+ if (states.options.size === 0) {
127
+ return props.noDataText || t("autosuggests.sem_dados");
128
+ }
129
+ }
130
+ return null;
131
+ });
132
+ const filteredOptionsCount = computed(
133
+ () => optionsArray.value.filter((option) => option.visible).length
134
+ );
135
+ const optionsArray = computed(() => {
136
+ const list = Array.from(states.options.values());
137
+ const newList = [];
138
+ states.optionValues.forEach((item) => {
139
+ const index = list.findIndex((i) => i.value === item);
140
+ if (index > -1) {
141
+ newList.push(list[index]);
142
+ }
143
+ });
144
+ return newList.length >= list.length ? newList : list;
145
+ });
146
+ const cachedOptionsArray = computed(
147
+ () => Array.from(states.cachedOptions.values())
148
+ );
149
+ const showNewOption = computed(() => {
150
+ const hasExistingOption = optionsArray.value.filter((option) => {
151
+ return !option.created;
152
+ }).some((option) => {
153
+ return option.currentLabel === states.inputValue;
154
+ });
155
+ return props.allowCreate && states.inputValue !== "" && !hasExistingOption;
156
+ });
157
+ const updateOptions = () => {
158
+ return;
159
+ };
160
+ const selectSize = useFormSize();
161
+ const collapseTagSize = computed(
162
+ () => ["small"].includes(selectSize.value) ? "small" : "default"
163
+ );
164
+ const dropdownMenuVisible = computed({
165
+ get() {
166
+ return expanded.value && emptyText.value !== false;
167
+ },
168
+ set(val) {
169
+ states.doRequest = true;
170
+ expanded.value = val;
171
+ }
172
+ });
173
+ const shouldShowPlaceholder = computed(() => {
174
+ if (isArray(props.modelValue)) {
175
+ return props.modelValue.length === 0 && !states.inputValue;
176
+ }
177
+ return !states.inputValue;
178
+ });
179
+ const currentPlaceholder = computed(() => {
180
+ const _placeholder = props.placeholder ?? t("el.select.placeholder");
181
+ return props.multiple || !hasModelValue.value ? _placeholder : states.selectedLabel;
182
+ });
183
+ const suggestionsList = computed(() => {
184
+ if (props.loading) return [];
185
+ const list = typeof props.suggestions === "object" ? Object.values(props.suggestions) : props.suggestions;
186
+ if (props.allowCreate) {
187
+ const createdSuggestion = { created: true };
188
+ createdSuggestion[props.labelKey] = states.inputValue !== "" ? states.inputValue : null;
189
+ createdSuggestion[props.valueKey] = createdSuggestion[props.labelKey];
190
+ list.push(createdSuggestion);
191
+ }
192
+ return list;
193
+ });
194
+ const newItem = computed(() => {
195
+ const instance = getCurrentInstance();
196
+ return states.inputValue ? t("autosuggests.cadastrar", { nameItem: states.inputValue }) : t(`autosuggests.newItem.${instance.type.componentName}`);
197
+ });
198
+ const myId = computed(() => {
199
+ const instance = getCurrentInstance();
200
+ return props.id || instance.type.componentName;
201
+ });
202
+ const firstValueStopHandle = watch(
203
+ () => props.suggestions,
204
+ (val, oldVal) => {
205
+ if (!isNumber(props.modelValue)) {
206
+ firstValueStopHandle();
207
+ }
208
+ if (val.length) {
209
+ setSelected();
210
+ }
211
+ firstValueStopHandle();
212
+ }
213
+ );
214
+ watch(
215
+ () => props.modelValue,
216
+ (val, oldVal) => {
217
+ if (props.multiple) {
218
+ if (!props.reserveKeyword) {
219
+ states.inputValue = "";
220
+ handleQueryChange("");
221
+ }
222
+ }
223
+ setSelected();
224
+ if (!isEqual(val, oldVal) && props.validateEvent) {
225
+ formItem == null ? void 0 : formItem.validate("change").catch((err) => debugWarn(err));
226
+ }
227
+ },
228
+ {
229
+ flush: "post",
230
+ deep: true
231
+ }
232
+ );
233
+ watch(
234
+ () => expanded.value,
235
+ (val) => {
236
+ if (val) {
237
+ handleQueryChange(states.inputValue);
238
+ } else {
239
+ states.inputValue = "";
240
+ states.previousQuery = null;
241
+ states.isBeforeHide = true;
242
+ }
243
+ emit("visible-change", val);
244
+ }
245
+ );
246
+ watch(
247
+ // fix `Array.prototype.push/splice/..` cannot trigger non-deep watcher
248
+ // https://github.com/vuejs/vue-next/issues/2116
249
+ () => states.options.entries(),
250
+ () => {
251
+ if (!isClient) return;
252
+ if (props.defaultFirstOption && filteredOptionsCount.value) {
253
+ checkDefaultFirstOption();
254
+ }
255
+ },
256
+ {
257
+ flush: "post"
258
+ }
259
+ );
260
+ watch(
261
+ () => states.hoveringIndex,
262
+ (val) => {
263
+ if (isNumber(val) && val > -1) {
264
+ hoverOption.value = optionsArray.value[val] || {};
265
+ } else {
266
+ hoverOption.value = {};
267
+ }
268
+ optionsArray.value.forEach((option) => {
269
+ option.hover = hoverOption.value === option;
270
+ });
271
+ }
272
+ );
273
+ watchEffect(() => {
274
+ if (states.isBeforeHide) return;
275
+ });
276
+ const handleQueryChange = (val) => {
277
+ if (!states.doRequest && states.previousQuery === val) {
278
+ return;
279
+ }
280
+ if (states.previousQuery === val) {
281
+ return;
282
+ }
283
+ states.previousQuery = val;
284
+ if (isFunction(props.remoteMethod)) {
285
+ props.remoteMethod(val);
286
+ }
287
+ if (props.defaultFirstOption) {
288
+ nextTick(checkDefaultFirstOption);
289
+ } else {
290
+ nextTick(updateHoveringIndex);
291
+ }
292
+ };
293
+ const checkDefaultFirstOption = () => {
294
+ const optionsInDropdown = optionsArray.value.filter(
295
+ (n) => n.visible && !n.disabled && !n.states.groupDisabled
296
+ );
297
+ const userCreatedOption = optionsInDropdown.find((n) => n.created);
298
+ const firstOriginOption = optionsInDropdown[0];
299
+ states.hoveringIndex = getValueIndex(
300
+ optionsArray.value,
301
+ userCreatedOption || firstOriginOption
302
+ );
303
+ };
304
+ const setSelected = () => {
305
+ if (!props.multiple) {
306
+ const option = getOption(props.modelValue);
307
+ states.selectedLabel = option.currentLabel;
308
+ states.selected = option;
309
+ return;
310
+ } else {
311
+ states.selectedLabel = "";
312
+ }
313
+ const result = [];
314
+ if (isArray(props.modelValue)) {
315
+ props.modelValue.forEach((value) => {
316
+ result.push(getOption(value));
317
+ });
318
+ }
319
+ states.selected = result;
320
+ };
321
+ const getObjectFromSuggestions = (value) => {
322
+ for (let i = 0; i < props.suggestions.length; i++) {
323
+ const item = props.suggestions[i];
324
+ if (item[props.valueKey] === value) {
325
+ return {
326
+ ...item,
327
+ [props.valueKey]: JSON.parse(JSON.stringify(value)),
328
+ [props.labelKey]: item[props.labelKey]
329
+ };
330
+ }
331
+ }
332
+ return {
333
+ [props.valueKey]: value,
334
+ [props.labelKey]: value
335
+ };
336
+ };
337
+ const getValueLabelForOption = (modelValue) => {
338
+ let value;
339
+ let initialLabel = modelValue ?? false;
340
+ if (typeof modelValue === "boolean") {
341
+ value = "";
342
+ } else if (Array.isArray(modelValue)) {
343
+ value = modelValue;
344
+ } else if (typeof modelValue === "number" && props.suggestions.length && typeof props.suggestions[0] === "object") {
345
+ const suggestionsValue = getObjectFromSuggestions(modelValue);
346
+ value = suggestionsValue[props.valueKey];
347
+ initialLabel = suggestionsValue[props.labelKey];
348
+ } else if (modelValue && typeof modelValue === "object") {
349
+ if (!Object.keys(modelValue).length) {
350
+ return {};
351
+ }
352
+ if (!modelValue[props.valueKey] && modelValue[props.valueKey] !== "") {
353
+ const instance = getCurrentInstance();
354
+ console.error(`Componente '${instance.type.componentName}' option doesn't have a valueKey '${props.valueKey}' key`);
355
+ } else {
356
+ if (modelValue[props.labelKey]) {
357
+ initialLabel = modelValue[props.labelKey];
358
+ }
359
+ value = modelValue[props.valueKey];
360
+ }
361
+ } else {
362
+ value = modelValue;
363
+ }
364
+ return { value, initialLabel };
365
+ };
366
+ const getOption = (val) => {
367
+ const { value, initialLabel } = getValueLabelForOption(val);
368
+ let option;
369
+ if (value && initialLabel) {
370
+ option = {
371
+ value,
372
+ currentLabel: initialLabel
373
+ };
374
+ }
375
+ const isObjectValue = toRawType(value).toLowerCase() === "object";
376
+ const isNull = toRawType(value).toLowerCase() === "null";
377
+ const isUndefined = toRawType(value).toLowerCase() === "undefined";
378
+ for (let i = states.cachedOptions.size - 1; i >= 0; i--) {
379
+ const cachedOption = cachedOptionsArray.value[i];
380
+ const isEqualValue = isObjectValue ? get(cachedOption.value, props.valueKey) === get(value, props.valueKey) : cachedOption.value === value;
381
+ if (isEqualValue) {
382
+ option = {
383
+ value,
384
+ currentLabel: cachedOption.currentLabel,
385
+ isDisabled: cachedOption.isDisabled
386
+ };
387
+ break;
388
+ }
389
+ }
390
+ if (option) return option;
391
+ const label = isObjectValue ? value.label : !isNull && !isUndefined ? value : "";
392
+ const newOption = {
393
+ value,
394
+ currentLabel: initialLabel || label
395
+ };
396
+ return newOption;
397
+ };
398
+ const updateHoveringIndex = () => {
399
+ if (!props.multiple) {
400
+ states.hoveringIndex = optionsArray.value.findIndex((item) => {
401
+ return getValueKey(item) === getValueKey(states.selected);
402
+ });
403
+ } else {
404
+ if (states.selected.length > 0) {
405
+ states.hoveringIndex = Math.min(
406
+ ...states.selected.map((selected) => {
407
+ return optionsArray.value.findIndex((item) => {
408
+ return getValueKey(item) === getValueKey(selected);
409
+ });
410
+ })
411
+ );
412
+ } else {
413
+ states.hoveringIndex = -1;
414
+ }
415
+ }
416
+ };
417
+ const resetSelectionWidth = () => {
418
+ states.selectionWidth = selectionRef.value.getBoundingClientRect().width;
419
+ };
420
+ const resetCalculatorWidth = () => {
421
+ states.calculatorWidth = calculatorRef.value.getBoundingClientRect().width;
422
+ };
423
+ const resetCollapseItemWidth = () => {
424
+ states.collapseItemWidth = collapseItemRef.value.getBoundingClientRect().width;
425
+ };
426
+ const updateTooltip = () => {
427
+ var _a, _b;
428
+ (_b = (_a = tooltipRef.value) == null ? void 0 : _a.updatePopper) == null ? void 0 : _b.call(_a);
429
+ };
430
+ const onInputChange = () => {
431
+ if (states.inputValue.length > 0 && !expanded.value) {
432
+ expanded.value = true;
433
+ }
434
+ handleQueryChange(states.inputValue);
435
+ };
436
+ const onInput = (event) => {
437
+ states.inputValue = event.target.value;
438
+ debouncedOnInputChange();
439
+ };
440
+ const debouncedOnInputChange = debounce(() => {
441
+ onInputChange();
442
+ }, debounce$1.value);
443
+ const emitChange = (val) => {
444
+ if (!isEqual(formattedValue, val)) {
445
+ emit(CHANGE_EVENT, val);
446
+ }
447
+ };
448
+ const getLastNotDisabledIndex = (value) => findLastIndex(value, (it) => !states.disabledOptions.has(it));
449
+ const deletePrevTag = (e) => {
450
+ if (!props.multiple) return;
451
+ if (e.code === EVENT_CODE.delete) return;
452
+ if (e.target.value.length <= 0) {
453
+ const value = props.modelValue.slice();
454
+ const lastNotDisabledIndex = getLastNotDisabledIndex(value);
455
+ if (lastNotDisabledIndex < 0) return;
456
+ value.splice(lastNotDisabledIndex, 1);
457
+ emit(UPDATE_MODEL_EVENT, value);
458
+ emitChange(value);
459
+ }
460
+ };
461
+ const deleteTag = (event, tag) => {
462
+ const index = states.selected.indexOf(tag);
463
+ if (index > -1 && !selectDisabled.value) {
464
+ const value = props.modelValue.slice();
465
+ value.splice(index, 1);
466
+ emit(UPDATE_MODEL_EVENT, value);
467
+ emitChange(value);
468
+ emit("remove-tag", tag.value);
469
+ }
470
+ event.stopPropagation();
471
+ focus();
472
+ };
473
+ const deleteSelected = (event) => {
474
+ event.stopPropagation();
475
+ const value = props.multiple ? [] : "";
476
+ if (!isString(value)) {
477
+ for (const item of states.selected) {
478
+ if (item.isDisabled) value.push(item.value);
479
+ }
480
+ }
481
+ emit(UPDATE_MODEL_EVENT, value);
482
+ emitChange(value);
483
+ states.hoveringIndex = -1;
484
+ expanded.value = false;
485
+ emit("clear");
486
+ focus();
487
+ };
488
+ const normalizarValor = (value) => {
489
+ if (isObject(value) && props.legacyModel) {
490
+ return value[props.valueKey];
491
+ } else if (!isObject(value) && !props.legacyModel) {
492
+ return getObjectFromSuggestions(value);
493
+ }
494
+ return value;
495
+ };
496
+ const normalizarTipos = (value) => {
497
+ if (props.multiple) {
498
+ return value.map((item) => {
499
+ return normalizarValor(item);
500
+ });
501
+ }
502
+ return normalizarValor(value);
503
+ };
504
+ const handleOptionSelect = (option) => {
505
+ if (props.multiple) {
506
+ const value = (props.modelValue || []).slice();
507
+ const optionIndex = getValueIndex(value, option.value);
508
+ if (optionIndex > -1) {
509
+ value.splice(optionIndex, 1);
510
+ } else if (props.multipleLimit <= 0 || value.length < props.multipleLimit) {
511
+ const emitValue = props.legacyModel ? option.value : option.item;
512
+ value.push(emitValue);
513
+ }
514
+ const formattedValue2 = normalizarTipos(value);
515
+ emit(UPDATE_MODEL_EVENT, formattedValue2);
516
+ emitChange(formattedValue2);
517
+ if (option.created) {
518
+ handleQueryChange("");
519
+ }
520
+ if (!props.reserveKeyword) {
521
+ states.inputValue = "";
522
+ }
523
+ } else {
524
+ const emitValue = props.legacyModel ? option.value : option.item;
525
+ const formattedValue2 = normalizarTipos(emitValue);
526
+ emit(UPDATE_MODEL_EVENT, formattedValue2);
527
+ emitChange(formattedValue2);
528
+ expanded.value = false;
529
+ }
530
+ focus();
531
+ if (expanded.value) return;
532
+ nextTick(() => {
533
+ scrollToOption(option);
534
+ });
535
+ };
536
+ const getValueIndex = (arr = [], value) => {
537
+ const compareValue = isObject(value) ? value[props.valueKey] : value;
538
+ for (let i = 0; i < arr.length; i++) {
539
+ const el = arr[i];
540
+ const elCompareValue = isObject(el) ? el[props.valueKey] : el;
541
+ if (compareValue === elCompareValue) {
542
+ return i;
543
+ }
544
+ }
545
+ return -1;
546
+ };
547
+ const scrollToOption = (option) => {
548
+ var _a, _b, _c, _d, _e;
549
+ const targetOption = isArray(option) ? option[0] : option;
550
+ let target = null;
551
+ if (targetOption == null ? void 0 : targetOption.value) {
552
+ const options = optionsArray.value.filter(
553
+ (item) => item.value === targetOption.value
554
+ );
555
+ if (options.length > 0) {
556
+ target = options[0].$el;
557
+ }
558
+ }
559
+ if (tooltipRef.value && target) {
560
+ const menu = (_d = (_c = (_b = (_a = tooltipRef.value) == null ? void 0 : _a.popperRef) == null ? void 0 : _b.contentRef) == null ? void 0 : _c.querySelector) == null ? void 0 : _d.call(
561
+ _c,
562
+ `.${nsSelect.be("dropdown", "wrap")}`
563
+ );
564
+ if (menu) {
565
+ scrollIntoView(menu, target);
566
+ }
567
+ }
568
+ (_e = scrollbarRef.value) == null ? void 0 : _e.handleScroll();
569
+ };
570
+ const onOptionCreate = (vm) => {
571
+ states.options.set(vm.value, vm);
572
+ states.cachedOptions.set(vm.value, vm);
573
+ vm.disabled && states.disabledOptions.set(vm.value, vm);
574
+ };
575
+ const onOptionDestroy = (key, vm) => {
576
+ if (states.options.get(key) === vm) {
577
+ states.options.delete(key);
578
+ }
579
+ };
580
+ const {
581
+ handleCompositionStart,
582
+ handleCompositionUpdate,
583
+ handleCompositionEnd
584
+ } = useInput((e) => onInput(e));
585
+ const popperRef = computed(() => {
586
+ var _a, _b;
587
+ return (_b = (_a = tooltipRef.value) == null ? void 0 : _a.popperRef) == null ? void 0 : _b.contentRef;
588
+ });
589
+ const handleMenuEnter = () => {
590
+ nextTick(() => scrollToOption(states.selected));
591
+ };
592
+ const focus = () => {
593
+ var _a;
594
+ (_a = inputRef.value) == null ? void 0 : _a.focus();
595
+ };
596
+ const blur = () => {
597
+ handleClickOutside();
598
+ };
599
+ const handleClearClick = (event) => {
600
+ deleteSelected(event);
601
+ };
602
+ const handleClickOutside = (event) => {
603
+ expanded.value = false;
604
+ if (isFocused.value) {
605
+ const _event = new FocusEvent("focus", event);
606
+ nextTick(() => handleBlur(_event));
607
+ }
608
+ };
609
+ const handleEsc = () => {
610
+ if (states.inputValue.length > 0) {
611
+ states.inputValue = "";
612
+ } else {
613
+ expanded.value = false;
614
+ }
615
+ };
616
+ const toggleMenu = () => {
617
+ if (selectDisabled.value) return;
618
+ if (states.menuVisibleOnFocus) {
619
+ states.menuVisibleOnFocus = false;
620
+ } else {
621
+ expanded.value = !expanded.value;
622
+ }
623
+ };
624
+ const selectOption = () => {
625
+ if (!expanded.value) {
626
+ toggleMenu();
627
+ } else {
628
+ if (optionsArray.value[states.hoveringIndex]) {
629
+ handleOptionSelect(optionsArray.value[states.hoveringIndex]);
630
+ }
631
+ }
632
+ };
633
+ const getValueKey = (item) => {
634
+ return isObject(item.value) ? get(item.value, props.valueKey) : item.value;
635
+ };
636
+ const optionsAllDisabled = computed(
637
+ () => optionsArray.value.filter((option) => option.visible).every((option) => option.disabled)
638
+ );
639
+ const showTagList = computed(() => {
640
+ if (!props.multiple) {
641
+ return [];
642
+ }
643
+ return props.collapseTags ? states.selected.slice(0, props.maxCollapseTags) : states.selected;
644
+ });
645
+ const collapseTagList = computed(() => {
646
+ if (!props.multiple) {
647
+ return [];
648
+ }
649
+ return props.collapseTags ? states.selected.slice(props.maxCollapseTags) : [];
650
+ });
651
+ const navigateOptions = (direction) => {
652
+ if (!expanded.value) {
653
+ expanded.value = true;
654
+ return;
655
+ }
656
+ if (states.options.size === 0 || filteredOptionsCount.value === 0) return;
657
+ if (!optionsAllDisabled.value) {
658
+ if (direction === "next") {
659
+ states.hoveringIndex++;
660
+ if (states.hoveringIndex === states.options.size) {
661
+ states.hoveringIndex = 0;
662
+ }
663
+ } else if (direction === "prev") {
664
+ states.hoveringIndex--;
665
+ if (states.hoveringIndex < 0) {
666
+ states.hoveringIndex = states.options.size - 1;
667
+ }
668
+ }
669
+ const option = optionsArray.value[states.hoveringIndex];
670
+ if (option.disabled === true || option.states.groupDisabled === true || !option.visible) {
671
+ navigateOptions(direction);
672
+ }
673
+ nextTick(() => scrollToOption(hoverOption.value));
674
+ }
675
+ };
676
+ const getGapWidth = () => {
677
+ if (!selectionRef.value) return 0;
678
+ const style = window.getComputedStyle(selectionRef.value);
679
+ return Number.parseFloat(style.gap || "6px");
680
+ };
681
+ const tagStyle = computed(() => {
682
+ const gapWidth = getGapWidth();
683
+ const maxWidth = collapseItemRef.value && props.maxCollapseTags === 1 ? states.selectionWidth - states.collapseItemWidth - gapWidth : states.selectionWidth;
684
+ return { maxWidth: `${maxWidth}px` };
685
+ });
686
+ const collapseTagStyle = computed(() => {
687
+ return { maxWidth: `${states.selectionWidth}px` };
688
+ });
689
+ const inputStyle = computed(() => ({
690
+ width: `${Math.max(states.calculatorWidth, MINIMUM_INPUT_WIDTH)}px`
691
+ }));
692
+ if (props.multiple && !isArray(props.modelValue)) {
693
+ emit(UPDATE_MODEL_EVENT, []);
694
+ }
695
+ if (!props.multiple && isArray(props.modelValue)) {
696
+ emit(UPDATE_MODEL_EVENT, "");
697
+ }
698
+ const clearTags = () => {
699
+ states.selectedLabel = "";
700
+ states.doRequest = true;
701
+ states.previousQuery = false;
702
+ handleQueryChange("");
703
+ emit(UPDATE_MODEL_EVENT, null);
704
+ if (typeof props.modelValue === "undefined") {
705
+ emit("change", null, null);
706
+ } else {
707
+ emit("change", null, props.modelValue);
708
+ }
709
+ };
710
+ useResizeObserver(selectionRef, resetSelectionWidth);
711
+ useResizeObserver(calculatorRef, resetCalculatorWidth);
712
+ useResizeObserver(menuRef, updateTooltip);
713
+ useResizeObserver(wrapperRef, updateTooltip);
714
+ useResizeObserver(collapseItemRef, resetCollapseItemWidth);
715
+ onMounted(() => {
716
+ states.doRequest = false;
717
+ if (props.loadOnCreate) {
718
+ states.previousQuery = false;
719
+ handleQueryChange("");
720
+ } else {
721
+ states.doRequest = true;
722
+ }
723
+ setSelected();
724
+ });
725
+ return {
726
+ inputId,
727
+ contentId,
728
+ nsSelect,
729
+ nsInput,
730
+ states,
731
+ isFocused,
732
+ expanded,
733
+ optionsArray,
734
+ hoverOption,
735
+ selectSize,
736
+ filteredOptionsCount,
737
+ resetCalculatorWidth,
738
+ updateTooltip,
739
+ debouncedOnInputChange,
740
+ onInput,
741
+ deletePrevTag,
742
+ deleteTag,
743
+ deleteSelected,
744
+ handleOptionSelect,
745
+ scrollToOption,
746
+ hasModelValue,
747
+ shouldShowPlaceholder,
748
+ currentPlaceholder,
749
+ showClose,
750
+ iconReverse,
751
+ validateState,
752
+ validateIcon,
753
+ showNewOption,
754
+ updateOptions,
755
+ collapseTagSize,
756
+ setSelected,
757
+ selectDisabled,
758
+ emptyText,
759
+ handleCompositionStart,
760
+ handleCompositionUpdate,
761
+ handleCompositionEnd,
762
+ onOptionCreate,
763
+ onOptionDestroy,
764
+ handleMenuEnter,
765
+ handleFocus,
766
+ focus,
767
+ blur,
768
+ handleBlur,
769
+ handleClearClick,
770
+ handleClickOutside,
771
+ handleEsc,
772
+ toggleMenu,
773
+ selectOption,
774
+ getValueKey,
775
+ navigateOptions,
776
+ dropdownMenuVisible,
777
+ showTagList,
778
+ collapseTagList,
779
+ clearTags,
780
+ suggestionsList,
781
+ newItem,
782
+ myId,
783
+ // computed style
784
+ tagStyle,
785
+ collapseTagStyle,
786
+ inputStyle,
787
+ // DOM ref
788
+ popperRef,
789
+ inputRef,
790
+ tooltipRef,
791
+ calculatorRef,
792
+ suffixRef,
793
+ selectRef,
794
+ wrapperRef,
795
+ selectionRef,
796
+ scrollbarRef,
797
+ menuRef,
798
+ collapseItemRef
799
+ };
800
+ };
801
+ export {
802
+ useSelect
803
+ };