2018-04-10 01:30:15 +00:00
|
|
|
<div class="compose-media">
|
2018-12-04 07:23:29 +00:00
|
|
|
<img src={mediaItem.data.preview_url} {alt} />
|
2018-04-10 01:30:15 +00:00
|
|
|
<div class="compose-media-delete">
|
|
|
|
<button class="compose-media-delete-button"
|
2018-12-04 07:23:29 +00:00
|
|
|
aria-label="Delete {shortName}"
|
2018-04-10 01:30:15 +00:00
|
|
|
on:click="onDeleteMedia()" >
|
|
|
|
<svg class="compose-media-delete-button-svg">
|
2018-12-10 08:13:54 +00:00
|
|
|
<use xlink:href="#fa-times" />
|
2018-04-10 01:30:15 +00:00
|
|
|
</svg>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<div class="compose-media-alt">
|
2018-12-04 07:23:29 +00:00
|
|
|
<input id="compose-media-input-{uuid}"
|
|
|
|
type="text"
|
2018-08-18 05:44:53 +00:00
|
|
|
class="compose-media-alt-input"
|
2018-04-10 01:30:15 +00:00
|
|
|
placeholder="Description"
|
|
|
|
bind:value=rawText
|
|
|
|
>
|
2018-12-04 07:23:29 +00:00
|
|
|
<label for="compose-media-input-{uuid}" class="sr-only">
|
|
|
|
Describe {shortName} for the visually impaired
|
|
|
|
</label>
|
2018-04-10 01:30:15 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<style>
|
|
|
|
.compose-media {
|
|
|
|
height: 200px;
|
|
|
|
overflow: hidden;
|
|
|
|
flex-direction: column;
|
|
|
|
position: relative;
|
|
|
|
display: flex;
|
|
|
|
background: var(--main-bg);
|
|
|
|
}
|
|
|
|
.compose-media img {
|
|
|
|
object-fit: contain;
|
|
|
|
object-position: center center;
|
|
|
|
flex: 1;
|
|
|
|
height: 100%;
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
.compose-media-alt {
|
|
|
|
z-index: 10;
|
|
|
|
position: absolute;
|
|
|
|
bottom: 0;
|
|
|
|
left: 0;
|
|
|
|
right: 0;
|
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
|
|
|
}
|
2018-08-18 05:44:53 +00:00
|
|
|
.compose-media-alt-input {
|
2018-04-10 01:30:15 +00:00
|
|
|
width: 100%;
|
|
|
|
font-size: 1.2em;
|
|
|
|
background: var(--alt-input-bg);
|
2018-08-18 05:44:53 +00:00
|
|
|
color: var(--body-text-color);
|
2018-04-10 01:30:15 +00:00
|
|
|
}
|
2018-08-18 05:44:53 +00:00
|
|
|
.compose-media-alt-input:focus {
|
2018-04-10 01:30:15 +00:00
|
|
|
background: var(--main-bg);
|
|
|
|
}
|
|
|
|
.compose-media-delete {
|
|
|
|
position: absolute;
|
|
|
|
z-index: 10;
|
|
|
|
top: 0;
|
|
|
|
right: 0;
|
|
|
|
left: 0;
|
|
|
|
display: flex;
|
|
|
|
justify-content: flex-end;
|
|
|
|
margin: 2px;
|
|
|
|
}
|
|
|
|
.compose-media-delete-button {
|
|
|
|
padding: 10px;
|
|
|
|
background: none;
|
|
|
|
border: none;
|
|
|
|
}
|
|
|
|
.compose-media-delete-button:hover {
|
|
|
|
background: var(--toast-border);
|
|
|
|
}
|
|
|
|
.compose-media-delete-button-svg {
|
|
|
|
fill: var(--button-text);
|
|
|
|
width: 18px;
|
|
|
|
height: 18px;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
<script>
|
|
|
|
import { store } from '../../_store/store'
|
|
|
|
import { deleteMedia } from '../../_actions/media'
|
|
|
|
import debounce from 'lodash-es/debounce'
|
|
|
|
import { scheduleIdleTask } from '../../_utils/scheduleIdleTask'
|
2018-04-30 15:29:04 +00:00
|
|
|
import { observe } from 'svelte-extras'
|
2018-04-10 01:30:15 +00:00
|
|
|
|
|
|
|
export default {
|
2018-04-20 04:38:01 +00:00
|
|
|
oncreate () {
|
2018-04-10 01:30:15 +00:00
|
|
|
this.setupSyncFromStore()
|
|
|
|
this.setupSyncToStore()
|
|
|
|
},
|
|
|
|
data: () => ({
|
|
|
|
rawText: ''
|
|
|
|
}),
|
2018-12-04 07:23:29 +00:00
|
|
|
computed: {
|
|
|
|
filename: ({ mediaItem }) => mediaItem.file && mediaItem.file.name,
|
|
|
|
alt: ({ filename, mediaItem }) => (
|
|
|
|
// sometimes we no longer have the file, e.g. in a delete and redraft situation,
|
|
|
|
// so fall back to the description if it was provided
|
|
|
|
filename || mediaItem.description || ''
|
|
|
|
),
|
|
|
|
shortName: ({ filename }) => filename || 'media',
|
|
|
|
uuid: ({ realm, mediaItem }) => `${realm}-${mediaItem.data.id}`
|
|
|
|
},
|
2018-04-10 01:30:15 +00:00
|
|
|
store: () => store,
|
|
|
|
methods: {
|
2018-04-30 15:29:04 +00:00
|
|
|
observe,
|
2018-04-20 04:38:01 +00:00
|
|
|
setupSyncFromStore () {
|
2018-08-27 01:54:59 +00:00
|
|
|
this.observe('media', media => {
|
|
|
|
media = media || []
|
2018-04-19 16:37:05 +00:00
|
|
|
let { index, rawText } = this.get()
|
2018-08-27 01:54:59 +00:00
|
|
|
let text = (media[index] && media[index].description) || ''
|
2018-04-19 16:37:05 +00:00
|
|
|
if (rawText !== text) {
|
2018-08-30 04:42:57 +00:00
|
|
|
this.set({ rawText: text })
|
2018-04-10 01:30:15 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
2018-04-20 04:38:01 +00:00
|
|
|
setupSyncToStore () {
|
2018-04-10 01:30:15 +00:00
|
|
|
const saveStore = debounce(() => scheduleIdleTask(() => this.store.save()), 1000)
|
|
|
|
|
|
|
|
this.observe('rawText', rawText => {
|
2018-08-27 01:54:59 +00:00
|
|
|
let { realm, index, media } = this.get()
|
|
|
|
if (media[index].description === rawText) {
|
2018-04-10 01:30:15 +00:00
|
|
|
return
|
|
|
|
}
|
2018-08-27 01:54:59 +00:00
|
|
|
media[index].description = rawText
|
2018-12-17 19:28:31 +00:00
|
|
|
this.store.setComposeData(realm, { media })
|
2018-04-10 01:30:15 +00:00
|
|
|
saveStore()
|
2018-08-30 04:42:57 +00:00
|
|
|
}, { init: false })
|
2018-04-10 01:30:15 +00:00
|
|
|
},
|
2018-04-20 04:38:01 +00:00
|
|
|
onDeleteMedia () {
|
2018-04-19 16:37:05 +00:00
|
|
|
let {
|
|
|
|
realm,
|
|
|
|
index
|
|
|
|
} = this.get()
|
|
|
|
deleteMedia(realm, index)
|
2018-04-10 01:30:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-12-04 07:23:29 +00:00
|
|
|
</script>
|