fix: anchor public pickers and preserve native Vue refs
This commit is contained in:
@@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user