UNPKG

@atlaskit/editor-plugin-quick-insert

Version:

Quick insert plugin for @atlaskit/editor-core

127 lines • 6.18 kB
/* RegistryElementBrowserSearchResults.tsx generated by @compiled/babel-plugin v3.0.2 */ import _defineProperty from "@babel/runtime/helpers/defineProperty"; import "./RegistryElementBrowserSearchResults.compiled.css"; import { ax, ix } from "@compiled/react/runtime"; 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) { _defineProperty(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; } import React, { useMemo } from 'react'; import { useIntl } from 'react-intl'; import LinkButton from '@atlaskit/button/link'; import { QuickInsertProvider } from '@atlaskit/editor-common/quick-insert/provider'; import { Text } from '@atlaskit/primitives/compiled'; import NotFoundIllustration from './NotFoundIllustration'; var resultsGridStyles = null; var emptyStateGridItemStyles = null; var styles = { fallbackMarketplace: "_1i531l7x _15a5nqa1 _uwhke4h9 _19pkpxbi _ca0qpxbi" }; var emptyStateWrapperStyles = null; var emptyStateHeadingStyles = null; var emptyStateSubheadingStyles = null; var emptyStateLinkStyles = null; var RegistryElementBrowserItem = function RegistryElementBrowserItem(_ref) { var editorView = _ref.editorView, isOffline = _ref.isOffline, isSelected = _ref.isSelected, item = _ref.item, onSelect = _ref.onSelect; var _item$registration = item.registration, Component = _item$registration.component, key = _item$registration.key; var contextValue = useMemo(function () { return { editorView: editorView, isOffline: isOffline, item: { description: item.description, id: key, isSelected: isSelected }, select: function select(handler) { return onSelect(key, handler); }, surface: 'element-browser' }; }, [editorView, isOffline, isSelected, item.description, key, onSelect]); if (!Component) { return null; } return /*#__PURE__*/React.createElement(QuickInsertProvider, { value: contextValue }, /*#__PURE__*/React.createElement(Component, undefined, null)); }; export var RegistryElementBrowserSearchResults = function RegistryElementBrowserSearchResults(_ref2) { var _emptyStateHandler; var editorView = _ref2.editorView, emptyStateHandler = _ref2.emptyStateHandler, fallbackItems = _ref2.fallbackItems, _ref2$isLoading = _ref2.isLoading, isLoading = _ref2$isLoading === void 0 ? false : _ref2$isLoading, isOffline = _ref2.isOffline, items = _ref2.items, query = _ref2.query, resultsId = _ref2.resultsId, section = _ref2.section, selectedKey = _ref2.selectedKey, onKeyDown = _ref2.onKeyDown, onSelect = _ref2.onSelect; var _useIntl = useIntl(), formatMessage = _useIntl.formatMessage; var hasFallbackItems = Boolean(!isLoading && items.length === 0 && query.trim().length > 0 && (fallbackItems === null || fallbackItems === void 0 ? void 0 : fallbackItems.length)); var resultsLabel = formatMessage({ defaultMessage: 'Element results', id: 'editor.quick-insert.results-label' }); var displayedItems = hasFallbackItems ? fallbackItems !== null && fallbackItems !== void 0 ? fallbackItems : [] : items; var shouldRenderEmptyState = items.length === 0 && !isLoading; var emptyState = shouldRenderEmptyState ? (_emptyStateHandler = emptyStateHandler === null || emptyStateHandler === void 0 ? void 0 : emptyStateHandler(_objectSpread({ mode: 'full', searchTerm: query, selectedCategory: section }, hasFallbackItems ? { showNoResultsMessage: false } : {}))) !== null && _emptyStateHandler !== void 0 ? _emptyStateHandler : /*#__PURE__*/React.createElement("div", { className: ax(["_4cvr1h6o _1e0c1txw _2lx21bp4 _1bah1h6o _1bsb1osq"]) }, /*#__PURE__*/React.createElement(NotFoundIllustration, null), /*#__PURE__*/React.createElement("div", { className: ax(["_11c81af2 _syazi7uo _19pk1ejb"]) }, formatMessage({ defaultMessage: 'Nothing matches your search', id: 'editor.quick-insert.empty' })), /*#__PURE__*/React.createElement("div", { className: ax(["_19pkpxbi _p12f1kdj _y3gn1h6o"]) }, /*#__PURE__*/React.createElement(Text, null, formatMessage({ defaultMessage: 'Try searching with a different term or discover new apps for Atlassian products.', id: 'editor.quick-insert.empty-description' })), /*#__PURE__*/React.createElement("div", { className: ax(["_19pkutpp"]) }, /*#__PURE__*/React.createElement(LinkButton, { appearance: "primary", href: "https://marketplace.atlassian.com/search?category=Macros&hosting=cloud&product=confluence", target: "_blank" }, formatMessage({ defaultMessage: 'Explore Atlassian Marketplace', id: 'editor.quick-insert.explore-marketplace' }))))) : null; return /*#__PURE__*/React.createElement("div", { "data-testid": "registry-element-browser-results", id: resultsId, tabIndex: -1 }, displayedItems.length > 0 && /*#__PURE__*/React.createElement("div", { "aria-label": resultsLabel, onKeyDown: onKeyDown, role: "listbox", tabIndex: -1, className: ax(["_zulpu2gc _ae4vv2br _4cvrv2br _1e0c11p5 _yv0ei47z _16409sye _g98o1koq"]) }, displayedItems.map(function (item) { return /*#__PURE__*/React.createElement(RegistryElementBrowserItem, { editorView: editorView, isOffline: isOffline, isSelected: selectedKey === item.registration.key, item: item, key: item.registration.key, onSelect: onSelect }); })), emptyState && /*#__PURE__*/React.createElement("div", { className: ax(["_yyhyjvu9 _1ul9idpf _1bsb1osq", hasFallbackItems && styles.fallbackMarketplace]) }, emptyState)); };