@atlaskit/editor-core 187.18.0 → 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 (35) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/cjs/plugins/help-dialog/ui/index.js +26 -27
  3. package/dist/cjs/plugins/list/index.js +5 -5
  4. package/dist/cjs/plugins/list/transforms.js +1 -223
  5. package/dist/cjs/plugins/paste/commands.js +224 -2
  6. package/dist/cjs/plugins/paste/pm-plugins/main.js +3 -3
  7. package/dist/cjs/plugins/toolbar-lists-indentation/ui/Toolbar.js +3 -3
  8. package/dist/cjs/plugins/toolbar-lists-indentation/ui/ToolbarDropdown.js +4 -4
  9. package/dist/cjs/version-wrapper.js +1 -1
  10. package/dist/cjs/version.json +1 -1
  11. package/dist/es2019/plugins/help-dialog/ui/index.js +1 -2
  12. package/dist/es2019/plugins/list/index.js +1 -1
  13. package/dist/es2019/plugins/list/transforms.js +2 -210
  14. package/dist/es2019/plugins/paste/commands.js +210 -2
  15. package/dist/es2019/plugins/paste/pm-plugins/main.js +1 -1
  16. package/dist/es2019/plugins/toolbar-lists-indentation/ui/Toolbar.js +1 -1
  17. package/dist/es2019/plugins/toolbar-lists-indentation/ui/ToolbarDropdown.js +1 -1
  18. package/dist/es2019/version-wrapper.js +1 -1
  19. package/dist/es2019/version.json +1 -1
  20. package/dist/esm/plugins/help-dialog/ui/index.js +1 -2
  21. package/dist/esm/plugins/list/index.js +1 -1
  22. package/dist/esm/plugins/list/transforms.js +2 -219
  23. package/dist/esm/plugins/paste/commands.js +218 -1
  24. package/dist/esm/plugins/paste/pm-plugins/main.js +1 -1
  25. package/dist/esm/plugins/toolbar-lists-indentation/ui/Toolbar.js +1 -1
  26. package/dist/esm/plugins/toolbar-lists-indentation/ui/ToolbarDropdown.js +1 -1
  27. package/dist/esm/version-wrapper.js +1 -1
  28. package/dist/esm/version.json +1 -1
  29. package/dist/types/plugins/list/transforms.d.ts +0 -13
  30. package/dist/types/plugins/paste/commands.d.ts +14 -0
  31. package/dist/types/plugins/paste/index.d.ts +2 -0
  32. package/dist/types-ts4.5/plugins/list/transforms.d.ts +0 -13
  33. package/dist/types-ts4.5/plugins/paste/commands.d.ts +14 -0
  34. package/dist/types-ts4.5/plugins/paste/index.d.ts +2 -0
  35. package/package.json +2 -2
@@ -1,6 +1,11 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
1
3
  import { createCommand } from './pm-plugins/plugin-factory';
2
4
  import { PastePluginActionTypes as ActionTypes } from './actions';
