@atlaskit/editor-plugin-media-insert 1.2.2 → 2.0.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 (57) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/cjs/actions.js +28 -0
  3. package/dist/cjs/index.js +1 -8
  4. package/dist/cjs/plugin.js +57 -10
  5. package/dist/cjs/pm-plugins/main.js +40 -0
  6. package/dist/cjs/pm-plugins/plugin-key.js +8 -0
  7. package/dist/cjs/types.js +5 -0
  8. package/dist/cjs/ui/FromURL.js +30 -22
  9. package/dist/cjs/ui/MediaCard.js +1 -9
  10. package/dist/cjs/ui/MediaInsertContent.js +30 -0
  11. package/dist/cjs/ui/MediaInsertPicker.js +96 -0
  12. package/dist/cjs/ui/MediaInsertWrapper.js +21 -0
  13. package/dist/es2019/actions.js +21 -0
  14. package/dist/es2019/index.js +1 -2
  15. package/dist/es2019/plugin.js +62 -12
  16. package/dist/es2019/pm-plugins/main.js +34 -0
  17. package/dist/es2019/pm-plugins/plugin-key.js +2 -0
  18. package/dist/es2019/types.js +1 -0
  19. package/dist/es2019/ui/FromURL.js +18 -5
  20. package/dist/es2019/ui/MediaCard.js +1 -5
  21. package/dist/es2019/ui/MediaInsertContent.js +21 -0
  22. package/dist/es2019/ui/MediaInsertPicker.js +86 -0
  23. package/dist/es2019/ui/MediaInsertWrapper.js +15 -0
  24. package/dist/esm/actions.js +22 -0
  25. package/dist/esm/index.js +1 -2
  26. package/dist/esm/plugin.js +57 -10
  27. package/dist/esm/pm-plugins/main.js +34 -0
  28. package/dist/esm/pm-plugins/plugin-key.js +2 -0
  29. package/dist/esm/types.js +1 -0
  30. package/dist/esm/ui/FromURL.js +30 -22
  31. package/dist/esm/ui/MediaCard.js +1 -9
  32. package/dist/esm/ui/MediaInsertContent.js +20 -0
  33. package/dist/esm/ui/MediaInsertPicker.js +89 -0
  34. package/dist/esm/ui/MediaInsertWrapper.js +14 -0
  35. package/dist/types/actions.d.ts +6 -0
  36. package/dist/types/index.d.ts +1 -2
  37. package/dist/types/plugin.d.ts +1 -2
  38. package/dist/types/pm-plugins/main.d.ts +3 -0
  39. package/dist/types/pm-plugins/plugin-key.d.ts +3 -0
  40. package/dist/types/types.d.ts +17 -0
  41. package/dist/types/ui/FromURL.d.ts +3 -2
  42. package/dist/types/ui/MediaCard.d.ts +2 -2
  43. package/dist/types/ui/MediaInsertContent.d.ts +8 -0
  44. package/dist/types/ui/MediaInsertPicker.d.ts +3 -0
  45. package/dist/types/ui/MediaInsertWrapper.d.ts +4 -0
  46. package/dist/types-ts4.5/actions.d.ts +6 -0
  47. package/dist/types-ts4.5/index.d.ts +1 -2
  48. package/dist/types-ts4.5/plugin.d.ts +1 -2
  49. package/dist/types-ts4.5/pm-plugins/main.d.ts +3 -0
  50. package/dist/types-ts4.5/pm-plugins/plugin-key.d.ts +3 -0
  51. package/dist/types-ts4.5/types.d.ts +20 -0
  52. package/dist/types-ts4.5/ui/FromURL.d.ts +3 -2
  53. package/dist/types-ts4.5/ui/MediaCard.d.ts +2 -2
  54. package/dist/types-ts4.5/ui/MediaInsertContent.d.ts +8 -0
  55. package/dist/types-ts4.5/ui/MediaInsertPicker.d.ts +3 -0
  56. package/dist/types-ts4.5/ui/MediaInsertWrapper.d.ts +4 -0
  57. package/package.json +9 -4
