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

This commit is contained in:
Saul-Mirone
2025-01-09 04:16:28 +00:00
parent 58ce86533e
commit d21ef47ae8
89 changed files with 359 additions and 348 deletions

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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;
}

View File

@@ -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,

View File

@@ -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']) &&

View File

@@ -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>);
}

View File

@@ -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,
});
}