mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-08 20:57:08 +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');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user