summaryrefslogtreecommitdiff
path: root/packages/client/src/components
diff options
context:
space:
mode:
Diffstat (limited to 'packages/client/src/components')
-rw-r--r--packages/client/src/components/MkNoteSub.vue (renamed from packages/client/src/components/note.sub.vue)75
-rw-r--r--packages/client/src/components/abuse-report-window.vue76
-rw-r--r--packages/client/src/components/abuse-report.vue102
-rw-r--r--packages/client/src/components/analog-clock.vue140
-rw-r--r--packages/client/src/components/autocomplete.vue493
-rw-r--r--packages/client/src/components/avatars.vue32
-rw-r--r--packages/client/src/components/captcha.vue168
-rw-r--r--packages/client/src/components/channel-follow-button.vue76
-rw-r--r--packages/client/src/components/channel-preview.vue41
-rw-r--r--packages/client/src/components/chart.vue8
-rw-r--r--packages/client/src/components/code-core.vue36
-rw-r--r--packages/client/src/components/code.vue30
-rw-r--r--packages/client/src/components/cw-button.vue52
-rw-r--r--packages/client/src/components/date-separated-list.vue53
-rw-r--r--packages/client/src/components/debobigego/base.vue65
-rw-r--r--packages/client/src/components/debobigego/button.vue81
-rw-r--r--packages/client/src/components/debobigego/debobigego.scss52
-rw-r--r--packages/client/src/components/debobigego/group.vue78
-rw-r--r--packages/client/src/components/debobigego/info.vue47
-rw-r--r--packages/client/src/components/debobigego/input.vue292
-rw-r--r--packages/client/src/components/debobigego/key-value-view.vue38
-rw-r--r--packages/client/src/components/debobigego/link.vue103
-rw-r--r--packages/client/src/components/debobigego/object-view.vue102
-rw-r--r--packages/client/src/components/debobigego/pagination.vue42
-rw-r--r--packages/client/src/components/debobigego/radios.vue112
-rw-r--r--packages/client/src/components/debobigego/range.vue122
-rw-r--r--packages/client/src/components/debobigego/select.vue145
-rw-r--r--packages/client/src/components/debobigego/suspense.vue101
-rw-r--r--packages/client/src/components/debobigego/switch.vue132
-rw-r--r--packages/client/src/components/debobigego/textarea.vue161
-rw-r--r--packages/client/src/components/debobigego/tuple.vue36
-rw-r--r--packages/client/src/components/dialog.vue188
-rw-r--r--packages/client/src/components/drive-file-thumbnail.vue95
-rw-r--r--packages/client/src/components/drive-select-dialog.vue71
-rw-r--r--packages/client/src/components/drive-window.vue39
-rw-r--r--packages/client/src/components/drive.file.vue288
-rw-r--r--packages/client/src/components/drive.folder.vue394
-rw-r--r--packages/client/src/components/drive.nav-folder.vue169
-rw-r--r--packages/client/src/components/drive.vue1027
-rw-r--r--packages/client/src/components/emoji-picker-dialog.vue95
-rw-r--r--packages/client/src/components/emoji-picker-window.vue51
-rw-r--r--packages/client/src/components/emoji-picker.section.vue38
-rw-r--r--packages/client/src/components/emoji-picker.vue471
-rw-r--r--packages/client/src/components/featured-photos.vue22
-rw-r--r--packages/client/src/components/file-type-icon.vue27
-rw-r--r--packages/client/src/components/follow-button.vue172
-rw-r--r--packages/client/src/components/forgot-password.vue76
-rw-r--r--packages/client/src/components/form/folder.vue107
-rw-r--r--packages/client/src/components/form/group.vue3
-rw-r--r--packages/client/src/components/form/input.vue4
-rw-r--r--packages/client/src/components/form/pagination.vue44
-rw-r--r--packages/client/src/components/form/radio.vue20
-rw-r--r--packages/client/src/components/form/section.vue14
-rw-r--r--packages/client/src/components/form/select.vue4
-rw-r--r--packages/client/src/components/form/split.vue27
-rw-r--r--packages/client/src/components/form/suspense.vue2
-rw-r--r--packages/client/src/components/form/switch.vue5
-rw-r--r--packages/client/src/components/global/a.vue202
-rw-r--r--packages/client/src/components/global/acct.vue29
-rw-r--r--packages/client/src/components/global/ad.vue6
-rw-r--r--packages/client/src/components/global/avatar.vue94
-rw-r--r--packages/client/src/components/global/error.vue13
-rw-r--r--packages/client/src/components/global/loading.vue30
-rw-r--r--packages/client/src/components/global/misskey-flavored-markdown.vue22
-rw-r--r--packages/client/src/components/global/spacer.vue2
-rw-r--r--packages/client/src/components/global/sticky-container.vue2
-rw-r--r--packages/client/src/components/global/time.vue112
-rw-r--r--packages/client/src/components/global/user-name.vue21
-rw-r--r--packages/client/src/components/google.vue35
-rw-r--r--packages/client/src/components/image-viewer.vue34
-rw-r--r--packages/client/src/components/img-with-blurhash.vue86
-rw-r--r--packages/client/src/components/instance-stats.vue15
-rw-r--r--packages/client/src/components/instance-ticker.vue41
-rw-r--r--packages/client/src/components/key-value.vue27
-rw-r--r--packages/client/src/components/link.vue84
-rw-r--r--packages/client/src/components/media-banner.vue46
-rw-r--r--packages/client/src/components/media-list.vue36
-rw-r--r--packages/client/src/components/media-video.vue28
-rw-r--r--packages/client/src/components/mini-chart.vue4
-rw-r--r--packages/client/src/components/modal-page-window.vue4
-rw-r--r--packages/client/src/components/note-detailed.vue862
-rw-r--r--packages/client/src/components/note-header.vue28
-rw-r--r--packages/client/src/components/note-preview.vue18
-rw-r--r--packages/client/src/components/note-simple.vue34
-rw-r--r--packages/client/src/components/note.vue867
-rw-r--r--packages/client/src/components/notes.vue124
-rw-r--r--packages/client/src/components/notification-toast.vue4
-rw-r--r--packages/client/src/components/notification.vue5
-rw-r--r--packages/client/src/components/notifications.vue191
-rw-r--r--packages/client/src/components/object-view.value.vue108
-rw-r--r--packages/client/src/components/object-view.vue33
-rw-r--r--packages/client/src/components/poll-editor.vue214
-rw-r--r--packages/client/src/components/post-form-attaches.vue9
-rw-r--r--packages/client/src/components/post-form.vue1106
-rw-r--r--packages/client/src/components/reaction-icon.vue28
-rw-r--r--packages/client/src/components/reaction-tooltip.vue35
-rw-r--r--packages/client/src/components/reactions-viewer.details.vue45
-rw-r--r--packages/client/src/components/reactions-viewer.vue34
-rw-r--r--packages/client/src/components/remote-caution.vue20
-rw-r--r--packages/client/src/components/renote.details.vue34
-rw-r--r--packages/client/src/components/ripple.vue2
-rw-r--r--packages/client/src/components/signin-dialog.vue42
-rw-r--r--packages/client/src/components/signup-dialog.vue46
-rw-r--r--packages/client/src/components/sub-note-content.vue38
-rw-r--r--packages/client/src/components/taskmanager.api-window.vue72
-rw-r--r--packages/client/src/components/taskmanager.vue233
-rw-r--r--packages/client/src/components/timeline.vue278
-rw-r--r--packages/client/src/components/toast.vue40
-rw-r--r--packages/client/src/components/ui/button.vue6
-rw-r--r--packages/client/src/components/ui/container.vue2
-rw-r--r--packages/client/src/components/ui/folder.vue2
-rw-r--r--packages/client/src/components/ui/menu.vue2
-rw-r--r--packages/client/src/components/ui/modal.vue2
-rw-r--r--packages/client/src/components/ui/pagination.vue282
-rw-r--r--packages/client/src/components/ui/tooltip.vue2
-rw-r--r--packages/client/src/components/ui/window.vue4
-rw-r--r--packages/client/src/components/url-preview-popup.vue2
-rw-r--r--packages/client/src/components/url-preview.vue158
-rw-r--r--packages/client/src/components/user-info.vue28
-rw-r--r--packages/client/src/components/user-list.vue104
-rw-r--r--packages/client/src/components/user-online-indicator.vue31
-rw-r--r--packages/client/src/components/user-preview.vue2
-rw-r--r--packages/client/src/components/user-select-dialog.vue148
-rw-r--r--packages/client/src/components/visibility-picker.vue81
-rw-r--r--packages/client/src/components/waiting-dialog.vue57
-rw-r--r--packages/client/src/components/widgets.vue79
126 files changed, 4687 insertions, 8372 deletions
diff --git a/packages/client/src/components/note.sub.vue b/packages/client/src/components/MkNoteSub.vue
index de4218e535..30c27e6235 100644
--- a/packages/client/src/components/note.sub.vue
+++ b/packages/client/src/components/MkNoteSub.vue
@@ -10,13 +10,13 @@
<XCwButton v-model="showContent" :note="note"/>
</p>
<div v-show="note.cw == null || showContent" class="content">
- <XSubNote-content class="text" :note="note"/>
+ <MkNoteSubNoteContent class="text" :note="note"/>
</div>
</div>
</div>
</div>
<template v-if="depth < 5">
- <XSub v-for="reply in replies" :key="reply.id" :note="reply" class="reply" :detail="true" :depth="depth + 1"/>
+ <MkNoteSub v-for="reply in replies" :key="reply.id" :note="reply" class="reply" :detail="true" :depth="depth + 1"/>
</template>
<div v-else class="more">
<MkA class="text _link" :to="notePage(note)">{{ $ts.continueThread }} <i class="fas fa-angle-double-right"></i></MkA>
@@ -24,63 +24,36 @@
</div>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
+<script lang="ts" setup>
+import { } from 'vue';
+import * as misskey from 'misskey-js';
import { notePage } from '@/filters/note';
import XNoteHeader from './note-header.vue';
-import XSubNoteContent from './sub-note-content.vue';
+import MkNoteSubNoteContent from './sub-note-content.vue';
import XCwButton from './cw-button.vue';
import * as os from '@/os';
-export default defineComponent({
- name: 'XSub',
+const props = withDefaults(defineProps<{
+ note: misskey.entities.Note;
+ detail?: boolean;
- components: {
- XNoteHeader,
- XSubNoteContent,
- XCwButton,
- },
-
- props: {
- note: {
- type: Object,
- required: true
- },
- detail: {
- type: Boolean,
- required: false,
- default: false
- },
- // how many notes are in between this one and the note being viewed in detail
- depth: {
- type: Number,
- required: false,
- default: 1
- },
- },
-
- data() {
- return {
- showContent: false,
- replies: [],
- };
- },
+ // how many notes are in between this one and the note being viewed in detail
+ depth?: number;
+}>(), {
+ depth: 1,
+});
- created() {
- if (this.detail) {
- os.api('notes/children', {
- noteId: this.note.id,
- limit: 5
- }).then(replies => {
- this.replies = replies;
- });
- }
- },
+let showContent = $ref(false);
+let replies: misskey.entities.Note[] = $ref([]);
- methods: {
- notePage,
- }
-});
+if (props.detail) {
+ os.api('notes/children', {
+ noteId: props.note.id,
+ limit: 5
+ }).then(res => {
+ replies = res;
+ });
+}
</script>
<style lang="scss" scoped>
diff --git a/packages/client/src/components/abuse-report-window.vue b/packages/client/src/components/abuse-report-window.vue
index 6b07639f6d..cd04f62bca 100644
--- a/packages/client/src/components/abuse-report-window.vue
+++ b/packages/client/src/components/abuse-report-window.vue
@@ -1,8 +1,8 @@
<template>
-<XWindow ref="window" :initial-width="400" :initial-height="500" :can-resize="true" @closed="$emit('closed')">
+<XWindow ref="window" :initial-width="400" :initial-height="500" :can-resize="true" @closed="emit('closed')">
<template #header>
<i class="fas fa-exclamation-circle" style="margin-right: 0.5em;"></i>
- <I18n :src="$ts.reportAbuseOf" tag="span">
+ <I18n :src="i18n.locale.reportAbuseOf" tag="span">
<template #name>
<b><MkAcct :user="user"/></b>
</template>
@@ -11,65 +11,51 @@
<div class="dpvffvvy _monolithic_">
<div class="_section">
<MkTextarea v-model="comment">
- <template #label>{{ $ts.details }}</template>
- <template #caption>{{ $ts.fillAbuseReportDescription }}</template>
+ <template #label>{{ i18n.locale.details }}</template>
+ <template #caption>{{ i18n.locale.fillAbuseReportDescription }}</template>
</MkTextarea>
</div>
<div class="_section">
- <MkButton primary full :disabled="comment.length === 0" @click="send">{{ $ts.send }}</MkButton>
+ <MkButton primary full :disabled="comment.length === 0" @click="send">{{ i18n.locale.send }}</MkButton>
</div>
</div>
</XWindow>
</template>
-<script lang="ts">
-import { defineComponent, markRaw } from 'vue';
+<script setup lang="ts">
+import { ref } from 'vue';
+import * as Misskey from 'misskey-js';
import XWindow from '@/components/ui/window.vue';
import MkTextarea from '@/components/form/textarea.vue';
import MkButton from '@/components/ui/button.vue';
import * as os from '@/os';
+import { i18n } from '@/i18n';
-export default defineComponent({
- components: {
- XWindow,
- MkTextarea,
- MkButton,
- },
+const props = defineProps<{
+ user: Misskey.entities.User;
+ initialComment?: string;
+}>();
- props: {
- user: {
- type: Object,
- required: true,
- },
- initialComment: {
- type: String,
- required: false,
- },
- },
+const emit = defineEmits<{
+ (e: 'closed'): void;
+}>();
- emits: ['closed'],
+const window = ref<InstanceType<typeof XWindow>>();
+const comment = ref(props.initialComment || '');
- data() {
- return {
- comment: this.initialComment || '',
- };
- },
-
- methods: {
- send() {
- os.apiWithDialog('users/report-abuse', {
- userId: this.user.id,
- comment: this.comment,
- }, undefined, res => {
- os.alert({
- type: 'success',
- text: this.$ts.abuseReported
- });
- this.$refs.window.close();
- });
- }
- },
-});
+function send() {
+ os.apiWithDialog('users/report-abuse', {
+ userId: props.user.id,
+ comment: comment.value,
+ }, undefined).then(res => {
+ os.alert({
+ type: 'success',
+ text: i18n.locale.abuseReported
+ });
+ window.value?.close();
+ emit('closed');
+ });
+}
</script>
<style lang="scss" scoped>
diff --git a/packages/client/src/components/abuse-report.vue b/packages/client/src/components/abuse-report.vue
new file mode 100644
index 0000000000..b67cef209b
--- /dev/null
+++ b/packages/client/src/components/abuse-report.vue
@@ -0,0 +1,102 @@
+<template>
+<div class="bcekxzvu _card _gap">
+ <div class="_content target">
+ <MkAvatar class="avatar" :user="report.targetUser" :show-indicator="true"/>
+ <MkA class="info" :to="userPage(report.targetUser)" v-user-preview="report.targetUserId">
+ <MkUserName class="name" :user="report.targetUser"/>
+ <MkAcct class="acct" :user="report.targetUser" style="display: block;"/>
+ </MkA>
+ </div>
+ <div class="_content">
+ <div>
+ <Mfm :text="report.comment"/>
+ </div>
+ <hr/>
+ <div>{{ $ts.reporter }}: <MkAcct :user="report.reporter"/></div>
+ <div v-if="report.assignee">
+ {{ $ts.moderator }}:
+ <MkAcct :user="report.assignee"/>
+ </div>
+ <div><MkTime :time="report.createdAt"/></div>
+ </div>
+ <div class="_footer">
+ <MkSwitch v-model="forward" :disabled="report.targetUser.host == null || report.resolved">
+ {{ $ts.forwardReport }}
+ <template #caption>{{ $ts.forwardReportIsAnonymous }}</template>
+ </MkSwitch>
+ <MkButton v-if="!report.resolved" primary @click="resolve">{{ $ts.abuseMarkAsResolved }}</MkButton>
+ </div>
+</div>
+</template>
+
+<script lang="ts">
+import { defineComponent } from 'vue';
+
+import MkButton from '@/components/ui/button.vue';
+import MkSwitch from '@/components/form/switch.vue';
+import { acct, userPage } from '@/filters/user';
+import * as os from '@/os';
+
+export default defineComponent({
+ components: {
+ MkButton,
+ MkSwitch,
+ },
+
+ emits: ['resolved'],
+
+ props: {
+ report: {
+ type: Object,
+ required: true,
+ }
+ }
+
+ data() {
+ return {
+ forward: this.report.forwarded,
+ };
+ }
+
+ methods: {
+ acct,
+ userPage,
+
+ resolve() {
+ os.apiWithDialog('admin/resolve-abuse-user-report', {
+ forward: this.forward,
+ reportId: this.report.id,
+ }).then(() => {
+ this.$emit('resolved', this.report.id);
+ });
+ }
+ }
+});
+</script>
+
+<style lang="scss" scoped>
+.bcekxzvu {
+ > .target {
+ display: flex;
+ width: 100%;
+ box-sizing: border-box;
+ text-align: left;
+ align-items: center;
+
+ > .avatar {
+ width: 42px;
+ height: 42px;
+ }
+
+ > .info {
+ margin-left: 0.3em;
+ padding: 0 8px;
+ flex: 1;
+
+ > .name {
+ font-weight: bold;
+ }
+ }
+ }
+}
+</style>
diff --git a/packages/client/src/components/analog-clock.vue b/packages/client/src/components/analog-clock.vue
index 450488b198..59b8e97304 100644
--- a/packages/client/src/components/analog-clock.vue
+++ b/packages/client/src/components/analog-clock.vue
@@ -40,106 +40,64 @@
</svg>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
+<script lang="ts" setup>
+import { ref, computed, onMounted, onBeforeUnmount } from 'vue';
import * as tinycolor from 'tinycolor2';
-export default defineComponent({
- props: {
- thickness: {
- type: Number,
- default: 0.1
- }
- },
-
- data() {
- return {
- now: new Date(),
- enabled: true,
-
- graduationsPadding: 0.5,
- handsPadding: 1,
- handsTailLength: 0.7,
- hHandLengthRatio: 0.75,
- mHandLengthRatio: 1,
- sHandLengthRatio: 1,
-
- computedStyle: getComputedStyle(document.documentElement)
- };
- },
-
- computed: {
- dark(): boolean {
- return tinycolor(this.computedStyle.getPropertyValue('--bg')).isDark();
- },
-
- majorGraduationColor(): string {
- return this.dark ? 'rgba(255, 255, 255, 0.3)' : 'rgba(0, 0, 0, 0.3)';
- },
- minorGraduationColor(): string {
- return this.dark ? 'rgba(255, 255, 255, 0.2)' : 'rgba(0, 0, 0, 0.2)';
- },
+withDefaults(defineProps<{
+ thickness: number;
+}>(), {
+ thickness: 0.1,
+});
- sHandColor(): string {
- return this.dark ? 'rgba(255, 255, 255, 0.5)' : 'rgba(0, 0, 0, 0.3)';
- },
- mHandColor(): string {
- return tinycolor(this.computedStyle.getPropertyValue('--fg')).toHexString();
- },
- hHandColor(): string {
- return tinycolor(this.computedStyle.getPropertyValue('--accent')).toHexString();
- },
+const now = ref(new Date());
+const enabled = ref(true);
+const graduationsPadding = ref(0.5);
+const handsPadding = ref(1);
+const handsTailLength = ref(0.7);
+const hHandLengthRatio = ref(0.75);
+const mHandLengthRatio = ref(1);
+const sHandLengthRatio = ref(1);
+const computedStyle = getComputedStyle(document.documentElement);
- s(): number {
- return this.now.getSeconds();
- },
- m(): number {
- return this.now.getMinutes();
- },
- h(): number {
- return this.now.getHours();
- },
+const dark = computed(() => tinycolor(computedStyle.getPropertyValue('--bg')).isDark());
+const majorGraduationColor = computed(() => dark.value ? 'rgba(255, 255, 255, 0.3)' : 'rgba(0, 0, 0, 0.3)');
+const minorGraduationColor = computed(() => dark.value ? 'rgba(255, 255, 255, 0.2)' : 'rgba(0, 0, 0, 0.2)');
+const sHandColor = computed(() => dark.value ? 'rgba(255, 255, 255, 0.5)' : 'rgba(0, 0, 0, 0.3)');
+const mHandColor = computed(() => tinycolor(computedStyle.getPropertyValue('--fg')).toHexString());
+const hHandColor = computed(() => tinycolor(computedStyle.getPropertyValue('--accent')).toHexString());
+const s = computed(() => now.value.getSeconds());
+const m = computed(() => now.value.getMinutes());
+const h = computed(() => now.value.getHours());
+const hAngle = computed(() => Math.PI * (h.value % 12 + (m.value + s.value / 60) / 60) / 6);
+const mAngle = computed(() => Math.PI * (m.value + s.value / 60) / 30);
+const sAngle = computed(() => Math.PI * s.value / 30);
+const graduations = computed(() => {
+ const angles: number[] = [];
+ for (let i = 0; i < 60; i++) {
+ const angle = Math.PI * i / 30;
+ angles.push(angle);
+ }
- hAngle(): number {
- return Math.PI * (this.h % 12 + (this.m + this.s / 60) / 60) / 6;
- },
- mAngle(): number {
- return Math.PI * (this.m + this.s / 60) / 30;
- },
- sAngle(): number {
- return Math.PI * this.s / 30;
- },
+ return angles;
+});
- graduations(): any {
- const angles = [];
- for (let i = 0; i < 60; i++) {
- const angle = Math.PI * i / 30;
- angles.push(angle);
- }
+function tick() {
+ now.value = new Date();
+}
- return angles;
+onMounted(() => {
+ const update = () => {
+ if (enabled.value) {
+ tick();
+ window.setTimeout(update, 1000);
}
- },
-
- mounted() {
- const update = () => {
- if (this.enabled) {
- this.tick();
- setTimeout(update, 1000);
- }
- };
- update();
- },
-
- beforeUnmount() {
- this.enabled = false;
- },
+ };
+ update();
+});
- methods: {
- tick() {
- this.now = new Date();
- }
- }
+onBeforeUnmount(() => {
+ enabled.value = false;
});
</script>
diff --git a/packages/client/src/components/autocomplete.vue b/packages/client/src/components/autocomplete.vue
index 30be2ac741..7ba83b7cb1 100644
--- a/packages/client/src/components/autocomplete.vue
+++ b/packages/client/src/components/autocomplete.vue
@@ -1,5 +1,5 @@
<template>
-<div class="swhvrteh _popup _shadow" :style="{ zIndex }" @contextmenu.prevent="() => {}">
+<div ref="rootEl" class="swhvrteh _popup _shadow" :style="{ zIndex }" @contextmenu.prevent="() => {}">
<ol v-if="type === 'user'" ref="suggests" class="users">
<li v-for="user in users" tabindex="-1" class="user" @click="complete(type, user)" @keydown="onKeydown">
<img class="avatar" :src="user.avatarUrl"/>
@@ -8,7 +8,7 @@
</span>
<span class="username">@{{ acct(user) }}</span>
</li>
- <li tabindex="-1" class="choose" @click="chooseUser()" @keydown="onKeydown">{{ $ts.selectUser }}</li>
+ <li tabindex="-1" class="choose" @click="chooseUser()" @keydown="onKeydown">{{ i18n.locale.selectUser }}</li>
</ol>
<ol v-else-if="hashtags.length > 0" ref="suggests" class="hashtags">
<li v-for="hashtag in hashtags" tabindex="-1" @click="complete(type, hashtag)" @keydown="onKeydown">
@@ -17,8 +17,8 @@
</ol>
<ol v-else-if="emojis.length > 0" ref="suggests" class="emojis">
<li v-for="emoji in emojis" tabindex="-1" @click="complete(type, emoji.emoji)" @keydown="onKeydown">
- <span v-if="emoji.isCustomEmoji" class="emoji"><img :src="$store.state.disableShowingAnimatedImages ? getStaticImageUrl(emoji.url) : emoji.url" :alt="emoji.emoji"/></span>
- <span v-else-if="!$store.state.useOsNativeEmojis" class="emoji"><img :src="emoji.url" :alt="emoji.emoji"/></span>
+ <span v-if="emoji.isCustomEmoji" class="emoji"><img :src="defaultStore.state.disableShowingAnimatedImages ? getStaticImageUrl(emoji.url) : emoji.url" :alt="emoji.emoji"/></span>
+ <span v-else-if="!defaultStore.state.useOsNativeEmojis" class="emoji"><img :src="emoji.url" :alt="emoji.emoji"/></span>
<span v-else class="emoji">{{ emoji.emoji }}</span>
<span class="name" v-html="emoji.name.replace(q, `<b>${q}</b>`)"></span>
<span v-if="emoji.aliasOf" class="alias">({{ emoji.aliasOf }})</span>
@@ -33,15 +33,17 @@
</template>
<script lang="ts">
-import { defineComponent, markRaw } from 'vue';
-import { emojilist } from '@/scripts/emojilist';
+import { markRaw, ref, onUpdated, onMounted, onBeforeUnmount, nextTick, watch } from 'vue';
import contains from '@/scripts/contains';
-import { twemojiSvgBase } from '@/scripts/twemoji-base';
import { getStaticImageUrl } from '@/scripts/get-static-image-url';
import { acct } from '@/filters/user';
import * as os from '@/os';
-import { instance } from '@/instance';
import { MFM_TAGS } from '@/scripts/mfm-tags';
+import { defaultStore } from '@/store';
+import { emojilist } from '@/scripts/emojilist';
+import { instance } from '@/instance';
+import { twemojiSvgBase } from '@/scripts/twemoji-base';
+import { i18n } from '@/i18n';
type EmojiDef = {
emoji: string;
@@ -54,16 +56,14 @@ type EmojiDef = {
const lib = emojilist.filter(x => x.category !== 'flags');
const char2file = (char: string) => {
- let codes = Array.from(char).map(x => x.codePointAt(0).toString(16));
+ let codes = Array.from(char).map(x => x.codePointAt(0)?.toString(16));
if (!codes.includes('200d')) codes = codes.filter(x => x != 'fe0f');
- codes = codes.filter(x => x && x.length);
- return codes.join('-');
+ return codes.filter(x => x && x.length).join('-');
};
const emjdb: EmojiDef[] = lib.map(x => ({
emoji: x.char,
name: x.name,
- aliasOf: null,
url: `${twemojiSvgBase}/${char2file(x.char)}.svg`
}));
@@ -112,291 +112,270 @@ emojiDefinitions.sort((a, b) => a.name.length - b.name.length);
const emojiDb = markRaw(emojiDefinitions.concat(emjdb));
//#endregion
-export default defineComponent({
- props: {
- type: {
- type: String,
- required: true,
- },
+export default {
+ emojiDb,
+ emojiDefinitions,
+ emojilist,
+ customEmojis,
+};
+</script>
- q: {
- type: String,
- required: false,
- },
+<script lang="ts" setup>
+const props = defineProps<{
+ type: string;
+ q: string | null;
+ textarea: HTMLTextAreaElement;
+ close: () => void;
+ x: number;
+ y: number;
+}>();
- textarea: {
- type: HTMLTextAreaElement,
- required: true,
- },
+const emit = defineEmits<{
+ (e: 'done', v: { type: string; value: any }): void;
+ (e: 'closed'): void;
+}>();
- close: {
- type: Function,
- required: true,
- },
+const suggests = ref<Element>();
+const rootEl = ref<HTMLDivElement>();
- x: {
- type: Number,
- required: true,
- },
+const fetching = ref(true);
+const users = ref<any[]>([]);
+const hashtags = ref<any[]>([]);
+const emojis = ref<(EmojiDef)[]>([]);
+const items = ref<Element[] | HTMLCollection>([]);
+const mfmTags = ref<string[]>([]);
+const select = ref(-1);
+const zIndex = os.claimZIndex('high');
- y: {
- type: Number,
- required: true,
- },
- },
+function complete(type: string, value: any) {
+ emit('done', { type, value });
+ emit('closed');
+ if (type === 'emoji') {
+ let recents = defaultStore.state.recentlyUsedEmojis;
+ recents = recents.filter((e: any) => e !== value);
+ recents.unshift(value);
+ defaultStore.set('recentlyUsedEmojis', recents.splice(0, 32));
+ }
+}
- emits: ['done', 'closed'],
+function setPosition() {
+ if (!rootEl.value) return;
+ if (props.x + rootEl.value.offsetWidth > window.innerWidth) {
+ rootEl.value.style.left = (window.innerWidth - rootEl.value.offsetWidth) + 'px';
+ } else {
+ rootEl.value.style.left = `${props.x}px`;
+ }
+ if (props.y + rootEl.value.offsetHeight > window.innerHeight) {
+ rootEl.value.style.top = (props.y - rootEl.value.offsetHeight) + 'px';
+ rootEl.value.style.marginTop = '0';
+ } else {
+ rootEl.value.style.top = props.y + 'px';
+ rootEl.value.style.marginTop = 'calc(1em + 8px)';
+ }
+}
- data() {
- return {
- getStaticImageUrl,
- fetching: true,
- users: [],
- hashtags: [],
- emojis: [],
- items: [],
- mfmTags: [],
- select: -1,
- zIndex: os.claimZIndex('high'),
+function exec() {
+ select.value = -1;
+ if (suggests.value) {
+ for (const el of Array.from(items.value)) {
+ el.removeAttribute('data-selected');
}
- },
-
- updated() {
- this.setPosition();
- this.items = (this.$refs.suggests as Element | undefined)?.children || [];
- },
-
- mounted() {
- this.setPosition();
-
- this.textarea.addEventListener('keydown', this.onKeydown);
-
- for (const el of Array.from(document.querySelectorAll('body *'))) {
- el.addEventListener('mousedown', this.onMousedown);
+ }
+ if (props.type === 'user') {
+ if (!props.q) {
+ users.value = [];
+ fetching.value = false;
+ return;
}
- this.$nextTick(() => {
- this.exec();
+ const cacheKey = `autocomplete:user:${props.q}`;
+ const cache = sessionStorage.getItem(cacheKey);
- this.$watch('q', () => {
- this.$nextTick(() => {
- this.exec();
- });
+ if (cache) {
+ const users = JSON.parse(cache);
+ users.value = users;
+ fetching.value = false;
+ } else {
+ os.api('users/search-by-username-and-host', {
+ username: props.q,
+ limit: 10,
+ detail: false
+ }).then(searchedUsers => {
+ users.value = searchedUsers as any[];
+ fetching.value = false;
+ // キャッシュ
+ sessionStorage.setItem(cacheKey, JSON.stringify(searchedUsers));
});
- });
- },
-
- beforeUnmount() {
- this.textarea.removeEventListener('keydown', this.onKeydown);
-
- for (const el of Array.from(document.querySelectorAll('body *'))) {
- el.removeEventListener('mousedown', this.onMousedown);
}
- },
-
- methods: {
- complete(type, value) {
- this.$emit('done', { type, value });
- this.$emit('closed');
-
- if (type === 'emoji') {
- let recents = this.$store.state.recentlyUsedEmojis;
- recents = recents.filter((e: any) => e !== value);
- recents.unshift(value);
- this.$store.set('recentlyUsedEmojis', recents.splice(0, 32));
- }
- },
-
- setPosition() {
- if (this.x + this.$el.offsetWidth > window.innerWidth) {
- this.$el.style.left = (window.innerWidth - this.$el.offsetWidth) + 'px';
+ } else if (props.type === 'hashtag') {
+ if (!props.q || props.q == '') {
+ hashtags.value = JSON.parse(localStorage.getItem('hashtags') || '[]');
+ fetching.value = false;
+ } else {
+ const cacheKey = `autocomplete:hashtag:${props.q}`;
+ const cache = sessionStorage.getItem(cacheKey);
+ if (cache) {
+ const hashtags = JSON.parse(cache);
+ hashtags.value = hashtags;
+ fetching.value = false;
} else {
- this.$el.style.left = this.x + 'px';
+ os.api('hashtags/search', {
+ query: props.q,
+ limit: 30
+ }).then(searchedHashtags => {
+ hashtags.value = searchedHashtags as any[];
+ fetching.value = false;
+ // キャッシュ
+ sessionStorage.setItem(cacheKey, JSON.stringify(searchedHashtags));
+ });
}
+ }
+ } else if (props.type === 'emoji') {
+ if (!props.q || props.q == '') {
+ // 最近使った絵文字をサジェスト
+ emojis.value = defaultStore.state.recentlyUsedEmojis.map(emoji => emojiDb.find(e => e.emoji == emoji)).filter(x => x) as EmojiDef[];
+ return;
+ }
- if (this.y + this.$el.offsetHeight > window.innerHeight) {
- this.$el.style.top = (this.y - this.$el.offsetHeight) + 'px';
- this.$el.style.marginTop = '0';
- } else {
- this.$el.style.top = this.y + 'px';
- this.$el.style.marginTop = 'calc(1em + 8px)';
- }
- },
+ const matched: EmojiDef[] = [];
+ const max = 30;
- exec() {
- this.select = -1;
- if (this.$refs.suggests) {
- for (const el of Array.from(this.items)) {
- el.removeAttribute('data-selected');
- }
- }
+ emojiDb.some(x => {
+ if (x.name.startsWith(props.q || '') && !x.aliasOf && !matched.some(y => y.emoji == x.emoji)) matched.push(x);
+ return matched.length == max;
+ });
- if (this.type === 'user') {
- if (this.q == null) {
- this.users = [];
- this.fetching = false;
- return;
- }
+ if (matched.length < max) {
+ emojiDb.some(x => {
+ if (x.name.startsWith(props.q || '') && !matched.some(y => y.emoji == x.emoji)) matched.push(x);
+ return matched.length == max;
+ });
+ }
- const cacheKey = `autocomplete:user:${this.q}`;
- const cache = sessionStorage.getItem(cacheKey);
- if (cache) {
- const users = JSON.parse(cache);
- this.users = users;
- this.fetching = false;
- } else {
- os.api('users/search-by-username-and-host', {
- username: this.q,
- limit: 10,
- detail: false
- }).then(users => {
- this.users = users;
- this.fetching = false;
+ if (matched.length < max) {
+ emojiDb.some(x => {
+ if (x.name.includes(props.q || '') && !matched.some(y => y.emoji == x.emoji)) matched.push(x);
+ return matched.length == max;
+ });
+ }
- // キャッシュ
- sessionStorage.setItem(cacheKey, JSON.stringify(users));
- });
- }
- } else if (this.type === 'hashtag') {
- if (this.q == null || this.q == '') {
- this.hashtags = JSON.parse(localStorage.getItem('hashtags') || '[]');
- this.fetching = false;
- } else {
- const cacheKey = `autocomplete:hashtag:${this.q}`;
- const cache = sessionStorage.getItem(cacheKey);
- if (cache) {
- const hashtags = JSON.parse(cache);
- this.hashtags = hashtags;
- this.fetching = false;
- } else {
- os.api('hashtags/search', {
- query: this.q,
- limit: 30
- }).then(hashtags => {
- this.hashtags = hashtags;
- this.fetching = false;
+ emojis.value = matched;
+ } else if (props.type === 'mfmTag') {
+ if (!props.q || props.q == '') {
+ mfmTags.value = MFM_TAGS;
+ return;
+ }
- // キャッシュ
- sessionStorage.setItem(cacheKey, JSON.stringify(hashtags));
- });
- }
- }
- } else if (this.type === 'emoji') {
- if (this.q == null || this.q == '') {
- // 最近使った絵文字をサジェスト
- this.emojis = this.$store.state.recentlyUsedEmojis.map(emoji => emojiDb.find(e => e.emoji == emoji)).filter(x => x != null);
- return;
- }
+ mfmTags.value = MFM_TAGS.filter(tag => tag.startsWith(props.q || ''));
+ }
+}
+
+function onMousedown(e: Event) {
+ if (!contains(rootEl.value, e.target) && (rootEl.value != e.target)) props.close();
+}
- const matched = [];
- const max = 30;
+function onKeydown(e: KeyboardEvent) {
+ const cancel = () => {
+ e.preventDefault();
+ e.stopPropagation();
+ };
- emojiDb.some(x => {
- if (x.name.startsWith(this.q) && !x.aliasOf && !matched.some(y => y.emoji == x.emoji)) matched.push(x);
- return matched.length == max;
- });
- if (matched.length < max) {
- emojiDb.some(x => {
- if (x.name.startsWith(this.q) && !matched.some(y => y.emoji == x.emoji)) matched.push(x);
- return matched.length == max;
- });
- }
- if (matched.length < max) {
- emojiDb.some(x => {
- if (x.name.includes(this.q) && !matched.some(y => y.emoji == x.emoji)) matched.push(x);
- return matched.length == max;
- });
- }
+ switch (e.key) {
+ case 'Enter':
+ if (select.value !== -1) {
+ cancel();
+ (items.value[select.value] as any).click();
+ } else {
+ props.close();
+ }
+ break;
- this.emojis = matched;
- } else if (this.type === 'mfmTag') {
- if (this.q == null || this.q == '') {
- this.mfmTags = MFM_TAGS;
- return;
- }
+ case 'Escape':
+ cancel();
+ props.close();
+ break;
- this.mfmTags = MFM_TAGS.filter(tag => tag.startsWith(this.q));
+ case 'ArrowUp':
+ if (select.value !== -1) {
+ cancel();
+ selectPrev();
+ } else {
+ props.close();
}
- },
+ break;
+
+ case 'Tab':
+ case 'ArrowDown':
+ cancel();
+ selectNext();
+ break;
- onMousedown(e) {
- if (!contains(this.$el, e.target) && (this.$el != e.target)) this.close();
- },
+ default:
+ e.stopPropagation();
+ props.textarea.focus();
+ }
+}
- onKeydown(e) {
- const cancel = () => {
- e.preventDefault();
- e.stopPropagation();
- };
+function selectNext() {
+ if (++select.value >= items.value.length) select.value = 0;
+ if (items.value.length === 0) select.value = -1;
+ applySelect();
+}
- switch (e.which) {
- case 10: // [ENTER]
- case 13: // [ENTER]
- if (this.select !== -1) {
- cancel();
- (this.items[this.select] as any).click();
- } else {
- this.close();
- }
- break;
+function selectPrev() {
+ if (--select.value < 0) select.value = items.value.length - 1;
+ applySelect();
+}
- case 27: // [ESC]
- cancel();
- this.close();
- break;
+function applySelect() {
+ for (const el of Array.from(items.value)) {
+ el.removeAttribute('data-selected');
+ }
- case 38: // [↑]
- if (this.select !== -1) {
- cancel();
- this.selectPrev();
- } else {
- this.close();
- }
- break;
+ if (select.value !== -1) {
+ items.value[select.value].setAttribute('data-selected', 'true');
+ (items.value[select.value] as any).focus();
+ }
+}
- case 9: // [TAB]
- case 40: // [↓]
- cancel();
- this.selectNext();
- break;
+function chooseUser() {
+ props.close();
+ os.selectUser().then(user => {
+ complete('user', user);
+ props.textarea.focus();
+ });
+}
- default:
- e.stopPropagation();
- this.textarea.focus();
- }
- },
+onUpdated(() => {
+ setPosition();
+ items.value = suggests.value?.children || [];
+});
- selectNext() {
- if (++this.select >= this.items.length) this.select = 0;
- if (this.items.length === 0) this.select = -1;
- this.applySelect();
- },
+onMounted(() => {
+ setPosition();
- selectPrev() {
- if (--this.select < 0) this.select = this.items.length - 1;
- this.applySelect();
- },
+ props.textarea.addEventListener('keydown', onKeydown);
- applySelect() {
- for (const el of Array.from(this.items)) {
- el.removeAttribute('data-selected');
- }
+ for (const el of Array.from(document.querySelectorAll('body *'))) {
+ el.addEventListener('mousedown', onMousedown);
+ }
- if (this.select !== -1) {
- this.items[this.select].setAttribute('data-selected', 'true');
- (this.items[this.select] as any).focus();
- }
- },
+ nextTick(() => {
+ exec();
- chooseUser() {
- this.close();
- os.selectUser().then(user => {
- this.complete('user', user);
- this.textarea.focus();
+ watch(() => props.q, () => {
+ nextTick(() => {
+ exec();
});
- },
+ });
+ });
+});
+
+onBeforeUnmount(() => {
+ props.textarea.removeEventListener('keydown', onKeydown);
- acct
+ for (const el of Array.from(document.querySelectorAll('body *'))) {
+ el.removeEventListener('mousedown', onMousedown);
}
});
</script>
diff --git a/packages/client/src/components/avatars.vue b/packages/client/src/components/avatars.vue
index e843d26daa..958e5db0a1 100644
--- a/packages/client/src/components/avatars.vue
+++ b/packages/client/src/components/avatars.vue
@@ -1,30 +1,24 @@
<template>
<div>
- <div v-for="user in us" :key="user.id" style="display:inline-block;width:32px;height:32px;margin-right:8px;">
+ <div v-for="user in users" :key="user.id" style="display:inline-block;width:32px;height:32px;margin-right:8px;">
<MkAvatar :user="user" style="width:32px;height:32px;" :show-indicator="true"/>
</div>
</div>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
+<script lang="ts" setup>
+import { onMounted, ref } from 'vue';
import * as os from '@/os';
-export default defineComponent({
- props: {
- userIds: {
- required: true
- },
- },
- data() {
- return {
- us: []
- };
- },
- async created() {
- this.us = await os.api('users/show', {
- userIds: this.userIds
- });
- }
+const props = defineProps<{
+ userIds: string[];
+}>();
+
+const users = ref([]);
+
+onMounted(async () => {
+ users.value = await os.api('users/show', {
+ userIds: props.userIds
+ });
});
</script>
diff --git a/packages/client/src/components/captcha.vue b/packages/client/src/components/captcha.vue
index baa922506e..307fc312bc 100644
--- a/packages/client/src/components/captcha.vue
+++ b/packages/client/src/components/captcha.vue
@@ -1,12 +1,14 @@
<template>
<div>
- <span v-if="!available">{{ $ts.waiting }}<MkEllipsis/></span>
- <div ref="captcha"></div>
+ <span v-if="!available">{{ i18n.locale.waiting }}<MkEllipsis/></span>
+ <div ref="captchaEl"></div>
</div>
</template>
-<script lang="ts">
-import { defineComponent, PropType } from 'vue';
+<script lang="ts" setup>
+import { ref, computed, onMounted, onBeforeUnmount, watch } from 'vue';
+import { defaultStore } from '@/store';
+import { i18n } from '@/i18n';
type Captcha = {
render(container: string | Node, options: {
@@ -14,7 +16,7 @@ type Captcha = {
}): string;
remove(id: string): void;
execute(id: string): void;
- reset(id: string): void;
+ reset(id?: string): void;
getResponse(id: string): string;
};
@@ -29,95 +31,85 @@ declare global {
}
}
-export default defineComponent({
- props: {
- provider: {
- type: String as PropType<CaptchaProvider>,
- required: true,
- },
- sitekey: {
- type: String,
- required: true,
- },
- modelValue: {
- type: String,
- },
- },
+const props = defineProps<{
+ provider: CaptchaProvider;
+ sitekey: string;
+ modelValue?: string | null;
+}>();
- data() {
- return {
- available: false,
- };
- },
+const emit = defineEmits<{
+ (ev: 'update:modelValue', v: string | null): void;
+}>();
- computed: {
- variable(): string {
- switch (this.provider) {
- case 'hcaptcha': return 'hcaptcha';
- case 'recaptcha': return 'grecaptcha';
- }
- },
- loaded(): boolean {
- return !!window[this.variable];
- },
- src(): string {
- const endpoint = ({
- hcaptcha: 'https://hcaptcha.com/1',
- recaptcha: 'https://www.recaptcha.net/recaptcha',
- } as Record<CaptchaProvider, string>)[this.provider];
+const available = ref(false);
- return `${typeof endpoint === 'string' ? endpoint : 'about:invalid'}/api.js?render=explicit`;
- },
- captcha(): Captcha {
- return window[this.variable] || {} as unknown as Captcha;
- },
- },
+const captchaEl = ref<HTMLDivElement | undefined>();
- created() {
- if (this.loaded) {
- this.available = true;
- } else {
- (document.getElementById(this.provider) || document.head.appendChild(Object.assign(document.createElement('script'), {
- async: true,
- id: this.provider,
- src: this.src,
- })))
- .addEventListener('load', () => this.available = true);
- }
- },
+const variable = computed(() => {
+ switch (props.provider) {
+ case 'hcaptcha': return 'hcaptcha';
+ case 'recaptcha': return 'grecaptcha';
+ }
+});
+
+const loaded = computed(() => !!window[variable.value]);
+
+const src = computed(() => {
+ switch (props.provider) {
+ case 'hcaptcha': return 'https://js.hcaptcha.com/1/api.js?render=explicit&recaptchacompat=off';
+ case 'recaptcha': return 'https://www.recaptcha.net/recaptcha/api.js?render=explicit';
+ }
+});
+
+const captcha = computed<Captcha>(() => window[variable.value] || {} as unknown as Captcha);
+
+if (loaded.value) {
+ available.value = true;
+} else {
+ (document.getElementById(props.provider) || document.head.appendChild(Object.assign(document.createElement('script'), {
+ async: true,
+ id: props.provider,
+ src: src.value,
+ })))
+ .addEventListener('load', () => available.value = true);
+}
+
+function reset() {
+ if (captcha.value?.reset) captcha.value.reset();
+}
+
+function requestRender() {
+ if (captcha.value.render && captchaEl.value instanceof Element) {
+ captcha.value.render(captchaEl.value, {
+ sitekey: props.sitekey,
+ theme: defaultStore.state.darkMode ? 'dark' : 'light',
+ callback: callback,
+ 'expired-callback': callback,
+ 'error-callback': callback,
+ });
+ } else {
+ window.setTimeout(requestRender, 1);
+ }
+}
+
+function callback(response?: string) {
+ emit('update:modelValue', typeof response == 'string' ? response : null);
+}
- mounted() {
- if (this.available) {
- this.requestRender();
- } else {
- this.$watch('available', this.requestRender);
- }
- },
+onMounted(() => {
+ if (available.value) {
+ requestRender();
+ } else {
+ watch(available, requestRender);
+ }
+});
- beforeUnmount() {
- this.reset();
- },
+onBeforeUnmount(() => {
+ reset();
+});
- methods: {
- reset() {
- if (this.captcha?.reset) this.captcha.reset();
- },
- requestRender() {
- if (this.captcha.render && this.$refs.captcha instanceof Element) {
- this.captcha.render(this.$refs.captcha, {
- sitekey: this.sitekey,
- theme: this.$store.state.darkMode ? 'dark' : 'light',
- callback: this.callback,
- 'expired-callback': this.callback,
- 'error-callback': this.callback,
- });
- } else {
- setTimeout(this.requestRender.bind(this), 1);
- }
- },
- callback(response?: string) {
- this.$emit('update:modelValue', typeof response == 'string' ? response : null);
- },
- },
+defineExpose({
+ reset,
});
+
</script>
diff --git a/packages/client/src/components/channel-follow-button.vue b/packages/client/src/components/channel-follow-button.vue
index abde7c8148..0ad5384cd5 100644
--- a/packages/client/src/components/channel-follow-button.vue
+++ b/packages/client/src/components/channel-follow-button.vue
@@ -6,66 +6,54 @@
>
<template v-if="!wait">
<template v-if="isFollowing">
- <span v-if="full">{{ $ts.unfollow }}</span><i class="fas fa-minus"></i>
+ <span v-if="full">{{ i18n.locale.unfollow }}</span><i class="fas fa-minus"></i>
</template>
<template v-else>
- <span v-if="full">{{ $ts.follow }}</span><i class="fas fa-plus"></i>
+ <span v-if="full">{{ i18n.locale.follow }}</span><i class="fas fa-plus"></i>
</template>
</template>
<template v-else>
- <span v-if="full">{{ $ts.processing }}</span><i class="fas fa-spinner fa-pulse fa-fw"></i>
+ <span v-if="full">{{ i18n.locale.processing }}</span><i class="fas fa-spinner fa-pulse fa-fw"></i>
</template>
</button>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
+<script lang="ts" setup>
+import { ref } from 'vue';
import * as os from '@/os';
+import { i18n } from '@/i18n';
-export default defineComponent({
- props: {
- channel: {
- type: Object,
- required: true
- },
- full: {
- type: Boolean,
- required: false,
- default: false,
- },
- },
+const props = withDefaults(defineProps<{
+ channel: Record<string, any>;
+ full?: boolean;
+}>(), {
+ full: false,
+});
- data() {
- return {
- isFollowing: this.channel.isFollowing,
- wait: false,
- };
- },
+const isFollowing = ref<boolean>(props.channel.isFollowing);
+const wait = ref(false);
- methods: {
- async onClick() {
- this.wait = true;
+async function onClick() {
+ wait.value = true;
- try {
- if (this.isFollowing) {
- await os.api('channels/unfollow', {
- channelId: this.channel.id
- });
- this.isFollowing = false;
- } else {
- await os.api('channels/follow', {
- channelId: this.channel.id
- });
- this.isFollowing = true;
- }
- } catch (e) {
- console.error(e);
- } finally {
- this.wait = false;
- }
+ try {
+ if (isFollowing.value) {
+ await os.api('channels/unfollow', {
+ channelId: props.channel.id
+ });
+ isFollowing.value = false;
+ } else {
+ await os.api('channels/follow', {
+ channelId: props.channel.id
+ });
+ isFollowing.value = true;
}
+ } catch (e) {
+ console.error(e);
+ } finally {
+ wait.value = false;
}
-});
+}
</script>
<style lang="scss" scoped>
diff --git a/packages/client/src/components/channel-preview.vue b/packages/client/src/components/channel-preview.vue
index f2b6de97fd..8d135a192f 100644
--- a/packages/client/src/components/channel-preview.vue
+++ b/packages/client/src/components/channel-preview.vue
@@ -6,7 +6,7 @@
<div class="status">
<div>
<i class="fas fa-users fa-fw"></i>
- <I18n :src="$ts._channel.usersCount" tag="span" style="margin-left: 4px;">
+ <I18n :src="i18n.locale._channel.usersCount" tag="span" style="margin-left: 4px;">
<template #n>
<b>{{ channel.usersCount }}</b>
</template>
@@ -14,7 +14,7 @@
</div>
<div>
<i class="fas fa-pencil-alt fa-fw"></i>
- <I18n :src="$ts._channel.notesCount" tag="span" style="margin-left: 4px;">
+ <I18n :src="i18n.locale._channel.notesCount" tag="span" style="margin-left: 4px;">
<template #n>
<b>{{ channel.notesCount }}</b>
</template>
@@ -27,37 +27,26 @@
</article>
<footer>
<span v-if="channel.lastNotedAt">
- {{ $ts.updatedAt }}: <MkTime :time="channel.lastNotedAt"/>
+ {{ i18n.locale.updatedAt }}: <MkTime :time="channel.lastNotedAt"/>
</span>
</footer>
</MkA>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
+<script lang="ts" setup>
+import { computed } from 'vue';
+import { i18n } from '@/i18n';
-export default defineComponent({
- props: {
- channel: {
- type: Object,
- required: true
- },
- },
+const props = defineProps<{
+ channel: Record<string, any>;
+}>();
- data() {
- return {
- };
- },
-
- computed: {
- bannerStyle() {
- if (this.channel.bannerUrl) {
- return { backgroundImage: `url(${this.channel.bannerUrl})` };
- } else {
- return { backgroundColor: '#4c5e6d' };
- }
- }
- },
+const bannerStyle = computed(() => {
+ if (props.channel.bannerUrl) {
+ return { backgroundImage: `url(${props.channel.bannerUrl})` };
+ } else {
+ return { backgroundColor: '#4c5e6d' };
+ }
});
</script>
diff --git a/packages/client/src/components/chart.vue b/packages/client/src/components/chart.vue
index c4d0eb85dd..1959271f5d 100644
--- a/packages/client/src/components/chart.vue
+++ b/packages/client/src/components/chart.vue
@@ -170,10 +170,10 @@ export default defineComponent({
aspectRatio: props.aspectRatio || 2.5,
layout: {
padding: {
- left: 16,
- right: 16,
- top: 16,
- bottom: 8,
+ left: 0,
+ right: 0,
+ top: 0,
+ bottom: 0,
},
},
scales: {
diff --git a/packages/client/src/components/code-core.vue b/packages/client/src/components/code-core.vue
index b58484c2ac..45a38afe04 100644
--- a/packages/client/src/components/code-core.vue
+++ b/packages/client/src/components/code-core.vue
@@ -3,33 +3,17 @@
<pre v-else :class="`language-${prismLang}`"><code :class="`language-${prismLang}`" v-html="html"></code></pre>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
+<script lang="ts" setup>
+import { computed } from 'vue';
import 'prismjs';
import 'prismjs/themes/prism-okaidia.css';
-export default defineComponent({
- props: {
- code: {
- type: String,
- required: true
- },
- lang: {
- type: String,
- required: false
- },
- inline: {
- type: Boolean,
- required: false
- }
- },
- computed: {
- prismLang() {
- return Prism.languages[this.lang] ? this.lang : 'js';
- },
- html() {
- return Prism.highlight(this.code, Prism.languages[this.prismLang], this.prismLang);
- }
- }
-});
+const props = defineProps<{
+ code: string;
+ lang?: string;
+ inline?: boolean;
+}>();
+
+const prismLang = computed(() => Prism.languages[props.lang] ? props.lang : 'js');
+const html = computed(() => Prism.highlight(props.code, Prism.languages[prismLang.value], prismLang.value));
</script>
diff --git a/packages/client/src/components/code.vue b/packages/client/src/components/code.vue
index f5d6c5673a..d6478fd2f8 100644
--- a/packages/client/src/components/code.vue
+++ b/packages/client/src/components/code.vue
@@ -2,26 +2,14 @@
<XCode :code="code" :lang="lang" :inline="inline"/>
</template>
-<script lang="ts">
-import { defineComponent, defineAsyncComponent } from 'vue';
+<script lang="ts" setup>
+import { defineAsyncComponent } from 'vue';
-export default defineComponent({
- components: {
- XCode: defineAsyncComponent(() => import('./code-core.vue'))
- },
- props: {
- code: {
- type: String,
- required: true
- },
- lang: {
- type: String,
- required: false
- },
- inline: {
- type: Boolean,
- required: false
- }
- }
-});
+defineProps<{
+ code: string;
+ lang?: string;
+ inline?: boolean;
+}>();
+
+const XCode = defineAsyncComponent(() => import('./code-core.vue'));
</script>
diff --git a/packages/client/src/components/cw-button.vue b/packages/client/src/components/cw-button.vue
index 4bec7b511e..ccfd11462a 100644
--- a/packages/client/src/components/cw-button.vue
+++ b/packages/client/src/components/cw-button.vue
@@ -1,45 +1,37 @@
<template>
<button class="nrvgflfu _button" @click="toggle">
- <b>{{ modelValue ? $ts._cw.hide : $ts._cw.show }}</b>
+ <b>{{ modelValue ? i18n.locale._cw.hide : i18n.locale._cw.show }}</b>
<span v-if="!modelValue">{{ label }}</span>
</button>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
+<script lang="ts" setup>
+import { computed } from 'vue';
import { length } from 'stringz';
+import * as misskey from 'misskey-js';
import { concat } from '@/scripts/array';
+import { i18n } from '@/i18n';
-export default defineComponent({
- props: {
- modelValue: {
- type: Boolean,
- required: true
- },
- note: {
- type: Object,
- required: true
- }
- },
-
- computed: {
- label(): string {
- return concat([
- this.note.text ? [this.$t('_cw.chars', { count: length(this.note.text) })] : [],
- this.note.files && this.note.files.length !== 0 ? [this.$t('_cw.files', { count: this.note.files.length }) ] : [],
- this.note.poll != null ? [this.$ts.poll] : []
- ] as string[][]).join(' / ');
- }
- },
+const props = defineProps<{
+ modelValue: boolean;
+ note: misskey.entities.Note;
+}>();
- methods: {
- length,
+const emit = defineEmits<{
+ (e: 'update:modelValue', v: boolean): void;
+}>();
- toggle() {
- this.$emit('update:modelValue', !this.modelValue);
- }
- }
+const label = computed(() => {
+ return concat([
+ props.note.text ? [i18n.t('_cw.chars', { count: length(props.note.text) })] : [],
+ props.note.files && props.note.files.length !== 0 ? [i18n.t('_cw.files', { count: props.note.files.length }) ] : [],
+ props.note.poll != null ? [i18n.locale.poll] : []
+ ] as string[][]).join(' / ');
});
+
+const toggle = () => {
+ emit('update:modelValue', !props.modelValue);
+};
</script>
<style lang="scss" scoped>
diff --git a/packages/client/src/components/date-separated-list.vue b/packages/client/src/components/date-separated-list.vue
index aa84c6f60d..c85a0a6ffc 100644
--- a/packages/client/src/components/date-separated-list.vue
+++ b/packages/client/src/components/date-separated-list.vue
@@ -1,6 +1,8 @@
<script lang="ts">
import { defineComponent, h, PropType, TransitionGroup } from 'vue';
import MkAd from '@/components/global/ad.vue';
+import { i18n } from '@/i18n';
+import { defaultStore } from '@/store';
export default defineComponent({
props: {
@@ -30,29 +32,29 @@ export default defineComponent({
},
},
- methods: {
- getDateText(time: string) {
+ setup(props, { slots, expose }) {
+ function getDateText(time: string) {
const date = new Date(time).getDate();
const month = new Date(time).getMonth() + 1;
- return this.$t('monthAndDay', {
+ return i18n.t('monthAndDay', {
month: month.toString(),
day: date.toString()
});
}
- },
- render() {
- if (this.items.length === 0) return;
+ if (props.items.length === 0) return;
+
+ const renderChildren = () => props.items.map((item, i) => {
+ if (!slots || !slots.default) return;
- const renderChildren = () => this.items.map((item, i) => {
- const el = this.$slots.default({
+ const el = slots.default({
item: item
})[0];
if (el.key == null && item.id) el.key = item.id;
if (
- i != this.items.length - 1 &&
- new Date(item.createdAt).getDate() != new Date(this.items[i + 1].createdAt).getDate()
+ i != props.items.length - 1 &&
+ new Date(item.createdAt).getDate() != new Date(props.items[i + 1].createdAt).getDate()
) {
const separator = h('div', {
class: 'separator',
@@ -64,10 +66,10 @@ export default defineComponent({
h('i', {
class: 'fas fa-angle-up icon',
}),
- this.getDateText(item.createdAt)
+ getDateText(item.createdAt)
]),
h('span', [
- this.getDateText(this.items[i + 1].createdAt),
+ getDateText(props.items[i + 1].createdAt),
h('i', {
class: 'fas fa-angle-down icon',
})
@@ -76,7 +78,7 @@ export default defineComponent({
return [el, separator];
} else {
- if (this.ad && item._shouldInsertAd_) {
+ if (props.ad && item._shouldInsertAd_) {
return [h(MkAd, {
class: 'a', // advertiseの意(ブロッカー対策)
key: item.id + ':ad',
@@ -88,18 +90,19 @@ export default defineComponent({
}
});
- return h(this.$store.state.animation ? TransitionGroup : 'div', this.$store.state.animation ? {
- class: 'sqadhkmv' + (this.noGap ? ' noGap' : ''),
- name: 'list',
- tag: 'div',
- 'data-direction': this.direction,
- 'data-reversed': this.reversed ? 'true' : 'false',
- } : {
- class: 'sqadhkmv' + (this.noGap ? ' noGap' : ''),
- }, {
- default: renderChildren
- });
- },
+ return () => h(
+ defaultStore.state.animation ? TransitionGroup : 'div',
+ defaultStore.state.animation ? {
+ class: 'sqadhkmv' + (props.noGap ? ' noGap' : ''),
+ name: 'list',
+ tag: 'div',
+ 'data-direction': props.direction,
+ 'data-reversed': props.reversed ? 'true' : 'false',
+ } : {
+ class: 'sqadhkmv' + (props.noGap ? ' noGap' : ''),
+ },
+ { default: renderChildren });
+ }
});
</script>
diff --git a/packages/client/src/components/debobigego/base.vue b/packages/client/src/components/debobigego/base.vue
deleted file mode 100644
index 9ed59abc69..0000000000
--- a/packages/client/src/components/debobigego/base.vue
+++ /dev/null
@@ -1,65 +0,0 @@
-<template>
-<div v-size="{ max: [400] }" class="rbusrurv" :class="{ wide: forceWide }">
- <slot></slot>
-</div>
-</template>
-
-<script lang="ts">
-import { defineComponent } from 'vue';
-
-export default defineComponent({
- props: {
- forceWide: {
- type: Boolean,
- required: false,
- default: false,
- }
- }
-});
-</script>
-
-<style lang="scss" scoped>
-.rbusrurv {
- // 他のCSSからも参照されるので消さないように
- --debobigegoXPadding: 32px;
- --debobigegoYPadding: 32px;
-
- --debobigegoContentHMargin: 16px;
-
- font-size: 95%;
- line-height: 1.3em;
- background: var(--bg);
- padding: var(--debobigegoYPadding) var(--debobigegoXPadding);
- max-width: 750px;
- margin: 0 auto;
-
- &:not(.wide).max-width_400px {
- --debobigegoXPadding: 0px;
-
- > ::v-deep(*) {
- ._debobigegoPanel {
- border: solid 0.5px var(--divider);
- border-radius: 0;
- border-left: none;
- border-right: none;
- }
-
- ._debobigego_group {
- > *:not(._debobigegoNoConcat) {
- &:not(:last-child):not(._debobigegoNoConcatPrev) {
- &._debobigegoPanel, ._debobigegoPanel {
- border-bottom: solid 0.5px var(--divider);
- }
- }
-
- &:not(:first-child):not(._debobigegoNoConcatNext) {
- &._debobigegoPanel, ._debobigegoPanel {
- border-top: none;
- }
- }
- }
- }
- }
- }
-}
-</style>
diff --git a/packages/client/src/components/debobigego/button.vue b/packages/client/src/components/debobigego/button.vue
deleted file mode 100644
index b883e817a4..0000000000
--- a/packages/client/src/components/debobigego/button.vue
+++ /dev/null
@@ -1,81 +0,0 @@
-<template>
-<div class="yzpgjkxe _debobigegoItem">
- <div class="_debobigegoLabel"><slot name="label"></slot></div>
- <button class="main _button _debobigegoPanel _debobigegoClickable" :class="{ center, primary, danger }">
- <slot></slot>
- <div class="suffix">
- <slot name="suffix"></slot>
- <div class="icon">
- <slot name="suffixIcon"></slot>
- </div>
- </div>
- </button>
- <div class="_debobigegoCaption"><slot name="desc"></slot></div>
-</div>
-</template>
-
-<script lang="ts">
-import { defineComponent } from 'vue';
-import './debobigego.scss';
-
-export default defineComponent({
- props: {
- primary: {
- type: Boolean,
- required: false,
- default: false,
- },
- danger: {
- type: Boolean,
- required: false,
- default: false,
- },
- disabled: {
- type: Boolean,
- required: false,
- default: false,
- },
- center: {
- type: Boolean,
- required: false,
- default: true,
- }
- },
-});
-</script>
-
-<style lang="scss" scoped>
-.yzpgjkxe {
- > .main {
- display: flex;
- width: 100%;
- box-sizing: border-box;
- padding: 14px 16px;
- text-align: left;
- align-items: center;
-
- &.center {
- display: block;
- text-align: center;
- }
-
- &.primary {
- color: var(--accent);
- }
-
- &.danger {
- color: #ff2a2a;
- }
-
- > .suffix {
- display: inline-flex;
- margin-left: auto;
- opacity: 0.7;
-
- > .icon {
- margin-left: 1em;
- }
- }
- }
-}
-</style>
diff --git a/packages/client/src/components/debobigego/debobigego.scss b/packages/client/src/components/debobigego/debobigego.scss
deleted file mode 100644
index 833b656b66..0000000000
--- a/packages/client/src/components/debobigego/debobigego.scss
+++ /dev/null
@@ -1,52 +0,0 @@
-._debobigegoPanel {
- background: var(--panel);
- border-radius: var(--radius);
- transition: background 0.2s ease;
-
- &._debobigegoClickable {
- &:hover {
- //background: var(--panelHighlight);
- }
-
- &:active {
- background: var(--panelHighlight);
- transition: background 0s;
- }
- }
-}
-
-._debobigegoLabel,
-._debobigegoCaption {
- font-size: 80%;
- color: var(--fgTransparentWeak);
-
- &:empty {
- display: none;
- }
-}
-
-._debobigegoLabel {
- position: sticky;
- top: var(--stickyTop, 0px);
- z-index: 2;
- margin: -8px calc(var(--debobigegoXPadding) * -1) 0 calc(var(--debobigegoXPadding) * -1);
- padding: 8px calc(var(--debobigegoContentHMargin) + var(--debobigegoXPadding)) 8px calc(var(--debobigegoContentHMargin) + var(--debobigegoXPadding));
- background: var(--X17);
- -webkit-backdrop-filter: var(--blur, blur(10px));
- backdrop-filter: var(--blur, blur(10px));
-}
-
-._themeChanging_ ._debobigegoLabel {
- transition: none !important;
- background: transparent;
-}
-
-._debobigegoCaption {
- padding: 8px var(--debobigegoContentHMargin) 0 var(--debobigegoContentHMargin);
-}
-
-._debobigegoItem {
- & + ._debobigegoItem {
- margin-top: 24px;
- }
-}
diff --git a/packages/client/src/components/debobigego/group.vue b/packages/client/src/components/debobigego/group.vue
deleted file mode 100644
index 871d3c8dba..0000000000
--- a/packages/client/src/components/debobigego/group.vue
+++ /dev/null
@@ -1,78 +0,0 @@
-<template>
-<div v-size="{ max: [500] }" v-sticky-container class="vrtktovg _debobigegoItem _debobigegoNoConcat">
- <div class="_debobigegoLabel"><slot name="label"></slot></div>
- <div ref="child" class="main _debobigego_group">
- <slot></slot>
- </div>
- <div class="_debobigegoCaption"><slot name="caption"></slot></div>
-</div>
-</template>
-
-<script lang="ts">
-import { defineComponent, onMounted, ref } from 'vue';
-
-export default defineComponent({
- setup(props, context) {
- const child = ref<HTMLElement | null>(null);
-
- const scanChild = () => {
- if (child.value == null) return;
- const els = Array.from(child.value.children);
- for (let i = 0; i < els.length; i++) {
- const el = els[i];
- if (el.classList.contains('_debobigegoNoConcat')) {
- if (els[i - 1]) els[i - 1].classList.add('_debobigegoNoConcatPrev');
- if (els[i + 1]) els[i + 1].classList.add('_debobigegoNoConcatNext');
- }
- }
- };
-
- onMounted(() => {
- scanChild();
-
- const observer = new MutationObserver(records => {
- scanChild();
- });
-
- observer.observe(child.value, {
- childList: true,
- subtree: false,
- attributes: false,
- characterData: false,
- });
- });
-
- return {
- child
- };
- }
-});
-</script>
-
-<style lang="scss" scoped>
-.vrtktovg {
- > .main {
- > ::v-deep(*):not(._debobigegoNoConcat) {
- &:not(._debobigegoNoConcatNext) {
- margin: 0;
- }
-
- &:not(:last-child):not(._debobigegoNoConcatPrev) {
- &._debobigegoPanel, ._debobigegoPanel {
- border-bottom: solid 0.5px var(--divider);
- border-bottom-left-radius: 0;
- border-bottom-right-radius: 0;
- }
- }
-
- &:not(:first-child):not(._debobigegoNoConcatNext) {
- &._debobigegoPanel, ._debobigegoPanel {
- border-top: none;
- border-top-left-radius: 0;
- border-top-right-radius: 0;
- }
- }
- }
- }
-}
-</style>
diff --git a/packages/client/src/components/debobigego/info.vue b/packages/client/src/components/debobigego/info.vue
deleted file mode 100644
index 41afb03304..0000000000
--- a/packages/client/src/components/debobigego/info.vue
+++ /dev/null
@@ -1,47 +0,0 @@
-<template>
-<div class="fzenkabp _debobigegoItem">
- <div class="_debobigegoPanel" :class="{ warn }">
- <i v-if="warn" class="fas fa-exclamation-triangle"></i>
- <i v-else class="fas fa-info-circle"></i>
- <slot></slot>
- </div>
-</div>
-</template>
-
-<script lang="ts">
-import { defineComponent } from 'vue';
-
-export default defineComponent({
- props: {
- warn: {
- type: Boolean,
- required: false,
- default: false
- },
- },
- data() {
- return {
- };
- }
-});
-</script>
-
-<style lang="scss" scoped>
-.fzenkabp {
- > div {
- padding: 14px 16px;
- font-size: 90%;
- background: var(--infoBg);
- color: var(--infoFg);
-
- &.warn {
- background: var(--infoWarnBg);
- color: var(--infoWarnFg);
- }
-
- > i {
- margin-right: 4px;
- }
- }
-}
-</style>
diff --git a/packages/client/src/components/debobigego/input.vue b/packages/client/src/components/debobigego/input.vue
deleted file mode 100644
index 6228a33fe4..0000000000
--- a/packages/client/src/components/debobigego/input.vue
+++ /dev/null
@@ -1,292 +0,0 @@
-<template>
-<FormGroup class="_debobigegoItem">
- <template #label><slot></slot></template>
- <div class="ztzhwixg _debobigegoItem" :class="{ inline, disabled }">
- <div ref="icon" class="icon"><slot name="icon"></slot></div>
- <div class="input _debobigegoPanel">
- <div ref="prefixEl" class="prefix"><slot name="prefix"></slot></div>
- <input ref="inputEl"
- v-model="v"
- :type="type"
- :disabled="disabled"
- :required="required"
- :readonly="readonly"
- :placeholder="placeholder"
- :pattern="pattern"
- :autocomplete="autocomplete"
- :spellcheck="spellcheck"
- :step="step"
- :list="id"
- @focus="focused = true"
- @blur="focused = false"
- @keydown="onKeydown($event)"
- @input="onInput"
- >
- <datalist v-if="datalist" :id="id">
- <option v-for="data in datalist" :value="data"/>
- </datalist>
- <div ref="suffixEl" class="suffix"><slot name="suffix"></slot></div>
- </div>
- </div>
- <template #caption><slot name="desc"></slot></template>
-
- <FormButton v-if="manualSave && changed" primary @click="updated"><i class="fas fa-save"></i> {{ $ts.save }}</FormButton>
-</FormGroup>
-</template>
-
-<script lang="ts">
-import { defineComponent, onMounted, onUnmounted, nextTick, ref, watch, computed, toRefs } from 'vue';
-import './debobigego.scss';
-import FormButton from './button.vue';
-import FormGroup from './group.vue';
-
-export default defineComponent({
- components: {
- FormGroup,
- FormButton,
- },
- props: {
- modelValue: {
- required: false
- },
- type: {
- type: String,
- required: false
- },
- required: {
- type: Boolean,
- required: false
- },
- readonly: {
- type: Boolean,
- required: false
- },
- disabled: {
- type: Boolean,
- required: false
- },
- pattern: {
- type: String,
- required: false
- },
- placeholder: {
- type: String,
- required: false
- },
- autofocus: {
- type: Boolean,
- required: false,
- default: false
- },
- autocomplete: {
- required: false
- },
- spellcheck: {
- required: false
- },
- step: {
- required: false
- },
- datalist: {
- type: Array,
- required: false,
- },
- inline: {
- type: Boolean,
- required: false,
- default: false
- },
- manualSave: {
- type: Boolean,
- required: false,
- default: false
- },
- },
- emits: ['change', 'keydown', 'enter', 'update:modelValue'],
- setup(props, context) {
- const { modelValue, type, autofocus } = toRefs(props);
- const v = ref(modelValue.value);
- const id = Math.random().toString(); // TODO: uuid?
- const focused = ref(false);
- const changed = ref(false);
- const invalid = ref(false);
- const filled = computed(() => v.value !== '' && v.value != null);
- const inputEl = ref(null);
- const prefixEl = ref(null);
- const suffixEl = ref(null);
-
- const focus = () => inputEl.value.focus();
- const onInput = (ev) => {
- changed.value = true;
- context.emit('change', ev);
- };
- const onKeydown = (ev: KeyboardEvent) => {
- context.emit('keydown', ev);
-
- if (ev.code === 'Enter') {
- context.emit('enter');
- }
- };
-
- const updated = () => {
- changed.value = false;
- if (type?.value === 'number') {
- context.emit('update:modelValue', parseFloat(v.value));
- } else {
- context.emit('update:modelValue', v.value);
- }
- };
-
- watch(modelValue.value, newValue => {
- v.value = newValue;
- });
-
- watch(v, newValue => {
- if (!props.manualSave) {
- updated();
- }
-
- invalid.value = inputEl.value.validity.badInput;
- });
-
- onMounted(() => {
- nextTick(() => {
- if (autofocus.value) {
- focus();
- }
-
- // このコンポーネントが作成された時、非表示状態である場合がある
- // 非表示状態だと要素の幅などは0になってしまうので、定期的に計算する
- const clock = setInterval(() => {
- if (prefixEl.value) {
- if (prefixEl.value.offsetWidth) {
- inputEl.value.style.paddingLeft = prefixEl.value.offsetWidth + 'px';
- }
- }
- if (suffixEl.value) {
- if (suffixEl.value.offsetWidth) {
- inputEl.value.style.paddingRight = suffixEl.value.offsetWidth + 'px';
- }
- }
- }, 100);
-
- onUnmounted(() => {
- clearInterval(clock);
- });
- });
- });
-
- return {
- id,
- v,
- focused,
- invalid,
- changed,
- filled,
- inputEl,
- prefixEl,
- suffixEl,
- focus,
- onInput,
- onKeydown,
- updated,
- };
- },
-});
-</script>
-
-<style lang="scss" scoped>
-.ztzhwixg {
- position: relative;
-
- > .icon {
- position: absolute;
- top: 0;
- left: 0;
- width: 24px;
- text-align: center;
- line-height: 32px;
-
- &:not(:empty) + .input {
- margin-left: 28px;
- }
- }
-
- > .input {
- $height: 48px;
- position: relative;
-
- > input {
- display: block;
- height: $height;
- width: 100%;
- margin: 0;
- padding: 0 16px;
- font: inherit;
- font-weight: normal;
- font-size: 1em;
- line-height: $height;
- color: var(--inputText);
- background: transparent;
- border: none;
- border-radius: 0;
- outline: none;
- box-shadow: none;
- box-sizing: border-box;
-
- &[type='file'] {
- display: none;
- }
- }
-
- > .prefix,
- > .suffix {
- display: block;
- position: absolute;
- z-index: 1;
- top: 0;
- padding: 0 16px;
- font-size: 1em;
- line-height: $height;
- color: var(--inputLabel);
- pointer-events: none;
-
- &:empty {
- display: none;
- }
-
- > * {
- display: inline-block;
- min-width: 16px;
- max-width: 150px;
- overflow: hidden;
- white-space: nowrap;
- text-overflow: ellipsis;
- }
- }
-
- > .prefix {
- left: 0;
- padding-right: 8px;
- }
-
- > .suffix {
- right: 0;
- padding-left: 8px;
- }
- }
-
- &.inline {
- display: inline-block;
- margin: 0;
- }
-
- &.disabled {
- opacity: 0.7;
-
- &, * {
- cursor: not-allowed !important;
- }
- }
-}
-</style>
diff --git a/packages/client/src/components/debobigego/key-value-view.vue b/packages/client/src/components/debobigego/key-value-view.vue
deleted file mode 100644
index 0e034a2d54..0000000000
--- a/packages/client/src/components/debobigego/key-value-view.vue
+++ /dev/null
@@ -1,38 +0,0 @@
-<template>
-<div class="_debobigegoItem">
- <div class="_debobigegoPanel anocepby">
- <span class="key"><slot name="key"></slot></span>
- <span class="value"><slot name="value"></slot></span>
- </div>
-</div>
-</template>
-
-<script lang="ts">
-import { defineComponent } from 'vue';
-import './debobigego.scss';
-
-export default defineComponent({
-
-});
-</script>
-
-<style lang="scss" scoped>
-.anocepby {
- display: flex;
- align-items: center;
- padding: 14px var(--debobigegoContentHMargin);
-
- > .key {
- margin-right: 12px;
- white-space: nowrap;
- }
-
- > .value {
- margin-left: auto;
- opacity: 0.7;
- text-overflow: ellipsis;
- white-space: nowrap;
- overflow: hidden;
- }
-}
-</style>
diff --git a/packages/client/src/components/debobigego/link.vue b/packages/client/src/components/debobigego/link.vue
deleted file mode 100644
index de463465d4..0000000000
--- a/packages/client/src/components/debobigego/link.vue
+++ /dev/null
@@ -1,103 +0,0 @@
-<template>
-<div class="qmfkfnzi _debobigegoItem">
- <a v-if="external" class="main _button _debobigegoPanel _debobigegoClickable" :href="to" target="_blank">
- <span class="icon"><slot name="icon"></slot></span>
- <span class="text"><slot></slot></span>
- <span class="right">
- <span class="text"><slot name="suffix"></slot></span>
- <i class="fas fa-external-link-alt icon"></i>
- </span>
- </a>
- <MkA v-else class="main _button _debobigegoPanel _debobigegoClickable" :class="{ active }" :to="to" :behavior="behavior">
- <span class="icon"><slot name="icon"></slot></span>
- <span class="text"><slot></slot></span>
- <span class="right">
- <span class="text"><slot name="suffix"></slot></span>
- <i class="fas fa-chevron-right icon"></i>
- </span>
- </MkA>
-</div>
-</template>
-
-<script lang="ts">
-import { defineComponent } from 'vue';
-import './debobigego.scss';
-
-export default defineComponent({
- props: {
- to: {
- type: String,
- required: true
- },
- active: {
- type: Boolean,
- required: false
- },
- external: {
- type: Boolean,
- required: false
- },
- behavior: {
- type: String,
- required: false,
- },
- },
- data() {
- return {
- };
- }
-});
-</script>
-
-<style lang="scss" scoped>
-.qmfkfnzi {
- > .main {
- display: flex;
- align-items: center;
- width: 100%;
- box-sizing: border-box;
- padding: 14px 16px 14px 14px;
-
- &:hover {
- text-decoration: none;
- }
-
- &.active {
- color: var(--accent);
- background: var(--panelHighlight);
- }
-
- > .icon {
- width: 32px;
- margin-right: 2px;
- flex-shrink: 0;
- text-align: center;
- opacity: 0.8;
-
- &:empty {
- display: none;
-
- & + .text {
- padding-left: 4px;
- }
- }
- }
-
- > .text {
- white-space: nowrap;
- text-overflow: ellipsis;
- overflow: hidden;
- padding-right: 12px;
- }
-
- > .right {
- margin-left: auto;
- opacity: 0.7;
-
- > .text:not(:empty) {
- margin-right: 0.75em;
- }
- }
- }
-}
-</style>
diff --git a/packages/client/src/components/debobigego/object-view.vue b/packages/client/src/components/debobigego/object-view.vue
deleted file mode 100644
index 68be08560b..0000000000
--- a/packages/client/src/components/debobigego/object-view.vue
+++ /dev/null
@@ -1,102 +0,0 @@
-<template>
-<FormGroup class="_debobigegoItem">
- <template #label><slot></slot></template>
- <div class="drooglns _debobigegoItem" :class="{ tall }">
- <div class="input _debobigegoPanel">
- <textarea v-model="v"
- class="_monospace"
- readonly
- :spellcheck="false"
- ></textarea>
- </div>
- </div>
- <template #caption><slot name="desc"></slot></template>
-</FormGroup>
-</template>
-
-<script lang="ts">
-import { defineComponent, ref, toRefs, watch } from 'vue';
-import * as JSON5 from 'json5';
-import './debobigego.scss';
-import FormGroup from './group.vue';
-
-export default defineComponent({
- components: {
- FormGroup,
- },
- props: {
- value: {
- required: false
- },
- tall: {
- type: Boolean,
- required: false,
- default: false
- },
- pre: {
- type: Boolean,
- required: false,
- default: false
- },
- manualSave: {
- type: Boolean,
- required: false,
- default: false
- },
- },
- setup(props, context) {
- const { value } = toRefs(props);
- const v = ref('');
-
- watch(() => value, newValue => {
- v.value = JSON5.stringify(newValue.value, null, '\t');
- }, {
- immediate: true
- });
-
- return {
- v,
- };
- }
-});
-</script>
-
-<style lang="scss" scoped>
-.drooglns {
- position: relative;
-
- > .input {
- position: relative;
-
- > textarea {
- display: block;
- width: 100%;
- min-width: 100%;
- max-width: 100%;
- min-height: 130px;
- margin: 0;
- padding: 16px var(--debobigegoContentHMargin);
- box-sizing: border-box;
- font: inherit;
- font-weight: normal;
- font-size: 1em;
- background: transparent;
- border: none;
- border-radius: 0;
- outline: none;
- box-shadow: none;
- color: var(--fg);
- tab-size: 2;
- white-space: pre;
- }
- }
-
- &.tall {
- > .input {
- > textarea {
- min-height: 200px;
- }
- }
- }
-}
-</style>
diff --git a/packages/client/src/components/debobigego/pagination.vue b/packages/client/src/components/debobigego/pagination.vue
deleted file mode 100644
index 16779caa42..0000000000
--- a/packages/client/src/components/debobigego/pagination.vue
+++ /dev/null
@@ -1,42 +0,0 @@
-<template>
-<FormGroup class="uljviswt _debobigegoItem">
- <template #label><slot name="label"></slot></template>
- <slot :items="items"></slot>
- <div v-if="empty" key="_empty_" class="empty">
- <slot name="empty"></slot>
- </div>
- <FormButton v-show="more" class="button" :disabled="moreFetching" :style="{ cursor: moreFetching ? 'wait' : 'pointer' }" primary @click="fetchMore">
- <template v-if="!moreFetching">{{ $ts.loadMore }}</template>
- <template v-if="moreFetching"><MkLoading inline/></template>
- </FormButton>
-</FormGroup>
-</template>
-
-<script lang="ts">
-import { defineComponent } from 'vue';
-import FormButton from './button.vue';
-import FormGroup from './group.vue';
-import paging from '@/scripts/paging';
-
-export default defineComponent({
- components: {
- FormButton,
- FormGroup,
- },
-
- mixins: [
- paging({}),
- ],
-
- props: {
- pagination: {
- required: true
- },
- },
-});
-</script>
-
-<style lang="scss" scoped>
-.uljviswt {
-}
-</style>
diff --git a/packages/client/src/components/debobigego/radios.vue b/packages/client/src/components/debobigego/radios.vue
deleted file mode 100644
index b4c5841337..0000000000
--- a/packages/client/src/components/debobigego/radios.vue
+++ /dev/null
@@ -1,112 +0,0 @@
-<script lang="ts">
-import { defineComponent, h } from 'vue';
-import MkRadio from '@/components/form/radio.vue';
-import './debobigego.scss';
-
-export default defineComponent({
- components: {
- MkRadio
- },
- props: {
- modelValue: {
- required: false
- },
- },
- data() {
- return {
- value: this.modelValue,
- }
- },
- watch: {
- modelValue() {
- this.value = this.modelValue;
- },
- value() {
- this.$emit('update:modelValue', this.value);
- }
- },
- render() {
- const label = this.$slots.desc();
- let options = this.$slots.default();
-
- // なぜかFragmentになることがあるため
- if (options.length === 1 && options[0].props == null) options = options[0].children;
-
- return h('div', {
- class: 'cnklmpwm _debobigegoItem'
- }, [
- h('div', {
- class: '_debobigegoLabel',
- }, label),
- ...options.map(option => h('button', {
- class: '_button _debobigegoPanel _debobigegoClickable',
- key: option.key,
- onClick: () => this.value = option.props.value,
- }, [h('span', {
- class: ['check', { checked: this.value === option.props.value }],
- }), option.children]))
- ]);
- }
-});
-</script>
-
-<style lang="scss">
-.cnklmpwm {
- > button {
- display: block;
- width: 100%;
- box-sizing: border-box;
- padding: 14px 18px;
- text-align: left;
-
- &:not(:first-of-type) {
- border-top: none !important;
- border-top-left-radius: 0;
- border-top-right-radius: 0;
- }
-
- &:not(:last-of-type) {
- border-bottom: solid 0.5px var(--divider);
- border-bottom-left-radius: 0;
- border-bottom-right-radius: 0;
- }
-
- > .check {
- display: inline-block;
- vertical-align: bottom;
- position: relative;
- width: 16px;
- height: 16px;
- margin-right: 8px;
- background: none;
- border: 2px solid var(--inputBorder);
- border-radius: 100%;
- transition: inherit;
-
- &:after {
- content: "";
- display: block;
- position: absolute;
- top: 3px;
- right: 3px;
- bottom: 3px;
- left: 3px;
- border-radius: 100%;
- opacity: 0;
- transform: scale(0);
- transition: .4s cubic-bezier(.25,.8,.25,1);
- }
-
- &.checked {
- border-color: var(--accent);
-
- &:after {
- background-color: var(--accent);
- transform: scale(1);
- opacity: 1;
- }
- }
- }
- }
-}
-</style>
diff --git a/packages/client/src/components/debobigego/range.vue b/packages/client/src/components/debobigego/range.vue
deleted file mode 100644
index dc71f25d83..0000000000
--- a/packages/client/src/components/debobigego/range.vue
+++ /dev/null
@@ -1,122 +0,0 @@
-<template>
-<div class="ifitouly _debobigegoItem" :class="{ focused, disabled }">
- <div class="_debobigegoLabel"><slot name="label"></slot></div>
- <div class="_debobigegoPanel main">
- <input
- ref="input"
- v-model="v"
- type="range"
- :disabled="disabled"
- :min="min"
- :max="max"
- :step="step"
- @focus="focused = true"
- @blur="focused = false"
- @input="$emit('update:value', $event.target.value)"
- />
- </div>
- <div class="_debobigegoCaption"><slot name="caption"></slot></div>
-</div>
-</template>
-
-<script lang="ts">
-import { defineComponent } from 'vue';
-
-export default defineComponent({
- props: {
- value: {
- type: Number,
- required: false,
- default: 0
- },
- disabled: {
- type: Boolean,
- required: false,
- default: false
- },
- min: {
- type: Number,
- required: false,
- default: 0
- },
- max: {
- type: Number,
- required: false,
- default: 100
- },
- step: {
- type: Number,
- required: false,
- default: 1
- },
- },
- data() {
- return {
- v: this.value,
- focused: false
- };
- },
- watch: {
- value(v) {
- this.v = parseFloat(v);
- }
- },
-});
-</script>
-
-<style lang="scss" scoped>
-.ifitouly {
- position: relative;
-
- > .main {
- padding: 22px 16px;
-
- > input {
- display: block;
- -webkit-appearance: none;
- -moz-appearance: none;
- appearance: none;
- background: var(--X10);
- height: 4px;
- width: 100%;
- box-sizing: border-box;
- margin: 0;
- outline: 0;
- border: 0;
- border-radius: 7px;
-
- &.disabled {
- opacity: 0.6;
- cursor: not-allowed;
- }
-
- &::-webkit-slider-thumb {
- -webkit-appearance: none;
- appearance: none;
- cursor: pointer;
- width: 20px;
- height: 20px;
- display: block;
- border-radius: 50%;
- border: none;
- background: var(--accent);
- box-shadow: 0 0 6px rgba(0, 0, 0, 0.3);
- box-sizing: content-box;
- }
-
- &::-moz-range-thumb {
- -moz-appearance: none;
- appearance: none;
- cursor: pointer;
- width: 20px;
- height: 20px;
- display: block;
- border-radius: 50%;
- border: none;
- background: var(--accent);
- box-shadow: 0 0 6px rgba(0, 0, 0, 0.3);
- }
- }
- }
-}
-</style>
diff --git a/packages/client/src/components/debobigego/select.vue b/packages/client/src/components/debobigego/select.vue
deleted file mode 100644
index 081bbfe302..0000000000
--- a/packages/client/src/components/debobigego/select.vue
+++ /dev/null
@@ -1,145 +0,0 @@
-<template>
-<div class="yrtfrpux _debobigegoItem" :class="{ disabled, inline }">
- <div class="_debobigegoLabel"><slot name="label"></slot></div>
- <div ref="icon" class="icon"><slot name="icon"></slot></div>
- <div class="input _debobigegoPanel _debobigegoClickable" @click="focus">
- <div ref="prefix" class="prefix"><slot name="prefix"></slot></div>
- <select ref="input"
- v-model="v"
- :required="required"
- :disabled="disabled"
- @focus="focused = true"
- @blur="focused = false"
- >
- <slot></slot>
- </select>
- <div class="suffix">
- <i class="fas fa-chevron-down"></i>
- </div>
- </div>
- <div class="_debobigegoCaption"><slot name="caption"></slot></div>
-</div>
-</template>
-
-<script lang="ts">
-import { defineComponent } from 'vue';
-import './debobigego.scss';
-
-export default defineComponent({
- props: {
- modelValue: {
- required: false
- },
- required: {
- type: Boolean,
- required: false
- },
- disabled: {
- type: Boolean,
- required: false
- },
- inline: {
- type: Boolean,
- required: false,
- default: false
- },
- },
- data() {
- return {
- };
- },
- computed: {
- v: {
- get() {
- return this.modelValue;
- },
- set(v) {
- this.$emit('update:modelValue', v);
- }
- },
- },
- methods: {
- focus() {
- this.$refs.input.focus();
- }
- }
-});
-</script>
-
-<style lang="scss" scoped>
-.yrtfrpux {
- position: relative;
-
- > .icon {
- position: absolute;
- top: 0;
- left: 0;
- width: 24px;
- text-align: center;
- line-height: 32px;
-
- &:not(:empty) + .input {
- margin-left: 28px;
- }
- }
-
- > .input {
- display: flex;
- position: relative;
-
- > select {
- display: block;
- flex: 1;
- width: 100%;
- padding: 0 16px;
- font: inherit;
- font-weight: normal;
- font-size: 1em;
- height: 48px;
- background: none;
- border: none;
- border-radius: 0;
- outline: none;
- box-shadow: none;
- appearance: none;
- -webkit-appearance: none;
- color: var(--fg);
-
- option,
- optgroup {
- color: var(--fg);
- background: var(--bg);
- }
- }
-
- > .prefix,
- > .suffix {
- display: block;
- align-self: center;
- justify-self: center;
- font-size: 1em;
- line-height: 32px;
- color: var(--inputLabel);
- pointer-events: none;
-
- &:empty {
- display: none;
- }
-
- > * {
- display: block;
- min-width: 16px;
- }
- }
-
- > .prefix {
- padding-right: 4px;
- }
-
- > .suffix {
- padding: 0 16px 0 0;
- opacity: 0.7;
- }
- }
-}
-</style>
diff --git a/packages/client/src/components/debobigego/suspense.vue b/packages/client/src/components/debobigego/suspense.vue
deleted file mode 100644
index acb0b64424..0000000000
--- a/packages/client/src/components/debobigego/suspense.vue
+++ /dev/null
@@ -1,101 +0,0 @@
-<template>
-<transition name="fade" mode="out-in">
- <div v-if="pending" class="_debobigegoItem">
- <div class="_debobigegoPanel">
- <MkLoading/>
- </div>
- </div>
- <div v-else-if="resolved" class="_debobigegoItem">
- <slot :result="result"></slot>
- </div>
- <div v-else class="_debobigegoItem">
- <div class="_debobigegoPanel eiurkvay">
- <div><i class="fas fa-exclamation-triangle"></i> {{ $ts.somethingHappened }}</div>
- <MkButton inline class="retry" @click="retry"><i class="fas fa-redo-alt"></i> {{ $ts.retry }}</MkButton>
- </div>
- </div>
-</transition>
-</template>
-
-<script lang="ts">
-import { defineComponent, PropType, ref, watch } from 'vue';
-import './debobigego.scss';
-import MkButton from '@/components/ui/button.vue';
-
-export default defineComponent({
- components: {
- MkButton
- },
-
- props: {
- p: {
- type: Function as PropType<() => Promise<any>>,
- required: true,
- }
- },
-
- setup(props, context) {
- const pending = ref(true);
- const resolved = ref(false);
- const rejected = ref(false);
- const result = ref(null);
-
- const process = () => {
- if (props.p == null) {
- return;
- }
- const promise = props.p();
- pending.value = true;
- resolved.value = false;
- rejected.value = false;
- promise.then((_result) => {
- pending.value = false;
- resolved.value = true;
- result.value = _result;
- });
- promise.catch(() => {
- pending.value = false;
- rejected.value = true;
- });
- };
-
- watch(() => props.p, () => {
- process();
- }, {
- immediate: true
- });
-
- const retry = () => {
- process();
- };
-
- return {
- pending,
- resolved,
- rejected,
- result,
- retry,
- };
- }
-});
-</script>
-
-<style lang="scss" scoped>
-.fade-enter-active,
-.fade-leave-active {
- transition: opacity 0.125s ease;
-}
-.fade-enter-from,
-.fade-leave-to {
- opacity: 0;
-}
-
-.eiurkvay {
- padding: 16px;
- text-align: center;
-
- > .retry {
- margin-top: 16px;
- }
-}
-</style>
diff --git a/packages/client/src/components/debobigego/switch.vue b/packages/client/src/components/debobigego/switch.vue
deleted file mode 100644
index 239140f730..0000000000
--- a/packages/client/src/components/debobigego/switch.vue
+++ /dev/null
@@ -1,132 +0,0 @@
-<template>
-<div class="ijnpvmgr _debobigegoItem">
- <div class="main _debobigegoPanel _debobigegoClickable"
- :class="{ disabled, checked }"
- :aria-checked="checked"
- :aria-disabled="disabled"
- @click.prevent="toggle"
- >
- <input
- ref="input"
- type="checkbox"
- :disabled="disabled"
- @keydown.enter="toggle"
- >
- <span v-tooltip="checked ? $ts.itsOn : $ts.itsOff" class="button">
- <span class="handle"></span>
- </span>
- <span class="label">
- <span><slot></slot></span>
- </span>
- </div>
- <div class="_debobigegoCaption"><slot name="desc"></slot></div>
-</div>
-</template>
-
-<script lang="ts">
-import { defineComponent } from 'vue';
-import './debobigego.scss';
-
-export default defineComponent({
- props: {
- modelValue: {
- type: Boolean,
- default: false
- },
- disabled: {
- type: Boolean,
- default: false
- }
- },
- computed: {
- checked(): boolean {
- return this.modelValue;
- }
- },
- methods: {
- toggle() {
- if (this.disabled) return;
- this.$emit('update:modelValue', !this.checked);
- }
- }
-});
-</script>
-
-<style lang="scss" scoped>
-.ijnpvmgr {
- > .main {
- position: relative;
- display: flex;
- padding: 14px 16px;
- cursor: pointer;
-
- > * {
- user-select: none;
- }
-
- > input {
- position: absolute;
- width: 0;
- height: 0;
- opacity: 0;
- margin: 0;
- }
-
- > .button {
- position: relative;
- display: inline-block;
- flex-shrink: 0;
- margin: 0;
- width: 34px;
- height: 22px;
- background: var(--switchBg);
- outline: none;
- border-radius: 999px;
- transition: all 0.3s;
- cursor: pointer;
-
- > .handle {
- position: absolute;
- top: 0;
- left: 3px;
- bottom: 0;
- margin: auto 0;
- border-radius: 100%;
- transition: background-color 0.3s, transform 0.3s;
- width: 16px;
- height: 16px;
- background-color: #fff;
- pointer-events: none;
- }
- }
-
- > .label {
- margin-left: 12px;
- display: block;
- transition: inherit;
- color: var(--fg);
-
- > span {
- display: block;
- line-height: 20px;
- transition: inherit;
- }
- }
-
- &.disabled {
- opacity: 0.6;
- cursor: not-allowed;
- }
-
- &.checked {
- > .button {
- background-color: var(--accent);
-
- > .handle {
- transform: translateX(12px);
- }
- }
- }
- }
-}
-</style>
diff --git a/packages/client/src/components/debobigego/textarea.vue b/packages/client/src/components/debobigego/textarea.vue
deleted file mode 100644
index ca5b35c49e..0000000000
--- a/packages/client/src/components/debobigego/textarea.vue
+++ /dev/null
@@ -1,161 +0,0 @@
-<template>
-<FormGroup class="_debobigegoItem">
- <template #label><slot></slot></template>
- <div class="rivhosbp _debobigegoItem" :class="{ tall, pre }">
- <div class="input _debobigegoPanel">
- <textarea ref="input" v-model="v"
- :class="{ code, _monospace: code }"
- :required="required"
- :readonly="readonly"
- :pattern="pattern"
- :autocomplete="autocomplete"
- :spellcheck="!code"
- @input="onInput"
- @focus="focused = true"
- @blur="focused = false"
- ></textarea>
- </div>
- </div>
- <template #caption><slot name="desc"></slot></template>
-
- <FormButton v-if="manualSave && changed" primary @click="updated"><i class="fas fa-save"></i> {{ $ts.save }}</FormButton>
-</FormGroup>
-</template>
-
-<script lang="ts">
-import { defineComponent, ref, toRefs, watch } from 'vue';
-import './debobigego.scss';
-import FormButton from './button.vue';
-import FormGroup from './group.vue';
-
-export default defineComponent({
- components: {
- FormGroup,
- FormButton,
- },
- props: {
- modelValue: {
- required: false
- },
- required: {
- type: Boolean,
- required: false
- },
- readonly: {
- type: Boolean,
- required: false
- },
- pattern: {
- type: String,
- required: false
- },
- autocomplete: {
- type: String,
- required: false
- },
- code: {
- type: Boolean,
- required: false
- },
- tall: {
- type: Boolean,
- required: false,
- default: false
- },
- pre: {
- type: Boolean,
- required: false,
- default: false
- },
- manualSave: {
- type: Boolean,
- required: false,
- default: false
- },
- },
- setup(props, context) {
- const { modelValue } = toRefs(props);
- const v = ref(modelValue.value);
- const changed = ref(false);
- const inputEl = ref(null);
- const focus = () => inputEl.value.focus();
- const onInput = (ev) => {
- changed.value = true;
- context.emit('change', ev);
- };
-
- const updated = () => {
- changed.value = false;
- context.emit('update:modelValue', v.value);
- };
-
- watch(modelValue.value, newValue => {
- v.value = newValue;
- });
-
- watch(v, newValue => {
- if (!props.manualSave) {
- updated();
- }
- });
-
- return {
- v,
- updated,
- changed,
- focus,
- onInput,
- };
- }
-});
-</script>
-
-<style lang="scss" scoped>
-.rivhosbp {
- position: relative;
-
- > .input {
- position: relative;
-
- > textarea {
- display: block;
- width: 100%;
- min-width: 100%;
- max-width: 100%;
- min-height: 130px;
- margin: 0;
- padding: 16px;
- box-sizing: border-box;
- font: inherit;
- font-weight: normal;
- font-size: 1em;
- background: transparent;
- border: none;
- border-radius: 0;
- outline: none;
- box-shadow: none;
- color: var(--fg);
-
- &.code {
- tab-size: 2;
- }
- }
- }
-
- &.tall {
- > .input {
- > textarea {
- min-height: 200px;
- }
- }
- }
-
- &.pre {
- > .input {
- > textarea {
- white-space: pre;
- }
- }
- }
-}
-</style>
diff --git a/packages/client/src/components/debobigego/tuple.vue b/packages/client/src/components/debobigego/tuple.vue
deleted file mode 100644
index 1d2a6cb55e..0000000000
--- a/packages/client/src/components/debobigego/tuple.vue
+++ /dev/null
@@ -1,36 +0,0 @@
-<template>
-<div v-size="{ max: [500] }" class="wthhikgt _debobigegoItem">
- <slot></slot>
-</div>
-</template>
-
-<script lang="ts">
-import { defineComponent } from 'vue';
-
-export default defineComponent({
-});
-</script>
-
-<style lang="scss" scoped>
-.wthhikgt {
- position: relative;
- display: flex;
-
- > ::v-deep(*) {
- flex: 1;
- margin: 0;
-
- &:not(:last-child) {
- margin-right: 16px;
- }
- }
-
- &.max-width_500px {
- display: block;
-
- > ::v-deep(*) {
- margin: inherit;
- }
- }
-}
-</style>
diff --git a/packages/client/src/components/dialog.vue b/packages/client/src/components/dialog.vue
index c2fa1b02b8..b6b649cde9 100644
--- a/packages/client/src/components/dialog.vue
+++ b/packages/client/src/components/dialog.vue
@@ -1,5 +1,5 @@
<template>
-<MkModal ref="modal" :prefer-type="'dialog'" :z-priority="'high'" @click="done(true)" @closed="$emit('closed')">
+<MkModal ref="modal" :prefer-type="'dialog'" :z-priority="'high'" @click="done(true)" @closed="emit('closed')">
<div class="mk-dialog">
<div v-if="icon" class="icon">
<i :class="icon"></i>
@@ -14,7 +14,7 @@
</div>
<header v-if="title"><Mfm :text="title"/></header>
<div v-if="text" class="body"><Mfm :text="text"/></div>
- <MkInput v-if="input" v-model="inputValue" autofocus :type="input.type || 'text'" :placeholder="input.placeholder" @keydown="onInputKeydown">
+ <MkInput v-if="input" v-model="inputValue" autofocus :type="input.type || 'text'" :placeholder="input.placeholder || undefined" @keydown="onInputKeydown">
<template v-if="input.type === 'password'" #prefix><i class="fas fa-lock"></i></template>
</MkInput>
<MkSelect v-if="select" v-model="selectedValue" autofocus>
@@ -28,8 +28,8 @@
</template>
</MkSelect>
<div v-if="(showOkButton || showCancelButton) && !actions" class="buttons">
- <MkButton v-if="showOkButton" inline primary :autofocus="!input && !select" @click="ok">{{ (showCancelButton || input || select) ? $ts.ok : $ts.gotIt }}</MkButton>
- <MkButton v-if="showCancelButton || input || select" inline @click="cancel">{{ $ts.cancel }}</MkButton>
+ <MkButton v-if="showOkButton" inline primary :autofocus="!input && !select" @click="ok">{{ (showCancelButton || input || select) ? i18n.locale.ok : i18n.locale.gotIt }}</MkButton>
+ <MkButton v-if="showCancelButton || input || select" inline @click="cancel">{{ i18n.locale.cancel }}</MkButton>
</div>
<div v-if="actions" class="buttons">
<MkButton v-for="action in actions" :key="action.text" inline :primary="action.primary" @click="() => { action.callback(); close(); }">{{ action.text }}</MkButton>
@@ -38,118 +38,108 @@
</MkModal>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
+<script lang="ts" setup>
+import { onBeforeUnmount, onMounted, ref } from 'vue';
import MkModal from '@/components/ui/modal.vue';
import MkButton from '@/components/ui/button.vue';
import MkInput from '@/components/form/input.vue';
import MkSelect from '@/components/form/select.vue';
+import { i18n } from '@/i18n';
-export default defineComponent({
- components: {
- MkModal,
- MkButton,
- MkInput,
- MkSelect,
- },
+type Input = {
+ type: HTMLInputElement['type'];
+ placeholder?: string | null;
+ default: any | null;
+};
- props: {
- type: {
- type: String,
- required: false,
- default: 'info'
- },
- title: {
- type: String,
- required: false
- },
- text: {
- type: String,
- required: false
- },
- input: {
- required: false
- },
- select: {
- required: false
- },
- icon: {
- required: false
- },
- actions: {
- required: false
- },
- showOkButton: {
- type: Boolean,
- default: true
- },
- showCancelButton: {
- type: Boolean,
- default: false
- },
- cancelableByBgClick: {
- type: Boolean,
- default: true
- },
- },
+type Select = {
+ items: {
+ value: string;
+ text: string;
+ }[];
+ groupedItems: {
+ label: string;
+ items: {
+ value: string;
+ text: string;
+ }[];
+ }[];
+ default: string | null;
+};
- emits: ['done', 'closed'],
+const props = withDefaults(defineProps<{
+ type?: 'success' | 'error' | 'warning' | 'info' | 'question' | 'waiting';
+ title: string;
+ text?: string;
+ input?: Input;
+ select?: Select;
+ icon?: string;
+ actions?: {
+ text: string;
+ primary?: boolean,
+ callback: (...args: any[]) => void;
+ }[];
+ showOkButton?: boolean;
+ showCancelButton?: boolean;
+ cancelableByBgClick?: boolean;
+}>(), {
+ type: 'info',
+ showOkButton: true,
+ showCancelButton: false,
+ cancelableByBgClick: true,
+});
- data() {
- return {
- inputValue: this.input && this.input.default ? this.input.default : null,
- selectedValue: this.select ? this.select.default ? this.select.default : this.select.items ? this.select.items[0].value : this.select.groupedItems[0].items[0].value : null,
- };
- },
+const emit = defineEmits<{
+ (e: 'done', v: { canceled: boolean; result: any }): void;
+ (e: 'closed'): void;
+}>();
- mounted() {
- document.addEventListener('keydown', this.onKeydown);
- },
+const modal = ref<InstanceType<typeof MkModal>>();
- beforeUnmount() {
- document.removeEventListener('keydown', this.onKeydown);
- },
+const inputValue = ref(props.input?.default || null);
+const selectedValue = ref(props.select?.default || null);
- methods: {
- done(canceled, result?) {
- this.$emit('done', { canceled, result });
- this.$refs.modal.close();
- },
+function done(canceled: boolean, result?) {
+ emit('done', { canceled, result });
+ modal.value?.close();
+}
- async ok() {
- if (!this.showOkButton) return;
+async function ok() {
+ if (!props.showOkButton) return;
- const result =
- this.input ? this.inputValue :
- this.select ? this.selectedValue :
- true;
- this.done(false, result);
- },
+ const result =
+ props.input ? inputValue.value :
+ props.select ? selectedValue.value :
+ true;
+ done(false, result);
+}
- cancel() {
- this.done(true);
- },
+function cancel() {
+ done(true);
+}
+/*
+function onBgClick() {
+ if (props.cancelableByBgClick) cancel();
+}
+*/
+function onKeydown(e: KeyboardEvent) {
+ if (e.key === 'Escape') cancel();
+}
- onBgClick() {
- if (this.cancelableByBgClick) {
- this.cancel();
- }
- },
+function onInputKeydown(e: KeyboardEvent) {
+ if (e.key === 'Enter') {
+ e.preventDefault();
+ e.stopPropagation();
+ ok();
+ }
+}
- onKeydown(e) {
- if (e.which === 27) { // ESC
- this.cancel();
- }
- },
+onMounted(() => {
+ document.addEventListener('keydown', onKeydown);
+});
- onInputKeydown(e) {
- if (e.which === 13) { // Enter
- e.preventDefault();
- e.stopPropagation();
- this.ok();
- }
- }
- }
+onBeforeUnmount(() => {
+ document.removeEventListener('keydown', onKeydown);
});
</script>
diff --git a/packages/client/src/components/drive-file-thumbnail.vue b/packages/client/src/components/drive-file-thumbnail.vue
index e94b6b8bcb..81b80e7e8e 100644
--- a/packages/client/src/components/drive-file-thumbnail.vue
+++ b/packages/client/src/components/drive-file-thumbnail.vue
@@ -14,71 +14,42 @@
</div>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
+<script lang="ts" setup>
+import { computed } from 'vue';
+import * as Misskey from 'misskey-js';
import ImgWithBlurhash from '@/components/img-with-blurhash.vue';
-import { ColdDeviceStorage } from '@/store';
-export default defineComponent({
- components: {
- ImgWithBlurhash
- },
- props: {
- file: {
- type: Object,
- required: true
- },
- fit: {
- type: String,
- required: false,
- default: 'cover'
- },
- },
- data() {
- return {
- isContextmenuShowing: false,
- isDragging: false,
+const props = defineProps<{
+ file: Misskey.entities.DriveFile;
+ fit: string;
+}>();
- };
- },
- computed: {
- is(): 'image' | 'video' | 'midi' | 'audio' | 'csv' | 'pdf' | 'textfile' | 'archive' | 'unknown' {
- if (this.file.type.startsWith('image/')) return 'image';
- if (this.file.type.startsWith('video/')) return 'video';
- if (this.file.type === 'audio/midi') return 'midi';
- if (this.file.type.startsWith('audio/')) return 'audio';
- if (this.file.type.endsWith('/csv')) return 'csv';
- if (this.file.type.endsWith('/pdf')) return 'pdf';
- if (this.file.type.startsWith('text/')) return 'textfile';
- if ([
- "application/zip",
- "application/x-cpio",
- "application/x-bzip",
- "application/x-bzip2",
- "application/java-archive",
- "application/x-rar-compressed",
- "application/x-tar",
- "application/gzip",
- "application/x-7z-compressed"
- ].some(e => e === this.file.type)) return 'archive';
- return 'unknown';
- },
- isThumbnailAvailable(): boolean {
- return this.file.thumbnailUrl
- ? (this.is === 'image' || this.is === 'video')
- : false;
- },
- },
- mounted() {
- const audioTag = this.$refs.volumectrl as HTMLAudioElement;
- if (audioTag) audioTag.volume = ColdDeviceStorage.get('mediaVolume');
- },
- methods: {
- volumechange() {
- const audioTag = this.$refs.volumectrl as HTMLAudioElement;
- ColdDeviceStorage.set('mediaVolume', audioTag.volume);
- }
- }
+const is = computed(() => {
+ if (props.file.type.startsWith('image/')) return 'image';
+ if (props.file.type.startsWith('video/')) return 'video';
+ if (props.file.type === 'audio/midi') return 'midi';
+ if (props.file.type.startsWith('audio/')) return 'audio';
+ if (props.file.type.endsWith('/csv')) return 'csv';
+ if (props.file.type.endsWith('/pdf')) return 'pdf';
+ if (props.file.type.startsWith('text/')) return 'textfile';
+ if ([
+ "application/zip",
+ "application/x-cpio",
+ "application/x-bzip",
+ "application/x-bzip2",
+ "application/java-archive",
+ "application/x-rar-compressed",
+ "application/x-tar",
+ "application/gzip",
+ "application/x-7z-compressed"
+ ].some(e => e === props.file.type)) return 'archive';
+ return 'unknown';
+});
+
+const isThumbnailAvailable = computed(() => {
+ return props.file.thumbnailUrl
+ ? (is.value === 'image' as const || is.value === 'video')
+ : false;
});
</script>
diff --git a/packages/client/src/components/drive-select-dialog.vue b/packages/client/src/components/drive-select-dialog.vue
index 75537dfe3e..6d84511277 100644
--- a/packages/client/src/components/drive-select-dialog.vue
+++ b/packages/client/src/components/drive-select-dialog.vue
@@ -7,64 +7,51 @@
@click="cancel()"
@close="cancel()"
@ok="ok()"
- @closed="$emit('closed')"
+ @closed="emit('closed')"
>
<template #header>
- {{ multiple ? ((type === 'file') ? $ts.selectFiles : $ts.selectFolders) : ((type === 'file') ? $ts.selectFile : $ts.selectFolder) }}
+ {{ multiple ? ((type === 'file') ? i18n.locale.selectFiles : i18n.locale.selectFolders) : ((type === 'file') ? i18n.locale.selectFile : i18n.locale.selectFolder) }}
<span v-if="selected.length > 0" style="margin-left: 8px; opacity: 0.5;">({{ number(selected.length) }})</span>
</template>
<XDrive :multiple="multiple" :select="type" @changeSelection="onChangeSelection" @selected="ok()"/>
</XModalWindow>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
+<script lang="ts" setup>
+import { ref } from 'vue';
+import * as Misskey from 'misskey-js';
import XDrive from './drive.vue';
import XModalWindow from '@/components/ui/modal-window.vue';
import number from '@/filters/number';
+import { i18n } from '@/i18n';
-export default defineComponent({
- components: {
- XDrive,
- XModalWindow,
- },
-
- props: {
- type: {
- type: String,
- required: false,
- default: 'file'
- },
- multiple: {
- type: Boolean,
- default: false
- }
- },
+withDefaults(defineProps<{
+ type?: 'file' | 'folder';
+ multiple: boolean;
+}>(), {
+ type: 'file',
+});
- emits: ['done', 'closed'],
+const emit = defineEmits<{
+ (e: 'done', r?: Misskey.entities.DriveFile[]): void;
+ (e: 'closed'): void;
+}>();
- data() {
- return {
- selected: []
- };
- },
+const dialog = ref<InstanceType<typeof XModalWindow>>();
- methods: {
- ok() {
- this.$emit('done', this.selected);
- this.$refs.dialog.close();
- },
+const selected = ref<Misskey.entities.DriveFile[]>([]);
- cancel() {
- this.$emit('done');
- this.$refs.dialog.close();
- },
+function ok() {
+ emit('done', selected.value);
+ dialog.value?.close();
+}
- onChangeSelection(xs) {
- this.selected = xs;
- },
+function cancel() {
+ emit('done');
+ dialog.value?.close();
+}
- number
- }
-});
+function onChangeSelection(files: Misskey.entities.DriveFile[]) {
+ selected.value = files;
+}
</script>
diff --git a/packages/client/src/components/drive-window.vue b/packages/client/src/components/drive-window.vue
index 43f07ebe76..8b60bf7794 100644
--- a/packages/client/src/components/drive-window.vue
+++ b/packages/client/src/components/drive-window.vue
@@ -3,42 +3,27 @@
:initial-width="800"
:initial-height="500"
:can-resize="true"
- @closed="$emit('closed')"
+ @closed="emit('closed')"
>
<template #header>
- {{ $ts.drive }}
+ {{ i18n.locale.drive }}
</template>
<XDrive :initial-folder="initialFolder"/>
</XWindow>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
+<script lang="ts" setup>
+import { } from 'vue';
+import * as Misskey from 'misskey-js';
import XDrive from './drive.vue';
import XWindow from '@/components/ui/window.vue';
+import { i18n } from '@/i18n';
-export default defineComponent({
- components: {
- XDrive,
- XWindow,
- },
+defineProps<{
+ initialFolder?: Misskey.entities.DriveFolder;
+}>();
- props: {
- initialFolder: {
- type: Object,
- required: false
- },
- },
-
- emits: ['closed'],
-
- data() {
- return {
- };
- },
-
- methods: {
-
- }
-});
+const emit = defineEmits<{
+ (e: 'closed'): void;
+}>();
</script>
diff --git a/packages/client/src/components/drive.file.vue b/packages/client/src/components/drive.file.vue
index 511647229e..fd6a813838 100644
--- a/packages/client/src/components/drive.file.vue
+++ b/packages/client/src/components/drive.file.vue
@@ -8,17 +8,17 @@
@dragstart="onDragstart"
@dragend="onDragend"
>
- <div v-if="$i.avatarId == file.id" class="label">
+ <div v-if="$i?.avatarId == file.id" class="label">
<img src="/client-assets/label.svg"/>
- <p>{{ $ts.avatar }}</p>
+ <p>{{ i18n.locale.avatar }}</p>
</div>
- <div v-if="$i.bannerId == file.id" class="label">
+ <div v-if="$i?.bannerId == file.id" class="label">
<img src="/client-assets/label.svg"/>
- <p>{{ $ts.banner }}</p>
+ <p>{{ i18n.locale.banner }}</p>
</div>
<div v-if="file.isSensitive" class="label red">
<img src="/client-assets/label-red.svg"/>
- <p>{{ $ts.nsfw }}</p>
+ <p>{{ i18n.locale.nsfw }}</p>
</div>
<MkDriveFileThumbnail class="thumbnail" :file="file" fit="contain"/>
@@ -30,179 +30,155 @@
</div>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
+<script lang="ts" setup>
+import { computed, ref } from 'vue';
+import * as Misskey from 'misskey-js';
import copyToClipboard from '@/scripts/copy-to-clipboard';
import MkDriveFileThumbnail from './drive-file-thumbnail.vue';
import bytes from '@/filters/bytes';
import * as os from '@/os';
+import { i18n } from '@/i18n';
+import { $i } from '@/account';
-export default defineComponent({
- components: {
- MkDriveFileThumbnail
- },
+const props = withDefaults(defineProps<{
+ file: Misskey.entities.DriveFile;
+ isSelected?: boolean;
+ selectMode?: boolean;
+}>(), {
+ isSelected: false,
+ selectMode: false,
+});
- props: {
- file: {
- type: Object,
- required: true,
- },
- isSelected: {
- type: Boolean,
- required: false,
- default: false,
- },
- selectMode: {
- type: Boolean,
- required: false,
- default: false,
- }
- },
+const emit = defineEmits<{
+ (e: 'chosen', r: Misskey.entities.DriveFile): void;
+ (e: 'dragstart'): void;
+ (e: 'dragend'): void;
+}>();
- emits: ['chosen'],
+const isDragging = ref(false);
- data() {
- return {
- isDragging: false
- };
- },
+const title = computed(() => `${props.file.name}\n${props.file.type} ${bytes(props.file.size)}`);
- computed: {
- // TODO: parentへの参照を無くす
- browser(): any {
- return this.$parent;
- },
- title(): string {
- return `${this.file.name}\n${this.file.type} ${bytes(this.file.size)}`;
- }
- },
-
- methods: {
- getMenu() {
- return [{
- text: this.$ts.rename,
- icon: 'fas fa-i-cursor',
- action: this.rename
- }, {
- text: this.file.isSensitive ? this.$ts.unmarkAsSensitive : this.$ts.markAsSensitive,
- icon: this.file.isSensitive ? 'fas fa-eye' : 'fas fa-eye-slash',
- action: this.toggleSensitive
- }, {
- text: this.$ts.describeFile,
- icon: 'fas fa-i-cursor',
- action: this.describe
- }, null, {
- text: this.$ts.copyUrl,
- icon: 'fas fa-link',
- action: this.copyUrl
- }, {
- type: 'a',
- href: this.file.url,
- target: '_blank',
- text: this.$ts.download,
- icon: 'fas fa-download',
- download: this.file.name
- }, null, {
- text: this.$ts.delete,
- icon: 'fas fa-trash-alt',
- danger: true,
- action: this.deleteFile
- }];
- },
+function getMenu() {
+ return [{
+ text: i18n.locale.rename,
+ icon: 'fas fa-i-cursor',
+ action: rename
+ }, {
+ text: props.file.isSensitive ? i18n.locale.unmarkAsSensitive : i18n.locale.markAsSensitive,
+ icon: props.file.isSensitive ? 'fas fa-eye' : 'fas fa-eye-slash',
+ action: toggleSensitive
+ }, {
+ text: i18n.locale.describeFile,
+ icon: 'fas fa-i-cursor',
+ action: describe
+ }, null, {
+ text: i18n.locale.copyUrl,
+ icon: 'fas fa-link',
+ action: copyUrl
+ }, {
+ type: 'a',
+ href: props.file.url,
+ target: '_blank',
+ text: i18n.locale.download,
+ icon: 'fas fa-download',
+ download: props.file.name
+ }, null, {
+ text: i18n.locale.delete,
+ icon: 'fas fa-trash-alt',
+ danger: true,
+ action: deleteFile
+ }];
+}
- onClick(ev) {
- if (this.selectMode) {
- this.$emit('chosen', this.file);
- } else {
- os.popupMenu(this.getMenu(), ev.currentTarget || ev.target);
- }
- },
+function onClick(ev: MouseEvent) {
+ if (props.selectMode) {
+ emit('chosen', props.file);
+ } else {
+ os.popupMenu(getMenu(), (ev.currentTarget || ev.target || undefined) as HTMLElement | undefined);
+ }
+}
- onContextmenu(e) {
- os.contextMenu(this.getMenu(), e);
- },
+function onContextmenu(e: MouseEvent) {
+ os.contextMenu(getMenu(), e);
+}
- onDragstart(e) {
- e.dataTransfer.effectAllowed = 'move';
- e.dataTransfer.setData(_DATA_TRANSFER_DRIVE_FILE_, JSON.stringify(this.file));
- this.isDragging = true;
+function onDragstart(e: DragEvent) {
+ if (e.dataTransfer) {
+ e.dataTransfer.effectAllowed = 'move';
+ e.dataTransfer.setData(_DATA_TRANSFER_DRIVE_FILE_, JSON.stringify(props.file));
+ }
+ isDragging.value = true;
- // 親ブラウザに対して、ドラッグが開始されたフラグを立てる
- // (=あなたの子供が、ドラッグを開始しましたよ)
- this.browser.isDragSource = true;
- },
+ emit('dragstart');
+}
- onDragend(e) {
- this.isDragging = false;
- this.browser.isDragSource = false;
- },
+function onDragend() {
+ isDragging.value = false;
+ emit('dragend');
+}
- rename() {
- os.inputText({
- title: this.$ts.renameFile,
- placeholder: this.$ts.inputNewFileName,
- default: this.file.name,
- allowEmpty: false
- }).then(({ canceled, result: name }) => {
- if (canceled) return;
- os.api('drive/files/update', {
- fileId: this.file.id,
- name: name
- });
- });
- },
+function rename() {
+ os.inputText({
+ title: i18n.locale.renameFile,
+ placeholder: i18n.locale.inputNewFileName,
+ default: props.file.name,
+ }).then(({ canceled, result: name }) => {
+ if (canceled) return;
+ os.api('drive/files/update', {
+ fileId: props.file.id,
+ name: name
+ });
+ });
+}
- describe() {
- os.popup(import('@/components/media-caption.vue'), {
- title: this.$ts.describeFile,
- input: {
- placeholder: this.$ts.inputNewDescription,
- default: this.file.comment !== null ? this.file.comment : '',
- },
- image: this.file
- }, {
- done: result => {
- if (!result || result.canceled) return;
- let comment = result.result;
- os.api('drive/files/update', {
- fileId: this.file.id,
- comment: comment.length == 0 ? null : comment
- });
- }
- }, 'closed');
+function describe() {
+ os.popup(import('@/components/media-caption.vue'), {
+ title: i18n.locale.describeFile,
+ input: {
+ placeholder: i18n.locale.inputNewDescription,
+ default: props.file.comment !== null ? props.file.comment : '',
},
-
- toggleSensitive() {
+ image: props.file
+ }, {
+ done: result => {
+ if (!result || result.canceled) return;
+ let comment = result.result;
os.api('drive/files/update', {
- fileId: this.file.id,
- isSensitive: !this.file.isSensitive
+ fileId: props.file.id,
+ comment: comment.length == 0 ? null : comment
});
- },
-
- copyUrl() {
- copyToClipboard(this.file.url);
- os.success();
- },
-
- addApp() {
- alert('not implemented yet');
- },
+ }
+ }, 'closed');
+}
- async deleteFile() {
- const { canceled } = await os.confirm({
- type: 'warning',
- text: this.$t('driveFileDeleteConfirm', { name: this.file.name }),
- });
- if (canceled) return;
+function toggleSensitive() {
+ os.api('drive/files/update', {
+ fileId: props.file.id,
+ isSensitive: !props.file.isSensitive
+ });
+}
- os.api('drive/files/delete', {
- fileId: this.file.id
- });
- },
+function copyUrl() {
+ copyToClipboard(props.file.url);
+ os.success();
+}
+/*
+function addApp() {
+ alert('not implemented yet');
+}
+*/
+async function deleteFile() {
+ const { canceled } = await os.confirm({
+ type: 'warning',
+ text: i18n.t('driveFileDeleteConfirm', { name: props.file.name }),
+ });
- bytes
- }
-});
+ if (canceled) return;
+ os.api('drive/files/delete', {
+ fileId: props.file.id
+ });
+}
</script>
<style lang="scss" scoped>
diff --git a/packages/client/src/components/drive.folder.vue b/packages/client/src/components/drive.folder.vue
index aaba736cf8..20a6343cfe 100644
--- a/packages/client/src/components/drive.folder.vue
+++ b/packages/client/src/components/drive.folder.vue
@@ -19,243 +19,233 @@
<template v-if="!hover"><i class="fas fa-folder fa-fw"></i></template>
{{ folder.name }}
</p>
- <p v-if="$store.state.uploadFolder == folder.id" class="upload">
- {{ $ts.uploadFolder }}
+ <p v-if="defaultStore.state.uploadFolder == folder.id" class="upload">
+ {{ i18n.locale.uploadFolder }}
</p>
<button v-if="selectMode" class="checkbox _button" :class="{ checked: isSelected }" @click.prevent.stop="checkboxClicked"></button>
</div>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
+<script lang="ts" setup>
+import { computed, ref } from 'vue';
+import * as Misskey from 'misskey-js';
import * as os from '@/os';
+import { i18n } from '@/i18n';
+import { defaultStore } from '@/store';
-export default defineComponent({
- props: {
- folder: {
- type: Object,
- required: true,
- },
- isSelected: {
- type: Boolean,
- required: false,
- default: false,
- },
- selectMode: {
- type: Boolean,
- required: false,
- default: false,
- }
- },
+const props = withDefaults(defineProps<{
+ folder: Misskey.entities.DriveFolder;
+ isSelected?: boolean;
+ selectMode?: boolean;
+}>(), {
+ isSelected: false,
+ selectMode: false,
+});
- emits: ['chosen'],
+const emit = defineEmits<{
+ (ev: 'chosen', v: Misskey.entities.DriveFolder): void;
+ (ev: 'move', v: Misskey.entities.DriveFolder): void;
+ (ev: 'upload', file: File, folder: Misskey.entities.DriveFolder);
+ (ev: 'removeFile', v: Misskey.entities.DriveFile['id']): void;
+ (ev: 'removeFolder', v: Misskey.entities.DriveFolder['id']): void;
+ (ev: 'dragstart'): void;
+ (ev: 'dragend'): void;
+}>();
- data() {
- return {
- hover: false,
- draghover: false,
- isDragging: false,
- };
- },
+const hover = ref(false);
+const draghover = ref(false);
+const isDragging = ref(false);
- computed: {
- browser(): any {
- return this.$parent;
- },
- title(): string {
- return this.folder.name;
- }
- },
+const title = computed(() => props.folder.name);
- methods: {
- checkboxClicked(e) {
- this.$emit('chosen', this.folder);
- },
+function checkboxClicked() {
+ emit('chosen', props.folder);
+}
- onClick() {
- this.browser.move(this.folder);
- },
+function onClick() {
+ emit('move', props.folder);
+}
- onMouseover() {
- this.hover = true;
- },
+function onMouseover() {
+ hover.value = true;
+}
- onMouseout() {
- this.hover = false
- },
+function onMouseout() {
+ hover.value = false
+}
- onDragover(e) {
- // 自分自身がドラッグされている場合
- if (this.isDragging) {
- // 自分自身にはドロップさせない
- e.dataTransfer.dropEffect = 'none';
- return;
- }
+function onDragover(ev: DragEvent) {
+ if (!ev.dataTransfer) return;
- const isFile = e.dataTransfer.items[0].kind == 'file';
- const isDriveFile = e.dataTransfer.types[0] == _DATA_TRANSFER_DRIVE_FILE_;
- const isDriveFolder = e.dataTransfer.types[0] == _DATA_TRANSFER_DRIVE_FOLDER_;
+ // 自分自身がドラッグされている場合
+ if (isDragging.value) {
+ // 自分自身にはドロップさせない
+ ev.dataTransfer.dropEffect = 'none';
+ return;
+ }
- if (isFile || isDriveFile || isDriveFolder) {
- e.dataTransfer.dropEffect = e.dataTransfer.effectAllowed == 'all' ? 'copy' : 'move';
- } else {
- e.dataTransfer.dropEffect = 'none';
- }
- },
+ const isFile = ev.dataTransfer.items[0].kind == 'file';
+ const isDriveFile = ev.dataTransfer.types[0] == _DATA_TRANSFER_DRIVE_FILE_;
+ const isDriveFolder = ev.dataTransfer.types[0] == _DATA_TRANSFER_DRIVE_FOLDER_;
- onDragenter() {
- if (!this.isDragging) this.draghover = true;
- },
+ if (isFile || isDriveFile || isDriveFolder) {
+ ev.dataTransfer.dropEffect = ev.dataTransfer.effectAllowed == 'all' ? 'copy' : 'move';
+ } else {
+ ev.dataTransfer.dropEffect = 'none';
+ }
+}
- onDragleave() {
- this.draghover = false;
- },
+function onDragenter() {
+ if (!isDragging.value) draghover.value = true;
+}
- onDrop(e) {
- this.draghover = false;
+function onDragleave() {
+ draghover.value = false;
+}
- // ファイルだったら
- if (e.dataTransfer.files.length > 0) {
- for (const file of Array.from(e.dataTransfer.files)) {
- this.browser.upload(file, this.folder);
- }
- return;
- }
+function onDrop(ev: DragEvent) {
+ draghover.value = false;
- //#region ドライブのファイル
- const driveFile = e.dataTransfer.getData(_DATA_TRANSFER_DRIVE_FILE_);
- if (driveFile != null && driveFile != '') {
- const file = JSON.parse(driveFile);
- this.browser.removeFile(file.id);
- os.api('drive/files/update', {
- fileId: file.id,
- folderId: this.folder.id
- });
- }
- //#endregion
+ if (!ev.dataTransfer) return;
+
+ // ファイルだったら
+ if (ev.dataTransfer.files.length > 0) {
+ for (const file of Array.from(ev.dataTransfer.files)) {
+ emit('upload', file, props.folder);
+ }
+ return;
+ }
- //#region ドライブのフォルダ
- const driveFolder = e.dataTransfer.getData(_DATA_TRANSFER_DRIVE_FOLDER_);
- if (driveFolder != null && driveFolder != '') {
- const folder = JSON.parse(driveFolder);
+ //#region ドライブのファイル
+ const driveFile = ev.dataTransfer.getData(_DATA_TRANSFER_DRIVE_FILE_);
+ if (driveFile != null && driveFile != '') {
+ const file = JSON.parse(driveFile);
+ emit('removeFile', file.id);
+ os.api('drive/files/update', {
+ fileId: file.id,
+ folderId: props.folder.id
+ });
+ }
+ //#endregion
- // 移動先が自分自身ならreject
- if (folder.id == this.folder.id) return;
+ //#region ドライブのフォルダ
+ const driveFolder = ev.dataTransfer.getData(_DATA_TRANSFER_DRIVE_FOLDER_);
+ if (driveFolder != null && driveFolder != '') {
+ const folder = JSON.parse(driveFolder);
- this.browser.removeFolder(folder.id);
- os.api('drive/folders/update', {
- folderId: folder.id,
- parentId: this.folder.id
- }).then(() => {
- // noop
- }).catch(err => {
- switch (err) {
- case 'detected-circular-definition':
- os.alert({
- title: this.$ts.unableToProcess,
- text: this.$ts.circularReferenceFolder
- });
- break;
- default:
- os.alert({
- type: 'error',
- text: this.$ts.somethingHappened
- });
- }
- });
+ // 移動先が自分自身ならreject
+ if (folder.id == props.folder.id) return;
+
+ emit('removeFolder', folder.id);
+ os.api('drive/folders/update', {
+ folderId: folder.id,
+ parentId: props.folder.id
+ }).then(() => {
+ // noop
+ }).catch(err => {
+ switch (err) {
+ case 'detected-circular-definition':
+ os.alert({
+ title: i18n.locale.unableToProcess,
+ text: i18n.locale.circularReferenceFolder
+ });
+ break;
+ default:
+ os.alert({
+ type: 'error',
+ text: i18n.locale.somethingHappened
+ });
}
- //#endregion
- },
+ });
+ }
+ //#endregion
+}
- onDragstart(e) {
- e.dataTransfer.effectAllowed = 'move';
- e.dataTransfer.setData(_DATA_TRANSFER_DRIVE_FOLDER_, JSON.stringify(this.folder));
- this.isDragging = true;
+function onDragstart(ev: DragEvent) {
+ if (!ev.dataTransfer) return;
- // 親ブラウザに対して、ドラッグが開始されたフラグを立てる
- // (=あなたの子供が、ドラッグを開始しましたよ)
- this.browser.isDragSource = true;
- },
+ ev.dataTransfer.effectAllowed = 'move';
+ ev.dataTransfer.setData(_DATA_TRANSFER_DRIVE_FOLDER_, JSON.stringify(props.folder));
+ isDragging.value = true;
- onDragend() {
- this.isDragging = false;
- this.browser.isDragSource = false;
- },
+ // 親ブラウザに対して、ドラッグが開始されたフラグを立てる
+ // (=あなたの子供が、ドラッグを開始しましたよ)
+ emit('dragstart');
+}
- go() {
- this.browser.move(this.folder.id);
- },
+function onDragend() {
+ isDragging.value = false;
+ emit('dragend');
+}
- newWindow() {
- this.browser.newWindow(this.folder);
- },
+function go() {
+ emit('move', props.folder.id);
+}
- rename() {
- os.inputText({
- title: this.$ts.renameFolder,
- placeholder: this.$ts.inputNewFolderName,
- default: this.folder.name
- }).then(({ canceled, result: name }) => {
- if (canceled) return;
- os.api('drive/folders/update', {
- folderId: this.folder.id,
- name: name
- });
- });
- },
+function rename() {
+ os.inputText({
+ title: i18n.locale.renameFolder,
+ placeholder: i18n.locale.inputNewFolderName,
+ default: props.folder.name
+ }).then(({ canceled, result: name }) => {
+ if (canceled) return;
+ os.api('drive/folders/update', {
+ folderId: props.folder.id,
+ name: name
+ });
+ });
+}
- deleteFolder() {
- os.api('drive/folders/delete', {
- folderId: this.folder.id
- }).then(() => {
- if (this.$store.state.uploadFolder === this.folder.id) {
- this.$store.set('uploadFolder', null);
- }
- }).catch(err => {
- switch(err.id) {
- case 'b0fc8a17-963c-405d-bfbc-859a487295e1':
- os.alert({
- type: 'error',
- title: this.$ts.unableToDelete,
- text: this.$ts.hasChildFilesOrFolders
- });
- break;
- default:
- os.alert({
- type: 'error',
- text: this.$ts.unableToDelete
- });
- }
- });
- },
+function deleteFolder() {
+ os.api('drive/folders/delete', {
+ folderId: props.folder.id
+ }).then(() => {
+ if (defaultStore.state.uploadFolder === props.folder.id) {
+ defaultStore.set('uploadFolder', null);
+ }
+ }).catch(err => {
+ switch(err.id) {
+ case 'b0fc8a17-963c-405d-bfbc-859a487295e1':
+ os.alert({
+ type: 'error',
+ title: i18n.locale.unableToDelete,
+ text: i18n.locale.hasChildFilesOrFolders
+ });
+ break;
+ default:
+ os.alert({
+ type: 'error',
+ text: i18n.locale.unableToDelete
+ });
+ }
+ });
+}
- setAsUploadFolder() {
- this.$store.set('uploadFolder', this.folder.id);
- },
+function setAsUploadFolder() {
+ defaultStore.set('uploadFolder', props.folder.id);
+}
- onContextmenu(e) {
- os.contextMenu([{
- text: this.$ts.openInWindow,
- icon: 'fas fa-window-restore',
- action: () => {
- os.popup(import('./drive-window.vue'), {
- initialFolder: this.folder
- }, {
- }, 'closed');
- }
- }, null, {
- text: this.$ts.rename,
- icon: 'fas fa-i-cursor',
- action: this.rename
- }, null, {
- text: this.$ts.delete,
- icon: 'fas fa-trash-alt',
- danger: true,
- action: this.deleteFolder
- }], e);
- },
- }
-});
+function onContextmenu(ev: MouseEvent) {
+ os.contextMenu([{
+ text: i18n.locale.openInWindow,
+ icon: 'fas fa-window-restore',
+ action: () => {
+ os.popup(import('./drive-window.vue'), {
+ initialFolder: props.folder
+ }, {
+ }, 'closed');
+ }
+ }, null, {
+ text: i18n.locale.rename,
+ icon: 'fas fa-i-cursor',
+ action: rename,
+ }, null, {
+ text: i18n.locale.delete,
+ icon: 'fas fa-trash-alt',
+ danger: true,
+ action: deleteFolder,
+ }], ev);
+}
</script>
<style lang="scss" scoped>
diff --git a/packages/client/src/components/drive.nav-folder.vue b/packages/client/src/components/drive.nav-folder.vue
index 4f0e6ce0e9..7c35c5d3da 100644
--- a/packages/client/src/components/drive.nav-folder.vue
+++ b/packages/client/src/components/drive.nav-folder.vue
@@ -8,114 +8,111 @@
@drop.stop="onDrop"
>
<i v-if="folder == null" class="fas fa-cloud"></i>
- <span>{{ folder == null ? $ts.drive : folder.name }}</span>
+ <span>{{ folder == null ? i18n.locale.drive : folder.name }}</span>
</div>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
+<script lang="ts" setup>
+import { ref } from 'vue';
+import * as Misskey from 'misskey-js';
import * as os from '@/os';
+import { i18n } from '@/i18n';
-export default defineComponent({
- props: {
- folder: {
- type: Object,
- required: false,
- }
- },
+const props = defineProps<{
+ folder?: Misskey.entities.DriveFolder;
+ parentFolder: Misskey.entities.DriveFolder | null;
+}>();
- data() {
- return {
- hover: false,
- draghover: false,
- };
- },
+const emit = defineEmits<{
+ (e: 'move', v?: Misskey.entities.DriveFolder): void;
+ (e: 'upload', file: File, folder?: Misskey.entities.DriveFolder | null): void;
+ (e: 'removeFile', v: Misskey.entities.DriveFile['id']): void;
+ (e: 'removeFolder', v: Misskey.entities.DriveFolder['id']): void;
+}>();
- computed: {
- browser(): any {
- return this.$parent;
- }
- },
+const hover = ref(false);
+const draghover = ref(false);
- methods: {
- onClick() {
- this.browser.move(this.folder);
- },
+function onClick() {
+ emit('move', props.folder);
+}
- onMouseover() {
- this.hover = true;
- },
+function onMouseover() {
+ hover.value = true;
+}
- onMouseout() {
- this.hover = false;
- },
+function onMouseout() {
+ hover.value = false;
+}
- onDragover(e) {
- // このフォルダがルートかつカレントディレクトリならドロップ禁止
- if (this.folder == null && this.browser.folder == null) {
- e.dataTransfer.dropEffect = 'none';
- }
+function onDragover(e: DragEvent) {
+ if (!e.dataTransfer) return;
- const isFile = e.dataTransfer.items[0].kind == 'file';
- const isDriveFile = e.dataTransfer.types[0] == _DATA_TRANSFER_DRIVE_FILE_;
- const isDriveFolder = e.dataTransfer.types[0] == _DATA_TRANSFER_DRIVE_FOLDER_;
+ // このフォルダがルートかつカレントディレクトリならドロップ禁止
+ if (props.folder == null && props.parentFolder == null) {
+ e.dataTransfer.dropEffect = 'none';
+ }
- if (isFile || isDriveFile || isDriveFolder) {
- e.dataTransfer.dropEffect = e.dataTransfer.effectAllowed == 'all' ? 'copy' : 'move';
- } else {
- e.dataTransfer.dropEffect = 'none';
- }
+ const isFile = e.dataTransfer.items[0].kind == 'file';
+ const isDriveFile = e.dataTransfer.types[0] == _DATA_TRANSFER_DRIVE_FILE_;
+ const isDriveFolder = e.dataTransfer.types[0] == _DATA_TRANSFER_DRIVE_FOLDER_;
- return false;
- },
+ if (isFile || isDriveFile || isDriveFolder) {
+ e.dataTransfer.dropEffect = e.dataTransfer.effectAllowed == 'all' ? 'copy' : 'move';
+ } else {
+ e.dataTransfer.dropEffect = 'none';
+ }
- onDragenter() {
- if (this.folder || this.browser.folder) this.draghover = true;
- },
+ return false;
+}
- onDragleave() {
- if (this.folder || this.browser.folder) this.draghover = false;
- },
+function onDragenter() {
+ if (props.folder || props.parentFolder) draghover.value = true;
+}
- onDrop(e) {
- this.draghover = false;
+function onDragleave() {
+ if (props.folder || props.parentFolder) draghover.value = false;
+}
- // ファイルだったら
- if (e.dataTransfer.files.length > 0) {
- for (const file of Array.from(e.dataTransfer.files)) {
- this.browser.upload(file, this.folder);
- }
- return;
- }
+function onDrop(e: DragEvent) {
+ draghover.value = false;
- //#region ドライブのファイル
- const driveFile = e.dataTransfer.getData(_DATA_TRANSFER_DRIVE_FILE_);
- if (driveFile != null && driveFile != '') {
- const file = JSON.parse(driveFile);
- this.browser.removeFile(file.id);
- os.api('drive/files/update', {
- fileId: file.id,
- folderId: this.folder ? this.folder.id : null
- });
- }
- //#endregion
+ if (!e.dataTransfer) return;
- //#region ドライブのフォルダ
- const driveFolder = e.dataTransfer.getData(_DATA_TRANSFER_DRIVE_FOLDER_);
- if (driveFolder != null && driveFolder != '') {
- const folder = JSON.parse(driveFolder);
- // 移動先が自分自身ならreject
- if (this.folder && folder.id == this.folder.id) return;
- this.browser.removeFolder(folder.id);
- os.api('drive/folders/update', {
- folderId: folder.id,
- parentId: this.folder ? this.folder.id : null
- });
- }
- //#endregion
+ // ファイルだったら
+ if (e.dataTransfer.files.length > 0) {
+ for (const file of Array.from(e.dataTransfer.files)) {
+ emit('upload', file, props.folder);
}
+ return;
+ }
+
+ //#region ドライブのファイル
+ const driveFile = e.dataTransfer.getData(_DATA_TRANSFER_DRIVE_FILE_);
+ if (driveFile != null && driveFile != '') {
+ const file = JSON.parse(driveFile);
+ emit('removeFile', file.id);
+ os.api('drive/files/update', {
+ fileId: file.id,
+ folderId: props.folder ? props.folder.id : null
+ });
}
-});
+ //#endregion
+
+ //#region ドライブのフォルダ
+ const driveFolder = e.dataTransfer.getData(_DATA_TRANSFER_DRIVE_FOLDER_);
+ if (driveFolder != null && driveFolder != '') {
+ const folder = JSON.parse(driveFolder);
+ // 移動先が自分自身ならreject
+ if (props.folder && folder.id == props.folder.id) return;
+ emit('removeFolder', folder.id);
+ os.api('drive/folders/update', {
+ folderId: folder.id,
+ parentId: props.folder ? props.folder.id : null
+ });
+ }
+ //#endregion
+}
</script>
<style lang="scss" scoped>
diff --git a/packages/client/src/components/drive.vue b/packages/client/src/components/drive.vue
index 46bcd42558..e27b0a5fbb 100644
--- a/packages/client/src/components/drive.vue
+++ b/packages/client/src/components/drive.vue
@@ -2,10 +2,24 @@
<div class="yfudmmck">
<nav>
<div class="path" @contextmenu.prevent.stop="() => {}">
- <XNavFolder :class="{ current: folder == null }"/>
+ <XNavFolder
+ :class="{ current: folder == null }"
+ :parent-folder="folder"
+ @move="move"
+ @upload="upload"
+ @removeFile="removeFile"
+ @removeFolder="removeFolder"
+ />
<template v-for="f in hierarchyFolders">
<span class="separator"><i class="fas fa-angle-right"></i></span>
- <XNavFolder :folder="f"/>
+ <XNavFolder
+ :folder="f"
+ :parent-folder="folder"
+ @move="move"
+ @upload="upload"
+ @removeFile="removeFile"
+ @removeFolder="removeFolder"
+ />
</template>
<span v-if="folder != null" class="separator"><i class="fas fa-angle-right"></i></span>
<span v-if="folder != null" class="folder current">{{ folder.name }}</span>
@@ -22,616 +36,601 @@
>
<div ref="contents" class="contents">
<div v-show="folders.length > 0" ref="foldersContainer" class="folders">
- <XFolder v-for="(f, i) in folders" :key="f.id" v-anim="i" class="folder" :folder="f" :select-mode="select === 'folder'" :is-selected="selectedFolders.some(x => x.id === f.id)" @chosen="chooseFolder"/>
+ <XFolder
+ v-for="(f, i) in folders"
+ :key="f.id"
+ v-anim="i"
+ class="folder"
+ :folder="f"
+ :select-mode="select === 'folder'"
+ :is-selected="selectedFolders.some(x => x.id === f.id)"
+ @chosen="chooseFolder"
+ @move="move"
+ @upload="upload"
+ @removeFile="removeFile"
+ @removeFolder="removeFolder"
+ @dragstart="isDragSource = true"
+ @dragend="isDragSource = false"
+ />
<!-- SEE: https://stackoverflow.com/questions/18744164/flex-box-align-last-row-to-grid -->
<div v-for="(n, i) in 16" :key="i" class="padding"></div>
- <MkButton v-if="moreFolders" ref="moreFolders">{{ $ts.loadMore }}</MkButton>
+ <MkButton v-if="moreFolders" ref="moreFolders">{{ i18n.locale.loadMore }}</MkButton>
</div>
<div v-show="files.length > 0" ref="filesContainer" class="files">
- <XFile v-for="(file, i) in files" :key="file.id" v-anim="i" class="file" :file="file" :select-mode="select === 'file'" :is-selected="selectedFiles.some(x => x.id === file.id)" @chosen="chooseFile"/>
+ <XFile
+ v-for="(file, i) in files"
+ :key="file.id"
+ v-anim="i"
+ class="file"
+ :file="file"
+ :select-mode="select === 'file'"
+ :is-selected="selectedFiles.some(x => x.id === file.id)"
+ @chosen="chooseFile"
+ @dragstart="isDragSource = true"
+ @dragend="isDragSource = false"
+ />
<!-- SEE: https://stackoverflow.com/questions/18744164/flex-box-align-last-row-to-grid -->
<div v-for="(n, i) in 16" :key="i" class="padding"></div>
- <MkButton v-show="moreFiles" ref="loadMoreFiles" @click="fetchMoreFiles">{{ $ts.loadMore }}</MkButton>
+ <MkButton v-show="moreFiles" ref="loadMoreFiles" @click="fetchMoreFiles">{{ i18n.locale.loadMore }}</MkButton>
</div>
<div v-if="files.length == 0 && folders.length == 0 && !fetching" class="empty">
- <p v-if="draghover">{{ $t('empty-draghover') }}</p>
- <p v-if="!draghover && folder == null"><strong>{{ $ts.emptyDrive }}</strong><br/>{{ $t('empty-drive-description') }}</p>
- <p v-if="!draghover && folder != null">{{ $ts.emptyFolder }}</p>
+ <p v-if="draghover">{{ i18n.t('empty-draghover') }}</p>
+ <p v-if="!draghover && folder == null"><strong>{{ i18n.locale.emptyDrive }}</strong><br/>{{ i18n.t('empty-drive-description') }}</p>
+ <p v-if="!draghover && folder != null">{{ i18n.locale.emptyFolder }}</p>
</div>
</div>
<MkLoading v-if="fetching"/>
</div>
<div v-if="draghover" class="dropzone"></div>
- <input ref="fileInput" type="file" accept="*/*" multiple="multiple" tabindex="-1" @change="onChangeFileInput"/>
+ <input ref="fileInput" type="file" accept="*/*" multiple tabindex="-1" @change="onChangeFileInput"/>
</div>
</template>
-<script lang="ts">
-import { defineComponent, markRaw } from 'vue';
+<script lang="ts" setup>
+import { markRaw, nextTick, onActivated, onBeforeUnmount, onMounted, ref, watch } from 'vue';
+import * as Misskey from 'misskey-js';
import XNavFolder from './drive.nav-folder.vue';
import XFolder from './drive.folder.vue';
import XFile from './drive.file.vue';
import MkButton from './ui/button.vue';
import * as os from '@/os';
+import { stream } from '@/stream';
+import { defaultStore } from '@/store';
+import { i18n } from '@/i18n';
-export default defineComponent({
- components: {
- XNavFolder,
- XFolder,
- XFile,
- MkButton,
- },
-
- props: {
- initialFolder: {
- type: Object,
- required: false
- },
- type: {
- type: String,
- required: false,
- default: undefined
- },
- multiple: {
- type: Boolean,
- required: false,
- default: false
- },
- select: {
- type: String,
- required: false,
- default: null
- }
- },
-
- emits: ['selected', 'change-selection', 'move-root', 'cd', 'open-folder'],
-
- data() {
- return {
- /**
- * 現在の階層(フォルダ)
- * * null でルートを表す
- */
- folder: null,
+const props = withDefaults(defineProps<{
+ initialFolder?: Misskey.entities.DriveFolder;
+ type?: string;
+ multiple?: boolean;
+ select?: 'file' | 'folder' | null;
+}>(), {
+ multiple: false,
+ select: null,
+});
- files: [],
- folders: [],
- moreFiles: false,
- moreFolders: false,
- hierarchyFolders: [],
- selectedFiles: [],
- selectedFolders: [],
- uploadings: os.uploads,
- connection: null,
+const emit = defineEmits<{
+ (e: 'selected', v: Misskey.entities.DriveFile | Misskey.entities.DriveFolder): void;
+ (e: 'change-selection', v: Misskey.entities.DriveFile[] | Misskey.entities.DriveFolder[]): void;
+ (e: 'move-root'): void;
+ (e: 'cd', v: Misskey.entities.DriveFolder | null): void;
+ (e: 'open-folder', v: Misskey.entities.DriveFolder): void;
+}>();
- /**
- * ドロップされようとしているか
- */
- draghover: false,
+const loadMoreFiles = ref<InstanceType<typeof MkButton>>();
+const fileInput = ref<HTMLInputElement>();
- /**
- * 自信の所有するアイテムがドラッグをスタートさせたか
- * (自分自身の階層にドロップできないようにするためのフラグ)
- */
- isDragSource: false,
+const folder = ref<Misskey.entities.DriveFolder | null>(null);
+const files = ref<Misskey.entities.DriveFile[]>([]);
+const folders = ref<Misskey.entities.DriveFolder[]>([]);
+const moreFiles = ref(false);
+const moreFolders = ref(false);
+const hierarchyFolders = ref<Misskey.entities.DriveFolder[]>([]);
+const selectedFiles = ref<Misskey.entities.DriveFile[]>([]);
+const selectedFolders = ref<Misskey.entities.DriveFolder[]>([]);
+const uploadings = os.uploads;
+const connection = stream.useChannel('drive');
- fetching: true,
+// ドロップされようとしているか
+const draghover = ref(false);
- ilFilesObserver: new IntersectionObserver(
- (entries) => entries.some((entry) => entry.isIntersecting)
- && !this.fetching && this.moreFiles &&
- this.fetchMoreFiles()
- ),
- moreFilesElement: null as Element,
+// 自身の所有するアイテムがドラッグをスタートさせたか
+// (自分自身の階層にドロップできないようにするためのフラグ)
+const isDragSource = ref(false);
- };
- },
+const fetching = ref(true);
- watch: {
- folder() {
- this.$emit('cd', this.folder);
- }
- },
+const ilFilesObserver = new IntersectionObserver(
+ (entries) => entries.some((entry) => entry.isIntersecting) && !fetching.value && moreFiles.value && fetchMoreFiles()
+)
- mounted() {
- if (this.$store.state.enableInfiniteScroll && this.$refs.loadMoreFiles) {
- this.$nextTick(() => {
- this.ilFilesObserver.observe((this.$refs.loadMoreFiles as Vue).$el)
- });
- }
+watch(folder, () => emit('cd', folder.value));
- this.connection = markRaw(os.stream.useChannel('drive'));
-
- this.connection.on('fileCreated', this.onStreamDriveFileCreated);
- this.connection.on('fileUpdated', this.onStreamDriveFileUpdated);
- this.connection.on('fileDeleted', this.onStreamDriveFileDeleted);
- this.connection.on('folderCreated', this.onStreamDriveFolderCreated);
- this.connection.on('folderUpdated', this.onStreamDriveFolderUpdated);
- this.connection.on('folderDeleted', this.onStreamDriveFolderDeleted);
+function onStreamDriveFileCreated(file: Misskey.entities.DriveFile) {
+ addFile(file, true);
+}
- if (this.initialFolder) {
- this.move(this.initialFolder);
- } else {
- this.fetch();
- }
- },
+function onStreamDriveFileUpdated(file: Misskey.entities.DriveFile) {
+ const current = folder.value ? folder.value.id : null;
+ if (current != file.folderId) {
+ removeFile(file);
+ } else {
+ addFile(file, true);
+ }
+}
- activated() {
- if (this.$store.state.enableInfiniteScroll) {
- this.$nextTick(() => {
- this.ilFilesObserver.observe((this.$refs.loadMoreFiles as Vue).$el)
- });
- }
- },
+function onStreamDriveFileDeleted(fileId: string) {
+ removeFile(fileId);
+}
- beforeUnmount() {
- this.connection.dispose();
- this.ilFilesObserver.disconnect();
- },
+function onStreamDriveFolderCreated(createdFolder: Misskey.entities.DriveFolder) {
+ addFolder(createdFolder, true);
+}
- methods: {
- onStreamDriveFileCreated(file) {
- this.addFile(file, true);
- },
+function onStreamDriveFolderUpdated(updatedFolder: Misskey.entities.DriveFolder) {
+ const current = folder.value ? folder.value.id : null;
+ if (current != updatedFolder.parentId) {
+ removeFolder(updatedFolder);
+ } else {
+ addFolder(updatedFolder, true);
+ }
+}
- onStreamDriveFileUpdated(file) {
- const current = this.folder ? this.folder.id : null;
- if (current != file.folderId) {
- this.removeFile(file);
- } else {
- this.addFile(file, true);
- }
- },
+function onStreamDriveFolderDeleted(folderId: string) {
+ removeFolder(folderId);
+}
- onStreamDriveFileDeleted(fileId) {
- this.removeFile(fileId);
- },
+function onDragover(e: DragEvent): any {
+ if (!e.dataTransfer) return;
- onStreamDriveFolderCreated(folder) {
- this.addFolder(folder, true);
- },
+ // ドラッグ元が自分自身の所有するアイテムだったら
+ if (isDragSource.value) {
+ // 自分自身にはドロップさせない
+ e.dataTransfer.dropEffect = 'none';
+ return;
+ }
- onStreamDriveFolderUpdated(folder) {
- const current = this.folder ? this.folder.id : null;
- if (current != folder.parentId) {
- this.removeFolder(folder);
- } else {
- this.addFolder(folder, true);
- }
- },
+ const isFile = e.dataTransfer.items[0].kind == 'file';
+ const isDriveFile = e.dataTransfer.types[0] == _DATA_TRANSFER_DRIVE_FILE_;
+ const isDriveFolder = e.dataTransfer.types[0] == _DATA_TRANSFER_DRIVE_FOLDER_;
+ if (isFile || isDriveFile || isDriveFolder) {
+ e.dataTransfer.dropEffect = e.dataTransfer.effectAllowed == 'all' ? 'copy' : 'move';
+ } else {
+ e.dataTransfer.dropEffect = 'none';
+ }
- onStreamDriveFolderDeleted(folderId) {
- this.removeFolder(folderId);
- },
+ return false;
+}
- onDragover(e): any {
- // ドラッグ元が自分自身の所有するアイテムだったら
- if (this.isDragSource) {
- // 自分自身にはドロップさせない
- e.dataTransfer.dropEffect = 'none';
- return;
- }
+function onDragenter() {
+ if (!isDragSource.value) draghover.value = true;
+}
- const isFile = e.dataTransfer.items[0].kind == 'file';
- const isDriveFile = e.dataTransfer.types[0] == _DATA_TRANSFER_DRIVE_FILE_;
- const isDriveFolder = e.dataTransfer.types[0] == _DATA_TRANSFER_DRIVE_FOLDER_;
+function onDragleave() {
+ draghover.value = false;
+}
- if (isFile || isDriveFile || isDriveFolder) {
- e.dataTransfer.dropEffect = e.dataTransfer.effectAllowed == 'all' ? 'copy' : 'move';
- } else {
- e.dataTransfer.dropEffect = 'none';
- }
+function onDrop(e: DragEvent): any {
+ draghover.value = false;
- return false;
- },
+ if (!e.dataTransfer) return;
- onDragenter(e) {
- if (!this.isDragSource) this.draghover = true;
- },
+ // ドロップされてきたものがファイルだったら
+ if (e.dataTransfer.files.length > 0) {
+ for (const file of Array.from(e.dataTransfer.files)) {
+ upload(file, folder.value);
+ }
+ return;
+ }
- onDragleave(e) {
- this.draghover = false;
- },
+ //#region ドライブのファイル
+ const driveFile = e.dataTransfer.getData(_DATA_TRANSFER_DRIVE_FILE_);
+ if (driveFile != null && driveFile != '') {
+ const file = JSON.parse(driveFile);
+ if (files.value.some(f => f.id == file.id)) return;
+ removeFile(file.id);
+ os.api('drive/files/update', {
+ fileId: file.id,
+ folderId: folder.value ? folder.value.id : null
+ });
+ }
+ //#endregion
- onDrop(e): any {
- this.draghover = false;
+ //#region ドライブのフォルダ
+ const driveFolder = e.dataTransfer.getData(_DATA_TRANSFER_DRIVE_FOLDER_);
+ if (driveFolder != null && driveFolder != '') {
+ const droppedFolder = JSON.parse(driveFolder);
- // ドロップされてきたものがファイルだったら
- if (e.dataTransfer.files.length > 0) {
- for (const file of Array.from(e.dataTransfer.files)) {
- this.upload(file, this.folder);
- }
- return;
+ // 移動先が自分自身ならreject
+ if (folder.value && droppedFolder.id == folder.value.id) return false;
+ if (folders.value.some(f => f.id == droppedFolder.id)) return false;
+ removeFolder(droppedFolder.id);
+ os.api('drive/folders/update', {
+ folderId: droppedFolder.id,
+ parentId: folder.value ? folder.value.id : null
+ }).then(() => {
+ // noop
+ }).catch(err => {
+ switch (err) {
+ case 'detected-circular-definition':
+ os.alert({
+ title: i18n.locale.unableToProcess,
+ text: i18n.locale.circularReferenceFolder
+ });
+ break;
+ default:
+ os.alert({
+ type: 'error',
+ text: i18n.locale.somethingHappened
+ });
}
+ });
+ }
+ //#endregion
+}
- //#region ドライブのファイル
- const driveFile = e.dataTransfer.getData(_DATA_TRANSFER_DRIVE_FILE_);
- if (driveFile != null && driveFile != '') {
- const file = JSON.parse(driveFile);
- if (this.files.some(f => f.id == file.id)) return;
- this.removeFile(file.id);
- os.api('drive/files/update', {
- fileId: file.id,
- folderId: this.folder ? this.folder.id : null
- });
- }
- //#endregion
+function selectLocalFile() {
+ fileInput.value?.click();
+}
- //#region ドライブのフォルダ
- const driveFolder = e.dataTransfer.getData(_DATA_TRANSFER_DRIVE_FOLDER_);
- if (driveFolder != null && driveFolder != '') {
- const folder = JSON.parse(driveFolder);
+function urlUpload() {
+ os.inputText({
+ title: i18n.locale.uploadFromUrl,
+ type: 'url',
+ placeholder: i18n.locale.uploadFromUrlDescription
+ }).then(({ canceled, result: url }) => {
+ if (canceled || !url) return;
+ os.api('drive/files/upload-from-url', {
+ url: url,
+ folderId: folder.value ? folder.value.id : undefined
+ });
- // 移動先が自分自身ならreject
- if (this.folder && folder.id == this.folder.id) return false;
- if (this.folders.some(f => f.id == folder.id)) return false;
- this.removeFolder(folder.id);
- os.api('drive/folders/update', {
- folderId: folder.id,
- parentId: this.folder ? this.folder.id : null
- }).then(() => {
- // noop
- }).catch(err => {
- switch (err) {
- case 'detected-circular-definition':
- os.alert({
- title: this.$ts.unableToProcess,
- text: this.$ts.circularReferenceFolder
- });
- break;
- default:
- os.alert({
- type: 'error',
- text: this.$ts.somethingHappened
- });
- }
- });
- }
- //#endregion
- },
+ os.alert({
+ title: i18n.locale.uploadFromUrlRequested,
+ text: i18n.locale.uploadFromUrlMayTakeTime
+ });
+ });
+}
- selectLocalFile() {
- (this.$refs.fileInput as any).click();
- },
+function createFolder() {
+ os.inputText({
+ title: i18n.locale.createFolder,
+ placeholder: i18n.locale.folderName
+ }).then(({ canceled, result: name }) => {
+ if (canceled) return;
+ os.api('drive/folders/create', {
+ name: name,
+ parentId: folder.value ? folder.value.id : undefined
+ }).then(createdFolder => {
+ addFolder(createdFolder, true);
+ });
+ });
+}
- urlUpload() {
- os.inputText({
- title: this.$ts.uploadFromUrl,
- type: 'url',
- placeholder: this.$ts.uploadFromUrlDescription
- }).then(({ canceled, result: url }) => {
- if (canceled) return;
- os.api('drive/files/upload-from-url', {
- url: url,
- folderId: this.folder ? this.folder.id : undefined
- });
+function renameFolder(folderToRename: Misskey.entities.DriveFolder) {
+ os.inputText({
+ title: i18n.locale.renameFolder,
+ placeholder: i18n.locale.inputNewFolderName,
+ default: folderToRename.name
+ }).then(({ canceled, result: name }) => {
+ if (canceled) return;
+ os.api('drive/folders/update', {
+ folderId: folderToRename.id,
+ name: name
+ }).then(updatedFolder => {
+ // FIXME: 画面を更新するために自分自身に移動
+ move(updatedFolder);
+ });
+ });
+}
+function deleteFolder(folderToDelete: Misskey.entities.DriveFolder) {
+ os.api('drive/folders/delete', {
+ folderId: folderToDelete.id
+ }).then(() => {
+ // 削除時に親フォルダに移動
+ move(folderToDelete.parentId);
+ }).catch(err => {
+ switch(err.id) {
+ case 'b0fc8a17-963c-405d-bfbc-859a487295e1':
os.alert({
- title: this.$ts.uploadFromUrlRequested,
- text: this.$ts.uploadFromUrlMayTakeTime
+ type: 'error',
+ title: i18n.locale.unableToDelete,
+ text: i18n.locale.hasChildFilesOrFolders
});
- });
- },
-
- createFolder() {
- os.inputText({
- title: this.$ts.createFolder,
- placeholder: this.$ts.folderName
- }).then(({ canceled, result: name }) => {
- if (canceled) return;
- os.api('drive/folders/create', {
- name: name,
- parentId: this.folder ? this.folder.id : undefined
- }).then(folder => {
- this.addFolder(folder, true);
+ break;
+ default:
+ os.alert({
+ type: 'error',
+ text: i18n.locale.unableToDelete
});
- });
- },
+ }
+ });
+}
- renameFolder(folder) {
- os.inputText({
- title: this.$ts.renameFolder,
- placeholder: this.$ts.inputNewFolderName,
- default: folder.name
- }).then(({ canceled, result: name }) => {
- if (canceled) return;
- os.api('drive/folders/update', {
- folderId: folder.id,
- name: name
- }).then(folder => {
- // FIXME: 画面を更新するために自分自身に移動
- this.move(folder);
- });
- });
- },
+function onChangeFileInput() {
+ if (!fileInput.value?.files) return;
+ for (const file of Array.from(fileInput.value.files)) {
+ upload(file, folder.value);
+ }
+}
- deleteFolder(folder) {
- os.api('drive/folders/delete', {
- folderId: folder.id
- }).then(() => {
- // 削除時に親フォルダに移動
- this.move(folder.parentId);
- }).catch(err => {
- switch(err.id) {
- case 'b0fc8a17-963c-405d-bfbc-859a487295e1':
- os.alert({
- type: 'error',
- title: this.$ts.unableToDelete,
- text: this.$ts.hasChildFilesOrFolders
- });
- break;
- default:
- os.alert({
- type: 'error',
- text: this.$ts.unableToDelete
- });
- }
- });
- },
+function upload(file: File, folderToUpload?: Misskey.entities.DriveFolder | null) {
+ os.upload(file, (folderToUpload && typeof folderToUpload == 'object') ? folderToUpload.id : null).then(res => {
+ addFile(res, true);
+ });
+}
- onChangeFileInput() {
- for (const file of Array.from((this.$refs.fileInput as any).files)) {
- this.upload(file, this.folder);
- }
- },
+function chooseFile(file: Misskey.entities.DriveFile) {
+ const isAlreadySelected = selectedFiles.value.some(f => f.id == file.id);
+ if (props.multiple) {
+ if (isAlreadySelected) {
+ selectedFiles.value = selectedFiles.value.filter(f => f.id != file.id);
+ } else {
+ selectedFiles.value.push(file);
+ }
+ emit('change-selection', selectedFiles.value);
+ } else {
+ if (isAlreadySelected) {
+ emit('selected', file);
+ } else {
+ selectedFiles.value = [file];
+ emit('change-selection', [file]);
+ }
+ }
+}
- upload(file, folder) {
- if (folder && typeof folder == 'object') folder = folder.id;
- os.upload(file, folder).then(res => {
- this.addFile(res, true);
- });
- },
+function chooseFolder(folderToChoose: Misskey.entities.DriveFolder) {
+ const isAlreadySelected = selectedFolders.value.some(f => f.id == folderToChoose.id);
+ if (props.multiple) {
+ if (isAlreadySelected) {
+ selectedFolders.value = selectedFolders.value.filter(f => f.id != folderToChoose.id);
+ } else {
+ selectedFolders.value.push(folderToChoose);
+ }
+ emit('change-selection', selectedFolders.value);
+ } else {
+ if (isAlreadySelected) {
+ emit('selected', folderToChoose);
+ } else {
+ selectedFolders.value = [folderToChoose];
+ emit('change-selection', [folderToChoose]);
+ }
+ }
+}
- chooseFile(file) {
- const isAlreadySelected = this.selectedFiles.some(f => f.id == file.id);
- if (this.multiple) {
- if (isAlreadySelected) {
- this.selectedFiles = this.selectedFiles.filter(f => f.id != file.id);
- } else {
- this.selectedFiles.push(file);
- }
- this.$emit('change-selection', this.selectedFiles);
- } else {
- if (isAlreadySelected) {
- this.$emit('selected', file);
- } else {
- this.selectedFiles = [file];
- this.$emit('change-selection', [file]);
- }
- }
- },
+function move(target?: Misskey.entities.DriveFolder) {
+ if (!target) {
+ goRoot();
+ return;
+ } else if (typeof target == 'object') {
+ target = target.id;
+ }
- chooseFolder(folder) {
- const isAlreadySelected = this.selectedFolders.some(f => f.id == folder.id);
- if (this.multiple) {
- if (isAlreadySelected) {
- this.selectedFolders = this.selectedFolders.filter(f => f.id != folder.id);
- } else {
- this.selectedFolders.push(folder);
- }
- this.$emit('change-selection', this.selectedFolders);
- } else {
- if (isAlreadySelected) {
- this.$emit('selected', folder);
- } else {
- this.selectedFolders = [folder];
- this.$emit('change-selection', [folder]);
- }
- }
- },
+ fetching.value = true;
- move(target) {
- if (target == null) {
- this.goRoot();
- return;
- } else if (typeof target == 'object') {
- target = target.id;
- }
+ os.api('drive/folders/show', {
+ folderId: target
+ }).then(folderToMove => {
+ folder.value = folderToMove;
+ hierarchyFolders.value = [];
- this.fetching = true;
+ const dive = folderToDive => {
+ hierarchyFolders.value.unshift(folderToDive);
+ if (folderToDive.parent) dive(folderToDive.parent);
+ };
+
+ if (folderToMove.parent) dive(folderToMove.parent);
- os.api('drive/folders/show', {
- folderId: target
- }).then(folder => {
- this.folder = folder;
- this.hierarchyFolders = [];
+ emit('open-folder', folderToMove);
+ fetch();
+ });
+}
- const dive = folder => {
- this.hierarchyFolders.unshift(folder);
- if (folder.parent) dive(folder.parent);
- };
+function addFolder(folderToAdd: Misskey.entities.DriveFolder, unshift = false) {
+ const current = folder.value ? folder.value.id : null;
+ if (current != folderToAdd.parentId) return;
- if (folder.parent) dive(folder.parent);
+ if (folders.value.some(f => f.id == folderToAdd.id)) {
+ const exist = folders.value.map(f => f.id).indexOf(folderToAdd.id);
+ folders.value[exist] = folderToAdd;
+ return;
+ }
- this.$emit('open-folder', folder);
- this.fetch();
- });
- },
+ if (unshift) {
+ folders.value.unshift(folderToAdd);
+ } else {
+ folders.value.push(folderToAdd);
+ }
+}
- addFolder(folder, unshift = false) {
- const current = this.folder ? this.folder.id : null;
- if (current != folder.parentId) return;
+function addFile(fileToAdd: Misskey.entities.DriveFile, unshift = false) {
+ const current = folder.value ? folder.value.id : null;
+ if (current != fileToAdd.folderId) return;
- if (this.folders.some(f => f.id == folder.id)) {
- const exist = this.folders.map(f => f.id).indexOf(folder.id);
- this.folders[exist] = folder;
- return;
- }
+ if (files.value.some(f => f.id == fileToAdd.id)) {
+ const exist = files.value.map(f => f.id).indexOf(fileToAdd.id);
+ files.value[exist] = fileToAdd;
+ return;
+ }
- if (unshift) {
- this.folders.unshift(folder);
- } else {
- this.folders.push(folder);
- }
- },
+ if (unshift) {
+ files.value.unshift(fileToAdd);
+ } else {
+ files.value.push(fileToAdd);
+ }
+}
- addFile(file, unshift = false) {
- const current = this.folder ? this.folder.id : null;
- if (current != file.folderId) return;
+function removeFolder(folderToRemove: Misskey.entities.DriveFolder | string) {
+ const folderIdToRemove = typeof folderToRemove === 'object' ? folderToRemove.id : folderToRemove;
+ folders.value = folders.value.filter(f => f.id != folderIdToRemove);
+}
- if (this.files.some(f => f.id == file.id)) {
- const exist = this.files.map(f => f.id).indexOf(file.id);
- this.files[exist] = file;
- return;
- }
+function removeFile(file: Misskey.entities.DriveFile | string) {
+ const fileId = typeof file === 'object' ? file.id : file;
+ files.value = files.value.filter(f => f.id != fileId);
+}
- if (unshift) {
- this.files.unshift(file);
- } else {
- this.files.push(file);
- }
- },
+function appendFile(file: Misskey.entities.DriveFile) {
+ addFile(file);
+}
- removeFolder(folder) {
- if (typeof folder == 'object') folder = folder.id;
- this.folders = this.folders.filter(f => f.id != folder);
- },
+function appendFolder(folderToAppend: Misskey.entities.DriveFolder) {
+ addFolder(folderToAppend);
+}
+/*
+function prependFile(file: Misskey.entities.DriveFile) {
+ addFile(file, true);
+}
- removeFile(file) {
- if (typeof file == 'object') file = file.id;
- this.files = this.files.filter(f => f.id != file);
- },
+function prependFolder(folderToPrepend: Misskey.entities.DriveFolder) {
+ addFolder(folderToPrepend, true);
+}
+*/
+function goRoot() {
+ // 既にrootにいるなら何もしない
+ if (folder.value == null) return;
- appendFile(file) {
- this.addFile(file);
- },
+ folder.value = null;
+ hierarchyFolders.value = [];
+ emit('move-root');
+ fetch();
+}
- appendFolder(folder) {
- this.addFolder(folder);
- },
+async function fetch() {
+ folders.value = [];
+ files.value = [];
+ moreFolders.value = false;
+ moreFiles.value = false;
+ fetching.value = true;
- prependFile(file) {
- this.addFile(file, true);
- },
+ const foldersMax = 30;
+ const filesMax = 30;
- prependFolder(folder) {
- this.addFolder(folder, true);
- },
+ const foldersPromise = os.api('drive/folders', {
+ folderId: folder.value ? folder.value.id : null,
+ limit: foldersMax + 1
+ }).then(fetchedFolders => {
+ if (fetchedFolders.length == foldersMax + 1) {
+ moreFolders.value = true;
+ fetchedFolders.pop();
+ }
+ return fetchedFolders;
+ });
- goRoot() {
- // 既にrootにいるなら何もしない
- if (this.folder == null) return;
+ const filesPromise = os.api('drive/files', {
+ folderId: folder.value ? folder.value.id : null,
+ type: props.type,
+ limit: filesMax + 1
+ }).then(fetchedFiles => {
+ if (fetchedFiles.length == filesMax + 1) {
+ moreFiles.value = true;
+ fetchedFiles.pop();
+ }
+ return fetchedFiles;
+ });
- this.folder = null;
- this.hierarchyFolders = [];
- this.$emit('move-root');
- this.fetch();
- },
+ const [fetchedFolders, fetchedFiles] = await Promise.all([foldersPromise, filesPromise]);
- fetch() {
- this.folders = [];
- this.files = [];
- this.moreFolders = false;
- this.moreFiles = false;
- this.fetching = true;
+ for (const x of fetchedFolders) appendFolder(x);
+ for (const x of fetchedFiles) appendFile(x);
- let fetchedFolders = null;
- let fetchedFiles = null;
+ fetching.value = false;
+}
- const foldersMax = 30;
- const filesMax = 30;
+function fetchMoreFiles() {
+ fetching.value = true;
- // フォルダ一覧取得
- os.api('drive/folders', {
- folderId: this.folder ? this.folder.id : null,
- limit: foldersMax + 1
- }).then(folders => {
- if (folders.length == foldersMax + 1) {
- this.moreFolders = true;
- folders.pop();
- }
- fetchedFolders = folders;
- complete();
- });
+ const max = 30;
- // ファイル一覧取得
- os.api('drive/files', {
- folderId: this.folder ? this.folder.id : null,
- type: this.type,
- limit: filesMax + 1
- }).then(files => {
- if (files.length == filesMax + 1) {
- this.moreFiles = true;
- files.pop();
- }
- fetchedFiles = files;
- complete();
- });
+ // ファイル一覧取得
+ os.api('drive/files', {
+ folderId: folder.value ? folder.value.id : null,
+ type: props.type,
+ untilId: files.value[files.value.length - 1].id,
+ limit: max + 1
+ }).then(files => {
+ if (files.length == max + 1) {
+ moreFiles.value = true;
+ files.pop();
+ } else {
+ moreFiles.value = false;
+ }
+ for (const x of files) appendFile(x);
+ fetching.value = false;
+ });
+}
- let flag = false;
- const complete = () => {
- if (flag) {
- for (const x of fetchedFolders) this.appendFolder(x);
- for (const x of fetchedFiles) this.appendFile(x);
- this.fetching = false;
- } else {
- flag = true;
- }
- };
- },
+function getMenu() {
+ return [{
+ text: i18n.locale.addFile,
+ type: 'label'
+ }, {
+ text: i18n.locale.upload,
+ icon: 'fas fa-upload',
+ action: () => { selectLocalFile(); }
+ }, {
+ text: i18n.locale.fromUrl,
+ icon: 'fas fa-link',
+ action: () => { urlUpload(); }
+ }, null, {
+ text: folder.value ? folder.value.name : i18n.locale.drive,
+ type: 'label'
+ }, folder.value ? {
+ text: i18n.locale.renameFolder,
+ icon: 'fas fa-i-cursor',
+ action: () => { renameFolder(folder.value); }
+ } : undefined, folder.value ? {
+ text: i18n.locale.deleteFolder,
+ icon: 'fas fa-trash-alt',
+ action: () => { deleteFolder(folder.value as Misskey.entities.DriveFolder); }
+ } : undefined, {
+ text: i18n.locale.createFolder,
+ icon: 'fas fa-folder-plus',
+ action: () => { createFolder(); }
+ }];
+}
- fetchMoreFiles() {
- this.fetching = true;
+function showMenu(ev: MouseEvent) {
+ os.popupMenu(getMenu(), (ev.currentTarget || ev.target || undefined) as HTMLElement | undefined);
+}
- const max = 30;
+function onContextmenu(ev: MouseEvent) {
+ os.contextMenu(getMenu(), ev);
+}
- // ファイル一覧取得
- os.api('drive/files', {
- folderId: this.folder ? this.folder.id : null,
- type: this.type,
- untilId: this.files[this.files.length - 1].id,
- limit: max + 1
- }).then(files => {
- if (files.length == max + 1) {
- this.moreFiles = true;
- files.pop();
- } else {
- this.moreFiles = false;
- }
- for (const x of files) this.appendFile(x);
- this.fetching = false;
- });
- },
+onMounted(() => {
+ if (defaultStore.state.enableInfiniteScroll && loadMoreFiles.value) {
+ nextTick(() => {
+ ilFilesObserver.observe(loadMoreFiles.value?.$el)
+ });
+ }
- getMenu() {
- return [{
- text: this.$ts.addFile,
- type: 'label'
- }, {
- text: this.$ts.upload,
- icon: 'fas fa-upload',
- action: () => { this.selectLocalFile(); }
- }, {
- text: this.$ts.fromUrl,
- icon: 'fas fa-link',
- action: () => { this.urlUpload(); }
- }, null, {
- text: this.folder ? this.folder.name : this.$ts.drive,
- type: 'label'
- }, this.folder ? {
- text: this.$ts.renameFolder,
- icon: 'fas fa-i-cursor',
- action: () => { this.renameFolder(this.folder); }
- } : undefined, this.folder ? {
- text: this.$ts.deleteFolder,
- icon: 'fas fa-trash-alt',
- action: () => { this.deleteFolder(this.folder); }
- } : undefined, {
- text: this.$ts.createFolder,
- icon: 'fas fa-folder-plus',
- action: () => { this.createFolder(); }
- }];
- },
+ connection.on('fileCreated', onStreamDriveFileCreated);
+ connection.on('fileUpdated', onStreamDriveFileUpdated);
+ connection.on('fileDeleted', onStreamDriveFileDeleted);
+ connection.on('folderCreated', onStreamDriveFolderCreated);
+ connection.on('folderUpdated', onStreamDriveFolderUpdated);
+ connection.on('folderDeleted', onStreamDriveFolderDeleted);
- showMenu(ev) {
- os.popupMenu(this.getMenu(), ev.currentTarget || ev.target);
- },
+ if (props.initialFolder) {
+ move(props.initialFolder);
+ } else {
+ fetch();
+ }
+});
- onContextmenu(ev) {
- os.contextMenu(this.getMenu(), ev);
- },
+onActivated(() => {
+ if (defaultStore.state.enableInfiniteScroll) {
+ nextTick(() => {
+ ilFilesObserver.observe(loadMoreFiles.value?.$el)
+ });
}
});
+
+onBeforeUnmount(() => {
+ connection.dispose();
+ ilFilesObserver.disconnect();
+});
</script>
<style lang="scss" scoped>
diff --git a/packages/client/src/components/emoji-picker-dialog.vue b/packages/client/src/components/emoji-picker-dialog.vue
index 51c634dd8e..f06a24636c 100644
--- a/packages/client/src/components/emoji-picker-dialog.vue
+++ b/packages/client/src/components/emoji-picker-dialog.vue
@@ -1,58 +1,65 @@
<template>
-<MkModal ref="modal" v-slot="{ type, maxHeight }" :z-priority="'middle'" :prefer-type="asReactionPicker && $store.state.reactionPickerUseDrawerForMobile === false ? 'popup' : 'auto'" :transparent-bg="true" :manual-showing="manualShowing" :src="src" @click="$refs.modal.close()" @opening="opening" @close="$emit('close')" @closed="$emit('closed')">
- <MkEmojiPicker ref="picker" class="ryghynhb _popup _shadow" :class="{ drawer: type === 'drawer' }" :show-pinned="showPinned" :as-reaction-picker="asReactionPicker" :as-drawer="type === 'drawer'" :max-height="maxHeight" @chosen="chosen"/>
+<MkModal
+ ref="modal"
+ v-slot="{ type, maxHeight }"
+ :z-priority="'middle'"
+ :prefer-type="asReactionPicker && defaultStore.state.reactionPickerUseDrawerForMobile === false ? 'popup' : 'auto'"
+ :transparent-bg="true"
+ :manual-showing="manualShowing"
+ :src="src"
+ @click="modal?.close()"
+ @opening="opening"
+ @close="emit('close')"
+ @closed="emit('closed')"
+>
+ <MkEmojiPicker
+ ref="picker"
+ class="ryghynhb _popup _shadow"
+ :class="{ drawer: type === 'drawer' }"
+ :show-pinned="showPinned"
+ :as-reaction-picker="asReactionPicker"
+ :as-drawer="type === 'drawer'"
+ :max-height="maxHeight"
+ @chosen="chosen"
+ />
</MkModal>
</template>
-<script lang="ts">
-import { defineComponent, markRaw } from 'vue';
+<script lang="ts" setup>
+import { ref } from 'vue';
import MkModal from '@/components/ui/modal.vue';
import MkEmojiPicker from '@/components/emoji-picker.vue';
+import { defaultStore } from '@/store';
-export default defineComponent({
- components: {
- MkModal,
- MkEmojiPicker,
- },
-
- props: {
- manualShowing: {
- type: Boolean,
- required: false,
- default: null,
- },
- src: {
- required: false
- },
- showPinned: {
- required: false,
- default: true
- },
- asReactionPicker: {
- required: false
- },
- },
-
- emits: ['done', 'close', 'closed'],
+withDefaults(defineProps<{
+ manualShowing?: boolean;
+ src?: HTMLElement;
+ showPinned?: boolean;
+ asReactionPicker?: boolean;
+}>(), {
+ manualShowing: false,
+ showPinned: true,
+ asReactionPicker: false,
+});
- data() {
- return {
+const emit = defineEmits<{
+ (e: 'done', v: any): void;
+ (e: 'close'): void;
+ (e: 'closed'): void;
+}>();
- };
- },
+const modal = ref<InstanceType<typeof MkModal>>();
+const picker = ref<InstanceType<typeof MkEmojiPicker>>();
- methods: {
- chosen(emoji: any) {
- this.$emit('done', emoji);
- this.$refs.modal.close();
- },
+function chosen(emoji: any) {
+ emit('done', emoji);
+ modal.value?.close();
+}
- opening() {
- this.$refs.picker.reset();
- this.$refs.picker.focus();
- }
- }
-});
+function opening() {
+ picker.value?.reset();
+ picker.value?.focus();
+}
</script>
<style lang="scss" scoped>
diff --git a/packages/client/src/components/emoji-picker-window.vue b/packages/client/src/components/emoji-picker-window.vue
index 0ffa0c1187..4d27fb48ba 100644
--- a/packages/client/src/components/emoji-picker-window.vue
+++ b/packages/client/src/components/emoji-picker-window.vue
@@ -5,50 +5,33 @@
:can-resize="false"
:mini="true"
:front="true"
- @closed="$emit('closed')"
+ @closed="emit('closed')"
>
<MkEmojiPicker :show-pinned="showPinned" :as-reaction-picker="asReactionPicker" @chosen="chosen"/>
</MkWindow>
</template>
-<script lang="ts">
-import { defineComponent, markRaw } from 'vue';
+<script lang="ts" setup>
+import { } from 'vue';
import MkWindow from '@/components/ui/window.vue';
import MkEmojiPicker from '@/components/emoji-picker.vue';
-export default defineComponent({
- components: {
- MkWindow,
- MkEmojiPicker,
- },
-
- props: {
- src: {
- required: false
- },
- showPinned: {
- required: false,
- default: true
- },
- asReactionPicker: {
- required: false
- },
- },
-
- emits: ['chosen', 'closed'],
-
- data() {
- return {
+withDefaults(defineProps<{
+ src?: HTMLElement;
+ showPinned?: boolean;
+ asReactionPicker?: boolean;
+}>(), {
+ showPinned: true,
+});
- };
- },
+const emit = defineEmits<{
+ (e: 'chosen', v: any): void;
+ (e: 'closed'): void;
+}>();
- methods: {
- chosen(emoji: any) {
- this.$emit('chosen', emoji);
- },
- }
-});
+function chosen(emoji: any) {
+ emit('chosen', emoji);
+}
</script>
<style lang="scss" scoped>
diff --git a/packages/client/src/components/emoji-picker.section.vue b/packages/client/src/components/emoji-picker.section.vue
index 08c4f6813d..1026e894d1 100644
--- a/packages/client/src/components/emoji-picker.section.vue
+++ b/packages/client/src/components/emoji-picker.section.vue
@@ -7,7 +7,7 @@
<button v-for="emoji in emojis"
:key="emoji"
class="_button"
- @click="chosen(emoji, $event)"
+ @click="emit('chosen', emoji, $event)"
>
<MkEmoji :emoji="emoji" :normal="true"/>
</button>
@@ -15,35 +15,19 @@
</section>
</template>
-<script lang="ts">
-import { defineComponent, markRaw } from 'vue';
-import { getStaticImageUrl } from '@/scripts/get-static-image-url';
+<script lang="ts" setup>
+import { ref } from 'vue';
-export default defineComponent({
- props: {
- emojis: {
- required: true,
- },
- initialShown: {
- required: false
- }
- },
+const props = defineProps<{
+ emojis: string[];
+ initialShown?: boolean;
+}>();
- emits: ['chosen'],
+const emit = defineEmits<{
+ (e: 'chosen', v: string, ev: MouseEvent): void;
+}>();
- data() {
- return {
- getStaticImageUrl,
- shown: this.initialShown,
- };
- },
-
- methods: {
- chosen(emoji: any, ev) {
- this.$parent.chosen(emoji, ev);
- },
- }
-});
+const shown = ref(!!props.initialShown);
</script>
<style lang="scss" scoped>
diff --git a/packages/client/src/components/emoji-picker.vue b/packages/client/src/components/emoji-picker.vue
index a8eed1ca21..96670fa58c 100644
--- a/packages/client/src/components/emoji-picker.vue
+++ b/packages/client/src/components/emoji-picker.vue
@@ -1,18 +1,18 @@
<template>
-<div class="omfetrab" :class="['w' + width, 'h' + height, { big, asDrawer }]" :style="{ maxHeight: maxHeight ? maxHeight + 'px' : null }">
- <input ref="search" v-model.trim="q" class="search" data-prevent-emoji-insert :class="{ filled: q != null && q != '' }" :placeholder="$ts.search" @paste.stop="paste" @keyup.enter="done()">
+<div class="omfetrab" :class="['w' + width, 'h' + height, { big, asDrawer }]" :style="{ maxHeight: maxHeight ? maxHeight + 'px' : undefined }">
+ <input ref="search" v-model.trim="q" class="search" data-prevent-emoji-insert :class="{ filled: q != null && q != '' }" :placeholder="i18n.locale.search" @paste.stop="paste" @keyup.enter="done()">
<div ref="emojis" class="emojis">
<section class="result">
<div v-if="searchResultCustom.length > 0">
<button v-for="emoji in searchResultCustom"
- :key="emoji"
+ :key="emoji.id"
class="_button"
:title="emoji.name"
tabindex="0"
@click="chosen(emoji, $event)"
>
- <MkEmoji v-if="emoji.char != null" :emoji="emoji.char"/>
- <img v-else :src="$store.state.disableShowingAnimatedImages ? getStaticImageUrl(emoji.url) : emoji.url"/>
+ <!--<MkEmoji v-if="emoji.char != null" :emoji="emoji.char"/>-->
+ <img :src="disableShowingAnimatedImages ? getStaticImageUrl(emoji.url) : emoji.url"/>
</button>
</div>
<div v-if="searchResultUnicode.length > 0">
@@ -43,9 +43,9 @@
</section>
<section>
- <header class="_acrylic"><i class="far fa-clock fa-fw"></i> {{ $ts.recentUsed }}</header>
+ <header class="_acrylic"><i class="far fa-clock fa-fw"></i> {{ i18n.locale.recentUsed }}</header>
<div>
- <button v-for="emoji in $store.state.recentlyUsedEmojis"
+ <button v-for="emoji in recentlyUsedEmojis"
:key="emoji"
class="_button"
@click="chosen(emoji, $event)"
@@ -56,12 +56,12 @@
</section>
</div>
<div>
- <header class="_acrylic">{{ $ts.customEmojis }}</header>
- <XSection v-for="category in customEmojiCategories" :key="'custom:' + category" :initial-shown="false" :emojis="customEmojis.filter(e => e.category === category).map(e => ':' + e.name + ':')">{{ category || $ts.other }}</XSection>
+ <header class="_acrylic">{{ i18n.locale.customEmojis }}</header>
+ <XSection v-for="category in customEmojiCategories" :key="'custom:' + category" :initial-shown="false" :emojis="customEmojis.filter(e => e.category === category).map(e => ':' + e.name + ':')" @chosen="chosen">{{ category || i18n.locale.other }}</XSection>
</div>
<div>
- <header class="_acrylic">{{ $ts.emoji }}</header>
- <XSection v-for="category in categories" :emojis="emojilist.filter(e => e.category === category).map(e => e.char)">{{ category }}</XSection>
+ <header class="_acrylic">{{ i18n.locale.emoji }}</header>
+ <XSection v-for="category in categories" :emojis="emojilist.filter(e => e.category === category).map(e => e.char)" @chosen="chosen">{{ category }}</XSection>
</div>
</div>
<div class="tabs">
@@ -73,277 +73,272 @@
</div>
</template>
-<script lang="ts">
-import { defineComponent, markRaw } from 'vue';
-import { emojilist } from '@/scripts/emojilist';
+<script lang="ts" setup>
+import { ref, computed, watch, onMounted } from 'vue';
+import * as Misskey from 'misskey-js';
+import { emojilist, UnicodeEmojiDef, unicodeEmojiCategories as categories } from '@/scripts/emojilist';
import { getStaticImageUrl } from '@/scripts/get-static-image-url';
import Ripple from '@/components/ripple.vue';
import * as os from '@/os';
import { isTouchUsing } from '@/scripts/touch';
import { isMobile } from '@/scripts/is-mobile';
-import { emojiCategories } from '@/instance';
+import { emojiCategories, instance } from '@/instance';
import XSection from './emoji-picker.section.vue';
+import { i18n } from '@/i18n';
+import { defaultStore } from '@/store';
-export default defineComponent({
- components: {
- XSection
- },
-
- props: {
- showPinned: {
- required: false,
- default: true,
- },
- asReactionPicker: {
- required: false,
- },
- maxHeight: {
- type: Number,
- required: false,
- },
- asDrawer: {
- type: Boolean,
- required: false
- },
- },
+const props = withDefaults(defineProps<{
+ showPinned?: boolean;
+ asReactionPicker?: boolean;
+ maxHeight?: number;
+ asDrawer?: boolean;
+}>(), {
+ showPinned: true,
+});
- emits: ['chosen'],
+const emit = defineEmits<{
+ (e: 'chosen', v: string): void;
+}>();
- data() {
- return {
- emojilist: markRaw(emojilist),
- getStaticImageUrl,
- pinned: this.$store.reactiveState.reactions,
- width: this.asReactionPicker ? this.$store.state.reactionPickerWidth : 3,
- height: this.asReactionPicker ? this.$store.state.reactionPickerHeight : 2,
- big: this.asReactionPicker ? isTouchUsing : false,
- customEmojiCategories: emojiCategories,
- customEmojis: this.$instance.emojis,
- q: null,
- searchResultCustom: [],
- searchResultUnicode: [],
- tab: 'index',
- categories: ['face', 'people', 'animals_and_nature', 'food_and_drink', 'activity', 'travel_and_places', 'objects', 'symbols', 'flags'],
- };
- },
+const search = ref<HTMLInputElement>();
+const emojis = ref<HTMLDivElement>();
- watch: {
- q() {
- this.$refs.emojis.scrollTop = 0;
+const {
+ reactions: pinned,
+ reactionPickerWidth,
+ reactionPickerHeight,
+ disableShowingAnimatedImages,
+ recentlyUsedEmojis,
+} = defaultStore.reactiveState;
- if (this.q == null || this.q === '') {
- this.searchResultCustom = [];
- this.searchResultUnicode = [];
- return;
- }
+const width = computed(() => props.asReactionPicker ? reactionPickerWidth.value : 3);
+const height = computed(() => props.asReactionPicker ? reactionPickerHeight.value : 2);
+const big = props.asReactionPicker ? isTouchUsing : false;
+const customEmojiCategories = emojiCategories;
+const customEmojis = instance.emojis;
+const q = ref<string | null>(null);
+const searchResultCustom = ref<Misskey.entities.CustomEmoji[]>([]);
+const searchResultUnicode = ref<UnicodeEmojiDef[]>([]);
+const tab = ref<'index' | 'custom' | 'unicode' | 'tags'>('index');
- const q = this.q.replace(/:/g, '');
+watch(q, () => {
+ if (emojis.value) emojis.value.scrollTop = 0;
- const searchCustom = () => {
- const max = 8;
- const emojis = this.customEmojis;
- const matches = new Set();
+ if (q.value == null || q.value === '') {
+ searchResultCustom.value = [];
+ searchResultUnicode.value = [];
+ return;
+ }
- const exactMatch = emojis.find(e => e.name === q);
- if (exactMatch) matches.add(exactMatch);
+ const newQ = q.value.replace(/:/g, '');
- if (q.includes(' ')) { // AND検索
- const keywords = q.split(' ');
+ const searchCustom = () => {
+ const max = 8;
+ const emojis = customEmojis;
+ const matches = new Set<Misskey.entities.CustomEmoji>();
- // 名前にキーワードが含まれている
- for (const emoji of emojis) {
- if (keywords.every(keyword => emoji.name.includes(keyword))) {
- matches.add(emoji);
- if (matches.size >= max) break;
- }
- }
- if (matches.size >= max) return matches;
+ const exactMatch = emojis.find(e => e.name === newQ);
+ if (exactMatch) matches.add(exactMatch);
- // 名前またはエイリアスにキーワードが含まれている
- for (const emoji of emojis) {
- if (keywords.every(keyword => emoji.name.includes(keyword) || emoji.aliases.some(alias => alias.includes(keyword)))) {
- matches.add(emoji);
- if (matches.size >= max) break;
- }
- }
- } else {
- for (const emoji of emojis) {
- if (emoji.name.startsWith(q)) {
- matches.add(emoji);
- if (matches.size >= max) break;
- }
- }
- if (matches.size >= max) return matches;
+ if (newQ.includes(' ')) { // AND検索
+ const keywords = newQ.split(' ');
- for (const emoji of emojis) {
- if (emoji.aliases.some(alias => alias.startsWith(q))) {
- matches.add(emoji);
- if (matches.size >= max) break;
- }
- }
- if (matches.size >= max) return matches;
+ // 名前にキーワードが含まれている
+ for (const emoji of emojis) {
+ if (keywords.every(keyword => emoji.name.includes(keyword))) {
+ matches.add(emoji);
+ if (matches.size >= max) break;
+ }
+ }
+ if (matches.size >= max) return matches;
- for (const emoji of emojis) {
- if (emoji.name.includes(q)) {
- matches.add(emoji);
- if (matches.size >= max) break;
- }
- }
- if (matches.size >= max) return matches;
+ // 名前またはエイリアスにキーワードが含まれている
+ for (const emoji of emojis) {
+ if (keywords.every(keyword => emoji.name.includes(keyword) || emoji.aliases.some(alias => alias.includes(keyword)))) {
+ matches.add(emoji);
+ if (matches.size >= max) break;
+ }
+ }
+ } else {
+ for (const emoji of emojis) {
+ if (emoji.name.startsWith(newQ)) {
+ matches.add(emoji);
+ if (matches.size >= max) break;
+ }
+ }
+ if (matches.size >= max) return matches;
- for (const emoji of emojis) {
- if (emoji.aliases.some(alias => alias.includes(q))) {
- matches.add(emoji);
- if (matches.size >= max) break;
- }
- }
+ for (const emoji of emojis) {
+ if (emoji.aliases.some(alias => alias.startsWith(newQ))) {
+ matches.add(emoji);
+ if (matches.size >= max) break;
}
+ }
+ if (matches.size >= max) return matches;
- return matches;
- };
+ for (const emoji of emojis) {
+ if (emoji.name.includes(newQ)) {
+ matches.add(emoji);
+ if (matches.size >= max) break;
+ }
+ }
+ if (matches.size >= max) return matches;
- const searchUnicode = () => {
- const max = 8;
- const emojis = this.emojilist;
- const matches = new Set();
+ for (const emoji of emojis) {
+ if (emoji.aliases.some(alias => alias.includes(newQ))) {
+ matches.add(emoji);
+ if (matches.size >= max) break;
+ }
+ }
+ }
- const exactMatch = emojis.find(e => e.name === q);
- if (exactMatch) matches.add(exactMatch);
+ return matches;
+ };
- if (q.includes(' ')) { // AND検索
- const keywords = q.split(' ');
+ const searchUnicode = () => {
+ const max = 8;
+ const emojis = emojilist;
+ const matches = new Set<UnicodeEmojiDef>();
- // 名前にキーワードが含まれている
- for (const emoji of emojis) {
- if (keywords.every(keyword => emoji.name.includes(keyword))) {
- matches.add(emoji);
- if (matches.size >= max) break;
- }
- }
- if (matches.size >= max) return matches;
+ const exactMatch = emojis.find(e => e.name === newQ);
+ if (exactMatch) matches.add(exactMatch);
- // 名前またはエイリアスにキーワードが含まれている
- for (const emoji of emojis) {
- if (keywords.every(keyword => emoji.name.includes(keyword) || emoji.keywords.some(alias => alias.includes(keyword)))) {
- matches.add(emoji);
- if (matches.size >= max) break;
- }
- }
- } else {
- for (const emoji of emojis) {
- if (emoji.name.startsWith(q)) {
- matches.add(emoji);
- if (matches.size >= max) break;
- }
- }
- if (matches.size >= max) return matches;
+ if (newQ.includes(' ')) { // AND検索
+ const keywords = newQ.split(' ');
- for (const emoji of emojis) {
- if (emoji.keywords.some(keyword => keyword.startsWith(q))) {
- matches.add(emoji);
- if (matches.size >= max) break;
- }
- }
- if (matches.size >= max) return matches;
+ // 名前にキーワードが含まれている
+ for (const emoji of emojis) {
+ if (keywords.every(keyword => emoji.name.includes(keyword))) {
+ matches.add(emoji);
+ if (matches.size >= max) break;
+ }
+ }
+ if (matches.size >= max) return matches;
- for (const emoji of emojis) {
- if (emoji.name.includes(q)) {
- matches.add(emoji);
- if (matches.size >= max) break;
- }
- }
- if (matches.size >= max) return matches;
+ // 名前またはエイリアスにキーワードが含まれている
+ for (const emoji of emojis) {
+ if (keywords.every(keyword => emoji.name.includes(keyword) || emoji.keywords.some(alias => alias.includes(keyword)))) {
+ matches.add(emoji);
+ if (matches.size >= max) break;
+ }
+ }
+ } else {
+ for (const emoji of emojis) {
+ if (emoji.name.startsWith(newQ)) {
+ matches.add(emoji);
+ if (matches.size >= max) break;
+ }
+ }
+ if (matches.size >= max) return matches;
- for (const emoji of emojis) {
- if (emoji.keywords.some(keyword => keyword.includes(q))) {
- matches.add(emoji);
- if (matches.size >= max) break;
- }
- }
+ for (const emoji of emojis) {
+ if (emoji.keywords.some(keyword => keyword.startsWith(newQ))) {
+ matches.add(emoji);
+ if (matches.size >= max) break;
}
+ }
+ if (matches.size >= max) return matches;
- return matches;
- };
+ for (const emoji of emojis) {
+ if (emoji.name.includes(newQ)) {
+ matches.add(emoji);
+ if (matches.size >= max) break;
+ }
+ }
+ if (matches.size >= max) return matches;
- this.searchResultCustom = Array.from(searchCustom());
- this.searchResultUnicode = Array.from(searchUnicode());
+ for (const emoji of emojis) {
+ if (emoji.keywords.some(keyword => keyword.includes(newQ))) {
+ matches.add(emoji);
+ if (matches.size >= max) break;
+ }
+ }
}
- },
- mounted() {
- this.focus();
- },
+ return matches;
+ };
- methods: {
- focus() {
- if (!isMobile && !isTouchUsing) {
- this.$refs.search.focus({
- preventScroll: true
- });
- }
- },
+ searchResultCustom.value = Array.from(searchCustom());
+ searchResultUnicode.value = Array.from(searchUnicode());
+});
- reset() {
- this.$refs.emojis.scrollTop = 0;
- this.q = '';
- },
+function focus() {
+ if (!isMobile && !isTouchUsing) {
+ search.value?.focus({
+ preventScroll: true
+ });
+ }
+}
- getKey(emoji: any) {
- return typeof emoji === 'string' ? emoji : (emoji.char || `:${emoji.name}:`);
- },
+function reset() {
+ if (emojis.value) emojis.value.scrollTop = 0;
+ q.value = '';
+}
- chosen(emoji: any, ev) {
- if (ev) {
- const el = ev.currentTarget || ev.target;
- const rect = el.getBoundingClientRect();
- const x = rect.left + (el.offsetWidth / 2);
- const y = rect.top + (el.offsetHeight / 2);
- os.popup(Ripple, { x, y }, {}, 'end');
- }
+function getKey(emoji: string | Misskey.entities.CustomEmoji | UnicodeEmojiDef): string {
+ return typeof emoji === 'string' ? emoji : (emoji.char || `:${emoji.name}:`);
+}
- const key = this.getKey(emoji);
- this.$emit('chosen', key);
+function chosen(emoji: any, ev?: MouseEvent) {
+ const el = ev && (ev.currentTarget || ev.target) as HTMLElement | null | undefined;
+ if (el) {
+ const rect = el.getBoundingClientRect();
+ const x = rect.left + (el.offsetWidth / 2);
+ const y = rect.top + (el.offsetHeight / 2);
+ os.popup(Ripple, { x, y }, {}, 'end');
+ }
- // 最近使った絵文字更新
- if (!this.pinned.includes(key)) {
- let recents = this.$store.state.recentlyUsedEmojis;
- recents = recents.filter((e: any) => e !== key);
- recents.unshift(key);
- this.$store.set('recentlyUsedEmojis', recents.splice(0, 32));
- }
- },
+ const key = getKey(emoji);
+ emit('chosen', key);
- paste(event) {
- const paste = (event.clipboardData || window.clipboardData).getData('text');
- if (this.done(paste)) {
- event.preventDefault();
- }
- },
+ // 最近使った絵文字更新
+ if (!pinned.value.includes(key)) {
+ let recents = defaultStore.state.recentlyUsedEmojis;
+ recents = recents.filter((e: any) => e !== key);
+ recents.unshift(key);
+ defaultStore.set('recentlyUsedEmojis', recents.splice(0, 32));
+ }
+}
- done(query) {
- if (query == null) query = this.q;
- if (query == null) return;
- const q = query.replace(/:/g, '');
- const exactMatchCustom = this.customEmojis.find(e => e.name === q);
- if (exactMatchCustom) {
- this.chosen(exactMatchCustom);
- return true;
- }
- const exactMatchUnicode = this.emojilist.find(e => e.char === q || e.name === q);
- if (exactMatchUnicode) {
- this.chosen(exactMatchUnicode);
- return true;
- }
- if (this.searchResultCustom.length > 0) {
- this.chosen(this.searchResultCustom[0]);
- return true;
- }
- if (this.searchResultUnicode.length > 0) {
- this.chosen(this.searchResultUnicode[0]);
- return true;
- }
- },
+function paste(event: ClipboardEvent) {
+ const paste = (event.clipboardData || window.clipboardData).getData('text');
+ if (done(paste)) {
+ event.preventDefault();
}
+}
+
+function done(query?: any): boolean | void {
+ if (query == null) query = q.value;
+ if (query == null || typeof query !== 'string') return;
+
+ const q2 = query.replace(/:/g, '');
+ const exactMatchCustom = customEmojis.find(e => e.name === q2);
+ if (exactMatchCustom) {
+ chosen(exactMatchCustom);
+ return true;
+ }
+ const exactMatchUnicode = emojilist.find(e => e.char === q2 || e.name === q2);
+ if (exactMatchUnicode) {
+ chosen(exactMatchUnicode);
+ return true;
+ }
+ if (searchResultCustom.value.length > 0) {
+ chosen(searchResultCustom.value[0]);
+ return true;
+ }
+ if (searchResultUnicode.value.length > 0) {
+ chosen(searchResultUnicode.value[0]);
+ return true;
+ }
+}
+
+onMounted(() => {
+ focus();
+});
+
+defineExpose({
+ focus,
+ reset,
});
</script>
diff --git a/packages/client/src/components/featured-photos.vue b/packages/client/src/components/featured-photos.vue
index af5892c98e..e58b5d2849 100644
--- a/packages/client/src/components/featured-photos.vue
+++ b/packages/client/src/components/featured-photos.vue
@@ -2,25 +2,15 @@
<div v-if="meta" class="xfbouadm" :style="{ backgroundImage: `url(${ meta.backgroundImageUrl })` }"></div>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
+<script lang="ts" setup>
+import { ref } from 'vue';
+import * as Misskey from 'misskey-js';
import * as os from '@/os';
-export default defineComponent({
- components: {
- },
+const meta = ref<Misskey.entities.DetailedInstanceMetadata>();
- data() {
- return {
- meta: null,
- };
- },
-
- created() {
- os.api('meta', { detail: true }).then(meta => {
- this.meta = meta;
- });
- },
+os.api('meta', { detail: true }).then(gotMeta => {
+ meta.value = gotMeta;
});
</script>
diff --git a/packages/client/src/components/file-type-icon.vue b/packages/client/src/components/file-type-icon.vue
index be1af5e501..11d28188cc 100644
--- a/packages/client/src/components/file-type-icon.vue
+++ b/packages/client/src/components/file-type-icon.vue
@@ -4,25 +4,12 @@
</span>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
-import * as os from '@/os';
+<script lang="ts" setup>
+import { computed } from 'vue';
-export default defineComponent({
- props: {
- type: {
- type: String,
- required: true,
- }
- },
- data() {
- return {
- };
- },
- computed: {
- kind(): string {
- return this.type.split('/')[0];
- }
- }
-});
+const props = defineProps<{
+ type: string;
+}>();
+
+const kind = computed(() => props.type.split('/')[0]);
</script>
diff --git a/packages/client/src/components/follow-button.vue b/packages/client/src/components/follow-button.vue
index 7136261914..345edb6441 100644
--- a/packages/client/src/components/follow-button.vue
+++ b/packages/client/src/components/follow-button.vue
@@ -6,128 +6,110 @@
>
<template v-if="!wait">
<template v-if="hasPendingFollowRequestFromYou && user.isLocked">
- <span v-if="full">{{ $ts.followRequestPending }}</span><i class="fas fa-hourglass-half"></i>
+ <span v-if="full">{{ i18n.locale.followRequestPending }}</span><i class="fas fa-hourglass-half"></i>
</template>
<template v-else-if="hasPendingFollowRequestFromYou && !user.isLocked"> <!-- つまりリモートフォローの場合。 -->
- <span v-if="full">{{ $ts.processing }}</span><i class="fas fa-spinner fa-pulse"></i>
+ <span v-if="full">{{ i18n.locale.processing }}</span><i class="fas fa-spinner fa-pulse"></i>
</template>
<template v-else-if="isFollowing">
- <span v-if="full">{{ $ts.unfollow }}</span><i class="fas fa-minus"></i>
+ <span v-if="full">{{ i18n.locale.unfollow }}</span><i class="fas fa-minus"></i>
</template>
<template v-else-if="!isFollowing && user.isLocked">
- <span v-if="full">{{ $ts.followRequest }}</span><i class="fas fa-plus"></i>
+ <span v-if="full">{{ i18n.locale.followRequest }}</span><i class="fas fa-plus"></i>
</template>
<template v-else-if="!isFollowing && !user.isLocked">
- <span v-if="full">{{ $ts.follow }}</span><i class="fas fa-plus"></i>
+ <span v-if="full">{{ i18n.locale.follow }}</span><i class="fas fa-plus"></i>
</template>
</template>
<template v-else>
- <span v-if="full">{{ $ts.processing }}</span><i class="fas fa-spinner fa-pulse fa-fw"></i>
+ <span v-if="full">{{ i18n.locale.processing }}</span><i class="fas fa-spinner fa-pulse fa-fw"></i>
</template>
</button>
</template>
-<script lang="ts">
-import { defineComponent, markRaw } from 'vue';
+<script lang="ts" setup>
+import { onBeforeUnmount, onMounted, ref } from 'vue';
+import * as Misskey from 'misskey-js';
import * as os from '@/os';
+import { stream } from '@/stream';
+import { i18n } from '@/i18n';
-export default defineComponent({
- props: {
- user: {
- type: Object,
- required: true
- },
- full: {
- type: Boolean,
- required: false,
- default: false,
- },
- large: {
- type: Boolean,
- required: false,
- default: false,
- },
- },
-
- data() {
- return {
- isFollowing: this.user.isFollowing,
- hasPendingFollowRequestFromYou: this.user.hasPendingFollowRequestFromYou,
- wait: false,
- connection: null,
- };
- },
-
- created() {
- // 渡されたユーザー情報が不完全な場合
- if (this.user.isFollowing == null) {
- os.api('users/show', {
- userId: this.user.id
- }).then(u => {
- this.isFollowing = u.isFollowing;
- this.hasPendingFollowRequestFromYou = u.hasPendingFollowRequestFromYou;
- });
- }
- },
-
- mounted() {
- this.connection = markRaw(os.stream.useChannel('main'));
+const props = withDefaults(defineProps<{
+ user: Misskey.entities.UserDetailed,
+ full?: boolean,
+ large?: boolean,
+}>(), {
+ full: false,
+ large: false,
+});
- this.connection.on('follow', this.onFollowChange);
- this.connection.on('unfollow', this.onFollowChange);
- },
+const isFollowing = ref(props.user.isFollowing);
+const hasPendingFollowRequestFromYou = ref(props.user.hasPendingFollowRequestFromYou);
+const wait = ref(false);
+const connection = stream.useChannel('main');
- beforeUnmount() {
- this.connection.dispose();
- },
+if (props.user.isFollowing == null) {
+ os.api('users/show', {
+ userId: props.user.id
+ }).then(u => {
+ isFollowing.value = u.isFollowing;
+ hasPendingFollowRequestFromYou.value = u.hasPendingFollowRequestFromYou;
+ });
+}
- methods: {
- onFollowChange(user) {
- if (user.id == this.user.id) {
- this.isFollowing = user.isFollowing;
- this.hasPendingFollowRequestFromYou = user.hasPendingFollowRequestFromYou;
- }
- },
+function onFollowChange(user: Misskey.entities.UserDetailed) {
+ if (user.id == props.user.id) {
+ isFollowing.value = user.isFollowing;
+ hasPendingFollowRequestFromYou.value = user.hasPendingFollowRequestFromYou;
+ }
+}
- async onClick() {
- this.wait = true;
+async function onClick() {
+ wait.value = true;
- try {
- if (this.isFollowing) {
- const { canceled } = await os.confirm({
- type: 'warning',
- text: this.$t('unfollowConfirm', { name: this.user.name || this.user.username }),
- });
+ try {
+ if (isFollowing.value) {
+ const { canceled } = await os.confirm({
+ type: 'warning',
+ text: i18n.t('unfollowConfirm', { name: props.user.name || props.user.username }),
+ });
- if (canceled) return;
+ if (canceled) return;
- await os.api('following/delete', {
- userId: this.user.id
- });
- } else {
- if (this.hasPendingFollowRequestFromYou) {
- await os.api('following/requests/cancel', {
- userId: this.user.id
- });
- } else if (this.user.isLocked) {
- await os.api('following/create', {
- userId: this.user.id
- });
- this.hasPendingFollowRequestFromYou = true;
- } else {
- await os.api('following/create', {
- userId: this.user.id
- });
- this.hasPendingFollowRequestFromYou = true;
- }
- }
- } catch (e) {
- console.error(e);
- } finally {
- this.wait = false;
+ await os.api('following/delete', {
+ userId: props.user.id
+ });
+ } else {
+ if (hasPendingFollowRequestFromYou.value) {
+ await os.api('following/requests/cancel', {
+ userId: props.user.id
+ });
+ } else if (props.user.isLocked) {
+ await os.api('following/create', {
+ userId: props.user.id
+ });
+ hasPendingFollowRequestFromYou.value = true;
+ } else {
+ await os.api('following/create', {
+ userId: props.user.id
+ });
+ hasPendingFollowRequestFromYou.value = true;
}
}
+ } catch (e) {
+ console.error(e);
+ } finally {
+ wait.value = false;
}
+}
+
+onMounted(() => {
+ connection.on('follow', onFollowChange);
+ connection.on('unfollow', onFollowChange);
+});
+
+onBeforeUnmount(() => {
+ connection.dispose();
});
</script>
diff --git a/packages/client/src/components/forgot-password.vue b/packages/client/src/components/forgot-password.vue
index b03a6133b4..c74e1ac75e 100644
--- a/packages/client/src/components/forgot-password.vue
+++ b/packages/client/src/components/forgot-password.vue
@@ -2,72 +2,64 @@
<XModalWindow ref="dialog"
:width="370"
:height="400"
- @close="$refs.dialog.close()"
- @closed="$emit('closed')"
+ @close="dialog.close()"
+ @closed="emit('closed')"
>
- <template #header>{{ $ts.forgotPassword }}</template>
+ <template #header>{{ i18n.locale.forgotPassword }}</template>
- <form v-if="$instance.enableEmail" class="bafeceda" @submit.prevent="onSubmit">
+ <form v-if="instance.enableEmail" class="bafeceda" @submit.prevent="onSubmit">
<div class="main _formRoot">
<MkInput v-model="username" class="_formBlock" type="text" pattern="^[a-zA-Z0-9_]+$" spellcheck="false" autofocus required>
- <template #label>{{ $ts.username }}</template>
+ <template #label>{{ i18n.locale.username }}</template>
<template #prefix>@</template>
</MkInput>
<MkInput v-model="email" class="_formBlock" type="email" spellcheck="false" required>
- <template #label>{{ $ts.emailAddress }}</template>
- <template #caption>{{ $ts._forgotPassword.enterEmail }}</template>
+ <template #label>{{ i18n.locale.emailAddress }}</template>
+ <template #caption>{{ i18n.locale._forgotPassword.enterEmail }}</template>
</MkInput>
- <MkButton class="_formBlock" type="submit" :disabled="processing" primary style="margin: 0 auto;">{{ $ts.send }}</MkButton>
+ <MkButton class="_formBlock" type="submit" :disabled="processing" primary style="margin: 0 auto;">{{ i18n.locale.send }}</MkButton>
</div>
<div class="sub">
- <MkA to="/about" class="_link">{{ $ts._forgotPassword.ifNoEmail }}</MkA>
+ <MkA to="/about" class="_link">{{ i18n.locale._forgotPassword.ifNoEmail }}</MkA>
</div>
</form>
- <div v-else>
- {{ $ts._forgotPassword.contactAdmin }}
+ <div v-else class="bafecedb">
+ {{ i18n.locale._forgotPassword.contactAdmin }}
</div>
</XModalWindow>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
+<script lang="ts" setup>
+import { } from 'vue';
import XModalWindow from '@/components/ui/modal-window.vue';
import MkButton from '@/components/ui/button.vue';
import MkInput from '@/components/form/input.vue';
import * as os from '@/os';
+import { instance } from '@/instance';
+import { i18n } from '@/i18n';
-export default defineComponent({
- components: {
- XModalWindow,
- MkButton,
- MkInput,
- },
+const emit = defineEmits<{
+ (e: 'done'): void;
+ (e: 'closed'): void;
+}>();
- emits: ['done', 'closed'],
+let dialog: InstanceType<typeof XModalWindow> = $ref();
- data() {
- return {
- username: '',
- email: '',
- processing: false,
- };
- },
+let username = $ref('');
+let email = $ref('');
+let processing = $ref(false);
- methods: {
- async onSubmit() {
- this.processing = true;
- await os.apiWithDialog('request-reset-password', {
- username: this.username,
- email: this.email,
- });
-
- this.$emit('done');
- this.$refs.dialog.close();
- }
- }
-});
+async function onSubmit() {
+ processing = true;
+ await os.apiWithDialog('request-reset-password', {
+ username,
+ email,
+ });
+ emit('done');
+ dialog.close();
+}
</script>
<style lang="scss" scoped>
@@ -81,4 +73,8 @@ export default defineComponent({
padding: 24px;
}
}
+
+.bafecedb {
+ padding: 24px;
+}
</style>
diff --git a/packages/client/src/components/form/folder.vue b/packages/client/src/components/form/folder.vue
new file mode 100644
index 0000000000..571afe50c0
--- /dev/null
+++ b/packages/client/src/components/form/folder.vue
@@ -0,0 +1,107 @@
+<template>
+<div class="dwzlatin" :class="{ opened }">
+ <div class="header _button" @click="toggle">
+ <span class="icon"><slot name="icon"></slot></span>
+ <span class="text"><slot name="label"></slot></span>
+ <span class="right">
+ <span class="text"><slot name="suffix"></slot></span>
+ <i v-if="opened" class="fas fa-angle-up icon"></i>
+ <i v-else class="fas fa-angle-down icon"></i>
+ </span>
+ </div>
+ <keep-alive>
+ <div v-if="openedAtLeastOnce" v-show="opened" class="body">
+ <MkSpacer :margin-min="14" :margin-max="22">
+ <slot></slot>
+ </MkSpacer>
+ </div>
+ </keep-alive>
+</div>
+</template>
+
+<script lang="ts" setup>
+const props = withDefaults(defineProps<{
+ defaultOpen: boolean;
+}>(), {
+ defaultOpen: false,
+})
+
+let opened = $ref(props.defaultOpen);
+let openedAtLeastOnce = $ref(props.defaultOpen);
+
+const toggle = () => {
+ opened = !opened;
+ if (opened) {
+ openedAtLeastOnce = true;
+ }
+};
+</script>
+
+<style lang="scss" scoped>
+.dwzlatin {
+ display: block;
+
+ > .header {
+ display: flex;
+ align-items: center;
+ width: 100%;
+ box-sizing: border-box;
+ padding: 12px 14px 12px 14px;
+ background: var(--buttonBg);
+ border-radius: 6px;
+
+ &:hover {
+ text-decoration: none;
+ background: var(--buttonHoverBg);
+ }
+
+ &.active {
+ color: var(--accent);
+ background: var(--buttonHoverBg);
+ }
+
+ > .icon {
+ margin-right: 0.75em;
+ flex-shrink: 0;
+ text-align: center;
+ opacity: 0.8;
+
+ &:empty {
+ display: none;
+
+ & + .text {
+ padding-left: 4px;
+ }
+ }
+ }
+
+ > .text {
+ white-space: nowrap;
+ text-overflow: ellipsis;
+ overflow: hidden;
+ padding-right: 12px;
+ }
+
+ > .right {
+ margin-left: auto;
+ opacity: 0.7;
+ white-space: nowrap;
+
+ > .text:not(:empty) {
+ margin-right: 0.75em;
+ }
+ }
+ }
+
+ > .body {
+ background: var(--panel);
+ border-radius: 0 0 6px 6px;
+ }
+
+ &.opened {
+ > .header {
+ border-radius: 6px 6px 0 0;
+ }
+ }
+}
+</style>
diff --git a/packages/client/src/components/form/group.vue b/packages/client/src/components/form/group.vue
index 2fc203f1b9..1e8376ca44 100644
--- a/packages/client/src/components/form/group.vue
+++ b/packages/client/src/components/form/group.vue
@@ -1,5 +1,5 @@
<template>
-<div v-sticky-container v-panel class="adfeebaf _formBlock">
+<div v-sticky-container class="adfeebaf _formBlock">
<div class="label"><slot name="label"></slot></div>
<div class="main _formRoot">
<slot></slot>
@@ -17,6 +17,7 @@ export default defineComponent({
<style lang="scss" scoped>
.adfeebaf {
padding: 24px 24px;
+ border: solid 1px var(--divider);
border-radius: var(--radius);
> .label {
diff --git a/packages/client/src/components/form/input.vue b/packages/client/src/components/form/input.vue
index 3533f4f27b..7165671af3 100644
--- a/packages/client/src/components/form/input.vue
+++ b/packages/client/src/components/form/input.vue
@@ -167,7 +167,7 @@ export default defineComponent({
// このコンポーネントが作成された時、非表示状態である場合がある
// 非表示状態だと要素の幅などは0になってしまうので、定期的に計算する
- const clock = setInterval(() => {
+ const clock = window.setInterval(() => {
if (prefixEl.value) {
if (prefixEl.value.offsetWidth) {
inputEl.value.style.paddingLeft = prefixEl.value.offsetWidth + 'px';
@@ -181,7 +181,7 @@ export default defineComponent({
}, 100);
onUnmounted(() => {
- clearInterval(clock);
+ window.clearInterval(clock);
});
});
});
diff --git a/packages/client/src/components/form/pagination.vue b/packages/client/src/components/form/pagination.vue
deleted file mode 100644
index 3d3b40a783..0000000000
--- a/packages/client/src/components/form/pagination.vue
+++ /dev/null
@@ -1,44 +0,0 @@
-<template>
-<FormSlot>
- <template #label><slot name="label"></slot></template>
- <div class="abcaccfa">
- <slot :items="items"></slot>
- <div v-if="empty" key="_empty_" class="empty">
- <slot name="empty"></slot>
- </div>
- <MkButton v-show="more" class="button" :disabled="moreFetching" :style="{ cursor: moreFetching ? 'wait' : 'pointer' }" @click="fetchMore">
- <template v-if="!moreFetching">{{ $ts.loadMore }}</template>
- <template v-if="moreFetching"><MkLoading inline/></template>
- </MkButton>
- </div>
-</FormSlot>
-</template>
-
-<script lang="ts">
-import { defineComponent } from 'vue';
-import MkButton from '@/components/ui/button.vue';
-import FormSlot from './slot.vue';
-import paging from '@/scripts/paging';
-
-export default defineComponent({
- components: {
- MkButton,
- FormSlot,
- },
-
- mixins: [
- paging({}),
- ],
-
- props: {
- pagination: {
- required: true
- },
- },
-});
-</script>
-
-<style lang="scss" scoped>
-.abcaccfa {
-}
-</style>
diff --git a/packages/client/src/components/form/radio.vue b/packages/client/src/components/form/radio.vue
index f0b8c71376..2becbec6f3 100644
--- a/packages/client/src/components/form/radio.vue
+++ b/packages/client/src/components/form/radio.vue
@@ -1,6 +1,6 @@
<template>
<div
- v-panel
+ v-adaptive-border
class="novjtctn"
:class="{ disabled, checked }"
:aria-checked="checked"
@@ -53,7 +53,10 @@ export default defineComponent({
display: inline-block;
text-align: left;
cursor: pointer;
- padding: 11px 14px;
+ padding: 10px 12px;
+ background-color: var(--panel);
+ background-clip: padding-box !important;
+ border: solid 1px var(--panel);
border-radius: 6px;
transition: all 0.3s;
@@ -69,9 +72,13 @@ export default defineComponent({
}
}
+ &:hover {
+ border-color: var(--inputBorderHover) !important;
+ }
+
&.checked {
- background: var(--accentedBg) !important;
- border-color: var(--accent);
+ background-color: var(--accentedBg) !important;
+ border-color: var(--accentedBg) !important;
color: var(--accent);
&, * {
@@ -89,11 +96,6 @@ export default defineComponent({
}
}
- &:hover {
- border-color: var(--inputBorderHover);
- color: var(--accent);
- }
-
> input {
position: absolute;
width: 0;
diff --git a/packages/client/src/components/form/section.vue b/packages/client/src/components/form/section.vue
index bc2ab966b8..c6e34ef1cc 100644
--- a/packages/client/src/components/form/section.vue
+++ b/packages/client/src/components/form/section.vue
@@ -1,5 +1,5 @@
<template>
-<div v-size="{ max: [500] }" v-sticky-container class="vrtktovh _formBlock">
+<div class="vrtktovh _formBlock">
<div class="label"><slot name="label"></slot></div>
<div class="main _formRoot">
<slot></slot>
@@ -7,20 +7,13 @@
</div>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
-
-export default defineComponent({
-
-});
+<script lang="ts" setup>
</script>
<style lang="scss" scoped>
.vrtktovh {
- margin: 0;
border-top: solid 0.5px var(--divider);
border-bottom: solid 0.5px var(--divider);
- padding: 24px 0;
& + .vrtktovh {
border-top: none;
@@ -36,7 +29,7 @@ export default defineComponent({
> .label {
font-weight: bold;
- padding: 0 0 16px 0;
+ margin: 1.5em 0 16px 0;
&:empty {
display: none;
@@ -44,6 +37,7 @@ export default defineComponent({
}
> .main {
+ margin: 1.5em 0;
}
}
</style>
diff --git a/packages/client/src/components/form/select.vue b/packages/client/src/components/form/select.vue
index afc53ca9c8..87196027a8 100644
--- a/packages/client/src/components/form/select.vue
+++ b/packages/client/src/components/form/select.vue
@@ -117,7 +117,7 @@ export default defineComponent({
// このコンポーネントが作成された時、非表示状態である場合がある
// 非表示状態だと要素の幅などは0になってしまうので、定期的に計算する
- const clock = setInterval(() => {
+ const clock = window.setInterval(() => {
if (prefixEl.value) {
if (prefixEl.value.offsetWidth) {
inputEl.value.style.paddingLeft = prefixEl.value.offsetWidth + 'px';
@@ -131,7 +131,7 @@ export default defineComponent({
}, 100);
onUnmounted(() => {
- clearInterval(clock);
+ window.clearInterval(clock);
});
});
});
diff --git a/packages/client/src/components/form/split.vue b/packages/client/src/components/form/split.vue
new file mode 100644
index 0000000000..676b293967
--- /dev/null
+++ b/packages/client/src/components/form/split.vue
@@ -0,0 +1,27 @@
+<template>
+<div class="terlnhxf _formBlock">
+ <slot></slot>
+</div>
+</template>
+
+<script lang="ts" setup>
+const props = withDefaults(defineProps<{
+ minWidth: number;
+}>(), {
+ minWidth: 210,
+});
+
+const minWidth = props.minWidth + 'px';
+</script>
+
+<style lang="scss" scoped>
+.terlnhxf {
+ display: grid;
+ grid-template-columns: repeat(auto-fill, minmax(v-bind('minWidth'), 1fr));
+ grid-gap: 12px;
+
+ > ::v-deep(*) {
+ margin: 0 !important;
+ }
+}
+</style>
diff --git a/packages/client/src/components/form/suspense.vue b/packages/client/src/components/form/suspense.vue
index 4d5debe604..2ad55dacae 100644
--- a/packages/client/src/components/form/suspense.vue
+++ b/packages/client/src/components/form/suspense.vue
@@ -1,5 +1,5 @@
<template>
-<transition name="fade" mode="out-in">
+<transition :name="$store.state.animation ? 'fade' : ''" mode="out-in">
<div v-if="pending">
<MkLoading/>
</div>
diff --git a/packages/client/src/components/form/switch.vue b/packages/client/src/components/form/switch.vue
index aa9b09215e..f8a07b4caa 100644
--- a/packages/client/src/components/form/switch.vue
+++ b/packages/client/src/components/form/switch.vue
@@ -13,7 +13,8 @@
<i class="check fas fa-check"></i>
</span>
<span class="label">
- <span @click="toggle"><slot></slot></span>
+ <!-- TODO: 無名slotの方は廃止 -->
+ <span @click="toggle"><slot name="label"></slot><slot></slot></span>
<p class="caption"><slot name="caption"></slot></p>
</span>
</div>
@@ -110,7 +111,7 @@ export default defineComponent({
}
> .label {
- margin-left: 16px;
+ margin-left: 12px;
margin-top: 2px;
display: block;
transition: inherit;
diff --git a/packages/client/src/components/global/a.vue b/packages/client/src/components/global/a.vue
index 77ee7525a4..cf7385ca22 100644
--- a/packages/client/src/components/global/a.vue
+++ b/packages/client/src/components/global/a.vue
@@ -4,130 +4,114 @@
</a>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
+<script lang="ts" setup>
+import { inject } from 'vue';
import * as os from '@/os';
import copyToClipboard from '@/scripts/copy-to-clipboard';
import { router } from '@/router';
import { url } from '@/config';
-import { popout } from '@/scripts/popout';
-import { ColdDeviceStorage } from '@/store';
+import { popout as popout_ } from '@/scripts/popout';
+import { i18n } from '@/i18n';
+import { defaultStore } from '@/store';
-export default defineComponent({
- inject: {
- navHook: {
- default: null
- },
- sideViewHook: {
- default: null
- }
- },
+const props = withDefaults(defineProps<{
+ to: string;
+ activeClass?: null | string;
+ behavior?: null | 'window' | 'browser' | 'modalWindow';
+}>(), {
+ activeClass: null,
+ behavior: null,
+});
- props: {
- to: {
- type: String,
- required: true,
- },
- activeClass: {
- type: String,
- required: false,
- },
- behavior: {
- type: String,
- required: false,
- },
- },
+const navHook = inject('navHook', null);
+const sideViewHook = inject('sideViewHook', null);
- computed: {
- active() {
- if (this.activeClass == null) return false;
- const resolved = router.resolve(this.to);
- if (resolved.path == this.$route.path) return true;
- if (resolved.name == null) return false;
- if (this.$route.name == null) return false;
- return resolved.name == this.$route.name;
- }
- },
+const active = $computed(() => {
+ if (props.activeClass == null) return false;
+ const resolved = router.resolve(props.to);
+ if (resolved.path === router.currentRoute.value.path) return true;
+ if (resolved.name == null) return false;
+ if (router.currentRoute.value.name == null) return false;
+ return resolved.name === router.currentRoute.value.name;
+});
- methods: {
- onContextmenu(e) {
- if (window.getSelection().toString() !== '') return;
- os.contextMenu([{
- type: 'label',
- text: this.to,
- }, {
- icon: 'fas fa-window-maximize',
- text: this.$ts.openInWindow,
- action: () => {
- os.pageWindow(this.to);
- }
- }, this.sideViewHook ? {
- icon: 'fas fa-columns',
- text: this.$ts.openInSideView,
- action: () => {
- this.sideViewHook(this.to);
- }
- } : undefined, {
- icon: 'fas fa-expand-alt',
- text: this.$ts.showInPage,
- action: () => {
- this.$router.push(this.to);
- }
- }, null, {
- icon: 'fas fa-external-link-alt',
- text: this.$ts.openInNewTab,
- action: () => {
- window.open(this.to, '_blank');
- }
- }, {
- icon: 'fas fa-link',
- text: this.$ts.copyLink,
- action: () => {
- copyToClipboard(`${url}${this.to}`);
- }
- }], e);
- },
+function onContextmenu(ev) {
+ const selection = window.getSelection();
+ if (selection && selection.toString() !== '') return;
+ os.contextMenu([{
+ type: 'label',
+ text: props.to,
+ }, {
+ icon: 'fas fa-window-maximize',
+ text: i18n.locale.openInWindow,
+ action: () => {
+ os.pageWindow(props.to);
+ }
+ }, sideViewHook ? {
+ icon: 'fas fa-columns',
+ text: i18n.locale.openInSideView,
+ action: () => {
+ sideViewHook(props.to);
+ }
+ } : undefined, {
+ icon: 'fas fa-expand-alt',
+ text: i18n.locale.showInPage,
+ action: () => {
+ router.push(props.to);
+ }
+ }, null, {
+ icon: 'fas fa-external-link-alt',
+ text: i18n.locale.openInNewTab,
+ action: () => {
+ window.open(props.to, '_blank');
+ }
+ }, {
+ icon: 'fas fa-link',
+ text: i18n.locale.copyLink,
+ action: () => {
+ copyToClipboard(`${url}${props.to}`);
+ }
+ }], ev);
+}
- window() {
- os.pageWindow(this.to);
- },
+function openWindow() {
+ os.pageWindow(props.to);
+}
- modalWindow() {
- os.modalPageWindow(this.to);
- },
+function modalWindow() {
+ os.modalPageWindow(props.to);
+}
- popout() {
- popout(this.to);
- },
+function popout() {
+ popout_(props.to);
+}
- nav() {
- if (this.behavior === 'browser') {
- location.href = this.to;
- return;
- }
+function nav() {
+ if (props.behavior === 'browser') {
+ location.href = props.to;
+ return;
+ }
- if (this.behavior) {
- if (this.behavior === 'window') {
- return this.window();
- } else if (this.behavior === 'modalWindow') {
- return this.modalWindow();
- }
- }
+ if (props.behavior) {
+ if (props.behavior === 'window') {
+ return openWindow();
+ } else if (props.behavior === 'modalWindow') {
+ return modalWindow();
+ }
+ }
- if (this.navHook) {
- this.navHook(this.to);
- } else {
- if (this.$store.state.defaultSideView && this.sideViewHook && this.to !== '/') {
- return this.sideViewHook(this.to);
- }
+ if (navHook) {
+ navHook(props.to);
+ } else {
+ if (defaultStore.state.defaultSideView && sideViewHook && props.to !== '/') {
+ return sideViewHook(props.to);
+ }
- if (this.$router.currentRoute.value.path === this.to) {
- window.scroll({ top: 0, behavior: 'smooth' });
- } else {
- this.$router.push(this.to);
- }
- }
+ if (router.currentRoute.value.path === props.to) {
+ window.scroll({ top: 0, behavior: 'smooth' });
+ } else {
+ router.push(props.to);
}
}
-});
+}
</script>
diff --git a/packages/client/src/components/global/acct.vue b/packages/client/src/components/global/acct.vue
index 018826153c..c3e806b5fb 100644
--- a/packages/client/src/components/global/acct.vue
+++ b/packages/client/src/components/global/acct.vue
@@ -5,28 +5,17 @@
</span>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
+<script lang="ts" setup>
+import * as misskey from 'misskey-js';
import { toUnicode } from 'punycode/';
-import { host } from '@/config';
+import { host as hostRaw } from '@/config';
-export default defineComponent({
- props: {
- user: {
- type: Object,
- required: true
- },
- detail: {
- type: Boolean,
- default: false
- },
- },
- data() {
- return {
- host: toUnicode(host),
- };
- }
-});
+defineProps<{
+ user: misskey.entities.UserDetailed;
+ detail?: boolean;
+}>();
+
+const host = toUnicode(hostRaw);
</script>
<style lang="scss" scoped>
diff --git a/packages/client/src/components/global/ad.vue b/packages/client/src/components/global/ad.vue
index 49046b00a7..180dabb2a2 100644
--- a/packages/client/src/components/global/ad.vue
+++ b/packages/client/src/components/global/ad.vue
@@ -20,7 +20,7 @@
<script lang="ts">
import { defineComponent, ref } from 'vue';
-import { Instance, instance } from '@/instance';
+import { instance } from '@/instance';
import { host } from '@/config';
import MkButton from '@/components/ui/button.vue';
import { defaultStore } from '@/store';
@@ -48,9 +48,9 @@ export default defineComponent({
showMenu.value = !showMenu.value;
};
- const choseAd = (): Instance['ads'][number] | null => {
+ const choseAd = (): (typeof instance)['ads'][number] | null => {
if (props.specify) {
- return props.specify as Instance['ads'][number];
+ return props.specify as (typeof instance)['ads'][number];
}
const allAds = instance.ads.map(ad => defaultStore.state.mutedAds.includes(ad.id) ? {
diff --git a/packages/client/src/components/global/avatar.vue b/packages/client/src/components/global/avatar.vue
index 300e5e079f..27cfb6e4d4 100644
--- a/packages/client/src/components/global/avatar.vue
+++ b/packages/client/src/components/global/avatar.vue
@@ -1,74 +1,54 @@
<template>
-<span v-if="disableLink" v-user-preview="disablePreview ? undefined : user.id" class="eiwwqkts _noSelect" :class="{ cat, square: $store.state.squareAvatars }" :title="acct(user)" @click="onClick">
+<span v-if="disableLink" v-user-preview="disablePreview ? undefined : user.id" class="eiwwqkts _noSelect" :class="{ cat: user.isCat, square: $store.state.squareAvatars }" :style="{ color }" :title="acct(user)" @click="onClick">
<img class="inner" :src="url" decoding="async"/>
<MkUserOnlineIndicator v-if="showIndicator" class="indicator" :user="user"/>
</span>
-<MkA v-else v-user-preview="disablePreview ? undefined : user.id" class="eiwwqkts _noSelect" :class="{ cat, square: $store.state.squareAvatars }" :to="userPage(user)" :title="acct(user)" :target="target">
+<MkA v-else v-user-preview="disablePreview ? undefined : user.id" class="eiwwqkts _noSelect" :class="{ cat: user.isCat, square: $store.state.squareAvatars }" :style="{ color }" :to="userPage(user)" :title="acct(user)" :target="target">
<img class="inner" :src="url" decoding="async"/>
<MkUserOnlineIndicator v-if="showIndicator" class="indicator" :user="user"/>
</MkA>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
+<script lang="ts" setup>
+import { onMounted, watch } from 'vue';
+import * as misskey from 'misskey-js';
import { getStaticImageUrl } from '@/scripts/get-static-image-url';
import { extractAvgColorFromBlurhash } from '@/scripts/extract-avg-color-from-blurhash';
import { acct, userPage } from '@/filters/user';
import MkUserOnlineIndicator from '@/components/user-online-indicator.vue';
+import { defaultStore } from '@/store';
-export default defineComponent({
- components: {
- MkUserOnlineIndicator
- },
- props: {
- user: {
- type: Object,
- required: true
- },
- target: {
- required: false,
- default: null
- },
- disableLink: {
- required: false,
- default: false
- },
- disablePreview: {
- required: false,
- default: false
- },
- showIndicator: {
- required: false,
- default: false
- }
- },
- emits: ['click'],
- computed: {
- cat(): boolean {
- return this.user.isCat;
- },
- url(): string {
- return this.$store.state.disableShowingAnimatedImages
- ? getStaticImageUrl(this.user.avatarUrl)
- : this.user.avatarUrl;
- },
- },
- watch: {
- 'user.avatarBlurhash'() {
- if (this.$el == null) return;
- this.$el.style.color = extractAvgColorFromBlurhash(this.user.avatarBlurhash);
- }
- },
- mounted() {
- this.$el.style.color = extractAvgColorFromBlurhash(this.user.avatarBlurhash);
- },
- methods: {
- onClick(e) {
- this.$emit('click', e);
- },
- acct,
- userPage
- }
+const props = withDefaults(defineProps<{
+ user: misskey.entities.User;
+ target?: string | null;
+ disableLink?: boolean;
+ disablePreview?: boolean;
+ showIndicator?: boolean;
+}>(), {
+ target: null,
+ disableLink: false,
+ disablePreview: false,
+ showIndicator: false,
+});
+
+const emit = defineEmits<{
+ (e: 'click', ev: MouseEvent): void;
+}>();
+
+const url = $computed(() => defaultStore.state.disableShowingAnimatedImages
+ ? getStaticImageUrl(props.user.avatarUrl)
+ : props.user.avatarUrl);
+
+function onClick(ev: MouseEvent) {
+ emit('click', ev);
+}
+
+let color = $ref();
+
+watch(() => props.user.avatarBlurhash, () => {
+ color = extractAvgColorFromBlurhash(props.user.avatarBlurhash);
+}, {
+ immediate: true,
});
</script>
diff --git a/packages/client/src/components/global/error.vue b/packages/client/src/components/global/error.vue
index d759186167..98b96fb414 100644
--- a/packages/client/src/components/global/error.vue
+++ b/packages/client/src/components/global/error.vue
@@ -8,19 +8,8 @@
</transition>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
+<script lang="ts" setup>
import MkButton from '@/components/ui/button.vue';
-
-export default defineComponent({
- components: {
- MkButton,
- },
- data() {
- return {
- };
- },
-});
</script>
<style lang="scss" scoped>
diff --git a/packages/client/src/components/global/loading.vue b/packages/client/src/components/global/loading.vue
index 7bde53c12e..43ea1395ed 100644
--- a/packages/client/src/components/global/loading.vue
+++ b/packages/client/src/components/global/loading.vue
@@ -4,27 +4,17 @@
</div>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
+<script lang="ts" setup>
+import { } from 'vue';
-export default defineComponent({
- props: {
- inline: {
- type: Boolean,
- required: false,
- default: false
- },
- colored: {
- type: Boolean,
- required: false,
- default: true
- },
- mini: {
- type: Boolean,
- required: false,
- default: false
- },
- }
+const props = withDefaults(defineProps<{
+ inline?: boolean;
+ colored?: boolean;
+ mini?: boolean;
+}>(), {
+ inline: false,
+ colored: true,
+ mini: false,
});
</script>
diff --git a/packages/client/src/components/global/misskey-flavored-markdown.vue b/packages/client/src/components/global/misskey-flavored-markdown.vue
index ab20404909..243d8614ba 100644
--- a/packages/client/src/components/global/misskey-flavored-markdown.vue
+++ b/packages/client/src/components/global/misskey-flavored-markdown.vue
@@ -1,15 +1,23 @@
<template>
-<mfm-core v-bind="$attrs" class="havbbuyv" :class="{ nowrap: $attrs['nowrap'] }"/>
+<MfmCore :text="text" :plain="plain" :nowrap="nowrap" :author="author" :customEmojis="customEmojis" :isNote="isNote" class="havbbuyv" :class="{ nowrap }"/>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
+<script lang="ts" setup>
+import { } from 'vue';
import MfmCore from '@/components/mfm';
-export default defineComponent({
- components: {
- MfmCore
- }
+const props = withDefaults(defineProps<{
+ text: string;
+ plain?: boolean;
+ nowrap?: boolean;
+ author?: any;
+ customEmojis?: any;
+ isNote?: boolean;
+}>(), {
+ plain: false,
+ nowrap: false,
+ author: null,
+ isNote: true,
});
</script>
diff --git a/packages/client/src/components/global/spacer.vue b/packages/client/src/components/global/spacer.vue
index e2f1d1aec7..8a1d7a4e8a 100644
--- a/packages/client/src/components/global/spacer.vue
+++ b/packages/client/src/components/global/spacer.vue
@@ -40,7 +40,7 @@ export default defineComponent({
return;
}
- if (rect.width > props.contentMax || rect.width > 500) {
+ if (rect.width > props.contentMax || (rect.width > 360 && window.innerWidth > 400)) {
margin.value = props.marginMax;
} else {
margin.value = props.marginMin;
diff --git a/packages/client/src/components/global/sticky-container.vue b/packages/client/src/components/global/sticky-container.vue
index 859b2c1d73..89d397f082 100644
--- a/packages/client/src/components/global/sticky-container.vue
+++ b/packages/client/src/components/global/sticky-container.vue
@@ -45,7 +45,7 @@ export default defineComponent({
calc();
const observer = new MutationObserver(() => {
- setTimeout(() => {
+ window.setTimeout(() => {
calc();
}, 100);
});
diff --git a/packages/client/src/components/global/time.vue b/packages/client/src/components/global/time.vue
index 6a330a2307..d2788264c5 100644
--- a/packages/client/src/components/global/time.vue
+++ b/packages/client/src/components/global/time.vue
@@ -1,73 +1,57 @@
<template>
<time :title="absolute">
- <template v-if="mode == 'relative'">{{ relative }}</template>
- <template v-else-if="mode == 'absolute'">{{ absolute }}</template>
- <template v-else-if="mode == 'detail'">{{ absolute }} ({{ relative }})</template>
+ <template v-if="mode === 'relative'">{{ relative }}</template>
+ <template v-else-if="mode === 'absolute'">{{ absolute }}</template>
+ <template v-else-if="mode === 'detail'">{{ absolute }} ({{ relative }})</template>
</time>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
+<script lang="ts" setup>
+import { onUnmounted } from 'vue';
+import { i18n } from '@/i18n';
-export default defineComponent({
- props: {
- time: {
- type: [Date, String],
- required: true
- },
- mode: {
- type: String,
- default: 'relative'
- }
- },
- data() {
- return {
- tickId: null,
- now: new Date()
- };
- },
- computed: {
- _time(): Date {
- return typeof this.time == 'string' ? new Date(this.time) : this.time;
- },
- absolute(): string {
- return this._time.toLocaleString();
- },
- relative(): string {
- const time = this._time;
- const ago = (this.now.getTime() - time.getTime()) / 1000/*ms*/;
- return (
- ago >= 31536000 ? this.$t('_ago.yearsAgo', { n: (~~(ago / 31536000)).toString() }) :
- ago >= 2592000 ? this.$t('_ago.monthsAgo', { n: (~~(ago / 2592000)).toString() }) :
- ago >= 604800 ? this.$t('_ago.weeksAgo', { n: (~~(ago / 604800)).toString() }) :
- ago >= 86400 ? this.$t('_ago.daysAgo', { n: (~~(ago / 86400)).toString() }) :
- ago >= 3600 ? this.$t('_ago.hoursAgo', { n: (~~(ago / 3600)).toString() }) :
- ago >= 60 ? this.$t('_ago.minutesAgo', { n: (~~(ago / 60)).toString() }) :
- ago >= 10 ? this.$t('_ago.secondsAgo', { n: (~~(ago % 60)).toString() }) :
- ago >= -1 ? this.$ts._ago.justNow :
- ago < -1 ? this.$ts._ago.future :
- this.$ts._ago.unknown);
- }
- },
- created() {
- if (this.mode == 'relative' || this.mode == 'detail') {
- this.tickId = window.requestAnimationFrame(this.tick);
- }
- },
- unmounted() {
- if (this.mode === 'relative' || this.mode === 'detail') {
- window.clearTimeout(this.tickId);
- }
- },
- methods: {
- tick() {
- // TODO: パフォーマンス向上のため、このコンポーネントが画面内に表示されている場合のみ更新する
- this.now = new Date();
+const props = withDefaults(defineProps<{
+ time: Date | string;
+ mode?: 'relative' | 'absolute' | 'detail';
+}>(), {
+ mode: 'relative',
+});
+
+const _time = typeof props.time == 'string' ? new Date(props.time) : props.time;
+const absolute = _time.toLocaleString();
- this.tickId = setTimeout(() => {
- window.requestAnimationFrame(this.tick);
- }, 10000);
- }
- }
+let now = $ref(new Date());
+const relative = $computed(() => {
+ const ago = (now.getTime() - _time.getTime()) / 1000/*ms*/;
+ return (
+ ago >= 31536000 ? i18n.t('_ago.yearsAgo', { n: (~~(ago / 31536000)).toString() }) :
+ ago >= 2592000 ? i18n.t('_ago.monthsAgo', { n: (~~(ago / 2592000)).toString() }) :
+ ago >= 604800 ? i18n.t('_ago.weeksAgo', { n: (~~(ago / 604800)).toString() }) :
+ ago >= 86400 ? i18n.t('_ago.daysAgo', { n: (~~(ago / 86400)).toString() }) :
+ ago >= 3600 ? i18n.t('_ago.hoursAgo', { n: (~~(ago / 3600)).toString() }) :
+ ago >= 60 ? i18n.t('_ago.minutesAgo', { n: (~~(ago / 60)).toString() }) :
+ ago >= 10 ? i18n.t('_ago.secondsAgo', { n: (~~(ago % 60)).toString() }) :
+ ago >= -1 ? i18n.locale._ago.justNow :
+ ago < -1 ? i18n.locale._ago.future :
+ i18n.locale._ago.unknown);
});
+
+function tick() {
+ // TODO: パフォーマンス向上のため、このコンポーネントが画面内に表示されている場合のみ更新する
+ now = new Date();
+
+ tickId = window.setTimeout(() => {
+ window.requestAnimationFrame(tick);
+ }, 10000);
+}
+
+let tickId: number;
+
+if (props.mode === 'relative' || props.mode === 'detail') {
+ tickId = window.requestAnimationFrame(tick);
+
+ onUnmounted(() => {
+ window.clearTimeout(tickId);
+ });
+}
</script>
diff --git a/packages/client/src/components/global/user-name.vue b/packages/client/src/components/global/user-name.vue
index bc93a8ea30..090de3df30 100644
--- a/packages/client/src/components/global/user-name.vue
+++ b/packages/client/src/components/global/user-name.vue
@@ -2,19 +2,14 @@
<Mfm :text="user.name || user.username" :plain="true" :nowrap="nowrap" :custom-emojis="user.emojis"/>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
+<script lang="ts" setup>
+import { } from 'vue';
+import * as misskey from 'misskey-js';
-export default defineComponent({
- props: {
- user: {
- type: Object,
- required: true
- },
- nowrap: {
- type: Boolean,
- default: true
- },
- }
+const props = withDefaults(defineProps<{
+ user: misskey.entities.User;
+ nowrap?: boolean;
+}>(), {
+ nowrap: true,
});
</script>
diff --git a/packages/client/src/components/google.vue b/packages/client/src/components/google.vue
index a39168b80f..210ca72bfe 100644
--- a/packages/client/src/components/google.vue
+++ b/packages/client/src/components/google.vue
@@ -5,31 +5,18 @@
</div>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
-import * as os from '@/os';
+<script lang="ts" setup>
+import { ref } from 'vue';
-export default defineComponent({
- props: {
- q: {
- type: String,
- required: true,
- }
- },
- data() {
- return {
- query: null,
- };
- },
- mounted() {
- this.query = this.q;
- },
- methods: {
- search() {
- window.open(`https://www.google.com/search?q=${this.query}`, '_blank');
- }
- }
-});
+const props = defineProps<{
+ q: string;
+}>();
+
+const query = ref(props.q);
+
+const search = () => {
+ window.open(`https://www.google.com/search?q=${query.value}`, '_blank');
+};
</script>
<style lang="scss" scoped>
diff --git a/packages/client/src/components/image-viewer.vue b/packages/client/src/components/image-viewer.vue
index 8584b91a61..c39076df16 100644
--- a/packages/client/src/components/image-viewer.vue
+++ b/packages/client/src/components/image-viewer.vue
@@ -1,8 +1,8 @@
<template>
-<MkModal ref="modal" :z-priority="'middle'" @click="$refs.modal.close()" @closed="$emit('closed')">
+<MkModal ref="modal" :z-priority="'middle'" @click="modal.close()" @closed="emit('closed')">
<div class="xubzgfga">
<header>{{ image.name }}</header>
- <img :src="image.url" :alt="image.comment" :title="image.comment" @click="$refs.modal.close()"/>
+ <img :src="image.url" :alt="image.comment" :title="image.comment" @click="modal.close()"/>
<footer>
<span>{{ image.type }}</span>
<span>{{ bytes(image.size) }}</span>
@@ -12,31 +12,23 @@
</MkModal>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
+<script lang="ts" setup>
+import { } from 'vue';
+import * as misskey from 'misskey-js';
import bytes from '@/filters/bytes';
import number from '@/filters/number';
import MkModal from '@/components/ui/modal.vue';
-export default defineComponent({
- components: {
- MkModal,
- },
-
- props: {
- image: {
- type: Object,
- required: true
- },
- },
+const props = withDefaults(defineProps<{
+ image: misskey.entities.DriveFile;
+}>(), {
+});
- emits: ['closed'],
+const emit = defineEmits<{
+ (e: 'closed'): void;
+}>();
- methods: {
- bytes,
- number,
- }
-});
+const modal = $ref<InstanceType<typeof MkModal>>();
</script>
<style lang="scss" scoped>
diff --git a/packages/client/src/components/img-with-blurhash.vue b/packages/client/src/components/img-with-blurhash.vue
index a000c699b6..06ad764403 100644
--- a/packages/client/src/components/img-with-blurhash.vue
+++ b/packages/client/src/components/img-with-blurhash.vue
@@ -5,67 +5,43 @@
</div>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
+<script lang="ts" setup>
+import { onMounted } from 'vue';
import { decode } from 'blurhash';
-export default defineComponent({
- props: {
- src: {
- type: String,
- required: false,
- default: null
- },
- hash: {
- type: String,
- required: true
- },
- alt: {
- type: String,
- required: false,
- default: '',
- },
- title: {
- type: String,
- required: false,
- default: null,
- },
- size: {
- type: Number,
- required: false,
- default: 64
- },
- cover: {
- type: Boolean,
- required: false,
- default: true,
- }
- },
+const props = withDefaults(defineProps<{
+ src?: string | null;
+ hash: string;
+ alt?: string;
+ title?: string | null;
+ size?: number;
+ cover?: boolean;
+}>(), {
+ src: null,
+ alt: '',
+ title: null,
+ size: 64,
+ cover: true,
+});
- data() {
- return {
- loaded: false,
- };
- },
+const canvas = $ref<HTMLCanvasElement>();
+let loaded = $ref(false);
- mounted() {
- this.draw();
- },
+function draw() {
+ if (props.hash == null) return;
+ const pixels = decode(props.hash, props.size, props.size);
+ const ctx = canvas.getContext('2d');
+ const imageData = ctx!.createImageData(props.size, props.size);
+ imageData.data.set(pixels);
+ ctx!.putImageData(imageData, 0, 0);
+}
- methods: {
- draw() {
- if (this.hash == null) return;
- const pixels = decode(this.hash, this.size, this.size);
- const ctx = (this.$refs.canvas as HTMLCanvasElement).getContext('2d');
- const imageData = ctx!.createImageData(this.size, this.size);
- imageData.data.set(pixels);
- ctx!.putImageData(imageData, 0, 0);
- },
+function onLoad() {
+ loaded = true;
+}
- onLoad() {
- this.loaded = true;
- }
- }
+onMounted(() => {
+ draw();
});
</script>
diff --git a/packages/client/src/components/instance-stats.vue b/packages/client/src/components/instance-stats.vue
index bc62998a4a..409c3a49ca 100644
--- a/packages/client/src/components/instance-stats.vue
+++ b/packages/client/src/components/instance-stats.vue
@@ -1,5 +1,5 @@
<template>
-<div class="zbcjwnqg" style="margin-top: -8px;">
+<div class="zbcjwnqg">
<div class="selects" style="display: flex;">
<MkSelect v-model="chartSrc" style="margin: 0; flex: 1;">
<optgroup :label="$ts.federation">
@@ -29,16 +29,16 @@
<option value="day">{{ $ts.perDay }}</option>
</MkSelect>
</div>
- <MkChart :src="chartSrc" :span="chartSpan" :limit="chartLimit" :detailed="detailed"></MkChart>
+ <div class="chart">
+ <MkChart :src="chartSrc" :span="chartSpan" :limit="chartLimit" :detailed="detailed"></MkChart>
+ </div>
</div>
</template>
<script lang="ts">
-import { defineComponent, onMounted, ref, watch } from 'vue';
+import { defineComponent, ref } from 'vue';
import MkSelect from '@/components/form/select.vue';
import MkChart from '@/components/chart.vue';
-import * as os from '@/os';
-import { defaultStore } from '@/store';
export default defineComponent({
components: {
@@ -74,7 +74,10 @@ export default defineComponent({
<style lang="scss" scoped>
.zbcjwnqg {
> .selects {
- padding: 8px 16px 0 16px;
+ }
+
+ > .chart {
+ padding: 8px 0 0 0;
}
}
</style>
diff --git a/packages/client/src/components/instance-ticker.vue b/packages/client/src/components/instance-ticker.vue
index 1ce5a1c2c1..77fd8bb344 100644
--- a/packages/client/src/components/instance-ticker.vue
+++ b/packages/client/src/components/instance-ticker.vue
@@ -1,41 +1,22 @@
<template>
<div class="hpaizdrt" :style="bg">
- <img v-if="info.faviconUrl" class="icon" :src="info.faviconUrl"/>
- <span class="name">{{ info.name }}</span>
+ <img v-if="instance.faviconUrl" class="icon" :src="instance.faviconUrl"/>
+ <span class="name">{{ instance.name }}</span>
</div>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
-import { instanceName } from '@/config';
+<script lang="ts" setup>
+import { } from 'vue';
-export default defineComponent({
- props: {
- instance: {
- type: Object,
- required: false
- },
- },
+const props = defineProps<{
+ instance: any; // TODO
+}>();
- data() {
- return {
- info: this.instance || {
- faviconUrl: '/favicon.ico',
- name: instanceName,
- themeColor: (document.querySelector('meta[name="theme-color-orig"]') as HTMLMetaElement)?.content
- }
- }
- },
+const themeColor = props.instance.themeColor || '#777777';
- computed: {
- bg(): any {
- const themeColor = this.info.themeColor || '#777777';
- return {
- background: `linear-gradient(90deg, ${themeColor}, ${themeColor + '00'})`
- };
- }
- }
-});
+const bg = {
+ background: `linear-gradient(90deg, ${themeColor}, ${themeColor + '00'})`
+};
</script>
<style lang="scss" scoped>
diff --git a/packages/client/src/components/key-value.vue b/packages/client/src/components/key-value.vue
index 6a9a948ce9..da98abd77c 100644
--- a/packages/client/src/components/key-value.vue
+++ b/packages/client/src/components/key-value.vue
@@ -1,5 +1,5 @@
<template>
-<div class="alqyeyti">
+<div class="alqyeyti" :class="{ oneline }">
<div class="key">
<slot name="key"></slot>
</div>
@@ -22,6 +22,11 @@ export default defineComponent({
required: false,
default: null,
},
+ oneline: {
+ type: Boolean,
+ required: false,
+ default: false,
+ },
},
setup(props) {
@@ -39,10 +44,30 @@ export default defineComponent({
<style lang="scss" scoped>
.alqyeyti {
+ > .key, > .value {
+ white-space: nowrap;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ }
+
> .key {
font-size: 0.85em;
padding: 0 0 0.25em 0;
opacity: 0.75;
}
+
+ &.oneline {
+ display: flex;
+
+ > .key {
+ width: 30%;
+ font-size: 1em;
+ padding: 0 8px 0 0;
+ }
+
+ > .value {
+ width: 70%;
+ }
+ }
}
</style>
diff --git a/packages/client/src/components/link.vue b/packages/client/src/components/link.vue
index 8b8cde6510..317c931cec 100644
--- a/packages/client/src/components/link.vue
+++ b/packages/client/src/components/link.vue
@@ -1,82 +1,36 @@
<template>
-<component :is="self ? 'MkA' : 'a'" class="xlcxczvw _link" :[attr]="self ? url.substr(local.length) : url" :rel="rel" :target="target"
+<component :is="self ? 'MkA' : 'a'" ref="el" class="xlcxczvw _link" :[attr]="self ? url.substr(local.length) : url" :rel="rel" :target="target"
:title="url"
- @mouseover="onMouseover"
- @mouseleave="onMouseleave"
>
<slot></slot>
<i v-if="target === '_blank'" class="fas fa-external-link-square-alt icon"></i>
</component>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
+<script lang="ts" setup>
+import { } from 'vue';
import { url as local } from '@/config';
-import { isTouchUsing } from '@/scripts/touch';
+import { useTooltip } from '@/scripts/use-tooltip';
import * as os from '@/os';
-export default defineComponent({
- props: {
- url: {
- type: String,
- required: true,
- },
- rel: {
- type: String,
- required: false,
- }
- },
- data() {
- const self = this.url.startsWith(local);
- return {
- local,
- self: self,
- attr: self ? 'to' : 'href',
- target: self ? null : '_blank',
- showTimer: null,
- hideTimer: null,
- checkTimer: null,
- close: null,
- };
- },
- methods: {
- async showPreview() {
- if (!document.body.contains(this.$el)) return;
- if (this.close) return;
+const props = withDefaults(defineProps<{
+ url: string;
+ rel?: null | string;
+}>(), {
+});
- const { dispose } = await os.popup(import('@/components/url-preview-popup.vue'), {
- url: this.url,
- source: this.$el
- });
+const self = props.url.startsWith(local);
+const attr = self ? 'to' : 'href';
+const target = self ? null : '_blank';
- this.close = () => {
- dispose();
- };
+const el = $ref();
- this.checkTimer = setInterval(() => {
- if (!document.body.contains(this.$el)) this.closePreview();
- }, 1000);
- },
- closePreview() {
- if (this.close) {
- clearInterval(this.checkTimer);
- this.close();
- this.close = null;
- }
- },
- onMouseover() {
- if (isTouchUsing) return;
- clearTimeout(this.showTimer);
- clearTimeout(this.hideTimer);
- this.showTimer = setTimeout(this.showPreview, 500);
- },
- onMouseleave() {
- if (isTouchUsing) return;
- clearTimeout(this.showTimer);
- clearTimeout(this.hideTimer);
- this.hideTimer = setTimeout(this.closePreview, 500);
- }
- }
+useTooltip($$(el), (showing) => {
+ os.popup(import('@/components/url-preview-popup.vue'), {
+ showing,
+ url: props.url,
+ source: el,
+ }, {}, 'closed');
});
</script>
diff --git a/packages/client/src/components/media-banner.vue b/packages/client/src/components/media-banner.vue
index 9dbfe3d0c6..5093f11e97 100644
--- a/packages/client/src/components/media-banner.vue
+++ b/packages/client/src/components/media-banner.vue
@@ -6,7 +6,7 @@
<span>{{ $ts.clickToShow }}</span>
</div>
<div v-else-if="media.type.startsWith('audio') && media.type !== 'audio/midi'" class="audio">
- <audio ref="audio"
+ <audio ref="audioEl"
class="audio"
:src="media.url"
:title="media.name"
@@ -25,34 +25,26 @@
</div>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
-import * as os from '@/os';
+<script lang="ts" setup>
+import { onMounted } from 'vue';
+import * as misskey from 'misskey-js';
import { ColdDeviceStorage } from '@/store';
-export default defineComponent({
- props: {
- media: {
- type: Object,
- required: true
- }
- },
- data() {
- return {
- hide: true,
- };
- },
- mounted() {
- const audioTag = this.$refs.audio as HTMLAudioElement;
- if (audioTag) audioTag.volume = ColdDeviceStorage.get('mediaVolume');
- },
- methods: {
- volumechange() {
- const audioTag = this.$refs.audio as HTMLAudioElement;
- ColdDeviceStorage.set('mediaVolume', audioTag.volume);
- },
- },
-})
+const props = withDefaults(defineProps<{
+ media: misskey.entities.DriveFile;
+}>(), {
+});
+
+const audioEl = $ref<HTMLAudioElement | null>();
+let hide = $ref(true);
+
+function volumechange() {
+ if (audioEl) ColdDeviceStorage.set('mediaVolume', audioEl.volume);
+}
+
+onMounted(() => {
+ if (audioEl) audioEl.volume = ColdDeviceStorage.get('mediaVolume');
+});
</script>
<style lang="scss" scoped>
diff --git a/packages/client/src/components/media-list.vue b/packages/client/src/components/media-list.vue
index 2970d06c97..efcbb12922 100644
--- a/packages/client/src/components/media-list.vue
+++ b/packages/client/src/components/media-list.vue
@@ -3,7 +3,7 @@
<XBanner v-for="media in mediaList.filter(media => !previewable(media))" :key="media.id" :media="media"/>
<div v-if="mediaList.filter(media => previewable(media)).length > 0" class="gird-container">
<div ref="gallery" :data-count="mediaList.filter(media => previewable(media)).length">
- <template v-for="media in mediaList">
+ <template v-for="media in mediaList.filter(media => previewable(media))">
<XVideo v-if="media.type.startsWith('video')" :key="media.id" :video="media"/>
<XImage v-else-if="media.type.startsWith('image')" :key="media.id" class="image" :data-id="media.id" :image="media" :raw="raw"/>
</template>
@@ -22,6 +22,7 @@ import XBanner from './media-banner.vue';
import XImage from './media-image.vue';
import XVideo from './media-video.vue';
import * as os from '@/os';
+import { FILE_TYPE_BROWSERSAFE } from '@/const';
import { defaultStore } from '@/store';
export default defineComponent({
@@ -44,18 +45,23 @@ export default defineComponent({
onMounted(() => {
const lightbox = new PhotoSwipeLightbox({
- dataSource: props.mediaList.filter(media => media.type.startsWith('image')).map(media => {
- const item = {
- src: media.url,
- w: media.properties.width,
- h: media.properties.height,
- alt: media.name,
- };
- if (media.properties.orientation != null && media.properties.orientation >= 5) {
- [item.w, item.h] = [item.h, item.w];
- }
- return item;
- }),
+ dataSource: props.mediaList
+ .filter(media => {
+ if (media.type === 'image/svg+xml') return true; // svgのwebpublicはpngなのでtrue
+ return media.type.startsWith('image') && FILE_TYPE_BROWSERSAFE.includes(media.type);
+ })
+ .map(media => {
+ const item = {
+ src: media.url,
+ w: media.properties.width,
+ h: media.properties.height,
+ alt: media.name,
+ };
+ if (media.properties.orientation != null && media.properties.orientation >= 5) {
+ [item.w, item.h] = [item.h, item.w];
+ }
+ return item;
+ }),
gallery: gallery.value,
children: '.image',
thumbSelector: '.image',
@@ -99,7 +105,9 @@ export default defineComponent({
});
const previewable = (file: misskey.entities.DriveFile): boolean => {
- return file.type.startsWith('video') || file.type.startsWith('image');
+ if (file.type === 'image/svg+xml') return true; // svgのwebpublic/thumbnailはpngなのでtrue
+ // FILE_TYPE_BROWSERSAFEに適合しないものはブラウザで表示するのに不適切
+ return (file.type.startsWith('video') || file.type.startsWith('image')) && FILE_TYPE_BROWSERSAFE.includes(file.type);
};
return {
diff --git a/packages/client/src/components/media-video.vue b/packages/client/src/components/media-video.vue
index a0dc57b657..680eb27e64 100644
--- a/packages/client/src/components/media-video.vue
+++ b/packages/client/src/components/media-video.vue
@@ -22,26 +22,16 @@
</div>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
-import * as os from '@/os';
+<script lang="ts" setup>
+import { ref } from 'vue';
+import * as misskey from 'misskey-js';
+import { defaultStore } from '@/store';
-export default defineComponent({
- props: {
- video: {
- type: Object,
- required: true
- }
- },
- data() {
- return {
- hide: true,
- };
- },
- created() {
- this.hide = (this.$store.state.nsfw === 'force') ? true : this.video.isSensitive && (this.$store.state.nsfw !== 'ignore');
- },
-});
+const props = defineProps<{
+ video: misskey.entities.DriveFile;
+}>();
+
+const hide = ref((defaultStore.state.nsfw === 'force') ? true : props.video.isSensitive && (defaultStore.state.nsfw !== 'ignore'));
</script>
<style lang="scss" scoped>
diff --git a/packages/client/src/components/mini-chart.vue b/packages/client/src/components/mini-chart.vue
index 2eb9ae8cbe..8c74eae876 100644
--- a/packages/client/src/components/mini-chart.vue
+++ b/packages/client/src/components/mini-chart.vue
@@ -63,10 +63,10 @@ export default defineComponent({
this.draw();
// Vueが何故かWatchを発動させない場合があるので
- this.clock = setInterval(this.draw, 1000);
+ this.clock = window.setInterval(this.draw, 1000);
},
beforeUnmount() {
- clearInterval(this.clock);
+ window.clearInterval(this.clock);
},
methods: {
draw() {
diff --git a/packages/client/src/components/modal-page-window.vue b/packages/client/src/components/modal-page-window.vue
index 3de1980820..2e17d5d030 100644
--- a/packages/client/src/components/modal-page-window.vue
+++ b/packages/client/src/components/modal-page-window.vue
@@ -153,8 +153,8 @@ export default defineComponent({
this.$refs.window.close();
},
- onContextmenu(e) {
- os.contextMenu(this.contextmenu, e);
+ onContextmenu(ev: MouseEvent) {
+ os.contextMenu(this.contextmenu, ev);
}
},
});
diff --git a/packages/client/src/components/note-detailed.vue b/packages/client/src/components/note-detailed.vue
index 55a02f1e73..a3b30f726e 100644
--- a/packages/client/src/components/note-detailed.vue
+++ b/packages/client/src/components/note-detailed.vue
@@ -4,12 +4,13 @@
v-show="!isDeleted"
v-hotkey="keymap"
v-size="{ max: [500, 450, 350, 300] }"
+ ref="el"
class="lxwezrsl _block"
:tabindex="!isDeleted ? '-1' : null"
:class="{ renote: isRenote }"
>
- <XSub v-for="note in conversation" :key="note.id" class="reply-to-more" :note="note"/>
- <XSub v-if="appearNote.reply" :note="appearNote.reply" class="reply-to"/>
+ <MkNoteSub v-for="note in conversation" :key="note.id" class="reply-to-more" :note="note"/>
+ <MkNoteSub v-if="appearNote.reply" :note="appearNote.reply" class="reply-to"/>
<div v-if="isRenote" class="renote">
<MkAvatar class="avatar" :user="note.user"/>
<i class="fas fa-retweet"></i>
@@ -107,7 +108,7 @@
</footer>
</div>
</article>
- <XSub v-for="note in replies" :key="note.id" :note="note" class="reply" :detail="true"/>
+ <MkNoteSub v-for="note in replies" :key="note.id" :note="note" class="reply" :detail="true"/>
</div>
<div v-else class="_panel muted" @click="muted = false">
<I18n :src="$ts.userSaysSomething" tag="small">
@@ -120,764 +121,171 @@
</div>
</template>
-<script lang="ts">
-import { defineAsyncComponent, defineComponent, markRaw } from 'vue';
+<script lang="ts" setup>
+import { computed, inject, onMounted, onUnmounted, reactive, ref } from 'vue';
import * as mfm from 'mfm-js';
-import { sum } from '@/scripts/array';
-import XSub from './note.sub.vue';
-import XNoteHeader from './note-header.vue';
+import * as misskey from 'misskey-js';
+import MkNoteSub from './MkNoteSub.vue';
import XNoteSimple from './note-simple.vue';
import XReactionsViewer from './reactions-viewer.vue';
import XMediaList from './media-list.vue';
import XCwButton from './cw-button.vue';
import XPoll from './poll.vue';
import XRenoteButton from './renote-button.vue';
+import MkUrlPreview from '@/components/url-preview.vue';
+import MkInstanceTicker from '@/components/instance-ticker.vue';
import { pleaseLogin } from '@/scripts/please-login';
-import { focusPrev, focusNext } from '@/scripts/focus';
-import { url } from '@/config';
-import copyToClipboard from '@/scripts/copy-to-clipboard';
import { checkWordMute } from '@/scripts/check-word-mute';
import { userPage } from '@/filters/user';
import { notePage } from '@/filters/note';
import * as os from '@/os';
-import { noteActions, noteViewInterruptors } from '@/store';
+import { defaultStore, noteViewInterruptors } from '@/store';
import { reactionPicker } from '@/scripts/reaction-picker';
import { extractUrlFromMfm } from '@/scripts/extract-url-from-mfm';
+import { $i } from '@/account';
+import { i18n } from '@/i18n';
+import { getNoteMenu } from '@/scripts/get-note-menu';
+import { useNoteCapture } from '@/scripts/use-note-capture';
-// TODO: note.vueとほぼ同じなので共通化したい
-export default defineComponent({
- components: {
- XSub,
- XNoteHeader,
- XNoteSimple,
- XReactionsViewer,
- XMediaList,
- XCwButton,
- XPoll,
- XRenoteButton,
- MkUrlPreview: defineAsyncComponent(() => import('@/components/url-preview.vue')),
- MkInstanceTicker: defineAsyncComponent(() => import('@/components/instance-ticker.vue')),
- },
+const props = defineProps<{
+ note: misskey.entities.Note;
+ pinned?: boolean;
+}>();
- inject: {
- inChannel: {
- default: null
- },
- },
+const inChannel = inject('inChannel', null);
- props: {
- note: {
- type: Object,
- required: true
- },
- },
+const isRenote = (
+ props.note.renote != null &&
+ props.note.text == null &&
+ props.note.fileIds.length === 0 &&
+ props.note.poll == null
+);
- emits: ['update:note'],
+const el = ref<HTMLElement>();
+const menuButton = ref<HTMLElement>();
+const renoteButton = ref<InstanceType<typeof XRenoteButton>>();
+const renoteTime = ref<HTMLElement>();
+const reactButton = ref<HTMLElement>();
+let appearNote = $ref(isRenote ? props.note.renote as misskey.entities.Note : props.note);
+const isMyRenote = $i && ($i.id === props.note.userId);
+const showContent = ref(false);
+const isDeleted = ref(false);
+const muted = ref(checkWordMute(appearNote, $i, defaultStore.state.mutedWords));
+const translation = ref(null);
+const translating = ref(false);
+const urls = appearNote.text ? extractUrlFromMfm(mfm.parse(appearNote.text)) : null;
+const showTicker = (defaultStore.state.instanceTicker === 'always') || (defaultStore.state.instanceTicker === 'remote' && appearNote.user.instance);
+const conversation = ref<misskey.entities.Note[]>([]);
+const replies = ref<misskey.entities.Note[]>([]);
- data() {
- return {
- connection: null,
- conversation: [],
- replies: [],
- showContent: false,
- isDeleted: false,
- muted: false,
- translation: null,
- translating: false,
- notePage,
- };
- },
+const keymap = {
+ 'r': () => reply(true),
+ 'e|a|plus': () => react(true),
+ 'q': () => renoteButton.value.renote(true),
+ 'esc': blur,
+ 'm|o': () => menu(true),
+ 's': () => showContent.value != showContent.value,
+};
- computed: {
- rs() {
- return this.$store.state.reactions;
- },
- keymap(): any {
- return {
- 'r': () => this.reply(true),
- 'e|a|plus': () => this.react(true),
- 'q': () => this.$refs.renoteButton.renote(true),
- 'f|b': this.favorite,
- 'delete|ctrl+d': this.del,
- 'ctrl+q': this.renoteDirectly,
- 'up|k|shift+tab': this.focusBefore,
- 'down|j|tab': this.focusAfter,
- 'esc': this.blur,
- 'm|o': () => this.menu(true),
- 's': this.toggleShowContent,
- '1': () => this.reactDirectly(this.rs[0]),
- '2': () => this.reactDirectly(this.rs[1]),
- '3': () => this.reactDirectly(this.rs[2]),
- '4': () => this.reactDirectly(this.rs[3]),
- '5': () => this.reactDirectly(this.rs[4]),
- '6': () => this.reactDirectly(this.rs[5]),
- '7': () => this.reactDirectly(this.rs[6]),
- '8': () => this.reactDirectly(this.rs[7]),
- '9': () => this.reactDirectly(this.rs[8]),
- '0': () => this.reactDirectly(this.rs[9]),
- };
- },
-
- isRenote(): boolean {
- return (this.note.renote &&
- this.note.text == null &&
- this.note.fileIds.length == 0 &&
- this.note.poll == null);
- },
-
- appearNote(): any {
- return this.isRenote ? this.note.renote : this.note;
- },
-
- isMyNote(): boolean {
- return this.$i && (this.$i.id === this.appearNote.userId);
- },
-
- isMyRenote(): boolean {
- return this.$i && (this.$i.id === this.note.userId);
- },
-
- reactionsCount(): number {
- return this.appearNote.reactions
- ? sum(Object.values(this.appearNote.reactions))
- : 0;
- },
-
- urls(): string[] {
- if (this.appearNote.text) {
- return extractUrlFromMfm(mfm.parse(this.appearNote.text));
- } else {
- return null;
- }
- },
-
- showTicker() {
- if (this.$store.state.instanceTicker === 'always') return true;
- if (this.$store.state.instanceTicker === 'remote' && this.appearNote.user.instance) return true;
- return false;
- }
- },
-
- async created() {
- if (this.$i) {
- this.connection = os.stream;
- }
-
- this.muted = await checkWordMute(this.appearNote, this.$i, this.$store.state.mutedWords);
+useNoteCapture({
+ appearNote: $$(appearNote),
+ rootEl: el,
+});
- // plugin
- if (noteViewInterruptors.length > 0) {
- let result = this.note;
- for (const interruptor of noteViewInterruptors) {
- result = await interruptor.handler(JSON.parse(JSON.stringify(result)));
- }
- this.$emit('update:note', Object.freeze(result));
- }
+function reply(viaKeyboard = false): void {
+ pleaseLogin();
+ os.post({
+ reply: appearNote,
+ animation: !viaKeyboard,
+ }, () => {
+ focus();
+ });
+}
- os.api('notes/children', {
- noteId: this.appearNote.id,
- limit: 30
- }).then(replies => {
- this.replies = replies;
+function react(viaKeyboard = false): void {
+ pleaseLogin();
+ blur();
+ reactionPicker.show(reactButton.value, reaction => {
+ os.api('notes/reactions/create', {
+ noteId: appearNote.id,
+ reaction: reaction
});
+ }, () => {
+ focus();
+ });
+}
- if (this.appearNote.replyId) {
- os.api('notes/conversation', {
- noteId: this.appearNote.replyId
- }).then(conversation => {
- this.conversation = conversation.reverse();
- });
- }
- },
-
- mounted() {
- this.capture(true);
-
- if (this.$i) {
- this.connection.on('_connected_', this.onStreamConnected);
- }
- },
-
- beforeUnmount() {
- this.decapture(true);
+function undoReact(note): void {
+ const oldReaction = note.myReaction;
+ if (!oldReaction) return;
+ os.api('notes/reactions/delete', {
+ noteId: note.id
+ });
+}
- if (this.$i) {
- this.connection.off('_connected_', this.onStreamConnected);
+function onContextmenu(ev: MouseEvent): void {
+ const isLink = (el: HTMLElement) => {
+ if (el.tagName === 'A') return true;
+ if (el.parentElement) {
+ return isLink(el.parentElement);
}
- },
-
- methods: {
- updateAppearNote(v) {
- this.$emit('update:note', Object.freeze(this.isRenote ? {
- ...this.note,
- renote: {
- ...this.note.renote,
- ...v
- }
- } : {
- ...this.note,
- ...v
- }));
- },
-
- readPromo() {
- os.api('promo/read', {
- noteId: this.appearNote.id
- });
- this.isDeleted = true;
- },
-
- capture(withHandler = false) {
- if (this.$i) {
- // TODO: このノートがストリーミング経由で流れてきた場合のみ sr する
- this.connection.send(document.body.contains(this.$el) ? 'sr' : 's', { id: this.appearNote.id });
- if (withHandler) this.connection.on('noteUpdated', this.onStreamNoteUpdated);
- }
- },
-
- decapture(withHandler = false) {
- if (this.$i) {
- this.connection.send('un', {
- id: this.appearNote.id
- });
- if (withHandler) this.connection.off('noteUpdated', this.onStreamNoteUpdated);
- }
- },
-
- onStreamConnected() {
- this.capture();
- },
-
- onStreamNoteUpdated(data) {
- const { type, id, body } = data;
-
- if (id !== this.appearNote.id) return;
+ };
+ if (isLink(ev.target)) return;
+ if (window.getSelection().toString() !== '') return;
- switch (type) {
- case 'reacted': {
- const reaction = body.reaction;
-
- // DeepではなくShallowコピーであることに注意。n.reactions[reaction] = hogeとかしないように(親からもらったデータをミューテートすることになるので)
- let n = {
- ...this.appearNote,
- };
-
- if (body.emoji) {
- const emojis = this.appearNote.emojis || [];
- if (!emojis.includes(body.emoji)) {
- n.emojis = [...emojis, body.emoji];
- }
- }
-
- // TODO: reactionsプロパティがない場合ってあったっけ? なければ || {} は消せる
- const currentCount = (this.appearNote.reactions || {})[reaction] || 0;
-
- // Increment the count
- n.reactions = {
- ...this.appearNote.reactions,
- [reaction]: currentCount + 1
- };
-
- if (body.userId === this.$i.id) {
- n.myReaction = reaction;
- }
-
- this.updateAppearNote(n);
- break;
- }
-
- case 'unreacted': {
- const reaction = body.reaction;
-
- // DeepではなくShallowコピーであることに注意。n.reactions[reaction] = hogeとかしないように(親からもらったデータをミューテートすることになるので)
- let n = {
- ...this.appearNote,
- };
-
- // TODO: reactionsプロパティがない場合ってあったっけ? なければ || {} は消せる
- const currentCount = (this.appearNote.reactions || {})[reaction] || 0;
-
- // Decrement the count
- n.reactions = {
- ...this.appearNote.reactions,
- [reaction]: Math.max(0, currentCount - 1)
- };
-
- if (body.userId === this.$i.id) {
- n.myReaction = null;
- }
-
- this.updateAppearNote(n);
- break;
- }
-
- case 'pollVoted': {
- const choice = body.choice;
-
- // DeepではなくShallowコピーであることに注意。n.reactions[reaction] = hogeとかしないように(親からもらったデータをミューテートすることになるので)
- let n = {
- ...this.appearNote,
- };
-
- const choices = [...this.appearNote.poll.choices];
- choices[choice] = {
- ...choices[choice],
- votes: choices[choice].votes + 1,
- ...(body.userId === this.$i.id ? {
- isVoted: true
- } : {})
- };
-
- n.poll = {
- ...this.appearNote.poll,
- choices: choices
- };
-
- this.updateAppearNote(n);
- break;
- }
-
- case 'deleted': {
- this.isDeleted = true;
- break;
- }
- }
- },
-
- reply(viaKeyboard = false) {
- pleaseLogin();
- os.post({
- reply: this.appearNote,
- animation: !viaKeyboard,
- }, () => {
- this.focus();
- });
- },
-
- renoteDirectly() {
- os.apiWithDialog('notes/create', {
- renoteId: this.appearNote.id
- }, undefined, (res: any) => {
- os.alert({
- type: 'success',
- text: this.$ts.renoted,
- });
- }, (e: Error) => {
- if (e.id === 'b5c90186-4ab0-49c8-9bba-a1f76c282ba4') {
- os.alert({
- type: 'error',
- text: this.$ts.cantRenote,
- });
- } else if (e.id === 'fd4cc33e-2a37-48dd-99cc-9b806eb2031a') {
- os.alert({
- type: 'error',
- text: this.$ts.cantReRenote,
- });
- }
- });
- },
-
- react(viaKeyboard = false) {
- pleaseLogin();
- this.blur();
- reactionPicker.show(this.$refs.reactButton, reaction => {
- os.api('notes/reactions/create', {
- noteId: this.appearNote.id,
- reaction: reaction
- });
- }, () => {
- this.focus();
- });
- },
-
- reactDirectly(reaction) {
- os.api('notes/reactions/create', {
- noteId: this.appearNote.id,
- reaction: reaction
- });
- },
-
- undoReact(note) {
- const oldReaction = note.myReaction;
- if (!oldReaction) return;
- os.api('notes/reactions/delete', {
- noteId: note.id
- });
- },
-
- favorite() {
- pleaseLogin();
- os.apiWithDialog('notes/favorites/create', {
- noteId: this.appearNote.id
- }, undefined, (res: any) => {
- os.alert({
- type: 'success',
- text: this.$ts.favorited,
- });
- }, (e: Error) => {
- if (e.id === 'a402c12b-34dd-41d2-97d8-4d2ffd96a1a6') {
- os.alert({
- type: 'error',
- text: this.$ts.alreadyFavorited,
- });
- } else if (e.id === '6dd26674-e060-4816-909a-45ba3f4da458') {
- os.alert({
- type: 'error',
- text: this.$ts.cantFavorite,
- });
- }
- });
- },
-
- del() {
- os.confirm({
- type: 'warning',
- text: this.$ts.noteDeleteConfirm,
- }).then(({ canceled }) => {
- if (canceled) return;
-
- os.api('notes/delete', {
- noteId: this.appearNote.id
- });
- });
- },
-
- delEdit() {
- os.confirm({
- type: 'warning',
- text: this.$ts.deleteAndEditConfirm,
- }).then(({ canceled }) => {
- if (canceled) return;
-
- os.api('notes/delete', {
- noteId: this.appearNote.id
- });
-
- os.post({ initialNote: this.appearNote, renote: this.appearNote.renote, reply: this.appearNote.reply, channel: this.appearNote.channel });
- });
- },
-
- toggleFavorite(favorite: boolean) {
- os.apiWithDialog(favorite ? 'notes/favorites/create' : 'notes/favorites/delete', {
- noteId: this.appearNote.id
- });
- },
-
- toggleWatch(watch: boolean) {
- os.apiWithDialog(watch ? 'notes/watching/create' : 'notes/watching/delete', {
- noteId: this.appearNote.id
- });
- },
-
- toggleThreadMute(mute: boolean) {
- os.apiWithDialog(mute ? 'notes/thread-muting/create' : 'notes/thread-muting/delete', {
- noteId: this.appearNote.id
- });
- },
-
- getMenu() {
- let menu;
- if (this.$i) {
- const statePromise = os.api('notes/state', {
- noteId: this.appearNote.id
- });
-
- menu = [{
- icon: 'fas fa-copy',
- text: this.$ts.copyContent,
- action: this.copyContent
- }, {
- icon: 'fas fa-link',
- text: this.$ts.copyLink,
- action: this.copyLink
- }, (this.appearNote.url || this.appearNote.uri) ? {
- icon: 'fas fa-external-link-square-alt',
- text: this.$ts.showOnRemote,
- action: () => {
- window.open(this.appearNote.url || this.appearNote.uri, '_blank');
- }
- } : undefined,
- {
- icon: 'fas fa-share-alt',
- text: this.$ts.share,
- action: this.share
- },
- this.$instance.translatorAvailable ? {
- icon: 'fas fa-language',
- text: this.$ts.translate,
- action: this.translate
- } : undefined,
- null,
- statePromise.then(state => state.isFavorited ? {
- icon: 'fas fa-star',
- text: this.$ts.unfavorite,
- action: () => this.toggleFavorite(false)
- } : {
- icon: 'fas fa-star',
- text: this.$ts.favorite,
- action: () => this.toggleFavorite(true)
- }),
- {
- icon: 'fas fa-paperclip',
- text: this.$ts.clip,
- action: () => this.clip()
- },
- (this.appearNote.userId != this.$i.id) ? statePromise.then(state => state.isWatching ? {
- icon: 'fas fa-eye-slash',
- text: this.$ts.unwatch,
- action: () => this.toggleWatch(false)
- } : {
- icon: 'fas fa-eye',
- text: this.$ts.watch,
- action: () => this.toggleWatch(true)
- }) : undefined,
- statePromise.then(state => state.isMutedThread ? {
- icon: 'fas fa-comment-slash',
- text: this.$ts.unmuteThread,
- action: () => this.toggleThreadMute(false)
- } : {
- icon: 'fas fa-comment-slash',
- text: this.$ts.muteThread,
- action: () => this.toggleThreadMute(true)
- }),
- this.appearNote.userId == this.$i.id ? (this.$i.pinnedNoteIds || []).includes(this.appearNote.id) ? {
- icon: 'fas fa-thumbtack',
- text: this.$ts.unpin,
- action: () => this.togglePin(false)
- } : {
- icon: 'fas fa-thumbtack',
- text: this.$ts.pin,
- action: () => this.togglePin(true)
- } : undefined,
- /*...(this.$i.isModerator || this.$i.isAdmin ? [
- null,
- {
- icon: 'fas fa-bullhorn',
- text: this.$ts.promote,
- action: this.promote
- }]
- : []
- ),*/
- ...(this.appearNote.userId != this.$i.id ? [
- null,
- {
- icon: 'fas fa-exclamation-circle',
- text: this.$ts.reportAbuse,
- action: () => {
- const u = `${url}/notes/${this.appearNote.id}`;
- os.popup(import('@/components/abuse-report-window.vue'), {
- user: this.appearNote.user,
- initialComment: `Note: ${u}\n-----\n`
- }, {}, 'closed');
- }
- }]
- : []
- ),
- ...(this.appearNote.userId == this.$i.id || this.$i.isModerator || this.$i.isAdmin ? [
- null,
- this.appearNote.userId == this.$i.id ? {
- icon: 'fas fa-edit',
- text: this.$ts.deleteAndEdit,
- action: this.delEdit
- } : undefined,
- {
- icon: 'fas fa-trash-alt',
- text: this.$ts.delete,
- danger: true,
- action: this.del
- }]
- : []
- )]
- .filter(x => x !== undefined);
- } else {
- menu = [{
- icon: 'fas fa-copy',
- text: this.$ts.copyContent,
- action: this.copyContent
- }, {
- icon: 'fas fa-link',
- text: this.$ts.copyLink,
- action: this.copyLink
- }, (this.appearNote.url || this.appearNote.uri) ? {
- icon: 'fas fa-external-link-square-alt',
- text: this.$ts.showOnRemote,
- action: () => {
- window.open(this.appearNote.url || this.appearNote.uri, '_blank');
- }
- } : undefined]
- .filter(x => x !== undefined);
- }
-
- if (noteActions.length > 0) {
- menu = menu.concat([null, ...noteActions.map(action => ({
- icon: 'fas fa-plug',
- text: action.title,
- action: () => {
- action.handler(this.appearNote);
- }
- }))]);
- }
-
- return menu;
- },
-
- onContextmenu(e) {
- const isLink = (el: HTMLElement) => {
- if (el.tagName === 'A') return true;
- if (el.parentElement) {
- return isLink(el.parentElement);
- }
- };
- if (isLink(e.target)) return;
- if (window.getSelection().toString() !== '') return;
-
- if (this.$store.state.useReactionPickerForContextMenu) {
- e.preventDefault();
- this.react();
- } else {
- os.contextMenu(this.getMenu(), e).then(this.focus);
- }
- },
-
- menu(viaKeyboard = false) {
- os.popupMenu(this.getMenu(), this.$refs.menuButton, {
- viaKeyboard
- }).then(this.focus);
- },
-
- showRenoteMenu(viaKeyboard = false) {
- if (!this.isMyRenote) return;
- os.popupMenu([{
- text: this.$ts.unrenote,
- icon: 'fas fa-trash-alt',
- danger: true,
- action: () => {
- os.api('notes/delete', {
- noteId: this.note.id
- });
- this.isDeleted = true;
- }
- }], this.$refs.renoteTime, {
- viaKeyboard: viaKeyboard
- });
- },
-
- toggleShowContent() {
- this.showContent = !this.showContent;
- },
-
- copyContent() {
- copyToClipboard(this.appearNote.text);
- os.success();
- },
-
- copyLink() {
- copyToClipboard(`${url}/notes/${this.appearNote.id}`);
- os.success();
- },
-
- togglePin(pin: boolean) {
- os.apiWithDialog(pin ? 'i/pin' : 'i/unpin', {
- noteId: this.appearNote.id
- }, undefined, null, e => {
- if (e.id === '72dab508-c64d-498f-8740-a8eec1ba385a') {
- os.alert({
- type: 'error',
- text: this.$ts.pinLimitExceeded
- });
- }
- });
- },
-
- async clip() {
- const clips = await os.api('clips/list');
- os.popupMenu([{
- icon: 'fas fa-plus',
- text: this.$ts.createNew,
- action: async () => {
- const { canceled, result } = await os.form(this.$ts.createNewClip, {
- name: {
- type: 'string',
- label: this.$ts.name
- },
- description: {
- type: 'string',
- required: false,
- multiline: true,
- label: this.$ts.description
- },
- isPublic: {
- type: 'boolean',
- label: this.$ts.public,
- default: false
- }
- });
- if (canceled) return;
-
- const clip = await os.apiWithDialog('clips/create', result);
-
- os.apiWithDialog('clips/add-note', { clipId: clip.id, noteId: this.appearNote.id });
- }
- }, null, ...clips.map(clip => ({
- text: clip.name,
- action: () => {
- os.apiWithDialog('clips/add-note', { clipId: clip.id, noteId: this.appearNote.id });
- }
- }))], this.$refs.menuButton, {
- }).then(this.focus);
- },
-
- async promote() {
- const { canceled, result: days } = await os.inputNumber({
- title: this.$ts.numberOfDays,
- });
-
- if (canceled) return;
-
- os.apiWithDialog('admin/promo/create', {
- noteId: this.appearNote.id,
- expiresAt: Date.now() + (86400000 * days)
- });
- },
+ if (defaultStore.state.useReactionPickerForContextMenu) {
+ ev.preventDefault();
+ react();
+ } else {
+ os.contextMenu(getNoteMenu({ note: props.note, translating, translation, menuButton }), ev).then(focus);
+ }
+}
- share() {
- navigator.share({
- title: this.$t('noteOf', { user: this.appearNote.user.name }),
- text: this.appearNote.text,
- url: `${url}/notes/${this.appearNote.id}`
- });
- },
+function menu(viaKeyboard = false): void {
+ os.popupMenu(getNoteMenu({ note: props.note, translating, translation, menuButton }), menuButton.value, {
+ viaKeyboard
+ }).then(focus);
+}
- async translate() {
- if (this.translation != null) return;
- this.translating = true;
- const res = await os.api('notes/translate', {
- noteId: this.appearNote.id,
- targetLang: localStorage.getItem('lang') || navigator.language,
+function showRenoteMenu(viaKeyboard = false): void {
+ if (!isMyRenote) return;
+ os.popupMenu([{
+ text: i18n.locale.unrenote,
+ icon: 'fas fa-trash-alt',
+ danger: true,
+ action: () => {
+ os.api('notes/delete', {
+ noteId: props.note.id
});
- this.translating = false;
- this.translation = res;
- },
-
- focus() {
- this.$el.focus();
- },
-
- blur() {
- this.$el.blur();
- },
+ isDeleted.value = true;
+ }
+ }], renoteTime.value, {
+ viaKeyboard: viaKeyboard
+ });
+}
- focusBefore() {
- focusPrev(this.$el);
- },
+function focus() {
+ el.value.focus();
+}
- focusAfter() {
- focusNext(this.$el);
- },
+function blur() {
+ el.value.blur();
+}
- userPage
- }
+os.api('notes/children', {
+ noteId: appearNote.id,
+ limit: 30
+}).then(res => {
+ replies.value = res;
});
+
+if (appearNote.replyId) {
+ os.api('notes/conversation', {
+ noteId: appearNote.replyId
+ }).then(res => {
+ conversation.value = res.reverse();
+ });
+}
</script>
<style lang="scss" scoped>
diff --git a/packages/client/src/components/note-header.vue b/packages/client/src/components/note-header.vue
index 26e725c6b8..56a3a37e75 100644
--- a/packages/client/src/components/note-header.vue
+++ b/packages/client/src/components/note-header.vue
@@ -19,30 +19,16 @@
</header>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
+<script lang="ts" setup>
+import { } from 'vue';
+import * as misskey from 'misskey-js';
import { notePage } from '@/filters/note';
import { userPage } from '@/filters/user';
-import * as os from '@/os';
-export default defineComponent({
- props: {
- note: {
- type: Object,
- required: true
- },
- },
-
- data() {
- return {
- };
- },
-
- methods: {
- notePage,
- userPage
- }
-});
+defineProps<{
+ note: misskey.entities.Note;
+ pinned?: boolean;
+}>();
</script>
<style lang="scss" scoped>
diff --git a/packages/client/src/components/note-preview.vue b/packages/client/src/components/note-preview.vue
index bdcb8d5eed..a78b499654 100644
--- a/packages/client/src/components/note-preview.vue
+++ b/packages/client/src/components/note-preview.vue
@@ -14,20 +14,12 @@
</div>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
+<script lang="ts" setup>
+import { } from 'vue';
-export default defineComponent({
- components: {
- },
-
- props: {
- text: {
- type: String,
- required: true
- }
- },
-});
+const props = defineProps<{
+ text: string;
+}>();
</script>
<style lang="scss" scoped>
diff --git a/packages/client/src/components/note-simple.vue b/packages/client/src/components/note-simple.vue
index 135f06602d..c6907787b5 100644
--- a/packages/client/src/components/note-simple.vue
+++ b/packages/client/src/components/note-simple.vue
@@ -9,40 +9,26 @@
<XCwButton v-model="showContent" :note="note"/>
</p>
<div v-show="note.cw == null || showContent" class="content">
- <XSubNote-content class="text" :note="note"/>
+ <MkNoteSubNoteContent class="text" :note="note"/>
</div>
</div>
</div>
</div>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
+<script lang="ts" setup>
+import { } from 'vue';
+import * as misskey from 'misskey-js';
import XNoteHeader from './note-header.vue';
-import XSubNoteContent from './sub-note-content.vue';
+import MkNoteSubNoteContent from './sub-note-content.vue';
import XCwButton from './cw-button.vue';
-import * as os from '@/os';
-export default defineComponent({
- components: {
- XNoteHeader,
- XSubNoteContent,
- XCwButton,
- },
+const props = defineProps<{
+ note: misskey.entities.Note;
+ pinned?: boolean;
+}>();
- props: {
- note: {
- type: Object,
- required: true
- }
- },
-
- data() {
- return {
- showContent: false
- };
- }
-});
+const showContent = $ref(false);
</script>
<style lang="scss" scoped>
diff --git a/packages/client/src/components/note.vue b/packages/client/src/components/note.vue
index c4040388a9..fc89c2777b 100644
--- a/packages/client/src/components/note.vue
+++ b/packages/client/src/components/note.vue
@@ -2,20 +2,21 @@
<div
v-if="!muted"
v-show="!isDeleted"
+ ref="el"
v-hotkey="keymap"
v-size="{ max: [500, 450, 350, 300] }"
class="tkcbzcuz"
:tabindex="!isDeleted ? '-1' : null"
:class="{ renote: isRenote }"
>
- <XSub v-if="appearNote.reply" :note="appearNote.reply" class="reply-to"/>
- <div v-if="pinned" class="info"><i class="fas fa-thumbtack"></i> {{ $ts.pinnedNote }}</div>
- <div v-if="appearNote._prId_" class="info"><i class="fas fa-bullhorn"></i> {{ $ts.promotion }}<button class="_textButton hide" @click="readPromo()">{{ $ts.hideThisNote }} <i class="fas fa-times"></i></button></div>
- <div v-if="appearNote._featuredId_" class="info"><i class="fas fa-bolt"></i> {{ $ts.featured }}</div>
+ <MkNoteSub v-if="appearNote.reply" :note="appearNote.reply" class="reply-to"/>
+ <div v-if="pinned" class="info"><i class="fas fa-thumbtack"></i> {{ i18n.locale.pinnedNote }}</div>
+ <div v-if="appearNote._prId_" class="info"><i class="fas fa-bullhorn"></i> {{ i18n.locale.promotion }}<button class="_textButton hide" @click="readPromo()">{{ i18n.locale.hideThisNote }} <i class="fas fa-times"></i></button></div>
+ <div v-if="appearNote._featuredId_" class="info"><i class="fas fa-bolt"></i> {{ i18n.locale.featured }}</div>
<div v-if="isRenote" class="renote">
<MkAvatar class="avatar" :user="note.user"/>
<i class="fas fa-retweet"></i>
- <I18n :src="$ts.renotedBy" tag="span">
+ <I18n :src="i18n.locale.renotedBy" tag="span">
<template #user>
<MkA v-user-preview="note.userId" class="name" :to="userPage(note.user)">
<MkUserName :user="note.user"/>
@@ -47,7 +48,7 @@
</p>
<div v-show="appearNote.cw == null || showContent" class="content" :class="{ collapsed }">
<div class="text">
- <span v-if="appearNote.isHidden" style="opacity: 0.5">({{ $ts.private }})</span>
+ <span v-if="appearNote.isHidden" style="opacity: 0.5">({{ i18n.locale.private }})</span>
<MkA v-if="appearNote.replyId" class="reply" :to="`/notes/${appearNote.replyId}`"><i class="fas fa-reply"></i></MkA>
<Mfm v-if="appearNote.text" :text="appearNote.text" :author="appearNote.user" :i="$i" :custom-emojis="appearNote.emojis"/>
<a v-if="appearNote.renote != null" class="rp">RN:</a>
@@ -66,7 +67,7 @@
<MkUrlPreview v-for="url in urls" :key="url" :url="url" :compact="true" :detail="false" class="url-preview"/>
<div v-if="appearNote.renote" class="renote"><XNoteSimple :note="appearNote.renote"/></div>
<button v-if="collapsed" class="fade _button" @click="collapsed = false">
- <span>{{ $ts.showMore }}</span>
+ <span>{{ i18n.locale.showMore }}</span>
</button>
</div>
<MkA v-if="appearNote.channel && !inChannel" class="channel" :to="`/channels/${appearNote.channel.id}`"><i class="fas fa-satellite-dish"></i> {{ appearNote.channel.name }}</MkA>
@@ -93,7 +94,7 @@
</article>
</div>
<div v-else class="muted" @click="muted = false">
- <I18n :src="$ts.userSaysSomething" tag="small">
+ <I18n :src="i18n.locale.userSaysSomething" tag="small">
<template #name>
<MkA v-user-preview="appearNote.userId" class="name" :to="userPage(appearNote.user)">
<MkUserName :user="appearNote.user"/>
@@ -103,11 +104,11 @@
</div>
</template>
-<script lang="ts">
-import { defineAsyncComponent, defineComponent, markRaw } from 'vue';
+<script lang="ts" setup>
+import { computed, inject, onMounted, onUnmounted, reactive, ref } from 'vue';
import * as mfm from 'mfm-js';
-import { sum } from '@/scripts/array';
-import XSub from './note.sub.vue';
+import * as misskey from 'misskey-js';
+import MkNoteSub from './MkNoteSub.vue';
import XNoteHeader from './note-header.vue';
import XNoteSimple from './note-simple.vue';
import XReactionsViewer from './reactions-viewer.vue';
@@ -115,744 +116,164 @@ import XMediaList from './media-list.vue';
import XCwButton from './cw-button.vue';
import XPoll from './poll.vue';
import XRenoteButton from './renote-button.vue';
+import MkUrlPreview from '@/components/url-preview.vue';
+import MkInstanceTicker from '@/components/instance-ticker.vue';
import { pleaseLogin } from '@/scripts/please-login';
import { focusPrev, focusNext } from '@/scripts/focus';
-import { url } from '@/config';
-import copyToClipboard from '@/scripts/copy-to-clipboard';
import { checkWordMute } from '@/scripts/check-word-mute';
import { userPage } from '@/filters/user';
import * as os from '@/os';
-import { noteActions, noteViewInterruptors } from '@/store';
+import { defaultStore, noteViewInterruptors } from '@/store';
import { reactionPicker } from '@/scripts/reaction-picker';
import { extractUrlFromMfm } from '@/scripts/extract-url-from-mfm';
+import { $i } from '@/account';
+import { i18n } from '@/i18n';
+import { getNoteMenu } from '@/scripts/get-note-menu';
+import { useNoteCapture } from '@/scripts/use-note-capture';
-export default defineComponent({
- components: {
- XSub,
- XNoteHeader,
- XNoteSimple,
- XReactionsViewer,
- XMediaList,
- XCwButton,
- XPoll,
- XRenoteButton,
- MkUrlPreview: defineAsyncComponent(() => import('@/components/url-preview.vue')),
- MkInstanceTicker: defineAsyncComponent(() => import('@/components/instance-ticker.vue')),
- },
+const props = defineProps<{
+ note: misskey.entities.Note;
+ pinned?: boolean;
+}>();
- inject: {
- inChannel: {
- default: null
- },
- },
+const inChannel = inject('inChannel', null);
- props: {
- note: {
- type: Object,
- required: true
- },
- pinned: {
- type: Boolean,
- required: false,
- default: false
- },
- },
+const isRenote = (
+ props.note.renote != null &&
+ props.note.text == null &&
+ props.note.fileIds.length === 0 &&
+ props.note.poll == null
+);
- emits: ['update:note'],
+const el = ref<HTMLElement>();
+const menuButton = ref<HTMLElement>();
+const renoteButton = ref<InstanceType<typeof XRenoteButton>>();
+const renoteTime = ref<HTMLElement>();
+const reactButton = ref<HTMLElement>();
+let appearNote = $ref(isRenote ? props.note.renote as misskey.entities.Note : props.note);
+const isMyRenote = $i && ($i.id === props.note.userId);
+const showContent = ref(false);
+const collapsed = ref(appearNote.cw == null && appearNote.text != null && (
+ (appearNote.text.split('\n').length > 9) ||
+ (appearNote.text.length > 500)
+));
+const isDeleted = ref(false);
+const muted = ref(checkWordMute(appearNote, $i, defaultStore.state.mutedWords));
+const translation = ref(null);
+const translating = ref(false);
+const urls = appearNote.text ? extractUrlFromMfm(mfm.parse(appearNote.text)) : null;
+const showTicker = (defaultStore.state.instanceTicker === 'always') || (defaultStore.state.instanceTicker === 'remote' && appearNote.user.instance);
- data() {
- return {
- connection: null,
- replies: [],
- showContent: false,
- collapsed: false,
- isDeleted: false,
- muted: false,
- translation: null,
- translating: false,
- };
- },
+const keymap = {
+ 'r': () => reply(true),
+ 'e|a|plus': () => react(true),
+ 'q': () => renoteButton.value.renote(true),
+ 'up|k|shift+tab': focusBefore,
+ 'down|j|tab': focusAfter,
+ 'esc': blur,
+ 'm|o': () => menu(true),
+ 's': () => showContent.value != showContent.value,
+};
- computed: {
- rs() {
- return this.$store.state.reactions;
- },
- keymap(): any {
- return {
- 'r': () => this.reply(true),
- 'e|a|plus': () => this.react(true),
- 'q': () => this.$refs.renoteButton.renote(true),
- 'f|b': this.favorite,
- 'delete|ctrl+d': this.del,
- 'ctrl+q': this.renoteDirectly,
- 'up|k|shift+tab': this.focusBefore,
- 'down|j|tab': this.focusAfter,
- 'esc': this.blur,
- 'm|o': () => this.menu(true),
- 's': this.toggleShowContent,
- '1': () => this.reactDirectly(this.rs[0]),
- '2': () => this.reactDirectly(this.rs[1]),
- '3': () => this.reactDirectly(this.rs[2]),
- '4': () => this.reactDirectly(this.rs[3]),
- '5': () => this.reactDirectly(this.rs[4]),
- '6': () => this.reactDirectly(this.rs[5]),
- '7': () => this.reactDirectly(this.rs[6]),
- '8': () => this.reactDirectly(this.rs[7]),
- '9': () => this.reactDirectly(this.rs[8]),
- '0': () => this.reactDirectly(this.rs[9]),
- };
- },
-
- isRenote(): boolean {
- return (this.note.renote &&
- this.note.text == null &&
- this.note.fileIds.length == 0 &&
- this.note.poll == null);
- },
-
- appearNote(): any {
- return this.isRenote ? this.note.renote : this.note;
- },
-
- isMyNote(): boolean {
- return this.$i && (this.$i.id === this.appearNote.userId);
- },
-
- isMyRenote(): boolean {
- return this.$i && (this.$i.id === this.note.userId);
- },
-
- reactionsCount(): number {
- return this.appearNote.reactions
- ? sum(Object.values(this.appearNote.reactions))
- : 0;
- },
-
- urls(): string[] {
- if (this.appearNote.text) {
- return extractUrlFromMfm(mfm.parse(this.appearNote.text));
- } else {
- return null;
- }
- },
-
- showTicker() {
- if (this.$store.state.instanceTicker === 'always') return true;
- if (this.$store.state.instanceTicker === 'remote' && this.appearNote.user.instance) return true;
- return false;
- }
- },
-
- async created() {
- if (this.$i) {
- this.connection = os.stream;
- }
-
- this.collapsed = this.appearNote.cw == null && this.appearNote.text && (
- (this.appearNote.text.split('\n').length > 9) ||
- (this.appearNote.text.length > 500)
- );
- this.muted = await checkWordMute(this.appearNote, this.$i, this.$store.state.mutedWords);
-
- // plugin
- if (noteViewInterruptors.length > 0) {
- let result = this.note;
- for (const interruptor of noteViewInterruptors) {
- result = await interruptor.handler(JSON.parse(JSON.stringify(result)));
- }
- this.$emit('update:note', Object.freeze(result));
- }
- },
+useNoteCapture({
+ appearNote: $$(appearNote),
+ rootEl: el,
+});
- mounted() {
- this.capture(true);
+function reply(viaKeyboard = false): void {
+ pleaseLogin();
+ os.post({
+ reply: appearNote,
+ animation: !viaKeyboard,
+ }, () => {
+ focus();
+ });
+}
- if (this.$i) {
- this.connection.on('_connected_', this.onStreamConnected);
- }
- },
+function react(viaKeyboard = false): void {
+ pleaseLogin();
+ blur();
+ reactionPicker.show(reactButton.value, reaction => {
+ os.api('notes/reactions/create', {
+ noteId: appearNote.id,
+ reaction: reaction
+ });
+ }, () => {
+ focus();
+ });
+}
- beforeUnmount() {
- this.decapture(true);
+function undoReact(note): void {
+ const oldReaction = note.myReaction;
+ if (!oldReaction) return;
+ os.api('notes/reactions/delete', {
+ noteId: note.id
+ });
+}
- if (this.$i) {
- this.connection.off('_connected_', this.onStreamConnected);
+function onContextmenu(ev: MouseEvent): void {
+ const isLink = (el: HTMLElement) => {
+ if (el.tagName === 'A') return true;
+ if (el.parentElement) {
+ return isLink(el.parentElement);
}
- },
-
- methods: {
- updateAppearNote(v) {
- this.$emit('update:note', Object.freeze(this.isRenote ? {
- ...this.note,
- renote: {
- ...this.note.renote,
- ...v
- }
- } : {
- ...this.note,
- ...v
- }));
- },
-
- readPromo() {
- os.api('promo/read', {
- noteId: this.appearNote.id
- });
- this.isDeleted = true;
- },
-
- capture(withHandler = false) {
- if (this.$i) {
- // TODO: このノートがストリーミング経由で流れてきた場合のみ sr する
- this.connection.send(document.body.contains(this.$el) ? 'sr' : 's', { id: this.appearNote.id });
- if (withHandler) this.connection.on('noteUpdated', this.onStreamNoteUpdated);
- }
- },
+ };
+ if (isLink(ev.target)) return;
+ if (window.getSelection().toString() !== '') return;
- decapture(withHandler = false) {
- if (this.$i) {
- this.connection.send('un', {
- id: this.appearNote.id
- });
- if (withHandler) this.connection.off('noteUpdated', this.onStreamNoteUpdated);
- }
- },
-
- onStreamConnected() {
- this.capture();
- },
-
- onStreamNoteUpdated(data) {
- const { type, id, body } = data;
-
- if (id !== this.appearNote.id) return;
-
- switch (type) {
- case 'reacted': {
- const reaction = body.reaction;
-
- // DeepではなくShallowコピーであることに注意。n.reactions[reaction] = hogeとかしないように(親からもらったデータをミューテートすることになるので)
- let n = {
- ...this.appearNote,
- };
-
- if (body.emoji) {
- const emojis = this.appearNote.emojis || [];
- if (!emojis.includes(body.emoji)) {
- n.emojis = [...emojis, body.emoji];
- }
- }
-
- // TODO: reactionsプロパティがない場合ってあったっけ? なければ || {} は消せる
- const currentCount = (this.appearNote.reactions || {})[reaction] || 0;
-
- // Increment the count
- n.reactions = {
- ...this.appearNote.reactions,
- [reaction]: currentCount + 1
- };
-
- if (body.userId === this.$i.id) {
- n.myReaction = reaction;
- }
-
- this.updateAppearNote(n);
- break;
- }
-
- case 'unreacted': {
- const reaction = body.reaction;
-
- // DeepではなくShallowコピーであることに注意。n.reactions[reaction] = hogeとかしないように(親からもらったデータをミューテートすることになるので)
- let n = {
- ...this.appearNote,
- };
-
- // TODO: reactionsプロパティがない場合ってあったっけ? なければ || {} は消せる
- const currentCount = (this.appearNote.reactions || {})[reaction] || 0;
-
- // Decrement the count
- n.reactions = {
- ...this.appearNote.reactions,
- [reaction]: Math.max(0, currentCount - 1)
- };
-
- if (body.userId === this.$i.id) {
- n.myReaction = null;
- }
-
- this.updateAppearNote(n);
- break;
- }
-
- case 'pollVoted': {
- const choice = body.choice;
-
- // DeepではなくShallowコピーであることに注意。n.reactions[reaction] = hogeとかしないように(親からもらったデータをミューテートすることになるので)
- let n = {
- ...this.appearNote,
- };
-
- const choices = [...this.appearNote.poll.choices];
- choices[choice] = {
- ...choices[choice],
- votes: choices[choice].votes + 1,
- ...(body.userId === this.$i.id ? {
- isVoted: true
- } : {})
- };
-
- n.poll = {
- ...this.appearNote.poll,
- choices: choices
- };
-
- this.updateAppearNote(n);
- break;
- }
-
- case 'deleted': {
- this.isDeleted = true;
- break;
- }
- }
- },
-
- reply(viaKeyboard = false) {
- pleaseLogin();
- os.post({
- reply: this.appearNote,
- animation: !viaKeyboard,
- }, () => {
- this.focus();
- });
- },
-
- renoteDirectly() {
- os.apiWithDialog('notes/create', {
- renoteId: this.appearNote.id
- }, undefined, (res: any) => {
- os.alert({
- type: 'success',
- text: this.$ts.renoted,
- });
- }, (e: Error) => {
- if (e.id === 'b5c90186-4ab0-49c8-9bba-a1f76c282ba4') {
- os.alert({
- type: 'error',
- text: this.$ts.cantRenote,
- });
- } else if (e.id === 'fd4cc33e-2a37-48dd-99cc-9b806eb2031a') {
- os.alert({
- type: 'error',
- text: this.$ts.cantReRenote,
- });
- }
- });
- },
-
- react(viaKeyboard = false) {
- pleaseLogin();
- this.blur();
- reactionPicker.show(this.$refs.reactButton, reaction => {
- os.api('notes/reactions/create', {
- noteId: this.appearNote.id,
- reaction: reaction
- });
- }, () => {
- this.focus();
- });
- },
-
- reactDirectly(reaction) {
- os.api('notes/reactions/create', {
- noteId: this.appearNote.id,
- reaction: reaction
- });
- },
-
- undoReact(note) {
- const oldReaction = note.myReaction;
- if (!oldReaction) return;
- os.api('notes/reactions/delete', {
- noteId: note.id
- });
- },
-
- favorite() {
- pleaseLogin();
- os.apiWithDialog('notes/favorites/create', {
- noteId: this.appearNote.id
- }, undefined, (res: any) => {
- os.alert({
- type: 'success',
- text: this.$ts.favorited,
- });
- }, (e: Error) => {
- if (e.id === 'a402c12b-34dd-41d2-97d8-4d2ffd96a1a6') {
- os.alert({
- type: 'error',
- text: this.$ts.alreadyFavorited,
- });
- } else if (e.id === '6dd26674-e060-4816-909a-45ba3f4da458') {
- os.alert({
- type: 'error',
- text: this.$ts.cantFavorite,
- });
- }
- });
- },
-
- del() {
- os.confirm({
- type: 'warning',
- text: this.$ts.noteDeleteConfirm,
- }).then(({ canceled }) => {
- if (canceled) return;
-
- os.api('notes/delete', {
- noteId: this.appearNote.id
- });
- });
- },
-
- delEdit() {
- os.confirm({
- type: 'warning',
- text: this.$ts.deleteAndEditConfirm,
- }).then(({ canceled }) => {
- if (canceled) return;
-
- os.api('notes/delete', {
- noteId: this.appearNote.id
- });
-
- os.post({ initialNote: this.appearNote, renote: this.appearNote.renote, reply: this.appearNote.reply, channel: this.appearNote.channel });
- });
- },
-
- toggleFavorite(favorite: boolean) {
- os.apiWithDialog(favorite ? 'notes/favorites/create' : 'notes/favorites/delete', {
- noteId: this.appearNote.id
- });
- },
-
- toggleWatch(watch: boolean) {
- os.apiWithDialog(watch ? 'notes/watching/create' : 'notes/watching/delete', {
- noteId: this.appearNote.id
- });
- },
-
- toggleThreadMute(mute: boolean) {
- os.apiWithDialog(mute ? 'notes/thread-muting/create' : 'notes/thread-muting/delete', {
- noteId: this.appearNote.id
- });
- },
-
- getMenu() {
- let menu;
- if (this.$i) {
- const statePromise = os.api('notes/state', {
- noteId: this.appearNote.id
- });
-
- menu = [{
- icon: 'fas fa-copy',
- text: this.$ts.copyContent,
- action: this.copyContent
- }, {
- icon: 'fas fa-link',
- text: this.$ts.copyLink,
- action: this.copyLink
- }, (this.appearNote.url || this.appearNote.uri) ? {
- icon: 'fas fa-external-link-square-alt',
- text: this.$ts.showOnRemote,
- action: () => {
- window.open(this.appearNote.url || this.appearNote.uri, '_blank');
- }
- } : undefined,
- {
- icon: 'fas fa-share-alt',
- text: this.$ts.share,
- action: this.share
- },
- this.$instance.translatorAvailable ? {
- icon: 'fas fa-language',
- text: this.$ts.translate,
- action: this.translate
- } : undefined,
- null,
- statePromise.then(state => state.isFavorited ? {
- icon: 'fas fa-star',
- text: this.$ts.unfavorite,
- action: () => this.toggleFavorite(false)
- } : {
- icon: 'fas fa-star',
- text: this.$ts.favorite,
- action: () => this.toggleFavorite(true)
- }),
- {
- icon: 'fas fa-paperclip',
- text: this.$ts.clip,
- action: () => this.clip()
- },
- (this.appearNote.userId != this.$i.id) ? statePromise.then(state => state.isWatching ? {
- icon: 'fas fa-eye-slash',
- text: this.$ts.unwatch,
- action: () => this.toggleWatch(false)
- } : {
- icon: 'fas fa-eye',
- text: this.$ts.watch,
- action: () => this.toggleWatch(true)
- }) : undefined,
- statePromise.then(state => state.isMutedThread ? {
- icon: 'fas fa-comment-slash',
- text: this.$ts.unmuteThread,
- action: () => this.toggleThreadMute(false)
- } : {
- icon: 'fas fa-comment-slash',
- text: this.$ts.muteThread,
- action: () => this.toggleThreadMute(true)
- }),
- this.appearNote.userId == this.$i.id ? (this.$i.pinnedNoteIds || []).includes(this.appearNote.id) ? {
- icon: 'fas fa-thumbtack',
- text: this.$ts.unpin,
- action: () => this.togglePin(false)
- } : {
- icon: 'fas fa-thumbtack',
- text: this.$ts.pin,
- action: () => this.togglePin(true)
- } : undefined,
- /*
- ...(this.$i.isModerator || this.$i.isAdmin ? [
- null,
- {
- icon: 'fas fa-bullhorn',
- text: this.$ts.promote,
- action: this.promote
- }]
- : []
- ),*/
- ...(this.appearNote.userId != this.$i.id ? [
- null,
- {
- icon: 'fas fa-exclamation-circle',
- text: this.$ts.reportAbuse,
- action: () => {
- const u = `${url}/notes/${this.appearNote.id}`;
- os.popup(import('@/components/abuse-report-window.vue'), {
- user: this.appearNote.user,
- initialComment: `Note: ${u}\n-----\n`
- }, {}, 'closed');
- }
- }]
- : []
- ),
- ...(this.appearNote.userId == this.$i.id || this.$i.isModerator || this.$i.isAdmin ? [
- null,
- this.appearNote.userId == this.$i.id ? {
- icon: 'fas fa-edit',
- text: this.$ts.deleteAndEdit,
- action: this.delEdit
- } : undefined,
- {
- icon: 'fas fa-trash-alt',
- text: this.$ts.delete,
- danger: true,
- action: this.del
- }]
- : []
- )]
- .filter(x => x !== undefined);
- } else {
- menu = [{
- icon: 'fas fa-copy',
- text: this.$ts.copyContent,
- action: this.copyContent
- }, {
- icon: 'fas fa-link',
- text: this.$ts.copyLink,
- action: this.copyLink
- }, (this.appearNote.url || this.appearNote.uri) ? {
- icon: 'fas fa-external-link-square-alt',
- text: this.$ts.showOnRemote,
- action: () => {
- window.open(this.appearNote.url || this.appearNote.uri, '_blank');
- }
- } : undefined]
- .filter(x => x !== undefined);
- }
-
- if (noteActions.length > 0) {
- menu = menu.concat([null, ...noteActions.map(action => ({
- icon: 'fas fa-plug',
- text: action.title,
- action: () => {
- action.handler(this.appearNote);
- }
- }))]);
- }
-
- return menu;
- },
-
- onContextmenu(e) {
- const isLink = (el: HTMLElement) => {
- if (el.tagName === 'A') return true;
- if (el.parentElement) {
- return isLink(el.parentElement);
- }
- };
- if (isLink(e.target)) return;
- if (window.getSelection().toString() !== '') return;
-
- if (this.$store.state.useReactionPickerForContextMenu) {
- e.preventDefault();
- this.react();
- } else {
- os.contextMenu(this.getMenu(), e).then(this.focus);
- }
- },
-
- menu(viaKeyboard = false) {
- os.popupMenu(this.getMenu(), this.$refs.menuButton, {
- viaKeyboard
- }).then(this.focus);
- },
-
- showRenoteMenu(viaKeyboard = false) {
- if (!this.isMyRenote) return;
- os.popupMenu([{
- text: this.$ts.unrenote,
- icon: 'fas fa-trash-alt',
- danger: true,
- action: () => {
- os.api('notes/delete', {
- noteId: this.note.id
- });
- this.isDeleted = true;
- }
- }], this.$refs.renoteTime, {
- viaKeyboard: viaKeyboard
- });
- },
-
- toggleShowContent() {
- this.showContent = !this.showContent;
- },
-
- copyContent() {
- copyToClipboard(this.appearNote.text);
- os.success();
- },
-
- copyLink() {
- copyToClipboard(`${url}/notes/${this.appearNote.id}`);
- os.success();
- },
-
- togglePin(pin: boolean) {
- os.apiWithDialog(pin ? 'i/pin' : 'i/unpin', {
- noteId: this.appearNote.id
- }, undefined, null, e => {
- if (e.id === '72dab508-c64d-498f-8740-a8eec1ba385a') {
- os.alert({
- type: 'error',
- text: this.$ts.pinLimitExceeded
- });
- }
- });
- },
-
- async clip() {
- const clips = await os.api('clips/list');
- os.popupMenu([{
- icon: 'fas fa-plus',
- text: this.$ts.createNew,
- action: async () => {
- const { canceled, result } = await os.form(this.$ts.createNewClip, {
- name: {
- type: 'string',
- label: this.$ts.name
- },
- description: {
- type: 'string',
- required: false,
- multiline: true,
- label: this.$ts.description
- },
- isPublic: {
- type: 'boolean',
- label: this.$ts.public,
- default: false
- }
- });
- if (canceled) return;
-
- const clip = await os.apiWithDialog('clips/create', result);
-
- os.apiWithDialog('clips/add-note', { clipId: clip.id, noteId: this.appearNote.id });
- }
- }, null, ...clips.map(clip => ({
- text: clip.name,
- action: () => {
- os.apiWithDialog('clips/add-note', { clipId: clip.id, noteId: this.appearNote.id });
- }
- }))], this.$refs.menuButton, {
- }).then(this.focus);
- },
-
- async promote() {
- const { canceled, result: days } = await os.inputNumber({
- title: this.$ts.numberOfDays,
- });
-
- if (canceled) return;
-
- os.apiWithDialog('admin/promo/create', {
- noteId: this.appearNote.id,
- expiresAt: Date.now() + (86400000 * days)
- });
- },
+ if (defaultStore.state.useReactionPickerForContextMenu) {
+ ev.preventDefault();
+ react();
+ } else {
+ os.contextMenu(getNoteMenu({ note: props.note, translating, translation, menuButton }), ev).then(focus);
+ }
+}
- share() {
- navigator.share({
- title: this.$t('noteOf', { user: this.appearNote.user.name }),
- text: this.appearNote.text,
- url: `${url}/notes/${this.appearNote.id}`
- });
- },
+function menu(viaKeyboard = false): void {
+ os.popupMenu(getNoteMenu({ note: props.note, translating, translation, menuButton }), menuButton.value, {
+ viaKeyboard
+ }).then(focus);
+}
- async translate() {
- if (this.translation != null) return;
- this.translating = true;
- const res = await os.api('notes/translate', {
- noteId: this.appearNote.id,
- targetLang: localStorage.getItem('lang') || navigator.language,
+function showRenoteMenu(viaKeyboard = false): void {
+ if (!isMyRenote) return;
+ os.popupMenu([{
+ text: i18n.locale.unrenote,
+ icon: 'fas fa-trash-alt',
+ danger: true,
+ action: () => {
+ os.api('notes/delete', {
+ noteId: props.note.id
});
- this.translating = false;
- this.translation = res;
- },
+ isDeleted.value = true;
+ }
+ }], renoteTime.value, {
+ viaKeyboard: viaKeyboard
+ });
+}
- focus() {
- this.$el.focus();
- },
+function focus() {
+ el.value.focus();
+}
- blur() {
- this.$el.blur();
- },
+function blur() {
+ el.value.blur();
+}
- focusBefore() {
- focusPrev(this.$el);
- },
+function focusBefore() {
+ focusPrev(el.value);
+}
- focusAfter() {
- focusNext(this.$el);
- },
+function focusAfter() {
+ focusNext(el.value);
+}
- userPage
- }
-});
+function readPromo() {
+ os.api('promo/read', {
+ noteId: appearNote.id
+ });
+ isDeleted.value = true;
+}
</script>
<style lang="scss" scoped>
diff --git a/packages/client/src/components/notes.vue b/packages/client/src/components/notes.vue
index 4136f72b1b..41bec5a579 100644
--- a/packages/client/src/components/notes.vue
+++ b/packages/client/src/components/notes.vue
@@ -1,114 +1,42 @@
<template>
-<transition name="fade" mode="out-in">
- <MkLoading v-if="fetching"/>
-
- <MkError v-else-if="error" @retry="init()"/>
-
- <div v-else-if="empty" class="_fullinfo">
- <img src="https://xn--931a.moe/assets/info.jpg" class="_ghost"/>
- <div>{{ $ts.noNotes }}</div>
- </div>
-
- <div v-else class="giivymft" :class="{ noGap }">
- <div v-show="more && reversed" style="margin-bottom: var(--margin);">
- <MkButton style="margin: 0 auto;" :disabled="moreFetching" :style="{ cursor: moreFetching ? 'wait' : 'pointer' }" @click="fetchMoreFeature">
- <template v-if="!moreFetching">{{ $ts.loadMore }}</template>
- <template v-if="moreFetching"><MkLoading inline/></template>
- </MkButton>
+<MkPagination ref="pagingComponent" :pagination="pagination">
+ <template #empty>
+ <div class="_fullinfo">
+ <img src="https://xn--931a.moe/assets/info.jpg" class="_ghost"/>
+ <div>{{ $ts.noNotes }}</div>
</div>
+ </template>
- <XList ref="notes" v-slot="{ item: note }" :items="notes" :direction="reversed ? 'up' : 'down'" :reversed="reversed" :no-gap="noGap" :ad="true" class="notes">
- <XNote :key="note._featuredId_ || note._prId_ || note.id" class="qtqtichx" :note="note" @update:note="updated(note, $event)"/>
- </XList>
-
- <div v-show="more && !reversed" style="margin-top: var(--margin);">
- <MkButton v-appear="$store.state.enableInfiniteScroll ? fetchMore : null" style="margin: 0 auto;" :disabled="moreFetching" :style="{ cursor: moreFetching ? 'wait' : 'pointer' }" @click="fetchMore">
- <template v-if="!moreFetching">{{ $ts.loadMore }}</template>
- <template v-if="moreFetching"><MkLoading inline/></template>
- </MkButton>
+ <template #default="{ items: notes }">
+ <div class="giivymft" :class="{ noGap }">
+ <XList ref="notes" v-slot="{ item: note }" :items="notes" :direction="pagination.reversed ? 'up' : 'down'" :reversed="pagination.reversed" :no-gap="noGap" :ad="true" class="notes">
+ <XNote :key="note._featuredId_ || note._prId_ || note.id" class="qtqtichx" :note="note"/>
+ </XList>
</div>
- </div>
-</transition>
+ </template>
+</MkPagination>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
-import paging from '@/scripts/paging';
-import XNote from './note.vue';
-import XList from './date-separated-list.vue';
-import MkButton from '@/components/ui/button.vue';
-
-export default defineComponent({
- components: {
- XNote, XList, MkButton,
- },
-
- mixins: [
- paging({
- before: (self) => {
- self.$emit('before');
- },
-
- after: (self, e) => {
- self.$emit('after', e);
- }
- }),
- ],
-
- props: {
- pagination: {
- required: true
- },
- prop: {
- type: String,
- required: false
- },
- noGap: {
- type: Boolean,
- required: false,
- default: false
- },
- },
+<script lang="ts" setup>
+import { ref } from 'vue';
+import XNote from '@/components/note.vue';
+import XList from '@/components/date-separated-list.vue';
+import MkPagination from '@/components/ui/pagination.vue';
+import { Paging } from '@/components/ui/pagination.vue';
- emits: ['before', 'after'],
+const props = defineProps<{
+ pagination: Paging;
+ noGap?: boolean;
+}>();
- computed: {
- notes(): any[] {
- return this.prop ? this.items.map(item => item[this.prop]) : this.items;
- },
+const pagingComponent = ref<InstanceType<typeof MkPagination>>();
- reversed(): boolean {
- return this.pagination.reversed;
- }
- },
-
- methods: {
- updated(oldValue, newValue) {
- const i = this.notes.findIndex(n => n === oldValue);
- if (this.prop) {
- this.items[i][this.prop] = newValue;
- } else {
- this.items[i] = newValue;
- }
- },
-
- focus() {
- this.$refs.notes.focus();
- }
- }
+defineExpose({
+ pagingComponent,
});
</script>
<style lang="scss" scoped>
-.fade-enter-active,
-.fade-leave-active {
- transition: opacity 0.125s ease;
-}
-.fade-enter-from,
-.fade-leave-to {
- opacity: 0;
-}
-
.giivymft {
&.noGap {
> .notes {
diff --git a/packages/client/src/components/notification-toast.vue b/packages/client/src/components/notification-toast.vue
index 5449409ccc..b2ab1029ad 100644
--- a/packages/client/src/components/notification-toast.vue
+++ b/packages/client/src/components/notification-toast.vue
@@ -1,6 +1,6 @@
<template>
<div class="mk-notification-toast" :style="{ zIndex }">
- <transition name="notification-toast" appear @after-leave="$emit('closed')">
+ <transition :name="$store.state.animation ? 'notification-toast' : ''" appear @after-leave="$emit('closed')">
<XNotification v-if="showing" :notification="notification" class="notification _acrylic"/>
</transition>
</div>
@@ -29,7 +29,7 @@ export default defineComponent({
};
},
mounted() {
- setTimeout(() => {
+ window.setTimeout(() => {
this.showing = false;
}, 6000);
}
diff --git a/packages/client/src/components/notification.vue b/packages/client/src/components/notification.vue
index 37a88edc64..5659c899be 100644
--- a/packages/client/src/components/notification.vue
+++ b/packages/client/src/components/notification.vue
@@ -74,6 +74,7 @@ import { notePage } from '@/filters/note';
import { userPage } from '@/filters/user';
import { i18n } from '@/i18n';
import * as os from '@/os';
+import { stream } from '@/stream';
import { useTooltip } from '@/scripts/use-tooltip';
export default defineComponent({
@@ -106,7 +107,7 @@ export default defineComponent({
if (!props.notification.isRead) {
const readObserver = new IntersectionObserver((entries, observer) => {
if (!entries.some(entry => entry.isIntersecting)) return;
- os.stream.send('readNotification', {
+ stream.send('readNotification', {
id: props.notification.id
});
observer.disconnect();
@@ -114,7 +115,7 @@ export default defineComponent({
readObserver.observe(elRef.value);
- const connection = os.stream.useChannel('main');
+ const connection = stream.useChannel('main');
connection.on('readAllNotifications', () => readObserver.disconnect());
onUnmounted(() => {
diff --git a/packages/client/src/components/notifications.vue b/packages/client/src/components/notifications.vue
index f3e5ee32f7..5a77b5487e 100644
--- a/packages/client/src/components/notifications.vue
+++ b/packages/client/src/components/notifications.vue
@@ -1,158 +1,77 @@
<template>
-<transition name="fade" mode="out-in">
- <MkLoading v-if="fetching"/>
+<MkPagination ref="pagingComponent" :pagination="pagination">
+ <template #empty>
+ <div class="_fullinfo">
+ <img src="https://xn--931a.moe/assets/info.jpg" class="_ghost"/>
+ <div>{{ $ts.noNotifications }}</div>
+ </div>
+ </template>
- <MkError v-else-if="error" @retry="init()"/>
-
- <p v-else-if="empty" class="mfcuwfyp">{{ $ts.noNotifications }}</p>
-
- <div v-else>
- <XList v-slot="{ item: notification }" class="elsfgstc" :items="items" :no-gap="true">
- <XNote v-if="['reply', 'quote', 'mention'].includes(notification.type)" :key="notification.id" :note="notification.note" @update:note="noteUpdated(notification.note, $event)"/>
+ <template #default="{ items: notifications }">
+ <XList v-slot="{ item: notification }" class="elsfgstc" :items="notifications" :no-gap="true">
+ <XNote v-if="['reply', 'quote', 'mention'].includes(notification.type)" :key="notification.id" :note="notification.note"/>
<XNotification v-else :key="notification.id" :notification="notification" :with-time="true" :full="true" class="_panel notification"/>
</XList>
-
- <MkButton v-show="more" v-appear="$store.state.enableInfiniteScroll ? fetchMore : null" primary style="margin: var(--margin) auto;" :disabled="moreFetching" :style="{ cursor: moreFetching ? 'wait' : 'pointer' }" @click="fetchMore">
- <template v-if="!moreFetching">{{ $ts.loadMore }}</template>
- <template v-if="moreFetching"><MkLoading inline/></template>
- </MkButton>
- </div>
-</transition>
+ </template>
+</MkPagination>
</template>
-<script lang="ts">
-import { defineComponent, PropType, markRaw } from 'vue';
-import paging from '@/scripts/paging';
-import XNotification from './notification.vue';
-import XList from './date-separated-list.vue';
-import XNote from './note.vue';
+<script lang="ts" setup>
+import { defineComponent, PropType, markRaw, onUnmounted, onMounted, computed, ref } from 'vue';
import { notificationTypes } from 'misskey-js';
+import MkPagination from '@/components/ui/pagination.vue';
+import { Paging } from '@/components/ui/pagination.vue';
+import XNotification from '@/components/notification.vue';
+import XList from '@/components/date-separated-list.vue';
+import XNote from '@/components/note.vue';
import * as os from '@/os';
-import MkButton from '@/components/ui/button.vue';
-
-export default defineComponent({
- components: {
- XNotification,
- XList,
- XNote,
- MkButton,
- },
-
- mixins: [
- paging({}),
- ],
-
- props: {
- includeTypes: {
- type: Array as PropType<typeof notificationTypes[number][]>,
- required: false,
- default: null,
- },
- unreadOnly: {
- type: Boolean,
- required: false,
- default: false,
- },
- },
-
- data() {
- return {
- connection: null,
- pagination: {
- endpoint: 'i/notifications',
- limit: 10,
- params: () => ({
- includeTypes: this.allIncludeTypes || undefined,
- unreadOnly: this.unreadOnly,
- })
- },
- };
- },
-
- computed: {
- allIncludeTypes() {
- return this.includeTypes ?? notificationTypes.filter(x => !this.$i.mutingNotificationTypes.includes(x));
- }
- },
+import { stream } from '@/stream';
+import { $i } from '@/account';
- watch: {
- includeTypes: {
- handler() {
- this.reload();
- },
- deep: true
- },
- unreadOnly: {
- handler() {
- this.reload();
- },
- },
- // TODO: vue/vuexのバグか仕様かは不明なものの、プロフィール更新するなどして $i が更新されると、
- // mutingNotificationTypes に変化が無くてもこのハンドラーが呼び出され無駄なリロードが発生するのを直す
- '$i.mutingNotificationTypes': {
- handler() {
- if (this.includeTypes === null) {
- this.reload();
- }
- },
- deep: true
- }
- },
+const props = defineProps<{
+ includeTypes?: PropType<typeof notificationTypes[number][]>;
+ unreadOnly?: boolean;
+}>();
- mounted() {
- this.connection = markRaw(os.stream.useChannel('main'));
- this.connection.on('notification', this.onNotification);
- },
+const pagingComponent = ref<InstanceType<typeof MkPagination>>();
- beforeUnmount() {
- this.connection.dispose();
- },
+const allIncludeTypes = computed(() => props.includeTypes ?? notificationTypes.filter(x => !$i.mutingNotificationTypes.includes(x)));
- methods: {
- onNotification(notification) {
- const isMuted = !this.allIncludeTypes.includes(notification.type);
- if (isMuted || document.visibilityState === 'visible') {
- os.stream.send('readNotification', {
- id: notification.id
- });
- }
+const pagination: Paging = {
+ endpoint: 'i/notifications' as const,
+ limit: 10,
+ params: computed(() => ({
+ includeTypes: allIncludeTypes.value || undefined,
+ unreadOnly: props.unreadOnly,
+ })),
+};
- if (!isMuted) {
- this.prepend({
- ...notification,
- isRead: document.visibilityState === 'visible'
- });
- }
- },
+const onNotification = (notification) => {
+ const isMuted = !allIncludeTypes.value.includes(notification.type);
+ if (isMuted || document.visibilityState === 'visible') {
+ stream.send('readNotification', {
+ id: notification.id
+ });
+ }
- noteUpdated(oldValue, newValue) {
- const i = this.items.findIndex(n => n.note === oldValue);
- this.items[i] = {
- ...this.items[i],
- note: newValue
- };
- },
+ if (!isMuted) {
+ pagingComponent.value.prepend({
+ ...notification,
+ isRead: document.visibilityState === 'visible'
+ });
}
+};
+
+onMounted(() => {
+ const connection = stream.useChannel('main');
+ connection.on('notification', onNotification);
+ onUnmounted(() => {
+ connection.dispose();
+ });
});
</script>
<style lang="scss" scoped>
-.fade-enter-active,
-.fade-leave-active {
- transition: opacity 0.125s ease;
-}
-.fade-enter-from,
-.fade-leave-to {
- opacity: 0;
-}
-
-.mfcuwfyp {
- margin: 0;
- padding: 16px;
- text-align: center;
- color: var(--fg);
-}
-
.elsfgstc {
background: var(--panel);
}
diff --git a/packages/client/src/components/object-view.value.vue b/packages/client/src/components/object-view.value.vue
new file mode 100644
index 0000000000..6f388636dd
--- /dev/null
+++ b/packages/client/src/components/object-view.value.vue
@@ -0,0 +1,108 @@
+<template>
+<div class="igpposuu _monospace">
+ <div v-if="value === null" class="null">null</div>
+ <div v-else-if="typeof value === 'boolean'" class="boolean">{{ value ? 'true' : 'false' }}</div>
+ <div v-else-if="typeof value === 'string'" class="string">"{{ value }}"</div>
+ <div v-else-if="typeof value === 'number'" class="number">{{ number(value) }}</div>
+ <div v-else-if="Array.isArray(value)" class="array">
+ <button @click="collapsed_ = !collapsed_">[ {{ collapsed_ ? '+' : '-' }} ]</button>
+ <template v-if="!collapsed_">
+ <div v-for="i in value.length" class="element">
+ {{ i }}: <XValue :value="value[i - 1]" collapsed/>
+ </div>
+ </template>
+ </div>
+ <div v-else-if="typeof value === 'object'" class="object">
+ <button @click="collapsed_ = !collapsed_">{ {{ collapsed_ ? '+' : '-' }} }</button>
+ <template v-if="!collapsed_">
+ <div v-for="k in Object.keys(value)" class="kv">
+ <div class="k">{{ k }}:</div>
+ <div class="v"><XValue :value="value[k]" collapsed/></div>
+ </div>
+ </template>
+ </div>
+</div>
+</template>
+
+<script lang="ts">
+import { computed, defineComponent, ref } from 'vue';
+import number from '@/filters/number';
+
+export default defineComponent({
+ name: 'XValue',
+
+ props: {
+ value: {
+ type: Object,
+ required: true,
+ },
+ collapsed: {
+ type: Boolean,
+ required: false,
+ default: false,
+ },
+ },
+
+ setup(props) {
+ const collapsed_ = ref(props.collapsed);
+
+ return {
+ number,
+ collapsed_,
+ };
+ }
+});
+</script>
+
+<style lang="scss" scoped>
+.igpposuu {
+ display: inline;
+
+ > .null {
+ display: inline;
+ opacity: 0.7;
+ }
+
+ > .boolean {
+ display: inline;
+ color: var(--codeBoolean);
+ }
+
+ > .string {
+ display: inline;
+ color: var(--codeString);
+ }
+
+ > .number {
+ display: inline;
+ color: var(--codeNumber);
+ }
+
+ > .array {
+ display: inline;
+
+ > .element {
+ display: block;
+ padding-left: 16px;
+ }
+ }
+
+ > .object {
+ display: inline;
+
+ > .kv {
+ display: block;
+ padding-left: 16px;
+
+ > .k {
+ display: inline;
+ margin-right: 8px;
+ }
+
+ > .v {
+ display: inline;
+ }
+ }
+ }
+}
+</style>
diff --git a/packages/client/src/components/object-view.vue b/packages/client/src/components/object-view.vue
new file mode 100644
index 0000000000..e9db96de8c
--- /dev/null
+++ b/packages/client/src/components/object-view.vue
@@ -0,0 +1,33 @@
+<template>
+<div class="zhyxdalp">
+ <XValue :value="value" :collapsed="false"/>
+</div>
+</template>
+
+<script lang="ts">
+import { computed, defineComponent } from 'vue';
+import XValue from './object-view.value.vue';
+
+export default defineComponent({
+ components: {
+ XValue
+ },
+
+ props: {
+ value: {
+ type: Object,
+ required: true,
+ },
+ },
+
+ setup(props) {
+
+ }
+});
+</script>
+
+<style lang="scss" scoped>
+.zhyxdalp {
+
+}
+</style>
diff --git a/packages/client/src/components/poll-editor.vue b/packages/client/src/components/poll-editor.vue
index fad0cf1593..6f3f23a2d3 100644
--- a/packages/client/src/components/poll-editor.vue
+++ b/packages/client/src/components/poll-editor.vue
@@ -3,7 +3,7 @@
<p v-if="choices.length < 2" class="caution">
<i class="fas fa-exclamation-triangle"></i>{{ $ts._poll.noOnlyOneChoice }}
</p>
- <ul ref="choices">
+ <ul>
<li v-for="(choice, i) in choices" :key="i">
<MkInput class="input" :model-value="choice" :placeholder="$t('_poll.choiceN', { n: i + 1 })" @update:modelValue="onInput(i, $event)">
</MkInput>
@@ -14,8 +14,8 @@
</ul>
<MkButton v-if="choices.length < 10" class="add" @click="add">{{ $ts.add }}</MkButton>
<MkButton v-else class="add" disabled>{{ $ts._poll.noMore }}</MkButton>
+ <MkSwitch v-model="multiple">{{ $ts._poll.canMultipleVote }}</MkSwitch>
<section>
- <MkSwitch v-model="multiple">{{ $ts._poll.canMultipleVote }}</MkSwitch>
<div>
<MkSelect v-model="expiration">
<template #label>{{ $ts._poll.expiration }}</template>
@@ -31,7 +31,7 @@
<template #label>{{ $ts._poll.deadlineTime }}</template>
</MkInput>
</section>
- <section v-if="expiration === 'after'">
+ <section v-else-if="expiration === 'after'">
<MkInput v-model="after" type="number" class="input">
<template #label>{{ $ts._poll.duration }}</template>
</MkInput>
@@ -47,8 +47,8 @@
</div>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
+<script lang="ts" setup>
+import { ref, watch } from 'vue';
import { addTime } from '@/scripts/time';
import { formatDateTimeString } from '@/scripts/format-time-string';
import MkInput from './form/input.vue';
@@ -56,131 +56,91 @@ import MkSelect from './form/select.vue';
import MkSwitch from './form/switch.vue';
import MkButton from './ui/button.vue';
-export default defineComponent({
- components: {
- MkInput,
- MkSelect,
- MkSwitch,
- MkButton,
- },
+const props = defineProps<{
+ modelValue: {
+ expiresAt: string;
+ expiredAfter: number;
+ choices: string[];
+ multiple: boolean;
+ };
+}>();
+const emit = defineEmits<{
+ (ev: 'update:modelValue', v: {
+ expiresAt: string;
+ expiredAfter: number;
+ choices: string[];
+ multiple: boolean;
+ }): void;
+}>();
- props: {
- poll: {
- type: Object,
- required: true
- }
- },
-
- emits: ['updated'],
-
- data() {
- return {
- choices: this.poll.choices,
- multiple: this.poll.multiple,
- expiration: 'infinite',
- atDate: formatDateTimeString(addTime(new Date(), 1, 'day'), 'yyyy-MM-dd'),
- atTime: '00:00',
- after: 0,
- unit: 'second',
- };
- },
+const choices = ref(props.modelValue.choices);
+const multiple = ref(props.modelValue.multiple);
+const expiration = ref('infinite');
+const atDate = ref(formatDateTimeString(addTime(new Date(), 1, 'day'), 'yyyy-MM-dd'));
+const atTime = ref('00:00');
+const after = ref(0);
+const unit = ref('second');
- watch: {
- choices: {
- handler() {
- this.$emit('updated', this.get());
- },
- deep: true
- },
- multiple: {
- handler() {
- this.$emit('updated', this.get());
- },
- },
- expiration: {
- handler() {
- this.$emit('updated', this.get());
- },
- },
- atDate: {
- handler() {
- this.$emit('updated', this.get());
- },
- },
- after: {
- handler() {
- this.$emit('updated', this.get());
- },
- },
- unit: {
- handler() {
- this.$emit('updated', this.get());
- },
- },
- },
+if (props.modelValue.expiresAt) {
+ expiration.value = 'at';
+ atDate.value = atTime.value = props.modelValue.expiresAt;
+} else if (typeof props.modelValue.expiredAfter === 'number') {
+ expiration.value = 'after';
+ after.value = props.modelValue.expiredAfter / 1000;
+} else {
+ expiration.value = 'infinite';
+}
- created() {
- const poll = this.poll;
- if (poll.expiresAt) {
- this.expiration = 'at';
- this.atDate = this.atTime = poll.expiresAt;
- } else if (typeof poll.expiredAfter === 'number') {
- this.expiration = 'after';
- this.after = poll.expiredAfter / 1000;
- } else {
- this.expiration = 'infinite';
- }
- },
+function onInput(i, value) {
+ choices.value[i] = value;
+}
- methods: {
- onInput(i, e) {
- this.choices[i] = e;
- },
+function add() {
+ choices.value.push('');
+ // TODO
+ // nextTick(() => {
+ // (this.$refs.choices as any).childNodes[this.choices.length - 1].childNodes[0].focus();
+ // });
+}
- add() {
- this.choices.push('');
- this.$nextTick(() => {
- // TODO
- //(this.$refs.choices as any).childNodes[this.choices.length - 1].childNodes[0].focus();
- });
- },
+function remove(i) {
+ choices.value = choices.value.filter((_, _i) => _i != i);
+}
- remove(i) {
- this.choices = this.choices.filter((_, _i) => _i != i);
- },
+function get() {
+ const calcAt = () => {
+ return new Date(`${atDate.value} ${atTime.value}`).getTime();
+ };
- get() {
- const at = () => {
- return new Date(`${this.atDate} ${this.atTime}`).getTime();
- };
+ const calcAfter = () => {
+ let base = parseInt(after.value);
+ switch (unit.value) {
+ case 'day': base *= 24;
+ case 'hour': base *= 60;
+ case 'minute': base *= 60;
+ case 'second': return base *= 1000;
+ default: return null;
+ }
+ };
- const after = () => {
- let base = parseInt(this.after);
- switch (this.unit) {
- case 'day': base *= 24;
- case 'hour': base *= 60;
- case 'minute': base *= 60;
- case 'second': return base *= 1000;
- default: return null;
- }
- };
+ return {
+ choices: choices.value,
+ multiple: multiple.value,
+ ...(
+ expiration.value === 'at' ? { expiresAt: calcAt() } :
+ expiration.value === 'after' ? { expiredAfter: calcAfter() } : {}
+ )
+ };
+}
- return {
- choices: this.choices,
- multiple: this.multiple,
- ...(
- this.expiration === 'at' ? { expiresAt: at() } :
- this.expiration === 'after' ? { expiredAfter: after() } : {}
- )
- };
- },
- }
+watch([choices, multiple, expiration, atDate, atTime, after, unit], () => emit('update:modelValue', get()), {
+ deep: true,
});
</script>
<style lang="scss" scoped>
.zmdxowus {
- padding: 8px;
+ padding: 8px 16px;
> .caution {
margin: 0 0 8px 0;
@@ -216,7 +176,7 @@ export default defineComponent({
}
> .add {
- margin: 8px 0 0 0;
+ margin: 8px 0;
z-index: 1;
}
@@ -225,21 +185,27 @@ export default defineComponent({
> div {
margin: 0 8px;
+ display: flex;
+ flex-direction: row;
+ flex-wrap: wrap;
+ gap: 12px;
&:last-child {
flex: 1 0 auto;
+ > div {
+ flex-grow: 1;
+ }
+
> section {
- align-items: center;
+ // MAGIC: Prevent div above from growing unless wrapped to its own line
+ flex-grow: 9999;
+ align-items: end;
display: flex;
- margin: -32px 0 0;
-
- > &:first-child {
- margin-right: 16px;
- }
+ gap: 4px;
> .input {
- flex: 1 0 auto;
+ flex: 1 1 auto;
}
}
}
diff --git a/packages/client/src/components/post-form-attaches.vue b/packages/client/src/components/post-form-attaches.vue
index 0782ce22e5..0c8181b481 100644
--- a/packages/client/src/components/post-form-attaches.vue
+++ b/packages/client/src/components/post-form-attaches.vue
@@ -10,7 +10,7 @@
</div>
</template>
</XDraggable>
- <p class="remain">{{ 4 - files.length }}/4</p>
+ <p class="remain">{{ 16 - files.length }}/16</p>
</div>
</template>
@@ -41,7 +41,6 @@ export default defineComponent({
data() {
return {
menu: null as Promise<null> | null,
-
};
},
@@ -99,10 +98,12 @@ export default defineComponent({
}, {
done: result => {
if (!result || result.canceled) return;
- let comment = result.result;
+ let comment = result.result.length == 0 ? null : result.result;
os.api('drive/files/update', {
fileId: file.id,
- comment: comment.length == 0 ? null : comment
+ comment: comment,
+ }).then(() => {
+ file.comment = comment;
});
}
}, 'closed');
diff --git a/packages/client/src/components/post-form.vue b/packages/client/src/components/post-form.vue
index 4265c575e2..ed78c5a3fb 100644
--- a/packages/client/src/components/post-form.vue
+++ b/packages/client/src/components/post-form.vue
@@ -8,25 +8,28 @@
>
<header>
<button v-if="!fixed" class="cancel _button" @click="cancel"><i class="fas fa-times"></i></button>
+ <button v-click-anime v-tooltip="i18n.locale.switchAccount" class="account _button" @click="openAccountMenu">
+ <MkAvatar :user="postAccount ?? $i" class="avatar"/>
+ </button>
<div>
- <span class="text-count" :class="{ over: textLength > max }">{{ max - textLength }}</span>
+ <span class="text-count" :class="{ over: textLength > maxTextLength }">{{ maxTextLength - textLength }}</span>
<span v-if="localOnly" class="local-only"><i class="fas fa-biohazard"></i></span>
- <button ref="visibilityButton" v-tooltip="$ts.visibility" class="_button visibility" :disabled="channel != null" @click="setVisibility">
+ <button ref="visibilityButton" v-tooltip="i18n.locale.visibility" class="_button visibility" :disabled="channel != null" @click="setVisibility">
<span v-if="visibility === 'public'"><i class="fas fa-globe"></i></span>
<span v-if="visibility === 'home'"><i class="fas fa-home"></i></span>
<span v-if="visibility === 'followers'"><i class="fas fa-unlock"></i></span>
<span v-if="visibility === 'specified'"><i class="fas fa-envelope"></i></span>
</button>
- <button v-tooltip="$ts.previewNoteText" class="_button preview" :class="{ active: showPreview }" @click="showPreview = !showPreview"><i class="fas fa-file-code"></i></button>
+ <button v-tooltip="i18n.locale.previewNoteText" class="_button preview" :class="{ active: showPreview }" @click="showPreview = !showPreview"><i class="fas fa-file-code"></i></button>
<button class="submit _buttonGradate" :disabled="!canPost" data-cy-open-post-form-submit @click="post">{{ submitText }}<i :class="reply ? 'fas fa-reply' : renote ? 'fas fa-quote-right' : 'fas fa-paper-plane'"></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"><i class="fas fa-quote-left"></i> {{ $ts.quoteAttached }}<button @click="quoteId = null"><i class="fas fa-times"></i></button></div>
+ <div v-if="quoteId" class="with-quote"><i class="fas fa-quote-left"></i> {{ i18n.locale.quoteAttached }}<button @click="quoteId = null"><i class="fas fa-times"></i></button></div>
<div v-if="visibility === 'specified'" class="to-specified">
- <span style="margin-right: 8px;">{{ $ts.recipient }}</span>
+ <span style="margin-right: 8px;">{{ i18n.locale.recipient }}</span>
<div class="visibleUsers">
<span v-for="u in visibleUsers" :key="u.id">
<MkAcct :user="u"/>
@@ -35,21 +38,21 @@
<button class="_buttonPrimary" @click="addVisibleUser"><i class="fas fa-plus fa-fw"></i></button>
</div>
</div>
- <MkInfo v-if="hasNotSpecifiedMentions" warn class="hasNotSpecifiedMentions">{{ $ts.notSpecifiedMentionWarning }} - <button class="_textButton" @click="addMissingMention()">{{ $ts.add }}</button></MkInfo>
- <input v-show="useCw" ref="cw" v-model="cw" class="cw" :placeholder="$ts.annotation" @keydown="onKeydown">
- <textarea ref="text" 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="hashtags" v-model="hashtags" class="hashtags" :placeholder="$ts.hashtags" list="hashtags">
+ <MkInfo v-if="hasNotSpecifiedMentions" warn class="hasNotSpecifiedMentions">{{ i18n.locale.notSpecifiedMentionWarning }} - <button class="_textButton" @click="addMissingMention()">{{ i18n.locale.add }}</button></MkInfo>
+ <input v-show="useCw" ref="cwInputEl" v-model="cw" class="cw" :placeholder="i18n.locale.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.locale.hashtags" list="hashtags">
<XPostFormAttaches class="attaches" :files="files" @updated="updateFiles" @detach="detachFile" @changeSensitive="updateFileSensitive" @changeName="updateFileName"/>
- <XPollEditor v-if="poll" :poll="poll" @destroyed="poll = null" @updated="onPollUpdate"/>
+ <XPollEditor v-if="poll" v-model="poll" @destroyed="poll = null"/>
<XNotePreview v-if="showPreview" class="preview" :text="text"/>
<footer>
- <button v-tooltip="$ts.attachFile" class="_button" @click="chooseFileFrom"><i class="fas fa-photo-video"></i></button>
- <button v-tooltip="$ts.poll" class="_button" :class="{ active: poll }" @click="togglePoll"><i class="fas fa-poll-h"></i></button>
- <button v-tooltip="$ts.useCw" class="_button" :class="{ active: useCw }" @click="useCw = !useCw"><i class="fas fa-eye-slash"></i></button>
- <button v-tooltip="$ts.mention" class="_button" @click="insertMention"><i class="fas fa-at"></i></button>
- <button v-tooltip="$ts.hashtags" class="_button" :class="{ active: withHashtags }" @click="withHashtags = !withHashtags"><i class="fas fa-hashtag"></i></button>
- <button v-tooltip="$ts.emoji" class="_button" @click="insertEmoji"><i class="fas fa-laugh-squint"></i></button>
- <button v-if="postFormActions.length > 0" v-tooltip="$ts.plugin" class="_button" @click="showActions"><i class="fas fa-plug"></i></button>
+ <button v-tooltip="i18n.locale.attachFile" class="_button" @click="chooseFileFrom"><i class="fas fa-photo-video"></i></button>
+ <button v-tooltip="i18n.locale.poll" class="_button" :class="{ active: poll }" @click="togglePoll"><i class="fas fa-poll-h"></i></button>
+ <button v-tooltip="i18n.locale.useCw" class="_button" :class="{ active: useCw }" @click="useCw = !useCw"><i class="fas fa-eye-slash"></i></button>
+ <button v-tooltip="i18n.locale.mention" class="_button" @click="insertMention"><i class="fas fa-at"></i></button>
+ <button v-tooltip="i18n.locale.hashtags" class="_button" :class="{ active: withHashtags }" @click="withHashtags = !withHashtags"><i class="fas fa-hashtag"></i></button>
+ <button v-tooltip="i18n.locale.emoji" class="_button" @click="insertEmoji"><i class="fas fa-laugh-squint"></i></button>
+ <button v-if="postFormActions.length > 0" v-tooltip="i18n.locale.plugin" class="_button" @click="showActions"><i class="fas fa-plug"></i></button>
</footer>
<datalist id="hashtags">
<option v-for="hashtag in recentHashtags" :key="hashtag" :value="hashtag"/>
@@ -58,667 +61,623 @@
</div>
</template>
-<script lang="ts">
-import { defineComponent, defineAsyncComponent } from 'vue';
+<script lang="ts" setup>
+import { inject, watch, nextTick, onMounted } from 'vue';
+import * as mfm from 'mfm-js';
+import * as misskey from 'misskey-js';
import insertTextAtCursor from 'insert-text-at-cursor';
import { length } from 'stringz';
import { toASCII } from 'punycode/';
import XNoteSimple from './note-simple.vue';
import XNotePreview from './note-preview.vue';
-import * as mfm from 'mfm-js';
+import XPostFormAttaches from './post-form-attaches.vue';
+import XPollEditor from './poll-editor.vue';
import { host, url } from '@/config';
import { erase, unique } from '@/scripts/array';
import { extractMentions } from '@/scripts/extract-mentions';
import * as Acct from 'misskey-js/built/acct';
import { formatTimeString } from '@/scripts/format-time-string';
import { Autocomplete } from '@/scripts/autocomplete';
-import { noteVisibilities } from 'misskey-js';
import * as os from '@/os';
+import { stream } from '@/stream';
import { selectFiles } from '@/scripts/select-file';
import { defaultStore, notePostInterruptors, postFormActions } from '@/store';
import { throttle } from 'throttle-debounce';
import MkInfo from '@/components/ui/info.vue';
-import { defaultStore } from '@/store';
+import { i18n } from '@/i18n';
+import { instance } from '@/instance';
+import { $i, getAccounts, openAccountMenu as openAccountMenu_ } from '@/account';
-export default defineComponent({
- components: {
- XNoteSimple,
- XNotePreview,
- XPostFormAttaches: defineAsyncComponent(() => import('./post-form-attaches.vue')),
- XPollEditor: defineAsyncComponent(() => import('./poll-editor.vue')),
- MkInfo,
- },
+const modal = inject('modal');
- inject: ['modal'],
+const props = withDefaults(defineProps<{
+ reply?: misskey.entities.Note;
+ renote?: misskey.entities.Note;
+ channel?: any; // TODO
+ mention?: misskey.entities.User;
+ specified?: misskey.entities.User;
+ initialText?: string;
+ initialVisibility?: typeof misskey.noteVisibilities;
+ initialFiles?: misskey.entities.DriveFile[];
+ initialLocalOnly?: boolean;
+ initialVisibleUsers?: misskey.entities.User[];
+ initialNote?: misskey.entities.Note;
+ share?: boolean;
+ fixed?: boolean;
+ autofocus?: boolean;
+}>(), {
+ initialVisibleUsers: [],
+ autofocus: true,
+});
- props: {
- reply: {
- type: Object,
- required: false
- },
- renote: {
- type: Object,
- required: false
- },
- channel: {
- type: Object,
- required: false
- },
- mention: {
- type: Object,
- required: false
- },
- specified: {
- type: Object,
- required: false
- },
- initialText: {
- type: String,
- required: false
- },
- initialVisibility: {
- type: String,
- required: false
- },
- initialFiles: {
- type: Array,
- required: false
- },
- initialLocalOnly: {
- type: Boolean,
- required: false
- },
- initialVisibleUsers: {
- type: Array,
- required: false,
- default: () => []
- },
- initialNote: {
- type: Object,
- required: false
- },
- share: {
- type: Boolean,
- required: false,
- default: false
- },
- fixed: {
- type: Boolean,
- required: false,
- default: false
- },
- autofocus: {
- type: Boolean,
- required: false,
- default: true
- },
- },
+const emit = defineEmits<{
+ (ev: 'posted'): void;
+ (ev: 'cancel'): void;
+ (ev: 'esc'): void;
+}>();
- emits: ['posted', 'cancel', 'esc'],
+const textareaEl = $ref<HTMLTextAreaElement | null>(null);
+const cwInputEl = $ref<HTMLInputElement | null>(null);
+const hashtagsInputEl = $ref<HTMLInputElement | null>(null);
+const visibilityButton = $ref<HTMLElement | null>(null);
- data() {
- return {
- posting: false,
- text: '',
- files: [],
- poll: null,
- useCw: false,
- showPreview: false,
- cw: null,
- localOnly: this.$store.state.rememberNoteVisibility ? this.$store.state.localOnly : this.$store.state.defaultNoteLocalOnly,
- visibility: (this.$store.state.rememberNoteVisibility ? this.$store.state.visibility : this.$store.state.defaultNoteVisibility) as typeof noteVisibilities[number],
- visibleUsers: [],
- autocomplete: null,
- draghover: false,
- quoteId: null,
- hasNotSpecifiedMentions: false,
- recentHashtags: JSON.parse(localStorage.getItem('hashtags') || '[]'),
- imeText: '',
- typing: throttle(3000, () => {
- if (this.channel) {
- os.stream.send('typingOnChannel', { channel: this.channel.id });
- }
- }),
- postFormActions,
- };
- },
+let posting = $ref(false);
+let text = $ref(props.initialText ?? '');
+let files = $ref(props.initialFiles ?? []);
+let poll = $ref<{
+ choices: string[];
+ multiple: boolean;
+ expiresAt: string | null;
+ expiredAfter: string | null;
+} | null>(null);
+let useCw = $ref(false);
+let showPreview = $ref(false);
+let cw = $ref<string | null>(null);
+let localOnly = $ref<boolean>(props.initialLocalOnly ?? defaultStore.state.rememberNoteVisibility ? defaultStore.state.localOnly : defaultStore.state.defaultNoteLocalOnly);
+let visibility = $ref(props.initialVisibility ?? (defaultStore.state.rememberNoteVisibility ? defaultStore.state.visibility : defaultStore.state.defaultNoteVisibility) as typeof misskey.noteVisibilities[number]);
+let visibleUsers = $ref(props.initialVisibleUsers ?? []);
+let autocomplete = $ref(null);
+let draghover = $ref(false);
+let quoteId = $ref(null);
+let hasNotSpecifiedMentions = $ref(false);
+let recentHashtags = $ref(JSON.parse(localStorage.getItem('hashtags') || '[]'));
+let imeText = $ref('');
- computed: {
- draftKey(): string {
- let key = this.channel ? `channel:${this.channel.id}` : '';
+const typing = throttle(3000, () => {
+ if (props.channel) {
+ stream.send('typingOnChannel', { channel: props.channel.id });
+ }
+});
- if (this.renote) {
- key += `renote:${this.renote.id}`;
- } else if (this.reply) {
- key += `reply:${this.reply.id}`;
- } else {
- key += 'note';
- }
+const draftKey = $computed((): string => {
+ let key = props.channel ? `channel:${props.channel.id}` : '';
- return key;
- },
+ if (props.renote) {
+ key += `renote:${props.renote.id}`;
+ } else if (props.reply) {
+ key += `reply:${props.reply.id}`;
+ } else {
+ key += 'note';
+ }
- placeholder(): string {
- if (this.renote) {
- return this.$ts._postForm.quotePlaceholder;
- } else if (this.reply) {
- return this.$ts._postForm.replyPlaceholder;
- } else if (this.channel) {
- return this.$ts._postForm.channelPlaceholder;
- } else {
- const xs = [
- this.$ts._postForm._placeholders.a,
- this.$ts._postForm._placeholders.b,
- this.$ts._postForm._placeholders.c,
- this.$ts._postForm._placeholders.d,
- this.$ts._postForm._placeholders.e,
- this.$ts._postForm._placeholders.f
- ];
- return xs[Math.floor(Math.random() * xs.length)];
- }
- },
+ return key;
+});
- submitText(): string {
- return this.renote
- ? this.$ts.quote
- : this.reply
- ? this.$ts.reply
- : this.$ts.note;
- },
+const placeholder = $computed((): string => {
+ if (props.renote) {
+ return i18n.locale._postForm.quotePlaceholder;
+ } else if (props.reply) {
+ return i18n.locale._postForm.replyPlaceholder;
+ } else if (props.channel) {
+ return i18n.locale._postForm.channelPlaceholder;
+ } else {
+ const xs = [
+ i18n.locale._postForm._placeholders.a,
+ i18n.locale._postForm._placeholders.b,
+ i18n.locale._postForm._placeholders.c,
+ i18n.locale._postForm._placeholders.d,
+ i18n.locale._postForm._placeholders.e,
+ i18n.locale._postForm._placeholders.f
+ ];
+ return xs[Math.floor(Math.random() * xs.length)];
+ }
+});
- textLength(): number {
- return length((this.text + this.imeText).trim());
- },
+const submitText = $computed((): string => {
+ return props.renote
+ ? i18n.locale.quote
+ : props.reply
+ ? i18n.locale.reply
+ : i18n.locale.note;
+});
- canPost(): boolean {
- return !this.posting &&
- (1 <= this.textLength || 1 <= this.files.length || !!this.poll || !!this.renote) &&
- (this.textLength <= this.max) &&
- (!this.poll || this.poll.choices.length >= 2);
- },
+const textLength = $computed((): number => {
+ return length((text + imeText).trim());
+});
- max(): number {
- return this.$instance ? this.$instance.maxNoteTextLength : 1000;
- },
+const maxTextLength = $computed((): number => {
+ return instance ? instance.maxNoteTextLength : 1000;
+});
- withHashtags: defaultStore.makeGetterSetter('postFormWithHashtags'),
- hashtags: defaultStore.makeGetterSetter('postFormHashtags'),
- },
+const canPost = $computed((): boolean => {
+ return !posting &&
+ (1 <= textLength || 1 <= files.length || !!poll || !!props.renote) &&
+ (textLength <= maxTextLength) &&
+ (!poll || poll.choices.length >= 2);
+});
- watch: {
- text() {
- this.checkMissingMention();
- },
- visibleUsers: {
- handler() {
- this.checkMissingMention();
- },
- deep: true
- }
- },
+const withHashtags = $computed(defaultStore.makeGetterSetter('postFormWithHashtags'));
+const hashtags = $computed(defaultStore.makeGetterSetter('postFormHashtags'));
- mounted() {
- if (this.initialText) {
- this.text = this.initialText;
- }
+watch($$(text), () => {
+ checkMissingMention();
+});
- if (this.initialVisibility) {
- this.visibility = this.initialVisibility;
- }
+watch($$(visibleUsers), () => {
+ checkMissingMention();
+}, {
+ deep: true,
+});
- if (this.initialFiles) {
- this.files = this.initialFiles;
- }
+if (props.mention) {
+ text = props.mention.host ? `@${props.mention.username}@${toASCII(props.mention.host)}` : `@${props.mention.username}`;
+ text += ' ';
+}
- if (typeof this.initialLocalOnly === 'boolean') {
- this.localOnly = this.initialLocalOnly;
- }
+if (props.reply && (props.reply.user.username != $i.username || (props.reply.user.host != null && props.reply.user.host != host))) {
+ text = `@${props.reply.user.username}${props.reply.user.host != null ? '@' + toASCII(props.reply.user.host) : ''} `;
+}
- if (this.initialVisibleUsers) {
- this.visibleUsers = this.initialVisibleUsers;
- }
+if (props.reply && props.reply.text != null) {
+ const ast = mfm.parse(props.reply.text);
+ const otherHost = props.reply.user.host;
- if (this.mention) {
- this.text = this.mention.host ? `@${this.mention.username}@${toASCII(this.mention.host)}` : `@${this.mention.username}`;
- this.text += ' ';
- }
+ for (const x of extractMentions(ast)) {
+ const mention = x.host ?
+ `@${x.username}@${toASCII(x.host)}` :
+ (otherHost == null || otherHost == host) ?
+ `@${x.username}` :
+ `@${x.username}@${toASCII(otherHost)}`;
- if (this.reply && (this.reply.user.username != this.$i.username || (this.reply.user.host != null && this.reply.user.host != host))) {
- this.text = `@${this.reply.user.username}${this.reply.user.host != null ? '@' + toASCII(this.reply.user.host) : ''} `;
- }
+ // 自分は除外
+ if ($i.username == x.username && x.host == null) continue;
+ if ($i.username == x.username && x.host == host) continue;
- if (this.reply && this.reply.text != null) {
- const ast = mfm.parse(this.reply.text);
- const otherHost = this.reply.user.host;
+ // 重複は除外
+ if (text.indexOf(`${mention} `) != -1) continue;
- for (const x of extractMentions(ast)) {
- const mention = x.host ?
- `@${x.username}@${toASCII(x.host)}` :
- (otherHost == null || otherHost == host) ?
- `@${x.username}` :
- `@${x.username}@${toASCII(otherHost)}`;
+ text += `${mention} `;
+ }
+}
- // 自分は除外
- if (this.$i.username == x.username && x.host == null) continue;
- if (this.$i.username == x.username && x.host == host) continue;
+if (props.channel) {
+ visibility = 'public';
+ localOnly = true; // TODO: チャンネルが連合するようになった折には消す
+}
- // 重複は除外
- if (this.text.indexOf(`${mention} `) != -1) continue;
+// 公開以外へのリプライ時は元の公開範囲を引き継ぐ
+if (props.reply && ['home', 'followers', 'specified'].includes(props.reply.visibility)) {
+ visibility = props.reply.visibility;
+ if (props.reply.visibility === 'specified') {
+ os.api('users/show', {
+ userIds: props.reply.visibleUserIds.filter(uid => uid !== $i.id && uid !== props.reply.userId)
+ }).then(users => {
+ visibleUsers.push(...users);
+ });
- this.text += `${mention} `;
- }
+ if (props.reply.userId !== $i.id) {
+ os.api('users/show', { userId: props.reply.userId }).then(user => {
+ visibleUsers.push(user);
+ });
}
+ }
+}
- if (this.channel) {
- this.visibility = 'public';
- this.localOnly = true; // TODO: チャンネルが連合するようになった折には消す
- }
+if (props.specified) {
+ visibility = 'specified';
+ visibleUsers.push(props.specified);
+}
- // 公開以外へのリプライ時は元の公開範囲を引き継ぐ
- if (this.reply && ['home', 'followers', 'specified'].includes(this.reply.visibility)) {
- this.visibility = this.reply.visibility;
- if (this.reply.visibility === 'specified') {
- os.api('users/show', {
- userIds: this.reply.visibleUserIds.filter(uid => uid !== this.$i.id && uid !== this.reply.userId)
- }).then(users => {
- this.visibleUsers.push(...users);
- });
+// keep cw when reply
+if (defaultStore.state.keepCw && props.reply && props.reply.cw) {
+ useCw = true;
+ cw = props.reply.cw;
+}
- if (this.reply.userId !== this.$i.id) {
- os.api('users/show', { userId: this.reply.userId }).then(user => {
- this.visibleUsers.push(user);
- });
- }
- }
- }
+function watchForDraft() {
+ watch($$(text), () => saveDraft());
+ watch($$(useCw), () => saveDraft());
+ watch($$(cw), () => saveDraft());
+ watch($$(poll), () => saveDraft());
+ watch($$(files), () => saveDraft(), { deep: true });
+ watch($$(visibility), () => saveDraft());
+ watch($$(localOnly), () => saveDraft());
+}
- if (this.specified) {
- this.visibility = 'specified';
- this.visibleUsers.push(this.specified);
- }
+function checkMissingMention() {
+ if (visibility === 'specified') {
+ const ast = mfm.parse(text);
- // keep cw when reply
- if (this.$store.state.keepCw && this.reply && this.reply.cw) {
- this.useCw = true;
- this.cw = this.reply.cw;
+ for (const x of extractMentions(ast)) {
+ if (!visibleUsers.some(u => (u.username === x.username) && (u.host == x.host))) {
+ hasNotSpecifiedMentions = true;
+ return;
+ }
}
+ hasNotSpecifiedMentions = false;
+ }
+}
- if (this.autofocus) {
- this.focus();
+function addMissingMention() {
+ const ast = mfm.parse(text);
- this.$nextTick(() => {
- this.focus();
+ for (const x of extractMentions(ast)) {
+ if (!visibleUsers.some(u => (u.username === x.username) && (u.host == x.host))) {
+ os.api('users/show', { username: x.username, host: x.host }).then(user => {
+ visibleUsers.push(user);
});
}
+ }
+}
- // TODO: detach when unmount
- new Autocomplete(this.$refs.text, this, { model: 'text' });
- new Autocomplete(this.$refs.cw, this, { model: 'cw' });
- new Autocomplete(this.$refs.hashtags, this, { model: 'hashtags' });
+function togglePoll() {
+ if (poll) {
+ poll = null;
+ } else {
+ poll = {
+ choices: ['', ''],
+ multiple: false,
+ expiresAt: null,
+ expiredAfter: null,
+ };
+ }
+}
- this.$nextTick(() => {
- // 書きかけの投稿を復元
- if (!this.share && !this.mention && !this.specified) {
- const draft = JSON.parse(localStorage.getItem('drafts') || '{}')[this.draftKey];
- if (draft) {
- this.text = draft.data.text;
- this.useCw = draft.data.useCw;
- this.cw = draft.data.cw;
- this.visibility = draft.data.visibility;
- this.localOnly = draft.data.localOnly;
- this.files = (draft.data.files || []).filter(e => e);
- if (draft.data.poll) {
- this.poll = draft.data.poll;
- }
- }
- }
+function addTag(tag: string) {
+ insertTextAtCursor(textareaEl, ` #${tag} `);
+}
- // 削除して編集
- if (this.initialNote) {
- const init = this.initialNote;
- this.text = init.text ? init.text : '';
- this.files = init.files;
- this.cw = init.cw;
- this.useCw = init.cw != null;
- if (init.poll) {
- this.poll = {
- choices: init.poll.choices.map(x => x.text),
- multiple: init.poll.multiple,
- expiresAt: init.poll.expiresAt,
- expiredAfter: init.poll.expiredAfter,
- };
- }
- this.visibility = init.visibility;
- this.localOnly = init.localOnly;
- this.quoteId = init.renote ? init.renote.id : null;
- }
+function focus() {
+ textareaEl.focus();
+}
- this.$nextTick(() => this.watch());
- });
- },
+function chooseFileFrom(ev) {
+ selectFiles(ev.currentTarget || ev.target, i18n.locale.attachFile).then(files_ => {
+ for (const file of files_) {
+ files.push(file);
+ }
+ });
+}
- methods: {
- watch() {
- this.$watch('text', () => this.saveDraft());
- this.$watch('useCw', () => this.saveDraft());
- this.$watch('cw', () => this.saveDraft());
- this.$watch('poll', () => this.saveDraft());
- this.$watch('files', () => this.saveDraft(), { deep: true });
- this.$watch('visibility', () => this.saveDraft());
- this.$watch('localOnly', () => this.saveDraft());
- },
+function detachFile(id) {
+ files = files.filter(x => x.id != id);
+}
- checkMissingMention() {
- if (this.visibility === 'specified') {
- const ast = mfm.parse(this.text);
+function updateFiles(_files) {
+ files = _files;
+}
- for (const x of extractMentions(ast)) {
- if (!this.visibleUsers.some(u => (u.username === x.username) && (u.host == x.host))) {
- this.hasNotSpecifiedMentions = true;
- return;
- }
- }
- this.hasNotSpecifiedMentions = false;
- }
- },
+function updateFileSensitive(file, sensitive) {
+ files[files.findIndex(x => x.id === file.id)].isSensitive = sensitive;
+}
- addMissingMention() {
- const ast = mfm.parse(this.text);
+function updateFileName(file, name) {
+ files[files.findIndex(x => x.id === file.id)].name = name;
+}
- for (const x of extractMentions(ast)) {
- if (!this.visibleUsers.some(u => (u.username === x.username) && (u.host == x.host))) {
- os.api('users/show', { username: x.username, host: x.host }).then(user => {
- this.visibleUsers.push(user);
- });
- }
- }
- },
+function upload(file: File, name?: string) {
+ os.upload(file, defaultStore.state.uploadFolder, name).then(res => {
+ files.push(res);
+ });
+}
- togglePoll() {
- if (this.poll) {
- this.poll = null;
- } else {
- this.poll = {
- choices: ['', ''],
- multiple: false,
- expiresAt: null,
- expiredAfter: null,
- };
+function setVisibility() {
+ if (props.channel) {
+ // TODO: information dialog
+ return;
+ }
+
+ os.popup(import('./visibility-picker.vue'), {
+ currentVisibility: visibility,
+ currentLocalOnly: localOnly,
+ src: visibilityButton,
+ }, {
+ changeVisibility: v => {
+ visibility = v;
+ if (defaultStore.state.rememberNoteVisibility) {
+ defaultStore.set('visibility', visibility);
}
},
+ changeLocalOnly: v => {
+ localOnly = v;
+ if (defaultStore.state.rememberNoteVisibility) {
+ defaultStore.set('localOnly', localOnly);
+ }
+ }
+ }, 'closed');
+}
- addTag(tag: string) {
- insertTextAtCursor(this.$refs.text, ` #${tag} `);
- },
+function addVisibleUser() {
+ os.selectUser().then(user => {
+ visibleUsers.push(user);
+ });
+}
- focus() {
- (this.$refs.text as any).focus();
- },
+function removeVisibleUser(user) {
+ visibleUsers = erase(user, visibleUsers);
+}
- chooseFileFrom(ev) {
- selectFiles(ev.currentTarget || ev.target, this.$ts.attachFile).then(files => {
- for (const file of files) {
- this.files.push(file);
- }
- });
- },
+function clear() {
+ text = '';
+ files = [];
+ poll = null;
+ quoteId = null;
+}
- detachFile(id) {
- this.files = this.files.filter(x => x.id != id);
- },
+function onKeydown(e: KeyboardEvent) {
+ if ((e.which === 10 || e.which === 13) && (e.ctrlKey || e.metaKey) && canPost) post();
+ if (e.which === 27) emit('esc');
+ typing();
+}
- updateFiles(files) {
- this.files = files;
- },
+function onCompositionUpdate(e: CompositionEvent) {
+ imeText = e.data;
+ typing();
+}
- updateFileSensitive(file, sensitive) {
- this.files[this.files.findIndex(x => x.id === file.id)].isSensitive = sensitive;
- },
+function onCompositionEnd(e: CompositionEvent) {
+ imeText = '';
+}
- updateFileName(file, name) {
- this.files[this.files.findIndex(x => x.id === file.id)].name = name;
- },
+async function onPaste(e: ClipboardEvent) {
+ for (const { item, i } of Array.from(e.clipboardData.items).map((item, i) => ({item, i}))) {
+ if (item.kind == 'file') {
+ const file = item.getAsFile();
+ const lio = file.name.lastIndexOf('.');
+ const ext = lio >= 0 ? file.name.slice(lio) : '';
+ const formatted = `${formatTimeString(new Date(file.lastModified), defaultStore.state.pastedFileName).replace(/{{number}}/g, `${i + 1}`)}${ext}`;
+ upload(file, formatted);
+ }
+ }
- upload(file: File, name?: string) {
- os.upload(file, this.$store.state.uploadFolder, name).then(res => {
- this.files.push(res);
- });
- },
+ const paste = e.clipboardData.getData('text');
- onPollUpdate(poll) {
- this.poll = poll;
- this.saveDraft();
- },
+ if (!props.renote && !quoteId && paste.startsWith(url + '/notes/')) {
+ e.preventDefault();
- setVisibility() {
- if (this.channel) {
- // TODO: information dialog
+ os.confirm({
+ type: 'info',
+ text: i18n.locale.quoteQuestion,
+ }).then(({ canceled }) => {
+ if (canceled) {
+ insertTextAtCursor(textareaEl, paste);
return;
}
- os.popup(import('./visibility-picker.vue'), {
- currentVisibility: this.visibility,
- currentLocalOnly: this.localOnly,
- src: this.$refs.visibilityButton
- }, {
- changeVisibility: visibility => {
- this.visibility = visibility;
- if (this.$store.state.rememberNoteVisibility) {
- this.$store.set('visibility', visibility);
- }
- },
- changeLocalOnly: localOnly => {
- this.localOnly = localOnly;
- if (this.$store.state.rememberNoteVisibility) {
- this.$store.set('localOnly', localOnly);
- }
- }
- }, 'closed');
- },
-
- addVisibleUser() {
- os.selectUser().then(user => {
- this.visibleUsers.push(user);
- });
- },
-
- removeVisibleUser(user) {
- this.visibleUsers = erase(user, this.visibleUsers);
- },
+ quoteId = paste.substr(url.length).match(/^\/notes\/(.+?)\/?$/)[1];
+ });
+ }
+}
- clear() {
- this.text = '';
- this.files = [];
- this.poll = null;
- this.quoteId = null;
- },
+function onDragover(e) {
+ if (!e.dataTransfer.items[0]) return;
+ const isFile = e.dataTransfer.items[0].kind == 'file';
+ const isDriveFile = e.dataTransfer.types[0] == _DATA_TRANSFER_DRIVE_FILE_;
+ if (isFile || isDriveFile) {
+ e.preventDefault();
+ draghover = true;
+ e.dataTransfer.dropEffect = e.dataTransfer.effectAllowed == 'all' ? 'copy' : 'move';
+ }
+}
- onKeydown(e: KeyboardEvent) {
- if ((e.which === 10 || e.which === 13) && (e.ctrlKey || e.metaKey) && this.canPost) this.post();
- if (e.which === 27) this.$emit('esc');
- this.typing();
- },
+function onDragenter(e) {
+ draghover = true;
+}
- onCompositionUpdate(e: CompositionEvent) {
- this.imeText = e.data;
- this.typing();
- },
+function onDragleave(e) {
+ draghover = false;
+}
- onCompositionEnd(e: CompositionEvent) {
- this.imeText = '';
- },
+function onDrop(e): void {
+ draghover = false;
- async onPaste(e: ClipboardEvent) {
- for (const { item, i } of Array.from(e.clipboardData.items).map((item, i) => ({item, i}))) {
- if (item.kind == 'file') {
- const file = item.getAsFile();
- const lio = file.name.lastIndexOf('.');
- const ext = lio >= 0 ? file.name.slice(lio) : '';
- const formatted = `${formatTimeString(new Date(file.lastModified), this.$store.state.pastedFileName).replace(/{{number}}/g, `${i + 1}`)}${ext}`;
- this.upload(file, formatted);
- }
- }
+ // ファイルだったら
+ if (e.dataTransfer.files.length > 0) {
+ e.preventDefault();
+ for (const x of Array.from(e.dataTransfer.files)) upload(x);
+ return;
+ }
- const paste = e.clipboardData.getData('text');
+ //#region ドライブのファイル
+ const driveFile = e.dataTransfer.getData(_DATA_TRANSFER_DRIVE_FILE_);
+ if (driveFile != null && driveFile != '') {
+ const file = JSON.parse(driveFile);
+ files.push(file);
+ e.preventDefault();
+ }
+ //#endregion
+}
- if (!this.renote && !this.quoteId && paste.startsWith(url + '/notes/')) {
- e.preventDefault();
+function saveDraft() {
+ const data = JSON.parse(localStorage.getItem('drafts') || '{}');
- os.confirm({
- type: 'info',
- text: this.$ts.quoteQuestion,
- }).then(({ canceled }) => {
- if (canceled) {
- insertTextAtCursor(this.$refs.text, paste);
- return;
- }
+ data[draftKey] = {
+ updatedAt: new Date(),
+ data: {
+ text: text,
+ useCw: useCw,
+ cw: cw,
+ visibility: visibility,
+ localOnly: localOnly,
+ files: files,
+ poll: poll
+ }
+ };
- this.quoteId = paste.substr(url.length).match(/^\/notes\/(.+?)\/?$/)[1];
- });
- }
- },
+ localStorage.setItem('drafts', JSON.stringify(data));
+}
- onDragover(e) {
- if (!e.dataTransfer.items[0]) return;
- const isFile = e.dataTransfer.items[0].kind == 'file';
- const isDriveFile = e.dataTransfer.types[0] == _DATA_TRANSFER_DRIVE_FILE_;
- if (isFile || isDriveFile) {
- e.preventDefault();
- this.draghover = true;
- e.dataTransfer.dropEffect = e.dataTransfer.effectAllowed == 'all' ? 'copy' : 'move';
- }
- },
+function deleteDraft() {
+ const data = JSON.parse(localStorage.getItem('drafts') || '{}');
- onDragenter(e) {
- this.draghover = true;
- },
+ delete data[draftKey];
- onDragleave(e) {
- this.draghover = false;
- },
+ localStorage.setItem('drafts', JSON.stringify(data));
+}
- onDrop(e): void {
- this.draghover = false;
+async function post() {
+ let data = {
+ text: text == '' ? undefined : text,
+ fileIds: files.length > 0 ? files.map(f => f.id) : undefined,
+ replyId: props.reply ? props.reply.id : undefined,
+ renoteId: props.renote ? props.renote.id : quoteId ? quoteId : undefined,
+ channelId: props.channel ? props.channel.id : undefined,
+ poll: poll,
+ cw: useCw ? cw || '' : undefined,
+ localOnly: localOnly,
+ visibility: visibility,
+ visibleUserIds: visibility == 'specified' ? visibleUsers.map(u => u.id) : undefined,
+ };
- // ファイルだったら
- if (e.dataTransfer.files.length > 0) {
- e.preventDefault();
- for (const x of Array.from(e.dataTransfer.files)) this.upload(x);
- return;
- }
+ if (withHashtags && hashtags && hashtags.trim() !== '') {
+ const hashtags = hashtags.trim().split(' ').map(x => x.startsWith('#') ? x : '#' + x).join(' ');
+ data.text = data.text ? `${data.text} ${hashtags}` : hashtags;
+ }
- //#region ドライブのファイル
- const driveFile = e.dataTransfer.getData(_DATA_TRANSFER_DRIVE_FILE_);
- if (driveFile != null && driveFile != '') {
- const file = JSON.parse(driveFile);
- this.files.push(file);
- e.preventDefault();
- }
- //#endregion
- },
+ // plugin
+ if (notePostInterruptors.length > 0) {
+ for (const interruptor of notePostInterruptors) {
+ data = await interruptor.handler(JSON.parse(JSON.stringify(data)));
+ }
+ }
- saveDraft() {
- const data = JSON.parse(localStorage.getItem('drafts') || '{}');
+ let token = undefined;
- data[this.draftKey] = {
- updatedAt: new Date(),
- data: {
- text: this.text,
- useCw: this.useCw,
- cw: this.cw,
- visibility: this.visibility,
- localOnly: this.localOnly,
- files: this.files,
- poll: this.poll
- }
- };
+ if (postAccount) {
+ const storedAccounts = await getAccounts();
+ token = storedAccounts.find(x => x.id === postAccount.id)?.token;
+ }
- localStorage.setItem('drafts', JSON.stringify(data));
- },
+ posting = true;
+ os.api('notes/create', data, token).then(() => {
+ clear();
+ nextTick(() => {
+ deleteDraft();
+ emit('posted');
+ if (data.text && data.text != '') {
+ const hashtags = mfm.parse(data.text).filter(x => x.type === 'hashtag').map(x => x.props.hashtag);
+ const history = JSON.parse(localStorage.getItem('hashtags') || '[]') as string[];
+ localStorage.setItem('hashtags', JSON.stringify(unique(hashtags.concat(history))));
+ }
+ posting = false;
+ postAccount = null;
+ });
+ }).catch(err => {
+ posting = false;
+ os.alert({
+ type: 'error',
+ text: err.message + '\n' + (err as any).id,
+ });
+ });
+}
- deleteDraft() {
- const data = JSON.parse(localStorage.getItem('drafts') || '{}');
+function cancel() {
+ emit('cancel');
+}
- delete data[this.draftKey];
+function insertMention() {
+ os.selectUser().then(user => {
+ insertTextAtCursor(textareaEl, '@' + Acct.toString(user) + ' ');
+ });
+}
- localStorage.setItem('drafts', JSON.stringify(data));
- },
+async function insertEmoji(ev: MouseEvent) {
+ os.openEmojiPicker(ev.currentTarget || ev.target, {}, textareaEl);
+}
- async post() {
- let data = {
- text: this.text == '' ? undefined : this.text,
- fileIds: this.files.length > 0 ? this.files.map(f => f.id) : undefined,
- replyId: this.reply ? this.reply.id : undefined,
- renoteId: this.renote ? this.renote.id : this.quoteId ? this.quoteId : undefined,
- channelId: this.channel ? this.channel.id : undefined,
- poll: this.poll,
- cw: this.useCw ? this.cw || '' : undefined,
- localOnly: this.localOnly,
- visibility: this.visibility,
- visibleUserIds: this.visibility == 'specified' ? this.visibleUsers.map(u => u.id) : undefined,
- };
+function showActions(ev) {
+ os.popupMenu(postFormActions.map(action => ({
+ text: action.title,
+ action: () => {
+ action.handler({
+ text: text
+ }, (key, value) => {
+ if (key === 'text') { text = value; }
+ });
+ }
+ })), ev.currentTarget || ev.target);
+}
- if (this.withHashtags && this.hashtags && this.hashtags.trim() !== '') {
- const hashtags = this.hashtags.trim().split(' ').map(x => x.startsWith('#') ? x : '#' + x).join(' ');
- data.text = data.text ? `${data.text} ${hashtags}` : hashtags;
- }
+let postAccount = $ref<misskey.entities.UserDetailed | null>(null);
- // plugin
- if (notePostInterruptors.length > 0) {
- for (const interruptor of notePostInterruptors) {
- data = await interruptor.handler(JSON.parse(JSON.stringify(data)));
- }
+function openAccountMenu(ev: MouseEvent) {
+ openAccountMenu_({
+ withExtraOperation: false,
+ includeCurrentAccount: true,
+ active: postAccount != null ? postAccount.id : $i.id,
+ onChoose: (account) => {
+ if (account.id === $i.id) {
+ postAccount = null;
+ } else {
+ postAccount = account;
}
-
- this.posting = true;
- os.api('notes/create', data).then(() => {
- this.clear();
- this.$nextTick(() => {
- this.deleteDraft();
- this.$emit('posted');
- if (data.text && data.text != '') {
- const hashtags = mfm.parse(data.text).filter(x => x.type === 'hashtag').map(x => x.props.hashtag);
- const history = JSON.parse(localStorage.getItem('hashtags') || '[]') as string[];
- localStorage.setItem('hashtags', JSON.stringify(unique(hashtags.concat(history))));
- }
- this.posting = false;
- });
- }).catch(err => {
- this.posting = false;
- os.alert({
- type: 'error',
- text: err.message + '\n' + (err as any).id,
- });
- });
},
+ }, ev);
+}
- cancel() {
- this.$emit('cancel');
- },
+onMounted(() => {
+ if (props.autofocus) {
+ focus();
- insertMention() {
- os.selectUser().then(user => {
- insertTextAtCursor(this.$refs.text, '@' + Acct.toString(user) + ' ');
- });
- },
+ nextTick(() => {
+ focus();
+ });
+ }
- async insertEmoji(ev) {
- os.openEmojiPicker(ev.currentTarget || ev.target, {}, this.$refs.text);
- },
+ // TODO: detach when unmount
+ new Autocomplete(textareaEl, $$(text));
+ new Autocomplete(cwInputEl, $$(cw));
+ new Autocomplete(hashtagsInputEl, $$(hashtags));
- showActions(ev) {
- os.popupMenu(postFormActions.map(action => ({
- text: action.title,
- action: () => {
- action.handler({
- text: this.text
- }, (key, value) => {
- if (key === 'text') { this.text = value; }
- });
+ nextTick(() => {
+ // 書きかけの投稿を復元
+ if (!props.share && !props.mention && !props.specified) {
+ const draft = JSON.parse(localStorage.getItem('drafts') || '{}')[draftKey];
+ if (draft) {
+ text = draft.data.text;
+ useCw = draft.data.useCw;
+ cw = draft.data.cw;
+ visibility = draft.data.visibility;
+ localOnly = draft.data.localOnly;
+ files = (draft.data.files || []).filter(e => e);
+ if (draft.data.poll) {
+ poll = draft.data.poll;
}
- })), ev.currentTarget || ev.target);
+ }
}
- }
+
+ // 削除して編集
+ if (props.initialNote) {
+ const init = props.initialNote;
+ text = init.text ? init.text : '';
+ files = init.files;
+ cw = init.cw;
+ useCw = init.cw != null;
+ if (init.poll) {
+ poll = {
+ choices: init.poll.choices.map(x => x.text),
+ multiple: init.poll.multiple,
+ expiresAt: init.poll.expiresAt,
+ expiredAfter: init.poll.expiredAfter,
+ };
+ }
+ visibility = init.visibility;
+ localOnly = init.localOnly;
+ quoteId = init.renote ? init.renote.id : null;
+ }
+
+ nextTick(() => watchForDraft());
+ });
});
</script>
@@ -742,6 +701,19 @@ export default defineComponent({
line-height: 66px;
}
+ > .account {
+ height: 100%;
+ aspect-ratio: 1/1;
+ display: inline-flex;
+ vertical-align: bottom;
+
+ > .avatar {
+ width: 28px;
+ height: 28px;
+ margin: auto;
+ }
+ }
+
> div {
position: absolute;
top: 0;
diff --git a/packages/client/src/components/reaction-icon.vue b/packages/client/src/components/reaction-icon.vue
index c0ec955e32..5638c9a816 100644
--- a/packages/client/src/components/reaction-icon.vue
+++ b/packages/client/src/components/reaction-icon.vue
@@ -1,25 +1,13 @@
<template>
-<MkEmoji :emoji="reaction" :custom-emojis="customEmojis" :is-reaction="true" :normal="true" :no-style="noStyle"/>
+<MkEmoji :emoji="reaction" :custom-emojis="customEmojis || []" :is-reaction="true" :normal="true" :no-style="noStyle"/>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
+<script lang="ts" setup>
+import { } from 'vue';
-export default defineComponent({
- props: {
- reaction: {
- type: String,
- required: true
- },
- customEmojis: {
- required: false,
- default: () => []
- },
- noStyle: {
- type: Boolean,
- required: false,
- default: false
- },
- },
-});
+const props = defineProps<{
+ reaction: string;
+ customEmojis?: any[]; // TODO
+ noStyle?: boolean;
+}>();
</script>
diff --git a/packages/client/src/components/reaction-tooltip.vue b/packages/client/src/components/reaction-tooltip.vue
index dda8e7c6d7..1b2a024e21 100644
--- a/packages/client/src/components/reaction-tooltip.vue
+++ b/packages/client/src/components/reaction-tooltip.vue
@@ -1,5 +1,5 @@
<template>
-<MkTooltip ref="tooltip" :source="source" :max-width="340" @closed="$emit('closed')">
+<MkTooltip ref="tooltip" :source="source" :max-width="340" @closed="emit('closed')">
<div class="beeadbfb">
<XReactionIcon :reaction="reaction" :custom-emojis="emojis" class="icon" :no-style="true"/>
<div class="name">{{ reaction.replace('@.', '') }}</div>
@@ -7,31 +7,20 @@
</MkTooltip>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
+<script lang="ts" setup>
+import { } from 'vue';
import MkTooltip from './ui/tooltip.vue';
import XReactionIcon from './reaction-icon.vue';
-export default defineComponent({
- components: {
- MkTooltip,
- XReactionIcon,
- },
- props: {
- reaction: {
- type: String,
- required: true,
- },
- emojis: {
- type: Array,
- required: true,
- },
- source: {
- required: true,
- }
- },
- emits: ['closed'],
-})
+const props = defineProps<{
+ reaction: string;
+ emojis: any[]; // TODO
+ source: any; // TODO
+}>();
+
+const emit = defineEmits<{
+ (e: 'closed'): void;
+}>();
</script>
<style lang="scss" scoped>
diff --git a/packages/client/src/components/reactions-viewer.details.vue b/packages/client/src/components/reactions-viewer.details.vue
index d6374517a2..8cec8dfa2f 100644
--- a/packages/client/src/components/reactions-viewer.details.vue
+++ b/packages/client/src/components/reactions-viewer.details.vue
@@ -1,5 +1,5 @@
<template>
-<MkTooltip ref="tooltip" :source="source" :max-width="340" @closed="$emit('closed')">
+<MkTooltip ref="tooltip" :source="source" :max-width="340" @closed="emit('closed')">
<div class="bqxuuuey">
<div class="reaction">
<XReactionIcon :reaction="reaction" :custom-emojis="emojis" class="icon" :no-style="true"/>
@@ -16,39 +16,22 @@
</MkTooltip>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
+<script lang="ts" setup>
+import { } from 'vue';
import MkTooltip from './ui/tooltip.vue';
import XReactionIcon from './reaction-icon.vue';
-export default defineComponent({
- components: {
- MkTooltip,
- XReactionIcon
- },
- props: {
- reaction: {
- type: String,
- required: true,
- },
- users: {
- type: Array,
- required: true,
- },
- count: {
- type: Number,
- required: true,
- },
- emojis: {
- type: Array,
- required: true,
- },
- source: {
- required: true,
- }
- },
- emits: ['closed'],
-})
+const props = defineProps<{
+ reaction: string;
+ users: any[]; // TODO
+ count: number;
+ emojis: any[]; // TODO
+ source: any; // TODO
+}>();
+
+const emit = defineEmits<{
+ (e: 'closed'): void;
+}>();
</script>
<style lang="scss" scoped>
diff --git a/packages/client/src/components/reactions-viewer.vue b/packages/client/src/components/reactions-viewer.vue
index 59fcbb7129..a9bf51f65f 100644
--- a/packages/client/src/components/reactions-viewer.vue
+++ b/packages/client/src/components/reactions-viewer.vue
@@ -4,31 +4,19 @@
</div>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
+<script lang="ts" setup>
+import { computed } from 'vue';
+import * as misskey from 'misskey-js';
+import { $i } from '@/account';
import XReaction from './reactions-viewer.reaction.vue';
-export default defineComponent({
- components: {
- XReaction
- },
- props: {
- note: {
- type: Object,
- required: true
- },
- },
- data() {
- return {
- initialReactions: new Set(Object.keys(this.note.reactions))
- };
- },
- computed: {
- isMe(): boolean {
- return this.$i && this.$i.id === this.note.userId;
- },
- },
-});
+const props = defineProps<{
+ note: misskey.entities.Note;
+}>();
+
+const initialReactions = new Set(Object.keys(props.note.reactions));
+
+const isMe = computed(() => $i && $i.id === props.note.userId);
</script>
<style lang="scss" scoped>
diff --git a/packages/client/src/components/remote-caution.vue b/packages/client/src/components/remote-caution.vue
index c496ea8f48..aa623f0fb0 100644
--- a/packages/client/src/components/remote-caution.vue
+++ b/packages/client/src/components/remote-caution.vue
@@ -2,22 +2,10 @@
<div class="jmgmzlwq _block"><i class="fas fa-exclamation-triangle" style="margin-right: 8px;"></i>{{ $ts.remoteUserCaution }}<a :href="href" rel="nofollow noopener" target="_blank">{{ $ts.showOnRemote }}</a></div>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
-import * as os from '@/os';
-
-export default defineComponent({
- props: {
- href: {
- type: String,
- required: true
- },
- },
- data() {
- return {
- };
- }
-});
+<script lang="ts" setup>
+defineProps<{
+ href: string;
+}>();
</script>
<style lang="scss" scoped>
diff --git a/packages/client/src/components/renote.details.vue b/packages/client/src/components/renote.details.vue
index e3ef15c753..cdbc71bdce 100644
--- a/packages/client/src/components/renote.details.vue
+++ b/packages/client/src/components/renote.details.vue
@@ -1,5 +1,5 @@
<template>
-<MkTooltip ref="tooltip" :source="source" :max-width="250" @closed="$emit('closed')">
+<MkTooltip ref="tooltip" :source="source" :max-width="250" @closed="emit('closed')">
<div class="beaffaef">
<div v-for="u in users" :key="u.id" class="user">
<MkAvatar class="avatar" :user="u"/>
@@ -10,29 +10,19 @@
</MkTooltip>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
+<script lang="ts" setup>
+import { } from 'vue';
import MkTooltip from './ui/tooltip.vue';
-export default defineComponent({
- components: {
- MkTooltip,
- },
- props: {
- users: {
- type: Array,
- required: true,
- },
- count: {
- type: Number,
- required: true,
- },
- source: {
- required: true,
- }
- },
- emits: ['closed'],
-})
+const props = defineProps<{
+ users: any[]; // TODO
+ count: number;
+ source: any; // TODO
+}>();
+
+const emit = defineEmits<{
+ (e: 'closed'): void;
+}>();
</script>
<style lang="scss" scoped>
diff --git a/packages/client/src/components/ripple.vue b/packages/client/src/components/ripple.vue
index 272eacbc6e..401e78e304 100644
--- a/packages/client/src/components/ripple.vue
+++ b/packages/client/src/components/ripple.vue
@@ -94,7 +94,7 @@ export default defineComponent({
}
onMounted(() => {
- setTimeout(() => {
+ window.setTimeout(() => {
context.emit('end');
}, 1100);
});
diff --git a/packages/client/src/components/signin-dialog.vue b/packages/client/src/components/signin-dialog.vue
index 2edd10f539..5c2048e7b0 100644
--- a/packages/client/src/components/signin-dialog.vue
+++ b/packages/client/src/components/signin-dialog.vue
@@ -2,8 +2,8 @@
<XModalWindow ref="dialog"
:width="370"
:height="400"
- @close="$refs.dialog.close()"
- @closed="$emit('closed')"
+ @close="dialog.close()"
+ @closed="emit('closed')"
>
<template #header>{{ $ts.login }}</template>
@@ -11,32 +11,26 @@
</XModalWindow>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
+<script lang="ts" setup>
+import { } from 'vue';
import XModalWindow from '@/components/ui/modal-window.vue';
import MkSignin from './signin.vue';
-export default defineComponent({
- components: {
- MkSignin,
- XModalWindow,
- },
+const props = withDefaults(defineProps<{
+ autoSet?: boolean;
+}>(), {
+ autoSet: false,
+});
- props: {
- autoSet: {
- type: Boolean,
- required: false,
- default: false,
- }
- },
+const emit = defineEmits<{
+ (e: 'done'): void;
+ (e: 'closed'): void;
+}>();
- emits: ['done', 'closed'],
+const dialog = $ref<InstanceType<typeof XModalWindow>>();
- methods: {
- onLogin(res) {
- this.$emit('done', res);
- this.$refs.dialog.close();
- }
- }
-});
+function onLogin(res) {
+ emit('done', res);
+ dialog.close();
+}
</script>
diff --git a/packages/client/src/components/signup-dialog.vue b/packages/client/src/components/signup-dialog.vue
index 30fe3bf7d3..bda2495ba7 100644
--- a/packages/client/src/components/signup-dialog.vue
+++ b/packages/client/src/components/signup-dialog.vue
@@ -2,7 +2,7 @@
<XModalWindow ref="dialog"
:width="366"
:height="500"
- @close="$refs.dialog.close()"
+ @close="dialog.close()"
@closed="$emit('closed')"
>
<template #header>{{ $ts.signup }}</template>
@@ -15,36 +15,30 @@
</XModalWindow>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
+<script lang="ts" setup>
+import { } from 'vue';
import XModalWindow from '@/components/ui/modal-window.vue';
import XSignup from './signup.vue';
-export default defineComponent({
- components: {
- XSignup,
- XModalWindow,
- },
+const props = withDefaults(defineProps<{
+ autoSet?: boolean;
+}>(), {
+ autoSet: false,
+});
- props: {
- autoSet: {
- type: Boolean,
- required: false,
- default: false,
- }
- },
+const emit = defineEmits<{
+ (e: 'done'): void;
+ (e: 'closed'): void;
+}>();
- emits: ['done', 'closed'],
+const dialog = $ref<InstanceType<typeof XModalWindow>>();
- methods: {
- onSignup(res) {
- this.$emit('done', res);
- this.$refs.dialog.close();
- },
+function onSignup(res) {
+ emit('done', res);
+ dialog.close();
+}
- onSignupEmailPending() {
- this.$refs.dialog.close();
- }
- }
-});
+function onSignupEmailPending() {
+ dialog.close();
+}
</script>
diff --git a/packages/client/src/components/sub-note-content.vue b/packages/client/src/components/sub-note-content.vue
index efa202ce2f..d6a37d07be 100644
--- a/packages/client/src/components/sub-note-content.vue
+++ b/packages/client/src/components/sub-note-content.vue
@@ -21,35 +21,21 @@
</div>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
+<script lang="ts" setup>
+import { } from 'vue';
import XPoll from './poll.vue';
import XMediaList from './media-list.vue';
-import * as os from '@/os';
+import * as misskey from 'misskey-js';
-export default defineComponent({
- components: {
- XPoll,
- XMediaList,
- },
- props: {
- note: {
- type: Object,
- required: true
- }
- },
- data() {
- return {
- collapsed: false,
- };
- },
- created() {
- this.collapsed = this.note.cw == null && this.note.text && (
- (this.note.text.split('\n').length > 9) ||
- (this.note.text.length > 500)
- );
- }
-});
+const props = defineProps<{
+ note: misskey.entities.Note;
+}>();
+
+const collapsed = $ref(
+ props.note.cw == null && props.note.text != null && (
+ (props.note.text.split('\n').length > 9) ||
+ (props.note.text.length > 500)
+ ));
</script>
<style lang="scss" scoped>
diff --git a/packages/client/src/components/taskmanager.api-window.vue b/packages/client/src/components/taskmanager.api-window.vue
deleted file mode 100644
index 6ec4da3a59..0000000000
--- a/packages/client/src/components/taskmanager.api-window.vue
+++ /dev/null
@@ -1,72 +0,0 @@
-<template>
-<XWindow ref="window"
- :initial-width="370"
- :initial-height="450"
- :can-resize="true"
- @close="$refs.window.close()"
- @closed="$emit('closed')"
->
- <template #header>Req Viewer</template>
-
- <div class="rlkneywz">
- <MkTab v-model="tab" style="border-bottom: solid 0.5px var(--divider);">
- <option value="req">Request</option>
- <option value="res">Response</option>
- </MkTab>
-
- <code v-if="tab === 'req'" class="_monospace">{{ reqStr }}</code>
- <code v-if="tab === 'res'" class="_monospace">{{ resStr }}</code>
- </div>
-</XWindow>
-</template>
-
-<script lang="ts">
-import { defineComponent } from 'vue';
-import * as JSON5 from 'json5';
-import XWindow from '@/components/ui/window.vue';
-import MkTab from '@/components/tab.vue';
-
-export default defineComponent({
- components: {
- XWindow,
- MkTab,
- },
-
- props: {
- req: {
- required: true,
- }
- },
-
- emits: ['closed'],
-
- data() {
- return {
- tab: 'req',
- reqStr: JSON5.stringify(this.req.req, null, '\t'),
- resStr: JSON5.stringify(this.req.res, null, '\t'),
- }
- },
-
- methods: {
- }
-});
-</script>
-
-<style lang="scss" scoped>
-.rlkneywz {
- display: flex;
- flex-direction: column;
- height: 100%;
-
- > code {
- display: block;
- flex: 1;
- padding: 8px;
- overflow: auto;
- font-size: 0.9em;
- tab-size: 2;
- white-space: pre;
- }
-}
-</style>
diff --git a/packages/client/src/components/taskmanager.vue b/packages/client/src/components/taskmanager.vue
deleted file mode 100644
index 6901d88c2c..0000000000
--- a/packages/client/src/components/taskmanager.vue
+++ /dev/null
@@ -1,233 +0,0 @@
-<template>
-<XWindow ref="window" :initial-width="650" :initial-height="420" :can-resize="true" @closed="$emit('closed')">
- <template #header>
- <i class="fas fa-terminal" style="margin-right: 0.5em;"></i>Task Manager
- </template>
- <div class="qljqmnzj _monospace">
- <MkTab v-model="tab" style="border-bottom: solid 0.5px var(--divider);">
- <option value="windows">Windows</option>
- <option value="stream">Stream</option>
- <option value="streamPool">Stream (Pool)</option>
- <option value="api">API</option>
- </MkTab>
-
- <div class="content">
- <div v-if="tab === 'windows'" v-follow class="windows">
- <div class="header">
- <div>#ID</div>
- <div>Component</div>
- <div>Action</div>
- </div>
- <div v-for="p in popups">
- <div>#{{ p.id }}</div>
- <div>{{ p.component.name ? p.component.name : '<anonymous>' }}</div>
- <div><button class="_textButton" @click="killPopup(p)">Kill</button></div>
- </div>
- </div>
- <div v-if="tab === 'stream'" v-follow class="stream">
- <div class="header">
- <div>#ID</div>
- <div>Ch</div>
- <div>Handle</div>
- <div>In</div>
- <div>Out</div>
- </div>
- <div v-for="c in connections">
- <div>#{{ c.id }}</div>
- <div>{{ c.channel }}</div>
- <div v-if="c.users !== null">(shared)<span v-if="c.name">{{ ' ' + c.name }}</span></div>
- <div v-else>{{ c.name ? c.name : '<anonymous>' }}</div>
- <div>{{ c.in }}</div>
- <div>{{ c.out }}</div>
- </div>
- </div>
- <div v-if="tab === 'streamPool'" v-follow class="streamPool">
- <div class="header">
- <div>#ID</div>
- <div>Ch</div>
- <div>Users</div>
- </div>
- <div v-for="p in pools">
- <div>#{{ p.id }}</div>
- <div>{{ p.channel }}</div>
- <div>{{ p.users }}</div>
- </div>
- </div>
- <div v-if="tab === 'api'" v-follow class="api">
- <div class="header">
- <div>#ID</div>
- <div>Endpoint</div>
- <div>State</div>
- </div>
- <div v-for="req in apiRequests" @click="showReq(req)">
- <div>#{{ req.id }}</div>
- <div>{{ req.endpoint }}</div>
- <div class="state" :class="req.state">{{ req.state }}</div>
- </div>
- </div>
- </div>
-
- <footer>
- <div><span class="label">Windows</span>{{ popups.length }}</div>
- <div><span class="label">Stream</span>{{ connections.length }}</div>
- <div><span class="label">Stream (Pool)</span>{{ pools.length }}</div>
- </footer>
- </div>
-</XWindow>
-</template>
-
-<script lang="ts">
-import { defineComponent, markRaw, onBeforeUnmount, ref, shallowRef } from 'vue';
-import XWindow from '@/components/ui/window.vue';
-import MkTab from '@/components/tab.vue';
-import MkButton from '@/components/ui/button.vue';
-import follow from '@/directives/follow-append';
-import * as os from '@/os';
-
-export default defineComponent({
- components: {
- XWindow,
- MkTab,
- MkButton,
- },
-
- directives: {
- follow
- },
-
- props: {
- },
-
- emits: ['closed'],
-
- setup() {
- const connections = shallowRef([]);
- const pools = shallowRef([]);
- const refreshStreamInfo = () => {
- console.log(os.stream.sharedConnectionPools, os.stream.sharedConnections, os.stream.nonSharedConnections);
- const conn = os.stream.sharedConnections.map(c => ({
- id: c.id, name: c.name, channel: c.channel, users: c.pool.users, in: c.inCount, out: c.outCount,
- })).concat(os.stream.nonSharedConnections.map(c => ({
- id: c.id, name: c.name, channel: c.channel, users: null, in: c.inCount, out: c.outCount,
- })));
- conn.sort((a, b) => (a.id > b.id) ? 1 : -1);
- connections.value = conn;
- pools.value = os.stream.sharedConnectionPools;
- };
- const interval = setInterval(refreshStreamInfo, 1000);
- onBeforeUnmount(() => {
- clearInterval(interval);
- });
-
- const killPopup = p => {
- os.popups.value = os.popups.value.filter(x => x !== p);
- };
-
- const showReq = req => {
- os.popup(import('./taskmanager.api-window.vue'), {
- req: req
- }, {
- }, 'closed');
- };
-
- return {
- tab: ref('stream'),
- popups: os.popups,
- apiRequests: os.apiRequests,
- connections,
- pools,
- killPopup,
- showReq,
- };
- },
-});
-</script>
-
-<style lang="scss" scoped>
-.qljqmnzj {
- display: flex;
- flex-direction: column;
- height: 100%;
-
- > .content {
- flex: 1;
- overflow: auto;
-
- > div {
- display: table;
- width: 100%;
- padding: 16px;
- box-sizing: border-box;
-
- > div {
- display: table-row;
-
- &:nth-child(even) {
- //background: rgba(0, 0, 0, 0.1);
- }
-
- &.header {
- opacity: 0.7;
- }
-
- > div {
- display: table-cell;
- white-space: nowrap;
-
- &:not(:last-child) {
- padding-right: 8px;
- }
- }
- }
-
- &.api {
- > div {
- &:not(.header) {
- cursor: pointer;
-
- &:hover {
- color: var(--accent);
- }
- }
-
- > .state {
- &.pending {
- color: var(--warn);
- }
-
- &.success {
- color: var(--success);
- }
-
- &.failed {
- color: var(--error);
- }
- }
- }
- }
- }
- }
-
- > footer {
- display: flex;
- width: 100%;
- padding: 8px 16px;
- box-sizing: border-box;
- border-top: solid 0.5px var(--divider);
- font-size: 0.9em;
-
- > div {
- flex: 1;
-
- > .label {
- opacity: 0.7;
- margin-right: 0.5em;
-
- &:after {
- content: ":";
- }
- }
- }
- }
-}
-</style>
diff --git a/packages/client/src/components/timeline.vue b/packages/client/src/components/timeline.vue
index f8a800872f..59956b9526 100644
--- a/packages/client/src/components/timeline.vue
+++ b/packages/client/src/components/timeline.vue
@@ -1,183 +1,143 @@
<template>
-<XNotes ref="tl" :no-gap="!$store.state.showGapBetweenNotesInTimeline" :pagination="pagination" @before="$emit('before')" @after="e => $emit('after', e)" @queue="$emit('queue', $event)"/>
+<XNotes ref="tlComponent" :no-gap="!$store.state.showGapBetweenNotesInTimeline" :pagination="pagination" @queue="emit('queue', $event)"/>
</template>
-<script lang="ts">
-import { defineComponent, markRaw } from 'vue';
+<script lang="ts" setup>
+import { ref, computed, provide, onUnmounted } from 'vue';
import XNotes from './notes.vue';
import * as os from '@/os';
+import { stream } from '@/stream';
import * as sound from '@/scripts/sound';
+import { $i } from '@/account';
-export default defineComponent({
- components: {
- XNotes
- },
+const props = defineProps<{
+ src: string;
+ list?: string;
+ antenna?: string;
+ channel?: string;
+ sound?: boolean;
+}>();
- provide() {
- return {
- inChannel: this.src === 'channel'
- };
- },
+const emit = defineEmits<{
+ (e: 'note'): void;
+ (e: 'queue', count: number): void;
+}>();
- props: {
- src: {
- type: String,
- required: true
- },
- list: {
- type: String,
- required: false
- },
- antenna: {
- type: String,
- required: false
- },
- channel: {
- type: String,
- required: false
- },
- sound: {
- type: Boolean,
- required: false,
- default: false,
- }
- },
-
- emits: ['note', 'queue', 'before', 'after'],
+provide('inChannel', computed(() => props.src === 'channel'));
- data() {
- return {
- connection: null,
- connection2: null,
- pagination: null,
- baseQuery: {
- includeMyRenotes: this.$store.state.showMyRenotes,
- includeRenotedMyNotes: this.$store.state.showRenotedMyNotes,
- includeLocalRenotes: this.$store.state.showLocalRenotes
- },
- query: {},
- date: null
- };
- },
+const tlComponent: InstanceType<typeof XNotes> = $ref();
- created() {
- const prepend = note => {
- (this.$refs.tl as any).prepend(note);
+const prepend = note => {
+ tlComponent.pagingComponent?.prepend(note);
- this.$emit('note');
+ emit('note');
- if (this.sound) {
- sound.play(note.userId === this.$i.id ? 'noteMy' : 'note');
- }
- };
+ if (props.sound) {
+ sound.play($i && (note.userId === $i.id) ? 'noteMy' : 'note');
+ }
+};
- const onUserAdded = () => {
- (this.$refs.tl as any).reload();
- };
+const onUserAdded = () => {
+ tlComponent.pagingComponent?.reload();
+};
- const onUserRemoved = () => {
- (this.$refs.tl as any).reload();
- };
+const onUserRemoved = () => {
+ tlComponent.pagingComponent?.reload();
+};
- const onChangeFollowing = () => {
- if (!this.$refs.tl.backed) {
- this.$refs.tl.reload();
- }
- };
+const onChangeFollowing = () => {
+ if (!tlComponent.pagingComponent?.backed) {
+ tlComponent.pagingComponent?.reload();
+ }
+};
- let endpoint;
+let endpoint;
+let query;
+let connection;
+let connection2;
- if (this.src == 'antenna') {
- endpoint = 'antennas/notes';
- this.query = {
- antennaId: this.antenna
- };
- this.connection = markRaw(os.stream.useChannel('antenna', {
- antennaId: this.antenna
- }));
- this.connection.on('note', prepend);
- } else if (this.src == 'home') {
- endpoint = 'notes/timeline';
- this.connection = markRaw(os.stream.useChannel('homeTimeline'));
- this.connection.on('note', prepend);
+if (props.src === 'antenna') {
+ endpoint = 'antennas/notes';
+ query = {
+ antennaId: props.antenna
+ };
+ connection = stream.useChannel('antenna', {
+ antennaId: props.antenna
+ });
+ connection.on('note', prepend);
+} else if (props.src === 'home') {
+ endpoint = 'notes/timeline';
+ connection = stream.useChannel('homeTimeline');
+ connection.on('note', prepend);
- this.connection2 = markRaw(os.stream.useChannel('main'));
- this.connection2.on('follow', onChangeFollowing);
- this.connection2.on('unfollow', onChangeFollowing);
- } else if (this.src == 'local') {
- endpoint = 'notes/local-timeline';
- this.connection = markRaw(os.stream.useChannel('localTimeline'));
- this.connection.on('note', prepend);
- } else if (this.src == 'social') {
- endpoint = 'notes/hybrid-timeline';
- this.connection = markRaw(os.stream.useChannel('hybridTimeline'));
- this.connection.on('note', prepend);
- } else if (this.src == 'global') {
- endpoint = 'notes/global-timeline';
- this.connection = markRaw(os.stream.useChannel('globalTimeline'));
- this.connection.on('note', prepend);
- } else if (this.src == 'mentions') {
- endpoint = 'notes/mentions';
- this.connection = markRaw(os.stream.useChannel('main'));
- this.connection.on('mention', prepend);
- } else if (this.src == 'directs') {
- endpoint = 'notes/mentions';
- this.query = {
- visibility: 'specified'
- };
- const onNote = note => {
- if (note.visibility == 'specified') {
- prepend(note);
- }
- };
- this.connection = markRaw(os.stream.useChannel('main'));
- this.connection.on('mention', onNote);
- } else if (this.src == 'list') {
- endpoint = 'notes/user-list-timeline';
- this.query = {
- listId: this.list
- };
- this.connection = markRaw(os.stream.useChannel('userList', {
- listId: this.list
- }));
- this.connection.on('note', prepend);
- this.connection.on('userAdded', onUserAdded);
- this.connection.on('userRemoved', onUserRemoved);
- } else if (this.src == 'channel') {
- endpoint = 'channels/timeline';
- this.query = {
- channelId: this.channel
- };
- this.connection = markRaw(os.stream.useChannel('channel', {
- channelId: this.channel
- }));
- this.connection.on('note', prepend);
+ connection2 = stream.useChannel('main');
+ connection2.on('follow', onChangeFollowing);
+ connection2.on('unfollow', onChangeFollowing);
+} else if (props.src === 'local') {
+ endpoint = 'notes/local-timeline';
+ connection = stream.useChannel('localTimeline');
+ connection.on('note', prepend);
+} else if (props.src === 'social') {
+ endpoint = 'notes/hybrid-timeline';
+ connection = stream.useChannel('hybridTimeline');
+ connection.on('note', prepend);
+} else if (props.src === 'global') {
+ endpoint = 'notes/global-timeline';
+ connection = stream.useChannel('globalTimeline');
+ connection.on('note', prepend);
+} else if (props.src === 'mentions') {
+ endpoint = 'notes/mentions';
+ connection = stream.useChannel('main');
+ connection.on('mention', prepend);
+} else if (props.src === 'directs') {
+ endpoint = 'notes/mentions';
+ query = {
+ visibility: 'specified'
+ };
+ const onNote = note => {
+ if (note.visibility == 'specified') {
+ prepend(note);
}
+ };
+ connection = stream.useChannel('main');
+ connection.on('mention', onNote);
+} else if (props.src === 'list') {
+ endpoint = 'notes/user-list-timeline';
+ query = {
+ listId: props.list
+ };
+ connection = stream.useChannel('userList', {
+ listId: props.list
+ });
+ connection.on('note', prepend);
+ connection.on('userAdded', onUserAdded);
+ connection.on('userRemoved', onUserRemoved);
+} else if (props.src === 'channel') {
+ endpoint = 'channels/timeline';
+ query = {
+ channelId: props.channel
+ };
+ connection = stream.useChannel('channel', {
+ channelId: props.channel
+ });
+ connection.on('note', prepend);
+}
- this.pagination = {
- endpoint: endpoint,
- limit: 10,
- params: init => ({
- untilDate: this.date?.getTime(),
- ...this.baseQuery, ...this.query
- })
- };
- },
-
- beforeUnmount() {
- this.connection.dispose();
- if (this.connection2) this.connection2.dispose();
- },
+const pagination = {
+ endpoint: endpoint,
+ limit: 10,
+ params: query,
+};
- methods: {
- focus() {
- this.$refs.tl.focus();
- },
-
- timetravel(date?: Date) {
- this.date = date;
- this.$refs.tl.reload();
- }
- }
+onUnmounted(() => {
+ connection.dispose();
+ if (connection2) connection2.dispose();
});
+
+/* TODO
+const timetravel = (date?: Date) => {
+ this.date = date;
+ this.$refs.tl.reload();
+};
+*/
</script>
diff --git a/packages/client/src/components/toast.vue b/packages/client/src/components/toast.vue
index 914704c527..c114379716 100644
--- a/packages/client/src/components/toast.vue
+++ b/packages/client/src/components/toast.vue
@@ -1,6 +1,6 @@
<template>
<div class="mk-toast">
- <transition name="toast" appear @after-leave="$emit('closed')">
+ <transition :name="$store.state.animation ? 'toast' : ''" appear @after-leave="emit('closed')">
<div v-if="showing" class="body _acrylic" :style="{ zIndex }">
<div class="message">
{{ message }}
@@ -10,29 +10,25 @@
</div>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
+<script lang="ts" setup>
+import { onMounted, ref } from 'vue';
import * as os from '@/os';
-export default defineComponent({
- props: {
- message: {
- type: String,
- required: true,
- },
- },
- emits: ['closed'],
- data() {
- return {
- showing: true,
- zIndex: os.claimZIndex('high'),
- };
- },
- mounted() {
- setTimeout(() => {
- this.showing = false;
- }, 4000);
- }
+defineProps<{
+ message: string;
+}>();
+
+const emit = defineEmits<{
+ (e: 'closed'): void;
+}>();
+
+const showing = ref(true);
+const zIndex = os.claimZIndex('high');
+
+onMounted(() => {
+ window.setTimeout(() => {
+ showing.value = false;
+ }, 4000);
});
</script>
diff --git a/packages/client/src/components/ui/button.vue b/packages/client/src/components/ui/button.vue
index 804a2e2720..c7b6c8ba96 100644
--- a/packages/client/src/components/ui/button.vue
+++ b/packages/client/src/components/ui/button.vue
@@ -117,14 +117,14 @@ export default defineComponent({
const scale = calcCircleScale(e.target.clientWidth, e.target.clientHeight, circleCenterX, circleCenterY);
- setTimeout(() => {
+ window.setTimeout(() => {
ripple.style.transform = 'scale(' + (scale / 2) + ')';
}, 1);
- setTimeout(() => {
+ window.setTimeout(() => {
ripple.style.transition = 'all 1s ease';
ripple.style.opacity = '0';
}, 1000);
- setTimeout(() => {
+ window.setTimeout(() => {
if (this.$refs.ripples) this.$refs.ripples.removeChild(ripple);
}, 2000);
}
diff --git a/packages/client/src/components/ui/container.vue b/packages/client/src/components/ui/container.vue
index fcd9f32290..7c595d8116 100644
--- a/packages/client/src/components/ui/container.vue
+++ b/packages/client/src/components/ui/container.vue
@@ -10,7 +10,7 @@
</button>
</div>
</header>
- <transition name="container-toggle"
+ <transition :name="$store.state.animation ? 'container-toggle' : ''"
@enter="enter"
@after-enter="afterEnter"
@leave="leave"
diff --git a/packages/client/src/components/ui/folder.vue b/packages/client/src/components/ui/folder.vue
index 9795b1d81a..fe1602b2bb 100644
--- a/packages/client/src/components/ui/folder.vue
+++ b/packages/client/src/components/ui/folder.vue
@@ -8,7 +8,7 @@
<template v-else><i class="fas fa-angle-down"></i></template>
</button>
</header>
- <transition name="folder-toggle"
+ <transition :name="$store.state.animation ? 'folder-toggle' : ''"
@enter="enter"
@after-enter="afterEnter"
@leave="leave"
diff --git a/packages/client/src/components/ui/menu.vue b/packages/client/src/components/ui/menu.vue
index 6f3f277b11..41165c8d33 100644
--- a/packages/client/src/components/ui/menu.vue
+++ b/packages/client/src/components/ui/menu.vue
@@ -24,7 +24,7 @@
<span>{{ item.text }}</span>
<span v-if="item.indicate" class="indicator"><i class="fas fa-circle"></i></span>
</a>
- <button v-else-if="item.type === 'user'" :tabindex="i" class="_button item" @click="clicked(item.action, $event)">
+ <button v-else-if="item.type === 'user'" :tabindex="i" class="_button item" :class="{ active: item.active }" :disabled="item.active" @click="clicked(item.action, $event)">
<MkAvatar :user="item.user" class="avatar"/><MkUserName :user="item.user"/>
<span v-if="item.indicate" class="indicator"><i class="fas fa-circle"></i></span>
</button>
diff --git a/packages/client/src/components/ui/modal.vue b/packages/client/src/components/ui/modal.vue
index 3e2e59b27c..c691c8c6d0 100644
--- a/packages/client/src/components/ui/modal.vue
+++ b/packages/client/src/components/ui/modal.vue
@@ -211,7 +211,7 @@ export default defineComponent({
contentClicking = true;
window.addEventListener('mouseup', e => {
// click イベントより先に mouseup イベントが発生するかもしれないのでちょっと待つ
- setTimeout(() => {
+ window.setTimeout(() => {
contentClicking = false;
}, 100);
}, { passive: true, once: true });
diff --git a/packages/client/src/components/ui/pagination.vue b/packages/client/src/components/ui/pagination.vue
index 64af4a54f7..13f3215671 100644
--- a/packages/client/src/components/ui/pagination.vue
+++ b/packages/client/src/components/ui/pagination.vue
@@ -1,5 +1,5 @@
<template>
-<transition name="fade" mode="out-in">
+<transition :name="$store.state.animation ? 'fade' : ''" mode="out-in">
<MkLoading v-if="fetching"/>
<MkError v-else-if="error" @retry="init()"/>
@@ -13,43 +13,269 @@
</slot>
</div>
- <div v-else class="cxiknjgy">
+ <div v-else ref="rootEl">
<slot :items="items"></slot>
- <div v-show="more" key="_more_" class="more _gap">
- <MkButton v-appear="($store.state.enableInfiniteScroll && !disableAutoLoad) ? fetchMore : null" class="button" :disabled="moreFetching" :style="{ cursor: moreFetching ? 'wait' : 'pointer' }" primary @click="fetchMore">
- <template v-if="!moreFetching">{{ $ts.loadMore }}</template>
- <template v-if="moreFetching"><MkLoading inline/></template>
+ <div v-show="more" key="_more_" class="cxiknjgy _gap">
+ <MkButton v-if="!moreFetching" v-appear="($store.state.enableInfiniteScroll && !disableAutoLoad) ? fetchMore : null" class="button" :disabled="moreFetching" :style="{ cursor: moreFetching ? 'wait' : 'pointer' }" primary @click="fetchMore">
+ {{ $ts.loadMore }}
</MkButton>
+ <MkLoading v-else class="loading"/>
</div>
</div>
</transition>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
-import MkButton from './button.vue';
-import paging from '@/scripts/paging';
+<script lang="ts" setup>
+import { computed, ComputedRef, isRef, markRaw, onActivated, onDeactivated, Ref, ref, watch } from 'vue';
+import * as misskey from 'misskey-js';
+import * as os from '@/os';
+import { onScrollTop, isTopVisible, getScrollPosition, getScrollContainer } from '@/scripts/scroll';
+import MkButton from '@/components/ui/button.vue';
-export default defineComponent({
- components: {
- MkButton
- },
+const SECOND_FETCH_LIMIT = 30;
- mixins: [
- paging({}),
- ],
+export type Paging<E extends keyof misskey.Endpoints = keyof misskey.Endpoints> = {
+ endpoint: E;
+ limit: number;
+ params?: misskey.Endpoints[E]['req'] | ComputedRef<misskey.Endpoints[E]['req']>;
- props: {
- pagination: {
- required: true
- },
+ /**
+ * 検索APIのような、ページング不可なエンドポイントを利用する場合
+ * (そのようなAPIをこの関数で使うのは若干矛盾してるけど)
+ */
+ noPaging?: boolean;
- disableAutoLoad: {
- type: Boolean,
- required: false,
- default: false,
+ /**
+ * items 配列の中身を逆順にする(新しい方が最後)
+ */
+ reversed?: boolean;
+
+ offsetMode?: boolean;
+};
+
+const props = withDefaults(defineProps<{
+ pagination: Paging;
+ disableAutoLoad?: boolean;
+ displayLimit?: number;
+}>(), {
+ displayLimit: 30,
+});
+
+const emit = defineEmits<{
+ (e: 'queue', count: number): void;
+}>();
+
+type Item = { id: string; [another: string]: unknown; };
+
+const rootEl = ref<HTMLElement>();
+const items = ref<Item[]>([]);
+const queue = ref<Item[]>([]);
+const offset = ref(0);
+const fetching = ref(true);
+const moreFetching = ref(false);
+const more = ref(false);
+const backed = ref(false); // 遡り中か否か
+const isBackTop = ref(false);
+const empty = computed(() => items.value.length === 0);
+const error = ref(false);
+
+const init = async (): Promise<void> => {
+ queue.value = [];
+ fetching.value = true;
+ const params = props.pagination.params ? isRef(props.pagination.params) ? props.pagination.params.value : props.pagination.params : {};
+ await os.api(props.pagination.endpoint, {
+ ...params,
+ limit: props.pagination.noPaging ? (props.pagination.limit || 10) : (props.pagination.limit || 10) + 1,
+ }).then(res => {
+ for (let i = 0; i < res.length; i++) {
+ const item = res[i];
+ if (props.pagination.reversed) {
+ if (i === res.length - 2) item._shouldInsertAd_ = true;
+ } else {
+ if (i === 3) item._shouldInsertAd_ = true;
+ }
+ }
+ if (!props.pagination.noPaging && (res.length > (props.pagination.limit || 10))) {
+ res.pop();
+ items.value = props.pagination.reversed ? [...res].reverse() : res;
+ more.value = true;
+ } else {
+ items.value = props.pagination.reversed ? [...res].reverse() : res;
+ more.value = false;
+ }
+ offset.value = res.length;
+ error.value = false;
+ fetching.value = false;
+ }, e => {
+ error.value = true;
+ fetching.value = false;
+ });
+};
+
+const reload = (): void => {
+ items.value = [];
+ init();
+};
+
+const fetchMore = async (): Promise<void> => {
+ if (!more.value || fetching.value || moreFetching.value || items.value.length === 0) return;
+ moreFetching.value = true;
+ backed.value = true;
+ const params = props.pagination.params ? isRef(props.pagination.params) ? props.pagination.params.value : props.pagination.params : {};
+ await os.api(props.pagination.endpoint, {
+ ...params,
+ limit: SECOND_FETCH_LIMIT + 1,
+ ...(props.pagination.offsetMode ? {
+ offset: offset.value,
+ } : {
+ untilId: props.pagination.reversed ? items.value[0].id : items.value[items.value.length - 1].id,
+ }),
+ }).then(res => {
+ for (let i = 0; i < res.length; i++) {
+ const item = res[i];
+ if (props.pagination.reversed) {
+ if (i === res.length - 9) item._shouldInsertAd_ = true;
+ } else {
+ if (i === 10) item._shouldInsertAd_ = true;
+ }
+ }
+ if (res.length > SECOND_FETCH_LIMIT) {
+ res.pop();
+ items.value = props.pagination.reversed ? [...res].reverse().concat(items.value) : items.value.concat(res);
+ more.value = true;
+ } else {
+ items.value = props.pagination.reversed ? [...res].reverse().concat(items.value) : items.value.concat(res);
+ more.value = false;
+ }
+ offset.value += res.length;
+ moreFetching.value = false;
+ }, e => {
+ moreFetching.value = false;
+ });
+};
+
+const fetchMoreAhead = async (): Promise<void> => {
+ if (!more.value || fetching.value || moreFetching.value || items.value.length === 0) return;
+ moreFetching.value = true;
+ const params = props.pagination.params ? isRef(props.pagination.params) ? props.pagination.params.value : props.pagination.params : {};
+ await os.api(props.pagination.endpoint, {
+ ...params,
+ limit: SECOND_FETCH_LIMIT + 1,
+ ...(props.pagination.offsetMode ? {
+ offset: offset.value,
+ } : {
+ sinceId: props.pagination.reversed ? items.value[0].id : items.value[items.value.length - 1].id,
+ }),
+ }).then(res => {
+ if (res.length > SECOND_FETCH_LIMIT) {
+ res.pop();
+ items.value = props.pagination.reversed ? [...res].reverse().concat(items.value) : items.value.concat(res);
+ more.value = true;
+ } else {
+ items.value = props.pagination.reversed ? [...res].reverse().concat(items.value) : items.value.concat(res);
+ more.value = false;
+ }
+ offset.value += res.length;
+ moreFetching.value = false;
+ }, e => {
+ moreFetching.value = false;
+ });
+};
+
+const prepend = (item: Item): void => {
+ if (props.pagination.reversed) {
+ if (rootEl.value) {
+ const container = getScrollContainer(rootEl.value);
+ if (container == null) return; // TODO?
+
+ const pos = getScrollPosition(rootEl.value);
+ const viewHeight = container.clientHeight;
+ const height = container.scrollHeight;
+ const isBottom = (pos + viewHeight > height - 32);
+ if (isBottom) {
+ // オーバーフローしたら古いアイテムは捨てる
+ if (items.value.length >= props.displayLimit) {
+ // このやり方だとVue 3.2以降アニメーションが動かなくなる
+ //items.value = items.value.slice(-props.displayLimit);
+ while (items.value.length >= props.displayLimit) {
+ items.value.shift();
+ }
+ more.value = true;
+ }
+ }
}
- },
+ items.value.push(item);
+ // TODO
+ } else {
+ // 初回表示時はunshiftだけでOK
+ if (!rootEl.value) {
+ items.value.unshift(item);
+ return;
+ }
+
+ const isTop = isBackTop.value || (document.body.contains(rootEl.value) && isTopVisible(rootEl.value));
+
+ if (isTop) {
+ // Prepend the item
+ items.value.unshift(item);
+
+ // オーバーフローしたら古いアイテムは捨てる
+ if (items.value.length >= props.displayLimit) {
+ // このやり方だとVue 3.2以降アニメーションが動かなくなる
+ //this.items = items.value.slice(0, props.displayLimit);
+ while (items.value.length >= props.displayLimit) {
+ items.value.pop();
+ }
+ more.value = true;
+ }
+ } else {
+ queue.value.push(item);
+ onScrollTop(rootEl.value, () => {
+ for (const item of queue.value) {
+ prepend(item);
+ }
+ queue.value = [];
+ });
+ }
+ }
+};
+
+const append = (item: Item): void => {
+ items.value.push(item);
+};
+
+const updateItem = (id: Item['id'], replacer: (old: Item) => Item): void => {
+ const i = items.value.findIndex(item => item.id === id);
+ items.value[i] = replacer(items.value[i]);
+};
+
+if (props.pagination.params && isRef(props.pagination.params)) {
+ watch(props.pagination.params, init, { deep: true });
+}
+
+watch(queue, (a, b) => {
+ if (a.length === 0 && b.length === 0) return;
+ emit('queue', queue.value.length);
+}, { deep: true });
+
+init();
+
+onActivated(() => {
+ isBackTop.value = false;
+});
+
+onDeactivated(() => {
+ isBackTop.value = window.scrollY === 0;
+});
+
+defineExpose({
+ items,
+ backed,
+ reload,
+ fetchMoreAhead,
+ prepend,
+ append,
+ updateItem,
});
</script>
@@ -64,11 +290,9 @@ export default defineComponent({
}
.cxiknjgy {
- > .more > .button {
+ > .button {
margin-left: auto;
margin-right: auto;
- height: 48px;
- min-width: 150px;
}
}
</style>
diff --git a/packages/client/src/components/ui/tooltip.vue b/packages/client/src/components/ui/tooltip.vue
index 2e48ab623e..394b068352 100644
--- a/packages/client/src/components/ui/tooltip.vue
+++ b/packages/client/src/components/ui/tooltip.vue
@@ -1,5 +1,5 @@
<template>
-<transition name="tooltip" appear @after-leave="$emit('closed')">
+<transition :name="$store.state.animation ? 'tooltip' : ''" appear @after-leave="$emit('closed')">
<div v-show="showing" ref="el" class="buebdbiu _acrylic _shadow" :style="{ zIndex, maxWidth: maxWidth + 'px' }">
<slot>{{ text }}</slot>
</div>
diff --git a/packages/client/src/components/ui/window.vue b/packages/client/src/components/ui/window.vue
index bd33289ccc..fa32ecfdef 100644
--- a/packages/client/src/components/ui/window.vue
+++ b/packages/client/src/components/ui/window.vue
@@ -147,9 +147,9 @@ export default defineComponent({
}
},
- onContextmenu(e) {
+ onContextmenu(ev: MouseEvent) {
if (this.contextmenu) {
- os.contextMenu(this.contextmenu, e);
+ os.contextMenu(this.contextmenu, ev);
}
},
diff --git a/packages/client/src/components/url-preview-popup.vue b/packages/client/src/components/url-preview-popup.vue
index c345bafcf9..5f3717ab91 100644
--- a/packages/client/src/components/url-preview-popup.vue
+++ b/packages/client/src/components/url-preview-popup.vue
@@ -1,6 +1,6 @@
<template>
<div class="fgmtyycl" :style="{ zIndex, top: top + 'px', left: left + 'px' }">
- <transition name="zoom" @after-leave="$emit('closed')">
+ <transition :name="$store.state.animation ? 'zoom' : ''" @after-leave="$emit('closed')">
<MkUrlPreview v-if="showing" class="_popup _shadow" :url="url"/>
</transition>
</div>
diff --git a/packages/client/src/components/url-preview.vue b/packages/client/src/components/url-preview.vue
index fe88985a62..6c57957617 100644
--- a/packages/client/src/components/url-preview.vue
+++ b/packages/client/src/components/url-preview.vue
@@ -4,10 +4,10 @@
<iframe :src="player.url + (player.url.match(/\?/) ? '&autoplay=1&auto_play=1' : '?autoplay=1&auto_play=1')" :width="player.width || '100%'" :heigth="player.height || 250" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen />
</div>
<div v-else-if="tweetId && tweetExpanded" ref="twitter" class="twitter">
- <iframe ref="tweet" scrolling="no" frameborder="no" :style="{ position: 'relative', left: `${tweetLeft}px`, width: `${tweetLeft < 0 ? 'auto' : '100%'}`, height: `${tweetHeight}px` }" :src="`https://platform.twitter.com/embed/index.html?embedId=${embedId}&amp;hideCard=false&amp;hideThread=false&amp;lang=en&amp;theme=${$store.state.darkMode ? 'dark' : 'light'}&amp;id=${tweetId}`"></iframe>
+ <iframe ref="tweet" scrolling="no" frameborder="no" :style="{ position: 'relative', width: '100%', height: `${tweetHeight}px` }" :src="`https://platform.twitter.com/embed/index.html?embedId=${embedId}&amp;hideCard=false&amp;hideThread=false&amp;lang=en&amp;theme=${$store.state.darkMode ? 'dark' : 'light'}&amp;id=${tweetId}`"></iframe>
</div>
<div v-else v-size="{ max: [400, 350] }" class="mk-url-preview">
- <transition name="zoom" mode="out-in">
+ <transition :name="$store.state.animation ? 'zoom' : ''" mode="out-in">
<component :is="self ? 'MkA' : 'a'" v-if="!fetching" :class="{ compact }" :[attr]="self ? url.substr(local.length) : url" rel="nofollow noopener" :target="target" :title="url">
<div v-if="thumbnail" class="thumbnail" :style="`background-image: url('${thumbnail}')`">
<button v-if="!playerEnabled && player.url" class="_button" :title="$ts.enablePlayer" @click.prevent="playerEnabled = true"><i class="fas fa-play-circle"></i></button>
@@ -32,110 +32,80 @@
</div>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
+<script lang="ts" setup>
+import { onMounted, onUnmounted } from 'vue';
import { url as local, lang } from '@/config';
-import * as os from '@/os';
-export default defineComponent({
- props: {
- url: {
- type: String,
- require: true
- },
-
- detail: {
- type: Boolean,
- required: false,
- default: false
- },
-
- compact: {
- type: Boolean,
- required: false,
- default: false
- },
- },
-
- data() {
- const self = this.url.startsWith(local);
- return {
- local,
- fetching: true,
- title: null,
- description: null,
- thumbnail: null,
- icon: null,
- sitename: null,
- player: {
- url: null,
- width: null,
- height: null
- },
- tweetId: null,
- tweetExpanded: this.detail,
- embedId: `embed${Math.random().toString().replace(/\D/,'')}`,
- tweetHeight: 150,
- tweetLeft: 0,
- playerEnabled: false,
- self: self,
- attr: self ? 'to' : 'href',
- target: self ? null : '_blank',
- };
- },
+const props = withDefaults(defineProps<{
+ url: string;
+ detail?: boolean;
+ compact?: boolean;
+}>(), {
+ detail: false,
+ compact: false,
+});
- created() {
- const requestUrl = new URL(this.url);
+const self = props.url.startsWith(local);
+const attr = self ? 'to' : 'href';
+const target = self ? null : '_blank';
+let fetching = $ref(true);
+let title = $ref<string | null>(null);
+let description = $ref<string | null>(null);
+let thumbnail = $ref<string | null>(null);
+let icon = $ref<string | null>(null);
+let sitename = $ref<string | null>(null);
+let player = $ref({
+ url: null,
+ width: null,
+ height: null
+});
+let playerEnabled = $ref(false);
+let tweetId = $ref<string | null>(null);
+let tweetExpanded = $ref(props.detail);
+const embedId = `embed${Math.random().toString().replace(/\D/,'')}`;
+let tweetHeight = $ref(150);
- if (requestUrl.hostname == 'twitter.com') {
- const m = requestUrl.pathname.match(/^\/.+\/status(?:es)?\/(\d+)/);
- if (m) this.tweetId = m[1];
- }
+const requestUrl = new URL(props.url);
- if (requestUrl.hostname === 'music.youtube.com' && requestUrl.pathname.match('^/(?:watch|channel)')) {
- requestUrl.hostname = 'www.youtube.com';
- }
+if (requestUrl.hostname == 'twitter.com') {
+ const m = requestUrl.pathname.match(/^\/.+\/status(?:es)?\/(\d+)/);
+ if (m) tweetId = m[1];
+}
- const requestLang = (lang || 'ja-JP').replace('ja-KS', 'ja-JP');
+if (requestUrl.hostname === 'music.youtube.com' && requestUrl.pathname.match('^/(?:watch|channel)')) {
+ requestUrl.hostname = 'www.youtube.com';
+}
- requestUrl.hash = '';
+const requestLang = (lang || 'ja-JP').replace('ja-KS', 'ja-JP');
- fetch(`/url?url=${encodeURIComponent(requestUrl.href)}&lang=${requestLang}`).then(res => {
- res.json().then(info => {
- if (info.url == null) return;
- this.title = info.title;
- this.description = info.description;
- this.thumbnail = info.thumbnail;
- this.icon = info.icon;
- this.sitename = info.sitename;
- this.fetching = false;
- this.player = info.player;
- })
- });
+requestUrl.hash = '';
- (window as any).addEventListener('message', this.adjustTweetHeight);
- },
+fetch(`/url?url=${encodeURIComponent(requestUrl.href)}&lang=${requestLang}`).then(res => {
+ res.json().then(info => {
+ if (info.url == null) return;
+ title = info.title;
+ description = info.description;
+ thumbnail = info.thumbnail;
+ icon = info.icon;
+ sitename = info.sitename;
+ fetching = false;
+ player = info.player;
+ })
+});
- mounted() {
- // 300pxないと絶対右にはみ出るので左に移動してしまう
- const areaWidth = (this.$el as any)?.clientWidth;
- if (areaWidth && areaWidth < 300) this.tweetLeft = areaWidth - 241;
- },
+function adjustTweetHeight(message: any) {
+ if (message.origin !== 'https://platform.twitter.com') return;
+ const embed = message.data?.['twttr.embed'];
+ if (embed?.method !== 'twttr.private.resize') return;
+ if (embed?.id !== embedId) return;
+ const height = embed?.params[0]?.height;
+ if (height) tweetHeight = height;
+}
- beforeUnmount() {
- (window as any).removeEventListener('message', this.adjustTweetHeight);
- },
+(window as any).addEventListener('message', adjustTweetHeight);
- methods: {
- adjustTweetHeight(message: any) {
- if (message.origin !== 'https://platform.twitter.com') return;
- const embed = message.data?.['twttr.embed'];
- if (embed?.method !== 'twttr.private.resize') return;
- if (embed?.id !== this.embedId) return;
- const height = embed?.params[0]?.height;
- if (height) this.tweetHeight = height;
- },
- },
+onUnmounted(() => {
+ (window as any).removeEventListener('message', adjustTweetHeight);
});
</script>
diff --git a/packages/client/src/components/user-info.vue b/packages/client/src/components/user-info.vue
index 779a71358d..6a25d412fc 100644
--- a/packages/client/src/components/user-info.vue
+++ b/packages/client/src/components/user-info.vue
@@ -27,32 +27,14 @@
</div>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
+<script lang="ts" setup>
+import * as misskey from 'misskey-js';
import MkFollowButton from './follow-button.vue';
import { userPage } from '@/filters/user';
-export default defineComponent({
- components: {
- MkFollowButton
- },
-
- props: {
- user: {
- type: Object,
- required: true
- },
- },
-
- data() {
- return {
- };
- },
-
- methods: {
- userPage,
- }
-});
+defineProps<{
+ user: misskey.entities.UserDetailed;
+}>();
</script>
<style lang="scss" scoped>
diff --git a/packages/client/src/components/user-list.vue b/packages/client/src/components/user-list.vue
index 2148dab608..3e273721c7 100644
--- a/packages/client/src/components/user-list.vue
+++ b/packages/client/src/components/user-list.vue
@@ -1,91 +1,39 @@
<template>
-<MkError v-if="error" @retry="init()"/>
+<MkPagination ref="pagingComponent" :pagination="pagination">
+ <template #empty>
+ <div class="_fullinfo">
+ <img src="https://xn--931a.moe/assets/info.jpg" class="_ghost"/>
+ <div>{{ $ts.noUsers }}</div>
+ </div>
+ </template>
-<div v-else class="efvhhmdq _isolated">
- <div v-if="empty" class="no-users">
- <p>{{ $ts.noUsers }}</p>
- </div>
- <div class="users">
- <MkUserInfo v-for="user in users" :key="user.id" class="user" :user="user"/>
- </div>
- <button v-show="more" v-appear="$store.state.enableInfiniteScroll ? fetchMore : null" class="more" :class="{ fetching: moreFetching }" :disabled="moreFetching" @click="fetchMore">
- <template v-if="moreFetching"><i class="fas fa-spinner fa-pulse fa-fw"></i></template>{{ moreFetching ? $ts.loading : $ts.loadMore }}
- </button>
-</div>
+ <template #default="{ items: users }">
+ <div class="efvhhmdq">
+ <MkUserInfo v-for="user in users" :key="user.id" class="user" :user="user"/>
+ </div>
+ </template>
+</MkPagination>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
-import paging from '@/scripts/paging';
-import MkUserInfo from './user-info.vue';
+<script lang="ts" setup>
+import { ref } from 'vue';
+import MkUserInfo from '@/components/user-info.vue';
+import MkPagination from '@/components/ui/pagination.vue';
+import { Paging } from '@/components/ui/pagination.vue';
import { userPage } from '@/filters/user';
-export default defineComponent({
- components: {
- MkUserInfo,
- },
+const props = defineProps<{
+ pagination: Paging;
+ noGap?: boolean;
+}>();
- mixins: [
- paging({}),
- ],
-
- props: {
- pagination: {
- required: true
- },
- extract: {
- required: false
- },
- expanded: {
- type: Boolean,
- default: true
- },
- },
-
- computed: {
- users() {
- return this.extract ? this.extract(this.items) : this.items;
- }
- },
-
- methods: {
- userPage
- }
-});
+const pagingComponent = ref<InstanceType<typeof MkPagination>>();
</script>
<style lang="scss" scoped>
.efvhhmdq {
- > .no-users {
- text-align: center;
- }
-
- > .users {
- display: grid;
- grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
- grid-gap: var(--margin);
- }
-
- > .more {
- display: block;
- width: 100%;
- padding: 16px;
-
- &:hover {
- background: rgba(#000, 0.025);
- }
-
- &:active {
- background: rgba(#000, 0.05);
- }
-
- &.fetching {
- cursor: wait;
- }
-
- > i {
- margin-right: 4px;
- }
- }
+ display: grid;
+ grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
+ grid-gap: var(--margin);
}
</style>
diff --git a/packages/client/src/components/user-online-indicator.vue b/packages/client/src/components/user-online-indicator.vue
index 93e9dea57b..a87b0aeff5 100644
--- a/packages/client/src/components/user-online-indicator.vue
+++ b/packages/client/src/components/user-online-indicator.vue
@@ -2,26 +2,21 @@
<div v-tooltip="text" class="fzgwjkgc" :class="user.onlineStatus"></div>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
+<script lang="ts" setup>
+import { } from 'vue';
+import * as misskey from 'misskey-js';
+import { i18n } from '@/i18n';
-export default defineComponent({
- props: {
- user: {
- type: Object,
- required: true
- },
- },
+const props = defineProps<{
+ user: misskey.entities.User;
+}>();
- computed: {
- text(): string {
- switch (this.user.onlineStatus) {
- case 'online': return this.$ts.online;
- case 'active': return this.$ts.active;
- case 'offline': return this.$ts.offline;
- case 'unknown': return this.$ts.unknown;
- }
- }
+const text = $computed(() => {
+ switch (props.user.onlineStatus) {
+ case 'online': return i18n.locale.online;
+ case 'active': return i18n.locale.active;
+ case 'offline': return i18n.locale.offline;
+ case 'unknown': return i18n.locale.unknown;
}
});
</script>
diff --git a/packages/client/src/components/user-preview.vue b/packages/client/src/components/user-preview.vue
index f85a32fbe7..51c5330564 100644
--- a/packages/client/src/components/user-preview.vue
+++ b/packages/client/src/components/user-preview.vue
@@ -1,5 +1,5 @@
<template>
-<transition name="popup" appear @after-leave="$emit('closed')">
+<transition :name="$store.state.animation ? 'popup' : ''" appear @after-leave="$emit('closed')">
<div v-if="showing" class="fxxzrfni _popup _shadow" :style="{ zIndex, top: top + 'px', left: left + 'px' }" @mouseover="() => { $emit('mouseover'); }" @mouseleave="() => { $emit('mouseleave'); }">
<div v-if="fetched" class="info">
<div class="banner" :style="user.bannerUrl ? `background-image: url(${user.bannerUrl})` : ''"></div>
diff --git a/packages/client/src/components/user-select-dialog.vue b/packages/client/src/components/user-select-dialog.vue
index ba2975478b..dbef34d547 100644
--- a/packages/client/src/components/user-select-dialog.vue
+++ b/packages/client/src/components/user-select-dialog.vue
@@ -1,5 +1,5 @@
<template>
-<XModalWindow ref="dialog"
+<XModalWindow ref="dialogEl"
:with-ok-button="true"
:ok-button-disabled="selected == null"
@click="cancel()"
@@ -8,20 +8,20 @@
@closed="$emit('closed')"
>
<template #header>{{ $ts.selectUser }}</template>
- <div class="tbhwbxda _monolithic_">
- <div class="_section">
- <div class="_inputSplit">
- <MkInput ref="username" v-model="username" class="input" @update:modelValue="search">
+ <div class="tbhwbxda">
+ <div class="form">
+ <FormSplit :min-width="170">
+ <MkInput ref="usernameEl" v-model="username" @update:modelValue="search">
<template #label>{{ $ts.username }}</template>
<template #prefix>@</template>
</MkInput>
- <MkInput v-model="host" class="input" @update:modelValue="search">
+ <MkInput v-model="host" @update:modelValue="search">
<template #label>{{ $ts.host }}</template>
<template #prefix>@</template>
</MkInput>
- </div>
+ </FormSplit>
</div>
- <div v-if="username != '' || host != ''" class="_section result" :class="{ hit: users.length > 0 }">
+ <div v-if="username != '' || host != ''" class="result" :class="{ hit: users.length > 0 }">
<div v-if="users.length > 0" class="users">
<div v-for="user in users" :key="user.id" class="user" :class="{ selected: selected && selected.id === user.id }" @click="selected = user" @dblclick="ok()">
<MkAvatar :user="user" class="avatar" :show-indicator="true"/>
@@ -35,7 +35,7 @@
<span>{{ $ts.noUsers }}</span>
</div>
</div>
- <div v-if="username == '' && host == ''" class="_section recent">
+ <div v-if="username == '' && host == ''" class="recent">
<div class="users">
<div v-for="user in recentUsers" :key="user.id" class="user" :class="{ selected: selected && selected.id === user.id }" @click="selected = user" @dblclick="ok()">
<MkAvatar :user="user" class="avatar" :show-indicator="true"/>
@@ -50,87 +50,89 @@
</XModalWindow>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
-import MkInput from './form/input.vue';
+<script lang="ts" setup>
+import { nextTick, onMounted } from 'vue';
+import * as misskey from 'misskey-js';
+import MkInput from '@/components/form/input.vue';
+import FormSplit from '@/components/form/split.vue';
import XModalWindow from '@/components/ui/modal-window.vue';
import * as os from '@/os';
+import { defaultStore } from '@/store';
-export default defineComponent({
- components: {
- MkInput,
- XModalWindow,
- },
-
- props: {
- },
+const emit = defineEmits<{
+ (e: 'ok', selected: misskey.entities.UserDetailed): void;
+ (e: 'cancel'): void;
+ (e: 'closed'): void;
+}>();
- emits: ['ok', 'cancel', 'closed'],
+let username = $ref('');
+let host = $ref('');
+let users: misskey.entities.UserDetailed[] = $ref([]);
+let recentUsers: misskey.entities.UserDetailed[] = $ref([]);
+let selected: misskey.entities.UserDetailed | null = $ref(null);
+let usernameEl: HTMLElement = $ref();
+let dialogEl = $ref();
- data() {
- return {
- username: '',
- host: '',
- recentUsers: [],
- users: [],
- selected: null,
- };
- },
+const focus = () => {
+ if (usernameEl) {
+ usernameEl.focus();
+ }
+};
- async mounted() {
- this.focus();
+const search = () => {
+ if (username === '' && host === '') {
+ users = [];
+ return;
+ }
+ os.api('users/search-by-username-and-host', {
+ username: username,
+ host: host,
+ limit: 10,
+ detail: false
+ }).then(_users => {
+ users = _users;
+ });
+};
- this.$nextTick(() => {
- this.focus();
- });
+const ok = () => {
+ if (selected == null) return;
+ emit('ok', selected);
+ dialogEl.close();
- this.recentUsers = await os.api('users/show', {
- userIds: this.$store.state.recentlyUsedUsers
- });
- },
+ // 最近使ったユーザー更新
+ let recents = defaultStore.state.recentlyUsedUsers;
+ recents = recents.filter(x => x !== selected.id);
+ recents.unshift(selected.id);
+ defaultStore.set('recentlyUsedUsers', recents.splice(0, 16));
+};
- methods: {
- search() {
- if (this.username == '' && this.host == '') {
- this.users = [];
- return;
- }
- os.api('users/search-by-username-and-host', {
- username: this.username,
- host: this.host,
- limit: 10,
- detail: false
- }).then(users => {
- this.users = users;
- });
- },
+const cancel = () => {
+ emit('cancel');
+ dialogEl.close();
+};
- focus() {
- this.$refs.username.focus();
- },
+onMounted(() => {
+ focus();
- ok() {
- this.$emit('ok', this.selected);
- this.$refs.dialog.close();
+ nextTick(() => {
+ focus();
+ });
- // 最近使ったユーザー更新
- let recents = this.$store.state.recentlyUsedUsers;
- recents = recents.filter(x => x !== this.selected.id);
- recents.unshift(this.selected.id);
- this.$store.set('recentlyUsedUsers', recents.splice(0, 16));
- },
-
- cancel() {
- this.$emit('cancel');
- this.$refs.dialog.close();
- },
- }
+ os.api('users/show', {
+ userIds: defaultStore.state.recentlyUsedUsers,
+ }).then(users => {
+ recentUsers = users;
+ });
});
</script>
<style lang="scss" scoped>
.tbhwbxda {
- > ._section {
+ > .form {
+ padding: 0 var(--root-margin);
+ }
+
+ > .result, > .recent {
display: flex;
flex-direction: column;
overflow: auto;
diff --git a/packages/client/src/components/visibility-picker.vue b/packages/client/src/components/visibility-picker.vue
index 4200f4354e..4b20063a51 100644
--- a/packages/client/src/components/visibility-picker.vue
+++ b/packages/client/src/components/visibility-picker.vue
@@ -1,28 +1,28 @@
<template>
-<MkModal ref="modal" :z-priority="'high'" :src="src" @click="$refs.modal.close()" @closed="$emit('closed')">
+<MkModal ref="modal" :z-priority="'high'" :src="src" @click="modal.close()" @closed="emit('closed')">
<div class="gqyayizv _popup">
- <button key="public" class="_button" :class="{ active: v == 'public' }" data-index="1" @click="choose('public')">
+ <button key="public" class="_button" :class="{ active: v === 'public' }" data-index="1" @click="choose('public')">
<div><i class="fas fa-globe"></i></div>
<div>
<span>{{ $ts._visibility.public }}</span>
<span>{{ $ts._visibility.publicDescription }}</span>
</div>
</button>
- <button key="home" class="_button" :class="{ active: v == 'home' }" data-index="2" @click="choose('home')">
+ <button key="home" class="_button" :class="{ active: v === 'home' }" data-index="2" @click="choose('home')">
<div><i class="fas fa-home"></i></div>
<div>
<span>{{ $ts._visibility.home }}</span>
<span>{{ $ts._visibility.homeDescription }}</span>
</div>
</button>
- <button key="followers" class="_button" :class="{ active: v == 'followers' }" data-index="3" @click="choose('followers')">
+ <button key="followers" class="_button" :class="{ active: v === 'followers' }" data-index="3" @click="choose('followers')">
<div><i class="fas fa-unlock"></i></div>
<div>
<span>{{ $ts._visibility.followers }}</span>
<span>{{ $ts._visibility.followersDescription }}</span>
</div>
</button>
- <button key="specified" :disabled="localOnly" class="_button" :class="{ active: v == 'specified' }" data-index="4" @click="choose('specified')">
+ <button key="specified" :disabled="localOnly" class="_button" :class="{ active: v === 'specified' }" data-index="4" @click="choose('specified')">
<div><i class="fas fa-envelope"></i></div>
<div>
<span>{{ $ts._visibility.specified }}</span>
@@ -42,49 +42,40 @@
</MkModal>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
+<script lang="ts" setup>
+import { nextTick, watch } from 'vue';
+import * as misskey from 'misskey-js';
import MkModal from '@/components/ui/modal.vue';
-export default defineComponent({
- components: {
- MkModal,
- },
- props: {
- currentVisibility: {
- type: String,
- required: true
- },
- currentLocalOnly: {
- type: Boolean,
- required: true
- },
- src: {
- required: false
- },
- },
- emits: ['change-visibility', 'change-local-only', 'closed'],
- data() {
- return {
- v: this.currentVisibility,
- localOnly: this.currentLocalOnly,
- }
- },
- watch: {
- localOnly() {
- this.$emit('change-local-only', this.localOnly);
- }
- },
- methods: {
- choose(visibility) {
- this.v = visibility;
- this.$emit('change-visibility', visibility);
- this.$nextTick(() => {
- this.$refs.modal.close();
- });
- },
- }
+const modal = $ref<InstanceType<typeof MkModal>>();
+
+const props = withDefaults(defineProps<{
+ currentVisibility: typeof misskey.noteVisibilities[number];
+ currentLocalOnly: boolean;
+ src?: HTMLElement;
+}>(), {
+});
+
+const emit = defineEmits<{
+ (e: 'changeVisibility', v: typeof misskey.noteVisibilities[number]): void;
+ (e: 'changeLocalOnly', v: boolean): void;
+ (e: 'closed'): void;
+}>();
+
+let v = $ref(props.currentVisibility);
+let localOnly = $ref(props.currentLocalOnly);
+
+watch($$(localOnly), () => {
+ emit('changeLocalOnly', localOnly);
});
+
+function choose(visibility: typeof misskey.noteVisibilities[number]): void {
+ v = visibility;
+ emit('changeVisibility', visibility);
+ nextTick(() => {
+ modal.close();
+ });
+}
</script>
<style lang="scss" scoped>
diff --git a/packages/client/src/components/waiting-dialog.vue b/packages/client/src/components/waiting-dialog.vue
index 10aedbd8f6..7dfcc55695 100644
--- a/packages/client/src/components/waiting-dialog.vue
+++ b/packages/client/src/components/waiting-dialog.vue
@@ -1,5 +1,5 @@
<template>
-<MkModal ref="modal" :prefer-type="'dialog'" :z-priority="'high'" @click="success ? done() : () => {}" @closed="$emit('closed')">
+<MkModal ref="modal" :prefer-type="'dialog'" :z-priority="'high'" @click="success ? done() : () => {}" @closed="emit('closed')">
<div class="iuyakobc" :class="{ iconOnly: (text == null) || success }">
<i v-if="success" class="fas fa-check icon success"></i>
<i v-else class="fas fa-spinner fa-pulse icon waiting"></i>
@@ -8,49 +8,30 @@
</MkModal>
</template>
-<script lang="ts">
-import { defineComponent } from 'vue';
+<script lang="ts" setup>
+import { watch, ref } from 'vue';
import MkModal from '@/components/ui/modal.vue';
-export default defineComponent({
- components: {
- MkModal,
- },
+const modal = ref<InstanceType<typeof MkModal>>();
- props: {
- success: {
- type: Boolean,
- required: true,
- },
- showing: {
- type: Boolean,
- required: true,
- },
- text: {
- type: String,
- required: false,
- },
- },
+const props = defineProps<{
+ success: boolean;
+ showing: boolean;
+ text?: string;
+}>();
- emits: ['done', 'closed'],
+const emit = defineEmits<{
+ (e: 'done');
+ (e: 'closed');
+}>();
- data() {
- return {
- };
- },
-
- watch: {
- showing() {
- if (!this.showing) this.done();
- }
- },
+function done() {
+ emit('done');
+ modal.value.close();
+}
- methods: {
- done() {
- this.$emit('done');
- this.$refs.modal.close();
- },
- }
+watch(() => props.showing, () => {
+ if (!props.showing) done();
});
</script>
diff --git a/packages/client/src/components/widgets.vue b/packages/client/src/components/widgets.vue
index 12f7129253..ccde5fbe55 100644
--- a/packages/client/src/components/widgets.vue
+++ b/packages/client/src/components/widgets.vue
@@ -10,7 +10,7 @@
<MkButton inline @click="$emit('exit')">{{ $ts.close }}</MkButton>
</header>
<XDraggable
- v-model="_widgets"
+ v-model="widgets_"
item-key="id"
animation="150"
>
@@ -18,7 +18,7 @@
<div class="customize-container">
<button class="config _button" @click.prevent.stop="configWidget(element.id)"><i class="fas fa-cog"></i></button>
<button class="remove _button" @click.prevent.stop="removeWidget(element)"><i class="fas fa-times"></i></button>
- <component :is="`mkw-${element.name}`" :widget="element" :setting-callback="setting => settings[element.id] = setting" @updateProps="updateWidget(element.id, $event)"/>
+ <component :ref="el => widgetRefs[element.id] = el" :is="`mkw-${element.name}`" :widget="element" @updateProps="updateWidget(element.id, $event)"/>
</div>
</template>
</XDraggable>
@@ -28,7 +28,7 @@
</template>
<script lang="ts">
-import { defineComponent, defineAsyncComponent } from 'vue';
+import { defineComponent, defineAsyncComponent, reactive, ref, computed } from 'vue';
import { v4 as uuid } from 'uuid';
import MkSelect from '@/components/form/select.vue';
import MkButton from '@/components/ui/button.vue';
@@ -54,50 +54,47 @@ export default defineComponent({
emits: ['updateWidgets', 'addWidget', 'removeWidget', 'updateWidget', 'exit'],
- data() {
- return {
- widgetAdderSelected: null,
- widgetDefs,
- settings: {},
+ setup(props, context) {
+ const widgetRefs = reactive({});
+ const configWidget = (id: string) => {
+ widgetRefs[id].configure();
};
- },
-
- computed: {
- _widgets: {
- get() {
- return this.widgets;
- },
- set(value) {
- this.$emit('updateWidgets', value);
- }
- }
- },
-
- methods: {
- configWidget(id) {
- this.settings[id]();
- },
+ const widgetAdderSelected = ref(null);
+ const addWidget = () => {
+ if (widgetAdderSelected.value == null) return;
- addWidget() {
- if (this.widgetAdderSelected == null) return;
-
- this.$emit('addWidget', {
- name: this.widgetAdderSelected,
+ context.emit('addWidget', {
+ name: widgetAdderSelected.value,
id: uuid(),
- data: {}
+ data: {},
});
- this.widgetAdderSelected = null;
- },
-
- removeWidget(widget) {
- this.$emit('removeWidget', widget);
- },
+ widgetAdderSelected.value = null;
+ };
+ const removeWidget = (widget) => {
+ context.emit('removeWidget', widget);
+ };
+ const updateWidget = (id, data) => {
+ context.emit('updateWidget', { id, data });
+ };
+ const widgets_ = computed({
+ get: () => props.widgets,
+ set: (value) => {
+ context.emit('updateWidgets', value);
+ },
+ });
- updateWidget(id, data) {
- this.$emit('updateWidget', { id, data });
- },
- }
+ return {
+ widgetRefs,
+ configWidget,
+ widgetAdderSelected,
+ widgetDefs,
+ addWidget,
+ removeWidget,
+ updateWidget,
+ widgets_,
+ };
+ },
});
</script>