@atlaskit/editor-plugin-type-ahead 10.2.2 → 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 +20 -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
|
@@ -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;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
3
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
4
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
5
|
+
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
6
|
+
export var buildSectionedResult = function buildSectionedResult(_ref) {
|
|
7
|
+
var _triggerHandler$getSe;
|
|
8
|
+
var items = _ref.items,
|
|
9
|
+
triggerHandler = _ref.triggerHandler,
|
|
10
|
+
intl = _ref.intl;
|
|
11
|
+
if (!editorExperiment('platform_editor_agent_mentions', true) || !intl) {
|
|
12
|
+
return {
|
|
13
|
+
items: items,
|
|
14
|
+
sections: []
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
var sectionDefinitions = (_triggerHandler$getSe = triggerHandler.getSections) === null || _triggerHandler$getSe === void 0 ? void 0 : _triggerHandler$getSe.call(triggerHandler, {
|
|
18
|
+
intl: intl
|
|
19
|
+
});
|
|
20
|
+
if (!sectionDefinitions || sectionDefinitions.length === 0) {
|
|
21
|
+
return {
|
|
22
|
+
items: items,
|
|
23
|
+
sections: []
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Track which item indexes have been claimed by a section, or excluded (matched a section but
|
|
28
|
+
// cut by that section's limit). Items excluded by limit should not appear anywhere in the output.
|
|
29
|
+
var assignedToSection = new Set();
|
|
30
|
+
var excludedByLimit = new Set();
|
|
31
|
+
var groupedBySection = new Map();
|
|
32
|
+
var _iterator = _createForOfIteratorHelper(sectionDefinitions),
|
|
33
|
+
_step;
|
|
34
|
+
try {
|
|
35
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
36
|
+
var section = _step.value;
|
|
37
|
+
var matchingIndexes = [];
|
|
38
|
+
for (var _i = 0; _i < items.length; _i++) {
|
|
39
|
+
if (assignedToSection.has(_i) || excludedByLimit.has(_i)) {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (section.filter(items[_i])) {
|
|
43
|
+
matchingIndexes.push(_i);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
var acceptedIndexes = section.limit !== undefined ? matchingIndexes.slice(0, section.limit) : matchingIndexes;
|
|
47
|
+
var rejectedByLimit = matchingIndexes.slice(acceptedIndexes.length);
|
|
48
|
+
var _iterator3 = _createForOfIteratorHelper(acceptedIndexes),
|
|
49
|
+
_step3;
|
|
50
|
+
try {
|
|
51
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
52
|
+
var _i2 = _step3.value;
|
|
53
|
+
assignedToSection.add(_i2);
|
|
54
|
+
}
|
|
55
|
+
} catch (err) {
|
|
56
|
+
_iterator3.e(err);
|
|
57
|
+
} finally {
|
|
58
|
+
_iterator3.f();
|
|
59
|
+
}
|
|
60
|
+
var _iterator4 = _createForOfIteratorHelper(rejectedByLimit),
|
|
61
|
+
_step4;
|
|
62
|
+
try {
|
|
63
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
64
|
+
var _i3 = _step4.value;
|
|
65
|
+
excludedByLimit.add(_i3);
|
|
66
|
+
}
|
|
67
|
+
} catch (err) {
|
|
68
|
+
_iterator4.e(err);
|
|
69
|
+
} finally {
|
|
70
|
+
_iterator4.f();
|
|
71
|
+
}
|
|
72
|
+
if (acceptedIndexes.length === 0) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
groupedBySection.set(section.id, {
|
|
76
|
+
indexes: acceptedIndexes,
|
|
77
|
+
section: section
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
} catch (err) {
|
|
81
|
+
_iterator.e(err);
|
|
82
|
+
} finally {
|
|
83
|
+
_iterator.f();
|
|
84
|
+
}
|
|
85
|
+
var flattenedItems = [];
|
|
86
|
+
var sections = [];
|
|
87
|
+
var _iterator2 = _createForOfIteratorHelper(sectionDefinitions),
|
|
88
|
+
_step2;
|
|
89
|
+
try {
|
|
90
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
91
|
+
var _section = _step2.value;
|
|
92
|
+
var grouped = groupedBySection.get(_section.id);
|
|
93
|
+
if (!grouped) {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
var startIndex = flattenedItems.length;
|
|
97
|
+
flattenedItems.push.apply(flattenedItems, _toConsumableArray(grouped.indexes.map(function (i) {
|
|
98
|
+
return items[i];
|
|
99
|
+
})));
|
|
100
|
+
var endIndex = flattenedItems.length - 1;
|
|
101
|
+
sections.push({
|
|
102
|
+
endIndex: endIndex,
|
|
103
|
+
id: _section.id,
|
|
104
|
+
startIndex: startIndex,
|
|
105
|
+
title: _section.title
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Append items not claimed by any section and not excluded by a limit
|
|
110
|
+
} catch (err) {
|
|
111
|
+
_iterator2.e(err);
|
|
112
|
+
} finally {
|
|
113
|
+
_iterator2.f();
|
|
114
|
+
}
|
|
115
|
+
for (var i = 0; i < items.length; i++) {
|
|
116
|
+
if (!assignedToSection.has(i) && !excludedByLimit.has(i)) {
|
|
117
|
+
flattenedItems.push(items[i]);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
items: flattenedItems,
|
|
122
|
+
sections: sections
|
|
123
|
+
};
|
|
124
|
+
};
|
|
@@ -5,8 +5,9 @@ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
|
5
5
|
import { clearListError } from '../../pm-plugins/commands/clear-list-error';
|
|
6
6
|
import { updateListError } from '../../pm-plugins/commands/update-list-error';
|
|
7
7
|
import { updateListItem } from '../../pm-plugins/commands/update-list-items';
|
|
8
|
+
import { buildSectionedResult } from './build-sectioned-result';
|
|
8
9
|
var EMPTY_LIST_ITEM = [];
|
|
9
|
-
export var useLoadItems = function useLoadItems(triggerHandler, editorView, query, showViewMore, api) {
|
|
10
|
+
export var useLoadItems = function useLoadItems(triggerHandler, editorView, query, showViewMore, api, intl) {
|
|
10
11
|
var _useState = useState(EMPTY_LIST_ITEM),
|
|
11
12
|
_useState2 = _slicedToArray(_useState, 2),
|
|
12
13
|
items = _useState2[0],
|
|
@@ -37,7 +38,14 @@ export var useLoadItems = function useLoadItems(triggerHandler, editorView, quer
|
|
|
37
38
|
var 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, {
|
|
38
39
|
editorState: editorView.state
|
|
39
40
|
}) : undefined;
|
|
40
|
-
var
|
|
41
|
+
var rawList = result.length > 0 ? result : emptyItem ? [emptyItem] : EMPTY_LIST_ITEM;
|
|
42
|
+
var _buildSectionedResult = buildSectionedResult({
|
|
43
|
+
items: rawList,
|
|
44
|
+
triggerHandler: triggerHandler,
|
|
45
|
+
intl: intl !== null && intl !== void 0 ? intl : null
|
|
46
|
+
}),
|
|
47
|
+
list = _buildSectionedResult.items,
|
|
48
|
+
sections = _buildSectionedResult.sections;
|
|
41
49
|
if (componentIsMounted.current) {
|
|
42
50
|
setItems(list);
|
|
43
51
|
}
|
|
@@ -47,7 +55,7 @@ export var useLoadItems = function useLoadItems(triggerHandler, editorView, quer
|
|
|
47
55
|
title: 'View more'
|
|
48
56
|
};
|
|
49
57
|
queueMicrotask(function () {
|
|
50
|
-
updateListItem(showViewMore ? list.concat(viewMoreItem) : list)(view.state, view.dispatch);
|
|
58
|
+
updateListItem(showViewMore ? list.concat(viewMoreItem) : list, sections)(view.state, view.dispatch);
|
|
51
59
|
});
|
|
52
60
|
}).catch(function (e) {
|
|
53
61
|
if (editorExperiment('platform_editor_offline_editing_web', true)) {
|
|
@@ -65,7 +73,7 @@ export var useLoadItems = function useLoadItems(triggerHandler, editorView, quer
|
|
|
65
73
|
// ignore because EditorView is mutable but we don't want to
|
|
66
74
|
// call loadItems when it changes, only when the query changes
|
|
67
75
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
68
|
-
}, [triggerHandler, query]);
|
|
76
|
+
}, [triggerHandler, query, intl]);
|
|
69
77
|
useEffect(function () {
|
|
70
78
|
return function () {
|
|
71
79
|
componentIsMounted.current = false;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import type { Command, TypeAheadItem } from '@atlaskit/editor-common/types';
|
|
2
|
-
|
|
2
|
+
import type { TypeAheadResolvedSection } from '../../types';
|
|
3
|
+
export declare const updateListItem: (items: Array<TypeAheadItem>, sections?: Array<TypeAheadResolvedSection>) => Command;
|
|
@@ -35,11 +35,18 @@ export type TypeAheadPluginState = {
|
|
|
35
35
|
* If true, removes the trigger character from query when typeahead is closed
|
|
36
36
|
*/
|
|
37
37
|
removePrefixTriggerOnCancel?: boolean;
|
|
38
|
+
sections: Array<TypeAheadResolvedSection>;
|
|
38
39
|
selectedIndex: number;
|
|
39
40
|
stats: TypeAheadStatsSerializable | null;
|
|
40
41
|
triggerHandler?: TypeAheadHandler;
|
|
41
42
|
typeAheadHandlers: Array<TypeAheadHandler>;
|
|
42
43
|
};
|
|
44
|
+
export type TypeAheadResolvedSection = {
|
|
45
|
+
endIndex: number;
|
|
46
|
+
id: string;
|
|
47
|
+
startIndex: number;
|
|
48
|
+
title: string;
|
|
49
|
+
};
|
|
43
50
|
export type OnInsertSelectedItemProps = {
|
|
44
51
|
index: number;
|
|
45
52
|
mode: SelectItemMode;
|
|
@@ -88,6 +95,7 @@ export interface TypeAheadPluginSharedState {
|
|
|
88
95
|
isOpen: boolean;
|
|
89
96
|
items: Array<TypeAheadItem>;
|
|
90
97
|
query: string;
|
|
98
|
+
sections: Array<TypeAheadResolvedSection>;
|
|
91
99
|
selectedIndex: number;
|
|
92
100
|
triggerHandler?: TypeAheadHandler;
|
|
93
101
|
}
|