@atlaskit/editor-plugin-insert-block 18.0.6 → 18.1.1

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 (43) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/cjs/ui/ToolbarInsertBlock/block-insert-element-browser.js +21 -3
  3. package/dist/cjs/ui/ToolbarInsertBlock/block-insert-menu.js +3 -1
  4. package/dist/cjs/ui/ToolbarInsertBlock/index.js +3 -1
  5. package/dist/cjs/ui/registered-insert-menu/RegisteredInsertButton.js +122 -0
  6. package/dist/cjs/ui/registered-insert-menu/RegisteredInsertMenu.compiled.css +11 -0
  7. package/dist/cjs/ui/registered-insert-menu/RegisteredInsertMenu.js +154 -0
  8. package/dist/cjs/ui/registered-insert-menu/RegisteredInsertMenuContent.js +53 -0
  9. package/dist/cjs/ui/registered-insert-menu/RegisteredInsertMenuItem.js +59 -0
  10. package/dist/cjs/ui/registered-insert-menu/RegisteredInsertMenuList.compiled.css +4 -0
  11. package/dist/cjs/ui/registered-insert-menu/RegisteredInsertMenuList.js +205 -0
  12. package/dist/cjs/ui/toolbar-components.js +5 -1
  13. package/dist/es2019/ui/ToolbarInsertBlock/block-insert-element-browser.js +21 -2
  14. package/dist/es2019/ui/ToolbarInsertBlock/block-insert-menu.js +3 -1
  15. package/dist/es2019/ui/ToolbarInsertBlock/index.js +3 -1
  16. package/dist/es2019/ui/registered-insert-menu/RegisteredInsertButton.js +107 -0
  17. package/dist/es2019/ui/registered-insert-menu/RegisteredInsertMenu.compiled.css +11 -0
  18. package/dist/es2019/ui/registered-insert-menu/RegisteredInsertMenu.js +117 -0
  19. package/dist/es2019/ui/registered-insert-menu/RegisteredInsertMenuContent.js +43 -0
  20. package/dist/es2019/ui/registered-insert-menu/RegisteredInsertMenuItem.js +49 -0
  21. package/dist/es2019/ui/registered-insert-menu/RegisteredInsertMenuList.compiled.css +4 -0
  22. package/dist/es2019/ui/registered-insert-menu/RegisteredInsertMenuList.js +161 -0
  23. package/dist/es2019/ui/toolbar-components.js +5 -1
  24. package/dist/esm/ui/ToolbarInsertBlock/block-insert-element-browser.js +21 -2
  25. package/dist/esm/ui/ToolbarInsertBlock/block-insert-menu.js +3 -1
  26. package/dist/esm/ui/ToolbarInsertBlock/index.js +3 -1
  27. package/dist/esm/ui/registered-insert-menu/RegisteredInsertButton.js +113 -0
  28. package/dist/esm/ui/registered-insert-menu/RegisteredInsertMenu.compiled.css +11 -0
  29. package/dist/esm/ui/registered-insert-menu/RegisteredInsertMenu.js +145 -0
  30. package/dist/esm/ui/registered-insert-menu/RegisteredInsertMenuContent.js +44 -0
  31. package/dist/esm/ui/registered-insert-menu/RegisteredInsertMenuItem.js +51 -0
  32. package/dist/esm/ui/registered-insert-menu/RegisteredInsertMenuList.compiled.css +4 -0
  33. package/dist/esm/ui/registered-insert-menu/RegisteredInsertMenuList.js +196 -0
  34. package/dist/esm/ui/toolbar-components.js +5 -1
  35. package/dist/types/types/index.d.ts +3 -1
  36. package/dist/types/ui/ToolbarInsertBlock/block-insert-element-browser.d.ts +1 -0
  37. package/dist/types/ui/ToolbarInsertBlock/block-insert-menu.d.ts +1 -0
  38. package/dist/types/ui/registered-insert-menu/RegisteredInsertButton.d.ts +12 -0
  39. package/dist/types/ui/registered-insert-menu/RegisteredInsertMenu.d.ts +12 -0
  40. package/dist/types/ui/registered-insert-menu/RegisteredInsertMenuContent.d.ts +15 -0
  41. package/dist/types/ui/registered-insert-menu/RegisteredInsertMenuItem.d.ts +15 -0
  42. package/dist/types/ui/registered-insert-menu/RegisteredInsertMenuList.d.ts +23 -0
  43. package/package.json +11 -5
