@elastic/eui 77.1.3 → 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 (33) 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/es/components/datagrid/body/data_grid_cell.js +7 -2
  10. package/eui.d.ts +19 -3
  11. package/i18ntokens.json +12 -12
  12. package/lib/components/code/code_block_annotations.js +13 -4
  13. package/lib/components/code/code_block_copy.js +14 -2
  14. package/lib/components/code/code_block_line.styles.js +1 -1
  15. package/lib/components/code/utils.js +32 -18
  16. package/lib/components/datagrid/body/data_grid_cell.js +7 -2
  17. package/optimize/es/components/code/code_block_annotations.js +8 -4
  18. package/optimize/es/components/code/code_block_copy.js +14 -2
  19. package/optimize/es/components/code/code_block_line.styles.js +1 -1
  20. package/optimize/es/components/code/utils.js +29 -17
  21. package/optimize/es/components/datagrid/body/data_grid_cell.js +6 -2
  22. package/optimize/lib/components/code/code_block_annotations.js +8 -12
  23. package/optimize/lib/components/code/code_block_copy.js +14 -2
  24. package/optimize/lib/components/code/code_block_line.styles.js +1 -1
  25. package/optimize/lib/components/code/utils.js +32 -18
  26. package/optimize/lib/components/datagrid/body/data_grid_cell.js +6 -2
  27. package/package.json +1 -1
  28. package/src/components/table/_table.scss +7 -9
  29. package/test-env/components/code/code_block_annotations.js +12 -12
  30. package/test-env/components/code/code_block_copy.js +14 -2
  31. package/test-env/components/code/code_block_line.styles.js +1 -1
  32. package/test-env/components/code/utils.js +32 -18
  33. package/test-env/components/datagrid/body/data_grid_cell.js +7 -2
@@ -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
 
@@ -1,5 +1,5 @@
1
1
  function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
- var _excluded = ["renderCellValue", "column", "setCellContentsRef", "rowHeightsOptions", "rowIndex", "colIndex", "ariaRowIndex", "rowHeightUtils", "isDefinedHeight"],
2
+ var _excluded = ["renderCellValue", "column", "setCellContentsRef", "rowHeightsOptions", "rowIndex", "colIndex", "ariaRowIndex", "rowHeightUtils", "isDefinedHeight", "isFocused"],
3
3
  _excluded2 = ["width", "popoverContext", "interactiveCellId", "columnType", "className", "column", "style", "rowHeightUtils", "rowHeightsOptions", "rowManager", "pagination"],
4
4
  _excluded3 = ["isExpandable", "style", "className", "data-test-subj"];
