mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 18:12:29 +08:00
feat(share): disable search if single note
This commit is contained in:
parent
3b81d00de7
commit
d68d0b5dd8
@ -23,7 +23,10 @@ function buildResultItem(result: SearchResult) {
|
|||||||
|
|
||||||
|
|
||||||
export default function setupSearch() {
|
export default function setupSearch() {
|
||||||
const searchInput: HTMLInputElement = document.querySelector(".search-input")!;
|
const searchInput: HTMLInputElement | null = document.querySelector(".search-input");
|
||||||
|
if (!searchInput) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
searchInput.addEventListener("keyup", debounce(async () => {
|
searchInput.addEventListener("keyup", debounce(async () => {
|
||||||
// console.log("CHANGE EVENT");
|
// console.log("CHANGE EVENT");
|
||||||
@ -38,14 +41,14 @@ export default function setupSearch() {
|
|||||||
lines.push(buildResultItem(result));
|
lines.push(buildResultItem(result));
|
||||||
}
|
}
|
||||||
lines.push("</div>");
|
lines.push("</div>");
|
||||||
|
|
||||||
const container = parseHTML(lines.join("")) as HTMLDivElement;
|
const container = parseHTML(lines.join("")) as HTMLDivElement;
|
||||||
// console.log(container, lines);
|
// console.log(container, lines);
|
||||||
const rect = searchInput.getBoundingClientRect();
|
const rect = searchInput.getBoundingClientRect();
|
||||||
container.style.top = `${rect.bottom}px`;
|
container.style.top = `${rect.bottom}px`;
|
||||||
container.style.left = `${rect.left}px`;
|
container.style.left = `${rect.left}px`;
|
||||||
container.style.minWidth = `${rect.width}px`;
|
container.style.minWidth = `${rect.width}px`;
|
||||||
|
|
||||||
const existing = document.querySelector(".search-results");
|
const existing = document.querySelector(".search-results");
|
||||||
if (existing) existing.replaceWith(container);
|
if (existing) existing.replaceWith(container);
|
||||||
else document.body.append(container);
|
else document.body.append(container);
|
||||||
@ -58,4 +61,4 @@ export default function setupSearch() {
|
|||||||
if (parents(e.target as HTMLElement, ".search-results,.search-item").length) return;
|
if (parents(e.target as HTMLElement, ".search-results,.search-item").length) return;
|
||||||
if (existing) existing.remove();
|
if (existing) existing.remove();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -131,10 +131,12 @@ content = content.replaceAll(headingRe, (...match) => {
|
|||||||
<svg class="light-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor"><path d="M6.993 12c0 2.761 2.246 5.007 5.007 5.007s5.007-2.246 5.007-5.007S14.761 6.993 12 6.993 6.993 9.239 6.993 12zM12 8.993c1.658 0 3.007 1.349 3.007 3.007S13.658 15.007 12 15.007 8.993 13.658 8.993 12 10.342 8.993 12 8.993zM10.998 19h2v3h-2zm0-17h2v3h-2zm-9 9h3v2h-3zm17 0h3v2h-3zM4.219 18.363l2.12-2.122 1.415 1.414-2.12 2.122zM16.24 6.344l2.122-2.122 1.414 1.414-2.122 2.122zM6.342 7.759 4.22 5.637l1.415-1.414 2.12 2.122zm13.434 10.605-1.414 1.414-2.122-2.122 1.414-1.414z"></path></svg>
|
<svg class="light-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor"><path d="M6.993 12c0 2.761 2.246 5.007 5.007 5.007s5.007-2.246 5.007-5.007S14.761 6.993 12 6.993 6.993 9.239 6.993 12zM12 8.993c1.658 0 3.007 1.349 3.007 3.007S13.658 15.007 12 15.007 8.993 13.658 8.993 12 10.342 8.993 12 8.993zM10.998 19h2v3h-2zm0-17h2v3h-2zm-9 9h3v2h-3zm17 0h3v2h-3zM4.219 18.363l2.12-2.122 1.415 1.414-2.12 2.122zM16.24 6.344l2.122-2.122 1.414 1.414-2.122 2.122zM6.342 7.759 4.22 5.637l1.415-1.414 2.12 2.122zm13.434 10.605-1.414 1.414-2.122-2.122 1.414-1.414z"></path></svg>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="search-item">
|
<% if (hasTree) { %>
|
||||||
<svg class="search-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor"><path d="M10 18a7.952 7.952 0 0 0 4.897-1.688l4.396 4.396 1.414-1.414-4.396-4.396A7.952 7.952 0 0 0 18 10c0-4.411-3.589-8-8-8s-8 3.589-8 8 3.589 8 8 8zm0-14c3.309 0 6 2.691 6 6s-2.691 6-6 6-6-2.691-6-6 2.691-6 6-6z"></path></svg>
|
<div class="search-item">
|
||||||
<input type="text" class="search-input" placeholder="Search...">
|
<svg class="search-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor"><path d="M10 18a7.952 7.952 0 0 0 4.897-1.688l4.396 4.396 1.414-1.414-4.396-4.396A7.952 7.952 0 0 0 18 10c0-4.411-3.589-8-8-8s-8 3.589-8 8 3.589 8 8 8zm0-14c3.309 0 6 2.691 6 6s-2.691 6-6 6-6-2.691-6-6 2.691-6 6-6z"></path></svg>
|
||||||
</div>
|
<input type="text" class="search-input" placeholder="Search...">
|
||||||
|
</div>
|
||||||
|
<% } %>
|
||||||
</div>
|
</div>
|
||||||
<% if (hasTree) { %>
|
<% if (hasTree) { %>
|
||||||
<nav id="menu">
|
<nav id="menu">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user