@atlaskit/editor-plugin-block-menu 5.2.2 → 5.2.3

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.
Files changed (20) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/cjs/editor-commands/transform-node-utils/{flattenListStep.js → steps/flattenListStep.js} +3 -5
  3. package/dist/cjs/editor-commands/transform-node-utils/steps/listToListStep.js +232 -0
  4. package/dist/cjs/editor-commands/transform-node-utils/transform.js +4 -3
  5. package/dist/es2019/editor-commands/transform-node-utils/{flattenListStep.js → steps/flattenListStep.js} +3 -5
  6. package/dist/es2019/editor-commands/transform-node-utils/steps/listToListStep.js +225 -0
  7. package/dist/es2019/editor-commands/transform-node-utils/transform.js +4 -3
  8. package/dist/esm/editor-commands/transform-node-utils/{flattenListStep.js → steps/flattenListStep.js} +3 -5
  9. package/dist/esm/editor-commands/transform-node-utils/steps/listToListStep.js +226 -0
  10. package/dist/esm/editor-commands/transform-node-utils/transform.js +4 -3
  11. package/dist/{types-ts4.5/editor-commands/transform-node-utils → types/editor-commands/transform-node-utils/steps}/flattenListStep.d.ts +1 -1
  12. package/dist/types/editor-commands/transform-node-utils/steps/listToListStep.d.ts +65 -0
  13. package/dist/{types-ts4.5/editor-commands/transform-node-utils → types/editor-commands/transform-node-utils/steps}/unwrapListStep.d.ts +1 -1
  14. package/dist/{types/editor-commands/transform-node-utils → types-ts4.5/editor-commands/transform-node-utils/steps}/flattenListStep.d.ts +1 -1
  15. package/dist/types-ts4.5/editor-commands/transform-node-utils/steps/listToListStep.d.ts +65 -0
  16. package/dist/{types/editor-commands/transform-node-utils → types-ts4.5/editor-commands/transform-node-utils/steps}/unwrapListStep.d.ts +1 -1
  17. package/package.json +1 -1
  18. /package/dist/cjs/editor-commands/transform-node-utils/{unwrapListStep.js → steps/unwrapListStep.js} +0 -0
  19. /package/dist/es2019/editor-commands/transform-node-utils/{unwrapListStep.js → steps/unwrapListStep.js} +0 -0
  20. /package/dist/esm/editor-commands/transform-node-utils/{unwrapListStep.js → steps/unwrapListStep.js} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @atlaskit/editor-plugin-block-menu
2
2
 
3
+ ## 5.2.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [`d0857f52fd866`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/d0857f52fd866) -
8
+ Add list-to-list transformation support in block menu
9
+
3
10
  ## 5.2.2
4
11
 
5
12
  ### Patch Changes
@@ -20,12 +20,10 @@ var extractNestedLists = function extractNestedLists(node, listTypes, itemTypes,
20
20
  return grandChild.type === type;
21
21
  })) {
22
22
  nestedLists.push(grandChild);
23
+ } else if (grandChild.isText) {
24
+ contentWithoutNestedLists.push(paragraph.createAndFill({}, grandChild));
23
25
  } else {
24
- if (grandChild.isText) {
25
- contentWithoutNestedLists.push(paragraph.createAndFill({}, grandChild));
26
- } else {
27
- contentWithoutNestedLists.push(grandChild);
28
- }
26
+ contentWithoutNestedLists.push(grandChild);
29
27
  }
30
28
  });
31
29
  items.push(child.copy(_model.Fragment.from(contentWithoutNestedLists)));
