diff --git a/packages/blocks/src/__tests__/database/database.unit.spec.ts b/packages/blocks/src/__tests__/database/database.unit.spec.ts index 9af1cdf4b887..c8dc4063d1e8 100644 --- a/packages/blocks/src/__tests__/database/database.unit.spec.ts +++ b/packages/blocks/src/__tests__/database/database.unit.spec.ts @@ -1,17 +1,16 @@ -/* eslint-disable @typescript-eslint/no-restricted-imports */ -import '../../database-block/kanban/define.js'; -import '../../database-block/table/define.js'; - import type { BlockModel, Doc } from '@blocksuite/store'; import { DocCollection, Generator, Schema } from '@blocksuite/store'; import { beforeEach, describe, expect, test } from 'vitest'; -import { numberPureColumnConfig } from '../../database-block/common/columns/number/define.js'; -import { richTextPureColumnConfig } from '../../database-block/common/columns/rich-text/define.js'; -import { selectPureColumnConfig } from '../../database-block/common/columns/select/define.js'; +import { selectColumnModelConfig } from '../../database-block/data-view/column/presets/select/define.js'; import type { DatabaseBlockModel } from '../../database-block/database-model.js'; import { DatabaseBlockSchema } from '../../database-block/database-model.js'; -import type { Cell, Column } from '../../database-block/types.js'; +import { + type Cell, + type Column, + columnPresets, + richTextColumnConfig, +} from '../../database-block/index.js'; import { NoteBlockSchema } from '../../note-block/note-model.js'; import { ParagraphBlockSchema } from '../../paragraph-block/paragraph-model.js'; import { RootBlockSchema } from '../../root-block/root-model.js'; @@ -79,12 +78,15 @@ describe('DatabaseManager', () => { ) as DatabaseBlockModel; db = databaseModel; - col1 = db.addColumn('end', numberPureColumnConfig.create('Number')); + col1 = db.addColumn( + 'end', + columnPresets.numberColumnConfig.model.create('Number') + ); col2 = db.addColumn( 'end', - selectPureColumnConfig.create('Single Select', { options: selection }) + selectColumnModelConfig.create('Single Select', { options: selection }) ); - col3 = db.addColumn('end', richTextPureColumnConfig.create('Rich Text')); + col3 = db.addColumn('end', richTextColumnConfig.model.create('Rich Text')); doc.updateBlock(databaseModel, { columns: [col1, col2, col3], @@ -117,7 +119,7 @@ describe('DatabaseManager', () => { test('getColumn', () => { const column = { - ...numberPureColumnConfig.create('testColumnId'), + ...columnPresets.numberColumnConfig.model.create('testColumnId'), id: 'testColumnId', }; db.addColumn('end', column); @@ -127,7 +129,7 @@ describe('DatabaseManager', () => { }); test('addColumn', () => { - const column = numberPureColumnConfig.create('Test Column'); + const column = columnPresets.numberColumnConfig.model.create('Test Column'); const id = db.addColumn('end', column); const result = db.getColumn(id); @@ -137,7 +139,7 @@ describe('DatabaseManager', () => { test('deleteColumn', () => { const column = { - ...numberPureColumnConfig.create('Test Column'), + ...columnPresets.numberColumnConfig.model.create('Test Column'), id: 'testColumnId', }; db.addColumn('end', column); @@ -156,7 +158,7 @@ describe('DatabaseManager', () => { noteBlockId ); const column = { - ...numberPureColumnConfig.create('Test Column'), + ...columnPresets.numberColumnConfig.model.create('Test Column'), id: 'testColumnId', }; const cell: Cell = { @@ -200,7 +202,7 @@ describe('DatabaseManager', () => { test('copyCellsByColumn', () => { const newColId = db.addColumn( 'end', - selectPureColumnConfig.create('Copied Select', { options: selection }) + selectColumnModelConfig.create('Copied Select', { options: selection }) ); db.copyCellsByColumn(col2, newColId); diff --git a/packages/blocks/src/__tests__/database/typesystem.unit.spec.ts b/packages/blocks/src/__tests__/database/typesystem.unit.spec.ts index ef16b3492269..247164aa467f 100644 --- a/packages/blocks/src/__tests__/database/typesystem.unit.spec.ts +++ b/packages/blocks/src/__tests__/database/typesystem.unit.spec.ts @@ -8,7 +8,7 @@ import { tUnion, tUnknown, typesystem, -} from '../../database-block/logical/typesystem.js'; +} from '../../database-block/data-view/logical/typesystem.js'; export const tString = typesystem.defineData<{ value: string }>({ name: 'String', diff --git a/packages/blocks/src/_common/adapters/notion-html.ts b/packages/blocks/src/_common/adapters/notion-html.ts index 31153584f57f..a7cbe77a5604 100644 --- a/packages/blocks/src/_common/adapters/notion-html.ts +++ b/packages/blocks/src/_common/adapters/notion-html.ts @@ -8,18 +8,21 @@ import type { FromSliceSnapshotPayload, FromSliceSnapshotResult, } from '@blocksuite/store'; -import { type AssetsManager, getAssetName, sha } from '@blocksuite/store'; -import { ASTWalker, BaseAdapter } from '@blocksuite/store'; import { + type AssetsManager, + ASTWalker, + BaseAdapter, type BlockSnapshot, type DocSnapshot, + getAssetName, + nanoid, + sha, type SliceSnapshot, } from '@blocksuite/store'; -import { nanoid } from '@blocksuite/store'; import rehypeParse from 'rehype-parse'; import { unified } from 'unified'; -import { getTagColor } from '../components/tags/colors.js'; +import { getTagColor } from '../../database-block/data-view/utils/tags/colors.js'; import { NoteDisplayMode } from '../types.js'; import { getFilenameFromContentDisposition } from '../utils/header-value-parser.js'; import { diff --git a/packages/blocks/src/_common/components/icon/uni-icon.ts b/packages/blocks/src/_common/components/icon/uni-icon.ts deleted file mode 100644 index 373f721f6608..000000000000 --- a/packages/blocks/src/_common/components/icon/uni-icon.ts +++ /dev/null @@ -1,11 +0,0 @@ -import type * as icons from '../../../_common/icons/index.js'; -import { map } from '../uni-component/operation.js'; -import { createUniComponentFromWebComponent } from '../uni-component/uni-component.js'; -import { AffineLitIcon } from './icon.js'; - -const litIcon = createUniComponentFromWebComponent<{ name: string }>( - AffineLitIcon -); -export const createIcon = (name: keyof typeof icons) => { - return map(litIcon, () => ({ name })); -}; diff --git a/packages/blocks/src/_common/components/index.ts b/packages/blocks/src/_common/components/index.ts index 55604d136793..814eceb896d7 100644 --- a/packages/blocks/src/_common/components/index.ts +++ b/packages/blocks/src/_common/components/index.ts @@ -8,5 +8,9 @@ export * from './rich-text/rich-text.js'; export * from './toast.js'; export * from './tooltip/index.js'; import './portal.js'; -export { popTagSelect, type SelectTag } from './tags/multi-tag-select.js'; + +export { + popTagSelect, + type SelectTag, +} from '../../database-block/data-view/utils/tags/multi-tag-select.js'; export { scrollbarStyle } from './utils.js'; diff --git a/packages/blocks/src/_common/configs/quick-action/database-convert-view.ts b/packages/blocks/src/_common/configs/quick-action/database-convert-view.ts index bd98a9abb83d..f81c1ab31a5a 100644 --- a/packages/blocks/src/_common/configs/quick-action/database-convert-view.ts +++ b/packages/blocks/src/_common/configs/quick-action/database-convert-view.ts @@ -4,16 +4,18 @@ import { assertExists } from '@blocksuite/global/utils'; import { css, html, LitElement, type TemplateResult } from 'lit'; import { customElement, property } from 'lit/decorators.js'; -import type { DataViewTypes } from '../../../database-block/common/data-view.js'; -import type { DatabaseBlockModel } from '../../../database-block/database-model.js'; -import { DatabaseSearchClose } from '../../icons/database.js'; +import { DatabaseSearchClose } from '../../../database-block/data-view/common/icons/index.js'; +import type { ViewMeta } from '../../../database-block/data-view/index.js'; +import { viewPresets } from '../../../database-block/data-view/index.js'; +import type { DatabaseBlockModel } from '../../../database-block/index.js'; +import { databaseViewInitConvert } from '../../../database-block/utils.js'; import { DatabaseKanbanViewIcon, DatabaseTableViewIcon, } from '../../icons/text.js'; interface DatabaseView { - type: DataViewTypes; + meta: ViewMeta; text: string; icon: TemplateResult; description?: string; @@ -22,12 +24,12 @@ interface DatabaseView { const databaseViews: DatabaseView[] = [ { - type: 'table', + meta: viewPresets.tableViewConfig, text: 'Table view', icon: DatabaseTableViewIcon, }, { - type: 'kanban', + meta: viewPresets.kanbanViewConfig, text: 'Kanban view', icon: DatabaseKanbanViewIcon, }, @@ -161,7 +163,7 @@ export class DatabaseConvertView extends WithDisposable(LitElement) { return this.host.doc; } - private _convertToDatabase(viewType: DataViewTypes) { + private _convertToDatabase(viewMeta: ViewMeta) { const [_, ctx] = this.host.std.command .chain() .getSelectedModels({ @@ -184,7 +186,7 @@ export class DatabaseConvertView extends WithDisposable(LitElement) { ); const databaseModel = this.doc.getBlockById(id) as DatabaseBlockModel; assertExists(databaseModel); - databaseModel.initConvert(viewType); + databaseViewInitConvert(databaseModel, viewMeta); databaseModel.applyColumnUpdate(); this.doc.moveBlocks(selectedModels, databaseModel); @@ -216,13 +218,13 @@ export class DatabaseConvertView extends WithDisposable(LitElement) { ${databaseViews.map(view => { return html`