refactor(editor): edgeless external embed card toolbar config extension (#10712)

This commit is contained in:
fundon
2025-03-19 04:05:36 +00:00
parent 284aae9b52
commit 7f4b56e05c
11 changed files with 415 additions and 160 deletions

View File

@@ -128,8 +128,8 @@ abstract class ToolbarContextBase {
);
}
getSurfaceModelsByType<M extends abstract new (...args: any) => any>(
klass: M
getSurfaceModelsByType<T extends abstract new (...args: any) => any>(
klass: T
) {
if (this.hasSelectedSurfaceModels) {
const elements = this.elementsMap$.peek().get(this.flavour$.peek());
@@ -140,6 +140,20 @@ abstract class ToolbarContextBase {
return [];
}
getSurfaceBlocksByType<T extends abstract new (...args: any) => any>(
klass: T
) {
if (this.hasSelectedSurfaceModels) {
const elements = this.elementsMap$.peek().get(this.flavour$.peek());
if (elements?.length) {
return elements
.map(model => this.gfx.view.get(model.id))
.filter(block => block && this.matchBlock(block, klass));
}
}
return [];
}
getCurrentBlockBy<T extends SelectionConstructor>(type: T) {
const selection = this.selection.find(type);
if (!selection) return null;
@@ -160,17 +174,17 @@ abstract class ToolbarContextBase {
: this.getCurrentBlockBy(BlockSelection);
}
getCurrentBlockByType<K extends abstract new (...args: any) => any>(
klass: K
getCurrentBlockByType<T extends abstract new (...args: any) => any>(
klass: T
) {
const block = this.getCurrentBlock();
return this.matchBlock(block, klass) ? block : null;
}
matchBlock<K extends abstract new (...args: any) => any>(
matchBlock<T extends abstract new (...args: any) => any>(
component: GfxElementModelView | BlockComponent | null,
klass: K
): component is InstanceType<K> {
klass: T
): component is InstanceType<T> {
return component instanceof klass;
}
@@ -184,23 +198,23 @@ abstract class ToolbarContextBase {
return this.store.getBlock(selection.blockId)?.model ?? null;
}
getCurrentModel() {
getCurrentModel(): GfxModel | BlockModel | null {
return this.hasSelectedSurfaceModels
? this.getCurrentModelBy(SurfaceSelection)
: this.getCurrentModelBy(BlockSelection);
}
getCurrentModelByType<M extends abstract new (...args: any) => any>(
klass: M
getCurrentModelByType<T extends abstract new (...args: any) => any>(
klass: T
) {
const model = this.getCurrentModel();
return this.matchModel(model, klass) ? model : null;
}
matchModel<K extends abstract new (...args: any) => any>(
matchModel<T extends abstract new (...args: any) => any>(
model: GfxModel | BlockModel | null,
klass: K
): model is InstanceType<K> {
klass: T
): model is InstanceType<T> {
return model instanceof klass;
}