mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-15 05:37:32 +00:00
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:
@@ -23,7 +23,7 @@ const surfaceRefSlashMenuConfig: SlashMenuConfig = {
|
||||
.map(block => block.model as FrameBlockModel);
|
||||
|
||||
const frameItems = frameModels.map<SlashMenuActionItem>(frameModel => ({
|
||||
name: 'Frame: ' + frameModel.title,
|
||||
name: 'Frame: ' + frameModel.props.title,
|
||||
icon: FrameIcon(),
|
||||
group: `5_Document Group & Frame@${index++}`,
|
||||
tooltip: {
|
||||
|
||||
@@ -68,13 +68,16 @@ export class SurfaceRefNotePortal extends WithDisposable(ShadowlessElement) {
|
||||
|
||||
override render() {
|
||||
const { model, index } = this;
|
||||
const { displayMode, edgeless } = model;
|
||||
const { displayMode, edgeless } = model.props;
|
||||
if (!!displayMode && displayMode === NoteDisplayMode.DocOnly)
|
||||
return nothing;
|
||||
|
||||
const backgroundColor = this.host.std
|
||||
.get(ThemeProvider)
|
||||
.generateColorProperty(model.background, DefaultTheme.noteBackgrounColor);
|
||||
.generateColorProperty(
|
||||
model.props.background,
|
||||
DefaultTheme.noteBackgrounColor
|
||||
);
|
||||
|
||||
const [modelX, modelY, modelW, modelH] = deserializeXYWH(model.xywh);
|
||||
const style = {
|
||||
|
||||
@@ -316,19 +316,19 @@ export class SurfaceRefBlockComponent extends BlockComponent<SurfaceRefBlockMode
|
||||
this._surfaceModel = surfaceModel;
|
||||
|
||||
const findReferencedModel = (): [GfxModel | null, string] => {
|
||||
if (!this.model.reference) return [null, this.doc.id];
|
||||
if (!this.model.props.reference) return [null, this.doc.id];
|
||||
|
||||
if (this.doc.getBlock(this.model.reference)) {
|
||||
if (this.doc.getBlock(this.model.props.reference)) {
|
||||
return [
|
||||
this.doc.getBlock(this.model.reference)
|
||||
this.doc.getBlock(this.model.props.reference)
|
||||
?.model as GfxBlockElementModel,
|
||||
this.doc.id,
|
||||
];
|
||||
}
|
||||
|
||||
if (this._surfaceModel?.getElementById(this.model.reference)) {
|
||||
if (this._surfaceModel?.getElementById(this.model.props.reference)) {
|
||||
return [
|
||||
this._surfaceModel.getElementById(this.model.reference),
|
||||
this._surfaceModel.getElementById(this.model.props.reference),
|
||||
this.doc.id,
|
||||
];
|
||||
}
|
||||
@@ -337,17 +337,18 @@ export class SurfaceRefBlockComponent extends BlockComponent<SurfaceRefBlockMode
|
||||
.map(doc => doc.getStore())
|
||||
.find(
|
||||
doc =>
|
||||
doc.getBlock(this.model.reference) ||
|
||||
getSurfaceBlock(doc)?.getElementById(this.model.reference)
|
||||
doc.getBlock(this.model.props.reference) ||
|
||||
getSurfaceBlock(doc)?.getElementById(this.model.props.reference)
|
||||
);
|
||||
|
||||
if (doc) {
|
||||
this._surfaceModel = getSurfaceBlock(doc);
|
||||
}
|
||||
|
||||
if (doc && doc.getBlock(this.model.reference)) {
|
||||
if (doc && doc.getBlock(this.model.props.reference)) {
|
||||
return [
|
||||
doc.getBlock(this.model.reference)?.model as GfxBlockElementModel,
|
||||
doc.getBlock(this.model.props.reference)
|
||||
?.model as GfxBlockElementModel,
|
||||
doc.id,
|
||||
];
|
||||
}
|
||||
@@ -355,7 +356,10 @@ export class SurfaceRefBlockComponent extends BlockComponent<SurfaceRefBlockMode
|
||||
if (doc) {
|
||||
const surfaceBlock = getSurfaceBlock(doc);
|
||||
if (surfaceBlock) {
|
||||
return [surfaceBlock.getElementById(this.model.reference), doc.id];
|
||||
return [
|
||||
surfaceBlock.getElementById(this.model.props.reference),
|
||||
doc.id,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -379,7 +383,7 @@ export class SurfaceRefBlockComponent extends BlockComponent<SurfaceRefBlockMode
|
||||
this.model.propsUpdated.subscribe(payload => {
|
||||
if (
|
||||
payload.key === 'reference' &&
|
||||
this.model.reference !== this._referencedModel?.id
|
||||
this.model.props.reference !== this._referencedModel?.id
|
||||
) {
|
||||
init();
|
||||
}
|
||||
@@ -389,7 +393,7 @@ export class SurfaceRefBlockComponent extends BlockComponent<SurfaceRefBlockMode
|
||||
if (surfaceModel && this._referencedModel instanceof SurfaceElementModel) {
|
||||
this._disposables.add(
|
||||
surfaceModel.elementRemoved.subscribe(({ id }) => {
|
||||
if (this.model.reference === id) {
|
||||
if (this.model.props.reference === id) {
|
||||
init();
|
||||
}
|
||||
})
|
||||
@@ -399,7 +403,7 @@ export class SurfaceRefBlockComponent extends BlockComponent<SurfaceRefBlockMode
|
||||
if (this._referencedModel instanceof GfxBlockElementModel) {
|
||||
this._disposables.add(
|
||||
this.doc.slots.blockUpdated.subscribe(({ type, id }) => {
|
||||
if (type === 'delete' && id === this.model.reference) {
|
||||
if (type === 'delete' && id === this.model.props.reference) {
|
||||
init();
|
||||
}
|
||||
})
|
||||
@@ -442,7 +446,7 @@ export class SurfaceRefBlockComponent extends BlockComponent<SurfaceRefBlockMode
|
||||
}
|
||||
this._previewSpec.extend([SurfaceRefViewportInitializer]);
|
||||
|
||||
const referenceId = this.model.reference;
|
||||
const referenceId = this.model.props.reference;
|
||||
const setReferenceXYWH = (xywh: typeof this._referenceXYWH) => {
|
||||
this._referenceXYWH = xywh;
|
||||
};
|
||||
@@ -564,7 +568,7 @@ export class SurfaceRefBlockComponent extends BlockComponent<SurfaceRefBlockMode
|
||||
<div class="placeholder-image">${noContentPlaceholder}</div>
|
||||
<div class="placeholder-text">
|
||||
No Such
|
||||
${NO_CONTENT_TITLE[model.refFlavour ?? 'DEFAULT'] ??
|
||||
${NO_CONTENT_TITLE[model.props.refFlavour ?? 'DEFAULT'] ??
|
||||
NO_CONTENT_TITLE.DEFAULT}
|
||||
</div>
|
||||
<div class="placeholder-action">
|
||||
@@ -574,7 +578,7 @@ export class SurfaceRefBlockComponent extends BlockComponent<SurfaceRefBlockMode
|
||||
</button>
|
||||
</div>
|
||||
<div class="placeholder-reason">
|
||||
${NO_CONTENT_REASON[model.refFlavour ?? 'DEFAULT'] ??
|
||||
${NO_CONTENT_REASON[model.props.refFlavour ?? 'DEFAULT'] ??
|
||||
NO_CONTENT_REASON.DEFAULT}
|
||||
</div>
|
||||
</div>`;
|
||||
|
||||
Reference in New Issue
Block a user