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

@@ -11,7 +11,10 @@ import { WorkspaceService } from '@affine/core/modules/workspace';
import { i18nTime, Trans, useI18n } from '@affine/i18n';
import { track } from '@affine/track';
import type { DocMode } from '@blocksuite/affine/blocks';
import type { Doc as BlockSuiteDoc, Workspace } from '@blocksuite/affine/store';
import type {
Blocks as BlockSuiteDoc,
Workspace,
} from '@blocksuite/affine/store';
import { CloseIcon, ToggleCollapseIcon } from '@blocksuite/icons/rc';
import * as Collapsible from '@radix-ui/react-collapsible';
import type { DialogContentProps } from '@radix-ui/react-dialog';

View File

@@ -1,14 +1,14 @@
import { useEnableCloud } from '@affine/core/components/hooks/affine/use-enable-cloud';
import type { Workspace } from '@affine/core/modules/workspace';
import { track } from '@affine/track';
import type { Doc } from '@blocksuite/affine/store';
import type { Blocks } from '@blocksuite/affine/store';
import { useCallback } from 'react';
import { ShareMenu } from './share-menu';
type SharePageModalProps = {
workspace: Workspace;
page: Doc;
page: Blocks;
};
export const SharePageButton = ({ workspace, page }: SharePageModalProps) => {

View File

@@ -4,7 +4,7 @@ import { Menu } from '@affine/component/ui/menu';
import { ShareInfoService } from '@affine/core/modules/share-doc';
import type { WorkspaceMetadata } from '@affine/core/modules/workspace';
import { useI18n } from '@affine/i18n';
import type { Doc } from '@blocksuite/affine/store';
import type { Blocks } from '@blocksuite/affine/store';
import { LockIcon, PublishIcon } from '@blocksuite/icons/rc';
import { useLiveData, useService } from '@toeverything/infra';
import { forwardRef, type PropsWithChildren, type Ref, useEffect } from 'react';
@@ -15,7 +15,7 @@ import { SharePage } from './share-page';
export interface ShareMenuProps extends PropsWithChildren {
workspaceMetadata: WorkspaceMetadata;
currentPage: Doc;
currentPage: Blocks;
onEnableAffineCloud: () => void;
onOpenShareModal?: (open: boolean) => void;
}

View File

@@ -10,7 +10,7 @@ import type {
EdgelessEditor,
PageEditor,
} from '@blocksuite/affine/presets';
import { type BlockModel, type Doc } from '@blocksuite/affine/store';
import { type BlockModel, type Blocks } from '@blocksuite/affine/store';
import clsx from 'clsx';
import type React from 'react';
import {
@@ -27,7 +27,7 @@ import { BlocksuiteDocEditor, BlocksuiteEdgelessEditor } from './lit-adaper';
import * as styles from './styles.css';
interface BlocksuiteEditorContainerProps {
page: Doc;
page: Blocks;
mode: DocMode;
shared?: boolean;
className?: string;
@@ -191,7 +191,7 @@ export const BlocksuiteEditorContainer = forwardRef<
});
// copy from '@blocksuite/affine-shared/utils'
export function getLastNoteBlock(doc: Doc) {
export function getLastNoteBlock(doc: Blocks) {
let note: NoteBlockModel | null = null;
if (!doc.root) return null;
const { children } = doc.root;

View File

@@ -11,7 +11,7 @@ import {
} from '@blocksuite/affine/blocks';
import { DisposableGroup } from '@blocksuite/affine/global/utils';
import type { AffineEditorContainer } from '@blocksuite/affine/presets';
import type { Doc } from '@blocksuite/affine/store';
import type { Blocks } from '@blocksuite/affine/store';
import type { CSSProperties } from 'react';
import { useEffect, useState } from 'react';
@@ -20,7 +20,7 @@ import { BlocksuiteEditorContainer } from './blocksuite-editor-container';
import { NoPageRootError } from './no-page-error';
export type EditorProps = {
page: Doc;
page: Blocks;
mode: DocMode;
shared?: boolean;
defaultOpenProperty?: DefaultOpenProperty;

View File

@@ -1,12 +1,12 @@
import { JournalService } from '@affine/core/modules/journal';
import { i18nTime, useI18n } from '@affine/i18n';
import type { Doc } from '@blocksuite/affine/store';
import type { Blocks } from '@blocksuite/affine/store';
import { useLiveData, useService } from '@toeverything/infra';
import dayjs from 'dayjs';
import * as styles from './styles.css';
export const BlocksuiteEditorJournalDocTitle = ({ page }: { page: Doc }) => {
export const BlocksuiteEditorJournalDocTitle = ({ page }: { page: Blocks }) => {
const journalService = useService(JournalService);
const journalDateStr = useLiveData(journalService.journalDate$(page.id));
const journalDate = journalDateStr ? dayjs(journalDateStr) : null;

View File

@@ -23,7 +23,7 @@ import {
EdgelessEditor,
PageEditor,
} from '@blocksuite/affine/presets';
import type { Doc } from '@blocksuite/affine/store';
import type { Blocks } from '@blocksuite/affine/store';
import {
useFramework,
useLiveData,
@@ -85,7 +85,7 @@ const adapted = {
};
interface BlocksuiteEditorProps {
page: Doc;
page: Blocks;
shared?: boolean;
defaultOpenProperty?: DefaultOpenProperty;
}

View File

@@ -1,11 +1,11 @@
import type { Doc } from '@blocksuite/affine/store';
import type { Blocks } from '@blocksuite/affine/store';
import type { Map as YMap } from 'yjs';
/**
* TODO(@eyhn): Define error to unexpected state together in the future.
*/
export class NoPageRootError extends Error {
constructor(public page: Doc) {
constructor(public page: Blocks) {
super('Page root not found when render editor!');
// Log info to let sentry collect more message

View File

@@ -2,13 +2,13 @@ import type { WeekDatePickerHandle } from '@affine/component';
import { WeekDatePicker } from '@affine/component';
import { useJournalRouteHelper } from '@affine/core/components/hooks/use-journal';
import { JournalService } from '@affine/core/modules/journal';
import type { Doc } from '@blocksuite/affine/store';
import type { Blocks } from '@blocksuite/affine/store';
import { useLiveData, useService } from '@toeverything/infra';
import dayjs from 'dayjs';
import { useEffect, useRef, useState } from 'react';
export interface JournalWeekDatePickerProps {
page: Doc;
page: Blocks;
}
const weekStyle = { maxWidth: 800, width: '100%' };

View File

@@ -22,7 +22,7 @@ import { ViewService } from '@affine/core/modules/workbench/services/view';
import { WorkspaceService } from '@affine/core/modules/workspace';
import { useI18n } from '@affine/i18n';
import { track } from '@affine/track';
import type { Doc } from '@blocksuite/affine/store';
import type { Blocks } from '@blocksuite/affine/store';
import {
DuplicateIcon,
EdgelessIcon,
@@ -52,7 +52,7 @@ import { HistoryTipsModal } from './history-tips-modal';
type PageMenuProps = {
rename?: () => void;
page: Doc;
page: Blocks;
isJournal?: boolean;
containerWidth: number;
};

View File

@@ -22,7 +22,7 @@ import {
ZipTransformer,
} from '@blocksuite/affine/blocks';
import type { AffineEditorContainer } from '@blocksuite/affine/presets';
import { type Doc, Job } from '@blocksuite/affine/store';
import { type Blocks, Job } from '@blocksuite/affine/store';
import { useLiveData, useService } from '@toeverything/infra';
import { useSetAtom } from 'jotai';
import { nanoid } from 'nanoid';
@@ -32,7 +32,7 @@ import { useAsyncCallback } from '../affine-async-hooks';
type ExportType = 'pdf' | 'html' | 'png' | 'markdown' | 'snapshot';
interface ExportHandlerOptions {
page: Doc;
page: Blocks;
editorContainer: AffineEditorContainer;
type: ExportType;
}
@@ -53,7 +53,11 @@ interface AdapterConfig {
indexFileName: string;
}
async function exportDoc(doc: Doc, std: BlockStdScope, config: AdapterConfig) {
async function exportDoc(
doc: Blocks,
std: BlockStdScope,
config: AdapterConfig
) {
const job = new Job({
schema: doc.collection.schema,
blobCRUD: doc.collection.blobSync,
@@ -99,7 +103,7 @@ async function exportDoc(doc: Doc, std: BlockStdScope, config: AdapterConfig) {
download(downloadBlob, name);
}
async function exportToHtml(doc: Doc, std?: BlockStdScope) {
async function exportToHtml(doc: Blocks, std?: BlockStdScope) {
if (!std) {
// If std is not provided, we use the default export method
await HtmlTransformer.exportDoc(doc);
@@ -113,7 +117,7 @@ async function exportToHtml(doc: Doc, std?: BlockStdScope) {
}
}
async function exportToMarkdown(doc: Doc, std?: BlockStdScope) {
async function exportToMarkdown(doc: Blocks, std?: BlockStdScope) {
if (!std) {
// If std is not provided, we use the default export method
await MarkdownTransformer.exportDoc(doc);

View File

@@ -1,10 +1,10 @@
import type { Doc, Workspace } from '@blocksuite/affine/store';
import type { Blocks, Workspace } from '@blocksuite/affine/store';
import { useMemo } from 'react';
export function useDocCollectionHelper(docCollection: Workspace) {
return useMemo(
() => ({
createDoc: (pageId?: string): Doc => {
createDoc: (pageId?: string): Blocks => {
return docCollection.createDoc({ id: pageId });
},
}),

View File

@@ -1,6 +1,6 @@
import { DebugLogger } from '@affine/debug';
import { DisposableGroup } from '@blocksuite/affine/global/utils';
import type { Doc, Workspace } from '@blocksuite/affine/store';
import type { Blocks, Workspace } from '@blocksuite/affine/store';
import { useEffect, useState } from 'react';
const logger = new DebugLogger('use-doc-collection-page');
@@ -8,7 +8,7 @@ const logger = new DebugLogger('use-doc-collection-page');
export function useDocCollectionPage(
docCollection: Workspace,
pageId: string | null
): Doc | null {
): Blocks | null {
const [page, setPage] = useState(
pageId ? docCollection.getDoc(pageId) : null
);

View File

@@ -5,7 +5,7 @@ import 'fake-indexeddb/auto';
import { AffineSchemas } from '@blocksuite/affine/blocks/schemas';
import { assertExists } from '@blocksuite/affine/global/utils';
import type { Doc } from '@blocksuite/affine/store';
import type { Blocks } from '@blocksuite/affine/store';
import { Schema } from '@blocksuite/store';
import { TestWorkspace } from '@blocksuite/store/test';
import { renderHook } from '@testing-library/react';
@@ -22,7 +22,7 @@ beforeEach(async () => {
vi.useFakeTimers({ toFake: ['requestIdleCallback'] });
docCollection = new TestWorkspace({ id: 'test', schema });
docCollection.meta.initialize();
const initPage = async (page: Doc) => {
const initPage = async (page: Blocks) => {
page.load();
expect(page).not.toBeNull();
assertExists(page);
@@ -37,7 +37,7 @@ beforeEach(async () => {
describe('useBlockSuitePagePreview', () => {
test('basic', async () => {
const page = docCollection.getDoc('page0') as Doc;
const page = docCollection.getDoc('page0') as Blocks;
const id = page.addBlock(
'affine:paragraph',
{

View File

@@ -1,13 +1,13 @@
import type { Doc } from '@blocksuite/affine/store';
import type { Blocks } from '@blocksuite/affine/store';
import type { Atom } from 'jotai';
import { atom } from 'jotai';
const MAX_PREVIEW_LENGTH = 150;
const MAX_SEARCH_BLOCK_COUNT = 30;
const weakMap = new WeakMap<Doc, Atom<string>>();
const weakMap = new WeakMap<Blocks, Atom<string>>();
export const getPagePreviewText = (page: Doc) => {
export const getPagePreviewText = (page: Blocks) => {
const pageRoot = page.root;
if (!pageRoot) {
return '';
@@ -60,7 +60,7 @@ export const getPagePreviewText = (page: Doc) => {
const emptyAtom = atom<string>('');
export function useBlockSuitePagePreview(page: Doc | null): Atom<string> {
export function useBlockSuitePagePreview(page: Blocks | null): Atom<string> {
if (page === null) {
return emptyAtom;
} else if (weakMap.has(page)) {

View File

@@ -1,6 +1,6 @@
import { DebugLogger } from '@affine/debug';
import { DisposableGroup } from '@blocksuite/affine/global/utils';
import type { Doc, Workspace } from '@blocksuite/affine/store';
import type { Blocks, Workspace } from '@blocksuite/affine/store';
import { useEffect, useState } from 'react';
const logger = new DebugLogger('useBlockSuiteWorkspacePage');
@@ -8,7 +8,7 @@ const logger = new DebugLogger('useBlockSuiteWorkspacePage');
export function useDocCollectionPage(
docCollection: Workspace,
pageId: string | null
): Doc | null {
): Blocks | null {
const [page, setPage] = useState(
pageId ? docCollection.getDoc(pageId) : null
);

View File

@@ -25,7 +25,7 @@ import { CMDKQuickSearchService } from '@affine/core/modules/quicksearch/service
import type { Workspace } from '@affine/core/modules/workspace';
import { useI18n } from '@affine/i18n';
import { track } from '@affine/track';
import type { Doc } from '@blocksuite/affine/store';
import type { Blocks } from '@blocksuite/affine/store';
import {
AllDocsIcon,
GithubIcon,
@@ -56,7 +56,7 @@ export type RootAppSidebarProps = {
onOpenSettingModal: () => void;
currentWorkspace: Workspace;
openPage: (pageId: string) => void;
createPage: () => Doc;
createPage: () => Blocks;
paths: {
all: (workspaceId: string) => string;
trash: (workspaceId: string) => string;