@atlaskit/editor-common 74.30.0 → 74.32.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 (79) hide show
  1. package/CHANGELOG.md +12 -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/types/input-rules.js +5 -0
  11. package/dist/cjs/ui/DropList/index.js +1 -1
  12. package/dist/cjs/utils/commands.js +110 -2
  13. package/dist/cjs/utils/document.js +26 -1
  14. package/dist/cjs/utils/index.js +58 -2
  15. package/dist/cjs/utils/input-rules.js +26 -0
  16. package/dist/cjs/utils/prosemirror/autojoin.js +68 -0
  17. package/dist/cjs/version.json +1 -1
  18. package/dist/es2019/lists/analytics.js +36 -0
  19. package/dist/es2019/lists/indentation.js +18 -0
  20. package/dist/es2019/lists/index.js +6 -0
  21. package/dist/es2019/lists/node.js +97 -0
  22. package/dist/es2019/lists/replace-content.js +18 -0
  23. package/dist/es2019/lists/selection.js +53 -0
  24. package/dist/es2019/monitoring/error.js +1 -1
  25. package/dist/es2019/node-width/index.js +7 -0
  26. package/dist/es2019/types/input-rules.js +1 -0
  27. package/dist/es2019/ui/DropList/index.js +1 -1
  28. package/dist/es2019/utils/commands.js +106 -2
  29. package/dist/es2019/utils/document.js +25 -1
  30. package/dist/es2019/utils/index.js +5 -3
  31. package/dist/es2019/utils/input-rules.js +16 -0
  32. package/dist/es2019/utils/prosemirror/autojoin.js +57 -0
  33. package/dist/es2019/version.json +1 -1
  34. package/dist/esm/lists/analytics.js +32 -0
  35. package/dist/esm/lists/indentation.js +17 -0
  36. package/dist/esm/lists/index.js +6 -0
  37. package/dist/esm/lists/node.js +87 -0
  38. package/dist/esm/lists/replace-content.js +17 -0
  39. package/dist/esm/lists/selection.js +50 -0
  40. package/dist/esm/monitoring/error.js +1 -1
  41. package/dist/esm/node-width/index.js +7 -0
  42. package/dist/esm/types/input-rules.js +1 -0
  43. package/dist/esm/ui/DropList/index.js +1 -1
  44. package/dist/esm/utils/commands.js +104 -2
  45. package/dist/esm/utils/document.js +25 -1
  46. package/dist/esm/utils/index.js +5 -3
  47. package/dist/esm/utils/input-rules.js +18 -0
  48. package/dist/esm/utils/prosemirror/autojoin.js +63 -0
  49. package/dist/esm/version.json +1 -1
  50. package/dist/types/lists/analytics.d.ts +4 -0
  51. package/dist/types/lists/indentation.d.ts +5 -0
  52. package/dist/types/lists/index.d.ts +6 -0
  53. package/dist/types/lists/node.d.ts +18 -0
  54. package/dist/types/lists/replace-content.d.ts +8 -0
  55. package/dist/types/lists/selection.d.ts +13 -0
  56. package/dist/types/node-width/index.d.ts +1 -0
  57. package/dist/types/types/index.d.ts +1 -0
  58. package/dist/types/types/input-rules.d.ts +8 -0
  59. package/dist/types/utils/commands.d.ts +36 -2
  60. package/dist/types/utils/document.d.ts +4 -0
  61. package/dist/types/utils/index.d.ts +5 -2
  62. package/dist/types/utils/input-rules.d.ts +7 -0
  63. package/dist/types/utils/prosemirror/autojoin.d.ts +13 -0
  64. package/dist/types-ts4.5/lists/analytics.d.ts +4 -0
  65. package/dist/types-ts4.5/lists/indentation.d.ts +5 -0
  66. package/dist/types-ts4.5/lists/index.d.ts +6 -0
  67. package/dist/types-ts4.5/lists/node.d.ts +18 -0
  68. package/dist/types-ts4.5/lists/replace-content.d.ts +8 -0
  69. package/dist/types-ts4.5/lists/selection.d.ts +13 -0
  70. package/dist/types-ts4.5/node-width/index.d.ts +1 -0
  71. package/dist/types-ts4.5/types/index.d.ts +1 -0
  72. package/dist/types-ts4.5/types/input-rules.d.ts +8 -0
  73. package/dist/types-ts4.5/utils/commands.d.ts +42 -2
  74. package/dist/types-ts4.5/utils/document.d.ts +4 -0
  75. package/dist/types-ts4.5/utils/index.d.ts +5 -2
  76. package/dist/types-ts4.5/utils/input-rules.d.ts +7 -0
  77. package/dist/types-ts4.5/utils/prosemirror/autojoin.d.ts +13 -0
  78. package/lists/package.json +15 -0
  79. package/package.json +3 -2