@@ -0,0 +1,161 @@
1
+ /* RegisteredInsertMenuList.tsx generated by @compiled/babel-plugin v3.0.1 */
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 { Box } from '@atlaskit/primitives/compiled';
9
+ import { RegisteredInsertMenuItem } from './RegisteredInsertMenuItem';
10
+ const ESTIMATED_ROW_HEIGHT = 56;
11
+ const MENU_FOOTER_HEIGHT = 52;
12
+ const MENU_SEARCH_HEIGHT = 64;
13
+ const LIST_WIDTH = 350;
14
+ const listAriaProps = {
15
+ // @ts-expect-error react-virtualized forwards null to omit its grid-only default; its types exclude null.
16
+ 'aria-readonly': null
17
+ };
18
+ const styles = {
19
+ footer: "_1rjc1b66 _1i531l7x _15a5nqa1 _uwhke4h9 _1o9zidpf"
20
+ };
21
+ export const RegisteredInsertMenuList = ({
22
+ editorView,
23
+ isOffline,
24
+ listId,
25
+ listLabel,
26
+ maxHeight,
27
+ menuOpenId,
28
+ model,
29
+ onClose,
30
+ onItemHover,
31
+ onRenderedItemsChange,
32
+ selectedItemIndex,
33
+ surfaceContext
34
+ }) => {
35
+ var _model$root$component, _model$root;
36
+ 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;
37
+ const listRef = useRef(null);
38
+ const rows = useMemo(() => model.sections.flat(), [model.sections]);
39
+ const cache = useMemo(() => new CellMeasurerCache({
40
+ defaultHeight: ESTIMATED_ROW_HEIGHT,
41
+ fixedWidth: true
42
+ }), []);
43
+ const itemIndexByRowIndex = useMemo(() => {
44
+ const indexes = new Map();
45
+ let itemIndex = 0;
46
+ rows.forEach((registration, rowIndex) => {
47
+ if (registration.type === 'menu-item') {
48
+ indexes.set(rowIndex, itemIndex++);
49
+ }
50
+ });
51
+ return indexes;
52
+ }, [rows]);
53
+ const selectedRowIndex = useMemo(() => {
54
+ for (const [rowIndex, itemIndex] of itemIndexByRowIndex) {
55
+ if (itemIndex === selectedItemIndex) {
56
+ return rowIndex;
57
+ }
58
+ }
59
+ return -1;
60
+ }, [itemIndexByRowIndex, selectedItemIndex]);
61
+ const rowKeySignature = useMemo(() => rows.map(({
62
+ key,
63
+ type
64
+ }) => `${type}:${key}`).join('\0'), [rows]);
65
+ useLayoutEffect(() => {
66
+ var _listRef$current, _listRef$current2;
67
+ cache.clearAll();
68
+ (_listRef$current = listRef.current) === null || _listRef$current === void 0 ? void 0 : _listRef$current.recomputeRowHeights();
69
+ (_listRef$current2 = listRef.current) === null || _listRef$current2 === void 0 ? void 0 : _listRef$current2.scrollToPosition(0);
70
+ }, [cache, rowKeySignature]);
71
+ const onRowsRendered = useCallback(({
72
+ overscanStartIndex,
73
+ overscanStopIndex
74
+ }) => {
75
+ var _indexes$, _indexes;
76
+ const indexes = [...itemIndexByRowIndex].filter(([rowIndex]) => rowIndex >= overscanStartIndex && rowIndex <= overscanStopIndex).map(([, itemIndex]) => itemIndex);
77
+ onRenderedItemsChange({
78
+ startIndex: (_indexes$ = indexes[0]) !== null && _indexes$ !== void 0 ? _indexes$ : -1,
79
+ stopIndex: (_indexes = indexes[indexes.length - 1]) !== null && _indexes !== void 0 ? _indexes : -1
80
+ });
81
+ }, [itemIndexByRowIndex, onRenderedItemsChange]);
82
+ const renderRow = useCallback(({
83
+ index,
84
+ key,
85
+ parent,
86
+ style
87
+ }) => {
88
+ var _registration$compone;
89
+ const registration = rows[index];
90
+ if (!registration) {
91
+ return null;
92
+ }
93
+ const itemIndex = itemIndexByRowIndex.get(index);
94
+ 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("div", {
95
+ onMouseMove: () => onItemHover(itemIndex !== null && itemIndex !== void 0 ? itemIndex : 0)
96
+ }, /*#__PURE__*/React.createElement(RegisteredInsertMenuItem, {
97
+ editorView: editorView,
98
+ id: `${listId}-${itemIndex}`,
99
+ isOffline: isOffline,
100
+ isSelected: itemIndex === selectedItemIndex,
101
+ menuOpenId: menuOpenId,
102
+ onClose: onClose,
103
+ registration: registration,
104
+ surfaceContext: surfaceContext
105
+ }));
106
+ return /*#__PURE__*/React.createElement(CellMeasurer, {
107
+ key: key,
108
+ cache: cache,
109
+ parent: parent,
110
+ columnIndex: 0,
111
+ rowIndex: index
112
+ }, ({
113
+ registerChild
114
+ }) => /*#__PURE__*/React.createElement("div", {
115
+ ref: element => registerChild === null || registerChild === void 0 ? void 0 : registerChild(element !== null && element !== void 0 ? element : undefined),
116
+ "data-index": index
117
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop
118
+ ,
119
+ style: style
120
+ }, rowContent));
121
+ }, [cache, editorView, isOffline, itemIndexByRowIndex, listId, menuOpenId, onClose, onItemHover, rows, selectedItemIndex, surfaceContext]);
122
+ const footerItemIndex = itemIndexByRowIndex.size;
123
+ const listMaxHeight = Math.max(0, maxHeight - MENU_SEARCH_HEIGHT - (model.footer ? MENU_FOOTER_HEIGHT : 0));
124
+ const onFooterItemHover = useCallback(() => onItemHover(footerItemIndex), [footerItemIndex, onItemHover]);
125
+ if (!model.root) {
126
+ return null;
127
+ }
128
+ return /*#__PURE__*/React.createElement(Root, null, /*#__PURE__*/React.createElement(Box, {
129
+ "aria-label": listLabel,
130
+ id: listId,
131
+ role: "listbox"
132
+ }, rows.length > 0 && /*#__PURE__*/React.createElement(List
133
+ // eslint-disable-next-line react/jsx-props-no-spreading -- Omits the library's grid-only ARIA default without declaring it on the group role.
134
+ , _extends({}, listAriaProps, {
135
+ tabIndex: null,
136
+ containerRole: "presentation",
137
+ height: Math.min(rows.length * ESTIMATED_ROW_HEIGHT, listMaxHeight),
138
+ overscanRowCount: 3,
139
+ onRowsRendered: onRowsRendered,
140
+ ref: listRef,
141
+ role: "group",
142
+ rowCount: rows.length,
143
+ rowHeight: cache.rowHeight,
144
+ rowRenderer: renderRow,
145
+ scrollToAlignment: "auto",
146
+ scrollToIndex: selectedRowIndex,
147
+ width: LIST_WIDTH
148
+ })), model.footer && /*#__PURE__*/React.createElement(Box, {
149
+ xcss: styles.footer,
150
+ onMouseMove: onFooterItemHover
151
+ }, /*#__PURE__*/React.createElement(RegisteredInsertMenuItem, {
152
+ editorView: editorView,
153
+ id: `${listId}-${footerItemIndex}`,
154
+ isOffline: isOffline,
155
+ isSelected: footerItemIndex === selectedItemIndex,
156
+ menuOpenId: menuOpenId,
157
+ onClose: onClose,
158
+ registration: model.footer,
159
+ surfaceContext: surfaceContext
160
+ }))));
161
+ };
@@ -6,6 +6,8 @@ import { resolveToolbarConfig } from './toolbar-components/config-resolver';
6
6
  import { EmojiButton } from './toolbar-components/EmojiButton';
