@elastic/eui 95.9.0 → 95.10.0

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 (101) hide show
  1. package/dist/eui_theme_dark.css +35 -6
  2. package/dist/eui_theme_dark.min.css +1 -1
  3. package/dist/eui_theme_light.css +35 -6
  4. package/dist/eui_theme_light.min.css +1 -1
  5. package/es/components/basic_table/in_memory_table.js +2 -1
  6. package/es/components/datagrid/body/cell/data_grid_cell.js +2 -0
  7. package/es/components/datagrid/body/cell/focus_utils.js +57 -11
  8. package/es/components/datagrid/body/data_grid_body.js +1 -0
  9. package/es/components/datagrid/body/data_grid_body_custom.js +1 -0
  10. package/es/components/datagrid/body/data_grid_body_virtualized.js +1 -0
  11. package/es/components/datagrid/body/header/data_grid_header_cell.js +92 -83
  12. package/es/components/datagrid/body/header/data_grid_header_cell_wrapper.js +37 -22
  13. package/es/components/datagrid/controls/column_sorting.js +1 -0
  14. package/es/components/datagrid/data_grid.a11y.js +2 -0
  15. package/es/components/datagrid/utils/in_memory.js +1 -0
  16. package/es/components/date_picker/date_picker.js +32 -10
  17. package/es/components/date_picker/date_picker.styles.js +3 -2
  18. package/es/components/date_picker/date_picker_range.styles.js +1 -1
  19. package/es/components/form/super_select/super_select.styles.js +1 -1
  20. package/es/components/markdown_editor/plugins/markdown_default_plugins/parsing_plugins.js +15 -8
  21. package/es/components/markdown_editor/plugins/markdown_default_plugins/plugins.js +21 -4
  22. package/es/components/markdown_editor/plugins/markdown_default_plugins/processing_plugins.js +5 -2
  23. package/es/components/markdown_editor/plugins/markdown_link_validator.js +8 -2
  24. package/es/components/search_bar/filters/field_value_selection_filter.js +171 -152
  25. package/es/components/search_bar/search_bar.js +2 -1
  26. package/es/components/search_bar/search_filters.js +2 -1
  27. package/eui.d.ts +138 -69
  28. package/i18ntokens.json +78 -42
  29. package/lib/components/basic_table/in_memory_table.js +2 -1
  30. package/lib/components/datagrid/body/cell/data_grid_cell.js +2 -0
  31. package/lib/components/datagrid/body/cell/focus_utils.js +58 -12
  32. package/lib/components/datagrid/body/data_grid_body.js +1 -0
  33. package/lib/components/datagrid/body/data_grid_body_custom.js +1 -0
  34. package/lib/components/datagrid/body/data_grid_body_virtualized.js +1 -0
  35. package/lib/components/datagrid/body/header/data_grid_header_cell.js +98 -88
  36. package/lib/components/datagrid/body/header/data_grid_header_cell_wrapper.js +38 -23
  37. package/lib/components/datagrid/controls/column_sorting.js +1 -0
  38. package/lib/components/datagrid/data_grid.a11y.js +2 -0
  39. package/lib/components/datagrid/utils/in_memory.js +1 -0
  40. package/lib/components/date_picker/date_picker.js +32 -10
  41. package/lib/components/date_picker/date_picker.styles.js +3 -2
  42. package/lib/components/date_picker/date_picker_range.styles.js +1 -1
  43. package/lib/components/form/super_select/super_select.styles.js +1 -1
  44. package/lib/components/markdown_editor/plugins/markdown_default_plugins/parsing_plugins.js +26 -17
  45. package/lib/components/markdown_editor/plugins/markdown_default_plugins/plugins.js +21 -6
  46. package/lib/components/markdown_editor/plugins/markdown_default_plugins/processing_plugins.js +5 -2
  47. package/lib/components/markdown_editor/plugins/markdown_link_validator.js +9 -2
  48. package/lib/components/search_bar/filters/field_value_selection_filter.js +170 -151
  49. package/lib/components/search_bar/search_bar.js +2 -1
  50. package/lib/components/search_bar/search_filters.js +2 -1
  51. package/optimize/es/components/datagrid/body/cell/focus_utils.js +55 -10
  52. package/optimize/es/components/datagrid/body/header/data_grid_header_cell.js +90 -83
  53. package/optimize/es/components/datagrid/body/header/data_grid_header_cell_wrapper.js +33 -19
  54. package/optimize/es/components/datagrid/data_grid.a11y.js +2 -0
  55. package/optimize/es/components/date_picker/date_picker.js +15 -9
  56. package/optimize/es/components/date_picker/date_picker.styles.js +3 -2
  57. package/optimize/es/components/date_picker/date_picker_range.styles.js +1 -1
  58. package/optimize/es/components/form/super_select/super_select.styles.js +1 -1
  59. package/optimize/es/components/markdown_editor/plugins/markdown_default_plugins/parsing_plugins.js +14 -8
  60. package/optimize/es/components/markdown_editor/plugins/markdown_default_plugins/plugins.js +18 -4
  61. package/optimize/es/components/markdown_editor/plugins/markdown_default_plugins/processing_plugins.js +5 -2
  62. package/optimize/es/components/markdown_editor/plugins/markdown_link_validator.js +8 -2
  63. package/optimize/es/components/search_bar/filters/field_value_selection_filter.js +168 -151
  64. package/optimize/lib/components/datagrid/body/cell/focus_utils.js +56 -11
  65. package/optimize/lib/components/datagrid/body/header/data_grid_header_cell.js +92 -84
  66. package/optimize/lib/components/datagrid/body/header/data_grid_header_cell_wrapper.js +33 -19
  67. package/optimize/lib/components/datagrid/data_grid.a11y.js +2 -0
  68. package/optimize/lib/components/date_picker/date_picker.js +15 -9
  69. package/optimize/lib/components/date_picker/date_picker.styles.js +3 -2
  70. package/optimize/lib/components/date_picker/date_picker_range.styles.js +1 -1
  71. package/optimize/lib/components/form/super_select/super_select.styles.js +1 -1
  72. package/optimize/lib/components/markdown_editor/plugins/markdown_default_plugins/parsing_plugins.js +15 -11
  73. package/optimize/lib/components/markdown_editor/plugins/markdown_default_plugins/plugins.js +19 -6
  74. package/optimize/lib/components/markdown_editor/plugins/markdown_default_plugins/processing_plugins.js +5 -2
  75. package/optimize/lib/components/markdown_editor/plugins/markdown_link_validator.js +9 -2
  76. package/optimize/lib/components/search_bar/filters/field_value_selection_filter.js +167 -150
  77. package/package.json +1 -1
  78. package/src/components/datagrid/_data_grid_data_row.scss +5 -0
  79. package/src/components/datagrid/body/header/_data_grid_header_row.scss +27 -5
  80. package/test-env/components/basic_table/in_memory_table.js +2 -1
  81. package/test-env/components/datagrid/body/cell/data_grid_cell.js +2 -0
  82. package/test-env/components/datagrid/body/cell/focus_utils.js +58 -12
  83. package/test-env/components/datagrid/body/data_grid_body.js +1 -0
  84. package/test-env/components/datagrid/body/data_grid_body_custom.js +1 -0
  85. package/test-env/components/datagrid/body/data_grid_body_virtualized.js +1 -0
  86. package/test-env/components/datagrid/body/header/data_grid_header_cell.js +93 -84
  87. package/test-env/components/datagrid/body/header/data_grid_header_cell_wrapper.js +37 -22
  88. package/test-env/components/datagrid/controls/column_sorting.js +1 -0
  89. package/test-env/components/datagrid/data_grid.a11y.js +2 -0
  90. package/test-env/components/datagrid/utils/in_memory.js +1 -0
  91. package/test-env/components/date_picker/date_picker.js +32 -10
  92. package/test-env/components/date_picker/date_picker.styles.js +3 -2
  93. package/test-env/components/date_picker/date_picker_range.styles.js +1 -1
  94. package/test-env/components/form/super_select/super_select.styles.js +1 -1
  95. package/test-env/components/markdown_editor/plugins/markdown_default_plugins/parsing_plugins.js +15 -11
  96. package/test-env/components/markdown_editor/plugins/markdown_default_plugins/plugins.js +19 -6
  97. package/test-env/components/markdown_editor/plugins/markdown_default_plugins/processing_plugins.js +5 -2
  98. package/test-env/components/markdown_editor/plugins/markdown_link_validator.js +9 -2
  99. package/test-env/components/search_bar/filters/field_value_selection_filter.js +169 -151
  100. package/test-env/components/search_bar/search_bar.js +2 -1
  101. package/test-env/components/search_bar/search_filters.js +2 -1
