@atlaskit/editor-plugin-insert-block 30.0.4 → 31.0.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.
Files changed (29) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/cjs/ui/ToolbarInsertBlock/block-insert-element-browser.js +2 -2
  3. package/dist/cjs/ui/registered-insert-menu/RegisteredInsertButton.js +2 -2
  4. package/dist/cjs/ui/registered-insert-menu/RegisteredInsertMenu.compiled.css +1 -0
  5. package/dist/cjs/ui/registered-insert-menu/RegisteredInsertMenu.js +113 -238
  6. package/dist/cjs/ui/registered-insert-menu/RegisteredInsertMenuContent.js +1 -4
  7. package/dist/es2019/ui/ToolbarInsertBlock/block-insert-element-browser.js +1 -1
  8. package/dist/es2019/ui/registered-insert-menu/RegisteredInsertButton.js +1 -1
  9. package/dist/es2019/ui/registered-insert-menu/RegisteredInsertMenu.compiled.css +1 -0
  10. package/dist/es2019/ui/registered-insert-menu/RegisteredInsertMenu.js +97 -204
  11. package/dist/es2019/ui/registered-insert-menu/RegisteredInsertMenuContent.js +1 -4
  12. package/dist/esm/ui/ToolbarInsertBlock/block-insert-element-browser.js +1 -1
  13. package/dist/esm/ui/registered-insert-menu/RegisteredInsertButton.js +1 -1
  14. package/dist/esm/ui/registered-insert-menu/RegisteredInsertMenu.compiled.css +1 -0
  15. package/dist/esm/ui/registered-insert-menu/RegisteredInsertMenu.js +115 -240
  16. package/dist/esm/ui/registered-insert-menu/RegisteredInsertMenuContent.js +1 -4
  17. package/dist/types/ui/registered-insert-menu/RegisteredInsertMenu.d.ts +5 -7
  18. package/package.json +31 -31
  19. package/dist/cjs/ui/registered-insert-menu/RegisteredInsertMenuItem.js +0 -64
  20. package/dist/cjs/ui/registered-insert-menu/RegisteredInsertMenuList.compiled.css +0 -11
  21. package/dist/cjs/ui/registered-insert-menu/RegisteredInsertMenuList.js +0 -324
  22. package/dist/es2019/ui/registered-insert-menu/RegisteredInsertMenuItem.js +0 -54
  23. package/dist/es2019/ui/registered-insert-menu/RegisteredInsertMenuList.compiled.css +0 -11
  24. package/dist/es2019/ui/registered-insert-menu/RegisteredInsertMenuList.js +0 -273
  25. package/dist/esm/ui/registered-insert-menu/RegisteredInsertMenuItem.js +0 -56
  26. package/dist/esm/ui/registered-insert-menu/RegisteredInsertMenuList.compiled.css +0 -11
  27. package/dist/esm/ui/registered-insert-menu/RegisteredInsertMenuList.js +0 -317
  28. package/dist/types/ui/registered-insert-menu/RegisteredInsertMenuItem.d.ts +0 -16
  29. package/dist/types/ui/registered-insert-menu/RegisteredInsertMenuList.d.ts +0 -31
