/* eslint-disable no-continue */
import { ContextualMenu } from '../../contextual-menu/ContextualMenu.js';
import commands from './SchemaDesignerCommands.js';
export class SchemaDesignerContextMenu extends ContextualMenu {
    constructor() {
        super(document.body, {
            cancelNativeWhenHandled: false,
        });
        this.registerCommands(commands);
    }
    /**
     * Finds the click target which can be one of the model objects
     * or SVG elements.
     */
    findTarget(e) {
        const element = e.target;
        if (element.localName === 'schema-design-navigation') {
            return this.readNavigationElement(e, element);
        }
        return element;
    }
    readNavigationElement(e, element) {
        if (element === this.workspace) {
            return element;
        }
        const path = e.composedPath();
        while (path.length) {
            const target = path.shift();
            if (target.nodeType !== Node.ELEMENT_NODE) {
                continue;
            }
            const elm = target;
            if (elm.matches('.ns-selector')) {
                return elm;
            }
            if (elm.matches('li[data-key][data-kind]')) {
                return elm;
            }
            // top most for the navigation
            if (elm.localName === 'schema-design-navigation') {
                return elm;
            }
        }
        return undefined;
    }
}
//# sourceMappingURL=SchemaDesignerContextMenu.js.map