@atlaskit/editor-plugin-block-menu 3.1.4 → 3.1.6
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 +16 -0
- package/dist/cjs/editor-commands/transforms/container-transforms.js +10 -6
- package/dist/cjs/editor-commands/transforms/inline-node-transforms.js +14 -4
- package/dist/cjs/editor-commands/transforms/layout/utils.js +10 -8
- package/dist/cjs/editor-commands/transforms/list/transformOrderedUnorderedListToBlockNodes.js +71 -29
- package/dist/cjs/ui/copy-block.js +17 -1
- package/dist/es2019/editor-commands/transforms/container-transforms.js +10 -6
- package/dist/es2019/editor-commands/transforms/inline-node-transforms.js +14 -4
- package/dist/es2019/editor-commands/transforms/layout/utils.js +10 -8
- package/dist/es2019/editor-commands/transforms/list/transformOrderedUnorderedListToBlockNodes.js +70 -20
- package/dist/es2019/ui/copy-block.js +17 -1
- package/dist/esm/editor-commands/transforms/container-transforms.js +10 -6
- package/dist/esm/editor-commands/transforms/inline-node-transforms.js +14 -4
- package/dist/esm/editor-commands/transforms/layout/utils.js +10 -8
- package/dist/esm/editor-commands/transforms/list/transformOrderedUnorderedListToBlockNodes.js +70 -29
- package/dist/esm/ui/copy-block.js +17 -1
- package/dist/types/editor-commands/transforms/inline-node-transforms.d.ts +6 -3
- package/dist/types-ts4.5/editor-commands/transforms/inline-node-transforms.d.ts +6 -3
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-menu
|
|
2
2
|
|
|
3
|
+
## 3.1.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`f1e12e7cf00ba`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/f1e12e7cf00ba) -
|
|
8
|
+
ED-29083: Fixed copying code block only copy texts
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
|
|
11
|
+
## 3.1.5
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [`6087f73c2a306`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/6087f73c2a306) -
|
|
16
|
+
[ux] ED-29309 Insert unsupported content from lists when transformed
|
|
17
|
+
- Updated dependencies
|
|
18
|
+
|
|
3
19
|
## 3.1.4
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
|
@@ -311,7 +311,7 @@ var splitContentForCodeBlock = function splitContentForCodeBlock(sourceNode, tar
|
|
|
311
311
|
var splits = [];
|
|
312
312
|
var children = sourceNode.content.content;
|
|
313
313
|
var currentTextContent = [];
|
|
314
|
-
|
|
314
|
+
var invalidContent = [];
|
|
315
315
|
// Handle expand title - add as first text if source is expand with title
|
|
316
316
|
if (sourceNode.type.name === 'expand' && (_sourceNode$attrs3 = sourceNode.attrs) !== null && _sourceNode$attrs3 !== void 0 && _sourceNode$attrs3.title) {
|
|
317
317
|
currentTextContent.push(sourceNode.attrs.title);
|
|
@@ -336,7 +336,7 @@ var splitContentForCodeBlock = function splitContentForCodeBlock(sourceNode, tar
|
|
|
336
336
|
currentTextContent.push(childNode.textContent);
|
|
337
337
|
} else if (childNode.isTextblock) {
|
|
338
338
|
// Extract text from text blocks (paragraphs, headings, etc.)
|
|
339
|
-
var text = (0, _inlineNodeTransforms.getInlineNodeTextContent)(_model.Fragment.from(childNode));
|
|
339
|
+
var text = (0, _inlineNodeTransforms.getInlineNodeTextContent)(_model.Fragment.from(childNode)).inlineTextContent;
|
|
340
340
|
if (text.trim()) {
|
|
341
341
|
currentTextContent.push(text);
|
|
342
342
|
}
|
|
@@ -350,9 +350,13 @@ var splitContentForCodeBlock = function splitContentForCodeBlock(sourceNode, tar
|
|
|
350
350
|
var listItemType = isTaskList ? childNode.type.schema.nodes.taskItem : childNode.type.schema.nodes.listItem;
|
|
351
351
|
var listItems = (0, _utils.findChildrenByType)(childNode, listItemType);
|
|
352
352
|
listItems.forEach(function (listItem) {
|
|
353
|
-
var
|
|
354
|
-
|
|
355
|
-
|
|
353
|
+
var content = isTaskList ? _model.Fragment.from(listItem.node) : listItem.node.content;
|
|
354
|
+
var inlineContent = (0, _inlineNodeTransforms.getInlineNodeTextContent)(content);
|
|
355
|
+
if (inlineContent.inlineTextContent.trim()) {
|
|
356
|
+
currentTextContent.push(inlineContent.inlineTextContent);
|
|
357
|
+
}
|
|
358
|
+
if (inlineContent.invalidContent.length > 0) {
|
|
359
|
+
invalidContent.push.apply(invalidContent, (0, _toConsumableArray2.default)(inlineContent.invalidContent));
|
|
356
360
|
}
|
|
357
361
|
});
|
|
358
362
|
} else {
|
|
@@ -366,7 +370,7 @@ var splitContentForCodeBlock = function splitContentForCodeBlock(sourceNode, tar
|
|
|
366
370
|
|
|
367
371
|
// Flush any remaining text content as a codeBlock
|
|
368
372
|
flushCurrentCodeBlock();
|
|
369
|
-
return splits;
|
|
373
|
+
return [].concat(splits, invalidContent);
|
|
370
374
|
};
|
|
371
375
|
|
|
372
376
|
/**
|
|
@@ -4,14 +4,19 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getInlineNodeTextNode = exports.getInlineNodeTextContent = void 0;
|
|
7
|
+
var _utils = require("./utils");
|
|
7
8
|
var getInlineNodeTextContent = exports.getInlineNodeTextContent = function getInlineNodeTextContent(sourceContent) {
|
|
8
9
|
var validTransformedContent = '';
|
|
10
|
+
var invalidContent = [];
|
|
9
11
|
if (sourceContent.content.length < 1) {
|
|
10
|
-
return
|
|
12
|
+
return {
|
|
13
|
+
inlineTextContent: '',
|
|
14
|
+
invalidContent: invalidContent
|
|
15
|
+
};
|
|
11
16
|
}
|
|
12
17
|
// Headings are not valid inside headings so convert heading nodes to paragraphs
|
|
13
18
|
sourceContent.forEach(function (node) {
|
|
14
|
-
if (['paragraph', 'heading', 'taskItem'].includes(node.type.name)) {
|
|
19
|
+
if (['paragraph', 'heading', 'taskItem', 'codeBlock'].includes(node.type.name)) {
|
|
15
20
|
node.content.forEach(function (inlineNode) {
|
|
16
21
|
if (inlineNode.type.name === 'status') {
|
|
17
22
|
validTransformedContent += inlineNode.attrs.text;
|
|
@@ -19,11 +24,16 @@ var getInlineNodeTextContent = exports.getInlineNodeTextContent = function getIn
|
|
|
19
24
|
validTransformedContent += "".concat(inlineNode.textContent);
|
|
20
25
|
}
|
|
21
26
|
});
|
|
27
|
+
} else if (!(0, _utils.isListNodeType)(node.type)) {
|
|
28
|
+
invalidContent.push(node);
|
|
22
29
|
}
|
|
23
30
|
});
|
|
24
|
-
return
|
|
31
|
+
return {
|
|
32
|
+
inlineTextContent: validTransformedContent,
|
|
33
|
+
invalidContent: invalidContent
|
|
34
|
+
};
|
|
25
35
|
};
|
|
26
36
|
var getInlineNodeTextNode = exports.getInlineNodeTextNode = function getInlineNodeTextNode(sourceContent, schema) {
|
|
27
|
-
var text = getInlineNodeTextContent(sourceContent);
|
|
37
|
+
var text = getInlineNodeTextContent(sourceContent).inlineTextContent;
|
|
28
38
|
return schema.text(text);
|
|
29
39
|
};
|
|
@@ -112,9 +112,7 @@ var transformToCodeBlock = function transformToCodeBlock(nodes, schema) {
|
|
|
112
112
|
};
|
|
113
113
|
nodes.forEach(function (node) {
|
|
114
114
|
if (node.isTextblock) {
|
|
115
|
-
var inlineTextContent = node.type === schema.nodes.codeBlock ? node.textContent : (0, _inlineNodeTransforms.getInlineNodeTextContent)(_model.Fragment.from(node));
|
|
116
|
-
|
|
117
|
-
// For first node, add directly
|
|
115
|
+
var inlineTextContent = node.type === schema.nodes.codeBlock ? node.textContent : (0, _inlineNodeTransforms.getInlineNodeTextContent)(_model.Fragment.from(node)).inlineTextContent;
|
|
118
116
|
addToNewNodes([inlineTextContent]);
|
|
119
117
|
} else if ((0, _utils2.isListNode)(node)) {
|
|
120
118
|
var textContent = [];
|
|
@@ -124,10 +122,10 @@ var transformToCodeBlock = function transformToCodeBlock(nodes, schema) {
|
|
|
124
122
|
});
|
|
125
123
|
listItems.forEach(function (listItem) {
|
|
126
124
|
if (listItem.type === schema.nodes.taskItem) {
|
|
127
|
-
var _inlineTextContent = (0, _inlineNodeTransforms.getInlineNodeTextContent)(_model.Fragment.from(listItem));
|
|
125
|
+
var _inlineTextContent = (0, _inlineNodeTransforms.getInlineNodeTextContent)(_model.Fragment.from(listItem)).inlineTextContent;
|
|
128
126
|
textContent.push(_inlineTextContent);
|
|
129
127
|
} else {
|
|
130
|
-
var _inlineTextContent2 = (0, _inlineNodeTransforms.getInlineNodeTextContent)(listItem.content);
|
|
128
|
+
var _inlineTextContent2 = (0, _inlineNodeTransforms.getInlineNodeTextContent)(listItem.content).inlineTextContent;
|
|
131
129
|
textContent.push(_inlineTextContent2);
|
|
132
130
|
}
|
|
133
131
|
});
|
|
@@ -242,6 +240,10 @@ var transformToListNode = exports.transformToListNode = function transformToList
|
|
|
242
240
|
var isTargetTask = (0, _transforms.isTaskList)(targetNodeType);
|
|
243
241
|
var listItems = [];
|
|
244
242
|
var listItemType = isTargetTask ? schema.nodes.taskItem : schema.nodes.listItem;
|
|
243
|
+
var unsupportedContent = [];
|
|
244
|
+
var onhandleUnsupportedContent = function onhandleUnsupportedContent(content) {
|
|
245
|
+
unsupportedContent.push(content);
|
|
246
|
+
};
|
|
245
247
|
var isValid = (0, _utils2.getContentSupportChecker)(listItemType);
|
|
246
248
|
nodes.forEach(function (node) {
|
|
247
249
|
// Append unsupported nodes as is
|
|
@@ -273,7 +275,7 @@ var transformToListNode = exports.transformToListNode = function transformToList
|
|
|
273
275
|
schema: schema,
|
|
274
276
|
supportedListTypes: supportedListTypes,
|
|
275
277
|
targetNodeType: targetNodeType
|
|
276
|
-
});
|
|
278
|
+
}, onhandleUnsupportedContent);
|
|
277
279
|
newListItems = (0, _toConsumableArray2.default)(newList.content.content);
|
|
278
280
|
}
|
|
279
281
|
} else if ((0, _utils2.isHeadingOrParagraphNode)(node) || isValid(node)) {
|
|
@@ -314,7 +316,7 @@ var transformToListNode = exports.transformToListNode = function transformToList
|
|
|
314
316
|
}
|
|
315
317
|
}
|
|
316
318
|
});
|
|
317
|
-
return listItems.map(function (_ref3) {
|
|
319
|
+
return [].concat((0, _toConsumableArray2.default)(listItems.map(function (_ref3) {
|
|
318
320
|
var node = _ref3.node,
|
|
319
321
|
canBeTransformed = _ref3.canBeTransformed;
|
|
320
322
|
if (canBeTransformed) {
|
|
@@ -322,7 +324,7 @@ var transformToListNode = exports.transformToListNode = function transformToList
|
|
|
322
324
|
} else {
|
|
323
325
|
return node;
|
|
324
326
|
}
|
|
325
|
-
});
|
|
327
|
+
})), unsupportedContent);
|
|
326
328
|
};
|
|
327
329
|
var convertUnwrappedLayoutContent = exports.convertUnwrappedLayoutContent = function convertUnwrappedLayoutContent(nodes, targetNodeType, schema, targetAttrs) {
|
|
328
330
|
if (nodes.length === 1 && nodes[0].content.size === 0 && !(0, _utils2.isContainerNodeType)(targetNodeType)) {
|
package/dist/cjs/editor-commands/transforms/list/transformOrderedUnorderedListToBlockNodes.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
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
7
|
exports.transformOrderedUnorderedListToBlockNodes = void 0;
|
|
8
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
7
9
|
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
8
10
|
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
11
|
+
var _inlineNodeTransforms = require("../inline-node-transforms");
|
|
12
|
+
var _utils2 = require("../utils");
|
|
9
13
|
var transformOrderedUnorderedListToBlockNodes = exports.transformOrderedUnorderedListToBlockNodes = function transformOrderedUnorderedListToBlockNodes(context) {
|
|
10
14
|
var tr = context.tr,
|
|
11
15
|
targetNodeType = context.targetNodeType,
|
|
@@ -14,38 +18,76 @@ var transformOrderedUnorderedListToBlockNodes = exports.transformOrderedUnordere
|
|
|
14
18
|
sourcePos = context.sourcePos;
|
|
15
19
|
var selection = tr.selection;
|
|
16
20
|
var schema = selection.$from.doc.type.schema;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
var
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
var targetNodes = [];
|
|
22
|
+
// find all list items inside the list node
|
|
23
|
+
var listItems = (0, _utils.findChildrenByType)(sourceNode, schema.nodes.listItem);
|
|
24
|
+
var textContent = [];
|
|
25
|
+
var flushTextContent = function flushTextContent() {
|
|
26
|
+
if (targetNodeType !== schema.nodes.codeBlock) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (textContent.length > 0) {
|
|
30
|
+
var inlineText = textContent.join('\n');
|
|
31
|
+
targetNodes.push(schema.nodes.codeBlock.createChecked({}, inlineText !== '' ? schema.text(inlineText) : null));
|
|
32
|
+
textContent = [];
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
listItems.forEach(function (listItem) {
|
|
36
|
+
// Convert paragraphs to headings if target is heading
|
|
37
|
+
var content = listItem.node.content.content;
|
|
38
|
+
content.forEach(function (node) {
|
|
39
|
+
var isValid = (0, _utils2.getContentSupportChecker)(targetNodeType)(node);
|
|
40
|
+
if ((0, _utils2.isListNode)(node)) {
|
|
41
|
+
// Skip nested lists as it will return listItems that we will deal with separately
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
23
44
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}, paragraphNode.content);
|
|
31
|
-
});
|
|
32
|
-
}
|
|
45
|
+
// Deal with the case where targetNode and node are both codeBlocks, then append text content
|
|
46
|
+
if (targetNodeType === schema.nodes.codeBlock && node.type === schema.nodes.codeBlock) {
|
|
47
|
+
var inlineContent = node.textContent;
|
|
48
|
+
textContent = [].concat((0, _toConsumableArray2.default)(textContent), [inlineContent]);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
33
51
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
52
|
+
// If the node is not valid for the target container,
|
|
53
|
+
// flush any existing text content if target is codeBlock
|
|
54
|
+
// and extract the node without any conversion
|
|
55
|
+
if (!isValid && !node.isTextblock) {
|
|
56
|
+
flushTextContent();
|
|
57
|
+
targetNodes.push(node);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// If the target is codeBlock, accumulate text content
|
|
62
|
+
if (targetNodeType === schema.nodes.codeBlock) {
|
|
63
|
+
var _inlineContent = (0, _inlineNodeTransforms.getInlineNodeTextContent)(_model.Fragment.from(node)).inlineTextContent;
|
|
64
|
+
textContent = [].concat((0, _toConsumableArray2.default)(textContent), [_inlineContent]);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Convert codeblocks to block nodes
|
|
69
|
+
if (node.type === schema.nodes.codeBlock) {
|
|
70
|
+
var _targetAttrs$level;
|
|
71
|
+
var _textContent = node.textContent.split('\n');
|
|
72
|
+
var attributes = targetNodeType === schema.nodes.heading ? {
|
|
73
|
+
level: (_targetAttrs$level = targetAttrs === null || targetAttrs === void 0 ? void 0 : targetAttrs.level) !== null && _targetAttrs$level !== void 0 ? _targetAttrs$level : 1
|
|
74
|
+
} : null;
|
|
75
|
+
_textContent.forEach(function (textLine) {
|
|
76
|
+
targetNodes.push(targetNodeType.createChecked(attributes, textLine ? schema.text(textLine) : null));
|
|
77
|
+
});
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (targetNodeType === schema.nodes.heading && targetAttrs) {
|
|
81
|
+
var targetHeadingLevel = targetAttrs.level;
|
|
82
|
+
targetNodes.push(schema.nodes.heading.createChecked({
|
|
83
|
+
level: targetHeadingLevel
|
|
84
|
+
}, node.content));
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
targetNodes.push(node);
|
|
43
88
|
});
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}).join('\n');
|
|
47
|
-
targetNodes = [schema.nodes.codeBlock.createChecked({}, schema.text(codeBlockContent))];
|
|
48
|
-
}
|
|
89
|
+
});
|
|
90
|
+
flushTextContent();
|
|
49
91
|
var fragment = _model.Fragment.fromArray(targetNodes);
|
|
50
92
|
var slice = new _model.Slice(fragment, 0, 0);
|
|
51
93
|
var rangeStart = sourcePos !== null ? sourcePos : selection.from;
|
|
@@ -33,7 +33,7 @@ var CopyBlockMenuItem = function CopyBlockMenuItem(_ref) {
|
|
|
33
33
|
var schema = selection.$from.doc.type.schema;
|
|
34
34
|
// for texts and inline nodes
|
|
35
35
|
if (selection instanceof _state.TextSelection) {
|
|
36
|
-
var _fragment;
|
|
36
|
+
var _fragment, _fragment2;
|
|
37
37
|
var fragment = selection === null || selection === void 0 ? void 0 : selection.content().content;
|
|
38
38
|
if (!fragment) {
|
|
39
39
|
return;
|
|
@@ -46,6 +46,15 @@ var CopyBlockMenuItem = function CopyBlockMenuItem(_ref) {
|
|
|
46
46
|
var layoutContent = layoutColumnNode === null || layoutColumnNode === void 0 ? void 0 : layoutColumnNode.firstChild;
|
|
47
47
|
fragment = (layoutContent === null || layoutContent === void 0 ? void 0 : layoutContent.content) || _model.Fragment.empty;
|
|
48
48
|
}
|
|
49
|
+
|
|
50
|
+
// if text is inside of an expand, the selection contains an expand for some reason
|
|
51
|
+
// the expandNode always and only have one child, no matter how much contents are inside the expand,
|
|
52
|
+
// and the one child is the line that is being selected, so we can use the .firstChild again
|
|
53
|
+
if ((_fragment2 = fragment) !== null && _fragment2 !== void 0 && _fragment2.firstChild && fragment.firstChild.type.name === 'expand') {
|
|
54
|
+
var expandNode = fragment.firstChild;
|
|
55
|
+
var actualNodeToCopy = expandNode.firstChild;
|
|
56
|
+
fragment = _model.Fragment.from(actualNodeToCopy) || _model.Fragment.empty;
|
|
57
|
+
}
|
|
49
58
|
var domNode = toDOMFromFragment(fragment, schema);
|
|
50
59
|
var div = document.createElement('div');
|
|
51
60
|
div.appendChild(domNode);
|
|
@@ -66,6 +75,13 @@ var CopyBlockMenuItem = function CopyBlockMenuItem(_ref) {
|
|
|
66
75
|
// for other nodes
|
|
67
76
|
if (selection instanceof _state.NodeSelection) {
|
|
68
77
|
var _nodeType = selection.node.type;
|
|
78
|
+
|
|
79
|
+
// code block is a special case where it is a block node but has inlineContent to true,
|
|
80
|
+
// When nodeType.inlineContent is true, it will be treated as an inline node in the copyDomNode function,
|
|
81
|
+
// but we want to treat it as a block node when copying, hence setting it to false here
|
|
82
|
+
if (selection.node.type.name === 'codeBlock') {
|
|
83
|
+
_nodeType.inlineContent = false;
|
|
84
|
+
}
|
|
69
85
|
var _domNode2 = (0, _copyButton.toDOM)(selection.node, schema);
|
|
70
86
|
(0, _copyButton.copyDomNode)(_domNode2, _nodeType, selection);
|
|
71
87
|
}
|
|
@@ -312,7 +312,7 @@ const splitContentForCodeBlock = (sourceNode, targetNodeType, targetAttrs, schem
|
|
|
312
312
|
const splits = [];
|
|
313
313
|
const children = sourceNode.content.content;
|
|
314
314
|
let currentTextContent = [];
|
|
315
|
-
|
|
315
|
+
const invalidContent = [];
|
|
316
316
|
// Handle expand title - add as first text if source is expand with title
|
|
317
317
|
if (sourceNode.type.name === 'expand' && (_sourceNode$attrs3 = sourceNode.attrs) !== null && _sourceNode$attrs3 !== void 0 && _sourceNode$attrs3.title) {
|
|
318
318
|
currentTextContent.push(sourceNode.attrs.title);
|
|
@@ -337,7 +337,7 @@ const splitContentForCodeBlock = (sourceNode, targetNodeType, targetAttrs, schem
|
|
|
337
337
|
currentTextContent.push(childNode.textContent);
|
|
338
338
|
} else if (childNode.isTextblock) {
|
|
339
339
|
// Extract text from text blocks (paragraphs, headings, etc.)
|
|
340
|
-
const text = getInlineNodeTextContent(Fragment.from(childNode));
|
|
340
|
+
const text = getInlineNodeTextContent(Fragment.from(childNode)).inlineTextContent;
|
|
341
341
|
if (text.trim()) {
|
|
342
342
|
currentTextContent.push(text);
|
|
343
343
|
}
|
|
@@ -351,9 +351,13 @@ const splitContentForCodeBlock = (sourceNode, targetNodeType, targetAttrs, schem
|
|
|
351
351
|
const listItemType = isTaskList ? childNode.type.schema.nodes.taskItem : childNode.type.schema.nodes.listItem;
|
|
352
352
|
const listItems = findChildrenByType(childNode, listItemType);
|
|
353
353
|
listItems.forEach(listItem => {
|
|
354
|
-
const
|
|
355
|
-
|
|
356
|
-
|
|
354
|
+
const content = isTaskList ? Fragment.from(listItem.node) : listItem.node.content;
|
|
355
|
+
const inlineContent = getInlineNodeTextContent(content);
|
|
356
|
+
if (inlineContent.inlineTextContent.trim()) {
|
|
357
|
+
currentTextContent.push(inlineContent.inlineTextContent);
|
|
358
|
+
}
|
|
359
|
+
if (inlineContent.invalidContent.length > 0) {
|
|
360
|
+
invalidContent.push(...inlineContent.invalidContent);
|
|
357
361
|
}
|
|
358
362
|
});
|
|
359
363
|
} else {
|
|
@@ -367,7 +371,7 @@ const splitContentForCodeBlock = (sourceNode, targetNodeType, targetAttrs, schem
|
|
|
367
371
|
|
|
368
372
|
// Flush any remaining text content as a codeBlock
|
|
369
373
|
flushCurrentCodeBlock();
|
|
370
|
-
return splits;
|
|
374
|
+
return [...splits, ...invalidContent];
|
|
371
375
|
};
|
|
372
376
|
|
|
373
377
|
/**
|
|
@@ -1,11 +1,16 @@
|
|
|
1
|
+
import { isListNodeType } from './utils';
|
|
1
2
|
export const getInlineNodeTextContent = sourceContent => {
|
|
2
3
|
let validTransformedContent = '';
|
|
4
|
+
const invalidContent = [];
|
|
3
5
|
if (sourceContent.content.length < 1) {
|
|
4
|
-
return
|
|
6
|
+
return {
|
|
7
|
+
inlineTextContent: '',
|
|
8
|
+
invalidContent
|
|
9
|
+
};
|
|
5
10
|
}
|
|
6
11
|
// Headings are not valid inside headings so convert heading nodes to paragraphs
|
|
7
12
|
sourceContent.forEach(node => {
|
|
8
|
-
if (['paragraph', 'heading', 'taskItem'].includes(node.type.name)) {
|
|
13
|
+
if (['paragraph', 'heading', 'taskItem', 'codeBlock'].includes(node.type.name)) {
|
|
9
14
|
node.content.forEach(inlineNode => {
|
|
10
15
|
if (inlineNode.type.name === 'status') {
|
|
11
16
|
validTransformedContent += inlineNode.attrs.text;
|
|
@@ -13,11 +18,16 @@ export const getInlineNodeTextContent = sourceContent => {
|
|
|
13
18
|
validTransformedContent += `${inlineNode.textContent}`;
|
|
14
19
|
}
|
|
15
20
|
});
|
|
21
|
+
} else if (!isListNodeType(node.type)) {
|
|
22
|
+
invalidContent.push(node);
|
|
16
23
|
}
|
|
17
24
|
});
|
|
18
|
-
return
|
|
25
|
+
return {
|
|
26
|
+
inlineTextContent: validTransformedContent,
|
|
27
|
+
invalidContent
|
|
28
|
+
};
|
|
19
29
|
};
|
|
20
30
|
export const getInlineNodeTextNode = (sourceContent, schema) => {
|
|
21
|
-
const text = getInlineNodeTextContent(sourceContent);
|
|
31
|
+
const text = getInlineNodeTextContent(sourceContent).inlineTextContent;
|
|
22
32
|
return schema.text(text);
|
|
23
33
|
};
|
|
@@ -92,9 +92,7 @@ const transformToCodeBlock = (nodes, schema) => {
|
|
|
92
92
|
};
|
|
93
93
|
nodes.forEach(node => {
|
|
94
94
|
if (node.isTextblock) {
|
|
95
|
-
const inlineTextContent = node.type === schema.nodes.codeBlock ? node.textContent : getInlineNodeTextContent(Fragment.from(node));
|
|
96
|
-
|
|
97
|
-
// For first node, add directly
|
|
95
|
+
const inlineTextContent = node.type === schema.nodes.codeBlock ? node.textContent : getInlineNodeTextContent(Fragment.from(node)).inlineTextContent;
|
|
98
96
|
addToNewNodes([inlineTextContent]);
|
|
99
97
|
} else if (isListNode(node)) {
|
|
100
98
|
const textContent = [];
|
|
@@ -102,10 +100,10 @@ const transformToCodeBlock = (nodes, schema) => {
|
|
|
102
100
|
const listItems = findChildrenByType(node, listItemType).map(item => item.node);
|
|
103
101
|
listItems.forEach(listItem => {
|
|
104
102
|
if (listItem.type === schema.nodes.taskItem) {
|
|
105
|
-
const inlineTextContent = getInlineNodeTextContent(Fragment.from(listItem));
|
|
103
|
+
const inlineTextContent = getInlineNodeTextContent(Fragment.from(listItem)).inlineTextContent;
|
|
106
104
|
textContent.push(inlineTextContent);
|
|
107
105
|
} else {
|
|
108
|
-
const inlineTextContent = getInlineNodeTextContent(listItem.content);
|
|
106
|
+
const inlineTextContent = getInlineNodeTextContent(listItem.content).inlineTextContent;
|
|
109
107
|
textContent.push(inlineTextContent);
|
|
110
108
|
}
|
|
111
109
|
});
|
|
@@ -220,6 +218,10 @@ export const transformToListNode = (nodes, targetNodeType, schema) => {
|
|
|
220
218
|
const isTargetTask = isTaskList(targetNodeType);
|
|
221
219
|
const listItems = [];
|
|
222
220
|
const listItemType = isTargetTask ? schema.nodes.taskItem : schema.nodes.listItem;
|
|
221
|
+
const unsupportedContent = [];
|
|
222
|
+
const onhandleUnsupportedContent = content => {
|
|
223
|
+
unsupportedContent.push(content);
|
|
224
|
+
};
|
|
223
225
|
const isValid = getContentSupportChecker(listItemType);
|
|
224
226
|
nodes.forEach(node => {
|
|
225
227
|
// Append unsupported nodes as is
|
|
@@ -251,7 +253,7 @@ export const transformToListNode = (nodes, targetNodeType, schema) => {
|
|
|
251
253
|
schema,
|
|
252
254
|
supportedListTypes,
|
|
253
255
|
targetNodeType
|
|
254
|
-
});
|
|
256
|
+
}, onhandleUnsupportedContent);
|
|
255
257
|
newListItems = [...newList.content.content];
|
|
256
258
|
}
|
|
257
259
|
} else if (isHeadingOrParagraphNode(node) || isValid(node)) {
|
|
@@ -292,7 +294,7 @@ export const transformToListNode = (nodes, targetNodeType, schema) => {
|
|
|
292
294
|
}
|
|
293
295
|
}
|
|
294
296
|
});
|
|
295
|
-
return listItems.map(({
|
|
297
|
+
return [...listItems.map(({
|
|
296
298
|
node,
|
|
297
299
|
canBeTransformed
|
|
298
300
|
}) => {
|
|
@@ -301,7 +303,7 @@ export const transformToListNode = (nodes, targetNodeType, schema) => {
|
|
|
301
303
|
} else {
|
|
302
304
|
return node;
|
|
303
305
|
}
|
|
304
|
-
});
|
|
306
|
+
}), ...unsupportedContent];
|
|
305
307
|
};
|
|
306
308
|
export const convertUnwrappedLayoutContent = (nodes, targetNodeType, schema, targetAttrs) => {
|
|
307
309
|
if (nodes.length === 1 && nodes[0].content.size === 0 && !isContainerNodeType(targetNodeType)) {
|
package/dist/es2019/editor-commands/transforms/list/transformOrderedUnorderedListToBlockNodes.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
|
|
2
2
|
import { findChildrenByType } from '@atlaskit/editor-prosemirror/utils';
|
|
3
|
+
import { getInlineNodeTextContent } from '../inline-node-transforms';
|
|
4
|
+
import { getContentSupportChecker, isListNode } from '../utils';
|
|
3
5
|
export const transformOrderedUnorderedListToBlockNodes = context => {
|
|
4
6
|
const {
|
|
5
7
|
tr,
|
|
@@ -12,28 +14,76 @@ export const transformOrderedUnorderedListToBlockNodes = context => {
|
|
|
12
14
|
selection
|
|
13
15
|
} = tr;
|
|
14
16
|
const schema = selection.$from.doc.type.schema;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
let
|
|
17
|
+
const targetNodes = [];
|
|
18
|
+
// find all list items inside the list node
|
|
19
|
+
const listItems = findChildrenByType(sourceNode, schema.nodes.listItem);
|
|
20
|
+
let textContent = [];
|
|
21
|
+
const flushTextContent = () => {
|
|
22
|
+
if (targetNodeType !== schema.nodes.codeBlock) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (textContent.length > 0) {
|
|
26
|
+
const inlineText = textContent.join('\n');
|
|
27
|
+
targetNodes.push(schema.nodes.codeBlock.createChecked({}, inlineText !== '' ? schema.text(inlineText) : null));
|
|
28
|
+
textContent = [];
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
listItems.forEach(listItem => {
|
|
32
|
+
// Convert paragraphs to headings if target is heading
|
|
33
|
+
const content = listItem.node.content.content;
|
|
34
|
+
content.forEach(node => {
|
|
35
|
+
const isValid = getContentSupportChecker(targetNodeType)(node);
|
|
36
|
+
if (isListNode(node)) {
|
|
37
|
+
// Skip nested lists as it will return listItems that we will deal with separately
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
19
40
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
41
|
+
// Deal with the case where targetNode and node are both codeBlocks, then append text content
|
|
42
|
+
if (targetNodeType === schema.nodes.codeBlock && node.type === schema.nodes.codeBlock) {
|
|
43
|
+
const inlineContent = node.textContent;
|
|
44
|
+
textContent = [...textContent, inlineContent];
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
27
47
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
48
|
+
// If the node is not valid for the target container,
|
|
49
|
+
// flush any existing text content if target is codeBlock
|
|
50
|
+
// and extract the node without any conversion
|
|
51
|
+
if (!isValid && !node.isTextblock) {
|
|
52
|
+
flushTextContent();
|
|
53
|
+
targetNodes.push(node);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// If the target is codeBlock, accumulate text content
|
|
58
|
+
if (targetNodeType === schema.nodes.codeBlock) {
|
|
59
|
+
const inlineContent = getInlineNodeTextContent(Fragment.from(node)).inlineTextContent;
|
|
60
|
+
textContent = [...textContent, inlineContent];
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Convert codeblocks to block nodes
|
|
65
|
+
if (node.type === schema.nodes.codeBlock) {
|
|
66
|
+
var _targetAttrs$level;
|
|
67
|
+
const textContent = node.textContent.split('\n');
|
|
68
|
+
const attributes = targetNodeType === schema.nodes.heading ? {
|
|
69
|
+
level: (_targetAttrs$level = targetAttrs === null || targetAttrs === void 0 ? void 0 : targetAttrs.level) !== null && _targetAttrs$level !== void 0 ? _targetAttrs$level : 1
|
|
70
|
+
} : null;
|
|
71
|
+
textContent.forEach(textLine => {
|
|
72
|
+
targetNodes.push(targetNodeType.createChecked(attributes, textLine ? schema.text(textLine) : null));
|
|
73
|
+
});
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (targetNodeType === schema.nodes.heading && targetAttrs) {
|
|
77
|
+
const targetHeadingLevel = targetAttrs.level;
|
|
78
|
+
targetNodes.push(schema.nodes.heading.createChecked({
|
|
79
|
+
level: targetHeadingLevel
|
|
80
|
+
}, node.content));
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
targetNodes.push(node);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
flushTextContent();
|
|
37
87
|
const fragment = Fragment.fromArray(targetNodes);
|
|
38
88
|
const slice = new Slice(fragment, 0, 0);
|
|
39
89
|
const rangeStart = sourcePos !== null ? sourcePos : selection.from;
|
|
@@ -28,7 +28,7 @@ const CopyBlockMenuItem = ({
|
|
|
28
28
|
const schema = selection.$from.doc.type.schema;
|
|
29
29
|
// for texts and inline nodes
|
|
30
30
|
if (selection instanceof TextSelection) {
|
|
31
|
-
var _fragment;
|
|
31
|
+
var _fragment, _fragment2;
|
|
32
32
|
let fragment = selection === null || selection === void 0 ? void 0 : selection.content().content;
|
|
33
33
|
if (!fragment) {
|
|
34
34
|
return;
|
|
@@ -41,6 +41,15 @@ const CopyBlockMenuItem = ({
|
|
|
41
41
|
const layoutContent = layoutColumnNode === null || layoutColumnNode === void 0 ? void 0 : layoutColumnNode.firstChild;
|
|
42
42
|
fragment = (layoutContent === null || layoutContent === void 0 ? void 0 : layoutContent.content) || Fragment.empty;
|
|
43
43
|
}
|
|
44
|
+
|
|
45
|
+
// if text is inside of an expand, the selection contains an expand for some reason
|
|
46
|
+
// the expandNode always and only have one child, no matter how much contents are inside the expand,
|
|
47
|
+
// and the one child is the line that is being selected, so we can use the .firstChild again
|
|
48
|
+
if ((_fragment2 = fragment) !== null && _fragment2 !== void 0 && _fragment2.firstChild && fragment.firstChild.type.name === 'expand') {
|
|
49
|
+
const expandNode = fragment.firstChild;
|
|
50
|
+
const actualNodeToCopy = expandNode.firstChild;
|
|
51
|
+
fragment = Fragment.from(actualNodeToCopy) || Fragment.empty;
|
|
52
|
+
}
|
|
44
53
|
const domNode = toDOMFromFragment(fragment, schema);
|
|
45
54
|
const div = document.createElement('div');
|
|
46
55
|
div.appendChild(domNode);
|
|
@@ -61,6 +70,13 @@ const CopyBlockMenuItem = ({
|
|
|
61
70
|
// for other nodes
|
|
62
71
|
if (selection instanceof NodeSelection) {
|
|
63
72
|
const nodeType = selection.node.type;
|
|
73
|
+
|
|
74
|
+
// code block is a special case where it is a block node but has inlineContent to true,
|
|
75
|
+
// When nodeType.inlineContent is true, it will be treated as an inline node in the copyDomNode function,
|
|
76
|
+
// but we want to treat it as a block node when copying, hence setting it to false here
|
|
77
|
+
if (selection.node.type.name === 'codeBlock') {
|
|
78
|
+
nodeType.inlineContent = false;
|
|
79
|
+
}
|
|
64
80
|
const domNode = toDOM(selection.node, schema);
|
|
65
81
|
copyDomNode(domNode, nodeType, selection);
|
|
66
82
|
}
|
|
@@ -304,7 +304,7 @@ var splitContentForCodeBlock = function splitContentForCodeBlock(sourceNode, tar
|
|
|
304
304
|
var splits = [];
|
|
305
305
|
var children = sourceNode.content.content;
|
|
306
306
|
var currentTextContent = [];
|
|
307
|
-
|
|
307
|
+
var invalidContent = [];
|
|
308
308
|
// Handle expand title - add as first text if source is expand with title
|
|
309
309
|
if (sourceNode.type.name === 'expand' && (_sourceNode$attrs3 = sourceNode.attrs) !== null && _sourceNode$attrs3 !== void 0 && _sourceNode$attrs3.title) {
|
|
310
310
|
currentTextContent.push(sourceNode.attrs.title);
|
|
@@ -329,7 +329,7 @@ var splitContentForCodeBlock = function splitContentForCodeBlock(sourceNode, tar
|
|
|
329
329
|
currentTextContent.push(childNode.textContent);
|
|
330
330
|
} else if (childNode.isTextblock) {
|
|
331
331
|
// Extract text from text blocks (paragraphs, headings, etc.)
|
|
332
|
-
var text = getInlineNodeTextContent(Fragment.from(childNode));
|
|
332
|
+
var text = getInlineNodeTextContent(Fragment.from(childNode)).inlineTextContent;
|
|
333
333
|
if (text.trim()) {
|
|
334
334
|
currentTextContent.push(text);
|
|
335
335
|
}
|
|
@@ -343,9 +343,13 @@ var splitContentForCodeBlock = function splitContentForCodeBlock(sourceNode, tar
|
|
|
343
343
|
var listItemType = isTaskList ? childNode.type.schema.nodes.taskItem : childNode.type.schema.nodes.listItem;
|
|
344
344
|
var listItems = findChildrenByType(childNode, listItemType);
|
|
345
345
|
listItems.forEach(function (listItem) {
|
|
346
|
-
var
|
|
347
|
-
|
|
348
|
-
|
|
346
|
+
var content = isTaskList ? Fragment.from(listItem.node) : listItem.node.content;
|
|
347
|
+
var inlineContent = getInlineNodeTextContent(content);
|
|
348
|
+
if (inlineContent.inlineTextContent.trim()) {
|
|
349
|
+
currentTextContent.push(inlineContent.inlineTextContent);
|
|
350
|
+
}
|
|
351
|
+
if (inlineContent.invalidContent.length > 0) {
|
|
352
|
+
invalidContent.push.apply(invalidContent, _toConsumableArray(inlineContent.invalidContent));
|
|
349
353
|
}
|
|
350
354
|
});
|
|
351
355
|
} else {
|
|
@@ -359,7 +363,7 @@ var splitContentForCodeBlock = function splitContentForCodeBlock(sourceNode, tar
|
|
|
359
363
|
|
|
360
364
|
// Flush any remaining text content as a codeBlock
|
|
361
365
|
flushCurrentCodeBlock();
|
|
362
|
-
return splits;
|
|
366
|
+
return [].concat(splits, invalidContent);
|
|
363
367
|
};
|
|
364
368
|
|
|
365
369
|
/**
|
|
@@ -1,11 +1,16 @@
|
|
|
1
|
+
import { isListNodeType } from './utils';
|
|
1
2
|
export var getInlineNodeTextContent = function getInlineNodeTextContent(sourceContent) {
|
|
2
3
|
var validTransformedContent = '';
|
|
4
|
+
var invalidContent = [];
|
|
3
5
|
if (sourceContent.content.length < 1) {
|
|
4
|
-
return
|
|
6
|
+
return {
|
|
7
|
+
inlineTextContent: '',
|
|
8
|
+
invalidContent: invalidContent
|
|
9
|
+
};
|
|
5
10
|
}
|
|
6
11
|
// Headings are not valid inside headings so convert heading nodes to paragraphs
|
|
7
12
|
sourceContent.forEach(function (node) {
|
|
8
|
-
if (['paragraph', 'heading', 'taskItem'].includes(node.type.name)) {
|
|
13
|
+
if (['paragraph', 'heading', 'taskItem', 'codeBlock'].includes(node.type.name)) {
|
|
9
14
|
node.content.forEach(function (inlineNode) {
|
|
10
15
|
if (inlineNode.type.name === 'status') {
|
|
11
16
|
validTransformedContent += inlineNode.attrs.text;
|
|
@@ -13,11 +18,16 @@ export var getInlineNodeTextContent = function getInlineNodeTextContent(sourceCo
|
|
|
13
18
|
validTransformedContent += "".concat(inlineNode.textContent);
|
|
14
19
|
}
|
|
15
20
|
});
|
|
21
|
+
} else if (!isListNodeType(node.type)) {
|
|
22
|
+
invalidContent.push(node);
|
|
16
23
|
}
|
|
17
24
|
});
|
|
18
|
-
return
|
|
25
|
+
return {
|
|
26
|
+
inlineTextContent: validTransformedContent,
|
|
27
|
+
invalidContent: invalidContent
|
|
28
|
+
};
|
|
19
29
|
};
|
|
20
30
|
export var getInlineNodeTextNode = function getInlineNodeTextNode(sourceContent, schema) {
|
|
21
|
-
var text = getInlineNodeTextContent(sourceContent);
|
|
31
|
+
var text = getInlineNodeTextContent(sourceContent).inlineTextContent;
|
|
22
32
|
return schema.text(text);
|
|
23
33
|
};
|
|
@@ -105,9 +105,7 @@ var transformToCodeBlock = function transformToCodeBlock(nodes, schema) {
|
|
|
105
105
|
};
|
|
106
106
|
nodes.forEach(function (node) {
|
|
107
107
|
if (node.isTextblock) {
|
|
108
|
-
var inlineTextContent = node.type === schema.nodes.codeBlock ? node.textContent : getInlineNodeTextContent(Fragment.from(node));
|
|
109
|
-
|
|
110
|
-
// For first node, add directly
|
|
108
|
+
var inlineTextContent = node.type === schema.nodes.codeBlock ? node.textContent : getInlineNodeTextContent(Fragment.from(node)).inlineTextContent;
|
|
111
109
|
addToNewNodes([inlineTextContent]);
|
|
112
110
|
} else if (isListNode(node)) {
|
|
113
111
|
var textContent = [];
|
|
@@ -117,10 +115,10 @@ var transformToCodeBlock = function transformToCodeBlock(nodes, schema) {
|
|
|
117
115
|
});
|
|
118
116
|
listItems.forEach(function (listItem) {
|
|
119
117
|
if (listItem.type === schema.nodes.taskItem) {
|
|
120
|
-
var _inlineTextContent = getInlineNodeTextContent(Fragment.from(listItem));
|
|
118
|
+
var _inlineTextContent = getInlineNodeTextContent(Fragment.from(listItem)).inlineTextContent;
|
|
121
119
|
textContent.push(_inlineTextContent);
|
|
122
120
|
} else {
|
|
123
|
-
var _inlineTextContent2 = getInlineNodeTextContent(listItem.content);
|
|
121
|
+
var _inlineTextContent2 = getInlineNodeTextContent(listItem.content).inlineTextContent;
|
|
124
122
|
textContent.push(_inlineTextContent2);
|
|
125
123
|
}
|
|
126
124
|
});
|
|
@@ -235,6 +233,10 @@ export var transformToListNode = function transformToListNode(nodes, targetNodeT
|
|
|
235
233
|
var isTargetTask = isTaskList(targetNodeType);
|
|
236
234
|
var listItems = [];
|
|
237
235
|
var listItemType = isTargetTask ? schema.nodes.taskItem : schema.nodes.listItem;
|
|
236
|
+
var unsupportedContent = [];
|
|
237
|
+
var onhandleUnsupportedContent = function onhandleUnsupportedContent(content) {
|
|
238
|
+
unsupportedContent.push(content);
|
|
239
|
+
};
|
|
238
240
|
var isValid = getContentSupportChecker(listItemType);
|
|
239
241
|
nodes.forEach(function (node) {
|
|
240
242
|
// Append unsupported nodes as is
|
|
@@ -266,7 +268,7 @@ export var transformToListNode = function transformToListNode(nodes, targetNodeT
|
|
|
266
268
|
schema: schema,
|
|
267
269
|
supportedListTypes: supportedListTypes,
|
|
268
270
|
targetNodeType: targetNodeType
|
|
269
|
-
});
|
|
271
|
+
}, onhandleUnsupportedContent);
|
|
270
272
|
newListItems = _toConsumableArray(newList.content.content);
|
|
271
273
|
}
|
|
272
274
|
} else if (isHeadingOrParagraphNode(node) || isValid(node)) {
|
|
@@ -307,7 +309,7 @@ export var transformToListNode = function transformToListNode(nodes, targetNodeT
|
|
|
307
309
|
}
|
|
308
310
|
}
|
|
309
311
|
});
|
|
310
|
-
return listItems.map(function (_ref3) {
|
|
312
|
+
return [].concat(_toConsumableArray(listItems.map(function (_ref3) {
|
|
311
313
|
var node = _ref3.node,
|
|
312
314
|
canBeTransformed = _ref3.canBeTransformed;
|
|
313
315
|
if (canBeTransformed) {
|
|
@@ -315,7 +317,7 @@ export var transformToListNode = function transformToListNode(nodes, targetNodeT
|
|
|
315
317
|
} else {
|
|
316
318
|
return node;
|
|
317
319
|
}
|
|
318
|
-
});
|
|
320
|
+
})), unsupportedContent);
|
|
319
321
|
};
|
|
320
322
|
export var convertUnwrappedLayoutContent = function convertUnwrappedLayoutContent(nodes, targetNodeType, schema, targetAttrs) {
|
|
321
323
|
if (nodes.length === 1 && nodes[0].content.size === 0 && !isContainerNodeType(targetNodeType)) {
|
package/dist/esm/editor-commands/transforms/list/transformOrderedUnorderedListToBlockNodes.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
1
2
|
import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
|
|
2
3
|
import { findChildrenByType } from '@atlaskit/editor-prosemirror/utils';
|
|
4
|
+
import { getInlineNodeTextContent } from '../inline-node-transforms';
|
|
5
|
+
import { getContentSupportChecker, isListNode } from '../utils';
|
|
3
6
|
export var transformOrderedUnorderedListToBlockNodes = function transformOrderedUnorderedListToBlockNodes(context) {
|
|
4
7
|
var tr = context.tr,
|
|
5
8
|
targetNodeType = context.targetNodeType,
|
|
@@ -8,38 +11,76 @@ export var transformOrderedUnorderedListToBlockNodes = function transformOrdered
|
|
|
8
11
|
sourcePos = context.sourcePos;
|
|
9
12
|
var selection = tr.selection;
|
|
10
13
|
var schema = selection.$from.doc.type.schema;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
var targetNodes = [];
|
|
15
|
+
// find all list items inside the list node
|
|
16
|
+
var listItems = findChildrenByType(sourceNode, schema.nodes.listItem);
|
|
17
|
+
var textContent = [];
|
|
18
|
+
var flushTextContent = function flushTextContent() {
|
|
19
|
+
if (targetNodeType !== schema.nodes.codeBlock) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (textContent.length > 0) {
|
|
23
|
+
var inlineText = textContent.join('\n');
|
|
24
|
+
targetNodes.push(schema.nodes.codeBlock.createChecked({}, inlineText !== '' ? schema.text(inlineText) : null));
|
|
25
|
+
textContent = [];
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
listItems.forEach(function (listItem) {
|
|
29
|
+
// Convert paragraphs to headings if target is heading
|
|
30
|
+
var content = listItem.node.content.content;
|
|
31
|
+
content.forEach(function (node) {
|
|
32
|
+
var isValid = getContentSupportChecker(targetNodeType)(node);
|
|
33
|
+
if (isListNode(node)) {
|
|
34
|
+
// Skip nested lists as it will return listItems that we will deal with separately
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
17
37
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}, paragraphNode.content);
|
|
25
|
-
});
|
|
26
|
-
}
|
|
38
|
+
// Deal with the case where targetNode and node are both codeBlocks, then append text content
|
|
39
|
+
if (targetNodeType === schema.nodes.codeBlock && node.type === schema.nodes.codeBlock) {
|
|
40
|
+
var inlineContent = node.textContent;
|
|
41
|
+
textContent = [].concat(_toConsumableArray(textContent), [inlineContent]);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
27
44
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
45
|
+
// If the node is not valid for the target container,
|
|
46
|
+
// flush any existing text content if target is codeBlock
|
|
47
|
+
// and extract the node without any conversion
|
|
48
|
+
if (!isValid && !node.isTextblock) {
|
|
49
|
+
flushTextContent();
|
|
50
|
+
targetNodes.push(node);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// If the target is codeBlock, accumulate text content
|
|
55
|
+
if (targetNodeType === schema.nodes.codeBlock) {
|
|
56
|
+
var _inlineContent = getInlineNodeTextContent(Fragment.from(node)).inlineTextContent;
|
|
57
|
+
textContent = [].concat(_toConsumableArray(textContent), [_inlineContent]);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Convert codeblocks to block nodes
|
|
62
|
+
if (node.type === schema.nodes.codeBlock) {
|
|
63
|
+
var _targetAttrs$level;
|
|
64
|
+
var _textContent = node.textContent.split('\n');
|
|
65
|
+
var attributes = targetNodeType === schema.nodes.heading ? {
|
|
66
|
+
level: (_targetAttrs$level = targetAttrs === null || targetAttrs === void 0 ? void 0 : targetAttrs.level) !== null && _targetAttrs$level !== void 0 ? _targetAttrs$level : 1
|
|
67
|
+
} : null;
|
|
68
|
+
_textContent.forEach(function (textLine) {
|
|
69
|
+
targetNodes.push(targetNodeType.createChecked(attributes, textLine ? schema.text(textLine) : null));
|
|
70
|
+
});
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (targetNodeType === schema.nodes.heading && targetAttrs) {
|
|
74
|
+
var targetHeadingLevel = targetAttrs.level;
|
|
75
|
+
targetNodes.push(schema.nodes.heading.createChecked({
|
|
76
|
+
level: targetHeadingLevel
|
|
77
|
+
}, node.content));
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
targetNodes.push(node);
|
|
37
81
|
});
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}).join('\n');
|
|
41
|
-
targetNodes = [schema.nodes.codeBlock.createChecked({}, schema.text(codeBlockContent))];
|
|
42
|
-
}
|
|
82
|
+
});
|
|
83
|
+
flushTextContent();
|
|
43
84
|
var fragment = Fragment.fromArray(targetNodes);
|
|
44
85
|
var slice = new Slice(fragment, 0, 0);
|
|
45
86
|
var rangeStart = sourcePos !== null ? sourcePos : selection.from;
|
|
@@ -26,7 +26,7 @@ var CopyBlockMenuItem = function CopyBlockMenuItem(_ref) {
|
|
|
26
26
|
var schema = selection.$from.doc.type.schema;
|
|
27
27
|
// for texts and inline nodes
|
|
28
28
|
if (selection instanceof TextSelection) {
|
|
29
|
-
var _fragment;
|
|
29
|
+
var _fragment, _fragment2;
|
|
30
30
|
var fragment = selection === null || selection === void 0 ? void 0 : selection.content().content;
|
|
31
31
|
if (!fragment) {
|
|
32
32
|
return;
|
|
@@ -39,6 +39,15 @@ var CopyBlockMenuItem = function CopyBlockMenuItem(_ref) {
|
|
|
39
39
|
var layoutContent = layoutColumnNode === null || layoutColumnNode === void 0 ? void 0 : layoutColumnNode.firstChild;
|
|
40
40
|
fragment = (layoutContent === null || layoutContent === void 0 ? void 0 : layoutContent.content) || Fragment.empty;
|
|
41
41
|
}
|
|
42
|
+
|
|
43
|
+
// if text is inside of an expand, the selection contains an expand for some reason
|
|
44
|
+
// the expandNode always and only have one child, no matter how much contents are inside the expand,
|
|
45
|
+
// and the one child is the line that is being selected, so we can use the .firstChild again
|
|
46
|
+
if ((_fragment2 = fragment) !== null && _fragment2 !== void 0 && _fragment2.firstChild && fragment.firstChild.type.name === 'expand') {
|
|
47
|
+
var expandNode = fragment.firstChild;
|
|
48
|
+
var actualNodeToCopy = expandNode.firstChild;
|
|
49
|
+
fragment = Fragment.from(actualNodeToCopy) || Fragment.empty;
|
|
50
|
+
}
|
|
42
51
|
var domNode = toDOMFromFragment(fragment, schema);
|
|
43
52
|
var div = document.createElement('div');
|
|
44
53
|
div.appendChild(domNode);
|
|
@@ -59,6 +68,13 @@ var CopyBlockMenuItem = function CopyBlockMenuItem(_ref) {
|
|
|
59
68
|
// for other nodes
|
|
60
69
|
if (selection instanceof NodeSelection) {
|
|
61
70
|
var _nodeType = selection.node.type;
|
|
71
|
+
|
|
72
|
+
// code block is a special case where it is a block node but has inlineContent to true,
|
|
73
|
+
// When nodeType.inlineContent is true, it will be treated as an inline node in the copyDomNode function,
|
|
74
|
+
// but we want to treat it as a block node when copying, hence setting it to false here
|
|
75
|
+
if (selection.node.type.name === 'codeBlock') {
|
|
76
|
+
_nodeType.inlineContent = false;
|
|
77
|
+
}
|
|
62
78
|
var _domNode2 = toDOM(selection.node, schema);
|
|
63
79
|
copyDomNode(_domNode2, _nodeType, selection);
|
|
64
80
|
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
import type { Fragment, Schema } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
-
export declare const getInlineNodeTextContent: (sourceContent: Fragment) =>
|
|
3
|
-
|
|
1
|
+
import type { Fragment, Schema, Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
export declare const getInlineNodeTextContent: (sourceContent: Fragment) => {
|
|
3
|
+
inlineTextContent: string;
|
|
4
|
+
invalidContent: PMNode[];
|
|
5
|
+
};
|
|
6
|
+
export declare const getInlineNodeTextNode: (sourceContent: Fragment, schema: Schema) => PMNode;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
import type { Fragment, Schema } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
-
export declare const getInlineNodeTextContent: (sourceContent: Fragment) =>
|
|
3
|
-
|
|
1
|
+
import type { Fragment, Schema, Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
export declare const getInlineNodeTextContent: (sourceContent: Fragment) => {
|
|
3
|
+
inlineTextContent: string;
|
|
4
|
+
invalidContent: PMNode[];
|
|
5
|
+
};
|
|
6
|
+
export declare const getInlineNodeTextNode: (sourceContent: Fragment, schema: Schema) => PMNode;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-block-menu",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.6",
|
|
4
4
|
"description": "BlockMenu plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@atlaskit/css": "^0.14.0",
|
|
32
32
|
"@atlaskit/dropdown-menu": "^16.3.0",
|
|
33
|
-
"@atlaskit/editor-plugin-block-controls": "^6.
|
|
33
|
+
"@atlaskit/editor-plugin-block-controls": "^6.3.0",
|
|
34
34
|
"@atlaskit/editor-plugin-decorations": "^5.0.0",
|
|
35
35
|
"@atlaskit/editor-plugin-selection": "^5.0.0",
|
|
36
36
|
"@atlaskit/editor-plugin-user-intent": "^3.0.0",
|
|
@@ -38,16 +38,16 @@
|
|
|
38
38
|
"@atlaskit/editor-shared-styles": "^3.6.0",
|
|
39
39
|
"@atlaskit/editor-tables": "^2.9.0",
|
|
40
40
|
"@atlaskit/editor-toolbar": "^0.9.0",
|
|
41
|
-
"@atlaskit/icon": "^28.
|
|
41
|
+
"@atlaskit/icon": "^28.2.0",
|
|
42
42
|
"@atlaskit/icon-lab": "^5.7.0",
|
|
43
43
|
"@atlaskit/platform-feature-flags": "^1.1.0",
|
|
44
44
|
"@atlaskit/primitives": "^14.14.0",
|
|
45
|
-
"@atlaskit/tmp-editor-statsig": "^12.
|
|
45
|
+
"@atlaskit/tmp-editor-statsig": "^12.23.0",
|
|
46
46
|
"@atlaskit/tokens": "^6.3.0",
|
|
47
47
|
"@babel/runtime": "^7.0.0"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@atlaskit/editor-common": "^109.
|
|
50
|
+
"@atlaskit/editor-common": "^109.8.0",
|
|
51
51
|
"react": "^18.2.0",
|
|
52
52
|
"react-intl-next": "npm:react-intl@^5.18.1"
|
|
53
53
|
},
|