@atlaskit/editor-core 187.17.6 → 187.18.1

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/CHANGELOG.md +18 -0
  2. package/dist/cjs/labs/next/presets/default.js +2 -2
  3. package/dist/cjs/plugins/annotation/toolbar.js +31 -8
  4. package/dist/cjs/plugins/help-dialog/ui/index.js +26 -27
  5. package/dist/cjs/plugins/index.js +0 -7
  6. package/dist/cjs/plugins/list/index.js +5 -5
  7. package/dist/cjs/plugins/list/transforms.js +1 -223
  8. package/dist/cjs/plugins/paste/commands.js +224 -2
  9. package/dist/cjs/plugins/paste/pm-plugins/main.js +3 -3
  10. package/dist/cjs/plugins/toolbar-lists-indentation/ui/Toolbar.js +3 -3
  11. package/dist/cjs/plugins/toolbar-lists-indentation/ui/ToolbarDropdown.js +4 -4
  12. package/dist/cjs/version-wrapper.js +1 -1
  13. package/dist/cjs/version.json +1 -1
  14. package/dist/es2019/labs/next/presets/default.js +1 -1
  15. package/dist/es2019/plugins/annotation/toolbar.js +34 -9
  16. package/dist/es2019/plugins/help-dialog/ui/index.js +1 -2
  17. package/dist/es2019/plugins/index.js +0 -1
  18. package/dist/es2019/plugins/list/index.js +1 -1
  19. package/dist/es2019/plugins/list/transforms.js +2 -210
  20. package/dist/es2019/plugins/paste/commands.js +210 -2
  21. package/dist/es2019/plugins/paste/pm-plugins/main.js +1 -1
  22. package/dist/es2019/plugins/toolbar-lists-indentation/ui/Toolbar.js +1 -1
  23. package/dist/es2019/plugins/toolbar-lists-indentation/ui/ToolbarDropdown.js +1 -1
  24. package/dist/es2019/version-wrapper.js +1 -1
  25. package/dist/es2019/version.json +1 -1
  26. package/dist/esm/labs/next/presets/default.js +1 -1
  27. package/dist/esm/plugins/annotation/toolbar.js +30 -7
  28. package/dist/esm/plugins/help-dialog/ui/index.js +1 -2
  29. package/dist/esm/plugins/index.js +0 -1
  30. package/dist/esm/plugins/list/index.js +1 -1
  31. package/dist/esm/plugins/list/transforms.js +2 -219
  32. package/dist/esm/plugins/paste/commands.js +218 -1
  33. package/dist/esm/plugins/paste/pm-plugins/main.js +1 -1
  34. package/dist/esm/plugins/toolbar-lists-indentation/ui/Toolbar.js +1 -1
  35. package/dist/esm/plugins/toolbar-lists-indentation/ui/ToolbarDropdown.js +1 -1
  36. package/dist/esm/version-wrapper.js +1 -1
  37. package/dist/esm/version.json +1 -1
  38. package/dist/types/index.d.ts +0 -5
  39. package/dist/types/labs/next/presets/default.d.ts +28 -28
  40. package/dist/types/plugins/annotation/types.d.ts +9 -3
  41. package/dist/types/plugins/index.d.ts +0 -1
  42. package/dist/types/plugins/list/pm-plugins/input-rules/wrapping-join-rule.d.ts +1 -2
  43. package/dist/types/plugins/list/transforms.d.ts +0 -13
  44. package/dist/types/plugins/paste/commands.d.ts +14 -0
  45. package/dist/types/plugins/paste/index.d.ts +2 -0
  46. package/dist/types-ts4.5/index.d.ts +0 -5
  47. package/dist/types-ts4.5/labs/next/presets/default.d.ts +28 -28
  48. package/dist/types-ts4.5/plugins/annotation/types.d.ts +9 -3
  49. package/dist/types-ts4.5/plugins/index.d.ts +0 -1
  50. package/dist/types-ts4.5/plugins/list/pm-plugins/input-rules/wrapping-join-rule.d.ts +1 -2
  51. package/dist/types-ts4.5/plugins/list/transforms.d.ts +0 -13
  52. package/dist/types-ts4.5/plugins/paste/commands.d.ts +14 -0
  53. package/dist/types-ts4.5/plugins/paste/index.d.ts +2 -0
  54. package/package.json +3 -2
  55. package/report.api.md +1 -24
  56. package/tmp/api-report-tmp.d.ts +1 -21
  57. package/dist/cjs/plugins/text-formatting/actions.js +0 -188
  58. package/dist/cjs/plugins/text-formatting/commands/clear-formatting.js +0 -111
  59. package/dist/cjs/plugins/text-formatting/commands/text-formatting.js +0 -143
  60. package/dist/cjs/plugins/text-formatting/commands/transform-to-code.js +0 -68
  61. package/dist/cjs/plugins/text-formatting/index.js +0 -136
  62. package/dist/cjs/plugins/text-formatting/pm-plugins/clear-formatting-keymap.js +0 -21
  63. package/dist/cjs/plugins/text-formatting/pm-plugins/clear-formatting.js +0 -36
  64. package/dist/cjs/plugins/text-formatting/pm-plugins/cursor.js +0 -55
  65. package/dist/cjs/plugins/text-formatting/pm-plugins/input-rule.js +0 -276
  66. package/dist/cjs/plugins/text-formatting/pm-plugins/keymap.js +0 -52
  67. package/dist/cjs/plugins/text-formatting/pm-plugins/main.js +0 -113
  68. package/dist/cjs/plugins/text-formatting/pm-plugins/plugin-key.js +0 -9
  69. package/dist/cjs/plugins/text-formatting/pm-plugins/smart-input-rule.js +0 -176
  70. package/dist/cjs/plugins/text-formatting/ui/Toolbar/constants.js +0 -19
  71. package/dist/cjs/plugins/text-formatting/ui/Toolbar/dropdown-menu.js +0 -86
  72. package/dist/cjs/plugins/text-formatting/ui/Toolbar/hooks/clear-formatting-icon.js +0 -53
  73. package/dist/cjs/plugins/text-formatting/ui/Toolbar/hooks/formatting-icons.js +0 -225
  74. package/dist/cjs/plugins/text-formatting/ui/Toolbar/hooks/menu-state.js +0 -23
  75. package/dist/cjs/plugins/text-formatting/ui/Toolbar/hooks/responsive-toolbar-buttons.js +0 -60
  76. package/dist/cjs/plugins/text-formatting/ui/Toolbar/index.js +0 -201
  77. package/dist/cjs/plugins/text-formatting/ui/Toolbar/more-button.js +0 -40
  78. package/dist/cjs/plugins/text-formatting/ui/Toolbar/single-toolbar-buttons.js +0 -46
  79. package/dist/cjs/plugins/text-formatting/ui/Toolbar/types.js +0 -17
  80. package/dist/cjs/plugins/text-formatting/utils/cell-selection.js +0 -12
  81. package/dist/cjs/plugins/text-formatting/utils.js +0 -86
  82. package/dist/es2019/plugins/text-formatting/actions.js +0 -161
  83. package/dist/es2019/plugins/text-formatting/commands/clear-formatting.js +0 -105
  84. package/dist/es2019/plugins/text-formatting/commands/text-formatting.js +0 -144
  85. package/dist/es2019/plugins/text-formatting/commands/transform-to-code.js +0 -71
  86. package/dist/es2019/plugins/text-formatting/index.js +0 -127
  87. package/dist/es2019/plugins/text-formatting/pm-plugins/clear-formatting-keymap.js +0 -10
  88. package/dist/es2019/plugins/text-formatting/pm-plugins/clear-formatting.js +0 -26
  89. package/dist/es2019/plugins/text-formatting/pm-plugins/cursor.js +0 -52
  90. package/dist/es2019/plugins/text-formatting/pm-plugins/input-rule.js +0 -244
  91. package/dist/es2019/plugins/text-formatting/pm-plugins/keymap.js +0 -43
  92. package/dist/es2019/plugins/text-formatting/pm-plugins/main.js +0 -109
  93. package/dist/es2019/plugins/text-formatting/pm-plugins/plugin-key.js +0 -2
  94. package/dist/es2019/plugins/text-formatting/pm-plugins/smart-input-rule.js +0 -155
  95. package/dist/es2019/plugins/text-formatting/ui/Toolbar/constants.js +0 -20
  96. package/dist/es2019/plugins/text-formatting/ui/Toolbar/dropdown-menu.js +0 -66
  97. package/dist/es2019/plugins/text-formatting/ui/Toolbar/hooks/clear-formatting-icon.js +0 -42
  98. package/dist/es2019/plugins/text-formatting/ui/Toolbar/hooks/formatting-icons.js +0 -210
  99. package/dist/es2019/plugins/text-formatting/ui/Toolbar/hooks/menu-state.js +0 -11
  100. package/dist/es2019/plugins/text-formatting/ui/Toolbar/hooks/responsive-toolbar-buttons.js +0 -48
  101. package/dist/es2019/plugins/text-formatting/ui/Toolbar/index.js +0 -168
  102. package/dist/es2019/plugins/text-formatting/ui/Toolbar/more-button.js +0 -32
  103. package/dist/es2019/plugins/text-formatting/ui/Toolbar/single-toolbar-buttons.js +0 -36
  104. package/dist/es2019/plugins/text-formatting/ui/Toolbar/types.js +0 -10
  105. package/dist/es2019/plugins/text-formatting/utils/cell-selection.js +0 -5
  106. package/dist/es2019/plugins/text-formatting/utils.js +0 -74
  107. package/dist/esm/plugins/text-formatting/actions.js +0 -168
  108. package/dist/esm/plugins/text-formatting/commands/clear-formatting.js +0 -101
  109. package/dist/esm/plugins/text-formatting/commands/text-formatting.js +0 -134
  110. package/dist/esm/plugins/text-formatting/commands/transform-to-code.js +0 -61
  111. package/dist/esm/plugins/text-formatting/index.js +0 -128
  112. package/dist/esm/plugins/text-formatting/pm-plugins/clear-formatting-keymap.js +0 -10
  113. package/dist/esm/plugins/text-formatting/pm-plugins/clear-formatting.js +0 -28
  114. package/dist/esm/plugins/text-formatting/pm-plugins/cursor.js +0 -48
  115. package/dist/esm/plugins/text-formatting/pm-plugins/input-rule.js +0 -259
  116. package/dist/esm/plugins/text-formatting/pm-plugins/keymap.js +0 -43
  117. package/dist/esm/plugins/text-formatting/pm-plugins/main.js +0 -98
  118. package/dist/esm/plugins/text-formatting/pm-plugins/plugin-key.js +0 -2
  119. package/dist/esm/plugins/text-formatting/pm-plugins/smart-input-rule.js +0 -169
  120. package/dist/esm/plugins/text-formatting/ui/Toolbar/constants.js +0 -8
  121. package/dist/esm/plugins/text-formatting/ui/Toolbar/dropdown-menu.js +0 -75
  122. package/dist/esm/plugins/text-formatting/ui/Toolbar/hooks/clear-formatting-icon.js +0 -45
  123. package/dist/esm/plugins/text-formatting/ui/Toolbar/hooks/formatting-icons.js +0 -213
  124. package/dist/esm/plugins/text-formatting/ui/Toolbar/hooks/menu-state.js +0 -15
  125. package/dist/esm/plugins/text-formatting/ui/Toolbar/hooks/responsive-toolbar-buttons.js +0 -50
  126. package/dist/esm/plugins/text-formatting/ui/Toolbar/index.js +0 -191
  127. package/dist/esm/plugins/text-formatting/ui/Toolbar/more-button.js +0 -31
  128. package/dist/esm/plugins/text-formatting/ui/Toolbar/single-toolbar-buttons.js +0 -35
  129. package/dist/esm/plugins/text-formatting/ui/Toolbar/types.js +0 -10
  130. package/dist/esm/plugins/text-formatting/utils/cell-selection.js +0 -5
  131. package/dist/esm/plugins/text-formatting/utils.js +0 -75
  132. package/dist/types/plugins/text-formatting/actions.d.ts +0 -22
  133. package/dist/types/plugins/text-formatting/commands/clear-formatting.d.ts +0 -6
  134. package/dist/types/plugins/text-formatting/commands/text-formatting.d.ts +0 -5
  135. package/dist/types/plugins/text-formatting/commands/transform-to-code.d.ts +0 -2
  136. package/dist/types/plugins/text-formatting/index.d.ts +0 -17
  137. package/dist/types/plugins/text-formatting/pm-plugins/clear-formatting-keymap.d.ts +0 -4
  138. package/dist/types/plugins/text-formatting/pm-plugins/clear-formatting.d.ts +0 -8
  139. package/dist/types/plugins/text-formatting/pm-plugins/cursor.d.ts +0 -3
  140. package/dist/types/plugins/text-formatting/pm-plugins/input-rule.d.ts +0 -24
  141. package/dist/types/plugins/text-formatting/pm-plugins/keymap.d.ts +0 -4
  142. package/dist/types/plugins/text-formatting/pm-plugins/main.d.ts +0 -7
  143. package/dist/types/plugins/text-formatting/pm-plugins/plugin-key.d.ts +0 -3
  144. package/dist/types/plugins/text-formatting/pm-plugins/smart-input-rule.d.ts +0 -3
  145. package/dist/types/plugins/text-formatting/ui/Toolbar/constants.d.ts +0 -6
  146. package/dist/types/plugins/text-formatting/ui/Toolbar/dropdown-menu.d.ts +0 -15
  147. package/dist/types/plugins/text-formatting/ui/Toolbar/hooks/clear-formatting-icon.d.ts +0 -7
  148. package/dist/types/plugins/text-formatting/ui/Toolbar/hooks/formatting-icons.d.ts +0 -14
  149. package/dist/types/plugins/text-formatting/ui/Toolbar/hooks/menu-state.d.ts +0 -1
  150. package/dist/types/plugins/text-formatting/ui/Toolbar/hooks/responsive-toolbar-buttons.d.ts +0 -20
  151. package/dist/types/plugins/text-formatting/ui/Toolbar/index.d.ts +0 -26
  152. package/dist/types/plugins/text-formatting/ui/Toolbar/more-button.d.ts +0 -13
  153. package/dist/types/plugins/text-formatting/ui/Toolbar/single-toolbar-buttons.d.ts +0 -9
  154. package/dist/types/plugins/text-formatting/ui/Toolbar/types.d.ts +0 -32
  155. package/dist/types/plugins/text-formatting/utils/cell-selection.d.ts +0 -3
  156. package/dist/types/plugins/text-formatting/utils.d.ts +0 -11
  157. package/dist/types-ts4.5/plugins/text-formatting/actions.d.ts +0 -22
  158. package/dist/types-ts4.5/plugins/text-formatting/commands/clear-formatting.d.ts +0 -6
  159. package/dist/types-ts4.5/plugins/text-formatting/commands/text-formatting.d.ts +0 -5
  160. package/dist/types-ts4.5/plugins/text-formatting/commands/transform-to-code.d.ts +0 -2
  161. package/dist/types-ts4.5/plugins/text-formatting/index.d.ts +0 -19
  162. package/dist/types-ts4.5/plugins/text-formatting/pm-plugins/clear-formatting-keymap.d.ts +0 -4
  163. package/dist/types-ts4.5/plugins/text-formatting/pm-plugins/clear-formatting.d.ts +0 -8
  164. package/dist/types-ts4.5/plugins/text-formatting/pm-plugins/cursor.d.ts +0 -3
  165. package/dist/types-ts4.5/plugins/text-formatting/pm-plugins/input-rule.d.ts +0 -24
  166. package/dist/types-ts4.5/plugins/text-formatting/pm-plugins/keymap.d.ts +0 -4
  167. package/dist/types-ts4.5/plugins/text-formatting/pm-plugins/main.d.ts +0 -7
  168. package/dist/types-ts4.5/plugins/text-formatting/pm-plugins/plugin-key.d.ts +0 -3
  169. package/dist/types-ts4.5/plugins/text-formatting/pm-plugins/smart-input-rule.d.ts +0 -3
  170. package/dist/types-ts4.5/plugins/text-formatting/ui/Toolbar/constants.d.ts +0 -6
  171. package/dist/types-ts4.5/plugins/text-formatting/ui/Toolbar/dropdown-menu.d.ts +0 -15
  172. package/dist/types-ts4.5/plugins/text-formatting/ui/Toolbar/hooks/clear-formatting-icon.d.ts +0 -7
  173. package/dist/types-ts4.5/plugins/text-formatting/ui/Toolbar/hooks/formatting-icons.d.ts +0 -14
  174. package/dist/types-ts4.5/plugins/text-formatting/ui/Toolbar/hooks/menu-state.d.ts +0 -5
  175. package/dist/types-ts4.5/plugins/text-formatting/ui/Toolbar/hooks/responsive-toolbar-buttons.d.ts +0 -20
  176. package/dist/types-ts4.5/plugins/text-formatting/ui/Toolbar/index.d.ts +0 -26
  177. package/dist/types-ts4.5/plugins/text-formatting/ui/Toolbar/more-button.d.ts +0 -13
  178. package/dist/types-ts4.5/plugins/text-formatting/ui/Toolbar/single-toolbar-buttons.d.ts +0 -9
  179. package/dist/types-ts4.5/plugins/text-formatting/ui/Toolbar/types.d.ts +0 -32
  180. package/dist/types-ts4.5/plugins/text-formatting/utils/cell-selection.d.ts +0 -3
  181. package/dist/types-ts4.5/plugins/text-formatting/utils.d.ts +0 -11