3
-
5
+ import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
6
+ import { isListNode, mapChildren, mapSlice } from '@atlaskit/editor-common/utils';
7
+ import { EditorState } from '@atlaskit/editor-prosemirror/state';
8
+ import { autoJoin } from '@atlaskit/editor-prosemirror/commands';
4
9
  /**
5
10
  * Use this to register macro link positions during a paste operation, that you
6
11
  * want to track in a document over time, through any document changes.
@@ -28,4 +33,216 @@ export var stopTrackingPastedMacroPositions = function stopTrackingPastedMacroPo
28
33
  pastedMacroPositionKeys: pastedMacroPositionKeys
29
34
  };
30
35
  });
36
+ };
37
+
38
+ // matchers for text lists
39
+ var bullets = /^\s*[\*\-\u2022](\s+|\s+$)/;
40
+ var numbers = /^\s*\d[\.\)](\s+|$)/;
41
+ var getListType = function getListType(node, schema) {
42
+ if (!node.text) {
43
+ return null;
44
+ }
45
+ var _schema$nodes = schema.nodes,
46
+ bulletList = _schema$nodes.bulletList,
47
+ orderedList = _schema$nodes.orderedList;
48
+ return [{
49
+ node: bulletList,
50
+ matcher: bullets
51
+ }, {
52
+ node: orderedList,
53
+ matcher: numbers
54
+ }].reduce(function (lastMatch, listType) {
55
+ if (lastMatch) {
56
+ return lastMatch;
57
+ }
58
+ var match = node.text.match(listType.matcher);
59
+ return match ? [listType.node, match[0].length] : lastMatch;
60
+ }, null);
61
+ };
62
+ var extractListFromParagraph = function extractListFromParagraph(node, parent, schema) {
63
+ var _schema$nodes2 = schema.nodes,
64
+ hardBreak = _schema$nodes2.hardBreak,
65
+ bulletList = _schema$nodes2.bulletList,
66
+ orderedList = _schema$nodes2.orderedList;
67
+ var content = mapChildren(node.content, function (node) {
68
+ return node;
69
+ });
70
+ var listTypes = [bulletList, orderedList];
71
+
72
+ // wrap each line into a listItem and a containing list
73
+ var listified = content.map(function (child, index) {
74
+ var listMatch = getListType(child, schema);
75
+ var prevChild = index > 0 && content[index - 1];
76
+
77
+ // only extract list when preceded by a hardbreak
78
+ if (prevChild && prevChild.type !== hardBreak) {
79
+ return child;
80
+ }
81
+ if (!listMatch || !child.text) {
82
+ return child;
83
+ }
84
+ var _listMatch = _slicedToArray(listMatch, 2),
85
+ nodeType = _listMatch[0],
86
+ length = _listMatch[1];
87
+
88
+ // convert to list item
89
+ var newText = child.text.substr(length);
90
+ var listItemNode = schema.nodes.listItem.createAndFill(undefined, schema.nodes.paragraph.createChecked(undefined, newText.length ? schema.text(newText) : undefined));
91
+ if (!listItemNode) {
92
+ return child;
93
+ }
94
+ var newList = nodeType.createChecked(undefined, [listItemNode]);
95
+ // Check whether our new list is valid content in our current structure,
96
+ // otherwise dont convert.
97
+ if (parent && !parent.type.validContent(Fragment.from(newList))) {
98
+ return child;
99
+ }
100
+ return newList;
101
+ }).filter(function (child, idx, arr) {
102
+ // remove hardBreaks that have a list node on either side
103
+
104
+ // wasn't hardBreak, leave as-is
105
+ if (child.type !== hardBreak) {
106
+ return child;
107
+ }
108
+ if (idx > 0 && listTypes.indexOf(arr[idx - 1].type) > -1) {
109
+ // list node on the left
110
+ return null;
111
+ }
112
+ if (idx < arr.length - 1 && listTypes.indexOf(arr[idx + 1].type) > -1) {
113
+ // list node on the right
114
+ return null;
115
+ }
116
+ return child;
117
+ });
118
+
119
+ // try to join
120
+ var mockState = EditorState.create({
121
+ schema: schema
122
+ });
123
+ var joinedListsTr;
124
+ var mockDispatch = function mockDispatch(tr) {
125
+ joinedListsTr = tr;
126
+ };
127
+ autoJoin(function (state, dispatch) {
128
+ if (!dispatch) {
129
+ return false;
130
+ }
131
+
132
+ // Return false to prevent replaceWith from wrapping the text node in a paragraph
133
+ // paragraph since that will be done later. If it's done here, it will fail
134
+ // the paragraph.validContent check.
135
+ // Dont return false if there are lists, as they arent validContent for paragraphs
136
+ // and will result in hanging textNodes
137
+ var containsList = listified.some(function (node) {
138
+ return node.type === bulletList || node.type === orderedList;
139
+ });
140
+ if (listified.some(function (node) {
141
+ return node.isText;
142
+ }) && !containsList) {
143
+ return false;
144
+ }
145
+ dispatch(state.tr.replaceWith(0, 2, listified));
146
+ return true;
147
+ }, function (before, after) {
148
+ return isListNode(before) && isListNode(after);
149
+ })(mockState, mockDispatch);
150
+ var fragment = joinedListsTr ? joinedListsTr.doc.content : Fragment.from(listified);
151
+
152
+ // try to re-wrap fragment in paragraph (which is the original node we unwrapped)
153
+ var paragraph = schema.nodes.paragraph;
154
+ if (paragraph.validContent(fragment)) {
155
+ return Fragment.from(paragraph.create(node.attrs, fragment, node.marks));
156
+ }
157
+
158
+ // fragment now contains other nodes, get Prosemirror to wrap with ContentMatch later
159
+ return fragment;
160
+ };
161
+
162
+ // above will wrap everything in paragraphs for us
163
+ export var upgradeTextToLists = function upgradeTextToLists(slice, schema) {
164
+ return mapSlice(slice, function (node, parent) {
165
+ if (node.type === schema.nodes.paragraph) {
166
+ return extractListFromParagraph(node, parent, schema);
167
+ }
168
+ return node;
169
+ });
170
+ };
171
+ export var splitParagraphs = function splitParagraphs(slice, schema) {
172
+ // exclude Text nodes with a code mark, since we transform those later
173
+ // into a codeblock
174
+ var hasCodeMark = false;
175
+ slice.content.forEach(function (child) {
176
+ hasCodeMark = hasCodeMark || child.marks.some(function (mark) {
177
+ return mark.type === schema.marks.code;
178
+ });
179
+ });
180
+
181
+ // slice might just be a raw text string
182
+ if (schema.nodes.paragraph.validContent(slice.content) && !hasCodeMark) {
183
+ var replSlice = splitIntoParagraphs({
184
+ fragment: slice.content,
185
+ schema: schema
186
+ });
187
+ return new Slice(replSlice, slice.openStart + 1, slice.openEnd + 1);
188
+ }
189
+ return mapSlice(slice, function (node) {
190
+ if (node.type === schema.nodes.paragraph) {
191
+ return splitIntoParagraphs({
192
+ fragment: node.content,
193
+ blockMarks: node.marks,
194
+ schema: schema
195
+ });
196
+ }
197
+ return node;
198
+ });
199
+ };
200
+
201
+ /**
202
+ * Walks the slice, creating paragraphs that were previously separated by hardbreaks.
203
+ * Returns the original paragraph node (as a fragment), or a fragment containing multiple nodes.
204
+ */
205
+ export var splitIntoParagraphs = function splitIntoParagraphs(_ref) {
206
+ var fragment = _ref.fragment,
207
+ _ref$blockMarks = _ref.blockMarks,
208
+ blockMarks = _ref$blockMarks === void 0 ? [] : _ref$blockMarks,
209
+ schema = _ref.schema;
210
+ var paragraphs = [];
211
+ var curChildren = [];
212
+ var lastNode = null;
213
+ var _schema$nodes3 = schema.nodes,
214
+ hardBreak = _schema$nodes3.hardBreak,
215
+ paragraph = _schema$nodes3.paragraph;
216
+ fragment.forEach(function (node, i) {
217
+ var isNodeValidContentForParagraph = schema.nodes.paragraph.validContent(Fragment.from(node));
218
+ if (!isNodeValidContentForParagraph) {
219
+ paragraphs.push(node);
220
+ return;
221
+ }
222
+ // ED-14725 Fixed the issue that it make duplicated line
223
+ // when pasting <br /> from google docs.
224
+ if (i === 0 && node.type === hardBreak) {
225
+ paragraphs.push(paragraph.createChecked(undefined, curChildren, _toConsumableArray(blockMarks)));
226
+ lastNode = node;
227
+ return;
228
+ } else if (lastNode && lastNode.type === hardBreak && node.type === hardBreak) {
229
+ // double hardbreak
230
+
231
+ // backtrack a little; remove the trailing hardbreak we added last loop
232
+ curChildren.pop();
233
+
234
+ // create a new paragraph
235
+ paragraphs.push(paragraph.createChecked(undefined, curChildren, _toConsumableArray(blockMarks)));
236
+ curChildren = [];
237
+ return;
238
+ }
239
+
240
+ // add to this paragraph
241
+ curChildren.push(node);
242
+ lastNode = node;
243
+ });
244
+ if (curChildren.length) {
245
+ paragraphs.push(paragraph.createChecked(undefined, curChildren, _toConsumableArray(blockMarks)));
246
+ }
247
+ return Fragment.from(paragraphs.length ? paragraphs : [paragraph.createAndFill(undefined, undefined, _toConsumableArray(blockMarks))]);
31
248
  };
