@atlaskit/editor-core 172.3.2 → 173.0.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 (189) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/dist/cjs/index.js +0 -6
  3. package/dist/cjs/plugins/base/index.js +8 -0
  4. package/dist/cjs/plugins/base/pm-plugins/composition.js +60 -0
  5. package/dist/cjs/plugins/breakout/index.js +5 -4
  6. package/dist/cjs/plugins/breakout/ui/LayoutButton.js +1 -3
  7. package/dist/cjs/plugins/card/pm-plugins/doc.js +8 -1
  8. package/dist/cjs/plugins/code-block/pm-plugins/ide-ux.js +2 -36
  9. package/dist/cjs/plugins/collab-edit/plugin-state.js +16 -9
  10. package/dist/cjs/plugins/collab-edit/utils.js +16 -2
  11. package/dist/cjs/plugins/feature-flags-context/feature-flags-from-props.js +24 -22
  12. package/dist/cjs/plugins/floating-toolbar/ui/Dropdown.js +20 -15
  13. package/dist/cjs/plugins/floating-toolbar/ui/DropdownMenu.js +8 -5
  14. package/dist/cjs/plugins/floating-toolbar/ui/Toolbar.js +3 -3
  15. package/dist/cjs/plugins/paste/actions.js +13 -0
  16. package/dist/cjs/plugins/paste/commands.js +44 -0
  17. package/dist/cjs/plugins/paste/handlers.js +48 -7
  18. package/dist/cjs/plugins/paste/index.js +3 -2
  19. package/dist/cjs/plugins/paste/pm-plugins/main.js +34 -9
  20. package/dist/cjs/plugins/paste/pm-plugins/plugin-factory.js +62 -0
  21. package/dist/cjs/plugins/paste/reducer.js +47 -0
  22. package/dist/cjs/plugins/paste/types.js +5 -0
  23. package/dist/cjs/plugins/placeholder/index.js +3 -1
  24. package/dist/cjs/plugins/placeholder-text/index.js +9 -3
  25. package/dist/cjs/plugins/status/ui/statusPicker.js +4 -1
  26. package/dist/cjs/plugins/table/commands-with-analytics.js +59 -52
  27. package/dist/cjs/plugins/table/index.js +53 -36
  28. package/dist/cjs/plugins/table/toolbar.js +136 -20
  29. package/dist/cjs/plugins/table/ui/FloatingContextualMenu/ContextualMenu.js +3 -3
  30. package/dist/cjs/plugins/tasks-and-decisions/commands.js +1 -16
  31. package/dist/cjs/plugins/type-ahead/constants.js +3 -1
  32. package/dist/cjs/plugins/type-ahead/messages.js +16 -1
  33. package/dist/cjs/plugins/type-ahead/pm-plugins/main.js +1 -1
  34. package/dist/cjs/plugins/type-ahead/pm-plugins/reducer.js +2 -2
  35. package/dist/cjs/plugins/type-ahead/ui/AssistiveText.js +143 -0
  36. package/dist/cjs/plugins/type-ahead/ui/InputQuery.js +59 -11
  37. package/dist/cjs/plugins/type-ahead/ui/TypeAheadList.js +156 -31
  38. package/dist/cjs/plugins/type-ahead/ui/TypeAheadListItem.js +55 -29
  39. package/dist/cjs/plugins/type-ahead/ui/TypeAheadPopup.js +3 -3
  40. package/dist/cjs/plugins/type-ahead/ui/WrapperTypeAhead.js +5 -2
  41. package/dist/cjs/plugins/type-ahead/utils.js +1 -1
  42. package/dist/cjs/ui/MediaAndEmbedsToolbar/index.js +8 -0
  43. package/dist/cjs/ui/PortalProvider/PortalProviderThemesProvider.js +2 -6
  44. package/dist/cjs/ui/PortalProvider/index.js +26 -32
  45. package/dist/cjs/utils/index.js +8 -1
  46. package/dist/cjs/version-wrapper.js +1 -1
  47. package/dist/cjs/version.json +1 -1
  48. package/dist/es2019/index.js +1 -1
  49. package/dist/es2019/plugins/base/index.js +5 -0
  50. package/dist/es2019/plugins/base/pm-plugins/composition.js +45 -0
  51. package/dist/es2019/plugins/breakout/index.js +5 -4
  52. package/dist/es2019/plugins/breakout/ui/LayoutButton.js +1 -3
  53. package/dist/es2019/plugins/card/pm-plugins/doc.js +10 -1
  54. package/dist/es2019/plugins/code-block/pm-plugins/ide-ux.js +3 -40
  55. package/dist/es2019/plugins/collab-edit/plugin-state.js +9 -3
  56. package/dist/es2019/plugins/collab-edit/utils.js +17 -3
  57. package/dist/es2019/plugins/feature-flags-context/feature-flags-from-props.js +24 -22
  58. package/dist/es2019/plugins/floating-toolbar/ui/Dropdown.js +15 -7
  59. package/dist/es2019/plugins/floating-toolbar/ui/DropdownMenu.js +9 -5
  60. package/dist/es2019/plugins/floating-toolbar/ui/Toolbar.js +3 -3
  61. package/dist/es2019/plugins/paste/actions.js +6 -0
  62. package/dist/es2019/plugins/paste/commands.js +27 -0
  63. package/dist/es2019/plugins/paste/handlers.js +50 -8
  64. package/dist/es2019/plugins/paste/index.js +3 -2
  65. package/dist/es2019/plugins/paste/pm-plugins/main.js +29 -6
  66. package/dist/es2019/plugins/paste/pm-plugins/plugin-factory.js +33 -0
  67. package/dist/es2019/plugins/paste/reducer.js +24 -0
  68. package/dist/es2019/plugins/paste/types.js +1 -0
  69. package/dist/es2019/plugins/placeholder/index.js +2 -1
  70. package/dist/es2019/plugins/placeholder-text/index.js +13 -3
  71. package/dist/es2019/plugins/status/ui/statusPicker.js +5 -1
  72. package/dist/es2019/plugins/table/commands-with-analytics.js +6 -3
  73. package/dist/es2019/plugins/table/index.js +22 -4
  74. package/dist/es2019/plugins/table/toolbar.js +118 -14
  75. package/dist/es2019/plugins/table/ui/FloatingContextualMenu/ContextualMenu.js +3 -3
  76. package/dist/es2019/plugins/tasks-and-decisions/commands.js +0 -9
  77. package/dist/es2019/plugins/type-ahead/constants.js +1 -0
  78. package/dist/es2019/plugins/type-ahead/messages.js +16 -1
  79. package/dist/es2019/plugins/type-ahead/pm-plugins/main.js +1 -1
  80. package/dist/es2019/plugins/type-ahead/pm-plugins/reducer.js +2 -2
  81. package/dist/es2019/plugins/type-ahead/ui/AssistiveText.js +95 -0
  82. package/dist/es2019/plugins/type-ahead/ui/InputQuery.js +49 -12
  83. package/dist/es2019/plugins/type-ahead/ui/TypeAheadList.js +143 -29
  84. package/dist/es2019/plugins/type-ahead/ui/TypeAheadListItem.js +64 -31
  85. package/dist/es2019/plugins/type-ahead/ui/TypeAheadPopup.js +3 -3
  86. package/dist/es2019/plugins/type-ahead/ui/WrapperTypeAhead.js +5 -2
  87. package/dist/es2019/plugins/type-ahead/utils.js +1 -1
  88. package/dist/es2019/ui/MediaAndEmbedsToolbar/index.js +17 -0
  89. package/dist/es2019/ui/PortalProvider/PortalProviderThemesProvider.js +2 -5
  90. package/dist/es2019/ui/PortalProvider/index.js +5 -8
  91. package/dist/es2019/utils/index.js +6 -0
  92. package/dist/es2019/version-wrapper.js +1 -1
  93. package/dist/es2019/version.json +1 -1
  94. package/dist/esm/index.js +1 -1
  95. package/dist/esm/plugins/base/index.js +7 -0
  96. package/dist/esm/plugins/base/pm-plugins/composition.js +45 -0
  97. package/dist/esm/plugins/breakout/index.js +5 -4
  98. package/dist/esm/plugins/breakout/ui/LayoutButton.js +1 -3
  99. package/dist/esm/plugins/card/pm-plugins/doc.js +8 -1
  100. package/dist/esm/plugins/code-block/pm-plugins/ide-ux.js +3 -37
  101. package/dist/esm/plugins/collab-edit/plugin-state.js +9 -3
  102. package/dist/esm/plugins/collab-edit/utils.js +17 -3
  103. package/dist/esm/plugins/feature-flags-context/feature-flags-from-props.js +24 -22
  104. package/dist/esm/plugins/floating-toolbar/ui/Dropdown.js +20 -15
  105. package/dist/esm/plugins/floating-toolbar/ui/DropdownMenu.js +8 -5
  106. package/dist/esm/plugins/floating-toolbar/ui/Toolbar.js +3 -3
  107. package/dist/esm/plugins/paste/actions.js +6 -0
  108. package/dist/esm/plugins/paste/commands.js +31 -0
  109. package/dist/esm/plugins/paste/handlers.js +46 -8
  110. package/dist/esm/plugins/paste/index.js +3 -2
  111. package/dist/esm/plugins/paste/pm-plugins/main.js +27 -6
  112. package/dist/esm/plugins/paste/pm-plugins/plugin-factory.js +46 -0
  113. package/dist/esm/plugins/paste/reducer.js +34 -0
  114. package/dist/esm/plugins/paste/types.js +1 -0
  115. package/dist/esm/plugins/placeholder/index.js +2 -1
  116. package/dist/esm/plugins/placeholder-text/index.js +9 -3
  117. package/dist/esm/plugins/status/ui/statusPicker.js +4 -1
  118. package/dist/esm/plugins/table/commands-with-analytics.js +56 -49
  119. package/dist/esm/plugins/table/index.js +54 -37
  120. package/dist/esm/plugins/table/toolbar.js +124 -15
  121. package/dist/esm/plugins/table/ui/FloatingContextualMenu/ContextualMenu.js +3 -3
  122. package/dist/esm/plugins/tasks-and-decisions/commands.js +0 -12
  123. package/dist/esm/plugins/type-ahead/constants.js +1 -0
  124. package/dist/esm/plugins/type-ahead/messages.js +16 -1
  125. package/dist/esm/plugins/type-ahead/pm-plugins/main.js +1 -1
  126. package/dist/esm/plugins/type-ahead/pm-plugins/reducer.js +2 -2
  127. package/dist/esm/plugins/type-ahead/ui/AssistiveText.js +129 -0
  128. package/dist/esm/plugins/type-ahead/ui/InputQuery.js +56 -12
  129. package/dist/esm/plugins/type-ahead/ui/TypeAheadList.js +151 -32
  130. package/dist/esm/plugins/type-ahead/ui/TypeAheadListItem.js +54 -31
  131. package/dist/esm/plugins/type-ahead/ui/TypeAheadPopup.js +3 -3
  132. package/dist/esm/plugins/type-ahead/ui/WrapperTypeAhead.js +5 -2
  133. package/dist/esm/plugins/type-ahead/utils.js +1 -1
  134. package/dist/esm/ui/MediaAndEmbedsToolbar/index.js +7 -0
  135. package/dist/esm/ui/PortalProvider/PortalProviderThemesProvider.js +2 -5
  136. package/dist/esm/ui/PortalProvider/index.js +26 -35
  137. package/dist/esm/utils/index.js +4 -0
  138. package/dist/esm/version-wrapper.js +1 -1
  139. package/dist/esm/version.json +1 -1
  140. package/dist/types/index.d.ts +1 -1
  141. package/dist/types/plugins/base/pm-plugins/composition.d.ts +8 -0
  142. package/dist/types/plugins/code-block/pm-plugins/ide-ux.d.ts +1 -4
  143. package/dist/types/plugins/floating-toolbar/ui/Dropdown.d.ts +2 -0
  144. package/dist/types/plugins/floating-toolbar/ui/DropdownMenu.d.ts +1 -0
  145. package/dist/types/plugins/paste/actions.d.ts +15 -0
  146. package/dist/types/plugins/paste/commands.d.ts +16 -0
  147. package/dist/types/plugins/paste/handlers.d.ts +1 -1
  148. package/dist/types/plugins/paste/pm-plugins/main.d.ts +3 -3
  149. package/dist/types/plugins/paste/pm-plugins/plugin-factory.d.ts +3 -0
  150. package/dist/types/plugins/paste/reducer.d.ts +3 -0
  151. package/dist/types/plugins/paste/types.d.ts +6 -0
  152. package/dist/types/plugins/table/commands-with-analytics.d.ts +5 -5
  153. package/dist/types/plugins/tasks-and-decisions/commands.d.ts +0 -2
  154. package/dist/types/plugins/type-ahead/constants.d.ts +1 -0
  155. package/dist/types/plugins/type-ahead/messages.d.ts +15 -0
  156. package/dist/types/plugins/type-ahead/ui/AssistiveText.d.ts +33 -0
  157. package/dist/types/plugins/type-ahead/ui/InputQuery.d.ts +3 -0
  158. package/dist/types/plugins/type-ahead/ui/TypeAheadList.d.ts +6 -3
  159. package/dist/types/plugins/type-ahead/ui/TypeAheadListItem.d.ts +2 -2
  160. package/dist/types/plugins/type-ahead/ui/TypeAheadPopup.d.ts +1 -1
  161. package/dist/types/ui/Appearance/FullPage/StyledComponents.d.ts +2 -2
  162. package/dist/types/ui/ContentStyles/index.d.ts +2 -2
  163. package/dist/types/utils/index.d.ts +1 -0
  164. package/dist/types-ts4.0/index.d.ts +1 -1
  165. package/dist/types-ts4.0/plugins/base/pm-plugins/composition.d.ts +8 -0
  166. package/dist/types-ts4.0/plugins/code-block/pm-plugins/ide-ux.d.ts +1 -4
  167. package/dist/types-ts4.0/plugins/floating-toolbar/ui/Dropdown.d.ts +2 -0
  168. package/dist/types-ts4.0/plugins/floating-toolbar/ui/DropdownMenu.d.ts +1 -0
  169. package/dist/types-ts4.0/plugins/paste/actions.d.ts +15 -0
  170. package/dist/types-ts4.0/plugins/paste/commands.d.ts +16 -0
  171. package/dist/types-ts4.0/plugins/paste/handlers.d.ts +1 -1
  172. package/dist/types-ts4.0/plugins/paste/pm-plugins/main.d.ts +3 -3
  173. package/dist/types-ts4.0/plugins/paste/pm-plugins/plugin-factory.d.ts +3 -0
  174. package/dist/types-ts4.0/plugins/paste/reducer.d.ts +3 -0
  175. package/dist/types-ts4.0/plugins/paste/types.d.ts +6 -0
  176. package/dist/types-ts4.0/plugins/table/commands-with-analytics.d.ts +5 -5
  177. package/dist/types-ts4.0/plugins/tasks-and-decisions/commands.d.ts +0 -2
  178. package/dist/types-ts4.0/plugins/type-ahead/constants.d.ts +1 -0
  179. package/dist/types-ts4.0/plugins/type-ahead/messages.d.ts +15 -0
  180. package/dist/types-ts4.0/plugins/type-ahead/ui/AssistiveText.d.ts +33 -0
  181. package/dist/types-ts4.0/plugins/type-ahead/ui/InputQuery.d.ts +3 -0
  182. package/dist/types-ts4.0/plugins/type-ahead/ui/TypeAheadList.d.ts +6 -3
  183. package/dist/types-ts4.0/plugins/type-ahead/ui/TypeAheadListItem.d.ts +2 -2
  184. package/dist/types-ts4.0/plugins/type-ahead/ui/TypeAheadPopup.d.ts +1 -1
  185. package/dist/types-ts4.0/ui/Appearance/FullPage/StyledComponents.d.ts +2 -2
  186. package/dist/types-ts4.0/ui/ContentStyles/index.d.ts +2 -2
  187. package/dist/types-ts4.0/utils/index.d.ts +1 -0
  188. package/package.json +30 -31
  189. package/report.api.md +161 -49
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.AssistiveText = void 0;
9
+
10
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
+
12
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
+
14
+ var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
15
+
16
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
17
+
18
+ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
19
+
20
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
21
+
22
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
23
+
24
+ var _debounce = _interopRequireDefault(require("lodash/debounce"));
25
+
26
+ var _react = _interopRequireDefault(require("react"));
27
+
28
+ var _react2 = require("@emotion/react");
29
+
30
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
31
+
32
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
33
+
34
+ var statusDebounceMillis = 1400;
35
+ var assitiveTextStyles = (0, _react2.css)({
36
+ border: 0,
37
+ clip: 'rect(0 0 0 0)',
38
+ height: '1px',
39
+ marginbottom: '-1px',
40
+ marginright: '-1px',
41
+ overflow: 'hidden',
42
+ padding: 0,
43
+ position: 'absolute',
44
+ whitespace: 'nowrap',
45
+ width: '1px'
46
+ });
47
+
48
+ var AssistveTextComponent = /*#__PURE__*/function (_React$Component) {
49
+ (0, _inherits2.default)(AssistveTextComponent, _React$Component);
50
+
51
+ var _super = _createSuper(AssistveTextComponent);
52
+
53
+ function AssistveTextComponent() {
54
+ var _this;
55
+
56
+ (0, _classCallCheck2.default)(this, AssistveTextComponent);
57
+
58
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
59
+ args[_key] = arguments[_key];
60
+ }
61
+
62
+ _this = _super.call.apply(_super, [this].concat(args));
63
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "state", {
64
+ bump: false,
65
+ //when the same text needs to be read again, Hence it needs to be toggled between __status--A and __status--B
66
+ debounced: false,
67
+ silenced: false
68
+ });
69
+ return _this;
70
+ }
71
+
72
+ (0, _createClass2.default)(AssistveTextComponent, [{
73
+ key: "componentWillMount",
74
+ value: function componentWillMount() {
75
+ var _this2 = this;
76
+
77
+ this.debounceStatusUpdate = (0, _debounce.default)(function () {
78
+ if (!_this2.state.debounced) {
79
+ var shouldSilence = !_this2.props.isInFocus;
80
+
81
+ _this2.setState(function (_ref) {
82
+ var bump = _ref.bump;
83
+ return {
84
+ bump: !bump,
85
+ debounced: true,
86
+ silenced: shouldSilence
87
+ };
88
+ });
89
+ }
90
+ }, statusDebounceMillis);
91
+ }
92
+ }, {
93
+ key: "componentWillUnmount",
94
+ value: function componentWillUnmount() {}
95
+ }, {
96
+ key: "componentWillReceiveProps",
97
+ value: function componentWillReceiveProps() {
98
+ this.setState(function (_ref2) {
99
+ var bump = _ref2.bump;
100
+ return {
101
+ bump: !bump,
102
+ debounced: false
103
+ };
104
+ });
105
+ }
106
+ }, {
107
+ key: "render",
108
+ value: function render() {
109
+ var _this$props = this.props,
110
+ assistiveText = _this$props.assistiveText,
111
+ id = _this$props.id;
112
+ var _this$state = this.state,
113
+ bump = _this$state.bump,
114
+ debounced = _this$state.debounced,
115
+ silenced = _this$state.silenced;
116
+ this.debounceStatusUpdate();
117
+ return (0, _react2.jsx)("div", {
118
+ css: assitiveTextStyles
119
+ }, (0, _react2.jsx)("div", {
120
+ id: id + '__status--A',
121
+ role: "status",
122
+ "aria-atomic": "true",
123
+ "aria-live": "polite"
124
+ }, "".concat(!silenced && debounced && bump ? assistiveText : '')), (0, _react2.jsx)("div", {
125
+ id: id + '__status--B',
126
+ role: "status",
127
+ "aria-atomic": "true",
128
+ "aria-live": "polite"
129
+ }, "".concat(!silenced && debounced && !bump ? assistiveText : '')));
130
+ }
131
+ }]);
132
+ return AssistveTextComponent;
133
+ }(_react.default.Component);
134
+
135
+ (0, _defineProperty2.default)(AssistveTextComponent, "defaultProps", {
136
+ statusDebounceMillis: 1400,
137
+ debounce: true,
138
+ assistiveText: '',
139
+ isInFocus: false,
140
+ id: ''
141
+ });
142
+ var AssistiveText = AssistveTextComponent;
143
+ exports.AssistiveText = AssistiveText;
@@ -9,6 +9,8 @@ Object.defineProperty(exports, "__esModule", {
9
9
  });