@@ -1,6 +1,9 @@
1
1
  import { createCommand } from './pm-plugins/plugin-factory';
2
2
  import { PastePluginActionTypes as ActionTypes } from './actions';
3
-
3
+ import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
4
+ import { isListNode, mapChildren, mapSlice } from '@atlaskit/editor-common/utils';
5
+ import { EditorState } from '@atlaskit/editor-prosemirror/state';
6
+ import { autoJoin } from '@atlaskit/editor-prosemirror/commands';
4
7
  /**
5
8
  * Use this to register macro link positions during a paste operation, that you
6
9
  * want to track in a document over time, through any document changes.
@@ -24,4 +27,209 @@ export const stopTrackingPastedMacroPositions = pastedMacroPositionKeys => creat
24
27
  type: ActionTypes.STOP_TRACKING_PASTED_MACRO_POSITIONS,
25
28
  pastedMacroPositionKeys
26
29
  };
27
- });
30
+ });
31
+
32
+ // matchers for text lists
33
+ const bullets = /^\s*[\*\-\u2022](\s+|\s+$)/;
34
+ const numbers = /^\s*\d[\.\)](\s+|$)/;
35
+ const getListType = (node, schema) => {
36
+ if (!node.text) {
37
+ return null;
38
+ }
39
+ const {
40
+ bulletList,
41
+ orderedList
42
+ } = schema.nodes;
43
+ return [{
44
+ node: bulletList,
45
+ matcher: bullets
46
+ }, {
47
+ node: orderedList,
48
+ matcher: numbers
49
+ }].reduce((lastMatch, listType) => {
50
+ if (lastMatch) {
51
+ return lastMatch;
52
+ }
53
+ const match = node.text.match(listType.matcher);
54
+ return match ? [listType.node, match[0].length] : lastMatch;
55
+ }, null);
56
+ };
57
+ const extractListFromParagraph = (node, parent, schema) => {
58
+ const {
59
+ hardBreak,
60
+ bulletList,
61
+ orderedList
62
+ } = schema.nodes;
63
+ const content = mapChildren(node.content, node => node);
64
+ const listTypes = [bulletList, orderedList];
65
+
66
+ // wrap each line into a listItem and a containing list
67
+ const listified = content.map((child, index) => {
68
+ const listMatch = getListType(child, schema);
69
+ const prevChild = index > 0 && content[index - 1];
70
+
71
+ // only extract list when preceded by a hardbreak
72
+ if (prevChild && prevChild.type !== hardBreak) {
73
+ return child;
74
+ }
75
+ if (!listMatch || !child.text) {
76
+ return child;
77
+ }
78
+ const [nodeType, length] = listMatch;
79
+
80
+ // convert to list item
81
+ const newText = child.text.substr(length);
82
+ const listItemNode = schema.nodes.listItem.createAndFill(undefined, schema.nodes.paragraph.createChecked(undefined, newText.length ? schema.text(newText) : undefined));
83
+ if (!listItemNode) {
84
+ return child;
85
+ }
86
+ const newList = nodeType.createChecked(undefined, [listItemNode]);
87
+ // Check whether our new list is valid content in our current structure,
88
+ // otherwise dont convert.
89
+ if (parent && !parent.type.validContent(Fragment.from(newList))) {
90
+ return child;
91
+ }
92
+ return newList;
93
+ }).filter((child, idx, arr) => {
94
+ // remove hardBreaks that have a list node on either side
95
+
96
+ // wasn't hardBreak, leave as-is
97
+ if (child.type !== hardBreak) {
98
+ return child;
99
+ }
100
+ if (idx > 0 && listTypes.indexOf(arr[idx - 1].type) > -1) {
101
+ // list node on the left
102
+ return null;
103
+ }
104
+ if (idx < arr.length - 1 && listTypes.indexOf(arr[idx + 1].type) > -1) {
105
+ // list node on the right
106
+ return null;
107
+ }
108
+ return child;
109
+ });
110
+
111
+ // try to join
112
+ const mockState = EditorState.create({
113
+ schema
114
+ });
115
+ let joinedListsTr;
116
+ const mockDispatch = tr => {
117
+ joinedListsTr = tr;
118
+ };
119
+ autoJoin((state, dispatch) => {
120
+ if (!dispatch) {
121
+ return false;
122
+ }
123
+
124
+ // Return false to prevent replaceWith from wrapping the text node in a paragraph
125
+ // paragraph since that will be done later. If it's done here, it will fail
126
+ // the paragraph.validContent check.
127
+ // Dont return false if there are lists, as they arent validContent for paragraphs
128
+ // and will result in hanging textNodes
129
+ const containsList = listified.some(node => node.type === bulletList || node.type === orderedList);
130
+ if (listified.some(node => node.isText) && !containsList) {
131
+ return false;
132
+ }
133
+ dispatch(state.tr.replaceWith(0, 2, listified));
134
+ return true;
135
+ }, (before, after) => isListNode(before) && isListNode(after))(mockState, mockDispatch);
136
+ const fragment = joinedListsTr ? joinedListsTr.doc.content : Fragment.from(listified);
137
+
138
+ // try to re-wrap fragment in paragraph (which is the original node we unwrapped)
139
+ const {
140
+ paragraph
141
+ } = schema.nodes;
142
+ if (paragraph.validContent(fragment)) {
143
+ return Fragment.from(paragraph.create(node.attrs, fragment, node.marks));
144
+ }
145
+
146
+ // fragment now contains other nodes, get Prosemirror to wrap with ContentMatch later
147
+ return fragment;
148
+ };
149
+
150
+ // above will wrap everything in paragraphs for us
151
+ export const upgradeTextToLists = (slice, schema) => {
152
+ return mapSlice(slice, (node, parent) => {
153
+ if (node.type === schema.nodes.paragraph) {
154
+ return extractListFromParagraph(node, parent, schema);
155
+ }
156
+ return node;
157
+ });
158
+ };
159
+ export const splitParagraphs = (slice, schema) => {
160
+ // exclude Text nodes with a code mark, since we transform those later
161
+ // into a codeblock
162
+ let hasCodeMark = false;
163
+ slice.content.forEach(child => {
164
+ hasCodeMark = hasCodeMark || child.marks.some(mark => mark.type === schema.marks.code);
165
+ });
166
+
167
+ // slice might just be a raw text string
168
+ if (schema.nodes.paragraph.validContent(slice.content) && !hasCodeMark) {
169
+ const replSlice = splitIntoParagraphs({
170
+ fragment: slice.content,
171
+ schema
172
+ });
173
+ return new Slice(replSlice, slice.openStart + 1, slice.openEnd + 1);
174
+ }
175
+ return mapSlice(slice, node => {
176
+ if (node.type === schema.nodes.paragraph) {
177
+ return splitIntoParagraphs({
178
+ fragment: node.content,
179
+ blockMarks: node.marks,
180
+ schema
181
+ });
182
+ }
183
+ return node;
184
+ });
185
+ };
186
+
187
+ /**
188
+ * Walks the slice, creating paragraphs that were previously separated by hardbreaks.
189
+ * Returns the original paragraph node (as a fragment), or a fragment containing multiple nodes.
190
+ */
191
+ export const splitIntoParagraphs = ({
192
+ fragment,
193
+ blockMarks = [],
194
+ schema
195
+ }) => {
196
+ const paragraphs = [];
197
+ let curChildren = [];
198
+ let lastNode = null;
199
+ const {
200
+ hardBreak,
201
+ paragraph
202
+ } = schema.nodes;
203
+ fragment.forEach((node, i) => {
204
+ const isNodeValidContentForParagraph = schema.nodes.paragraph.validContent(Fragment.from(node));
205
+ if (!isNodeValidContentForParagraph) {
206
+ paragraphs.push(node);
207
+ return;
208
+ }
209
+ // ED-14725 Fixed the issue that it make duplicated line
210
+ // when pasting <br /> from google docs.
211
+ if (i === 0 && node.type === hardBreak) {
212
+ paragraphs.push(paragraph.createChecked(undefined, curChildren, [...blockMarks]));
213
+ lastNode = node;
214
+ return;
215
+ } else if (lastNode && lastNode.type === hardBreak && node.type === hardBreak) {
216
+ // double hardbreak
217
+
218
+ // backtrack a little; remove the trailing hardbreak we added last loop
219
+ curChildren.pop();
220
+
221
+ // create a new paragraph
222
+ paragraphs.push(paragraph.createChecked(undefined, curChildren, [...blockMarks]));
223
+ curChildren = [];
224
+ return;
225
+ }
226
+
227
+ // add to this paragraph
228
+ curChildren.push(node);
229
+ lastNode = node;
230
+ });
231
+ if (curChildren.length) {
232
+ paragraphs.push(paragraph.createChecked(undefined, curChildren, [...blockMarks]));
233
+ }
234
+ return Fragment.from(paragraphs.length ? paragraphs : [paragraph.createAndFill(undefined, undefined, [...blockMarks])]);
235
+ };
@@ -17,7 +17,7 @@ import { ACTION, analyticsPluginKey, INPUT_METHOD, PasteTypes } from '../../anal
17
17
  import { isInsideBlockQuote, insideTable, measurements } from '../../../utils';
