UNPKG

@atlaskit/editor-common

Version:

A package that contains common classes and components for editor and renderer

154 lines (147 loc) • 7.1 kB
"use strict"; var _typeof = require("@babel/runtime/helpers/typeof"); Object.defineProperty(exports, "__esModule", { value: true }); exports.nameStyle = exports.default = exports.containerSelected = exports.containerName = exports.container = exports.ForwardedLinkSearchListItemWithIntl = void 0; var _react = _interopRequireWildcard(require("react")); var _react2 = require("@emotion/react"); var _reactIntl = require("react-intl"); var _editorSharedStyles = require("@atlaskit/editor-shared-styles"); var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals"); var _listItemAlts = require("./listItemAlts"); var _transformTimeStamp = require("./transformTimeStamp"); 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); } /* eslint-disable @atlaskit/ui-styling-standard/use-compiled -- Pre-existing lint debt surfaced by this mechanical type-import-only PR. */ /** * @jsxRuntime classic * @jsx jsx */ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766 // AFP-2532 TODO: Fix automatic suppressions below // eslint-disable-next-line @atlassian/tangerine/import/entry-points // eslint-disable-next-line @atlaskit/ui-styling-standard/no-exported-styles -- Ignored via go/DSP-18766 var container = exports.container = (0, _react2.css)({ backgroundColor: 'transparent', padding: "var(--ds-space-100, 8px)".concat(" ", "var(--ds-space-150, 12px)"), cursor: 'pointer', display: 'flex', marginTop: 0 }); // eslint-disable-next-line @atlaskit/ui-styling-standard/no-exported-styles -- Ignored via go/DSP-18766 var containerSelected = exports.containerSelected = (0, _react2.css)({ backgroundColor: "var(--ds-background-neutral-subtle-hovered, #0515240F)" }); var nameWrapper = (0, _react2.css)({ overflow: 'hidden' }); // eslint-disable-next-line @atlaskit/ui-styling-standard/no-exported-styles -- Ignored via go/DSP-18766 var nameStyle = exports.nameStyle = (0, _react2.css)({ color: "var(--ds-text, #292A2E)", overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', // eslint-disable-next-line @atlaskit/design-system/use-tokens-typography lineHeight: '20px' }); // eslint-disable-next-line @atlaskit/ui-styling-standard/no-exported-styles -- Ignored via go/DSP-18766 var containerName = exports.containerName = (0, _react2.css)({ color: "var(--ds-text-subtlest, #6B6E76)", // eslint-disable-next-line @atlaskit/design-system/use-tokens-typography lineHeight: '14px', // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/ui-styling-standard/no-unsafe-values -- Ignored via go/DSP-18766 fontSize: (0, _editorSharedStyles.relativeFontSizeToBase16)(11) }); var iconStyle = (0, _react2.css)({ minWidth: '16px', marginTop: "var(--ds-space-050, 4px)", marginRight: "var(--ds-space-150, 12px)", // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors -- Ignored via go/DSP-18766 img: { maxWidth: '16px' } }); var LinkSearchListItem = function LinkSearchListItem(props, ref) { var id = props.id, item = props.item, onBlur = props.onBlur, onFocus = props.onFocus, onKeyDown = props.onKeyDown, onMouseEnter = props.onMouseEnter, onMouseLeave = props.onMouseLeave, onMouseMove = props.onMouseMove, onSelect = props.onSelect, selected = props.selected, intl = props.intl; var handleSelect = (0, _react.useCallback)(function (e) { e.preventDefault(); // don't let editor lose focus onSelect(item.url, item.name); }, [onSelect, item.url, item.name]); var handleKeyDown = (0, _react.useCallback)(function (event) { if (event.key === 'Enter') { onSelect(item.url, item.name); } onKeyDown === null || onKeyDown === void 0 || onKeyDown(event); }, [onSelect, onKeyDown, item.url, item.name]); var handleMouseMove = (0, _react.useCallback)(function () { onMouseMove === null || onMouseMove === void 0 || onMouseMove(item.objectId); }, [onMouseMove, item.objectId]); var handleMouseEnter = (0, _react.useCallback)(function () { onMouseEnter === null || onMouseEnter === void 0 || onMouseEnter(item.objectId); }, [onMouseEnter, item.objectId]); var handleMouseLeave = (0, _react.useCallback)(function () { onMouseLeave === null || onMouseLeave === void 0 || onMouseLeave(item.objectId); }, [onMouseLeave, item.objectId]); var renderIcon = function renderIcon() { if (item.icon) { return (0, _react2.jsx)("span", { css: iconStyle }, item.icon); } if (item.iconUrl) { return (0, _react2.jsx)("span", { css: iconStyle }, (0, _react2.jsx)("img", { src: item.iconUrl, alt: (0, _listItemAlts.getCorrectAltByIconUrl)(item.iconUrl, intl) })); } return null; }; var renderTimeStamp = function renderTimeStamp() { var date = (0, _transformTimeStamp.transformTimeStamp)(intl, item.lastViewedDate, item.lastUpdatedDate); return date && (0, _react2.jsx)(_react.Fragment, null, "\xA0 \u2022", (0, _react2.jsx)("span", { // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766 className: "link-search-timestamp", "data-testid": "link-search-timestamp" }, "\xA0 ", date.pageAction, " ", date.dateString, " ", date.timeSince || '')); }; return (0, _react2.jsx)("div", { ref: ref, css: [container, selected && containerSelected], role: 'option', tabIndex: 0, id: id, "aria-selected": selected, "data-testid": "link-search-list-item", onBlur: (0, _expValEquals.expValEquals)('editor_a11y__enghealth-46814_fy26', 'isEnabled', true) ? onBlur : undefined, onFocus: onFocus, onKeyDown: handleKeyDown, onMouseMove: handleMouseMove, onMouseEnter: handleMouseEnter, onMouseLeave: handleMouseLeave, onClick: handleSelect }, renderIcon(), (0, _react2.jsx)("span", { css: nameWrapper }, (0, _react2.jsx)("div", { css: nameStyle }, item.name), (0, _react2.jsx)("div", { "data-testid": "link-search-list-item-container", css: containerName }, item.container, renderTimeStamp()))); }; var ForwardedLinkSearchListItem = /*#__PURE__*/(0, _react.forwardRef)(LinkSearchListItem); var ForwardedLinkSearchListItemWithIntl = exports.ForwardedLinkSearchListItemWithIntl = (0, _reactIntl.injectIntl)(ForwardedLinkSearchListItem, { forwardRef: true }); var _default = exports.default = ForwardedLinkSearchListItemWithIntl;