feat(editor): unify block props api (#10888)

Closes: [BS-2707](https://linear.app/affine-design/issue/BS-2707/统一使用props获取和更新block-prop)
This commit is contained in:
Saul-Mirone
2025-03-16 05:48:34 +00:00
parent 8f9e5bf0aa
commit 26285f7dcb
193 changed files with 1019 additions and 891 deletions
@@ -155,7 +155,7 @@ export class EmbedIframeLinkEditPopup extends SignalWatcher(
override render() {
const isInputEmpty = this._isInputEmpty();
const { url$ } = this.model;
const { url$ } = this.model.props;
return html`
<div class="embed-iframe-link-edit-popup">
@@ -49,7 +49,8 @@ export const builtinToolbarConfig = {
);
if (!model) return;
const { title, caption, url, parent } = model;
const { title, caption, url } = model.props;
const { parent } = model;
const index = parent?.children.indexOf(model);
const yText = new Y.Text();
@@ -84,7 +85,8 @@ export const builtinToolbarConfig = {
);
if (!model) return;
const { url, caption, parent } = model;
const { url, caption } = model.props;
const { parent } = model;
const index = parent?.children.indexOf(model);
const flavour = 'affine:bookmark';
@@ -37,8 +37,8 @@ export class EmbedEdgelessIframeBlockComponent extends toGfxBlockComponent(
return nothing;
}
const bound = Bound.deserialize(this.model.xywh$.value);
const scale = this.model.scale$.value;
const bound = Bound.deserialize(this.model.props.xywh$.value);
const scale = this.model.props.scale$.value;
const width = bound.w / scale;
const height = bound.h / scale;
const style = {
@@ -75,7 +75,7 @@ export class EmbedIframeBlockComponent extends CaptionedBlockComponent<EmbedIfra
}
open = () => {
const link = this.model.url;
const link = this.model.props.url;
window.open(link, '_blank');
};
@@ -95,7 +95,7 @@ export class EmbedIframeBlockComponent extends CaptionedBlockComponent<EmbedIfra
);
}
const { url } = this.model;
const { url } = this.model.props;
if (!url) {
throw new BlockSuiteError(
ErrorCode.ValueNotExists,
@@ -110,7 +110,7 @@ export class EmbedIframeBlockComponent extends CaptionedBlockComponent<EmbedIfra
]);
// if the embed data is not found, and the iframeUrl is not set, throw an error
const currentIframeUrl = this.model.iframeUrl;
const currentIframeUrl = this.model.props.iframeUrl;
if (!embedData && !currentIframeUrl) {
throw new BlockSuiteError(
ErrorCode.ValueNotExists,
@@ -172,7 +172,7 @@ export class EmbedIframeBlockComponent extends CaptionedBlockComponent<EmbedIfra
};
private readonly _renderIframe = () => {
const { iframeUrl } = this.model;
const { iframeUrl } = this.model.props;
const {
widthPercent,
heightInNote,
@@ -226,13 +226,13 @@ export class EmbedIframeBlockComponent extends CaptionedBlockComponent<EmbedIfra
this.contentEditable = 'false';
if (!this.model.iframeUrl) {
if (!this.model.props.iframeUrl) {
this.doc.withoutTransact(() => {
this.refreshData().catch(console.error);
});
} else {
// update iframe options, to ensure the iframe is rendered with the correct options
this._updateIframeOptions(this.model.url);
this._updateIframeOptions(this.model.props.url);
this.status$.value = 'success';
}