18
18
  import { measureRender } from '@atlaskit/editor-common/utils';
19
19
  import { transformSliceToCorrectMediaWrapper, unwrapNestedMediaElements } from '../../media/utils/media-common';
20
- import { upgradeTextToLists, splitParagraphs } from '../../list/transforms';
20
+ import { upgradeTextToLists, splitParagraphs } from '../commands';
21
21
  import { md } from '@atlaskit/editor-common/paste';
22
22
  import { transformSliceToDecisionList } from '../../tasks-and-decisions/utils';
23
23
  import { containsAnyAnnotations, stripNonExistingAnnotations } from '../../annotation/utils';
@@ -7,7 +7,7 @@ import IndentIcon from '@atlaskit/icon/glyph/editor/indent';
7
7
  import OutdentIcon from '@atlaskit/icon/glyph/editor/outdent';
8
8
  import { toggleBulletList as toggleBulletListKeymap, toggleOrderedList as toggleOrderedListKeymap, indent as toggleIndentKeymap, outdent as toggleOutdentKeymap, ToolTipContent, tooltip } from '../../../keymaps';
9
9
  import ToolbarButton, { TOOLBAR_BUTTON } from '../../../ui/ToolbarButton';
10
- import { messages } from '../../list/messages';
10
+ import { listMessages as messages } from '@atlaskit/editor-common/messages';
11
11
  import { messages as indentationMessages } from '../../indentation/messages';
