@atlaskit/editor-core 185.14.2 → 185.14.3

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 (39) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/cjs/plugins/image-upload/pm-plugins/commands.js +1 -1
  3. package/dist/cjs/plugins/image-upload/pm-plugins/main.js +56 -28
  4. package/dist/cjs/utils/clipboard.js +7 -1
  5. package/dist/cjs/utils/drag-drop.js +6 -0
  6. package/dist/cjs/version-wrapper.js +1 -1
  7. package/dist/cjs/version.json +1 -1
  8. package/dist/es2019/plugins/image-upload/pm-plugins/commands.js +1 -1
  9. package/dist/es2019/plugins/image-upload/pm-plugins/main.js +54 -28
  10. package/dist/es2019/utils/clipboard.js +3 -0
  11. package/dist/es2019/utils/drag-drop.js +2 -0
  12. package/dist/es2019/version-wrapper.js +1 -1
  13. package/dist/es2019/version.json +1 -1
  14. package/dist/esm/plugins/image-upload/pm-plugins/commands.js +1 -1
  15. package/dist/esm/plugins/image-upload/pm-plugins/main.js +58 -31
  16. package/dist/esm/utils/clipboard.js +5 -0
  17. package/dist/esm/utils/drag-drop.js +4 -0
  18. package/dist/esm/version-wrapper.js +1 -1
  19. package/dist/esm/version.json +1 -1
  20. package/dist/types/create-editor/get-plugins.d.ts +1 -1
  21. package/dist/types/plugins/image-upload/pm-plugins/actions.d.ts +2 -1
  22. package/dist/types/plugins/image-upload/pm-plugins/commands.d.ts +3 -2
  23. package/dist/types/plugins/image-upload/pm-plugins/main.d.ts +1 -1
  24. package/dist/types/plugins/image-upload/types.d.ts +3 -2
  25. package/dist/types/plugins/insert-block/ui/ToolbarInsertBlock/types.d.ts +2 -2
  26. package/dist/types/plugins/media/nodeviews/mediaSingle.d.ts +2 -2
  27. package/dist/types/utils/clipboard.d.ts +1 -0
  28. package/dist/types/utils/drag-drop.d.ts +1 -0
  29. package/dist/types-ts4.5/create-editor/get-plugins.d.ts +1 -1
  30. package/dist/types-ts4.5/plugins/image-upload/pm-plugins/actions.d.ts +2 -1
  31. package/dist/types-ts4.5/plugins/image-upload/pm-plugins/commands.d.ts +3 -2
  32. package/dist/types-ts4.5/plugins/image-upload/pm-plugins/main.d.ts +1 -1
  33. package/dist/types-ts4.5/plugins/image-upload/types.d.ts +3 -2
  34. package/dist/types-ts4.5/plugins/insert-block/ui/ToolbarInsertBlock/types.d.ts +2 -2
  35. package/dist/types-ts4.5/plugins/media/nodeviews/mediaSingle.d.ts +2 -2
  36. package/dist/types-ts4.5/utils/clipboard.d.ts +1 -0
  37. package/dist/types-ts4.5/utils/drag-drop.d.ts +1 -0
  38. package/package.json +1 -1
  39. package/report.api.md +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @atlaskit/editor-core
2
2
 
