@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,11 +1,18 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
- exports.stopTrackingPastedMacroPositions = exports.startTrackingPastedMacroPositions = void 0;
7
+ exports.upgradeTextToLists = exports.stopTrackingPastedMacroPositions = exports.startTrackingPastedMacroPositions = exports.splitParagraphs = exports.splitIntoParagraphs = void 0;
8
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
7
10
  var _pluginFactory = require("./pm-plugins/plugin-factory");
8
11
  var _actions = require("./actions");
12
+ var _model = require("@atlaskit/editor-prosemirror/model");
13
+ var _utils = require("@atlaskit/editor-common/utils");
14
+ var _state = require("@atlaskit/editor-prosemirror/state");
15
+ var _commands = require("@atlaskit/editor-prosemirror/commands");
9
16
  /**
10
17
  * Use this to register macro link positions during a paste operation, that you
11
18
  * want to track in a document over time, through any document changes.
@@ -35,4 +42,219 @@ var stopTrackingPastedMacroPositions = function stopTrackingPastedMacroPositions
35
42
  };
36
43
  });
37
44
  };
38
- exports.stopTrackingPastedMacroPositions = stopTrackingPastedMacroPositions;
45
+
46
+ // matchers for text lists
47
+ exports.stopTrackingPastedMacroPositions = stopTrackingPastedMacroPositions;
48
+ var bullets = /^\s*[\*\-\u2022](\s+|\s+$)/;
49
+ var numbers = /^\s*\d[\.\)](\s+|$)/;
50
+ var getListType = function getListType(node, schema) {
51
+ if (!node.text) {
52
+ return null;
53
+ }
54
+ var _schema$nodes = schema.nodes,
55
+ bulletList = _schema$nodes.bulletList,
56
+ orderedList = _schema$nodes.orderedList;
57
+ return [{
58
+ node: bulletList,
59
+ matcher: bullets
60
+ }, {
61
+ node: orderedList,
62
+ matcher: numbers
63
+ }].reduce(function (lastMatch, listType) {
64
+ if (lastMatch) {
65
+ return lastMatch;
66
+ }
67
+ var match = node.text.match(listType.matcher);
68
+ return match ? [listType.node, match[0].length] : lastMatch;
69
+ }, null);
70
+ };
71
+ var extractListFromParagraph = function extractListFromParagraph(node, parent, schema) {
72
+ var _schema$nodes2 = schema.nodes,
73
+ hardBreak = _schema$nodes2.hardBreak,
74
+ bulletList = _schema$nodes2.bulletList,
75
+ orderedList = _schema$nodes2.orderedList;
76
+ var content = (0, _utils.mapChildren)(node.content, function (node) {
77
+ return node;
78
+ });
79
+ var listTypes = [bulletList, orderedList];
80
+
81
+ // wrap each line into a listItem and a containing list
82
+ var listified = content.map(function (child, index) {
83
+ var listMatch = getListType(child, schema);
84
+ var prevChild = index > 0 && content[index - 1];
85
+
86
+ // only extract list when preceded by a hardbreak
87
+ if (prevChild && prevChild.type !== hardBreak) {
88
+ return child;
89
+ }
90
+ if (!listMatch || !child.text) {
91
+ return child;
92
+ }
93
+ var _listMatch = (0, _slicedToArray2.default)(listMatch, 2),
94
+ nodeType = _listMatch[0],
95
+ length = _listMatch[1];
96
+
97
+ // convert to list item
98
+ var newText = child.text.substr(length);
99
+ var listItemNode = schema.nodes.listItem.createAndFill(undefined, schema.nodes.paragraph.createChecked(undefined, newText.length ? schema.text(newText) : undefined));
100
+ if (!listItemNode) {
101
+ return child;
102
+ }
103
+ var newList = nodeType.createChecked(undefined, [listItemNode]);
104
+ // Check whether our new list is valid content in our current structure,
105
+ // otherwise dont convert.
106
+ if (parent && !parent.type.validContent(_model.Fragment.from(newList))) {
107
+ return child;
108
+ }
109
+ return newList;
110
+ }).filter(function (child, idx, arr) {
111
+ // remove hardBreaks that have a list node on either side
112
+
113
+ // wasn't hardBreak, leave as-is
114
+ if (child.type !== hardBreak) {
115
+ return child;
116
+ }
117
+ if (idx > 0 && listTypes.indexOf(arr[idx - 1].type) > -1) {
118
+ // list node on the left
119
+ return null;
120
+ }
121
+ if (idx < arr.length - 1 && listTypes.indexOf(arr[idx + 1].type) > -1) {
122
+ // list node on the right
123
+ return null;
124
+ }
125
+ return child;
126
+ });
127
+
128
+ // try to join
129
+ var mockState = _state.EditorState.create({
130
+ schema: schema
131
+ });
132
+ var joinedListsTr;
133
+ var mockDispatch = function mockDispatch(tr) {
134
+ joinedListsTr = tr;
135
+ };
136
+ (0, _commands.autoJoin)(function (state, dispatch) {
137
+ if (!dispatch) {
138
+ return false;
139
+ }
140
+
141
+ // Return false to prevent replaceWith from wrapping the text node in a paragraph
142
+ // paragraph since that will be done later. If it's done here, it will fail
143
+ // the paragraph.validContent check.
144
+ // Dont return false if there are lists, as they arent validContent for paragraphs
145
+ // and will result in hanging textNodes
146
+ var containsList = listified.some(function (node) {
147
+ return node.type === bulletList || node.type === orderedList;
148
+ });
149
+ if (listified.some(function (node) {
150
+ return node.isText;
151
+ }) && !containsList) {
152
+ return false;
153
+ }
154
+ dispatch(state.tr.replaceWith(0, 2, listified));
155
+ return true;
156
+ }, function (before, after) {
157
+ return (0, _utils.isListNode)(before) && (0, _utils.isListNode)(after);
158
+ })(mockState, mockDispatch);
159
+ var fragment = joinedListsTr ? joinedListsTr.doc.content : _model.Fragment.from(listified);
160
+
161
+ // try to re-wrap fragment in paragraph (which is the original node we unwrapped)
162
+ var paragraph = schema.nodes.paragraph;
163
+ if (paragraph.validContent(fragment)) {
164
+ return _model.Fragment.from(paragraph.create(node.attrs, fragment, node.marks));
165
+ }
166
+
167
+ // fragment now contains other nodes, get Prosemirror to wrap with ContentMatch later
168
+ return fragment;
169
+ };
170
+
171
+ // above will wrap everything in paragraphs for us
172
+ var upgradeTextToLists = function upgradeTextToLists(slice, schema) {
173
+ return (0, _utils.mapSlice)(slice, function (node, parent) {
174
+ if (node.type === schema.nodes.paragraph) {
175
+ return extractListFromParagraph(node, parent, schema);
176
+ }
177
+ return node;
178
+ });
179
+ };
180
+ exports.upgradeTextToLists = upgradeTextToLists;
181
+ var splitParagraphs = function splitParagraphs(slice, schema) {
182
+ // exclude Text nodes with a code mark, since we transform those later
183
+ // into a codeblock
184
+ var hasCodeMark = false;
185
+ slice.content.forEach(function (child) {
186
+ hasCodeMark = hasCodeMark || child.marks.some(function (mark) {
187
+ return mark.type === schema.marks.code;
188
+ });
189
+ });
190
+
191
+ // slice might just be a raw text string
192
+ if (schema.nodes.paragraph.validContent(slice.content) && !hasCodeMark) {
193
+ var replSlice = splitIntoParagraphs({
194
+ fragment: slice.content,
195
+ schema: schema
196
+ });
197
+ return new _model.Slice(replSlice, slice.openStart + 1, slice.openEnd + 1);
198
+ }
199
+ return (0, _utils.mapSlice)(slice, function (node) {
200
+ if (node.type === schema.nodes.paragraph) {
201
+ return splitIntoParagraphs({
202
+ fragment: node.content,
203
+ blockMarks: node.marks,
204
+ schema: schema
205
+ });
206
+ }
207
+ return node;
208
+ });
209
+ };
210
+
211
+ /**
212
+ * Walks the slice, creating paragraphs that were previously separated by hardbreaks.
213
+ * Returns the original paragraph node (as a fragment), or a fragment containing multiple nodes.
214
+ */
215
+ exports.splitParagraphs = splitParagraphs;
216
+ var splitIntoParagraphs = function splitIntoParagraphs(_ref) {
217
+ var fragment = _ref.fragment,
218
+ _ref$blockMarks = _ref.blockMarks,
219
+ blockMarks = _ref$blockMarks === void 0 ? [] : _ref$blockMarks,
220
+ schema = _ref.schema;
221
+ var paragraphs = [];
222
+ var curChildren = [];
223
+ var lastNode = null;
224
+ var _schema$nodes3 = schema.nodes,
225
+ hardBreak = _schema$nodes3.hardBreak,
226
+ paragraph = _schema$nodes3.paragraph;
227
+ fragment.forEach(function (node, i) {
228
+ var isNodeValidContentForParagraph = schema.nodes.paragraph.validContent(_model.Fragment.from(node));
229
+ if (!isNodeValidContentForParagraph) {
230
+ paragraphs.push(node);
231
+ return;
232
+ }
233
+ // ED-14725 Fixed the issue that it make duplicated line
234
+ // when pasting <br /> from google docs.
235
+ if (i === 0 && node.type === hardBreak) {
236
+ paragraphs.push(paragraph.createChecked(undefined, curChildren, (0, _toConsumableArray2.default)(blockMarks)));
237
+ lastNode = node;
238
+ return;
239
+ } else if (lastNode && lastNode.type === hardBreak && node.type === hardBreak) {
240
+ // double hardbreak
241
+
242
+ // backtrack a little; remove the trailing hardbreak we added last loop
243
+ curChildren.pop();
244
+
245
+ // create a new paragraph
246
+ paragraphs.push(paragraph.createChecked(undefined, curChildren, (0, _toConsumableArray2.default)(blockMarks)));
247
+ curChildren = [];
248
+ return;
249
+ }
250
+
251
+ // add to this paragraph
252
+ curChildren.push(node);
253
+ lastNode = node;
254
+ });
255
+ if (curChildren.length) {
256
+ paragraphs.push(paragraph.createChecked(undefined, curChildren, (0, _toConsumableArray2.default)(blockMarks)));
257
+ }
258
+ return _model.Fragment.from(paragraphs.length ? paragraphs : [paragraph.createAndFill(undefined, undefined, (0, _toConsumableArray2.default)(blockMarks))]);
259
+ };
260
+ exports.splitIntoParagraphs = splitIntoParagraphs;
@@ -32,7 +32,7 @@ var _analytics = require("./analytics");
32
32
  var _analytics2 = require("../../analytics");