@@ -0,0 +1,232 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.listToListStep = void 0;
7
+ var _model = require("@atlaskit/editor-prosemirror/model");
8
+ var isListType = function isListType(node, schema) {
9
+ var lists = [schema.nodes.taskList, schema.nodes.bulletList, schema.nodes.orderedList];
10
+ return lists.some(function (list) {
11
+ return list === node.type;
12
+ });
13
+ };
14
+
15
+ /**
16
+ * Converts FROM taskList structure TO bulletList/orderedList structure.
17
+ */
18
+ var convertFromTaskListStructure = function convertFromTaskListStructure(node, targetListType, targetItemType) {
19
+ var schema = node.type.schema;
20
+ var targetListNodeType = schema.nodes[targetListType];
21
+ var convertedItems = [];
22
+ node.content.forEach(function (child) {
23
+ if (isListType(child, schema)) {
24
+ // This is a nested list - it should become a child of the previous item
25
+ if (convertedItems.length > 0) {
26
+ var previousItem = convertedItems[convertedItems.length - 1];
27
+ // Convert the nested list and add it to the previous item's content
28
+ var convertedNestedList = _transformList(child, targetListType, targetItemType);
29
+ var newContent = previousItem.content.append(_model.Fragment.from([convertedNestedList]));
30
+ var updatedItem = previousItem.type.create(previousItem.attrs, newContent);
31
+ convertedItems[convertedItems.length - 1] = updatedItem;
32
+ }
33
+ // If there's no previous item, skip this nested list (orphaned)
34
+ } else {
35
+ var convertedItem = transformListItem(child, targetItemType, targetListType);
36
+ if (convertedItem) {
37
+ convertedItems.push(convertedItem);
38
+ }
39
+ }
40
+ });
41
+ return targetListNodeType.create(node.attrs, _model.Fragment.from(convertedItems));
42
+ };
43
+
44
+ /**
45
+ * Converts FROM bulletList/orderedList structure TO taskList structure.
46
+ */
47
+ var convertToTaskListStructure = function convertToTaskListStructure(node, targetListType, targetItemType) {
48
+ var schema = node.type.schema;
49
+ var targetListNodeType = schema.nodes[targetListType];
50
+ var transformedContent = [];
51
+ node.content.forEach(function (itemNode) {
52
+ var transformedItem = transformListItem(itemNode, targetItemType, targetListType, true);
53
+ if (transformedItem) {
54
+ transformedContent.push(transformedItem);
55
+ }
56
+ itemNode.content.forEach(function (child) {
57
+ if (isListType(child, schema)) {
58
+ var transformedNestedList = _transformList(child, targetListType, targetItemType);
59
+ transformedContent.push(transformedNestedList);
60
+ }
61
+ });
62
+ });
63
+ return targetListNodeType.create(node.attrs, _model.Fragment.from(transformedContent));
64
+ };
65
+
66
+ /**
67
+ * Converts a single list item (listItem or taskItem) to the target item type.
68
+ * Handles content transformation based on the target type's requirements.
69
+ * @param itemNode - The list item node to convert
70
+ * @param targetItemType - The target item type (listItem or taskItem)
71
+ * @param targetListType - The target list type (bulletList, orderedList, or taskList)
72
+ * @param excludeNestedLists - When true, nested lists are excluded from the item's content
73
+ * (used when converting to taskList where nested lists become siblings)
74
+ */
75
+ var transformListItem = function transformListItem(itemNode, targetItemType, targetListType) {
76
+ var excludeNestedLists = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
77
+ var schema = itemNode.type.schema;
78
+ var targetItemNodeType = schema.nodes[targetItemType];
79
+ var isTargetTaskItem = targetItemType === 'taskItem';
80
+ var isSourceTaskItem = itemNode.type.name === 'taskItem';
81
+ var paragraphType = schema.nodes.paragraph;
82
+ if (!targetItemNodeType) {
83
+ return null;
84
+ }
85
+ if (isTargetTaskItem) {
86
+ var inlineContent = [];
87
+ itemNode.content.forEach(function (child) {
88
+ if (child.type === paragraphType) {
89
+ child.content.forEach(function (inline) {
90
+ inlineContent.push(inline);
91
+ });
92
+ }
93
+ if (child.isText) {
94
+ inlineContent.push(child);
95
+ }
96
+ // TODO: EDITOR-3887 - Skip mediaSingle, codeBlock, and nested lists
97
+ // Nested lists will be extracted and placed as siblings in the taskList
98
+ });
99
+ return targetItemNodeType.create({}, _model.Fragment.from(inlineContent));
100
+ } else {
101
+ var newContent = [];
102
+ if (isSourceTaskItem) {
103
+ newContent.push(paragraphType.create(null, itemNode.content));
104
+ } else {
105
+ itemNode.content.forEach(function (child) {
106
+ if (isListType(child, schema)) {
107
+ if (excludeNestedLists) {
108
+ // Skip nested lists - they will be handled separately as siblings
109
+ return;
110
+ }
111
+ newContent.push(_transformList(child, targetListType, targetItemType));
112
+ } else {
113
+ newContent.push(child);
114
+ }
115
+ });
116
+ }
117
+ if (newContent.length === 0) {
118
+ newContent.push(paragraphType.create());
119
+ }
120
+ return targetItemNodeType.create({}, _model.Fragment.from(newContent));
121
+ }
122
+ };
123
+
124
+ /**
125
+ * Recursively converts nested lists to the target list type.
126
+ * This function handles the conversion of both the list container and its items,
127
+ * including any nested lists within those items.
128
+ *
129
+ * Important: taskList has a different nesting structure than bulletList/orderedList:
130
+ * - taskList: nested taskLists are SIBLINGS of taskItems in the parent taskList
131
+ * - bulletList/orderedList: nested lists are CHILDREN of listItems
132
+ */
133
+ var _transformList = function transformList(node, targetListType, targetItemType) {
134
+ var schema = node.type.schema;
135
+ var targetListNodeType = schema.nodes[targetListType];
136
+ var targetItemNodeType = schema.nodes[targetItemType];
137
+ var taskListType = schema.nodes.taskList;
138
+ if (!targetListNodeType || !targetItemNodeType) {
139
+ return node;
140
+ }
141
+ var isSourceTaskList = node.type === taskListType;
142
+ var isTargetTaskList = targetListType === 'taskList';
143
+ if (isSourceTaskList && !isTargetTaskList) {
144
+ return convertFromTaskListStructure(node, targetListType, targetItemType);
145
+ } else if (!isSourceTaskList && isTargetTaskList) {
146
+ return convertToTaskListStructure(node, targetListType, targetItemType);
147
+ } else {
148
+ var transformedItems = [];
149
+ node.content.forEach(function (childNode) {
150
+ var transformedItem = isListType(childNode, schema) ? _transformList(childNode, targetListType, targetItemType) : transformListItem(childNode, targetItemType, targetListType);
151
+ if (transformedItem) {
152
+ transformedItems.push(transformedItem);
153
+ }
154
+ });
155
+ return targetListNodeType.create(node.attrs, _model.Fragment.from(transformedItems));
156
+ }
157
+ };
158
+
159
+ /**
160
+ * Transform step that converts between bulletList, orderedList, and taskList types.
161
+ * This step maintains the order and indentation of the list by recursively
162
+ * converting all nested lists while preserving the structure. It also handles
163
+ * conversion between listItem and taskItem types.
164
+ *
165
+ * When converting to taskList/taskItem, unsupported content (images, codeBlocks) is filtered out.
166
+ *
167
+ * @example
168
+ * Input (bulletList with nested bulletList):
169
+ * - bulletList
170
+ * - listItem "1"
171
+ * - bulletList
172
+ * - listItem "1.1"
173
+ * - bulletList
174
+ * - listItem "1.1.1"
175
+ * - listItem "1.2"
176
+ * - listItem "2"
177
+ *
178
+ * Output (orderedList with nested orderedList):
179
+ * 1. orderedList
180
+ * 1. listItem "1"
181
+ * 1. orderedList
182
+ * 1. listItem "1.1"
183
+ * 1. orderedList
184
+ * 1. listItem "1.1.1"
185
+ * 2. listItem "1.2"
186
+ * 2. listItem "2"
187
+ *
188
+ * @example
189
+ * Input (bulletList with nested taskList):
190
+ * - bulletList
191
+ * - listItem "Regular item"
192
+ * - taskList
193
+ * - taskItem "Task 1" (checked)
194
+ * - taskItem "Task 2" (unchecked)
195
+ *
196
+ * Output (orderedList with nested orderedList, taskItems converted to listItems):
197
+ * 1. orderedList
198
+ * 1. listItem "Regular item"
199
+ * 1. orderedList
200
+ * 1. listItem "Task 1"
201
+ * 2. listItem "Task 2"
202
+ *
203
+ * @example
204
+ * Input (bulletList to taskList, with paragraph extraction):
205
+ * - bulletList
206
+ * - listItem
207
+ * - paragraph "Text content"
208
+ * - listItem
209
+ * - paragraph "Text"
210
+ * - codeBlock "code"
211
+ * - mediaSingle (image)
212
+ *
213
+ * Output (taskList with text extracted from paragraphs, unsupported content filtered):
214
+ * - taskList
215
+ * - taskItem "Text content" (text extracted from paragraph)
216
+ * - taskItem "Text" (text extracted, codeBlock and image filtered out)
217
+ *
218
+ * @param nodes - The nodes to transform
219
+ * @param context - The transformation context containing schema and target node type
220
+ * @returns The transformed nodes
221
+ */
222
+ var listToListStep = exports.listToListStep = function listToListStep(nodes, context) {
223
+ var schema = context.schema,
224
+ targetNodeTypeName = context.targetNodeTypeName;
225
+ return nodes.map(function (node) {
226
+ if (isListType(node, schema)) {
227
+ var targetItemType = targetNodeTypeName === 'taskList' ? 'taskItem' : 'listItem';
228
+ return _transformList(node, targetNodeTypeName, targetItemType);
229
+ }
230
+ return node;
231
+ });
232
+ };
@@ -5,16 +5,17 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.getOutputNodes = void 0;
7
7
  var _utils = require("../transform-node-utils/utils");