@@ -19,7 +19,7 @@ import { ACTION, analyticsPluginKey, INPUT_METHOD, PasteTypes } from '../../anal
19
19
  import { isInsideBlockQuote, insideTable, measurements } from '../../../utils';
20
20
  import { measureRender } from '@atlaskit/editor-common/utils';
21
21
  import { transformSliceToCorrectMediaWrapper, unwrapNestedMediaElements } from '../../media/utils/media-common';
22
- import { upgradeTextToLists, splitParagraphs } from '../../list/transforms';
22
+ import { upgradeTextToLists, splitParagraphs } from '../commands';
23
23
  import { md } from '@atlaskit/editor-common/paste';
24
24
  import { transformSliceToDecisionList } from '../../tasks-and-decisions/utils';
25
25
  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';
@@ -10,7 +10,7 @@ import { DropdownMenuWithKeyboardNavigation as DropdownMenu } from '@atlaskit/ed
10
10
  import ToolbarButton from '../../../ui/ToolbarButton';
11
11
  import { expandIconWrapperStyle, shortcutStyle } from '../../../ui/styles';
12
12
  import { wrapperStyle, separatorStyles } from '@atlaskit/editor-common/styles';
13
- import { messages as listMessages } from '../../list/messages';
13
+ import { listMessages } from '@atlaskit/editor-common/messages';
14
14
  import { messages as indentationMessages } from '../../indentation/messages';
