@atlaskit/editor-core 150.0.0 → 151.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 (209) hide show
  1. package/CHANGELOG.md +65 -0
  2. package/dist/cjs/actions/index.js +5 -23
  3. package/dist/cjs/create-editor/ErrorBoundary.js +113 -79
  4. package/dist/cjs/create-editor/ReactEditorView.js +145 -31
  5. package/dist/cjs/create-editor/create-plugins-list.js +4 -2
  6. package/dist/cjs/editor.js +101 -40
  7. package/dist/cjs/labs/next/presets/cxhtml.js +2 -1
  8. package/dist/cjs/plugins/analytics/types/enums.js +3 -1
  9. package/dist/cjs/plugins/base/index.js +4 -3
  10. package/dist/cjs/plugins/base/pm-plugins/frozen-editor.js +66 -36
  11. package/dist/cjs/plugins/block-type/ui/ToolbarBlockType/styled.js +3 -1
  12. package/dist/cjs/plugins/card/index.js +13 -2
  13. package/dist/cjs/plugins/card/nodeviews/embedCard.js +1 -0
  14. package/dist/cjs/plugins/card/pm-plugins/main.js +7 -2
  15. package/dist/cjs/plugins/card/pm-plugins/util/resolve.js +10 -3
  16. package/dist/cjs/plugins/code-block/toolbar.js +1 -1
  17. package/dist/cjs/plugins/collab-edit/ui/to-avatar.js +4 -8
  18. package/dist/cjs/plugins/emoji/styles.js +1 -1
  19. package/dist/cjs/plugins/extension/pm-plugins/main.js +1 -4
  20. package/dist/cjs/plugins/extension/toolbar.js +28 -23
  21. package/dist/cjs/plugins/feature-flags-context/feature-flags-from-props.js +8 -3
  22. package/dist/cjs/plugins/find-replace/ui/Find.js +27 -7
  23. package/dist/cjs/plugins/hyperlink/pm-plugins/keymap.js +3 -3
  24. package/dist/cjs/plugins/hyperlink/ui/HyperlinkAddToolbar/HyperlinkAddToolbar.js +7 -4
  25. package/dist/cjs/plugins/hyperlink/utils.js +6 -69
  26. package/dist/cjs/plugins/media/index.js +14 -3
  27. package/dist/cjs/plugins/media/nodeviews/mediaGroup.js +24 -10
  28. package/dist/cjs/plugins/media/nodeviews/mediaInline.js +179 -0
  29. package/dist/cjs/plugins/media/pm-plugins/main.js +18 -9
  30. package/dist/cjs/plugins/media/toolbar/index.js +49 -17
  31. package/dist/cjs/plugins/media/toolbar/utils.js +20 -2
  32. package/dist/cjs/plugins/media/utils/media-files.js +67 -1
  33. package/dist/cjs/plugins/mentions/type-ahead/index.js +39 -3
  34. package/dist/cjs/plugins/panel/index.js +2 -3
  35. package/dist/cjs/plugins/panel/message.js +47 -0
  36. package/dist/cjs/plugins/panel/toolbar.js +64 -84
  37. package/dist/cjs/plugins/panel/utils.js +2 -2
  38. package/dist/cjs/plugins/paste/linkify-md-plugin.js +3 -3
  39. package/dist/cjs/plugins/status/styles.js +1 -1
  40. package/dist/cjs/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.js +18 -2
  41. package/dist/cjs/plugins/type-ahead/transforms/open-typeahead-at-cursor.js +20 -3
  42. package/dist/cjs/profiler/render-count.js +82 -0
  43. package/dist/cjs/ui/Appearance/Comment/Comment.js +6 -5
  44. package/dist/cjs/utils/react-hooks/use-component-renderer-tracking/index.js +55 -19
  45. package/dist/cjs/version-wrapper.js +1 -1
  46. package/dist/cjs/version.json +1 -1
  47. package/dist/es2019/actions/index.js +6 -28
  48. package/dist/es2019/create-editor/ErrorBoundary.js +73 -60
  49. package/dist/es2019/create-editor/ReactEditorView.js +130 -23
  50. package/dist/es2019/create-editor/create-plugins-list.js +4 -2
  51. package/dist/es2019/editor.js +74 -35
  52. package/dist/es2019/labs/next/presets/cxhtml.js +2 -1
  53. package/dist/es2019/plugins/analytics/types/enums.js +3 -1
  54. package/dist/es2019/plugins/base/index.js +4 -3
  55. package/dist/es2019/plugins/base/pm-plugins/frozen-editor.js +63 -35
  56. package/dist/es2019/plugins/block-type/ui/ToolbarBlockType/styled.js +2 -1
  57. package/dist/es2019/plugins/card/index.js +7 -2
  58. package/dist/es2019/plugins/card/nodeviews/embedCard.js +1 -0
  59. package/dist/es2019/plugins/card/pm-plugins/main.js +9 -2
  60. package/dist/es2019/plugins/card/pm-plugins/util/resolve.js +12 -5
  61. package/dist/es2019/plugins/code-block/toolbar.js +1 -1
  62. package/dist/es2019/plugins/collab-edit/ui/to-avatar.js +2 -6
  63. package/dist/es2019/plugins/emoji/styles.js +2 -0
  64. package/dist/es2019/plugins/extension/pm-plugins/main.js +1 -4
  65. package/dist/es2019/plugins/extension/toolbar.js +30 -25
  66. package/dist/es2019/plugins/feature-flags-context/feature-flags-from-props.js +8 -4
  67. package/dist/es2019/plugins/find-replace/ui/Find.js +27 -6
  68. package/dist/es2019/plugins/hyperlink/pm-plugins/keymap.js +1 -1
  69. package/dist/es2019/plugins/hyperlink/ui/HyperlinkAddToolbar/HyperlinkAddToolbar.js +7 -4
  70. package/dist/es2019/plugins/hyperlink/utils.js +3 -59
  71. package/dist/es2019/plugins/media/index.js +13 -4
  72. package/dist/es2019/plugins/media/nodeviews/mediaGroup.js +16 -7
  73. package/dist/es2019/plugins/media/nodeviews/mediaInline.js +88 -0
  74. package/dist/es2019/plugins/media/pm-plugins/main.js +20 -11
  75. package/dist/es2019/plugins/media/toolbar/index.js +44 -15
  76. package/dist/es2019/plugins/media/toolbar/utils.js +16 -0
  77. package/dist/es2019/plugins/media/utils/media-files.js +68 -2
  78. package/dist/es2019/plugins/mentions/type-ahead/index.js +21 -2
  79. package/dist/es2019/plugins/panel/index.js +3 -4
  80. package/dist/es2019/plugins/panel/message.js +38 -0
  81. package/dist/es2019/plugins/panel/toolbar.js +52 -71
  82. package/dist/es2019/plugins/panel/utils.js +2 -2
  83. package/dist/es2019/plugins/paste/linkify-md-plugin.js +2 -2
  84. package/dist/es2019/plugins/status/styles.js +2 -0
  85. package/dist/es2019/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.js +18 -2
  86. package/dist/es2019/plugins/type-ahead/transforms/open-typeahead-at-cursor.js +20 -3
  87. package/dist/es2019/profiler/render-count.js +60 -0
  88. package/dist/es2019/ui/Appearance/Comment/Comment.js +4 -2
  89. package/dist/es2019/utils/react-hooks/use-component-renderer-tracking/index.js +51 -18
  90. package/dist/es2019/version-wrapper.js +1 -1
  91. package/dist/es2019/version.json +1 -1
  92. package/dist/esm/actions/index.js +6 -24
  93. package/dist/esm/create-editor/ErrorBoundary.js +113 -78
  94. package/dist/esm/create-editor/ReactEditorView.js +146 -31
  95. package/dist/esm/create-editor/create-plugins-list.js +4 -2
  96. package/dist/esm/editor.js +100 -40
  97. package/dist/esm/labs/next/presets/cxhtml.js +2 -1
  98. package/dist/esm/plugins/analytics/types/enums.js +3 -1
  99. package/dist/esm/plugins/base/index.js +4 -3
  100. package/dist/esm/plugins/base/pm-plugins/frozen-editor.js +64 -36
  101. package/dist/esm/plugins/block-type/ui/ToolbarBlockType/styled.js +3 -1
  102. package/dist/esm/plugins/card/index.js +13 -2
  103. package/dist/esm/plugins/card/nodeviews/embedCard.js +1 -0
  104. package/dist/esm/plugins/card/pm-plugins/main.js +7 -2
  105. package/dist/esm/plugins/card/pm-plugins/util/resolve.js +12 -5
  106. package/dist/esm/plugins/code-block/toolbar.js +1 -1
  107. package/dist/esm/plugins/collab-edit/ui/to-avatar.js +4 -8
  108. package/dist/esm/plugins/emoji/styles.js +1 -1
  109. package/dist/esm/plugins/extension/pm-plugins/main.js +1 -4
  110. package/dist/esm/plugins/extension/toolbar.js +28 -23
  111. package/dist/esm/plugins/feature-flags-context/feature-flags-from-props.js +8 -4
  112. package/dist/esm/plugins/find-replace/ui/Find.js +27 -7
  113. package/dist/esm/plugins/hyperlink/pm-plugins/keymap.js +1 -1
  114. package/dist/esm/plugins/hyperlink/ui/HyperlinkAddToolbar/HyperlinkAddToolbar.js +7 -4
  115. package/dist/esm/plugins/hyperlink/utils.js +3 -59
  116. package/dist/esm/plugins/media/index.js +14 -4
  117. package/dist/esm/plugins/media/nodeviews/mediaGroup.js +24 -10
  118. package/dist/esm/plugins/media/nodeviews/mediaInline.js +147 -0
  119. package/dist/esm/plugins/media/pm-plugins/main.js +19 -11
  120. package/dist/esm/plugins/media/toolbar/index.js +47 -19
  121. package/dist/esm/plugins/media/toolbar/utils.js +15 -1
  122. package/dist/esm/plugins/media/utils/media-files.js +60 -2
  123. package/dist/esm/plugins/mentions/type-ahead/index.js +39 -3
  124. package/dist/esm/plugins/panel/index.js +3 -4
  125. package/dist/esm/plugins/panel/message.js +38 -0
  126. package/dist/esm/plugins/panel/toolbar.js +57 -77
  127. package/dist/esm/plugins/panel/utils.js +2 -2
  128. package/dist/esm/plugins/paste/linkify-md-plugin.js +2 -2
  129. package/dist/esm/plugins/status/styles.js +1 -1
  130. package/dist/esm/plugins/table/pm-plugins/sticky-headers/nodeviews/tableRow.js +18 -2
  131. package/dist/esm/plugins/type-ahead/transforms/open-typeahead-at-cursor.js +20 -3
  132. package/dist/esm/profiler/render-count.js +57 -0
  133. package/dist/esm/ui/Appearance/Comment/Comment.js +6 -5
  134. package/dist/esm/utils/react-hooks/use-component-renderer-tracking/index.js +53 -20
  135. package/dist/esm/version-wrapper.js +1 -1
  136. package/dist/esm/version.json +1 -1
  137. package/dist/types/create-editor/ErrorBoundary.d.ts +6 -6
  138. package/dist/types/create-editor/ReactEditorView.d.ts +15 -3
  139. package/dist/types/editor.d.ts +3 -1
  140. package/dist/types/plugins/analytics/analytics-queue.d.ts +1 -1
  141. package/dist/types/plugins/analytics/index.d.ts +1 -1
  142. package/dist/types/plugins/analytics/types/enums.d.ts +4 -2
  143. package/dist/types/plugins/analytics/types/events.d.ts +7 -2
  144. package/dist/types/plugins/analytics/types/general-events.d.ts +4 -1
  145. package/dist/types/plugins/analytics/types/index.d.ts +1 -1
  146. package/dist/types/plugins/analytics/types/insert-events.d.ts +6 -1
  147. package/dist/types/plugins/analytics/types/link-tool-bar-events.d.ts +1 -0
  148. package/dist/types/plugins/base/index.d.ts +1 -0
  149. package/dist/types/plugins/base/pm-plugins/frozen-editor.d.ts +3 -2
  150. package/dist/types/plugins/card/pm-plugins/main.d.ts +2 -3
  151. package/dist/types/plugins/card/pm-plugins/util/resolve.d.ts +2 -1
  152. package/dist/types/plugins/card/types.d.ts +6 -0
  153. package/dist/types/plugins/collab-edit/ui/to-avatar.d.ts +1 -1
  154. package/dist/types/plugins/extension/types.d.ts +0 -2
  155. package/dist/types/plugins/extension/ui/Extension/ExtensionComponent.d.ts +2 -2
  156. package/dist/types/plugins/feature-flags-context/get-enabled-feature-flag-keys.d.ts +1 -1
  157. package/dist/types/plugins/floating-toolbar/types.d.ts +1 -1
  158. package/dist/types/plugins/floating-toolbar/ui/Select.d.ts +1 -1
  159. package/dist/types/plugins/hyperlink/utils.d.ts +0 -21
  160. package/dist/types/plugins/insert-block/ui/ToolbarInsertBlock/create-items.d.ts +1 -1
  161. package/dist/types/plugins/media/nodeviews/mediaInline.d.ts +27 -0
  162. package/dist/types/plugins/media/pm-plugins/main.d.ts +2 -2
  163. package/dist/types/plugins/media/toolbar/utils.d.ts +2 -0
  164. package/dist/types/plugins/media/utils/media-files.d.ts +8 -0
  165. package/dist/types/plugins/panel/message.d.ts +37 -0
  166. package/dist/types/plugins/panel/toolbar.d.ts +4 -37
  167. package/dist/types/plugins/panel/types.d.ts +1 -0
  168. package/dist/types/plugins/quick-insert/index.d.ts +1 -1
  169. package/dist/types/profiler/render-count.d.ts +14 -0
  170. package/dist/types/types/feature-flags.d.ts +8 -0
  171. package/dist/types/ui/LinkSearch/types.d.ts +1 -0
  172. package/dist/types/utils/react-hooks/use-component-renderer-tracking/index.d.ts +17 -1
  173. package/package.json +20 -17
  174. package/dist/cjs/plugins/caption/nodeviews/index.test.js +0 -135
  175. package/dist/cjs/plugins/caption/pm-plugins/keymap.test.js +0 -203
  176. package/dist/cjs/plugins/caption/pm-plugins/main.test.js +0 -141
  177. package/dist/cjs/plugins/code-block/language-list.test.js +0 -74
  178. package/dist/cjs/plugins/extension/ui/SaveIndicator/SaveIndicator.test.js +0 -101
  179. package/dist/cjs/plugins/floating-toolbar/ui/EmojiPickerButton.test.js +0 -98
  180. package/dist/cjs/plugins/media/commands/captions.test.js +0 -149
  181. package/dist/cjs/plugins/media/commands/linking.test.js +0 -296
  182. package/dist/cjs/plugins/media/ui/CaptionPlaceholder/index.test.js +0 -50
  183. package/dist/cjs/plugins/panel/toolbar.test.js +0 -250
  184. package/dist/cjs/ui/ColorPickerButton/index.test.js +0 -123
  185. package/dist/cjs/ui/PortalProvider/index.test.js +0 -139
  186. package/dist/es2019/plugins/caption/nodeviews/index.test.js +0 -122
  187. package/dist/es2019/plugins/caption/pm-plugins/keymap.test.js +0 -193
  188. package/dist/es2019/plugins/caption/pm-plugins/main.test.js +0 -132
  189. package/dist/es2019/plugins/code-block/language-list.test.js +0 -69
  190. package/dist/es2019/plugins/extension/ui/SaveIndicator/SaveIndicator.test.js +0 -83
  191. package/dist/es2019/plugins/floating-toolbar/ui/EmojiPickerButton.test.js +0 -85
  192. package/dist/es2019/plugins/media/commands/captions.test.js +0 -126
  193. package/dist/es2019/plugins/media/commands/linking.test.js +0 -208
  194. package/dist/es2019/plugins/media/ui/CaptionPlaceholder/index.test.js +0 -41
  195. package/dist/es2019/plugins/panel/toolbar.test.js +0 -200
  196. package/dist/es2019/ui/ColorPickerButton/index.test.js +0 -88
  197. package/dist/es2019/ui/PortalProvider/index.test.js +0 -115
  198. package/dist/esm/plugins/caption/nodeviews/index.test.js +0 -125
  199. package/dist/esm/plugins/caption/pm-plugins/keymap.test.js +0 -195
  200. package/dist/esm/plugins/caption/pm-plugins/main.test.js +0 -124
  201. package/dist/esm/plugins/code-block/language-list.test.js +0 -71
  202. package/dist/esm/plugins/extension/ui/SaveIndicator/SaveIndicator.test.js +0 -92
  203. package/dist/esm/plugins/floating-toolbar/ui/EmojiPickerButton.test.js +0 -85
  204. package/dist/esm/plugins/media/commands/captions.test.js +0 -135
  205. package/dist/esm/plugins/media/commands/linking.test.js +0 -268
  206. package/dist/esm/plugins/media/ui/CaptionPlaceholder/index.test.js +0 -41
  207. package/dist/esm/plugins/panel/toolbar.test.js +0 -230
  208. package/dist/esm/ui/ColorPickerButton/index.test.js +0 -107
  209. package/dist/esm/ui/PortalProvider/index.test.js +0 -129
