mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-19 23:37:15 +08:00
feat(editor): replace slot with rxjs subject (#10768)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
@@ -57,7 +57,7 @@ export class AffineLink extends WithDisposable(ShadowlessElement) {
|
||||
|
||||
e?.preventDefault();
|
||||
|
||||
refNodeSlotsProvider.docLinkClicked.emit({
|
||||
refNodeSlotsProvider.docLinkClicked.next({
|
||||
...referenceInfo,
|
||||
host: this.std.host,
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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>;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user