2020-01-29 20:37:25 +01:00
|
|
|
<template>
|
2023-05-10 22:20:52 +02:00
|
|
|
<section
|
2023-04-08 02:01:42 +02:00
|
|
|
v-size="{ max: [310, 500] }"
|
|
|
|
class="gafaadew"
|
|
|
|
:class="{ modal, _popup: modal }"
|
2023-05-10 23:44:08 +02:00
|
|
|
:aria-label="i18n.ts._pages.blocks.post"
|
2023-04-08 02:01:42 +02:00
|
|
|
@dragover.stop="onDragover"
|
|
|
|
@dragenter="onDragenter"
|
|
|
|
@dragleave="onDragleave"
|
|
|
|
@drop.stop="onDrop"
|
|
|
|
>
|
|
|
|
<header>
|
|
|
|
<button v-if="!fixed" class="cancel _button" @click="cancel">
|
2023-10-17 03:57:20 +02:00
|
|
|
<i :class="icon('ph-x')" :aria-label="i18n.t('close')"></i>
|
2020-02-05 13:28:51 +01:00
|
|
|
</button>
|
2023-04-08 02:01:42 +02:00
|
|
|
<button
|
2023-06-19 02:46:39 +02:00
|
|
|
v-if="$props.editId == null"
|
2023-04-08 02:01:42 +02:00
|
|
|
v-click-anime
|
|
|
|
v-tooltip="i18n.ts.switchAccount"
|
|
|
|
class="account _button"
|
|
|
|
@click="openAccountMenu"
|
|
|
|
>
|
|
|
|
<MkAvatar :user="postAccount ?? $i" class="avatar" />
|
|
|
|
</button>
|
|
|
|
<div class="right">
|
|
|
|
<span
|
|
|
|
class="text-count"
|
|
|
|
:class="{ over: textLength > maxTextLength }"
|
|
|
|
>{{ maxTextLength - textLength }}</span
|
|
|
|
>
|
|
|
|
<span v-if="localOnly" class="local-only"
|
2023-10-17 03:57:20 +02:00
|
|
|
><i :class="icon('ph-users')"></i
|
2023-04-08 02:01:42 +02:00
|
|
|
></span>
|
|
|
|
<button
|
|
|
|
ref="visibilityButton"
|
|
|
|
v-tooltip="i18n.ts.visibility"
|
|
|
|
class="_button visibility"
|
|
|
|
:disabled="channel != null"
|
|
|
|
@click="setVisibility"
|
|
|
|
>
|
|
|
|
<span v-if="visibility === 'public'"
|
2023-10-17 03:57:20 +02:00
|
|
|
><i :class="icon('ph-planet')"></i
|
2023-04-08 02:01:42 +02:00
|
|
|
></span>
|
|
|
|
<span v-if="visibility === 'home'"
|
2023-10-17 03:57:20 +02:00
|
|
|
><i :class="icon('ph-house')"></i
|
2023-04-08 02:01:42 +02:00
|
|
|
></span>
|
|
|
|
<span v-if="visibility === 'followers'"
|
2023-10-17 03:57:20 +02:00
|
|
|
><i :class="icon('ph-lock')"></i
|
2023-04-08 02:01:42 +02:00
|
|
|
></span>
|
|
|
|
<span v-if="visibility === 'specified'"
|
2023-10-17 03:57:20 +02:00
|
|
|
><i :class="icon('ph-envelope-simple-open')"></i
|
2023-04-08 02:01:42 +02:00
|
|
|
></span>
|
|
|
|
</button>
|
2023-10-06 05:28:12 +02:00
|
|
|
<button
|
|
|
|
ref="languageButton"
|
|
|
|
v-tooltip="i18n.ts.language"
|
|
|
|
class="_button language"
|
|
|
|
@click="setLanguage"
|
|
|
|
>
|
2023-11-23 10:09:55 +01:00
|
|
|
<i
|
|
|
|
v-if="language === '' || language == null"
|
|
|
|
class="_button"
|
|
|
|
:class="icon('ph-seal-warning')"
|
|
|
|
></i>
|
|
|
|
<p v-else class="_button" style="font-weight: bold">
|
|
|
|
{{ language.split("-")[0] }}
|
|
|
|
</p>
|
2023-10-06 05:28:12 +02:00
|
|
|
</button>
|
2023-04-08 02:01:42 +02:00
|
|
|
<button
|
|
|
|
v-tooltip="i18n.ts.previewNoteText"
|
|
|
|
class="_button preview"
|
|
|
|
:class="{ active: showPreview }"
|
|
|
|
@click="showPreview = !showPreview"
|
|
|
|
>
|
2023-10-17 03:57:20 +02:00
|
|
|
<i :class="icon('ph-binoculars')"></i>
|
2023-04-08 02:01:42 +02:00
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
class="submit _buttonGradate"
|
|
|
|
:disabled="!canPost"
|
|
|
|
data-cy-open-post-form-submit
|
|
|
|
@click="post"
|
|
|
|
>
|
|
|
|
{{ submitText
|
|
|
|
}}<i
|
|
|
|
:class="
|
2023-10-17 03:57:20 +02:00
|
|
|
icon(
|
|
|
|
reply
|
|
|
|
? 'ph-arrow-u-up-left'
|
|
|
|
: renote
|
2024-02-11 18:50:57 +01:00
|
|
|
? 'ph-quotes'
|
|
|
|
: 'ph-paper-plane-tilt',
|
2023-10-17 03:57:20 +02:00
|
|
|
)
|
2023-04-08 02:01:42 +02:00
|
|
|
"
|
|
|
|
></i>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</header>
|
|
|
|
<div class="form" :class="{ fixed }">
|
|
|
|
<XNoteSimple v-if="reply" class="preview" :note="reply" />
|
|
|
|
<XNoteSimple v-if="renote" class="preview" :note="renote" />
|
|
|
|
<div v-if="quoteId" class="with-quote">
|
2023-10-17 03:57:20 +02:00
|
|
|
<i :class="icon('ph-quotes')"></i>
|
2023-04-08 02:01:42 +02:00
|
|
|
{{ i18n.ts.quoteAttached
|
2023-07-14 01:53:53 +02:00
|
|
|
}}<button
|
|
|
|
class="_button"
|
|
|
|
:aria-label="i18n.t('removeQuote')"
|
2023-09-02 01:27:33 +02:00
|
|
|
@click="quoteId = null"
|
2023-07-14 01:53:53 +02:00
|
|
|
>
|
2023-10-17 03:57:20 +02:00
|
|
|
<i :class="icon('ph-x')"></i>
|
2023-04-08 02:01:42 +02:00
|
|
|
</button>
|
2020-01-29 20:37:25 +01:00
|
|
|
</div>
|
2023-04-08 02:01:42 +02:00
|
|
|
<div v-if="visibility === 'specified'" class="to-specified">
|
|
|
|
<span style="margin-right: 8px">{{ i18n.ts.recipient }}</span>
|
|
|
|
<div class="visibleUsers">
|
|
|
|
<span v-for="u in visibleUsers" :key="u.id">
|
|
|
|
<MkAcct :user="u" />
|
2023-07-14 01:53:53 +02:00
|
|
|
<button
|
|
|
|
class="_button"
|
|
|
|
:aria-label="i18n.t('removeRecipient')"
|
2023-09-02 01:27:33 +02:00
|
|
|
@click="removeVisibleUser(u)"
|
2023-07-14 01:53:53 +02:00
|
|
|
>
|
2023-10-17 03:57:20 +02:00
|
|
|
<i :class="icon('ph-x')"></i>
|
2023-04-08 02:01:42 +02:00
|
|
|
</button>
|
|
|
|
</span>
|
|
|
|
<button class="_button" @click="addVisibleUser">
|
2023-10-17 03:57:20 +02:00
|
|
|
<i :class="icon('ph-plus ph-md ph-fw')"></i>
|
2023-04-08 02:01:42 +02:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<MkInfo
|
|
|
|
v-if="hasNotSpecifiedMentions"
|
|
|
|
warn
|
|
|
|
class="hasNotSpecifiedMentions"
|
|
|
|
>{{ i18n.ts.notSpecifiedMentionWarning }} -
|
|
|
|
<button class="_textButton" @click="addMissingMention()">
|
|
|
|
{{ i18n.ts.add }}
|
|
|
|
</button></MkInfo
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
v-show="useCw"
|
|
|
|
ref="cwInputEl"
|
|
|
|
v-model="cw"
|
|
|
|
class="cw"
|
|
|
|
:placeholder="i18n.ts.annotation"
|
|
|
|
@keydown="onKeydown"
|
|
|
|
/>
|
|
|
|
<textarea
|
|
|
|
ref="textareaEl"
|
|
|
|
v-model="text"
|
|
|
|
class="text"
|
|
|
|
:class="{ withCw: useCw }"
|
|
|
|
:disabled="posting"
|
|
|
|
:placeholder="placeholder"
|
|
|
|
data-cy-post-form-text
|
|
|
|
@keydown="onKeydown"
|
|
|
|
@paste="onPaste"
|
|
|
|
@compositionupdate="onCompositionUpdate"
|
|
|
|
@compositionend="onCompositionEnd"
|
|
|
|
/>
|
|
|
|
<input
|
|
|
|
v-show="withHashtags"
|
|
|
|
ref="hashtagsInputEl"
|
|
|
|
v-model="hashtags"
|
|
|
|
class="hashtags"
|
|
|
|
:placeholder="i18n.ts.hashtags"
|
|
|
|
list="hashtags"
|
|
|
|
/>
|
|
|
|
<XPostFormAttaches
|
|
|
|
class="attaches"
|
|
|
|
:files="files"
|
|
|
|
@updated="updateFiles"
|
|
|
|
@detach="detachFile"
|
|
|
|
@changeSensitive="updateFileSensitive"
|
|
|
|
@changeName="updateFileName"
|
|
|
|
/>
|
|
|
|
<XPollEditor v-if="poll" v-model="poll" @destroyed="poll = null" />
|
|
|
|
<XNotePreview v-if="showPreview" class="preview" :text="text" />
|
|
|
|
<footer>
|
|
|
|
<button
|
|
|
|
v-tooltip="i18n.ts.attachFile"
|
|
|
|
class="_button"
|
|
|
|
@click="chooseFileFrom"
|
|
|
|
>
|
2023-10-17 03:57:20 +02:00
|
|
|
<i :class="icon('ph-upload')"></i>
|
2023-04-08 02:01:42 +02:00
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
v-tooltip="i18n.ts.poll"
|
|
|
|
class="_button"
|
|
|
|
:class="{ active: poll }"
|
|
|
|
@click="togglePoll"
|
|
|
|
>
|
2023-10-17 03:57:20 +02:00
|
|
|
<i :class="icon('ph-microphone-stage')"></i>
|
2023-04-08 02:01:42 +02:00
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
v-tooltip="i18n.ts.useCw"
|
|
|
|
class="_button"
|
|
|
|
:class="{ active: useCw }"
|
|
|
|
@click="useCw = !useCw"
|
|
|
|
>
|
2023-10-17 03:57:20 +02:00
|
|
|
<i :class="icon('ph-eye-slash')"></i>
|
2023-04-08 02:01:42 +02:00
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
v-tooltip="i18n.ts.mention"
|
|
|
|
class="_button"
|
|
|
|
@click="insertMention"
|
|
|
|
>
|
2023-10-17 03:57:20 +02:00
|
|
|
<i :class="icon('ph-at')"></i>
|
2023-04-08 02:01:42 +02:00
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
v-tooltip="i18n.ts.hashtags"
|
|
|
|
class="_button"
|
|
|
|
:class="{ active: withHashtags }"
|
|
|
|
@click="withHashtags = !withHashtags"
|
|
|
|
>
|
2023-10-17 03:57:20 +02:00
|
|
|
<i :class="icon('ph-hash')"></i>
|
2023-04-08 02:01:42 +02:00
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
v-tooltip="i18n.ts.emoji"
|
|
|
|
class="_button"
|
|
|
|
@click="insertEmoji"
|
|
|
|
>
|
2023-10-17 03:57:20 +02:00
|
|
|
<i :class="icon('ph-smiley')"></i>
|
2023-04-08 02:01:42 +02:00
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
v-if="postFormActions.length > 0"
|
|
|
|
v-tooltip="i18n.ts.plugin"
|
|
|
|
class="_button"
|
|
|
|
@click="showActions"
|
|
|
|
>
|
2023-10-17 03:57:20 +02:00
|
|
|
<i :class="icon('ph-plug')"></i>
|
2023-04-08 02:01:42 +02:00
|
|
|
</button>
|
2023-05-20 08:38:36 +02:00
|
|
|
<!-- v-if="showMfmCheatsheet" -->
|
2023-04-08 02:01:42 +02:00
|
|
|
<button
|
|
|
|
v-tooltip="i18n.ts._mfm.cheatSheet"
|
|
|
|
class="_button right"
|
|
|
|
@click="openCheatSheet"
|
|
|
|
>
|
2023-10-17 03:57:20 +02:00
|
|
|
<i :class="icon('ph-question')"></i>
|
2023-04-08 02:01:42 +02:00
|
|
|
</button>
|
|
|
|
</footer>
|
|
|
|
<datalist id="hashtags">
|
|
|
|
<option
|
|
|
|
v-for="hashtag in recentHashtags"
|
|
|
|
:key="hashtag"
|
|
|
|
:value="hashtag"
|
|
|
|
/>
|
|
|
|
</datalist>
|
2020-01-29 20:37:25 +01:00
|
|
|
</div>
|
2023-05-10 22:20:52 +02:00
|
|
|
</section>
|
2020-01-29 20:37:25 +01:00
|
|
|
</template>
|
|
|
|
|
2022-01-15 17:46:25 +01:00
|
|
|
<script lang="ts" setup>
|
2023-08-12 02:44:46 +02:00
|
|
|
import {
|
2023-09-02 01:27:33 +02:00
|
|
|
computed,
|
|
|
|
defineAsyncComponent,
|
2023-08-12 02:44:46 +02:00
|
|
|
inject,
|
|
|
|
nextTick,
|
|
|
|
onMounted,
|
|
|
|
ref,
|
2023-09-02 01:27:33 +02:00
|
|
|
watch,
|
2023-08-12 02:44:46 +02:00
|
|
|
} from "vue";
|
2023-04-08 02:01:42 +02:00
|
|
|
import * as mfm from "mfm-js";
|
2023-09-24 06:27:16 +02:00
|
|
|
import type * as firefish from "firefish-js";
|
2023-07-28 20:41:25 +02:00
|
|
|
import autosize from "autosize";
|
2023-04-08 02:01:42 +02:00
|
|
|
import insertTextAtCursor from "insert-text-at-cursor";
|
|
|
|
import { length } from "stringz";
|
|
|
|
import { toASCII } from "punycode/";
|
2023-07-03 00:18:30 +02:00
|
|
|
import * as Acct from "firefish-js/built/acct";
|
2023-04-08 02:01:42 +02:00
|
|
|
import { throttle } from "throttle-debounce";
|
|
|
|
import XNoteSimple from "@/components/MkNoteSimple.vue";
|
|
|
|
import XNotePreview from "@/components/MkNotePreview.vue";
|
|
|
|
import XPostFormAttaches from "@/components/MkPostFormAttaches.vue";
|
|
|
|
import XPollEditor from "@/components/MkPollEditor.vue";
|
|
|
|
import { host, url } from "@/config";
|
|
|
|
import { erase, unique } from "@/scripts/array";
|
|
|
|
import { extractMentions } from "@/scripts/extract-mentions";
|
|
|
|
import { formatTimeString } from "@/scripts/format-time-string";
|
|
|
|
import { Autocomplete } from "@/scripts/autocomplete";
|
|
|
|
import * as os from "@/os";
|
|
|
|
import { stream } from "@/stream";
|
|
|
|
import { selectFiles } from "@/scripts/select-file";
|
|
|
|
import { defaultStore, notePostInterruptors, postFormActions } from "@/store";
|
|
|
|
import MkInfo from "@/components/MkInfo.vue";
|
|
|
|
import { i18n } from "@/i18n";
|
|
|
|
import { instance } from "@/instance";
|
2023-10-22 23:29:46 +02:00
|
|
|
import { getAccounts, openAccountMenu as openAccountMenu_ } from "@/account";
|
|
|
|
import { $i } from "@/reactiveAccount";
|
2023-04-08 02:01:42 +02:00
|
|
|
import { uploadFile } from "@/scripts/upload";
|
|
|
|
import { deepClone } from "@/scripts/clone";
|
|
|
|
import XCheatSheet from "@/components/MkCheatSheetDialog.vue";
|
2023-09-24 11:03:36 +02:00
|
|
|
import preprocess from "@/scripts/preprocess";
|
2023-09-17 23:59:09 +02:00
|
|
|
import { vibrate } from "@/scripts/vibrate";
|
2023-10-06 05:28:12 +02:00
|
|
|
import { langmap } from "@/scripts/langmap";
|
|
|
|
import { MenuItem } from "@/types/menu";
|
|
|
|
import detectLanguage from "@/scripts/detect-language";
|
2023-10-17 03:57:20 +02:00
|
|
|
import icon from "@/scripts/icon";
|
2023-04-08 02:01:42 +02:00
|
|
|
|
|
|
|
const modal = inject("modal");
|
|
|
|
|
|
|
|
const props = withDefaults(
|
|
|
|
defineProps<{
|
2023-09-24 06:27:16 +02:00
|
|
|
reply?: firefish.entities.Note;
|
|
|
|
renote?: firefish.entities.Note;
|
2023-04-08 02:01:42 +02:00
|
|
|
channel?: any; // TODO
|
2023-09-24 06:27:16 +02:00
|
|
|
mention?: firefish.entities.User;
|
|
|
|
specified?: firefish.entities.User;
|
2023-04-08 02:01:42 +02:00
|
|
|
initialText?: string;
|
2023-09-24 06:27:16 +02:00
|
|
|
initialVisibility?: typeof firefish.noteVisibilities;
|
2023-10-06 05:28:12 +02:00
|
|
|
initialLanguage?: typeof firefish.languages;
|
2023-09-24 06:27:16 +02:00
|
|
|
initialFiles?: firefish.entities.DriveFile[];
|
2023-04-08 02:01:42 +02:00
|
|
|
initialLocalOnly?: boolean;
|
2023-09-24 06:27:16 +02:00
|
|
|
initialVisibleUsers?: firefish.entities.User[];
|
|
|
|
initialNote?: firefish.entities.Note;
|
2023-04-08 02:01:42 +02:00
|
|
|
instant?: boolean;
|
|
|
|
fixed?: boolean;
|
|
|
|
autofocus?: boolean;
|
2023-05-17 05:31:13 +02:00
|
|
|
showMfmCheatSheet?: boolean;
|
2023-09-24 06:27:16 +02:00
|
|
|
editId?: firefish.entities.Note["id"];
|
2023-04-08 02:01:42 +02:00
|
|
|
}>(),
|
|
|
|
{
|
|
|
|
initialVisibleUsers: () => [],
|
|
|
|
autofocus: true,
|
2023-05-17 05:31:13 +02:00
|
|
|
showMfmCheatSheet: true,
|
2023-07-06 03:28:27 +02:00
|
|
|
},
|
2023-04-08 02:01:42 +02:00
|
|
|
);
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2022-01-15 17:46:25 +01:00
|
|
|
const emit = defineEmits<{
|
2023-04-08 02:01:42 +02:00
|
|
|
(ev: "posted"): void;
|
|
|
|
(ev: "cancel"): void;
|
|
|
|
(ev: "esc"): void;
|
2022-01-15 17:46:25 +01:00
|
|
|
}>();
|
|
|
|
|
2023-08-12 02:44:46 +02:00
|
|
|
const textareaEl = ref<HTMLTextAreaElement | null>(null);
|
|
|
|
const cwInputEl = ref<HTMLInputElement | null>(null);
|
|
|
|
const hashtagsInputEl = ref<HTMLInputElement | null>(null);
|
|
|
|
const visibilityButton = ref<HTMLElement | null>(null);
|
2023-10-06 05:28:12 +02:00
|
|
|
const languageButton = ref<HTMLElement | undefined>();
|
2022-01-15 17:46:25 +01:00
|
|
|
|
2023-09-02 01:27:33 +02:00
|
|
|
const posting = ref(false);
|
|
|
|
const text = ref(props.initialText ?? "");
|
|
|
|
const files = ref(props.initialFiles ?? []);
|
|
|
|
const poll = ref<{
|
2022-01-15 17:46:25 +01:00
|
|
|
choices: string[];
|
|
|
|
multiple: boolean;
|
2022-01-25 19:26:12 +01:00
|
|
|
expiresAt: string | null;
|
|
|
|
expiredAfter: string | null;
|
2022-01-15 17:46:25 +01:00
|
|
|
} | null>(null);
|
2023-09-02 01:27:33 +02:00
|
|
|
const useCw = ref(false);
|
2024-02-10 18:08:25 +01:00
|
|
|
const showPreview = ref(defaultStore.state.showPreviewByDefault);
|
2023-09-02 01:27:33 +02:00
|
|
|
const cw = ref<string | null>(null);
|
|
|
|
const localOnly = ref<boolean>(
|
2023-04-08 02:01:42 +02:00
|
|
|
props.initialLocalOnly ?? defaultStore.state.rememberNoteVisibility
|
|
|
|
? defaultStore.state.localOnly
|
2023-07-06 03:28:27 +02:00
|
|
|
: defaultStore.state.defaultNoteLocalOnly,
|
2023-04-08 02:01:42 +02:00
|
|
|
);
|
2023-09-02 01:27:33 +02:00
|
|
|
const visibility = ref(
|
2023-04-08 02:01:42 +02:00
|
|
|
props.initialVisibility ??
|
|
|
|
((defaultStore.state.rememberNoteVisibility
|
|
|
|
? defaultStore.state.visibility
|
|
|
|
: defaultStore.state
|
2023-09-24 06:27:16 +02:00
|
|
|
.defaultNoteVisibility) as (typeof firefish.noteVisibilities)[number]),
|
2023-04-08 02:01:42 +02:00
|
|
|
);
|
2023-11-23 09:49:13 +01:00
|
|
|
|
2023-09-02 01:27:33 +02:00
|
|
|
const visibleUsers = ref([]);
|
2022-02-01 13:49:34 +01:00
|
|
|
if (props.initialVisibleUsers) {
|
|
|
|
props.initialVisibleUsers.forEach(pushVisibleUser);
|
|
|
|
}
|
2023-09-02 01:27:33 +02:00
|
|
|
const draghover = ref(false);
|
|
|
|
const quoteId = ref(null);
|
|
|
|
const hasNotSpecifiedMentions = ref(false);
|
|
|
|
const recentHashtags = ref(
|
|
|
|
JSON.parse(localStorage.getItem("hashtags") || "[]"),
|
|
|
|
);
|
|
|
|
const imeText = ref("");
|
2022-01-15 17:46:25 +01:00
|
|
|
|
|
|
|
const typing = throttle(3000, () => {
|
|
|
|
if (props.channel) {
|
2023-04-08 02:01:42 +02:00
|
|
|
stream.send("typingOnChannel", { channel: props.channel.id });
|
2022-01-15 17:46:25 +01:00
|
|
|
}
|
|
|
|
});
|
2019-05-27 08:38:14 +02:00
|
|
|
|
2023-08-12 02:44:46 +02:00
|
|
|
const draftKey = computed((): string => {
|
2023-05-07 12:27:25 +02:00
|
|
|
if (props.editId) {
|
|
|
|
return `edit:${props.editId}`;
|
|
|
|
}
|
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
let key = props.channel ? `channel:${props.channel.id}` : "";
|
2019-05-27 08:38:14 +02:00
|
|
|
|
2022-01-15 17:46:25 +01:00
|
|
|
if (props.renote) {
|
|
|
|
key += `renote:${props.renote.id}`;
|
|
|
|
} else if (props.reply) {
|
|
|
|
key += `reply:${props.reply.id}`;
|
|
|
|
} else {
|
2023-04-08 02:01:42 +02:00
|
|
|
key += "note";
|
2022-01-15 17:46:25 +01:00
|
|
|
}
|
2021-01-15 15:20:47 +01:00
|
|
|
|
2022-01-15 17:46:25 +01:00
|
|
|
return key;
|
|
|
|
});
|
2020-02-10 15:17:42 +01:00
|
|
|
|
2023-08-12 02:44:46 +02:00
|
|
|
const placeholder = computed((): string => {
|
2022-01-15 17:46:25 +01:00
|
|
|
if (props.renote) {
|
2022-01-28 03:39:49 +01:00
|
|
|
return i18n.ts._postForm.quotePlaceholder;
|
2022-01-15 17:46:25 +01:00
|
|
|
} else if (props.reply) {
|
2022-01-28 03:39:49 +01:00
|
|
|
return i18n.ts._postForm.replyPlaceholder;
|
2022-01-15 17:46:25 +01:00
|
|
|
} else if (props.channel) {
|
2022-01-28 03:39:49 +01:00
|
|
|
return i18n.ts._postForm.channelPlaceholder;
|
2022-01-15 17:46:25 +01:00
|
|
|
} else {
|
|
|
|
const xs = [
|
2022-01-28 03:39:49 +01:00
|
|
|
i18n.ts._postForm._placeholders.a,
|
|
|
|
i18n.ts._postForm._placeholders.b,
|
|
|
|
i18n.ts._postForm._placeholders.c,
|
|
|
|
i18n.ts._postForm._placeholders.d,
|
|
|
|
i18n.ts._postForm._placeholders.e,
|
2022-07-05 16:01:23 +02:00
|
|
|
i18n.ts._postForm._placeholders.f,
|
2022-01-15 17:46:25 +01:00
|
|
|
];
|
|
|
|
return xs[Math.floor(Math.random() * xs.length)];
|
|
|
|
}
|
|
|
|
});
|
2021-08-07 05:47:01 +02:00
|
|
|
|
2023-08-12 02:44:46 +02:00
|
|
|
const submitText = computed((): string => {
|
2023-05-07 12:27:25 +02:00
|
|
|
return props.editId
|
|
|
|
? i18n.ts.edit
|
|
|
|
: props.renote
|
2024-02-11 18:50:57 +01:00
|
|
|
? i18n.ts.quote
|
|
|
|
: props.reply
|
|
|
|
? i18n.ts.reply
|
|
|
|
: i18n.ts.note;
|
2022-01-15 17:46:25 +01:00
|
|
|
});
|
2019-05-27 08:38:14 +02:00
|
|
|
|
2023-08-12 02:44:46 +02:00
|
|
|
const textLength = computed((): number => {
|
|
|
|
return length((preprocess(text.value) + imeText.value).trim());
|
2022-01-15 17:46:25 +01:00
|
|
|
});
|
2021-04-15 17:13:20 +02:00
|
|
|
|
2023-08-12 02:44:46 +02:00
|
|
|
const maxTextLength = computed((): number => {
|
2023-07-15 09:06:53 +02:00
|
|
|
return instance ? instance.maxNoteTextLength : 3000;
|
2022-01-15 17:46:25 +01:00
|
|
|
});
|
2019-05-27 08:38:14 +02:00
|
|
|
|
2023-08-12 02:44:46 +02:00
|
|
|
const canPost = computed((): boolean => {
|
2023-04-08 02:01:42 +02:00
|
|
|
return (
|
2023-08-12 02:44:46 +02:00
|
|
|
!posting.value &&
|
2023-09-02 01:27:33 +02:00
|
|
|
(textLength.value >= 1 ||
|
|
|
|
files.value.length >= 1 ||
|
2023-08-12 02:44:46 +02:00
|
|
|
!!poll.value ||
|
|
|
|
!!props.renote) &&
|
|
|
|
textLength.value <= maxTextLength.value &&
|
|
|
|
(!poll.value || poll.value.choices.length >= 2)
|
2023-04-08 02:01:42 +02:00
|
|
|
);
|
2022-01-15 17:46:25 +01:00
|
|
|
});
|
2021-10-19 20:10:36 +02:00
|
|
|
|
2023-08-12 02:44:46 +02:00
|
|
|
const withHashtags = computed(
|
2023-07-06 03:28:27 +02:00
|
|
|
defaultStore.makeGetterSetter("postFormWithHashtags"),
|
2023-04-08 02:01:42 +02:00
|
|
|
);
|
2023-08-12 02:44:46 +02:00
|
|
|
const hashtags = computed(defaultStore.makeGetterSetter("postFormHashtags"));
|
2021-10-19 20:10:36 +02:00
|
|
|
|
2023-08-12 02:44:46 +02:00
|
|
|
watch(text, () => {
|
2022-01-15 17:46:25 +01:00
|
|
|
checkMissingMention();
|
|
|
|
});
|
2021-10-19 20:10:36 +02:00
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
watch(
|
2023-08-12 02:44:46 +02:00
|
|
|
visibleUsers,
|
2023-04-08 02:01:42 +02:00
|
|
|
() => {
|
|
|
|
checkMissingMention();
|
|
|
|
},
|
|
|
|
{
|
|
|
|
deep: true,
|
2023-07-06 03:28:27 +02:00
|
|
|
},
|
2023-04-08 02:01:42 +02:00
|
|
|
);
|
2021-11-18 15:32:43 +01:00
|
|
|
|
2022-01-15 17:46:25 +01:00
|
|
|
if (props.mention) {
|
2023-08-12 02:44:46 +02:00
|
|
|
text.value = props.mention.host
|
2023-04-08 02:01:42 +02:00
|
|
|
? `@${props.mention.username}@${toASCII(props.mention.host)}`
|
|
|
|
: `@${props.mention.username}`;
|
2023-08-12 02:44:46 +02:00
|
|
|
text.value += " ";
|
2022-01-15 17:46:25 +01:00
|
|
|
}
|
2019-05-27 08:38:14 +02:00
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
if (
|
|
|
|
props.reply &&
|
|
|
|
(props.reply.user.username !== $i.username ||
|
|
|
|
(props.reply.user.host != null && props.reply.user.host !== host))
|
|
|
|
) {
|
2023-08-12 02:44:46 +02:00
|
|
|
text.value = `@${props.reply.user.username}${
|
2023-04-08 02:01:42 +02:00
|
|
|
props.reply.user.host != null
|
|
|
|
? "@" + toASCII(props.reply.user.host)
|
|
|
|
: ""
|
|
|
|
} `;
|
2022-01-15 17:46:25 +01:00
|
|
|
}
|
2019-05-27 08:38:14 +02:00
|
|
|
|
2022-01-15 17:46:25 +01:00
|
|
|
if (props.reply && props.reply.text != null) {
|
|
|
|
const ast = mfm.parse(props.reply.text);
|
|
|
|
const otherHost = props.reply.user.host;
|
2019-05-27 08:38:14 +02:00
|
|
|
|
2022-01-15 17:46:25 +01:00
|
|
|
for (const x of extractMentions(ast)) {
|
2023-04-08 02:01:42 +02:00
|
|
|
const mention = x.host
|
|
|
|
? `@${x.username}@${toASCII(x.host)}`
|
|
|
|
: otherHost == null || otherHost === host
|
2024-02-11 18:50:57 +01:00
|
|
|
? `@${x.username}`
|
|
|
|
: `@${x.username}@${toASCII(otherHost)}`;
|
2019-05-27 08:38:14 +02:00
|
|
|
|
2023-11-22 14:21:47 +01:00
|
|
|
// exclude me
|
2023-04-08 02:01:42 +02:00
|
|
|
if ($i.username === x.username && (x.host == null || x.host === host))
|
|
|
|
continue;
|
2019-05-27 08:38:14 +02:00
|
|
|
|
2023-11-22 14:21:47 +01:00
|
|
|
// remove duplicates
|
2023-08-12 02:44:46 +02:00
|
|
|
if (text.value.includes(`${mention} `)) continue;
|
2019-05-27 08:38:14 +02:00
|
|
|
|
2023-08-12 02:44:46 +02:00
|
|
|
text.value += `${mention} `;
|
2022-01-15 17:46:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (props.channel) {
|
2023-08-12 02:44:46 +02:00
|
|
|
visibility.value = "public";
|
2023-11-22 14:21:47 +01:00
|
|
|
localOnly.value = true; // TODO: Delete this once channels get federated
|
2022-01-15 17:46:25 +01:00
|
|
|
}
|
|
|
|
|
2023-11-22 14:21:47 +01:00
|
|
|
// Inherit the original visibility
|
2023-04-08 02:01:42 +02:00
|
|
|
if (
|
|
|
|
props.reply &&
|
|
|
|
["home", "followers", "specified"].includes(props.reply.visibility)
|
|
|
|
) {
|
2023-08-12 02:44:46 +02:00
|
|
|
if (props.reply.visibility === "home" && visibility.value === "followers") {
|
|
|
|
visibility.value = "followers";
|
2023-05-02 05:32:18 +02:00
|
|
|
} else if (
|
|
|
|
["home", "followers"].includes(props.reply.visibility) &&
|
2023-08-12 02:44:46 +02:00
|
|
|
visibility.value === "specified"
|
2023-05-02 05:32:18 +02:00
|
|
|
) {
|
2023-08-12 02:44:46 +02:00
|
|
|
visibility.value = "specified";
|
2023-05-01 17:42:27 +02:00
|
|
|
} else {
|
2023-08-12 02:44:46 +02:00
|
|
|
visibility.value = props.reply.visibility;
|
2023-05-01 17:42:27 +02:00
|
|
|
}
|
2023-08-12 02:44:46 +02:00
|
|
|
if (visibility.value === "specified") {
|
2023-05-01 17:42:27 +02:00
|
|
|
if (props.reply.visibleUserIds) {
|
2023-05-02 05:32:18 +02:00
|
|
|
os.api("users/show", {
|
|
|
|
userIds: props.reply.visibleUserIds.filter(
|
2023-07-06 03:28:27 +02:00
|
|
|
(uid) => uid !== $i.id && uid !== props.reply.userId,
|
2023-05-02 05:32:18 +02:00
|
|
|
),
|
|
|
|
}).then((users) => {
|
2023-05-01 17:42:27 +02:00
|
|
|
users.forEach(pushVisibleUser);
|
|
|
|
});
|
|
|
|
}
|
2019-05-27 08:38:14 +02:00
|
|
|
|
2022-01-15 17:46:25 +01:00
|
|
|
if (props.reply.userId !== $i.id) {
|
2023-04-08 02:01:42 +02:00
|
|
|
os.api("users/show", { userId: props.reply.userId }).then(
|
|
|
|
(user) => {
|
|
|
|
pushVisibleUser(user);
|
2023-07-06 03:28:27 +02:00
|
|
|
},
|
2023-04-08 02:01:42 +02:00
|
|
|
);
|
2020-08-18 15:44:21 +02:00
|
|
|
}
|
2022-01-15 17:46:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (props.specified) {
|
2023-08-12 02:44:46 +02:00
|
|
|
visibility.value = "specified";
|
2022-02-01 13:49:34 +01:00
|
|
|
pushVisibleUser(props.specified);
|
2022-01-15 17:46:25 +01:00
|
|
|
}
|
|
|
|
|
2023-07-21 15:48:27 +02:00
|
|
|
const addRe = (s: string) => {
|
|
|
|
if (
|
|
|
|
!defaultStore.state.addRe ||
|
|
|
|
s.trim() === "" ||
|
|
|
|
s.slice(0, 3).toLowerCase() === "re:"
|
|
|
|
)
|
|
|
|
return s;
|
|
|
|
return `re: ${s}`;
|
|
|
|
};
|
|
|
|
|
2022-01-15 17:46:25 +01:00
|
|
|
// keep cw when reply
|
|
|
|
if (defaultStore.state.keepCw && props.reply && props.reply.cw) {
|
2023-08-12 02:44:46 +02:00
|
|
|
useCw.value = true;
|
|
|
|
cw.value =
|
2023-07-21 15:48:27 +02:00
|
|
|
props.reply.user.username === $i.username
|
|
|
|
? props.reply.cw
|
|
|
|
: addRe(props.reply.cw);
|
2022-01-15 17:46:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function watchForDraft() {
|
2023-08-12 02:44:46 +02:00
|
|
|
watch(text, () => saveDraft());
|
|
|
|
watch(useCw, () => saveDraft());
|
|
|
|
watch(cw, () => saveDraft());
|
|
|
|
watch(poll, () => saveDraft());
|
|
|
|
watch(files, () => saveDraft(), { deep: true });
|
|
|
|
watch(visibility, () => saveDraft());
|
|
|
|
watch(localOnly, () => saveDraft());
|
2023-10-06 05:28:12 +02:00
|
|
|
watch(language, () => saveDraft());
|
2022-01-15 17:46:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function checkMissingMention() {
|
2023-08-12 02:44:46 +02:00
|
|
|
if (visibility.value === "specified") {
|
|
|
|
const ast = mfm.parse(text.value);
|
2022-01-15 17:46:25 +01:00
|
|
|
|
|
|
|
for (const x of extractMentions(ast)) {
|
2023-04-08 02:01:42 +02:00
|
|
|
if (
|
2023-08-12 02:44:46 +02:00
|
|
|
!visibleUsers.value.some(
|
2023-07-06 03:28:27 +02:00
|
|
|
(u) => u.username === x.username && u.host === x.host,
|
2023-04-08 02:01:42 +02:00
|
|
|
)
|
|
|
|
) {
|
2023-08-12 02:44:46 +02:00
|
|
|
hasNotSpecifiedMentions.value = true;
|
2022-01-15 17:46:25 +01:00
|
|
|
return;
|
2019-08-25 09:12:01 +02:00
|
|
|
}
|
2019-05-27 08:38:14 +02:00
|
|
|
}
|
2023-08-12 02:44:46 +02:00
|
|
|
hasNotSpecifiedMentions.value = false;
|
2022-01-15 17:46:25 +01:00
|
|
|
}
|
|
|
|
}
|
2019-05-27 08:38:14 +02:00
|
|
|
|
2022-01-15 17:46:25 +01:00
|
|
|
function addMissingMention() {
|
2023-08-12 02:44:46 +02:00
|
|
|
const ast = mfm.parse(text.value);
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2022-01-15 17:46:25 +01:00
|
|
|
for (const x of extractMentions(ast)) {
|
2023-04-08 02:01:42 +02:00
|
|
|
if (
|
2023-08-12 02:44:46 +02:00
|
|
|
!visibleUsers.value.some(
|
2023-07-06 03:28:27 +02:00
|
|
|
(u) => u.username === x.username && u.host === x.host,
|
2023-04-08 02:01:42 +02:00
|
|
|
)
|
|
|
|
) {
|
|
|
|
os.api("users/show", { username: x.username, host: x.host }).then(
|
|
|
|
(user) => {
|
2023-08-12 02:44:46 +02:00
|
|
|
visibleUsers.value.push(user);
|
2023-07-06 03:28:27 +02:00
|
|
|
},
|
2023-04-08 02:01:42 +02:00
|
|
|
);
|
2020-10-17 13:12:00 +02:00
|
|
|
}
|
2022-01-15 17:46:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function togglePoll() {
|
2023-08-12 02:44:46 +02:00
|
|
|
if (poll.value) {
|
|
|
|
poll.value = null;
|
2022-01-15 17:46:25 +01:00
|
|
|
} else {
|
2023-08-12 02:44:46 +02:00
|
|
|
poll.value = {
|
2023-04-08 02:01:42 +02:00
|
|
|
choices: ["", ""],
|
2022-01-15 17:46:25 +01:00
|
|
|
multiple: false,
|
|
|
|
expiresAt: null,
|
|
|
|
expiredAfter: null,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2022-01-15 17:46:25 +01:00
|
|
|
function focus() {
|
2023-08-12 02:44:46 +02:00
|
|
|
if (textareaEl.value) {
|
|
|
|
textareaEl.value.focus();
|
|
|
|
textareaEl.value.setSelectionRange(
|
|
|
|
textareaEl.value.value.length,
|
|
|
|
textareaEl.value.value.length,
|
2023-04-08 02:01:42 +02:00
|
|
|
);
|
2022-02-09 13:27:42 +01:00
|
|
|
}
|
2022-01-15 17:46:25 +01:00
|
|
|
}
|
2021-04-15 17:13:20 +02:00
|
|
|
|
2022-01-15 17:46:25 +01:00
|
|
|
function chooseFileFrom(ev) {
|
2023-04-08 02:01:42 +02:00
|
|
|
selectFiles(ev.currentTarget ?? ev.target, i18n.ts.attachFile).then(
|
|
|
|
(files_) => {
|
|
|
|
for (const file of files_) {
|
2023-08-12 02:44:46 +02:00
|
|
|
files.value.push(file);
|
2023-04-08 02:01:42 +02:00
|
|
|
}
|
2023-07-06 03:28:27 +02:00
|
|
|
},
|
2023-04-08 02:01:42 +02:00
|
|
|
);
|
2022-01-15 17:46:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function detachFile(id) {
|
2023-08-12 02:44:46 +02:00
|
|
|
files.value = files.value.filter((x) => x.id !== id);
|
2022-01-15 17:46:25 +01:00
|
|
|
}
|
|
|
|
|
2022-01-20 15:15:08 +01:00
|
|
|
function updateFiles(_files) {
|
2023-08-12 02:44:46 +02:00
|
|
|
files.value = _files;
|
2022-01-15 17:46:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function updateFileSensitive(file, sensitive) {
|
2023-08-12 02:44:46 +02:00
|
|
|
files.value[files.value.findIndex((x) => x.id === file.id)].isSensitive =
|
|
|
|
sensitive;
|
2022-01-15 17:46:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function updateFileName(file, name) {
|
2023-08-12 02:44:46 +02:00
|
|
|
files.value[files.value.findIndex((x) => x.id === file.id)].name = name;
|
2022-01-15 17:46:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function upload(file: File, name?: string) {
|
2023-04-08 02:01:42 +02:00
|
|
|
uploadFile(file, defaultStore.state.uploadFolder, name).then((res) => {
|
2023-08-12 02:44:46 +02:00
|
|
|
files.value.push(res);
|
2022-01-15 17:46:25 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function setVisibility() {
|
|
|
|
if (props.channel) {
|
|
|
|
// TODO: information dialog
|
|
|
|
return;
|
|
|
|
}
|
2021-04-15 17:13:20 +02:00
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
os.popup(
|
|
|
|
defineAsyncComponent(
|
2023-07-06 03:28:27 +02:00
|
|
|
() => import("@/components/MkVisibilityPicker.vue"),
|
2023-04-08 02:01:42 +02:00
|
|
|
),
|
|
|
|
{
|
2023-08-12 02:44:46 +02:00
|
|
|
currentVisibility: visibility.value,
|
|
|
|
currentLocalOnly: localOnly.value,
|
|
|
|
src: visibilityButton.value,
|
2021-04-15 17:13:20 +02:00
|
|
|
},
|
2023-04-08 02:01:42 +02:00
|
|
|
{
|
|
|
|
changeVisibility: (v) => {
|
2023-08-12 02:44:46 +02:00
|
|
|
visibility.value = v;
|
2023-04-08 02:01:42 +02:00
|
|
|
if (defaultStore.state.rememberNoteVisibility) {
|
2023-08-12 02:44:46 +02:00
|
|
|
defaultStore.set("visibility", visibility.value);
|
2023-04-08 02:01:42 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
changeLocalOnly: (v) => {
|
2023-08-12 02:44:46 +02:00
|
|
|
localOnly.value = v;
|
2023-04-08 02:01:42 +02:00
|
|
|
if (defaultStore.state.rememberNoteVisibility) {
|
2023-08-12 02:44:46 +02:00
|
|
|
defaultStore.set("localOnly", localOnly.value);
|
2023-04-08 02:01:42 +02:00
|
|
|
}
|
|
|
|
},
|
2022-07-05 16:01:23 +02:00
|
|
|
},
|
2023-07-06 03:28:27 +02:00
|
|
|
"closed",
|
2023-04-08 02:01:42 +02:00
|
|
|
);
|
2022-01-15 17:46:25 +01:00
|
|
|
}
|
|
|
|
|
2023-11-28 17:47:48 +01:00
|
|
|
const language = ref<string | null>(
|
2023-11-23 09:49:13 +01:00
|
|
|
props.initialLanguage ??
|
|
|
|
defaultStore.state.recentlyUsedPostLanguages[0] ??
|
|
|
|
localStorage.getItem("lang")?.split("-")[0],
|
|
|
|
);
|
|
|
|
|
2023-11-22 20:24:21 +01:00
|
|
|
function filterLangmapByPrefix(
|
2023-11-22 15:19:14 +01:00
|
|
|
prefix: string,
|
2023-11-22 20:24:21 +01:00
|
|
|
): { langCode: string; nativeName: string }[] {
|
2023-11-28 17:47:48 +01:00
|
|
|
let to_return = Object.entries(langmap)
|
2023-11-22 20:24:21 +01:00
|
|
|
.filter(([langCode, _]) => langCode.startsWith(prefix))
|
|
|
|
.map(([langCode, v]) => {
|
|
|
|
return { langCode, nativeName: v.nativeName };
|
2023-11-22 15:19:14 +01:00
|
|
|
});
|
2023-11-23 11:48:33 +01:00
|
|
|
|
|
|
|
if (prefix === "zh")
|
|
|
|
to_return = to_return.concat([
|
|
|
|
{ langCode: "yue", nativeName: langmap["yue"].nativeName },
|
|
|
|
{ langCode: "nan", nativeName: langmap["nan"].nativeName },
|
|
|
|
]);
|
|
|
|
|
|
|
|
return to_return;
|
2023-11-22 15:19:14 +01:00
|
|
|
}
|
|
|
|
|
2023-10-06 05:28:12 +02:00
|
|
|
function setLanguage() {
|
2023-11-17 09:17:46 +01:00
|
|
|
const actions: Array<MenuItem> = [];
|
|
|
|
|
2023-11-23 09:49:13 +01:00
|
|
|
const detectedLanguage: string = detectLanguage(text.value) ?? "";
|
|
|
|
if (detectedLanguage !== "" && detectedLanguage !== language.value) {
|
2023-11-22 15:19:14 +01:00
|
|
|
actions.push({
|
|
|
|
type: "label",
|
|
|
|
text: i18n.ts.suggested,
|
|
|
|
});
|
2023-11-22 20:24:21 +01:00
|
|
|
filterLangmapByPrefix(detectedLanguage).forEach((v) => {
|
2023-11-22 15:19:14 +01:00
|
|
|
actions.push({
|
|
|
|
text: v.nativeName,
|
2023-11-17 09:17:46 +01:00
|
|
|
danger: false,
|
|
|
|
active: false,
|
|
|
|
action: () => {
|
2023-11-22 20:24:21 +01:00
|
|
|
language.value = v.langCode;
|
2023-11-17 09:17:46 +01:00
|
|
|
},
|
2023-11-22 15:19:14 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
actions.push(null);
|
|
|
|
}
|
2023-11-17 09:17:46 +01:00
|
|
|
|
|
|
|
if (language.value != null)
|
2023-10-17 05:44:55 +02:00
|
|
|
actions.push({
|
|
|
|
text: langmap[language.value].nativeName,
|
|
|
|
danger: false,
|
|
|
|
active: true,
|
|
|
|
action: () => {},
|
|
|
|
});
|
2023-10-06 05:28:12 +02:00
|
|
|
|
|
|
|
const langs = Object.keys(langmap);
|
2023-11-23 09:49:13 +01:00
|
|
|
|
|
|
|
// Show recently used language first
|
|
|
|
let recentlyUsedLanguagesExist = false;
|
|
|
|
for (const lang of defaultStore.state.recentlyUsedPostLanguages) {
|
|
|
|
if (lang === language.value) continue;
|
|
|
|
if (!langs.includes(lang)) continue;
|
|
|
|
actions.push({
|
|
|
|
text: langmap[lang].nativeName,
|
|
|
|
danger: false,
|
|
|
|
active: false,
|
|
|
|
action: () => {
|
|
|
|
language.value = lang;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
recentlyUsedLanguagesExist = true;
|
|
|
|
}
|
|
|
|
if (recentlyUsedLanguagesExist) actions.push(null);
|
|
|
|
|
2023-11-28 17:47:48 +01:00
|
|
|
actions.push({
|
|
|
|
text: i18n.ts.noLanguage,
|
|
|
|
danger: false,
|
|
|
|
active: false,
|
|
|
|
action: () => {
|
|
|
|
language.value = null;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2023-10-06 05:28:12 +02:00
|
|
|
for (const lang of langs) {
|
|
|
|
if (lang === language.value) continue;
|
2023-11-23 09:49:13 +01:00
|
|
|
if (defaultStore.state.recentlyUsedPostLanguages.includes(lang))
|
|
|
|
continue;
|
2023-10-06 05:28:12 +02:00
|
|
|
actions.push({
|
|
|
|
text: langmap[lang].nativeName,
|
|
|
|
danger: false,
|
|
|
|
active: false,
|
|
|
|
action: () => {
|
|
|
|
language.value = lang;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
os.popupMenu(actions, languageButton.value, {});
|
|
|
|
}
|
|
|
|
|
2022-02-01 13:49:34 +01:00
|
|
|
function pushVisibleUser(user) {
|
2023-04-08 02:01:42 +02:00
|
|
|
if (
|
2023-08-12 02:44:46 +02:00
|
|
|
!visibleUsers.value.some(
|
2023-07-06 03:28:27 +02:00
|
|
|
(u) => u.username === user.username && u.host === user.host,
|
2023-04-08 02:01:42 +02:00
|
|
|
)
|
|
|
|
) {
|
2023-08-12 02:44:46 +02:00
|
|
|
visibleUsers.value.push(user);
|
2022-02-01 13:49:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-15 17:46:25 +01:00
|
|
|
function addVisibleUser() {
|
2023-04-08 02:01:42 +02:00
|
|
|
os.selectUser().then((user) => {
|
2022-02-01 13:49:34 +01:00
|
|
|
pushVisibleUser(user);
|
2022-01-15 17:46:25 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeVisibleUser(user) {
|
2023-08-12 02:44:46 +02:00
|
|
|
visibleUsers.value = erase(user, visibleUsers.value);
|
2022-01-15 17:46:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function clear() {
|
2023-08-12 02:44:46 +02:00
|
|
|
text.value = "";
|
|
|
|
files.value = [];
|
|
|
|
poll.value = null;
|
|
|
|
quoteId.value = null;
|
2022-01-15 17:46:25 +01:00
|
|
|
}
|
|
|
|
|
2023-11-22 14:21:47 +01:00
|
|
|
// FIXME: ev.which is deprecated
|
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/which
|
2022-05-07 10:01:01 +02:00
|
|
|
function onKeydown(ev: KeyboardEvent) {
|
2023-04-08 02:01:42 +02:00
|
|
|
if (
|
|
|
|
(ev.which === 10 || ev.which === 13) &&
|
|
|
|
(ev.ctrlKey || ev.metaKey) &&
|
2023-08-12 02:44:46 +02:00
|
|
|
canPost.value
|
2023-04-08 02:01:42 +02:00
|
|
|
)
|
|
|
|
post();
|
|
|
|
if (ev.which === 27) emit("esc");
|
2022-01-15 17:46:25 +01:00
|
|
|
typing();
|
|
|
|
}
|
|
|
|
|
2022-05-07 10:01:01 +02:00
|
|
|
function onCompositionUpdate(ev: CompositionEvent) {
|
2023-08-12 02:44:46 +02:00
|
|
|
imeText.value = ev.data;
|
2022-01-15 17:46:25 +01:00
|
|
|
typing();
|
|
|
|
}
|
|
|
|
|
2022-05-07 10:01:01 +02:00
|
|
|
function onCompositionEnd(ev: CompositionEvent) {
|
2023-08-12 02:44:46 +02:00
|
|
|
imeText.value = "";
|
2022-01-15 17:46:25 +01:00
|
|
|
}
|
|
|
|
|
2022-05-07 10:01:01 +02:00
|
|
|
async function onPaste(ev: ClipboardEvent) {
|
2023-04-08 02:01:42 +02:00
|
|
|
for (const { item, i } of Array.from(ev.clipboardData.items).map(
|
2023-07-06 03:28:27 +02:00
|
|
|
(item, i) => ({ item, i }),
|
2023-04-08 02:01:42 +02:00
|
|
|
)) {
|
|
|
|
if (item.kind === "file") {
|
2022-01-15 17:46:25 +01:00
|
|
|
const file = item.getAsFile();
|
2023-04-08 02:01:42 +02:00
|
|
|
const lio = file.name.lastIndexOf(".");
|
|
|
|
const ext = lio >= 0 ? file.name.slice(lio) : "";
|
|
|
|
const formatted = `${formatTimeString(
|
|
|
|
new Date(file.lastModified),
|
2023-07-06 03:28:27 +02:00
|
|
|
defaultStore.state.pastedFileName,
|
2023-04-08 02:01:42 +02:00
|
|
|
).replace(/{{number}}/g, `${i + 1}`)}${ext}`;
|
2022-01-15 17:46:25 +01:00
|
|
|
upload(file, formatted);
|
|
|
|
}
|
|
|
|
}
|
2020-12-05 04:50:09 +01:00
|
|
|
|
2023-11-22 14:21:47 +01:00
|
|
|
const paste = ev.clipboardData?.getData("text") ?? "";
|
2019-05-27 08:38:14 +02:00
|
|
|
|
2023-08-12 02:44:46 +02:00
|
|
|
if (!props.renote && !quoteId.value && paste.startsWith(url + "/notes/")) {
|
2022-05-07 10:01:01 +02:00
|
|
|
ev.preventDefault();
|
2019-05-27 08:38:14 +02:00
|
|
|
|
2022-11-16 07:38:05 +01:00
|
|
|
os.yesno({
|
2023-04-08 02:01:42 +02:00
|
|
|
type: "info",
|
2022-01-28 03:39:49 +01:00
|
|
|
text: i18n.ts.quoteQuestion,
|
2022-01-15 17:46:25 +01:00
|
|
|
}).then(({ canceled }) => {
|
|
|
|
if (canceled) {
|
2023-08-12 02:44:46 +02:00
|
|
|
insertTextAtCursor(textareaEl.value, paste);
|
2020-08-18 15:44:21 +02:00
|
|
|
return;
|
|
|
|
}
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2023-08-12 02:44:46 +02:00
|
|
|
quoteId.value = paste
|
2023-11-22 14:21:47 +01:00
|
|
|
.substring(url.length)
|
2023-08-12 02:44:46 +02:00
|
|
|
.match(/^\/notes\/(.+?)\/?$/)[1];
|
2022-01-15 17:46:25 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-07 10:01:01 +02:00
|
|
|
function onDragover(ev) {
|
|
|
|
if (!ev.dataTransfer.items[0]) return;
|
2023-04-08 02:01:42 +02:00
|
|
|
const isFile = ev.dataTransfer.items[0].kind === "file";
|
2022-05-07 10:01:01 +02:00
|
|
|
const isDriveFile = ev.dataTransfer.types[0] === _DATA_TRANSFER_DRIVE_FILE_;
|
2022-01-15 17:46:25 +01:00
|
|
|
if (isFile || isDriveFile) {
|
2022-05-07 10:01:01 +02:00
|
|
|
ev.preventDefault();
|
2023-08-12 02:44:46 +02:00
|
|
|
draghover.value = true;
|
2022-07-25 14:16:11 +02:00
|
|
|
switch (ev.dataTransfer.effectAllowed) {
|
2023-04-08 02:01:42 +02:00
|
|
|
case "all":
|
|
|
|
case "uninitialized":
|
|
|
|
case "copy":
|
|
|
|
case "copyLink":
|
|
|
|
case "copyMove":
|
|
|
|
ev.dataTransfer.dropEffect = "copy";
|
2022-07-25 14:16:11 +02:00
|
|
|
break;
|
2023-04-08 02:01:42 +02:00
|
|
|
case "linkMove":
|
|
|
|
case "move":
|
|
|
|
ev.dataTransfer.dropEffect = "move";
|
2022-07-25 14:16:11 +02:00
|
|
|
break;
|
|
|
|
default:
|
2023-04-08 02:01:42 +02:00
|
|
|
ev.dataTransfer.dropEffect = "none";
|
2022-07-25 14:16:11 +02:00
|
|
|
break;
|
|
|
|
}
|
2022-01-15 17:46:25 +01:00
|
|
|
}
|
|
|
|
}
|
2021-01-15 15:20:47 +01:00
|
|
|
|
2022-05-07 10:01:01 +02:00
|
|
|
function onDragenter(ev) {
|
2023-08-12 02:44:46 +02:00
|
|
|
draghover.value = true;
|
2022-01-15 17:46:25 +01:00
|
|
|
}
|
2021-01-15 15:20:47 +01:00
|
|
|
|
2022-05-07 10:01:01 +02:00
|
|
|
function onDragleave(ev) {
|
2023-08-12 02:44:46 +02:00
|
|
|
draghover.value = false;
|
2022-01-15 17:46:25 +01:00
|
|
|
}
|
2019-05-27 08:38:14 +02:00
|
|
|
|
2022-05-07 10:01:01 +02:00
|
|
|
function onDrop(ev): void {
|
2023-08-12 02:44:46 +02:00
|
|
|
draghover.value = false;
|
2019-05-27 08:38:14 +02:00
|
|
|
|
2022-01-15 17:46:25 +01:00
|
|
|
// ファイルだったら
|
2022-05-07 10:01:01 +02:00
|
|
|
if (ev.dataTransfer.files.length > 0) {
|
|
|
|
ev.preventDefault();
|
|
|
|
for (const x of Array.from(ev.dataTransfer.files)) upload(x);
|
2022-01-15 17:46:25 +01:00
|
|
|
return;
|
|
|
|
}
|
2019-05-27 08:38:14 +02:00
|
|
|
|
2023-09-02 01:27:33 +02:00
|
|
|
// #region ドライブのファイル
|
2022-05-07 10:01:01 +02:00
|
|
|
const driveFile = ev.dataTransfer.getData(_DATA_TRANSFER_DRIVE_FILE_);
|
2023-04-08 02:01:42 +02:00
|
|
|
if (driveFile != null && driveFile !== "") {
|
2022-01-15 17:46:25 +01:00
|
|
|
const file = JSON.parse(driveFile);
|
2023-08-12 02:44:46 +02:00
|
|
|
files.value.push(file);
|
2022-05-07 10:01:01 +02:00
|
|
|
ev.preventDefault();
|
2022-01-15 17:46:25 +01:00
|
|
|
}
|
2023-09-02 01:27:33 +02:00
|
|
|
// #endregion
|
2022-01-15 17:46:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function saveDraft() {
|
2023-04-08 02:01:42 +02:00
|
|
|
const draftData = JSON.parse(localStorage.getItem("drafts") || "{}");
|
2022-01-15 17:46:25 +01:00
|
|
|
|
2023-08-12 02:44:46 +02:00
|
|
|
draftData[draftKey.value] = {
|
2022-01-15 17:46:25 +01:00
|
|
|
updatedAt: new Date(),
|
|
|
|
data: {
|
2023-08-12 02:44:46 +02:00
|
|
|
text: text.value,
|
|
|
|
useCw: useCw.value,
|
|
|
|
cw: cw.value,
|
|
|
|
visibility: visibility.value,
|
|
|
|
localOnly: localOnly.value,
|
2023-10-06 05:28:12 +02:00
|
|
|
lang: language.value,
|
2023-08-12 02:44:46 +02:00
|
|
|
files: files.value,
|
|
|
|
poll: poll.value,
|
2022-07-05 16:01:23 +02:00
|
|
|
},
|
2022-01-15 17:46:25 +01:00
|
|
|
};
|
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
localStorage.setItem("drafts", JSON.stringify(draftData));
|
2022-01-15 17:46:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function deleteDraft() {
|
2023-04-08 02:01:42 +02:00
|
|
|
const draftData = JSON.parse(localStorage.getItem("drafts") || "{}");
|
2022-01-15 17:46:25 +01:00
|
|
|
|
2023-08-12 02:44:46 +02:00
|
|
|
delete draftData[draftKey.value];
|
2022-01-15 17:46:25 +01:00
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
localStorage.setItem("drafts", JSON.stringify(draftData));
|
2022-01-15 17:46:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
async function post() {
|
2023-08-12 02:44:46 +02:00
|
|
|
const processedText = preprocess(text.value);
|
2023-03-30 05:11:57 +02:00
|
|
|
|
2022-05-07 10:01:01 +02:00
|
|
|
let postData = {
|
2023-05-07 12:27:25 +02:00
|
|
|
editId: props.editId ? props.editId : undefined,
|
2023-04-08 02:01:42 +02:00
|
|
|
text: processedText === "" ? undefined : processedText,
|
2023-08-12 02:44:46 +02:00
|
|
|
fileIds:
|
|
|
|
files.value.length > 0 ? files.value.map((f) => f.id) : undefined,
|
2022-01-15 17:46:25 +01:00
|
|
|
replyId: props.reply ? props.reply.id : undefined,
|
2023-04-08 02:01:42 +02:00
|
|
|
renoteId: props.renote
|
|
|
|
? props.renote.id
|
2023-08-12 02:44:46 +02:00
|
|
|
: quoteId.value
|
2024-02-11 18:50:57 +01:00
|
|
|
? quoteId.value
|
|
|
|
: undefined,
|
2022-01-15 17:46:25 +01:00
|
|
|
channelId: props.channel ? props.channel.id : undefined,
|
2023-08-12 02:44:46 +02:00
|
|
|
poll: poll.value,
|
|
|
|
cw: useCw.value ? cw.value || "" : undefined,
|
2023-11-29 07:32:23 +01:00
|
|
|
lang: language.value ? language.value : undefined,
|
2023-08-12 02:44:46 +02:00
|
|
|
localOnly: localOnly.value,
|
|
|
|
visibility: visibility.value,
|
2023-04-08 02:01:42 +02:00
|
|
|
visibleUserIds:
|
2023-08-12 02:44:46 +02:00
|
|
|
visibility.value === "specified"
|
|
|
|
? visibleUsers.value.map((u) => u.id)
|
2023-04-08 02:01:42 +02:00
|
|
|
: undefined,
|
2022-01-15 17:46:25 +01:00
|
|
|
};
|
|
|
|
|
2023-08-12 02:44:46 +02:00
|
|
|
if (withHashtags.value && hashtags.value && hashtags.value.trim() !== "") {
|
|
|
|
const hashtags_ = hashtags.value
|
2023-04-08 02:01:42 +02:00
|
|
|
.trim()
|
|
|
|
.split(" ")
|
|
|
|
.map((x) => (x.startsWith("#") ? x : "#" + x))
|
|
|
|
.join(" ");
|
|
|
|
postData.text = postData.text
|
|
|
|
? `${postData.text} ${hashtags_}`
|
|
|
|
: hashtags_;
|
2022-01-15 17:46:25 +01:00
|
|
|
}
|
2019-05-27 08:38:14 +02:00
|
|
|
|
2022-01-15 17:46:25 +01:00
|
|
|
// plugin
|
|
|
|
if (notePostInterruptors.length > 0) {
|
|
|
|
for (const interruptor of notePostInterruptors) {
|
2022-11-17 01:31:07 +01:00
|
|
|
postData = await interruptor.handler(deepClone(postData));
|
2022-01-15 17:46:25 +01:00
|
|
|
}
|
|
|
|
}
|
2019-05-27 08:38:14 +02:00
|
|
|
|
2023-09-02 01:27:33 +02:00
|
|
|
let token;
|
2022-01-21 12:17:31 +01:00
|
|
|
|
2023-08-12 02:44:46 +02:00
|
|
|
if (postAccount.value) {
|
2022-01-21 12:17:31 +01:00
|
|
|
const storedAccounts = await getAccounts();
|
2024-02-11 18:50:57 +01:00
|
|
|
token = storedAccounts.find(
|
|
|
|
(x) => x.id === postAccount.value.id,
|
|
|
|
)?.token;
|
2022-01-21 12:17:31 +01:00
|
|
|
}
|
|
|
|
|
2023-08-12 02:44:46 +02:00
|
|
|
posting.value = true;
|
2023-05-07 12:27:25 +02:00
|
|
|
os.api(postData.editId ? "notes/edit" : "notes/create", postData, token)
|
2023-04-08 02:01:42 +02:00
|
|
|
.then(() => {
|
|
|
|
clear();
|
|
|
|
nextTick(() => {
|
|
|
|
deleteDraft();
|
|
|
|
emit("posted");
|
|
|
|
if (postData.text && postData.text !== "") {
|
|
|
|
const hashtags_ = mfm
|
|
|
|
.parse(postData.text)
|
|
|
|
.filter((x) => x.type === "hashtag")
|
|
|
|
.map((x) => x.props.hashtag);
|
|
|
|
const history = JSON.parse(
|
2023-07-06 03:28:27 +02:00
|
|
|
localStorage.getItem("hashtags") || "[]",
|
2023-04-08 02:01:42 +02:00
|
|
|
) as string[];
|
|
|
|
localStorage.setItem(
|
|
|
|
"hashtags",
|
2023-07-06 03:28:27 +02:00
|
|
|
JSON.stringify(unique(hashtags_.concat(history))),
|
2023-04-08 02:01:42 +02:00
|
|
|
);
|
|
|
|
}
|
2023-08-12 02:44:46 +02:00
|
|
|
posting.value = false;
|
|
|
|
postAccount.value = null;
|
2023-04-08 02:01:42 +02:00
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
2023-08-12 02:44:46 +02:00
|
|
|
posting.value = false;
|
2023-04-08 02:01:42 +02:00
|
|
|
os.alert({
|
|
|
|
type: "error",
|
|
|
|
text: err.message + "\n" + (err as any).id,
|
|
|
|
});
|
2022-01-15 17:46:25 +01:00
|
|
|
});
|
2023-09-17 23:59:09 +02:00
|
|
|
vibrate([10, 20, 10, 20, 10, 20, 60]);
|
2023-11-23 09:49:13 +01:00
|
|
|
|
|
|
|
// update recentlyUsedLanguages
|
|
|
|
if (language.value != null) {
|
|
|
|
const languages = Object.keys(langmap);
|
2023-11-23 17:31:24 +01:00
|
|
|
const maxLength = 6;
|
2023-11-23 09:49:13 +01:00
|
|
|
|
2023-12-27 13:07:20 +01:00
|
|
|
defaultStore.set(
|
|
|
|
"recentlyUsedPostLanguages",
|
|
|
|
[language.value]
|
|
|
|
.concat(
|
|
|
|
defaultStore.state.recentlyUsedPostLanguages.filter(
|
|
|
|
(lang) => {
|
|
|
|
return (
|
|
|
|
lang !== language.value &&
|
|
|
|
languages.includes(lang)
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.slice(0, maxLength),
|
|
|
|
);
|
2023-11-23 09:49:13 +01:00
|
|
|
}
|
2022-01-15 17:46:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function cancel() {
|
2023-04-08 02:01:42 +02:00
|
|
|
emit("cancel");
|
2022-01-15 17:46:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function insertMention() {
|
2023-04-08 02:01:42 +02:00
|
|
|
os.selectUser().then((user) => {
|
2023-08-12 02:44:46 +02:00
|
|
|
insertTextAtCursor(textareaEl.value, "@" + Acct.toString(user) + " ");
|
2022-01-15 17:46:25 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-01-21 12:17:31 +01:00
|
|
|
async function insertEmoji(ev: MouseEvent) {
|
2023-08-12 02:44:46 +02:00
|
|
|
os.openEmojiPicker(ev.currentTarget ?? ev.target, {}, textareaEl.value);
|
2022-01-15 17:46:25 +01:00
|
|
|
}
|
|
|
|
|
2023-01-29 03:56:48 +01:00
|
|
|
async function openCheatSheet(ev: MouseEvent) {
|
2023-04-08 02:01:42 +02:00
|
|
|
os.popup(XCheatSheet, {}, {}, "closed");
|
2023-01-29 03:56:48 +01:00
|
|
|
}
|
|
|
|
|
2022-01-15 17:46:25 +01:00
|
|
|
function showActions(ev) {
|
2023-04-08 02:01:42 +02:00
|
|
|
os.popupMenu(
|
|
|
|
postFormActions.map((action) => ({
|
|
|
|
text: action.title,
|
|
|
|
action: () => {
|
|
|
|
action.handler(
|
|
|
|
{
|
2023-08-12 02:44:46 +02:00
|
|
|
text: text.value,
|
2023-04-08 02:01:42 +02:00
|
|
|
},
|
|
|
|
(key, value) => {
|
|
|
|
if (key === "text") {
|
2023-08-12 02:44:46 +02:00
|
|
|
text.value = value;
|
2023-04-08 02:01:42 +02:00
|
|
|
}
|
2023-07-06 03:28:27 +02:00
|
|
|
},
|
2023-04-08 02:01:42 +02:00
|
|
|
);
|
|
|
|
},
|
|
|
|
})),
|
2023-07-06 03:28:27 +02:00
|
|
|
ev.currentTarget ?? ev.target,
|
2023-04-08 02:01:42 +02:00
|
|
|
);
|
2022-01-15 17:46:25 +01:00
|
|
|
}
|
2019-05-27 08:38:14 +02:00
|
|
|
|
2023-09-24 06:27:16 +02:00
|
|
|
const postAccount = ref<firefish.entities.UserDetailed | null>(null);
|
2022-01-21 12:17:31 +01:00
|
|
|
|
|
|
|
function openAccountMenu(ev: MouseEvent) {
|
2023-04-08 02:01:42 +02:00
|
|
|
openAccountMenu_(
|
|
|
|
{
|
|
|
|
withExtraOperation: false,
|
|
|
|
includeCurrentAccount: true,
|
2023-08-12 02:44:46 +02:00
|
|
|
active: postAccount.value != null ? postAccount.value.id : $i.id,
|
2023-04-08 02:01:42 +02:00
|
|
|
onChoose: (account) => {
|
|
|
|
if (account.id === $i.id) {
|
2023-08-12 02:44:46 +02:00
|
|
|
postAccount.value = null;
|
2023-04-08 02:01:42 +02:00
|
|
|
} else {
|
2023-08-12 02:44:46 +02:00
|
|
|
postAccount.value = account;
|
2023-04-08 02:01:42 +02:00
|
|
|
}
|
|
|
|
},
|
2022-01-21 12:17:31 +01:00
|
|
|
},
|
2023-07-06 03:28:27 +02:00
|
|
|
ev,
|
2023-04-08 02:01:42 +02:00
|
|
|
);
|
2022-01-21 12:17:31 +01:00
|
|
|
}
|
|
|
|
|
2022-01-15 17:46:25 +01:00
|
|
|
onMounted(() => {
|
|
|
|
if (props.autofocus) {
|
|
|
|
focus();
|
2019-05-27 08:38:14 +02:00
|
|
|
|
2022-01-15 17:46:25 +01:00
|
|
|
nextTick(() => {
|
|
|
|
focus();
|
|
|
|
});
|
|
|
|
}
|
2019-05-27 08:38:14 +02:00
|
|
|
|
2022-01-15 17:46:25 +01:00
|
|
|
// TODO: detach when unmount
|
2023-08-12 02:44:46 +02:00
|
|
|
new Autocomplete(textareaEl.value, text);
|
|
|
|
new Autocomplete(cwInputEl.value, cw);
|
|
|
|
new Autocomplete(hashtagsInputEl.value, hashtags);
|
2022-01-15 17:46:25 +01:00
|
|
|
|
2023-08-12 02:44:46 +02:00
|
|
|
autosize(textareaEl.value);
|
2023-07-28 20:41:25 +02:00
|
|
|
|
2022-01-15 17:46:25 +01:00
|
|
|
nextTick(() => {
|
2023-08-12 02:44:46 +02:00
|
|
|
autosize(textareaEl.value);
|
2022-01-15 17:46:25 +01:00
|
|
|
// 書きかけの投稿を復元
|
2022-01-27 09:38:02 +01:00
|
|
|
if (!props.instant && !props.mention && !props.specified) {
|
2023-04-08 02:01:42 +02:00
|
|
|
const draft = JSON.parse(localStorage.getItem("drafts") || "{}")[
|
2023-08-12 02:44:46 +02:00
|
|
|
draftKey.value
|
2023-04-08 02:01:42 +02:00
|
|
|
];
|
2022-01-15 17:46:25 +01:00
|
|
|
if (draft) {
|
2023-08-12 02:44:46 +02:00
|
|
|
text.value = draft.data.text;
|
|
|
|
useCw.value = draft.data.useCw;
|
|
|
|
cw.value = draft.data.cw;
|
|
|
|
visibility.value = draft.data.visibility;
|
|
|
|
localOnly.value = draft.data.localOnly;
|
2023-10-06 05:28:12 +02:00
|
|
|
language.value = draft.data.lang;
|
2023-08-12 02:44:46 +02:00
|
|
|
files.value = (draft.data.files || []).filter(
|
2023-07-06 03:28:27 +02:00
|
|
|
(draftFile) => draftFile,
|
2023-04-08 02:01:42 +02:00
|
|
|
);
|
2022-01-15 17:46:25 +01:00
|
|
|
if (draft.data.poll) {
|
2023-08-12 02:44:46 +02:00
|
|
|
poll.value = draft.data.poll;
|
2019-05-27 08:38:14 +02:00
|
|
|
}
|
2021-08-07 05:47:01 +02:00
|
|
|
}
|
2022-01-15 17:46:25 +01:00
|
|
|
}
|
2021-08-07 05:47:01 +02:00
|
|
|
|
2022-01-15 17:46:25 +01:00
|
|
|
// 削除して編集
|
|
|
|
if (props.initialNote) {
|
|
|
|
const init = props.initialNote;
|
2023-08-12 02:44:46 +02:00
|
|
|
text.value = init.text ? init.text : "";
|
|
|
|
files.value = init.files;
|
|
|
|
cw.value = init.cw;
|
|
|
|
useCw.value = init.cw != null;
|
2022-01-15 17:46:25 +01:00
|
|
|
if (init.poll) {
|
2023-08-12 02:44:46 +02:00
|
|
|
poll.value = {
|
2023-04-08 02:01:42 +02:00
|
|
|
choices: init.poll.choices.map((x) => x.text),
|
2022-01-15 17:46:25 +01:00
|
|
|
multiple: init.poll.multiple,
|
|
|
|
expiresAt: init.poll.expiresAt,
|
|
|
|
expiredAfter: init.poll.expiredAfter,
|
|
|
|
};
|
2020-07-29 16:37:50 +02:00
|
|
|
}
|
2023-08-12 02:44:46 +02:00
|
|
|
visibility.value = init.visibility;
|
|
|
|
localOnly.value = init.localOnly;
|
2023-10-06 05:28:12 +02:00
|
|
|
language.value = init.lang;
|
2023-08-12 02:44:46 +02:00
|
|
|
quoteId.value = init.renote ? init.renote.id : null;
|
2020-07-11 17:38:55 +02:00
|
|
|
}
|
2022-01-15 17:46:25 +01:00
|
|
|
|
|
|
|
nextTick(() => watchForDraft());
|
|
|
|
});
|
2019-05-27 08:38:14 +02:00
|
|
|
});
|
2020-01-29 20:37:25 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2023-01-29 03:56:48 +01:00
|
|
|
.right {
|
2023-04-08 02:01:42 +02:00
|
|
|
float: right;
|
2023-01-29 03:56:48 +01:00
|
|
|
}
|
2020-01-29 20:37:25 +01:00
|
|
|
.gafaadew {
|
2020-10-17 13:12:00 +02:00
|
|
|
position: relative;
|
|
|
|
|
|
|
|
&.modal {
|
|
|
|
width: 100%;
|
|
|
|
max-width: 520px;
|
|
|
|
}
|
2020-01-29 20:37:25 +01:00
|
|
|
|
|
|
|
> header {
|
2023-05-30 00:29:42 +02:00
|
|
|
display: flex;
|
|
|
|
flex-wrap: wrap;
|
2020-01-29 20:37:25 +01:00
|
|
|
z-index: 1000;
|
|
|
|
height: 66px;
|
|
|
|
|
|
|
|
> .cancel {
|
|
|
|
padding: 0;
|
|
|
|
font-size: 20px;
|
|
|
|
width: 64px;
|
|
|
|
line-height: 66px;
|
|
|
|
}
|
|
|
|
|
2022-01-21 12:17:31 +01:00
|
|
|
> .account {
|
|
|
|
height: 100%;
|
|
|
|
aspect-ratio: 1/1;
|
|
|
|
display: inline-flex;
|
|
|
|
vertical-align: bottom;
|
|
|
|
|
|
|
|
> .avatar {
|
|
|
|
width: 28px;
|
|
|
|
height: 28px;
|
|
|
|
margin: auto;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-05 16:01:23 +02:00
|
|
|
> .right {
|
2020-01-29 20:37:25 +01:00
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
|
|
|
right: 0;
|
2023-07-25 00:39:37 +02:00
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
2020-01-29 20:37:25 +01:00
|
|
|
|
|
|
|
> .text-count {
|
2020-02-11 18:55:35 +01:00
|
|
|
opacity: 0.7;
|
2020-01-29 20:37:25 +01:00
|
|
|
line-height: 66px;
|
|
|
|
}
|
|
|
|
|
2020-02-05 13:28:51 +01:00
|
|
|
> .visibility {
|
|
|
|
height: 34px;
|
|
|
|
width: 34px;
|
2021-10-15 18:19:49 +02:00
|
|
|
margin: 0 0 0 8px;
|
2020-05-16 14:50:16 +02:00
|
|
|
|
|
|
|
& + .localOnly {
|
|
|
|
margin-left: 0 !important;
|
|
|
|
}
|
2023-07-25 00:39:37 +02:00
|
|
|
|
|
|
|
> span:only-child > i {
|
|
|
|
display: block;
|
|
|
|
}
|
2020-05-16 14:50:16 +02:00
|
|
|
}
|
2022-11-18 05:32:24 +01:00
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
> .local-only {
|
|
|
|
margin: 0 0 0 12px;
|
|
|
|
opacity: 0.7;
|
2020-02-05 13:28:51 +01:00
|
|
|
}
|
|
|
|
|
2023-10-06 05:28:12 +02:00
|
|
|
> .language {
|
|
|
|
height: 34px;
|
|
|
|
width: 34px;
|
|
|
|
}
|
|
|
|
|
2021-10-15 18:19:49 +02:00
|
|
|
> .preview {
|
|
|
|
display: inline-block;
|
|
|
|
padding: 0;
|
|
|
|
margin: 0 8px 0 0;
|
2023-07-25 00:39:37 +02:00
|
|
|
font-size: inherit !important;
|
2021-10-15 18:19:49 +02:00
|
|
|
width: 34px;
|
|
|
|
height: 34px;
|
|
|
|
border-radius: 6px;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
background: var(--X5);
|
|
|
|
}
|
|
|
|
|
|
|
|
&.active {
|
|
|
|
color: var(--accent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-29 20:37:25 +01:00
|
|
|
> .submit {
|
2023-03-16 02:24:12 +01:00
|
|
|
display: inline-flex;
|
|
|
|
align-items: center;
|
2020-02-05 13:28:51 +01:00
|
|
|
margin: 16px 16px 16px 0;
|
2020-02-08 09:49:54 +01:00
|
|
|
padding: 0 12px;
|
2020-01-29 20:37:25 +01:00
|
|
|
line-height: 34px;
|
2020-02-08 09:49:54 +01:00
|
|
|
font-weight: bold;
|
2020-01-29 20:37:25 +01:00
|
|
|
vertical-align: bottom;
|
|
|
|
border-radius: 4px;
|
2021-10-16 08:00:55 +02:00
|
|
|
font-size: 0.9em;
|
2020-01-29 20:37:25 +01:00
|
|
|
|
|
|
|
&:disabled {
|
|
|
|
opacity: 0.7;
|
|
|
|
}
|
2020-02-08 09:49:54 +01:00
|
|
|
|
2021-04-20 16:22:59 +02:00
|
|
|
> i {
|
2020-02-08 09:49:54 +01:00
|
|
|
margin-left: 6px;
|
|
|
|
}
|
2020-01-29 20:37:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .form {
|
|
|
|
> .preview {
|
|
|
|
padding: 16px;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .with-quote {
|
2023-05-08 23:26:59 +02:00
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
2023-05-10 23:08:51 +02:00
|
|
|
gap: 0.4em;
|
2023-05-08 23:26:59 +02:00
|
|
|
margin-inline: 24px;
|
|
|
|
margin-bottom: 12px;
|
2020-01-29 20:37:25 +01:00
|
|
|
color: var(--accent);
|
|
|
|
|
|
|
|
> button {
|
2023-05-08 23:26:59 +02:00
|
|
|
display: flex;
|
|
|
|
padding: 0;
|
2020-01-29 20:37:25 +01:00
|
|
|
color: var(--accentAlpha04);
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
color: var(--accentAlpha06);
|
|
|
|
}
|
|
|
|
|
|
|
|
&:active {
|
|
|
|
color: var(--accentDarken30);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .to-specified {
|
|
|
|
padding: 6px 24px;
|
|
|
|
margin-bottom: 8px;
|
|
|
|
overflow: auto;
|
2022-11-18 06:01:05 +01:00
|
|
|
line-height: 2rem;
|
2020-01-29 20:37:25 +01:00
|
|
|
|
|
|
|
> .visibleUsers {
|
|
|
|
display: inline;
|
|
|
|
top: -1px;
|
|
|
|
font-size: 14px;
|
|
|
|
|
|
|
|
> button {
|
2022-11-18 05:32:24 +01:00
|
|
|
padding: 2px;
|
2020-01-29 20:37:25 +01:00
|
|
|
border-radius: 8px;
|
2022-11-18 05:32:24 +01:00
|
|
|
|
|
|
|
> i {
|
|
|
|
transform: translateX(2px);
|
|
|
|
}
|
2020-01-29 20:37:25 +01:00
|
|
|
}
|
|
|
|
|
2022-11-18 05:32:24 +01:00
|
|
|
> span {
|
|
|
|
margin: 0.3rem;
|
|
|
|
padding: 4px 0 4px 4px;
|
|
|
|
border-radius: 999px;
|
|
|
|
background: var(--X3);
|
2020-01-29 20:37:25 +01:00
|
|
|
|
|
|
|
> button {
|
|
|
|
padding: 4px 8px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-15 17:13:20 +02:00
|
|
|
> .hasNotSpecifiedMentions {
|
|
|
|
margin: 0 20px 16px 20px;
|
|
|
|
}
|
|
|
|
|
2020-02-05 00:59:24 +01:00
|
|
|
> .cw,
|
2021-08-07 05:47:01 +02:00
|
|
|
> .hashtags,
|
2020-02-05 00:59:24 +01:00
|
|
|
> .text {
|
2020-01-29 20:37:25 +01:00
|
|
|
display: block;
|
|
|
|
box-sizing: border-box;
|
|
|
|
padding: 0 24px;
|
|
|
|
margin: 0;
|
|
|
|
width: 100%;
|
2023-06-13 21:18:43 +02:00
|
|
|
font-size: 1.05em;
|
2020-01-29 20:37:25 +01:00
|
|
|
border: none;
|
|
|
|
border-radius: 0;
|
|
|
|
background: transparent;
|
|
|
|
color: var(--fg);
|
2020-02-09 11:59:28 +01:00
|
|
|
font-family: inherit;
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2021-11-07 19:43:14 +01:00
|
|
|
&:focus {
|
2020-01-29 20:37:25 +01:00
|
|
|
outline: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
&:disabled {
|
|
|
|
opacity: 0.5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-05 00:59:24 +01:00
|
|
|
> .cw {
|
|
|
|
z-index: 1;
|
|
|
|
padding-bottom: 8px;
|
2021-04-10 05:40:50 +02:00
|
|
|
border-bottom: solid 0.5px var(--divider);
|
2020-02-05 00:59:24 +01:00
|
|
|
}
|
|
|
|
|
2021-08-07 05:47:01 +02:00
|
|
|
> .hashtags {
|
|
|
|
z-index: 1;
|
|
|
|
padding-top: 8px;
|
|
|
|
padding-bottom: 8px;
|
|
|
|
border-top: solid 0.5px var(--divider);
|
|
|
|
}
|
|
|
|
|
2020-02-05 00:59:24 +01:00
|
|
|
> .text {
|
2020-01-29 20:37:25 +01:00
|
|
|
max-width: 100%;
|
|
|
|
min-width: 100%;
|
|
|
|
min-height: 90px;
|
|
|
|
|
2020-02-05 00:59:24 +01:00
|
|
|
&.withCw {
|
|
|
|
padding-top: 8px;
|
|
|
|
}
|
2020-01-29 20:37:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
> footer {
|
|
|
|
padding: 0 16px 16px 16px;
|
|
|
|
|
2020-02-05 01:15:28 +01:00
|
|
|
> button {
|
2020-01-29 20:37:25 +01:00
|
|
|
display: inline-block;
|
|
|
|
padding: 0;
|
|
|
|
margin: 0;
|
|
|
|
font-size: 16px;
|
|
|
|
width: 48px;
|
|
|
|
height: 48px;
|
|
|
|
border-radius: 6px;
|
|
|
|
|
|
|
|
&:hover {
|
2020-07-04 20:49:58 +02:00
|
|
|
background: var(--X5);
|
2020-01-29 20:37:25 +01:00
|
|
|
}
|
2020-02-05 01:15:28 +01:00
|
|
|
|
|
|
|
&.active {
|
|
|
|
color: var(--accent);
|
|
|
|
}
|
2020-01-29 20:37:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-10-17 13:12:00 +02:00
|
|
|
|
|
|
|
&.max-width_500px {
|
|
|
|
> header {
|
|
|
|
height: 50px;
|
|
|
|
|
|
|
|
> .cancel {
|
|
|
|
width: 50px;
|
|
|
|
line-height: 50px;
|
|
|
|
}
|
|
|
|
|
2022-07-05 16:01:23 +02:00
|
|
|
> .right {
|
2020-10-17 13:12:00 +02:00
|
|
|
> .text-count {
|
|
|
|
line-height: 50px;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .submit {
|
|
|
|
margin: 8px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .form {
|
|
|
|
> .to-specified {
|
|
|
|
padding: 6px 16px;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .cw,
|
2021-08-07 05:47:01 +02:00
|
|
|
> .hashtags,
|
2020-10-17 13:12:00 +02:00
|
|
|
> .text {
|
|
|
|
padding: 0 16px;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .text {
|
|
|
|
min-height: 80px;
|
|
|
|
}
|
|
|
|
|
|
|
|
> footer {
|
|
|
|
padding: 0 8px 8px 8px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-10-14 11:51:15 +02:00
|
|
|
|
|
|
|
&.max-width_310px {
|
|
|
|
> .form {
|
|
|
|
> footer {
|
|
|
|
> button {
|
|
|
|
font-size: 14px;
|
|
|
|
width: 44px;
|
2023-04-08 02:01:42 +02:00
|
|
|
height: 44px;
|
2021-10-14 11:51:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-01-29 20:37:25 +01:00
|
|
|
}
|
|
|
|
</style>
|