@atlaskit/editor-core 185.2.5 → 185.2.8

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 (38) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/plugins/block-type/index.js +12 -9
  3. package/dist/cjs/ui/ElementBrowser/ElementBrowser.js +4 -2
  4. package/dist/cjs/ui/ElementBrowser/InsertMenu.js +11 -30
  5. package/dist/cjs/ui/ElementBrowser/ViewMore.js +39 -0
  6. package/dist/cjs/ui/ElementBrowser/components/StatelessElementBrowser.js +16 -6
  7. package/dist/cjs/ui/ElementBrowser/hooks/use-select-and-focus-on-arrow-navigation.js +98 -26
  8. package/dist/cjs/version-wrapper.js +1 -1
  9. package/dist/cjs/version.json +1 -1
  10. package/dist/es2019/plugins/block-type/index.js +12 -9
  11. package/dist/es2019/ui/ElementBrowser/ElementBrowser.js +4 -2
  12. package/dist/es2019/ui/ElementBrowser/InsertMenu.js +5 -35
  13. package/dist/es2019/ui/ElementBrowser/ViewMore.js +40 -0
  14. package/dist/es2019/ui/ElementBrowser/components/StatelessElementBrowser.js +16 -6
  15. package/dist/es2019/ui/ElementBrowser/hooks/use-select-and-focus-on-arrow-navigation.js +104 -26
  16. package/dist/es2019/version-wrapper.js +1 -1
  17. package/dist/es2019/version.json +1 -1
  18. package/dist/esm/plugins/block-type/index.js +12 -9
  19. package/dist/esm/ui/ElementBrowser/ElementBrowser.js +4 -2
  20. package/dist/esm/ui/ElementBrowser/InsertMenu.js +12 -31
  21. package/dist/esm/ui/ElementBrowser/ViewMore.js +31 -0
  22. package/dist/esm/ui/ElementBrowser/components/StatelessElementBrowser.js +16 -6
  23. package/dist/esm/ui/ElementBrowser/hooks/use-select-and-focus-on-arrow-navigation.js +98 -26
  24. package/dist/esm/version-wrapper.js +1 -1
  25. package/dist/esm/version.json +1 -1
  26. package/dist/types/plugins/block-type/index.d.ts +3 -1
  27. package/dist/types/ui/ElementBrowser/ElementBrowser.d.ts +1 -0
  28. package/dist/types/ui/ElementBrowser/ViewMore.d.ts +6 -0
  29. package/dist/types/ui/ElementBrowser/components/StatelessElementBrowser.d.ts +2 -1
  30. package/dist/types/ui/ElementBrowser/hooks/use-select-and-focus-on-arrow-navigation.d.ts +7 -3
  31. package/dist/types/ui/ElementBrowser/types.d.ts +1 -1
  32. package/dist/types-ts4.5/plugins/block-type/index.d.ts +5 -1
  33. package/dist/types-ts4.5/ui/ElementBrowser/ElementBrowser.d.ts +1 -0
  34. package/dist/types-ts4.5/ui/ElementBrowser/ViewMore.d.ts +6 -0
  35. package/dist/types-ts4.5/ui/ElementBrowser/components/StatelessElementBrowser.d.ts +2 -1
  36. package/dist/types-ts4.5/ui/ElementBrowser/hooks/use-select-and-focus-on-arrow-navigation.d.ts +7 -3
  37. package/dist/types-ts4.5/ui/ElementBrowser/types.d.ts +1 -1
  38. package/package.json +3 -3
@@ -1,8 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  /** @jsx jsx */
3
- import { useState, useCallback } from 'react';
3
+ import { useCallback, useState } from 'react';
4
4
  import { css, jsx } from '@emotion/react';
5
- import { Section, ButtonItem } from '@atlaskit/menu';
6
5
  // AFP-2532 TODO: Fix automatic suppressions below
7
6
  // eslint-disable-next-line @atlassian/tangerine/import/entry-points
8
7
  import { borderRadius } from '@atlaskit/theme';
@@ -39,7 +38,7 @@ const InsertMenu = ({
39
38
  value: item.value
40
39
  }), [onInsert]);
41
40
  const quickInsertDropdownItems = dropdownItems.map(transform);
