@atlaskit/editor-plugin-paste 1.5.5 → 1.5.7
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 +17 -0
- package/dist/cjs/commands.js +7 -111
- package/dist/cjs/util/index.js +9 -0
- package/dist/es2019/commands.js +3 -100
- package/dist/es2019/util/index.js +7 -0
- package/dist/esm/commands.js +6 -110
- package/dist/esm/util/index.js +9 -0
- package/dist/types/commands.d.ts +1 -1
- package/dist/types-ts4.5/commands.d.ts +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-paste
|
|
2
2
|
|
|
3
|
+
## 1.5.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#122612](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/122612)
|
|
8
|
+
[`01a85ce0a88ec`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/01a85ce0a88ec) -
|
|
9
|
+
[ux] ED-23705 Add logic to handle annotations on inline nodes when they are inserted or pasted.
|
|
10
|
+
Covers the following inline nodes: emoji, status, mention, date, inlineCard
|
|
11
|
+
|
|
12
|
+
## 1.5.6
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- [#121483](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/121483)
|
|
17
|
+
[`b73c87fcb17dd`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/b73c87fcb17dd) -
|
|
18
|
+
[ED-22946] Cleanup feature flag extractListFromParagraphV2
|
|
19
|
+
|
|
3
20
|
## 1.5.5
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
package/dist/cjs/commands.js
CHANGED
|
@@ -4,14 +4,13 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.upgradeTextToLists = exports.stopTrackingPastedMacroPositions = exports.startTrackingPastedMacroPositions = exports.splitParagraphs = exports.splitIntoParagraphs = exports.
|
|
7
|
+
exports.upgradeTextToLists = exports.stopTrackingPastedMacroPositions = exports.startTrackingPastedMacroPositions = exports.splitParagraphs = exports.splitIntoParagraphs = exports.extractListFromParagraph = exports._contentSplitByHardBreaks = void 0;
|
|
8
8
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
9
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
10
|
var _utils = require("@atlaskit/editor-common/utils");
|
|
11
11
|
var _commands = require("@atlaskit/editor-prosemirror/commands");
|
|
12
12
|
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
13
13
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
14
|
-
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
15
14
|
var _actions = require("./actions");
|
|
16
15
|
var _pluginFactory = require("./pm-plugins/plugin-factory");
|
|
17
16
|
/**
|
|
@@ -92,7 +91,7 @@ var _contentSplitByHardBreaks = exports._contentSplitByHardBreaks = function _co
|
|
|
92
91
|
wrapperContent.push(nextContent);
|
|
93
92
|
return wrapperContent;
|
|
94
93
|
};
|
|
95
|
-
var
|
|
94
|
+
var extractListFromParagraph = exports.extractListFromParagraph = function extractListFromParagraph(node, parent, schema) {
|
|
96
95
|
var content = (0, _utils.mapChildren)(node.content, function (node) {
|
|
97
96
|
return node;
|
|
98
97
|
});
|
|
@@ -148,7 +147,7 @@ var _extractListFromParagraphV2 = exports._extractListFromParagraphV2 = function
|
|
|
148
147
|
[schema.text(startingText, firstNonHardBreakNode === null || firstNonHardBreakNode === void 0 ? void 0 : firstNonHardBreakNode.marks)].concat((0, _toConsumableArray2.default)(chunksWithoutLeadingHardBreaks.slice(1))) : chunksWithoutLeadingHardBreaks.slice(1);
|
|
149
148
|
|
|
150
149
|
// convert to list
|
|
151
|
-
var listItemNode = listItem.createAndFill(undefined, paragraph.createChecked(undefined, restOfChunk));
|
|
150
|
+
var listItemNode = listItem === null || listItem === void 0 ? void 0 : listItem.createAndFill(undefined, paragraph.createChecked(undefined, restOfChunk));
|
|
152
151
|
if (!listItemNode) {
|
|
153
152
|
paragraphParts.push(line);
|
|
154
153
|
continue;
|
|
@@ -201,115 +200,12 @@ var _extractListFromParagraphV2 = exports._extractListFromParagraphV2 = function
|
|
|
201
200
|
var fragment = joinedListsTr ? joinedListsTr.doc.content : _model.Fragment.from(result);
|
|
202
201
|
return fragment;
|
|
203
202
|
};
|
|
204
|
-
var extractListFromParagraph = function extractListFromParagraph(node, parent, schema) {
|
|
205
|
-
var _schema$nodes3 = schema.nodes,
|
|
206
|
-
hardBreak = _schema$nodes3.hardBreak,
|
|
207
|
-
bulletList = _schema$nodes3.bulletList,
|
|
208
|
-
orderedList = _schema$nodes3.orderedList;
|
|
209
|
-
var content = (0, _utils.mapChildren)(node.content, function (node) {
|
|
210
|
-
return node;
|
|
211
|
-
});
|
|
212
|
-
var listTypes = [bulletList, orderedList];
|
|
213
|
-
|
|
214
|
-
// wrap each line into a listItem and a containing list
|
|
215
|
-
var listified = content.map(function (child, index) {
|
|
216
|
-
var listMatch = getListType(child, schema);
|
|
217
|
-
var prevChild = index > 0 && content[index - 1];
|
|
218
|
-
|
|
219
|
-
// only extract list when preceded by a hardbreak
|
|
220
|
-
if (prevChild && prevChild.type !== hardBreak) {
|
|
221
|
-
return child;
|
|
222
|
-
}
|
|
223
|
-
if (!listMatch || !child.text) {
|
|
224
|
-
return child;
|
|
225
|
-
}
|
|
226
|
-
var _listMatch3 = (0, _slicedToArray2.default)(listMatch, 2),
|
|
227
|
-
nodeType = _listMatch3[0],
|
|
228
|
-
length = _listMatch3[1];
|
|
229
|
-
|
|
230
|
-
// convert to list item
|
|
231
|
-
var newText = child.text.substr(length);
|
|
232
|
-
var listItemNode = schema.nodes.listItem.createAndFill(undefined, schema.nodes.paragraph.createChecked(undefined, newText.length ? schema.text(newText) : undefined));
|
|
233
|
-
if (!listItemNode) {
|
|
234
|
-
return child;
|
|
235
|
-
}
|
|
236
|
-
var newList = nodeType.createChecked(undefined, [listItemNode]);
|
|
237
|
-
// Check whether our new list is valid content in our current structure,
|
|
238
|
-
// otherwise dont convert.
|
|
239
|
-
if (parent && !parent.type.validContent(_model.Fragment.from(newList))) {
|
|
240
|
-
return child;
|
|
241
|
-
}
|
|
242
|
-
return newList;
|
|
243
|
-
}).filter(function (child, idx, arr) {
|
|
244
|
-
// remove hardBreaks that have a list node on either side
|
|
245
|
-
|
|
246
|
-
// wasn't hardBreak, leave as-is
|
|
247
|
-
if (child.type !== hardBreak) {
|
|
248
|
-
return child;
|
|
249
|
-
}
|
|
250
|
-
if (idx > 0 && listTypes.indexOf(arr[idx - 1].type) > -1) {
|
|
251
|
-
// list node on the left
|
|
252
|
-
return null;
|
|
253
|
-
}
|
|
254
|
-
if (idx < arr.length - 1 && listTypes.indexOf(arr[idx + 1].type) > -1) {
|
|
255
|
-
// list node on the right
|
|
256
|
-
return null;
|
|
257
|
-
}
|
|
258
|
-
return child;
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
// try to join
|
|
262
|
-
var mockState = _state.EditorState.create({
|
|
263
|
-
schema: schema
|
|
264
|
-
});
|
|
265
|
-
var joinedListsTr;
|
|
266
|
-
var mockDispatch = function mockDispatch(tr) {
|
|
267
|
-
joinedListsTr = tr;
|
|
268
|
-
};
|
|
269
|
-
(0, _commands.autoJoin)(function (state, dispatch) {
|
|
270
|
-
if (!dispatch) {
|
|
271
|
-
return false;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
// Return false to prevent replaceWith from wrapping the text node in a paragraph
|
|
275
|
-
// paragraph since that will be done later. If it's done here, it will fail
|
|
276
|
-
// the paragraph.validContent check.
|
|
277
|
-
// Dont return false if there are lists, as they arent validContent for paragraphs
|
|
278
|
-
// and will result in hanging textNodes
|
|
279
|
-
var containsList = listified.some(function (node) {
|
|
280
|
-
return node.type === bulletList || node.type === orderedList;
|
|
281
|
-
});
|
|
282
|
-
if (listified.some(function (node) {
|
|
283
|
-
return node.isText;
|
|
284
|
-
}) && !containsList) {
|
|
285
|
-
return false;
|
|
286
|
-
}
|
|
287
|
-
dispatch(state.tr.replaceWith(0, 2, listified));
|
|
288
|
-
return true;
|
|
289
|
-
}, function (before, after) {
|
|
290
|
-
return (0, _utils.isListNode)(before) && (0, _utils.isListNode)(after);
|
|
291
|
-
})(mockState, mockDispatch);
|
|
292
|
-
var fragment = joinedListsTr ? joinedListsTr.doc.content : _model.Fragment.from(listified);
|
|
293
|
-
|
|
294
|
-
// try to re-wrap fragment in paragraph (which is the original node we unwrapped)
|
|
295
|
-
var paragraph = schema.nodes.paragraph;
|
|
296
|
-
if (paragraph.validContent(fragment)) {
|
|
297
|
-
return _model.Fragment.from(paragraph.create(node.attrs, fragment, node.marks));
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
// fragment now contains other nodes, get Prosemirror to wrap with ContentMatch later
|
|
301
|
-
return fragment;
|
|
302
|
-
};
|
|
303
203
|
|
|
304
204
|
// above will wrap everything in paragraphs for us
|
|
305
205
|
var upgradeTextToLists = exports.upgradeTextToLists = function upgradeTextToLists(slice, schema) {
|
|
306
206
|
return (0, _utils.mapSlice)(slice, function (node, parent) {
|
|
307
207
|
if (node.type === schema.nodes.paragraph) {
|
|
308
|
-
|
|
309
|
-
return _extractListFromParagraphV2(node, parent, schema);
|
|
310
|
-
} else {
|
|
311
|
-
return extractListFromParagraph(node, parent, schema);
|
|
312
|
-
}
|
|
208
|
+
return extractListFromParagraph(node, parent, schema);
|
|
313
209
|
}
|
|
314
210
|
return node;
|
|
315
211
|
});
|
|
@@ -356,9 +252,9 @@ var splitIntoParagraphs = exports.splitIntoParagraphs = function splitIntoParagr
|
|
|
356
252
|
var paragraphs = [];
|
|
357
253
|
var curChildren = [];
|
|
358
254
|
var lastNode = null;
|
|
359
|
-
var _schema$
|
|
360
|
-
hardBreak = _schema$
|
|
361
|
-
paragraph = _schema$
|
|
255
|
+
var _schema$nodes3 = schema.nodes,
|
|
256
|
+
hardBreak = _schema$nodes3.hardBreak,
|
|
257
|
+
paragraph = _schema$nodes3.paragraph;
|
|
362
258
|
fragment.forEach(function (node, i) {
|
|
363
259
|
var isNodeValidContentForParagraph = schema.nodes.paragraph.validContent(_model.Fragment.from(node));
|
|
364
260
|
if (!isNodeValidContentForParagraph) {
|
package/dist/cjs/util/index.js
CHANGED
|
@@ -27,6 +27,7 @@ var _state = require("@atlaskit/editor-prosemirror/state");
|
|
|
27
27
|
var _utils2 = require("@atlaskit/editor-prosemirror/utils");
|
|
28
28
|
var _utils3 = require("@atlaskit/editor-tables/utils");
|
|
29
29
|
var _mediaClient = require("@atlaskit/media-client");
|
|
30
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
30
31
|
function isPastedFromWord(html) {
|
|
31
32
|
return !!html && html.indexOf('urn:schemas-microsoft-com:office:word') >= 0;
|
|
32
33
|
}
|
|
@@ -117,6 +118,14 @@ function applyTextMarksToSlice(schema, marks) {
|
|
|
117
118
|
}))).sort((0, _legacyRankPlugins.sortByOrderWithTypeName)('marks'));
|
|
118
119
|
return false;
|
|
119
120
|
}
|
|
121
|
+
if ((0, _platformFeatureFlags.fg)('editor_inline_comments_paste_insert_nodes')) {
|
|
122
|
+
if (node.isInline && ['inlineCard', 'emoji', 'status', 'date', 'mention'].includes(node.type.name) && parent && parent.isBlock) {
|
|
123
|
+
// @ts-ignore - [unblock prosemirror bump] assigning to readonly prop
|
|
124
|
+
node.marks = [].concat((0, _toConsumableArray2.default)(node.marks), (0, _toConsumableArray2.default)(parent.type.allowedMarks(marks).filter(function (mark) {
|
|
125
|
+
return mark.type === schema.marks.annotation;
|
|
126
|
+
})));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
120
129
|
return true;
|
|
121
130
|
});
|
|
122
131
|
return sliceCopy;
|
package/dist/es2019/commands.js
CHANGED
|
@@ -2,7 +2,6 @@ import { isListNode, mapChildren, mapSlice } from '@atlaskit/editor-common/utils
|
|
|
2
2
|
import { autoJoin } from '@atlaskit/editor-prosemirror/commands';
|
|
3
3
|
import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
|
|
4
4
|
import { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
5
|
-
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
6
5
|
import { PastePluginActionTypes as ActionTypes } from './actions';
|
|
7
6
|
import { createCommand } from './pm-plugins/plugin-factory';
|
|
8
7
|
|
|
@@ -81,7 +80,7 @@ export const _contentSplitByHardBreaks = (content, schema) => {
|
|
|
81
80
|
wrapperContent.push(nextContent);
|
|
82
81
|
return wrapperContent;
|
|
83
82
|
};
|
|
84
|
-
export const
|
|
83
|
+
export const extractListFromParagraph = (node, parent, schema) => {
|
|
85
84
|
const content = mapChildren(node.content, node => node);
|
|
86
85
|
const linesSplitByHardbreaks = _contentSplitByHardBreaks(content, schema);
|
|
87
86
|
const {
|
|
@@ -130,7 +129,7 @@ export const _extractListFromParagraphV2 = (node, parent, schema) => {
|
|
|
130
129
|
[schema.text(startingText, firstNonHardBreakNode === null || firstNonHardBreakNode === void 0 ? void 0 : firstNonHardBreakNode.marks), ...chunksWithoutLeadingHardBreaks.slice(1)] : chunksWithoutLeadingHardBreaks.slice(1);
|
|
131
130
|
|
|
132
131
|
// convert to list
|
|
133
|
-
const listItemNode = listItem.createAndFill(undefined, paragraph.createChecked(undefined, restOfChunk));
|
|
132
|
+
const listItemNode = listItem === null || listItem === void 0 ? void 0 : listItem.createAndFill(undefined, paragraph.createChecked(undefined, restOfChunk));
|
|
134
133
|
if (!listItemNode) {
|
|
135
134
|
paragraphParts.push(line);
|
|
136
135
|
continue;
|
|
@@ -177,108 +176,12 @@ export const _extractListFromParagraphV2 = (node, parent, schema) => {
|
|
|
177
176
|
const fragment = joinedListsTr ? joinedListsTr.doc.content : Fragment.from(result);
|
|
178
177
|
return fragment;
|
|
179
178
|
};
|
|
180
|
-
const extractListFromParagraph = (node, parent, schema) => {
|
|
181
|
-
const {
|
|
182
|
-
hardBreak,
|
|
183
|
-
bulletList,
|
|
184
|
-
orderedList
|
|
185
|
-
} = schema.nodes;
|
|
186
|
-
const content = mapChildren(node.content, node => node);
|
|
187
|
-
const listTypes = [bulletList, orderedList];
|
|
188
|
-
|
|
189
|
-
// wrap each line into a listItem and a containing list
|
|
190
|
-
const listified = content.map((child, index) => {
|
|
191
|
-
const listMatch = getListType(child, schema);
|
|
192
|
-
const prevChild = index > 0 && content[index - 1];
|
|
193
|
-
|
|
194
|
-
// only extract list when preceded by a hardbreak
|
|
195
|
-
if (prevChild && prevChild.type !== hardBreak) {
|
|
196
|
-
return child;
|
|
197
|
-
}
|
|
198
|
-
if (!listMatch || !child.text) {
|
|
199
|
-
return child;
|
|
200
|
-
}
|
|
201
|
-
const [nodeType, length] = listMatch;
|
|
202
|
-
|
|
203
|
-
// convert to list item
|
|
204
|
-
const newText = child.text.substr(length);
|
|
205
|
-
const listItemNode = schema.nodes.listItem.createAndFill(undefined, schema.nodes.paragraph.createChecked(undefined, newText.length ? schema.text(newText) : undefined));
|
|
206
|
-
if (!listItemNode) {
|
|
207
|
-
return child;
|
|
208
|
-
}
|
|
209
|
-
const newList = nodeType.createChecked(undefined, [listItemNode]);
|
|
210
|
-
// Check whether our new list is valid content in our current structure,
|
|
211
|
-
// otherwise dont convert.
|
|
212
|
-
if (parent && !parent.type.validContent(Fragment.from(newList))) {
|
|
213
|
-
return child;
|
|
214
|
-
}
|
|
215
|
-
return newList;
|
|
216
|
-
}).filter((child, idx, arr) => {
|
|
217
|
-
// remove hardBreaks that have a list node on either side
|
|
218
|
-
|
|
219
|
-
// wasn't hardBreak, leave as-is
|
|
220
|
-
if (child.type !== hardBreak) {
|
|
221
|
-
return child;
|
|
222
|
-
}
|
|
223
|
-
if (idx > 0 && listTypes.indexOf(arr[idx - 1].type) > -1) {
|
|
224
|
-
// list node on the left
|
|
225
|
-
return null;
|
|
226
|
-
}
|
|
227
|
-
if (idx < arr.length - 1 && listTypes.indexOf(arr[idx + 1].type) > -1) {
|
|
228
|
-
// list node on the right
|
|
229
|
-
return null;
|
|
230
|
-
}
|
|
231
|
-
return child;
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
// try to join
|
|
235
|
-
const mockState = EditorState.create({
|
|
236
|
-
schema
|
|
237
|
-
});
|
|
238
|
-
let joinedListsTr;
|
|
239
|
-
const mockDispatch = tr => {
|
|
240
|
-
joinedListsTr = tr;
|
|
241
|
-
};
|
|
242
|
-
autoJoin((state, dispatch) => {
|
|
243
|
-
if (!dispatch) {
|
|
244
|
-
return false;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
// Return false to prevent replaceWith from wrapping the text node in a paragraph
|
|
248
|
-
// paragraph since that will be done later. If it's done here, it will fail
|
|
249
|
-
// the paragraph.validContent check.
|
|
250
|
-
// Dont return false if there are lists, as they arent validContent for paragraphs
|
|
251
|
-
// and will result in hanging textNodes
|
|
252
|
-
const containsList = listified.some(node => node.type === bulletList || node.type === orderedList);
|
|
253
|
-
if (listified.some(node => node.isText) && !containsList) {
|
|
254
|
-
return false;
|
|
255
|
-
}
|
|
256
|
-
dispatch(state.tr.replaceWith(0, 2, listified));
|
|
257
|
-
return true;
|
|
258
|
-
}, (before, after) => isListNode(before) && isListNode(after))(mockState, mockDispatch);
|
|
259
|
-
const fragment = joinedListsTr ? joinedListsTr.doc.content : Fragment.from(listified);
|
|
260
|
-
|
|
261
|
-
// try to re-wrap fragment in paragraph (which is the original node we unwrapped)
|
|
262
|
-
const {
|
|
263
|
-
paragraph
|
|
264
|
-
} = schema.nodes;
|
|
265
|
-
if (paragraph.validContent(fragment)) {
|
|
266
|
-
return Fragment.from(paragraph.create(node.attrs, fragment, node.marks));
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
// fragment now contains other nodes, get Prosemirror to wrap with ContentMatch later
|
|
270
|
-
return fragment;
|
|
271
|
-
};
|
|
272
179
|
|
|
273
180
|
// above will wrap everything in paragraphs for us
|
|
274
181
|
export const upgradeTextToLists = (slice, schema) => {
|
|
275
182
|
return mapSlice(slice, (node, parent) => {
|
|
276
183
|
if (node.type === schema.nodes.paragraph) {
|
|
277
|
-
|
|
278
|
-
return _extractListFromParagraphV2(node, parent, schema);
|
|
279
|
-
} else {
|
|
280
|
-
return extractListFromParagraph(node, parent, schema);
|
|
281
|
-
}
|
|
184
|
+
return extractListFromParagraph(node, parent, schema);
|
|
282
185
|
}
|
|
283
186
|
return node;
|
|
284
187
|
});
|
|
@@ -6,6 +6,7 @@ import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state
|
|
|
6
6
|
import { findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
7
7
|
import { getSelectedTableInfo, isTableSelected } from '@atlaskit/editor-tables/utils';
|
|
8
8
|
import { isMediaBlobUrl } from '@atlaskit/media-client';
|
|
9
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
9
10
|
export function isPastedFromWord(html) {
|
|
10
11
|
return !!html && html.indexOf('urn:schemas-microsoft-com:office:word') >= 0;
|
|
11
12
|
}
|
|
@@ -98,6 +99,12 @@ export function applyTextMarksToSlice(schema, marks) {
|
|
|
98
99
|
...parent.type.allowedMarks(marks).filter(mark => mark.type !== linkMark)].sort(sortByOrderWithTypeName('marks'));
|
|
99
100
|
return false;
|
|
100
101
|
}
|
|
102
|
+
if (fg('editor_inline_comments_paste_insert_nodes')) {
|
|
103
|
+
if (node.isInline && ['inlineCard', 'emoji', 'status', 'date', 'mention'].includes(node.type.name) && parent && parent.isBlock) {
|
|
104
|
+
// @ts-ignore - [unblock prosemirror bump] assigning to readonly prop
|
|
105
|
+
node.marks = [...node.marks, ...parent.type.allowedMarks(marks).filter(mark => mark.type === schema.marks.annotation)];
|
|
106
|
+
}
|
|
107
|
+
}
|
|
101
108
|
return true;
|
|
102
109
|
});
|
|
103
110
|
return sliceCopy;
|
package/dist/esm/commands.js
CHANGED
|
@@ -4,7 +4,6 @@ import { isListNode, mapChildren, mapSlice } from '@atlaskit/editor-common/utils
|
|
|
4
4
|
import { autoJoin } from '@atlaskit/editor-prosemirror/commands';
|
|
5
5
|
import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
|
|
6
6
|
import { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
7
|
-
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
8
7
|
import { PastePluginActionTypes as ActionTypes } from './actions';
|
|
9
8
|
import { createCommand } from './pm-plugins/plugin-factory';
|
|
10
9
|
|
|
@@ -86,7 +85,7 @@ export var _contentSplitByHardBreaks = function _contentSplitByHardBreaks(conten
|
|
|
86
85
|
wrapperContent.push(nextContent);
|
|
87
86
|
return wrapperContent;
|
|
88
87
|
};
|
|
89
|
-
export var
|
|
88
|
+
export var extractListFromParagraph = function extractListFromParagraph(node, parent, schema) {
|
|
90
89
|
var content = mapChildren(node.content, function (node) {
|
|
91
90
|
return node;
|
|
92
91
|
});
|
|
@@ -142,7 +141,7 @@ export var _extractListFromParagraphV2 = function _extractListFromParagraphV2(no
|
|
|
142
141
|
[schema.text(startingText, firstNonHardBreakNode === null || firstNonHardBreakNode === void 0 ? void 0 : firstNonHardBreakNode.marks)].concat(_toConsumableArray(chunksWithoutLeadingHardBreaks.slice(1))) : chunksWithoutLeadingHardBreaks.slice(1);
|
|
143
142
|
|
|
144
143
|
// convert to list
|
|
145
|
-
var listItemNode = listItem.createAndFill(undefined, paragraph.createChecked(undefined, restOfChunk));
|
|
144
|
+
var listItemNode = listItem === null || listItem === void 0 ? void 0 : listItem.createAndFill(undefined, paragraph.createChecked(undefined, restOfChunk));
|
|
146
145
|
if (!listItemNode) {
|
|
147
146
|
paragraphParts.push(line);
|
|
148
147
|
continue;
|
|
@@ -195,115 +194,12 @@ export var _extractListFromParagraphV2 = function _extractListFromParagraphV2(no
|
|
|
195
194
|
var fragment = joinedListsTr ? joinedListsTr.doc.content : Fragment.from(result);
|
|
196
195
|
return fragment;
|
|
197
196
|
};
|
|
198
|
-
var extractListFromParagraph = function extractListFromParagraph(node, parent, schema) {
|
|
199
|
-
var _schema$nodes3 = schema.nodes,
|
|
200
|
-
hardBreak = _schema$nodes3.hardBreak,
|
|
201
|
-
bulletList = _schema$nodes3.bulletList,
|
|
202
|
-
orderedList = _schema$nodes3.orderedList;
|
|
203
|
-
var content = mapChildren(node.content, function (node) {
|
|
204
|
-
return node;
|
|
205
|
-
});
|
|
206
|
-
var listTypes = [bulletList, orderedList];
|
|
207
|
-
|
|
208
|
-
// wrap each line into a listItem and a containing list
|
|
209
|
-
var listified = content.map(function (child, index) {
|
|
210
|
-
var listMatch = getListType(child, schema);
|
|
211
|
-
var prevChild = index > 0 && content[index - 1];
|
|
212
|
-
|
|
213
|
-
// only extract list when preceded by a hardbreak
|
|
214
|
-
if (prevChild && prevChild.type !== hardBreak) {
|
|
215
|
-
return child;
|
|
216
|
-
}
|
|
217
|
-
if (!listMatch || !child.text) {
|
|
218
|
-
return child;
|
|
219
|
-
}
|
|
220
|
-
var _listMatch3 = _slicedToArray(listMatch, 2),
|
|
221
|
-
nodeType = _listMatch3[0],
|
|
222
|
-
length = _listMatch3[1];
|
|
223
|
-
|
|
224
|
-
// convert to list item
|
|
225
|
-
var newText = child.text.substr(length);
|
|
226
|
-
var listItemNode = schema.nodes.listItem.createAndFill(undefined, schema.nodes.paragraph.createChecked(undefined, newText.length ? schema.text(newText) : undefined));
|
|
227
|
-
if (!listItemNode) {
|
|
228
|
-
return child;
|
|
229
|
-
}
|
|
230
|
-
var newList = nodeType.createChecked(undefined, [listItemNode]);
|
|
231
|
-
// Check whether our new list is valid content in our current structure,
|
|
232
|
-
// otherwise dont convert.
|
|
233
|
-
if (parent && !parent.type.validContent(Fragment.from(newList))) {
|
|
234
|
-
return child;
|
|
235
|
-
}
|
|
236
|
-
return newList;
|
|
237
|
-
}).filter(function (child, idx, arr) {
|
|
238
|
-
// remove hardBreaks that have a list node on either side
|
|
239
|
-
|
|
240
|
-
// wasn't hardBreak, leave as-is
|
|
241
|
-
if (child.type !== hardBreak) {
|
|
242
|
-
return child;
|
|
243
|
-
}
|
|
244
|
-
if (idx > 0 && listTypes.indexOf(arr[idx - 1].type) > -1) {
|
|
245
|
-
// list node on the left
|
|
246
|
-
return null;
|
|
247
|
-
}
|
|
248
|
-
if (idx < arr.length - 1 && listTypes.indexOf(arr[idx + 1].type) > -1) {
|
|
249
|
-
// list node on the right
|
|
250
|
-
return null;
|
|
251
|
-
}
|
|
252
|
-
return child;
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
// try to join
|
|
256
|
-
var mockState = EditorState.create({
|
|
257
|
-
schema: schema
|
|
258
|
-
});
|
|
259
|
-
var joinedListsTr;
|
|
260
|
-
var mockDispatch = function mockDispatch(tr) {
|
|
261
|
-
joinedListsTr = tr;
|
|
262
|
-
};
|
|
263
|
-
autoJoin(function (state, dispatch) {
|
|
264
|
-
if (!dispatch) {
|
|
265
|
-
return false;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
// Return false to prevent replaceWith from wrapping the text node in a paragraph
|
|
269
|
-
// paragraph since that will be done later. If it's done here, it will fail
|
|
270
|
-
// the paragraph.validContent check.
|
|
271
|
-
// Dont return false if there are lists, as they arent validContent for paragraphs
|
|
272
|
-
// and will result in hanging textNodes
|
|
273
|
-
var containsList = listified.some(function (node) {
|
|
274
|
-
return node.type === bulletList || node.type === orderedList;
|
|
275
|
-
});
|
|
276
|
-
if (listified.some(function (node) {
|
|
277
|
-
return node.isText;
|
|
278
|
-
}) && !containsList) {
|
|
279
|
-
return false;
|
|
280
|
-
}
|
|
281
|
-
dispatch(state.tr.replaceWith(0, 2, listified));
|
|
282
|
-
return true;
|
|
283
|
-
}, function (before, after) {
|
|
284
|
-
return isListNode(before) && isListNode(after);
|
|
285
|
-
})(mockState, mockDispatch);
|
|
286
|
-
var fragment = joinedListsTr ? joinedListsTr.doc.content : Fragment.from(listified);
|
|
287
|
-
|
|
288
|
-
// try to re-wrap fragment in paragraph (which is the original node we unwrapped)
|
|
289
|
-
var paragraph = schema.nodes.paragraph;
|
|
290
|
-
if (paragraph.validContent(fragment)) {
|
|
291
|
-
return Fragment.from(paragraph.create(node.attrs, fragment, node.marks));
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
// fragment now contains other nodes, get Prosemirror to wrap with ContentMatch later
|
|
295
|
-
return fragment;
|
|
296
|
-
};
|
|
297
197
|
|
|
298
198
|
// above will wrap everything in paragraphs for us
|
|
299
199
|
export var upgradeTextToLists = function upgradeTextToLists(slice, schema) {
|
|
300
200
|
return mapSlice(slice, function (node, parent) {
|
|
301
201
|
if (node.type === schema.nodes.paragraph) {
|
|
302
|
-
|
|
303
|
-
return _extractListFromParagraphV2(node, parent, schema);
|
|
304
|
-
} else {
|
|
305
|
-
return extractListFromParagraph(node, parent, schema);
|
|
306
|
-
}
|
|
202
|
+
return extractListFromParagraph(node, parent, schema);
|
|
307
203
|
}
|
|
308
204
|
return node;
|
|
309
205
|
});
|
|
@@ -350,9 +246,9 @@ export var splitIntoParagraphs = function splitIntoParagraphs(_ref) {
|
|
|
350
246
|
var paragraphs = [];
|
|
351
247
|
var curChildren = [];
|
|
352
248
|
var lastNode = null;
|
|
353
|
-
var _schema$
|
|
354
|
-
hardBreak = _schema$
|
|
355
|
-
paragraph = _schema$
|
|
249
|
+
var _schema$nodes3 = schema.nodes,
|
|
250
|
+
hardBreak = _schema$nodes3.hardBreak,
|
|
251
|
+
paragraph = _schema$nodes3.paragraph;
|
|
356
252
|
fragment.forEach(function (node, i) {
|
|
357
253
|
var isNodeValidContentForParagraph = schema.nodes.paragraph.validContent(Fragment.from(node));
|
|
358
254
|
if (!isNodeValidContentForParagraph) {
|
package/dist/esm/util/index.js
CHANGED
|
@@ -7,6 +7,7 @@ import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state
|
|
|
7
7
|
import { findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
8
8
|
import { getSelectedTableInfo, isTableSelected } from '@atlaskit/editor-tables/utils';
|
|
9
9
|
import { isMediaBlobUrl } from '@atlaskit/media-client';
|
|
10
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
10
11
|
export function isPastedFromWord(html) {
|
|
11
12
|
return !!html && html.indexOf('urn:schemas-microsoft-com:office:word') >= 0;
|
|
12
13
|
}
|
|
@@ -97,6 +98,14 @@ export function applyTextMarksToSlice(schema, marks) {
|
|
|
97
98
|
}))).sort(sortByOrderWithTypeName('marks'));
|
|
98
99
|
return false;
|
|
99
100
|
}
|
|
101
|
+
if (fg('editor_inline_comments_paste_insert_nodes')) {
|
|
102
|
+
if (node.isInline && ['inlineCard', 'emoji', 'status', 'date', 'mention'].includes(node.type.name) && parent && parent.isBlock) {
|
|
103
|
+
// @ts-ignore - [unblock prosemirror bump] assigning to readonly prop
|
|
104
|
+
node.marks = [].concat(_toConsumableArray(node.marks), _toConsumableArray(parent.type.allowedMarks(marks).filter(function (mark) {
|
|
105
|
+
return mark.type === schema.marks.annotation;
|
|
106
|
+
})));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
100
109
|
return true;
|
|
101
110
|
});
|
|
102
111
|
return sliceCopy;
|
package/dist/types/commands.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export declare const startTrackingPastedMacroPositions: (pastedMacroPositions: {
|
|
|
17
17
|
}) => import("@atlaskit/editor-common/types").Command;
|
|
18
18
|
export declare const stopTrackingPastedMacroPositions: (pastedMacroPositionKeys: string[]) => import("@atlaskit/editor-common/types").Command;
|
|
19
19
|
export declare const _contentSplitByHardBreaks: (content: Array<Node>, schema: Schema) => Array<Node>[];
|
|
20
|
-
export declare const
|
|
20
|
+
export declare const extractListFromParagraph: (node: Node, parent: Node | null, schema: Schema) => Fragment;
|
|
21
21
|
export declare const upgradeTextToLists: (slice: Slice, schema: Schema) => Slice;
|
|
22
22
|
export declare const splitParagraphs: (slice: Slice, schema: Schema) => Slice;
|
|
23
23
|
/**
|
|
@@ -17,7 +17,7 @@ export declare const startTrackingPastedMacroPositions: (pastedMacroPositions: {
|
|
|
17
17
|
}) => import("@atlaskit/editor-common/types").Command;
|
|
18
18
|
export declare const stopTrackingPastedMacroPositions: (pastedMacroPositionKeys: string[]) => import("@atlaskit/editor-common/types").Command;
|
|
19
19
|
export declare const _contentSplitByHardBreaks: (content: Array<Node>, schema: Schema) => Array<Node>[];
|
|
20
|
-
export declare const
|
|
20
|
+
export declare const extractListFromParagraph: (node: Node, parent: Node | null, schema: Schema) => Fragment;
|
|
21
21
|
export declare const upgradeTextToLists: (slice: Slice, schema: Schema) => Slice;
|
|
22
22
|
export declare const splitParagraphs: (slice: Slice, schema: Schema) => Slice;
|
|
23
23
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-paste",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.7",
|
|
4
4
|
"description": "Paste plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
".": "./src/index.ts"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@atlaskit/editor-common": "^86.
|
|
36
|
+
"@atlaskit/editor-common": "^86.4.0",
|
|
37
37
|
"@atlaskit/editor-markdown-transformer": "^5.8.0",
|
|
38
38
|
"@atlaskit/editor-plugin-analytics": "^1.4.0",
|
|
39
39
|
"@atlaskit/editor-plugin-annotation": "^1.15.0",
|
|
@@ -128,10 +128,10 @@
|
|
|
128
128
|
"platform.editor.multi-bodied-extension_0rygg": {
|
|
129
129
|
"type": "boolean"
|
|
130
130
|
},
|
|
131
|
-
"platform.editor.
|
|
131
|
+
"platform.editor.preserve-whitespace-clipboard-text-serialization": {
|
|
132
132
|
"type": "boolean"
|
|
133
133
|
},
|
|
134
|
-
"
|
|
134
|
+
"editor_inline_comments_paste_insert_nodes": {
|
|
135
135
|
"type": "boolean"
|
|
136
136
|
}
|
|
137
137
|
}
|