mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 05:14:54 +00:00
refactor(editor): remove assertExists (#10615)
This commit is contained in:
@@ -11,7 +11,6 @@ import { EMBED_CARD_HEIGHT } from '@blocksuite/affine-shared/consts';
|
||||
import { NotificationProvider } from '@blocksuite/affine-shared/services';
|
||||
import { matchModels, SpecProvider } from '@blocksuite/affine-shared/utils';
|
||||
import { BlockStdScope } from '@blocksuite/block-std';
|
||||
import { assertExists } from '@blocksuite/global/utils';
|
||||
import {
|
||||
type BlockModel,
|
||||
type BlockSnapshot,
|
||||
@@ -36,10 +35,12 @@ export function renderLinkedDocInCard(
|
||||
card: EmbedLinkedDocBlockComponent | EmbedSyncedDocCard
|
||||
) {
|
||||
const linkedDoc = card.linkedDoc;
|
||||
assertExists(
|
||||
linkedDoc,
|
||||
`Trying to load page ${card.model.pageId} in linked page block, but the page is not found.`
|
||||
);
|
||||
if (!linkedDoc) {
|
||||
console.error(
|
||||
`Trying to load page ${card.model.pageId} in linked page block, but the page is not found.`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line sonarjs/no-collapsible-if
|
||||
if ('bannerContainer' in card) {
|
||||
@@ -59,10 +60,12 @@ export function renderLinkedDocInCard(
|
||||
|
||||
async function renderPageAsBanner(card: EmbedSyncedDocCard) {
|
||||
const linkedDoc = card.linkedDoc;
|
||||
assertExists(
|
||||
linkedDoc,
|
||||
`Trying to load page ${card.model.pageId} in linked page block, but the page is not found.`
|
||||
);
|
||||
if (!linkedDoc) {
|
||||
console.error(
|
||||
`Trying to load page ${card.model.pageId} in linked page block, but the page is not found.`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const notes = getNotesFromDoc(linkedDoc);
|
||||
if (!notes) {
|
||||
@@ -126,10 +129,12 @@ async function renderNoteContent(
|
||||
card.isNoteContentEmpty = true;
|
||||
|
||||
const doc = card.linkedDoc;
|
||||
assertExists(
|
||||
doc,
|
||||
`Trying to load page ${card.model.pageId} in linked page block, but the page is not found.`
|
||||
);
|
||||
if (!doc) {
|
||||
console.error(
|
||||
`Trying to load page ${card.model.pageId} in linked page block, but the page is not found.`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const notes = getNotesFromDoc(doc);
|
||||
if (!notes) {
|
||||
|
||||
@@ -4,7 +4,6 @@ import type {
|
||||
} from '@blocksuite/affine-model';
|
||||
import type { LinkPreviewerService } from '@blocksuite/affine-shared/services';
|
||||
import { isAbortError } from '@blocksuite/affine-shared/utils';
|
||||
import { assertExists } from '@blocksuite/global/utils';
|
||||
import { nothing } from 'lit';
|
||||
|
||||
import type { EmbedGithubBlockComponent } from './embed-github-block.js';
|
||||
@@ -89,8 +88,14 @@ export async function refreshEmbedGithubUrlData(
|
||||
try {
|
||||
embedGithubElement.loading = true;
|
||||
|
||||
// TODO(@mirone): remove service
|
||||
const queryUrlData = embedGithubElement.service?.queryUrlData;
|
||||
assertExists(queryUrlData);
|
||||
if (!queryUrlData) {
|
||||
console.error(
|
||||
`Trying to refresh github url data, but the queryUrlData is not found.`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const githubUrlData = await queryUrlData(embedGithubElement.model);
|
||||
({
|
||||
@@ -126,8 +131,15 @@ export async function refreshEmbedGithubStatus(
|
||||
embedGithubElement: EmbedGithubBlockComponent,
|
||||
signal?: AbortSignal
|
||||
) {
|
||||
// TODO(@mirone): remove service
|
||||
const queryApiData = embedGithubElement.service?.queryApiData;
|
||||
assertExists(queryApiData);
|
||||
if (!queryApiData) {
|
||||
console.error(
|
||||
`Trying to refresh github status, but the queryApiData is not found.`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const githubApiData = await queryApiData(embedGithubElement.model, signal);
|
||||
|
||||
if (!githubApiData.status || signal?.aborted) return;
|
||||
|
||||
@@ -35,7 +35,6 @@ import {
|
||||
GfxExtension,
|
||||
} from '@blocksuite/block-std/gfx';
|
||||
import { Bound, getCommonBound } from '@blocksuite/global/gfx';
|
||||
import { assertExists } from '@blocksuite/global/utils';
|
||||
import { type GetBlocksOptions, type Query, Text } from '@blocksuite/store';
|
||||
import { computed, signal } from '@preact/signals-core';
|
||||
import { html, nothing, type PropertyValues } from 'lit';
|
||||
@@ -284,7 +283,12 @@ export class EmbedSyncedDocBlockComponent extends EmbedBlockComponent<EmbedSynce
|
||||
const { doc, caption } = this.model;
|
||||
|
||||
const parent = doc.getParent(this.model);
|
||||
assertExists(parent);
|
||||
if (!parent) {
|
||||
console.error(
|
||||
`Trying to convert synced doc to card, but the parent is not found.`
|
||||
);
|
||||
return;
|
||||
}
|
||||
const index = parent.children.indexOf(this.model);
|
||||
|
||||
doc.addBlock(
|
||||
@@ -301,7 +305,12 @@ export class EmbedSyncedDocBlockComponent extends EmbedBlockComponent<EmbedSynce
|
||||
covertToInline = () => {
|
||||
const { doc } = this.model;
|
||||
const parent = doc.getParent(this.model);
|
||||
assertExists(parent);
|
||||
if (!parent) {
|
||||
console.error(
|
||||
`Trying to convert synced doc to inline, but the parent is not found.`
|
||||
);
|
||||
return;
|
||||
}
|
||||
const index = parent.children.indexOf(this.model);
|
||||
|
||||
const yText = new Y.Text();
|
||||
|
||||
@@ -4,7 +4,6 @@ import type {
|
||||
} from '@blocksuite/affine-model';
|
||||
import type { LinkPreviewerService } from '@blocksuite/affine-shared/services';
|
||||
import { isAbortError } from '@blocksuite/affine-shared/utils';
|
||||
import { assertExists } from '@blocksuite/global/utils';
|
||||
|
||||
import type { EmbedYoutubeBlockComponent } from './embed-youtube-block.js';
|
||||
|
||||
@@ -73,8 +72,14 @@ export async function refreshEmbedYoutubeUrlData(
|
||||
try {
|
||||
embedYoutubeElement.loading = true;
|
||||
|
||||
// TODO(@mirone): remove service
|
||||
const queryUrlData = embedYoutubeElement.service?.queryUrlData;
|
||||
assertExists(queryUrlData);
|
||||
if (!queryUrlData) {
|
||||
console.error(
|
||||
`Trying to refresh youtube url data, but the queryUrlData is not found.`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const youtubeUrlData = await queryUrlData(
|
||||
embedYoutubeElement.model,
|
||||
|
||||
Reference in New Issue
Block a user