UNPKG

@atlaskit/editor-plugin-block-controls

Version:

Block controls plugin for @atlaskit/editor-core

53 lines (51 loc) 1.95 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getTypeNameFromDom = exports.getTypeNameAttrName = exports.getAnchorAttrName = exports.NODE_NODE_TYPE_ATTR_NAME = exports.NODE_ANCHOR_ATTR_NAME = void 0; var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals"); var NODE_ANCHOR_ATTR_NAME = exports.NODE_ANCHOR_ATTR_NAME = 'data-node-anchor'; var NODE_NODE_TYPE_ATTR_NAME = exports.NODE_NODE_TYPE_ATTR_NAME = 'data-prosemirror-node-name'; var getAnchorAttrName = exports.getAnchorAttrName = function getAnchorAttrName() { if ((0, _expValEquals.expValEquals)('platform_editor_native_anchor_with_dnd', 'isEnabled', true)) { return NODE_ANCHOR_ATTR_NAME; } return 'data-drag-handler-anchor-name'; }; var getTypeNameAttrName = exports.getTypeNameAttrName = function getTypeNameAttrName() { if ((0, _expValEquals.expValEquals)('platform_editor_native_anchor_with_dnd', 'isEnabled', true)) { return NODE_NODE_TYPE_ATTR_NAME; } return 'data-drag-handler-node-type'; }; var isHeadingElement = function isHeadingElement(element) { var headingTags = ['H1', 'H2', 'H3', 'H4', 'H5', 'H6']; return headingTags.includes(element.tagName); }; // This function replicates the behavior of getNodeTypeWithLevel by returning the same value. var getTypeNameFromDom = exports.getTypeNameFromDom = function getTypeNameFromDom(element) { if (!element) { return ''; } var nodeType = element === null || element === void 0 ? void 0 : element.getAttribute(NODE_NODE_TYPE_ATTR_NAME); if (!nodeType) { return ''; } if (isHeadingElement(element)) { switch (element.tagName) { case 'H1': return 'heading-1'; case 'H2': return 'heading-2'; case 'H3': return 'heading-3'; case 'H4': return 'heading-4'; case 'H5': return 'heading-5'; case 'H6': return 'heading-6'; } } return nodeType; };