12
12
  import { separatorStyles, buttonGroupStyle } from '@atlaskit/editor-common/styles';
13
13
  import { getAriaKeyshortcuts } from '@atlaskit/editor-common/keymaps';
@@ -9,7 +9,7 @@ import { DropdownMenuWithKeyboardNavigation as DropdownMenu } from '@atlaskit/ed
9
9
  import ToolbarButton from '../../../ui/ToolbarButton';
10
10
  import { expandIconWrapperStyle, shortcutStyle } from '../../../ui/styles';
11
11
  import { wrapperStyle, separatorStyles } from '@atlaskit/editor-common/styles';
12
- import { messages as listMessages } from '../../list/messages';
12
+ import { listMessages } from '@atlaskit/editor-common/messages';
13
13
  import { messages as indentationMessages } from '../../indentation/messages';
14
14
  export function ToolbarDropdown(props) {
15
15
  const {
@@ -1,5 +1,5 @@
1
1
  export const name = "@atlaskit/editor-core";
2
- export const version = "187.17.6";
2
+ export const version = "187.18.1";
3
3
  export const nextMajorVersion = () => {
4
4
  return [Number(version.split('.')[0]) + 1, 0, 0].join('.');
5
5
  };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-core",
3
- "version": "187.17.6",
3
+ "version": "187.18.1",
4
4
  "sideEffects": false
5
5
  }
@@ -4,7 +4,7 @@ import pastePlugin from '../../../plugins/paste';
4
4
  import blockTypePlugin from '../../../plugins/block-type';
5
5
  import clearMarksOnChangeToEmptyDocumentPlugin from '../../../plugins/clear-marks-on-change-to-empty-document';
6
6
  import { hyperlinkPlugin } from '@atlaskit/editor-plugin-hyperlink';
7
- import textFormattingPlugin from '../../../plugins/text-formatting';
7
+ import { textFormattingPlugin } from '@atlaskit/editor-plugin-text-formatting';
8
8
  import { widthPlugin } from '@atlaskit/editor-plugin-width';
9
9
  import unsupportedContentPlugin from '../../../plugins/unsupported-content';
10
10
  import basePlugin from '../../../plugins/base';
@@ -24,6 +24,15 @@ export var annotationMessages = defineMessages({
24
24
  description: 'A label for a toolbar (UI element) that creates annotations/comments in the document'
25
25
  }
26
26
  });
