Skip to content

Commit

Permalink
Merge branch 'misskey-dev:develop' into feat/client-dev-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
yupix authored May 14, 2023
2 parents 30ff459 + 238d0fa commit 7cc555f
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 1,044 deletions.
29 changes: 29 additions & 0 deletions packages/frontend/src/components/page/block.type.ts
Original file line number Diff line number Diff line change
@@ -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;
34 changes: 10 additions & 24 deletions packages/frontend/src/components/page/page.block.vue
Original file line number Diff line number Diff line change
@@ -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>
12 changes: 6 additions & 6 deletions packages/frontend/src/components/page/page.image.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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>
40 changes: 14 additions & 26 deletions packages/frontend/src/components/page/page.note.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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);
return {
note,
};
},
onMounted(() => {
os.api('notes/show', { noteId: props.block.note })
.then(result => {
note.value = result;
});
});
</script>
37 changes: 13 additions & 24 deletions packages/frontend/src/components/page/page.section.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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';
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,
},
},
});
<script lang="ts" setup>
import { defineAsyncComponent } from 'vue';
import * as Misskey from 'misskey-js';
import { SectionBlock } from './block.type';
const XBlock = defineAsyncComponent(() => import('./page.block.vue'));
defineProps<{
block: SectionBlock,
h: number,
page: Misskey.entities.Page,
}>();
</script>

<style lang="scss" scoped>
Expand Down
56 changes: 13 additions & 43 deletions packages/frontend/src/components/page/page.text.vue
Original file line number Diff line number Diff line change
@@ -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>
Expand Down
43 changes: 8 additions & 35 deletions packages/frontend/src/components/page/page.vue
Original file line number Diff line number Diff line change
@@ -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>
Expand Down
Loading

0 comments on commit 7cc555f

Please sign in to comment.