@atlaskit/editor-plugin-media-insert 2.1.2 → 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.
Files changed (38) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/cjs/plugin.js +48 -4
  3. package/dist/cjs/ui/LocalMedia.js +143 -0
  4. package/dist/cjs/ui/{FromURL.js → MediaFromURL.js} +50 -27
  5. package/dist/cjs/ui/MediaInsertContent.js +14 -6
  6. package/dist/cjs/ui/MediaInsertPicker.js +6 -2
  7. package/dist/cjs/ui/useAnalyticsEvents.js +26 -10
  8. package/dist/es2019/plugin.js +49 -3
  9. package/dist/es2019/ui/LocalMedia.js +137 -0
  10. package/dist/es2019/ui/{FromURL.js → MediaFromURL.js} +39 -16
  11. package/dist/es2019/ui/MediaInsertContent.js +14 -6
  12. package/dist/es2019/ui/MediaInsertPicker.js +6 -2
  13. package/dist/es2019/ui/useAnalyticsEvents.js +26 -10
  14. package/dist/esm/plugin.js +48 -4
  15. package/dist/esm/ui/LocalMedia.js +136 -0
  16. package/dist/esm/ui/{FromURL.js → MediaFromURL.js} +50 -27
  17. package/dist/esm/ui/MediaInsertContent.js +14 -6
  18. package/dist/esm/ui/MediaInsertPicker.js +6 -2
  19. package/dist/esm/ui/useAnalyticsEvents.js +26 -10
  20. package/dist/types/types.d.ts +13 -0
  21. package/dist/types/ui/LocalMedia.d.ts +12 -0
  22. package/dist/types/ui/MediaCard.d.ts +1 -1
  23. package/dist/types/ui/MediaFromURL.d.ts +13 -0
  24. package/dist/types/ui/MediaInsertContent.d.ts +8 -3
  25. package/dist/types/ui/MediaInsertPicker.d.ts +1 -1
  26. package/dist/types/ui/types.d.ts +3 -2
  27. package/dist/types/ui/useAnalyticsEvents.d.ts +6 -3
  28. package/dist/types-ts4.5/types.d.ts +13 -0
  29. package/dist/types-ts4.5/ui/LocalMedia.d.ts +12 -0
  30. package/dist/types-ts4.5/ui/MediaCard.d.ts +1 -1
  31. package/dist/types-ts4.5/ui/MediaFromURL.d.ts +13 -0
  32. package/dist/types-ts4.5/ui/MediaInsertContent.d.ts +8 -3
  33. package/dist/types-ts4.5/ui/MediaInsertPicker.d.ts +1 -1
  34. package/dist/types-ts4.5/ui/types.d.ts +3 -2
  35. package/dist/types-ts4.5/ui/useAnalyticsEvents.d.ts +6 -3
  36. package/package.json +6 -5
  37. package/dist/types/ui/FromURL.d.ts +0 -13
  38. package/dist/types-ts4.5/ui/FromURL.d.ts +0 -13
@@ -65,18 +65,18 @@ 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),
75
75
  insert: intl.formatMessage(mediaInsertMessages.insert),
76
76
  pasteLinkToUpload: intl.formatMessage(mediaInsertMessages.pasteLinkToUpload),
77
77
  cancel: intl.formatMessage(mediaInsertMessages.cancel),
78
- errorMessage: intl.formatMessage(mediaInsertMessages.errorMessage),
79
- warning: intl.formatMessage(mediaInsertMessages.warning)
78
+ errorMessage: intl.formatMessage(mediaInsertMessages.fromUrlErrorMessage),
79
+ warning: intl.formatMessage(mediaInsertMessages.fromUrlWarning)
80
80
  };
81
81
  var _React$useState = React.useState(''),
82
82
  _React$useState2 = _slicedToArray(_React$useState, 2),
