@atlaskit/editor-plugin-code-block 14.1.14 → 14.1.16
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 +14 -0
- package/dist/cjs/ui/CodeBlockLanguagePicker.js +18 -6
- package/dist/cjs/ui/LanguagePicker.js +33 -6
- package/dist/es2019/ui/CodeBlockLanguagePicker.js +18 -6
- package/dist/es2019/ui/LanguagePicker.js +33 -6
- package/dist/esm/ui/CodeBlockLanguagePicker.js +18 -6
- package/dist/esm/ui/LanguagePicker.js +33 -6
- package/dist/types/ui/CodeBlockLanguagePicker.d.ts +1 -1
- package/dist/types/ui/LanguagePicker.d.ts +2 -1
- package/package.json +10 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-code-block
|
|
2
2
|
|
|
3
|
+
## 14.1.16
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
|
|
9
|
+
## 14.1.15
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [`be1ffe44994f0`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/be1ffe44994f0) -
|
|
14
|
+
Fix code block language picker trigger focus and overflow behavior
|
|
15
|
+
- Updated dependencies
|
|
16
|
+
|
|
3
17
|
## 14.1.14
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -32,17 +32,29 @@ var CodeBlockLanguagePicker = exports.CodeBlockLanguagePicker = function CodeBlo
|
|
|
32
32
|
var refreshRecentLanguages = (0, _react.useCallback)(function () {
|
|
33
33
|
setRecentLanguageValues((0, _recentLanguages.getRecentLanguages)());
|
|
34
34
|
}, []);
|
|
35
|
-
var handleSelection = (0, _react.useCallback)(function (option, selectionSource) {
|
|
35
|
+
var handleSelection = (0, _react.useCallback)(function (option, selectionSource, interactionMethod) {
|
|
36
36
|
var _api$analytics;
|
|
37
37
|
var command = option.value === _languagePickerOptions.DETECT_LANGUAGE_VALUE && (0, _platformFeatureFlags.fg)('platform_editor_code_block_language_detection_flow') ? (0, _editorCommands.detectLanguage)() : (0, _editorCommands.changeLanguage)(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(option.value, selectionSource);
|
|
38
38
|
var commandSucceeded = command(editorView.state, editorView.dispatch);
|
|
39
39
|
if ((0, _platformFeatureFlags.fg)('platform_editor_code_block_dogfooding_patch')) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
if ((0, _platformFeatureFlags.fg)('platform_editor_code_block_ga_patch_1')) {
|
|
41
|
+
if (interactionMethod === 'mouse') {
|
|
42
|
+
requestAnimationFrame(function () {
|
|
43
|
+
// Mouse-opened picker should return editing focus to the code block. Keyboard-opened
|
|
44
|
+
// picker keeps focus on the trigger to avoid CodeMirror DOM focus without cm.hasFocus.
|
|
45
|
+
api === null || api === void 0 || api.core.actions.focus({
|
|
46
|
+
scrollIntoView: false
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
} else {
|
|
51
|
+
requestAnimationFrame(function () {
|
|
52
|
+
// Let PopupSelect/FocusLock finish returning focus to the trigger, then restore the editor.
|
|
53
|
+
api === null || api === void 0 || api.core.actions.focus({
|
|
54
|
+
scrollIntoView: false
|
|
55
|
+
});
|
|
44
56
|
});
|
|
45
|
-
}
|
|
57
|
+
}
|
|
46
58
|
}
|
|
47
59
|
if (commandSucceeded && option.value !== _languagePickerOptions.DETECT_LANGUAGE_VALUE) {
|
|
48
60
|
(0, _recentLanguages.saveRecentLanguage)(option.value);
|
|
@@ -27,7 +27,8 @@ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length)
|
|
|
27
27
|
var pickerOptionStyles = null;
|
|
28
28
|
var styles = {
|
|
29
29
|
divider: "_h7alglyw _179rglyw _mqm2ia51 _1bsb1osq",
|
|
30
|
-
trigger: "
|
|
30
|
+
trigger: "_p12fuuw1 _ficf1e5h _1xw9glyw",
|
|
31
|
+
legacyTriggerTextOverflow: "_1reo15vq _18m915vq _1bto1l2s _o5721q9c"
|
|
31
32
|
};
|
|
32
33
|
var CustomGroup = function CustomGroup(props) {
|
|
33
34
|
var allGroups = props.selectProps.options;
|
|
@@ -109,6 +110,10 @@ var LanguagePicker = exports.LanguagePicker = function LanguagePicker(_ref) {
|
|
|
109
110
|
lockedPopperPlacement = _useState4[0],
|
|
110
111
|
setLockedPopperPlacement = _useState4[1];
|
|
111
112
|
var inputValueRef = (0, _react.useRef)('');
|
|
113
|
+
// PopupSelect restores focus based on the trigger/open interaction, not the option
|
|
114
|
+
// interaction. Keep this tied to the trigger so keyboard-open + mouse-select still follows
|
|
115
|
+
// the keyboard focus path.
|
|
116
|
+
var interactionMethodRef = (0, _react.useRef)('keyboard');
|
|
112
117
|
var optionsByValue = (0, _react.useMemo)(function () {
|
|
113
118
|
return new Map(languagePickerOptions.map(function (option) {
|
|
114
119
|
return [option.value, option];
|
|
@@ -159,7 +164,11 @@ var LanguagePicker = exports.LanguagePicker = function LanguagePicker(_ref) {
|
|
|
159
164
|
}
|
|
160
165
|
var isSearchSelection = inputValueRef.current.trim().length > 0;
|
|
161
166
|
var selectionSource = isSearchSelection ? 'search' : (_option$selectionSour = option.selectionSource) !== null && _option$selectionSour !== void 0 ? _option$selectionSour : 'all';
|
|
162
|
-
|
|
167
|
+
if ((0, _platformFeatureFlags.fg)('platform_editor_code_block_ga_patch_1')) {
|
|
168
|
+
onSelection(option, selectionSource, interactionMethodRef.current);
|
|
169
|
+
} else {
|
|
170
|
+
onSelection(option, selectionSource);
|
|
171
|
+
}
|
|
163
172
|
}, [onSelection]);
|
|
164
173
|
var handleInputChange = (0, _react.useCallback)(function (newInputValue, actionMeta) {
|
|
165
174
|
// React-select clears the input as part of selecting a value before onChange fires.
|
|
@@ -192,26 +201,44 @@ var LanguagePicker = exports.LanguagePicker = function LanguagePicker(_ref) {
|
|
|
192
201
|
focusWithoutScrolling(event.currentTarget);
|
|
193
202
|
}
|
|
194
203
|
}, []);
|
|
204
|
+
var handleTriggerMouseUp = (0, _react.useCallback)(function (event) {
|
|
205
|
+
if ((0, _platformFeatureFlags.fg)('platform_editor_code_block_ga_patch_1')) {
|
|
206
|
+
interactionMethodRef.current = 'mouse';
|
|
207
|
+
// Focus the trigger before PopupSelect opens so FocusLock restores focus to the
|
|
208
|
+
// trigger after a mouse selection. Relying on the button's default mouse focus is too
|
|
209
|
+
// late here; FocusLock can still remember the code block as the previous focus target.
|
|
210
|
+
focusWithoutScrolling(event.currentTarget);
|
|
211
|
+
}
|
|
212
|
+
}, []);
|
|
213
|
+
var handleTriggerKeyDownCapture = (0, _react.useCallback)(function () {
|
|
214
|
+
interactionMethodRef.current = 'keyboard';
|
|
215
|
+
}, []);
|
|
195
216
|
var renderTarget = (0, _react.useCallback)(function (_ref3) {
|
|
196
217
|
var isOpen = _ref3.isOpen,
|
|
197
218
|
ref = _ref3.ref,
|
|
198
219
|
onKeyDown = _ref3.onKeyDown,
|
|
199
|
-
ariaControls = _ref3['aria-controls']
|
|
220
|
+
ariaControls = _ref3['aria-controls'],
|
|
221
|
+
ariaExpanded = _ref3['aria-expanded'],
|
|
222
|
+
ariaHasPopup = _ref3['aria-haspopup'];
|
|
200
223
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
201
|
-
className: (0, _runtime.ax)([styles.trigger])
|
|
224
|
+
className: (0, _runtime.ax)([styles.trigger, !(0, _platformFeatureFlags.fg)('platform_editor_code_block_ga_patch_1') && styles.legacyTriggerTextOverflow])
|
|
202
225
|
}, /*#__PURE__*/_react.default.createElement(_new.default, {
|
|
203
226
|
spacing: triggerSpacing,
|
|
204
227
|
shouldFitContainer: true,
|
|
205
|
-
onMouseDown: handleTriggerMouseDown,
|
|
228
|
+
onMouseDown: (0, _platformFeatureFlags.fg)('platform_editor_code_block_ga_patch_1') ? undefined : handleTriggerMouseDown,
|
|
229
|
+
onMouseUp: (0, _platformFeatureFlags.fg)('platform_editor_code_block_ga_patch_1') ? handleTriggerMouseUp : undefined,
|
|
230
|
+
onKeyDownCapture: (0, _platformFeatureFlags.fg)('platform_editor_code_block_ga_patch_1') ? handleTriggerKeyDownCapture : undefined,
|
|
206
231
|
onKeyDown: onKeyDown,
|
|
207
232
|
ref: ref,
|
|
208
233
|
iconAfter: _chevronDown.default,
|
|
209
234
|
appearance: "subtle",
|
|
210
235
|
isSelected: isOpen,
|
|
211
236
|
"aria-controls": ariaControls,
|
|
237
|
+
"aria-expanded": (0, _platformFeatureFlags.fg)('platform_editor_code_block_ga_patch_1') ? ariaExpanded : undefined,
|
|
238
|
+
"aria-haspopup": (0, _platformFeatureFlags.fg)('platform_editor_code_block_ga_patch_1') ? ariaHasPopup : undefined,
|
|
212
239
|
testId: "code-block-language-picker-trigger"
|
|
213
240
|
}, label));
|
|
214
|
-
}, [label, triggerSpacing, handleTriggerMouseDown]);
|
|
241
|
+
}, [label, triggerSpacing, handleTriggerMouseDown, handleTriggerMouseUp, handleTriggerKeyDownCapture]);
|
|
215
242
|
return /*#__PURE__*/_react.default.createElement(_select.PopupSelect, {
|
|
216
243
|
components: popupSelectComponents,
|
|
217
244
|
filterOption: filterOption,
|
|
@@ -18,17 +18,29 @@ export const CodeBlockLanguagePicker = ({
|
|
|
18
18
|
const refreshRecentLanguages = useCallback(() => {
|
|
19
19
|
setRecentLanguageValues(getRecentLanguages());
|
|
20
20
|
}, []);
|
|
21
|
-
const handleSelection = useCallback((option, selectionSource) => {
|
|
21
|
+
const handleSelection = useCallback((option, selectionSource, interactionMethod) => {
|
|
22
22
|
var _api$analytics;
|
|
23
23
|
const command = option.value === DETECT_LANGUAGE_VALUE && fg('platform_editor_code_block_language_detection_flow') ? detectLanguage() : changeLanguage(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(option.value, selectionSource);
|
|
24
24
|
const commandSucceeded = command(editorView.state, editorView.dispatch);
|
|
25
25
|
if (fg('platform_editor_code_block_dogfooding_patch')) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
if (fg('platform_editor_code_block_ga_patch_1')) {
|
|
27
|
+
if (interactionMethod === 'mouse') {
|
|
28
|
+
requestAnimationFrame(() => {
|
|
29
|
+
// Mouse-opened picker should return editing focus to the code block. Keyboard-opened
|
|
30
|
+
// picker keeps focus on the trigger to avoid CodeMirror DOM focus without cm.hasFocus.
|
|
31
|
+
api === null || api === void 0 ? void 0 : api.core.actions.focus({
|
|
32
|
+
scrollIntoView: false
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
} else {
|
|
37
|
+
requestAnimationFrame(() => {
|
|
38
|
+
// Let PopupSelect/FocusLock finish returning focus to the trigger, then restore the editor.
|
|
39
|
+
api === null || api === void 0 ? void 0 : api.core.actions.focus({
|
|
40
|
+
scrollIntoView: false
|
|
41
|
+
});
|
|
30
42
|
});
|
|
31
|
-
}
|
|
43
|
+
}
|
|
32
44
|
}
|
|
33
45
|
if (commandSucceeded && option.value !== DETECT_LANGUAGE_VALUE) {
|
|
34
46
|
saveRecentLanguage(option.value);
|
|
@@ -13,7 +13,8 @@ import { createGroupedLanguageOptions } from './language-picker-options';
|
|
|
13
13
|
const pickerOptionStyles = null;
|
|
14
14
|
const styles = {
|
|
15
15
|
divider: "_h7alglyw _179rglyw _mqm2ia51 _1bsb1osq",
|
|
16
|
-
trigger: "
|
|
16
|
+
trigger: "_p12fuuw1 _ficf1e5h _1xw9glyw",
|
|
17
|
+
legacyTriggerTextOverflow: "_1reo15vq _18m915vq _1bto1l2s _o5721q9c"
|
|
17
18
|
};
|
|
18
19
|
const CustomGroup = props => {
|
|
19
20
|
const allGroups = props.selectProps.options;
|
|
@@ -79,6 +80,10 @@ export const LanguagePicker = ({
|
|
|
79
80
|
const [hasSearchQuery, setHasSearchQuery] = useState(false);
|
|
80
81
|
const [lockedPopperPlacement, setLockedPopperPlacement] = useState();
|
|
81
82
|
const inputValueRef = useRef('');
|
|
83
|
+
// PopupSelect restores focus based on the trigger/open interaction, not the option
|
|
84
|
+
// interaction. Keep this tied to the trigger so keyboard-open + mouse-select still follows
|
|
85
|
+
// the keyboard focus path.
|
|
86
|
+
const interactionMethodRef = useRef('keyboard');
|
|
82
87
|
const optionsByValue = useMemo(() => new Map(languagePickerOptions.map(option => [option.value, option])), [languagePickerOptions]);
|
|
83
88
|
const recentlyUsedLanguages = useMemo(() => getRecentlyUsedLanguages(recentLanguageValues, optionsByValue), [recentLanguageValues, optionsByValue]);
|
|
84
89
|
const options = useMemo(() => createGroupedLanguageOptions({
|
|
@@ -116,7 +121,11 @@ export const LanguagePicker = ({
|
|
|
116
121
|
}
|
|
117
122
|
const isSearchSelection = inputValueRef.current.trim().length > 0;
|
|
118
123
|
const selectionSource = isSearchSelection ? 'search' : (_option$selectionSour = option.selectionSource) !== null && _option$selectionSour !== void 0 ? _option$selectionSour : 'all';
|
|
119
|
-
|
|
124
|
+
if (fg('platform_editor_code_block_ga_patch_1')) {
|
|
125
|
+
onSelection(option, selectionSource, interactionMethodRef.current);
|
|
126
|
+
} else {
|
|
127
|
+
onSelection(option, selectionSource);
|
|
128
|
+
}
|
|
120
129
|
}, [onSelection]);
|
|
121
130
|
const handleInputChange = useCallback((newInputValue, actionMeta) => {
|
|
122
131
|
// React-select clears the input as part of selecting a value before onChange fires.
|
|
@@ -149,25 +158,43 @@ export const LanguagePicker = ({
|
|
|
149
158
|
focusWithoutScrolling(event.currentTarget);
|
|
150
159
|
}
|
|
151
160
|
}, []);
|
|
161
|
+
const handleTriggerMouseUp = useCallback(event => {
|
|
162
|
+
if (fg('platform_editor_code_block_ga_patch_1')) {
|
|
163
|
+
interactionMethodRef.current = 'mouse';
|
|
164
|
+
// Focus the trigger before PopupSelect opens so FocusLock restores focus to the
|
|
165
|
+
// trigger after a mouse selection. Relying on the button's default mouse focus is too
|
|
166
|
+
// late here; FocusLock can still remember the code block as the previous focus target.
|
|
167
|
+
focusWithoutScrolling(event.currentTarget);
|
|
168
|
+
}
|
|
169
|
+
}, []);
|
|
170
|
+
const handleTriggerKeyDownCapture = useCallback(() => {
|
|
171
|
+
interactionMethodRef.current = 'keyboard';
|
|
172
|
+
}, []);
|
|
152
173
|
const renderTarget = useCallback(({
|
|
153
174
|
isOpen,
|
|
154
175
|
ref,
|
|
155
176
|
onKeyDown,
|
|
156
|
-
'aria-controls': ariaControls
|
|
177
|
+
'aria-controls': ariaControls,
|
|
178
|
+
'aria-expanded': ariaExpanded,
|
|
179
|
+
'aria-haspopup': ariaHasPopup
|
|
157
180
|
}) => /*#__PURE__*/React.createElement("div", {
|
|
158
|
-
className: ax([styles.trigger])
|
|
181
|
+
className: ax([styles.trigger, !fg('platform_editor_code_block_ga_patch_1') && styles.legacyTriggerTextOverflow])
|
|
159
182
|
}, /*#__PURE__*/React.createElement(Button, {
|
|
160
183
|
spacing: triggerSpacing,
|
|
161
184
|
shouldFitContainer: true,
|
|
162
|
-
onMouseDown: handleTriggerMouseDown,
|
|
185
|
+
onMouseDown: fg('platform_editor_code_block_ga_patch_1') ? undefined : handleTriggerMouseDown,
|
|
186
|
+
onMouseUp: fg('platform_editor_code_block_ga_patch_1') ? handleTriggerMouseUp : undefined,
|
|
187
|
+
onKeyDownCapture: fg('platform_editor_code_block_ga_patch_1') ? handleTriggerKeyDownCapture : undefined,
|
|
163
188
|
onKeyDown: onKeyDown,
|
|
164
189
|
ref: ref,
|
|
165
190
|
iconAfter: ChevronDownIcon,
|
|
166
191
|
appearance: "subtle",
|
|
167
192
|
isSelected: isOpen,
|
|
168
193
|
"aria-controls": ariaControls,
|
|
194
|
+
"aria-expanded": fg('platform_editor_code_block_ga_patch_1') ? ariaExpanded : undefined,
|
|
195
|
+
"aria-haspopup": fg('platform_editor_code_block_ga_patch_1') ? ariaHasPopup : undefined,
|
|
169
196
|
testId: "code-block-language-picker-trigger"
|
|
170
|
-
}, label)), [label, triggerSpacing, handleTriggerMouseDown]);
|
|
197
|
+
}, label)), [label, triggerSpacing, handleTriggerMouseDown, handleTriggerMouseUp, handleTriggerKeyDownCapture]);
|
|
171
198
|
return /*#__PURE__*/React.createElement(PopupSelect, {
|
|
172
199
|
components: popupSelectComponents,
|
|
173
200
|
filterOption: filterOption,
|
|
@@ -23,17 +23,29 @@ export var CodeBlockLanguagePicker = function CodeBlockLanguagePicker(_ref) {
|
|
|
23
23
|
var refreshRecentLanguages = useCallback(function () {
|
|
24
24
|
setRecentLanguageValues(getRecentLanguages());
|
|
25
25
|
}, []);
|
|
26
|
-
var handleSelection = useCallback(function (option, selectionSource) {
|
|
26
|
+
var handleSelection = useCallback(function (option, selectionSource, interactionMethod) {
|
|
27
27
|
var _api$analytics;
|
|
28
28
|
var command = option.value === DETECT_LANGUAGE_VALUE && fg('platform_editor_code_block_language_detection_flow') ? detectLanguage() : changeLanguage(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(option.value, selectionSource);
|
|
29
29
|
var commandSucceeded = command(editorView.state, editorView.dispatch);
|
|
30
30
|
if (fg('platform_editor_code_block_dogfooding_patch')) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
if (fg('platform_editor_code_block_ga_patch_1')) {
|
|
32
|
+
if (interactionMethod === 'mouse') {
|
|
33
|
+
requestAnimationFrame(function () {
|
|
34
|
+
// Mouse-opened picker should return editing focus to the code block. Keyboard-opened
|
|
35
|
+
// picker keeps focus on the trigger to avoid CodeMirror DOM focus without cm.hasFocus.
|
|
36
|
+
api === null || api === void 0 || api.core.actions.focus({
|
|
37
|
+
scrollIntoView: false
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
} else {
|
|
42
|
+
requestAnimationFrame(function () {
|
|
43
|
+
// Let PopupSelect/FocusLock finish returning focus to the trigger, then restore the editor.
|
|
44
|
+
api === null || api === void 0 || api.core.actions.focus({
|
|
45
|
+
scrollIntoView: false
|
|
46
|
+
});
|
|
35
47
|
});
|
|
36
|
-
}
|
|
48
|
+
}
|
|
37
49
|
}
|
|
38
50
|
if (commandSucceeded && option.value !== DETECT_LANGUAGE_VALUE) {
|
|
39
51
|
saveRecentLanguage(option.value);
|
|
@@ -18,7 +18,8 @@ import { createGroupedLanguageOptions } from './language-picker-options';
|
|
|
18
18
|
var pickerOptionStyles = null;
|
|
19
19
|
var styles = {
|
|
20
20
|
divider: "_h7alglyw _179rglyw _mqm2ia51 _1bsb1osq",
|
|
21
|
-
trigger: "
|
|
21
|
+
trigger: "_p12fuuw1 _ficf1e5h _1xw9glyw",
|
|
22
|
+
legacyTriggerTextOverflow: "_1reo15vq _18m915vq _1bto1l2s _o5721q9c"
|
|
22
23
|
};
|
|
23
24
|
var CustomGroup = function CustomGroup(props) {
|
|
24
25
|
var allGroups = props.selectProps.options;
|
|
@@ -100,6 +101,10 @@ export var LanguagePicker = function LanguagePicker(_ref) {
|
|
|
100
101
|
lockedPopperPlacement = _useState4[0],
|
|
101
102
|
setLockedPopperPlacement = _useState4[1];
|
|
102
103
|
var inputValueRef = useRef('');
|
|
104
|
+
// PopupSelect restores focus based on the trigger/open interaction, not the option
|
|
105
|
+
// interaction. Keep this tied to the trigger so keyboard-open + mouse-select still follows
|
|
106
|
+
// the keyboard focus path.
|
|
107
|
+
var interactionMethodRef = useRef('keyboard');
|
|
103
108
|
var optionsByValue = useMemo(function () {
|
|
104
109
|
return new Map(languagePickerOptions.map(function (option) {
|
|
105
110
|
return [option.value, option];
|
|
@@ -150,7 +155,11 @@ export var LanguagePicker = function LanguagePicker(_ref) {
|
|
|
150
155
|
}
|
|
151
156
|
var isSearchSelection = inputValueRef.current.trim().length > 0;
|
|
152
157
|
var selectionSource = isSearchSelection ? 'search' : (_option$selectionSour = option.selectionSource) !== null && _option$selectionSour !== void 0 ? _option$selectionSour : 'all';
|
|
153
|
-
|
|
158
|
+
if (fg('platform_editor_code_block_ga_patch_1')) {
|
|
159
|
+
onSelection(option, selectionSource, interactionMethodRef.current);
|
|
160
|
+
} else {
|
|
161
|
+
onSelection(option, selectionSource);
|
|
162
|
+
}
|
|
154
163
|
}, [onSelection]);
|
|
155
164
|
var handleInputChange = useCallback(function (newInputValue, actionMeta) {
|
|
156
165
|
// React-select clears the input as part of selecting a value before onChange fires.
|
|
@@ -183,26 +192,44 @@ export var LanguagePicker = function LanguagePicker(_ref) {
|
|
|
183
192
|
focusWithoutScrolling(event.currentTarget);
|
|
184
193
|
}
|
|
185
194
|
}, []);
|
|
195
|
+
var handleTriggerMouseUp = useCallback(function (event) {
|
|
196
|
+
if (fg('platform_editor_code_block_ga_patch_1')) {
|
|
197
|
+
interactionMethodRef.current = 'mouse';
|
|
198
|
+
// Focus the trigger before PopupSelect opens so FocusLock restores focus to the
|
|
199
|
+
// trigger after a mouse selection. Relying on the button's default mouse focus is too
|
|
200
|
+
// late here; FocusLock can still remember the code block as the previous focus target.
|
|
201
|
+
focusWithoutScrolling(event.currentTarget);
|
|
202
|
+
}
|
|
203
|
+
}, []);
|
|
204
|
+
var handleTriggerKeyDownCapture = useCallback(function () {
|
|
205
|
+
interactionMethodRef.current = 'keyboard';
|
|
206
|
+
}, []);
|
|
186
207
|
var renderTarget = useCallback(function (_ref3) {
|
|
187
208
|
var isOpen = _ref3.isOpen,
|
|
188
209
|
ref = _ref3.ref,
|
|
189
210
|
onKeyDown = _ref3.onKeyDown,
|
|
190
|
-
ariaControls = _ref3['aria-controls']
|
|
211
|
+
ariaControls = _ref3['aria-controls'],
|
|
212
|
+
ariaExpanded = _ref3['aria-expanded'],
|
|
213
|
+
ariaHasPopup = _ref3['aria-haspopup'];
|
|
191
214
|
return /*#__PURE__*/React.createElement("div", {
|
|
192
|
-
className: ax([styles.trigger])
|
|
215
|
+
className: ax([styles.trigger, !fg('platform_editor_code_block_ga_patch_1') && styles.legacyTriggerTextOverflow])
|
|
193
216
|
}, /*#__PURE__*/React.createElement(Button, {
|
|
194
217
|
spacing: triggerSpacing,
|
|
195
218
|
shouldFitContainer: true,
|
|
196
|
-
onMouseDown: handleTriggerMouseDown,
|
|
219
|
+
onMouseDown: fg('platform_editor_code_block_ga_patch_1') ? undefined : handleTriggerMouseDown,
|
|
220
|
+
onMouseUp: fg('platform_editor_code_block_ga_patch_1') ? handleTriggerMouseUp : undefined,
|
|
221
|
+
onKeyDownCapture: fg('platform_editor_code_block_ga_patch_1') ? handleTriggerKeyDownCapture : undefined,
|
|
197
222
|
onKeyDown: onKeyDown,
|
|
198
223
|
ref: ref,
|
|
199
224
|
iconAfter: ChevronDownIcon,
|
|
200
225
|
appearance: "subtle",
|
|
201
226
|
isSelected: isOpen,
|
|
202
227
|
"aria-controls": ariaControls,
|
|
228
|
+
"aria-expanded": fg('platform_editor_code_block_ga_patch_1') ? ariaExpanded : undefined,
|
|
229
|
+
"aria-haspopup": fg('platform_editor_code_block_ga_patch_1') ? ariaHasPopup : undefined,
|
|
203
230
|
testId: "code-block-language-picker-trigger"
|
|
204
231
|
}, label));
|
|
205
|
-
}, [label, triggerSpacing, handleTriggerMouseDown]);
|
|
232
|
+
}, [label, triggerSpacing, handleTriggerMouseDown, handleTriggerMouseUp, handleTriggerKeyDownCapture]);
|
|
206
233
|
return /*#__PURE__*/React.createElement(PopupSelect, {
|
|
207
234
|
components: popupSelectComponents,
|
|
208
235
|
filterOption: filterOption,
|
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
3
3
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
4
4
|
import type { CodeBlockPlugin } from '../index';
|
|
5
|
-
import type
|
|
5
|
+
import { type LanguagePickerProps } from './LanguagePicker';
|
|
6
6
|
type CodeBlockLanguagePickerProps = Omit<LanguagePickerProps, 'recentLanguageValues' | 'onMenuOpen' | 'onSelection'> & {
|
|
7
7
|
api: ExtractInjectionAPI<CodeBlockPlugin> | undefined;
|
|
8
8
|
editorView: EditorView;
|
|
@@ -12,8 +12,9 @@ export type LanguagePickerProps = {
|
|
|
12
12
|
formatMessage: IntlShape['formatMessage'];
|
|
13
13
|
languagePickerOptions: LanguagePickerOption[];
|
|
14
14
|
onMenuOpen?: () => void;
|
|
15
|
-
onSelection: (option: LanguagePickerOption, selectionSource: LanguagePickerSelectionSource) => void;
|
|
15
|
+
onSelection: (option: LanguagePickerOption, selectionSource: LanguagePickerSelectionSource, interactionMethod?: LanguagePickerInteractionMethod) => void;
|
|
16
16
|
recentLanguageValues?: string[];
|
|
17
17
|
triggerSpacing?: 'default' | 'compact';
|
|
18
18
|
};
|
|
19
|
+
export type LanguagePickerInteractionMethod = 'keyboard' | 'mouse';
|
|
19
20
|
export declare const LanguagePicker: ({ defaultValue, filterOption, formatMessage, languagePickerOptions, recentLanguageValues, onMenuOpen, onSelection, triggerSpacing, }: LanguagePickerProps) => React.JSX.Element;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-code-block",
|
|
3
|
-
"version": "14.1.
|
|
3
|
+
"version": "14.1.16",
|
|
4
4
|
"description": "Code block plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"sideEffects": false,
|
|
20
20
|
"atlaskit:src": "src/index.ts",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@atlaskit/adf-schema": "^56.
|
|
22
|
+
"@atlaskit/adf-schema": "^56.1.0",
|
|
23
23
|
"@atlaskit/button": "^24.3.0",
|
|
24
24
|
"@atlaskit/code": "^18.2.0",
|
|
25
25
|
"@atlaskit/css": "^1.0.0",
|
|
@@ -39,16 +39,16 @@
|
|
|
39
39
|
"@atlaskit/frontend-utilities": "^4.1.0",
|
|
40
40
|
"@atlaskit/icon": "^36.2.0",
|
|
41
41
|
"@atlaskit/platform-feature-flags": "^2.0.0",
|
|
42
|
-
"@atlaskit/primitives": "^20.
|
|
42
|
+
"@atlaskit/primitives": "^20.5.0",
|
|
43
43
|
"@atlaskit/prosemirror-input-rules": "^4.0.0",
|
|
44
|
-
"@atlaskit/select": "^22.
|
|
45
|
-
"@atlaskit/tmp-editor-statsig": "^
|
|
46
|
-
"@atlaskit/tokens": "^15.
|
|
44
|
+
"@atlaskit/select": "^22.4.0",
|
|
45
|
+
"@atlaskit/tmp-editor-statsig": "^122.0.0",
|
|
46
|
+
"@atlaskit/tokens": "^15.5.0",
|
|
47
47
|
"@babel/runtime": "^7.0.0",
|
|
48
48
|
"@compiled/react": "^0.20.0"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"@atlaskit/editor-common": "^116.
|
|
51
|
+
"@atlaskit/editor-common": "^116.24.0",
|
|
52
52
|
"react": "^18.2.0",
|
|
53
53
|
"react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"
|
|
54
54
|
},
|
|
@@ -106,6 +106,9 @@
|
|
|
106
106
|
"platform_editor_code_block_dogfooding_patch": {
|
|
107
107
|
"type": "boolean"
|
|
108
108
|
},
|
|
109
|
+
"platform_editor_code_block_ga_patch_1": {
|
|
110
|
+
"type": "boolean"
|
|
111
|
+
},
|
|
109
112
|
"platform_editor_code_block_language_detection_flow": {
|
|
110
113
|
"type": "boolean"
|
|
111
114
|
}
|