@atlaskit/editor-plugin-block-menu 5.2.8 → 5.2.9
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 +9 -0
- package/dist/cjs/editor-actions/index.js +3 -13
- package/dist/cjs/editor-commands/transform-node-utils/steps/listToDecisionListStep.js +12 -12
- package/dist/cjs/editor-commands/transform-node-utils/steps/listToListStep.js +96 -119
- package/dist/es2019/editor-actions/index.js +1 -11
- package/dist/es2019/editor-commands/transform-node-utils/steps/listToDecisionListStep.js +10 -12
- package/dist/es2019/editor-commands/transform-node-utils/steps/listToListStep.js +93 -118
- package/dist/esm/editor-actions/index.js +2 -13
- package/dist/esm/editor-commands/transform-node-utils/steps/listToDecisionListStep.js +11 -12
- package/dist/esm/editor-commands/transform-node-utils/steps/listToListStep.js +95 -119
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-menu
|
|
2
2
|
|
|
3
|
+
## 5.2.9
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`3d03e8b001dab`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/3d03e8b001dab) -
|
|
8
|
+
Add logic to handle unsupported content for list to task/decision list
|
|
9
|
+
- [`b831109342cdf`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/b831109342cdf) -
|
|
10
|
+
EDITOR-3880 Register block menu selection extensions statically
|
|
11
|
+
|
|
3
12
|
## 5.2.8
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
|
@@ -1,9 +1,11 @@
|
|
|
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.createBlockMenuRegistry = void 0;
|
|
8
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
7
9
|
/**
|
|
8
10
|
* Create a simple registry for block menu components.
|
|
9
11
|
*
|
|
@@ -54,19 +56,7 @@ exports.createBlockMenuRegistry = void 0;
|
|
|
54
56
|
var createBlockMenuRegistry = exports.createBlockMenuRegistry = function createBlockMenuRegistry() {
|
|
55
57
|
var components = [];
|
|
56
58
|
var register = function register(blockMenuComponents) {
|
|
57
|
-
|
|
58
|
-
// Find if a component with the same key already exists
|
|
59
|
-
var existingIndex = components.findIndex(function (comp) {
|
|
60
|
-
return comp.key === newComponent.key;
|
|
61
|
-
});
|
|
62
|
-
if (existingIndex !== -1) {
|
|
63
|
-
// Replace the existing component
|
|
64
|
-
components[existingIndex] = newComponent;
|
|
65
|
-
} else {
|
|
66
|
-
// Add new component
|
|
67
|
-
components.push(newComponent);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
59
|
+
components.push.apply(components, (0, _toConsumableArray2.default)(blockMenuComponents));
|
|
70
60
|
};
|
|
71
61
|
return {
|
|
72
62
|
register: register,
|
|
@@ -1,10 +1,11 @@
|
|
|
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.listToDecisionListStep = void 0;
|
|
7
|
-
var
|
|
8
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
8
9
|
var _utils = require("../utils");
|
|
9
10
|
/**
|
|
10
11
|
* Transforms a bulletList, orderedList, or taskList into a decisionList.
|
|
@@ -32,7 +33,8 @@ var _utils = require("../utils");
|
|
|
32
33
|
var listToDecisionListStep = exports.listToDecisionListStep = function listToDecisionListStep(nodes, context) {
|
|
33
34
|
var schema = context.schema;
|
|
34
35
|
var paragraphType = schema.nodes.paragraph;
|
|
35
|
-
|
|
36
|
+
var unsupportedContent = [];
|
|
37
|
+
var transformedNodes = nodes.map(function (node) {
|
|
36
38
|
if (!(0, _utils.isListType)(node, schema)) {
|
|
37
39
|
return node;
|
|
38
40
|
}
|
|
@@ -42,20 +44,18 @@ var listToDecisionListStep = exports.listToDecisionListStep = function listToDec
|
|
|
42
44
|
item.forEach(function (child) {
|
|
43
45
|
if (child.type === paragraphType) {
|
|
44
46
|
// paragraph may contain hard breaks etc.
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
});
|
|
48
|
-
} else {
|
|
47
|
+
itemContent.push.apply(itemContent, (0, _toConsumableArray2.default)(child.children));
|
|
48
|
+
} else if (child.isText) {
|
|
49
49
|
itemContent.push(child);
|
|
50
|
+
} else if (!(0, _utils.isListType)(child, schema)) {
|
|
51
|
+
unsupportedContent.push(child);
|
|
50
52
|
}
|
|
51
|
-
// TODO: EDITOR-3887 - Skip mediaSingle, codeBlock, and nested lists
|
|
52
53
|
});
|
|
53
|
-
var decisionItem = schema.nodes.decisionItem.create({},
|
|
54
|
-
|
|
55
|
-
decisionItems.push(decisionItem);
|
|
56
|
-
}
|
|
54
|
+
var decisionItem = schema.nodes.decisionItem.create({}, itemContent);
|
|
55
|
+
decisionItems.push(decisionItem);
|
|
57
56
|
});
|
|
58
|
-
var decisionList = schema.nodes.decisionList.create({},
|
|
57
|
+
var decisionList = schema.nodes.decisionList.create({}, decisionItems);
|
|
59
58
|
return decisionList || node;
|
|
60
59
|
});
|
|
60
|
+
return [].concat((0, _toConsumableArray2.default)(transformedNodes), unsupportedContent);
|
|
61
61
|
};
|
|
@@ -1,153 +1,128 @@
|
|
|
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.listToListStep = 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("../utils");
|
|
9
11
|
/**
|
|
10
|
-
*
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if ((0, _utils.isListType)(child, schema)) {
|
|
18
|
-
// This is a nested list - it should become a child of the previous item
|
|
19
|
-
if (convertedItems.length > 0) {
|
|
20
|
-
var previousItem = convertedItems[convertedItems.length - 1];
|
|
21
|
-
// Convert the nested list and add it to the previous item's content
|
|
22
|
-
var convertedNestedList = _transformList(child, targetListType, targetItemType);
|
|
23
|
-
var newContent = previousItem.content.append(_model.Fragment.from([convertedNestedList]));
|
|
24
|
-
var updatedItem = previousItem.type.create(previousItem.attrs, newContent);
|
|
25
|
-
convertedItems[convertedItems.length - 1] = updatedItem;
|
|
26
|
-
}
|
|
27
|
-
// If there's no previous item, skip this nested list (orphaned)
|
|
28
|
-
} else {
|
|
29
|
-
var convertedItem = transformListItem(child, targetItemType, targetListType);
|
|
30
|
-
if (convertedItem) {
|
|
31
|
-
convertedItems.push(convertedItem);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
return targetListNodeType.create(node.attrs, _model.Fragment.from(convertedItems));
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Converts FROM bulletList/orderedList structure TO taskList structure.
|
|
12
|
+
* Recursively converts nested lists to the target list type.
|
|
13
|
+
* This function handles the conversion of both the list container and its items,
|
|
14
|
+
* including any nested lists within those items.
|
|
15
|
+
*
|
|
16
|
+
* Important: taskList has a different nesting structure than bulletList/orderedList:
|
|
17
|
+
* - taskList: nested taskLists are SIBLINGS of taskItems in the parent taskList
|
|
18
|
+
* - bulletList/orderedList: nested lists are CHILDREN of listItems
|
|
40
19
|
*/
|
|
41
|
-
var
|
|
20
|
+
var _transformList = function transformList(node, targetListType, targetItemType, unsupportedContent) {
|
|
42
21
|
var schema = node.type.schema;
|
|
43
|
-
var
|
|
44
|
-
var
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
22
|
+
var taskListType = schema.nodes.taskList;
|
|
23
|
+
var isSourceTaskList = node.type === taskListType;
|
|
24
|
+
var isTargetTaskList = targetListType === 'taskList';
|
|
25
|
+
var convertFromTaskListStructure = function convertFromTaskListStructure(node, targetListType, targetItemType) {
|
|
26
|
+
var schema = node.type.schema;
|
|
27
|
+
var targetListNodeType = schema.nodes[targetListType];
|
|
28
|
+
var transformedContent = [];
|
|
29
|
+
node.forEach(function (child) {
|
|
51
30
|
if ((0, _utils.isListType)(child, schema)) {
|
|
52
|
-
|
|
53
|
-
transformedContent.
|
|
31
|
+
// This is a nested list - it should become a child of the previous item
|
|
32
|
+
if (transformedContent.length > 0) {
|
|
33
|
+
var previousItem = transformedContent[transformedContent.length - 1];
|
|
34
|
+
// Convert the nested list and add it to the previous item's content
|
|
35
|
+
var transformedNestedList = _transformList(child, targetListType, targetItemType, unsupportedContent);
|
|
36
|
+
var newContent = previousItem.content.append(_model.Fragment.from([transformedNestedList]));
|
|
37
|
+
var updatedItem = previousItem.type.create(previousItem.attrs, newContent);
|
|
38
|
+
transformedContent[transformedContent.length - 1] = updatedItem;
|
|
39
|
+
}
|
|
40
|
+
// If there's no previous item, skip this nested list (orphaned)
|
|
41
|
+
} else {
|
|
42
|
+
var transformedItem = transformListItem(child, targetItemType, targetListType);
|
|
43
|
+
if (transformedItem) {
|
|
44
|
+
transformedContent.push(transformedItem);
|
|
45
|
+
}
|
|
54
46
|
}
|
|
55
47
|
});
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
* @param excludeNestedLists - When true, nested lists are excluded from the item's content
|
|
67
|
-
* (used when converting to taskList where nested lists become siblings)
|
|
68
|
-
*/
|
|
69
|
-
var transformListItem = function transformListItem(itemNode, targetItemType, targetListType) {
|
|
70
|
-
var excludeNestedLists = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
71
|
-
var schema = itemNode.type.schema;
|
|
72
|
-
var targetItemNodeType = schema.nodes[targetItemType];
|
|
73
|
-
var isTargetTaskItem = targetItemType === 'taskItem';
|
|
74
|
-
var isSourceTaskItem = itemNode.type.name === 'taskItem';
|
|
75
|
-
var paragraphType = schema.nodes.paragraph;
|
|
76
|
-
if (!targetItemNodeType) {
|
|
77
|
-
return null;
|
|
78
|
-
}
|
|
79
|
-
if (isTargetTaskItem) {
|
|
80
|
-
var inlineContent = [];
|
|
81
|
-
itemNode.content.forEach(function (child) {
|
|
82
|
-
if (child.type === paragraphType) {
|
|
83
|
-
child.content.forEach(function (inline) {
|
|
84
|
-
inlineContent.push(inline);
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
if (child.isText) {
|
|
88
|
-
inlineContent.push(child);
|
|
48
|
+
return targetListNodeType.create(node.attrs, transformedContent);
|
|
49
|
+
};
|
|
50
|
+
var convertToTaskListStructure = function convertToTaskListStructure(node, targetListType, targetItemType) {
|
|
51
|
+
var schema = node.type.schema;
|
|
52
|
+
var targetListNodeType = schema.nodes[targetListType];
|
|
53
|
+
var transformedContent = [];
|
|
54
|
+
node.forEach(function (itemNode) {
|
|
55
|
+
var transformedItem = transformListItem(itemNode, targetItemType, targetListType, true);
|
|
56
|
+
if (transformedItem) {
|
|
57
|
+
transformedContent.push(transformedItem);
|
|
89
58
|
}
|
|
90
|
-
|
|
91
|
-
|
|
59
|
+
itemNode.forEach(function (child) {
|
|
60
|
+
if ((0, _utils.isListType)(child, schema)) {
|
|
61
|
+
transformedContent.push(_transformList(child, targetListType, targetItemType, unsupportedContent));
|
|
62
|
+
}
|
|
63
|
+
});
|
|
92
64
|
});
|
|
93
|
-
return
|
|
94
|
-
}
|
|
95
|
-
|
|
65
|
+
return targetListNodeType.create(node.attrs, transformedContent);
|
|
66
|
+
};
|
|
67
|
+
var transformListItem = function transformListItem(itemNode, targetItemType, targetListType) {
|
|
68
|
+
var excludeNestedLists = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
69
|
+
var schema = itemNode.type.schema;
|
|
70
|
+
var targetItemNodeType = schema.nodes[targetItemType];
|
|
71
|
+
var isTargetTaskItem = targetItemType === 'taskItem';
|
|
72
|
+
var isSourceTaskItem = itemNode.type.name === 'taskItem';
|
|
73
|
+
var paragraphType = schema.nodes.paragraph;
|
|
74
|
+
if (isTargetTaskItem) {
|
|
75
|
+
var inlineContent = [];
|
|
76
|
+
itemNode.forEach(function (child) {
|
|
77
|
+
if (child.type === paragraphType) {
|
|
78
|
+
inlineContent.push.apply(inlineContent, (0, _toConsumableArray2.default)(child.children));
|
|
79
|
+
} else if (child.isText) {
|
|
80
|
+
inlineContent.push(child);
|
|
81
|
+
// Nested lists will be extracted and placed as siblings in the taskList
|
|
82
|
+
} else if (!(0, _utils.isListType)(child, schema)) {
|
|
83
|
+
unsupportedContent.push(child);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
return targetItemNodeType.create({}, inlineContent);
|
|
87
|
+
}
|
|
88
|
+
var transformedContent = [];
|
|
96
89
|
if (isSourceTaskItem) {
|
|
97
|
-
|
|
90
|
+
transformedContent.push(paragraphType.create(null, itemNode.content));
|
|
98
91
|
} else {
|
|
99
|
-
itemNode.
|
|
92
|
+
itemNode.forEach(function (child) {
|
|
100
93
|
if ((0, _utils.isListType)(child, schema)) {
|
|
101
94
|
if (excludeNestedLists) {
|
|
102
95
|
// Skip nested lists - they will be handled separately as siblings
|
|
103
96
|
return;
|
|
104
97
|
}
|
|
105
|
-
|
|
98
|
+
transformedContent.push(_transformList(child, targetListType, targetItemType, unsupportedContent));
|
|
106
99
|
} else {
|
|
107
|
-
|
|
100
|
+
transformedContent.push(child);
|
|
108
101
|
}
|
|
109
102
|
});
|
|
110
103
|
}
|
|
111
|
-
if (
|
|
112
|
-
|
|
104
|
+
if (transformedContent.length === 0) {
|
|
105
|
+
transformedContent.push(paragraphType.create());
|
|
113
106
|
}
|
|
114
|
-
return targetItemNodeType.create({},
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
var _transformList = function transformList(node, targetListType, targetItemType) {
|
|
128
|
-
var schema = node.type.schema;
|
|
129
|
-
var targetListNodeType = schema.nodes[targetListType];
|
|
130
|
-
var targetItemNodeType = schema.nodes[targetItemType];
|
|
131
|
-
var taskListType = schema.nodes.taskList;
|
|
132
|
-
if (!targetListNodeType || !targetItemNodeType) {
|
|
133
|
-
return node;
|
|
134
|
-
}
|
|
135
|
-
var isSourceTaskList = node.type === taskListType;
|
|
136
|
-
var isTargetTaskList = targetListType === 'taskList';
|
|
107
|
+
return targetItemNodeType.create({}, transformedContent);
|
|
108
|
+
};
|
|
109
|
+
var convertList = function convertList(node, schema, targetListType, targetItemType) {
|
|
110
|
+
var targetListNodeType = schema.nodes[targetListType];
|
|
111
|
+
var transformedContent = [];
|
|
112
|
+
node.forEach(function (childNode) {
|
|
113
|
+
var transformedItem = (0, _utils.isListType)(childNode, schema) ? _transformList(childNode, targetListType, targetItemType, unsupportedContent) : transformListItem(childNode, targetItemType, targetListType);
|
|
114
|
+
if (transformedItem) {
|
|
115
|
+
transformedContent.push(transformedItem);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
return targetListNodeType.create(node.attrs, transformedContent);
|
|
119
|
+
};
|
|
137
120
|
if (isSourceTaskList && !isTargetTaskList) {
|
|
138
121
|
return convertFromTaskListStructure(node, targetListType, targetItemType);
|
|
139
122
|
} else if (!isSourceTaskList && isTargetTaskList) {
|
|
140
123
|
return convertToTaskListStructure(node, targetListType, targetItemType);
|
|
141
|
-
} else {
|
|
142
|
-
var transformedItems = [];
|
|
143
|
-
node.content.forEach(function (childNode) {
|
|
144
|
-
var transformedItem = (0, _utils.isListType)(childNode, schema) ? _transformList(childNode, targetListType, targetItemType) : transformListItem(childNode, targetItemType, targetListType);
|
|
145
|
-
if (transformedItem) {
|
|
146
|
-
transformedItems.push(transformedItem);
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
return targetListNodeType.create(node.attrs, _model.Fragment.from(transformedItems));
|
|
150
124
|
}
|
|
125
|
+
return convertList(node, schema, targetListType, targetItemType);
|
|
151
126
|
};
|
|
152
127
|
|
|
153
128
|
/**
|
|
@@ -216,11 +191,13 @@ var _transformList = function transformList(node, targetListType, targetItemType
|
|
|
216
191
|
var listToListStep = exports.listToListStep = function listToListStep(nodes, context) {
|
|
217
192
|
var schema = context.schema,
|
|
218
193
|
targetNodeTypeName = context.targetNodeTypeName;
|
|
219
|
-
|
|
194
|
+
var unsupportedContent = [];
|
|
195
|
+
var transformedNodes = nodes.map(function (node) {
|
|
220
196
|
if ((0, _utils.isListType)(node, schema)) {
|
|
221
197
|
var targetItemType = targetNodeTypeName === 'taskList' ? 'taskItem' : 'listItem';
|
|
222
|
-
return _transformList(node, targetNodeTypeName, targetItemType);
|
|
198
|
+
return _transformList(node, targetNodeTypeName, targetItemType, unsupportedContent);
|
|
223
199
|
}
|
|
224
200
|
return node;
|
|
225
201
|
});
|
|
202
|
+
return [].concat((0, _toConsumableArray2.default)(transformedNodes), unsupportedContent);
|
|
226
203
|
};
|
|
@@ -48,17 +48,7 @@
|
|
|
48
48
|
export const createBlockMenuRegistry = () => {
|
|
49
49
|
const components = [];
|
|
50
50
|
const register = blockMenuComponents => {
|
|
51
|
-
|
|
52
|
-
// Find if a component with the same key already exists
|
|
53
|
-
const existingIndex = components.findIndex(comp => comp.key === newComponent.key);
|
|
54
|
-
if (existingIndex !== -1) {
|
|
55
|
-
// Replace the existing component
|
|
56
|
-
components[existingIndex] = newComponent;
|
|
57
|
-
} else {
|
|
58
|
-
// Add new component
|
|
59
|
-
components.push(newComponent);
|
|
60
|
-
}
|
|
61
|
-
});
|
|
51
|
+
components.push(...blockMenuComponents);
|
|
62
52
|
};
|
|
63
53
|
return {
|
|
64
54
|
register,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
2
1
|
import { isListType } from '../utils';
|
|
3
2
|
|
|
4
3
|
/**
|
|
@@ -29,7 +28,8 @@ export const listToDecisionListStep = (nodes, context) => {
|
|
|
29
28
|
schema
|
|
30
29
|
} = context;
|
|
31
30
|
const paragraphType = schema.nodes.paragraph;
|
|
32
|
-
|
|
31
|
+
const unsupportedContent = [];
|
|
32
|
+
const transformedNodes = nodes.map(node => {
|
|
33
33
|
if (!isListType(node, schema)) {
|
|
34
34
|
return node;
|
|
35
35
|
}
|
|
@@ -39,20 +39,18 @@ export const listToDecisionListStep = (nodes, context) => {
|
|
|
39
39
|
item.forEach(child => {
|
|
40
40
|
if (child.type === paragraphType) {
|
|
41
41
|
// paragraph may contain hard breaks etc.
|
|
42
|
-
child.
|
|
43
|
-
|
|
44
|
-
});
|
|
45
|
-
} else {
|
|
42
|
+
itemContent.push(...child.children);
|
|
43
|
+
} else if (child.isText) {
|
|
46
44
|
itemContent.push(child);
|
|
45
|
+
} else if (!isListType(child, schema)) {
|
|
46
|
+
unsupportedContent.push(child);
|
|
47
47
|
}
|
|
48
|
-
// TODO: EDITOR-3887 - Skip mediaSingle, codeBlock, and nested lists
|
|
49
48
|
});
|
|
50
|
-
const decisionItem = schema.nodes.decisionItem.create({},
|
|
51
|
-
|
|
52
|
-
decisionItems.push(decisionItem);
|
|
53
|
-
}
|
|
49
|
+
const decisionItem = schema.nodes.decisionItem.create({}, itemContent);
|
|
50
|
+
decisionItems.push(decisionItem);
|
|
54
51
|
});
|
|
55
|
-
const decisionList = schema.nodes.decisionList.create({},
|
|
52
|
+
const decisionList = schema.nodes.decisionList.create({}, decisionItems);
|
|
56
53
|
return decisionList || node;
|
|
57
54
|
});
|
|
55
|
+
return [...transformedNodes, ...unsupportedContent];
|
|
58
56
|
};
|
|
@@ -2,146 +2,119 @@ import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
|
2
2
|
import { isListType } from '../utils';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (isListType(child, schema)) {
|
|
13
|
-
// This is a nested list - it should become a child of the previous item
|
|
14
|
-
if (convertedItems.length > 0) {
|
|
15
|
-
const previousItem = convertedItems[convertedItems.length - 1];
|
|
16
|
-
// Convert the nested list and add it to the previous item's content
|
|
17
|
-
const convertedNestedList = transformList(child, targetListType, targetItemType);
|
|
18
|
-
const newContent = previousItem.content.append(Fragment.from([convertedNestedList]));
|
|
19
|
-
const updatedItem = previousItem.type.create(previousItem.attrs, newContent);
|
|
20
|
-
convertedItems[convertedItems.length - 1] = updatedItem;
|
|
21
|
-
}
|
|
22
|
-
// If there's no previous item, skip this nested list (orphaned)
|
|
23
|
-
} else {
|
|
24
|
-
const convertedItem = transformListItem(child, targetItemType, targetListType);
|
|
25
|
-
if (convertedItem) {
|
|
26
|
-
convertedItems.push(convertedItem);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
return targetListNodeType.create(node.attrs, Fragment.from(convertedItems));
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Converts FROM bulletList/orderedList structure TO taskList structure.
|
|
5
|
+
* Recursively converts nested lists to the target list type.
|
|
6
|
+
* This function handles the conversion of both the list container and its items,
|
|
7
|
+
* including any nested lists within those items.
|
|
8
|
+
*
|
|
9
|
+
* Important: taskList has a different nesting structure than bulletList/orderedList:
|
|
10
|
+
* - taskList: nested taskLists are SIBLINGS of taskItems in the parent taskList
|
|
11
|
+
* - bulletList/orderedList: nested lists are CHILDREN of listItems
|
|
35
12
|
*/
|
|
36
|
-
const
|
|
13
|
+
const transformList = (node, targetListType, targetItemType, unsupportedContent) => {
|
|
37
14
|
const schema = node.type.schema;
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
15
|
+
const taskListType = schema.nodes.taskList;
|
|
16
|
+
const isSourceTaskList = node.type === taskListType;
|
|
17
|
+
const isTargetTaskList = targetListType === 'taskList';
|
|
18
|
+
const convertFromTaskListStructure = (node, targetListType, targetItemType) => {
|
|
19
|
+
const schema = node.type.schema;
|
|
20
|
+
const targetListNodeType = schema.nodes[targetListType];
|
|
21
|
+
const transformedContent = [];
|
|
22
|
+
node.forEach(child => {
|
|
46
23
|
if (isListType(child, schema)) {
|
|
47
|
-
|
|
48
|
-
transformedContent.
|
|
24
|
+
// This is a nested list - it should become a child of the previous item
|
|
25
|
+
if (transformedContent.length > 0) {
|
|
26
|
+
const previousItem = transformedContent[transformedContent.length - 1];
|
|
27
|
+
// Convert the nested list and add it to the previous item's content
|
|
28
|
+
const transformedNestedList = transformList(child, targetListType, targetItemType, unsupportedContent);
|
|
29
|
+
const newContent = previousItem.content.append(Fragment.from([transformedNestedList]));
|
|
30
|
+
const updatedItem = previousItem.type.create(previousItem.attrs, newContent);
|
|
31
|
+
transformedContent[transformedContent.length - 1] = updatedItem;
|
|
32
|
+
}
|
|
33
|
+
// If there's no previous item, skip this nested list (orphaned)
|
|
34
|
+
} else {
|
|
35
|
+
const transformedItem = transformListItem(child, targetItemType, targetListType);
|
|
36
|
+
if (transformedItem) {
|
|
37
|
+
transformedContent.push(transformedItem);
|
|
38
|
+
}
|
|
49
39
|
}
|
|
50
40
|
});
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
* @param excludeNestedLists - When true, nested lists are excluded from the item's content
|
|
62
|
-
* (used when converting to taskList where nested lists become siblings)
|
|
63
|
-
*/
|
|
64
|
-
const transformListItem = (itemNode, targetItemType, targetListType, excludeNestedLists = false) => {
|
|
65
|
-
const schema = itemNode.type.schema;
|
|
66
|
-
const targetItemNodeType = schema.nodes[targetItemType];
|
|
67
|
-
const isTargetTaskItem = targetItemType === 'taskItem';
|
|
68
|
-
const isSourceTaskItem = itemNode.type.name === 'taskItem';
|
|
69
|
-
const paragraphType = schema.nodes.paragraph;
|
|
70
|
-
if (!targetItemNodeType) {
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
if (isTargetTaskItem) {
|
|
74
|
-
const inlineContent = [];
|
|
75
|
-
itemNode.content.forEach(child => {
|
|
76
|
-
if (child.type === paragraphType) {
|
|
77
|
-
child.content.forEach(inline => {
|
|
78
|
-
inlineContent.push(inline);
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
if (child.isText) {
|
|
82
|
-
inlineContent.push(child);
|
|
41
|
+
return targetListNodeType.create(node.attrs, transformedContent);
|
|
42
|
+
};
|
|
43
|
+
const convertToTaskListStructure = (node, targetListType, targetItemType) => {
|
|
44
|
+
const schema = node.type.schema;
|
|
45
|
+
const targetListNodeType = schema.nodes[targetListType];
|
|
46
|
+
const transformedContent = [];
|
|
47
|
+
node.forEach(itemNode => {
|
|
48
|
+
const transformedItem = transformListItem(itemNode, targetItemType, targetListType, true);
|
|
49
|
+
if (transformedItem) {
|
|
50
|
+
transformedContent.push(transformedItem);
|
|
83
51
|
}
|
|
84
|
-
|
|
85
|
-
|
|
52
|
+
itemNode.forEach(child => {
|
|
53
|
+
if (isListType(child, schema)) {
|
|
54
|
+
transformedContent.push(transformList(child, targetListType, targetItemType, unsupportedContent));
|
|
55
|
+
}
|
|
56
|
+
});
|
|
86
57
|
});
|
|
87
|
-
return
|
|
88
|
-
}
|
|
89
|
-
|
|
58
|
+
return targetListNodeType.create(node.attrs, transformedContent);
|
|
59
|
+
};
|
|
60
|
+
const transformListItem = (itemNode, targetItemType, targetListType, excludeNestedLists = false) => {
|
|
61
|
+
const schema = itemNode.type.schema;
|
|
62
|
+
const targetItemNodeType = schema.nodes[targetItemType];
|
|
63
|
+
const isTargetTaskItem = targetItemType === 'taskItem';
|
|
64
|
+
const isSourceTaskItem = itemNode.type.name === 'taskItem';
|
|
65
|
+
const paragraphType = schema.nodes.paragraph;
|
|
66
|
+
if (isTargetTaskItem) {
|
|
67
|
+
const inlineContent = [];
|
|
68
|
+
itemNode.forEach(child => {
|
|
69
|
+
if (child.type === paragraphType) {
|
|
70
|
+
inlineContent.push(...child.children);
|
|
71
|
+
} else if (child.isText) {
|
|
72
|
+
inlineContent.push(child);
|
|
73
|
+
// Nested lists will be extracted and placed as siblings in the taskList
|
|
74
|
+
} else if (!isListType(child, schema)) {
|
|
75
|
+
unsupportedContent.push(child);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
return targetItemNodeType.create({}, inlineContent);
|
|
79
|
+
}
|
|
80
|
+
const transformedContent = [];
|
|
90
81
|
if (isSourceTaskItem) {
|
|
91
|
-
|
|
82
|
+
transformedContent.push(paragraphType.create(null, itemNode.content));
|
|
92
83
|
} else {
|
|
93
|
-
itemNode.
|
|
84
|
+
itemNode.forEach(child => {
|
|
94
85
|
if (isListType(child, schema)) {
|
|
95
86
|
if (excludeNestedLists) {
|
|
96
87
|
// Skip nested lists - they will be handled separately as siblings
|
|
97
88
|
return;
|
|
98
89
|
}
|
|
99
|
-
|
|
90
|
+
transformedContent.push(transformList(child, targetListType, targetItemType, unsupportedContent));
|
|
100
91
|
} else {
|
|
101
|
-
|
|
92
|
+
transformedContent.push(child);
|
|
102
93
|
}
|
|
103
94
|
});
|
|
104
95
|
}
|
|
105
|
-
if (
|
|
106
|
-
|
|
96
|
+
if (transformedContent.length === 0) {
|
|
97
|
+
transformedContent.push(paragraphType.create());
|
|
107
98
|
}
|
|
108
|
-
return targetItemNodeType.create({},
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
const transformList = (node, targetListType, targetItemType) => {
|
|
122
|
-
const schema = node.type.schema;
|
|
123
|
-
const targetListNodeType = schema.nodes[targetListType];
|
|
124
|
-
const targetItemNodeType = schema.nodes[targetItemType];
|
|
125
|
-
const taskListType = schema.nodes.taskList;
|
|
126
|
-
if (!targetListNodeType || !targetItemNodeType) {
|
|
127
|
-
return node;
|
|
128
|
-
}
|
|
129
|
-
const isSourceTaskList = node.type === taskListType;
|
|
130
|
-
const isTargetTaskList = targetListType === 'taskList';
|
|
99
|
+
return targetItemNodeType.create({}, transformedContent);
|
|
100
|
+
};
|
|
101
|
+
const convertList = (node, schema, targetListType, targetItemType) => {
|
|
102
|
+
const targetListNodeType = schema.nodes[targetListType];
|
|
103
|
+
const transformedContent = [];
|
|
104
|
+
node.forEach(childNode => {
|
|
105
|
+
const transformedItem = isListType(childNode, schema) ? transformList(childNode, targetListType, targetItemType, unsupportedContent) : transformListItem(childNode, targetItemType, targetListType);
|
|
106
|
+
if (transformedItem) {
|
|
107
|
+
transformedContent.push(transformedItem);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
return targetListNodeType.create(node.attrs, transformedContent);
|
|
111
|
+
};
|
|
131
112
|
if (isSourceTaskList && !isTargetTaskList) {
|
|
132
113
|
return convertFromTaskListStructure(node, targetListType, targetItemType);
|
|
133
114
|
} else if (!isSourceTaskList && isTargetTaskList) {
|
|
134
115
|
return convertToTaskListStructure(node, targetListType, targetItemType);
|
|
135
|
-
} else {
|
|
136
|
-
const transformedItems = [];
|
|
137
|
-
node.content.forEach(childNode => {
|
|
138
|
-
const transformedItem = isListType(childNode, schema) ? transformList(childNode, targetListType, targetItemType) : transformListItem(childNode, targetItemType, targetListType);
|
|
139
|
-
if (transformedItem) {
|
|
140
|
-
transformedItems.push(transformedItem);
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
return targetListNodeType.create(node.attrs, Fragment.from(transformedItems));
|
|
144
116
|
}
|
|
117
|
+
return convertList(node, schema, targetListType, targetItemType);
|
|
145
118
|
};
|
|
146
119
|
|
|
147
120
|
/**
|
|
@@ -212,11 +185,13 @@ export const listToListStep = (nodes, context) => {
|
|
|
212
185
|
schema,
|
|
213
186
|
targetNodeTypeName
|
|
214
187
|
} = context;
|
|
215
|
-
|
|
188
|
+
const unsupportedContent = [];
|
|
189
|
+
const transformedNodes = nodes.map(node => {
|
|
216
190
|
if (isListType(node, schema)) {
|
|
217
191
|
const targetItemType = targetNodeTypeName === 'taskList' ? 'taskItem' : 'listItem';
|
|
218
|
-
return transformList(node, targetNodeTypeName, targetItemType);
|
|
192
|
+
return transformList(node, targetNodeTypeName, targetItemType, unsupportedContent);
|
|
219
193
|
}
|
|
220
194
|
return node;
|
|
221
195
|
});
|
|
196
|
+
return [...transformedNodes, ...unsupportedContent];
|
|
222
197
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
1
2
|
/**
|
|
2
3
|
* Create a simple registry for block menu components.
|
|
3
4
|
*
|
|
@@ -48,19 +49,7 @@
|
|
|
48
49
|
export var createBlockMenuRegistry = function createBlockMenuRegistry() {
|
|
49
50
|
var components = [];
|
|
50
51
|
var register = function register(blockMenuComponents) {
|
|
51
|
-
|
|
52
|
-
// Find if a component with the same key already exists
|
|
53
|
-
var existingIndex = components.findIndex(function (comp) {
|
|
54
|
-
return comp.key === newComponent.key;
|
|
55
|
-
});
|
|
56
|
-
if (existingIndex !== -1) {
|
|
57
|
-
// Replace the existing component
|
|
58
|
-
components[existingIndex] = newComponent;
|
|
59
|
-
} else {
|
|
60
|
-
// Add new component
|
|
61
|
-
components.push(newComponent);
|
|
62
|
-
}
|
|
63
|
-
});
|
|
52
|
+
components.push.apply(components, _toConsumableArray(blockMenuComponents));
|
|
64
53
|
};
|
|
65
54
|
return {
|
|
66
55
|
register: register,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
2
|
import { isListType } from '../utils';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -27,7 +27,8 @@ import { isListType } from '../utils';
|
|
|
27
27
|
export var listToDecisionListStep = function listToDecisionListStep(nodes, context) {
|
|
28
28
|
var schema = context.schema;
|
|
29
29
|
var paragraphType = schema.nodes.paragraph;
|
|
30
|
-
|
|
30
|
+
var unsupportedContent = [];
|
|
31
|
+
var transformedNodes = nodes.map(function (node) {
|
|
31
32
|
if (!isListType(node, schema)) {
|
|
32
33
|
return node;
|
|
33
34
|
}
|
|
@@ -37,20 +38,18 @@ export var listToDecisionListStep = function listToDecisionListStep(nodes, conte
|
|
|
37
38
|
item.forEach(function (child) {
|
|
38
39
|
if (child.type === paragraphType) {
|
|
39
40
|
// paragraph may contain hard breaks etc.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
});
|
|
43
|
-
} else {
|
|
41
|
+
itemContent.push.apply(itemContent, _toConsumableArray(child.children));
|
|
42
|
+
} else if (child.isText) {
|
|
44
43
|
itemContent.push(child);
|
|
44
|
+
} else if (!isListType(child, schema)) {
|
|
45
|
+
unsupportedContent.push(child);
|
|
45
46
|
}
|
|
46
|
-
// TODO: EDITOR-3887 - Skip mediaSingle, codeBlock, and nested lists
|
|
47
47
|
});
|
|
48
|
-
var decisionItem = schema.nodes.decisionItem.create({},
|
|
49
|
-
|
|
50
|
-
decisionItems.push(decisionItem);
|
|
51
|
-
}
|
|
48
|
+
var decisionItem = schema.nodes.decisionItem.create({}, itemContent);
|
|
49
|
+
decisionItems.push(decisionItem);
|
|
52
50
|
});
|
|
53
|
-
var decisionList = schema.nodes.decisionList.create({},
|
|
51
|
+
var decisionList = schema.nodes.decisionList.create({}, decisionItems);
|
|
54
52
|
return decisionList || node;
|
|
55
53
|
});
|
|
54
|
+
return [].concat(_toConsumableArray(transformedNodes), unsupportedContent);
|
|
56
55
|
};
|
|
@@ -1,148 +1,122 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
1
2
|
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
2
3
|
import { isListType } from '../utils';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
|
-
*
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (isListType(child, schema)) {
|
|
13
|
-
// This is a nested list - it should become a child of the previous item
|
|
14
|
-
if (convertedItems.length > 0) {
|
|
15
|
-
var previousItem = convertedItems[convertedItems.length - 1];
|
|
16
|
-
// Convert the nested list and add it to the previous item's content
|
|
17
|
-
var convertedNestedList = _transformList(child, targetListType, targetItemType);
|
|
18
|
-
var newContent = previousItem.content.append(Fragment.from([convertedNestedList]));
|
|
19
|
-
var updatedItem = previousItem.type.create(previousItem.attrs, newContent);
|
|
20
|
-
convertedItems[convertedItems.length - 1] = updatedItem;
|
|
21
|
-
}
|
|
22
|
-
// If there's no previous item, skip this nested list (orphaned)
|
|
23
|
-
} else {
|
|
24
|
-
var convertedItem = transformListItem(child, targetItemType, targetListType);
|
|
25
|
-
if (convertedItem) {
|
|
26
|
-
convertedItems.push(convertedItem);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
return targetListNodeType.create(node.attrs, Fragment.from(convertedItems));
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Converts FROM bulletList/orderedList structure TO taskList structure.
|
|
6
|
+
* Recursively converts nested lists to the target list type.
|
|
7
|
+
* This function handles the conversion of both the list container and its items,
|
|
8
|
+
* including any nested lists within those items.
|
|
9
|
+
*
|
|
10
|
+
* Important: taskList has a different nesting structure than bulletList/orderedList:
|
|
11
|
+
* - taskList: nested taskLists are SIBLINGS of taskItems in the parent taskList
|
|
12
|
+
* - bulletList/orderedList: nested lists are CHILDREN of listItems
|
|
35
13
|
*/
|
|
36
|
-
var
|
|
14
|
+
var _transformList = function transformList(node, targetListType, targetItemType, unsupportedContent) {
|
|
37
15
|
var schema = node.type.schema;
|
|
38
|
-
var
|
|
39
|
-
var
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
16
|
+
var taskListType = schema.nodes.taskList;
|
|
17
|
+
var isSourceTaskList = node.type === taskListType;
|
|
18
|
+
var isTargetTaskList = targetListType === 'taskList';
|
|
19
|
+
var convertFromTaskListStructure = function convertFromTaskListStructure(node, targetListType, targetItemType) {
|
|
20
|
+
var schema = node.type.schema;
|
|
21
|
+
var targetListNodeType = schema.nodes[targetListType];
|
|
22
|
+
var transformedContent = [];
|
|
23
|
+
node.forEach(function (child) {
|
|
46
24
|
if (isListType(child, schema)) {
|
|
47
|
-
|
|
48
|
-
transformedContent.
|
|
25
|
+
// This is a nested list - it should become a child of the previous item
|
|
26
|
+
if (transformedContent.length > 0) {
|
|
27
|
+
var previousItem = transformedContent[transformedContent.length - 1];
|
|
28
|
+
// Convert the nested list and add it to the previous item's content
|
|
29
|
+
var transformedNestedList = _transformList(child, targetListType, targetItemType, unsupportedContent);
|
|
30
|
+
var newContent = previousItem.content.append(Fragment.from([transformedNestedList]));
|
|
31
|
+
var updatedItem = previousItem.type.create(previousItem.attrs, newContent);
|
|
32
|
+
transformedContent[transformedContent.length - 1] = updatedItem;
|
|
33
|
+
}
|
|
34
|
+
// If there's no previous item, skip this nested list (orphaned)
|
|
35
|
+
} else {
|
|
36
|
+
var transformedItem = transformListItem(child, targetItemType, targetListType);
|
|
37
|
+
if (transformedItem) {
|
|
38
|
+
transformedContent.push(transformedItem);
|
|
39
|
+
}
|
|
49
40
|
}
|
|
50
41
|
});
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
* @param excludeNestedLists - When true, nested lists are excluded from the item's content
|
|
62
|
-
* (used when converting to taskList where nested lists become siblings)
|
|
63
|
-
*/
|
|
64
|
-
var transformListItem = function transformListItem(itemNode, targetItemType, targetListType) {
|
|
65
|
-
var excludeNestedLists = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
66
|
-
var schema = itemNode.type.schema;
|
|
67
|
-
var targetItemNodeType = schema.nodes[targetItemType];
|
|
68
|
-
var isTargetTaskItem = targetItemType === 'taskItem';
|
|
69
|
-
var isSourceTaskItem = itemNode.type.name === 'taskItem';
|
|
70
|
-
var paragraphType = schema.nodes.paragraph;
|
|
71
|
-
if (!targetItemNodeType) {
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
if (isTargetTaskItem) {
|
|
75
|
-
var inlineContent = [];
|
|
76
|
-
itemNode.content.forEach(function (child) {
|
|
77
|
-
if (child.type === paragraphType) {
|
|
78
|
-
child.content.forEach(function (inline) {
|
|
79
|
-
inlineContent.push(inline);
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
if (child.isText) {
|
|
83
|
-
inlineContent.push(child);
|
|
42
|
+
return targetListNodeType.create(node.attrs, transformedContent);
|
|
43
|
+
};
|
|
44
|
+
var convertToTaskListStructure = function convertToTaskListStructure(node, targetListType, targetItemType) {
|
|
45
|
+
var schema = node.type.schema;
|
|
46
|
+
var targetListNodeType = schema.nodes[targetListType];
|
|
47
|
+
var transformedContent = [];
|
|
48
|
+
node.forEach(function (itemNode) {
|
|
49
|
+
var transformedItem = transformListItem(itemNode, targetItemType, targetListType, true);
|
|
50
|
+
if (transformedItem) {
|
|
51
|
+
transformedContent.push(transformedItem);
|
|
84
52
|
}
|
|
85
|
-
|
|
86
|
-
|
|
53
|
+
itemNode.forEach(function (child) {
|
|
54
|
+
if (isListType(child, schema)) {
|
|
55
|
+
transformedContent.push(_transformList(child, targetListType, targetItemType, unsupportedContent));
|
|
56
|
+
}
|
|
57
|
+
});
|
|
87
58
|
});
|
|
88
|
-
return
|
|
89
|
-
}
|
|
90
|
-
|
|
59
|
+
return targetListNodeType.create(node.attrs, transformedContent);
|
|
60
|
+
};
|
|
61
|
+
var transformListItem = function transformListItem(itemNode, targetItemType, targetListType) {
|
|
62
|
+
var excludeNestedLists = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
63
|
+
var schema = itemNode.type.schema;
|
|
64
|
+
var targetItemNodeType = schema.nodes[targetItemType];
|
|
65
|
+
var isTargetTaskItem = targetItemType === 'taskItem';
|
|
66
|
+
var isSourceTaskItem = itemNode.type.name === 'taskItem';
|
|
67
|
+
var paragraphType = schema.nodes.paragraph;
|
|
68
|
+
if (isTargetTaskItem) {
|
|
69
|
+
var inlineContent = [];
|
|
70
|
+
itemNode.forEach(function (child) {
|
|
71
|
+
if (child.type === paragraphType) {
|
|
72
|
+
inlineContent.push.apply(inlineContent, _toConsumableArray(child.children));
|
|
73
|
+
} else if (child.isText) {
|
|
74
|
+
inlineContent.push(child);
|
|
75
|
+
// Nested lists will be extracted and placed as siblings in the taskList
|
|
76
|
+
} else if (!isListType(child, schema)) {
|
|
77
|
+
unsupportedContent.push(child);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
return targetItemNodeType.create({}, inlineContent);
|
|
81
|
+
}
|
|
82
|
+
var transformedContent = [];
|
|
91
83
|
if (isSourceTaskItem) {
|
|
92
|
-
|
|
84
|
+
transformedContent.push(paragraphType.create(null, itemNode.content));
|
|
93
85
|
} else {
|
|
94
|
-
itemNode.
|
|
86
|
+
itemNode.forEach(function (child) {
|
|
95
87
|
if (isListType(child, schema)) {
|
|
96
88
|
if (excludeNestedLists) {
|
|
97
89
|
// Skip nested lists - they will be handled separately as siblings
|
|
98
90
|
return;
|
|
99
91
|
}
|
|
100
|
-
|
|
92
|
+
transformedContent.push(_transformList(child, targetListType, targetItemType, unsupportedContent));
|
|
101
93
|
} else {
|
|
102
|
-
|
|
94
|
+
transformedContent.push(child);
|
|
103
95
|
}
|
|
104
96
|
});
|
|
105
97
|
}
|
|
106
|
-
if (
|
|
107
|
-
|
|
98
|
+
if (transformedContent.length === 0) {
|
|
99
|
+
transformedContent.push(paragraphType.create());
|
|
108
100
|
}
|
|
109
|
-
return targetItemNodeType.create({},
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
var _transformList = function transformList(node, targetListType, targetItemType) {
|
|
123
|
-
var schema = node.type.schema;
|
|
124
|
-
var targetListNodeType = schema.nodes[targetListType];
|
|
125
|
-
var targetItemNodeType = schema.nodes[targetItemType];
|
|
126
|
-
var taskListType = schema.nodes.taskList;
|
|
127
|
-
if (!targetListNodeType || !targetItemNodeType) {
|
|
128
|
-
return node;
|
|
129
|
-
}
|
|
130
|
-
var isSourceTaskList = node.type === taskListType;
|
|
131
|
-
var isTargetTaskList = targetListType === 'taskList';
|
|
101
|
+
return targetItemNodeType.create({}, transformedContent);
|
|
102
|
+
};
|
|
103
|
+
var convertList = function convertList(node, schema, targetListType, targetItemType) {
|
|
104
|
+
var targetListNodeType = schema.nodes[targetListType];
|
|
105
|
+
var transformedContent = [];
|
|
106
|
+
node.forEach(function (childNode) {
|
|
107
|
+
var transformedItem = isListType(childNode, schema) ? _transformList(childNode, targetListType, targetItemType, unsupportedContent) : transformListItem(childNode, targetItemType, targetListType);
|
|
108
|
+
if (transformedItem) {
|
|
109
|
+
transformedContent.push(transformedItem);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
return targetListNodeType.create(node.attrs, transformedContent);
|
|
113
|
+
};
|
|
132
114
|
if (isSourceTaskList && !isTargetTaskList) {
|
|
133
115
|
return convertFromTaskListStructure(node, targetListType, targetItemType);
|
|
134
116
|
} else if (!isSourceTaskList && isTargetTaskList) {
|
|
135
117
|
return convertToTaskListStructure(node, targetListType, targetItemType);
|
|
136
|
-
} else {
|
|
137
|
-
var transformedItems = [];
|
|
138
|
-
node.content.forEach(function (childNode) {
|
|
139
|
-
var transformedItem = isListType(childNode, schema) ? _transformList(childNode, targetListType, targetItemType) : transformListItem(childNode, targetItemType, targetListType);
|
|
140
|
-
if (transformedItem) {
|
|
141
|
-
transformedItems.push(transformedItem);
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
return targetListNodeType.create(node.attrs, Fragment.from(transformedItems));
|
|
145
118
|
}
|
|
119
|
+
return convertList(node, schema, targetListType, targetItemType);
|
|
146
120
|
};
|
|
147
121
|
|
|
148
122
|
/**
|
|
@@ -211,11 +185,13 @@ var _transformList = function transformList(node, targetListType, targetItemType
|
|
|
211
185
|
export var listToListStep = function listToListStep(nodes, context) {
|
|
212
186
|
var schema = context.schema,
|
|
213
187
|
targetNodeTypeName = context.targetNodeTypeName;
|
|
214
|
-
|
|
188
|
+
var unsupportedContent = [];
|
|
189
|
+
var transformedNodes = nodes.map(function (node) {
|
|
215
190
|
if (isListType(node, schema)) {
|
|
216
191
|
var targetItemType = targetNodeTypeName === 'taskList' ? 'taskItem' : 'listItem';
|
|
217
|
-
return _transformList(node, targetNodeTypeName, targetItemType);
|
|
192
|
+
return _transformList(node, targetNodeTypeName, targetItemType, unsupportedContent);
|
|
218
193
|
}
|
|
219
194
|
return node;
|
|
220
195
|
});
|
|
196
|
+
return [].concat(_toConsumableArray(transformedNodes), unsupportedContent);
|
|
221
197
|
};
|