UNPKG

@atlaskit/editor-plugin-card

Version:

Card plugin for @atlaskit/editor-core

48 lines (45 loc) 1.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isOneLine = exports.getOverlayWidths = exports.getInlineCardAvailableWidth = exports.getIconSize = exports.getChildElement = void 0; /** * Find a child element inside a ref. */ var getChildElement = exports.getChildElement = function getChildElement(ref, selector) { return ref.current ? ref.current.querySelector(selector) : undefined; }; /** * Get the available width of the inline card. * (Mainly here to make the component unit testable.) */ var getInlineCardAvailableWidth = exports.getInlineCardAvailableWidth = function getInlineCardAvailableWidth(startEl, endEl) { var start = startEl.getBoundingClientRect().left; var end = endEl.getBoundingClientRect().left; return end - start; }; var isOneLine = exports.isOneLine = function isOneLine(startEl, endEl) { var start = startEl.getBoundingClientRect().top; var end = endEl.getBoundingClientRect().top; return start === end; }; /** * Get max and min width of an overlay. * (Mainly here to make the component unit testable.) */ var getOverlayWidths = exports.getOverlayWidths = function getOverlayWidths(overlayEl, labelEl) { var max = overlayEl.getBoundingClientRect().width; var min = max - labelEl.getBoundingClientRect().width; return { max: max, min: min }; }; var getIconSize = exports.getIconSize = function getIconSize(labelEl) { var h2FontSizePx = 20; var fontSize = window && parseFloat(window.getComputedStyle(labelEl).fontSize); if (!fontSize || fontSize < h2FontSizePx) { return 'small'; } return 'medium'; };