10
10
  exports.InputQuery = void 0;
11
11
 
12
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
13
+
12
14
  var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
13
15
 
14
16
  var _react = _interopRequireWildcard(require("react"));
@@ -19,10 +21,18 @@ var _w3cKeyname = require("w3c-keyname");
19
21
 
20
22
  var _utils = require("@atlaskit/editor-common/utils");
21
23
 
24
+ var _utils2 = require("../utils");
25
+
22
26
  var _constants = require("../constants");
23
27
 
24
28
  var _typeAhead = require("@atlaskit/editor-common/type-ahead");
25
29
 
30
+ var _AssistiveText = require("./AssistiveText");
31
+
32
+ var _messages = require("../messages");
33
+
34
+ var _reactIntlNext = require("react-intl-next");
35
+
26
36
  var _templateObject;
27
37
 
28
38
  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); }
@@ -63,7 +73,9 @@ var InputQuery = /*#__PURE__*/_react.default.memo(function (_ref) {
63
73
  forceFocus = _ref.forceFocus,
64
74
  reopenQuery = _ref.reopenQuery,
65
75
  onQueryFocus = _ref.onQueryFocus,
66
- onUndoRedo = _ref.onUndoRedo;
76
+ onUndoRedo = _ref.onUndoRedo,
77
+ editorView = _ref.editorView,
78
+ items = _ref.items;
67
79
  var ref = (0, _react.useRef)(document.createElement('span'));
68
80
  var cleanedInputContent = (0, _react.useCallback)(function () {
69
81
  var _ref$current;
@@ -75,6 +87,12 @@ var InputQuery = /*#__PURE__*/_react.default.memo(function (_ref) {
75
87
  var text = cleanedInputContent();
76
88
  onQueryChange(text);
77
89
  }, [onQueryChange, cleanedInputContent]);
90
+
91
+ var _useState = (0, _react.useState)(false),
92
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
93
+ isInFocus = _useState2[0],
94
+ setInFocus = _useState2[1];
95
+
78
96
  var checkKeyEvent = (0, _react.useCallback)(function (event) {
79
97
  var _ref$current2;
80
98
 
@@ -84,6 +102,11 @@ var InputQuery = /*#__PURE__*/_react.default.memo(function (_ref) {
84
102
  var text = cleanedInputContent();
85
103
  var stopDefault = false;
86
104
 
105
+ var _getPluginState = (0, _utils2.getPluginState)(editorView.state),
106
+ selectedIndex = _getPluginState.selectedIndex;
107
+
108
+ setInFocus(true);
109
+
87
110
  switch (key) {
88
111
  case ' ':
89
112
  // space key
@@ -127,23 +150,29 @@ var InputQuery = /*#__PURE__*/_react.default.memo(function (_ref) {
127
150
  // ED-14758 - Under the W3C specification, any keycode sent under IME would return a keycode 229
128
151
  // event.isComposing can't be used alone as this also included a virtual keyboard under a keyboardless device, therefore, it seems the best practice would be intercepting the event as below.
129
152
  // Some suggested the other workaround maybe listen on`keypress` instead of `keydown`
130
- if (event.isComposing && (event.which === 229 || event.keyCode === 229)) {
131
- break;
153
+ if (!event.isComposing || event.which !== 229 && event.keyCode !== 229) {
154
+ if (selectedIndex === -1) {
155
+ selectNextItem();
156
+ }
157
+
158
+ onItemSelect(event.shiftKey ? _typeAhead.SelectItemMode.SHIFT_ENTER : _typeAhead.SelectItemMode.ENTER);
132
159
  }
133
160
 
134
- onItemSelect(event.shiftKey ? _typeAhead.SelectItemMode.SHIFT_ENTER : _typeAhead.SelectItemMode.ENTER);
135
161
  break;
136
162
 
137
163
  case 'Tab':
164
+ if (selectedIndex === -1) {
165
+ selectNextItem();
166
+ }
167
+
138
168
  onItemSelect(_typeAhead.SelectItemMode.TAB);
139
169
  break;
140
170
 
141
171
  case 'ArrowDown':
142
- selectNextItem();
143
- break;
172
+ if (selectedIndex === -1) {
173
+ selectNextItem();
174
+ }
144
175
 
145
- case 'ArrowUp':
146
- selectPreviousItem();
147
176
  break;
148
177
  }
149
178
 
@@ -158,7 +187,7 @@ var InputQuery = /*#__PURE__*/_react.default.memo(function (_ref) {
158
187
  event.preventDefault();
159
188
  return false;
160
189
  }
161
- }, [onUndoRedo, onItemSelect, selectNextItem, cancel, selectPreviousItem, cleanedInputContent]);
190
+ }, [onUndoRedo, onItemSelect, selectNextItem, cancel, cleanedInputContent, editorView.state]);
162
191
  var onClick = (0, _react.useCallback)(function (event) {
163
192
  var _ref$current3;
164
193
 
@@ -249,6 +278,7 @@ var InputQuery = /*#__PURE__*/_react.default.memo(function (_ref) {
249
278
  var beforeinput = function beforeinput(e) {
250
279
  var _target$textContent;
251
280
 
281
+ setInFocus(false);
252
282
  var target = e.target;
253
283
 
254
284
  if (e.isComposing || !(target instanceof HTMLElement)) {
@@ -320,7 +350,7 @@ var InputQuery = /*#__PURE__*/_react.default.memo(function (_ref) {
320
350
  element.removeEventListener('input', onInput);
321
351
  }
322
352
  };
323
- }, [triggerQueryPrefix, cleanedInputContent, onQueryFocus, cancel, checkKeyEvent]);
353
+ }, [triggerQueryPrefix, cleanedInputContent, onQueryFocus, cancel, checkKeyEvent, editorView.state]);
324
354
  (0, _react.useLayoutEffect)(function () {
325
355
  var hasReopenQuery = typeof reopenQuery === 'string' && reopenQuery.trim().length > 0;
326
356
 
@@ -343,9 +373,12 @@ var InputQuery = /*#__PURE__*/_react.default.memo(function (_ref) {
343
373
  }
344
374
 
345
375
  ref.current.focus();
376
+ setInFocus(true);
346
377
  });
347
378
  }
348
379
  }, [forceFocus, reopenQuery]);
380
+ var assistiveHintID = _constants.TYPE_AHEAD_DECORATION_ELEMENT_ID + '__assistiveHint';
381
+ var intl = (0, _reactIntlNext.useIntl)();
349
382
  /**
350
383
  When we migrated to emotion from styled component, we started getting this error.
351
384
  jsx-a11y/interactive-supports-focus
@@ -358,9 +391,24 @@ var InputQuery = /*#__PURE__*/_react.default.memo(function (_ref) {
358
391
  ref: ref,
359
392
  onKeyUp: onKeyUp,
360
393
  onClick: onClick,
361
- role: "textbox",
394
+ role: "combobox",
395
+ "aria-controls": _constants.TYPE_AHEAD_DECORATION_ELEMENT_ID,
396
+ "aria-autocomplete": "list",
397
+ "aria-expanded": items.length !== 0,
398
+ "aria-labelledby": assistiveHintID,
362
399
  suppressContentEditableWarning: true,
363
400
  "data-query-prefix": triggerQueryPrefix
401
+ }), (0, _react2.jsx)("span", {
402
+ id: assistiveHintID,
403
+ style: {
404
+ display: 'none'
405
+ }
406
+ }, intl.formatMessage(_messages.typeAheadListMessages.inputQueryAssistiveLabel)), (0, _react2.jsx)(_AssistiveText.AssistiveText, {
407
+ assistiveText: items.length === 0 ? intl.formatMessage(_messages.typeAheadListMessages.noSearchResultsLabel, {
408
+ itemsLength: items.length
409
+ }) : '',
410
+ isInFocus: items.length === 0 || isInFocus,
411
+ id: _constants.TYPE_AHEAD_DECORATION_ELEMENT_ID
364
412
  }));
365
413
  });
366
414
 
@@ -19,6 +19,8 @@ var _react2 = require("@emotion/react");
19
19
 
20
20
  var _menu = require("@atlaskit/menu");
21
21
 
22
+ var _typeAhead = require("@atlaskit/editor-common/type-ahead");
23
+
22
24
  var _CellMeasurer = require("react-virtualized/dist/commonjs/CellMeasurer");
23
25
 
24
26
  var _List = require("react-virtualized/dist/commonjs/List");
@@ -29,6 +31,14 @@ var _reactIntlNext = require("react-intl-next");
29
31
 
30
32
  var _messages = require("../messages");
31
33
 
34
+ var _utils = require("../utils");
35
+
36
+ var _updateSelectedIndex = require("../commands/update-selected-index");
37
+
38
+ var _AssistiveText = require("./AssistiveText");
39
+
40
+ var _constants = require("../constants");
41
+
32
42
  var _templateObject;
33
43
 
34
44
  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); }
@@ -38,14 +48,31 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
38
48
  var LIST_ITEM_ESTIMATED_HEIGHT = _TypeAheadListItem.ICON_HEIGHT + _TypeAheadListItem.ITEM_PADDING * 2;
39
49
  var LIST_WIDTH = 320;
40
50
 
41
- var TypeAheadListComponent = /*#__PURE__*/_react.default.memo(function (_ref) {
42
- var items = _ref.items,
43
- selectedIndex = _ref.selectedIndex,
44
- onItemHover = _ref.onItemHover,
45
- onItemClick = _ref.onItemClick,
46
- intl = _ref.intl,
47
- fitHeight = _ref.fitHeight;
51
+ var TypeaheadAssistiveTextPureComponent = /*#__PURE__*/_react.default.memo(function (_ref) {
52
+ var numberOfResults = _ref.numberOfResults;
53
+ var intl = (0, _reactIntlNext.useIntl)();
54
+ return (0, _react2.jsx)(_AssistiveText.AssistiveText, {
55
+ assistiveText: intl.formatMessage(_messages.typeAheadListMessages.searchResultsLabel, {
56
+ itemsLength: numberOfResults
57
+ }) // when the popup is open its always in focus
58
+ ,
59
+ isInFocus: true,
60
+ id: _constants.TYPE_AHEAD_DECORATION_ELEMENT_ID + '__popup'
61
+ });
62
+ });
63
+
64
+ var TypeAheadListComponent = /*#__PURE__*/_react.default.memo(function (_ref2) {
65
+ var _decorationElement$qu2;
66
+
67
+ var items = _ref2.items,
68
+ selectedIndex = _ref2.selectedIndex,
69
+ editorView = _ref2.editorView,
70
+ onItemClick = _ref2.onItemClick,
71
+ intl = _ref2.intl,
72
+ fitHeight = _ref2.fitHeight,
73
+ decorationElement = _ref2.decorationElement;
48
74
  var listRef = (0, _react.useRef)();
75
+ var listContainerRef = (0, _react.useRef)(null);
49
76
  var lastVisibleIndexes = (0, _react.useRef)({
50
77
  overscanStartIndex: 0,
51
78
  overscanStopIndex: 0,
@@ -72,12 +99,38 @@ var TypeAheadListComponent = /*#__PURE__*/_react.default.memo(function (_ref) {
72
99
  }, []);
73
100
  var actions = (0, _react.useMemo)(function () {
74
101
  return {
75
- onItemClick: onItemClick,
76
- onItemHover: onItemHover
102
+ onItemClick: onItemClick
77
103
  };
78
- }, [onItemClick, onItemHover]);
79
- var onScroll = (0, _react.useCallback)(function (_ref2) {
80
- var scrollUpdateWasRequested = _ref2.scrollUpdateWasRequested;
104
+ }, [onItemClick]);
105
+
106
+ var isNavigationKey = function isNavigationKey(event) {
107
+ return ['ArrowDown', 'ArrowUp', 'Tab', 'Enter'].includes(event.key);
108
+ };
109
+
110
+ var focusTargetElement = (0, _react.useCallback)(function () {
111
+ var _decorationElement$qu;
112
+
113
+ //To reset the selected index
114
+ (0, _updateSelectedIndex.updateSelectedIndex)(-1)(editorView.state, editorView.dispatch);
115
+ listRef.current.scrollToRow(0);
116
+ decorationElement === null || decorationElement === void 0 ? void 0 : (_decorationElement$qu = decorationElement.querySelector("[role='combobox']")) === null || _decorationElement$qu === void 0 ? void 0 : _decorationElement$qu.focus();
117
+ }, [editorView, listRef, decorationElement]);
118
+ var selectNextItem = (0, _react.useMemo)(function () {
119
+ return (0, _utils.moveSelectedIndex)({
120
+ editorView: editorView,
121
+ direction: 'next'
122
+ });
123
+ }, [editorView]);
124
+ var selectPreviousItem = (0, _react.useMemo)(function () {
125
+ return (0, _utils.moveSelectedIndex)({
126
+ editorView: editorView,
127
+ direction: 'previous'
128
+ });
129
+ }, [editorView]);
130
+ var lastVisibleStartIndex = lastVisibleIndexes.current.startIndex;
131
+ var lastVisibleStopIndex = lastVisibleIndexes.current.stopIndex;
132
+ var onScroll = (0, _react.useCallback)(function (_ref3) {
133
+ var scrollUpdateWasRequested = _ref3.scrollUpdateWasRequested;
81
134
 
82
135
  if (!scrollUpdateWasRequested) {
83
136
  return;
@@ -95,27 +148,29 @@ var TypeAheadListComponent = /*#__PURE__*/_react.default.memo(function (_ref) {
95
148
 
96
149
  requestAnimationFrame(function () {
97
150
  requestAnimationFrame(function () {
98
- var indexes = lastVisibleIndexes.current;
99
- var isSelectedItemVisible = selectedIndex >= indexes.startIndex && selectedIndex <= indexes.stopIndex;
151
+ var isSelectedItemVisible = selectedIndex >= lastVisibleStartIndex && selectedIndex <= lastVisibleStopIndex; //Should scroll to the list item only when the selectedIndex >= 0 and item is not visible
100
152
 
101
- if (!isSelectedItemVisible) {
153
+ if (!isSelectedItemVisible && selectedIndex !== -1) {
102
154
  listRef.current.scrollToRow(selectedIndex);
155
+ } else if (selectedIndex === -1) {
156
+ listRef.current.scrollToRow(0);
103
157
  }
104
158
  });
105
159
  });
106
- }, [selectedIndex, lastVisibleIndexes]);
160
+ }, [selectedIndex, lastVisibleStartIndex, lastVisibleStopIndex]);
107
161
  (0, _react.useLayoutEffect)(function () {
108
162
  if (!listRef.current) {
109
163
  return;
110
164
  }
111
165
 
112
- var indexes = lastVisibleIndexes.current;
113
- var isSelectedItemVisible = selectedIndex >= indexes.startIndex && selectedIndex <= indexes.stopIndex;
166
+ var isSelectedItemVisible = selectedIndex >= lastVisibleStartIndex && selectedIndex <= lastVisibleStopIndex; //Should scroll to the list item only when the selectedIndex >= 0 and item is not visible
114
167
 
115
- if (!isSelectedItemVisible) {
168
+ if (!isSelectedItemVisible && selectedIndex !== -1) {
116
169
  listRef.current.scrollToRow(selectedIndex);
170
+ } else if (selectedIndex === -1) {
171
+ listRef.current.scrollToRow(0);
117
172
  }
118
- }, [selectedIndex, lastVisibleIndexes]);
173
+ }, [selectedIndex, lastVisibleStartIndex, lastVisibleStopIndex]);
119
174
  (0, _react.useLayoutEffect)(function () {
120
175
  setCache(new _CellMeasurer.CellMeasurerCache({
121
176
  fixedWidth: true,
@@ -130,12 +185,76 @@ var TypeAheadListComponent = /*#__PURE__*/_react.default.memo(function (_ref) {
130
185
  }, 0), fitHeight);
131
186
  setHeight(height);
132
187
  }, [items, cache, fitHeight]);
188
+ (0, _react.useLayoutEffect)(function () {
189
+ if (!listContainerRef.current) {
190
+ return;
191
+ }
192
+
193
+ var element = listContainerRef.current;
194
+ /**
195
+ * To handle the key events on the list
196
+ * @param event
197
+ */
198
+
199
+ var handleKeyDown = function handleKeyDown(event) {
200
+ if (isNavigationKey(event)) {
201
+ switch (event.key) {
202
+ case 'ArrowDown':
203
+ if (selectedIndex === items.length - 1) {
204
+ event.stopPropagation();
205
+ } else {
206
+ selectNextItem();
207
+ }
208
+
209
+ event.preventDefault();
210
+ break;
211
+
212
+ case 'ArrowUp':
213
+ if (selectedIndex === 0) {
214
+ //To set focus on target element when up arrow is pressed on first option of list
215
+ focusTargetElement();
216
+ } else {
217
+ selectPreviousItem();
218
+ }
219
+
220
+ event.preventDefault();
221
+ break;
222
+
223
+ case 'Tab':
224
+ //Tab key quick inserts the selected item.
225
+ onItemClick(_typeAhead.SelectItemMode.TAB, selectedIndex);
226
+ event.preventDefault();
227
+ break;
228
+
229
+ case 'Enter':
230
+ //Enter key quick inserts the selected item.
231
+ if (!event.isComposing || event.which !== 229 && event.keyCode !== 229) {
232
+ onItemClick(event.shiftKey ? _typeAhead.SelectItemMode.SHIFT_ENTER : _typeAhead.SelectItemMode.ENTER, selectedIndex);
233
+ event.preventDefault();
234
+ }
133
235
 
134
- var renderRow = function renderRow(_ref3) {
135
- var index = _ref3.index,
136
- key = _ref3.key,
137
- style = _ref3.style,
138
- parent = _ref3.parent;
236
+ break;
237
+
238
+ default:
239
+ event.preventDefault();
240
+ }
241
+ } else {
242
+ //All the remaining keys sets focus on the typeahead query(inputQuery.tsx))
243
+ focusTargetElement();
244
+ }
245
+ };
246
+
247
+ element === null || element === void 0 ? void 0 : element.addEventListener('keydown', handleKeyDown);
248
+ return function () {
249
+ element === null || element === void 0 ? void 0 : element.removeEventListener('keydown', handleKeyDown);
250
+ };
251
+ }, [editorView.state, focusTargetElement, selectNextItem, selectPreviousItem, selectedIndex, onItemClick, items.length]);
252
+
253
+ var renderRow = function renderRow(_ref4) {
254
+ var index = _ref4.index,
255
+ key = _ref4.key,
256
+ style = _ref4.style,
257
+ parent = _ref4.parent;
139
258
  return (0, _react2.jsx)(_CellMeasurer.CellMeasurer, {
140
259
  key: key,
141
260
  cache: cache,
@@ -150,10 +269,10 @@ var TypeAheadListComponent = /*#__PURE__*/_react.default.memo(function (_ref) {
150
269
  }, (0, _react2.jsx)(_TypeAheadListItem.TypeAheadListItem, {
151
270
  key: items[index].title,
152
271
  item: items[index],
272
+ itemsLength: items.length,
153
273
  itemIndex: index,
154
274
  selectedIndex: selectedIndex,
155
- onItemClick: actions.onItemClick,
156
- onItemHover: actions.onItemHover
275
+ onItemClick: actions.onItemClick
157
276
  }))));
158
277
  };
159
278
 
@@ -161,11 +280,13 @@ var TypeAheadListComponent = /*#__PURE__*/_react.default.memo(function (_ref) {
161
280
  return null;
162
281
  }
163
282
 
283
+ var menuGroupId = ((_decorationElement$qu2 = decorationElement.querySelector("[role='combobox']")) === null || _decorationElement$qu2 === void 0 ? void 0 : _decorationElement$qu2.getAttribute('aria-controls')) || _constants.TYPE_AHEAD_DECORATION_ELEMENT_ID;
164
284
  return (0, _react2.jsx)(_menu.MenuGroup, {
165
- role: "listbox",
166
- "aria-live": "polite",
167
285
  "aria-label": intl.formatMessage(_messages.typeAheadListMessages.typeAheadResultLabel),
168
286
  "aria-relevant": "additions removals"
287
+ }, (0, _react2.jsx)("div", {
288
+ id: menuGroupId,
289
+ ref: listContainerRef
169
290
  }, (0, _react2.jsx)(_List.List, {
170
291
  rowRenderer: renderRow,
171
292
  ref: listRef,
@@ -176,8 +297,12 @@ var TypeAheadListComponent = /*#__PURE__*/_react.default.memo(function (_ref) {
176
297
  onScroll: onScroll,
177
298
  height: height,
178
299
  overscanRowCount: 3,
179
- css: (0, _react2.css)(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n button {\n padding: 12px 12px 11px;\n span:last-child span:last-child {\n white-space: normal;\n }\n }\n "])))
180
- }));
300
+ containerRole: "presentation",
301
+ role: "listbox",
302
+ css: (0, _react2.css)(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n button {\n padding: 12px 12px 11px;\n span:last-child span:last-child {\n white-space: normal;\n }\n }\n "])))
303
+ }), (0, _react2.jsx)(TypeaheadAssistiveTextPureComponent, {
304
+ numberOfResults: items.length.toString()
305
+ })));
181
306
  });
182
307
 
183
308
  var TypeAheadList = (0, _reactIntlNext.injectIntl)(TypeAheadListComponent);