33
33
  var _utils4 = require("../../../utils");
34
34
  var _mediaCommon = require("../../media/utils/media-common");
35
- var _transforms = require("../../list/transforms");
35
+ var _commands = require("../commands");
36
36
  var _paste = require("@atlaskit/editor-common/paste");
37
37
  var _utils5 = require("../../tasks-and-decisions/utils");
38
38
  var _utils6 = require("../../annotation/utils");
@@ -403,8 +403,8 @@ function createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFlags, pl
403
403
  slice = (0, _utils5.transformSliceToDecisionList)(slice, schema);
404
404
 
405
405
  // splitting linebreaks into paragraphs must happen before upgrading text to lists
406
- slice = (0, _transforms.splitParagraphs)(slice, schema);
407
- slice = (0, _transforms.upgradeTextToLists)(slice, schema);
406
+ slice = (0, _commands.splitParagraphs)(slice, schema);
407
+ slice = (0, _commands.upgradeTextToLists)(slice, schema);
408
408
  if (slice.content.childCount && slice.content.lastChild.type === schema.nodes.codeBlock) {
409
409
  slice = new _model.Slice(slice.content.append(_model.Fragment.from(schema.nodes.paragraph.createAndFill())), slice.openStart, 1);
410
410
  }
@@ -14,7 +14,7 @@ var _indent = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/indent
14
14
  var _outdent = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/outdent"));
