Skip to content

Build your personal knowledge base with Trilium Notes

chore(client/ts): fix errors related to autocomplete

Elian Doranffd609e0c5c1
diff --git a/src/public/app/services/attribute_autocomplete.ts b/src/public/app/services/attribute_autocomplete.ts
index 04c601f461..0411299742 100644
--- a/src/public/app/services/attribute_autocomplete.ts
+++ b/src/public/app/services/attribute_autocomplete.ts
@@ -1,11 +1,19 @@
+import { AttributeType } from "../entities/fattribute.js";
import server from "./server.js";
+interface InitOptions {
+ $el: JQuery<HTMLElement>;
+ attributeType: AttributeType | (() => AttributeType);
+ open: boolean;
+ nameCallback: () => string;
+}
+
/**
* @param $el - element on which to init autocomplete
* @param attributeType - "relation" or "label" or callback providing one of those values as a type of autocompleted attributes
* @param open - should the autocomplete be opened after init?
*/
-function initAttributeNameAutocomplete({ $el, attributeType, open }) {
+function initAttributeNameAutocomplete({ $el, attributeType, open }: InitOptions) {
if (!$el.hasClass("aa-input")) {
$el.autocomplete({
appendTo: document.querySelector('body'),
@@ -39,7 +47,7 @@ function initAttributeNameAutocomplete({ $el, attributeType, open }) {
}
}
-async function initLabelValueAutocomplete({ $el, open, nameCallback }) {
+async function initLabelValueAutocomplete({ $el, open, nameCallback }: InitOptions) {
if ($el.hasClass("aa-input")) {
// we reinit every time because autocomplete seems to have a bug where it retains state from last
// open even though the value was reset
diff --git a/src/public/app/services/options.ts b/src/public/app/services/options.ts
index 23cddcfd91..138c0402a9 100644
--- a/src/public/app/services/options.ts
+++ b/src/public/app/services/options.ts
@@ -1,7 +1,7 @@
import server from "./server.js";
-type OptionValue = string;
+type OptionValue = number | string;
class Options {
initializedPromise: Promise<void>;
diff --git a/src/public/app/types.d.ts b/src/public/app/types.d.ts
index 705a16b3a3..4fb103b796 100644
--- a/src/public/app/types.d.ts
+++ b/src/public/app/types.d.ts
@@ -47,8 +47,24 @@ declare global {
glob?: CustomGlobals;
}
+ interface AutoCompleteConfig {
+ appendTo?: HTMLElement | null;
+ hint?: boolean;
+ openOnFocus?: boolean;
+ minLength?: number;
+ tabAutocomplete?: boolean
+ }
+
+ type AutoCompleteCallback = (values: AutoCompleteCallbackArgs[]) => void;
+
+ interface AutoCompleteArg {
+ displayKey: "name" | "value";
+ cache: boolean;
+ source: (term: string, cb: AutoCompleteCallback) => void
+ };
+
interface JQuery {
- // autocomplete: (action: "close") => void;
+ autocomplete: (action: "close" | "open" | "destroy" | AutoCompleteConfig, args?: AutoCompleteArg[]) => void;
}
var logError: (message: string) => void;