@atlaskit/editor-plugin-media-insert 1.2.0 → 1.2.2
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 +15 -0
- package/dist/cjs/ui/FromURL.js +108 -85
- package/dist/es2019/ui/FromURL.js +34 -16
- package/dist/esm/ui/FromURL.js +108 -85
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-media-insert
|
|
2
2
|
|
|
3
|
+
## 1.2.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#128111](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/128111)
|
|
8
|
+
[`5d65c0d1d28c8`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/5d65c0d1d28c8) -
|
|
9
|
+
[ux] [ED-24322] Add onPaste UX improvements to url upload
|
|
10
|
+
- Updated dependencies
|
|
11
|
+
|
|
12
|
+
## 1.2.1
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Updated dependencies
|
|
17
|
+
|
|
3
18
|
## 1.2.0
|
|
4
19
|
|
|
5
20
|
### Minor Changes
|
package/dist/cjs/ui/FromURL.js
CHANGED
|
@@ -89,118 +89,141 @@ function MediaFromURL(_ref) {
|
|
|
89
89
|
};
|
|
90
90
|
var _React$useState = _react.default.useState(placeholders[1]),
|
|
91
91
|
_React$useState2 = (0, _slicedToArray2.default)(_React$useState, 2),
|
|
92
|
-
|
|
92
|
+
inputUrl = _React$useState2[0],
|
|
93
93
|
setUrl = _React$useState2[1];
|
|
94
94
|
var _React$useReducer = _react.default.useReducer(previewStateReducer, INITIAL_PREVIEW_STATE),
|
|
95
95
|
_React$useReducer2 = (0, _slicedToArray2.default)(_React$useReducer, 2),
|
|
96
96
|
previewState = _React$useReducer2[0],
|
|
97
97
|
dispatch = _React$useReducer2[1];
|
|
98
|
+
var pasteFlag = _react.default.useRef(false);
|
|
98
99
|
var _useAnalyticsEvents = (0, _useAnalyticsEvents2.useAnalyticsEvents)(dispatchAnalyticsEvent),
|
|
99
100
|
onUploadAnalytics = _useAnalyticsEvents.onUploadAnalytics,
|
|
100
101
|
onUploadSuccessAnalytics = _useAnalyticsEvents.onUploadSuccessAnalytics,
|
|
101
102
|
onUploadFailureAnalytics = _useAnalyticsEvents.onUploadFailureAnalytics;
|
|
102
|
-
var
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
var uploadExternalMedia = _react.default.useCallback( /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
|
|
109
|
-
var _yield$mediaProvider, uploadMediaClientConfig, uploadParams, mediaClient, collection, _yield$mediaClient$fi, uploadableFileUpfrontIds, dimensions, message;
|
|
110
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
|
111
|
-
while (1) switch (_context.prev = _context.next) {
|
|
112
|
-
case 0:
|
|
113
|
-
dispatch({
|
|
114
|
-
type: 'loading'
|
|
115
|
-
});
|
|
116
|
-
_context.next = 3;
|
|
117
|
-
return mediaProvider;
|
|
118
|
-
case 3:
|
|
119
|
-
_yield$mediaProvider = _context.sent;
|
|
120
|
-
uploadMediaClientConfig = _yield$mediaProvider.uploadMediaClientConfig;
|
|
121
|
-
uploadParams = _yield$mediaProvider.uploadParams;
|
|
122
|
-
if (uploadMediaClientConfig) {
|
|
123
|
-
_context.next = 8;
|
|
124
|
-
break;
|
|
125
|
-
}
|
|
126
|
-
return _context.abrupt("return");
|
|
127
|
-
case 8:
|
|
128
|
-
mediaClient = (0, _mediaClientReact.getMediaClient)(uploadMediaClientConfig);
|
|
129
|
-
collection = uploadParams === null || uploadParams === void 0 ? void 0 : uploadParams.collection;
|
|
130
|
-
onUploadAnalytics();
|
|
131
|
-
_context.prev = 11;
|
|
132
|
-
_context.next = 14;
|
|
133
|
-
return mediaClient.file.uploadExternal(url, collection);
|
|
134
|
-
case 14:
|
|
135
|
-
_yield$mediaClient$fi = _context.sent;
|
|
136
|
-
uploadableFileUpfrontIds = _yield$mediaClient$fi.uploadableFileUpfrontIds;
|
|
137
|
-
dimensions = _yield$mediaClient$fi.dimensions;
|
|
138
|
-
onUploadSuccessAnalytics();
|
|
139
|
-
dispatch({
|
|
140
|
-
type: 'success',
|
|
141
|
-
payload: {
|
|
142
|
-
id: uploadableFileUpfrontIds.id,
|
|
143
|
-
collection: collection,
|
|
144
|
-
height: dimensions.height,
|
|
145
|
-
width: dimensions.width,
|
|
146
|
-
occurrenceKey: uploadableFileUpfrontIds.occurrenceKey
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
_context.next = 24;
|
|
150
|
-
break;
|
|
151
|
-
case 21:
|
|
152
|
-
_context.prev = 21;
|
|
153
|
-
_context.t0 = _context["catch"](11);
|
|
154
|
-
if (typeof _context.t0 === 'string' && _context.t0 === 'Could not download remote file') {
|
|
155
|
-
// TODO: Make sure this gets good unit test coverage with the actual
|
|
156
|
-
// media plugin. This hard coded error message could be changed at any
|
|
157
|
-
// point and we need a unit test to break to stop people changing it.
|
|
158
|
-
onUploadFailureAnalytics(_context.t0);
|
|
159
|
-
dispatch({
|
|
160
|
-
type: 'warning',
|
|
161
|
-
warning: _context.t0,
|
|
162
|
-
url: url
|
|
163
|
-
});
|
|
164
|
-
} else if (_context.t0 instanceof Error) {
|
|
165
|
-
message = 'Image preview fetch failed';
|
|
166
|
-
onUploadFailureAnalytics(message);
|
|
103
|
+
var uploadExternalMedia = _react.default.useCallback( /*#__PURE__*/function () {
|
|
104
|
+
var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(url) {
|
|
105
|
+
var _yield$mediaProvider, uploadMediaClientConfig, uploadParams, mediaClient, collection, _yield$mediaClient$fi, uploadableFileUpfrontIds, dimensions, message;
|
|
106
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
107
|
+
while (1) switch (_context.prev = _context.next) {
|
|
108
|
+
case 0:
|
|
167
109
|
dispatch({
|
|
168
|
-
type: '
|
|
169
|
-
error: message
|
|
110
|
+
type: 'loading'
|
|
170
111
|
});
|
|
171
|
-
|
|
172
|
-
|
|
112
|
+
_context.next = 3;
|
|
113
|
+
return mediaProvider;
|
|
114
|
+
case 3:
|
|
115
|
+
_yield$mediaProvider = _context.sent;
|
|
116
|
+
uploadMediaClientConfig = _yield$mediaProvider.uploadMediaClientConfig;
|
|
117
|
+
uploadParams = _yield$mediaProvider.uploadParams;
|
|
118
|
+
if (uploadMediaClientConfig) {
|
|
119
|
+
_context.next = 8;
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
return _context.abrupt("return");
|
|
123
|
+
case 8:
|
|
124
|
+
mediaClient = (0, _mediaClientReact.getMediaClient)(uploadMediaClientConfig);
|
|
125
|
+
collection = uploadParams === null || uploadParams === void 0 ? void 0 : uploadParams.collection;
|
|
126
|
+
onUploadAnalytics();
|
|
127
|
+
_context.prev = 11;
|
|
128
|
+
_context.next = 14;
|
|
129
|
+
return mediaClient.file.uploadExternal(url, collection);
|
|
130
|
+
case 14:
|
|
131
|
+
_yield$mediaClient$fi = _context.sent;
|
|
132
|
+
uploadableFileUpfrontIds = _yield$mediaClient$fi.uploadableFileUpfrontIds;
|
|
133
|
+
dimensions = _yield$mediaClient$fi.dimensions;
|
|
134
|
+
onUploadSuccessAnalytics();
|
|
173
135
|
dispatch({
|
|
174
|
-
type: '
|
|
175
|
-
|
|
136
|
+
type: 'success',
|
|
137
|
+
payload: {
|
|
138
|
+
id: uploadableFileUpfrontIds.id,
|
|
139
|
+
collection: collection,
|
|
140
|
+
height: dimensions.height,
|
|
141
|
+
width: dimensions.width,
|
|
142
|
+
occurrenceKey: uploadableFileUpfrontIds.occurrenceKey
|
|
143
|
+
}
|
|
176
144
|
});
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
145
|
+
_context.next = 24;
|
|
146
|
+
break;
|
|
147
|
+
case 21:
|
|
148
|
+
_context.prev = 21;
|
|
149
|
+
_context.t0 = _context["catch"](11);
|
|
150
|
+
if (typeof _context.t0 === 'string' && _context.t0 === 'Could not download remote file') {
|
|
151
|
+
// TODO: Make sure this gets good unit test coverage with the actual
|
|
152
|
+
// media plugin. This hard coded error message could be changed at any
|
|
153
|
+
// point and we need a unit test to break to stop people changing it.
|
|
154
|
+
onUploadFailureAnalytics(_context.t0);
|
|
155
|
+
dispatch({
|
|
156
|
+
type: 'warning',
|
|
157
|
+
warning: _context.t0,
|
|
158
|
+
url: inputUrl
|
|
159
|
+
});
|
|
160
|
+
} else if (_context.t0 instanceof Error) {
|
|
161
|
+
message = 'Image preview fetch failed';
|
|
162
|
+
onUploadFailureAnalytics(message);
|
|
163
|
+
dispatch({
|
|
164
|
+
type: 'error',
|
|
165
|
+
error: message
|
|
166
|
+
});
|
|
167
|
+
} else {
|
|
168
|
+
onUploadFailureAnalytics('Unknown error');
|
|
169
|
+
dispatch({
|
|
170
|
+
type: 'error',
|
|
171
|
+
error: 'Unknown error'
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
case 24:
|
|
175
|
+
case "end":
|
|
176
|
+
return _context.stop();
|
|
177
|
+
}
|
|
178
|
+
}, _callee, null, [[11, 21]]);
|
|
179
|
+
}));
|
|
180
|
+
return function (_x) {
|
|
181
|
+
return _ref2.apply(this, arguments);
|
|
182
|
+
};
|
|
183
|
+
}(), [mediaProvider, onUploadAnalytics, onUploadFailureAnalytics, onUploadSuccessAnalytics, inputUrl]);
|
|
184
|
+
var onURLChange = _react.default.useCallback(function (e) {
|
|
185
|
+
var url = e.target.value;
|
|
186
|
+
setUrl(url);
|
|
187
|
+
dispatch({
|
|
188
|
+
type: 'reset'
|
|
189
|
+
});
|
|
190
|
+
if (pasteFlag.current === true) {
|
|
191
|
+
pasteFlag.current = false;
|
|
192
|
+
uploadExternalMedia(url);
|
|
193
|
+
}
|
|
194
|
+
}, [uploadExternalMedia]);
|
|
195
|
+
var onPaste = _react.default.useCallback(function (e) {
|
|
196
|
+
// Note: this is a little weird, but the paste event will always be
|
|
197
|
+
// fired before the change event when pasting. We don't really want to
|
|
198
|
+
// duplicate logic by handling pastes separately to changes, so we're
|
|
199
|
+
// just noting paste occured to then be handled in the onURLChange fn
|
|
200
|
+
// above. The one exception to this is where paste inputs exactly what was
|
|
201
|
+
// already in the input, in which case we want to ignore it.
|
|
202
|
+
if (e.clipboardData.getData('text') !== inputUrl) {
|
|
203
|
+
pasteFlag.current = true;
|
|
204
|
+
}
|
|
205
|
+
}, [inputUrl]);
|
|
184
206
|
var onInsertClick = _react.default.useCallback(function () {
|
|
185
207
|
if (previewState.previewInfo) {
|
|
186
208
|
return onInsert(previewState.previewInfo);
|
|
187
209
|
}
|
|
188
210
|
if (previewState.warning) {
|
|
189
|
-
return onExternalInsert(
|
|
211
|
+
return onExternalInsert(inputUrl);
|
|
190
212
|
}
|
|
191
|
-
}, [onExternalInsert, onInsert, previewState.previewInfo, previewState.warning,
|
|
213
|
+
}, [onExternalInsert, onInsert, previewState.previewInfo, previewState.warning, inputUrl]);
|
|
192
214
|
return /*#__PURE__*/_react.default.createElement("form", {
|
|
193
215
|
onSubmit: function onSubmit(e) {
|
|
194
216
|
e.preventDefault();
|
|
195
|
-
uploadExternalMedia();
|
|
217
|
+
uploadExternalMedia(inputUrl);
|
|
196
218
|
}
|
|
197
219
|
}, /*#__PURE__*/_react.default.createElement(_primitives.Stack, {
|
|
198
220
|
space: "space.150"
|
|
199
221
|
}, /*#__PURE__*/_react.default.createElement(_textfield.default, {
|
|
200
222
|
autoFocus: true,
|
|
201
|
-
value:
|
|
223
|
+
value: inputUrl,
|
|
202
224
|
placeholder: strings.pasteLinkToUpload,
|
|
203
|
-
onChange: onURLChange
|
|
225
|
+
onChange: onURLChange,
|
|
226
|
+
onPaste: onPaste
|
|
204
227
|
}), previewState.previewInfo && /*#__PURE__*/_react.default.createElement(_primitives.Inline, {
|
|
205
228
|
alignInline: "center",
|
|
206
229
|
alignBlock: "center",
|
|
@@ -220,7 +243,7 @@ function MediaFromURL(_ref) {
|
|
|
220
243
|
}, /*#__PURE__*/_react.default.createElement(_new.default, {
|
|
221
244
|
type: "submit",
|
|
222
245
|
isLoading: previewState.isLoading,
|
|
223
|
-
isDisabled: !
|
|
246
|
+
isDisabled: !inputUrl,
|
|
224
247
|
iconBefore: _filePreview.default
|
|
225
248
|
}, strings.loadPreview)), /*#__PURE__*/_react.default.createElement(_primitives.Box, {
|
|
226
249
|
xcss: ButtonGroupStyles
|
|
@@ -79,20 +79,15 @@ export function MediaFromURL({
|
|
|
79
79
|
errorMessage: intl.formatMessage(mediaInsertMessages.errorMessage),
|
|
80
80
|
warning: intl.formatMessage(mediaInsertMessages.warning)
|
|
81
81
|
};
|
|
82
|
-
const [
|
|
82
|
+
const [inputUrl, setUrl] = React.useState(placeholders[1]);
|
|
83
83
|
const [previewState, dispatch] = React.useReducer(previewStateReducer, INITIAL_PREVIEW_STATE);
|
|
84
|
+
const pasteFlag = React.useRef(false);
|
|
84
85
|
const {
|
|
85
86
|
onUploadAnalytics,
|
|
86
87
|
onUploadSuccessAnalytics,
|
|
87
88
|
onUploadFailureAnalytics
|
|
88
89
|
} = useAnalyticsEvents(dispatchAnalyticsEvent);
|
|
89
|
-
const
|
|
90
|
-
setUrl(e.target.value);
|
|
91
|
-
dispatch({
|
|
92
|
-
type: 'reset'
|
|
93
|
-
});
|
|
94
|
-
}, []);
|
|
95
|
-
const uploadExternalMedia = React.useCallback(async () => {
|
|
90
|
+
const uploadExternalMedia = React.useCallback(async url => {
|
|
96
91
|
dispatch({
|
|
97
92
|
type: 'loading'
|
|
98
93
|
});
|
|
@@ -131,7 +126,7 @@ export function MediaFromURL({
|
|
|
131
126
|
dispatch({
|
|
132
127
|
type: 'warning',
|
|
133
128
|
warning: e,
|
|
134
|
-
url
|
|
129
|
+
url: inputUrl
|
|
135
130
|
});
|
|
136
131
|
} else if (e instanceof Error) {
|
|
137
132
|
const message = 'Image preview fetch failed';
|
|
@@ -148,27 +143,50 @@ export function MediaFromURL({
|
|
|
148
143
|
});
|
|
149
144
|
}
|
|
150
145
|
}
|
|
151
|
-
}, [mediaProvider, onUploadAnalytics, onUploadFailureAnalytics, onUploadSuccessAnalytics,
|
|
146
|
+
}, [mediaProvider, onUploadAnalytics, onUploadFailureAnalytics, onUploadSuccessAnalytics, inputUrl]);
|
|
147
|
+
const onURLChange = React.useCallback(e => {
|
|
148
|
+
const url = e.target.value;
|
|
149
|
+
setUrl(url);
|
|
150
|
+
dispatch({
|
|
151
|
+
type: 'reset'
|
|
152
|
+
});
|
|
153
|
+
if (pasteFlag.current === true) {
|
|
154
|
+
pasteFlag.current = false;
|
|
155
|
+
uploadExternalMedia(url);
|
|
156
|
+
}
|
|
157
|
+
}, [uploadExternalMedia]);
|
|
158
|
+
const onPaste = React.useCallback(e => {
|
|
159
|
+
// Note: this is a little weird, but the paste event will always be
|
|
160
|
+
// fired before the change event when pasting. We don't really want to
|
|
161
|
+
// duplicate logic by handling pastes separately to changes, so we're
|
|
162
|
+
// just noting paste occured to then be handled in the onURLChange fn
|
|
163
|
+
// above. The one exception to this is where paste inputs exactly what was
|
|
164
|
+
// already in the input, in which case we want to ignore it.
|
|
165
|
+
if (e.clipboardData.getData('text') !== inputUrl) {
|
|
166
|
+
pasteFlag.current = true;
|
|
167
|
+
}
|
|
168
|
+
}, [inputUrl]);
|
|
152
169
|
const onInsertClick = React.useCallback(() => {
|
|
153
170
|
if (previewState.previewInfo) {
|
|
154
171
|
return onInsert(previewState.previewInfo);
|
|
155
172
|
}
|
|
156
173
|
if (previewState.warning) {
|
|
157
|
-
return onExternalInsert(
|
|
174
|
+
return onExternalInsert(inputUrl);
|
|
158
175
|
}
|
|
159
|
-
}, [onExternalInsert, onInsert, previewState.previewInfo, previewState.warning,
|
|
176
|
+
}, [onExternalInsert, onInsert, previewState.previewInfo, previewState.warning, inputUrl]);
|
|
160
177
|
return /*#__PURE__*/React.createElement("form", {
|
|
161
178
|
onSubmit: e => {
|
|
162
179
|
e.preventDefault();
|
|
163
|
-
uploadExternalMedia();
|
|
180
|
+
uploadExternalMedia(inputUrl);
|
|
164
181
|
}
|
|
165
182
|
}, /*#__PURE__*/React.createElement(Stack, {
|
|
166
183
|
space: "space.150"
|
|
167
184
|
}, /*#__PURE__*/React.createElement(TextField, {
|
|
168
185
|
autoFocus: true,
|
|
169
|
-
value:
|
|
186
|
+
value: inputUrl,
|
|
170
187
|
placeholder: strings.pasteLinkToUpload,
|
|
171
|
-
onChange: onURLChange
|
|
188
|
+
onChange: onURLChange,
|
|
189
|
+
onPaste: onPaste
|
|
172
190
|
}), previewState.previewInfo && /*#__PURE__*/React.createElement(Inline, {
|
|
173
191
|
alignInline: "center",
|
|
174
192
|
alignBlock: "center",
|
|
@@ -188,7 +206,7 @@ export function MediaFromURL({
|
|
|
188
206
|
}, /*#__PURE__*/React.createElement(Button, {
|
|
189
207
|
type: "submit",
|
|
190
208
|
isLoading: previewState.isLoading,
|
|
191
|
-
isDisabled: !
|
|
209
|
+
isDisabled: !inputUrl,
|
|
192
210
|
iconBefore: EditorFilePreviewIcon
|
|
193
211
|
}, strings.loadPreview)), /*#__PURE__*/React.createElement(Box, {
|
|
194
212
|
xcss: ButtonGroupStyles
|
package/dist/esm/ui/FromURL.js
CHANGED
|
@@ -82,118 +82,141 @@ export function MediaFromURL(_ref) {
|
|
|
82
82
|
};
|
|
83
83
|
var _React$useState = React.useState(placeholders[1]),
|
|
84
84
|
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
85
|
-
|
|
85
|
+
inputUrl = _React$useState2[0],
|
|
86
86
|
setUrl = _React$useState2[1];
|
|
87
87
|
var _React$useReducer = React.useReducer(previewStateReducer, INITIAL_PREVIEW_STATE),
|
|
88
88
|
_React$useReducer2 = _slicedToArray(_React$useReducer, 2),
|
|
89
89
|
previewState = _React$useReducer2[0],
|
|
90
90
|
dispatch = _React$useReducer2[1];
|
|
91
|
+
var pasteFlag = React.useRef(false);
|
|
91
92
|
var _useAnalyticsEvents = useAnalyticsEvents(dispatchAnalyticsEvent),
|
|
92
93
|
onUploadAnalytics = _useAnalyticsEvents.onUploadAnalytics,
|
|
93
94
|
onUploadSuccessAnalytics = _useAnalyticsEvents.onUploadSuccessAnalytics,
|
|
94
95
|
onUploadFailureAnalytics = _useAnalyticsEvents.onUploadFailureAnalytics;
|
|
95
|
-
var
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
var uploadExternalMedia = React.useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
102
|
-
var _yield$mediaProvider, uploadMediaClientConfig, uploadParams, mediaClient, collection, _yield$mediaClient$fi, uploadableFileUpfrontIds, dimensions, message;
|
|
103
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
104
|
-
while (1) switch (_context.prev = _context.next) {
|
|
105
|
-
case 0:
|
|
106
|
-
dispatch({
|
|
107
|
-
type: 'loading'
|
|
108
|
-
});
|
|
109
|
-
_context.next = 3;
|
|
110
|
-
return mediaProvider;
|
|
111
|
-
case 3:
|
|
112
|
-
_yield$mediaProvider = _context.sent;
|
|
113
|
-
uploadMediaClientConfig = _yield$mediaProvider.uploadMediaClientConfig;
|
|
114
|
-
uploadParams = _yield$mediaProvider.uploadParams;
|
|
115
|
-
if (uploadMediaClientConfig) {
|
|
116
|
-
_context.next = 8;
|
|
117
|
-
break;
|
|
118
|
-
}
|
|
119
|
-
return _context.abrupt("return");
|
|
120
|
-
case 8:
|
|
121
|
-
mediaClient = getMediaClient(uploadMediaClientConfig);
|
|
122
|
-
collection = uploadParams === null || uploadParams === void 0 ? void 0 : uploadParams.collection;
|
|
123
|
-
onUploadAnalytics();
|
|
124
|
-
_context.prev = 11;
|
|
125
|
-
_context.next = 14;
|
|
126
|
-
return mediaClient.file.uploadExternal(url, collection);
|
|
127
|
-
case 14:
|
|
128
|
-
_yield$mediaClient$fi = _context.sent;
|
|
129
|
-
uploadableFileUpfrontIds = _yield$mediaClient$fi.uploadableFileUpfrontIds;
|
|
130
|
-
dimensions = _yield$mediaClient$fi.dimensions;
|
|
131
|
-
onUploadSuccessAnalytics();
|
|
132
|
-
dispatch({
|
|
133
|
-
type: 'success',
|
|
134
|
-
payload: {
|
|
135
|
-
id: uploadableFileUpfrontIds.id,
|
|
136
|
-
collection: collection,
|
|
137
|
-
height: dimensions.height,
|
|
138
|
-
width: dimensions.width,
|
|
139
|
-
occurrenceKey: uploadableFileUpfrontIds.occurrenceKey
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
_context.next = 24;
|
|
143
|
-
break;
|
|
144
|
-
case 21:
|
|
145
|
-
_context.prev = 21;
|
|
146
|
-
_context.t0 = _context["catch"](11);
|
|
147
|
-
if (typeof _context.t0 === 'string' && _context.t0 === 'Could not download remote file') {
|
|
148
|
-
// TODO: Make sure this gets good unit test coverage with the actual
|
|
149
|
-
// media plugin. This hard coded error message could be changed at any
|
|
150
|
-
// point and we need a unit test to break to stop people changing it.
|
|
151
|
-
onUploadFailureAnalytics(_context.t0);
|
|
152
|
-
dispatch({
|
|
153
|
-
type: 'warning',
|
|
154
|
-
warning: _context.t0,
|
|
155
|
-
url: url
|
|
156
|
-
});
|
|
157
|
-
} else if (_context.t0 instanceof Error) {
|
|
158
|
-
message = 'Image preview fetch failed';
|
|
159
|
-
onUploadFailureAnalytics(message);
|
|
96
|
+
var uploadExternalMedia = React.useCallback( /*#__PURE__*/function () {
|
|
97
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(url) {
|
|
98
|
+
var _yield$mediaProvider, uploadMediaClientConfig, uploadParams, mediaClient, collection, _yield$mediaClient$fi, uploadableFileUpfrontIds, dimensions, message;
|
|
99
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
100
|
+
while (1) switch (_context.prev = _context.next) {
|
|
101
|
+
case 0:
|
|
160
102
|
dispatch({
|
|
161
|
-
type: '
|
|
162
|
-
error: message
|
|
103
|
+
type: 'loading'
|
|
163
104
|
});
|
|
164
|
-
|
|
165
|
-
|
|
105
|
+
_context.next = 3;
|
|
106
|
+
return mediaProvider;
|
|
107
|
+
case 3:
|
|
108
|
+
_yield$mediaProvider = _context.sent;
|
|
109
|
+
uploadMediaClientConfig = _yield$mediaProvider.uploadMediaClientConfig;
|
|
110
|
+
uploadParams = _yield$mediaProvider.uploadParams;
|
|
111
|
+
if (uploadMediaClientConfig) {
|
|
112
|
+
_context.next = 8;
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
return _context.abrupt("return");
|
|
116
|
+
case 8:
|
|
117
|
+
mediaClient = getMediaClient(uploadMediaClientConfig);
|
|
118
|
+
collection = uploadParams === null || uploadParams === void 0 ? void 0 : uploadParams.collection;
|
|
119
|
+
onUploadAnalytics();
|
|
120
|
+
_context.prev = 11;
|
|
121
|
+
_context.next = 14;
|
|
122
|
+
return mediaClient.file.uploadExternal(url, collection);
|
|
123
|
+
case 14:
|
|
124
|
+
_yield$mediaClient$fi = _context.sent;
|
|
125
|
+
uploadableFileUpfrontIds = _yield$mediaClient$fi.uploadableFileUpfrontIds;
|
|
126
|
+
dimensions = _yield$mediaClient$fi.dimensions;
|
|
127
|
+
onUploadSuccessAnalytics();
|
|
166
128
|
dispatch({
|
|
167
|
-
type: '
|
|
168
|
-
|
|
129
|
+
type: 'success',
|
|
130
|
+
payload: {
|
|
131
|
+
id: uploadableFileUpfrontIds.id,
|
|
132
|
+
collection: collection,
|
|
133
|
+
height: dimensions.height,
|
|
134
|
+
width: dimensions.width,
|
|
135
|
+
occurrenceKey: uploadableFileUpfrontIds.occurrenceKey
|
|
136
|
+
}
|
|
169
137
|
});
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
138
|
+
_context.next = 24;
|
|
139
|
+
break;
|
|
140
|
+
case 21:
|
|
141
|
+
_context.prev = 21;
|
|
142
|
+
_context.t0 = _context["catch"](11);
|
|
143
|
+
if (typeof _context.t0 === 'string' && _context.t0 === 'Could not download remote file') {
|
|
144
|
+
// TODO: Make sure this gets good unit test coverage with the actual
|
|
145
|
+
// media plugin. This hard coded error message could be changed at any
|
|
146
|
+
// point and we need a unit test to break to stop people changing it.
|
|
147
|
+
onUploadFailureAnalytics(_context.t0);
|
|
148
|
+
dispatch({
|
|
149
|
+
type: 'warning',
|
|
150
|
+
warning: _context.t0,
|
|
151
|
+
url: inputUrl
|
|
152
|
+
});
|
|
153
|
+
} else if (_context.t0 instanceof Error) {
|
|
154
|
+
message = 'Image preview fetch failed';
|
|
155
|
+
onUploadFailureAnalytics(message);
|
|
156
|
+
dispatch({
|
|
157
|
+
type: 'error',
|
|
158
|
+
error: message
|
|
159
|
+
});
|
|
160
|
+
} else {
|
|
161
|
+
onUploadFailureAnalytics('Unknown error');
|
|
162
|
+
dispatch({
|
|
163
|
+
type: 'error',
|
|
164
|
+
error: 'Unknown error'
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
case 24:
|
|
168
|
+
case "end":
|
|
169
|
+
return _context.stop();
|
|
170
|
+
}
|
|
171
|
+
}, _callee, null, [[11, 21]]);
|
|
172
|
+
}));
|
|
173
|
+
return function (_x) {
|
|
174
|
+
return _ref2.apply(this, arguments);
|
|
175
|
+
};
|
|
176
|
+
}(), [mediaProvider, onUploadAnalytics, onUploadFailureAnalytics, onUploadSuccessAnalytics, inputUrl]);
|
|
177
|
+
var onURLChange = React.useCallback(function (e) {
|
|
178
|
+
var url = e.target.value;
|
|
179
|
+
setUrl(url);
|
|
180
|
+
dispatch({
|
|
181
|
+
type: 'reset'
|
|
182
|
+
});
|
|
183
|
+
if (pasteFlag.current === true) {
|
|
184
|
+
pasteFlag.current = false;
|
|
185
|
+
uploadExternalMedia(url);
|
|
186
|
+
}
|
|
187
|
+
}, [uploadExternalMedia]);
|
|
188
|
+
var onPaste = React.useCallback(function (e) {
|
|
189
|
+
// Note: this is a little weird, but the paste event will always be
|
|
190
|
+
// fired before the change event when pasting. We don't really want to
|
|
191
|
+
// duplicate logic by handling pastes separately to changes, so we're
|
|
192
|
+
// just noting paste occured to then be handled in the onURLChange fn
|
|
193
|
+
// above. The one exception to this is where paste inputs exactly what was
|
|
194
|
+
// already in the input, in which case we want to ignore it.
|
|
195
|
+
if (e.clipboardData.getData('text') !== inputUrl) {
|
|
196
|
+
pasteFlag.current = true;
|
|
197
|
+
}
|
|
198
|
+
}, [inputUrl]);
|
|
177
199
|
var onInsertClick = React.useCallback(function () {
|
|
178
200
|
if (previewState.previewInfo) {
|
|
179
201
|
return onInsert(previewState.previewInfo);
|
|
180
202
|
}
|
|
181
203
|
if (previewState.warning) {
|
|
182
|
-
return onExternalInsert(
|
|
204
|
+
return onExternalInsert(inputUrl);
|
|
183
205
|
}
|
|
184
|
-
}, [onExternalInsert, onInsert, previewState.previewInfo, previewState.warning,
|
|
206
|
+
}, [onExternalInsert, onInsert, previewState.previewInfo, previewState.warning, inputUrl]);
|
|
185
207
|
return /*#__PURE__*/React.createElement("form", {
|
|
186
208
|
onSubmit: function onSubmit(e) {
|
|
187
209
|
e.preventDefault();
|
|
188
|
-
uploadExternalMedia();
|
|
210
|
+
uploadExternalMedia(inputUrl);
|
|
189
211
|
}
|
|
190
212
|
}, /*#__PURE__*/React.createElement(Stack, {
|
|
191
213
|
space: "space.150"
|
|
192
214
|
}, /*#__PURE__*/React.createElement(TextField, {
|
|
193
215
|
autoFocus: true,
|
|
194
|
-
value:
|
|
216
|
+
value: inputUrl,
|
|
195
217
|
placeholder: strings.pasteLinkToUpload,
|
|
196
|
-
onChange: onURLChange
|
|
218
|
+
onChange: onURLChange,
|
|
219
|
+
onPaste: onPaste
|
|
197
220
|
}), previewState.previewInfo && /*#__PURE__*/React.createElement(Inline, {
|
|
198
221
|
alignInline: "center",
|
|
199
222
|
alignBlock: "center",
|
|
@@ -213,7 +236,7 @@ export function MediaFromURL(_ref) {
|
|
|
213
236
|
}, /*#__PURE__*/React.createElement(Button, {
|
|
214
237
|
type: "submit",
|
|
215
238
|
isLoading: previewState.isLoading,
|
|
216
|
-
isDisabled: !
|
|
239
|
+
isDisabled: !inputUrl,
|
|
217
240
|
iconBefore: EditorFilePreviewIcon
|
|
218
241
|
}, strings.loadPreview)), /*#__PURE__*/React.createElement(Box, {
|
|
219
242
|
xcss: ButtonGroupStyles
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-media-insert",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"description": "Media Insert plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -24,21 +24,21 @@
|
|
|
24
24
|
".": "./src/index.ts"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@atlaskit/button": "^19.
|
|
28
|
-
"@atlaskit/editor-common": "^87.
|
|
29
|
-
"@atlaskit/icon": "^22.
|
|
27
|
+
"@atlaskit/button": "^19.2.0",
|
|
28
|
+
"@atlaskit/editor-common": "^87.8.0",
|
|
29
|
+
"@atlaskit/icon": "^22.12.0",
|
|
30
30
|
"@atlaskit/media-card": "^78.0.0",
|
|
31
31
|
"@atlaskit/media-client": "^27.3.0",
|
|
32
32
|
"@atlaskit/media-client-react": "^2.0.0",
|
|
33
|
-
"@atlaskit/primitives": "^
|
|
34
|
-
"@atlaskit/section-message": "^6.
|
|
35
|
-
"@atlaskit/textfield": "^6.
|
|
33
|
+
"@atlaskit/primitives": "^12.0.0",
|
|
34
|
+
"@atlaskit/section-message": "^6.6.0",
|
|
35
|
+
"@atlaskit/textfield": "^6.5.0",
|
|
36
36
|
"@babel/runtime": "^7.0.0",
|
|
37
37
|
"react": "^16.8.0",
|
|
38
38
|
"react-intl-next": "npm:react-intl@^5.18.1"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"@atlaskit/tokens": "^1.
|
|
41
|
+
"@atlaskit/tokens": "^1.58.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"typescript": "~5.4.2"
|