mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-25 02:13:00 +08:00
refactor(editor): rename doc to blocks (#9510)
This commit is contained in:
@@ -11,7 +11,7 @@ import type { EditorHost } from '@blocksuite/block-std';
|
|||||||
import { DataSourceBase, type PropertyMetaConfig } from '@blocksuite/data-view';
|
import { DataSourceBase, type PropertyMetaConfig } from '@blocksuite/data-view';
|
||||||
import { propertyPresets } from '@blocksuite/data-view/property-presets';
|
import { propertyPresets } from '@blocksuite/data-view/property-presets';
|
||||||
import { assertExists, Slot } from '@blocksuite/global/utils';
|
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 type { BlockMeta } from './block-meta/base.js';
|
||||||
import { blockMetaMap } from './block-meta/index.js';
|
import { blockMetaMap } from './block-meta/index.js';
|
||||||
@@ -140,7 +140,7 @@ export class BlockQueryDataSource extends DataSourceBase {
|
|||||||
return this.block.columns.find(v => v.id === id);
|
return this.block.columns.find(v => v.id === id);
|
||||||
}
|
}
|
||||||
|
|
||||||
listenToDoc(doc: Doc) {
|
listenToDoc(doc: Blocks) {
|
||||||
this.docDisposeMap.set(
|
this.docDisposeMap.set(
|
||||||
doc.id,
|
doc.id,
|
||||||
doc.slots.blockUpdated.on(v => {
|
doc.slots.blockUpdated.on(v => {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import {
|
|||||||
} from '@blocksuite/affine-model';
|
} from '@blocksuite/affine-model';
|
||||||
import { BlockService } from '@blocksuite/block-std';
|
import { BlockService } from '@blocksuite/block-std';
|
||||||
import { viewPresets } from '@blocksuite/data-view/view-presets';
|
import { viewPresets } from '@blocksuite/data-view/view-presets';
|
||||||
import type { BlockModel, Doc } from '@blocksuite/store';
|
import type { BlockModel, Blocks } from '@blocksuite/store';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
databaseViewAddView,
|
databaseViewAddView,
|
||||||
@@ -36,7 +36,7 @@ export class DatabaseBlockService extends BlockService {
|
|||||||
viewPresets = viewPresets;
|
viewPresets = viewPresets;
|
||||||
|
|
||||||
initDatabaseBlock(
|
initDatabaseBlock(
|
||||||
doc: Doc,
|
doc: Blocks,
|
||||||
model: BlockModel,
|
model: BlockModel,
|
||||||
databaseId: string,
|
databaseId: string,
|
||||||
viewType: string,
|
viewType: string,
|
||||||
|
|||||||
@@ -11,9 +11,9 @@ import { BlockStdScope } from '@blocksuite/block-std';
|
|||||||
import { assertExists } from '@blocksuite/global/utils';
|
import { assertExists } from '@blocksuite/global/utils';
|
||||||
import {
|
import {
|
||||||
type BlockModel,
|
type BlockModel,
|
||||||
|
type Blocks,
|
||||||
type BlockSnapshot,
|
type BlockSnapshot,
|
||||||
BlockViewType,
|
BlockViewType,
|
||||||
type Doc,
|
|
||||||
type DraftModel,
|
type DraftModel,
|
||||||
type Query,
|
type Query,
|
||||||
Slice,
|
Slice,
|
||||||
@@ -220,7 +220,7 @@ function filterTextModel(model: BlockModel) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getNotesFromDoc(doc: Doc) {
|
export function getNotesFromDoc(doc: Blocks) {
|
||||||
const notes = doc.root?.children.filter(
|
const notes = doc.root?.children.filter(
|
||||||
child =>
|
child =>
|
||||||
matchFlavours(child, ['affine:note']) &&
|
matchFlavours(child, ['affine:note']) &&
|
||||||
@@ -234,7 +234,7 @@ export function getNotesFromDoc(doc: Doc) {
|
|||||||
return notes;
|
return notes;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isEmptyDoc(doc: Doc | null, mode: DocMode) {
|
export function isEmptyDoc(doc: Blocks | null, mode: DocMode) {
|
||||||
if (!doc) {
|
if (!doc) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -266,7 +266,7 @@ export function isEmptyNote(note: BlockModel) {
|
|||||||
/**
|
/**
|
||||||
* Gets the document content with a max length.
|
* 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);
|
const notes = getNotesFromDoc(doc);
|
||||||
if (!notes) return;
|
if (!notes) return;
|
||||||
|
|
||||||
@@ -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);
|
const notification = std.getOptional(NotificationProvider);
|
||||||
if (!notification) return;
|
if (!notification) return;
|
||||||
|
|
||||||
@@ -365,7 +365,7 @@ export function notifyDocCreated(std: BlockStdScope, doc: Doc) {
|
|||||||
|
|
||||||
export async function convertSelectedBlocksToLinkedDoc(
|
export async function convertSelectedBlocksToLinkedDoc(
|
||||||
std: BlockStdScope,
|
std: BlockStdScope,
|
||||||
doc: Doc,
|
doc: Blocks,
|
||||||
selectedModels: DraftModel[] | Promise<DraftModel[]>,
|
selectedModels: DraftModel[] | Promise<DraftModel[]>,
|
||||||
docTitle?: string
|
docTitle?: string
|
||||||
) {
|
) {
|
||||||
@@ -399,7 +399,7 @@ export async function convertSelectedBlocksToLinkedDoc(
|
|||||||
|
|
||||||
export function createLinkedDocFromSlice(
|
export function createLinkedDocFromSlice(
|
||||||
std: BlockStdScope,
|
std: BlockStdScope,
|
||||||
doc: Doc,
|
doc: Blocks,
|
||||||
snapshots: BlockSnapshot[],
|
snapshots: BlockSnapshot[],
|
||||||
docTitle?: string
|
docTitle?: string
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import {
|
|||||||
getNextContinuousNumberedLists,
|
getNextContinuousNumberedLists,
|
||||||
matchFlavours,
|
matchFlavours,
|
||||||
} from '@blocksuite/affine-shared/utils';
|
} 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:
|
* correct target is a numbered list, which is divided into two steps:
|
||||||
@@ -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
|
* 2. find continuous lists starting from the target list and keep their order continuous
|
||||||
*/
|
*/
|
||||||
export function correctNumberedListsOrderToPrev(
|
export function correctNumberedListsOrderToPrev(
|
||||||
doc: Doc,
|
doc: Blocks,
|
||||||
modelOrId: BlockModel | string,
|
modelOrId: BlockModel | string,
|
||||||
transact = true
|
transact = true
|
||||||
) {
|
) {
|
||||||
@@ -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
|
// old numbered list has no order
|
||||||
if (model.type === 'numbered' && !Number.isInteger(model.order)) {
|
if (model.type === 'numbered' && !Number.isInteger(model.order)) {
|
||||||
correctNumberedListsOrderToPrev(doc, model, false);
|
correctNumberedListsOrderToPrev(doc, model, false);
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ import {
|
|||||||
DisposableGroup,
|
DisposableGroup,
|
||||||
type SerializedXYWH,
|
type SerializedXYWH,
|
||||||
} from '@blocksuite/global/utils';
|
} 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 { css, html, nothing, type TemplateResult } from 'lit';
|
||||||
import { query, state } from 'lit/decorators.js';
|
import { query, state } from 'lit/decorators.js';
|
||||||
import { styleMap } from 'lit/directives/style-map.js';
|
import { styleMap } from 'lit/directives/style-map.js';
|
||||||
@@ -238,7 +238,7 @@ export class SurfaceRefBlockComponent extends BlockComponent<SurfaceRefBlockMode
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
private _previewDoc: Doc | null = null;
|
private _previewDoc: Blocks | null = null;
|
||||||
|
|
||||||
private readonly _previewSpec =
|
private readonly _previewSpec =
|
||||||
SpecProvider.getInstance().getSpec('edgeless:preview');
|
SpecProvider.getInstance().getSpec('edgeless:preview');
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import type { Doc } from '@blocksuite/store';
|
import type { Blocks } from '@blocksuite/store';
|
||||||
|
|
||||||
import type { SurfaceBlockModel } from '../surface-model';
|
import type { SurfaceBlockModel } from '../surface-model';
|
||||||
|
|
||||||
export function getSurfaceBlock(doc: Doc) {
|
export function getSurfaceBlock(doc: Blocks) {
|
||||||
const blocks = doc.getBlocksByFlavour('affine:surface');
|
const blocks = doc.getBlocksByFlavour('affine:surface');
|
||||||
return blocks.length !== 0 ? (blocks[0].model as SurfaceBlockModel) : null;
|
return blocks.length !== 0 ? (blocks[0].model as SurfaceBlockModel) : null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import {
|
|||||||
stdContext,
|
stdContext,
|
||||||
} from '@blocksuite/block-std';
|
} from '@blocksuite/block-std';
|
||||||
import { WithDisposable } from '@blocksuite/global/utils';
|
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 { Text } from '@blocksuite/store';
|
||||||
import { consume } from '@lit/context';
|
import { consume } from '@lit/context';
|
||||||
import { css, html, nothing } from 'lit';
|
import { css, html, nothing } from 'lit';
|
||||||
@@ -161,7 +161,7 @@ export class BlockCaptionEditor<
|
|||||||
accessor display = false;
|
accessor display = false;
|
||||||
|
|
||||||
@consume({ context: docContext })
|
@consume({ context: docContext })
|
||||||
accessor doc!: Doc;
|
accessor doc!: Blocks;
|
||||||
|
|
||||||
@query('.block-caption-editor')
|
@query('.block-caption-editor')
|
||||||
accessor input!: HTMLInputElement;
|
accessor input!: HTMLInputElement;
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import {
|
|||||||
ZERO_WIDTH_NON_JOINER,
|
ZERO_WIDTH_NON_JOINER,
|
||||||
ZERO_WIDTH_SPACE,
|
ZERO_WIDTH_SPACE,
|
||||||
} from '@blocksuite/inline';
|
} from '@blocksuite/inline';
|
||||||
import type { Doc, DocMeta } from '@blocksuite/store';
|
import type { Blocks, DocMeta } from '@blocksuite/store';
|
||||||
import { css, html, nothing } from 'lit';
|
import { css, html, nothing } from 'lit';
|
||||||
import { property, state } from 'lit/decorators.js';
|
import { property, state } from 'lit/decorators.js';
|
||||||
import { choose } from 'lit/directives/choose.js';
|
import { choose } from 'lit/directives/choose.js';
|
||||||
@@ -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;
|
const refAttribute = this.delta.attributes?.reference;
|
||||||
if (!refAttribute) {
|
if (!refAttribute) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import type { BlockStdScope, EditorHost } from '@blocksuite/block-std';
|
import type { BlockStdScope, EditorHost } from '@blocksuite/block-std';
|
||||||
import type { GfxModel } from '@blocksuite/block-std/gfx';
|
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 {
|
export abstract class MenuContext {
|
||||||
abstract get doc(): Doc;
|
abstract get doc(): Blocks;
|
||||||
|
|
||||||
get firstElement(): GfxModel | null {
|
get firstElement(): GfxModel | null {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import {
|
|||||||
LinkedPageIcon,
|
LinkedPageIcon,
|
||||||
PageIcon,
|
PageIcon,
|
||||||
} from '@blocksuite/icons/lit';
|
} 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 { computed, type Signal, signal } from '@preact/signals-core';
|
||||||
import type { TemplateResult } from 'lit';
|
import type { TemplateResult } from 'lit';
|
||||||
|
|
||||||
@@ -70,9 +70,9 @@ export class DocDisplayMetaService
|
|||||||
|
|
||||||
readonly disposables: Disposable[] = [];
|
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) {
|
static override setup(di: Container) {
|
||||||
di.addImpl(DocDisplayMetaProvider, this, [StdIdentifier]);
|
di.addImpl(DocDisplayMetaProvider, this, [StdIdentifier]);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { BlockModel, Doc, DraftModel } from '@blocksuite/store';
|
import type { BlockModel, Blocks, DraftModel } from '@blocksuite/store';
|
||||||
import { minimatch } from 'minimatch';
|
import { minimatch } from 'minimatch';
|
||||||
|
|
||||||
export function matchFlavours<Key extends (keyof BlockSuite.BlockModels)[]>(
|
export function matchFlavours<Key extends (keyof BlockSuite.BlockModels)[]>(
|
||||||
@@ -14,7 +14,7 @@ export function matchFlavours<Key extends (keyof BlockSuite.BlockModels)[]>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function isInsideBlockByFlavour(
|
export function isInsideBlockByFlavour(
|
||||||
doc: Doc,
|
doc: Blocks,
|
||||||
block: BlockModel | string,
|
block: BlockModel | string,
|
||||||
flavour: string
|
flavour: string
|
||||||
): boolean {
|
): boolean {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { type NoteBlockModel, NoteDisplayMode } from '@blocksuite/affine-model';
|
import { type NoteBlockModel, NoteDisplayMode } from '@blocksuite/affine-model';
|
||||||
import type { BlockComponent, EditorHost } from '@blocksuite/block-std';
|
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';
|
import { matchFlavours } from './checker.js';
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ export function findNoteBlockModel(model: BlockModel) {
|
|||||||
) as NoteBlockModel | null;
|
) as NoteBlockModel | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getLastNoteBlock(doc: Doc) {
|
export function getLastNoteBlock(doc: Blocks) {
|
||||||
let note: NoteBlockModel | null = null;
|
let note: NoteBlockModel | null = null;
|
||||||
if (!doc.root) return null;
|
if (!doc.root) return null;
|
||||||
const { children } = doc.root;
|
const { children } = doc.root;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { ListBlockModel } from '@blocksuite/affine-model';
|
import type { ListBlockModel } from '@blocksuite/affine-model';
|
||||||
import type { BlockStdScope } from '@blocksuite/block-std';
|
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';
|
import { matchFlavours } from './checker.js';
|
||||||
|
|
||||||
@@ -9,7 +9,7 @@ import { matchFlavours } from './checker.js';
|
|||||||
* typically used for updating list numbers. The result not contains the list passed in.
|
* typically used for updating list numbers. The result not contains the list passed in.
|
||||||
*/
|
*/
|
||||||
export function getNextContinuousNumberedLists(
|
export function getNextContinuousNumberedLists(
|
||||||
doc: Doc,
|
doc: Blocks,
|
||||||
modelOrId: BlockModel | string
|
modelOrId: BlockModel | string
|
||||||
): ListBlockModel[] {
|
): ListBlockModel[] {
|
||||||
const model =
|
const model =
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import type { BlockModel, Doc, Text } from '@blocksuite/store';
|
import type { BlockModel, Blocks, Text } from '@blocksuite/store';
|
||||||
|
|
||||||
export function transformModel(
|
export function transformModel(
|
||||||
model: BlockModel,
|
model: BlockModel,
|
||||||
flavour: BlockSuite.Flavour,
|
flavour: BlockSuite.Flavour,
|
||||||
props?: Parameters<Doc['addBlock']>[1]
|
props?: Parameters<Blocks['addBlock']>[1]
|
||||||
) {
|
) {
|
||||||
const doc = model.doc;
|
const doc = model.doc;
|
||||||
const parent = doc.getParent(model);
|
const parent = doc.getParent(model);
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import {
|
|||||||
RootBlockSchema,
|
RootBlockSchema,
|
||||||
} from '@blocksuite/affine-model';
|
} from '@blocksuite/affine-model';
|
||||||
import { propertyModelPresets } from '@blocksuite/data-view/property-pure-presets';
|
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 { Schema } from '@blocksuite/store';
|
||||||
import {
|
import {
|
||||||
createAutoIncrementIdGenerator,
|
createAutoIncrementIdGenerator,
|
||||||
@@ -49,7 +49,7 @@ function createTestDoc(docId = 'doc0') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
describe('DatabaseManager', () => {
|
describe('DatabaseManager', () => {
|
||||||
let doc: Doc;
|
let doc: Blocks;
|
||||||
let db: DatabaseBlockModel;
|
let db: DatabaseBlockModel;
|
||||||
|
|
||||||
let rootId: BlockModel['id'];
|
let rootId: BlockModel['id'];
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import type { GfxBlockElementModel } from '@blocksuite/block-std/gfx';
|
|||||||
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
||||||
import type { IBound } from '@blocksuite/global/utils';
|
import type { IBound } from '@blocksuite/global/utils';
|
||||||
import { Bound } from '@blocksuite/global/utils';
|
import { Bound } from '@blocksuite/global/utils';
|
||||||
import type { Doc } from '@blocksuite/store';
|
import type { Blocks } from '@blocksuite/store';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
getBlockComponentByModel,
|
getBlockComponentByModel,
|
||||||
@@ -110,7 +110,7 @@ export class ExportManager {
|
|||||||
await Promise.all(promises);
|
await Promise.all(promises);
|
||||||
};
|
};
|
||||||
|
|
||||||
get doc(): Doc {
|
get doc(): Blocks {
|
||||||
return this.std.doc;
|
return this.std.doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { HtmlAdapter } from '@blocksuite/affine-shared/adapters';
|
import { HtmlAdapter } from '@blocksuite/affine-shared/adapters';
|
||||||
import { Container } from '@blocksuite/global/di';
|
import { Container } from '@blocksuite/global/di';
|
||||||
import { sha } from '@blocksuite/global/utils';
|
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 { extMimeMap, Job } from '@blocksuite/store';
|
||||||
|
|
||||||
import { defaultBlockHtmlAdapterMatchers } from '../adapters/html/block-matcher.js';
|
import { defaultBlockHtmlAdapterMatchers } from '../adapters/html/block-matcher.js';
|
||||||
@@ -43,7 +43,7 @@ const provider = container.provider();
|
|||||||
* @param doc - The doc to be exported.
|
* @param doc - The doc to be exported.
|
||||||
* @returns A Promise that resolves when the export is complete.
|
* @returns A Promise that resolves when the export is complete.
|
||||||
*/
|
*/
|
||||||
async function exportDoc(doc: Doc) {
|
async function exportDoc(doc: Blocks) {
|
||||||
const job = new Job({
|
const job = new Job({
|
||||||
schema: doc.schema,
|
schema: doc.schema,
|
||||||
blobCRUD: doc.blobSync,
|
blobCRUD: doc.blobSync,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { MarkdownAdapter } from '@blocksuite/affine-shared/adapters';
|
|||||||
import { Container } from '@blocksuite/global/di';
|
import { Container } from '@blocksuite/global/di';
|
||||||
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
||||||
import { assertExists, sha } from '@blocksuite/global/utils';
|
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 { extMimeMap, Job } from '@blocksuite/store';
|
||||||
|
|
||||||
import { defaultBlockMarkdownAdapterMatchers } from '../adapters/index.js';
|
import { defaultBlockMarkdownAdapterMatchers } from '../adapters/index.js';
|
||||||
@@ -28,7 +28,7 @@ const container = new Container();
|
|||||||
const provider = container.provider();
|
const provider = container.provider();
|
||||||
|
|
||||||
type ImportMarkdownToBlockOptions = {
|
type ImportMarkdownToBlockOptions = {
|
||||||
doc: Doc;
|
doc: Blocks;
|
||||||
markdown: string;
|
markdown: string;
|
||||||
blockId: string;
|
blockId: string;
|
||||||
};
|
};
|
||||||
@@ -49,7 +49,7 @@ type ImportMarkdownZipOptions = {
|
|||||||
* @param doc The doc to export
|
* @param doc The doc to export
|
||||||
* @returns A Promise that resolves when the export is complete
|
* @returns A Promise that resolves when the export is complete
|
||||||
*/
|
*/
|
||||||
async function exportDoc(doc: Doc) {
|
async function exportDoc(doc: Blocks) {
|
||||||
const job = new Job({
|
const job = new Job({
|
||||||
schema: doc.schema,
|
schema: doc.schema,
|
||||||
blobCRUD: doc.blobSync,
|
blobCRUD: doc.blobSync,
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import { sha } from '@blocksuite/global/utils';
|
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 { extMimeMap, getAssetName, Job } from '@blocksuite/store';
|
||||||
|
|
||||||
import { download, Unzip, Zip } from '../transformers/utils.js';
|
import { download, Unzip, Zip } from '../transformers/utils.js';
|
||||||
import { replaceIdMiddleware, titleMiddleware } from './middlewares.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 zip = new Zip();
|
||||||
const job = new Job({
|
const job = new Job({
|
||||||
schema: collection.schema,
|
schema: collection.schema,
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import type {
|
|||||||
GroupElementModel,
|
GroupElementModel,
|
||||||
} from '@blocksuite/affine-model';
|
} from '@blocksuite/affine-model';
|
||||||
import type { Slot } from '@blocksuite/global/utils';
|
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. */
|
/** Common context interface definition for block models. */
|
||||||
|
|
||||||
@@ -14,7 +14,7 @@ type EditorSlots = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type AbstractEditor = {
|
export type AbstractEditor = {
|
||||||
doc: Doc;
|
doc: Blocks;
|
||||||
mode: DocMode;
|
mode: DocMode;
|
||||||
readonly slots: EditorSlots;
|
readonly slots: EditorSlots;
|
||||||
} & HTMLElement;
|
} & HTMLElement;
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import {
|
|||||||
} from '@blocksuite/affine-shared/adapters';
|
} from '@blocksuite/affine-shared/adapters';
|
||||||
import type { BlockComponent, UIEventHandler } from '@blocksuite/block-std';
|
import type { BlockComponent, UIEventHandler } from '@blocksuite/block-std';
|
||||||
import { DisposableGroup } from '@blocksuite/global/utils';
|
import { DisposableGroup } from '@blocksuite/global/utils';
|
||||||
import type { BlockSnapshot, Doc } from '@blocksuite/store';
|
import type { Blocks, BlockSnapshot } from '@blocksuite/store';
|
||||||
|
|
||||||
import { MixTextAdapter } from '../../_common/adapters/index.js';
|
import { MixTextAdapter } from '../../_common/adapters/index.js';
|
||||||
import {
|
import {
|
||||||
@@ -99,7 +99,7 @@ export class PageClipboard {
|
|||||||
|
|
||||||
onBlockSnapshotPaste = async (
|
onBlockSnapshotPaste = async (
|
||||||
snapshot: BlockSnapshot,
|
snapshot: BlockSnapshot,
|
||||||
doc: Doc,
|
doc: Blocks,
|
||||||
parent?: string,
|
parent?: string,
|
||||||
index?: number
|
index?: number
|
||||||
) => {
|
) => {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import {
|
|||||||
} from '@blocksuite/block-std';
|
} from '@blocksuite/block-std';
|
||||||
import { GfxControllerIdentifier } from '@blocksuite/block-std/gfx';
|
import { GfxControllerIdentifier } from '@blocksuite/block-std/gfx';
|
||||||
import { DisposableGroup, Vec, WithDisposable } from '@blocksuite/global/utils';
|
import { DisposableGroup, Vec, WithDisposable } from '@blocksuite/global/utils';
|
||||||
import type { Doc } from '@blocksuite/store';
|
import type { Blocks } from '@blocksuite/store';
|
||||||
import { consume } from '@lit/context';
|
import { consume } from '@lit/context';
|
||||||
import { css, html, LitElement } from 'lit';
|
import { css, html, LitElement } from 'lit';
|
||||||
import { property, query } from 'lit/decorators.js';
|
import { property, query } from 'lit/decorators.js';
|
||||||
@@ -150,7 +150,7 @@ export class EdgelessConnectorHandle extends WithDisposable(LitElement) {
|
|||||||
@consume({
|
@consume({
|
||||||
context: docContext,
|
context: docContext,
|
||||||
})
|
})
|
||||||
accessor doc!: Doc;
|
accessor doc!: Blocks;
|
||||||
|
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
accessor edgeless!: EdgelessRootBlockComponent;
|
accessor edgeless!: EdgelessRootBlockComponent;
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import {
|
|||||||
DisposableGroup,
|
DisposableGroup,
|
||||||
WithDisposable,
|
WithDisposable,
|
||||||
} from '@blocksuite/global/utils';
|
} from '@blocksuite/global/utils';
|
||||||
import { BlockViewType, type Doc, type Query } from '@blocksuite/store';
|
import { type Blocks, BlockViewType, type Query } from '@blocksuite/store';
|
||||||
import { css, html, nothing, type PropertyValues } from 'lit';
|
import { css, html, nothing, type PropertyValues } from 'lit';
|
||||||
import { property, query, state } from 'lit/decorators.js';
|
import { property, query, state } from 'lit/decorators.js';
|
||||||
import { styleMap } from 'lit/directives/style-map.js';
|
import { styleMap } from 'lit/directives/style-map.js';
|
||||||
@@ -78,7 +78,7 @@ export class FramePreview extends WithDisposable(ShadowlessElement) {
|
|||||||
|
|
||||||
private _frameDisposables: DisposableGroup | null = null;
|
private _frameDisposables: DisposableGroup | null = null;
|
||||||
|
|
||||||
private _previewDoc: Doc | null = null;
|
private _previewDoc: Blocks | null = null;
|
||||||
|
|
||||||
private readonly _previewSpec =
|
private readonly _previewSpec =
|
||||||
SpecProvider.getInstance().getSpec('edgeless:preview');
|
SpecProvider.getInstance().getSpec('edgeless:preview');
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import {
|
|||||||
type IVec,
|
type IVec,
|
||||||
type SerializedXYWH,
|
type SerializedXYWH,
|
||||||
} from '@blocksuite/global/utils';
|
} from '@blocksuite/global/utils';
|
||||||
import type { Doc } from '@blocksuite/store';
|
import type { Blocks } from '@blocksuite/store';
|
||||||
import { Text } from '@blocksuite/store';
|
import { Text } from '@blocksuite/store';
|
||||||
import * as Y from 'yjs';
|
import * as Y from 'yjs';
|
||||||
|
|
||||||
@@ -463,7 +463,7 @@ export class EdgelessFrameManager extends GfxExtension {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getNotesInFrameBound(
|
export function getNotesInFrameBound(
|
||||||
doc: Doc,
|
doc: Blocks,
|
||||||
frame: FrameBlockModel,
|
frame: FrameBlockModel,
|
||||||
fullyContained: boolean = true
|
fullyContained: boolean = true
|
||||||
) {
|
) {
|
||||||
@@ -481,7 +481,7 @@ export function getNotesInFrameBound(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getBlocksInFrameBound(
|
export function getBlocksInFrameBound(
|
||||||
doc: Doc,
|
doc: Blocks,
|
||||||
model: FrameBlockModel,
|
model: FrameBlockModel,
|
||||||
fullyContained: boolean = true
|
fullyContained: boolean = true
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { DocModeProvider } from '@blocksuite/affine-shared/services';
|
|||||||
import { getBlockProps } from '@blocksuite/affine-shared/utils';
|
import { getBlockProps } from '@blocksuite/affine-shared/utils';
|
||||||
import type { EditorHost } from '@blocksuite/block-std';
|
import type { EditorHost } from '@blocksuite/block-std';
|
||||||
import { GfxBlockElementModel } from '@blocksuite/block-std/gfx';
|
import { GfxBlockElementModel } from '@blocksuite/block-std/gfx';
|
||||||
import { type BlockModel, type Doc } from '@blocksuite/store';
|
import { type BlockModel, type Blocks } from '@blocksuite/store';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
getElementProps,
|
getElementProps,
|
||||||
@@ -14,7 +14,11 @@ import {
|
|||||||
} from '../../../edgeless/utils/clone-utils.js';
|
} from '../../../edgeless/utils/clone-utils.js';
|
||||||
import { isFrameBlock, isNoteBlock } from '../../../edgeless/utils/query.js';
|
import { isFrameBlock, isNoteBlock } from '../../../edgeless/utils/query.js';
|
||||||
|
|
||||||
function addBlocksToDoc(targetDoc: Doc, model: BlockModel, parentId: string) {
|
function addBlocksToDoc(
|
||||||
|
targetDoc: Blocks,
|
||||||
|
model: BlockModel,
|
||||||
|
parentId: string
|
||||||
|
) {
|
||||||
// Add current block to linked doc
|
// Add current block to linked doc
|
||||||
const blockProps = getBlockProps(model);
|
const blockProps = getBlockProps(model);
|
||||||
const newModelId = targetDoc.addBlock(
|
const newModelId = targetDoc.addBlock(
|
||||||
@@ -32,7 +36,7 @@ function addBlocksToDoc(targetDoc: Doc, model: BlockModel, parentId: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function createLinkedDocFromNote(
|
export function createLinkedDocFromNote(
|
||||||
doc: Doc,
|
doc: Blocks,
|
||||||
note: NoteBlockModel,
|
note: NoteBlockModel,
|
||||||
docTitle?: string
|
docTitle?: string
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { SignalWatcher, WithDisposable } from '@blocksuite/global/utils';
|
import { SignalWatcher, WithDisposable } from '@blocksuite/global/utils';
|
||||||
import type { Doc } from '@blocksuite/store';
|
import type { Blocks } from '@blocksuite/store';
|
||||||
import { html } from 'lit';
|
import { html } from 'lit';
|
||||||
import { customElement, property } from 'lit/decorators.js';
|
import { customElement, property } from 'lit/decorators.js';
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ export class TestEditorContainer extends SignalWatcher(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
accessor doc!: Doc;
|
accessor doc!: Blocks;
|
||||||
|
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
accessor specs: ExtensionType[] = [];
|
accessor specs: ExtensionType[] = [];
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ import type { ServiceProvider } from '@blocksuite/global/di';
|
|||||||
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
||||||
import type {
|
import type {
|
||||||
BaseAdapter,
|
BaseAdapter,
|
||||||
|
Blocks,
|
||||||
BlockSnapshot,
|
BlockSnapshot,
|
||||||
Doc,
|
|
||||||
Job,
|
Job,
|
||||||
JobMiddleware,
|
JobMiddleware,
|
||||||
Slice,
|
Slice,
|
||||||
@@ -110,7 +110,7 @@ export class Clipboard extends LifeCycleWatcher {
|
|||||||
|
|
||||||
private readonly _getSnapshotByPriority = async (
|
private readonly _getSnapshotByPriority = async (
|
||||||
getItem: (type: string) => string | File[],
|
getItem: (type: string) => string | File[],
|
||||||
doc: Doc,
|
doc: Blocks,
|
||||||
parent?: string,
|
parent?: string,
|
||||||
index?: number
|
index?: number
|
||||||
) => {
|
) => {
|
||||||
@@ -182,7 +182,7 @@ export class Clipboard extends LifeCycleWatcher {
|
|||||||
|
|
||||||
duplicateSlice = async (
|
duplicateSlice = async (
|
||||||
slice: Slice,
|
slice: Slice,
|
||||||
doc: Doc,
|
doc: Blocks,
|
||||||
parent?: string,
|
parent?: string,
|
||||||
index?: number,
|
index?: number,
|
||||||
type = 'BLOCKSUITE/SNAPSHOT'
|
type = 'BLOCKSUITE/SNAPSHOT'
|
||||||
@@ -201,7 +201,7 @@ export class Clipboard extends LifeCycleWatcher {
|
|||||||
|
|
||||||
paste = async (
|
paste = async (
|
||||||
event: ClipboardEvent,
|
event: ClipboardEvent,
|
||||||
doc: Doc,
|
doc: Blocks,
|
||||||
parent?: string,
|
parent?: string,
|
||||||
index?: number
|
index?: number
|
||||||
) => {
|
) => {
|
||||||
@@ -238,7 +238,7 @@ export class Clipboard extends LifeCycleWatcher {
|
|||||||
|
|
||||||
pasteBlockSnapshot = async (
|
pasteBlockSnapshot = async (
|
||||||
snapshot: BlockSnapshot,
|
snapshot: BlockSnapshot,
|
||||||
doc: Doc,
|
doc: Blocks,
|
||||||
parent?: string,
|
parent?: string,
|
||||||
index?: number
|
index?: number
|
||||||
) => {
|
) => {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import {
|
|||||||
getBoundWithRotation,
|
getBoundWithRotation,
|
||||||
intersects,
|
intersects,
|
||||||
} from '@blocksuite/global/utils';
|
} 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 { compare } from '../utils/layer.js';
|
||||||
import { GfxBlockElementModel } from './model/gfx-block-model.js';
|
import { GfxBlockElementModel } from './model/gfx-block-model.js';
|
||||||
@@ -361,7 +361,7 @@ export class GridManager {
|
|||||||
this.add(element);
|
this.add(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(blocks: { doc?: Doc; surface?: SurfaceBlockModel | null }) {
|
watch(blocks: { doc?: Blocks; surface?: SurfaceBlockModel | null }) {
|
||||||
const disposables: { dispose: () => void }[] = [];
|
const disposables: { dispose: () => void }[] = [];
|
||||||
const { doc, surface } = blocks;
|
const { doc, surface } = blocks;
|
||||||
const isRenderableBlock = (
|
const isRenderableBlock = (
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
last,
|
last,
|
||||||
Slot,
|
Slot,
|
||||||
} from '@blocksuite/global/utils';
|
} from '@blocksuite/global/utils';
|
||||||
import type { Doc } from '@blocksuite/store';
|
import type { Blocks } from '@blocksuite/store';
|
||||||
import { generateKeyBetween } from 'fractional-indexing';
|
import { generateKeyBetween } from 'fractional-indexing';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -100,7 +100,7 @@ export class LayerManager {
|
|||||||
};
|
};
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly _doc: Doc,
|
private readonly _doc: Blocks,
|
||||||
private _surface: SurfaceBlockModel | null,
|
private _surface: SurfaceBlockModel | null,
|
||||||
options: {
|
options: {
|
||||||
watch: boolean;
|
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;
|
const { doc, surface } = blocks;
|
||||||
|
|
||||||
if (doc) {
|
if (doc) {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { ServiceProvider } from '@blocksuite/global/di';
|
import type { ServiceProvider } from '@blocksuite/global/di';
|
||||||
import { Container } from '@blocksuite/global/di';
|
import { Container } from '@blocksuite/global/di';
|
||||||
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
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 { Clipboard } from '../clipboard/index.js';
|
||||||
import { CommandManager } from '../command/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';
|
import { ViewStore } from '../view/view-store.js';
|
||||||
|
|
||||||
export interface BlockStdOptions {
|
export interface BlockStdOptions {
|
||||||
doc: Doc;
|
doc: Blocks;
|
||||||
extensions: ExtensionType[];
|
extensions: ExtensionType[];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,7 +60,7 @@ export class BlockStdScope {
|
|||||||
|
|
||||||
readonly container: Container;
|
readonly container: Container;
|
||||||
|
|
||||||
readonly doc: Doc;
|
readonly doc: Blocks;
|
||||||
|
|
||||||
readonly provider: ServiceProvider;
|
readonly provider: ServiceProvider;
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import type { Doc } from '@blocksuite/store';
|
import type { Blocks } from '@blocksuite/store';
|
||||||
import { effect } from '@preact/signals-core';
|
import { effect } from '@preact/signals-core';
|
||||||
|
|
||||||
import { SurfaceBlockModel } from '../gfx/model/surface/surface-model.js';
|
import { SurfaceBlockModel } from '../gfx/model/surface/surface-model.js';
|
||||||
|
|
||||||
export function onSurfaceAdded(
|
export function onSurfaceAdded(
|
||||||
doc: Doc,
|
doc: Blocks,
|
||||||
callback: (model: SurfaceBlockModel | null) => void
|
callback: (model: SurfaceBlockModel | null) => void
|
||||||
) {
|
) {
|
||||||
let found = false;
|
let found = false;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { nToLast } from '@blocksuite/global/utils';
|
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 { GfxLocalElementModel } from '../gfx/index.js';
|
||||||
import type { Layer } from '../gfx/layer.js';
|
import type { Layer } from '../gfx/layer.js';
|
||||||
@@ -82,7 +82,7 @@ export function isInRange(edges: [GfxModel, GfxModel], target: GfxModel) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function renderableInEdgeless(
|
export function renderableInEdgeless(
|
||||||
doc: Doc,
|
doc: Blocks,
|
||||||
surface: SurfaceBlockModel,
|
surface: SurfaceBlockModel,
|
||||||
block: GfxBlockElementModel
|
block: GfxBlockElementModel
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { Doc } from '@blocksuite/store';
|
import type { Blocks } from '@blocksuite/store';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
type GfxCompatibleInterface,
|
type GfxCompatibleInterface,
|
||||||
@@ -124,13 +124,16 @@ export function isLockedImpl(element: GfxCompatibleInterface): boolean {
|
|||||||
return isLockedBySelfImpl(element) || isLockedByAncestorImpl(element);
|
return isLockedBySelfImpl(element) || isLockedByAncestorImpl(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function lockElementImpl(doc: Doc, element: GfxCompatibleInterface) {
|
export function lockElementImpl(doc: Blocks, element: GfxCompatibleInterface) {
|
||||||
doc.transact(() => {
|
doc.transact(() => {
|
||||||
element.lockedBySelf = true;
|
element.lockedBySelf = true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function unlockElementImpl(doc: Doc, element: GfxCompatibleInterface) {
|
export function unlockElementImpl(
|
||||||
|
doc: Blocks,
|
||||||
|
element: GfxCompatibleInterface
|
||||||
|
) {
|
||||||
doc.transact(() => {
|
doc.transact(() => {
|
||||||
element.lockedBySelf = false;
|
element.lockedBySelf = false;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
||||||
import { SignalWatcher, WithDisposable } from '@blocksuite/global/utils';
|
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 { consume, provide } from '@lit/context';
|
||||||
import { computed } from '@preact/signals-core';
|
import { computed } from '@preact/signals-core';
|
||||||
import { nothing, type TemplateResult } from 'lit';
|
import { nothing, type TemplateResult } from 'lit';
|
||||||
@@ -23,7 +23,7 @@ import { ShadowlessElement } from './shadowless-element.js';
|
|||||||
import type { WidgetComponent } from './widget-component.js';
|
import type { WidgetComponent } from './widget-component.js';
|
||||||
|
|
||||||
@requiredProperties({
|
@requiredProperties({
|
||||||
doc: PropTypes.instanceOf(Doc),
|
doc: PropTypes.instanceOf(Blocks),
|
||||||
std: PropTypes.object,
|
std: PropTypes.object,
|
||||||
widgets: PropTypes.recordOf(PropTypes.object),
|
widgets: PropTypes.recordOf(PropTypes.object),
|
||||||
})
|
})
|
||||||
@@ -307,7 +307,7 @@ export class BlockComponent<
|
|||||||
private accessor _service: Service | null = null;
|
private accessor _service: Service | null = null;
|
||||||
|
|
||||||
@consume({ context: docContext })
|
@consume({ context: docContext })
|
||||||
accessor doc!: Doc;
|
accessor doc!: Blocks;
|
||||||
|
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
accessor viewType: BlockViewType = BlockViewType.Display;
|
accessor viewType: BlockViewType = BlockViewType.Display;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import {
|
|||||||
handleError,
|
handleError,
|
||||||
} from '@blocksuite/global/exceptions';
|
} from '@blocksuite/global/exceptions';
|
||||||
import { SignalWatcher, Slot, WithDisposable } from '@blocksuite/global/utils';
|
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 { createContext, provide } from '@lit/context';
|
||||||
import { css, LitElement, nothing, type TemplateResult } from 'lit';
|
import { css, LitElement, nothing, type TemplateResult } from 'lit';
|
||||||
import { property } from 'lit/decorators.js';
|
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 { BLOCK_ID_ATTR, WIDGET_ID_ATTR } from './consts.js';
|
||||||
import { ShadowlessElement } from './shadowless-element.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');
|
export const stdContext = createContext<BlockStdScope>('std');
|
||||||
|
|
||||||
@requiredProperties({
|
@requiredProperties({
|
||||||
doc: PropTypes.instanceOf(Doc),
|
doc: PropTypes.instanceOf(Blocks),
|
||||||
std: PropTypes.object,
|
std: PropTypes.object,
|
||||||
})
|
})
|
||||||
export class EditorHost extends SignalWatcher(
|
export class EditorHost extends SignalWatcher(
|
||||||
@@ -189,7 +189,7 @@ export class EditorHost extends SignalWatcher(
|
|||||||
|
|
||||||
@provide({ context: docContext })
|
@provide({ context: docContext })
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
accessor doc!: Doc;
|
accessor doc!: Blocks;
|
||||||
|
|
||||||
@provide({ context: stdContext })
|
@provide({ context: stdContext })
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { SignalWatcher, WithDisposable } from '@blocksuite/global/utils';
|
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 { consume } from '@lit/context';
|
||||||
import { LitElement } from 'lit';
|
import { LitElement } from 'lit';
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ export class WidgetComponent<
|
|||||||
}
|
}
|
||||||
|
|
||||||
@consume({ context: docContext })
|
@consume({ context: docContext })
|
||||||
private accessor _doc!: Doc;
|
private accessor _doc!: Blocks;
|
||||||
|
|
||||||
@consume({ context: modelContext })
|
@consume({ context: modelContext })
|
||||||
private accessor _model!: Model;
|
private accessor _model!: Model;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { assert, beforeEach, describe, expect, it, vi } from 'vitest';
|
|||||||
import { applyUpdate, encodeStateAsUpdate } from 'yjs';
|
import { applyUpdate, encodeStateAsUpdate } from 'yjs';
|
||||||
|
|
||||||
import { COLLECTION_VERSION, PAGE_VERSION } from '../consts.js';
|
import { COLLECTION_VERSION, PAGE_VERSION } from '../consts.js';
|
||||||
import type { BlockModel, BlockSchemaType, Doc } from '../index.js';
|
import type { BlockModel, Blocks, BlockSchemaType } from '../index.js';
|
||||||
import { Schema } from '../index.js';
|
import { Schema } from '../index.js';
|
||||||
import type { DocMeta } from '../store/workspace.js';
|
import type { DocMeta } from '../store/workspace.js';
|
||||||
import { TestWorkspace } from '../test/test-workspace.js';
|
import { TestWorkspace } from '../test/test-workspace.js';
|
||||||
@@ -54,7 +54,7 @@ function waitOnce<T>(slot: Slot<T>) {
|
|||||||
return new Promise<T>(resolve => slot.once(val => resolve(val)));
|
return new Promise<T>(resolve => slot.once(val => resolve(val)));
|
||||||
}
|
}
|
||||||
|
|
||||||
function createRoot(doc: Doc) {
|
function createRoot(doc: Blocks) {
|
||||||
doc.addBlock('affine:page');
|
doc.addBlock('affine:page');
|
||||||
if (!doc.root) throw new Error('root not found');
|
if (!doc.root) throw new Error('root not found');
|
||||||
return doc.root;
|
return doc.root;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { BlockSuiteError } from '@blocksuite/global/exceptions';
|
import { BlockSuiteError } from '@blocksuite/global/exceptions';
|
||||||
|
|
||||||
import type { Doc } from '../store/index.js';
|
import type { Blocks } from '../store/index.js';
|
||||||
import type { AssetsManager } from '../transformer/assets.js';
|
import type { AssetsManager } from '../transformer/assets.js';
|
||||||
import type { DraftModel, Job, Slice } from '../transformer/index.js';
|
import type { DraftModel, Job, Slice } from '../transformer/index.js';
|
||||||
import type {
|
import type {
|
||||||
@@ -93,7 +93,7 @@ export abstract class BaseAdapter<AdapterTarget = unknown> {
|
|||||||
| Promise<FromBlockSnapshotResult<AdapterTarget>>
|
| Promise<FromBlockSnapshotResult<AdapterTarget>>
|
||||||
| FromBlockSnapshotResult<AdapterTarget>;
|
| FromBlockSnapshotResult<AdapterTarget>;
|
||||||
|
|
||||||
async fromDoc(doc: Doc) {
|
async fromDoc(doc: Blocks) {
|
||||||
try {
|
try {
|
||||||
const docSnapshot = this.job.docToSnapshot(doc);
|
const docSnapshot = this.job.docToSnapshot(doc);
|
||||||
if (!docSnapshot) return;
|
if (!docSnapshot) return;
|
||||||
@@ -138,7 +138,7 @@ export abstract class BaseAdapter<AdapterTarget = unknown> {
|
|||||||
|
|
||||||
async toBlock(
|
async toBlock(
|
||||||
payload: ToBlockSnapshotPayload<AdapterTarget>,
|
payload: ToBlockSnapshotPayload<AdapterTarget>,
|
||||||
doc: Doc,
|
doc: Blocks,
|
||||||
parent?: string,
|
parent?: string,
|
||||||
index?: number
|
index?: number
|
||||||
) {
|
) {
|
||||||
@@ -175,7 +175,7 @@ export abstract class BaseAdapter<AdapterTarget = unknown> {
|
|||||||
|
|
||||||
async toSlice(
|
async toSlice(
|
||||||
payload: ToSliceSnapshotPayload<AdapterTarget>,
|
payload: ToSliceSnapshotPayload<AdapterTarget>,
|
||||||
doc: Doc,
|
doc: Blocks,
|
||||||
parent?: string,
|
parent?: string,
|
||||||
index?: number
|
index?: number
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { z } from 'zod';
|
|||||||
import { Boxed } from '../reactive/boxed.js';
|
import { Boxed } from '../reactive/boxed.js';
|
||||||
import { Text } from '../reactive/text.js';
|
import { Text } from '../reactive/text.js';
|
||||||
import type { YBlock } from '../store/doc/block/index.js';
|
import type { YBlock } from '../store/doc/block/index.js';
|
||||||
import type { Doc } from '../store/index.js';
|
import type { Blocks } from '../store/index.js';
|
||||||
import type { BaseBlockTransformer } from '../transformer/base.js';
|
import type { BaseBlockTransformer } from '../transformer/base.js';
|
||||||
|
|
||||||
const FlavourSchema = z.string();
|
const FlavourSchema = z.string();
|
||||||
@@ -160,7 +160,7 @@ export class BlockModel<
|
|||||||
/**
|
/**
|
||||||
* @deprecated use doc instead
|
* @deprecated use doc instead
|
||||||
*/
|
*/
|
||||||
page!: Doc;
|
page!: Blocks;
|
||||||
|
|
||||||
private readonly _childModels = computed(() => {
|
private readonly _childModels = computed(() => {
|
||||||
const value: BlockModel[] = [];
|
const value: BlockModel[] = [];
|
||||||
@@ -224,7 +224,7 @@ export class BlockModel<
|
|||||||
return this.page;
|
return this.page;
|
||||||
}
|
}
|
||||||
|
|
||||||
set doc(doc: Doc) {
|
set doc(doc: Blocks) {
|
||||||
this.page = doc;
|
this.page = doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import type { BlockModel } from '../../schema/base.js';
|
|||||||
import type { IdGenerator } from '../../utils/id-generator.js';
|
import type { IdGenerator } from '../../utils/id-generator.js';
|
||||||
import type { AwarenessStore, BlockSuiteDoc } from '../../yjs/index.js';
|
import type { AwarenessStore, BlockSuiteDoc } from '../../yjs/index.js';
|
||||||
import type { GetDocOptions, Workspace } from '../workspace.js';
|
import type { GetDocOptions, Workspace } from '../workspace.js';
|
||||||
import { Doc } from './doc.js';
|
import { Blocks } from './doc.js';
|
||||||
import type { YBlock } from './index.js';
|
import type { YBlock } from './index.js';
|
||||||
import type { Query } from './query.js';
|
import type { Query } from './query.js';
|
||||||
|
|
||||||
@@ -40,9 +40,9 @@ export class BlockCollection {
|
|||||||
private readonly _collection: Workspace;
|
private readonly _collection: Workspace;
|
||||||
|
|
||||||
private readonly _docMap = {
|
private readonly _docMap = {
|
||||||
undefined: new Map<string, Doc>(),
|
undefined: new Map<string, Blocks>(),
|
||||||
true: new Map<string, Doc>(),
|
true: new Map<string, Blocks>(),
|
||||||
false: new Map<string, Doc>(),
|
false: new Map<string, Blocks>(),
|
||||||
};
|
};
|
||||||
|
|
||||||
// doc/space container.
|
// doc/space container.
|
||||||
@@ -324,7 +324,7 @@ export class BlockCollection {
|
|||||||
return this._docMap[readonlyKey].get(key)!;
|
return this._docMap[readonlyKey].get(key)!;
|
||||||
}
|
}
|
||||||
|
|
||||||
const doc = new Doc({
|
const doc = new Blocks({
|
||||||
blockCollection: this,
|
blockCollection: this,
|
||||||
schema: this.collection.schema,
|
schema: this.collection.schema,
|
||||||
readonly,
|
readonly,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { Schema } from '../../../schema/index.js';
|
import type { Schema } from '../../../schema/index.js';
|
||||||
import { BlockViewType } from '../consts.js';
|
import { BlockViewType } from '../consts.js';
|
||||||
import type { Doc } from '../doc.js';
|
import type { Blocks } from '../doc.js';
|
||||||
import { SyncController } from './sync-controller.js';
|
import { SyncController } from './sync-controller.js';
|
||||||
import type { BlockOptions, YBlock } from './types.js';
|
import type { BlockOptions, YBlock } from './types.js';
|
||||||
|
|
||||||
@@ -38,7 +38,7 @@ export class Block {
|
|||||||
constructor(
|
constructor(
|
||||||
readonly schema: Schema,
|
readonly schema: Schema,
|
||||||
readonly yBlock: YBlock,
|
readonly yBlock: YBlock,
|
||||||
readonly doc?: Doc,
|
readonly doc?: Blocks,
|
||||||
readonly options: BlockOptions = {}
|
readonly options: BlockOptions = {}
|
||||||
) {
|
) {
|
||||||
const onChange = !options.onChange
|
const onChange = !options.onChange
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import {
|
|||||||
} from '../../../reactive/index.js';
|
} from '../../../reactive/index.js';
|
||||||
import { BlockModel, internalPrimitives } from '../../../schema/base.js';
|
import { BlockModel, internalPrimitives } from '../../../schema/base.js';
|
||||||
import type { Schema } from '../../../schema/schema.js';
|
import type { Schema } from '../../../schema/schema.js';
|
||||||
import type { Doc } from '../doc.js';
|
import type { Blocks } from '../doc.js';
|
||||||
import type { YBlock } from './types.js';
|
import type { YBlock } from './types.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -103,7 +103,7 @@ export class SyncController {
|
|||||||
constructor(
|
constructor(
|
||||||
readonly schema: Schema,
|
readonly schema: Schema,
|
||||||
readonly yBlock: YBlock,
|
readonly yBlock: YBlock,
|
||||||
readonly doc?: Doc,
|
readonly doc?: Blocks,
|
||||||
readonly onChange?: (key: string, value: unknown) => void
|
readonly onChange?: (key: string, value: unknown) => void
|
||||||
) {
|
) {
|
||||||
const { id, flavour, version, yChildren, props } = this._parseYBlock();
|
const { id, flavour, version, yChildren, props } = this._parseYBlock();
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ type DocOptions = {
|
|||||||
query?: Query;
|
query?: Query;
|
||||||
};
|
};
|
||||||
|
|
||||||
export class Doc {
|
export class Blocks {
|
||||||
private readonly _runQuery = (block: Block) => {
|
private readonly _runQuery = (block: Block) => {
|
||||||
runQuery(this._query, block);
|
runQuery(this._query, block);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import type { Schema } from '../schema/schema.js';
|
|||||||
import type { IdGenerator } from '../utils/id-generator.js';
|
import type { IdGenerator } from '../utils/id-generator.js';
|
||||||
import type { AwarenessStore } from '../yjs/awareness.js';
|
import type { AwarenessStore } from '../yjs/awareness.js';
|
||||||
import type { BlockSuiteDoc } from '../yjs/doc.js';
|
import type { BlockSuiteDoc } from '../yjs/doc.js';
|
||||||
import type { Doc } from './doc/doc.js';
|
import type { Blocks } from './doc/doc.js';
|
||||||
import type { BlockCollection } from './doc/index.js';
|
import type { BlockCollection } from './doc/index.js';
|
||||||
import type { Query } from './doc/query.js';
|
import type { Query } from './doc/query.js';
|
||||||
|
|
||||||
@@ -78,8 +78,8 @@ export interface Workspace {
|
|||||||
docRemoved: Slot<string>;
|
docRemoved: Slot<string>;
|
||||||
};
|
};
|
||||||
|
|
||||||
createDoc(options?: CreateDocOptions): Doc;
|
createDoc(options?: CreateDocOptions): Blocks;
|
||||||
getDoc(docId: string, options?: GetDocOptions): Doc | null;
|
getDoc(docId: string, options?: GetDocOptions): Blocks | null;
|
||||||
removeDoc(docId: string): void;
|
removeDoc(docId: string): void;
|
||||||
|
|
||||||
dispose(): void;
|
dispose(): void;
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ import { Awareness } from 'y-protocols/awareness.js';
|
|||||||
import type { Schema } from '../schema/index.js';
|
import type { Schema } from '../schema/index.js';
|
||||||
import {
|
import {
|
||||||
BlockCollection,
|
BlockCollection,
|
||||||
|
type Blocks,
|
||||||
type CreateDocOptions,
|
type CreateDocOptions,
|
||||||
type Doc,
|
|
||||||
DocCollectionMeta,
|
DocCollectionMeta,
|
||||||
type GetDocOptions,
|
type GetDocOptions,
|
||||||
type Workspace,
|
type Workspace,
|
||||||
@@ -208,7 +208,7 @@ export class TestWorkspace implements Workspace {
|
|||||||
tags: [],
|
tags: [],
|
||||||
});
|
});
|
||||||
this.slots.docCreated.emit(docId);
|
this.slots.docCreated.emit(docId);
|
||||||
return this.getDoc(docId, { query, readonly }) as Doc;
|
return this.getDoc(docId, { query, readonly }) as Blocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
dispose() {
|
dispose() {
|
||||||
@@ -230,7 +230,7 @@ export class TestWorkspace implements Workspace {
|
|||||||
return space ?? null;
|
return space ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
getDoc(docId: string, options?: GetDocOptions): Doc | null {
|
getDoc(docId: string, options?: GetDocOptions): Blocks | null {
|
||||||
const collection = this.getBlockCollection(docId);
|
const collection = this.getBlockCollection(docId);
|
||||||
return collection?.getDoc(options) ?? null;
|
return collection?.getDoc(options) ?? null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
|||||||
import { nextTick, Slot } from '@blocksuite/global/utils';
|
import { nextTick, Slot } from '@blocksuite/global/utils';
|
||||||
|
|
||||||
import type { BlockModel, BlockSchemaType, Schema } from '../schema/index.js';
|
import type { BlockModel, BlockSchemaType, Schema } from '../schema/index.js';
|
||||||
import type { Doc } from '../store/index.js';
|
import type { Blocks } from '../store/index.js';
|
||||||
import { AssetsManager } from './assets.js';
|
import { AssetsManager } from './assets.js';
|
||||||
import { BaseBlockTransformer } from './base.js';
|
import { BaseBlockTransformer } from './base.js';
|
||||||
import type { DraftModel } from './draft.js';
|
import type { DraftModel } from './draft.js';
|
||||||
@@ -78,7 +78,7 @@ export class Job {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
docToSnapshot = (doc: Doc): DocSnapshot | undefined => {
|
docToSnapshot = (doc: Blocks): DocSnapshot | undefined => {
|
||||||
try {
|
try {
|
||||||
this._slots.beforeExport.emit({
|
this._slots.beforeExport.emit({
|
||||||
type: 'page',
|
type: 'page',
|
||||||
@@ -154,7 +154,7 @@ export class Job {
|
|||||||
|
|
||||||
snapshotToBlock = async (
|
snapshotToBlock = async (
|
||||||
snapshot: BlockSnapshot,
|
snapshot: BlockSnapshot,
|
||||||
doc: Doc,
|
doc: Blocks,
|
||||||
parent?: string,
|
parent?: string,
|
||||||
index?: number
|
index?: number
|
||||||
): Promise<BlockModel | undefined> => {
|
): Promise<BlockModel | undefined> => {
|
||||||
@@ -170,7 +170,9 @@ export class Job {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
snapshotToDoc = async (snapshot: DocSnapshot): Promise<Doc | undefined> => {
|
snapshotToDoc = async (
|
||||||
|
snapshot: DocSnapshot
|
||||||
|
): Promise<Blocks | undefined> => {
|
||||||
try {
|
try {
|
||||||
this._slots.beforeImport.emit({
|
this._slots.beforeImport.emit({
|
||||||
type: 'page',
|
type: 'page',
|
||||||
@@ -222,7 +224,7 @@ export class Job {
|
|||||||
|
|
||||||
snapshotToSlice = async (
|
snapshotToSlice = async (
|
||||||
snapshot: SliceSnapshot,
|
snapshot: SliceSnapshot,
|
||||||
doc: Doc,
|
doc: Blocks,
|
||||||
parent?: string,
|
parent?: string,
|
||||||
index?: number
|
index?: number
|
||||||
): Promise<Slice | undefined> => {
|
): Promise<Slice | undefined> => {
|
||||||
@@ -418,7 +420,7 @@ export class Job {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private _exportDocMeta(doc: Doc): DocSnapshot['meta'] {
|
private _exportDocMeta(doc: Blocks): DocSnapshot['meta'] {
|
||||||
const docMeta = doc.meta;
|
const docMeta = doc.meta;
|
||||||
|
|
||||||
if (!docMeta) {
|
if (!docMeta) {
|
||||||
@@ -466,7 +468,7 @@ export class Job {
|
|||||||
|
|
||||||
private async _insertBlockTree(
|
private async _insertBlockTree(
|
||||||
nodes: DraftBlockTreeNode[],
|
nodes: DraftBlockTreeNode[],
|
||||||
doc: Doc,
|
doc: Blocks,
|
||||||
parentId?: string,
|
parentId?: string,
|
||||||
startIndex?: number,
|
startIndex?: number,
|
||||||
counter: number = 0
|
counter: number = 0
|
||||||
@@ -555,7 +557,7 @@ export class Job {
|
|||||||
|
|
||||||
private async _snapshotToBlock(
|
private async _snapshotToBlock(
|
||||||
snapshot: BlockSnapshot,
|
snapshot: BlockSnapshot,
|
||||||
doc: Doc,
|
doc: Blocks,
|
||||||
parent?: string,
|
parent?: string,
|
||||||
index?: number
|
index?: number
|
||||||
): Promise<BlockModel | null> {
|
): Promise<BlockModel | null> {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { Slot } from '@blocksuite/global/utils';
|
import type { Slot } from '@blocksuite/global/utils';
|
||||||
|
|
||||||
import type { Doc } from '../store/index.js';
|
import type { Blocks } from '../store/index.js';
|
||||||
import type { AssetsManager } from './assets.js';
|
import type { AssetsManager } from './assets.js';
|
||||||
import type { DraftModel } from './draft.js';
|
import type { DraftModel } from './draft.js';
|
||||||
import type { Slice } from './slice.js';
|
import type { Slice } from './slice.js';
|
||||||
@@ -38,7 +38,7 @@ export type BeforeExportPayload =
|
|||||||
type: 'block';
|
type: 'block';
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
page: Doc;
|
page: Blocks;
|
||||||
type: 'page';
|
type: 'page';
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
@@ -60,7 +60,7 @@ export type FinalPayload =
|
|||||||
| {
|
| {
|
||||||
snapshot: DocSnapshot;
|
snapshot: DocSnapshot;
|
||||||
type: 'page';
|
type: 'page';
|
||||||
page: Doc;
|
page: Blocks;
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
snapshot: SliceSnapshot;
|
snapshot: SliceSnapshot;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { Doc } from '../store/index.js';
|
import type { Blocks } from '../store/index.js';
|
||||||
import type { DraftModel } from './draft.js';
|
import type { DraftModel } from './draft.js';
|
||||||
|
|
||||||
type SliceData = {
|
type SliceData = {
|
||||||
@@ -22,7 +22,7 @@ export class Slice {
|
|||||||
|
|
||||||
constructor(readonly data: SliceData) {}
|
constructor(readonly data: SliceData) {}
|
||||||
|
|
||||||
static fromModels(doc: Doc, models: DraftModel[]) {
|
static fromModels(doc: Blocks, models: DraftModel[]) {
|
||||||
return new Slice({
|
return new Slice({
|
||||||
content: models,
|
content: models,
|
||||||
workspaceId: doc.collection.id,
|
workspaceId: doc.collection.id,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
import type { Doc } from '../store/doc/doc.js';
|
import type { Blocks } from '../store/doc/doc.js';
|
||||||
import type { DocMeta, DocsPropertiesMeta } from '../store/workspace.js';
|
import type { DocMeta, DocsPropertiesMeta } from '../store/workspace.js';
|
||||||
|
|
||||||
export type BlockSnapshot = {
|
export type BlockSnapshot = {
|
||||||
@@ -75,7 +75,7 @@ export interface BlobCRUD {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface DocCRUD {
|
export interface DocCRUD {
|
||||||
create: (id: string) => Doc;
|
create: (id: string) => Blocks;
|
||||||
get: (id: string) => Doc | null;
|
get: (id: string) => Blocks | null;
|
||||||
delete: (id: string) => void;
|
delete: (id: string) => void;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import type {
|
|||||||
GroupElementModel,
|
GroupElementModel,
|
||||||
NoteBlockModel,
|
NoteBlockModel,
|
||||||
} from '@blocksuite/blocks';
|
} 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 { beforeEach, describe, expect, test } from 'vitest';
|
||||||
import * as Y from 'yjs';
|
import * as Y from 'yjs';
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ import { setupEditor } from '../utils/setup.js';
|
|||||||
|
|
||||||
let service!: EdgelessRootBlockComponent['service'];
|
let service!: EdgelessRootBlockComponent['service'];
|
||||||
|
|
||||||
const addNote = (doc: Doc, props: Record<string, unknown> = {}) => {
|
const addNote = (doc: Blocks, props: Record<string, unknown> = {}) => {
|
||||||
return _addNote(doc, {
|
return _addNote(doc, {
|
||||||
index: service.layer.generateIndex(),
|
index: service.layer.generateIndex(),
|
||||||
...props,
|
...props,
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
||||||
import type {
|
import type {
|
||||||
EdgelessRootBlockComponent,
|
EdgelessRootBlockComponent,
|
||||||
PageRootBlockComponent,
|
PageRootBlockComponent,
|
||||||
SurfaceBlockComponent,
|
SurfaceBlockComponent,
|
||||||
} from '@blocksuite/blocks';
|
} from '@blocksuite/blocks';
|
||||||
import type { Doc } from '@blocksuite/store';
|
import type { Blocks } from '@blocksuite/store';
|
||||||
|
|
||||||
import type { AffineEditorContainer } from '../../index.js';
|
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');
|
const surfaceModel = doc.getBlockByFlavour('affine:surface');
|
||||||
|
|
||||||
return editor.host!.view.getBlock(
|
return editor.host!.view.getBlock(
|
||||||
@@ -17,17 +16,17 @@ export function getSurface(doc: Doc, editor: AffineEditorContainer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getDocRootBlock(
|
export function getDocRootBlock(
|
||||||
doc: Doc,
|
doc: Blocks,
|
||||||
editor: AffineEditorContainer,
|
editor: AffineEditorContainer,
|
||||||
mode: 'page'
|
mode: 'page'
|
||||||
): PageRootBlockComponent;
|
): PageRootBlockComponent;
|
||||||
export function getDocRootBlock(
|
export function getDocRootBlock(
|
||||||
doc: Doc,
|
doc: Blocks,
|
||||||
editor: AffineEditorContainer,
|
editor: AffineEditorContainer,
|
||||||
mode: 'edgeless'
|
mode: 'edgeless'
|
||||||
): EdgelessRootBlockComponent;
|
): EdgelessRootBlockComponent;
|
||||||
export function getDocRootBlock(
|
export function getDocRootBlock(
|
||||||
doc: Doc,
|
doc: Blocks,
|
||||||
editor: AffineEditorContainer,
|
editor: AffineEditorContainer,
|
||||||
_?: 'edgeless' | 'page'
|
_?: 'edgeless' | 'page'
|
||||||
) {
|
) {
|
||||||
@@ -36,7 +35,7 @@ export function getDocRootBlock(
|
|||||||
| PageRootBlockComponent;
|
| PageRootBlockComponent;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function addNote(doc: Doc, props: Record<string, any> = {}) {
|
export function addNote(doc: Blocks, props: Record<string, any> = {}) {
|
||||||
const noteId = doc.addBlock(
|
const noteId = doc.addBlock(
|
||||||
'affine:note',
|
'affine:note',
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { effects as blocksEffects } from '@blocksuite/blocks/effects';
|
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';
|
import { effects } from '../../effects.js';
|
||||||
|
|
||||||
@@ -111,12 +111,12 @@ export function cleanup() {
|
|||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
const editor: AffineEditorContainer;
|
const editor: AffineEditorContainer;
|
||||||
const doc: Doc;
|
const doc: Blocks;
|
||||||
const collection: TestWorkspace;
|
const collection: TestWorkspace;
|
||||||
const job: Job;
|
const job: Job;
|
||||||
interface Window {
|
interface Window {
|
||||||
editor: AffineEditorContainer;
|
editor: AffineEditorContainer;
|
||||||
doc: Doc;
|
doc: Blocks;
|
||||||
job: Job;
|
job: Job;
|
||||||
collection: TestWorkspace;
|
collection: TestWorkspace;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { BlockStdScope, ShadowlessElement } from '@blocksuite/block-std';
|
import { BlockStdScope, ShadowlessElement } from '@blocksuite/block-std';
|
||||||
import { EdgelessEditorBlockSpecs, ThemeProvider } from '@blocksuite/blocks';
|
import { EdgelessEditorBlockSpecs, ThemeProvider } from '@blocksuite/blocks';
|
||||||
import { SignalWatcher, WithDisposable } from '@blocksuite/global/utils';
|
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 { css, html, nothing, type TemplateResult } from 'lit';
|
||||||
import { property, state } from 'lit/decorators.js';
|
import { property, state } from 'lit/decorators.js';
|
||||||
import { guard } from 'lit/directives/guard.js';
|
import { guard } from 'lit/directives/guard.js';
|
||||||
@@ -85,7 +85,7 @@ export class EdgelessEditor extends SignalWatcher(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
accessor doc!: Doc;
|
accessor doc!: Blocks;
|
||||||
|
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
accessor editor!: TemplateResult;
|
accessor editor!: TemplateResult;
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import {
|
|||||||
ThemeProvider,
|
ThemeProvider,
|
||||||
} from '@blocksuite/blocks';
|
} from '@blocksuite/blocks';
|
||||||
import { SignalWatcher, Slot, WithDisposable } from '@blocksuite/global/utils';
|
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 { computed, signal } from '@preact/signals-core';
|
||||||
import { css, html } from 'lit';
|
import { css, html } from 'lit';
|
||||||
import { property } from 'lit/decorators.js';
|
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[]>(
|
private readonly _edgelessSpecs = signal<ExtensionType[]>(
|
||||||
EdgelessEditorBlockSpecs
|
EdgelessEditorBlockSpecs
|
||||||
@@ -123,10 +123,10 @@ export class AffineEditorContainer
|
|||||||
};
|
};
|
||||||
|
|
||||||
get doc() {
|
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;
|
this._doc.value = doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
} from '@blocksuite/block-std';
|
} from '@blocksuite/block-std';
|
||||||
import { PageEditorBlockSpecs, ThemeProvider } from '@blocksuite/blocks';
|
import { PageEditorBlockSpecs, ThemeProvider } from '@blocksuite/blocks';
|
||||||
import { noop, SignalWatcher, WithDisposable } from '@blocksuite/global/utils';
|
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 { css, html, nothing } from 'lit';
|
||||||
import { property, state } from 'lit/decorators.js';
|
import { property, state } from 'lit/decorators.js';
|
||||||
import { guard } from 'lit/directives/guard.js';
|
import { guard } from 'lit/directives/guard.js';
|
||||||
@@ -101,7 +101,7 @@ export class PageEditor extends SignalWatcher(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
accessor doc!: Doc;
|
accessor doc!: Blocks;
|
||||||
|
|
||||||
@property({ type: Boolean })
|
@property({ type: Boolean })
|
||||||
accessor hasViewport = true;
|
accessor hasViewport = true;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import type { EditorHost } from '@blocksuite/block-std';
|
|||||||
import { ShadowlessElement } from '@blocksuite/block-std';
|
import { ShadowlessElement } from '@blocksuite/block-std';
|
||||||
import type { RichText, RootBlockModel } from '@blocksuite/blocks';
|
import type { RichText, RootBlockModel } from '@blocksuite/blocks';
|
||||||
import { assertExists, WithDisposable } from '@blocksuite/global/utils';
|
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 { css, html } from 'lit';
|
||||||
import { property, query, state } from 'lit/decorators.js';
|
import { property, query, state } from 'lit/decorators.js';
|
||||||
|
|
||||||
@@ -178,7 +178,7 @@ export class DocTitle extends WithDisposable(ShadowlessElement) {
|
|||||||
private accessor _richTextElement!: RichText;
|
private accessor _richTextElement!: RichText;
|
||||||
|
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
accessor doc!: Doc;
|
accessor doc!: Blocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getDocTitleByEditorHost(
|
export function getDocTitleByEditorHost(
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import {
|
|||||||
SignalWatcher,
|
SignalWatcher,
|
||||||
WithDisposable,
|
WithDisposable,
|
||||||
} from '@blocksuite/global/utils';
|
} 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 { css, html, nothing, type PropertyValues } from 'lit';
|
||||||
import { property, query, state } from 'lit/decorators.js';
|
import { property, query, state } from 'lit/decorators.js';
|
||||||
import { keyed } from 'lit/directives/keyed.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._clearDocDisposables();
|
||||||
this._docDisposables = new DisposableGroup();
|
this._docDisposables = new DisposableGroup();
|
||||||
this._docDisposables.add(
|
this._docDisposables.add(
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import {
|
|||||||
SignalWatcher,
|
SignalWatcher,
|
||||||
WithDisposable,
|
WithDisposable,
|
||||||
} from '@blocksuite/global/utils';
|
} from '@blocksuite/global/utils';
|
||||||
import type { Doc } from '@blocksuite/store';
|
import type { Blocks } from '@blocksuite/store';
|
||||||
import { effect, signal } from '@preact/signals-core';
|
import { effect, signal } from '@preact/signals-core';
|
||||||
import { css, html, LitElement, nothing, type PropertyValues } from 'lit';
|
import { css, html, LitElement, nothing, type PropertyValues } from 'lit';
|
||||||
import { property, query, state } from 'lit/decorators.js';
|
import { property, query, state } from 'lit/decorators.js';
|
||||||
@@ -698,7 +698,7 @@ export class OutlinePanelBody extends SignalWatcher(
|
|||||||
private accessor _selected: string[] = [];
|
private accessor _selected: string[] = [];
|
||||||
|
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
accessor doc!: Doc;
|
accessor doc!: Blocks;
|
||||||
|
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
accessor domHost!: Document | HTMLElement;
|
accessor domHost!: Document | HTMLElement;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import {
|
|||||||
once,
|
once,
|
||||||
} from '@blocksuite/blocks';
|
} from '@blocksuite/blocks';
|
||||||
import { SignalWatcher, WithDisposable } from '@blocksuite/global/utils';
|
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 { baseTheme } from '@toeverything/theme';
|
||||||
import { css, html, LitElement, nothing, unsafeCSS } from 'lit';
|
import { css, html, LitElement, nothing, unsafeCSS } from 'lit';
|
||||||
import { property, query, state } from 'lit/decorators.js';
|
import { property, query, state } from 'lit/decorators.js';
|
||||||
@@ -395,7 +395,7 @@ export class OutlineNoteCard extends SignalWatcher(WithDisposable(LitElement)) {
|
|||||||
accessor activeHeadingId: string | null = null;
|
accessor activeHeadingId: string | null = null;
|
||||||
|
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
accessor doc!: Doc;
|
accessor doc!: Blocks;
|
||||||
|
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
accessor editorMode: 'page' | 'edgeless' = 'page';
|
accessor editorMode: 'page' | 'edgeless' = 'page';
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { on, once } from '@blocksuite/blocks';
|
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 { OutlinePanelBody } from '../body/outline-panel-body.js';
|
||||||
import type { OutlineNoteCard } from '../card/outline-card.js';
|
import type { OutlineNoteCard } from '../card/outline-card.js';
|
||||||
@@ -15,7 +15,7 @@ export function startDragging(options: {
|
|||||||
document: Document;
|
document: Document;
|
||||||
host: Document | HTMLElement;
|
host: Document | HTMLElement;
|
||||||
container: OutlinePanelBody;
|
container: OutlinePanelBody;
|
||||||
doc: Doc;
|
doc: Blocks;
|
||||||
}) {
|
}) {
|
||||||
const {
|
const {
|
||||||
document,
|
document,
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
type ParagraphBlockModel,
|
type ParagraphBlockModel,
|
||||||
type RootBlockModel,
|
type RootBlockModel,
|
||||||
} from '@blocksuite/blocks';
|
} from '@blocksuite/blocks';
|
||||||
import type { BlockModel, Doc } from '@blocksuite/store';
|
import type { BlockModel, Blocks } from '@blocksuite/store';
|
||||||
|
|
||||||
import { headingKeys } from '../config.js';
|
import { headingKeys } from '../config.js';
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ type OutlineNoteItem = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export function getNotesFromDoc(
|
export function getNotesFromDoc(
|
||||||
doc: Doc,
|
doc: Blocks,
|
||||||
modes: NoteDisplayMode[]
|
modes: NoteDisplayMode[]
|
||||||
): OutlineNoteItem[] {
|
): OutlineNoteItem[] {
|
||||||
const rootModel = doc.root;
|
const rootModel = doc.root;
|
||||||
@@ -74,7 +74,7 @@ export function getHeadingBlocksFromNote(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getHeadingBlocksFromDoc(
|
export function getHeadingBlocksFromDoc(
|
||||||
doc: Doc,
|
doc: Blocks,
|
||||||
modes: NoteDisplayMode[],
|
modes: NoteDisplayMode[],
|
||||||
ignoreEmpty = false
|
ignoreEmpty = false
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
type ParagraphProps,
|
type ParagraphProps,
|
||||||
type RootBlockProps,
|
type RootBlockProps,
|
||||||
} from '@blocksuite/affine/blocks';
|
} from '@blocksuite/affine/blocks';
|
||||||
import { type Doc, Text } from '@blocksuite/affine/store';
|
import { type Blocks, Text } from '@blocksuite/affine/store';
|
||||||
|
|
||||||
export interface DocProps {
|
export interface DocProps {
|
||||||
page?: Partial<RootBlockProps>;
|
page?: Partial<RootBlockProps>;
|
||||||
@@ -14,7 +14,7 @@ export interface DocProps {
|
|||||||
paragraph?: Partial<ParagraphProps>;
|
paragraph?: Partial<ParagraphProps>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function initEmptyDoc(doc: Doc, title?: string) {
|
export function initEmptyDoc(doc: Blocks, title?: string) {
|
||||||
doc.load(() => {
|
doc.load(() => {
|
||||||
initDocFromProps(doc, {
|
initDocFromProps(doc, {
|
||||||
page: {
|
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(() => {
|
doc.load(() => {
|
||||||
const pageBlockId = doc.addBlock(
|
const pageBlockId = doc.addBlock(
|
||||||
'affine:page',
|
'affine:page',
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ import {
|
|||||||
import { Container, type ServiceProvider } from '@blocksuite/affine/global/di';
|
import { Container, type ServiceProvider } from '@blocksuite/affine/global/di';
|
||||||
import { WithDisposable } from '@blocksuite/affine/global/utils';
|
import { WithDisposable } from '@blocksuite/affine/global/utils';
|
||||||
import {
|
import {
|
||||||
|
type Blocks,
|
||||||
BlockViewType,
|
BlockViewType,
|
||||||
type Doc,
|
|
||||||
type JobMiddleware,
|
type JobMiddleware,
|
||||||
type Query,
|
type Query,
|
||||||
type Schema,
|
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 = {
|
private readonly _query: Query = {
|
||||||
mode: 'strict',
|
mode: 'strict',
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ import type { ServiceProvider } from '@blocksuite/affine/global/di';
|
|||||||
import { assertExists } from '@blocksuite/affine/global/utils';
|
import { assertExists } from '@blocksuite/affine/global/utils';
|
||||||
import type {
|
import type {
|
||||||
BlockModel,
|
BlockModel,
|
||||||
|
Blocks,
|
||||||
BlockSnapshot,
|
BlockSnapshot,
|
||||||
Doc,
|
|
||||||
DraftModel,
|
DraftModel,
|
||||||
JobMiddleware,
|
JobMiddleware,
|
||||||
Schema,
|
Schema,
|
||||||
@@ -166,7 +166,7 @@ export const markdownToSnapshot = async (
|
|||||||
export async function insertFromMarkdown(
|
export async function insertFromMarkdown(
|
||||||
host: EditorHost,
|
host: EditorHost,
|
||||||
markdown: string,
|
markdown: string,
|
||||||
doc: Doc,
|
doc: Blocks,
|
||||||
parent?: string,
|
parent?: string,
|
||||||
index?: number
|
index?: number
|
||||||
) {
|
) {
|
||||||
@@ -235,5 +235,5 @@ export async function markDownToDoc(
|
|||||||
if (!doc) {
|
if (!doc) {
|
||||||
console.error('Failed to convert markdown to doc');
|
console.error('Failed to convert markdown to doc');
|
||||||
}
|
}
|
||||||
return doc as Doc;
|
return doc as Blocks;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import {
|
|||||||
getCommonBoundWithRotation,
|
getCommonBoundWithRotation,
|
||||||
type SerializedXYWH,
|
type SerializedXYWH,
|
||||||
} from '@blocksuite/affine/global/utils';
|
} 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 { TemplateResult } from 'lit';
|
||||||
|
|
||||||
import type { ChatMessage } from '../../../blocks';
|
import type { ChatMessage } from '../../../blocks';
|
||||||
@@ -101,7 +101,7 @@ export function constructUserInfoWithMessages(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function constructRootChatBlockMessages(
|
export async function constructRootChatBlockMessages(
|
||||||
doc: Doc,
|
doc: Blocks,
|
||||||
forkSessionId: string
|
forkSessionId: string
|
||||||
) {
|
) {
|
||||||
// Convert chat messages to AI chat block messages
|
// 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 { ShadowlessElement } from '@blocksuite/affine/block-std';
|
||||||
import { NotificationProvider } from '@blocksuite/affine/blocks';
|
import { NotificationProvider } from '@blocksuite/affine/blocks';
|
||||||
import { debounce, WithDisposable } from '@blocksuite/affine/global/utils';
|
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 { css, html, type PropertyValues } from 'lit';
|
||||||
import { property, state } from 'lit/decorators.js';
|
import { property, state } from 'lit/decorators.js';
|
||||||
import { createRef, type Ref, ref } from 'lit/directives/ref.js';
|
import { createRef, type Ref, ref } from 'lit/directives/ref.js';
|
||||||
@@ -141,7 +141,7 @@ export class ChatPanel extends WithDisposable(ShadowlessElement) {
|
|||||||
accessor host!: EditorHost;
|
accessor host!: EditorHost;
|
||||||
|
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
accessor doc!: Doc;
|
accessor doc!: Blocks;
|
||||||
|
|
||||||
@state()
|
@state()
|
||||||
accessor isLoading = false;
|
accessor isLoading = false;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
} from '@blocksuite/affine/blocks';
|
} from '@blocksuite/affine/blocks';
|
||||||
import { AffineSchemas } from '@blocksuite/affine/blocks/schemas';
|
import { AffineSchemas } from '@blocksuite/affine/blocks/schemas';
|
||||||
import { WithDisposable } from '@blocksuite/affine/global/utils';
|
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 { Schema } from '@blocksuite/affine/store';
|
||||||
import { css, html, LitElement, nothing } from 'lit';
|
import { css, html, LitElement, nothing } from 'lit';
|
||||||
import { property, query } from 'lit/decorators.js';
|
import { property, query } from 'lit/decorators.js';
|
||||||
@@ -53,7 +53,7 @@ export class AISlidesRenderer extends WithDisposable(LitElement) {
|
|||||||
private readonly _editorContainer: Ref<HTMLDivElement> =
|
private readonly _editorContainer: Ref<HTMLDivElement> =
|
||||||
createRef<HTMLDivElement>();
|
createRef<HTMLDivElement>();
|
||||||
|
|
||||||
private _doc!: Doc;
|
private _doc!: Blocks;
|
||||||
|
|
||||||
private _docCollection: WorkspaceImpl | null = null;
|
private _docCollection: WorkspaceImpl | null = null;
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import {
|
|||||||
} from '@blocksuite/affine/blocks';
|
} from '@blocksuite/affine/blocks';
|
||||||
import type { ServiceProvider } from '@blocksuite/affine/global/di';
|
import type { ServiceProvider } from '@blocksuite/affine/global/di';
|
||||||
import { WithDisposable } from '@blocksuite/affine/global/utils';
|
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 { css, html, LitElement, nothing } from 'lit';
|
||||||
import { property, query } from 'lit/decorators.js';
|
import { property, query } from 'lit/decorators.js';
|
||||||
import { repeat } from 'lit/directives/repeat.js';
|
import { repeat } from 'lit/directives/repeat.js';
|
||||||
@@ -79,7 +79,7 @@ export class MiniMindmapPreview extends WithDisposable(LitElement) {
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
doc?: Doc;
|
doc?: Blocks;
|
||||||
|
|
||||||
mindmapId?: string;
|
mindmapId?: string;
|
||||||
|
|
||||||
@@ -131,7 +131,7 @@ export class MiniMindmapPreview extends WithDisposable(LitElement) {
|
|||||||
this.requestUpdate();
|
this.requestUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
private _toMindmapNode(answer: string, doc: Doc) {
|
private _toMindmapNode(answer: string, doc: Blocks) {
|
||||||
return markdownToMindmap(answer, doc, this.host.std.provider);
|
return markdownToMindmap(answer, doc, this.host.std.provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,7 +234,7 @@ type Node = {
|
|||||||
|
|
||||||
export const markdownToMindmap = (
|
export const markdownToMindmap = (
|
||||||
answer: string,
|
answer: string,
|
||||||
doc: Doc,
|
doc: Blocks,
|
||||||
provider: ServiceProvider
|
provider: ServiceProvider
|
||||||
) => {
|
) => {
|
||||||
let result: Node | null = null;
|
let result: Node | null = null;
|
||||||
|
|||||||
@@ -11,7 +11,10 @@ import { WorkspaceService } from '@affine/core/modules/workspace';
|
|||||||
import { i18nTime, Trans, useI18n } from '@affine/i18n';
|
import { i18nTime, Trans, useI18n } from '@affine/i18n';
|
||||||
import { track } from '@affine/track';
|
import { track } from '@affine/track';
|
||||||
import type { DocMode } from '@blocksuite/affine/blocks';
|
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 { CloseIcon, ToggleCollapseIcon } from '@blocksuite/icons/rc';
|
||||||
import * as Collapsible from '@radix-ui/react-collapsible';
|
import * as Collapsible from '@radix-ui/react-collapsible';
|
||||||
import type { DialogContentProps } from '@radix-ui/react-dialog';
|
import type { DialogContentProps } from '@radix-ui/react-dialog';
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
import { useEnableCloud } from '@affine/core/components/hooks/affine/use-enable-cloud';
|
import { useEnableCloud } from '@affine/core/components/hooks/affine/use-enable-cloud';
|
||||||
import type { Workspace } from '@affine/core/modules/workspace';
|
import type { Workspace } from '@affine/core/modules/workspace';
|
||||||
import { track } from '@affine/track';
|
import { track } from '@affine/track';
|
||||||
import type { Doc } from '@blocksuite/affine/store';
|
import type { Blocks } from '@blocksuite/affine/store';
|
||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
|
|
||||||
import { ShareMenu } from './share-menu';
|
import { ShareMenu } from './share-menu';
|
||||||
|
|
||||||
type SharePageModalProps = {
|
type SharePageModalProps = {
|
||||||
workspace: Workspace;
|
workspace: Workspace;
|
||||||
page: Doc;
|
page: Blocks;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const SharePageButton = ({ workspace, page }: SharePageModalProps) => {
|
export const SharePageButton = ({ workspace, page }: SharePageModalProps) => {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { Menu } from '@affine/component/ui/menu';
|
|||||||
import { ShareInfoService } from '@affine/core/modules/share-doc';
|
import { ShareInfoService } from '@affine/core/modules/share-doc';
|
||||||
import type { WorkspaceMetadata } from '@affine/core/modules/workspace';
|
import type { WorkspaceMetadata } from '@affine/core/modules/workspace';
|
||||||
import { useI18n } from '@affine/i18n';
|
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 { LockIcon, PublishIcon } from '@blocksuite/icons/rc';
|
||||||
import { useLiveData, useService } from '@toeverything/infra';
|
import { useLiveData, useService } from '@toeverything/infra';
|
||||||
import { forwardRef, type PropsWithChildren, type Ref, useEffect } from 'react';
|
import { forwardRef, type PropsWithChildren, type Ref, useEffect } from 'react';
|
||||||
@@ -15,7 +15,7 @@ import { SharePage } from './share-page';
|
|||||||
|
|
||||||
export interface ShareMenuProps extends PropsWithChildren {
|
export interface ShareMenuProps extends PropsWithChildren {
|
||||||
workspaceMetadata: WorkspaceMetadata;
|
workspaceMetadata: WorkspaceMetadata;
|
||||||
currentPage: Doc;
|
currentPage: Blocks;
|
||||||
onEnableAffineCloud: () => void;
|
onEnableAffineCloud: () => void;
|
||||||
onOpenShareModal?: (open: boolean) => void;
|
onOpenShareModal?: (open: boolean) => void;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import type {
|
|||||||
EdgelessEditor,
|
EdgelessEditor,
|
||||||
PageEditor,
|
PageEditor,
|
||||||
} from '@blocksuite/affine/presets';
|
} 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 clsx from 'clsx';
|
||||||
import type React from 'react';
|
import type React from 'react';
|
||||||
import {
|
import {
|
||||||
@@ -27,7 +27,7 @@ import { BlocksuiteDocEditor, BlocksuiteEdgelessEditor } from './lit-adaper';
|
|||||||
import * as styles from './styles.css';
|
import * as styles from './styles.css';
|
||||||
|
|
||||||
interface BlocksuiteEditorContainerProps {
|
interface BlocksuiteEditorContainerProps {
|
||||||
page: Doc;
|
page: Blocks;
|
||||||
mode: DocMode;
|
mode: DocMode;
|
||||||
shared?: boolean;
|
shared?: boolean;
|
||||||
className?: string;
|
className?: string;
|
||||||
@@ -191,7 +191,7 @@ export const BlocksuiteEditorContainer = forwardRef<
|
|||||||
});
|
});
|
||||||
|
|
||||||
// copy from '@blocksuite/affine-shared/utils'
|
// copy from '@blocksuite/affine-shared/utils'
|
||||||
export function getLastNoteBlock(doc: Doc) {
|
export function getLastNoteBlock(doc: Blocks) {
|
||||||
let note: NoteBlockModel | null = null;
|
let note: NoteBlockModel | null = null;
|
||||||
if (!doc.root) return null;
|
if (!doc.root) return null;
|
||||||
const { children } = doc.root;
|
const { children } = doc.root;
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import {
|
|||||||
} from '@blocksuite/affine/blocks';
|
} from '@blocksuite/affine/blocks';
|
||||||
import { DisposableGroup } from '@blocksuite/affine/global/utils';
|
import { DisposableGroup } from '@blocksuite/affine/global/utils';
|
||||||
import type { AffineEditorContainer } from '@blocksuite/affine/presets';
|
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 type { CSSProperties } from 'react';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ import { BlocksuiteEditorContainer } from './blocksuite-editor-container';
|
|||||||
import { NoPageRootError } from './no-page-error';
|
import { NoPageRootError } from './no-page-error';
|
||||||
|
|
||||||
export type EditorProps = {
|
export type EditorProps = {
|
||||||
page: Doc;
|
page: Blocks;
|
||||||
mode: DocMode;
|
mode: DocMode;
|
||||||
shared?: boolean;
|
shared?: boolean;
|
||||||
defaultOpenProperty?: DefaultOpenProperty;
|
defaultOpenProperty?: DefaultOpenProperty;
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import { JournalService } from '@affine/core/modules/journal';
|
import { JournalService } from '@affine/core/modules/journal';
|
||||||
import { i18nTime, useI18n } from '@affine/i18n';
|
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 { useLiveData, useService } from '@toeverything/infra';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
import * as styles from './styles.css';
|
import * as styles from './styles.css';
|
||||||
|
|
||||||
export const BlocksuiteEditorJournalDocTitle = ({ page }: { page: Doc }) => {
|
export const BlocksuiteEditorJournalDocTitle = ({ page }: { page: Blocks }) => {
|
||||||
const journalService = useService(JournalService);
|
const journalService = useService(JournalService);
|
||||||
const journalDateStr = useLiveData(journalService.journalDate$(page.id));
|
const journalDateStr = useLiveData(journalService.journalDate$(page.id));
|
||||||
const journalDate = journalDateStr ? dayjs(journalDateStr) : null;
|
const journalDate = journalDateStr ? dayjs(journalDateStr) : null;
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import {
|
|||||||
EdgelessEditor,
|
EdgelessEditor,
|
||||||
PageEditor,
|
PageEditor,
|
||||||
} from '@blocksuite/affine/presets';
|
} from '@blocksuite/affine/presets';
|
||||||
import type { Doc } from '@blocksuite/affine/store';
|
import type { Blocks } from '@blocksuite/affine/store';
|
||||||
import {
|
import {
|
||||||
useFramework,
|
useFramework,
|
||||||
useLiveData,
|
useLiveData,
|
||||||
@@ -85,7 +85,7 @@ const adapted = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
interface BlocksuiteEditorProps {
|
interface BlocksuiteEditorProps {
|
||||||
page: Doc;
|
page: Blocks;
|
||||||
shared?: boolean;
|
shared?: boolean;
|
||||||
defaultOpenProperty?: DefaultOpenProperty;
|
defaultOpenProperty?: DefaultOpenProperty;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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';
|
import type { Map as YMap } from 'yjs';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO(@eyhn): Define error to unexpected state together in the future.
|
* TODO(@eyhn): Define error to unexpected state together in the future.
|
||||||
*/
|
*/
|
||||||
export class NoPageRootError extends Error {
|
export class NoPageRootError extends Error {
|
||||||
constructor(public page: Doc) {
|
constructor(public page: Blocks) {
|
||||||
super('Page root not found when render editor!');
|
super('Page root not found when render editor!');
|
||||||
|
|
||||||
// Log info to let sentry collect more message
|
// Log info to let sentry collect more message
|
||||||
|
|||||||
@@ -2,13 +2,13 @@ import type { WeekDatePickerHandle } from '@affine/component';
|
|||||||
import { WeekDatePicker } from '@affine/component';
|
import { WeekDatePicker } from '@affine/component';
|
||||||
import { useJournalRouteHelper } from '@affine/core/components/hooks/use-journal';
|
import { useJournalRouteHelper } from '@affine/core/components/hooks/use-journal';
|
||||||
import { JournalService } from '@affine/core/modules/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 { useLiveData, useService } from '@toeverything/infra';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import { useEffect, useRef, useState } from 'react';
|
import { useEffect, useRef, useState } from 'react';
|
||||||
|
|
||||||
export interface JournalWeekDatePickerProps {
|
export interface JournalWeekDatePickerProps {
|
||||||
page: Doc;
|
page: Blocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
const weekStyle = { maxWidth: 800, width: '100%' };
|
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 { WorkspaceService } from '@affine/core/modules/workspace';
|
||||||
import { useI18n } from '@affine/i18n';
|
import { useI18n } from '@affine/i18n';
|
||||||
import { track } from '@affine/track';
|
import { track } from '@affine/track';
|
||||||
import type { Doc } from '@blocksuite/affine/store';
|
import type { Blocks } from '@blocksuite/affine/store';
|
||||||
import {
|
import {
|
||||||
DuplicateIcon,
|
DuplicateIcon,
|
||||||
EdgelessIcon,
|
EdgelessIcon,
|
||||||
@@ -52,7 +52,7 @@ import { HistoryTipsModal } from './history-tips-modal';
|
|||||||
|
|
||||||
type PageMenuProps = {
|
type PageMenuProps = {
|
||||||
rename?: () => void;
|
rename?: () => void;
|
||||||
page: Doc;
|
page: Blocks;
|
||||||
isJournal?: boolean;
|
isJournal?: boolean;
|
||||||
containerWidth: number;
|
containerWidth: number;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import {
|
|||||||
ZipTransformer,
|
ZipTransformer,
|
||||||
} from '@blocksuite/affine/blocks';
|
} from '@blocksuite/affine/blocks';
|
||||||
import type { AffineEditorContainer } from '@blocksuite/affine/presets';
|
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 { useLiveData, useService } from '@toeverything/infra';
|
||||||
import { useSetAtom } from 'jotai';
|
import { useSetAtom } from 'jotai';
|
||||||
import { nanoid } from 'nanoid';
|
import { nanoid } from 'nanoid';
|
||||||
@@ -32,7 +32,7 @@ import { useAsyncCallback } from '../affine-async-hooks';
|
|||||||
type ExportType = 'pdf' | 'html' | 'png' | 'markdown' | 'snapshot';
|
type ExportType = 'pdf' | 'html' | 'png' | 'markdown' | 'snapshot';
|
||||||
|
|
||||||
interface ExportHandlerOptions {
|
interface ExportHandlerOptions {
|
||||||
page: Doc;
|
page: Blocks;
|
||||||
editorContainer: AffineEditorContainer;
|
editorContainer: AffineEditorContainer;
|
||||||
type: ExportType;
|
type: ExportType;
|
||||||
}
|
}
|
||||||
@@ -53,7 +53,11 @@ interface AdapterConfig {
|
|||||||
indexFileName: string;
|
indexFileName: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function exportDoc(doc: Doc, std: BlockStdScope, config: AdapterConfig) {
|
async function exportDoc(
|
||||||
|
doc: Blocks,
|
||||||
|
std: BlockStdScope,
|
||||||
|
config: AdapterConfig
|
||||||
|
) {
|
||||||
const job = new Job({
|
const job = new Job({
|
||||||
schema: doc.collection.schema,
|
schema: doc.collection.schema,
|
||||||
blobCRUD: doc.collection.blobSync,
|
blobCRUD: doc.collection.blobSync,
|
||||||
@@ -99,7 +103,7 @@ async function exportDoc(doc: Doc, std: BlockStdScope, config: AdapterConfig) {
|
|||||||
download(downloadBlob, name);
|
download(downloadBlob, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function exportToHtml(doc: Doc, std?: BlockStdScope) {
|
async function exportToHtml(doc: Blocks, std?: BlockStdScope) {
|
||||||
if (!std) {
|
if (!std) {
|
||||||
// If std is not provided, we use the default export method
|
// If std is not provided, we use the default export method
|
||||||
await HtmlTransformer.exportDoc(doc);
|
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) {
|
||||||
// If std is not provided, we use the default export method
|
// If std is not provided, we use the default export method
|
||||||
await MarkdownTransformer.exportDoc(doc);
|
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';
|
import { useMemo } from 'react';
|
||||||
|
|
||||||
export function useDocCollectionHelper(docCollection: Workspace) {
|
export function useDocCollectionHelper(docCollection: Workspace) {
|
||||||
return useMemo(
|
return useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
createDoc: (pageId?: string): Doc => {
|
createDoc: (pageId?: string): Blocks => {
|
||||||
return docCollection.createDoc({ id: pageId });
|
return docCollection.createDoc({ id: pageId });
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { DebugLogger } from '@affine/debug';
|
import { DebugLogger } from '@affine/debug';
|
||||||
import { DisposableGroup } from '@blocksuite/affine/global/utils';
|
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';
|
import { useEffect, useState } from 'react';
|
||||||
|
|
||||||
const logger = new DebugLogger('use-doc-collection-page');
|
const logger = new DebugLogger('use-doc-collection-page');
|
||||||
@@ -8,7 +8,7 @@ const logger = new DebugLogger('use-doc-collection-page');
|
|||||||
export function useDocCollectionPage(
|
export function useDocCollectionPage(
|
||||||
docCollection: Workspace,
|
docCollection: Workspace,
|
||||||
pageId: string | null
|
pageId: string | null
|
||||||
): Doc | null {
|
): Blocks | null {
|
||||||
const [page, setPage] = useState(
|
const [page, setPage] = useState(
|
||||||
pageId ? docCollection.getDoc(pageId) : null
|
pageId ? docCollection.getDoc(pageId) : null
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import 'fake-indexeddb/auto';
|
|||||||
|
|
||||||
import { AffineSchemas } from '@blocksuite/affine/blocks/schemas';
|
import { AffineSchemas } from '@blocksuite/affine/blocks/schemas';
|
||||||
import { assertExists } from '@blocksuite/affine/global/utils';
|
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 { Schema } from '@blocksuite/store';
|
||||||
import { TestWorkspace } from '@blocksuite/store/test';
|
import { TestWorkspace } from '@blocksuite/store/test';
|
||||||
import { renderHook } from '@testing-library/react';
|
import { renderHook } from '@testing-library/react';
|
||||||
@@ -22,7 +22,7 @@ beforeEach(async () => {
|
|||||||
vi.useFakeTimers({ toFake: ['requestIdleCallback'] });
|
vi.useFakeTimers({ toFake: ['requestIdleCallback'] });
|
||||||
docCollection = new TestWorkspace({ id: 'test', schema });
|
docCollection = new TestWorkspace({ id: 'test', schema });
|
||||||
docCollection.meta.initialize();
|
docCollection.meta.initialize();
|
||||||
const initPage = async (page: Doc) => {
|
const initPage = async (page: Blocks) => {
|
||||||
page.load();
|
page.load();
|
||||||
expect(page).not.toBeNull();
|
expect(page).not.toBeNull();
|
||||||
assertExists(page);
|
assertExists(page);
|
||||||
@@ -37,7 +37,7 @@ beforeEach(async () => {
|
|||||||
|
|
||||||
describe('useBlockSuitePagePreview', () => {
|
describe('useBlockSuitePagePreview', () => {
|
||||||
test('basic', async () => {
|
test('basic', async () => {
|
||||||
const page = docCollection.getDoc('page0') as Doc;
|
const page = docCollection.getDoc('page0') as Blocks;
|
||||||
const id = page.addBlock(
|
const id = page.addBlock(
|
||||||
'affine:paragraph',
|
'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 type { Atom } from 'jotai';
|
||||||
import { atom } from 'jotai';
|
import { atom } from 'jotai';
|
||||||
|
|
||||||
const MAX_PREVIEW_LENGTH = 150;
|
const MAX_PREVIEW_LENGTH = 150;
|
||||||
const MAX_SEARCH_BLOCK_COUNT = 30;
|
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;
|
const pageRoot = page.root;
|
||||||
if (!pageRoot) {
|
if (!pageRoot) {
|
||||||
return '';
|
return '';
|
||||||
@@ -60,7 +60,7 @@ export const getPagePreviewText = (page: Doc) => {
|
|||||||
|
|
||||||
const emptyAtom = atom<string>('');
|
const emptyAtom = atom<string>('');
|
||||||
|
|
||||||
export function useBlockSuitePagePreview(page: Doc | null): Atom<string> {
|
export function useBlockSuitePagePreview(page: Blocks | null): Atom<string> {
|
||||||
if (page === null) {
|
if (page === null) {
|
||||||
return emptyAtom;
|
return emptyAtom;
|
||||||
} else if (weakMap.has(page)) {
|
} else if (weakMap.has(page)) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { DebugLogger } from '@affine/debug';
|
import { DebugLogger } from '@affine/debug';
|
||||||
import { DisposableGroup } from '@blocksuite/affine/global/utils';
|
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';
|
import { useEffect, useState } from 'react';
|
||||||
|
|
||||||
const logger = new DebugLogger('useBlockSuiteWorkspacePage');
|
const logger = new DebugLogger('useBlockSuiteWorkspacePage');
|
||||||
@@ -8,7 +8,7 @@ const logger = new DebugLogger('useBlockSuiteWorkspacePage');
|
|||||||
export function useDocCollectionPage(
|
export function useDocCollectionPage(
|
||||||
docCollection: Workspace,
|
docCollection: Workspace,
|
||||||
pageId: string | null
|
pageId: string | null
|
||||||
): Doc | null {
|
): Blocks | null {
|
||||||
const [page, setPage] = useState(
|
const [page, setPage] = useState(
|
||||||
pageId ? docCollection.getDoc(pageId) : null
|
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 type { Workspace } from '@affine/core/modules/workspace';
|
||||||
import { useI18n } from '@affine/i18n';
|
import { useI18n } from '@affine/i18n';
|
||||||
import { track } from '@affine/track';
|
import { track } from '@affine/track';
|
||||||
import type { Doc } from '@blocksuite/affine/store';
|
import type { Blocks } from '@blocksuite/affine/store';
|
||||||
import {
|
import {
|
||||||
AllDocsIcon,
|
AllDocsIcon,
|
||||||
GithubIcon,
|
GithubIcon,
|
||||||
@@ -56,7 +56,7 @@ export type RootAppSidebarProps = {
|
|||||||
onOpenSettingModal: () => void;
|
onOpenSettingModal: () => void;
|
||||||
currentWorkspace: Workspace;
|
currentWorkspace: Workspace;
|
||||||
openPage: (pageId: string) => void;
|
openPage: (pageId: string) => void;
|
||||||
createPage: () => Doc;
|
createPage: () => Blocks;
|
||||||
paths: {
|
paths: {
|
||||||
all: (workspaceId: string) => string;
|
all: (workspaceId: string) => string;
|
||||||
trash: (workspaceId: string) => string;
|
trash: (workspaceId: string) => string;
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import {
|
|||||||
StrokeStyle,
|
StrokeStyle,
|
||||||
TextAlign,
|
TextAlign,
|
||||||
} from '@blocksuite/affine/blocks';
|
} 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 { useFramework, useLiveData } from '@toeverything/infra';
|
||||||
import { isEqual } from 'lodash-es';
|
import { isEqual } from 'lodash-es';
|
||||||
import { useCallback, useMemo } from 'react';
|
import { useCallback, useMemo } from 'react';
|
||||||
@@ -357,7 +357,7 @@ export const ConnectorSettings = () => {
|
|||||||
return getCurrentTextColor(color);
|
return getCurrentTextColor(color);
|
||||||
}, [getCurrentTextColor, settings]);
|
}, [getCurrentTextColor, settings]);
|
||||||
|
|
||||||
const getElements = useCallback((doc: Doc) => {
|
const getElements = useCallback((doc: Blocks) => {
|
||||||
const surface = getSurfaceBlock(doc);
|
const surface = getSurfaceBlock(doc);
|
||||||
return surface?.getElementsByType('connector') || [];
|
return surface?.getElementsByType('connector') || [];
|
||||||
}, []);
|
}, []);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { WorkspaceImpl } from '@affine/core/modules/workspace/impl/workspace';
|
import { WorkspaceImpl } from '@affine/core/modules/workspace/impl/workspace';
|
||||||
import { AffineSchemas } from '@blocksuite/affine/blocks';
|
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';
|
import { Job, Schema } from '@blocksuite/affine/store';
|
||||||
|
|
||||||
const getCollection = (() => {
|
const getCollection = (() => {
|
||||||
@@ -26,7 +26,7 @@ export type DocName =
|
|||||||
| 'connector'
|
| 'connector'
|
||||||
| 'mindmap';
|
| 'mindmap';
|
||||||
|
|
||||||
const docMap = new Map<DocName, Promise<Doc | undefined>>();
|
const docMap = new Map<DocName, Promise<Blocks | undefined>>();
|
||||||
|
|
||||||
async function loadNote() {
|
async function loadNote() {
|
||||||
return (await import('./note.json')).default;
|
return (await import('./note.json')).default;
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { SettingRow } from '@affine/component/setting-components';
|
|||||||
import { EditorSettingService } from '@affine/core/modules/editor-setting';
|
import { EditorSettingService } from '@affine/core/modules/editor-setting';
|
||||||
import { useI18n } from '@affine/i18n';
|
import { useI18n } from '@affine/i18n';
|
||||||
import { LayoutType, MindmapStyle } from '@blocksuite/affine/blocks';
|
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 { useFramework, useLiveData } from '@toeverything/infra';
|
||||||
import { useCallback, useMemo } from 'react';
|
import { useCallback, useMemo } from 'react';
|
||||||
|
|
||||||
@@ -93,7 +93,7 @@ export const MindMapSettings = () => {
|
|||||||
});
|
});
|
||||||
}, [editorSetting, settings]);
|
}, [editorSetting, settings]);
|
||||||
|
|
||||||
const getElements = useCallback((doc: Doc) => {
|
const getElements = useCallback((doc: Blocks) => {
|
||||||
const surface = getSurfaceBlock(doc);
|
const surface = getSurfaceBlock(doc);
|
||||||
return surface?.getElementsByType('mindmap') || [];
|
return surface?.getElementsByType('mindmap') || [];
|
||||||
}, []);
|
}, []);
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import {
|
|||||||
NoteShadowMap,
|
NoteShadowMap,
|
||||||
StrokeStyle,
|
StrokeStyle,
|
||||||
} from '@blocksuite/affine/blocks';
|
} 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 { useFramework, useLiveData } from '@toeverything/infra';
|
||||||
import { isEqual } from 'lodash-es';
|
import { isEqual } from 'lodash-es';
|
||||||
import { useCallback, useMemo } from 'react';
|
import { useCallback, useMemo } from 'react';
|
||||||
@@ -170,7 +170,7 @@ export const NoteSettings = () => {
|
|||||||
return getCurrentColor(background);
|
return getCurrentColor(background);
|
||||||
}, [getCurrentColor, settings]);
|
}, [getCurrentColor, settings]);
|
||||||
|
|
||||||
const getElements = useCallback((doc: Doc) => {
|
const getElements = useCallback((doc: Blocks) => {
|
||||||
return doc.getBlocksByFlavour('affine:note') || [];
|
return doc.getBlocksByFlavour('affine:note') || [];
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { SettingRow } from '@affine/component/setting-components';
|
|||||||
import { EditorSettingService } from '@affine/core/modules/editor-setting';
|
import { EditorSettingService } from '@affine/core/modules/editor-setting';
|
||||||
import { useI18n } from '@affine/i18n';
|
import { useI18n } from '@affine/i18n';
|
||||||
import { DefaultTheme } from '@blocksuite/affine/blocks';
|
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 { useFramework, useLiveData } from '@toeverything/infra';
|
||||||
import { isEqual } from 'lodash-es';
|
import { isEqual } from 'lodash-es';
|
||||||
import { useCallback, useMemo } from 'react';
|
import { useCallback, useMemo } from 'react';
|
||||||
@@ -59,7 +59,7 @@ export const PenSettings = () => {
|
|||||||
[editorSetting]
|
[editorSetting]
|
||||||
);
|
);
|
||||||
|
|
||||||
const getElements = useCallback((doc: Doc) => {
|
const getElements = useCallback((doc: Blocks) => {
|
||||||
const surface = getSurfaceBlock(doc);
|
const surface = getSurfaceBlock(doc);
|
||||||
return surface?.getElementsByType('brush') || [];
|
return surface?.getElementsByType('brush') || [];
|
||||||
}, []);
|
}, []);
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import {
|
|||||||
StrokeStyle,
|
StrokeStyle,
|
||||||
TextAlign,
|
TextAlign,
|
||||||
} from '@blocksuite/affine/blocks';
|
} 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 { useFramework, useLiveData } from '@toeverything/infra';
|
||||||
import { isEqual } from 'lodash-es';
|
import { isEqual } from 'lodash-es';
|
||||||
import { useCallback, useMemo, useState } from 'react';
|
import { useCallback, useMemo, useState } from 'react';
|
||||||
@@ -339,7 +339,7 @@ export const ShapeSettings = () => {
|
|||||||
}, [editorSetting, settings, currentShape, strokeColorPalettes]);
|
}, [editorSetting, settings, currentShape, strokeColorPalettes]);
|
||||||
|
|
||||||
const getElements = useCallback(
|
const getElements = useCallback(
|
||||||
(doc: Doc) => {
|
(doc: Blocks) => {
|
||||||
const surface = getSurfaceBlock(doc);
|
const surface = getSurfaceBlock(doc);
|
||||||
if (!surface) return [];
|
if (!surface) return [];
|
||||||
return surface.getElementsByType('shape').filter(node => {
|
return surface.getElementsByType('shape').filter(node => {
|
||||||
@@ -353,7 +353,7 @@ export const ShapeSettings = () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const firstUpdate = useCallback(
|
const firstUpdate = useCallback(
|
||||||
(doc: Doc, editorHost: EditorHost) => {
|
(doc: Blocks, editorHost: EditorHost) => {
|
||||||
const edgelessService = editorHost.std.getService(
|
const edgelessService = editorHost.std.getService(
|
||||||
'affine:page'
|
'affine:page'
|
||||||
) as EdgelessRootService;
|
) as EdgelessRootService;
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import {
|
|||||||
ThemeExtensionIdentifier,
|
ThemeExtensionIdentifier,
|
||||||
} from '@blocksuite/affine/blocks';
|
} from '@blocksuite/affine/blocks';
|
||||||
import { Bound } from '@blocksuite/affine/global/utils';
|
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 { createSignalFromObservable } from '@blocksuite/affine-shared/utils';
|
||||||
import type { Container } from '@blocksuite/global/di';
|
import type { Container } from '@blocksuite/global/di';
|
||||||
import type { Signal } from '@preact/signals-core';
|
import type { Signal } from '@preact/signals-core';
|
||||||
@@ -45,8 +45,8 @@ interface Props {
|
|||||||
docName: DocName;
|
docName: DocName;
|
||||||
keyName: keyof EditorSettingSchema;
|
keyName: keyof EditorSettingSchema;
|
||||||
height?: number;
|
height?: number;
|
||||||
getElements: (doc: Doc) => Array<Block | GfxPrimitiveElementModel>;
|
getElements: (doc: Blocks) => Array<Block | GfxPrimitiveElementModel>;
|
||||||
firstUpdate?: (doc: Doc, editorHost: EditorHost) => void;
|
firstUpdate?: (doc: Blocks, editorHost: EditorHost) => void;
|
||||||
children?: React.ReactElement;
|
children?: React.ReactElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@ export const EdgelessSnapshot = (props: Props) => {
|
|||||||
children,
|
children,
|
||||||
} = props;
|
} = props;
|
||||||
const wrapperRef = useRef<HTMLDivElement | null>(null);
|
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 editorHostRef = useRef<EditorHost | null>(null);
|
||||||
const framework = useFramework();
|
const framework = useFramework();
|
||||||
const { editorSetting } = framework.get(EditorSettingService);
|
const { editorSetting } = framework.get(EditorSettingService);
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import {
|
|||||||
FontWeightMap,
|
FontWeightMap,
|
||||||
TextAlign,
|
TextAlign,
|
||||||
} from '@blocksuite/affine/blocks';
|
} 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 { useFramework, useLiveData } from '@toeverything/infra';
|
||||||
import { isEqual } from 'lodash-es';
|
import { isEqual } from 'lodash-es';
|
||||||
import { useCallback, useMemo } from 'react';
|
import { useCallback, useMemo } from 'react';
|
||||||
@@ -143,7 +143,7 @@ export const TextSettings = () => {
|
|||||||
return getCurrentColor(color);
|
return getCurrentColor(color);
|
||||||
}, [getCurrentColor, settings]);
|
}, [getCurrentColor, settings]);
|
||||||
|
|
||||||
const getElements = useCallback((doc: Doc) => {
|
const getElements = useCallback((doc: Blocks) => {
|
||||||
return doc.getBlocksByFlavour('affine:edgeless-text') || [];
|
return doc.getBlocksByFlavour('affine:edgeless-text') || [];
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
import type { SurfaceBlockModel } from '@blocksuite/affine/block-std/gfx';
|
import type { SurfaceBlockModel } from '@blocksuite/affine/block-std/gfx';
|
||||||
import type { FrameBlockModel } from '@blocksuite/affine/blocks';
|
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');
|
const blocks = doc.getBlocksByFlavour('affine:surface');
|
||||||
return blocks.length !== 0 ? (blocks[0].model as SurfaceBlockModel) : null;
|
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');
|
const blocks = doc.getBlocksByFlavour('affine:frame');
|
||||||
return blocks.length !== 0 ? (blocks[0].model as FrameBlockModel) : null;
|
return blocks.length !== 0 ? (blocks[0].model as FrameBlockModel) : null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import type { Workspace } from '@affine/core/modules/workspace';
|
|||||||
import type { AffineDNDData } from '@affine/core/types/dnd';
|
import type { AffineDNDData } from '@affine/core/types/dnd';
|
||||||
import { useI18n } from '@affine/i18n';
|
import { useI18n } from '@affine/i18n';
|
||||||
import { track } from '@affine/track';
|
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 { useLiveData, useService } from '@toeverything/infra';
|
||||||
import { forwardRef, useCallback, useEffect, useRef, useState } from 'react';
|
import { forwardRef, useCallback, useEffect, useRef, useState } from 'react';
|
||||||
|
|
||||||
@@ -49,7 +49,7 @@ const Header = forwardRef<
|
|||||||
Header.displayName = 'forwardRef(Header)';
|
Header.displayName = 'forwardRef(Header)';
|
||||||
|
|
||||||
interface PageHeaderProps {
|
interface PageHeaderProps {
|
||||||
page: Doc;
|
page: Blocks;
|
||||||
workspace: Workspace;
|
workspace: Workspace;
|
||||||
}
|
}
|
||||||
export function JournalPageHeader({ page, workspace }: PageHeaderProps) {
|
export function JournalPageHeader({ page, workspace }: PageHeaderProps) {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { DebugLogger } from '@affine/debug';
|
import { DebugLogger } from '@affine/debug';
|
||||||
import { BlockStdScope } from '@blocksuite/affine/block-std';
|
import { BlockStdScope } from '@blocksuite/affine/block-std';
|
||||||
import { PageEditorBlockSpecs } from '@blocksuite/affine/blocks';
|
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 { LiveData } from '@toeverything/infra';
|
||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
@@ -42,7 +42,7 @@ export function signalToLiveData<T>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// todo(pengx17): use rc pool?
|
// todo(pengx17): use rc pool?
|
||||||
export function createBlockStdScope(doc: Doc) {
|
export function createBlockStdScope(doc: Blocks) {
|
||||||
logger.debug('createBlockStdScope', doc.id);
|
logger.debug('createBlockStdScope', doc.id);
|
||||||
const std = new BlockStdScope({
|
const std = new BlockStdScope({
|
||||||
doc,
|
doc,
|
||||||
@@ -51,6 +51,6 @@ export function createBlockStdScope(doc: Doc) {
|
|||||||
return std;
|
return std;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useBlockStdScope(doc: Doc) {
|
export function useBlockStdScope(doc: Blocks) {
|
||||||
return useMemo(() => createBlockStdScope(doc), [doc]);
|
return useMemo(() => createBlockStdScope(doc), [doc]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
DefaultInlineManagerExtension,
|
DefaultInlineManagerExtension,
|
||||||
RichText,
|
RichText,
|
||||||
} from '@blocksuite/affine/blocks';
|
} 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 { TextIcon } from '@blocksuite/icons/rc';
|
||||||
import { type LiveData, useLiveData } from '@toeverything/infra';
|
import { type LiveData, useLiveData } from '@toeverything/infra';
|
||||||
import { type CSSProperties, useEffect, useRef, useState } from 'react';
|
import { type CSSProperties, useEffect, useRef, useState } from 'react';
|
||||||
@@ -23,7 +23,7 @@ const renderRichText = ({
|
|||||||
}: {
|
}: {
|
||||||
std: BlockStdScope;
|
std: BlockStdScope;
|
||||||
text: Y.Text;
|
text: Y.Text;
|
||||||
doc: Doc;
|
doc: Blocks;
|
||||||
}) => {
|
}) => {
|
||||||
const inlineManager = std.get(DefaultInlineManagerExtension.identifier);
|
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 { Scope } from '@toeverything/infra';
|
||||||
|
|
||||||
import type { DocRecord } from '../entities/record';
|
import type { DocRecord } from '../entities/record';
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ import { NoopLogger, Slot } from '@blocksuite/affine/global/utils';
|
|||||||
import {
|
import {
|
||||||
AwarenessStore,
|
AwarenessStore,
|
||||||
BlockCollection,
|
BlockCollection,
|
||||||
|
type Blocks,
|
||||||
BlockSuiteDoc,
|
BlockSuiteDoc,
|
||||||
type CreateDocOptions,
|
type CreateDocOptions,
|
||||||
type Doc,
|
|
||||||
DocCollectionMeta,
|
DocCollectionMeta,
|
||||||
type GetDocOptions,
|
type GetDocOptions,
|
||||||
type IdGenerator,
|
type IdGenerator,
|
||||||
@@ -168,7 +168,7 @@ export class WorkspaceImpl implements Workspace {
|
|||||||
tags: [],
|
tags: [],
|
||||||
});
|
});
|
||||||
this.slots.docCreated.emit(docId);
|
this.slots.docCreated.emit(docId);
|
||||||
return this.getDoc(docId, { query, readonly }) as Doc;
|
return this.getDoc(docId, { query, readonly }) as Blocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
dispose() {
|
dispose() {
|
||||||
@@ -190,7 +190,7 @@ export class WorkspaceImpl implements Workspace {
|
|||||||
return space ?? null;
|
return space ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
getDoc(docId: string, options?: GetDocOptions): Doc | null {
|
getDoc(docId: string, options?: GetDocOptions): Blocks | null {
|
||||||
const collection = this.getBlockCollection(docId);
|
const collection = this.getBlockCollection(docId);
|
||||||
return collection?.getDoc(options) ?? null;
|
return collection?.getDoc(options) ?? null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user