Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance(frontend): MFMや絵文字が使える入力ボックスでオートコンプリートを使えるように #12643

Merged
merged 18 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
- Enhance: データセーバーの適用範囲を個別で設定できるように
- 従来のデータセーバーの設定はリセットされます
- Enhance: タイムライン上のタブからリスト、アンテナ、チャンネルの管理ページにジャンプできるように
- Enhance: ユーザー名、プロフィール、お知らせ、ページの編集画面でMFMや絵文字のオートコンプリートが使用できるように
- Enhance: プロフィール、お知らせの編集画面でMFMのプレビューを表示できるように
- Feat: センシティブと判断されたウェブサイトのサムネイルをぼかすように
- ウェブサイトをセンシティブと判断する仕組みが動いていないため、summalyProxyを使用しないと機能しません。
- fix: 「設定のバックアップ」で一部の項目がバックアップに含まれていなかった問題を修正
Expand Down
Binary file added dump.rdb
1Step621 marked this conversation as resolved.
Show resolved Hide resolved
Binary file not shown.
9 changes: 7 additions & 2 deletions packages/frontend/src/components/MkFormDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,18 @@ SPDX-License-Identifier: AGPL-3.0-only
<template #label><span v-text="form[item].label || item"></span><span v-if="form[item].required === false"> ({{ i18n.ts.optional }})</span></template>
<template v-if="form[item].description" #caption>{{ form[item].description }}</template>
</MkInput>
<MkInput v-else-if="form[item].type === 'string' && !form[item].multiline" v-model="values[item]" type="text">
<MkInput v-else-if="form[item].type === 'string' && !form[item].multiline" v-model="values[item]" type="text" :richAutocomplete="form[item].richSyntax">
<template #label><span v-text="form[item].label || item"></span><span v-if="form[item].required === false"> ({{ i18n.ts.optional }})</span></template>
<template v-if="form[item].description" #caption>{{ form[item].description }}</template>
</MkInput>
<MkTextarea v-else-if="form[item].type === 'string' && form[item].multiline" v-model="values[item]">
<MkTextarea v-else-if="form[item].type === 'string' && form[item].multiline && !form[item].richSyntax" v-model="values[item]">
<template #label><span v-text="form[item].label || item"></span><span v-if="form[item].required === false"> ({{ i18n.ts.optional }})</span></template>
<template v-if="form[item].description" #caption>{{ form[item].description }}</template>
</MkTextarea>
<MkTextareaWithMfmPreview v-else-if="form[item].type === 'string' && form[item].multiline && form[item].richSyntax" v-model="values[item]">
<template #label><span v-text="form[item].label || item"></span><span v-if="form[item].required === false"> ({{ i18n.ts.optional }})</span></template>
<template v-if="form[item].description" #caption>{{ form[item].description }}</template>
</MkTextareaWithMfmPreview>
<MkSwitch v-else-if="form[item].type === 'boolean'" v-model="values[item]">
<span v-text="form[item].label || item"></span>
<template v-if="form[item].description" #caption>{{ form[item].description }}</template>
Expand Down Expand Up @@ -69,6 +73,7 @@ import MkRange from './MkRange.vue';
import MkButton from './MkButton.vue';
import MkRadios from './MkRadios.vue';
import MkModalWindow from '@/components/MkModalWindow.vue';
import MkTextareaWithMfmPreview from './MkTextareaWithMfmPreview.vue';
import { i18n } from '@/i18n.js';

