mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-27 10:52:40 +08:00
refactor(editor): rename doc to blocks (#9510)
This commit is contained in:
@@ -11,7 +11,7 @@ import type { EditorHost } from '@blocksuite/block-std';
|
||||
import { DataSourceBase, type PropertyMetaConfig } from '@blocksuite/data-view';
|
||||
import { propertyPresets } from '@blocksuite/data-view/property-presets';
|
||||
import { assertExists, Slot } from '@blocksuite/global/utils';
|
||||
import type { Block, Doc } from '@blocksuite/store';
|
||||
import type { Block, Blocks } from '@blocksuite/store';
|
||||
|
||||
import type { BlockMeta } from './block-meta/base.js';
|
||||
import { blockMetaMap } from './block-meta/index.js';
|
||||
@@ -140,7 +140,7 @@ export class BlockQueryDataSource extends DataSourceBase {
|
||||
return this.block.columns.find(v => v.id === id);
|
||||
}
|
||||
|
||||
listenToDoc(doc: Doc) {
|
||||
listenToDoc(doc: Blocks) {
|
||||
this.docDisposeMap.set(
|
||||
doc.id,
|
||||
doc.slots.blockUpdated.on(v => {
|
||||
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
} from '@blocksuite/affine-model';
|
||||
import { BlockService } from '@blocksuite/block-std';
|
||||
import { viewPresets } from '@blocksuite/data-view/view-presets';
|
||||
import type { BlockModel, Doc } from '@blocksuite/store';
|
||||
import type { BlockModel, Blocks } from '@blocksuite/store';
|
||||
|
||||
import {
|
||||
databaseViewAddView,
|
||||
@@ -36,7 +36,7 @@ export class DatabaseBlockService extends BlockService {
|
||||
viewPresets = viewPresets;
|
||||
|
||||
initDatabaseBlock(
|
||||
doc: Doc,
|
||||
doc: Blocks,
|
||||
model: BlockModel,
|
||||
databaseId: string,
|
||||
viewType: string,
|
||||
|
||||
@@ -11,9 +11,9 @@ import { BlockStdScope } from '@blocksuite/block-std';
|
||||
import { assertExists } from '@blocksuite/global/utils';
|
||||
import {
|
||||
type BlockModel,
|
||||
type Blocks,
|
||||
type BlockSnapshot,
|
||||
BlockViewType,
|
||||
type Doc,
|
||||
type DraftModel,
|
||||
type Query,
|
||||
Slice,
|
||||
@@ -220,7 +220,7 @@ function filterTextModel(model: BlockModel) {
|
||||
return false;
|
||||
}
|
||||
|
||||
export function getNotesFromDoc(doc: Doc) {
|
||||
export function getNotesFromDoc(doc: Blocks) {
|
||||
const notes = doc.root?.children.filter(
|
||||
child =>
|
||||
matchFlavours(child, ['affine:note']) &&
|
||||
@@ -234,7 +234,7 @@ export function getNotesFromDoc(doc: Doc) {
|
||||
return notes;
|
||||
}
|
||||
|
||||
export function isEmptyDoc(doc: Doc | null, mode: DocMode) {
|
||||
export function isEmptyDoc(doc: Blocks | null, mode: DocMode) {
|
||||
if (!doc) {
|
||||
return true;
|
||||
}
|
||||
@@ -266,7 +266,7 @@ export function isEmptyNote(note: BlockModel) {
|
||||
/**
|
||||
* Gets the document content with a max length.
|
||||
*/
|
||||
export function getDocContentWithMaxLength(doc: Doc, maxlength = 500) {
|
||||
export function getDocContentWithMaxLength(doc: Blocks, maxlength = 500) {
|
||||
const notes = getNotesFromDoc(doc);
|
||||
if (!notes) return;
|
||||
|
||||
@@ -326,7 +326,7 @@ export function promptDocTitle(std: BlockStdScope, autofill?: string) {
|
||||
});
|
||||
}
|
||||
|
||||
export function notifyDocCreated(std: BlockStdScope, doc: Doc) {
|
||||
export function notifyDocCreated(std: BlockStdScope, doc: Blocks) {
|
||||
const notification = std.getOptional(NotificationProvider);
|
||||
if (!notification) return;
|
||||
|
||||
@@ -365,7 +365,7 @@ export function notifyDocCreated(std: BlockStdScope, doc: Doc) {
|
||||
|
||||
export async function convertSelectedBlocksToLinkedDoc(
|
||||
std: BlockStdScope,
|
||||
doc: Doc,
|
||||
doc: Blocks,
|
||||
selectedModels: DraftModel[] | Promise<DraftModel[]>,
|
||||
docTitle?: string
|
||||
) {
|
||||
@@ -399,7 +399,7 @@ export async function convertSelectedBlocksToLinkedDoc(
|
||||
|
||||
export function createLinkedDocFromSlice(
|
||||
std: BlockStdScope,
|
||||
doc: Doc,
|
||||
doc: Blocks,
|
||||
snapshots: BlockSnapshot[],
|
||||
docTitle?: string
|
||||
) {
|
||||
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
getNextContinuousNumberedLists,
|
||||
matchFlavours,
|
||||
} from '@blocksuite/affine-shared/utils';
|
||||
import type { BlockModel, Doc } from '@blocksuite/store';
|
||||
import type { BlockModel, Blocks } from '@blocksuite/store';
|
||||
|
||||
/**
|
||||
* correct target is a numbered list, which is divided into two steps:
|
||||
@@ -12,7 +12,7 @@ import type { BlockModel, Doc } from '@blocksuite/store';
|
||||
* 2. find continuous lists starting from the target list and keep their order continuous
|
||||
*/
|
||||
export function correctNumberedListsOrderToPrev(
|
||||
doc: Doc,
|
||||
doc: Blocks,
|
||||
modelOrId: BlockModel | string,
|
||||
transact = true
|
||||
) {
|
||||
@@ -58,7 +58,7 @@ export function correctNumberedListsOrderToPrev(
|
||||
}
|
||||
}
|
||||
|
||||
export function correctListOrder(doc: Doc, model: ListBlockModel) {
|
||||
export function correctListOrder(doc: Blocks, model: ListBlockModel) {
|
||||
// old numbered list has no order
|
||||
if (model.type === 'numbered' && !Number.isInteger(model.order)) {
|
||||
correctNumberedListsOrderToPrev(doc, model, false);
|
||||
|
||||
@@ -45,7 +45,7 @@ import {
|
||||
DisposableGroup,
|
||||
type SerializedXYWH,
|
||||
} from '@blocksuite/global/utils';
|
||||
import type { Doc } from '@blocksuite/store';
|
||||
import type { Blocks } from '@blocksuite/store';
|
||||
import { css, html, nothing, type TemplateResult } from 'lit';
|
||||
import { query, state } from 'lit/decorators.js';
|
||||
import { styleMap } from 'lit/directives/style-map.js';
|
||||
@@ -238,7 +238,7 @@ export class SurfaceRefBlockComponent extends BlockComponent<SurfaceRefBlockMode
|
||||
}
|
||||
`;
|
||||
|
||||
private _previewDoc: Doc | null = null;
|
||||
private _previewDoc: Blocks | null = null;
|
||||
|
||||
private readonly _previewSpec =
|
||||
SpecProvider.getInstance().getSpec('edgeless:preview');
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import type { Doc } from '@blocksuite/store';
|
||||
import type { Blocks } from '@blocksuite/store';
|
||||
|
||||
import type { SurfaceBlockModel } from '../surface-model';
|
||||
|
||||
export function getSurfaceBlock(doc: Doc) {
|
||||
export function getSurfaceBlock(doc: Blocks) {
|
||||
const blocks = doc.getBlocksByFlavour('affine:surface');
|
||||
return blocks.length !== 0 ? (blocks[0].model as SurfaceBlockModel) : null;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
stdContext,
|
||||
} from '@blocksuite/block-std';
|
||||
import { WithDisposable } from '@blocksuite/global/utils';
|
||||
import type { BlockModel, Doc } from '@blocksuite/store';
|
||||
import type { BlockModel, Blocks } from '@blocksuite/store';
|
||||
import { Text } from '@blocksuite/store';
|
||||
import { consume } from '@lit/context';
|
||||
import { css, html, nothing } from 'lit';
|
||||
@@ -161,7 +161,7 @@ export class BlockCaptionEditor<
|
||||
accessor display = false;
|
||||
|
||||
@consume({ context: docContext })
|
||||
accessor doc!: Doc;
|
||||
accessor doc!: Blocks;
|
||||
|
||||
@query('.block-caption-editor')
|
||||
accessor input!: HTMLInputElement;
|
||||
|
||||
@@ -24,7 +24,7 @@ import {
|
||||
ZERO_WIDTH_NON_JOINER,
|
||||
ZERO_WIDTH_SPACE,
|
||||
} from '@blocksuite/inline';
|
||||
import type { Doc, DocMeta } from '@blocksuite/store';
|
||||
import type { Blocks, DocMeta } from '@blocksuite/store';
|
||||
import { css, html, nothing } from 'lit';
|
||||
import { property, state } from 'lit/decorators.js';
|
||||
import { choose } from 'lit/directives/choose.js';
|
||||
@@ -71,7 +71,7 @@ export class AffineReference extends WithDisposable(ShadowlessElement) {
|
||||
}
|
||||
`;
|
||||
|
||||
private readonly _updateRefMeta = (doc: Doc) => {
|
||||
private readonly _updateRefMeta = (doc: Blocks) => {
|
||||
const refAttribute = this.delta.attributes?.reference;
|
||||
if (!refAttribute) {
|
||||
return;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { BlockStdScope, EditorHost } from '@blocksuite/block-std';
|
||||
import type { GfxModel } from '@blocksuite/block-std/gfx';
|
||||
import type { BlockModel, Doc } from '@blocksuite/store';
|
||||
import type { BlockModel, Blocks } from '@blocksuite/store';
|
||||
|
||||
export abstract class MenuContext {
|
||||
abstract get doc(): Doc;
|
||||
abstract get doc(): Blocks;
|
||||
|
||||
get firstElement(): GfxModel | null {
|
||||
return null;
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
LinkedPageIcon,
|
||||
PageIcon,
|
||||
} from '@blocksuite/icons/lit';
|
||||
import type { Doc } from '@blocksuite/store';
|
||||
import type { Blocks } from '@blocksuite/store';
|
||||
import { computed, type Signal, signal } from '@preact/signals-core';
|
||||
import type { TemplateResult } from 'lit';
|
||||
|
||||
@@ -70,9 +70,9 @@ export class DocDisplayMetaService
|
||||
|
||||
readonly disposables: Disposable[] = [];
|
||||
|
||||
readonly iconMap = new WeakMap<Doc, Signal<TemplateResult>>();
|
||||
readonly iconMap = new WeakMap<Blocks, Signal<TemplateResult>>();
|
||||
|
||||
readonly titleMap = new WeakMap<Doc, Signal<string>>();
|
||||
readonly titleMap = new WeakMap<Blocks, Signal<string>>();
|
||||
|
||||
static override setup(di: Container) {
|
||||
di.addImpl(DocDisplayMetaProvider, this, [StdIdentifier]);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { BlockModel, Doc, DraftModel } from '@blocksuite/store';
|
||||
import type { BlockModel, Blocks, DraftModel } from '@blocksuite/store';
|
||||
import { minimatch } from 'minimatch';
|
||||
|
||||
export function matchFlavours<Key extends (keyof BlockSuite.BlockModels)[]>(
|
||||
@@ -14,7 +14,7 @@ export function matchFlavours<Key extends (keyof BlockSuite.BlockModels)[]>(
|
||||
}
|
||||
|
||||
export function isInsideBlockByFlavour(
|
||||
doc: Doc,
|
||||
doc: Blocks,
|
||||
block: BlockModel | string,
|
||||
flavour: string
|
||||
): boolean {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { type NoteBlockModel, NoteDisplayMode } from '@blocksuite/affine-model';
|
||||
import type { BlockComponent, EditorHost } from '@blocksuite/block-std';
|
||||
import type { BlockModel, Doc } from '@blocksuite/store';
|
||||
import type { BlockModel, Blocks } from '@blocksuite/store';
|
||||
|
||||
import { matchFlavours } from './checker.js';
|
||||
|
||||
@@ -41,7 +41,7 @@ export function findNoteBlockModel(model: BlockModel) {
|
||||
) as NoteBlockModel | null;
|
||||
}
|
||||
|
||||
export function getLastNoteBlock(doc: Doc) {
|
||||
export function getLastNoteBlock(doc: Blocks) {
|
||||
let note: NoteBlockModel | null = null;
|
||||
if (!doc.root) return null;
|
||||
const { children } = doc.root;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { ListBlockModel } from '@blocksuite/affine-model';
|
||||
import type { BlockStdScope } from '@blocksuite/block-std';
|
||||
import type { BlockModel, Doc } from '@blocksuite/store';
|
||||
import type { BlockModel, Blocks } from '@blocksuite/store';
|
||||
|
||||
import { matchFlavours } from './checker.js';
|
||||
|
||||
@@ -9,7 +9,7 @@ import { matchFlavours } from './checker.js';
|
||||
* typically used for updating list numbers. The result not contains the list passed in.
|
||||
*/
|
||||
export function getNextContinuousNumberedLists(
|
||||
doc: Doc,
|
||||
doc: Blocks,
|
||||
modelOrId: BlockModel | string
|
||||
): ListBlockModel[] {
|
||||
const model =
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { BlockModel, Doc, Text } from '@blocksuite/store';
|
||||
import type { BlockModel, Blocks, Text } from '@blocksuite/store';
|
||||
|
||||
export function transformModel(
|
||||
model: BlockModel,
|
||||
flavour: BlockSuite.Flavour,
|
||||
props?: Parameters<Doc['addBlock']>[1]
|
||||
props?: Parameters<Blocks['addBlock']>[1]
|
||||
) {
|
||||
const doc = model.doc;
|
||||
const parent = doc.getParent(model);
|
||||
|
||||
Reference in New Issue
Block a user