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