package/CHANGELOG.md CHANGED
@@ -1,5 +1,30 @@
1
1
  # @atlaskit/editor-plugin-media-insert
2
2
 
3
+ ## 2.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - [#129869](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/129869)
8
+ [`48b31a6b8fb5a`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/48b31a6b8fb5a) -
9
+ [ux] [ED-24566] Integrated Media URL UI into the Insert Media Popup [ED-24589] Removed export of
10
+ UI component from `editor-plugin-media-insert`
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies
15
+
16
+ ## 1.3.0
17
+
18
+ ### Minor Changes
19
+
20
+ - [#129365](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/129365)
21
+ [`0cb229e53ad8f`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/0cb229e53ad8f) -
22
+ [ux] [ED-24249] Added popup dialog for inserting media using editor-plugin-media-insert
23
+
24
+ ### Patch Changes
25
+
26
+ - Updated dependencies
27
+
3
28
  ## 1.2.2
4
29
 
5
30
  ### Patch Changes
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.showMediaInsertPopup = exports.closeMediaInsertPicker = exports.ACTION_OPEN_POPUP = exports.ACTION_CLOSE_POPUP = void 0;
7
+ var _pluginKey = require("./pm-plugins/plugin-key");
8
+ var ACTION_OPEN_POPUP = exports.ACTION_OPEN_POPUP = 'OPEN_POPUP';
9
+ var ACTION_CLOSE_POPUP = exports.ACTION_CLOSE_POPUP = 'CLOSE_POPUP';
10
+ var setPopupMeta = function setPopupMeta(_ref) {
11
+ var type = _ref.type,
12
+ tr = _ref.tr;
13
+ return tr.setMeta(_pluginKey.pluginKey, {
14
+ type: type
15
+ });
16
+ };
17
+ var showMediaInsertPopup = exports.showMediaInsertPopup = function showMediaInsertPopup(tr) {
18
+ return setPopupMeta({
19
+ type: ACTION_OPEN_POPUP,
20
+ tr: tr
21
+ });
22
+ };
23
+ var closeMediaInsertPicker = exports.closeMediaInsertPicker = function closeMediaInsertPicker(tr) {
24
+ return setPopupMeta({
25
+ type: ACTION_CLOSE_POPUP,
26
+ tr: tr
27
+ });
28
+ };
package/dist/cjs/index.js CHANGED
@@ -3,17 +3,10 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- Object.defineProperty(exports, "MediaFromURL", {
7
- enumerable: true,
8
- get: function get() {
9
- return _FromURL.MediaFromURL;
10
- }
11
- });
12
6
  Object.defineProperty(exports, "mediaInsertPlugin", {
13
7
  enumerable: true,
14
8
  get: function get() {
15
9
  return _plugin.mediaInsertPlugin;
16
10
  }
17
11
  });
18
- var _plugin = require("./plugin");
19
- var _FromURL = require("./ui/FromURL");
12
+ var _plugin = require("./plugin");
@@ -6,24 +6,60 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.mediaInsertPlugin = void 0;
8
8
  var _react = _interopRequireDefault(require("react"));
9
+ var _analytics = require("@atlaskit/editor-common/analytics");
9
10
  var _messages = require("@atlaskit/editor-common/messages");
10
11
  var _quickInsert = require("@atlaskit/editor-common/quick-insert");
11
- var mediaInsertPlugin = exports.mediaInsertPlugin = function mediaInsertPlugin() {
12
+ var _actions = require("./actions");
13
+ var _main = require("./pm-plugins/main");
14
+ var _pluginKey = require("./pm-plugins/plugin-key");
15
+ var _MediaInsertPicker = require("./ui/MediaInsertPicker");
16
+ var mediaInsertPlugin = exports.mediaInsertPlugin = function mediaInsertPlugin(_ref) {
17
+ var api = _ref.api;
12
18
  return {
13
19
  name: 'mediaInsert',
14
20
  pmPlugins: function pmPlugins() {
15
21
  return [{
16
22
  name: 'mediaInsert',
17
23
  plugin: function plugin() {
18
- // eslint-disable-next-line no-console
19
- console.log('mediaInsert plugin');
20
- return undefined;
24
+ return (0, _main.createPlugin)();
21
25
  }
22
26
  }];
23
27
  },
28
+ getSharedState: function getSharedState(editorState) {
29
+ if (!editorState) {
30
+ return {
31
+ isOpen: false
32
+ };
33
+ }
34
+ var _ref2 = _pluginKey.pluginKey.getState(editorState) || {},
35
+ isOpen = _ref2.isOpen;
36
+ return {
37
+ isOpen: isOpen
38
+ };
39
+ },
40
+ contentComponent: function contentComponent(_ref3) {
41
+ var editorView = _ref3.editorView,
42
+ dispatchAnalyticsEvent = _ref3.dispatchAnalyticsEvent,
43
+ popupsMountPoint = _ref3.popupsMountPoint,
44
+ popupsBoundariesElement = _ref3.popupsBoundariesElement,
45
+ popupsScrollableElement = _ref3.popupsScrollableElement;
46
+ var dispatch = editorView.dispatch,
47
+ state = editorView.state;
48
+ return /*#__PURE__*/_react.default.createElement(_MediaInsertPicker.MediaInsertPicker, {
49
+ api: api,
50
+ editorView: editorView,
51
+ dispatchAnalyticsEvent: dispatchAnalyticsEvent,
52
+ popupsMountPoint: popupsMountPoint,
53
+ popupsBoundariesElement: popupsBoundariesElement,
54
+ popupsScrollableElement: popupsScrollableElement,
55
+ closeMediaInsertPicker: function closeMediaInsertPicker() {
56
+ return dispatch((0, _actions.closeMediaInsertPicker)(state.tr));
57
+ }
58
+ });
59
+ },
24
60
  pluginsOptions: {
25
- quickInsert: function quickInsert(_ref) {
26
- var formatMessage = _ref.formatMessage;
61
+ quickInsert: function quickInsert(_ref4) {
62
+ var formatMessage = _ref4.formatMessage;
27
63
  return [{
28
64
  id: 'media-insert',
29
65
  title: formatMessage(_messages.toolbarInsertBlockMessages.insertMediaFromUrl),
@@ -34,10 +70,21 @@ var mediaInsertPlugin = exports.mediaInsertPlugin = function mediaInsertPlugin()
34
70
  return /*#__PURE__*/_react.default.createElement(_quickInsert.IconImages, null);
35
71
  },
36
72
  action: function action(insert) {
37
- return insert({
38
- type: 'paragraph',
39
- content: []
40
- });
73
+ var _api$analytics;
74
+ // Insert empty string to remove the typeahead raw text
75
+ // close the quick insert immediately
76
+ var tr = insert('');
77
+ (0, _actions.showMediaInsertPopup)(tr);
78
+ api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || (_api$analytics = _api$analytics.actions) === null || _api$analytics === void 0 || _api$analytics.attachAnalyticsEvent({
79
+ action: _analytics.ACTION.OPENED,
80
+ actionSubject: _analytics.ACTION_SUBJECT.PICKER,
81
+ actionSubjectId: _analytics.ACTION_SUBJECT_ID.PICKER_MEDIA,
82
+ attributes: {
83
+ inputMethod: _analytics.INPUT_METHOD.QUICK_INSERT
84
+ },
85
+ eventType: _analytics.EVENT_TYPE.UI
86
+ })(tr);
87
+ return tr;
41
88
  }
42
89
  }];
43
90
  }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createPlugin = void 0;
7
+ var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
8
+ var _actions = require("../actions");
9
+ var _pluginKey = require("./plugin-key");
10
+ var createPlugin = exports.createPlugin = function createPlugin() {
11
+ return new _safePlugin.SafePlugin({
12
+ state: {
13
+ init: function init() {
14
+ return {
15
+ isOpen: false
16
+ };
17
+ },
18
+ apply: function apply(tr, mediaInsertPluginState) {
19
+ var meta = tr.getMeta(_pluginKey.pluginKey);
20
+ if (meta) {
21
+ switch (meta.type) {
22
+ case _actions.ACTION_OPEN_POPUP:
23
+ return {
24
+ isOpen: true
25
+ };
26
+ case _actions.ACTION_CLOSE_POPUP:
27
+ return {
28
+ isOpen: false
29
+ };
30
+ default:
31
+ return mediaInsertPluginState;
32
+ }
33
+ } else {
34
+ return mediaInsertPluginState;
35
+ }
36
+ }
37
+ },
38
+ key: _pluginKey.pluginKey
39
+ });
40
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.pluginKey = void 0;
7
+ var _state = require("@atlaskit/editor-prosemirror/state");
8
+ var pluginKey = exports.pluginKey = new _state.PluginKey('mediaInsertPlugin');
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -36,6 +36,9 @@ var PreviewImageStyles = (0, _primitives.xcss)({
36
36
  var ButtonGroupStyles = (0, _primitives.xcss)({
37
37
  alignSelf: 'end'
38
38
  });
39
+ var FormStyles = (0, _primitives.xcss)({
40
+ flexGrow: 1
41
+ });
39
42
  var INITIAL_PREVIEW_STATE = Object.freeze({
40
43
  isLoading: false,
41
44
  error: null,
@@ -77,7 +80,8 @@ function MediaFromURL(_ref) {
77
80
  var mediaProvider = _ref.mediaProvider,
78
81
  onInsert = _ref.onInsert,
79
82
  onExternalInsert = _ref.onExternalInsert,
80
- dispatchAnalyticsEvent = _ref.dispatchAnalyticsEvent;
83
+ dispatchAnalyticsEvent = _ref.dispatchAnalyticsEvent,
84
+ onEscKeyPressed = _ref.onEscKeyPressed;
81
85
  var intl = (0, _reactIntlNext.useIntl)();
82
86
  var strings = {
83
87
  loadPreview: intl.formatMessage(_messages.mediaInsertMessages.loadPreview),
@@ -102,32 +106,27 @@ function MediaFromURL(_ref) {
102
106
  onUploadFailureAnalytics = _useAnalyticsEvents.onUploadFailureAnalytics;
103
107
  var uploadExternalMedia = _react.default.useCallback( /*#__PURE__*/function () {
104
108
  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;
109
+ var uploadMediaClientConfig, uploadParams, mediaClient, collection, _yield$mediaClient$fi, uploadableFileUpfrontIds, dimensions, message;
106
110
  return _regenerator.default.wrap(function _callee$(_context) {
107
111
  while (1) switch (_context.prev = _context.next) {
108
112
  case 0:
109
113
  dispatch({
110
114
  type: 'loading'
111
115
  });
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;
116
+ uploadMediaClientConfig = mediaProvider.uploadMediaClientConfig, uploadParams = mediaProvider.uploadParams;
118
117
  if (uploadMediaClientConfig) {
119
- _context.next = 8;
118
+ _context.next = 4;
120
119
  break;
121
120
  }
122
121
  return _context.abrupt("return");
123
- case 8:
122
+ case 4:
124
123
  mediaClient = (0, _mediaClientReact.getMediaClient)(uploadMediaClientConfig);
125
124
  collection = uploadParams === null || uploadParams === void 0 ? void 0 : uploadParams.collection;
126
125
  onUploadAnalytics();
127
- _context.prev = 11;
128
- _context.next = 14;
126
+ _context.prev = 7;
127
+ _context.next = 10;
129
128
  return mediaClient.file.uploadExternal(url, collection);
130
- case 14:
129
+ case 10:
131
130
  _yield$mediaClient$fi = _context.sent;
132
131
  uploadableFileUpfrontIds = _yield$mediaClient$fi.uploadableFileUpfrontIds;
133
132
  dimensions = _yield$mediaClient$fi.dimensions;
@@ -142,11 +141,11 @@ function MediaFromURL(_ref) {
142
141
  occurrenceKey: uploadableFileUpfrontIds.occurrenceKey
143
142
  }
144
143
  });
145
- _context.next = 24;
144
+ _context.next = 20;
146
145
  break;
147
- case 21:
148
- _context.prev = 21;
149
- _context.t0 = _context["catch"](11);
146
+ case 17:
147
+ _context.prev = 17;
148
+ _context.t0 = _context["catch"](7);
150
149
  if (typeof _context.t0 === 'string' && _context.t0 === 'Could not download remote file') {
151
150
  // TODO: Make sure this gets good unit test coverage with the actual
152
151
  // media plugin. This hard coded error message could be changed at any
@@ -171,11 +170,11 @@ function MediaFromURL(_ref) {
171
170
  error: 'Unknown error'
172
171
  });
173
172
  }
174
- case 24:
173
+ case 20:
175
174
  case "end":
176
175
  return _context.stop();
177
176
  }
178
- }, _callee, null, [[11, 21]]);
177
+ }, _callee, null, [[7, 17]]);
179
178
  }));
180
179
  return function (_x) {
181
180
  return _ref2.apply(this, arguments);
@@ -211,18 +210,27 @@ function MediaFromURL(_ref) {
211
210
  return onExternalInsert(inputUrl);
212
211
  }
213
212
  }, [onExternalInsert, onInsert, previewState.previewInfo, previewState.warning, inputUrl]);
214
- return /*#__PURE__*/_react.default.createElement("form", {
213
+ var onInputKeyPress = _react.default.useCallback(function (event) {
214
+ if (event && event.key === 'Esc') {
215
+ onEscKeyPressed();
216
+ }
217
+ }, [onEscKeyPressed]);
218
+ return /*#__PURE__*/_react.default.createElement(_primitives.Box, {
219
+ as: "form",
215
220
  onSubmit: function onSubmit(e) {
216
221
  e.preventDefault();
217
222
  uploadExternalMedia(inputUrl);
218
- }
223
+ },
224
+ xcss: FormStyles
219
225
  }, /*#__PURE__*/_react.default.createElement(_primitives.Stack, {
220
- space: "space.150"
226
+ space: "space.150",
227
+ grow: "fill"
221
228
  }, /*#__PURE__*/_react.default.createElement(_textfield.default, {
222
229
  autoFocus: true,
223
230
  value: inputUrl,
224
231
  placeholder: strings.pasteLinkToUpload,
225
232
  onChange: onURLChange,
233
+ onKeyPress: onInputKeyPress,
226
234
  onPaste: onPaste
227
235
  }), previewState.previewInfo && /*#__PURE__*/_react.default.createElement(_primitives.Inline, {
228
236
  alignInline: "center",
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.MediaCard = void 0;
8
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
8
  var _react = _interopRequireDefault(require("react"));
10
9
  var _reactIntlNext = require("react-intl-next");
11
10
  var _messages = require("@atlaskit/editor-common/messages");
@@ -16,16 +15,9 @@ var maxDimensions = {
16
15
  };
17
16
  var MediaCard = exports.MediaCard = function MediaCard(_ref) {
18
17
  var attrs = _ref.attrs,
19
- mediaProviderPromise = _ref.mediaProvider;
18
+ mediaProvider = _ref.mediaProvider;
20
19
  var intl = (0, _reactIntlNext.useIntl)();
21
20
  var mediaAlt = intl.formatMessage(_messages.mediaInsertMessages.mediaAlt);
22
- var _React$useState = _react.default.useState(),
23
- _React$useState2 = (0, _slicedToArray2.default)(_React$useState, 2),
24
- mediaProvider = _React$useState2[0],
25
- setMediaProvider = _React$useState2[1];
26
- _react.default.useEffect(function () {
27
- mediaProviderPromise.then(setMediaProvider);
28
- }, [mediaProviderPromise]);
29
21
  var dimensions = _react.default.useMemo(function () {
30
22
  return {
31
23
  width: attrs.width,
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _typeof = require("@babel/runtime/helpers/typeof");
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.MediaInsertContent = void 0;
9
+ var _react = _interopRequireDefault(require("react"));
10
+ var _primitives = require("@atlaskit/primitives");
11
+ var _tabs = _interopRequireWildcard(require("@atlaskit/tabs"));
12
+ var _FromURL = require("./FromURL");
13
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
14
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
15
+ var MediaInsertContent = exports.MediaInsertContent = function MediaInsertContent(_ref) {
16
+ var mediaProvider = _ref.mediaProvider,
17
+ dispatchAnalyticsEvent = _ref.dispatchAnalyticsEvent,
18
+ onEscKeyPressed = _ref.onEscKeyPressed;
19
+ return /*#__PURE__*/_react.default.createElement(_tabs.default, {
20
+ id: "media-insert-tab-navigation"
21
+ }, /*#__PURE__*/_react.default.createElement(_primitives.Box, {
22
+ paddingBlockEnd: "space.150"
23
+ }, /*#__PURE__*/_react.default.createElement(_tabs.TabList, null, /*#__PURE__*/_react.default.createElement(_tabs.Tab, null, "Link"))), /*#__PURE__*/_react.default.createElement(_tabs.TabPanel, null, /*#__PURE__*/_react.default.createElement(_FromURL.MediaFromURL, {
24
+ mediaProvider: mediaProvider,
25
+ onExternalInsert: function onExternalInsert() {},
26
+ onInsert: function onInsert() {},
27
+ dispatchAnalyticsEvent: dispatchAnalyticsEvent,
28
+ onEscKeyPressed: onEscKeyPressed
29
+ })));
30
+ };
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.MediaInsertPicker = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _analytics = require("@atlaskit/editor-common/analytics");
10
+ var _hooks = require("@atlaskit/editor-common/hooks");
11
+ var _ui = require("@atlaskit/editor-common/ui");
12
+ var _utils = require("@atlaskit/editor-prosemirror/utils");
13
+ var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
14
+ var _MediaInsertContent = require("./MediaInsertContent");
15
+ var _MediaInsertWrapper = require("./MediaInsertWrapper");
16
+ var PopupWithListeners = (0, _ui.withOuterListeners)(_ui.Popup);
17
+ var getDomRefFromSelection = function getDomRefFromSelection(view, dispatchAnalyticsEvent) {
18
+ try {
19
+ var domRef = (0, _utils.findDomRefAtPos)(view.state.selection.from, view.domAtPos.bind(view));
20
+ if (domRef instanceof HTMLElement) {
21
+ return domRef;
22
+ } else {
23
+ throw new Error('Invalid DOM reference');
24
+ }
25
+ } catch (error) {
26
+ if (dispatchAnalyticsEvent) {
27
+ var payload = {
28
+ action: _analytics.ACTION.ERRORED,
29
+ actionSubject: _analytics.ACTION_SUBJECT.PICKER,
30
+ actionSubjectId: _analytics.ACTION_SUBJECT_ID.PICKER_MEDIA,
31
+ eventType: _analytics.EVENT_TYPE.OPERATIONAL,
32
+ attributes: {
33
+ error: 'Error getting DOM reference from selection'
34
+ }
35
+ };
36
+ dispatchAnalyticsEvent(payload);
37
+ }
38
+ }
39
+ };
40
+ var MediaInsertPicker = exports.MediaInsertPicker = function MediaInsertPicker(_ref) {
41
+ var _useSharedPluginState, _useSharedPluginState2;
42
+ var api = _ref.api,
43
+ editorView = _ref.editorView,
44
+ dispatchAnalyticsEvent = _ref.dispatchAnalyticsEvent,
45
+ popupsMountPoint = _ref.popupsMountPoint,
46
+ popupsBoundariesElement = _ref.popupsBoundariesElement,
47
+ popupsScrollableElement = _ref.popupsScrollableElement,
48
+ closeMediaInsertPicker = _ref.closeMediaInsertPicker;
49
+ var targetRef = getDomRefFromSelection(editorView, dispatchAnalyticsEvent);
50
+ var isOpen = (_useSharedPluginState = (0, _hooks.useSharedPluginState)(api, ['mediaInsert'])) === null || _useSharedPluginState === void 0 || (_useSharedPluginState = _useSharedPluginState.mediaInsertState) === null || _useSharedPluginState === void 0 ? void 0 : _useSharedPluginState.isOpen;
51
+ var mediaProvider = (_useSharedPluginState2 = (0, _hooks.useSharedPluginState)(api, ['media'])) === null || _useSharedPluginState2 === void 0 || (_useSharedPluginState2 = _useSharedPluginState2.mediaState) === null || _useSharedPluginState2 === void 0 ? void 0 : _useSharedPluginState2.mediaProvider;
52
+ if (!isOpen || !mediaProvider) {
53
+ return null;
54
+ }
55
+ var handleClose = function handleClose(exitMethod) {
56
+ return function (event) {
57
+ event.preventDefault();
58
+ if (dispatchAnalyticsEvent) {
59
+ var payload = {
60
+ action: _analytics.ACTION.CLOSED,
61
+ actionSubject: _analytics.ACTION_SUBJECT.PICKER,
62
+ actionSubjectId: _analytics.ACTION_SUBJECT_ID.PICKER_MEDIA,
63
+ eventType: _analytics.EVENT_TYPE.UI,
64
+ attributes: {
65
+ exitMethod: exitMethod
66
+ }
67
+ };
68
+ dispatchAnalyticsEvent(payload);
69
+ }
70
+ closeMediaInsertPicker();
71
+ };
72
+ };
73
+ return /*#__PURE__*/_react.default.createElement(PopupWithListeners
74
+ // TODO: i18n
75
+ , {
76
+ ariaLabel: 'Media Insert',
77
+ offset: [0, 12],
78
+ target: targetRef,
79
+ zIndex: _editorSharedStyles.akEditorFloatingDialogZIndex,
80
+ fitHeight: 390,
81
+ fitWidth: 340,
82
+ mountTo: popupsMountPoint,
83
+ boundariesElement: popupsBoundariesElement,
84
+ handleClickOutside: handleClose(_analytics.INPUT_METHOD.MOUSE),
85
+ handleEscapeKeydown: handleClose(_analytics.INPUT_METHOD.KEYBOARD),
86
+ scrollableElement: popupsScrollableElement,
87
+ preventOverflow: true,
88
+ focusTrap: true
89
+ }, /*#__PURE__*/_react.default.createElement(_MediaInsertWrapper.MediaInsertWrapper, null, /*#__PURE__*/_react.default.createElement(_MediaInsertContent.MediaInsertContent, {
90
+ mediaProvider: mediaProvider,
91
+ dispatchAnalyticsEvent: dispatchAnalyticsEvent,
92
+ onEscKeyPressed: function onEscKeyPressed() {
93
+ return handleClose(_analytics.INPUT_METHOD.KEYBOARD);
94
+ }
95
+ })));
96
+ };
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.MediaInsertWrapper = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _primitives = require("@atlaskit/primitives");
10
+ var styles = (0, _primitives.xcss)({
11
+ boxShadow: 'elevation.shadow.overflow',
12
+ width: '340px',
13
+ padding: 'space.200',
14
+ borderRadius: 'border.radius'
15
+ });
16
+ var MediaInsertWrapper = exports.MediaInsertWrapper = function MediaInsertWrapper(_ref) {
17
+ var children = _ref.children;
18
+ return /*#__PURE__*/_react.default.createElement(_primitives.Box, {
19
+ xcss: styles
20
+ }, children);
21
+ };
@@ -0,0 +1,21 @@
1
+ import { pluginKey } from './pm-plugins/plugin-key';
2
+ export const ACTION_OPEN_POPUP = 'OPEN_POPUP';
3
+ export const ACTION_CLOSE_POPUP = 'CLOSE_POPUP';
4
+ const setPopupMeta = ({
5
+ type,
6
+ tr
7
+ }) => tr.setMeta(pluginKey, {
8
+ type
9
+ });
10
+ export const showMediaInsertPopup = tr => {
11
+ return setPopupMeta({
12
+ type: ACTION_OPEN_POPUP,
13
+ tr
14
+ });
15
+ };
16
+ export const closeMediaInsertPicker = tr => {
17
+ return setPopupMeta({
18
+ type: ACTION_CLOSE_POPUP,
19
+ tr
20
+ });
21
+ };
@@ -1,2 +1 @@
1
- export { mediaInsertPlugin } from './plugin';
2
- export { MediaFromURL } from './ui/FromURL';
1
+ export { mediaInsertPlugin } from './plugin';
@@ -1,17 +1,56 @@
1
1
  import React from 'react';
2
+ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
3
  import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
3
4
  import { IconImages } from '@atlaskit/editor-common/quick-insert';
4
- export const mediaInsertPlugin = () => {
5
+ import { closeMediaInsertPicker, showMediaInsertPopup } from './actions';
6
+ import { createPlugin } from './pm-plugins/main';
7
+ import { pluginKey } from './pm-plugins/plugin-key';
8
+ import { MediaInsertPicker } from './ui/MediaInsertPicker';
9
+ export const mediaInsertPlugin = ({
10
+ api
11
+ }) => {
5
12
  return {
6
13
  name: 'mediaInsert',
7
- pmPlugins: () => [{
8
- name: 'mediaInsert',
9
- plugin: () => {
10
- // eslint-disable-next-line no-console
11
- console.log('mediaInsert plugin');
12
- return undefined;
14
+ pmPlugins() {
15
+ return [{
16
+ name: 'mediaInsert',
17
+ plugin: () => createPlugin()
18
+ }];
19
+ },
20
+ getSharedState(editorState) {
21
+ if (!editorState) {
22
+ return {
23
+ isOpen: false
24
+ };
13
25
  }
14
- }],
26
+ const {
27
+ isOpen
28
+ } = pluginKey.getState(editorState) || {};
29
+ return {
30
+ isOpen
31
+ };
32
+ },
33
+ contentComponent: ({
34
+ editorView,
35
+ dispatchAnalyticsEvent,
36
+ popupsMountPoint,
37
+ popupsBoundariesElement,
38
+ popupsScrollableElement
39
+ }) => {
40
+ const {
41
+ dispatch,
42
+ state
43
+ } = editorView;
44
+ return /*#__PURE__*/React.createElement(MediaInsertPicker, {
45
+ api: api,
46
+ editorView: editorView,
47
+ dispatchAnalyticsEvent: dispatchAnalyticsEvent,
48
+ popupsMountPoint: popupsMountPoint,
49
+ popupsBoundariesElement: popupsBoundariesElement,
50
+ popupsScrollableElement: popupsScrollableElement,
51
+ closeMediaInsertPicker: () => dispatch(closeMediaInsertPicker(state.tr))
52
+ });
53
+ },
15
54
  pluginsOptions: {
16
55
  quickInsert: ({
17
56
  formatMessage
@@ -23,10 +62,21 @@ export const mediaInsertPlugin = () => {
23
62
  keywords: ['attachment', 'gif', 'media', 'picture', 'image', 'video'],
24
63
  icon: () => /*#__PURE__*/React.createElement(IconImages, null),
25
64
  action(insert) {
26
- return insert({
27
- type: 'paragraph',
28
- content: []
29
- });
65
+ var _api$analytics, _api$analytics$action;
66
+ // Insert empty string to remove the typeahead raw text
67
+ // close the quick insert immediately
68
+ const tr = insert('');
69
+ showMediaInsertPopup(tr);
70
+ api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : (_api$analytics$action = _api$analytics.actions) === null || _api$analytics$action === void 0 ? void 0 : _api$analytics$action.attachAnalyticsEvent({
71
+ action: ACTION.OPENED,
72
+ actionSubject: ACTION_SUBJECT.PICKER,
73
+ actionSubjectId: ACTION_SUBJECT_ID.PICKER_MEDIA,
74
+ attributes: {
75
+ inputMethod: INPUT_METHOD.QUICK_INSERT
76
+ },
77
+ eventType: EVENT_TYPE.UI
78
+ })(tr);
79
+ return tr;
30
80
  }
31
81
  }]
32
82
  }