@tagplus/components 5.2.19 → 5.3.0

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