refactor(editor): reorg block specs (#9421)
This commit is contained in:
@@ -509,17 +509,6 @@ export class EmbedSyncedDocBlockComponent extends EmbedBlockComponent<EmbedSynce
|
||||
}
|
||||
});
|
||||
|
||||
// Forward docLinkClicked event from the synced doc
|
||||
const refNodeProvider =
|
||||
this.syncedDocEditorHost?.std.getOptional(RefNodeSlotsProvider);
|
||||
if (refNodeProvider) {
|
||||
this.disposables.add(
|
||||
refNodeProvider.docLinkClicked.on(args => {
|
||||
this.std.getOptional(RefNodeSlotsProvider)?.docLinkClicked.emit(args);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
this._initEdgelessFitEffect();
|
||||
}
|
||||
|
||||
|
||||
@@ -7,14 +7,12 @@ import type { RefNodeSlots } from '../inline/index.js';
|
||||
export const RefNodeSlotsProvider =
|
||||
createIdentifier<RefNodeSlots>('AffineRefNodeSlots');
|
||||
|
||||
export function RefNodeSlotsExtension(
|
||||
slots: RefNodeSlots = {
|
||||
docLinkClicked: new Slot(),
|
||||
}
|
||||
): ExtensionType {
|
||||
return {
|
||||
setup: di => {
|
||||
di.addImpl(RefNodeSlotsProvider, () => slots);
|
||||
},
|
||||
};
|
||||
}
|
||||
const slots: RefNodeSlots = {
|
||||
docLinkClicked: new Slot(),
|
||||
};
|
||||
|
||||
export const RefNodeSlotsExtension: ExtensionType = {
|
||||
setup: di => {
|
||||
di.addImpl(RefNodeSlotsProvider, () => slots);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -14,4 +14,14 @@ export class SpecBuilder {
|
||||
extend(extensions: ExtensionType[]) {
|
||||
this._value = [...this._value, ...extensions];
|
||||
}
|
||||
|
||||
omit(target: ExtensionType) {
|
||||
this._value = this._value.filter(extension => extension !== target);
|
||||
}
|
||||
|
||||
replace(target: ExtensionType, newExtension: ExtensionType) {
|
||||
this._value = this._value.map(extension =>
|
||||
extension === target ? newExtension : extension
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +46,15 @@ export class SpecProvider {
|
||||
return this.specMap.has(id);
|
||||
}
|
||||
|
||||
cloneSpec(id: string, targetId: string) {
|
||||
const existingSpec = this.specMap.get(id);
|
||||
if (!existingSpec) {
|
||||
console.error(`Spec not found for ${id}`);
|
||||
return;
|
||||
}
|
||||
this.specMap.set(targetId, [...existingSpec]);
|
||||
}
|
||||
|
||||
omitSpec(id: string, targetSpec: ExtensionType) {
|
||||
const existingSpec = this.specMap.get(id);
|
||||
if (!existingSpec) {
|
||||
@@ -58,4 +67,17 @@ export class SpecProvider {
|
||||
existingSpec.filter(spec => spec !== targetSpec)
|
||||
);
|
||||
}
|
||||
|
||||
replaceSpec(id: string, targetSpec: ExtensionType, newSpec: ExtensionType) {
|
||||
const existingSpec = this.specMap.get(id);
|
||||
if (!existingSpec) {
|
||||
console.error(`Spec not found for ${id}`);
|
||||
return;
|
||||
}
|
||||
|
||||
this.specMap.set(
|
||||
id,
|
||||
existingSpec.map(spec => (spec === targetSpec ? newSpec : spec))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user