mirror of
https://github.com/zadam/trilium.git
synced 2026-03-13 11:53:38 +01:00
refactor: fix missing function def
This commit is contained in:
parent
fb3826552a
commit
5223e2ac86
@ -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<NameItem>({
|
||||
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<NameItem>({
|
||||
sourceId: "attribute-values",
|
||||
async getItems() {
|
||||
const attributeName = nameCallback ? nameCallback() : "";
|
||||
@ -348,7 +349,7 @@ function initLabelValueAutocomplete({ $el, open, nameCallback, onValueChange }:
|
||||
onSelect({ item }) {
|
||||
handleSelect(item);
|
||||
},
|
||||
},
|
||||
}),
|
||||
];
|
||||
},
|
||||
|
||||
|
||||
15
apps/client/src/services/autocomplete_core.ts
Normal file
15
apps/client/src/services/autocomplete_core.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import type { AutocompleteSource, BaseItem } from "@algolia/autocomplete-core";
|
||||
|
||||
export function withHeadlessSourceDefaults<TItem extends BaseItem>(
|
||||
source: AutocompleteSource<TItem>
|
||||
): AutocompleteSource<TItem> {
|
||||
return {
|
||||
getItemUrl() {
|
||||
return undefined;
|
||||
},
|
||||
onActive() {
|
||||
// Headless consumers handle highlight side effects themselves.
|
||||
},
|
||||
...source
|
||||
};
|
||||
}
|
||||
@ -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<Suggestion>({
|
||||
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(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user