fix: anchor public pickers and preserve native Vue refs

This commit is contained in:
maoyingjie
2026-10-25 20:54:57 +08:00
parent 05c2f501a0
commit ff480c5fc3
8 changed files with 161 additions and 59 deletions
+16 -10
View File
@@ -1,15 +1,21 @@
/**
* Case- and accent-insensitive substring match, the equivalent of ICU
* "base" sensitivity for search: `Café` matches `cafe`, `STRASSE` matches
* `strasse` after compatibility normalisation.
*/
const fold = (value: string) => value.normalize("NFKD").replace(/\p{Mn}/gu, "");
/** Locale-aware base-sensitivity substring matching; no hand-written accent folding. */
export function createBaseContains(locale?: string) {
const collator = new Intl.Collator(locale, {
usage: "search",
sensitivity: "base",
});
return (text: string, query: string) => {
if (!query) return true;
return fold(text)
.toLocaleLowerCase(locale)
.includes(fold(query).toLocaleLowerCase(locale));
const characters = Array.from(text.normalize("NFC"));
const needle = query.normalize("NFC");
// Collation expansions (ß/ss, ligatures) need not have equal code-point lengths.
for (let start = 0; start < characters.length; start++) {
let candidate = "";
for (let end = start; end < characters.length; end++) {
candidate += characters[end];
if (collator.compare(candidate, needle) === 0) return true;
}
}
return false;
};
}