mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-27 02:42:25 +08:00
refactor(editor): rename doc to blocks (#9510)
This commit is contained in:
@@ -5,7 +5,7 @@ import type {
|
||||
GroupElementModel,
|
||||
NoteBlockModel,
|
||||
} from '@blocksuite/blocks';
|
||||
import { type BlockModel, type Doc } from '@blocksuite/store';
|
||||
import { type BlockModel, type Blocks } from '@blocksuite/store';
|
||||
import { beforeEach, describe, expect, test } from 'vitest';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
@@ -19,7 +19,7 @@ import { setupEditor } from '../utils/setup.js';
|
||||
|
||||
let service!: EdgelessRootBlockComponent['service'];
|
||||
|
||||
const addNote = (doc: Doc, props: Record<string, unknown> = {}) => {
|
||||
const addNote = (doc: Blocks, props: Record<string, unknown> = {}) => {
|
||||
return _addNote(doc, {
|
||||
index: service.layer.generateIndex(),
|
||||
...props,
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
||||
import type {
|
||||
EdgelessRootBlockComponent,
|
||||
PageRootBlockComponent,
|
||||
SurfaceBlockComponent,
|
||||
} from '@blocksuite/blocks';
|
||||
import type { Doc } from '@blocksuite/store';
|
||||
import type { Blocks } from '@blocksuite/store';
|
||||
|
||||
import type { AffineEditorContainer } from '../../index.js';
|
||||
|
||||
export function getSurface(doc: Doc, editor: AffineEditorContainer) {
|
||||
export function getSurface(doc: Blocks, editor: AffineEditorContainer) {
|
||||
const surfaceModel = doc.getBlockByFlavour('affine:surface');
|
||||
|
||||
return editor.host!.view.getBlock(
|
||||
@@ -17,17 +16,17 @@ export function getSurface(doc: Doc, editor: AffineEditorContainer) {
|
||||
}
|
||||
|
||||
export function getDocRootBlock(
|
||||
doc: Doc,
|
||||
doc: Blocks,
|
||||
editor: AffineEditorContainer,
|
||||
mode: 'page'
|
||||
): PageRootBlockComponent;
|
||||
export function getDocRootBlock(
|
||||
doc: Doc,
|
||||
doc: Blocks,
|
||||
editor: AffineEditorContainer,
|
||||
mode: 'edgeless'
|
||||
): EdgelessRootBlockComponent;
|
||||
export function getDocRootBlock(
|
||||
doc: Doc,
|
||||
doc: Blocks,
|
||||
editor: AffineEditorContainer,
|
||||
_?: 'edgeless' | 'page'
|
||||
) {
|
||||
@@ -36,7 +35,7 @@ export function getDocRootBlock(
|
||||
| PageRootBlockComponent;
|
||||
}
|
||||
|
||||
export function addNote(doc: Doc, props: Record<string, any> = {}) {
|
||||
export function addNote(doc: Blocks, props: Record<string, any> = {}) {
|
||||
const noteId = doc.addBlock(
|
||||
'affine:note',
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { effects as blocksEffects } from '@blocksuite/blocks/effects';
|
||||
import type { BlockCollection, Doc, Job } from '@blocksuite/store';
|
||||
import type { BlockCollection, Blocks, Job } from '@blocksuite/store';
|
||||
|
||||
import { effects } from '../../effects.js';
|
||||
|
||||
@@ -111,12 +111,12 @@ export function cleanup() {
|
||||
|
||||
declare global {
|
||||
const editor: AffineEditorContainer;
|
||||
const doc: Doc;
|
||||
const doc: Blocks;
|
||||
const collection: TestWorkspace;
|
||||
const job: Job;
|
||||
interface Window {
|
||||
editor: AffineEditorContainer;
|
||||
doc: Doc;
|
||||
doc: Blocks;
|
||||
job: Job;
|
||||
collection: TestWorkspace;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { BlockStdScope, ShadowlessElement } from '@blocksuite/block-std';
|
||||
import { EdgelessEditorBlockSpecs, ThemeProvider } from '@blocksuite/blocks';
|
||||
import { SignalWatcher, WithDisposable } 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 { property, state } from 'lit/decorators.js';
|
||||
import { guard } from 'lit/directives/guard.js';
|
||||
@@ -85,7 +85,7 @@ export class EdgelessEditor extends SignalWatcher(
|
||||
}
|
||||
|
||||
@property({ attribute: false })
|
||||
accessor doc!: Doc;
|
||||
accessor doc!: Blocks;
|
||||
|
||||
@property({ attribute: false })
|
||||
accessor editor!: TemplateResult;
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
ThemeProvider,
|
||||
} from '@blocksuite/blocks';
|
||||
import { SignalWatcher, Slot, WithDisposable } from '@blocksuite/global/utils';
|
||||
import type { BlockModel, Doc } from '@blocksuite/store';
|
||||
import type { BlockModel, Blocks } from '@blocksuite/store';
|
||||
import { computed, signal } from '@preact/signals-core';
|
||||
import { css, html } from 'lit';
|
||||
import { property } from 'lit/decorators.js';
|
||||
@@ -88,7 +88,7 @@ export class AffineEditorContainer
|
||||
}
|
||||
`;
|
||||
|
||||
private readonly _doc = signal<Doc>();
|
||||
private readonly _doc = signal<Blocks>();
|
||||
|
||||
private readonly _edgelessSpecs = signal<ExtensionType[]>(
|
||||
EdgelessEditorBlockSpecs
|
||||
@@ -123,10 +123,10 @@ export class AffineEditorContainer
|
||||
};
|
||||
|
||||
get doc() {
|
||||
return this._doc.value as Doc;
|
||||
return this._doc.value as Blocks;
|
||||
}
|
||||
|
||||
set doc(doc: Doc) {
|
||||
set doc(doc: Blocks) {
|
||||
this._doc.value = doc;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
} from '@blocksuite/block-std';
|
||||
import { PageEditorBlockSpecs, ThemeProvider } from '@blocksuite/blocks';
|
||||
import { noop, SignalWatcher, WithDisposable } from '@blocksuite/global/utils';
|
||||
import type { Doc } from '@blocksuite/store';
|
||||
import type { Blocks } from '@blocksuite/store';
|
||||
import { css, html, nothing } from 'lit';
|
||||
import { property, state } from 'lit/decorators.js';
|
||||
import { guard } from 'lit/directives/guard.js';
|
||||
@@ -101,7 +101,7 @@ export class PageEditor extends SignalWatcher(
|
||||
}
|
||||
|
||||
@property({ attribute: false })
|
||||
accessor doc!: Doc;
|
||||
accessor doc!: Blocks;
|
||||
|
||||
@property({ type: Boolean })
|
||||
accessor hasViewport = true;
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { EditorHost } from '@blocksuite/block-std';
|
||||
import { ShadowlessElement } from '@blocksuite/block-std';
|
||||
import type { RichText, RootBlockModel } from '@blocksuite/blocks';
|
||||
import { assertExists, WithDisposable } from '@blocksuite/global/utils';
|
||||
import type { Doc } from '@blocksuite/store';
|
||||
import type { Blocks } from '@blocksuite/store';
|
||||
import { css, html } from 'lit';
|
||||
import { property, query, state } from 'lit/decorators.js';
|
||||
|
||||
@@ -178,7 +178,7 @@ export class DocTitle extends WithDisposable(ShadowlessElement) {
|
||||
private accessor _richTextElement!: RichText;
|
||||
|
||||
@property({ attribute: false })
|
||||
accessor doc!: Doc;
|
||||
accessor doc!: Blocks;
|
||||
}
|
||||
|
||||
export function getDocTitleByEditorHost(
|
||||
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
SignalWatcher,
|
||||
WithDisposable,
|
||||
} from '@blocksuite/global/utils';
|
||||
import type { Doc } from '@blocksuite/store';
|
||||
import type { Blocks } from '@blocksuite/store';
|
||||
import { css, html, nothing, type PropertyValues } from 'lit';
|
||||
import { property, query, state } from 'lit/decorators.js';
|
||||
import { keyed } from 'lit/directives/keyed.js';
|
||||
@@ -326,7 +326,7 @@ export class FramePanelBody extends SignalWatcher(
|
||||
}
|
||||
}
|
||||
|
||||
private _setDocDisposables(doc: Doc) {
|
||||
private _setDocDisposables(doc: Blocks) {
|
||||
this._clearDocDisposables();
|
||||
this._docDisposables = new DisposableGroup();
|
||||
this._docDisposables.add(
|
||||
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
SignalWatcher,
|
||||
WithDisposable,
|
||||
} from '@blocksuite/global/utils';
|
||||
import type { Doc } from '@blocksuite/store';
|
||||
import type { Blocks } from '@blocksuite/store';
|
||||
import { effect, signal } from '@preact/signals-core';
|
||||
import { css, html, LitElement, nothing, type PropertyValues } from 'lit';
|
||||
import { property, query, state } from 'lit/decorators.js';
|
||||
@@ -698,7 +698,7 @@ export class OutlinePanelBody extends SignalWatcher(
|
||||
private accessor _selected: string[] = [];
|
||||
|
||||
@property({ attribute: false })
|
||||
accessor doc!: Doc;
|
||||
accessor doc!: Blocks;
|
||||
|
||||
@property({ attribute: false })
|
||||
accessor domHost!: Document | HTMLElement;
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
once,
|
||||
} from '@blocksuite/blocks';
|
||||
import { SignalWatcher, WithDisposable } from '@blocksuite/global/utils';
|
||||
import type { BlockModel, Doc } from '@blocksuite/store';
|
||||
import type { BlockModel, Blocks } from '@blocksuite/store';
|
||||
import { baseTheme } from '@toeverything/theme';
|
||||
import { css, html, LitElement, nothing, unsafeCSS } from 'lit';
|
||||
import { property, query, state } from 'lit/decorators.js';
|
||||
@@ -395,7 +395,7 @@ export class OutlineNoteCard extends SignalWatcher(WithDisposable(LitElement)) {
|
||||
accessor activeHeadingId: string | null = null;
|
||||
|
||||
@property({ attribute: false })
|
||||
accessor doc!: Doc;
|
||||
accessor doc!: Blocks;
|
||||
|
||||
@property({ attribute: false })
|
||||
accessor editorMode: 'page' | 'edgeless' = 'page';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { on, once } from '@blocksuite/blocks';
|
||||
import type { Doc } from '@blocksuite/store';
|
||||
import type { Blocks } from '@blocksuite/store';
|
||||
|
||||
import type { OutlinePanelBody } from '../body/outline-panel-body.js';
|
||||
import type { OutlineNoteCard } from '../card/outline-card.js';
|
||||
@@ -15,7 +15,7 @@ export function startDragging(options: {
|
||||
document: Document;
|
||||
host: Document | HTMLElement;
|
||||
container: OutlinePanelBody;
|
||||
doc: Doc;
|
||||
doc: Blocks;
|
||||
}) {
|
||||
const {
|
||||
document,
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
type ParagraphBlockModel,
|
||||
type RootBlockModel,
|
||||
} from '@blocksuite/blocks';
|
||||
import type { BlockModel, Doc } from '@blocksuite/store';
|
||||
import type { BlockModel, Blocks } from '@blocksuite/store';
|
||||
|
||||
import { headingKeys } from '../config.js';
|
||||
|
||||
@@ -22,7 +22,7 @@ type OutlineNoteItem = {
|
||||
};
|
||||
|
||||
export function getNotesFromDoc(
|
||||
doc: Doc,
|
||||
doc: Blocks,
|
||||
modes: NoteDisplayMode[]
|
||||
): OutlineNoteItem[] {
|
||||
const rootModel = doc.root;
|
||||
@@ -74,7 +74,7 @@ export function getHeadingBlocksFromNote(
|
||||
}
|
||||
|
||||
export function getHeadingBlocksFromDoc(
|
||||
doc: Doc,
|
||||
doc: Blocks,
|
||||
modes: NoteDisplayMode[],
|
||||
ignoreEmpty = false
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user