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

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 (48) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/editor-commands/transform-node-utils/steps/decisionListToListStep.js +88 -0
  3. package/dist/cjs/editor-commands/transform-node-utils/steps/listToDecisionListStep.js +61 -0
  4. package/dist/cjs/editor-commands/transform-node-utils/steps/listToListStep.js +6 -12
  5. package/dist/cjs/editor-commands/transform-node-utils/{wrapMixedContentStep.js → steps/wrapMixedContentStep.js} +25 -25
  6. package/dist/cjs/editor-commands/transform-node-utils/transform.js +23 -17
  7. package/dist/cjs/editor-commands/transform-node-utils/utils.js +7 -1
  8. package/dist/es2019/editor-commands/transform-node-utils/steps/decisionListToListStep.js +85 -0
  9. package/dist/es2019/editor-commands/transform-node-utils/steps/listToDecisionListStep.js +58 -0
  10. package/dist/es2019/editor-commands/transform-node-utils/steps/listToListStep.js +1 -4
  11. package/dist/es2019/editor-commands/transform-node-utils/{wrapMixedContentStep.js → steps/wrapMixedContentStep.js} +25 -22
  12. package/dist/es2019/editor-commands/transform-node-utils/transform.js +23 -17
  13. package/dist/es2019/editor-commands/transform-node-utils/utils.js +4 -0
  14. package/dist/esm/editor-commands/transform-node-utils/steps/decisionListToListStep.js +82 -0
  15. package/dist/esm/editor-commands/transform-node-utils/steps/listToDecisionListStep.js +56 -0
  16. package/dist/esm/editor-commands/transform-node-utils/steps/listToListStep.js +1 -6
  17. package/dist/esm/editor-commands/transform-node-utils/{wrapMixedContentStep.js → steps/wrapMixedContentStep.js} +25 -24
  18. package/dist/esm/editor-commands/transform-node-utils/transform.js +23 -17
  19. package/dist/esm/editor-commands/transform-node-utils/utils.js +6 -0
  20. package/dist/types/editor-commands/transform-node-utils/steps/decisionListToListStep.d.ts +30 -0
  21. package/dist/types/editor-commands/transform-node-utils/steps/listToDecisionListStep.d.ts +25 -0
  22. package/dist/types/editor-commands/transform-node-utils/{wrapMixedContentStep.d.ts → steps/wrapMixedContentStep.d.ts} +1 -1
  23. package/dist/types/editor-commands/transform-node-utils/utils.d.ts +2 -0
  24. package/dist/types-ts4.5/editor-commands/transform-node-utils/steps/decisionListToListStep.d.ts +30 -0
  25. package/dist/types-ts4.5/editor-commands/transform-node-utils/steps/listToDecisionListStep.d.ts +25 -0
  26. package/dist/types-ts4.5/editor-commands/transform-node-utils/{wrapMixedContentStep.d.ts → steps/wrapMixedContentStep.d.ts} +1 -1
  27. package/dist/types-ts4.5/editor-commands/transform-node-utils/utils.d.ts +2 -0
  28. package/package.json +1 -1
  29. package/dist/cjs/editor-commands/transform-node-utils/steps/convertBulletListToTextStep.js +0 -34
  30. package/dist/cjs/editor-commands/transform-node-utils/steps/convertOrderedListToTextStep.js +0 -62
  31. package/dist/cjs/editor-commands/transform-node-utils/steps/convertTaskListToTextStep.js +0 -39
  32. package/dist/cjs/editor-commands/transform-node-utils/steps/createListToTextStep.js +0 -90
  33. package/dist/es2019/editor-commands/transform-node-utils/steps/convertBulletListToTextStep.js +0 -27
  34. package/dist/es2019/editor-commands/transform-node-utils/steps/convertOrderedListToTextStep.js +0 -55
  35. package/dist/es2019/editor-commands/transform-node-utils/steps/convertTaskListToTextStep.js +0 -34
  36. package/dist/es2019/editor-commands/transform-node-utils/steps/createListToTextStep.js +0 -86
  37. package/dist/esm/editor-commands/transform-node-utils/steps/convertBulletListToTextStep.js +0 -29
  38. package/dist/esm/editor-commands/transform-node-utils/steps/convertOrderedListToTextStep.js +0 -57
  39. package/dist/esm/editor-commands/transform-node-utils/steps/convertTaskListToTextStep.js +0 -34
  40. package/dist/esm/editor-commands/transform-node-utils/steps/createListToTextStep.js +0 -85
  41. package/dist/types/editor-commands/transform-node-utils/steps/convertBulletListToTextStep.d.ts +0 -18
  42. package/dist/types/editor-commands/transform-node-utils/steps/convertOrderedListToTextStep.d.ts +0 -19
  43. package/dist/types/editor-commands/transform-node-utils/steps/convertTaskListToTextStep.d.ts +0 -22
  44. package/dist/types/editor-commands/transform-node-utils/steps/createListToTextStep.d.ts +0 -38
  45. package/dist/types-ts4.5/editor-commands/transform-node-utils/steps/convertBulletListToTextStep.d.ts +0 -18
  46. package/dist/types-ts4.5/editor-commands/transform-node-utils/steps/convertOrderedListToTextStep.d.ts +0 -19
  47. package/dist/types-ts4.5/editor-commands/transform-node-utils/steps/convertTaskListToTextStep.d.ts +0 -22
  48. package/dist/types-ts4.5/editor-commands/transform-node-utils/steps/createListToTextStep.d.ts +0 -38
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @atlaskit/editor-plugin-block-menu
2
2
 
