mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-20 03:26:47 +08:00
refactor(editor): rename doc to blocks (#9510)
This commit is contained in:
@@ -5,7 +5,7 @@ import {
|
||||
type ParagraphProps,
|
||||
type RootBlockProps,
|
||||
} from '@blocksuite/affine/blocks';
|
||||
import { type Doc, Text } from '@blocksuite/affine/store';
|
||||
import { type Blocks, Text } from '@blocksuite/affine/store';
|
||||
|
||||
export interface DocProps {
|
||||
page?: Partial<RootBlockProps>;
|
||||
@@ -14,7 +14,7 @@ export interface DocProps {
|
||||
paragraph?: Partial<ParagraphProps>;
|
||||
}
|
||||
|
||||
export function initEmptyDoc(doc: Doc, title?: string) {
|
||||
export function initEmptyDoc(doc: Blocks, title?: string) {
|
||||
doc.load(() => {
|
||||
initDocFromProps(doc, {
|
||||
page: {
|
||||
@@ -24,7 +24,7 @@ export function initEmptyDoc(doc: Doc, title?: string) {
|
||||
});
|
||||
}
|
||||
|
||||
export function initDocFromProps(doc: Doc, props?: DocProps) {
|
||||
export function initDocFromProps(doc: Blocks, props?: DocProps) {
|
||||
doc.load(() => {
|
||||
const pageBlockId = doc.addBlock(
|
||||
'affine:page',
|
||||
|
||||
@@ -20,8 +20,8 @@ import {
|
||||
import { Container, type ServiceProvider } from '@blocksuite/affine/global/di';
|
||||
import { WithDisposable } from '@blocksuite/affine/global/utils';
|
||||
import {
|
||||
type Blocks,
|
||||
BlockViewType,
|
||||
type Doc,
|
||||
type JobMiddleware,
|
||||
type Query,
|
||||
type Schema,
|
||||
@@ -174,7 +174,7 @@ export class TextRenderer extends WithDisposable(ShadowlessElement) {
|
||||
}
|
||||
};
|
||||
|
||||
private _doc: Doc | null = null;
|
||||
private _doc: Blocks | null = null;
|
||||
|
||||
private readonly _query: Query = {
|
||||
mode: 'strict',
|
||||
|
||||
@@ -17,8 +17,8 @@ import type { ServiceProvider } from '@blocksuite/affine/global/di';
|
||||
import { assertExists } from '@blocksuite/affine/global/utils';
|
||||
import type {
|
||||
BlockModel,
|
||||
Blocks,
|
||||
BlockSnapshot,
|
||||
Doc,
|
||||
DraftModel,
|
||||
JobMiddleware,
|
||||
Schema,
|
||||
@@ -166,7 +166,7 @@ export const markdownToSnapshot = async (
|
||||
export async function insertFromMarkdown(
|
||||
host: EditorHost,
|
||||
markdown: string,
|
||||
doc: Doc,
|
||||
doc: Blocks,
|
||||
parent?: string,
|
||||
index?: number
|
||||
) {
|
||||
@@ -235,5 +235,5 @@ export async function markDownToDoc(
|
||||
if (!doc) {
|
||||
console.error('Failed to convert markdown to doc');
|
||||
}
|
||||
return doc as Doc;
|
||||
return doc as Blocks;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ import {
|
||||
getCommonBoundWithRotation,
|
||||
type SerializedXYWH,
|
||||
} from '@blocksuite/affine/global/utils';
|
||||
import type { Doc } from '@blocksuite/affine/store';
|
||||
import type { Blocks } from '@blocksuite/affine/store';
|
||||
import type { TemplateResult } from 'lit';
|
||||
|
||||
import type { ChatMessage } from '../../../blocks';
|
||||
@@ -101,7 +101,7 @@ export function constructUserInfoWithMessages(
|
||||
}
|
||||
|
||||
export async function constructRootChatBlockMessages(
|
||||
doc: Doc,
|
||||
doc: Blocks,
|
||||
forkSessionId: string
|
||||
) {
|
||||
// Convert chat messages to AI chat block messages
|
||||
|
||||
@@ -5,7 +5,7 @@ import type { EditorHost } from '@blocksuite/affine/block-std';
|
||||
import { ShadowlessElement } from '@blocksuite/affine/block-std';
|
||||
import { NotificationProvider } from '@blocksuite/affine/blocks';
|
||||
import { debounce, WithDisposable } from '@blocksuite/affine/global/utils';
|
||||
import type { Doc } from '@blocksuite/affine/store';
|
||||
import type { Blocks } from '@blocksuite/affine/store';
|
||||
import { css, html, type PropertyValues } from 'lit';
|
||||
import { property, state } from 'lit/decorators.js';
|
||||
import { createRef, type Ref, ref } from 'lit/directives/ref.js';
|
||||
@@ -141,7 +141,7 @@ export class ChatPanel extends WithDisposable(ShadowlessElement) {
|
||||
accessor host!: EditorHost;
|
||||
|
||||
@property({ attribute: false })
|
||||
accessor doc!: Doc;
|
||||
accessor doc!: Blocks;
|
||||
|
||||
@state()
|
||||
accessor isLoading = false;
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
} from '@blocksuite/affine/blocks';
|
||||
import { AffineSchemas } from '@blocksuite/affine/blocks/schemas';
|
||||
import { WithDisposable } from '@blocksuite/affine/global/utils';
|
||||
import type { Doc } from '@blocksuite/affine/store';
|
||||
import type { Blocks } from '@blocksuite/affine/store';
|
||||
import { Schema } from '@blocksuite/affine/store';
|
||||
import { css, html, LitElement, nothing } from 'lit';
|
||||
import { property, query } from 'lit/decorators.js';
|
||||
@@ -53,7 +53,7 @@ export class AISlidesRenderer extends WithDisposable(LitElement) {
|
||||
private readonly _editorContainer: Ref<HTMLDivElement> =
|
||||
createRef<HTMLDivElement>();
|
||||
|
||||
private _doc!: Doc;
|
||||
private _doc!: Blocks;
|
||||
|
||||
private _docCollection: WorkspaceImpl | null = null;
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
} from '@blocksuite/affine/blocks';
|
||||
import type { ServiceProvider } from '@blocksuite/affine/global/di';
|
||||
import { WithDisposable } from '@blocksuite/affine/global/utils';
|
||||
import { type Doc, Job, Schema } from '@blocksuite/affine/store';
|
||||
import { type Blocks, Job, Schema } from '@blocksuite/affine/store';
|
||||
import { css, html, LitElement, nothing } from 'lit';
|
||||
import { property, query } from 'lit/decorators.js';
|
||||
import { repeat } from 'lit/directives/repeat.js';
|
||||
@@ -79,7 +79,7 @@ export class MiniMindmapPreview extends WithDisposable(LitElement) {
|
||||
}
|
||||
`;
|
||||
|
||||
doc?: Doc;
|
||||
doc?: Blocks;
|
||||
|
||||
mindmapId?: string;
|
||||
|
||||
@@ -131,7 +131,7 @@ export class MiniMindmapPreview extends WithDisposable(LitElement) {
|
||||
this.requestUpdate();
|
||||
}
|
||||
|
||||
private _toMindmapNode(answer: string, doc: Doc) {
|
||||
private _toMindmapNode(answer: string, doc: Blocks) {
|
||||
return markdownToMindmap(answer, doc, this.host.std.provider);
|
||||
}
|
||||
|
||||
@@ -234,7 +234,7 @@ type Node = {
|
||||
|
||||
export const markdownToMindmap = (
|
||||
answer: string,
|
||||
doc: Doc,
|
||||
doc: Blocks,
|
||||
provider: ServiceProvider
|
||||
) => {
|
||||
let result: Node | null = null;
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
+2
-2
@@ -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;
|
||||
}
|
||||
|
||||
+3
-3
@@ -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;
|
||||
|
||||
+2
-2
@@ -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;
|
||||
|
||||
+2
-2
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
+2
-2
@@ -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
|
||||
|
||||
+2
-2
@@ -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%' };
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 });
|
||||
},
|
||||
}),
|
||||
|
||||
@@ -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
|
||||
);
|
||||
|
||||
+3
-3
@@ -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',
|
||||
{
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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
|
||||
);
|
||||
|
||||
@@ -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;
|
||||
|
||||
+2
-2
@@ -19,7 +19,7 @@ import {
|
||||
StrokeStyle,
|
||||
TextAlign,
|
||||
} from '@blocksuite/affine/blocks';
|
||||
import type { Doc } from '@blocksuite/affine/store';
|
||||
import type { Blocks } from '@blocksuite/affine/store';
|
||||
import { useFramework, useLiveData } from '@toeverything/infra';
|
||||
import { isEqual } from 'lodash-es';
|
||||
import { useCallback, useMemo } from 'react';
|
||||
@@ -357,7 +357,7 @@ export const ConnectorSettings = () => {
|
||||
return getCurrentTextColor(color);
|
||||
}, [getCurrentTextColor, settings]);
|
||||
|
||||
const getElements = useCallback((doc: Doc) => {
|
||||
const getElements = useCallback((doc: Blocks) => {
|
||||
const surface = getSurfaceBlock(doc);
|
||||
return surface?.getElementsByType('connector') || [];
|
||||
}, []);
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
import { WorkspaceImpl } from '@affine/core/modules/workspace/impl/workspace';
|
||||
import { AffineSchemas } from '@blocksuite/affine/blocks';
|
||||
import type { Doc, DocSnapshot } from '@blocksuite/affine/store';
|
||||
import type { Blocks, DocSnapshot } from '@blocksuite/affine/store';
|
||||
import { Job, Schema } from '@blocksuite/affine/store';
|
||||
|
||||
const getCollection = (() => {
|
||||
@@ -26,7 +26,7 @@ export type DocName =
|
||||
| 'connector'
|
||||
| 'mindmap';
|
||||
|
||||
const docMap = new Map<DocName, Promise<Doc | undefined>>();
|
||||
const docMap = new Map<DocName, Promise<Blocks | undefined>>();
|
||||
|
||||
async function loadNote() {
|
||||
return (await import('./note.json')).default;
|
||||
|
||||
+2
-2
@@ -8,7 +8,7 @@ import { SettingRow } from '@affine/component/setting-components';
|
||||
import { EditorSettingService } from '@affine/core/modules/editor-setting';
|
||||
import { useI18n } from '@affine/i18n';
|
||||
import { LayoutType, MindmapStyle } from '@blocksuite/affine/blocks';
|
||||
import type { Doc } from '@blocksuite/affine/store';
|
||||
import type { Blocks } from '@blocksuite/affine/store';
|
||||
import { useFramework, useLiveData } from '@toeverything/infra';
|
||||
import { useCallback, useMemo } from 'react';
|
||||
|
||||
@@ -93,7 +93,7 @@ export const MindMapSettings = () => {
|
||||
});
|
||||
}, [editorSetting, settings]);
|
||||
|
||||
const getElements = useCallback((doc: Doc) => {
|
||||
const getElements = useCallback((doc: Blocks) => {
|
||||
const surface = getSurfaceBlock(doc);
|
||||
return surface?.getElementsByType('mindmap') || [];
|
||||
}, []);
|
||||
|
||||
+2
-2
@@ -15,7 +15,7 @@ import {
|
||||
NoteShadowMap,
|
||||
StrokeStyle,
|
||||
} from '@blocksuite/affine/blocks';
|
||||
import type { Doc } from '@blocksuite/affine/store';
|
||||
import type { Blocks } from '@blocksuite/affine/store';
|
||||
import { useFramework, useLiveData } from '@toeverything/infra';
|
||||
import { isEqual } from 'lodash-es';
|
||||
import { useCallback, useMemo } from 'react';
|
||||
@@ -170,7 +170,7 @@ export const NoteSettings = () => {
|
||||
return getCurrentColor(background);
|
||||
}, [getCurrentColor, settings]);
|
||||
|
||||
const getElements = useCallback((doc: Doc) => {
|
||||
const getElements = useCallback((doc: Blocks) => {
|
||||
return doc.getBlocksByFlavour('affine:note') || [];
|
||||
}, []);
|
||||
|
||||
|
||||
+2
-2
@@ -3,7 +3,7 @@ import { SettingRow } from '@affine/component/setting-components';
|
||||
import { EditorSettingService } from '@affine/core/modules/editor-setting';
|
||||
import { useI18n } from '@affine/i18n';
|
||||
import { DefaultTheme } from '@blocksuite/affine/blocks';
|
||||
import type { Doc } from '@blocksuite/affine/store';
|
||||
import type { Blocks } from '@blocksuite/affine/store';
|
||||
import { useFramework, useLiveData } from '@toeverything/infra';
|
||||
import { isEqual } from 'lodash-es';
|
||||
import { useCallback, useMemo } from 'react';
|
||||
@@ -59,7 +59,7 @@ export const PenSettings = () => {
|
||||
[editorSetting]
|
||||
);
|
||||
|
||||
const getElements = useCallback((doc: Doc) => {
|
||||
const getElements = useCallback((doc: Blocks) => {
|
||||
const surface = getSurfaceBlock(doc);
|
||||
return surface?.getElementsByType('brush') || [];
|
||||
}, []);
|
||||
|
||||
+3
-3
@@ -26,7 +26,7 @@ import {
|
||||
StrokeStyle,
|
||||
TextAlign,
|
||||
} from '@blocksuite/affine/blocks';
|
||||
import type { Doc } from '@blocksuite/affine/store';
|
||||
import type { Blocks } from '@blocksuite/affine/store';
|
||||
import { useFramework, useLiveData } from '@toeverything/infra';
|
||||
import { isEqual } from 'lodash-es';
|
||||
import { useCallback, useMemo, useState } from 'react';
|
||||
@@ -339,7 +339,7 @@ export const ShapeSettings = () => {
|
||||
}, [editorSetting, settings, currentShape, strokeColorPalettes]);
|
||||
|
||||
const getElements = useCallback(
|
||||
(doc: Doc) => {
|
||||
(doc: Blocks) => {
|
||||
const surface = getSurfaceBlock(doc);
|
||||
if (!surface) return [];
|
||||
return surface.getElementsByType('shape').filter(node => {
|
||||
@@ -353,7 +353,7 @@ export const ShapeSettings = () => {
|
||||
);
|
||||
|
||||
const firstUpdate = useCallback(
|
||||
(doc: Doc, editorHost: EditorHost) => {
|
||||
(doc: Blocks, editorHost: EditorHost) => {
|
||||
const edgelessService = editorHost.std.getService(
|
||||
'affine:page'
|
||||
) as EdgelessRootService;
|
||||
|
||||
+4
-4
@@ -19,7 +19,7 @@ import {
|
||||
ThemeExtensionIdentifier,
|
||||
} from '@blocksuite/affine/blocks';
|
||||
import { Bound } from '@blocksuite/affine/global/utils';
|
||||
import type { Block, Doc } from '@blocksuite/affine/store';
|
||||
import type { Block, Blocks } from '@blocksuite/affine/store';
|
||||
import { createSignalFromObservable } from '@blocksuite/affine-shared/utils';
|
||||
import type { Container } from '@blocksuite/global/di';
|
||||
import type { Signal } from '@preact/signals-core';
|
||||
@@ -45,8 +45,8 @@ interface Props {
|
||||
docName: DocName;
|
||||
keyName: keyof EditorSettingSchema;
|
||||
height?: number;
|
||||
getElements: (doc: Doc) => Array<Block | GfxPrimitiveElementModel>;
|
||||
firstUpdate?: (doc: Doc, editorHost: EditorHost) => void;
|
||||
getElements: (doc: Blocks) => Array<Block | GfxPrimitiveElementModel>;
|
||||
firstUpdate?: (doc: Blocks, editorHost: EditorHost) => void;
|
||||
children?: React.ReactElement;
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ export const EdgelessSnapshot = (props: Props) => {
|
||||
children,
|
||||
} = props;
|
||||
const wrapperRef = useRef<HTMLDivElement | null>(null);
|
||||
const docRef = useRef<Doc | null>(null);
|
||||
const docRef = useRef<Blocks | null>(null);
|
||||
const editorHostRef = useRef<EditorHost | null>(null);
|
||||
const framework = useFramework();
|
||||
const { editorSetting } = framework.get(EditorSettingService);
|
||||
|
||||
+2
-2
@@ -15,7 +15,7 @@ import {
|
||||
FontWeightMap,
|
||||
TextAlign,
|
||||
} from '@blocksuite/affine/blocks';
|
||||
import type { Doc } from '@blocksuite/affine/store';
|
||||
import type { Blocks } from '@blocksuite/affine/store';
|
||||
import { useFramework, useLiveData } from '@toeverything/infra';
|
||||
import { isEqual } from 'lodash-es';
|
||||
import { useCallback, useMemo } from 'react';
|
||||
@@ -143,7 +143,7 @@ export const TextSettings = () => {
|
||||
return getCurrentColor(color);
|
||||
}, [getCurrentColor, settings]);
|
||||
|
||||
const getElements = useCallback((doc: Doc) => {
|
||||
const getElements = useCallback((doc: Blocks) => {
|
||||
return doc.getBlocksByFlavour('affine:edgeless-text') || [];
|
||||
}, []);
|
||||
|
||||
|
||||
+3
-3
@@ -1,13 +1,13 @@
|
||||
import type { SurfaceBlockModel } from '@blocksuite/affine/block-std/gfx';
|
||||
import type { FrameBlockModel } from '@blocksuite/affine/blocks';
|
||||
import type { Doc } from '@blocksuite/affine/store';
|
||||
import type { Blocks } from '@blocksuite/affine/store';
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
export function getFrameBlock(doc: Doc) {
|
||||
export function getFrameBlock(doc: Blocks) {
|
||||
const blocks = doc.getBlocksByFlavour('affine:frame');
|
||||
return blocks.length !== 0 ? (blocks[0].model as FrameBlockModel) : null;
|
||||
}
|
||||
|
||||
+2
-2
@@ -24,7 +24,7 @@ import type { Workspace } from '@affine/core/modules/workspace';
|
||||
import type { AffineDNDData } from '@affine/core/types/dnd';
|
||||
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 { useLiveData, useService } from '@toeverything/infra';
|
||||
import { forwardRef, useCallback, useEffect, useRef, useState } from 'react';
|
||||
|
||||
@@ -49,7 +49,7 @@ const Header = forwardRef<
|
||||
Header.displayName = 'forwardRef(Header)';
|
||||
|
||||
interface PageHeaderProps {
|
||||
page: Doc;
|
||||
page: Blocks;
|
||||
workspace: Workspace;
|
||||
}
|
||||
export function JournalPageHeader({ page, workspace }: PageHeaderProps) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { DebugLogger } from '@affine/debug';
|
||||
import { BlockStdScope } from '@blocksuite/affine/block-std';
|
||||
import { PageEditorBlockSpecs } from '@blocksuite/affine/blocks';
|
||||
import type { Doc } from '@blocksuite/affine/store';
|
||||
import type { Blocks } from '@blocksuite/affine/store';
|
||||
import { LiveData } from '@toeverything/infra';
|
||||
import { useMemo } from 'react';
|
||||
import { Observable } from 'rxjs';
|
||||
@@ -42,7 +42,7 @@ export function signalToLiveData<T>(
|
||||
}
|
||||
|
||||
// todo(pengx17): use rc pool?
|
||||
export function createBlockStdScope(doc: Doc) {
|
||||
export function createBlockStdScope(doc: Blocks) {
|
||||
logger.debug('createBlockStdScope', doc.id);
|
||||
const std = new BlockStdScope({
|
||||
doc,
|
||||
@@ -51,6 +51,6 @@ export function createBlockStdScope(doc: Doc) {
|
||||
return std;
|
||||
}
|
||||
|
||||
export function useBlockStdScope(doc: Doc) {
|
||||
export function useBlockStdScope(doc: Blocks) {
|
||||
return useMemo(() => createBlockStdScope(doc), [doc]);
|
||||
}
|
||||
|
||||
+2
-2
@@ -5,7 +5,7 @@ import {
|
||||
DefaultInlineManagerExtension,
|
||||
RichText,
|
||||
} from '@blocksuite/affine/blocks';
|
||||
import type { Doc } from '@blocksuite/affine/store';
|
||||
import type { Blocks } from '@blocksuite/affine/store';
|
||||
import { TextIcon } from '@blocksuite/icons/rc';
|
||||
import { type LiveData, useLiveData } from '@toeverything/infra';
|
||||
import { type CSSProperties, useEffect, useRef, useState } from 'react';
|
||||
@@ -23,7 +23,7 @@ const renderRichText = ({
|
||||
}: {
|
||||
std: BlockStdScope;
|
||||
text: Y.Text;
|
||||
doc: Doc;
|
||||
doc: Blocks;
|
||||
}) => {
|
||||
const inlineManager = std.get(DefaultInlineManagerExtension.identifier);
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { Doc as BlockSuiteDoc } from '@blocksuite/affine/store';
|
||||
import type { Blocks as BlockSuiteDoc } from '@blocksuite/affine/store';
|
||||
import { Scope } from '@toeverything/infra';
|
||||
|
||||
import type { DocRecord } from '../entities/record';
|
||||
|
||||
@@ -7,9 +7,9 @@ import { NoopLogger, Slot } from '@blocksuite/affine/global/utils';
|
||||
import {
|
||||
AwarenessStore,
|
||||
BlockCollection,
|
||||
type Blocks,
|
||||
BlockSuiteDoc,
|
||||
type CreateDocOptions,
|
||||
type Doc,
|
||||
DocCollectionMeta,
|
||||
type GetDocOptions,
|
||||
type IdGenerator,
|
||||
@@ -168,7 +168,7 @@ export class WorkspaceImpl implements Workspace {
|
||||
tags: [],
|
||||
});
|
||||
this.slots.docCreated.emit(docId);
|
||||
return this.getDoc(docId, { query, readonly }) as Doc;
|
||||
return this.getDoc(docId, { query, readonly }) as Blocks;
|
||||
}
|
||||
|
||||
dispose() {
|
||||
@@ -190,7 +190,7 @@ export class WorkspaceImpl implements Workspace {
|
||||
return space ?? null;
|
||||
}
|
||||
|
||||
getDoc(docId: string, options?: GetDocOptions): Doc | null {
|
||||
getDoc(docId: string, options?: GetDocOptions): Blocks | null {
|
||||
const collection = this.getBlockCollection(docId);
|
||||
return collection?.getDoc(options) ?? null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user