@atlaskit/editor-plugin-list 0.2.0 → 1.1.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 (181) hide show
  1. package/.eslintrc.js +14 -0
  2. package/CHANGELOG.md +16 -0
  3. package/README.md +1 -1
  4. package/dist/cjs/actions/conversions.js +153 -0
  5. package/dist/cjs/actions/indent-list-items-selected.js +125 -0
  6. package/dist/cjs/actions/indent-list.js +49 -0
  7. package/dist/cjs/actions/join-list-items-forward.js +59 -0
  8. package/dist/cjs/actions/join-list-items-scenarios/index.js +40 -0
  9. package/dist/cjs/actions/join-list-items-scenarios/join-list-item-with-paragraph.js +88 -0
  10. package/dist/cjs/actions/join-list-items-scenarios/join-list-item-with-parent-nested-list.js +85 -0
  11. package/dist/cjs/actions/join-list-items-scenarios/join-nested-list-with-parent-list-item.js +79 -0
  12. package/dist/cjs/actions/join-list-items-scenarios/join-paragraph-with-list.js +45 -0
  13. package/dist/cjs/actions/join-list-items-scenarios/join-sibling-list-items.js +56 -0
  14. package/dist/cjs/actions/merge-lists.js +27 -0
  15. package/dist/cjs/actions/outdent-list-items-selected.js +289 -0
  16. package/dist/cjs/actions/wrap-and-join-lists.js +100 -0
  17. package/dist/cjs/commands/indent-list.js +69 -0
  18. package/dist/cjs/commands/index.js +349 -0
  19. package/dist/cjs/commands/isFirstChildOfParent.js +12 -0
  20. package/dist/cjs/commands/join-list-item-forward.js +61 -0
  21. package/dist/cjs/commands/listBackspace.js +284 -0
  22. package/dist/cjs/commands/outdent-list.js +69 -0
  23. package/dist/cjs/index.js +8 -1
  24. package/dist/cjs/messages.js +37 -0
  25. package/dist/cjs/plugin.js +137 -0
  26. package/dist/cjs/pm-plugins/input-rules/create-list-input-rule.js +63 -0
  27. package/dist/cjs/pm-plugins/input-rules/index.js +38 -0
  28. package/dist/cjs/pm-plugins/input-rules/wrapping-join-rule.js +60 -0
  29. package/dist/cjs/pm-plugins/keymap.js +27 -0
  30. package/dist/cjs/pm-plugins/main.js +166 -0
  31. package/dist/cjs/transforms.js +99 -0
  32. package/dist/cjs/types.js +4 -1
  33. package/dist/cjs/utils/analytics.js +22 -0
  34. package/dist/cjs/utils/find.js +68 -0
  35. package/dist/cjs/utils/indentation.js +22 -0
  36. package/dist/cjs/utils/mark.js +40 -0
  37. package/dist/cjs/utils/node.js +16 -0
  38. package/dist/cjs/utils/selection.js +95 -0
  39. package/dist/es2019/actions/conversions.js +160 -0
  40. package/dist/es2019/actions/indent-list-items-selected.js +124 -0
  41. package/dist/es2019/actions/indent-list.js +44 -0
  42. package/dist/es2019/actions/join-list-items-forward.js +54 -0
  43. package/dist/es2019/actions/join-list-items-scenarios/index.js +5 -0
  44. package/dist/es2019/actions/join-list-items-scenarios/join-list-item-with-paragraph.js +74 -0
  45. package/dist/es2019/actions/join-list-items-scenarios/join-list-item-with-parent-nested-list.js +77 -0
  46. package/dist/es2019/actions/join-list-items-scenarios/join-nested-list-with-parent-list-item.js +71 -0
  47. package/dist/es2019/actions/join-list-items-scenarios/join-paragraph-with-list.js +37 -0
  48. package/dist/es2019/actions/join-list-items-scenarios/join-sibling-list-items.js +48 -0
  49. package/dist/es2019/actions/merge-lists.js +24 -0
  50. package/dist/es2019/actions/outdent-list-items-selected.js +293 -0
  51. package/dist/es2019/actions/wrap-and-join-lists.js +93 -0
  52. package/dist/es2019/commands/indent-list.js +61 -0
  53. package/dist/es2019/commands/index.js +322 -0
  54. package/dist/es2019/commands/isFirstChildOfParent.js +7 -0
  55. package/dist/es2019/commands/join-list-item-forward.js +53 -0
  56. package/dist/es2019/commands/listBackspace.js +276 -0
  57. package/dist/es2019/commands/outdent-list.js +60 -0
  58. package/dist/es2019/index.js +1 -1
  59. package/dist/es2019/messages.js +29 -0
  60. package/dist/es2019/plugin.js +123 -0
  61. package/dist/es2019/pm-plugins/input-rules/create-list-input-rule.js +56 -0
  62. package/dist/es2019/pm-plugins/input-rules/index.js +35 -0
  63. package/dist/es2019/pm-plugins/input-rules/wrapping-join-rule.js +55 -0
  64. package/dist/es2019/pm-plugins/keymap.js +19 -0
  65. package/dist/es2019/pm-plugins/main.js +156 -0
  66. package/dist/es2019/transforms.js +101 -0
  67. package/dist/es2019/types.js +1 -1
  68. package/dist/es2019/utils/analytics.js +12 -0
  69. package/dist/es2019/utils/find.js +61 -0
  70. package/dist/es2019/utils/indentation.js +15 -0
  71. package/dist/es2019/utils/mark.js +30 -0
  72. package/dist/es2019/utils/node.js +12 -0
  73. package/dist/es2019/utils/selection.js +96 -0
  74. package/dist/esm/actions/conversions.js +147 -0
  75. package/dist/esm/actions/indent-list-items-selected.js +117 -0
  76. package/dist/esm/actions/indent-list.js +43 -0
  77. package/dist/esm/actions/join-list-items-forward.js +52 -0
  78. package/dist/esm/actions/join-list-items-scenarios/index.js +5 -0
  79. package/dist/esm/actions/join-list-items-scenarios/join-list-item-with-paragraph.js +81 -0
  80. package/dist/esm/actions/join-list-items-scenarios/join-list-item-with-parent-nested-list.js +78 -0
  81. package/dist/esm/actions/join-list-items-scenarios/join-nested-list-with-parent-list-item.js +72 -0
  82. package/dist/esm/actions/join-list-items-scenarios/join-paragraph-with-list.js +38 -0
  83. package/dist/esm/actions/join-list-items-scenarios/join-sibling-list-items.js +49 -0
  84. package/dist/esm/actions/merge-lists.js +21 -0
  85. package/dist/esm/actions/outdent-list-items-selected.js +281 -0
  86. package/dist/esm/actions/wrap-and-join-lists.js +94 -0
  87. package/dist/esm/commands/indent-list.js +61 -0
  88. package/dist/esm/commands/index.js +323 -0
  89. package/dist/esm/commands/isFirstChildOfParent.js +5 -0
  90. package/dist/esm/commands/join-list-item-forward.js +53 -0
  91. package/dist/esm/commands/listBackspace.js +275 -0
  92. package/dist/esm/commands/outdent-list.js +61 -0
  93. package/dist/esm/index.js +1 -1
  94. package/dist/esm/messages.js +29 -0
  95. package/dist/esm/plugin.js +130 -0
  96. package/dist/esm/pm-plugins/input-rules/create-list-input-rule.js +57 -0
  97. package/dist/esm/pm-plugins/input-rules/index.js +32 -0
  98. package/dist/esm/pm-plugins/input-rules/wrapping-join-rule.js +54 -0
  99. package/dist/esm/pm-plugins/keymap.js +19 -0
  100. package/dist/esm/pm-plugins/main.js +156 -0
  101. package/dist/esm/transforms.js +91 -0
  102. package/dist/esm/types.js +1 -1
  103. package/dist/esm/utils/analytics.js +12 -0
  104. package/dist/esm/utils/find.js +59 -0
  105. package/dist/esm/utils/indentation.js +15 -0
  106. package/dist/esm/utils/mark.js +33 -0
  107. package/dist/esm/utils/node.js +10 -0
  108. package/dist/esm/utils/selection.js +81 -0
  109. package/dist/types/actions/conversions.d.ts +6 -0
  110. package/dist/types/actions/indent-list-items-selected.d.ts +2 -0
  111. package/dist/types/actions/indent-list.d.ts +2 -0
  112. package/dist/types/actions/join-list-items-forward.d.ts +13 -0
  113. package/dist/types/actions/join-list-items-scenarios/index.d.ts +5 -0
  114. package/dist/types/actions/join-list-items-scenarios/join-list-item-with-paragraph.d.ts +9 -0
  115. package/dist/types/actions/join-list-items-scenarios/join-list-item-with-parent-nested-list.d.ts +9 -0
  116. package/dist/types/actions/join-list-items-scenarios/join-nested-list-with-parent-list-item.d.ts +9 -0
  117. package/dist/types/actions/join-list-items-scenarios/join-paragraph-with-list.d.ts +9 -0
  118. package/dist/types/actions/join-list-items-scenarios/join-sibling-list-items.d.ts +9 -0
  119. package/dist/types/actions/merge-lists.d.ts +7 -0
  120. package/dist/types/actions/outdent-list-items-selected.d.ts +3 -0
  121. package/dist/types/actions/wrap-and-join-lists.d.ts +17 -0
  122. package/dist/types/commands/indent-list.d.ts +6 -0
  123. package/dist/types/commands/index.d.ts +15 -0
  124. package/dist/types/commands/isFirstChildOfParent.d.ts +2 -0
  125. package/dist/types/commands/join-list-item-forward.d.ts +3 -0
  126. package/dist/types/commands/listBackspace.d.ts +10 -0
  127. package/dist/types/commands/outdent-list.d.ts +6 -0
  128. package/dist/types/index.d.ts +2 -1
  129. package/dist/types/messages.d.ts +27 -0
  130. package/dist/types/plugin.d.ts +2 -0
  131. package/dist/types/pm-plugins/input-rules/create-list-input-rule.d.ts +11 -0
  132. package/dist/types/pm-plugins/input-rules/index.d.ts +5 -0
  133. package/dist/types/pm-plugins/input-rules/wrapping-join-rule.d.ts +13 -0
  134. package/dist/types/pm-plugins/keymap.d.ts +5 -0
  135. package/dist/types/pm-plugins/main.d.ts +11 -0
  136. package/dist/types/transforms.d.ts +4 -0
  137. package/dist/types/types.d.ts +13 -13
  138. package/dist/types/utils/analytics.d.ts +5 -0
  139. package/dist/types/utils/find.d.ts +10 -0
  140. package/dist/types/utils/indentation.d.ts +2 -0
  141. package/dist/types/utils/mark.d.ts +8 -0
  142. package/dist/types/utils/node.d.ts +2 -0
  143. package/dist/types/utils/selection.d.ts +14 -0
  144. package/dist/types-ts4.5/actions/conversions.d.ts +6 -0
  145. package/dist/types-ts4.5/actions/indent-list-items-selected.d.ts +2 -0
  146. package/dist/types-ts4.5/actions/indent-list.d.ts +2 -0
  147. package/dist/types-ts4.5/actions/join-list-items-forward.d.ts +16 -0
  148. package/dist/types-ts4.5/actions/join-list-items-scenarios/index.d.ts +5 -0
  149. package/dist/types-ts4.5/actions/join-list-items-scenarios/join-list-item-with-paragraph.d.ts +9 -0
  150. package/dist/types-ts4.5/actions/join-list-items-scenarios/join-list-item-with-parent-nested-list.d.ts +9 -0
  151. package/dist/types-ts4.5/actions/join-list-items-scenarios/join-nested-list-with-parent-list-item.d.ts +9 -0
  152. package/dist/types-ts4.5/actions/join-list-items-scenarios/join-paragraph-with-list.d.ts +9 -0
  153. package/dist/types-ts4.5/actions/join-list-items-scenarios/join-sibling-list-items.d.ts +9 -0
  154. package/dist/types-ts4.5/actions/merge-lists.d.ts +7 -0
  155. package/dist/types-ts4.5/actions/outdent-list-items-selected.d.ts +3 -0
  156. package/dist/types-ts4.5/actions/wrap-and-join-lists.d.ts +17 -0
  157. package/dist/types-ts4.5/commands/indent-list.d.ts +6 -0
  158. package/dist/types-ts4.5/commands/index.d.ts +15 -0
  159. package/dist/types-ts4.5/commands/isFirstChildOfParent.d.ts +2 -0
  160. package/dist/types-ts4.5/commands/join-list-item-forward.d.ts +3 -0
  161. package/dist/types-ts4.5/commands/listBackspace.d.ts +13 -0
  162. package/dist/types-ts4.5/commands/outdent-list.d.ts +6 -0
  163. package/dist/types-ts4.5/index.d.ts +2 -1
  164. package/dist/types-ts4.5/messages.d.ts +27 -0
  165. package/dist/types-ts4.5/plugin.d.ts +2 -0
  166. package/dist/types-ts4.5/pm-plugins/input-rules/create-list-input-rule.d.ts +11 -0
  167. package/dist/types-ts4.5/pm-plugins/input-rules/index.d.ts +5 -0
  168. package/dist/types-ts4.5/pm-plugins/input-rules/wrapping-join-rule.d.ts +13 -0
  169. package/dist/types-ts4.5/pm-plugins/keymap.d.ts +5 -0
  170. package/dist/types-ts4.5/pm-plugins/main.d.ts +11 -0
  171. package/dist/types-ts4.5/transforms.d.ts +4 -0
  172. package/dist/types-ts4.5/types.d.ts +13 -13
  173. package/dist/types-ts4.5/utils/analytics.d.ts +5 -0
  174. package/dist/types-ts4.5/utils/find.d.ts +10 -0
  175. package/dist/types-ts4.5/utils/indentation.d.ts +2 -0
  176. package/dist/types-ts4.5/utils/mark.d.ts +8 -0
  177. package/dist/types-ts4.5/utils/node.d.ts +2 -0
  178. package/dist/types-ts4.5/utils/selection.d.ts +14 -0
  179. package/package.json +8 -5
  180. package/report.api.md +17 -18
  181. package/tmp/api-report-tmp.d.ts +15 -11
