mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-27 03:06:41 +00:00
Use ignoreDiacritics in fuse library (#24041)
This commit is contained in:
parent
ad561b885b
commit
173725f011
@ -1,8 +1,6 @@
|
|||||||
import type { IFuseOptions } from "fuse.js";
|
import type { IFuseOptions } from "fuse.js";
|
||||||
import Fuse from "fuse.js";
|
import Fuse from "fuse.js";
|
||||||
import { stripDiacritics } from "../../../src/common/string/strip-diacritics";
|
|
||||||
import type { StoreAddon } from "../../../src/data/supervisor/store";
|
import type { StoreAddon } from "../../../src/data/supervisor/store";
|
||||||
import { getStripDiacriticsFn } from "../../../src/util/fuse";
|
|
||||||
|
|
||||||
export function filterAndSort(addons: StoreAddon[], filter: string) {
|
export function filterAndSort(addons: StoreAddon[], filter: string) {
|
||||||
const options: IFuseOptions<StoreAddon> = {
|
const options: IFuseOptions<StoreAddon> = {
|
||||||
@ -10,8 +8,8 @@ export function filterAndSort(addons: StoreAddon[], filter: string) {
|
|||||||
isCaseSensitive: false,
|
isCaseSensitive: false,
|
||||||
minMatchCharLength: Math.min(filter.length, 2),
|
minMatchCharLength: Math.min(filter.length, 2),
|
||||||
threshold: 0.2,
|
threshold: 0.2,
|
||||||
getFn: getStripDiacriticsFn,
|
ignoreDiacritics: true,
|
||||||
};
|
};
|
||||||
const fuse = new Fuse(addons, options);
|
const fuse = new Fuse(addons, options);
|
||||||
return fuse.search(stripDiacritics(filter)).map((result) => result.item);
|
return fuse.search(filter).map((result) => result.item);
|
||||||
}
|
}
|
||||||
|
@ -110,7 +110,7 @@
|
|||||||
"dialog-polyfill": "0.5.6",
|
"dialog-polyfill": "0.5.6",
|
||||||
"echarts": "5.6.0",
|
"echarts": "5.6.0",
|
||||||
"element-internals-polyfill": "1.3.13",
|
"element-internals-polyfill": "1.3.13",
|
||||||
"fuse.js": "7.0.0",
|
"fuse.js": "7.1.0",
|
||||||
"google-timezones-json": "1.2.0",
|
"google-timezones-json": "1.2.0",
|
||||||
"gulp-zopfli-green": "6.0.2",
|
"gulp-zopfli-green": "6.0.2",
|
||||||
"hls.js": "patch:hls.js@npm%3A1.5.7#~/.yarn/patches/hls.js-npm-1.5.7-f5bbd3d060.patch",
|
"hls.js": "patch:hls.js@npm%3A1.5.7#~/.yarn/patches/hls.js-npm-1.5.7-f5bbd3d060.patch",
|
||||||
|
@ -11,17 +11,16 @@ import memoizeOne from "memoize-one";
|
|||||||
import { fireEvent } from "../../../common/dom/fire_event";
|
import { fireEvent } from "../../../common/dom/fire_event";
|
||||||
import { computeDomain } from "../../../common/entity/compute_domain";
|
import { computeDomain } from "../../../common/entity/compute_domain";
|
||||||
import { stringCompare } from "../../../common/string/compare";
|
import { stringCompare } from "../../../common/string/compare";
|
||||||
import { stripDiacritics } from "../../../common/string/strip-diacritics";
|
|
||||||
import type { LocalizeFunc } from "../../../common/translations/localize";
|
import type { LocalizeFunc } from "../../../common/translations/localize";
|
||||||
import { deepEqual } from "../../../common/util/deep-equal";
|
import { deepEqual } from "../../../common/util/deep-equal";
|
||||||
import "../../../components/ha-dialog";
|
import "../../../components/ha-dialog";
|
||||||
import type { HaDialog } from "../../../components/ha-dialog";
|
import type { HaDialog } from "../../../components/ha-dialog";
|
||||||
import "../../../components/ha-dialog-header";
|
import "../../../components/ha-dialog-header";
|
||||||
import "../../../components/ha-md-divider";
|
|
||||||
import "../../../components/ha-domain-icon";
|
import "../../../components/ha-domain-icon";
|
||||||
import "../../../components/ha-icon-button";
|
import "../../../components/ha-icon-button";
|
||||||
import "../../../components/ha-icon-button-prev";
|
import "../../../components/ha-icon-button-prev";
|
||||||
import "../../../components/ha-icon-next";
|
import "../../../components/ha-icon-next";
|
||||||
|
import "../../../components/ha-md-divider";
|
||||||
import "../../../components/ha-md-list";
|
import "../../../components/ha-md-list";
|
||||||
import "../../../components/ha-md-list-item";
|
import "../../../components/ha-md-list-item";
|
||||||
import "../../../components/ha-service-icon";
|
import "../../../components/ha-service-icon";
|
||||||
@ -45,7 +44,6 @@ import { TRIGGER_GROUPS, TRIGGER_ICONS } from "../../../data/trigger";
|
|||||||
import type { HassDialog } from "../../../dialogs/make-dialog-manager";
|
import type { HassDialog } from "../../../dialogs/make-dialog-manager";
|
||||||
import { haStyle, haStyleDialog } from "../../../resources/styles";
|
import { haStyle, haStyleDialog } from "../../../resources/styles";
|
||||||
import type { HomeAssistant } from "../../../types";
|
import type { HomeAssistant } from "../../../types";
|
||||||
import { getStripDiacriticsFn } from "../../../util/fuse";
|
|
||||||
import type { AddAutomationElementDialogParams } from "./show-add-automation-element-dialog";
|
import type { AddAutomationElementDialogParams } from "./show-add-automation-element-dialog";
|
||||||
import { PASTE_VALUE } from "./show-add-automation-element-dialog";
|
import { PASTE_VALUE } from "./show-add-automation-element-dialog";
|
||||||
|
|
||||||
@ -202,10 +200,10 @@ class DialogAddAutomationElement extends LitElement implements HassDialog {
|
|||||||
ignoreLocation: true,
|
ignoreLocation: true,
|
||||||
minMatchCharLength: Math.min(filter.length, 2),
|
minMatchCharLength: Math.min(filter.length, 2),
|
||||||
threshold: 0.2,
|
threshold: 0.2,
|
||||||
getFn: getStripDiacriticsFn,
|
ignoreDiacritics: true,
|
||||||
};
|
};
|
||||||
const fuse = new Fuse(items, options);
|
const fuse = new Fuse(items, options);
|
||||||
return fuse.search(stripDiacritics(filter)).map((result) => result.item);
|
return fuse.search(filter).map((result) => result.item);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ import type { LocalizeFunc } from "../../../common/translations/localize";
|
|||||||
import { createCloseHeading } from "../../../components/ha-dialog";
|
import { createCloseHeading } from "../../../components/ha-dialog";
|
||||||
import "../../../components/ha-icon-button-prev";
|
import "../../../components/ha-icon-button-prev";
|
||||||
import "../../../components/search-input";
|
import "../../../components/search-input";
|
||||||
|
import { getConfigEntries } from "../../../data/config_entries";
|
||||||
import { fetchConfigFlowInProgress } from "../../../data/config_flow";
|
import { fetchConfigFlowInProgress } from "../../../data/config_flow";
|
||||||
import type { DataEntryFlowProgress } from "../../../data/data_entry_flow";
|
import type { DataEntryFlowProgress } from "../../../data/data_entry_flow";
|
||||||
import {
|
import {
|
||||||
@ -49,9 +50,6 @@ import "./ha-domain-integrations";
|
|||||||
import "./ha-integration-list-item";
|
import "./ha-integration-list-item";
|
||||||
import type { AddIntegrationDialogParams } from "./show-add-integration-dialog";
|
import type { AddIntegrationDialogParams } from "./show-add-integration-dialog";
|
||||||
import { showYamlIntegrationDialog } from "./show-add-integration-dialog";
|
import { showYamlIntegrationDialog } from "./show-add-integration-dialog";
|
||||||
import { getConfigEntries } from "../../../data/config_entries";
|
|
||||||
import { stripDiacritics } from "../../../common/string/strip-diacritics";
|
|
||||||
import { getStripDiacriticsFn } from "../../../util/fuse";
|
|
||||||
|
|
||||||
export interface IntegrationListItem {
|
export interface IntegrationListItem {
|
||||||
name: string;
|
name: string;
|
||||||
@ -256,7 +254,7 @@ class AddIntegrationDialog extends LitElement {
|
|||||||
isCaseSensitive: false,
|
isCaseSensitive: false,
|
||||||
minMatchCharLength: Math.min(filter.length, 2),
|
minMatchCharLength: Math.min(filter.length, 2),
|
||||||
threshold: 0.2,
|
threshold: 0.2,
|
||||||
getFn: getStripDiacriticsFn,
|
ignoreDiacritics: true,
|
||||||
};
|
};
|
||||||
const helpers = Object.entries(h).map(([domain, integration]) => ({
|
const helpers = Object.entries(h).map(([domain, integration]) => ({
|
||||||
domain,
|
domain,
|
||||||
@ -266,16 +264,15 @@ class AddIntegrationDialog extends LitElement {
|
|||||||
is_built_in: integration.is_built_in !== false,
|
is_built_in: integration.is_built_in !== false,
|
||||||
cloud: integration.iot_class?.startsWith("cloud_"),
|
cloud: integration.iot_class?.startsWith("cloud_"),
|
||||||
}));
|
}));
|
||||||
const normalizedFilter = stripDiacritics(filter);
|
|
||||||
return [
|
return [
|
||||||
...new Fuse(integrations, options)
|
...new Fuse(integrations, options)
|
||||||
.search(normalizedFilter)
|
.search(filter)
|
||||||
.map((result) => result.item),
|
.map((result) => result.item),
|
||||||
...new Fuse(yamlIntegrations, options)
|
...new Fuse(yamlIntegrations, options)
|
||||||
.search(normalizedFilter)
|
.search(filter)
|
||||||
.map((result) => result.item),
|
.map((result) => result.item),
|
||||||
...new Fuse(helpers, options)
|
...new Fuse(helpers, options)
|
||||||
.search(normalizedFilter)
|
.search(filter)
|
||||||
.map((result) => result.item),
|
.map((result) => result.item),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,6 @@ import {
|
|||||||
} from "../../../common/integrations/protocolIntegrationPicked";
|
} from "../../../common/integrations/protocolIntegrationPicked";
|
||||||
import { navigate } from "../../../common/navigate";
|
import { navigate } from "../../../common/navigate";
|
||||||
import { caseInsensitiveStringCompare } from "../../../common/string/compare";
|
import { caseInsensitiveStringCompare } from "../../../common/string/compare";
|
||||||
import { stripDiacritics } from "../../../common/string/strip-diacritics";
|
|
||||||
import { extractSearchParam } from "../../../common/url/search-params";
|
import { extractSearchParam } from "../../../common/url/search-params";
|
||||||
import { nextRender } from "../../../common/util/render-status";
|
import { nextRender } from "../../../common/util/render-status";
|
||||||
import "../../../components/ha-button-menu";
|
import "../../../components/ha-button-menu";
|
||||||
@ -32,6 +31,7 @@ import { getConfigFlowInProgressCollection } from "../../../data/config_flow";
|
|||||||
import { fetchDiagnosticHandlers } from "../../../data/diagnostics";
|
import { fetchDiagnosticHandlers } from "../../../data/diagnostics";
|
||||||
import type { EntityRegistryEntry } from "../../../data/entity_registry";
|
import type { EntityRegistryEntry } from "../../../data/entity_registry";
|
||||||
import { subscribeEntityRegistry } from "../../../data/entity_registry";
|
import { subscribeEntityRegistry } from "../../../data/entity_registry";
|
||||||
|
import { fetchEntitySourcesWithCache } from "../../../data/entity_sources";
|
||||||
import type {
|
import type {
|
||||||
IntegrationLogInfo,
|
IntegrationLogInfo,
|
||||||
IntegrationManifest,
|
IntegrationManifest,
|
||||||
@ -52,12 +52,13 @@ import {
|
|||||||
showAlertDialog,
|
showAlertDialog,
|
||||||
showConfirmationDialog,
|
showConfirmationDialog,
|
||||||
} from "../../../dialogs/generic/show-dialog-box";
|
} from "../../../dialogs/generic/show-dialog-box";
|
||||||
|
import type { ImprovDiscoveredDevice } from "../../../external_app/external_messaging";
|
||||||
import "../../../layouts/hass-loading-screen";
|
import "../../../layouts/hass-loading-screen";
|
||||||
import "../../../layouts/hass-tabs-subpage";
|
import "../../../layouts/hass-tabs-subpage";
|
||||||
|
import { KeyboardShortcutMixin } from "../../../mixins/keyboard-shortcut-mixin";
|
||||||
import { SubscribeMixin } from "../../../mixins/subscribe-mixin";
|
import { SubscribeMixin } from "../../../mixins/subscribe-mixin";
|
||||||
import { haStyle } from "../../../resources/styles";
|
import { haStyle } from "../../../resources/styles";
|
||||||
import type { HomeAssistant, Route } from "../../../types";
|
import type { HomeAssistant, Route } from "../../../types";
|
||||||
import { getStripDiacriticsFn } from "../../../util/fuse";
|
|
||||||
import { configSections } from "../ha-panel-config";
|
import { configSections } from "../ha-panel-config";
|
||||||
import { isHelperDomain } from "../helpers/const";
|
import { isHelperDomain } from "../helpers/const";
|
||||||
import "./ha-config-flow-card";
|
import "./ha-config-flow-card";
|
||||||
@ -68,9 +69,6 @@ import "./ha-integration-card";
|
|||||||
import type { HaIntegrationCard } from "./ha-integration-card";
|
import type { HaIntegrationCard } from "./ha-integration-card";
|
||||||
import "./ha-integration-overflow-menu";
|
import "./ha-integration-overflow-menu";
|
||||||
import { showAddIntegrationDialog } from "./show-add-integration-dialog";
|
import { showAddIntegrationDialog } from "./show-add-integration-dialog";
|
||||||
import { fetchEntitySourcesWithCache } from "../../../data/entity_sources";
|
|
||||||
import type { ImprovDiscoveredDevice } from "../../../external_app/external_messaging";
|
|
||||||
import { KeyboardShortcutMixin } from "../../../mixins/keyboard-shortcut-mixin";
|
|
||||||
|
|
||||||
export interface ConfigEntryExtended extends Omit<ConfigEntry, "entry_id"> {
|
export interface ConfigEntryExtended extends Omit<ConfigEntry, "entry_id"> {
|
||||||
entry_id?: string;
|
entry_id?: string;
|
||||||
@ -304,12 +302,10 @@ class HaConfigIntegrationsDashboard extends KeyboardShortcutMixin(
|
|||||||
isCaseSensitive: false,
|
isCaseSensitive: false,
|
||||||
minMatchCharLength: Math.min(filter.length, 2),
|
minMatchCharLength: Math.min(filter.length, 2),
|
||||||
threshold: 0.2,
|
threshold: 0.2,
|
||||||
getFn: getStripDiacriticsFn,
|
ignoreDiacritics: true,
|
||||||
};
|
};
|
||||||
const fuse = new Fuse(inProgress, options);
|
const fuse = new Fuse(inProgress, options);
|
||||||
filteredEntries = fuse
|
filteredEntries = fuse.search(filter).map((result) => result.item);
|
||||||
.search(stripDiacritics(filter))
|
|
||||||
.map((result) => result.item);
|
|
||||||
} else {
|
} else {
|
||||||
filteredEntries = inProgress;
|
filteredEntries = inProgress;
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ import memoizeOne from "memoize-one";
|
|||||||
import { storage } from "../../../../common/decorators/storage";
|
import { storage } from "../../../../common/decorators/storage";
|
||||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||||
import { stringCompare } from "../../../../common/string/compare";
|
import { stringCompare } from "../../../../common/string/compare";
|
||||||
import { stripDiacritics } from "../../../../common/string/strip-diacritics";
|
|
||||||
import "../../../../components/ha-circular-progress";
|
import "../../../../components/ha-circular-progress";
|
||||||
import "../../../../components/search-input";
|
import "../../../../components/search-input";
|
||||||
import { isUnavailableState } from "../../../../data/entity";
|
import { isUnavailableState } from "../../../../data/entity";
|
||||||
@ -23,7 +22,6 @@ import {
|
|||||||
getCustomBadgeEntry,
|
getCustomBadgeEntry,
|
||||||
} from "../../../../data/lovelace_custom_cards";
|
} from "../../../../data/lovelace_custom_cards";
|
||||||
import type { HomeAssistant } from "../../../../types";
|
import type { HomeAssistant } from "../../../../types";
|
||||||
import { getStripDiacriticsFn } from "../../../../util/fuse";
|
|
||||||
import {
|
import {
|
||||||
calcUnusedEntities,
|
calcUnusedEntities,
|
||||||
computeUsedEntities,
|
computeUsedEntities,
|
||||||
@ -82,12 +80,10 @@ export class HuiBadgePicker extends LitElement {
|
|||||||
isCaseSensitive: false,
|
isCaseSensitive: false,
|
||||||
minMatchCharLength: Math.min(filter.length, 2),
|
minMatchCharLength: Math.min(filter.length, 2),
|
||||||
threshold: 0.2,
|
threshold: 0.2,
|
||||||
getFn: getStripDiacriticsFn,
|
ignoreDiacritics: true,
|
||||||
};
|
};
|
||||||
const fuse = new Fuse(badges, options);
|
const fuse = new Fuse(badges, options);
|
||||||
badges = fuse
|
badges = fuse.search(filter).map((result) => result.item);
|
||||||
.search(stripDiacritics(filter))
|
|
||||||
.map((result) => result.item);
|
|
||||||
return badgeElements.filter((badgeElement: BadgeElement) =>
|
return badgeElements.filter((badgeElement: BadgeElement) =>
|
||||||
badges.includes(badgeElement.badge)
|
badges.includes(badgeElement.badge)
|
||||||
);
|
);
|
||||||
|
@ -10,7 +10,6 @@ import memoizeOne from "memoize-one";
|
|||||||
import { storage } from "../../../../common/decorators/storage";
|
import { storage } from "../../../../common/decorators/storage";
|
||||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||||
import { stringCompare } from "../../../../common/string/compare";
|
import { stringCompare } from "../../../../common/string/compare";
|
||||||
import { stripDiacritics } from "../../../../common/string/strip-diacritics";
|
|
||||||
import "../../../../components/ha-circular-progress";
|
import "../../../../components/ha-circular-progress";
|
||||||
import "../../../../components/search-input";
|
import "../../../../components/search-input";
|
||||||
import { isUnavailableState } from "../../../../data/entity";
|
import { isUnavailableState } from "../../../../data/entity";
|
||||||
@ -23,7 +22,6 @@ import {
|
|||||||
getCustomCardEntry,
|
getCustomCardEntry,
|
||||||
} from "../../../../data/lovelace_custom_cards";
|
} from "../../../../data/lovelace_custom_cards";
|
||||||
import type { HomeAssistant } from "../../../../types";
|
import type { HomeAssistant } from "../../../../types";
|
||||||
import { getStripDiacriticsFn } from "../../../../util/fuse";
|
|
||||||
import {
|
import {
|
||||||
calcUnusedEntities,
|
calcUnusedEntities,
|
||||||
computeUsedEntities,
|
computeUsedEntities,
|
||||||
@ -92,10 +90,10 @@ export class HuiCardPicker extends LitElement {
|
|||||||
isCaseSensitive: false,
|
isCaseSensitive: false,
|
||||||
minMatchCharLength: Math.min(filter.length, 2),
|
minMatchCharLength: Math.min(filter.length, 2),
|
||||||
threshold: 0.2,
|
threshold: 0.2,
|
||||||
getFn: getStripDiacriticsFn,
|
ignoreDiacritics: true,
|
||||||
};
|
};
|
||||||
const fuse = new Fuse(cards, options);
|
const fuse = new Fuse(cards, options);
|
||||||
cards = fuse.search(stripDiacritics(filter)).map((result) => result.item);
|
cards = fuse.search(filter).map((result) => result.item);
|
||||||
return cardElements.filter((cardElement: CardElement) =>
|
return cardElements.filter((cardElement: CardElement) =>
|
||||||
cards.includes(cardElement.card)
|
cards.includes(cardElement.card)
|
||||||
);
|
);
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
import Fuse from "fuse.js";
|
|
||||||
import { stripDiacritics } from "../common/string/strip-diacritics";
|
|
||||||
|
|
||||||
type GetFn = typeof Fuse.config.getFn;
|
|
||||||
|
|
||||||
export const getStripDiacriticsFn: GetFn = (obj, path) => {
|
|
||||||
const value = Fuse.config.getFn(obj, path);
|
|
||||||
if (Array.isArray(value)) {
|
|
||||||
return value.map((v) => stripDiacritics(v ?? ""));
|
|
||||||
}
|
|
||||||
return stripDiacritics((value as string | undefined) ?? "");
|
|
||||||
};
|
|
10
yarn.lock
10
yarn.lock
@ -8795,10 +8795,10 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"fuse.js@npm:7.0.0":
|
"fuse.js@npm:7.1.0":
|
||||||
version: 7.0.0
|
version: 7.1.0
|
||||||
resolution: "fuse.js@npm:7.0.0"
|
resolution: "fuse.js@npm:7.1.0"
|
||||||
checksum: 10/d75d35f2d61afa85b8248f9cbfc7d4df29ae47ea574a15ad5c3c2a41930c5ed78668346295508b59ec4929fcb1a5cd6d9a8c649b5a3bc8b18e515f4e4cb9809d
|
checksum: 10/9f9105e54372897a46cb3e04074f0db5bd0a428320d4618276a57e6142d7502235a556f05cf87aa3c5d6d9c6fdfa06b901b78379c48aa0951672ccbc4a1bfe70
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
@ -9402,7 +9402,7 @@ __metadata:
|
|||||||
eslint-plugin-wc: "npm:2.2.0"
|
eslint-plugin-wc: "npm:2.2.0"
|
||||||
fancy-log: "npm:2.0.0"
|
fancy-log: "npm:2.0.0"
|
||||||
fs-extra: "npm:11.3.0"
|
fs-extra: "npm:11.3.0"
|
||||||
fuse.js: "npm:7.0.0"
|
fuse.js: "npm:7.1.0"
|
||||||
glob: "npm:11.0.1"
|
glob: "npm:11.0.1"
|
||||||
google-timezones-json: "npm:1.2.0"
|
google-timezones-json: "npm:1.2.0"
|
||||||
gulp: "npm:5.0.0"
|
gulp: "npm:5.0.0"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user