@@ -0,0 +1,16 @@
1
+ // Roughly based on atlassian-frontend/packages/editor/editor-core/src/utils/input-rules.ts but with the Editor Analytics API that's injected in plugins
2
+ export const inputRuleWithAnalytics = (getPayload, analyticsApi) => {
3
+ return originalRule => {
4
+ const onHandlerApply = (state, tr, matchResult) => {
5
+ const payload = typeof getPayload === 'function' ? getPayload(state, matchResult) : getPayload;
6
+ analyticsApi === null || analyticsApi === void 0 ? void 0 : analyticsApi.attachAnalyticsEvent(payload)(tr);
7
+ if (originalRule.onHandlerApply) {
8
+ originalRule.onHandlerApply(state, tr, matchResult);
9
+ }
10
+ };
11
+ return {
12
+ ...originalRule,
13
+ onHandlerApply
14
+ };
15
+ };
16
+ };
@@ -0,0 +1,57 @@
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
+ let types = isJoinable;
16
+ isJoinable = node => types.indexOf(node.type.name) > -1;
17
+ }
18
+ const ranges = [];
19
+ for (let i = 0; i < tr.mapping.maps.length; i++) {
20
+ const map = tr.mapping.maps[i];
21
+ for (let j = 0; j < ranges.length; j++) {
22
+ ranges[j] = map.map(ranges[j]);
23
+ }
24
+ map.forEach((_s, _e, from, to) => ranges.push(from, to));
25
+ }
26
+
27
+ // Figure out which joinable points exist inside those ranges,
28
+ // by checking all node boundaries in their parent nodes.
29
+ const joinable = [];
30
+ for (let i = 0; i < ranges.length; i += 2) {
31
+ const from = ranges[i];
32
+ const to = ranges[i + 1];
33
+ const $from = tr.doc.resolve(from);
34
+ const depth = $from.sharedDepth(to);
35
+ const parent = $from.node(depth);
36
+ for (let index = $from.indexAfter(depth), pos = $from.after(depth + 1); pos <= to; ++index) {
37
+ const after = parent.maybeChild(index);
38
+ if (!after) {
39
+ break;
40
+ }
41
+ if (index && joinable.indexOf(pos) === -1) {
42
+ const before = parent.child(index - 1);
43
+ if (before.type === after.type && isJoinable(before, after)) {
44
+ joinable.push(pos);
45
+ }
46
+ }
47
+ pos += after.nodeSize;
48
+ }
49
+ }
50
+ // Join the joinable points
51
+ joinable.sort((a, b) => a - b);
52
+ for (let i = joinable.length - 1; i >= 0; i--) {
53
+ if (canJoin(tr.doc, joinable[i])) {
54
+ tr.join(joinable[i]);
55
+ }
56
+ }
57
+ }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-common",
3
- "version": "74.30.0",
3
+ "version": "74.32.0",
4
4
  "sideEffects": false
5
5
  }
