UNPKG

@elastic/eui

Version:

Elastic UI Component Library

71 lines (70 loc) 3.56 kB
var _excluded = ["style"], _excluded2 = ["style"]; function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License * 2.0 and the Server Side Public License, v 1; you may not use this file except * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ import React, { forwardRef, useMemo } from 'react'; import { FixedSizeList } from 'react-window'; import { logicalStyles } from '../../global_styling'; import { EuiAutoSizer } from '../auto_sizer'; import { nodeToHtml } from './utils'; import { jsx as ___EmotionJSX } from "@emotion/react"; export var EuiCodeBlockVirtualized = function EuiCodeBlockVirtualized(_ref) { var data = _ref.data, rowHeight = _ref.rowHeight, overflowHeight = _ref.overflowHeight, preProps = _ref.preProps, codeProps = _ref.codeProps; var VirtualizedOuterElement = useMemo(function () { return /*#__PURE__*/forwardRef(function (_ref2, ref) { var style = _ref2.style, props = _objectWithoutProperties(_ref2, _excluded); return ___EmotionJSX("pre", _extends({ style: logicalStyles(style) }, props, { ref: ref }, preProps)); }); }, [preProps]); var VirtualizedInnerElement = useMemo(function () { return /*#__PURE__*/forwardRef(function (_ref3, ref) { var style = _ref3.style, props = _objectWithoutProperties(_ref3, _excluded2); return ___EmotionJSX("code", _extends({ style: logicalStyles(style) }, props, { ref: ref }, codeProps)); }); }, [codeProps]); return ___EmotionJSX(EuiAutoSizer, { disableHeight: typeof overflowHeight === 'number' }, function (_ref4) { var height = _ref4.height, width = _ref4.width; return ___EmotionJSX(FixedSizeList, { height: height !== null && height !== void 0 ? height : overflowHeight, width: width, itemData: data, itemSize: rowHeight, itemCount: data.length, outerElementType: VirtualizedOuterElement, innerElementType: VirtualizedInnerElement }, ListRow); }); }; var ListRow = function ListRow(_ref5) { var data = _ref5.data, index = _ref5.index, style = _ref5.style; var row = data[index]; row.properties.style = logicalStyles(style); return nodeToHtml(row, index, data, 0); };