@atlaskit/editor-plugin-block-menu 1.0.11 → 1.0.13
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 +20 -0
- package/dist/cjs/editor-commands/transforms/block-transforms.js +1 -1
- package/dist/cjs/editor-commands/transforms/container-transforms.js +8 -25
- package/dist/cjs/editor-commands/transforms/inline-node-transforms.js +9 -7
- package/dist/cjs/editor-commands/transforms/layout/utils.js +289 -0
- package/dist/cjs/editor-commands/transforms/layout-transforms.js +40 -2
- package/dist/cjs/editor-commands/transforms/list/transformBetweenListTypes.js +92 -50
- package/dist/cjs/editor-commands/transforms/list-transforms.js +7 -0
- package/dist/cjs/editor-commands/transforms/transformNodeToTargetType.js +3 -0
- package/dist/cjs/editor-commands/transforms/utils.js +40 -1
- package/dist/es2019/editor-commands/transforms/block-transforms.js +2 -2
- package/dist/es2019/editor-commands/transforms/container-transforms.js +8 -23
- package/dist/es2019/editor-commands/transforms/inline-node-transforms.js +8 -6
- package/dist/es2019/editor-commands/transforms/layout/utils.js +272 -0
- package/dist/es2019/editor-commands/transforms/layout-transforms.js +40 -1
- package/dist/es2019/editor-commands/transforms/list/transformBetweenListTypes.js +94 -51
- package/dist/es2019/editor-commands/transforms/list-transforms.js +7 -0
- package/dist/es2019/editor-commands/transforms/transformNodeToTargetType.js +5 -2
- package/dist/es2019/editor-commands/transforms/utils.js +39 -0
- package/dist/esm/editor-commands/transforms/block-transforms.js +2 -2
- package/dist/esm/editor-commands/transforms/container-transforms.js +8 -25
- package/dist/esm/editor-commands/transforms/inline-node-transforms.js +8 -6
- package/dist/esm/editor-commands/transforms/layout/utils.js +282 -0
- package/dist/esm/editor-commands/transforms/layout-transforms.js +38 -1
- package/dist/esm/editor-commands/transforms/list/transformBetweenListTypes.js +92 -49
- package/dist/esm/editor-commands/transforms/list-transforms.js +7 -0
- package/dist/esm/editor-commands/transforms/transformNodeToTargetType.js +5 -2
- package/dist/esm/editor-commands/transforms/utils.js +39 -0
- package/dist/types/editor-commands/transforms/inline-node-transforms.d.ts +3 -3
- package/dist/types/editor-commands/transforms/layout/utils.d.ts +5 -0
- package/dist/types/editor-commands/transforms/layout-transforms.d.ts +1 -0
- package/dist/types/editor-commands/transforms/list/transformBetweenListTypes.d.ts +13 -0
- package/dist/types/editor-commands/transforms/utils.d.ts +13 -0
- package/dist/types-ts4.5/editor-commands/transforms/inline-node-transforms.d.ts +3 -3
- package/dist/types-ts4.5/editor-commands/transforms/layout/utils.d.ts +5 -0
- package/dist/types-ts4.5/editor-commands/transforms/layout-transforms.d.ts +1 -0
- package/dist/types-ts4.5/editor-commands/transforms/list/transformBetweenListTypes.d.ts +13 -0
- package/dist/types-ts4.5/editor-commands/transforms/utils.d.ts +13 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-menu
|
|
2
2
|
|
|
3
|
+
## 1.0.13
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`c24edcf83432c`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/c24edcf83432c) -
|
|
8
|
+
[ux] ED-29147 Add functionality to convert layout to nodes
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
|
|
11
|
+
## 1.0.12
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [`6e27819feadc7`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/6e27819feadc7) -
|
|
16
|
+
ED-29183: Fixed aligned p and heading not able to convert to list
|
|
17
|
+
- [`6a9265f5389db`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/6a9265f5389db) -
|
|
18
|
+
Fix container transform with blockquote containing list
|
|
19
|
+
- [`24e0d952943aa`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/24e0d952943aa) -
|
|
20
|
+
ED-29206: Fixed conversion from code block to panel, expand text formatting issue
|
|
21
|
+
- Updated dependencies
|
|
22
|
+
|
|
3
23
|
## 1.0.11
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
|
@@ -41,7 +41,7 @@ var transformToBlockNode = function transformToBlockNode(context) {
|
|
|
41
41
|
$to = selection.$to;
|
|
42
42
|
var schema = doc.type.schema;
|
|
43
43
|
if (targetNodeType === schema.nodes.codeBlock) {
|
|
44
|
-
var textContent = (0, _inlineNodeTransforms.
|
|
44
|
+
var textContent = (0, _inlineNodeTransforms.getInlineNodeTextNode)(selection.content().content, schema);
|
|
45
45
|
var node = schema.nodes.codeBlock.createChecked(undefined, textContent);
|
|
46
46
|
return tr.replaceRangeWith(selection.from, selection.to, node);
|
|
47
47
|
}
|
|
@@ -20,19 +20,6 @@ var convertInvalidNodeToValidNodeType = function convertInvalidNodeToValidNodeTy
|
|
|
20
20
|
});
|
|
21
21
|
return _model.Fragment.from(validTransformedContent);
|
|
22
22
|
};
|
|
23
|
-
var filterMarksForTargetNodeType = function filterMarksForTargetNodeType(content, targetNodeType) {
|
|
24
|
-
var withValidMarks = [];
|
|
25
|
-
content.forEach(function (node) {
|
|
26
|
-
if (node.marks.length > 0) {
|
|
27
|
-
var allowedMarks = targetNodeType.allowedMarks(node.marks);
|
|
28
|
-
var updatedNode = node.mark(allowedMarks);
|
|
29
|
-
withValidMarks.push(updatedNode);
|
|
30
|
-
} else {
|
|
31
|
-
withValidMarks.push(node);
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
return _model.Fragment.from(withValidMarks);
|
|
35
|
-
};
|
|
36
23
|
|
|
37
24
|
/**
|
|
38
25
|
* Transform selection to container type
|
|
@@ -47,7 +34,8 @@ var transformToContainer = exports.transformToContainer = function transformToCo
|
|
|
47
34
|
var content = selection.content().content;
|
|
48
35
|
var transformedContent = content;
|
|
49
36
|
if (sourceNode.type === schema.nodes.codeBlock) {
|
|
50
|
-
|
|
37
|
+
var paragraphNodes = (0, _utils.convertCodeBlockContentToParagraphs)(sourceNode, schema);
|
|
38
|
+
transformedContent = _model.Fragment.fromArray(paragraphNodes);
|
|
51
39
|
}
|
|
52
40
|
if (targetNodeType === schema.nodes.blockquote) {
|
|
53
41
|
transformedContent = convertInvalidNodeToValidNodeType(transformedContent, schema.nodes.heading, schema.nodes.paragraph, true);
|
|
@@ -57,7 +45,7 @@ var transformToContainer = exports.transformToContainer = function transformToCo
|
|
|
57
45
|
// e.g. blocks (heading/ paragraph) with alignment need to remove alignment
|
|
58
46
|
// as panel/ blockQuote/ expands does not support alignment
|
|
59
47
|
if (sourceNode.type === schema.nodes.paragraph || sourceNode.type === schema.nodes.heading) {
|
|
60
|
-
transformedContent = filterMarksForTargetNodeType(transformedContent, targetNodeType);
|
|
48
|
+
transformedContent = (0, _utils.filterMarksForTargetNodeType)(transformedContent, targetNodeType);
|
|
61
49
|
}
|
|
62
50
|
var newNode = targetNodeType.createAndFill(targetAttrs, transformedContent);
|
|
63
51
|
if (!newNode) {
|
|
@@ -158,12 +146,7 @@ var unwrapAndConvertToBlockType = exports.unwrapAndConvertToBlockType = function
|
|
|
158
146
|
|
|
159
147
|
// if the container is a code block, convert text content to multiple paragraphs
|
|
160
148
|
if (sourceNode.type === codeBlock) {
|
|
161
|
-
|
|
162
|
-
var lines = codeText.split('\n');
|
|
163
|
-
var paragraphNodes = lines.map(function (line) {
|
|
164
|
-
return paragraph.create(null, line ? schema.text(line) : null);
|
|
165
|
-
});
|
|
166
|
-
sourceChildren = paragraphNodes;
|
|
149
|
+
sourceChildren = (0, _utils.convertCodeBlockContentToParagraphs)(sourceNode, schema);
|
|
167
150
|
}
|
|
168
151
|
|
|
169
152
|
// if target node is a paragraph, just do unwrap
|
|
@@ -400,15 +383,15 @@ var splitContentAroundUnsupportedBlocks = function splitContentAroundUnsupported
|
|
|
400
383
|
if (isContentSupported(childNode)) {
|
|
401
384
|
// Supported content - add to current container
|
|
402
385
|
currentContainerContent.push(childNode);
|
|
403
|
-
} else if ((0, _utils.isBlockNodeForExtraction)(childNode)) {
|
|
404
|
-
// Unsupported block node - flush current container, add block, continue
|
|
405
|
-
flushCurrentContainer();
|
|
406
|
-
splits.push(childNode);
|
|
407
386
|
} else if (childNode.type.name === targetNodeType.name) {
|
|
408
387
|
// Same type of container merge contents
|
|
409
388
|
childNode.content.forEach(function (child) {
|
|
410
389
|
currentContainerContent.push(child);
|
|
411
390
|
});
|
|
391
|
+
} else if (childNode.isBlock) {
|
|
392
|
+
// Unsupported block node - flush current container, add block, continue
|
|
393
|
+
flushCurrentContainer();
|
|
394
|
+
splits.push(childNode);
|
|
412
395
|
} else {
|
|
413
396
|
// Unsupported inline content - convert to paragraph and add to container
|
|
414
397
|
var inlineContent = (0, _utils.convertNodeToInlineContent)(childNode, schema);
|
|
@@ -3,12 +3,11 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.getInlineNodeTextContent = void 0;
|
|
7
|
-
var getInlineNodeTextContent = exports.getInlineNodeTextContent = function getInlineNodeTextContent(sourceContent
|
|
6
|
+
exports.getInlineNodeTextNode = exports.getInlineNodeTextContent = void 0;
|
|
7
|
+
var getInlineNodeTextContent = exports.getInlineNodeTextContent = function getInlineNodeTextContent(sourceContent) {
|
|
8
8
|
var validTransformedContent = '';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return;
|
|
9
|
+
if (sourceContent.content.length < 1) {
|
|
10
|
+
return '';
|
|
12
11
|
}
|
|
13
12
|
// Headings are not valid inside headings so convert heading nodes to paragraphs
|
|
14
13
|
sourceContent.forEach(function (node) {
|
|
@@ -20,8 +19,11 @@ var getInlineNodeTextContent = exports.getInlineNodeTextContent = function getIn
|
|
|
20
19
|
validTransformedContent += "".concat(inlineNode.textContent);
|
|
21
20
|
}
|
|
22
21
|
});
|
|
23
|
-
validTransformedContent;
|
|
24
22
|
}
|
|
25
23
|
});
|
|
26
|
-
return
|
|
24
|
+
return validTransformedContent;
|
|
25
|
+
};
|
|
26
|
+
var getInlineNodeTextNode = exports.getInlineNodeTextNode = function getInlineNodeTextNode(sourceContent, schema) {
|
|
27
|
+
var text = getInlineNodeTextContent(sourceContent);
|
|
28
|
+
return schema.text(text);
|
|
27
29
|
};
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.unwrapLayoutNodesToTextNodes = exports.transformToListNode = exports.convertUnwrappedLayoutContent = void 0;
|
|
8
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
|
+
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
10
|
+
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
11
|
+
var _inlineNodeTransforms = require("../inline-node-transforms");
|
|
12
|
+
var _transformBetweenListTypes = require("../list/transformBetweenListTypes");
|
|
13
|
+
var _utils2 = require("../utils");
|
|
14
|
+
var unwrapLayoutNodesToTextNodes = exports.unwrapLayoutNodesToTextNodes = function unwrapLayoutNodesToTextNodes(context, finalTargetNodeType) {
|
|
15
|
+
var tr = context.tr,
|
|
16
|
+
sourceNode = context.sourceNode,
|
|
17
|
+
targetNodeType = context.targetNodeType,
|
|
18
|
+
targetAttrs = context.targetAttrs;
|
|
19
|
+
var schema = tr.doc.type.schema || {};
|
|
20
|
+
var isValid = (0, _utils2.getContentSupportChecker)(finalTargetNodeType);
|
|
21
|
+
var createTextNode = function createTextNode(node) {
|
|
22
|
+
var isTextNode = node.type.name === 'text';
|
|
23
|
+
if (isValid(node) && !isTextNode) {
|
|
24
|
+
return node;
|
|
25
|
+
}
|
|
26
|
+
return targetNodeType.createChecked(targetAttrs, isTextNode ? node : node.content, node.marks);
|
|
27
|
+
};
|
|
28
|
+
if ((0, _utils2.isBlockNode)(sourceNode)) {
|
|
29
|
+
// code block acts like a container, we need to unwrap it
|
|
30
|
+
if (sourceNode.type === schema.nodes.codeBlock) {
|
|
31
|
+
var textNodes = sourceNode.textContent.split('\n').map(function (line) {
|
|
32
|
+
return targetNodeType.createChecked(undefined, line ? schema.text(line) : null);
|
|
33
|
+
});
|
|
34
|
+
return textNodes;
|
|
35
|
+
}
|
|
36
|
+
return [createTextNode(sourceNode)];
|
|
37
|
+
}
|
|
38
|
+
if ((0, _utils2.isContainerNode)(sourceNode)) {
|
|
39
|
+
var _sourceNode$attrs;
|
|
40
|
+
var containerNodes = [];
|
|
41
|
+
if (sourceNode.type.name === 'expand' && (_sourceNode$attrs = sourceNode.attrs) !== null && _sourceNode$attrs !== void 0 && _sourceNode$attrs.title) {
|
|
42
|
+
containerNodes.push(createTextNode(schema.text(sourceNode.attrs.title)));
|
|
43
|
+
}
|
|
44
|
+
sourceNode.content.forEach(function (childNode) {
|
|
45
|
+
if ((0, _utils2.isHeadingOrParagraphNode)(childNode)) {
|
|
46
|
+
containerNodes.push(createTextNode(childNode));
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
containerNodes.push(childNode);
|
|
50
|
+
});
|
|
51
|
+
return containerNodes;
|
|
52
|
+
}
|
|
53
|
+
if ((0, _utils2.isListNode)(sourceNode)) {
|
|
54
|
+
if ((0, _utils2.isBlockNodeType)(finalTargetNodeType)) {
|
|
55
|
+
if (sourceNode.type.name === 'taskList') {
|
|
56
|
+
var taskItemsResult = (0, _utils.findChildrenByType)(sourceNode, schema.nodes.taskItem);
|
|
57
|
+
var taskItems = taskItemsResult.map(function (item) {
|
|
58
|
+
return item.node;
|
|
59
|
+
});
|
|
60
|
+
var taskItemFragments = taskItems.map(function (taskItem) {
|
|
61
|
+
return taskItem.content;
|
|
62
|
+
});
|
|
63
|
+
return taskItemFragments.map(function (fragment) {
|
|
64
|
+
return targetNodeType.createChecked(targetAttrs, fragment.content);
|
|
65
|
+
});
|
|
66
|
+
} else {
|
|
67
|
+
var paragraphs = (0, _utils.findChildrenByType)(sourceNode, schema.nodes.paragraph);
|
|
68
|
+
var paragraphNodes = paragraphs.map(function (paragraph) {
|
|
69
|
+
return paragraph.node;
|
|
70
|
+
});
|
|
71
|
+
if (targetNodeType === schema.nodes.heading) {
|
|
72
|
+
return paragraphNodes.map(function (paragraphNode) {
|
|
73
|
+
return targetNodeType.createChecked(targetAttrs, paragraphNode.content);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return paragraphNodes;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return [sourceNode];
|
|
80
|
+
}
|
|
81
|
+
return [sourceNode];
|
|
82
|
+
};
|
|
83
|
+
var transformToBlockNode = function transformToBlockNode(nodes, targetNodeType, schema) {
|
|
84
|
+
if (targetNodeType === schema.nodes.codeBlock) {
|
|
85
|
+
var newNodes = [];
|
|
86
|
+
nodes.forEach(function (node) {
|
|
87
|
+
if (node.isTextblock) {
|
|
88
|
+
var inlineTextContent = node.type === schema.nodes.codeBlock ? node.textContent : (0, _inlineNodeTransforms.getInlineNodeTextContent)(_model.Fragment.from(node));
|
|
89
|
+
|
|
90
|
+
// For first node, add directly
|
|
91
|
+
if (newNodes.length === 0) {
|
|
92
|
+
newNodes.push({
|
|
93
|
+
canBeTransformed: true,
|
|
94
|
+
content: [inlineTextContent]
|
|
95
|
+
});
|
|
96
|
+
} else {
|
|
97
|
+
// Check if last node can also be transformed, if yes then append content
|
|
98
|
+
var lastItem = newNodes[newNodes.length - 1];
|
|
99
|
+
if (lastItem.canBeTransformed) {
|
|
100
|
+
newNodes[newNodes.length - 1] = {
|
|
101
|
+
content: [].concat((0, _toConsumableArray2.default)(lastItem.content), [inlineTextContent]),
|
|
102
|
+
canBeTransformed: true
|
|
103
|
+
};
|
|
104
|
+
} else {
|
|
105
|
+
newNodes.push({
|
|
106
|
+
content: [inlineTextContent],
|
|
107
|
+
canBeTransformed: true
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
} else {
|
|
112
|
+
// If not text block, then cannot be transformed
|
|
113
|
+
newNodes.push({
|
|
114
|
+
canBeTransformed: false,
|
|
115
|
+
content: node
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
return newNodes.map(function (_ref) {
|
|
120
|
+
var canBeTransformed = _ref.canBeTransformed,
|
|
121
|
+
content = _ref.content;
|
|
122
|
+
if (canBeTransformed) {
|
|
123
|
+
var text = content.join('\n');
|
|
124
|
+
if (text === '') {
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
return targetNodeType.createChecked(null, schema.text(text));
|
|
128
|
+
} else {
|
|
129
|
+
return content;
|
|
130
|
+
}
|
|
131
|
+
}).filter(Boolean);
|
|
132
|
+
}
|
|
133
|
+
return nodes;
|
|
134
|
+
};
|
|
135
|
+
var transformToContainerNode = function transformToContainerNode(nodes, targetNodeType) {
|
|
136
|
+
var newNodes = [];
|
|
137
|
+
var isNodeValid = (0, _utils2.getContentSupportChecker)(targetNodeType);
|
|
138
|
+
nodes.forEach(function (node) {
|
|
139
|
+
// If the node is not supported then we append as is
|
|
140
|
+
if ((0, _utils2.isBlockNodeForExtraction)(node)) {
|
|
141
|
+
newNodes.push({
|
|
142
|
+
node: node,
|
|
143
|
+
canBeTransformed: false
|
|
144
|
+
});
|
|
145
|
+
} else {
|
|
146
|
+
// Remove alignment marks as container nodes don't support them
|
|
147
|
+
var nodeWithValidAttrs = node.mark(node.marks.filter(function (mark) {
|
|
148
|
+
return mark.type.name !== 'alignment';
|
|
149
|
+
}));
|
|
150
|
+
var isSameNodeType = node.type === targetNodeType;
|
|
151
|
+
|
|
152
|
+
// If the node is not valid and not the same type, we cannot transform it
|
|
153
|
+
if (!isNodeValid(nodeWithValidAttrs) && !isSameNodeType) {
|
|
154
|
+
newNodes.push({
|
|
155
|
+
node: node,
|
|
156
|
+
canBeTransformed: false
|
|
157
|
+
});
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
var _nodes = isSameNodeType ? node.content.content : [nodeWithValidAttrs];
|
|
161
|
+
if (newNodes.length === 0) {
|
|
162
|
+
newNodes.push({
|
|
163
|
+
node: _nodes,
|
|
164
|
+
canBeTransformed: true
|
|
165
|
+
});
|
|
166
|
+
} else {
|
|
167
|
+
var lastItem = newNodes[newNodes.length - 1];
|
|
168
|
+
if (lastItem.canBeTransformed) {
|
|
169
|
+
newNodes[newNodes.length - 1] = {
|
|
170
|
+
node: [].concat((0, _toConsumableArray2.default)(lastItem.node), (0, _toConsumableArray2.default)(_nodes)),
|
|
171
|
+
canBeTransformed: true
|
|
172
|
+
};
|
|
173
|
+
} else {
|
|
174
|
+
newNodes.push({
|
|
175
|
+
node: _nodes,
|
|
176
|
+
canBeTransformed: true
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
return newNodes.map(function (_ref2) {
|
|
183
|
+
var node = _ref2.node,
|
|
184
|
+
canBeTransformed = _ref2.canBeTransformed;
|
|
185
|
+
if (canBeTransformed) {
|
|
186
|
+
return targetNodeType.createChecked(null, _model.Fragment.fromArray(node));
|
|
187
|
+
} else {
|
|
188
|
+
return node;
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
};
|
|
192
|
+
var transformToListNode = exports.transformToListNode = function transformToListNode(nodes, targetNodeType, schema) {
|
|
193
|
+
var isTargetTask = (0, _utils2.isTaskList)(targetNodeType);
|
|
194
|
+
var listItems = [];
|
|
195
|
+
var listItemType = isTargetTask ? schema.nodes.taskItem : schema.nodes.listItem;
|
|
196
|
+
var isValid = (0, _utils2.getContentSupportChecker)(listItemType);
|
|
197
|
+
nodes.forEach(function (node) {
|
|
198
|
+
// Append unsupported nodes as is
|
|
199
|
+
if ((0, _utils2.isBlockNodeForExtraction)(node)) {
|
|
200
|
+
listItems.push({
|
|
201
|
+
canBeTransformed: false,
|
|
202
|
+
node: node
|
|
203
|
+
});
|
|
204
|
+
} else {
|
|
205
|
+
var newListItems;
|
|
206
|
+
|
|
207
|
+
// If the node is a list, we may need to transform it
|
|
208
|
+
if ((0, _utils2.isListNode)(node)) {
|
|
209
|
+
var isSourceBulletOrOrdered = (0, _utils2.isBulletOrOrderedList)(node.type);
|
|
210
|
+
var _isTargetTask = (0, _utils2.isTaskList)(targetNodeType);
|
|
211
|
+
var isSourceTask = (0, _utils2.isTaskList)(node.type);
|
|
212
|
+
var isTargetBulletOrOrdered = (0, _utils2.isBulletOrOrderedList)(targetNodeType);
|
|
213
|
+
var supportedListTypes = (0, _utils2.getSupportedListTypesSet)(schema.nodes);
|
|
214
|
+
if (node.type === targetNodeType) {
|
|
215
|
+
// For the same list type, we can keep the structure
|
|
216
|
+
newListItems = node.content.content;
|
|
217
|
+
} else {
|
|
218
|
+
var newList = (0, _transformBetweenListTypes.transformListRecursively)({
|
|
219
|
+
isSourceBulletOrOrdered: isSourceBulletOrOrdered,
|
|
220
|
+
isSourceTask: isSourceTask,
|
|
221
|
+
isTargetBulletOrOrdered: isTargetBulletOrOrdered,
|
|
222
|
+
isTargetTask: _isTargetTask,
|
|
223
|
+
listNode: node,
|
|
224
|
+
schema: schema,
|
|
225
|
+
supportedListTypes: supportedListTypes,
|
|
226
|
+
targetNodeType: targetNodeType
|
|
227
|
+
});
|
|
228
|
+
newListItems = (0, _toConsumableArray2.default)(newList.content.content);
|
|
229
|
+
}
|
|
230
|
+
} else if ((0, _utils2.isHeadingOrParagraphNode)(node) || isValid(node)) {
|
|
231
|
+
if (isTargetTask) {
|
|
232
|
+
var inlineContent = (0, _toConsumableArray2.default)(node.content.content);
|
|
233
|
+
if (inlineContent.length > 0) {
|
|
234
|
+
newListItems = [listItemType.create(null, inlineContent)];
|
|
235
|
+
}
|
|
236
|
+
} else {
|
|
237
|
+
newListItems = [listItemType.create(null, node)];
|
|
238
|
+
}
|
|
239
|
+
} else if (!isValid(node)) {
|
|
240
|
+
listItems.push({
|
|
241
|
+
canBeTransformed: false,
|
|
242
|
+
node: node
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
if (newListItems) {
|
|
246
|
+
if (listItems.length === 0) {
|
|
247
|
+
listItems.push({
|
|
248
|
+
canBeTransformed: true,
|
|
249
|
+
node: newListItems
|
|
250
|
+
});
|
|
251
|
+
} else {
|
|
252
|
+
var lastItem = listItems[listItems.length - 1];
|
|
253
|
+
if (lastItem.canBeTransformed) {
|
|
254
|
+
listItems[listItems.length - 1] = {
|
|
255
|
+
node: [].concat((0, _toConsumableArray2.default)(lastItem.node), (0, _toConsumableArray2.default)(newListItems)),
|
|
256
|
+
canBeTransformed: true
|
|
257
|
+
};
|
|
258
|
+
} else {
|
|
259
|
+
listItems.push({
|
|
260
|
+
node: newListItems,
|
|
261
|
+
canBeTransformed: true
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
return listItems.map(function (_ref3) {
|
|
269
|
+
var node = _ref3.node,
|
|
270
|
+
canBeTransformed = _ref3.canBeTransformed;
|
|
271
|
+
if (canBeTransformed) {
|
|
272
|
+
return targetNodeType.createChecked(null, _model.Fragment.fromArray(node));
|
|
273
|
+
} else {
|
|
274
|
+
return node;
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
};
|
|
278
|
+
var convertUnwrappedLayoutContent = exports.convertUnwrappedLayoutContent = function convertUnwrappedLayoutContent(nodes, targetNodeType, schema) {
|
|
279
|
+
if ((0, _utils2.isBlockNodeType)(targetNodeType)) {
|
|
280
|
+
return transformToBlockNode(nodes, targetNodeType, schema);
|
|
281
|
+
}
|
|
282
|
+
if ((0, _utils2.isContainerNodeType)(targetNodeType)) {
|
|
283
|
+
return transformToContainerNode(nodes, targetNodeType);
|
|
284
|
+
}
|
|
285
|
+
if ((0, _utils2.isListNodeType)(targetNodeType)) {
|
|
286
|
+
return transformToListNode(nodes, targetNodeType, schema);
|
|
287
|
+
}
|
|
288
|
+
return [];
|
|
289
|
+
};
|
|
@@ -1,11 +1,14 @@
|
|
|
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
|
-
exports.convertToLayout = void 0;
|
|
7
|
+
exports.transformLayoutNode = exports.convertToLayout = void 0;
|
|
8
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
7
9
|
var _styles = require("@atlaskit/editor-common/styles");
|
|
8
10
|
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
11
|
+
var _utils = require("./layout/utils");
|
|
9
12
|
var convertToLayout = exports.convertToLayout = function convertToLayout(context) {
|
|
10
13
|
var tr = context.tr,
|
|
11
14
|
sourceNode = context.sourceNode,
|
|
@@ -25,6 +28,41 @@ var convertToLayout = exports.convertToLayout = function convertToLayout(context
|
|
|
25
28
|
var layoutSectionNode = layoutSection.createChecked(undefined, layoutContent);
|
|
26
29
|
|
|
27
30
|
// Replace the original node with the new layout node
|
|
28
|
-
tr.replaceRangeWith(sourcePos
|
|
31
|
+
tr.replaceRangeWith(sourcePos, sourcePos + sourceNode.nodeSize, layoutSectionNode);
|
|
29
32
|
return tr;
|
|
33
|
+
};
|
|
34
|
+
var transformLayoutNode = exports.transformLayoutNode = function transformLayoutNode(context) {
|
|
35
|
+
var tr = context.tr,
|
|
36
|
+
sourceNode = context.sourceNode,
|
|
37
|
+
targetNodeType = context.targetNodeType,
|
|
38
|
+
sourcePos = context.sourcePos,
|
|
39
|
+
targetAttrs = context.targetAttrs;
|
|
40
|
+
var schema = tr.doc.type.schema || {};
|
|
41
|
+
var _ref2 = schema.nodes || {},
|
|
42
|
+
layoutSection = _ref2.layoutSection,
|
|
43
|
+
layoutColumn = _ref2.layoutColumn,
|
|
44
|
+
paragraph = _ref2.paragraph,
|
|
45
|
+
heading = _ref2.heading;
|
|
46
|
+
var layoutColumnNodes = [];
|
|
47
|
+
var targetTextNodeType = targetNodeType === heading ? heading : paragraph;
|
|
48
|
+
sourceNode.children.forEach(function (child) {
|
|
49
|
+
if (child.type === layoutColumn) {
|
|
50
|
+
var unwrappedContent = [];
|
|
51
|
+
child.content.forEach(function (node) {
|
|
52
|
+
// Unwrap all nodes and convert to text nodes
|
|
53
|
+
var context = {
|
|
54
|
+
tr: tr,
|
|
55
|
+
sourceNode: node,
|
|
56
|
+
targetNodeType: targetTextNodeType,
|
|
57
|
+
sourcePos: 0,
|
|
58
|
+
targetAttrs: targetAttrs
|
|
59
|
+
};
|
|
60
|
+
var newContent = (0, _utils.unwrapLayoutNodesToTextNodes)(context, targetNodeType);
|
|
61
|
+
unwrappedContent.push.apply(unwrappedContent, (0, _toConsumableArray2.default)(newContent));
|
|
62
|
+
});
|
|
63
|
+
var newColumnContent = (0, _utils.convertUnwrappedLayoutContent)(unwrappedContent, targetNodeType, schema);
|
|
64
|
+
layoutColumnNodes.push(layoutColumn.createChecked(child.attrs, _model.Fragment.fromArray(newColumnContent), child.marks));
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
return tr.replaceRangeWith(sourcePos, sourcePos + sourceNode.nodeSize, layoutSection.createChecked(sourceNode.attrs, _model.Fragment.fromArray(layoutColumnNodes), sourceNode.marks));
|
|
30
68
|
};
|
|
@@ -4,9 +4,12 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.transformListStructure = void 0;
|
|
7
|
+
exports.transformListStructure = exports.transformListRecursively = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
8
9
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
10
|
var _utils = require("../utils");
|
|
11
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
12
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
10
13
|
/**
|
|
11
14
|
* Convert a block node to inline content suitable for task items
|
|
12
15
|
*/
|
|
@@ -21,6 +24,82 @@ var convertBlockToInlineContent = function convertBlockToInlineContent(node, sch
|
|
|
21
24
|
}
|
|
22
25
|
return [node];
|
|
23
26
|
};
|
|
27
|
+
var _transformListRecursively = exports.transformListRecursively = function transformListRecursively(props) {
|
|
28
|
+
var transformedItems = [];
|
|
29
|
+
var listNode = props.listNode,
|
|
30
|
+
isSourceBulletOrOrdered = props.isSourceBulletOrOrdered,
|
|
31
|
+
isTargetBulletOrOrdered = props.isTargetBulletOrOrdered,
|
|
32
|
+
isSourceTask = props.isSourceTask,
|
|
33
|
+
isTargetTask = props.isTargetTask,
|
|
34
|
+
supportedListTypes = props.supportedListTypes,
|
|
35
|
+
schema = props.schema,
|
|
36
|
+
targetNodeType = props.targetNodeType;
|
|
37
|
+
var _schema$nodes = schema.nodes,
|
|
38
|
+
taskList = _schema$nodes.taskList,
|
|
39
|
+
listItem = _schema$nodes.listItem,
|
|
40
|
+
taskItem = _schema$nodes.taskItem,
|
|
41
|
+
paragraph = _schema$nodes.paragraph;
|
|
42
|
+
listNode.forEach(function (child) {
|
|
43
|
+
if (isSourceBulletOrOrdered && isTargetTask) {
|
|
44
|
+
// Convert bullet/ordered => task
|
|
45
|
+
if (child.type === listItem) {
|
|
46
|
+
var inlineContent = [];
|
|
47
|
+
var nestedTaskLists = [];
|
|
48
|
+
child.forEach(function (grandChild) {
|
|
49
|
+
if (supportedListTypes.has(grandChild.type) && grandChild.type !== taskList) {
|
|
50
|
+
nestedTaskLists.push(_transformListRecursively(_objectSpread(_objectSpread({}, props), {}, {
|
|
51
|
+
listNode: grandChild
|
|
52
|
+
})));
|
|
53
|
+
} else {
|
|
54
|
+
inlineContent.push.apply(inlineContent, (0, _toConsumableArray2.default)(convertBlockToInlineContent(grandChild, schema)));
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
if (inlineContent.length > 0) {
|
|
58
|
+
transformedItems.push(taskItem.create(null, inlineContent));
|
|
59
|
+
}
|
|
60
|
+
transformedItems.push.apply(transformedItems, nestedTaskLists);
|
|
61
|
+
}
|
|
62
|
+
} else if (isSourceTask && isTargetBulletOrOrdered) {
|
|
63
|
+
// Convert task => bullet/ordered
|
|
64
|
+
if (child.type === taskItem) {
|
|
65
|
+
var _inlineContent = (0, _toConsumableArray2.default)(child.content.content);
|
|
66
|
+
if (_inlineContent.length > 0) {
|
|
67
|
+
var paragraphNode = paragraph.create(null, _inlineContent);
|
|
68
|
+
transformedItems.push(listItem.create(null, [paragraphNode]));
|
|
69
|
+
}
|
|
70
|
+
} else if (child.type === taskList) {
|
|
71
|
+
var transformedNestedList = _transformListRecursively(_objectSpread(_objectSpread({}, props), {}, {
|
|
72
|
+
listNode: child
|
|
73
|
+
}));
|
|
74
|
+
var lastItem = transformedItems[transformedItems.length - 1];
|
|
75
|
+
if ((lastItem === null || lastItem === void 0 ? void 0 : lastItem.type) === listItem) {
|
|
76
|
+
// Attach nested list to previous item
|
|
77
|
+
var updatedContent = [].concat((0, _toConsumableArray2.default)(lastItem.content.content), [transformedNestedList]);
|
|
78
|
+
transformedItems[transformedItems.length - 1] = listItem.create(lastItem.attrs, updatedContent);
|
|
79
|
+
} else {
|
|
80
|
+
// No previous item, flatten nested items
|
|
81
|
+
transformedItems.push.apply(transformedItems, (0, _toConsumableArray2.default)(transformedNestedList.content.content));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
} else if (isSourceBulletOrOrdered && isTargetBulletOrOrdered) {
|
|
85
|
+
if (child.type === listItem) {
|
|
86
|
+
var convertedNestedLists = [];
|
|
87
|
+
child.forEach(function (grandChild) {
|
|
88
|
+
if (supportedListTypes.has(grandChild.type) && grandChild.type !== targetNodeType) {
|
|
89
|
+
var convertedNode = _transformListRecursively(_objectSpread(_objectSpread({}, props), {}, {
|
|
90
|
+
listNode: grandChild
|
|
91
|
+
}));
|
|
92
|
+
convertedNestedLists.push(convertedNode);
|
|
93
|
+
} else {
|
|
94
|
+
convertedNestedLists.push(grandChild);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
transformedItems.push(listItem.create(null, convertedNestedLists));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
return targetNodeType.create(null, transformedItems);
|
|
102
|
+
};
|
|
24
103
|
|
|
25
104
|
/**
|
|
26
105
|
* Transform list structure between different list types
|
|
@@ -38,60 +117,23 @@ var transformListStructure = exports.transformListStructure = function transform
|
|
|
38
117
|
};
|
|
39
118
|
var sourceList = listNode.node,
|
|
40
119
|
listPos = listNode.pos;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
taskItem = nodes.taskItem,
|
|
44
|
-
paragraph = nodes.paragraph;
|
|
120
|
+
// const { taskList, listItem, taskItem, paragraph } = nodes;
|
|
121
|
+
|
|
45
122
|
var isSourceBulletOrOrdered = (0, _utils.isBulletOrOrderedList)(sourceList.type);
|
|
46
123
|
var isTargetTask = (0, _utils.isTaskList)(targetNodeType);
|
|
47
124
|
var isSourceTask = (0, _utils.isTaskList)(sourceList.type);
|
|
48
125
|
var isTargetBulletOrOrdered = (0, _utils.isBulletOrOrderedList)(targetNodeType);
|
|
49
126
|
var supportedListTypes = (0, _utils.getSupportedListTypesSet)(nodes);
|
|
50
|
-
var
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
nestedTaskLists.push(_transformListRecursively(grandChild));
|
|
61
|
-
} else {
|
|
62
|
-
inlineContent.push.apply(inlineContent, (0, _toConsumableArray2.default)(convertBlockToInlineContent(grandChild, tr.doc.type.schema)));
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
if (inlineContent.length > 0) {
|
|
66
|
-
transformedItems.push(taskItem.create(null, inlineContent));
|
|
67
|
-
}
|
|
68
|
-
transformedItems.push.apply(transformedItems, nestedTaskLists);
|
|
69
|
-
}
|
|
70
|
-
} else if (isSourceTask && isTargetBulletOrOrdered) {
|
|
71
|
-
// Convert task => bullet/ordered
|
|
72
|
-
if (child.type === taskItem) {
|
|
73
|
-
var _inlineContent = (0, _toConsumableArray2.default)(child.content.content);
|
|
74
|
-
if (_inlineContent.length > 0) {
|
|
75
|
-
var paragraphNode = paragraph.create(null, _inlineContent);
|
|
76
|
-
transformedItems.push(listItem.create(null, [paragraphNode]));
|
|
77
|
-
}
|
|
78
|
-
} else if (child.type === taskList) {
|
|
79
|
-
var transformedNestedList = _transformListRecursively(child);
|
|
80
|
-
var lastItem = transformedItems[transformedItems.length - 1];
|
|
81
|
-
if ((lastItem === null || lastItem === void 0 ? void 0 : lastItem.type) === listItem) {
|
|
82
|
-
// Attach nested list to previous item
|
|
83
|
-
var updatedContent = [].concat((0, _toConsumableArray2.default)(lastItem.content.content), [transformedNestedList]);
|
|
84
|
-
transformedItems[transformedItems.length - 1] = listItem.create(lastItem.attrs, updatedContent);
|
|
85
|
-
} else {
|
|
86
|
-
// No previous item, flatten nested items
|
|
87
|
-
transformedItems.push.apply(transformedItems, (0, _toConsumableArray2.default)(transformedNestedList.content.content));
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
return targetNodeType.create(null, transformedItems);
|
|
93
|
-
};
|
|
94
|
-
var newList = _transformListRecursively(sourceList);
|
|
127
|
+
var newList = _transformListRecursively({
|
|
128
|
+
isSourceBulletOrOrdered: isSourceBulletOrOrdered,
|
|
129
|
+
isSourceTask: isSourceTask,
|
|
130
|
+
isTargetBulletOrOrdered: isTargetBulletOrOrdered,
|
|
131
|
+
isTargetTask: isTargetTask,
|
|
132
|
+
listNode: sourceList,
|
|
133
|
+
schema: tr.doc.type.schema,
|
|
134
|
+
supportedListTypes: supportedListTypes,
|
|
135
|
+
targetNodeType: targetNodeType
|
|
136
|
+
});
|
|
95
137
|
tr.replaceWith(listPos, listPos + sourceList.nodeSize, newList);
|
|
96
138
|
return tr;
|
|
97
139
|
} catch (_unused) {
|
|
@@ -24,6 +24,7 @@ var transformBlockToList = exports.transformBlockToList = function transformBloc
|
|
|
24
24
|
var _tr$selection = tr.selection,
|
|
25
25
|
$from = _tr$selection.$from,
|
|
26
26
|
$to = _tr$selection.$to;
|
|
27
|
+
var schema = tr.doc.type.schema;
|
|
27
28
|
var range = $from.blockRange($to);
|
|
28
29
|
if (!range) {
|
|
29
30
|
return null;
|
|
@@ -36,6 +37,12 @@ var transformBlockToList = exports.transformBlockToList = function transformBloc
|
|
|
36
37
|
return (0, _transformToTaskList.transformToTaskList)(tr, range, targetNodeType, targetAttrs, nodes);
|
|
37
38
|
}
|
|
38
39
|
|
|
40
|
+
// filter marks that are not allowed in the target node type
|
|
41
|
+
if (sourceNode.type === schema.nodes.paragraph || sourceNode.type === schema.nodes.heading) {
|
|
42
|
+
var allowedMarks = targetNodeType.allowedMarks(sourceNode.marks);
|
|
43
|
+
tr.setNodeMarkup(range.start, null, null, allowedMarks);
|
|
44
|
+
}
|
|
45
|
+
|
|
39
46
|
// For headings, convert to paragraph first since headings cannot be direct children of list items
|
|
40
47
|
if (sourceNode && sourceNode.type.name.startsWith('heading')) {
|
|
41
48
|
tr.setBlockType(range.start, range.end, nodes.paragraph);
|