@atlaskit/editor-plugin-block-menu 3.0.1 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/cjs/editor-commands/transforms/inline-node-transforms.js +1 -1
- package/dist/cjs/editor-commands/transforms/layout/utils.js +94 -44
- package/dist/cjs/editor-commands/transforms/list/transformBetweenListTypes.js +3 -7
- package/dist/es2019/editor-commands/transforms/inline-node-transforms.js +1 -1
- package/dist/es2019/editor-commands/transforms/layout/utils.js +91 -45
- package/dist/es2019/editor-commands/transforms/list/transformBetweenListTypes.js +3 -7
- package/dist/esm/editor-commands/transforms/inline-node-transforms.js +1 -1
- package/dist/esm/editor-commands/transforms/layout/utils.js +94 -44
- package/dist/esm/editor-commands/transforms/list/transformBetweenListTypes.js +3 -7
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-menu
|
|
2
2
|
|
|
3
|
+
## 3.0.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`d6f3f3b09ebff`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/d6f3f3b09ebff) -
|
|
8
|
+
[ux] ED-29255 Fix layout transformation when column is empty, transform nested lists to match
|
|
9
|
+
container to list transformations and fix task list transforms when task item is empty
|
|
10
|
+
|
|
3
11
|
## 3.0.1
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
|
@@ -11,7 +11,7 @@ var getInlineNodeTextContent = exports.getInlineNodeTextContent = function getIn
|
|
|
11
11
|
}
|
|
12
12
|
// Headings are not valid inside headings so convert heading nodes to paragraphs
|
|
13
13
|
sourceContent.forEach(function (node) {
|
|
14
|
-
if (['paragraph', 'heading'].includes(node.type.name)) {
|
|
14
|
+
if (['paragraph', 'heading', 'taskItem'].includes(node.type.name)) {
|
|
15
15
|
node.content.forEach(function (inlineNode) {
|
|
16
16
|
if (inlineNode.type.name === 'status') {
|
|
17
17
|
validTransformedContent += inlineNode.attrs.text;
|
|
@@ -80,57 +80,104 @@ var unwrapLayoutNodesToTextNodes = exports.unwrapLayoutNodesToTextNodes = functi
|
|
|
80
80
|
}
|
|
81
81
|
return [sourceNode];
|
|
82
82
|
};
|
|
83
|
-
var
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
-
}
|
|
83
|
+
var transformToCodeBlock = function transformToCodeBlock(nodes, schema) {
|
|
84
|
+
var newNodes = [];
|
|
85
|
+
var addToNewNodes = function addToNewNodes(content) {
|
|
86
|
+
if (newNodes.length === 0) {
|
|
87
|
+
newNodes.push({
|
|
88
|
+
canBeTransformed: true,
|
|
89
|
+
content: content
|
|
90
|
+
});
|
|
91
|
+
} else {
|
|
92
|
+
// Check if last node can also be transformed, if yes then append content
|
|
93
|
+
var lastItem = newNodes[newNodes.length - 1];
|
|
94
|
+
if (lastItem.canBeTransformed) {
|
|
95
|
+
newNodes[newNodes.length - 1] = {
|
|
96
|
+
content: [].concat((0, _toConsumableArray2.default)(lastItem.content), (0, _toConsumableArray2.default)(content)),
|
|
97
|
+
canBeTransformed: true
|
|
98
|
+
};
|
|
111
99
|
} else {
|
|
112
|
-
// If not text block, then cannot be transformed
|
|
113
100
|
newNodes.push({
|
|
114
|
-
|
|
115
|
-
|
|
101
|
+
content: content,
|
|
102
|
+
canBeTransformed: true
|
|
116
103
|
});
|
|
117
104
|
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
nodes.forEach(function (node) {
|
|
108
|
+
if (node.isTextblock) {
|
|
109
|
+
var inlineTextContent = node.type === schema.nodes.codeBlock ? node.textContent : (0, _inlineNodeTransforms.getInlineNodeTextContent)(_model.Fragment.from(node));
|
|
110
|
+
|
|
111
|
+
// For first node, add directly
|
|
112
|
+
addToNewNodes([inlineTextContent]);
|
|
113
|
+
} else if ((0, _utils2.isListNode)(node)) {
|
|
114
|
+
var textContent = [];
|
|
115
|
+
var listItemType = node.type === schema.nodes.taskList ? schema.nodes.taskItem : schema.nodes.listItem;
|
|
116
|
+
var listItems = (0, _utils.findChildrenByType)(node, listItemType).map(function (item) {
|
|
117
|
+
return item.node;
|
|
118
|
+
});
|
|
119
|
+
listItems.forEach(function (listItem) {
|
|
120
|
+
if (listItem.type === schema.nodes.taskItem) {
|
|
121
|
+
var _inlineTextContent = (0, _inlineNodeTransforms.getInlineNodeTextContent)(_model.Fragment.from(listItem));
|
|
122
|
+
textContent.push(_inlineTextContent);
|
|
123
|
+
} else {
|
|
124
|
+
var _inlineTextContent2 = (0, _inlineNodeTransforms.getInlineNodeTextContent)(listItem.content);
|
|
125
|
+
textContent.push(_inlineTextContent2);
|
|
126
126
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
127
|
+
});
|
|
128
|
+
addToNewNodes(textContent);
|
|
129
|
+
} else {
|
|
130
|
+
// If not text block or list node, then cannot be transformed
|
|
131
|
+
newNodes.push({
|
|
132
|
+
canBeTransformed: false,
|
|
133
|
+
content: node
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
return newNodes.map(function (_ref) {
|
|
138
|
+
var canBeTransformed = _ref.canBeTransformed,
|
|
139
|
+
content = _ref.content;
|
|
140
|
+
if (canBeTransformed) {
|
|
141
|
+
var text = content.join('\n');
|
|
142
|
+
if (text === '') {
|
|
143
|
+
return undefined;
|
|
130
144
|
}
|
|
131
|
-
|
|
145
|
+
return schema.nodes.codeBlock.createChecked(null, schema.text(text));
|
|
146
|
+
} else {
|
|
147
|
+
return content;
|
|
148
|
+
}
|
|
149
|
+
}).filter(Boolean);
|
|
150
|
+
};
|
|
151
|
+
var transformToBlockNode = function transformToBlockNode(nodes, targetNodeType, schema) {
|
|
152
|
+
if (targetNodeType === schema.nodes.codeBlock) {
|
|
153
|
+
return transformToCodeBlock(nodes, schema);
|
|
132
154
|
}
|
|
133
|
-
|
|
155
|
+
var newNodes = [];
|
|
156
|
+
nodes.forEach(function (node) {
|
|
157
|
+
if ((0, _utils2.isListNode)(node)) {
|
|
158
|
+
var listItemType = node.type === schema.nodes.taskList ? schema.nodes.taskItem : schema.nodes.listItem;
|
|
159
|
+
var listItems = (0, _utils.findChildrenByType)(node, listItemType).map(function (item) {
|
|
160
|
+
return item.node;
|
|
161
|
+
});
|
|
162
|
+
listItems.forEach(function (listItem) {
|
|
163
|
+
if (listItem.type === schema.nodes.taskItem) {
|
|
164
|
+
var inlineContent = (0, _toConsumableArray2.default)(listItem.content.content);
|
|
165
|
+
if (inlineContent.length > 0) {
|
|
166
|
+
newNodes.push(targetNodeType.createChecked(null, inlineContent));
|
|
167
|
+
}
|
|
168
|
+
} else {
|
|
169
|
+
listItem.forEach(function (child) {
|
|
170
|
+
if ((0, _utils2.isHeadingOrParagraphNode)(child)) {
|
|
171
|
+
newNodes.push(targetNodeType.createChecked(null, (0, _toConsumableArray2.default)(child.content.content)));
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
} else {
|
|
177
|
+
newNodes.push(node);
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
return newNodes;
|
|
134
181
|
};
|
|
135
182
|
var transformToContainerNode = function transformToContainerNode(nodes, targetNodeType) {
|
|
136
183
|
var newNodes = [];
|
|
@@ -276,6 +323,9 @@ var transformToListNode = exports.transformToListNode = function transformToList
|
|
|
276
323
|
});
|
|
277
324
|
};
|
|
278
325
|
var convertUnwrappedLayoutContent = exports.convertUnwrappedLayoutContent = function convertUnwrappedLayoutContent(nodes, targetNodeType, schema) {
|
|
326
|
+
if (nodes.length === 1 && nodes[0].content.size === 0) {
|
|
327
|
+
return nodes;
|
|
328
|
+
}
|
|
279
329
|
if ((0, _utils2.isBlockNodeType)(targetNodeType)) {
|
|
280
330
|
return transformToBlockNode(nodes, targetNodeType, schema);
|
|
281
331
|
}
|
|
@@ -54,19 +54,15 @@ var _transformListRecursively = exports.transformListRecursively = function tran
|
|
|
54
54
|
inlineContent.push.apply(inlineContent, (0, _toConsumableArray2.default)(convertBlockToInlineContent(grandChild, schema)));
|
|
55
55
|
}
|
|
56
56
|
});
|
|
57
|
-
|
|
58
|
-
transformedItems.push(taskItem.create(null, inlineContent));
|
|
59
|
-
}
|
|
57
|
+
transformedItems.push(taskItem.create(null, inlineContent.length > 0 ? inlineContent : null));
|
|
60
58
|
transformedItems.push.apply(transformedItems, nestedTaskLists);
|
|
61
59
|
}
|
|
62
60
|
} else if (isSourceTask && isTargetBulletOrOrdered) {
|
|
63
61
|
// Convert task => bullet/ordered
|
|
64
62
|
if (child.type === taskItem) {
|
|
65
63
|
var _inlineContent = (0, _toConsumableArray2.default)(child.content.content);
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
transformedItems.push(listItem.create(null, [paragraphNode]));
|
|
69
|
-
}
|
|
64
|
+
var paragraphNode = paragraph.create(null, _inlineContent.length > 0 ? _inlineContent : null);
|
|
65
|
+
transformedItems.push(listItem.create(null, [paragraphNode]));
|
|
70
66
|
} else if (child.type === taskList) {
|
|
71
67
|
var transformedNestedList = _transformListRecursively(_objectSpread(_objectSpread({}, props), {}, {
|
|
72
68
|
listNode: child
|
|
@@ -5,7 +5,7 @@ export const getInlineNodeTextContent = sourceContent => {
|
|
|
5
5
|
}
|
|
6
6
|
// Headings are not valid inside headings so convert heading nodes to paragraphs
|
|
7
7
|
sourceContent.forEach(node => {
|
|
8
|
-
if (['paragraph', 'heading'].includes(node.type.name)) {
|
|
8
|
+
if (['paragraph', 'heading', 'taskItem'].includes(node.type.name)) {
|
|
9
9
|
node.content.forEach(inlineNode => {
|
|
10
10
|
if (inlineNode.type.name === 'status') {
|
|
11
11
|
validTransformedContent += inlineNode.attrs.text;
|
|
@@ -62,58 +62,101 @@ export const unwrapLayoutNodesToTextNodes = (context, finalTargetNodeType) => {
|
|
|
62
62
|
}
|
|
63
63
|
return [sourceNode];
|
|
64
64
|
};
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (lastItem.canBeTransformed) {
|
|
82
|
-
newNodes[newNodes.length - 1] = {
|
|
83
|
-
content: [...lastItem.content, inlineTextContent],
|
|
84
|
-
canBeTransformed: true
|
|
85
|
-
};
|
|
86
|
-
} else {
|
|
87
|
-
newNodes.push({
|
|
88
|
-
content: [inlineTextContent],
|
|
89
|
-
canBeTransformed: true
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
}
|
|
65
|
+
const transformToCodeBlock = (nodes, schema) => {
|
|
66
|
+
const newNodes = [];
|
|
67
|
+
const addToNewNodes = content => {
|
|
68
|
+
if (newNodes.length === 0) {
|
|
69
|
+
newNodes.push({
|
|
70
|
+
canBeTransformed: true,
|
|
71
|
+
content
|
|
72
|
+
});
|
|
73
|
+
} else {
|
|
74
|
+
// Check if last node can also be transformed, if yes then append content
|
|
75
|
+
const lastItem = newNodes[newNodes.length - 1];
|
|
76
|
+
if (lastItem.canBeTransformed) {
|
|
77
|
+
newNodes[newNodes.length - 1] = {
|
|
78
|
+
content: [...lastItem.content, ...content],
|
|
79
|
+
canBeTransformed: true
|
|
80
|
+
};
|
|
93
81
|
} else {
|
|
94
|
-
// If not text block, then cannot be transformed
|
|
95
82
|
newNodes.push({
|
|
96
|
-
|
|
97
|
-
|
|
83
|
+
content,
|
|
84
|
+
canBeTransformed: true
|
|
98
85
|
});
|
|
99
86
|
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
nodes.forEach(node => {
|
|
90
|
+
if (node.isTextblock) {
|
|
91
|
+
const inlineTextContent = node.type === schema.nodes.codeBlock ? node.textContent : getInlineNodeTextContent(Fragment.from(node));
|
|
92
|
+
|
|
93
|
+
// For first node, add directly
|
|
94
|
+
addToNewNodes([inlineTextContent]);
|
|
95
|
+
} else if (isListNode(node)) {
|
|
96
|
+
const textContent = [];
|
|
97
|
+
const listItemType = node.type === schema.nodes.taskList ? schema.nodes.taskItem : schema.nodes.listItem;
|
|
98
|
+
const listItems = findChildrenByType(node, listItemType).map(item => item.node);
|
|
99
|
+
listItems.forEach(listItem => {
|
|
100
|
+
if (listItem.type === schema.nodes.taskItem) {
|
|
101
|
+
const inlineTextContent = getInlineNodeTextContent(Fragment.from(listItem));
|
|
102
|
+
textContent.push(inlineTextContent);
|
|
103
|
+
} else {
|
|
104
|
+
const inlineTextContent = getInlineNodeTextContent(listItem.content);
|
|
105
|
+
textContent.push(inlineTextContent);
|
|
109
106
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
107
|
+
});
|
|
108
|
+
addToNewNodes(textContent);
|
|
109
|
+
} else {
|
|
110
|
+
// If not text block or list node, then cannot be transformed
|
|
111
|
+
newNodes.push({
|
|
112
|
+
canBeTransformed: false,
|
|
113
|
+
content: node
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
return newNodes.map(({
|
|
118
|
+
canBeTransformed,
|
|
119
|
+
content
|
|
120
|
+
}) => {
|
|
121
|
+
if (canBeTransformed) {
|
|
122
|
+
const text = content.join('\n');
|
|
123
|
+
if (text === '') {
|
|
124
|
+
return undefined;
|
|
113
125
|
}
|
|
114
|
-
|
|
126
|
+
return schema.nodes.codeBlock.createChecked(null, schema.text(text));
|
|
127
|
+
} else {
|
|
128
|
+
return content;
|
|
129
|
+
}
|
|
130
|
+
}).filter(Boolean);
|
|
131
|
+
};
|
|
132
|
+
const transformToBlockNode = (nodes, targetNodeType, schema) => {
|
|
133
|
+
if (targetNodeType === schema.nodes.codeBlock) {
|
|
134
|
+
return transformToCodeBlock(nodes, schema);
|
|
115
135
|
}
|
|
116
|
-
|
|
136
|
+
const newNodes = [];
|
|
137
|
+
nodes.forEach(node => {
|
|
138
|
+
if (isListNode(node)) {
|
|
139
|
+
const listItemType = node.type === schema.nodes.taskList ? schema.nodes.taskItem : schema.nodes.listItem;
|
|
140
|
+
const listItems = findChildrenByType(node, listItemType).map(item => item.node);
|
|
141
|
+
listItems.forEach(listItem => {
|
|
142
|
+
if (listItem.type === schema.nodes.taskItem) {
|
|
143
|
+
const inlineContent = [...listItem.content.content];
|
|
144
|
+
if (inlineContent.length > 0) {
|
|
145
|
+
newNodes.push(targetNodeType.createChecked(null, inlineContent));
|
|
146
|
+
}
|
|
147
|
+
} else {
|
|
148
|
+
listItem.forEach(child => {
|
|
149
|
+
if (isHeadingOrParagraphNode(child)) {
|
|
150
|
+
newNodes.push(targetNodeType.createChecked(null, [...child.content.content]));
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
} else {
|
|
156
|
+
newNodes.push(node);
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
return newNodes;
|
|
117
160
|
};
|
|
118
161
|
const transformToContainerNode = (nodes, targetNodeType) => {
|
|
119
162
|
const newNodes = [];
|
|
@@ -259,6 +302,9 @@ export const transformToListNode = (nodes, targetNodeType, schema) => {
|
|
|
259
302
|
});
|
|
260
303
|
};
|
|
261
304
|
export const convertUnwrappedLayoutContent = (nodes, targetNodeType, schema) => {
|
|
305
|
+
if (nodes.length === 1 && nodes[0].content.size === 0) {
|
|
306
|
+
return nodes;
|
|
307
|
+
}
|
|
262
308
|
if (isBlockNodeType(targetNodeType)) {
|
|
263
309
|
return transformToBlockNode(nodes, targetNodeType, schema);
|
|
264
310
|
}
|
|
@@ -50,19 +50,15 @@ export const transformListRecursively = props => {
|
|
|
50
50
|
inlineContent.push(...convertBlockToInlineContent(grandChild, schema));
|
|
51
51
|
}
|
|
52
52
|
});
|
|
53
|
-
|
|
54
|
-
transformedItems.push(taskItem.create(null, inlineContent));
|
|
55
|
-
}
|
|
53
|
+
transformedItems.push(taskItem.create(null, inlineContent.length > 0 ? inlineContent : null));
|
|
56
54
|
transformedItems.push(...nestedTaskLists);
|
|
57
55
|
}
|
|
58
56
|
} else if (isSourceTask && isTargetBulletOrOrdered) {
|
|
59
57
|
// Convert task => bullet/ordered
|
|
60
58
|
if (child.type === taskItem) {
|
|
61
59
|
const inlineContent = [...child.content.content];
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
transformedItems.push(listItem.create(null, [paragraphNode]));
|
|
65
|
-
}
|
|
60
|
+
const paragraphNode = paragraph.create(null, inlineContent.length > 0 ? inlineContent : null);
|
|
61
|
+
transformedItems.push(listItem.create(null, [paragraphNode]));
|
|
66
62
|
} else if (child.type === taskList) {
|
|
67
63
|
const transformedNestedList = transformListRecursively({
|
|
68
64
|
...props,
|
|
@@ -5,7 +5,7 @@ export var getInlineNodeTextContent = function getInlineNodeTextContent(sourceCo
|
|
|
5
5
|
}
|
|
6
6
|
// Headings are not valid inside headings so convert heading nodes to paragraphs
|
|
7
7
|
sourceContent.forEach(function (node) {
|
|
8
|
-
if (['paragraph', 'heading'].includes(node.type.name)) {
|
|
8
|
+
if (['paragraph', 'heading', 'taskItem'].includes(node.type.name)) {
|
|
9
9
|
node.content.forEach(function (inlineNode) {
|
|
10
10
|
if (inlineNode.type.name === 'status') {
|
|
11
11
|
validTransformedContent += inlineNode.attrs.text;
|
|
@@ -73,57 +73,104 @@ export var unwrapLayoutNodesToTextNodes = function unwrapLayoutNodesToTextNodes(
|
|
|
73
73
|
}
|
|
74
74
|
return [sourceNode];
|
|
75
75
|
};
|
|
76
|
-
var
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (lastItem.canBeTransformed) {
|
|
93
|
-
newNodes[newNodes.length - 1] = {
|
|
94
|
-
content: [].concat(_toConsumableArray(lastItem.content), [inlineTextContent]),
|
|
95
|
-
canBeTransformed: true
|
|
96
|
-
};
|
|
97
|
-
} else {
|
|
98
|
-
newNodes.push({
|
|
99
|
-
content: [inlineTextContent],
|
|
100
|
-
canBeTransformed: true
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
}
|
|
76
|
+
var transformToCodeBlock = function transformToCodeBlock(nodes, schema) {
|
|
77
|
+
var newNodes = [];
|
|
78
|
+
var addToNewNodes = function addToNewNodes(content) {
|
|
79
|
+
if (newNodes.length === 0) {
|
|
80
|
+
newNodes.push({
|
|
81
|
+
canBeTransformed: true,
|
|
82
|
+
content: content
|
|
83
|
+
});
|
|
84
|
+
} else {
|
|
85
|
+
// Check if last node can also be transformed, if yes then append content
|
|
86
|
+
var lastItem = newNodes[newNodes.length - 1];
|
|
87
|
+
if (lastItem.canBeTransformed) {
|
|
88
|
+
newNodes[newNodes.length - 1] = {
|
|
89
|
+
content: [].concat(_toConsumableArray(lastItem.content), _toConsumableArray(content)),
|
|
90
|
+
canBeTransformed: true
|
|
91
|
+
};
|
|
104
92
|
} else {
|
|
105
|
-
// If not text block, then cannot be transformed
|
|
106
93
|
newNodes.push({
|
|
107
|
-
|
|
108
|
-
|
|
94
|
+
content: content,
|
|
95
|
+
canBeTransformed: true
|
|
109
96
|
});
|
|
110
97
|
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
nodes.forEach(function (node) {
|
|
101
|
+
if (node.isTextblock) {
|
|
102
|
+
var inlineTextContent = node.type === schema.nodes.codeBlock ? node.textContent : getInlineNodeTextContent(Fragment.from(node));
|
|
103
|
+
|
|
104
|
+
// For first node, add directly
|
|
105
|
+
addToNewNodes([inlineTextContent]);
|
|
106
|
+
} else if (isListNode(node)) {
|
|
107
|
+
var textContent = [];
|
|
108
|
+
var listItemType = node.type === schema.nodes.taskList ? schema.nodes.taskItem : schema.nodes.listItem;
|
|
109
|
+
var listItems = findChildrenByType(node, listItemType).map(function (item) {
|
|
110
|
+
return item.node;
|
|
111
|
+
});
|
|
112
|
+
listItems.forEach(function (listItem) {
|
|
113
|
+
if (listItem.type === schema.nodes.taskItem) {
|
|
114
|
+
var _inlineTextContent = getInlineNodeTextContent(Fragment.from(listItem));
|
|
115
|
+
textContent.push(_inlineTextContent);
|
|
116
|
+
} else {
|
|
117
|
+
var _inlineTextContent2 = getInlineNodeTextContent(listItem.content);
|
|
118
|
+
textContent.push(_inlineTextContent2);
|
|
119
119
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
120
|
+
});
|
|
121
|
+
addToNewNodes(textContent);
|
|
122
|
+
} else {
|
|
123
|
+
// If not text block or list node, then cannot be transformed
|
|
124
|
+
newNodes.push({
|
|
125
|
+
canBeTransformed: false,
|
|
126
|
+
content: node
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
return newNodes.map(function (_ref) {
|
|
131
|
+
var canBeTransformed = _ref.canBeTransformed,
|
|
132
|
+
content = _ref.content;
|
|
133
|
+
if (canBeTransformed) {
|
|
134
|
+
var text = content.join('\n');
|
|
135
|
+
if (text === '') {
|
|
136
|
+
return undefined;
|
|
123
137
|
}
|
|
124
|
-
|
|
138
|
+
return schema.nodes.codeBlock.createChecked(null, schema.text(text));
|
|
139
|
+
} else {
|
|
140
|
+
return content;
|
|
141
|
+
}
|
|
142
|
+
}).filter(Boolean);
|
|
143
|
+
};
|
|
144
|
+
var transformToBlockNode = function transformToBlockNode(nodes, targetNodeType, schema) {
|
|
145
|
+
if (targetNodeType === schema.nodes.codeBlock) {
|
|
146
|
+
return transformToCodeBlock(nodes, schema);
|
|
125
147
|
}
|
|
126
|
-
|
|
148
|
+
var newNodes = [];
|
|
149
|
+
nodes.forEach(function (node) {
|
|
150
|
+
if (isListNode(node)) {
|
|
151
|
+
var listItemType = node.type === schema.nodes.taskList ? schema.nodes.taskItem : schema.nodes.listItem;
|
|
152
|
+
var listItems = findChildrenByType(node, listItemType).map(function (item) {
|
|
153
|
+
return item.node;
|
|
154
|
+
});
|
|
155
|
+
listItems.forEach(function (listItem) {
|
|
156
|
+
if (listItem.type === schema.nodes.taskItem) {
|
|
157
|
+
var inlineContent = _toConsumableArray(listItem.content.content);
|
|
158
|
+
if (inlineContent.length > 0) {
|
|
159
|
+
newNodes.push(targetNodeType.createChecked(null, inlineContent));
|
|
160
|
+
}
|
|
161
|
+
} else {
|
|
162
|
+
listItem.forEach(function (child) {
|
|
163
|
+
if (isHeadingOrParagraphNode(child)) {
|
|
164
|
+
newNodes.push(targetNodeType.createChecked(null, _toConsumableArray(child.content.content)));
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
} else {
|
|
170
|
+
newNodes.push(node);
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
return newNodes;
|
|
127
174
|
};
|
|
128
175
|
var transformToContainerNode = function transformToContainerNode(nodes, targetNodeType) {
|
|
129
176
|
var newNodes = [];
|
|
@@ -269,6 +316,9 @@ export var transformToListNode = function transformToListNode(nodes, targetNodeT
|
|
|
269
316
|
});
|
|
270
317
|
};
|
|
271
318
|
export var convertUnwrappedLayoutContent = function convertUnwrappedLayoutContent(nodes, targetNodeType, schema) {
|
|
319
|
+
if (nodes.length === 1 && nodes[0].content.size === 0) {
|
|
320
|
+
return nodes;
|
|
321
|
+
}
|
|
272
322
|
if (isBlockNodeType(targetNodeType)) {
|
|
273
323
|
return transformToBlockNode(nodes, targetNodeType, schema);
|
|
274
324
|
}
|
|
@@ -48,19 +48,15 @@ var _transformListRecursively = function transformListRecursively(props) {
|
|
|
48
48
|
inlineContent.push.apply(inlineContent, _toConsumableArray(convertBlockToInlineContent(grandChild, schema)));
|
|
49
49
|
}
|
|
50
50
|
});
|
|
51
|
-
|
|
52
|
-
transformedItems.push(taskItem.create(null, inlineContent));
|
|
53
|
-
}
|
|
51
|
+
transformedItems.push(taskItem.create(null, inlineContent.length > 0 ? inlineContent : null));
|
|
54
52
|
transformedItems.push.apply(transformedItems, nestedTaskLists);
|
|
55
53
|
}
|
|
56
54
|
} else if (isSourceTask && isTargetBulletOrOrdered) {
|
|
57
55
|
// Convert task => bullet/ordered
|
|
58
56
|
if (child.type === taskItem) {
|
|
59
57
|
var _inlineContent = _toConsumableArray(child.content.content);
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
transformedItems.push(listItem.create(null, [paragraphNode]));
|
|
63
|
-
}
|
|
58
|
+
var paragraphNode = paragraph.create(null, _inlineContent.length > 0 ? _inlineContent : null);
|
|
59
|
+
transformedItems.push(listItem.create(null, [paragraphNode]));
|
|
64
60
|
} else if (child.type === taskList) {
|
|
65
61
|
var transformedNestedList = _transformListRecursively(_objectSpread(_objectSpread({}, props), {}, {
|
|
66
62
|
listNode: child
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-block-menu",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
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.1.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",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"@babel/runtime": "^7.0.0"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
|
-
"@atlaskit/editor-common": "^109.
|
|
49
|
+
"@atlaskit/editor-common": "^109.3.0",
|
|
50
50
|
"react": "^18.2.0",
|
|
51
51
|
"react-intl-next": "npm:react-intl@^5.18.1"
|
|
52
52
|
},
|