5
5
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
@@ -53,6 +53,7 @@ var EuiDataGridCellContent = /*#__PURE__*/memo(function (_ref) {
53
53
  ariaRowIndex = _ref.ariaRowIndex,
54
54
  rowHeightUtils = _ref.rowHeightUtils,
55
55
  isDefinedHeight = _ref.isDefinedHeight,
56
+ isFocused = _ref.isFocused,
56
57
  rest = _objectWithoutProperties(_ref, _excluded);
57
58
  // React is more permissible than the TS types indicate
58
59
  var CellElement = renderCellValue;
@@ -67,7 +68,9 @@ var EuiDataGridCellContent = /*#__PURE__*/memo(function (_ref) {
67
68
  rowIndex: rowIndex,
68
69
  colIndex: colIndex,
69
70
  schema: (column === null || column === void 0 ? void 0 : column.schema) || rest.columnType
70
- }, rest))), ___EmotionJSX(EuiScreenReaderOnly, null, ___EmotionJSX("p", null, '- ', ___EmotionJSX(EuiI18n, {
71
+ }, rest))), ___EmotionJSX(EuiScreenReaderOnly, null, ___EmotionJSX("p", {
72
+ hidden: !isFocused
73
+ }, '- ', ___EmotionJSX(EuiI18n, {
71
74
  token: "euiDataGridCell.position",
72
75
  default: "{columnId}, column {col}, row {row}",
73
76
  values: {
@@ -556,6 +559,7 @@ EuiDataGridCellContent.propTypes = {
556
559
  setCellContentsRef: PropTypes.any.isRequired,
557
560
  isExpanded: PropTypes.bool.isRequired,
558
561
  isDefinedHeight: PropTypes.bool.isRequired,
562
+ isFocused: PropTypes.bool.isRequired,
559
563
  ariaRowIndex: PropTypes.number.isRequired
560
564
  };
561
565
  export var EuiDataGridCell = /*#__PURE__*/function (_Component) {
@@ -1014,6 +1018,7 @@ export var EuiDataGridCell = /*#__PURE__*/function (_Component) {
1014
1018
  isExpandable: isExpandable,
1015
1019
  isExpanded: popoverIsOpen,
1016
1020
  isDetails: false,
1021
+ isFocused: this.state.isFocused,
1017
1022
  setCellContentsRef: this.setCellContentsRef,
1018
1023
  rowHeightsOptions: rowHeightsOptions,
1019
1024
  rowHeightUtils: rowHeightUtils,
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"
@@ -977,14 +977,14 @@
977
977
  "highlighting": "string",
978
978
  "loc": {
979
979
  "start": {
980
- "line": 98,
980
+ "line": 100,
981
981
  "column": 12,
982
- "index": 2913
982
+ "index": 2972
983
983
  },
984
984
  "end": {
985
- "line": 106,
985
+ "line": 108,
986
986
  "column": 14,
987
- "index": 3220
987
+ "index": 3279
988
988
  }
989
989
  },
990
990
  "filepath": "src/components/datagrid/body/data_grid_cell.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
 
@@ -20,7 +20,7 @@ var _data_grid_cell_actions = require("./data_grid_cell_actions");
20
20
  var _data_grid_cell_popover = require("./data_grid_cell_popover");
21
21
  var _utils = require("../../../utils");
22
22
  var _react2 = require("@emotion/react");
23
- var _excluded = ["renderCellValue", "column", "setCellContentsRef", "rowHeightsOptions", "rowIndex", "colIndex", "ariaRowIndex", "rowHeightUtils", "isDefinedHeight"],
23
+ var _excluded = ["renderCellValue", "column", "setCellContentsRef", "rowHeightsOptions", "rowIndex", "colIndex", "ariaRowIndex", "rowHeightUtils", "isDefinedHeight", "isFocused"],
24
24
  _excluded2 = ["width", "popoverContext", "interactiveCellId", "columnType", "className", "column", "style", "rowHeightUtils", "rowHeightsOptions", "rowManager", "pagination"],
25
25
  _excluded3 = ["isExpandable", "style", "className", "data-test-subj"];
26
26
  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); }
@@ -54,6 +54,7 @@ var EuiDataGridCellContent = /*#__PURE__*/(0, _react.memo)(function (_ref) {
54
54
  ariaRowIndex = _ref.ariaRowIndex,
55
55
  rowHeightUtils = _ref.rowHeightUtils,
56
56
  isDefinedHeight = _ref.isDefinedHeight,
57
+ isFocused = _ref.isFocused,
57
58
  rest = _objectWithoutProperties(_ref, _excluded);
58
59
  // React is more permissible than the TS types indicate
59
60
  var CellElement = renderCellValue;
@@ -68,7 +69,9 @@ var EuiDataGridCellContent = /*#__PURE__*/(0, _react.memo)(function (_ref) {
68
69
  rowIndex: rowIndex,
69
70
  colIndex: colIndex,
70
71
  schema: (column === null || column === void 0 ? void 0 : column.schema) || rest.columnType
71
- }, rest))), (0, _react2.jsx)(_accessibility.EuiScreenReaderOnly, null, (0, _react2.jsx)("p", null, '- ', (0, _react2.jsx)(_i18n.EuiI18n, {
72
+ }, rest))), (0, _react2.jsx)(_accessibility.EuiScreenReaderOnly, null, (0, _react2.jsx)("p", {
73
+ hidden: !isFocused
74
+ }, '- ', (0, _react2.jsx)(_i18n.EuiI18n, {
72
75
  token: "euiDataGridCell.position",
73
76
  default: "{columnId}, column {col}, row {row}",
74
77
  values: {
@@ -557,6 +560,7 @@ EuiDataGridCellContent.propTypes = {
557
560
  setCellContentsRef: _propTypes.default.any.isRequired,
558
561
  isExpanded: _propTypes.default.bool.isRequired,
559
562
  isDefinedHeight: _propTypes.default.bool.isRequired,
563
+ isFocused: _propTypes.default.bool.isRequired,
560
564
  ariaRowIndex: _propTypes.default.number.isRequired
561
565
  };
562
566
  var EuiDataGridCell = /*#__PURE__*/function (_Component) {
@@ -1015,6 +1019,7 @@ var EuiDataGridCell = /*#__PURE__*/function (_Component) {
1015
1019
  isExpandable: isExpandable,
1016
1020
  isExpanded: popoverIsOpen,
1017
1021
  isDetails: false,
1022
+ isFocused: this.state.isFocused,
1018
1023
  setCellContentsRef: this.setCellContentsRef,
1019
1024
  rowHeightsOptions: rowHeightsOptions,
1020
1025
  rowHeightUtils: rowHeightUtils,
@@ -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({