@atlaskit/editor-core 188.9.0 → 188.9.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 (207) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/labs/next/presets/default.js +2 -2
  3. package/dist/cjs/plugins/index.js +0 -7
  4. package/dist/cjs/plugins/insert-block/index.js +4 -6
  5. package/dist/cjs/plugins/tasks-and-decisions/index.js +4 -3
  6. package/dist/cjs/plugins/tasks-and-decisions/nodeviews/decisionItem.js +26 -6
  7. package/dist/cjs/plugins/tasks-and-decisions/nodeviews/taskItem.js +45 -13
  8. package/dist/cjs/plugins/tasks-and-decisions/pm-plugins/main.js +15 -7
  9. package/dist/cjs/version-wrapper.js +1 -1
  10. package/dist/es2019/labs/next/presets/default.js +1 -1
  11. package/dist/es2019/plugins/index.js +0 -1
  12. package/dist/es2019/plugins/insert-block/index.js +4 -6
  13. package/dist/es2019/plugins/tasks-and-decisions/index.js +4 -3
  14. package/dist/es2019/plugins/tasks-and-decisions/nodeviews/decisionItem.js +26 -6
  15. package/dist/es2019/plugins/tasks-and-decisions/nodeviews/taskItem.js +43 -10
  16. package/dist/es2019/plugins/tasks-and-decisions/pm-plugins/main.js +13 -6
  17. package/dist/es2019/version-wrapper.js +1 -1
  18. package/dist/esm/labs/next/presets/default.js +1 -1
  19. package/dist/esm/plugins/index.js +0 -1
  20. package/dist/esm/plugins/insert-block/index.js +4 -6
  21. package/dist/esm/plugins/tasks-and-decisions/index.js +4 -3
  22. package/dist/esm/plugins/tasks-and-decisions/nodeviews/decisionItem.js +26 -6
  23. package/dist/esm/plugins/tasks-and-decisions/nodeviews/taskItem.js +45 -12
  24. package/dist/esm/plugins/tasks-and-decisions/pm-plugins/main.js +14 -7
  25. package/dist/esm/version-wrapper.js +1 -1
  26. package/dist/types/labs/next/presets/default.d.ts +43 -43
  27. package/dist/types/plugins/index.d.ts +0 -1
  28. package/dist/types/plugins/insert-block/types.d.ts +2 -0
  29. package/dist/types/plugins/tasks-and-decisions/index.d.ts +2 -5
  30. package/dist/types/plugins/tasks-and-decisions/nodeviews/decisionItem.d.ts +9 -4
  31. package/dist/types/plugins/tasks-and-decisions/nodeviews/taskItem.d.ts +9 -4
  32. package/dist/types/plugins/tasks-and-decisions/pm-plugins/main.d.ts +4 -2
  33. package/dist/types/plugins/tasks-and-decisions/types.d.ts +6 -1
  34. package/dist/types-ts4.5/labs/next/presets/default.d.ts +43 -43
  35. package/dist/types-ts4.5/plugins/index.d.ts +0 -1
  36. package/dist/types-ts4.5/plugins/insert-block/types.d.ts +2 -0
  37. package/dist/types-ts4.5/plugins/tasks-and-decisions/index.d.ts +2 -5
  38. package/dist/types-ts4.5/plugins/tasks-and-decisions/nodeviews/decisionItem.d.ts +9 -4
  39. package/dist/types-ts4.5/plugins/tasks-and-decisions/nodeviews/taskItem.d.ts +9 -4
  40. package/dist/types-ts4.5/plugins/tasks-and-decisions/pm-plugins/main.d.ts +4 -2
  41. package/dist/types-ts4.5/plugins/tasks-and-decisions/types.d.ts +8 -1
  42. package/package.json +10 -8
  43. package/dist/cjs/plugins/type-ahead/api.js +0 -215
  44. package/dist/cjs/plugins/type-ahead/commands/insert-type-ahead-item.js +0 -205
  45. package/dist/cjs/plugins/type-ahead/commands/update-list-items.js +0 -23
  46. package/dist/cjs/plugins/type-ahead/commands/update-query.js +0 -27
  47. package/dist/cjs/plugins/type-ahead/commands/update-selected-index.js +0 -27
  48. package/dist/cjs/plugins/type-ahead/constants.js +0 -15
  49. package/dist/cjs/plugins/type-ahead/index.js +0 -14
  50. package/dist/cjs/plugins/type-ahead/insert-utils.js +0 -107
  51. package/dist/cjs/plugins/type-ahead/messages.js +0 -79
  52. package/dist/cjs/plugins/type-ahead/plugin.js +0 -382
  53. package/dist/cjs/plugins/type-ahead/pm-plugins/actions.js +0 -16
  54. package/dist/cjs/plugins/type-ahead/pm-plugins/decorations.js +0 -148
  55. package/dist/cjs/plugins/type-ahead/pm-plugins/input-rules.js +0 -36
  56. package/dist/cjs/plugins/type-ahead/pm-plugins/insert-item-plugin.js +0 -22
  57. package/dist/cjs/plugins/type-ahead/pm-plugins/key.js +0 -8
  58. package/dist/cjs/plugins/type-ahead/pm-plugins/main.js +0 -110
  59. package/dist/cjs/plugins/type-ahead/pm-plugins/reducer.js +0 -158
  60. package/dist/cjs/plugins/type-ahead/pm-plugins/utils.js +0 -18
  61. package/dist/cjs/plugins/type-ahead/stats-modifier.js +0 -42
  62. package/dist/cjs/plugins/type-ahead/transforms/close-type-ahead.js +0 -13
  63. package/dist/cjs/plugins/type-ahead/transforms/open-typeahead-at-cursor.js +0 -75
  64. package/dist/cjs/plugins/type-ahead/transforms/set-selection-before-query.js +0 -18
  65. package/dist/cjs/plugins/type-ahead/types.js +0 -5
  66. package/dist/cjs/plugins/type-ahead/ui/AssistiveText.js +0 -120
  67. package/dist/cjs/plugins/type-ahead/ui/InputQuery.js +0 -400
  68. package/dist/cjs/plugins/type-ahead/ui/TypeAheadList.js +0 -285
  69. package/dist/cjs/plugins/type-ahead/ui/TypeAheadListItem.js +0 -179
  70. package/dist/cjs/plugins/type-ahead/ui/TypeAheadPopup.js +0 -230
  71. package/dist/cjs/plugins/type-ahead/ui/WrapperTypeAhead.js +0 -127
  72. package/dist/cjs/plugins/type-ahead/ui/hooks/use-item-insert.js +0 -109
  73. package/dist/cjs/plugins/type-ahead/ui/hooks/use-load-items.js +0 -50
  74. package/dist/cjs/plugins/type-ahead/ui/hooks/use-on-force-select.js +0 -41
  75. package/dist/cjs/plugins/type-ahead/utils.js +0 -130
  76. package/dist/es2019/plugins/type-ahead/api.js +0 -205
  77. package/dist/es2019/plugins/type-ahead/commands/insert-type-ahead-item.js +0 -204
  78. package/dist/es2019/plugins/type-ahead/commands/update-list-items.js +0 -17
  79. package/dist/es2019/plugins/type-ahead/commands/update-query.js +0 -21
  80. package/dist/es2019/plugins/type-ahead/commands/update-selected-index.js +0 -21
  81. package/dist/es2019/plugins/type-ahead/constants.js +0 -9
  82. package/dist/es2019/plugins/type-ahead/index.js +0 -3
  83. package/dist/es2019/plugins/type-ahead/insert-utils.js +0 -106
  84. package/dist/es2019/plugins/type-ahead/messages.js +0 -73
  85. package/dist/es2019/plugins/type-ahead/plugin.js +0 -381
  86. package/dist/es2019/plugins/type-ahead/pm-plugins/actions.js +0 -10
  87. package/dist/es2019/plugins/type-ahead/pm-plugins/decorations.js +0 -148
  88. package/dist/es2019/plugins/type-ahead/pm-plugins/input-rules.js +0 -29
  89. package/dist/es2019/plugins/type-ahead/pm-plugins/insert-item-plugin.js +0 -16
  90. package/dist/es2019/plugins/type-ahead/pm-plugins/key.js +0 -2
  91. package/dist/es2019/plugins/type-ahead/pm-plugins/main.js +0 -106
  92. package/dist/es2019/plugins/type-ahead/pm-plugins/reducer.js +0 -160
  93. package/dist/es2019/plugins/type-ahead/pm-plugins/utils.js +0 -12
  94. package/dist/es2019/plugins/type-ahead/stats-modifier.js +0 -33
  95. package/dist/es2019/plugins/type-ahead/transforms/close-type-ahead.js +0 -7
  96. package/dist/es2019/plugins/type-ahead/transforms/open-typeahead-at-cursor.js +0 -71
  97. package/dist/es2019/plugins/type-ahead/transforms/set-selection-before-query.js +0 -10
  98. package/dist/es2019/plugins/type-ahead/types.js +0 -1
  99. package/dist/es2019/plugins/type-ahead/ui/AssistiveText.js +0 -88
  100. package/dist/es2019/plugins/type-ahead/ui/InputQuery.js +0 -393
  101. package/dist/es2019/plugins/type-ahead/ui/TypeAheadList.js +0 -273
  102. package/dist/es2019/plugins/type-ahead/ui/TypeAheadListItem.js +0 -214
  103. package/dist/es2019/plugins/type-ahead/ui/TypeAheadPopup.js +0 -233
  104. package/dist/es2019/plugins/type-ahead/ui/WrapperTypeAhead.js +0 -109
  105. package/dist/es2019/plugins/type-ahead/ui/hooks/use-item-insert.js +0 -112
  106. package/dist/es2019/plugins/type-ahead/ui/hooks/use-load-items.js +0 -41
  107. package/dist/es2019/plugins/type-ahead/ui/hooks/use-on-force-select.js +0 -38
  108. package/dist/es2019/plugins/type-ahead/utils.js +0 -126
  109. package/dist/esm/plugins/type-ahead/api.js +0 -209
  110. package/dist/esm/plugins/type-ahead/commands/insert-type-ahead-item.js +0 -198
  111. package/dist/esm/plugins/type-ahead/commands/update-list-items.js +0 -17
  112. package/dist/esm/plugins/type-ahead/commands/update-query.js +0 -21
  113. package/dist/esm/plugins/type-ahead/commands/update-selected-index.js +0 -21
  114. package/dist/esm/plugins/type-ahead/constants.js +0 -9
  115. package/dist/esm/plugins/type-ahead/index.js +0 -3
  116. package/dist/esm/plugins/type-ahead/insert-utils.js +0 -101
  117. package/dist/esm/plugins/type-ahead/messages.js +0 -73
  118. package/dist/esm/plugins/type-ahead/plugin.js +0 -374
  119. package/dist/esm/plugins/type-ahead/pm-plugins/actions.js +0 -10
  120. package/dist/esm/plugins/type-ahead/pm-plugins/decorations.js +0 -141
  121. package/dist/esm/plugins/type-ahead/pm-plugins/input-rules.js +0 -29
  122. package/dist/esm/plugins/type-ahead/pm-plugins/insert-item-plugin.js +0 -16
  123. package/dist/esm/plugins/type-ahead/pm-plugins/key.js +0 -2
  124. package/dist/esm/plugins/type-ahead/pm-plugins/main.js +0 -104
  125. package/dist/esm/plugins/type-ahead/pm-plugins/reducer.js +0 -151
  126. package/dist/esm/plugins/type-ahead/pm-plugins/utils.js +0 -12
  127. package/dist/esm/plugins/type-ahead/stats-modifier.js +0 -35
  128. package/dist/esm/plugins/type-ahead/transforms/close-type-ahead.js +0 -7
  129. package/dist/esm/plugins/type-ahead/transforms/open-typeahead-at-cursor.js +0 -69
  130. package/dist/esm/plugins/type-ahead/transforms/set-selection-before-query.js +0 -12
  131. package/dist/esm/plugins/type-ahead/types.js +0 -1
  132. package/dist/esm/plugins/type-ahead/ui/AssistiveText.js +0 -115
  133. package/dist/esm/plugins/type-ahead/ui/InputQuery.js +0 -390
  134. package/dist/esm/plugins/type-ahead/ui/TypeAheadList.js +0 -276
  135. package/dist/esm/plugins/type-ahead/ui/TypeAheadListItem.js +0 -169
  136. package/dist/esm/plugins/type-ahead/ui/TypeAheadPopup.js +0 -220
  137. package/dist/esm/plugins/type-ahead/ui/WrapperTypeAhead.js +0 -117
  138. package/dist/esm/plugins/type-ahead/ui/hooks/use-item-insert.js +0 -103
  139. package/dist/esm/plugins/type-ahead/ui/hooks/use-load-items.js +0 -43
  140. package/dist/esm/plugins/type-ahead/ui/hooks/use-on-force-select.js +0 -35
  141. package/dist/esm/plugins/type-ahead/utils.js +0 -124
  142. package/dist/types/plugins/type-ahead/api.d.ts +0 -61
  143. package/dist/types/plugins/type-ahead/commands/insert-type-ahead-item.d.ts +0 -12
  144. package/dist/types/plugins/type-ahead/commands/update-list-items.d.ts +0 -3
  145. package/dist/types/plugins/type-ahead/commands/update-query.d.ts +0 -2
  146. package/dist/types/plugins/type-ahead/commands/update-selected-index.d.ts +0 -2
  147. package/dist/types/plugins/type-ahead/constants.d.ts +0 -8
  148. package/dist/types/plugins/type-ahead/index.d.ts +0 -4
  149. package/dist/types/plugins/type-ahead/insert-utils.d.ts +0 -18
  150. package/dist/types/plugins/type-ahead/messages.d.ts +0 -72
  151. package/dist/types/plugins/type-ahead/plugin.d.ts +0 -10
  152. package/dist/types/plugins/type-ahead/pm-plugins/actions.d.ts +0 -9
  153. package/dist/types/plugins/type-ahead/pm-plugins/decorations.d.ts +0 -14
  154. package/dist/types/plugins/type-ahead/pm-plugins/input-rules.d.ts +0 -6
  155. package/dist/types/plugins/type-ahead/pm-plugins/insert-item-plugin.d.ts +0 -2
  156. package/dist/types/plugins/type-ahead/pm-plugins/key.d.ts +0 -3
  157. package/dist/types/plugins/type-ahead/pm-plugins/main.d.ts +0 -14
  158. package/dist/types/plugins/type-ahead/pm-plugins/reducer.d.ts +0 -10
  159. package/dist/types/plugins/type-ahead/pm-plugins/utils.d.ts +0 -4
  160. package/dist/types/plugins/type-ahead/stats-modifier.d.ts +0 -20
  161. package/dist/types/plugins/type-ahead/transforms/close-type-ahead.d.ts +0 -2
  162. package/dist/types/plugins/type-ahead/transforms/open-typeahead-at-cursor.d.ts +0 -11
  163. package/dist/types/plugins/type-ahead/transforms/set-selection-before-query.d.ts +0 -2
  164. package/dist/types/plugins/type-ahead/types.d.ts +0 -109
  165. package/dist/types/plugins/type-ahead/ui/AssistiveText.d.ts +0 -33
  166. package/dist/types/plugins/type-ahead/ui/InputQuery.d.ts +0 -26
  167. package/dist/types/plugins/type-ahead/ui/TypeAheadList.d.ts +0 -25
  168. package/dist/types/plugins/type-ahead/ui/TypeAheadListItem.d.ts +0 -18
  169. package/dist/types/plugins/type-ahead/ui/TypeAheadPopup.d.ts +0 -29
  170. package/dist/types/plugins/type-ahead/ui/WrapperTypeAhead.d.ts +0 -20
  171. package/dist/types/plugins/type-ahead/ui/hooks/use-item-insert.d.ts +0 -3
  172. package/dist/types/plugins/type-ahead/ui/hooks/use-load-items.d.ts +0 -3
  173. package/dist/types/plugins/type-ahead/ui/hooks/use-on-force-select.d.ts +0 -11
  174. package/dist/types/plugins/type-ahead/utils.d.ts +0 -27
  175. package/dist/types-ts4.5/plugins/type-ahead/api.d.ts +0 -61
  176. package/dist/types-ts4.5/plugins/type-ahead/commands/insert-type-ahead-item.d.ts +0 -12
  177. package/dist/types-ts4.5/plugins/type-ahead/commands/update-list-items.d.ts +0 -3
  178. package/dist/types-ts4.5/plugins/type-ahead/commands/update-query.d.ts +0 -2
  179. package/dist/types-ts4.5/plugins/type-ahead/commands/update-selected-index.d.ts +0 -2
  180. package/dist/types-ts4.5/plugins/type-ahead/constants.d.ts +0 -8
  181. package/dist/types-ts4.5/plugins/type-ahead/index.d.ts +0 -4
  182. package/dist/types-ts4.5/plugins/type-ahead/insert-utils.d.ts +0 -18
  183. package/dist/types-ts4.5/plugins/type-ahead/messages.d.ts +0 -72
  184. package/dist/types-ts4.5/plugins/type-ahead/plugin.d.ts +0 -10
  185. package/dist/types-ts4.5/plugins/type-ahead/pm-plugins/actions.d.ts +0 -9
  186. package/dist/types-ts4.5/plugins/type-ahead/pm-plugins/decorations.d.ts +0 -14
  187. package/dist/types-ts4.5/plugins/type-ahead/pm-plugins/input-rules.d.ts +0 -6
  188. package/dist/types-ts4.5/plugins/type-ahead/pm-plugins/insert-item-plugin.d.ts +0 -2
  189. package/dist/types-ts4.5/plugins/type-ahead/pm-plugins/key.d.ts +0 -3
  190. package/dist/types-ts4.5/plugins/type-ahead/pm-plugins/main.d.ts +0 -14
  191. package/dist/types-ts4.5/plugins/type-ahead/pm-plugins/reducer.d.ts +0 -10
  192. package/dist/types-ts4.5/plugins/type-ahead/pm-plugins/utils.d.ts +0 -4
  193. package/dist/types-ts4.5/plugins/type-ahead/stats-modifier.d.ts +0 -20
  194. package/dist/types-ts4.5/plugins/type-ahead/transforms/close-type-ahead.d.ts +0 -2
  195. package/dist/types-ts4.5/plugins/type-ahead/transforms/open-typeahead-at-cursor.d.ts +0 -11
  196. package/dist/types-ts4.5/plugins/type-ahead/transforms/set-selection-before-query.d.ts +0 -2
  197. package/dist/types-ts4.5/plugins/type-ahead/types.d.ts +0 -111
  198. package/dist/types-ts4.5/plugins/type-ahead/ui/AssistiveText.d.ts +0 -33
  199. package/dist/types-ts4.5/plugins/type-ahead/ui/InputQuery.d.ts +0 -26
  200. package/dist/types-ts4.5/plugins/type-ahead/ui/TypeAheadList.d.ts +0 -25
  201. package/dist/types-ts4.5/plugins/type-ahead/ui/TypeAheadListItem.d.ts +0 -18
  202. package/dist/types-ts4.5/plugins/type-ahead/ui/TypeAheadPopup.d.ts +0 -29
  203. package/dist/types-ts4.5/plugins/type-ahead/ui/WrapperTypeAhead.d.ts +0 -20
  204. package/dist/types-ts4.5/plugins/type-ahead/ui/hooks/use-item-insert.d.ts +0 -7
  205. package/dist/types-ts4.5/plugins/type-ahead/ui/hooks/use-load-items.d.ts +0 -3
  206. package/dist/types-ts4.5/plugins/type-ahead/ui/hooks/use-on-force-select.d.ts +0 -11
  207. package/dist/types-ts4.5/plugins/type-ahead/utils.d.ts +0 -27
