yumechi-no-kuni/packages/frontend/src/pages/page-editor/els/page-editor.el.note.vue

61 lines
2 KiB
Vue
Raw Normal View History

<!--
SPDX-FileCopyrightText: syuilo and other misskey contributors
SPDX-License-Identifier: AGPL-3.0-only
-->
2020-11-14 22:42:04 -06:00
<template>
<!-- eslint-disable vue/no-mutating-props -->
2021-11-19 04:36:12 -06:00
<XContainer :draggable="true" @remove="() => $emit('remove')">
2023-04-01 00:01:57 -05:00
<template #header><i class="ti ti-note"></i> {{ i18n.ts._pages.blocks.note }}</template>
2020-11-14 22:42:04 -06:00
<section style="padding: 0 16px 0 16px;">
2021-08-06 08:29:19 -05:00
<MkInput v-model="id">
2023-04-01 00:01:57 -05:00
<template #label>{{ i18n.ts._pages.blocks._note.id }}</template>
<template #caption>{{ i18n.ts._pages.blocks._note.idDescription }}</template>
2020-11-14 22:42:04 -06:00
</MkInput>
2023-04-01 00:01:57 -05:00
<MkSwitch v-model="props.modelValue.detailed"><span>{{ i18n.ts._pages.blocks._note.detailed }}</span></MkSwitch>
2020-11-14 22:42:04 -06:00
2023-03-31 00:14:30 -05:00
<MkNote v-if="note && !props.modelValue.detailed" :key="note.id + ':normal'" v-model:note="note" style="margin-bottom: 16px;"/>
<MkNoteDetailed v-if="note && props.modelValue.detailed" :key="note.id + ':detail'" v-model:note="note" style="margin-bottom: 16px;"/>
2020-11-14 22:42:04 -06:00
</section>
</XContainer>
</template>
<script lang="ts" setup>
/* eslint-disable vue/no-mutating-props */
import { watch, ref } from 'vue';
import * as Misskey from 'misskey-js';
2020-11-14 22:42:04 -06:00
import XContainer from '../page-editor.container.vue';
2023-01-07 00:09:46 -06:00
import MkInput from '@/components/MkInput.vue';
2023-01-06 23:59:54 -06:00
import MkSwitch from '@/components/MkSwitch.vue';
2023-03-31 00:14:30 -05:00
import MkNote from '@/components/MkNote.vue';
import MkNoteDetailed from '@/components/MkNoteDetailed.vue';
import { misskeyApi } from '@/scripts/misskey-api.js';
2023-09-19 02:37:43 -05:00
import { i18n } from '@/i18n.js';
2020-11-14 22:42:04 -06:00
2022-12-23 20:57:06 -06:00
const props = defineProps<{
modelValue: any
}>();
const emit = defineEmits<{
(ev: 'update:modelValue', value: any): void;
}>();
2020-11-14 22:42:04 -06:00
const id = ref<any>(props.modelValue.note);
const note = ref<Misskey.entities.Note | null>(null);
2020-11-14 22:42:04 -06:00
watch(id, async () => {
if (id.value && (id.value.startsWith('http://') || id.value.startsWith('https://'))) {
id.value = (id.value.endsWith('/') ? id.value.slice(0, -1) : id.value).split('/').pop();
}
2020-11-14 22:42:04 -06:00
emit('update:modelValue', {
...props.modelValue,
note: id.value,
});
note.value = await misskeyApi('notes/show', { noteId: id.value });
}, {
immediate: true,
2020-11-14 22:42:04 -06:00
});
</script>