2018-02-19 23:13:27 +02:00
|
|
|
<template>
|
2018-11-12 18:04:15 +02:00
|
|
|
<div>
|
2019-02-15 08:35:52 +02:00
|
|
|
<ui-container :show-header="props.design == 0">
|
2019-02-18 02:48:00 +02:00
|
|
|
<template v-slot:header><fa icon="pencil-alt"/>{{ $t('title') }}</template>
|
2018-11-12 18:04:15 +02:00
|
|
|
|
2018-11-13 08:01:05 +02:00
|
|
|
<div class="lhcuptdmcdkfwmipgazeawoiuxpzaclc-body"
|
|
|
|
@dragover.stop="onDragover"
|
|
|
|
@drop.stop="onDrop"
|
|
|
|
>
|
2018-11-12 18:04:15 +02:00
|
|
|
<div class="textarea">
|
|
|
|
<textarea
|
|
|
|
:disabled="posting"
|
|
|
|
v-model="text"
|
|
|
|
@keydown="onKeydown"
|
|
|
|
@paste="onPaste"
|
|
|
|
:placeholder="placeholder"
|
|
|
|
ref="text"
|
2018-12-16 01:45:10 +02:00
|
|
|
v-autocomplete="{ model: 'text' }"
|
2018-11-12 18:04:15 +02:00
|
|
|
></textarea>
|
|
|
|
<button class="emoji" @click="emoji" ref="emoji">
|
|
|
|
<fa :icon="['far', 'laugh']"/>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<div class="files" v-show="files.length != 0">
|
|
|
|
<x-draggable :list="files" :options="{ animation: 150 }">
|
|
|
|
<div v-for="file in files" :key="file.id">
|
|
|
|
<div class="img" :style="{ backgroundImage: `url(${file.thumbnailUrl})` }" :title="file.name"></div>
|
|
|
|
<img class="remove" @click="detachMedia(file.id)" src="/assets/desktop/remove.png" :title="$t('attach-cancel')" alt=""/>
|
|
|
|
</div>
|
|
|
|
</x-draggable>
|
|
|
|
</div>
|
|
|
|
<input ref="file" type="file" multiple="multiple" tabindex="-1" @change="onChangeFile"/>
|
|
|
|
<mk-uploader ref="uploader" @uploaded="attachMedia"/>
|
|
|
|
<footer>
|
|
|
|
<button @click="chooseFile"><fa icon="upload"/></button>
|
|
|
|
<button @click="chooseFileFromDrive"><fa icon="cloud"/></button>
|
|
|
|
<button @click="post" :disabled="posting" class="post">{{ $t('note') }}</button>
|
|
|
|
</footer>
|
|
|
|
</div>
|
2019-02-15 08:35:52 +02:00
|
|
|
</ui-container>
|
2018-02-19 23:13:27 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2018-02-24 17:18:09 +02:00
|
|
|
import define from '../../../common/define-widget';
|
2018-11-08 20:44:35 +02:00
|
|
|
import i18n from '../../../i18n';
|
2018-11-12 18:04:15 +02:00
|
|
|
import insertTextAtCursor from 'insert-text-at-cursor';
|
|
|
|
import * as XDraggable from 'vuedraggable';
|
2018-11-08 20:44:35 +02:00
|
|
|
|
2018-02-19 23:13:27 +02:00
|
|
|
export default define({
|
|
|
|
name: 'post-form',
|
2018-02-21 08:30:03 +02:00
|
|
|
props: () => ({
|
2018-02-19 23:13:27 +02:00
|
|
|
design: 0
|
2018-02-21 08:30:03 +02:00
|
|
|
})
|
2018-02-19 23:13:27 +02:00
|
|
|
}).extend({
|
2018-11-08 20:44:35 +02:00
|
|
|
i18n: i18n('desktop/views/widgets/post-form.vue'),
|
2018-11-12 18:04:15 +02:00
|
|
|
|
|
|
|
components: {
|
|
|
|
XDraggable
|
|
|
|
},
|
|
|
|
|
2018-02-19 23:13:27 +02:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
posting: false,
|
2018-11-12 18:04:15 +02:00
|
|
|
text: '',
|
|
|
|
files: [],
|
2018-02-19 23:13:27 +02:00
|
|
|
};
|
|
|
|
},
|
2018-11-12 18:04:15 +02:00
|
|
|
|
2018-05-28 19:44:15 +03:00
|
|
|
computed: {
|
|
|
|
placeholder(): string {
|
2018-05-28 20:00:45 +03:00
|
|
|
const xs = [
|
2018-11-08 20:44:35 +02:00
|
|
|
this.$t('@.note-placeholders.a'),
|
|
|
|
this.$t('@.note-placeholders.b'),
|
|
|
|
this.$t('@.note-placeholders.c'),
|
|
|
|
this.$t('@.note-placeholders.d'),
|
|
|
|
this.$t('@.note-placeholders.e'),
|
|
|
|
this.$t('@.note-placeholders.f')
|
2018-05-28 20:00:45 +03:00
|
|
|
];
|
|
|
|
return xs[Math.floor(Math.random() * xs.length)];
|
2018-05-28 19:44:15 +03:00
|
|
|
}
|
|
|
|
},
|
2018-11-12 18:04:15 +02:00
|
|
|
|
2018-02-19 23:13:27 +02:00
|
|
|
methods: {
|
|
|
|
func() {
|
|
|
|
if (this.props.design == 1) {
|
|
|
|
this.props.design = 0;
|
|
|
|
} else {
|
|
|
|
this.props.design++;
|
|
|
|
}
|
2018-04-29 11:17:15 +03:00
|
|
|
this.save();
|
2018-02-19 23:13:27 +02:00
|
|
|
},
|
2018-11-12 18:04:15 +02:00
|
|
|
|
|
|
|
chooseFile() {
|
|
|
|
(this.$refs.file as any).click();
|
|
|
|
},
|
|
|
|
|
|
|
|
chooseFileFromDrive() {
|
|
|
|
this.$chooseDriveFile({
|
|
|
|
multiple: true
|
|
|
|
}).then(files => {
|
2018-12-11 13:36:55 +02:00
|
|
|
for (const x of files) this.attachMedia(x);
|
2018-11-12 18:04:15 +02:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
attachMedia(driveFile) {
|
|
|
|
this.files.push(driveFile);
|
|
|
|
this.$emit('change-attached-files', this.files);
|
|
|
|
},
|
|
|
|
|
|
|
|
detachMedia(id) {
|
|
|
|
this.files = this.files.filter(x => x.id != id);
|
|
|
|
this.$emit('change-attached-files', this.files);
|
|
|
|
},
|
|
|
|
|
2018-02-19 23:13:27 +02:00
|
|
|
onKeydown(e) {
|
2018-07-20 20:14:24 +03:00
|
|
|
if ((e.which == 10 || e.which == 13) && (e.ctrlKey || e.metaKey) && !this.posting && this.text) this.post();
|
2018-02-19 23:13:27 +02:00
|
|
|
},
|
2018-11-12 18:04:15 +02:00
|
|
|
|
|
|
|
onPaste(e) {
|
2018-12-11 13:36:55 +02:00
|
|
|
for (const item of Array.from(e.clipboardData.items)) {
|
2018-11-12 18:04:15 +02:00
|
|
|
if (item.kind == 'file') {
|
|
|
|
this.upload(item.getAsFile());
|
|
|
|
}
|
2018-12-11 13:36:55 +02:00
|
|
|
}
|
2018-11-12 18:04:15 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
onChangeFile() {
|
2018-12-11 13:36:55 +02:00
|
|
|
for (const x of Array.from((this.$refs.file as any).files)) this.upload(x);
|
2018-11-12 18:04:15 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
upload(file) {
|
|
|
|
(this.$refs.uploader as any).upload(file);
|
|
|
|
},
|
|
|
|
|
2018-11-13 08:01:05 +02:00
|
|
|
onDragover(e) {
|
|
|
|
const isFile = e.dataTransfer.items[0].kind == 'file';
|
|
|
|
const isDriveFile = e.dataTransfer.types[0] == 'mk_drive_file';
|
|
|
|
if (isFile || isDriveFile) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.dataTransfer.dropEffect = e.dataTransfer.effectAllowed == 'all' ? 'copy' : 'move';
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onDrop(e): void {
|
|
|
|
// ファイルだったら
|
|
|
|
if (e.dataTransfer.files.length > 0) {
|
|
|
|
e.preventDefault();
|
2018-12-11 13:36:55 +02:00
|
|
|
for (const x of Array.from(e.dataTransfer.files)) this.upload(x);
|
2018-11-13 08:01:05 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//#region ドライブのファイル
|
|
|
|
const driveFile = e.dataTransfer.getData('mk_drive_file');
|
|
|
|
if (driveFile != null && driveFile != '') {
|
|
|
|
const file = JSON.parse(driveFile);
|
|
|
|
this.files.push(file);
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
//#endregion
|
|
|
|
},
|
|
|
|
|
2018-11-12 18:04:15 +02:00
|
|
|
async emoji() {
|
|
|
|
const Picker = await import('../components/emoji-picker-dialog.vue').then(m => m.default);
|
|
|
|
const button = this.$refs.emoji;
|
|
|
|
const rect = button.getBoundingClientRect();
|
|
|
|
const vm = this.$root.new(Picker, {
|
|
|
|
x: button.offsetWidth + rect.left + window.pageXOffset,
|
|
|
|
y: rect.top + window.pageYOffset
|
|
|
|
});
|
|
|
|
vm.$once('chosen', emoji => {
|
|
|
|
insertTextAtCursor(this.$refs.text, emoji);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2018-02-19 23:13:27 +02:00
|
|
|
post() {
|
|
|
|
this.posting = true;
|
|
|
|
|
2018-11-09 01:13:34 +02:00
|
|
|
this.$root.api('notes/create', {
|
2018-11-12 18:04:15 +02:00
|
|
|
text: this.text == '' ? undefined : this.text,
|
|
|
|
fileIds: this.files.length > 0 ? this.files.map(f => f.id) : undefined,
|
2019-01-23 12:45:14 +02:00
|
|
|
visibility: this.$store.state.settings.defaultNoteVisibility
|
2018-02-19 23:13:27 +02:00
|
|
|
}).then(data => {
|
|
|
|
this.clear();
|
|
|
|
}).catch(err => {
|
2018-08-06 21:20:26 +03:00
|
|
|
alert('Something happened');
|
2018-02-19 23:13:27 +02:00
|
|
|
}).then(() => {
|
|
|
|
this.posting = false;
|
|
|
|
});
|
|
|
|
},
|
2018-11-12 18:04:15 +02:00
|
|
|
|
2018-02-19 23:13:27 +02:00
|
|
|
clear() {
|
|
|
|
this.text = '';
|
2018-11-12 18:04:15 +02:00
|
|
|
this.files = [];
|
2018-02-19 23:13:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="stylus" scoped>
|
2018-11-12 18:04:15 +02:00
|
|
|
.lhcuptdmcdkfwmipgazeawoiuxpzaclc-body
|
|
|
|
> .textarea
|
|
|
|
> .emoji
|
|
|
|
position absolute
|
|
|
|
top 0
|
|
|
|
right 0
|
|
|
|
padding 10px
|
|
|
|
font-size 18px
|
|
|
|
color var(--text)
|
|
|
|
opacity 0.5
|
|
|
|
|
|
|
|
&:hover
|
|
|
|
color var(--textHighlighted)
|
|
|
|
opacity 1
|
|
|
|
|
|
|
|
&:active
|
|
|
|
color var(--primary)
|
|
|
|
opacity 1
|
|
|
|
|
|
|
|
> textarea
|
|
|
|
display block
|
|
|
|
width 100%
|
|
|
|
max-width 100%
|
|
|
|
min-width 100%
|
|
|
|
padding 16px
|
|
|
|
color var(--desktopPostFormTextareaFg)
|
|
|
|
outline none
|
|
|
|
background var(--desktopPostFormTextareaBg)
|
|
|
|
border none
|
|
|
|
border-bottom solid 1px var(--faceDivider)
|
2018-11-16 10:41:52 +02:00
|
|
|
padding-right 30px
|
2018-11-12 18:04:15 +02:00
|
|
|
|
|
|
|
&:focus
|
|
|
|
& + .emoji
|
|
|
|
opacity 0.7
|
|
|
|
|
|
|
|
> .files
|
|
|
|
> div
|
|
|
|
padding 4px
|
|
|
|
|
|
|
|
&:after
|
|
|
|
content ""
|
|
|
|
display block
|
|
|
|
clear both
|
|
|
|
|
|
|
|
> div
|
|
|
|
float left
|
|
|
|
border solid 4px transparent
|
|
|
|
cursor move
|
|
|
|
|
|
|
|
&:hover > .remove
|
|
|
|
display block
|
|
|
|
|
|
|
|
> .img
|
|
|
|
width 64px
|
|
|
|
height 64px
|
|
|
|
background-size cover
|
|
|
|
background-position center center
|
|
|
|
|
|
|
|
> .remove
|
|
|
|
display none
|
|
|
|
position absolute
|
|
|
|
top -6px
|
|
|
|
right -6px
|
|
|
|
width 16px
|
|
|
|
height 16px
|
|
|
|
cursor pointer
|
|
|
|
|
|
|
|
> input[type=file]
|
|
|
|
display none
|
|
|
|
|
|
|
|
> footer
|
|
|
|
display flex
|
|
|
|
padding 8px
|
|
|
|
|
|
|
|
> button:not(.post)
|
|
|
|
color var(--text)
|
|
|
|
|
|
|
|
&:hover
|
|
|
|
color var(--textHighlighted)
|
|
|
|
|
|
|
|
> .post
|
|
|
|
display block
|
|
|
|
margin 0 0 0 auto
|
|
|
|
padding 0 10px
|
|
|
|
height 28px
|
|
|
|
color var(--primaryForeground)
|
|
|
|
background var(--primary) !important
|
|
|
|
outline none
|
|
|
|
border none
|
|
|
|
border-radius 4px
|
|
|
|
transition background 0.1s ease
|
|
|
|
cursor pointer
|
2018-09-26 14:19:35 +03:00
|
|
|
|
2018-11-12 18:04:15 +02:00
|
|
|
&:hover
|
|
|
|
background var(--primaryLighten10) !important
|
2018-03-03 06:47:55 +02:00
|
|
|
|
2018-11-12 18:04:15 +02:00
|
|
|
&:active
|
|
|
|
background var(--primaryDarken10) !important
|
|
|
|
transition background 0s ease
|
2018-02-19 23:13:27 +02:00
|
|
|
|
|
|
|
</style>
|