15
15
  var _keymaps = require("../../../keymaps");
16
16
  var _ToolbarButton = _interopRequireWildcard(require("../../../ui/ToolbarButton"));
17
- var _messages = require("../../list/messages");
17
+ var _messages = require("@atlaskit/editor-common/messages");
18
18
  var _messages2 = require("../../indentation/messages");
19
19
  var _styles = require("@atlaskit/editor-common/styles");
20
20
  var _keymaps2 = require("@atlaskit/editor-common/keymaps");
@@ -38,8 +38,8 @@ function Toolbar(props) {
38
38
  indentDisabled = props.indentDisabled,
39
39
  outdentDisabled = props.outdentDisabled,
40
40
  onItemActivated = props.onItemActivated;
41
- var labelUnorderedList = formatMessage(_messages.messages.unorderedList);
42
- var labelOrderedList = formatMessage(_messages.messages.orderedList);
41
+ var labelUnorderedList = formatMessage(_messages.listMessages.unorderedList);
42
+ var labelOrderedList = formatMessage(_messages.listMessages.orderedList);
43
43
  var indentMessage = formatMessage(_messages2.messages.indent);
44
44
  var outdentMessage = formatMessage(_messages2.messages.outdent);
45
45
  var isIndentButtonFocused = document.activeElement === indentButtonRef.current;
@@ -16,7 +16,7 @@ var _uiMenu = require("@atlaskit/editor-common/ui-menu");
16
16
  var _ToolbarButton = _interopRequireDefault(require("../../../ui/ToolbarButton"));
17
17
  var _styles = require("../../../ui/styles");
18
18
  var _styles2 = require("@atlaskit/editor-common/styles");
19
- var _messages = require("../../list/messages");
19
+ var _messages = require("@atlaskit/editor-common/messages");
20
20
  var _messages2 = require("../../indentation/messages");
21
21
  /** @jsx jsx */
22
22
 
@@ -39,7 +39,7 @@ function ToolbarDropdown(props) {
39
39
  _React$useState4 = (0, _slicedToArray2.default)(_React$useState3, 2),
40
40
  isOpenedByKeyboard = _React$useState4[0],
41
41
  setOpenedByKeyboard = _React$useState4[1];
42
- var labelLists = formatMessage(_messages.messages.lists);
42
+ var labelLists = formatMessage(_messages.listMessages.lists);
43
43
  var onOpenChange = function onOpenChange(attrs) {
44
44
  setIsDropdownOpen(attrs.isDropdownOpen);
45
45
  };
@@ -112,8 +112,8 @@ function ToolbarDropdown(props) {
112
112
  function useItems(props) {
113
113
  var _useIntl2 = (0, _reactIntlNext.useIntl)(),
114
114
  formatMessage = _useIntl2.formatMessage;
115
- var labelUnorderedList = formatMessage(_messages.messages.unorderedList);
116
- var labelOrderedList = formatMessage(_messages.messages.orderedList);
115
+ var labelUnorderedList = formatMessage(_messages.listMessages.unorderedList);
116
+ var labelOrderedList = formatMessage(_messages.listMessages.orderedList);
117
117
  var items = [{
118
118
  key: 'unorderedList',
119
119
  content: labelUnorderedList,
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.version = exports.nextMajorVersion = exports.name = void 0;
7
7
  var name = "@atlaskit/editor-core";
8
8
  exports.name = name;
9
- var version = "187.17.6";
9
+ var version = "187.18.1";
10
10
  exports.version = version;
11
11
  var nextMajorVersion = function nextMajorVersion() {
12
12
  return [Number(version.split('.')[0]) + 1, 0, 0].join('.');
@@ -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 const 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
+ const 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.
@@ -61,7 +70,7 @@ const calculateToolbarPositionAboveSelection = toolbarTitle => (editorView, next
61
70
  } = editorView.state.selection;
62
71
  const topCoords = editorView.coordsAtPos(Math.min(head, anchor));
63
72
  const bottomCoords = editorView.coordsAtPos(Math.max(head, anchor) - Math.min(range.endOffset, 1));
64
- const top = (topCoords.top || 0) - toolbarRect.height * 1.5;
73
+ let top = (topCoords.top || 0) - toolbarRect.height * 1.5;
65
74
  let left = 0;
66
75
 
67
76
  // If not on the same line
@@ -74,13 +83,13 @@ const calculateToolbarPositionAboveSelection = toolbarTitle => (editorView, next
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
  const cliffPosition = range.getClientRects()[0];
86
95
  if (cliffPosition.right < left) {
@@ -92,6 +101,14 @@ const calculateToolbarPositionAboveSelection = toolbarTitle => (editorView, next
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
+ ({
107
+ top,
108
+ left
109
+ } = getCoordsBelowSelection(bottomCoords, toolbarRect));
110
+ }
111
+
95
112
  // remap positions from browser document to wrapperBounds
96
113
  return {
97
114
  top: top - wrapperBounds.top + scrollWrapper.scrollTop,
@@ -144,7 +161,15 @@ const calculateToolbarPositionTrackHead = toolbarTitle => (editorView, nextPos)
144
161
  } else {
145
162
  top = (topCoords.top || 0) - toolbarRect.height * 1.5;
146
163
  }
147
- const left = (head > anchor ? bottomCoords.right : topCoords.left) - toolbarRect.width / 2;
164
+ let left = (head > anchor ? bottomCoords.right : topCoords.left) - toolbarRect.width / 2;
165
+
166
+ // Place toolbar below selection if not sufficient space above
167
+ if (top < wrapperBounds.top) {
168
+ ({
169
+ top,
170
+ left
171
+ } = getCoordsBelowSelection(bottomCoords, toolbarRect));
172
+ }
148
173
 
149
174
  // remap positions from browser document to wrapperBounds
150
175
  return {
@@ -10,8 +10,7 @@ import AkModalDialog, { ModalTransition, useModal } from '@atlaskit/modal-dialog
10
10
  import { header, footer, contentWrapper, line, content, row, codeSm, codeMd, codeLg, title, column, dialogHeader } from './styles';
11
11
  import * as keymaps from '../../../keymaps';
12
12
  import ToolbarButton from '../../../ui/ToolbarButton';
13
- import { toolbarMessages } from '@atlaskit/editor-common/messages';
14
- import { messages as listMessages } from '../../list/messages';
13
+ import { toolbarMessages, listMessages } from '@atlaskit/editor-common/messages';
15
14
  import { messages as insertBlockMessages } from '../../insert-block/ui/ToolbarInsertBlock/messages';
16
15
  import { messages as blockTypeMessages } from '../../block-type/messages';
17
16
  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,9 +1,6 @@
1
1
  import { Fragment, NodeRange, Slice } from '@atlaskit/editor-prosemirror/model';
2
- import { EditorState, TextSelection } from '@atlaskit/editor-prosemirror/state';
2
+ import { TextSelection } from '@atlaskit/editor-prosemirror/state';
3
3
  import { liftTarget, ReplaceAroundStep } from '@atlaskit/editor-prosemirror/transform';
4
- import { autoJoin } from '@atlaskit/editor-prosemirror/commands';
5
- import { isListNode } from '@atlaskit/editor-common/utils';
6
- import { mapSlice, mapChildren } from '../../utils/slice';
7
4
  import { getListLiftTarget } from './utils/indentation';
8
5
  function liftListItem(selection, tr) {
9
6
  let {
@@ -102,209 +99,4 @@ export function liftTextSelectionList(selection, tr) {
102
99
  }
103
100
  }
104
101
  return tr;
105
- }
106
-
107
- // matchers for text lists
108
- const bullets = /^\s*[\*\-\u2022](\s+|\s+$)/;
109
- const numbers = /^\s*\d[\.\)](\s+|$)/;
110
- const getListType = (node, schema) => {
111
- if (!node.text) {
112
- return null;
113
- }
114
- const {
115
- bulletList,
116
- orderedList
117
- } = schema.nodes;
118
- return [{
119
- node: bulletList,
120
- matcher: bullets
121
- }, {
122
- node: orderedList,
123
- matcher: numbers
124
- }].reduce((lastMatch, listType) => {
125
- if (lastMatch) {
126
- return lastMatch;
127
- }
128
- const match = node.text.match(listType.matcher);
129
- return match ? [listType.node, match[0].length] : lastMatch;
130
- }, null);
131
- };
132
- const extractListFromParagraph = (node, parent, schema) => {
133
- const {
134
- hardBreak,
135
- bulletList,
136
- orderedList
137
- } = schema.nodes;
138
- const content = mapChildren(node.content, node => node);
139
- const listTypes = [bulletList, orderedList];
140
-
141
- // wrap each line into a listItem and a containing list
142
- const listified = content.map((child, index) => {
143
- const listMatch = getListType(child, schema);
144
- const prevChild = index > 0 && content[index - 1];
145
-
146
- // only extract list when preceded by a hardbreak
147
- if (prevChild && prevChild.type !== hardBreak) {
148
- return child;
149
- }
150
- if (!listMatch || !child.text) {
151
- return child;
152
- }
153
- const [nodeType, length] = listMatch;
154
-
155
- // convert to list item
156
- const newText = child.text.substr(length);
157
- const listItemNode = schema.nodes.listItem.createAndFill(undefined, schema.nodes.paragraph.createChecked(undefined, newText.length ? schema.text(newText) : undefined));
158
- if (!listItemNode) {
159
- return child;
160
- }
161
- const newList = nodeType.createChecked(undefined, [listItemNode]);
162
- // Check whether our new list is valid content in our current structure,
163
- // otherwise dont convert.
164
- if (parent && !parent.type.validContent(Fragment.from(newList))) {
165
- return child;
166
- }
167
- return newList;
168
- }).filter((child, idx, arr) => {
169
- // remove hardBreaks that have a list node on either side
170
-
171
- // wasn't hardBreak, leave as-is
172
- if (child.type !== hardBreak) {
173
- return child;
174
- }
175
- if (idx > 0 && listTypes.indexOf(arr[idx - 1].type) > -1) {
176
- // list node on the left
177
- return null;
178
- }
179
- if (idx < arr.length - 1 && listTypes.indexOf(arr[idx + 1].type) > -1) {
180
- // list node on the right
181
- return null;
182
- }
183
- return child;
184
- });
185
-
186
- // try to join
187
- const mockState = EditorState.create({
188
- schema
189
- });
190
- let joinedListsTr;
191
- const mockDispatch = tr => {
192
- joinedListsTr = tr;
193
- };
194
- autoJoin((state, dispatch) => {
195
- if (!dispatch) {
196
- return false;
197
- }
198
-
199
- // Return false to prevent replaceWith from wrapping the text node in a paragraph
200
- // paragraph since that will be done later. If it's done here, it will fail
201
- // the paragraph.validContent check.
202
- // Dont return false if there are lists, as they arent validContent for paragraphs
203
- // and will result in hanging textNodes
204
- const containsList = listified.some(node => node.type === bulletList || node.type === orderedList);
205
- if (listified.some(node => node.isText) && !containsList) {
206
- return false;
207
- }
208
- dispatch(state.tr.replaceWith(0, 2, listified));
209
- return true;
210
- }, (before, after) => isListNode(before) && isListNode(after))(mockState, mockDispatch);
211
- const 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
- const {
215
- paragraph
216
- } = schema.nodes;
217
- if (paragraph.validContent(fragment)) {
218
- return Fragment.from(paragraph.create(node.attrs, fragment, node.marks));
219
- }
220
-
221
- // fragment now contains other nodes, get Prosemirror to wrap with ContentMatch later
222
- return fragment;
223
- };
224
-
225
- /**
226
- * Walks the slice, creating paragraphs that were previously separated by hardbreaks.
227
- * Returns the original paragraph node (as a fragment), or a fragment containing multiple nodes.
228
- */
229
- export const splitIntoParagraphs = ({
230
- fragment,
231
- blockMarks = [],
232
- schema
233
- }) => {
234
- const paragraphs = [];
235
- let curChildren = [];
236
- let lastNode = null;
237
- const {
238
- hardBreak,
239
- paragraph
240
- } = schema.nodes;
241
- fragment.forEach((node, i) => {
242
- const isNodeValidContentForParagraph = schema.nodes.paragraph.validContent(Fragment.from(node));
243
- if (!isNodeValidContentForParagraph) {
244
- paragraphs.push(node);
245
- return;
246
- }
247
- // ED-14725 Fixed the issue that it make duplicated line
248
- // when pasting <br /> from google docs.
249
- if (i === 0 && node.type === hardBreak) {
250
- paragraphs.push(paragraph.createChecked(undefined, curChildren, [...blockMarks]));
251
- lastNode = node;
252
- return;
253
- } else if (lastNode && lastNode.type === hardBreak && node.type === hardBreak) {
254
- // double hardbreak
255
-
256
- // backtrack a little; remove the trailing hardbreak we added last loop
257
- curChildren.pop();
258
-
259
- // create a new paragraph
260
- paragraphs.push(paragraph.createChecked(undefined, curChildren, [...blockMarks]));
261
- curChildren = [];
262
- return;
263
- }
264
-
265
- // add to this paragraph
266
- curChildren.push(node);
267
- lastNode = node;
268
- });
269
- if (curChildren.length) {
270
- paragraphs.push(paragraph.createChecked(undefined, curChildren, [...blockMarks]));
271
- }
272
- return Fragment.from(paragraphs.length ? paragraphs : [paragraph.createAndFill(undefined, undefined, [...blockMarks])]);
273
- };
274
- export const splitParagraphs = (slice, schema) => {
275
- // exclude Text nodes with a code mark, since we transform those later
276
- // into a codeblock
277
- let hasCodeMark = false;
278
- slice.content.forEach(child => {
279
- hasCodeMark = hasCodeMark || child.marks.some(mark => mark.type === schema.marks.code);
280
- });
281
-
282
- // slice might just be a raw text string
283
- if (schema.nodes.paragraph.validContent(slice.content) && !hasCodeMark) {
284
- const replSlice = splitIntoParagraphs({
285
- fragment: slice.content,
286
- schema
287
- });
288
- return new Slice(replSlice, slice.openStart + 1, slice.openEnd + 1);
289
- }
290
- return mapSlice(slice, node => {
291
- if (node.type === schema.nodes.paragraph) {
292
- return splitIntoParagraphs({
293
- fragment: node.content,
294
- blockMarks: node.marks,
295
- schema
296
- });
297
- }
298
- return node;
299
- });
300
- };
301
-
302
- // above will wrap everything in paragraphs for us
303
- export const upgradeTextToLists = (slice, schema) => {
304
- return mapSlice(slice, (node, parent) => {
305
- if (node.type === schema.nodes.paragraph) {
306
- return extractListFromParagraph(node, parent, schema);
307
- }
308
- return node;
309
- });
310
- };
102
+ }