@atlaskit/editor-core 166.0.1 → 166.0.4

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 (34) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/cjs/plugins/annotation/pm-plugins/plugin-factory.js +0 -1
  3. package/dist/cjs/plugins/extension/plugin-factory.js +1 -4
  4. package/dist/cjs/plugins/extension/pm-plugins/main.js +11 -34
  5. package/dist/cjs/plugins/extension/utils.js +12 -57
  6. package/dist/cjs/plugins/feedback-dialog/index.js +0 -1
  7. package/dist/cjs/plugins/find-replace/utils/batch-decorations.js +0 -1
  8. package/dist/cjs/plugins/paste/handlers.js +21 -6
  9. package/dist/cjs/plugins/table/event-handlers.js +3 -3
  10. package/dist/cjs/plugins/text-formatting/utils.js +1 -1
  11. package/dist/cjs/version-wrapper.js +1 -1
  12. package/dist/cjs/version.json +1 -1
  13. package/dist/es2019/plugins/extension/plugin-factory.js +1 -3
  14. package/dist/es2019/plugins/extension/pm-plugins/main.js +12 -38
  15. package/dist/es2019/plugins/extension/utils.js +2 -37
  16. package/dist/es2019/plugins/paste/handlers.js +22 -7
  17. package/dist/es2019/plugins/text-formatting/utils.js +1 -1
  18. package/dist/es2019/version-wrapper.js +1 -1
  19. package/dist/es2019/version.json +1 -1
  20. package/dist/esm/plugins/annotation/pm-plugins/plugin-factory.js +0 -1
  21. package/dist/esm/plugins/extension/plugin-factory.js +1 -3
  22. package/dist/esm/plugins/extension/pm-plugins/main.js +11 -34
  23. package/dist/esm/plugins/extension/utils.js +9 -51
  24. package/dist/esm/plugins/feedback-dialog/index.js +0 -1
  25. package/dist/esm/plugins/find-replace/utils/batch-decorations.js +0 -1
  26. package/dist/esm/plugins/paste/handlers.js +22 -7
  27. package/dist/esm/plugins/table/event-handlers.js +3 -3
  28. package/dist/esm/plugins/text-formatting/utils.js +1 -1
  29. package/dist/esm/version-wrapper.js +1 -1
  30. package/dist/esm/version.json +1 -1
  31. package/dist/types/plugins/extension/pm-plugins/main.d.ts +1 -2
  32. package/dist/types/plugins/extension/types.d.ts +0 -1
  33. package/dist/types/plugins/extension/utils.d.ts +1 -3
  34. package/package.json +4 -4
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @atlaskit/editor-core
2
2
 
3
+ ## 166.0.4
4
+
5
+ ### Patch Changes
6
+
7
+ - [`08b3ceadbe3`](https://bitbucket.org/atlassian/atlassian-frontend/commits/08b3ceadbe3) - [Hotfix] Revert of ED-14241
8
+
9
+ ## 166.0.3
10
+
11
+ ### Patch Changes
12
+
13
+ - [`56238fdc70e`](https://bitbucket.org/atlassian/atlassian-frontend/commits/56238fdc70e) - ED-14998 Fix paste issue in a table inside a bodied extension. Copying and pasting inline nodes inside the table should not create a new table during paste
14
+
15
+ ## 166.0.2
16
+
17
+ ### Patch Changes
18
+
19
+ - [`61b504d9af7`](https://bitbucket.org/atlassian/atlassian-frontend/commits/61b504d9af7) - [ED-15023] Fix editor crashing when first line contains only sub or super script
20
+
3
21
  ## 166.0.1
4
22
 
5
23
  ### Patch Changes
@@ -63,7 +63,6 @@ var _pluginFactory = (0, _pluginStateFactory.pluginFactory)(_utils.inlineComment
63
63
  } // return same pluginState if mappings did not change
64
64
 
65
65
 
66
- // return same pluginState if mappings did not change
67
66
  if (mappedBookmark === bookmark && mappedDecorationSet === draftDecorationSet) {
68
67
  return pluginState;
69
68
  }
@@ -15,8 +15,6 @@ var _reducer = _interopRequireDefault(require("./reducer"));
15
15
 
16
16
  var _pluginKey = require("./plugin-key");
17
17
 
18
- var _utils = require("./utils");
19
-
20
18
  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; }
21
19
 
22
20
  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) { (0, _defineProperty2.default)(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; }
@@ -39,8 +37,7 @@ var factory = (0, _pluginStateFactory.pluginFactory)(_pluginKey.pluginKey, _redu
39
37
  return _objectSpread(_objectSpread({}, state), {}, {
40
38
  positions: positions
41
39
  });
42
- },
43
- onSelectionChanged: _utils.onSelectionChanged
40
+ }
44
41
  });
45
42
  var createPluginState = factory.createPluginState;
46
43
  exports.createPluginState = createPluginState;
