diff --git a/blocksuite/affine/blocks/data-view/src/data-view-block.ts b/blocksuite/affine/blocks/data-view/src/data-view-block.ts index 2aae05240..35bcf3d5b 100644 --- a/blocksuite/affine/blocks/data-view/src/data-view-block.ts +++ b/blocksuite/affine/blocks/data-view/src/data-view-block.ts @@ -23,9 +23,9 @@ import { createRecordDetail, createUniComponentFromWebComponent, type DataSource, - DataView, dataViewCommonStyle, type DataViewProps, + DataViewRootUILogic, type DataViewSelection, type DataViewWidget, type DataViewWidgetProps, @@ -133,8 +133,6 @@ export class DataViewBlockComponent extends CaptionedBlockComponent { return { dispose: this.host.event.bindHotkey(hotkeys, { @@ -232,10 +230,6 @@ export class DataViewBlockComponent extends CaptionedBlockComponent { + const notification = this.std.getOptional(NotificationProvider); + if (notification) { + notification.toast(message); + } else { + toast(this.host, message); + } + }, + }, + eventTrace: (key, params) => { + const telemetryService = this.std.getOptional(TelemetryProvider); + telemetryService?.track(key, { + ...(params as TelemetryEventMap[typeof key]), + blockId: this.blockId, + }); + }, + detailPanelConfig: { + openDetailPanel: (target, data) => { + const peekViewService = this.std.getOptional(PeekViewProvider); + if (peekViewService) { + const template = createRecordDetail({ + ...data, + openDoc: () => {}, + detail: { + header: uniMap( + createUniComponentFromWebComponent(BlockRenderer), + props => ({ + ...props, + host: this.host, + }) + ), + note: uniMap( + createUniComponentFromWebComponent(NoteRenderer), + props => ({ + ...props, + model: this.model, + host: this.host, + }) + ), + }, + }); + return peekViewService.peek({ target, template }); + } else { + return Promise.resolve(); + } + }, + }, + }); override renderBlock() { - const peekViewService = this.std.getOptional(PeekViewProvider); - const telemetryService = this.std.getOptional(TelemetryProvider); return html`
- ${this.dataView.render({ - virtualPadding$: signal(0), - bindHotkey: this._bindHotkey, - handleEvent: this._handleEvent, - selection$: this.selection$, - setSelection: this.setSelection, - dataSource: this.dataSource, - headerWidget: this.headerWidget, - clipboard: this.std.clipboard, - notification: { - toast: message => { - const notification = this.std.getOptional(NotificationProvider); - if (notification) { - notification.toast(message); - } else { - toast(this.host, message); - } - }, - }, - eventTrace: (key, params) => { - telemetryService?.track(key, { - ...(params as TelemetryEventMap[typeof key]), - blockId: this.blockId, - }); - }, - detailPanelConfig: { - openDetailPanel: (target, data) => { - if (peekViewService) { - const template = createRecordDetail({ - ...data, - openDoc: () => {}, - detail: { - header: uniMap( - createUniComponentFromWebComponent(BlockRenderer), - props => ({ - ...props, - host: this.host, - }) - ), - note: uniMap( - createUniComponentFromWebComponent(NoteRenderer), - props => ({ - ...props, - model: this.model, - host: this.host, - }) - ), - }, - }); - return peekViewService.peek({ target, template }); - } else { - return Promise.resolve(); - } - }, - }, - })} + ${this.dataViewRootLogic.render()}
`; } diff --git a/blocksuite/affine/blocks/database/src/components/title/index.ts b/blocksuite/affine/blocks/database/src/components/title/index.ts index 4c4d1f556..4a49c7d93 100644 --- a/blocksuite/affine/blocks/database/src/components/title/index.ts +++ b/blocksuite/affine/blocks/database/src/components/title/index.ts @@ -1,15 +1,19 @@ import { stopPropagation } from '@blocksuite/affine-shared/utils'; -import { WithDisposable } from '@blocksuite/global/lit'; +import type { DataViewUILogicBase } from '@blocksuite/data-view'; +import { SignalWatcher, WithDisposable } from '@blocksuite/global/lit'; import { ShadowlessElement } from '@blocksuite/std'; import type { Text } from '@blocksuite/store'; +import { signal } from '@preact/signals-core'; import { css, html } from 'lit'; -import { property, query, state } from 'lit/decorators.js'; +import { property, query } from 'lit/decorators.js'; import { classMap } from 'lit/directives/class-map.js'; import { styleMap } from 'lit/directives/style-map.js'; import type { DatabaseBlockComponent } from '../../database-block.js'; -export class DatabaseTitle extends WithDisposable(ShadowlessElement) { +export class DatabaseTitle extends SignalWatcher( + WithDisposable(ShadowlessElement) +) { static override styles = css` .affine-database-title { position: relative; @@ -71,22 +75,23 @@ export class DatabaseTitle extends WithDisposable(ShadowlessElement) { `; private readonly compositionEnd = () => { + this.isComposing$.value = false; this.titleText.replace(0, this.titleText.length, this.input.value); }; private readonly onBlur = () => { - this.isFocus = false; + this.isFocus$.value = false; }; private readonly onFocus = () => { - this.isFocus = true; - if (this.database?.viewSelection$?.value) { - this.database?.setSelection(undefined); + this.isFocus$.value = true; + if (this.dataViewLogic.selection$.value) { + this.dataViewLogic.setSelection(undefined); } }; private readonly onInput = (e: InputEvent) => { - this.text = this.input.value; + this.text$.value = this.input.value; if (!e.isComposing) { this.titleText.replace(0, this.titleText.length, this.input.value); } @@ -102,9 +107,9 @@ export class DatabaseTitle extends WithDisposable(ShadowlessElement) { }; updateText = () => { - if (!this.isFocus) { + if (!this.isFocus$.value) { this.input.value = this.titleText.toString(); - this.text = this.input.value; + this.text$.value = this.input.value; } }; @@ -124,25 +129,25 @@ export class DatabaseTitle extends WithDisposable(ShadowlessElement) { } override render() { - const isEmpty = !this.text; + const isEmpty = !this.text$.value; const classList = classMap({ 'affine-database-title': true, - ellipsis: !this.isFocus, + ellipsis: !this.isFocus$.value, }); const untitledStyle = styleMap({ height: isEmpty ? 'auto' : 0, - opacity: isEmpty && !this.isFocus ? 1 : 0, + opacity: isEmpty && !this.isFocus$.value ? 1 : 0, }); return html`
Untitled
-
${this.text}
+
${this.text$.value}