@atlaskit/editor-common 74.30.0 → 74.31.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 (67) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cjs/lists/analytics.js +40 -0
  3. package/dist/cjs/lists/indentation.js +24 -0
  4. package/dist/cjs/lists/index.js +89 -0
  5. package/dist/cjs/lists/node.js +97 -0
  6. package/dist/cjs/lists/replace-content.js +24 -0
  7. package/dist/cjs/lists/selection.js +59 -0
  8. package/dist/cjs/monitoring/error.js +1 -1
  9. package/dist/cjs/node-width/index.js +10 -2
  10. package/dist/cjs/ui/DropList/index.js +1 -1
  11. package/dist/cjs/utils/commands.js +110 -2
  12. package/dist/cjs/utils/document.js +26 -1
  13. package/dist/cjs/utils/index.js +51 -2
  14. package/dist/cjs/utils/prosemirror/autojoin.js +68 -0
  15. package/dist/cjs/version.json +1 -1
  16. package/dist/es2019/lists/analytics.js +36 -0
  17. package/dist/es2019/lists/indentation.js +18 -0
  18. package/dist/es2019/lists/index.js +6 -0
  19. package/dist/es2019/lists/node.js +97 -0
  20. package/dist/es2019/lists/replace-content.js +18 -0
  21. package/dist/es2019/lists/selection.js +53 -0
  22. package/dist/es2019/monitoring/error.js +1 -1
  23. package/dist/es2019/node-width/index.js +7 -0
  24. package/dist/es2019/ui/DropList/index.js +1 -1
  25. package/dist/es2019/utils/commands.js +106 -2
  26. package/dist/es2019/utils/document.js +25 -1
  27. package/dist/es2019/utils/index.js +3 -2
  28. package/dist/es2019/utils/prosemirror/autojoin.js +57 -0
  29. package/dist/es2019/version.json +1 -1
  30. package/dist/esm/lists/analytics.js +32 -0
  31. package/dist/esm/lists/indentation.js +17 -0
  32. package/dist/esm/lists/index.js +6 -0
  33. package/dist/esm/lists/node.js +87 -0
  34. package/dist/esm/lists/replace-content.js +17 -0
  35. package/dist/esm/lists/selection.js +50 -0
  36. package/dist/esm/monitoring/error.js +1 -1
  37. package/dist/esm/node-width/index.js +7 -0
  38. package/dist/esm/ui/DropList/index.js +1 -1
  39. package/dist/esm/utils/commands.js +104 -2
  40. package/dist/esm/utils/document.js +25 -1
  41. package/dist/esm/utils/index.js +3 -2
  42. package/dist/esm/utils/prosemirror/autojoin.js +63 -0
  43. package/dist/esm/version.json +1 -1
  44. package/dist/types/lists/analytics.d.ts +4 -0
  45. package/dist/types/lists/indentation.d.ts +5 -0
  46. package/dist/types/lists/index.d.ts +6 -0
  47. package/dist/types/lists/node.d.ts +18 -0
  48. package/dist/types/lists/replace-content.d.ts +8 -0
  49. package/dist/types/lists/selection.d.ts +13 -0
  50. package/dist/types/node-width/index.d.ts +1 -0
  51. package/dist/types/utils/commands.d.ts +36 -2
  52. package/dist/types/utils/document.d.ts +4 -0
  53. package/dist/types/utils/index.d.ts +4 -2
  54. package/dist/types/utils/prosemirror/autojoin.d.ts +13 -0
  55. package/dist/types-ts4.5/lists/analytics.d.ts +4 -0
  56. package/dist/types-ts4.5/lists/indentation.d.ts +5 -0
  57. package/dist/types-ts4.5/lists/index.d.ts +6 -0
  58. package/dist/types-ts4.5/lists/node.d.ts +18 -0
  59. package/dist/types-ts4.5/lists/replace-content.d.ts +8 -0
  60. package/dist/types-ts4.5/lists/selection.d.ts +13 -0
  61. package/dist/types-ts4.5/node-width/index.d.ts +1 -0
  62. package/dist/types-ts4.5/utils/commands.d.ts +42 -2
  63. package/dist/types-ts4.5/utils/document.d.ts +4 -0
  64. package/dist/types-ts4.5/utils/index.d.ts +4 -2
  65. package/dist/types-ts4.5/utils/prosemirror/autojoin.d.ts +13 -0
  66. package/lists/package.json +15 -0
  67. package/package.json +3 -2