@@ -0,0 +1,32 @@
1
+ import { isListItemNode, isListNode } from '../utils';
2
+ import { getListItemAttributes } from './selection';
3
+ export var getCommonListAnalyticsAttributes = function getCommonListAnalyticsAttributes(state) {
4
+ var _state$selection = state.selection,
5
+ $from = _state$selection.$from,
6
+ $to = _state$selection.$to;
7
+ var fromAttrs = getListItemAttributes($from);
8
+ var toAttrs = getListItemAttributes($to);
9
+ return {
10
+ itemIndexAtSelectionStart: fromAttrs.itemIndex,
11
+ itemIndexAtSelectionEnd: toAttrs.itemIndex,
12
+ indentLevelAtSelectionStart: fromAttrs.indentLevel,
13
+ indentLevelAtSelectionEnd: toAttrs.indentLevel,
14
+ itemsInSelection: countListItemsInSelection(state)
15
+ };
16
+ };
17
+ export var countListItemsInSelection = function countListItemsInSelection(state) {
18
+ var _state$selection2 = state.selection,
19
+ from = _state$selection2.from,
20
+ to = _state$selection2.to;
21
+ if (from === to) {
22
+ return 1;
23
+ }
24
+ var count = 0;
25
+ var listSlice = state.doc.cut(from, to);
26
+ listSlice.content.nodesBetween(0, listSlice.content.size, function (node, pos, parent, index) {
27
+ if (parent && isListItemNode(parent) && !isListNode(node) && index === 0) {
28
+ count++;
29
+ }
30
+ });
31
+ return count;
32
+ };
@@ -0,0 +1,17 @@
1
+ import { numberNestedLists } from './selection';
2
+ export var hasValidListIndentationLevel = function hasValidListIndentationLevel(_ref) {
3
+ var tr = _ref.tr,
4
+ maxIndentation = _ref.maxIndentation;
5
+ var initialIndentationLevel = numberNestedLists(tr.selection.$from);
6
+ var currentIndentationLevel;
7
+ var currentPos = tr.selection.$to.pos;
8
+ do {
9
+ var resolvedPos = tr.doc.resolve(currentPos);
10
+ currentIndentationLevel = numberNestedLists(resolvedPos);
11
+ if (currentIndentationLevel > maxIndentation) {
12
+ return false;
13
+ }
14
+ currentPos++;
15
+ } while (currentIndentationLevel >= initialIndentationLevel);
16
+ return true;
17
+ };
@@ -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,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.32.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
  };
@@ -0,0 +1 @@
1
+ export {};
@@ -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.32.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] : {};
@@ -53,4 +54,5 @@ export function shallowEqual() {
53
54
  return keys1.length === keys2.length && keys1.reduce(function (acc, key) {
54
55
  return acc && obj1[key] === obj2[key];
55
56
  }, true);
56
- }
57
+ }
58
+ export { inputRuleWithAnalytics } from './input-rules';
@@ -0,0 +1,18 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ 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; }
3
+ 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; }
4
+ // Roughly based on atlassian-frontend/packages/editor/editor-core/src/utils/input-rules.ts but with the Editor Analytics API that's injected in plugins
5
+ export var inputRuleWithAnalytics = function inputRuleWithAnalytics(getPayload, analyticsApi) {
6
+ return function (originalRule) {
7
+ var onHandlerApply = function onHandlerApply(state, tr, matchResult) {
8
+ var payload = typeof getPayload === 'function' ? getPayload(state, matchResult) : getPayload;
9
+ analyticsApi === null || analyticsApi === void 0 ? void 0 : analyticsApi.attachAnalyticsEvent(payload)(tr);
10
+ if (originalRule.onHandlerApply) {
11
+ originalRule.onHandlerApply(state, tr, matchResult);
12
+ }
13
+ };
14
+ return _objectSpread(_objectSpread({}, originalRule), {}, {
15
+ onHandlerApply: onHandlerApply
16
+ });
17
+ };
18
+ };
@@ -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.32.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 {};