refactor(editor): reorg block specs (#9421)

This commit is contained in:
Saul-Mirone
2024-12-30 05:59:25 +00:00
parent 87331b49b7
commit e3b6841944
16 changed files with 121 additions and 173 deletions

View File

@@ -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
);
}
}

View File

@@ -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))
);
}
}