refactor
This commit is contained in:
29
packages/frontend/src/components/page/block.type.ts
Normal file
29
packages/frontend/src/components/page/block.type.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
export type BlockBase = {
|
||||
id: string;
|
||||
type: string;
|
||||
};
|
||||
|
||||
export type TextBlock = BlockBase & {
|
||||
type: 'text';
|
||||
text: string;
|
||||
};
|
||||
|
||||
export type SectionBlock = BlockBase & {
|
||||
type: 'section';
|
||||
title: string;
|
||||
children: Block[];
|
||||
};
|
||||
|
||||
export type ImageBlock = BlockBase & {
|
||||
type: 'image';
|
||||
fileId: string | null;
|
||||
};
|
||||
|
||||
export type NoteBlock = BlockBase & {
|
||||
type: 'note';
|
||||
detailed: boolean;
|
||||
note: string | null;
|
||||
};
|
||||
|
||||
export type Block =
|
||||
TextBlock | SectionBlock | ImageBlock | NoteBlock;
|
@@ -1,33 +1,19 @@
|
||||
<template>
|
||||
<component :is="'x-' + block.type" :key="block.id" :block="block" :hpml="hpml" :h="h"/>
|
||||
<component :is="'x-' + block.type" :key="block.id" :page="page" :block="block" :h="h"/>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent, PropType } from 'vue';
|
||||
<script lang="ts" setup>
|
||||
import { } from 'vue';
|
||||
import * as Misskey from 'misskey-js';
|
||||
import XText from './page.text.vue';
|
||||
import XSection from './page.section.vue';
|
||||
import XImage from './page.image.vue';
|
||||
import XNote from './page.note.vue';
|
||||
import { Hpml } from '@/scripts/hpml/evaluator';
|
||||
import { Block } from '@/scripts/hpml/block';
|
||||
import { Block } from './block.type';
|
||||
|
||||
export default defineComponent({
|
||||
components: {
|
||||
XText, XSection, XImage, XNote,
|
||||
},
|
||||
props: {
|
||||
block: {
|
||||
type: Object as PropType<Block>,
|
||||
required: true,
|
||||
},
|
||||
hpml: {
|
||||
type: Object as PropType<Hpml>,
|
||||
required: true,
|
||||
},
|
||||
h: {
|
||||
type: Number,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
defineProps<{
|
||||
block: Block,
|
||||
h: number,
|
||||
page: Misskey.entities.Page,
|
||||
}>();
|
||||
</script>
|
||||
|
@@ -5,15 +5,15 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { PropType } from 'vue';
|
||||
import { } from 'vue';
|
||||
import * as Misskey from 'misskey-js';
|
||||
import { ImageBlock } from './block.type';
|
||||
import ImgWithBlurhash from '@/components/MkImgWithBlurhash.vue';
|
||||
import { ImageBlock } from '@/scripts/hpml/block';
|
||||
import { Hpml } from '@/scripts/hpml/evaluator';
|
||||
|
||||
const props = defineProps<{
|
||||
block: PropType<ImageBlock>,
|
||||
hpml: PropType<Hpml>,
|
||||
block: ImageBlock,
|
||||
page: Misskey.entities.Page,
|
||||
}>();
|
||||
|
||||
const image = props.hpml.page.attachedFiles.find(x => x.id === props.block.fileId);
|
||||
const image = props.page.attachedFiles.find(x => x.id === props.block.fileId);
|
||||
</script>
|
||||
|
@@ -5,37 +5,25 @@
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent, onMounted, PropType, Ref, ref } from 'vue';
|
||||
<script lang="ts" setup>
|
||||
import { onMounted, Ref, ref } from 'vue';
|
||||
import * as Misskey from 'misskey-js';
|
||||
import { NoteBlock } from './block.type';
|
||||
import MkNote from '@/components/MkNote.vue';
|
||||
import MkNoteDetailed from '@/components/MkNoteDetailed.vue';
|
||||
import * as os from '@/os';
|
||||
import { NoteBlock } from '@/scripts/hpml/block';
|
||||
|
||||
export default defineComponent({
|
||||
components: {
|
||||
MkNote,
|
||||
MkNoteDetailed,
|
||||
},
|
||||
props: {
|
||||
block: {
|
||||
type: Object as PropType<NoteBlock>,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
setup(props, ctx) {
|
||||
const note: Ref<Record<string, any> | null> = ref(null);
|
||||
const props = defineProps<{
|
||||
block: NoteBlock,
|
||||
page: Misskey.entities.Page,
|
||||
}>();
|
||||
|
||||
onMounted(() => {
|
||||
os.api('notes/show', { noteId: props.block.note })
|
||||
.then(result => {
|
||||
note.value = result;
|
||||
});
|
||||
const note: Ref<Misskey.entities.Note | null> = ref(null);
|
||||
|
||||
onMounted(() => {
|
||||
os.api('notes/show', { noteId: props.block.note })
|
||||
.then(result => {
|
||||
note.value = result;
|
||||
});
|
||||
|
||||
return {
|
||||
note,
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
@@ -3,34 +3,23 @@
|
||||
<component :is="'h' + h">{{ block.title }}</component>
|
||||
|
||||
<div class="children">
|
||||
<XBlock v-for="child in block.children" :key="child.id" :block="child" :hpml="hpml" :h="h + 1"/>
|
||||
<XBlock v-for="child in block.children" :key="child.id" :page="page" :block="child" :h="h + 1"/>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent, defineAsyncComponent, PropType } from 'vue';
|
||||
import { SectionBlock } from '@/scripts/hpml/block';
|
||||
import { Hpml } from '@/scripts/hpml/evaluator';
|
||||
<script lang="ts" setup>
|
||||
import { defineAsyncComponent } from 'vue';
|
||||
import * as Misskey from 'misskey-js';
|
||||
import { SectionBlock } from './block.type';
|
||||
|
||||
export default defineComponent({
|
||||
components: {
|
||||
XBlock: defineAsyncComponent(() => import('./page.block.vue')),
|
||||
},
|
||||
props: {
|
||||
block: {
|
||||
type: Object as PropType<SectionBlock>,
|
||||
required: true,
|
||||
},
|
||||
hpml: {
|
||||
type: Object as PropType<Hpml>,
|
||||
required: true,
|
||||
},
|
||||
h: {
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
const XBlock = defineAsyncComponent(() => import('./page.block.vue'));
|
||||
|
||||
defineProps<{
|
||||
block: SectionBlock,
|
||||
h: number,
|
||||
page: Misskey.entities.Page,
|
||||
}>();
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
@@ -1,56 +1,26 @@
|
||||
<template>
|
||||
<div class="mrdgzndn">
|
||||
<Mfm :key="text" :text="text" :is-note="false" :i="$i"/>
|
||||
<Mfm :text="block.text" :is-note="false" :i="$i"/>
|
||||
<MkUrlPreview v-for="url in urls" :key="url" :url="url" class="url"/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineAsyncComponent, defineComponent, PropType } from 'vue';
|
||||
<script lang="ts" setup>
|
||||
import { defineAsyncComponent } from 'vue';
|
||||
import * as mfm from 'mfm-js';
|
||||
import { TextBlock } from '@/scripts/hpml/block';
|
||||
import { Hpml } from '@/scripts/hpml/evaluator';
|
||||
import * as Misskey from 'misskey-js';
|
||||
import { TextBlock } from './block.type';
|
||||
import { extractUrlFromMfm } from '@/scripts/extract-url-from-mfm';
|
||||
import { $i } from '@/account';
|
||||
|
||||
export default defineComponent({
|
||||
components: {
|
||||
MkUrlPreview: defineAsyncComponent(() => import('@/components/MkUrlPreview.vue')),
|
||||
},
|
||||
props: {
|
||||
block: {
|
||||
type: Object as PropType<TextBlock>,
|
||||
required: true,
|
||||
},
|
||||
hpml: {
|
||||
type: Object as PropType<Hpml>,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
text: this.hpml.interpolate(this.block.text),
|
||||
$i,
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
urls(): string[] {
|
||||
if (this.text) {
|
||||
return extractUrlFromMfm(mfm.parse(this.text));
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
'hpml.vars': {
|
||||
handler() {
|
||||
this.text = this.hpml.interpolate(this.block.text);
|
||||
},
|
||||
deep: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
const MkUrlPreview = defineAsyncComponent(() => import('@/components/MkUrlPreview.vue'));
|
||||
|
||||
const props = defineProps<{
|
||||
block: TextBlock,
|
||||
page: Misskey.entities.Page,
|
||||
}>();
|
||||
|
||||
const urls = props.block.text ? extractUrlFromMfm(mfm.parse(props.block.text)) : [];
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
@@ -1,44 +1,17 @@
|
||||
<template>
|
||||
<div v-if="hpml" class="iroscrza" :class="{ center: page.alignCenter, serif: page.font === 'serif' }">
|
||||
<XBlock v-for="child in page.content" :key="child.id" :block="child" :hpml="hpml" :h="2"/>
|
||||
<div class="iroscrza" :class="{ center: page.alignCenter, serif: page.font === 'serif' }">
|
||||
<XBlock v-for="child in page.content" :key="child.id" :block="child" :h="2"/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent, onMounted, nextTick, PropType } from 'vue';
|
||||
<script lang="ts" setup>
|
||||
import { onMounted, nextTick } from 'vue';
|
||||
import * as Misskey from 'misskey-js';
|
||||
import XBlock from './page.block.vue';
|
||||
import { Hpml } from '@/scripts/hpml/evaluator';
|
||||
import { url } from '@/config';
|
||||
import { $i } from '@/account';
|
||||
|
||||
export default defineComponent({
|
||||
components: {
|
||||
XBlock,
|
||||
},
|
||||
props: {
|
||||
page: {
|
||||
type: Object as PropType<Record<string, any>>,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
setup(props, ctx) {
|
||||
const hpml = new Hpml(props.page, {
|
||||
randomSeed: Math.random(),
|
||||
visitor: $i,
|
||||
url: url,
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
nextTick(() => {
|
||||
hpml.eval();
|
||||
});
|
||||
});
|
||||
|
||||
return {
|
||||
hpml,
|
||||
};
|
||||
},
|
||||
});
|
||||
defineProps<{
|
||||
page: Misskey.entities.Page,
|
||||
}>();
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
Reference in New Issue
Block a user