ads-nuxt 0.6.2 → 0.6.3
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.
|
@@ -147,7 +147,7 @@ const props = withDefaults(
|
|
|
147
147
|
panelWidthClass?: string;
|
|
148
148
|
/**
|
|
149
149
|
* Ação de cadastrar no rodapé da lista, com ícone de adicionar. `{query}` vira a busca atual,
|
|
150
|
-
* ex.: "Cadastrar {query}". Sem valor, a ação não aparece.
|
|
150
|
+
* ex.: "Cadastrar {query}". Sem valor, com busca vazia ou com texto igual a uma opção, a ação não aparece.
|
|
151
151
|
*/
|
|
152
152
|
addLabel?: string;
|
|
153
153
|
}>(),
|
|
@@ -125,7 +125,7 @@ const props = withDefaults(
|
|
|
125
125
|
widthClass?: string;
|
|
126
126
|
/**
|
|
127
127
|
* Ação de cadastrar no rodapé, com ícone de adicionar. `{query}` vira a busca atual.
|
|
128
|
-
* Sem valor, a ação não aparece.
|
|
128
|
+
* Sem valor, com busca vazia ou com texto igual a uma opção, a ação não aparece.
|
|
129
129
|
*/
|
|
130
130
|
addLabel?: string;
|
|
131
131
|
}>(),
|
|
@@ -148,11 +148,22 @@ const emit = defineEmits<{
|
|
|
148
148
|
add: [query: string];
|
|
149
149
|
}>();
|
|
150
150
|
|
|
151
|
-
|
|
151
|
+
const queryMatchesOption = (typed: string): boolean => {
|
|
152
|
+
const key = typed.toLocaleLowerCase("pt-BR");
|
|
153
|
+
return props.options.some((option) => {
|
|
154
|
+
const label = option.label.trim().toLocaleLowerCase("pt-BR");
|
|
155
|
+
const value = String(option.value).trim().toLocaleLowerCase("pt-BR");
|
|
156
|
+
return label === key || value === key;
|
|
157
|
+
});
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
/** A ação só aparece com texto na busca e se esse texto ainda não é uma opção. */
|
|
152
161
|
const addText = computed(() => {
|
|
153
162
|
if (!props.addLabel) return "";
|
|
154
|
-
const
|
|
155
|
-
|
|
163
|
+
const typed = query.value.trim();
|
|
164
|
+
if (props.addLabel.includes("{query}") && !typed) return "";
|
|
165
|
+
if (typed && queryMatchesOption(typed)) return "";
|
|
166
|
+
return props.addLabel.replaceAll("{query}", typed).replace(/\s+/g, " ").trim();
|
|
156
167
|
});
|
|
157
168
|
|
|
158
169
|
const groups = computed(() => groupFilterOptions(props.options, query.value));
|