@elastic/eui 77.1.4 → 77.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/dist/eui_theme_dark.css +14 -13
  2. package/dist/eui_theme_dark.min.css +1 -1
  3. package/dist/eui_theme_light.css +14 -13
  4. package/dist/eui_theme_light.min.css +1 -1
  5. package/es/components/code/code_block_annotations.js +13 -4
  6. package/es/components/code/code_block_copy.js +14 -2
  7. package/es/components/code/code_block_line.styles.js +1 -1
  8. package/es/components/code/utils.js +29 -17
  9. package/eui.d.ts +19 -3
  10. package/i18ntokens.json +8 -8
  11. package/lib/components/code/code_block_annotations.js +13 -4
  12. package/lib/components/code/code_block_copy.js +14 -2
  13. package/lib/components/code/code_block_line.styles.js +1 -1
  14. package/lib/components/code/utils.js +32 -18
  15. package/optimize/es/components/code/code_block_annotations.js +8 -4
  16. package/optimize/es/components/code/code_block_copy.js +14 -2
  17. package/optimize/es/components/code/code_block_line.styles.js +1 -1
  18. package/optimize/es/components/code/utils.js +29 -17
  19. package/optimize/lib/components/code/code_block_annotations.js +8 -12
  20. package/optimize/lib/components/code/code_block_copy.js +14 -2
  21. package/optimize/lib/components/code/code_block_line.styles.js +1 -1
  22. package/optimize/lib/components/code/utils.js +32 -18
  23. package/package.json +1 -1
  24. package/src/components/table/_table.scss +7 -9
  25. package/test-env/components/code/code_block_annotations.js +12 -12
  26. package/test-env/components/code/code_block_copy.js +14 -2
  27. package/test-env/components/code/code_block_line.styles.js +1 -1
  28. package/test-env/components/code/utils.js +32 -18
@@ -1,3 +1,4 @@
1
+ var _excluded = ["lineNumber", "children"];
1
2
  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); }
2
3
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
3
4
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
@@ -5,6 +6,8 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
5
6
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
6
7
  function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
