@@ -69,7 +69,7 @@ export class DocTitle extends WithDisposable(ShadowlessElement) {
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
private _getOrCreateFirstPageVisibleNote() {
|
private _getOrCreateFirstPageVisibleNote() {
|
||||||
const note = this._rootModel.children.find(
|
const note = this._rootModel?.children.find(
|
||||||
(child): child is NoteBlockModel =>
|
(child): child is NoteBlockModel =>
|
||||||
matchModels(child, [NoteBlockModel]) &&
|
matchModels(child, [NoteBlockModel]) &&
|
||||||
child.props.displayMode !== NoteDisplayMode.EdgelessOnly
|
child.props.displayMode !== NoteDisplayMode.EdgelessOnly
|
||||||
@@ -91,7 +91,7 @@ export class DocTitle extends WithDisposable(ShadowlessElement) {
|
|||||||
|
|
||||||
const inlineRange = this.inlineEditor?.getInlineRange();
|
const inlineRange = this.inlineEditor?.getInlineRange();
|
||||||
if (inlineRange) {
|
if (inlineRange) {
|
||||||
const rightText = this._rootModel.props.title.split(inlineRange.index);
|
const rightText = this._rootModel?.props.title.split(inlineRange.index);
|
||||||
const newFirstParagraphId = this.doc.addBlock(
|
const newFirstParagraphId = this.doc.addBlock(
|
||||||
'affine:paragraph',
|
'affine:paragraph',
|
||||||
{ text: rightText },
|
{ text: rightText },
|
||||||
@@ -131,6 +131,7 @@ export class DocTitle extends WithDisposable(ShadowlessElement) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
private readonly _updateTitleInMeta = () => {
|
private readonly _updateTitleInMeta = () => {
|
||||||
|
if (!this._rootModel) return;
|
||||||
this.doc.workspace.meta.setDocMeta(this.doc.id, {
|
this.doc.workspace.meta.setDocMeta(this.doc.id, {
|
||||||
title: this._rootModel.props.title.toString(),
|
title: this._rootModel.props.title.toString(),
|
||||||
});
|
});
|
||||||
@@ -141,7 +142,7 @@ export class DocTitle extends WithDisposable(ShadowlessElement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private get _rootModel() {
|
private get _rootModel() {
|
||||||
return this.doc.root as RootBlockModel;
|
return this.doc.root as RootBlockModel | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private get _viewport() {
|
private get _viewport() {
|
||||||
@@ -191,14 +192,14 @@ export class DocTitle extends WithDisposable(ShadowlessElement) {
|
|||||||
this._updateTitleInMeta();
|
this._updateTitleInMeta();
|
||||||
this.requestUpdate();
|
this.requestUpdate();
|
||||||
};
|
};
|
||||||
this._rootModel.props.title.yText.observe(updateMetaTitle);
|
this._rootModel?.props.title.yText.observe(updateMetaTitle);
|
||||||
this._disposables.add(() => {
|
this._disposables.add(() => {
|
||||||
this._rootModel.props.title.yText.unobserve(updateMetaTitle);
|
this._rootModel?.props.title.yText.unobserve(updateMetaTitle);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
override render() {
|
override render() {
|
||||||
const isEmpty = !this._rootModel.props.title.length && !this._isComposing;
|
const isEmpty = !this._rootModel?.props.title.length && !this._isComposing;
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<div
|
<div
|
||||||
@@ -208,7 +209,7 @@ export class DocTitle extends WithDisposable(ShadowlessElement) {
|
|||||||
data-block-is-title="true"
|
data-block-is-title="true"
|
||||||
>
|
>
|
||||||
<rich-text
|
<rich-text
|
||||||
.yText=${this._rootModel.props.title.yText}
|
.yText=${this._rootModel?.props.title.yText}
|
||||||
.undoManager=${this.doc.history}
|
.undoManager=${this.doc.history}
|
||||||
.verticalScrollContainerGetter=${() => this._viewport}
|
.verticalScrollContainerGetter=${() => this._viewport}
|
||||||
.readonly=${this.doc.readonly}
|
.readonly=${this.doc.readonly}
|
||||||
|
|||||||
Reference in New Issue
Block a user