3
+ ## 5.2.5
4
+
5
+ ### Patch Changes
6
+
7
+ - [`c125e9935090b`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/c125e9935090b) -
8
+ Add decision list transformation support in block menu
9
+
10
+ ## 5.2.4
11
+
12
+ ### Patch Changes
13
+
14
+ - [`dbbf4fabef4fe`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/dbbf4fabef4fe) -
15
+ [ux] Scope change | Remove text transformations for incompatible nodes
16
+ - [`bb7cbcb12ae4f`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/bb7cbcb12ae4f) -
17
+ [ux] Implement transformation steps for panel to other nodes
18
+
3
19
  ## 5.2.3
4
20
 
5
21
  ### Patch Changes
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.decisionListToListStep = void 0;
7
+ var _model = require("@atlaskit/editor-prosemirror/model");
8
+ var targets = function targets(targetNodeTypeName, schema) {
9
+ var targetListType;
10
+ var targetItemType;
11
+ switch (targetNodeTypeName) {
12
+ case 'bulletList':
13
+ targetListType = schema.nodes.bulletList;
14
+ targetItemType = schema.nodes.listItem;
15
+ break;
16
+ case 'orderedList':
17
+ targetListType = schema.nodes.orderedList;
18
+ targetItemType = schema.nodes.listItem;
19
+ break;
20
+ case 'taskList':
21
+ targetListType = schema.nodes.taskList;
22
+ targetItemType = schema.nodes.taskItem;
23
+ break;
24
+ default:
25
+ }
26
+ return {
27
+ targetListType: targetListType,
28
+ targetItemType: targetItemType
29
+ };
30
+ };
31
+
32
+ /**
33
+ * Transforms a decisionList into a bulletList, orderedList, or taskList.
34
+ * Decision items are converted to the appropriate list item type.
35
+ *
36
+ * @example
37
+ * Input (decisionList):
38
+ * - decisionList
39
+ * - decisionItem "Task 1"
40
+ * - decisionItem "Task 2"
41
+ *
42
+ * Output (bulletList):
43
+ * - bulletList
44
+ * - listItem
45
+ * - paragraph "Task 1"
46
+ * - listItem
47
+ * - paragraph "Task 2"
48
+ *
49
+ * Output (taskList):
50
+ * - taskList
51
+ * - taskItem
52
+ * - paragraph "Task 1"
53
+ * - taskItem
54
+ * - paragraph "Task 2"
55
+ *
56
+ * @param nodes - Array of nodes to transform
57
+ * @param context - Transform context with schema and target node type
58
+ * @returns array of transformed nodes
59
+ */
60
+ var decisionListToListStep = exports.decisionListToListStep = function decisionListToListStep(nodes, context) {
61
+ var schema = context.schema,
62
+ targetNodeTypeName = context.targetNodeTypeName;
63
+ var paragraphType = schema.nodes.paragraph;
64
+ return nodes.map(function (node) {
65
+ if (node.type !== schema.nodes.decisionList) {
66
+ return node;
67
+ }
68
+ var _targets = targets(targetNodeTypeName, schema),
69
+ targetListType = _targets.targetListType,
70
+ targetItemType = _targets.targetItemType;
71
+ if (!targetListType || !targetItemType) {
72
+ return node;
73
+ }
74
+ var newItems = [];
75
+ node.forEach(function (decisionItem) {
76
+ var itemContent = [];
77
+ decisionItem.forEach(function (child) {
78
+ itemContent.push(child);
79
+ });
80
+ var newItem = targetItemType === schema.nodes.listItem ? targetItemType.create({}, paragraphType.create({}, itemContent)) : targetItemType.create({}, itemContent);
81
+ if (newItem) {
82
+ newItems.push(newItem);
83
+ }
84
+ });
85
+ var newList = targetListType.create({}, _model.Fragment.from(newItems));
86
+ return newList || node;
87
+ });
88
+ };
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.listToDecisionListStep = void 0;
7
+ var _model = require("@atlaskit/editor-prosemirror/model");
8
+ var _utils = require("../utils");
9
+ /**
10
+ * Transforms a bulletList, orderedList, or taskList into a decisionList.
11
+ *
12
+ * Notes
13
+ * - decisionLists and taskList only support text as children - need to ensure content is converted to text
14
+ *
15
+ * @example
16
+ * Input (nested bulletList):
17
+ * - bulletList
18
+ * - listItem "1.1"
19
+ * - listItem "1.2"
20
+ * - listItem "1.3"
21
+ *
22
+ * Output (flat decisionList):
23
+ * - decisionList
24
+ * - decisionItem "1"
25
+ * - decisionItem "1.1"
26
+ * - decisionItem "2"
27
+ *
28
+ * @param nodes - Array of nodes to transform
29
+ * @param context - Transform context with schema and target node type
30
+ * @returns array of transformed nodes
31
+ */
32
+ var listToDecisionListStep = exports.listToDecisionListStep = function listToDecisionListStep(nodes, context) {
33
+ var schema = context.schema;
34
+ var paragraphType = schema.nodes.paragraph;
35
+ return nodes.map(function (node) {
36
+ if (!(0, _utils.isListType)(node, schema)) {
37
+ return node;
38
+ }
39
+ var decisionItems = [];
40
+ node.forEach(function (item) {
41
+ var itemContent = [];
42
+ item.forEach(function (child) {
43
+ if (child.type === paragraphType) {
44
+ // paragraph may contain hard breaks etc.
45
+ child.content.forEach(function (inline) {
46
+ itemContent.push(inline);
47
+ });
48
+ } else {
49
+ itemContent.push(child);
50
+ }
51
+ // TODO: EDITOR-3887 - Skip mediaSingle, codeBlock, and nested lists
52
+ });
53
+ var decisionItem = schema.nodes.decisionItem.create({}, _model.Fragment.from(itemContent));
54
+ if (decisionItem) {
55
+ decisionItems.push(decisionItem);
56
+ }
57
+ });
58
+ var decisionList = schema.nodes.decisionList.create({}, _model.Fragment.from(decisionItems));
59
+ return decisionList || node;
60
+ });
61
+ };
@@ -5,13 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.listToListStep = void 0;
7
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
-
8
+ var _utils = require("../utils");
15
9
  /**
16
10
  * Converts FROM taskList structure TO bulletList/orderedList structure.
17
11
  */