42
- const viewMoreItem = showElementBrowserLink && quickInsertDropdownItems.pop();
41
+ const viewMoreItem = showElementBrowserLink ? quickInsertDropdownItems.pop() : undefined;
43
42
  const onInsertItem = useCallback(item => {
44
43
  toggleVisiblity();
45
44
  if (!editorView.hasFocus()) {
@@ -71,8 +70,9 @@ const InsertMenu = ({
71
70
  showCategories: false
72
71
  // On page resize we want the InlineElementBrowser to show updated tools/overflow items
73
72
  ,
74
- key: quickInsertDropdownItems.length
75
- })), [getItems, onInsertItem, quickInsertDropdownItems.length, toggleVisiblity]);
73
+ key: quickInsertDropdownItems.length,
74
+ viewMoreItem: viewMoreItem
75
+ })), [getItems, onInsertItem, quickInsertDropdownItems.length, toggleVisiblity, viewMoreItem]);
76
76
  return jsx("div", {
77
77
  css: theme => insertMenuWrapper(theme, itemCount)
78
78
  }, jsx(WithPluginState, {
@@ -80,29 +80,8 @@ const InsertMenu = ({
80
80
  quickInsertState: pluginKey
81
81
  },
82
82
  render: render
83
- }), itemCount > 0 && viewMoreItem && jsx(ViewMore, {
84
- item: viewMoreItem
85
83
  }));
86
84
  };
87
- const ViewMore = ({
88
- item
89
- }) => {
90
- return jsx(Section, {
91
- hasSeparator: true
92
- }, jsx(ButtonItem, {
93
- onClick: item.action,
94
- iconBefore: jsx("div", {
95
- css: itemBefore
96
- }, item.icon()),
97
- "aria-describedby": item.title,
98
- "data-testid": "view-more-elements-item"
99
- // @ts-ignore Overriding Menu styles is not supported
100
- ,
101
- css: css`
102
- padding: 0px 12px;
103
- `
104
- }, item.title));
105
- };
106
85
  const getSvgIconForItem = ({
107
86
  name
108
87
  }) => {
@@ -147,15 +126,6 @@ const insertMenuWrapper = (theme, itemCount) => css`
147
126
  0 2px 1px ${N30A},
148
127
  0 0 20px -6px ${N60A}`})`};
149
128
  `;
150
- const itemBefore = css`
151
- width: 40px;
152
- height: 40px;
153
- box-sizing: border-box;
154
- display: flex;
155
- justify-content: center;
156
- align-items: center;
157
- margin-right: ${"var(--ds-space-050, 4px)"};
158
- `;
159
129
  const flexWrapperStyles = css`
160
130
  display: flex;
161
131
  flex: 1;
@@ -0,0 +1,40 @@
1
+ /** @jsx jsx */
2
+ import { useEffect, useRef } from 'react';
3
+ import { css, jsx } from '@emotion/react';
4
+ import { Section, ButtonItem } from '@atlaskit/menu';
5
+ const itemBefore = css`
6
+ width: 40px;
7
+ height: 40px;
8
+ box-sizing: border-box;
9
+ display: flex;
10
+ justify-content: center;
11
+ align-items: center;
12
+ margin-right: ${"var(--ds-space-050, 4px)"};
13
+ `;
14
+ export const ViewMore = ({
15
+ item,
16
+ focus
17
+ }) => {
18
+ const ref = useRef(null);
19
+ useEffect(() => {
20
+ if (ref.current && focus) {
21
+ ref.current.focus();
22
+ }
23
+ }, [focus]);
24
+ return jsx(Section, {
25
+ hasSeparator: true
26
+ }, jsx(ButtonItem, {
27
+ onClick: item.action,
28
+ iconBefore: jsx("div", {
29
+ css: itemBefore
30
+ }, item.icon()),
31
+ "aria-describedby": item.title,
32
+ "data-testid": "view-more-elements-item"
33
+ // @ts-ignore Overriding Menu styles is not supported
34
+ ,
35
+ css: css`
36
+ padding: 0px 12px;
37
+ `,
38
+ ref: ref
39
+ }, item.title));
40
+ };
@@ -11,6 +11,7 @@ import ElementSearch from './ElementSearch';
11
11
  import { DEVICE_BREAKPOINT_NUMBERS, GRID_SIZE, INLINE_SIDEBAR_HEIGHT, SIDEBAR_HEADING_PADDING_LEFT, SIDEBAR_HEADING_WRAPPER_HEIGHT, SIDEBAR_WIDTH } from '../constants';
12
12
  import useContainerWidth from '../hooks/use-container-width';
13
13
  import useSelectAndFocusOnArrowNavigation from '../hooks/use-select-and-focus-on-arrow-navigation';
14
+ import { ViewMore } from '../ViewMore';
14
15
  const wrapper = css`