8
- var _flattenListStep = require("./flattenListStep");
9
8
  var _flattenStep = require("./flattenStep");
10
9
  var _convertBulletListToTextStep = require("./steps/convertBulletListToTextStep");
11
10
  var _convertOrderedListToTextStep = require("./steps/convertOrderedListToTextStep");
12
11
  var _convertTaskListToTextStep = require("./steps/convertTaskListToTextStep");
12
+ var _flattenListStep = require("./steps/flattenListStep");
13
+ var _listToListStep = require("./steps/listToListStep");
13
14
  var _unwrapLayoutStep = require("./steps/unwrapLayoutStep");
15
+ var _unwrapListStep = require("./steps/unwrapListStep");
14
16
  var _stubStep = require("./stubStep");
15
17
  var _types = require("./types");
16
18
  var _unwrapExpandStep = require("./unwrapExpandStep");
17
- var _unwrapListStep = require("./unwrapListStep");
18
19
  var _unwrapStep = require("./unwrapStep");
19
20
  var _wrapIntoLayoutStep = require("./wrapIntoLayoutStep");
20
21
  var _wrapMixedContentStep = require("./wrapMixedContentStep");
@@ -44,7 +45,7 @@ var TRANSFORM_STEPS = {
44
45
  list: {
45
46
  atomic: undefined,
46
47
  container: [_wrapStep.wrapStep],
47
- list: [_stubStep.stubStep],
48
+ list: [_listToListStep.listToListStep],
48
49
  text: [_flattenListStep.flattenListStep, _unwrapListStep.unwrapListStep]
49
50
  },
50
51
  text: {
@@ -10,12 +10,10 @@ const extractNestedLists = (node, listTypes, itemTypes, schema) => {
10
10
  child.forEach(grandChild => {
11
11
  if (listTypes.some(type => grandChild.type === type)) {
12
12
  nestedLists.push(grandChild);
13
+ } else if (grandChild.isText) {
14
+ contentWithoutNestedLists.push(paragraph.createAndFill({}, grandChild));
13
15
  } else {
14
- if (grandChild.isText) {
15
- contentWithoutNestedLists.push(paragraph.createAndFill({}, grandChild));
16
- } else {
17
- contentWithoutNestedLists.push(grandChild);
18
- }
16
+ contentWithoutNestedLists.push(grandChild);
19
17
  }
20
18
  });
21
19
  items.push(child.copy(Fragment.from(contentWithoutNestedLists)));
@@ -0,0 +1,225 @@
1
+ import { Fragment } from '@atlaskit/editor-prosemirror/model';
2
+ const isListType = (node, schema) => {
3
+ const lists = [schema.nodes.taskList, schema.nodes.bulletList, schema.nodes.orderedList];
4
+ return lists.some(list => list === node.type);
5
+ };
6
+
7
+ /**
8
+ * Converts FROM taskList structure TO bulletList/orderedList structure.
9
+ */
10
+ const convertFromTaskListStructure = (node, targetListType, targetItemType) => {
11
+ const schema = node.type.schema;
12
+ const targetListNodeType = schema.nodes[targetListType];
13
+ const convertedItems = [];
14
+ node.content.forEach(child => {
15
+ if (isListType(child, schema)) {
16
+ // This is a nested list - it should become a child of the previous item
17
+ if (convertedItems.length > 0) {
18
+ const previousItem = convertedItems[convertedItems.length - 1];
19
+ // Convert the nested list and add it to the previous item's content
20
+ const convertedNestedList = transformList(child, targetListType, targetItemType);
21
+ const newContent = previousItem.content.append(Fragment.from([convertedNestedList]));
22
+ const updatedItem = previousItem.type.create(previousItem.attrs, newContent);
23
+ convertedItems[convertedItems.length - 1] = updatedItem;
24
+ }
25
+ // If there's no previous item, skip this nested list (orphaned)
26
+ } else {
27
+ const convertedItem = transformListItem(child, targetItemType, targetListType);
28
+ if (convertedItem) {
29
+ convertedItems.push(convertedItem);
30
+ }
31
+ }
32
+ });
33
+ return targetListNodeType.create(node.attrs, Fragment.from(convertedItems));
34
+ };
35
+
36
+ /**
37
+ * Converts FROM bulletList/orderedList structure TO taskList structure.
38
+ */
39
+ const convertToTaskListStructure = (node, targetListType, targetItemType) => {
40
+ const schema = node.type.schema;
41
+ const targetListNodeType = schema.nodes[targetListType];
42
+ const transformedContent = [];
43
+ node.content.forEach(itemNode => {
44
+ const transformedItem = transformListItem(itemNode, targetItemType, targetListType, true);
45
+ if (transformedItem) {
46
+ transformedContent.push(transformedItem);
47
+ }
48
+ itemNode.content.forEach(child => {
49
+ if (isListType(child, schema)) {
50
+ const transformedNestedList = transformList(child, targetListType, targetItemType);
51
+ transformedContent.push(transformedNestedList);
52
+ }
53
+ });
54
+ });
55
+ return targetListNodeType.create(node.attrs, Fragment.from(transformedContent));
56
+ };
57
+
58
+ /**
59
+ * Converts a single list item (listItem or taskItem) to the target item type.
60
+ * Handles content transformation based on the target type's requirements.
61
+ * @param itemNode - The list item node to convert
62
+ * @param targetItemType - The target item type (listItem or taskItem)
63
+ * @param targetListType - The target list type (bulletList, orderedList, or taskList)
64
+ * @param excludeNestedLists - When true, nested lists are excluded from the item's content
65
+ * (used when converting to taskList where nested lists become siblings)
66
+ */
67
+ const transformListItem = (itemNode, targetItemType, targetListType, excludeNestedLists = false) => {
68
+ const schema = itemNode.type.schema;
69
+ const targetItemNodeType = schema.nodes[targetItemType];
70
+ const isTargetTaskItem = targetItemType === 'taskItem';
71
+ const isSourceTaskItem = itemNode.type.name === 'taskItem';
72
+ const paragraphType = schema.nodes.paragraph;
73
+ if (!targetItemNodeType) {
74
+ return null;
75
+ }
76
+ if (isTargetTaskItem) {
77
+ const inlineContent = [];
78
+ itemNode.content.forEach(child => {
79
+ if (child.type === paragraphType) {
80
+ child.content.forEach(inline => {
81
+ inlineContent.push(inline);
82
+ });
83
+ }
84
+ if (child.isText) {
85
+ inlineContent.push(child);
86
+ }
87
+ // TODO: EDITOR-3887 - Skip mediaSingle, codeBlock, and nested lists
88
+ // Nested lists will be extracted and placed as siblings in the taskList
89
+ });
90
+ return targetItemNodeType.create({}, Fragment.from(inlineContent));
91
+ } else {
92
+ const newContent = [];
93
+ if (isSourceTaskItem) {
94
+ newContent.push(paragraphType.create(null, itemNode.content));
95
+ } else {
96
+ itemNode.content.forEach(child => {
97
+ if (isListType(child, schema)) {
98
+ if (excludeNestedLists) {
99
+ // Skip nested lists - they will be handled separately as siblings
100
+ return;
101
+ }
102
+ newContent.push(transformList(child, targetListType, targetItemType));
103
+ } else {
104
+ newContent.push(child);
105
+ }
106
+ });
107
+ }
108
+ if (newContent.length === 0) {
109
+ newContent.push(paragraphType.create());
110
+ }
111
+ return targetItemNodeType.create({}, Fragment.from(newContent));
112
+ }
113
+ };
114
+
115
+ /**
116
+ * Recursively converts nested lists to the target list type.
117
+ * This function handles the conversion of both the list container and its items,
118
+ * including any nested lists within those items.
119
+ *
120
+ * Important: taskList has a different nesting structure than bulletList/orderedList:
121
+ * - taskList: nested taskLists are SIBLINGS of taskItems in the parent taskList
122
+ * - bulletList/orderedList: nested lists are CHILDREN of listItems
123
+ */
124
+ const transformList = (node, targetListType, targetItemType) => {
125
+ const schema = node.type.schema;
126
+ const targetListNodeType = schema.nodes[targetListType];
127
+ const targetItemNodeType = schema.nodes[targetItemType];
128
+ const taskListType = schema.nodes.taskList;
129
+ if (!targetListNodeType || !targetItemNodeType) {
130
+ return node;
131
+ }
132
+ const isSourceTaskList = node.type === taskListType;
133
+ const isTargetTaskList = targetListType === 'taskList';
134
+ if (isSourceTaskList && !isTargetTaskList) {
135
+ return convertFromTaskListStructure(node, targetListType, targetItemType);
136
+ } else if (!isSourceTaskList && isTargetTaskList) {
137
+ return convertToTaskListStructure(node, targetListType, targetItemType);
138
+ } else {
139
+ const transformedItems = [];
140
+ node.content.forEach(childNode => {
141
+ const transformedItem = isListType(childNode, schema) ? transformList(childNode, targetListType, targetItemType) : transformListItem(childNode, targetItemType, targetListType);
142
+ if (transformedItem) {
143
+ transformedItems.push(transformedItem);
144
+ }
145
+ });
146
+ return targetListNodeType.create(node.attrs, Fragment.from(transformedItems));
147
+ }
148
+ };
149
+
150
+ /**
151
+ * Transform step that converts between bulletList, orderedList, and taskList types.
152
+ * This step maintains the order and indentation of the list by recursively
153
+ * converting all nested lists while preserving the structure. It also handles
154
+ * conversion between listItem and taskItem types.
155
+ *
156
+ * When converting to taskList/taskItem, unsupported content (images, codeBlocks) is filtered out.
157
+ *
158
+ * @example
159
+ * Input (bulletList with nested bulletList):
160
+ * - bulletList
161
+ * - listItem "1"
162
+ * - bulletList
163
+ * - listItem "1.1"
164
+ * - bulletList
165
+ * - listItem "1.1.1"
166
+ * - listItem "1.2"
167
+ * - listItem "2"
168
+ *
169
+ * Output (orderedList with nested orderedList):
170
+ * 1. orderedList
171
+ * 1. listItem "1"
172
+ * 1. orderedList
173
+ * 1. listItem "1.1"
174
+ * 1. orderedList
175
+ * 1. listItem "1.1.1"
176
+ * 2. listItem "1.2"
177
+ * 2. listItem "2"
178
+ *
179
+ * @example
180
+ * Input (bulletList with nested taskList):
181
+ * - bulletList
182
+ * - listItem "Regular item"
183
+ * - taskList
184
+ * - taskItem "Task 1" (checked)
185
+ * - taskItem "Task 2" (unchecked)
186
+ *
187
+ * Output (orderedList with nested orderedList, taskItems converted to listItems):
188
+ * 1. orderedList
189
+ * 1. listItem "Regular item"
190
+ * 1. orderedList
191
+ * 1. listItem "Task 1"
192
+ * 2. listItem "Task 2"
193
+ *
194
+ * @example
195
+ * Input (bulletList to taskList, with paragraph extraction):
196
+ * - bulletList
197
+ * - listItem
198
+ * - paragraph "Text content"
199
+ * - listItem
200
+ * - paragraph "Text"
201
+ * - codeBlock "code"
202
+ * - mediaSingle (image)
203
+ *
204
+ * Output (taskList with text extracted from paragraphs, unsupported content filtered):
205
+ * - taskList
206
+ * - taskItem "Text content" (text extracted from paragraph)
207
+ * - taskItem "Text" (text extracted, codeBlock and image filtered out)
208
+ *
209
+ * @param nodes - The nodes to transform
210
+ * @param context - The transformation context containing schema and target node type
211
+ * @returns The transformed nodes
212
+ */
213
+ export const listToListStep = (nodes, context) => {
214
+ const {
215
+ schema,
216
+ targetNodeTypeName
217
+ } = context;
218
+ return nodes.map(node => {
219
+ if (isListType(node, schema)) {
220
+ const targetItemType = targetNodeTypeName === 'taskList' ? 'taskItem' : 'listItem';
221
+ return transformList(node, targetNodeTypeName, targetItemType);
222
+ }
223
+ return node;
224
+ });
225
+ };
@@ -1,14 +1,15 @@
1
1
  import { getTargetNodeTypeNameInContext } from '../transform-node-utils/utils';
2
- import { flattenListStep } from './flattenListStep';
3
2
  import { flattenStep } from './flattenStep';
4
3
  import { convertBulletListToTextStep } from './steps/convertBulletListToTextStep';
5
4
  import { convertOrderedListToTextStep } from './steps/convertOrderedListToTextStep';
6
5
  import { convertTaskListToTextStep } from './steps/convertTaskListToTextStep';
6
+ import { flattenListStep } from './steps/flattenListStep';
7
+ import { listToListStep } from './steps/listToListStep';
7
8
  import { unwrapLayoutStep } from './steps/unwrapLayoutStep';
9
+ import { unwrapListStep } from './steps/unwrapListStep';
8
10
  import { stubStep } from './stubStep';
9
11
  import { NODE_CATEGORY_BY_TYPE, toNodeTypeValue } from './types';
10
12
  import { unwrapExpandStep } from './unwrapExpandStep';
11
- import { unwrapListStep } from './unwrapListStep';
12
13
  import { unwrapStep } from './unwrapStep';
13
14
  import { wrapIntoLayoutStep } from './wrapIntoLayoutStep';
14
15
  import { wrapMixedContentStep } from './wrapMixedContentStep';
@@ -39,7 +40,7 @@ const TRANSFORM_STEPS = {
39
40
  list: {
40
41
  atomic: undefined,
41
42
  container: [wrapStep],
42
- list: [stubStep],
43
+ list: [listToListStep],
43
44
  text: [flattenListStep, unwrapListStep]
44
45
  },
45
46
  text: {
@@ -14,12 +14,10 @@ var extractNestedLists = function extractNestedLists(node, listTypes, itemTypes,
14
14
  return grandChild.type === type;
15
15
  })) {
16
16
  nestedLists.push(grandChild);
17
+ } else if (grandChild.isText) {
18
+ contentWithoutNestedLists.push(paragraph.createAndFill({}, grandChild));
17
19
  } else {
18
- if (grandChild.isText) {
19
- contentWithoutNestedLists.push(paragraph.createAndFill({}, grandChild));
20
- } else {
21
- contentWithoutNestedLists.push(grandChild);
22
- }
20
+ contentWithoutNestedLists.push(grandChild);
23
21
  }
24
22
  });
25
23
  items.push(child.copy(Fragment.from(contentWithoutNestedLists)));
@@ -0,0 +1,226 @@
1
+ import { Fragment } from '@atlaskit/editor-prosemirror/model';
2
+ var isListType = function isListType(node, schema) {
3
+ var lists = [schema.nodes.taskList, schema.nodes.bulletList, schema.nodes.orderedList];
4
+ return lists.some(function (list) {
5
+ return list === node.type;
6
+ });
7
+ };
8
+
9
+ /**
10
+ * Converts FROM taskList structure TO bulletList/orderedList structure.
11
+ */
12
+ var convertFromTaskListStructure = function convertFromTaskListStructure(node, targetListType, targetItemType) {
13
+ var schema = node.type.schema;
14
+ var targetListNodeType = schema.nodes[targetListType];
15
+ var convertedItems = [];
16
+ node.content.forEach(function (child) {
17
+ if (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(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, Fragment.from(convertedItems));
36
+ };
37
+
38
+ /**
39
+ * Converts FROM bulletList/orderedList structure TO taskList structure.
40
+ */
41
+ var convertToTaskListStructure = function convertToTaskListStructure(node, targetListType, targetItemType) {
42
+ var schema = node.type.schema;
43
+ var targetListNodeType = schema.nodes[targetListType];
44
+ var transformedContent = [];
45
+ node.content.forEach(function (itemNode) {
46
+ var transformedItem = transformListItem(itemNode, targetItemType, targetListType, true);
47
+ if (transformedItem) {
48
+ transformedContent.push(transformedItem);
49
+ }
50
+ itemNode.content.forEach(function (child) {
51
+ if (isListType(child, schema)) {
52
+ var transformedNestedList = _transformList(child, targetListType, targetItemType);
53
+ transformedContent.push(transformedNestedList);
54
+ }
55
+ });
56
+ });
57
+ return targetListNodeType.create(node.attrs, Fragment.from(transformedContent));
58
+ };
59
+
60
+ /**
61
+ * Converts a single list item (listItem or taskItem) to the target item type.
62
+ * Handles content transformation based on the target type's requirements.
63
+ * @param itemNode - The list item node to convert
64
+ * @param targetItemType - The target item type (listItem or taskItem)
65
+ * @param targetListType - The target list type (bulletList, orderedList, or taskList)
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);
89
+ }
90
+ // TODO: EDITOR-3887 - Skip mediaSingle, codeBlock, and nested lists
91
+ // Nested lists will be extracted and placed as siblings in the taskList
92
+ });
93
+ return targetItemNodeType.create({}, Fragment.from(inlineContent));
94
+ } else {
95
+ var newContent = [];
96
+ if (isSourceTaskItem) {
97
+ newContent.push(paragraphType.create(null, itemNode.content));
98
+ } else {
99
+ itemNode.content.forEach(function (child) {
100
+ if (isListType(child, schema)) {
101
+ if (excludeNestedLists) {
102
+ // Skip nested lists - they will be handled separately as siblings
103
+ return;
104
+ }
105
+ newContent.push(_transformList(child, targetListType, targetItemType));
106
+ } else {
107
+ newContent.push(child);
108
+ }
109
+ });
110
+ }
111
+ if (newContent.length === 0) {
112
+ newContent.push(paragraphType.create());
113
+ }
114
+ return targetItemNodeType.create({}, Fragment.from(newContent));
115
+ }
116
+ };
117
+
118
+ /**
119
+ * Recursively converts nested lists to the target list type.
120
+ * This function handles the conversion of both the list container and its items,
121
+ * including any nested lists within those items.
122
+ *
123
+ * Important: taskList has a different nesting structure than bulletList/orderedList:
124
+ * - taskList: nested taskLists are SIBLINGS of taskItems in the parent taskList
125
+ * - bulletList/orderedList: nested lists are CHILDREN of listItems
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';
137
+ if (isSourceTaskList && !isTargetTaskList) {
138
+ return convertFromTaskListStructure(node, targetListType, targetItemType);
139
+ } else if (!isSourceTaskList && isTargetTaskList) {
140
+ return convertToTaskListStructure(node, targetListType, targetItemType);
141
+ } else {
142
+ var transformedItems = [];
143
+ node.content.forEach(function (childNode) {
144
+ var transformedItem = 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, Fragment.from(transformedItems));
150
+ }
151
+ };
152
+
153
+ /**
154
+ * Transform step that converts between bulletList, orderedList, and taskList types.
155
+ * This step maintains the order and indentation of the list by recursively
156
+ * converting all nested lists while preserving the structure. It also handles
157
+ * conversion between listItem and taskItem types.
158
+ *
159
+ * When converting to taskList/taskItem, unsupported content (images, codeBlocks) is filtered out.
160
+ *
161
+ * @example
162
+ * Input (bulletList with nested bulletList):
163
+ * - bulletList
164
+ * - listItem "1"
165
+ * - bulletList
166
+ * - listItem "1.1"
167
+ * - bulletList
168
+ * - listItem "1.1.1"
169
+ * - listItem "1.2"
170
+ * - listItem "2"
171
+ *
172
+ * Output (orderedList with nested orderedList):
173
+ * 1. orderedList
174
+ * 1. listItem "1"
175
+ * 1. orderedList
176
+ * 1. listItem "1.1"
177
+ * 1. orderedList
178
+ * 1. listItem "1.1.1"
179
+ * 2. listItem "1.2"
180
+ * 2. listItem "2"
181
+ *
182
+ * @example
183
+ * Input (bulletList with nested taskList):
184
+ * - bulletList
185
+ * - listItem "Regular item"
186
+ * - taskList
187
+ * - taskItem "Task 1" (checked)
188
+ * - taskItem "Task 2" (unchecked)
189
+ *
190
+ * Output (orderedList with nested orderedList, taskItems converted to listItems):
191
+ * 1. orderedList
192
+ * 1. listItem "Regular item"
193
+ * 1. orderedList
194
+ * 1. listItem "Task 1"
195
+ * 2. listItem "Task 2"
196
+ *
197
+ * @example
198
+ * Input (bulletList to taskList, with paragraph extraction):
199
+ * - bulletList
200
+ * - listItem
201
+ * - paragraph "Text content"
202
+ * - listItem
203
+ * - paragraph "Text"
204
+ * - codeBlock "code"
205
+ * - mediaSingle (image)
206
+ *
207
+ * Output (taskList with text extracted from paragraphs, unsupported content filtered):
208
+ * - taskList
209
+ * - taskItem "Text content" (text extracted from paragraph)
210
+ * - taskItem "Text" (text extracted, codeBlock and image filtered out)
211
+ *
212
+ * @param nodes - The nodes to transform
213
+ * @param context - The transformation context containing schema and target node type
214
+ * @returns The transformed nodes
215
+ */
216
+ export var listToListStep = function listToListStep(nodes, context) {
217
+ var schema = context.schema,
218
+ targetNodeTypeName = context.targetNodeTypeName;
219
+ return nodes.map(function (node) {
220
+ if (isListType(node, schema)) {
221
+ var targetItemType = targetNodeTypeName === 'taskList' ? 'taskItem' : 'listItem';
222
+ return _transformList(node, targetNodeTypeName, targetItemType);
223
+ }
224
+ return node;
225
+ });
226
+ };
@@ -1,14 +1,15 @@
1
1
  import { getTargetNodeTypeNameInContext } from '../transform-node-utils/utils';
2
- import { flattenListStep } from './flattenListStep';
3
2
  import { flattenStep } from './flattenStep';
4
3
  import { convertBulletListToTextStep } from './steps/convertBulletListToTextStep';
5
4
  import { convertOrderedListToTextStep } from './steps/convertOrderedListToTextStep';
6
5
  import { convertTaskListToTextStep } from './steps/convertTaskListToTextStep';
6
+ import { flattenListStep } from './steps/flattenListStep';
7
+ import { listToListStep } from './steps/listToListStep';
7
8
  import { unwrapLayoutStep } from './steps/unwrapLayoutStep';
9
+ import { unwrapListStep } from './steps/unwrapListStep';
8
10
  import { stubStep } from './stubStep';
9
11
  import { NODE_CATEGORY_BY_TYPE, toNodeTypeValue } from './types';
10
12
  import { unwrapExpandStep } from './unwrapExpandStep';
11
- import { unwrapListStep } from './unwrapListStep';
12
13
  import { unwrapStep } from './unwrapStep';
13
14
  import { wrapIntoLayoutStep } from './wrapIntoLayoutStep';
14
15
  import { wrapMixedContentStep } from './wrapMixedContentStep';
@@ -39,7 +40,7 @@ var TRANSFORM_STEPS = {
39
40
  list: {
40
41
  atomic: undefined,
41
42
  container: [wrapStep],
42
- list: [stubStep],
43
+ list: [listToListStep],
43
44
  text: [flattenListStep, unwrapListStep]
44
45
  },
45
46
  text: {
@@ -1,4 +1,4 @@
1
- import type { TransformStep } from './types';
1
+ import type { TransformStep } from '../types';
2
2
  /**
3
3
  * Given an array of nodes, returns an array with the flattened children of any list node
4
4
  * to it's first ancestor list, maintaining document order.
@@ -0,0 +1,65 @@
1
+ import type { TransformStep } from '../types';
2
+ /**
3
+ * Transform step that converts between bulletList, orderedList, and taskList types.
4
+ * This step maintains the order and indentation of the list by recursively
5
+ * converting all nested lists while preserving the structure. It also handles
6
+ * conversion between listItem and taskItem types.
7
+ *
8
+ * When converting to taskList/taskItem, unsupported content (images, codeBlocks) is filtered out.
9
+ *
10
+ * @example
11
+ * Input (bulletList with nested bulletList):
12
+ * - bulletList
13
+ * - listItem "1"
14
+ * - bulletList
15
+ * - listItem "1.1"
16
+ * - bulletList
17
+ * - listItem "1.1.1"
18
+ * - listItem "1.2"
19
+ * - listItem "2"
20
+ *
21
+ * Output (orderedList with nested orderedList):
22
+ * 1. orderedList
23
+ * 1. listItem "1"
24
+ * 1. orderedList
25
+ * 1. listItem "1.1"
26
+ * 1. orderedList
27
+ * 1. listItem "1.1.1"
28
+ * 2. listItem "1.2"
29
+ * 2. listItem "2"
30
+ *
31
+ * @example
32
+ * Input (bulletList with nested taskList):
33
+ * - bulletList
34
+ * - listItem "Regular item"
35
+ * - taskList
36
+ * - taskItem "Task 1" (checked)
37
+ * - taskItem "Task 2" (unchecked)
38
+ *
39
+ * Output (orderedList with nested orderedList, taskItems converted to listItems):
40
+ * 1. orderedList
41
+ * 1. listItem "Regular item"
42
+ * 1. orderedList
43
+ * 1. listItem "Task 1"
44
+ * 2. listItem "Task 2"
45
+ *
46
+ * @example
47
+ * Input (bulletList to taskList, with paragraph extraction):
48
+ * - bulletList
49
+ * - listItem
50
+ * - paragraph "Text content"
51
+ * - listItem
52
+ * - paragraph "Text"
53
+ * - codeBlock "code"
54
+ * - mediaSingle (image)
55
+ *
56
+ * Output (taskList with text extracted from paragraphs, unsupported content filtered):
57
+ * - taskList
58
+ * - taskItem "Text content" (text extracted from paragraph)
59
+ * - taskItem "Text" (text extracted, codeBlock and image filtered out)
60
+ *
61
+ * @param nodes - The nodes to transform
62
+ * @param context - The transformation context containing schema and target node type
63
+ * @returns The transformed nodes
64
+ */
65
+ export declare const listToListStep: TransformStep;
@@ -1,4 +1,4 @@
1
- import type { TransformStep } from './types';
1
+ import type { TransformStep } from '../types';
2
2
  /**
3
3
  * Given an array of nodes, processes each list removing all parent list nodes and
4
4
  * just returning their child contents.
@@ -1,4 +1,4 @@
1
- import type { TransformStep } from './types';
1
+ import type { TransformStep } from '../types';
2
2
  /**
3
3
  * Given an array of nodes, returns an array with the flattened children of any list node
4
4
  * to it's first ancestor list, maintaining document order.
@@ -0,0 +1,65 @@
1
+ import type { TransformStep } from '../types';
2
+ /**
3
+ * Transform step that converts between bulletList, orderedList, and taskList types.
4
+ * This step maintains the order and indentation of the list by recursively
5
+ * converting all nested lists while preserving the structure. It also handles
6
+ * conversion between listItem and taskItem types.
7
+ *
8
+ * When converting to taskList/taskItem, unsupported content (images, codeBlocks) is filtered out.
9
+ *
10
+ * @example
11
+ * Input (bulletList with nested bulletList):
12
+ * - bulletList
13
+ * - listItem "1"
14
+ * - bulletList
15
+ * - listItem "1.1"
16
+ * - bulletList
17
+ * - listItem "1.1.1"
18
+ * - listItem "1.2"
19
+ * - listItem "2"
20
+ *
21
+ * Output (orderedList with nested orderedList):
22
+ * 1. orderedList
23
+ * 1. listItem "1"
24
+ * 1. orderedList
25
+ * 1. listItem "1.1"
26
+ * 1. orderedList
27
+ * 1. listItem "1.1.1"
28
+ * 2. listItem "1.2"
29
+ * 2. listItem "2"
30
+ *
31
+ * @example
32
+ * Input (bulletList with nested taskList):
33
+ * - bulletList
34
+ * - listItem "Regular item"
35
+ * - taskList
36
+ * - taskItem "Task 1" (checked)
37
+ * - taskItem "Task 2" (unchecked)
38
+ *
39
+ * Output (orderedList with nested orderedList, taskItems converted to listItems):
40
+ * 1. orderedList
41
+ * 1. listItem "Regular item"
42
+ * 1. orderedList
43
+ * 1. listItem "Task 1"
44
+ * 2. listItem "Task 2"
45
+ *
46
+ * @example
47
+ * Input (bulletList to taskList, with paragraph extraction):
48
+ * - bulletList
49
+ * - listItem
50
+ * - paragraph "Text content"
51
+ * - listItem
52
+ * - paragraph "Text"
53
+ * - codeBlock "code"
54
+ * - mediaSingle (image)
55
+ *
56
+ * Output (taskList with text extracted from paragraphs, unsupported content filtered):
57
+ * - taskList
58
+ * - taskItem "Text content" (text extracted from paragraph)
59
+ * - taskItem "Text" (text extracted, codeBlock and image filtered out)
60
+ *
61
+ * @param nodes - The nodes to transform
62
+ * @param context - The transformation context containing schema and target node type
63
+ * @returns The transformed nodes
64
+ */
65
+ export declare const listToListStep: TransformStep;
@@ -1,4 +1,4 @@
1
- import type { TransformStep } from './types';
1
+ import type { TransformStep } from '../types';
2
2
  /**
3
3
  * Given an array of nodes, processes each list removing all parent list nodes and
4
4
  * just returning their child contents.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-menu",
3
- "version": "5.2.2",
3
+ "version": "5.2.3",
4
4
  "description": "BlockMenu plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",