feat(editor): replace slot with rxjs subject (#10768)

This commit is contained in:
Mirone
2025-03-12 11:29:24 +09:00
committed by GitHub
parent 19f978d9aa
commit cd63e0ed8b
302 changed files with 1405 additions and 1251 deletions

View File

@@ -19,7 +19,8 @@
"@blocksuite/global": "workspace:*",
"@preact/signals-core": "^1.8.0",
"@toeverything/theme": "^1.1.12",
"lit": "^3.2.0"
"lit": "^3.2.0",
"rxjs": "^7.8.1"
},
"exports": {
".": "./src/index.ts",

View File

@@ -102,18 +102,24 @@ export class AffineScrollAnchoringWidget extends WidgetComponent {
if (!xywh) {
if (!this.#listened) return;
// listen for document updates
this.disposables.add(
this.std.store.slots.blockUpdated
.filter(v => v.type === 'add' && v.id === id)
.once(() => this.#moveToAnchorInEdgeless(id))
);
const blockUpdatedSubscription =
this.std.store.slots.blockUpdated.subscribe(v => {
if (v.type === 'add' && v.id === id) {
blockUpdatedSubscription.unsubscribe();
this.#moveToAnchorInEdgeless(id);
}
});
this.disposables.add(
surface.elementAdded
.filter(v => v.id === id && v.local === false)
.once(() => this.#moveToAnchorInEdgeless(id))
);
const elementAddedSubscription = surface.elementAdded.subscribe(v => {
if (v.id === id && v.local === false) {
elementAddedSubscription.unsubscribe();
this.#moveToAnchorInEdgeless(id);
}
});
// listen for document updates
this.disposables.add(blockUpdatedSubscription);
this.disposables.add(elementAddedSubscription);
return;
}
@@ -152,11 +158,13 @@ export class AffineScrollAnchoringWidget extends WidgetComponent {
if (!this.#listened) return;
// listen for document updates
this.disposables.add(
this.std.store.slots.blockUpdated
.filter(v => v.type === 'add' && v.id === id)
.once(() => this.#moveToAnchorInPage(id))
);
const subscription = this.std.store.slots.blockUpdated.subscribe(v => {
if (v.type === 'add' && v.id === id) {
subscription.unsubscribe();
this.#moveToAnchorInPage(id);
}
});
this.disposables.add(subscription);
return;
}
@@ -192,7 +200,7 @@ export class AffineScrollAnchoringWidget extends WidgetComponent {
// In edgeless
const controler = this.std.get(GfxControllerIdentifier);
this.disposables.add(
controler.viewport.viewportUpdated.on(this.#requestUpdateFn)
controler.viewport.viewportUpdated.subscribe(this.#requestUpdateFn)
);
this.disposables.add(