mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-21 16:26:58 +08:00
refactor(editor): reorg block specs (#9421)
This commit is contained in:
@@ -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