@@ -0,0 +1,61 @@
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
+ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
5
+ import { getCommonListAnalyticsAttributes, getListItemAttributes, hasValidListIndentationLevel } from '@atlaskit/editor-common/lists';
6
+ import { PassiveTransaction } from '@atlaskit/editor-common/preset';
7
+ import { isBulletList } from '@atlaskit/editor-common/utils';
8
+ import { closeHistory } from '@atlaskit/editor-prosemirror/history';
9
+ import { indentListItemsSelected as indentListAction } from '../actions/indent-list-items-selected';
10
+ import { MAX_NESTED_LIST_INDENTATION } from '../types';
11
+ import { findFirstParentListNode } from '../utils/find';
12
+ import { isInsideListItem, isInsideTableCell } from '../utils/selection';
13
+ export var indentList = function indentList(editorAnalyticsAPI) {
14
+ return function () {
15
+ var inputMethod = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : INPUT_METHOD.KEYBOARD;
16
+ return function (_ref) {
17
+ var tr = _ref.tr;
18
+ var $from = tr.selection.$from;
19
+
20
+ // don't indent if selection is not inside a list
21
+ if (!isInsideListItem(tr)) {
22
+ return null;
23
+ }
24
+
25
+ // Save the history, so it could undo/revert to the same state before the indent, see https://product-fabric.atlassian.net/browse/ED-14753
26
+ closeHistory(tr);
27
+ var firstListItemSelectedAttributes = getListItemAttributes($from);
28
+ var parentListNode = findFirstParentListNode($from);
29
+ if (!parentListNode || firstListItemSelectedAttributes && firstListItemSelectedAttributes.indentLevel === 0 && firstListItemSelectedAttributes.itemIndex === 0) {
30
+ if (isInsideTableCell(tr)) {
31
+ // dont consume tab, as table-keymap should move cursor to next cell
32
+ return null;
33
+ } else {
34
+ // Even though this is a non-operation, we don't want to send this event to the browser. Because if we return false, the browser will move the focus to another place
35
+ return new PassiveTransaction();
36
+ }
37
+ }
38
+ var currentListNode = parentListNode.node;
39
+ var actionSubjectId = isBulletList(currentListNode) ? ACTION_SUBJECT_ID.FORMAT_LIST_BULLET : ACTION_SUBJECT_ID.FORMAT_LIST_NUMBER;
40
+ indentListAction(tr);
41
+ var maximimunNestedLevelReached = !hasValidListIndentationLevel({
42
+ tr: tr,
43
+ maxIndentation: MAX_NESTED_LIST_INDENTATION
44
+ });
45
+ if (maximimunNestedLevelReached || !tr.docChanged) {
46
+ // Even though this is a non-operation, we don't want to send this event to the browser. Because if we return false, the browser will move the focus to another place
47
+ return new PassiveTransaction();
48
+ }
49
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
50
+ action: ACTION.INDENTED,
51
+ actionSubject: ACTION_SUBJECT.LIST,
52
+ actionSubjectId: actionSubjectId,
53
+ eventType: EVENT_TYPE.TRACK,
54
+ attributes: _objectSpread(_objectSpread({}, getCommonListAnalyticsAttributes(tr)), {}, {
55
+ inputMethod: inputMethod
56
+ })
57
+ })(tr);
58
+ return tr;
59
+ };
60
+ };
61
+ };
@@ -0,0 +1,323 @@
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
+ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
5
+ import { findCutBefore } from '@atlaskit/editor-common/commands';
6
+ import { getCommonListAnalyticsAttributes, moveTargetIntoList } from '@atlaskit/editor-common/lists';
7
+ import { editorCommandToPMCommand } from '@atlaskit/editor-common/preset';
8
+ import { GapCursorSelection } from '@atlaskit/editor-common/selection';
9
+ import { filterCommand as filter, hasVisibleContent, isEmptySelectionAtStart } from '@atlaskit/editor-common/utils';
10
+ import { chainCommands } from '@atlaskit/editor-prosemirror/commands';
11
+ import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
12
+ import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
13
+ import { findPositionOfNodeBefore, hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
14
+ import { convertListType } from '../actions/conversions';
15
+ import { wrapInListAndJoin } from '../actions/wrap-and-join-lists';
16
+ import { liftFollowingList, liftNodeSelectionList, liftTextSelectionList } from '../transforms';
17
+ import { sanitiseMarksInSelection } from '../utils/mark';
18
+ import { canJoinToPreviousListItem, isInsideListItem, selectionContainsList } from '../utils/selection';
19
+ import { indentList } from './indent-list';
20
+ import { isFirstChildOfParent } from './isFirstChildOfParent';
21
+ import { joinListItemForward } from './join-list-item-forward';
22
+ import { listBackspace } from './listBackspace';
23
+ import { outdentList } from './outdent-list';
24
+ export { outdentList, indentList };
25
+ export var enterKeyCommand = function enterKeyCommand(editorAnalyticsAPI) {
26
+ return function (featureFlags) {
27
+ return function (state, dispatch) {
28
+ var selection = state.selection;
29
+ if (selection.empty) {
30
+ var $from = selection.$from;
31
+ var _state$schema$nodes = state.schema.nodes,
32
+ listItem = _state$schema$nodes.listItem,
33
+ codeBlock = _state$schema$nodes.codeBlock;
34
+ var wrapper = $from.node($from.depth - 1);
35
+ if (wrapper && wrapper.type === listItem) {
36
+ /** Check if the wrapper has any visible content */
37
+ var wrapperHasContent = hasVisibleContent(wrapper);
38
+ if (!wrapperHasContent) {
39
+ return editorCommandToPMCommand(outdentList(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD, featureFlags))(state, dispatch);
40
+ } else if (!hasParentNodeOfType(codeBlock)(selection)) {
41
+ return splitListItem(listItem)(state, dispatch);
42
+ }
43
+ }
44
+ }
45
+ return false;
46
+ };
47
+ };
48
+ };
49
+ export var backspaceKeyCommand = function backspaceKeyCommand(editorAnalyticsAPI) {
50
+ return function (featureFlags) {
51
+ return function (state, dispatch) {
52
+ return chainCommands(listBackspace(editorAnalyticsAPI),
53
+ // if we're at the start of a list item, we need to either backspace
54
+ // directly to an empty list item above, or outdent this node
55
+ filter([isEmptySelectionAtStart,
56
+ // list items might have multiple paragraphs; only do this at the first one
57
+ isFirstChildOfParent, function (state) {
58
+ return isInsideListItem(state.tr);
59
+ }], chainCommands(deletePreviousEmptyListItem, editorCommandToPMCommand(outdentList(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD, featureFlags)))),
60
+ // if we're just inside a paragraph node (or gapcursor is shown) and backspace, then try to join
61
+ // the text to the previous list item, if one exists
62
+ filter([isEmptySelectionAtStart, function (state) {
63
+ return canJoinToPreviousListItem(state.tr);
64
+ }], joinToPreviousListItem))(state, dispatch);
65
+ };
66
+ };
67
+ };
68
+ export var deleteKeyCommand = function deleteKeyCommand(editorAnalyticsAPI) {
69
+ return joinListItemForward(editorAnalyticsAPI);
70
+ };
71
+
72
+ // Get the depth of the nearest ancestor list
73
+ export var rootListDepth = function rootListDepth(pos, nodes) {
74
+ var bulletList = nodes.bulletList,
75
+ orderedList = nodes.orderedList,
76
+ listItem = nodes.listItem;
77
+ var depth;
78
+ for (var i = pos.depth - 1; i > 0; i--) {
79
+ var node = pos.node(i);
80
+ if (node.type === bulletList || node.type === orderedList) {
81
+ depth = i;
82
+ }
83
+ if (node.type !== bulletList && node.type !== orderedList && node.type !== listItem) {
84
+ break;
85
+ }
86
+ }
87
+ return depth;
88
+ };
89
+ function untoggleSelectedList(tr) {
90
+ var _tr = tr,
91
+ selection = _tr.selection;
92
+ var depth = rootListDepth(selection.$to, tr.doc.type.schema.nodes);
93
+ tr = liftFollowingList(selection.$to.pos, selection.$to.end(depth), depth || 0, tr);
94
+ if (selection instanceof NodeSelection || selection instanceof GapCursorSelection) {
95
+ return liftNodeSelectionList(selection, tr);
96
+ }
97
+ return liftTextSelectionList(selection, tr);
98
+ }
99
+ export var toggleList = function toggleList(editorAnalyticsAPI) {
100
+ return function (inputMethod, listType) {
101
+ return function (_ref) {
102
+ var tr = _ref.tr;
103
+ var listInsideSelection = selectionContainsList(tr);
104
+ var listNodeType = tr.doc.type.schema.nodes[listType];
105
+ var actionSubjectId = listType === 'bulletList' ? ACTION_SUBJECT_ID.FORMAT_LIST_BULLET : ACTION_SUBJECT_ID.FORMAT_LIST_NUMBER;
106
+ if (listInsideSelection) {
107
+ var selection = tr.selection;
108
+
109
+ // for gap cursor or node selection - list is expected 1 level up (listItem -> list)
110
+ // for text selection - list is expected 2 levels up (paragraph -> listItem -> list)
111
+ var positionDiff = selection instanceof GapCursorSelection || selection instanceof NodeSelection ? 1 : 2;
112
+ var fromNode = selection.$from.node(selection.$from.depth - positionDiff);
113
+ var toNode = selection.$to.node(selection.$to.depth - positionDiff);
114
+ var transformedFrom = listInsideSelection.type.name === 'bulletList' ? ACTION_SUBJECT_ID.FORMAT_LIST_BULLET : ACTION_SUBJECT_ID.FORMAT_LIST_NUMBER;
115
+ if ((fromNode === null || fromNode === void 0 ? void 0 : fromNode.type.name) === listType && (toNode === null || toNode === void 0 ? void 0 : toNode.type.name) === listType) {
116
+ var commonAttributes = getCommonListAnalyticsAttributes(tr);
117
+ untoggleSelectedList(tr);
118
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
119
+ action: ACTION.CONVERTED,
120
+ actionSubject: ACTION_SUBJECT.LIST,
121
+ actionSubjectId: ACTION_SUBJECT_ID.TEXT,
122
+ eventType: EVENT_TYPE.TRACK,
123
+ attributes: _objectSpread(_objectSpread({}, commonAttributes), {}, {
124
+ transformedFrom: transformedFrom,
125
+ inputMethod: inputMethod
126
+ })
127
+ })(tr);
128
+ return tr;
129
+ }
130
+ convertListType({
131
+ tr: tr,
132
+ nextListNodeType: listNodeType
133
+ });
134
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
135
+ action: ACTION.CONVERTED,
136
+ actionSubject: ACTION_SUBJECT.LIST,
137
+ actionSubjectId: actionSubjectId,
138
+ eventType: EVENT_TYPE.TRACK,
139
+ attributes: _objectSpread(_objectSpread({}, getCommonListAnalyticsAttributes(tr)), {}, {
140
+ transformedFrom: transformedFrom,
141
+ inputMethod: inputMethod
142
+ })
143
+ })(tr);
144
+ } else {
145
+ // Need to have this before wrapInList so the wrapping is done with valid content
146
+ // For example, if trying to convert centre or right aligned paragraphs to lists
147
+ sanitiseMarksInSelection(tr, listNodeType);
148
+ wrapInListAndJoin(listNodeType, tr);
149
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
150
+ action: ACTION.INSERTED,
151
+ actionSubject: ACTION_SUBJECT.LIST,
152
+ actionSubjectId: actionSubjectId,
153
+ eventType: EVENT_TYPE.TRACK,
154
+ attributes: {
155
+ inputMethod: inputMethod
156
+ }
157
+ })(tr);
158
+ }
159
+
160
+ // If document wasn't changed, return false from the command to indicate that the
161
+ // editing action failed
162
+ if (!tr.docChanged) {
163
+ return null;
164
+ }
165
+ return tr;
166
+ };
167
+ };
168
+ };
169
+ export var toggleBulletList = function toggleBulletList(editorAnalyticsAPI) {
170
+ return function () {
171
+ var inputMethod = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : INPUT_METHOD.TOOLBAR;
172
+ return toggleList(editorAnalyticsAPI)(inputMethod, 'bulletList');
173
+ };
174
+ };
175
+ export var toggleOrderedList = function toggleOrderedList(editorAnalyticsAPI) {
176
+ return function () {
177
+ var inputMethod = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : INPUT_METHOD.TOOLBAR;
178
+ return toggleList(editorAnalyticsAPI)(inputMethod, 'orderedList');
179
+ };
180
+ };
181
+
182
+ /**
183
+ * Implementation taken and modified for our needs from PM
184
+ * @param itemType Node
185
+ * Splits the list items, specific implementation take from PM
186
+ */
187
+ function splitListItem(itemType) {
188
+ return function (state, dispatch) {
189
+ var ref = state.selection;
190
+ var $from = ref.$from;
191
+ var $to = ref.$to;
192
+ var node = ref.node;
193
+ if (node && node.isBlock || $from.depth < 2 || !$from.sameParent($to)) {
194
+ return false;
195
+ }
196
+ var grandParent = $from.node(-1);
197
+ if (grandParent.type !== itemType) {
198
+ return false;
199
+ }
200
+ /** --> The following line changed from the original PM implementation to allow list additions with multiple paragraphs */
201
+ if (
202
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
203
+ grandParent.content.content.length <= 1 && $from.parent.content.size === 0 && !(grandParent.content.size === 0)) {
204
+ // In an empty block. If this is a nested list, the wrapping
205
+ // list item should be split. Otherwise, bail out and let next
206
+ // command handle lifting.
207
+ if ($from.depth === 2 || $from.node(-3).type !== itemType || $from.index(-2) !== $from.node(-2).childCount - 1) {
208
+ return false;
209
+ }
210
+ if (dispatch) {
211
+ var wrap = Fragment.empty;
212
+ var keepItem = $from.index(-1) > 0;
213
+ // Build a fragment containing empty versions of the structure
214
+ // from the outer list item to the parent node of the cursor
215
+ for (var d = $from.depth - (keepItem ? 1 : 2); d >= $from.depth - 3; d--) {
216
+ wrap = Fragment.from($from.node(d).copy(wrap));
217
+ }
218
+ // Add a second list item with an empty default start node
219
+ wrap = wrap.append(Fragment.from(itemType.createAndFill()));
220
+ var tr$1 = state.tr.replace($from.before(keepItem ? undefined : -1), $from.after(-3), new Slice(wrap, keepItem ? 3 : 2, 2));
221
+ tr$1.setSelection(
222
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
223
+ state.selection.constructor.near(tr$1.doc.resolve($from.pos + (keepItem ? 3 : 2))));
224
+ dispatch(tr$1.scrollIntoView());
225
+ }
226
+ return true;
227
+ }
228
+ var nextType = $to.pos === $from.end() ? grandParent.contentMatchAt(0).defaultType : null;
229
+ var tr = state.tr.delete($from.pos, $to.pos);
230
+ var types = nextType && [null, {
231
+ type: nextType
232
+ }];
233
+ if (dispatch) {
234
+ dispatch(tr.split($from.pos, 2, types !== null && types !== void 0 ? types : undefined).scrollIntoView());
235
+ }
236
+ return true;
237
+ };
238
+ }
239
+ var deletePreviousEmptyListItem = function deletePreviousEmptyListItem(state, dispatch) {
240
+ var $from = state.selection.$from;
241
+ var listItem = state.schema.nodes.listItem;
242
+ var $cut = findCutBefore($from);
243
+ if (!$cut || !$cut.nodeBefore || !($cut.nodeBefore.type === listItem)) {
244
+ return false;
245
+ }
246
+ var previousListItemEmpty = $cut.nodeBefore.childCount === 1 && $cut.nodeBefore.firstChild.nodeSize <= 2;
247
+ if (previousListItemEmpty) {
248
+ var tr = state.tr;
249
+ if (dispatch) {
250
+ dispatch(tr.delete($cut.pos - $cut.nodeBefore.nodeSize, $from.pos).scrollIntoView());
251
+ }
252
+ return true;
253
+ }
254
+ return false;
255
+ };
256
+ var joinToPreviousListItem = function joinToPreviousListItem(state, dispatch) {
257
+ var $from = state.selection.$from;
258
+ var _state$schema$nodes2 = state.schema.nodes,
259
+ paragraph = _state$schema$nodes2.paragraph,
260
+ listItem = _state$schema$nodes2.listItem,
261
+ codeBlock = _state$schema$nodes2.codeBlock,
262
+ bulletList = _state$schema$nodes2.bulletList,
263
+ orderedList = _state$schema$nodes2.orderedList;
264
+ var isGapCursorShown = state.selection instanceof GapCursorSelection;
265
+ var $cutPos = isGapCursorShown ? state.doc.resolve($from.pos + 1) : $from;
266
+ var $cut = findCutBefore($cutPos);
267
+ if (!$cut) {
268
+ return false;
269
+ }
270
+
271
+ // see if the containing node is a list
272
+ if ($cut.nodeBefore && [bulletList, orderedList].indexOf($cut.nodeBefore.type) > -1) {
273
+ // and the node after this is a paragraph or a codeBlock
274
+ if ($cut.nodeAfter && ($cut.nodeAfter.type === paragraph || $cut.nodeAfter.type === codeBlock)) {
275
+ // find the nearest paragraph that precedes this node
276
+ var $lastNode = $cut.doc.resolve($cut.pos - 1);
277
+ while ($lastNode.parent.type !== paragraph) {
278
+ $lastNode = state.doc.resolve($lastNode.pos - 1);
279
+ }
280
+ var tr = state.tr;
281
+ if (isGapCursorShown) {
282
+ var nodeBeforePos = findPositionOfNodeBefore(tr.selection);
283
+ if (typeof nodeBeforePos !== 'number') {
284
+ return false;
285
+ }
286
+ // append the codeblock to the list node
287
+ var list = $cut.nodeBefore.copy($cut.nodeBefore.content.append(Fragment.from(listItem.createChecked({}, $cut.nodeAfter))));
288
+ tr.replaceWith(nodeBeforePos, $from.pos + $cut.nodeAfter.nodeSize, list);
289
+ } else {
290
+ var step = moveTargetIntoList({
291
+ insertPosition: $lastNode.pos,
292
+ $target: $cut
293
+ });
294
+
295
+ // ED-13966: check if the step will cause an ProseMirror error
296
+ // if there's an error don't apply the step as it will might lead into a data loss.
297
+ // It doesn't play well with media being a leaf node.
298
+ var stepResult = state.tr.maybeStep(step);
299
+ if (stepResult.failed) {
300
+ return false;
301
+ } else {
302
+ tr = state.tr.step(step);
303
+ }
304
+ }
305
+
306
+ // find out if there's now another list following and join them
307
+ // as in, [list, p, list] => [list with p, list], and we want [joined list]
308
+ var $postCut = tr.doc.resolve(tr.mapping.map($cut.pos + $cut.nodeAfter.nodeSize));
309
+ if ($postCut.nodeBefore && $postCut.nodeAfter && $postCut.nodeBefore.type === $postCut.nodeAfter.type && [bulletList, orderedList].indexOf($postCut.nodeBefore.type) > -1) {
310
+ tr = tr.join($postCut.pos);
311
+ }
312
+ if (dispatch) {
313
+ var _tr$doc$resolve$nodeB;
314
+ if (!((_tr$doc$resolve$nodeB = tr.doc.resolve($lastNode.pos).nodeBefore) !== null && _tr$doc$resolve$nodeB !== void 0 && _tr$doc$resolve$nodeB.isBlock) || tr.doc.resolve($lastNode.pos).nodeBefore === null) {
315
+ tr = tr.setSelection(TextSelection.near(tr.doc.resolve(tr.mapping.map($cut.pos)), -1));
316
+ }
317
+ dispatch(tr.scrollIntoView());
318
+ }
319
+ return true;
320
+ }
321
+ }
322
+ return false;
323
+ };
@@ -0,0 +1,5 @@
1
+ import { GapCursorSelection } from '@atlaskit/editor-common/selection';
2
+ export var isFirstChildOfParent = function isFirstChildOfParent(state) {
3
+ var $from = state.selection.$from;
4
+ return $from.depth > 1 ? state.selection instanceof GapCursorSelection && $from.parentOffset === 0 || $from.index($from.depth - 1) === 0 : true;
5
+ };
@@ -0,0 +1,53 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, DELETE_DIRECTION, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
3
+ import { isEmptySelectionAtEnd, walkNextNode } from '@atlaskit/editor-common/utils';
4
+ import { findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
5
+ import { calcJoinListScenario } from '../actions/join-list-items-forward';
6
+ export var joinListItemForward = function joinListItemForward(editorAnalyticsAPI) {
7
+ return function (state, dispatch) {
8
+ var tr = state.tr,
9
+ $head = state.selection.$head;
10
+ var walkNode = walkNextNode($head);
11
+ if (!isEmptySelectionAtEnd(state)) {
12
+ return false;
13
+ }
14
+ var scenarios = calcJoinListScenario(walkNode, $head);
15
+ if (!scenarios) {
16
+ return false;
17
+ }
18
+ var _scenarios = _slicedToArray(scenarios, 2),
19
+ scenario = _scenarios[0],
20
+ action = _scenarios[1];
21
+ var result = action({
22
+ tr: tr,
23
+ $next: walkNode.$pos,
24
+ $head: $head
25
+ });
26
+ if (!result) {
27
+ return false;
28
+ }
29
+ var _state$schema$nodes = state.schema.nodes,
30
+ bulletList = _state$schema$nodes.bulletList,
31
+ orderedList = _state$schema$nodes.orderedList;
32
+ var listParent = findParentNodeOfType([bulletList, orderedList])(tr.selection);
33
+ var actionSubjectId = ACTION_SUBJECT_ID.FORMAT_LIST_BULLET;
34
+ if (listParent && listParent.node.type === orderedList) {
35
+ actionSubjectId = ACTION_SUBJECT_ID.FORMAT_LIST_NUMBER;
36
+ }
37
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
38
+ action: ACTION.LIST_ITEM_JOINED,
39
+ actionSubject: ACTION_SUBJECT.LIST,
40
+ actionSubjectId: actionSubjectId,
41
+ eventType: EVENT_TYPE.TRACK,
42
+ attributes: {
43
+ inputMethod: INPUT_METHOD.KEYBOARD,
44
+ direction: DELETE_DIRECTION.FORWARD,
45
+ scenario: scenario
46
+ }
47
+ })(tr);
48
+ if (dispatch) {
49
+ dispatch(tr);
50
+ }
51
+ return true;
52
+ };
53
+ };