mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-09 21:25:45 +08:00
refactor(editor): unify directories naming (#11516)
**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`
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import {
|
||||
type TableBlockModel,
|
||||
TableModelFlavour,
|
||||
} from '@blocksuite/affine-model';
|
||||
import type { Command } from '@blocksuite/std';
|
||||
import { type BlockModel } from '@blocksuite/store';
|
||||
|
||||
import { TableDataManager } from './table-data-manager';
|
||||
|
||||
export const insertTableBlockCommand: Command<
|
||||
{
|
||||
place?: 'after' | 'before';
|
||||
removeEmptyLine?: boolean;
|
||||
selectedModels?: BlockModel[];
|
||||
},
|
||||
{
|
||||
insertedTableBlockId: string;
|
||||
}
|
||||
> = (ctx, next) => {
|
||||
const { selectedModels, place, removeEmptyLine, std } = ctx;
|
||||
if (!selectedModels?.length) return;
|
||||
|
||||
const targetModel =
|
||||
place === 'before'
|
||||
? selectedModels[0]
|
||||
: selectedModels[selectedModels.length - 1];
|
||||
|
||||
if (!targetModel) return;
|
||||
|
||||
const result = std.store.addSiblingBlocks(
|
||||
targetModel,
|
||||
[{ flavour: TableModelFlavour }],
|
||||
place
|
||||
);
|
||||
const blockId = result[0];
|
||||
|
||||
if (blockId == null) return;
|
||||
|
||||
const model = std.store.getBlock(blockId)?.model as TableBlockModel;
|
||||
if (model == null) return;
|
||||
|
||||
const dataManager = new TableDataManager(model);
|
||||
|
||||
dataManager.addNRow(2);
|
||||
dataManager.addNColumn(2);
|
||||
|
||||
if (removeEmptyLine && targetModel.text?.length === 0) {
|
||||
std.store.deleteBlock(targetModel);
|
||||
}
|
||||
|
||||
next({ insertedTableBlockId: blockId });
|
||||
};
|
||||
Reference in New Issue
Block a user