27
+ /**
28
+ * Returns the coordintes at the bottom the selection.
29
+ */
30
+ var getCoordsBelowSelection = function getCoordsBelowSelection(bottomCoords, toolbarRect) {
31
+ return {
32
+ top: (bottomCoords.top || 0) + toolbarRect.height / 1.15,
33
+ left: bottomCoords.right - toolbarRect.width / 2
34
+ };
35
+ };
27
36
 
28
37
  /*
29
38
  Calculates the position of the floating toolbar relative to the selection.
@@ -74,13 +83,13 @@ var calculateToolbarPositionAboveSelection = function calculateToolbarPositionAb
74
83
  }
75
84
 
76
85
  /*
77
- short selection above a long paragraph
78
- eg. short {<}heading
79
- The purpose of this text is to show the selection range{>}.
80
- The horizontal positioning should center around "heading",
81
- not where it ends at "range".
82
- Note: if it was "head<b>ing</b>" then it would only center
83
- around "head". Undesireable but matches the current renderer.
86
+ short selection above a long paragraph
87
+ eg. short {<}heading
88
+ The purpose of this text is to show the selection range{>}.
89
+ The horizontal positioning should center around "heading",
90
+ not where it ends at "range".
91
+ Note: if it was "head<b>ing</b>" then it would only center
92
+ around "head". Undesireable but matches the current renderer.
84
93
  */
