@atlaskit/editor-core 187.18.0 → 187.18.2
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.
- package/CHANGELOG.md +14 -0
- package/dist/cjs/labs/next/presets/universal.js +2 -1
- package/dist/cjs/plugins/help-dialog/ui/index.js +26 -27
- package/dist/cjs/plugins/index.js +0 -7
- package/dist/cjs/plugins/list/index.js +5 -5
- package/dist/cjs/plugins/list/transforms.js +1 -223
- package/dist/cjs/plugins/paste/commands.js +224 -2
- package/dist/cjs/plugins/paste/pm-plugins/main.js +5 -9
- package/dist/cjs/plugins/toolbar-lists-indentation/ui/Toolbar.js +3 -3
- package/dist/cjs/plugins/toolbar-lists-indentation/ui/ToolbarDropdown.js +4 -4
- package/dist/cjs/utils/clipboard.js +5 -27
- package/dist/cjs/version-wrapper.js +1 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/labs/next/presets/universal.js +2 -1
- package/dist/es2019/plugins/help-dialog/ui/index.js +1 -2
- package/dist/es2019/plugins/index.js +0 -1
- package/dist/es2019/plugins/list/index.js +1 -1
- package/dist/es2019/plugins/list/transforms.js +2 -210
- package/dist/es2019/plugins/paste/commands.js +210 -2
- package/dist/es2019/plugins/paste/pm-plugins/main.js +3 -3
- package/dist/es2019/plugins/toolbar-lists-indentation/ui/Toolbar.js +1 -1
- package/dist/es2019/plugins/toolbar-lists-indentation/ui/ToolbarDropdown.js +1 -1
- package/dist/es2019/utils/clipboard.js +0 -16
- package/dist/es2019/version-wrapper.js +1 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/labs/next/presets/universal.js +2 -1
- package/dist/esm/plugins/help-dialog/ui/index.js +1 -2
- package/dist/esm/plugins/index.js +0 -1
- package/dist/esm/plugins/list/index.js +1 -1
- package/dist/esm/plugins/list/transforms.js +2 -219
- package/dist/esm/plugins/paste/commands.js +218 -1
- package/dist/esm/plugins/paste/pm-plugins/main.js +3 -3
- package/dist/esm/plugins/toolbar-lists-indentation/ui/Toolbar.js +1 -1
- package/dist/esm/plugins/toolbar-lists-indentation/ui/ToolbarDropdown.js +1 -1
- package/dist/esm/utils/clipboard.js +4 -23
- package/dist/esm/version-wrapper.js +1 -1
- package/dist/esm/version.json +1 -1
- package/dist/types/plugins/index.d.ts +0 -1
- package/dist/types/plugins/insert-block/index.d.ts +1 -1
- package/dist/types/plugins/list/transforms.d.ts +0 -13
- package/dist/types/plugins/paste/commands.d.ts +14 -0
- package/dist/types/plugins/paste/index.d.ts +2 -0
- package/dist/types/utils/clipboard.d.ts +0 -3
- package/dist/types-ts4.5/plugins/index.d.ts +0 -1
- package/dist/types-ts4.5/plugins/insert-block/index.d.ts +1 -1
- package/dist/types-ts4.5/plugins/list/transforms.d.ts +0 -13
- package/dist/types-ts4.5/plugins/paste/commands.d.ts +14 -0
- package/dist/types-ts4.5/plugins/paste/index.d.ts +2 -0
- package/dist/types-ts4.5/utils/clipboard.d.ts +0 -3
- package/package.json +4 -3
- package/dist/cjs/plugins/image-upload/index.js +0 -45
- package/dist/cjs/plugins/image-upload/pm-plugins/actions.js +0 -19
- package/dist/cjs/plugins/image-upload/pm-plugins/commands-toolbar.js +0 -19
- package/dist/cjs/plugins/image-upload/pm-plugins/commands.js +0 -40
- package/dist/cjs/plugins/image-upload/pm-plugins/input-rule.js +0 -31
- package/dist/cjs/plugins/image-upload/pm-plugins/main.js +0 -194
- package/dist/cjs/plugins/image-upload/pm-plugins/plugin-key.js +0 -9
- package/dist/cjs/plugins/image-upload/types.js +0 -5
- package/dist/cjs/plugins/image-upload/utils.js +0 -40
- package/dist/cjs/utils/drag-drop.js +0 -19
- package/dist/es2019/plugins/image-upload/index.js +0 -34
- package/dist/es2019/plugins/image-upload/pm-plugins/actions.js +0 -8
- package/dist/es2019/plugins/image-upload/pm-plugins/commands-toolbar.js +0 -12
- package/dist/es2019/plugins/image-upload/pm-plugins/commands.js +0 -28
- package/dist/es2019/plugins/image-upload/pm-plugins/input-rule.js +0 -25
- package/dist/es2019/plugins/image-upload/pm-plugins/main.js +0 -159
- package/dist/es2019/plugins/image-upload/pm-plugins/plugin-key.js +0 -2
- package/dist/es2019/plugins/image-upload/types.js +0 -1
- package/dist/es2019/plugins/image-upload/utils.js +0 -38
- package/dist/es2019/utils/drag-drop.js +0 -9
- package/dist/esm/plugins/image-upload/index.js +0 -37
- package/dist/esm/plugins/image-upload/pm-plugins/actions.js +0 -12
- package/dist/esm/plugins/image-upload/pm-plugins/commands-toolbar.js +0 -12
- package/dist/esm/plugins/image-upload/pm-plugins/commands.js +0 -32
- package/dist/esm/plugins/image-upload/pm-plugins/input-rule.js +0 -23
- package/dist/esm/plugins/image-upload/pm-plugins/main.js +0 -186
- package/dist/esm/plugins/image-upload/pm-plugins/plugin-key.js +0 -2
- package/dist/esm/plugins/image-upload/types.js +0 -1
- package/dist/esm/plugins/image-upload/utils.js +0 -31
- package/dist/esm/utils/drag-drop.js +0 -11
- package/dist/types/plugins/image-upload/index.d.ts +0 -16
- package/dist/types/plugins/image-upload/pm-plugins/actions.d.ts +0 -3
- package/dist/types/plugins/image-upload/pm-plugins/commands-toolbar.d.ts +0 -3
- package/dist/types/plugins/image-upload/pm-plugins/commands.d.ts +0 -5
- package/dist/types/plugins/image-upload/pm-plugins/input-rule.d.ts +0 -5
- package/dist/types/plugins/image-upload/pm-plugins/main.d.ts +0 -4
- package/dist/types/plugins/image-upload/pm-plugins/plugin-key.d.ts +0 -3
- package/dist/types/plugins/image-upload/types.d.ts +0 -18
- package/dist/types/plugins/image-upload/utils.d.ts +0 -5
- package/dist/types/utils/drag-drop.d.ts +0 -2
- package/dist/types-ts4.5/plugins/image-upload/index.d.ts +0 -16
- package/dist/types-ts4.5/plugins/image-upload/pm-plugins/actions.d.ts +0 -3
- package/dist/types-ts4.5/plugins/image-upload/pm-plugins/commands-toolbar.d.ts +0 -3
- package/dist/types-ts4.5/plugins/image-upload/pm-plugins/commands.d.ts +0 -5
- package/dist/types-ts4.5/plugins/image-upload/pm-plugins/input-rule.d.ts +0 -5
- package/dist/types-ts4.5/plugins/image-upload/pm-plugins/main.d.ts +0 -4
- package/dist/types-ts4.5/plugins/image-upload/pm-plugins/plugin-key.d.ts +0 -3
- package/dist/types-ts4.5/plugins/image-upload/types.d.ts +0 -18
- package/dist/types-ts4.5/plugins/image-upload/utils.d.ts +0 -5
- package/dist/types-ts4.5/utils/drag-drop.d.ts +0 -2
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { Fragment, NodeRange, Slice } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
-
import {
|
|
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
|
+
}
|
|
@@ -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
|
+
};
|
|
@@ -5,7 +5,7 @@ import { MarkdownTransformer } from '@atlaskit/editor-markdown-transformer';
|
|
|
5
5
|
import { addLinkMetadata } from '@atlaskit/editor-common/card';
|
|
6
6
|
import { mapChildren } from '../../../utils/slice';
|
|
7
7
|
import { getExtensionAutoConvertersFromProvider } from '@atlaskit/editor-common/extensions';
|
|
8
|
-
import
|
|
8
|
+
import { isPastedFile as isPastedFileFromEvent } from '@atlaskit/editor-common/paste';
|
|
9
9
|
import { transformSliceForMedia } from '../../media/utils/media-single';
|
|
10
10
|
import { escapeLinks, htmlContainsSingleFile, isPastedFromWord, isPastedFromExcel, htmlHasInvalidLinkTags, removeDuplicateInvalidLinks, transformUnsupportedBlockCardToInline } from '../util';
|
|
11
11
|
import { linkifyContent } from '@atlaskit/editor-common/utils';
|
|
@@ -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 '
|
|
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';
|
|
@@ -95,7 +95,7 @@ export function createPlugin(schema, dispatchAnalyticsEvent, dispatch, featureFl
|
|
|
95
95
|
if ((_text = text) !== null && _text !== void 0 && _text.includes('\r')) {
|
|
96
96
|
text = text.replace(/\r/g, '');
|
|
97
97
|
}
|
|
98
|
-
const isPastedFile =
|
|
98
|
+
const isPastedFile = isPastedFileFromEvent(event);
|
|
99
99
|
const isPlainText = text && !html;
|
|
100
100
|
const isRichText = !!html;
|
|
101
101
|
|
|
@@ -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 '
|
|
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 {
|
|
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,20 +1,4 @@
|
|
|
1
1
|
import * as clipboard from 'clipboard-polyfill';
|
|
2
|
-
export function checkClipboardTypes(type, item) {
|
|
3
|
-
const isDOMStringList = t => !t.indexOf && !!t.contains;
|
|
4
|
-
return isDOMStringList(type) ? type.contains(item) : type.indexOf(item) > -1;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
// Typeguard Function
|
|
8
|
-
export const isClipboardEvent = event => 'clipboardData' in event;
|
|
9
|
-
export function isPastedFile(rawEvent) {
|
|
10
|
-
const {
|
|
11
|
-
clipboardData
|
|
12
|
-
} = rawEvent;
|
|
13
|
-
if (!clipboardData) {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
return checkClipboardTypes(clipboardData.types, 'Files');
|
|
17
|
-
}
|
|
18
2
|
const isClipboardApiSupported = () => !!navigator.clipboard && typeof navigator.clipboard.writeText === 'function';
|
|
19
3
|
const isIEClipboardApiSupported = () => window.clipboardData && typeof window.clipboardData.setData === 'function';
|
|
20
4
|
export const copyToClipboard = async textToCopy => {
|
package/dist/es2019/version.json
CHANGED
|
@@ -3,7 +3,8 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
|
3
3
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
4
4
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
5
5
|
import { createEditorSelectionAPI } from '../../../selection-api/api';
|
|
6
|
-
import { breakoutPlugin, collabEditPlugin, dataConsumerMarkPlugin, datePlugin, emojiPlugin, extensionPlugin, fragmentMarkPlugin, helpDialogPlugin,
|
|
6
|
+
import { breakoutPlugin, collabEditPlugin, dataConsumerMarkPlugin, datePlugin, emojiPlugin, extensionPlugin, fragmentMarkPlugin, helpDialogPlugin, insertBlockPlugin, jiraIssuePlugin, layoutPlugin, listPlugin, toolbarListsIndentationPlugin, macroPlugin, maxContentSizePlugin, mediaPlugin, mentionsPlugin, panelPlugin, placeholderTextPlugin, rulePlugin, saveOnEnterPlugin, tasksAndDecisionsPlugin, textColorPlugin, statusPlugin, alignmentPlugin, indentationPlugin, customAutoformatPlugin, feedbackDialogPlugin, historyPlugin, expandPlugin, isExpandInsertionEnabled, scrollIntoViewPlugin, mobileDimensionsPlugin, findReplacePlugin, mobileSelectionPlugin, annotationPlugin, captionPlugin, avatarGroupPlugin, viewUpdateSubscriptionPlugin, beforePrimaryToolbarPlugin, codeBidiWarningPlugin, copyButtonPlugin, borderPlugin } from '../../../plugins';
|
|
7
|
+
import { imageUploadPlugin } from '@atlaskit/editor-plugin-image-upload';
|
|
7
8
|
import { guidelinePlugin } from '@atlaskit/editor-plugin-guideline';
|
|
8
9
|
import { contextPanelPlugin } from '@atlaskit/editor-plugin-context-panel';
|
|
9
10
|
import { gridPlugin } from '@atlaskit/editor-plugin-grid';
|
|
@@ -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';
|
|
@@ -10,7 +10,6 @@ export { default as emojiPlugin } from './emoji';
|
|
|
10
10
|
export { default as extensionPlugin } from './extension';
|
|
11
11
|
export { default as fakeTextCursorPlugin } from './fake-text-cursor';
|
|
12
12
|
export { default as helpDialogPlugin } from './help-dialog';
|
|
13
|
-
export { default as imageUploadPlugin } from './image-upload';
|
|
14
13
|
export { default as insertBlockPlugin } from './insert-block';
|
|
15
14
|
export { default as jiraIssuePlugin } from './jira-issue';
|
|
16
15
|
export { default as layoutPlugin } from './layout';
|
|
@@ -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 '
|
|
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';
|