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