@atlaskit/editor-plugin-media 9.1.1 → 9.2.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 CHANGED
@@ -1,5 +1,16 @@
1
1
  # @atlaskit/editor-plugin-media
2
2
 
3
+ ## 9.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`ca937489954b8`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/ca937489954b8) -
8
+ Introduce new insertMediaSingle on media plugin and deprecate old action version.
9
+
10
+ ### Patch Changes
11
+
12
+ - Updated dependencies
13
+
3
14
  ## 9.1.1
4
15
 
5
16
  ### Patch Changes
@@ -105,6 +105,7 @@ var MediaViewerFunctionalComponent = function MediaViewerFunctionalComponent(_re
105
105
  });
106
106
  };
107
107
  var mediaPlugin = exports.mediaPlugin = function mediaPlugin(_ref3) {
108
+ var _api$analytics3;
108
109
  var _ref3$config = _ref3.config,
109
110
  options = _ref3$config === void 0 ? {} : _ref3$config,
110
111
  api = _ref3.api;
@@ -159,7 +160,8 @@ var mediaPlugin = exports.mediaPlugin = function mediaPlugin(_ref3) {
159
160
  commands: {
160
161
  showMediaViewer: _commands.showMediaViewer,
161
162
  hideMediaViewer: _commands.hideMediaViewer,
162
- trackMediaPaste: _commands.trackMediaPaste
163
+ trackMediaPaste: _commands.trackMediaPaste,
164
+ insertMediaSingle: (0, _commands.insertMediaAsMediaSingleCommand)(api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions, options.allowPixelResizing)
163
165
  },
164
166
  nodes: function nodes() {
165
167
  var _ref5 = options || {},
@@ -234,9 +236,9 @@ var mediaPlugin = exports.mediaPlugin = function mediaPlugin(_ref3) {
234
236
  }, {
235
237
  name: 'mediaKeymap',
236
238
  plugin: function plugin(_ref7) {
237
- var _api$analytics3, _api$selection;
239
+ var _api$analytics4, _api$selection;
238
240
  var getIntl = _ref7.getIntl;
239
- return (0, _keymap2.default)(options, api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions, api === null || api === void 0 || (_api$selection = api.selection) === null || _api$selection === void 0 ? void 0 : _api$selection.actions, api === null || api === void 0 ? void 0 : api.width, getIntl);
241
+ return (0, _keymap2.default)(options, api === null || api === void 0 || (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions, api === null || api === void 0 || (_api$selection = api.selection) === null || _api$selection === void 0 ? void 0 : _api$selection.actions, api === null || api === void 0 ? void 0 : api.width, getIntl);
240
242
  }
241
243
  }];
242
244
  if (options && options.allowMediaSingle) {
@@ -256,9 +258,9 @@ var mediaPlugin = exports.mediaPlugin = function mediaPlugin(_ref3) {
256
258
  pmPlugins.push({
257
259
  name: 'mediaAltTextKeymap',
258
260
  plugin: function plugin(_ref9) {
259
- var _api$analytics4;
261
+ var _api$analytics5;
260
262
  var schema = _ref9.schema;
261
- return (0, _keymap.default)(schema, api === null || api === void 0 || (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions);
263
+ return (0, _keymap.default)(schema, api === null || api === void 0 || (_api$analytics5 = api.analytics) === null || _api$analytics5 === void 0 ? void 0 : _api$analytics5.actions);
262
264
  }
263
265
  });
264
266
  }
@@ -3,10 +3,11 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.trackMediaPaste = exports.showMediaViewer = exports.hideMediaViewer = void 0;
6
+ exports.trackMediaPaste = exports.showMediaViewer = exports.insertMediaAsMediaSingleCommand = exports.hideMediaViewer = void 0;
7
7
  var _actions = require("../pm-plugins/actions");
8
8
  var _pluginKey = require("../pm-plugins/plugin-key");
9
9
  var _mediaCommon = require("../pm-plugins/utils/media-common");
10
+ var _mediaSingle = require("./utils/media-single");
10
11
  var showMediaViewer = exports.showMediaViewer = function showMediaViewer(media) {
11
12
  return function (_ref) {
12
13
  var tr = _ref.tr;
@@ -37,4 +38,9 @@ var trackMediaPaste = exports.trackMediaPaste = function trackMediaPaste(attrs)
37
38
  });
38
39
  return tr;
39
40
  };
41
+ };
42
+ var insertMediaAsMediaSingleCommand = exports.insertMediaAsMediaSingleCommand = function insertMediaAsMediaSingleCommand(editorAnalyticsAPI, allowPixelResizing) {
43
+ return function (mediaAttrs, inputMethod, insertMediaVia) {
44
+ return (0, _mediaSingle.createInsertMediaAsMediaSingleCommand)(mediaAttrs, inputMethod, editorAnalyticsAPI, insertMediaVia, allowPixelResizing);
45
+ };
40
46
  };
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.isVideo = exports.isMediaSingle = exports.insertMediaSingleNode = exports.insertMediaAsMediaSingle = exports.changeFromMediaInlineToMediaSingleNode = void 0;
7
+ exports.isVideo = exports.isMediaSingle = exports.insertMediaSingleNode = exports.insertMediaAsMediaSingle = exports.createInsertMediaAsMediaSingleCommand = exports.changeFromMediaInlineToMediaSingleNode = void 0;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
9
  var _memoizeOne = _interopRequireDefault(require("memoize-one"));
10
10
  var _analytics = require("@atlaskit/editor-common/analytics");
@@ -14,6 +14,7 @@ var _selection = require("@atlaskit/editor-common/selection");
14
14
  var _utils = require("@atlaskit/editor-common/utils");
15
15
  var _model = require("@atlaskit/editor-prosemirror/model");
16
16
  var _utils2 = require("@atlaskit/editor-prosemirror/utils");
17
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
17
18
  var _mediaCommon = require("../utils/media-common");
18
19
  var _analytics2 = require("./analytics");
19
20
  var _isType = require("./is-type");
@@ -44,6 +45,21 @@ function insertNodesWithOptionalParagraph(_ref) {
44
45
  insertMediaVia = _ref.insertMediaVia;
45
46
  return function (state, dispatch) {
46
47
  var tr = state.tr;
48
+ if ((0, _platformFeatureFlags.fg)('platform_editor_introduce_insert_media_command')) {
49
+ var _updatedTr = insertNodesWithOptionalParagraphCommand({
50
+ nodes: nodes,
51
+ analyticsAttributes: analyticsAttributes,
52
+ editorAnalyticsAPI: editorAnalyticsAPI,
53
+ insertMediaVia: insertMediaVia
54
+ })({
55
+ tr: tr
56
+ });
57
+ if (_updatedTr && dispatch) {
58
+ dispatch === null || dispatch === void 0 || dispatch(_updatedTr);
59
+ return true;
60
+ }
61
+ return false;
62
+ }
47
63
  var inputMethod = analyticsAttributes.inputMethod,
48
64
  fileExtension = analyticsAttributes.fileExtension,
49
65
  newType = analyticsAttributes.newType,
@@ -76,6 +92,43 @@ function insertNodesWithOptionalParagraph(_ref) {
76
92
  return true;
77
93
  };
78
94
  }
95
+ function insertNodesWithOptionalParagraphCommand(_ref2) {
96
+ var nodes = _ref2.nodes,
97
+ _ref2$analyticsAttrib = _ref2.analyticsAttributes,
98
+ analyticsAttributes = _ref2$analyticsAttrib === void 0 ? {} : _ref2$analyticsAttrib,
99
+ editorAnalyticsAPI = _ref2.editorAnalyticsAPI,
100
+ insertMediaVia = _ref2.insertMediaVia;
101
+ return function (_ref3) {
102
+ var tr = _ref3.tr;
103
+ var inputMethod = analyticsAttributes.inputMethod,
104
+ fileExtension = analyticsAttributes.fileExtension,
105
+ newType = analyticsAttributes.newType,
106
+ previousType = analyticsAttributes.previousType;
107
+ var updatedTr = tr;
108
+ var openEnd = 0;
109
+ if (tr.selection.empty) {
110
+ var insertFrom = (0, _selection.selectionIsAtTheBeginningOfBlock)(tr.selection) ? tr.selection.$from.before() : tr.selection.from;
111
+
112
+ // the use of pmSafeInsert causes the node selection to media single node.
113
+ // It leads to discrepancy between the full-page and comment editor - not sure why :shrug:
114
+ // When multiple images are uploaded, the node selection is set to the previous node
115
+ // and got overridden by the next node inserted.
116
+ // It also causes the images position shifted when the images are uploaded.
117
+ // E.g the images are uploaded after a table, the images will be inserted inside the table.
118
+ // so we revert to use tr.insert instead. No extra paragraph is added.
119
+ updatedTr = updatedTr.insert(insertFrom, nodes);
120
+ } else {
121
+ updatedTr.replaceSelection(new _model.Slice(_model.Fragment.from(nodes), 0, openEnd));
122
+ }
123
+ if (inputMethod) {
124
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent(getInsertMediaAnalytics(inputMethod, fileExtension, insertMediaVia))(updatedTr);
125
+ }
126
+ if (newType && previousType) {
127
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent((0, _analytics2.getChangeMediaAnalytics)(previousType, newType, (0, _analytics2.findChangeFromLocation)(tr.selection)))(updatedTr);
128
+ }
129
+ return updatedTr;
130
+ };
131
+ }
79
132
  var isMediaSingle = exports.isMediaSingle = function isMediaSingle(schema, fileMimeType) {
80
133
  return !!schema.nodes.mediaSingle && (0, _isType.isImage)(fileMimeType);
81
134
  };
@@ -94,6 +147,16 @@ var insertMediaAsMediaSingle = exports.insertMediaAsMediaSingle = function inser
94
147
  if (node.type !== media || !(0, _isType.isImage)(node.attrs.__fileMimeType) && node.attrs.type !== 'external') {
95
148
  return false;
96
149
  }
150
+ if ((0, _platformFeatureFlags.fg)('platform_editor_introduce_insert_media_command')) {
151
+ var updatedTr = createInsertMediaAsMediaSingleCommand(node.attrs, inputMethod, editorAnalyticsAPI, insertMediaVia, allowPixelResizing)({
152
+ tr: state.tr
153
+ });
154
+ if (updatedTr && dispatch) {
155
+ dispatch === null || dispatch === void 0 || dispatch(updatedTr);
156
+ return true;
157
+ }
158
+ return false;
159
+ }
97
160
  var mediaSingleAttrs = allowPixelResizing ? {
98
161
  widthType: 'pixel',
99
162
  width: (0, _mediaSingle.getMediaSingleInitialWidth)((_node$attrs$width = node.attrs.width) !== null && _node$attrs$width !== void 0 ? _node$attrs$width : _mediaSingle.DEFAULT_IMAGE_WIDTH),
@@ -112,6 +175,42 @@ var insertMediaAsMediaSingle = exports.insertMediaAsMediaSingle = function inser
112
175
  insertMediaVia: insertMediaVia
113
176
  })(state, dispatch);
114
177
  };
178
+ var createInsertMediaAsMediaSingleCommand = exports.createInsertMediaAsMediaSingleCommand = function createInsertMediaAsMediaSingleCommand(mediaAttrs, inputMethod, editorAnalyticsAPI, insertMediaVia, allowPixelResizing) {
179
+ return function (_ref4) {
180
+ var _mediaAttrs$__fileMim, _mediaAttrs$width, _mediaAttrs$__fileMim2;
181
+ var tr = _ref4.tr;
182
+ var _tr$doc$type$schema$n = tr.doc.type.schema.nodes,
183
+ mediaSingle = _tr$doc$type$schema$n.mediaSingle,
184
+ media = _tr$doc$type$schema$n.media;
185
+ if (!mediaSingle || !media) {
186
+ return null;
187
+ }
188
+ if (mediaAttrs.type !== 'external' && !(0, _isType.isImage)((_mediaAttrs$__fileMim = mediaAttrs.__fileMimeType) !== null && _mediaAttrs$__fileMim !== void 0 ? _mediaAttrs$__fileMim : undefined)) {
189
+ return null;
190
+ }
191
+ var mediaSingleAttrs = allowPixelResizing ? {
192
+ widthType: 'pixel',
193
+ width: (0, _mediaSingle.getMediaSingleInitialWidth)((_mediaAttrs$width = mediaAttrs.width) !== null && _mediaAttrs$width !== void 0 ? _mediaAttrs$width : _mediaSingle.DEFAULT_IMAGE_WIDTH),
194
+ layout: 'center'
195
+ } : {};
196
+ var mediaNode = media.create(mediaAttrs);
197
+ var mediaSingleNode = mediaSingle.create(mediaSingleAttrs, mediaNode);
198
+ var nodes = [mediaSingleNode];
199
+ var analyticsAttributes = {
200
+ inputMethod: inputMethod,
201
+ // External images have no file extension
202
+ fileExtension: mediaAttrs.type !== 'external' && mediaAttrs.__fileMimeType ? (_mediaAttrs$__fileMim2 = mediaAttrs.__fileMimeType) !== null && _mediaAttrs$__fileMim2 !== void 0 ? _mediaAttrs$__fileMim2 : undefined : undefined
203
+ };
204
+ return insertNodesWithOptionalParagraphCommand({
205
+ nodes: nodes,
206
+ analyticsAttributes: analyticsAttributes,
207
+ editorAnalyticsAPI: editorAnalyticsAPI,
208
+ insertMediaVia: insertMediaVia
209
+ })({
210
+ tr: tr
211
+ });
212
+ };
213
+ };
115
214
  var getFileExtension = function getFileExtension(fileName) {
116
215
  if (fileName) {
117
216
  var extensionIdx = fileName.lastIndexOf('.');
@@ -225,12 +324,12 @@ var createMediaSingleNode = function createMediaSingleNode(schema, collection, m
225
324
  _mediaState$scaleFact = mediaState.scaleFactor,
226
325
  scaleFactor = _mediaState$scaleFact === void 0 ? 1 : _mediaState$scaleFact,
227
326
  fileName = mediaState.fileName;
228
- var _ref2 = dimensions || {
327
+ var _ref5 = dimensions || {
229
328
  height: undefined,
230
329
  width: undefined
231
330
  },
232
- width = _ref2.width,
233
- height = _ref2.height;
331
+ width = _ref5.width,
332
+ height = _ref5.height;
234
333
  var _schema$nodes = schema.nodes,
235
334
  media = _schema$nodes.media,
236
335
  mediaSingle = _schema$nodes.mediaSingle;
@@ -16,7 +16,7 @@ import { mediaInlineSpecWithFixedToDOM } from './nodeviews/toDOM-fixes/mediaInli
16
16
  import { mediaSingleSpecWithFixedToDOM } from './nodeviews/toDOM-fixes/mediaSingle';
17
17
  import { createPlugin as createMediaAltTextPlugin } from './pm-plugins/alt-text';
18
18
  import keymapMediaAltTextPlugin from './pm-plugins/alt-text/keymap';
19
- import { hideMediaViewer, showMediaViewer, trackMediaPaste } from './pm-plugins/commands';
19
+ import { hideMediaViewer, insertMediaAsMediaSingleCommand, showMediaViewer, trackMediaPaste } from './pm-plugins/commands';
20
20
  import keymapPlugin from './pm-plugins/keymap';
21
21
  import keymapMediaSinglePlugin from './pm-plugins/keymap-media';
22
22
  import linkingPlugin from './pm-plugins/linking';
@@ -103,6 +103,7 @@ export const mediaPlugin = ({
103
103
  config: options = {},
104
104
  api
105
105
  }) => {
106
+ var _api$analytics3;
106
107
  let previousMediaProvider;
107
108
  const mediaErrorLocalIds = new Set();
108
109
  return {
@@ -153,7 +154,8 @@ export const mediaPlugin = ({
153
154
  commands: {
154
155
  showMediaViewer,
155
156
  hideMediaViewer,
156
- trackMediaPaste
157
+ trackMediaPaste,
158
+ insertMediaSingle: insertMediaAsMediaSingleCommand(api === null || api === void 0 ? void 0 : (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions, options.allowPixelResizing)
157
159
  },
158
160
  nodes() {
159
161
  const {
@@ -229,8 +231,8 @@ export const mediaPlugin = ({
229
231
  plugin: ({
230
232
  getIntl
231
233
  }) => {
232
- var _api$analytics3, _api$selection;
233
- return keymapPlugin(options, api === null || api === void 0 ? void 0 : (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions, api === null || api === void 0 ? void 0 : (_api$selection = api.selection) === null || _api$selection === void 0 ? void 0 : _api$selection.actions, api === null || api === void 0 ? void 0 : api.width, getIntl);
234
+ var _api$analytics4, _api$selection;
235
+ return keymapPlugin(options, api === null || api === void 0 ? void 0 : (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions, api === null || api === void 0 ? void 0 : (_api$selection = api.selection) === null || _api$selection === void 0 ? void 0 : _api$selection.actions, api === null || api === void 0 ? void 0 : api.width, getIntl);
234
236
  }
235
237
  }];
236
238
  if (options && options.allowMediaSingle) {
@@ -251,8 +253,8 @@ export const mediaPlugin = ({
251
253
  plugin: ({
252
254
  schema
253
255
  }) => {
254
- var _api$analytics4;
255
- return keymapMediaAltTextPlugin(schema, api === null || api === void 0 ? void 0 : (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions);
256
+ var _api$analytics5;
257
+ return keymapMediaAltTextPlugin(schema, api === null || api === void 0 ? void 0 : (_api$analytics5 = api.analytics) === null || _api$analytics5 === void 0 ? void 0 : _api$analytics5.actions);
256
258
  }
257
259
  });
258
260
  }
@@ -1,6 +1,7 @@
1
1
  import { ACTIONS } from '../pm-plugins/actions';
2
2
  import { stateKey } from '../pm-plugins/plugin-key';
3
3
  import { getIdentifier } from '../pm-plugins/utils/media-common';
4
+ import { createInsertMediaAsMediaSingleCommand } from './utils/media-single';
4
5
  export const showMediaViewer = media => ({
5
6
  tr
6
7
  }) => {
@@ -30,4 +31,5 @@ export const trackMediaPaste = attrs => ({
30
31
  identifier
31
32
  });
32
33
  return tr;
33
- };
34
+ };
35
+ export const insertMediaAsMediaSingleCommand = (editorAnalyticsAPI, allowPixelResizing) => (mediaAttrs, inputMethod, insertMediaVia) => createInsertMediaAsMediaSingleCommand(mediaAttrs, inputMethod, editorAnalyticsAPI, insertMediaVia, allowPixelResizing);
@@ -2,10 +2,11 @@ import memoizeOne from 'memoize-one';
2
2
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
3
3
  import { safeInsert, shouldSplitSelectedNodeOnNodeInsertion } from '@atlaskit/editor-common/insert';
4
4
  import { DEFAULT_IMAGE_WIDTH, getMaxWidthForNestedNodeNext, getMediaSingleInitialWidth, MEDIA_SINGLE_DEFAULT_MIN_PIXEL_WIDTH, MEDIA_SINGLE_VIDEO_MIN_PIXEL_WIDTH } from '@atlaskit/editor-common/media-single';
5
- import { atTheBeginningOfBlock } from '@atlaskit/editor-common/selection';
5
+ import { atTheBeginningOfBlock, selectionIsAtTheBeginningOfBlock } from '@atlaskit/editor-common/selection';
6
6
  import { checkNodeDown, isEmptyParagraph } from '@atlaskit/editor-common/utils';
7
7
  import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
8
8
  import { safeInsert as pmSafeInsert, removeSelectedNode } from '@atlaskit/editor-prosemirror/utils';
9
+ import { fg } from '@atlaskit/platform-feature-flags';
9
10
  import { copyOptionalAttrsFromMediaState } from '../utils/media-common';
10
11
  import { findChangeFromLocation, getChangeMediaAnalytics } from './analytics';
11
12
  import { isImage } from './is-type';
@@ -34,6 +35,21 @@ function insertNodesWithOptionalParagraph({
34
35
  const {
35
36
  tr
36
37
  } = state;
38
+ if (fg('platform_editor_introduce_insert_media_command')) {
39
+ const updatedTr = insertNodesWithOptionalParagraphCommand({
40
+ nodes,
41
+ analyticsAttributes,
42
+ editorAnalyticsAPI,
43
+ insertMediaVia
44
+ })({
45
+ tr
46
+ });
47
+ if (updatedTr && dispatch) {
48
+ dispatch === null || dispatch === void 0 ? void 0 : dispatch(updatedTr);
49
+ return true;
50
+ }
51
+ return false;
52
+ }
37
53
  const {
38
54
  inputMethod,
39
55
  fileExtension,
@@ -68,6 +84,46 @@ function insertNodesWithOptionalParagraph({
68
84
  return true;
69
85
  };
70
86
  }
87
+ function insertNodesWithOptionalParagraphCommand({
88
+ nodes,
89
+ analyticsAttributes = {},
90
+ editorAnalyticsAPI,
91
+ insertMediaVia
92
+ }) {
93
+ return ({
94
+ tr
95
+ }) => {
96
+ const {
97
+ inputMethod,
98
+ fileExtension,
99
+ newType,
100
+ previousType
101
+ } = analyticsAttributes;
102
+ let updatedTr = tr;
103
+ const openEnd = 0;
104
+ if (tr.selection.empty) {
105
+ const insertFrom = selectionIsAtTheBeginningOfBlock(tr.selection) ? tr.selection.$from.before() : tr.selection.from;
106
+
107
+ // the use of pmSafeInsert causes the node selection to media single node.
108
+ // It leads to discrepancy between the full-page and comment editor - not sure why :shrug:
109
+ // When multiple images are uploaded, the node selection is set to the previous node
110
+ // and got overridden by the next node inserted.
111
+ // It also causes the images position shifted when the images are uploaded.
112
+ // E.g the images are uploaded after a table, the images will be inserted inside the table.
113
+ // so we revert to use tr.insert instead. No extra paragraph is added.
114
+ updatedTr = updatedTr.insert(insertFrom, nodes);
115
+ } else {
116
+ updatedTr.replaceSelection(new Slice(Fragment.from(nodes), 0, openEnd));
117
+ }
118
+ if (inputMethod) {
119
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent(getInsertMediaAnalytics(inputMethod, fileExtension, insertMediaVia))(updatedTr);
120
+ }
121
+ if (newType && previousType) {
122
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent(getChangeMediaAnalytics(previousType, newType, findChangeFromLocation(tr.selection)))(updatedTr);
123
+ }
124
+ return updatedTr;
125
+ };
126
+ }
71
127
  export const isMediaSingle = (schema, fileMimeType) => !!schema.nodes.mediaSingle && isImage(fileMimeType);
72
128
  export const insertMediaAsMediaSingle = (view, node, inputMethod, editorAnalyticsAPI, insertMediaVia, allowPixelResizing) => {
73
129
  var _node$attrs$width;
@@ -87,6 +143,16 @@ export const insertMediaAsMediaSingle = (view, node, inputMethod, editorAnalytic
87
143
  if (node.type !== media || !isImage(node.attrs.__fileMimeType) && node.attrs.type !== 'external') {
88
144
  return false;
89
145
  }
146
+ if (fg('platform_editor_introduce_insert_media_command')) {
147
+ const updatedTr = createInsertMediaAsMediaSingleCommand(node.attrs, inputMethod, editorAnalyticsAPI, insertMediaVia, allowPixelResizing)({
148
+ tr: state.tr
149
+ });
150
+ if (updatedTr && dispatch) {
151
+ dispatch === null || dispatch === void 0 ? void 0 : dispatch(updatedTr);
152
+ return true;
153
+ }
154
+ return false;
155
+ }
90
156
  const mediaSingleAttrs = allowPixelResizing ? {
91
157
  widthType: 'pixel',
92
158
  width: getMediaSingleInitialWidth((_node$attrs$width = node.attrs.width) !== null && _node$attrs$width !== void 0 ? _node$attrs$width : DEFAULT_IMAGE_WIDTH),
@@ -105,6 +171,44 @@ export const insertMediaAsMediaSingle = (view, node, inputMethod, editorAnalytic
105
171
  insertMediaVia
106
172
  })(state, dispatch);
107
173
  };
174
+ export const createInsertMediaAsMediaSingleCommand = (mediaAttrs, inputMethod, editorAnalyticsAPI, insertMediaVia, allowPixelResizing) => {
175
+ return ({
176
+ tr
177
+ }) => {
178
+ var _mediaAttrs$__fileMim, _mediaAttrs$width, _mediaAttrs$__fileMim2;
179
+ const {
180
+ mediaSingle,
181
+ media
182
+ } = tr.doc.type.schema.nodes;
183
+ if (!mediaSingle || !media) {
184
+ return null;
185
+ }
186
+ if (mediaAttrs.type !== 'external' && !isImage((_mediaAttrs$__fileMim = mediaAttrs.__fileMimeType) !== null && _mediaAttrs$__fileMim !== void 0 ? _mediaAttrs$__fileMim : undefined)) {
187
+ return null;
188
+ }
189
+ const mediaSingleAttrs = allowPixelResizing ? {
190
+ widthType: 'pixel',
191
+ width: getMediaSingleInitialWidth((_mediaAttrs$width = mediaAttrs.width) !== null && _mediaAttrs$width !== void 0 ? _mediaAttrs$width : DEFAULT_IMAGE_WIDTH),
192
+ layout: 'center'
193
+ } : {};
194
+ const mediaNode = media.create(mediaAttrs);
195
+ const mediaSingleNode = mediaSingle.create(mediaSingleAttrs, mediaNode);
196
+ const nodes = [mediaSingleNode];
197
+ const analyticsAttributes = {
198
+ inputMethod,
199
+ // External images have no file extension
200
+ fileExtension: mediaAttrs.type !== 'external' && mediaAttrs.__fileMimeType ? (_mediaAttrs$__fileMim2 = mediaAttrs.__fileMimeType) !== null && _mediaAttrs$__fileMim2 !== void 0 ? _mediaAttrs$__fileMim2 : undefined : undefined
201
+ };
202
+ return insertNodesWithOptionalParagraphCommand({
203
+ nodes,
204
+ analyticsAttributes,
205
+ editorAnalyticsAPI,
206
+ insertMediaVia
207
+ })({
208
+ tr
209
+ });
210
+ };
211
+ };
108
212
  const getFileExtension = fileName => {
109
213
  if (fileName) {
110
214
  const extensionIdx = fileName.lastIndexOf('.');
@@ -16,7 +16,7 @@ import { mediaInlineSpecWithFixedToDOM } from './nodeviews/toDOM-fixes/mediaInli
16
16
  import { mediaSingleSpecWithFixedToDOM } from './nodeviews/toDOM-fixes/mediaSingle';
17
17
  import { createPlugin as createMediaAltTextPlugin } from './pm-plugins/alt-text';
18
18
  import keymapMediaAltTextPlugin from './pm-plugins/alt-text/keymap';
19
- import { hideMediaViewer, showMediaViewer, trackMediaPaste } from './pm-plugins/commands';
19
+ import { hideMediaViewer, insertMediaAsMediaSingleCommand, showMediaViewer, trackMediaPaste } from './pm-plugins/commands';
20
20
  import keymapPlugin from './pm-plugins/keymap';
21
21
  import keymapMediaSinglePlugin from './pm-plugins/keymap-media';
22
22
  import linkingPlugin from './pm-plugins/linking';
@@ -96,6 +96,7 @@ var MediaViewerFunctionalComponent = function MediaViewerFunctionalComponent(_re
96
96
  });
97
97
  };
98
98
  export var mediaPlugin = function mediaPlugin(_ref3) {
99
+ var _api$analytics3;
99
100
  var _ref3$config = _ref3.config,
100
101
  options = _ref3$config === void 0 ? {} : _ref3$config,
101
102
  api = _ref3.api;
@@ -150,7 +151,8 @@ export var mediaPlugin = function mediaPlugin(_ref3) {
150
151
  commands: {
151
152
  showMediaViewer: showMediaViewer,
152
153
  hideMediaViewer: hideMediaViewer,
153
- trackMediaPaste: trackMediaPaste
154
+ trackMediaPaste: trackMediaPaste,
155
+ insertMediaSingle: insertMediaAsMediaSingleCommand(api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions, options.allowPixelResizing)
154
156
  },
155
157
  nodes: function nodes() {
156
158
  var _ref5 = options || {},
@@ -225,9 +227,9 @@ export var mediaPlugin = function mediaPlugin(_ref3) {
225
227
  }, {
226
228
  name: 'mediaKeymap',
227
229
  plugin: function plugin(_ref7) {
228
- var _api$analytics3, _api$selection;
230
+ var _api$analytics4, _api$selection;
229
231
  var getIntl = _ref7.getIntl;
230
- return keymapPlugin(options, api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions, api === null || api === void 0 || (_api$selection = api.selection) === null || _api$selection === void 0 ? void 0 : _api$selection.actions, api === null || api === void 0 ? void 0 : api.width, getIntl);
232
+ return keymapPlugin(options, api === null || api === void 0 || (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions, api === null || api === void 0 || (_api$selection = api.selection) === null || _api$selection === void 0 ? void 0 : _api$selection.actions, api === null || api === void 0 ? void 0 : api.width, getIntl);
231
233
  }
232
234
  }];
233
235
  if (options && options.allowMediaSingle) {
@@ -247,9 +249,9 @@ export var mediaPlugin = function mediaPlugin(_ref3) {
247
249
  pmPlugins.push({
248
250
  name: 'mediaAltTextKeymap',
249
251
  plugin: function plugin(_ref9) {
250
- var _api$analytics4;
252
+ var _api$analytics5;
251
253
  var schema = _ref9.schema;
252
- return keymapMediaAltTextPlugin(schema, api === null || api === void 0 || (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions);
254
+ return keymapMediaAltTextPlugin(schema, api === null || api === void 0 || (_api$analytics5 = api.analytics) === null || _api$analytics5 === void 0 ? void 0 : _api$analytics5.actions);
253
255
  }
254
256
  });
255
257
  }
@@ -1,6 +1,7 @@
1
1
  import { ACTIONS } from '../pm-plugins/actions';
2
2
  import { stateKey } from '../pm-plugins/plugin-key';
3
3
  import { getIdentifier } from '../pm-plugins/utils/media-common';
4
+ import { createInsertMediaAsMediaSingleCommand } from './utils/media-single';
4
5
  export var showMediaViewer = function showMediaViewer(media) {
5
6
  return function (_ref) {
6
7
  var tr = _ref.tr;
@@ -31,4 +32,9 @@ export var trackMediaPaste = function trackMediaPaste(attrs) {
31
32
  });
32
33
  return tr;
33
34
  };
35
+ };
36
+ export var insertMediaAsMediaSingleCommand = function insertMediaAsMediaSingleCommand(editorAnalyticsAPI, allowPixelResizing) {
37
+ return function (mediaAttrs, inputMethod, insertMediaVia) {
38
+ return createInsertMediaAsMediaSingleCommand(mediaAttrs, inputMethod, editorAnalyticsAPI, insertMediaVia, allowPixelResizing);
39
+ };
34
40
  };
@@ -5,10 +5,11 @@ import memoizeOne from 'memoize-one';
5
5
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
6
6
  import { safeInsert, shouldSplitSelectedNodeOnNodeInsertion } from '@atlaskit/editor-common/insert';
7
7
  import { DEFAULT_IMAGE_WIDTH, getMaxWidthForNestedNodeNext, getMediaSingleInitialWidth, MEDIA_SINGLE_DEFAULT_MIN_PIXEL_WIDTH, MEDIA_SINGLE_VIDEO_MIN_PIXEL_WIDTH } from '@atlaskit/editor-common/media-single';
8
- import { atTheBeginningOfBlock } from '@atlaskit/editor-common/selection';
8
+ import { atTheBeginningOfBlock, selectionIsAtTheBeginningOfBlock } from '@atlaskit/editor-common/selection';
9
9
  import { checkNodeDown, isEmptyParagraph } from '@atlaskit/editor-common/utils';
10
10
  import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
11
11
  import { safeInsert as pmSafeInsert, removeSelectedNode } from '@atlaskit/editor-prosemirror/utils';
12
+ import { fg } from '@atlaskit/platform-feature-flags';
12
13
  import { copyOptionalAttrsFromMediaState } from '../utils/media-common';
13
14
  import { findChangeFromLocation, getChangeMediaAnalytics } from './analytics';
14
15
  import { isImage } from './is-type';
@@ -37,6 +38,21 @@ function insertNodesWithOptionalParagraph(_ref) {
37
38
  insertMediaVia = _ref.insertMediaVia;
38
39
  return function (state, dispatch) {
39
40
  var tr = state.tr;
41
+ if (fg('platform_editor_introduce_insert_media_command')) {
42
+ var _updatedTr = insertNodesWithOptionalParagraphCommand({
43
+ nodes: nodes,
44
+ analyticsAttributes: analyticsAttributes,
45
+ editorAnalyticsAPI: editorAnalyticsAPI,
46
+ insertMediaVia: insertMediaVia
47
+ })({
48
+ tr: tr
49
+ });
50
+ if (_updatedTr && dispatch) {
51
+ dispatch === null || dispatch === void 0 || dispatch(_updatedTr);
52
+ return true;
53
+ }
54
+ return false;
55
+ }
40
56
  var inputMethod = analyticsAttributes.inputMethod,
41
57
  fileExtension = analyticsAttributes.fileExtension,
42
58
  newType = analyticsAttributes.newType,
@@ -69,6 +85,43 @@ function insertNodesWithOptionalParagraph(_ref) {
69
85
  return true;
70
86
  };
71
87
  }
88
+ function insertNodesWithOptionalParagraphCommand(_ref2) {
89
+ var nodes = _ref2.nodes,
90
+ _ref2$analyticsAttrib = _ref2.analyticsAttributes,
91
+ analyticsAttributes = _ref2$analyticsAttrib === void 0 ? {} : _ref2$analyticsAttrib,
92
+ editorAnalyticsAPI = _ref2.editorAnalyticsAPI,
93
+ insertMediaVia = _ref2.insertMediaVia;
94
+ return function (_ref3) {
95
+ var tr = _ref3.tr;
96
+ var inputMethod = analyticsAttributes.inputMethod,
97
+ fileExtension = analyticsAttributes.fileExtension,
98
+ newType = analyticsAttributes.newType,
99
+ previousType = analyticsAttributes.previousType;
100
+ var updatedTr = tr;
101
+ var openEnd = 0;
102
+ if (tr.selection.empty) {
103
+ var insertFrom = selectionIsAtTheBeginningOfBlock(tr.selection) ? tr.selection.$from.before() : tr.selection.from;
104
+
105
+ // the use of pmSafeInsert causes the node selection to media single node.
106
+ // It leads to discrepancy between the full-page and comment editor - not sure why :shrug:
107
+ // When multiple images are uploaded, the node selection is set to the previous node
108
+ // and got overridden by the next node inserted.
109
+ // It also causes the images position shifted when the images are uploaded.
110
+ // E.g the images are uploaded after a table, the images will be inserted inside the table.
111
+ // so we revert to use tr.insert instead. No extra paragraph is added.
112
+ updatedTr = updatedTr.insert(insertFrom, nodes);
113
+ } else {
114
+ updatedTr.replaceSelection(new Slice(Fragment.from(nodes), 0, openEnd));
115
+ }
116
+ if (inputMethod) {
117
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent(getInsertMediaAnalytics(inputMethod, fileExtension, insertMediaVia))(updatedTr);
118
+ }
119
+ if (newType && previousType) {
120
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent(getChangeMediaAnalytics(previousType, newType, findChangeFromLocation(tr.selection)))(updatedTr);
121
+ }
122
+ return updatedTr;
123
+ };
124
+ }
72
125
  export var isMediaSingle = function isMediaSingle(schema, fileMimeType) {
73
126
  return !!schema.nodes.mediaSingle && isImage(fileMimeType);
74
127
  };
@@ -87,6 +140,16 @@ export var insertMediaAsMediaSingle = function insertMediaAsMediaSingle(view, no
87
140
  if (node.type !== media || !isImage(node.attrs.__fileMimeType) && node.attrs.type !== 'external') {
88
141
  return false;
89
142
  }
143
+ if (fg('platform_editor_introduce_insert_media_command')) {
144
+ var updatedTr = createInsertMediaAsMediaSingleCommand(node.attrs, inputMethod, editorAnalyticsAPI, insertMediaVia, allowPixelResizing)({
145
+ tr: state.tr
146
+ });
147
+ if (updatedTr && dispatch) {
148
+ dispatch === null || dispatch === void 0 || dispatch(updatedTr);
149
+ return true;
150
+ }
151
+ return false;
152
+ }
90
153
  var mediaSingleAttrs = allowPixelResizing ? {
91
154
  widthType: 'pixel',
92
155
  width: getMediaSingleInitialWidth((_node$attrs$width = node.attrs.width) !== null && _node$attrs$width !== void 0 ? _node$attrs$width : DEFAULT_IMAGE_WIDTH),
@@ -105,6 +168,42 @@ export var insertMediaAsMediaSingle = function insertMediaAsMediaSingle(view, no
105
168
  insertMediaVia: insertMediaVia
106
169
  })(state, dispatch);
107
170
  };
171
+ export var createInsertMediaAsMediaSingleCommand = function createInsertMediaAsMediaSingleCommand(mediaAttrs, inputMethod, editorAnalyticsAPI, insertMediaVia, allowPixelResizing) {
172
+ return function (_ref4) {
173
+ var _mediaAttrs$__fileMim, _mediaAttrs$width, _mediaAttrs$__fileMim2;
174
+ var tr = _ref4.tr;
175
+ var _tr$doc$type$schema$n = tr.doc.type.schema.nodes,
176
+ mediaSingle = _tr$doc$type$schema$n.mediaSingle,
177
+ media = _tr$doc$type$schema$n.media;
178
+ if (!mediaSingle || !media) {
179
+ return null;
180
+ }
181
+ if (mediaAttrs.type !== 'external' && !isImage((_mediaAttrs$__fileMim = mediaAttrs.__fileMimeType) !== null && _mediaAttrs$__fileMim !== void 0 ? _mediaAttrs$__fileMim : undefined)) {
182
+ return null;
183
+ }
184
+ var mediaSingleAttrs = allowPixelResizing ? {
185
+ widthType: 'pixel',
186
+ width: getMediaSingleInitialWidth((_mediaAttrs$width = mediaAttrs.width) !== null && _mediaAttrs$width !== void 0 ? _mediaAttrs$width : DEFAULT_IMAGE_WIDTH),
187
+ layout: 'center'
188
+ } : {};
189
+ var mediaNode = media.create(mediaAttrs);
190
+ var mediaSingleNode = mediaSingle.create(mediaSingleAttrs, mediaNode);
191
+ var nodes = [mediaSingleNode];
192
+ var analyticsAttributes = {
193
+ inputMethod: inputMethod,
194
+ // External images have no file extension
195
+ fileExtension: mediaAttrs.type !== 'external' && mediaAttrs.__fileMimeType ? (_mediaAttrs$__fileMim2 = mediaAttrs.__fileMimeType) !== null && _mediaAttrs$__fileMim2 !== void 0 ? _mediaAttrs$__fileMim2 : undefined : undefined
196
+ };
197
+ return insertNodesWithOptionalParagraphCommand({
198
+ nodes: nodes,
199
+ analyticsAttributes: analyticsAttributes,
200
+ editorAnalyticsAPI: editorAnalyticsAPI,
201
+ insertMediaVia: insertMediaVia
202
+ })({
203
+ tr: tr
204
+ });
205
+ };
206
+ };
108
207
  var getFileExtension = function getFileExtension(fileName) {
109
208
  if (fileName) {
110
209
  var extensionIdx = fileName.lastIndexOf('.');
@@ -218,12 +317,12 @@ var createMediaSingleNode = function createMediaSingleNode(schema, collection, m
218
317
  _mediaState$scaleFact = mediaState.scaleFactor,
219
318
  scaleFactor = _mediaState$scaleFact === void 0 ? 1 : _mediaState$scaleFact,
220
319
  fileName = mediaState.fileName;
221
- var _ref2 = dimensions || {
320
+ var _ref5 = dimensions || {
222
321
  height: undefined,
223
322
  width: undefined
224
323
  },
225
- width = _ref2.width,
226
- height = _ref2.height;
324
+ width = _ref5.width,
325
+ height = _ref5.height;
227
326
  var _schema$nodes = schema.nodes,
228
327
  media = _schema$nodes.media,
229
328
  mediaSingle = _schema$nodes.mediaSingle;
@@ -1,4 +1,5 @@
1
1
  import type { MediaADFAttrs } from '@atlaskit/adf-schema';
2
+ import type { InputMethodInsertMedia, InsertMediaVia } from '@atlaskit/editor-common/analytics';
2
3
  import type { MediaProvider } from '@atlaskit/editor-common/provider-factory';
3
4
  import type { EditorCommand, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
4
5
  import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
@@ -48,6 +49,11 @@ export type MediaNextEditorPluginType = NextEditorPlugin<'media', {
48
49
  * Callback to be called when there is an error rendering a media node.
49
50
  */
50
51
  handleMediaNodeRenderError: (node: PMNode, reason: string) => void;
52
+ /**
53
+ * @private
54
+ * @deprecated Use the command `insertMediaSingle` instead which is decoupled from EditorView
55
+ * and easier to use.
56
+ */
51
57
  insertMediaAsMediaSingle: InsertMediaAsMediaSingle;
52
58
  /**
53
59
  * Used to update the initial provider passed to the media plugin.
@@ -62,6 +68,15 @@ export type MediaNextEditorPluginType = NextEditorPlugin<'media', {
62
68
  };
63
69
  commands: {
64
70
  hideMediaViewer: EditorCommand;
71
+ /**
72
+ * Inserts a media node as a media single.
73
+ * This command creates a media single node from a set of attributes
74
+ *
75
+ * @param attrs - The media node attributes of the node to insert
76
+ * @param inputMethod - The method used to input the media
77
+ * @param insertMediaVia - Optional parameter indicating how the media was inserted
78
+ */
79
+ insertMediaSingle: (attrs: MediaADFAttrs, inputMethod: InputMethodInsertMedia, insertMediaVia?: InsertMediaVia) => EditorCommand;
65
80
  showMediaViewer: (media: MediaADFAttrs) => EditorCommand;
66
81
  trackMediaPaste: (attrs: MediaADFAttrs) => EditorCommand;
67
82
  };
@@ -1,5 +1,7 @@
1
1
  import type { MediaADFAttrs } from '@atlaskit/adf-schema';
2
+ import type { EditorAnalyticsAPI, InputMethodInsertMedia, InsertMediaVia } from '@atlaskit/editor-common/analytics';
2
3
  import type { EditorCommand } from '@atlaskit/editor-common/types';
3
4
  export declare const showMediaViewer: (media: MediaADFAttrs) => EditorCommand;
4
5
  export declare const hideMediaViewer: EditorCommand;
5
6
  export declare const trackMediaPaste: (attrs: MediaADFAttrs) => EditorCommand;
7
+ export declare const insertMediaAsMediaSingleCommand: (editorAnalyticsAPI?: EditorAnalyticsAPI, allowPixelResizing?: boolean) => (mediaAttrs: MediaADFAttrs, inputMethod: InputMethodInsertMedia, insertMediaVia?: InsertMediaVia) => EditorCommand;
@@ -1,12 +1,14 @@
1
+ import type { MediaADFAttrs } from '@atlaskit/adf-schema';
1
2
  import type { EditorAnalyticsAPI, InputMethodInsertMedia } from '@atlaskit/editor-common/analytics';
2
3
  import { type InsertMediaVia } from '@atlaskit/editor-common/analytics';
3
- import type { EditorContainerWidth as WidthPluginState } from '@atlaskit/editor-common/types';
4
+ import type { EditorCommand, EditorContainerWidth as WidthPluginState } from '@atlaskit/editor-common/types';
4
5
  import type { Node as PMNode, Schema } from '@atlaskit/editor-prosemirror/model';
5
6
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
6
7
  import type { MediaState } from '../../types';
7
8
  export declare const isMediaSingle: (schema: Schema, fileMimeType?: string) => boolean;
8
9
  export type InsertMediaAsMediaSingle = (view: EditorView, node: PMNode, inputMethod: InputMethodInsertMedia, insertMediaVia?: InsertMediaVia, allowPixelResizing?: boolean) => boolean;
9
10
  export declare const insertMediaAsMediaSingle: (view: EditorView, node: PMNode, inputMethod: InputMethodInsertMedia, editorAnalyticsAPI: EditorAnalyticsAPI | undefined, insertMediaVia?: InsertMediaVia, allowPixelResizing?: boolean) => boolean;
11
+ export declare const createInsertMediaAsMediaSingleCommand: (mediaAttrs: MediaADFAttrs, inputMethod: InputMethodInsertMedia, editorAnalyticsAPI: EditorAnalyticsAPI | undefined, insertMediaVia?: InsertMediaVia, allowPixelResizing?: boolean) => EditorCommand;
10
12
  export declare const insertMediaSingleNode: (view: EditorView, mediaState: MediaState, inputMethod?: InputMethodInsertMedia, collection?: string, alignLeftOnInsert?: boolean, widthPluginState?: WidthPluginState | undefined, editorAnalyticsAPI?: EditorAnalyticsAPI | undefined, onNodeInserted?: (id: string, selectionPosition: number) => void, insertMediaVia?: InsertMediaVia, allowPixelResizing?: boolean) => boolean;
11
13
  export declare const changeFromMediaInlineToMediaSingleNode: (view: EditorView, fromNode: PMNode, widthPluginState?: WidthPluginState | undefined, editorAnalyticsAPI?: EditorAnalyticsAPI | undefined, allowPixelResizing?: boolean) => boolean;
12
14
  export declare const isVideo: import("memoize-one").MemoizedFn<(fileType?: string) => boolean>;
@@ -1,4 +1,5 @@
1
1
  import type { MediaADFAttrs } from '@atlaskit/adf-schema';
2
+ import type { InputMethodInsertMedia, InsertMediaVia } from '@atlaskit/editor-common/analytics';
2
3
  import type { MediaProvider } from '@atlaskit/editor-common/provider-factory';
3
4
  import type { EditorCommand, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
4
5
  import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
@@ -48,6 +49,11 @@ export type MediaNextEditorPluginType = NextEditorPlugin<'media', {
48
49
  * Callback to be called when there is an error rendering a media node.
49
50
  */
50
51
  handleMediaNodeRenderError: (node: PMNode, reason: string) => void;
52
+ /**
53
+ * @private
54
+ * @deprecated Use the command `insertMediaSingle` instead which is decoupled from EditorView
55
+ * and easier to use.
56
+ */
51
57
  insertMediaAsMediaSingle: InsertMediaAsMediaSingle;
52
58
  /**
53
59
  * Used to update the initial provider passed to the media plugin.
@@ -62,6 +68,15 @@ export type MediaNextEditorPluginType = NextEditorPlugin<'media', {
62
68
  };
63
69
  commands: {
64
70
  hideMediaViewer: EditorCommand;
71
+ /**
72
+ * Inserts a media node as a media single.
73
+ * This command creates a media single node from a set of attributes
74
+ *
75
+ * @param attrs - The media node attributes of the node to insert
76
+ * @param inputMethod - The method used to input the media
77
+ * @param insertMediaVia - Optional parameter indicating how the media was inserted
78
+ */
79
+ insertMediaSingle: (attrs: MediaADFAttrs, inputMethod: InputMethodInsertMedia, insertMediaVia?: InsertMediaVia) => EditorCommand;
65
80
  showMediaViewer: (media: MediaADFAttrs) => EditorCommand;
66
81
  trackMediaPaste: (attrs: MediaADFAttrs) => EditorCommand;
67
82
  };
@@ -1,5 +1,7 @@
1
1
  import type { MediaADFAttrs } from '@atlaskit/adf-schema';
2
+ import type { EditorAnalyticsAPI, InputMethodInsertMedia, InsertMediaVia } from '@atlaskit/editor-common/analytics';
2
3
  import type { EditorCommand } from '@atlaskit/editor-common/types';
3
4
  export declare const showMediaViewer: (media: MediaADFAttrs) => EditorCommand;
4
5
  export declare const hideMediaViewer: EditorCommand;
5
6
  export declare const trackMediaPaste: (attrs: MediaADFAttrs) => EditorCommand;
7
+ export declare const insertMediaAsMediaSingleCommand: (editorAnalyticsAPI?: EditorAnalyticsAPI, allowPixelResizing?: boolean) => (mediaAttrs: MediaADFAttrs, inputMethod: InputMethodInsertMedia, insertMediaVia?: InsertMediaVia) => EditorCommand;
@@ -1,12 +1,14 @@
1
+ import type { MediaADFAttrs } from '@atlaskit/adf-schema';
1
2
  import type { EditorAnalyticsAPI, InputMethodInsertMedia } from '@atlaskit/editor-common/analytics';
2
3
  import { type InsertMediaVia } from '@atlaskit/editor-common/analytics';
3
- import type { EditorContainerWidth as WidthPluginState } from '@atlaskit/editor-common/types';
4
+ import type { EditorCommand, EditorContainerWidth as WidthPluginState } from '@atlaskit/editor-common/types';
4
5
  import type { Node as PMNode, Schema } from '@atlaskit/editor-prosemirror/model';
5
6
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
6
7
  import type { MediaState } from '../../types';
7
8
  export declare const isMediaSingle: (schema: Schema, fileMimeType?: string) => boolean;
8
9
  export type InsertMediaAsMediaSingle = (view: EditorView, node: PMNode, inputMethod: InputMethodInsertMedia, insertMediaVia?: InsertMediaVia, allowPixelResizing?: boolean) => boolean;
9
10
  export declare const insertMediaAsMediaSingle: (view: EditorView, node: PMNode, inputMethod: InputMethodInsertMedia, editorAnalyticsAPI: EditorAnalyticsAPI | undefined, insertMediaVia?: InsertMediaVia, allowPixelResizing?: boolean) => boolean;
11
+ export declare const createInsertMediaAsMediaSingleCommand: (mediaAttrs: MediaADFAttrs, inputMethod: InputMethodInsertMedia, editorAnalyticsAPI: EditorAnalyticsAPI | undefined, insertMediaVia?: InsertMediaVia, allowPixelResizing?: boolean) => EditorCommand;
10
12
  export declare const insertMediaSingleNode: (view: EditorView, mediaState: MediaState, inputMethod?: InputMethodInsertMedia, collection?: string, alignLeftOnInsert?: boolean, widthPluginState?: WidthPluginState | undefined, editorAnalyticsAPI?: EditorAnalyticsAPI | undefined, onNodeInserted?: (id: string, selectionPosition: number) => void, insertMediaVia?: InsertMediaVia, allowPixelResizing?: boolean) => boolean;
11
13
  export declare const changeFromMediaInlineToMediaSingleNode: (view: EditorView, fromNode: PMNode, widthPluginState?: WidthPluginState | undefined, editorAnalyticsAPI?: EditorAnalyticsAPI | undefined, allowPixelResizing?: boolean) => boolean;
12
14
  export declare const isVideo: import("memoize-one").MemoizedFn<(fileType?: string) => boolean>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-media",
3
- "version": "9.1.1",
3
+ "version": "9.2.0",
4
4
  "description": "Media plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -66,8 +66,8 @@
66
66
  "@atlaskit/primitives": "^17.0.0",
67
67
  "@atlaskit/textfield": "^8.2.0",
68
68
  "@atlaskit/theme": "^21.0.0",
69
- "@atlaskit/tmp-editor-statsig": "^16.4.0",
70
- "@atlaskit/tokens": "^9.0.0",
69
+ "@atlaskit/tmp-editor-statsig": "^16.8.0",
70
+ "@atlaskit/tokens": "^9.1.0",
71
71
  "@atlaskit/tooltip": "^20.11.0",
72
72
  "@babel/runtime": "^7.0.0",
73
73
  "@emotion/react": "^11.7.1",
@@ -78,7 +78,7 @@
78
78
  "uuid": "^3.1.0"
79
79
  },
80
80
  "peerDependencies": {
81
- "@atlaskit/editor-common": "^111.2.0",
81
+ "@atlaskit/editor-common": "^111.5.0",
82
82
  "@atlaskit/media-core": "^37.0.0",
83
83
  "react": "^18.2.0",
84
84
  "react-dom": "^18.2.0",
@@ -133,6 +133,9 @@
133
133
  "platform-visual-refresh-icons": {
134
134
  "type": "boolean"
135
135
  },
136
+ "platform_editor_introduce_insert_media_command": {
137
+ "type": "boolean"
138
+ },
136
139
  "confluence_frontend_media_scroll_fix": {
137
140
  "type": "boolean"
138
141
  },