| import type { CachedHistoryListRow } from '../storage/cachedHistoryStore'; |
| import { initQueryHistoryDropdown } from './queryHistory'; |
|
|
| |
| export function createMruListMirror(loadList: () => Promise<CachedHistoryListRow[]>): { |
| getEntries: () => CachedHistoryListRow[]; |
| refresh: () => Promise<void>; |
| } { |
| let rows: CachedHistoryListRow[] = []; |
| return { |
| getEntries: () => rows, |
| refresh: async () => { |
| rows = await loadList(); |
| }, |
| }; |
| } |
|
|
| export type CachedHistorySelectContext = { |
| |
| refreshList: () => Promise<void>; |
| }; |
|
|
| export type InitCachedHistoryQueryDropdownOptions = { |
| dropdownId: string; |
| historyButton: HTMLElement | null; |
| clickOutsideRoot: HTMLElement | null; |
| listMru: () => Promise<CachedHistoryListRow[]>; |
| |
| |
| |
| |
| |
| onSelectEntry: ( |
| contentKey: string, |
| shouldTouch: boolean | undefined, |
| ctx: CachedHistorySelectContext |
| ) => void | Promise<void>; |
| onRemove: (contentKey: string) => void | Promise<void>; |
| onPromote: (contentKey: string) => void | Promise<void>; |
| }; |
|
|
| |
| |
| |
| |
| export function initCachedHistoryQueryDropdown( |
| options: InitCachedHistoryQueryDropdownOptions |
| ): { refreshList: () => Promise<void> } { |
| const mirror = createMruListMirror(options.listMru); |
| const ctx: CachedHistorySelectContext = { |
| refreshList: () => mirror.refresh(), |
| }; |
| initQueryHistoryDropdown({ |
| input: null, |
| dropdownId: options.dropdownId, |
| getHistoryEntries: () => |
| mirror.getEntries().map((r) => ({ id: r.contentKey, label: r.listLabel })), |
| refreshHistoryItems: () => mirror.refresh(), |
| openDropdownOnFocusInput: false, |
| filterHistoryByInput: false, |
| onSelect: () => {}, |
| fillInputOnSelect: false, |
| onHistorySelect: (contentKey, shouldTouch) => { |
| void Promise.resolve(options.onSelectEntry(contentKey, shouldTouch, ctx)); |
| }, |
| onRemove: options.onRemove, |
| onPromote: options.onPromote, |
| historyButton: options.historyButton, |
| clickOutsideRoot: options.clickOutsideRoot, |
| applyHistoryOnHover: true, |
| }); |
| void mirror.refresh(); |
| return { refreshList: ctx.refreshList }; |
| } |
|
|