@atlaskit/editor-plugin-list 0.2.0 → 1.0.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 +10 -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 +291 -0
  16. package/dist/cjs/actions/wrap-and-join-lists.js +100 -0
  17. package/dist/cjs/commands/indent-list.js +71 -0
  18. package/dist/cjs/commands/index.js +350 -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 +70 -0
  23. package/dist/cjs/index.js +8 -1
  24. package/dist/cjs/messages.js +37 -0
  25. package/dist/cjs/plugin.js +133 -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 +295 -0
  51. package/dist/es2019/actions/wrap-and-join-lists.js +93 -0
  52. package/dist/es2019/commands/indent-list.js +62 -0
  53. package/dist/es2019/commands/index.js +326 -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 +121 -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 +283 -0
  86. package/dist/esm/actions/wrap-and-join-lists.js +94 -0
  87. package/dist/esm/commands/indent-list.js +63 -0
  88. package/dist/esm/commands/index.js +324 -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 +62 -0
  93. package/dist/esm/index.js +1 -1
  94. package/dist/esm/messages.js +29 -0
  95. package/dist/esm/plugin.js +126 -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 +16 -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 +4 -6
  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 +16 -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 +4 -6
  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 +6 -2
  181. package/tmp/api-report-tmp.d.ts +4 -1