const props = defineProps<{
Expand Down
15 changes: 14 additions & 1 deletion packages/frontend/src/components/MkInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ SPDX-License-Identifier: AGPL-3.0-only
</template>

<script lang="ts" setup>
import { onMounted, nextTick, ref, shallowRef, watch, computed, toRefs } from 'vue';
import { onMounted, onUnmounted, nextTick, ref, shallowRef, watch, computed, toRefs } from 'vue';
import { debounce } from 'throttle-debounce';
import MkButton from '@/components/MkButton.vue';
import { useInterval } from '@/scripts/use-interval.js';
import { i18n } from '@/i18n.js';
import { Autocomplete, SuggestionType } from '@/scripts/autocomplete.js';

const props = defineProps<{
modelValue: string | number | null;
Expand All @@ -59,6 +60,7 @@ const props = defineProps<{
placeholder?: string;
autofocus?: boolean;
autocomplete?: string;
richAutocomplete?: boolean | SuggestionType[],
autocapitalize?: string;
spellcheck?: boolean;
step?: any;
Expand Down Expand Up @@ -93,6 +95,7 @@ const height =
props.small ? 33 :
props.large ? 39 :
36;
let autocomplete: Autocomplete;

const focus = () => inputEl.value.focus();
const onInput = (ev: KeyboardEvent) => {
Expand Down Expand Up @@ -160,6 +163,16 @@ onMounted(() => {
focus();
}
});

if (props.richAutocomplete) {
autocomplete = new Autocomplete(inputEl.value, v, props.richAutocomplete === true ? null : props.richAutocomplete);
}
});

onUnmounted(() => {
if (props.richAutocomplete) {
autocomplete.detach();
}
});

defineExpose({
Expand Down
15 changes: 14 additions & 1 deletion packages/frontend/src/components/MkTextarea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ SPDX-License-Identifier: AGPL-3.0-only
</template>

<script lang="ts" setup>
import { onMounted, nextTick, ref, watch, computed, toRefs, shallowRef } from 'vue';
import { onMounted, onUnmounted, nextTick, ref, watch, computed, toRefs, shallowRef } from 'vue';
import { debounce } from 'throttle-debounce';
import MkButton from '@/components/MkButton.vue';
import { i18n } from '@/i18n.js';
import { Autocomplete, SuggestionType } from '@/scripts/autocomplete.js';

const props = defineProps<{
modelValue: string | null;
Expand All @@ -46,6 +47,7 @@ const props = defineProps<{
placeholder?: string;
autofocus?: boolean;
autocomplete?: string;
richAutocomplete?: boolean | SuggestionType[],
spellcheck?: boolean;
debounce?: boolean;
manualSave?: boolean;
Expand All @@ -68,6 +70,7 @@ const changed = ref(false);
const invalid = ref(false);
const filled = computed(() => v.value !== '' && v.value != null);
const inputEl = shallowRef<HTMLTextAreaElement>();
let autocomplete: Autocomplete;

const focus = () => inputEl.value.focus();
const onInput = (ev) => {
Expand Down Expand Up @@ -113,6 +116,16 @@ onMounted(() => {
focus();
}
});

if (props.richAutocomplete) {
autocomplete = new Autocomplete(inputEl.value, v, props.richAutocomplete === true ? null : props.richAutocomplete);
}
});

onUnmounted(() => {
if (props.richAutocomplete) {
1Step621 marked this conversation as resolved.
Show resolved Hide resolved
autocomplete.detach();
}
});
</script>

Expand Down
133 changes: 133 additions & 0 deletions packages/frontend/src/components/MkTextareaWithMfmPreview.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<!--
SPDX-FileCopyrightText: syuilo and other misskey contributors
SPDX-License-Identifier: AGPL-3.0-only
-->

<template>
<FormSlot>
<template #label><slot name="label"></slot></template>
<MkTab v-model="tab" style="margin-bottom: var(--margin);">
<option value="edit">{{ i18n.ts.edit }}</option>
<option value="preview">{{ i18n.ts.preview }}</option>
</MkTab>
<MkTextarea
v-show="tab === 'edit'"
ref="inputEl"
v-model="v"
:required="required"
:readonly="readonly"
:disabled="disabled"
:pattern="pattern"
:placeholder="placeholder"
:autofocus="autofocus"
:autocomplete="autocomplete"
:spellcheck="spellcheck"
:debounce="props.debounce"
:manualSave="manualSave"
:code="code"
:tall="tall"
:pre="pre"
richAutocomplete
@focus="focused = true"
@blur="focused = false"
@keydown="onKeydown($event)"
@input="onInput" />
<div v-show="tab === 'preview'" class="_panel" :class="{ [$style.mfmPreview]: true, [$style.tall]: tall }">
<Mfm :text="v" :nyaize="nyaize ?? false" :author="author" />
</div>
<template #caption><slot name="caption"></slot></template>
</FormSlot>
</template>

<script lang="ts" setup>
import { ref, watch, toRefs, shallowRef } from 'vue';
import { debounce } from 'throttle-debounce';
import { i18n } from '@/i18n.js';
import FormSlot from '@/components/form/slot.vue';
import MkTab from '@/components/MkTab.vue';
import MkTextarea from '@/components/MkTextarea.vue';
import Misskey from 'misskey-js';

const props = defineProps<{
modelValue: string | null;
required?: boolean;
readonly?: boolean;
disabled?: boolean;
pattern?: string;
placeholder?: string;
autofocus?: boolean;
autocomplete?: string;
spellcheck?: boolean;
debounce?: boolean;
manualSave?: boolean;
code?: boolean;
tall?: boolean;
pre?: boolean;
author?: Misskey.entities.UserLite;
nyaize?: "respect" | boolean;
}>();

const emit = defineEmits<{
(ev: 'change', _ev: KeyboardEvent): void;
(ev: 'keydown', _ev: KeyboardEvent): void;
(ev: 'enter'): void;
(ev: 'update:modelValue', value: string): void;
}>();

const { modelValue } = toRefs(props);
const v = ref<string>(modelValue.value ?? '');
const focused = ref(false);
const changed = ref(false);
const inputEl = shallowRef<HTMLTextAreaElement>();
const tab = ref("edit");

const focus = () => inputEl.value.focus();
const onInput = (ev) => {
changed.value = true;
emit('change', ev);
};
const onKeydown = (ev: KeyboardEvent) => {
if (ev.isComposing || ev.key === 'Process' || ev.keyCode === 229) return;

emit('keydown', ev);

if (ev.code === 'Enter') {
emit('enter');
}
};

const updated = () => {
changed.value = false;
emit('update:modelValue', v.value ?? '');
};

const debouncedUpdated = debounce(1000, updated);

watch(modelValue, newValue => {
v.value = newValue;
});

watch(v, newValue => {
if (!props.manualSave) {
if (props.debounce) {
debouncedUpdated();
} else {
updated();
}
}
});
</script>

<style lang="scss" module>
.mfmPreview {
padding: 12px;
border: 1px solid var(--divider);
border-radius: 6px;
box-sizing: border-box;
min-height: 130px;
}

.tall {
min-height: 200px;
}
</style>
6 changes: 3 additions & 3 deletions packages/frontend/src/pages/admin/announcements.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkInput v-model="announcement.title">
<template #label>{{ i18n.ts.title }}</template>
</MkInput>
<MkTextarea v-model="announcement.text">
<MkTextareaWithMfmPreview v-model="announcement.text">
<template #label>{{ i18n.ts.text }}</template>
</MkTextarea>
</MkTextareaWithMfmPreview>
<MkInput v-model="announcement.imageUrl" type="url">
<template #label>{{ i18n.ts.imageUrl }}</template>
</MkInput>
Expand Down Expand Up @@ -75,7 +75,7 @@ import { ref, computed } from 'vue';
import XHeader from './_header_.vue';
import MkButton from '@/components/MkButton.vue';
import MkInput from '@/components/MkInput.vue';
import MkTextarea from '@/components/MkTextarea.vue';
import MkTextareaWithMfmPreview from '@/components/MkTextareaWithMfmPreview.vue';
import MkSwitch from '@/components/MkSwitch.vue';
import MkRadios from '@/components/MkRadios.vue';
import MkInfo from '@/components/MkInfo.vue';
Expand Down
6 changes: 3 additions & 3 deletions packages/frontend/src/pages/channel-editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ SPDX-License-Identifier: AGPL-3.0-only
<template #label>{{ i18n.ts.name }}</template>
</MkInput>

<MkTextarea v-model="description">
<MkTextareaWithMfmPreview v-model="description">
<template #label>{{ i18n.ts.description }}</template>
</MkTextarea>
</MkTextareaWithMfmPreview>

<MkColorInput v-model="color">
<template #label>{{ i18n.ts.color }}</template>
Expand Down Expand Up @@ -70,7 +70,6 @@ SPDX-License-Identifier: AGPL-3.0-only

<script lang="ts" setup>
import { computed, ref, watch, defineAsyncComponent } from 'vue';
import MkTextarea from '@/components/MkTextarea.vue';
import MkButton from '@/components/MkButton.vue';
import MkInput from '@/components/MkInput.vue';
import MkColorInput from '@/components/MkColorInput.vue';
Expand All @@ -81,6 +80,7 @@ import { definePageMetadata } from '@/scripts/page-metadata.js';
import { i18n } from '@/i18n.js';
import MkFolder from '@/components/MkFolder.vue';
import MkSwitch from '@/components/MkSwitch.vue';
import MkTextareaWithMfmPreview from '@/components/MkTextareaWithMfmPreview.vue';

const Sortable = defineAsyncComponent(() => import('vuedraggable').then(x => x.default));

Expand Down
1 change: 1 addition & 0 deletions packages/frontend/src/pages/clip.vue
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ const headerActions = computed(() => clip.value && isOwned.value ? [{
type: 'string',
required: false,
multiline: true,
richSyntax: true,
label: i18n.ts.description,
default: clip.value.description,
},
Expand Down
1 change: 1 addition & 0 deletions packages/frontend/src/pages/my-clips/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ async function create() {
type: 'string',
required: false,
multiline: true,
richSyntax: true,
label: i18n.ts.description,
},
isPublic: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ SPDX-License-Identifier: AGPL-3.0-only
<template #header><i class="ti ti-align-left"></i> {{ i18n.ts._pages.blocks.text }}</template>

<section>
<textarea v-model="text" :class="$style.textarea"></textarea>
<textarea ref="inputEl" v-model="text" :class="$style.textarea"></textarea>
</section>
</XContainer>
</template>

<script lang="ts" setup>
/* eslint-disable vue/no-mutating-props */
import { watch, ref } from 'vue';
import { watch, ref, shallowRef, onMounted, onUnmounted } from 'vue';
import XContainer from '../page-editor.container.vue';
import { i18n } from '@/i18n.js';
import { Autocomplete } from '@/scripts/autocomplete.js';

const props = defineProps<{
modelValue: any
Expand All @@ -28,14 +29,25 @@ const emit = defineEmits<{
(ev: 'update:modelValue', value: any): void;
}>();

let autocomplete: Autocomplete;

const text = ref(props.modelValue.text ?? '');
const inputEl = shallowRef<HTMLTextAreaElement | null>(null);

watch(text, () => {
emit('update:modelValue', {
...props.modelValue,
text: text.value,
});
});

onMounted(() => {
autocomplete = new Autocomplete(inputEl.value, text);
});

onUnmounted(() => {
autocomplete.detach();
});
</script>

<style lang="scss" module>
Expand Down
Loading
Loading