@@ -296,7 +296,6 @@ var createPlugin = function createPlugin(dispatch, providerFactory, extensionHan
296
296
  var useLongPressSelection = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
297
297
  var options = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : {};
298
298
  var state = (0, _pluginFactory.createPluginState)(dispatch, {
299
- shouldRefreshEditButton: false,
300
299
  showEditButton: false,
301
300
  showContextPanel: false
302
301
  });
@@ -320,45 +319,25 @@ var createPlugin = function createPlugin(dispatch, providerFactory, extensionHan
320
319
  element = _getPluginState.element,
321
320
  localId = _getPluginState.localId,
322
321
  extensionProvider = _getPluginState.extensionProvider,
323
- showContextPanel = _getPluginState.showContextPanel,
324
- shouldRefreshEditButton = _getPluginState.shouldRefreshEditButton;
322
+ showContextPanel = _getPluginState.showContextPanel; // This fetches the selected extension node, either by keyboard selection or click for all types of extensions
325
323
 
326
- if (!shouldRefreshEditButton) {
327
- return false;
328
- } // This fetches the selected extension node, either by keyboard selection or click for all types of extensions
329
324
 
330
-
331
- var selectedExtension = (0, _utils2.getSelectedExtension)(state, true); // If our selection isn't on an extension node, clear some state and hide the config panel
325
+ var selectedExtension = (0, _utils2.getSelectedExtension)(state, true);
332
326
 
333
327
  if (!selectedExtension) {
334
328
  if (showContextPanel) {
335
329
  (0, _commands.clearEditingContext)(state, dispatch);
336
330
  }
337
331
 
338
- (0, _commands.updateState)({
339
- shouldRefreshEditButton: false,
340
- localId: undefined,
341
- element: undefined,
342
- showEditButton: false,
343
- updateExtension: undefined
344
- })(state, dispatch);
345
332
  return;
346
- } // By this point we're certain we've selected an extension node.
347
- // But we need to determine if the selection has changed to another
348
- // extension node or remained on the same node.
349
-
333
+ }
350
334
 
351
335
  var node = selectedExtension.node;
352
336
  var newElement = (0, _utils2.getSelectedDomElement)(state.schema, domAtPos, selectedExtension); // New node is selection
353
337
 
354
- var hasSelectedNodeChanged = node.attrs.localId ? localId !== node.attrs.localId : // This is the current assumption and it's wrong but we are keeping it
338
+ if (node.attrs.localId ? localId !== node.attrs.localId : // This is the current assumption and it's wrong but we are keeping it
355
339
  // as fallback in case we need to turn off `allowLocalIdGeneration`
356
- element !== newElement;
357
- var nextState = {
358
- shouldRefreshEditButton: false
359
- };
360
-
361
- if (hasSelectedNodeChanged) {
340
+ element !== newElement) {
362
341
  if (showContextPanel) {
363
342
  (0, _commands.clearEditingContext)(state, dispatch);
364
343
  }
@@ -369,20 +348,20 @@ var createPlugin = function createPlugin(dispatch, providerFactory, extensionHan
369
348
  var showEditButton = shouldShowEditButton(extensionHandler, extensionProvider);
370
349
  var updateExtension = getUpdateExtensionPromise(view, extensionHandler, extensionProvider).catch(function () {// do nothing;
371
350
  });
372
- Object.assign(nextState, {
351
+ (0, _commands.updateState)({
373
352
  localId: node.attrs.localId,
353
+ showContextPanel: false,
374
354
  element: newElement,
375
355
  showEditButton: showEditButton,
376
356
  updateExtension: updateExtension
377
- });
357
+ })(state, dispatch);
378
358
  } // New DOM element doesn't necessarily mean it's a new Node
379
359
  else if (element !== newElement) {
380
- Object.assign(nextState, {
360
+ (0, _commands.updateState)({
381
361
  element: newElement
382
- });
362
+ })(state, dispatch);
383
363
  }
384
364
 
385
- (0, _commands.updateState)(nextState)(state, dispatch);
386
365
  return true;
387
366
  },
388
367
  destroy: function destroy() {
@@ -399,9 +378,7 @@ var createPlugin = function createPlugin(dispatch, providerFactory, extensionHan
399
378
  inlineExtension: (0, _extension.default)(portalProviderAPI, eventDispatcher, providerFactory, extensionHandlers, extensionNodeViewOptions)
400
379
  },
401
380
  handleClickOn: (0, _utils.createSelectionClickHandler)(['extension', 'bodiedExtension'], function (target) {
402
- // Clicked on anything around the extension content
403
- // or specifically on the content border of a bodied extension
404
- return !target.closest('.extension-content') || target.classList.contains('extension-content');
381
+ return !target.closest('.extension-content');
405
382
  }, {
406
383
  useLongPressSelection: useLongPressSelection
407
384
  })
@@ -1,13 +1,9 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
8
- exports.onSelectionChanged = exports.getSelectedExtension = exports.getSelectedDomElement = exports.getNodeTypesReferenced = exports.getDataConsumerMark = exports.findNodePosWithLocalId = exports.findExtensionWithLocalId = void 0;
9
-
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
6
+ exports.getSelectedExtension = exports.getSelectedDomElement = exports.getNodeTypesReferenced = exports.getDataConsumerMark = exports.findNodePosWithLocalId = exports.findExtensionWithLocalId = void 0;
11
7
 
12
8
  var _prosemirrorUtils = require("prosemirror-utils");
13
9
 
@@ -15,31 +11,18 @@ var _dom = require("../../utils/dom");
15
11
 
16
12
  var _nodesByLocalIds = require("../../utils/nodes-by-localIds");
17
13
 
18
- 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; }
19
-
20
- 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) { (0, _defineProperty2.default)(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; }
21
-
22
- var getSelectedExtensionByTransaction = function getSelectedExtensionByTransaction(transaction) {
23
- var searchParent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
24
- return _getSelectedExtension(transaction.doc.type.schema, transaction.selection, searchParent);
25
- };
26
-
27
14
  var getSelectedExtension = function getSelectedExtension(state) {
28
15
  var searchParent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
29
- return _getSelectedExtension(state.schema, state.selection, searchParent);
16
+ var _state$schema$nodes = state.schema.nodes,
17
+ inlineExtension = _state$schema$nodes.inlineExtension,
18
+ extension = _state$schema$nodes.extension,
19
+ bodiedExtension = _state$schema$nodes.bodiedExtension;
20
+ var nodeTypes = [extension, bodiedExtension, inlineExtension];
21
+ return (0, _prosemirrorUtils.findSelectedNodeOfType)(nodeTypes)(state.selection) || searchParent && (0, _prosemirrorUtils.findParentNodeOfType)(nodeTypes)(state.selection) || undefined;
30
22
  };
31
23
 
32
24
  exports.getSelectedExtension = getSelectedExtension;
33
25
 
34
- var _getSelectedExtension = function _getSelectedExtension(schema, selection, searchParent) {
35
- var _schema$nodes = schema.nodes,
36
- inlineExtension = _schema$nodes.inlineExtension,
37
- extension = _schema$nodes.extension,
38
- bodiedExtension = _schema$nodes.bodiedExtension;
39
- var nodeTypes = [extension, bodiedExtension, inlineExtension];
40
- return (0, _prosemirrorUtils.findSelectedNodeOfType)(nodeTypes)(selection) || searchParent && (0, _prosemirrorUtils.findParentNodeOfType)(nodeTypes)(selection) || undefined;
41
- };
42
-
43
26
  var findExtensionWithLocalId = function findExtensionWithLocalId(state, localId) {
44
27
  var selectedExtension = getSelectedExtension(state, true);
45
28
 
@@ -51,10 +34,10 @@ var findExtensionWithLocalId = function findExtensionWithLocalId(state, localId)
51
34
  return selectedExtension;
52
35
  }
53
36
 
54
- var _state$schema$nodes = state.schema.nodes,
55
- inlineExtension = _state$schema$nodes.inlineExtension,
56
- extension = _state$schema$nodes.extension,
57
- bodiedExtension = _state$schema$nodes.bodiedExtension;
37
+ var _state$schema$nodes2 = state.schema.nodes,
38
+ inlineExtension = _state$schema$nodes2.inlineExtension,
39
+ extension = _state$schema$nodes2.extension,
40
+ bodiedExtension = _state$schema$nodes2.bodiedExtension;
58
41
  var nodeTypes = [extension, bodiedExtension, inlineExtension];
59
42
  var matched;
60
43
  state.doc.descendants(function (node, pos) {
@@ -108,32 +91,4 @@ var findNodePosWithLocalId = function findNodePosWithLocalId(state, localId) {
108
91
  return nodes.length >= 1 ? nodes[0] : undefined;
109
92
  };
110
93
 
111
- exports.findNodePosWithLocalId = findNodePosWithLocalId;
112
-
113
- var onSelectionChanged = function onSelectionChanged(tr, state) {
114
- var selectedExtension = getSelectedExtensionByTransaction(tr, true);
115
- var hasUnselectedExtension = !!state.element && !selectedExtension;
116
- /*
117
- * We use this to indicate to our plugin that the selection has changed.
118
- *
119
- * - ignore if shouldRefreshEditButton already set
120
- * - restrict to scenarios when an extension is
121
- * - a) actually selected
122
- * - b) or un-selected (not accounting for selection extensionA -> extensionB)
123
- *
124
- * The rest of the logic will be handled in Extension main plugin view update().
125
- *
126
- * Known issue: typing inside of a bodiedExtension will trigger state changes each keystroke
127
- * as the toolbar always being open while it is focused.
128
- */
129
-
130
- if (!state.shouldRefreshEditButton && (selectedExtension || hasUnselectedExtension)) {
131
- return _objectSpread(_objectSpread({}, state), {}, {
132
- shouldRefreshEditButton: true
133
- });
134
- }
135
-
136
- return state;
137
- };
138
-
139
- exports.onSelectionChanged = onSelectionChanged;
94
+ exports.findNodePosWithLocalId = findNodePosWithLocalId;
@@ -94,7 +94,6 @@ var openFeedbackDialog = /*#__PURE__*/function () {
94
94
  case 13:
95
95
  timeoutId = window.setTimeout(showJiraCollectorDialog, 0); // Return the timoutId for consumers to call clearTimeout if they need to.
96
96
 
97
- // Return the timoutId for consumers to call clearTimeout if they need to.
98
97
  resolve(timeoutId);
99
98
 
100
99
  case 15:
@@ -263,7 +263,6 @@ var BatchDecorations = /*#__PURE__*/function () {
263
263
  } // only get those decorations whose from >= startPos
264
264
 
265
265
 
266
- // only get those decorations whose from >= startPos
267
266
  for (var i = 0; i < decorationsToRemove.length; i++) {
268
267
  if (decorationsToRemove[i].from >= startPos) {
269
268
  break;
@@ -700,7 +700,7 @@ function insertIntoPanel(tr, slice, panel) {
700
700
 
701
701
  function handleRichText(slice) {
702
702
  return function (state, dispatch) {
703
- var _slice$content, _panelParentOverCurre;
703
+ var _slice$content, _slice$content2, _panelParentOverCurre;
704
704
 
705
705
  var _state$schema$nodes2 = state.schema.nodes,
706
706
  codeBlock = _state$schema$nodes2.codeBlock,
@@ -708,7 +708,8 @@ function handleRichText(slice) {
708
708
  paragraph = _state$schema$nodes2.paragraph,
709
709
  panel = _state$schema$nodes2.panel;
710
710
  var selection = state.selection;
711
- var firstChildOfSlice = (_slice$content = slice.content) === null || _slice$content === void 0 ? void 0 : _slice$content.firstChild; // In case user is pasting inline code,
711
+ var firstChildOfSlice = (_slice$content = slice.content) === null || _slice$content === void 0 ? void 0 : _slice$content.firstChild;
712
+ var lastChildOfSlice = (_slice$content2 = slice.content) === null || _slice$content2 === void 0 ? void 0 : _slice$content2.lastChild; // In case user is pasting inline code,
712
713
  // any backtick ` immediately preceding it should be removed.
713
714
 
714
715
  var tr = state.tr;
@@ -723,7 +724,7 @@ function handleRichText(slice) {
723
724
 
724
725
  (0, _prosemirrorHistory.closeHistory)(tr);
725
726
  var isFirstChildListNode = (0, _node.isListNode)(firstChildOfSlice);
726
- var isLastChildListNode = (0, _node.isListNode)(firstChildOfSlice);
727
+ var isLastChildListNode = (0, _node.isListNode)(lastChildOfSlice);
727
728
  var isSliceContentListNodes = isFirstChildListNode || isLastChildListNode; // We want to use safeInsert to insert invalid content, as it inserts at the closest non schema violating position
728
729
  // rather than spliting the selection parent node in half (which is what replaceSelection does)
729
730
  // Exception is paragraph and heading nodes, these should be split, provided their parent supports the pasted content
@@ -742,9 +743,23 @@ function handleRichText(slice) {
742
743
  } else if (noNeedForSafeInsert) {
743
744
  tr.replaceSelection(slice);
744
745
  } else {
745
- // need safeInsert rather than replaceSelection, so that nodes aren't split in half
746
- // e.g. when pasting a layout into a table, replaceSelection splits the table in half and adds the layout in the middle
747
- tr = (0, _prosemirrorUtils.safeInsert)(slice.content, tr.selection.$to.pos)(tr);
746
+ // need to scan the slice if there's a block node inside it
747
+ var doesBlockNodeExist = false;
748
+ slice.content.nodesBetween(0, slice.content.size, function (node, start) {
749
+ if (start >= slice.openStart && start <= slice.content.size - slice.openEnd && node.isBlock) {
750
+ doesBlockNodeExist = true;
751
+ return false;
752
+ }
753
+ });
754
+
755
+ if ((0, _utils.insideTableCell)(state) && !doesBlockNodeExist) {
756
+ // bring back the old code for inline nodes
757
+ insertIntoPanel(tr, slice, panel);
758
+ } else {
759
+ // need safeInsert rather than replaceSelection, so that nodes aren't split in half
760
+ // e.g. when pasting a layout into a table, replaceSelection splits the table in half and adds the layout in the middle
761
+ tr = (0, _prosemirrorUtils.safeInsert)(slice.content, tr.selection.$to.pos)(tr);
762
+ }
748
763
  }
749
764
 
750
765
  tr.setStoredMarks([]);
@@ -303,9 +303,9 @@ var handleMouseMove = function handleMouseMove(view, event, tableCellOptimizatio
303
303
  var useMouseMoveOptimisation = tableCellOptimization && mouseMoveOptimization;
304
304
 
305
305
  if (!(0, _utils4.isResizeHandleDecoration)(element) && (0, _utils4.isCell)(element)) {
306
- var _positionColumn = (0, _utils4.getMousePositionHorizontalRelativeByElement)(event, useMouseMoveOptimisation, elementContentRects, _types.RESIZE_HANDLE_AREA_DECORATION_GAP);
306
+ var positionColumn = (0, _utils4.getMousePositionHorizontalRelativeByElement)(event, useMouseMoveOptimisation, elementContentRects, _types.RESIZE_HANDLE_AREA_DECORATION_GAP);
307
307
 
308
- if (_positionColumn !== null) {
308
+ if (positionColumn !== null) {
309
309
  var _state4 = view.state,
310
310
  _dispatch5 = view.dispatch;
311
311
 
@@ -317,7 +317,7 @@ var handleMouseMove = function handleMouseMove(view, event, tableCellOptimizatio
317
317
  var rect = (0, _utils.findCellRectClosestToPos)(_state4.doc.resolve(cellStartPosition));
318
318
 
319
319
  if (rect) {
320
- var columnEndIndexTarget = _positionColumn === 'left' ? rect.left : rect.right;
320
+ var columnEndIndexTarget = positionColumn === 'left' ? rect.left : rect.right;
321
321
 
322
322
  if (columnEndIndexTarget !== resizeHandleColumnIndex || !(0, _utils4.hasResizeHandler)({
323
323
  target: element,
@@ -164,7 +164,7 @@ var checkFormattingIsPresent = function checkFormattingIsPresent(state) {
164
164
  exports.checkFormattingIsPresent = checkFormattingIsPresent;
165
165
 
166
166
  var usePreviousObjectState = function usePreviousObjectState(value) {
167
- var ref = (0, _react.useRef)();
167
+ var ref = (0, _react.useRef)([]);
168
168
  (0, _react.useEffect)(function () {
169
169
  ref.current = value;
170
170
  });
@@ -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 = "166.0.1";
9
+ var version = "166.0.4";
10
10
  exports.version = version;
11
11
 
12
12
  var nextMajorVersion = function nextMajorVersion() {
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-core",
3
- "version": "166.0.1",
3
+ "version": "166.0.4",
4
4
  "sideEffects": false
5
5
  }
@@ -1,7 +1,6 @@
1
1
  import { pluginFactory } from '../../utils/plugin-state-factory';
2
2
  import reducer from './reducer';
3
3
  import { pluginKey } from './plugin-key';
4
- import { onSelectionChanged } from './utils';
5
4
  const factory = pluginFactory(pluginKey, reducer, {
6
5
  mapping(tr, state) {
7
6
  const {
@@ -22,9 +21,8 @@ const factory = pluginFactory(pluginKey, reducer, {
22
21
  return { ...state,
23
22
  positions
24
23
  };
25
- },
24
+ }
26
25
 
27
- onSelectionChanged: onSelectionChanged
28
26
  });
29
27
  export const createPluginState = factory.createPluginState;
30
28
  export const createCommand = factory.createCommand;
@@ -97,7 +97,6 @@ export const createContextIdentifierProviderHandler = view => async (name, provi
97
97
 
98
98
  const createPlugin = (dispatch, providerFactory, extensionHandlers, portalProviderAPI, eventDispatcher, useLongPressSelection = false, options = {}) => {
99
99
  const state = createPluginState(dispatch, {
100
- shouldRefreshEditButton: false,
101
100
  showEditButton: false,
102
101
  showContextPanel: false
103
102
  });
@@ -122,48 +121,27 @@ const createPlugin = (dispatch, providerFactory, extensionHandlers, portalProvid
122
121
  element,
123
122
  localId,
124
123
  extensionProvider,
125
- showContextPanel,
126
- shouldRefreshEditButton
127
- } = getPluginState(state);
124
+ showContextPanel
125
+ } = getPluginState(state); // This fetches the selected extension node, either by keyboard selection or click for all types of extensions
128
126
 
129
- if (!shouldRefreshEditButton) {
130
- return false;
131
- } // This fetches the selected extension node, either by keyboard selection or click for all types of extensions
132
-
133
-
134
- const selectedExtension = getSelectedExtension(state, true); // If our selection isn't on an extension node, clear some state and hide the config panel
127
+ const selectedExtension = getSelectedExtension(state, true);
135
128
 
136
129
  if (!selectedExtension) {
137
130
  if (showContextPanel) {
138
131
  clearEditingContext(state, dispatch);
139
132
  }
140
133
 
141
- updateState({
142
- shouldRefreshEditButton: false,
143
- localId: undefined,
144
- element: undefined,
145
- showEditButton: false,
146
- updateExtension: undefined
147
- })(state, dispatch);
148
134
  return;
149
- } // By this point we're certain we've selected an extension node.
150
- // But we need to determine if the selection has changed to another
151
- // extension node or remained on the same node.
152
-
135
+ }
153
136
 
154
137
  const {
155
138
  node
156
139
  } = selectedExtension;
157
140
  const newElement = getSelectedDomElement(state.schema, domAtPos, selectedExtension); // New node is selection
158
141
 
159
- const hasSelectedNodeChanged = node.attrs.localId ? localId !== node.attrs.localId : // This is the current assumption and it's wrong but we are keeping it
142
+ if (node.attrs.localId ? localId !== node.attrs.localId : // This is the current assumption and it's wrong but we are keeping it
160
143
  // as fallback in case we need to turn off `allowLocalIdGeneration`
161
- element !== newElement;
162
- const nextState = {
163
- shouldRefreshEditButton: false
164
- };
165
-
166
- if (hasSelectedNodeChanged) {
144
+ element !== newElement) {
167
145
  if (showContextPanel) {
168
146
  clearEditingContext(state, dispatch);
169
147
  }
@@ -176,20 +154,20 @@ const createPlugin = (dispatch, providerFactory, extensionHandlers, portalProvid
176
154
  const showEditButton = shouldShowEditButton(extensionHandler, extensionProvider);
177
155
  const updateExtension = getUpdateExtensionPromise(view, extensionHandler, extensionProvider).catch(() => {// do nothing;
178
156
  });
179
- Object.assign(nextState, {
157
+ updateState({
180
158
  localId: node.attrs.localId,
159
+ showContextPanel: false,
181
160
  element: newElement,
182
161
  showEditButton,
183
162
  updateExtension
184
- });
163
+ })(state, dispatch);
185
164
  } // New DOM element doesn't necessarily mean it's a new Node
186
165
  else if (element !== newElement) {
187
- Object.assign(nextState, {
166
+ updateState({
188
167
  element: newElement
189
- });
168
+ })(state, dispatch);
190
169
  }
191
170
 
192
- updateState(nextState)(state, dispatch);
193
171
  return true;
194
172
  },
195
173
  destroy: () => {
@@ -205,11 +183,7 @@ const createPlugin = (dispatch, providerFactory, extensionHandlers, portalProvid
205
183
  bodiedExtension: ExtensionNodeView(portalProviderAPI, eventDispatcher, providerFactory, extensionHandlers, extensionNodeViewOptions),
206
184
  inlineExtension: ExtensionNodeView(portalProviderAPI, eventDispatcher, providerFactory, extensionHandlers, extensionNodeViewOptions)
207
185
  },
208
- handleClickOn: createSelectionClickHandler(['extension', 'bodiedExtension'], target => {
209
- // Clicked on anything around the extension content
210
- // or specifically on the content border of a bodied extension
211
- return !target.closest('.extension-content') || target.classList.contains('extension-content');
212
- }, {
186
+ handleClickOn: createSelectionClickHandler(['extension', 'bodiedExtension'], target => !target.closest('.extension-content'), {
213
187
  useLongPressSelection
214
188
  })
215
189
  }
@@ -1,25 +1,15 @@
1
1
  import { findParentNodeOfType, findSelectedNodeOfType, findDomRefAtPos } from 'prosemirror-utils';
2
2
  import { closestElement } from '../../utils/dom';
3
3
  import { findNodePosByLocalIds } from '../../utils/nodes-by-localIds';
4
-
5
- const getSelectedExtensionByTransaction = (transaction, searchParent = true) => {
6
- return _getSelectedExtension(transaction.doc.type.schema, transaction.selection, searchParent);
7
- };
8
-
9
4
  export const getSelectedExtension = (state, searchParent = false) => {
10
- return _getSelectedExtension(state.schema, state.selection, searchParent);
11
- };
12
-
13
- const _getSelectedExtension = (schema, selection, searchParent) => {
14
5
  const {
15
6
  inlineExtension,
16
7
  extension,
17
8
  bodiedExtension
18
- } = schema.nodes;
9
+ } = state.schema.nodes;
19
10
  const nodeTypes = [extension, bodiedExtension, inlineExtension];
20
- return findSelectedNodeOfType(nodeTypes)(selection) || searchParent && findParentNodeOfType(nodeTypes)(selection) || undefined;
11
+ return findSelectedNodeOfType(nodeTypes)(state.selection) || searchParent && findParentNodeOfType(nodeTypes)(state.selection) || undefined;
21
12
  };
22
-
23
13
  export const findExtensionWithLocalId = (state, localId) => {
24
14
  const selectedExtension = getSelectedExtension(state, true);
25
15
 
@@ -72,29 +62,4 @@ export const getNodeTypesReferenced = (ids, state) => {
72
62
  export const findNodePosWithLocalId = (state, localId) => {
73
63
  const nodes = findNodePosByLocalIds(state, [localId]);
74
64
  return nodes.length >= 1 ? nodes[0] : undefined;
75
- };
76
- export const onSelectionChanged = (tr, state) => {
77
- const selectedExtension = getSelectedExtensionByTransaction(tr, true);
78
- const hasUnselectedExtension = !!state.element && !selectedExtension;
79
- /*
80
- * We use this to indicate to our plugin that the selection has changed.
81
- *
82
- * - ignore if shouldRefreshEditButton already set
83
- * - restrict to scenarios when an extension is
84
- * - a) actually selected
85
- * - b) or un-selected (not accounting for selection extensionA -> extensionB)
86
- *
87
- * The rest of the logic will be handled in Extension main plugin view update().
88
- *
89
- * Known issue: typing inside of a bodiedExtension will trigger state changes each keystroke
90
- * as the toolbar always being open while it is focused.
91
- */
92
-
93
- if (!state.shouldRefreshEditButton && (selectedExtension || hasUnselectedExtension)) {
94
- return { ...state,
95
- shouldRefreshEditButton: true
96
- };
97
- }
98
-
99
- return state;
100
65
  };
@@ -2,7 +2,7 @@ import { closeHistory } from 'prosemirror-history';
2
2
  import { Fragment, Node as PMNode, Slice } from 'prosemirror-model';
3
3
  import { TextSelection, NodeSelection } from 'prosemirror-state';
4
4
  import { findParentNodeOfType, hasParentNodeOfType, safeInsert } from 'prosemirror-utils';
5
- import { compose, insideTable, isParagraph, isText, isLinkMark, processRawValue } from '../../utils';
5
+ import { compose, insideTable, isParagraph, isText, isLinkMark, processRawValue, insideTableCell } from '../../utils';
6
6
  import { mapSlice } from '../../utils/slice';
7
7
  import { INPUT_METHOD } from '../analytics';
8
8
  import { insertCard, queueCardsFromChangedTr } from '../card/pm-plugins/doc';
@@ -610,7 +610,7 @@ export function insertIntoPanel(tr, slice, panel) {
610
610
  }
611
611
  export function handleRichText(slice) {
612
612
  return (state, dispatch) => {
613
- var _slice$content, _panelParentOverCurre;
613
+ var _slice$content, _slice$content2, _panelParentOverCurre;
614
614
 
615
615
  const {
616
616
  codeBlock,
@@ -621,7 +621,8 @@ export function handleRichText(slice) {
621
621
  const {
622
622
  selection
623
623
  } = state;
624
- const firstChildOfSlice = (_slice$content = slice.content) === null || _slice$content === void 0 ? void 0 : _slice$content.firstChild; // In case user is pasting inline code,
624
+ const firstChildOfSlice = (_slice$content = slice.content) === null || _slice$content === void 0 ? void 0 : _slice$content.firstChild;
625
+ const lastChildOfSlice = (_slice$content2 = slice.content) === null || _slice$content2 === void 0 ? void 0 : _slice$content2.lastChild; // In case user is pasting inline code,
625
626
  // any backtick ` immediately preceding it should be removed.
626
627
 
627
628
  let tr = state.tr;
@@ -636,7 +637,7 @@ export function handleRichText(slice) {
636
637
 
637
638
  closeHistory(tr);
638
639
  const isFirstChildListNode = isListNode(firstChildOfSlice);
639
- const isLastChildListNode = isListNode(firstChildOfSlice);
640
+ const isLastChildListNode = isListNode(lastChildOfSlice);
640
641
  const isSliceContentListNodes = isFirstChildListNode || isLastChildListNode; // We want to use safeInsert to insert invalid content, as it inserts at the closest non schema violating position
641
642
  // rather than spliting the selection parent node in half (which is what replaceSelection does)
642
643
  // Exception is paragraph and heading nodes, these should be split, provided their parent supports the pasted content
@@ -655,9 +656,23 @@ export function handleRichText(slice) {
655
656
  } else if (noNeedForSafeInsert) {
656
657
  tr.replaceSelection(slice);
657
658
  } else {
658
- // need safeInsert rather than replaceSelection, so that nodes aren't split in half
659
- // e.g. when pasting a layout into a table, replaceSelection splits the table in half and adds the layout in the middle
660
- tr = safeInsert(slice.content, tr.selection.$to.pos)(tr);
659
+ // need to scan the slice if there's a block node inside it
660
+ let doesBlockNodeExist = false;
661
+ slice.content.nodesBetween(0, slice.content.size, (node, start) => {
662
+ if (start >= slice.openStart && start <= slice.content.size - slice.openEnd && node.isBlock) {
663
+ doesBlockNodeExist = true;
664
+ return false;
665
+ }
666
+ });
667
+
668
+ if (insideTableCell(state) && !doesBlockNodeExist) {
669
+ // bring back the old code for inline nodes
670
+ insertIntoPanel(tr, slice, panel);
671
+ } else {
672
+ // need safeInsert rather than replaceSelection, so that nodes aren't split in half
673
+ // e.g. when pasting a layout into a table, replaceSelection splits the table in half and adds the layout in the middle
674
+ tr = safeInsert(slice.content, tr.selection.$to.pos)(tr);
675
+ }
661
676
  }
662
677
 
663
678
  tr.setStoredMarks([]);
@@ -134,7 +134,7 @@ export const checkFormattingIsPresent = state => {
134
134
  return marksArePresent(state) || blockStylingIsPresent(state);
135
135
  };
136
136
  export const usePreviousObjectState = value => {
137
- const ref = useRef();
137
+ const ref = useRef([]);
138
138
  useEffect(() => {
139
139
  ref.current = value;
140
140
  });
@@ -1,5 +1,5 @@
1
1
  export const name = "@atlaskit/editor-core";
2
- export const version = "166.0.1";
2
+ export const version = "166.0.4";
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": "166.0.1",
3
+ "version": "166.0.4",
4
4
  "sideEffects": false
5
5
  }
@@ -52,7 +52,6 @@ var _pluginFactory = pluginFactory(inlineCommentPluginKey, reducer, {
52
52
  } // return same pluginState if mappings did not change
53
53
 
54
54
 
55
- // return same pluginState if mappings did not change
56
55
  if (mappedBookmark === bookmark && mappedDecorationSet === draftDecorationSet) {
57
56
  return pluginState;
58
57
  }
@@ -7,7 +7,6 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
7
7
  import { pluginFactory } from '../../utils/plugin-state-factory';
8
8
  import reducer from './reducer';
9
9
  import { pluginKey } from './plugin-key';
10
- import { onSelectionChanged } from './utils';
11
10
  var factory = pluginFactory(pluginKey, reducer, {
12
11
  mapping: function mapping(tr, state) {
13
12
  var _ref = state,
@@ -26,8 +25,7 @@ var factory = pluginFactory(pluginKey, reducer, {
26
25
  return _objectSpread(_objectSpread({}, state), {}, {
27
26
  positions: positions
28
27
  });
29
- },
30
- onSelectionChanged: onSelectionChanged
28
+ }
31
29
  });
32
30
  export var createPluginState = factory.createPluginState;
33
31
  export var createCommand = factory.createCommand;
@@ -251,7 +251,6 @@ var createPlugin = function createPlugin(dispatch, providerFactory, extensionHan
251
251
  var useLongPressSelection = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
252
252
  var options = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : {};
253
253
  var state = createPluginState(dispatch, {
254
- shouldRefreshEditButton: false,
255
254
  showEditButton: false,
256
255
  showContextPanel: false
257
256
  });
@@ -275,45 +274,25 @@ var createPlugin = function createPlugin(dispatch, providerFactory, extensionHan
275
274
  element = _getPluginState.element,
276
275
  localId = _getPluginState.localId,
277
276
  extensionProvider = _getPluginState.extensionProvider,
278
- showContextPanel = _getPluginState.showContextPanel,
279
- shouldRefreshEditButton = _getPluginState.shouldRefreshEditButton;
277
+ showContextPanel = _getPluginState.showContextPanel; // This fetches the selected extension node, either by keyboard selection or click for all types of extensions
280
278
 
281
- if (!shouldRefreshEditButton) {
282
- return false;
283
- } // This fetches the selected extension node, either by keyboard selection or click for all types of extensions
284
279
 
285
-
286
- var selectedExtension = getSelectedExtension(state, true); // If our selection isn't on an extension node, clear some state and hide the config panel
280
+ var selectedExtension = getSelectedExtension(state, true);
287
281
 
288
282
  if (!selectedExtension) {
289
283
  if (showContextPanel) {
290
284
  clearEditingContext(state, dispatch);
291
285
  }
292
286
 
293
- updateState({
294
- shouldRefreshEditButton: false,
295
- localId: undefined,
296
- element: undefined,
297
- showEditButton: false,
298
- updateExtension: undefined
299
- })(state, dispatch);
300
287
  return;
301
- } // By this point we're certain we've selected an extension node.
302
- // But we need to determine if the selection has changed to another
303
- // extension node or remained on the same node.
304
-
288
+ }
305
289
 
306
290
  var node = selectedExtension.node;
307
291
  var newElement = getSelectedDomElement(state.schema, domAtPos, selectedExtension); // New node is selection
308
292
 
309
- var hasSelectedNodeChanged = node.attrs.localId ? localId !== node.attrs.localId : // This is the current assumption and it's wrong but we are keeping it
293
+ if (node.attrs.localId ? localId !== node.attrs.localId : // This is the current assumption and it's wrong but we are keeping it
310
294
  // as fallback in case we need to turn off `allowLocalIdGeneration`
311
- element !== newElement;
312
- var nextState = {
313
- shouldRefreshEditButton: false
314
- };
315
-
316
- if (hasSelectedNodeChanged) {
295
+ element !== newElement) {
317
296
  if (showContextPanel) {
318
297
  clearEditingContext(state, dispatch);
319
298
  }
@@ -324,20 +303,20 @@ var createPlugin = function createPlugin(dispatch, providerFactory, extensionHan
324
303
  var showEditButton = shouldShowEditButton(extensionHandler, extensionProvider);
325
304
  var updateExtension = getUpdateExtensionPromise(view, extensionHandler, extensionProvider).catch(function () {// do nothing;
326
305
  });
327
- Object.assign(nextState, {
306
+ updateState({
328
307
  localId: node.attrs.localId,
308
+ showContextPanel: false,
329
309
  element: newElement,
330
310
  showEditButton: showEditButton,
331
311
  updateExtension: updateExtension
332
- });
312
+ })(state, dispatch);
333
313
  } // New DOM element doesn't necessarily mean it's a new Node
334
314
  else if (element !== newElement) {
335
- Object.assign(nextState, {
315
+ updateState({
336
316
  element: newElement
337
- });
317
+ })(state, dispatch);
338
318
  }
339
319
 
340
- updateState(nextState)(state, dispatch);
341
320
  return true;
342
321
  },
343
322
  destroy: function destroy() {
@@ -354,9 +333,7 @@ var createPlugin = function createPlugin(dispatch, providerFactory, extensionHan
354
333
  inlineExtension: ExtensionNodeView(portalProviderAPI, eventDispatcher, providerFactory, extensionHandlers, extensionNodeViewOptions)
355
334
  },
356
335
  handleClickOn: createSelectionClickHandler(['extension', 'bodiedExtension'], function (target) {
357
- // Clicked on anything around the extension content
358
- // or specifically on the content border of a bodied extension
359
- return !target.closest('.extension-content') || target.classList.contains('extension-content');
336
+ return !target.closest('.extension-content');
360
337
  }, {
361
338
  useLongPressSelection: useLongPressSelection
362
339
  })
@@ -1,32 +1,15 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
-
3
- 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; }
4
-
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
-
7
1
  import { findParentNodeOfType, findSelectedNodeOfType, findDomRefAtPos } from 'prosemirror-utils';
8
2
  import { closestElement } from '../../utils/dom';
9
3
  import { findNodePosByLocalIds } from '../../utils/nodes-by-localIds';
10
-
11
- var getSelectedExtensionByTransaction = function getSelectedExtensionByTransaction(transaction) {
12
- var searchParent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
13
- return _getSelectedExtension(transaction.doc.type.schema, transaction.selection, searchParent);
14
- };
15
-
16
4
  export var getSelectedExtension = function getSelectedExtension(state) {
17
5
  var searchParent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
18
- return _getSelectedExtension(state.schema, state.selection, searchParent);
19
- };
20
-
21
- var _getSelectedExtension = function _getSelectedExtension(schema, selection, searchParent) {
22
- var _schema$nodes = schema.nodes,
23
- inlineExtension = _schema$nodes.inlineExtension,
24
- extension = _schema$nodes.extension,
25
- bodiedExtension = _schema$nodes.bodiedExtension;
6
+ var _state$schema$nodes = state.schema.nodes,
7
+ inlineExtension = _state$schema$nodes.inlineExtension,
8
+ extension = _state$schema$nodes.extension,
9
+ bodiedExtension = _state$schema$nodes.bodiedExtension;
26
10
  var nodeTypes = [extension, bodiedExtension, inlineExtension];
27
- return findSelectedNodeOfType(nodeTypes)(selection) || searchParent && findParentNodeOfType(nodeTypes)(selection) || undefined;
11
+ return findSelectedNodeOfType(nodeTypes)(state.selection) || searchParent && findParentNodeOfType(nodeTypes)(state.selection) || undefined;
28
12
  };
29
-
30
13
  export var findExtensionWithLocalId = function findExtensionWithLocalId(state, localId) {
31
14
  var selectedExtension = getSelectedExtension(state, true);
32
15
 
@@ -38,10 +21,10 @@ export var findExtensionWithLocalId = function findExtensionWithLocalId(state, l
38
21
  return selectedExtension;
39
22
  }
40
23
 
41
- var _state$schema$nodes = state.schema.nodes,
42
- inlineExtension = _state$schema$nodes.inlineExtension,
43
- extension = _state$schema$nodes.extension,
44
- bodiedExtension = _state$schema$nodes.bodiedExtension;
24
+ var _state$schema$nodes2 = state.schema.nodes,
25
+ inlineExtension = _state$schema$nodes2.inlineExtension,
26
+ extension = _state$schema$nodes2.extension,
27
+ bodiedExtension = _state$schema$nodes2.bodiedExtension;
45
28
  var nodeTypes = [extension, bodiedExtension, inlineExtension];
46
29
  var matched;
47
30
  state.doc.descendants(function (node, pos) {
@@ -81,29 +64,4 @@ export var getNodeTypesReferenced = function getNodeTypesReferenced(ids, state)
81
64
  export var findNodePosWithLocalId = function findNodePosWithLocalId(state, localId) {
82
65
  var nodes = findNodePosByLocalIds(state, [localId]);
83
66
  return nodes.length >= 1 ? nodes[0] : undefined;
84
- };
85
- export var onSelectionChanged = function onSelectionChanged(tr, state) {
86
- var selectedExtension = getSelectedExtensionByTransaction(tr, true);
87
- var hasUnselectedExtension = !!state.element && !selectedExtension;
88
- /*
89
- * We use this to indicate to our plugin that the selection has changed.
90
- *
91
- * - ignore if shouldRefreshEditButton already set
92
- * - restrict to scenarios when an extension is
93
- * - a) actually selected
94
- * - b) or un-selected (not accounting for selection extensionA -> extensionB)
95
- *
96
- * The rest of the logic will be handled in Extension main plugin view update().
97
- *
98
- * Known issue: typing inside of a bodiedExtension will trigger state changes each keystroke
99
- * as the toolbar always being open while it is focused.
100
- */
101
-
102
- if (!state.shouldRefreshEditButton && (selectedExtension || hasUnselectedExtension)) {
103
- return _objectSpread(_objectSpread({}, state), {}, {
104
- shouldRefreshEditButton: true
105
- });
106
- }
107
-
108
- return state;
109
67
  };
@@ -74,7 +74,6 @@ export var openFeedbackDialog = /*#__PURE__*/function () {
74
74
  case 13:
75
75
  timeoutId = window.setTimeout(showJiraCollectorDialog, 0); // Return the timoutId for consumers to call clearTimeout if they need to.
76
76
 
77
- // Return the timoutId for consumers to call clearTimeout if they need to.
78
77
  resolve(timeoutId);
79
78
 
80
79
  case 15:
@@ -248,7 +248,6 @@ var BatchDecorations = /*#__PURE__*/function () {
248
248
  } // only get those decorations whose from >= startPos
249
249
 
250
250
 
251
- // only get those decorations whose from >= startPos
252
251
  for (var i = 0; i < decorationsToRemove.length; i++) {
253
252
  if (decorationsToRemove[i].from >= startPos) {
254
253
  break;
@@ -16,7 +16,7 @@ import { closeHistory } from 'prosemirror-history';
16
16
  import { Fragment, Node as PMNode, Slice } from 'prosemirror-model';
17
17
  import { TextSelection, NodeSelection } from 'prosemirror-state';
18
18
  import { findParentNodeOfType, hasParentNodeOfType, safeInsert } from 'prosemirror-utils';
19
- import { compose, insideTable, isParagraph, isText, isLinkMark, processRawValue } from '../../utils';
19
+ import { compose, insideTable, isParagraph, isText, isLinkMark, processRawValue, insideTableCell } from '../../utils';
20
20
  import { mapSlice } from '../../utils/slice';
21
21
  import { INPUT_METHOD } from '../analytics';
22
22
  import { insertCard, queueCardsFromChangedTr } from '../card/pm-plugins/doc';
@@ -644,7 +644,7 @@ export function insertIntoPanel(tr, slice, panel) {
644
644
  }
645
645
  export function handleRichText(slice) {
646
646
  return function (state, dispatch) {
647
- var _slice$content, _panelParentOverCurre;
647
+ var _slice$content, _slice$content2, _panelParentOverCurre;
648
648
 
649
649
  var _state$schema$nodes2 = state.schema.nodes,
650
650
  codeBlock = _state$schema$nodes2.codeBlock,
@@ -652,7 +652,8 @@ export function handleRichText(slice) {
652
652
  paragraph = _state$schema$nodes2.paragraph,
653
653
  panel = _state$schema$nodes2.panel;
654
654
  var selection = state.selection;
655
- var firstChildOfSlice = (_slice$content = slice.content) === null || _slice$content === void 0 ? void 0 : _slice$content.firstChild; // In case user is pasting inline code,
655
+ var firstChildOfSlice = (_slice$content = slice.content) === null || _slice$content === void 0 ? void 0 : _slice$content.firstChild;
656
+ var lastChildOfSlice = (_slice$content2 = slice.content) === null || _slice$content2 === void 0 ? void 0 : _slice$content2.lastChild; // In case user is pasting inline code,
656
657
  // any backtick ` immediately preceding it should be removed.
657
658
 
658
659
  var tr = state.tr;
@@ -667,7 +668,7 @@ export function handleRichText(slice) {
667
668
 
668
669
  closeHistory(tr);
669
670
  var isFirstChildListNode = isListNode(firstChildOfSlice);
670
- var isLastChildListNode = isListNode(firstChildOfSlice);
671
+ var isLastChildListNode = isListNode(lastChildOfSlice);
671
672
  var isSliceContentListNodes = isFirstChildListNode || isLastChildListNode; // We want to use safeInsert to insert invalid content, as it inserts at the closest non schema violating position
672
673
  // rather than spliting the selection parent node in half (which is what replaceSelection does)
673
674
  // Exception is paragraph and heading nodes, these should be split, provided their parent supports the pasted content
@@ -686,9 +687,23 @@ export function handleRichText(slice) {
686
687
  } else if (noNeedForSafeInsert) {
687
688
  tr.replaceSelection(slice);
688
689
  } else {
689
- // need safeInsert rather than replaceSelection, so that nodes aren't split in half
690
- // e.g. when pasting a layout into a table, replaceSelection splits the table in half and adds the layout in the middle
691
- tr = safeInsert(slice.content, tr.selection.$to.pos)(tr);
690
+ // need to scan the slice if there's a block node inside it
691
+ var doesBlockNodeExist = false;
692
+ slice.content.nodesBetween(0, slice.content.size, function (node, start) {
693
+ if (start >= slice.openStart && start <= slice.content.size - slice.openEnd && node.isBlock) {
694
+ doesBlockNodeExist = true;
695
+ return false;
696
+ }
697
+ });
698
+
699
+ if (insideTableCell(state) && !doesBlockNodeExist) {
700
+ // bring back the old code for inline nodes
701
+ insertIntoPanel(tr, slice, panel);
702
+ } else {
703
+ // need safeInsert rather than replaceSelection, so that nodes aren't split in half
704
+ // e.g. when pasting a layout into a table, replaceSelection splits the table in half and adds the layout in the middle
705
+ tr = safeInsert(slice.content, tr.selection.$to.pos)(tr);
706
+ }
692
707
  }
693
708
 
694
709
  tr.setStoredMarks([]);
@@ -254,9 +254,9 @@ export var handleMouseMove = function handleMouseMove(view, event, tableCellOpti
254
254
  var useMouseMoveOptimisation = tableCellOptimization && mouseMoveOptimization;
255
255
 
256
256
  if (!isResizeHandleDecoration(element) && isCell(element)) {
257
- var _positionColumn = getMousePositionHorizontalRelativeByElement(event, useMouseMoveOptimisation, elementContentRects, RESIZE_HANDLE_AREA_DECORATION_GAP);
257
+ var positionColumn = getMousePositionHorizontalRelativeByElement(event, useMouseMoveOptimisation, elementContentRects, RESIZE_HANDLE_AREA_DECORATION_GAP);
258
258
 
259
- if (_positionColumn !== null) {
259
+ if (positionColumn !== null) {
260
260
  var _state4 = view.state,
261
261
  _dispatch5 = view.dispatch;
262
262
 
@@ -268,7 +268,7 @@ export var handleMouseMove = function handleMouseMove(view, event, tableCellOpti
268
268
  var rect = findCellRectClosestToPos(_state4.doc.resolve(cellStartPosition));
269
269
 
270
270
  if (rect) {
271
- var columnEndIndexTarget = _positionColumn === 'left' ? rect.left : rect.right;
271
+ var columnEndIndexTarget = positionColumn === 'left' ? rect.left : rect.right;
272
272
 
273
273
  if (columnEndIndexTarget !== resizeHandleColumnIndex || !hasResizeHandler({
274
274
  target: element,
@@ -130,7 +130,7 @@ export var checkFormattingIsPresent = function checkFormattingIsPresent(state) {
130
130
  return marksArePresent(state) || blockStylingIsPresent(state);
131
131
  };
132
132
  export var usePreviousObjectState = function usePreviousObjectState(value) {
133
- var ref = useRef();
133
+ var ref = useRef([]);
134
134
  useEffect(function () {
135
135
  ref.current = value;
136
136
  });
@@ -1,5 +1,5 @@
1
1
  export var name = "@atlaskit/editor-core";
2
- export var version = "166.0.1";
2
+ export var version = "166.0.4";
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": "166.0.1",
3
+ "version": "166.0.4",
4
4
  "sideEffects": false
5
5
  }
@@ -6,7 +6,6 @@ import type { ContextIdentifierProvider } from '@atlaskit/editor-common/provider
6
6
  import { EditorAppearance } from '../../../types/editor-appearance';
7
7
  import { Dispatch, EventDispatcher } from '../../../event-dispatcher';
8
8
  import { PortalProviderAPI } from '../../../ui/PortalProvider';
9
- import type { ExtensionState } from '../types';
10
9
  import { getPluginState, createCommand } from '../plugin-factory';
11
10
  import { pluginKey } from '../plugin-key';
12
11
  export declare const updateEditButton: (view: EditorView, extensionProvider: ExtensionProvider) => Promise<UpdateExtension<any> | undefined>;
@@ -14,5 +13,5 @@ export declare const createExtensionProviderHandler: (view: EditorView) => (name
14
13
  export declare const createContextIdentifierProviderHandler: (view: EditorView) => (name: string, provider?: Promise<ContextIdentifierProvider> | undefined) => Promise<void>;
15
14
  declare const createPlugin: (dispatch: Dispatch, providerFactory: ProviderFactory, extensionHandlers: ExtensionHandlers, portalProviderAPI: PortalProviderAPI, eventDispatcher: EventDispatcher, useLongPressSelection?: boolean, options?: {
16
15
  appearance?: EditorAppearance;
17
- }) => SafePlugin<ExtensionState<import("@atlaskit/editor-common/extensions").Parameters>, import("prosemirror-model").Schema<any, any>>;
16
+ }) => SafePlugin<import("../types").ExtensionState<import("@atlaskit/editor-common/extensions").Parameters>, import("prosemirror-model").Schema<any, any>>;
18
17
  export { pluginKey, createPlugin, createCommand, getPluginState };
@@ -3,7 +3,6 @@ import { UpdateExtension, ExtensionProvider, Parameters, TransformBefore, Transf
3
3
  export declare type ExtensionState<T extends Parameters = Parameters> = {
4
4
  localId?: string;
5
5
  autoSaveResolve?: () => void;
6
- shouldRefreshEditButton: boolean;
7
6
  showEditButton: boolean;
8
7
  showContextPanel: boolean;
9
8
  updateExtension?: Promise<UpdateExtension<T> | void>;
@@ -1,12 +1,10 @@
1
1
  import { Schema, Mark } from 'prosemirror-model';
2
- import { EditorState, ReadonlyTransaction } from 'prosemirror-state';
2
+ import { EditorState } from 'prosemirror-state';
3
3
  import { Node as PMNode } from 'prosemirror-model';
4
4
  import { NodeWithPos, DomAtPos } from 'prosemirror-utils';
5
- import type { ExtensionState } from './types';
6
5
  export declare const getSelectedExtension: (state: EditorState, searchParent?: boolean) => import("prosemirror-utils").ContentNodeWithPos | undefined;
7
6
  export declare const findExtensionWithLocalId: (state: EditorState, localId?: string | undefined) => NodeWithPos | undefined;
8
7
  export declare const getSelectedDomElement: (schema: Schema, domAtPos: DomAtPos, selectedExtensionNode: NodeWithPos) => HTMLElement;
9
8
  export declare const getDataConsumerMark: (newNode: PMNode) => Mark | undefined;
10
9
  export declare const getNodeTypesReferenced: (ids: string[], state: EditorState) => string[];
11
10
  export declare const findNodePosWithLocalId: (state: EditorState, localId: string) => NodeWithPos | undefined;
12
- export declare const onSelectionChanged: (tr: ReadonlyTransaction, state: ExtensionState) => ExtensionState;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-core",
3
- "version": "166.0.1",
3
+ "version": "166.0.4",
4
4
  "description": "A package contains Atlassian editor core functionality",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -69,7 +69,7 @@
69
69
  "@atlaskit/radio": "^5.3.0",
70
70
  "@atlaskit/section-message": "^6.1.0",
71
71
  "@atlaskit/select": "^15.2.0",
72
- "@atlaskit/smart-user-picker": "^5.0.2",
72
+ "@atlaskit/smart-user-picker": "^5.1.0",
73
73
  "@atlaskit/spinner": "^15.1.0",
74
74
  "@atlaskit/status": "^1.1.0",
75
75
  "@atlaskit/tabs": "^13.2.0",
@@ -159,7 +159,7 @@
159
159
  "@atlaskit/section-message": "^6.1.0",
160
160
  "@atlaskit/share": "*",
161
161
  "@atlaskit/smart-card": "^19.1.0",
162
- "@atlaskit/smart-user-picker": "^5.0.2",
162
+ "@atlaskit/smart-user-picker": "^5.1.0",
163
163
  "@atlaskit/synchrony-test-helpers": "^2.3.0",
164
164
  "@atlaskit/textarea": "^4.3.0",
165
165
  "@atlaskit/toggle": "^12.4.0",
@@ -168,7 +168,7 @@
168
168
  "@atlaskit/visual-regression": "*",
169
169
  "@atlaskit/webdriver-runner": "*",
170
170
  "@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1",
171
- "@atlassian/search-provider": "2.2.4",
171
+ "@atlassian/search-provider": "2.3.0",
172
172
  "@atlassian/ufo": "^0.1.0",
173
173
  "@emotion/jest": "^11.8.0",
174
174
  "@testing-library/dom": "^7.7.3",