| 1 |
<script> |
| 2 |
import '../assets/js/search-index.js'; |
| 3 |
</script> |
| 4 |
|
| 5 |
|
| 6 |
<search-index id="global-search" hx-preserve="true" |
| 7 |
src="/search-index.json" |
| 8 |
highlight="<mark class='bg-blue-700 dark:bg-blue-300 text-white dark:text-neutral-900 font-bold px-0.5 box-decoration-clone'>$1</mark>" |
| 9 |
class="group/search"> |
| 10 |
<dialog id="search-modal" |
| 11 |
class="fixed top-4 bottom-4 inset-x-4 sm:top-[12vh] sm:bottom-[12vh] bg-transparent open:flex items-start justify-center w-full h-auto |
| 12 |
backdrop:bg-neutral-950/40 backdrop:backdrop-blur-sm |
| 13 |
backdrop:transition backdrop:opacity-0 open:backdrop:opacity-100 |
| 14 |
transition-discrete transition open:starting:opacity-0 opacity-0 open:opacity-100 z-50 starting:open:scale-95 scale-95 open:scale-100 origin-top outline-none" |
| 15 |
role="alertdialog" |
| 16 |
aria-modal="true" |
| 17 |
aria-label="Search documentation" |
| 18 |
_="on click |
| 19 |
if target is me then close me end |
| 20 |
end |
| 21 |
on close |
| 22 |
reset #search-form |
| 23 |
put '' into #search-results |
| 24 |
blur document.activeElement" |
| 25 |
> |
| 26 |
<form id="search-form" |
| 27 |
role="search" |
| 28 |
hx-boost="false" |
| 29 |
onsubmit="return false" |
| 30 |
class="not-has-placeholder-shown:absolute inset-0 mx-auto w-full max-w-3xl overflow-hidden rounded-xl bg-white dark:bg-neutral-920 border border-neutral-200 dark:border-neutral-850 flex flex-col min-h-0 shadow" |
| 31 |
_="on submit |
| 32 |
halt the event |
| 33 |
get the first <.result[aria-selected='true']/> |
| 34 |
if it exists |
| 35 |
close #search-modal |
| 36 |
set window.location.href to it.href |
| 37 |
end |
| 38 |
end"> |
| 39 |
|
| 40 |
<header class="relative border-b border-neutral-200 dark:border-neutral-850 shrink-0 bg-neutral-50 dark:bg-neutral-900"> |
| 41 |
<i class="icon-[mdi--magnify] pointer-events-none absolute left-3 sm:left-5 top-1/2 -translate-y-1/2 text-base sm:text-lg text-neutral-400 group-data-searching/search:opacity-0 transition" |
| 42 |
aria-hidden="true"></i> |
| 43 |
<i class="icon-[svg-spinners--90-ring-with-bg] pointer-events-none absolute left-3 sm:left-5 top-1/2 -translate-y-1/2 text-base sm:text-lg text-neutral-400 opacity-0 group-data-searching/search:opacity-100 transition" |
| 44 |
aria-hidden="true" aria-live="polite" aria-label="Searching"></i> |
| 45 |
<label for="search-input" class="sr-only">Search documentation</label> |
| 46 |
<input |
| 47 |
type="text" |
| 48 |
id="search-input" |
| 49 |
role="combobox" |
| 50 |
aria-controls="search-results" |
| 51 |
aria-autocomplete="list" |
| 52 |
class="peer/search-input h-14 sm:h-16 w-full border-0 bg-transparent pl-10 sm:pl-14 pr-10 sm:pr-12 text-base sm:text-lg text-neutral-900 dark:text-neutral-100 placeholder:text-neutral-400 focus:ring-0 font-sans outline-none" |
| 53 |
autocomplete="off" |
| 54 |
autocapitalize="off" |
| 55 |
autocorrect="off" |
| 56 |
enterkeyhint="search" |
| 57 |
spellcheck="false" |
| 58 |
placeholder="Search documentation..." |
| 59 |
_=" |
| 60 |
on input |
| 61 |
set value to event.target.value |
| 62 |
if value.trim() is empty |
| 63 |
put '' into #search-results |
| 64 |
remove .has-results from #search-container |
| 65 |
else |
| 66 |
search(value) the closest <search-index/> |
| 67 |
set searchResults to it |
| 68 |
js(searchResults) |
| 69 |
return searchResults.map(result => { |
| 70 |
const coll = result.collection || ''; |
| 71 |
result.subcategory = result.breadcrumb?.[0] || ''; |
| 72 |
result.collectionId = coll.toLowerCase(); |
| 73 |
result.titleFont = 'font-chicago text-sm'; |
| 74 |
return result; |
| 75 |
}); |
| 76 |
end |
| 77 |
set flatResults to it |
| 78 |
render #search-template with results: flatResults, query: value |
| 79 |
put it into #search-results |
| 80 |
add .has-results to #search-container |
| 81 |
wait 10ms |
| 82 |
if <.result/> exists |
| 83 |
take @aria-selected='true' from .result for the first .result |
| 84 |
end |
| 85 |
end |
| 86 |
end |
| 87 |
on keydown[(key is 'ArrowDown' or key is 'ArrowUp') and .result exists] |
| 88 |
halt the event |
| 89 |
get the first <.result[aria-selected='true']/> in #search-results |
| 90 |
if it exists and it.isConnected |
| 91 |
if event.key is 'ArrowDown' |
| 92 |
set target to next .result from it |
| 93 |
if no target then set target to the first .result end |
| 94 |
else |
| 95 |
set target to previous .result from it |
| 96 |
if no target then set target to the last .result end |
| 97 |
end |
| 98 |
else |
| 99 |
if event.key is 'ArrowDown' |
| 100 |
set target to the first .result |
| 101 |
else |
| 102 |
set target to the last .result |
| 103 |
end |
| 104 |
end |
| 105 |
if target exists |
| 106 |
take @aria-selected='true' from .result for target |
| 107 |
add @data-keyboard-mode to #search-container |
| 108 |
call target.scrollIntoView({block: 'nearest'}) |
| 109 |
end |
| 110 |
end" |
| 111 |
/> |
| 112 |
<kbd class="z-10 absolute right-3 sm:right-4 top-1/2 -translate-y-1/2 flex items-center justify-center h-5 px-1.5 min-w-5 rounded border border-neutral-200 dark:border-neutral-800 bg-neutral-25 dark:bg-neutral-910 font-sans text-[10px] text-neutral-600 dark:text-neutral-400 pointer-events-none" |
| 113 |
aria-label="Press Escape to close"> |
| 114 |
esc |
| 115 |
</kbd> |
| 116 |
</header> |
| 117 |
|
| 118 |
<main id="search-container" |
| 119 |
class="peer h-[400px] sm:h-[500px] scroll-pt-10 overflow-y-auto flex-1 bg-neutral-25 dark:bg-neutral-920 |
| 120 |
data-[keyboard-mode]:*:pointer-events-none" |
| 121 |
_="on mousemove remove @data-keyboard-mode"> |
| 122 |
|
| 123 |
<div class="hidden group-not-has-placeholder-shown/search:group-data-searched/search:group-data-empty/search:flex flex-col items-center justify-center h-full px-4 sm:px-6" |
| 124 |
role="status" aria-live="polite"> |
| 125 |
<i class="icon-[mdi--magnify-close] text-6xl sm:text-7xl text-neutral-300 dark:text-neutral-700 mb-4" |
| 126 |
aria-hidden="true"></i> |
| 127 |
<p class="text-sm sm:text-base text-neutral-500 dark:text-neutral-400 font-medium">No results |
| 128 |
found</p> |
| 129 |
<p class="text-xs sm:text-sm text-neutral-400 dark:text-neutral-500 mt-1">Try a different search |
| 130 |
term</p> |
| 131 |
</div> |
| 132 |
|
| 133 |
<script type="text/hyperscript-template" id="search-template" is:raw> |
| 134 |
<ul class="space-y-2 p-3" role="listbox" aria-label="Search results"> |
| 135 |
#repeat for item in results |
| 136 |
#if not item.parent |
| 137 |
<li class="relative group/result"> |
| 138 |
<a href="${item.url}" |
| 139 |
role="option" |
| 140 |
class="result peer absolute inset-0 z-10 w-full h-full opacity-0 cursor-pointer touch-manipulation" |
| 141 |
_="on mousemove |
| 142 |
take @aria-selected='true' from .result for me |
| 143 |
end |
| 144 |
on click |
| 145 |
close #search-modal |
| 146 |
end"></a> |
| 147 |
|
| 148 |
<article |
| 149 |
class="flex items-center gap-4 px-3 py-3 rounded-lg border transition-all duration-100 |
| 150 |
/* Default */ |
| 151 |
border-transparent bg-transparent |
| 152 |
|
| 153 |
/* Active / Selected State */ |
| 154 |
peer-aria-selected:bg-neutral-50 dark:peer-aria-selected:bg-neutral-800/50 |
| 155 |
|
| 156 |
peer-aria-selected:border-neutral-300 dark:peer-aria-selected:border-neutral-600 |
| 157 |
peer-aria-selected:text-neutral-900 dark:peer-aria-selected:text-neutral-100" |
| 158 |
aria-hidden="true"> |
| 159 |
|
| 160 |
<div class="flex flex-col flex-1 min-w-0"> |
| 161 |
<nav class="flex items-center gap-2 mb-1 text-xs |
| 162 |
text-neutral-500 dark:text-neutral-450 |
| 163 |
group-has-aria-selected/result:text-neutral-600 dark:group-has-aria-selected/result:text-neutral-400 transition-colors"> |
| 164 |
<span>${item.collection}</span> |
| 165 |
#if item.subcategory |
| 166 |
<span class="text-neutral-300 dark:text-neutral-700 select-none">/</span> |
| 167 |
<span>${item.subcategory}</span> |
| 168 |
#end |
| 169 |
</nav> |
| 170 |
|
| 171 |
<div class="${item.titleFont} truncate leading-tight"> |
| 172 |
${unescaped item.title} |
| 173 |
</div> |
| 174 |
</div> |
| 175 |
|
| 176 |
<i class="icon-[uil--enter] text-xs text-neutral-400 opacity-0 -translate-x-2 transition-all duration-200 group-has-aria-selected/result:opacity-100 group-has-aria-selected/result:translate-x-0"></i> |
| 177 |
</article> |
| 178 |
</li> |
| 179 |
#end |
| 180 |
#end |
| 181 |
</ul> |
| 182 |
</script> |
| 183 |
|
| 184 |
<output id="search-results" role="region" aria-live="polite" aria-atomic="true"></output> |
| 185 |
</main> |
| 186 |
|
| 187 |
<footer class="flex flex-wrap items-center font-mono border-t border-transparent peer-[.has-results]:border-neutral-200 dark:peer-[.has-results]:border-neutral-850 bg-neutral-50 dark:bg-neutral-900 px-4 py-3 text-xs text-neutral-500 dark:text-neutral-400 shrink-0 rounded-b-xl" |
| 188 |
aria-label="Keyboard shortcuts"> |
| 189 |
<div class="flex items-center gap-6"> |
| 190 |
<span class="hidden sm:flex items-center gap-1.5"> |
| 191 |
<kbd class="flex items-center justify-center size-5 rounded border border-neutral-200 dark:border-neutral-800 bg-neutral-25 dark:bg-neutral-910 font-sans text-[10px] text-neutral-600 dark:text-neutral-400" |
| 192 |
aria-label="Up arrow"> |
| 193 |
↑ |
| 194 |
</kbd> |
| 195 |
<kbd class="flex items-center justify-center size-5 rounded border border-neutral-200 dark:border-neutral-800 bg-neutral-25 dark:bg-neutral-910 font-sans text-[10px] text-neutral-600 dark:text-neutral-400" |
| 196 |
aria-label="Down arrow"> |
| 197 |
↓ |
| 198 |
</kbd> |
| 199 |
<span>to navigate</span> |
| 200 |
</span> |
| 201 |
<span class="flex items-center gap-1.5"> |
| 202 |
<kbd class="flex items-center justify-center h-5 px-1.5 min-w-5 rounded border border-neutral-200 dark:border-neutral-800 bg-neutral-25 dark:bg-neutral-910 font-sans text-[10px] text-neutral-600 dark:text-neutral-400" |
| 203 |
aria-label="Enter"> |
| 204 |
<i class="icon-[uil--enter] text-xs"></i> |
| 205 |
</kbd> |
| 206 |
<span>to select</span> |
| 207 |
</span> |
| 208 |
<span class="sm:hidden flex items-center gap-1.5"> |
| 209 |
<i class="icon-[mdi--gesture-tap] text-sm -translate-y-px"></i> |
| 210 |
<span>outside to close</span> |
| 211 |
</span> |
| 212 |
</div> |
| 213 |
</footer> |
| 214 |
</form> |
| 215 |
</dialog> |
| 216 |
</search-index> |