mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
chore(editor): rename std.doc to std.store (#9596)
This commit is contained in:
@@ -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 => {
|
||||
|
||||
Reference in New Issue
Block a user