@@ -1,233 +0,0 @@
1
- /** @jsx jsx */
2
- import React, { useCallback, useEffect, useMemo, useState, useLayoutEffect, useRef } from 'react';
3
- import { css, jsx } from '@emotion/react';
4
- import rafSchedule from 'raf-schd';
5
- import { akEditorFloatingDialogZIndex } from '@atlaskit/editor-shared-styles';
6
- import { findOverflowScrollParent, Popup } from '@atlaskit/editor-common/ui';
7
- import { borderRadius } from '@atlaskit/theme/constants';
8
- import { N0, N60A, N50A } from '@atlaskit/theme/colors';
9
- import { ACTION, ACTION_SUBJECT, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
10
- import { CloseSelectionOptions, TYPE_AHEAD_DECORATION_DATA_ATTRIBUTE, TYPE_AHEAD_POPUP_CONTENT_CLASS } from '../constants';
11
- import { TypeAheadList } from './TypeAheadList';
12
- import { ITEM_PADDING } from './TypeAheadListItem';
13
- const DEFAULT_TYPEAHEAD_MENU_HEIGHT = 380;
14
- const typeAheadContent = css`
15
- background: ${`var(--ds-surface-overlay, ${N0})`};
16
- border-radius: ${borderRadius()}px;
17
- box-shadow: ${`var(--ds-shadow-overlay, ${`0 0 1px ${N60A}, 0 4px 8px -2px ${N50A}`})`};
18
- padding: ${"var(--ds-space-050, 4px)"} 0;
19
- width: 320px;
20
- max-height: 380px; /* ~5.5 visibile items */
21
- overflow-y: auto;
22
- -ms-overflow-style: -ms-autohiding-scrollbar;
23
- position: relative;
24
- `;
25
- const Highlight = ({
26
- state,
27
- triggerHandler
28
- }) => {
29
- if (!(triggerHandler !== null && triggerHandler !== void 0 && triggerHandler.getHighlight)) {
30
- return null;
31
- }
32
- return triggerHandler.getHighlight(state);
33
- };
34
- const OFFSET = [0, 8];
35
- export const TypeAheadPopup = /*#__PURE__*/React.memo(props => {
36
- const {
37
- editorView,
38
- triggerHandler,
39
- anchorElement,
40
- popupsMountPoint,
41
- popupsBoundariesElement,
42
- popupsScrollableElement,
43
- items,
44
- selectedIndex,
45
- onItemInsert,
46
- fireAnalyticsCallback,
47
- isEmptyQuery,
48
- cancel
49
- } = props;
50
- const ref = useRef(null);
51
- const startTime = useMemo(() => performance.now(),
52
- // In case those props changes
53
- // we need to recreate the startTime
54
- [items, isEmptyQuery, fireAnalyticsCallback, triggerHandler] // eslint-disable-line react-hooks/exhaustive-deps
55
- );
56
-
57
- useEffect(() => {
58
- if (!fireAnalyticsCallback) {
59
- return;
60
- }
61
- const stopTime = performance.now();
62
- const time = stopTime - startTime;
63
- fireAnalyticsCallback({
64
- payload: {
65
- action: ACTION.RENDERED,
66
- actionSubject: ACTION_SUBJECT.TYPEAHEAD,
67
- eventType: EVENT_TYPE.OPERATIONAL,
68
- attributes: {
69
- time,
70
- items: items.length,
71
- initial: isEmptyQuery
72
- }
73
- }
74
- });
75
- }, [startTime, items, fireAnalyticsCallback, isEmptyQuery,
76
- // In case the current triggerHandler changes
77
- // e.g: Inserting a mention using the quick insert
78
- // we need to send the event again
79
- // eslint-disable-next-line react-hooks/exhaustive-deps
80
- triggerHandler]);
81
- useEffect(() => {
82
- if (!fireAnalyticsCallback) {
83
- return;
84
- }
85
- fireAnalyticsCallback({
86
- payload: {
87
- action: ACTION.VIEWED,
88
- actionSubject: ACTION_SUBJECT.TYPEAHEAD_ITEM,
89
- eventType: EVENT_TYPE.OPERATIONAL,
90
- attributes: {
91
- index: selectedIndex,
92
- items: items.length
93
- }
94
- }
95
- });
96
- }, [items, fireAnalyticsCallback, selectedIndex,
97
- // In case the current triggerHandler changes
98
- // e.g: Inserting a mention using the quick insert
99
- // we need to send the event again
100
- // eslint-disable-next-line react-hooks/exhaustive-deps
101
- triggerHandler]);
102
- const [fitHeight, setFitHeight] = useState(DEFAULT_TYPEAHEAD_MENU_HEIGHT);
103
- const getFitHeight = useCallback(() => {
104
- if (!anchorElement || !popupsMountPoint) {
105
- return;
106
- }
107
- const target = anchorElement;
108
- const {
109
- top: targetTop,
110
- height: targetHeight
111
- } = target.getBoundingClientRect();
112
- const boundariesElement = document.body;
113
- const {
114
- height: boundariesHeight,
115
- top: boundariesTop
116
- } = boundariesElement.getBoundingClientRect();
117
-
118
- // Calculating the space above and space below our decoration
119
- const spaceAbove = targetTop - (boundariesTop - boundariesElement.scrollTop);
120
- const spaceBelow = boundariesTop + boundariesHeight - (targetTop + targetHeight);
121
-
122
- // Keep default height if more than enough space
123
- if (spaceBelow >= DEFAULT_TYPEAHEAD_MENU_HEIGHT) {
124
- return setFitHeight(DEFAULT_TYPEAHEAD_MENU_HEIGHT);
125
- }
126
-
127
- // Determines whether typeahead will fit above or below decoration
128
- // and return the space available.
129
- const newFitHeight = spaceBelow >= spaceAbove ? spaceBelow : spaceAbove;
130
-
131
- // Each typeahead item has some padding
132
- // We want to leave some space at the top so first item
133
- // is not partially cropped
134
- const fitHeightWithSpace = newFitHeight - ITEM_PADDING * 2;
135
-
136
- // Ensure typeahead height is max its default height
137
- const minFitHeight = Math.min(DEFAULT_TYPEAHEAD_MENU_HEIGHT, fitHeightWithSpace);
138
- return setFitHeight(minFitHeight);
139
- }, [anchorElement, popupsMountPoint]);
140
- const getFitHeightDebounced = rafSchedule(getFitHeight);
141
- useLayoutEffect(() => {
142
- const scrollableElement = popupsScrollableElement || findOverflowScrollParent(anchorElement);
143
- getFitHeight();
144
- window.addEventListener('resize', getFitHeightDebounced);
145
- if (scrollableElement) {
146
- scrollableElement.addEventListener('scroll', getFitHeightDebounced);
147
- }
148
- return () => {
149
- window.removeEventListener('resize', getFitHeightDebounced);
150
- if (scrollableElement) {
151
- scrollableElement.removeEventListener('scroll', getFitHeightDebounced);
152
- }
153
- };
154
- }, [anchorElement, popupsScrollableElement, getFitHeightDebounced, getFitHeight]);
155
- useLayoutEffect(() => {
156
- const focusOut = event => {
157
- var _window$getSelection;
158
- const {
159
- relatedTarget
160
- } = event;
161
-
162
- // Given the user is changing the focus
163
- // When the target is inside the TypeAhead Popup
164
- // Then the popup should stay open
165
- if (relatedTarget instanceof HTMLElement && relatedTarget.closest && (relatedTarget.closest(`.${TYPE_AHEAD_POPUP_CONTENT_CLASS}`) || relatedTarget.closest(`[data-type-ahead="${TYPE_AHEAD_DECORATION_DATA_ATTRIBUTE}"]`))) {
166
- return;
167
- }
168
- if (!(((_window$getSelection = window.getSelection()) === null || _window$getSelection === void 0 ? void 0 : _window$getSelection.type) === 'Range')) {
169
- return;
170
- }
171
- cancel({
172
- addPrefixTrigger: true,
173
- setSelectionAt: CloseSelectionOptions.AFTER_TEXT_INSERTED,
174
- forceFocusOnEditor: false
175
- });
176
- };
177
- const {
178
- current: element
179
- } = ref;
180
- element === null || element === void 0 ? void 0 : element.addEventListener('focusout', focusOut);
181
- return () => {
182
- element === null || element === void 0 ? void 0 : element.removeEventListener('focusout', focusOut);
183
- };
184
- }, [ref, cancel]);
185
-
186
- // ED-17443 When you press escape on typeahead panel, it should remove focus and close the panel
187
- // This is the expected keyboard behaviour advised by the Accessibility team
188
- useLayoutEffect(() => {
189
- const escape = event => {
190
- if (event.key === 'Escape') {
191
- cancel({
192
- addPrefixTrigger: true,
193
- setSelectionAt: CloseSelectionOptions.AFTER_TEXT_INSERTED,
194
- forceFocusOnEditor: true
195
- });
196
- }
197
- };
198
- const {
199
- current: element
200
- } = ref;
201
- element === null || element === void 0 ? void 0 : element.addEventListener('keydown', escape);
202
- return () => {
203
- element === null || element === void 0 ? void 0 : element.removeEventListener('keydown', escape);
204
- };
205
- }, [ref, cancel]);
206
- return jsx(Popup, {
207
- zIndex: akEditorFloatingDialogZIndex,
208
- target: anchorElement,
209
- mountTo: popupsMountPoint,
210
- boundariesElement: popupsBoundariesElement,
211
- scrollableElement: popupsScrollableElement,
212
- fitHeight: fitHeight,
213
- fitWidth: 340,
214
- offset: OFFSET
215
- }, jsx("div", {
216
- css: typeAheadContent,
217
- tabIndex: 0,
218
- className: TYPE_AHEAD_POPUP_CONTENT_CLASS,
219
- ref: ref
220
- }, jsx(Highlight, {
221
- state: editorView.state,
222
- triggerHandler: triggerHandler
223
- }), jsx(TypeAheadList, {
224
- items: items,
225
- selectedIndex: selectedIndex,
226
- onItemClick: onItemInsert,
227
- fitHeight: fitHeight,
228
- editorView: editorView,
229
- decorationElement: anchorElement,
230
- triggerHandler: triggerHandler
231
- })));
232
- });
233
- TypeAheadPopup.displayName = 'TypeAheadPopup';
@@ -1,109 +0,0 @@
1
- import React, { useMemo, useEffect, useLayoutEffect, useCallback, useRef, useState } from 'react';
2
- import { SelectItemMode } from '@atlaskit/editor-common/type-ahead';
3
- import { moveSelectedIndex, getPluginState } from '../utils';
4
- import { updateQuery } from '../commands/update-query';
5
- import { InputQuery } from './InputQuery';
6
- import { useLoadItems } from './hooks/use-load-items';
7
- import { useItemInsert } from './hooks/use-item-insert';
8
- import { useOnForceSelect } from './hooks/use-on-force-select';
9
- export const WrapperTypeAhead = /*#__PURE__*/React.memo(({
10
- triggerHandler,
11
- editorView,
12
- anchorElement,
13
- shouldFocusCursorInsideQuery,
14
- popupsMountPoint,
15
- popupsBoundariesElement,
16
- popupsScrollableElement,
17
- createAnalyticsEvent,
18
- inputMethod,
19
- getDecorationPosition,
20
- reopenQuery,
21
- onUndoRedo
22
- }) => {
23
- const [closed, setClosed] = useState(false);
24
- const [query, setQuery] = useState(reopenQuery || '');
25
- const queryRef = useRef(query);
26
- const editorViewRef = useRef(editorView);
27
- const items = useLoadItems(triggerHandler, editorView, query);
28
- useLayoutEffect(() => {
29
- queryRef.current = query;
30
- }, [query]);
31
- const [onItemInsert, onTextInsert] = useItemInsert(triggerHandler, editorView, items);
32
- const selectNextItem = useMemo(() => moveSelectedIndex({
33
- editorView,
34
- direction: 'next'
35
- }), [editorView]);
36
- const selectPreviousItem = useMemo(() => moveSelectedIndex({
37
- editorView,
38
- direction: 'previous'
39
- }), [editorView]);
40
- const cancel = useCallback(({
41
- setSelectionAt,
42
- addPrefixTrigger,
43
- text,
44
- forceFocusOnEditor
45
- }) => {
46
- setClosed(true);
47
- const fullquery = addPrefixTrigger ? `${triggerHandler.trigger}${text}` : text;
48
- onTextInsert({
49
- forceFocusOnEditor,
50
- setSelectionAt,
51
- text: fullquery
52
- });
53
- }, [triggerHandler, onTextInsert]);
54
- const insertSelectedItem = useCallback((mode = SelectItemMode.SELECTED) => {
55
- const {
56
- current: view
57
- } = editorViewRef;
58
- const {
59
- selectedIndex
60
- } = getPluginState(view.state);
61
- setClosed(true);
62
- queueMicrotask(() => {
63
- onItemInsert({
64
- mode,
65
- index: selectedIndex,
66
- query: queryRef.current
67
- });
68
- });
69
- }, [onItemInsert]);
70
- const showTypeAheadPopupList = useCallback(() => {}, []);
71
- const closePopup = useCallback(() => {
72
- setClosed(true);
73
- }, []);
74
- useEffect(() => {
75
- const {
76
- current: view
77
- } = editorViewRef;
78
- const pluginState = getPluginState(view.state);
79
- if (query.length === 0 || query === (pluginState === null || pluginState === void 0 ? void 0 : pluginState.query) || !(pluginState !== null && pluginState !== void 0 && pluginState.triggerHandler)) {
80
- return;
81
- }
82
- updateQuery(query)(view.state, view.dispatch);
83
- }, [query, reopenQuery]);
84
- useOnForceSelect({
85
- triggerHandler,
86
- items,
87
- query,
88
- editorView,
89
- closePopup
90
- });
91
- if (closed) {
92
- return null;
93
- }
94
- return /*#__PURE__*/React.createElement(InputQuery, {
95
- triggerQueryPrefix: triggerHandler.trigger,
96
- onQueryChange: setQuery,
97
- onItemSelect: insertSelectedItem,
98
- selectNextItem: selectNextItem,
99
- selectPreviousItem: selectPreviousItem,
100
- onQueryFocus: showTypeAheadPopupList,
101
- cancel: cancel,
102
- forceFocus: shouldFocusCursorInsideQuery,
103
- onUndoRedo: onUndoRedo,
104
- reopenQuery: reopenQuery,
105
- editorView: editorView,
106
- items: items
107
- });
108
- });
109
- WrapperTypeAhead.displayName = 'WrapperTypeAhead';
@@ -1,112 +0,0 @@
1
- import { useLayoutEffect, useCallback, useRef } from 'react';
2
- import { SelectItemMode } from '@atlaskit/editor-common/type-ahead';
3
- import { closeTypeAhead } from '../../transforms/close-type-ahead';
4
- import { setSelectionBeforeQuery } from '../../transforms/set-selection-before-query';
5
- import { insertTypeAheadItem } from '../../commands/insert-type-ahead-item';
6
- import { CloseSelectionOptions } from '../../constants';
7
- const insertRawQuery = ({
8
- view,
9
- setSelectionAt,
10
- text,
11
- forceFocusOnEditor
12
- }) => {
13
- const {
14
- tr,
15
- schema
16
- } = view.state;
17
- closeTypeAhead(tr);
18
- if (text.length > 0) {
19
- tr.replaceSelectionWith(schema.text(text));
20
- if (setSelectionAt === CloseSelectionOptions.BEFORE_TEXT_INSERTED) {
21
- setSelectionBeforeQuery(text)(tr);
22
- }
23
- }
24
- view.dispatch(tr);
25
- if (forceFocusOnEditor) {
26
- view.focus();
27
- }
28
- };
29
- export const useItemInsert = (triggerHandler, editorView, items) => {
30
- const editorViewRef = useRef(editorView);
31
- const itemsRef = useRef(items);
32
- const onTextInsert = useCallback(({
33
- setSelectionAt,
34
- text,
35
- forceFocusOnEditor
36
- }) => {
37
- if (!triggerHandler) {
38
- return;
39
- }
40
- const {
41
- current: view
42
- } = editorViewRef;
43
- insertRawQuery({
44
- view,
45
- setSelectionAt,
46
- text,
47
- forceFocusOnEditor
48
- });
49
- }, [triggerHandler]);
50
- const onItemInsert = useCallback(({
51
- mode,
52
- index,
53
- query
54
- }) => {
55
- const sourceListItem = itemsRef.current;
56
- if (sourceListItem.length === 0 || !triggerHandler) {
57
- const text = `${triggerHandler.trigger}${query}`;
58
- onTextInsert({
59
- forceFocusOnEditor: true,
60
- setSelectionAt: CloseSelectionOptions.AFTER_TEXT_INSERTED,
61
- text
62
- });
63
- return;
64
- }
65
- const itemToInsert = sourceListItem[index];
66
- if (!itemToInsert) {
67
- return;
68
- }
69
- const {
70
- current: view
71
- } = editorViewRef;
72
- insertTypeAheadItem(view)({
73
- item: itemToInsert,
74
- handler: triggerHandler,
75
- mode,
76
- query,
77
- sourceListItem
78
- });
79
- }, [triggerHandler, onTextInsert]);
80
- const onItemMatch = useCallback(({
81
- mode,
82
- query
83
- }) => {
84
- const _items = itemsRef.current;
85
- if (_items && _items.length > 1) {
86
- return false;
87
- }
88
- if (_items.length === 1) {
89
- queueMicrotask(() => {
90
- onItemInsert({
91
- mode,
92
- query,
93
- index: 0
94
- });
95
- });
96
- } else {
97
- const text = `${triggerHandler.trigger}${query}`;
98
- queueMicrotask(() => {
99
- onTextInsert({
100
- forceFocusOnEditor: true,
101
- setSelectionAt: CloseSelectionOptions.AFTER_TEXT_INSERTED,
102
- text: mode === SelectItemMode.SPACE ? text.concat(' ') : text
103
- });
104
- });
105
- }
106
- return true;
107
- }, [onItemInsert, triggerHandler, onTextInsert]);
108
- useLayoutEffect(() => {
109
- itemsRef.current = items;
110
- }, [items]);
111
- return [onItemInsert, onTextInsert, onItemMatch];
112
- };
@@ -1,41 +0,0 @@
1
- import { useRef, useState, useEffect } from 'react';
2
- import { updateListItem } from '../../commands/update-list-items';
3
- const EMPTY_LIST_ITEM = [];
4
- export const useLoadItems = (triggerHandler, editorView, query) => {
5
- const [items, setItems] = useState(EMPTY_LIST_ITEM);
6
- const componentIsMounted = useRef(true);
7
- const editorViewRef = useRef(editorView);
8
- useEffect(() => {
9
- const getItems = triggerHandler === null || triggerHandler === void 0 ? void 0 : triggerHandler.getItems;
10
- if (!getItems) {
11
- setItems(EMPTY_LIST_ITEM);
12
- return;
13
- }
14
- const options = {
15
- query: query || '',
16
- editorState: editorView.state
17
- };
18
- const {
19
- current: view
20
- } = editorViewRef;
21
- getItems(options).then(result => {
22
- const list = result.length > 0 ? result : EMPTY_LIST_ITEM;
23
- if (componentIsMounted.current) {
24
- setItems(list);
25
- }
26
- queueMicrotask(() => {
27
- updateListItem(list)(view.state, view.dispatch);
28
- });
29
- });
30
-
31
- // ignore because EditorView is mutable but we don't want to
32
- // call loadItems when it changes, only when the query changes
33
- // eslint-disable-next-line react-hooks/exhaustive-deps
34
- }, [triggerHandler, query]);
35
- useEffect(() => {
36
- return () => {
37
- componentIsMounted.current = false;
38
- };
39
- }, []);
40
- return items;
41
- };
@@ -1,38 +0,0 @@
1
- import { useLayoutEffect, useRef } from 'react';
2
- import { SelectItemMode } from '@atlaskit/editor-common/type-ahead';
3
- import { insertTypeAheadItem } from '../../commands/insert-type-ahead-item';
4
- export const useOnForceSelect = ({
5
- triggerHandler,
6
- items,
7
- query,
8
- editorView,
9
- closePopup
10
- }) => {
11
- const editorViewRef = useRef(editorView);
12
- useLayoutEffect(() => {
13
- if (!query || typeof triggerHandler.forceSelect !== 'function') {
14
- return;
15
- }
16
- const item = triggerHandler.forceSelect({
17
- items,
18
- query,
19
- editorState: editorViewRef.current.state
20
- });
21
- if (!item) {
22
- return;
23
- }
24
- const {
25
- current: view
26
- } = editorViewRef;
27
- closePopup();
28
- queueMicrotask(() => {
29
- insertTypeAheadItem(view)({
30
- item,
31
- mode: SelectItemMode.SPACE,
32
- query,
33
- handler: triggerHandler,
34
- sourceListItem: items
35
- });
36
- });
37
- }, [triggerHandler, closePopup, query, items]);
38
- };
@@ -1,126 +0,0 @@
1
- import { TypeAheadAvailableNodes } from '@atlaskit/editor-common/type-ahead';
2
- import { pluginKey as typeAheadPluginKey } from './pm-plugins/key';
3
- import { updateSelectedIndex } from './commands/update-selected-index';
4
- import { StatsModifier } from './stats-modifier';
5
- import { typeAheadListMessages } from './messages';
6
- export const isTypeAheadHandler = handler => {
7
- return handler && Object.values(TypeAheadAvailableNodes).includes(handler.id) && typeof handler.trigger === 'string' && typeof handler.selectItem === 'function' && typeof handler.getItems === 'function';
8
- };
9
-
10
- /** Is a typeahead plugin open? */
11
- export const isTypeAheadOpen = editorState => {
12
- var _typeAheadPluginKey$g, _typeAheadPluginKey$g2;
13
- return !!(typeAheadPluginKey !== null && typeAheadPluginKey !== void 0 && (_typeAheadPluginKey$g = typeAheadPluginKey.getState(editorState)) !== null && _typeAheadPluginKey$g !== void 0 && (_typeAheadPluginKey$g2 = _typeAheadPluginKey$g.decorationSet) !== null && _typeAheadPluginKey$g2 !== void 0 && _typeAheadPluginKey$g2.find().length);
14
- };
15
- export const getPluginState = editorState => {
16
- return typeAheadPluginKey.getState(editorState);
17
- };
18
- export const getTypeAheadHandler = editorState => {
19
- var _typeAheadPluginKey$g3;
20
- return (_typeAheadPluginKey$g3 = typeAheadPluginKey.getState(editorState)) === null || _typeAheadPluginKey$g3 === void 0 ? void 0 : _typeAheadPluginKey$g3.triggerHandler;
21
- };
22
- export const getTypeAheadQuery = editorState => {
23
- var _typeAheadPluginKey$g4;
24
- return (_typeAheadPluginKey$g4 = typeAheadPluginKey.getState(editorState)) === null || _typeAheadPluginKey$g4 === void 0 ? void 0 : _typeAheadPluginKey$g4.query;
25
- };
26
- export const isTypeAheadAllowed = state => {
27
- const isOpen = isTypeAheadOpen(state);
28
- // if the TypeAhead is open
29
- // we should not allow it
30
- return !isOpen;
31
- };
32
- export const findHandler = (id, state) => {
33
- const pluginState = typeAheadPluginKey.getState(state);
34
- if (!pluginState || !pluginState.typeAheadHandlers || pluginState.typeAheadHandlers.length === 0) {
35
- return null;
36
- }
37
- const {
38
- typeAheadHandlers
39
- } = pluginState;
40
- return typeAheadHandlers.find(h => h.id === id) || null;
41
- };
42
- export const findHandlerByTrigger = ({
43
- trigger,
44
- editorState
45
- }) => {
46
- const pluginState = typeAheadPluginKey.getState(editorState);
47
- if (!pluginState || !pluginState.typeAheadHandlers || pluginState.typeAheadHandlers.length === 0) {
48
- return null;
49
- }
50
- const {
51
- typeAheadHandlers
52
- } = pluginState;
53
- return typeAheadHandlers.find(h => h.trigger === trigger) || null;
54
- };
55
- export const moveSelectedIndex = ({
56
- editorView,
57
- direction
58
- }) => () => {
59
- const typeAheadState = getPluginState(editorView.state);
60
- if (!typeAheadState) {
61
- return;
62
- }
63
- const {
64
- selectedIndex,
65
- items
66
- } = typeAheadState;
67
- const stats = typeAheadState.stats instanceof StatsModifier ? typeAheadState.stats : new StatsModifier();
68
- let nextIndex;
69
- if (direction === 'next') {
70
- stats.increaseArrowDown();
71
-
72
- /**
73
- * See: https://product-fabric.atlassian.net/browse/ED-17200
74
- * `selectedIndex` is forced to -1 now to not immediately focus the typeahead
75
- * and only do so when there is explicit logic to focus into the typeahead
76
- * options.
77
- *
78
- * This check for "set index to 1 when -1"
79
- * - is a temporary workaround to get back the previous behaviour without
80
- * entirely reverting the a11y improvements
81
- *
82
- */
83
- if (selectedIndex === -1 && items.length > 1) {
84
- nextIndex = 1;
85
- } else {
86
- nextIndex = selectedIndex >= items.length - 1 ? 0 : selectedIndex + 1;
87
- }
88
- } else {
89
- stats.increaseArrowUp();
90
- nextIndex = selectedIndex <= 0 ? items.length - 1 : selectedIndex - 1;
91
- }
92
- updateSelectedIndex(nextIndex)(editorView.state, editorView.dispatch);
93
- };
94
- export const getTypeAheadListAriaLabels = (trigger, intl, item) => {
95
- var _item$mention, _item$mention2, _item$emoji, _item$emoji2, _item$emoji3;
96
- switch (trigger) {
97
- case '@':
98
- return {
99
- popupAriaLabel: intl.formatMessage(typeAheadListMessages.mentionPopupLabel),
100
- listItemAriaLabel: intl.formatMessage(typeAheadListMessages.metionListItemLabel, {
101
- name: (item === null || item === void 0 ? void 0 : (_item$mention = item.mention) === null || _item$mention === void 0 ? void 0 : _item$mention.name) || '',
102
- shortName: (item === null || item === void 0 ? void 0 : (_item$mention2 = item.mention) === null || _item$mention2 === void 0 ? void 0 : _item$mention2.mentionName) || ''
103
- })
104
- };
105
- case '/':
106
- return {
107
- popupAriaLabel: intl.formatMessage(typeAheadListMessages.quickInsertPopupLabel),
108
- listItemAriaLabel: intl.formatMessage(typeAheadListMessages.emojiListItemLabel, {
109
- name: (item === null || item === void 0 ? void 0 : item.title) || '',
110
- shortcut: (item === null || item === void 0 ? void 0 : (_item$emoji = item.emoji) === null || _item$emoji === void 0 ? void 0 : _item$emoji.shortName) || ''
111
- })
112
- };
113
- case ':':
114
- return {
115
- popupAriaLabel: intl.formatMessage(typeAheadListMessages.emojiPopupLabel),
116
- listItemAriaLabel: intl.formatMessage(typeAheadListMessages.emojiListItemLabel, {
117
- name: (item === null || item === void 0 ? void 0 : (_item$emoji2 = item.emoji) === null || _item$emoji2 === void 0 ? void 0 : _item$emoji2.name) || '',
118
- shortcut: (item === null || item === void 0 ? void 0 : (_item$emoji3 = item.emoji) === null || _item$emoji3 === void 0 ? void 0 : _item$emoji3.shortName) || ''
119
- })
120
- };
121
- default:
122
- return {
123
- popupAriaLabel: intl.formatMessage(typeAheadListMessages.typeAheadPopupLabel)
124
- };
125
- }
126
- };