@@ -18,14 +18,15 @@ import assert from 'assert';
18
18
  import { findDomRefAtPos, isNodeSelection } from 'prosemirror-utils';
19
19
  import { insertMediaSingleNode, isMediaSingle } from '../utils/media-single';
20
20
  import DropPlaceholder from '../ui/Media/DropPlaceholder';
21
- import { insertMediaGroupNode } from '../utils/media-files';
22
- import { removeMediaNode, splitMediaGroup } from '../utils/media-common';
21
+ import { insertMediaGroupNode, insertMediaInlineNode, canInsertMediaInline } from '../utils/media-files';
22
+ import { isInsidePotentialEmptyParagraph, removeMediaNode, splitMediaGroup } from '../utils/media-common';
23
23
  import * as helpers from '../commands/helpers';
24
24
  import { updateMediaNodeAttrs } from '../commands/helpers';
25
25
  import { stateKey } from './plugin-key';
26
26
  import PickerFacade from '../picker-facade';
27
27
  import { INPUT_METHOD } from '../../analytics/types';
28
28
  import { isImage } from '../utils/is-image';
29
+ import { isInEmptyLine } from '../../../utils/document';
29
30
  export { stateKey } from './plugin-key';
30
31
 
31
32
  var createDropPlaceholder = function createDropPlaceholder(allowDropLine) {
@@ -73,7 +74,7 @@ export var MediaPluginStateImplementation = /*#__PURE__*/function () {
73
74
 
74
75
  _defineProperty(this, "removeOnCloseListener", function () {});
75
76
 
76
- _defineProperty(this, "onPopupToogleCallback", function () {});
77
+ _defineProperty(this, "onPopupToggleCallback", function () {});
77
78
 
78
79
  _defineProperty(this, "pickers", []);
79
80
 
@@ -238,11 +239,12 @@ export var MediaPluginStateImplementation = /*#__PURE__*/function () {
238
239
 
239
240
  var type = _ref3.type;
240
241
  var _this$view$state$sche = _this.view.state.schema.nodes,
242
+ mediaInline = _this$view$state$sche.mediaInline,
241
243
  mediaSingle = _this$view$state$sche.mediaSingle,
242
244
  media = _this$view$state$sche.media;
243
245
 
244
246
  if ((_this$mediaOptions = _this.mediaOptions) !== null && _this$mediaOptions !== void 0 && _this$mediaOptions.allowMediaInline) {
245
- return type === mediaSingle || type === media;
247
+ return type === mediaSingle || type === media || type === mediaInline;
246
248
  }
247
249
 
248
250
  return type === mediaSingle;
@@ -253,6 +255,10 @@ export var MediaPluginStateImplementation = /*#__PURE__*/function () {
253
255
  });
254
256
 
255
257
  _defineProperty(this, "insertFile", function (mediaState, onMediaStateChanged, pickerType) {
258
+ var _this$mediaOptions2;
259
+
260
+ var state = _this.view.state;
261
+
256
262
  var mediaStateWithContext = _objectSpread(_objectSpread({}, mediaState), {}, {
257
263
  contextId: _this.contextIdentifierProvider ? _this.contextIdentifierProvider.objectId : undefined
258
264
  });
@@ -274,8 +280,10 @@ export var MediaPluginStateImplementation = /*#__PURE__*/function () {
274
280
  });
275
281
  }
276
282
 
277
- if (isMediaSingle(_this.view.state.schema, mediaStateWithContext.fileMimeType)) {
283
+ if (isMediaSingle(state.schema, mediaStateWithContext.fileMimeType)) {
278
284
  insertMediaSingleNode(_this.view, mediaStateWithContext, _this.getInputMethod(pickerType), collection, _this.mediaOptions && _this.mediaOptions.alignLeftOnInsert);
285
+ } else if ((_this$mediaOptions2 = _this.mediaOptions) !== null && _this$mediaOptions2 !== void 0 && _this$mediaOptions2.allowMediaInline && !isInEmptyLine(state) && !isInsidePotentialEmptyParagraph(state) && canInsertMediaInline(state)) {
286
+ insertMediaInlineNode(_this.view, mediaStateWithContext, collection, _this.getInputMethod(pickerType));
279
287
  } else {
280
288
  insertMediaGroupNode(_this.view, [mediaStateWithContext], collection, _this.getInputMethod(pickerType));
281
289
  } // do events when media state changes
@@ -328,7 +336,7 @@ export var MediaPluginStateImplementation = /*#__PURE__*/function () {
328
336
  });
329
337
 
330
338
  _defineProperty(this, "onPopupPickerClose", function () {
331
- _this.onPopupToogleCallback(false);
339
+ _this.onPopupToggleCallback(false);
332
340
  });
333
341
 
334
342
  _defineProperty(this, "shouldUseMediaPickerPopup", function () {
@@ -350,15 +358,15 @@ export var MediaPluginStateImplementation = /*#__PURE__*/function () {
350
358
 
351
359
  _this.popupPicker.show();
352
360
 
353
- _this.onPopupToogleCallback(true);
361
+ _this.onPopupToggleCallback(true);
354
362
  });
355
363
 
356
364
  _defineProperty(this, "setBrowseFn", function (browseFn) {
357
365
  _this.openMediaPickerBrowser = browseFn;
358
366
  });
359
367
 
360
- _defineProperty(this, "onPopupToggle", function (onPopupToogleCallback) {
361
- _this.onPopupToogleCallback = onPopupToogleCallback;
368
+ _defineProperty(this, "onPopupToggle", function (onPopupToggleCallback) {
369
+ _this.onPopupToggleCallback = onPopupToggleCallback;
362
370
  });
363
371
 
364
372
  _defineProperty(this, "waitForPendingTasks", function (timeout, lastTask) {
@@ -582,7 +590,7 @@ export var MediaPluginStateImplementation = /*#__PURE__*/function () {
582
590
  }, {
583
591
  key: "getDomElement",
584
592
  value: function getDomElement(domAtPos) {
585
- var _this$mediaOptions2;
593
+ var _this$mediaOptions3;
586
594
 
587
595
  var selection = this.view.state.selection;
588
596
 
@@ -594,7 +602,7 @@ export var MediaPluginStateImplementation = /*#__PURE__*/function () {
594
602
  return;
595
603
  }
596
604
 
597
- var position = (_this$mediaOptions2 = this.mediaOptions) !== null && _this$mediaOptions2 !== void 0 && _this$mediaOptions2.allowMediaInline ? selection.from + 1 : selection.from;
605
+ var position = (_this$mediaOptions3 = this.mediaOptions) !== null && _this$mediaOptions3 !== void 0 && _this$mediaOptions3.allowMediaInline ? selection.from + 1 : selection.from;
598
606
  var node = findDomRefAtPos(position, domAtPos);
599
607
 
600
608
  if (node) {
@@ -6,7 +6,8 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
6
6
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
7
7
 
8
8
  import React from 'react';
9
- import { findParentNodeOfType, removeSelectedNode } from 'prosemirror-utils';
9
+ import { NodeSelection } from 'prosemirror-state';
10
+ import { findParentNodeOfType, removeSelectedNode, safeInsert } from 'prosemirror-utils';
10
11
  import RemoveIcon from '@atlaskit/icon/glyph/editor/remove';
11
12
  import DownloadIcon from '@atlaskit/icon/glyph/download';
12
13
  import { mediaFilmstripItemDOMSelector } from '@atlaskit/media-filmstrip';
@@ -25,7 +26,8 @@ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, addAnalytics, EVENT_TYPE } f
25
26
  import { messages } from '@atlaskit/media-ui';
26
27
  import { messages as cardMessages } from '../../card/messages';
27
28
  import { FilePreviewItem } from './filePreviewItem';
28
- import { downloadMedia } from './utils';
29
+ import { downloadMedia, removeMediaGroupNode } from './utils';
30
+ import { Fragment } from 'prosemirror-model';
29
31
 
30
32
  var remove = function remove(state, dispatch) {
31
33
  if (dispatch) {
@@ -35,13 +37,42 @@ var remove = function remove(state, dispatch) {
35
37
  return true;
36
38
  };
37
39
 
38
- var removeMediaCard = function removeMediaCard(state, mediaPluginState) {
39
- var getPos = function getPos() {
40
- var mediaOffset = state.selection.$from.parentOffset + 1;
41
- return mediaOffset;
42
- };
40
+ var handleRemoveMediaGroup = function handleRemoveMediaGroup(state, dispatch) {
41
+ var tr = removeMediaGroupNode(state);
42
+
43
+ if (dispatch) {
44
+ dispatch(tr);
45
+ }
46
+
47
+ return true;
48
+ };
49
+
50
+ var changeMediaCardToInline = function changeMediaCardToInline(state, dispatch) {
51
+ var _state$schema$nodes = state.schema.nodes,
52
+ media = _state$schema$nodes.media,
53
+ mediaInline = _state$schema$nodes.mediaInline,
54
+ paragraph = _state$schema$nodes.paragraph;
55
+ var selectedNode = state.selection instanceof NodeSelection && state.selection.node;
56
+
57
+ if (!selectedNode || !selectedNode.type === media) {
58
+ return false;
59
+ }
60
+
61
+ var mediaInlineNode = mediaInline.create({
62
+ id: selectedNode.attrs.id,
63
+ collection: selectedNode.attrs.collection
64
+ });
65
+ var space = state.schema.text(' ');
66
+ var content = Fragment.from([mediaInlineNode, space]);
67
+ var node = paragraph.createChecked({}, content);
68
+ var nodePos = state.tr.doc.resolve(state.selection.from).start() - 1;
69
+ var tr = removeMediaGroupNode(state);
70
+ tr = safeInsert(node, nodePos, true)(tr);
71
+
72
+ if (dispatch) {
73
+ dispatch(tr);
74
+ }
43
75
 
44
- mediaPluginState.handleMediaNodeRemoval(undefined, getPos);
45
76
  return true;
46
77
  };
47
78
 
@@ -53,9 +84,7 @@ var generateMediaCardFloatingToolbar = function generateMediaCardFloatingToolbar
53
84
  options: [{
54
85
  title: intl.formatMessage(cardMessages.inline),
55
86
  selected: false,
56
- onClick: function onClick() {
57
- return true;
58
- },
87
+ onClick: changeMediaCardToInline,
59
88
  testId: 'inline-appearance'
60
89
  }, {
61
90
  title: intl.formatMessage(messages.displayThumbnail),
@@ -99,9 +128,7 @@ var generateMediaCardFloatingToolbar = function generateMediaCardFloatingToolbar
99
128
  onFocus: hoverDecoration(mediaGroup, true),
100
129
  onBlur: hoverDecoration(mediaGroup, false),
101
130
  title: intl.formatMessage(commonMessages.remove),
102
- onClick: function onClick(state) {
103
- return removeMediaCard(state, mediaPluginState);
104
- },
131
+ onClick: handleRemoveMediaGroup,
105
132
  testId: 'media-toolbar-remove-button'
106
133
  }];
107
134
  return items;
@@ -206,10 +233,11 @@ var generateMediaSingleFloatingToolbar = function generateMediaSingleFloatingToo
206
233
 
207
234
  export var floatingToolbar = function floatingToolbar(state, intl) {
208
235
  var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
209
- var _state$schema$nodes = state.schema.nodes,
210
- media = _state$schema$nodes.media,
211
- mediaSingle = _state$schema$nodes.mediaSingle,
212
- mediaGroup = _state$schema$nodes.mediaGroup;
236
+ var _state$schema$nodes2 = state.schema.nodes,
237
+ media = _state$schema$nodes2.media,
238
+ mediaInline = _state$schema$nodes2.mediaInline,
239
+ mediaSingle = _state$schema$nodes2.mediaSingle,
240
+ mediaGroup = _state$schema$nodes2.mediaGroup;
213
241
  var altTextValidator = options.altTextValidator,
214
242
  allowLinking = options.allowLinking,
215
243
  allowAltTextOnImages = options.allowAltTextOnImages,
@@ -222,7 +250,7 @@ export var floatingToolbar = function floatingToolbar(state, intl) {
222
250
  return;
223
251
  }
224
252
 
225
- var nodeType = allowMediaInline ? [mediaSingle, media] : [mediaSingle];
253
+ var nodeType = allowMediaInline ? [mediaInline, mediaSingle, media] : [mediaSingle];
226
254
  var baseToolbar = {
227
255
  title: 'Media floating controls',
228
256
  nodeType: nodeType,
@@ -1,6 +1,7 @@
1
1
  import _regeneratorRuntime from "@babel/runtime/regenerator";
2
2
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
3
  import { getMediaClient } from '@atlaskit/media-client';
4
+ import { findParentNodeOfType, removeParentNodeOfType, removeSelectedNode } from 'prosemirror-utils';
4
5
  export var getSelectedMediaContainerNodeAttrs = function getSelectedMediaContainerNodeAttrs(mediaPluginState) {
5
6
  var selectedNode = mediaPluginState.selectedMediaContainerNode();
6
7
 
@@ -57,4 +58,17 @@ export var downloadMedia = /*#__PURE__*/function () {
57
58
  return function downloadMedia(_x) {
58
59
  return _ref.apply(this, arguments);
59
60
  };
60
- }();
61
+ }();
62
+ export var removeMediaGroupNode = function removeMediaGroupNode(state) {
63
+ var mediaGroup = state.schema.nodes.mediaGroup;
64
+ var mediaGroupParent = findParentNodeOfType(mediaGroup)(state.selection);
65
+ var tr = state.tr; // If it is the last media group in filmstrip, remove the entire filmstrip
66
+
67
+ if (mediaGroupParent && mediaGroupParent.node.childCount === 1) {
68
+ tr = removeParentNodeOfType(mediaGroup)(tr);
69
+ } else {
70
+ tr = removeSelectedNode(tr);
71
+ }
72
+
73
+ return tr;
74
+ };
@@ -1,10 +1,14 @@
1
1
  import { Fragment } from 'prosemirror-model';
2
2
  import { setNodeSelection, setTextSelection, insideTableCell, isInListItem, findFarthestParentNode, isInLayoutColumn } from '../../../utils';
3
3
  import { posOfPrecedingMediaGroup, posOfMediaGroupNearby, posOfParentMediaGroup, isSelectionNonMediaBlockNode, isInsidePotentialEmptyParagraph, copyOptionalAttrsFromMediaState } from './media-common';
4
- import { safeInsert, hasParentNode } from 'prosemirror-utils';
4
+ import { canInsert, safeInsert, hasParentNode } from 'prosemirror-utils';
5
5
  import { atTheBeginningOfBlock, atTheEndOfBlock, atTheEndOfDoc, endPositionOfParent, startPositionOfParent } from '../../../utils/prosemirror/position';
6
6
  import { isSupportedInParent } from '../../../utils/nodes';
7
7
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, addAnalytics } from '../../analytics';
8
+ export var canInsertMediaInline = function canInsertMediaInline(state) {
9
+ var node = state.schema.nodes.mediaInline.create({});
10
+ return canInsert(state.selection.$to, Fragment.from(node));
11
+ };
8
12
 
9
13
  var getInsertMediaGroupAnalytics = function getInsertMediaGroupAnalytics(mediaState, inputMethod) {
10
14
  var media = '';
@@ -27,6 +31,21 @@ var getInsertMediaGroupAnalytics = function getInsertMediaGroupAnalytics(mediaSt
27
31
  eventType: EVENT_TYPE.TRACK
28
32
  };
29
33
  };
34
+
35
+ var getInsertMediaInlineAnalytics = function getInsertMediaInlineAnalytics(mediaState, inputMethod) {
36
+ var media = mediaState.fileMimeType || 'unknown';
37
+ return {
38
+ action: ACTION.INSERTED,
39
+ actionSubject: ACTION_SUBJECT.DOCUMENT,
40
+ actionSubjectId: ACTION_SUBJECT_ID.MEDIA,
41
+ attributes: {
42
+ type: ACTION_SUBJECT_ID.MEDIA_INLINE,
43
+ inputMethod: inputMethod,
44
+ fileExtension: media
45
+ },
46
+ eventType: EVENT_TYPE.TRACK
47
+ };
48
+ };
30
49
  /**
31
50
  * Check if current editor selections is a media group or not.
32
51
  * @param state Editor state
@@ -51,6 +70,46 @@ function shouldAppendParagraph(state, node) {
51
70
  var wasMediaNode = node && node.type === media;
52
71
  return (insideTableCell(state) || isInListItem(state) || isInLayoutColumn(state) || atTheEndOfDoc(state) && (!posOfPrecedingMediaGroup(state) || isSelectionNonMediaBlockNode(state))) && !wasMediaNode;
53
72
  }
73
+ /**
74
+ * Create a new media inline to insert the new media.
75
+ * @param view Editor view
76
+ * @param mediaState Media file to be added to the editor
77
+ * @param collection Collection for the media to be added
78
+ */
79
+
80
+
81
+ export var insertMediaInlineNode = function insertMediaInlineNode(view, mediaState, collection, inputMethod) {
82
+ var state = view.state,
83
+ dispatch = view.dispatch;
84
+ var schema = state.schema,
85
+ tr = state.tr;
86
+ var mediaInline = schema.nodes.mediaInline; // Do nothing if no media found
87
+
88
+ if (!mediaInline || !mediaState || collection === undefined) {
89
+ return false;
90
+ }
91
+
92
+ var id = mediaState.id;
93
+ var mediaInlineNode = mediaInline.create({
94
+ id: id,
95
+ collection: collection
96
+ });
97
+ var space = state.schema.text(' ');
98
+ var pos = state.selection.$to.pos;
99
+ var content = Fragment.from([mediaInlineNode, space]); // Delete the selection if a selection is made
100
+
101
+ var deleteRange = findDeleteRange(state);
102
+
103
+ if (!deleteRange) {
104
+ tr.insert(pos, content);
105
+ } else {
106
+ tr.insert(pos, content).deleteRange(deleteRange.start, deleteRange.end);
107
+ }
108
+
109
+ addAnalytics(state, tr, getInsertMediaInlineAnalytics(mediaState, inputMethod));
110
+ dispatch(tr);
111
+ return true;
112
+ };
54
113
  /**
55
114
  * Insert a media into an existing media group
56
115
  * or create a new media group to insert the new media.
@@ -59,7 +118,6 @@ function shouldAppendParagraph(state, node) {
59
118
  * @param collection Collection for the media to be added
60
119
  */
61
120
 
62
-
63
121
  export var insertMediaGroupNode = function insertMediaGroupNode(view, mediaStates, collection, inputMethod) {
64
122
  var state = view.state,
65
123
  dispatch = view.dispatch;
@@ -1,6 +1,12 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
3
3
 
4
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
5
+
6
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
7
+
8
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
9
+
4
10
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
5
11
 
6
12
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
@@ -201,6 +207,7 @@ export var createTypeAheadConfig = function createTypeAheadConfig(_ref6) {
201
207
  HighlightComponent = _ref6.HighlightComponent;
202
208
  var sessionId = uuid();
203
209
  var firstQueryWithoutResults = null;
210
+ var subscriptionKeys = new Set();
204
211
  var typeAhead = {
205
212
  id: TypeAheadAvailableNodes.MENTION,
206
213
  trigger: '@',
@@ -247,9 +254,15 @@ export var createTypeAheadConfig = function createTypeAheadConfig(_ref6) {
247
254
  var key = "loadingMentionsForTypeAhead_".concat(uuid());
248
255
 
249
256
  var mentionsSubscribeCallback = function mentionsSubscribeCallback(mentions) {
250
- var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
257
+ var resultQuery = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
251
258
  var stats = arguments.length > 2 ? arguments[2] : undefined;
259
+
260
+ if (query !== resultQuery) {
261
+ return;
262
+ }
263
+
252
264
  mentionProvider.unsubscribe(key);
265
+ subscriptionKeys.delete(key);
253
266
  var mentionItems = mentions.map(function (mention) {
254
267
  return memoizedToItem.call(mention);
255
268
  });
@@ -285,13 +298,14 @@ export var createTypeAheadConfig = function createTypeAheadConfig(_ref6) {
285
298
  }
286
299
  };
287
300
 
301
+ subscriptionKeys.add(key);
288
302
  mentionProvider.subscribe(key, mentionsSubscribeCallback);
289
303
  mentionProvider.filter(query || '', _objectSpread(_objectSpread({}, contextIdentifierProvider), {}, {
290
304
  sessionId: sessionId
291
305
  }));
292
306
  });
293
307
  },
294
- onOpen: function onOpen(editorState) {
308
+ onOpen: function onOpen() {
295
309
  firstQueryWithoutResults = null;
296
310
  },
297
311
  selectItem: function selectItem(state, item, insert, _ref8) {
@@ -362,11 +376,33 @@ export var createTypeAheadConfig = function createTypeAheadConfig(_ref6) {
362
376
  return insert(Fragment.from([mentionNode, space]));
363
377
  },
364
378
  dismiss: function dismiss(_ref9) {
365
- var query = _ref9.query,
379
+ var editorState = _ref9.editorState,
380
+ query = _ref9.query,
366
381
  stats = _ref9.stats;
367
382
  firstQueryWithoutResults = null;
368
383
  var pickerElapsedTime = stats.startedAt ? Date.now() - stats.startedAt : 0;
369
384
  fireEvent(buildTypeAheadCancelPayload(pickerElapsedTime, stats.keyCount.arrowUp, stats.keyCount.arrowDown, sessionId, query || ''));
385
+ var pluginState = getMentionPluginState(editorState);
386
+
387
+ if (pluginState !== null && pluginState !== void 0 && pluginState.mentionProvider) {
388
+ var mentionProvider = pluginState.mentionProvider;
389
+
390
+ var _iterator = _createForOfIteratorHelper(subscriptionKeys),
391
+ _step;
392
+
393
+ try {
394
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
395
+ var key = _step.value;
396
+ mentionProvider.unsubscribe(key);
397
+ }
398
+ } catch (err) {
399
+ _iterator.e(err);
400
+ } finally {
401
+ _iterator.f();
402
+ }
403
+ }
404
+
405
+ subscriptionKeys.clear();
370
406
  sessionId = uuid();
371
407
  }
372
408
  };
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { panel, customPanel, PanelType } from '@atlaskit/adf-schema';
2
+ import { customPanel, PanelType } from '@atlaskit/adf-schema';
3
3
  import { createPlugin } from './pm-plugins/main';
4
4
  import { getToolbarConfig } from './toolbar';
5
5
  import keymap from './pm-plugins/keymaps';
@@ -37,8 +37,7 @@ var panelPlugin = function panelPlugin() {
37
37
  return {
38
38
  name: 'panel',
39
39
  nodes: function nodes() {
40
- //TODO: ED-10445 remove this check after emoji panels moved to full schema
41
- var panelNode = options.UNSAFE_allowCustomPanel ? customPanel : panel;
40
+ var panelNode = customPanel(!!options.UNSAFE_allowCustomPanel);
42
41
  return [{
43
42
  name: 'panel',
44
43
  node: panelNode
@@ -131,7 +130,7 @@ var panelPlugin = function panelPlugin() {
131
130
  }
132
131
  }];
133
132
 
134
- if (options.UNSAFE_allowCustomPanel) {
133
+ if (options.UNSAFE_allowCustomPanelEdit && options.UNSAFE_allowCustomPanel) {
135
134
  quickInsertOptions.push({
136
135
  id: 'custompanel',
137
136
  title: formatMessage(messages.customPanel),
@@ -0,0 +1,38 @@
1
+ import { defineMessages } from 'react-intl';
2
+ export var messages = defineMessages({
3
+ info: {
4
+ id: 'fabric.editor.info',
5
+ defaultMessage: 'Info',
6
+ description: 'Panels provide a way to highlight text. The info panel has a blue background.'
7
+ },
8
+ note: {
9
+ id: 'fabric.editor.note',
10
+ defaultMessage: 'Note',
11
+ description: 'Panels provide a way to highlight text. The note panel has a purple background.'
12
+ },
13
+ success: {
14
+ id: 'fabric.editor.success',
15
+ defaultMessage: 'Success',
16
+ description: 'Panels provide a way to highlight text. The success panel has a green background.'
17
+ },
18
+ warning: {
19
+ id: 'fabric.editor.warning',
20
+ defaultMessage: 'Warning',
21
+ description: 'Panels provide a way to highlight text. The warning panel has a yellow background.'
22
+ },
23
+ error: {
24
+ id: 'fabric.editor.error',
25
+ defaultMessage: 'Error',
26
+ description: 'Panels provide a way to highlight text. The error panel has a red background.'
27
+ },
28
+ emoji: {
29
+ id: 'fabric.editor.panel.emoji',
30
+ defaultMessage: 'Add emoji',
31
+ description: 'Select the panel icon'
32
+ },
33
+ backgroundColor: {
34
+ id: 'fabric.editor.panel.backgroundColor',
35
+ defaultMessage: 'Background color',
36
+ description: 'Select the panel background color.'
37
+ }
38
+ });