refactor(core): move block collection to affine and implement as doc (#9514)
This commit is contained in:
@@ -167,7 +167,7 @@ export class BlockQueryDataSource extends DataSourceBase {
|
||||
type ?? propertyPresets.multiSelectPropertyConfig.type
|
||||
].create(this.newColumnName());
|
||||
|
||||
const id = doc.generateBlockId();
|
||||
const id = doc.collection.idGenerator();
|
||||
if (this.block.columns.some(v => v.id === id)) {
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ export class DataViewBlockModel extends BlockModel<Props> {
|
||||
}
|
||||
|
||||
duplicateView(id: string): string {
|
||||
const newId = this.doc.generateBlockId();
|
||||
const newId = this.doc.collection.idGenerator();
|
||||
this.doc.transact(() => {
|
||||
const index = this.views.findIndex(v => v.id === id);
|
||||
const view = this.views[index];
|
||||
|
||||
@@ -448,7 +448,7 @@ export const databaseViewInitTemplate = (
|
||||
const rowId = model.doc.addBlock(
|
||||
'affine:paragraph',
|
||||
{
|
||||
text: new model.doc.Text(`Task ${i + 1}`),
|
||||
text: new Text(`Task ${i + 1}`),
|
||||
},
|
||||
model.id
|
||||
);
|
||||
|
||||
@@ -19,7 +19,7 @@ export function addProperty(
|
||||
id?: string;
|
||||
}
|
||||
): string {
|
||||
const id = column.id ?? model.doc.generateBlockId();
|
||||
const id = column.id ?? model.doc.collection.idGenerator();
|
||||
if (model.columns.some(v => v.id === id)) {
|
||||
return id;
|
||||
}
|
||||
@@ -101,7 +101,7 @@ export function deleteView(model: DatabaseBlockModel, id: string) {
|
||||
}
|
||||
|
||||
export function duplicateView(model: DatabaseBlockModel, id: string): string {
|
||||
const newId = model.doc.generateBlockId();
|
||||
const newId = model.doc.collection.idGenerator();
|
||||
model.doc.transact(() => {
|
||||
const index = model.views.findIndex(v => v.id === id);
|
||||
const view = model.views[index];
|
||||
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
type DraftModel,
|
||||
type Query,
|
||||
Slice,
|
||||
Text,
|
||||
} from '@blocksuite/store';
|
||||
import { render, type TemplateResult } from 'lit';
|
||||
|
||||
@@ -407,7 +408,7 @@ export function createLinkedDocFromSlice(
|
||||
const linkedDoc = doc.collection.createDoc({});
|
||||
linkedDoc.load(() => {
|
||||
const rootId = linkedDoc.addBlock('affine:page', {
|
||||
title: new doc.Text(docTitle),
|
||||
title: new Text(docTitle),
|
||||
});
|
||||
linkedDoc.addBlock('affine:surface', {}, rootId);
|
||||
const noteId = linkedDoc.addBlock('affine:note', {}, rootId);
|
||||
|
||||
@@ -22,6 +22,7 @@ import {
|
||||
referenceToNode,
|
||||
} from '@blocksuite/affine-shared/utils';
|
||||
import { Bound, throttle } from '@blocksuite/global/utils';
|
||||
import { Text } from '@blocksuite/store';
|
||||
import { computed } from '@preact/signals-core';
|
||||
import { html, nothing } from 'lit';
|
||||
import { property, queryAsync, state } from 'lit/decorators.js';
|
||||
@@ -171,7 +172,7 @@ export class EmbedLinkedDocBlockComponent extends EmbedBlockComponent<EmbedLinke
|
||||
...this.referenceInfo$.peek(),
|
||||
},
|
||||
});
|
||||
const text = new doc.Text(yText);
|
||||
const text = new Text(yText);
|
||||
|
||||
doc.addBlock(
|
||||
'affine:paragraph',
|
||||
|
||||
@@ -29,6 +29,7 @@ import {
|
||||
BlockViewType,
|
||||
type GetDocOptions,
|
||||
type Query,
|
||||
Text,
|
||||
} from '@blocksuite/store';
|
||||
import { computed } from '@preact/signals-core';
|
||||
import { html, type PropertyValues } from 'lit';
|
||||
@@ -280,7 +281,7 @@ export class EmbedSyncedDocBlockComponent extends EmbedBlockComponent<EmbedSynce
|
||||
...this.referenceInfo,
|
||||
},
|
||||
});
|
||||
const text = new doc.Text(yText);
|
||||
const text = new Text(yText);
|
||||
|
||||
doc.addBlock(
|
||||
'affine:paragraph',
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { focusTextModel } from '@blocksuite/affine-components/rich-text';
|
||||
import { getLastNoteBlock } from '@blocksuite/affine-shared/utils';
|
||||
import type { Command } from '@blocksuite/block-std';
|
||||
import { Text } from '@blocksuite/store';
|
||||
|
||||
/**
|
||||
* Append a paragraph block at the end of the whole page.
|
||||
@@ -19,11 +20,7 @@ export const appendParagraphCommand: Command<
|
||||
if (!noteId) {
|
||||
noteId = doc.addBlock('affine:note', {}, doc.root.id);
|
||||
}
|
||||
const id = doc.addBlock(
|
||||
'affine:paragraph',
|
||||
{ text: new doc.Text(text) },
|
||||
noteId
|
||||
);
|
||||
const id = doc.addBlock('affine:paragraph', { text: new Text(text) }, noteId);
|
||||
|
||||
focusTextModel(std, id, text.length);
|
||||
next();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { Workspace } from '@blocksuite/store';
|
||||
import { Text } from '@blocksuite/store';
|
||||
|
||||
export function createDefaultDoc(
|
||||
collection: Workspace,
|
||||
@@ -9,7 +10,7 @@ export function createDefaultDoc(
|
||||
doc.load();
|
||||
const title = options.title ?? '';
|
||||
const rootId = doc.addBlock('affine:page', {
|
||||
title: new doc.Text(title),
|
||||
title: new Text(title),
|
||||
});
|
||||
collection.meta.setDocMeta(doc.id, {
|
||||
title,
|
||||
|
||||
Reference in New Issue
Block a user