@@ -0,0 +1,87 @@
1
+ import { Fragment } from '@atlaskit/editor-prosemirror/model';
2
+ import { isListItemNode, isListNode } from '../utils';
3
+ export function isListNodeValidContent(node) {
4
+ var bulletList = node.type.schema.nodes.bulletList;
5
+ if (!bulletList) {
6
+ return false;
7
+ }
8
+ var listFragment = Fragment.from(bulletList.createAndFill());
9
+ return !isListItemNode(node) && node.type.validContent(listFragment);
10
+ }
11
+ export var JoinDirection = /*#__PURE__*/function (JoinDirection) {
12
+ JoinDirection[JoinDirection["LEFT"] = 1] = "LEFT";
13
+ JoinDirection[JoinDirection["RIGHT"] = -1] = "RIGHT";
14
+ return JoinDirection;
15
+ }({});
16
+ export var joinSiblingLists = function joinSiblingLists(_ref) {
17
+ var tr = _ref.tr,
18
+ direction = _ref.direction,
19
+ forceListType = _ref.forceListType;
20
+ var result = {
21
+ orderedList: 0,
22
+ bulletList: 0
23
+ };
24
+ var doc = tr.doc,
25
+ _tr$selection = tr.selection,
26
+ $from = _tr$selection.$from,
27
+ $to = _tr$selection.$to,
28
+ selection = tr.selection;
29
+ var range = $from.blockRange($to, isListNodeValidContent);
30
+ if (!range) {
31
+ return result;
32
+ }
33
+ var rootListNode = doc.nodeAt(range.start);
34
+ var from = isListNode(rootListNode) ? range.start : 0;
35
+ var to = isListNode(rootListNode) ? range.end : tr.doc.content.size;
36
+ var joins = [];
37
+ doc.nodesBetween(from, to, function (node, pos, parent) {
38
+ var resolvedPos = doc.resolve(pos);
39
+ var nodeBefore = resolvedPos.nodeBefore,
40
+ nodeAfter = resolvedPos.nodeAfter;
41
+ if (!nodeBefore || !nodeAfter || !isListNode(nodeBefore) || !isListNode(nodeAfter)) {
42
+ return;
43
+ }
44
+ var isNestedList = isListItemNode(parent);
45
+ if (!isNestedList && nodeBefore.type !== nodeAfter.type && !forceListType) {
46
+ return;
47
+ }
48
+ var index = resolvedPos.index();
49
+ var positionPreviousNode = resolvedPos.posAtIndex(index - 1);
50
+ var positionCurrentNode = resolvedPos.posAtIndex(index);
51
+
52
+ // If the previous node is part of the selection, OR
53
+ // If the previous node is not part of the selection and the previous node has the same list type that we’re converting to
54
+ var joinBefore = positionPreviousNode >= from || nodeBefore.type === forceListType;
55
+ if (forceListType) {
56
+ if (joinBefore) {
57
+ tr.setNodeMarkup(positionPreviousNode, forceListType);
58
+ }
59
+ tr.setNodeMarkup(positionCurrentNode, forceListType);
60
+ }
61
+ if (isNestedList && nodeBefore.type !== nodeAfter.type) {
62
+ var nodeType = direction === JoinDirection.RIGHT ? nodeAfter.type : nodeBefore.type;
63
+ tr.setNodeMarkup(positionPreviousNode, nodeType);
64
+ }
65
+ if (joinBefore) {
66
+ joins.push(pos);
67
+ }
68
+ });
69
+ if (selection.empty && rootListNode && isListNode(rootListNode)) {
70
+ var resolvedPos = doc.resolve(range.start + rootListNode.nodeSize);
71
+ var nodeBefore = resolvedPos.nodeBefore,
72
+ nodeAfter = resolvedPos.nodeAfter;
73
+ if (nodeBefore && nodeAfter && isListNode(nodeBefore) && isListNode(nodeAfter) && nodeAfter.type === nodeBefore.type) {
74
+ joins.push(resolvedPos.pos);
75
+ }
76
+ }
77
+ for (var i = joins.length - 1; i >= 0; i--) {
78
+ var listNode = tr.doc.nodeAt(joins[i]);
79
+ var listName = listNode === null || listNode === void 0 ? void 0 : listNode.type.name;
80
+ if (listName && (listName === 'orderedList' || listName === 'bulletList')) {
81
+ var amount = result[listName] || 0;
82
+ result[listName] = amount + 1;
83
+ }
84
+ tr.join(joins[i]);
85
+ }
86
+ return result;
87
+ };
@@ -0,0 +1,17 @@
1
+ import { ReplaceAroundStep, ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
2
+ export var moveTargetIntoList = function moveTargetIntoList(_ref) {
3
+ var _$target$nodeAfter;
4
+ var insertPosition = _ref.insertPosition,
5
+ $target = _ref.$target;
6
+ // take the text content of the paragraph and insert after the paragraph up until before the the cut
7
+ var from = insertPosition;
8
+ var to = $target.pos + (((_$target$nodeAfter = $target.nodeAfter) === null || _$target$nodeAfter === void 0 ? void 0 : _$target$nodeAfter.nodeSize) || 0); //$cut.pos + $cut.nodeAfter.nodeSize;
9
+ var gapFrom = $target.posAtIndex(0, $target.depth + 1); // start pos of the child
10
+ var gapTo = $target.doc.resolve(gapFrom).end(); // end pos of the paragraph
11
+
12
+ if (gapTo - gapFrom === 0) {
13
+ return new ReplaceStep(from, to, $target.doc.slice(insertPosition, $target.pos));
14
+ }
15
+ var step = new ReplaceAroundStep(from, to, gapFrom, gapTo, $target.doc.slice(insertPosition, $target.pos), 0, true);
16
+ return step;
17
+ };
@@ -0,0 +1,50 @@
1
+ import { NodeSelection, Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
2
+ import { findParentNodeClosestToPos } from '@atlaskit/editor-prosemirror/utils';
3
+ import { isListItemNode, isListNode } from '../utils';
4
+ export var numberNestedLists = function numberNestedLists(resolvedPos) {
5
+ var count = 0;
6
+ for (var i = resolvedPos.depth - 1; i > 0; i--) {
7
+ var node = resolvedPos.node(i);
8
+ if (isListNode(node)) {
9
+ count += 1;
10
+ }
11
+ }
12
+ return count;
13
+ };
14
+ export var getListItemAttributes = function getListItemAttributes($pos) {
15
+ var indentLevel = numberNestedLists($pos) - 1;
16
+ var itemAtPos = findParentNodeClosestToPos($pos, isListItemNode);
17
+
18
+ // Get the index of the current item relative to parent (parent is at item depth - 1)
19
+ var itemIndex = $pos.index(itemAtPos ? itemAtPos.depth - 1 : undefined);
20
+ return {
21
+ indentLevel: indentLevel,
22
+ itemIndex: itemIndex
23
+ };
24
+ };
25
+ export var normalizeListItemsSelection = function normalizeListItemsSelection(_ref) {
26
+ var selection = _ref.selection,
27
+ doc = _ref.doc;
28
+ if (selection.empty) {
29
+ return selection;
30
+ }
31
+ var $from = selection.$from,
32
+ $to = selection.$to;
33
+ if (selection instanceof NodeSelection) {
34
+ var _head = resolvePositionToStartOfListItem($from);
35
+ return new TextSelection(_head, _head);
36
+ }
37
+ var head = resolvePositionToStartOfListItem($from);
38
+ var anchor = resolvePositionToEndOfListItem($to);
39
+ return new TextSelection(anchor, head);
40
+ };
41
+ var resolvePositionToStartOfListItem = function resolvePositionToStartOfListItem($pos) {
42
+ var fromRange = $pos.blockRange($pos, isListItemNode);
43
+ var fromPosition = fromRange && $pos.textOffset === 0 && fromRange.end - 1 === $pos.pos ? Selection.near($pos.doc.resolve(fromRange.end + 1), 1).$from : $pos;
44
+ return fromPosition;
45
+ };
46
+ var resolvePositionToEndOfListItem = function resolvePositionToEndOfListItem($pos) {
47
+ var toRange = $pos.blockRange($pos, isListItemNode);
48
+ var toPosition = toRange && $pos.textOffset === 0 && toRange.start + 1 === $pos.pos ? Selection.near($pos.doc.resolve(toRange.start - 1), -1).$to : $pos;
49
+ return toPosition;
50
+ };
@@ -6,7 +6,7 @@ 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 = 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; }
7
7
  var SENTRY_DSN = 'https://0b10c8e02fb44d8796c047b102c9bee8@o55978.ingest.sentry.io/4505129224110080';
8
8
  var packageName = 'editor-common'; // Sentry doesn't accept '/' in its releases https://docs.sentry.io/platforms/javascript/configuration/releases/
9
- var packageVersion = "74.30.0";
9
+ var packageVersion = "74.31.0";
10
10
  var sanitiseSentryEvents = function sanitiseSentryEvents(data, _hint) {
11
11
  // Remove URL as it has UGC
12
12
  // TODO: Sanitise the URL instead of just removing it
@@ -100,4 +100,11 @@ export var getTableContainerWidth = function getTableContainerWidth(node) {
100
100
  return node.attrs.width;
101
101
  }
102
102
  return layoutToWidth[node.attrs.layout];
103
+ };
104
+ export var getTableWidthWithNumberColumn = function getTableWidthWithNumberColumn(node, offset) {
105
+ var isNumberColumnEnabled = node.attrs.isNumberColumnEnabled;
106
+ if (isNumberColumnEnabled && offset > 0) {
107
+ return getTableContainerWidth(node) - offset;
108
+ }
109
+ return getTableContainerWidth(node);
103
110
  };
@@ -18,7 +18,7 @@ import { themed } from '@atlaskit/theme/components';
18
18
  import { borderRadius } from '@atlaskit/theme/constants';
19
19
  import Layer from '../Layer';
20
20
  var packageName = "@atlaskit/editor-common";
21
- var packageVersion = "74.30.0";
21
+ var packageVersion = "74.31.0";
22
22
  var halfFocusRing = 1;
23
23
  var dropOffset = '0, 8';
24
24
  var DropList = /*#__PURE__*/function (_Component) {
@@ -1,4 +1,8 @@
1
- export var filter = function filter(predicates, cmd) {
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ import { TextSelection } from '@atlaskit/editor-prosemirror/state';
3
+ import { GapCursorSelection } from '../selection';
4
+ import { isEmptyParagraph } from './editor-core-utils';
5
+ var filter = function filter(predicates, cmd) {
2
6
  return function (state, dispatch, view) {
3
7
  if (!Array.isArray(predicates)) {
4
8
  predicates = [predicates];
@@ -10,4 +14,102 @@ export var filter = function filter(predicates, cmd) {
10
14
  }
11
15
  return cmd(state, dispatch, view) || false;
12
16
  };
13
- };
17
+ };
18
+
19
+ /**
20
+ * Walk forwards from a position until we encounter the (inside) start of
21
+ * the next node, or reach the end of the document.
22
+ *
23
+ * @param $startPos Position to start walking from.
24
+ */
25
+ export var walkNextNode = function walkNextNode($startPos) {
26
+ var $pos = $startPos;
27
+
28
+ // invariant 1: don't walk past the end of the document
29
+ // invariant 2: we are at the beginning or
30
+ // we haven't walked to the start of *any* node
31
+ // parentOffset includes textOffset.
32
+ while ($pos.pos < $pos.doc.nodeSize - 2 && ($pos.pos === $startPos.pos || $pos.parentOffset > 0)) {
33
+ $pos = $pos.doc.resolve($pos.pos + 1);
34
+ }
35
+ return {
36
+ $pos: $pos,
37
+ foundNode: $pos.pos < $pos.doc.nodeSize - 2
38
+ };
39
+ };
40
+
41
+ /**
42
+ * Walk backwards from a position until we encounter the (inside) end of
43
+ * the previous node, or reach the start of the document.
44
+ *
45
+ * @param $startPos Position to start walking from.
46
+ */
47
+ export var walkPrevNode = function walkPrevNode($startPos) {
48
+ var $pos = $startPos;
49
+ while ($pos.pos > 0 && ($pos.pos === $startPos.pos || $pos.parentOffset < $pos.parent.nodeSize - 2)) {
50
+ $pos = $pos.doc.resolve($pos.pos - 1);
51
+ }
52
+ return {
53
+ $pos: $pos,
54
+ foundNode: $pos.pos > 0
55
+ };
56
+ };
57
+
58
+ /**
59
+ * If the selection is empty, is inside a paragraph node and `canNextNodeMoveUp` is true then delete current paragraph
60
+ * and move the node below it up. The selection will be retained, to be placed in the moved node.
61
+ *
62
+ * @param canNextNodeMoveUp check if node directly after the selection is able to be brought up to selection
63
+ * @returns PM Command
64
+ */
65
+ export var deleteEmptyParagraphAndMoveBlockUp = function deleteEmptyParagraphAndMoveBlockUp(canNextNodeMoveUp) {
66
+ return function (state, dispatch, view) {
67
+ var _state$selection = state.selection,
68
+ _state$selection$$fro = _state$selection.$from,
69
+ pos = _state$selection$$fro.pos,
70
+ parent = _state$selection$$fro.parent,
71
+ $head = _state$selection.$head,
72
+ empty = _state$selection.empty,
73
+ tr = state.tr,
74
+ doc = state.doc;
75
+ var _walkNextNode = walkNextNode($head),
76
+ $pos = _walkNextNode.$pos;
77
+ var nextPMNode = doc.nodeAt($pos.pos - 1);
78
+ if (empty && nextPMNode && canNextNodeMoveUp(nextPMNode) && isEmptyParagraph(parent) && view !== null && view !== void 0 && view.endOfTextblock('right')) {
79
+ tr.deleteRange(pos - 1, pos + 1);
80
+ if (dispatch) {
81
+ dispatch(tr);
82
+ }
83
+ return true;
84
+ }
85
+ return false;
86
+ };
87
+ };
88
+ export var insertContentDeleteRange = function insertContentDeleteRange(tr, getSelectionResolvedPos, insertions, deletions) {
89
+ insertions.forEach(function (contentInsert) {
90
+ var _contentInsert = _slicedToArray(contentInsert, 2),
91
+ content = _contentInsert[0],
92
+ pos = _contentInsert[1];
93
+ tr.insert(tr.mapping.map(pos), content);
94
+ });
95
+ deletions.forEach(function (deleteRange) {
96
+ var _deleteRange = _slicedToArray(deleteRange, 2),
97
+ firstPos = _deleteRange[0],
98
+ lastPos = _deleteRange[1];
99
+ tr.delete(tr.mapping.map(firstPos), tr.mapping.map(lastPos));
100
+ });
101
+ tr.setSelection(new TextSelection(getSelectionResolvedPos(tr)));
102
+ };
103
+ export var isEmptySelectionAtStart = function isEmptySelectionAtStart(state) {
104
+ var _state$selection2 = state.selection,
105
+ empty = _state$selection2.empty,
106
+ $from = _state$selection2.$from;
107
+ return empty && ($from.parentOffset === 0 || state.selection instanceof GapCursorSelection);
108
+ };
109
+ export var isEmptySelectionAtEnd = function isEmptySelectionAtEnd(state) {
110
+ var _state$selection3 = state.selection,
111
+ empty = _state$selection3.empty,
112
+ $from = _state$selection3.$from;
113
+ return empty && ($from.end() === $from.pos || state.selection instanceof GapCursorSelection);
114
+ };
115
+ export { filter as filterCommand };
@@ -243,4 +243,28 @@ var maySanitizePrivateContent = function maySanitizePrivateContent(entity, provi
243
243
  return sanitizeNodeForPrivacy(entity, providerFactory);
244
244
  }
245
245
  return entity;
246
- };
246
+ };
247
+
248
+ /**
249
+ * Returns false if node contains only empty inline nodes and hardBreaks.
250
+ */
251
+ export function hasVisibleContent(node) {
252
+ var isInlineNodeHasVisibleContent = function isInlineNodeHasVisibleContent(inlineNode) {
253
+ return inlineNode.isText ? !!inlineNode.textContent.trim() : inlineNode.type.name !== 'hardBreak';
254
+ };
255
+ if (node.isInline) {
256
+ return isInlineNodeHasVisibleContent(node);
257
+ } else if (node.isBlock && (node.isLeaf || node.isAtom)) {
258
+ return true;
259
+ } else if (!node.childCount) {
260
+ return false;
261
+ }
262
+ for (var _index = 0; _index < node.childCount; _index++) {
263
+ var child = node.child(_index);
264
+ var invisibleNodeTypes = ['paragraph', 'text', 'hardBreak'];
265
+ if (!invisibleNodeTypes.includes(child.type.name) || hasVisibleContent(child)) {
266
+ return true;
267
+ }
268
+ }
269
+ return false;
270
+ }
@@ -33,6 +33,7 @@ export { validateADFEntity, validationErrorHandler } from './validate-using-spec
33
33
  export { getShallowPropsDifference, getPropsDifference } from './compare-props';
34
34
  export { useComponentRenderTracking } from './performance/hooks/use-component-render-tracking';
35
35
  export { isOutdatedBrowser } from './outdated-browsers';
36
+ export { autoJoinTr } from './prosemirror/autojoin';
36
37
  export { isReferencedSource, removeConnectedNodes, getChildrenInfo, getNodeName } from './referentiality';
37
38
  export { getItemCounterDigitsSize, getOrderFromOrderedListNode, resolveOrder, isListNode, isParagraphNode, isListItemNode, isBulletList } from './list';
38
39
  export { isFromCurrentDomain, LinkMatcher, normalizeUrl, linkifyContent, getLinkDomain, findFilepaths, isLinkInMatches, FILEPATH_REGEXP, DONTLINKIFY_REGEXP, getLinkCreationAnalyticsEvent, canLinkBeCreatedInRange } from './hyperlink';
@@ -40,11 +41,11 @@ export { isFromCurrentDomain, LinkMatcher, normalizeUrl, linkifyContent, getLink
40
41
  // prosemirror-history does not export its plugin key
41
42
  export var pmHistoryPluginKey = 'history$';
42
43
  export { gridTypeForLayout } from './grid';
43
- export { nodesBetweenChanged, getStepRange, isEmptyDocument, processRawValue, hasDocAsParent, bracketTyped } from './document';
44
+ export { nodesBetweenChanged, getStepRange, isEmptyDocument, processRawValue, hasDocAsParent, bracketTyped, hasVisibleContent } from './document';
44
45
  export { floatingLayouts, isRichMediaInsideOfBlockNode, calculateSnapPoints, alignAttributes } from './rich-media-utils';
45
46
  export { sanitizeNodeForPrivacy } from './filter/privacy-filter';
46
47
  export { canRenderDatasource } from './datasource';
47
- export { filter as filterCommands } from './commands';
48
+ export { filterCommand, walkPrevNode, walkNextNode, isEmptySelectionAtStart, isEmptySelectionAtEnd, insertContentDeleteRange, deleteEmptyParagraphAndMoveBlockUp } from './commands';
48
49
  export function shallowEqual() {
49
50
  var obj1 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
50
51
  var obj2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
@@ -0,0 +1,63 @@
1
+ import { canJoin } from '@atlaskit/editor-prosemirror/transform';
2
+
3
+ /**
4
+ * Checks whether two adjacent nodes can be joined. If so, the document
5
+ * will be updated to join those nodes. If not, the original transaction
6
+ * remains untouched.
7
+ *
8
+ * Nodes are considered joinable if the `isJoinable` predicate returns true or,
9
+ * if an array of strings was passed, if their node type name is in that array.
10
+ *
11
+ * Adapted from https://github.com/ProseMirror/prosemirror-commands/blob/master/src/commands.js#L597-L610
12
+ */
13
+ export function autoJoinTr(tr, isJoinable) {
14
+ if (Array.isArray(isJoinable)) {
15
+ var types = isJoinable;
16
+ isJoinable = function isJoinable(node) {
17
+ return types.indexOf(node.type.name) > -1;
18
+ };
19
+ }
20
+ var ranges = [];
21
+ for (var i = 0; i < tr.mapping.maps.length; i++) {
22
+ var map = tr.mapping.maps[i];
23
+ for (var j = 0; j < ranges.length; j++) {
24
+ ranges[j] = map.map(ranges[j]);
25
+ }
26
+ map.forEach(function (_s, _e, from, to) {
27
+ return ranges.push(from, to);
28
+ });
29
+ }
30
+
31
+ // Figure out which joinable points exist inside those ranges,
32
+ // by checking all node boundaries in their parent nodes.
33
+ var joinable = [];
34
+ for (var _i = 0; _i < ranges.length; _i += 2) {
35
+ var from = ranges[_i];
36
+ var to = ranges[_i + 1];
37
+ var $from = tr.doc.resolve(from);
38
+ var depth = $from.sharedDepth(to);
39
+ var parent = $from.node(depth);
40
+ for (var index = $from.indexAfter(depth), pos = $from.after(depth + 1); pos <= to; ++index) {
41
+ var _after = parent.maybeChild(index);
42
+ if (!_after) {
43
+ break;
44
+ }
45
+ if (index && joinable.indexOf(pos) === -1) {
46
+ var _before = parent.child(index - 1);
47
+ if (_before.type === _after.type && isJoinable(_before, _after)) {
48
+ joinable.push(pos);
49
+ }
50
+ }
51
+ pos += _after.nodeSize;
52
+ }
53
+ }
54
+ // Join the joinable points
55
+ joinable.sort(function (a, b) {
56
+ return a - b;
57
+ });
58
+ for (var _i2 = joinable.length - 1; _i2 >= 0; _i2--) {
59
+ if (canJoin(tr.doc, joinable[_i2])) {
60
+ tr.join(joinable[_i2]);
61
+ }
62
+ }
63
+ }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-common",
3
- "version": "74.30.0",
3
+ "version": "74.31.0",
4
4
  "sideEffects": false
5
5
  }
@@ -0,0 +1,4 @@
1
+ import type { EditorState } from '@atlaskit/editor-prosemirror/state';
2
+ import { CommonListAnalyticsAttributes } from '../analytics';
3
+ export declare const getCommonListAnalyticsAttributes: (state: EditorState) => CommonListAnalyticsAttributes;
4
+ export declare const countListItemsInSelection: (state: EditorState) => number;
@@ -0,0 +1,5 @@
1
+ import { Transaction } from '@atlaskit/editor-prosemirror/state';
2
+ export declare const hasValidListIndentationLevel: ({ tr, maxIndentation, }: {
3
+ tr: Transaction;
4
+ maxIndentation: number;
5
+ }) => boolean;
@@ -0,0 +1,6 @@
1
+ export { getListItemAttributes, normalizeListItemsSelection, } from './selection';
2
+ export { moveTargetIntoList } from './replace-content';
3
+ export { JoinDirection, isListNodeValidContent, joinSiblingLists, } from './node';
4
+ export { getCommonListAnalyticsAttributes, countListItemsInSelection, } from './analytics';
5
+ export { hasValidListIndentationLevel } from './indentation';
6
+ export { isListNode, isListItemNode, isBulletList, isParagraphNode, } from '../utils';
@@ -0,0 +1,18 @@
1
+ import { NodeType, Node as PMNode } from '@atlaskit/editor-prosemirror/model';
2
+ import { Transaction } from '@atlaskit/editor-prosemirror/state';
3
+ export declare function isListNodeValidContent(node: PMNode): boolean;
4
+ export declare enum JoinDirection {
5
+ LEFT = 1,
6
+ RIGHT = -1
7
+ }
8
+ type JoinSiblingListsProps = {
9
+ tr: Transaction;
10
+ direction?: JoinDirection;
11
+ forceListType?: NodeType;
12
+ };
13
+ type ListsJoined = {
14
+ orderedList: number;
15
+ bulletList: number;
16
+ };
17
+ export declare const joinSiblingLists: ({ tr, direction, forceListType, }: JoinSiblingListsProps) => ListsJoined;
18
+ export {};
@@ -0,0 +1,8 @@
1
+ import type { ResolvedPos } from '@atlaskit/editor-prosemirror/model';
2
+ import { Step } from '@atlaskit/editor-prosemirror/transform';
3
+ type Params = {
4
+ insertPosition: number;
5
+ $target: ResolvedPos;
6
+ };
7
+ export declare const moveTargetIntoList: ({ insertPosition, $target, }: Params) => Step;
8
+ export {};
@@ -0,0 +1,13 @@
1
+ import { Node as PMNode, ResolvedPos } from '@atlaskit/editor-prosemirror/model';
2
+ import { Selection } from '@atlaskit/editor-prosemirror/state';
3
+ export declare const numberNestedLists: (resolvedPos: ResolvedPos) => number;
4
+ export declare const getListItemAttributes: ($pos: ResolvedPos) => {
5
+ indentLevel: number;
6
+ itemIndex: number;
7
+ };
8
+ type NormalizeListItemsSelection = (props: {
9
+ selection: Selection;
10
+ doc: PMNode;
11
+ }) => Selection;
12
+ export declare const normalizeListItemsSelection: NormalizeListItemsSelection;
13
+ export {};
@@ -12,3 +12,4 @@ export declare const layoutToWidth: {
12
12
  */
13
13
  export declare const getParentNodeWidth: (pos: number | undefined, state: EditorState, containerWidth: EditorContainerWidth, isFullWidthModeEnabled?: boolean) => any;
14
14
  export declare const getTableContainerWidth: (node: PMNode) => number;
15
+ export declare const getTableWidthWithNumberColumn: (node: PMNode, offset: number) => number;
@@ -1,2 +1,36 @@
1
- import type { Command, Predicate } from '../types';
2
- export declare const filter: (predicates: Predicate[] | Predicate, cmd: Command) => Command;
1
+ import type { Fragment, Node as PMNode, ResolvedPos } from '@atlaskit/editor-prosemirror/model';
2
+ import { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
3
+ import { EditorView } from '@atlaskit/editor-prosemirror/view';
4
+ import type { Command } from '../types';
5
+ export type WalkNode = {
6
+ $pos: ResolvedPos;
7
+ foundNode: boolean;
8
+ };
9
+ type Predicate = (state: EditorState, view?: EditorView) => boolean;
10
+ declare const filter: (predicates: Predicate[] | Predicate, cmd: Command) => Command;
11
+ /**
12
+ * Walk forwards from a position until we encounter the (inside) start of
13
+ * the next node, or reach the end of the document.
14
+ *
15
+ * @param $startPos Position to start walking from.
16
+ */
17
+ export declare const walkNextNode: ($startPos: ResolvedPos) => WalkNode;
18
+ /**
19
+ * Walk backwards from a position until we encounter the (inside) end of
20
+ * the previous node, or reach the start of the document.
21
+ *
22
+ * @param $startPos Position to start walking from.
23
+ */
24
+ export declare const walkPrevNode: ($startPos: ResolvedPos) => WalkNode;
25
+ /**
26
+ * If the selection is empty, is inside a paragraph node and `canNextNodeMoveUp` is true then delete current paragraph
27
+ * and move the node below it up. The selection will be retained, to be placed in the moved node.
28
+ *
29
+ * @param canNextNodeMoveUp check if node directly after the selection is able to be brought up to selection
30
+ * @returns PM Command
31
+ */
32
+ export declare const deleteEmptyParagraphAndMoveBlockUp: (canNextNodeMoveUp: (nextNode: PMNode) => boolean) => Command;
33
+ export declare const insertContentDeleteRange: (tr: Transaction, getSelectionResolvedPos: (tr: Transaction) => ResolvedPos, insertions: [Fragment, number][], deletions: [number, number][]) => void;
34
+ export declare const isEmptySelectionAtStart: (state: EditorState) => boolean;
35
+ export declare const isEmptySelectionAtEnd: (state: EditorState) => boolean;
36
+ export { filter as filterCommand };
@@ -16,4 +16,8 @@ export declare function isEmptyDocument(node: Node): boolean;
16
16
  export declare function bracketTyped(state: EditorState): boolean;
17
17
  export declare function nodesBetweenChanged(tr: Transaction | ReadonlyTransaction, f: ChangedFn, startPos?: number): void;
18
18
  export declare function processRawValue(schema: Schema, value?: ReplaceRawValue, providerFactory?: ProviderFactory, sanitizePrivateContent?: boolean, contentTransformer?: Transformer<string>, dispatchAnalyticsEvent?: DispatchAnalyticsEvent): Node | undefined;
19
+ /**
20
+ * Returns false if node contains only empty inline nodes and hardBreaks.
21
+ */
22
+ export declare function hasVisibleContent(node: Node): boolean;
19
23
  export {};
@@ -45,14 +45,16 @@ export type { ShallowPropsDifference, PropsDifference } from './compare-props';
45
45
  export { useComponentRenderTracking } from './performance/hooks/use-component-render-tracking';
46
46
  export type { UseComponentRenderTrackingArgs } from './performance/hooks/use-component-render-tracking';
47
47
  export { isOutdatedBrowser } from './outdated-browsers';
48
+ export { autoJoinTr } from './prosemirror/autojoin';
48
49
  export { isReferencedSource, removeConnectedNodes, getChildrenInfo, getNodeName, } from './referentiality';
49
50
  export { getItemCounterDigitsSize, getOrderFromOrderedListNode, resolveOrder, isListNode, isParagraphNode, isListItemNode, isBulletList, } from './list';
50
51
  export { isFromCurrentDomain, LinkMatcher, normalizeUrl, linkifyContent, getLinkDomain, findFilepaths, isLinkInMatches, FILEPATH_REGEXP, DONTLINKIFY_REGEXP, getLinkCreationAnalyticsEvent, canLinkBeCreatedInRange, } from './hyperlink';
51
52
  export declare const pmHistoryPluginKey = "history$";
52
53
  export { gridTypeForLayout } from './grid';
53
- export { nodesBetweenChanged, getStepRange, isEmptyDocument, processRawValue, hasDocAsParent, bracketTyped, } from './document';
54
+ export { nodesBetweenChanged, getStepRange, isEmptyDocument, processRawValue, hasDocAsParent, bracketTyped, hasVisibleContent, } from './document';
54
55
  export { floatingLayouts, isRichMediaInsideOfBlockNode, calculateSnapPoints, alignAttributes, } from './rich-media-utils';
55
56
  export { sanitizeNodeForPrivacy } from './filter/privacy-filter';
56
57
  export { canRenderDatasource } from './datasource';
57
- export { filter as filterCommands } from './commands';
58
+ export { filterCommand, walkPrevNode, walkNextNode, isEmptySelectionAtStart, isEmptySelectionAtEnd, insertContentDeleteRange, deleteEmptyParagraphAndMoveBlockUp, } from './commands';
59
+ export type { WalkNode } from './commands';
58
60
  export declare function shallowEqual(obj1?: any, obj2?: any): boolean;
@@ -0,0 +1,13 @@
1
+ import type { Node } from '@atlaskit/editor-prosemirror/model';
2
+ import type { Transaction } from '@atlaskit/editor-prosemirror/state';
3
+ /**
4
+ * Checks whether two adjacent nodes can be joined. If so, the document
5
+ * will be updated to join those nodes. If not, the original transaction
6
+ * remains untouched.
7
+ *
8
+ * Nodes are considered joinable if the `isJoinable` predicate returns true or,
9
+ * if an array of strings was passed, if their node type name is in that array.
10
+ *
11
+ * Adapted from https://github.com/ProseMirror/prosemirror-commands/blob/master/src/commands.js#L597-L610
12
+ */
13
+ export declare function autoJoinTr(tr: Transaction, isJoinable: ((before: Node, after: Node) => boolean) | string[]): void;
@@ -0,0 +1,4 @@
1
+ import type { EditorState } from '@atlaskit/editor-prosemirror/state';
2
+ import { CommonListAnalyticsAttributes } from '../analytics';
3
+ export declare const getCommonListAnalyticsAttributes: (state: EditorState) => CommonListAnalyticsAttributes;
4
+ export declare const countListItemsInSelection: (state: EditorState) => number;
@@ -0,0 +1,5 @@
1
+ import { Transaction } from '@atlaskit/editor-prosemirror/state';
2
+ export declare const hasValidListIndentationLevel: ({ tr, maxIndentation, }: {
3
+ tr: Transaction;
4
+ maxIndentation: number;
5
+ }) => boolean;
@@ -0,0 +1,6 @@
1
+ export { getListItemAttributes, normalizeListItemsSelection, } from './selection';
2
+ export { moveTargetIntoList } from './replace-content';
3
+ export { JoinDirection, isListNodeValidContent, joinSiblingLists, } from './node';
4
+ export { getCommonListAnalyticsAttributes, countListItemsInSelection, } from './analytics';
5
+ export { hasValidListIndentationLevel } from './indentation';
6
+ export { isListNode, isListItemNode, isBulletList, isParagraphNode, } from '../utils';
@@ -0,0 +1,18 @@
1
+ import { NodeType, Node as PMNode } from '@atlaskit/editor-prosemirror/model';
2
+ import { Transaction } from '@atlaskit/editor-prosemirror/state';
3
+ export declare function isListNodeValidContent(node: PMNode): boolean;
4
+ export declare enum JoinDirection {
5
+ LEFT = 1,
6
+ RIGHT = -1
7
+ }
8
+ type JoinSiblingListsProps = {
9
+ tr: Transaction;
10
+ direction?: JoinDirection;
11
+ forceListType?: NodeType;
12
+ };
13
+ type ListsJoined = {
14
+ orderedList: number;
15
+ bulletList: number;
16
+ };
17
+ export declare const joinSiblingLists: ({ tr, direction, forceListType, }: JoinSiblingListsProps) => ListsJoined;
18
+ export {};
@@ -0,0 +1,8 @@
1
+ import type { ResolvedPos } from '@atlaskit/editor-prosemirror/model';
2
+ import { Step } from '@atlaskit/editor-prosemirror/transform';
3
+ type Params = {
4
+ insertPosition: number;
5
+ $target: ResolvedPos;
6
+ };
7
+ export declare const moveTargetIntoList: ({ insertPosition, $target, }: Params) => Step;
8
+ export {};
@@ -0,0 +1,13 @@
1
+ import { Node as PMNode, ResolvedPos } from '@atlaskit/editor-prosemirror/model';
2
+ import { Selection } from '@atlaskit/editor-prosemirror/state';
3
+ export declare const numberNestedLists: (resolvedPos: ResolvedPos) => number;
4
+ export declare const getListItemAttributes: ($pos: ResolvedPos) => {
5
+ indentLevel: number;
6
+ itemIndex: number;
7
+ };
8
+ type NormalizeListItemsSelection = (props: {
9
+ selection: Selection;
10
+ doc: PMNode;
11
+ }) => Selection;
12
+ export declare const normalizeListItemsSelection: NormalizeListItemsSelection;
13
+ export {};