| 
									
										
										
										
											2018-05-01 17:05:36 -07:00
										 |  |  | <div class="compose-autosuggest {shown ? 'shown' : ''} {realm === 'dialog' ? 'is-dialog' : ''}" | 
					
						
							| 
									
										
										
										
											2018-04-05 21:35:22 -07:00
										 |  |  |        aria-hidden="true" > | 
					
						
							| 
									
										
										
										
											2018-03-24 18:04:54 -07:00
										 |  |  |   <ComposeAutosuggestionList | 
					
						
							| 
									
										
										
										
											2018-05-06 16:25:17 -07:00
										 |  |  |     items={autosuggestSearchResults} | 
					
						
							| 
									
										
										
										
											2018-03-25 12:24:38 -07:00
										 |  |  |     on:click="onClick(event)" | 
					
						
							| 
									
										
										
										
											2018-05-06 16:25:17 -07:00
										 |  |  |     type={autosuggestType} | 
					
						
							|  |  |  |     selected={autosuggestSelected} | 
					
						
							| 
									
										
										
										
											2018-03-24 18:04:54 -07:00
										 |  |  |   /> | 
					
						
							|  |  |  | </div> | 
					
						
							|  |  |  | <style> | 
					
						
							|  |  |  |   .compose-autosuggest { | 
					
						
							| 
									
										
										
										
											2018-04-05 21:35:22 -07:00
										 |  |  |     position: absolute; | 
					
						
							|  |  |  |     left: 5px; | 
					
						
							|  |  |  |     top: 0; | 
					
						
							| 
									
										
										
										
											2018-03-24 18:04:54 -07:00
										 |  |  |     pointer-events: none; | 
					
						
							| 
									
										
										
										
											2018-04-05 21:35:22 -07:00
										 |  |  |     opacity: 0; | 
					
						
							| 
									
										
										
										
											2018-03-24 18:04:54 -07:00
										 |  |  |     transition: opacity 0.1s linear; | 
					
						
							|  |  |  |     min-width: 400px; | 
					
						
							|  |  |  |     max-width: calc(100vw - 20px); | 
					
						
							| 
									
										
										
										
											2018-04-05 21:35:22 -07:00
										 |  |  |     z-index: 7000; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   .compose-autosuggest.is-dialog { | 
					
						
							|  |  |  |     z-index: 11000; | 
					
						
							| 
									
										
										
										
											2018-03-24 18:04:54 -07:00
										 |  |  |   } | 
					
						
							|  |  |  |   .compose-autosuggest.shown { | 
					
						
							|  |  |  |     pointer-events: auto; | 
					
						
							| 
									
										
										
										
											2018-04-05 21:35:22 -07:00
										 |  |  |     opacity: 1; | 
					
						
							| 
									
										
										
										
											2018-03-24 18:04:54 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @media (max-width: 479px) { | 
					
						
							|  |  |  |     .compose-autosuggest { | 
					
						
							|  |  |  |       /* hack: move this over to the left on mobile so it's easier to see */ | 
					
						
							|  |  |  |       transform: translateX(-58px); /* avatar size 48px + 10px padding */ | 
					
						
							| 
									
										
										
										
											2018-04-05 21:35:22 -07:00
										 |  |  |       min-width: 0; | 
					
						
							| 
									
										
										
										
											2018-03-24 18:04:54 -07:00
										 |  |  |       width: calc(100vw - 20px); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | </style> | 
					
						
							|  |  |  | <script> | 
					
						
							|  |  |  |   import { store } from '../../_store/store' | 
					
						
							|  |  |  |   import ComposeAutosuggestionList from './ComposeAutosuggestionList.html' | 
					
						
							| 
									
										
										
										
											2018-05-06 16:25:17 -07:00
										 |  |  |   import get from 'lodash-es/get' | 
					
						
							|  |  |  |   import { selectAutosuggestItem } from '../../_actions/autosuggest' | 
					
						
							| 
									
										
										
										
											2018-04-30 08:29:04 -07:00
										 |  |  |   import { observe } from 'svelte-extras' | 
					
						
							| 
									
										
										
										
											2018-05-06 16:25:17 -07:00
										 |  |  |   import { once } from '../../_utils/once' | 
					
						
							| 
									
										
										
										
											2018-03-24 18:04:54 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   export default { | 
					
						
							| 
									
										
										
										
											2018-04-19 21:38:01 -07:00
										 |  |  |     oncreate () { | 
					
						
							| 
									
										
										
										
											2018-05-06 16:25:17 -07:00
										 |  |  |       this._promiseChain = Promise.resolve() | 
					
						
							|  |  |  |       this.observe('shouldBeShown', (shouldBeShown) => { | 
					
						
							| 
									
										
										
										
											2018-03-24 18:04:54 -07:00
										 |  |  |         // TODO: hack so that when the user clicks the button, and the textarea blurs, | 
					
						
							|  |  |  |         // we don't immediately hide the dropdown which would cause the click to get lost | 
					
						
							| 
									
										
										
										
											2018-05-06 16:25:17 -07:00
										 |  |  |         this._promiseChain = this._promiseChain.then(() => { | 
					
						
							|  |  |  |           if (!shouldBeShown) { | 
					
						
							|  |  |  |             return Promise.race([ | 
					
						
							|  |  |  |               new Promise(resolve => setTimeout(resolve, 200)), | 
					
						
							|  |  |  |               new Promise(resolve => this.once('autosuggestItemSelected', resolve)) | 
					
						
							|  |  |  |             ]) | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         }).then(() => { | 
					
						
							|  |  |  |           this.set({shown: shouldBeShown}) | 
					
						
							| 
									
										
										
										
											2018-03-24 18:04:54 -07:00
										 |  |  |         }) | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     methods: { | 
					
						
							| 
									
										
										
										
											2018-04-30 08:29:04 -07:00
										 |  |  |       observe, | 
					
						
							| 
									
										
										
										
											2018-04-29 22:13:41 -07:00
										 |  |  |       once, | 
					
						
							| 
									
										
										
										
											2018-04-19 21:38:01 -07:00
										 |  |  |       onClick (item) { | 
					
						
							| 
									
										
										
										
											2018-03-25 12:24:38 -07:00
										 |  |  |         this.fire('autosuggestItemSelected') | 
					
						
							| 
									
										
										
										
											2018-05-06 16:25:17 -07:00
										 |  |  |         selectAutosuggestItem(item) | 
					
						
							| 
									
										
										
										
											2018-03-24 18:04:54 -07:00
										 |  |  |       } | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     computed: { | 
					
						
							| 
									
										
										
										
											2018-05-06 16:25:17 -07:00
										 |  |  |       /* eslint-disable camelcase */ | 
					
						
							|  |  |  |       composeSelectionStart: ({ $autosuggestData_composeSelectionStart, $currentInstance, realm }) => ( | 
					
						
							|  |  |  |         get($autosuggestData_composeSelectionStart, [$currentInstance, realm], 0) | 
					
						
							|  |  |  |       ), | 
					
						
							|  |  |  |       composeFocused: ({ $autosuggestData_composeFocused, $currentInstance, realm }) => ( | 
					
						
							|  |  |  |         get($autosuggestData_composeFocused, [$currentInstance, realm], false) | 
					
						
							|  |  |  |       ), | 
					
						
							|  |  |  |       autosuggestSearchResults: ({ $autosuggestData_autosuggestSearchResults, $currentInstance, realm }) => ( | 
					
						
							|  |  |  |         get($autosuggestData_autosuggestSearchResults, [$currentInstance, realm], []) | 
					
						
							|  |  |  |       ), | 
					
						
							|  |  |  |       autosuggestType: ({ $autosuggestData_autosuggestType, $currentInstance, realm }) => ( | 
					
						
							|  |  |  |         get($autosuggestData_autosuggestType, [$currentInstance, realm]) | 
					
						
							|  |  |  |       ), | 
					
						
							|  |  |  |       autosuggestSelected: ({ $autosuggestData_autosuggestSelected, $currentInstance, realm }) => ( | 
					
						
							|  |  |  |         get($autosuggestData_autosuggestSelected, [$currentInstance, realm], 0) | 
					
						
							|  |  |  |       ), | 
					
						
							|  |  |  |       autosuggestSearchText: ({ $autosuggestData_autosuggestSelected, $currentInstance, realm }) => ( | 
					
						
							|  |  |  |         get($autosuggestData_autosuggestSelected, [$currentInstance, realm]) | 
					
						
							|  |  |  |       ), | 
					
						
							|  |  |  |       /* eslint-enable camelcase */ | 
					
						
							|  |  |  |       shouldBeShown: ({ realm, $autosuggestShown, composeFocused }) => ( | 
					
						
							|  |  |  |         !!($autosuggestShown && composeFocused) | 
					
						
							|  |  |  |       ) | 
					
						
							| 
									
										
										
										
											2018-03-24 18:04:54 -07:00
										 |  |  |     }, | 
					
						
							| 
									
										
										
										
											2018-04-29 22:13:41 -07:00
										 |  |  |     data: () => ({ | 
					
						
							| 
									
										
										
										
											2018-05-06 16:25:17 -07:00
										 |  |  |       shown: false | 
					
						
							| 
									
										
										
										
											2018-04-29 22:13:41 -07:00
										 |  |  |     }), | 
					
						
							| 
									
										
										
										
											2018-03-24 18:04:54 -07:00
										 |  |  |     store: () => store, | 
					
						
							|  |  |  |     components: { | 
					
						
							|  |  |  |       ComposeAutosuggestionList | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | </script> |