15
15
  export function ToolbarDropdown(props) {
16
16
  var _useIntl = useIntl(),
@@ -1,5 +1,5 @@
1
1
  export var name = "@atlaskit/editor-core";
2
- export var version = "187.18.0";
2
+ export var version = "187.18.1";
3
3
  export var nextMajorVersion = function 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.18.0",
3
+ "version": "187.18.1",
4
4
  "sideEffects": false
5
5
  }
@@ -1,17 +1,4 @@
1
- import type { Schema, Mark } from '@atlaskit/editor-prosemirror/model';
2
- import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
3
1
  import type { Transaction, Selection } from '@atlaskit/editor-prosemirror/state';
4
2
  export declare function liftFollowingList(from: number, to: number, rootListDepth: number, tr: Transaction): Transaction;
5
3
  export declare function liftNodeSelectionList(selection: Selection, tr: Transaction): Transaction;
6
4
  export declare function liftTextSelectionList(selection: Selection, tr: Transaction): Transaction;
7
- /**
8
- * Walks the slice, creating paragraphs that were previously separated by hardbreaks.
9
- * Returns the original paragraph node (as a fragment), or a fragment containing multiple nodes.
10
- */
11
- export declare const splitIntoParagraphs: ({ fragment, blockMarks, schema, }: {
12
- fragment: Fragment;
13
- blockMarks?: readonly Mark[] | undefined;
14
- schema: Schema;
15
- }) => Fragment;
16
- export declare const splitParagraphs: (slice: Slice, schema: Schema) => Slice;
17
- export declare const upgradeTextToLists: (slice: Slice, schema: Schema) => Slice;
@@ -1,3 +1,6 @@
1
+ import type { Schema } from '@atlaskit/editor-prosemirror/model';
2
+ import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
3
+ import type { Mark } from '@atlaskit/editor-prosemirror/model';
1
4
  /**
2
5
  * Use this to register macro link positions during a paste operation, that you
3
6
  * want to track in a document over time, through any document changes.
@@ -14,3 +17,14 @@ export declare const startTrackingPastedMacroPositions: (pastedMacroPositions: {
14
17
  [key: string]: number;
15
18
  }) => import("@atlaskit/editor-common/types").Command;
16
19
  export declare const stopTrackingPastedMacroPositions: (pastedMacroPositionKeys: string[]) => import("@atlaskit/editor-common/types").Command;
20
+ export declare const upgradeTextToLists: (slice: Slice, schema: Schema) => Slice;
21
+ export declare const splitParagraphs: (slice: Slice, schema: Schema) => Slice;
22
+ /**
23
+ * Walks the slice, creating paragraphs that were previously separated by hardbreaks.
24
+ * Returns the original paragraph node (as a fragment), or a fragment containing multiple nodes.
25
+ */
26
+ export declare const splitIntoParagraphs: ({ fragment, blockMarks, schema, }: {
27
+ fragment: Fragment;
28
+ blockMarks?: readonly Mark[] | undefined;
29
+ schema: Schema;
30
+ }) => Fragment;
@@ -3,6 +3,7 @@ import type { CardOptions } from '@atlaskit/editor-common/card';
3
3
  import type featureFlagsPlugin from '@atlaskit/editor-plugin-feature-flags';
4
4
  import type { cardPlugin } from '@atlaskit/editor-plugin-card';
5
5
  import type betterTypeHistoryPlugin from '../better-type-history';
