Skip to content

Commit

Permalink
refactor: define getPageBlockList in separated file and import inst…
Browse files Browse the repository at this point in the history
…ead of provide/inject
  • Loading branch information
anatawa12 committed Aug 13, 2024
1 parent cf3a315 commit 5d48958
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
10 changes: 10 additions & 0 deletions packages/frontend/src/pages/page-editor/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { i18n } from '@/i18n.js';

export function getPageBlockList() {
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 },
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import * as os from '@/os.js';
import { i18n } from '@/i18n.js';
import { deepClone } from '@/scripts/clone.js';
import MkButton from '@/components/MkButton.vue';
import { getPageBlockList } from '@/pages/page-editor/common.js';

const XBlocks = defineAsyncComponent(() => import('../page-editor.blocks.vue'));

Expand All @@ -53,8 +54,6 @@ watch(children, () => {
deep: true,
});

const getPageBlockList = inject<() => any>('getPageBlockList');

async function rename() {
const { canceled, result: title } = await os.inputText({
title: i18n.ts._pages.enterSectionTitle,
Expand Down
11 changes: 1 addition & 10 deletions packages/frontend/src/pages/page-editor/page-editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import { i18n } from '@/i18n.js';
import { definePageMetadata } from '@/scripts/page-metadata.js';
import { $i } from '@/account.js';
import { mainRouter } from '@/router/main.js';
import { getPageBlockList } from '@/pages/page-editor/common.js';

const props = defineProps<{
initPageId?: string;
Expand All @@ -101,7 +102,6 @@ const alignCenter = ref(false);
const hideTitleWhenPinned = ref(false);

provide('readonly', readonly.value);
provide('getPageBlockList', getPageBlockList);

watch(eyeCatchingImageId, async () => {
if (eyeCatchingImageId.value == null) {
Expand Down Expand Up @@ -216,15 +216,6 @@ async function add() {
content.value.push({ id, type });
}

function getPageBlockList() {
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;
Expand Down

0 comments on commit 5d48958

Please sign in to comment.