hippofish/packages/frontend/src/pages/page-editor/els/page-editor.el.section.vue
zyoshoka 406b4bdbe7
refactor(frontend): 非推奨となったReactivity Transformを使わないように (#12539)
* refactor(frontend): 非推奨となったReactivity Transformを使わないように

* refactor: 不要な括弧を除去

* fix: 不要なアノテーションを除去

* fix: Refの配列をrefしている部分の対応

* refactor: 不要な括弧を除去

* fix: lint

* refactor: Ref、ShallowRef、ComputedRefの変数の宣言をletからconstに置換

* fix: type error

* chore: drop reactivity transform from eslint configuration

* refactor: remove unnecessary import

* fix: 対応漏れ
2023-12-07 14:42:09 +09:00

102 lines
2.2 KiB
Vue

<!--
SPDX-FileCopyrightText: syuilo and other misskey contributors
SPDX-License-Identifier: AGPL-3.0-only
-->
<template>
<!-- eslint-disable vue/no-mutating-props -->
<XContainer :draggable="true" @remove="() => $emit('remove')">
<template #header><i class="ti ti-note"></i> {{ props.modelValue.title }}</template>
<template #func>
<button class="_button" @click="rename()">
<i class="ti ti-pencil"></i>
</button>
</template>
<section class="ilrvjyvi">
<XBlocks v-model="children" class="children"/>
<MkButton rounded class="add" @click="add()"><i class="ti ti-plus"></i></MkButton>
</section>
</XContainer>
</template>
<script lang="ts" setup>
/* eslint-disable vue/no-mutating-props */
import { defineAsyncComponent, inject, onMounted, watch, ref } from 'vue';
import { v4 as uuid } from 'uuid';
import XContainer from '../page-editor.container.vue';
import * as os from '@/os.js';
import { i18n } from '@/i18n.js';
import { deepClone } from '@/scripts/clone.js';
import MkButton from '@/components/MkButton.vue';
const XBlocks = defineAsyncComponent(() => import('../page-editor.blocks.vue'));
const props = withDefaults(defineProps<{
modelValue: any,
}>(), {
modelValue: {},
});
const emit = defineEmits<{
(ev: 'update:modelValue', value: any): void;
}>();
const children = ref(deepClone(props.modelValue.children ?? []));
watch(children, () => {
emit('update:modelValue', {
...props.modelValue,
children: children.value,
});
}, {
deep: true,
});
const getPageBlockList = inject<(any) => any>('getPageBlockList');
async function rename() {
const { canceled, result: title } = await os.inputText({
title: 'Enter title',
default: props.modelValue.title,
});
if (canceled) return;
emit('update:modelValue', {
...props.modelValue,
title,
});
}
async function add() {
const { canceled, result: type } = await os.select({
title: i18n.ts._pages.chooseBlock,
items: getPageBlockList(),
});
if (canceled) return;
const id = uuid();
children.value.push({ id, type });
}
onMounted(() => {
if (props.modelValue.title == null) {
rename();
}
});
</script>
<style lang="scss" scoped>
.ilrvjyvi {
> .children {
margin: 16px;
&:empty {
display: none;
}
}
> .add {
margin: 16px auto;
}
}
</style>