mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-27 10:52:40 +08:00
refactor(editor): remove block models global type (#10086)
This commit is contained in:
@@ -7,7 +7,7 @@ import {
|
||||
} from '@blocksuite/affine-shared/services';
|
||||
import {
|
||||
isInsideEdgelessEditor,
|
||||
matchFlavours,
|
||||
matchModels,
|
||||
} from '@blocksuite/affine-shared/utils';
|
||||
import { GfxControllerIdentifier } from '@blocksuite/block-std/gfx';
|
||||
|
||||
@@ -24,7 +24,7 @@ export const AttachmentDropOption = FileDropConfigExtension({
|
||||
|
||||
const maxFileSize = std.store.get(FileSizeLimitService).maxFileSize;
|
||||
|
||||
if (targetModel && !matchFlavours(targetModel, [SurfaceBlockModel])) {
|
||||
if (targetModel && !matchModels(targetModel, [SurfaceBlockModel])) {
|
||||
addSiblingAttachmentBlocks(
|
||||
std.host,
|
||||
attachmentFiles,
|
||||
|
||||
@@ -1,14 +1,5 @@
|
||||
import { DataViewBlockComponent } from './data-view-block';
|
||||
import type { DataViewBlockModel } from './data-view-model';
|
||||
|
||||
export function effects() {
|
||||
customElements.define('affine-data-view', DataViewBlockComponent);
|
||||
}
|
||||
|
||||
declare global {
|
||||
namespace BlockSuite {
|
||||
interface BlockModels {
|
||||
'affine:data-view': DataViewBlockModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,10 +8,7 @@ import {
|
||||
import { REFERENCE_NODE } from '@blocksuite/affine-shared/consts';
|
||||
import { TelemetryProvider } from '@blocksuite/affine-shared/services';
|
||||
import type { AffineTextAttributes } from '@blocksuite/affine-shared/types';
|
||||
import {
|
||||
createDefaultDoc,
|
||||
matchFlavours,
|
||||
} from '@blocksuite/affine-shared/utils';
|
||||
import { createDefaultDoc, matchModels } from '@blocksuite/affine-shared/utils';
|
||||
import { type EditorHost, ShadowlessElement } from '@blocksuite/block-std';
|
||||
import type { DetailSlotProps, SingleView } from '@blocksuite/data-view';
|
||||
import { SignalWatcher, WithDisposable } from '@blocksuite/global/utils';
|
||||
@@ -75,7 +72,7 @@ export class NoteRenderer
|
||||
note.root.children
|
||||
.find(child => child.flavour === 'affine:note')
|
||||
?.children.find(block =>
|
||||
matchFlavours(block, [
|
||||
matchModels(block, [
|
||||
ParagraphBlockModel,
|
||||
ListBlockModel,
|
||||
CodeBlockModel,
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
ParagraphBlockModel,
|
||||
} from '@blocksuite/affine-model';
|
||||
import { ThemeProvider } from '@blocksuite/affine-shared/services';
|
||||
import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
||||
import { matchModels } from '@blocksuite/affine-shared/utils';
|
||||
import type { BlockComponent } from '@blocksuite/block-std';
|
||||
import {
|
||||
BlockSelection,
|
||||
@@ -162,7 +162,7 @@ export class EdgelessTextBlockComponent extends GfxBlockComponent<EdgelessTextBl
|
||||
const firstChild = this.model.firstChild();
|
||||
if (
|
||||
!firstChild ||
|
||||
!matchFlavours(firstChild, [ListBlockModel, ParagraphBlockModel])
|
||||
!matchModels(firstChild, [ListBlockModel, ParagraphBlockModel])
|
||||
) {
|
||||
newParagraphId = this.doc.addBlock(
|
||||
'affine:paragraph',
|
||||
@@ -175,7 +175,7 @@ export class EdgelessTextBlockComponent extends GfxBlockComponent<EdgelessTextBl
|
||||
const lastChild = this.model.lastChild();
|
||||
if (
|
||||
!lastChild ||
|
||||
!matchFlavours(lastChild, [ListBlockModel, ParagraphBlockModel])
|
||||
!matchModels(lastChild, [ListBlockModel, ParagraphBlockModel])
|
||||
) {
|
||||
newParagraphId = this.doc.addBlock(
|
||||
'affine:paragraph',
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
} from '@blocksuite/affine-model';
|
||||
import { EMBED_CARD_HEIGHT } from '@blocksuite/affine-shared/consts';
|
||||
import { NotificationProvider } from '@blocksuite/affine-shared/services';
|
||||
import { matchFlavours, SpecProvider } from '@blocksuite/affine-shared/utils';
|
||||
import { matchModels, SpecProvider } from '@blocksuite/affine-shared/utils';
|
||||
import { BlockStdScope } from '@blocksuite/block-std';
|
||||
import { assertExists } from '@blocksuite/global/utils';
|
||||
import {
|
||||
@@ -71,7 +71,7 @@ async function renderPageAsBanner(card: EmbedSyncedDocCard) {
|
||||
}
|
||||
|
||||
const target = notes.flatMap(note =>
|
||||
note.children.filter(child => matchFlavours(child, [ImageBlockModel]))
|
||||
note.children.filter(child => matchModels(child, [ImageBlockModel]))
|
||||
)[0];
|
||||
|
||||
if (target) {
|
||||
@@ -142,7 +142,7 @@ async function renderNoteContent(
|
||||
|
||||
const noteChildren = notes.flatMap(note =>
|
||||
note.children.filter(model => {
|
||||
if (matchFlavours(model, allowFlavours)) {
|
||||
if (matchModels(model, allowFlavours)) {
|
||||
return true;
|
||||
}
|
||||
return filterTextModel(model);
|
||||
@@ -215,7 +215,7 @@ async function renderNoteContent(
|
||||
}
|
||||
|
||||
function filterTextModel(model: BlockModel) {
|
||||
if (matchFlavours(model, [ParagraphBlockModel, ListBlockModel])) {
|
||||
if (matchModels(model, [ParagraphBlockModel, ListBlockModel])) {
|
||||
return !!model.text?.toString().length;
|
||||
}
|
||||
return false;
|
||||
@@ -224,7 +224,7 @@ function filterTextModel(model: BlockModel) {
|
||||
export function getNotesFromDoc(doc: Store) {
|
||||
const notes = doc.root?.children.filter(
|
||||
child =>
|
||||
matchFlavours(child, [NoteBlockModel]) &&
|
||||
matchModels(child, [NoteBlockModel]) &&
|
||||
child.displayMode !== NoteDisplayMode.EdgelessOnly
|
||||
);
|
||||
|
||||
@@ -305,7 +305,7 @@ export function getDocContentWithMaxLength(doc: Store, maxlength = 500) {
|
||||
export function getTitleFromSelectedModels(selectedModels: DraftModel[]) {
|
||||
const firstBlock = selectedModels[0];
|
||||
if (
|
||||
matchFlavours(firstBlock, [ParagraphBlockModel]) &&
|
||||
matchModels(firstBlock, [ParagraphBlockModel]) &&
|
||||
firstBlock.type.startsWith('h')
|
||||
) {
|
||||
return firstBlock.text.toString();
|
||||
|
||||
@@ -24,7 +24,7 @@ import {
|
||||
cloneReferenceInfoWithoutAliases,
|
||||
isNewTabTrigger,
|
||||
isNewViewTrigger,
|
||||
matchFlavours,
|
||||
matchModels,
|
||||
referenceToNode,
|
||||
} from '@blocksuite/affine-shared/utils';
|
||||
import { BlockSelection } from '@blocksuite/block-std';
|
||||
@@ -374,7 +374,7 @@ export class EmbedLinkedDocBlockComponent extends EmbedBlockComponent<EmbedLinke
|
||||
const isLoading = this._loading;
|
||||
const isError = this.isError;
|
||||
const isEmpty = this._isDocEmpty() && this.isBannerEmpty;
|
||||
const inCanvas = matchFlavours(this.model.parent, [SurfaceBlockModel]);
|
||||
const inCanvas = matchModels(this.model.parent, [SurfaceBlockModel]);
|
||||
|
||||
const cardClassMap = classMap({
|
||||
loading: isLoading,
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
} from '@blocksuite/affine-shared/services';
|
||||
import {
|
||||
isInsideEdgelessEditor,
|
||||
matchFlavours,
|
||||
matchModels,
|
||||
} from '@blocksuite/affine-shared/utils';
|
||||
import { BlockService } from '@blocksuite/block-std';
|
||||
import { GfxControllerIdentifier } from '@blocksuite/block-std/gfx';
|
||||
@@ -26,7 +26,7 @@ export const ImageDropOption = FileDropConfigExtension({
|
||||
|
||||
const maxFileSize = std.store.get(FileSizeLimitService).maxFileSize;
|
||||
|
||||
if (targetModel && !matchFlavours(targetModel, [SurfaceBlockModel])) {
|
||||
if (targetModel && !matchModels(targetModel, [SurfaceBlockModel])) {
|
||||
addSiblingImageBlock(
|
||||
std.host,
|
||||
imageFiles,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ListBlockModel } from '@blocksuite/affine-model';
|
||||
import type { IndentContext } from '@blocksuite/affine-shared/types';
|
||||
import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
||||
import { matchModels } from '@blocksuite/affine-shared/utils';
|
||||
import { type Command, TextSelection } from '@blocksuite/block-std';
|
||||
|
||||
import { correctNumberedListsOrderToPrev } from './utils.js';
|
||||
@@ -54,7 +54,7 @@ export const canDedentListCommand: Command<
|
||||
* ccc
|
||||
*/
|
||||
const model = store.getBlock(blockId)?.model;
|
||||
if (!model || !matchFlavours(model, [ListBlockModel])) {
|
||||
if (!model || !matchModels(model, [ListBlockModel])) {
|
||||
return;
|
||||
}
|
||||
/**
|
||||
|
||||
@@ -2,7 +2,7 @@ import { ListBlockModel, ParagraphBlockModel } from '@blocksuite/affine-model';
|
||||
import type { IndentContext } from '@blocksuite/affine-shared/types';
|
||||
import {
|
||||
getNearestHeadingBefore,
|
||||
matchFlavours,
|
||||
matchModels,
|
||||
} from '@blocksuite/affine-shared/utils';
|
||||
import { type Command, TextSelection } from '@blocksuite/block-std';
|
||||
|
||||
@@ -55,7 +55,7 @@ export const canIndentListCommand: Command<
|
||||
* ccc
|
||||
*/
|
||||
const model = store.getBlock(blockId)?.model;
|
||||
if (!model || !matchFlavours(model, [ListBlockModel])) {
|
||||
if (!model || !matchModels(model, [ListBlockModel])) {
|
||||
return;
|
||||
}
|
||||
const schema = std.store.schema;
|
||||
@@ -126,7 +126,7 @@ export const indentListCommand: Command<{
|
||||
const nearestHeading = getNearestHeadingBefore(model);
|
||||
if (
|
||||
nearestHeading &&
|
||||
matchFlavours(nearestHeading, [ParagraphBlockModel]) &&
|
||||
matchModels(nearestHeading, [ParagraphBlockModel]) &&
|
||||
nearestHeading.collapsed
|
||||
) {
|
||||
store.updateBlock(nearestHeading, {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { focusTextModel } from '@blocksuite/affine-components/rich-text';
|
||||
import { ListBlockModel } from '@blocksuite/affine-model';
|
||||
import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
||||
import { matchModels } from '@blocksuite/affine-shared/utils';
|
||||
import type { Command } from '@blocksuite/block-std';
|
||||
|
||||
export const listToParagraphCommand: Command<
|
||||
@@ -17,7 +17,7 @@ export const listToParagraphCommand: Command<
|
||||
const doc = std.store;
|
||||
const model = doc.getBlock(id)?.model;
|
||||
|
||||
if (!model || !matchFlavours(model, [ListBlockModel])) return false;
|
||||
if (!model || !matchModels(model, [ListBlockModel])) return false;
|
||||
|
||||
const parent = doc.getParent(model);
|
||||
if (!parent) return false;
|
||||
|
||||
@@ -2,7 +2,7 @@ import { focusTextModel } from '@blocksuite/affine-components/rich-text';
|
||||
import { ListBlockModel } from '@blocksuite/affine-model';
|
||||
import {
|
||||
getNextContinuousNumberedLists,
|
||||
matchFlavours,
|
||||
matchModels,
|
||||
} from '@blocksuite/affine-shared/utils';
|
||||
import type { Command, EditorHost } from '@blocksuite/block-std';
|
||||
|
||||
@@ -18,7 +18,7 @@ export const splitListCommand: Command<{
|
||||
const doc = host.doc;
|
||||
|
||||
const model = doc.getBlock(blockId)?.model;
|
||||
if (!model || !matchFlavours(model, [ListBlockModel])) {
|
||||
if (!model || !matchModels(model, [ListBlockModel])) {
|
||||
console.error(`block ${blockId} is not a list block`);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { ListBlockModel } from '@blocksuite/affine-model';
|
||||
import {
|
||||
getNextContinuousNumberedLists,
|
||||
matchFlavours,
|
||||
matchModels,
|
||||
} from '@blocksuite/affine-shared/utils';
|
||||
import type { BlockModel, Store } from '@blocksuite/store';
|
||||
|
||||
@@ -22,7 +22,7 @@ export function correctNumberedListsOrderToPrev(
|
||||
if (!model) return;
|
||||
|
||||
if (
|
||||
!matchFlavours(model, [ListBlockModel]) ||
|
||||
!matchModels(model, [ListBlockModel]) ||
|
||||
model.type$.value !== 'numbered'
|
||||
) {
|
||||
return;
|
||||
@@ -33,7 +33,7 @@ export function correctNumberedListsOrderToPrev(
|
||||
const previousSibling = doc.getPrev(model);
|
||||
if (
|
||||
previousSibling &&
|
||||
matchFlavours(previousSibling, [ListBlockModel]) &&
|
||||
matchModels(previousSibling, [ListBlockModel]) &&
|
||||
previousSibling.type === 'numbered'
|
||||
) {
|
||||
if (!previousSibling.order) previousSibling.order = 1;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { ListBlockModel } from '@blocksuite/affine-model';
|
||||
import {
|
||||
getNextContentBlock,
|
||||
matchFlavours,
|
||||
matchModels,
|
||||
} from '@blocksuite/affine-shared/utils';
|
||||
import { type BlockStdScope, TextSelection } from '@blocksuite/block-std';
|
||||
import type { Text } from '@blocksuite/store';
|
||||
@@ -26,7 +26,7 @@ export function forwardDelete(std: BlockStdScope): true | undefined {
|
||||
const isCollapsed = text.isCollapsed();
|
||||
const doc = std.store;
|
||||
const model = doc.getBlock(text.from.blockId)?.model;
|
||||
if (!model || !matchFlavours(model, [ListBlockModel])) return;
|
||||
if (!model || !matchModels(model, [ListBlockModel])) return;
|
||||
const isEnd = isCollapsed && text.from.index === model.text.length;
|
||||
if (!isEnd) return;
|
||||
// Has children in list
|
||||
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
getTextSelectionCommand,
|
||||
} from '@blocksuite/affine-shared/commands';
|
||||
import {
|
||||
matchFlavours,
|
||||
matchModels,
|
||||
mergeToCodeModel,
|
||||
transformModel,
|
||||
} from '@blocksuite/affine-shared/utils';
|
||||
@@ -27,7 +27,7 @@ import {
|
||||
import type { BlockModel } from '@blocksuite/store';
|
||||
|
||||
type UpdateBlockConfig = {
|
||||
flavour: BlockSuite.Flavour;
|
||||
flavour: string;
|
||||
props?: Record<string, unknown>;
|
||||
};
|
||||
|
||||
@@ -200,7 +200,7 @@ export const updateBlockType: Command<
|
||||
const newModels: BlockModel[] = [];
|
||||
blockModels.forEach(model => {
|
||||
if (
|
||||
!matchFlavours(model, [
|
||||
!matchModels(model, [
|
||||
ParagraphBlockModel,
|
||||
ListBlockModel,
|
||||
CodeBlockModel,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { NoteBlockModel, NoteDisplayMode } from '@blocksuite/affine-model';
|
||||
import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
||||
import { matchModels } from '@blocksuite/affine-shared/utils';
|
||||
import type { Command } from '@blocksuite/block-std';
|
||||
|
||||
export const changeNoteDisplayMode: Command<{
|
||||
@@ -10,8 +10,7 @@ export const changeNoteDisplayMode: Command<{
|
||||
const { std, noteId, mode, stopCapture } = ctx;
|
||||
|
||||
const noteBlockModel = std.store.getBlock(noteId)?.model;
|
||||
if (!noteBlockModel || !matchFlavours(noteBlockModel, [NoteBlockModel]))
|
||||
return;
|
||||
if (!noteBlockModel || !matchModels(noteBlockModel, [NoteBlockModel])) return;
|
||||
|
||||
const currentMode = noteBlockModel.displayMode;
|
||||
if (currentMode === mode) return;
|
||||
@@ -27,7 +26,7 @@ export const changeNoteDisplayMode: Command<{
|
||||
const parent = std.store.getParent(noteBlockModel);
|
||||
if (parent) {
|
||||
const notes = parent.children.filter(child =>
|
||||
matchFlavours(child, [NoteBlockModel])
|
||||
matchModels(child, [NoteBlockModel])
|
||||
);
|
||||
const firstEdgelessOnlyNote = notes.find(
|
||||
note => note.displayMode === NoteDisplayMode.EdgelessOnly
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { NoteBlockModel } from '@blocksuite/affine-model';
|
||||
import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
||||
import { matchModels } from '@blocksuite/affine-shared/utils';
|
||||
import type { Command } from '@blocksuite/block-std';
|
||||
|
||||
import { dedentBlock } from './dedent-block';
|
||||
@@ -21,7 +21,7 @@ export const dedentBlockToRoot: Command<{
|
||||
|
||||
let parent = store.getParent(model);
|
||||
let changed = false;
|
||||
while (parent && !matchFlavours(parent, [NoteBlockModel])) {
|
||||
while (parent && !matchModels(parent, [NoteBlockModel])) {
|
||||
if (!changed) {
|
||||
if (stopCapture) store.captureSync();
|
||||
changed = true;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { ParagraphBlockModel } from '@blocksuite/affine-model';
|
||||
import {
|
||||
calculateCollapsedSiblings,
|
||||
matchFlavours,
|
||||
matchModels,
|
||||
} from '@blocksuite/affine-shared/utils';
|
||||
import type { Command } from '@blocksuite/block-std';
|
||||
|
||||
@@ -46,7 +46,7 @@ export const dedentBlock: Command<{
|
||||
if (stopCapture) store.captureSync();
|
||||
|
||||
if (
|
||||
matchFlavours(model, [ParagraphBlockModel]) &&
|
||||
matchModels(model, [ParagraphBlockModel]) &&
|
||||
model.type.startsWith('h') &&
|
||||
model.collapsed
|
||||
) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { NoteBlockModel } from '@blocksuite/affine-model';
|
||||
import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
||||
import { matchModels } from '@blocksuite/affine-shared/utils';
|
||||
import { type Command, TextSelection } from '@blocksuite/block-std';
|
||||
|
||||
import { dedentBlockToRoot } from './dedent-block-to-root';
|
||||
@@ -31,7 +31,7 @@ export const dedentBlocksToRoot: Command<{
|
||||
for (let i = blockIds.length - 1; i >= 0; i--) {
|
||||
const model = blockIds[i];
|
||||
const parent = store.getParent(model);
|
||||
if (parent && !matchFlavours(parent, [NoteBlockModel])) {
|
||||
if (parent && !matchModels(parent, [NoteBlockModel])) {
|
||||
std.command.exec(dedentBlockToRoot, {
|
||||
blockId: model,
|
||||
stopCapture: false,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { ParagraphBlockModel } from '@blocksuite/affine-model';
|
||||
import {
|
||||
calculateCollapsedSiblings,
|
||||
matchFlavours,
|
||||
matchModels,
|
||||
} from '@blocksuite/affine-shared/utils';
|
||||
import { type Command, TextSelection } from '@blocksuite/block-std';
|
||||
|
||||
@@ -58,7 +58,7 @@ export const dedentBlocks: Command<{
|
||||
const model = store.getBlock(id)?.model;
|
||||
if (!model) return;
|
||||
if (
|
||||
matchFlavours(model, [ParagraphBlockModel]) &&
|
||||
matchModels(model, [ParagraphBlockModel]) &&
|
||||
model.type.startsWith('h') &&
|
||||
model.collapsed
|
||||
) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { ListBlockModel, ParagraphBlockModel } from '@blocksuite/affine-model';
|
||||
import {
|
||||
calculateCollapsedSiblings,
|
||||
matchFlavours,
|
||||
matchModels,
|
||||
} from '@blocksuite/affine-shared/utils';
|
||||
import type { Command } from '@blocksuite/block-std';
|
||||
|
||||
@@ -50,7 +50,7 @@ export const indentBlock: Command<{
|
||||
if (stopCapture) store.captureSync();
|
||||
|
||||
if (
|
||||
matchFlavours(model, [ParagraphBlockModel]) &&
|
||||
matchModels(model, [ParagraphBlockModel]) &&
|
||||
model.type.startsWith('h') &&
|
||||
model.collapsed
|
||||
) {
|
||||
@@ -62,7 +62,7 @@ export const indentBlock: Command<{
|
||||
|
||||
// update collapsed state of affine list
|
||||
if (
|
||||
matchFlavours(previousSibling, [ListBlockModel]) &&
|
||||
matchModels(previousSibling, [ListBlockModel]) &&
|
||||
previousSibling.collapsed
|
||||
) {
|
||||
store.updateBlock(previousSibling, {
|
||||
|
||||
@@ -2,7 +2,7 @@ import { ParagraphBlockModel } from '@blocksuite/affine-model';
|
||||
import {
|
||||
calculateCollapsedSiblings,
|
||||
getNearestHeadingBefore,
|
||||
matchFlavours,
|
||||
matchModels,
|
||||
} from '@blocksuite/affine-shared/utils';
|
||||
import { type Command, TextSelection } from '@blocksuite/block-std';
|
||||
|
||||
@@ -59,7 +59,7 @@ export const indentBlocks: Command<{
|
||||
const model = store.getBlock(id)?.model;
|
||||
if (!model) return;
|
||||
if (
|
||||
matchFlavours(model, [ParagraphBlockModel]) &&
|
||||
matchModels(model, [ParagraphBlockModel]) &&
|
||||
model.type.startsWith('h') &&
|
||||
model.collapsed
|
||||
) {
|
||||
@@ -84,7 +84,7 @@ export const indentBlocks: Command<{
|
||||
const nearestHeading = getNearestHeadingBefore(firstModel);
|
||||
if (
|
||||
nearestHeading &&
|
||||
matchFlavours(nearestHeading, [ParagraphBlockModel]) &&
|
||||
matchModels(nearestHeading, [ParagraphBlockModel]) &&
|
||||
nearestHeading.collapsed
|
||||
) {
|
||||
store.updateBlock(nearestHeading, { collapsed: false });
|
||||
@@ -105,7 +105,7 @@ export const indentBlocks: Command<{
|
||||
const nearestHeading = getNearestHeadingBefore(firstModel);
|
||||
if (
|
||||
nearestHeading &&
|
||||
matchFlavours(nearestHeading, [ParagraphBlockModel]) &&
|
||||
matchModels(nearestHeading, [ParagraphBlockModel]) &&
|
||||
nearestHeading.collapsed
|
||||
) {
|
||||
store.updateBlock(nearestHeading, { collapsed: false });
|
||||
|
||||
@@ -9,7 +9,7 @@ import { ThemeProvider } from '@blocksuite/affine-shared/services';
|
||||
import {
|
||||
getClosestBlockComponentByPoint,
|
||||
handleNativeRangeAtPoint,
|
||||
matchFlavours,
|
||||
matchModels,
|
||||
stopPropagation,
|
||||
} from '@blocksuite/affine-shared/utils';
|
||||
import {
|
||||
@@ -100,10 +100,10 @@ export class EdgelessNoteBackground extends SignalWatcher(
|
||||
|
||||
if (
|
||||
(!nearestModel.text ||
|
||||
!matchFlavours(nearestModel, [ParagraphBlockModel, ListBlockModel])) &&
|
||||
!matchModels(nearestModel, [ParagraphBlockModel, ListBlockModel])) &&
|
||||
(!siblingModel ||
|
||||
!siblingModel.text ||
|
||||
!matchFlavours(siblingModel, [ParagraphBlockModel, ListBlockModel]))
|
||||
!matchModels(siblingModel, [ParagraphBlockModel, ListBlockModel]))
|
||||
) {
|
||||
const [pId] = this.doc.addSiblingBlocks(
|
||||
nearestModel,
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
getPrevBlockCommand,
|
||||
getTextSelectionCommand,
|
||||
} from '@blocksuite/affine-shared/commands';
|
||||
import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
||||
import { matchModels } from '@blocksuite/affine-shared/utils';
|
||||
import {
|
||||
type BlockComponent,
|
||||
BlockSelection,
|
||||
@@ -155,7 +155,7 @@ export class NoteBlockService extends BlockService {
|
||||
const doc = this._std.store;
|
||||
let parent = doc.getBlock(blockId)?.model ?? null;
|
||||
while (parent) {
|
||||
if (matchFlavours(parent, [NoteBlockModel])) {
|
||||
if (matchModels(parent, [NoteBlockModel])) {
|
||||
return parent;
|
||||
}
|
||||
parent = doc.getParent(parent);
|
||||
@@ -194,7 +194,7 @@ export class NoteBlockService extends BlockService {
|
||||
}
|
||||
|
||||
if (
|
||||
!matchFlavours(nextBlock.model, [
|
||||
!matchModels(nextBlock.model, [
|
||||
ParagraphBlockModel,
|
||||
ListBlockModel,
|
||||
CodeBlockModel,
|
||||
@@ -230,7 +230,7 @@ export class NoteBlockService extends BlockService {
|
||||
|
||||
event.preventDefault();
|
||||
if (
|
||||
matchFlavours(nextBlock.model, [
|
||||
matchModels(nextBlock.model, [
|
||||
ParagraphBlockModel,
|
||||
ListBlockModel,
|
||||
CodeBlockModel,
|
||||
@@ -284,7 +284,7 @@ export class NoteBlockService extends BlockService {
|
||||
}
|
||||
|
||||
if (
|
||||
!matchFlavours(prevBlock.model, [
|
||||
!matchModels(prevBlock.model, [
|
||||
ParagraphBlockModel,
|
||||
ListBlockModel,
|
||||
CodeBlockModel,
|
||||
@@ -318,7 +318,7 @@ export class NoteBlockService extends BlockService {
|
||||
}
|
||||
|
||||
if (
|
||||
matchFlavours(prevBlock.model, [
|
||||
matchModels(prevBlock.model, [
|
||||
ParagraphBlockModel,
|
||||
ListBlockModel,
|
||||
CodeBlockModel,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { NoteBlockModel, NoteDisplayMode } from '@blocksuite/affine-model';
|
||||
import { FeatureFlagService } from '@blocksuite/affine-shared/services';
|
||||
import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
||||
import { matchModels } from '@blocksuite/affine-shared/utils';
|
||||
import type { BlockStdScope } from '@blocksuite/block-std';
|
||||
|
||||
/**
|
||||
@@ -11,7 +11,7 @@ export function isPageBlock(std: BlockStdScope, note: NoteBlockModel) {
|
||||
std.get(FeatureFlagService).getFlag('enable_page_block') &&
|
||||
note.parent?.children.find(
|
||||
child =>
|
||||
matchFlavours(child, [NoteBlockModel]) &&
|
||||
matchModels(child, [NoteBlockModel]) &&
|
||||
child.displayMode !== NoteDisplayMode.EdgelessOnly
|
||||
) === note
|
||||
);
|
||||
|
||||
@@ -2,7 +2,7 @@ import { ParagraphBlockModel } from '@blocksuite/affine-model';
|
||||
import type { IndentContext } from '@blocksuite/affine-shared/types';
|
||||
import {
|
||||
calculateCollapsedSiblings,
|
||||
matchFlavours,
|
||||
matchModels,
|
||||
} from '@blocksuite/affine-shared/utils';
|
||||
import { type Command, TextSelection } from '@blocksuite/block-std';
|
||||
|
||||
@@ -35,7 +35,7 @@ export const canDedentParagraphCommand: Command<
|
||||
}
|
||||
|
||||
const model = store.getBlock(blockId)?.model;
|
||||
if (!model || !matchFlavours(model, [ParagraphBlockModel])) {
|
||||
if (!model || !matchModels(model, [ParagraphBlockModel])) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ export const dedentParagraphCommand: Command<{
|
||||
store.captureSync();
|
||||
|
||||
if (
|
||||
matchFlavours(model, [ParagraphBlockModel]) &&
|
||||
matchModels(model, [ParagraphBlockModel]) &&
|
||||
model.type.startsWith('h') &&
|
||||
model.collapsed
|
||||
) {
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { IndentContext } from '@blocksuite/affine-shared/types';
|
||||
import {
|
||||
calculateCollapsedSiblings,
|
||||
getNearestHeadingBefore,
|
||||
matchFlavours,
|
||||
matchModels,
|
||||
} from '@blocksuite/affine-shared/utils';
|
||||
import { type Command, TextSelection } from '@blocksuite/block-std';
|
||||
|
||||
@@ -37,7 +37,7 @@ export const canIndentParagraphCommand: Command<
|
||||
}
|
||||
|
||||
const model = std.store.getBlock(blockId)?.model;
|
||||
if (!model || !matchFlavours(model, [ParagraphBlockModel])) {
|
||||
if (!model || !matchModels(model, [ParagraphBlockModel])) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ export const indentParagraphCommand: Command<{
|
||||
const nearestHeading = getNearestHeadingBefore(model);
|
||||
if (
|
||||
nearestHeading &&
|
||||
matchFlavours(nearestHeading, [ParagraphBlockModel]) &&
|
||||
matchModels(nearestHeading, [ParagraphBlockModel]) &&
|
||||
nearestHeading.collapsed
|
||||
) {
|
||||
store.updateBlock(nearestHeading, {
|
||||
@@ -105,7 +105,7 @@ export const indentParagraphCommand: Command<{
|
||||
}
|
||||
|
||||
if (
|
||||
matchFlavours(model, [ParagraphBlockModel]) &&
|
||||
matchModels(model, [ParagraphBlockModel]) &&
|
||||
model.type.startsWith('h') &&
|
||||
model.collapsed
|
||||
) {
|
||||
@@ -124,7 +124,7 @@ export const indentParagraphCommand: Command<{
|
||||
const nearestHeading = getNearestHeadingBefore(model);
|
||||
if (
|
||||
nearestHeading &&
|
||||
matchFlavours(nearestHeading, [ParagraphBlockModel]) &&
|
||||
matchModels(nearestHeading, [ParagraphBlockModel]) &&
|
||||
nearestHeading.collapsed
|
||||
) {
|
||||
store.updateBlock(nearestHeading, {
|
||||
@@ -135,7 +135,7 @@ export const indentParagraphCommand: Command<{
|
||||
|
||||
// update collapsed state of affine list
|
||||
if (
|
||||
matchFlavours(previousSibling, [ListBlockModel]) &&
|
||||
matchModels(previousSibling, [ListBlockModel]) &&
|
||||
previousSibling.collapsed
|
||||
) {
|
||||
store.updateBlock(previousSibling, {
|
||||
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
getInlineEditorByModel,
|
||||
} from '@blocksuite/affine-components/rich-text';
|
||||
import { ParagraphBlockModel } from '@blocksuite/affine-model';
|
||||
import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
||||
import { matchModels } from '@blocksuite/affine-shared/utils';
|
||||
import { type Command, TextSelection } from '@blocksuite/block-std';
|
||||
|
||||
export const splitParagraphCommand: Command<
|
||||
@@ -24,7 +24,7 @@ export const splitParagraphCommand: Command<
|
||||
if (!blockId) return;
|
||||
|
||||
const model = store.getBlock(blockId)?.model;
|
||||
if (!model || !matchFlavours(model, [ParagraphBlockModel])) return;
|
||||
if (!model || !matchModels(model, [ParagraphBlockModel])) return;
|
||||
|
||||
const inlineEditor = getInlineEditorByModel(host, model);
|
||||
const range = inlineEditor?.getInlineRange();
|
||||
@@ -43,7 +43,7 @@ export const splitParagraphCommand: Command<
|
||||
store.captureSync();
|
||||
const right = model.text.split(splitIndex, splitLength);
|
||||
const id = store.addBlock(
|
||||
model.flavour as BlockSuite.Flavour,
|
||||
model.flavour,
|
||||
{
|
||||
text: right,
|
||||
type: model.type,
|
||||
@@ -62,7 +62,7 @@ export const splitParagraphCommand: Command<
|
||||
store.captureSync();
|
||||
const right = model.text.split(splitIndex, splitLength);
|
||||
const id = store.addBlock(
|
||||
model.flavour as BlockSuite.Flavour,
|
||||
model.flavour,
|
||||
{
|
||||
text: right,
|
||||
type: model.type,
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
} from '@blocksuite/affine-model';
|
||||
import {
|
||||
calculateCollapsedSiblings,
|
||||
matchFlavours,
|
||||
matchModels,
|
||||
} from '@blocksuite/affine-shared/utils';
|
||||
import { KeymapExtension, TextSelection } from '@blocksuite/block-std';
|
||||
import { IS_MAC } from '@blocksuite/global/env';
|
||||
@@ -40,7 +40,7 @@ export const ParagraphKeymapExtension = KeymapExtension(
|
||||
|
||||
const { store } = std;
|
||||
const model = store.getBlock(text.from.blockId)?.model;
|
||||
if (!model || !matchFlavours(model, [ParagraphBlockModel])) return;
|
||||
if (!model || !matchModels(model, [ParagraphBlockModel])) return;
|
||||
|
||||
const event = ctx.get('keyboardState').raw;
|
||||
event.preventDefault();
|
||||
@@ -71,7 +71,7 @@ export const ParagraphKeymapExtension = KeymapExtension(
|
||||
const text = std.selection.find(TextSelection);
|
||||
if (!text) return;
|
||||
const model = store.getBlock(text.from.blockId)?.model;
|
||||
if (!model || !matchFlavours(model, [ParagraphBlockModel])) return;
|
||||
if (!model || !matchModels(model, [ParagraphBlockModel])) return;
|
||||
const inlineEditor = getInlineEditorByModel(
|
||||
std.host,
|
||||
text.from.blockId
|
||||
@@ -98,7 +98,7 @@ export const ParagraphKeymapExtension = KeymapExtension(
|
||||
const text = std.selection.find(TextSelection);
|
||||
if (!text) return;
|
||||
const model = store.getBlock(text.from.blockId)?.model;
|
||||
if (!model || !matchFlavours(model, [ParagraphBlockModel])) return;
|
||||
if (!model || !matchModels(model, [ParagraphBlockModel])) return;
|
||||
const inlineEditor = getInlineEditorByModel(
|
||||
std.host,
|
||||
text.from.blockId
|
||||
@@ -151,7 +151,7 @@ export const ParagraphKeymapExtension = KeymapExtension(
|
||||
|
||||
const rightText = model.text.split(range.index);
|
||||
const newId = store.addBlock(
|
||||
model.flavour as BlockSuite.Flavour,
|
||||
model.flavour,
|
||||
{ type: model.type, text: rightText },
|
||||
parent,
|
||||
index + collapsedSiblings.length + 1
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
import { EMBED_BLOCK_MODEL_LIST } from '@blocksuite/affine-shared/consts';
|
||||
import {
|
||||
getNextContentBlock,
|
||||
matchFlavours,
|
||||
matchModels,
|
||||
} from '@blocksuite/affine-shared/utils';
|
||||
import {
|
||||
BlockSelection,
|
||||
@@ -25,7 +25,7 @@ export function forwardDelete(std: BlockStdScope) {
|
||||
if (!text) return;
|
||||
const isCollapsed = text.isCollapsed();
|
||||
const model = store.getBlock(text.from.blockId)?.model;
|
||||
if (!model || !matchFlavours(model, [ParagraphBlockModel])) return;
|
||||
if (!model || !matchModels(model, [ParagraphBlockModel])) return;
|
||||
const isEnd = isCollapsed && text.from.index === model.text.length;
|
||||
if (!isEnd) return;
|
||||
const parent = store.getParent(model);
|
||||
@@ -34,7 +34,7 @@ export function forwardDelete(std: BlockStdScope) {
|
||||
const nextSibling = store.getNext(model);
|
||||
|
||||
if (
|
||||
matchFlavours(nextSibling, [
|
||||
matchModels(nextSibling, [
|
||||
AttachmentBlockModel,
|
||||
BookmarkBlockModel,
|
||||
DatabaseBlockModel,
|
||||
@@ -50,7 +50,7 @@ export function forwardDelete(std: BlockStdScope) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (matchFlavours(nextSibling, [ParagraphBlockModel, ListBlockModel])) {
|
||||
if (matchModels(nextSibling, [ParagraphBlockModel, ListBlockModel])) {
|
||||
model.text.join(nextSibling.text);
|
||||
if (nextSibling.children) {
|
||||
const parent = store.getParent(nextSibling);
|
||||
|
||||
@@ -20,7 +20,7 @@ import {
|
||||
focusTitle,
|
||||
getDocTitleInlineEditor,
|
||||
getPrevContentBlock,
|
||||
matchFlavours,
|
||||
matchModels,
|
||||
} from '@blocksuite/affine-shared/utils';
|
||||
import { BlockSelection, type EditorHost } from '@blocksuite/block-std';
|
||||
import type { BlockModel, Text } from '@blocksuite/store';
|
||||
@@ -44,7 +44,7 @@ export function mergeWithPrev(editorHost: EditorHost, model: BlockModel) {
|
||||
const parent = doc.getParent(model);
|
||||
if (!parent) return false;
|
||||
|
||||
if (matchFlavours(parent, [EdgelessTextBlockModel])) {
|
||||
if (matchModels(parent, [EdgelessTextBlockModel])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ export function mergeWithPrev(editorHost: EditorHost, model: BlockModel) {
|
||||
return handleNoPreviousSibling(editorHost, model);
|
||||
}
|
||||
|
||||
if (matchFlavours(prevBlock, [ParagraphBlockModel, ListBlockModel])) {
|
||||
if (matchModels(prevBlock, [ParagraphBlockModel, ListBlockModel])) {
|
||||
const modelIndex = parent.children.indexOf(model);
|
||||
if (
|
||||
(modelIndex === -1 || modelIndex === parent.children.length - 1) &&
|
||||
@@ -74,7 +74,7 @@ export function mergeWithPrev(editorHost: EditorHost, model: BlockModel) {
|
||||
}
|
||||
|
||||
if (
|
||||
matchFlavours(prevBlock, [
|
||||
matchModels(prevBlock, [
|
||||
AttachmentBlockModel,
|
||||
BookmarkBlockModel,
|
||||
CodeBlockModel,
|
||||
@@ -97,7 +97,7 @@ export function mergeWithPrev(editorHost: EditorHost, model: BlockModel) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (matchFlavours(parent, [DatabaseBlockModel])) {
|
||||
if (matchModels(parent, [DatabaseBlockModel])) {
|
||||
doc.deleteBlock(model);
|
||||
focusTextModel(editorHost.std, prevBlock.id, prevBlock.text?.yText.length);
|
||||
return true;
|
||||
@@ -115,7 +115,7 @@ function handleNoPreviousSibling(editorHost: EditorHost, model: ExtendedModel) {
|
||||
// Probably no title, e.g. in edgeless mode
|
||||
if (!titleEditor) {
|
||||
if (
|
||||
matchFlavours(parent, [EdgelessTextBlockModel]) ||
|
||||
matchModels(parent, [EdgelessTextBlockModel]) ||
|
||||
model.children.length > 0
|
||||
) {
|
||||
doc.deleteBlock(model, {
|
||||
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
FrameBlockModel,
|
||||
type SurfaceRefProps,
|
||||
} from '@blocksuite/affine-model';
|
||||
import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
||||
import { matchModels } from '@blocksuite/affine-shared/utils';
|
||||
import type { Command } from '@blocksuite/block-std';
|
||||
import type { BlockModel } from '@blocksuite/store';
|
||||
|
||||
@@ -41,7 +41,7 @@ export const insertSurfaceRefBlockCommand: Command<
|
||||
|
||||
if (element?.type === 'group') {
|
||||
surfaceRefProps.refFlavour = 'group';
|
||||
} else if (matchFlavours(blockModel, [FrameBlockModel])) {
|
||||
} else if (matchModels(blockModel, [FrameBlockModel])) {
|
||||
surfaceRefProps.refFlavour = 'frame';
|
||||
} else {
|
||||
console.error(`reference not found ${reference}`);
|
||||
|
||||
@@ -41,6 +41,7 @@ import {
|
||||
GfxBlockElementModel,
|
||||
GfxControllerIdentifier,
|
||||
GfxExtension,
|
||||
type GfxModel,
|
||||
} from '@blocksuite/block-std/gfx';
|
||||
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
||||
import {
|
||||
@@ -249,7 +250,7 @@ export class SurfaceRefBlockComponent extends BlockComponent<SurfaceRefBlockMode
|
||||
private readonly _previewSpec =
|
||||
SpecProvider.getInstance().getSpec('edgeless:preview');
|
||||
|
||||
private _referencedModel: BlockSuite.EdgelessModel | null = null;
|
||||
private _referencedModel: GfxModel | null = null;
|
||||
|
||||
private _referenceXYWH: SerializedXYWH | null = null;
|
||||
|
||||
@@ -321,10 +322,7 @@ export class SurfaceRefBlockComponent extends BlockComponent<SurfaceRefBlockMode
|
||||
const surfaceModel = getSurfaceBlock(this.doc);
|
||||
this._surfaceModel = surfaceModel;
|
||||
|
||||
const findReferencedModel = (): [
|
||||
BlockSuite.EdgelessModel | null,
|
||||
string,
|
||||
] => {
|
||||
const findReferencedModel = (): [GfxModel | null, string] => {
|
||||
if (!this.model.reference) return [null, this.doc.id];
|
||||
|
||||
if (this.doc.getBlock(this.model.reference)) {
|
||||
@@ -541,10 +539,7 @@ export class SurfaceRefBlockComponent extends BlockComponent<SurfaceRefBlockMode
|
||||
viewport.setViewportByBound(Bound.deserialize(this._referenceXYWH));
|
||||
}
|
||||
|
||||
private _renderMask(
|
||||
referencedModel: BlockSuite.EdgelessModel,
|
||||
flavourOrType: string
|
||||
) {
|
||||
private _renderMask(referencedModel: GfxModel, flavourOrType: string) {
|
||||
const title = 'title' in referencedModel ? referencedModel.title : '';
|
||||
|
||||
return html`
|
||||
@@ -561,7 +556,7 @@ export class SurfaceRefBlockComponent extends BlockComponent<SurfaceRefBlockMode
|
||||
`;
|
||||
}
|
||||
|
||||
private _renderRefContent(referencedModel: BlockSuite.EdgelessModel) {
|
||||
private _renderRefContent(referencedModel: GfxModel) {
|
||||
const [, , w, h] = deserializeXYWH(referencedModel.xywh);
|
||||
const flavourOrType =
|
||||
'flavour' in referencedModel
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { SurfaceBlockComponent } from './surface-block.js';
|
||||
import { SurfaceBlockVoidComponent } from './surface-block-void.js';
|
||||
import type { SurfaceBlockModel } from './surface-model.js';
|
||||
import type { SurfaceBlockService } from './surface-service.js';
|
||||
|
||||
export function effects() {
|
||||
@@ -13,8 +12,5 @@ declare global {
|
||||
interface BlockServices {
|
||||
'affine:surface': SurfaceBlockService;
|
||||
}
|
||||
interface BlockModels {
|
||||
'affine:surface': SurfaceBlockModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import { EditPropsStore } from '@blocksuite/affine-shared/services';
|
||||
import { type BlockStdScope, StdIdentifier } from '@blocksuite/block-std';
|
||||
import { GfxControllerIdentifier } from '@blocksuite/block-std/gfx';
|
||||
import {
|
||||
GfxControllerIdentifier,
|
||||
type GfxModel,
|
||||
} from '@blocksuite/block-std/gfx';
|
||||
import { type Container, createIdentifier } from '@blocksuite/global/di';
|
||||
import { type BlockModel, Extension } from '@blocksuite/store';
|
||||
|
||||
@@ -30,7 +33,7 @@ export class EdgelessCRUDExtension extends Extension {
|
||||
return this._gfx.surface as SurfaceBlockModel | null;
|
||||
}
|
||||
|
||||
deleteElements = (elements: BlockSuite.EdgelessModel[]) => {
|
||||
deleteElements = (elements: GfxModel[]) => {
|
||||
const surface = this._surface;
|
||||
if (!surface) {
|
||||
console.error('surface is not initialized');
|
||||
@@ -134,7 +137,7 @@ export class EdgelessCRUDExtension extends Extension {
|
||||
}
|
||||
};
|
||||
|
||||
getElementById(id: string): BlockSuite.EdgelessModel | null {
|
||||
getElementById(id: string): GfxModel | null {
|
||||
const surface = this._surface;
|
||||
if (!surface) {
|
||||
return null;
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
import type { NoteBlockModel } from '@blocksuite/affine-model';
|
||||
import type { GfxModel } from '@blocksuite/block-std/gfx';
|
||||
import type { BlockModel } from '@blocksuite/store';
|
||||
|
||||
import type { Connectable } from '../managers/connector-manager';
|
||||
|
||||
export function isConnectable(
|
||||
element: BlockSuite.EdgelessModel | null
|
||||
element: GfxModel | null
|
||||
): element is Connectable {
|
||||
return !!element && element.connectable;
|
||||
}
|
||||
|
||||
export function isNoteBlock(
|
||||
element: BlockModel | BlockSuite.EdgelessModel | null
|
||||
element: BlockModel | GfxModel | null
|
||||
): element is NoteBlockModel {
|
||||
return !!element && 'flavour' in element && element.flavour === 'affine:note';
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ import { Overlay } from '../renderer/overlay.js';
|
||||
import { AStarRunner } from '../utils/a-star.js';
|
||||
|
||||
export type Connectable = Exclude<
|
||||
BlockSuite.EdgelessModel,
|
||||
GfxModel,
|
||||
ConnectorElementModel | BrushElementModel | GroupElementModel
|
||||
>;
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ export function addNote(
|
||||
const doc = std.store;
|
||||
|
||||
const blockId = doc.addBlock(
|
||||
options.childFlavour as BlockSuite.Flavour,
|
||||
options.childFlavour,
|
||||
{ type: options.childType },
|
||||
noteId
|
||||
);
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
ParagraphBlockModel,
|
||||
type RootBlockModel,
|
||||
} from '@blocksuite/affine-model';
|
||||
import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
||||
import { matchModels } from '@blocksuite/affine-shared/utils';
|
||||
import { ShadowlessElement } from '@blocksuite/block-std';
|
||||
import { WithDisposable } from '@blocksuite/global/utils';
|
||||
import type { Store } from '@blocksuite/store';
|
||||
@@ -72,7 +72,7 @@ export class DocTitle extends WithDisposable(ShadowlessElement) {
|
||||
private _getOrCreateFirstPageVisibleNote() {
|
||||
const note = this._rootModel.children.find(
|
||||
(child): child is NoteBlockModel =>
|
||||
matchFlavours(child, [NoteBlockModel]) &&
|
||||
matchModels(child, [NoteBlockModel]) &&
|
||||
child.displayMode !== NoteDisplayMode.EdgelessOnly
|
||||
);
|
||||
if (note) return note;
|
||||
@@ -105,7 +105,7 @@ export class DocTitle extends WithDisposable(ShadowlessElement) {
|
||||
|
||||
const note = this._getOrCreateFirstPageVisibleNote();
|
||||
const firstText = note?.children.find(block =>
|
||||
matchFlavours(block, [
|
||||
matchModels(block, [
|
||||
ParagraphBlockModel,
|
||||
ListBlockModel,
|
||||
CodeBlockModel,
|
||||
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
type DropTarget,
|
||||
getClosestBlockComponentByPoint,
|
||||
isInsidePageEditor,
|
||||
matchFlavours,
|
||||
matchModels,
|
||||
} from '@blocksuite/affine-shared/utils';
|
||||
import {
|
||||
type BlockComponent,
|
||||
@@ -59,7 +59,7 @@ export class FileDropExtension extends LifeCycleWatcher {
|
||||
const model = element.model;
|
||||
const parent = this.std.store.getParent(model);
|
||||
|
||||
if (!matchFlavours(parent, [SurfaceBlockModel])) {
|
||||
if (!matchModels(parent, [SurfaceBlockModel])) {
|
||||
const point = this.point$.value;
|
||||
target = point && calcDropTarget(point, model, element);
|
||||
}
|
||||
@@ -75,7 +75,7 @@ export class FileDropExtension extends LifeCycleWatcher {
|
||||
if (!rootModel) return null;
|
||||
|
||||
let lastNote = rootModel.children[rootModel.children.length - 1];
|
||||
if (!lastNote || !matchFlavours(lastNote, [NoteBlockModel])) {
|
||||
if (!lastNote || !matchModels(lastNote, [NoteBlockModel])) {
|
||||
const newNoteId = this.doc.addBlock('affine:note', {}, rootModel.id);
|
||||
const newNote = this.doc.getBlock(newNoteId)?.model;
|
||||
if (!newNote) return null;
|
||||
|
||||
@@ -21,7 +21,7 @@ import {
|
||||
* which are also used for registering hotkeys for converting block flavours.
|
||||
*/
|
||||
export interface TextConversionConfig {
|
||||
flavour: BlockSuite.Flavour;
|
||||
flavour: string;
|
||||
type?: string;
|
||||
name: string;
|
||||
description?: string;
|
||||
|
||||
@@ -2,7 +2,7 @@ import { DatabaseBlockModel } from '@blocksuite/affine-model';
|
||||
import {
|
||||
asyncGetBlockComponent,
|
||||
getCurrentNativeRange,
|
||||
matchFlavours,
|
||||
matchModels,
|
||||
} from '@blocksuite/affine-shared/utils';
|
||||
import {
|
||||
type BlockStdScope,
|
||||
@@ -42,7 +42,7 @@ export function getInlineEditorByModel(
|
||||
typeof model === 'string'
|
||||
? editorHost.std.store.getBlock(model)?.model
|
||||
: model;
|
||||
if (!blockModel || matchFlavours(blockModel, [DatabaseBlockModel])) {
|
||||
if (!blockModel || matchModels(blockModel, [DatabaseBlockModel])) {
|
||||
// Not support database model since it's may be have multiple inline editor instances.
|
||||
// Support to enter the editing state through the Enter key in the database.
|
||||
return null;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { RootBlockModel } from '@blocksuite/affine-model';
|
||||
import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
||||
import { matchModels } from '@blocksuite/affine-shared/utils';
|
||||
import { type Command, TextSelection } from '@blocksuite/block-std';
|
||||
import type { Text } from '@blocksuite/store';
|
||||
|
||||
@@ -25,7 +25,7 @@ export const deleteTextCommand: Command<{
|
||||
if (!fromElement) return;
|
||||
|
||||
let fromText: Text | undefined;
|
||||
if (matchFlavours(fromElement.model, [RootBlockModel])) {
|
||||
if (matchModels(fromElement.model, [RootBlockModel])) {
|
||||
fromText = fromElement.model.title;
|
||||
} else {
|
||||
fromText = fromElement.model.text;
|
||||
|
||||
@@ -28,10 +28,7 @@ export const formatBlockCommand: Command<{
|
||||
.chain()
|
||||
.pipe(getSelectedBlocksCommand, {
|
||||
blockSelections,
|
||||
filter: el =>
|
||||
FORMAT_BLOCK_SUPPORT_FLAVOURS.includes(
|
||||
el.model.flavour as BlockSuite.Flavour
|
||||
),
|
||||
filter: el => FORMAT_BLOCK_SUPPORT_FLAVOURS.includes(el.model.flavour),
|
||||
types: ['block'],
|
||||
})
|
||||
.pipe((ctx, next) => {
|
||||
|
||||
@@ -31,9 +31,7 @@ export const formatNativeCommand: Command<{
|
||||
.filter(el => {
|
||||
const block = el.closest<BlockComponent>(`[${BLOCK_ID_ATTR}]`);
|
||||
if (block) {
|
||||
return FORMAT_NATIVE_SUPPORT_FLAVOURS.includes(
|
||||
block.model.flavour as BlockSuite.Flavour
|
||||
);
|
||||
return FORMAT_NATIVE_SUPPORT_FLAVOURS.includes(block.model.flavour);
|
||||
}
|
||||
return false;
|
||||
})
|
||||
|
||||
@@ -22,10 +22,7 @@ export const formatTextCommand: Command<{
|
||||
.chain()
|
||||
.pipe(getSelectedBlocksCommand, {
|
||||
textSelection,
|
||||
filter: el =>
|
||||
FORMAT_TEXT_SUPPORT_FLAVOURS.includes(
|
||||
el.model.flavour as BlockSuite.Flavour
|
||||
),
|
||||
filter: el => FORMAT_TEXT_SUPPORT_FLAVOURS.includes(el.model.flavour),
|
||||
types: ['text'],
|
||||
})
|
||||
.pipe((ctx, next) => {
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import { CodeBlockModel } from '@blocksuite/affine-model';
|
||||
import { BRACKET_PAIRS } from '@blocksuite/affine-shared/consts';
|
||||
import {
|
||||
createDefaultDoc,
|
||||
matchFlavours,
|
||||
} from '@blocksuite/affine-shared/utils';
|
||||
import { createDefaultDoc, matchModels } from '@blocksuite/affine-shared/utils';
|
||||
import {
|
||||
type BlockStdScope,
|
||||
TextSelection,
|
||||
@@ -29,7 +26,7 @@ export const bracketKeymap = (
|
||||
if (!textSelection) return;
|
||||
const model = doc.getBlock(textSelection.from.blockId)?.model;
|
||||
if (!model) return;
|
||||
if (!matchFlavours(model, [CodeBlockModel])) return;
|
||||
if (!matchModels(model, [CodeBlockModel])) return;
|
||||
const inlineEditor = getInlineEditorByModel(
|
||||
std.host,
|
||||
textSelection.from.blockId
|
||||
@@ -56,7 +53,7 @@ export const bracketKeymap = (
|
||||
const model = doc.getBlock(textSelection.from.blockId)?.model;
|
||||
if (!model) return;
|
||||
|
||||
const isCodeBlock = matchFlavours(model, [CodeBlockModel]);
|
||||
const isCodeBlock = matchModels(model, [CodeBlockModel]);
|
||||
// When selection is collapsed, only trigger auto complete in code block
|
||||
if (textSelection.isCollapsed() && !isCodeBlock) return;
|
||||
if (!textSelection.isInSameBlock()) return;
|
||||
|
||||
@@ -2,7 +2,7 @@ import {
|
||||
DividerBlockModel,
|
||||
ParagraphBlockModel,
|
||||
} from '@blocksuite/affine-model';
|
||||
import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
||||
import { matchModels } from '@blocksuite/affine-shared/utils';
|
||||
import type { BlockStdScope } from '@blocksuite/block-std';
|
||||
import type { BlockModel } from '@blocksuite/store';
|
||||
|
||||
@@ -16,8 +16,8 @@ export function toDivider(
|
||||
) {
|
||||
const { store: doc } = std;
|
||||
if (
|
||||
matchFlavours(model, [DividerBlockModel]) ||
|
||||
(matchFlavours(model, [ParagraphBlockModel]) && model.type === 'quote')
|
||||
matchModels(model, [DividerBlockModel]) ||
|
||||
(matchModels(model, [ParagraphBlockModel]) && model.type === 'quote')
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
type ListType,
|
||||
ParagraphBlockModel,
|
||||
} from '@blocksuite/affine-model';
|
||||
import { matchFlavours, toNumberedList } from '@blocksuite/affine-shared/utils';
|
||||
import { matchModels, toNumberedList } from '@blocksuite/affine-shared/utils';
|
||||
import type { BlockStdScope } from '@blocksuite/block-std';
|
||||
import type { BlockModel } from '@blocksuite/store';
|
||||
|
||||
@@ -17,7 +17,7 @@ export function toList(
|
||||
prefix: string,
|
||||
otherProperties?: Partial<ListProps>
|
||||
) {
|
||||
if (!matchFlavours(model, [ParagraphBlockModel])) {
|
||||
if (!matchModels(model, [ParagraphBlockModel])) {
|
||||
return;
|
||||
}
|
||||
const { store: doc } = std;
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import { CodeBlockModel, ParagraphBlockModel } from '@blocksuite/affine-model';
|
||||
import {
|
||||
isMarkdownPrefix,
|
||||
matchFlavours,
|
||||
} from '@blocksuite/affine-shared/utils';
|
||||
import { isMarkdownPrefix, matchModels } from '@blocksuite/affine-shared/utils';
|
||||
import { type BlockStdScope, TextSelection } from '@blocksuite/block-std';
|
||||
|
||||
import { getInlineEditorByModel } from '../dom.js';
|
||||
@@ -32,10 +29,10 @@ export function markdownInput(
|
||||
const prefixText = getPrefixText(inline);
|
||||
if (!isMarkdownPrefix(prefixText)) return;
|
||||
|
||||
const isParagraph = matchFlavours(model, [ParagraphBlockModel]);
|
||||
const isParagraph = matchModels(model, [ParagraphBlockModel]);
|
||||
const isHeading = isParagraph && model.type.startsWith('h');
|
||||
const isParagraphQuoteBlock = isParagraph && model.type === 'quote';
|
||||
const isCodeBlock = matchFlavours(model, [CodeBlockModel]);
|
||||
const isCodeBlock = matchModels(model, [CodeBlockModel]);
|
||||
if (isHeading || isParagraphQuoteBlock || isCodeBlock) return;
|
||||
|
||||
const lineInfo = inline.getLine(range.index);
|
||||
|
||||
@@ -2,7 +2,7 @@ import {
|
||||
ParagraphBlockModel,
|
||||
type ParagraphType,
|
||||
} from '@blocksuite/affine-model';
|
||||
import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
||||
import { matchModels } from '@blocksuite/affine-shared/utils';
|
||||
import type { BlockStdScope } from '@blocksuite/block-std';
|
||||
import type { BlockModel } from '@blocksuite/store';
|
||||
|
||||
@@ -16,7 +16,7 @@ export function toParagraph(
|
||||
prefix: string
|
||||
) {
|
||||
const { store: doc } = std;
|
||||
if (!matchFlavours(model, [ParagraphBlockModel])) {
|
||||
if (!matchModels(model, [ParagraphBlockModel])) {
|
||||
const parent = doc.getParent(model);
|
||||
if (!parent) return;
|
||||
|
||||
@@ -36,7 +36,7 @@ export function toParagraph(
|
||||
return id;
|
||||
}
|
||||
|
||||
if (matchFlavours(model, [ParagraphBlockModel]) && model.type !== type) {
|
||||
if (matchModels(model, [ParagraphBlockModel]) && model.type !== type) {
|
||||
beforeConvert(std, model, prefix.length);
|
||||
|
||||
doc.updateBlock(model, { type });
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ParagraphBlockModel } from '@blocksuite/affine-model';
|
||||
import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
||||
import { matchModels } from '@blocksuite/affine-shared/utils';
|
||||
import type { BlockStdScope } from '@blocksuite/block-std';
|
||||
import type { BlockModel } from '@blocksuite/store';
|
||||
|
||||
@@ -11,7 +11,7 @@ export function toCode(
|
||||
prefixText: string,
|
||||
language: string | null
|
||||
) {
|
||||
if (matchFlavours(model, [ParagraphBlockModel]) && model.type === 'quote') {
|
||||
if (matchModels(model, [ParagraphBlockModel]) && model.type === 'quote') {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -94,8 +94,5 @@ declare global {
|
||||
interface EdgelessBlockModelMap {
|
||||
'affine:attachment': AttachmentBlockModel;
|
||||
}
|
||||
interface BlockModels {
|
||||
'affine:attachment': AttachmentBlockModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,8 +63,5 @@ declare global {
|
||||
interface EdgelessBlockModelMap {
|
||||
'affine:bookmark': BookmarkBlockModel;
|
||||
}
|
||||
interface BlockModels {
|
||||
'affine:bookmark': BookmarkBlockModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,11 +33,3 @@ export const CodeBlockSchema = defineBlockSchema({
|
||||
export class CodeBlockModel extends BlockModel<CodeBlockProps> {
|
||||
override text!: Text;
|
||||
}
|
||||
|
||||
declare global {
|
||||
namespace BlockSuite {
|
||||
interface BlockModels {
|
||||
'affine:code': CodeBlockModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,11 +28,3 @@ export const DatabaseBlockSchema = defineBlockSchema({
|
||||
},
|
||||
toModel: () => new DatabaseBlockModel(),
|
||||
});
|
||||
|
||||
declare global {
|
||||
namespace BlockSuite {
|
||||
interface BlockModels {
|
||||
'affine:database': DatabaseBlockModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,11 +15,3 @@ type Props = {
|
||||
};
|
||||
|
||||
export class DividerBlockModel extends BlockModel<Props> {}
|
||||
|
||||
declare global {
|
||||
namespace BlockSuite {
|
||||
interface BlockModels {
|
||||
'affine:divider': DividerBlockModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,10 +82,6 @@ export class EdgelessTextBlockModel
|
||||
|
||||
declare global {
|
||||
namespace BlockSuite {
|
||||
interface BlockModels {
|
||||
'affine:edgeless-text': EdgelessTextBlockModel;
|
||||
}
|
||||
|
||||
interface EdgelessBlockModelMap {
|
||||
'affine:edgeless-text': EdgelessTextBlockModel;
|
||||
}
|
||||
|
||||
@@ -25,8 +25,5 @@ declare global {
|
||||
interface EdgelessBlockModelMap {
|
||||
'affine:embed-figma': EmbedFigmaModel;
|
||||
}
|
||||
interface BlockModels {
|
||||
'affine:embed-figma': EmbedFigmaModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,8 +39,5 @@ declare global {
|
||||
interface EdgelessBlockModelMap {
|
||||
'affine:embed-github': EmbedGithubModel;
|
||||
}
|
||||
interface BlockModels {
|
||||
'affine:embed-github': EmbedGithubModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,5 @@ declare global {
|
||||
interface EdgelessBlockModelMap {
|
||||
'affine:embed-html': EmbedHtmlModel;
|
||||
}
|
||||
interface BlockModels {
|
||||
'affine:embed-html': EmbedHtmlModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,8 +26,5 @@ declare global {
|
||||
interface EdgelessBlockModelMap {
|
||||
'affine:embed-linked-doc': EmbedLinkedDocModel;
|
||||
}
|
||||
interface BlockModels {
|
||||
'affine:embed-linked-doc': EmbedLinkedDocModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,8 +27,5 @@ declare global {
|
||||
interface EdgelessBlockModelMap {
|
||||
'affine:embed-loom': EmbedLoomModel;
|
||||
}
|
||||
interface BlockModels {
|
||||
'affine:embed-loom': EmbedLoomModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,5 @@ declare global {
|
||||
interface EdgelessBlockModelMap {
|
||||
'affine:embed-synced-doc': EmbedSyncedDocModel;
|
||||
}
|
||||
interface BlockModels {
|
||||
'affine:embed-synced-doc': EmbedSyncedDocModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,8 +30,5 @@ declare global {
|
||||
interface EdgelessBlockModelMap {
|
||||
'affine:embed-youtube': EmbedYoutubeModel;
|
||||
}
|
||||
interface BlockModels {
|
||||
'affine:embed-youtube': EmbedYoutubeModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,8 +150,5 @@ declare global {
|
||||
interface EdgelessBlockModelMap {
|
||||
'affine:frame': FrameBlockModel;
|
||||
}
|
||||
interface BlockModels {
|
||||
'affine:frame': FrameBlockModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,9 +45,6 @@ export class ImageBlockModel
|
||||
|
||||
declare global {
|
||||
namespace BlockSuite {
|
||||
interface BlockModels {
|
||||
'affine:image': ImageBlockModel;
|
||||
}
|
||||
interface EdgelessBlockModelMap {
|
||||
'affine:image': ImageBlockModel;
|
||||
}
|
||||
|
||||
@@ -40,10 +40,6 @@ export class LatexBlockModel
|
||||
|
||||
declare global {
|
||||
namespace BlockSuite {
|
||||
interface BlockModels {
|
||||
'affine:latex': LatexBlockModel;
|
||||
}
|
||||
|
||||
interface EdgelessBlockModelMap {
|
||||
'affine:latex': LatexBlockModel;
|
||||
}
|
||||
|
||||
@@ -41,11 +41,3 @@ export const ListBlockSchema = defineBlockSchema({
|
||||
export class ListBlockModel extends BlockModel<ListProps> {
|
||||
override text!: Text;
|
||||
}
|
||||
|
||||
declare global {
|
||||
namespace BlockSuite {
|
||||
interface BlockModels {
|
||||
'affine:list': ListBlockModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,9 +158,6 @@ export class NoteBlockModel
|
||||
|
||||
declare global {
|
||||
namespace BlockSuite {
|
||||
interface BlockModels {
|
||||
'affine:note': NoteBlockModel;
|
||||
}
|
||||
interface EdgelessBlockModelMap {
|
||||
'affine:note': NoteBlockModel;
|
||||
}
|
||||
|
||||
@@ -44,11 +44,3 @@ export class ParagraphBlockModel extends BlockModel<ParagraphProps> {
|
||||
return this.text$.value.length === 0 && this.children.length === 0;
|
||||
}
|
||||
}
|
||||
|
||||
declare global {
|
||||
namespace BlockSuite {
|
||||
interface BlockModels {
|
||||
'affine:paragraph': ParagraphBlockModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,11 +51,3 @@ export const RootBlockSchema = defineBlockSchema({
|
||||
},
|
||||
toModel: () => new RootBlockModel(),
|
||||
});
|
||||
|
||||
declare global {
|
||||
namespace BlockSuite {
|
||||
interface BlockModels {
|
||||
'affine:page': RootBlockModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,11 +22,3 @@ export const SurfaceRefBlockSchema = defineBlockSchema({
|
||||
});
|
||||
|
||||
export class SurfaceRefBlockModel extends BlockModel<SurfaceRefProps> {}
|
||||
|
||||
declare global {
|
||||
namespace BlockSuite {
|
||||
interface BlockModels {
|
||||
'affine:surface-ref': SurfaceRefBlockModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,11 +56,3 @@ export const TableBlockSchema = defineBlockSchema({
|
||||
},
|
||||
toModel: () => new TableBlockModel(),
|
||||
});
|
||||
|
||||
declare global {
|
||||
namespace BlockSuite {
|
||||
interface BlockModels {
|
||||
[TableModelFlavour]: TableBlockModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ import type {
|
||||
GfxBlockElementModel,
|
||||
GfxGroupLikeElementModel,
|
||||
GfxLocalElementModel,
|
||||
GfxModel,
|
||||
GfxPrimitiveElementModel,
|
||||
} from '@blocksuite/block-std/gfx';
|
||||
|
||||
@@ -14,8 +13,6 @@ declare global {
|
||||
| EdgelessBlockModelMap[EdgelessBlockModelKeyType]
|
||||
| GfxBlockElementModel;
|
||||
|
||||
type EdgelessModel = GfxModel;
|
||||
|
||||
interface EdgelessTextModelMap {}
|
||||
type EdgelessTextModelKeyType = keyof EdgelessTextModelMap;
|
||||
type EdgelessTextModelType = EdgelessTextModelMap[EdgelessTextModelKeyType];
|
||||
|
||||
@@ -12,7 +12,7 @@ import type {
|
||||
TransformerSlots,
|
||||
} from '@blocksuite/store';
|
||||
|
||||
import { matchFlavours } from '../../utils';
|
||||
import { matchModels } from '../../utils';
|
||||
|
||||
const handlePoint = (
|
||||
point: TextRangePoint,
|
||||
@@ -20,7 +20,7 @@ const handlePoint = (
|
||||
model: DraftModel
|
||||
) => {
|
||||
const { index, length } = point;
|
||||
if (matchFlavours(model, [RootBlockModel])) {
|
||||
if (matchModels(model, [RootBlockModel])) {
|
||||
if (length === 0) return;
|
||||
(snapshot.props.title as Record<string, unknown>).delta =
|
||||
model.title.sliceToDelta(index, length + index);
|
||||
|
||||
@@ -35,7 +35,7 @@ import {
|
||||
TelemetryProvider,
|
||||
} from '../../services';
|
||||
import type { AffineTextAttributes } from '../../types';
|
||||
import { matchFlavours, referenceToNode } from '../../utils';
|
||||
import { matchModels, referenceToNode } from '../../utils';
|
||||
|
||||
function findLastMatchingNode(
|
||||
root: BlockSnapshot[],
|
||||
@@ -293,7 +293,7 @@ class PasteTr {
|
||||
return;
|
||||
}
|
||||
if (!cursorModel.text) {
|
||||
if (matchFlavours(cursorModel, [ImageBlockModel])) {
|
||||
if (matchModels(cursorModel, [ImageBlockModel])) {
|
||||
const selection = this.std.selection.create(ImageSelection, {
|
||||
blockId: target.blockId,
|
||||
});
|
||||
@@ -358,7 +358,7 @@ class PasteTr {
|
||||
if (
|
||||
this.firstSnapshot !== this.lastSnapshot &&
|
||||
this.lastSnapshot.props.text &&
|
||||
!matchFlavours(this.pointState.model, [CodeBlockModel])
|
||||
!matchModels(this.pointState.model, [CodeBlockModel])
|
||||
) {
|
||||
const text = fromJSON(this.lastSnapshot.props.text) as Text;
|
||||
const doc = new Y.Doc();
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
import type { BlockComponent, Command } from '@blocksuite/block-std';
|
||||
import type {
|
||||
BlockComponent,
|
||||
BlockStdScope,
|
||||
Command,
|
||||
} from '@blocksuite/block-std';
|
||||
|
||||
import { getNextContentBlock } from '../../utils/index.js';
|
||||
|
||||
function getNextBlock(std: BlockSuite.Std, path: string) {
|
||||
function getNextBlock(std: BlockStdScope, path: string) {
|
||||
const view = std.view;
|
||||
const model = std.store.getBlock(path)?.model;
|
||||
if (!model) return null;
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
import type { BlockComponent, Command } from '@blocksuite/block-std';
|
||||
import type {
|
||||
BlockComponent,
|
||||
BlockStdScope,
|
||||
Command,
|
||||
} from '@blocksuite/block-std';
|
||||
|
||||
import { getPrevContentBlock } from '../../utils/index.js';
|
||||
|
||||
function getPrevBlock(std: BlockSuite.Std, path: string) {
|
||||
function getPrevBlock(std: BlockStdScope, path: string) {
|
||||
const view = std.view;
|
||||
|
||||
const model = std.store.getBlock(path)?.model;
|
||||
|
||||
@@ -52,10 +52,7 @@ export type EmbedOptions = {
|
||||
export type IndentContext = {
|
||||
blockId: string;
|
||||
inlineIndex: number;
|
||||
flavour: Extract<
|
||||
keyof BlockSuite.BlockModels,
|
||||
'affine:paragraph' | 'affine:list'
|
||||
>;
|
||||
flavour: string;
|
||||
type: 'indent' | 'dedent';
|
||||
};
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { ParagraphBlockModel } from '@blocksuite/affine-model';
|
||||
import type { BlockModel } from '@blocksuite/store';
|
||||
|
||||
import { matchFlavours } from '../model/checker.js';
|
||||
import { matchModels } from '../model/checker.js';
|
||||
|
||||
export function calculateCollapsedSiblings(
|
||||
model: ParagraphBlockModel
|
||||
@@ -15,7 +15,7 @@ export function calculateCollapsedSiblings(
|
||||
const collapsedEdgeIndex = children.findIndex((child, i) => {
|
||||
if (
|
||||
i > index &&
|
||||
matchFlavours(child, [ParagraphBlockModel]) &&
|
||||
matchModels(child, [ParagraphBlockModel]) &&
|
||||
child.type.startsWith('h')
|
||||
) {
|
||||
const modelLevel = parseInt(model.type.slice(1));
|
||||
@@ -46,7 +46,7 @@ export function getNearestHeadingBefore(
|
||||
for (let i = index - 1; i >= 0; i--) {
|
||||
const sibling = parent.children[i];
|
||||
if (
|
||||
matchFlavours(sibling, [ParagraphBlockModel]) &&
|
||||
matchModels(sibling, [ParagraphBlockModel]) &&
|
||||
sibling.type.startsWith('h')
|
||||
) {
|
||||
return sibling;
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
getClosestBlockComponentByElement,
|
||||
getRectByBlockComponent,
|
||||
} from '../dom/index.js';
|
||||
import { matchFlavours } from '../model/index.js';
|
||||
import { matchModels } from '../model/index.js';
|
||||
import { getDropRectByPoint } from './get-drop-rect-by-point.js';
|
||||
import { DropFlags, type DropPlacement, type DropTarget } from './types.js';
|
||||
|
||||
@@ -56,7 +56,7 @@ export function calcDropTarget(
|
||||
.every(m => children.includes(m.flavour));
|
||||
}
|
||||
|
||||
if (!shouldAppendToDatabase && !matchFlavours(model, [DatabaseBlockModel])) {
|
||||
if (!shouldAppendToDatabase && !matchModels(model, [DatabaseBlockModel])) {
|
||||
const databaseBlockComponent =
|
||||
element.closest<BlockComponent>('affine-database');
|
||||
if (databaseBlockComponent) {
|
||||
@@ -150,7 +150,7 @@ export function calcDropTarget(
|
||||
const hasChild = (element as BlockComponent).childBlocks.length;
|
||||
if (
|
||||
allowSublist &&
|
||||
matchFlavours(model, [ListBlockModel]) &&
|
||||
matchModels(model, [ListBlockModel]) &&
|
||||
!hasChild &&
|
||||
point.x > domRect.x + BLOCK_CHILDREN_CONTAINER_PADDING_LEFT
|
||||
) {
|
||||
|
||||
@@ -4,7 +4,7 @@ import type { Point } from '@blocksuite/global/utils';
|
||||
import type { BlockModel } from '@blocksuite/store';
|
||||
|
||||
import { getRectByBlockComponent } from '../dom/index.js';
|
||||
import { matchFlavours } from '../model/index.js';
|
||||
import { matchModels } from '../model/index.js';
|
||||
import { DropFlags } from './types.js';
|
||||
|
||||
const ATTR_SELECTOR = `[${BLOCK_ID_ATTR}]`;
|
||||
@@ -25,7 +25,7 @@ export function getDropRectByPoint(
|
||||
flag: DropFlags.Normal,
|
||||
};
|
||||
|
||||
const isDatabase = matchFlavours(model, [DatabaseBlockModel]);
|
||||
const isDatabase = matchModels(model, [DatabaseBlockModel]);
|
||||
|
||||
if (isDatabase) {
|
||||
const table = getDatabaseBlockTableElement(element);
|
||||
|
||||
@@ -6,7 +6,7 @@ import type { BlockModel } from '@blocksuite/store';
|
||||
|
||||
import { BLOCK_CHILDREN_CONTAINER_PADDING_LEFT } from '../../consts/index.js';
|
||||
import { clamp } from '../math.js';
|
||||
import { matchFlavours } from '../model/checker.js';
|
||||
import { matchModels } from '../model/checker.js';
|
||||
|
||||
const ATTR_SELECTOR = `[${BLOCK_ID_ATTR}]`;
|
||||
|
||||
@@ -36,7 +36,7 @@ function hasBlockId(element: Element): element is BlockComponent {
|
||||
* Returns `true` if element is default/edgeless page or note.
|
||||
*/
|
||||
function isRootOrNoteOrSurface(element: BlockComponent) {
|
||||
return matchFlavours(element.model, [
|
||||
return matchModels(element.model, [
|
||||
RootBlockModel,
|
||||
NoteBlockModel,
|
||||
SurfaceBlockModel,
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { FrameBlockModel, GroupElementModel } from '@blocksuite/affine-model';
|
||||
import type { GfxBlockElementModel } from '@blocksuite/block-std/gfx';
|
||||
import type { GfxBlockElementModel, GfxModel } from '@blocksuite/block-std/gfx';
|
||||
import {
|
||||
deserializeXYWH,
|
||||
getQuadBoundWithRotation,
|
||||
} from '@blocksuite/global/utils';
|
||||
import type { BlockModel } from '@blocksuite/store';
|
||||
|
||||
export function getSelectedRect(selected: BlockSuite.EdgelessModel[]): DOMRect {
|
||||
export function getSelectedRect(selected: GfxModel[]): DOMRect {
|
||||
if (selected.length === 0) {
|
||||
return new DOMRect();
|
||||
}
|
||||
@@ -57,8 +57,8 @@ export function getSelectedRect(selected: BlockSuite.EdgelessModel[]): DOMRect {
|
||||
);
|
||||
}
|
||||
|
||||
export function getElementsWithoutGroup(elements: BlockSuite.EdgelessModel[]) {
|
||||
const set = new Set<BlockSuite.EdgelessModel>();
|
||||
export function getElementsWithoutGroup(elements: GfxModel[]) {
|
||||
const set = new Set<GfxModel>();
|
||||
|
||||
elements.forEach(element => {
|
||||
if (element instanceof GroupElementModel) {
|
||||
@@ -73,7 +73,7 @@ export function getElementsWithoutGroup(elements: BlockSuite.EdgelessModel[]) {
|
||||
}
|
||||
|
||||
export function isTopLevelBlock(
|
||||
selectable: BlockModel | BlockSuite.EdgelessModel | null
|
||||
selectable: BlockModel | GfxModel | null
|
||||
): selectable is GfxBlockElementModel {
|
||||
return !!selectable && 'flavour' in selectable;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ type ModelList<T> =
|
||||
: never
|
||||
: never;
|
||||
|
||||
export function matchFlavours<
|
||||
export function matchModels<
|
||||
const Model extends ConstructorType<BlockModel>[],
|
||||
U extends ModelList<Model>[number] = ModelList<Model>[number],
|
||||
>(model: unknown, expected: Model): model is U {
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { EditorHost } from '@blocksuite/block-std';
|
||||
import type { BlockModel } from '@blocksuite/store';
|
||||
|
||||
import { DocModeProvider } from '../../services/doc-mode-service.js';
|
||||
import { matchFlavours } from './checker.js';
|
||||
import { matchModels } from './checker.js';
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -74,7 +74,7 @@ export function getPrevContentBlock(
|
||||
|
||||
const prev = getPrev(model);
|
||||
if (prev) {
|
||||
if (prev.role === 'content' && !matchFlavours(prev, [FrameBlockModel])) {
|
||||
if (prev.role === 'content' && !matchModels(prev, [FrameBlockModel])) {
|
||||
return prev;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import { NoteBlockModel, NoteDisplayMode } from '@blocksuite/affine-model';
|
||||
import type { BlockComponent, EditorHost } from '@blocksuite/block-std';
|
||||
import type { BlockModel, Store } from '@blocksuite/store';
|
||||
|
||||
import { matchFlavours } from './checker.js';
|
||||
import { matchModels } from './checker.js';
|
||||
|
||||
export function findAncestorModel(
|
||||
model: BlockModel,
|
||||
@@ -37,7 +37,7 @@ export async function asyncGetBlockComponent(
|
||||
|
||||
export function findNoteBlockModel(model: BlockModel) {
|
||||
return findAncestorModel(model, m =>
|
||||
matchFlavours(m, [NoteBlockModel])
|
||||
matchModels(m, [NoteBlockModel])
|
||||
) as NoteBlockModel | null;
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ export function getLastNoteBlock(doc: Store) {
|
||||
for (let i = children.length - 1; i >= 0; i--) {
|
||||
const child = children[i];
|
||||
if (
|
||||
matchFlavours(child, [NoteBlockModel]) &&
|
||||
matchModels(child, [NoteBlockModel]) &&
|
||||
child.displayMode !== NoteDisplayMode.EdgelessOnly
|
||||
) {
|
||||
note = child as NoteBlockModel;
|
||||
|
||||
@@ -2,7 +2,7 @@ import { ListBlockModel } from '@blocksuite/affine-model';
|
||||
import type { BlockStdScope } from '@blocksuite/block-std';
|
||||
import type { BlockModel, Store } from '@blocksuite/store';
|
||||
|
||||
import { matchFlavours } from './checker.js';
|
||||
import { matchModels } from './checker.js';
|
||||
|
||||
/**
|
||||
* Pass in a list model, and this function will look forward to find continuous sibling numbered lists,
|
||||
@@ -23,7 +23,7 @@ export function getNextContinuousNumberedLists(
|
||||
const firstNotNumberedListIndex = parent.children.findIndex(
|
||||
(model, i) =>
|
||||
i > modelIndex &&
|
||||
(!matchFlavours(model, [ListBlockModel]) || model.type !== 'numbered')
|
||||
(!matchModels(model, [ListBlockModel]) || model.type !== 'numbered')
|
||||
);
|
||||
const newContinuousLists = parent.children.slice(
|
||||
modelIndex + 1,
|
||||
@@ -31,8 +31,7 @@ export function getNextContinuousNumberedLists(
|
||||
);
|
||||
if (
|
||||
!newContinuousLists.every(
|
||||
model =>
|
||||
matchFlavours(model, [ListBlockModel]) && model.type === 'numbered'
|
||||
model => matchModels(model, [ListBlockModel]) && model.type === 'numbered'
|
||||
)
|
||||
)
|
||||
return [];
|
||||
@@ -56,7 +55,7 @@ export function toNumberedList(
|
||||
// if there is a numbered list before, the order continues from the previous list
|
||||
if (
|
||||
prevSibling &&
|
||||
matchFlavours(prevSibling, [ListBlockModel]) &&
|
||||
matchModels(prevSibling, [ListBlockModel]) &&
|
||||
prevSibling.type === 'numbered'
|
||||
) {
|
||||
doc.transact(() => {
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { BlockModel, Store, Text } from '@blocksuite/store';
|
||||
|
||||
export function transformModel(
|
||||
model: BlockModel,
|
||||
flavour: BlockSuite.Flavour,
|
||||
flavour: string,
|
||||
props?: Parameters<Store['addBlock']>[1]
|
||||
) {
|
||||
const doc = model.doc;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { correctNumberedListsOrderToPrev } from '@blocksuite/affine-block-list';
|
||||
import { ListBlockModel } from '@blocksuite/affine-model';
|
||||
import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
||||
import { matchModels } from '@blocksuite/affine-shared/utils';
|
||||
import type { BlockStdScope } from '@blocksuite/block-std';
|
||||
import type { TransformerMiddleware } from '@blocksuite/store';
|
||||
|
||||
@@ -10,10 +10,7 @@ export const reorderList =
|
||||
slots.afterImport.on(payload => {
|
||||
if (payload.type === 'block') {
|
||||
const model = payload.model;
|
||||
if (
|
||||
matchFlavours(model, [ListBlockModel]) &&
|
||||
model.type === 'numbered'
|
||||
) {
|
||||
if (matchModels(model, [ListBlockModel]) && model.type === 'numbered') {
|
||||
const next = std.store.getNext(model);
|
||||
correctNumberedListsOrderToPrev(std.store, model);
|
||||
if (next) {
|
||||
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
findClosestBlockComponent,
|
||||
getBlockProps,
|
||||
getClosestBlockComponentByPoint,
|
||||
matchFlavours,
|
||||
matchModels,
|
||||
} from '@blocksuite/affine-shared/utils';
|
||||
import type { BlockComponent, EditorHost } from '@blocksuite/block-std';
|
||||
import { Point, Rect } from '@blocksuite/global/utils';
|
||||
@@ -220,7 +220,7 @@ export const getDropResult = (
|
||||
|
||||
const model = closestBlock.model;
|
||||
|
||||
const isDatabase = matchFlavours(model, [DatabaseBlockModel]);
|
||||
const isDatabase = matchModels(model, [DatabaseBlockModel]);
|
||||
if (isDatabase) {
|
||||
return dropIndicator;
|
||||
}
|
||||
@@ -236,7 +236,7 @@ export const getDropResult = (
|
||||
export function getDragHandleLeftPadding(blocks: BlockComponent[]) {
|
||||
const hasToggleList = blocks.some(
|
||||
block =>
|
||||
(matchFlavours(block.model, [ListBlockModel]) &&
|
||||
(matchModels(block.model, [ListBlockModel]) &&
|
||||
block.model.children.length > 0) ||
|
||||
(block instanceof ParagraphBlockComponent &&
|
||||
block.model.type.startsWith('h') &&
|
||||
|
||||
@@ -28,7 +28,7 @@ import {
|
||||
getBlockComponentsExcludeSubtrees,
|
||||
getRectByBlockComponent,
|
||||
getScrollContainer,
|
||||
matchFlavours,
|
||||
matchModels,
|
||||
} from '@blocksuite/affine-shared/utils';
|
||||
import {
|
||||
type BlockComponent,
|
||||
@@ -161,17 +161,17 @@ export class DragEventWatcher {
|
||||
!snapshot ||
|
||||
snapshot.content.length === 0 ||
|
||||
!dragPayload?.from ||
|
||||
matchFlavours(model, [DatabaseBlockModel])
|
||||
matchModels(model, [DatabaseBlockModel])
|
||||
)
|
||||
return null;
|
||||
|
||||
const isDropOnNoteBlock = matchFlavours(model, [NoteBlockModel]);
|
||||
const isDropOnNoteBlock = matchModels(model, [NoteBlockModel]);
|
||||
|
||||
const edge = dropPayload.edge;
|
||||
const scale = this.widget.scale.peek();
|
||||
let result: DropResult;
|
||||
|
||||
if (edge === 'right' && matchFlavours(dropBlock.model, [ListBlockModel])) {
|
||||
if (edge === 'right' && matchModels(dropBlock.model, [ListBlockModel])) {
|
||||
const domRect = getRectByBlockComponent(dropBlock);
|
||||
const placement = 'in';
|
||||
const rect = Rect.fromLWTH(
|
||||
@@ -373,7 +373,7 @@ export class DragEventWatcher {
|
||||
result.placement === 'in' ? model : this.std.store.getParent(model);
|
||||
|
||||
if (!parent) return;
|
||||
if (matchFlavours(parent, [SurfaceBlockModel])) {
|
||||
if (matchModels(parent, [SurfaceBlockModel])) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -383,7 +383,7 @@ export class DragEventWatcher {
|
||||
: parent.children.indexOf(model) +
|
||||
(result.placement === 'before' ? 0 : 1);
|
||||
|
||||
if (matchFlavours(parent, [NoteBlockModel])) {
|
||||
if (matchModels(parent, [NoteBlockModel])) {
|
||||
const [first] = snapshot.content;
|
||||
if (first.flavour === 'affine:note') {
|
||||
if (parent.id !== first.id) {
|
||||
@@ -685,7 +685,7 @@ export class DragEventWatcher {
|
||||
})
|
||||
);
|
||||
|
||||
if (matchFlavours(view.model, [AttachmentBlockModel, BookmarkBlockModel])) {
|
||||
if (matchModels(view.model, [AttachmentBlockModel, BookmarkBlockModel])) {
|
||||
cleanups.push(this._makeDraggable(view));
|
||||
}
|
||||
|
||||
|
||||
@@ -17,10 +17,7 @@ import {
|
||||
SurfaceRefBlockModel,
|
||||
} from '@blocksuite/affine-model';
|
||||
import { FeatureFlagService } from '@blocksuite/affine-shared/services';
|
||||
import {
|
||||
matchFlavours,
|
||||
stopPropagation,
|
||||
} from '@blocksuite/affine-shared/utils';
|
||||
import { matchModels, stopPropagation } from '@blocksuite/affine-shared/utils';
|
||||
import { WidgetComponent } from '@blocksuite/block-std';
|
||||
import {
|
||||
type GfxController,
|
||||
@@ -195,7 +192,7 @@ export class EdgelessAutoConnectWidget extends WidgetComponent<RootBlockModel> {
|
||||
|
||||
const pageVisibleBlocks = new Map<AutoConnectElement, number>();
|
||||
const notes = service.doc.root?.children.filter(child =>
|
||||
matchFlavours(child, [NoteBlockModel])
|
||||
matchModels(child, [NoteBlockModel])
|
||||
);
|
||||
const edgelessOnlyNotesSet = new Set<NoteBlockModel>();
|
||||
|
||||
@@ -209,7 +206,7 @@ export class EdgelessAutoConnectWidget extends WidgetComponent<RootBlockModel> {
|
||||
}
|
||||
|
||||
note.children.forEach(model => {
|
||||
if (matchFlavours(model, [SurfaceRefBlockModel])) {
|
||||
if (matchModels(model, [SurfaceRefBlockModel])) {
|
||||
const reference = this._crud.getElementById(model.reference);
|
||||
|
||||
if (!isAutoConnectElement(reference)) return;
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
} from '@blocksuite/affine-model';
|
||||
import { getSelectionRectsCommand } from '@blocksuite/affine-shared/commands';
|
||||
import { EMBED_BLOCK_MODEL_LIST } from '@blocksuite/affine-shared/consts';
|
||||
import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
||||
import { matchModels } from '@blocksuite/affine-shared/utils';
|
||||
import {
|
||||
BlockSelection,
|
||||
TextSelection,
|
||||
@@ -76,7 +76,7 @@ export class AffineDocRemoteSelectionWidget extends WidgetComponent {
|
||||
private get _config(): DocRemoteSelectionConfig {
|
||||
return {
|
||||
blockSelectionBackgroundTransparent: block => {
|
||||
return matchFlavours(block, [
|
||||
return matchModels(block, [
|
||||
CodeBlockModel,
|
||||
DatabaseBlockModel,
|
||||
ImageBlockModel,
|
||||
|
||||
@@ -7,7 +7,10 @@ import {
|
||||
requestThrottledConnectedFrame,
|
||||
} from '@blocksuite/affine-shared/utils';
|
||||
import { WidgetComponent } from '@blocksuite/block-std';
|
||||
import { GfxControllerIdentifier } from '@blocksuite/block-std/gfx';
|
||||
import {
|
||||
GfxControllerIdentifier,
|
||||
type GfxModel,
|
||||
} from '@blocksuite/block-std/gfx';
|
||||
import { pickValues } from '@blocksuite/global/utils';
|
||||
import type { UserInfo } from '@blocksuite/store';
|
||||
import { css, html, nothing } from 'lit';
|
||||
@@ -118,7 +121,7 @@ export class EdgelessRemoteSelectionWidget extends WidgetComponent<RootBlockMode
|
||||
|
||||
const elements = selection.elements
|
||||
.map(id => this.crud.getElementById(id))
|
||||
.filter(element => element) as BlockSuite.EdgelessModel[];
|
||||
.filter(element => element) as GfxModel[];
|
||||
const rect = getSelectedRect(elements);
|
||||
|
||||
if (rect.width === 0 || rect.height === 0) return;
|
||||
|
||||
@@ -76,7 +76,7 @@ describe('DatabaseManager', () => {
|
||||
noteBlockId = doc.addBlock('affine:note', {}, rootId);
|
||||
|
||||
databaseBlockId = doc.addBlock(
|
||||
'affine:database' as BlockSuite.Flavour,
|
||||
'affine:database',
|
||||
{
|
||||
columns: [],
|
||||
titleColumn: 'Title',
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { MindmapElementModel } from '@blocksuite/affine-model';
|
||||
import type { Viewport } from '@blocksuite/block-std/gfx';
|
||||
import type { GfxModel, Viewport } from '@blocksuite/block-std/gfx';
|
||||
|
||||
export function isSingleMindMapNode(els: BlockSuite.EdgelessModel[]) {
|
||||
export function isSingleMindMapNode(els: GfxModel[]) {
|
||||
return els.length === 1 && els[0].group instanceof MindmapElementModel;
|
||||
}
|
||||
|
||||
export function isElementOutsideViewport(
|
||||
viewport: Viewport,
|
||||
element: BlockSuite.EdgelessModel,
|
||||
element: GfxModel,
|
||||
padding: [number, number] = [0, 0]
|
||||
) {
|
||||
const elementBound = element.elementBound;
|
||||
@@ -25,7 +25,7 @@ export function isElementOutsideViewport(
|
||||
|
||||
export function getNearestTranslation(
|
||||
viewport: Viewport,
|
||||
element: BlockSuite.EdgelessModel,
|
||||
element: GfxModel,
|
||||
padding: [number, number] = [0, 0]
|
||||
) {
|
||||
const viewportBound = viewport.viewportBounds;
|
||||
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
} from '@blocksuite/affine-shared/consts';
|
||||
import {
|
||||
isInsidePageEditor,
|
||||
matchFlavours,
|
||||
matchModels,
|
||||
} from '@blocksuite/affine-shared/utils';
|
||||
import {
|
||||
type BlockStdScope,
|
||||
@@ -458,7 +458,7 @@ export class ExportManager {
|
||||
edgeless?.service.gfx.getElementsByBound(bound, { type: 'block' }) ??
|
||||
[];
|
||||
for (const block of blocks) {
|
||||
if (matchFlavours(block, [ImageBlockModel])) {
|
||||
if (matchModels(block, [ImageBlockModel])) {
|
||||
if (!block.sourceId) return;
|
||||
|
||||
const blob = await block.doc.blobSync.get(block.sourceId);
|
||||
@@ -495,7 +495,7 @@ export class ExportManager {
|
||||
);
|
||||
}
|
||||
|
||||
if (matchFlavours(block, [FrameBlockModel])) {
|
||||
if (matchModels(block, [FrameBlockModel])) {
|
||||
// TODO(@L-Sun): use children of frame instead of bound
|
||||
const blocksInsideFrame = getBlocksInFrameBound(this.doc, block, false);
|
||||
const frameBound = Bound.deserialize(block.xywh);
|
||||
|
||||
@@ -4,6 +4,7 @@ import type {
|
||||
DocMode,
|
||||
GroupElementModel,
|
||||
} from '@blocksuite/affine-model';
|
||||
import type { GfxModel } from '@blocksuite/block-std/gfx';
|
||||
import type { Store } from '@blocksuite/store';
|
||||
|
||||
export type AbstractEditor = {
|
||||
@@ -12,6 +13,6 @@ export type AbstractEditor = {
|
||||
} & HTMLElement;
|
||||
|
||||
export type Connectable = Exclude<
|
||||
BlockSuite.EdgelessModel,
|
||||
GfxModel,
|
||||
ConnectorElementModel | BrushElementModel | GroupElementModel
|
||||
>;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* oxlint-disable @typescript-eslint/triple-slash-reference */
|
||||
/// <reference path="./effects.ts" />
|
||||
import { matchFlavours } from '@blocksuite/affine-shared/utils';
|
||||
import { matchModels } from '@blocksuite/affine-shared/utils';
|
||||
import { deserializeXYWH, Point } from '@blocksuite/global/utils';
|
||||
|
||||
import { splitElements } from './root-block/edgeless/utils/clipboard-utils.js';
|
||||
@@ -142,7 +142,7 @@ export {
|
||||
getLastNoteBlock,
|
||||
isInsideEdgelessEditor,
|
||||
isInsidePageEditor,
|
||||
matchFlavours,
|
||||
matchModels,
|
||||
on,
|
||||
once,
|
||||
openFileOrFiles,
|
||||
@@ -155,7 +155,7 @@ export type { DragBlockPayload } from '@blocksuite/affine-widget-drag-handle';
|
||||
|
||||
export const BlocksUtils = {
|
||||
splitElements,
|
||||
matchFlavours,
|
||||
matchModels,
|
||||
deserializeXYWH,
|
||||
isCanvasElement,
|
||||
Point,
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user