chore(editor): rename std.doc to std.store (#9596)

This commit is contained in:
Saul-Mirone
2025-01-09 04:16:28 +00:00
parent 58ce86533e
commit d21ef47ae8
89 changed files with 359 additions and 348 deletions
@@ -303,7 +303,7 @@ export async function addAttachments(
EMBED_CARD_WIDTH.cubeThick, EMBED_CARD_WIDTH.cubeThick,
EMBED_CARD_HEIGHT.cubeThick EMBED_CARD_HEIGHT.cubeThick
); );
const blockId = std.doc.addBlock( const blockId = std.store.addBlock(
'affine:attachment', 'affine:attachment',
{ {
name: file.name, name: file.name,
@@ -36,7 +36,7 @@ export class CodeClipboardController {
const e = ctx.get('clipboardState').raw; const e = ctx.get('clipboardState').raw;
e.preventDefault(); e.preventDefault();
this._std.doc.captureSync(); this._std.store.captureSync();
this._std.command this._std.command
.chain() .chain()
.try(cmd => [ .try(cmd => [
@@ -63,7 +63,7 @@ export class CodeClipboardController {
this._clipboard this._clipboard
.paste( .paste(
e, e,
this._std.doc, this._std.store,
ctx.parentBlock.model.id, ctx.parentBlock.model.id,
ctx.blockIndex ? ctx.blockIndex + 1 : 1 ctx.blockIndex ? ctx.blockIndex + 1 : 1
) )
@@ -20,17 +20,17 @@ export const insertDatabaseBlockCommand: Command<
const service = std.getService('affine:database'); const service = std.getService('affine:database');
if (!service) return; if (!service) return;
const result = std.doc.addSiblingBlocks( const result = std.store.addSiblingBlocks(
targetModel, targetModel,
[{ flavour: 'affine:database' }], [{ flavour: 'affine:database' }],
place place
); );
if (result.length === 0) return; if (result.length === 0) return;
service.initDatabaseBlock(std.doc, targetModel, result[0], viewType, false); service.initDatabaseBlock(std.store, targetModel, result[0], viewType, false);
if (removeEmptyLine && targetModel.text?.length === 0) { if (removeEmptyLine && targetModel.text?.length === 0) {
std.doc.deleteBlock(targetModel); std.store.deleteBlock(targetModel);
} }
next({ insertedDatabaseBlockId: result[0] }); next({ insertedDatabaseBlockId: result[0] });
@@ -50,7 +50,7 @@ export function insertEmbedCard(
const index = parent.children.indexOf(block.model); const index = parent.children.indexOf(block.model);
host.doc.addBlock(flavour as never, props, parent, index + 1); host.doc.addBlock(flavour as never, props, parent, index + 1);
} else { } else {
const rootId = std.doc.root?.id; const rootId = std.store.root?.id;
if (!rootId) return; if (!rootId) return;
const edgelessRoot = std.view.getBlock(rootId); const edgelessRoot = std.view.getBlock(rootId);
if (!edgelessRoot) return; if (!edgelessRoot) return;
@@ -35,7 +35,7 @@ export const insertImagesCommand: Command<
place place
); );
if (removeEmptyLine && targetModel.text?.length === 0) { if (removeEmptyLine && targetModel.text?.length === 0) {
std.doc.deleteBlock(targetModel); std.store.deleteBlock(targetModel);
} }
return result ?? []; return result ?? [];
+3 -3
View File
@@ -468,7 +468,7 @@ export async function addImages(
); );
const center = Vec.toVec(point); const center = Vec.toVec(point);
const bound = calcBoundByOrigin(center, inTopLeft); const bound = calcBoundByOrigin(center, inTopLeft);
const blockId = std.doc.addBlock( const blockId = std.store.addBlock(
'affine:image', 'affine:image',
{ {
size: file.size, size: file.size,
@@ -484,7 +484,7 @@ export async function addImages(
const uploadPromises = imageFiles.map(async (file, index) => { const uploadPromises = imageFiles.map(async (file, index) => {
const { point, blockId } = dropInfos[index]; const { point, blockId } = dropInfos[index];
const sourceId = await std.doc.blobSync.set(file); const sourceId = await std.store.blobSync.set(file);
const imageSize = await readImageSize(file); const imageSize = await readImageSize(file);
const center = Vec.toVec(point); const center = Vec.toVec(point);
@@ -498,7 +498,7 @@ export async function addImages(
: imageSize.height; : imageSize.height;
const bound = calcBoundByOrigin(center, inTopLeft, width, height); const bound = calcBoundByOrigin(center, inTopLeft, width, height);
std.doc.withoutTransact(() => { std.store.withoutTransact(() => {
gfx.updateElement(blockId, { gfx.updateElement(blockId, {
sourceId, sourceId,
...imageSize, ...imageSize,
@@ -28,7 +28,7 @@ export const insertLatexBlockCommand: Command<
latex: latex ?? '', latex: latex ?? '',
}; };
const result = std.doc.addSiblingBlocks( const result = std.store.addSiblingBlocks(
targetModel, targetModel,
[latexBlockProps], [latexBlockProps],
place place
@@ -36,7 +36,7 @@ export const insertLatexBlockCommand: Command<
if (result.length === 0) return; if (result.length === 0) return;
if (removeEmptyLine && targetModel.text?.length === 0) { if (removeEmptyLine && targetModel.text?.length === 0) {
std.doc.deleteBlock(targetModel); std.store.deleteBlock(targetModel);
} }
next({ next({
@@ -11,7 +11,7 @@ export const canDedentListCommand: Command<
> = (ctx, next) => { > = (ctx, next) => {
let { blockId, inlineIndex } = ctx; let { blockId, inlineIndex } = ctx;
const { std } = ctx; const { std } = ctx;
const { selection, doc } = std; const { selection, store } = std;
if (!blockId) { if (!blockId) {
const text = selection.find(TextSelection); const text = selection.find(TextSelection);
/** /**
@@ -51,25 +51,25 @@ export const canDedentListCommand: Command<
/** /**
* ccc * ccc
*/ */
const model = doc.getBlock(blockId)?.model; const model = store.getBlock(blockId)?.model;
if (!model || !matchFlavours(model, ['affine:list'])) { if (!model || !matchFlavours(model, ['affine:list'])) {
return; return;
} }
/** /**
* bbb * bbb
*/ */
const parent = doc.getParent(model); const parent = store.getParent(model);
if (!parent) { if (!parent) {
return; return;
} }
if (doc.readonly || parent.role !== 'content') { if (store.readonly || parent.role !== 'content') {
// Top most list cannot be unindent // Top most list cannot be unindent
return; return;
} }
/** /**
* aaa * aaa
*/ */
const grandParent = doc.getParent(parent); const grandParent = store.getParent(parent);
if (!grandParent) { if (!grandParent) {
return; return;
} }
@@ -93,7 +93,7 @@ export const canDedentListCommand: Command<
export const dedentListCommand: Command<'indentContext'> = (ctx, next) => { export const dedentListCommand: Command<'indentContext'> = (ctx, next) => {
const { indentContext: dedentContext, std } = ctx; const { indentContext: dedentContext, std } = ctx;
const { doc, selection, range, host } = std; const { store, selection, range, host } = std;
if ( if (
!dedentContext || !dedentContext ||
@@ -108,16 +108,16 @@ export const dedentListCommand: Command<'indentContext'> = (ctx, next) => {
const { blockId } = dedentContext; const { blockId } = dedentContext;
const model = doc.getBlock(blockId)?.model; const model = store.getBlock(blockId)?.model;
if (!model) return; if (!model) return;
const parent = doc.getParent(model); const parent = store.getParent(model);
if (!parent) return; if (!parent) return;
const grandParent = doc.getParent(parent); const grandParent = store.getParent(parent);
if (!grandParent) return; if (!grandParent) return;
doc.captureSync(); store.captureSync();
/** /**
* step 1: * step 1:
@@ -128,13 +128,13 @@ export const dedentListCommand: Command<'indentContext'> = (ctx, next) => {
* - eee <- make eee as ccc's child * - eee <- make eee as ccc's child
* - fff * - fff
*/ */
const nextSiblings = doc.getNexts(model); // [eee] const nextSiblings = store.getNexts(model); // [eee]
doc.moveBlocks(nextSiblings, model); store.moveBlocks(nextSiblings, model);
/** /**
* eee * eee
*/ */
const nextSibling = nextSiblings.at(0); const nextSibling = nextSiblings.at(0);
if (nextSibling) correctNumberedListsOrderToPrev(doc, nextSibling); if (nextSibling) correctNumberedListsOrderToPrev(store, nextSibling);
/** /**
* step 2: * step 2:
@@ -145,8 +145,8 @@ export const dedentListCommand: Command<'indentContext'> = (ctx, next) => {
* - eee * - eee
* - fff * - fff
*/ */
doc.moveBlocks([model], grandParent, parent, false); store.moveBlocks([model], grandParent, parent, false);
correctNumberedListsOrderToPrev(doc, model); correctNumberedListsOrderToPrev(store, model);
const textSelection = selection.find(TextSelection); const textSelection = selection.find(TextSelection);
if (textSelection) { if (textSelection) {
@@ -14,7 +14,7 @@ export const canIndentListCommand: Command<
> = (ctx, next) => { > = (ctx, next) => {
let { blockId, inlineIndex } = ctx; let { blockId, inlineIndex } = ctx;
const { std } = ctx; const { std } = ctx;
const { selection, doc } = std; const { selection, store } = std;
if (!blockId) { if (!blockId) {
const text = selection.find(TextSelection); const text = selection.find(TextSelection);
/** /**
@@ -52,17 +52,17 @@ export const canIndentListCommand: Command<
/** /**
* ccc * ccc
*/ */
const model = doc.getBlock(blockId)?.model; const model = store.getBlock(blockId)?.model;
if (!model || !matchFlavours(model, ['affine:list'])) { if (!model || !matchFlavours(model, ['affine:list'])) {
return; return;
} }
const schema = std.doc.schema; const schema = std.store.schema;
/** /**
* aaa * aaa
*/ */
const previousSibling = doc.getPrev(model); const previousSibling = store.getPrev(model);
if ( if (
doc.readonly || store.readonly ||
!previousSibling || !previousSibling ||
!schema.isValid(model.flavour, previousSibling.flavour) !schema.isValid(model.flavour, previousSibling.flavour)
) { ) {
@@ -72,7 +72,7 @@ export const canIndentListCommand: Command<
/** /**
* eee * eee
*/ */
// const nextSibling = doc.getNext(model); // const nextSibling = store.getNext(model);
return next({ return next({
indentContext: { indentContext: {
@@ -101,21 +101,21 @@ export const indentListCommand: Command<'indentContext', never> = (
} }
const { blockId } = indentContext; const { blockId } = indentContext;
const { doc, selection, host, range } = std; const { store, selection, host, range } = std;
const model = doc.getBlock(blockId)?.model; const model = store.getBlock(blockId)?.model;
if (!model) return; if (!model) return;
const previousSibling = doc.getPrev(model); const previousSibling = store.getPrev(model);
if (!previousSibling) return; if (!previousSibling) return;
const nextSibling = doc.getNext(model); const nextSibling = store.getNext(model);
doc.captureSync(); store.captureSync();
doc.moveBlocks([model], previousSibling); store.moveBlocks([model], previousSibling);
correctNumberedListsOrderToPrev(doc, model); correctNumberedListsOrderToPrev(store, model);
if (nextSibling) correctNumberedListsOrderToPrev(doc, nextSibling); if (nextSibling) correctNumberedListsOrderToPrev(store, nextSibling);
// 123 // 123
// > # 456 // > # 456
@@ -128,7 +128,7 @@ export const indentListCommand: Command<'indentContext', never> = (
matchFlavours(nearestHeading, ['affine:paragraph']) && matchFlavours(nearestHeading, ['affine:paragraph']) &&
nearestHeading.collapsed nearestHeading.collapsed
) { ) {
doc.updateBlock(nearestHeading, { store.updateBlock(nearestHeading, {
collapsed: false, collapsed: false,
}); });
} }
@@ -12,7 +12,7 @@ export const listToParagraphCommand: Command<
> = (ctx, next) => { > = (ctx, next) => {
const { id, stopCapturing = true } = ctx; const { id, stopCapturing = true } = ctx;
const std = ctx.std; const std = ctx.std;
const doc = std.doc; const doc = std.store;
const model = doc.getBlock(id)?.model; const model = doc.getBlock(id)?.model;
if (!model || !matchFlavours(model, ['affine:list'])) return false; if (!model || !matchFlavours(model, ['affine:list'])) return false;
@@ -26,7 +26,7 @@ export const listToParagraphCommand: Command<
text: model.text?.clone(), text: model.text?.clone(),
children: model.children, children: model.children,
}; };
if (stopCapturing) std.doc.captureSync(); if (stopCapturing) std.store.captureSync();
doc.deleteBlock(model, { doc.deleteBlock(model, {
deleteChildren: false, deleteChildren: false,
}); });
@@ -23,7 +23,7 @@ export function forwardDelete(std: BlockStdScope): true | undefined {
const text = std.selection.find(TextSelection); const text = std.selection.find(TextSelection);
if (!text) return; if (!text) return;
const isCollapsed = text.isCollapsed(); const isCollapsed = text.isCollapsed();
const doc = std.doc; const doc = std.store;
const model = doc.getBlock(text.from.blockId)?.model; const model = doc.getBlock(text.from.blockId)?.model;
if (!model || !matchFlavours(model, ['affine:list'])) return; if (!model || !matchFlavours(model, ['affine:list'])) return;
const isEnd = isCollapsed && text.from.index === model.text.length; const isEnd = isCollapsed && text.from.index === model.text.length;
@@ -27,7 +27,7 @@ export const updateBlockType: Command<
> = (ctx, next) => { > = (ctx, next) => {
const { std, flavour, props } = ctx; const { std, flavour, props } = ctx;
const host = std.host; const host = std.host;
const doc = std.doc; const doc = std.store;
const getSelectedBlocks = () => { const getSelectedBlocks = () => {
let { selectedBlocks } = ctx; let { selectedBlocks } = ctx;
@@ -11,24 +11,24 @@ export const dedentBlockToRoot: Command<
> = (ctx, next) => { > = (ctx, next) => {
let { blockId } = ctx; let { blockId } = ctx;
const { std, stopCapture = true } = ctx; const { std, stopCapture = true } = ctx;
const { doc } = std; const { store } = std;
if (!blockId) { if (!blockId) {
const sel = std.selection.getGroup('note').at(0); const sel = std.selection.getGroup('note').at(0);
blockId = sel?.blockId; blockId = sel?.blockId;
} }
if (!blockId) return; if (!blockId) return;
const model = std.doc.getBlock(blockId)?.model; const model = std.store.getBlock(blockId)?.model;
if (!model) return; if (!model) return;
let parent = doc.getParent(model); let parent = store.getParent(model);
let changed = false; let changed = false;
while (parent && !matchFlavours(parent, ['affine:note'])) { while (parent && !matchFlavours(parent, ['affine:note'])) {
if (!changed) { if (!changed) {
if (stopCapture) doc.captureSync(); if (stopCapture) store.captureSync();
changed = true; changed = true;
} }
std.command.exec('dedentBlock', { blockId: model.id, stopCapture: true }); std.command.exec('dedentBlock', { blockId: model.id, stopCapture: true });
parent = doc.getParent(model); parent = store.getParent(model);
} }
if (!changed) { if (!changed) {
@@ -30,23 +30,23 @@ export const dedentBlock: Command<
> = (ctx, next) => { > = (ctx, next) => {
let { blockId } = ctx; let { blockId } = ctx;
const { std, stopCapture = true } = ctx; const { std, stopCapture = true } = ctx;
const { doc } = std; const { store } = std;
if (!blockId) { if (!blockId) {
const sel = std.selection.getGroup('note').at(0); const sel = std.selection.getGroup('note').at(0);
blockId = sel?.blockId; blockId = sel?.blockId;
} }
if (!blockId) return; if (!blockId) return;
const model = std.doc.getBlock(blockId)?.model; const model = std.store.getBlock(blockId)?.model;
if (!model) return; if (!model) return;
const parent = doc.getParent(model); const parent = store.getParent(model);
const grandParent = parent && doc.getParent(parent); const grandParent = parent && store.getParent(parent);
if (doc.readonly || !parent || parent.role !== 'content' || !grandParent) { if (store.readonly || !parent || parent.role !== 'content' || !grandParent) {
// Top most, can not unindent, do nothing // Top most, can not unindent, do nothing
return; return;
} }
if (stopCapture) doc.captureSync(); if (stopCapture) store.captureSync();
if ( if (
matchFlavours(model, ['affine:paragraph']) && matchFlavours(model, ['affine:paragraph']) &&
@@ -54,14 +54,14 @@ export const dedentBlock: Command<
model.collapsed model.collapsed
) { ) {
const collapsedSiblings = calculateCollapsedSiblings(model); const collapsedSiblings = calculateCollapsedSiblings(model);
doc.moveBlocks([model, ...collapsedSiblings], grandParent, parent, false); store.moveBlocks([model, ...collapsedSiblings], grandParent, parent, false);
return next(); return next();
} }
try { try {
const nextSiblings = doc.getNexts(model); const nextSiblings = store.getNexts(model);
doc.moveBlocks(nextSiblings, model); store.moveBlocks(nextSiblings, model);
doc.moveBlocks([model], grandParent, parent, false); store.moveBlocks([model], grandParent, parent, false);
} catch { } catch {
return; return;
} }
@@ -11,7 +11,7 @@ export const dedentBlocksToRoot: Command<
> = (ctx, next) => { > = (ctx, next) => {
let { blockIds } = ctx; let { blockIds } = ctx;
const { std, stopCapture = true } = ctx; const { std, stopCapture = true } = ctx;
const { doc } = std; const { store } = std;
if (!blockIds || !blockIds.length) { if (!blockIds || !blockIds.length) {
const text = std.selection.find(TextSelection); const text = std.selection.find(TextSelection);
if (text) { if (text) {
@@ -26,12 +26,12 @@ export const dedentBlocksToRoot: Command<
} }
} }
if (!blockIds || !blockIds.length || doc.readonly) return; if (!blockIds || !blockIds.length || store.readonly) return;
if (stopCapture) doc.captureSync(); if (stopCapture) store.captureSync();
for (let i = blockIds.length - 1; i >= 0; i--) { for (let i = blockIds.length - 1; i >= 0; i--) {
const model = blockIds[i]; const model = blockIds[i];
const parent = doc.getParent(model); const parent = store.getParent(model);
if (parent && !matchFlavours(parent, ['affine:note'])) { if (parent && !matchFlavours(parent, ['affine:note'])) {
std.command.exec('dedentBlockToRoot', { std.command.exec('dedentBlockToRoot', {
blockId: model, blockId: model,
@@ -14,8 +14,8 @@ export const dedentBlocks: Command<
> = (ctx, next) => { > = (ctx, next) => {
let { blockIds } = ctx; let { blockIds } = ctx;
const { std, stopCapture = true } = ctx; const { std, stopCapture = true } = ctx;
const { doc, selection, range, host } = std; const { store, selection, range, host } = std;
const { schema } = doc; const { schema } = store;
if (!blockIds || !blockIds.length) { if (!blockIds || !blockIds.length) {
const nativeRange = range.value; const nativeRange = range.value;
@@ -32,16 +32,16 @@ export const dedentBlocks: Command<
} }
} }
if (!blockIds || !blockIds.length || doc.readonly) return; if (!blockIds || !blockIds.length || store.readonly) return;
// Find the first model that can be unindented // Find the first model that can be unindented
let firstDedentIndex = -1; let firstDedentIndex = -1;
for (let i = 0; i < blockIds.length; i++) { for (let i = 0; i < blockIds.length; i++) {
const model = doc.getBlock(blockIds[i])?.model; const model = store.getBlock(blockIds[i])?.model;
if (!model) continue; if (!model) continue;
const parent = doc.getParent(blockIds[i]); const parent = store.getParent(blockIds[i]);
if (!parent) continue; if (!parent) continue;
const grandParent = doc.getParent(parent); const grandParent = store.getParent(parent);
if (!grandParent) continue; if (!grandParent) continue;
if (schema.isValid(model.flavour, grandParent.flavour)) { if (schema.isValid(model.flavour, grandParent.flavour)) {
@@ -52,11 +52,11 @@ export const dedentBlocks: Command<
if (firstDedentIndex === -1) return; if (firstDedentIndex === -1) return;
if (stopCapture) doc.captureSync(); if (stopCapture) store.captureSync();
const collapsedIds: string[] = []; const collapsedIds: string[] = [];
blockIds.slice(firstDedentIndex).forEach(id => { blockIds.slice(firstDedentIndex).forEach(id => {
const model = doc.getBlock(id)?.model; const model = store.getBlock(id)?.model;
if (!model) return; if (!model) return;
if ( if (
matchFlavours(model, ['affine:paragraph']) && matchFlavours(model, ['affine:paragraph']) &&
@@ -31,19 +31,19 @@ export const indentBlock: Command<
> = (ctx, next) => { > = (ctx, next) => {
let { blockId } = ctx; let { blockId } = ctx;
const { std, stopCapture = true } = ctx; const { std, stopCapture = true } = ctx;
const { doc } = std; const { store } = std;
const { schema } = doc; const { schema } = store;
if (!blockId) { if (!blockId) {
const sel = std.selection.getGroup('note').at(0); const sel = std.selection.getGroup('note').at(0);
blockId = sel?.blockId; blockId = sel?.blockId;
} }
if (!blockId) return; if (!blockId) return;
const model = std.doc.getBlock(blockId)?.model; const model = std.store.getBlock(blockId)?.model;
if (!model) return; if (!model) return;
const previousSibling = doc.getPrev(model); const previousSibling = store.getPrev(model);
if ( if (
doc.readonly || store.readonly ||
!previousSibling || !previousSibling ||
!schema.isValid(model.flavour, previousSibling.flavour) !schema.isValid(model.flavour, previousSibling.flavour)
) { ) {
@@ -51,7 +51,7 @@ export const indentBlock: Command<
return; return;
} }
if (stopCapture) doc.captureSync(); if (stopCapture) store.captureSync();
if ( if (
matchFlavours(model, ['affine:paragraph']) && matchFlavours(model, ['affine:paragraph']) &&
@@ -59,9 +59,9 @@ export const indentBlock: Command<
model.collapsed model.collapsed
) { ) {
const collapsedSiblings = calculateCollapsedSiblings(model); const collapsedSiblings = calculateCollapsedSiblings(model);
doc.moveBlocks([model, ...collapsedSiblings], previousSibling); store.moveBlocks([model, ...collapsedSiblings], previousSibling);
} else { } else {
doc.moveBlocks([model], previousSibling); store.moveBlocks([model], previousSibling);
} }
// update collapsed state of affine list // update collapsed state of affine list
@@ -69,7 +69,7 @@ export const indentBlock: Command<
matchFlavours(previousSibling, ['affine:list']) && matchFlavours(previousSibling, ['affine:list']) &&
previousSibling.collapsed previousSibling.collapsed
) { ) {
doc.updateBlock(previousSibling, { store.updateBlock(previousSibling, {
collapsed: false, collapsed: false,
} as Partial<ListBlockModel>); } as Partial<ListBlockModel>);
} }
@@ -15,8 +15,8 @@ export const indentBlocks: Command<
> = (ctx, next) => { > = (ctx, next) => {
let { blockIds } = ctx; let { blockIds } = ctx;
const { std, stopCapture = true } = ctx; const { std, stopCapture = true } = ctx;
const { doc, selection, range, host } = std; const { store, selection, range, host } = std;
const { schema } = doc; const { schema } = store;
if (!blockIds || !blockIds.length) { if (!blockIds || !blockIds.length) {
const nativeRange = range.value; const nativeRange = range.value;
@@ -33,13 +33,13 @@ export const indentBlocks: Command<
} }
} }
if (!blockIds || !blockIds.length || doc.readonly) return; if (!blockIds || !blockIds.length || store.readonly) return;
// Find the first model that can be indented // Find the first model that can be indented
let firstIndentIndex = -1; let firstIndentIndex = -1;
for (let i = 0; i < blockIds.length; i++) { for (let i = 0; i < blockIds.length; i++) {
const previousSibling = doc.getPrev(blockIds[i]); const previousSibling = store.getPrev(blockIds[i]);
const model = doc.getBlock(blockIds[i])?.model; const model = store.getBlock(blockIds[i])?.model;
if ( if (
model && model &&
previousSibling && previousSibling &&
@@ -53,11 +53,11 @@ export const indentBlocks: Command<
// No model can be indented // No model can be indented
if (firstIndentIndex === -1) return; if (firstIndentIndex === -1) return;
if (stopCapture) doc.captureSync(); if (stopCapture) store.captureSync();
const collapsedIds: string[] = []; const collapsedIds: string[] = [];
blockIds.slice(firstIndentIndex).forEach(id => { blockIds.slice(firstIndentIndex).forEach(id => {
const model = doc.getBlock(id)?.model; const model = store.getBlock(id)?.model;
if (!model) return; if (!model) return;
if ( if (
matchFlavours(model, ['affine:paragraph']) && matchFlavours(model, ['affine:paragraph']) &&
@@ -72,7 +72,7 @@ export const indentBlocks: Command<
const indentIds = blockIds const indentIds = blockIds
.slice(firstIndentIndex) .slice(firstIndentIndex)
.filter(id => !collapsedIds.includes(id)); .filter(id => !collapsedIds.includes(id));
const firstModel = doc.getBlock(indentIds[0])?.model; const firstModel = store.getBlock(indentIds[0])?.model;
if (!firstModel) return; if (!firstModel) return;
{ {
@@ -88,7 +88,7 @@ export const indentBlocks: Command<
matchFlavours(nearestHeading, ['affine:paragraph']) && matchFlavours(nearestHeading, ['affine:paragraph']) &&
nearestHeading.collapsed nearestHeading.collapsed
) { ) {
doc.updateBlock(nearestHeading, { store.updateBlock(nearestHeading, {
collapsed: false, collapsed: false,
}); });
} }
@@ -111,7 +111,7 @@ export const indentBlocks: Command<
matchFlavours(nearestHeading, ['affine:paragraph']) && matchFlavours(nearestHeading, ['affine:paragraph']) &&
nearestHeading.collapsed nearestHeading.collapsed
) { ) {
doc.updateBlock(nearestHeading, { store.updateBlock(nearestHeading, {
collapsed: false, collapsed: false,
}); });
} }
@@ -32,7 +32,7 @@ export const moveBlockConfigs: MoveBlockConfig[] = [
name: 'Move Up', name: 'Move Up',
hotkey: ['Mod-Alt-ArrowUp', 'Mod-Shift-ArrowUp'], hotkey: ['Mod-Alt-ArrowUp', 'Mod-Shift-ArrowUp'],
action: std => { action: std => {
const doc = std.doc; const doc = std.store;
const textSelection = getTextSelection(std); const textSelection = getTextSelection(std);
if (textSelection) { if (textSelection) {
const currentModel = pathToBlock( const currentModel = pathToBlock(
@@ -44,10 +44,10 @@ export const moveBlockConfigs: MoveBlockConfig[] = [
const previousSiblingModel = doc.getPrev(currentModel); const previousSiblingModel = doc.getPrev(currentModel);
if (!previousSiblingModel) return; if (!previousSiblingModel) return;
const parentModel = std.doc.getParent(previousSiblingModel); const parentModel = std.store.getParent(previousSiblingModel);
if (!parentModel) return; if (!parentModel) return;
std.doc.moveBlocks( std.store.moveBlocks(
[currentModel], [currentModel],
parentModel, parentModel,
previousSiblingModel, previousSiblingModel,
@@ -86,7 +86,7 @@ export const moveBlockConfigs: MoveBlockConfig[] = [
name: 'Move Down', name: 'Move Down',
hotkey: ['Mod-Alt-ArrowDown', 'Mod-Shift-ArrowDown'], hotkey: ['Mod-Alt-ArrowDown', 'Mod-Shift-ArrowDown'],
action: std => { action: std => {
const doc = std.doc; const doc = std.store;
const textSelection = getTextSelection(std); const textSelection = getTextSelection(std);
if (textSelection) { if (textSelection) {
const currentModel = pathToBlock( const currentModel = pathToBlock(
@@ -130,7 +130,7 @@ export class NoteBlockService extends BlockService {
private _focusBlock: BlockComponent | null = null; private _focusBlock: BlockComponent | null = null;
private readonly _getClosestNoteByBlockId = (blockId: string) => { private readonly _getClosestNoteByBlockId = (blockId: string) => {
const doc = this._std.doc; const doc = this._std.store;
let parent = doc.getBlock(blockId)?.model ?? null; let parent = doc.getBlock(blockId)?.model ?? null;
while (parent) { while (parent) {
if (matchFlavours(parent, [NoteBlockSchema.model.flavour])) { if (matchFlavours(parent, [NoteBlockSchema.model.flavour])) {
@@ -423,7 +423,7 @@ export class NoteBlockService extends BlockService {
return; return;
} }
const { view, doc, selection } = ctx.std; const { view, store, selection } = ctx.std;
const element = view.getBlock(blockSelection.blockId); const element = view.getBlock(blockSelection.blockId);
if (!element) { if (!element) {
@@ -431,14 +431,19 @@ export class NoteBlockService extends BlockService {
} }
const { model } = element; const { model } = element;
const parent = doc.getParent(model); const parent = store.getParent(model);
if (!parent) { if (!parent) {
return; return;
} }
const index = parent.children.indexOf(model) ?? undefined; const index = parent.children.indexOf(model) ?? undefined;
const blockId = doc.addBlock('affine:paragraph', {}, parent, index + 1); const blockId = store.addBlock(
'affine:paragraph',
{},
parent,
index + 1
);
const sel = selection.create(TextSelection, { const sel = selection.create(TextSelection, {
from: { from: {
@@ -43,7 +43,7 @@ export const quickActionConfig: QuickActionConfig[] = [
std.selection.clear(); std.selection.clear();
const doc = std.doc; const doc = std.store;
const autofill = getTitleFromSelectedModels(selectedModels); const autofill = getTitleFromSelectedModels(selectedModels);
promptDocTitle(std, autofill) promptDocTitle(std, autofill)
.then(title => { .then(title => {
@@ -12,8 +12,8 @@ export const addParagraphCommand: Command<
} }
> = (ctx, next) => { > = (ctx, next) => {
const { std } = ctx; const { std } = ctx;
const { doc, selection } = std; const { store, selection } = std;
doc.captureSync(); store.captureSync();
let blockId = ctx.blockId; let blockId = ctx.blockId;
if (!blockId) { if (!blockId) {
@@ -22,7 +22,7 @@ export const addParagraphCommand: Command<
} }
if (!blockId) return; if (!blockId) return;
const model = doc.getBlock(blockId)?.model; const model = store.getBlock(blockId)?.model;
if (!model) return; if (!model) return;
let id: string; let id: string;
@@ -35,9 +35,9 @@ export const addParagraphCommand: Command<
// aaa // aaa
// | // |
// bbb // bbb
id = doc.addBlock('affine:paragraph', {}, model, 0); id = store.addBlock('affine:paragraph', {}, model, 0);
} else { } else {
const parent = doc.getParent(model); const parent = store.getParent(model);
if (!parent) return; if (!parent) return;
const index = parent.children.indexOf(model); const index = parent.children.indexOf(model);
if (index < 0) return; if (index < 0) return;
@@ -47,7 +47,7 @@ export const addParagraphCommand: Command<
// after: // after:
// aaa // aaa
// | // |
id = doc.addBlock('affine:paragraph', {}, parent, index + 1); id = store.addBlock('affine:paragraph', {}, parent, index + 1);
} }
focusTextModel(std, id); focusTextModel(std, id);
@@ -12,15 +12,19 @@ export const appendParagraphCommand: Command<
{ text?: string } { text?: string }
> = (ctx, next) => { > = (ctx, next) => {
const { std, text = '' } = ctx; const { std, text = '' } = ctx;
const { doc } = std; const { store } = std;
if (!doc.root) return; if (!store.root) return;
const note = getLastNoteBlock(doc); const note = getLastNoteBlock(store);
let noteId = note?.id; let noteId = note?.id;
if (!noteId) { if (!noteId) {
noteId = doc.addBlock('affine:note', {}, doc.root.id); noteId = store.addBlock('affine:note', {}, store.root.id);
} }
const id = doc.addBlock('affine:paragraph', { text: new Text(text) }, noteId); const id = store.addBlock(
'affine:paragraph',
{ text: new Text(text) },
noteId
);
focusTextModel(std, id, text.length); focusTextModel(std, id, text.length);
next(); next();
@@ -12,7 +12,7 @@ export const canDedentParagraphCommand: Command<
> = (ctx, next) => { > = (ctx, next) => {
let { blockId, inlineIndex } = ctx; let { blockId, inlineIndex } = ctx;
const { std } = ctx; const { std } = ctx;
const { selection, doc } = std; const { selection, store } = std;
const text = selection.find(TextSelection); const text = selection.find(TextSelection);
if (!blockId) { if (!blockId) {
@@ -32,18 +32,18 @@ export const canDedentParagraphCommand: Command<
return; return;
} }
const model = doc.getBlock(blockId)?.model; const model = store.getBlock(blockId)?.model;
if (!model || !matchFlavours(model, ['affine:paragraph'])) { if (!model || !matchFlavours(model, ['affine:paragraph'])) {
return; return;
} }
const parent = doc.getParent(model); const parent = store.getParent(model);
if (doc.readonly || !parent || parent.role !== 'content') { if (store.readonly || !parent || parent.role !== 'content') {
// Top most, can not unindent, do nothing // Top most, can not unindent, do nothing
return; return;
} }
const grandParent = doc.getParent(parent); const grandParent = store.getParent(parent);
if (!grandParent) return; if (!grandParent) return;
return next({ return next({
@@ -58,7 +58,7 @@ export const canDedentParagraphCommand: Command<
export const dedentParagraphCommand: Command<'indentContext'> = (ctx, next) => { export const dedentParagraphCommand: Command<'indentContext'> = (ctx, next) => {
const { indentContext: dedentContext, std } = ctx; const { indentContext: dedentContext, std } = ctx;
const { doc, selection, range, host } = std; const { store, selection, range, host } = std;
if ( if (
!dedentContext || !dedentContext ||
@@ -73,16 +73,16 @@ export const dedentParagraphCommand: Command<'indentContext'> = (ctx, next) => {
const { blockId } = dedentContext; const { blockId } = dedentContext;
const model = doc.getBlock(blockId)?.model; const model = store.getBlock(blockId)?.model;
if (!model) return; if (!model) return;
const parent = doc.getParent(model); const parent = store.getParent(model);
if (!parent) return; if (!parent) return;
const grandParent = doc.getParent(parent); const grandParent = store.getParent(parent);
if (!grandParent) return; if (!grandParent) return;
doc.captureSync(); store.captureSync();
if ( if (
matchFlavours(model, ['affine:paragraph']) && matchFlavours(model, ['affine:paragraph']) &&
@@ -90,11 +90,11 @@ export const dedentParagraphCommand: Command<'indentContext'> = (ctx, next) => {
model.collapsed model.collapsed
) { ) {
const collapsedSiblings = calculateCollapsedSiblings(model); const collapsedSiblings = calculateCollapsedSiblings(model);
doc.moveBlocks([model, ...collapsedSiblings], grandParent, parent, false); store.moveBlocks([model, ...collapsedSiblings], grandParent, parent, false);
} else { } else {
const nextSiblings = doc.getNexts(model); const nextSiblings = store.getNexts(model);
doc.moveBlocks(nextSiblings, model); store.moveBlocks(nextSiblings, model);
doc.moveBlocks([model], grandParent, parent, false); store.moveBlocks([model], grandParent, parent, false);
} }
const textSelection = selection.find(TextSelection); const textSelection = selection.find(TextSelection);
@@ -14,8 +14,8 @@ export const canIndentParagraphCommand: Command<
> = (cxt, next) => { > = (cxt, next) => {
let { blockId, inlineIndex } = cxt; let { blockId, inlineIndex } = cxt;
const { std } = cxt; const { std } = cxt;
const { selection, doc } = std; const { selection, store } = std;
const { schema } = doc; const { schema } = store;
if (!blockId) { if (!blockId) {
const text = selection.find(TextSelection); const text = selection.find(TextSelection);
@@ -35,14 +35,14 @@ export const canIndentParagraphCommand: Command<
return; return;
} }
const model = std.doc.getBlock(blockId)?.model; const model = std.store.getBlock(blockId)?.model;
if (!model || !matchFlavours(model, ['affine:paragraph'])) { if (!model || !matchFlavours(model, ['affine:paragraph'])) {
return; return;
} }
const previousSibling = doc.getPrev(model); const previousSibling = store.getPrev(model);
if ( if (
doc.readonly || store.readonly ||
!previousSibling || !previousSibling ||
!schema.isValid(model.flavour, previousSibling.flavour) !schema.isValid(model.flavour, previousSibling.flavour)
) { ) {
@@ -62,7 +62,7 @@ export const canIndentParagraphCommand: Command<
export const indentParagraphCommand: Command<'indentContext'> = (ctx, next) => { export const indentParagraphCommand: Command<'indentContext'> = (ctx, next) => {
const { indentContext, std } = ctx; const { indentContext, std } = ctx;
const { doc, selection, host, range } = std; const { store, selection, host, range } = std;
if ( if (
!indentContext || !indentContext ||
@@ -76,13 +76,13 @@ export const indentParagraphCommand: Command<'indentContext'> = (ctx, next) => {
} }
const { blockId } = indentContext; const { blockId } = indentContext;
const model = doc.getBlock(blockId)?.model; const model = store.getBlock(blockId)?.model;
if (!model) return; if (!model) return;
const previousSibling = doc.getPrev(model); const previousSibling = store.getPrev(model);
if (!previousSibling) return; if (!previousSibling) return;
doc.captureSync(); store.captureSync();
{ {
// > # 123 // > # 123
@@ -95,7 +95,7 @@ export const indentParagraphCommand: Command<'indentContext'> = (ctx, next) => {
matchFlavours(nearestHeading, ['affine:paragraph']) && matchFlavours(nearestHeading, ['affine:paragraph']) &&
nearestHeading.collapsed nearestHeading.collapsed
) { ) {
doc.updateBlock(nearestHeading, { store.updateBlock(nearestHeading, {
collapsed: false, collapsed: false,
}); });
} }
@@ -107,9 +107,9 @@ export const indentParagraphCommand: Command<'indentContext'> = (ctx, next) => {
model.collapsed model.collapsed
) { ) {
const collapsedSiblings = calculateCollapsedSiblings(model); const collapsedSiblings = calculateCollapsedSiblings(model);
doc.moveBlocks([model, ...collapsedSiblings], previousSibling); store.moveBlocks([model, ...collapsedSiblings], previousSibling);
} else { } else {
doc.moveBlocks([model], previousSibling); store.moveBlocks([model], previousSibling);
} }
{ {
@@ -124,7 +124,7 @@ export const indentParagraphCommand: Command<'indentContext'> = (ctx, next) => {
matchFlavours(nearestHeading, ['affine:paragraph']) && matchFlavours(nearestHeading, ['affine:paragraph']) &&
nearestHeading.collapsed nearestHeading.collapsed
) { ) {
doc.updateBlock(nearestHeading, { store.updateBlock(nearestHeading, {
collapsed: false, collapsed: false,
}); });
} }
@@ -135,7 +135,7 @@ export const indentParagraphCommand: Command<'indentContext'> = (ctx, next) => {
matchFlavours(previousSibling, ['affine:list']) && matchFlavours(previousSibling, ['affine:list']) &&
previousSibling.collapsed previousSibling.collapsed
) { ) {
doc.updateBlock(previousSibling, { store.updateBlock(previousSibling, {
collapsed: false, collapsed: false,
} as Partial<ListBlockModel>); } as Partial<ListBlockModel>);
} }
@@ -13,7 +13,7 @@ export const splitParagraphCommand: Command<
} }
> = (ctx, next) => { > = (ctx, next) => {
const { std } = ctx; const { std } = ctx;
const { doc, host, selection } = std; const { store, host, selection } = std;
let blockId = ctx.blockId; let blockId = ctx.blockId;
if (!blockId) { if (!blockId) {
const text = selection.find(TextSelection); const text = selection.find(TextSelection);
@@ -21,7 +21,7 @@ export const splitParagraphCommand: Command<
} }
if (!blockId) return; if (!blockId) return;
const model = doc.getBlock(blockId)?.model; const model = store.getBlock(blockId)?.model;
if (!model || !matchFlavours(model, ['affine:paragraph'])) return; if (!model || !matchFlavours(model, ['affine:paragraph'])) return;
const inlineEditor = getInlineEditorByModel(host, model); const inlineEditor = getInlineEditorByModel(host, model);
@@ -38,9 +38,9 @@ export const splitParagraphCommand: Command<
if (model.text.yText.length < splitIndex + splitLength) return; if (model.text.yText.length < splitIndex + splitLength) return;
if (model.children.length > 0 && splitIndex > 0) { if (model.children.length > 0 && splitIndex > 0) {
doc.captureSync(); store.captureSync();
const right = model.text.split(splitIndex, splitLength); const right = model.text.split(splitIndex, splitLength);
const id = doc.addBlock( const id = store.addBlock(
model.flavour as BlockSuite.Flavour, model.flavour as BlockSuite.Flavour,
{ {
text: right, text: right,
@@ -53,13 +53,13 @@ export const splitParagraphCommand: Command<
return next({ paragraphConvertedId: id }); return next({ paragraphConvertedId: id });
} }
const parent = doc.getParent(model); const parent = store.getParent(model);
if (!parent) return; if (!parent) return;
const index = parent.children.indexOf(model); const index = parent.children.indexOf(model);
if (index < 0) return; if (index < 0) return;
doc.captureSync(); store.captureSync();
const right = model.text.split(splitIndex, splitLength); const right = model.text.split(splitIndex, splitLength);
const id = doc.addBlock( const id = store.addBlock(
model.flavour, model.flavour,
{ {
text: right, text: right,
@@ -68,9 +68,9 @@ export const splitParagraphCommand: Command<
parent, parent,
index + 1 index + 1
); );
const newModel = doc.getBlock(id)?.model; const newModel = store.getBlock(id)?.model;
if (newModel) { if (newModel) {
doc.moveBlocks(model.children, newModel); store.moveBlocks(model.children, newModel);
} else { } else {
console.error('Failed to find the new model split from the paragraph'); console.error('Failed to find the new model split from the paragraph');
} }
@@ -25,11 +25,10 @@ export const ParagraphKeymapExtension = KeymapExtension(
const isStart = isCollapsed && text.from.index === 0; const isStart = isCollapsed && text.from.index === 0;
if (!isStart) return; if (!isStart) return;
const { doc } = std; const { store } = std;
const model = doc.getBlock(text.from.blockId)?.model; const model = store.getBlock(text.from.blockId)?.model;
if (!model || !matchFlavours(model, ['affine:paragraph'])) return; if (!model || !matchFlavours(model, ['affine:paragraph'])) return;
// const { model, doc } = this;
const event = ctx.get('keyboardState').raw; const event = ctx.get('keyboardState').raw;
event.preventDefault(); event.preventDefault();
@@ -37,8 +36,8 @@ export const ParagraphKeymapExtension = KeymapExtension(
// firstly switch it to normal text, then delete this empty block. // firstly switch it to normal text, then delete this empty block.
if (model.type !== 'text') { if (model.type !== 'text') {
// Try to switch to normal text // Try to switch to normal text
doc.captureSync(); store.captureSync();
doc.updateBlock(model, { type: 'text' }); store.updateBlock(model, { type: 'text' });
return true; return true;
} }
@@ -51,10 +50,10 @@ export const ParagraphKeymapExtension = KeymapExtension(
return true; return true;
}, },
'Mod-Enter': ctx => { 'Mod-Enter': ctx => {
const { doc } = std; const { store } = std;
const text = std.selection.find(TextSelection); const text = std.selection.find(TextSelection);
if (!text) return; if (!text) return;
const model = doc.getBlock(text.from.blockId)?.model; const model = store.getBlock(text.from.blockId)?.model;
if (!model || !matchFlavours(model, ['affine:paragraph'])) return; if (!model || !matchFlavours(model, ['affine:paragraph'])) return;
const inlineEditor = getInlineEditorByModel( const inlineEditor = getInlineEditorByModel(
std.host, std.host,
@@ -65,7 +64,7 @@ export const ParagraphKeymapExtension = KeymapExtension(
const raw = ctx.get('keyboardState').raw; const raw = ctx.get('keyboardState').raw;
raw.preventDefault(); raw.preventDefault();
if (model.type === 'quote') { if (model.type === 'quote') {
doc.captureSync(); store.captureSync();
inlineEditor.insertText(inlineRange, '\n'); inlineEditor.insertText(inlineRange, '\n');
inlineEditor.setInlineRange({ inlineEditor.setInlineRange({
index: inlineRange.index + 1, index: inlineRange.index + 1,
@@ -78,10 +77,10 @@ export const ParagraphKeymapExtension = KeymapExtension(
return true; return true;
}, },
Enter: ctx => { Enter: ctx => {
const { doc } = std; const { store } = std;
const text = std.selection.find(TextSelection); const text = std.selection.find(TextSelection);
if (!text) return; if (!text) return;
const model = doc.getBlock(text.from.blockId)?.model; const model = store.getBlock(text.from.blockId)?.model;
if (!model || !matchFlavours(model, ['affine:paragraph'])) return; if (!model || !matchFlavours(model, ['affine:paragraph'])) return;
const inlineEditor = getInlineEditorByModel( const inlineEditor = getInlineEditorByModel(
std.host, std.host,
@@ -112,7 +111,7 @@ export const ParagraphKeymapExtension = KeymapExtension(
textStr === '\n' || textStr.endsWith('\n'); textStr === '\n' || textStr.endsWith('\n');
if (isEnd && endWithTwoBlankLines) { if (isEnd && endWithTwoBlankLines) {
raw.preventDefault(); raw.preventDefault();
doc.captureSync(); store.captureSync();
model.text.delete(range.index - 1, 1); model.text.delete(range.index - 1, 1);
std.command.exec('addParagraph'); std.command.exec('addParagraph');
return true; return true;
@@ -127,14 +126,14 @@ export const ParagraphKeymapExtension = KeymapExtension(
} }
if (model.type.startsWith('h') && model.collapsed) { if (model.type.startsWith('h') && model.collapsed) {
const parent = doc.getParent(model); const parent = store.getParent(model);
if (!parent) return true; if (!parent) return true;
const index = parent.children.indexOf(model); const index = parent.children.indexOf(model);
if (index === -1) return true; if (index === -1) return true;
const collapsedSiblings = calculateCollapsedSiblings(model); const collapsedSiblings = calculateCollapsedSiblings(model);
const rightText = model.text.split(range.index); const rightText = model.text.split(range.index);
const newId = doc.addBlock( const newId = store.addBlock(
model.flavour, model.flavour,
{ type: model.type, text: rightText }, { type: model.type, text: rightText },
parent, parent,
@@ -10,18 +10,18 @@ import {
} from '@blocksuite/block-std'; } from '@blocksuite/block-std';
export function forwardDelete(std: BlockStdScope) { export function forwardDelete(std: BlockStdScope) {
const { doc, host } = std; const { store, host } = std;
const text = std.selection.find(TextSelection); const text = std.selection.find(TextSelection);
if (!text) return; if (!text) return;
const isCollapsed = text.isCollapsed(); const isCollapsed = text.isCollapsed();
const model = doc.getBlock(text.from.blockId)?.model; const model = store.getBlock(text.from.blockId)?.model;
if (!model || !matchFlavours(model, ['affine:paragraph'])) return; if (!model || !matchFlavours(model, ['affine:paragraph'])) return;
const isEnd = isCollapsed && text.from.index === model.text.length; const isEnd = isCollapsed && text.from.index === model.text.length;
if (!isEnd) return; if (!isEnd) return;
const parent = doc.getParent(model); const parent = store.getParent(model);
if (!parent) return; if (!parent) return;
const nextSibling = doc.getNext(model); const nextSibling = store.getNext(model);
const ignoreForwardDeleteFlavourList: BlockSuite.Flavour[] = [ const ignoreForwardDeleteFlavourList: BlockSuite.Flavour[] = [
'affine:attachment', 'affine:attachment',
'affine:bookmark', 'affine:bookmark',
@@ -42,12 +42,12 @@ export function forwardDelete(std: BlockStdScope) {
if (nextSibling?.text) { if (nextSibling?.text) {
model.text.join(nextSibling.text); model.text.join(nextSibling.text);
if (nextSibling.children) { if (nextSibling.children) {
const parent = doc.getParent(nextSibling); const parent = store.getParent(nextSibling);
if (!parent) return false; if (!parent) return false;
doc.moveBlocks(nextSibling.children, parent, model, false); store.moveBlocks(nextSibling.children, parent, model, false);
} }
doc.deleteBlock(nextSibling); store.deleteBlock(nextSibling);
return true; return true;
} }
@@ -55,11 +55,16 @@ export function forwardDelete(std: BlockStdScope) {
if (nextBlock?.text) { if (nextBlock?.text) {
model.text.join(nextBlock.text); model.text.join(nextBlock.text);
if (nextBlock.children) { if (nextBlock.children) {
const parent = doc.getParent(nextBlock); const parent = store.getParent(nextBlock);
if (!parent) return false; if (!parent) return false;
doc.moveBlocks(nextBlock.children, parent, doc.getParent(model), false); store.moveBlocks(
nextBlock.children,
parent,
store.getParent(model),
false
);
} }
doc.deleteBlock(nextBlock); store.deleteBlock(nextBlock);
return true; return true;
} }
@@ -27,11 +27,11 @@ export const insertSurfaceRefBlockCommand: Command<
reference, reference,
}; };
const surface = getSurfaceBlock(std.doc); const surface = getSurfaceBlock(std.store);
if (!surface) return; if (!surface) return;
const element = surface.getElementById(reference); const element = surface.getElementById(reference);
const blockModel = std.doc.getBlock(reference)?.model ?? null; const blockModel = std.store.getBlock(reference)?.model ?? null;
if (element?.type === 'group') { if (element?.type === 'group') {
surfaceRefProps.refFlavour = 'group'; surfaceRefProps.refFlavour = 'group';
@@ -42,7 +42,7 @@ export const insertSurfaceRefBlockCommand: Command<
return; return;
} }
const result = std.doc.addSiblingBlocks( const result = std.store.addSiblingBlocks(
targetModel, targetModel,
[surfaceRefProps], [surfaceRefProps],
place place
@@ -50,7 +50,7 @@ export const insertSurfaceRefBlockCommand: Command<
if (result.length === 0) return; if (result.length === 0) return;
if (removeEmptyLine && targetModel.text?.length === 0) { if (removeEmptyLine && targetModel.text?.length === 0) {
std.doc.deleteBlock(targetModel); std.store.deleteBlock(targetModel);
} }
next({ next({
@@ -460,7 +460,7 @@ export class SurfaceRefBlockComponent extends BlockComponent<SurfaceRefBlockMode
override mounted() { override mounted() {
const crud = this.std.get(EdgelessCRUDExtension); const crud = this.std.get(EdgelessCRUDExtension);
const { _disposable } = this; const { _disposable } = this;
const surfaceModel = getSurfaceBlock(this.std.doc); const surfaceModel = getSurfaceBlock(this.std.store);
if (!surfaceModel) return; if (!surfaceModel) return;
const referenceElement = crud.getElementById(referenceId); const referenceElement = crud.getElementById(referenceId);
@@ -28,7 +28,7 @@ export const autoArrangeElementsCommand: Command<never, never, {}> = (
ctx, ctx,
next next
) => { ) => {
const { updateBlock } = ctx.std.doc; const { updateBlock } = ctx.std.store;
const gfx = ctx.std.get(GfxControllerIdentifier); const gfx = ctx.std.get(GfxControllerIdentifier);
const elements = gfx.selection.selectedElements; const elements = gfx.selection.selectedElements;
@@ -46,7 +46,7 @@ export const autoResizeElementsCommand: Command<never, never, {}> = (
ctx, ctx,
next next
) => { ) => {
const { updateBlock } = ctx.std.doc; const { updateBlock } = ctx.std.store;
const gfx = ctx.std.get(GfxControllerIdentifier); const gfx = ctx.std.get(GfxControllerIdentifier);
const elements = gfx.selection.selectedElements; const elements = gfx.selection.selectedElements;
@@ -75,7 +75,7 @@ export class EdgelessCRUDExtension extends Extension {
index: gfx.layer.generateIndex(), index: gfx.layer.generateIndex(),
}; };
return this.std.doc.addBlock( return this.std.store.addBlock(
flavour as never, flavour as never,
nProps, nProps,
parentId, parentId,
@@ -123,14 +123,14 @@ export class EdgelessCRUDExtension extends Extension {
return; return;
} }
const block = this.std.doc.getBlockById(id); const block = this.std.store.getBlockById(id);
if (block) { if (block) {
const key = getLastPropsKey( const key = getLastPropsKey(
block.flavour as BlockSuite.EdgelessModelKeys, block.flavour as BlockSuite.EdgelessModelKeys,
{ ...block.yBlock.toJSON(), ...props } { ...block.yBlock.toJSON(), ...props }
); );
key && this.std.get(EditPropsStore).recordLastProps(key, props); key && this.std.get(EditPropsStore).recordLastProps(key, props);
this.std.doc.updateBlock(block, props); this.std.store.updateBlock(block, props);
} }
}; };
@@ -141,7 +141,7 @@ export class EdgelessCRUDExtension extends Extension {
} }
const el = const el =
surface.getElementById(id) ?? surface.getElementById(id) ??
(this.std.doc.getBlockById( (this.std.store.getBlockById(
id id
) as BlockSuite.EdgelessBlockModelType | null); ) as BlockSuite.EdgelessBlockModelType | null);
return el; return el;
@@ -93,7 +93,7 @@ export function addNote(
}); });
const gfx = std.get(GfxControllerIdentifier); const gfx = std.get(GfxControllerIdentifier);
const doc = std.doc; const doc = std.store;
const blockId = doc.addBlock( const blockId = doc.addBlock(
options.childFlavour as BlockSuite.Flavour, options.childFlavour as BlockSuite.Flavour,
@@ -71,7 +71,7 @@ export class FileDropExtension extends LifeCycleWatcher {
let result: DropResult | null = null; let result: DropResult | null = null;
if (element) { if (element) {
const model = element.model; const model = element.model;
const parent = this.std.doc.getParent(model); const parent = this.std.store.getParent(model);
if (!matchFlavours(parent, ['affine:surface' as BlockSuite.Flavour])) { if (!matchFlavours(parent, ['affine:surface' as BlockSuite.Flavour])) {
result = calcDropTarget(point, model, element); result = calcDropTarget(point, model, element);
} }
@@ -119,7 +119,7 @@ export class FileDropExtension extends LifeCycleWatcher {
} }
get doc() { get doc() {
return this.std.doc; return this.std.store;
} }
get editorHost(): EditorHost { get editorHost(): EditorHost {
@@ -155,7 +155,7 @@ export class FileDropExtension extends LifeCycleWatcher {
let result: DropResult | null = null; let result: DropResult | null = null;
if (element) { if (element) {
const model = element.model; const model = element.model;
const parent = this.std.doc.getParent(model); const parent = this.std.store.getParent(model);
if (!matchFlavours(parent, ['affine:surface' as BlockSuite.Flavour])) { if (!matchFlavours(parent, ['affine:surface' as BlockSuite.Flavour])) {
result = calcDropTarget(point, model, element); result = calcDropTarget(point, model, element);
} }
@@ -5,7 +5,7 @@ import { toast } from '../toast/toast.js';
function notify(std: BlockStdScope, title: string, message: string) { function notify(std: BlockStdScope, title: string, message: string) {
const notification = std.getOptional(NotificationProvider); const notification = std.getOptional(NotificationProvider);
const { doc, host } = std; const { store: doc, host } = std;
if (!notification) { if (!notification) {
toast(host, title); toast(host, title);
@@ -39,7 +39,7 @@ export function getInlineEditorByModel(
) { ) {
const blockModel = const blockModel =
typeof model === 'string' typeof model === 'string'
? editorHost.std.doc.getBlock(model)?.model ? editorHost.std.store.getBlock(model)?.model
: model; : model;
if (!blockModel || matchFlavours(blockModel, ['affine:database'])) { if (!blockModel || matchFlavours(blockModel, ['affine:database'])) {
// Not support database model since it's may be have multiple inline editor instances. // Not support database model since it's may be have multiple inline editor instances.
@@ -62,7 +62,7 @@ export const deleteTextCommand: Command<
selectedElements selectedElements
.filter(el => el.model.id !== fromElement.model.id) .filter(el => el.model.id !== fromElement.model.id)
.forEach(el => { .forEach(el => {
ctx.std.doc.deleteBlock(el.model, { ctx.std.store.deleteBlock(el.model, {
bringChildrenTo: bringChildrenTo:
el.model.id === toElement.model.id ? fromElement.model : undefined, el.model.id === toElement.model.id ? fromElement.model : undefined,
}); });
@@ -38,7 +38,7 @@ export class ReferenceNodeConfigProvider {
} }
get doc() { get doc() {
return this.std.doc; return this.std.store;
} }
get hidePopup() { get hidePopup() {
@@ -41,7 +41,7 @@ export const textCommonKeymap = (
const text = std.selection.find(TextSelection); const text = std.selection.find(TextSelection);
if (!text) return; if (!text) return;
const model = std.doc.getBlock(text.from.blockId)?.model; const model = std.store.getBlock(text.from.blockId)?.model;
if (!model || !model.text) return; if (!model || !model.text) return;
ctx.get('keyboardState').raw.preventDefault(); ctx.get('keyboardState').raw.preventDefault();
@@ -62,7 +62,7 @@ export const textCommonKeymap = (
const blockId = blocks.at(-1)?.blockId; const blockId = blocks.at(-1)?.blockId;
if (!blockId) return; if (!blockId) return;
const model = std.doc.getBlock(blockId)?.model; const model = std.store.getBlock(blockId)?.model;
if (!model || !model.text) return; if (!model || !model.text) return;
ctx.get('keyboardState').raw.preventDefault(); ctx.get('keyboardState').raw.preventDefault();
@@ -21,7 +21,7 @@ export const bracketKeymap = (
return { return {
...acc, ...acc,
[pair.right]: ctx => { [pair.right]: ctx => {
const { doc, selection } = std; const { store: doc, selection } = std;
if (doc.readonly) return; if (doc.readonly) return;
const textSelection = selection.find(TextSelection); const textSelection = selection.find(TextSelection);
@@ -47,7 +47,7 @@ export const bracketKeymap = (
} }
}, },
[pair.left]: ctx => { [pair.left]: ctx => {
const { doc, selection } = std; const { store: doc, selection } = std;
if (doc.readonly) return; if (doc.readonly) return;
const textSelection = selection.find(TextSelection); const textSelection = selection.find(TextSelection);
@@ -98,7 +98,7 @@ export const bracketKeymap = (
return { return {
...keymap, ...keymap,
'`': ctx => { '`': ctx => {
const { doc, selection } = std; const { store: doc, selection } = std;
if (doc.readonly) return; if (doc.readonly) return;
const textSelection = selection.find(TextSelection); const textSelection = selection.find(TextSelection);
@@ -128,7 +128,7 @@ export const bracketKeymap = (
}; };
function tryConvertToLinkedDoc(std: BlockStdScope, inlineEditor: InlineEditor) { function tryConvertToLinkedDoc(std: BlockStdScope, inlineEditor: InlineEditor) {
const root = std.doc.root; const root = std.store.root;
if (!root) return false; if (!root) return false;
const linkedDocWidgetEle = std.view.getWidget( const linkedDocWidgetEle = std.view.getWidget(
'affine-linked-doc-widget', 'affine-linked-doc-widget',
@@ -154,7 +154,7 @@ function tryConvertToLinkedDoc(std: BlockStdScope, inlineEditor: InlineEditor) {
}); });
inlineEditor.setInlineRange({ index: inlineRange.index - 1, length: 0 }); inlineEditor.setInlineRange({ index: inlineRange.index - 1, length: 0 });
const doc = createDefaultDoc(std.doc.workspace, { const doc = createDefaultDoc(std.store.workspace, {
title: docName, title: docName,
}); });
insertLinkedNode({ insertLinkedNode({
@@ -14,7 +14,7 @@ export const textFormatKeymap = (std: BlockStdScope) =>
return { return {
...acc, ...acc,
[config.hotkey as string]: ctx => { [config.hotkey as string]: ctx => {
const { doc, selection } = std; const { store: doc, selection } = std;
if (doc.readonly) return; if (doc.readonly) return;
const textSelection = selection.find(TextSelection); const textSelection = selection.find(TextSelection);
@@ -10,7 +10,7 @@ export function toDivider(
model: BlockModel, model: BlockModel,
prefix: string prefix: string
) { ) {
const { doc } = std; const { store: doc } = std;
if ( if (
matchFlavours(model, ['affine:divider']) || matchFlavours(model, ['affine:divider']) ||
(matchFlavours(model, ['affine:paragraph']) && model.type === 'quote') (matchFlavours(model, ['affine:paragraph']) && model.type === 'quote')
@@ -16,7 +16,7 @@ export function toList(
if (!matchFlavours(model, ['affine:paragraph'])) { if (!matchFlavours(model, ['affine:paragraph'])) {
return; return;
} }
const { doc } = std; const { store: doc } = std;
const parent = doc.getParent(model); const parent = doc.getParent(model);
if (!parent) return; if (!parent) return;
@@ -21,7 +21,7 @@ export function markdownInput(
id = text?.from.blockId; id = text?.from.blockId;
} }
if (!id) return; if (!id) return;
const model = std.doc.getBlock(id)?.model; const model = std.store.getBlock(id)?.model;
if (!model) return; if (!model) return;
const inline = getInlineEditorByModel(std.host, model); const inline = getInlineEditorByModel(std.host, model);
if (!inline) return; if (!inline) return;
@@ -12,7 +12,7 @@ export function toParagraph(
type: ParagraphType, type: ParagraphType,
prefix: string prefix: string
) { ) {
const { doc } = std; const { store: doc } = std;
if (!matchFlavours(model, ['affine:paragraph'])) { if (!matchFlavours(model, ['affine:paragraph'])) {
const parent = doc.getParent(model); const parent = doc.getParent(model);
if (!parent) return; if (!parent) return;
@@ -34,6 +34,6 @@ export function beforeConvert(
// *<space>| -> undo // *<space>| -> undo
text.insert(' ', index); text.insert(' ', index);
focusTextModel(std, model.id, index + 1); focusTextModel(std, model.id, index + 1);
std.doc.captureSync(); std.store.captureSync();
text.delete(0, index + 1); text.delete(0, index + 1);
} }
@@ -239,10 +239,10 @@ class PasteTr {
linkToDocId, linkToDocId,
parseDocUrlService parseDocUrlService
); );
const model = this.std.doc.getBlock(blockSnapshot.id)?.model; const model = this.std.store.getBlock(blockSnapshot.id)?.model;
if (transformed && model) { if (transformed && model) {
this.std.doc.captureSync(); this.std.store.captureSync();
this.std.doc.transact(() => { this.std.store.transact(() => {
const text = model.text as Text; const text = model.text as Text;
text.clear(); text.clear();
text.applyDelta(delta); text.applyDelta(delta);
@@ -263,8 +263,8 @@ class PasteTr {
if (!transformed) { if (!transformed) {
return; return;
} }
this.std.doc.captureSync(); this.std.store.captureSync();
this.std.doc.transact(() => { this.std.store.transact(() => {
fromPointStateText.clear(); fromPointStateText.clear();
fromPointStateText.applyDelta(delta); fromPointStateText.applyDelta(delta);
}); });
@@ -275,8 +275,8 @@ class PasteTr {
const cursorBlock = const cursorBlock =
this.pointState.model.flavour === 'affine:code' || !this.lastSnapshot this.pointState.model.flavour === 'affine:code' || !this.lastSnapshot
? this.std.doc.getBlock(this.pointState.model.id) ? this.std.store.getBlock(this.pointState.model.id)
: this.std.doc.getBlock(this.lastSnapshot.id); : this.std.store.getBlock(this.lastSnapshot.id);
if (!cursorBlock) { if (!cursorBlock) {
return; return;
} }
@@ -323,22 +323,22 @@ class PasteTr {
} }
if (this.lastSnapshot) { if (this.lastSnapshot) {
const lastModel = this.std.doc.getBlock(this.lastSnapshot.id)?.model; const lastModel = this.std.store.getBlock(this.lastSnapshot.id)?.model;
if (!lastModel) { if (!lastModel) {
return; return;
} }
this.std.doc.moveBlocks(this.pointState.model.children, lastModel); this.std.store.moveBlocks(this.pointState.model.children, lastModel);
} }
this.std.doc.moveBlocks( this.std.store.moveBlocks(
this.std.doc this.std.store
.getNexts(this.pointState.model.id) .getNexts(this.pointState.model.id)
.slice(0, this.pasteStartModelChildrenCount), .slice(0, this.pasteStartModelChildrenCount),
this.pointState.model this.pointState.model
); );
if (!this.firstSnapshotIsPlainText && this.pointState.text.length == 0) { if (!this.firstSnapshotIsPlainText && this.pointState.text.length == 0) {
this.std.doc.deleteBlock(this.pointState.model); this.std.store.deleteBlock(this.pointState.model);
} }
}; };
@@ -14,7 +14,7 @@ export const getBlockIndexCommand: Command<
'`path` is required, you need to pass it in args or ctx before adding this command to the pipeline.' '`path` is required, you need to pass it in args or ctx before adding this command to the pipeline.'
); );
const parentModel = ctx.std.doc.getParent(path); const parentModel = ctx.std.store.getParent(path);
if (!parentModel) return; if (!parentModel) return;
const parent = ctx.std.view.getBlock(parentModel.id); const parent = ctx.std.view.getBlock(parentModel.id);
@@ -5,7 +5,7 @@ import { getNextContentBlock } from '../../utils/index.js';
function getNextBlock(std: BlockSuite.Std, path: string) { function getNextBlock(std: BlockSuite.Std, path: string) {
const view = std.view; const view = std.view;
const model = std.doc.getBlock(path)?.model; const model = std.store.getBlock(path)?.model;
if (!model) return null; if (!model) return null;
const nextModel = getNextContentBlock(std.host, model); const nextModel = getNextContentBlock(std.host, model);
if (!nextModel) return null; if (!nextModel) return null;
@@ -6,7 +6,7 @@ import { getPrevContentBlock } from '../../utils/index.js';
function getPrevBlock(std: BlockSuite.Std, path: string) { function getPrevBlock(std: BlockSuite.Std, path: string) {
const view = std.view; const view = std.view;
const model = std.doc.getBlock(path)?.model; const model = std.store.getBlock(path)?.model;
if (!model) return null; if (!model) return null;
const prevModel = getPrevContentBlock(std.host, model); const prevModel = getPrevContentBlock(std.host, model);
if (!prevModel) return null; if (!prevModel) return null;
@@ -51,7 +51,7 @@ export const getSelectedBlocksCommand: Command<
const blockSelections = ctx.blockSelections ?? ctx.currentBlockSelections; const blockSelections = ctx.blockSelections ?? ctx.currentBlockSelections;
if (types.includes('block') && blockSelections) { if (types.includes('block') && blockSelections) {
const viewStore = ctx.std.view; const viewStore = ctx.std.view;
const doc = ctx.std.doc; const doc = ctx.std.store;
const selectedBlockComponents = blockSelections.flatMap(selection => { const selectedBlockComponents = blockSelections.flatMap(selection => {
const el = viewStore.getBlock(selection.blockId); const el = viewStore.getBlock(selection.blockId);
if (!el) { if (!el) {
@@ -15,7 +15,7 @@ export const copySelectedModelsCommand: Command<'draftedModels' | 'onCopy'> = (
models models
.then(models => { .then(models => {
const slice = Slice.fromModels(ctx.std.doc, models); const slice = Slice.fromModels(ctx.std.store, models);
return ctx.std.clipboard.copy(slice); return ctx.std.clipboard.copy(slice);
}) })
@@ -14,7 +14,7 @@ export const deleteSelectedModelsCommand: Command<'selectedModels'> = (
} }
models.forEach(model => { models.forEach(model => {
ctx.std.doc.deleteBlock(model); ctx.std.store.deleteBlock(model);
}); });
return next(); return next();
@@ -9,17 +9,17 @@ export const duplicateSelectedModelsCommand: Command<
const model = selectedModels[selectedModels.length - 1]; const model = selectedModels[selectedModels.length - 1];
const parentModel = std.doc.getParent(model.id); const parentModel = std.store.getParent(model.id);
if (!parentModel) return; if (!parentModel) return;
const index = parentModel.children.findIndex(x => x.id === model.id); const index = parentModel.children.findIndex(x => x.id === model.id);
draftedModels draftedModels
.then(models => { .then(models => {
const slice = Slice.fromModels(std.doc, models); const slice = Slice.fromModels(std.store, models);
return std.clipboard.duplicateSlice( return std.clipboard.duplicateSlice(
slice, slice,
std.doc, std.store,
parentModel.id, parentModel.id,
index + 1 index + 1
); );
@@ -35,7 +35,7 @@ export class DNDAPIExtension extends Extension {
}): SliceSnapshot | null { }): SliceSnapshot | null {
const { docId, flavour = 'affine:embed-linked-doc', blockId } = options; const { docId, flavour = 'affine:embed-linked-doc', blockId } = options;
const slice = Slice.fromModels(this.std.doc, []); const slice = Slice.fromModels(this.std.store, []);
const job = this.std.getJob(); const job = this.std.getJob();
const snapshot = job.sliceToSnapshot(slice); const snapshot = job.sliceToSnapshot(slice);
if (!snapshot) { if (!snapshot) {
@@ -116,7 +116,7 @@ export class EditPropsStore extends LifeCycleWatcher {
} }
private _getStorageKey<T extends StoragePropsKey>(key: T) { private _getStorageKey<T extends StoragePropsKey>(key: T) {
const id = this.std.doc.id; const id = this.std.store.id;
switch (key) { switch (key) {
case 'viewport': case 'viewport':
return 'blocksuite:' + id + ':edgelessViewport'; return 'blocksuite:' + id + ':edgelessViewport';
@@ -63,7 +63,7 @@ export class ThemeService extends Extension {
const extension = this.std.getOptional(ThemeExtensionIdentifier); const extension = this.std.getOptional(ThemeExtensionIdentifier);
this.app$ = extension?.getAppTheme?.() || getThemeObserver().theme$; this.app$ = extension?.getAppTheme?.() || getThemeObserver().theme$;
this.edgeless$ = this.edgeless$ =
extension?.getEdgelessTheme?.(this.std.doc.id) || extension?.getEdgelessTheme?.(this.std.store.id) ||
getThemeObserver().theme$; getThemeObserver().theme$;
} }
@@ -45,7 +45,7 @@ export function toNumberedList(
model: BlockModel, model: BlockModel,
order: number order: number
) { ) {
const { doc } = std; const { store: doc } = std;
if (!model.text) return; if (!model.text) return;
const parent = doc.getParent(model); const parent = doc.getParent(model);
if (!parent) return; if (!parent) return;
@@ -85,7 +85,7 @@ export class AffineDragHandleWidget extends WidgetComponent<RootBlockModel> {
matchFlavours(this.draggingElements[0].model, ['affine:note']); matchFlavours(this.draggingElements[0].model, ['affine:note']);
if (isDraggedElementNote) { if (isDraggedElementNote) {
const parent = this.std.doc.getParent(closestBlock.model); const parent = this.std.store.getParent(closestBlock.model);
if (!parent) return null; if (!parent) return null;
const parentElement = this._getBlockView(parent.id); const parentElement = this._getBlockView(parent.id);
if (!parentElement) return null; if (!parentElement) return null;
@@ -7,7 +7,7 @@ export const newIdCrossDoc =
let samePage = false; let samePage = false;
slots.beforeImport.on(payload => { slots.beforeImport.on(payload => {
if (payload.type === 'slice') { if (payload.type === 'slice') {
samePage = payload.snapshot.pageId === std.doc.id; samePage = payload.snapshot.pageId === std.store.id;
} }
if (payload.type === 'block' && !samePage) { if (payload.type === 'block' && !samePage) {
payload.snapshot.id = std.workspace.idGenerator(); payload.snapshot.id = std.workspace.idGenerator();
@@ -13,10 +13,10 @@ export const reorderList =
matchFlavours(model, ['affine:list']) && matchFlavours(model, ['affine:list']) &&
model.type === 'numbered' model.type === 'numbered'
) { ) {
const next = std.doc.getNext(model); const next = std.store.getNext(model);
correctNumberedListsOrderToPrev(std.doc, model); correctNumberedListsOrderToPrev(std.store, model);
if (next) { if (next) {
correctNumberedListsOrderToPrev(std.doc, next); correctNumberedListsOrderToPrev(std.store, next);
} }
} }
} }
@@ -15,7 +15,7 @@ export const surfaceRefToEmbed =
pageId && pageId &&
payload.type === 'block' && payload.type === 'block' &&
payload.snapshot.flavour === 'affine:surface-ref' && payload.snapshot.flavour === 'affine:surface-ref' &&
!std.doc.hasBlock(payload.snapshot.id) !std.store.hasBlock(payload.snapshot.id)
) { ) {
const id = payload.snapshot.id; const id = payload.snapshot.id;
payload.snapshot.id = std.workspace.idGenerator(); payload.snapshot.id = std.workspace.idGenerator();
@@ -285,7 +285,7 @@ export class DragEventWatcher {
return; return;
} }
const model = element.model; const model = element.model;
const parent = this._std.doc.getParent(model.id); const parent = this._std.store.getParent(model.id);
if (!parent) return; if (!parent) return;
if (matchFlavours(parent, ['affine:surface'])) { if (matchFlavours(parent, ['affine:surface'])) {
return; return;
@@ -327,11 +327,11 @@ export class DragEventWatcher {
content: first.children, content: first.children,
}; };
job job
.snapshotToSlice(snapshotWithoutNote, std.doc, parent, index) .snapshotToSlice(snapshotWithoutNote, std.store, parent, index)
.then(() => { .then(() => {
const block = std.doc.getBlock(id)?.model; const block = std.store.getBlock(id)?.model;
if (block) { if (block) {
std.doc.deleteBlock(block); std.store.deleteBlock(block);
} }
}) })
.catch(console.error); .catch(console.error);
@@ -363,7 +363,7 @@ export class DragEventWatcher {
const std = this._std; const std = this._std;
const job = this._getJob(); const job = this._getJob();
job job
.snapshotToSlice(snapshot, std.doc, surfaceBlockModel.id) .snapshotToSlice(snapshot, std.store, surfaceBlockModel.id)
.catch(console.error); .catch(console.error);
}; };
@@ -456,7 +456,7 @@ export class DragEventWatcher {
); );
const slice = Slice.fromModels( const slice = Slice.fromModels(
this._std.doc, this._std.store,
blocks.map(block => block.model) blocks.map(block => block.model)
); );
@@ -467,7 +467,7 @@ export class DragEventWatcher {
}; };
private readonly _trackLinkedDocCreated = (id: string) => { private readonly _trackLinkedDocCreated = (id: string) => {
const isNewBlock = !this._std.doc.hasBlock(id); const isNewBlock = !this._std.store.hasBlock(id);
if (!isNewBlock) { if (!isNewBlock) {
return; return;
} }
@@ -517,7 +517,7 @@ export class DragEventWatcher {
// use snapshot // use snapshot
const slice = await job.snapshotToSlice( const slice = await job.snapshotToSlice(
snapshot, snapshot,
std.doc, std.store,
parent, parent,
index index
); );
@@ -287,7 +287,7 @@ export class AffineDocRemoteSelectionWidget extends WidgetComponent {
); );
this.disposables.add( this.disposables.add(
this.std.doc.slots.blockUpdated.on(() => { this.std.store.slots.blockUpdated.on(() => {
this._updateSelections(this._remoteSelections.peek()); this._updateSelections(this._remoteSelections.peek());
}) })
); );
@@ -5,7 +5,7 @@ import { multiPlayersColor } from './color-picker';
export class RemoteColorManager { export class RemoteColorManager {
private get awarenessStore() { private get awarenessStore() {
return this.std.doc.workspace.awarenessStore; return this.std.store.workspace.awarenessStore;
} }
constructor(readonly std: BlockStdScope) { constructor(readonly std: BlockStdScope) {
@@ -108,7 +108,7 @@ export class AffineScrollAnchoringWidget extends WidgetComponent {
// listen for document updates // listen for document updates
this.disposables.add( this.disposables.add(
this.std.doc.slots.blockUpdated this.std.store.slots.blockUpdated
.filter(v => v.type === 'add' && v.id === id) .filter(v => v.type === 'add' && v.id === id)
.once(() => this.#moveToAnchorInEdgeless(id)) .once(() => this.#moveToAnchorInEdgeless(id))
); );
@@ -157,7 +157,7 @@ export class AffineScrollAnchoringWidget extends WidgetComponent {
// listen for document updates // listen for document updates
this.disposables.add( this.disposables.add(
this.std.doc.slots.blockUpdated this.std.store.slots.blockUpdated
.filter(v => v.type === 'add' && v.id === id) .filter(v => v.type === 'add' && v.id === id)
.once(() => this.#moveToAnchorInPage(id)) .once(() => this.#moveToAnchorInPage(id))
); );
@@ -110,7 +110,7 @@ export class ExportManager {
}; };
get doc(): Store { get doc(): Store {
return this.std.doc; return this.std.store;
} }
get editorHost(): EditorHost { get editorHost(): EditorHost {
@@ -60,10 +60,10 @@ export class PageClipboard {
this._std.clipboard.use(copy); this._std.clipboard.use(copy);
this._std.clipboard.use(paste); this._std.clipboard.use(paste);
this._std.clipboard.use( this._std.clipboard.use(
replaceIdMiddleware(this._std.doc.workspace.idGenerator) replaceIdMiddleware(this._std.store.workspace.idGenerator)
); );
this._std.clipboard.use( this._std.clipboard.use(
titleMiddleware(this._std.doc.workspace.meta.docMetas) titleMiddleware(this._std.store.workspace.meta.docMetas)
); );
this._std.clipboard.use(defaultImageProxyMiddleware); this._std.clipboard.use(defaultImageProxyMiddleware);
@@ -85,10 +85,10 @@ export class PageClipboard {
this._std.clipboard.unuse(copy); this._std.clipboard.unuse(copy);
this._std.clipboard.unuse(paste); this._std.clipboard.unuse(paste);
this._std.clipboard.unuse( this._std.clipboard.unuse(
replaceIdMiddleware(this._std.doc.workspace.idGenerator) replaceIdMiddleware(this._std.store.workspace.idGenerator)
); );
this._std.clipboard.unuse( this._std.clipboard.unuse(
titleMiddleware(this._std.doc.workspace.meta.docMetas) titleMiddleware(this._std.store.workspace.meta.docMetas)
); );
this._std.clipboard.unuse(defaultImageProxyMiddleware); this._std.clipboard.unuse(defaultImageProxyMiddleware);
}, },
@@ -138,7 +138,7 @@ export class PageClipboard {
const e = ctx.get('clipboardState').raw; const e = ctx.get('clipboardState').raw;
e.preventDefault(); e.preventDefault();
this._std.doc.captureSync(); this._std.store.captureSync();
this._std.command this._std.command
.chain() .chain()
.try(cmd => [ .try(cmd => [
@@ -188,7 +188,7 @@ export class PageClipboard {
this._std.clipboard this._std.clipboard
.paste( .paste(
e, e,
this._std.doc, this._std.store,
ctx.parentBlock.model.id, ctx.parentBlock.model.id,
ctx.blockIndex ? ctx.blockIndex + 1 : 1 ctx.blockIndex ? ctx.blockIndex + 1 : 1
) )
@@ -317,7 +317,9 @@ export class EdgelessMindmapMenu extends EdgelessToolbarToolMixin(
</div> </div>
`; `;
})} })}
${this.std.doc.get(FeatureFlagService).getFlag('enable_mind_map_import') ${this.std.store
.get(FeatureFlagService)
.getFlag('enable_mind_map_import')
? this._importMindMapEntry() ? this._importMindMapEntry()
: nothing} : nothing}
</div> </div>
@@ -29,7 +29,7 @@ export function addText(gfx: GfxController, event: PointerEventState) {
}); });
gfx.doc.captureSync(); gfx.doc.captureSync();
const textElement = gfx.getElementById(id) as TextElementModel; const textElement = gfx.getElementById(id) as TextElementModel;
const edgelessView = gfx.std.view.getBlock(gfx.std.doc.root!.id); const edgelessView = gfx.std.view.getBlock(gfx.std.store.root!.id);
mountTextElementEditor( mountTextElementEditor(
textElement, textElement,
edgelessView as EdgelessRootBlockComponent edgelessView as EdgelessRootBlockComponent
@@ -41,7 +41,7 @@ export abstract class RootService extends BlockService {
} }
get viewportElement() { get viewportElement() {
const rootId = this.std.doc.root?.id; const rootId = this.std.store.root?.id;
if (!rootId) return null; if (!rootId) return null;
const rootComponent = this.std.view.getBlock( const rootComponent = this.std.view.getBlock(
rootId rootId
@@ -383,10 +383,10 @@ export const BUILT_IN_GROUPS: MenuItemGroup<FormatBarContext>[] = [
ctx.draftedModels ctx.draftedModels
.then(models => { .then(models => {
const slice = Slice.fromModels(ctx.std.doc, models); const slice = Slice.fromModels(ctx.std.store, models);
return ctx.std.clipboard.duplicateSlice( return ctx.std.clipboard.duplicateSlice(
slice, slice,
ctx.std.doc, ctx.std.store,
ctx.parentBlock?.model.id, ctx.parentBlock?.model.id,
ctx.blockIndex ? ctx.blockIndex + 1 : 1 ctx.blockIndex ? ctx.blockIndex + 1 : 1
); );
@@ -155,7 +155,7 @@ const textToolActionItems: KeyboardToolbarActionItem[] = [
name: 'Text', name: 'Text',
icon: TextIcon(), icon: TextIcon(),
showWhen: ({ std }) => showWhen: ({ std }) =>
std.doc.schema.flavourSchemaMap.has('affine:paragraph'), std.store.schema.flavourSchemaMap.has('affine:paragraph'),
action: ({ std }) => { action: ({ std }) => {
std.command.exec('updateBlockType', { std.command.exec('updateBlockType', {
flavour: 'affine:paragraph', flavour: 'affine:paragraph',
@@ -167,7 +167,7 @@ const textToolActionItems: KeyboardToolbarActionItem[] = [
name: `Heading ${i}`, name: `Heading ${i}`,
icon: HeadingIcon(i), icon: HeadingIcon(i),
showWhen: ({ std }: KeyboardToolbarContext) => showWhen: ({ std }: KeyboardToolbarContext) =>
std.doc.schema.flavourSchemaMap.has('affine:paragraph'), std.store.schema.flavourSchemaMap.has('affine:paragraph'),
action: ({ std }: KeyboardToolbarContext) => { action: ({ std }: KeyboardToolbarContext) => {
std.command.exec('updateBlockType', { std.command.exec('updateBlockType', {
flavour: 'affine:paragraph', flavour: 'affine:paragraph',
@@ -177,7 +177,7 @@ const textToolActionItems: KeyboardToolbarActionItem[] = [
})), })),
{ {
name: 'CodeBlock', name: 'CodeBlock',
showWhen: ({ std }) => std.doc.schema.flavourSchemaMap.has('affine:code'), showWhen: ({ std }) => std.store.schema.flavourSchemaMap.has('affine:code'),
icon: CodeBlockIcon(), icon: CodeBlockIcon(),
action: ({ std }) => { action: ({ std }) => {
std.command.exec('updateBlockType', { std.command.exec('updateBlockType', {
@@ -188,7 +188,7 @@ const textToolActionItems: KeyboardToolbarActionItem[] = [
{ {
name: 'Quote', name: 'Quote',
showWhen: ({ std }) => showWhen: ({ std }) =>
std.doc.schema.flavourSchemaMap.has('affine:paragraph'), std.store.schema.flavourSchemaMap.has('affine:paragraph'),
icon: QuoteIcon(), icon: QuoteIcon(),
action: ({ std }) => { action: ({ std }) => {
std.command.exec('updateBlockType', { std.command.exec('updateBlockType', {
@@ -201,7 +201,7 @@ const textToolActionItems: KeyboardToolbarActionItem[] = [
name: 'Divider', name: 'Divider',
icon: DividerIcon(), icon: DividerIcon(),
showWhen: ({ std }) => showWhen: ({ std }) =>
std.doc.schema.flavourSchemaMap.has('affine:divider'), std.store.schema.flavourSchemaMap.has('affine:divider'),
action: ({ std }) => { action: ({ std }) => {
std.command.exec('updateBlockType', { std.command.exec('updateBlockType', {
flavour: 'affine:divider', flavour: 'affine:divider',
@@ -213,7 +213,7 @@ const textToolActionItems: KeyboardToolbarActionItem[] = [
name: 'Inline equation', name: 'Inline equation',
icon: TeXIcon(), icon: TeXIcon(),
showWhen: ({ std }) => showWhen: ({ std }) =>
std.doc.schema.flavourSchemaMap.has('affine:paragraph'), std.store.schema.flavourSchemaMap.has('affine:paragraph'),
action: ({ std }) => { action: ({ std }) => {
std.command.chain().getTextSelection().insertInlineLatex().run(); std.command.chain().getTextSelection().insertInlineLatex().run();
}, },
@@ -224,7 +224,7 @@ const listToolActionItems: KeyboardToolbarActionItem[] = [
{ {
name: 'BulletedList', name: 'BulletedList',
icon: BulletedListIcon(), icon: BulletedListIcon(),
showWhen: ({ std }) => std.doc.schema.flavourSchemaMap.has('affine:list'), showWhen: ({ std }) => std.store.schema.flavourSchemaMap.has('affine:list'),
action: ({ std }) => { action: ({ std }) => {
std.command.exec('updateBlockType', { std.command.exec('updateBlockType', {
flavour: 'affine:list', flavour: 'affine:list',
@@ -237,7 +237,7 @@ const listToolActionItems: KeyboardToolbarActionItem[] = [
{ {
name: 'NumberedList', name: 'NumberedList',
icon: NumberedListIcon(), icon: NumberedListIcon(),
showWhen: ({ std }) => std.doc.schema.flavourSchemaMap.has('affine:list'), showWhen: ({ std }) => std.store.schema.flavourSchemaMap.has('affine:list'),
action: ({ std }) => { action: ({ std }) => {
std.command.exec('updateBlockType', { std.command.exec('updateBlockType', {
flavour: 'affine:list', flavour: 'affine:list',
@@ -250,7 +250,7 @@ const listToolActionItems: KeyboardToolbarActionItem[] = [
{ {
name: 'CheckBox', name: 'CheckBox',
icon: CheckBoxCheckLinearIcon(), icon: CheckBoxCheckLinearIcon(),
showWhen: ({ std }) => std.doc.schema.flavourSchemaMap.has('affine:list'), showWhen: ({ std }) => std.store.schema.flavourSchemaMap.has('affine:list'),
action: ({ std }) => { action: ({ std }) => {
std.command.exec('updateBlockType', { std.command.exec('updateBlockType', {
flavour: 'affine:list', flavour: 'affine:list',
@@ -269,13 +269,13 @@ const pageToolGroup: KeyboardToolPanelGroup = {
name: 'NewPage', name: 'NewPage',
icon: NewPageIcon(), icon: NewPageIcon(),
showWhen: ({ std }) => showWhen: ({ std }) =>
std.doc.schema.flavourSchemaMap.has('affine:embed-linked-doc'), std.store.schema.flavourSchemaMap.has('affine:embed-linked-doc'),
action: ({ std }) => { action: ({ std }) => {
std.command std.command
.chain() .chain()
.getSelectedModels() .getSelectedModels()
.inline(({ selectedModels }) => { .inline(({ selectedModels }) => {
const newDoc = createDefaultDoc(std.doc.workspace); const newDoc = createDefaultDoc(std.store.workspace);
if (!selectedModels?.length) return; if (!selectedModels?.length) return;
insertContent(std.host, selectedModels[0], REFERENCE_NODE, { insertContent(std.host, selectedModels[0], REFERENCE_NODE, {
reference: { reference: {
@@ -297,7 +297,7 @@ const pageToolGroup: KeyboardToolPanelGroup = {
); );
if (!linkedDocWidget) return false; if (!linkedDocWidget) return false;
return std.doc.schema.flavourSchemaMap.has('affine:embed-linked-doc'); return std.store.schema.flavourSchemaMap.has('affine:embed-linked-doc');
}, },
action: ({ rootComponent, closeToolPanel }) => { action: ({ rootComponent, closeToolPanel }) => {
const { std } = rootComponent; const { std } = rootComponent;
@@ -344,7 +344,7 @@ const contentMediaToolGroup: KeyboardToolPanelGroup = {
name: 'Image', name: 'Image',
icon: ImageIcon(), icon: ImageIcon(),
showWhen: ({ std }) => showWhen: ({ std }) =>
std.doc.schema.flavourSchemaMap.has('affine:image'), std.store.schema.flavourSchemaMap.has('affine:image'),
action: ({ std }) => { action: ({ std }) => {
std.command std.command
.chain() .chain()
@@ -357,13 +357,13 @@ const contentMediaToolGroup: KeyboardToolPanelGroup = {
name: 'Link', name: 'Link',
icon: LinkIcon(), icon: LinkIcon(),
showWhen: ({ std }) => showWhen: ({ std }) =>
std.doc.schema.flavourSchemaMap.has('affine:bookmark'), std.store.schema.flavourSchemaMap.has('affine:bookmark'),
action: async ({ std }) => { action: async ({ std }) => {
const { selectedModels } = std.command.exec('getSelectedModels'); const { selectedModels } = std.command.exec('getSelectedModels');
const model = selectedModels?.[0]; const model = selectedModels?.[0];
if (!model) return; if (!model) return;
const parentModel = std.doc.getParent(model); const parentModel = std.store.getParent(model);
if (!parentModel) return; if (!parentModel) return;
const index = parentModel.children.indexOf(model) + 1; const index = parentModel.children.indexOf(model) + 1;
@@ -374,7 +374,7 @@ const contentMediaToolGroup: KeyboardToolPanelGroup = {
{ mode: 'page', parentModel, index } { mode: 'page', parentModel, index }
); );
if (model.text?.length === 0) { if (model.text?.length === 0) {
std.doc.deleteBlock(model); std.store.deleteBlock(model);
} }
}, },
}, },
@@ -382,7 +382,7 @@ const contentMediaToolGroup: KeyboardToolPanelGroup = {
name: 'Attachment', name: 'Attachment',
icon: AttachmentIcon(), icon: AttachmentIcon(),
showWhen: ({ std }) => showWhen: ({ std }) =>
std.doc.schema.flavourSchemaMap.has('affine:attachment'), std.store.schema.flavourSchemaMap.has('affine:attachment'),
action: async ({ std }) => { action: async ({ std }) => {
const { selectedModels } = std.command.exec('getSelectedModels'); const { selectedModels } = std.command.exec('getSelectedModels');
const model = selectedModels?.[0]; const model = selectedModels?.[0];
@@ -397,7 +397,7 @@ const contentMediaToolGroup: KeyboardToolPanelGroup = {
await addSiblingAttachmentBlocks(std.host, [file], maxFileSize, model); await addSiblingAttachmentBlocks(std.host, [file], maxFileSize, model);
if (model.text?.length === 0) { if (model.text?.length === 0) {
std.doc.deleteBlock(model); std.store.deleteBlock(model);
} }
}, },
}, },
@@ -407,13 +407,13 @@ const contentMediaToolGroup: KeyboardToolPanelGroup = {
style: `color: white`, style: `color: white`,
}), }),
showWhen: ({ std }) => showWhen: ({ std }) =>
std.doc.schema.flavourSchemaMap.has('affine:embed-youtube'), std.store.schema.flavourSchemaMap.has('affine:embed-youtube'),
action: async ({ std }) => { action: async ({ std }) => {
const { selectedModels } = std.command.exec('getSelectedModels'); const { selectedModels } = std.command.exec('getSelectedModels');
const model = selectedModels?.[0]; const model = selectedModels?.[0];
if (!model) return; if (!model) return;
const parentModel = std.doc.getParent(model); const parentModel = std.store.getParent(model);
if (!parentModel) return; if (!parentModel) return;
const index = parentModel.children.indexOf(model) + 1; const index = parentModel.children.indexOf(model) + 1;
@@ -424,7 +424,7 @@ const contentMediaToolGroup: KeyboardToolPanelGroup = {
{ mode: 'page', parentModel, index } { mode: 'page', parentModel, index }
); );
if (model.text?.length === 0) { if (model.text?.length === 0) {
std.doc.deleteBlock(model); std.store.deleteBlock(model);
} }
}, },
}, },
@@ -432,13 +432,13 @@ const contentMediaToolGroup: KeyboardToolPanelGroup = {
name: 'Github', name: 'Github',
icon: GithubIcon({ style: `color: black` }), icon: GithubIcon({ style: `color: black` }),
showWhen: ({ std }) => showWhen: ({ std }) =>
std.doc.schema.flavourSchemaMap.has('affine:embed-github'), std.store.schema.flavourSchemaMap.has('affine:embed-github'),
action: async ({ std }) => { action: async ({ std }) => {
const { selectedModels } = std.command.exec('getSelectedModels'); const { selectedModels } = std.command.exec('getSelectedModels');
const model = selectedModels?.[0]; const model = selectedModels?.[0];
if (!model) return; if (!model) return;
const parentModel = std.doc.getParent(model); const parentModel = std.store.getParent(model);
if (!parentModel) return; if (!parentModel) return;
const index = parentModel.children.indexOf(model) + 1; const index = parentModel.children.indexOf(model) + 1;
@@ -449,7 +449,7 @@ const contentMediaToolGroup: KeyboardToolPanelGroup = {
{ mode: 'page', parentModel, index } { mode: 'page', parentModel, index }
); );
if (model.text?.length === 0) { if (model.text?.length === 0) {
std.doc.deleteBlock(model); std.store.deleteBlock(model);
} }
}, },
}, },
@@ -457,13 +457,13 @@ const contentMediaToolGroup: KeyboardToolPanelGroup = {
name: 'Figma', name: 'Figma',
icon: FigmaDuotoneIcon, icon: FigmaDuotoneIcon,
showWhen: ({ std }) => showWhen: ({ std }) =>
std.doc.schema.flavourSchemaMap.has('affine:embed-figma'), std.store.schema.flavourSchemaMap.has('affine:embed-figma'),
action: async ({ std }) => { action: async ({ std }) => {
const { selectedModels } = std.command.exec('getSelectedModels'); const { selectedModels } = std.command.exec('getSelectedModels');
const model = selectedModels?.[0]; const model = selectedModels?.[0];
if (!model) return; if (!model) return;
const parentModel = std.doc.getParent(model); const parentModel = std.store.getParent(model);
if (!parentModel) { if (!parentModel) {
return; return;
} }
@@ -475,7 +475,7 @@ const contentMediaToolGroup: KeyboardToolPanelGroup = {
{ mode: 'page', parentModel, index } { mode: 'page', parentModel, index }
); );
if (model.text?.length === 0) { if (model.text?.length === 0) {
std.doc.deleteBlock(model); std.store.deleteBlock(model);
} }
}, },
}, },
@@ -483,13 +483,13 @@ const contentMediaToolGroup: KeyboardToolPanelGroup = {
name: 'Loom', name: 'Loom',
icon: LoomLogoIcon({ style: `color: #625DF5` }), icon: LoomLogoIcon({ style: `color: #625DF5` }),
showWhen: ({ std }) => showWhen: ({ std }) =>
std.doc.schema.flavourSchemaMap.has('affine:embed-loom'), std.store.schema.flavourSchemaMap.has('affine:embed-loom'),
action: async ({ std }) => { action: async ({ std }) => {
const { selectedModels } = std.command.exec('getSelectedModels'); const { selectedModels } = std.command.exec('getSelectedModels');
const model = selectedModels?.[0]; const model = selectedModels?.[0];
if (!model) return; if (!model) return;
const parentModel = std.doc.getParent(model); const parentModel = std.store.getParent(model);
if (!parentModel) return; if (!parentModel) return;
const index = parentModel.children.indexOf(model) + 1; const index = parentModel.children.indexOf(model) + 1;
@@ -500,7 +500,7 @@ const contentMediaToolGroup: KeyboardToolPanelGroup = {
{ mode: 'page', parentModel, index } { mode: 'page', parentModel, index }
); );
if (model.text?.length === 0) { if (model.text?.length === 0) {
std.doc.deleteBlock(model); std.store.deleteBlock(model);
} }
}, },
}, },
@@ -508,7 +508,7 @@ const contentMediaToolGroup: KeyboardToolPanelGroup = {
name: 'Equation', name: 'Equation',
icon: TeXIcon(), icon: TeXIcon(),
showWhen: ({ std }) => showWhen: ({ std }) =>
std.doc.schema.flavourSchemaMap.has('affine:latex'), std.store.schema.flavourSchemaMap.has('affine:latex'),
action: ({ std }) => { action: ({ std }) => {
std.command std.command
.chain() .chain()
@@ -526,9 +526,9 @@ const contentMediaToolGroup: KeyboardToolPanelGroup = {
const documentGroupFrameToolGroup: DynamicKeyboardToolPanelGroup = ({ const documentGroupFrameToolGroup: DynamicKeyboardToolPanelGroup = ({
std, std,
}) => { }) => {
const { doc } = std; const { store } = std;
const frameModels = doc const frameModels = store
.getBlocksByFlavour('affine:frame') .getBlocksByFlavour('affine:frame')
.map(block => block.model) as FrameBlockModel[]; .map(block => block.model) as FrameBlockModel[];
@@ -548,7 +548,7 @@ const documentGroupFrameToolGroup: DynamicKeyboardToolPanelGroup = ({
}, },
})); }));
const surfaceModel = getSurfaceBlock(doc); const surfaceModel = getSurfaceBlock(store);
const groupElements = surfaceModel const groupElements = surfaceModel
? surfaceModel.getElementsByType('group') ? surfaceModel.getElementsByType('group')
@@ -641,7 +641,7 @@ const databaseToolGroup: KeyboardToolPanelGroup = {
name: 'Table view', name: 'Table view',
icon: DatabaseTableViewIcon(), icon: DatabaseTableViewIcon(),
showWhen: ({ std }) => showWhen: ({ std }) =>
std.doc.schema.flavourSchemaMap.has('affine:database'), std.store.schema.flavourSchemaMap.has('affine:database'),
action: ({ std }) => { action: ({ std }) => {
std.command std.command
.chain() .chain()
@@ -658,7 +658,7 @@ const databaseToolGroup: KeyboardToolPanelGroup = {
name: 'Kanban view', name: 'Kanban view',
icon: DatabaseKanbanViewIcon(), icon: DatabaseKanbanViewIcon(),
showWhen: ({ std }) => showWhen: ({ std }) =>
std.doc.schema.flavourSchemaMap.has('affine:database'), std.store.schema.flavourSchemaMap.has('affine:database'),
action: ({ std }) => { action: ({ std }) => {
std.command std.command
.chain() .chain()
@@ -896,7 +896,7 @@ export const defaultKeyboardToolbarConfig: KeyboardToolbarConfig = {
name: 'Image', name: 'Image',
icon: ImageIcon(), icon: ImageIcon(),
showWhen: ({ std }) => showWhen: ({ std }) =>
std.doc.schema.flavourSchemaMap.has('affine:image'), std.store.schema.flavourSchemaMap.has('affine:image'),
action: ({ std }) => { action: ({ std }) => {
std.command std.command
.chain() .chain()
@@ -909,7 +909,7 @@ export const defaultKeyboardToolbarConfig: KeyboardToolbarConfig = {
name: 'Attachment', name: 'Attachment',
icon: AttachmentIcon(), icon: AttachmentIcon(),
showWhen: ({ std }) => showWhen: ({ std }) =>
std.doc.schema.flavourSchemaMap.has('affine:attachment'), std.store.schema.flavourSchemaMap.has('affine:attachment'),
action: async ({ std }) => { action: async ({ std }) => {
const { selectedModels } = std.command.exec('getSelectedModels'); const { selectedModels } = std.command.exec('getSelectedModels');
const model = selectedModels?.[0]; const model = selectedModels?.[0];
@@ -924,24 +924,24 @@ export const defaultKeyboardToolbarConfig: KeyboardToolbarConfig = {
await addSiblingAttachmentBlocks(std.host, [file], maxFileSize, model); await addSiblingAttachmentBlocks(std.host, [file], maxFileSize, model);
if (model.text?.length === 0) { if (model.text?.length === 0) {
std.doc.deleteBlock(model); std.store.deleteBlock(model);
} }
}, },
}, },
{ {
name: 'Undo', name: 'Undo',
icon: UndoIcon(), icon: UndoIcon(),
disableWhen: ({ std }) => !std.doc.canUndo, disableWhen: ({ std }) => !std.store.canUndo,
action: ({ std }) => { action: ({ std }) => {
std.doc.undo(); std.store.undo();
}, },
}, },
{ {
name: 'Redo', name: 'Redo',
icon: RedoIcon(), icon: RedoIcon(),
disableWhen: ({ std }) => !std.doc.canRedo, disableWhen: ({ std }) => !std.store.canRedo,
action: ({ std }) => { action: ({ std }) => {
std.doc.redo(); std.store.redo();
}, },
}, },
{ {
@@ -673,7 +673,7 @@ export const defaultSlashMenuConfig: SlashMenuConfig = {
icon: CopyIcon, icon: CopyIcon,
tooltip: slashMenuToolTips['Copy'], tooltip: slashMenuToolTips['Copy'],
action: ({ rootComponent, model }) => { action: ({ rootComponent, model }) => {
const slice = Slice.fromModels(rootComponent.std.doc, [model]); const slice = Slice.fromModels(rootComponent.std.store, [model]);
rootComponent.std.clipboard rootComponent.std.clipboard
.copy(slice) .copy(slice)
@@ -350,7 +350,7 @@ export class UIEventDispatcher extends LifeCycleWatcher {
); );
const flavourHandlers = blockIds const flavourHandlers = blockIds
.map(blockId => this.std.doc.getBlock(blockId)?.flavour) .map(blockId => this.std.store.getBlock(blockId)?.flavour)
.filter((flavour): flavour is string => { .filter((flavour): flavour is string => {
if (!flavour) return false; if (!flavour) return false;
if (flavourSeen[flavour]) return false; if (flavourSeen[flavour]) return false;
@@ -364,7 +364,7 @@ export class UIEventDispatcher extends LifeCycleWatcher {
events.push(...idHandlers, ...flavourHandlers); events.push(...idHandlers, ...flavourHandlers);
blockIds = blockIds blockIds = blockIds
.map(blockId => { .map(blockId => {
const parent = this.std.doc.getParent(blockId); const parent = this.std.store.getParent(blockId);
return parent?.id; return parent?.id;
}) })
.filter((id): id is string => !!id); .filter((id): id is string => !!id);
@@ -34,7 +34,7 @@ export abstract class BlockService extends Extension {
} }
get doc() { get doc() {
return this.std.doc; return this.std.store;
} }
get host() { get host() {
@@ -50,7 +50,7 @@ export class GfxController extends LifeCycleWatcher {
readonly viewport: Viewport = new Viewport(); readonly viewport: Viewport = new Viewport();
get doc() { get doc() {
return this.std.doc; return this.std.store;
} }
get elementsBound() { get elementsBound() {
@@ -316,7 +316,7 @@ export class GfxSelectionManager extends GfxExtension {
} }
const { blocks = [], elements = [] } = groupBy(selection.elements, id => { const { blocks = [], elements = [] } = groupBy(selection.elements, id => {
return this.std.doc.getBlockById(id) ? 'blocks' : 'elements'; return this.std.store.getBlockById(id) ? 'blocks' : 'elements';
}); });
let instances: (SurfaceSelection | CursorSelection)[] = []; let instances: (SurfaceSelection | CursorSelection)[] = [];
@@ -51,7 +51,7 @@ export class SurfaceMiddlewareExtension extends LifeCycleWatcher {
this.std.provider.getAll(SurfaceMiddlewareBuilderIdentifier).values() this.std.provider.getAll(SurfaceMiddlewareBuilderIdentifier).values()
); );
const dispose = onSurfaceAdded(this.std.doc, surface => { const dispose = onSurfaceAdded(this.std.store, surface => {
if (surface) { if (surface) {
surface.applyMiddlewares(builders.map(builder => builder.middleware)); surface.applyMiddlewares(builders.map(builder => builder.middleware));
queueMicrotask(() => dispose()); queueMicrotask(() => dispose());
@@ -107,7 +107,7 @@ export class ViewManager extends GfxExtension {
updateViewOnElementChange(this.gfx.surface); updateViewOnElementChange(this.gfx.surface);
} else { } else {
this._disposable.add( this._disposable.add(
onSurfaceAdded(this.std.doc, surface => { onSurfaceAdded(this.std.store, surface => {
if (surface) { if (surface) {
updateViewOnElementChange(surface); updateViewOnElementChange(surface);
} }
@@ -16,7 +16,7 @@ export class RangeBinding {
| null = null; | null = null;
private readonly _computePath = (modelId: string) => { private readonly _computePath = (modelId: string) => {
const block = this.host.std.doc.getBlock(modelId)?.model; const block = this.host.std.store.getBlock(modelId)?.model;
if (!block) return []; if (!block) return [];
const path: string[] = []; const path: string[] = [];
@@ -74,16 +74,12 @@ export class BlockStdScope {
return this.provider.getAll(LifeCycleWatcherIdentifier); return this.provider.getAll(LifeCycleWatcherIdentifier);
} }
get doc() {
return this.store;
}
get clipboard() { get clipboard() {
return this.get(Clipboard); return this.get(Clipboard);
} }
get workspace() { get workspace() {
return this.doc.workspace; return this.store.workspace;
} }
get command() { get command() {
@@ -198,7 +194,7 @@ export class BlockStdScope {
render() { render() {
const element = new EditorHost(); const element = new EditorHost();
element.std = this; element.std = this;
element.doc = this.doc; element.doc = this.store;
this._getHost = () => element; this._getHost = () => element;
this._lifeCycleWatchers.forEach(watcher => { this._lifeCycleWatchers.forEach(watcher => {
watcher.rendered.call(watcher); watcher.rendered.call(watcher);
@@ -76,7 +76,7 @@ export class SelectionManager extends LifeCycleWatcher {
constructor(std: BlockStdScope) { constructor(std: BlockStdScope) {
super(std); super(std);
this._id = `${this.std.doc.id}:${nanoid()}`; this._id = `${this.std.store.id}:${nanoid()}`;
this._setupDefaultSelections(); this._setupDefaultSelections();
this._store.awareness.on( this._store.awareness.on(
'change', 'change',
@@ -100,7 +100,7 @@ export class SelectionManager extends LifeCycleWatcher {
if (id === this._store.awareness.clientID) return; if (id === this._store.awareness.clientID) return;
// selection id starts with the same block collection id from others clients would be considered as remote selections // selection id starts with the same block collection id from others clients would be considered as remote selections
const selection = Object.entries(state.selectionV2) const selection = Object.entries(state.selectionV2)
.filter(([key]) => key.startsWith(this.std.doc.id)) .filter(([key]) => key.startsWith(this.std.store.id))
.flatMap(([_, selection]) => selection); .flatMap(([_, selection]) => selection);
const selections = selection const selections = selection
@@ -191,8 +191,8 @@ export class SelectionManager extends LifeCycleWatcher {
if (this.disposables.disposed) { if (this.disposables.disposed) {
this.disposables = new DisposableGroup(); this.disposables = new DisposableGroup();
} }
this.std.doc.history.on('stack-item-added', this._itemAdded); this.std.store.history.on('stack-item-added', this._itemAdded);
this.std.doc.history.on('stack-item-popped', this._itemPopped); this.std.store.history.on('stack-item-popped', this._itemPopped);
this.disposables.add( this.disposables.add(
this._store.slots.update.on(({ id }) => { this._store.slots.update.on(({ id }) => {
if (id === this._store.awareness.clientID) { if (id === this._store.awareness.clientID) {
@@ -224,8 +224,8 @@ export class SelectionManager extends LifeCycleWatcher {
} }
override unmounted() { override unmounted() {
this.std.doc.history.off('stack-item-added', this._itemAdded); this.std.store.history.off('stack-item-added', this._itemAdded);
this.std.doc.history.off('stack-item-popped', this._itemPopped); this.std.store.history.off('stack-item-popped', this._itemPopped);
this.slots.changed.dispose(); this.slots.changed.dispose();
this.disposables.dispose(); this.disposables.dispose();
this.clear(); this.clear();
@@ -218,7 +218,7 @@ export class BlockComponent<
this.std.view.setBlock(this); this.std.view.setBlock(this);
const disposable = this.std.doc.slots.blockUpdated.on(({ type, id }) => { const disposable = this.std.store.slots.blockUpdated.on(({ type, id }) => {
if (id === this.model.id && type === 'delete') { if (id === this.model.id && type === 'delete') {
this.std.view.deleteBlock(this); this.std.view.deleteBlock(this);
disposable.dispose(); disposable.dispose();
@@ -9,7 +9,7 @@ export class ViewStore extends LifeCycleWatcher {
private readonly _fromId = ( private readonly _fromId = (
blockId: string | undefined | null blockId: string | undefined | null
): BlockComponent | null => { ): BlockComponent | null => {
const id = blockId ?? this.std.doc.root?.id; const id = blockId ?? this.std.store.root?.id;
if (!id) { if (!id) {
return null; return null;
} }
@@ -194,7 +194,7 @@ export class TextRenderer extends WithDisposable(ShadowlessElement) {
if (this._answers.length > 0) { if (this._answers.length > 0) {
const latestAnswer = this._answers.pop(); const latestAnswer = this._answers.pop();
this._answers = []; this._answers = [];
const schema = this.schema ?? this.host?.std.doc.workspace.schema; const schema = this.schema ?? this.host?.std.store.workspace.schema;
let provider: ServiceProvider; let provider: ServiceProvider;
if (this.host) { if (this.host) {
provider = this.host.std.provider; provider = this.host.std.provider;
@@ -80,15 +80,15 @@ export async function getContentFromSlice(
type: 'markdown' | 'plain-text' = 'markdown' type: 'markdown' | 'plain-text' = 'markdown'
) { ) {
const job = new Job({ const job = new Job({
schema: host.std.doc.workspace.schema, schema: host.std.store.workspace.schema,
blobCRUD: host.std.doc.workspace.blobSync, blobCRUD: host.std.store.workspace.blobSync,
docCRUD: { docCRUD: {
create: (id: string) => host.std.doc.workspace.createDoc({ id }), create: (id: string) => host.std.store.workspace.createDoc({ id }),
get: (id: string) => host.std.doc.workspace.getDoc(id), get: (id: string) => host.std.store.workspace.getDoc(id),
delete: (id: string) => host.std.doc.workspace.removeDoc(id), delete: (id: string) => host.std.store.workspace.removeDoc(id),
}, },
middlewares: [ middlewares: [
titleMiddleware(host.std.doc.workspace.meta.docMetas), titleMiddleware(host.std.store.workspace.meta.docMetas),
embedSyncedDocMiddleware('content'), embedSyncedDocMiddleware('content'),
], ],
}); });
@@ -110,14 +110,14 @@ export async function getContentFromSlice(
export async function getPlainTextFromSlice(host: EditorHost, slice: Slice) { export async function getPlainTextFromSlice(host: EditorHost, slice: Slice) {
const job = new Job({ const job = new Job({
schema: host.std.doc.workspace.schema, schema: host.std.store.workspace.schema,
blobCRUD: host.std.doc.workspace.blobSync, blobCRUD: host.std.store.workspace.blobSync,
docCRUD: { docCRUD: {
create: (id: string) => host.std.doc.workspace.createDoc({ id }), create: (id: string) => host.std.store.workspace.createDoc({ id }),
get: (id: string) => host.std.doc.workspace.getDoc(id), get: (id: string) => host.std.store.workspace.getDoc(id),
delete: (id: string) => host.std.doc.workspace.removeDoc(id), delete: (id: string) => host.std.store.workspace.removeDoc(id),
}, },
middlewares: [titleMiddleware(host.std.doc.workspace.meta.docMetas)], middlewares: [titleMiddleware(host.std.store.workspace.meta.docMetas)],
}); });
const snapshot = job.sliceToSnapshot(slice); const snapshot = job.sliceToSnapshot(slice);
if (!snapshot) { if (!snapshot) {
@@ -137,12 +137,12 @@ export const markdownToSnapshot = async (
host: EditorHost host: EditorHost
) => { ) => {
const job = new Job({ const job = new Job({
schema: host.std.doc.workspace.schema, schema: host.std.store.workspace.schema,
blobCRUD: host.std.doc.workspace.blobSync, blobCRUD: host.std.store.workspace.blobSync,
docCRUD: { docCRUD: {
create: (id: string) => host.std.doc.workspace.createDoc({ id }), create: (id: string) => host.std.store.workspace.createDoc({ id }),
get: (id: string) => host.std.doc.workspace.getDoc(id), get: (id: string) => host.std.store.workspace.getDoc(id),
delete: (id: string) => host.std.doc.workspace.removeDoc(id), delete: (id: string) => host.std.store.workspace.removeDoc(id),
}, },
middlewares: [defaultImageProxyMiddleware, pasteMiddleware(host.std)], middlewares: [defaultImageProxyMiddleware, pasteMiddleware(host.std)],
}); });
@@ -150,8 +150,8 @@ export const markdownToSnapshot = async (
const payload = { const payload = {
file: markdown, file: markdown,
assets: job.assetsManager, assets: job.assetsManager,
workspaceId: host.std.doc.workspace.id, workspaceId: host.std.store.workspace.id,
pageId: host.std.doc.id, pageId: host.std.store.id,
}; };
const snapshot = await markdownAdapter.toSliceSnapshot(payload); const snapshot = await markdownAdapter.toSliceSnapshot(payload);
@@ -147,7 +147,7 @@ export const copyTextAnswer = async (panel: AffineAIPanelWidget) => {
export const copyText = async (host: EditorHost, text: string) => { export const copyText = async (host: EditorHost, text: string) => {
const previewDoc = await markDownToDoc( const previewDoc = await markDownToDoc(
host.std.provider, host.std.provider,
host.std.doc.schema, host.std.store.schema,
text text
); );
const models = previewDoc const models = previewDoc
@@ -124,7 +124,7 @@ export async function getTextContentFromBlockModels(
); );
const drafts = selectedTextModels.map(toDraftModel); const drafts = selectedTextModels.map(toDraftModel);
drafts.forEach(draft => traverse(draft, drafts)); drafts.forEach(draft => traverse(draft, drafts));
const slice = Slice.fromModels(editorHost.std.doc, drafts); const slice = Slice.fromModels(editorHost.std.store, drafts);
return getContentFromSlice(editorHost, slice, type); return getContentFromSlice(editorHost, slice, type);
} }