Skip to content

Commit

Permalink
refactor(editor): rename doc to blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Saul-Mirone committed Jan 3, 2025
1 parent 51b109e commit f21c320
Show file tree
Hide file tree
Showing 99 changed files with 272 additions and 256 deletions.
4 changes: 2 additions & 2 deletions blocksuite/affine/block-data-view/src/data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 => {
Expand Down
4 changes: 2 additions & 2 deletions blocksuite/affine/block-database/src/database-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -36,7 +36,7 @@ export class DatabaseBlockService extends BlockService {
viewPresets = viewPresets;

initDatabaseBlock(
doc: Doc,
doc: Blocks,
model: BlockModel,
databaseId: string,
viewType: string,
Expand Down
14 changes: 7 additions & 7 deletions blocksuite/affine/block-embed/src/common/render-linked-doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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']) &&
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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
) {
Expand Down Expand Up @@ -399,7 +399,7 @@ export async function convertSelectedBlocksToLinkedDoc(

export function createLinkedDocFromSlice(
std: BlockStdScope,
doc: Doc,
doc: Blocks,
snapshots: BlockSnapshot[],
docTitle?: string
) {
Expand Down
6 changes: 3 additions & 3 deletions blocksuite/affine/block-list/src/commands/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
) {
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions blocksuite/affine/block-surface-ref/src/surface-ref-block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
4 changes: 2 additions & 2 deletions blocksuite/affine/components/src/caption/block-caption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions blocksuite/affine/components/src/toolbar/menu-context.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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]);
Expand Down
4 changes: 2 additions & 2 deletions blocksuite/affine/shared/src/utils/model/checker.ts
Original file line number Diff line number Diff line change
@@ -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)[]>(
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions blocksuite/affine/shared/src/utils/model/getter.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions blocksuite/affine/shared/src/utils/model/list.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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 =
Expand Down
4 changes: 2 additions & 2 deletions blocksuite/affine/shared/src/utils/model/transform-model.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
RootBlockSchema,
} from '@blocksuite/affine-model';
import { propertyModelPresets } from '@blocksuite/data-view/property-pure-presets';
import type { BlockModel, Doc } from '@blocksuite/store';
import type { BlockModel, Blocks } from '@blocksuite/store';
import { Schema } from '@blocksuite/store';
import {
createAutoIncrementIdGenerator,
Expand Down Expand Up @@ -49,7 +49,7 @@ function createTestDoc(docId = 'doc0') {
}

describe('DatabaseManager', () => {
let doc: Doc;
let doc: Blocks;
let db: DatabaseBlockModel;

let rootId: BlockModel['id'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import type { GfxBlockElementModel } from '@blocksuite/block-std/gfx';
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
import type { IBound } from '@blocksuite/global/utils';
import { Bound } from '@blocksuite/global/utils';
import type { Doc } from '@blocksuite/store';
import type { Blocks } from '@blocksuite/store';

import {
getBlockComponentByModel,
Expand Down Expand Up @@ -110,7 +110,7 @@ export class ExportManager {
await Promise.all(promises);
};

get doc(): Doc {
get doc(): Blocks {
return this.std.doc;
}

Expand Down
4 changes: 2 additions & 2 deletions blocksuite/blocks/src/_common/transformers/html.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HtmlAdapter } from '@blocksuite/affine-shared/adapters';
import { Container } from '@blocksuite/global/di';
import { sha } from '@blocksuite/global/utils';
import type { Doc, Workspace } from '@blocksuite/store';
import type { Blocks, Workspace } from '@blocksuite/store';
import { extMimeMap, Job } from '@blocksuite/store';

import { defaultBlockHtmlAdapterMatchers } from '../adapters/html/block-matcher.js';
Expand Down Expand Up @@ -43,7 +43,7 @@ const provider = container.provider();
* @param doc - The doc to be exported.
* @returns A Promise that resolves when the export is complete.
*/
async function exportDoc(doc: Doc) {
async function exportDoc(doc: Blocks) {
const job = new Job({
schema: doc.schema,
blobCRUD: doc.blobSync,
Expand Down
6 changes: 3 additions & 3 deletions blocksuite/blocks/src/_common/transformers/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { MarkdownAdapter } from '@blocksuite/affine-shared/adapters';
import { Container } from '@blocksuite/global/di';
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
import { assertExists, sha } from '@blocksuite/global/utils';
import type { Doc, Workspace } from '@blocksuite/store';
import type { Blocks, Workspace } from '@blocksuite/store';
import { extMimeMap, Job } from '@blocksuite/store';

import { defaultBlockMarkdownAdapterMatchers } from '../adapters/index.js';
Expand All @@ -28,7 +28,7 @@ const container = new Container();
const provider = container.provider();

type ImportMarkdownToBlockOptions = {
doc: Doc;
doc: Blocks;
markdown: string;
blockId: string;
};
Expand All @@ -49,7 +49,7 @@ type ImportMarkdownZipOptions = {
* @param doc The doc to export
* @returns A Promise that resolves when the export is complete
*/
async function exportDoc(doc: Doc) {
async function exportDoc(doc: Blocks) {
const job = new Job({
schema: doc.schema,
blobCRUD: doc.blobSync,
Expand Down
4 changes: 2 additions & 2 deletions blocksuite/blocks/src/_common/transformers/zip.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { sha } from '@blocksuite/global/utils';
import type { Doc, DocSnapshot, Workspace } from '@blocksuite/store';
import type { Blocks, DocSnapshot, Workspace } from '@blocksuite/store';
import { extMimeMap, getAssetName, Job } from '@blocksuite/store';

import { download, Unzip, Zip } from '../transformers/utils.js';
import { replaceIdMiddleware, titleMiddleware } from './middlewares.js';

async function exportDocs(collection: Workspace, docs: Doc[]) {
async function exportDocs(collection: Workspace, docs: Blocks[]) {
const zip = new Zip();
const job = new Job({
schema: collection.schema,
Expand Down
4 changes: 2 additions & 2 deletions blocksuite/blocks/src/_common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
GroupElementModel,
} from '@blocksuite/affine-model';
import type { Slot } from '@blocksuite/global/utils';
import type { Doc } from '@blocksuite/store';
import type { Blocks } from '@blocksuite/store';

/** Common context interface definition for block models. */

Expand All @@ -14,7 +14,7 @@ type EditorSlots = {
};

export type AbstractEditor = {
doc: Doc;
doc: Blocks;
mode: DocMode;
readonly slots: EditorSlots;
} & HTMLElement;
Expand Down
Loading

0 comments on commit f21c320

Please sign in to comment.