mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-03 18:40:00 +08:00
1f45cc5dec
**Directory Structure Changes** - Renamed multiple block-related directories by removing the "block-" prefix: - `block-attachment` → `attachment` - `block-bookmark` → `bookmark` - `block-callout` → `callout` - `block-code` → `code` - `block-data-view` → `data-view` - `block-database` → `database` - `block-divider` → `divider` - `block-edgeless-text` → `edgeless-text` - `block-embed` → `embed`
39 lines
1012 B
TypeScript
39 lines
1012 B
TypeScript
import { NoteBlockModel } from '@blocksuite/affine-model';
|
|
import { matchModels } from '@blocksuite/affine-shared/utils';
|
|
import type { Command } from '@blocksuite/std';
|
|
|
|
import { dedentBlock } from './dedent-block';
|
|
|
|
export const dedentBlockToRoot: Command<{
|
|
blockId?: string;
|
|
stopCapture?: boolean;
|
|
}> = (ctx, next) => {
|
|
let { blockId } = ctx;
|
|
const { std, stopCapture = true } = ctx;
|
|
const { store } = std;
|
|
if (!blockId) {
|
|
const sel = std.selection.getGroup('note').at(0);
|
|
blockId = sel?.blockId;
|
|
}
|
|
if (!blockId) return;
|
|
const model = std.store.getBlock(blockId)?.model;
|
|
if (!model) return;
|
|
|
|
let parent = store.getParent(model);
|
|
let changed = false;
|
|
while (parent && !matchModels(parent, [NoteBlockModel])) {
|
|
if (!changed) {
|
|
if (stopCapture) store.captureSync();
|
|
changed = true;
|
|
}
|
|
std.command.exec(dedentBlock, { blockId: model.id, stopCapture: true });
|
|
parent = store.getParent(model);
|
|
}
|
|
|
|
if (!changed) {
|
|
return;
|
|
}
|
|
|
|
return next();
|
|
};
|