6
+ import type listPlugin from '../list';
6
7
  export type PastePluginOptions = {
7
8
  cardOptions?: CardOptions;
8
9
  sanitizePrivateContent?: boolean;
@@ -11,6 +12,7 @@ declare const pastePlugin: NextEditorPlugin<'paste', {
11
12
  pluginConfiguration: PastePluginOptions;
12
13
  dependencies: [
13
14
  typeof featureFlagsPlugin,
15
+ OptionalPlugin<typeof listPlugin>,
14
16
  typeof betterTypeHistoryPlugin,
15
17
  OptionalPlugin<typeof cardPlugin>
16
18
  ];
@@ -1,17 +1,4 @@
1
- import type { Schema, Mark } from '@atlaskit/editor-prosemirror/model';
2
- import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
3
1
  import type { Transaction, Selection } from '@atlaskit/editor-prosemirror/state';
4
2
  export declare function liftFollowingList(from: number, to: number, rootListDepth: number, tr: Transaction): Transaction;
5
3
  export declare function liftNodeSelectionList(selection: Selection, tr: Transaction): Transaction;
6
4
  export declare function liftTextSelectionList(selection: Selection, tr: Transaction): Transaction;
7
- /**
8
- * Walks the slice, creating paragraphs that were previously separated by hardbreaks.
9
- * Returns the original paragraph node (as a fragment), or a fragment containing multiple nodes.
10
- */
11
- export declare const splitIntoParagraphs: ({ fragment, blockMarks, schema, }: {
12
- fragment: Fragment;
13
- blockMarks?: readonly Mark[] | undefined;
14
- schema: Schema;
15
- }) => Fragment;
16
- export declare const splitParagraphs: (slice: Slice, schema: Schema) => Slice;
17
- export declare const upgradeTextToLists: (slice: Slice, schema: Schema) => Slice;
@@ -1,3 +1,6 @@
1
+ import type { Schema } from '@atlaskit/editor-prosemirror/model';
2
+ import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
3
+ import type { Mark } from '@atlaskit/editor-prosemirror/model';
1
4
  /**
2
5
  * Use this to register macro link positions during a paste operation, that you
3
6
  * want to track in a document over time, through any document changes.
@@ -14,3 +17,14 @@ export declare const startTrackingPastedMacroPositions: (pastedMacroPositions: {
14
17
  [key: string]: number;
15
18
  }) => import("@atlaskit/editor-common/types").Command;
16
19
  export declare const stopTrackingPastedMacroPositions: (pastedMacroPositionKeys: string[]) => import("@atlaskit/editor-common/types").Command;
20
+ export declare const upgradeTextToLists: (slice: Slice, schema: Schema) => Slice;
21
+ export declare const splitParagraphs: (slice: Slice, schema: Schema) => Slice;
22
+ /**
23
+ * Walks the slice, creating paragraphs that were previously separated by hardbreaks.
24
+ * Returns the original paragraph node (as a fragment), or a fragment containing multiple nodes.
25
+ */
26
+ export declare const splitIntoParagraphs: ({ fragment, blockMarks, schema, }: {
27
+ fragment: Fragment;
28
+ blockMarks?: readonly Mark[] | undefined;
29
+ schema: Schema;
30
+ }) => Fragment;
@@ -3,6 +3,7 @@ import type { CardOptions } from '@atlaskit/editor-common/card';
3
3
  import type featureFlagsPlugin from '@atlaskit/editor-plugin-feature-flags';
4
4
  import type { cardPlugin } from '@atlaskit/editor-plugin-card';
5
5
  import type betterTypeHistoryPlugin from '../better-type-history';
6
+ import type listPlugin from '../list';
6
7
  export type PastePluginOptions = {
7
8
  cardOptions?: CardOptions;
8
9
  sanitizePrivateContent?: boolean;
@@ -11,6 +12,7 @@ declare const pastePlugin: NextEditorPlugin<'paste', {
11
12
  pluginConfiguration: PastePluginOptions;
12
13
  dependencies: [
13
14
  typeof featureFlagsPlugin,
15
+ OptionalPlugin<typeof listPlugin>,
14
16
  typeof betterTypeHistoryPlugin,
15
17
  OptionalPlugin<typeof cardPlugin>
16
18
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-core",
3
- "version": "187.18.0",
3
+ "version": "187.18.1",
4
4
  "description": "A package contains Atlassian editor core functionality",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -55,7 +55,7 @@
55
55
  "@atlaskit/code": "^14.6.0",
56
56
  "@atlaskit/date": "^0.10.0",
57
57
  "@atlaskit/datetime-picker": "^12.7.0",
58
- "@atlaskit/editor-common": "^74.42.0",
58
+ "@atlaskit/editor-common": "^74.43.0",
59
59
  "@atlaskit/editor-json-transformer": "^8.10.0",
60
60
  "@atlaskit/editor-markdown-transformer": "^5.2.5",
61
61
  "@atlaskit/editor-palette": "1.5.1",