From 2690256f275c8c62fd942aeb92ab309ebecc1c0f Mon Sep 17 00:00:00 2001 From: JYC333 <22962980+JYC333@users.noreply.github.com> Date: Mon, 9 Mar 2026 17:17:12 +0000 Subject: [PATCH] refactor: fix missing function def --- .../client/src/services/attribute_autocomplete.ts | 9 +++++---- apps/client/src/services/autocomplete_core.ts | 15 +++++++++++++++ apps/client/src/services/note_autocomplete.ts | 5 +++-- 3 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 apps/client/src/services/autocomplete_core.ts diff --git a/apps/client/src/services/attribute_autocomplete.ts b/apps/client/src/services/attribute_autocomplete.ts index 37fad01b51..c69fb32983 100644 --- a/apps/client/src/services/attribute_autocomplete.ts +++ b/apps/client/src/services/attribute_autocomplete.ts @@ -2,6 +2,7 @@ import type { AutocompleteApi as CoreAutocompleteApi, BaseItem } from "@algolia/ import { createAutocomplete } from "@algolia/autocomplete-core"; import type { AttributeType } from "../entities/fattribute.js"; +import { withHeadlessSourceDefaults } from "./autocomplete_core.js"; import server from "./server.js"; // --------------------------------------------------------------------------- @@ -133,7 +134,7 @@ function initAttributeNameAutocomplete({ $el, attributeType, open, onValueChange getSources({ query }) { return [ - { + withHeadlessSourceDefaults({ sourceId: "attribute-names", getItems() { const type = typeof attributeType === "function" ? attributeType() : attributeType; @@ -150,7 +151,7 @@ function initAttributeNameAutocomplete({ $el, attributeType, open, onValueChange autocomplete.setIsOpen(false); onValueChange?.(item.name); }, - }, + }), ]; }, @@ -325,7 +326,7 @@ function initLabelValueAutocomplete({ $el, open, nameCallback, onValueChange }: getSources({ query }) { return [ - { + withHeadlessSourceDefaults({ sourceId: "attribute-values", async getItems() { const attributeName = nameCallback ? nameCallback() : ""; @@ -348,7 +349,7 @@ function initLabelValueAutocomplete({ $el, open, nameCallback, onValueChange }: onSelect({ item }) { handleSelect(item); }, - }, + }), ]; }, diff --git a/apps/client/src/services/autocomplete_core.ts b/apps/client/src/services/autocomplete_core.ts new file mode 100644 index 0000000000..7332f59fab --- /dev/null +++ b/apps/client/src/services/autocomplete_core.ts @@ -0,0 +1,15 @@ +import type { AutocompleteSource, BaseItem } from "@algolia/autocomplete-core"; + +export function withHeadlessSourceDefaults( + source: AutocompleteSource +): AutocompleteSource { + return { + getItemUrl() { + return undefined; + }, + onActive() { + // Headless consumers handle highlight side effects themselves. + }, + ...source + }; +} diff --git a/apps/client/src/services/note_autocomplete.ts b/apps/client/src/services/note_autocomplete.ts index 265dbee0e6..7b061d11b7 100644 --- a/apps/client/src/services/note_autocomplete.ts +++ b/apps/client/src/services/note_autocomplete.ts @@ -3,6 +3,7 @@ import { createAutocomplete } from "@algolia/autocomplete-core"; import type { MentionFeedObjectItem } from "@triliumnext/ckeditor5"; import appContext from "../components/app_context.js"; +import { withHeadlessSourceDefaults } from "./autocomplete_core.js"; import commandRegistry from "./command_registry.js"; import froca from "./froca.js"; import { t } from "./i18n.js"; @@ -201,7 +202,7 @@ function renderSuggestion(item: Suggestion): string { } function createSuggestionSource(options: Options, onSelectItem: (item: Suggestion) => void) { - return { + return withHeadlessSourceDefaults({ sourceId: "note-suggestions", async getItems({ query }: { query: string }) { return await fetchResolvedSuggestions(query, options); @@ -212,7 +213,7 @@ function createSuggestionSource(options: Options, onSelectItem: (item: Suggestio onSelect({ item }: { item: Suggestion }) { void onSelectItem(item); } - }; + }); } function renderItems(