2023-07-27 07:31:52 +02:00
|
|
|
<!--
|
|
|
|
|
SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
-->
|
|
|
|
|
|
2019-04-29 02:11:57 +02:00
|
|
|
<template>
|
2021-11-18 15:32:43 +01:00
|
|
|
<!-- eslint-disable vue/no-mutating-props -->
|
2021-11-19 11:36:12 +01:00
|
|
|
<XContainer :draggable="true" @remove="() => $emit('remove')">
|
2023-04-01 07:01:57 +02:00
|
|
|
<template #header><i class="ti ti-photo"></i> {{ i18n.ts._pages.blocks.image }}</template>
|
2019-04-29 02:11:57 +02:00
|
|
|
<template #func>
|
|
|
|
|
<button @click="choose()">
|
2023-02-14 05:17:00 +01:00
|
|
|
<i class="ti ti-folder"></i>
|
2019-04-29 02:11:57 +02:00
|
|
|
</button>
|
|
|
|
|
</template>
|
|
|
|
|
|
2023-05-14 03:21:56 +02:00
|
|
|
<section>
|
|
|
|
|
<MkDriveFileThumbnail v-if="file" style="height: 150px;" :file="file" fit="contain" @click="choose()"/>
|
2019-04-29 02:11:57 +02:00
|
|
|
</section>
|
2020-10-17 13:12:00 +02:00
|
|
|
</XContainer>
|
2019-04-29 02:11:57 +02:00
|
|
|
</template>
|
|
|
|
|
|
2022-06-18 11:39:04 +02:00
|
|
|
<script lang="ts" setup>
|
2021-11-18 15:32:43 +01:00
|
|
|
/* eslint-disable vue/no-mutating-props */
|
2023-12-07 06:42:09 +01:00
|
|
|
import { onMounted, ref } from 'vue';
|
2019-04-29 23:40:02 +02:00
|
|
|
import XContainer from '../page-editor.container.vue';
|
2022-08-30 17:24:33 +02:00
|
|
|
import MkDriveFileThumbnail from '@/components/MkDriveFileThumbnail.vue';
|
2023-09-19 09:37:43 +02:00
|
|
|
import * as os from '@/os.js';
|
|
|
|
|
import { i18n } from '@/i18n.js';
|
2019-04-29 02:11:57 +02:00
|
|
|
|
2022-12-24 03:57:06 +01:00
|
|
|
const props = defineProps<{
|
|
|
|
|
modelValue: any
|
|
|
|
|
}>();
|
|
|
|
|
|
|
|
|
|
const emit = defineEmits<{
|
|
|
|
|
(ev: 'update:modelValue', value: any): void;
|
|
|
|
|
}>();
|
2019-04-29 02:11:57 +02:00
|
|
|
|
2023-12-07 06:42:09 +01:00
|
|
|
const file = ref<any>(null);
|
2019-04-29 02:11:57 +02:00
|
|
|
|
2022-06-18 11:39:04 +02:00
|
|
|
async function choose() {
|
2023-05-08 01:52:01 +02:00
|
|
|
os.selectDriveFile(false).then((fileResponse) => {
|
2023-12-07 06:42:09 +01:00
|
|
|
file.value = fileResponse[0];
|
2022-12-24 03:57:06 +01:00
|
|
|
emit('update:modelValue', {
|
|
|
|
|
...props.modelValue,
|
2023-12-07 06:42:09 +01:00
|
|
|
fileId: file.value.id,
|
2022-12-24 03:57:06 +01:00
|
|
|
});
|
2022-06-18 11:39:04 +02:00
|
|
|
});
|
|
|
|
|
}
|
2019-04-29 02:11:57 +02:00
|
|
|
|
2022-06-18 11:39:04 +02:00
|
|
|
onMounted(async () => {
|
2022-12-24 03:57:06 +01:00
|
|
|
if (props.modelValue.fileId == null) {
|
2022-06-18 11:39:04 +02:00
|
|
|
await choose();
|
|
|
|
|
} else {
|
|
|
|
|
os.api('drive/files/show', {
|
2022-12-24 03:57:06 +01:00
|
|
|
fileId: props.modelValue.fileId,
|
2022-06-18 11:39:04 +02:00
|
|
|
}).then(fileResponse => {
|
2023-12-07 06:42:09 +01:00
|
|
|
file.value = fileResponse;
|
2022-06-18 11:39:04 +02:00
|
|
|
});
|
2019-04-29 02:11:57 +02:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
</script>
|