2023-07-27 05:31:52 +00:00
|
|
|
<!--
|
|
|
|
SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2022-06-20 10:49:51 +00:00
|
|
|
<template>
|
|
|
|
<MkStickyContainer>
|
2022-07-05 02:21:59 +00:00
|
|
|
<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>
|
2023-11-03 22:20:53 +00:00
|
|
|
<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">
|
2022-06-20 10:49:51 +00:00
|
|
|
<template #prefix>{{ url }}/@{{ 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>
|
2021-04-10 03:40:50 +00:00
|
|
|
</div>
|
2019-04-29 00:11:57 +00:00
|
|
|
|
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"/>
|
2019-04-29 00:11:57 +00:00
|
|
|
|
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>
|
2021-04-10 03:40:50 +00:00
|
|
|
</div>
|
2022-06-20 10:49:51 +00:00
|
|
|
</MkSpacer>
|
|
|
|
</MkStickyContainer>
|
2019-04-29 00:11:57 +00:00
|
|
|
</template>
|
|
|
|
|
2022-06-20 08:38:49 +00:00
|
|
|
<script lang="ts" setup>
|
2023-02-16 14:09:41 +00:00
|
|
|
import { computed, provide, watch } from 'vue';
|
2020-01-29 19:37:25 +00:00
|
|
|
import { v4 as uuid } from 'uuid';
|
2019-05-02 08:55:59 +00:00
|
|
|
import XBlocks from './page-editor.blocks.vue';
|
2022-09-06 09:21:49 +00:00
|
|
|
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 { url } from '@/config.js';
|
|
|
|
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';
|
2022-06-20 08:38:49 +00:00
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
initPageId?: string;
|
|
|
|
initPageName?: string;
|
|
|
|
initUser?: string;
|
|
|
|
}>();
|
|
|
|
|
|
|
|
let tab = $ref('settings');
|
|
|
|
let author = $ref($i);
|
|
|
|
let readonly = $ref(false);
|
|
|
|
let page = $ref(null);
|
|
|
|
let pageId = $ref(null);
|
|
|
|
let currentName = $ref(null);
|
|
|
|
let title = $ref('');
|
|
|
|
let summary = $ref(null);
|
|
|
|
let name = $ref(Date.now().toString());
|
|
|
|
let eyeCatchingImage = $ref(null);
|
|
|
|
let eyeCatchingImageId = $ref(null);
|
|
|
|
let font = $ref('sans-serif');
|
|
|
|
let content = $ref([]);
|
|
|
|
let alignCenter = $ref(false);
|
|
|
|
let hideTitleWhenPinned = $ref(false);
|
|
|
|
|
|
|
|
provide('readonly', readonly);
|
|
|
|
provide('getPageBlockList', getPageBlockList);
|
|
|
|
|
|
|
|
watch($$(eyeCatchingImageId), async () => {
|
|
|
|
if (eyeCatchingImageId == null) {
|
|
|
|
eyeCatchingImage = null;
|
|
|
|
} else {
|
|
|
|
eyeCatchingImage = await os.api('drive/files/show', {
|
|
|
|
fileId: eyeCatchingImageId,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
function getSaveOptions() {
|
|
|
|
return {
|
2022-06-21 05:12:39 +00:00
|
|
|
title: title.trim(),
|
|
|
|
name: name.trim(),
|
|
|
|
summary: summary,
|
|
|
|
font: font,
|
2022-12-24 02:57:06 +00:00
|
|
|
script: '',
|
2022-06-21 05:12:39 +00:00
|
|
|
hideTitleWhenPinned: hideTitleWhenPinned,
|
|
|
|
alignCenter: alignCenter,
|
|
|
|
content: content,
|
2022-12-24 02:57:06 +00:00
|
|
|
variables: [],
|
2022-06-21 05:12:39 +00:00
|
|
|
eyeCatchingImageId: eyeCatchingImageId,
|
2022-06-20 08:38:49 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function save() {
|
2022-06-21 05:12:39 +00:00
|
|
|
const options = getSaveOptions();
|
2022-06-20 08:38:49 +00:00
|
|
|
|
|
|
|
const onError = err => {
|
2022-07-05 02:21:59 +00:00
|
|
|
if (err.id === '3d81ceae-475f-4600-b2a8-2bc116157532') {
|
|
|
|
if (err.info.param === 'name') {
|
2022-06-20 08:38:49 +00:00
|
|
|
os.alert({
|
|
|
|
type: 'error',
|
|
|
|
title: i18n.ts._pages.invalidNameTitle,
|
|
|
|
text: i18n.ts._pages.invalidNameText,
|
2019-04-29 00:11:57 +00:00
|
|
|
});
|
|
|
|
}
|
2022-07-05 02:21:59 +00:00
|
|
|
} else if (err.code === 'NAME_ALREADY_EXISTS') {
|
2022-06-20 08:38:49 +00:00
|
|
|
os.alert({
|
|
|
|
type: 'error',
|
|
|
|
text: i18n.ts._pages.nameAlreadyExists,
|
2019-05-24 10:19:43 +00:00
|
|
|
});
|
|
|
|
}
|
2022-06-20 08:38:49 +00:00
|
|
|
};
|
|
|
|
|
2022-06-21 05:12:39 +00:00
|
|
|
if (pageId) {
|
|
|
|
options.pageId = pageId;
|
2022-06-20 08:38:49 +00:00
|
|
|
os.api('pages/update', options)
|
2022-12-21 02:04:49 +00:00
|
|
|
.then(page => {
|
|
|
|
currentName = name.trim();
|
|
|
|
os.alert({
|
|
|
|
type: 'success',
|
|
|
|
text: i18n.ts._pages.updated,
|
|
|
|
});
|
|
|
|
}).catch(onError);
|
2022-06-20 08:38:49 +00:00
|
|
|
} else {
|
|
|
|
os.api('pages/create', options)
|
2022-12-21 02:04:49 +00:00
|
|
|
.then(created => {
|
|
|
|
pageId = created.id;
|
|
|
|
currentName = name.trim();
|
|
|
|
os.alert({
|
|
|
|
type: 'success',
|
|
|
|
text: i18n.ts._pages.created,
|
|
|
|
});
|
|
|
|
mainRouter.push(`/pages/edit/${pageId}`);
|
|
|
|
}).catch(onError);
|
2022-06-20 08:38:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function del() {
|
|
|
|
os.confirm({
|
|
|
|
type: 'warning',
|
|
|
|
text: i18n.t('removeAreYouSure', { x: title.trim() }),
|
|
|
|
}).then(({ canceled }) => {
|
|
|
|
if (canceled) return;
|
|
|
|
os.api('pages/delete', {
|
|
|
|
pageId: pageId,
|
|
|
|
}).then(() => {
|
|
|
|
os.alert({
|
|
|
|
type: 'success',
|
|
|
|
text: i18n.ts._pages.deleted,
|
2019-04-29 00:11:57 +00:00
|
|
|
});
|
2022-06-20 08:38:49 +00:00
|
|
|
mainRouter.push('/pages');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function duplicate() {
|
2022-06-21 05:12:39 +00:00
|
|
|
title = title + ' - copy';
|
|
|
|
name = name + '-copy';
|
|
|
|
os.api('pages/create', getSaveOptions()).then(created => {
|
|
|
|
pageId = created.id;
|
|
|
|
currentName = name.trim();
|
2022-06-20 08:38:49 +00:00
|
|
|
os.alert({
|
|
|
|
type: 'success',
|
|
|
|
text: i18n.ts._pages.created,
|
|
|
|
});
|
|
|
|
mainRouter.push(`/pages/edit/${pageId}`);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
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(),
|
2022-06-20 08:38:49 +00:00
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
|
|
|
|
const id = uuid();
|
2022-06-21 05:12:39 +00:00
|
|
|
content.push({ id, type });
|
2022-06-20 08:38:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 },
|
|
|
|
];
|
2022-06-20 08:38:49 +00:00
|
|
|
}
|
|
|
|
|
2022-07-05 02:21:59 +00:00
|
|
|
function setEyeCatchingImage(img) {
|
|
|
|
selectFile(img.currentTarget ?? img.target, null).then(file => {
|
2022-06-20 08:38:49 +00:00
|
|
|
eyeCatchingImageId = file.id;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeEyeCatchingImage() {
|
2022-06-21 05:12:39 +00:00
|
|
|
eyeCatchingImageId = null;
|
2022-06-20 08:38:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function init() {
|
|
|
|
if (props.initPageId) {
|
|
|
|
page = await os.api('pages/show', {
|
|
|
|
pageId: props.initPageId,
|
|
|
|
});
|
|
|
|
} else if (props.initPageName && props.initUser) {
|
|
|
|
page = await os.api('pages/show', {
|
|
|
|
name: props.initPageName,
|
|
|
|
username: props.initUser,
|
|
|
|
});
|
|
|
|
readonly = true;
|
|
|
|
}
|
2019-04-29 00:11:57 +00:00
|
|
|
|
2022-06-20 08:38:49 +00:00
|
|
|
if (page) {
|
|
|
|
author = page.user;
|
|
|
|
pageId = page.id;
|
|
|
|
title = page.title;
|
|
|
|
name = page.name;
|
|
|
|
currentName = page.name;
|
|
|
|
summary = page.summary;
|
|
|
|
font = page.font;
|
|
|
|
hideTitleWhenPinned = page.hideTitleWhenPinned;
|
|
|
|
alignCenter = page.alignCenter;
|
|
|
|
content = page.content;
|
|
|
|
eyeCatchingImageId = page.eyeCatchingImageId;
|
|
|
|
} else {
|
|
|
|
const id = uuid();
|
|
|
|
content = [{
|
|
|
|
id,
|
|
|
|
type: 'text',
|
|
|
|
text: 'Hello World!',
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
}
|
2019-04-29 00:11:57 +00:00
|
|
|
|
2022-06-20 08:38:49 +00:00
|
|
|
init();
|
2019-04-29 00:11:57 +00:00
|
|
|
|
2022-06-20 08:38:49 +00:00
|
|
|
const headerActions = $computed(() => []);
|
2019-04-29 00:11:57 +00:00
|
|
|
|
2022-06-20 10:49:51 +00:00
|
|
|
const headerTabs = $computed(() => [{
|
2022-06-22 07:29:21 +00:00
|
|
|
key: 'settings',
|
2022-06-20 10:49:51 +00:00
|
|
|
title: i18n.ts._pages.pageSetting,
|
2023-11-03 22:20:53 +00:00
|
|
|
icon: 'ph-gear ph-bold ph-lg',
|
2022-06-20 10:49:51 +00:00
|
|
|
}, {
|
2022-06-22 07:29:21 +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
|
|
|
|
2022-06-20 08:38:49 +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) {
|
2022-06-20 08:38:49 +00:00
|
|
|
title = i18n.ts._pages.readPage;
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
title: title,
|
2023-09-30 19:53:52 +00:00
|
|
|
icon: 'ph-pencil ph-bold ph-lg',
|
2022-12-21 02:04:49 +00:00
|
|
|
};
|
2022-06-20 08:38:49 +00:00
|
|
|
}));
|
2019-04-29 00:11:57 +00:00
|
|
|
</script>
|
|
|
|
|
2022-12-24 02:57:06 +00:00
|
|
|
<style lang="scss" module>
|
|
|
|
.contents {
|
|
|
|
&:global {
|
|
|
|
> .add {
|
|
|
|
margin: 16px auto 0 auto;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
|
2022-12-27 09:29:39 +00:00
|
|
|
<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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-29 19:37:25 +00:00
|
|
|
.gwbmwxkm {
|
2020-10-17 11:12:00 +00:00
|
|
|
position: relative;
|
2020-01-29 19:37:25 +00:00
|
|
|
|
|
|
|
> 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);
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2021-04-20 14:22:59 +00:00
|
|
|
> i {
|
2020-01-29 19:37:25 +00:00
|
|
|
margin-right: 6px;
|
|
|
|
}
|
2019-04-29 00:11:57 +00:00
|
|
|
|
2020-01-29 19:37:25 +00:00
|
|
|
&:empty {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
}
|
2019-04-29 00:11:57 +00:00
|
|
|
|
2020-01-29 19:37:25 +00:00
|
|
|
> .buttons {
|
|
|
|
position: absolute;
|
|
|
|
z-index: 2;
|
|
|
|
top: 0;
|
|
|
|
right: 0;
|
|
|
|
|
|
|
|
> button {
|
|
|
|
padding: 0;
|
|
|
|
width: 42px;
|
|
|
|
font-size: 0.9em;
|
|
|
|
line-height: 42px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-29 00:11:57 +00:00
|
|
|
|
2020-01-29 19:37:25 +00:00
|
|
|
> section {
|
|
|
|
padding: 0 32px 32px 32px;
|
2019-04-29 00:11:57 +00:00
|
|
|
|
2020-01-29 19:37:25 +00:00
|
|
|
@media (max-width: 500px) {
|
|
|
|
padding: 0 16px 16px 16px;
|
|
|
|
}
|
2019-04-29 05:46:35 +00:00
|
|
|
|
2020-01-29 19:37:25 +00:00
|
|
|
> .view {
|
|
|
|
display: inline-block;
|
|
|
|
margin: 16px 0 0 0;
|
|
|
|
font-size: 14px;
|
|
|
|
}
|
2019-04-29 00:11:57 +00:00
|
|
|
|
2020-01-29 19:37:25 +00:00
|
|
|
> .content {
|
|
|
|
margin-bottom: 16px;
|
|
|
|
}
|
2019-04-29 00:11:57 +00:00
|
|
|
|
2020-01-29 19:37:25 +00:00
|
|
|
> .eyeCatch {
|
|
|
|
margin-bottom: 16px;
|
2019-04-29 00:11:57 +00:00
|
|
|
|
2020-01-29 19:37:25 +00:00
|
|
|
> div {
|
|
|
|
> img {
|
|
|
|
max-width: 100%;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-29 00:11:57 +00:00
|
|
|
|
2020-01-29 19:37:25 +00:00
|
|
|
.qmuvgica {
|
2021-10-11 16:04:50 +00:00
|
|
|
padding: 16px;
|
2019-04-29 00:11:57 +00:00
|
|
|
|
2020-01-29 19:37:25 +00:00
|
|
|
> .variables {
|
|
|
|
margin-bottom: 16px;
|
|
|
|
}
|
2019-04-29 00:11:57 +00:00
|
|
|
|
2020-01-29 19:37:25 +00:00
|
|
|
> .add {
|
|
|
|
margin-bottom: 16px;
|
|
|
|
}
|
|
|
|
}
|
2019-04-29 00:11:57 +00:00
|
|
|
</style>
|