mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-11 19:22:31 +08:00
chore(client/ts): fix errors related to autocomplete
This commit is contained in:
parent
e4053de735
commit
ffd609e0c5
@ -1,11 +1,19 @@
|
|||||||
|
import { AttributeType } from "../entities/fattribute.js";
|
||||||
import server from "./server.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 $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 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?
|
* @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")) {
|
if (!$el.hasClass("aa-input")) {
|
||||||
$el.autocomplete({
|
$el.autocomplete({
|
||||||
appendTo: document.querySelector('body'),
|
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")) {
|
if ($el.hasClass("aa-input")) {
|
||||||
// we reinit every time because autocomplete seems to have a bug where it retains state from last
|
// we reinit every time because autocomplete seems to have a bug where it retains state from last
|
||||||
// open even though the value was reset
|
// open even though the value was reset
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
import server from "./server.js";
|
import server from "./server.js";
|
||||||
|
|
||||||
type OptionValue = string;
|
type OptionValue = number | string;
|
||||||
|
|
||||||
class Options {
|
class Options {
|
||||||
initializedPromise: Promise<void>;
|
initializedPromise: Promise<void>;
|
||||||
|
18
src/public/app/types.d.ts
vendored
18
src/public/app/types.d.ts
vendored
@ -47,8 +47,24 @@ declare global {
|
|||||||
glob?: CustomGlobals;
|
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 {
|
interface JQuery {
|
||||||
// autocomplete: (action: "close") => void;
|
autocomplete: (action: "close" | "open" | "destroy" | AutoCompleteConfig, args?: AutoCompleteArg[]) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
var logError: (message: string) => void;
|
var logError: (message: string) => void;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user