@@ -88,36 +88,39 @@ export function MediaFromURL(_ref) {
88
88
  dispatch = _React$useReducer2[1];
89
89
  var pasteFlag = React.useRef(false);
90
90
  var _useAnalyticsEvents = useAnalyticsEvents(dispatchAnalyticsEvent),
91
- onUploadAnalytics = _useAnalyticsEvents.onUploadAnalytics,
91
+ onUploadButtonClickedAnalytics = _useAnalyticsEvents.onUploadButtonClickedAnalytics,
92
+ onUploadCommencedAnalytics = _useAnalyticsEvents.onUploadCommencedAnalytics,
92
93
  onUploadSuccessAnalytics = _useAnalyticsEvents.onUploadSuccessAnalytics,
93
94
  onUploadFailureAnalytics = _useAnalyticsEvents.onUploadFailureAnalytics;
94
95
  var uploadExternalMedia = React.useCallback( /*#__PURE__*/function () {
95
96
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(url) {
96
- var uploadMediaClientConfig, uploadParams, mediaClient, collection, _yield$mediaClient$fi, uploadableFileUpfrontIds, dimensions, message;
97
+ var uploadMediaClientConfig, uploadParams, mediaClient, collection, _yield$mediaClient$fi, uploadableFileUpfrontIds, dimensions, mimeType, message;
97
98
  return _regeneratorRuntime.wrap(function _callee$(_context) {
98
99
  while (1) switch (_context.prev = _context.next) {
99
100
  case 0:
101
+ onUploadButtonClickedAnalytics();
100
102
  dispatch({
101
103
  type: 'loading'
102
104
  });
103
105
  uploadMediaClientConfig = mediaProvider.uploadMediaClientConfig, uploadParams = mediaProvider.uploadParams;
104
106
  if (uploadMediaClientConfig) {
105
- _context.next = 4;
107
+ _context.next = 5;
106
108
  break;
107
109
  }
108
110
  return _context.abrupt("return");
109
- case 4:
111
+ case 5:
110
112
  mediaClient = getMediaClient(uploadMediaClientConfig);
111
113
  collection = uploadParams === null || uploadParams === void 0 ? void 0 : uploadParams.collection;
112
- onUploadAnalytics();
113
- _context.prev = 7;
114
- _context.next = 10;
114
+ onUploadCommencedAnalytics('url');
115
+ _context.prev = 8;
116
+ _context.next = 11;
115
117
  return mediaClient.file.uploadExternal(url, collection);
116
- case 10:
118
+ case 11:
117
119
  _yield$mediaClient$fi = _context.sent;
118
120
  uploadableFileUpfrontIds = _yield$mediaClient$fi.uploadableFileUpfrontIds;
119
121
  dimensions = _yield$mediaClient$fi.dimensions;
120
- onUploadSuccessAnalytics();
122
+ mimeType = _yield$mediaClient$fi.mimeType;
123
+ onUploadSuccessAnalytics('url');
121
124
  dispatch({
122
125
  type: 'success',
123
126
  payload: {
@@ -125,19 +128,20 @@ export function MediaFromURL(_ref) {
125
128
  collection: collection,
126
129
  height: dimensions.height,
127
130
  width: dimensions.width,
128
- occurrenceKey: uploadableFileUpfrontIds.occurrenceKey
131
+ occurrenceKey: uploadableFileUpfrontIds.occurrenceKey,
132
+ fileMimeType: mimeType
129
133
  }
130
134
  });
131
- _context.next = 20;
135
+ _context.next = 22;
132
136
  break;
133
- case 17:
134
- _context.prev = 17;
135
- _context.t0 = _context["catch"](7);
137
+ case 19:
138
+ _context.prev = 19;
139
+ _context.t0 = _context["catch"](8);
136
140
  if (typeof _context.t0 === 'string' && _context.t0 === 'Could not download remote file') {
137
141
  // TODO: Make sure this gets good unit test coverage with the actual
138
142
  // media plugin. This hard coded error message could be changed at any
139
143
  // point and we need a unit test to break to stop people changing it.
140
- onUploadFailureAnalytics(_context.t0);
144
+ onUploadFailureAnalytics(_context.t0, 'url');
141
145
  dispatch({
142
146
  type: 'warning',
143
147
  warning: _context.t0,
@@ -145,28 +149,28 @@ export function MediaFromURL(_ref) {
145
149
  });
146
150
  } else if (_context.t0 instanceof Error) {
147
151
  message = 'Image preview fetch failed';
148
- onUploadFailureAnalytics(message);
152
+ onUploadFailureAnalytics(message, 'url');
149
153
  dispatch({
150
154
  type: 'error',
151
155
  error: message
152
156
  });
153
157
  } else {
154
- onUploadFailureAnalytics('Unknown error');
158
+ onUploadFailureAnalytics('Unknown error', 'url');
155
159
  dispatch({
156
160
  type: 'error',
157
161
  error: 'Unknown error'
158
162
  });
159
163
  }
160
- case 20:
164
+ case 22:
161
165
  case "end":
162
166
  return _context.stop();
163
167
  }
164
- }, _callee, null, [[7, 17]]);
168
+ }, _callee, null, [[8, 19]]);
165
169
  }));
166
170
  return function (_x) {
167
171
  return _ref2.apply(this, arguments);
168
172
  };
169
- }(), [mediaProvider, onUploadAnalytics, onUploadFailureAnalytics, onUploadSuccessAnalytics, inputUrl]);
173
+ }(), [onUploadButtonClickedAnalytics, mediaProvider, onUploadCommencedAnalytics, onUploadSuccessAnalytics, onUploadFailureAnalytics, inputUrl]);
170
174
  var onURLChange = React.useCallback(function (e) {
171
175
  var url = e.target.value;
172
176
  setUrl(url);
@@ -189,14 +193,33 @@ export function MediaFromURL(_ref) {
189
193
  pasteFlag.current = true;
190
194
  }
191
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]);
192
215
  var onInsertClick = React.useCallback(function () {
193
216
  if (previewState.previewInfo) {
194
- return onInsert(previewState.previewInfo);
217
+ return onInsert();
195
218
  }
196
219
  if (previewState.warning) {
197
220
  return onExternalInsert(inputUrl);
198
221
  }
199
- }, [onExternalInsert, onInsert, previewState.previewInfo, previewState.warning, inputUrl]);
222
+ }, [previewState.previewInfo, previewState.warning, onInsert, onExternalInsert, inputUrl]);
200
223
  var onInputKeyPress = React.useCallback(function (event) {
201
224
  if (event && event.key === 'Esc') {
202
225
  if (dispatchAnalyticsEvent) {
@@ -3,21 +3,29 @@ import { useIntl } from 'react-intl-next';
3
3
  import { mediaInsertMessages } from '@atlaskit/editor-common/messages';
4
4
  import { Box } from '@atlaskit/primitives';
5
5
  import Tabs, { Tab, TabList, TabPanel } from '@atlaskit/tabs';
6
- import { MediaFromURL } from './FromURL';
6
+ import { LocalMedia } from './LocalMedia';
7
+ import { MediaFromURL } from './MediaFromURL';
7
8
  export var MediaInsertContent = function MediaInsertContent(_ref) {
8
9
  var mediaProvider = _ref.mediaProvider,
9
10
  dispatchAnalyticsEvent = _ref.dispatchAnalyticsEvent,
10
- closeMediaInsertPicker = _ref.closeMediaInsertPicker;
11
+ closeMediaInsertPicker = _ref.closeMediaInsertPicker,
12
+ insertMediaSingle = _ref.insertMediaSingle,
13
+ insertExternalMediaSingle = _ref.insertExternalMediaSingle;
11
14
  var intl = useIntl();
12
15
  return /*#__PURE__*/React.createElement(Tabs, {
13
16
  id: "media-insert-tab-navigation"
14
17
  }, /*#__PURE__*/React.createElement(Box, {
15
18
  paddingBlockEnd: "space.150"
16
- }, /*#__PURE__*/React.createElement(TabList, null, /*#__PURE__*/React.createElement(Tab, null, intl.formatMessage(mediaInsertMessages.linkTabTitle)))), /*#__PURE__*/React.createElement(TabPanel, null, /*#__PURE__*/React.createElement(MediaFromURL, {
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, {
20
+ mediaProvider: mediaProvider,
21
+ onInsert: insertMediaSingle,
22
+ onClose: closeMediaInsertPicker,
23
+ dispatchAnalyticsEvent: dispatchAnalyticsEvent
24
+ })), /*#__PURE__*/React.createElement(TabPanel, null, /*#__PURE__*/React.createElement(MediaFromURL, {
17
25
  mediaProvider: mediaProvider,
18
- onExternalInsert: function onExternalInsert() {},
19
- onInsert: function onInsert() {},
20
26
  dispatchAnalyticsEvent: dispatchAnalyticsEvent,
21
- closeMediaInsertPicker: closeMediaInsertPicker
27
+ closeMediaInsertPicker: closeMediaInsertPicker,
28
+ insertMediaSingle: insertMediaSingle,
29
+ insertExternalMediaSingle: insertExternalMediaSingle
22
30
  })));
23
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
  };
@@ -1,38 +1,54 @@
1
1
  import React from 'react';
2
2
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
3
3
  export function useAnalyticsEvents(dispatchAnalyticsEvent) {
4
- var onUploadAnalytics = React.useCallback(function () {
4
+ var onUploadButtonClickedAnalytics = React.useCallback(function () {
5
5
  dispatchAnalyticsEvent === null || dispatchAnalyticsEvent === void 0 || dispatchAnalyticsEvent({
6
6
  action: ACTION.CLICKED,
7
7
  actionSubject: ACTION_SUBJECT.BUTTON,
8
- actionSubjectId: ACTION_SUBJECT_ID.UPLOAD_MEDIA_FROM_URL,
8
+ actionSubjectId: ACTION_SUBJECT_ID.UPLOAD_MEDIA,
9
9
  eventType: EVENT_TYPE.UI
10
10
  });
11
11
  }, [dispatchAnalyticsEvent]);
12
- var onUploadSuccessAnalytics = React.useCallback(function () {
12
+ var onUploadCommencedAnalytics = React.useCallback(function (mediaUploadSource) {
13
+ dispatchAnalyticsEvent === null || dispatchAnalyticsEvent === void 0 || dispatchAnalyticsEvent({
14
+ action: ACTION.UPLOAD_COMMENCED,
15
+ actionSubject: ACTION_SUBJECT.MEDIA,
16
+ actionSubjectId: ACTION_SUBJECT_ID.UPLOAD_MEDIA,
17
+ eventType: EVENT_TYPE.OPERATIONAL,
18
+ attributes: {
19
+ mediaUploadSource: mediaUploadSource
20
+ }
21
+ });
22
+ }, [dispatchAnalyticsEvent]);
23
+ var onUploadSuccessAnalytics = React.useCallback(function (mediaUploadSource) {
13
24
  dispatchAnalyticsEvent === null || dispatchAnalyticsEvent === void 0 || dispatchAnalyticsEvent({
14
25
  action: ACTION.UPLOAD_SUCCEEDED,
15
26
  actionSubject: ACTION_SUBJECT.MEDIA,
16
- actionSubjectId: ACTION_SUBJECT_ID.UPLOAD_MEDIA_FROM_URL,
17
- eventType: EVENT_TYPE.OPERATIONAL
27
+ actionSubjectId: ACTION_SUBJECT_ID.UPLOAD_MEDIA,
28
+ eventType: EVENT_TYPE.OPERATIONAL,
29
+ attributes: {
30
+ mediaUploadSource: mediaUploadSource
31
+ }
18
32
  });
19
33
  }, [dispatchAnalyticsEvent]);
20
- var onUploadFailureAnalytics = React.useCallback(function (reason) {
34
+ var onUploadFailureAnalytics = React.useCallback(function (reason, mediaUploadSource) {
21
35
  dispatchAnalyticsEvent === null || dispatchAnalyticsEvent === void 0 || dispatchAnalyticsEvent({
22
36
  action: ACTION.UPLOAD_FAILED,
23
37
  actionSubject: ACTION_SUBJECT.MEDIA,
24
- actionSubjectId: ACTION_SUBJECT_ID.UPLOAD_MEDIA_FROM_URL,
38
+ actionSubjectId: ACTION_SUBJECT_ID.UPLOAD_MEDIA,
25
39
  eventType: EVENT_TYPE.OPERATIONAL,
26
40
  attributes: {
27
- reason: reason
41
+ reason: reason,
42
+ mediaUploadSource: mediaUploadSource
28
43
  }
29
44
  });
30
45
  }, [dispatchAnalyticsEvent]);
31
46
  return React.useMemo(function () {
32
47
  return {
33
- onUploadAnalytics: onUploadAnalytics,
48
+ onUploadButtonClickedAnalytics: onUploadButtonClickedAnalytics,
49
+ onUploadCommencedAnalytics: onUploadCommencedAnalytics,
34
50
  onUploadSuccessAnalytics: onUploadSuccessAnalytics,
35
51
  onUploadFailureAnalytics: onUploadFailureAnalytics
36
52
  };
37
- }, [onUploadAnalytics, onUploadSuccessAnalytics, onUploadFailureAnalytics]);
53
+ }, [onUploadButtonClickedAnalytics, onUploadCommencedAnalytics, onUploadSuccessAnalytics, onUploadFailureAnalytics]);
38
54
  }
@@ -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
  };
@@ -0,0 +1,12 @@
1
+ /// <reference types="react" />
2
+ import { type DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
3
+ import type { MediaProvider } from '@atlaskit/editor-common/provider-factory';
4
+ import { type InsertMediaSingle } from '../types';
5
+ type Props = {
6
+ mediaProvider: MediaProvider;
7
+ onInsert: InsertMediaSingle;
8
+ onClose: () => void;
9
+ dispatchAnalyticsEvent?: DispatchAnalyticsEvent;
10
+ };
11
+ export declare const LocalMedia: ({ mediaProvider, onInsert, dispatchAnalyticsEvent }: Props) => JSX.Element;
12
+ export {};
@@ -2,7 +2,7 @@
2
2
  import type { MediaProvider } from '@atlaskit/editor-common/provider-factory';
3
3
  import { type OnInsertAttrs } from './types';
4
4
  type Props = {
5
- attrs: OnInsertAttrs;
5
+ attrs: Required<OnInsertAttrs>;
6
6
  mediaProvider: MediaProvider;
7
7
  };
8
8
  export declare const MediaCard: ({ attrs, mediaProvider }: Props) => JSX.Element;
@@ -0,0 +1,13 @@
1
+ /// <reference types="react" />
2
+ import { type DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
3
+ import type { MediaProvider } from '@atlaskit/editor-common/provider-factory';
4
+ import { type InsertExternalMediaSingle, type InsertMediaSingle } from '../types';
5
+ type Props = {
6
+ mediaProvider: MediaProvider;
7
+ dispatchAnalyticsEvent?: DispatchAnalyticsEvent;
8
+ closeMediaInsertPicker: () => void;
9
+ insertMediaSingle: InsertMediaSingle;
10
+ insertExternalMediaSingle: InsertExternalMediaSingle;
11
+ };
12
+ export declare function MediaFromURL({ mediaProvider, dispatchAnalyticsEvent, closeMediaInsertPicker, insertMediaSingle, insertExternalMediaSingle, }: Props): JSX.Element;
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
- export declare const MediaInsertContent: ({ mediaProvider, dispatchAnalyticsEvent, closeMediaInsertPicker, }: {
4
+ import { type InsertExternalMediaSingle, type InsertMediaSingle } from '../types';
5
+ type Props = {
5
6
  mediaProvider: MediaProvider;
6
- dispatchAnalyticsEvent?: DispatchAnalyticsEvent | undefined;
7
+ dispatchAnalyticsEvent?: DispatchAnalyticsEvent;
7
8
  closeMediaInsertPicker: () => void;
8
- }) => JSX.Element;
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;
@@ -1,7 +1,8 @@
1
1
  export type OnInsertAttrs = {
2
2
  id: string;
3
3
  collection: string | undefined;
4
- height: number;
5
- width: number;
4
+ height?: number;
5
+ width?: number;
6
6
  occurrenceKey: string | undefined;
7
+ fileMimeType: string;
7
8
  };
@@ -1,6 +1,9 @@
1
1
  import { type DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
2
+ type Source = 'local' | 'url';
2
3
  export declare function useAnalyticsEvents(dispatchAnalyticsEvent?: DispatchAnalyticsEvent): {
3
- onUploadAnalytics: () => void;
4
- onUploadSuccessAnalytics: () => void;
5
- onUploadFailureAnalytics: (reason: string) => void;
4
+ onUploadButtonClickedAnalytics: () => void;
5
+ onUploadCommencedAnalytics: (mediaUploadSource: Source) => void;
6
+ onUploadSuccessAnalytics: (mediaUploadSource: Source) => void;
7
+ onUploadFailureAnalytics: (reason: string, mediaUploadSource: Source) => void;
6
8
  };
9
+ export {};
@@ -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
  };
@@ -0,0 +1,12 @@
1
+ /// <reference types="react" />
2
+ import { type DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
3
+ import type { MediaProvider } from '@atlaskit/editor-common/provider-factory';
4
+ import { type InsertMediaSingle } from '../types';
5
+ type Props = {
6
+ mediaProvider: MediaProvider;
7
+ onInsert: InsertMediaSingle;
8
+ onClose: () => void;
9
+ dispatchAnalyticsEvent?: DispatchAnalyticsEvent;
10
+ };
11
+ export declare const LocalMedia: ({ mediaProvider, onInsert, dispatchAnalyticsEvent }: Props) => JSX.Element;
12
+ export {};
@@ -2,7 +2,7 @@
2
2
  import type { MediaProvider } from '@atlaskit/editor-common/provider-factory';
3
3
  import { type OnInsertAttrs } from './types';
4
4
  type Props = {
5
- attrs: OnInsertAttrs;
5
+ attrs: Required<OnInsertAttrs>;
6
6
  mediaProvider: MediaProvider;
7
7
  };
8
8
  export declare const MediaCard: ({ attrs, mediaProvider }: Props) => JSX.Element;
@@ -0,0 +1,13 @@
1
+ /// <reference types="react" />
2
+ import { type DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
3
+ import type { MediaProvider } from '@atlaskit/editor-common/provider-factory';
4
+ import { type InsertExternalMediaSingle, type InsertMediaSingle } from '../types';
5
+ type Props = {
6
+ mediaProvider: MediaProvider;
7
+ dispatchAnalyticsEvent?: DispatchAnalyticsEvent;
8
+ closeMediaInsertPicker: () => void;
9
+ insertMediaSingle: InsertMediaSingle;
10
+ insertExternalMediaSingle: InsertExternalMediaSingle;
11
+ };
12
+ export declare function MediaFromURL({ mediaProvider, dispatchAnalyticsEvent, closeMediaInsertPicker, insertMediaSingle, insertExternalMediaSingle, }: Props): JSX.Element;
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
- export declare const MediaInsertContent: ({ mediaProvider, dispatchAnalyticsEvent, closeMediaInsertPicker, }: {
4
+ import { type InsertExternalMediaSingle, type InsertMediaSingle } from '../types';
5
+ type Props = {
5
6
  mediaProvider: MediaProvider;
6
- dispatchAnalyticsEvent?: DispatchAnalyticsEvent | undefined;
7
+ dispatchAnalyticsEvent?: DispatchAnalyticsEvent;
7
8
  closeMediaInsertPicker: () => void;
8
- }) => JSX.Element;
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;
@@ -1,7 +1,8 @@
1
1
  export type OnInsertAttrs = {
2
2
  id: string;
3
3
  collection: string | undefined;
4
- height: number;
5
- width: number;
4
+ height?: number;
5
+ width?: number;
6
6
  occurrenceKey: string | undefined;
7
+ fileMimeType: string;
7
8
  };
@@ -1,6 +1,9 @@
1
1
  import { type DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
2
+ type Source = 'local' | 'url';
2
3
  export declare function useAnalyticsEvents(dispatchAnalyticsEvent?: DispatchAnalyticsEvent): {
3
- onUploadAnalytics: () => void;
4
- onUploadSuccessAnalytics: () => void;
5
- onUploadFailureAnalytics: (reason: string) => void;
4
+ onUploadButtonClickedAnalytics: () => void;
5
+ onUploadCommencedAnalytics: (mediaUploadSource: Source) => void;
6
+ onUploadSuccessAnalytics: (mediaUploadSource: Source) => void;
7
+ onUploadFailureAnalytics: (reason: string, mediaUploadSource: Source) => void;
6
8
  };
9
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-media-insert",
3
- "version": "2.1.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,16 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "@atlaskit/button": "^20.1.0",
28
- "@atlaskit/editor-common": "^88.2.0",
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.1.0",
35
- "@atlaskit/media-client": "^27.5.0",
36
- "@atlaskit/media-client-react": "^2.1.0",
34
+ "@atlaskit/media-card": "^78.2.0",
35
+ "@atlaskit/media-client": "^27.6.0",
36
+ "@atlaskit/media-client-react": "^2.2.0",
37
+ "@atlaskit/media-picker": "^66.4.0",
37
38
  "@atlaskit/primitives": "^12.0.0",
38
39
  "@atlaskit/section-message": "^6.6.0",
39
40
  "@atlaskit/tabs": "^16.4.0",
@@ -1,13 +0,0 @@
1
- /// <reference types="react" />
2
- import { type DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
3
- import type { MediaProvider } from '@atlaskit/editor-common/provider-factory';
4
- import { type OnInsertAttrs } from './types';
5
- type Props = {
6
- mediaProvider: MediaProvider;
7
- onInsert: (attrs: OnInsertAttrs) => void;
8
- onExternalInsert: (url: string) => void;
9
- dispatchAnalyticsEvent?: DispatchAnalyticsEvent;
10
- closeMediaInsertPicker: () => void;
11
- };
12
- export declare function MediaFromURL({ mediaProvider, onInsert, onExternalInsert, dispatchAnalyticsEvent, closeMediaInsertPicker, }: Props): JSX.Element;
13
- export {};
@@ -1,13 +0,0 @@
1
- /// <reference types="react" />
2
- import { type DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
3
- import type { MediaProvider } from '@atlaskit/editor-common/provider-factory';
4
- import { type OnInsertAttrs } from './types';
5
- type Props = {
6
- mediaProvider: MediaProvider;
7
- onInsert: (attrs: OnInsertAttrs) => void;
8
- onExternalInsert: (url: string) => void;
9
- dispatchAnalyticsEvent?: DispatchAnalyticsEvent;
10
- closeMediaInsertPicker: () => void;
11
- };
12
- export declare function MediaFromURL({ mediaProvider, onInsert, onExternalInsert, dispatchAnalyticsEvent, closeMediaInsertPicker, }: Props): JSX.Element;
13
- export {};