2018-02-19 22:13:27 +01:00
|
|
|
<template>
|
2018-11-12 17:04:15 +01:00
|
|
|
<div>
|
2019-02-15 07:35:52 +01:00
|
|
|
<ui-container :show-header="props.design == 0">
|
2019-02-18 03:13:56 +01:00
|
|
|
<template #header><fa icon="pencil-alt"/>{{ $t('title') }}</template>
|
2018-11-12 17:04:15 +01:00
|
|
|
|
2018-11-13 07:01:05 +01:00
|
|
|
<div class="lhcuptdmcdkfwmipgazeawoiuxpzaclc-body"
|
|
|
|
@dragover.stop="onDragover"
|
|
|
|
@drop.stop="onDrop"
|
|
|
|
>
|
2018-11-12 17:04:15 +01:00
|
|
|
<div class="textarea">
|
|
|
|
<textarea
|
|
|
|
:disabled="posting"
|
|
|
|
v-model="text"
|
|
|
|
@keydown="onKeydown"
|
|
|
|
@paste="onPaste"
|
|
|
|
:placeholder="placeholder"
|
|
|
|
ref="text"
|
2018-12-16 00:45:10 +01:00
|
|
|
v-autocomplete="{ model: 'text' }"
|
2018-11-12 17:04:15 +01:00
|
|
|
></textarea>
|
2019-02-26 21:31:16 +01:00
|
|
|
<button class="emoji" @click="emoji" ref="emoji" v-if="!$root.isMobile">
|
2018-11-12 17:04:15 +01:00
|
|
|
<fa :icon="['far', 'laugh']"/>
|
|
|
|
</button>
|
|
|
|
</div>
|
2019-04-14 10:12:04 +02:00
|
|
|
<x-post-form-attaches class="files" :files="files" :detachMediaFn="detachMedia"/>
|
2018-11-12 17:04:15 +01:00
|
|
|
<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 07:35:52 +01:00
|
|
|
</ui-container>
|
2018-02-19 22:13:27 +01:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2018-02-24 16:18:09 +01:00
|
|
|
import define from '../../../common/define-widget';
|
2018-11-08 19:44:35 +01:00
|
|
|
import i18n from '../../../i18n';
|
2018-11-12 17:04:15 +01:00
|
|
|
import insertTextAtCursor from 'insert-text-at-cursor';
|
2019-04-14 10:12:04 +02:00
|
|
|
import XPostFormAttaches from '../components/post-form-attaches.vue';
|
2018-11-08 19:44:35 +01:00
|
|
|
|
2018-02-19 22:13:27 +01:00
|
|
|
export default define({
|
|
|
|
name: 'post-form',
|
2018-02-21 07:30:03 +01:00
|
|
|
props: () => ({
|
2018-02-19 22:13:27 +01:00
|
|
|
design: 0
|
2018-02-21 07:30:03 +01:00
|
|
|
})
|
2018-02-19 22:13:27 +01:00
|
|
|
}).extend({
|
2018-11-08 19:44:35 +01:00
|
|
|
i18n: i18n('desktop/views/widgets/post-form.vue'),
|
2018-11-12 17:04:15 +01:00
|
|
|
|
|
|
|
components: {
|
2019-04-14 10:12:04 +02:00
|
|
|
XPostFormAttaches
|
2018-11-12 17:04:15 +01:00
|
|
|
},
|
|
|
|
|
2018-02-19 22:13:27 +01:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
posting: false,
|
2018-11-12 17:04:15 +01:00
|
|
|
text: '',
|
|
|
|
files: [],
|
2018-02-19 22:13:27 +01:00
|
|
|
};
|
|
|
|
},
|
2018-11-12 17:04:15 +01:00
|
|
|
|
2018-05-28 18:44:15 +02:00
|
|
|
computed: {
|
|
|
|
placeholder(): string {
|
2018-05-28 19:00:45 +02:00
|
|
|
const xs = [
|
2018-11-08 19:44:35 +01: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 19:00:45 +02:00
|
|
|
];
|
|
|
|
return xs[Math.floor(Math.random() * xs.length)];
|
2018-05-28 18:44:15 +02:00
|
|
|
}
|
|
|
|
},
|
2018-11-12 17:04:15 +01:00
|
|
|
|
2018-02-19 22:13:27 +01:00
|
|
|
methods: {
|
|
|
|
func() {
|
|
|
|
if (this.props.design == 1) {
|
|
|
|
this.props.design = 0;
|
|
|
|
} else {
|
|
|
|
this.props.design++;
|
|
|
|
}
|
2018-04-29 10:17:15 +02:00
|
|
|
this.save();
|
2018-02-19 22:13:27 +01:00
|
|
|
},
|
2018-11-12 17:04:15 +01:00
|
|
|
|
|
|
|
chooseFile() {
|
|
|
|
(this.$refs.file as any).click();
|
|
|
|
},
|
|
|
|
|
|
|
|
chooseFileFromDrive() {
|
|
|
|
this.$chooseDriveFile({
|
|
|
|
multiple: true
|
|
|
|
}).then(files => {
|
2018-12-11 12:36:55 +01:00
|
|
|
for (const x of files) this.attachMedia(x);
|
2018-11-12 17:04:15 +01: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 22:13:27 +01:00
|
|
|
onKeydown(e) {
|
2018-07-20 19:14:24 +02:00
|
|
|
if ((e.which == 10 || e.which == 13) && (e.ctrlKey || e.metaKey) && !this.posting && this.text) this.post();
|
2018-02-19 22:13:27 +01:00
|
|
|
},
|
2018-11-12 17:04:15 +01:00
|
|
|
|
|
|
|
onPaste(e) {
|
2018-12-11 12:36:55 +01:00
|
|
|
for (const item of Array.from(e.clipboardData.items)) {
|
2018-11-12 17:04:15 +01:00
|
|
|
if (item.kind == 'file') {
|
|
|
|
this.upload(item.getAsFile());
|
|
|
|
}
|
2018-12-11 12:36:55 +01:00
|
|
|
}
|
2018-11-12 17:04:15 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
onChangeFile() {
|
2018-12-11 12:36:55 +01:00
|
|
|
for (const x of Array.from((this.$refs.file as any).files)) this.upload(x);
|
2018-11-12 17:04:15 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
upload(file) {
|
|
|
|
(this.$refs.uploader as any).upload(file);
|
|
|
|
},
|
|
|
|
|
2018-11-13 07:01:05 +01: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 12:36:55 +01:00
|
|
|
for (const x of Array.from(e.dataTransfer.files)) this.upload(x);
|
2018-11-13 07:01:05 +01: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 17:04:15 +01:00
|
|
|
async emoji() {
|
2019-02-26 21:31:16 +01:00
|
|
|
const Picker = await import('../../../desktop/views/components/emoji-picker-dialog.vue').then(m => m.default);
|
2018-11-12 17:04:15 +01:00
|
|
|
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 22:13:27 +01:00
|
|
|
post() {
|
|
|
|
this.posting = true;
|
|
|
|
|
2019-04-08 06:31:42 +02:00
|
|
|
let visibility = 'public';
|
|
|
|
let localOnly = false;
|
|
|
|
|
|
|
|
const m = this.$store.state.settings.defaultNoteVisibility.match(/^local-(.+)/);
|
|
|
|
if (m) {
|
|
|
|
visibility = m[1];
|
|
|
|
localOnly = true;
|
|
|
|
} else {
|
|
|
|
visibility = this.$store.state.settings.defaultNoteVisibility;
|
|
|
|
}
|
|
|
|
|
2018-11-09 00:13:34 +01:00
|
|
|
this.$root.api('notes/create', {
|
2018-11-12 17:04:15 +01:00
|
|
|
text: this.text == '' ? undefined : this.text,
|
|
|
|
fileIds: this.files.length > 0 ? this.files.map(f => f.id) : undefined,
|
2019-04-08 06:31:42 +02:00
|
|
|
visibility,
|
|
|
|
localOnly,
|
2018-02-19 22:13:27 +01:00
|
|
|
}).then(data => {
|
|
|
|
this.clear();
|
|
|
|
}).catch(err => {
|
2019-04-16 06:05:10 +02:00
|
|
|
this.$root.dialog({
|
|
|
|
type: 'error',
|
|
|
|
text: this.$t('something-happened')
|
|
|
|
});
|
2018-02-19 22:13:27 +01:00
|
|
|
}).then(() => {
|
|
|
|
this.posting = false;
|
2019-02-26 21:31:16 +01:00
|
|
|
this.$nextTick(() => {
|
|
|
|
this.$refs.text.focus();
|
|
|
|
});
|
2018-02-19 22:13:27 +01:00
|
|
|
});
|
|
|
|
},
|
2018-11-12 17:04:15 +01:00
|
|
|
|
2018-02-19 22:13:27 +01:00
|
|
|
clear() {
|
|
|
|
this.text = '';
|
2018-11-12 17:04:15 +01:00
|
|
|
this.files = [];
|
2018-02-19 22:13:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="stylus" scoped>
|
2018-11-12 17:04:15 +01: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 09:41:52 +01:00
|
|
|
padding-right 30px
|
2018-11-12 17:04:15 +01:00
|
|
|
|
|
|
|
&:focus
|
|
|
|
& + .emoji
|
|
|
|
opacity 0.7
|
|
|
|
|
|
|
|
> 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 13:19:35 +02:00
|
|
|
|
2018-11-12 17:04:15 +01:00
|
|
|
&:hover
|
|
|
|
background var(--primaryLighten10) !important
|
2018-03-03 05:47:55 +01:00
|
|
|
|
2018-11-12 17:04:15 +01:00
|
|
|
&:active
|
|
|
|
background var(--primaryDarken10) !important
|
|
|
|
transition background 0s ease
|
2018-02-19 22:13:27 +01:00
|
|
|
|
|
|
|
</style>
|