@atlaskit/editor-core 188.9.0 → 188.9.2
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.
- package/CHANGELOG.md +7 -0
- package/dist/cjs/labs/next/presets/default.js +2 -2
- package/dist/cjs/plugins/index.js +0 -7
- package/dist/cjs/plugins/insert-block/index.js +4 -6
- package/dist/cjs/plugins/tasks-and-decisions/index.js +4 -3
- package/dist/cjs/plugins/tasks-and-decisions/nodeviews/decisionItem.js +26 -6
- package/dist/cjs/plugins/tasks-and-decisions/nodeviews/taskItem.js +45 -13
- package/dist/cjs/plugins/tasks-and-decisions/pm-plugins/main.js +15 -7
- package/dist/cjs/version-wrapper.js +1 -1
- package/dist/es2019/labs/next/presets/default.js +1 -1
- package/dist/es2019/plugins/index.js +0 -1
- package/dist/es2019/plugins/insert-block/index.js +4 -6
- package/dist/es2019/plugins/tasks-and-decisions/index.js +4 -3
- package/dist/es2019/plugins/tasks-and-decisions/nodeviews/decisionItem.js +26 -6
- package/dist/es2019/plugins/tasks-and-decisions/nodeviews/taskItem.js +43 -10
- package/dist/es2019/plugins/tasks-and-decisions/pm-plugins/main.js +13 -6
- package/dist/es2019/version-wrapper.js +1 -1
- package/dist/esm/labs/next/presets/default.js +1 -1
- package/dist/esm/plugins/index.js +0 -1
- package/dist/esm/plugins/insert-block/index.js +4 -6
- package/dist/esm/plugins/tasks-and-decisions/index.js +4 -3
- package/dist/esm/plugins/tasks-and-decisions/nodeviews/decisionItem.js +26 -6
- package/dist/esm/plugins/tasks-and-decisions/nodeviews/taskItem.js +45 -12
- package/dist/esm/plugins/tasks-and-decisions/pm-plugins/main.js +14 -7
- package/dist/esm/version-wrapper.js +1 -1
- package/dist/types/labs/next/presets/default.d.ts +43 -43
- package/dist/types/plugins/index.d.ts +0 -1
- package/dist/types/plugins/insert-block/types.d.ts +2 -0
- package/dist/types/plugins/tasks-and-decisions/index.d.ts +2 -5
- package/dist/types/plugins/tasks-and-decisions/nodeviews/decisionItem.d.ts +9 -4
- package/dist/types/plugins/tasks-and-decisions/nodeviews/taskItem.d.ts +9 -4
- package/dist/types/plugins/tasks-and-decisions/pm-plugins/main.d.ts +4 -2
- package/dist/types/plugins/tasks-and-decisions/types.d.ts +6 -1
- package/dist/types-ts4.5/labs/next/presets/default.d.ts +43 -43
- package/dist/types-ts4.5/plugins/index.d.ts +0 -1
- package/dist/types-ts4.5/plugins/insert-block/types.d.ts +2 -0
- package/dist/types-ts4.5/plugins/tasks-and-decisions/index.d.ts +2 -5
- package/dist/types-ts4.5/plugins/tasks-and-decisions/nodeviews/decisionItem.d.ts +9 -4
- package/dist/types-ts4.5/plugins/tasks-and-decisions/nodeviews/taskItem.d.ts +9 -4
- package/dist/types-ts4.5/plugins/tasks-and-decisions/pm-plugins/main.d.ts +4 -2
- package/dist/types-ts4.5/plugins/tasks-and-decisions/types.d.ts +8 -1
- package/package.json +3 -5
- package/dist/cjs/plugins/type-ahead/api.js +0 -215
- package/dist/cjs/plugins/type-ahead/commands/insert-type-ahead-item.js +0 -205
- package/dist/cjs/plugins/type-ahead/commands/update-list-items.js +0 -23
- package/dist/cjs/plugins/type-ahead/commands/update-query.js +0 -27
- package/dist/cjs/plugins/type-ahead/commands/update-selected-index.js +0 -27
- package/dist/cjs/plugins/type-ahead/constants.js +0 -15
- package/dist/cjs/plugins/type-ahead/index.js +0 -14
- package/dist/cjs/plugins/type-ahead/insert-utils.js +0 -107
- package/dist/cjs/plugins/type-ahead/messages.js +0 -79
- package/dist/cjs/plugins/type-ahead/plugin.js +0 -382
- package/dist/cjs/plugins/type-ahead/pm-plugins/actions.js +0 -16
- package/dist/cjs/plugins/type-ahead/pm-plugins/decorations.js +0 -148
- package/dist/cjs/plugins/type-ahead/pm-plugins/input-rules.js +0 -36
- package/dist/cjs/plugins/type-ahead/pm-plugins/insert-item-plugin.js +0 -22
- package/dist/cjs/plugins/type-ahead/pm-plugins/key.js +0 -8
- package/dist/cjs/plugins/type-ahead/pm-plugins/main.js +0 -110
- package/dist/cjs/plugins/type-ahead/pm-plugins/reducer.js +0 -158
- package/dist/cjs/plugins/type-ahead/pm-plugins/utils.js +0 -18
- package/dist/cjs/plugins/type-ahead/stats-modifier.js +0 -42
- package/dist/cjs/plugins/type-ahead/transforms/close-type-ahead.js +0 -13
- package/dist/cjs/plugins/type-ahead/transforms/open-typeahead-at-cursor.js +0 -75
- package/dist/cjs/plugins/type-ahead/transforms/set-selection-before-query.js +0 -18
- package/dist/cjs/plugins/type-ahead/types.js +0 -5
- package/dist/cjs/plugins/type-ahead/ui/AssistiveText.js +0 -120
- package/dist/cjs/plugins/type-ahead/ui/InputQuery.js +0 -400
- package/dist/cjs/plugins/type-ahead/ui/TypeAheadList.js +0 -285
- package/dist/cjs/plugins/type-ahead/ui/TypeAheadListItem.js +0 -179
- package/dist/cjs/plugins/type-ahead/ui/TypeAheadPopup.js +0 -230
- package/dist/cjs/plugins/type-ahead/ui/WrapperTypeAhead.js +0 -127
- package/dist/cjs/plugins/type-ahead/ui/hooks/use-item-insert.js +0 -109
- package/dist/cjs/plugins/type-ahead/ui/hooks/use-load-items.js +0 -50
- package/dist/cjs/plugins/type-ahead/ui/hooks/use-on-force-select.js +0 -41
- package/dist/cjs/plugins/type-ahead/utils.js +0 -130
- package/dist/es2019/plugins/type-ahead/api.js +0 -205
- package/dist/es2019/plugins/type-ahead/commands/insert-type-ahead-item.js +0 -204
- package/dist/es2019/plugins/type-ahead/commands/update-list-items.js +0 -17
- package/dist/es2019/plugins/type-ahead/commands/update-query.js +0 -21
- package/dist/es2019/plugins/type-ahead/commands/update-selected-index.js +0 -21
- package/dist/es2019/plugins/type-ahead/constants.js +0 -9
- package/dist/es2019/plugins/type-ahead/index.js +0 -3
- package/dist/es2019/plugins/type-ahead/insert-utils.js +0 -106
- package/dist/es2019/plugins/type-ahead/messages.js +0 -73
- package/dist/es2019/plugins/type-ahead/plugin.js +0 -381
- package/dist/es2019/plugins/type-ahead/pm-plugins/actions.js +0 -10
- package/dist/es2019/plugins/type-ahead/pm-plugins/decorations.js +0 -148
- package/dist/es2019/plugins/type-ahead/pm-plugins/input-rules.js +0 -29
- package/dist/es2019/plugins/type-ahead/pm-plugins/insert-item-plugin.js +0 -16
- package/dist/es2019/plugins/type-ahead/pm-plugins/key.js +0 -2
- package/dist/es2019/plugins/type-ahead/pm-plugins/main.js +0 -106
- package/dist/es2019/plugins/type-ahead/pm-plugins/reducer.js +0 -160
- package/dist/es2019/plugins/type-ahead/pm-plugins/utils.js +0 -12
- package/dist/es2019/plugins/type-ahead/stats-modifier.js +0 -33
- package/dist/es2019/plugins/type-ahead/transforms/close-type-ahead.js +0 -7
- package/dist/es2019/plugins/type-ahead/transforms/open-typeahead-at-cursor.js +0 -71
- package/dist/es2019/plugins/type-ahead/transforms/set-selection-before-query.js +0 -10
- package/dist/es2019/plugins/type-ahead/types.js +0 -1
- package/dist/es2019/plugins/type-ahead/ui/AssistiveText.js +0 -88
- package/dist/es2019/plugins/type-ahead/ui/InputQuery.js +0 -393
- package/dist/es2019/plugins/type-ahead/ui/TypeAheadList.js +0 -273
- package/dist/es2019/plugins/type-ahead/ui/TypeAheadListItem.js +0 -214
- package/dist/es2019/plugins/type-ahead/ui/TypeAheadPopup.js +0 -233
- package/dist/es2019/plugins/type-ahead/ui/WrapperTypeAhead.js +0 -109
- package/dist/es2019/plugins/type-ahead/ui/hooks/use-item-insert.js +0 -112
- package/dist/es2019/plugins/type-ahead/ui/hooks/use-load-items.js +0 -41
- package/dist/es2019/plugins/type-ahead/ui/hooks/use-on-force-select.js +0 -38
- package/dist/es2019/plugins/type-ahead/utils.js +0 -126
- package/dist/esm/plugins/type-ahead/api.js +0 -209
- package/dist/esm/plugins/type-ahead/commands/insert-type-ahead-item.js +0 -198
- package/dist/esm/plugins/type-ahead/commands/update-list-items.js +0 -17
- package/dist/esm/plugins/type-ahead/commands/update-query.js +0 -21
- package/dist/esm/plugins/type-ahead/commands/update-selected-index.js +0 -21
- package/dist/esm/plugins/type-ahead/constants.js +0 -9
- package/dist/esm/plugins/type-ahead/index.js +0 -3
- package/dist/esm/plugins/type-ahead/insert-utils.js +0 -101
- package/dist/esm/plugins/type-ahead/messages.js +0 -73
- package/dist/esm/plugins/type-ahead/plugin.js +0 -374
- package/dist/esm/plugins/type-ahead/pm-plugins/actions.js +0 -10
- package/dist/esm/plugins/type-ahead/pm-plugins/decorations.js +0 -141
- package/dist/esm/plugins/type-ahead/pm-plugins/input-rules.js +0 -29
- package/dist/esm/plugins/type-ahead/pm-plugins/insert-item-plugin.js +0 -16
- package/dist/esm/plugins/type-ahead/pm-plugins/key.js +0 -2
- package/dist/esm/plugins/type-ahead/pm-plugins/main.js +0 -104
- package/dist/esm/plugins/type-ahead/pm-plugins/reducer.js +0 -151
- package/dist/esm/plugins/type-ahead/pm-plugins/utils.js +0 -12
- package/dist/esm/plugins/type-ahead/stats-modifier.js +0 -35
- package/dist/esm/plugins/type-ahead/transforms/close-type-ahead.js +0 -7
- package/dist/esm/plugins/type-ahead/transforms/open-typeahead-at-cursor.js +0 -69
- package/dist/esm/plugins/type-ahead/transforms/set-selection-before-query.js +0 -12
- package/dist/esm/plugins/type-ahead/types.js +0 -1
- package/dist/esm/plugins/type-ahead/ui/AssistiveText.js +0 -115
- package/dist/esm/plugins/type-ahead/ui/InputQuery.js +0 -390
- package/dist/esm/plugins/type-ahead/ui/TypeAheadList.js +0 -276
- package/dist/esm/plugins/type-ahead/ui/TypeAheadListItem.js +0 -169
- package/dist/esm/plugins/type-ahead/ui/TypeAheadPopup.js +0 -220
- package/dist/esm/plugins/type-ahead/ui/WrapperTypeAhead.js +0 -117
- package/dist/esm/plugins/type-ahead/ui/hooks/use-item-insert.js +0 -103
- package/dist/esm/plugins/type-ahead/ui/hooks/use-load-items.js +0 -43
- package/dist/esm/plugins/type-ahead/ui/hooks/use-on-force-select.js +0 -35
- package/dist/esm/plugins/type-ahead/utils.js +0 -124
- package/dist/types/plugins/type-ahead/api.d.ts +0 -61
- package/dist/types/plugins/type-ahead/commands/insert-type-ahead-item.d.ts +0 -12
- package/dist/types/plugins/type-ahead/commands/update-list-items.d.ts +0 -3
- package/dist/types/plugins/type-ahead/commands/update-query.d.ts +0 -2
- package/dist/types/plugins/type-ahead/commands/update-selected-index.d.ts +0 -2
- package/dist/types/plugins/type-ahead/constants.d.ts +0 -8
- package/dist/types/plugins/type-ahead/index.d.ts +0 -4
- package/dist/types/plugins/type-ahead/insert-utils.d.ts +0 -18
- package/dist/types/plugins/type-ahead/messages.d.ts +0 -72
- package/dist/types/plugins/type-ahead/plugin.d.ts +0 -10
- package/dist/types/plugins/type-ahead/pm-plugins/actions.d.ts +0 -9
- package/dist/types/plugins/type-ahead/pm-plugins/decorations.d.ts +0 -14
- package/dist/types/plugins/type-ahead/pm-plugins/input-rules.d.ts +0 -6
- package/dist/types/plugins/type-ahead/pm-plugins/insert-item-plugin.d.ts +0 -2
- package/dist/types/plugins/type-ahead/pm-plugins/key.d.ts +0 -3
- package/dist/types/plugins/type-ahead/pm-plugins/main.d.ts +0 -14
- package/dist/types/plugins/type-ahead/pm-plugins/reducer.d.ts +0 -10
- package/dist/types/plugins/type-ahead/pm-plugins/utils.d.ts +0 -4
- package/dist/types/plugins/type-ahead/stats-modifier.d.ts +0 -20
- package/dist/types/plugins/type-ahead/transforms/close-type-ahead.d.ts +0 -2
- package/dist/types/plugins/type-ahead/transforms/open-typeahead-at-cursor.d.ts +0 -11
- package/dist/types/plugins/type-ahead/transforms/set-selection-before-query.d.ts +0 -2
- package/dist/types/plugins/type-ahead/types.d.ts +0 -109
- package/dist/types/plugins/type-ahead/ui/AssistiveText.d.ts +0 -33
- package/dist/types/plugins/type-ahead/ui/InputQuery.d.ts +0 -26
- package/dist/types/plugins/type-ahead/ui/TypeAheadList.d.ts +0 -25
- package/dist/types/plugins/type-ahead/ui/TypeAheadListItem.d.ts +0 -18
- package/dist/types/plugins/type-ahead/ui/TypeAheadPopup.d.ts +0 -29
- package/dist/types/plugins/type-ahead/ui/WrapperTypeAhead.d.ts +0 -20
- package/dist/types/plugins/type-ahead/ui/hooks/use-item-insert.d.ts +0 -3
- package/dist/types/plugins/type-ahead/ui/hooks/use-load-items.d.ts +0 -3
- package/dist/types/plugins/type-ahead/ui/hooks/use-on-force-select.d.ts +0 -11
- package/dist/types/plugins/type-ahead/utils.d.ts +0 -27
- package/dist/types-ts4.5/plugins/type-ahead/api.d.ts +0 -61
- package/dist/types-ts4.5/plugins/type-ahead/commands/insert-type-ahead-item.d.ts +0 -12
- package/dist/types-ts4.5/plugins/type-ahead/commands/update-list-items.d.ts +0 -3
- package/dist/types-ts4.5/plugins/type-ahead/commands/update-query.d.ts +0 -2
- package/dist/types-ts4.5/plugins/type-ahead/commands/update-selected-index.d.ts +0 -2
- package/dist/types-ts4.5/plugins/type-ahead/constants.d.ts +0 -8
- package/dist/types-ts4.5/plugins/type-ahead/index.d.ts +0 -4
- package/dist/types-ts4.5/plugins/type-ahead/insert-utils.d.ts +0 -18
- package/dist/types-ts4.5/plugins/type-ahead/messages.d.ts +0 -72
- package/dist/types-ts4.5/plugins/type-ahead/plugin.d.ts +0 -10
- package/dist/types-ts4.5/plugins/type-ahead/pm-plugins/actions.d.ts +0 -9
- package/dist/types-ts4.5/plugins/type-ahead/pm-plugins/decorations.d.ts +0 -14
- package/dist/types-ts4.5/plugins/type-ahead/pm-plugins/input-rules.d.ts +0 -6
- package/dist/types-ts4.5/plugins/type-ahead/pm-plugins/insert-item-plugin.d.ts +0 -2
- package/dist/types-ts4.5/plugins/type-ahead/pm-plugins/key.d.ts +0 -3
- package/dist/types-ts4.5/plugins/type-ahead/pm-plugins/main.d.ts +0 -14
- package/dist/types-ts4.5/plugins/type-ahead/pm-plugins/reducer.d.ts +0 -10
- package/dist/types-ts4.5/plugins/type-ahead/pm-plugins/utils.d.ts +0 -4
- package/dist/types-ts4.5/plugins/type-ahead/stats-modifier.d.ts +0 -20
- package/dist/types-ts4.5/plugins/type-ahead/transforms/close-type-ahead.d.ts +0 -2
- package/dist/types-ts4.5/plugins/type-ahead/transforms/open-typeahead-at-cursor.d.ts +0 -11
- package/dist/types-ts4.5/plugins/type-ahead/transforms/set-selection-before-query.d.ts +0 -2
- package/dist/types-ts4.5/plugins/type-ahead/types.d.ts +0 -111
- package/dist/types-ts4.5/plugins/type-ahead/ui/AssistiveText.d.ts +0 -33
- package/dist/types-ts4.5/plugins/type-ahead/ui/InputQuery.d.ts +0 -26
- package/dist/types-ts4.5/plugins/type-ahead/ui/TypeAheadList.d.ts +0 -25
- package/dist/types-ts4.5/plugins/type-ahead/ui/TypeAheadListItem.d.ts +0 -18
- package/dist/types-ts4.5/plugins/type-ahead/ui/TypeAheadPopup.d.ts +0 -29
- package/dist/types-ts4.5/plugins/type-ahead/ui/WrapperTypeAhead.d.ts +0 -20
- package/dist/types-ts4.5/plugins/type-ahead/ui/hooks/use-item-insert.d.ts +0 -7
- package/dist/types-ts4.5/plugins/type-ahead/ui/hooks/use-load-items.d.ts +0 -3
- package/dist/types-ts4.5/plugins/type-ahead/ui/hooks/use-on-force-select.d.ts +0 -11
- package/dist/types-ts4.5/plugins/type-ahead/utils.d.ts +0 -27
|
@@ -1,273 +0,0 @@
|
|
|
1
|
-
/** @jsx jsx */
|
|
2
|
-
|
|
3
|
-
import React, { useMemo, useRef, useCallback, useLayoutEffect, useState } from 'react';
|
|
4
|
-
import { jsx, css } from '@emotion/react';
|
|
5
|
-
import { MenuGroup } from '@atlaskit/menu';
|
|
6
|
-
import { SelectItemMode } from '@atlaskit/editor-common/type-ahead';
|
|
7
|
-
import { CellMeasurer, CellMeasurerCache } from 'react-virtualized/dist/commonjs/CellMeasurer';
|
|
8
|
-
import { List } from 'react-virtualized/dist/commonjs/List';
|
|
9
|
-
import { ICON_HEIGHT, ITEM_PADDING, TypeAheadListItem } from './TypeAheadListItem';
|
|
10
|
-
import { injectIntl, useIntl } from 'react-intl-next';
|
|
11
|
-
import { typeAheadListMessages } from '../messages';
|
|
12
|
-
import { getTypeAheadListAriaLabels, moveSelectedIndex } from '../utils';
|
|
13
|
-
import { updateSelectedIndex } from '../commands/update-selected-index';
|
|
14
|
-
import { AssistiveText } from './AssistiveText';
|
|
15
|
-
import { TYPE_AHEAD_DECORATION_ELEMENT_ID } from '../constants';
|
|
16
|
-
const LIST_ITEM_ESTIMATED_HEIGHT = ICON_HEIGHT + ITEM_PADDING * 2;
|
|
17
|
-
const LIST_WIDTH = 320;
|
|
18
|
-
const TypeaheadAssistiveTextPureComponent = /*#__PURE__*/React.memo(({
|
|
19
|
-
numberOfResults
|
|
20
|
-
}) => {
|
|
21
|
-
const intl = useIntl();
|
|
22
|
-
return jsx(AssistiveText, {
|
|
23
|
-
assistiveText: intl.formatMessage(typeAheadListMessages.searchResultsLabel, {
|
|
24
|
-
itemsLength: numberOfResults
|
|
25
|
-
})
|
|
26
|
-
// when the popup is open its always in focus
|
|
27
|
-
,
|
|
28
|
-
isInFocus: true,
|
|
29
|
-
id: TYPE_AHEAD_DECORATION_ELEMENT_ID + '__popup'
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
const TypeAheadListComponent = /*#__PURE__*/React.memo(({
|
|
33
|
-
items,
|
|
34
|
-
selectedIndex,
|
|
35
|
-
editorView,
|
|
36
|
-
onItemClick,
|
|
37
|
-
intl,
|
|
38
|
-
fitHeight,
|
|
39
|
-
decorationElement,
|
|
40
|
-
triggerHandler
|
|
41
|
-
}) => {
|
|
42
|
-
var _decorationElement$qu2;
|
|
43
|
-
const listRef = useRef();
|
|
44
|
-
const listContainerRef = useRef(null);
|
|
45
|
-
const lastVisibleIndexes = useRef({
|
|
46
|
-
overscanStartIndex: 0,
|
|
47
|
-
overscanStopIndex: 0,
|
|
48
|
-
startIndex: 0,
|
|
49
|
-
stopIndex: 0
|
|
50
|
-
});
|
|
51
|
-
const estimatedHeight = items.length * LIST_ITEM_ESTIMATED_HEIGHT;
|
|
52
|
-
const [height, setHeight] = useState(Math.min(estimatedHeight, fitHeight));
|
|
53
|
-
const [cache, setCache] = useState(new CellMeasurerCache({
|
|
54
|
-
fixedWidth: true,
|
|
55
|
-
defaultHeight: LIST_ITEM_ESTIMATED_HEIGHT
|
|
56
|
-
}));
|
|
57
|
-
const onItemsRendered = useCallback(props => {
|
|
58
|
-
lastVisibleIndexes.current = props;
|
|
59
|
-
}, []);
|
|
60
|
-
const actions = useMemo(() => ({
|
|
61
|
-
onItemClick
|
|
62
|
-
}), [onItemClick]);
|
|
63
|
-
const isNavigationKey = event => {
|
|
64
|
-
return ['ArrowDown', 'ArrowUp', 'Tab', 'Enter'].includes(event.key);
|
|
65
|
-
};
|
|
66
|
-
const focusTargetElement = useCallback(() => {
|
|
67
|
-
var _decorationElement$qu;
|
|
68
|
-
//To reset the selected index
|
|
69
|
-
updateSelectedIndex(-1)(editorView.state, editorView.dispatch);
|
|
70
|
-
listRef.current.scrollToRow(0);
|
|
71
|
-
decorationElement === null || decorationElement === void 0 ? void 0 : (_decorationElement$qu = decorationElement.querySelector(`[role='combobox']`)) === null || _decorationElement$qu === void 0 ? void 0 : _decorationElement$qu.focus();
|
|
72
|
-
}, [editorView, listRef, decorationElement]);
|
|
73
|
-
const selectNextItem = useMemo(() => moveSelectedIndex({
|
|
74
|
-
editorView,
|
|
75
|
-
direction: 'next'
|
|
76
|
-
}), [editorView]);
|
|
77
|
-
const selectPreviousItem = useMemo(() => moveSelectedIndex({
|
|
78
|
-
editorView,
|
|
79
|
-
direction: 'previous'
|
|
80
|
-
}), [editorView]);
|
|
81
|
-
const lastVisibleStartIndex = lastVisibleIndexes.current.startIndex;
|
|
82
|
-
const lastVisibleStopIndex = lastVisibleIndexes.current.stopIndex;
|
|
83
|
-
const onScroll = useCallback(({
|
|
84
|
-
scrollUpdateWasRequested
|
|
85
|
-
}) => {
|
|
86
|
-
if (!scrollUpdateWasRequested) {
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// In case the user scroll to a non-visible item like press ArrowUp from the first index
|
|
91
|
-
// We will force the scroll calling the scrollToItem in the useEffect hook
|
|
92
|
-
// When the scroll happens and we render the elements,
|
|
93
|
-
// we still need calculate the items height and re-draw the List.
|
|
94
|
-
// It is possible the item selected became invisible again (because the items height changed)
|
|
95
|
-
// So, we need to wait for height to be calculated. Then we need to check
|
|
96
|
-
// if the selected item is visible or not. If it isn't visible we call the scrollToItem again.
|
|
97
|
-
//
|
|
98
|
-
// We can't do this check in the first frame because that frame is being used by the resetScreenThrottled
|
|
99
|
-
// to calculate each height. THen, we can schedule a new frame when this one finishs.
|
|
100
|
-
requestAnimationFrame(() => {
|
|
101
|
-
requestAnimationFrame(() => {
|
|
102
|
-
const isSelectedItemVisible = selectedIndex >= lastVisibleStartIndex && selectedIndex <= lastVisibleStopIndex;
|
|
103
|
-
|
|
104
|
-
//Should scroll to the list item only when the selectedIndex >= 0 and item is not visible
|
|
105
|
-
if (!isSelectedItemVisible && selectedIndex !== -1) {
|
|
106
|
-
listRef.current.scrollToRow(selectedIndex);
|
|
107
|
-
} else if (selectedIndex === -1) {
|
|
108
|
-
listRef.current.scrollToRow(0);
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
}, [selectedIndex, lastVisibleStartIndex, lastVisibleStopIndex]);
|
|
113
|
-
const onMouseMove = (event, index) => {
|
|
114
|
-
event.preventDefault();
|
|
115
|
-
event.stopPropagation();
|
|
116
|
-
if (selectedIndex === index) {
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
updateSelectedIndex(index)(editorView.state, editorView.dispatch);
|
|
120
|
-
};
|
|
121
|
-
useLayoutEffect(() => {
|
|
122
|
-
if (!listRef.current) {
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
const isSelectedItemVisible = selectedIndex >= lastVisibleStartIndex && selectedIndex <= lastVisibleStopIndex;
|
|
126
|
-
|
|
127
|
-
//Should scroll to the list item only when the selectedIndex >= 0 and item is not visible
|
|
128
|
-
if (!isSelectedItemVisible && selectedIndex !== -1) {
|
|
129
|
-
listRef.current.scrollToRow(selectedIndex);
|
|
130
|
-
} else if (selectedIndex === -1) {
|
|
131
|
-
listRef.current.scrollToRow(0);
|
|
132
|
-
}
|
|
133
|
-
}, [selectedIndex, lastVisibleStartIndex, lastVisibleStopIndex]);
|
|
134
|
-
useLayoutEffect(() => {
|
|
135
|
-
setCache(new CellMeasurerCache({
|
|
136
|
-
fixedWidth: true,
|
|
137
|
-
defaultHeight: LIST_ITEM_ESTIMATED_HEIGHT
|
|
138
|
-
}));
|
|
139
|
-
// When query is updated, sometimes the scroll position of the menu is not at the top
|
|
140
|
-
// Scrolling back to top for consistency
|
|
141
|
-
requestAnimationFrame(() => {
|
|
142
|
-
var _listContainerRef$cur;
|
|
143
|
-
if ((_listContainerRef$cur = listContainerRef.current) !== null && _listContainerRef$cur !== void 0 && _listContainerRef$cur.firstChild) {
|
|
144
|
-
listContainerRef.current.firstChild.scrollTo(0, 0);
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
}, [items]);
|
|
148
|
-
useLayoutEffect(() => {
|
|
149
|
-
const height = Math.min(items.reduce((prevValue, currentValue, index) => {
|
|
150
|
-
return prevValue + cache.rowHeight({
|
|
151
|
-
index: index
|
|
152
|
-
});
|
|
153
|
-
}, 0), fitHeight);
|
|
154
|
-
setHeight(height);
|
|
155
|
-
}, [items, cache, fitHeight]);
|
|
156
|
-
useLayoutEffect(() => {
|
|
157
|
-
if (!listContainerRef.current) {
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
const {
|
|
161
|
-
current: element
|
|
162
|
-
} = listContainerRef;
|
|
163
|
-
/**
|
|
164
|
-
* To handle the key events on the list
|
|
165
|
-
* @param event
|
|
166
|
-
*/
|
|
167
|
-
const handleKeyDown = event => {
|
|
168
|
-
if (isNavigationKey(event)) {
|
|
169
|
-
switch (event.key) {
|
|
170
|
-
case 'ArrowDown':
|
|
171
|
-
selectNextItem();
|
|
172
|
-
event.preventDefault();
|
|
173
|
-
event.stopPropagation();
|
|
174
|
-
break;
|
|
175
|
-
case 'ArrowUp':
|
|
176
|
-
selectPreviousItem();
|
|
177
|
-
event.preventDefault();
|
|
178
|
-
event.stopPropagation();
|
|
179
|
-
break;
|
|
180
|
-
|
|
181
|
-
// TODO DTR-1401: why is this calling item click when hitting tab? fix this in DTR-1401
|
|
182
|
-
case 'Tab':
|
|
183
|
-
//Tab key quick inserts the selected item.
|
|
184
|
-
onItemClick(SelectItemMode.TAB, selectedIndex);
|
|
185
|
-
event.preventDefault();
|
|
186
|
-
break;
|
|
187
|
-
case 'Enter':
|
|
188
|
-
//Enter key quick inserts the selected item.
|
|
189
|
-
if (!event.isComposing || event.which !== 229 && event.keyCode !== 229) {
|
|
190
|
-
onItemClick(event.shiftKey ? SelectItemMode.SHIFT_ENTER : SelectItemMode.ENTER, selectedIndex);
|
|
191
|
-
event.preventDefault();
|
|
192
|
-
}
|
|
193
|
-
break;
|
|
194
|
-
default:
|
|
195
|
-
event.preventDefault();
|
|
196
|
-
}
|
|
197
|
-
} else {
|
|
198
|
-
//All the remaining keys sets focus on the typeahead query(inputQuery.tsx))
|
|
199
|
-
focusTargetElement();
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
element === null || element === void 0 ? void 0 : element.addEventListener('keydown', handleKeyDown);
|
|
203
|
-
return () => {
|
|
204
|
-
element === null || element === void 0 ? void 0 : element.removeEventListener('keydown', handleKeyDown);
|
|
205
|
-
};
|
|
206
|
-
}, [editorView.state, focusTargetElement, selectNextItem, selectPreviousItem, selectedIndex, onItemClick, items.length]);
|
|
207
|
-
const renderRow = ({
|
|
208
|
-
index,
|
|
209
|
-
key,
|
|
210
|
-
style,
|
|
211
|
-
parent
|
|
212
|
-
}) => {
|
|
213
|
-
const currentItem = items[index];
|
|
214
|
-
return jsx(CellMeasurer, {
|
|
215
|
-
key: key,
|
|
216
|
-
cache: cache,
|
|
217
|
-
parent: parent,
|
|
218
|
-
columnIndex: 0,
|
|
219
|
-
rowIndex: index
|
|
220
|
-
}, jsx("div", {
|
|
221
|
-
style: style,
|
|
222
|
-
"data-index": index
|
|
223
|
-
}, jsx("div", {
|
|
224
|
-
"data-testid": `list-item-height-observed-${index}`,
|
|
225
|
-
onMouseMove: e => onMouseMove(e, index)
|
|
226
|
-
}, jsx(TypeAheadListItem, {
|
|
227
|
-
key: items[index].title,
|
|
228
|
-
item: currentItem,
|
|
229
|
-
itemsLength: items.length,
|
|
230
|
-
itemIndex: index,
|
|
231
|
-
selectedIndex: selectedIndex,
|
|
232
|
-
onItemClick: actions.onItemClick,
|
|
233
|
-
ariaLabel: getTypeAheadListAriaLabels(triggerHandler === null || triggerHandler === void 0 ? void 0 : triggerHandler.trigger, intl, currentItem).listItemAriaLabel
|
|
234
|
-
}))));
|
|
235
|
-
};
|
|
236
|
-
const popupAriaLabel = getTypeAheadListAriaLabels(triggerHandler === null || triggerHandler === void 0 ? void 0 : triggerHandler.trigger, intl).popupAriaLabel;
|
|
237
|
-
if (!Array.isArray(items)) {
|
|
238
|
-
return null;
|
|
239
|
-
}
|
|
240
|
-
const menuGroupId = ((_decorationElement$qu2 = decorationElement.querySelector(`[role='combobox']`)) === null || _decorationElement$qu2 === void 0 ? void 0 : _decorationElement$qu2.getAttribute('aria-controls')) || TYPE_AHEAD_DECORATION_ELEMENT_ID;
|
|
241
|
-
return jsx(MenuGroup, {
|
|
242
|
-
"aria-label": popupAriaLabel,
|
|
243
|
-
"aria-relevant": "additions removals"
|
|
244
|
-
}, jsx("div", {
|
|
245
|
-
id: menuGroupId,
|
|
246
|
-
ref: listContainerRef
|
|
247
|
-
}, jsx(List, {
|
|
248
|
-
rowRenderer: renderRow,
|
|
249
|
-
ref: listRef,
|
|
250
|
-
rowCount: items.length,
|
|
251
|
-
rowHeight: cache.rowHeight,
|
|
252
|
-
onRowsRendered: onItemsRendered,
|
|
253
|
-
width: LIST_WIDTH,
|
|
254
|
-
onScroll: onScroll,
|
|
255
|
-
height: height,
|
|
256
|
-
overscanRowCount: 3,
|
|
257
|
-
containerRole: "presentation",
|
|
258
|
-
role: "listbox",
|
|
259
|
-
css: css`
|
|
260
|
-
button {
|
|
261
|
-
padding: ${"var(--ds-space-150, 12px)"}
|
|
262
|
-
${"var(--ds-space-150, 12px)"} 11px;
|
|
263
|
-
span:last-child span:last-child {
|
|
264
|
-
white-space: normal;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
`
|
|
268
|
-
}), jsx(TypeaheadAssistiveTextPureComponent, {
|
|
269
|
-
numberOfResults: items.length.toString()
|
|
270
|
-
})));
|
|
271
|
-
});
|
|
272
|
-
export const TypeAheadList = injectIntl(TypeAheadListComponent);
|
|
273
|
-
TypeAheadList.displayName = 'TypeAheadList';
|
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
/** @jsx jsx */
|
|
2
|
-
import React, { useCallback, useMemo, useLayoutEffect } from 'react';
|
|
3
|
-
import { css, jsx } from '@emotion/react';
|
|
4
|
-
import { DN600, N200, N800, N30, B400 } from '@atlaskit/theme/colors';
|
|
5
|
-
import { themed } from '@atlaskit/theme/components';
|
|
6
|
-
import { borderRadius } from '@atlaskit/theme/constants';
|
|
7
|
-
import { ButtonItem } from '@atlaskit/menu';
|
|
8
|
-
import { relativeFontSizeToBase16 } from '@atlaskit/editor-shared-styles';
|
|
9
|
-
import { IconFallback } from '@atlaskit/editor-common/quick-insert';
|
|
10
|
-
import { shortcutStyle } from '@atlaskit/editor-shared-styles/shortcut';
|
|
11
|
-
import { SelectItemMode } from '@atlaskit/editor-common/type-ahead';
|
|
12
|
-
import { useIntl } from 'react-intl-next';
|
|
13
|
-
import { typeAheadListMessages } from '../messages';
|
|
14
|
-
export const ICON_HEIGHT = 40;
|
|
15
|
-
export const ICON_WIDTH = 40;
|
|
16
|
-
export const ITEM_PADDING = 12;
|
|
17
|
-
export const itemIcon = css`
|
|
18
|
-
width: ${ICON_WIDTH}px;
|
|
19
|
-
height: ${ICON_HEIGHT}px;
|
|
20
|
-
overflow: hidden;
|
|
21
|
-
border: 1px solid ${"var(--ds-border, rgba(223, 225, 229, 0.5))"}; /* N60 at 50% */
|
|
22
|
-
border-radius: ${borderRadius()}px;
|
|
23
|
-
box-sizing: border-box;
|
|
24
|
-
|
|
25
|
-
display: flex;
|
|
26
|
-
justify-content: center;
|
|
27
|
-
align-items: center;
|
|
28
|
-
|
|
29
|
-
div {
|
|
30
|
-
width: ${ICON_WIDTH}px;
|
|
31
|
-
height: ${ICON_HEIGHT}px;
|
|
32
|
-
}
|
|
33
|
-
`;
|
|
34
|
-
const itemBody = css`
|
|
35
|
-
display: flex;
|
|
36
|
-
flex-direction: row;
|
|
37
|
-
flex-wrap: nowrap;
|
|
38
|
-
justify-content: space-between;
|
|
39
|
-
`;
|
|
40
|
-
const itemText = theme => css`
|
|
41
|
-
white-space: initial;
|
|
42
|
-
color: ${themed({
|
|
43
|
-
light: `var(--ds-text, ${N800})`,
|
|
44
|
-
dark: `var(--ds-text, ${DN600})`
|
|
45
|
-
})(theme)};
|
|
46
|
-
.item-title {
|
|
47
|
-
line-height: 1.4;
|
|
48
|
-
}
|
|
49
|
-
.item-description {
|
|
50
|
-
font-size: ${relativeFontSizeToBase16(12)};
|
|
51
|
-
color: ${`var(--ds-text-subtlest, ${N200})`};
|
|
52
|
-
margin-top: 3px;
|
|
53
|
-
}
|
|
54
|
-
`;
|
|
55
|
-
const itemAfter = css`
|
|
56
|
-
flex: 0 0 auto;
|
|
57
|
-
`;
|
|
58
|
-
const customRenderItemDivStyle = css`
|
|
59
|
-
overflow: hidden;
|
|
60
|
-
&:focus {
|
|
61
|
-
box-shadow: inset 2px 0px 0px ${`var(--ds-border-focused, ${B400})`};
|
|
62
|
-
background-color: ${`var(--ds-background-neutral-subtle-hovered, ${N30})`};
|
|
63
|
-
outline: none;
|
|
64
|
-
}
|
|
65
|
-
`;
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* This CSS emulates the desired behaviour with :focus-visible for firefox.
|
|
69
|
-
* Firefox unfortunately does not register keyboard focus if user mouseDown and drag a typeahead item
|
|
70
|
-
* resulting in focus-visible style not drawn.
|
|
71
|
-
*/
|
|
72
|
-
const selectionFrame = {
|
|
73
|
-
'& > button:focus': {
|
|
74
|
-
boxShadow: `inset 2px 0px 0px ${`var(--ds-border-focused, ${B400})`};`,
|
|
75
|
-
backgroundColor: `${`var(--ds-background-neutral-subtle-hovered, ${N30})`}`,
|
|
76
|
-
outline: 'none',
|
|
77
|
-
'&:active': {
|
|
78
|
-
boxShadow: 'none'
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
'& > button:hover': {
|
|
82
|
-
backgroundColor: 'inherit',
|
|
83
|
-
outline: 'none'
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
const selectedStyle = css`
|
|
87
|
-
background-color: ${`var(--ds-background-neutral-subtle-hovered, ${N30})`};
|
|
88
|
-
box-shadow: inset 2px 0px 0px ${`var(--ds-border-focused, ${B400})`};
|
|
89
|
-
`;
|
|
90
|
-
const FallbackIcon = /*#__PURE__*/React.memo(({
|
|
91
|
-
label
|
|
92
|
-
}) => {
|
|
93
|
-
return jsx(IconFallback, null);
|
|
94
|
-
});
|
|
95
|
-
const noop = () => {};
|
|
96
|
-
const AssistiveText = ({
|
|
97
|
-
title,
|
|
98
|
-
description,
|
|
99
|
-
shortcut
|
|
100
|
-
}) => {
|
|
101
|
-
const intl = useIntl();
|
|
102
|
-
const descriptionText = description ? ` ${intl.formatMessage(typeAheadListMessages.descriptionLabel)} ${description}.` : '';
|
|
103
|
-
const shortcutText = shortcut ? ` ${intl.formatMessage(typeAheadListMessages.shortcutLabel)} ${shortcut}.` : '';
|
|
104
|
-
return jsx("span", {
|
|
105
|
-
className: "assistive"
|
|
106
|
-
}, `${title}. ${descriptionText} ${shortcutText}`);
|
|
107
|
-
};
|
|
108
|
-
export const TypeAheadListItem = ({
|
|
109
|
-
item,
|
|
110
|
-
itemsLength,
|
|
111
|
-
selectedIndex,
|
|
112
|
-
onItemClick,
|
|
113
|
-
itemIndex,
|
|
114
|
-
ariaLabel
|
|
115
|
-
}) => {
|
|
116
|
-
/**
|
|
117
|
-
* To select and highlight the first Item when no item is selected
|
|
118
|
-
* However selectedIndex remains -1, So that user does not skip the first item when down arrow key is used from typeahead query(inputQuery.tsx)
|
|
119
|
-
*/
|
|
120
|
-
const isSelected = itemIndex === selectedIndex || selectedIndex === -1 && itemIndex === 0;
|
|
121
|
-
const {
|
|
122
|
-
icon,
|
|
123
|
-
title,
|
|
124
|
-
render: customRenderItem
|
|
125
|
-
} = item;
|
|
126
|
-
const elementIcon = useMemo(() => {
|
|
127
|
-
return jsx("div", {
|
|
128
|
-
css: itemIcon
|
|
129
|
-
}, icon ? icon() : jsx(FallbackIcon, {
|
|
130
|
-
label: title
|
|
131
|
-
}));
|
|
132
|
-
}, [icon, title]);
|
|
133
|
-
const insertSelectedItem = useCallback(() => {
|
|
134
|
-
onItemClick(SelectItemMode.SELECTED, itemIndex);
|
|
135
|
-
}, [onItemClick, itemIndex]);
|
|
136
|
-
const customItemRef = /*#__PURE__*/React.createRef();
|
|
137
|
-
const buttonItemRef = /*#__PURE__*/React.createRef();
|
|
138
|
-
const shouldUpdateFocus = selectedIndex === itemIndex;
|
|
139
|
-
useLayoutEffect(() => {
|
|
140
|
-
if (shouldUpdateFocus) {
|
|
141
|
-
var _customItemRef$curren;
|
|
142
|
-
customItemRef === null || customItemRef === void 0 ? void 0 : (_customItemRef$curren = customItemRef.current) === null || _customItemRef$curren === void 0 ? void 0 : _customItemRef$curren.focus();
|
|
143
|
-
}
|
|
144
|
-
}, [customItemRef, shouldUpdateFocus]);
|
|
145
|
-
useLayoutEffect(() => {
|
|
146
|
-
if (shouldUpdateFocus) {
|
|
147
|
-
var _buttonItemRef$curren;
|
|
148
|
-
buttonItemRef === null || buttonItemRef === void 0 ? void 0 : (_buttonItemRef$curren = buttonItemRef.current) === null || _buttonItemRef$curren === void 0 ? void 0 : _buttonItemRef$curren.focus();
|
|
149
|
-
}
|
|
150
|
-
}, [buttonItemRef, shouldUpdateFocus]);
|
|
151
|
-
const customItem = useMemo(() => {
|
|
152
|
-
if (!customRenderItem) {
|
|
153
|
-
return null;
|
|
154
|
-
}
|
|
155
|
-
const Comp = customRenderItem;
|
|
156
|
-
const listItemClasses = [customRenderItemDivStyle, isSelected && selectedStyle];
|
|
157
|
-
return jsx("div", {
|
|
158
|
-
"aria-selected": isSelected,
|
|
159
|
-
role: "option",
|
|
160
|
-
"aria-label": ariaLabel,
|
|
161
|
-
"aria-setsize": itemsLength,
|
|
162
|
-
"aria-posinset": itemIndex,
|
|
163
|
-
tabIndex: 0,
|
|
164
|
-
css: listItemClasses,
|
|
165
|
-
className: `ak-typeahead-item ${isSelected ? 'typeahead-selected-item' : ''}`
|
|
166
|
-
//CSS classes added for test cases purpose
|
|
167
|
-
,
|
|
168
|
-
ref: customItemRef
|
|
169
|
-
}, jsx("div", {
|
|
170
|
-
"aria-hidden": true
|
|
171
|
-
}, jsx(Comp, {
|
|
172
|
-
onClick: insertSelectedItem,
|
|
173
|
-
isSelected: false //The selection styles are handled in the parent div instead. Hence isSelected is made false always.
|
|
174
|
-
,
|
|
175
|
-
onHover: noop
|
|
176
|
-
})));
|
|
177
|
-
}, [customRenderItem, isSelected, ariaLabel, itemsLength, customItemRef, insertSelectedItem, itemIndex]);
|
|
178
|
-
if (customItem) {
|
|
179
|
-
return customItem;
|
|
180
|
-
}
|
|
181
|
-
const listItemClasses = [selectionFrame, isSelected && selectedStyle];
|
|
182
|
-
return jsx("span", {
|
|
183
|
-
css: listItemClasses
|
|
184
|
-
}, jsx(ButtonItem, {
|
|
185
|
-
onClick: insertSelectedItem,
|
|
186
|
-
iconBefore: elementIcon,
|
|
187
|
-
isSelected: isSelected,
|
|
188
|
-
"aria-selected": isSelected,
|
|
189
|
-
"aria-label": title,
|
|
190
|
-
"aria-setsize": itemsLength,
|
|
191
|
-
"aria-posinset": itemIndex,
|
|
192
|
-
role: "option",
|
|
193
|
-
ref: buttonItemRef,
|
|
194
|
-
css: listItemClasses
|
|
195
|
-
}, jsx("div", {
|
|
196
|
-
"aria-hidden": true
|
|
197
|
-
}, jsx("div", {
|
|
198
|
-
css: itemText
|
|
199
|
-
}, jsx("div", {
|
|
200
|
-
css: itemBody
|
|
201
|
-
}, jsx("div", {
|
|
202
|
-
className: "item-title"
|
|
203
|
-
}, item.title), jsx("div", {
|
|
204
|
-
css: itemAfter
|
|
205
|
-
}, item.keyshortcut && jsx("div", {
|
|
206
|
-
css: shortcutStyle
|
|
207
|
-
}, item.keyshortcut))), jsx("div", {
|
|
208
|
-
className: "item-description"
|
|
209
|
-
}, item.description))), jsx(AssistiveText, {
|
|
210
|
-
title: item.title,
|
|
211
|
-
description: item.description,
|
|
212
|
-
shortcut: item.keyshortcut
|
|
213
|
-
})));
|
|
214
|
-
};
|