/**
|
* 画布节点 → 质量组件定义的反查。
|
* <p>
|
* 单独成文件:canvas-sync 与 trait-binding 都要用它,
|
* 放在任一方都会让「属性面板控件」和「画布同步」互相依赖。
|
*/
|
import type { Component } from 'grapesjs';
|
|
import type { QualityComponentDefinition } from './types';
|
|
import { QUALITY_TYPE_ATTR } from './attrs';
|
import { getQualityComponent } from './registry';
|
|
/** 按节点上的 data-quality-type 查定义;不是质量组件时返回 undefined */
|
export function definitionOf(component?: Component): QualityComponentDefinition | undefined {
|
const attributes = component?.getAttributes() ?? {};
|
return getQualityComponent(String(attributes[QUALITY_TYPE_ATTR] ?? ''));
|
}
|