@atlaskit/editor-plugin-media-insert 31.0.1 → 31.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.
- package/CHANGELOG.md +21 -0
- package/dist/cjs/ui/MediaFromURL.js +15 -4
- package/dist/cjs/ui/MediaInsertPicker.js +32 -9
- package/dist/cjs/ui/hooks/use-focus.js +19 -0
- package/dist/es2019/ui/MediaFromURL.js +14 -4
- package/dist/es2019/ui/MediaInsertPicker.js +31 -10
- package/dist/es2019/ui/hooks/use-focus.js +13 -0
- package/dist/esm/ui/MediaFromURL.js +15 -4
- package/dist/esm/ui/MediaInsertPicker.js +32 -9
- package/dist/esm/ui/hooks/use-focus.js +14 -0
- package/dist/types/ui/MediaFromURL.d.ts +2 -1
- package/dist/types/ui/hooks/use-focus.d.ts +7 -0
- package/package.json +4 -3
- package/dist/cjs/ui/hooks/use-focus-editor.js +0 -17
- package/dist/es2019/ui/hooks/use-focus-editor.js +0 -10
- package/dist/esm/ui/hooks/use-focus-editor.js +0 -11
- package/dist/types/ui/hooks/use-focus-editor.d.ts +0 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-media-insert
|
|
2
2
|
|
|
3
|
+
## 31.1.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
|
|
9
|
+
## 31.1.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [`8ed6929dc7678`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/8ed6929dc7678) -
|
|
14
|
+
[ux] [A11Y-42785] Restore keyboard focus to the triggering toolbar button (e.g. "Add image, video,
|
|
15
|
+
or file") when the media insert picker is closed via Cancel, Escape, or click-outside. Previously
|
|
16
|
+
focus was lost or moved unpredictably, forcing keyboard and screen-reader users to tab through the
|
|
17
|
+
page to return to the toolbar. Behind the `platform_editor_fix_focus_MediaInsertPicker`
|
|
18
|
+
experiment.
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- Updated dependencies
|
|
23
|
+
|
|
3
24
|
## 31.0.1
|
|
4
25
|
|
|
5
26
|
### Patch Changes
|
|
@@ -28,6 +28,7 @@ var _helperMessage = require("@atlaskit/form/helper-message");
|
|
|
28
28
|
var _messageWrapper = require("@atlaskit/form/message-wrapper");
|
|
29
29
|
var _growDiagonal = _interopRequireDefault(require("@atlaskit/icon/core/grow-diagonal"));
|
|
30
30
|
var _getMediaClient = require("@atlaskit/media-client-react/get-media-client");
|
|
31
|
+
var _isExperimentEnabled = require("@atlaskit/platform-feature-experiments/is-experiment-enabled");
|
|
31
32
|
var _primitives = require("@atlaskit/primitives");
|
|
32
33
|
var _message = _interopRequireDefault(require("@atlaskit/section-message/message"));
|
|
33
34
|
var _textField = _interopRequireDefault(require("@atlaskit/textfield/text-field"));
|
|
@@ -106,6 +107,8 @@ function MediaFromURL(_ref) {
|
|
|
106
107
|
var mediaProvider = _ref.mediaProvider,
|
|
107
108
|
dispatchAnalyticsEvent = _ref.dispatchAnalyticsEvent,
|
|
108
109
|
closeMediaInsertPicker = _ref.closeMediaInsertPicker,
|
|
110
|
+
_ref$cancelMediaInser = _ref.cancelMediaInsertPicker,
|
|
111
|
+
cancelMediaInsertPicker = _ref$cancelMediaInser === void 0 ? closeMediaInsertPicker : _ref$cancelMediaInser,
|
|
109
112
|
insertMediaSingle = _ref.insertMediaSingle,
|
|
110
113
|
insertExternalMediaSingle = _ref.insertExternalMediaSingle,
|
|
111
114
|
isOnlyExternalLinks = _ref.isOnlyExternalLinks,
|
|
@@ -275,9 +278,13 @@ function MediaFromURL(_ref) {
|
|
|
275
278
|
};
|
|
276
279
|
dispatchAnalyticsEvent(payload);
|
|
277
280
|
}
|
|
278
|
-
|
|
281
|
+
if ((0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_fix_focus_MediaInsertPicker')) {
|
|
282
|
+
cancelMediaInsertPicker();
|
|
283
|
+
} else {
|
|
284
|
+
closeMediaInsertPicker();
|
|
285
|
+
}
|
|
279
286
|
}
|
|
280
|
-
}, [dispatchAnalyticsEvent, closeMediaInsertPicker]);
|
|
287
|
+
}, [dispatchAnalyticsEvent, cancelMediaInsertPicker, closeMediaInsertPicker]);
|
|
281
288
|
var onCancel = _react.default.useCallback(function () {
|
|
282
289
|
if (dispatchAnalyticsEvent) {
|
|
283
290
|
var payload = {
|
|
@@ -288,8 +295,12 @@ function MediaFromURL(_ref) {
|
|
|
288
295
|
};
|
|
289
296
|
dispatchAnalyticsEvent(payload);
|
|
290
297
|
}
|
|
291
|
-
|
|
292
|
-
|
|
298
|
+
if ((0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_fix_focus_MediaInsertPicker')) {
|
|
299
|
+
cancelMediaInsertPicker();
|
|
300
|
+
} else {
|
|
301
|
+
closeMediaInsertPicker();
|
|
302
|
+
}
|
|
303
|
+
}, [cancelMediaInsertPicker, dispatchAnalyticsEvent, closeMediaInsertPicker]);
|
|
293
304
|
return /*#__PURE__*/_react.default.createElement(_form.default, {
|
|
294
305
|
// eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed)
|
|
295
306
|
onSubmit: function onSubmit(_ref3, form) {
|
|
@@ -23,7 +23,7 @@ var _tabList = _interopRequireDefault(require("@atlaskit/tabs/tab-list"));
|
|
|
23
23
|
var _useTab2 = _interopRequireDefault(require("@atlaskit/tabs/use-tab"));
|
|
24
24
|
var _useTabPanel = _interopRequireDefault(require("@atlaskit/tabs/use-tab-panel"));
|
|
25
25
|
var _expValEqualsNoExposure = require("@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure");
|
|
26
|
-
var
|
|
26
|
+
var _useFocus = require("./hooks/use-focus");
|
|
27
27
|
var _useUnholyAutofocus2 = require("./hooks/use-unholy-autofocus");
|
|
28
28
|
var _LocalMedia = require("./LocalMedia");
|
|
29
29
|
var _MediaFromURL = require("./MediaFromURL");
|
|
@@ -154,10 +154,26 @@ var MediaInsertPicker = exports.MediaInsertPicker = function MediaInsertPicker(_
|
|
|
154
154
|
targetRef = (0, _getDomRefFromSelection.getDomRefFromSelection)(editorView, _analytics.ACTION_SUBJECT_ID.PICKER_MEDIA, api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions);
|
|
155
155
|
mountPoint = popupsMountPoint;
|
|
156
156
|
}
|
|
157
|
-
var
|
|
158
|
-
|
|
159
|
-
|
|
157
|
+
var focusButton = (0, _useFocus.useFocus)({
|
|
158
|
+
target: targetRef !== null && targetRef !== void 0 ? targetRef : editorView
|
|
159
|
+
});
|
|
160
|
+
var focusEditor = (0, _useFocus.useFocus)({
|
|
161
|
+
target: editorView
|
|
160
162
|
});
|
|
163
|
+
// returnFocusRef stores which function we call on unmount: focusButton | focusEditor
|
|
164
|
+
// Needs to be a ref so we can instantly toggle it before unmounting triggers the focus trap
|
|
165
|
+
var returnFocusRef = _react.default.useRef(focusEditor);
|
|
166
|
+
// When inserting media, close picker and focus editor.
|
|
167
|
+
var closeAndFocusEditor = _react.default.useCallback(function () {
|
|
168
|
+
returnFocusRef.current = focusEditor;
|
|
169
|
+
closeMediaInsertPicker();
|
|
170
|
+
}, [closeMediaInsertPicker, focusEditor]);
|
|
171
|
+
// When cancelling, close picker and return focus to button.
|
|
172
|
+
var closeAndReturnFocusToButton = _react.default.useCallback(function () {
|
|
173
|
+
returnFocusRef.current = focusButton;
|
|
174
|
+
closeMediaInsertPicker();
|
|
175
|
+
}, [closeMediaInsertPicker, focusButton]);
|
|
176
|
+
var intl = (0, _reactIntl.useIntl)();
|
|
161
177
|
var _useUnholyAutofocus = (0, _useUnholyAutofocus2.useUnholyAutofocus)(),
|
|
162
178
|
autofocusRef = _useUnholyAutofocus.autofocusRef,
|
|
163
179
|
onPositionCalculated = _useUnholyAutofocus.onPositionCalculated;
|
|
@@ -292,15 +308,19 @@ var MediaInsertPicker = exports.MediaInsertPicker = function MediaInsertPicker(_
|
|
|
292
308
|
};
|
|
293
309
|
dispatchAnalyticsEvent(payload);
|
|
294
310
|
}
|
|
295
|
-
|
|
296
|
-
|
|
311
|
+
if ((0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_fix_focus_MediaInsertPicker')) {
|
|
312
|
+
closeAndReturnFocusToButton();
|
|
313
|
+
} else {
|
|
314
|
+
closeMediaInsertPicker(); // Focuses editor on unmount
|
|
297
315
|
focusEditor();
|
|
298
316
|
}
|
|
299
317
|
};
|
|
300
318
|
};
|
|
301
319
|
var closePickerAndFocusEditor = function closePickerAndFocusEditor() {
|
|
302
|
-
|
|
303
|
-
|
|
320
|
+
if ((0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_fix_focus_MediaInsertPicker')) {
|
|
321
|
+
closeAndFocusEditor();
|
|
322
|
+
} else {
|
|
323
|
+
closeMediaInsertPicker();
|
|
304
324
|
focusEditor();
|
|
305
325
|
}
|
|
306
326
|
};
|
|
@@ -315,7 +335,9 @@ var MediaInsertPicker = exports.MediaInsertPicker = function MediaInsertPicker(_
|
|
|
315
335
|
fitHeight: 390,
|
|
316
336
|
fitWidth: 340,
|
|
317
337
|
mountTo: mountPoint,
|
|
318
|
-
onUnmount: (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_fix_focus_MediaInsertPicker') ?
|
|
338
|
+
onUnmount: (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_fix_focus_MediaInsertPicker') ? function () {
|
|
339
|
+
return returnFocusRef.current();
|
|
340
|
+
} : undefined,
|
|
319
341
|
boundariesElement: popupsBoundariesElement,
|
|
320
342
|
handleClickOutside: handleClose(_analytics.INPUT_METHOD.MOUSE),
|
|
321
343
|
handleEscapeKeydown: handleClose(_analytics.INPUT_METHOD.KEYBOARD),
|
|
@@ -369,6 +391,7 @@ var MediaInsertPicker = exports.MediaInsertPicker = function MediaInsertPicker(_
|
|
|
369
391
|
mediaProvider: mediaProvider,
|
|
370
392
|
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
371
393
|
closeMediaInsertPicker: closePickerAndFocusEditor,
|
|
394
|
+
cancelMediaInsertPicker: closeAndReturnFocusToButton,
|
|
372
395
|
insertMediaSingle: insertMediaSingle,
|
|
373
396
|
insertExternalMediaSingle: insertExternalMediaSingle,
|
|
374
397
|
isOnlyExternalLinks: isOnlyExternalLinks,
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useFocus = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
// Usually either a DOM node or editorView
|
|
9
|
+
|
|
10
|
+
var useFocus = exports.useFocus = function useFocus(_ref) {
|
|
11
|
+
var target = _ref.target;
|
|
12
|
+
var focus = (0, _react.useCallback)(function () {
|
|
13
|
+
// Use setTimeout to run this async after any DOM updates in same callback
|
|
14
|
+
setTimeout(function () {
|
|
15
|
+
return target.focus();
|
|
16
|
+
}, 0);
|
|
17
|
+
}, [target]);
|
|
18
|
+
return focus;
|
|
19
|
+
};
|
|
@@ -14,6 +14,7 @@ import { HelperMessage } from '@atlaskit/form/helper-message';
|
|
|
14
14
|
import { MessageWrapper } from '@atlaskit/form/message-wrapper';
|
|
15
15
|
import ExpandIcon from '@atlaskit/icon/core/grow-diagonal';
|
|
16
16
|
import { getMediaClient } from '@atlaskit/media-client-react/get-media-client';
|
|
17
|
+
import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
|
|
17
18
|
// eslint-disable-next-line @atlaskit/design-system/no-emotion-primitives -- to be migrated to @atlaskit/primitives/compiled – go/akcss
|
|
18
19
|
import { Box, Flex, Inline, Stack, xcss } from '@atlaskit/primitives';
|
|
19
20
|
import SectionMessage from '@atlaskit/section-message/message';
|
|
@@ -94,6 +95,7 @@ export function MediaFromURL({
|
|
|
94
95
|
mediaProvider,
|
|
95
96
|
dispatchAnalyticsEvent,
|
|
96
97
|
closeMediaInsertPicker,
|
|
98
|
+
cancelMediaInsertPicker = closeMediaInsertPicker,
|
|
97
99
|
insertMediaSingle,
|
|
98
100
|
insertExternalMediaSingle,
|
|
99
101
|
isOnlyExternalLinks,
|
|
@@ -240,9 +242,13 @@ export function MediaFromURL({
|
|
|
240
242
|
};
|
|
241
243
|
dispatchAnalyticsEvent(payload);
|
|
242
244
|
}
|
|
243
|
-
|
|
245
|
+
if (isExperimentEnabled('platform_editor_fix_focus_MediaInsertPicker')) {
|
|
246
|
+
cancelMediaInsertPicker();
|
|
247
|
+
} else {
|
|
248
|
+
closeMediaInsertPicker();
|
|
249
|
+
}
|
|
244
250
|
}
|
|
245
|
-
}, [dispatchAnalyticsEvent, closeMediaInsertPicker]);
|
|
251
|
+
}, [dispatchAnalyticsEvent, cancelMediaInsertPicker, closeMediaInsertPicker]);
|
|
246
252
|
const onCancel = React.useCallback(() => {
|
|
247
253
|
if (dispatchAnalyticsEvent) {
|
|
248
254
|
const payload = {
|
|
@@ -253,8 +259,12 @@ export function MediaFromURL({
|
|
|
253
259
|
};
|
|
254
260
|
dispatchAnalyticsEvent(payload);
|
|
255
261
|
}
|
|
256
|
-
|
|
257
|
-
|
|
262
|
+
if (isExperimentEnabled('platform_editor_fix_focus_MediaInsertPicker')) {
|
|
263
|
+
cancelMediaInsertPicker();
|
|
264
|
+
} else {
|
|
265
|
+
closeMediaInsertPicker();
|
|
266
|
+
}
|
|
267
|
+
}, [cancelMediaInsertPicker, dispatchAnalyticsEvent, closeMediaInsertPicker]);
|
|
258
268
|
return /*#__PURE__*/React.createElement(Form, {
|
|
259
269
|
// eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed)
|
|
260
270
|
onSubmit: ({
|
|
@@ -15,7 +15,7 @@ import TabList from '@atlaskit/tabs/tab-list';
|
|
|
15
15
|
import useTab from '@atlaskit/tabs/use-tab';
|
|
16
16
|
import useTabPanel from '@atlaskit/tabs/use-tab-panel';
|
|
17
17
|
import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
|
|
18
|
-
import {
|
|
18
|
+
import { useFocus } from './hooks/use-focus';
|
|
19
19
|
import { useUnholyAutofocus } from './hooks/use-unholy-autofocus';
|
|
20
20
|
import { LocalMedia } from './LocalMedia';
|
|
21
21
|
import { MediaFromURL } from './MediaFromURL';
|
|
@@ -117,7 +117,7 @@ export const MediaInsertPicker = ({
|
|
|
117
117
|
customizedUrlValidation,
|
|
118
118
|
customizedHelperMessage
|
|
119
119
|
}) => {
|
|
120
|
-
var _api$mediaInsert$acti, _api$mediaInsert, _api$mediaInsert$acti2, _api$mediaInsert$acti3;
|
|
120
|
+
var _api$mediaInsert$acti, _api$mediaInsert, _api$mediaInsert$acti2, _api$mediaInsert$acti3, _targetRef;
|
|
121
121
|
// Tabs registered by other plugins via `api.mediaInsert.actions.registerInsertTab(...)`.
|
|
122
122
|
// Read once per render; the registry is mutated only at plugin setup time so this is stable
|
|
123
123
|
// for the lifetime of an editor instance.
|
|
@@ -145,10 +145,26 @@ export const MediaInsertPicker = ({
|
|
|
145
145
|
targetRef = getDomRefFromSelection(editorView, ACTION_SUBJECT_ID.PICKER_MEDIA, api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions);
|
|
146
146
|
mountPoint = popupsMountPoint;
|
|
147
147
|
}
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
148
|
+
const focusButton = useFocus({
|
|
149
|
+
target: (_targetRef = targetRef) !== null && _targetRef !== void 0 ? _targetRef : editorView
|
|
150
|
+
});
|
|
151
|
+
const focusEditor = useFocus({
|
|
152
|
+
target: editorView
|
|
151
153
|
});
|
|
154
|
+
// returnFocusRef stores which function we call on unmount: focusButton | focusEditor
|
|
155
|
+
// Needs to be a ref so we can instantly toggle it before unmounting triggers the focus trap
|
|
156
|
+
const returnFocusRef = React.useRef(focusEditor);
|
|
157
|
+
// When inserting media, close picker and focus editor.
|
|
158
|
+
const closeAndFocusEditor = React.useCallback(() => {
|
|
159
|
+
returnFocusRef.current = focusEditor;
|
|
160
|
+
closeMediaInsertPicker();
|
|
161
|
+
}, [closeMediaInsertPicker, focusEditor]);
|
|
162
|
+
// When cancelling, close picker and return focus to button.
|
|
163
|
+
const closeAndReturnFocusToButton = React.useCallback(() => {
|
|
164
|
+
returnFocusRef.current = focusButton;
|
|
165
|
+
closeMediaInsertPicker();
|
|
166
|
+
}, [closeMediaInsertPicker, focusButton]);
|
|
167
|
+
const intl = useIntl();
|
|
152
168
|
const {
|
|
153
169
|
autofocusRef,
|
|
154
170
|
onPositionCalculated
|
|
@@ -279,14 +295,18 @@ export const MediaInsertPicker = ({
|
|
|
279
295
|
};
|
|
280
296
|
dispatchAnalyticsEvent(payload);
|
|
281
297
|
}
|
|
282
|
-
|
|
283
|
-
|
|
298
|
+
if (isExperimentEnabled('platform_editor_fix_focus_MediaInsertPicker')) {
|
|
299
|
+
closeAndReturnFocusToButton();
|
|
300
|
+
} else {
|
|
301
|
+
closeMediaInsertPicker(); // Focuses editor on unmount
|
|
284
302
|
focusEditor();
|
|
285
303
|
}
|
|
286
304
|
};
|
|
287
305
|
const closePickerAndFocusEditor = () => {
|
|
288
|
-
|
|
289
|
-
|
|
306
|
+
if (isExperimentEnabled('platform_editor_fix_focus_MediaInsertPicker')) {
|
|
307
|
+
closeAndFocusEditor();
|
|
308
|
+
} else {
|
|
309
|
+
closeMediaInsertPicker();
|
|
290
310
|
focusEditor();
|
|
291
311
|
}
|
|
292
312
|
};
|
|
@@ -301,7 +321,7 @@ export const MediaInsertPicker = ({
|
|
|
301
321
|
fitHeight: 390,
|
|
302
322
|
fitWidth: 340,
|
|
303
323
|
mountTo: mountPoint,
|
|
304
|
-
onUnmount: isExperimentEnabled('platform_editor_fix_focus_MediaInsertPicker') ?
|
|
324
|
+
onUnmount: isExperimentEnabled('platform_editor_fix_focus_MediaInsertPicker') ? () => returnFocusRef.current() : undefined,
|
|
305
325
|
boundariesElement: popupsBoundariesElement,
|
|
306
326
|
handleClickOutside: handleClose(INPUT_METHOD.MOUSE),
|
|
307
327
|
handleEscapeKeydown: handleClose(INPUT_METHOD.KEYBOARD),
|
|
@@ -352,6 +372,7 @@ export const MediaInsertPicker = ({
|
|
|
352
372
|
mediaProvider: mediaProvider,
|
|
353
373
|
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
354
374
|
closeMediaInsertPicker: closePickerAndFocusEditor,
|
|
375
|
+
cancelMediaInsertPicker: closeAndReturnFocusToButton,
|
|
355
376
|
insertMediaSingle: insertMediaSingle,
|
|
356
377
|
insertExternalMediaSingle: insertExternalMediaSingle,
|
|
357
378
|
isOnlyExternalLinks: isOnlyExternalLinks,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
|
|
3
|
+
// Usually either a DOM node or editorView
|
|
4
|
+
|
|
5
|
+
export const useFocus = ({
|
|
6
|
+
target
|
|
7
|
+
}) => {
|
|
8
|
+
const focus = useCallback(() => {
|
|
9
|
+
// Use setTimeout to run this async after any DOM updates in same callback
|
|
10
|
+
setTimeout(() => target.focus(), 0);
|
|
11
|
+
}, [target]);
|
|
12
|
+
return focus;
|
|
13
|
+
};
|
|
@@ -22,6 +22,7 @@ import { HelperMessage } from '@atlaskit/form/helper-message';
|
|
|
22
22
|
import { MessageWrapper } from '@atlaskit/form/message-wrapper';
|
|
23
23
|
import ExpandIcon from '@atlaskit/icon/core/grow-diagonal';
|
|
24
24
|
import { getMediaClient } from '@atlaskit/media-client-react/get-media-client';
|
|
25
|
+
import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
|
|
25
26
|
// eslint-disable-next-line @atlaskit/design-system/no-emotion-primitives -- to be migrated to @atlaskit/primitives/compiled – go/akcss
|
|
26
27
|
import { Box, Flex, Inline, Stack, xcss } from '@atlaskit/primitives';
|
|
27
28
|
import SectionMessage from '@atlaskit/section-message/message';
|
|
@@ -98,6 +99,8 @@ export function MediaFromURL(_ref) {
|
|
|
98
99
|
var mediaProvider = _ref.mediaProvider,
|
|
99
100
|
dispatchAnalyticsEvent = _ref.dispatchAnalyticsEvent,
|
|
100
101
|
closeMediaInsertPicker = _ref.closeMediaInsertPicker,
|
|
102
|
+
_ref$cancelMediaInser = _ref.cancelMediaInsertPicker,
|
|
103
|
+
cancelMediaInsertPicker = _ref$cancelMediaInser === void 0 ? closeMediaInsertPicker : _ref$cancelMediaInser,
|
|
101
104
|
insertMediaSingle = _ref.insertMediaSingle,
|
|
102
105
|
insertExternalMediaSingle = _ref.insertExternalMediaSingle,
|
|
103
106
|
isOnlyExternalLinks = _ref.isOnlyExternalLinks,
|
|
@@ -267,9 +270,13 @@ export function MediaFromURL(_ref) {
|
|
|
267
270
|
};
|
|
268
271
|
dispatchAnalyticsEvent(payload);
|
|
269
272
|
}
|
|
270
|
-
|
|
273
|
+
if (isExperimentEnabled('platform_editor_fix_focus_MediaInsertPicker')) {
|
|
274
|
+
cancelMediaInsertPicker();
|
|
275
|
+
} else {
|
|
276
|
+
closeMediaInsertPicker();
|
|
277
|
+
}
|
|
271
278
|
}
|
|
272
|
-
}, [dispatchAnalyticsEvent, closeMediaInsertPicker]);
|
|
279
|
+
}, [dispatchAnalyticsEvent, cancelMediaInsertPicker, closeMediaInsertPicker]);
|
|
273
280
|
var onCancel = React.useCallback(function () {
|
|
274
281
|
if (dispatchAnalyticsEvent) {
|
|
275
282
|
var payload = {
|
|
@@ -280,8 +287,12 @@ export function MediaFromURL(_ref) {
|
|
|
280
287
|
};
|
|
281
288
|
dispatchAnalyticsEvent(payload);
|
|
282
289
|
}
|
|
283
|
-
|
|
284
|
-
|
|
290
|
+
if (isExperimentEnabled('platform_editor_fix_focus_MediaInsertPicker')) {
|
|
291
|
+
cancelMediaInsertPicker();
|
|
292
|
+
} else {
|
|
293
|
+
closeMediaInsertPicker();
|
|
294
|
+
}
|
|
295
|
+
}, [cancelMediaInsertPicker, dispatchAnalyticsEvent, closeMediaInsertPicker]);
|
|
285
296
|
return /*#__PURE__*/React.createElement(Form, {
|
|
286
297
|
// eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed)
|
|
287
298
|
onSubmit: function onSubmit(_ref3, form) {
|
|
@@ -18,7 +18,7 @@ import TabList from '@atlaskit/tabs/tab-list';
|
|
|
18
18
|
import useTab from '@atlaskit/tabs/use-tab';
|
|
19
19
|
import useTabPanel from '@atlaskit/tabs/use-tab-panel';
|
|
20
20
|
import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
|
|
21
|
-
import {
|
|
21
|
+
import { useFocus } from './hooks/use-focus';
|
|
22
22
|
import { useUnholyAutofocus } from './hooks/use-unholy-autofocus';
|
|
23
23
|
import { LocalMedia } from './LocalMedia';
|
|
24
24
|
import { MediaFromURL } from './MediaFromURL';
|
|
@@ -147,10 +147,26 @@ export var MediaInsertPicker = function MediaInsertPicker(_ref3) {
|
|
|
147
147
|
targetRef = getDomRefFromSelection(editorView, ACTION_SUBJECT_ID.PICKER_MEDIA, api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions);
|
|
148
148
|
mountPoint = popupsMountPoint;
|
|
149
149
|
}
|
|
150
|
-
var
|
|
151
|
-
|
|
152
|
-
|
|
150
|
+
var focusButton = useFocus({
|
|
151
|
+
target: targetRef !== null && targetRef !== void 0 ? targetRef : editorView
|
|
152
|
+
});
|
|
153
|
+
var focusEditor = useFocus({
|
|
154
|
+
target: editorView
|
|
153
155
|
});
|
|
156
|
+
// returnFocusRef stores which function we call on unmount: focusButton | focusEditor
|
|
157
|
+
// Needs to be a ref so we can instantly toggle it before unmounting triggers the focus trap
|
|
158
|
+
var returnFocusRef = React.useRef(focusEditor);
|
|
159
|
+
// When inserting media, close picker and focus editor.
|
|
160
|
+
var closeAndFocusEditor = React.useCallback(function () {
|
|
161
|
+
returnFocusRef.current = focusEditor;
|
|
162
|
+
closeMediaInsertPicker();
|
|
163
|
+
}, [closeMediaInsertPicker, focusEditor]);
|
|
164
|
+
// When cancelling, close picker and return focus to button.
|
|
165
|
+
var closeAndReturnFocusToButton = React.useCallback(function () {
|
|
166
|
+
returnFocusRef.current = focusButton;
|
|
167
|
+
closeMediaInsertPicker();
|
|
168
|
+
}, [closeMediaInsertPicker, focusButton]);
|
|
169
|
+
var intl = useIntl();
|
|
154
170
|
var _useUnholyAutofocus = useUnholyAutofocus(),
|
|
155
171
|
autofocusRef = _useUnholyAutofocus.autofocusRef,
|
|
156
172
|
onPositionCalculated = _useUnholyAutofocus.onPositionCalculated;
|
|
@@ -285,15 +301,19 @@ export var MediaInsertPicker = function MediaInsertPicker(_ref3) {
|
|
|
285
301
|
};
|
|
286
302
|
dispatchAnalyticsEvent(payload);
|
|
287
303
|
}
|
|
288
|
-
|
|
289
|
-
|
|
304
|
+
if (isExperimentEnabled('platform_editor_fix_focus_MediaInsertPicker')) {
|
|
305
|
+
closeAndReturnFocusToButton();
|
|
306
|
+
} else {
|
|
307
|
+
closeMediaInsertPicker(); // Focuses editor on unmount
|
|
290
308
|
focusEditor();
|
|
291
309
|
}
|
|
292
310
|
};
|
|
293
311
|
};
|
|
294
312
|
var closePickerAndFocusEditor = function closePickerAndFocusEditor() {
|
|
295
|
-
|
|
296
|
-
|
|
313
|
+
if (isExperimentEnabled('platform_editor_fix_focus_MediaInsertPicker')) {
|
|
314
|
+
closeAndFocusEditor();
|
|
315
|
+
} else {
|
|
316
|
+
closeMediaInsertPicker();
|
|
297
317
|
focusEditor();
|
|
298
318
|
}
|
|
299
319
|
};
|
|
@@ -308,7 +328,9 @@ export var MediaInsertPicker = function MediaInsertPicker(_ref3) {
|
|
|
308
328
|
fitHeight: 390,
|
|
309
329
|
fitWidth: 340,
|
|
310
330
|
mountTo: mountPoint,
|
|
311
|
-
onUnmount: isExperimentEnabled('platform_editor_fix_focus_MediaInsertPicker') ?
|
|
331
|
+
onUnmount: isExperimentEnabled('platform_editor_fix_focus_MediaInsertPicker') ? function () {
|
|
332
|
+
return returnFocusRef.current();
|
|
333
|
+
} : undefined,
|
|
312
334
|
boundariesElement: popupsBoundariesElement,
|
|
313
335
|
handleClickOutside: handleClose(INPUT_METHOD.MOUSE),
|
|
314
336
|
handleEscapeKeydown: handleClose(INPUT_METHOD.KEYBOARD),
|
|
@@ -362,6 +384,7 @@ export var MediaInsertPicker = function MediaInsertPicker(_ref3) {
|
|
|
362
384
|
mediaProvider: mediaProvider,
|
|
363
385
|
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
364
386
|
closeMediaInsertPicker: closePickerAndFocusEditor,
|
|
387
|
+
cancelMediaInsertPicker: closeAndReturnFocusToButton,
|
|
365
388
|
insertMediaSingle: insertMediaSingle,
|
|
366
389
|
insertExternalMediaSingle: insertExternalMediaSingle,
|
|
367
390
|
isOnlyExternalLinks: isOnlyExternalLinks,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
|
|
3
|
+
// Usually either a DOM node or editorView
|
|
4
|
+
|
|
5
|
+
export var useFocus = function useFocus(_ref) {
|
|
6
|
+
var target = _ref.target;
|
|
7
|
+
var focus = useCallback(function () {
|
|
8
|
+
// Use setTimeout to run this async after any DOM updates in same callback
|
|
9
|
+
setTimeout(function () {
|
|
10
|
+
return target.focus();
|
|
11
|
+
}, 0);
|
|
12
|
+
}, [target]);
|
|
13
|
+
return focus;
|
|
14
|
+
};
|
|
@@ -4,6 +4,7 @@ import type { MediaProvider } from '@atlaskit/editor-common/provider-factory';
|
|
|
4
4
|
import type { CustomizedHelperMessage, InsertExternalMediaSingle, InsertMediaSingle } from '../types';
|
|
5
5
|
export declare const isValidUrl: (value: string) => boolean;
|
|
6
6
|
type Props = {
|
|
7
|
+
cancelMediaInsertPicker?: () => void;
|
|
7
8
|
closeMediaInsertPicker: () => void;
|
|
8
9
|
customizedHelperMessage?: CustomizedHelperMessage;
|
|
9
10
|
customizedUrlValidation?: (input: string) => boolean;
|
|
@@ -13,5 +14,5 @@ type Props = {
|
|
|
13
14
|
isOnlyExternalLinks: boolean;
|
|
14
15
|
mediaProvider: MediaProvider;
|
|
15
16
|
};
|
|
16
|
-
export declare function MediaFromURL({ mediaProvider, dispatchAnalyticsEvent, closeMediaInsertPicker, insertMediaSingle, insertExternalMediaSingle, isOnlyExternalLinks, customizedUrlValidation, customizedHelperMessage, }: Props): React.JSX.Element;
|
|
17
|
+
export declare function MediaFromURL({ mediaProvider, dispatchAnalyticsEvent, closeMediaInsertPicker, cancelMediaInsertPicker, insertMediaSingle, insertExternalMediaSingle, isOnlyExternalLinks, customizedUrlValidation, customizedHelperMessage, }: Props): React.JSX.Element;
|
|
17
18
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-media-insert",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.1.1",
|
|
4
4
|
"description": "Media Insert plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -42,11 +42,12 @@
|
|
|
42
42
|
"@atlaskit/section-message": "^10.1.0",
|
|
43
43
|
"@atlaskit/tabs": "^21.1.0",
|
|
44
44
|
"@atlaskit/textfield": "^10.1.0",
|
|
45
|
-
"@atlaskit/tmp-editor-statsig": "^
|
|
45
|
+
"@atlaskit/tmp-editor-statsig": "^162.0.0",
|
|
46
46
|
"@babel/runtime": "^7.0.0"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
|
-
"@atlaskit/editor-common": "^120.
|
|
49
|
+
"@atlaskit/editor-common": "^120.2.0",
|
|
50
|
+
"@atlaskit/platform-feature-flags-react": "^1.1.0",
|
|
50
51
|
"@atlaskit/tokens": "^16.8.0",
|
|
51
52
|
"react": "^18.2.0 || ^19.2.0",
|
|
52
53
|
"react-dom": "^18.2.0 || ^19.2.0",
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.useFocusEditor = void 0;
|
|
7
|
-
var _react = require("react");
|
|
8
|
-
var useFocusEditor = exports.useFocusEditor = function useFocusEditor(_ref) {
|
|
9
|
-
var editorView = _ref.editorView;
|
|
10
|
-
var focusEditor = (0, _react.useCallback)(function () {
|
|
11
|
-
// Use setTimeout to run this async after any DOM updates in same callback
|
|
12
|
-
setTimeout(function () {
|
|
13
|
-
return editorView.focus();
|
|
14
|
-
}, 0);
|
|
15
|
-
}, [editorView]);
|
|
16
|
-
return focusEditor;
|
|
17
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { useCallback } from 'react';
|
|
2
|
-
export const useFocusEditor = ({
|
|
3
|
-
editorView
|
|
4
|
-
}) => {
|
|
5
|
-
const focusEditor = useCallback(() => {
|
|
6
|
-
// Use setTimeout to run this async after any DOM updates in same callback
|
|
7
|
-
setTimeout(() => editorView.focus(), 0);
|
|
8
|
-
}, [editorView]);
|
|
9
|
-
return focusEditor;
|
|
10
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { useCallback } from 'react';
|
|
2
|
-
export var useFocusEditor = function useFocusEditor(_ref) {
|
|
3
|
-
var editorView = _ref.editorView;
|
|
4
|
-
var focusEditor = useCallback(function () {
|
|
5
|
-
// Use setTimeout to run this async after any DOM updates in same callback
|
|
6
|
-
setTimeout(function () {
|
|
7
|
-
return editorView.focus();
|
|
8
|
-
}, 0);
|
|
9
|
-
}, [editorView]);
|
|
10
|
-
return focusEditor;
|
|
11
|
-
};
|