(elements?: QueryElement[], focusOnInput = true)
| 1138 | } |
| 1139 | |
| 1140 | async parseQuery(elements?: QueryElement[], focusOnInput = true) { |
| 1141 | this.#parseAbortController?.abort(); |
| 1142 | const { signal } = (this.#parseAbortController = new AbortController()); |
| 1143 | |
| 1144 | if (!elements) { |
| 1145 | elements = this.parseInputValue(); |
| 1146 | } else { |
| 1147 | const newInputValue = elements |
| 1148 | .map((item) => { |
| 1149 | if (item.type === "filter") return `${item.filter}:${item.value}`; |
| 1150 | return item.value; |
| 1151 | }) |
| 1152 | // Don't assume separator if a custom parser is specified |
| 1153 | .join(this.#usingCustomParser ? "" : " "); |
| 1154 | |
| 1155 | // When using in react, we need to update the prototype value so the dispatched `change` event does not get |
| 1156 | // discarded |
| 1157 | const prototypeValueSetter = Object.getOwnPropertyDescriptor( |
| 1158 | Object.getPrototypeOf(this.input), |
| 1159 | "value" |
| 1160 | )?.set; |
| 1161 | |
| 1162 | if (prototypeValueSetter) { |
| 1163 | prototypeValueSetter?.call(this.input, newInputValue); |
| 1164 | } else { |
| 1165 | this.input.value = newInputValue; |
| 1166 | } |
| 1167 | |
| 1168 | this.input.dispatchEvent(new Event("change", { bubbles: true })); |
| 1169 | } |
| 1170 | |
| 1171 | this.lastParsedQuery = this.input.value; |
| 1172 | |
| 1173 | await new Promise((resolve) => requestAnimationFrame(resolve)); |
| 1174 | |
| 1175 | if (signal.aborted) return; |
| 1176 | this.styleInputText(elements); |
| 1177 | if (focusOnInput) this.input.focus(); |
| 1178 | |
| 1179 | await new Promise((resolve) => setTimeout(resolve, 100)); |
| 1180 | if (signal.aborted) return; |
| 1181 | |
| 1182 | for (const provider of this.#searchItems.keys()) { |
| 1183 | this.#searchItemsMarkedForClearing.add(provider); |
| 1184 | } |
| 1185 | |
| 1186 | this.#filterItems.clear(); |
| 1187 | this.#filters.clear(); |
| 1188 | |
| 1189 | const event = new QueryEvent( |
| 1190 | elements, |
| 1191 | this.input.value, |
| 1192 | this.parsedMetadata |
| 1193 | ); |
| 1194 | this.dispatchEvent(event); |
| 1195 | |
| 1196 | // The sync effects of the QueryEvent should all have triggered by now, |
| 1197 | // meaning that any providers which did not clear their own search items |
no test coverage detected