chore: merge blocksuite source code (#9213)

This commit is contained in:
Mirone
2024-12-20 15:38:06 +08:00
committed by GitHub
parent 2c9ef916f4
commit 30200ff86d
2031 changed files with 238888 additions and 229 deletions
@@ -0,0 +1,2 @@
export * from './spec-builder.js';
export * from './spec-provider.js';
@@ -0,0 +1,17 @@
import type { ExtensionType } from '@blocksuite/block-std';
export class SpecBuilder {
private _value: ExtensionType[];
get value() {
return this._value;
}
constructor(spec: ExtensionType[]) {
this._value = [...spec];
}
extend(extensions: ExtensionType[]) {
this._value = [...this._value, ...extensions];
}
}
@@ -0,0 +1,61 @@
import type { ExtensionType } from '@blocksuite/block-std';
import { assertExists } from '@blocksuite/global/utils';
import { SpecBuilder } from './spec-builder.js';
export class SpecProvider {
static instance: SpecProvider;
private specMap = new Map<string, ExtensionType[]>();
private constructor() {}
static getInstance() {
if (!SpecProvider.instance) {
SpecProvider.instance = new SpecProvider();
}
return SpecProvider.instance;
}
addSpec(id: string, spec: ExtensionType[]) {
if (!this.specMap.has(id)) {
this.specMap.set(id, spec);
}
}
clearSpec(id: string) {
this.specMap.delete(id);
}
extendSpec(id: string, newSpec: ExtensionType[]) {
const existingSpec = this.specMap.get(id);
if (!existingSpec) {
console.error(`Spec not found for ${id}`);
return;
}
this.specMap.set(id, [...existingSpec, ...newSpec]);
}
getSpec(id: string) {
const spec = this.specMap.get(id);
assertExists(spec, `Spec not found for ${id}`);
return new SpecBuilder(spec);
}
hasSpec(id: string) {
return this.specMap.has(id);
}
omitSpec(id: string, targetSpec: ExtensionType) {
const existingSpec = this.specMap.get(id);
if (!existingSpec) {
console.error(`Spec not found for ${id}`);
return;
}
this.specMap.set(
id,
existingSpec.filter(spec => spec !== targetSpec)
);
}
}