@@ -1,324 +0,0 @@
1
- /* RegisteredInsertMenuList.tsx generated by @compiled/babel-plugin v3.0.2 */
2
- "use strict";
3
-
4
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
5
- var _typeof = require("@babel/runtime/helpers/typeof");
6
- Object.defineProperty(exports, "__esModule", {
7
- value: true
8
- });
9
- exports.RegisteredInsertMenuList = void 0;
10
- require("./RegisteredInsertMenuList.compiled.css");
11
- var _runtime = require("@compiled/react/runtime");
12
- var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
14
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
15
- var _react = _interopRequireWildcard(require("react"));
16
- var _CellMeasurer = require("react-virtualized/dist/commonjs/CellMeasurer");
17
- var _List = require("react-virtualized/dist/commonjs/List");
18
- var _emptyState = require("@atlaskit/editor-common/quick-insert/empty-state");
19
- var _registeredMenuModel = require("@atlaskit/editor-common/quick-insert/registered-menu-model");
20
- var _useMenuListHeight2 = require("@atlaskit/editor-common/quick-insert/use-menu-list-height");
21
- var _box = require("@atlaskit/primitives/compiled/box");
22
- var _RegisteredInsertMenuItem = require("./RegisteredInsertMenuItem");
23
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
24
- 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; } } }; }
25
- 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; } }
26
- 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; } // eslint-disable-next-line @atlaskit/platform/no-barrel-entry-imports
27
- var ESTIMATED_ROW_HEIGHT = 44;
28
- // 44px item + 1px separator.
29
- var MENU_FOOTER_HEIGHT = 45;
30
- var MENU_SEARCH_HEIGHT = 64;
31
- var LIST_WIDTH = 350;
32
- var listAriaProps = {
33
- // @ts-expect-error react-virtualized forwards null to omit its grid-only default; its types exclude null.
34
- 'aria-readonly': null
35
- };
36
- var styles = {
37
- content: "_1e0c1txw _2lx21bp4 _1tkeidpf",
38
- scrollable: "_16jlkb7n _1tkeidpf _18m91wug",
39
- footer: "_1o9zidpf",
40
- footerWithDivider: "_1i531l7x _15a5nqa1 _uwhke4h9 _1o9zidpf",
41
- externalControls: "_1i531l7x _15a5nqa1 _uwhke4h9 _1q51u2gc _85i5u2gc"
42
- };
43
- var RegisteredInsertMenuItemRow = function RegisteredInsertMenuItemRow(_ref) {
44
- var editorView = _ref.editorView,
45
- id = _ref.id,
46
- isOffline = _ref.isOffline,
47
- isSelected = _ref.isSelected,
48
- itemIndex = _ref.itemIndex,
49
- menuOpenId = _ref.menuOpenId,
50
- onClose = _ref.onClose,
51
- onItemFocus = _ref.onItemFocus,
52
- onItemBlur = _ref.onItemBlur,
53
- onItemHover = _ref.onItemHover,
54
- onItemLeave = _ref.onItemLeave,
55
- registration = _ref.registration,
56
- surfaceContext = _ref.surfaceContext;
57
- (0, _react.useLayoutEffect)(function () {
58
- return function () {
59
- return onItemLeave(registration.key);
60
- };
61
- }, [onItemLeave, registration.key]);
62
- var onBlur = (0, _react.useCallback)(function (event) {
63
- if (!event.currentTarget.contains(event.relatedTarget)) {
64
- onItemBlur(registration.key);
65
- }
66
- }, [onItemBlur, registration.key]);
67
- return /*#__PURE__*/_react.default.createElement("div", {
68
- onBlur: onBlur,
69
- onFocus: function onFocus() {
70
- return onItemFocus(itemIndex, registration.key);
71
- },
72
- onMouseLeave: function onMouseLeave() {
73
- return onItemLeave(registration.key);
74
- },
75
- onMouseMove: function onMouseMove() {
76
- return onItemHover(itemIndex, registration.key);
77
- }
78
- }, /*#__PURE__*/_react.default.createElement(_RegisteredInsertMenuItem.RegisteredInsertMenuItem, {
79
- editorView: editorView,
80
- id: id,
81
- isOffline: isOffline,
82
- isSelected: isSelected,
83
- menuOpenId: menuOpenId,
84
- onClose: onClose,
85
- registration: registration,
86
- surfaceContext: surfaceContext
87
- }));
88
- };
89
- var RegisteredInsertMenuList = exports.RegisteredInsertMenuList = function RegisteredInsertMenuList(_ref2) {
90
- var _model$root$component, _model$root;
91
- var editorView = _ref2.editorView,
92
- emptyStateHandler = _ref2.emptyStateHandler,
93
- isOffline = _ref2.isOffline,
94
- listId = _ref2.listId,
95
- listLabel = _ref2.listLabel,
96
- maxHeight = _ref2.maxHeight,
97
- menuOpenId = _ref2.menuOpenId,
98
- model = _ref2.model,
99
- onClose = _ref2.onClose,
100
- onItemFocus = _ref2.onItemFocus,
101
- onItemBlur = _ref2.onItemBlur,
102
- query = _ref2.query,
103
- onItemHover = _ref2.onItemHover,
104
- onItemLeave = _ref2.onItemLeave,
105
- onItemVisibilityChange = _ref2.onItemVisibilityChange,
106
- onRenderedItemsChange = _ref2.onRenderedItemsChange,
107
- selectedItemIndex = _ref2.selectedItemIndex,
108
- surfaceContext = _ref2.surfaceContext,
109
- activePreviewItemKey = _ref2.activePreviewItemKey;
110
- var Root = (_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 : _react.default.Fragment;
111
- var listRef = (0, _react.useRef)(null);
112
- var setListRef = (0, _react.useCallback)(function (list) {
113
- listRef.current = list;
114
- }, []);
115
- var rows = (0, _react.useMemo)(function () {
116
- return (0, _registeredMenuModel.getQuickInsertMenuRows)(model);
117
- }, [model]);
118
- var cache = (0, _react.useMemo)(function () {
119
- return new _CellMeasurer.CellMeasurerCache({
120
- defaultHeight: ESTIMATED_ROW_HEIGHT,
121
- fixedWidth: true
122
- });
123
- }, []);
124
- var itemIndexByRowIndex = (0, _react.useMemo)(function () {
125
- var indexes = new Map();
126
- var itemIndex = 0;
127
- rows.forEach(function (registration, rowIndex) {
128
- if (registration.type === 'menu-item') {
129
- indexes.set(rowIndex, itemIndex++);
130
- }
131
- });
132
- return indexes;
133
- }, [rows]);
134
- var selectedRowIndex = (0, _react.useMemo)(function () {
135
- var _iterator = _createForOfIteratorHelper(itemIndexByRowIndex),
136
- _step;
137
- try {
138
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
139
- var _step$value = (0, _slicedToArray2.default)(_step.value, 2),
140
- rowIndex = _step$value[0],
141
- itemIndex = _step$value[1];
142
- if (itemIndex === selectedItemIndex) {
143
- return rowIndex;
144
- }
145
- }
146
- } catch (err) {
147
- _iterator.e(err);
148
- } finally {
149
- _iterator.f();
150
- }
151
- return -1;
152
- }, [itemIndexByRowIndex, selectedItemIndex]);
153
- var rowKeySignature = (0, _react.useMemo)(function () {
154
- return rows.map(function (_ref3) {
155
- var key = _ref3.key,
156
- type = _ref3.type;
157
- return "".concat(type, ":").concat(key);
158
- }).join('\0');
159
- }, [rows]);
160
- var _useMenuListHeight = (0, _useMenuListHeight2.useMenuListHeight)(cache, rows.length, rowKeySignature),
161
- measuredHeight = _useMenuListHeight.height,
162
- updateHeight = _useMenuListHeight.updateHeight;
163
- (0, _react.useLayoutEffect)(function () {
164
- var _listRef$current, _listRef$current2;
165
- cache.clearAll();
166
- (_listRef$current = listRef.current) === null || _listRef$current === void 0 || _listRef$current.recomputeRowHeights();
167
- (_listRef$current2 = listRef.current) === null || _listRef$current2 === void 0 || _listRef$current2.scrollToPosition(0);
168
- }, [cache, rowKeySignature]);
169
- var onRowsRendered = (0, _react.useCallback)(function (_ref4) {
170
- var _indexes$, _indexes;
171
- var overscanStartIndex = _ref4.overscanStartIndex,
172
- overscanStopIndex = _ref4.overscanStopIndex,
173
- startIndex = _ref4.startIndex,
174
- stopIndex = _ref4.stopIndex;
175
- if (activePreviewItemKey) {
176
- var previewRowIndex = rows.findIndex(function (_ref5) {
177
- var key = _ref5.key;
178
- return key === activePreviewItemKey;
179
- });
180
- if (previewRowIndex < startIndex || previewRowIndex > stopIndex) {
181
- onItemVisibilityChange(activePreviewItemKey, false);
182
- }
183
- }
184
- updateHeight();
185
- var indexes = (0, _toConsumableArray2.default)(itemIndexByRowIndex).filter(function (_ref6) {
186
- var _ref7 = (0, _slicedToArray2.default)(_ref6, 1),
187
- rowIndex = _ref7[0];
188
- return rowIndex >= overscanStartIndex && rowIndex <= overscanStopIndex;
189
- }).map(function (_ref8) {
190
- var _ref9 = (0, _slicedToArray2.default)(_ref8, 2),
191
- itemIndex = _ref9[1];
192
- return itemIndex;
193
- });
194
- onRenderedItemsChange({
195
- startIndex: (_indexes$ = indexes[0]) !== null && _indexes$ !== void 0 ? _indexes$ : -1,
196
- stopIndex: (_indexes = indexes[indexes.length - 1]) !== null && _indexes !== void 0 ? _indexes : -1
197
- });
198
- }, [activePreviewItemKey, itemIndexByRowIndex, onItemVisibilityChange, onRenderedItemsChange, rows, updateHeight]);
199
- var onScrollableContentScroll = (0, _react.useCallback)(function (event) {
200
- if (event.target === event.currentTarget && activePreviewItemKey) {
201
- onItemVisibilityChange(activePreviewItemKey, false);
202
- }
203
- }, [activePreviewItemKey, onItemVisibilityChange]);
204
- var renderRow = (0, _react.useCallback)(function (_ref0) {
205
- var _registration$compone;
206
- var index = _ref0.index,
207
- key = _ref0.key,
208
- parent = _ref0.parent,
209
- style = _ref0.style;
210
- var registration = rows[index];
211
- if (!registration) {
212
- return null;
213
- }
214
- var itemIndex = itemIndexByRowIndex.get(index);
215
- var rowContent = registration.type === 'menu-section' ? ( /*#__PURE__*/_react.default.createElement((_registration$compone = registration.component) !== null && _registration$compone !== void 0 ? _registration$compone : _react.default.Fragment, null, null)) : /*#__PURE__*/_react.default.createElement(RegisteredInsertMenuItemRow, {
216
- editorView: editorView,
217
- id: "".concat(listId, "-").concat(itemIndex),
218
- isOffline: isOffline,
219
- isSelected: itemIndex === selectedItemIndex,
220
- itemIndex: itemIndex !== null && itemIndex !== void 0 ? itemIndex : 0,
221
- menuOpenId: menuOpenId,
222
- onClose: onClose,
223
- onItemFocus: onItemFocus,
224
- onItemBlur: onItemBlur,
225
- onItemHover: onItemHover,
226
- onItemLeave: onItemLeave,
227
- registration: registration,
228
- surfaceContext: surfaceContext
229
- });
230
- return /*#__PURE__*/_react.default.createElement(_CellMeasurer.CellMeasurer, {
231
- key: key,
232
- cache: cache,
233
- parent: parent,
234
- columnIndex: 0,
235
- rowIndex: index
236
- }, function (_ref1) {
237
- var registerChild = _ref1.registerChild;
238
- return /*#__PURE__*/_react.default.createElement("div", {
239
- ref: function ref(element) {
240
- return registerChild === null || registerChild === void 0 ? void 0 : registerChild(element !== null && element !== void 0 ? element : undefined);
241
- }
242
- // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop
243
- ,
244
- style: style
245
- }, /*#__PURE__*/_react.default.createElement(_box.Box, {
246
- paddingBlockEnd: index === rows.length - 1 ? 'space.100' : undefined
247
- }, rowContent));
248
- });
249
- }, [cache, editorView, isOffline, itemIndexByRowIndex, listId, menuOpenId, onClose, onItemFocus, onItemBlur, onItemHover, onItemLeave, rows, selectedItemIndex, surfaceContext]);
250
- var footerItemIndex = itemIndexByRowIndex.size;
251
- var footerItemId = "".concat(listId, "-").concat(footerItemIndex);
252
- var hasExternalControls = model.fallbackItems !== undefined && emptyStateHandler !== undefined;
253
- var hasNoSearchResults = query !== '' && rows.length === 0;
254
- var externalControls = hasExternalControls && emptyStateHandler ? emptyStateHandler({
255
- mode: 'inline',
256
- searchTerm: query,
257
- showNoResultsMessage: false
258
- }) : null;
259
- var showFooterDivider = !hasNoSearchResults || Boolean(externalControls);
260
- var listMaxHeight = Math.max(0, maxHeight - MENU_SEARCH_HEIGHT - (model.footer ? MENU_FOOTER_HEIGHT : 0));
261
- var contentStyle = {
262
- maxHeight: Math.max(0, maxHeight - MENU_SEARCH_HEIGHT)
263
- };
264
- var onFooterItemHover = (0, _react.useCallback)(function () {
265
- return onItemHover(footerItemIndex);
266
- }, [footerItemIndex, onItemHover]);
267
- var onFooterItemFocus = (0, _react.useCallback)(function () {
268
- return onItemFocus(footerItemIndex);
269
- }, [footerItemIndex, onItemFocus]);
270
- var footer = model.footer ? /*#__PURE__*/_react.default.createElement(_box.Box, {
271
- testId: "registered-insert-menu-footer",
272
- xcss: showFooterDivider ? styles.footerWithDivider : styles.footer,
273
- onFocus: onFooterItemFocus,
274
- onMouseMove: onFooterItemHover
275
- }, /*#__PURE__*/_react.default.createElement(_RegisteredInsertMenuItem.RegisteredInsertMenuItem, {
276
- editorView: editorView,
277
- id: footerItemId,
278
- isOffline: isOffline,
279
- isSelected: footerItemIndex === selectedItemIndex,
280
- menuOpenId: menuOpenId,
281
- onClose: onClose,
282
- registration: model.footer,
283
- surfaceContext: surfaceContext
284
- })) : null;
285
- if (!model.root) {
286
- return null;
287
- }
288
- return /*#__PURE__*/_react.default.createElement(Root, null, /*#__PURE__*/_react.default.createElement(_RegisteredInsertMenuItem.RegisteredInsertMenuPreviewContext.Provider, {
289
- value: activePreviewItemKey
290
- }, /*#__PURE__*/_react.default.createElement(_box.Box, {
291
- xcss: styles.content,
292
- style: contentStyle
293
- }, /*#__PURE__*/_react.default.createElement(_box.Box, {
294
- xcss: styles.scrollable,
295
- onScroll: onScrollableContentScroll
296
- }, /*#__PURE__*/_react.default.createElement(_box.Box, {
297
- "aria-label": listLabel,
298
- "aria-owns": model.footer ? footerItemId : undefined,
299
- id: listId,
300
- role: "listbox"
301
- }, rows.length > 0 && /*#__PURE__*/_react.default.createElement(_List.List
302
- // eslint-disable-next-line react/jsx-props-no-spreading -- Omits the library's grid-only ARIA default without declaring it on the group role.
303
- , (0, _extends2.default)({}, listAriaProps, {
304
- tabIndex: null,
305
- containerRole: "presentation",
306
- height: Math.min(measuredHeight, listMaxHeight),
307
- overscanRowCount: 3,
308
- onRowsRendered: onRowsRendered,
309
- ref: setListRef,
310
- role: "group",
311
- rowCount: rows.length,
312
- rowHeight: cache.rowHeight,
313
- rowRenderer: renderRow,
314
- scrollToAlignment: "auto",
315
- scrollToIndex: selectedRowIndex,
316
- width: LIST_WIDTH
317
- }))), hasNoSearchResults && /*#__PURE__*/_react.default.createElement(_emptyState.QuickInsertEmptyState, {
318
- mode: "inline",
319
- spacing: "compact"
320
- }), externalControls && /*#__PURE__*/_react.default.createElement(_box.Box, {
321
- testId: "registered-insert-menu-external-controls",
322
- xcss: styles.externalControls
323
- }, externalControls)), footer)));
324
- };
@@ -1,54 +0,0 @@
1
- import React, { createContext, useCallback, useContext, useMemo } from 'react';
2
- import { INPUT_METHOD } from '@atlaskit/editor-common/analytics/types/enums';
3
- import { insertSelectedItem } from '@atlaskit/editor-common/insert';
4
- import { QuickInsertProvider } from '@atlaskit/editor-common/quick-insert/provider';
5
- // Preview updates must remain live while react-virtualized caches row elements during scrolling.
6
- export const RegisteredInsertMenuPreviewContext = /*#__PURE__*/createContext(undefined);
7
- export const RegisteredInsertMenuItem = ({
8
- editorView,
9
- id,
10
- isOffline,
11
- isSelected,
12
- menuOpenId,
13
- onClose,
14
- registration,
15
- surfaceContext
16
- }) => {
17
- var _registration$compone;
18
- const Component = (_registration$compone = registration.component) !== null && _registration$compone !== void 0 ? _registration$compone : React.Fragment;
19
- const activePreviewItemKey = useContext(RegisteredInsertMenuPreviewContext);
20
- const isPreviewActive = activePreviewItemKey === registration.key;
21
- const select = useCallback(selectionHandler => {
22
- // Close first so a registered item may safely focus the editor or open its picker.
23
- onClose();
24
- queueMicrotask(() => {
25
- const {
26
- state
27
- } = editorView;
28
- const insert = (content, options = {}) => insertSelectedItem(content, options)(state, state.tr, state.selection.head);
29
- const transaction = selectionHandler({
30
- insert,
31
- source: INPUT_METHOD.INSERT_MENU
32
- });
33
- if (transaction) {
34
- editorView.dispatch(transaction);
35
- }
36
- });
37
- }, [editorView, onClose]);
38
- const contextValue = useMemo(() => ({
39
- editorView,
40
- isOffline,
41
- item: {
42
- id,
43
- isPreviewActive,
44
- isSelected
45
- },
46
- menuOpenId,
47
- select,
48
- surface: 'toolbar',
49
- surfaceContext
50
- }), [editorView, id, isOffline, isPreviewActive, isSelected, menuOpenId, select, surfaceContext]);
51
- return /*#__PURE__*/React.createElement(QuickInsertProvider, {
52
- value: contextValue
53
- }, /*#__PURE__*/React.createElement(Component, null, null));
54
- };
@@ -1,11 +0,0 @@
1
- ._15a5nqa1{border-top-style:solid}
2
- ._16jlkb7n{flex-grow:1}
3
- ._18m91wug{overflow-y:auto}
4
- ._1e0c1txw{display:flex}
5
- ._1i531l7x{border-top-color:var(--ds-border,#0b120e24)}
6
- ._1o9zidpf{flex-shrink:0}
7
- ._1q51u2gc{padding-block-start:var(--ds-space-100,8px)}
8
- ._1tkeidpf{min-height:0}
9
- ._2lx21bp4{flex-direction:column}
10
- ._85i5u2gc{padding-block-end:var(--ds-space-100,8px)}
11
- ._uwhke4h9{border-top-width:var(--ds-border-width,1px)}
@@ -1,273 +0,0 @@
1
- /* RegisteredInsertMenuList.tsx generated by @compiled/babel-plugin v3.0.2 */
2
- import _extends from "@babel/runtime/helpers/extends";
3
- import "./RegisteredInsertMenuList.compiled.css";
4
- import { ax, ix } from "@compiled/react/runtime";
5
- import React, { useCallback, useLayoutEffect, useMemo, useRef } from 'react';
6
- import { CellMeasurer, CellMeasurerCache } from 'react-virtualized/dist/commonjs/CellMeasurer';
7
- import { List } from 'react-virtualized/dist/commonjs/List';
8
- import { QuickInsertEmptyState } from '@atlaskit/editor-common/quick-insert/empty-state';
9
- import { getQuickInsertMenuRows } from '@atlaskit/editor-common/quick-insert/registered-menu-model';
10
- import { useMenuListHeight } from '@atlaskit/editor-common/quick-insert/use-menu-list-height';
11
- // eslint-disable-next-line @atlaskit/platform/no-barrel-entry-imports
12
-
13
- import { Box } from '@atlaskit/primitives/compiled/box';
14
- import { RegisteredInsertMenuItem, RegisteredInsertMenuPreviewContext } from './RegisteredInsertMenuItem';
15
- const ESTIMATED_ROW_HEIGHT = 44;
16
- // 44px item + 1px separator.
17
- const MENU_FOOTER_HEIGHT = 45;
18
- const MENU_SEARCH_HEIGHT = 64;
19
- const LIST_WIDTH = 350;
20
- const listAriaProps = {
21
- // @ts-expect-error react-virtualized forwards null to omit its grid-only default; its types exclude null.
22
- 'aria-readonly': null
23
- };
24
- const styles = {
25
- content: "_1e0c1txw _2lx21bp4 _1tkeidpf",
26
- scrollable: "_16jlkb7n _1tkeidpf _18m91wug",
27
- footer: "_1o9zidpf",
28
- footerWithDivider: "_1i531l7x _15a5nqa1 _uwhke4h9 _1o9zidpf",
29
- externalControls: "_1i531l7x _15a5nqa1 _uwhke4h9 _1q51u2gc _85i5u2gc"
30
- };
31
- const RegisteredInsertMenuItemRow = ({
32
- editorView,
33
- id,
34
- isOffline,
35
- isSelected,
36
- itemIndex,
37
- menuOpenId,
38
- onClose,
39
- onItemFocus,
40
- onItemBlur,
41
- onItemHover,
42
- onItemLeave,
43
- registration,
44
- surfaceContext
45
- }) => {
46
- useLayoutEffect(() => () => onItemLeave(registration.key), [onItemLeave, registration.key]);
47
- const onBlur = useCallback(event => {
48
- if (!event.currentTarget.contains(event.relatedTarget)) {
49
- onItemBlur(registration.key);
50
- }
51
- }, [onItemBlur, registration.key]);
52
- return /*#__PURE__*/React.createElement("div", {
53
- onBlur: onBlur,
54
- onFocus: () => onItemFocus(itemIndex, registration.key),
55
- onMouseLeave: () => onItemLeave(registration.key),
56
- onMouseMove: () => onItemHover(itemIndex, registration.key)
57
- }, /*#__PURE__*/React.createElement(RegisteredInsertMenuItem, {
58
- editorView: editorView,
59
- id: id,
60
- isOffline: isOffline,
61
- isSelected: isSelected,
62
- menuOpenId: menuOpenId,
63
- onClose: onClose,
64
- registration: registration,
65
- surfaceContext: surfaceContext
66
- }));
67
- };
68
- export const RegisteredInsertMenuList = ({
69
- editorView,
70
- emptyStateHandler,
71
- isOffline,
72
- listId,
73
- listLabel,
74
- maxHeight,
75
- menuOpenId,
76
- model,
77
- onClose,
78
- onItemFocus,
79
- onItemBlur,
80
- query,
81
- onItemHover,
82
- onItemLeave,
83
- onItemVisibilityChange,
84
- onRenderedItemsChange,
85
- selectedItemIndex,
86
- surfaceContext,
87
- activePreviewItemKey
88
- }) => {
89
- var _model$root$component, _model$root;
90
- const Root = (_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 : React.Fragment;
91
- const listRef = useRef(null);
92
- const setListRef = useCallback(list => {
93
- listRef.current = list;
94
- }, []);
95
- const rows = useMemo(() => getQuickInsertMenuRows(model), [model]);
96
- const cache = useMemo(() => new CellMeasurerCache({
97
- defaultHeight: ESTIMATED_ROW_HEIGHT,
98
- fixedWidth: true
99
- }), []);
100
- const itemIndexByRowIndex = useMemo(() => {
101
- const indexes = new Map();
102
- let itemIndex = 0;
103
- rows.forEach((registration, rowIndex) => {
104
- if (registration.type === 'menu-item') {
105
- indexes.set(rowIndex, itemIndex++);
106
- }
107
- });
108
- return indexes;
109
- }, [rows]);
110
- const selectedRowIndex = useMemo(() => {
111
- for (const [rowIndex, itemIndex] of itemIndexByRowIndex) {
112
- if (itemIndex === selectedItemIndex) {
113
- return rowIndex;
114
- }
115
- }
116
- return -1;
117
- }, [itemIndexByRowIndex, selectedItemIndex]);
118
- const rowKeySignature = useMemo(() => rows.map(({
119
- key,
120
- type
121
- }) => `${type}:${key}`).join('\0'), [rows]);
122
- const {
123
- height: measuredHeight,
124
- updateHeight
125
- } = useMenuListHeight(cache, rows.length, rowKeySignature);
126
- useLayoutEffect(() => {
127
- var _listRef$current, _listRef$current2;
128
- cache.clearAll();
129
- (_listRef$current = listRef.current) === null || _listRef$current === void 0 ? void 0 : _listRef$current.recomputeRowHeights();
130
- (_listRef$current2 = listRef.current) === null || _listRef$current2 === void 0 ? void 0 : _listRef$current2.scrollToPosition(0);
131
- }, [cache, rowKeySignature]);
132
- const onRowsRendered = useCallback(({
133
- overscanStartIndex,
134
- overscanStopIndex,
135
- startIndex,
136
- stopIndex
137
- }) => {
138
- var _indexes$, _indexes;
139
- if (activePreviewItemKey) {
140
- const previewRowIndex = rows.findIndex(({
141
- key
142
- }) => key === activePreviewItemKey);
143
- if (previewRowIndex < startIndex || previewRowIndex > stopIndex) {
144
- onItemVisibilityChange(activePreviewItemKey, false);
145
- }
146
- }
147
- updateHeight();
148
- const indexes = [...itemIndexByRowIndex].filter(([rowIndex]) => rowIndex >= overscanStartIndex && rowIndex <= overscanStopIndex).map(([, itemIndex]) => itemIndex);
149
- onRenderedItemsChange({
150
- startIndex: (_indexes$ = indexes[0]) !== null && _indexes$ !== void 0 ? _indexes$ : -1,
151
- stopIndex: (_indexes = indexes[indexes.length - 1]) !== null && _indexes !== void 0 ? _indexes : -1
152
- });
153
- }, [activePreviewItemKey, itemIndexByRowIndex, onItemVisibilityChange, onRenderedItemsChange, rows, updateHeight]);
154
- const onScrollableContentScroll = useCallback(event => {
155
- if (event.target === event.currentTarget && activePreviewItemKey) {
156
- onItemVisibilityChange(activePreviewItemKey, false);
157
- }
158
- }, [activePreviewItemKey, onItemVisibilityChange]);
159
- const renderRow = useCallback(({
160
- index,
161
- key,
162
- parent,
163
- style
164
- }) => {
165
- var _registration$compone;
166
- const registration = rows[index];
167
- if (!registration) {
168
- return null;
169
- }
170
- const itemIndex = itemIndexByRowIndex.get(index);
171
- const rowContent = registration.type === 'menu-section' ? ( /*#__PURE__*/React.createElement((_registration$compone = registration.component) !== null && _registration$compone !== void 0 ? _registration$compone : React.Fragment, null, null)) : /*#__PURE__*/React.createElement(RegisteredInsertMenuItemRow, {
172
- editorView: editorView,
173
- id: `${listId}-${itemIndex}`,
174
- isOffline: isOffline,
175
- isSelected: itemIndex === selectedItemIndex,
176
- itemIndex: itemIndex !== null && itemIndex !== void 0 ? itemIndex : 0,
177
- menuOpenId: menuOpenId,
178
- onClose: onClose,
179
- onItemFocus: onItemFocus,
180
- onItemBlur: onItemBlur,
181
- onItemHover: onItemHover,
182
- onItemLeave: onItemLeave,
183
- registration: registration,
184
- surfaceContext: surfaceContext
185
- });
186
- return /*#__PURE__*/React.createElement(CellMeasurer, {
187
- key: key,
188
- cache: cache,
189
- parent: parent,
190
- columnIndex: 0,
191
- rowIndex: index
192
- }, ({
193
- registerChild
194
- }) => /*#__PURE__*/React.createElement("div", {
195
- ref: element => registerChild === null || registerChild === void 0 ? void 0 : registerChild(element !== null && element !== void 0 ? element : undefined)
196
- // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop
197
- ,
198
- style: style
199
- }, /*#__PURE__*/React.createElement(Box, {
200
- paddingBlockEnd: index === rows.length - 1 ? 'space.100' : undefined
201
- }, rowContent)));
202
- }, [cache, editorView, isOffline, itemIndexByRowIndex, listId, menuOpenId, onClose, onItemFocus, onItemBlur, onItemHover, onItemLeave, rows, selectedItemIndex, surfaceContext]);
203
- const footerItemIndex = itemIndexByRowIndex.size;
204
- const footerItemId = `${listId}-${footerItemIndex}`;
205
- const hasExternalControls = model.fallbackItems !== undefined && emptyStateHandler !== undefined;
206
- const hasNoSearchResults = query !== '' && rows.length === 0;
207
- const externalControls = hasExternalControls && emptyStateHandler ? emptyStateHandler({
208
- mode: 'inline',
209
- searchTerm: query,
210
- showNoResultsMessage: false
211
- }) : null;
212
- const showFooterDivider = !hasNoSearchResults || Boolean(externalControls);
213
- const listMaxHeight = Math.max(0, maxHeight - MENU_SEARCH_HEIGHT - (model.footer ? MENU_FOOTER_HEIGHT : 0));
214
- const contentStyle = {
215
- maxHeight: Math.max(0, maxHeight - MENU_SEARCH_HEIGHT)
216
- };
217
- const onFooterItemHover = useCallback(() => onItemHover(footerItemIndex), [footerItemIndex, onItemHover]);
218
- const onFooterItemFocus = useCallback(() => onItemFocus(footerItemIndex), [footerItemIndex, onItemFocus]);
219
- const footer = model.footer ? /*#__PURE__*/React.createElement(Box, {
220
- testId: "registered-insert-menu-footer",
221
- xcss: showFooterDivider ? styles.footerWithDivider : styles.footer,
222
- onFocus: onFooterItemFocus,
223
- onMouseMove: onFooterItemHover
224
- }, /*#__PURE__*/React.createElement(RegisteredInsertMenuItem, {
225
- editorView: editorView,
226
- id: footerItemId,
227
- isOffline: isOffline,
228
- isSelected: footerItemIndex === selectedItemIndex,
229
- menuOpenId: menuOpenId,
230
- onClose: onClose,
231
- registration: model.footer,
232
- surfaceContext: surfaceContext
233
- })) : null;
234
- if (!model.root) {
235
- return null;
236
- }
237
- return /*#__PURE__*/React.createElement(Root, null, /*#__PURE__*/React.createElement(RegisteredInsertMenuPreviewContext.Provider, {
238
- value: activePreviewItemKey
239
- }, /*#__PURE__*/React.createElement(Box, {
240
- xcss: styles.content,
241
- style: contentStyle
242
- }, /*#__PURE__*/React.createElement(Box, {
243
- xcss: styles.scrollable,
244
- onScroll: onScrollableContentScroll
245
- }, /*#__PURE__*/React.createElement(Box, {
246
- "aria-label": listLabel,
247
- "aria-owns": model.footer ? footerItemId : undefined,
248
- id: listId,
249
- role: "listbox"
250
- }, rows.length > 0 && /*#__PURE__*/React.createElement(List
251
- // eslint-disable-next-line react/jsx-props-no-spreading -- Omits the library's grid-only ARIA default without declaring it on the group role.
252
- , _extends({}, listAriaProps, {
253
- tabIndex: null,
254
- containerRole: "presentation",
255
- height: Math.min(measuredHeight, listMaxHeight),
256
- overscanRowCount: 3,
257
- onRowsRendered: onRowsRendered,
258
- ref: setListRef,
259
- role: "group",
260
- rowCount: rows.length,
261
- rowHeight: cache.rowHeight,
262
- rowRenderer: renderRow,
263
- scrollToAlignment: "auto",
264
- scrollToIndex: selectedRowIndex,
265
- width: LIST_WIDTH
266
- }))), hasNoSearchResults && /*#__PURE__*/React.createElement(QuickInsertEmptyState, {
267
- mode: "inline",
268
- spacing: "compact"
269
- }), externalControls && /*#__PURE__*/React.createElement(Box, {
270
- testId: "registered-insert-menu-external-controls",
271
- xcss: styles.externalControls
272
- }, externalControls)), footer)));
273
- };