@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,79 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.joinNestedListWithParentListItem = void 0;
7
+ var _utils = require("@atlaskit/editor-common/utils");
8
+ //Case for two adjacent list items with the first being of lower indentation
9
+ var joinNestedListWithParentListItem = function joinNestedListWithParentListItem(_ref) {
10
+ var tr = _ref.tr,
11
+ $next = _ref.$next,
12
+ $head = _ref.$head;
13
+ /* CASE 3
14
+ * Initial Structure:
15
+ *
16
+ * List A {
17
+ * ListItem B {
18
+ * ...Children C
19
+ * Paragraph D { text1 |$head||textInsertPos| } |childrenHInsertPos|
20
+ * List E { |$next||childrenJInsertPos|
21
+ * ListItem F {
22
+ * Paragraph G { text2 }
23
+ * ...Children H
24
+ * List? I {
25
+ * ...Children J
26
+ * }
27
+ * }
28
+ * ...Children K
29
+ * }
30
+ * }
31
+ * }
32
+ *
33
+ * Converts to:
34
+ *
35
+ * List A {
36
+ * ListItem B {
37
+ * ...Children C
38
+ * Paragraph D { text1text2 }
39
+ * ...Children H
40
+ * List E {
41
+ * ...Children J
42
+ * ...Children K
43
+ * }
44
+ * }
45
+ * }
46
+ *
47
+ */
48
+
49
+ var listE = $next.parent;
50
+ var listItemF = $next.nodeAfter; //We know next is before a ListItem. ListItem must have at least one child
51
+ if (!listItemF || !listItemF.lastChild) {
52
+ return false;
53
+ }
54
+ var paragraphG = listItemF.firstChild; //ListItem must have at least one child
55
+ if (!paragraphG) {
56
+ return false;
57
+ }
58
+ var beforeListE = $next.before();
59
+ var beforeListItemF = $next.pos;
60
+ var afterParagraphD = $head.after();
61
+ var afterListE = $next.after();
62
+ var afterListItemF = tr.doc.resolve($next.pos + 1).after(); //List must always have at least one listItem
63
+
64
+ var containsChildrenJ = (0, _utils.isListNode)(listItemF.lastChild);
65
+ var shouldRemoveListE = listE.childCount === 1 && !containsChildrenJ; //Assures no Children J and K
66
+
67
+ var textInsertPos = $head.pos;
68
+ var childrenHInsertPos = afterParagraphD;
69
+ var childrenJInsertPos = $next.pos;
70
+ var textContent = paragraphG.content;
71
+ var childrenHContent = containsChildrenJ ? listItemF.content.cut(paragraphG.nodeSize, listItemF.nodeSize - listItemF.lastChild.nodeSize - 2) : listItemF.content.cut(paragraphG.nodeSize); //If Children J doesn't exist then Children H will include the last node
72
+ var childrenJContent = listItemF.lastChild.content; //Will be invalid if there are no Children J but it will be unused
73
+
74
+ (0, _utils.insertContentDeleteRange)(tr, function (tr) {
75
+ return tr.doc.resolve(textInsertPos);
76
+ }, containsChildrenJ ? [[textContent, textInsertPos], [childrenHContent, childrenHInsertPos], [childrenJContent, childrenJInsertPos]] : [[textContent, textInsertPos], [childrenHContent, childrenHInsertPos]], [shouldRemoveListE ? [beforeListE, afterListE] : [beforeListItemF, afterListItemF]]);
77
+ return true;
78
+ };
79
+ exports.joinNestedListWithParentListItem = joinNestedListWithParentListItem;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.joinParagrapWithList = void 0;
7
+ var _utils = require("@atlaskit/editor-common/utils");
8
+ //Case for two adjacent nodes with the first being a list item and the last being a paragraph
9
+ var joinParagrapWithList = function joinParagrapWithList(_ref) {
10
+ var tr = _ref.tr,
11
+ $next = _ref.$next,
12
+ $head = _ref.$head;
13
+ /* CASE 1
14
+ * Initial Structure:
15
+ *
16
+ * List A {
17
+ * ListItem B {
18
+ * ...Children C
19
+ * Paragraph D { text1 |$head||textInsertPos| }
20
+ * }
21
+ * }
22
+ * Paragraph E { |$next| text 2 }
23
+ *
24
+ * Converts to:
25
+ *
26
+ * List A {
27
+ * ListItem B {
28
+ * ...Children C
29
+ * Paragraph D { text1text2 }
30
+ * }
31
+ * }
32
+ *
33
+ */
34
+
35
+ var paragraphE = $next.parent;
36
+ var beforeParagraphE = $next.before();
37
+ var afterParagraphE = $next.after();
38
+ var textInsertPos = $head.pos;
39
+ var textContent = paragraphE.content;
40
+ (0, _utils.insertContentDeleteRange)(tr, function (tr) {
41
+ return tr.doc.resolve(textInsertPos);
42
+ }, [[textContent, textInsertPos]], [[beforeParagraphE, afterParagraphE]]);
43
+ return true;
44
+ };
45
+ exports.joinParagrapWithList = joinParagrapWithList;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.joinSiblingListItems = void 0;
7
+ var _utils = require("@atlaskit/editor-common/utils");
8
+ //Case for two adjacent list items of the same indentation
9
+ var joinSiblingListItems = function joinSiblingListItems(_ref) {
10
+ var tr = _ref.tr,
11
+ $next = _ref.$next,
12
+ $head = _ref.$head;
13
+ /* CASE 2
14
+ * Initial Structure:
15
+ *
16
+ * List A {
17
+ * ListItem B {
18
+ * ...Children C
19
+ * Paragraph D { text1 |$head||textInsertPos| } //Cant have children since that would be Case 4
20
+ * |childrenGInsertPos| }
21
+ * ListItem E { |$next|
22
+ * Paragraph F { text2 }
23
+ * ...Children G
24
+ * }
25
+ * }
26
+ *
27
+ * Converts to:
28
+ *
29
+ * List A {
30
+ * ListItem B {
31
+ * ...Children C
32
+ * Paragraph C { text1text2 }
33
+ * ...Children G
34
+ * }
35
+ * }
36
+ *
37
+ */
38
+
39
+ var listItemE = $next.parent;
40
+ var paragraphF = $next.nodeAfter; //ListItem must have at least one child
41
+ if (!paragraphF) {
42
+ return false;
43
+ }
44
+ var beforeListItemE = $next.before();
45
+ var afterListItemE = $next.after();
46
+ var endListItemB = $head.end(-1);
47
+ var textInsertPos = $head.pos;
48
+ var childrenGInsertPos = endListItemB;
49
+ var textContent = paragraphF.content;
50
+ var childrenGContent = listItemE.content.cut(paragraphF.nodeSize);
51
+ (0, _utils.insertContentDeleteRange)(tr, function (tr) {
52
+ return tr.doc.resolve(textInsertPos);
53
+ }, [[textContent, textInsertPos], [childrenGContent, childrenGInsertPos]], [[beforeListItemE, afterListItemE]]);
54
+ return true;
55
+ };
56
+ exports.joinSiblingListItems = joinSiblingListItems;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.mergeNextListAtPosition = mergeNextListAtPosition;
7
+ var _utils = require("@atlaskit/editor-common/utils");
8
+ function mergeNextListAtPosition(_ref) {
9
+ var tr = _ref.tr,
10
+ listPosition = _ref.listPosition;
11
+ var listNodeAtPosition = tr.doc.nodeAt(listPosition);
12
+ if (!(0, _utils.isListNode)(listNodeAtPosition)) {
13
+ return;
14
+ }
15
+ var listPositionResolved = tr.doc.resolve(listPosition + listNodeAtPosition.nodeSize);
16
+ var pos = listPositionResolved.pos,
17
+ nodeAfter = listPositionResolved.nodeAfter,
18
+ nodeBefore = listPositionResolved.nodeBefore;
19
+ if (!(0, _utils.isListNode)(nodeBefore) || !(0, _utils.isListNode)(nodeAfter)) {
20
+ return;
21
+ }
22
+ if ((nodeAfter === null || nodeAfter === void 0 ? void 0 : nodeAfter.type.name) !== (nodeBefore === null || nodeBefore === void 0 ? void 0 : nodeBefore.type.name)) {
23
+ var previousListPosition = pos - nodeBefore.nodeSize;
24
+ tr.setNodeMarkup(previousListPosition, nodeAfter.type);
25
+ }
26
+ tr.join(pos);
27
+ }
@@ -0,0 +1,289 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.outdentListItemsSelected = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _analytics = require("@atlaskit/editor-common/analytics");
10
+ var _lists = require("@atlaskit/editor-common/lists");
11
+ var _selection = require("@atlaskit/editor-common/selection");
12
+ var _utils = require("@atlaskit/editor-common/utils");
13
+ var _model = require("@atlaskit/editor-prosemirror/model");
14
+ var _state = require("@atlaskit/editor-prosemirror/state");
15
+ var _transform = require("@atlaskit/editor-prosemirror/transform");
16
+ var _analytics2 = require("../utils/analytics");
17
+ var _find = require("../utils/find");
18
+ var _selection2 = require("../utils/selection");
19
+ 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; }
20
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
21
+ var outdentListItemsSelected = function outdentListItemsSelected(tr, featureFlags) {
22
+ var originalSelection = tr.selection;
23
+ var normalizedSelection = (0, _lists.normalizeListItemsSelection)({
24
+ selection: tr.selection,
25
+ doc: tr.doc
26
+ });
27
+ var rootList = (0, _find.findRootParentListNode)(normalizedSelection.$from);
28
+ if (!rootList) {
29
+ return;
30
+ }
31
+ var commonList = normalizedSelection.$from.blockRange(rootList, _utils.isListNode);
32
+ if (!commonList) {
33
+ return;
34
+ }
35
+ var hasNormalizedToPositionLiftedOut = false;
36
+ var hasNormalizedFromPositionLiftedOut = false;
37
+ var oldFrom = normalizedSelection.from,
38
+ oldTo = normalizedSelection.to;
39
+ var nodeRanges = splitRangeSelection(normalizedSelection);
40
+ nodeRanges.forEach(function (range) {
41
+ var $from = tr.doc.resolve(tr.mapping.map(range.from));
42
+ var $to = tr.doc.resolve(tr.mapping.map(range.to));
43
+ var mappedRange = $from.blockRange($to, _utils.isListNode);
44
+ if (!mappedRange) {
45
+ return;
46
+ }
47
+ if ((0, _utils.isListItemNode)($from.node(mappedRange.depth - 1))) {
48
+ outdentRangeToParentList({
49
+ tr: tr,
50
+ range: mappedRange
51
+ });
52
+ } else {
53
+ extractListItemsRangeFromList({
54
+ tr: tr,
55
+ range: mappedRange,
56
+ featureFlags: featureFlags
57
+ });
58
+ hasNormalizedToPositionLiftedOut = hasNormalizedToPositionLiftedOut || oldTo >= range.from && oldTo < range.to;
59
+ hasNormalizedFromPositionLiftedOut = hasNormalizedFromPositionLiftedOut || oldFrom >= range.from && oldFrom < range.to;
60
+ }
61
+ });
62
+ var hasCommonListMoved = commonList.start !== tr.mapping.map(commonList.start);
63
+ var nextSelection = calculateNewSelection({
64
+ originalSelection: originalSelection,
65
+ normalizedSelection: normalizedSelection,
66
+ tr: tr,
67
+ hasCommonListMoved: hasCommonListMoved,
68
+ hasNormalizedToPositionLiftedOut: hasNormalizedToPositionLiftedOut,
69
+ hasNormalizedFromPositionLiftedOut: hasNormalizedFromPositionLiftedOut
70
+ });
71
+ tr.setSelection(nextSelection);
72
+ (0, _lists.joinSiblingLists)({
73
+ tr: tr,
74
+ direction: _lists.JoinDirection.RIGHT
75
+ });
76
+ };
77
+ exports.outdentListItemsSelected = outdentListItemsSelected;
78
+ var calculateNewSelection = function calculateNewSelection(_ref) {
79
+ var tr = _ref.tr,
80
+ originalSelection = _ref.originalSelection,
81
+ normalizedSelection = _ref.normalizedSelection,
82
+ hasCommonListMoved = _ref.hasCommonListMoved,
83
+ hasNormalizedToPositionLiftedOut = _ref.hasNormalizedToPositionLiftedOut,
84
+ hasNormalizedFromPositionLiftedOut = _ref.hasNormalizedFromPositionLiftedOut;
85
+ var $from = normalizedSelection.$from,
86
+ $to = normalizedSelection.$to;
87
+ var isCursorSelection = normalizedSelection.empty;
88
+ var from = tr.mapping.map($from.pos);
89
+ var to = tr.mapping.map($to.pos);
90
+ var LIST_STRUCTURE_CHANGED_OFFSET = 2;
91
+ var isToFromSameListItem = $from.sameParent($to);
92
+ if (hasNormalizedFromPositionLiftedOut) {
93
+ var fromMapped = isToFromSameListItem ? $from.pos : from;
94
+ from = hasNormalizedFromPositionLiftedOut ? $from.pos : fromMapped;
95
+ from = hasCommonListMoved ? from - LIST_STRUCTURE_CHANGED_OFFSET : from;
96
+ from = Math.max(from, 0);
97
+ }
98
+ if (hasNormalizedToPositionLiftedOut) {
99
+ var toMapped = isToFromSameListItem ? $to.pos : to;
100
+ to = hasNormalizedToPositionLiftedOut ? $to.pos : toMapped;
101
+ to = hasCommonListMoved ? to - LIST_STRUCTURE_CHANGED_OFFSET : to;
102
+ to = Math.min(to, tr.doc.nodeSize - 2);
103
+ }
104
+ if (normalizedSelection instanceof _selection.GapCursorSelection) {
105
+ var nextSelectionFrom = tr.doc.resolve(from);
106
+ return new _selection.GapCursorSelection(nextSelectionFrom, normalizedSelection.side);
107
+ }
108
+ if (originalSelection instanceof _state.NodeSelection) {
109
+ return _state.NodeSelection.create(tr.doc, from);
110
+ }
111
+ if (isCursorSelection) {
112
+ return _state.TextSelection.between(tr.doc.resolve(to), tr.doc.resolve(to), -1);
113
+ }
114
+ return _state.TextSelection.between(tr.doc.resolve(from), tr.doc.resolve(to), -1);
115
+ };
116
+ var splitRangeSelection = function splitRangeSelection(selection) {
117
+ var commonListRange = (0, _selection2.createListNodeRange)({
118
+ selection: selection
119
+ });
120
+ if (!commonListRange) {
121
+ return [];
122
+ }
123
+ var $from = selection.$from,
124
+ $to = selection.$to;
125
+ if ($from.pos === $to.pos && $from.sameParent($to)) {
126
+ return [{
127
+ from: commonListRange.start,
128
+ to: commonListRange.end,
129
+ depth: commonListRange.depth
130
+ }];
131
+ }
132
+ var lastListItem = findPreviousListItemSibling($from);
133
+ if (!lastListItem) {
134
+ return [];
135
+ }
136
+ var nodeRanges = [];
137
+ var doc = $from.doc;
138
+ var previousListItem = findPreviousListItemSibling($to);
139
+ while (previousListItem && previousListItem.pos >= lastListItem.pos && previousListItem.pos >= commonListRange.start) {
140
+ var node = doc.nodeAt(previousListItem.pos);
141
+ if (!node || !(0, _utils.isListItemNode)(node)) {
142
+ return [];
143
+ }
144
+ var offset = 0;
145
+ if (node && node.lastChild && (0, _utils.isListNode)(node.lastChild)) {
146
+ offset = node.lastChild.nodeSize;
147
+ }
148
+ var start = previousListItem.pos + 1;
149
+ nodeRanges.push({
150
+ from: start,
151
+ to: doc.resolve(start).end() - offset,
152
+ depth: previousListItem.depth
153
+ });
154
+ previousListItem = findPreviousListItemSibling(previousListItem);
155
+ }
156
+ return nodeRanges;
157
+ };
158
+ var outdentRangeToParentList = function outdentRangeToParentList(_ref2) {
159
+ var tr = _ref2.tr,
160
+ range = _ref2.range;
161
+ var end = range.end;
162
+ var endOfList = range.$to.end(range.depth);
163
+ var listItem = tr.doc.type.schema.nodes.listItem;
164
+ if (end < endOfList) {
165
+ var slice = new _model.Slice(_model.Fragment.from(listItem.create(null, range.parent.copy())), 1, 0);
166
+ var step = new _transform.ReplaceAroundStep(end - 1, endOfList, end, endOfList, slice, 1, true);
167
+ tr.step(step);
168
+ range = new _model.NodeRange(tr.doc.resolve(range.$from.pos), tr.doc.resolve(endOfList), range.depth);
169
+ }
170
+ var target = (0, _transform.liftTarget)(range);
171
+ if (target) {
172
+ tr.lift(range, target);
173
+ }
174
+ };
175
+ var extractListItemsRangeFromList = function extractListItemsRangeFromList(_ref3) {
176
+ var tr = _ref3.tr,
177
+ range = _ref3.range,
178
+ featureFlags = _ref3.featureFlags;
179
+ var list = range.parent;
180
+ var $start = tr.doc.resolve(range.start);
181
+ var listStart = $start.start(range.depth);
182
+ var listEnd = $start.end(range.depth);
183
+ var isAtTop = listStart === range.start;
184
+ var isAtBottom = listEnd === range.end;
185
+ var isTheEntireList = isAtTop && isAtBottom;
186
+ var listItemContent = isAtTop ? _model.Fragment.empty : _model.Fragment.from(list.copy(_model.Fragment.empty));
187
+ for (var i = range.startIndex; i < range.endIndex; i++) {
188
+ listItemContent = listItemContent.append(list.child(i).content);
189
+ }
190
+ if (isAtTop) {
191
+ for (var _i = 0; _i < listItemContent.childCount; _i++) {
192
+ var child = listItemContent.child(_i);
193
+ if (child && (0, _utils.isListNode)(child) && child.type !== list.type) {
194
+ var newNestedList = list.type.create(null, child.content);
195
+ listItemContent = listItemContent.replaceChild(_i, newNestedList);
196
+ }
197
+ }
198
+ }
199
+ var nextList = list.copy(_model.Fragment.empty);
200
+ var nextListStartNumber;
201
+ if (featureFlags !== null && featureFlags !== void 0 && featureFlags.restartNumberedLists) {
202
+ // if splitting a numbered list, keep the splitted item
203
+ // counter as the start of the next (second half) list (instead
204
+ // of reverting back to 1 as a starting number)
205
+ var order = (0, _utils.getOrderFromOrderedListNode)(list);
206
+ if (list.type.name === 'orderedList') {
207
+ nextListStartNumber = range.endIndex - 1 + order;
208
+ // @ts-ignore - [unblock prosemirror bump] assigning to readonly attrs
209
+ nextList.attrs = _objectSpread(_objectSpread({}, nextList.attrs), {}, {
210
+ order: nextListStartNumber
211
+ });
212
+ var _getRestartListsAttri = (0, _analytics2.getRestartListsAttributes)(tr),
213
+ splitListStartNumber = _getRestartListsAttri.splitListStartNumber;
214
+ if (typeof splitListStartNumber !== 'number') {
215
+ (0, _analytics2.storeRestartListsAttributes)(tr, {
216
+ splitListStartNumber: nextListStartNumber
217
+ });
218
+ }
219
+ }
220
+ }
221
+ var nextListFragment = listItemContent.append(_model.Fragment.from(nextList));
222
+ if (featureFlags !== null && featureFlags !== void 0 && featureFlags.restartNumberedLists) {
223
+ // if the split list with nextListStartNumber is below another list
224
+ // with order (e.g due to multi-level indent items being lifted), track the
225
+ // list above's order instead, as it will be the split list's order after sibling joins
226
+ nextListFragment.forEach(function (node, _offset, index) {
227
+ var _node$attrs;
228
+ if (node.type.name === 'orderedList' && ((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.order) === nextListStartNumber) {
229
+ var _prev$attrs;
230
+ var prev = nextListFragment.child(index - 1);
231
+ if ((prev === null || prev === void 0 ? void 0 : (_prev$attrs = prev.attrs) === null || _prev$attrs === void 0 ? void 0 : _prev$attrs.order) >= 0) {
232
+ var _prev$attrs2;
233
+ (0, _analytics2.storeRestartListsAttributes)(tr, {
234
+ splitListStartNumber: prev === null || prev === void 0 ? void 0 : (_prev$attrs2 = prev.attrs) === null || _prev$attrs2 === void 0 ? void 0 : _prev$attrs2.order
235
+ });
236
+ }
237
+ }
238
+ });
239
+ }
240
+ if (isTheEntireList) {
241
+ var slice = new _model.Slice(listItemContent, 0, 0);
242
+ var step = new _transform.ReplaceStep($start.pos - 1, range.end + 1, slice, false);
243
+ if (featureFlags !== null && featureFlags !== void 0 && featureFlags.restartNumberedLists) {
244
+ (0, _analytics2.storeRestartListsAttributes)(tr, {
245
+ outdentScenario: undefined
246
+ });
247
+ }
248
+ tr.step(step);
249
+ } else if (isAtTop) {
250
+ var _slice = new _model.Slice(nextListFragment, 0, 1);
251
+ var _step = new _transform.ReplaceStep($start.pos - 1, range.end, _slice, false);
252
+ tr.step(_step);
253
+ } else if (isAtBottom) {
254
+ var _slice2 = new _model.Slice(listItemContent, 1, 0);
255
+ var _step2 = new _transform.ReplaceStep($start.pos, listEnd + 1, _slice2, false);
256
+ tr.step(_step2);
257
+ } else {
258
+ if (featureFlags !== null && featureFlags !== void 0 && featureFlags.restartNumberedLists) {
259
+ (0, _analytics2.storeRestartListsAttributes)(tr, {
260
+ outdentScenario: _analytics.OUTDENT_SCENARIOS.SPLIT_LIST
261
+ });
262
+ }
263
+ var _slice3 = new _model.Slice(nextListFragment, 1, 1);
264
+ var _step3 = new _transform.ReplaceAroundStep($start.pos, listEnd, range.end, listEnd, _slice3, _slice3.size, false);
265
+ tr.step(_step3);
266
+ }
267
+ };
268
+ var findPreviousListItemSibling = function findPreviousListItemSibling($pos) {
269
+ var doc = $pos.doc;
270
+ var isPositionListItem = (0, _utils.isListNode)($pos.node());
271
+ var listItemPosition = $pos;
272
+ if (!isPositionListItem) {
273
+ var listItem = (0, _find.findFirstParentListItemNode)($pos);
274
+ if (!listItem) {
275
+ return null;
276
+ }
277
+ return doc.resolve(listItem.pos);
278
+ }
279
+ var resolved = doc.resolve(listItemPosition.pos);
280
+ var foundPosition = _state.Selection.findFrom(resolved, -1);
281
+ if (!foundPosition) {
282
+ return null;
283
+ }
284
+ var parentListItemNode = (0, _find.findFirstParentListItemNode)(foundPosition.$from);
285
+ if (!parentListItemNode) {
286
+ return null;
287
+ }
288
+ return doc.resolve(parentListItemNode.pos);
289
+ };
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.wrapInList = wrapInList;
7
+ exports.wrapInListAndJoin = wrapInListAndJoin;
8
+ var _selection = require("@atlaskit/editor-common/selection");
9
+ var _utils = require("@atlaskit/editor-common/utils");
10
+ var _model = require("@atlaskit/editor-prosemirror/model");
11
+ var _transform = require("@atlaskit/editor-prosemirror/transform");
12
+ var _selection2 = require("../utils/selection");
13
+ /**
14
+ * Wraps the selection in a list with the given type. If this results in
15
+ * two adjacent lists of the same type, those will be joined together.
16
+ */
17
+ function wrapInListAndJoin(nodeType, tr) {
18
+ wrapInList(nodeType)(tr);
19
+ (0, _utils.autoJoinTr)(tr, function (before, after) {
20
+ return before.type === after.type && before.type === nodeType;
21
+ });
22
+ }
23
+
24
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
+
26
+ /**
27
+ * Wraps the selection in a list with the given type and attributes.
28
+ *
29
+ * Adapted from https://github.com/ProseMirror/prosemirror-schema-list/blob/master/src/schema-list.js#L64-L89
30
+ */
31
+ function wrapInList(listType, attrs) {
32
+ return function (tr) {
33
+ var _tr$selection = tr.selection,
34
+ $from = _tr$selection.$from,
35
+ $to = _tr$selection.$to;
36
+ var range;
37
+ if (tr.selection instanceof _selection.GapCursorSelection && $from.nodeAfter && (0, _selection2.isWrappingPossible)(listType, tr.selection)) {
38
+ var nodeSize = $from.nodeAfter.nodeSize || 1;
39
+ range = $from.blockRange($from.doc.resolve($from.pos + nodeSize));
40
+ } else {
41
+ range = $from.blockRange($to);
42
+ }
43
+ var doJoin = false;
44
+ var outerRange = range;
45
+ if (!range) {
46
+ return false;
47
+ }
48
+ // This is at the top of an existing list item
49
+ if (range.depth >= 2 &&
50
+ // @ts-ignore - missing type for compatibleContent
51
+ $from.node(range.depth - 1).type.compatibleContent(listType) && range.startIndex === 0) {
52
+ // Don't do anything if this is the top of the list
53
+ if ($from.index(range.depth - 1) === 0) {
54
+ return false;
55
+ }
56
+ var $insert = tr.doc.resolve(range.start - 2);
57
+ outerRange = new _model.NodeRange($insert, $insert, range.depth);
58
+ if (range.endIndex < range.parent.childCount) {
59
+ range = new _model.NodeRange($from, tr.doc.resolve($to.end(range.depth)), range.depth);
60
+ }
61
+ doJoin = true;
62
+ }
63
+ var wrap = (0, _transform.findWrapping)(outerRange, listType, attrs, range);
64
+ if (!wrap) {
65
+ return false;
66
+ }
67
+ tr = doWrapInList(tr, range, wrap, doJoin, listType);
68
+ return true;
69
+ };
70
+ }
71
+
72
+ /**
73
+ * Internal function used by wrapInList
74
+ *
75
+ * Adapted from https://github.com/ProseMirror/prosemirror-schema-list/blob/master/src/schema-list.js#L91-L112
76
+ */
77
+ function doWrapInList(tr, range, wrappers, joinBefore, listType) {
78
+ var content = _model.Fragment.empty;
79
+ for (var i = wrappers.length - 1; i >= 0; i--) {
80
+ content = _model.Fragment.from(wrappers[i].type.create(wrappers[i].attrs, content));
81
+ }
82
+ tr.step(new _transform.ReplaceAroundStep(range.start - (joinBefore ? 2 : 0), range.end, range.start, range.end, new _model.Slice(content, 0, 0), wrappers.length, true));
83
+ var found = 0;
84
+ for (var _i = 0; _i < wrappers.length; _i++) {
85
+ if (wrappers[_i].type === listType) {
86
+ found = _i + 1;
87
+ }
88
+ }
89
+ var splitDepth = wrappers.length - found;
90
+ var splitPos = range.start + wrappers.length - (joinBefore ? 2 : 0);
91
+ var parent = range.parent;
92
+ for (var _i2 = range.startIndex, e = range.endIndex, first = true; _i2 < e; _i2++, first = false) {
93
+ if (!first && (0, _transform.canSplit)(tr.doc, splitPos, splitDepth)) {
94
+ tr.split(splitPos, splitDepth);
95
+ splitPos += 2 * splitDepth;
96
+ }
97
+ splitPos += parent.child(_i2).nodeSize;
98
+ }
99
+ return tr;
100
+ }
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.indentList = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _analytics = require("@atlaskit/editor-common/analytics");
10
+ var _lists = require("@atlaskit/editor-common/lists");
11
+ var _preset = require("@atlaskit/editor-common/preset");
12
+ var _utils = require("@atlaskit/editor-common/utils");
13
+ var _history = require("@atlaskit/editor-prosemirror/history");
14
+ var _indentListItemsSelected = require("../actions/indent-list-items-selected");
15
+ var _types = require("../types");
16
+ var _find = require("../utils/find");
17
+ var _selection = require("../utils/selection");
18
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
19
+ 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; }
20
+ var indentList = function indentList(editorAnalyticsAPI) {
21
+ return function () {
22
+ var inputMethod = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _analytics.INPUT_METHOD.KEYBOARD;
23
+ return function (_ref) {
24
+ var tr = _ref.tr;
25
+ var $from = tr.selection.$from;
26
+
27
+ // don't indent if selection is not inside a list
28
+ if (!(0, _selection.isInsideListItem)(tr)) {
29
+ return null;
30
+ }
31
+
32
+ // Save the history, so it could undo/revert to the same state before the indent, see https://product-fabric.atlassian.net/browse/ED-14753
33
+ (0, _history.closeHistory)(tr);
34
+ var firstListItemSelectedAttributes = (0, _lists.getListItemAttributes)($from);
35
+ var parentListNode = (0, _find.findFirstParentListNode)($from);
36
+ if (!parentListNode || firstListItemSelectedAttributes && firstListItemSelectedAttributes.indentLevel === 0 && firstListItemSelectedAttributes.itemIndex === 0) {
37
+ if ((0, _selection.isInsideTableCell)(tr)) {
38
+ // dont consume tab, as table-keymap should move cursor to next cell
39
+ return null;
40
+ } else {
41
+ // 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
42
+ return new _preset.PassiveTransaction();
43
+ }
44
+ }
45
+ var currentListNode = parentListNode.node;
46
+ var actionSubjectId = (0, _utils.isBulletList)(currentListNode) ? _analytics.ACTION_SUBJECT_ID.FORMAT_LIST_BULLET : _analytics.ACTION_SUBJECT_ID.FORMAT_LIST_NUMBER;
47
+ (0, _indentListItemsSelected.indentListItemsSelected)(tr);
48
+ var maximimunNestedLevelReached = !(0, _lists.hasValidListIndentationLevel)({
49
+ tr: tr,
50
+ maxIndentation: _types.MAX_NESTED_LIST_INDENTATION
51
+ });
52
+ if (maximimunNestedLevelReached || !tr.docChanged) {
53
+ // 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
54
+ return new _preset.PassiveTransaction();
55
+ }
56
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
57
+ action: _analytics.ACTION.INDENTED,
58
+ actionSubject: _analytics.ACTION_SUBJECT.LIST,
59
+ actionSubjectId: actionSubjectId,
60
+ eventType: _analytics.EVENT_TYPE.TRACK,
61
+ attributes: _objectSpread(_objectSpread({}, (0, _lists.getCommonListAnalyticsAttributes)(tr)), {}, {
62
+ inputMethod: inputMethod
63
+ })
64
+ })(tr);
65
+ return tr;
66
+ };
67
+ };
68
+ };
69
+ exports.indentList = indentList;