import { v4 as uuidv4 } from 'uuid';
import { findFirstDescedantNode } from "./descedants.js";
export const entityIdAttr = 'data-entity-id';
export function generateEntityId(name = 'entity') {
    return name + '-' + uuidv4();
}
/**
 * Returns true when entityId is not set, is set to default value, or is duplicated (other node already has this entityId)
 */
export function isInvalidEntityId({ doc, node, defaultId, }) {
    const entityId = node.attrs[entityIdAttr];
    if (!entityId || entityId === defaultId)
        return true;
    return Boolean(findFirstDescedantNode(doc, (dNode) => node !== dNode && dNode.attrs[entityIdAttr] === entityId));
}
//# sourceMappingURL=entity-id.js.map
