@atlaskit/editor-core
Version:
A package contains Atlassian editor core functionality
182 lines (176 loc) • 9.21 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof3 = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.MainToolbar = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _react = _interopRequireWildcard(require("react"));
var _react2 = require("@emotion/react");
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof3(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
/**
* @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
var MAXIMUM_TWO_LINE_TOOLBAR_BREAKPOINT = 490;
var akEditorMenuZIndex = 500;
var akEditorToolbarKeylineHeight = 2;
var mainToolbarWrapperStyleNew = (0, _react2.css)({
position: 'relative',
alignItems: 'center',
padding: "var(--ds-space-100, 8px)".concat(" ", "var(--ds-space-100, 8px)", " 0"),
display: 'flex',
height: 'auto',
backgroundColor: "var(--ds-surface, #FFFFFF)",
boxShadow: 'none',
paddingLeft: "var(--ds-space-250, 20px)",
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors
'> div': {
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors
'> div:first-of-type:not(style), > style:first-of-type + *': {
marginLeft: 0
}
},
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors
'.block-type-btn': {
paddingLeft: 0
}
});
/** keep default padding for entire toolbar */
var mainToolbarWithoutLeftPadding = (0, _react2.css)({
padding: "var(--ds-space-100, 8px)".concat(" ", "var(--ds-space-100, 8px)", " 0")
});
var mainToolbarWithPadding = (0, _react2.css)({
padding: "var(--ds-space-100, 8px)"
});
var mainToolbarTwoLineStylesNew = (0, _react2.css)({
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors
'& > div': (0, _defineProperty2.default)((0, _defineProperty2.default)({}, "@media (max-width: ".concat(MAXIMUM_TWO_LINE_TOOLBAR_BREAKPOINT, "px)"), {
flexDirection: 'column-reverse',
alignItems: 'end',
display: 'flex',
justifyContent: 'flex-end'
}), '> div:first-of-type', (0, _defineProperty2.default)({}, "@media (max-width: ".concat(MAXIMUM_TWO_LINE_TOOLBAR_BREAKPOINT, "px)"), {
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors
'> div:nth-of-type(2)': {
justifyContent: 'flex-end',
display: 'flex'
}
}))
});
var mainToolbarWrapperStylesVisualRefresh = (0, _react2.css)({
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors
'span svg': {
maxWidth: '100%'
}
});
var mainToolbarWithRadiusStyle = (0, _react2.css)({
borderRadius: "var(--ds-radius-small, 3px)".concat(" ", "var(--ds-radius-small, 3px)", " 0 0")
});
var mainToolbarRadius = (0, _react2.css)({
borderRadius: "var(--ds-radius-medium, 6px)".concat(" ", "var(--ds-radius-medium, 6px)", " 0 0")
});
var stickyToolbarWrapperStyleNew = (0, _react2.css)({
position: 'sticky',
paddingBottom: "var(--ds-space-100, 8px)",
zIndex: akEditorMenuZIndex,
transition: 'box-shadow ease-in-out 0.2s',
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors
'&.show-keyline': {
boxShadow: "0 ".concat(akEditorToolbarKeylineHeight, "px 0 0 ", "var(--ds-background-accent-gray-subtlest, #F0F1F2)")
}
});
var StickyToolbar = function StickyToolbar(props) {
var _useState = (0, _react.useState)(0),
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
top = _useState2[0],
setTop = _useState2[1];
// ED-15802: if externalToolbarRef is passed in, set top to externalToolbarRef?.current?.clientHeight
// else if offsetTop is a number set top to offsetTop
// otherwise top is 0 as initial state
(0, _react.useEffect)(function () {
var _props$externalToolba;
if ((_props$externalToolba = props.externalToolbarRef) !== null && _props$externalToolba !== void 0 && (_props$externalToolba = _props$externalToolba.current) !== null && _props$externalToolba !== void 0 && _props$externalToolba.clientHeight) {
setTop(props.externalToolbarRef.current.clientHeight);
} else {
setTop(props.offsetTop || 0);
}
}, [props.externalToolbarRef, props.offsetTop]);
return (
// eslint-disable-next-line @atlaskit/design-system/prefer-primitives
(0, _react2.jsx)("div", {
css: [mainToolbarWrapperStyleNew, props.twoLineEditorToolbar && mainToolbarTwoLineStylesNew, mainToolbarWrapperStylesVisualRefresh, stickyToolbarWrapperStyleNew, props.isNewToolbarEnabled && mainToolbarWithPadding, (0, _expValEquals.expValEquals)('platform_editor_fix_comment_border', 'isEnabled', true) && (0, _expValEquals.expValEquals)('platform_editor_comment_editor_border_radius', 'isEnabled', true) && mainToolbarRadius, (0, _expValEquals.expValEquals)('platform_editor_fix_comment_border', 'isEnabled', true) && !(0, _expValEquals.expValEquals)('platform_editor_comment_editor_border_radius', 'isEnabled', true) && (0, _platformFeatureFlags.fg)('platform_editor_comments_border_radius') && mainToolbarWithRadiusStyle]
// eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage/preview
,
style: {
top: "".concat(top, "px")
},
"data-testid": "ak-editor-main-toolbar"
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
,
className: 'show-keyline'
}, props.children)
);
};
var FixedToolbar = function FixedToolbar(props) {
return (
// eslint-disable-next-line @atlaskit/design-system/prefer-primitives
(0, _react2.jsx)("div", {
css: [mainToolbarWrapperStyleNew, props.twoLineEditorToolbar && mainToolbarTwoLineStylesNew, mainToolbarWrapperStylesVisualRefresh, props.isNewToolbarEnabled && mainToolbarWithoutLeftPadding, !(0, _expValEquals.expValEquals)('platform_editor_comment_editor_border_radius', 'isEnabled', true) && (0, _platformFeatureFlags.fg)('platform_editor_comments_border_radius') && mainToolbarWithRadiusStyle, (0, _expValEquals.expValEquals)('platform_editor_comment_editor_border_radius', 'isEnabled', true) && mainToolbarRadius],
"data-testid": "ak-editor-main-toolbar"
}, props.children)
);
};
/**
* ED-15802: Scenarios when a sticky bar is used:
* 1. useStickyToolbar is true
* 2. useStickyToolbar is a DOM element
* 3. useStickyToolbar is an object and has offsetTop key;
*/
var getStickyParameters = function getStickyParameters(configuration) {
// const isUsingStickyOffset, isHTMLElement is used so TS can properly infer types.
var isHTMLElement = (0, _typeof2.default)(configuration) === 'object' && !('offsetTop' in configuration);
var isUsingStickyOffset = (0, _typeof2.default)(configuration) === 'object' && 'offsetTop' in configuration;
if ((0, _typeof2.default)(configuration) !== 'object') {
return {
externalToolbarRef: undefined,
offsetTop: undefined
};
}
if (isUsingStickyOffset) {
return {
offsetTop: configuration.offsetTop
};
}
if (isHTMLElement) {
return {
externalToolbarRef: configuration
};
}
};
var MainToolbar = exports.MainToolbar = function MainToolbar(_ref) {
var useStickyToolbar = _ref.useStickyToolbar,
twoLineEditorToolbar = _ref.twoLineEditorToolbar,
children = _ref.children,
isNewToolbarEnabled = _ref.isNewToolbarEnabled;
if (useStickyToolbar) {
return (0, _react2.jsx)(StickyToolbar
// Ignored via go/ees005
// eslint-disable-next-line react/jsx-props-no-spreading
, (0, _extends2.default)({}, getStickyParameters(useStickyToolbar), {
twoLineEditorToolbar: twoLineEditorToolbar,
isNewToolbarEnabled: isNewToolbarEnabled
}), children);
}
return (0, _react2.jsx)(FixedToolbar, {
twoLineEditorToolbar: twoLineEditorToolbar,
isNewToolbarEnabled: isNewToolbarEnabled
}, children);
};