@@ -20,7 +14,7 @@ var convertFromTaskListStructure = function convertFromTaskListStructure(node, t
20
14
  var targetListNodeType = schema.nodes[targetListType];
21
15
  var convertedItems = [];
22
16
  node.content.forEach(function (child) {
23
- if (isListType(child, schema)) {
17
+ if ((0, _utils.isListType)(child, schema)) {
24
18
  // This is a nested list - it should become a child of the previous item
25
19
  if (convertedItems.length > 0) {
26
20
  var previousItem = convertedItems[convertedItems.length - 1];
@@ -54,7 +48,7 @@ var convertToTaskListStructure = function convertToTaskListStructure(node, targe
54
48
  transformedContent.push(transformedItem);
55
49
  }
56
50
  itemNode.content.forEach(function (child) {
57
- if (isListType(child, schema)) {
51
+ if ((0, _utils.isListType)(child, schema)) {
58
52
  var transformedNestedList = _transformList(child, targetListType, targetItemType);
59
53
  transformedContent.push(transformedNestedList);
60
54
  }
@@ -103,7 +97,7 @@ var transformListItem = function transformListItem(itemNode, targetItemType, tar
103
97
  newContent.push(paragraphType.create(null, itemNode.content));
104
98
  } else {
105
99
  itemNode.content.forEach(function (child) {
106
- if (isListType(child, schema)) {
100
+ if ((0, _utils.isListType)(child, schema)) {
107
101
  if (excludeNestedLists) {
108
102
  // Skip nested lists - they will be handled separately as siblings
109
103
  return;
@@ -147,7 +141,7 @@ var _transformList = function transformList(node, targetListType, targetItemType
147
141
  } else {
148
142
  var transformedItems = [];
149
143
  node.content.forEach(function (childNode) {
150
- var transformedItem = isListType(childNode, schema) ? _transformList(childNode, targetListType, targetItemType) : transformListItem(childNode, targetItemType, targetListType);
144
+ var transformedItem = (0, _utils.isListType)(childNode, schema) ? _transformList(childNode, targetListType, targetItemType) : transformListItem(childNode, targetItemType, targetListType);
151
145
  if (transformedItem) {
152
146
  transformedItems.push(transformedItem);
153
147
  }
@@ -223,7 +217,7 @@ var listToListStep = exports.listToListStep = function listToListStep(nodes, con
223
217
  var schema = context.schema,
224
218
  targetNodeTypeName = context.targetNodeTypeName;
225
219
  return nodes.map(function (node) {
226
- if (isListType(node, schema)) {
220
+ if ((0, _utils.isListType)(node, schema)) {
227
221
  var targetItemType = targetNodeTypeName === 'taskList' ? 'taskItem' : 'listItem';
228
222
  return _transformList(node, targetNodeTypeName, targetItemType);
229
223
  }
@@ -1,36 +1,33 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.wrapMixedContentStep = void 0;
8
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
7
  var _model = require("@atlaskit/editor-prosemirror/model");
10
- var _types = require("./types");
11
- var _unwrapStep = require("./unwrapStep");
8
+ var _types = require("../types");
12
9
  /**
13
- * Determines if a node can be flattened (unwrapped and its contents merged).
14
- *
15
- * According to the text transformations list, flattenable nodes are:
16
- * - Bulleted list, Numbered list, Task list
17
- * - Text nodes (heading, paragraph)
18
- *
19
- * Containers (panels, expands, layouts, blockquotes) and atomic nodes (tables, media, macros) break out.
10
+ * Determines if a node is a text node (heading or paragraph).
11
+ * Text nodes can have their content converted to paragraphs when they can't be wrapped directly.
20
12
  */
21
- var canFlatten = function canFlatten(node) {
13
+ var isTextNode = function isTextNode(node) {
22
14
  var category = _types.NODE_CATEGORY_BY_TYPE[node.type.name];
23
- // Text and list nodes can be flattened (converted to simpler forms)
24
- return category === 'text' || category === 'list';
15
+ return category === 'text';
25
16
  };
26
17
 
27
18
  /**
28
- * Flattens a node by extracting its contents using the appropriate unwrap step.
29
- * This is only called for text and list nodes that can be converted to simpler forms.
30
- * Uses unwrapStep to extract children from list containers.
19
+ * Converts a text node (heading, paragraph) to a paragraph preserving its inline content.
20
+ * This is used when a text node can't be wrapped directly in the target container
21
+ * (e.g., heading can't go in blockquote, so it becomes a paragraph).
31
22
  */
32
- var flattenNode = function flattenNode(node, context) {
33
- return (0, _unwrapStep.unwrapStep)([node], context);
23
+ var convertTextNodeToParagraph = function convertTextNodeToParagraph(node, schema) {
24
+ var _schema$nodes$paragra;
25
+ // If it's already a paragraph, return as-is
26
+ if (node.type.name === 'paragraph') {
27
+ return node;
28
+ }
29
+ // Convert heading (or other text node) to paragraph with same inline content
30
+ return (_schema$nodes$paragra = schema.nodes.paragraph.createAndFill({}, node.content)) !== null && _schema$nodes$paragra !== void 0 ? _schema$nodes$paragra : null;
34
31
  };
35
32
 
36
33
  /**
@@ -123,13 +120,16 @@ var wrapMixedContentStep = exports.wrapMixedContentStep = function wrapMixedCont
123
120
  if (expandNode) {
124
121
  result.push(expandNode);
125
122
  }
126
- } else if (canFlatten(node)) {
127
- var _currentContainerCont;
128
- // Node cannot be wrapped but CAN be flattened - flatten and add to container
129
- var flattenedNodes = flattenNode(node, context);
130
- (_currentContainerCont = currentContainerContent).push.apply(_currentContainerCont, (0, _toConsumableArray2.default)(flattenedNodes));
123
+ } else if (isTextNode(node)) {
124
+ // Text node (heading, paragraph) that can't be wrapped - convert to paragraph
125
+ // Example: heading can't go in blockquote, so convert to paragraph with same content
126
+ var paragraph = convertTextNodeToParagraph(node, schema);
127
+ if (paragraph) {
128
+ currentContainerContent.push(paragraph);
129
+ }
131
130
  } else {
132
- // Node cannot be wrapped AND cannot be flattened (containers, tables, media, macros) - break out
131
+ // All other nodes that cannot be wrapped (lists, containers, tables, media, macros) - break out
132
+ // This includes list nodes like taskList that can't be placed in certain containers
133
133
  flushCurrentContainer();
134
134
  result.push(node);
135
135
  }
@@ -6,19 +6,18 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.getOutputNodes = void 0;
7
7
  var _utils = require("../transform-node-utils/utils");
8
8
  var _flattenStep = require("./flattenStep");
9
- var _convertBulletListToTextStep = require("./steps/convertBulletListToTextStep");
10
- var _convertOrderedListToTextStep = require("./steps/convertOrderedListToTextStep");
11
- var _convertTaskListToTextStep = require("./steps/convertTaskListToTextStep");
9
+ var _decisionListToListStep = require("./steps/decisionListToListStep");
12
10
  var _flattenListStep = require("./steps/flattenListStep");
11
+ var _listToDecisionListStep = require("./steps/listToDecisionListStep");
13
12
  var _listToListStep = require("./steps/listToListStep");
14
13
  var _unwrapLayoutStep = require("./steps/unwrapLayoutStep");
15
14
  var _unwrapListStep = require("./steps/unwrapListStep");
15
+ var _wrapMixedContentStep = require("./steps/wrapMixedContentStep");
16
16
  var _stubStep = require("./stubStep");
17
17
  var _types = require("./types");
18
18
  var _unwrapExpandStep = require("./unwrapExpandStep");
19
19
  var _unwrapStep = require("./unwrapStep");
20
20
  var _wrapIntoLayoutStep = require("./wrapIntoLayoutStep");
21
- var _wrapMixedContentStep = require("./wrapMixedContentStep");
22
21
  var _wrapStep = require("./wrapStep");
23
22
  // Exampled step for overrides:
24
23
  // - open Block menu on a paragraph, click 'Panel' in the Turn into'
@@ -64,7 +63,8 @@ var TRANSFORM_STEPS_OVERRIDE = {
64
63
  },
65
64
  panel: {
66
65
  layoutSection: [_unwrapStep.unwrapStep, _wrapIntoLayoutStep.wrapIntoLayoutStep],
67
- codeBlock: [_unwrapStep.unwrapStep, _flattenStep.flattenStep, _wrapStep.wrapStep]
66
+ codeBlock: [_unwrapStep.unwrapStep, _flattenStep.flattenStep, _wrapStep.wrapStep],
67
+ blockquote: [_unwrapStep.unwrapStep, _wrapMixedContentStep.wrapMixedContentStep]
68
68
  },
69
69
  expand: {
70
70
  panel: [_unwrapExpandStep.unwrapExpandStep, _wrapMixedContentStep.wrapMixedContentStep],
@@ -100,26 +100,32 @@ var TRANSFORM_STEPS_OVERRIDE = {
100
100
  panel: [_wrapStep.wrapStep]
101
101
  },
102
102
  bulletList: {
103
- // Warning: Actuall transformation logic not complete (Likelly prosemirror-markdown to be used)
104
- codeBlock: [_convertBulletListToTextStep.convertBulletListToTextStep, _flattenStep.flattenStep, _wrapStep.wrapStep],
105
- layoutSection: [_wrapIntoLayoutStep.wrapIntoLayoutStep]
103
+ // Text transformations currently not in scope > options will be disabled > stubbing in case
104
+ codeBlock: [_stubStep.stubStep],
105
+ layoutSection: [_wrapIntoLayoutStep.wrapIntoLayoutStep],
106
+ decisionList: [_flattenListStep.flattenListStep, _listToDecisionListStep.listToDecisionListStep]
106
107
  },
107
108
  orderedList: {
108
- // Warning: Actuall transformation logic not complete (Likelly prosemirror-markdown to be used)
109
- codeBlock: [_convertOrderedListToTextStep.convertOrderedListToTextStep, _flattenStep.flattenStep, _wrapStep.wrapStep],
110
- // Warning: Actuall transformation logic not complete (Likelly prosemirror-markdown to be used)
111
- layoutSection: [_wrapIntoLayoutStep.wrapIntoLayoutStep]
109
+ // Text transformations currently not in scope > options will be disabled > stubbing in case
110
+ codeBlock: [_stubStep.stubStep],
111
+ layoutSection: [_wrapIntoLayoutStep.wrapIntoLayoutStep],
112
+ decisionList: [_flattenListStep.flattenListStep, _listToDecisionListStep.listToDecisionListStep]
112
113
  },
113
114
  taskList: {
114
- // Warning: Actuall transformation logic not complete (Skeptical that prosemirror-markdown can be used)
115
- blockquote: [_convertTaskListToTextStep.convertTaskListToTextStep, _wrapStep.wrapStep],
116
- // Warning: Actuall transformation logic not complete (Likelly prosemirror-markdown to be used)
117
- codeBlock: [_convertTaskListToTextStep.convertTaskListToTextStep, _flattenStep.flattenStep, _wrapStep.wrapStep],
118
- layoutSection: [_wrapIntoLayoutStep.wrapIntoLayoutStep]
115
+ // Text transformations currently not in scope > options will be disabled > stubbing in case
116
+ blockquote: [_stubStep.stubStep],
117
+ codeBlock: [_stubStep.stubStep],
118
+ layoutSection: [_wrapIntoLayoutStep.wrapIntoLayoutStep],
119
+ decisionList: [_flattenListStep.flattenListStep, _listToDecisionListStep.listToDecisionListStep]
119
120
  },
120
121
  table: {
121
122
  expand: [_wrapStep.wrapStep],
122
123
  layoutSection: [_wrapIntoLayoutStep.wrapIntoLayoutStep]
124
+ },
125
+ decisionList: {
126
+ bulletList: [_decisionListToListStep.decisionListToListStep],
127
+ orderedList: [_decisionListToListStep.decisionListToListStep],
128
+ taskList: [_decisionListToListStep.decisionListToListStep]
123
129
  }
124
130
  };
125
131
  var getTransformStepsForNodeTypes = function getTransformStepsForNodeTypes(selectedNodeTypeName, targetNodeTypeName) {
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getTargetNodeTypeNameInContext = exports.getSelectedNode = exports.expandSelectionToBlockRange = void 0;
6
+ exports.isListType = exports.getTargetNodeTypeNameInContext = exports.getSelectedNode = exports.expandSelectionToBlockRange = void 0;
7
7
  var _selection = require("@atlaskit/editor-common/selection");
8
8
  var _state = require("@atlaskit/editor-prosemirror/state");
9
9
  var _utils = require("@atlaskit/editor-prosemirror/utils");
@@ -89,4 +89,10 @@ var expandSelectionToBlockRange = exports.expandSelectionToBlockRange = function
89
89
  }
90
90
  return true;
91
91
  });
92
+ };
93
+ var isListType = exports.isListType = function isListType(node, schema) {
94
+ var lists = [schema.nodes.taskList, schema.nodes.bulletList, schema.nodes.orderedList];
95
+ return lists.some(function (list) {
96
+ return list === node.type;
97
+ });
92
98
  };
@@ -0,0 +1,85 @@
1
+ import { Fragment } from '@atlaskit/editor-prosemirror/model';
2
+ const targets = (targetNodeTypeName, schema) => {
3
+ let targetListType;
4
+ let targetItemType;
5
+ switch (targetNodeTypeName) {
6
+ case 'bulletList':
7
+ targetListType = schema.nodes.bulletList;
8
+ targetItemType = schema.nodes.listItem;
9
+ break;
10
+ case 'orderedList':
11
+ targetListType = schema.nodes.orderedList;
12
+ targetItemType = schema.nodes.listItem;
13
+ break;
14
+ case 'taskList':
15
+ targetListType = schema.nodes.taskList;
16
+ targetItemType = schema.nodes.taskItem;
17
+ break;
18
+ default:
19
+ }
20
+ return {
21
+ targetListType,
22
+ targetItemType
23
+ };
24
+ };
25
+
26
+ /**
27
+ * Transforms a decisionList into a bulletList, orderedList, or taskList.
28
+ * Decision items are converted to the appropriate list item type.
29
+ *
30
+ * @example
31
+ * Input (decisionList):
32
+ * - decisionList
33
+ * - decisionItem "Task 1"
34
+ * - decisionItem "Task 2"
35
+ *
36
+ * Output (bulletList):
37
+ * - bulletList
38
+ * - listItem
39
+ * - paragraph "Task 1"
40
+ * - listItem
41
+ * - paragraph "Task 2"
42
+ *
43
+ * Output (taskList):
44
+ * - taskList
45
+ * - taskItem
46
+ * - paragraph "Task 1"
47
+ * - taskItem
48
+ * - paragraph "Task 2"
49
+ *
50
+ * @param nodes - Array of nodes to transform
51
+ * @param context - Transform context with schema and target node type
52
+ * @returns array of transformed nodes
53
+ */
54
+ export const decisionListToListStep = (nodes, context) => {
55
+ const {
56
+ schema,
57
+ targetNodeTypeName
58
+ } = context;
59
+ const paragraphType = schema.nodes.paragraph;
60
+ return nodes.map(node => {
61
+ if (node.type !== schema.nodes.decisionList) {
62
+ return node;
63
+ }
64
+ const {
65
+ targetListType,
66
+ targetItemType
67
+ } = targets(targetNodeTypeName, schema);
68
+ if (!targetListType || !targetItemType) {
69
+ return node;
70
+ }
71
+ const newItems = [];
72
+ node.forEach(decisionItem => {
73
+ const itemContent = [];
74
+ decisionItem.forEach(child => {
75
+ itemContent.push(child);
76
+ });
77
+ const newItem = targetItemType === schema.nodes.listItem ? targetItemType.create({}, paragraphType.create({}, itemContent)) : targetItemType.create({}, itemContent);
78
+ if (newItem) {
79
+ newItems.push(newItem);
80
+ }
81
+ });
82
+ const newList = targetListType.create({}, Fragment.from(newItems));
83
+ return newList || node;
84
+ });
85
+ };
@@ -0,0 +1,58 @@
1
+ import { Fragment } from '@atlaskit/editor-prosemirror/model';
2
+ import { isListType } from '../utils';
3
+
4
+ /**
5
+ * Transforms a bulletList, orderedList, or taskList into a decisionList.
6
+ *
7
+ * Notes
8
+ * - decisionLists and taskList only support text as children - need to ensure content is converted to text
9
+ *
10
+ * @example
11
+ * Input (nested bulletList):
12
+ * - bulletList
13
+ * - listItem "1.1"
14
+ * - listItem "1.2"
15
+ * - listItem "1.3"
16
+ *
17
+ * Output (flat decisionList):
18
+ * - decisionList
19
+ * - decisionItem "1"
20
+ * - decisionItem "1.1"
21
+ * - decisionItem "2"
22
+ *
23
+ * @param nodes - Array of nodes to transform
24
+ * @param context - Transform context with schema and target node type
25
+ * @returns array of transformed nodes
26
+ */
27
+ export const listToDecisionListStep = (nodes, context) => {
28
+ const {
29
+ schema
30
+ } = context;
31
+ const paragraphType = schema.nodes.paragraph;
32
+ return nodes.map(node => {
33
+ if (!isListType(node, schema)) {
34
+ return node;
35
+ }
36
+ const decisionItems = [];
37
+ node.forEach(item => {
38
+ const itemContent = [];
39
+ item.forEach(child => {
40
+ if (child.type === paragraphType) {
41
+ // paragraph may contain hard breaks etc.
42
+ child.content.forEach(inline => {
43
+ itemContent.push(inline);
44
+ });
45
+ } else {
46
+ itemContent.push(child);
47
+ }
48
+ // TODO: EDITOR-3887 - Skip mediaSingle, codeBlock, and nested lists
49
+ });
50
+ const decisionItem = schema.nodes.decisionItem.create({}, Fragment.from(itemContent));
51
+ if (decisionItem) {
52
+ decisionItems.push(decisionItem);
53
+ }
54
+ });
55
+ const decisionList = schema.nodes.decisionList.create({}, Fragment.from(decisionItems));
56
+ return decisionList || node;
57
+ });
58
+ };
@@ -1,8 +1,5 @@
1
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
- };
2
+ import { isListType } from '../utils';
6
3
 
7
4
  /**
8
5
  * Converts FROM taskList structure TO bulletList/orderedList structure.
@@ -1,29 +1,28 @@
1
1
  import { Fragment } from '@atlaskit/editor-prosemirror/model';
2
- import { NODE_CATEGORY_BY_TYPE } from './types';
3
- import { unwrapStep } from './unwrapStep';
2
+ import { NODE_CATEGORY_BY_TYPE } from '../types';
4
3
 
5
4
  /**
6
- * Determines if a node can be flattened (unwrapped and its contents merged).
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 canFlatten = node => {
8
+ const isTextNode = node => {
15
9
  const category = NODE_CATEGORY_BY_TYPE[node.type.name];
16
- // Text and list nodes can be flattened (converted to simpler forms)
17
- return category === 'text' || category === 'list';
10
+ return category === 'text';
18
11
  };
19
12
 
20
13
  /**
21
- * Flattens a node by extracting its contents using the appropriate unwrap step.
22
- * This is only called for text and list nodes that can be converted to simpler forms.
23
- * Uses unwrapStep to extract children from list containers.
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 flattenNode = (node, context) => {
26
- return unwrapStep([node], context);
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 (canFlatten(node)) {
122
- // Node cannot be wrapped but CAN be flattened - flatten and add to container
123
- const flattenedNodes = flattenNode(node, context);
124
- currentContainerContent.push(...flattenedNodes);
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
- // Node cannot be wrapped AND cannot be flattened (containers, tables, media, macros) - break out
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
  }