@atlaskit/editor-plugin-block-menu 5.2.2 → 5.2.4
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 +16 -0
- package/dist/cjs/editor-commands/transform-node-utils/{flattenListStep.js → steps/flattenListStep.js} +3 -5
- package/dist/cjs/editor-commands/transform-node-utils/steps/listToListStep.js +232 -0
- package/dist/cjs/editor-commands/transform-node-utils/{wrapMixedContentStep.js → steps/wrapMixedContentStep.js} +25 -25
- package/dist/cjs/editor-commands/transform-node-utils/transform.js +14 -17
- package/dist/es2019/editor-commands/transform-node-utils/{flattenListStep.js → steps/flattenListStep.js} +3 -5
- package/dist/es2019/editor-commands/transform-node-utils/steps/listToListStep.js +225 -0
- package/dist/es2019/editor-commands/transform-node-utils/{wrapMixedContentStep.js → steps/wrapMixedContentStep.js} +25 -22
- package/dist/es2019/editor-commands/transform-node-utils/transform.js +14 -17
- package/dist/esm/editor-commands/transform-node-utils/{flattenListStep.js → steps/flattenListStep.js} +3 -5
- package/dist/esm/editor-commands/transform-node-utils/steps/listToListStep.js +226 -0
- package/dist/esm/editor-commands/transform-node-utils/{wrapMixedContentStep.js → steps/wrapMixedContentStep.js} +25 -24
- package/dist/esm/editor-commands/transform-node-utils/transform.js +14 -17
- package/dist/{types-ts4.5/editor-commands/transform-node-utils → types/editor-commands/transform-node-utils/steps}/flattenListStep.d.ts +1 -1
- package/dist/types/editor-commands/transform-node-utils/steps/listToListStep.d.ts +65 -0
- package/dist/types/editor-commands/transform-node-utils/{unwrapListStep.d.ts → steps/unwrapListStep.d.ts} +1 -1
- package/dist/types/editor-commands/transform-node-utils/{wrapMixedContentStep.d.ts → steps/wrapMixedContentStep.d.ts} +1 -1
- package/dist/{types/editor-commands/transform-node-utils → types-ts4.5/editor-commands/transform-node-utils/steps}/flattenListStep.d.ts +1 -1
- package/dist/types-ts4.5/editor-commands/transform-node-utils/steps/listToListStep.d.ts +65 -0
- package/dist/types-ts4.5/editor-commands/transform-node-utils/{unwrapListStep.d.ts → steps/unwrapListStep.d.ts} +1 -1
- package/dist/types-ts4.5/editor-commands/transform-node-utils/{wrapMixedContentStep.d.ts → steps/wrapMixedContentStep.d.ts} +1 -1
- package/package.json +1 -1
- package/dist/cjs/editor-commands/transform-node-utils/steps/convertBulletListToTextStep.js +0 -34
- package/dist/cjs/editor-commands/transform-node-utils/steps/convertOrderedListToTextStep.js +0 -62
- package/dist/cjs/editor-commands/transform-node-utils/steps/convertTaskListToTextStep.js +0 -39
- package/dist/cjs/editor-commands/transform-node-utils/steps/createListToTextStep.js +0 -90
- package/dist/es2019/editor-commands/transform-node-utils/steps/convertBulletListToTextStep.js +0 -27
- package/dist/es2019/editor-commands/transform-node-utils/steps/convertOrderedListToTextStep.js +0 -55
- package/dist/es2019/editor-commands/transform-node-utils/steps/convertTaskListToTextStep.js +0 -34
- package/dist/es2019/editor-commands/transform-node-utils/steps/createListToTextStep.js +0 -86
- package/dist/esm/editor-commands/transform-node-utils/steps/convertBulletListToTextStep.js +0 -29
- package/dist/esm/editor-commands/transform-node-utils/steps/convertOrderedListToTextStep.js +0 -57
- package/dist/esm/editor-commands/transform-node-utils/steps/convertTaskListToTextStep.js +0 -34
- package/dist/esm/editor-commands/transform-node-utils/steps/createListToTextStep.js +0 -85
- package/dist/types/editor-commands/transform-node-utils/steps/convertBulletListToTextStep.d.ts +0 -18
- package/dist/types/editor-commands/transform-node-utils/steps/convertOrderedListToTextStep.d.ts +0 -19
- package/dist/types/editor-commands/transform-node-utils/steps/convertTaskListToTextStep.d.ts +0 -22
- package/dist/types/editor-commands/transform-node-utils/steps/createListToTextStep.d.ts +0 -38
- package/dist/types-ts4.5/editor-commands/transform-node-utils/steps/convertBulletListToTextStep.d.ts +0 -18
- package/dist/types-ts4.5/editor-commands/transform-node-utils/steps/convertOrderedListToTextStep.d.ts +0 -19
- package/dist/types-ts4.5/editor-commands/transform-node-utils/steps/convertTaskListToTextStep.d.ts +0 -22
- package/dist/types-ts4.5/editor-commands/transform-node-utils/steps/createListToTextStep.d.ts +0 -38
- /package/dist/cjs/editor-commands/transform-node-utils/{unwrapListStep.js → steps/unwrapListStep.js} +0 -0
- /package/dist/es2019/editor-commands/transform-node-utils/{unwrapListStep.js → steps/unwrapListStep.js} +0 -0
- /package/dist/esm/editor-commands/transform-node-utils/{unwrapListStep.js → steps/unwrapListStep.js} +0 -0
|
@@ -1,29 +1,28 @@
|
|
|
1
1
|
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
-
import { NODE_CATEGORY_BY_TYPE } from '
|
|
3
|
-
import { unwrapStep } from './unwrapStep';
|
|
2
|
+
import { NODE_CATEGORY_BY_TYPE } from '../types';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
|
-
* Determines if a node
|
|
7
|
-
*
|
|
8
|
-
* According to the text transformations list, flattenable nodes are:
|
|
9
|
-
* - Bulleted list, Numbered list, Task list
|
|
10
|
-
* - Text nodes (heading, paragraph)
|
|
11
|
-
*
|
|
12
|
-
* Containers (panels, expands, layouts, blockquotes) and atomic nodes (tables, media, macros) break out.
|
|
5
|
+
* Determines if a node is a text node (heading or paragraph).
|
|
6
|
+
* Text nodes can have their content converted to paragraphs when they can't be wrapped directly.
|
|
13
7
|
*/
|
|
14
|
-
const
|
|
8
|
+
const isTextNode = node => {
|
|
15
9
|
const category = NODE_CATEGORY_BY_TYPE[node.type.name];
|
|
16
|
-
|
|
17
|
-
return category === 'text' || category === 'list';
|
|
10
|
+
return category === 'text';
|
|
18
11
|
};
|
|
19
12
|
|
|
20
13
|
/**
|
|
21
|
-
*
|
|
22
|
-
* This is
|
|
23
|
-
*
|
|
14
|
+
* Converts a text node (heading, paragraph) to a paragraph preserving its inline content.
|
|
15
|
+
* This is used when a text node can't be wrapped directly in the target container
|
|
16
|
+
* (e.g., heading can't go in blockquote, so it becomes a paragraph).
|
|
24
17
|
*/
|
|
25
|
-
const
|
|
26
|
-
|
|
18
|
+
const convertTextNodeToParagraph = (node, schema) => {
|
|
19
|
+
var _schema$nodes$paragra;
|
|
20
|
+
// If it's already a paragraph, return as-is
|
|
21
|
+
if (node.type.name === 'paragraph') {
|
|
22
|
+
return node;
|
|
23
|
+
}
|
|
24
|
+
// Convert heading (or other text node) to paragraph with same inline content
|
|
25
|
+
return (_schema$nodes$paragra = schema.nodes.paragraph.createAndFill({}, node.content)) !== null && _schema$nodes$paragra !== void 0 ? _schema$nodes$paragra : null;
|
|
27
26
|
};
|
|
28
27
|
|
|
29
28
|
/**
|
|
@@ -118,12 +117,16 @@ export const wrapMixedContentStep = (nodes, context) => {
|
|
|
118
117
|
if (expandNode) {
|
|
119
118
|
result.push(expandNode);
|
|
120
119
|
}
|
|
121
|
-
} else if (
|
|
122
|
-
//
|
|
123
|
-
|
|
124
|
-
|
|
120
|
+
} else if (isTextNode(node)) {
|
|
121
|
+
// Text node (heading, paragraph) that can't be wrapped - convert to paragraph
|
|
122
|
+
// Example: heading can't go in blockquote, so convert to paragraph with same content
|
|
123
|
+
const paragraph = convertTextNodeToParagraph(node, schema);
|
|
124
|
+
if (paragraph) {
|
|
125
|
+
currentContainerContent.push(paragraph);
|
|
126
|
+
}
|
|
125
127
|
} else {
|
|
126
|
-
//
|
|
128
|
+
// All other nodes that cannot be wrapped (lists, containers, tables, media, macros) - break out
|
|
129
|
+
// This includes list nodes like taskList that can't be placed in certain containers
|
|
127
130
|
flushCurrentContainer();
|
|
128
131
|
result.push(node);
|
|
129
132
|
}
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import { getTargetNodeTypeNameInContext } from '../transform-node-utils/utils';
|
|
2
|
-
import { flattenListStep } from './flattenListStep';
|
|
3
2
|
import { flattenStep } from './flattenStep';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { convertTaskListToTextStep } from './steps/convertTaskListToTextStep';
|
|
3
|
+
import { flattenListStep } from './steps/flattenListStep';
|
|
4
|
+
import { listToListStep } from './steps/listToListStep';
|
|
7
5
|
import { unwrapLayoutStep } from './steps/unwrapLayoutStep';
|
|
6
|
+
import { unwrapListStep } from './steps/unwrapListStep';
|
|
7
|
+
import { wrapMixedContentStep } from './steps/wrapMixedContentStep';
|
|
8
8
|
import { stubStep } from './stubStep';
|
|
9
9
|
import { NODE_CATEGORY_BY_TYPE, toNodeTypeValue } from './types';
|
|
10
10
|
import { unwrapExpandStep } from './unwrapExpandStep';
|
|
11
|
-
import { unwrapListStep } from './unwrapListStep';
|
|
12
11
|
import { unwrapStep } from './unwrapStep';
|
|
13
12
|
import { wrapIntoLayoutStep } from './wrapIntoLayoutStep';
|
|
14
|
-
import { wrapMixedContentStep } from './wrapMixedContentStep';
|
|
15
13
|
import { wrapStep } from './wrapStep';
|
|
16
14
|
|
|
17
15
|
// Exampled step for overrides:
|
|
@@ -39,7 +37,7 @@ const TRANSFORM_STEPS = {
|
|
|
39
37
|
list: {
|
|
40
38
|
atomic: undefined,
|
|
41
39
|
container: [wrapStep],
|
|
42
|
-
list: [
|
|
40
|
+
list: [listToListStep],
|
|
43
41
|
text: [flattenListStep, unwrapListStep]
|
|
44
42
|
},
|
|
45
43
|
text: {
|
|
@@ -58,7 +56,8 @@ const TRANSFORM_STEPS_OVERRIDE = {
|
|
|
58
56
|
},
|
|
59
57
|
panel: {
|
|
60
58
|
layoutSection: [unwrapStep, wrapIntoLayoutStep],
|
|
61
|
-
codeBlock: [unwrapStep, flattenStep, wrapStep]
|
|
59
|
+
codeBlock: [unwrapStep, flattenStep, wrapStep],
|
|
60
|
+
blockquote: [unwrapStep, wrapMixedContentStep]
|
|
62
61
|
},
|
|
63
62
|
expand: {
|
|
64
63
|
panel: [unwrapExpandStep, wrapMixedContentStep],
|
|
@@ -94,21 +93,19 @@ const TRANSFORM_STEPS_OVERRIDE = {
|
|
|
94
93
|
panel: [wrapStep]
|
|
95
94
|
},
|
|
96
95
|
bulletList: {
|
|
97
|
-
//
|
|
98
|
-
codeBlock: [
|
|
96
|
+
// Text transformations currently not in scope > options will be disabled > stubbing in case
|
|
97
|
+
codeBlock: [stubStep],
|
|
99
98
|
layoutSection: [wrapIntoLayoutStep]
|
|
100
99
|
},
|
|
101
100
|
orderedList: {
|
|
102
|
-
//
|
|
103
|
-
codeBlock: [
|
|
104
|
-
// Warning: Actuall transformation logic not complete (Likelly prosemirror-markdown to be used)
|
|
101
|
+
// Text transformations currently not in scope > options will be disabled > stubbing in case
|
|
102
|
+
codeBlock: [stubStep],
|
|
105
103
|
layoutSection: [wrapIntoLayoutStep]
|
|
106
104
|
},
|
|
107
105
|
taskList: {
|
|
108
|
-
//
|
|
109
|
-
blockquote: [
|
|
110
|
-
|
|
111
|
-
codeBlock: [convertTaskListToTextStep, flattenStep, wrapStep],
|
|
106
|
+
// Text transformations currently not in scope > options will be disabled > stubbing in case
|
|
107
|
+
blockquote: [stubStep],
|
|
108
|
+
codeBlock: [stubStep],
|
|
112
109
|
layoutSection: [wrapIntoLayoutStep]
|
|
113
110
|
},
|
|
114
111
|
table: {
|
|
@@ -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
|
-
|
|
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,30 +1,28 @@
|
|
|
1
|
-
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
1
|
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
-
import { NODE_CATEGORY_BY_TYPE } from '
|
|
4
|
-
import { unwrapStep } from './unwrapStep';
|
|
2
|
+
import { NODE_CATEGORY_BY_TYPE } from '../types';
|
|
5
3
|
|
|
6
4
|
/**
|
|
7
|
-
* Determines if a node
|
|
8
|
-
*
|
|
9
|
-
* According to the text transformations list, flattenable nodes are:
|
|
10
|
-
* - Bulleted list, Numbered list, Task list
|
|
11
|
-
* - Text nodes (heading, paragraph)
|
|
12
|
-
*
|
|
13
|
-
* Containers (panels, expands, layouts, blockquotes) and atomic nodes (tables, media, macros) break out.
|
|
5
|
+
* Determines if a node is a text node (heading or paragraph).
|
|
6
|
+
* Text nodes can have their content converted to paragraphs when they can't be wrapped directly.
|
|
14
7
|
*/
|
|
15
|
-
var
|
|
8
|
+
var isTextNode = function isTextNode(node) {
|
|
16
9
|
var category = NODE_CATEGORY_BY_TYPE[node.type.name];
|
|
17
|
-
|
|
18
|
-
return category === 'text' || category === 'list';
|
|
10
|
+
return category === 'text';
|
|
19
11
|
};
|
|
20
12
|
|
|
21
13
|
/**
|
|
22
|
-
*
|
|
23
|
-
* This is
|
|
24
|
-
*
|
|
14
|
+
* Converts a text node (heading, paragraph) to a paragraph preserving its inline content.
|
|
15
|
+
* This is used when a text node can't be wrapped directly in the target container
|
|
16
|
+
* (e.g., heading can't go in blockquote, so it becomes a paragraph).
|
|
25
17
|
*/
|
|
26
|
-
var
|
|
27
|
-
|
|
18
|
+
var convertTextNodeToParagraph = function convertTextNodeToParagraph(node, schema) {
|
|
19
|
+
var _schema$nodes$paragra;
|
|
20
|
+
// If it's already a paragraph, return as-is
|
|
21
|
+
if (node.type.name === 'paragraph') {
|
|
22
|
+
return node;
|
|
23
|
+
}
|
|
24
|
+
// Convert heading (or other text node) to paragraph with same inline content
|
|
25
|
+
return (_schema$nodes$paragra = schema.nodes.paragraph.createAndFill({}, node.content)) !== null && _schema$nodes$paragra !== void 0 ? _schema$nodes$paragra : null;
|
|
28
26
|
};
|
|
29
27
|
|
|
30
28
|
/**
|
|
@@ -117,13 +115,16 @@ export var wrapMixedContentStep = function wrapMixedContentStep(nodes, context)
|
|
|
117
115
|
if (expandNode) {
|
|
118
116
|
result.push(expandNode);
|
|
119
117
|
}
|
|
120
|
-
} else if (
|
|
121
|
-
|
|
122
|
-
//
|
|
123
|
-
var
|
|
124
|
-
(
|
|
118
|
+
} else if (isTextNode(node)) {
|
|
119
|
+
// Text node (heading, paragraph) that can't be wrapped - convert to paragraph
|
|
120
|
+
// Example: heading can't go in blockquote, so convert to paragraph with same content
|
|
121
|
+
var paragraph = convertTextNodeToParagraph(node, schema);
|
|
122
|
+
if (paragraph) {
|
|
123
|
+
currentContainerContent.push(paragraph);
|
|
124
|
+
}
|
|
125
125
|
} else {
|
|
126
|
-
//
|
|
126
|
+
// All other nodes that cannot be wrapped (lists, containers, tables, media, macros) - break out
|
|
127
|
+
// This includes list nodes like taskList that can't be placed in certain containers
|
|
127
128
|
flushCurrentContainer();
|
|
128
129
|
result.push(node);
|
|
129
130
|
}
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import { getTargetNodeTypeNameInContext } from '../transform-node-utils/utils';
|
|
2
|
-
import { flattenListStep } from './flattenListStep';
|
|
3
2
|
import { flattenStep } from './flattenStep';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { convertTaskListToTextStep } from './steps/convertTaskListToTextStep';
|
|
3
|
+
import { flattenListStep } from './steps/flattenListStep';
|
|
4
|
+
import { listToListStep } from './steps/listToListStep';
|
|
7
5
|
import { unwrapLayoutStep } from './steps/unwrapLayoutStep';
|
|
6
|
+
import { unwrapListStep } from './steps/unwrapListStep';
|
|
7
|
+
import { wrapMixedContentStep } from './steps/wrapMixedContentStep';
|
|
8
8
|
import { stubStep } from './stubStep';
|
|
9
9
|
import { NODE_CATEGORY_BY_TYPE, toNodeTypeValue } from './types';
|
|
10
10
|
import { unwrapExpandStep } from './unwrapExpandStep';
|
|
11
|
-
import { unwrapListStep } from './unwrapListStep';
|
|
12
11
|
import { unwrapStep } from './unwrapStep';
|
|
13
12
|
import { wrapIntoLayoutStep } from './wrapIntoLayoutStep';
|
|
14
|
-
import { wrapMixedContentStep } from './wrapMixedContentStep';
|
|
15
13
|
import { wrapStep } from './wrapStep';
|
|
16
14
|
|
|
17
15
|
// Exampled step for overrides:
|
|
@@ -39,7 +37,7 @@ var TRANSFORM_STEPS = {
|
|
|
39
37
|
list: {
|
|
40
38
|
atomic: undefined,
|
|
41
39
|
container: [wrapStep],
|
|
42
|
-
list: [
|
|
40
|
+
list: [listToListStep],
|
|
43
41
|
text: [flattenListStep, unwrapListStep]
|
|
44
42
|
},
|
|
45
43
|
text: {
|
|
@@ -58,7 +56,8 @@ var TRANSFORM_STEPS_OVERRIDE = {
|
|
|
58
56
|
},
|
|
59
57
|
panel: {
|
|
60
58
|
layoutSection: [unwrapStep, wrapIntoLayoutStep],
|
|
61
|
-
codeBlock: [unwrapStep, flattenStep, wrapStep]
|
|
59
|
+
codeBlock: [unwrapStep, flattenStep, wrapStep],
|
|
60
|
+
blockquote: [unwrapStep, wrapMixedContentStep]
|
|
62
61
|
},
|
|
63
62
|
expand: {
|
|
64
63
|
panel: [unwrapExpandStep, wrapMixedContentStep],
|
|
@@ -94,21 +93,19 @@ var TRANSFORM_STEPS_OVERRIDE = {
|
|
|
94
93
|
panel: [wrapStep]
|
|
95
94
|
},
|
|
96
95
|
bulletList: {
|
|
97
|
-
//
|
|
98
|
-
codeBlock: [
|
|
96
|
+
// Text transformations currently not in scope > options will be disabled > stubbing in case
|
|
97
|
+
codeBlock: [stubStep],
|
|
99
98
|
layoutSection: [wrapIntoLayoutStep]
|
|
100
99
|
},
|
|
101
100
|
orderedList: {
|
|
102
|
-
//
|
|
103
|
-
codeBlock: [
|
|
104
|
-
// Warning: Actuall transformation logic not complete (Likelly prosemirror-markdown to be used)
|
|
101
|
+
// Text transformations currently not in scope > options will be disabled > stubbing in case
|
|
102
|
+
codeBlock: [stubStep],
|
|
105
103
|
layoutSection: [wrapIntoLayoutStep]
|
|
106
104
|
},
|
|
107
105
|
taskList: {
|
|
108
|
-
//
|
|
109
|
-
blockquote: [
|
|
110
|
-
|
|
111
|
-
codeBlock: [convertTaskListToTextStep, flattenStep, wrapStep],
|
|
106
|
+
// Text transformations currently not in scope > options will be disabled > stubbing in case
|
|
107
|
+
blockquote: [stubStep],
|
|
108
|
+
codeBlock: [stubStep],
|
|
112
109
|
layoutSection: [wrapIntoLayoutStep]
|
|
113
110
|
},
|
|
114
111
|
table: {
|
|
@@ -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;
|