3
+ ## 185.14.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [`b8d84a1ffcd`](https://bitbucket.org/atlassian/atlassian-frontend/commits/b8d84a1ffcd) - [ux] ED-17632 disable table resizer when nested
8
+ - [`f188d9ea397`](https://bitbucket.org/atlassian/atlassian-frontend/commits/f188d9ea397) - Create reference event for legacy image upload so DataTransfer is not lost
9
+ - [`ade972c0252`](https://bitbucket.org/atlassian/atlassian-frontend/commits/ade972c0252) - Remove stopPropagation from paste image plugin main
10
+
3
11
  ## 185.14.2
4
12
 
5
13
  ### Patch Changes
@@ -28,7 +28,7 @@ exports.insertExternalImage = insertExternalImage;
28
28
  var startImageUpload = function startImageUpload(event) {
29
29
  return function (state, dispatch) {
30
30
  var pluginState = _pluginKey.stateKey.getState(state);
31
- if (!(pluginState !== null && pluginState !== void 0 && pluginState.enabled)) {
31
+ if (pluginState && !pluginState.enabled) {
32
32
  return false;
33
33
  }
34
34
  if (dispatch) {
@@ -48,16 +48,54 @@ var hasScreenshotImageFromMSOffice = function hasScreenshotImageFromMSOffice(ev)
48
48
  var isImagePNG = file.type === 'image/png' && file.name === 'image.png';
49
49
  return isImagePNG && textPlain && isOfficeXMLNamespace;
50
50
  };
51
- var createDOMHandler = function createDOMHandler(pred, eventName) {
51
+ var createReferenceEventFromEvent = function createReferenceEventFromEvent(event) {
52
+ var _event$dataTransfer, _event$clipboardData;
53
+ if (!(0, _dragDrop.isDragEvent)(event) && !(0, _clipboard.isClipboardEvent)(event)) {
54
+ return null;
55
+ }
56
+
57
+ // Get files list and early exit if files is undefined
58
+ var files = (0, _dragDrop.isDragEvent)(event) ? (_event$dataTransfer = event.dataTransfer) === null || _event$dataTransfer === void 0 ? void 0 : _event$dataTransfer.files : (_event$clipboardData = event.clipboardData) === null || _event$clipboardData === void 0 ? void 0 : _event$clipboardData.files;
59
+ if (!files) {
60
+ return null;
61
+ }
62
+
63
+ // Convert filelist into an array
64
+ var filesArray = Array.from(files);
65
+
66
+ // Creating a new DataTransfer object should remove any mutation that could be possible from the original event
67
+ var dataTransfer = filesArray.reduce(function (acc, value) {
68
+ acc.items.add(value);
69
+ return acc;
70
+ }, new DataTransfer());
71
+ return _objectSpread(_objectSpread({
72
+ type: (0, _dragDrop.isDragEvent)(event) ? 'drop' : 'paste'
73
+ }, (0, _dragDrop.isDragEvent)(event) && {
74
+ dataTransfer: dataTransfer
75
+ }), (0, _clipboard.isClipboardEvent)(event) && {
76
+ clipboardData: dataTransfer
77
+ });
78
+ };
79
+ var createDOMHandler = function createDOMHandler(pred, _eventName, uploadHandlerReference) {
52
80
  return function (view, event) {
53
81
  if (!pred(event)) {
54
82
  return false;
55
83
  }
56
84
  var shouldUpload = !hasScreenshotImageFromMSOffice(event);
57
- if (shouldUpload) {
85
+ var referenceEvent = createReferenceEventFromEvent(event);
86
+ if (shouldUpload && referenceEvent) {
58
87
  event.preventDefault();
59
88
  event.stopPropagation();
60
- (0, _commands.startImageUpload)(event)(view.state, view.dispatch);
89
+
90
+ // Insert external image into document
91
+ if (uploadHandlerReference.current) {
92
+ uploadHandlerReference.current(referenceEvent, function (options) {
93
+ (0, _commands.insertExternalImage)(options)(view.state, view.dispatch);
94
+ });
95
+ }
96
+
97
+ // Start image upload
98
+ (0, _commands.startImageUpload)(referenceEvent)(view.state, view.dispatch);
61
99
  }
62
100
  return shouldUpload;
63
101
  };
@@ -74,7 +112,9 @@ var getNewActiveUpload = function getNewActiveUpload(tr, pluginState) {
74
112
  var createPlugin = function createPlugin(_ref2) {
75
113
  var dispatch = _ref2.dispatch,
76
114
  providerFactory = _ref2.providerFactory;
77
- var uploadHandler;
115
+ var uploadHandlerReference = {
116
+ current: null
117
+ };
78
118
  return new _safePlugin.SafePlugin({
79
119
  state: {
80
120
  init: function init(_config, state) {
@@ -104,6 +144,7 @@ var createPlugin = function createPlugin(_ref2) {
104
144
  view: function view() {
105
145
  var handleProvider = /*#__PURE__*/function () {
106
146
  var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(name, provider) {
147
+ var imageUploadProvider;
107
148
  return _regenerator.default.wrap(function _callee$(_context) {
108
149
  while (1) switch (_context.prev = _context.next) {
109
150
  case 0:
@@ -117,18 +158,19 @@ var createPlugin = function createPlugin(_ref2) {
117
158
  _context.next = 5;
118
159
  return provider;
119
160
  case 5:
120
- uploadHandler = _context.sent;
121
- _context.next = 11;
161
+ imageUploadProvider = _context.sent;
162
+ uploadHandlerReference.current = imageUploadProvider;
163
+ _context.next = 12;
122
164
  break;
123
- case 8:
124
- _context.prev = 8;
165
+ case 9:
166
+ _context.prev = 9;
125
167
  _context.t0 = _context["catch"](2);
126
- uploadHandler = undefined;
127
- case 11:
168
+ uploadHandlerReference.current = null;
169
+ case 12:
128
170
  case "end":
129
171
  return _context.stop();
130
172
  }
131
- }, _callee, null, [[2, 8]]);
173
+ }, _callee, null, [[2, 9]]);
132
174
  }));
133
175
  return function handleProvider(_x, _x2) {
134
176
  return _ref3.apply(this, arguments);
@@ -136,30 +178,16 @@ var createPlugin = function createPlugin(_ref2) {
136
178
  }();
137
179
  providerFactory.subscribe('imageUploadProvider', handleProvider);
138
180
  return {
139
- update: function update(view, prevState) {
140
- var editorState = view.state;
141
- var currentState = _pluginKey.stateKey.getState(editorState);
142
-
143
- // if we've add a new upload to the state, execute the uploadHandler
144
- var oldState = _pluginKey.stateKey.getState(prevState);
145
- if (currentState.activeUpload !== oldState.activeUpload && currentState.activeUpload && uploadHandler) {
146
- var event = currentState.activeUpload.event;
147
- if (!event || !hasScreenshotImageFromMSOffice(event)) {
148
- uploadHandler(event, function (options) {
149
- return (0, _commands.insertExternalImage)(options)(view.state, view.dispatch);
150
- });
151
- }
152
- }
153
- },
154
181
  destroy: function destroy() {
182
+ uploadHandlerReference.current = null;
155
183
  providerFactory.unsubscribe('imageUploadProvider', handleProvider);
156
184
  }
157
185
  };
158
186
  },
159
187
  props: {
160
188
  handleDOMEvents: {
161
- drop: createDOMHandler(_dragDrop.isDroppedFile, 'atlassian.editor.image.drop'),
162
- paste: createDOMHandler(_clipboard.isPastedFile, 'atlassian.editor.image.paste')
189
+ drop: createDOMHandler(_dragDrop.isDroppedFile, 'atlassian.editor.image.drop', uploadHandlerReference),
190
+ paste: createDOMHandler(_clipboard.isPastedFile, 'atlassian.editor.image.paste', uploadHandlerReference)
163
191
  }
164
192
  }
165
193
  });
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
8
  exports.checkClipboardTypes = checkClipboardTypes;
9
- exports.copyToClipboard = exports.copyHTMLToClipboardPolyfill = exports.copyHTMLToClipboard = void 0;
9
+ exports.isClipboardEvent = exports.copyToClipboard = exports.copyHTMLToClipboardPolyfill = exports.copyHTMLToClipboard = void 0;
10
10
  exports.isPastedFile = isPastedFile;
11
11
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
12
12
  var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
@@ -20,6 +20,12 @@ function checkClipboardTypes(type, item) {
20
20
  };
21
21
  return isDOMStringList(type) ? type.contains(item) : type.indexOf(item) > -1;
22
22
  }
23
+
24
+ // Typeguard Function
25
+ var isClipboardEvent = function isClipboardEvent(event) {
26
+ return 'clipboardData' in event;
27
+ };
28
+ exports.isClipboardEvent = isClipboardEvent;
23
29
  function isPastedFile(rawEvent) {
24
30
  var _ref = rawEvent,
25
31
  clipboardData = _ref.clipboardData;
@@ -3,7 +3,13 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.isDragEvent = void 0;
6
7
  exports.isDroppedFile = isDroppedFile;
8
+ // Typeguard Function
9
+ var isDragEvent = function isDragEvent(event) {
10
+ return 'dataTransfer' in event;
11
+ };
12
+ exports.isDragEvent = isDragEvent;
7
13
  function isDroppedFile(rawEvent) {
8
14
  var e = rawEvent;
9
15
  if (!e.dataTransfer) {
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.version = exports.nextMajorVersion = exports.name = void 0;
7
7
  var name = "@atlaskit/editor-core";
8
8
  exports.name = name;
9
- var version = "185.14.2";
9
+ var version = "185.14.3";
10
10
  exports.version = version;
11
11
  var nextMajorVersion = function nextMajorVersion() {
12
12
  return [Number(version.split('.')[0]) + 1, 0, 0].join('.');
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-core",
3
- "version": "185.14.2",
3
+ "version": "185.14.3",
4
4
  "sideEffects": false
5
5
  }
@@ -18,7 +18,7 @@ export const insertExternalImage = options => (state, dispatch) => {
18
18
  };
19
19
  export const startImageUpload = event => (state, dispatch) => {
20
20
  const pluginState = stateKey.getState(state);
21
- if (!(pluginState !== null && pluginState !== void 0 && pluginState.enabled)) {
21
+ if (pluginState && !pluginState.enabled) {
22
22
  return false;
23
23
  }
24
24
  if (dispatch) {
@@ -1,10 +1,9 @@
1
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
- import { isPastedFile } from '../../../utils/clipboard';
3
- import { isDroppedFile } from '../../../utils/drag-drop';
2
+ import { isClipboardEvent, isPastedFile } from '../../../utils/clipboard';
3
+ import { isDragEvent, isDroppedFile } from '../../../utils/drag-drop';
4
4
  import { canInsertMedia, isMediaSelected } from '../utils';
5
5
  import { insertExternalImage, startImageUpload } from './commands';
6
6
  import { stateKey } from './plugin-key';
7
-
8
7
  /**
9
8
  * Microsoft Office includes a screenshot image when copying text content.
10
9
  *
@@ -38,15 +37,55 @@ const hasScreenshotImageFromMSOffice = ev => {
38
37
  const isImagePNG = file.type === 'image/png' && file.name === 'image.png';
39
38
  return isImagePNG && textPlain && isOfficeXMLNamespace;
40
39
  };
41
- const createDOMHandler = (pred, eventName) => (view, event) => {
40
+ const createReferenceEventFromEvent = event => {
41
+ var _event$dataTransfer, _event$clipboardData;
42
+ if (!isDragEvent(event) && !isClipboardEvent(event)) {
43
+ return null;
44
+ }
45
+
46
+ // Get files list and early exit if files is undefined
47
+ const files = isDragEvent(event) ? (_event$dataTransfer = event.dataTransfer) === null || _event$dataTransfer === void 0 ? void 0 : _event$dataTransfer.files : (_event$clipboardData = event.clipboardData) === null || _event$clipboardData === void 0 ? void 0 : _event$clipboardData.files;
48
+ if (!files) {
49
+ return null;
50
+ }
51
+
52
+ // Convert filelist into an array
53
+ const filesArray = Array.from(files);
54
+
55
+ // Creating a new DataTransfer object should remove any mutation that could be possible from the original event
56
+ const dataTransfer = filesArray.reduce((acc, value) => {
57
+ acc.items.add(value);
58
+ return acc;
59
+ }, new DataTransfer());
60
+ return {
61
+ type: isDragEvent(event) ? 'drop' : 'paste',
62
+ ...(isDragEvent(event) && {
63
+ dataTransfer
64
+ }),
65
+ ...(isClipboardEvent(event) && {
66
+ clipboardData: dataTransfer
67
+ })
68
+ };
69
+ };
70
+ const createDOMHandler = (pred, _eventName, uploadHandlerReference) => (view, event) => {
42
71
  if (!pred(event)) {
43
72
  return false;
44
73
  }
45
74
  const shouldUpload = !hasScreenshotImageFromMSOffice(event);
46
- if (shouldUpload) {
75
+ const referenceEvent = createReferenceEventFromEvent(event);
76
+ if (shouldUpload && referenceEvent) {
47
77
  event.preventDefault();
48
78
  event.stopPropagation();
49
- startImageUpload(event)(view.state, view.dispatch);
79
+
80
+ // Insert external image into document
81
+ if (uploadHandlerReference.current) {
82
+ uploadHandlerReference.current(referenceEvent, options => {
83
+ insertExternalImage(options)(view.state, view.dispatch);
84
+ });
85
+ }
86
+
87
+ // Start image upload
88
+ startImageUpload(referenceEvent)(view.state, view.dispatch);
50
89
  }
51
90
  return shouldUpload;
52
91
  };
@@ -63,7 +102,9 @@ export const createPlugin = ({
63
102
  dispatch,
64
103
  providerFactory
65
104
  }) => {
66
- let uploadHandler;
105
+ let uploadHandlerReference = {
106
+ current: null
107
+ };
67
108
  return new SafePlugin({
68
109
  state: {
69
110
  init(_config, state) {
@@ -97,39 +138,24 @@ export const createPlugin = ({
97
138
  return;
98
139
  }
99
140
  try {
100
- uploadHandler = await provider;
141
+ const imageUploadProvider = await provider;
142
+ uploadHandlerReference.current = imageUploadProvider;
101
143
  } catch (e) {
102
- uploadHandler = undefined;
144
+ uploadHandlerReference.current = null;
103
145
  }
104
146
  };
105
147
  providerFactory.subscribe('imageUploadProvider', handleProvider);
106
148
  return {
107
- update(view, prevState) {
108
- const {
109
- state: editorState
110
- } = view;
111
- const currentState = stateKey.getState(editorState);
112
-
113
- // if we've add a new upload to the state, execute the uploadHandler
114
- const oldState = stateKey.getState(prevState);
115
- if (currentState.activeUpload !== oldState.activeUpload && currentState.activeUpload && uploadHandler) {
116
- const {
117
- event
118
- } = currentState.activeUpload;
119
- if (!event || !hasScreenshotImageFromMSOffice(event)) {
120
- uploadHandler(event, options => insertExternalImage(options)(view.state, view.dispatch));
121
- }
122
- }
123
- },
124
149
  destroy() {
150
+ uploadHandlerReference.current = null;
125
151
  providerFactory.unsubscribe('imageUploadProvider', handleProvider);
126
152
  }
127
153
  };
128
154
  },
129
155
  props: {
130
156
  handleDOMEvents: {
131
- drop: createDOMHandler(isDroppedFile, 'atlassian.editor.image.drop'),
132
- paste: createDOMHandler(isPastedFile, 'atlassian.editor.image.paste')
157
+ drop: createDOMHandler(isDroppedFile, 'atlassian.editor.image.drop', uploadHandlerReference),
158
+ paste: createDOMHandler(isPastedFile, 'atlassian.editor.image.paste', uploadHandlerReference)
133
159
  }
134
160
  }
135
161
  });
@@ -3,6 +3,9 @@ export function checkClipboardTypes(type, item) {
3
3
  const isDOMStringList = t => !t.indexOf && !!t.contains;
4
4
  return isDOMStringList(type) ? type.contains(item) : type.indexOf(item) > -1;
5
5
  }
6
+
7
+ // Typeguard Function
8
+ export const isClipboardEvent = event => 'clipboardData' in event;
6
9
  export function isPastedFile(rawEvent) {
7
10
  const {
8
11
  clipboardData
@@ -1,3 +1,5 @@
1
+ // Typeguard Function
2
+ export const isDragEvent = event => 'dataTransfer' in event;
1
3
  export function isDroppedFile(rawEvent) {
2
4
  const e = rawEvent;
3
5
  if (!e.dataTransfer) {
@@ -1,5 +1,5 @@
1
1
  export const name = "@atlaskit/editor-core";
2
- export const version = "185.14.2";
2
+ export const version = "185.14.3";
3
3
  export const nextMajorVersion = () => {
4
4
  return [Number(version.split('.')[0]) + 1, 0, 0].join('.');
5
5
  };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-core",
3
- "version": "185.14.2",
3
+ "version": "185.14.3",
4
4
  "sideEffects": false
5
5
  }
@@ -21,7 +21,7 @@ export var insertExternalImage = function insertExternalImage(options) {
21
21
  export var startImageUpload = function startImageUpload(event) {
22
22
  return function (state, dispatch) {
23
23
  var pluginState = stateKey.getState(state);
24
- if (!(pluginState !== null && pluginState !== void 0 && pluginState.enabled)) {
24
+ if (pluginState && !pluginState.enabled) {
25
25
  return false;
26
26
  }
27
27
  if (dispatch) {
@@ -4,12 +4,11 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
4
4
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
5
5
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
6
6
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
7
- import { isPastedFile } from '../../../utils/clipboard';
8
- import { isDroppedFile } from '../../../utils/drag-drop';
7
+ import { isClipboardEvent, isPastedFile } from '../../../utils/clipboard';
8
+ import { isDragEvent, isDroppedFile } from '../../../utils/drag-drop';
9
9
  import { canInsertMedia, isMediaSelected } from '../utils';
10
10
  import { insertExternalImage, startImageUpload } from './commands';
11
11
  import { stateKey } from './plugin-key';
12
-
13
12
  /**
14
13
  * Microsoft Office includes a screenshot image when copying text content.
15
14
  *
@@ -42,16 +41,54 @@ var hasScreenshotImageFromMSOffice = function hasScreenshotImageFromMSOffice(ev)
42
41
  var isImagePNG = file.type === 'image/png' && file.name === 'image.png';
43
42
  return isImagePNG && textPlain && isOfficeXMLNamespace;
44
43
  };
45
- var createDOMHandler = function createDOMHandler(pred, eventName) {
44
+ var createReferenceEventFromEvent = function createReferenceEventFromEvent(event) {
45
+ var _event$dataTransfer, _event$clipboardData;
46
+ if (!isDragEvent(event) && !isClipboardEvent(event)) {
47
+ return null;
48
+ }
49
+
50
+ // Get files list and early exit if files is undefined
51
+ var files = isDragEvent(event) ? (_event$dataTransfer = event.dataTransfer) === null || _event$dataTransfer === void 0 ? void 0 : _event$dataTransfer.files : (_event$clipboardData = event.clipboardData) === null || _event$clipboardData === void 0 ? void 0 : _event$clipboardData.files;
52
+ if (!files) {
53
+ return null;
54
+ }
55
+
56
+ // Convert filelist into an array
57
+ var filesArray = Array.from(files);
58
+
59
+ // Creating a new DataTransfer object should remove any mutation that could be possible from the original event
60
+ var dataTransfer = filesArray.reduce(function (acc, value) {
61
+ acc.items.add(value);
62
+ return acc;
63
+ }, new DataTransfer());
64
+ return _objectSpread(_objectSpread({
65
+ type: isDragEvent(event) ? 'drop' : 'paste'
66
+ }, isDragEvent(event) && {
67
+ dataTransfer: dataTransfer
68
+ }), isClipboardEvent(event) && {
69
+ clipboardData: dataTransfer
70
+ });
71
+ };
72
+ var createDOMHandler = function createDOMHandler(pred, _eventName, uploadHandlerReference) {
46
73
  return function (view, event) {
47
74
  if (!pred(event)) {
48
75
  return false;
49
76
  }
50
77
  var shouldUpload = !hasScreenshotImageFromMSOffice(event);
51
- if (shouldUpload) {
78
+ var referenceEvent = createReferenceEventFromEvent(event);
79
+ if (shouldUpload && referenceEvent) {
52
80
  event.preventDefault();
53
81
  event.stopPropagation();
54
- startImageUpload(event)(view.state, view.dispatch);
82
+
83
+ // Insert external image into document
84
+ if (uploadHandlerReference.current) {
85
+ uploadHandlerReference.current(referenceEvent, function (options) {
86
+ insertExternalImage(options)(view.state, view.dispatch);
87
+ });
88
+ }
89
+
90
+ // Start image upload
91
+ startImageUpload(referenceEvent)(view.state, view.dispatch);
55
92
  }
56
93
  return shouldUpload;
57
94
  };
@@ -68,7 +105,9 @@ var getNewActiveUpload = function getNewActiveUpload(tr, pluginState) {
68
105
  export var createPlugin = function createPlugin(_ref2) {
69
106
  var dispatch = _ref2.dispatch,
70
107
  providerFactory = _ref2.providerFactory;
71
- var uploadHandler;
108
+ var uploadHandlerReference = {
109
+ current: null
110
+ };
72
111
  return new SafePlugin({
73
112
  state: {
74
113
  init: function init(_config, state) {
@@ -98,6 +137,7 @@ export var createPlugin = function createPlugin(_ref2) {
98
137
  view: function view() {
99
138
  var handleProvider = /*#__PURE__*/function () {
100
139
  var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(name, provider) {
140
+ var imageUploadProvider;
101
141
  return _regeneratorRuntime.wrap(function _callee$(_context) {
102
142
  while (1) switch (_context.prev = _context.next) {
103
143
  case 0:
@@ -111,18 +151,19 @@ export var createPlugin = function createPlugin(_ref2) {
111
151
  _context.next = 5;
112
152
  return provider;
113
153
  case 5:
114
- uploadHandler = _context.sent;
115
- _context.next = 11;
154
+ imageUploadProvider = _context.sent;
155
+ uploadHandlerReference.current = imageUploadProvider;
156
+ _context.next = 12;
116
157
  break;
117
- case 8:
118
- _context.prev = 8;
158
+ case 9:
159
+ _context.prev = 9;
119
160
  _context.t0 = _context["catch"](2);
120
- uploadHandler = undefined;
121
- case 11:
161
+ uploadHandlerReference.current = null;
162
+ case 12:
122
163
  case "end":
123
164
  return _context.stop();
124
165
  }
125
- }, _callee, null, [[2, 8]]);
166
+ }, _callee, null, [[2, 9]]);
126
167
  }));
127
168
  return function handleProvider(_x, _x2) {
128
169
  return _ref3.apply(this, arguments);
@@ -130,30 +171,16 @@ export var createPlugin = function createPlugin(_ref2) {
130
171
  }();
131
172
  providerFactory.subscribe('imageUploadProvider', handleProvider);
132
173
  return {
133
- update: function update(view, prevState) {
134
- var editorState = view.state;
135
- var currentState = stateKey.getState(editorState);
136
-
137
- // if we've add a new upload to the state, execute the uploadHandler
138
- var oldState = stateKey.getState(prevState);
139
- if (currentState.activeUpload !== oldState.activeUpload && currentState.activeUpload && uploadHandler) {
140
- var event = currentState.activeUpload.event;
141
- if (!event || !hasScreenshotImageFromMSOffice(event)) {
142
- uploadHandler(event, function (options) {
143
- return insertExternalImage(options)(view.state, view.dispatch);
144
- });
145
- }
146
- }
147
- },
148
174
  destroy: function destroy() {
175
+ uploadHandlerReference.current = null;
149
176
  providerFactory.unsubscribe('imageUploadProvider', handleProvider);
150
177
  }
151
178
  };
152
179
  },
153
180
  props: {
154
181
  handleDOMEvents: {
155
- drop: createDOMHandler(isDroppedFile, 'atlassian.editor.image.drop'),
156
- paste: createDOMHandler(isPastedFile, 'atlassian.editor.image.paste')
182
+ drop: createDOMHandler(isDroppedFile, 'atlassian.editor.image.drop', uploadHandlerReference),
183
+ paste: createDOMHandler(isPastedFile, 'atlassian.editor.image.paste', uploadHandlerReference)
157
184
  }
158
185
  }
159
186
  });
@@ -8,6 +8,11 @@ export function checkClipboardTypes(type, item) {
8
8
  };
9
9
  return isDOMStringList(type) ? type.contains(item) : type.indexOf(item) > -1;
10
10
  }
11
+
12
+ // Typeguard Function
13
+ export var isClipboardEvent = function isClipboardEvent(event) {
14
+ return 'clipboardData' in event;
15
+ };
11
16
  export function isPastedFile(rawEvent) {
12
17
  var _ref = rawEvent,
13
18
  clipboardData = _ref.clipboardData;
@@ -1,3 +1,7 @@
1
+ // Typeguard Function
2
+ export var isDragEvent = function isDragEvent(event) {
3
+ return 'dataTransfer' in event;
4
+ };
1
5
  export function isDroppedFile(rawEvent) {
2
6
  var e = rawEvent;
3
7
  if (!e.dataTransfer) {
@@ -1,5 +1,5 @@
1
1
  export var name = "@atlaskit/editor-core";
2
- export var version = "185.14.2";
2
+ export var version = "185.14.3";
3
3
  export var nextMajorVersion = function nextMajorVersion() {
4
4
  return [Number(version.split('.')[0]) + 1, 0, 0].join('.');
5
5
  };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-core",
3
- "version": "185.14.2",
3
+ "version": "185.14.3",
4
4
  "sideEffects": false
5
5
  }
@@ -28,7 +28,7 @@ export type LightPMPlugin = {
28
28
  };
29
29
  export type OnEditorViewStateUpdated = (props: {
30
30
  readonly originalTransaction: Readonly<Transaction>;
31
- readonly transactions: Transaction[];
31
+ readonly transactions: ReadonlyArray<Transaction>;
32
32
  readonly oldEditorState: Readonly<EditorState>;
33
33
  readonly newEditorState: Readonly<EditorState>;
34
34
  }) => void;
@@ -1,2 +1,3 @@
1
1
  import { Transaction } from 'prosemirror-state';
2
- export declare const startUpload: (event: any) => (tr: Transaction) => Transaction;
2
+ import { ImageUploadPluginReferenceEvent } from '@atlaskit/editor-common/types';
3
+ export declare const startUpload: (event?: ImageUploadPluginReferenceEvent) => (tr: Transaction) => Transaction;
@@ -1,4 +1,5 @@
1
1
  import { InsertedImageProperties } from '@atlaskit/editor-common/provider-factory';
2
- import { Command } from '../../../types';
2
+ import type { Command } from '../../../types';
3
+ import { ImageUploadPluginReferenceEvent } from '@atlaskit/editor-common/types';
3
4
  export declare const insertExternalImage: (options: InsertedImageProperties) => Command;
4
- export declare const startImageUpload: (event?: Event) => Command;
5
+ export declare const startImageUpload: (event?: ImageUploadPluginReferenceEvent) => Command;
@@ -1,4 +1,4 @@
1
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
2
  import { ImageUploadPluginState } from '../types';
3
- import { PMPluginFactoryParams } from '../../../types';
3
+ import type { PMPluginFactoryParams } from '../../../types';
4
4
  export declare const createPlugin: ({ dispatch, providerFactory, }: PMPluginFactoryParams) => SafePlugin<ImageUploadPluginState>;
@@ -1,13 +1,14 @@
1
+ import { ImageUploadPluginReferenceEvent } from '@atlaskit/editor-common/types';
1
2
  export type { InsertedImageProperties, ImageUploadProvider as ImageUploadHandler, } from '@atlaskit/editor-common/provider-factory';
2
3
  export type ImageUploadPluginAction = {
3
4
  name: 'START_UPLOAD';
4
- event?: Event;
5
+ event?: ImageUploadPluginReferenceEvent;
5
6
  };
6
7
  export type ImageUploadPluginState = {
7
8
  active: boolean;
8
9
  enabled: boolean;
9
10
  hidden: boolean;
10
11
  activeUpload?: {
11
- event?: Event;
12
+ event?: ImageUploadPluginReferenceEvent;
12
13
  };
13
14
  };
@@ -1,6 +1,6 @@
1
1
  import { INPUT_METHOD } from '../../../analytics/types';
2
2
  import { EditorView } from 'prosemirror-view';
3
- import { EditorActionsOptions as EditorActions, FeatureFlags, ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
+ import { EditorActionsOptions as EditorActions, FeatureFlags, ExtractInjectionAPI, ImageUploadPluginReferenceEvent } from '@atlaskit/editor-common/types';
4
4
  import { Command } from '../../../../types/command';
5
5
  import { EmojiProvider } from '@atlaskit/emoji';
6
6
  import { BlockType } from '../../../block-type/types';
@@ -25,7 +25,7 @@ export interface Props {
25
25
  mediaSupported?: boolean;
26
26
  imageUploadSupported?: boolean;
27
27
  imageUploadEnabled?: boolean;
28
- handleImageUpload?: (event?: Event) => Command;
28
+ handleImageUpload?: (event?: ImageUploadPluginReferenceEvent) => Command;
29
29
  dateEnabled?: boolean;
30
30
  horizontalRuleEnabled?: boolean;
31
31
  placeholderTextEnabled?: boolean;
@@ -2,7 +2,7 @@
2
2
  import { jsx } from '@emotion/react';
3
3
  import React, { Component, MouseEvent } from 'react';
4
4
  import { Node as PMNode } from 'prosemirror-model';
5
- import { EditorView, Decoration } from 'prosemirror-view';
5
+ import { DecorationSource, EditorView, Decoration } from 'prosemirror-view';
6
6
  import { RichMediaLayout as MediaSingleLayout } from '@atlaskit/adf-schema';
7
7
  import { ProviderFactory } from '@atlaskit/editor-common/provider-factory';
8
8
  import type { ContextIdentifierProvider } from '@atlaskit/editor-common/provider-factory';
@@ -56,7 +56,7 @@ declare class MediaSingleNodeView extends ReactNodeView<MediaSingleNodeViewProps
56
56
  checkAndUpdateSelectionType: () => import("@atlaskit/editor-common/utils").SelectedState | null;
57
57
  isNodeSelected: () => boolean;
58
58
  getNodeMediaId(node: PMNode): string | undefined;
59
- update(node: PMNode, decorations: readonly Decoration[], _innerDecorations?: Decoration[], isValidUpdate?: (currentNode: PMNode, newNode: PMNode) => boolean): boolean;
59
+ update(node: PMNode, decorations: readonly Decoration[], _innerDecorations?: DecorationSource, isValidUpdate?: (currentNode: PMNode, newNode: PMNode) => boolean): boolean;
60
60
  render(props: MediaSingleNodeViewProps, forwardRef?: ForwardRef): jsx.JSX.Element;
61
61
  ignoreMutation(): boolean;
62
62
  }
@@ -1,4 +1,5 @@
1
1
  export declare function checkClipboardTypes(type: DOMStringList | ReadonlyArray<string>, item: string): boolean;
2
+ export declare const isClipboardEvent: (event: Event) => event is ClipboardEvent;
2
3
  export declare function isPastedFile(rawEvent: Event): boolean;
3
4
  export declare const copyToClipboard: (textToCopy: string) => Promise<void>;
4
5
  export declare const copyHTMLToClipboard: (elementToCopy: HTMLElement, plainTextToCopy?: string) => Promise<void>;
@@ -1 +1,2 @@
1
+ export declare const isDragEvent: (event: Event) => event is DragEvent;
1
2
  export declare function isDroppedFile(rawEvent: Event): boolean;
@@ -28,7 +28,7 @@ export type LightPMPlugin = {
28
28
  };
29
29
  export type OnEditorViewStateUpdated = (props: {
30
30
  readonly originalTransaction: Readonly<Transaction>;
31
- readonly transactions: Transaction[];
31
+ readonly transactions: ReadonlyArray<Transaction>;
32
32
  readonly oldEditorState: Readonly<EditorState>;
33
33
  readonly newEditorState: Readonly<EditorState>;
34
34
  }) => void;
@@ -1,2 +1,3 @@
1
1
  import { Transaction } from 'prosemirror-state';
2
- export declare const startUpload: (event: any) => (tr: Transaction) => Transaction;
2
+ import { ImageUploadPluginReferenceEvent } from '@atlaskit/editor-common/types';
3
+ export declare const startUpload: (event?: ImageUploadPluginReferenceEvent) => (tr: Transaction) => Transaction;
@@ -1,4 +1,5 @@
1
1
  import { InsertedImageProperties } from '@atlaskit/editor-common/provider-factory';
2
- import { Command } from '../../../types';
2
+ import type { Command } from '../../../types';
3
+ import { ImageUploadPluginReferenceEvent } from '@atlaskit/editor-common/types';
3
4
  export declare const insertExternalImage: (options: InsertedImageProperties) => Command;
4
- export declare const startImageUpload: (event?: Event) => Command;
5
+ export declare const startImageUpload: (event?: ImageUploadPluginReferenceEvent) => Command;
@@ -1,4 +1,4 @@
1
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
2
  import { ImageUploadPluginState } from '../types';
3
- import { PMPluginFactoryParams } from '../../../types';
3
+ import type { PMPluginFactoryParams } from '../../../types';
4
4
  export declare const createPlugin: ({ dispatch, providerFactory, }: PMPluginFactoryParams) => SafePlugin<ImageUploadPluginState>;
@@ -1,13 +1,14 @@
1
+ import { ImageUploadPluginReferenceEvent } from '@atlaskit/editor-common/types';
1
2
  export type { InsertedImageProperties, ImageUploadProvider as ImageUploadHandler, } from '@atlaskit/editor-common/provider-factory';
2
3
  export type ImageUploadPluginAction = {
3
4
  name: 'START_UPLOAD';
4
- event?: Event;
5
+ event?: ImageUploadPluginReferenceEvent;
5
6
  };
6
7
  export type ImageUploadPluginState = {
7
8
  active: boolean;
8
9
  enabled: boolean;
9
10
  hidden: boolean;
10
11
  activeUpload?: {
11
- event?: Event;
12
+ event?: ImageUploadPluginReferenceEvent;
12
13
  };
13
14
  };
@@ -1,6 +1,6 @@
1
1
  import { INPUT_METHOD } from '../../../analytics/types';
2
2
  import { EditorView } from 'prosemirror-view';
3
- import { EditorActionsOptions as EditorActions, FeatureFlags, ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
+ import { EditorActionsOptions as EditorActions, FeatureFlags, ExtractInjectionAPI, ImageUploadPluginReferenceEvent } from '@atlaskit/editor-common/types';
4
4
  import { Command } from '../../../../types/command';
5
5
  import { EmojiProvider } from '@atlaskit/emoji';
6
6
  import { BlockType } from '../../../block-type/types';
@@ -25,7 +25,7 @@ export interface Props {
25
25
  mediaSupported?: boolean;
26
26
  imageUploadSupported?: boolean;
27
27
  imageUploadEnabled?: boolean;
28
- handleImageUpload?: (event?: Event) => Command;
28
+ handleImageUpload?: (event?: ImageUploadPluginReferenceEvent) => Command;
29
29
  dateEnabled?: boolean;
30
30
  horizontalRuleEnabled?: boolean;
31
31
  placeholderTextEnabled?: boolean;
@@ -2,7 +2,7 @@
2
2
  import { jsx } from '@emotion/react';
3
3
  import React, { Component, MouseEvent } from 'react';
4
4
  import { Node as PMNode } from 'prosemirror-model';
5
- import { EditorView, Decoration } from 'prosemirror-view';
5
+ import { DecorationSource, EditorView, Decoration } from 'prosemirror-view';
6
6
  import { RichMediaLayout as MediaSingleLayout } from '@atlaskit/adf-schema';
7
7
  import { ProviderFactory } from '@atlaskit/editor-common/provider-factory';
8
8
  import type { ContextIdentifierProvider } from '@atlaskit/editor-common/provider-factory';
@@ -56,7 +56,7 @@ declare class MediaSingleNodeView extends ReactNodeView<MediaSingleNodeViewProps
56
56
  checkAndUpdateSelectionType: () => import("@atlaskit/editor-common/utils").SelectedState | null;
57
57
  isNodeSelected: () => boolean;
58
58
  getNodeMediaId(node: PMNode): string | undefined;
59
- update(node: PMNode, decorations: readonly Decoration[], _innerDecorations?: Decoration[], isValidUpdate?: (currentNode: PMNode, newNode: PMNode) => boolean): boolean;
59
+ update(node: PMNode, decorations: readonly Decoration[], _innerDecorations?: DecorationSource, isValidUpdate?: (currentNode: PMNode, newNode: PMNode) => boolean): boolean;
60
60
  render(props: MediaSingleNodeViewProps, forwardRef?: ForwardRef): jsx.JSX.Element;
61
61
  ignoreMutation(): boolean;
62
62
  }
@@ -1,4 +1,5 @@
1
1
  export declare function checkClipboardTypes(type: DOMStringList | ReadonlyArray<string>, item: string): boolean;
2
+ export declare const isClipboardEvent: (event: Event) => event is ClipboardEvent;
2
3
  export declare function isPastedFile(rawEvent: Event): boolean;
3
4
  export declare const copyToClipboard: (textToCopy: string) => Promise<void>;
4
5
  export declare const copyHTMLToClipboard: (elementToCopy: HTMLElement, plainTextToCopy?: string) => Promise<void>;
@@ -1 +1,2 @@
1
+ export declare const isDragEvent: (event: Event) => event is DragEvent;
1
2
  export declare function isDroppedFile(rawEvent: Event): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-core",
3
- "version": "185.14.2",
3
+ "version": "185.14.3",
4
4
  "description": "A package contains Atlassian editor core functionality",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
package/report.api.md CHANGED
@@ -1838,7 +1838,7 @@ type NormalTextLevel = 0;
1838
1838
  // @public (undocumented)
1839
1839
  type OnEditorViewStateUpdated = (props: {
1840
1840
  readonly originalTransaction: Readonly<Transaction>;
1841
- readonly transactions: Transaction[];
1841
+ readonly transactions: ReadonlyArray<Transaction>;
1842
1842
  readonly oldEditorState: Readonly<EditorState>;
1843
1843
  readonly newEditorState: Readonly<EditorState>;
1844
1844
  }) => void;