@atlaskit/editor-plugin-type-ahead 10.2.1 → 10.3.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.
- package/CHANGELOG.md +26 -0
- package/dist/cjs/pm-plugins/commands/update-list-items.js +3 -1
- package/dist/cjs/pm-plugins/main.js +1 -0
- package/dist/cjs/pm-plugins/reducer.js +7 -1
- package/dist/cjs/typeAheadPlugin.js +3 -1
- package/dist/cjs/ui/ContentComponent.js +10 -7
- package/dist/cjs/ui/TypeAheadList.js +126 -52
- package/dist/cjs/ui/TypeAheadMenu.js +3 -0
- package/dist/cjs/ui/TypeAheadPopup.js +3 -0
- package/dist/cjs/ui/WrapperTypeAhead.js +3 -1
- package/dist/cjs/ui/hooks/build-sectioned-result.js +131 -0
- package/dist/cjs/ui/hooks/use-load-items.js +12 -4
- package/dist/es2019/pm-plugins/commands/update-list-items.js +3 -2
- package/dist/es2019/pm-plugins/main.js +1 -0
- package/dist/es2019/pm-plugins/reducer.js +6 -1
- package/dist/es2019/typeAheadPlugin.js +3 -1
- package/dist/es2019/ui/ContentComponent.js +10 -7
- package/dist/es2019/ui/TypeAheadList.js +85 -23
- package/dist/es2019/ui/TypeAheadMenu.js +2 -0
- package/dist/es2019/ui/TypeAheadPopup.js +2 -0
- package/dist/es2019/ui/WrapperTypeAhead.js +3 -1
- package/dist/es2019/ui/hooks/build-sectioned-result.js +83 -0
- package/dist/es2019/ui/hooks/use-load-items.js +13 -4
- package/dist/esm/pm-plugins/commands/update-list-items.js +3 -1
- package/dist/esm/pm-plugins/main.js +1 -0
- package/dist/esm/pm-plugins/reducer.js +7 -1
- package/dist/esm/typeAheadPlugin.js +3 -1
- package/dist/esm/ui/ContentComponent.js +10 -7
- package/dist/esm/ui/TypeAheadList.js +126 -52
- package/dist/esm/ui/TypeAheadMenu.js +3 -0
- package/dist/esm/ui/TypeAheadPopup.js +3 -0
- package/dist/esm/ui/WrapperTypeAhead.js +3 -1
- package/dist/esm/ui/hooks/build-sectioned-result.js +124 -0
- package/dist/esm/ui/hooks/use-load-items.js +12 -4
- package/dist/types/pm-plugins/commands/update-list-items.d.ts +2 -1
- package/dist/types/types/index.d.ts +8 -0
- package/dist/types/ui/TypeAheadList.d.ts +3 -1
- package/dist/types/ui/TypeAheadPopup.d.ts +3 -2
- package/dist/types/ui/hooks/build-sectioned-result.d.ts +11 -0
- package/dist/types/ui/hooks/use-load-items.d.ts +2 -1
- package/dist/types-ts4.5/pm-plugins/commands/update-list-items.d.ts +2 -1
- package/dist/types-ts4.5/types/index.d.ts +8 -0
- package/dist/types-ts4.5/ui/TypeAheadList.d.ts +3 -1
- package/dist/types-ts4.5/ui/TypeAheadPopup.d.ts +3 -2
- package/dist/types-ts4.5/ui/hooks/build-sectioned-result.d.ts +11 -0
- package/dist/types-ts4.5/ui/hooks/use-load-items.d.ts +2 -1
- package/package.json +4 -4
|
@@ -4,8 +4,9 @@ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
|
4
4
|
import { clearListError } from '../../pm-plugins/commands/clear-list-error';
|
|
5
5
|
import { updateListError } from '../../pm-plugins/commands/update-list-error';
|
|
6
6
|
import { updateListItem } from '../../pm-plugins/commands/update-list-items';
|
|
7
|
+
import { buildSectionedResult } from './build-sectioned-result';
|
|
7
8
|
const EMPTY_LIST_ITEM = [];
|
|
8
|
-
export const useLoadItems = (triggerHandler, editorView, query, showViewMore, api) => {
|
|
9
|
+
export const useLoadItems = (triggerHandler, editorView, query, showViewMore, api, intl) => {
|
|
9
10
|
const [items, setItems] = useState(EMPTY_LIST_ITEM);
|
|
10
11
|
const componentIsMounted = useRef(true);
|
|
11
12
|
const editorViewRef = useRef(editorView);
|
|
@@ -35,7 +36,15 @@ export const useLoadItems = (triggerHandler, editorView, query, showViewMore, ap
|
|
|
35
36
|
const emptyItem = result.length === 0 && expValEquals('platform_editor_insert_menu_ai', 'isEnabled', true) ? (_triggerHandler$getEm = triggerHandler.getEmptyItem) === null || _triggerHandler$getEm === void 0 ? void 0 : _triggerHandler$getEm.call(triggerHandler, {
|
|
36
37
|
editorState: editorView.state
|
|
37
38
|
}) : undefined;
|
|
38
|
-
const
|
|
39
|
+
const rawList = result.length > 0 ? result : emptyItem ? [emptyItem] : EMPTY_LIST_ITEM;
|
|
40
|
+
const {
|
|
41
|
+
items: list,
|
|
42
|
+
sections
|
|
43
|
+
} = buildSectionedResult({
|
|
44
|
+
items: rawList,
|
|
45
|
+
triggerHandler,
|
|
46
|
+
intl: intl !== null && intl !== void 0 ? intl : null
|
|
47
|
+
});
|
|
39
48
|
if (componentIsMounted.current) {
|
|
40
49
|
setItems(list);
|
|
41
50
|
}
|
|
@@ -45,7 +54,7 @@ export const useLoadItems = (triggerHandler, editorView, query, showViewMore, ap
|
|
|
45
54
|
title: 'View more'
|
|
46
55
|
};
|
|
47
56
|
queueMicrotask(() => {
|
|
48
|
-
updateListItem(showViewMore ? list.concat(viewMoreItem) : list)(view.state, view.dispatch);
|
|
57
|
+
updateListItem(showViewMore ? list.concat(viewMoreItem) : list, sections)(view.state, view.dispatch);
|
|
49
58
|
});
|
|
50
59
|
}).catch(e => {
|
|
51
60
|
if (editorExperiment('platform_editor_offline_editing_web', true)) {
|
|
@@ -63,7 +72,7 @@ export const useLoadItems = (triggerHandler, editorView, query, showViewMore, ap
|
|
|
63
72
|
// ignore because EditorView is mutable but we don't want to
|
|
64
73
|
// call loadItems when it changes, only when the query changes
|
|
65
74
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
66
|
-
}, [triggerHandler, query]);
|
|
75
|
+
}, [triggerHandler, query, intl]);
|
|
67
76
|
useEffect(() => {
|
|
68
77
|
return () => {
|
|
69
78
|
componentIsMounted.current = false;
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { ACTIONS } from '../actions';
|
|
2
2
|
import { pluginKey as typeAheadPluginKey } from '../key';
|
|
3
3
|
export var updateListItem = function updateListItem(items) {
|
|
4
|
+
var sections = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
4
5
|
return function (state, dispatch) {
|
|
5
6
|
var tr = state.tr;
|
|
6
7
|
tr.setMeta(typeAheadPluginKey, {
|
|
7
8
|
action: ACTIONS.UPDATE_LIST_ITEMS,
|
|
8
9
|
params: {
|
|
9
|
-
items: items
|
|
10
|
+
items: items,
|
|
11
|
+
sections: sections
|
|
10
12
|
}
|
|
11
13
|
});
|
|
12
14
|
if (dispatch) {
|
|
@@ -69,6 +69,7 @@ export var createReducer = function createReducer(_ref) {
|
|
|
69
69
|
inputMethod: inputMethod,
|
|
70
70
|
selectedIndex: typeof selectedIndex === 'number' ? selectedIndex : -1,
|
|
71
71
|
items: [],
|
|
72
|
+
sections: [],
|
|
72
73
|
query: reopenQuery || '',
|
|
73
74
|
removePrefixTriggerOnCancel: removePrefixTriggerOnCancel
|
|
74
75
|
});
|
|
@@ -87,6 +88,7 @@ export var createReducer = function createReducer(_ref) {
|
|
|
87
88
|
stats: null,
|
|
88
89
|
triggerHandler: undefined,
|
|
89
90
|
items: [],
|
|
91
|
+
sections: [],
|
|
90
92
|
removePrefixTriggerOnCancel: undefined
|
|
91
93
|
});
|
|
92
94
|
};
|
|
@@ -137,13 +139,17 @@ export var createReducer = function createReducer(_ref) {
|
|
|
137
139
|
return _objectSpread(_objectSpread({}, currentPluginState), {}, {
|
|
138
140
|
errorInfo: errorInfo,
|
|
139
141
|
items: [],
|
|
142
|
+
sections: [],
|
|
140
143
|
selectedIndex: -1
|
|
141
144
|
});
|
|
142
145
|
} else if (shouldUpdateListItems) {
|
|
143
|
-
var items = params.items
|
|
146
|
+
var items = params.items,
|
|
147
|
+
_params$sections = params.sections,
|
|
148
|
+
sections = _params$sections === void 0 ? [] : _params$sections;
|
|
144
149
|
var selectedIndex = currentPluginState.selectedIndex;
|
|
145
150
|
return _objectSpread(_objectSpread({}, currentPluginState), {}, {
|
|
146
151
|
items: items,
|
|
152
|
+
sections: sections,
|
|
147
153
|
selectedIndex: Math.max(selectedIndex >= items.length ? items.length - 1 : selectedIndex, -1)
|
|
148
154
|
});
|
|
149
155
|
} else if (shouldUpdateSelectedIndex) {
|
|
@@ -206,7 +206,7 @@ export var typeAheadPlugin = function typeAheadPlugin(_ref) {
|
|
|
206
206
|
}];
|
|
207
207
|
},
|
|
208
208
|
getSharedState: function getSharedState(editorState) {
|
|
209
|
-
var _state$decorationSet, _state$decorationElem, _state$items, _state$errorInfo, _state$selectedIndex;
|
|
209
|
+
var _state$decorationSet, _state$decorationElem, _state$items, _state$sections, _state$errorInfo, _state$selectedIndex;
|
|
210
210
|
if (!editorState) {
|
|
211
211
|
return {
|
|
212
212
|
query: '',
|
|
@@ -217,6 +217,7 @@ export var typeAheadPlugin = function typeAheadPlugin(_ref) {
|
|
|
217
217
|
decorationElement: null,
|
|
218
218
|
triggerHandler: undefined,
|
|
219
219
|
items: [],
|
|
220
|
+
sections: [],
|
|
220
221
|
errorInfo: null,
|
|
221
222
|
selectedIndex: 0
|
|
222
223
|
};
|
|
@@ -232,6 +233,7 @@ export var typeAheadPlugin = function typeAheadPlugin(_ref) {
|
|
|
232
233
|
decorationElement: (_state$decorationElem = state === null || state === void 0 ? void 0 : state.decorationElement) !== null && _state$decorationElem !== void 0 ? _state$decorationElem : null,
|
|
233
234
|
triggerHandler: state === null || state === void 0 ? void 0 : state.triggerHandler,
|
|
234
235
|
items: (_state$items = state === null || state === void 0 ? void 0 : state.items) !== null && _state$items !== void 0 ? _state$items : [],
|
|
236
|
+
sections: (_state$sections = state === null || state === void 0 ? void 0 : state.sections) !== null && _state$sections !== void 0 ? _state$sections : [],
|
|
235
237
|
errorInfo: (_state$errorInfo = state === null || state === void 0 ? void 0 : state.errorInfo) !== null && _state$errorInfo !== void 0 ? _state$errorInfo : null,
|
|
236
238
|
selectedIndex: (_state$selectedIndex = state === null || state === void 0 ? void 0 : state.selectedIndex) !== null && _state$selectedIndex !== void 0 ? _state$selectedIndex : 0
|
|
237
239
|
};
|
|
@@ -6,25 +6,27 @@ export function ContentComponent(_ref) {
|
|
|
6
6
|
editorView = _ref.editorView,
|
|
7
7
|
popupMountRef = _ref.popupMountRef;
|
|
8
8
|
var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['typeAhead'], function (states) {
|
|
9
|
-
var _states$typeAheadStat, _states$typeAheadStat2, _states$typeAheadStat3, _states$typeAheadStat4, _states$typeAheadStat5, _states$typeAheadStat6, _states$typeAheadStat7;
|
|
9
|
+
var _states$typeAheadStat, _states$typeAheadStat2, _states$typeAheadStat3, _states$typeAheadStat4, _states$typeAheadStat5, _states$typeAheadStat6, _states$typeAheadStat7, _states$typeAheadStat8;
|
|
10
10
|
return {
|
|
11
11
|
triggerHandler: (_states$typeAheadStat = states.typeAheadState) === null || _states$typeAheadStat === void 0 ? void 0 : _states$typeAheadStat.triggerHandler,
|
|
12
12
|
items: (_states$typeAheadStat2 = states.typeAheadState) === null || _states$typeAheadStat2 === void 0 ? void 0 : _states$typeAheadStat2.items,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
sections: (_states$typeAheadStat3 = states.typeAheadState) === null || _states$typeAheadStat3 === void 0 ? void 0 : _states$typeAheadStat3.sections,
|
|
14
|
+
errorInfo: (_states$typeAheadStat4 = states.typeAheadState) === null || _states$typeAheadStat4 === void 0 ? void 0 : _states$typeAheadStat4.errorInfo,
|
|
15
|
+
decorationElement: (_states$typeAheadStat5 = states.typeAheadState) === null || _states$typeAheadStat5 === void 0 ? void 0 : _states$typeAheadStat5.decorationElement,
|
|
16
|
+
decorationSet: (_states$typeAheadStat6 = states.typeAheadState) === null || _states$typeAheadStat6 === void 0 ? void 0 : _states$typeAheadStat6.decorationSet,
|
|
17
|
+
query: (_states$typeAheadStat7 = states.typeAheadState) === null || _states$typeAheadStat7 === void 0 ? void 0 : _states$typeAheadStat7.query,
|
|
18
|
+
selectedIndex: (_states$typeAheadStat8 = states.typeAheadState) === null || _states$typeAheadStat8 === void 0 ? void 0 : _states$typeAheadStat8.selectedIndex
|
|
18
19
|
};
|
|
19
20
|
}),
|
|
20
21
|
triggerHandler = _useSharedPluginState.triggerHandler,
|
|
21
22
|
items = _useSharedPluginState.items,
|
|
23
|
+
sections = _useSharedPluginState.sections,
|
|
22
24
|
errorInfo = _useSharedPluginState.errorInfo,
|
|
23
25
|
decorationElement = _useSharedPluginState.decorationElement,
|
|
24
26
|
decorationSet = _useSharedPluginState.decorationSet,
|
|
25
27
|
query = _useSharedPluginState.query,
|
|
26
28
|
selectedIndex = _useSharedPluginState.selectedIndex;
|
|
27
|
-
if (items === undefined || decorationSet === undefined || errorInfo === undefined || decorationElement === undefined || query === undefined || selectedIndex === undefined) {
|
|
29
|
+
if (items === undefined || sections === undefined || decorationSet === undefined || errorInfo === undefined || decorationElement === undefined || query === undefined || selectedIndex === undefined) {
|
|
28
30
|
return null;
|
|
29
31
|
}
|
|
30
32
|
return /*#__PURE__*/React.createElement(TypeAheadMenu, {
|
|
@@ -35,6 +37,7 @@ export function ContentComponent(_ref) {
|
|
|
35
37
|
typeAheadState: {
|
|
36
38
|
triggerHandler: triggerHandler,
|
|
37
39
|
items: items,
|
|
40
|
+
sections: sections,
|
|
38
41
|
errorInfo: errorInfo,
|
|
39
42
|
decorationElement: decorationElement,
|
|
40
43
|
decorationSet: decorationSet,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
3
|
/**
|
|
3
4
|
* @jsxRuntime classic
|
|
4
5
|
* @jsx jsx
|
|
@@ -18,6 +19,7 @@ import { AssistiveText } from '@atlaskit/editor-common/ui';
|
|
|
18
19
|
import { MenuGroup } from '@atlaskit/menu';
|
|
19
20
|
import { Text, Box } from '@atlaskit/primitives/compiled';
|
|
20
21
|
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
22
|
+
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
21
23
|
import { closeTypeAhead } from '../pm-plugins/commands/close-type-ahead';
|
|
22
24
|
import { updateSelectedIndex } from '../pm-plugins/commands/update-selected-index';
|
|
23
25
|
import { TYPE_AHEAD_DECORATION_ELEMENT_ID } from '../pm-plugins/constants';
|
|
@@ -33,8 +35,43 @@ var list = css({
|
|
|
33
35
|
padding: "var(--ds-space-100, 8px)".concat(" ", "var(--ds-space-150, 12px)")
|
|
34
36
|
}
|
|
35
37
|
});
|
|
36
|
-
var
|
|
37
|
-
var
|
|
38
|
+
var buildTypeAheadRows = function buildTypeAheadRows(_ref) {
|
|
39
|
+
var itemsLength = _ref.itemsLength,
|
|
40
|
+
sections = _ref.sections;
|
|
41
|
+
if (sections.length === 0) {
|
|
42
|
+
return Array.from({
|
|
43
|
+
length: itemsLength
|
|
44
|
+
}, function (_, itemIndex) {
|
|
45
|
+
return {
|
|
46
|
+
type: 'item',
|
|
47
|
+
itemIndex: itemIndex
|
|
48
|
+
};
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
var sortedSections = _toConsumableArray(sections).sort(function (left, right) {
|
|
52
|
+
return left.startIndex - right.startIndex;
|
|
53
|
+
});
|
|
54
|
+
var sectionsByStartIndex = new Map(sortedSections.map(function (section) {
|
|
55
|
+
return [section.startIndex, section];
|
|
56
|
+
}));
|
|
57
|
+
var rows = [];
|
|
58
|
+
for (var itemIndex = 0; itemIndex < itemsLength; itemIndex++) {
|
|
59
|
+
var section = sectionsByStartIndex.get(itemIndex);
|
|
60
|
+
if (section) {
|
|
61
|
+
rows.push({
|
|
62
|
+
type: 'section',
|
|
63
|
+
section: section
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
rows.push({
|
|
67
|
+
type: 'item',
|
|
68
|
+
itemIndex: itemIndex
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return rows;
|
|
72
|
+
};
|
|
73
|
+
var TypeaheadAssistiveTextPureComponent = /*#__PURE__*/React.memo(function (_ref2) {
|
|
74
|
+
var numberOfResults = _ref2.numberOfResults;
|
|
38
75
|
var intl = useIntl();
|
|
39
76
|
return jsx(AssistiveText, {
|
|
40
77
|
assistiveText: intl.formatMessage(typeAheadListMessages.searchResultsLabel, {
|
|
@@ -46,21 +83,22 @@ var TypeaheadAssistiveTextPureComponent = /*#__PURE__*/React.memo(function (_ref
|
|
|
46
83
|
id: TYPE_AHEAD_DECORATION_ELEMENT_ID + '__popup'
|
|
47
84
|
});
|
|
48
85
|
});
|
|
49
|
-
var TypeAheadListComponent = /*#__PURE__*/React.memo(function (
|
|
50
|
-
var _triggerHandler$getMo, _decorationElement$qu2;
|
|
51
|
-
var items =
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
86
|
+
var TypeAheadListComponent = /*#__PURE__*/React.memo(function (_ref3) {
|
|
87
|
+
var _itemRowIndexByItemIn, _triggerHandler$getMo, _decorationElement$qu2;
|
|
88
|
+
var items = _ref3.items,
|
|
89
|
+
sections = _ref3.sections,
|
|
90
|
+
emptyItem = _ref3.emptyItem,
|
|
91
|
+
selectedIndex = _ref3.selectedIndex,
|
|
92
|
+
editorView = _ref3.editorView,
|
|
93
|
+
onItemClick = _ref3.onItemClick,
|
|
94
|
+
intl = _ref3.intl,
|
|
95
|
+
fitHeight = _ref3.fitHeight,
|
|
96
|
+
decorationElement = _ref3.decorationElement,
|
|
97
|
+
triggerHandler = _ref3.triggerHandler,
|
|
98
|
+
moreElementsInQuickInsertViewEnabled = _ref3.moreElementsInQuickInsertViewEnabled,
|
|
99
|
+
api = _ref3.api,
|
|
100
|
+
showMoreOptionsButton = _ref3.showMoreOptionsButton,
|
|
101
|
+
onMoreOptionsClicked = _ref3.onMoreOptionsClicked;
|
|
64
102
|
var listRef = useRef();
|
|
65
103
|
var listContainerRef = useRef(null);
|
|
66
104
|
var lastInputMethodRef = useRef('keyboard');
|
|
@@ -87,6 +125,27 @@ var TypeAheadListComponent = /*#__PURE__*/React.memo(function (_ref2) {
|
|
|
87
125
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
88
126
|
cache = _useState4[0],
|
|
89
127
|
setCache = _useState4[1];
|
|
128
|
+
var listRows = useMemo(function () {
|
|
129
|
+
return buildTypeAheadRows({
|
|
130
|
+
itemsLength: itemsLength,
|
|
131
|
+
sections: sections || []
|
|
132
|
+
});
|
|
133
|
+
}, [itemsLength, sections]);
|
|
134
|
+
var itemRowIndexByItemIndex = useMemo(function () {
|
|
135
|
+
var rowIndexByItemIndex = new Map();
|
|
136
|
+
listRows.forEach(function (row, rowIndex) {
|
|
137
|
+
if (row.type === 'item') {
|
|
138
|
+
rowIndexByItemIndex.set(row.itemIndex, rowIndex);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
return rowIndexByItemIndex;
|
|
142
|
+
}, [listRows]);
|
|
143
|
+
var populatedSectionCount = useMemo(function () {
|
|
144
|
+
return listRows.filter(function (row) {
|
|
145
|
+
return row.type === 'section';
|
|
146
|
+
}).length;
|
|
147
|
+
}, [listRows]);
|
|
148
|
+
var selectedItemRowIndex = selectedIndex >= 0 ? (_itemRowIndexByItemIn = itemRowIndexByItemIndex.get(selectedIndex)) !== null && _itemRowIndexByItemIn !== void 0 ? _itemRowIndexByItemIn : -1 : -1;
|
|
90
149
|
var onItemsRendered = useCallback(function (props) {
|
|
91
150
|
lastVisibleIndexes.current = props;
|
|
92
151
|
}, []);
|
|
@@ -123,8 +182,8 @@ var TypeAheadListComponent = /*#__PURE__*/React.memo(function (_ref2) {
|
|
|
123
182
|
var lastVisibleStopIndex = lastVisibleIndexes.current.stopIndex;
|
|
124
183
|
var onScroll = useCallback(
|
|
125
184
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
126
|
-
function (
|
|
127
|
-
var scrollUpdateWasRequested =
|
|
185
|
+
function (_ref4) {
|
|
186
|
+
var scrollUpdateWasRequested = _ref4.scrollUpdateWasRequested;
|
|
128
187
|
if (!scrollUpdateWasRequested) {
|
|
129
188
|
return;
|
|
130
189
|
}
|
|
@@ -142,28 +201,32 @@ var TypeAheadListComponent = /*#__PURE__*/React.memo(function (_ref2) {
|
|
|
142
201
|
requestAnimationFrame(function () {
|
|
143
202
|
requestAnimationFrame(function () {
|
|
144
203
|
var isViewMoreSelected = showMoreOptionsButton && selectedIndex === itemsLength;
|
|
145
|
-
var isSelectedItemVisible =
|
|
204
|
+
var isSelectedItemVisible = selectedItemRowIndex >= lastVisibleStartIndex && selectedItemRowIndex <= lastVisibleStopIndex ||
|
|
146
205
|
// view more is always visible, hence no scrolling
|
|
147
206
|
isViewMoreSelected;
|
|
148
207
|
|
|
149
208
|
//Should scroll to the list item only when the selectedIndex >= 0 and item is not visible
|
|
150
209
|
if (!isSelectedItemVisible && selectedIndex !== -1) {
|
|
151
|
-
listRef.current.scrollToRow(
|
|
210
|
+
listRef.current.scrollToRow(selectedItemRowIndex);
|
|
152
211
|
} else if (selectedIndex === -1) {
|
|
153
212
|
listRef.current.scrollToRow(0);
|
|
154
213
|
}
|
|
155
214
|
});
|
|
156
215
|
});
|
|
157
|
-
}, [selectedIndex, lastVisibleStartIndex, lastVisibleStopIndex, itemsLength, showMoreOptionsButton]);
|
|
158
|
-
var _onMouseMove = function onMouseMove(event,
|
|
216
|
+
}, [selectedIndex, lastVisibleStartIndex, lastVisibleStopIndex, itemsLength, showMoreOptionsButton, selectedItemRowIndex]);
|
|
217
|
+
var _onMouseMove = function onMouseMove(event, row) {
|
|
218
|
+
if (row.type !== 'item') {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
var itemIndex = row.itemIndex;
|
|
159
222
|
event.preventDefault();
|
|
160
223
|
event.stopPropagation();
|
|
161
|
-
if (selectedIndex ===
|
|
224
|
+
if (selectedIndex === itemIndex) {
|
|
162
225
|
return;
|
|
163
226
|
}
|
|
164
227
|
mouseMovedRef.current = true;
|
|
165
228
|
lastInputMethodRef.current = 'mouse';
|
|
166
|
-
updateSelectedIndex(
|
|
229
|
+
updateSelectedIndex(itemIndex, api)(editorView.state, editorView.dispatch);
|
|
167
230
|
};
|
|
168
231
|
useLayoutEffect(function () {
|
|
169
232
|
if (mouseMovedRef.current) {
|
|
@@ -177,17 +240,17 @@ var TypeAheadListComponent = /*#__PURE__*/React.memo(function (_ref2) {
|
|
|
177
240
|
return;
|
|
178
241
|
}
|
|
179
242
|
var isViewMoreSelected = showMoreOptionsButton && selectedIndex === itemsLength;
|
|
180
|
-
var isSelectedItemVisible =
|
|
243
|
+
var isSelectedItemVisible = selectedItemRowIndex >= lastVisibleStartIndex && selectedItemRowIndex <= lastVisibleStopIndex ||
|
|
181
244
|
// view more is always visible, hence no scrolling
|
|
182
245
|
isViewMoreSelected;
|
|
183
246
|
|
|
184
247
|
//Should scroll to the list item only when the selectedIndex >= 0 and item is not visible
|
|
185
248
|
if (!isSelectedItemVisible && selectedIndex !== -1) {
|
|
186
|
-
listRef.current.scrollToRow(
|
|
249
|
+
listRef.current.scrollToRow(selectedItemRowIndex);
|
|
187
250
|
} else if (selectedIndex === -1) {
|
|
188
251
|
listRef.current.scrollToRow(0);
|
|
189
252
|
}
|
|
190
|
-
}, [selectedIndex, lastVisibleStartIndex, lastVisibleStopIndex, itemsLength, showMoreOptionsButton]);
|
|
253
|
+
}, [selectedIndex, lastVisibleStartIndex, lastVisibleStopIndex, itemsLength, showMoreOptionsButton, selectedItemRowIndex]);
|
|
191
254
|
useLayoutEffect(function () {
|
|
192
255
|
setCache(new CellMeasurerCache({
|
|
193
256
|
fixedWidth: true,
|
|
@@ -203,10 +266,10 @@ var TypeAheadListComponent = /*#__PURE__*/React.memo(function (_ref2) {
|
|
|
203
266
|
listContainerRef.current.firstChild.scrollTo(0, 0);
|
|
204
267
|
}
|
|
205
268
|
});
|
|
206
|
-
}, [items]);
|
|
269
|
+
}, [items, sections]);
|
|
207
270
|
useLayoutEffect(function () {
|
|
208
271
|
// Exclude view more item from the count
|
|
209
|
-
var itemsToRender = showMoreOptionsButton ? items.slice(0, -1) : items;
|
|
272
|
+
var itemsToRender = editorExperiment('platform_editor_agent_mentions', true) ? listRows : showMoreOptionsButton ? items.slice(0, -1) : items;
|
|
210
273
|
var height = Math.min(
|
|
211
274
|
// eslint-disable-next-line @atlassian/perf-linting/no-expensive-computations-in-render -- Ignored via go/ees017 (to be fixed)
|
|
212
275
|
itemsToRender.reduce(function (prevValue, currentValue, index) {
|
|
@@ -215,7 +278,7 @@ var TypeAheadListComponent = /*#__PURE__*/React.memo(function (_ref2) {
|
|
|
215
278
|
});
|
|
216
279
|
}, 0), fitHeight);
|
|
217
280
|
setHeight(height);
|
|
218
|
-
}, [items, cache, fitHeight, showMoreOptionsButton]);
|
|
281
|
+
}, [listRows, items, cache, fitHeight, showMoreOptionsButton]);
|
|
219
282
|
useLayoutEffect(function () {
|
|
220
283
|
if (!listContainerRef.current) {
|
|
221
284
|
return;
|
|
@@ -278,8 +341,8 @@ var TypeAheadListComponent = /*#__PURE__*/React.memo(function (_ref2) {
|
|
|
278
341
|
if (onMoreOptionsClicked) {
|
|
279
342
|
onMoreOptionsClicked();
|
|
280
343
|
}
|
|
281
|
-
api === null || api === void 0 || api.core.actions.execute(function (
|
|
282
|
-
var tr =
|
|
344
|
+
api === null || api === void 0 || api.core.actions.execute(function (_ref5) {
|
|
345
|
+
var tr = _ref5.tr;
|
|
283
346
|
closeTypeAhead(tr);
|
|
284
347
|
config === null || config === void 0 || config.onClick({
|
|
285
348
|
tr: tr
|
|
@@ -287,22 +350,25 @@ var TypeAheadListComponent = /*#__PURE__*/React.memo(function (_ref2) {
|
|
|
287
350
|
return tr;
|
|
288
351
|
});
|
|
289
352
|
};
|
|
290
|
-
var renderRow = function renderRow(
|
|
291
|
-
var index =
|
|
292
|
-
key =
|
|
293
|
-
style =
|
|
294
|
-
parent =
|
|
295
|
-
isScrolling =
|
|
296
|
-
isVisible =
|
|
297
|
-
var
|
|
353
|
+
var renderRow = function renderRow(_ref6) {
|
|
354
|
+
var index = _ref6.index,
|
|
355
|
+
key = _ref6.key,
|
|
356
|
+
style = _ref6.style,
|
|
357
|
+
parent = _ref6.parent,
|
|
358
|
+
isScrolling = _ref6.isScrolling,
|
|
359
|
+
isVisible = _ref6.isVisible;
|
|
360
|
+
var currentRow = listRows[index];
|
|
361
|
+
if (!currentRow) {
|
|
362
|
+
return null;
|
|
363
|
+
}
|
|
298
364
|
return jsx(CellMeasurer, {
|
|
299
365
|
key: key,
|
|
300
366
|
cache: cache,
|
|
301
367
|
parent: parent,
|
|
302
368
|
columnIndex: 0,
|
|
303
369
|
rowIndex: index
|
|
304
|
-
}, function (
|
|
305
|
-
var measure =
|
|
370
|
+
}, function (_ref7) {
|
|
371
|
+
var measure = _ref7.measure;
|
|
306
372
|
return jsx(ListRow, {
|
|
307
373
|
measure: measure,
|
|
308
374
|
index: index
|
|
@@ -314,21 +380,29 @@ var TypeAheadListComponent = /*#__PURE__*/React.memo(function (_ref2) {
|
|
|
314
380
|
// eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed)
|
|
315
381
|
,
|
|
316
382
|
onMouseMove: function onMouseMove(e) {
|
|
317
|
-
return _onMouseMove(e,
|
|
383
|
+
return _onMouseMove(e, currentRow);
|
|
318
384
|
}
|
|
319
|
-
}, jsx(
|
|
320
|
-
|
|
321
|
-
|
|
385
|
+
}, currentRow.type === 'section' ? populatedSectionCount === 1 ? null : jsx(Box, {
|
|
386
|
+
paddingInline: "space.150",
|
|
387
|
+
paddingBlock: "space.050"
|
|
388
|
+
}, jsx(Text, {
|
|
389
|
+
as: "span",
|
|
390
|
+
size: "small",
|
|
391
|
+
color: "color.text.subtle",
|
|
392
|
+
weight: "medium"
|
|
393
|
+
}, currentRow.section.title)) : jsx(TypeAheadListItem, {
|
|
394
|
+
key: items[currentRow.itemIndex].title,
|
|
395
|
+
item: items[currentRow.itemIndex],
|
|
322
396
|
firstOnlineSupportedIndex: firstOnlineSupportedRow,
|
|
323
397
|
itemsLength: itemsLength,
|
|
324
|
-
itemIndex:
|
|
398
|
+
itemIndex: currentRow.itemIndex,
|
|
325
399
|
selectedIndex: selectedIndex
|
|
326
400
|
// eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed)
|
|
327
401
|
,
|
|
328
|
-
onItemClick: function onItemClick(mode,
|
|
329
|
-
actions.onItemClick(mode,
|
|
402
|
+
onItemClick: function onItemClick(mode, itemIndex) {
|
|
403
|
+
actions.onItemClick(mode, itemIndex, INPUT_METHOD.MOUSE);
|
|
330
404
|
},
|
|
331
|
-
ariaLabel: getTypeAheadListAriaLabels(triggerHandler === null || triggerHandler === void 0 ? void 0 : triggerHandler.trigger, intl,
|
|
405
|
+
ariaLabel: getTypeAheadListAriaLabels(triggerHandler === null || triggerHandler === void 0 ? void 0 : triggerHandler.trigger, intl, items[currentRow.itemIndex]).listItemAriaLabel,
|
|
332
406
|
moreElementsInQuickInsertViewEnabled: moreElementsInQuickInsertViewEnabled,
|
|
333
407
|
api: api,
|
|
334
408
|
lastInputMethodRef: lastInputMethodRef
|
|
@@ -362,7 +436,7 @@ var TypeAheadListComponent = /*#__PURE__*/React.memo(function (_ref2) {
|
|
|
362
436
|
ref: listRef
|
|
363
437
|
// Skip rendering the view more button in the list
|
|
364
438
|
,
|
|
365
|
-
rowCount:
|
|
439
|
+
rowCount: listRows.length,
|
|
366
440
|
rowHeight: cache.rowHeight,
|
|
367
441
|
onRowsRendered: onItemsRendered,
|
|
368
442
|
width: LIST_WIDTH,
|
|
@@ -16,6 +16,8 @@ export var TypeAheadMenu = /*#__PURE__*/React.memo(function (_ref) {
|
|
|
16
16
|
var isOpen = typeAheadState.decorationSet.find().length > 0;
|
|
17
17
|
var triggerHandler = typeAheadState.triggerHandler,
|
|
18
18
|
items = typeAheadState.items,
|
|
19
|
+
_typeAheadState$secti = typeAheadState.sections,
|
|
20
|
+
sections = _typeAheadState$secti === void 0 ? [] : _typeAheadState$secti,
|
|
19
21
|
errorInfo = typeAheadState.errorInfo,
|
|
20
22
|
decorationElement = typeAheadState.decorationElement,
|
|
21
23
|
decorationSet = typeAheadState.decorationSet,
|
|
@@ -96,6 +98,7 @@ export var TypeAheadMenu = /*#__PURE__*/React.memo(function (_ref) {
|
|
|
96
98
|
anchorElement: decorationElement,
|
|
97
99
|
triggerHandler: triggerHandler,
|
|
98
100
|
items: items,
|
|
101
|
+
sections: sections,
|
|
99
102
|
emptyItem: emptyItem,
|
|
100
103
|
errorInfo: errorInfo,
|
|
101
104
|
selectedIndex: selectedIndex,
|
|
@@ -60,6 +60,8 @@ export var TypeAheadPopup = /*#__PURE__*/React.memo(function (props) {
|
|
|
60
60
|
popupsBoundariesElement = props.popupsBoundariesElement,
|
|
61
61
|
popupsScrollableElement = props.popupsScrollableElement,
|
|
62
62
|
items = props.items,
|
|
63
|
+
_props$sections = props.sections,
|
|
64
|
+
sections = _props$sections === void 0 ? [] : _props$sections,
|
|
63
65
|
emptyItem = props.emptyItem,
|
|
64
66
|
errorInfo = props.errorInfo,
|
|
65
67
|
selectedIndex = props.selectedIndex,
|
|
@@ -335,6 +337,7 @@ export var TypeAheadPopup = /*#__PURE__*/React.memo(function (props) {
|
|
|
335
337
|
triggerHandler: triggerHandler
|
|
336
338
|
}), jsx(TypeAheadList, {
|
|
337
339
|
items: items,
|
|
340
|
+
sections: sections,
|
|
338
341
|
emptyItem: emptyItem,
|
|
339
342
|
selectedIndex: selectedIndex
|
|
340
343
|
// eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
2
|
import React, { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
3
|
+
import { useIntl } from 'react-intl';
|
|
3
4
|
import { ACTION, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
4
5
|
import { SelectItemMode } from '@atlaskit/editor-common/type-ahead';
|
|
5
6
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
@@ -31,6 +32,7 @@ export var WrapperTypeAhead = /*#__PURE__*/React.memo(function (_ref) {
|
|
|
31
32
|
if (editorExperiment('platform_editor_controls', 'variant1')) {
|
|
32
33
|
showMoreOptionsButton = !!(triggerHandler !== null && triggerHandler !== void 0 && triggerHandler.getMoreOptionsButtonConfig);
|
|
33
34
|
}
|
|
35
|
+
var intl = useIntl();
|
|
34
36
|
var _useState = useState(false),
|
|
35
37
|
_useState2 = _slicedToArray(_useState, 2),
|
|
36
38
|
closed = _useState2[0],
|
|
@@ -41,7 +43,7 @@ export var WrapperTypeAhead = /*#__PURE__*/React.memo(function (_ref) {
|
|
|
41
43
|
setQuery = _useState4[1];
|
|
42
44
|
var queryRef = useRef(query);
|
|
43
45
|
var editorViewRef = useRef(editorView);
|
|
44
|
-
var items = useLoadItems(triggerHandler, editorView, query, showMoreOptionsButton, api);
|
|
46
|
+
var items = useLoadItems(triggerHandler, editorView, query, showMoreOptionsButton, api, intl);
|
|
45
47
|
useEffect(function () {
|
|
46
48
|
if (!closed && fg('platform_editor_ease_of_use_metrics')) {
|
|
47
49
|
var _api$metrics;
|