@atlaskit/editor-plugin-selection-marker
Version:
Selection marker plugin for @atlaskit/editor-core.
71 lines (67 loc) • 3.42 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.GlobalStylesWrapper = void 0;
var _react = require("@emotion/react");
var _isExperimentEnabled = require("@atlaskit/platform-feature-experiments/is-experiment-enabled");
var _fg = require("@atlaskit/platform-feature-flags/fg");
/**
* @jsxRuntime classic
* @jsx jsx
*/
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-global-styles, @atlaskit/ui-styling-standard/use-compiled, @typescript-eslint/consistent-type-imports
/**
* Unset the selection background color as we are using our own
* Otherwise we might have a mix of grey + our selection marker depending on the state.
*
* Edge cases:
* - We do not apply this reset to input fields or code blocks (ie. expand case) because otherwise
* selection highlight will not show on those.
* - We do not apply this reset when the editor is disabled
*/
var globalStyles = (0, _react.css)({
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors -- Ignored via go/DSP-18766
'.ProseMirror:not(:focus):not([contenteditable="false"]) ::selection:not(input, .cm-editor)': {
background: 'unset'
}
});
// Target marker text directly rather than depending on the editor root's focus
// state. The style-recalculation benefit still needs profiling on large documents.
var markerSelectionStyles = (0, _react.css)({
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-selectors, @atlaskit/ui-styling-standard/no-nested-selectors -- ProseMirror owns the decoration DOM; React cannot style its selection pseudo-element directly.
'.ProseMirror:not([contenteditable="false"]) [data-selection-marker]::selection': {
background: 'unset'
}
});
/**
* Hides the native highlight wherever the marker paints the selection, including inside inline
* atom node views. The native selection is not restored while the editor is blurred, so any part
* of it left on marker content would otherwise show through.
*/
var markerAndDescendantSelectionStyles = (0, _react.css)({
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-selectors, @atlaskit/ui-styling-standard/no-nested-selectors -- ProseMirror owns the decoration DOM; React cannot style its selection pseudo-element directly.
'.ProseMirror:not([contenteditable="false"]) [data-selection-marker]::selection, .ProseMirror:not([contenteditable="false"]) [data-selection-marker] ::selection': {
background: 'transparent'
}
});
var hideSelectionStyles = (0, _react.css)({
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors
'.ProseMirror *.danger::selection': {
background: 'transparent'
}
});
var getSelectionStyles = function getSelectionStyles() {
if ((0, _fg.fg)('platform_editor_selection_marker_blur_fix')) {
return markerAndDescendantSelectionStyles;
}
return (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_improve_inp_batch_3') ? markerSelectionStyles : globalStyles;
};
var GlobalStylesWrapper = exports.GlobalStylesWrapper = function GlobalStylesWrapper() {
var selectionStyles = getSelectionStyles();
return (0, _react.jsx)(_react.Global
// eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed)
, {
styles: [selectionStyles, hideSelectionStyles]
});
};