@atlaskit/editor-plugin-media-insert 2.2.0 → 2.3.0
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 +12 -0
- package/dist/cjs/plugin.js +48 -4
- package/dist/cjs/ui/LocalMedia.js +14 -5
- package/dist/cjs/ui/MediaFromURL.js +33 -12
- package/dist/cjs/ui/MediaInsertContent.js +7 -5
- package/dist/cjs/ui/MediaInsertPicker.js +6 -2
- package/dist/es2019/plugin.js +49 -3
- package/dist/es2019/ui/LocalMedia.js +14 -5
- package/dist/es2019/ui/MediaFromURL.js +28 -7
- package/dist/es2019/ui/MediaInsertContent.js +7 -5
- package/dist/es2019/ui/MediaInsertPicker.js +6 -2
- package/dist/esm/plugin.js +48 -4
- package/dist/esm/ui/LocalMedia.js +14 -5
- package/dist/esm/ui/MediaFromURL.js +33 -12
- package/dist/esm/ui/MediaInsertContent.js +7 -5
- package/dist/esm/ui/MediaInsertPicker.js +6 -2
- package/dist/types/types.d.ts +13 -0
- package/dist/types/ui/LocalMedia.d.ts +2 -2
- package/dist/types/ui/MediaFromURL.d.ts +4 -4
- package/dist/types/ui/MediaInsertContent.d.ts +8 -3
- package/dist/types/ui/MediaInsertPicker.d.ts +1 -1
- package/dist/types/ui/types.d.ts +1 -0
- package/dist/types-ts4.5/types.d.ts +13 -0
- package/dist/types-ts4.5/ui/LocalMedia.d.ts +2 -2
- package/dist/types-ts4.5/ui/MediaFromURL.d.ts +4 -4
- package/dist/types-ts4.5/ui/MediaInsertContent.d.ts +8 -3
- package/dist/types-ts4.5/ui/MediaInsertPicker.d.ts +1 -1
- package/dist/types-ts4.5/ui/types.d.ts +1 -0
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-media-insert
|
|
2
2
|
|
|
3
|
+
## 2.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#134882](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/134882)
|
|
8
|
+
[`ba204702f8e32`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/ba204702f8e32) -
|
|
9
|
+
[ux] [ED-24567] Insert media into the editor via the media insert picker
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies
|
|
14
|
+
|
|
3
15
|
## 2.2.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/dist/cjs/plugin.js
CHANGED
|
@@ -43,6 +43,48 @@ var mediaInsertPlugin = exports.mediaInsertPlugin = function mediaInsertPlugin(_
|
|
|
43
43
|
popupsMountPoint = _ref3.popupsMountPoint,
|
|
44
44
|
popupsBoundariesElement = _ref3.popupsBoundariesElement,
|
|
45
45
|
popupsScrollableElement = _ref3.popupsScrollableElement;
|
|
46
|
+
var insertMediaSingle = function insertMediaSingle(_ref4) {
|
|
47
|
+
var _api$media$actions$in;
|
|
48
|
+
var mediaState = _ref4.mediaState,
|
|
49
|
+
inputMethod = _ref4.inputMethod;
|
|
50
|
+
var id = mediaState.id,
|
|
51
|
+
dimensions = mediaState.dimensions,
|
|
52
|
+
contextId = mediaState.contextId,
|
|
53
|
+
_mediaState$scaleFact = mediaState.scaleFactor,
|
|
54
|
+
scaleFactor = _mediaState$scaleFact === void 0 ? 1 : _mediaState$scaleFact,
|
|
55
|
+
fileName = mediaState.fileName,
|
|
56
|
+
collection = mediaState.collection;
|
|
57
|
+
var _ref5 = dimensions || {
|
|
58
|
+
height: undefined,
|
|
59
|
+
width: undefined
|
|
60
|
+
},
|
|
61
|
+
width = _ref5.width,
|
|
62
|
+
height = _ref5.height;
|
|
63
|
+
var scaledWidth = width && Math.round(width / scaleFactor);
|
|
64
|
+
var node = editorView.state.schema.nodes.media.create({
|
|
65
|
+
id: id,
|
|
66
|
+
type: 'file',
|
|
67
|
+
collection: collection,
|
|
68
|
+
contextId: contextId,
|
|
69
|
+
width: scaledWidth,
|
|
70
|
+
height: height && Math.round(height / scaleFactor),
|
|
71
|
+
alt: fileName,
|
|
72
|
+
__fileMimeType: mediaState.fileMimeType
|
|
73
|
+
});
|
|
74
|
+
return (_api$media$actions$in = api === null || api === void 0 ? void 0 : api.media.actions.insertMediaAsMediaSingle(editorView, node, inputMethod)) !== null && _api$media$actions$in !== void 0 ? _api$media$actions$in : false;
|
|
75
|
+
};
|
|
76
|
+
var insertExternalMediaSingle = function insertExternalMediaSingle(_ref6) {
|
|
77
|
+
var _api$media$actions$in2;
|
|
78
|
+
var url = _ref6.url,
|
|
79
|
+
alt = _ref6.alt,
|
|
80
|
+
inputMethod = _ref6.inputMethod;
|
|
81
|
+
var node = editorView.state.schema.nodes.media.create({
|
|
82
|
+
type: 'external',
|
|
83
|
+
url: url,
|
|
84
|
+
alt: alt
|
|
85
|
+
});
|
|
86
|
+
return (_api$media$actions$in2 = api === null || api === void 0 ? void 0 : api.media.actions.insertMediaAsMediaSingle(editorView, node, inputMethod)) !== null && _api$media$actions$in2 !== void 0 ? _api$media$actions$in2 : false;
|
|
87
|
+
};
|
|
46
88
|
return /*#__PURE__*/_react.default.createElement(_MediaInsertPicker.MediaInsertPicker, {
|
|
47
89
|
api: api,
|
|
48
90
|
editorView: editorView,
|
|
@@ -51,13 +93,15 @@ var mediaInsertPlugin = exports.mediaInsertPlugin = function mediaInsertPlugin(_
|
|
|
51
93
|
popupsBoundariesElement: popupsBoundariesElement,
|
|
52
94
|
popupsScrollableElement: popupsScrollableElement,
|
|
53
95
|
closeMediaInsertPicker: function closeMediaInsertPicker() {
|
|
54
|
-
editorView.dispatch((0, _actions.closeMediaInsertPicker)(editorView.state.tr));
|
|
55
|
-
}
|
|
96
|
+
return editorView.dispatch((0, _actions.closeMediaInsertPicker)(editorView.state.tr));
|
|
97
|
+
},
|
|
98
|
+
insertMediaSingle: insertMediaSingle,
|
|
99
|
+
insertExternalMediaSingle: insertExternalMediaSingle
|
|
56
100
|
});
|
|
57
101
|
},
|
|
58
102
|
pluginsOptions: {
|
|
59
|
-
quickInsert: function quickInsert(
|
|
60
|
-
var formatMessage =
|
|
103
|
+
quickInsert: function quickInsert(_ref7) {
|
|
104
|
+
var formatMessage = _ref7.formatMessage;
|
|
61
105
|
return [{
|
|
62
106
|
id: 'media-insert',
|
|
63
107
|
title: formatMessage(_messages.toolbarInsertBlockMessages.insertMediaFromUrl),
|
|
@@ -10,6 +10,7 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
|
|
|
10
10
|
var _react = _interopRequireDefault(require("react"));
|
|
11
11
|
var _reactIntlNext = require("react-intl-next");
|
|
12
12
|
var _new = _interopRequireDefault(require("@atlaskit/button/new"));
|
|
13
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
13
14
|
var _messages = require("@atlaskit/editor-common/messages");
|
|
14
15
|
var _upload = _interopRequireDefault(require("@atlaskit/icon/glyph/upload"));
|
|
15
16
|
var _mediaPicker = require("@atlaskit/media-picker");
|
|
@@ -70,16 +71,24 @@ var LocalMedia = exports.LocalMedia = function LocalMedia(_ref) {
|
|
|
70
71
|
var file = _ref2.file,
|
|
71
72
|
preview = _ref2.preview;
|
|
72
73
|
onUploadSuccessAnalytics('local');
|
|
73
|
-
var
|
|
74
|
+
var mediaState = {
|
|
74
75
|
id: file.id,
|
|
75
76
|
collection: (_mediaProvider$upload = mediaProvider.uploadParams) === null || _mediaProvider$upload === void 0 ? void 0 : _mediaProvider$upload.collection,
|
|
76
|
-
|
|
77
|
+
fileMimeType: file.type,
|
|
78
|
+
fileSize: file.size,
|
|
79
|
+
fileName: file.name,
|
|
80
|
+
dimensions: undefined
|
|
77
81
|
};
|
|
78
82
|
if (isImagePreview(preview)) {
|
|
79
|
-
|
|
80
|
-
|
|
83
|
+
mediaState.dimensions = {
|
|
84
|
+
width: preview.dimensions.width,
|
|
85
|
+
height: preview.dimensions.height
|
|
86
|
+
};
|
|
81
87
|
}
|
|
82
|
-
onInsert(
|
|
88
|
+
onInsert({
|
|
89
|
+
mediaState: mediaState,
|
|
90
|
+
inputMethod: _analytics.INPUT_METHOD.MEDIA_PICKER
|
|
91
|
+
});
|
|
83
92
|
|
|
84
93
|
// Probably not needed but I guess it _could_ fail to close for some reason
|
|
85
94
|
dispatch({
|
|
@@ -72,10 +72,10 @@ var previewStateReducer = function previewStateReducer(state, action) {
|
|
|
72
72
|
};
|
|
73
73
|
function MediaFromURL(_ref) {
|
|
74
74
|
var mediaProvider = _ref.mediaProvider,
|
|
75
|
-
onInsert = _ref.onInsert,
|
|
76
|
-
onExternalInsert = _ref.onExternalInsert,
|
|
77
75
|
dispatchAnalyticsEvent = _ref.dispatchAnalyticsEvent,
|
|
78
|
-
closeMediaInsertPicker = _ref.closeMediaInsertPicker
|
|
76
|
+
closeMediaInsertPicker = _ref.closeMediaInsertPicker,
|
|
77
|
+
insertMediaSingle = _ref.insertMediaSingle,
|
|
78
|
+
insertExternalMediaSingle = _ref.insertExternalMediaSingle;
|
|
79
79
|
var intl = (0, _reactIntlNext.useIntl)();
|
|
80
80
|
var strings = {
|
|
81
81
|
loadPreview: intl.formatMessage(_messages.mediaInsertMessages.loadPreview),
|
|
@@ -101,7 +101,7 @@ function MediaFromURL(_ref) {
|
|
|
101
101
|
onUploadFailureAnalytics = _useAnalyticsEvents.onUploadFailureAnalytics;
|
|
102
102
|
var uploadExternalMedia = _react.default.useCallback( /*#__PURE__*/function () {
|
|
103
103
|
var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(url) {
|
|
104
|
-
var uploadMediaClientConfig, uploadParams, mediaClient, collection, _yield$mediaClient$fi, uploadableFileUpfrontIds, dimensions, message;
|
|
104
|
+
var uploadMediaClientConfig, uploadParams, mediaClient, collection, _yield$mediaClient$fi, uploadableFileUpfrontIds, dimensions, mimeType, message;
|
|
105
105
|
return _regenerator.default.wrap(function _callee$(_context) {
|
|
106
106
|
while (1) switch (_context.prev = _context.next) {
|
|
107
107
|
case 0:
|
|
@@ -126,6 +126,7 @@ function MediaFromURL(_ref) {
|
|
|
126
126
|
_yield$mediaClient$fi = _context.sent;
|
|
127
127
|
uploadableFileUpfrontIds = _yield$mediaClient$fi.uploadableFileUpfrontIds;
|
|
128
128
|
dimensions = _yield$mediaClient$fi.dimensions;
|
|
129
|
+
mimeType = _yield$mediaClient$fi.mimeType;
|
|
129
130
|
onUploadSuccessAnalytics('url');
|
|
130
131
|
dispatch({
|
|
131
132
|
type: 'success',
|
|
@@ -134,13 +135,14 @@ function MediaFromURL(_ref) {
|
|
|
134
135
|
collection: collection,
|
|
135
136
|
height: dimensions.height,
|
|
136
137
|
width: dimensions.width,
|
|
137
|
-
occurrenceKey: uploadableFileUpfrontIds.occurrenceKey
|
|
138
|
+
occurrenceKey: uploadableFileUpfrontIds.occurrenceKey,
|
|
139
|
+
fileMimeType: mimeType
|
|
138
140
|
}
|
|
139
141
|
});
|
|
140
|
-
_context.next =
|
|
142
|
+
_context.next = 22;
|
|
141
143
|
break;
|
|
142
|
-
case
|
|
143
|
-
_context.prev =
|
|
144
|
+
case 19:
|
|
145
|
+
_context.prev = 19;
|
|
144
146
|
_context.t0 = _context["catch"](8);
|
|
145
147
|
if (typeof _context.t0 === 'string' && _context.t0 === 'Could not download remote file') {
|
|
146
148
|
// TODO: Make sure this gets good unit test coverage with the actual
|
|
@@ -166,11 +168,11 @@ function MediaFromURL(_ref) {
|
|
|
166
168
|
error: 'Unknown error'
|
|
167
169
|
});
|
|
168
170
|
}
|
|
169
|
-
case
|
|
171
|
+
case 22:
|
|
170
172
|
case "end":
|
|
171
173
|
return _context.stop();
|
|
172
174
|
}
|
|
173
|
-
}, _callee, null, [[8,
|
|
175
|
+
}, _callee, null, [[8, 19]]);
|
|
174
176
|
}));
|
|
175
177
|
return function (_x) {
|
|
176
178
|
return _ref2.apply(this, arguments);
|
|
@@ -198,14 +200,33 @@ function MediaFromURL(_ref) {
|
|
|
198
200
|
pasteFlag.current = true;
|
|
199
201
|
}
|
|
200
202
|
}, [inputUrl]);
|
|
203
|
+
var onInsert = _react.default.useCallback(function () {
|
|
204
|
+
if (previewState.previewInfo) {
|
|
205
|
+
insertMediaSingle({
|
|
206
|
+
mediaState: previewState.previewInfo,
|
|
207
|
+
inputMethod: _analytics.INPUT_METHOD.MEDIA_PICKER
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
closeMediaInsertPicker();
|
|
211
|
+
}, [closeMediaInsertPicker, insertMediaSingle, previewState.previewInfo]);
|
|
212
|
+
var onExternalInsert = _react.default.useCallback(function (url) {
|
|
213
|
+
if (previewState.warning) {
|
|
214
|
+
insertExternalMediaSingle({
|
|
215
|
+
url: url,
|
|
216
|
+
alt: url,
|
|
217
|
+
inputMethod: _analytics.INPUT_METHOD.MEDIA_PICKER
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
closeMediaInsertPicker();
|
|
221
|
+
}, [closeMediaInsertPicker, insertExternalMediaSingle, previewState.warning]);
|
|
201
222
|
var onInsertClick = _react.default.useCallback(function () {
|
|
202
223
|
if (previewState.previewInfo) {
|
|
203
|
-
return onInsert(
|
|
224
|
+
return onInsert();
|
|
204
225
|
}
|
|
205
226
|
if (previewState.warning) {
|
|
206
227
|
return onExternalInsert(inputUrl);
|
|
207
228
|
}
|
|
208
|
-
}, [
|
|
229
|
+
}, [previewState.previewInfo, previewState.warning, onInsert, onExternalInsert, inputUrl]);
|
|
209
230
|
var onInputKeyPress = _react.default.useCallback(function (event) {
|
|
210
231
|
if (event && event.key === 'Esc') {
|
|
211
232
|
if (dispatchAnalyticsEvent) {
|
|
@@ -18,7 +18,9 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
|
|
|
18
18
|
var MediaInsertContent = exports.MediaInsertContent = function MediaInsertContent(_ref) {
|
|
19
19
|
var mediaProvider = _ref.mediaProvider,
|
|
20
20
|
dispatchAnalyticsEvent = _ref.dispatchAnalyticsEvent,
|
|
21
|
-
closeMediaInsertPicker = _ref.closeMediaInsertPicker
|
|
21
|
+
closeMediaInsertPicker = _ref.closeMediaInsertPicker,
|
|
22
|
+
insertMediaSingle = _ref.insertMediaSingle,
|
|
23
|
+
insertExternalMediaSingle = _ref.insertExternalMediaSingle;
|
|
22
24
|
var intl = (0, _reactIntlNext.useIntl)();
|
|
23
25
|
return /*#__PURE__*/_react.default.createElement(_tabs.default, {
|
|
24
26
|
id: "media-insert-tab-navigation"
|
|
@@ -26,14 +28,14 @@ var MediaInsertContent = exports.MediaInsertContent = function MediaInsertConten
|
|
|
26
28
|
paddingBlockEnd: "space.150"
|
|
27
29
|
}, /*#__PURE__*/_react.default.createElement(_tabs.TabList, null, /*#__PURE__*/_react.default.createElement(_tabs.Tab, null, intl.formatMessage(_messages.mediaInsertMessages.fileTabTitle)), /*#__PURE__*/_react.default.createElement(_tabs.Tab, null, intl.formatMessage(_messages.mediaInsertMessages.linkTabTitle)))), /*#__PURE__*/_react.default.createElement(_tabs.TabPanel, null, /*#__PURE__*/_react.default.createElement(_LocalMedia.LocalMedia, {
|
|
28
30
|
mediaProvider: mediaProvider,
|
|
29
|
-
onInsert:
|
|
31
|
+
onInsert: insertMediaSingle,
|
|
30
32
|
onClose: closeMediaInsertPicker,
|
|
31
33
|
dispatchAnalyticsEvent: dispatchAnalyticsEvent
|
|
32
34
|
})), /*#__PURE__*/_react.default.createElement(_tabs.TabPanel, null, /*#__PURE__*/_react.default.createElement(_MediaFromURL.MediaFromURL, {
|
|
33
35
|
mediaProvider: mediaProvider,
|
|
34
|
-
onExternalInsert: function onExternalInsert() {},
|
|
35
|
-
onInsert: function onInsert() {},
|
|
36
36
|
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
37
|
-
closeMediaInsertPicker: closeMediaInsertPicker
|
|
37
|
+
closeMediaInsertPicker: closeMediaInsertPicker,
|
|
38
|
+
insertMediaSingle: insertMediaSingle,
|
|
39
|
+
insertExternalMediaSingle: insertExternalMediaSingle
|
|
38
40
|
})));
|
|
39
41
|
};
|
|
@@ -48,7 +48,9 @@ var MediaInsertPicker = exports.MediaInsertPicker = function MediaInsertPicker(_
|
|
|
48
48
|
popupsMountPoint = _ref.popupsMountPoint,
|
|
49
49
|
popupsBoundariesElement = _ref.popupsBoundariesElement,
|
|
50
50
|
popupsScrollableElement = _ref.popupsScrollableElement,
|
|
51
|
-
_closeMediaInsertPicker = _ref.closeMediaInsertPicker
|
|
51
|
+
_closeMediaInsertPicker = _ref.closeMediaInsertPicker,
|
|
52
|
+
insertMediaSingle = _ref.insertMediaSingle,
|
|
53
|
+
insertExternalMediaSingle = _ref.insertExternalMediaSingle;
|
|
52
54
|
var targetRef = getDomRefFromSelection(editorView, dispatchAnalyticsEvent);
|
|
53
55
|
var isOpen = (_useSharedPluginState = (0, _hooks.useSharedPluginState)(api, ['mediaInsert'])) === null || _useSharedPluginState === void 0 || (_useSharedPluginState = _useSharedPluginState.mediaInsertState) === null || _useSharedPluginState === void 0 ? void 0 : _useSharedPluginState.isOpen;
|
|
54
56
|
var mediaProvider = (_useSharedPluginState2 = (0, _hooks.useSharedPluginState)(api, ['media'])) === null || _useSharedPluginState2 === void 0 || (_useSharedPluginState2 = _useSharedPluginState2.mediaState) === null || _useSharedPluginState2 === void 0 ? void 0 : _useSharedPluginState2.mediaProvider;
|
|
@@ -98,6 +100,8 @@ var MediaInsertPicker = exports.MediaInsertPicker = function MediaInsertPicker(_
|
|
|
98
100
|
closeMediaInsertPicker: function closeMediaInsertPicker() {
|
|
99
101
|
_closeMediaInsertPicker();
|
|
100
102
|
focusEditor();
|
|
101
|
-
}
|
|
103
|
+
},
|
|
104
|
+
insertMediaSingle: insertMediaSingle,
|
|
105
|
+
insertExternalMediaSingle: insertExternalMediaSingle
|
|
102
106
|
})));
|
|
103
107
|
};
|
package/dist/es2019/plugin.js
CHANGED
|
@@ -37,6 +37,52 @@ export const mediaInsertPlugin = ({
|
|
|
37
37
|
popupsBoundariesElement,
|
|
38
38
|
popupsScrollableElement
|
|
39
39
|
}) => {
|
|
40
|
+
const insertMediaSingle = ({
|
|
41
|
+
mediaState,
|
|
42
|
+
inputMethod
|
|
43
|
+
}) => {
|
|
44
|
+
var _api$media$actions$in;
|
|
45
|
+
const {
|
|
46
|
+
id,
|
|
47
|
+
dimensions,
|
|
48
|
+
contextId,
|
|
49
|
+
scaleFactor = 1,
|
|
50
|
+
fileName,
|
|
51
|
+
collection
|
|
52
|
+
} = mediaState;
|
|
53
|
+
const {
|
|
54
|
+
width,
|
|
55
|
+
height
|
|
56
|
+
} = dimensions || {
|
|
57
|
+
height: undefined,
|
|
58
|
+
width: undefined
|
|
59
|
+
};
|
|
60
|
+
const scaledWidth = width && Math.round(width / scaleFactor);
|
|
61
|
+
const node = editorView.state.schema.nodes.media.create({
|
|
62
|
+
id,
|
|
63
|
+
type: 'file',
|
|
64
|
+
collection,
|
|
65
|
+
contextId,
|
|
66
|
+
width: scaledWidth,
|
|
67
|
+
height: height && Math.round(height / scaleFactor),
|
|
68
|
+
alt: fileName,
|
|
69
|
+
__fileMimeType: mediaState.fileMimeType
|
|
70
|
+
});
|
|
71
|
+
return (_api$media$actions$in = api === null || api === void 0 ? void 0 : api.media.actions.insertMediaAsMediaSingle(editorView, node, inputMethod)) !== null && _api$media$actions$in !== void 0 ? _api$media$actions$in : false;
|
|
72
|
+
};
|
|
73
|
+
const insertExternalMediaSingle = ({
|
|
74
|
+
url,
|
|
75
|
+
alt,
|
|
76
|
+
inputMethod
|
|
77
|
+
}) => {
|
|
78
|
+
var _api$media$actions$in2;
|
|
79
|
+
const node = editorView.state.schema.nodes.media.create({
|
|
80
|
+
type: 'external',
|
|
81
|
+
url,
|
|
82
|
+
alt
|
|
83
|
+
});
|
|
84
|
+
return (_api$media$actions$in2 = api === null || api === void 0 ? void 0 : api.media.actions.insertMediaAsMediaSingle(editorView, node, inputMethod)) !== null && _api$media$actions$in2 !== void 0 ? _api$media$actions$in2 : false;
|
|
85
|
+
};
|
|
40
86
|
return /*#__PURE__*/React.createElement(MediaInsertPicker, {
|
|
41
87
|
api: api,
|
|
42
88
|
editorView: editorView,
|
|
@@ -44,9 +90,9 @@ export const mediaInsertPlugin = ({
|
|
|
44
90
|
popupsMountPoint: popupsMountPoint,
|
|
45
91
|
popupsBoundariesElement: popupsBoundariesElement,
|
|
46
92
|
popupsScrollableElement: popupsScrollableElement,
|
|
47
|
-
closeMediaInsertPicker: () =>
|
|
48
|
-
|
|
49
|
-
|
|
93
|
+
closeMediaInsertPicker: () => editorView.dispatch(closeMediaInsertPicker(editorView.state.tr)),
|
|
94
|
+
insertMediaSingle: insertMediaSingle,
|
|
95
|
+
insertExternalMediaSingle: insertExternalMediaSingle
|
|
50
96
|
});
|
|
51
97
|
},
|
|
52
98
|
pluginsOptions: {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { useIntl } from 'react-intl-next';
|
|
3
3
|
import Button from '@atlaskit/button/new';
|
|
4
|
+
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
4
5
|
import { mediaInsertMessages } from '@atlaskit/editor-common/messages';
|
|
5
6
|
import UploadIcon from '@atlaskit/icon/glyph/upload';
|
|
6
7
|
import { Browser } from '@atlaskit/media-picker';
|
|
@@ -62,16 +63,24 @@ export const LocalMedia = ({
|
|
|
62
63
|
}) => {
|
|
63
64
|
var _mediaProvider$upload;
|
|
64
65
|
onUploadSuccessAnalytics('local');
|
|
65
|
-
const
|
|
66
|
+
const mediaState = {
|
|
66
67
|
id: file.id,
|
|
67
68
|
collection: (_mediaProvider$upload = mediaProvider.uploadParams) === null || _mediaProvider$upload === void 0 ? void 0 : _mediaProvider$upload.collection,
|
|
68
|
-
|
|
69
|
+
fileMimeType: file.type,
|
|
70
|
+
fileSize: file.size,
|
|
71
|
+
fileName: file.name,
|
|
72
|
+
dimensions: undefined
|
|
69
73
|
};
|
|
70
74
|
if (isImagePreview(preview)) {
|
|
71
|
-
|
|
72
|
-
|
|
75
|
+
mediaState.dimensions = {
|
|
76
|
+
width: preview.dimensions.width,
|
|
77
|
+
height: preview.dimensions.height
|
|
78
|
+
};
|
|
73
79
|
}
|
|
74
|
-
onInsert(
|
|
80
|
+
onInsert({
|
|
81
|
+
mediaState,
|
|
82
|
+
inputMethod: INPUT_METHOD.MEDIA_PICKER
|
|
83
|
+
});
|
|
75
84
|
|
|
76
85
|
// Probably not needed but I guess it _could_ fail to close for some reason
|
|
77
86
|
dispatch({
|
|
@@ -63,10 +63,10 @@ const previewStateReducer = (state, action) => {
|
|
|
63
63
|
};
|
|
64
64
|
export function MediaFromURL({
|
|
65
65
|
mediaProvider,
|
|
66
|
-
onInsert,
|
|
67
|
-
onExternalInsert,
|
|
68
66
|
dispatchAnalyticsEvent,
|
|
69
|
-
closeMediaInsertPicker
|
|
67
|
+
closeMediaInsertPicker,
|
|
68
|
+
insertMediaSingle,
|
|
69
|
+
insertExternalMediaSingle
|
|
70
70
|
}) {
|
|
71
71
|
const intl = useIntl();
|
|
72
72
|
const strings = {
|
|
@@ -104,7 +104,8 @@ export function MediaFromURL({
|
|
|
104
104
|
try {
|
|
105
105
|
const {
|
|
106
106
|
uploadableFileUpfrontIds,
|
|
107
|
-
dimensions
|
|
107
|
+
dimensions,
|
|
108
|
+
mimeType
|
|
108
109
|
} = await mediaClient.file.uploadExternal(url, collection);
|
|
109
110
|
onUploadSuccessAnalytics('url');
|
|
110
111
|
dispatch({
|
|
@@ -114,7 +115,8 @@ export function MediaFromURL({
|
|
|
114
115
|
collection,
|
|
115
116
|
height: dimensions.height,
|
|
116
117
|
width: dimensions.width,
|
|
117
|
-
occurrenceKey: uploadableFileUpfrontIds.occurrenceKey
|
|
118
|
+
occurrenceKey: uploadableFileUpfrontIds.occurrenceKey,
|
|
119
|
+
fileMimeType: mimeType
|
|
118
120
|
}
|
|
119
121
|
});
|
|
120
122
|
} catch (e) {
|
|
@@ -166,14 +168,33 @@ export function MediaFromURL({
|
|
|
166
168
|
pasteFlag.current = true;
|
|
167
169
|
}
|
|
168
170
|
}, [inputUrl]);
|
|
171
|
+
const onInsert = React.useCallback(() => {
|
|
172
|
+
if (previewState.previewInfo) {
|
|
173
|
+
insertMediaSingle({
|
|
174
|
+
mediaState: previewState.previewInfo,
|
|
175
|
+
inputMethod: INPUT_METHOD.MEDIA_PICKER
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
closeMediaInsertPicker();
|
|
179
|
+
}, [closeMediaInsertPicker, insertMediaSingle, previewState.previewInfo]);
|
|
180
|
+
const onExternalInsert = React.useCallback(url => {
|
|
181
|
+
if (previewState.warning) {
|
|
182
|
+
insertExternalMediaSingle({
|
|
183
|
+
url,
|
|
184
|
+
alt: url,
|
|
185
|
+
inputMethod: INPUT_METHOD.MEDIA_PICKER
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
closeMediaInsertPicker();
|
|
189
|
+
}, [closeMediaInsertPicker, insertExternalMediaSingle, previewState.warning]);
|
|
169
190
|
const onInsertClick = React.useCallback(() => {
|
|
170
191
|
if (previewState.previewInfo) {
|
|
171
|
-
return onInsert(
|
|
192
|
+
return onInsert();
|
|
172
193
|
}
|
|
173
194
|
if (previewState.warning) {
|
|
174
195
|
return onExternalInsert(inputUrl);
|
|
175
196
|
}
|
|
176
|
-
}, [
|
|
197
|
+
}, [previewState.previewInfo, previewState.warning, onInsert, onExternalInsert, inputUrl]);
|
|
177
198
|
const onInputKeyPress = React.useCallback(event => {
|
|
178
199
|
if (event && event.key === 'Esc') {
|
|
179
200
|
if (dispatchAnalyticsEvent) {
|
|
@@ -8,7 +8,9 @@ import { MediaFromURL } from './MediaFromURL';
|
|
|
8
8
|
export const MediaInsertContent = ({
|
|
9
9
|
mediaProvider,
|
|
10
10
|
dispatchAnalyticsEvent,
|
|
11
|
-
closeMediaInsertPicker
|
|
11
|
+
closeMediaInsertPicker,
|
|
12
|
+
insertMediaSingle,
|
|
13
|
+
insertExternalMediaSingle
|
|
12
14
|
}) => {
|
|
13
15
|
const intl = useIntl();
|
|
14
16
|
return /*#__PURE__*/React.createElement(Tabs, {
|
|
@@ -17,14 +19,14 @@ export const MediaInsertContent = ({
|
|
|
17
19
|
paddingBlockEnd: "space.150"
|
|
18
20
|
}, /*#__PURE__*/React.createElement(TabList, null, /*#__PURE__*/React.createElement(Tab, null, intl.formatMessage(mediaInsertMessages.fileTabTitle)), /*#__PURE__*/React.createElement(Tab, null, intl.formatMessage(mediaInsertMessages.linkTabTitle)))), /*#__PURE__*/React.createElement(TabPanel, null, /*#__PURE__*/React.createElement(LocalMedia, {
|
|
19
21
|
mediaProvider: mediaProvider,
|
|
20
|
-
onInsert:
|
|
22
|
+
onInsert: insertMediaSingle,
|
|
21
23
|
onClose: closeMediaInsertPicker,
|
|
22
24
|
dispatchAnalyticsEvent: dispatchAnalyticsEvent
|
|
23
25
|
})), /*#__PURE__*/React.createElement(TabPanel, null, /*#__PURE__*/React.createElement(MediaFromURL, {
|
|
24
26
|
mediaProvider: mediaProvider,
|
|
25
|
-
onExternalInsert: () => {},
|
|
26
|
-
onInsert: () => {},
|
|
27
27
|
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
28
|
-
closeMediaInsertPicker: closeMediaInsertPicker
|
|
28
|
+
closeMediaInsertPicker: closeMediaInsertPicker,
|
|
29
|
+
insertMediaSingle: insertMediaSingle,
|
|
30
|
+
insertExternalMediaSingle: insertExternalMediaSingle
|
|
29
31
|
})));
|
|
30
32
|
};
|
|
@@ -40,7 +40,9 @@ export const MediaInsertPicker = ({
|
|
|
40
40
|
popupsMountPoint,
|
|
41
41
|
popupsBoundariesElement,
|
|
42
42
|
popupsScrollableElement,
|
|
43
|
-
closeMediaInsertPicker
|
|
43
|
+
closeMediaInsertPicker,
|
|
44
|
+
insertMediaSingle,
|
|
45
|
+
insertExternalMediaSingle
|
|
44
46
|
}) => {
|
|
45
47
|
var _useSharedPluginState, _useSharedPluginState2, _useSharedPluginState3, _useSharedPluginState4;
|
|
46
48
|
const targetRef = getDomRefFromSelection(editorView, dispatchAnalyticsEvent);
|
|
@@ -90,6 +92,8 @@ export const MediaInsertPicker = ({
|
|
|
90
92
|
closeMediaInsertPicker: () => {
|
|
91
93
|
closeMediaInsertPicker();
|
|
92
94
|
focusEditor();
|
|
93
|
-
}
|
|
95
|
+
},
|
|
96
|
+
insertMediaSingle: insertMediaSingle,
|
|
97
|
+
insertExternalMediaSingle: insertExternalMediaSingle
|
|
94
98
|
})));
|
|
95
99
|
};
|
package/dist/esm/plugin.js
CHANGED
|
@@ -36,6 +36,48 @@ export var mediaInsertPlugin = function mediaInsertPlugin(_ref) {
|
|
|
36
36
|
popupsMountPoint = _ref3.popupsMountPoint,
|
|
37
37
|
popupsBoundariesElement = _ref3.popupsBoundariesElement,
|
|
38
38
|
popupsScrollableElement = _ref3.popupsScrollableElement;
|
|
39
|
+
var insertMediaSingle = function insertMediaSingle(_ref4) {
|
|
40
|
+
var _api$media$actions$in;
|
|
41
|
+
var mediaState = _ref4.mediaState,
|
|
42
|
+
inputMethod = _ref4.inputMethod;
|
|
43
|
+
var id = mediaState.id,
|
|
44
|
+
dimensions = mediaState.dimensions,
|
|
45
|
+
contextId = mediaState.contextId,
|
|
46
|
+
_mediaState$scaleFact = mediaState.scaleFactor,
|
|
47
|
+
scaleFactor = _mediaState$scaleFact === void 0 ? 1 : _mediaState$scaleFact,
|
|
48
|
+
fileName = mediaState.fileName,
|
|
49
|
+
collection = mediaState.collection;
|
|
50
|
+
var _ref5 = dimensions || {
|
|
51
|
+
height: undefined,
|
|
52
|
+
width: undefined
|
|
53
|
+
},
|
|
54
|
+
width = _ref5.width,
|
|
55
|
+
height = _ref5.height;
|
|
56
|
+
var scaledWidth = width && Math.round(width / scaleFactor);
|
|
57
|
+
var node = editorView.state.schema.nodes.media.create({
|
|
58
|
+
id: id,
|
|
59
|
+
type: 'file',
|
|
60
|
+
collection: collection,
|
|
61
|
+
contextId: contextId,
|
|
62
|
+
width: scaledWidth,
|
|
63
|
+
height: height && Math.round(height / scaleFactor),
|
|
64
|
+
alt: fileName,
|
|
65
|
+
__fileMimeType: mediaState.fileMimeType
|
|
66
|
+
});
|
|
67
|
+
return (_api$media$actions$in = api === null || api === void 0 ? void 0 : api.media.actions.insertMediaAsMediaSingle(editorView, node, inputMethod)) !== null && _api$media$actions$in !== void 0 ? _api$media$actions$in : false;
|
|
68
|
+
};
|
|
69
|
+
var insertExternalMediaSingle = function insertExternalMediaSingle(_ref6) {
|
|
70
|
+
var _api$media$actions$in2;
|
|
71
|
+
var url = _ref6.url,
|
|
72
|
+
alt = _ref6.alt,
|
|
73
|
+
inputMethod = _ref6.inputMethod;
|
|
74
|
+
var node = editorView.state.schema.nodes.media.create({
|
|
75
|
+
type: 'external',
|
|
76
|
+
url: url,
|
|
77
|
+
alt: alt
|
|
78
|
+
});
|
|
79
|
+
return (_api$media$actions$in2 = api === null || api === void 0 ? void 0 : api.media.actions.insertMediaAsMediaSingle(editorView, node, inputMethod)) !== null && _api$media$actions$in2 !== void 0 ? _api$media$actions$in2 : false;
|
|
80
|
+
};
|
|
39
81
|
return /*#__PURE__*/React.createElement(MediaInsertPicker, {
|
|
40
82
|
api: api,
|
|
41
83
|
editorView: editorView,
|
|
@@ -44,13 +86,15 @@ export var mediaInsertPlugin = function mediaInsertPlugin(_ref) {
|
|
|
44
86
|
popupsBoundariesElement: popupsBoundariesElement,
|
|
45
87
|
popupsScrollableElement: popupsScrollableElement,
|
|
46
88
|
closeMediaInsertPicker: function closeMediaInsertPicker() {
|
|
47
|
-
editorView.dispatch(_closeMediaInsertPicker(editorView.state.tr));
|
|
48
|
-
}
|
|
89
|
+
return editorView.dispatch(_closeMediaInsertPicker(editorView.state.tr));
|
|
90
|
+
},
|
|
91
|
+
insertMediaSingle: insertMediaSingle,
|
|
92
|
+
insertExternalMediaSingle: insertExternalMediaSingle
|
|
49
93
|
});
|
|
50
94
|
},
|
|
51
95
|
pluginsOptions: {
|
|
52
|
-
quickInsert: function quickInsert(
|
|
53
|
-
var formatMessage =
|
|
96
|
+
quickInsert: function quickInsert(_ref7) {
|
|
97
|
+
var formatMessage = _ref7.formatMessage;
|
|
54
98
|
return [{
|
|
55
99
|
id: 'media-insert',
|
|
56
100
|
title: formatMessage(messages.insertMediaFromUrl),
|
|
@@ -5,6 +5,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
5
5
|
import React from 'react';
|
|
6
6
|
import { useIntl } from 'react-intl-next';
|
|
7
7
|
import Button from '@atlaskit/button/new';
|
|
8
|
+
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
8
9
|
import { mediaInsertMessages } from '@atlaskit/editor-common/messages';
|
|
9
10
|
import UploadIcon from '@atlaskit/icon/glyph/upload';
|
|
10
11
|
import { Browser } from '@atlaskit/media-picker';
|
|
@@ -63,16 +64,24 @@ export var LocalMedia = function LocalMedia(_ref) {
|
|
|
63
64
|
var file = _ref2.file,
|
|
64
65
|
preview = _ref2.preview;
|
|
65
66
|
onUploadSuccessAnalytics('local');
|
|
66
|
-
var
|
|
67
|
+
var mediaState = {
|
|
67
68
|
id: file.id,
|
|
68
69
|
collection: (_mediaProvider$upload = mediaProvider.uploadParams) === null || _mediaProvider$upload === void 0 ? void 0 : _mediaProvider$upload.collection,
|
|
69
|
-
|
|
70
|
+
fileMimeType: file.type,
|
|
71
|
+
fileSize: file.size,
|
|
72
|
+
fileName: file.name,
|
|
73
|
+
dimensions: undefined
|
|
70
74
|
};
|
|
71
75
|
if (isImagePreview(preview)) {
|
|
72
|
-
|
|
73
|
-
|
|
76
|
+
mediaState.dimensions = {
|
|
77
|
+
width: preview.dimensions.width,
|
|
78
|
+
height: preview.dimensions.height
|
|
79
|
+
};
|
|
74
80
|
}
|
|
75
|
-
onInsert(
|
|
81
|
+
onInsert({
|
|
82
|
+
mediaState: mediaState,
|
|
83
|
+
inputMethod: INPUT_METHOD.MEDIA_PICKER
|
|
84
|
+
});
|
|
76
85
|
|
|
77
86
|
// Probably not needed but I guess it _could_ fail to close for some reason
|
|
78
87
|
dispatch({
|
|
@@ -65,10 +65,10 @@ var previewStateReducer = function previewStateReducer(state, action) {
|
|
|
65
65
|
};
|
|
66
66
|
export function MediaFromURL(_ref) {
|
|
67
67
|
var mediaProvider = _ref.mediaProvider,
|
|
68
|
-
onInsert = _ref.onInsert,
|
|
69
|
-
onExternalInsert = _ref.onExternalInsert,
|
|
70
68
|
dispatchAnalyticsEvent = _ref.dispatchAnalyticsEvent,
|
|
71
|
-
closeMediaInsertPicker = _ref.closeMediaInsertPicker
|
|
69
|
+
closeMediaInsertPicker = _ref.closeMediaInsertPicker,
|
|
70
|
+
insertMediaSingle = _ref.insertMediaSingle,
|
|
71
|
+
insertExternalMediaSingle = _ref.insertExternalMediaSingle;
|
|
72
72
|
var intl = useIntl();
|
|
73
73
|
var strings = {
|
|
74
74
|
loadPreview: intl.formatMessage(mediaInsertMessages.loadPreview),
|
|
@@ -94,7 +94,7 @@ export function MediaFromURL(_ref) {
|
|
|
94
94
|
onUploadFailureAnalytics = _useAnalyticsEvents.onUploadFailureAnalytics;
|
|
95
95
|
var uploadExternalMedia = React.useCallback( /*#__PURE__*/function () {
|
|
96
96
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(url) {
|
|
97
|
-
var uploadMediaClientConfig, uploadParams, mediaClient, collection, _yield$mediaClient$fi, uploadableFileUpfrontIds, dimensions, message;
|
|
97
|
+
var uploadMediaClientConfig, uploadParams, mediaClient, collection, _yield$mediaClient$fi, uploadableFileUpfrontIds, dimensions, mimeType, message;
|
|
98
98
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
99
99
|
while (1) switch (_context.prev = _context.next) {
|
|
100
100
|
case 0:
|
|
@@ -119,6 +119,7 @@ export function MediaFromURL(_ref) {
|
|
|
119
119
|
_yield$mediaClient$fi = _context.sent;
|
|
120
120
|
uploadableFileUpfrontIds = _yield$mediaClient$fi.uploadableFileUpfrontIds;
|
|
121
121
|
dimensions = _yield$mediaClient$fi.dimensions;
|
|
122
|
+
mimeType = _yield$mediaClient$fi.mimeType;
|
|
122
123
|
onUploadSuccessAnalytics('url');
|
|
123
124
|
dispatch({
|
|
124
125
|
type: 'success',
|
|
@@ -127,13 +128,14 @@ export function MediaFromURL(_ref) {
|
|
|
127
128
|
collection: collection,
|
|
128
129
|
height: dimensions.height,
|
|
129
130
|
width: dimensions.width,
|
|
130
|
-
occurrenceKey: uploadableFileUpfrontIds.occurrenceKey
|
|
131
|
+
occurrenceKey: uploadableFileUpfrontIds.occurrenceKey,
|
|
132
|
+
fileMimeType: mimeType
|
|
131
133
|
}
|
|
132
134
|
});
|
|
133
|
-
_context.next =
|
|
135
|
+
_context.next = 22;
|
|
134
136
|
break;
|
|
135
|
-
case
|
|
136
|
-
_context.prev =
|
|
137
|
+
case 19:
|
|
138
|
+
_context.prev = 19;
|
|
137
139
|
_context.t0 = _context["catch"](8);
|
|
138
140
|
if (typeof _context.t0 === 'string' && _context.t0 === 'Could not download remote file') {
|
|
139
141
|
// TODO: Make sure this gets good unit test coverage with the actual
|
|
@@ -159,11 +161,11 @@ export function MediaFromURL(_ref) {
|
|
|
159
161
|
error: 'Unknown error'
|
|
160
162
|
});
|
|
161
163
|
}
|
|
162
|
-
case
|
|
164
|
+
case 22:
|
|
163
165
|
case "end":
|
|
164
166
|
return _context.stop();
|
|
165
167
|
}
|
|
166
|
-
}, _callee, null, [[8,
|
|
168
|
+
}, _callee, null, [[8, 19]]);
|
|
167
169
|
}));
|
|
168
170
|
return function (_x) {
|
|
169
171
|
return _ref2.apply(this, arguments);
|
|
@@ -191,14 +193,33 @@ export function MediaFromURL(_ref) {
|
|
|
191
193
|
pasteFlag.current = true;
|
|
192
194
|
}
|
|
193
195
|
}, [inputUrl]);
|
|
196
|
+
var onInsert = React.useCallback(function () {
|
|
197
|
+
if (previewState.previewInfo) {
|
|
198
|
+
insertMediaSingle({
|
|
199
|
+
mediaState: previewState.previewInfo,
|
|
200
|
+
inputMethod: INPUT_METHOD.MEDIA_PICKER
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
closeMediaInsertPicker();
|
|
204
|
+
}, [closeMediaInsertPicker, insertMediaSingle, previewState.previewInfo]);
|
|
205
|
+
var onExternalInsert = React.useCallback(function (url) {
|
|
206
|
+
if (previewState.warning) {
|
|
207
|
+
insertExternalMediaSingle({
|
|
208
|
+
url: url,
|
|
209
|
+
alt: url,
|
|
210
|
+
inputMethod: INPUT_METHOD.MEDIA_PICKER
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
closeMediaInsertPicker();
|
|
214
|
+
}, [closeMediaInsertPicker, insertExternalMediaSingle, previewState.warning]);
|
|
194
215
|
var onInsertClick = React.useCallback(function () {
|
|
195
216
|
if (previewState.previewInfo) {
|
|
196
|
-
return onInsert(
|
|
217
|
+
return onInsert();
|
|
197
218
|
}
|
|
198
219
|
if (previewState.warning) {
|
|
199
220
|
return onExternalInsert(inputUrl);
|
|
200
221
|
}
|
|
201
|
-
}, [
|
|
222
|
+
}, [previewState.previewInfo, previewState.warning, onInsert, onExternalInsert, inputUrl]);
|
|
202
223
|
var onInputKeyPress = React.useCallback(function (event) {
|
|
203
224
|
if (event && event.key === 'Esc') {
|
|
204
225
|
if (dispatchAnalyticsEvent) {
|
|
@@ -8,7 +8,9 @@ import { MediaFromURL } from './MediaFromURL';
|
|
|
8
8
|
export var MediaInsertContent = function MediaInsertContent(_ref) {
|
|
9
9
|
var mediaProvider = _ref.mediaProvider,
|
|
10
10
|
dispatchAnalyticsEvent = _ref.dispatchAnalyticsEvent,
|
|
11
|
-
closeMediaInsertPicker = _ref.closeMediaInsertPicker
|
|
11
|
+
closeMediaInsertPicker = _ref.closeMediaInsertPicker,
|
|
12
|
+
insertMediaSingle = _ref.insertMediaSingle,
|
|
13
|
+
insertExternalMediaSingle = _ref.insertExternalMediaSingle;
|
|
12
14
|
var intl = useIntl();
|
|
13
15
|
return /*#__PURE__*/React.createElement(Tabs, {
|
|
14
16
|
id: "media-insert-tab-navigation"
|
|
@@ -16,14 +18,14 @@ export var MediaInsertContent = function MediaInsertContent(_ref) {
|
|
|
16
18
|
paddingBlockEnd: "space.150"
|
|
17
19
|
}, /*#__PURE__*/React.createElement(TabList, null, /*#__PURE__*/React.createElement(Tab, null, intl.formatMessage(mediaInsertMessages.fileTabTitle)), /*#__PURE__*/React.createElement(Tab, null, intl.formatMessage(mediaInsertMessages.linkTabTitle)))), /*#__PURE__*/React.createElement(TabPanel, null, /*#__PURE__*/React.createElement(LocalMedia, {
|
|
18
20
|
mediaProvider: mediaProvider,
|
|
19
|
-
onInsert:
|
|
21
|
+
onInsert: insertMediaSingle,
|
|
20
22
|
onClose: closeMediaInsertPicker,
|
|
21
23
|
dispatchAnalyticsEvent: dispatchAnalyticsEvent
|
|
22
24
|
})), /*#__PURE__*/React.createElement(TabPanel, null, /*#__PURE__*/React.createElement(MediaFromURL, {
|
|
23
25
|
mediaProvider: mediaProvider,
|
|
24
|
-
onExternalInsert: function onExternalInsert() {},
|
|
25
|
-
onInsert: function onInsert() {},
|
|
26
26
|
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
27
|
-
closeMediaInsertPicker: closeMediaInsertPicker
|
|
27
|
+
closeMediaInsertPicker: closeMediaInsertPicker,
|
|
28
|
+
insertMediaSingle: insertMediaSingle,
|
|
29
|
+
insertExternalMediaSingle: insertExternalMediaSingle
|
|
28
30
|
})));
|
|
29
31
|
};
|
|
@@ -41,7 +41,9 @@ export var MediaInsertPicker = function MediaInsertPicker(_ref) {
|
|
|
41
41
|
popupsMountPoint = _ref.popupsMountPoint,
|
|
42
42
|
popupsBoundariesElement = _ref.popupsBoundariesElement,
|
|
43
43
|
popupsScrollableElement = _ref.popupsScrollableElement,
|
|
44
|
-
_closeMediaInsertPicker = _ref.closeMediaInsertPicker
|
|
44
|
+
_closeMediaInsertPicker = _ref.closeMediaInsertPicker,
|
|
45
|
+
insertMediaSingle = _ref.insertMediaSingle,
|
|
46
|
+
insertExternalMediaSingle = _ref.insertExternalMediaSingle;
|
|
45
47
|
var targetRef = getDomRefFromSelection(editorView, dispatchAnalyticsEvent);
|
|
46
48
|
var isOpen = (_useSharedPluginState = useSharedPluginState(api, ['mediaInsert'])) === null || _useSharedPluginState === void 0 || (_useSharedPluginState = _useSharedPluginState.mediaInsertState) === null || _useSharedPluginState === void 0 ? void 0 : _useSharedPluginState.isOpen;
|
|
47
49
|
var mediaProvider = (_useSharedPluginState2 = useSharedPluginState(api, ['media'])) === null || _useSharedPluginState2 === void 0 || (_useSharedPluginState2 = _useSharedPluginState2.mediaState) === null || _useSharedPluginState2 === void 0 ? void 0 : _useSharedPluginState2.mediaProvider;
|
|
@@ -91,6 +93,8 @@ export var MediaInsertPicker = function MediaInsertPicker(_ref) {
|
|
|
91
93
|
closeMediaInsertPicker: function closeMediaInsertPicker() {
|
|
92
94
|
_closeMediaInsertPicker();
|
|
93
95
|
focusEditor();
|
|
94
|
-
}
|
|
96
|
+
},
|
|
97
|
+
insertMediaSingle: insertMediaSingle,
|
|
98
|
+
insertExternalMediaSingle: insertExternalMediaSingle
|
|
95
99
|
})));
|
|
96
100
|
};
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,17 +1,30 @@
|
|
|
1
|
+
import type { InputMethodInsertMedia } from '@atlaskit/editor-common/analytics';
|
|
1
2
|
import type { Providers } from '@atlaskit/editor-common/provider-factory';
|
|
2
3
|
import type { NextEditorPlugin, OptionalPlugin, UiComponentFactoryParams } from '@atlaskit/editor-common/types';
|
|
3
4
|
import { type ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
4
5
|
import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
5
6
|
import type { MediaPlugin } from '@atlaskit/editor-plugin-media';
|
|
7
|
+
import { type MediaState } from '@atlaskit/editor-plugin-media/types';
|
|
6
8
|
export type MediaInsertPluginState = {
|
|
7
9
|
isOpen?: boolean;
|
|
8
10
|
};
|
|
11
|
+
export type InsertMediaSingle = (props: {
|
|
12
|
+
mediaState: MediaState;
|
|
13
|
+
inputMethod: InputMethodInsertMedia;
|
|
14
|
+
}) => boolean;
|
|
9
15
|
export type MediaInsertPlugin = NextEditorPlugin<'mediaInsert', {
|
|
10
16
|
dependencies: [OptionalPlugin<AnalyticsPlugin>, MediaPlugin];
|
|
11
17
|
sharedState: MediaInsertPluginState;
|
|
12
18
|
}>;
|
|
19
|
+
export type InsertExternalMediaSingle = (props: {
|
|
20
|
+
url: string;
|
|
21
|
+
alt: string;
|
|
22
|
+
inputMethod: InputMethodInsertMedia;
|
|
23
|
+
}) => boolean;
|
|
13
24
|
export type MediaInsertPickerProps = Pick<UiComponentFactoryParams, 'editorView' | 'dispatchAnalyticsEvent' | 'popupsMountPoint' | 'popupsBoundariesElement' | 'popupsScrollableElement'> & {
|
|
14
25
|
api?: ExtractInjectionAPI<MediaInsertPlugin>;
|
|
15
26
|
closeMediaInsertPicker: () => void;
|
|
16
27
|
mediaProvider?: Providers['mediaProvider'];
|
|
28
|
+
insertMediaSingle: InsertMediaSingle;
|
|
29
|
+
insertExternalMediaSingle: InsertExternalMediaSingle;
|
|
17
30
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { type DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
|
|
3
3
|
import type { MediaProvider } from '@atlaskit/editor-common/provider-factory';
|
|
4
|
-
import { type
|
|
4
|
+
import { type InsertMediaSingle } from '../types';
|
|
5
5
|
type Props = {
|
|
6
6
|
mediaProvider: MediaProvider;
|
|
7
|
-
onInsert:
|
|
7
|
+
onInsert: InsertMediaSingle;
|
|
8
8
|
onClose: () => void;
|
|
9
9
|
dispatchAnalyticsEvent?: DispatchAnalyticsEvent;
|
|
10
10
|
};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { type DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
|
|
3
3
|
import type { MediaProvider } from '@atlaskit/editor-common/provider-factory';
|
|
4
|
-
import { type
|
|
4
|
+
import { type InsertExternalMediaSingle, type InsertMediaSingle } from '../types';
|
|
5
5
|
type Props = {
|
|
6
6
|
mediaProvider: MediaProvider;
|
|
7
|
-
onInsert: (attrs: OnInsertAttrs) => void;
|
|
8
|
-
onExternalInsert: (url: string) => void;
|
|
9
7
|
dispatchAnalyticsEvent?: DispatchAnalyticsEvent;
|
|
10
8
|
closeMediaInsertPicker: () => void;
|
|
9
|
+
insertMediaSingle: InsertMediaSingle;
|
|
10
|
+
insertExternalMediaSingle: InsertExternalMediaSingle;
|
|
11
11
|
};
|
|
12
|
-
export declare function MediaFromURL({ mediaProvider,
|
|
12
|
+
export declare function MediaFromURL({ mediaProvider, dispatchAnalyticsEvent, closeMediaInsertPicker, insertMediaSingle, insertExternalMediaSingle, }: Props): JSX.Element;
|
|
13
13
|
export {};
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
|
|
3
3
|
import type { MediaProvider } from '@atlaskit/editor-common/provider-factory';
|
|
4
|
-
|
|
4
|
+
import { type InsertExternalMediaSingle, type InsertMediaSingle } from '../types';
|
|
5
|
+
type Props = {
|
|
5
6
|
mediaProvider: MediaProvider;
|
|
6
|
-
dispatchAnalyticsEvent?: DispatchAnalyticsEvent
|
|
7
|
+
dispatchAnalyticsEvent?: DispatchAnalyticsEvent;
|
|
7
8
|
closeMediaInsertPicker: () => void;
|
|
8
|
-
|
|
9
|
+
insertMediaSingle: InsertMediaSingle;
|
|
10
|
+
insertExternalMediaSingle: InsertExternalMediaSingle;
|
|
11
|
+
};
|
|
12
|
+
export declare const MediaInsertContent: ({ mediaProvider, dispatchAnalyticsEvent, closeMediaInsertPicker, insertMediaSingle, insertExternalMediaSingle, }: Props) => JSX.Element;
|
|
13
|
+
export {};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { type MediaInsertPickerProps } from '../types';
|
|
3
|
-
export declare const MediaInsertPicker: ({ api, editorView, dispatchAnalyticsEvent, popupsMountPoint, popupsBoundariesElement, popupsScrollableElement, closeMediaInsertPicker, }: MediaInsertPickerProps) => JSX.Element | null;
|
|
3
|
+
export declare const MediaInsertPicker: ({ api, editorView, dispatchAnalyticsEvent, popupsMountPoint, popupsBoundariesElement, popupsScrollableElement, closeMediaInsertPicker, insertMediaSingle, insertExternalMediaSingle, }: MediaInsertPickerProps) => JSX.Element | null;
|
package/dist/types/ui/types.d.ts
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
|
+
import type { InputMethodInsertMedia } from '@atlaskit/editor-common/analytics';
|
|
1
2
|
import type { Providers } from '@atlaskit/editor-common/provider-factory';
|
|
2
3
|
import type { NextEditorPlugin, OptionalPlugin, UiComponentFactoryParams } from '@atlaskit/editor-common/types';
|
|
3
4
|
import { type ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
4
5
|
import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
5
6
|
import type { MediaPlugin } from '@atlaskit/editor-plugin-media';
|
|
7
|
+
import { type MediaState } from '@atlaskit/editor-plugin-media/types';
|
|
6
8
|
export type MediaInsertPluginState = {
|
|
7
9
|
isOpen?: boolean;
|
|
8
10
|
};
|
|
11
|
+
export type InsertMediaSingle = (props: {
|
|
12
|
+
mediaState: MediaState;
|
|
13
|
+
inputMethod: InputMethodInsertMedia;
|
|
14
|
+
}) => boolean;
|
|
9
15
|
export type MediaInsertPlugin = NextEditorPlugin<'mediaInsert', {
|
|
10
16
|
dependencies: [
|
|
11
17
|
OptionalPlugin<AnalyticsPlugin>,
|
|
@@ -13,8 +19,15 @@ export type MediaInsertPlugin = NextEditorPlugin<'mediaInsert', {
|
|
|
13
19
|
];
|
|
14
20
|
sharedState: MediaInsertPluginState;
|
|
15
21
|
}>;
|
|
22
|
+
export type InsertExternalMediaSingle = (props: {
|
|
23
|
+
url: string;
|
|
24
|
+
alt: string;
|
|
25
|
+
inputMethod: InputMethodInsertMedia;
|
|
26
|
+
}) => boolean;
|
|
16
27
|
export type MediaInsertPickerProps = Pick<UiComponentFactoryParams, 'editorView' | 'dispatchAnalyticsEvent' | 'popupsMountPoint' | 'popupsBoundariesElement' | 'popupsScrollableElement'> & {
|
|
17
28
|
api?: ExtractInjectionAPI<MediaInsertPlugin>;
|
|
18
29
|
closeMediaInsertPicker: () => void;
|
|
19
30
|
mediaProvider?: Providers['mediaProvider'];
|
|
31
|
+
insertMediaSingle: InsertMediaSingle;
|
|
32
|
+
insertExternalMediaSingle: InsertExternalMediaSingle;
|
|
20
33
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { type DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
|
|
3
3
|
import type { MediaProvider } from '@atlaskit/editor-common/provider-factory';
|
|
4
|
-
import { type
|
|
4
|
+
import { type InsertMediaSingle } from '../types';
|
|
5
5
|
type Props = {
|
|
6
6
|
mediaProvider: MediaProvider;
|
|
7
|
-
onInsert:
|
|
7
|
+
onInsert: InsertMediaSingle;
|
|
8
8
|
onClose: () => void;
|
|
9
9
|
dispatchAnalyticsEvent?: DispatchAnalyticsEvent;
|
|
10
10
|
};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { type DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
|
|
3
3
|
import type { MediaProvider } from '@atlaskit/editor-common/provider-factory';
|
|
4
|
-
import { type
|
|
4
|
+
import { type InsertExternalMediaSingle, type InsertMediaSingle } from '../types';
|
|
5
5
|
type Props = {
|
|
6
6
|
mediaProvider: MediaProvider;
|
|
7
|
-
onInsert: (attrs: OnInsertAttrs) => void;
|
|
8
|
-
onExternalInsert: (url: string) => void;
|
|
9
7
|
dispatchAnalyticsEvent?: DispatchAnalyticsEvent;
|
|
10
8
|
closeMediaInsertPicker: () => void;
|
|
9
|
+
insertMediaSingle: InsertMediaSingle;
|
|
10
|
+
insertExternalMediaSingle: InsertExternalMediaSingle;
|
|
11
11
|
};
|
|
12
|
-
export declare function MediaFromURL({ mediaProvider,
|
|
12
|
+
export declare function MediaFromURL({ mediaProvider, dispatchAnalyticsEvent, closeMediaInsertPicker, insertMediaSingle, insertExternalMediaSingle, }: Props): JSX.Element;
|
|
13
13
|
export {};
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
|
|
3
3
|
import type { MediaProvider } from '@atlaskit/editor-common/provider-factory';
|
|
4
|
-
|
|
4
|
+
import { type InsertExternalMediaSingle, type InsertMediaSingle } from '../types';
|
|
5
|
+
type Props = {
|
|
5
6
|
mediaProvider: MediaProvider;
|
|
6
|
-
dispatchAnalyticsEvent?: DispatchAnalyticsEvent
|
|
7
|
+
dispatchAnalyticsEvent?: DispatchAnalyticsEvent;
|
|
7
8
|
closeMediaInsertPicker: () => void;
|
|
8
|
-
|
|
9
|
+
insertMediaSingle: InsertMediaSingle;
|
|
10
|
+
insertExternalMediaSingle: InsertExternalMediaSingle;
|
|
11
|
+
};
|
|
12
|
+
export declare const MediaInsertContent: ({ mediaProvider, dispatchAnalyticsEvent, closeMediaInsertPicker, insertMediaSingle, insertExternalMediaSingle, }: Props) => JSX.Element;
|
|
13
|
+
export {};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { type MediaInsertPickerProps } from '../types';
|
|
3
|
-
export declare const MediaInsertPicker: ({ api, editorView, dispatchAnalyticsEvent, popupsMountPoint, popupsBoundariesElement, popupsScrollableElement, closeMediaInsertPicker, }: MediaInsertPickerProps) => JSX.Element | null;
|
|
3
|
+
export declare const MediaInsertPicker: ({ api, editorView, dispatchAnalyticsEvent, popupsMountPoint, popupsBoundariesElement, popupsScrollableElement, closeMediaInsertPicker, insertMediaSingle, insertExternalMediaSingle, }: MediaInsertPickerProps) => JSX.Element | null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-media-insert",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "Media Insert plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -25,15 +25,15 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@atlaskit/button": "^20.1.0",
|
|
28
|
-
"@atlaskit/editor-common": "^88.
|
|
28
|
+
"@atlaskit/editor-common": "^88.4.0",
|
|
29
29
|
"@atlaskit/editor-plugin-analytics": "^1.8.0",
|
|
30
30
|
"@atlaskit/editor-plugin-media": "^1.29.0",
|
|
31
31
|
"@atlaskit/editor-prosemirror": "5.0.1",
|
|
32
32
|
"@atlaskit/editor-shared-styles": "^2.13.0",
|
|
33
33
|
"@atlaskit/icon": "^22.15.0",
|
|
34
|
-
"@atlaskit/media-card": "^78.
|
|
35
|
-
"@atlaskit/media-client": "^27.
|
|
36
|
-
"@atlaskit/media-client-react": "^2.
|
|
34
|
+
"@atlaskit/media-card": "^78.2.0",
|
|
35
|
+
"@atlaskit/media-client": "^27.6.0",
|
|
36
|
+
"@atlaskit/media-client-react": "^2.2.0",
|
|
37
37
|
"@atlaskit/media-picker": "^66.4.0",
|
|
38
38
|
"@atlaskit/primitives": "^12.0.0",
|
|
39
39
|
"@atlaskit/section-message": "^6.6.0",
|