@@ -44,7 +44,8 @@ var DEFAULT_COMPONENT_RENDERERS = {
44
44
  };
45
45
  export var getDefaultEuiMarkdownProcessingPlugins = function getDefaultEuiMarkdownProcessingPlugins() {
46
46
  var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
47
- exclude = _ref.exclude;
47
+ exclude = _ref.exclude,
48
+ linkProps = _ref.linkProps;
48
49
  var componentPluginsWithExclusions = {};
49
50
  Object.entries(DEFAULT_COMPONENT_RENDERERS).forEach(function (_ref2) {
50
51
  var _ref3 = _slicedToArray(_ref2, 2),
@@ -63,7 +64,9 @@ export var getDefaultEuiMarkdownProcessingPlugins = function getDefaultEuiMarkdo
63
64
  createElement: createElement,
64
65
  Fragment: Fragment,
65
66
  components: _objectSpread({
66
- a: EuiLink,
67
+ a: function a(props) {
68
+ return ___EmotionJSX(EuiLink, _extends({}, props, linkProps));
69
+ },
67
70
  code: function code(props) {
68
71
  return (
69
72
  // If there are linebreaks use codeblock, otherwise code
@@ -7,6 +7,10 @@
7
7
  */
8
8
 
9
9
  import visit from 'unist-util-visit';
10
+ export var DEFAULT_OPTIONS = {
11
+ allowRelative: true,
12
+ allowProtocols: ['https:', 'http:', 'mailto:']
13
+ };
10
14
  export function euiMarkdownLinkValidator(options) {
11
15
  return function (ast) {
12
16
  visit(ast, 'link', function (_node) {
@@ -37,8 +41,10 @@ export function mutateLinkToText(node) {
37
41
  return node;
38
42
  }
39
43
  export function validateUrl(url, _ref) {
40
- var allowRelative = _ref.allowRelative,
41
- allowProtocols = _ref.allowProtocols;
44
+ var _ref$allowRelative = _ref.allowRelative,
45
+ allowRelative = _ref$allowRelative === void 0 ? DEFAULT_OPTIONS.allowRelative : _ref$allowRelative,
46
+ _ref$allowProtocols = _ref.allowProtocols,
47
+ allowProtocols = _ref$allowProtocols === void 0 ? DEFAULT_OPTIONS.allowProtocols : _ref$allowProtocols;
42
48
  // relative captures both relative paths `/` and protocols `//`
43
49
  var isRelative = url.startsWith('/');
44
50
  if (isRelative) {
@@ -1,13 +1,14 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
2
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
3
- 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; }
4
- 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; }
3
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
5
4
  function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
6
5
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
6
  function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
8
7
  function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
9
8
  function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
10
9
  function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
10
+ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
11
+ function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
11
12
  function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
12
13
  function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
13
14
  function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
@@ -29,7 +30,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
29
30
  * Side Public License, v 1.
30
31
  */
31
32
 
32
- import React, { Component } from 'react';
33
+ import React, { Component, createRef } from 'react';
33
34
  import PropTypes from "prop-types";
34
35
  import { RenderWithEuiTheme } from '../../../services';
35
36
  import { isArray, isNil } from '../../../services/predicate';
@@ -44,7 +45,8 @@ var defaults = {
44
45
  config: {
45
46
  multiSelect: true,
46
47
  filterWith: 'prefix',
47
- searchThreshold: 10
48
+ searchThreshold: 10,
49
+ autoSortOptions: true
48
50
  }
49
51
  };
50
52
  export var FieldValueSelectionFilter = /*#__PURE__*/function (_Component) {
@@ -52,45 +54,132 @@ export var FieldValueSelectionFilter = /*#__PURE__*/function (_Component) {
52
54
  var _this;
53
55
  _classCallCheck(this, FieldValueSelectionFilter);
54
56
  _this = _callSuper(this, FieldValueSelectionFilter, [props]);
55
- _defineProperty(_this, "resolveOptionsLoader", function () {
56
- var options = _this.props.config.options;
57
- if (isArray(options)) {
58
- return function () {
59
- return Promise.resolve(options);
60
- };
61
- }
62
- return function () {
63
- var cachedOptions = _this.state.cachedOptions;
64
- if (cachedOptions) {
65
- return Promise.resolve(cachedOptions);
66
- }
67
- return options().then(function (opts) {
68
- // If a cache time is set, populate the cache and also schedule a
69
- // cache reset.
70
- if (_this.props.config.cache != null && _this.props.config.cache > 0) {
57
+ _defineProperty(_this, "selectableClassRef", /*#__PURE__*/createRef());
58
+ _defineProperty(_this, "cacheTimeout", void 0);
59
+ _defineProperty(_this, "loadOptions", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
60
+ var loadedOptions, _this$props$config, options, cache, _this$state$cachedOpt, items, _this$props, query, config;
61
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
62
+ while (1) switch (_context.prev = _context.next) {
63
+ case 0:
71
64
  _this.setState({
72
- cachedOptions: opts
65
+ options: null,
66
+ error: null
73
67
  });
74
- setTimeout(function () {
68
+ _this$props$config = _this.props.config, options = _this$props$config.options, cache = _this$props$config.cache;
69
+ _context.prev = 2;
70
+ if (!isArray(options)) {
71
+ _context.next = 7;
72
+ break;
73
+ }
74
+ // Synchronous options, already loaded
75
+ loadedOptions = options;
76
+ _context.next = 16;
77
+ break;
78
+ case 7:
79
+ if (!((_this$state$cachedOpt = _this.state.cachedOptions) !== null && _this$state$cachedOpt !== void 0)) {
80
+ _context.next = 11;
81
+ break;
82
+ }
83
+ _context.t0 = _this$state$cachedOpt;
84
+ _context.next = 14;
85
+ break;
86
+ case 11:
87
+ _context.next = 13;
88
+ return options();
89
+ case 13:
90
+ _context.t0 = _context.sent;
91
+ case 14:
92
+ loadedOptions = _context.t0;
93
+ // If a cache time is set, populate the cache and schedule a cache reset
94
+ if (cache != null && cache > 0) {
75
95
  _this.setState({
76
- cachedOptions: null
96
+ cachedOptions: loadedOptions
77
97
  });
78
- }, _this.props.config.cache);
79
- }
80
- return opts;
98
+ _this.cacheTimeout = setTimeout(function () {
99
+ _this.setState({
100
+ cachedOptions: null
101
+ });
102
+ }, cache);
103
+ }
104
+ case 16:
105
+ _context.next = 21;
106
+ break;
107
+ case 18:
108
+ _context.prev = 18;
109
+ _context.t1 = _context["catch"](2);
110
+ return _context.abrupt("return", _this.setState({
111
+ options: null,
112
+ error: 'Could not load options'
113
+ }));
114
+ case 21:
115
+ items = {
116
+ on: [],
117
+ off: [],
118
+ rest: []
119
+ };
120
+ _this$props = _this.props, query = _this$props.query, config = _this$props.config;
121
+ if (loadedOptions) {
122
+ loadedOptions.forEach(function (op) {
123
+ var optionField = op.field || config.field;
124
+ if (optionField) {
125
+ var clause = _this.multiSelect === 'or' ? query.getOrFieldClause(optionField, op.value) : query.getSimpleFieldClause(optionField, op.value);
126
+ var checked = _this.resolveChecked(clause);
127
+ if (!checked) {
128
+ items.rest.push(op);
129
+ } else if (checked === 'on') {
130
+ items.on.push(op);
131
+ } else {
132
+ items.off.push(op);
133
+ }
134
+ }
135
+ return;
136
+ });
137
+ }
138
+ _this.setState({
139
+ error: null,
140
+ activeItemsCount: items.on.length,
141
+ options: {
142
+ unsorted: loadedOptions,
143
+ sorted: [].concat(_toConsumableArray(items.on), _toConsumableArray(items.off), _toConsumableArray(items.rest))
144
+ }
145
+ }, _this.scrollToAutoSortedOption);
146
+ case 25:
147
+ case "end":
148
+ return _context.stop();
149
+ }
150
+ }, _callee, null, [[2, 18]]);
151
+ })));
152
+ _defineProperty(_this, "scrollToAutoSortedOption", function () {
153
+ if (!_this.autoSortOptions) return;
154
+ var _this$state = _this.state,
155
+ lastCheckedValue = _this$state.lastCheckedValue,
156
+ options = _this$state.options;
157
+ if (lastCheckedValue) {
158
+ var sortedIndex = options.sorted.findIndex(function (option) {
159
+ return option.value === lastCheckedValue;
81
160
  });
82
- };
161
+ if (sortedIndex >= 0) {
162
+ var _this$selectableClass;
163
+ // EuiSelectable should automatically handle scrolling its list to the new index
164
+ (_this$selectableClass = _this.selectableClassRef.current) === null || _this$selectableClass === void 0 || _this$selectableClass.setState({
165
+ activeOptionIndex: sortedIndex
166
+ });
167
+ }
168
+ _this.setState({
169
+ lastCheckedValue: undefined
170
+ });
171
+ }
83
172
  });
84
173
  var _options = props.config.options;
85
174
  var preloadedOptions = isArray(_options) ? {
86
- all: _options,
87
- shown: _options
175
+ unsorted: _options,
176
+ sorted: _options
88
177
  } : null;
89
178
  _this.state = {
90
179
  popoverOpen: false,
91
180
  error: null,
92
181
  options: preloadedOptions,
93
- activeItems: []
182
+ activeItemsCount: 0
94
183
  };
95
184
  return _this;
96
185
  }
@@ -120,94 +209,6 @@ export var FieldValueSelectionFilter = /*#__PURE__*/function (_Component) {
120
209
  };
121
210
  });
122
211
  }
123
- }, {
124
- key: "loadOptions",
125
- value: function loadOptions() {
126
- var _this3 = this;
127
- var loader = this.resolveOptionsLoader();
128
- this.setState({
129
- options: null,
130
- error: null
131
- });
132
- loader().then(function (options) {
133
- var items = {
134
- on: [],
135
- off: [],
136
- rest: []
137
- };
138
- var _this3$props = _this3.props,
139
- query = _this3$props.query,
140
- config = _this3$props.config;
141
- var multiSelect = _this3.resolveMultiSelect();
142
- if (options) {
143
- options.forEach(function (op) {
144
- var optionField = op.field || config.field;
145
- if (optionField) {
146
- var clause = multiSelect === 'or' ? query.getOrFieldClause(optionField, op.value) : query.getSimpleFieldClause(optionField, op.value);
147
- var checked = _this3.resolveChecked(clause);
148
- if (!checked) {
149
- items.rest.push(op);
150
- } else if (checked === 'on') {
151
- items.on.push(op);
152
- } else {
153
- items.off.push(op);
154
- }
155
- }
156
- return;
157
- });
158
- }
159
- _this3.setState({
160
- error: null,
161
- activeItems: items.on,
162
- options: {
163
- all: options,
164
- shown: [].concat(_toConsumableArray(items.on), _toConsumableArray(items.off), _toConsumableArray(items.rest))
165
- }
166
- });
167
- }).catch(function () {
168
- _this3.setState({
169
- options: null,
170
- error: 'Could not load options'
171
- });
172
- });
173
- }
174
- }, {
175
- key: "filterOptions",
176
- value: function filterOptions() {
177
- var _this4 = this;
178
- var q = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
179
- this.setState(function (prevState) {
180
- if (isNil(prevState.options)) {
181
- return {};
182
- }
183
- var predicate = _this4.getOptionFilter();
184
- return _objectSpread(_objectSpread({}, prevState), {}, {
185
- options: _objectSpread(_objectSpread({}, prevState.options), {}, {
186
- shown: prevState.options.all.filter(function (option, i, options) {
187
- var name = _this4.resolveOptionName(option).toLowerCase();
188
- var query = q.toLowerCase();
189
- return predicate(name, query, options);
190
- })
191
- })
192
- });
193
- });
194
- }
195
- }, {
196
- key: "getOptionFilter",
197
- value: function getOptionFilter() {
198
- var filterWith = this.props.config.filterWith || defaults.config.filterWith;
199
- if (typeof filterWith === 'function') {
200
- return filterWith;
201
- }
202
- if (filterWith === 'includes') {
203
- return function (name, query) {
204
- return name.includes(query);
205
- };
206
- }
207
- return function (name, query) {
208
- return name.startsWith(query);
209
- };
210
- }
211
212
  }, {
212
213
  key: "resolveOptionName",
213
214
  value: function resolveOptionName(option) {
@@ -216,23 +217,27 @@ export var FieldValueSelectionFilter = /*#__PURE__*/function (_Component) {
216
217
  }, {
217
218
  key: "onOptionClick",
218
219
  value: function onOptionClick(field, value, checked) {
219
- var multiSelect = this.resolveMultiSelect();
220
- var _this$props$config = this.props.config,
221
- autoClose = _this$props$config.autoClose,
222
- _this$props$config$op = _this$props$config.operator,
223
- operator = _this$props$config$op === void 0 ? Operator.EQ : _this$props$config$op;
220
+ var _this$props$config2 = this.props.config,
221
+ autoClose = _this$props$config2.autoClose,
222
+ _this$props$config2$o = _this$props$config2.operator,
223
+ operator = _this$props$config2$o === void 0 ? Operator.EQ : _this$props$config2$o;
224
+ if (checked && this.autoSortOptions) {
225
+ this.setState({
226
+ lastCheckedValue: value
227
+ });
228
+ }
224
229
 
225
230
  // If the consumer explicitly sets `autoClose`, always defer to that.
226
231
  // Otherwise, default to auto-closing for single selections and leaving the
227
232
  // popover open for multi-select (so users can continue selecting options)
228
- var shouldClosePopover = autoClose !== null && autoClose !== void 0 ? autoClose : !multiSelect;
233
+ var shouldClosePopover = autoClose !== null && autoClose !== void 0 ? autoClose : !this.multiSelect;
229
234
  if (shouldClosePopover) {
230
235
  this.closePopover();
231
236
  }
232
- if (!multiSelect) {
237
+ if (!this.multiSelect) {
233
238
  var _query = checked ? this.props.query.removeSimpleFieldClauses(field).addSimpleFieldValue(field, value, true, operator) : this.props.query.removeSimpleFieldClauses(field);
234
239
  this.props.onChange(_query);
235
- } else if (multiSelect === 'or') {
240
+ } else if (this.multiSelect === 'or') {
236
241
  var _query2 = checked ? this.props.query.addOrFieldValue(field, value, true, operator) : this.props.query.removeOrFieldValue(field, value);
237
242
  this.props.onChange(_query2);
238
243
  } else {
@@ -241,10 +246,16 @@ export var FieldValueSelectionFilter = /*#__PURE__*/function (_Component) {
241
246
  }
242
247
  }
243
248
  }, {
244
- key: "resolveMultiSelect",
245
- value: function resolveMultiSelect() {
246
- var config = this.props.config;
247
- return !isNil(config.multiSelect) ? config.multiSelect : defaults.config.multiSelect;
249
+ key: "autoSortOptions",
250
+ get: function get() {
251
+ var _this$props$config$au;
252
+ return (_this$props$config$au = this.props.config.autoSortOptions) !== null && _this$props$config$au !== void 0 ? _this$props$config$au : defaults.config.autoSortOptions;
253
+ }
254
+ }, {
255
+ key: "multiSelect",
256
+ get: function get() {
257
+ var _this$props$config$mu;
258
+ return (_this$props$config$mu = this.props.config.multiSelect) !== null && _this$props$config$mu !== void 0 ? _this$props$config$mu : defaults.config.multiSelect;
248
259
  }
249
260
  }, {
250
261
  key: "componentDidMount",
@@ -256,19 +267,26 @@ export var FieldValueSelectionFilter = /*#__PURE__*/function (_Component) {
256
267
  value: function componentDidUpdate(prevProps) {
257
268
  if (this.props.query !== prevProps.query) this.loadOptions();
258
269
  }
270
+ }, {
271
+ key: "componentWillUnmount",
272
+ value: function componentWillUnmount() {
273
+ clearTimeout(this.cacheTimeout);
274
+ }
259
275
  }, {
260
276
  key: "render",
261
277
  value: function render() {
262
- var _this5 = this;
263
- var _this$props = this.props,
264
- query = _this$props.query,
265
- config = _this$props.config;
266
- var multiSelect = this.resolveMultiSelect();
278
+ var _this$state$options,
279
+ _this$state$options2,
280
+ _this3 = this;
281
+ var _this$props2 = this.props,
282
+ query = _this$props2.query,
283
+ config = _this$props2.config;
284
+ var options = this.autoSortOptions ? (_this$state$options = this.state.options) === null || _this$state$options === void 0 ? void 0 : _this$state$options.sorted : (_this$state$options2 = this.state.options) === null || _this$state$options2 === void 0 ? void 0 : _this$state$options2.unsorted;
267
285
  var activeTop = this.isActiveField(config.field);
268
- var activeItem = this.state.options ? this.state.options.all.some(function (item) {
269
- return _this5.isActiveField(item.field);
286
+ var activeItem = options ? options.some(function (item) {
287
+ return _this3.isActiveField(item.field);
270
288
  }) : false;
271
- var activeItemsCount = this.state.activeItems.length;
289
+ var activeItemsCount = this.state.activeItemsCount;
272
290
  var active = (activeTop || activeItem) && activeItemsCount > 0;
273
291
  var button = ___EmotionJSX(EuiFilterButton, {
274
292
  iconType: "arrowDown",
@@ -278,15 +296,15 @@ export var FieldValueSelectionFilter = /*#__PURE__*/function (_Component) {
278
296
  numActiveFilters: active ? activeItemsCount : undefined,
279
297
  grow: true
280
298
  }, config.name);
281
- var items = this.state.options ? this.state.options.shown.map(function (option) {
299
+ var items = options ? options.map(function (option) {
282
300
  var _option$view;
283
301
  var optionField = option.field || config.field;
284
302
  if (optionField == null) {
285
303
  throw new Error('option.field or field should be provided in <FieldValueSelectionFilter/>');
286
304
  }
287
- var clause = multiSelect === 'or' ? query.getOrFieldClause(optionField, option.value) : query.getSimpleFieldClause(optionField, option.value);
288
- var label = _this5.resolveOptionName(option);
289
- var checked = _this5.resolveChecked(clause);
305
+ var clause = _this3.multiSelect === 'or' ? query.getOrFieldClause(optionField, option.value) : query.getSimpleFieldClause(optionField, option.value);
306
+ var label = _this3.resolveOptionName(option);
307
+ var checked = _this3.resolveChecked(clause);
290
308
  return {
291
309
  label: label,
292
310
  checked: checked,
@@ -298,7 +316,7 @@ export var FieldValueSelectionFilter = /*#__PURE__*/function (_Component) {
298
316
  };
299
317
  }) : [];
300
318
  var threshold = config.searchThreshold || defaults.config.searchThreshold;
301
- var isOverSearchThreshold = this.state.options && this.state.options.all.length >= threshold;
319
+ var isOverSearchThreshold = options && options.length >= threshold;
302
320
  var searchProps = {
303
321
  searchable: false
304
322
  };
@@ -314,31 +332,32 @@ export var FieldValueSelectionFilter = /*#__PURE__*/function (_Component) {
314
332
  return ___EmotionJSX(RenderWithEuiTheme, null, function (euiThemeContext) {
315
333
  return ___EmotionJSX(EuiPopover, {
316
334
  button: button,
317
- isOpen: _this5.state.popoverOpen,
318
- closePopover: _this5.closePopover.bind(_this5),
335
+ isOpen: _this3.state.popoverOpen,
336
+ closePopover: _this3.closePopover.bind(_this3),
319
337
  panelPaddingSize: "none",
320
338
  anchorPosition: "downCenter",
321
339
  panelProps: {
322
340
  css: euiFilterGroupStyles(euiThemeContext).euiFilterGroup__popoverPanel
323
341
  }
324
342
  }, ___EmotionJSX(EuiSelectable, _extends({
325
- singleSelection: !multiSelect,
343
+ ref: _this3.selectableClassRef,
344
+ singleSelection: !_this3.multiSelect,
326
345
  "aria-label": config.name,
327
346
  options: items,
328
347
  renderOption: function renderOption(option) {
329
348
  return option.view;
330
349
  },
331
- isLoading: isNil(_this5.state.options),
350
+ isLoading: isNil(options),
332
351
  loadingMessage: config.loadingMessage,
333
352
  emptyMessage: config.noOptionsMessage,
334
- errorMessage: _this5.state.error,
353
+ errorMessage: _this3.state.error,
335
354
  noMatchesMessage: config.noOptionsMessage,
336
355
  listProps: {
337
356
  isVirtualized: isOverSearchThreshold || false
338
357
  },
339
358
  onChange: function onChange(options, event, changedOption) {
340
359
  if (changedOption.data) {
341
- _this5.onOptionClick(changedOption.data.optionField, changedOption.data.value, changedOption.checked);
360
+ _this3.onOptionClick(changedOption.data.optionField, changedOption.data.value, changedOption.checked);
342
361
  }
343
362
  }
344
363
  }, searchProps), function (list, search) {
@@ -362,8 +381,7 @@ export var FieldValueSelectionFilter = /*#__PURE__*/function (_Component) {
362
381
  return false;
363
382
  }
364
383
  var query = this.props.query;
365
- var multiSelect = this.resolveMultiSelect();
366
- if (multiSelect === 'or') {
384
+ if (this.multiSelect === 'or') {
367
385
  return query.hasOrFieldClause(field);
368
386
  }
369
387
  return query.hasSimpleFieldClause(field);
@@ -406,7 +424,8 @@ FieldValueSelectionFilter.propTypes = {
406
424
  searchThreshold: PropTypes.number,
407
425
  available: PropTypes.func,
408
426
  autoClose: PropTypes.bool,
409
- operator: PropTypes.oneOf(["eq", "exact", "gt", "gte", "lt", "lte"])
427
+ operator: PropTypes.oneOf(["eq", "exact", "gt", "gte", "lt", "lte"]),
428
+ autoSortOptions: PropTypes.bool
410
429
  }).isRequired,
411
430
  query: PropTypes.any.isRequired,
412
431
  onChange: PropTypes.func.isRequired
@@ -352,7 +352,8 @@ EuiSearchBar.propTypes = {
352
352
  searchThreshold: PropTypes.number,
353
353
  available: PropTypes.func,
354
354
  autoClose: PropTypes.bool,
355
- operator: PropTypes.oneOf(["eq", "exact", "gt", "gte", "lt", "lte"])
355
+ operator: PropTypes.oneOf(["eq", "exact", "gt", "gte", "lt", "lte"]),
356
+ autoSortOptions: PropTypes.bool
356
357
  }).isRequired, PropTypes.shape({
357
358
  type: PropTypes.oneOf(["field_value_toggle"]).isRequired,
358
359
  field: PropTypes.string.isRequired,
@@ -100,7 +100,8 @@ EuiSearchBarFilters.propTypes = {
100
100
  searchThreshold: PropTypes.number,
101
101
  available: PropTypes.func,
102
102
  autoClose: PropTypes.bool,
103
- operator: PropTypes.oneOf(["eq", "exact", "gt", "gte", "lt", "lte"])
103
+ operator: PropTypes.oneOf(["eq", "exact", "gt", "gte", "lt", "lte"]),
104
+ autoSortOptions: PropTypes.bool
104
105
  }).isRequired, PropTypes.shape({
105
106
  type: PropTypes.oneOf(["field_value_toggle"]).isRequired,
106
107
  field: PropTypes.string.isRequired,