85
94
  var cliffPosition = range.getClientRects()[0];
86
95
  if (cliffPosition.right < left) {
@@ -92,6 +101,13 @@ var calculateToolbarPositionAboveSelection = function calculateToolbarPositionAb
92
101
  }
93
102
  left -= toolbarRect.width / 2;
94
103
 
104
+ // Place toolbar below selection if not sufficient space above
105
+ if (top < wrapperBounds.top) {
106
+ var _getCoordsBelowSelect = getCoordsBelowSelection(bottomCoords, toolbarRect);
107
+ top = _getCoordsBelowSelect.top;
108
+ left = _getCoordsBelowSelect.left;
109
+ }
110
+
95
111
  // remap positions from browser document to wrapperBounds
96
112
  return {
97
113
  top: top - wrapperBounds.top + scrollWrapper.scrollTop,
@@ -147,6 +163,13 @@ var calculateToolbarPositionTrackHead = function calculateToolbarPositionTrackHe
147
163
  }
148
164
  var left = (head > anchor ? bottomCoords.right : topCoords.left) - toolbarRect.width / 2;
149
165
 
166
+ // Place toolbar below selection if not sufficient space above
167
+ if (top < wrapperBounds.top) {
168
+ var _getCoordsBelowSelect2 = getCoordsBelowSelection(bottomCoords, toolbarRect);
169
+ top = _getCoordsBelowSelect2.top;
170
+ left = _getCoordsBelowSelect2.left;
171
+ }
172
+
150
173
  // remap positions from browser document to wrapperBounds
