@atlaskit/editor-plugin-highlight
Version:
Highlight plugin for @atlaskit/editor-core
88 lines (85 loc) • 4.83 kB
JavaScript
"use strict";
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.PaletteDropdown = void 0;
var _react = _interopRequireWildcard(require("react"));
var _uiColor = require("@atlaskit/editor-common/ui-color");
var _uiMenu = require("@atlaskit/editor-common/ui-menu");
var _editorPalette = require("@atlaskit/editor-palette");
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
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" != _typeof(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); }
var HIGHLIGHT_COLOR_PICKER_COLUMNS = 8;
var HIGHLIGHT_COLOR_PICKER_COLUMNS_NEW = 10;
var PaletteDropdown = exports.PaletteDropdown = function PaletteDropdown(props) {
var popupsMountPoint = props.popupsMountPoint,
popupsBoundariesElement = props.popupsBoundariesElement,
popupsScrollableElement = props.popupsScrollableElement,
isOpen = props.isOpen,
activeColor = props.activeColor,
trigger = props.trigger,
onColorChange = props.onColorChange,
isOpenedByKeyboard = props.isOpenedByKeyboard,
handleClickOutside = props.handleClickOutside,
handleEscapeKeydown = props.handleEscapeKeydown;
var isNewColorPaletteEnabled = (0, _expValEquals.expValEquals)('platform_editor_lovability_text_bg_color', 'isEnabled', true);
var isRedHighlightEnabled = (0, _platformFeatureFlags.fg)('platform_editor_lovability_text_bg_color_patch_1');
var highlightPalette = (0, _react.useMemo)(function () {
if (isNewColorPaletteEnabled) {
return _uiColor.highlightColorPaletteNew.filter(function (color) {
if (isRedHighlightEnabled) {
return color.value !== _uiColor.REMOVE_HIGHLIGHT_COLOR;
}
return color.label !== 'Red';
});
}
return _uiColor.highlightColorPalette;
}, [isNewColorPaletteEnabled, isRedHighlightEnabled]);
var colorPickerColumns = isNewColorPaletteEnabled ? HIGHLIGHT_COLOR_PICKER_COLUMNS_NEW : HIGHLIGHT_COLOR_PICKER_COLUMNS;
// pixels, used to determine where to horizontally position the dropdown when space is limited
// this should reflect the width of the dropdown when fully populated with colors, including translations due to layering
var fitWidth = isNewColorPaletteEnabled ? 338 : 274;
// 8 cols: 272 = (32 * 8) + (8 + 8)
// 10 cols: 336 = (32 * 10) + (8 + 8)
// Not sure where the extra 2px comes from
var selectedColor = activeColor || (isNewColorPaletteEnabled ? _uiColor.REMOVE_HIGHLIGHT_COLOR : null);
var _getSelectedRowAndCol = (0, _uiColor.getSelectedRowAndColumnFromPalette)(highlightPalette, selectedColor, colorPickerColumns),
selectedRowIndex = _getSelectedRowAndCol.selectedRowIndex,
selectedColumnIndex = _getSelectedRowAndCol.selectedColumnIndex;
return /*#__PURE__*/_react.default.createElement(_uiMenu.DropdownContainer, {
mountTo: popupsMountPoint,
boundariesElement: popupsBoundariesElement,
scrollableElement: popupsScrollableElement,
isOpen: isOpen,
handleClickOutside: handleClickOutside,
handleEscapeKeydown: handleEscapeKeydown,
zIndex: _editorSharedStyles.akEditorMenuZIndex,
fitWidth: fitWidth,
closeOnTab: true
// eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed)
,
arrowKeyNavigationProviderOptions: {
type: _uiMenu.ArrowKeyNavigationType.COLOR,
selectedRowIndex: selectedRowIndex,
selectedColumnIndex: selectedColumnIndex,
isOpenedByKeyboard: isOpenedByKeyboard,
isPopupPositioned: true
},
trigger: trigger
}, /*#__PURE__*/_react.default.createElement("div", {
"data-testid": "highlight-color-palette"
}, /*#__PURE__*/_react.default.createElement(_uiColor.ColorPalette, {
cols: colorPickerColumns,
onClick: onColorChange,
selectedColor: selectedColor
// eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed)
,
paletteOptions: {
palette: highlightPalette,
hexToPaletteColor: _editorPalette.hexToEditorTextBackgroundPaletteColor
}
})));
};