@@ -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,291 @@
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, state, 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
+ state: state,
57
+ featureFlags: featureFlags
58
+ });
59
+ hasNormalizedToPositionLiftedOut = hasNormalizedToPositionLiftedOut || oldTo >= range.from && oldTo < range.to;
60
+ hasNormalizedFromPositionLiftedOut = hasNormalizedFromPositionLiftedOut || oldFrom >= range.from && oldFrom < range.to;
61
+ }
62
+ });
63
+ var hasCommonListMoved = commonList.start !== tr.mapping.map(commonList.start);
64
+ var nextSelection = calculateNewSelection({
65
+ originalSelection: originalSelection,
66
+ normalizedSelection: normalizedSelection,
67
+ tr: tr,
68
+ hasCommonListMoved: hasCommonListMoved,
69
+ hasNormalizedToPositionLiftedOut: hasNormalizedToPositionLiftedOut,
70
+ hasNormalizedFromPositionLiftedOut: hasNormalizedFromPositionLiftedOut
71
+ });
72
+ tr.setSelection(nextSelection);
73
+ (0, _lists.joinSiblingLists)({
74
+ tr: tr,
75
+ direction: _lists.JoinDirection.RIGHT
76
+ });
77
+ };
78
+ exports.outdentListItemsSelected = outdentListItemsSelected;
79
+ var calculateNewSelection = function calculateNewSelection(_ref) {
80
+ var tr = _ref.tr,
81
+ originalSelection = _ref.originalSelection,
82
+ normalizedSelection = _ref.normalizedSelection,
83
+ hasCommonListMoved = _ref.hasCommonListMoved,
84
+ hasNormalizedToPositionLiftedOut = _ref.hasNormalizedToPositionLiftedOut,
85
+ hasNormalizedFromPositionLiftedOut = _ref.hasNormalizedFromPositionLiftedOut;
86
+ var $from = normalizedSelection.$from,
87
+ $to = normalizedSelection.$to;
88
+ var isCursorSelection = normalizedSelection.empty;
89
+ var from = tr.mapping.map($from.pos);
90
+ var to = tr.mapping.map($to.pos);
91
+ var LIST_STRUCTURE_CHANGED_OFFSET = 2;
92
+ var isToFromSameListItem = $from.sameParent($to);
93
+ if (hasNormalizedFromPositionLiftedOut) {
94
+ var fromMapped = isToFromSameListItem ? $from.pos : from;
95
+ from = hasNormalizedFromPositionLiftedOut ? $from.pos : fromMapped;
96
+ from = hasCommonListMoved ? from - LIST_STRUCTURE_CHANGED_OFFSET : from;
97
+ from = Math.max(from, 0);
98
+ }
99
+ if (hasNormalizedToPositionLiftedOut) {
100
+ var toMapped = isToFromSameListItem ? $to.pos : to;
101
+ to = hasNormalizedToPositionLiftedOut ? $to.pos : toMapped;
102
+ to = hasCommonListMoved ? to - LIST_STRUCTURE_CHANGED_OFFSET : to;
103
+ to = Math.min(to, tr.doc.nodeSize - 2);
104
+ }
105
+ if (normalizedSelection instanceof _selection.GapCursorSelection) {
106
+ var nextSelectionFrom = tr.doc.resolve(from);
107
+ return new _selection.GapCursorSelection(nextSelectionFrom, normalizedSelection.side);
108
+ }
109
+ if (originalSelection instanceof _state.NodeSelection) {
110
+ return _state.NodeSelection.create(tr.doc, from);
111
+ }
112
+ if (isCursorSelection) {
113
+ return _state.TextSelection.between(tr.doc.resolve(to), tr.doc.resolve(to), -1);
114
+ }
115
+ return _state.TextSelection.between(tr.doc.resolve(from), tr.doc.resolve(to), -1);
116
+ };
117
+ var splitRangeSelection = function splitRangeSelection(selection) {
118
+ var commonListRange = (0, _selection2.createListNodeRange)({
119
+ selection: selection
120
+ });
121
+ if (!commonListRange) {
122
+ return [];
123
+ }
124
+ var $from = selection.$from,
125
+ $to = selection.$to;
126
+ if ($from.pos === $to.pos && $from.sameParent($to)) {
127
+ return [{
128
+ from: commonListRange.start,
129
+ to: commonListRange.end,
130
+ depth: commonListRange.depth
131
+ }];
132
+ }
133
+ var lastListItem = findPreviousListItemSibling($from);
134
+ if (!lastListItem) {
135
+ return [];
136
+ }
137
+ var nodeRanges = [];
138
+ var doc = $from.doc;
139
+ var previousListItem = findPreviousListItemSibling($to);
140
+ while (previousListItem && previousListItem.pos >= lastListItem.pos && previousListItem.pos >= commonListRange.start) {
141
+ var node = doc.nodeAt(previousListItem.pos);
142
+ if (!node || !(0, _utils.isListItemNode)(node)) {
143
+ return [];
144
+ }
145
+ var offset = 0;
146
+ if (node && node.lastChild && (0, _utils.isListNode)(node.lastChild)) {
147
+ offset = node.lastChild.nodeSize;
148
+ }
149
+ var start = previousListItem.pos + 1;
150
+ nodeRanges.push({
151
+ from: start,
152
+ to: doc.resolve(start).end() - offset,
153
+ depth: previousListItem.depth
154
+ });
155
+ previousListItem = findPreviousListItemSibling(previousListItem);
156
+ }
157
+ return nodeRanges;
158
+ };
159
+ var outdentRangeToParentList = function outdentRangeToParentList(_ref2) {
160
+ var tr = _ref2.tr,
161
+ range = _ref2.range;
162
+ var end = range.end;
163
+ var endOfList = range.$to.end(range.depth);
164
+ var listItem = tr.doc.type.schema.nodes.listItem;
165
+ if (end < endOfList) {
166
+ var slice = new _model.Slice(_model.Fragment.from(listItem.create(null, range.parent.copy())), 1, 0);
167
+ var step = new _transform.ReplaceAroundStep(end - 1, endOfList, end, endOfList, slice, 1, true);
168
+ tr.step(step);
169
+ range = new _model.NodeRange(tr.doc.resolve(range.$from.pos), tr.doc.resolve(endOfList), range.depth);
170
+ }
171
+ var target = (0, _transform.liftTarget)(range);
172
+ if (target) {
173
+ tr.lift(range, target);
174
+ }
175
+ };
176
+ var extractListItemsRangeFromList = function extractListItemsRangeFromList(_ref3) {
177
+ var tr = _ref3.tr,
178
+ range = _ref3.range,
179
+ state = _ref3.state,
180
+ featureFlags = _ref3.featureFlags;
181
+ var list = range.parent;
182
+ var $start = tr.doc.resolve(range.start);
183
+ var listStart = $start.start(range.depth);
184
+ var listEnd = $start.end(range.depth);
185
+ var isAtTop = listStart === range.start;
186
+ var isAtBottom = listEnd === range.end;
187
+ var isTheEntireList = isAtTop && isAtBottom;
188
+ var listItemContent = isAtTop ? _model.Fragment.empty : _model.Fragment.from(list.copy(_model.Fragment.empty));
189
+ for (var i = range.startIndex; i < range.endIndex; i++) {
190
+ listItemContent = listItemContent.append(list.child(i).content);
191
+ }
192
+ if (isAtTop) {
193
+ for (var _i = 0; _i < listItemContent.childCount; _i++) {
194
+ var child = listItemContent.child(_i);
195
+ if (child && (0, _utils.isListNode)(child) && child.type !== list.type) {
196
+ var newNestedList = list.type.create(null, child.content);
197
+ listItemContent = listItemContent.replaceChild(_i, newNestedList);
198
+ }
199
+ }
200
+ }
201
+ var nextList = list.copy(_model.Fragment.empty);
202
+ var nextListStartNumber;
203
+ if (featureFlags !== null && featureFlags !== void 0 && featureFlags.restartNumberedLists) {
204
+ // if splitting a numbered list, keep the splitted item
205
+ // counter as the start of the next (second half) list (instead
206
+ // of reverting back to 1 as a starting number)
207
+ var order = (0, _utils.getOrderFromOrderedListNode)(list);
208
+ if (list.type.name === 'orderedList') {
209
+ nextListStartNumber = range.endIndex - 1 + order;
210
+ // @ts-ignore - [unblock prosemirror bump] assigning to readonly attrs
211
+ nextList.attrs = _objectSpread(_objectSpread({}, nextList.attrs), {}, {
212
+ order: nextListStartNumber
213
+ });
214
+ var _getRestartListsAttri = (0, _analytics2.getRestartListsAttributes)(tr),
215
+ splitListStartNumber = _getRestartListsAttri.splitListStartNumber;
216
+ if (typeof splitListStartNumber !== 'number') {
217
+ (0, _analytics2.storeRestartListsAttributes)(tr, {
218
+ splitListStartNumber: nextListStartNumber
219
+ });
220
+ }
221
+ }
222
+ }
223
+ var nextListFragment = listItemContent.append(_model.Fragment.from(nextList));
224
+ if (featureFlags !== null && featureFlags !== void 0 && featureFlags.restartNumberedLists) {
225
+ // if the split list with nextListStartNumber is below another list
226
+ // with order (e.g due to multi-level indent items being lifted), track the
227
+ // list above's order instead, as it will be the split list's order after sibling joins
228
+ nextListFragment.forEach(function (node, _offset, index) {
229
+ var _node$attrs;
230
+ if (node.type.name === 'orderedList' && ((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.order) === nextListStartNumber) {
231
+ var _prev$attrs;
232
+ var prev = nextListFragment.child(index - 1);
233
+ if ((prev === null || prev === void 0 ? void 0 : (_prev$attrs = prev.attrs) === null || _prev$attrs === void 0 ? void 0 : _prev$attrs.order) >= 0) {
234
+ var _prev$attrs2;
235
+ (0, _analytics2.storeRestartListsAttributes)(tr, {
236
+ splitListStartNumber: prev === null || prev === void 0 ? void 0 : (_prev$attrs2 = prev.attrs) === null || _prev$attrs2 === void 0 ? void 0 : _prev$attrs2.order
237
+ });
238
+ }
239
+ }
240
+ });
241
+ }
242
+ if (isTheEntireList) {
243
+ var slice = new _model.Slice(listItemContent, 0, 0);
244
+ var step = new _transform.ReplaceStep($start.pos - 1, range.end + 1, slice, false);
245
+ if (featureFlags !== null && featureFlags !== void 0 && featureFlags.restartNumberedLists) {
246
+ (0, _analytics2.storeRestartListsAttributes)(tr, {
247
+ outdentScenario: undefined
248
+ });
249
+ }
250
+ tr.step(step);
251
+ } else if (isAtTop) {
252
+ var _slice = new _model.Slice(nextListFragment, 0, 1);
253
+ var _step = new _transform.ReplaceStep($start.pos - 1, range.end, _slice, false);
254
+ tr.step(_step);
255
+ } else if (isAtBottom) {
256
+ var _slice2 = new _model.Slice(listItemContent, 1, 0);
257
+ var _step2 = new _transform.ReplaceStep($start.pos, listEnd + 1, _slice2, false);
258
+ tr.step(_step2);
259
+ } else {
260
+ if (featureFlags !== null && featureFlags !== void 0 && featureFlags.restartNumberedLists) {
261
+ (0, _analytics2.storeRestartListsAttributes)(tr, {
262
+ outdentScenario: _analytics.OUTDENT_SCENARIOS.SPLIT_LIST
263
+ });
264
+ }
265
+ var _slice3 = new _model.Slice(nextListFragment, 1, 1);
266
+ var _step3 = new _transform.ReplaceAroundStep($start.pos, listEnd, range.end, listEnd, _slice3, _slice3.size, false);
267
+ tr.step(_step3);
268
+ }
269
+ };
270
+ var findPreviousListItemSibling = function findPreviousListItemSibling($pos) {
271
+ var doc = $pos.doc;
272
+ var isPositionListItem = (0, _utils.isListNode)($pos.node());
273
+ var listItemPosition = $pos;
274
+ if (!isPositionListItem) {
275
+ var listItem = (0, _find.findFirstParentListItemNode)($pos);
276
+ if (!listItem) {
277
+ return null;
278
+ }
279
+ return doc.resolve(listItem.pos);
280
+ }
281
+ var resolved = doc.resolve(listItemPosition.pos);
282
+ var foundPosition = _state.Selection.findFrom(resolved, -1);
283
+ if (!foundPosition) {
284
+ return null;
285
+ }
286
+ var parentListItemNode = (0, _find.findFirstParentListItemNode)(foundPosition.$from);
287
+ if (!parentListItemNode) {
288
+ return null;
289
+ }
290
+ return doc.resolve(parentListItemNode.pos);
291
+ };
@@ -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,71 @@
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 _utils = require("@atlaskit/editor-common/utils");
12
+ var _history = require("@atlaskit/editor-prosemirror/history");
13
+ var _indentListItemsSelected = require("../actions/indent-list-items-selected");
14
+ var _types = require("../types");
15
+ var _find = require("../utils/find");
16
+ var _selection = require("../utils/selection");
17
+ 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; }
18
+ 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; }
19
+ var indentList = function indentList(editorAnalyticsAPI) {
20
+ return function () {
21
+ var inputMethod = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _analytics.INPUT_METHOD.KEYBOARD;
22
+ return function (state, dispatch) {
23
+ var tr = state.tr,
24
+ $from = state.selection.$from;
25
+
26
+ // don't indent if selection is not inside a list
27
+ if (!(0, _selection.isInsideListItem)(state)) {
28
+ return false;
29
+ }
30
+
31
+ // Save the history, so it could undo/revert to the same state before the indent, see https://product-fabric.atlassian.net/browse/ED-14753
32
+ (0, _history.closeHistory)(tr);
33
+ var firstListItemSelectedAttributes = (0, _lists.getListItemAttributes)($from);
34
+ var parentListNode = (0, _find.findFirstParentListNode)($from);
35
+ if (!parentListNode || firstListItemSelectedAttributes && firstListItemSelectedAttributes.indentLevel === 0 && firstListItemSelectedAttributes.itemIndex === 0) {
36
+ if ((0, _selection.isInsideTableCell)(state)) {
37
+ // dont consume tab, as table-keymap should move cursor to next cell
38
+ return false;
39
+ } else {
40
+ // 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
41
+ return true;
42
+ }
43
+ }
44
+ var currentListNode = parentListNode.node;
45
+ var actionSubjectId = (0, _utils.isBulletList)(currentListNode) ? _analytics.ACTION_SUBJECT_ID.FORMAT_LIST_BULLET : _analytics.ACTION_SUBJECT_ID.FORMAT_LIST_NUMBER;
46
+ (0, _indentListItemsSelected.indentListItemsSelected)(tr);
47
+ var maximimunNestedLevelReached = !(0, _lists.hasValidListIndentationLevel)({
48
+ tr: tr,
49
+ maxIndentation: _types.MAX_NESTED_LIST_INDENTATION
50
+ });
51
+ if (maximimunNestedLevelReached || !tr.docChanged) {
52
+ // 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
53
+ return true;
54
+ }
55
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
56
+ action: _analytics.ACTION.INDENTED,
57
+ actionSubject: _analytics.ACTION_SUBJECT.LIST,
58
+ actionSubjectId: actionSubjectId,
59
+ eventType: _analytics.EVENT_TYPE.TRACK,
60
+ attributes: _objectSpread(_objectSpread({}, (0, _lists.getCommonListAnalyticsAttributes)(state)), {}, {
61
+ inputMethod: inputMethod
62
+ })
63
+ })(tr);
64
+ if (dispatch) {
65
+ dispatch(tr);
66
+ }
67
+ return true;
68
+ };
69
+ };
70
+ };
71
+ exports.indentList = indentList;