Skip to content

Commit ea943af

Browse files
zzj3720pull[bot]
authored andcommitted
refactor(database): render the title of the detail panel using rich-text (#7134)
1 parent 34bf22e commit ea943af

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

packages/blocks/src/database-block/data-source.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,10 @@ export class DatabaseBlockDataSource extends BaseDataSource {
328328
public override get detailSlots(): DetailSlots {
329329
return {
330330
...super.detailSlots,
331-
header: createUniComponentFromWebComponent(BlockRenderer),
331+
header: map(createUniComponentFromWebComponent(BlockRenderer), props => ({
332+
...props,
333+
host: this.host,
334+
})),
332335
note: map(createUniComponentFromWebComponent(NoteRenderer), props => ({
333336
...props,
334337
model: this._model,

packages/blocks/src/database-block/detail-panel/block-renderer.ts

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ export class BlockRenderer
4646
accessor view!: DataViewTableManager | DataViewKanbanManager;
4747
@property({ attribute: false })
4848
accessor rowId!: string;
49-
host?: EditorHost;
50-
49+
@property({ attribute: false })
50+
accessor host!: EditorHost;
5151
get model() {
52-
return this.host?.doc.getBlockById(this.rowId);
52+
return this.host?.doc.getBlock(this.rowId)?.model;
5353
}
5454

5555
get topContenteditableElement() {
@@ -60,7 +60,6 @@ export class BlockRenderer
6060

6161
public override connectedCallback() {
6262
super.connectedCallback();
63-
this.host = this.closest('editor-host') ?? undefined;
6463
this._disposables.addFromEvent(
6564
this.topContenteditableElement ?? this,
6665
'keydown',
@@ -95,11 +94,31 @@ export class BlockRenderer
9594
</div>`;
9695
}
9796

97+
get service() {
98+
return this.host.std.spec.getService('affine:database');
99+
}
100+
get inlineManager() {
101+
return this.service.inlineManager;
102+
}
103+
get attributesSchema() {
104+
return this.inlineManager.getSchema();
105+
}
106+
get attributeRenderer() {
107+
return this.inlineManager.getRenderer();
108+
}
98109
protected override render(): unknown {
99110
const model = this.model;
100111
if (!model) {
101112
return;
102113
}
103-
return html` ${this.host?.renderModel(model)} ${this.renderIcon()} `;
114+
return html`<rich-text
115+
.yText=${model.text}
116+
.attributesSchema=${this.attributesSchema}
117+
.attributeRenderer=${this.attributeRenderer}
118+
.embedChecker=${this.inlineManager.embedChecker}
119+
.markdownShortcutHandler=${this.inlineManager.markdownShortcutHandler}
120+
class="inline-editor"
121+
></rich-text
122+
>${this.renderIcon()} `;
104123
}
105124
}

0 commit comments

Comments
 (0)