refactor: pageBlockTypesをjson-schemaに移植
This commit is contained in:
parent
6e99fd5224
commit
02b9c7aecc
|
@ -25,7 +25,7 @@ import { packedBlockingSchema } from '@/models/json-schema/blocking.js';
|
||||||
import { packedNoteReactionSchema } from '@/models/json-schema/note-reaction.js';
|
import { packedNoteReactionSchema } from '@/models/json-schema/note-reaction.js';
|
||||||
import { packedHashtagSchema } from '@/models/json-schema/hashtag.js';
|
import { packedHashtagSchema } from '@/models/json-schema/hashtag.js';
|
||||||
import { packedInviteCodeSchema } from '@/models/json-schema/invite-code.js';
|
import { packedInviteCodeSchema } from '@/models/json-schema/invite-code.js';
|
||||||
import { packedPageSchema } from '@/models/json-schema/page.js';
|
import { packedPageSchema, packedPageBlockSchema } from '@/models/json-schema/page.js';
|
||||||
import { packedNoteFavoriteSchema } from '@/models/json-schema/note-favorite.js';
|
import { packedNoteFavoriteSchema } from '@/models/json-schema/note-favorite.js';
|
||||||
import { packedChannelSchema } from '@/models/json-schema/channel.js';
|
import { packedChannelSchema } from '@/models/json-schema/channel.js';
|
||||||
import { packedAntennaSchema } from '@/models/json-schema/antenna.js';
|
import { packedAntennaSchema } from '@/models/json-schema/antenna.js';
|
||||||
|
@ -66,6 +66,7 @@ export const refs = {
|
||||||
Hashtag: packedHashtagSchema,
|
Hashtag: packedHashtagSchema,
|
||||||
InviteCode: packedInviteCodeSchema,
|
InviteCode: packedInviteCodeSchema,
|
||||||
Page: packedPageSchema,
|
Page: packedPageSchema,
|
||||||
|
PageBlock: packedPageBlockSchema,
|
||||||
Channel: packedChannelSchema,
|
Channel: packedChannelSchema,
|
||||||
QueueCount: packedQueueCountSchema,
|
QueueCount: packedQueueCountSchema,
|
||||||
Antenna: packedAntennaSchema,
|
Antenna: packedAntennaSchema,
|
||||||
|
|
|
@ -3,6 +3,107 @@
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
const blockBaseSchema = {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
id: {
|
||||||
|
type: 'string',
|
||||||
|
optional: false, nullable: false,
|
||||||
|
},
|
||||||
|
type: {
|
||||||
|
type: 'string',
|
||||||
|
optional: false, nullable: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
const textBlockSchema = {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
...blockBaseSchema.properties,
|
||||||
|
type: {
|
||||||
|
type: 'string',
|
||||||
|
optional: false, nullable: false,
|
||||||
|
enum: ['text'],
|
||||||
|
},
|
||||||
|
text: {
|
||||||
|
type: 'string',
|
||||||
|
optional: false, nullable: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
const sectionBlockSchema = {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
...blockBaseSchema.properties,
|
||||||
|
type: {
|
||||||
|
type: 'string',
|
||||||
|
optional: false, nullable: false,
|
||||||
|
enum: ['section'],
|
||||||
|
},
|
||||||
|
title: {
|
||||||
|
type: 'string',
|
||||||
|
optional: false, nullable: false,
|
||||||
|
},
|
||||||
|
children: {
|
||||||
|
type: 'array',
|
||||||
|
optional: false, nullable: false,
|
||||||
|
items: {
|
||||||
|
type: 'object',
|
||||||
|
optional: false, nullable: false,
|
||||||
|
ref: 'PageBlock',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
const imageBlockSchema = {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
...blockBaseSchema.properties,
|
||||||
|
type: {
|
||||||
|
type: 'string',
|
||||||
|
optional: false, nullable: false,
|
||||||
|
enum: ['image'],
|
||||||
|
},
|
||||||
|
fileId: {
|
||||||
|
type: 'string',
|
||||||
|
optional: false, nullable: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
const noteBlockSchema = {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
...blockBaseSchema.properties,
|
||||||
|
type: {
|
||||||
|
type: 'string',
|
||||||
|
optional: false, nullable: false,
|
||||||
|
enum: ['note'],
|
||||||
|
},
|
||||||
|
detailed: {
|
||||||
|
type: 'boolean',
|
||||||
|
optional: false, nullable: false,
|
||||||
|
},
|
||||||
|
note: {
|
||||||
|
type: 'string',
|
||||||
|
optional: false, nullable: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
export const packedPageBlockSchema = {
|
||||||
|
type: 'object',
|
||||||
|
oneOf: [
|
||||||
|
textBlockSchema,
|
||||||
|
sectionBlockSchema,
|
||||||
|
imageBlockSchema,
|
||||||
|
noteBlockSchema,
|
||||||
|
],
|
||||||
|
} as const;
|
||||||
|
|
||||||
export const packedPageSchema = {
|
export const packedPageSchema = {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: {
|
properties: {
|
||||||
|
@ -38,6 +139,7 @@ export const packedPageSchema = {
|
||||||
items: {
|
items: {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
optional: false, nullable: false,
|
optional: false, nullable: false,
|
||||||
|
ref: 'PageBlock',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
variables: {
|
variables: {
|
||||||
|
|
|
@ -1,34 +0,0 @@
|
||||||
/*
|
|
||||||
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
|
||||||
*/
|
|
||||||
|
|
||||||
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;
|
|
|
@ -14,7 +14,6 @@ import XText from './page.text.vue';
|
||||||
import XSection from './page.section.vue';
|
import XSection from './page.section.vue';
|
||||||
import XImage from './page.image.vue';
|
import XImage from './page.image.vue';
|
||||||
import XNote from './page.note.vue';
|
import XNote from './page.note.vue';
|
||||||
import { Block } from './block.type.js';
|
|
||||||
|
|
||||||
function getComponent(type: string) {
|
function getComponent(type: string) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
@ -27,7 +26,7 @@ function getComponent(type: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
defineProps<{
|
defineProps<{
|
||||||
block: Block,
|
block: Misskey.entities.PageBlock,
|
||||||
h: number,
|
h: number,
|
||||||
page: Misskey.entities.Page,
|
page: Misskey.entities.Page,
|
||||||
}>();
|
}>();
|
||||||
|
|
|
@ -14,15 +14,19 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { ref } from 'vue';
|
import { onMounted, ref } from 'vue';
|
||||||
import * as Misskey from 'misskey-js';
|
import * as Misskey from 'misskey-js';
|
||||||
import { ImageBlock } from './block.type.js';
|
|
||||||
import MediaImage from '@/components/MkMediaImage.vue';
|
import MediaImage from '@/components/MkMediaImage.vue';
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
block: ImageBlock,
|
block: Misskey.entities.PageBlock,
|
||||||
page: Misskey.entities.Page,
|
page: Misskey.entities.Page,
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const image = ref<Misskey.entities.DriveFile>(props.page.attachedFiles.find(x => x.id === props.block.fileId));
|
const image = ref<Misskey.entities.DriveFile | null>(null);
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
image.value = props.page.attachedFiles.find(x => x.id === props.block.fileId) ?? null;
|
||||||
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -13,19 +13,19 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { onMounted, ref } from 'vue';
|
import { onMounted, ref } from 'vue';
|
||||||
import * as Misskey from 'misskey-js';
|
import * as Misskey from 'misskey-js';
|
||||||
import { NoteBlock } from './block.type.js';
|
|
||||||
import MkNote from '@/components/MkNote.vue';
|
import MkNote from '@/components/MkNote.vue';
|
||||||
import MkNoteDetailed from '@/components/MkNoteDetailed.vue';
|
import MkNoteDetailed from '@/components/MkNoteDetailed.vue';
|
||||||
import * as os from '@/os.js';
|
import * as os from '@/os.js';
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
block: NoteBlock,
|
block: Misskey.entities.PageBlock,
|
||||||
page: Misskey.entities.Page,
|
page: Misskey.entities.Page,
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const note = ref<Misskey.entities.Note | null>(null);
|
const note = ref<Misskey.entities.Note | null>(null);
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
if (props.block.note == null) return;
|
||||||
os.api('notes/show', { noteId: props.block.note })
|
os.api('notes/show', { noteId: props.block.note })
|
||||||
.then(result => {
|
.then(result => {
|
||||||
note.value = result;
|
note.value = result;
|
||||||
|
|
|
@ -25,12 +25,11 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { defineAsyncComponent } from 'vue';
|
import { defineAsyncComponent } from 'vue';
|
||||||
import * as Misskey from 'misskey-js';
|
import * as Misskey from 'misskey-js';
|
||||||
import { SectionBlock } from './block.type.js';
|
|
||||||
|
|
||||||
const XBlock = defineAsyncComponent(() => import('./page.block.vue'));
|
const XBlock = defineAsyncComponent(() => import('./page.block.vue'));
|
||||||
|
|
||||||
defineProps<{
|
defineProps<{
|
||||||
block: SectionBlock,
|
block: Misskey.entities.PageBlock,
|
||||||
h: number,
|
h: number,
|
||||||
page: Misskey.entities.Page,
|
page: Misskey.entities.Page,
|
||||||
}>();
|
}>();
|
||||||
|
|
|
@ -5,7 +5,7 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="_gaps">
|
<div class="_gaps">
|
||||||
<Mfm :text="block.text" :isNote="false"/>
|
<Mfm :text="block.text ?? ''" :isNote="false"/>
|
||||||
<MkUrlPreview v-for="url in urls" :key="url" :url="url"/>
|
<MkUrlPreview v-for="url in urls" :key="url" :url="url"/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -14,13 +14,12 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||||
import { defineAsyncComponent } from 'vue';
|
import { defineAsyncComponent } from 'vue';
|
||||||
import * as mfm from 'mfm-js';
|
import * as mfm from 'mfm-js';
|
||||||
import * as Misskey from 'misskey-js';
|
import * as Misskey from 'misskey-js';
|
||||||
import { TextBlock } from './block.type.js';
|
|
||||||
import { extractUrlFromMfm } from '@/scripts/extract-url-from-mfm.js';
|
import { extractUrlFromMfm } from '@/scripts/extract-url-from-mfm.js';
|
||||||
|
|
||||||
const MkUrlPreview = defineAsyncComponent(() => import('@/components/MkUrlPreview.vue'));
|
const MkUrlPreview = defineAsyncComponent(() => import('@/components/MkUrlPreview.vue'));
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
block: TextBlock,
|
block: Misskey.entities.PageBlock,
|
||||||
page: Misskey.entities.Page,
|
page: Misskey.entities.Page,
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
|
|
|
@ -1614,6 +1614,7 @@ declare namespace entities {
|
||||||
Hashtag,
|
Hashtag,
|
||||||
InviteCode,
|
InviteCode,
|
||||||
Page,
|
Page,
|
||||||
|
PageBlock,
|
||||||
Channel,
|
Channel,
|
||||||
QueueCount,
|
QueueCount,
|
||||||
Antenna,
|
Antenna,
|
||||||
|
@ -2462,6 +2463,9 @@ export const notificationTypes: readonly ["note", "follow", "mention", "reply",
|
||||||
// @public (undocumented)
|
// @public (undocumented)
|
||||||
type Page = components['schemas']['Page'];
|
type Page = components['schemas']['Page'];
|
||||||
|
|
||||||
|
// @public (undocumented)
|
||||||
|
type PageBlock = components['schemas']['PageBlock'];
|
||||||
|
|
||||||
// @public (undocumented)
|
// @public (undocumented)
|
||||||
type PageEvent = {
|
type PageEvent = {
|
||||||
pageId: Page['id'];
|
pageId: Page['id'];
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* version: 2023.12.2
|
* version: 2023.12.2
|
||||||
* generatedAt: 2024-01-03T10:08:26.060Z
|
* generatedAt: 2024-01-03T14:50:11.647Z
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type { SwitchCaseResponseType } from '../api.js';
|
import type { SwitchCaseResponseType } from '../api.js';
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* version: 2023.12.2
|
* version: 2023.12.2
|
||||||
* generatedAt: 2024-01-03T10:08:26.055Z
|
* generatedAt: 2024-01-03T14:50:11.643Z
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* version: 2023.12.2
|
* version: 2023.12.2
|
||||||
* generatedAt: 2024-01-03T10:08:26.052Z
|
* generatedAt: 2024-01-03T14:50:11.639Z
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { operations } from './types.js';
|
import { operations } from './types.js';
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* version: 2023.12.2
|
* version: 2023.12.2
|
||||||
* generatedAt: 2024-01-03T10:08:26.049Z
|
* generatedAt: 2024-01-03T14:50:11.637Z
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { components } from './types.js';
|
import { components } from './types.js';
|
||||||
|
@ -29,6 +29,7 @@ export type Blocking = components['schemas']['Blocking'];
|
||||||
export type Hashtag = components['schemas']['Hashtag'];
|
export type Hashtag = components['schemas']['Hashtag'];
|
||||||
export type InviteCode = components['schemas']['InviteCode'];
|
export type InviteCode = components['schemas']['InviteCode'];
|
||||||
export type Page = components['schemas']['Page'];
|
export type Page = components['schemas']['Page'];
|
||||||
|
export type PageBlock = components['schemas']['PageBlock'];
|
||||||
export type Channel = components['schemas']['Channel'];
|
export type Channel = components['schemas']['Channel'];
|
||||||
export type QueueCount = components['schemas']['QueueCount'];
|
export type QueueCount = components['schemas']['QueueCount'];
|
||||||
export type Antenna = components['schemas']['Antenna'];
|
export type Antenna = components['schemas']['Antenna'];
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* version: 2023.12.2
|
* version: 2023.12.2
|
||||||
* generatedAt: 2024-01-03T10:08:25.920Z
|
* generatedAt: 2024-01-03T14:50:11.515Z
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4012,7 +4012,7 @@ export type components = {
|
||||||
/** Format: id */
|
/** Format: id */
|
||||||
userId: string;
|
userId: string;
|
||||||
user: components['schemas']['UserLite'];
|
user: components['schemas']['UserLite'];
|
||||||
content: Record<string, never>[];
|
content: components['schemas']['PageBlock'][];
|
||||||
variables: Record<string, never>[];
|
variables: Record<string, never>[];
|
||||||
title: string;
|
title: string;
|
||||||
name: string;
|
name: string;
|
||||||
|
@ -4027,6 +4027,29 @@ export type components = {
|
||||||
likedCount: number;
|
likedCount: number;
|
||||||
isLiked?: boolean;
|
isLiked?: boolean;
|
||||||
};
|
};
|
||||||
|
PageBlock: OneOf<[{
|
||||||
|
id: string;
|
||||||
|
/** @enum {string} */
|
||||||
|
type: 'text';
|
||||||
|
text: string;
|
||||||
|
}, {
|
||||||
|
id: string;
|
||||||
|
/** @enum {string} */
|
||||||
|
type: 'section';
|
||||||
|
title: string;
|
||||||
|
children: components['schemas']['PageBlock'][];
|
||||||
|
}, {
|
||||||
|
id: string;
|
||||||
|
/** @enum {string} */
|
||||||
|
type: 'image';
|
||||||
|
fileId: string | null;
|
||||||
|
}, {
|
||||||
|
id: string;
|
||||||
|
/** @enum {string} */
|
||||||
|
type: 'note';
|
||||||
|
detailed: boolean;
|
||||||
|
note: string | null;
|
||||||
|
}]>;
|
||||||
Channel: {
|
Channel: {
|
||||||
/**
|
/**
|
||||||
* Format: id
|
* Format: id
|
||||||
|
|
Loading…
Reference in New Issue