fix: apply state.xxx pattern and exports to regenerated modules
This commit is contained in:
+105
-105
@@ -1,12 +1,12 @@
|
||||
/* ObsiGate — Auto-extracted module */
|
||||
import { state } from './state.js';
|
||||
import { state } from './state.js';;
|
||||
// ---------------------------------------------------------------------------
|
||||
// Search History Service (localStorage, LIFO, max 50, dedup)
|
||||
// ---------------------------------------------------------------------------
|
||||
const SearchHistory = {
|
||||
_load() {
|
||||
try {
|
||||
const raw = localStorage.getItem(SEARCH_HISTORY_KEY);
|
||||
const raw = localStorage.getItem(state.SEARCH_HISTORY_KEY);
|
||||
return raw ? JSON.parse(raw) : [];
|
||||
} catch {
|
||||
return [];
|
||||
@@ -14,7 +14,7 @@ const SearchHistory = {
|
||||
},
|
||||
_save(entries) {
|
||||
try {
|
||||
localStorage.setItem(SEARCH_HISTORY_KEY, JSON.stringify(entries));
|
||||
localStorage.setItem(state.SEARCH_HISTORY_KEY, JSON.stringify(entries));
|
||||
} catch {}
|
||||
},
|
||||
getAll() {
|
||||
@@ -25,7 +25,7 @@ const SearchHistory = {
|
||||
const q = query.trim();
|
||||
let entries = this._load().filter((e) => e !== q);
|
||||
entries.unshift(q);
|
||||
if (entries.length > MAX_HISTORY_ENTRIES) entries = entries.slice(0, MAX_HISTORY_ENTRIES);
|
||||
if (entries.length > state.MAX_HISTORY_ENTRIES) entries = entries.slice(0, state.MAX_HISTORY_ENTRIES);
|
||||
this._save(entries);
|
||||
},
|
||||
remove(query) {
|
||||
@@ -167,8 +167,8 @@ const AutocompleteDropdown = {
|
||||
|
||||
hide() {
|
||||
if (this._dropdown) this._dropdown.hidden = true;
|
||||
dropdownActiveIndex = -1;
|
||||
dropdownItems = [];
|
||||
state.dropdownActiveIndex = -1;
|
||||
state.dropdownItems = [];
|
||||
},
|
||||
|
||||
isVisible() {
|
||||
@@ -179,9 +179,9 @@ const AutocompleteDropdown = {
|
||||
async populate(inputValue, cursorPos) {
|
||||
if (this._suppressNext) { this._suppressNext = false; return; }
|
||||
// Cancel previous suggestion request
|
||||
if (suggestAbortController) {
|
||||
suggestAbortController.abort();
|
||||
suggestAbortController = null;
|
||||
if (state.suggestAbortController) {
|
||||
state.suggestAbortController.abort();
|
||||
state.suggestAbortController = null;
|
||||
}
|
||||
|
||||
const ctx = QueryParser.getContext(inputValue, cursorPos);
|
||||
@@ -228,10 +228,10 @@ const AutocompleteDropdown = {
|
||||
},
|
||||
|
||||
async _fetchSuggestions(prefix, vault) {
|
||||
suggestAbortController = new AbortController();
|
||||
state.suggestAbortController = new AbortController();
|
||||
// Fetch titles
|
||||
try {
|
||||
const titlesRes = await api(`/api/suggest?q=${encodeURIComponent(prefix)}&vault=${encodeURIComponent(vault)}&limit=5`, { signal: suggestAbortController.signal });
|
||||
const titlesRes = await api(`/api/suggest?q=${encodeURIComponent(prefix)}&vault=${encodeURIComponent(vault)}&limit=5`, { signal: state.suggestAbortController.signal });
|
||||
this._renderTitles(titlesRes.suggestions || [], prefix);
|
||||
this._titlesSection.hidden = !(titlesRes.suggestions || []).length;
|
||||
if (titlesRes.suggestions?.length) this.show();
|
||||
@@ -241,7 +241,7 @@ const AutocompleteDropdown = {
|
||||
}
|
||||
// Fetch tags — keep section always visible to confirm it works
|
||||
try {
|
||||
const tagsRes = await api(`/api/tags/suggest?q=${encodeURIComponent(prefix)}&vault=${encodeURIComponent(vault)}&limit=5`, { signal: suggestAbortController.signal });
|
||||
const tagsRes = await api(`/api/tags/suggest?q=${encodeURIComponent(prefix)}&vault=${encodeURIComponent(vault)}&limit=5`, { signal: state.suggestAbortController.signal });
|
||||
const items = tagsRes.suggestions || [];
|
||||
if (items.length > 0) {
|
||||
this._renderTags(items, prefix);
|
||||
@@ -363,30 +363,30 @@ const AutocompleteDropdown = {
|
||||
},
|
||||
|
||||
_collectItems() {
|
||||
dropdownItems = Array.from(this._dropdown.querySelectorAll(".search-dropdown__item"));
|
||||
dropdownActiveIndex = -1;
|
||||
dropdownItems.forEach((item) => item.classList.remove("active"));
|
||||
state.dropdownItems = Array.from(this._dropdown.querySelectorAll(".search-dropdown__item"));
|
||||
state.dropdownActiveIndex = -1;
|
||||
state.dropdownItems.forEach((item) => item.classList.remove("active"));
|
||||
},
|
||||
|
||||
navigateDown() {
|
||||
if (!this.isVisible() || dropdownItems.length === 0) return;
|
||||
if (dropdownActiveIndex >= 0) dropdownItems[dropdownActiveIndex].classList.remove("active");
|
||||
dropdownActiveIndex = (dropdownActiveIndex + 1) % dropdownItems.length;
|
||||
dropdownItems[dropdownActiveIndex].classList.add("active");
|
||||
dropdownItems[dropdownActiveIndex].scrollIntoView({ block: "nearest" });
|
||||
if (!this.isVisible() || state.dropdownItems.length === 0) return;
|
||||
if (dropdownActiveIndex >= 0) state.dropdownItems[state.dropdownActiveIndex].classList.remove("active");
|
||||
state.dropdownActiveIndex = (dropdownActiveIndex + 1) % state.dropdownItems.length;
|
||||
state.dropdownItems[state.dropdownActiveIndex].classList.add("active");
|
||||
state.dropdownItems[state.dropdownActiveIndex].scrollIntoView({ block: "nearest" });
|
||||
},
|
||||
|
||||
navigateUp() {
|
||||
if (!this.isVisible() || dropdownItems.length === 0) return;
|
||||
if (dropdownActiveIndex >= 0) dropdownItems[dropdownActiveIndex].classList.remove("active");
|
||||
dropdownActiveIndex = dropdownActiveIndex <= 0 ? dropdownItems.length - 1 : dropdownActiveIndex - 1;
|
||||
dropdownItems[dropdownActiveIndex].classList.add("active");
|
||||
dropdownItems[dropdownActiveIndex].scrollIntoView({ block: "nearest" });
|
||||
if (!this.isVisible() || state.dropdownItems.length === 0) return;
|
||||
if (dropdownActiveIndex >= 0) state.dropdownItems[state.dropdownActiveIndex].classList.remove("active");
|
||||
state.dropdownActiveIndex = dropdownActiveIndex <= 0 ? state.dropdownItems.length - 1 : dropdownActiveIndex - 1;
|
||||
state.dropdownItems[state.dropdownActiveIndex].classList.add("active");
|
||||
state.dropdownItems[state.dropdownActiveIndex].scrollIntoView({ block: "nearest" });
|
||||
},
|
||||
|
||||
selectActive() {
|
||||
if (dropdownActiveIndex >= 0 && dropdownActiveIndex < dropdownItems.length) {
|
||||
dropdownItems[dropdownActiveIndex].click();
|
||||
if (dropdownActiveIndex >= 0 && dropdownActiveIndex < state.dropdownItems.length) {
|
||||
state.dropdownItems[state.dropdownActiveIndex].click();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -460,8 +460,8 @@ const SearchChips = {
|
||||
function _triggerAdvancedSearch(rawQuery) {
|
||||
const q = (rawQuery || "").trim();
|
||||
const vault = document.getElementById("vault-filter").value;
|
||||
const tagFilter = selectedTags.length > 0 ? selectedTags.join(",") : null;
|
||||
advancedSearchOffset = 0;
|
||||
const tagFilter = state.selectedTags.length > 0 ? state.selectedTags.join(",") : null;
|
||||
state.advancedSearchOffset = 0;
|
||||
if (q.length > 0 || tagFilter) {
|
||||
SearchHistory.add(q);
|
||||
performAdvancedSearch(q, vault, tagFilter);
|
||||
@@ -490,17 +490,17 @@ function initSearch() {
|
||||
const countEl = document.getElementById("search-match-count");
|
||||
|
||||
function _updateToggleUI() {
|
||||
caseBtn.classList.toggle("active", searchCaseSensitive);
|
||||
wordBtn.classList.toggle("active", searchWholeWord);
|
||||
regexBtn.classList.toggle("active", searchRegex);
|
||||
filterBtn.classList.toggle("active", searchFilterVisible);
|
||||
caseBtn.classList.toggle("active", state.searchCaseSensitive);
|
||||
wordBtn.classList.toggle("active", state.searchWholeWord);
|
||||
regexBtn.classList.toggle("active", state.searchRegex);
|
||||
filterBtn.classList.toggle("active", state.searchFilterVisible);
|
||||
}
|
||||
|
||||
// Toggle buttons
|
||||
caseBtn.addEventListener("click", () => { searchCaseSensitive = !searchCaseSensitive; _updateToggleUI(); _research(); });
|
||||
if (wordBtn) wordBtn.addEventListener("click", () => { searchWholeWord = !searchWholeWord; _updateToggleUI(); _research(); });
|
||||
if (regexBtn) regexBtn.addEventListener("click", () => { searchRegex = !searchRegex; _updateToggleUI(); _research(); });
|
||||
if (filterBtn) filterBtn.addEventListener("click", () => { searchFilterVisible = !searchFilterVisible; if (filterRow) filterRow.style.display = searchFilterVisible ? "flex" : "none"; _updateToggleUI(); });
|
||||
caseBtn.addEventListener("click", () => { state.searchCaseSensitive = !state.searchCaseSensitive; _updateToggleUI(); _research(); });
|
||||
if (wordBtn) wordBtn.addEventListener("click", () => { state.searchWholeWord = !state.searchWholeWord; _updateToggleUI(); _research(); });
|
||||
if (regexBtn) regexBtn.addEventListener("click", () => { state.searchRegex = !state.searchRegex; _updateToggleUI(); _research(); });
|
||||
if (filterBtn) filterBtn.addEventListener("click", () => { state.searchFilterVisible = !state.searchFilterVisible; if (filterRow) filterRow.style.display = searchFilterVisible ? "flex" : "none"; _updateToggleUI(); });
|
||||
|
||||
// ── Result navigation (up/down arrows + Enter) ──
|
||||
let _searchResultIdx = -1;
|
||||
@@ -536,11 +536,11 @@ function initSearch() {
|
||||
function _research() {
|
||||
const q = input.value.trim();
|
||||
if (q.length >= _getEffective("min_query_length", 2)) {
|
||||
clearTimeout(searchTimeout);
|
||||
searchTimeout = setTimeout(() => {
|
||||
clearTimeout(state.searchTimeout);
|
||||
state.searchTimeout = setTimeout(() => {
|
||||
const vault = document.getElementById("vault-filter").value;
|
||||
const tagFilter = selectedTags.length > 0 ? selectedTags.join(",") : null;
|
||||
advancedSearchOffset = 0;
|
||||
const tagFilter = state.selectedTags.length > 0 ? state.selectedTags.join(",") : null;
|
||||
state.advancedSearchOffset = 0;
|
||||
performAdvancedSearch(q, vault, tagFilter);
|
||||
}, _getEffective("debounce_ms", 300));
|
||||
}
|
||||
@@ -572,14 +572,14 @@ function initSearch() {
|
||||
AutocompleteDropdown.populate(input.value, input.selectionStart);
|
||||
|
||||
// Debounced search execution
|
||||
clearTimeout(searchTimeout);
|
||||
searchTimeout = setTimeout(
|
||||
clearTimeout(state.searchTimeout);
|
||||
state.searchTimeout = setTimeout(
|
||||
() => {
|
||||
const q = input.value.trim();
|
||||
const vault = document.getElementById("vault-filter").value;
|
||||
const tagFilter = selectedTags.length > 0 ? selectedTags.join(",") : null;
|
||||
advancedSearchOffset = 0;
|
||||
if (q.length >= _getEffective("min_query_length", MIN_SEARCH_LENGTH) || tagFilter) {
|
||||
const tagFilter = state.selectedTags.length > 0 ? state.selectedTags.join(",") : null;
|
||||
state.advancedSearchOffset = 0;
|
||||
if (q.length >= _getEffective("min_query_length", state.MIN_SEARCH_LENGTH) || tagFilter) {
|
||||
performAdvancedSearch(q, vault, tagFilter);
|
||||
} else if (q.length === 0) {
|
||||
SearchChips.clear();
|
||||
@@ -630,10 +630,10 @@ function initSearch() {
|
||||
const q = input.value.trim();
|
||||
if (q) {
|
||||
SearchHistory.add(q);
|
||||
clearTimeout(searchTimeout);
|
||||
advancedSearchOffset = 0;
|
||||
clearTimeout(state.searchTimeout);
|
||||
state.advancedSearchOffset = 0;
|
||||
const vault = document.getElementById("vault-filter").value;
|
||||
const tagFilter = selectedTags.length > 0 ? selectedTags.join(",") : null;
|
||||
const tagFilter = state.selectedTags.length > 0 ? state.selectedTags.join(",") : null;
|
||||
performAdvancedSearch(q, vault, tagFilter);
|
||||
}
|
||||
e.preventDefault();
|
||||
@@ -654,10 +654,10 @@ function initSearch() {
|
||||
const q = input.value.trim();
|
||||
if (q) {
|
||||
SearchHistory.add(q);
|
||||
clearTimeout(searchTimeout);
|
||||
advancedSearchOffset = 0;
|
||||
clearTimeout(state.searchTimeout);
|
||||
state.advancedSearchOffset = 0;
|
||||
const vault = document.getElementById("vault-filter").value;
|
||||
const tagFilter = selectedTags.length > 0 ? selectedTags.join(",") : null;
|
||||
const tagFilter = state.selectedTags.length > 0 ? state.selectedTags.join(",") : null;
|
||||
performAdvancedSearch(q, vault, tagFilter);
|
||||
}
|
||||
e.preventDefault();
|
||||
@@ -667,9 +667,9 @@ function initSearch() {
|
||||
clearBtn.addEventListener("click", () => {
|
||||
input.value = "";
|
||||
if (clearBtn) clearBtn.style.display = "none";
|
||||
searchCaseSensitive = false;
|
||||
searchWholeWord = false;
|
||||
searchRegex = false;
|
||||
state.searchCaseSensitive = false;
|
||||
state.searchWholeWord = false;
|
||||
state.searchRegex = false;
|
||||
_updateToggleUI();
|
||||
SearchChips.clear();
|
||||
AutocompleteDropdown.hide();
|
||||
@@ -706,47 +706,47 @@ function _isInputFocused() {
|
||||
|
||||
// --- Backward-compatible search (existing /api/search endpoint) ---
|
||||
async function performSearch(query, vaultFilter, tagFilter) {
|
||||
if (searchAbortController) searchAbortController.abort();
|
||||
searchAbortController = new AbortController();
|
||||
const searchId = ++currentSearchId;
|
||||
if (state.searchAbortController) state.searchAbortController.abort();
|
||||
state.searchAbortController = new AbortController();
|
||||
const searchId = ++state.currentSearchId;
|
||||
showLoading();
|
||||
let url = `/api/search?q=${encodeURIComponent(query)}&vault=${encodeURIComponent(vaultFilter)}`;
|
||||
if (tagFilter) url += `&tag=${encodeURIComponent(tagFilter)}`;
|
||||
try {
|
||||
const data = await api(url, { signal: searchAbortController.signal });
|
||||
if (searchId !== currentSearchId) return;
|
||||
const data = await api(url, { signal: state.searchAbortController.signal });
|
||||
if (searchId !== state.currentSearchId) return;
|
||||
renderSearchResults(data, query, tagFilter);
|
||||
} catch (err) {
|
||||
if (err.name === "AbortError") return;
|
||||
if (searchId !== currentSearchId) return;
|
||||
if (searchId !== state.currentSearchId) return;
|
||||
showWelcome();
|
||||
} finally {
|
||||
hideProgressBar();
|
||||
if (searchId === currentSearchId) searchAbortController = null;
|
||||
if (searchId === state.currentSearchId) state.searchAbortController = null;
|
||||
}
|
||||
}
|
||||
|
||||
// --- Advanced search with TF-IDF, facets, pagination ---
|
||||
async function performAdvancedSearch(query, vaultFilter, tagFilter, offset, sort) {
|
||||
if (searchAbortController) searchAbortController.abort();
|
||||
searchAbortController = new AbortController();
|
||||
const searchId = ++currentSearchId;
|
||||
if (state.searchAbortController) state.searchAbortController.abort();
|
||||
state.searchAbortController = new AbortController();
|
||||
const searchId = ++state.currentSearchId;
|
||||
showLoading();
|
||||
|
||||
const ofs = offset !== undefined ? offset : advancedSearchOffset;
|
||||
const sortBy = sort || advancedSearchSort;
|
||||
advancedSearchLastQuery = query;
|
||||
const ofs = offset !== undefined ? offset : state.advancedSearchOffset;
|
||||
const sortBy = sort || state.advancedSearchSort;
|
||||
state.advancedSearchLastQuery = query;
|
||||
|
||||
// Update chips from parsed query
|
||||
const parsed = QueryParser.parse(query);
|
||||
SearchChips.update(parsed);
|
||||
|
||||
const effectiveLimit = _getEffective("results_per_page", ADVANCED_SEARCH_LIMIT);
|
||||
const effectiveLimit = _getEffective("results_per_page", state.ADVANCED_SEARCH_LIMIT);
|
||||
let url = `/api/search/advanced?q=${encodeURIComponent(query)}&vault=${encodeURIComponent(vaultFilter)}&limit=${effectiveLimit}&offset=${ofs}&sort=${sortBy}`;
|
||||
if (tagFilter) url += `&tag=${encodeURIComponent(tagFilter)}`;
|
||||
if (searchCaseSensitive) url += "&case_sensitive=true";
|
||||
if (searchWholeWord) url += "&whole_word=true";
|
||||
if (searchRegex) url += "®ex=true";
|
||||
if (state.searchCaseSensitive) url += "&case_sensitive=true";
|
||||
if (state.searchWholeWord) url += "&whole_word=true";
|
||||
if (state.searchRegex) url += "®ex=true";
|
||||
const includeEl = document.getElementById("search-include-input");
|
||||
const excludeEl = document.getElementById("search-exclude-input");
|
||||
if (includeEl?.value.trim()) url += `&include_paths=${encodeURIComponent(includeEl.value.trim())}`;
|
||||
@@ -755,26 +755,26 @@ async function performAdvancedSearch(query, vaultFilter, tagFilter, offset, sort
|
||||
// Search timeout — abort if server takes too long
|
||||
const timeoutId = setTimeout(
|
||||
() => {
|
||||
if (searchAbortController) searchAbortController.abort();
|
||||
if (state.searchAbortController) state.searchAbortController.abort();
|
||||
},
|
||||
_getEffective("search_timeout_ms", SEARCH_TIMEOUT_MS),
|
||||
_getEffective("search_timeout_ms", state.SEARCH_TIMEOUT_MS),
|
||||
);
|
||||
|
||||
try {
|
||||
const data = await api(url, { signal: searchAbortController.signal });
|
||||
const data = await api(url, { signal: state.searchAbortController.signal });
|
||||
clearTimeout(timeoutId);
|
||||
if (searchId !== currentSearchId) return;
|
||||
advancedSearchTotal = data.total;
|
||||
advancedSearchOffset = ofs;
|
||||
if (searchId !== state.currentSearchId) return;
|
||||
state.advancedSearchTotal = data.total;
|
||||
state.advancedSearchOffset = ofs;
|
||||
renderAdvancedSearchResults(data, query, tagFilter);
|
||||
} catch (err) {
|
||||
clearTimeout(timeoutId);
|
||||
if (err.name === "AbortError") return;
|
||||
if (searchId !== currentSearchId) return;
|
||||
if (searchId !== state.currentSearchId) return;
|
||||
showWelcome();
|
||||
} finally {
|
||||
hideProgressBar();
|
||||
if (searchId === currentSearchId) searchAbortController = null;
|
||||
if (searchId === state.currentSearchId) state.searchAbortController = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -797,7 +797,7 @@ function renderSearchResults(data, query, tagFilter) {
|
||||
|
||||
const titleDiv = el("div", { class: "search-result-title" });
|
||||
if (query && query.trim()) {
|
||||
highlightSearchText(titleDiv, r.title, query, searchCaseSensitive);
|
||||
highlightSearchText(titleDiv, r.title, query, state.searchCaseSensitive);
|
||||
} else {
|
||||
titleDiv.textContent = r.title;
|
||||
}
|
||||
@@ -805,7 +805,7 @@ function renderSearchResults(data, query, tagFilter) {
|
||||
if (r.snippet && r.snippet.includes("<mark>")) {
|
||||
snippetDiv.innerHTML = r.snippet;
|
||||
} else if (query && query.trim() && r.snippet) {
|
||||
highlightSearchText(snippetDiv, r.snippet, query, searchCaseSensitive);
|
||||
highlightSearchText(snippetDiv, r.snippet, query, state.searchCaseSensitive);
|
||||
} else {
|
||||
snippetDiv.textContent = r.snippet || "";
|
||||
}
|
||||
@@ -869,9 +869,9 @@ function renderAdvancedSearchResults(data, query, tagFilter) {
|
||||
|
||||
// Active filter badges
|
||||
const filtersRow = el("div", { class: "search-filters-row" });
|
||||
if (searchCaseSensitive) filtersRow.appendChild(el("span", { class: "search-filter-badge" }, [document.createTextNode("Aa")]));
|
||||
if (searchWholeWord) filtersRow.appendChild(el("span", { class: "search-filter-badge" }, [document.createTextNode("wd")]));
|
||||
if (searchRegex) filtersRow.appendChild(el("span", { class: "search-filter-badge" }, [document.createTextNode(".*")]));
|
||||
if (state.searchCaseSensitive) filtersRow.appendChild(el("span", { class: "search-filter-badge" }, [document.createTextNode("Aa")]));
|
||||
if (state.searchWholeWord) filtersRow.appendChild(el("span", { class: "search-filter-badge" }, [document.createTextNode("wd")]));
|
||||
if (state.searchRegex) filtersRow.appendChild(el("span", { class: "search-filter-badge" }, [document.createTextNode(".*")]));
|
||||
const inclEl = document.getElementById("search-include-input");
|
||||
const exclEl = document.getElementById("search-exclude-input");
|
||||
if (inclEl?.value.trim()) filtersRow.appendChild(el("span", { class: "search-filter-badge path" }, [document.createTextNode("incl: " + inclEl.value.trim())]));
|
||||
@@ -880,19 +880,19 @@ function renderAdvancedSearchResults(data, query, tagFilter) {
|
||||
|
||||
// Sort controls
|
||||
const sortDiv = el("div", { class: "search-sort" });
|
||||
const btnRelevance = el("button", { class: "search-sort__btn" + (advancedSearchSort === "relevance" ? " active" : ""), type: "button" });
|
||||
const btnRelevance = el("button", { class: "search-sort__btn" + (state.advancedSearchSort === "relevance" ? " active" : ""), type: "button" });
|
||||
btnRelevance.textContent = "Pertinence";
|
||||
btnRelevance.addEventListener("click", () => {
|
||||
advancedSearchSort = "relevance";
|
||||
advancedSearchOffset = 0;
|
||||
state.advancedSearchSort = "relevance";
|
||||
state.advancedSearchOffset = 0;
|
||||
const vault = document.getElementById("vault-filter").value;
|
||||
performAdvancedSearch(query, vault, tagFilter, 0, "relevance");
|
||||
});
|
||||
const btnDate = el("button", { class: "search-sort__btn" + (advancedSearchSort === "modified" ? " active" : ""), type: "button" });
|
||||
const btnDate = el("button", { class: "search-sort__btn" + (state.advancedSearchSort === "modified" ? " active" : ""), type: "button" });
|
||||
btnDate.textContent = "Date";
|
||||
btnDate.addEventListener("click", () => {
|
||||
advancedSearchSort = "modified";
|
||||
advancedSearchOffset = 0;
|
||||
state.advancedSearchSort = "modified";
|
||||
state.advancedSearchOffset = 0;
|
||||
const vault = document.getElementById("vault-filter").value;
|
||||
performAdvancedSearch(query, vault, tagFilter, 0, "modified");
|
||||
});
|
||||
@@ -913,9 +913,9 @@ function renderAdvancedSearchResults(data, query, tagFilter) {
|
||||
body: JSON.stringify({
|
||||
query: query,
|
||||
vault: document.getElementById("vault-filter")?.value || "all",
|
||||
case_sensitive: searchCaseSensitive,
|
||||
whole_word: searchWholeWord,
|
||||
regex: searchRegex,
|
||||
case_sensitive: state.searchCaseSensitive,
|
||||
whole_word: state.searchWholeWord,
|
||||
regex: state.searchRegex,
|
||||
include_paths: inclEl?.value || "",
|
||||
exclude_paths: exclEl?.value || "",
|
||||
}),
|
||||
@@ -927,9 +927,9 @@ function renderAdvancedSearchResults(data, query, tagFilter) {
|
||||
area.appendChild(header);
|
||||
|
||||
// Active sidebar tag chips
|
||||
if (selectedTags.length > 0) {
|
||||
if (state.selectedTags.length > 0) {
|
||||
const activeTags = el("div", { class: "search-results-active-tags" });
|
||||
selectedTags.forEach((tag) => {
|
||||
state.selectedTags.forEach((tag) => {
|
||||
const removeBtn = el(
|
||||
"button",
|
||||
{
|
||||
@@ -1012,7 +1012,7 @@ function renderAdvancedSearchResults(data, query, tagFilter) {
|
||||
|
||||
const titleDiv = el("div", { class: "search-result-title" });
|
||||
if (freeText) {
|
||||
highlightSearchText(titleDiv, r.title, freeText, searchCaseSensitive);
|
||||
highlightSearchText(titleDiv, r.title, freeText, state.searchCaseSensitive);
|
||||
} else {
|
||||
titleDiv.textContent = r.title;
|
||||
}
|
||||
@@ -1022,7 +1022,7 @@ function renderAdvancedSearchResults(data, query, tagFilter) {
|
||||
if (r.snippet && r.snippet.includes("<mark>")) {
|
||||
snippetDiv.innerHTML = r.snippet;
|
||||
} else if (freeText && r.snippet) {
|
||||
highlightSearchText(snippetDiv, r.snippet, freeText, searchCaseSensitive);
|
||||
highlightSearchText(snippetDiv, r.snippet, freeText, state.searchCaseSensitive);
|
||||
} else {
|
||||
snippetDiv.textContent = r.snippet || "";
|
||||
}
|
||||
@@ -1060,30 +1060,30 @@ function renderAdvancedSearchResults(data, query, tagFilter) {
|
||||
area.appendChild(container);
|
||||
|
||||
// Pagination
|
||||
if (data.total > ADVANCED_SEARCH_LIMIT) {
|
||||
if (data.total > state.ADVANCED_SEARCH_LIMIT) {
|
||||
const paginationDiv = el("div", { class: "search-pagination" });
|
||||
const prevBtn = el("button", { class: "search-pagination__btn", type: "button" });
|
||||
prevBtn.textContent = "← Précédent";
|
||||
prevBtn.disabled = advancedSearchOffset === 0;
|
||||
prevBtn.disabled = state.advancedSearchOffset === 0;
|
||||
prevBtn.addEventListener("click", () => {
|
||||
advancedSearchOffset = Math.max(0, advancedSearchOffset - ADVANCED_SEARCH_LIMIT);
|
||||
state.advancedSearchOffset = Math.max(0, advancedSearchOffset - state.ADVANCED_SEARCH_LIMIT);
|
||||
const vault = document.getElementById("vault-filter").value;
|
||||
performAdvancedSearch(query, vault, tagFilter, advancedSearchOffset);
|
||||
performAdvancedSearch(query, vault, tagFilter, state.advancedSearchOffset);
|
||||
document.getElementById("content-area").scrollTop = 0;
|
||||
});
|
||||
|
||||
const info = el("span", { class: "search-pagination__info" });
|
||||
const from = advancedSearchOffset + 1;
|
||||
const to = Math.min(advancedSearchOffset + ADVANCED_SEARCH_LIMIT, data.total);
|
||||
const to = Math.min(advancedSearchOffset + state.ADVANCED_SEARCH_LIMIT, data.total);
|
||||
info.textContent = `${from}–${to} sur ${data.total}`;
|
||||
|
||||
const nextBtn = el("button", { class: "search-pagination__btn", type: "button" });
|
||||
nextBtn.textContent = "Suivant →";
|
||||
nextBtn.disabled = advancedSearchOffset + ADVANCED_SEARCH_LIMIT >= data.total;
|
||||
nextBtn.addEventListener("click", () => {
|
||||
advancedSearchOffset += ADVANCED_SEARCH_LIMIT;
|
||||
advancedSearchOffset += state.ADVANCED_SEARCH_LIMIT;
|
||||
const vault = document.getElementById("vault-filter").value;
|
||||
performAdvancedSearch(query, vault, tagFilter, advancedSearchOffset);
|
||||
performAdvancedSearch(query, vault, tagFilter, state.advancedSearchOffset);
|
||||
document.getElementById("content-area").scrollTop = 0;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user