15
16
  width: 100%;
16
17
  max-height: inherit;
@@ -109,7 +110,8 @@ const categoryListWrapper = css`
109
110
  function StatelessElementBrowser(props) {
110
111
  const {
111
112
  items,
112
- onSelectItem
113
+ onSelectItem,
114
+ viewMoreItem
113
115
  } = props;
114
116
  const {
115
117
  containerWidth,
@@ -121,9 +123,10 @@ function StatelessElementBrowser(props) {
121
123
  focusedItemIndex,
122
124
  setFocusedItemIndex,
123
125
  focusOnSearch,
126
+ focusOnViewMore,
124
127
  onKeyDown,
125
128
  setFocusOnSearch
126
- } = useSelectAndFocusOnArrowNavigation(items.length - 1, columnCount);
129
+ } = useSelectAndFocusOnArrowNavigation(items.length - 1, columnCount, !!viewMoreItem);
127
130
  useEffect(() => {
128
131
  fireAnalyticsEvent(props.createAnalyticsEvent)({
129
132
  payload: {
@@ -152,7 +155,7 @@ function StatelessElementBrowser(props) {
152
155
  /* Only for hitting enter to select item when focused on search bar,
153
156
  * The actual enter key press is handled on individual items level.
154
157
  */
155
- const selectedItem = items[selectedItemIndex];
158
+ const selectedItem = selectedItemIndex !== undefined ? items[selectedItemIndex] : null;
156
159
  const onItemsEnterKeyPress = useCallback(e => {
157
160
  if (e.key !== 'Enter') {
158
161
  return;
@@ -182,7 +185,9 @@ function StatelessElementBrowser(props) {
182
185
  setColumnCount: setColumnCount,
183
186
  setFocusOnSearch: setFocusOnSearch,
184
187
  onKeyPress: onItemsEnterKeyPress,
185
- onKeyDown: onKeyDown
188
+ onKeyDown: onKeyDown,
189
+ viewMoreItem: viewMoreItem,
190
+ focusOnViewMore: focusOnViewMore
186
191
  })) : jsx(DesktopBrowser, _extends({}, props, {
187
192
  selectedItemIndex: selectedItemIndex,
188
193
  focusedItemIndex: focusedItemIndex,
@@ -208,13 +213,15 @@ function MobileBrowser({
208
213
  focusedItemIndex,
209
214
  setFocusedItemIndex,
210
215
  focusOnSearch,
216
+ focusOnViewMore,
211
217
  setColumnCount,
212
218
  setFocusOnSearch,
213
219
  onKeyPress,
214
220
  onKeyDown,
215
221
  searchTerm,
216
222
  createAnalyticsEvent,
217
- emptyStateHandler
223
+ emptyStateHandler,
224
+ viewMoreItem
218
225
  }) {
219
226
  return jsx("div", {
220
227
  css: mobileElementBrowserContainer,
@@ -250,7 +257,10 @@ function MobileBrowser({
250
257
  emptyStateHandler: emptyStateHandler,
251
258
  selectedCategory: selectedCategory,
252
259
  searchTerm: searchTerm
253
- })));
260
+ })), viewMoreItem && jsx(ViewMore, {
261
+ item: viewMoreItem,
262
+ focus: focusOnViewMore
263
+ }));
254
264
  }
255
265
  function DesktopBrowser({
256
266
  showCategories,
@@ -13,6 +13,7 @@ import { useCallback, useEffect, useRef, useReducer } from 'react';
13
13
  * selectedItemIndex,
14
14
  * focusedItemIndex,
15
15
  * focusOnSearch,
16
+ * focusOnViewMore,
16
17
  * setFocusedItemIndex,
17
18
  * onKeyDown
18
19
  * } = useSelectAndFocusOnArrowNavigation(list.length - 1, 1);
@@ -56,7 +57,8 @@ const reducer = (state, action) => {
56
57
  return {
57
58
  ...state,
58
59
  focusedItemIndex: undefined,
59
- focusOnSearch: true
60
+ focusOnSearch: true,
61
+ focusOnViewMore: false
60
62
  };
61
63
  case ACTIONS.MOVE:
62
64
  return moveReducer(state, action);
@@ -64,53 +66,127 @@ const reducer = (state, action) => {
64
66
  return state;
65
67
  };
66
68
  const moveReducer = (state, action) => {
67
- const newIndex = state.selectedItemIndex + action.payload.positions;
68
-
69
- // The step payload is only sent for up arrow.
70
- // When user presses up arrow on first row, focus on search bar.
71
- if (action.payload.step && state.selectedItemIndex < action.payload.step) {
69
+ const {
70
+ listSize,
71
+ canFocusViewMore
72
+ } = state;
73
+ if (state.focusOnSearch) {
74
+ // up arrow
75
+ if (action.payload.positions && action.payload.positions <= -1) {
76
+ return {
77
+ ...state,
78
+ focusOnSearch: false,
79
+ focusOnViewMore: !!canFocusViewMore,
80
+ focusedItemIndex: canFocusViewMore ? undefined : listSize,
81
+ selectedItemIndex: canFocusViewMore ? undefined : listSize
82
+ };
83
+ } else {
84
+ return {
85
+ ...state,
86
+ focusOnSearch: false,
87
+ focusOnViewMore: false,
88
+ focusedItemIndex: 0,
89
+ selectedItemIndex: 0
90
+ };
91
+ }
92
+ }
93
+ if (state.focusOnViewMore) {
94
+ // down arrow
95
+ if (action.payload.positions === 1) {
96
+ return {
97
+ ...state,
98
+ focusOnSearch: true,
99
+ focusOnViewMore: false,
100
+ focusedItemIndex: undefined,
101
+ // if search is focused then select first item.
102
+ selectedItemIndex: 0
103
+ };
104
+ } else {
105
+ return {
106
+ ...state,
107
+ focusOnSearch: false,
108
+ focusOnViewMore: false,
109
+ focusedItemIndex: listSize,
110
+ selectedItemIndex: listSize
111
+ };
112
+ }
113
+ }
114
+ const newIndex = state.selectedItemIndex ? state.selectedItemIndex + action.payload.positions : action.payload.positions;
115
+ const safeIndex = ensureSafeIndex(newIndex, state.listSize);
116
+ // down arrow key is pressed or right arrow key is pressed.
117
+ if (state.focusedItemIndex !== undefined && action.payload.positions && action.payload.positions >= 1) {
118
+ // when multi column element browser is open and we are in last
119
+ // row then newIndex will be greater than listSize when
120
+ // down arrow key is pressed.
121
+ // Or when last item is focused and down or right arrow key is pressed.
122
+ const isLastItemFocused = newIndex > listSize;
123
+ const focusOnSearch = isLastItemFocused && !canFocusViewMore;
124
+ const focusOnViewMore = isLastItemFocused && !!canFocusViewMore;
125
+ // if search is focused, then select first item.
126
+ // otherwise if view more is focused then select item should be undefined.
127
+ const selectedItemIndex = focusOnSearch ? 0 : focusOnViewMore ? undefined : safeIndex;
72
128
  return {
73
129
  ...state,
74
- focusOnSearch: true,
75
- focusedItemIndex: undefined
130
+ focusOnSearch,
131
+ focusOnViewMore,
132
+ selectedItemIndex,
133
+ focusedItemIndex: isLastItemFocused ? undefined : safeIndex
76
134
  };
77
135
  }
78
- if (newIndex < 0) {
79
- return state;
80
- }
81
136
 
82
- // Set focus position to first item when moving forward or backward from searchbar
83
- if (state.focusedItemIndex == null || state.focusOnSearch) {
137
+ // up arrow key is pressed or left arrow key is pressed.
138
+ if (state.focusedItemIndex !== undefined && action.payload.positions && action.payload.positions <= -1) {
139
+ // if arrow up key is pressed when focus is in first row,
140
+ // or, arrow left key is pressed when first item is focused,
141
+ // then newIndex will become less than zero.
142
+ // In this case, focus search, and, kept previously selected item.
143
+ const isFirstRowFocused = newIndex < 0;
144
+ // if focus goes to search then kept last selected item in first row.
145
+ const selectedItemIndex = isFirstRowFocused ? state.selectedItemIndex : safeIndex;
84
146
  return {
85
147
  ...state,
86
- focusOnSearch: false,
87
- focusedItemIndex: 0,
88
- selectedItemIndex: 0
148
+ // focus search if first item is focused on up or left arrow key
149
+ focusOnSearch: isFirstRowFocused,
150
+ focusOnViewMore: false,
151
+ focusedItemIndex: isFirstRowFocused ? undefined : safeIndex,
152
+ selectedItemIndex
89
153
  };
90
154
  }
91
- const safeIndex = ensureSafeIndex(newIndex, state.listSize);
92
155
  return {
93
156
  ...state,
94
- focusedItemIndex: safeIndex,
95
- selectedItemIndex: safeIndex
157
+ focusOnSearch: false,
158
+ focusOnViewMore: false,
159
+ selectedItemIndex: safeIndex,
160
+ focusedItemIndex: safeIndex
96
161
  };
97
162
  };
98
163
  const initialState = {
99
164
  focusOnSearch: true,
165
+ focusOnViewMore: false,
100
166
  selectedItemIndex: 0,
101
167
  focusedItemIndex: undefined,
102
168
  listSize: 0
103
169
  };
104
- const getInitialState = listSize => initialState => ({
170
+ const getInitialState = (listSize, canFocusViewMore) => initialState => ({
105
171
  ...initialState,
106
- listSize
172
+ listSize,
173
+ canFocusViewMore
107
174
  });
108
- function useSelectAndFocusOnArrowNavigation(listSize, step) {
109
- const [state, dispatch] = useReducer(reducer, initialState, getInitialState(listSize));
175
+ function useSelectAndFocusOnArrowNavigation(listSize, step, canFocusViewMore) {
176
+ const [state, dispatch] = useReducer(reducer, initialState, getInitialState(listSize, canFocusViewMore));
177
+ useEffect(() => {
178
+ dispatch({
179
+ type: ACTIONS.UPDATE_STATE,
180
+ payload: {
181
+ canFocusViewMore
182
+ }
183
+ });
184
+ }, [canFocusViewMore]);
110
185
  const {
111
186
  selectedItemIndex,
112
187
  focusedItemIndex,
113
- focusOnSearch
188
+ focusOnSearch,
189
+ focusOnViewMore
114
190
  } = state;
115
191
  const reset = useCallback(listSize => {
116
192
  let payload = {
@@ -126,7 +202,8 @@ function useSelectAndFocusOnArrowNavigation(listSize, step) {
126
202
  const payload = {
127
203
  focusedItemIndex: index,
128
204
  selectedItemIndex: index,
129
- focusOnSearch: false
205
+ focusOnSearch: false,
206
+ focusOnViewMore: false
130
207
  };
131
208
  dispatch({
132
209
  type: ACTIONS.UPDATE_STATE,
@@ -162,7 +239,7 @@ function useSelectAndFocusOnArrowNavigation(listSize, step) {
162
239
  const onKeyDown = useCallback(e => {
163
240
  const avoidKeysWhileSearching = ['/',
164
241
  // While already focused on search bar, let users type in.
165
- 'ArrowRight', 'ArrowLeft', 'ArrowUp'];
242
+ 'ArrowRight', 'ArrowLeft'];
166
243
  if (focusOnSearch && avoidKeysWhileSearching.includes(e.key)) {
167
244
  return;
168
245
  }
@@ -189,6 +266,7 @@ function useSelectAndFocusOnArrowNavigation(listSize, step) {
189
266
  selectedItemIndex,
190
267
  onKeyDown,
191
268
  focusOnSearch,
269
+ focusOnViewMore,
192
270
  setFocusOnSearch,
193
271
  focusedItemIndex,
194
272
  setFocusedItemIndex: removeFocusFromSearchAndSetOnItem
@@ -1,5 +1,5 @@
1
1
  export const name = "@atlaskit/editor-core";
2
- export const version = "185.2.5";
2
+ export const version = "185.2.8";
3
3
  export const nextMajorVersion = () => {
4
4
  return [Number(version.split('.')[0]) + 1, 0, 0].join('.');
5
5
  };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-core",
3
- "version": "185.2.5",
3
+ "version": "185.2.8",
4
4
  "sideEffects": false
5
5
  }
@@ -7,12 +7,12 @@ import inputRulePlugin from './pm-plugins/input-rule';
7
7
  import ToolbarBlockType from './ui/ToolbarBlockType';
8
8
  import WithPluginState from '../../ui/WithPluginState';
9
9
  import { setBlockTypeWithAnalytics } from './commands';
10
- import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, addAnalytics, EVENT_TYPE, INPUT_METHOD } from '../analytics';
10
+ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
11
11
  import * as keymaps from '../../keymaps';
12
12
  import { IconHeading, IconQuote } from '../quick-insert/assets';
13
13
  import { messages } from './messages';
14
14
  import { ToolbarSize } from '../../ui/Toolbar/types';
15
- var headingPluginOptions = function headingPluginOptions(_ref, isAllowed) {
15
+ var headingPluginOptions = function headingPluginOptions(_ref, isAllowed, editorAnalyticsApi) {
16
16
  var formatMessage = _ref.formatMessage;
17
17
  if (!isAllowed) {
18
18
  return [];
@@ -40,7 +40,7 @@ var headingPluginOptions = function headingPluginOptions(_ref, isAllowed) {
40
40
  var tr = insert(state.schema.nodes.heading.createChecked({
41
41
  level: level
42
42
  }));
43
- return addAnalytics(state, tr, {
43
+ editorAnalyticsApi === null || editorAnalyticsApi === void 0 ? void 0 : editorAnalyticsApi.attachAnalyticsEvent({
44
44
  action: ACTION.FORMATTED,
45
45
  actionSubject: ACTION_SUBJECT.TEXT,
46
46
  eventType: EVENT_TYPE.TRACK,
@@ -49,12 +49,13 @@ var headingPluginOptions = function headingPluginOptions(_ref, isAllowed) {
49
49
  inputMethod: INPUT_METHOD.QUICK_INSERT,
50
50
  newHeadingLevel: level
51
51
  }
52
- });
52
+ })(tr);
53
+ return tr;
53
54
  }
54
55
  };
55
56
  });
56
57
  };
57
- var blockquotePluginOptions = function blockquotePluginOptions(_ref2, isAllowed) {
58
+ var blockquotePluginOptions = function blockquotePluginOptions(_ref2, isAllowed, editorAnalyticsApi) {
58
59
  var formatMessage = _ref2.formatMessage;
59
60
  if (!isAllowed) {
60
61
  return [];
@@ -70,7 +71,7 @@ var blockquotePluginOptions = function blockquotePluginOptions(_ref2, isAllowed)
70
71
  },
71
72
  action: function action(insert, state) {
72
73
  var tr = insert(state.schema.nodes.blockquote.createChecked({}, state.schema.nodes.paragraph.createChecked()));
73
- return addAnalytics(state, tr, {
74
+ editorAnalyticsApi === null || editorAnalyticsApi === void 0 ? void 0 : editorAnalyticsApi.attachAnalyticsEvent({
74
75
  action: ACTION.FORMATTED,
75
76
  actionSubject: ACTION_SUBJECT.TEXT,
76
77
  eventType: EVENT_TYPE.TRACK,
@@ -78,11 +79,12 @@ var blockquotePluginOptions = function blockquotePluginOptions(_ref2, isAllowed)
78
79
  attributes: {
79
80
  inputMethod: INPUT_METHOD.QUICK_INSERT
80
81
  }
81
- });
82
+ })(tr);
83
+ return tr;
82
84
  }
83
85
  }];
84
86
  };
85
- var blockTypePlugin = function blockTypePlugin(options) {
87
+ var blockTypePlugin = function blockTypePlugin(options, api) {
86
88
  return {
87
89
  name: 'blockType',
88
90
  nodes: function nodes() {
@@ -166,8 +168,9 @@ var blockTypePlugin = function blockTypePlugin(options) {
166
168
  },
167
169
  pluginsOptions: {
168
170
  quickInsert: function quickInsert(intl) {
171
+ var _api$dependencies$ana, _api$dependencies$ana2;
169
172
  var exclude = options && options.allowBlockType && options.allowBlockType.exclude ? options.allowBlockType.exclude : [];
170
- return [].concat(_toConsumableArray(blockquotePluginOptions(intl, exclude.indexOf('blockquote') === -1)), _toConsumableArray(headingPluginOptions(intl, exclude.indexOf('heading') === -1)));
173
+ return [].concat(_toConsumableArray(blockquotePluginOptions(intl, exclude.indexOf('blockquote') === -1, api === null || api === void 0 ? void 0 : (_api$dependencies$ana = api.dependencies.analytics) === null || _api$dependencies$ana === void 0 ? void 0 : _api$dependencies$ana.actions)), _toConsumableArray(headingPluginOptions(intl, exclude.indexOf('heading') === -1, api === null || api === void 0 ? void 0 : (_api$dependencies$ana2 = api.dependencies.analytics) === null || _api$dependencies$ana2 === void 0 ? void 0 : _api$dependencies$ana2.actions)));
171
174
  }
172
175
  }
173
176
  };
@@ -109,7 +109,8 @@ var ElementBrowser = /*#__PURE__*/function (_PureComponent) {
109
109
  showSearch = _this$props.showSearch,
110
110
  showCategories = _this$props.showCategories,
111
111
  mode = _this$props.mode,
112
- emptyStateHandler = _this$props.emptyStateHandler;
112
+ emptyStateHandler = _this$props.emptyStateHandler,
113
+ viewMoreItem = _this$props.viewMoreItem;
113
114
  var _this$state2 = this.state,
114
115
  categories = _this$state2.categories,
115
116
  searchTerm = _this$state2.searchTerm,
@@ -127,7 +128,8 @@ var ElementBrowser = /*#__PURE__*/function (_PureComponent) {
127
128
  showCategories: showCategories,
128
129
  mode: mode,
129
130
  searchTerm: searchTerm,
130
- emptyStateHandler: emptyStateHandler
131
+ emptyStateHandler: emptyStateHandler,
132
+ viewMoreItem: viewMoreItem
131
133
  });
132
134
  }
133
135
  }]);
@@ -3,11 +3,10 @@ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProper
3
3
  import _taggedTemplateLiteral from "@babel/runtime/helpers/taggedTemplateLiteral";
4
4
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
5
5
  var _excluded = ["children"];
6
- var _templateObject, _templateObject2, _templateObject3, _templateObject4;
6
+ var _templateObject, _templateObject2;
7
7
  /** @jsx jsx */
8
- import { useState, useCallback } from 'react';
8
+ import { useCallback, useState } from 'react';
9
9
  import { css, jsx } from '@emotion/react';
10
- import { Section, ButtonItem } from '@atlaskit/menu';
11
10
  // AFP-2532 TODO: Fix automatic suppressions below
12
11
  // eslint-disable-next-line @atlassian/tangerine/import/entry-points
13
12
  import { borderRadius } from '@atlaskit/theme';
@@ -52,7 +51,7 @@ var InsertMenu = function InsertMenu(_ref) {
52
51
  };
53
52
  }, [onInsert]);
54
53
  var quickInsertDropdownItems = dropdownItems.map(transform);
55
- var viewMoreItem = showElementBrowserLink && quickInsertDropdownItems.pop();
54
+ var viewMoreItem = showElementBrowserLink ? quickInsertDropdownItems.pop() : undefined;
56
55
  var onInsertItem = useCallback(function (item) {
57
56
  toggleVisiblity();
58
57
  if (!editorView.hasFocus()) {
@@ -86,9 +85,10 @@ var InsertMenu = function InsertMenu(_ref) {
86
85
  showCategories: false
87
86
  // On page resize we want the InlineElementBrowser to show updated tools/overflow items
88
87
  ,
89
- key: quickInsertDropdownItems.length
88
+ key: quickInsertDropdownItems.length,
89
+ viewMoreItem: viewMoreItem
90
90
  }));
91
- }, [getItems, onInsertItem, quickInsertDropdownItems.length, toggleVisiblity]);
91
+ }, [getItems, onInsertItem, quickInsertDropdownItems.length, toggleVisiblity, viewMoreItem]);
92
92
  return jsx("div", {
93
93
  css: function css(theme) {
94
94
  return insertMenuWrapper(theme, itemCount);
@@ -98,28 +98,10 @@ var InsertMenu = function InsertMenu(_ref) {
98
98
  quickInsertState: pluginKey
99
99
  },
100
100
  render: render
101
- }), itemCount > 0 && viewMoreItem && jsx(ViewMore, {
102
- item: viewMoreItem
103
101
  }));
104
102
  };
105
- var ViewMore = function ViewMore(_ref3) {
106
- var item = _ref3.item;
107
- return jsx(Section, {
108
- hasSeparator: true
109
- }, jsx(ButtonItem, {
110
- onClick: item.action,
111
- iconBefore: jsx("div", {
112
- css: itemBefore
113
- }, item.icon()),
114
- "aria-describedby": item.title,
115
- "data-testid": "view-more-elements-item"
116
- // @ts-ignore Overriding Menu styles is not supported
117
- ,
118
- css: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n padding: 0px 12px;\n "])))
119
- }, item.title));
120
- };
121
- var getSvgIconForItem = function getSvgIconForItem(_ref4) {
122
- var name = _ref4.name;
103
+ var getSvgIconForItem = function getSvgIconForItem(_ref3) {
104
+ var name = _ref3.name;
123
105
  var Icon = {
124
106
  codeblock: IconCode,
125
107
  panel: IconPanel,
@@ -134,8 +116,8 @@ var getSvgIconForItem = function getSvgIconForItem(_ref4) {
134
116
  label: ""
135
117
  }) : undefined;
136
118
  };
137
- var getInsertMenuHeight = function getInsertMenuHeight(_ref5) {
138
- var itemCount = _ref5.itemCount;
119
+ var getInsertMenuHeight = function getInsertMenuHeight(_ref4) {
120
+ var itemCount = _ref4.itemCount;
139
121
  // Figure based on visuals to exclude the searchbar, padding/margin, and the ViewMore item.
140
122
  var EXTRA_SPACE_EXCLUDING_ELEMENTLIST = 112;
141
123
  if (itemCount > 0 && itemCount < 6) {
@@ -145,15 +127,14 @@ var getInsertMenuHeight = function getInsertMenuHeight(_ref5) {
145
127
  };
146
128
 
147
129
  var insertMenuWrapper = function insertMenuWrapper(theme, itemCount) {
148
- return css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n display: flex;\n flex-direction: column;\n width: 320px;\n height: ", "px;\n background-color: ", ";\n border-radius: ", "px;\n box-shadow: ", ";\n"])), getInsertMenuHeight({
130
+ return css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: flex;\n flex-direction: column;\n width: 320px;\n height: ", "px;\n background-color: ", ";\n border-radius: ", "px;\n box-shadow: ", ";\n"])), getInsertMenuHeight({
149
131
  itemCount: itemCount
150
132
  }), themed({
151
133
  light: "var(--ds-surface-overlay, ".concat(N0, ")"),
152
134
  dark: "var(--ds-surface-overlay, ".concat(DN50, ")")
153
135
  })(theme), borderRadius(), "var(--ds-shadow-overlay, ".concat("0 0 0 1px ".concat(N30A, ",\n 0 2px 1px ").concat(N30A, ",\n 0 0 20px -6px ").concat(N60A), ")"));
154
136
  };
155
- var itemBefore = css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n width: 40px;\n height: 40px;\n box-sizing: border-box;\n display: flex;\n justify-content: center;\n align-items: center;\n margin-right: ", ";\n"])), "var(--ds-space-050, 4px)");
156
- var flexWrapperStyles = css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n display: flex;\n flex: 1;\n box-sizing: border-box;\n overflow: hidden;\n"])));
137
+ var flexWrapperStyles = css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n display: flex;\n flex: 1;\n box-sizing: border-box;\n overflow: hidden;\n"])));
157
138
  var FlexWrapper = function FlexWrapper(props) {
158
139
  var children = props.children,
159
140
  divProps = _objectWithoutProperties(props, _excluded);
@@ -0,0 +1,31 @@
1
+ import _taggedTemplateLiteral from "@babel/runtime/helpers/taggedTemplateLiteral";
2
+ var _templateObject, _templateObject2;
3
+ /** @jsx jsx */
4
+ import { useEffect, useRef } from 'react';
5
+ import { css, jsx } from '@emotion/react';
6
+ import { Section, ButtonItem } from '@atlaskit/menu';
7
+ var itemBefore = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n width: 40px;\n height: 40px;\n box-sizing: border-box;\n display: flex;\n justify-content: center;\n align-items: center;\n margin-right: ", ";\n"])), "var(--ds-space-050, 4px)");
8
+ export var ViewMore = function ViewMore(_ref) {
9
+ var item = _ref.item,
10
+ focus = _ref.focus;
11
+ var ref = useRef(null);
12
+ useEffect(function () {
13
+ if (ref.current && focus) {
14
+ ref.current.focus();
15
+ }
16
+ }, [focus]);
17
+ return jsx(Section, {
18
+ hasSeparator: true
19
+ }, jsx(ButtonItem, {
20
+ onClick: item.action,
21
+ iconBefore: jsx("div", {
22
+ css: itemBefore
23
+ }, item.icon()),
24
+ "aria-describedby": item.title,
25
+ "data-testid": "view-more-elements-item"
26
+ // @ts-ignore Overriding Menu styles is not supported
27
+ ,
28
+ css: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n padding: 0px 12px;\n "]))),
29
+ ref: ref
30
+ }, item.title));
31
+ };