7
7
  import { ImageButton } from './toolbar-components/ImageButton';
8
8
  import { InsertButton } from './toolbar-components/InsertButton';
9
+ import { RegisteredInsertButton } from './registered-insert-menu/RegisteredInsertButton';
10
+ import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
9
11
  import { LayoutButton } from './toolbar-components/LayoutButton';
10
12
  import { MediaButton } from './toolbar-components/MediaButton';
11
13
  import { MentionButton } from './toolbar-components/MentionButton';
@@ -239,7 +241,9 @@ export const getToolbarComponents = ({
239
241
  // Insert Group
240
242
  if ((_config$insert = config.insert) !== null && _config$insert !== void 0 && _config$insert.enabled) {
241
243
  const createInsertButtonComponent = breakpoint => {
242
- return () => /*#__PURE__*/React.createElement(InsertButton, {
244
+ return () => isExperimentEnabled('platform_editor_slash_command') ? /*#__PURE__*/React.createElement(RegisteredInsertButton, {
245
+ api: api
246
+ }) : /*#__PURE__*/React.createElement(InsertButton, {
243
247
  api: api,
244
248
  breakpoint: breakpoint,
245
249
  toolbarConfig: config,
@@ -1,12 +1,23 @@
1
- import React from 'react';
1
+ import React, { useCallback } from 'react';
2
2
  import { Popup } from '@atlaskit/editor-common/ui';
3
+ import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
3
4
  import InsertMenu, { DEFAULT_HEIGHT } from '../ElementBrowser/InsertMenu';
5
+ import { RegisteredInsertMenuContent } from '../registered-insert-menu/RegisteredInsertMenuContent';
4
6
  import { DropDownButton } from './dropdown-button';
5
7
  // This determines how the popup should fit. We prefer the insert menu
6
8
  // opening on the bottom as we have a search bar and should only open on
7
9
  // top if there is more than sufficient room.
8
10
  var FIT_HEIGHT_BUFFER = 100;
9
11
  export var BlockInsertElementBrowser = function BlockInsertElementBrowser(props) {
12
+ var togglePlusMenuVisibility = props.togglePlusMenuVisibility,
13
+ plusButtonRef = props.plusButtonRef;
14
+ var closeRegisteredMenu = useCallback(function () {
15
+ return togglePlusMenuVisibility();
16
+ }, [togglePlusMenuVisibility]);
17
+ var closeRegisteredMenuAndRestoreFocus = useCallback(function () {
18
+ togglePlusMenuVisibility();
19
+ plusButtonRef === null || plusButtonRef === void 0 || plusButtonRef.focus();
20
+ }, [togglePlusMenuVisibility, plusButtonRef]);
10
21
  return /*#__PURE__*/React.createElement(React.Fragment, null, props.open && /*#__PURE__*/React.createElement(Popup, {
11
22
  target: props.plusButtonRef,
12
23
  fitHeight: DEFAULT_HEIGHT + FIT_HEIGHT_BUFFER,
@@ -19,7 +30,15 @@ export var BlockInsertElementBrowser = function BlockInsertElementBrowser(props)
19
30
  scrollableElement: props.popupsScrollableElement,
20
31
  preventOverflow: true,
21
32
  alignX: "right"
22
- }, /*#__PURE__*/React.createElement(InsertMenu, {
33
+ }, isExperimentEnabled('platform_editor_slash_command') ? /*#__PURE__*/React.createElement(RegisteredInsertMenuContent, {
34
+ api: props.pluginInjectionApi,
35
+ editorView: props.editorView,
36
+ isOffline: Boolean(props.isEditorOffline),
37
+ onClose: closeRegisteredMenuAndRestoreFocus,
38
+ onDismiss: closeRegisteredMenu,
39
+ onSelect: closeRegisteredMenu,
40
+ target: props.plusButtonRef
41
+ }) : /*#__PURE__*/React.createElement(InsertMenu, {
23
42
  editorView: props.editorView,
24
43
  dropdownItems: props.items,
25
44
  onInsert: props.onInsert,
@@ -1,8 +1,9 @@
1
1
  import React from 'react';
2
+ import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
2
3
  import { BlockInsertElementBrowser } from './block-insert-element-browser';
3
4
  import { DropDownButton } from './dropdown-button';
4
5
  export var BlockInsertMenu = function BlockInsertMenu(props) {
5
- if (props.items.length === 0 && !props.showElementBrowserLink) {
6
+ if (props.items.length === 0 && !props.showElementBrowserLink && !isExperimentEnabled('platform_editor_slash_command')) {
6
7
  return null;
7
8
  }
8
9
  if (props.disabled) {
@@ -36,6 +37,7 @@ export var BlockInsertMenu = function BlockInsertMenu(props) {
36
37
  spacing: props.spacing,
37
38
  togglePlusMenuVisibility: props.togglePlusMenuVisibility,
38
39
  showElementBrowserLink: props.showElementBrowserLink,
40
+ isEditorOffline: props.isEditorOffline,
39
41
  pluginInjectionApi: props.pluginInjectionApi,
40
42
  isFullPageAppearance: props.isFullPageAppearance
41
43
  });
@@ -33,6 +33,7 @@ import { ToolbarButton } from '@atlaskit/editor-common/ui-menu';
33
33
  import { OutsideClickTargetRefContext, withReactEditorViewOuterListeners as withOuterListeners } from '@atlaskit/editor-common/ui-react';
34
34
  import { akEditorMenuZIndex } from '@atlaskit/editor-shared-styles';
35
35
  import { EmojiPicker as AkEmojiPicker } from '@atlaskit/emoji/picker';
36
+ import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
36
37
  // Ignored via go/ees005
37
38
  // eslint-disable-next-line import/no-namespace
38
39
  import { fg } from '@atlaskit/platform-feature-flags/fg';
@@ -677,7 +678,7 @@ export var ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
677
678
  var value = _ref8.value;
678
679
  return value.name === 'table selector';
679
680
  });
680
- if (buttons.length === 0 && dropdownItems.length === 0) {
681
+ if (buttons.length === 0 && dropdownItems.length === 0 && !isExperimentEnabled('platform_editor_slash_command')) {
681
682
  return null;
682
683
  }
683
684
  var toolbarButtons = [];
@@ -784,6 +785,7 @@ export var ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
784
785
  onInsert: this.insertInsertMenuItem,
785
786
  togglePlusMenuVisibility: this.togglePlusMenuVisibility,
786
787
  showElementBrowserLink: this.props.showElementBrowserLink || false,
788
+ isEditorOffline: this.props.isEditorOffline,
787
789
  pluginInjectionApi: this.props.pluginInjectionApi,
788
790
  isFullPageAppearance: isFullPageAppearance
789
791
  })), (!((_this$props$pluginInj = this.props.pluginInjectionApi) !== null && _this$props$pluginInj !== void 0 && _this$props$pluginInj.primaryToolbar) && this.props.showSeparator || isFullPageAppearance && editorExperiment('platform_editor_controls', 'variant1')) && /* eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage */
@@ -0,0 +1,113 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ import React, { useCallback, useRef, useState } from 'react';
3
+ import { useIntl } from 'react-intl';
4
+ import { getAriaKeyshortcuts, insertElements, ToolTipContent } from '@atlaskit/editor-common/keymaps';
5
+ import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
6
+ import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
7
+ import { TOOLBAR_BUTTON_TEST_ID, useEditorToolbar } from '@atlaskit/editor-common/toolbar';
8
+ import { Popup } from '@atlaskit/editor-common/ui';
9
+ import { isOfflineMode } from '@atlaskit/editor-plugin-connectivity/connectivityPluginType';
10
+ import { akEditorMenuZIndex } from '@atlaskit/editor-shared-styles/constants';
11
+ import { AddIcon } from '@atlaskit/editor-toolbar/add-icon';
12
+ import { ToolbarButton } from '@atlaskit/editor-toolbar/toolbar-button';
13
+ import { ToolbarTooltip } from '@atlaskit/editor-toolbar/toolbar-tooltip';
14
+ import { useToolbarUI } from '@atlaskit/editor-toolbar/ui-context';
15
+ import { RegisteredInsertMenuContent } from './RegisteredInsertMenuContent';
16
+ var DEFAULT_MENU_MAX_HEIGHT = 520;
17
+ var FIT_HEIGHT_BUFFER = 100;
18
+ var POPUP_OFFSET = [0, 3];
19
+ /**
20
+ * The toolbar owns its popup lifecycle, but renders the same registered items
21
+ * and menu model as slash command.
22
+ */
23
+ export var RegisteredInsertButton = function RegisteredInsertButton(_ref) {
24
+ var api = _ref.api;
25
+ var _useEditorToolbar = useEditorToolbar(),
26
+ editorView = _useEditorToolbar.editorView;
27
+ var _useIntl = useIntl(),
28
+ formatMessage = _useIntl.formatMessage;
29
+ var _useToolbarUI = useToolbarUI(),
30
+ isDisabled = _useToolbarUI.isDisabled,
31
+ popupsBoundariesElement = _useToolbarUI.popupsBoundariesElement,
32
+ popupsMountPoint = _useToolbarUI.popupsMountPoint,
33
+ popupsScrollableElement = _useToolbarUI.popupsScrollableElement;
34
+ var _useState = useState(false),
35
+ _useState2 = _slicedToArray(_useState, 2),
36
+ isOpen = _useState2[0],
37
+ setIsOpen = _useState2[1];
38
+ var buttonRef = useRef(null);
39
+ var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['connectivity', 'typeAhead'], function (states) {
40
+ var _states$connectivityS, _states$typeAheadStat;
41
+ return {
42
+ connectivityMode: (_states$connectivityS = states.connectivityState) === null || _states$connectivityS === void 0 ? void 0 : _states$connectivityS.mode,
43
+ isAllowed: (_states$typeAheadStat = states.typeAheadState) === null || _states$typeAheadStat === void 0 ? void 0 : _states$typeAheadStat.isAllowed
44
+ };
45
+ }),
46
+ connectivityMode = _useSharedPluginState.connectivityMode,
47
+ isAllowed = _useSharedPluginState.isAllowed;
48
+ var close = useCallback(function () {
49
+ var restoreFocus = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
50
+ setIsOpen(false);
51
+ if (restoreFocus) {
52
+ requestAnimationFrame(function () {
53
+ var _buttonRef$current;
54
+ return (_buttonRef$current = buttonRef.current) === null || _buttonRef$current === void 0 ? void 0 : _buttonRef$current.focus();
55
+ });
56
+ }
57
+ }, []);
58
+ var open = useCallback(function () {
59
+ setIsOpen(true);
60
+ }, []);
61
+ var onPopupUnmount = useCallback(function () {
62
+ // Outside dismissal must not move focus away from the element that was clicked.
63
+ setIsOpen(false);
64
+ }, []);
65
+ var closeAndRestoreFocus = useCallback(function () {
66
+ return close(true);
67
+ }, [close]);
68
+ var closeForSelection = useCallback(function () {
69
+ return close(false);
70
+ }, [close]);
71
+ if (!(api !== null && api !== void 0 && api.insertBlock) || !editorView) {
72
+ return null;
73
+ }
74
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ToolbarTooltip, {
75
+ content: /*#__PURE__*/React.createElement(ToolTipContent, {
76
+ description: formatMessage(messages.insertMenu),
77
+ keymap: insertElements
78
+ })
79
+ }, /*#__PURE__*/React.createElement(ToolbarButton, {
80
+ ariaKeyshortcuts: getAriaKeyshortcuts(insertElements),
81
+ iconBefore: /*#__PURE__*/React.createElement(AddIcon, {
82
+ size: "small",
83
+ label: formatMessage(messages.insertMenu)
84
+ }),
85
+ isDisabled: !isAllowed || isDisabled,
86
+ isSelected: isOpen,
87
+ onClick: isOpen ? function () {
88
+ return close(true);
89
+ } : open,
90
+ ref: buttonRef,
91
+ testId: TOOLBAR_BUTTON_TEST_ID.INSERT
92
+ })), isOpen && buttonRef.current && /*#__PURE__*/React.createElement(Popup, {
93
+ alignX: "right",
94
+ boundariesElement: popupsBoundariesElement,
95
+ fitHeight: DEFAULT_MENU_MAX_HEIGHT + FIT_HEIGHT_BUFFER,
96
+ fitWidth: 350,
97
+ mountTo: popupsMountPoint,
98
+ offset: POPUP_OFFSET,
99
+ onUnmount: onPopupUnmount,
100
+ preventOverflow: true,
101
+ scrollableElement: popupsScrollableElement,
102
+ target: buttonRef.current,
103
+ zIndex: akEditorMenuZIndex
104
+ }, /*#__PURE__*/React.createElement(RegisteredInsertMenuContent, {
105
+ api: api,
106
+ editorView: editorView,
107
+ isOffline: isOfflineMode(connectivityMode),
108
+ onClose: closeAndRestoreFocus,
109
+ onDismiss: closeForSelection,
110
+ onSelect: closeForSelection,
111
+ target: buttonRef.current
112
+ })));
113
+ };
@@ -0,0 +1,11 @@
1
+ ._2rko12b0{border-radius:var(--ds-radius-small,4px)}
2
+ ._18zrutpp{padding-inline:var(--ds-space-150,9pt)}
3
+ ._1rjcutpp{padding-block:var(--ds-space-150,9pt)}._16qs130s{box-shadow:var(--ds-shadow-overlay,0 8px 9pt #1e1f2126,0 0 1px #1e1f214f)}
4
+ ._18m915vq{overflow-y:hidden}
5
+ ._1bsb1edt{width:350px}
6
+ ._1e0c1txw{display:flex}
7
+ ._1o9zidpf{flex-shrink:0}
8
+ ._1reo15vq{overflow-x:hidden}
9
+ ._2lx21bp4{flex-direction:column}
10
+ ._bfhk1bhr{background-color:var(--ds-surface-overlay,#fff)}
11
+ ._c71l1lk4{max-height:520px}
@@ -0,0 +1,145 @@
1
+ /* RegisteredInsertMenu.tsx generated by @compiled/babel-plugin v3.0.1 */
2
+ import _toArray from "@babel/runtime/helpers/toArray";
3
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
4
+ import "./RegisteredInsertMenu.compiled.css";
5
+ import { ax, ix } from "@compiled/react/runtime";
6
+ 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; }
7
+ import React, { useCallback, useId, useMemo, useState } from 'react';
8
+ import { getDocument } from '@atlaskit/browser-apis';
9
+ import { useIntl } from 'react-intl';
10
+ import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
11
+ import { buildQuickInsertMenuModel, getMatchingQuickInsertComponents } from '@atlaskit/editor-common/quick-insert/registered-menu-model';
12
+ import { MENU } from '@atlaskit/editor-common/quick-insert/keys';
13
+ import { TYPE_AHEAD_SURFACE_CONTEXT } from '@atlaskit/editor-common/type-ahead-surface-context';
14
+ import { createSurfaceContext } from '@atlaskit/editor-ui-control-model/create-surface-context';
15
+ import { Box } from '@atlaskit/primitives/compiled';
16
+ import Textfield from '@atlaskit/textfield/text-field';
17
+ import { RegisteredInsertMenuList } from './RegisteredInsertMenuList';
18
+ var DEFAULT_MENU_MAX_HEIGHT = 520;
19
+ var styles = {
20
+ menu: "_2rko12b0 _1reo15vq _18m915vq _bfhk1bhr _16qs130s _1e0c1txw _2lx21bp4 _c71l1lk4 _1bsb1edt",
21
+ search: "_1rjcutpp _18zrutpp _1o9zidpf"
22
+ };
23
+ export var RegisteredInsertMenu = function RegisteredInsertMenu(_ref) {
24
+ var components = _ref.components,
25
+ editorView = _ref.editorView,
26
+ isOffline = _ref.isOffline,
27
+ onClose = _ref.onClose,
28
+ onSelect = _ref.onSelect;
29
+ var _useIntl = useIntl(),
30
+ formatMessage = _useIntl.formatMessage;
31
+ var listId = useId();
32
+ var _useState = useState(function () {
33
+ return Symbol('registered-insert-menu-open');
34
+ }),
35
+ _useState2 = _slicedToArray(_useState, 1),
36
+ menuOpenId = _useState2[0];
37
+ var _useState3 = useState(''),
38
+ _useState4 = _slicedToArray(_useState3, 2),
39
+ query = _useState4[0],
40
+ setQuery = _useState4[1];
41
+ var _useState5 = useState(0),
42
+ _useState6 = _slicedToArray(_useState5, 2),
43
+ selectedItemIndex = _useState6[0],
44
+ setSelectedItemIndex = _useState6[1];
45
+ var _useState7 = useState({
46
+ startIndex: -1,
47
+ stopIndex: -1
48
+ }),
49
+ _useState8 = _slicedToArray(_useState7, 2),
50
+ renderedItems = _useState8[0],
51
+ setRenderedItems = _useState8[1];
52
+ var surfaceContext = useMemo(function () {
53
+ return createSurfaceContext(TYPE_AHEAD_SURFACE_CONTEXT, {
54
+ menuOpenId: menuOpenId
55
+ });
56
+ }, [menuOpenId]);
57
+ var model = useMemo(function () {
58
+ return query === '' ? buildQuickInsertMenuModel(components, MENU, undefined, surfaceContext) : getMatchingQuickInsertComponents({
59
+ components: components,
60
+ formatMessage: formatMessage,
61
+ query: query,
62
+ rootComponent: MENU,
63
+ surfaceContext: surfaceContext
64
+ });
65
+ }, [components, formatMessage, query, surfaceContext]);
66
+ var itemCount = useMemo(function () {
67
+ return model.sections.reduce(function (count, _ref2) {
68
+ var _ref3 = _toArray(_ref2),
69
+ items = _arrayLikeToArray(_ref3).slice(1);
70
+ return count + items.length;
71
+ }, 0) + (model.footer ? 1 : 0);
72
+ }, [model.footer, model.sections]);
73
+ var isActiveItemMounted = selectedItemIndex >= 0 && selectedItemIndex < itemCount && (selectedItemIndex >= renderedItems.startIndex && selectedItemIndex <= renderedItems.stopIndex || Boolean(model.footer) && selectedItemIndex === itemCount - 1);
74
+ var activeItemId = "".concat(listId, "-").concat(selectedItemIndex);
75
+ var selectNextItem = useCallback(function () {
76
+ setSelectedItemIndex(function (index) {
77
+ return itemCount === 0 ? -1 : (index + 1) % itemCount;
78
+ });
79
+ }, [itemCount]);
80
+ var selectPreviousItem = useCallback(function () {
81
+ setSelectedItemIndex(function (index) {
82
+ return itemCount === 0 ? -1 : index <= 0 ? itemCount - 1 : index - 1;
83
+ });
84
+ }, [itemCount]);
85
+ var selectActiveItem = useCallback(function () {
86
+ if (isActiveItemMounted) {
87
+ var _getDocument;
88
+ (_getDocument = getDocument()) === null || _getDocument === void 0 || (_getDocument = _getDocument.getElementById(activeItemId)) === null || _getDocument === void 0 || _getDocument.click();
89
+ }
90
+ }, [activeItemId, isActiveItemMounted]);
91
+ var onQueryChange = useCallback(function (event) {
92
+ setQuery(event.currentTarget.value);
93
+ setSelectedItemIndex(0);
94
+ }, []);
95
+ var onKeyDown = useCallback(function (event) {
96
+ switch (event.key) {
97
+ case 'ArrowDown':
98
+ event.preventDefault();
99
+ selectNextItem();
100
+ break;
101
+ case 'ArrowUp':
102
+ event.preventDefault();
103
+ selectPreviousItem();
104
+ break;
105
+ case 'Enter':
106
+ event.preventDefault();
107
+ selectActiveItem();
108
+ break;
109
+ case 'Escape':
110
+ event.preventDefault();
111
+ onClose();
112
+ break;
113
+ }
114
+ }, [onClose, selectActiveItem, selectNextItem, selectPreviousItem]);
115
+ return /*#__PURE__*/React.createElement(Box, {
116
+ "data-registered-insert-menu": "",
117
+ testId: "registered-insert-menu",
118
+ onKeyDownCapture: onKeyDown,
119
+ xcss: styles.menu
120
+ }, /*#__PURE__*/React.createElement(Box, {
121
+ xcss: styles.search
122
+ }, /*#__PURE__*/React.createElement(Textfield, {
123
+ "aria-activedescendant": isActiveItemMounted ? activeItemId : undefined,
124
+ "aria-controls": listId,
125
+ "aria-expanded": "true",
126
+ autoFocus: true,
127
+ placeholder: "Search",
128
+ role: "combobox",
129
+ value: query,
130
+ onChange: onQueryChange
131
+ })), /*#__PURE__*/React.createElement(RegisteredInsertMenuList, {
132
+ editorView: editorView,
133
+ isOffline: isOffline,
134
+ listId: listId,
135
+ listLabel: formatMessage(messages.insertMenu),
136
+ maxHeight: DEFAULT_MENU_MAX_HEIGHT,
137
+ menuOpenId: menuOpenId,
138
+ model: model,
139
+ onClose: onSelect,
140
+ onItemHover: setSelectedItemIndex,
141
+ onRenderedItemsChange: setRenderedItems,
142
+ selectedItemIndex: selectedItemIndex,
143
+ surfaceContext: surfaceContext
144
+ }));
145
+ };
@@ -0,0 +1,44 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ import React, { useCallback, useContext, useState } from 'react';
3
+ import { MENU } from '@atlaskit/editor-common/quick-insert/keys';
4
+ import { PlainOutsideClickTargetRefContext, withOuterListeners } from '@atlaskit/editor-common/ui';
5
+ import { RegisteredInsertMenu } from './RegisteredInsertMenu';
6
+ var RegisteredInsertMenuContainer = function RegisteredInsertMenuContainer(_ref) {
7
+ var children = _ref.children;
8
+ var setOutsideClickTargetRef = useContext(PlainOutsideClickTargetRefContext);
9
+ return /*#__PURE__*/React.createElement("div", {
10
+ ref: setOutsideClickTargetRef
11
+ }, children);
12
+ };
13
+ var RegisteredInsertMenuWithListeners = withOuterListeners(RegisteredInsertMenuContainer);
14
+ export var RegisteredInsertMenuContent = function RegisteredInsertMenuContent(_ref2) {
15
+ var api = _ref2.api,
16
+ editorView = _ref2.editorView,
17
+ isOffline = _ref2.isOffline,
18
+ onClose = _ref2.onClose,
19
+ onDismiss = _ref2.onDismiss,
20
+ onSelect = _ref2.onSelect,
21
+ target = _ref2.target;
22
+ // Keep registrations stable while the open menu is searched or navigated.
23
+ var _useState = useState(function () {
24
+ var _api$uiControlRegistr, _api$uiControlRegistr2;
25
+ return (_api$uiControlRegistr = api === null || api === void 0 || (_api$uiControlRegistr2 = api.uiControlRegistry) === null || _api$uiControlRegistr2 === void 0 ? void 0 : _api$uiControlRegistr2.actions.getComponents(MENU.key)) !== null && _api$uiControlRegistr !== void 0 ? _api$uiControlRegistr : [];
26
+ }),
27
+ _useState2 = _slicedToArray(_useState, 1),
28
+ components = _useState2[0];
29
+ var onClickOutside = useCallback(function (event) {
30
+ if (event.target instanceof Node && target !== null && target !== void 0 && target.contains(event.target)) {
31
+ return;
32
+ }
33
+ onDismiss();
34
+ }, [onDismiss, target]);
35
+ return /*#__PURE__*/React.createElement(RegisteredInsertMenuWithListeners, {
36
+ handleClickOutside: onClickOutside
37
+ }, /*#__PURE__*/React.createElement(RegisteredInsertMenu, {
38
+ components: components,
39
+ editorView: editorView,
40
+ isOffline: isOffline,
41
+ onClose: onClose,
42
+ onSelect: onSelect
43
+ }));
44
+ };
@@ -0,0 +1,51 @@
1
+ import React, { useCallback, useMemo } from 'react';
2
+ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
3
+ import { insertSelectedItem } from '@atlaskit/editor-common/insert';
4
+ import { QuickInsertProvider } from '@atlaskit/editor-common/quick-insert/provider';
5
+ export var RegisteredInsertMenuItem = function RegisteredInsertMenuItem(_ref) {
6
+ var _registration$compone;
7
+ var editorView = _ref.editorView,
8
+ id = _ref.id,
9
+ isOffline = _ref.isOffline,
10
+ isSelected = _ref.isSelected,
11
+ menuOpenId = _ref.menuOpenId,
12
+ onClose = _ref.onClose,
13
+ registration = _ref.registration,
14
+ surfaceContext = _ref.surfaceContext;
15
+ var Component = (_registration$compone = registration.component) !== null && _registration$compone !== void 0 ? _registration$compone : React.Fragment;
16
+ var select = useCallback(function (selectionHandler) {
17
+ // Close first so a registered item may safely focus the editor or open its picker.
18
+ onClose();
19
+ queueMicrotask(function () {
20
+ var state = editorView.state;
21
+ var insert = function insert(content) {
22
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
23
+ return insertSelectedItem(content, options)(state, state.tr, state.selection.head);
24
+ };
25
+ var transaction = selectionHandler({
26
+ insert: insert,
27
+ source: INPUT_METHOD.INSERT_MENU
28
+ });
29
+ if (transaction) {
30
+ editorView.dispatch(transaction);
31
+ }
32
+ });
33
+ }, [editorView, onClose]);
34
+ var contextValue = useMemo(function () {
35
+ return {
36
+ editorView: editorView,
37
+ isOffline: isOffline,
38
+ item: {
39
+ id: id,
40
+ isSelected: isSelected
41
+ },
42
+ menuOpenId: menuOpenId,
43
+ select: select,
44
+ surface: 'toolbar',
45
+ surfaceContext: surfaceContext
46
+ };
47
+ }, [editorView, id, isOffline, isSelected, menuOpenId, select, surfaceContext]);
48
+ return /*#__PURE__*/React.createElement(QuickInsertProvider, {
49
+ value: contextValue
50
+ }, /*#__PURE__*/React.createElement(Component, null, null));
51
+ };
@@ -0,0 +1,4 @@
1
+ ._1rjc1b66{padding-block:var(--ds-space-050,4px)}._15a5nqa1{border-top-style:solid}
2
+ ._1i531l7x{border-top-color:var(--ds-border,#0b120e24)}
3
+ ._1o9zidpf{flex-shrink:0}
4
+ ._uwhke4h9{border-top-width:var(--ds-border-width,1px)}