UNPKG

@atlaskit/renderer

Version:
95 lines 4.5 kB
import _slicedToArray from "@babel/runtime/helpers/slicedToArray"; import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator"; import _regeneratorRuntime from "@babel/runtime/regenerator"; /** * @jsxRuntime classic * @jsx jsx */ import { Fragment, lazy, memo, Suspense, useState } from 'react'; /* eslint-disable @typescript-eslint/consistent-type-imports, @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766; jsx required at runtime for @jsxRuntime classic */ import { jsx } from '@emotion/react'; import { CodeBlockSharedCssClassName } from '@atlaskit/editor-common/styles'; import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals'; import { useInViewport } from '../../hooks/use-in-viewport'; import { useBidiWarnings } from '../../hooks/use-bidi-warnings'; import LightWeightCodeBlock from './components/lightWeightCodeBlock'; import CodeBlockContainer from './components/codeBlockContainer'; var LazyAkCodeBlock = /*#__PURE__*/lazy( /*#__PURE__*/ // Ignored via go/ees005 // eslint-disable-next-line require-await _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() { return _regeneratorRuntime.wrap(function (_context) { while (1) switch (_context.prev = _context.next) { case 0: return _context.abrupt("return", import( /* webpackChunkName: "@atlaskit-internal_renderer-codeBlock" */ '@atlaskit/code/block')); case 1: case "end": return _context.stop(); } }, _callee); }))); var joinWithSpaces = function joinWithSpaces() { for (var _len = arguments.length, strs = new Array(_len), _key = 0; _key < _len; _key++) { strs[_key] = arguments[_key]; } return strs.join(' '); }; var MemoizedLightWeightCodeBlock = /*#__PURE__*/memo(LightWeightCodeBlock); var WindowedCodeBlock = function WindowedCodeBlock(_ref2) { var text = _ref2.text, language = _ref2.language, allowCopyToClipboard = _ref2.allowCopyToClipboard, _ref2$allowWrapCodeBl = _ref2.allowWrapCodeBlock, allowWrapCodeBlock = _ref2$allowWrapCodeBl === void 0 ? false : _ref2$allowWrapCodeBl, codeBidiWarningTooltipEnabled = _ref2.codeBidiWarningTooltipEnabled, _ref2$hideLineNumbers = _ref2.hideLineNumbers, hideLineNumbers = _ref2$hideLineNumbers === void 0 ? false : _ref2$hideLineNumbers, rootClassName = _ref2.className, wrap = _ref2.wrap; var _useBidiWarnings = useBidiWarnings({ enableWarningTooltip: codeBidiWarningTooltipEnabled }), warningLabel = _useBidiWarnings.warningLabel; var _useInViewport = useInViewport(), isInViewport = _useInViewport.isInViewport, trackingRef = _useInViewport.trackingRef; var className = joinWithSpaces(CodeBlockSharedCssClassName.CODEBLOCK_CONTAINER, rootClassName); var memoizedLightWeightCodeBlock = jsx(MemoizedLightWeightCodeBlock, { ref: trackingRef, text: text, codeBidiWarningTooltipEnabled: codeBidiWarningTooltipEnabled, hideLineNumbers: expValEquals('platform_editor_code_block_q4_lovability', 'isEnabled', true) && hideLineNumbers // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766 , className: rootClassName }); var _useState = useState(function () { return expValEquals('platform_editor_code_block_q4_lovability', 'isEnabled', true) && Boolean(wrap); }), _useState2 = _slicedToArray(_useState, 2), wrapLongLines = _useState2[0], setWrapLongLines = _useState2[1]; return isInViewport ? jsx(Fragment, null, jsx(Suspense, { fallback: memoizedLightWeightCodeBlock }, jsx(CodeBlockContainer, { allowCopyToClipboard: allowCopyToClipboard, allowWrapCodeBlock: allowWrapCodeBlock // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766 , className: className, setWrapLongLines: setWrapLongLines, text: text, wrapLongLines: wrapLongLines }, jsx(LazyAkCodeBlock, { language: language, text: text, codeBidiWarningLabel: warningLabel, codeBidiWarningTooltipEnabled: codeBidiWarningTooltipEnabled, shouldWrapLongLines: allowWrapCodeBlock && wrapLongLines, shouldShowLineNumbers: !(expValEquals('platform_editor_code_block_q4_lovability', 'isEnabled', true) && hideLineNumbers), hasBidiWarnings: expValEquals('platform_editor_remove_bidi_char_warning', 'isEnabled', true) ? false : undefined })))) : memoizedLightWeightCodeBlock; }; export default WindowedCodeBlock;