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