diff --git a/blocksuite/affine/block-table/package.json b/blocksuite/affine/block-table/package.json index a7b566d42e..11ec3dc5cc 100644 --- a/blocksuite/affine/block-table/package.json +++ b/blocksuite/affine/block-table/package.json @@ -18,6 +18,7 @@ "@blocksuite/affine-model": "workspace:*", "@blocksuite/affine-rich-text": "workspace:*", "@blocksuite/affine-shared": "workspace:*", + "@blocksuite/affine-widget-slash-menu": "workspace:*", "@blocksuite/block-std": "workspace:*", "@blocksuite/data-view": "workspace:*", "@blocksuite/global": "workspace:*", diff --git a/blocksuite/affine/block-table/src/commands.ts b/blocksuite/affine/block-table/src/commands.ts index 8548bb8be2..5dfeaffa81 100644 --- a/blocksuite/affine/block-table/src/commands.ts +++ b/blocksuite/affine/block-table/src/commands.ts @@ -44,8 +44,8 @@ export const insertTableBlockCommand: Command< dataManager.addNRow(2); dataManager.addNColumn(2); - if (removeEmptyLine && model.text?.length === 0) { - std.store.deleteBlock(model); + if (removeEmptyLine && targetModel.text?.length === 0) { + std.store.deleteBlock(targetModel); } next({ insertedTableBlockId: blockId }); diff --git a/blocksuite/affine/block-table/src/configs/slash-menu.ts b/blocksuite/affine/block-table/src/configs/slash-menu.ts new file mode 100644 index 0000000000..b6cd24f82e --- /dev/null +++ b/blocksuite/affine/block-table/src/configs/slash-menu.ts @@ -0,0 +1,39 @@ +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'; + +export const tableSlashMenuConfig: SlashMenuConfig = { + disableWhen: ({ model }) => model.flavour === 'affine:table', + items: [ + { + name: 'Table', + description: 'Create a simple table.', + icon: TableIcon(), + group: '4_Content & Media@0', + when: ({ model }) => + !isInsideBlockByFlavour(model.doc, 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(); + }, + }, + ], +}; diff --git a/blocksuite/affine/block-table/src/table-spec.ts b/blocksuite/affine/block-table/src/table-spec.ts index b2d1e39231..134310f329 100644 --- a/blocksuite/affine/block-table/src/table-spec.ts +++ b/blocksuite/affine/block-table/src/table-spec.ts @@ -1,12 +1,15 @@ import { TableModelFlavour } from '@blocksuite/affine-model'; +import { SlashMenuConfigExtension } from '@blocksuite/affine-widget-slash-menu'; import { BlockViewExtension, FlavourExtension } from '@blocksuite/block-std'; import type { ExtensionType } from '@blocksuite/store'; import { literal } from 'lit/static-html.js'; import { TableBlockAdapterExtensions } from './adapters/extension.js'; +import { tableSlashMenuConfig } from './configs/slash-menu.js'; export const TableBlockSpec: ExtensionType[] = [ FlavourExtension(TableModelFlavour), BlockViewExtension(TableModelFlavour, literal`affine-table`), TableBlockAdapterExtensions, + SlashMenuConfigExtension(TableModelFlavour, tableSlashMenuConfig), ].flat(); diff --git a/blocksuite/affine/block-table/tsconfig.json b/blocksuite/affine/block-table/tsconfig.json index 6e6d4588bd..0c13dc513c 100644 --- a/blocksuite/affine/block-table/tsconfig.json +++ b/blocksuite/affine/block-table/tsconfig.json @@ -12,6 +12,7 @@ { "path": "../model" }, { "path": "../rich-text" }, { "path": "../shared" }, + { "path": "../widget-slash-menu" }, { "path": "../../framework/block-std" }, { "path": "../data-view" }, { "path": "../../framework/global" }, diff --git a/blocksuite/affine/widget-slash-menu/package.json b/blocksuite/affine/widget-slash-menu/package.json index a95f0552c7..d88bb24d4e 100644 --- a/blocksuite/affine/widget-slash-menu/package.json +++ b/blocksuite/affine/widget-slash-menu/package.json @@ -20,7 +20,6 @@ "@blocksuite/affine-block-note": "workspace:*", "@blocksuite/affine-block-surface": "workspace:*", "@blocksuite/affine-block-surface-ref": "workspace:*", - "@blocksuite/affine-block-table": "workspace:*", "@blocksuite/affine-components": "workspace:*", "@blocksuite/affine-rich-text": "workspace:*", "@blocksuite/affine-shared": "workspace:*", diff --git a/blocksuite/affine/widget-slash-menu/src/config.ts b/blocksuite/affine/widget-slash-menu/src/config.ts index 1d7afd1a52..47571b27b9 100644 --- a/blocksuite/affine/widget-slash-menu/src/config.ts +++ b/blocksuite/affine/widget-slash-menu/src/config.ts @@ -3,7 +3,6 @@ import { insertImagesCommand } from '@blocksuite/affine-block-image'; import { insertLatexBlockCommand } from '@blocksuite/affine-block-latex'; import { getSurfaceBlock } from '@blocksuite/affine-block-surface'; import { insertSurfaceRefBlockCommand } from '@blocksuite/affine-block-surface-ref'; -import { insertTableBlockCommand } from '@blocksuite/affine-block-table'; import { toggleEmbedCardCreateModal } from '@blocksuite/affine-components/embed-card-modal'; import { toast } from '@blocksuite/affine-components/toast'; import type { @@ -22,10 +21,7 @@ import { getTextSelectionCommand, } from '@blocksuite/affine-shared/commands'; import { REFERENCE_NODE } from '@blocksuite/affine-shared/consts'; -import { - FileSizeLimitService, - TelemetryProvider, -} from '@blocksuite/affine-shared/services'; +import { FileSizeLimitService } from '@blocksuite/affine-shared/services'; import { createDefaultDoc, openFileOrFiles, @@ -49,7 +45,6 @@ import { LoomLogoDuotoneIcon, NowIcon, PlusIcon, - TableIcon, TeXIcon, TodayIcon, TomorrowIcon, @@ -195,32 +190,6 @@ export const defaultSlashMenuConfig: SlashMenuConfig = { // --------------------------------------------------------- // { groupName: 'Content & Media' }, - { - name: 'Table', - description: 'Create a simple table.', - icon: TableIcon(), - tooltip: slashMenuToolTips['Table View'], - group: `4_Content & Media@${index++}`, - when: ({ model }) => !insideEdgelessText(model), - 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(); - }, - }, { name: 'Image', description: 'Insert an image.', diff --git a/blocksuite/affine/widget-slash-menu/tsconfig.json b/blocksuite/affine/widget-slash-menu/tsconfig.json index 359b2ff5f0..2c607f862c 100644 --- a/blocksuite/affine/widget-slash-menu/tsconfig.json +++ b/blocksuite/affine/widget-slash-menu/tsconfig.json @@ -14,7 +14,6 @@ { "path": "../block-note" }, { "path": "../block-surface" }, { "path": "../block-surface-ref" }, - { "path": "../block-table" }, { "path": "../components" }, { "path": "../rich-text" }, { "path": "../shared" }, diff --git a/tools/utils/src/workspace.gen.ts b/tools/utils/src/workspace.gen.ts index ba2c339ec4..9a868b04be 100644 --- a/tools/utils/src/workspace.gen.ts +++ b/tools/utils/src/workspace.gen.ts @@ -308,6 +308,7 @@ export const PackageList = [ 'blocksuite/affine/model', 'blocksuite/affine/rich-text', 'blocksuite/affine/shared', + 'blocksuite/affine/widget-slash-menu', 'blocksuite/framework/block-std', 'blocksuite/affine/data-view', 'blocksuite/framework/global', @@ -494,7 +495,6 @@ export const PackageList = [ 'blocksuite/affine/block-note', 'blocksuite/affine/block-surface', 'blocksuite/affine/block-surface-ref', - 'blocksuite/affine/block-table', 'blocksuite/affine/components', 'blocksuite/affine/rich-text', 'blocksuite/affine/shared', diff --git a/yarn.lock b/yarn.lock index 331315520a..e12dfae01a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2711,6 +2711,7 @@ __metadata: "@blocksuite/affine-model": "workspace:*" "@blocksuite/affine-rich-text": "workspace:*" "@blocksuite/affine-shared": "workspace:*" + "@blocksuite/affine-widget-slash-menu": "workspace:*" "@blocksuite/block-std": "workspace:*" "@blocksuite/data-view": "workspace:*" "@blocksuite/global": "workspace:*" @@ -3038,7 +3039,6 @@ __metadata: "@blocksuite/affine-block-note": "workspace:*" "@blocksuite/affine-block-surface": "workspace:*" "@blocksuite/affine-block-surface-ref": "workspace:*" - "@blocksuite/affine-block-table": "workspace:*" "@blocksuite/affine-components": "workspace:*" "@blocksuite/affine-rich-text": "workspace:*" "@blocksuite/affine-shared": "workspace:*"