@atlaskit/editor-core 185.2.7 → 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.
- package/CHANGELOG.md +6 -0
- package/dist/cjs/ui/ElementBrowser/ElementBrowser.js +4 -2
- package/dist/cjs/ui/ElementBrowser/InsertMenu.js +11 -30
- package/dist/cjs/ui/ElementBrowser/ViewMore.js +39 -0
- package/dist/cjs/ui/ElementBrowser/components/StatelessElementBrowser.js +16 -6
- package/dist/cjs/ui/ElementBrowser/hooks/use-select-and-focus-on-arrow-navigation.js +98 -26
- package/dist/cjs/version-wrapper.js +1 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/ui/ElementBrowser/ElementBrowser.js +4 -2
- package/dist/es2019/ui/ElementBrowser/InsertMenu.js +5 -35
- package/dist/es2019/ui/ElementBrowser/ViewMore.js +40 -0
- package/dist/es2019/ui/ElementBrowser/components/StatelessElementBrowser.js +16 -6
- package/dist/es2019/ui/ElementBrowser/hooks/use-select-and-focus-on-arrow-navigation.js +104 -26
- package/dist/es2019/version-wrapper.js +1 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/ui/ElementBrowser/ElementBrowser.js +4 -2
- package/dist/esm/ui/ElementBrowser/InsertMenu.js +12 -31
- package/dist/esm/ui/ElementBrowser/ViewMore.js +31 -0
- package/dist/esm/ui/ElementBrowser/components/StatelessElementBrowser.js +16 -6
- package/dist/esm/ui/ElementBrowser/hooks/use-select-and-focus-on-arrow-navigation.js +98 -26
- package/dist/esm/version-wrapper.js +1 -1
- package/dist/esm/version.json +1 -1
- package/dist/types/ui/ElementBrowser/ElementBrowser.d.ts +1 -0
- package/dist/types/ui/ElementBrowser/ViewMore.d.ts +6 -0
- package/dist/types/ui/ElementBrowser/components/StatelessElementBrowser.d.ts +2 -1
- package/dist/types/ui/ElementBrowser/hooks/use-select-and-focus-on-arrow-navigation.d.ts +7 -3
- package/dist/types/ui/ElementBrowser/types.d.ts +1 -1
- package/dist/types-ts4.5/ui/ElementBrowser/ElementBrowser.d.ts +1 -0
- package/dist/types-ts4.5/ui/ElementBrowser/ViewMore.d.ts +6 -0
- package/dist/types-ts4.5/ui/ElementBrowser/components/StatelessElementBrowser.d.ts +2 -1
- package/dist/types-ts4.5/ui/ElementBrowser/hooks/use-select-and-focus-on-arrow-navigation.d.ts +7 -3
- package/dist/types-ts4.5/ui/ElementBrowser/types.d.ts +1 -1
- package/package.json +2 -2
|
@@ -17,6 +17,7 @@ import { useCallback, useEffect, useRef, useReducer } from 'react';
|
|
|
17
17
|
* selectedItemIndex,
|
|
18
18
|
* focusedItemIndex,
|
|
19
19
|
* focusOnSearch,
|
|
20
|
+
* focusOnViewMore,
|
|
20
21
|
* setFocusedItemIndex,
|
|
21
22
|
* onKeyDown
|
|
22
23
|
* } = useSelectAndFocusOnArrowNavigation(list.length - 1, 1);
|
|
@@ -56,7 +57,8 @@ var reducer = function reducer(state, action) {
|
|
|
56
57
|
case ACTIONS.FOCUS_SEARCH:
|
|
57
58
|
return _objectSpread(_objectSpread({}, 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,55 +66,123 @@ var reducer = function reducer(state, action) {
|
|
|
64
66
|
return state;
|
|
65
67
|
};
|
|
66
68
|
var moveReducer = function moveReducer(state, action) {
|
|
67
|
-
var
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
var listSize = state.listSize,
|
|
70
|
+
canFocusViewMore = state.canFocusViewMore;
|
|
71
|
+
if (state.focusOnSearch) {
|
|
72
|
+
// up arrow
|
|
73
|
+
if (action.payload.positions && action.payload.positions <= -1) {
|
|
74
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
75
|
+
focusOnSearch: false,
|
|
76
|
+
focusOnViewMore: !!canFocusViewMore,
|
|
77
|
+
focusedItemIndex: canFocusViewMore ? undefined : listSize,
|
|
78
|
+
selectedItemIndex: canFocusViewMore ? undefined : listSize
|
|
79
|
+
});
|
|
80
|
+
} else {
|
|
81
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
82
|
+
focusOnSearch: false,
|
|
83
|
+
focusOnViewMore: false,
|
|
84
|
+
focusedItemIndex: 0,
|
|
85
|
+
selectedItemIndex: 0
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (state.focusOnViewMore) {
|
|
90
|
+
// down arrow
|
|
91
|
+
if (action.payload.positions === 1) {
|
|
92
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
93
|
+
focusOnSearch: true,
|
|
94
|
+
focusOnViewMore: false,
|
|
95
|
+
focusedItemIndex: undefined,
|
|
96
|
+
// if search is focused then select first item.
|
|
97
|
+
selectedItemIndex: 0
|
|
98
|
+
});
|
|
99
|
+
} else {
|
|
100
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
101
|
+
focusOnSearch: false,
|
|
102
|
+
focusOnViewMore: false,
|
|
103
|
+
focusedItemIndex: listSize,
|
|
104
|
+
selectedItemIndex: listSize
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
var newIndex = state.selectedItemIndex ? state.selectedItemIndex + action.payload.positions : action.payload.positions;
|
|
109
|
+
var safeIndex = ensureSafeIndex(newIndex, state.listSize);
|
|
110
|
+
// down arrow key is pressed or right arrow key is pressed.
|
|
111
|
+
if (state.focusedItemIndex !== undefined && action.payload.positions && action.payload.positions >= 1) {
|
|
112
|
+
// when multi column element browser is open and we are in last
|
|
113
|
+
// row then newIndex will be greater than listSize when
|
|
114
|
+
// down arrow key is pressed.
|
|
115
|
+
// Or when last item is focused and down or right arrow key is pressed.
|
|
116
|
+
var isLastItemFocused = newIndex > listSize;
|
|
117
|
+
var focusOnSearch = isLastItemFocused && !canFocusViewMore;
|
|
118
|
+
var focusOnViewMore = isLastItemFocused && !!canFocusViewMore;
|
|
119
|
+
// if search is focused, then select first item.
|
|
120
|
+
// otherwise if view more is focused then select item should be undefined.
|
|
121
|
+
var selectedItemIndex = focusOnSearch ? 0 : focusOnViewMore ? undefined : safeIndex;
|
|
72
122
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
73
|
-
focusOnSearch:
|
|
74
|
-
|
|
123
|
+
focusOnSearch: focusOnSearch,
|
|
124
|
+
focusOnViewMore: focusOnViewMore,
|
|
125
|
+
selectedItemIndex: selectedItemIndex,
|
|
126
|
+
focusedItemIndex: isLastItemFocused ? undefined : safeIndex
|
|
75
127
|
});
|
|
76
128
|
}
|
|
77
|
-
if (newIndex < 0) {
|
|
78
|
-
return state;
|
|
79
|
-
}
|
|
80
129
|
|
|
81
|
-
//
|
|
82
|
-
if (state.focusedItemIndex
|
|
130
|
+
// up arrow key is pressed or left arrow key is pressed.
|
|
131
|
+
if (state.focusedItemIndex !== undefined && action.payload.positions && action.payload.positions <= -1) {
|
|
132
|
+
// if arrow up key is pressed when focus is in first row,
|
|
133
|
+
// or, arrow left key is pressed when first item is focused,
|
|
134
|
+
// then newIndex will become less than zero.
|
|
135
|
+
// In this case, focus search, and, kept previously selected item.
|
|
136
|
+
var isFirstRowFocused = newIndex < 0;
|
|
137
|
+
// if focus goes to search then kept last selected item in first row.
|
|
138
|
+
var _selectedItemIndex = isFirstRowFocused ? state.selectedItemIndex : safeIndex;
|
|
83
139
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
140
|
+
// focus search if first item is focused on up or left arrow key
|
|
141
|
+
focusOnSearch: isFirstRowFocused,
|
|
142
|
+
focusOnViewMore: false,
|
|
143
|
+
focusedItemIndex: isFirstRowFocused ? undefined : safeIndex,
|
|
144
|
+
selectedItemIndex: _selectedItemIndex
|
|
87
145
|
});
|
|
88
146
|
}
|
|
89
|
-
var safeIndex = ensureSafeIndex(newIndex, state.listSize);
|
|
90
147
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
91
|
-
|
|
92
|
-
|
|
148
|
+
focusOnSearch: false,
|
|
149
|
+
focusOnViewMore: false,
|
|
150
|
+
selectedItemIndex: safeIndex,
|
|
151
|
+
focusedItemIndex: safeIndex
|
|
93
152
|
});
|
|
94
153
|
};
|
|
95
154
|
var initialState = {
|
|
96
155
|
focusOnSearch: true,
|
|
156
|
+
focusOnViewMore: false,
|
|
97
157
|
selectedItemIndex: 0,
|
|
98
158
|
focusedItemIndex: undefined,
|
|
99
159
|
listSize: 0
|
|
100
160
|
};
|
|
101
|
-
var getInitialState = function getInitialState(listSize) {
|
|
161
|
+
var getInitialState = function getInitialState(listSize, canFocusViewMore) {
|
|
102
162
|
return function (initialState) {
|
|
103
163
|
return _objectSpread(_objectSpread({}, initialState), {}, {
|
|
104
|
-
listSize: listSize
|
|
164
|
+
listSize: listSize,
|
|
165
|
+
canFocusViewMore: canFocusViewMore
|
|
105
166
|
});
|
|
106
167
|
};
|
|
107
168
|
};
|
|
108
|
-
function useSelectAndFocusOnArrowNavigation(listSize, step) {
|
|
109
|
-
var _useReducer = useReducer(reducer, initialState, getInitialState(listSize)),
|
|
169
|
+
function useSelectAndFocusOnArrowNavigation(listSize, step, canFocusViewMore) {
|
|
170
|
+
var _useReducer = useReducer(reducer, initialState, getInitialState(listSize, canFocusViewMore)),
|
|
110
171
|
_useReducer2 = _slicedToArray(_useReducer, 2),
|
|
111
172
|
state = _useReducer2[0],
|
|
112
173
|
dispatch = _useReducer2[1];
|
|
174
|
+
useEffect(function () {
|
|
175
|
+
dispatch({
|
|
176
|
+
type: ACTIONS.UPDATE_STATE,
|
|
177
|
+
payload: {
|
|
178
|
+
canFocusViewMore: canFocusViewMore
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
}, [canFocusViewMore]);
|
|
113
182
|
var selectedItemIndex = state.selectedItemIndex,
|
|
114
183
|
focusedItemIndex = state.focusedItemIndex,
|
|
115
|
-
focusOnSearch = state.focusOnSearch
|
|
184
|
+
focusOnSearch = state.focusOnSearch,
|
|
185
|
+
focusOnViewMore = state.focusOnViewMore;
|
|
116
186
|
var reset = useCallback(function (listSize) {
|
|
117
187
|
var payload = _objectSpread(_objectSpread({}, initialState), {}, {
|
|
118
188
|
listSize: listSize
|
|
@@ -126,7 +196,8 @@ function useSelectAndFocusOnArrowNavigation(listSize, step) {
|
|
|
126
196
|
var payload = {
|
|
127
197
|
focusedItemIndex: index,
|
|
128
198
|
selectedItemIndex: index,
|
|
129
|
-
focusOnSearch: false
|
|
199
|
+
focusOnSearch: false,
|
|
200
|
+
focusOnViewMore: false
|
|
130
201
|
};
|
|
131
202
|
dispatch({
|
|
132
203
|
type: ACTIONS.UPDATE_STATE,
|
|
@@ -162,7 +233,7 @@ function useSelectAndFocusOnArrowNavigation(listSize, step) {
|
|
|
162
233
|
var onKeyDown = useCallback(function (e) {
|
|
163
234
|
var avoidKeysWhileSearching = ['/',
|
|
164
235
|
// While already focused on search bar, let users type in.
|
|
165
|
-
'ArrowRight', 'ArrowLeft'
|
|
236
|
+
'ArrowRight', 'ArrowLeft'];
|
|
166
237
|
if (focusOnSearch && avoidKeysWhileSearching.includes(e.key)) {
|
|
167
238
|
return;
|
|
168
239
|
}
|
|
@@ -189,6 +260,7 @@ function useSelectAndFocusOnArrowNavigation(listSize, step) {
|
|
|
189
260
|
selectedItemIndex: selectedItemIndex,
|
|
190
261
|
onKeyDown: onKeyDown,
|
|
191
262
|
focusOnSearch: focusOnSearch,
|
|
263
|
+
focusOnViewMore: focusOnViewMore,
|
|
192
264
|
setFocusOnSearch: setFocusOnSearch,
|
|
193
265
|
focusedItemIndex: focusedItemIndex,
|
|
194
266
|
setFocusedItemIndex: removeFocusFromSearchAndSetOnItem
|
package/dist/esm/version.json
CHANGED
|
@@ -17,6 +17,7 @@ export type StatelessElementBrowserProps = {
|
|
|
17
17
|
mode: keyof typeof Modes;
|
|
18
18
|
searchTerm?: string;
|
|
19
19
|
emptyStateHandler?: EmptyStateHandler;
|
|
20
|
+
viewMoreItem?: QuickInsertItem;
|
|
20
21
|
} & WithAnalyticsEventsProps;
|
|
21
|
-
declare const MemoizedElementBrowser: React.MemoExoticComponent<React.ForwardRefExoticComponent<Pick<Omit<StatelessElementBrowserProps, keyof WithAnalyticsEventsProps> & React.RefAttributes<any> & import("@atlaskit/analytics-next").WithContextProps, "key" | "mode" | "analyticsContext" | "items" | "emptyStateHandler" | "selectedCategory" | "searchTerm" | "onInsertItem" | "categories" | "onSelectCategory" | "onSearch" | "onSelectItem" | "showCategories" | "showSearch"> & React.RefAttributes<any>>>;
|
|
22
|
+
declare const MemoizedElementBrowser: React.MemoExoticComponent<React.ForwardRefExoticComponent<Pick<Omit<StatelessElementBrowserProps, keyof WithAnalyticsEventsProps> & React.RefAttributes<any> & import("@atlaskit/analytics-next").WithContextProps, "key" | "mode" | "analyticsContext" | "items" | "emptyStateHandler" | "selectedCategory" | "searchTerm" | "onInsertItem" | "categories" | "onSelectCategory" | "onSearch" | "onSelectItem" | "viewMoreItem" | "showCategories" | "showSearch"> & React.RefAttributes<any>>>;
|
|
22
23
|
export default MemoizedElementBrowser;
|
|
@@ -12,6 +12,7 @@ import React from 'react';
|
|
|
12
12
|
* selectedItemIndex,
|
|
13
13
|
* focusedItemIndex,
|
|
14
14
|
* focusOnSearch,
|
|
15
|
+
* focusOnViewMore,
|
|
15
16
|
* setFocusedItemIndex,
|
|
16
17
|
* onKeyDown
|
|
17
18
|
* } = useSelectAndFocusOnArrowNavigation(list.length - 1, 1);
|
|
@@ -39,9 +40,11 @@ import React from 'react';
|
|
|
39
40
|
*/
|
|
40
41
|
type ReducerState = {
|
|
41
42
|
focusOnSearch: boolean;
|
|
42
|
-
|
|
43
|
+
focusOnViewMore: boolean;
|
|
44
|
+
selectedItemIndex?: number;
|
|
43
45
|
focusedItemIndex?: number;
|
|
44
46
|
listSize: number;
|
|
47
|
+
canFocusViewMore?: boolean;
|
|
45
48
|
};
|
|
46
49
|
export declare enum ACTIONS {
|
|
47
50
|
FOCUS_SEARCH = "focusOnSearch",
|
|
@@ -56,13 +59,14 @@ export type ReducerAction = {
|
|
|
56
59
|
};
|
|
57
60
|
};
|
|
58
61
|
export type useSelectAndFocusReturnType = {
|
|
59
|
-
selectedItemIndex
|
|
62
|
+
selectedItemIndex?: number;
|
|
60
63
|
onKeyDown: (e: React.KeyboardEvent<HTMLDivElement>) => void;
|
|
61
64
|
focusOnSearch: boolean;
|
|
65
|
+
focusOnViewMore: boolean;
|
|
62
66
|
focusedItemIndex?: number;
|
|
63
67
|
setFocusedItemIndex: (index?: number) => void;
|
|
64
68
|
setFocusOnSearch: () => void;
|
|
65
69
|
};
|
|
66
|
-
declare function useSelectAndFocusOnArrowNavigation(listSize: number, step: number): useSelectAndFocusReturnType;
|
|
70
|
+
declare function useSelectAndFocusOnArrowNavigation(listSize: number, step: number, canFocusViewMore: boolean): useSelectAndFocusReturnType;
|
|
67
71
|
export declare const ensureSafeIndex: (index: number, listSize: number) => number;
|
|
68
72
|
export default useSelectAndFocusOnArrowNavigation;
|
|
@@ -17,6 +17,7 @@ export type StatelessElementBrowserProps = {
|
|
|
17
17
|
mode: keyof typeof Modes;
|
|
18
18
|
searchTerm?: string;
|
|
19
19
|
emptyStateHandler?: EmptyStateHandler;
|
|
20
|
+
viewMoreItem?: QuickInsertItem;
|
|
20
21
|
} & WithAnalyticsEventsProps;
|
|
21
|
-
declare const MemoizedElementBrowser: React.MemoExoticComponent<React.ForwardRefExoticComponent<Pick<Omit<StatelessElementBrowserProps, keyof WithAnalyticsEventsProps> & React.RefAttributes<any> & import("@atlaskit/analytics-next").WithContextProps, "key" | "mode" | "analyticsContext" | "items" | "emptyStateHandler" | "selectedCategory" | "searchTerm" | "onInsertItem" | "categories" | "onSelectCategory" | "onSearch" | "onSelectItem" | "showCategories" | "showSearch"> & React.RefAttributes<any>>>;
|
|
22
|
+
declare const MemoizedElementBrowser: React.MemoExoticComponent<React.ForwardRefExoticComponent<Pick<Omit<StatelessElementBrowserProps, keyof WithAnalyticsEventsProps> & React.RefAttributes<any> & import("@atlaskit/analytics-next").WithContextProps, "key" | "mode" | "analyticsContext" | "items" | "emptyStateHandler" | "selectedCategory" | "searchTerm" | "onInsertItem" | "categories" | "onSelectCategory" | "onSearch" | "onSelectItem" | "viewMoreItem" | "showCategories" | "showSearch"> & React.RefAttributes<any>>>;
|
|
22
23
|
export default MemoizedElementBrowser;
|
package/dist/types-ts4.5/ui/ElementBrowser/hooks/use-select-and-focus-on-arrow-navigation.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ import React from 'react';
|
|
|
12
12
|
* selectedItemIndex,
|
|
13
13
|
* focusedItemIndex,
|
|
14
14
|
* focusOnSearch,
|
|
15
|
+
* focusOnViewMore,
|
|
15
16
|
* setFocusedItemIndex,
|
|
16
17
|
* onKeyDown
|
|
17
18
|
* } = useSelectAndFocusOnArrowNavigation(list.length - 1, 1);
|
|
@@ -39,9 +40,11 @@ import React from 'react';
|
|
|
39
40
|
*/
|
|
40
41
|
type ReducerState = {
|
|
41
42
|
focusOnSearch: boolean;
|
|
42
|
-
|
|
43
|
+
focusOnViewMore: boolean;
|
|
44
|
+
selectedItemIndex?: number;
|
|
43
45
|
focusedItemIndex?: number;
|
|
44
46
|
listSize: number;
|
|
47
|
+
canFocusViewMore?: boolean;
|
|
45
48
|
};
|
|
46
49
|
export declare enum ACTIONS {
|
|
47
50
|
FOCUS_SEARCH = "focusOnSearch",
|
|
@@ -56,13 +59,14 @@ export type ReducerAction = {
|
|
|
56
59
|
};
|
|
57
60
|
};
|
|
58
61
|
export type useSelectAndFocusReturnType = {
|
|
59
|
-
selectedItemIndex
|
|
62
|
+
selectedItemIndex?: number;
|
|
60
63
|
onKeyDown: (e: React.KeyboardEvent<HTMLDivElement>) => void;
|
|
61
64
|
focusOnSearch: boolean;
|
|
65
|
+
focusOnViewMore: boolean;
|
|
62
66
|
focusedItemIndex?: number;
|
|
63
67
|
setFocusedItemIndex: (index?: number) => void;
|
|
64
68
|
setFocusOnSearch: () => void;
|
|
65
69
|
};
|
|
66
|
-
declare function useSelectAndFocusOnArrowNavigation(listSize: number, step: number): useSelectAndFocusReturnType;
|
|
70
|
+
declare function useSelectAndFocusOnArrowNavigation(listSize: number, step: number, canFocusViewMore: boolean): useSelectAndFocusReturnType;
|
|
67
71
|
export declare const ensureSafeIndex: (index: number, listSize: number) => number;
|
|
68
72
|
export default useSelectAndFocusOnArrowNavigation;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-core",
|
|
3
|
-
"version": "185.2.
|
|
3
|
+
"version": "185.2.8",
|
|
4
4
|
"description": "A package contains Atlassian editor core functionality",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -181,7 +181,7 @@
|
|
|
181
181
|
"@atlaskit/visual-regression": "*",
|
|
182
182
|
"@atlaskit/webdriver-runner": "*",
|
|
183
183
|
"@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1",
|
|
184
|
-
"@atlassian/link-picker-plugins": "^22.
|
|
184
|
+
"@atlassian/link-picker-plugins": "^22.3.0",
|
|
185
185
|
"@atlassian/search-provider": "2.4.6",
|
|
186
186
|
"@atlassian/ufo": "^0.2.0",
|
|
187
187
|
"@emotion/jest": "^11.8.0",
|