mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-09 21:25:45 +08:00
45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
import { getSelectedModelsCommand } from '@blocksuite/affine-shared/commands';
|
|
import { TelemetryProvider } from '@blocksuite/affine-shared/services';
|
|
import { isInsideBlockByFlavour } from '@blocksuite/affine-shared/utils';
|
|
import type { SlashMenuConfig } from '@blocksuite/affine-widget-slash-menu';
|
|
import { TableIcon } from '@blocksuite/icons/lit';
|
|
|
|
import { insertTableBlockCommand } from '../commands';
|
|
import { tableTooltip } from './tooltips';
|
|
|
|
export const tableSlashMenuConfig: SlashMenuConfig = {
|
|
disableWhen: ({ model }) => model.flavour === 'affine:table',
|
|
items: [
|
|
{
|
|
name: 'Table',
|
|
description: 'Create a simple table.',
|
|
icon: TableIcon(),
|
|
tooltip: {
|
|
figure: tableTooltip,
|
|
caption: 'Table',
|
|
},
|
|
group: '4_Content & Media@0',
|
|
when: ({ model }) =>
|
|
!isInsideBlockByFlavour(model.store, model, 'affine:edgeless-text'),
|
|
action: ({ std }) => {
|
|
std.command
|
|
.chain()
|
|
.pipe(getSelectedModelsCommand)
|
|
.pipe(insertTableBlockCommand, {
|
|
place: 'after',
|
|
removeEmptyLine: true,
|
|
})
|
|
.pipe(({ insertedTableBlockId }) => {
|
|
if (insertedTableBlockId) {
|
|
const telemetry = std.getOptional(TelemetryProvider);
|
|
telemetry?.track('BlockCreated', {
|
|
blockType: 'affine:table',
|
|
});
|
|
}
|
|
})
|
|
.run();
|
|
},
|
|
},
|
|
],
|
|
};
|