7
8
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
9
+ 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; }
10
+ 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; }
8
11
  /*
9
12
  * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
10
13
  * or more contributor license agreements. Licensed under the Elastic License
@@ -24,7 +27,8 @@ import { euiCodeBlockAnnotationsStyles } from './code_block_annotations.style';
24
27
  import { jsx as ___EmotionJSX } from "@emotion/react";
25
28
  export var EuiCodeBlockAnnotation = function EuiCodeBlockAnnotation(_ref) {
26
29
  var lineNumber = _ref.lineNumber,
27
- children = _ref.children;
30
+ children = _ref.children,
31
+ rest = _objectWithoutProperties(_ref, _excluded);
28
32
  var _useState = useState(false),
29
33
  _useState2 = _slicedToArray(_useState, 2),
30
34
  isOpen = _useState2[0],
@@ -39,7 +43,9 @@ export var EuiCodeBlockAnnotation = function EuiCodeBlockAnnotation(_ref) {
39
43
  var buttonIconFocusStyle = useEuiButtonFocusCSS();
40
44
  var cssButtonIconStyles = [styles.euiCodeBlockAnnotation__buttonIcon, buttonIconFocusStyle];
41
45
  var isDarkMode = colorMode === 'DARK';
42
- return ___EmotionJSX(EuiPopover, {
46
+ return ___EmotionJSX(EuiPopover, _extends({
47
+ css: styles.euiCodeBlockAnnotation
48
+ }, rest, {
43
49
  isOpen: isOpen,
44
50
  closePopover: function closePopover() {
45
51
  return setIsOpen(false);
@@ -56,16 +62,19 @@ export var EuiCodeBlockAnnotation = function EuiCodeBlockAnnotation(_ref) {
56
62
  size: "s",
57
63
  color: isDarkMode ? euiTheme.colors.ink : 'ghost'
58
64
  })),
59
- css: styles.euiCodeBlockAnnotation,
60
65
  zIndex: Number(euiTheme.levels.mask) + 1 // Ensure fullscreen annotation popovers sit above the mask
61
66
  ,
62
67
  anchorPosition: "downLeft",
63
68
  panelProps: {
64
69
  'data-test-subj': 'euiCodeBlockAnnotationPopover'
65
70
  }
66
- }, children);
71
+ }), children);
67
72
  };
68
73
  EuiCodeBlockAnnotation.propTypes = {
74
+ className: PropTypes.string,
75
+ "aria-label": PropTypes.string,
76
+ "data-test-subj": PropTypes.string,
77
+ css: PropTypes.any,
69
78
  lineNumber: PropTypes.number.isRequired
70
79
  };
71
80
  var AnnotationInfoIcon = function AnnotationInfoIcon(props) {
@@ -17,6 +17,7 @@ import { useInnerText } from '../inner_text';
17
17
  import { EuiCopy } from '../copy';
18
18
  import { useEuiI18n } from '../i18n';
19
19
  import { EuiButtonIcon } from '../button';
20
+ import { NEW_LINE_REGEX_GLOBAL } from './utils';
20
21
 
21
22
  /**
22
23
  * Hook that returns copy-related state/logic/utils
@@ -31,7 +32,17 @@ export var useCopy = function useCopy(_ref) {
31
32
  innerTextRef = _useInnerText2[0],
32
33
  _innerText = _useInnerText2[1];
33
34
  var innerText = useMemo(function () {
34
- return (_innerText === null || _innerText === void 0 ? void 0 : _innerText.replace(/[\r\n?]{2}|\n\n/g, '\n')) || '';
35
+ return (_innerText
36
+ // Normalize line terminations to match native JS format
37
+ === null || _innerText
38
+ // Normalize line terminations to match native JS format
39
+ === void 0 ? void 0 : _innerText
40
+ // Normalize line terminations to match native JS format
41
+ .replace(NEW_LINE_REGEX_GLOBAL, '\n')
42
+ // Reduce two or more consecutive new line characters to a single one
43
+ // This is needed primarily because of how syntax highlighting
44
+ // generated DOM elements affect `innerText` output.
45
+ .replace(/\n{2,}/g, '\n')) || '';
35
46
  }, [_innerText]);
36
47
  var textToCopy = isVirtualized ? "".concat(children) : innerText; // Virtualized code blocks do not have inner text
37
48
 
@@ -47,7 +58,8 @@ export var useCopy = function useCopy(_ref) {
47
58
  onClick: copy,
48
59
  iconType: "copyClipboard",
49
60
  color: "text",
50
- "aria-label": copyAriaLabel
61
+ "aria-label": copyAriaLabel,
62
+ "data-test-subj": "euiCodeBlockCopy"
51
63
  });
52
64
  })) : null;
53
65
  }, [showCopyButton, textToCopy, copyAriaLabel]);
@@ -44,7 +44,7 @@ export var euiCodeBlockLineStyles = function euiCodeBlockLineStyles(euiThemeCont
44
44
  },
45
45
  lineNumber: {
46
46
  euiCodeBlock__lineNumberWrapper: /*#__PURE__*/css("position:relative;flex-grow:0;flex-shrink:0;user-select:none;padding-inline-end:", euiTheme.size.m, ";box-sizing:content-box;;label:euiCodeBlock__lineNumberWrapper;"),
47
- euiCodeBlock__lineNumber: /*#__PURE__*/css("color:", euiTheme.colors.subduedText, ";text-align:end;display:block;;label:euiCodeBlock__lineNumber;")
47
+ euiCodeBlock__lineNumber: /*#__PURE__*/css("color:", euiTheme.colors.subduedText, ";text-align:end;display:block;&::before{content:attr(data-line-number);};label:euiCodeBlock__lineNumber;")
48
48
  }
49
49
  };
50
50
  };
@@ -24,6 +24,22 @@ import { euiCodeBlockLineStyles } from './code_block_line.styles';
24
24
  import { jsx as ___EmotionJSX } from "@emotion/react";
25
25
  export var SUPPORTED_LANGUAGES = listLanguages();
26
26
  export var DEFAULT_LANGUAGE = 'text';
