@atlaskit/editor-plugin-type-ahead 14.0.1 → 14.0.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 +8 -0
- package/dist/cjs/ui/registered-menu/RegisteredTypeAheadMenu.compiled.css +6 -0
- package/dist/cjs/ui/registered-menu/RegisteredTypeAheadMenu.js +62 -45
- package/dist/cjs/ui/registered-menu/TypeAheadItemRow.js +7 -5
- package/dist/cjs/ui/registered-menu/TypeAheadMenuFooter.compiled.css +3 -0
- package/dist/cjs/ui/registered-menu/TypeAheadMenuFooter.js +30 -0
- package/dist/cjs/ui/registered-menu/TypeAheadMenuRenderer.js +141 -0
- package/dist/cjs/ui/registered-menu/TypeAheadSectionRow.js +15 -0
- package/dist/cjs/ui/registered-menu/buildTypeAheadMenuModel.js +34 -16
- package/dist/cjs/ui/registered-menu/createTypeAheadRowRenderer.js +62 -0
- package/dist/cjs/ui/registered-menu/getTypeAheadGlobalViewMoreId.js +9 -0
- package/dist/cjs/ui/registered-menu/quick-insert/TypeAheadQuickInsertItem.js +7 -11
- package/dist/es2019/ui/registered-menu/RegisteredTypeAheadMenu.compiled.css +6 -0
- package/dist/es2019/ui/registered-menu/RegisteredTypeAheadMenu.js +47 -37
- package/dist/es2019/ui/registered-menu/TypeAheadItemRow.js +7 -5
- package/dist/es2019/ui/registered-menu/TypeAheadMenuFooter.compiled.css +3 -0
- package/dist/es2019/ui/registered-menu/TypeAheadMenuFooter.js +22 -0
- package/dist/es2019/ui/registered-menu/TypeAheadMenuRenderer.js +109 -0
- package/dist/es2019/ui/registered-menu/TypeAheadSectionRow.js +9 -0
- package/dist/es2019/ui/registered-menu/buildTypeAheadMenuModel.js +29 -8
- package/dist/es2019/ui/registered-menu/createTypeAheadRowRenderer.js +54 -0
- package/dist/es2019/ui/registered-menu/getTypeAheadGlobalViewMoreId.js +1 -0
- package/dist/es2019/ui/registered-menu/quick-insert/TypeAheadQuickInsertItem.js +5 -6
- package/dist/esm/ui/registered-menu/RegisteredTypeAheadMenu.compiled.css +6 -0
- package/dist/esm/ui/registered-menu/RegisteredTypeAheadMenu.js +62 -45
- package/dist/esm/ui/registered-menu/TypeAheadItemRow.js +7 -5
- package/dist/esm/ui/registered-menu/TypeAheadMenuFooter.compiled.css +3 -0
- package/dist/esm/ui/registered-menu/TypeAheadMenuFooter.js +23 -0
- package/dist/esm/ui/registered-menu/TypeAheadMenuRenderer.js +132 -0
- package/dist/esm/ui/registered-menu/TypeAheadSectionRow.js +8 -0
- package/dist/esm/ui/registered-menu/buildTypeAheadMenuModel.js +33 -16
- package/dist/esm/ui/registered-menu/createTypeAheadRowRenderer.js +55 -0
- package/dist/esm/ui/registered-menu/getTypeAheadGlobalViewMoreId.js +3 -0
- package/dist/esm/ui/registered-menu/quick-insert/TypeAheadQuickInsertItem.js +7 -10
- package/dist/types/ui/registered-menu/RegisteredTypeAheadMenu.d.ts +2 -1
- package/dist/types/ui/registered-menu/TypeAheadItemRow.d.ts +2 -1
- package/dist/types/ui/registered-menu/TypeAheadMenuFooter.d.ts +10 -0
- package/dist/types/ui/registered-menu/TypeAheadMenuRenderer.d.ts +15 -0
- package/dist/types/ui/registered-menu/TypeAheadSectionRow.d.ts +5 -0
- package/dist/types/ui/registered-menu/buildTypeAheadMenuModel.d.ts +5 -3
- package/dist/types/ui/registered-menu/createTypeAheadRowRenderer.d.ts +13 -0
- package/dist/types/ui/registered-menu/getTypeAheadGlobalViewMoreId.d.ts +1 -0
- package/dist/types/ui/registered-menu/quick-insert/TypeAheadQuickInsertItem.d.ts +1 -1
- package/dist/types/ui/registered-menu/typeAheadMenuTypes.d.ts +0 -1
- package/package.json +4 -2
|
@@ -1,21 +1,30 @@
|
|
|
1
|
+
/* RegisteredTypeAheadMenu.tsx generated by @compiled/babel-plugin v2.0.0 */
|
|
2
|
+
import "./RegisteredTypeAheadMenu.compiled.css";
|
|
3
|
+
import { ax, ix } from "@compiled/react/runtime";
|
|
1
4
|
import React, { useCallback, useId, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
-
import {
|
|
5
|
+
import { isSectionOverflowItemKey } from '@atlaskit/editor-common/type-ahead-is-section-overflow-item-key';
|
|
3
6
|
import { Popup } from '@atlaskit/editor-common/ui';
|
|
4
7
|
import { akEditorFloatingDialogZIndex } from '@atlaskit/editor-shared-styles/constants';
|
|
5
8
|
import { Box } from '@atlaskit/primitives/compiled';
|
|
6
9
|
import { InputQuery } from '../InputQuery';
|
|
7
10
|
import { buildTypeAheadMenuModel } from './buildTypeAheadMenuModel';
|
|
11
|
+
import { getTypeAheadGlobalViewMoreId } from './getTypeAheadGlobalViewMoreId';
|
|
8
12
|
import { getTypeAheadItemId } from './getTypeAheadItemId';
|
|
9
|
-
import {
|
|
10
|
-
import { TypeAheadItemRow } from './TypeAheadItemRow';
|
|
13
|
+
import { TypeAheadMenuRenderer } from './TypeAheadMenuRenderer';
|
|
11
14
|
import { TypeAheadProvider } from './TypeAheadProvider';
|
|
15
|
+
const styles = {
|
|
16
|
+
menu: "_2rko12b0 _1reo15vq _18m915vq _1rjc1b66 _bfhk1bhr _16qs130s _1bsb5x59"
|
|
17
|
+
};
|
|
18
|
+
const DEFAULT_MENU_MAX_HEIGHT = 520;
|
|
12
19
|
const POPUP_OFFSET = [0, 8];
|
|
20
|
+
const SECTION_OVERFLOW_LIMIT = 30;
|
|
13
21
|
export const RegisteredTypeAheadMenu = ({
|
|
14
22
|
anchorElement,
|
|
15
23
|
api,
|
|
16
24
|
cancel,
|
|
17
25
|
editorView,
|
|
18
26
|
forceFocus,
|
|
27
|
+
maxHeight = DEFAULT_MENU_MAX_HEIGHT,
|
|
19
28
|
onClose,
|
|
20
29
|
onUndoRedo,
|
|
21
30
|
popupsBoundariesElement,
|
|
@@ -27,8 +36,6 @@ export const RegisteredTypeAheadMenu = ({
|
|
|
27
36
|
surface,
|
|
28
37
|
triggerHandler
|
|
29
38
|
}) => {
|
|
30
|
-
var _model$root$component, _model$root;
|
|
31
|
-
const intl = useIntl();
|
|
32
39
|
const generatedId = useId();
|
|
33
40
|
const listId = `${surface.listIdPrefix}-${generatedId}`;
|
|
34
41
|
const menuRef = useRef(null);
|
|
@@ -37,36 +44,44 @@ export const RegisteredTypeAheadMenu = ({
|
|
|
37
44
|
var _api$uiControlRegistr, _api$uiControlRegistr2;
|
|
38
45
|
return (_api$uiControlRegistr = api === null || api === void 0 ? void 0 : (_api$uiControlRegistr2 = api.uiControlRegistry) === null || _api$uiControlRegistr2 === void 0 ? void 0 : _api$uiControlRegistr2.actions.getComponents(surface.root.key)) !== null && _api$uiControlRegistr !== void 0 ? _api$uiControlRegistr : [];
|
|
39
46
|
}, [api, surface.root.key]);
|
|
40
|
-
const
|
|
41
|
-
const itemKeySignature = model.items.map(({
|
|
47
|
+
const hasSectionOverflowItems = useMemo(() => components.some(({
|
|
42
48
|
key
|
|
43
|
-
}) => key)
|
|
49
|
+
}) => isSectionOverflowItemKey(key)), [components]);
|
|
50
|
+
const menuModel = useMemo(() => buildTypeAheadMenuModel(components, surface.root, hasSectionOverflowItems ? SECTION_OVERFLOW_LIMIT : undefined), [components, hasSectionOverflowItems, surface.root]);
|
|
51
|
+
const rows = useMemo(() => menuModel.sections.flat(), [menuModel.sections]);
|
|
52
|
+
const selectableRowIndexes = useMemo(() => rows.flatMap((registration, rowIndex) => registration.type === 'menu-item' ? [rowIndex] : []), [rows]);
|
|
53
|
+
const selectableRowKeys = selectableRowIndexes.map(index => {
|
|
54
|
+
var _rows$index;
|
|
55
|
+
return (_rows$index = rows[index]) === null || _rows$index === void 0 ? void 0 : _rows$index.key;
|
|
56
|
+
}).join(',');
|
|
57
|
+
const selectableItemCount = selectableRowIndexes.length + (menuModel.footer ? 1 : 0);
|
|
44
58
|
useLayoutEffect(() => {
|
|
45
|
-
setSelectedItemIndex(
|
|
46
|
-
}, [
|
|
59
|
+
setSelectedItemIndex(selectableItemCount > 0 ? 0 : -1);
|
|
60
|
+
}, [query, selectableItemCount, selectableRowKeys]);
|
|
47
61
|
const selectActiveItem = useCallback(_mode => {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
62
|
+
const rowIndex = selectableRowIndexes[selectedItemIndex];
|
|
63
|
+
const selectedId = rowIndex !== undefined ? getTypeAheadItemId(listId, rowIndex) : menuModel.footer && selectedItemIndex === selectableRowIndexes.length ? getTypeAheadGlobalViewMoreId(listId) : undefined;
|
|
64
|
+
if (selectedId) {
|
|
65
|
+
var _menuRef$current, _menuRef$current$owne;
|
|
66
|
+
(_menuRef$current = menuRef.current) === null || _menuRef$current === void 0 ? void 0 : (_menuRef$current$owne = _menuRef$current.ownerDocument.getElementById(selectedId)) === null || _menuRef$current$owne === void 0 ? void 0 : _menuRef$current$owne.click();
|
|
51
67
|
}
|
|
52
|
-
|
|
53
|
-
}, [listId, selectedItemIndex]);
|
|
68
|
+
}, [listId, menuModel.footer, selectableRowIndexes, selectedItemIndex]);
|
|
54
69
|
const selectNextItem = useCallback(() => {
|
|
55
70
|
setSelectedItemIndex(currentIndex => {
|
|
56
|
-
if (
|
|
71
|
+
if (selectableItemCount === 0) {
|
|
57
72
|
return -1;
|
|
58
73
|
}
|
|
59
|
-
return currentIndex < 0 || currentIndex ===
|
|
74
|
+
return currentIndex < 0 || currentIndex === selectableItemCount - 1 ? 0 : currentIndex + 1;
|
|
60
75
|
});
|
|
61
|
-
}, [
|
|
76
|
+
}, [selectableItemCount]);
|
|
62
77
|
const selectPreviousItem = useCallback(() => {
|
|
63
78
|
setSelectedItemIndex(currentIndex => {
|
|
64
|
-
if (
|
|
79
|
+
if (selectableItemCount === 0) {
|
|
65
80
|
return -1;
|
|
66
81
|
}
|
|
67
|
-
return currentIndex <= 0 ?
|
|
82
|
+
return currentIndex <= 0 ? selectableItemCount - 1 : currentIndex - 1;
|
|
68
83
|
});
|
|
69
|
-
}, [
|
|
84
|
+
}, [selectableItemCount]);
|
|
70
85
|
const typeAheadContextValue = useMemo(() => ({
|
|
71
86
|
api,
|
|
72
87
|
editorView,
|
|
@@ -76,10 +91,9 @@ export const RegisteredTypeAheadMenu = ({
|
|
|
76
91
|
triggerHandler
|
|
77
92
|
}), [api, editorView, onClose, query, surface.inputMethod, triggerHandler]);
|
|
78
93
|
const noOp = useCallback(() => {}, []);
|
|
79
|
-
const RootComponent = (_model$root$component = (_model$root = model.root) === null || _model$root === void 0 ? void 0 : _model$root.component) !== null && _model$root$component !== void 0 ? _model$root$component : PassThrough;
|
|
80
94
|
const SurfaceProvider = surface.Provider;
|
|
81
95
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(InputQuery, {
|
|
82
|
-
activeDescendantId: selectedItemIndex
|
|
96
|
+
activeDescendantId: selectableRowIndexes[selectedItemIndex] !== undefined ? getTypeAheadItemId(listId, selectableRowIndexes[selectedItemIndex]) : menuModel.footer && selectedItemIndex === selectableRowIndexes.length ? getTypeAheadGlobalViewMoreId(listId) : undefined,
|
|
83
97
|
cancel: cancel,
|
|
84
98
|
editorView: editorView,
|
|
85
99
|
forceFocus: forceFocus,
|
|
@@ -88,7 +102,7 @@ export const RegisteredTypeAheadMenu = ({
|
|
|
88
102
|
onQueryChange: setQuery,
|
|
89
103
|
onQueryFocus: noOp,
|
|
90
104
|
onUndoRedo: onUndoRedo,
|
|
91
|
-
optionCount:
|
|
105
|
+
optionCount: selectableItemCount,
|
|
92
106
|
reopenQuery: reopenQuery,
|
|
93
107
|
selectNextItem: selectNextItem,
|
|
94
108
|
selectPreviousItem: selectPreviousItem,
|
|
@@ -97,7 +111,8 @@ export const RegisteredTypeAheadMenu = ({
|
|
|
97
111
|
}), /*#__PURE__*/React.createElement(Popup, {
|
|
98
112
|
ariaLabel: null,
|
|
99
113
|
boundariesElement: popupsBoundariesElement,
|
|
100
|
-
|
|
114
|
+
fitHeight: maxHeight,
|
|
115
|
+
fitWidth: 340,
|
|
101
116
|
mountTo: popupsMountPoint,
|
|
102
117
|
offset: POPUP_OFFSET,
|
|
103
118
|
preventOverflow: true,
|
|
@@ -106,22 +121,17 @@ export const RegisteredTypeAheadMenu = ({
|
|
|
106
121
|
zIndex: akEditorFloatingDialogZIndex
|
|
107
122
|
}, /*#__PURE__*/React.createElement(Box, {
|
|
108
123
|
ref: menuRef,
|
|
109
|
-
backgroundColor: "elevation.surface.overlay",
|
|
110
124
|
"data-registered-type-ahead-menu": "",
|
|
111
|
-
|
|
125
|
+
xcss: styles.menu
|
|
112
126
|
}, /*#__PURE__*/React.createElement(TypeAheadProvider, {
|
|
113
127
|
value: typeAheadContextValue
|
|
114
|
-
}, /*#__PURE__*/React.createElement(SurfaceProvider, null, /*#__PURE__*/React.createElement(
|
|
115
|
-
"aria-label": intl.formatMessage(surface.listLabel),
|
|
116
|
-
id: listId,
|
|
117
|
-
role: "listbox"
|
|
118
|
-
}, model.items.map((registration, itemIndex) => /*#__PURE__*/React.createElement(TypeAheadItemRow, {
|
|
119
|
-
isSelected: selectedItemIndex === itemIndex,
|
|
120
|
-
itemIndex: itemIndex,
|
|
128
|
+
}, /*#__PURE__*/React.createElement(SurfaceProvider, null, /*#__PURE__*/React.createElement(TypeAheadMenuRenderer, {
|
|
121
129
|
Item: surface.Item,
|
|
122
|
-
|
|
130
|
+
listLabel: surface.listLabel,
|
|
123
131
|
listId: listId,
|
|
132
|
+
maxHeight: maxHeight,
|
|
133
|
+
model: menuModel,
|
|
124
134
|
onItemHover: setSelectedItemIndex,
|
|
125
|
-
|
|
126
|
-
}))))))
|
|
135
|
+
selectedItemIndex: selectedItemIndex
|
|
136
|
+
}))))));
|
|
127
137
|
};
|
|
@@ -6,13 +6,15 @@ export const TypeAheadItemRow = ({
|
|
|
6
6
|
Item,
|
|
7
7
|
listId,
|
|
8
8
|
onItemHover,
|
|
9
|
-
registration
|
|
9
|
+
registration,
|
|
10
|
+
rowIndex
|
|
10
11
|
}) => {
|
|
11
12
|
const onMouseMove = useCallback(() => onItemHover(itemIndex), [itemIndex, onItemHover]);
|
|
12
|
-
return /*#__PURE__*/React.createElement(
|
|
13
|
-
|
|
13
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
14
|
+
onMouseMove: onMouseMove
|
|
15
|
+
}, /*#__PURE__*/React.createElement(Item, {
|
|
16
|
+
id: getTypeAheadItemId(listId, rowIndex),
|
|
14
17
|
isSelected: isSelected,
|
|
15
|
-
onMouseMove: onMouseMove,
|
|
16
18
|
registration: registration
|
|
17
|
-
});
|
|
19
|
+
}));
|
|
18
20
|
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/* TypeAheadMenuFooter.tsx generated by @compiled/babel-plugin v2.0.0 */
|
|
2
|
+
import "./TypeAheadMenuFooter.compiled.css";
|
|
3
|
+
import { ax, ix } from "@compiled/react/runtime";
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { Box } from '@atlaskit/primitives/compiled';
|
|
6
|
+
const styles = {
|
|
7
|
+
footer: "_1rjc1b66 _1i531l7x _15a5nqa1 _uwhke4h9"
|
|
8
|
+
};
|
|
9
|
+
export const TypeAheadMenuFooter = ({
|
|
10
|
+
id,
|
|
11
|
+
isSelected,
|
|
12
|
+
Item,
|
|
13
|
+
onMouseMove,
|
|
14
|
+
registration
|
|
15
|
+
}) => /*#__PURE__*/React.createElement(Box, {
|
|
16
|
+
onMouseMove: onMouseMove,
|
|
17
|
+
xcss: styles.footer
|
|
18
|
+
}, /*#__PURE__*/React.createElement(Item, {
|
|
19
|
+
id: id,
|
|
20
|
+
isSelected: isSelected,
|
|
21
|
+
registration: registration
|
|
22
|
+
}));
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import React, { useCallback, useLayoutEffect, useMemo, useRef } from 'react';
|
|
2
|
+
import { useIntl } from 'react-intl';
|
|
3
|
+
import { CellMeasurerCache } from 'react-virtualized/dist/commonjs/CellMeasurer';
|
|
4
|
+
import { List } from 'react-virtualized/dist/commonjs/List';
|
|
5
|
+
import { typeAheadListMessages } from '@atlaskit/editor-common/type-ahead';
|
|
6
|
+
import { Box, Text } from '@atlaskit/primitives/compiled';
|
|
7
|
+
import { createTypeAheadRowRenderer } from './createTypeAheadRowRenderer';
|
|
8
|
+
import { getTypeAheadGlobalViewMoreId } from './getTypeAheadGlobalViewMoreId';
|
|
9
|
+
import { PassThrough } from './PassThrough';
|
|
10
|
+
import { TypeAheadMenuFooter } from './TypeAheadMenuFooter';
|
|
11
|
+
const LIST_WIDTH = 340;
|
|
12
|
+
const ESTIMATED_ROW_HEIGHT = 56;
|
|
13
|
+
const MENU_FOOTER_HEIGHT = 48;
|
|
14
|
+
export const TypeAheadMenuRenderer = ({
|
|
15
|
+
Item,
|
|
16
|
+
listLabel,
|
|
17
|
+
listId,
|
|
18
|
+
maxHeight,
|
|
19
|
+
model,
|
|
20
|
+
onItemHover,
|
|
21
|
+
selectedItemIndex
|
|
22
|
+
}) => {
|
|
23
|
+
var _model$root$component;
|
|
24
|
+
const intl = useIntl();
|
|
25
|
+
const listRef = useRef(null);
|
|
26
|
+
const rows = useMemo(() => model.sections.flat(), [model.sections]);
|
|
27
|
+
const cache = useMemo(() => new CellMeasurerCache({
|
|
28
|
+
defaultHeight: ESTIMATED_ROW_HEIGHT,
|
|
29
|
+
fixedWidth: true
|
|
30
|
+
}), []);
|
|
31
|
+
const itemIndexByRowIndex = useMemo(() => {
|
|
32
|
+
const indexes = new Map();
|
|
33
|
+
let itemIndex = 0;
|
|
34
|
+
rows.forEach((registration, rowIndex) => {
|
|
35
|
+
if (registration.type === 'menu-item') {
|
|
36
|
+
indexes.set(rowIndex, itemIndex++);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
return indexes;
|
|
40
|
+
}, [rows]);
|
|
41
|
+
const selectedRowIndex = useMemo(() => {
|
|
42
|
+
for (const [rowIndex, itemIndex] of itemIndexByRowIndex) {
|
|
43
|
+
if (itemIndex === selectedItemIndex) {
|
|
44
|
+
return rowIndex;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return -1;
|
|
48
|
+
}, [itemIndexByRowIndex, selectedItemIndex]);
|
|
49
|
+
const rowKeySignature = useMemo(() => rows.map(({
|
|
50
|
+
key,
|
|
51
|
+
type
|
|
52
|
+
}) => `${type}:${key}`).join('\0'), [rows]);
|
|
53
|
+
useLayoutEffect(() => {
|
|
54
|
+
var _listRef$current, _listRef$current2;
|
|
55
|
+
cache.clearAll();
|
|
56
|
+
(_listRef$current = listRef.current) === null || _listRef$current === void 0 ? void 0 : _listRef$current.recomputeRowHeights();
|
|
57
|
+
(_listRef$current2 = listRef.current) === null || _listRef$current2 === void 0 ? void 0 : _listRef$current2.scrollToPosition(0);
|
|
58
|
+
}, [cache, rowKeySignature]);
|
|
59
|
+
useLayoutEffect(() => {
|
|
60
|
+
if (selectedRowIndex >= 0) {
|
|
61
|
+
var _listRef$current3;
|
|
62
|
+
(_listRef$current3 = listRef.current) === null || _listRef$current3 === void 0 ? void 0 : _listRef$current3.scrollToRow(selectedRowIndex);
|
|
63
|
+
}
|
|
64
|
+
}, [selectedRowIndex]);
|
|
65
|
+
const renderRow = createTypeAheadRowRenderer({
|
|
66
|
+
cache,
|
|
67
|
+
itemIndexByRowIndex,
|
|
68
|
+
Item,
|
|
69
|
+
listId,
|
|
70
|
+
onItemHover,
|
|
71
|
+
rows,
|
|
72
|
+
selectedItemIndex
|
|
73
|
+
});
|
|
74
|
+
const footerItemIndex = itemIndexByRowIndex.size;
|
|
75
|
+
const onFooterItemHover = useCallback(() => onItemHover(footerItemIndex), [footerItemIndex, onItemHover]);
|
|
76
|
+
if (!model.root) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
const RootComponent = (_model$root$component = model.root.component) !== null && _model$root$component !== void 0 ? _model$root$component : PassThrough;
|
|
80
|
+
const listMaxHeight = Math.max(0, maxHeight - (model.footer ? MENU_FOOTER_HEIGHT : 0));
|
|
81
|
+
return /*#__PURE__*/React.createElement(RootComponent, null, /*#__PURE__*/React.createElement(Box, {
|
|
82
|
+
"aria-label": intl.formatMessage(listLabel),
|
|
83
|
+
id: listId,
|
|
84
|
+
role: "listbox"
|
|
85
|
+
}, rows.length === 0 ? /*#__PURE__*/React.createElement(Box, {
|
|
86
|
+
paddingBlock: "space.150",
|
|
87
|
+
paddingInline: "space.250"
|
|
88
|
+
}, /*#__PURE__*/React.createElement(Text, {
|
|
89
|
+
align: "center",
|
|
90
|
+
as: "p"
|
|
91
|
+
}, intl.formatMessage(typeAheadListMessages.emptySearchResults))) : /*#__PURE__*/React.createElement(List, {
|
|
92
|
+
containerRole: "presentation",
|
|
93
|
+
height: Math.min(rows.length * ESTIMATED_ROW_HEIGHT, listMaxHeight),
|
|
94
|
+
overscanRowCount: 3,
|
|
95
|
+
ref: listRef,
|
|
96
|
+
role: "presentation",
|
|
97
|
+
rowCount: rows.length,
|
|
98
|
+
rowHeight: cache.rowHeight,
|
|
99
|
+
rowRenderer: renderRow,
|
|
100
|
+
scrollToAlignment: "auto",
|
|
101
|
+
width: LIST_WIDTH
|
|
102
|
+
}), model.footer && /*#__PURE__*/React.createElement(TypeAheadMenuFooter, {
|
|
103
|
+
id: getTypeAheadGlobalViewMoreId(listId),
|
|
104
|
+
isSelected: selectedItemIndex === footerItemIndex,
|
|
105
|
+
Item: Item,
|
|
106
|
+
onMouseMove: onFooterItemHover,
|
|
107
|
+
registration: model.footer
|
|
108
|
+
})));
|
|
109
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { PassThrough } from './PassThrough';
|
|
3
|
+
export const TypeAheadSectionRow = ({
|
|
4
|
+
registration
|
|
5
|
+
}) => {
|
|
6
|
+
var _registration$compone;
|
|
7
|
+
const Component = (_registration$compone = registration.component) !== null && _registration$compone !== void 0 ? _registration$compone : PassThrough;
|
|
8
|
+
return /*#__PURE__*/React.createElement(Component, null, null);
|
|
9
|
+
};
|
|
@@ -1,24 +1,45 @@
|
|
|
1
|
+
import { isMenuFooterSectionKey } from '@atlaskit/editor-common/type-ahead-is-menu-footer-section-key';
|
|
2
|
+
import { isSectionOverflowItemKey } from '@atlaskit/editor-common/type-ahead-is-section-overflow-item-key';
|
|
1
3
|
import { resolveSurface, willComponentRender } from '@atlaskit/editor-ui-control-model/surface-renderer';
|
|
2
|
-
export const buildTypeAheadMenuModel = (components, rootComponent) => {
|
|
4
|
+
export const buildTypeAheadMenuModel = (components, rootComponent, sectionOverflowLimit) => {
|
|
3
5
|
const {
|
|
4
6
|
root,
|
|
5
7
|
childrenMap,
|
|
6
8
|
topLevelChildren
|
|
7
9
|
} = resolveSurface(components, rootComponent);
|
|
8
|
-
const
|
|
10
|
+
const sections = [];
|
|
11
|
+
let footer;
|
|
9
12
|
for (const section of topLevelChildren !== null && topLevelChildren !== void 0 ? topLevelChildren : []) {
|
|
13
|
+
var _childrenMap$get;
|
|
10
14
|
if (section.type !== 'menu-section' || !willComponentRender(section, childrenMap)) {
|
|
11
15
|
continue;
|
|
12
16
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
const children = (_childrenMap$get = childrenMap.get(section.key)) !== null && _childrenMap$get !== void 0 ? _childrenMap$get : [];
|
|
18
|
+
if (isMenuFooterSectionKey(section.key)) {
|
|
19
|
+
footer = children.find(child => child.type === 'menu-item' && willComponentRender(child, childrenMap));
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
let viewMoreItem;
|
|
23
|
+
for (let index = children.length - 1; index >= 0; index--) {
|
|
24
|
+
const child = children[index];
|
|
25
|
+
if ((child === null || child === void 0 ? void 0 : child.type) === 'menu-item' && isSectionOverflowItemKey(child.key) && willComponentRender(child, childrenMap)) {
|
|
26
|
+
viewMoreItem = child;
|
|
27
|
+
break;
|
|
17
28
|
}
|
|
18
29
|
}
|
|
30
|
+
const items = children.filter(child => child.type === 'menu-item' && !isSectionOverflowItemKey(child.key) && willComponentRender(child, childrenMap));
|
|
31
|
+
if (items.length === 0) {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (sectionOverflowLimit !== undefined && viewMoreItem !== undefined && items.length > sectionOverflowLimit) {
|
|
35
|
+
sections.push([section, ...items.slice(0, sectionOverflowLimit), viewMoreItem]);
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
sections.push([section, ...items]);
|
|
19
39
|
}
|
|
20
40
|
return {
|
|
21
|
-
|
|
22
|
-
root
|
|
41
|
+
footer,
|
|
42
|
+
root,
|
|
43
|
+
sections
|
|
23
44
|
};
|
|
24
45
|
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { CellMeasurer } from 'react-virtualized/dist/commonjs/CellMeasurer';
|
|
3
|
+
import { ListRow } from '../ListRow';
|
|
4
|
+
import { TypeAheadItemRow } from './TypeAheadItemRow';
|
|
5
|
+
import { TypeAheadSectionRow } from './TypeAheadSectionRow';
|
|
6
|
+
const noOp = () => {};
|
|
7
|
+
export const createTypeAheadRowRenderer = ({
|
|
8
|
+
cache,
|
|
9
|
+
itemIndexByRowIndex,
|
|
10
|
+
Item,
|
|
11
|
+
listId,
|
|
12
|
+
onItemHover,
|
|
13
|
+
rows,
|
|
14
|
+
selectedItemIndex
|
|
15
|
+
}) => ({
|
|
16
|
+
index,
|
|
17
|
+
key,
|
|
18
|
+
parent,
|
|
19
|
+
style,
|
|
20
|
+
isScrolling,
|
|
21
|
+
isVisible
|
|
22
|
+
}) => {
|
|
23
|
+
const registration = rows[index];
|
|
24
|
+
if (!registration) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
const itemIndex = itemIndexByRowIndex.get(index);
|
|
28
|
+
return /*#__PURE__*/React.createElement(CellMeasurer, {
|
|
29
|
+
key: key,
|
|
30
|
+
cache: cache,
|
|
31
|
+
parent: parent,
|
|
32
|
+
columnIndex: 0,
|
|
33
|
+
rowIndex: index
|
|
34
|
+
}, ({
|
|
35
|
+
measure
|
|
36
|
+
}) => /*#__PURE__*/React.createElement(ListRow, {
|
|
37
|
+
index: index,
|
|
38
|
+
isScrolling: isScrolling,
|
|
39
|
+
isVisible: isVisible,
|
|
40
|
+
measure: measure,
|
|
41
|
+
onMouseMove: noOp,
|
|
42
|
+
style: style
|
|
43
|
+
}, registration.type === 'menu-section' ? /*#__PURE__*/React.createElement(TypeAheadSectionRow, {
|
|
44
|
+
registration: registration
|
|
45
|
+
}) : /*#__PURE__*/React.createElement(TypeAheadItemRow, {
|
|
46
|
+
Item: Item,
|
|
47
|
+
isSelected: itemIndex === selectedItemIndex,
|
|
48
|
+
itemIndex: itemIndex !== null && itemIndex !== void 0 ? itemIndex : 0,
|
|
49
|
+
listId: listId,
|
|
50
|
+
onItemHover: onItemHover,
|
|
51
|
+
registration: registration,
|
|
52
|
+
rowIndex: index
|
|
53
|
+
})));
|
|
54
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const getTypeAheadGlobalViewMoreId = listId => `${listId}-view-all`;
|
|
@@ -5,20 +5,19 @@ import { PassThrough } from '../PassThrough';
|
|
|
5
5
|
export const TypeAheadQuickInsertItem = ({
|
|
6
6
|
id,
|
|
7
7
|
isSelected,
|
|
8
|
-
onMouseMove,
|
|
9
8
|
registration
|
|
10
9
|
}) => {
|
|
11
10
|
var _registration$compone;
|
|
12
11
|
const quickInsertContext = useQuickInsertContext();
|
|
13
12
|
const Component = (_registration$compone = registration.component) !== null && _registration$compone !== void 0 ? _registration$compone : PassThrough;
|
|
14
13
|
const contextValue = useMemo(() => ({
|
|
15
|
-
|
|
14
|
+
editorView: quickInsertContext.editorView,
|
|
16
15
|
item: {
|
|
17
16
|
id,
|
|
18
|
-
isSelected
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}), [id, isSelected,
|
|
17
|
+
isSelected
|
|
18
|
+
},
|
|
19
|
+
select: quickInsertContext.select
|
|
20
|
+
}), [id, isSelected, quickInsertContext]);
|
|
22
21
|
return /*#__PURE__*/React.createElement(QuickInsertProvider, {
|
|
23
22
|
value: contextValue
|
|
24
23
|
}, /*#__PURE__*/React.createElement(Component, null, null));
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
._2rko12b0{border-radius:var(--ds-radius-small,4px)}
|
|
2
|
+
._1rjc1b66{padding-block:var(--ds-space-050,4px)}._16qs130s{box-shadow:var(--ds-shadow-overlay,0 8px 9pt #1e1f2126,0 0 1px #1e1f214f)}
|
|
3
|
+
._18m915vq{overflow-y:hidden}
|
|
4
|
+
._1bsb5x59{width:340px}
|
|
5
|
+
._1reo15vq{overflow-x:hidden}
|
|
6
|
+
._bfhk1bhr{background-color:var(--ds-surface-overlay,#fff)}
|