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