27
+
28
+ /**
29
+ * Platform-agnostic new line regex that safely matches all standard
30
+ * line termination conventions:
31
+ * - LF: Unix-based platforms and JS-native sources like text areas
32
+ * - CRLF: Windows
33
+ * - CR: Mac Classic; to support files saved a long time ago
34
+ */
35
+ export var NEW_LINE_REGEX = /\r\n|\r|\n/;
36
+
37
+ /**
38
+ * Platform-agnostic global new line regex that safely matches all standard
39
+ * line termination conventions.
40
+ * See [NEW_LINE_REGEX]{@link NEW_LINE_REGEX} for more details.
41
+ */
42
+ export var NEW_LINE_REGEX_GLOBAL = new RegExp(NEW_LINE_REGEX, 'g');
27
43
  export var checkSupportedLanguage = function checkSupportedLanguage(language) {
28
44
  return SUPPORTED_LANGUAGES.includes(language) ? language : DEFAULT_LANGUAGE;
29
45
  };
@@ -49,14 +65,12 @@ export var nodeToHtml = function nodeToHtml(node, idx, nodes) {
49
65
  }), children && children.map(function (el, i) {
50
66
  return (
51
67
  // @ts-ignore - using a custom type here to handle JSX annotations
52
- el.type === 'annotation' ?
53
- // @ts-ignore - custom keys are passed by annotationElement below
54
- ___EmotionJSX(EuiCodeBlockAnnotation, {
68
+ el.type === 'annotation' ? ___EmotionJSX(EuiCodeBlockAnnotation, {
69
+ className: "euiCodeBlock__lineAnnotation",
55
70
  lineNumber: el.lineNumber,
56
71
  children: el.annotation,
57
72
  key: i
58
- }) // prettier-ignore
59
- : nodeToHtml(el, i, nodes, depth + 1)
73
+ }) : nodeToHtml(el, i, nodes, depth + 1)
60
74
  );
61
75
  }));
62
76
  }
