UNPKG

@atlaskit/editor-plugin-show-diff

Version:

ShowDiff plugin for @atlaskit/editor-core

43 lines (41 loc) • 1.87 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createMarginAbsorber = exports.createBoxlessMarginAbsorber = void 0; /** * An empty, invisible element whose only job is to occupy a position in the DOM. * * At the top of the document `firstBlockNodeStyles` zeroes the top margin of whatever element * follows a leading `.ProseMirror-widget`, and it does so with `!important` — which no inline style * can outrank. This takes that hit so the shaped spacer after it, one position further along, keeps * the margin it is there to supply. * * It contributes no height (no content, border or padding) and margins collapse through it, so it * cannot affect layout beyond the selector it absorbs. */ var createMarginAbsorber = exports.createMarginAbsorber = function createMarginAbsorber(_ref) { var testId = _ref.testId; // Block-level: an empty inline element takes the match just as well, but collapses to a // zero-height line box, and the following margin then lands in the wrong place. var absorber = document.createElement('div'); absorber.dataset.testid = testId; absorber.setAttribute('aria-hidden', 'true'); absorber.contentEditable = 'false'; return absorber; }; /** * An absorber that occupies a DOM position without generating a box. * * Not interchangeable with `createMarginAbsorber`: a rule that selects the *rendered* sibling of a * leading widget needs an element that generates a box, and this one does not. */ var createBoxlessMarginAbsorber = exports.createBoxlessMarginAbsorber = function createBoxlessMarginAbsorber(_ref2) { var testId = _ref2.testId; var absorber = document.createElement('div'); absorber.dataset.testid = testId; absorber.setAttribute('aria-hidden', 'true'); absorber.contentEditable = 'false'; absorber.style.display = 'contents'; return absorber; };