diff --git a/src/public/app/services/attribute_autocomplete.ts b/src/public/app/services/attribute_autocomplete.ts index 04c601f46..041129974 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; + 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 23cddcfd9..138c0402a 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; diff --git a/src/public/app/types.d.ts b/src/public/app/types.d.ts index 705a16b3a..4fb103b79 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;