egirlskey/packages/frontend/src/pages/page-editor/page-editor.vue

398 lines
9.6 KiB
Vue
Raw Normal View History

<!--
SPDX-FileCopyrightText: syuilo and other misskey contributors
SPDX-License-Identifier: AGPL-3.0-only
-->
2022-06-20 10:49:51 +00:00
<template>
<MkStickyContainer>
<template #header><MkPageHeader v-model:tab="tab" :actions="headerActions" :tabs="headerTabs"/></template>
2023-05-19 11:52:15 +00:00
<MkSpacer :contentMax="700">
2022-06-20 10:49:51 +00:00
<div class="jqqmcavi">
2023-09-30 19:53:52 +00:00
<MkButton v-if="pageId" class="button" inline link :to="`/@${ author.username }/pages/${ currentName }`"><i class="ph-arrow-square-out ph-bold ph-lg"></i> {{ i18n.ts._pages.viewPage }}</MkButton>
<MkButton v-if="!readonly" inline primary class="button" @click="save"><i class="ph-floppy-disk ph-bold ph-lg"></i> {{ i18n.ts.save }}</MkButton>
2023-09-30 19:53:52 +00:00
<MkButton v-if="pageId" inline class="button" @click="duplicate"><i class="ph-copy ph-bold ph-lg"></i> {{ i18n.ts.duplicate }}</MkButton>
<MkButton v-if="pageId && !readonly" inline class="button" danger @click="del"><i class="ph-trash ph-bold ph-lg"></i> {{ i18n.ts.delete }}</MkButton>
2022-06-20 10:49:51 +00:00
</div>
<div v-if="tab === 'settings'">
2023-01-06 04:40:17 +00:00
<div class="_gaps_m">
2023-01-05 12:04:56 +00:00
<MkInput v-model="title">
2023-04-01 05:01:57 +00:00
<template #label>{{ i18n.ts._pages.title }}</template>
2022-06-20 10:49:51 +00:00
</MkInput>
2023-01-05 12:04:56 +00:00
<MkInput v-model="summary">
2023-04-01 05:01:57 +00:00
<template #label>{{ i18n.ts._pages.summary }}</template>
2022-06-20 10:49:51 +00:00
</MkInput>
2023-01-05 12:04:56 +00:00
<MkInput v-model="name">
<template #prefix>@{{ author.username }}/pages/</template>
2023-04-01 05:01:57 +00:00
<template #label>{{ i18n.ts._pages.url }}</template>
2022-06-20 10:49:51 +00:00
</MkInput>
2023-04-01 05:01:57 +00:00
<MkSwitch v-model="alignCenter">{{ i18n.ts._pages.alignCenter }}</MkSwitch>
2022-06-20 10:49:51 +00:00
2023-01-05 12:04:56 +00:00
<MkSelect v-model="font">
2023-04-01 05:01:57 +00:00
<template #label>{{ i18n.ts._pages.font }}</template>
<option value="serif">{{ i18n.ts._pages.fontSerif }}</option>
<option value="sans-serif">{{ i18n.ts._pages.fontSansSerif }}</option>
2022-06-20 10:49:51 +00:00
</MkSelect>
2023-04-01 05:01:57 +00:00
<MkSwitch v-model="hideTitleWhenPinned">{{ i18n.ts._pages.hideTitleWhenPinned }}</MkSwitch>
2022-06-20 10:49:51 +00:00
<div class="eyeCatch">
2023-09-30 19:53:52 +00:00
<MkButton v-if="eyeCatchingImageId == null && !readonly" @click="setEyeCatchingImage"><i class="ph-plus ph-bold ph-lg"></i> {{ i18n.ts._pages.eyeCatchingImageSet }}</MkButton>
2022-06-20 10:49:51 +00:00
<div v-else-if="eyeCatchingImage">
<img :src="eyeCatchingImage.url" :alt="eyeCatchingImage.name" style="max-width: 100%;"/>
2023-09-30 19:53:52 +00:00
<MkButton v-if="!readonly" @click="removeEyeCatchingImage()"><i class="ph-trash ph-bold ph-lg"></i> {{ i18n.ts._pages.eyeCatchingImageRemove }}</MkButton>
2022-06-20 10:49:51 +00:00
</div>
2020-11-15 04:42:04 +00:00
</div>
</div>
</div>
2022-06-20 10:49:51 +00:00
<div v-else-if="tab === 'contents'">
2022-12-24 02:57:06 +00:00
<div :class="$style.contents">
<XBlocks v-model="content" class="content"/>
2023-09-30 19:53:52 +00:00
<MkButton v-if="!readonly" rounded class="add" @click="add()"><i class="ph-plus ph-bold ph-lg"></i></MkButton>
2022-06-20 10:49:51 +00:00
</div>
</div>
2022-06-20 10:49:51 +00:00
</MkSpacer>
</MkStickyContainer>
</template>
<script lang="ts" setup>
import { computed, provide, watch, ref } from 'vue';
import * as Misskey from 'misskey-js';
import { v4 as uuid } from 'uuid';
2019-05-02 08:55:59 +00:00
import XBlocks from './page-editor.blocks.vue';
import MkButton from '@/components/MkButton.vue';
2023-01-07 06:09:46 +00:00
import MkSelect from '@/components/MkSelect.vue';
2023-01-07 05:59:54 +00:00
import MkSwitch from '@/components/MkSwitch.vue';
2023-01-07 06:09:46 +00:00
import MkInput from '@/components/MkInput.vue';
2023-09-19 07:37:43 +00:00
import * as os from '@/os.js';
import { selectFile } from '@/scripts/select-file.js';
import { mainRouter } from '@/router.js';
import { i18n } from '@/i18n.js';
import { definePageMetadata } from '@/scripts/page-metadata.js';
import { $i } from '@/account.js';
const props = defineProps<{
initPageId?: string;
initPageName?: string;
initUser?: string;
}>();
const tab = ref('settings');
const author = ref($i);
const readonly = ref(false);
const page = ref<Misskey.entities.Page | null>(null);
const pageId = ref<string | null>(null);
const currentName = ref<string | null>(null);
const title = ref('');
const summary = ref<string | null>(null);
const name = ref(Date.now().toString());
const eyeCatchingImage = ref<Misskey.entities.DriveFile | null>(null);
const eyeCatchingImageId = ref<string | null>(null);
const font = ref('sans-serif');
const content = ref<Misskey.entities.Page['content']>([]);
const alignCenter = ref(false);
const hideTitleWhenPinned = ref(false);
provide('readonly', readonly.value);
provide('getPageBlockList', getPageBlockList);
watch(eyeCatchingImageId, async () => {
if (eyeCatchingImageId.value == null) {
eyeCatchingImage.value = null;
} else {
eyeCatchingImage.value = await os.api('drive/files/show', {
fileId: eyeCatchingImageId.value,
});
}
});
function getSaveOptions() {
return {
title: title.value.trim(),
name: name.value.trim(),
summary: summary.value,
font: font.value,
2022-12-24 02:57:06 +00:00
script: '',
hideTitleWhenPinned: hideTitleWhenPinned.value,
alignCenter: alignCenter.value,
content: content.value,
2022-12-24 02:57:06 +00:00
variables: [],
eyeCatchingImageId: eyeCatchingImageId.value,
};
}
function save() {
2022-06-21 05:12:39 +00:00
const options = getSaveOptions();
const onError = err => {
if (err.id === '3d81ceae-475f-4600-b2a8-2bc116157532') {
if (err.info.param === 'name') {
os.alert({
type: 'error',
title: i18n.ts._pages.invalidNameTitle,
text: i18n.ts._pages.invalidNameText,
});
}
} else if (err.code === 'NAME_ALREADY_EXISTS') {
os.alert({
type: 'error',
text: i18n.ts._pages.nameAlreadyExists,
2019-05-24 10:19:43 +00:00
});
}
};
if (pageId.value) {
options.pageId = pageId.value;
os.api('pages/update', options)
.then(page => {
currentName.value = name.value.trim();
os.alert({
type: 'success',
text: i18n.ts._pages.updated,
});
}).catch(onError);
} else {
os.api('pages/create', options)
.then(created => {
pageId.value = created.id;
currentName.value = name.value.trim();
os.alert({
type: 'success',
text: i18n.ts._pages.created,
});
mainRouter.push(`/pages/edit/${pageId.value}`);
}).catch(onError);
}
}
function del() {
os.confirm({
type: 'warning',
text: i18n.t('removeAreYouSure', { x: title.value.trim() }),
}).then(({ canceled }) => {
if (canceled) return;
os.api('pages/delete', {
pageId: pageId.value,
}).then(() => {
os.alert({
type: 'success',
text: i18n.ts._pages.deleted,
});
mainRouter.push('/pages');
});
});
}
function duplicate() {
title.value = title.value + ' - copy';
name.value = name.value + '-copy';
2022-06-21 05:12:39 +00:00
os.api('pages/create', getSaveOptions()).then(created => {
pageId.value = created.id;
currentName.value = name.value.trim();
os.alert({
type: 'success',
text: i18n.ts._pages.created,
});
mainRouter.push(`/pages/edit/${pageId.value}`);
});
}
async function add() {
const { canceled, result: type } = await os.select({
type: null,
title: i18n.ts._pages.chooseBlock,
2022-12-24 02:57:06 +00:00
items: getPageBlockList(),
});
if (canceled) return;
const id = uuid();
content.value.push({ id, type });
}
function getPageBlockList() {
2022-12-24 02:57:06 +00:00
return [
{ value: 'section', text: i18n.ts._pages.blocks.section },
{ value: 'text', text: i18n.ts._pages.blocks.text },
{ value: 'image', text: i18n.ts._pages.blocks.image },
{ value: 'note', text: i18n.ts._pages.blocks.note },
];
}
function setEyeCatchingImage(img) {
selectFile(img.currentTarget ?? img.target, null).then(file => {
eyeCatchingImageId.value = file.id;
});
}
function removeEyeCatchingImage() {
eyeCatchingImageId.value = null;
}
async function init() {
if (props.initPageId) {
page.value = await os.api('pages/show', {
pageId: props.initPageId,
});
} else if (props.initPageName && props.initUser) {
page.value = await os.api('pages/show', {
name: props.initPageName,
username: props.initUser,
});
readonly.value = true;
}
if (page.value) {
author.value = page.value.user;
pageId.value = page.value.id;
title.value = page.value.title;
name.value = page.value.name;
currentName.value = page.value.name;
summary.value = page.value.summary;
font.value = page.value.font;
hideTitleWhenPinned.value = page.value.hideTitleWhenPinned;
alignCenter.value = page.value.alignCenter;
content.value = page.value.content;
eyeCatchingImageId.value = page.value.eyeCatchingImageId;
} else {
const id = uuid();
content.value = [{
id,
type: 'text',
text: 'Hello World!',
}];
}
}
init();
const headerActions = computed(() => []);
const headerTabs = computed(() => [{
key: 'settings',
2022-06-20 10:49:51 +00:00
title: i18n.ts._pages.pageSetting,
icon: 'ph-gear ph-bold ph-lg',
2022-06-20 10:49:51 +00:00
}, {
key: 'contents',
2022-06-20 10:49:51 +00:00
title: i18n.ts._pages.contents,
2023-09-30 22:46:42 +00:00
icon: 'ph-note ph-bold ph-lg',
2022-06-20 10:49:51 +00:00
}]);
2020-08-21 23:03:11 +00:00
definePageMetadata(computed(() => {
let title = i18n.ts._pages.newPage;
if (props.initPageId) {
title = i18n.ts._pages.editPage;
2023-10-09 06:37:58 +00:00
} else if (props.initPageName && props.initUser) {
title = i18n.ts._pages.readPage;
}
return {
title: title,
2023-09-30 19:53:52 +00:00
icon: 'ph-pencil ph-bold ph-lg',
};
}));
</script>
2022-12-24 02:57:06 +00:00
<style lang="scss" module>
.contents {
&:global {
> .add {
margin: 16px auto 0 auto;
}
}
}
</style>
<style lang="scss" scoped>
2021-10-11 16:04:50 +00:00
.jqqmcavi {
2022-12-24 02:57:06 +00:00
margin-bottom: 16px;
2021-10-11 16:04:50 +00:00
> .button {
& + .button {
margin-left: 8px;
}
}
}
.gwbmwxkm {
Migrate to Vue3 (#6587) * Update reaction.vue * fix bug * wip * wip * wjio * wip * Revert "wip" This reverts commit e427f2160adf4e8a4147006e25a89854edab0033. * wip * wip * wip * Update init.ts * Update drive-window.vue * wip * wip * Use PascalCase for components * Use PascalCase for components * update dep * wip * wip * wip * Update init.ts * wip * Update paging.ts * Update test.vue * watch deep * wip * lint * wip * wip * wip * wip * wiop * wip * Update webpack.config.ts * alllow null poll * wip * wip * wip * wiop * UI redesign & refactor (#6714) * wip * wip * wip * wip * wip * Update drive.vue * Update word-mute.vue * wip * wip * wip * clean up * wip * Update default.vue * wip * Update notes.vue * Update mfm.ts * Update index.home.vue * Update post-form.vue * Update post-form-attaches.vue * wip * Update post-form.vue * Update sidebar.vue * wip * wip * Update index.vue * wip * Update default.vue * Update index.vue * Update index.vue * wip * Update post-form-attaches.vue * Update note.vue * wip * clean up * Update notes.vue * wip * wip * Update ja-JP.yml * wip * wip * Update index.vue * wip * wip * wip * wip * wip * wip * wip * wip * Update default.vue * wip * Update _dark.json5 * wip * wip * wip * clean up * wip * wip * Update index.vue * Update test.vue * wip * wip * fix * wip * wip * wip * wip * clena yop * wip * wip * Update store.ts * Update messaging-room.vue * Update default.widgets.vue * fix * wip * wip * Update modal.vue * wip * Update os.ts * Update os.ts * Update deck.vue * Update init.ts * wip * Update ja-JP.yml * v-sizeは単にwindowのresizeを監視するだけで良いかもしれない * Update modal.vue * wip * Update tooltip.ts * wip * wip * wip * wip * wip * Update image-viewer.vue * wip * wip * Update style.scss * Update style.scss * Update visitor.vue * wip * Update init.ts * Update init.ts * wip * wip * Update visitor.vue * Update visitor.vue * Update visitor.vue * Update visitor.vue * wip * wip * Update modal.vue * Update header.vue * Update menu.vue * Update about.vue * Update about-misskey.vue * wip * wip * Update visitor.vue * Update tooltip.ts * wip * Update drive.vue * wip * Update style.scss * Update header.vue * wip * wip * Update users.user.vue * Update announcements.vue * wip * wip * wip * Update emojis.vue * wip * Update emojis.vue * Update style.scss * Update users.vue * wip * Update style.scss * wip * Update welcome.entrance.vue * Update radio.vue * Update size.ts * Update emoji-edit-dialog.vue * wip * Update emojis.vue * wip * Update emojis.vue * Update emojis.vue * Update emojis.vue * wip * wip * wip * wip * Update file-dialog.vue * wip * wip * Update token-generate-window.vue * Update notification-setting-window.vue * wip * wip * Update _error_.vue * Update ja-JP.yml * wip * wip * Update store.ts * Update emojis.vue * Update emojis.vue * Update emojis.vue * Update announcements.vue * Update store.ts * wip * Update page-editor.vue * wip * wip * Update modal.vue * wip * Update select-file.ts * Update timeline.vue * Update emojis.vue * Update os.ts * wip * Update user-select.vue * Update mfm.ts * Update get-file-info.ts * Update drive.vue * Update init.ts * Update mfm.ts * wip * wip * Update window.vue * Update note.vue * wip * wip * Update user-info.vue * wip * wip * wip * wip * wip * Update header.vue * Update header.vue * wip * Update explore.vue * wip * wip * wip * Update webpack.config.ts * wip * wip * wip * wip * wip * wip * Update autocomplete.ts * wip * wip * wip * Update toast.vue * wip * Update post-form-dialog.vue * wip * wip * wip * wip * wip * Update users.vue * wip * Update explore.vue * wip * wip * wip * Update package.json * wip * Update icon-dialog.vue * wip * wip * Update user-preview.ts * wip * wip * wip * wip * wip * Update instance.vue * Update user-name.vue * Update federation.vue * Update instance.vue * wip * wip * Update tag.vue * wip * wip * wip * wip * wip * Update instance.vue * wip * Update os.ts * Update os.ts * wip * wip * wip * Update router.ts * wip * Update init.ts * Update note.vue * Update messages.vue * wip * wip * wip * wip * wip * google * wip * wip * wip * wip * Update theme-editor.vue * wip * wip * Update room.vue * Update channel-editor.vue * wip * Update window.vue * Update window.vue * wip * Update window.vue * Update window.vue * wip * Update menu.vue * wip * wip * wip * wip * Update messaging-room.vue * wip * Update post-form.vue * Update default.widgets.vue * Update window.vue * wip
2020-10-17 11:12:00 +00:00
position: relative;
> header {
> .title {
z-index: 1;
margin: 0;
padding: 0 16px;
line-height: 42px;
font-size: 0.9em;
font-weight: bold;
2020-04-15 15:39:21 +00:00
box-shadow: 0 1px rgba(#000, 0.07);
> i {
margin-right: 6px;
}
&:empty {
display: none;
}
}
> .buttons {
position: absolute;
z-index: 2;
top: 0;
right: 0;
> button {
padding: 0;
width: 42px;
font-size: 0.9em;
line-height: 42px;
}
}
}
> section {
padding: 0 32px 32px 32px;
@media (max-width: 500px) {
padding: 0 16px 16px 16px;
}
2019-04-29 05:46:35 +00:00
> .view {
display: inline-block;
margin: 16px 0 0 0;
font-size: 14px;
}
> .content {
margin-bottom: 16px;
}
> .eyeCatch {
margin-bottom: 16px;
> div {
> img {
max-width: 100%;
}
}
}
}
}
.qmuvgica {
2021-10-11 16:04:50 +00:00
padding: 16px;
> .variables {
margin-bottom: 16px;
}
> .add {
margin-bottom: 16px;
}
}
</style>