2018-05-02 00:05:36 +00:00
|
|
|
<div class="compose-autosuggest {shown ? 'shown' : ''} {realm === 'dialog' ? 'is-dialog' : ''}"
|
2018-04-06 04:35:22 +00:00
|
|
|
aria-hidden="true" >
|
2018-03-25 01:04:54 +00:00
|
|
|
<ComposeAutosuggestionList
|
2018-05-06 23:25:17 +00:00
|
|
|
items={autosuggestSearchResults}
|
2018-03-25 19:24:38 +00:00
|
|
|
on:click="onClick(event)"
|
2018-05-06 23:25:17 +00:00
|
|
|
type={autosuggestType}
|
|
|
|
selected={autosuggestSelected}
|
2018-03-25 01:04:54 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<style>
|
|
|
|
.compose-autosuggest {
|
2018-04-06 04:35:22 +00:00
|
|
|
position: absolute;
|
|
|
|
left: 5px;
|
|
|
|
top: 0;
|
2018-03-25 01:04:54 +00:00
|
|
|
pointer-events: none;
|
2018-04-06 04:35:22 +00:00
|
|
|
opacity: 0;
|
2018-03-25 01:04:54 +00:00
|
|
|
transition: opacity 0.1s linear;
|
|
|
|
min-width: 400px;
|
|
|
|
max-width: calc(100vw - 20px);
|
2018-04-06 04:35:22 +00:00
|
|
|
z-index: 7000;
|
|
|
|
}
|
|
|
|
.compose-autosuggest.is-dialog {
|
|
|
|
z-index: 11000;
|
2018-03-25 01:04:54 +00:00
|
|
|
}
|
|
|
|
.compose-autosuggest.shown {
|
|
|
|
pointer-events: auto;
|
2018-04-06 04:35:22 +00:00
|
|
|
opacity: 1;
|
2018-03-25 01:04:54 +00: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-06 04:35:22 +00:00
|
|
|
min-width: 0;
|
2018-03-25 01:04:54 +00:00
|
|
|
width: calc(100vw - 20px);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
</style>
|
|
|
|
<script>
|
|
|
|
import { store } from '../../_store/store'
|
|
|
|
import ComposeAutosuggestionList from './ComposeAutosuggestionList.html'
|
2018-12-23 18:10:16 +00:00
|
|
|
import { get } from '../../_utils/lodash-lite'
|
2018-05-06 23:25:17 +00:00
|
|
|
import { selectAutosuggestItem } from '../../_actions/autosuggest'
|
2018-04-30 15:29:04 +00:00
|
|
|
import { observe } from 'svelte-extras'
|
2018-05-06 23:25:17 +00:00
|
|
|
import { once } from '../../_utils/once'
|
2018-03-25 01:04:54 +00:00
|
|
|
|
|
|
|
export default {
|
2018-04-20 04:38:01 +00:00
|
|
|
oncreate () {
|
2018-05-06 23:25:17 +00:00
|
|
|
this._promiseChain = Promise.resolve()
|
|
|
|
this.observe('shouldBeShown', (shouldBeShown) => {
|
2018-03-25 01:04:54 +00: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 23:25:17 +00: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(() => {
|
2018-08-30 04:42:57 +00:00
|
|
|
this.set({ shown: shouldBeShown })
|
2018-03-25 01:04:54 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
|
|
|
methods: {
|
2018-04-30 15:29:04 +00:00
|
|
|
observe,
|
2018-04-30 05:13:41 +00:00
|
|
|
once,
|
2018-04-20 04:38:01 +00:00
|
|
|
onClick (item) {
|
2018-03-25 19:24:38 +00:00
|
|
|
this.fire('autosuggestItemSelected')
|
2018-05-06 23:25:17 +00:00
|
|
|
selectAutosuggestItem(item)
|
2018-03-25 01:04:54 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
2018-05-06 23:25:17 +00: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-25 01:04:54 +00:00
|
|
|
},
|
2018-04-30 05:13:41 +00:00
|
|
|
data: () => ({
|
2018-05-06 23:25:17 +00:00
|
|
|
shown: false
|
2018-04-30 05:13:41 +00:00
|
|
|
}),
|
2018-03-25 01:04:54 +00:00
|
|
|
store: () => store,
|
|
|
|
components: {
|
|
|
|
ComposeAutosuggestionList
|
|
|
|
}
|
|
|
|
}
|
2018-12-23 18:10:16 +00:00
|
|
|
</script>
|