refactor(editor): rename doc to blocks (#9510)

This commit is contained in:
Saul-Mirone
2025-01-03 12:49:33 +00:00
parent 2074bda8ff
commit 4457cb7266
99 changed files with 271 additions and 256 deletions

View File

@@ -1,5 +1,5 @@
import { SignalWatcher, WithDisposable } from '@blocksuite/global/utils';
import type { Doc } from '@blocksuite/store';
import type { Blocks } from '@blocksuite/store';
import { html } from 'lit';
import { customElement, property } from 'lit/decorators.js';
@@ -32,7 +32,7 @@ export class TestEditorContainer extends SignalWatcher(
}
@property({ attribute: false })
accessor doc!: Doc;
accessor doc!: Blocks;
@property({ attribute: false })
accessor specs: ExtensionType[] = [];

View File

@@ -2,8 +2,8 @@ import type { ServiceProvider } from '@blocksuite/global/di';
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
import type {
BaseAdapter,
Blocks,
BlockSnapshot,
Doc,
Job,
JobMiddleware,
Slice,
@@ -110,7 +110,7 @@ export class Clipboard extends LifeCycleWatcher {
private readonly _getSnapshotByPriority = async (
getItem: (type: string) => string | File[],
doc: Doc,
doc: Blocks,
parent?: string,
index?: number
) => {
@@ -182,7 +182,7 @@ export class Clipboard extends LifeCycleWatcher {
duplicateSlice = async (
slice: Slice,
doc: Doc,
doc: Blocks,
parent?: string,
index?: number,
type = 'BLOCKSUITE/SNAPSHOT'
@@ -201,7 +201,7 @@ export class Clipboard extends LifeCycleWatcher {
paste = async (
event: ClipboardEvent,
doc: Doc,
doc: Blocks,
parent?: string,
index?: number
) => {
@@ -238,7 +238,7 @@ export class Clipboard extends LifeCycleWatcher {
pasteBlockSnapshot = async (
snapshot: BlockSnapshot,
doc: Doc,
doc: Blocks,
parent?: string,
index?: number
) => {

View File

@@ -4,7 +4,7 @@ import {
getBoundWithRotation,
intersects,
} from '@blocksuite/global/utils';
import type { BlockModel, Doc } from '@blocksuite/store';
import type { BlockModel, Blocks } from '@blocksuite/store';
import { compare } from '../utils/layer.js';
import { GfxBlockElementModel } from './model/gfx-block-model.js';
@@ -361,7 +361,7 @@ export class GridManager {
this.add(element);
}
watch(blocks: { doc?: Doc; surface?: SurfaceBlockModel | null }) {
watch(blocks: { doc?: Blocks; surface?: SurfaceBlockModel | null }) {
const disposables: { dispose: () => void }[] = [];
const { doc, surface } = blocks;
const isRenderableBlock = (

View File

@@ -5,7 +5,7 @@ import {
last,
Slot,
} from '@blocksuite/global/utils';
import type { Doc } from '@blocksuite/store';
import type { Blocks } from '@blocksuite/store';
import { generateKeyBetween } from 'fractional-indexing';
import {
@@ -100,7 +100,7 @@ export class LayerManager {
};
constructor(
private readonly _doc: Doc,
private readonly _doc: Blocks,
private _surface: SurfaceBlockModel | null,
options: {
watch: boolean;
@@ -775,7 +775,7 @@ export class LayerManager {
}
}
watch(blocks: { doc?: Doc; surface: SurfaceBlockModel | null }) {
watch(blocks: { doc?: Blocks; surface: SurfaceBlockModel | null }) {
const { doc, surface } = blocks;
if (doc) {

View File

@@ -1,7 +1,7 @@
import type { ServiceProvider } from '@blocksuite/global/di';
import { Container } from '@blocksuite/global/di';
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
import { type Doc, Job, type JobMiddleware } from '@blocksuite/store';
import { type Blocks, Job, type JobMiddleware } from '@blocksuite/store';
import { Clipboard } from '../clipboard/index.js';
import { CommandManager } from '../command/index.js';
@@ -31,7 +31,7 @@ import { EditorHost } from '../view/element/index.js';
import { ViewStore } from '../view/view-store.js';
export interface BlockStdOptions {
doc: Doc;
doc: Blocks;
extensions: ExtensionType[];
}
@@ -60,7 +60,7 @@ export class BlockStdScope {
readonly container: Container;
readonly doc: Doc;
readonly doc: Blocks;
readonly provider: ServiceProvider;

View File

@@ -1,10 +1,10 @@
import type { Doc } from '@blocksuite/store';
import type { Blocks } from '@blocksuite/store';
import { effect } from '@preact/signals-core';
import { SurfaceBlockModel } from '../gfx/model/surface/surface-model.js';
export function onSurfaceAdded(
doc: Doc,
doc: Blocks,
callback: (model: SurfaceBlockModel | null) => void
) {
let found = false;

View File

@@ -1,5 +1,5 @@
import { nToLast } from '@blocksuite/global/utils';
import type { Doc } from '@blocksuite/store';
import type { Blocks } from '@blocksuite/store';
import type { GfxLocalElementModel } from '../gfx/index.js';
import type { Layer } from '../gfx/layer.js';
@@ -82,7 +82,7 @@ export function isInRange(edges: [GfxModel, GfxModel], target: GfxModel) {
}
export function renderableInEdgeless(
doc: Doc,
doc: Blocks,
surface: SurfaceBlockModel,
block: GfxBlockElementModel
) {

View File

@@ -1,4 +1,4 @@
import type { Doc } from '@blocksuite/store';
import type { Blocks } from '@blocksuite/store';
import {
type GfxCompatibleInterface,
@@ -124,13 +124,16 @@ export function isLockedImpl(element: GfxCompatibleInterface): boolean {
return isLockedBySelfImpl(element) || isLockedByAncestorImpl(element);
}
export function lockElementImpl(doc: Doc, element: GfxCompatibleInterface) {
export function lockElementImpl(doc: Blocks, element: GfxCompatibleInterface) {
doc.transact(() => {
element.lockedBySelf = true;
});
}
export function unlockElementImpl(doc: Doc, element: GfxCompatibleInterface) {
export function unlockElementImpl(
doc: Blocks,
element: GfxCompatibleInterface
) {
doc.transact(() => {
element.lockedBySelf = false;
});

View File

@@ -1,6 +1,6 @@
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
import { SignalWatcher, WithDisposable } from '@blocksuite/global/utils';
import { type BlockModel, BlockViewType, Doc } from '@blocksuite/store';
import { type BlockModel, Blocks, BlockViewType } from '@blocksuite/store';
import { consume, provide } from '@lit/context';
import { computed } from '@preact/signals-core';
import { nothing, type TemplateResult } from 'lit';
@@ -23,7 +23,7 @@ import { ShadowlessElement } from './shadowless-element.js';
import type { WidgetComponent } from './widget-component.js';
@requiredProperties({
doc: PropTypes.instanceOf(Doc),
doc: PropTypes.instanceOf(Blocks),
std: PropTypes.object,
widgets: PropTypes.recordOf(PropTypes.object),
})
@@ -307,7 +307,7 @@ export class BlockComponent<
private accessor _service: Service | null = null;
@consume({ context: docContext })
accessor doc!: Doc;
accessor doc!: Blocks;
@property({ attribute: false })
accessor viewType: BlockViewType = BlockViewType.Display;

View File

@@ -4,7 +4,7 @@ import {
handleError,
} from '@blocksuite/global/exceptions';
import { SignalWatcher, Slot, WithDisposable } from '@blocksuite/global/utils';
import { type BlockModel, BlockViewType, Doc } from '@blocksuite/store';
import { type BlockModel, Blocks, BlockViewType } from '@blocksuite/store';
import { createContext, provide } from '@lit/context';
import { css, LitElement, nothing, type TemplateResult } from 'lit';
import { property } from 'lit/decorators.js';
@@ -22,11 +22,11 @@ import type { ViewStore } from '../view-store.js';
import { BLOCK_ID_ATTR, WIDGET_ID_ATTR } from './consts.js';
import { ShadowlessElement } from './shadowless-element.js';
export const docContext = createContext<Doc>('doc');
export const docContext = createContext<Blocks>('doc');
export const stdContext = createContext<BlockStdScope>('std');
@requiredProperties({
doc: PropTypes.instanceOf(Doc),
doc: PropTypes.instanceOf(Blocks),
std: PropTypes.object,
})
export class EditorHost extends SignalWatcher(
@@ -189,7 +189,7 @@ export class EditorHost extends SignalWatcher(
@provide({ context: docContext })
@property({ attribute: false })
accessor doc!: Doc;
accessor doc!: Blocks;
@provide({ context: stdContext })
@property({ attribute: false })

View File

@@ -1,5 +1,5 @@
import { SignalWatcher, WithDisposable } from '@blocksuite/global/utils';
import type { BlockModel, Doc } from '@blocksuite/store';
import type { BlockModel, Blocks } from '@blocksuite/store';
import { consume } from '@lit/context';
import { LitElement } from 'lit';
@@ -94,7 +94,7 @@ export class WidgetComponent<
}
@consume({ context: docContext })
private accessor _doc!: Doc;
private accessor _doc!: Blocks;
@consume({ context: modelContext })
private accessor _model!: Model;