mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-11 23:26:30 +08:00
refactor(editor): rename model.doc to store (#12172)
This commit is contained in:
@@ -104,7 +104,7 @@ const createHelmCommand = ({ isDryRun }) => {
|
||||
`--set web.resources.requests.cpu="${cpu.web}"`,
|
||||
`--set graphql.resources.requests.cpu="${cpu.graphql}"`,
|
||||
`--set sync.resources.requests.cpu="${cpu.sync}"`,
|
||||
`--set doc.resources.requests.cpu="${cpu.doc}"`,
|
||||
`--set doc.resources.requests.cpu="${cpu.store}"`,
|
||||
]
|
||||
: [];
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ import { downloadAttachmentBlob, refreshData } from './utils';
|
||||
|
||||
@Peekable({
|
||||
enableOn: ({ model }: AttachmentBlockComponent) => {
|
||||
return !model.doc.readonly && model.props.type.endsWith('pdf');
|
||||
return !model.store.readonly && model.props.type.endsWith('pdf');
|
||||
},
|
||||
})
|
||||
export class AttachmentBlockComponent extends CaptionedBlockComponent<AttachmentBlockModel> {
|
||||
|
||||
@@ -41,7 +41,7 @@ export const RenameModal = ({
|
||||
toast(editorHost, 'File name cannot be empty');
|
||||
return;
|
||||
}
|
||||
model.doc.updateBlock(model, {
|
||||
model.store.updateBlock(model, {
|
||||
name: newFileName,
|
||||
});
|
||||
abort();
|
||||
|
||||
@@ -18,7 +18,7 @@ export const attachmentSlashMenuConfig: SlashMenuConfig = {
|
||||
searchAlias: ['file'],
|
||||
group: '4_Content & Media@3',
|
||||
when: ({ model }) =>
|
||||
model.doc.schema.flavourSchemaMap.has('affine:attachment'),
|
||||
model.store.schema.flavourSchemaMap.has('affine:attachment'),
|
||||
action: ({ std, model }) => {
|
||||
(async () => {
|
||||
const file = await openFileOrFiles();
|
||||
@@ -41,7 +41,7 @@ export const attachmentSlashMenuConfig: SlashMenuConfig = {
|
||||
},
|
||||
group: '4_Content & Media@4',
|
||||
when: ({ model }) =>
|
||||
model.doc.schema.flavourSchemaMap.has('affine:attachment'),
|
||||
model.store.schema.flavourSchemaMap.has('affine:attachment'),
|
||||
action: ({ std, model }) => {
|
||||
(async () => {
|
||||
const file = await openFileOrFiles();
|
||||
|
||||
@@ -98,7 +98,7 @@ export class AttachmentEmbedService extends Extension {
|
||||
convertTo(model: AttachmentBlockModel, maxFileSize = this._maxFileSize) {
|
||||
const config = this.values.find(config => config.check(model, maxFileSize));
|
||||
if (!config?.action) {
|
||||
model.doc.updateBlock(model, { embed: true });
|
||||
model.store.updateBlock(model, { embed: true });
|
||||
return;
|
||||
}
|
||||
config.action(model, this.std)?.catch(console.error);
|
||||
@@ -129,7 +129,7 @@ const embedConfig: AttachmentEmbedConfig[] = [
|
||||
{
|
||||
name: 'image',
|
||||
check: model =>
|
||||
model.doc.schema.flavourSchemaMap.has('affine:image') &&
|
||||
model.store.schema.flavourSchemaMap.has('affine:image') &&
|
||||
model.props.type.startsWith('image/'),
|
||||
async action(model, std) {
|
||||
const component = std.view.getBlock(model.id);
|
||||
@@ -189,7 +189,7 @@ const embedConfig: AttachmentEmbedConfig[] = [
|
||||
* Turn the attachment block into an image block.
|
||||
*/
|
||||
async function turnIntoImageBlock(model: AttachmentBlockModel) {
|
||||
if (!model.doc.schema.flavourSchemaMap.has('affine:image')) {
|
||||
if (!model.store.schema.flavourSchemaMap.has('affine:image')) {
|
||||
console.error('The image flavour is not supported!');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ export async function getAttachmentBlob(model: AttachmentBlockModel) {
|
||||
const type = type$.peek();
|
||||
if (!sourceId) return null;
|
||||
|
||||
const doc = model.doc;
|
||||
const doc = model.store;
|
||||
const blob = await doc.blobSync.get(sourceId);
|
||||
if (!blob) return null;
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ const bookmarkSlashMenuConfig: SlashMenuConfig = {
|
||||
},
|
||||
group: '4_Content & Media@2',
|
||||
when: ({ model }) =>
|
||||
model.doc.schema.flavourSchemaMap.has('affine:bookmark'),
|
||||
model.store.schema.flavourSchemaMap.has('affine:bookmark'),
|
||||
action: ({ std, model }) => {
|
||||
const { host } = std;
|
||||
const parentModel = host.doc.getParent(model);
|
||||
@@ -45,7 +45,7 @@ const bookmarkSlashMenuConfig: SlashMenuConfig = {
|
||||
)
|
||||
.then(() => {
|
||||
if (model.text?.length === 0) {
|
||||
model.doc.deleteBlock(model);
|
||||
model.store.deleteBlock(model);
|
||||
}
|
||||
})
|
||||
.catch(console.error);
|
||||
|
||||
@@ -33,19 +33,24 @@ export const calloutSlashMenuConfig: SlashMenuConfig = {
|
||||
when: ({ std, model }) => {
|
||||
return (
|
||||
std.get(FeatureFlagService).getFlag('enable_callout') &&
|
||||
!isInsideBlockByFlavour(model.doc, model, 'affine:edgeless-text')
|
||||
!isInsideBlockByFlavour(model.store, model, 'affine:edgeless-text')
|
||||
);
|
||||
},
|
||||
action: ({ model, std }) => {
|
||||
const { doc } = model;
|
||||
const parent = doc.getParent(model);
|
||||
const { store } = model;
|
||||
const parent = store.getParent(model);
|
||||
if (!parent) return;
|
||||
|
||||
const index = parent.children.indexOf(model);
|
||||
if (index === -1) return;
|
||||
const calloutId = doc.addBlock('affine:callout', {}, parent, index + 1);
|
||||
const calloutId = store.addBlock(
|
||||
'affine:callout',
|
||||
{},
|
||||
parent,
|
||||
index + 1
|
||||
);
|
||||
if (!calloutId) return;
|
||||
const paragraphId = doc.addBlock('affine:paragraph', {}, calloutId);
|
||||
const paragraphId = store.addBlock('affine:paragraph', {}, calloutId);
|
||||
if (!paragraphId) return;
|
||||
std.host.updateComplete
|
||||
.then(() => {
|
||||
|
||||
@@ -363,7 +363,7 @@ export class CodeBlockComponent extends CaptionedBlockComponent<CodeBlockModel>
|
||||
|
||||
copyCode() {
|
||||
const model = this.model;
|
||||
const slice = Slice.fromModels(model.doc, [model]);
|
||||
const slice = Slice.fromModels(model.store, [model]);
|
||||
this.std.clipboard
|
||||
.copySlice(slice)
|
||||
.then(() => {
|
||||
|
||||
@@ -12,5 +12,5 @@ export const duplicateCodeBlock = (model: CodeBlockModel) => {
|
||||
...duplicateProps,
|
||||
};
|
||||
|
||||
return model.doc.addSiblingBlocks(model, [newProps])[0];
|
||||
return model.store.addSiblingBlocks(model, [newProps])[0];
|
||||
};
|
||||
|
||||
@@ -21,7 +21,7 @@ export const dataViewSlashMenuConfig: SlashMenuConfig = {
|
||||
},
|
||||
group: '7_Database@1',
|
||||
when: ({ model, std }) =>
|
||||
!isInsideBlockByFlavour(model.doc, model, 'affine:edgeless-text') &&
|
||||
!isInsideBlockByFlavour(model.store, model, 'affine:edgeless-text') &&
|
||||
!!std.get(FeatureFlagService).getFlag('enable_block_query'),
|
||||
|
||||
action: ({ model, std }) => {
|
||||
@@ -43,7 +43,7 @@ export const dataViewSlashMenuConfig: SlashMenuConfig = {
|
||||
dataView?.dataSource.viewManager.viewAdd('table');
|
||||
|
||||
if (model.text?.length === 0) {
|
||||
model.doc.deleteBlock(model);
|
||||
model.store.deleteBlock(model);
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
@@ -169,7 +169,7 @@ export class BlockQueryDataSource extends DataSourceBase {
|
||||
insertToPosition: InsertToPosition,
|
||||
type: string | undefined
|
||||
): string {
|
||||
const doc = this.block.doc;
|
||||
const doc = this.block.store;
|
||||
doc.captureSync();
|
||||
const column = DatabaseBlockDataSource.propertiesMap.value[
|
||||
type ?? propertyPresets.multiSelectPropertyConfig.type
|
||||
@@ -292,7 +292,7 @@ export class BlockQueryDataSource extends DataSourceBase {
|
||||
].config.propertyData.default(),
|
||||
cells: currentCells.map(() => undefined),
|
||||
};
|
||||
this.block.doc.captureSync();
|
||||
this.block.store.captureSync();
|
||||
viewColumn.type = toType;
|
||||
viewColumn.data = result.property;
|
||||
currentCells.forEach((value, i) => {
|
||||
|
||||
@@ -24,21 +24,21 @@ export class DataViewBlockModel extends BlockModel<Props> {
|
||||
}
|
||||
|
||||
applyViewsUpdate() {
|
||||
this.doc.updateBlock(this, {
|
||||
this.store.updateBlock(this, {
|
||||
views: this.props.views,
|
||||
});
|
||||
}
|
||||
|
||||
deleteView(id: string) {
|
||||
this.doc.captureSync();
|
||||
this.doc.transact(() => {
|
||||
this.store.captureSync();
|
||||
this.store.transact(() => {
|
||||
this.props.views = this.props.views.filter(v => v.id !== id);
|
||||
});
|
||||
}
|
||||
|
||||
duplicateView(id: string): string {
|
||||
const newId = this.doc.workspace.idGenerator();
|
||||
this.doc.transact(() => {
|
||||
const newId = this.store.workspace.idGenerator();
|
||||
this.store.transact(() => {
|
||||
const index = this.props.views.findIndex(v => v.id === id);
|
||||
const view = this.props.views[index];
|
||||
if (view) {
|
||||
@@ -53,7 +53,7 @@ export class DataViewBlockModel extends BlockModel<Props> {
|
||||
}
|
||||
|
||||
moveViewTo(id: string, position: InsertToPosition) {
|
||||
this.doc.transact(() => {
|
||||
this.store.transact(() => {
|
||||
this.props.views = arrayMove(
|
||||
this.props.views,
|
||||
v => v.id === id,
|
||||
@@ -67,7 +67,7 @@ export class DataViewBlockModel extends BlockModel<Props> {
|
||||
id: string,
|
||||
update: (data: DataViewDataType) => Partial<DataViewDataType>
|
||||
) {
|
||||
this.doc.transact(() => {
|
||||
this.store.transact(() => {
|
||||
this.props.views = this.props.views.map(v => {
|
||||
if (v.id !== id) {
|
||||
return v;
|
||||
|
||||
@@ -25,7 +25,7 @@ export const databaseSlashMenuConfig: SlashMenuConfig = {
|
||||
},
|
||||
group: '7_Database@0',
|
||||
when: ({ model }) =>
|
||||
!isInsideBlockByFlavour(model.doc, model, 'affine:edgeless-text'),
|
||||
!isInsideBlockByFlavour(model.store, model, 'affine:edgeless-text'),
|
||||
action: ({ std }) => {
|
||||
std.command
|
||||
.chain()
|
||||
@@ -58,7 +58,7 @@ export const databaseSlashMenuConfig: SlashMenuConfig = {
|
||||
},
|
||||
group: '7_Database@2',
|
||||
when: ({ model }) =>
|
||||
!isInsideBlockByFlavour(model.doc, model, 'affine:edgeless-text'),
|
||||
!isInsideBlockByFlavour(model.store, model, 'affine:edgeless-text'),
|
||||
action: ({ std }) => {
|
||||
std.command
|
||||
.chain()
|
||||
|
||||
@@ -99,7 +99,7 @@ export class DatabaseBlockDataSource extends DataSourceBase {
|
||||
|
||||
readonly$: ReadonlySignal<boolean> = computed(() => {
|
||||
return (
|
||||
this._model.doc.readonly ||
|
||||
this._model.store.readonly ||
|
||||
// TODO(@L-Sun): use block level readonly
|
||||
IS_MOBILE
|
||||
);
|
||||
@@ -120,7 +120,7 @@ export class DatabaseBlockDataSource extends DataSourceBase {
|
||||
viewMetas = databaseBlockViews;
|
||||
|
||||
get doc() {
|
||||
return this._model.doc;
|
||||
return this._model.store;
|
||||
}
|
||||
|
||||
allPropertyMetas$ = computed<PropertyMetaConfig<any, any, any, any>[]>(() => {
|
||||
@@ -302,7 +302,7 @@ export class DatabaseBlockDataSource extends DataSourceBase {
|
||||
return;
|
||||
}
|
||||
const { column: prevColumn, index } = result;
|
||||
this._model.doc.transact(() => {
|
||||
this._model.store.transact(() => {
|
||||
if (index >= 0) {
|
||||
const result = updater(prevColumn);
|
||||
this._model.props.columns[index] = { ...prevColumn, ...result };
|
||||
@@ -500,15 +500,15 @@ export class DatabaseBlockDataSource extends DataSourceBase {
|
||||
}
|
||||
|
||||
viewDataAdd(viewData: DataViewDataType): string {
|
||||
this._model.doc.captureSync();
|
||||
this._model.doc.transact(() => {
|
||||
this._model.store.captureSync();
|
||||
this._model.store.transact(() => {
|
||||
this._model.props.views = [...this._model.props.views, viewData];
|
||||
});
|
||||
return viewData.id;
|
||||
}
|
||||
|
||||
viewDataDelete(viewId: string): void {
|
||||
this._model.doc.captureSync();
|
||||
this._model.store.captureSync();
|
||||
deleteView(this._model, viewId);
|
||||
}
|
||||
|
||||
|
||||
@@ -434,13 +434,13 @@ export class DatabaseBlockComponent extends CaptionedBlockComponent<DatabaseBloc
|
||||
return peekViewService.peek({
|
||||
docId,
|
||||
databaseId: this.blockId,
|
||||
databaseDocId: this.model.doc.id,
|
||||
databaseDocId: this.model.store.id,
|
||||
databaseRowId: data.rowId,
|
||||
target: this,
|
||||
});
|
||||
};
|
||||
const doc = getSingleDocIdFromText(
|
||||
this.model.doc.getBlock(data.rowId)?.model?.text
|
||||
this.model.store.getBlock(data.rowId)?.model?.text
|
||||
);
|
||||
if (doc) {
|
||||
return openDoc(doc);
|
||||
|
||||
@@ -36,7 +36,7 @@ export class NoteRenderer
|
||||
accessor rowId!: string;
|
||||
|
||||
rowText$ = computed(() => {
|
||||
return this.databaseBlock.doc.getBlock(this.rowId)?.model?.text;
|
||||
return this.databaseBlock.store.getBlock(this.rowId)?.model?.text;
|
||||
});
|
||||
|
||||
allowCreateDoc$ = computed(() => {
|
||||
|
||||
@@ -19,11 +19,11 @@ export function addProperty(
|
||||
id?: string;
|
||||
}
|
||||
): string {
|
||||
const id = column.id ?? model.doc.workspace.idGenerator();
|
||||
const id = column.id ?? model.store.workspace.idGenerator();
|
||||
if (model.props.columns.some(v => v.id === id)) {
|
||||
return id;
|
||||
}
|
||||
model.doc.transact(() => {
|
||||
model.store.transact(() => {
|
||||
const col: ColumnDataType = {
|
||||
...column,
|
||||
id,
|
||||
@@ -42,7 +42,7 @@ export function copyCellsByProperty(
|
||||
fromId: ColumnDataType['id'],
|
||||
toId: ColumnDataType['id']
|
||||
) {
|
||||
model.doc.transact(() => {
|
||||
model.store.transact(() => {
|
||||
Object.keys(model.props.cells).forEach(rowId => {
|
||||
const cell = model.props.cells[rowId]?.[fromId];
|
||||
if (cell && model.props.cells[rowId]) {
|
||||
@@ -62,13 +62,13 @@ export function deleteColumn(
|
||||
const index = model.props.columns.findIndex(v => v.id === columnId);
|
||||
if (index < 0) return;
|
||||
|
||||
model.doc.transact(() => {
|
||||
model.store.transact(() => {
|
||||
model.props.columns.splice(index, 1);
|
||||
});
|
||||
}
|
||||
|
||||
export function deleteRows(model: DatabaseBlockModel, rowIds: string[]) {
|
||||
model.doc.transact(() => {
|
||||
model.store.transact(() => {
|
||||
for (const rowId of rowIds) {
|
||||
delete model.props.cells[rowId];
|
||||
}
|
||||
@@ -76,15 +76,15 @@ export function deleteRows(model: DatabaseBlockModel, rowIds: string[]) {
|
||||
}
|
||||
|
||||
export function deleteView(model: DatabaseBlockModel, id: string) {
|
||||
model.doc.captureSync();
|
||||
model.doc.transact(() => {
|
||||
model.store.captureSync();
|
||||
model.store.transact(() => {
|
||||
model.props.views = model.props.views.filter(v => v.id !== id);
|
||||
});
|
||||
}
|
||||
|
||||
export function duplicateView(model: DatabaseBlockModel, id: string): string {
|
||||
const newId = model.doc.workspace.idGenerator();
|
||||
model.doc.transact(() => {
|
||||
const newId = model.store.workspace.idGenerator();
|
||||
model.store.transact(() => {
|
||||
const index = model.props.views.findIndex(v => v.id === id);
|
||||
const view = model.props.views[index];
|
||||
if (view) {
|
||||
@@ -131,7 +131,7 @@ export function moveViewTo(
|
||||
id: string,
|
||||
position: InsertToPosition
|
||||
) {
|
||||
model.doc.transact(() => {
|
||||
model.store.transact(() => {
|
||||
model.props.views = arrayMove(
|
||||
model.props.views,
|
||||
v => v.id === id,
|
||||
@@ -145,7 +145,7 @@ export function updateCell(
|
||||
rowId: string,
|
||||
cell: CellDataType
|
||||
) {
|
||||
model.doc.transact(() => {
|
||||
model.store.transact(() => {
|
||||
const columnId = cell.columnId;
|
||||
if (
|
||||
rowId === '__proto__' ||
|
||||
@@ -180,7 +180,7 @@ export function updateCells(
|
||||
columnId: string,
|
||||
cells: Record<string, unknown>
|
||||
) {
|
||||
model.doc.transact(() => {
|
||||
model.store.transact(() => {
|
||||
Object.entries(cells).forEach(([rowId, value]) => {
|
||||
if (
|
||||
rowId === '__proto__' ||
|
||||
@@ -212,7 +212,7 @@ export function updateProperty(
|
||||
if (index == null) {
|
||||
return;
|
||||
}
|
||||
model.doc.transact(() => {
|
||||
model.store.transact(() => {
|
||||
const column = model.props.columns[index];
|
||||
if (!column) {
|
||||
return;
|
||||
@@ -228,7 +228,7 @@ export const updateView = <ViewData extends ViewBasicDataType>(
|
||||
id: string,
|
||||
update: (data: ViewData) => Partial<ViewData>
|
||||
) => {
|
||||
model.doc.transact(() => {
|
||||
model.store.transact(() => {
|
||||
model.props.views = model.props.views.map(v => {
|
||||
if (v.id !== id) {
|
||||
return v;
|
||||
|
||||
@@ -23,7 +23,7 @@ const linkedDocSlashMenuConfig: SlashMenuConfig = {
|
||||
},
|
||||
group: '3_Page@0',
|
||||
when: ({ model }) =>
|
||||
model.doc.schema.flavourSchemaMap.has('affine:embed-linked-doc'),
|
||||
model.store.schema.flavourSchemaMap.has('affine:embed-linked-doc'),
|
||||
action: ({ std, model }) => {
|
||||
const newDoc = createDefaultDoc(std.host.doc.workspace);
|
||||
insertContent(std, model, REFERENCE_NODE, {
|
||||
@@ -45,7 +45,7 @@ const linkedDocSlashMenuConfig: SlashMenuConfig = {
|
||||
searchAlias: ['dual link'],
|
||||
group: '3_Page@1',
|
||||
when: ({ std, model }) => {
|
||||
const root = model.doc.root;
|
||||
const root = model.store.root;
|
||||
if (!root) return false;
|
||||
const linkedDocWidget = std.view.getWidget(
|
||||
'affine-linked-doc-widget',
|
||||
@@ -53,10 +53,12 @@ const linkedDocSlashMenuConfig: SlashMenuConfig = {
|
||||
);
|
||||
if (!linkedDocWidget) return false;
|
||||
|
||||
return model.doc.schema.flavourSchemaMap.has('affine:embed-linked-doc');
|
||||
return model.store.schema.flavourSchemaMap.has(
|
||||
'affine:embed-linked-doc'
|
||||
);
|
||||
},
|
||||
action: ({ model, std }) => {
|
||||
const root = model.doc.root;
|
||||
const root = model.store.root;
|
||||
if (!root) return;
|
||||
const linkedDocWidget = std.view.getWidget(
|
||||
'affine-linked-doc-widget',
|
||||
|
||||
+2
-2
@@ -21,7 +21,7 @@ export class EmbedEdgelessLinkedDocBlockComponent extends toEdgelessEmbedBlock(
|
||||
) {
|
||||
override convertToEmbed = () => {
|
||||
const { caption, xywh } = this.model.props;
|
||||
const { doc, id } = this.model;
|
||||
const { store, id } = this.model;
|
||||
|
||||
const style = 'syncedDoc';
|
||||
const bound = Bound.deserialize(xywh);
|
||||
@@ -50,7 +50,7 @@ export class EmbedEdgelessLinkedDocBlockComponent extends toEdgelessEmbedBlock(
|
||||
elements: [newId],
|
||||
});
|
||||
|
||||
doc.deleteBlock(this.model);
|
||||
store.deleteBlock(this.model);
|
||||
};
|
||||
|
||||
protected override _handleClick = (evt: MouseEvent): void => {
|
||||
|
||||
+7
-7
@@ -137,10 +137,10 @@ export class EmbedLinkedDocBlockComponent extends EmbedBlockComponent<EmbedLinke
|
||||
if (this._referenceToNode) return;
|
||||
|
||||
const { caption } = this.model.props;
|
||||
const { parent, doc } = this.model;
|
||||
const { parent, store } = this.model;
|
||||
const index = parent?.children.indexOf(this.model);
|
||||
|
||||
const blockId = doc.addBlock(
|
||||
const blockId = store.addBlock(
|
||||
'affine:embed-synced-doc',
|
||||
{
|
||||
caption,
|
||||
@@ -150,7 +150,7 @@ export class EmbedLinkedDocBlockComponent extends EmbedBlockComponent<EmbedLinke
|
||||
index
|
||||
);
|
||||
|
||||
doc.deleteBlock(this.model);
|
||||
store.deleteBlock(this.model);
|
||||
|
||||
this.std.selection.setGroup('note', [
|
||||
this.std.selection.create(BlockSelection, { blockId }),
|
||||
@@ -158,8 +158,8 @@ export class EmbedLinkedDocBlockComponent extends EmbedBlockComponent<EmbedLinke
|
||||
};
|
||||
|
||||
convertToInline = () => {
|
||||
const { doc } = this.model;
|
||||
const parent = doc.getParent(this.model);
|
||||
const { store } = this.model;
|
||||
const parent = store.getParent(this.model);
|
||||
if (!parent) {
|
||||
return;
|
||||
}
|
||||
@@ -175,7 +175,7 @@ export class EmbedLinkedDocBlockComponent extends EmbedBlockComponent<EmbedLinke
|
||||
});
|
||||
const text = new Text(yText);
|
||||
|
||||
doc.addBlock(
|
||||
store.addBlock(
|
||||
'affine:paragraph',
|
||||
{
|
||||
text,
|
||||
@@ -184,7 +184,7 @@ export class EmbedLinkedDocBlockComponent extends EmbedBlockComponent<EmbedLinke
|
||||
index
|
||||
);
|
||||
|
||||
doc.deleteBlock(this.model);
|
||||
store.deleteBlock(this.model);
|
||||
};
|
||||
|
||||
referenceInfo$ = computed(() => {
|
||||
|
||||
+2
-2
@@ -145,7 +145,7 @@ export class EmbedEdgelessSyncedDocBlockComponent extends toEdgelessEmbedBlock(
|
||||
};
|
||||
|
||||
override convertToCard = (aliasInfo?: AliasInfo) => {
|
||||
const { id, doc, xywh } = this.model;
|
||||
const { id, store, xywh } = this.model;
|
||||
const { caption } = this.model.props;
|
||||
|
||||
const style = 'vertical';
|
||||
@@ -176,7 +176,7 @@ export class EmbedEdgelessSyncedDocBlockComponent extends toEdgelessEmbedBlock(
|
||||
editing: false,
|
||||
elements: [newId],
|
||||
});
|
||||
doc.deleteBlock(this.model);
|
||||
store.deleteBlock(this.model);
|
||||
};
|
||||
|
||||
override renderGfxBlock() {
|
||||
|
||||
+8
-8
@@ -276,10 +276,10 @@ export class EmbedSyncedDocBlockComponent extends EmbedBlockComponent<EmbedSynce
|
||||
});
|
||||
|
||||
convertToCard = (aliasInfo?: AliasInfo) => {
|
||||
const { doc } = this.model;
|
||||
const { store } = this.model;
|
||||
const { caption } = this.model.props;
|
||||
|
||||
const parent = doc.getParent(this.model);
|
||||
const parent = store.getParent(this.model);
|
||||
if (!parent) {
|
||||
console.error(
|
||||
`Trying to convert synced doc to card, but the parent is not found.`
|
||||
@@ -288,14 +288,14 @@ export class EmbedSyncedDocBlockComponent extends EmbedBlockComponent<EmbedSynce
|
||||
}
|
||||
const index = parent.children.indexOf(this.model);
|
||||
|
||||
const blockId = doc.addBlock(
|
||||
const blockId = store.addBlock(
|
||||
'affine:embed-linked-doc',
|
||||
{ caption, ...this.referenceInfo, ...aliasInfo },
|
||||
parent,
|
||||
index
|
||||
);
|
||||
|
||||
doc.deleteBlock(this.model);
|
||||
store.deleteBlock(this.model);
|
||||
|
||||
this.std.selection.setGroup('note', [
|
||||
this.std.selection.create(BlockSelection, { blockId }),
|
||||
@@ -303,8 +303,8 @@ export class EmbedSyncedDocBlockComponent extends EmbedBlockComponent<EmbedSynce
|
||||
};
|
||||
|
||||
convertToInline = () => {
|
||||
const { doc } = this.model;
|
||||
const parent = doc.getParent(this.model);
|
||||
const { store } = this.model;
|
||||
const parent = store.getParent(this.model);
|
||||
if (!parent) {
|
||||
console.error(
|
||||
`Trying to convert synced doc to inline, but the parent is not found.`
|
||||
@@ -323,7 +323,7 @@ export class EmbedSyncedDocBlockComponent extends EmbedBlockComponent<EmbedSynce
|
||||
});
|
||||
const text = new Text(yText);
|
||||
|
||||
doc.addBlock(
|
||||
store.addBlock(
|
||||
'affine:paragraph',
|
||||
{
|
||||
text,
|
||||
@@ -332,7 +332,7 @@ export class EmbedSyncedDocBlockComponent extends EmbedBlockComponent<EmbedSynce
|
||||
index
|
||||
);
|
||||
|
||||
doc.deleteBlock(this.model);
|
||||
store.deleteBlock(this.model);
|
||||
};
|
||||
|
||||
protected override embedContainerStyle: StyleInfo = {
|
||||
|
||||
@@ -18,7 +18,7 @@ export const embedFigmaSlashMenuConfig: SlashMenuConfig = {
|
||||
},
|
||||
group: '4_Content & Media@8',
|
||||
when: ({ model }) =>
|
||||
model.doc.schema.flavourSchemaMap.has('affine:embed-figma'),
|
||||
model.store.schema.flavourSchemaMap.has('affine:embed-figma'),
|
||||
action: ({ std, model }) => {
|
||||
(async () => {
|
||||
const { host } = std;
|
||||
|
||||
@@ -18,7 +18,7 @@ export const embedGithubSlashMenuConfig: SlashMenuConfig = {
|
||||
},
|
||||
group: '4_Content & Media@7',
|
||||
when: ({ model }) =>
|
||||
model.doc.schema.flavourSchemaMap.has('affine:embed-github'),
|
||||
model.store.schema.flavourSchemaMap.has('affine:embed-github'),
|
||||
action: ({ std, model }) => {
|
||||
(async () => {
|
||||
const { host } = std;
|
||||
|
||||
+1
-1
@@ -282,7 +282,7 @@ export class EmbedIframeErrorCard extends WithDisposable(LitElement) {
|
||||
}
|
||||
|
||||
get readonly() {
|
||||
return this.model.doc.readonly;
|
||||
return this.model.store.readonly;
|
||||
}
|
||||
|
||||
get telemetryService() {
|
||||
|
||||
+1
-1
@@ -133,7 +133,7 @@ export class EmbedIframeLinkInputBase extends WithDisposable(LitElement) {
|
||||
}
|
||||
|
||||
get store() {
|
||||
return this.model.doc;
|
||||
return this.model.store;
|
||||
}
|
||||
|
||||
get notificationService() {
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ export const embedIframeSlashMenuConfig: SlashMenuConfig = {
|
||||
},
|
||||
group: '4_Content & Media@5',
|
||||
when: ({ model }) => {
|
||||
return model.doc.schema.flavourSchemaMap.has('affine:embed-iframe');
|
||||
return model.store.schema.flavourSchemaMap.has('affine:embed-iframe');
|
||||
},
|
||||
action: ({ std }) => {
|
||||
std.command
|
||||
|
||||
@@ -18,7 +18,7 @@ export const embedLoomSlashMenuConfig: SlashMenuConfig = {
|
||||
},
|
||||
group: '4_Content & Media@9',
|
||||
when: ({ model }) =>
|
||||
model.doc.schema.flavourSchemaMap.has('affine:embed-loom'),
|
||||
model.store.schema.flavourSchemaMap.has('affine:embed-loom'),
|
||||
action: ({ std, model }) => {
|
||||
(async () => {
|
||||
const { host } = std;
|
||||
|
||||
@@ -18,7 +18,7 @@ export const embedYoutubeSlashMenuConfig: SlashMenuConfig = {
|
||||
},
|
||||
group: '4_Content & Media@6',
|
||||
when: ({ model }) =>
|
||||
model.doc.schema.flavourSchemaMap.has('affine:embed-youtube'),
|
||||
model.store.schema.flavourSchemaMap.has('affine:embed-youtube'),
|
||||
action: ({ std, model }) => {
|
||||
(async () => {
|
||||
const { host } = std;
|
||||
|
||||
@@ -17,7 +17,7 @@ export const imageSlashMenuConfig: SlashMenuConfig = {
|
||||
},
|
||||
group: '4_Content & Media@1',
|
||||
when: ({ model }) =>
|
||||
model.doc.schema.flavourSchemaMap.has('affine:image'),
|
||||
model.store.schema.flavourSchemaMap.has('affine:image'),
|
||||
action: ({ std }) => {
|
||||
const [success, ctx] = std.command
|
||||
.chain()
|
||||
|
||||
@@ -23,9 +23,9 @@ export class ImageResizeManager {
|
||||
}
|
||||
|
||||
const dragModel = getModelByElement(this._activeComponent);
|
||||
dragModel?.doc.captureSync();
|
||||
dragModel?.store.captureSync();
|
||||
const { width, height } = this._imageContainer.getBoundingClientRect();
|
||||
dragModel?.doc.updateBlock(dragModel, {
|
||||
dragModel?.store.updateBlock(dragModel, {
|
||||
width: width / this._zoom,
|
||||
height: height / this._zoom,
|
||||
});
|
||||
|
||||
@@ -13,7 +13,7 @@ const flavour = ImageBlockSchema.model.flavour;
|
||||
export const ImageBlockSpec: ExtensionType[] = [
|
||||
FlavourExtension(flavour),
|
||||
BlockViewExtension(flavour, model => {
|
||||
const parent = model.doc.getParent(model.id);
|
||||
const parent = model.store.getParent(model.id);
|
||||
|
||||
if (parent?.flavour === 'affine:surface') {
|
||||
return literal`affine-edgeless-image`;
|
||||
|
||||
@@ -36,7 +36,7 @@ async function getImageBlob(model: ImageBlockModel) {
|
||||
const sourceId = model.props.sourceId$.peek();
|
||||
if (!sourceId) return null;
|
||||
|
||||
const doc = model.doc;
|
||||
const doc = model.store;
|
||||
let blob = await doc.blobSync.get(sourceId);
|
||||
if (!blob) return null;
|
||||
|
||||
@@ -419,15 +419,15 @@ export function duplicate(block: ImageBlockComponent) {
|
||||
...duplicateProps
|
||||
} = blockProps;
|
||||
|
||||
const { doc } = model;
|
||||
const parent = doc.getParent(model);
|
||||
const { store } = model;
|
||||
const parent = store.getParent(model);
|
||||
if (!parent) {
|
||||
console.error(`Parent not found for block(${model.flavour}) ${model.id}`);
|
||||
return;
|
||||
}
|
||||
|
||||
const index = parent?.children.indexOf(model);
|
||||
const duplicateId = doc.addBlock(
|
||||
const duplicateId = store.addBlock(
|
||||
model.flavour,
|
||||
duplicateProps,
|
||||
parent,
|
||||
|
||||
@@ -15,10 +15,10 @@ import { getNumberPrefix } from './get-number-prefix.js';
|
||||
|
||||
const getListDeep = (model: ListBlockModel): number => {
|
||||
let deep = 0;
|
||||
let parent = model.doc.getParent(model);
|
||||
let parent = model.store.getParent(model);
|
||||
while (parent?.flavour === model.flavour) {
|
||||
deep++;
|
||||
parent = model.doc.getParent(parent);
|
||||
parent = model.store.getParent(parent);
|
||||
}
|
||||
return deep;
|
||||
};
|
||||
@@ -56,7 +56,7 @@ export function getListIcon(
|
||||
case 'todo':
|
||||
return html`<div
|
||||
contenteditable="false"
|
||||
class=${`affine-list-block__prefix affine-list-block__todo-prefix ${model.doc.readonly ? 'readonly' : ''}`}
|
||||
class=${`affine-list-block__prefix affine-list-block__todo-prefix ${model.store.readonly ? 'readonly' : ''}`}
|
||||
@click=${onClick}
|
||||
>
|
||||
${model.props.checked
|
||||
|
||||
@@ -45,8 +45,12 @@ const noteSlashMenuConfig: SlashMenuConfig = {
|
||||
({
|
||||
...createConversionItem(config, `0_Basic@${basicIndex++}`),
|
||||
when: ({ model }) =>
|
||||
model.doc.schema.flavourSchemaMap.has(config.flavour) &&
|
||||
!isInsideBlockByFlavour(model.doc, model, 'affine:edgeless-text'),
|
||||
model.store.schema.flavourSchemaMap.has(config.flavour) &&
|
||||
!isInsideBlockByFlavour(
|
||||
model.store,
|
||||
model,
|
||||
'affine:edgeless-text'
|
||||
),
|
||||
}) satisfies SlashMenuActionItem
|
||||
),
|
||||
|
||||
@@ -75,7 +79,7 @@ function createConversionItem(
|
||||
description,
|
||||
icon,
|
||||
tooltip: tooltips[name],
|
||||
when: ({ model }) => model.doc.schema.flavourSchemaMap.has(flavour),
|
||||
when: ({ model }) => model.store.schema.flavourSchemaMap.has(flavour),
|
||||
action: ({ std }) => {
|
||||
std.command.exec(updateBlockType, {
|
||||
flavour,
|
||||
|
||||
@@ -130,14 +130,14 @@ export class EdgelessNoteBlockComponent extends toGfxBlockComponent(
|
||||
const { collapse, collapsedHeight } = this.model.props.edgeless;
|
||||
|
||||
if (collapse) {
|
||||
this.model.doc.updateBlock(this.model, () => {
|
||||
this.model.store.updateBlock(this.model, () => {
|
||||
this.model.props.edgeless.collapse = false;
|
||||
});
|
||||
} else if (collapsedHeight) {
|
||||
const { xywh, edgeless } = this.model.props;
|
||||
const bound = Bound.deserialize(xywh);
|
||||
bound.h = collapsedHeight * (edgeless.scale ?? 1);
|
||||
this.model.doc.updateBlock(this.model, () => {
|
||||
this.model.store.updateBlock(this.model, () => {
|
||||
this.model.props.edgeless.collapse = true;
|
||||
this.model.props.xywh = bound.serialize();
|
||||
});
|
||||
|
||||
@@ -41,7 +41,7 @@ import type { BlockModel, Text } from '@blocksuite/store';
|
||||
* - line3
|
||||
*/
|
||||
export function mergeWithPrev(editorHost: EditorHost, model: BlockModel) {
|
||||
const doc = model.doc;
|
||||
const doc = model.store;
|
||||
const parent = doc.getParent(model);
|
||||
if (!parent) return false;
|
||||
|
||||
@@ -118,7 +118,7 @@ export function mergeWithPrev(editorHost: EditorHost, model: BlockModel) {
|
||||
}
|
||||
|
||||
function handleNoPreviousSibling(editorHost: EditorHost, model: ExtendedModel) {
|
||||
const doc = model.doc;
|
||||
const doc = model.store;
|
||||
const text = model.text;
|
||||
const parent = doc.getParent(model);
|
||||
if (!parent) return false;
|
||||
@@ -137,7 +137,7 @@ function handleNoPreviousSibling(editorHost: EditorHost, model: ExtendedModel) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const rootModel = model.doc.root as RootBlockModel;
|
||||
const rootModel = model.store.root as RootBlockModel;
|
||||
const title = rootModel.props.title;
|
||||
|
||||
doc.captureSync();
|
||||
|
||||
@@ -43,7 +43,7 @@ export class SurfaceRefNotePortal extends WithDisposable(ShadowlessElement) {
|
||||
let parent: BlockModel | null = this.model;
|
||||
while (parent) {
|
||||
this.ancestors.add(parent.id);
|
||||
parent = this.model.doc.getParent(parent.id);
|
||||
parent = this.model.store.getParent(parent.id);
|
||||
}
|
||||
const query: Query = {
|
||||
mode: 'include',
|
||||
@@ -54,7 +54,7 @@ export class SurfaceRefNotePortal extends WithDisposable(ShadowlessElement) {
|
||||
};
|
||||
this.query = query;
|
||||
|
||||
const doc = this.model.doc;
|
||||
const doc = this.model.store;
|
||||
this._disposables.add(() => {
|
||||
doc.doc.removeStore({ query, readonly: true });
|
||||
});
|
||||
@@ -118,7 +118,7 @@ export class SurfaceRefNotePortal extends WithDisposable(ShadowlessElement) {
|
||||
console.error('Query is not set before rendering note preview');
|
||||
return nothing;
|
||||
}
|
||||
const doc = this.model.doc.doc.getStore({
|
||||
const doc = this.model.store.doc.getStore({
|
||||
query: this.query,
|
||||
readonly: true,
|
||||
});
|
||||
|
||||
@@ -402,7 +402,7 @@ export class SurfaceRefBlockComponent extends BlockComponent<SurfaceRefBlockMode
|
||||
openMode?: OpenDocMode;
|
||||
event?: MouseEvent;
|
||||
} = {}) => {
|
||||
const pageId = this.referenceModel?.surface?.doc.id;
|
||||
const pageId = this.referenceModel?.surface?.store.id;
|
||||
if (!pageId) return;
|
||||
|
||||
this.std.getOptional(RefNodeSlotsProvider)?.docLinkClicked.next({
|
||||
|
||||
@@ -438,7 +438,7 @@ export class ExportManager {
|
||||
if (matchModels(block, [ImageBlockModel])) {
|
||||
if (!block.props.sourceId) return;
|
||||
|
||||
const blob = await block.doc.blobSync.get(block.props.sourceId);
|
||||
const blob = await block.store.blobSync.get(block.props.sourceId);
|
||||
if (!blob) return;
|
||||
|
||||
const blobToImage = (blob: Blob) =>
|
||||
|
||||
@@ -44,7 +44,7 @@ export class SurfaceBlockModel extends BaseSurfaceModel {
|
||||
override _init() {
|
||||
this._extendElement(elementsCtorMap);
|
||||
super._init();
|
||||
this.doc.provider
|
||||
this.store.provider
|
||||
.getAll(surfaceMiddlewareIdentifier)
|
||||
.forEach(({ middleware }) => {
|
||||
this._disposables.add(middleware(this));
|
||||
|
||||
@@ -51,7 +51,7 @@ export function updateXYWH(
|
||||
bound.w = clamp(bound.w, NOTE_MIN_WIDTH * scale, Infinity);
|
||||
bound.h = clamp(bound.h, NOTE_MIN_HEIGHT * scale, Infinity);
|
||||
if (bound.h >= NOTE_MIN_HEIGHT * scale) {
|
||||
updateBlock.call(ele.doc, ele, () => {
|
||||
updateBlock.call(ele.store, ele, () => {
|
||||
ele.props.edgeless.collapse = true;
|
||||
ele.props.edgeless.collapsedHeight = bound.h / scale;
|
||||
});
|
||||
|
||||
@@ -20,7 +20,7 @@ export const tableSlashMenuConfig: SlashMenuConfig = {
|
||||
},
|
||||
group: '4_Content & Media@0',
|
||||
when: ({ model }) =>
|
||||
!isInsideBlockByFlavour(model.doc, model, 'affine:edgeless-text'),
|
||||
!isInsideBlockByFlavour(model.store, model, 'affine:edgeless-text'),
|
||||
action: ({ std }) => {
|
||||
std.command
|
||||
.chain()
|
||||
|
||||
@@ -8,7 +8,7 @@ import type { TableAreaSelection } from './selection-schema';
|
||||
export class TableDataManager {
|
||||
constructor(private readonly model: TableBlockModel) {}
|
||||
readonly readonly$: ReadonlySignal<boolean> = computed(() => {
|
||||
return this.model.doc.readonly;
|
||||
return this.model.store.readonly;
|
||||
});
|
||||
readonly ui = {
|
||||
columnIndicatorIndex$: signal<number>(),
|
||||
@@ -83,7 +83,7 @@ export class TableDataManager {
|
||||
addRow(after?: number) {
|
||||
const order = this.getOrder(this.rows$.value, after);
|
||||
const rowId = nanoid();
|
||||
this.model.doc.transact(() => {
|
||||
this.model.store.transact(() => {
|
||||
this.model.props.rows[rowId] = {
|
||||
rowId,
|
||||
order,
|
||||
@@ -102,7 +102,7 @@ export class TableDataManager {
|
||||
return;
|
||||
}
|
||||
if (count > 0) {
|
||||
this.model.doc.transact(() => {
|
||||
this.model.store.transact(() => {
|
||||
for (let i = 0; i < count; i++) {
|
||||
this.addRow(this.rows$.value.length - 1);
|
||||
}
|
||||
@@ -110,7 +110,7 @@ export class TableDataManager {
|
||||
} else {
|
||||
const rows = this.rows$.value;
|
||||
const rowCount = rows.length;
|
||||
this.model.doc.transact(() => {
|
||||
this.model.store.transact(() => {
|
||||
rows.slice(rowCount + count, rowCount).forEach(row => {
|
||||
this.deleteRow(row.rowId);
|
||||
});
|
||||
@@ -123,7 +123,7 @@ export class TableDataManager {
|
||||
return;
|
||||
}
|
||||
if (count > 0) {
|
||||
this.model.doc.transact(() => {
|
||||
this.model.store.transact(() => {
|
||||
for (let i = 0; i < count; i++) {
|
||||
this.addColumn(this.columns$.value.length - 1);
|
||||
}
|
||||
@@ -131,7 +131,7 @@ export class TableDataManager {
|
||||
} else {
|
||||
const columns = this.columns$.value;
|
||||
const columnCount = columns.length;
|
||||
this.model.doc.transact(() => {
|
||||
this.model.store.transact(() => {
|
||||
columns.slice(columnCount + count, columnCount).forEach(column => {
|
||||
this.deleteColumn(column.columnId);
|
||||
});
|
||||
@@ -153,7 +153,7 @@ export class TableDataManager {
|
||||
addColumn(after?: number) {
|
||||
const order = this.getOrder(this.columns$.value, after);
|
||||
const columnId = nanoid();
|
||||
this.model.doc.transact(() => {
|
||||
this.model.store.transact(() => {
|
||||
this.model.props.columns[columnId] = {
|
||||
columnId,
|
||||
order,
|
||||
@@ -168,7 +168,7 @@ export class TableDataManager {
|
||||
}
|
||||
|
||||
deleteRow(rowId: string) {
|
||||
this.model.doc.transact(() => {
|
||||
this.model.store.transact(() => {
|
||||
Object.keys(this.model.props.rows).forEach(id => {
|
||||
if (id === rowId) {
|
||||
delete this.model.props.rows[id];
|
||||
@@ -183,7 +183,7 @@ export class TableDataManager {
|
||||
}
|
||||
|
||||
deleteColumn(columnId: string) {
|
||||
this.model.doc.transact(() => {
|
||||
this.model.store.transact(() => {
|
||||
Object.keys(this.model.props.columns).forEach(id => {
|
||||
if (id === columnId) {
|
||||
delete this.model.props.columns[id];
|
||||
@@ -198,7 +198,7 @@ export class TableDataManager {
|
||||
}
|
||||
|
||||
updateRowOrder(rowId: string, newOrder: string) {
|
||||
this.model.doc.transact(() => {
|
||||
this.model.store.transact(() => {
|
||||
if (this.model.props.rows[rowId]) {
|
||||
this.model.props.rows[rowId].order = newOrder;
|
||||
}
|
||||
@@ -206,7 +206,7 @@ export class TableDataManager {
|
||||
}
|
||||
|
||||
updateColumnOrder(columnId: string, newOrder: string) {
|
||||
this.model.doc.transact(() => {
|
||||
this.model.store.transact(() => {
|
||||
if (this.model.props.columns[columnId]) {
|
||||
this.model.props.columns[columnId].order = newOrder;
|
||||
}
|
||||
@@ -214,7 +214,7 @@ export class TableDataManager {
|
||||
}
|
||||
|
||||
setRowBackgroundColor(rowId: string, color?: string) {
|
||||
this.model.doc.transact(() => {
|
||||
this.model.store.transact(() => {
|
||||
if (this.model.props.rows[rowId]) {
|
||||
this.model.props.rows[rowId].backgroundColor = color;
|
||||
}
|
||||
@@ -222,7 +222,7 @@ export class TableDataManager {
|
||||
}
|
||||
|
||||
setColumnBackgroundColor(columnId: string, color?: string) {
|
||||
this.model.doc.transact(() => {
|
||||
this.model.store.transact(() => {
|
||||
if (this.model.props.columns[columnId]) {
|
||||
this.model.props.columns[columnId].backgroundColor = color;
|
||||
}
|
||||
@@ -230,7 +230,7 @@ export class TableDataManager {
|
||||
}
|
||||
|
||||
setColumnWidth(columnId: string, width: number) {
|
||||
this.model.doc.transact(() => {
|
||||
this.model.store.transact(() => {
|
||||
if (this.model.props.columns[columnId]) {
|
||||
this.model.props.columns[columnId].width = width;
|
||||
}
|
||||
@@ -238,7 +238,7 @@ export class TableDataManager {
|
||||
}
|
||||
|
||||
clearRow(rowId: string) {
|
||||
this.model.doc.transact(() => {
|
||||
this.model.store.transact(() => {
|
||||
Object.keys(this.model.props.cells).forEach(id => {
|
||||
if (id.startsWith(rowId)) {
|
||||
this.model.props.cells[id]?.text.replace(
|
||||
@@ -252,7 +252,7 @@ export class TableDataManager {
|
||||
}
|
||||
|
||||
clearColumn(columnId: string) {
|
||||
this.model.doc.transact(() => {
|
||||
this.model.store.transact(() => {
|
||||
Object.keys(this.model.props.cells).forEach(id => {
|
||||
if (id.endsWith(`:${columnId}`)) {
|
||||
this.model.props.cells[id]?.text.replace(
|
||||
@@ -290,7 +290,7 @@ export class TableDataManager {
|
||||
}
|
||||
|
||||
clearCells(cells: { rowId: string; columnId: string }[]) {
|
||||
this.model.doc.transact(() => {
|
||||
this.model.store.transact(() => {
|
||||
cells.forEach(({ rowId, columnId }) => {
|
||||
const text = this.model.props.cells[`${rowId}:${columnId}`]?.text;
|
||||
if (text) {
|
||||
@@ -313,7 +313,7 @@ export class TableDataManager {
|
||||
const column = columns[from];
|
||||
if (!column) return;
|
||||
const order = this.getOrder(columns, after);
|
||||
this.model.doc.transact(() => {
|
||||
this.model.store.transact(() => {
|
||||
const realColumn = this.model.props.columns[column.columnId];
|
||||
if (realColumn) {
|
||||
realColumn.order = order;
|
||||
@@ -326,7 +326,7 @@ export class TableDataManager {
|
||||
const row = rows[from];
|
||||
if (!row) return;
|
||||
const order = this.getOrder(rows, after);
|
||||
this.model.doc.transact(() => {
|
||||
this.model.store.transact(() => {
|
||||
const realRow = this.model.props.rows[row.rowId];
|
||||
if (realRow) {
|
||||
realRow.order = order;
|
||||
@@ -339,7 +339,7 @@ export class TableDataManager {
|
||||
if (!oldColumn) return;
|
||||
const order = this.getOrder(this.columns$.value, index);
|
||||
const newColumnId = nanoid();
|
||||
this.model.doc.transact(() => {
|
||||
this.model.store.transact(() => {
|
||||
this.model.props.columns[newColumnId] = {
|
||||
...oldColumn,
|
||||
columnId: newColumnId,
|
||||
@@ -362,7 +362,7 @@ export class TableDataManager {
|
||||
if (!oldRow) return;
|
||||
const order = this.getOrder(this.rows$.value, index);
|
||||
const newRowId = nanoid();
|
||||
this.model.doc.transact(() => {
|
||||
this.model.store.transact(() => {
|
||||
this.model.props.rows[newRowId] = {
|
||||
...oldRow,
|
||||
rowId: newRowId,
|
||||
|
||||
@@ -163,7 +163,10 @@ export class EmbedCardEditModal extends SignalWatcher(
|
||||
|
||||
const std = blockComponent.std;
|
||||
|
||||
this.model.doc.updateBlock(this.model, { title: null, description: null });
|
||||
this.model.store.updateBlock(this.model, {
|
||||
title: null,
|
||||
description: null,
|
||||
});
|
||||
|
||||
this.onReset?.(std, blockComponent);
|
||||
|
||||
|
||||
@@ -312,7 +312,7 @@ export class FramePanelBody extends SignalWatcher(
|
||||
const after = frames[insertIndex]?.props.presentationIndex || null;
|
||||
selectedFrames.forEach(frame => {
|
||||
const newIndex = generateKeyBetweenV2(before, after);
|
||||
frame.doc.updateBlock(frame, {
|
||||
frame.store.updateBlock(frame, {
|
||||
presentationIndex: newIndex,
|
||||
});
|
||||
before = newIndex;
|
||||
|
||||
@@ -112,7 +112,7 @@ export class FramePreview extends WithDisposable(ShadowlessElement) {
|
||||
};
|
||||
|
||||
get _originalDoc() {
|
||||
return this.frame.doc;
|
||||
return this.frame.store;
|
||||
}
|
||||
|
||||
private _initPreviewDoc() {
|
||||
|
||||
@@ -52,7 +52,7 @@ export class OutlineBlockPreview extends SignalWatcher(
|
||||
if (delta.attributes?.reference) {
|
||||
// If linked doc, render linked doc icon and the doc title.
|
||||
const refAttribute = delta.attributes.reference;
|
||||
const refMeta = block.doc.workspace.meta.docMetas.find(
|
||||
const refMeta = block.store.workspace.meta.docMetas.find(
|
||||
doc => doc.id === refAttribute.pageId
|
||||
);
|
||||
const unavailable = !refMeta;
|
||||
|
||||
@@ -12,9 +12,9 @@ export const connectorWatcher: SurfaceMiddleware = (
|
||||
surface: SurfaceBlockModel
|
||||
) => {
|
||||
const hasElementById = (id: string) =>
|
||||
surface.hasElementById(id) || surface.doc.hasBlock(id);
|
||||
surface.hasElementById(id) || surface.store.hasBlock(id);
|
||||
const elementGetter = (id: string) =>
|
||||
surface.getElementById(id) ?? (surface.doc.getModelById(id) as GfxModel);
|
||||
surface.getElementById(id) ?? (surface.store.getModelById(id) as GfxModel);
|
||||
const updateConnectorPath = (connector: ConnectorElementModel) => {
|
||||
if (
|
||||
((connector.source?.id && hasElementById(connector.source.id)) ||
|
||||
@@ -70,7 +70,7 @@ export const connectorWatcher: SurfaceMiddleware = (
|
||||
addToUpdateList(element as ConnectorElementModel);
|
||||
}
|
||||
}),
|
||||
surface.doc.slots.blockUpdated.subscribe(payload => {
|
||||
surface.store.slots.blockUpdated.subscribe(payload => {
|
||||
if (
|
||||
payload.type === 'add' ||
|
||||
(payload.type === 'update' && payload.props.key === 'xywh')
|
||||
|
||||
@@ -34,7 +34,7 @@ export const mindmap: ElementRenderer<MindmapElementModel> = (
|
||||
const { connector, outdated } = result;
|
||||
const elementGetter = (id: string) =>
|
||||
model.surface.getElementById(id) ??
|
||||
(model.surface.doc.getModelById(id) as GfxModel);
|
||||
(model.surface.store.getModelById(id) as GfxModel);
|
||||
|
||||
if (outdated) {
|
||||
ConnectorPathGenerator.updatePath(connector, null, elementGetter);
|
||||
|
||||
@@ -116,7 +116,7 @@ function moveNodePosition(
|
||||
)
|
||||
: (node.detail.index ?? undefined);
|
||||
|
||||
mindmap.surface.doc.transact(() => {
|
||||
mindmap.surface.store.transact(() => {
|
||||
const val: NodeDetail = {
|
||||
...node.detail,
|
||||
index,
|
||||
@@ -139,7 +139,7 @@ export function applyStyle(
|
||||
mindmap: MindmapElementModel,
|
||||
shouldFitContent: boolean = false
|
||||
) {
|
||||
mindmap.surface.doc.transact(() => {
|
||||
mindmap.surface.store.transact(() => {
|
||||
const style = mindmap.styleGetter;
|
||||
|
||||
if (!style) return;
|
||||
@@ -208,7 +208,7 @@ export function addNode(
|
||||
)
|
||||
: node.detail.index;
|
||||
|
||||
mindmap.surface.doc.transact(() => {
|
||||
mindmap.surface.store.transact(() => {
|
||||
mindmap.children.set(node.id, {
|
||||
...node.detail,
|
||||
index,
|
||||
@@ -281,7 +281,7 @@ export function addTree(
|
||||
|
||||
if (!('text' in tree)) {
|
||||
// Modify the children ymap directly hence need transaction
|
||||
mindmap.surface.doc.transact(() => {
|
||||
mindmap.surface.store.transact(() => {
|
||||
traverse(tree, parent, sibling);
|
||||
});
|
||||
|
||||
@@ -328,7 +328,7 @@ export function detachMindmap(
|
||||
subtree.children.forEach(child => traverse(child));
|
||||
};
|
||||
|
||||
mindmap.surface.doc.transact(() => {
|
||||
mindmap.surface.store.transact(() => {
|
||||
traverse(subtree);
|
||||
});
|
||||
|
||||
@@ -351,7 +351,7 @@ export function handleLayout(
|
||||
applyStyle(mindmap, true);
|
||||
}
|
||||
|
||||
mindmap.surface.doc.transact(() => {
|
||||
mindmap.surface.store.transact(() => {
|
||||
const path = mindmap.getPath(tree.id);
|
||||
layout(tree, mindmap, layoutType ?? mindmap.getLayoutDir(tree.id), path);
|
||||
});
|
||||
|
||||
@@ -68,7 +68,7 @@ export function drawGeneralShape(
|
||||
const { blur, offsetX, offsetY, color } = shapeModel.shadow;
|
||||
const scale = ctx.getTransform().a;
|
||||
|
||||
const enableShadowBlur = shapeModel.surface.doc
|
||||
const enableShadowBlur = shapeModel.surface.store
|
||||
.get(FeatureFlagService)
|
||||
.getFlag('enable_shape_shadow_blur');
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ export const replaceIdMiddleware = (job: TemplateJob) => {
|
||||
const { blockJson } = data;
|
||||
const newId = regeneratedIdMap.has(blockJson.id)
|
||||
? regeneratedIdMap.get(blockJson.id)!
|
||||
: job.model.doc.workspace.idGenerator();
|
||||
: job.model.store.workspace.idGenerator();
|
||||
|
||||
if (!regeneratedIdMap.has(blockJson.id)) {
|
||||
regeneratedIdMap.set(blockJson.id, newId);
|
||||
@@ -63,7 +63,7 @@ export const replaceIdMiddleware = (job: TemplateJob) => {
|
||||
});
|
||||
|
||||
blockJson.children.forEach(block => {
|
||||
regeneratedIdMap.set(block.id, job.model.doc.workspace.idGenerator());
|
||||
regeneratedIdMap.set(block.id, job.model.store.workspace.idGenerator());
|
||||
});
|
||||
|
||||
defered.forEach(id => {
|
||||
|
||||
@@ -97,7 +97,7 @@ export class TemplateJob {
|
||||
type: TemplateType;
|
||||
|
||||
constructor({ model, type, middlewares }: TemplateJobConfig) {
|
||||
this.job = model.doc.getTransformer();
|
||||
this.job = model.store.getTransformer();
|
||||
this.model = model;
|
||||
this.type = TEMPLATE_TYPES.includes(type as TemplateType)
|
||||
? (type as TemplateType)
|
||||
@@ -118,7 +118,7 @@ export class TemplateJob {
|
||||
private _getMergeBlockId(modelData: BlockSnapshot) {
|
||||
switch (modelData.flavour as MergeBlockFlavour) {
|
||||
case 'affine:page':
|
||||
return this.model.doc.root!.id;
|
||||
return this.model.store.root!.id;
|
||||
case 'affine:surface':
|
||||
return this.model.id;
|
||||
}
|
||||
@@ -174,7 +174,7 @@ export class TemplateJob {
|
||||
index?: number;
|
||||
}[]
|
||||
) {
|
||||
const doc = this.model.doc;
|
||||
const doc = this.model.store;
|
||||
const mergeIdMapping = new Map<string, string>();
|
||||
const deferInserting: typeof modelDataList = [];
|
||||
|
||||
@@ -199,7 +199,7 @@ export class TemplateJob {
|
||||
if (isMergeBlock) {
|
||||
this._mergeProps(
|
||||
json,
|
||||
this.model.doc.getModelById(
|
||||
this.model.store.getModelById(
|
||||
this._getMergeBlockId(json)
|
||||
) as BlockModel
|
||||
);
|
||||
@@ -320,12 +320,12 @@ export class TemplateJob {
|
||||
from: Record<string, Record<string, unknown>>,
|
||||
to: Y.Map<Y.Map<unknown>>
|
||||
) {
|
||||
const schema = this.model.doc.schema.get('affine:surface');
|
||||
const schema = this.model.store.schema.get('affine:surface');
|
||||
const surfaceTransformer = schema?.transformer?.(
|
||||
new Map()
|
||||
) as SurfaceBlockTransformer;
|
||||
|
||||
this.model.doc.transact(() => {
|
||||
this.model.store.transact(() => {
|
||||
const defered: [string, Record<string, unknown>][] = [];
|
||||
|
||||
Object.entries(from).forEach(([id, val]) => {
|
||||
|
||||
@@ -78,7 +78,7 @@ export class FrameBlockModel
|
||||
for (const key of this.childIds) {
|
||||
const element =
|
||||
this.surface.getElementById(key) ||
|
||||
(this.surface.doc.getModelById(key) as GfxBlockElementModel);
|
||||
(this.surface.store.getModelById(key) as GfxBlockElementModel);
|
||||
|
||||
element && elements.push(element);
|
||||
}
|
||||
@@ -99,7 +99,7 @@ export class FrameBlockModel
|
||||
addChild(element: GfxModel) {
|
||||
if (!canSafeAddToContainer(this, element)) return;
|
||||
|
||||
this.doc.transact(() => {
|
||||
this.store.transact(() => {
|
||||
this.props.childElementIds = {
|
||||
...this.props.childElementIds,
|
||||
[element.id]: true,
|
||||
@@ -118,7 +118,7 @@ export class FrameBlockModel
|
||||
newChildren[id] = true;
|
||||
}
|
||||
|
||||
this.doc.transact(() => {
|
||||
this.store.transact(() => {
|
||||
this.props.childElementIds = {
|
||||
...this.props.childElementIds,
|
||||
...newChildren,
|
||||
@@ -153,7 +153,7 @@ export class FrameBlockModel
|
||||
}
|
||||
|
||||
removeChild(element: GfxModel): void {
|
||||
this.doc.transact(() => {
|
||||
this.store.transact(() => {
|
||||
this.props.childElementIds &&
|
||||
delete this.props.childElementIds[element.id];
|
||||
});
|
||||
|
||||
@@ -14,15 +14,17 @@ export class RootBlockModel extends BlockModel<RootBlockProps> {
|
||||
super();
|
||||
const createdSubscription = this.created.subscribe(() => {
|
||||
createdSubscription.unsubscribe();
|
||||
this.doc.slots.rootAdded.subscribe(id => {
|
||||
const model = this.doc.getModelById(id);
|
||||
this.store.slots.rootAdded.subscribe(id => {
|
||||
const model = this.store.getModelById(id);
|
||||
if (model instanceof RootBlockModel) {
|
||||
const newDocMeta = this.doc.workspace.meta.getDocMeta(model.doc.id);
|
||||
const newDocMeta = this.store.workspace.meta.getDocMeta(
|
||||
model.store.id
|
||||
);
|
||||
if (
|
||||
!newDocMeta ||
|
||||
newDocMeta.title !== model.props.title.toString()
|
||||
) {
|
||||
this.doc.workspace.meta.setDocMeta(model.doc.id, {
|
||||
this.store.workspace.meta.setDocMeta(model.store.id, {
|
||||
title: model.props.title.toString(),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ export class GroupElementModel extends GfxGroupLikeElementModel<GroupElementProp
|
||||
return;
|
||||
}
|
||||
|
||||
this.surface.doc.transact(() => {
|
||||
this.surface.store.transact(() => {
|
||||
this.children.set(element.id, true);
|
||||
});
|
||||
}
|
||||
@@ -79,7 +79,7 @@ export class GroupElementModel extends GfxGroupLikeElementModel<GroupElementProp
|
||||
if (!this.children) {
|
||||
return;
|
||||
}
|
||||
this.surface.doc.transact(() => {
|
||||
this.surface.store.transact(() => {
|
||||
this.children.delete(element.id);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ function watchLayoutType(
|
||||
return;
|
||||
}
|
||||
|
||||
instance.surface.doc.transact(() => {
|
||||
instance.surface.store.transact(() => {
|
||||
instance['_tree']?.children.forEach(child => {
|
||||
if (!instance.children.has(child.id)) {
|
||||
return;
|
||||
@@ -285,7 +285,7 @@ export class MindmapElementModel extends GfxGroupLikeElementModel<MindmapElement
|
||||
|
||||
const type = (props.type as string) ?? 'shape';
|
||||
let id: string;
|
||||
this.surface.doc.transact(() => {
|
||||
this.surface.store.transact(() => {
|
||||
const parentNode = parent ? this._nodeMap.get(parent)! : null;
|
||||
|
||||
if (parentNode) {
|
||||
@@ -433,7 +433,7 @@ export class MindmapElementModel extends GfxGroupLikeElementModel<MindmapElement
|
||||
const loops = findInfiniteLoop(rootNode, mindmapNodeMap);
|
||||
|
||||
if (loops.length) {
|
||||
this.surface.doc.withoutTransact(() => {
|
||||
this.surface.store.withoutTransact(() => {
|
||||
loops.forEach(loop => {
|
||||
if (loop.detached) {
|
||||
loop.chain.forEach(node => {
|
||||
@@ -745,7 +745,7 @@ export class MindmapElementModel extends GfxGroupLikeElementModel<MindmapElement
|
||||
const offsetX = targetPos[0] - x;
|
||||
const offsetY = targetPos[1] - y;
|
||||
|
||||
this.surface.doc.transact(() => {
|
||||
this.surface.store.transact(() => {
|
||||
this.childElements.forEach(el => {
|
||||
const deserializedXYWH = deserializeXYWH(el.xywh);
|
||||
|
||||
@@ -775,7 +775,7 @@ export class MindmapElementModel extends GfxGroupLikeElementModel<MindmapElement
|
||||
removedDescendants.push(node.id);
|
||||
};
|
||||
|
||||
surface.doc.transact(() => {
|
||||
surface.store.transact(() => {
|
||||
remove(this._nodeMap.get(element.id)!);
|
||||
});
|
||||
|
||||
@@ -877,7 +877,7 @@ export class MindmapElementModel extends GfxGroupLikeElementModel<MindmapElement
|
||||
};
|
||||
|
||||
node.children.forEach(changeNodesVisibility);
|
||||
this.surface.doc.transact(() => {
|
||||
this.surface.store.transact(() => {
|
||||
this.children.set(node.id, {
|
||||
...node.detail,
|
||||
collapsed,
|
||||
@@ -921,7 +921,7 @@ export class MindmapElementModel extends GfxGroupLikeElementModel<MindmapElement
|
||||
|
||||
const map: Y.Map<NodeDetail> = new Y.Map();
|
||||
const surface = instance.surface;
|
||||
const doc = surface.doc;
|
||||
const doc = surface.store;
|
||||
const recursive = (
|
||||
node: NodeType,
|
||||
parent: string | null = null,
|
||||
|
||||
@@ -18,7 +18,7 @@ export function toCode(
|
||||
return;
|
||||
}
|
||||
|
||||
const doc = model.doc;
|
||||
const doc = model.store;
|
||||
const parent = doc.getParent(model);
|
||||
if (!parent) {
|
||||
return;
|
||||
|
||||
@@ -80,7 +80,7 @@ export const replaceIdMiddleware =
|
||||
model.props.reference = idMap.get(original)!;
|
||||
} else if (
|
||||
model.props.refFlavour === 'affine:frame' &&
|
||||
!model.doc.hasBlock(original)
|
||||
!model.store.hasBlock(original)
|
||||
) {
|
||||
const newId = idGenerator();
|
||||
idMap.set(original, newId);
|
||||
|
||||
@@ -45,7 +45,7 @@ export function calcDropTarget(
|
||||
*/
|
||||
allowSublist: boolean = true
|
||||
): DropTarget | null {
|
||||
const schema = model.doc.schema.get('affine:database');
|
||||
const schema = model.store.schema.get('affine:database');
|
||||
const children = schema?.model.children ?? [];
|
||||
|
||||
let shouldAppendToDatabase = true;
|
||||
|
||||
@@ -26,7 +26,7 @@ export function getPrevContentBlock(
|
||||
model: BlockModel
|
||||
): BlockModel | null {
|
||||
const getPrev = (model: BlockModel) => {
|
||||
const parent = model.doc.getParent(model);
|
||||
const parent = model.store.getParent(model);
|
||||
if (!parent) return null;
|
||||
|
||||
const index = parent.children.indexOf(model);
|
||||
@@ -113,7 +113,7 @@ export function getNextContentBlock(
|
||||
}
|
||||
map[model.id] = true;
|
||||
|
||||
const doc = model.doc;
|
||||
const doc = model.store;
|
||||
if (model.children.length) {
|
||||
return model.children[0];
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ export function mergeToCodeModel(models: BlockModel[]) {
|
||||
if (models.length === 0) {
|
||||
return null;
|
||||
}
|
||||
const doc = models[0].doc;
|
||||
const doc = models[0].store;
|
||||
|
||||
const parent = doc.getParent(models[0]);
|
||||
if (!parent) {
|
||||
|
||||
@@ -5,7 +5,7 @@ export function transformModel(
|
||||
flavour: string,
|
||||
props?: Parameters<Store['addBlock']>[1]
|
||||
) {
|
||||
const doc = model.doc;
|
||||
const doc = model.store;
|
||||
const parent = doc.getParent(model);
|
||||
if (!parent) {
|
||||
return null;
|
||||
|
||||
@@ -88,7 +88,7 @@ export class PreviewHelper {
|
||||
setup(di) {
|
||||
di.override(BlockViewIdentifier('affine:image'), () => {
|
||||
return (model: BlockModel) => {
|
||||
const parent = model.doc.getParent(model.id);
|
||||
const parent = model.store.getParent(model.id);
|
||||
|
||||
if (parent?.flavour === 'affine:surface') {
|
||||
return literal`affine-edgeless-placeholder-preview-image`;
|
||||
|
||||
@@ -75,7 +75,7 @@ export class AffineFrameTitle extends SignalWatcher(
|
||||
}
|
||||
|
||||
get doc() {
|
||||
return this.model.doc;
|
||||
return this.model.store;
|
||||
}
|
||||
|
||||
get gfx() {
|
||||
|
||||
@@ -164,7 +164,7 @@ export class GfxBlockElementModel<
|
||||
}
|
||||
|
||||
get surface(): SurfaceBlockModel | null {
|
||||
const result = this.doc.getBlocksByFlavour('affine:surface');
|
||||
const result = this.store.getBlocksByFlavour('affine:surface');
|
||||
if (result.length === 0) return null;
|
||||
return result[0].model as SurfaceBlockModel;
|
||||
}
|
||||
@@ -257,11 +257,11 @@ export class GfxBlockElementModel<
|
||||
}
|
||||
|
||||
lock() {
|
||||
lockElementImpl(this.doc, this);
|
||||
lockElementImpl(this.store, this);
|
||||
}
|
||||
|
||||
unlock() {
|
||||
unlockElementImpl(this.doc, this);
|
||||
unlockElementImpl(this.store, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ export function field<V, T extends GfxPrimitiveElementModel>(fallback?: V) {
|
||||
|
||||
if (this.yMap) {
|
||||
if (this.yMap.doc) {
|
||||
this.surface.doc.transact(() => {
|
||||
this.surface.store.transact(() => {
|
||||
this.yMap.set(prop as string, v);
|
||||
});
|
||||
} else {
|
||||
@@ -69,7 +69,7 @@ export function field<V, T extends GfxPrimitiveElementModel>(fallback?: V) {
|
||||
: convertProps(prop, originalVal, this);
|
||||
|
||||
if (this.yMap.doc) {
|
||||
this.surface.doc.transact(() => {
|
||||
this.surface.store.transact(() => {
|
||||
this.yMap.set(prop as string, val);
|
||||
});
|
||||
} else {
|
||||
|
||||
@@ -256,7 +256,7 @@ export abstract class GfxPrimitiveElementModel<
|
||||
}
|
||||
|
||||
lock() {
|
||||
lockElementImpl(this.surface.doc, this);
|
||||
lockElementImpl(this.surface.store, this);
|
||||
}
|
||||
|
||||
onCreated() {}
|
||||
@@ -278,7 +278,7 @@ export abstract class GfxPrimitiveElementModel<
|
||||
|
||||
if (getFieldPropsSet(this).has(prop as string)) {
|
||||
if (!isEqual(value, this.yMap.get(prop as string))) {
|
||||
this.surface.doc.transact(() => {
|
||||
this.surface.store.transact(() => {
|
||||
this.yMap.set(prop as string, value);
|
||||
});
|
||||
}
|
||||
@@ -339,7 +339,7 @@ export abstract class GfxPrimitiveElementModel<
|
||||
}
|
||||
|
||||
unlock() {
|
||||
unlockElementImpl(this.surface.doc, this);
|
||||
unlockElementImpl(this.surface.store, this);
|
||||
}
|
||||
|
||||
@local()
|
||||
@@ -396,7 +396,7 @@ export abstract class GfxGroupLikeElementModel<
|
||||
for (const key of this.childIds) {
|
||||
const element =
|
||||
this.surface.getElementById(key) ||
|
||||
(this.surface.doc.getModelById(key) as GfxBlockElementModel);
|
||||
(this.surface.store.getModelById(key) as GfxBlockElementModel);
|
||||
|
||||
element && elements.push(element);
|
||||
}
|
||||
|
||||
@@ -368,7 +368,7 @@ export class SurfaceBlockModel extends BlockModel<SurfaceBlockProps> {
|
||||
mount();
|
||||
});
|
||||
|
||||
Object.values(this.doc.blocks.peek()).forEach(block => {
|
||||
Object.values(this.store.blocks.peek()).forEach(block => {
|
||||
if (isGfxGroupCompatibleModel(block.model)) {
|
||||
this._groupLikeModels.set(block.id, block.model);
|
||||
}
|
||||
@@ -376,7 +376,7 @@ export class SurfaceBlockModel extends BlockModel<SurfaceBlockProps> {
|
||||
|
||||
elementsYMap.observe(onElementsMapChange);
|
||||
|
||||
const subscription = this.doc.slots.blockUpdated.subscribe(payload => {
|
||||
const subscription = this.store.slots.blockUpdated.subscribe(payload => {
|
||||
switch (payload.type) {
|
||||
case 'add':
|
||||
if (isGfxGroupCompatibleModel(payload.model)) {
|
||||
@@ -468,7 +468,7 @@ export class SurfaceBlockModel extends BlockModel<SurfaceBlockProps> {
|
||||
const disposables = new DisposableGroup();
|
||||
disposables.add(this.elementAdded.subscribe(updateIsEmpty));
|
||||
disposables.add(this.elementRemoved.subscribe(updateIsEmpty));
|
||||
this.doc.slots.blockUpdated.subscribe(payload => {
|
||||
this.store.slots.blockUpdated.subscribe(payload => {
|
||||
if (['add', 'delete'].includes(payload.type)) {
|
||||
updateIsEmpty();
|
||||
}
|
||||
@@ -503,7 +503,7 @@ export class SurfaceBlockModel extends BlockModel<SurfaceBlockProps> {
|
||||
addElement<T extends object = Record<string, unknown>>(
|
||||
props: Partial<T> & { type: string }
|
||||
) {
|
||||
if (this.doc.readonly) {
|
||||
if (this.store.readonly) {
|
||||
throw new Error('Cannot add element in readonly mode');
|
||||
}
|
||||
|
||||
@@ -535,7 +535,7 @@ export class SurfaceBlockModel extends BlockModel<SurfaceBlockProps> {
|
||||
|
||||
this._elementModels.set(id, elementModel);
|
||||
|
||||
this.doc.transact(() => {
|
||||
this.store.transact(() => {
|
||||
this.elements.getValue()!.set(id, elementModel.model.yMap);
|
||||
});
|
||||
|
||||
@@ -552,7 +552,7 @@ export class SurfaceBlockModel extends BlockModel<SurfaceBlockProps> {
|
||||
}
|
||||
|
||||
deleteElement(id: string) {
|
||||
if (this.doc.readonly) {
|
||||
if (this.store.readonly) {
|
||||
throw new Error('Cannot remove element in readonly mode');
|
||||
}
|
||||
|
||||
@@ -560,7 +560,7 @@ export class SurfaceBlockModel extends BlockModel<SurfaceBlockProps> {
|
||||
return;
|
||||
}
|
||||
|
||||
this.doc.transact(() => {
|
||||
this.store.transact(() => {
|
||||
const element = this.getElementById(id)!;
|
||||
const group = this.getGroup(id);
|
||||
|
||||
@@ -568,8 +568,8 @@ export class SurfaceBlockModel extends BlockModel<SurfaceBlockProps> {
|
||||
element.childIds.forEach(childId => {
|
||||
if (this.hasElementById(childId)) {
|
||||
this.deleteElement(childId);
|
||||
} else if (this.doc.hasBlock(childId)) {
|
||||
this.doc.deleteBlock(this.doc.getBlock(childId)!.model);
|
||||
} else if (this.store.hasBlock(childId)) {
|
||||
this.store.deleteBlock(this.store.getBlock(childId)!.model);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -610,7 +610,7 @@ export class SurfaceBlockModel extends BlockModel<SurfaceBlockProps> {
|
||||
elem =
|
||||
typeof elem === 'string'
|
||||
? ((this.getElementById(elem) ??
|
||||
this.doc.getBlock(elem)?.model) as GfxModel)
|
||||
this.store.getBlock(elem)?.model) as GfxModel)
|
||||
: elem;
|
||||
|
||||
if (!elem) return null;
|
||||
@@ -655,7 +655,7 @@ export class SurfaceBlockModel extends BlockModel<SurfaceBlockProps> {
|
||||
const el = this.getElementById(element);
|
||||
if (el) return isGfxGroupCompatibleModel(el);
|
||||
|
||||
const blockModel = this.doc.getBlock(element)?.model;
|
||||
const blockModel = this.store.getBlock(element)?.model;
|
||||
if (blockModel) return isGfxGroupCompatibleModel(blockModel);
|
||||
|
||||
return false;
|
||||
@@ -668,7 +668,7 @@ export class SurfaceBlockModel extends BlockModel<SurfaceBlockProps> {
|
||||
id: string,
|
||||
props: Partial<T>
|
||||
) {
|
||||
if (this.doc.readonly) {
|
||||
if (this.store.readonly) {
|
||||
throw new Error('Cannot update element in readonly mode');
|
||||
}
|
||||
|
||||
@@ -678,7 +678,7 @@ export class SurfaceBlockModel extends BlockModel<SurfaceBlockProps> {
|
||||
throw new Error(`Element ${id} is not found`);
|
||||
}
|
||||
|
||||
this.doc.transact(() => {
|
||||
this.store.transact(() => {
|
||||
props = this._propsToY(
|
||||
elementModel.type,
|
||||
props as Record<string, unknown>
|
||||
|
||||
@@ -97,16 +97,16 @@ export class BlockModel<Props extends object = object> {
|
||||
return this._childModels.value;
|
||||
}
|
||||
|
||||
get doc() {
|
||||
get store() {
|
||||
return this._store;
|
||||
}
|
||||
|
||||
set doc(doc: Store) {
|
||||
set store(doc: Store) {
|
||||
this._store = doc;
|
||||
}
|
||||
|
||||
get parent() {
|
||||
return this.doc.getParent(this);
|
||||
return this.store.getParent(this);
|
||||
}
|
||||
|
||||
get role() {
|
||||
|
||||
@@ -63,7 +63,7 @@ export class FlatSyncController {
|
||||
model.stash = this.stash;
|
||||
model.pop = this.pop;
|
||||
if (this.doc) {
|
||||
model.doc = this.doc;
|
||||
model.store = this.doc;
|
||||
}
|
||||
|
||||
const defaultProps = schema.model.props?.(internalPrimitives);
|
||||
|
||||
@@ -168,7 +168,7 @@ export class SyncController {
|
||||
model.stash = this.stash;
|
||||
model.pop = this.pop;
|
||||
if (this.doc) {
|
||||
model.doc = this.doc;
|
||||
model.store = this.doc;
|
||||
}
|
||||
|
||||
const proxy = new Proxy(signalWithProps, {
|
||||
|
||||
@@ -70,7 +70,7 @@ function getBlockViewType(query: Query, block: Block): BlockViewType {
|
||||
}
|
||||
|
||||
function setAncestorsToDisplayIfHidden(mode: QueryMode, block: Block) {
|
||||
const doc = block.model.doc;
|
||||
const doc = block.model.store;
|
||||
let parent = doc.getParent(block.model);
|
||||
while (parent) {
|
||||
const parentBlock = doc.getBlock(parent.id);
|
||||
|
||||
@@ -82,7 +82,7 @@ describe('group', () => {
|
||||
});
|
||||
const group = model.getElementById(groupId) as GroupElementModel;
|
||||
|
||||
model.doc.transact(() => {
|
||||
model.store.transact(() => {
|
||||
group.children.delete(id);
|
||||
group.children.delete(id2);
|
||||
});
|
||||
|
||||
@@ -141,7 +141,7 @@ export function cleanup() {
|
||||
|
||||
delete (window as any).editor;
|
||||
|
||||
delete (window as any).doc;
|
||||
delete (window as any).store;
|
||||
}
|
||||
|
||||
declare global {
|
||||
|
||||
@@ -182,7 +182,7 @@ export class AttachmentViewerPanel extends SignalWatcher(
|
||||
console.debug('connected');
|
||||
this.#state.value = State.Connected;
|
||||
|
||||
const blob = await model.doc.blobSync.get(model.props.sourceId!);
|
||||
const blob = await model.store.blobSync.get(model.props.sourceId!);
|
||||
|
||||
if (!blob) return;
|
||||
const buffer = await blob.arrayBuffer();
|
||||
|
||||
@@ -387,7 +387,7 @@ export function responseToExpandMindmap(host: EditorHost, ctx: AIContext) {
|
||||
|
||||
if (!subtree) return;
|
||||
|
||||
surface.doc.transact(() => {
|
||||
surface.store.transact(() => {
|
||||
const updateNodeSize = (node: typeof subtree) => {
|
||||
fitContent(node.element as ShapeElementModel);
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import { literal } from 'lit/static-html.js';
|
||||
|
||||
export const AIChatBlockSpec: ExtensionType[] = [
|
||||
BlockViewExtension('affine:embed-ai-chat', model => {
|
||||
const parent = model.doc.getParent(model.id);
|
||||
const parent = model.store.getParent(model.id);
|
||||
|
||||
if (parent?.flavour === 'affine:surface') {
|
||||
return literal`affine-edgeless-ai-chat`;
|
||||
|
||||
@@ -42,7 +42,7 @@ export class MindmapSurfaceBlock extends BlockComponent<SurfaceBlockModel> {
|
||||
}
|
||||
|
||||
private _adjustNodeWidth() {
|
||||
this.model.doc.transact(() => {
|
||||
this.model.store.transact(() => {
|
||||
this.model.elementModels.forEach(element => {
|
||||
if (element.type === 'shape') {
|
||||
fitContent(element as ShapeElementModel);
|
||||
|
||||
@@ -74,7 +74,7 @@ export function PDFViewerEmbedded({ model }: AttachmentViewerProps) {
|
||||
const canvasRef = useRef<HTMLCanvasElement>(null);
|
||||
|
||||
const peek = useCallback(() => {
|
||||
const target = model.doc.getBlock(model.id);
|
||||
const target = model.store.getBlock(model.id);
|
||||
if (!target) return;
|
||||
peekView.open({ element: target }).catch(console.error);
|
||||
}, [peekView, model]);
|
||||
|
||||
@@ -10,7 +10,7 @@ export async function getAttachmentBlob(model: AttachmentBlockModel) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const doc = model.doc;
|
||||
const doc = model.store;
|
||||
let blob = await doc.blobSync.get(sourceId);
|
||||
|
||||
if (blob) {
|
||||
|
||||
@@ -16,7 +16,7 @@ export function patchForPDFEmbedView(reactToLit: ReactToLit): ExtensionType {
|
||||
const bound = Bound.deserialize(model.props.xywh);
|
||||
bound.w = 537 + 24 + 2;
|
||||
bound.h = 759 + 46 + 24 + 2;
|
||||
model.doc.updateBlock(model, {
|
||||
model.store.updateBlock(model, {
|
||||
embed: true,
|
||||
style: 'pdf',
|
||||
xywh: bound.serialize(),
|
||||
|
||||
+1
-1
@@ -54,7 +54,7 @@ const ToggleButton = ({ model }: { model: EmbedSyncedDocModel }) => {
|
||||
}, [model.props.preFoldHeight$, model.xywh$]);
|
||||
|
||||
const toggle = useCallback(() => {
|
||||
model.doc.captureSync();
|
||||
model.store.captureSync();
|
||||
|
||||
batch(() => {
|
||||
const { x, y, w, h } = model.elementBound;
|
||||
|
||||
+4
-4
@@ -55,7 +55,7 @@ const EdgelessNoteToggleButton = ({ note }: { note: NoteBlockModel }) => {
|
||||
|
||||
const dispose = selection.slots.updated.subscribe(() => {
|
||||
if (selection.has(note.id) && selection.editing) {
|
||||
note.doc.transact(() => {
|
||||
note.store.transact(() => {
|
||||
note.props.edgeless.collapse = false;
|
||||
});
|
||||
}
|
||||
@@ -68,7 +68,7 @@ const EdgelessNoteToggleButton = ({ note }: { note: NoteBlockModel }) => {
|
||||
track.edgeless.pageBlock.headerToolbar.toggle({
|
||||
type: collapsed ? 'expand' : 'collapse',
|
||||
});
|
||||
note.doc.transact(() => {
|
||||
note.store.transact(() => {
|
||||
if (collapsed) {
|
||||
note.props.edgeless.collapse = false;
|
||||
} else {
|
||||
@@ -134,7 +134,7 @@ const PageBlockInfoButton = ({ note }: { note: NoteBlockModel }) => {
|
||||
|
||||
return (
|
||||
<DocInfoButton
|
||||
docId={note.doc.id}
|
||||
docId={note.store.id}
|
||||
trackFn={trackFn}
|
||||
data-testid="edgeless-note-info-button"
|
||||
/>
|
||||
@@ -148,7 +148,7 @@ const NoteCopyLinkButton = ({ note }: { note: NoteBlockModel }) => {
|
||||
|
||||
return (
|
||||
<CopyLinkButton
|
||||
pageId={note.doc.id}
|
||||
pageId={note.store.id}
|
||||
blockId={note.id}
|
||||
mode="edgeless"
|
||||
trackFn={trackFn}
|
||||
|
||||
@@ -26,11 +26,13 @@ export function patchForEdgelessNoteConfig(
|
||||
reactToLit(<EdgelessNoteHeader note={note} />),
|
||||
pageBlockTitle: ({ note }) => {
|
||||
const journalService = framework.get(JournalService);
|
||||
const isJournal = !!journalService.journalDate$(note.doc.id).value;
|
||||
const isJournal = !!journalService.journalDate$(note.store.id).value;
|
||||
if (isJournal) {
|
||||
return reactToLit(<BlocksuiteEditorJournalDocTitle page={note.doc} />);
|
||||
return reactToLit(
|
||||
<BlocksuiteEditorJournalDocTitle page={note.store} />
|
||||
);
|
||||
} else {
|
||||
return html`<doc-title .doc=${note.doc}></doc-title>`;
|
||||
return html`<doc-title .doc=${note.store}></doc-title>`;
|
||||
}
|
||||
},
|
||||
pageBlockViewportFitAnimation: insidePeekView
|
||||
|
||||
@@ -42,7 +42,7 @@ function createCopyLinkToBlockMenuItem(
|
||||
},
|
||||
select: () => {
|
||||
const serverService = framework.get(ServerService);
|
||||
const pageId = model.doc.id;
|
||||
const pageId = model.store.id;
|
||||
const { editor } = framework.get(EditorService);
|
||||
const mode = editor.mode$.value;
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ export class AudioAttachmentBlock extends Entity<AttachmentBlockModel> {
|
||||
computed(() => {
|
||||
// find the last transcription block
|
||||
for (const key of [...this.props.childMap.value.keys()].reverse()) {
|
||||
const block = this.props.doc.getBlock$(key);
|
||||
const block = this.props.store.getBlock$(key);
|
||||
if (block?.flavour === TranscriptionBlockFlavour) {
|
||||
return block.model as unknown as TranscriptionBlockModel;
|
||||
}
|
||||
@@ -113,7 +113,7 @@ export class AudioAttachmentBlock extends Entity<AttachmentBlockModel> {
|
||||
|
||||
if (!transcriptionBlockProps) {
|
||||
// transcription block is not created yet, we need to create it
|
||||
this.props.doc.addBlock(
|
||||
this.props.store.addBlock(
|
||||
'affine:transcription',
|
||||
{
|
||||
transcription: {},
|
||||
@@ -179,14 +179,14 @@ export class AudioAttachmentBlock extends Entity<AttachmentBlockModel> {
|
||||
title: string,
|
||||
collapsed: boolean = false
|
||||
) => {
|
||||
const calloutId = this.props.doc.addBlock(
|
||||
const calloutId = this.props.store.addBlock(
|
||||
'affine:callout',
|
||||
{
|
||||
emoji,
|
||||
},
|
||||
this.transcriptionBlock$.value?.id
|
||||
);
|
||||
this.props.doc.addBlock(
|
||||
this.props.store.addBlock(
|
||||
'affine:paragraph',
|
||||
{
|
||||
type: 'h6',
|
||||
@@ -223,7 +223,7 @@ export class AudioAttachmentBlock extends Entity<AttachmentBlockModel> {
|
||||
insert: ': ' + sanitizeText(segment.transcription),
|
||||
},
|
||||
];
|
||||
this.props.doc.addBlock(
|
||||
this.props.store.addBlock(
|
||||
'affine:paragraph',
|
||||
{
|
||||
text: new Text(deltaInserts),
|
||||
@@ -238,7 +238,7 @@ export class AudioAttachmentBlock extends Entity<AttachmentBlockModel> {
|
||||
await insertFromMarkdown(
|
||||
undefined,
|
||||
summary,
|
||||
this.props.doc,
|
||||
this.props.store,
|
||||
calloutId,
|
||||
1
|
||||
);
|
||||
@@ -252,7 +252,7 @@ export class AudioAttachmentBlock extends Entity<AttachmentBlockModel> {
|
||||
await insertFromMarkdown(
|
||||
undefined,
|
||||
actions ?? '',
|
||||
this.props.doc,
|
||||
this.props.store,
|
||||
calloutId,
|
||||
1
|
||||
);
|
||||
|
||||
@@ -28,8 +28,8 @@ export class AudioAttachmentService extends Service {
|
||||
const key = attachmentBlockAudioMediaKey({
|
||||
blobId: model.props.sourceId,
|
||||
blockId: model.id,
|
||||
docId: model.doc.id,
|
||||
workspaceId: model.doc.rootDoc.guid,
|
||||
docId: model.store.id,
|
||||
workspaceId: model.store.rootDoc.guid,
|
||||
});
|
||||
let exists = this.pool.get(key);
|
||||
if (!exists) {
|
||||
|
||||
@@ -308,8 +308,8 @@ export class AudioMediaManagerService extends Service {
|
||||
key: attachmentBlockAudioMediaKey({
|
||||
blobId: input.props.sourceId,
|
||||
blockId: input.id,
|
||||
docId: input.doc.id,
|
||||
workspaceId: input.doc.rootDoc.guid,
|
||||
docId: input.store.id,
|
||||
workspaceId: input.store.rootDoc.guid,
|
||||
}),
|
||||
name: input.props.name,
|
||||
size: input.props.size,
|
||||
|
||||
@@ -60,7 +60,7 @@ export async function downloadBlobToBuffer(model: AttachmentBlockModel) {
|
||||
throw new Error('Attachment not found');
|
||||
}
|
||||
|
||||
const blob = await model.doc.blobSync.get(sourceId);
|
||||
const blob = await model.store.blobSync.get(sourceId);
|
||||
if (!blob) {
|
||||
throw new Error('Attachment not found');
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ function resolvePeekInfoFromPeekTarget(
|
||||
// refModel can be null if the reference is invalid
|
||||
if (refModel) {
|
||||
const docId =
|
||||
'doc' in refModel ? refModel.doc.id : refModel.surface.doc.id;
|
||||
'store' in refModel ? refModel.store.id : refModel.surface.store.id;
|
||||
return {
|
||||
type: 'doc',
|
||||
docRef: {
|
||||
@@ -179,7 +179,7 @@ function resolvePeekInfoFromPeekTarget(
|
||||
return {
|
||||
type: 'attachment',
|
||||
docRef: {
|
||||
docId: blockModel.doc.id,
|
||||
docId: blockModel.store.id,
|
||||
blockIds: [blockModel.id],
|
||||
filetype: blockModel.props.type,
|
||||
},
|
||||
@@ -188,7 +188,7 @@ function resolvePeekInfoFromPeekTarget(
|
||||
return {
|
||||
type: 'image',
|
||||
docRef: {
|
||||
docId: blockModel.doc.id,
|
||||
docId: blockModel.store.id,
|
||||
blockIds: [blockModel.id],
|
||||
},
|
||||
};
|
||||
@@ -196,7 +196,7 @@ function resolvePeekInfoFromPeekTarget(
|
||||
return {
|
||||
type: 'ai-chat-block',
|
||||
docRef: {
|
||||
docId: blockModel.doc.id,
|
||||
docId: blockModel.store.id,
|
||||
blockIds: [blockModel.id],
|
||||
},
|
||||
model: blockModel,
|
||||
|
||||
@@ -362,7 +362,7 @@ const ImagePreviewModalImpl = ({
|
||||
index,
|
||||
url: blobUrl,
|
||||
caption: blockModel.props.caption,
|
||||
onDelete: !blockModel.doc.readonly
|
||||
onDelete: !blockModel.store.readonly
|
||||
? () => {
|
||||
handleDelete();
|
||||
}
|
||||
|
||||
@@ -440,7 +440,7 @@ export async function assertParentBlockId(
|
||||
if (!model) {
|
||||
throw new Error(`Block with id ${blockId} not found`);
|
||||
}
|
||||
return model.doc.getParent(model)?.id;
|
||||
return model.store.getParent(model)?.id;
|
||||
},
|
||||
{ blockId }
|
||||
);
|
||||
@@ -458,7 +458,7 @@ export async function assertParentBlockFlavour(
|
||||
if (!model) {
|
||||
throw new Error(`Block with id ${blockId} not found`);
|
||||
}
|
||||
return model.doc.getParent(model)?.flavour;
|
||||
return model.store.getParent(model)?.flavour;
|
||||
},
|
||||
{ blockId }
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user