|
1 | 1 | <script lang="ts">
|
2 | 2 | import {createEventDispatcher, onMount} from 'svelte';
|
3 | 3 | import type {DomainObject} from 'fn';
|
4 |
| - import {processInput} from 'fn'; |
| 4 | + import {processInput, colourCoded, allPossibleCombinations} from 'fn'; |
5 | 5 |
|
6 | 6 | const dispatch = createEventDispatcher();
|
7 | 7 | export let svalue = '';
|
|
11 | 11 |
|
12 | 12 | export let placeholder = 'Search';
|
13 | 13 | export let icon = 'search';
|
| 14 | + let conflict = false; |
14 | 15 |
|
15 | 16 |
|
16 | 17 | let processedInput = value;
|
17 | 18 | let richOutput;
|
| 19 | + let generatedURI = ''; |
| 20 | + let suggestions:string[] = (allPossibleCombinations(packJSONData)); |
| 21 | + let suggestionsFormatted:string[] = colourCoded(allPossibleCombinations(packJSONData)); |
18 | 22 |
|
19 | 23 | let v:string;
|
20 | 24 |
|
21 | 25 | function valueChanged(e:any) {
|
22 | 26 | v = v.replaceAll(' ', ' ').replaceAll('. ', ' ');
|
23 | 27 | value = e.target.value.replaceAll(' ', ' ').replaceAll('. ', ' ');
|
24 | 28 | richOutput = processInput(packJSONData, value);
|
| 29 | + generatedURI = richOutput.generatedURI; |
| 30 | + suggestions = richOutput.autocomplete; |
| 31 | + suggestionsFormatted = richOutput.autocompleteFormatted; |
| 32 | + conflict = richOutput.conflict |
| 33 | + // console.log(suggestions) |
| 34 | + // console.log(generatedURI, richOutput); |
25 | 35 | processedInput = richOutput.processedInput;
|
26 | 36 | dispatch('val', value);
|
27 | 37 | }
|
28 | 38 |
|
29 | 39 | let pointerActive = true;
|
| 40 | + let suggestionActive = true; |
| 41 | + // export let viewDomains = false; |
30 | 42 |
|
31 | 43 | // focus on input asap
|
32 | 44 | onMount(() => {
|
33 | 45 | input.focus();
|
34 | 46 | });
|
35 | 47 |
|
36 |
| - |
| 48 | + function suggestionClick (i:number) { |
| 49 | + v = suggestions[i]; |
| 50 | + valueChanged({target: {value: suggestions[i]}}); |
| 51 | + suggestionActive = false; |
| 52 | + } |
| 53 | +
|
| 54 | + function decideSuggestionVisibility (e:any) { |
| 55 | + // if the target is not the suggestions div, hide suggestions |
| 56 | + if (!e.relatedTarget || !e.relatedTarget.classList.contains('suggestion')) { |
| 57 | + suggestionActive = false; |
| 58 | + } |
| 59 | +
|
| 60 | + } |
| 61 | +
|
| 62 | + let searchBegun = false; |
| 63 | + let timeout = false; |
| 64 | +
|
| 65 | + function searchInitiated(e:any) { |
| 66 | + e.preventDefault(); |
| 67 | + // if (!conflict) |
| 68 | + searchBegun = true; |
| 69 | + suggestionActive = false; |
| 70 | + let currentURI = location.href |
| 71 | + location.href = (generatedURI) |
| 72 | + |
| 73 | + setTimeout(() => { |
| 74 | + searchBegun = false; |
| 75 | + suggestionActive = true; |
| 76 | + timeout = true; |
| 77 | + location.assign(currentURI) |
| 78 | + setTimeout( |
| 79 | + () => timeout = false, 5000 |
| 80 | + ) |
| 81 | + }, 5000) |
| 82 | + } |
37 | 83 |
|
38 | 84 | </script>
|
39 | 85 |
|
40 | 86 | <!-- <input spellcheck="false" autocapitalize="false" autocorrect="off" on:keypress={() => dispatch('val', value)} bind:value> -->
|
41 | 87 |
|
42 | 88 | <!-- An invisible input will listen for keyboard input, while a span will render with color data -->
|
43 | 89 |
|
44 |
| -<div class="wrap"> |
45 |
| - |
46 |
| - <input bind:value={v} bind:this={input} class:pointerActive on:focus={() => pointerActive = false} on:blur={() => pointerActive = true} class="flex center-flex flex-col left-align" spellcheck="false" autocapitalize="false" autocorrect="off" autocomplete="off" on:input={valueChanged}> |
47 |
| - <div class="render-point flex center-flex center-align left-flex"> |
48 |
| - <div class="whitespace-allower"> |
49 |
| - {@html processedInput} |
| 90 | +<div class="search-aspect"> |
| 91 | + <div class="wrap"> |
| 92 | + <form on:submit={searchInitiated}> |
| 93 | + <input on:blur={(e) => {pointerActive = true; decideSuggestionVisibility(e)}} bind:value={v} bind:this={input} class:pointerActive on:focus={() => {pointerActive = false; suggestionActive = true;}} class="flex center-flex flex-col left-align" spellcheck="false" autocapitalize="false" autocorrect="off" autocomplete="off" on:input={valueChanged}> |
| 94 | + </form> |
| 95 | + <div class="render-point flex center-flex center-align left-flex"> |
| 96 | + <div class="whitespace-allower"> |
| 97 | + {@html processedInput} |
| 98 | + </div> |
| 99 | + </div> |
| 100 | + <div class="conflict flex center-flex top-pad center-align fw" class:warning-invisible={!conflict}> |
| 101 | + <span class="material-symbols-outlined"> |
| 102 | + warning |
| 103 | + </span> |
| 104 | + Search syntax is incomplete. Submitting this search triggers Google. |
| 105 | + <!-- {generatedURI} --> |
| 106 | + </div> |
| 107 | + <div class="conflict flex center-flex top-pad center-align fw" class:warning-invisible={!timeout}> |
| 108 | + <span class="material-symbols-outlined"> |
| 109 | + warning |
| 110 | + </span> |
| 111 | + Search timed out at 5000ms. |
| 112 | + <!-- {generatedURI} --> |
| 113 | + </div> |
| 114 | + <div class="placeholder flex center-flex" class:placeholder-visible={processedInput.trim() == '' && pointerActive}> |
| 115 | + <span class="material-symbols-outlined"> |
| 116 | + {icon} |
| 117 | + </span> |
| 118 | + {placeholder} |
50 | 119 | </div>
|
51 | 120 | </div>
|
52 |
| - <div class="placeholder flex center-flex" class:placeholder-visible={processedInput.trim() == '' && pointerActive}> |
53 |
| - <span class="material-symbols-outlined"> |
54 |
| - {icon} |
55 |
| - </span> |
56 |
| - {placeholder} |
| 121 | + <div class="suggestions" class:invisible={!suggestionActive}> |
| 122 | + {#key suggestionsFormatted} |
| 123 | + {#each suggestionsFormatted as suggestionFormatted, i} |
| 124 | + <div |
| 125 | + on:click={() => suggestionClick(i)} |
| 126 | + on:keydown={() => suggestionClick(i)} |
| 127 | + role="button" |
| 128 | + tabindex="0" |
| 129 | + class="flex center-flex center-align left-flex suggestion"> |
| 130 | + {@html suggestionFormatted} |
| 131 | + </div> |
| 132 | + {/each} |
| 133 | + {/key} |
57 | 134 | </div>
|
58 | 135 | </div>
|
59 | 136 |
|
| 137 | +<div class="telewrap flex center-align center-flex" class:invisible={!searchBegun}> |
| 138 | + |
| 139 | +</div> |
| 140 | + |
60 | 141 | <style lang="scss">
|
| 142 | + .telewrap { |
| 143 | + position: fixed; |
| 144 | + top: 0; |
| 145 | + left: 0; |
| 146 | + right: 0; |
| 147 | + bottom: 0; |
| 148 | + backdrop-filter: blur(10px); |
| 149 | + -webkit-backdrop-filter: blur(10px); |
| 150 | + transition: all 300ms ease; |
| 151 | + // z-index: 100; |
| 152 | + } |
| 153 | +.invisible { |
| 154 | + opacity: 0; |
| 155 | + pointer-events: none; |
| 156 | + backdrop-filter: blur(0); |
| 157 | + -webkit-backdrop-filter: blur(0); |
| 158 | +} |
| 159 | +.search-aspect { |
| 160 | + position: relative; |
| 161 | +} |
| 162 | +
|
| 163 | +.warning-invisible { |
| 164 | + pointer-events: none; |
| 165 | + opacity: 0; |
| 166 | +} |
| 167 | +
|
| 168 | +.conflict { |
| 169 | + transition: 200ms ease; |
| 170 | + font-size: 1rem; |
| 171 | + gap: 1rem; |
| 172 | + position: absolute; |
| 173 | + top: -3.5rem; |
| 174 | + user-select: none; |
| 175 | + background: rgba(181, 77, 12, 0.472); |
| 176 | + padding-top: 0.25rem; |
| 177 | + padding-bottom: 4.25rem; |
| 178 | + backdrop-filter: blur(10px); |
| 179 | + -webkit-backdrop-filter: blur(10px); |
| 180 | + bottom: 0; |
| 181 | + border-radius: 2rem; |
| 182 | + color: #ffdbcfe0; |
| 183 | +} |
| 184 | +
|
| 185 | +
|
| 186 | +.suggestions { |
| 187 | + transition: 200ms ease; |
| 188 | + position: absolute; |
| 189 | + top: 140%; |
| 190 | + left: 0; |
| 191 | + width:100%; |
| 192 | + background: #11111155; |
| 193 | + --webkit-backdrop-filter: blur(10px); |
| 194 | + backdrop-filter: blur(10px); |
| 195 | + color: #ffffffc8; |
| 196 | + z-index: 4; |
| 197 | + border-radius: 1rem; |
| 198 | + max-height: 15rem; |
| 199 | + overflow-y: auto; |
| 200 | + .suggestion { |
| 201 | + padding: 1rem 2.5rem; |
| 202 | + font-size: 1rem; |
| 203 | + cursor: pointer; |
| 204 | + transition: 200ms ease all; |
| 205 | + border-top: solid 1px #ffffff24; |
| 206 | + &:first-child { |
| 207 | + border-top: none; |
| 208 | + } |
| 209 | + &:hover { |
| 210 | + background: #11111183; |
| 211 | + } |
| 212 | + gap: .5rem; |
| 213 | + } |
| 214 | +} |
| 215 | +
|
61 | 216 | .wrap {
|
62 |
| - max-width: 90%; |
| 217 | + width: 100%; |
63 | 218 | width: 45rem;
|
64 | 219 | height: calc(4rem + 2px);
|
65 | 220 | font-size: 2rem;
|
|
0 commit comments