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

@@ -109,7 +109,8 @@ export async function onModelTextUpdated(
console.error('Inline editor is not ready yet.');
return;
}
inlineEditor.slots.renderComplete.once(() => {
const subscription = inlineEditor.slots.renderComplete.subscribe(() => {
subscription.unsubscribe();
if (callback) {
callback(richText);
}

View File

@@ -1,6 +1,6 @@
import { createIdentifier } from '@blocksuite/global/di';
import { Slot } from '@blocksuite/global/slot';
import type { ExtensionType } from '@blocksuite/store';
import { Subject } from 'rxjs';
import type { RefNodeSlots } from '../inline/index.js';
@@ -8,7 +8,7 @@ export const RefNodeSlotsProvider =
createIdentifier<RefNodeSlots>('AffineRefNodeSlots');
const slots: RefNodeSlots = {
docLinkClicked: new Slot(),
docLinkClicked: new Subject(),
};
export const RefNodeSlotsExtension: ExtensionType = {

View File

@@ -57,7 +57,7 @@ export class AffineLink extends WithDisposable(ShadowlessElement) {
e?.preventDefault();
refNodeSlotsProvider.docLinkClicked.emit({
refNodeSlotsProvider.docLinkClicked.next({
...referenceInfo,
host: this.std.host,
});

View File

@@ -148,7 +148,7 @@ export class AffineReference extends WithDisposable(ShadowlessElement) {
readonly open = (event?: Partial<DocLinkClickedEvent>) => {
if (!this.config.interactable) return;
this.std.getOptional(RefNodeSlotsProvider)?.docLinkClicked.emit({
this.std.getOptional(RefNodeSlotsProvider)?.docLinkClicked.next({
...this.referenceInfo,
...event,
host: this.std.host,
@@ -205,7 +205,9 @@ export class AffineReference extends WithDisposable(ShadowlessElement) {
const doc = this.doc;
if (doc) {
this._disposables.add(
doc.workspace.slots.docListUpdated.on(() => this._updateRefMeta(doc))
doc.workspace.slots.docListUpdated.subscribe(() =>
this._updateRefMeta(doc)
)
);
}
@@ -215,7 +217,9 @@ export class AffineReference extends WithDisposable(ShadowlessElement) {
// observe yText update
this.disposables.add(
this.inlineEditor.slots.textChange.on(() => this._updateRefMeta(doc))
this.inlineEditor.slots.textChange.subscribe(() =>
this._updateRefMeta(doc)
)
);
})
.catch(console.error);

View File

@@ -1,7 +1,7 @@
import type { ReferenceInfo } from '@blocksuite/affine-model';
import type { OpenDocMode } from '@blocksuite/affine-shared/services';
import type { EditorHost } from '@blocksuite/block-std';
import type { Slot } from '@blocksuite/global/slot';
import type { Subject } from 'rxjs';
export type DocLinkClickedEvent = ReferenceInfo & {
// default is active view
@@ -11,5 +11,5 @@ export type DocLinkClickedEvent = ReferenceInfo & {
};
export type RefNodeSlots = {
docLinkClicked: Slot<DocLinkClickedEvent>;
docLinkClicked: Subject<DocLinkClickedEvent>;
};