@@ -93,12 +107,12 @@ var addLineData = function addLineData(nodes, data) {
93
107
  return nodes.reduce(function (result, node) {
94
108
  var lineStart = data.lineNumber;
95
109
  if (node.type === 'text') {
96
- if (!node.value.match(/\r\n?|\n/)) {
110
+ if (!node.value.match(NEW_LINE_REGEX)) {
97
111
  node.lineStart = lineStart;
98
112
  node.lineEnd = lineStart;
99
113
  result.push(node);
100
114
  } else {
101
- var lines = node.value.split(/\r\n?|\n/);
115
+ var lines = node.value.split(NEW_LINE_REGEX);
102
116
  lines.forEach(function (line, i) {
103
117
  var num = i === 0 ? data.lineNumber : ++data.lineNumber;
104
118
  result.push({
@@ -172,11 +186,12 @@ function wrapLines(nodes, options, euiTheme) {
172
186
  var lineNumberWrapperElement = {
173
187
  type: 'element',
174
188
  tagName: 'span',
175
- properties: (_properties = {
189
+ properties: {
176
190
  style: {
177
191
  inlineSize: width
178
- }
179
- }, _defineProperty(_properties, 'data-line-number', lineNumber), _defineProperty(_properties, "className", ['euiCodeBlock__lineNumber', lineNumberWrapperStyles]), _properties),
192
+ },
193
+ className: ['euiCodeBlock__lineNumberWrapper', lineNumberWrapperStyles]
194
+ },
180
195
  children: []
181
196
  };
182
197
 
@@ -185,13 +200,10 @@ function wrapLines(nodes, options, euiTheme) {
185
200
  var lineNumberElement = {
186
201
  type: 'element',
187
202
  tagName: 'span',
188
- properties: _defineProperty({
189
- className: [lineNumberStyles]
190
- }, 'aria-hidden', true),
191
- children: [{
192
- type: 'text',
193
- value: String(lineNumber)
194
- }]
203
+ properties: (_properties = {
204
+ className: ['euiCodeBlock__lineNumber', lineNumberStyles]
205
+ }, _defineProperty(_properties, 'data-line-number', lineNumber), _defineProperty(_properties, 'aria-hidden', true), _properties),
206
+ children: []
195
207
  };
196
208
  lineNumberWrapperElement.children.push(lineNumberElement);
197
209
 
package/eui.d.ts CHANGED
@@ -9259,10 +9259,12 @@ declare module '@elastic/eui/src/components/code/code_block_annotations.style' {
9259
9259
  }
9260
9260
  declare module '@elastic/eui/src/components/code/code_block_annotations' {
9261
9261
  import { FunctionComponent, ReactNode } from 'react';
9262
- export type LineAnnotationMap = Record<number, ReactNode>;
9263
- export const EuiCodeBlockAnnotation: FunctionComponent<{
9262
+ import { CommonProps } from '@elastic/eui/src/components/common';
9263
+ export type LineAnnotationMap = Record<number, ReactNode>; type EuiCodeBlockAnnotationProps = CommonProps & {
9264
9264
  lineNumber: number;
9265
- }>;
9265
+ };
9266
+ export const EuiCodeBlockAnnotation: FunctionComponent<EuiCodeBlockAnnotationProps>;
9267
+ export {};
9266
9268
 
9267
9269
  }
9268
9270
  declare module '@elastic/eui/src/components/code/code_block_line.styles' {
@@ -9300,6 +9302,20 @@ declare module '@elastic/eui/src/components/code/utils' {
9300
9302
  };
9301
9303
  export const SUPPORTED_LANGUAGES: string[];
9302
9304
  export const DEFAULT_LANGUAGE = "text";
9305
+ /**
9306
+ * Platform-agnostic new line regex that safely matches all standard
9307
+ * line termination conventions:
9308
+ * - LF: Unix-based platforms and JS-native sources like text areas
9309
+ * - CRLF: Windows
9310
+ * - CR: Mac Classic; to support files saved a long time ago
9311
+ */
9312
+ export const NEW_LINE_REGEX: RegExp;
9313
+ /**
9314
+ * Platform-agnostic global new line regex that safely matches all standard
9315
+ * line termination conventions.
9316
+ * See [NEW_LINE_REGEX]{@link NEW_LINE_REGEX} for more details.
9317
+ */
9318
+ export const NEW_LINE_REGEX_GLOBAL: RegExp;
9303
9319
  export const checkSupportedLanguage: (language: string) => string;
9304
9320
  export const getHtmlContent: (data: RefractorNode[], children: ReactNode) => ReactElement[] | ReactNode;
9305
9321
  export const isAstElement: (node: RefractorNode) => node is AST.Element;
package/i18ntokens.json CHANGED
@@ -347,14 +347,14 @@
347
347
  "highlighting": "string",
348
348
  "loc": {
349
349
  "start": {
350
- "line": 26,
350
+ "line": 33,
351
351
  "column": 20,
352
- "index": 1005
352
+ "index": 1140
353
353
  },
354
354
  "end": {
355
- "line": 30,
355
+ "line": 37,
356
356
  "column": 3,
357
- "index": 1141
357
+ "index": 1276
358
358
  }
359
359
  },
360
360
  "filepath": "src/components/code/code_block_annotations.tsx"
@@ -365,14 +365,14 @@
365
365
  "highlighting": "string",
366
366
  "loc": {
367
367
  "start": {
368
- "line": 36,
368
+ "line": 44,
369
369
  "column": 24,
370
- "index": 1143
370
+ "index": 1519
371
371
  },
372
372
  "end": {
373
- "line": 36,
373
+ "line": 44,
374
374
  "column": 67,
375
- "index": 1186
375
+ "index": 1562
376
376
  }
377
377
  },
378
378
  "filepath": "src/components/code/code_block_copy.tsx"
@@ -14,6 +14,7 @@ var _icon = require("../icon");
14
14
  var _button = require("../../themes/amsterdam/global_styling/mixins/button");
15
15
  var _code_block_annotations = require("./code_block_annotations.style");
16
16
  var _react2 = require("@emotion/react");
17
+ var _excluded = ["lineNumber", "children"];
17
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
19
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
19
20
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -24,9 +25,12 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
24
25
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
25
26
  function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
26
27
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
28
+ 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; }
29
+ 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; }
27
30
  var EuiCodeBlockAnnotation = function EuiCodeBlockAnnotation(_ref) {
28
31
  var lineNumber = _ref.lineNumber,
29
- children = _ref.children;
32
+ children = _ref.children,
33
+ rest = _objectWithoutProperties(_ref, _excluded);
30
34
  var _useState = (0, _react.useState)(false),
31
35
  _useState2 = _slicedToArray(_useState, 2),
32
36
  isOpen = _useState2[0],
@@ -41,7 +45,9 @@ var EuiCodeBlockAnnotation = function EuiCodeBlockAnnotation(_ref) {
41
45
  var buttonIconFocusStyle = (0, _button.useEuiButtonFocusCSS)();
42
46
  var cssButtonIconStyles = [styles.euiCodeBlockAnnotation__buttonIcon, buttonIconFocusStyle];
43
47
  var isDarkMode = colorMode === 'DARK';
44
- return (0, _react2.jsx)(_popover.EuiPopover, {
48
+ return (0, _react2.jsx)(_popover.EuiPopover, _extends({
49
+ css: styles.euiCodeBlockAnnotation
50
+ }, rest, {
45
51
  isOpen: isOpen,
46
52
  closePopover: function closePopover() {
47
53
  return setIsOpen(false);
@@ -58,17 +64,20 @@ var EuiCodeBlockAnnotation = function EuiCodeBlockAnnotation(_ref) {
58
64
  size: "s",
59
65
  color: isDarkMode ? euiTheme.colors.ink : 'ghost'
60
66
  })),
61
- css: styles.euiCodeBlockAnnotation,
62
67
  zIndex: Number(euiTheme.levels.mask) + 1 // Ensure fullscreen annotation popovers sit above the mask
63
68
  ,
64
69
  anchorPosition: "downLeft",
65
70
  panelProps: {
66
71
  'data-test-subj': 'euiCodeBlockAnnotationPopover'
67
72
  }
68
- }, children);
73
+ }), children);
69
74
  };
70
75
  exports.EuiCodeBlockAnnotation = EuiCodeBlockAnnotation;
71
76
  EuiCodeBlockAnnotation.propTypes = {
77
+ className: _propTypes.default.string,
78
+ "aria-label": _propTypes.default.string,
79
+ "data-test-subj": _propTypes.default.string,
80
+ css: _propTypes.default.any,
72
81
  lineNumber: _propTypes.default.number.isRequired
73
82
  };
74
83
  var AnnotationInfoIcon = function AnnotationInfoIcon(props) {
@@ -10,6 +10,7 @@ var _inner_text = require("../inner_text");
10
10
  var _copy = require("../copy");
11
11
  var _i18n = require("../i18n");
12
12
  var _button = require("../button");
13
+ var _utils = require("./utils");
13
14
  var _react2 = require("@emotion/react");
14
15
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
15
16
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -31,7 +32,17 @@ var useCopy = function useCopy(_ref) {
31
32
  innerTextRef = _useInnerText2[0],
32
33
  _innerText = _useInnerText2[1];
33
34
  var innerText = (0, _react.useMemo)(function () {
34
- return (_innerText === null || _innerText === void 0 ? void 0 : _innerText.replace(/[\r\n?]{2}|\n\n/g, '\n')) || '';
35
+ return (_innerText
36
+ // Normalize line terminations to match native JS format
37
+ === null || _innerText
38
+ // Normalize line terminations to match native JS format
39
+ === void 0 ? void 0 : _innerText
40
+ // Normalize line terminations to match native JS format
41
+ .replace(_utils.NEW_LINE_REGEX_GLOBAL, '\n')
42
+ // Reduce two or more consecutive new line characters to a single one
43
+ // This is needed primarily because of how syntax highlighting
44
+ // generated DOM elements affect `innerText` output.
45
+ .replace(/\n{2,}/g, '\n')) || '';
35
46
  }, [_innerText]);
36
47
  var textToCopy = isVirtualized ? "".concat(children) : innerText; // Virtualized code blocks do not have inner text
37
48
 
@@ -47,7 +58,8 @@ var useCopy = function useCopy(_ref) {
47
58
  onClick: copy,
48
59
  iconType: "copyClipboard",
49
60
  color: "text",
50
- "aria-label": copyAriaLabel
61
+ "aria-label": copyAriaLabel,
62
+ "data-test-subj": "euiCodeBlockCopy"
51
63
  });
52
64
  })) : null;
53
65
  }, [showCopyButton, textToCopy, copyAriaLabel]);
@@ -35,7 +35,7 @@ var euiCodeBlockLineStyles = function euiCodeBlockLineStyles(euiThemeContext) {
35
35
  },
36
36
  lineNumber: {
37
37
  euiCodeBlock__lineNumberWrapper: /*#__PURE__*/(0, _css.css)("position:relative;flex-grow:0;flex-shrink:0;user-select:none;padding-inline-end:", euiTheme.size.m, ";box-sizing:content-box;;label:euiCodeBlock__lineNumberWrapper;"),
38
- euiCodeBlock__lineNumber: /*#__PURE__*/(0, _css.css)("color:", euiTheme.colors.subduedText, ";text-align:end;display:block;;label:euiCodeBlock__lineNumber;")
38
+ euiCodeBlock__lineNumber: /*#__PURE__*/(0, _css.css)("color:", euiTheme.colors.subduedText, ";text-align:end;display:block;&::before{content:attr(data-line-number);};label:euiCodeBlock__lineNumber;")
39
39
  }
40
40
  };
41
41
  };
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.parseLineRanges = exports.nodeToHtml = exports.isAstElement = exports.highlightByLine = exports.getHtmlContent = exports.checkSupportedLanguage = exports.SUPPORTED_LANGUAGES = exports.DEFAULT_LANGUAGE = void 0;
6
+ exports.parseLineRanges = exports.nodeToHtml = exports.isAstElement = exports.highlightByLine = exports.getHtmlContent = exports.checkSupportedLanguage = exports.SUPPORTED_LANGUAGES = exports.NEW_LINE_REGEX_GLOBAL = exports.NEW_LINE_REGEX = exports.DEFAULT_LANGUAGE = void 0;
7
7
  var _react = _interopRequireWildcard(require("react"));
8
8
  var _refractor = require("refractor");
9
9
  var _css = require("@emotion/css");
@@ -21,7 +21,25 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
21
21
  var SUPPORTED_LANGUAGES = (0, _refractor.listLanguages)();
22
22
  exports.SUPPORTED_LANGUAGES = SUPPORTED_LANGUAGES;
23
23
  var DEFAULT_LANGUAGE = 'text';
24
+
25
+ /**
26
+ * Platform-agnostic new line regex that safely matches all standard
27
+ * line termination conventions:
28
+ * - LF: Unix-based platforms and JS-native sources like text areas
29
+ * - CRLF: Windows
30
+ * - CR: Mac Classic; to support files saved a long time ago
31
+ */
24
32
  exports.DEFAULT_LANGUAGE = DEFAULT_LANGUAGE;
33
+ var NEW_LINE_REGEX = /\r\n|\r|\n/;
34
+
35
+ /**
36
+ * Platform-agnostic global new line regex that safely matches all standard
37
+ * line termination conventions.
38
+ * See [NEW_LINE_REGEX]{@link NEW_LINE_REGEX} for more details.
39
+ */
40
+ exports.NEW_LINE_REGEX = NEW_LINE_REGEX;
41
+ var NEW_LINE_REGEX_GLOBAL = new RegExp(NEW_LINE_REGEX, 'g');
42
+ exports.NEW_LINE_REGEX_GLOBAL = NEW_LINE_REGEX_GLOBAL;
25
43
  var checkSupportedLanguage = function checkSupportedLanguage(language) {
26
44
  return SUPPORTED_LANGUAGES.includes(language) ? language : DEFAULT_LANGUAGE;
27
45
  };
@@ -50,14 +68,12 @@ var nodeToHtml = function nodeToHtml(node, idx, nodes) {
50
68
  }), children && children.map(function (el, i) {
51
69
  return (
52
70
  // @ts-ignore - using a custom type here to handle JSX annotations
53
- el.type === 'annotation' ?
54
- // @ts-ignore - custom keys are passed by annotationElement below
55
- (0, _react2.jsx)(_code_block_annotations.EuiCodeBlockAnnotation, {
71
+ el.type === 'annotation' ? (0, _react2.jsx)(_code_block_annotations.EuiCodeBlockAnnotation, {
72
+ className: "euiCodeBlock__lineAnnotation",
56
73
  lineNumber: el.lineNumber,
57
74
  children: el.annotation,
58
75
  key: i
59
- }) // prettier-ignore
60
- : nodeToHtml(el, i, nodes, depth + 1)
76
+ }) : nodeToHtml(el, i, nodes, depth + 1)
61
77
  );
62
78
  }));
63
79
  }
@@ -95,12 +111,12 @@ var addLineData = function addLineData(nodes, data) {
95
111
  return nodes.reduce(function (result, node) {
96
112
  var lineStart = data.lineNumber;
97
113
  if (node.type === 'text') {
98
- if (!node.value.match(/\r\n?|\n/)) {
114
+ if (!node.value.match(NEW_LINE_REGEX)) {
99
115
  node.lineStart = lineStart;
100
116
  node.lineEnd = lineStart;
101
117
  result.push(node);
102
118
  } else {
103
- var lines = node.value.split(/\r\n?|\n/);
119
+ var lines = node.value.split(NEW_LINE_REGEX);
104
120
  lines.forEach(function (line, i) {
105
121
  var num = i === 0 ? data.lineNumber : ++data.lineNumber;
106
122
  result.push({
@@ -174,11 +190,12 @@ function wrapLines(nodes, options, euiTheme) {
174
190
  var lineNumberWrapperElement = {
175
191
  type: 'element',
176
192
  tagName: 'span',
177
- properties: (_properties = {
193
+ properties: {
178
194
  style: {
179
195
  inlineSize: width
180
- }
181
- }, _defineProperty(_properties, 'data-line-number', lineNumber), _defineProperty(_properties, "className", ['euiCodeBlock__lineNumber', lineNumberWrapperStyles]), _properties),
196
+ },
197
+ className: ['euiCodeBlock__lineNumberWrapper', lineNumberWrapperStyles]
198
+ },
182
199
  children: []
183
200
  };
184
201
 
@@ -187,13 +204,10 @@ function wrapLines(nodes, options, euiTheme) {
187
204
  var lineNumberElement = {
188
205
  type: 'element',
189
206
  tagName: 'span',
190
- properties: _defineProperty({
191
- className: [lineNumberStyles]
192
- }, 'aria-hidden', true),
193
- children: [{
194
- type: 'text',
195
- value: String(lineNumber)
196
- }]
207
+ properties: (_properties = {
208
+ className: ['euiCodeBlock__lineNumber', lineNumberStyles]
209
+ }, _defineProperty(_properties, 'data-line-number', lineNumber), _defineProperty(_properties, 'aria-hidden', true), _properties),
210
+ children: []
197
211
  };
198
212
  lineNumberWrapperElement.children.push(lineNumberElement);
199
213
 
@@ -1,5 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
4
+ var _excluded = ["lineNumber", "children"];
3
5
  /*
4
6
  * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
5
7
  * or more contributor license agreements. Licensed under the Elastic License
@@ -18,7 +20,8 @@ import { euiCodeBlockAnnotationsStyles } from './code_block_annotations.style';
18
20
  import { jsx as ___EmotionJSX } from "@emotion/react";
19
21
  export var EuiCodeBlockAnnotation = function EuiCodeBlockAnnotation(_ref) {
20
22
  var lineNumber = _ref.lineNumber,
21
- children = _ref.children;
23
+ children = _ref.children,
24
+ rest = _objectWithoutProperties(_ref, _excluded);
22
25
  var _useState = useState(false),
23
26
  _useState2 = _slicedToArray(_useState, 2),
24
27
  isOpen = _useState2[0],
@@ -33,7 +36,9 @@ export var EuiCodeBlockAnnotation = function EuiCodeBlockAnnotation(_ref) {
33
36
  var buttonIconFocusStyle = useEuiButtonFocusCSS();
34
37
  var cssButtonIconStyles = [styles.euiCodeBlockAnnotation__buttonIcon, buttonIconFocusStyle];
35
38
  var isDarkMode = colorMode === 'DARK';
36
- return ___EmotionJSX(EuiPopover, {
39
+ return ___EmotionJSX(EuiPopover, _extends({
40
+ css: styles.euiCodeBlockAnnotation
41
+ }, rest, {
37
42
  isOpen: isOpen,
38
43
  closePopover: function closePopover() {
39
44
  return setIsOpen(false);
@@ -50,14 +55,13 @@ export var EuiCodeBlockAnnotation = function EuiCodeBlockAnnotation(_ref) {
50
55
  size: "s",
51
56
  color: isDarkMode ? euiTheme.colors.ink : 'ghost'
52
57
  })),
53
- css: styles.euiCodeBlockAnnotation,
54
58
  zIndex: Number(euiTheme.levels.mask) + 1 // Ensure fullscreen annotation popovers sit above the mask
55
59
  ,
56
60
  anchorPosition: "downLeft",
57
61
  panelProps: {
58
62
  'data-test-subj': 'euiCodeBlockAnnotationPopover'
59
63
  }
60
- }, children);
64
+ }), children);
61
65
  };
62
66
  var AnnotationInfoIcon = function AnnotationInfoIcon(props) {
63
67
  return ___EmotionJSX("svg", _extends({
@@ -12,6 +12,7 @@ import { useInnerText } from '../inner_text';
12
12
  import { EuiCopy } from '../copy';
13
13
  import { useEuiI18n } from '../i18n';
14
14
  import { EuiButtonIcon } from '../button';
15
+ import { NEW_LINE_REGEX_GLOBAL } from './utils';
15
16
 
16
17
  /**
17
18
  * Hook that returns copy-related state/logic/utils
@@ -26,7 +27,17 @@ export var useCopy = function useCopy(_ref) {
26
27
  innerTextRef = _useInnerText2[0],
27
28
  _innerText = _useInnerText2[1];
28
29
  var innerText = useMemo(function () {
29
- return (_innerText === null || _innerText === void 0 ? void 0 : _innerText.replace(/[\r\n?]{2}|\n\n/g, '\n')) || '';
30
+ return (_innerText
31
+ // Normalize line terminations to match native JS format
32
+ === null || _innerText
33
+ // Normalize line terminations to match native JS format
34
+ === void 0 ? void 0 : _innerText
35
+ // Normalize line terminations to match native JS format
36
+ .replace(NEW_LINE_REGEX_GLOBAL, '\n')
37
+ // Reduce two or more consecutive new line characters to a single one
38
+ // This is needed primarily because of how syntax highlighting
39
+ // generated DOM elements affect `innerText` output.
40
+ .replace(/\n{2,}/g, '\n')) || '';
30
41
  }, [_innerText]);
31
42
  var textToCopy = isVirtualized ? "".concat(children) : innerText; // Virtualized code blocks do not have inner text
32
43
 
@@ -42,7 +53,8 @@ export var useCopy = function useCopy(_ref) {
42
53
  onClick: copy,
43
54
  iconType: "copyClipboard",
44
55
  color: "text",
45
- "aria-label": copyAriaLabel
56
+ "aria-label": copyAriaLabel,
57
+ "data-test-subj": "euiCodeBlockCopy"
46
58
  });
47
59
  })) : null;
48
60
  }, [showCopyButton, textToCopy, copyAriaLabel]);
@@ -44,7 +44,7 @@ export var euiCodeBlockLineStyles = function euiCodeBlockLineStyles(euiThemeCont
44
44
  },
45
45
  lineNumber: {
46
46
  euiCodeBlock__lineNumberWrapper: /*#__PURE__*/css("position:relative;flex-grow:0;flex-shrink:0;user-select:none;padding-inline-end:", euiTheme.size.m, ";box-sizing:content-box;;label:euiCodeBlock__lineNumberWrapper;"),
47
- euiCodeBlock__lineNumber: /*#__PURE__*/css("color:", euiTheme.colors.subduedText, ";text-align:end;display:block;;label:euiCodeBlock__lineNumber;")
47
+ euiCodeBlock__lineNumber: /*#__PURE__*/css("color:", euiTheme.colors.subduedText, ";text-align:end;display:block;&::before{content:attr(data-line-number);};label:euiCodeBlock__lineNumber;")
48
48
  }
49
49
  };
50
50
  };