= {};
const allowedInputs = [
'zn-input',
'zn-select',
'zn-query-builder',
'zn-multiselect',
'zn-params-select',
'zn-datepicker',
'input',
'select',
'textarea',
'zn-cols',
'zn-input-group',
];
const collect = (element: Element): void => {
if (!allowedInputs.includes(element.tagName.toLowerCase())) return;
const input = element as AllowedInputElement;
const value: unknown = typeof input.value === 'string' ? input.value.trim() : input.value;
const name = input.name || element.getAttribute('name');
if (name) {
params[name] = value;
}
};
const slots = this.shadowRoot?.querySelectorAll('slot');
slots?.forEach((slot) => {
slot.assignedElements({flatten: true}).forEach((element) => {
collect(element);
element.querySelectorAll(allowedInputs.join(',')).forEach((descendant) => collect(descendant));
});
});
return params;
}
handleInput = (e: Event) => {
const input = e.target as ZnInput;
this.value = input.value as string;
this._formController.updateValidity();
if (this._searchTimeout) {
window.clearTimeout(this._searchTimeout);
}
this._searchTimeout = window.setTimeout(() => {
this.emitSearchChange();
}, this.debounceDelay);
}
handleClear = () => {
if (this._searchTimeout) {
window.clearTimeout(this._searchTimeout);
}
this.value = "";
const input = this.shadowRoot?.querySelector('zn-input');
if (input) {
input.value = "";
}
this._formController.updateValidity();
this.emitSearchChange();
}
disconnectedCallback() {
super.disconnectedCallback();
if (this._searchTimeout) {
window.clearTimeout(this._searchTimeout);
}
}
/**
* Emit the search change event with form data
*/
private emitSearchChange() {
const formData = this.getFormData();
this.emit('zn-search-change', {
detail: {
value: this.value.trim(),
formData: formData,
searchUri: this.searchUri
}
});
}
render() {
return html`
${this.helpText ? html`
` : nothing}
`;
}
}