@atlaskit/editor-plugin-floating-toolbar
Version:
Floating toolbar plugin for @atlaskit/editor-core
127 lines (119 loc) • 4.46 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.menuItemDimensions = exports.itemSpacing = exports.default = void 0;
var _react = require("react");
var _react2 = require("@emotion/react");
var _reactIntl = require("react-intl");
var _floatingToolbar = require("@atlaskit/editor-common/floating-toolbar");
var _menu = require("@atlaskit/menu");
/**
* @jsxRuntime classic
* @jsx jsx
*/
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
// eslint-disable-next-line @atlaskit/design-system/no-deprecated-imports
var menuItemDimensions = exports.menuItemDimensions = {
width: 175,
height: 32
};
var headingStyles = (0, _react2.css)({
padding: "var(--ds-space-200, 16px)".concat(" 0 ", "var(--ds-space-100, 8px)")
});
// eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage/preview
var menuContainerStyles = (0, _react2.css)({
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values -- Ignored via go/DSP-18766
minWidth: "".concat(menuItemDimensions.width, "px"),
// temporary solution to retain spacing defined by @atlaskit/Item
// eslint-disable-next-line @atlaskit/design-system/no-nested-styles, @atlaskit/ui-styling-standard/no-nested-selectors -- Ignored via go/DSP-18766
'& button': {
minHeight: "var(--ds-space-400, 32px)",
padding: "var(--ds-space-100, 8px)".concat(" ", "var(--ds-space-100, 8px)", " 7px"),
// eslint-disable-next-line @atlaskit/design-system/no-nested-styles, @atlaskit/ui-styling-standard/no-nested-selectors -- Ignored via go/DSP-18766
'& > [data-item-elem-before]': {
marginRight: "var(--ds-space-050, 4px)"
}
}
});
// itemSpacing is used in calculations expecting a number, hence not using a space token
var itemSpacing = exports.itemSpacing = 4;
// Extend the ButtonItem component type to allow mouse events to be accepted from the Typescript check
var Dropdown = /*#__PURE__*/(0, _react.memo)(function (props) {
var hide = props.hide,
dispatchCommand = props.dispatchCommand,
items = props.items,
intl = props.intl,
editorView = props.editorView,
_props$showSelected = props.showSelected,
showSelected = _props$showSelected === void 0 ? true : _props$showSelected,
areAnyNewToolbarFlagsEnabled = props.areAnyNewToolbarFlagsEnabled;
if (areAnyNewToolbarFlagsEnabled) {
return (0, _react2.jsx)("div", {
css: menuContainerStyles,
role: "menu"
}, items
// @ts-ignore
.filter(function (item) {
return item && (!('hidden' in item) || !item.hidden);
}).map(function (item, idx) {
if (!('type' in item)) {
return (0, _react2.jsx)(_floatingToolbar.DropdownMenuItem
// Ignored via go/ees005
// eslint-disable-next-line react/no-array-index-key
, {
key: idx,
item: item,
hide: hide,
dispatchCommand: dispatchCommand,
editorView: editorView,
showSelected: showSelected,
intl: intl
});
}
if (item.type === 'separator') {
// eslint-disable-next-line react/no-array-index-key
return (0, _react2.jsx)(_floatingToolbar.DropdownSeparator, {
key: idx
});
}
if (item.type === 'overflow-dropdown-heading') {
return (0, _react2.jsx)("div", {
key: item.title,
css: headingStyles
}, (0, _react2.jsx)(_menu.HeadingItem, null, item.title));
}
if (item.type === 'custom') {
var dropdownMenuOptions = {
hide: hide,
dispatchCommand: dispatchCommand,
editorView: editorView,
showSelected: showSelected,
intl: intl
};
return item.render(editorView, dropdownMenuOptions);
}
}));
}
return (0, _react2.jsx)("div", {
css: menuContainerStyles,
role: "menu"
}, items.filter(function (item) {
return !item.hidden;
}).map(function (item, idx) {
return (0, _react2.jsx)(_floatingToolbar.DropdownMenuItem
// Ignored via go/ees005
// eslint-disable-next-line react/no-array-index-key
, {
key: idx,
item: item,
hide: hide,
dispatchCommand: dispatchCommand,
editorView: editorView,
showSelected: showSelected,
intl: intl
});
}));
});
var _default_1 = (0, _reactIntl.injectIntl)(Dropdown);
var _default = exports.default = _default_1;