commit
783cc00dd0
@ -1,5 +1,9 @@
|
||||
<template>
|
||||
<conversation :collapsable="false" :statusoid="statusoid"></conversation>
|
||||
<conversation
|
||||
:collapsable="false"
|
||||
isPage="true"
|
||||
:statusoid="statusoid"
|
||||
></conversation>
|
||||
</template>
|
||||
|
||||
<script src="./conversation-page.js"></script>
|
||||
|
@ -1,26 +1,42 @@
|
||||
<template>
|
||||
<div class="timeline panel panel-default">
|
||||
<div class="panel-heading conversation-heading">
|
||||
<div class="timeline panel-default" :class="[isExpanded ? 'panel' : 'panel-disabled']">
|
||||
<div v-if="isExpanded" class="panel-heading conversation-heading">
|
||||
<span class="title"> {{ $t('timeline.conversation') }} </span>
|
||||
<span v-if="collapsable">
|
||||
<a href="#" @click.prevent="$emit('toggleExpanded')">{{ $t('timeline.collapse') }}</a>
|
||||
<a href="#" @click.prevent="toggleExpanded">{{ $t('timeline.collapse') }}</a>
|
||||
</span>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="timeline">
|
||||
<status
|
||||
v-for="status in conversation"
|
||||
@goto="setHighlight" :key="status.id"
|
||||
:inlineExpanded="collapsable" :statusoid="status"
|
||||
:expandable='false' :focused="focused(status.id)"
|
||||
:inConversation='true'
|
||||
:highlight="highlight"
|
||||
@goto="setHighlight"
|
||||
@toggleExpanded="toggleExpanded"
|
||||
:key="status.id"
|
||||
:inlineExpanded="collapsable"
|
||||
:statusoid="status"
|
||||
:expandable='!expanded'
|
||||
:focused="focused(status.id)"
|
||||
:inConversation="isExpanded"
|
||||
:highlight="getHighlight()"
|
||||
:replies="getReplies(status.id)"
|
||||
class="status-fadein">
|
||||
</status>
|
||||
</div>
|
||||
</div>
|
||||
class="status-fadein panel-body"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script src="./conversation.js"></script>
|
||||
|
||||
<style lang="scss">
|
||||
@import '../../_variables.scss';
|
||||
|
||||
.timeline {
|
||||
.panel-disabled {
|
||||
.status-el {
|
||||
border-left: none;
|
||||
border-bottom-width: 1px;
|
||||
border-bottom-style: solid;
|
||||
border-color: var(--border, $fallback--border);
|
||||
border-radius: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
@ -0,0 +1,107 @@
|
||||
import Completion from '../../services/completion/completion.js'
|
||||
import { take, filter, map } from 'lodash'
|
||||
|
||||
const EmojiInput = {
|
||||
props: [
|
||||
'value',
|
||||
'placeholder',
|
||||
'type',
|
||||
'classname'
|
||||
],
|
||||
data () {
|
||||
return {
|
||||
highlighted: 0,
|
||||
caret: 0
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
suggestions () {
|
||||
const firstchar = this.textAtCaret.charAt(0)
|
||||
if (firstchar === ':') {
|
||||
if (this.textAtCaret === ':') { return }
|
||||
const matchedEmoji = filter(this.emoji.concat(this.customEmoji), (emoji) => emoji.shortcode.startsWith(this.textAtCaret.slice(1)))
|
||||
if (matchedEmoji.length <= 0) {
|
||||
return false
|
||||
}
|
||||
return map(take(matchedEmoji, 5), ({shortcode, image_url, utf}, index) => ({
|
||||
shortcode: `:${shortcode}:`,
|
||||
utf: utf || '',
|
||||
// eslint-disable-next-line camelcase
|
||||
img: utf ? '' : this.$store.state.instance.server + image_url,
|
||||
highlighted: index === this.highlighted
|
||||
}))
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
},
|
||||
textAtCaret () {
|
||||
return (this.wordAtCaret || {}).word || ''
|
||||
},
|
||||
wordAtCaret () {
|
||||
const word = Completion.wordAtPosition(this.value, this.caret - 1) || {}
|
||||
return word
|
||||
},
|
||||
emoji () {
|
||||
return this.$store.state.instance.emoji || []
|
||||
},
|
||||
customEmoji () {
|
||||
return this.$store.state.instance.customEmoji || []
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
replace (replacement) {
|
||||
const newValue = Completion.replaceWord(this.value, this.wordAtCaret, replacement)
|
||||
this.$emit('input', newValue)
|
||||
this.caret = 0
|
||||
},
|
||||
replaceEmoji (e) {
|
||||
const len = this.suggestions.length || 0
|
||||
if (this.textAtCaret === ':' || e.ctrlKey) { return }
|
||||
if (len > 0) {
|
||||
e.preventDefault()
|
||||
const emoji = this.suggestions[this.highlighted]
|
||||
const replacement = emoji.utf || (emoji.shortcode + ' ')
|
||||
const newValue = Completion.replaceWord(this.value, this.wordAtCaret, replacement)
|
||||
this.$emit('input', newValue)
|
||||
this.caret = 0
|
||||
this.highlighted = 0
|
||||
}
|
||||
},
|
||||
cycleBackward (e) {
|
||||
const len = this.suggestions.length || 0
|
||||
if (len > 0) {
|
||||
e.preventDefault()
|
||||
this.highlighted -= 1
|
||||
if (this.highlighted < 0) {
|
||||
this.highlighted = this.suggestions.length - 1
|
||||
}
|
||||
} else {
|
||||
this.highlighted = 0
|
||||
}
|
||||
},
|
||||
cycleForward (e) {
|
||||
const len = this.suggestions.length || 0
|
||||
if (len > 0) {
|
||||
if (e.shiftKey) { return }
|
||||
e.preventDefault()
|
||||
this.highlighted += 1
|
||||
if (this.highlighted >= len) {
|
||||
this.highlighted = 0
|
||||
}
|
||||
} else {
|
||||
this.highlighted = 0
|
||||
}
|
||||
},
|
||||
onKeydown (e) {
|
||||
e.stopPropagation()
|
||||
},
|
||||
onInput (e) {
|
||||
this.$emit('input', e.target.value)
|
||||
},
|
||||
setCaret ({target: {selectionStart}}) {
|
||||
this.caret = selectionStart
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default EmojiInput
|
@ -0,0 +1,64 @@
|
||||
<template>
|
||||
<div class="emoji-input">
|
||||
<input
|
||||
v-if="type !== 'textarea'"
|
||||
:class="classname"
|
||||
:type="type"
|
||||
:value="value"
|
||||
:placeholder="placeholder"
|
||||
@input="onInput"
|
||||
@click="setCaret"
|
||||
@keyup="setCaret"
|
||||
@keydown="onKeydown"
|
||||
@keydown.down="cycleForward"
|
||||
@keydown.up="cycleBackward"
|
||||
@keydown.shift.tab="cycleBackward"
|
||||
@keydown.tab="cycleForward"
|
||||
@keydown.enter="replaceEmoji"
|
||||
/>
|
||||
<textarea
|
||||
v-else
|
||||
:class="classname"
|
||||
:value="value"
|
||||
:placeholder="placeholder"
|
||||
@input="onInput"
|
||||
@click="setCaret"
|
||||
@keyup="setCaret"
|
||||
@keydown="onKeydown"
|
||||
@keydown.down="cycleForward"
|
||||
@keydown.up="cycleBackward"
|
||||
@keydown.shift.tab="cycleBackward"
|
||||
@keydown.tab="cycleForward"
|
||||
@keydown.enter="replaceEmoji"
|
||||
></textarea>
|
||||
<div class="autocomplete-panel" v-if="suggestions">
|
||||
<div class="autocomplete-panel-body">
|
||||
<div
|
||||
v-for="(emoji, index) in suggestions"
|
||||
:key="index"
|
||||
@click="replace(emoji.utf || (emoji.shortcode + ' '))"
|
||||
class="autocomplete-item"
|
||||
:class="{ highlighted: emoji.highlighted }"
|
||||
>
|
||||
<span v-if="emoji.img">
|
||||
<img :src="emoji.img" />
|
||||
</span>
|
||||
<span v-else>{{emoji.utf}}</span>
|
||||
<span>{{emoji.shortcode}}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script src="./emoji-input.js"></script>
|
||||
|
||||
<style lang="scss">
|
||||
@import '../../_variables.scss';
|
||||
|
||||
.emoji-input {
|
||||
.form-control {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
</style>
|
@ -1,22 +0,0 @@
|
||||
import Status from '../status/status.vue'
|
||||
import Conversation from '../conversation/conversation.vue'
|
||||
|
||||
const statusOrConversation = {
|
||||
props: ['statusoid'],
|
||||
data () {
|
||||
return {
|
||||
expanded: false
|
||||
}
|
||||
},
|
||||
components: {
|
||||
Status,
|
||||
Conversation
|
||||
},
|
||||
methods: {
|
||||
toggleExpanded () {
|
||||
this.expanded = !this.expanded
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default statusOrConversation
|
@ -1,14 +0,0 @@
|
||||
<template>
|
||||
<div>
|
||||
<conversation v-if="expanded" @toggleExpanded="toggleExpanded" :collapsable="true" :statusoid="statusoid"></conversation>
|
||||
<status v-if="!expanded" @toggleExpanded="toggleExpanded" :expandable="true" :inConversation="false" :focused="false" :statusoid="statusoid"></status>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script src="./status_or_conversation.js"></script>
|
||||
|
||||
<style lang="scss">
|
||||
.spacer {
|
||||
height: 1em
|
||||
}
|
||||
</style>
|
@ -0,0 +1,74 @@
|
||||
|
||||
const DIRECTION_LEFT = [-1, 0]
|
||||
const DIRECTION_RIGHT = [1, 0]
|
||||
const DIRECTION_UP = [0, -1]
|
||||
const DIRECTION_DOWN = [0, 1]
|
||||
|
||||
const deltaCoord = (oldCoord, newCoord) => [newCoord[0] - oldCoord[0], newCoord[1] - oldCoord[1]]
|
||||
|
||||
const touchEventCoord = e => ([e.touches[0].screenX, e.touches[0].screenY])
|
||||
|
||||
const vectorLength = v => Math.sqrt(v[0] * v[0] + v[1] * v[1])
|
||||
|
||||
const perpendicular = v => [v[1], -v[0]]
|
||||
|
||||
const dotProduct = (v1, v2) => v1[0] * v2[0] + v1[1] * v2[1]
|
||||
|
||||
const project = (v1, v2) => {
|
||||
const scalar = (dotProduct(v1, v2) / dotProduct(v2, v2))
|
||||
return [scalar * v2[0], scalar * v2[1]]
|
||||
}
|
||||
|
||||
// direction: either use the constants above or an arbitrary 2d vector.
|
||||
// threshold: how many Px to move from touch origin before checking if the
|
||||
// callback should be called.
|
||||
// divergentTolerance: a scalar for much of divergent direction we tolerate when
|
||||
// above threshold. for example, with 1.0 we only call the callback if
|
||||
// divergent component of delta is < 1.0 * direction component of delta.
|
||||
const swipeGesture = (direction, onSwipe, threshold = 30, perpendicularTolerance = 1.0) => {
|
||||
return {
|
||||
direction,
|
||||
onSwipe,
|
||||
threshold,
|
||||
perpendicularTolerance,
|
||||
_startPos: [0, 0],
|
||||
_swiping: false
|
||||
}
|
||||
}
|
||||
|
||||
const beginSwipe = (event, gesture) => {
|
||||
gesture._startPos = touchEventCoord(event)
|
||||
gesture._swiping = true
|
||||
}
|
||||
|
||||
const updateSwipe = (event, gesture) => {
|
||||
if (!gesture._swiping) return
|
||||
// movement too small
|
||||
const delta = deltaCoord(gesture._startPos, touchEventCoord(event))
|
||||
if (vectorLength(delta) < gesture.threshold) return
|
||||
// movement is opposite from direction
|
||||
if (dotProduct(delta, gesture.direction) < 0) return
|
||||
// movement perpendicular to direction is too much
|
||||
const towardsDir = project(delta, gesture.direction)
|
||||
const perpendicularDir = perpendicular(gesture.direction)
|
||||
const towardsPerpendicular = project(delta, perpendicularDir)
|
||||
if (
|
||||
vectorLength(towardsDir) * gesture.perpendicularTolerance <
|
||||
vectorLength(towardsPerpendicular)
|
||||
) return
|
||||
|
||||
gesture.onSwipe()
|
||||
gesture._swiping = false
|
||||
}
|
||||
|
||||
const GestureService = {
|
||||
DIRECTION_LEFT,
|
||||
DIRECTION_RIGHT,
|
||||
DIRECTION_UP,
|
||||
DIRECTION_DOWN,
|
||||
swipeGesture,
|
||||
beginSwipe,
|
||||
updateSwipe
|
||||
}
|
||||
|
||||
export default GestureService
|
@ -0,0 +1,120 @@
|
||||
import GestureService from 'src/services/gesture_service/gesture_service.js'
|
||||
|
||||
const mockTouchEvent = (x, y) => ({
|
||||
touches: [
|
||||
{
|
||||
screenX: x,
|
||||
screenY: y
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
describe.only('GestureService', () => {
|
||||
describe('swipeGesture', () => {
|
||||
it('calls the callback on a successful swipe', () => {
|
||||
let swiped = false
|
||||
const callback = () => { swiped = true }
|
||||
const gesture = GestureService.swipeGesture(
|
||||
GestureService.DIRECTION_RIGHT,
|
||||
callback
|
||||
)
|
||||
|
||||
GestureService.beginSwipe(mockTouchEvent(100, 100), gesture)
|
||||
GestureService.updateSwipe(mockTouchEvent(200, 100), gesture)
|
||||
|
||||
expect(swiped).to.eql(true)
|
||||
})
|
||||
|
||||
it('calls the callback only once per begin', () => {
|
||||
let hits = 0
|
||||
const callback = () => { hits += 1 }
|
||||
const gesture = GestureService.swipeGesture(
|
||||
GestureService.DIRECTION_RIGHT,
|
||||
callback
|
||||
)
|
||||
|
||||
GestureService.beginSwipe(mockTouchEvent(100, 100), gesture)
|
||||
GestureService.updateSwipe(mockTouchEvent(150, 100), gesture)
|
||||
GestureService.updateSwipe(mockTouchEvent(200, 100), gesture)
|
||||
|
||||
expect(hits).to.eql(1)
|
||||
})
|
||||
|
||||
it('doesn\'t call the callback on an opposite swipe', () => {
|
||||
let swiped = false
|
||||
const callback = () => { swiped = true }
|
||||
const gesture = GestureService.swipeGesture(
|
||||
GestureService.DIRECTION_RIGHT,
|
||||
callback
|
||||
)
|
||||
|
||||
GestureService.beginSwipe(mockTouchEvent(100, 100), gesture)
|
||||
GestureService.updateSwipe(mockTouchEvent(0, 100), gesture)
|
||||
|
||||
expect(swiped).to.eql(false)
|
||||
})
|
||||
|
||||
it('doesn\'t call the callback on a swipe below threshold', () => {
|
||||
let swiped = false
|
||||
const callback = () => { swiped = true }
|
||||
const gesture = GestureService.swipeGesture(
|
||||
GestureService.DIRECTION_RIGHT,
|
||||
callback,
|
||||
100
|
||||
)
|
||||
|
||||
GestureService.beginSwipe(mockTouchEvent(100, 100), gesture)
|
||||
GestureService.updateSwipe(mockTouchEvent(150, 100), gesture)
|
||||
|
||||
expect(swiped).to.eql(false)
|
||||
})
|
||||
|
||||
it('doesn\'t call the callback on a perpendicular swipe', () => {
|
||||
let swiped = false
|
||||
const callback = () => { swiped = true }
|
||||
const gesture = GestureService.swipeGesture(
|
||||
GestureService.DIRECTION_RIGHT,
|
||||
callback,
|
||||
30,
|
||||
0.5
|
||||
)
|
||||
|
||||
GestureService.beginSwipe(mockTouchEvent(100, 100), gesture)
|
||||
GestureService.updateSwipe(mockTouchEvent(150, 200), gesture)
|
||||
|
||||
expect(swiped).to.eql(false)
|
||||
})
|
||||
|
||||
it('calls the callback on perpendicular swipe if within tolerance', () => {
|
||||
let swiped = false
|
||||
const callback = () => { swiped = true }
|
||||
const gesture = GestureService.swipeGesture(
|
||||
GestureService.DIRECTION_RIGHT,
|
||||
callback,
|
||||
30,
|
||||
2.0
|
||||
)
|
||||
|
||||
GestureService.beginSwipe(mockTouchEvent(100, 100), gesture)
|
||||
GestureService.updateSwipe(mockTouchEvent(150, 150), gesture)
|
||||
|
||||
expect(swiped).to.eql(true)
|
||||
})
|
||||
|
||||
it('works with any arbitrary 2d directions', () => {
|
||||
let swiped = false
|
||||
const callback = () => { swiped = true }
|
||||
const gesture = GestureService.swipeGesture(
|
||||
[-1, -1],
|
||||
callback,
|
||||
30,
|
||||
0.1
|
||||
)
|
||||
|
||||
GestureService.beginSwipe(mockTouchEvent(100, 100), gesture)
|
||||
GestureService.updateSwipe(mockTouchEvent(60, 60), gesture)
|
||||
|
||||
expect(swiped).to.eql(true)
|
||||
})
|
||||
})
|
||||
})
|
Loading…
Reference in new issue