UNPKG

@atlaskit/editor-plugin-block-controls

Version:

Block controls plugin for @atlaskit/editor-core

47 lines (46 loc) 1.55 kB
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals'; export var NODE_ANCHOR_ATTR_NAME = 'data-node-anchor'; export var NODE_NODE_TYPE_ATTR_NAME = 'data-prosemirror-node-name'; export var getAnchorAttrName = function getAnchorAttrName() { if (expValEquals('platform_editor_native_anchor_with_dnd', 'isEnabled', true)) { return NODE_ANCHOR_ATTR_NAME; } return 'data-drag-handler-anchor-name'; }; export var getTypeNameAttrName = function getTypeNameAttrName() { if (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. export var 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; };