mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-21 03:56:23 +08:00
chore: merge blocksuite source code (#9213)
This commit is contained in:
@@ -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)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user