151
174
  return {
152
175
  top: top - wrapperBounds.top + scrollWrapper.scrollTop,
@@ -19,8 +19,7 @@ import AkModalDialog, { ModalTransition, useModal } from '@atlaskit/modal-dialog
19
19
  import { header, footer, contentWrapper, line, content, row, codeSm, codeMd, codeLg, title, column, dialogHeader } from './styles';
20
20
  import * as keymaps from '../../../keymaps';
21
21
  import ToolbarButton from '../../../ui/ToolbarButton';
22
- import { toolbarMessages } from '@atlaskit/editor-common/messages';
23
- import { messages as listMessages } from '../../list/messages';
22
+ import { toolbarMessages, listMessages } from '@atlaskit/editor-common/messages';
24
23
  import { messages as insertBlockMessages } from '../../insert-block/ui/ToolbarInsertBlock/messages';
25
24
  import { messages as blockTypeMessages } from '../../block-type/messages';
26
25
  import { messages as undoRedoMessages } from '../../undo-redo/messages';
@@ -30,7 +30,6 @@ export { default as saveOnEnterPlugin } from './save-on-enter';
30
30
  export { default as submitEditorPlugin } from './submit-editor';
31
31
  export { default as tasksAndDecisionsPlugin } from './tasks-and-decisions';
32
32
  export { default as textColorPlugin } from './text-color';
33
- export { default as textFormattingPlugin } from './text-formatting';
34
33
  export { default as typeAheadPlugin } from './type-ahead';
35
34
  export { default as unsupportedContentPlugin } from './unsupported-content';
36
35
  export { default as floatingToolbarPlugin } from './floating-toolbar';
@@ -3,7 +3,7 @@ import { orderedList, orderedListWithOrder, bulletList, listItem } from '@atlask
3
3
  import { createPlugin } from './pm-plugins/main';
4
4
  import inputRulePlugin from './pm-plugins/input-rules';
5
5
  import keymapPlugin from './pm-plugins/keymap';
6
- import { messages } from './messages';
6
+ import { listMessages as messages } from '@atlaskit/editor-common/messages';
7
7
  import { ACTION, EVENT_TYPE, INPUT_METHOD, ACTION_SUBJECT, ACTION_SUBJECT_ID } from '../analytics';
8
8
  import { tooltip, toggleBulletList, toggleOrderedList } from '../../keymaps';
9
9
  import { IconList, IconListNumber } from '@atlaskit/editor-common/quick-insert';
@@ -1,11 +1,6 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
1
  import { Fragment, NodeRange, Slice } from '@atlaskit/editor-prosemirror/model';
4
- import { EditorState, TextSelection } from '@atlaskit/editor-prosemirror/state';
2
+ import { TextSelection } from '@atlaskit/editor-prosemirror/state';
5
3
  import { liftTarget, ReplaceAroundStep } from '@atlaskit/editor-prosemirror/transform';
6
- import { autoJoin } from '@atlaskit/editor-prosemirror/commands';
7
- import { isListNode } from '@atlaskit/editor-common/utils';
8
- import { mapSlice, mapChildren } from '../../utils/slice';
9
4
  import { getListLiftTarget } from './utils/indentation';
10
5
  function liftListItem(selection, tr) {
11
6
  var $from = selection.$from,
@@ -94,216 +89,4 @@ export function liftTextSelectionList(selection, tr) {
94
89
  }
95
90
  }
96
91
  return tr;
97
- }
98
-
99
- // matchers for text lists
100
- var bullets = /^\s*[\*\-\u2022](\s+|\s+$)/;
101
- var numbers = /^\s*\d[\.\)](\s+|$)/;
102
- var getListType = function getListType(node, schema) {
103
- if (!node.text) {
104
- return null;
105
- }
106
- var _schema$nodes = schema.nodes,
107
- bulletList = _schema$nodes.bulletList,
108
- orderedList = _schema$nodes.orderedList;
109
- return [{
110
- node: bulletList,
111
- matcher: bullets
112
- }, {
113
- node: orderedList,
114
- matcher: numbers
115
- }].reduce(function (lastMatch, listType) {
116
- if (lastMatch) {
117
- return lastMatch;
118
- }
119
- var match = node.text.match(listType.matcher);
120
- return match ? [listType.node, match[0].length] : lastMatch;
121
- }, null);
122
- };
123
- var extractListFromParagraph = function extractListFromParagraph(node, parent, schema) {
124
- var _schema$nodes2 = schema.nodes,
125
- hardBreak = _schema$nodes2.hardBreak,
126
- bulletList = _schema$nodes2.bulletList,
127
- orderedList = _schema$nodes2.orderedList;
128
- var content = mapChildren(node.content, function (node) {
129
- return node;
130
- });
131
- var listTypes = [bulletList, orderedList];
132
-
133
- // wrap each line into a listItem and a containing list
134
- var listified = content.map(function (child, index) {
135
- var listMatch = getListType(child, schema);
136
- var prevChild = index > 0 && content[index - 1];
137
-
138
- // only extract list when preceded by a hardbreak
139
- if (prevChild && prevChild.type !== hardBreak) {
140
- return child;
141
- }
142
- if (!listMatch || !child.text) {
143
- return child;
144
- }
145
- var _listMatch = _slicedToArray(listMatch, 2),
146
- nodeType = _listMatch[0],
147
- length = _listMatch[1];
148
-
149
- // convert to list item
150
- var newText = child.text.substr(length);
151
- var listItemNode = schema.nodes.listItem.createAndFill(undefined, schema.nodes.paragraph.createChecked(undefined, newText.length ? schema.text(newText) : undefined));
152
- if (!listItemNode) {
153
- return child;
154
- }
155
- var newList = nodeType.createChecked(undefined, [listItemNode]);
156
- // Check whether our new list is valid content in our current structure,
157
- // otherwise dont convert.
158
- if (parent && !parent.type.validContent(Fragment.from(newList))) {
159
- return child;
160
- }
161
- return newList;
162
- }).filter(function (child, idx, arr) {
163
- // remove hardBreaks that have a list node on either side
164
-
165
- // wasn't hardBreak, leave as-is
166
- if (child.type !== hardBreak) {
167
- return child;
168
- }
169
- if (idx > 0 && listTypes.indexOf(arr[idx - 1].type) > -1) {
170
- // list node on the left
171
- return null;
172
- }
173
- if (idx < arr.length - 1 && listTypes.indexOf(arr[idx + 1].type) > -1) {
174
- // list node on the right
175
- return null;
176
- }
177
- return child;
178
- });
179
-
180
- // try to join
181
- var mockState = EditorState.create({
182
- schema: schema
183
- });
184
- var joinedListsTr;
185
- var mockDispatch = function mockDispatch(tr) {
186
- joinedListsTr = tr;
187
- };
188
- autoJoin(function (state, dispatch) {
189
- if (!dispatch) {
190
- return false;
191
- }
192
-
193
- // Return false to prevent replaceWith from wrapping the text node in a paragraph
194
- // paragraph since that will be done later. If it's done here, it will fail
195
- // the paragraph.validContent check.
196
- // Dont return false if there are lists, as they arent validContent for paragraphs
197
- // and will result in hanging textNodes
198
- var containsList = listified.some(function (node) {
199
- return node.type === bulletList || node.type === orderedList;
200
- });
201
- if (listified.some(function (node) {
202
- return node.isText;
203
- }) && !containsList) {
204
- return false;
205
- }
206
- dispatch(state.tr.replaceWith(0, 2, listified));
207
- return true;
208
- }, function (before, after) {
209
- return isListNode(before) && isListNode(after);
210
- })(mockState, mockDispatch);
211
- var fragment = joinedListsTr ? joinedListsTr.doc.content : Fragment.from(listified);
212
-
213
- // try to re-wrap fragment in paragraph (which is the original node we unwrapped)
214
- var paragraph = schema.nodes.paragraph;
215
- if (paragraph.validContent(fragment)) {
216
- return Fragment.from(paragraph.create(node.attrs, fragment, node.marks));
217
- }
218
-
219
- // fragment now contains other nodes, get Prosemirror to wrap with ContentMatch later
220
- return fragment;
221
- };
222
-
223
- /**
224
- * Walks the slice, creating paragraphs that were previously separated by hardbreaks.
225
- * Returns the original paragraph node (as a fragment), or a fragment containing multiple nodes.
226
- */
227
- export var splitIntoParagraphs = function splitIntoParagraphs(_ref) {
228
- var fragment = _ref.fragment,
229
- _ref$blockMarks = _ref.blockMarks,
230
- blockMarks = _ref$blockMarks === void 0 ? [] : _ref$blockMarks,
231
- schema = _ref.schema;
232
- var paragraphs = [];
233
- var curChildren = [];
234
- var lastNode = null;
235
- var _schema$nodes3 = schema.nodes,
236
- hardBreak = _schema$nodes3.hardBreak,
237
- paragraph = _schema$nodes3.paragraph;
238
- fragment.forEach(function (node, i) {
239
- var isNodeValidContentForParagraph = schema.nodes.paragraph.validContent(Fragment.from(node));
240
- if (!isNodeValidContentForParagraph) {
241
- paragraphs.push(node);
242
- return;
243
- }
244
- // ED-14725 Fixed the issue that it make duplicated line
245
- // when pasting <br /> from google docs.
246
- if (i === 0 && node.type === hardBreak) {
247
- paragraphs.push(paragraph.createChecked(undefined, curChildren, _toConsumableArray(blockMarks)));
248
- lastNode = node;
249
- return;
250
- } else if (lastNode && lastNode.type === hardBreak && node.type === hardBreak) {
251
- // double hardbreak
252
-
253
- // backtrack a little; remove the trailing hardbreak we added last loop
254
- curChildren.pop();
255
-
256
- // create a new paragraph
257
- paragraphs.push(paragraph.createChecked(undefined, curChildren, _toConsumableArray(blockMarks)));
258
- curChildren = [];
259
- return;
260
- }
261
-
262
- // add to this paragraph
263
- curChildren.push(node);
264
- lastNode = node;
265
- });
266
- if (curChildren.length) {
267
- paragraphs.push(paragraph.createChecked(undefined, curChildren, _toConsumableArray(blockMarks)));
268
- }
269
- return Fragment.from(paragraphs.length ? paragraphs : [paragraph.createAndFill(undefined, undefined, _toConsumableArray(blockMarks))]);
270
- };
271
- export var splitParagraphs = function splitParagraphs(slice, schema) {
272
- // exclude Text nodes with a code mark, since we transform those later
273
- // into a codeblock
274
- var hasCodeMark = false;
275
- slice.content.forEach(function (child) {
276
- hasCodeMark = hasCodeMark || child.marks.some(function (mark) {
277
- return mark.type === schema.marks.code;
278
- });
279
- });
280
-
281
- // slice might just be a raw text string
282
- if (schema.nodes.paragraph.validContent(slice.content) && !hasCodeMark) {
283
- var replSlice = splitIntoParagraphs({
284
- fragment: slice.content,
285
- schema: schema
286
- });
287
- return new Slice(replSlice, slice.openStart + 1, slice.openEnd + 1);
288
- }
289
- return mapSlice(slice, function (node) {
290
- if (node.type === schema.nodes.paragraph) {
291
- return splitIntoParagraphs({
292
- fragment: node.content,
293
- blockMarks: node.marks,
294
- schema: schema
295
- });
296
- }
297
- return node;
298
- });
299
- };
300
-
301
- // above will wrap everything in paragraphs for us
302
- export var upgradeTextToLists = function upgradeTextToLists(slice, schema) {
303
- return mapSlice(slice, function (node, parent) {
304
- if (node.type === schema.nodes.paragraph) {
305
- return extractListFromParagraph(node, parent, schema);
306
- }
307
- return node;
308
- });
309
- };
92
+ }