2018-05-02 02:05:36 +02:00
|
|
|
<span class="compose-box-length {overLimit ? 'over-char-limit' : ''}"
|
|
|
|
aria-label={lengthLabel}>
|
|
|
|
{lengthToDisplayDeferred}
|
2018-02-27 06:50:03 +01:00
|
|
|
</span>
|
|
|
|
<style>
|
|
|
|
.compose-box-length {
|
|
|
|
grid-area: length;
|
|
|
|
justify-self: right;
|
|
|
|
color: var(--main-theme-color);
|
|
|
|
font-size: 1.3em;
|
|
|
|
align-self: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.compose-box-length.over-char-limit {
|
|
|
|
color: var(--warning-color);
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
<script>
|
|
|
|
import { mark, stop } from '../../_utils/marks'
|
2018-02-27 07:22:56 +01:00
|
|
|
import { store } from '../../_store/store'
|
2018-03-13 04:18:34 +01:00
|
|
|
import { scheduleIdleTask } from '../../_utils/scheduleIdleTask'
|
2018-04-30 17:29:04 +02:00
|
|
|
import { observe } from 'svelte-extras'
|
2018-02-27 06:50:03 +01:00
|
|
|
|
|
|
|
export default {
|
2018-04-20 06:38:01 +02:00
|
|
|
oncreate () {
|
2018-04-19 18:37:05 +02:00
|
|
|
let { lengthToDisplay } = this.get()
|
2018-08-30 06:42:57 +02:00
|
|
|
this.set({ lengthToDisplayDeferred: lengthToDisplay })
|
2018-02-27 07:22:56 +01:00
|
|
|
// perf improvement for keyboard input latency
|
2018-03-13 04:18:34 +01:00
|
|
|
this.observe('lengthToDisplay', () => {
|
|
|
|
scheduleIdleTask(() => {
|
|
|
|
mark('set lengthToDisplayDeferred')
|
2018-05-05 05:09:20 +02:00
|
|
|
let { lengthToDisplay } = this.get()
|
2018-08-30 06:42:57 +02:00
|
|
|
this.set({ lengthToDisplayDeferred: lengthToDisplay })
|
2018-03-13 04:18:34 +01:00
|
|
|
stop('set lengthToDisplayDeferred')
|
2018-02-27 06:50:03 +01:00
|
|
|
})
|
2018-08-30 06:42:57 +02:00
|
|
|
}, { init: false })
|
2018-02-27 06:50:03 +01:00
|
|
|
},
|
2018-04-30 07:13:41 +02:00
|
|
|
data: () => ({
|
|
|
|
lengthToDisplayDeferred: 0
|
|
|
|
}),
|
2018-02-27 07:22:56 +01:00
|
|
|
store: () => store,
|
2018-02-27 06:50:03 +01:00
|
|
|
computed: {
|
2018-08-26 21:14:16 +02:00
|
|
|
lengthToDisplay: ({ length, $maxStatusChars }) => $maxStatusChars - length,
|
2018-05-02 02:05:36 +02:00
|
|
|
lengthLabel: ({ overLimit, lengthToDisplayDeferred }) => {
|
2018-03-04 01:12:48 +01:00
|
|
|
if (overLimit) {
|
2018-03-13 04:18:34 +01:00
|
|
|
return `${lengthToDisplayDeferred} characters over limit`
|
2018-02-27 06:50:03 +01:00
|
|
|
} else {
|
2018-03-13 04:18:34 +01:00
|
|
|
return `${lengthToDisplayDeferred} characters remaining`
|
2018-02-27 06:50:03 +01:00
|
|
|
}
|
|
|
|
}
|
2018-04-30 17:29:04 +02:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
observe
|
2018-02-27 06:50:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|