@atlaskit/editor-common
Version:
A package that contains common classes and components for editor and renderer
74 lines (73 loc) • 4.72 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.InlineImageWrapper = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _react = require("@emotion/react");
var _editorPalette = require("@atlaskit/editor-palette");
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
var _styles = require("./styles");
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } /**
* @jsxRuntime classic
* @jsx jsx
*/ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled, @typescript-eslint/consistent-type-imports -- Ignored via go/DSP-18766; jsx required at runtime for @jsxRuntime classic
// The MediaImage component needs to obtain its parent's dimensions.
// To achieve this, we have added an additional wrapper that allows
// for better interaction with the parent element. This is necessary
// because the parent size changes its box-sizing with the node border.
var sizeWrapperStyle = (0, _react.css)({
display: 'inline-flex',
width: '100%',
height: '100%'
});
var InlineImageWrapper = exports.InlineImageWrapper = function InlineImageWrapper(_ref) {
var children = _ref.children,
isSelected = _ref.isSelected,
aspectRatio = _ref.aspectRatio,
borderSize = _ref.borderSize,
borderColor = _ref.borderColor,
_ref$htmlAttrs = _ref.htmlAttrs,
htmlAttrs = _ref$htmlAttrs === void 0 ? {} : _ref$htmlAttrs,
onClick = _ref.onClick;
var borderStyleVars = borderSize && borderColor ? (0, _defineProperty2.default)((0, _defineProperty2.default)({}, _styles.INLINE_IMAGE_BORDER_SIZE_CSS_VAR_KEY, borderSize), _styles.INLINE_IMAGE_BORDER_COLOR_CSS_VAR_KEY, (0, _editorPalette.hexToEditorBorderPaletteColor)(borderColor) || borderColor) : {};
var aspectStyleVars = aspectRatio ? (0, _defineProperty2.default)({}, _styles.INLINE_IMAGE_ASPECT_RATIO_CSS_VAR_KEY, aspectRatio) : {};
var onKeyDown = function onKeyDown(e) {
if ((0, _expValEquals.expValEquals)('editor_a11y__enghealth-46814_fy26', 'isEnabled', true)) {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
onClick(e);
}
}
return undefined;
};
return (
// eslint-disable-next-line @atlaskit/design-system/prefer-primitives
(0, _react.jsx)("span", (0, _extends2.default)({
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
style: _objectSpread(_objectSpread({}, borderStyleVars), aspectStyleVars)
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
,
className: _styles.INLINE_IMAGE_WRAPPER_CLASS_NAME,
css: [
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
_styles.wrapperStyle,
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
borderSize && borderColor && _styles.borderStyle,
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
isSelected && _styles.selectedStyle],
"data-testid": "inline-image-wrapper",
role: (0, _expValEquals.expValEquals)('editor_a11y__enghealth-46814_fy26', 'isEnabled', true) ? 'button' : undefined,
tabIndex: (0, _expValEquals.expValEquals)('editor_a11y__enghealth-46814_fy26', 'isEnabled', true) ? 0 : undefined,
onClick: onClick,
onKeyDown: onKeyDown
// Ignored via go/ees005
// eslint-disable-next-line react/jsx-props-no-spreading
}, htmlAttrs), (0, _react.jsx)("span", {
css: sizeWrapperStyle
}, children))
);
};