@atlaskit/editor-plugin-block-menu 3.1.3 → 3.1.5
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 +15 -0
- package/dist/cjs/editor-commands/transforms/container-transforms.js +29 -13
- 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/block-menu.js +1 -1
- package/dist/es2019/editor-commands/transforms/container-transforms.js +19 -3
- 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/block-menu.js +1 -1
- package/dist/esm/editor-commands/transforms/container-transforms.js +19 -3
- 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/block-menu.js +1 -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,20 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-menu
|
|
2
2
|
|
|
3
|
+
## 3.1.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`6087f73c2a306`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/6087f73c2a306) -
|
|
8
|
+
[ux] ED-29309 Insert unsupported content from lists when transformed
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
|
|
11
|
+
## 3.1.4
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [`f2000345dec2c`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/f2000345dec2c) -
|
|
16
|
+
ED-29258 Break up list items into new lines when converted into codeblock
|
|
17
|
+
|
|
3
18
|
## 3.1.3
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
|
@@ -7,7 +7,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.unwrapAndConvertToList = exports.unwrapAndConvertToBlockType = exports.transformToContainer = exports.transformContainerNode = exports.transformBetweenContainerTypes = void 0;
|
|
8
8
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
9
|
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
10
|
-
var _utils = require("
|
|
10
|
+
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
11
|
+
var _inlineNodeTransforms = require("./inline-node-transforms");
|
|
12
|
+
var _utils2 = require("./utils");
|
|
11
13
|
var convertInvalidNodeToValidNodeType = function convertInvalidNodeToValidNodeType(sourceContent, sourceNodeType, validNodeType, withMarks) {
|
|
12
14
|
var validTransformedContent = [];
|
|
13
15
|
// Headings are not valid inside headings so convert heading nodes to paragraphs
|
|
@@ -34,7 +36,7 @@ var transformToContainer = exports.transformToContainer = function transformToCo
|
|
|
34
36
|
var content = selection.content().content;
|
|
35
37
|
var transformedContent = content;
|
|
36
38
|
if (sourceNode.type === schema.nodes.codeBlock) {
|
|
37
|
-
var paragraphNodes = (0,
|
|
39
|
+
var paragraphNodes = (0, _utils2.convertCodeBlockContentToParagraphs)(sourceNode, schema);
|
|
38
40
|
transformedContent = _model.Fragment.fromArray(paragraphNodes);
|
|
39
41
|
}
|
|
40
42
|
if (targetNodeType === schema.nodes.blockquote) {
|
|
@@ -45,7 +47,7 @@ var transformToContainer = exports.transformToContainer = function transformToCo
|
|
|
45
47
|
// e.g. blocks (heading/ paragraph) with alignment need to remove alignment
|
|
46
48
|
// as panel/ blockQuote/ expands does not support alignment
|
|
47
49
|
if (sourceNode.type === schema.nodes.paragraph || sourceNode.type === schema.nodes.heading) {
|
|
48
|
-
transformedContent = (0,
|
|
50
|
+
transformedContent = (0, _utils2.filterMarksForTargetNodeType)(transformedContent, targetNodeType);
|
|
49
51
|
}
|
|
50
52
|
var newNode = targetNodeType.createAndFill(targetAttrs, transformedContent);
|
|
51
53
|
if (!newNode) {
|
|
@@ -69,7 +71,7 @@ var transformContainerNode = exports.transformContainerNode = function transform
|
|
|
69
71
|
}
|
|
70
72
|
|
|
71
73
|
// Transform container to block type - unwrap and convert content
|
|
72
|
-
if ((0,
|
|
74
|
+
if ((0, _utils2.isBlockNodeType)(targetNodeType)) {
|
|
73
75
|
// special case container to codeblock
|
|
74
76
|
if (targetNodeType.name === 'codeBlock') {
|
|
75
77
|
return transformBetweenContainerTypes({
|
|
@@ -90,7 +92,7 @@ var transformContainerNode = exports.transformContainerNode = function transform
|
|
|
90
92
|
}
|
|
91
93
|
|
|
92
94
|
// Transform container to list type
|
|
93
|
-
if ((0,
|
|
95
|
+
if ((0, _utils2.isListNodeType)(targetNodeType)) {
|
|
94
96
|
return unwrapAndConvertToList({
|
|
95
97
|
tr: tr,
|
|
96
98
|
sourceNode: sourceNode,
|
|
@@ -101,7 +103,7 @@ var transformContainerNode = exports.transformContainerNode = function transform
|
|
|
101
103
|
}
|
|
102
104
|
|
|
103
105
|
// Transform between container types
|
|
104
|
-
if ((0,
|
|
106
|
+
if ((0, _utils2.isContainerNodeType)(targetNodeType)) {
|
|
105
107
|
return transformBetweenContainerTypes({
|
|
106
108
|
tr: tr,
|
|
107
109
|
sourceNode: sourceNode,
|
|
@@ -146,7 +148,7 @@ var unwrapAndConvertToBlockType = exports.unwrapAndConvertToBlockType = function
|
|
|
146
148
|
|
|
147
149
|
// if the container is a code block, convert text content to multiple paragraphs
|
|
148
150
|
if (sourceNode.type === codeBlock) {
|
|
149
|
-
sourceChildren = (0,
|
|
151
|
+
sourceChildren = (0, _utils2.convertCodeBlockContentToParagraphs)(sourceNode, schema);
|
|
150
152
|
}
|
|
151
153
|
|
|
152
154
|
// if target node is a paragraph, just do unwrap
|
|
@@ -274,7 +276,7 @@ var transformBetweenContainerTypes = exports.transformBetweenContainerTypes = fu
|
|
|
274
276
|
}
|
|
275
277
|
|
|
276
278
|
// Get content validation for target container type
|
|
277
|
-
var isContentSupported = (0,
|
|
279
|
+
var isContentSupported = (0, _utils2.getContentSupportChecker)(targetNodeType);
|
|
278
280
|
|
|
279
281
|
// Process content and collect splits
|
|
280
282
|
var contentSplits = splitContentAroundUnsupportedBlocks(sourceNode, isContentSupported, targetNodeType, targetAttrs, tr.doc.type.schema);
|
|
@@ -309,7 +311,7 @@ var splitContentForCodeBlock = function splitContentForCodeBlock(sourceNode, tar
|
|
|
309
311
|
var splits = [];
|
|
310
312
|
var children = sourceNode.content.content;
|
|
311
313
|
var currentTextContent = [];
|
|
312
|
-
|
|
314
|
+
var invalidContent = [];
|
|
313
315
|
// Handle expand title - add as first text if source is expand with title
|
|
314
316
|
if (sourceNode.type.name === 'expand' && (_sourceNode$attrs3 = sourceNode.attrs) !== null && _sourceNode$attrs3 !== void 0 && _sourceNode$attrs3.title) {
|
|
315
317
|
currentTextContent.push(sourceNode.attrs.title);
|
|
@@ -334,15 +336,29 @@ var splitContentForCodeBlock = function splitContentForCodeBlock(sourceNode, tar
|
|
|
334
336
|
currentTextContent.push(childNode.textContent);
|
|
335
337
|
} else if (childNode.isTextblock) {
|
|
336
338
|
// Extract text from text blocks (paragraphs, headings, etc.)
|
|
337
|
-
var text = childNode.
|
|
339
|
+
var text = (0, _inlineNodeTransforms.getInlineNodeTextContent)(_model.Fragment.from(childNode)).inlineTextContent;
|
|
338
340
|
if (text.trim()) {
|
|
339
341
|
currentTextContent.push(text);
|
|
340
342
|
}
|
|
341
343
|
}
|
|
342
|
-
} else if ((0,
|
|
344
|
+
} else if ((0, _utils2.isBlockNodeForExtraction)(childNode)) {
|
|
343
345
|
// Unsupported block node (table, etc.) - flush current codeBlock, add block, continue
|
|
344
346
|
flushCurrentCodeBlock();
|
|
345
347
|
splits.push(childNode);
|
|
348
|
+
} else if ((0, _utils2.isListNodeType)(childNode.type)) {
|
|
349
|
+
var isTaskList = childNode.type.name === 'taskList';
|
|
350
|
+
var listItemType = isTaskList ? childNode.type.schema.nodes.taskItem : childNode.type.schema.nodes.listItem;
|
|
351
|
+
var listItems = (0, _utils.findChildrenByType)(childNode, listItemType);
|
|
352
|
+
listItems.forEach(function (listItem) {
|
|
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));
|
|
360
|
+
}
|
|
361
|
+
});
|
|
346
362
|
} else {
|
|
347
363
|
// Other unsupported content - try to extract text if possible
|
|
348
364
|
var _text = childNode.textContent;
|
|
@@ -354,7 +370,7 @@ var splitContentForCodeBlock = function splitContentForCodeBlock(sourceNode, tar
|
|
|
354
370
|
|
|
355
371
|
// Flush any remaining text content as a codeBlock
|
|
356
372
|
flushCurrentCodeBlock();
|
|
357
|
-
return splits;
|
|
373
|
+
return [].concat(splits, invalidContent);
|
|
358
374
|
};
|
|
359
375
|
|
|
360
376
|
/**
|
|
@@ -394,7 +410,7 @@ var splitContentAroundUnsupportedBlocks = function splitContentAroundUnsupported
|
|
|
394
410
|
splits.push(childNode);
|
|
395
411
|
} else {
|
|
396
412
|
// Unsupported inline content - convert to paragraph and add to container
|
|
397
|
-
var inlineContent = (0,
|
|
413
|
+
var inlineContent = (0, _utils2.convertNodeToInlineContent)(childNode, schema);
|
|
398
414
|
if (inlineContent.length > 0) {
|
|
399
415
|
var paragraph = schema.nodes.paragraph.create({}, _model.Fragment.fromArray(inlineContent));
|
|
400
416
|
currentContainerContent.push(paragraph);
|
|
@@ -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;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
import { findChildrenByType } from '@atlaskit/editor-prosemirror/utils';
|
|
3
|
+
import { getInlineNodeTextContent } from './inline-node-transforms';
|
|
2
4
|
import { isBlockNodeType, isListNodeType, isContainerNodeType, isBlockNodeForExtraction, convertNodeToInlineContent, getContentSupportChecker, convertCodeBlockContentToParagraphs, filterMarksForTargetNodeType } from './utils';
|
|
3
5
|
const convertInvalidNodeToValidNodeType = (sourceContent, sourceNodeType, validNodeType, withMarks) => {
|
|
4
6
|
const validTransformedContent = [];
|
|
@@ -310,7 +312,7 @@ const splitContentForCodeBlock = (sourceNode, targetNodeType, targetAttrs, schem
|
|
|
310
312
|
const splits = [];
|
|
311
313
|
const children = sourceNode.content.content;
|
|
312
314
|
let currentTextContent = [];
|
|
313
|
-
|
|
315
|
+
const invalidContent = [];
|
|
314
316
|
// Handle expand title - add as first text if source is expand with title
|
|
315
317
|
if (sourceNode.type.name === 'expand' && (_sourceNode$attrs3 = sourceNode.attrs) !== null && _sourceNode$attrs3 !== void 0 && _sourceNode$attrs3.title) {
|
|
316
318
|
currentTextContent.push(sourceNode.attrs.title);
|
|
@@ -335,7 +337,7 @@ const splitContentForCodeBlock = (sourceNode, targetNodeType, targetAttrs, schem
|
|
|
335
337
|
currentTextContent.push(childNode.textContent);
|
|
336
338
|
} else if (childNode.isTextblock) {
|
|
337
339
|
// Extract text from text blocks (paragraphs, headings, etc.)
|
|
338
|
-
const text = childNode.
|
|
340
|
+
const text = getInlineNodeTextContent(Fragment.from(childNode)).inlineTextContent;
|
|
339
341
|
if (text.trim()) {
|
|
340
342
|
currentTextContent.push(text);
|
|
341
343
|
}
|
|
@@ -344,6 +346,20 @@ const splitContentForCodeBlock = (sourceNode, targetNodeType, targetAttrs, schem
|
|
|
344
346
|
// Unsupported block node (table, etc.) - flush current codeBlock, add block, continue
|
|
345
347
|
flushCurrentCodeBlock();
|
|
346
348
|
splits.push(childNode);
|
|
349
|
+
} else if (isListNodeType(childNode.type)) {
|
|
350
|
+
const isTaskList = childNode.type.name === 'taskList';
|
|
351
|
+
const listItemType = isTaskList ? childNode.type.schema.nodes.taskItem : childNode.type.schema.nodes.listItem;
|
|
352
|
+
const listItems = findChildrenByType(childNode, listItemType);
|
|
353
|
+
listItems.forEach(listItem => {
|
|
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);
|
|
361
|
+
}
|
|
362
|
+
});
|
|
347
363
|
} else {
|
|
348
364
|
// Other unsupported content - try to extract text if possible
|
|
349
365
|
const text = childNode.textContent;
|
|
@@ -355,7 +371,7 @@ const splitContentForCodeBlock = (sourceNode, targetNodeType, targetAttrs, schem
|
|
|
355
371
|
|
|
356
372
|
// Flush any remaining text content as a codeBlock
|
|
357
373
|
flushCurrentCodeBlock();
|
|
358
|
-
return splits;
|
|
374
|
+
return [...splits, ...invalidContent];
|
|
359
375
|
};
|
|
360
376
|
|
|
361
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;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* block-menu.tsx generated by @compiled/babel-plugin v0.
|
|
1
|
+
/* block-menu.tsx generated by @compiled/babel-plugin v0.36.1 */
|
|
2
2
|
import "./block-menu.compiled.css";
|
|
3
3
|
import { ax, ix } from "@compiled/react/runtime";
|
|
4
4
|
import React, { useContext, useEffect } from 'react';
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
2
|
import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
+
import { findChildrenByType } from '@atlaskit/editor-prosemirror/utils';
|
|
4
|
+
import { getInlineNodeTextContent } from './inline-node-transforms';
|
|
3
5
|
import { isBlockNodeType, isListNodeType, isContainerNodeType, isBlockNodeForExtraction, convertNodeToInlineContent, getContentSupportChecker, convertCodeBlockContentToParagraphs, filterMarksForTargetNodeType } from './utils';
|
|
4
6
|
var convertInvalidNodeToValidNodeType = function convertInvalidNodeToValidNodeType(sourceContent, sourceNodeType, validNodeType, withMarks) {
|
|
5
7
|
var validTransformedContent = [];
|
|
@@ -302,7 +304,7 @@ var splitContentForCodeBlock = function splitContentForCodeBlock(sourceNode, tar
|
|
|
302
304
|
var splits = [];
|
|
303
305
|
var children = sourceNode.content.content;
|
|
304
306
|
var currentTextContent = [];
|
|
305
|
-
|
|
307
|
+
var invalidContent = [];
|
|
306
308
|
// Handle expand title - add as first text if source is expand with title
|
|
307
309
|
if (sourceNode.type.name === 'expand' && (_sourceNode$attrs3 = sourceNode.attrs) !== null && _sourceNode$attrs3 !== void 0 && _sourceNode$attrs3.title) {
|
|
308
310
|
currentTextContent.push(sourceNode.attrs.title);
|
|
@@ -327,7 +329,7 @@ var splitContentForCodeBlock = function splitContentForCodeBlock(sourceNode, tar
|
|
|
327
329
|
currentTextContent.push(childNode.textContent);
|
|
328
330
|
} else if (childNode.isTextblock) {
|
|
329
331
|
// Extract text from text blocks (paragraphs, headings, etc.)
|
|
330
|
-
var text = childNode.
|
|
332
|
+
var text = getInlineNodeTextContent(Fragment.from(childNode)).inlineTextContent;
|
|
331
333
|
if (text.trim()) {
|
|
332
334
|
currentTextContent.push(text);
|
|
333
335
|
}
|
|
@@ -336,6 +338,20 @@ var splitContentForCodeBlock = function splitContentForCodeBlock(sourceNode, tar
|
|
|
336
338
|
// Unsupported block node (table, etc.) - flush current codeBlock, add block, continue
|
|
337
339
|
flushCurrentCodeBlock();
|
|
338
340
|
splits.push(childNode);
|
|
341
|
+
} else if (isListNodeType(childNode.type)) {
|
|
342
|
+
var isTaskList = childNode.type.name === 'taskList';
|
|
343
|
+
var listItemType = isTaskList ? childNode.type.schema.nodes.taskItem : childNode.type.schema.nodes.listItem;
|
|
344
|
+
var listItems = findChildrenByType(childNode, listItemType);
|
|
345
|
+
listItems.forEach(function (listItem) {
|
|
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));
|
|
353
|
+
}
|
|
354
|
+
});
|
|
339
355
|
} else {
|
|
340
356
|
// Other unsupported content - try to extract text if possible
|
|
341
357
|
var _text = childNode.textContent;
|
|
@@ -347,7 +363,7 @@ var splitContentForCodeBlock = function splitContentForCodeBlock(sourceNode, tar
|
|
|
347
363
|
|
|
348
364
|
// Flush any remaining text content as a codeBlock
|
|
349
365
|
flushCurrentCodeBlock();
|
|
350
|
-
return splits;
|
|
366
|
+
return [].concat(splits, invalidContent);
|
|
351
367
|
};
|
|
352
368
|
|
|
353
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;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* block-menu.tsx generated by @compiled/babel-plugin v0.
|
|
1
|
+
/* block-menu.tsx generated by @compiled/babel-plugin v0.36.1 */
|
|
2
2
|
import "./block-menu.compiled.css";
|
|
3
3
|
import { ax, ix } from "@compiled/react/runtime";
|
|
4
4
|
import React, { useContext, useEffect } from 'react';
|
|
@@ -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.5",
|
|
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.22.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.7.0",
|
|
51
51
|
"react": "^18.2.0",
|
|
52
52
|
"react-intl-next": "npm:react-intl@^5.18.1"
|
|
53
53
|
},
|