mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-01 01:29:31 +08:00
chore(editor): rename std.doc to std.store (#9596)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user