@atlaskit/editor-plugin-block-menu 6.0.6 → 6.0.8

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 (40) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/cjs/editor-commands/transform-node-utils/flattenStep.js +0 -10
  3. package/dist/cjs/editor-commands/transform-node-utils/steps/applyTargetTextTypeStep.js +22 -18
  4. package/dist/cjs/editor-commands/transform-node-utils/steps/decisionListToListStep.js +1 -5
  5. package/dist/cjs/editor-commands/transform-node-utils/steps/flattenListStep.js +1 -3
  6. package/dist/cjs/editor-commands/transform-node-utils/steps/listToDecisionListStep.js +1 -1
  7. package/dist/cjs/editor-commands/transform-node-utils/steps/listToListStep.js +1 -1
  8. package/dist/cjs/editor-commands/transform-node-utils/steps/wrapMixedContentStep.js +79 -45
  9. package/dist/cjs/editor-commands/transform-node-utils/transform.js +13 -15
  10. package/dist/cjs/editor-commands/transformNode.js +8 -2
  11. package/dist/es2019/editor-commands/transform-node-utils/flattenStep.js +0 -8
  12. package/dist/es2019/editor-commands/transform-node-utils/steps/applyTargetTextTypeStep.js +22 -18
  13. package/dist/es2019/editor-commands/transform-node-utils/steps/decisionListToListStep.js +1 -5
  14. package/dist/es2019/editor-commands/transform-node-utils/steps/flattenListStep.js +1 -3
  15. package/dist/es2019/editor-commands/transform-node-utils/steps/listToDecisionListStep.js +1 -1
  16. package/dist/es2019/editor-commands/transform-node-utils/steps/listToListStep.js +1 -1
  17. package/dist/es2019/editor-commands/transform-node-utils/steps/wrapMixedContentStep.js +79 -45
  18. package/dist/es2019/editor-commands/transform-node-utils/transform.js +13 -15
  19. package/dist/es2019/editor-commands/transformNode.js +8 -2
  20. package/dist/esm/editor-commands/transform-node-utils/flattenStep.js +0 -10
  21. package/dist/esm/editor-commands/transform-node-utils/steps/applyTargetTextTypeStep.js +22 -18
  22. package/dist/esm/editor-commands/transform-node-utils/steps/decisionListToListStep.js +1 -5
  23. package/dist/esm/editor-commands/transform-node-utils/steps/flattenListStep.js +1 -3
  24. package/dist/esm/editor-commands/transform-node-utils/steps/listToDecisionListStep.js +1 -1
  25. package/dist/esm/editor-commands/transform-node-utils/steps/listToListStep.js +1 -1
  26. package/dist/esm/editor-commands/transform-node-utils/steps/wrapMixedContentStep.js +80 -46
  27. package/dist/esm/editor-commands/transform-node-utils/transform.js +13 -15
  28. package/dist/esm/editor-commands/transformNode.js +8 -2
  29. package/dist/types/editor-commands/transform-node-utils/steps/applyTargetTextTypeStep.d.ts +10 -7
  30. package/dist/types/editor-commands/transform-node-utils/steps/flattenListStep.d.ts +0 -2
  31. package/dist/types/editor-commands/transform-node-utils/steps/wrapMixedContentStep.d.ts +3 -0
  32. package/dist/types-ts4.5/editor-commands/transform-node-utils/steps/applyTargetTextTypeStep.d.ts +10 -7
  33. package/dist/types-ts4.5/editor-commands/transform-node-utils/steps/flattenListStep.d.ts +0 -2
  34. package/dist/types-ts4.5/editor-commands/transform-node-utils/steps/wrapMixedContentStep.d.ts +3 -0
  35. package/package.json +2 -2
  36. package/dist/cjs/editor-commands/transform-node-utils/steps/wrapTextToCodeblock.js +0 -21
  37. package/dist/es2019/editor-commands/transform-node-utils/steps/wrapTextToCodeblock.js +0 -18
  38. package/dist/esm/editor-commands/transform-node-utils/steps/wrapTextToCodeblock.js +0 -16
  39. package/dist/types/editor-commands/transform-node-utils/steps/wrapTextToCodeblock.d.ts +0 -9
  40. package/dist/types-ts4.5/editor-commands/transform-node-utils/steps/wrapTextToCodeblock.d.ts +0 -9
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @atlaskit/editor-plugin-block-menu
2
2
 
3
+ ## 6.0.8
4
+
5
+ ### Patch Changes
6
+
7
+ - [`bdcaf574d7d2d`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/bdcaf574d7d2d) -
8
+ Fix transformation of multiple headings and paragraphs to codeblocks
9
+ - [`68ebba7ccdc1b`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/68ebba7ccdc1b) -
10
+ [EDITOR-4157] Fix editor freeze when transforming mediaSingle at bottom of document
11
+ - [`fef9134c6feb5`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/fef9134c6feb5) -
12
+ [ux] Implement multiselect transformations for text (heading, paragraph) nodes
13
+ - Updated dependencies
14
+
15
+ ## 6.0.7
16
+
17
+ ### Patch Changes
18
+
19
+ - [`65223704a60e0`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/65223704a60e0) -
20
+ Fix hard breaks being lost in nested task lists during transformation
21
+ - Updated dependencies
22
+
3
23
  ## 6.0.6
4
24
 
5
25
  ### Patch Changes
@@ -12,16 +12,6 @@ var flattenStep = exports.flattenStep = function flattenStep(nodes, context) {
12
12
  if (!targetNodeType || !paragraph) {
13
13
  return nodes;
14
14
  }
15
-
16
- // TODO: EDITOR-2920 - Implement flattening logic.
17
- var isTargetCodeBlock = targetNodeTypeName === 'codeBlock';
18
- if (isTargetCodeBlock) {
19
- // This strips explicitly text nodes
20
- var codeBlockContent = nodes.map(function (node) {
21
- return node.content.textBetween(0, node.content.size, '\n');
22
- }).join('\n');
23
- return [schema.nodes.codeBlock.create({}, schema.text(codeBlockContent))];
24
- }
25
15
  return nodes.map(function (node) {
26
16
  var isValidWithin = targetNodeType.validContent(node.content);
27
17
  if (!isValidWithin) {
@@ -5,18 +5,21 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.applyTargetTextTypeStep = void 0;
7
7
  /**
8
- * Applies target text type conversion. If the target type is a heading, converts textblock nodes
9
- * (paragraphs, headings) to heading nodes with the specified level. Otherwise, leaves nodes unchanged.
10
- * Non-textblock nodes are always left unchanged.
8
+ * Applies target text type conversion. Converts textblock nodes to the target text type
9
+ * (paragraph or heading). Non-textblock nodes are left unchanged.
11
10
  *
12
11
  * @example
13
12
  * Input:
14
- * - paragraph "Heading 1"
15
- * - paragraph "Heading 2"
13
+ * - paragraph "Text 1"
14
+ * - paragraph "Text 2"
16
15
  *
17
16
  * Output (with target: heading, level: 2):
18
- * - heading (level: 2) "Heading 1"
19
- * - heading (level: 2) "Heading 2"
17
+ * - heading (level: 2) "Text 1"
18
+ * - heading (level: 2) "Text 2"
19
+ *
20
+ * Output (with target: paragraph):
21
+ * - paragraph "Text 1"
22
+ * - paragraph "Text 2"
20
23
  *
21
24
  * @param nodes
22
25
  * @param context
@@ -26,23 +29,24 @@ var applyTargetTextTypeStep = exports.applyTargetTextTypeStep = function applyTa
26
29
  var schema = context.schema,
27
30
  targetNodeTypeName = context.targetNodeTypeName,
28
31
  targetAttrs = context.targetAttrs;
29
- if (targetNodeTypeName !== 'heading') {
32
+ if (targetNodeTypeName !== 'heading' && targetNodeTypeName !== 'paragraph') {
30
33
  return nodes;
31
34
  }
32
- var headingType = schema.nodes.heading;
33
- if (!headingType) {
35
+ var targetType = schema.nodes[targetNodeTypeName];
36
+ if (!targetType) {
34
37
  return nodes;
35
38
  }
36
-
37
- // Default to level 1 if no level is specified
38
- // The level should ideally come from targetAttrs, but if not available, use default
39
- var headingLevel = typeof (targetAttrs === null || targetAttrs === void 0 ? void 0 : targetAttrs.level) === 'number' ? targetAttrs.level : 1;
40
39
  return nodes.map(function (node) {
41
40
  if (node.isTextblock) {
42
- // Convert textblock nodes (paragraphs, headings) to heading with specified level
43
- return headingType.create({
44
- level: headingLevel
45
- }, node.content, node.marks);
41
+ // Convert textblock nodes to the target type with content preserved
42
+ var attrs = {};
43
+ if (targetNodeTypeName === 'heading') {
44
+ var level = typeof (targetAttrs === null || targetAttrs === void 0 ? void 0 : targetAttrs.level) === 'number' ? targetAttrs.level : 1;
45
+ attrs = {
46
+ level: level
47
+ };
48
+ }
49
+ return targetType.create(attrs, node.content, node.marks);
46
50
  }
47
51
  // Non-textblock nodes are left unchanged
48
52
  return node;
@@ -73,11 +73,7 @@ var decisionListToListStep = exports.decisionListToListStep = function decisionL
73
73
  }
74
74
  var newItems = [];
75
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);
76
+ var newItem = targetItemType.inlineContent ? targetItemType.create({}, decisionItem.children) : targetItemType.create({}, paragraphType.create({}, decisionItem.children));
81
77
  if (newItem) {
82
78
  newItems.push(newItem);
83
79
  }
@@ -24,7 +24,7 @@ var extractNestedLists = function extractNestedLists(node, schema) {
24
24
  child.forEach(function (grandChild) {
25
25
  if ((0, _nodeChecks.isListWithIndentation)(grandChild.type.name, schema)) {
26
26
  nestedLists.push(grandChild);
27
- } else if (grandChild.isText) {
27
+ } else if (grandChild.isInline) {
28
28
  // For taskItem/decisionItem, keep text as-is (they support inline content)
29
29
  // For listItem, wrap text in paragraph (they require block content)
30
30
  if (isInlineItem) {
@@ -75,8 +75,6 @@ var extractNestedLists = function extractNestedLists(node, schema) {
75
75
  * @param nodes
76
76
  * @param context
77
77
  * @returns
78
- *
79
- * TODO: Lists with mixed types (e.g. bulletList with a taskItem) doesn't full flatten
80
78
  */
81
79
  var flattenListStep = exports.flattenListStep = function flattenListStep(nodes, context) {
82
80
  return nodes.map(function (node) {
@@ -45,7 +45,7 @@ var listToDecisionListStep = exports.listToDecisionListStep = function listToDec
45
45
  if (child.type === paragraphType) {
46
46
  // paragraph may contain hard breaks etc.
47
47
  itemContent.push.apply(itemContent, (0, _toConsumableArray2.default)(child.children));
48
- } else if (child.isText || child.isInline) {
48
+ } else if (child.isInline) {
49
49
  itemContent.push(child);
50
50
  } else if (!(0, _nodeChecks.isListWithIndentation)(child.type.name, schema)) {
51
51
  unsupportedContent.push(child);
@@ -76,7 +76,7 @@ var _transformList = function transformList(node, targetListType, targetItemType
76
76
  itemNode.forEach(function (child) {
77
77
  if (child.type === paragraphType) {
78
78
  inlineContent.push.apply(inlineContent, (0, _toConsumableArray2.default)(child.children));
79
- } else if (child.isText) {
79
+ } else if (child.isInline) {
80
80
  inlineContent.push(child);
81
81
  // Nested lists will be extracted and placed as siblings in the taskList
82
82
  } else if (!(0, _nodeChecks.isListWithIndentation)(child.type.name, schema)) {
@@ -10,6 +10,34 @@ var _model = require("@atlaskit/editor-prosemirror/model");
10
10
  var _marks = require("../marks");
11
11
  var _types = require("../types");
12
12
  var _utils = require("../utils");
13
+ /**
14
+ * Creates a layout section with two columns, where the first column contains the provided content.
15
+ */
16
+ var createLayoutSection = function createLayoutSection(content, layoutSection, layoutColumn) {
17
+ var columnOne = layoutColumn.createAndFill({}, (0, _marks.removeDisallowedMarks)(content, layoutColumn));
18
+ var columnTwo = layoutColumn.createAndFill();
19
+ if (!columnOne || !columnTwo) {
20
+ return null;
21
+ }
22
+ return layoutSection.createAndFill({}, [columnOne, columnTwo]);
23
+ };
24
+
25
+ /**
26
+ * Creates a container with text content (for codeblocks).
27
+ */
28
+ var createTextContentContainer = function createTextContentContainer(textContentArray, targetNodeType, schema) {
29
+ var textContent = textContentArray.join('\n');
30
+ var textNode = textContent ? schema.text(textContent) : null;
31
+ return targetNodeType.createAndFill({}, textNode);
32
+ };
33
+
34
+ /**
35
+ * Creates a regular container with node content.
36
+ */
37
+ var createNodeContentContainer = function createNodeContentContainer(nodeContent, targetNodeType) {
38
+ return targetNodeType.createAndFill({}, nodeContent);
39
+ };
40
+
13
41
  /**
14
42
  * Handles the edge case where transforming from a container to another container results in
15
43
  * all content breaking out (no valid children for the target). In this case, creates an empty
@@ -34,12 +62,16 @@ var handleEmptyContainerEdgeCase = function handleEmptyContainerEdgeCase(result,
34
62
  // (meaning there were no valid children that could be wrapped)
35
63
  var allContentBrokeOut = !hasCreatedContainer && result.length > 0;
36
64
  var shouldCreateEmptyTarget = isFromContainer && isTargetContainer && allContentBrokeOut;
37
- if (shouldCreateEmptyTarget) {
38
- var emptyParagraph = schema.nodes.paragraph.create();
39
- var emptyContainer = targetNodeType.create({}, emptyParagraph);
40
- return [emptyContainer].concat((0, _toConsumableArray2.default)(result));
65
+ if (!shouldCreateEmptyTarget) {
66
+ return result;
67
+ }
68
+ if (targetNodeTypeName === schema.nodes.codeBlock.name) {
69
+ var emptyCodeBlock = createTextContentContainer([], schema.nodes.codeBlock, schema);
70
+ return emptyCodeBlock ? [emptyCodeBlock].concat((0, _toConsumableArray2.default)(result)) : result;
41
71
  }
42
- return result;
72
+ var emptyParagraph = schema.nodes.paragraph.create();
73
+ var emptyContainer = targetNodeType.create({}, emptyParagraph);
74
+ return [emptyContainer].concat((0, _toConsumableArray2.default)(result));
43
75
  };
44
76
 
45
77
  /**
@@ -57,6 +89,9 @@ var handleEmptyContainerEdgeCase = function handleEmptyContainerEdgeCase(result,
57
89
  * - Layouts always require layoutColumns as children (never paragraphs directly)
58
90
  * - Layout columns can contain most block content including headings, paragraphs, lists, etc.
59
91
  *
92
+ * Special handling for codeblocks:
93
+ * - Text nodes are converted to plain text and added to the codeblock
94
+ *
60
95
  * Edge case handling:
61
96
  * - For regular containers: If all content breaks out (container → container transform with no
62
97
  * valid children), an empty container with a paragraph is created to ensure the target type exists
@@ -85,6 +120,7 @@ var wrapMixedContentStep = exports.wrapMixedContentStep = function wrapMixedCont
85
120
  return nodes;
86
121
  }
87
122
  var isLayout = targetNodeTypeName === 'layoutSection';
123
+ var isCodeblock = targetNodeTypeName === 'codeBlock';
88
124
  var _schema$nodes = schema.nodes,
89
125
  layoutSection = _schema$nodes.layoutSection,
90
126
  layoutColumn = _schema$nodes.layoutColumn;
@@ -95,64 +131,62 @@ var wrapMixedContentStep = exports.wrapMixedContentStep = function wrapMixedCont
95
131
  if (currentContainerContent.length === 0) {
96
132
  return;
97
133
  }
134
+ var container = null;
98
135
  if (isLayout) {
99
- // For layouts, create layoutSection with two layoutColumns
100
- var columnOne = layoutColumn.createAndFill({}, (0, _marks.removeDisallowedMarks)(currentContainerContent, layoutColumn));
101
- var columnTwo = layoutColumn.createAndFill();
102
- if (!columnOne || !columnTwo) {
103
- currentContainerContent = [];
104
- return;
105
- }
106
- var layout = layoutSection.createAndFill({}, [columnOne, columnTwo]);
107
- if (layout) {
108
- result.push(layout);
109
- hasCreatedContainer = true;
110
- }
111
- currentContainerContent = [];
112
- return;
136
+ container = createLayoutSection(currentContainerContent, layoutSection, layoutColumn);
137
+ } else if (isCodeblock) {
138
+ container = createTextContentContainer(currentContainerContent, targetNodeType, schema);
139
+ } else {
140
+ container = createNodeContentContainer(currentContainerContent, targetNodeType);
113
141
  }
114
-
115
- // For regular containers, create directly
116
- var containerNode = targetNodeType.createAndFill({}, currentContainerContent);
117
- if (containerNode) {
118
- result.push(containerNode);
142
+ if (container) {
143
+ result.push(container);
119
144
  hasCreatedContainer = true;
120
145
  }
121
146
  currentContainerContent = [];
122
147
  };
123
- var processNode = function processNode(node) {
148
+ var canNodeBeWrapped = function canNodeBeWrapped(node) {
124
149
  var validationType = isLayout ? layoutColumn : targetNodeType;
125
- var canWrapNode = validationType.validContent(_model.Fragment.from((0, _marks.removeDisallowedMarks)([node], validationType)));
126
-
127
- // Node can be wrapped - add to current container content
128
- if (canWrapNode) {
129
- var _currentContainerCont;
130
- // remove marks from node as nested nodes don't usually support block marks
131
- (_currentContainerCont = currentContainerContent).push.apply(_currentContainerCont, (0, _toConsumableArray2.default)((0, _marks.removeDisallowedMarks)([node], validationType)));
150
+ return validationType.validContent(_model.Fragment.from((0, _marks.removeDisallowedMarks)([node], validationType)));
151
+ };
152
+ var handleWrappableNode = function handleWrappableNode(node) {
153
+ var _currentContainerCont;
154
+ var validationType = isLayout ? layoutColumn : targetNodeType;
155
+ (_currentContainerCont = currentContainerContent).push.apply(_currentContainerCont, (0, _toConsumableArray2.default)((0, _marks.removeDisallowedMarks)([node], validationType)));
156
+ };
157
+ var handleCodeblockTextNode = function handleCodeblockTextNode(node) {
158
+ currentContainerContent.push((0, _utils.createTextContent)(node));
159
+ };
160
+ var handleConvertibleTextNode = function handleConvertibleTextNode(node) {
161
+ var paragraph = (0, _utils.convertTextNodeToParagraph)(node, schema);
162
+ if (paragraph) {
163
+ currentContainerContent.push(paragraph);
164
+ }
165
+ };
166
+ var handleUnsupportedNode = function handleUnsupportedNode(node) {
167
+ flushCurrentContainer();
168
+ result.push(node);
169
+ };
170
+ var processNode = function processNode(node) {
171
+ if (canNodeBeWrapped(node)) {
172
+ handleWrappableNode(node);
173
+ return;
174
+ }
175
+ if ((0, _utils.isTextNode)(node) && isCodeblock) {
176
+ handleCodeblockTextNode(node);
132
177
  return;
133
178
  }
134
-
135
- // Text node (heading, paragraph) that can't be wrapped - convert to paragraph
136
- // Example: heading can't go in blockquote, so convert to paragraph with same content
137
179
  if ((0, _utils.isTextNode)(node)) {
138
- var paragraph = (0, _utils.convertTextNodeToParagraph)(node, schema);
139
- if (paragraph) {
140
- currentContainerContent.push(paragraph);
141
- }
180
+ handleConvertibleTextNode(node);
142
181
  return;
143
182
  }
144
183
 
145
184
  // All other nodes that cannot be wrapped in the target node - break out
146
185
  // Examples: same-type containers, tables in panels, layoutSections in layouts
147
- flushCurrentContainer();
148
- result.push(node);
186
+ handleUnsupportedNode(node);
149
187
  };
150
188
  nodes.forEach(processNode);
151
-
152
- // Flush any remaining content into a container
153
189
  flushCurrentContainer();
154
-
155
- // Skip edge case handling for layouts since layouts always have columns
156
190
  if (isLayout) {
157
191
  return result.length > 0 ? result : nodes;
158
192
  }
@@ -17,7 +17,6 @@ var _unwrapLayoutStep = require("./steps/unwrapLayoutStep");
17
17
  var _unwrapListStep = require("./steps/unwrapListStep");
18
18
  var _wrapBlockquoteToDecisionListStep = require("./steps/wrapBlockquoteToDecisionListStep");
19
19
  var _wrapMixedContentStep = require("./steps/wrapMixedContentStep");
20
- var _wrapTextToCodeblock = require("./steps/wrapTextToCodeblock");
21
20
  var _types = require("./types");
22
21
  var _unwrapExpandStep = require("./unwrapExpandStep");
23
22
  var _unwrapStep = require("./unwrapStep");
@@ -36,7 +35,7 @@ var TRANSFORM_STEPS = {
36
35
  atomic: undefined,
37
36
  container: [_unwrapStep.unwrapStep, _wrapStep.wrapStep],
38
37
  list: undefined,
39
- text: [_unwrapStep.unwrapStep, _applyTargetTextTypeStep.applyTargetTextTypeStep],
38
+ text: [_unwrapStep.unwrapStep],
40
39
  multi: undefined
41
40
  },
42
41
  list: {
@@ -67,18 +66,13 @@ var TRANSFORM_STEPS = {
67
66
  // Use 'null' to indicate unavailable transfrorm for a case where TRANSFORM_STEPS are not undefined.
68
67
  var TRANSFORM_STEPS_OVERRIDE = {
69
68
  paragraph: {
70
- paragraph: null,
71
- codeBlock: [_wrapTextToCodeblock.wrapTextToCodeblockStep],
72
- layoutSection: [_wrapMixedContentStep.wrapMixedContentStep]
73
- },
74
- heading: {
75
- codeBlock: [_wrapTextToCodeblock.wrapTextToCodeblockStep],
76
- layoutSection: [_wrapMixedContentStep.wrapMixedContentStep]
69
+ paragraph: null
77
70
  },
71
+ heading: {},
78
72
  panel: {
79
73
  panel: null,
80
74
  layoutSection: [_unwrapStep.unwrapStep, _wrapMixedContentStep.wrapMixedContentStep],
81
- codeBlock: [_unwrapStep.unwrapStep, _flattenStep.flattenStep, _wrapStep.wrapStep],
75
+ codeBlock: [_unwrapStep.unwrapStep, _wrapMixedContentStep.wrapMixedContentStep],
82
76
  blockquote: [_unwrapStep.unwrapStep, _wrapMixedContentStep.wrapMixedContentStep],
83
77
  taskList: null,
84
78
  bulletList: null,
@@ -109,7 +103,9 @@ var TRANSFORM_STEPS_OVERRIDE = {
109
103
  nestedExpand: [_wrapStep.wrapStep],
110
104
  layoutSection: [_wrapMixedContentStep.wrapMixedContentStep],
111
105
  codeBlock: null,
112
- decisionList: [_unwrapStep.unwrapStep, _wrapBlockquoteToDecisionListStep.wrapBlockquoteToDecisionListStep]
106
+ decisionList: [_unwrapStep.unwrapStep, _wrapBlockquoteToDecisionListStep.wrapBlockquoteToDecisionListStep],
107
+ paragraph: [_unwrapStep.unwrapStep],
108
+ heading: [_unwrapStep.unwrapStep, _applyTargetTextTypeStep.applyTargetTextTypeStep]
113
109
  },
114
110
  layoutSection: {
115
111
  layoutSection: null,
@@ -127,6 +123,7 @@ var TRANSFORM_STEPS_OVERRIDE = {
127
123
  nestedExpand: [_wrapStep.wrapStep],
128
124
  layoutSection: [_wrapMixedContentStep.wrapMixedContentStep],
129
125
  panel: [_wrapStep.wrapStep],
126
+ paragraph: [_applyTargetTextTypeStep.applyTargetTextTypeStep],
130
127
  heading: null
131
128
  },
132
129
  bulletList: {
@@ -221,10 +218,11 @@ var TRANSFORM_STEPS_OVERRIDE = {
221
218
  decisionList: null
222
219
  },
223
220
  multi: {
224
- // TODO: EDITOR-4140 - Implement multiple paragraphs/headings/codeblocks to heading transform
225
- heading: null,
226
- // TODO: EDITOR-4141 - Implement multiple codeblocks/headings to paragraph transform
227
- paragraph: null
221
+ heading: [_applyTargetTextTypeStep.applyTargetTextTypeStep]
222
+ // Similar to heading, all structures are kept as is
223
+ // EG: transformed: other lists, paragarph, headings
224
+ // eg: not-transformed: quotes, codeblocks ... all typeof 'containers'
225
+ // decisionList: [],
228
226
  }
229
227
  };
230
228
  var getTransformStepsForNodeTypes = function getTransformStepsForNodeTypes(selectedNodeTypeName, targetNodeTypeName) {
@@ -51,8 +51,14 @@ var transformNode = exports.transformNode = function transformNode(api) {
51
51
  });
52
52
  var content = resultNodes.length > 0 ? resultNodes : slice.content;
53
53
  if (preservedSelection instanceof _state.NodeSelection && preservedSelection.node.type === nodes.mediaSingle) {
54
- tr.deleteRange($from.pos, $to.pos);
55
- tr.insert($from.pos, content);
54
+ // when node is media single, use tr.replaceWith freeze editor, if modify position, tr.replaceWith creates duplicats
55
+ var deleteFrom = $from.pos;
56
+ var deleteTo = $to.pos;
57
+ tr.delete(deleteFrom, deleteTo);
58
+ // After deletion, recalculate the insertion position to ensure it's valid
59
+ // especially when mediaSingle with caption is at the bottom of the document
60
+ var insertPos = Math.min(deleteFrom, tr.doc.content.size);
61
+ tr.insert(insertPos, content);
56
62
  } else {
57
63
  tr.replaceWith(sliceStart, $to.pos, content);
58
64
  }
@@ -10,14 +10,6 @@ export const flattenStep = (nodes, context) => {
10
10
  if (!targetNodeType || !paragraph) {
11
11
  return nodes;
12
12
  }
13
-
14
- // TODO: EDITOR-2920 - Implement flattening logic.
15
- const isTargetCodeBlock = targetNodeTypeName === 'codeBlock';
16
- if (isTargetCodeBlock) {
17
- // This strips explicitly text nodes
18
- const codeBlockContent = nodes.map(node => node.content.textBetween(0, node.content.size, '\n')).join('\n');
19
- return [schema.nodes.codeBlock.create({}, schema.text(codeBlockContent))];
20
- }
21
13
  return nodes.map(node => {
22
14
  const isValidWithin = targetNodeType.validContent(node.content);
23
15
  if (!isValidWithin) {
@@ -1,16 +1,19 @@
1
1
  /**
2
- * Applies target text type conversion. If the target type is a heading, converts textblock nodes
3
- * (paragraphs, headings) to heading nodes with the specified level. Otherwise, leaves nodes unchanged.
4
- * Non-textblock nodes are always left unchanged.
2
+ * Applies target text type conversion. Converts textblock nodes to the target text type
3
+ * (paragraph or heading). Non-textblock nodes are left unchanged.
5
4
  *
6
5
  * @example
7
6
  * Input:
8
- * - paragraph "Heading 1"
9
- * - paragraph "Heading 2"
7
+ * - paragraph "Text 1"
8
+ * - paragraph "Text 2"
10
9
  *
11
10
  * Output (with target: heading, level: 2):
12
- * - heading (level: 2) "Heading 1"
13
- * - heading (level: 2) "Heading 2"
11
+ * - heading (level: 2) "Text 1"
12
+ * - heading (level: 2) "Text 2"
13
+ *
14
+ * Output (with target: paragraph):
15
+ * - paragraph "Text 1"
16
+ * - paragraph "Text 2"
14
17
  *
15
18
  * @param nodes
16
19
  * @param context
@@ -22,23 +25,24 @@ export const applyTargetTextTypeStep = (nodes, context) => {
22
25
  targetNodeTypeName,
23
26
  targetAttrs
24
27
  } = context;
25
- if (targetNodeTypeName !== 'heading') {
28
+ if (targetNodeTypeName !== 'heading' && targetNodeTypeName !== 'paragraph') {
26
29
  return nodes;
27
30
  }
28
- const headingType = schema.nodes.heading;
29
- if (!headingType) {
31
+ const targetType = schema.nodes[targetNodeTypeName];
32
+ if (!targetType) {
30
33
  return nodes;
31
34
  }
32
-
33
- // Default to level 1 if no level is specified
34
- // The level should ideally come from targetAttrs, but if not available, use default
35
- const headingLevel = typeof (targetAttrs === null || targetAttrs === void 0 ? void 0 : targetAttrs.level) === 'number' ? targetAttrs.level : 1;
36
35
  return nodes.map(node => {
37
36
  if (node.isTextblock) {
38
- // Convert textblock nodes (paragraphs, headings) to heading with specified level
39
- return headingType.create({
40
- level: headingLevel
41
- }, node.content, node.marks);
37
+ // Convert textblock nodes to the target type with content preserved
38
+ let attrs = {};
39
+ if (targetNodeTypeName === 'heading') {
40
+ const level = typeof (targetAttrs === null || targetAttrs === void 0 ? void 0 : targetAttrs.level) === 'number' ? targetAttrs.level : 1;
41
+ attrs = {
42
+ level
43
+ };
44
+ }
45
+ return targetType.create(attrs, node.content, node.marks);
42
46
  }
43
47
  // Non-textblock nodes are left unchanged
44
48
  return node;
@@ -70,11 +70,7 @@ export const decisionListToListStep = (nodes, context) => {
70
70
  }
71
71
  const newItems = [];
72
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);
73
+ const newItem = targetItemType.inlineContent ? targetItemType.create({}, decisionItem.children) : targetItemType.create({}, paragraphType.create({}, decisionItem.children));
78
74
  if (newItem) {
79
75
  newItems.push(newItem);
80
76
  }
@@ -16,7 +16,7 @@ const extractNestedLists = (node, schema) => {
16
16
  child.forEach(grandChild => {
17
17
  if (isListWithIndentation(grandChild.type.name, schema)) {
18
18
  nestedLists.push(grandChild);
19
- } else if (grandChild.isText) {
19
+ } else if (grandChild.isInline) {
20
20
  // For taskItem/decisionItem, keep text as-is (they support inline content)
21
21
  // For listItem, wrap text in paragraph (they require block content)
22
22
  if (isInlineItem) {
@@ -67,8 +67,6 @@ const extractNestedLists = (node, schema) => {
67
67
  * @param nodes
68
68
  * @param context
69
69
  * @returns
70
- *
71
- * TODO: Lists with mixed types (e.g. bulletList with a taskItem) doesn't full flatten
72
70
  */
73
71
  export const flattenListStep = (nodes, context) => {
74
72
  return nodes.map(node => {
@@ -39,7 +39,7 @@ export const listToDecisionListStep = (nodes, context) => {
39
39
  if (child.type === paragraphType) {
40
40
  // paragraph may contain hard breaks etc.
41
41
  itemContent.push(...child.children);
42
- } else if (child.isText || child.isInline) {
42
+ } else if (child.isInline) {
43
43
  itemContent.push(child);
44
44
  } else if (!isListWithIndentation(child.type.name, schema)) {
45
45
  unsupportedContent.push(child);
@@ -67,7 +67,7 @@ const transformList = (node, targetListType, targetItemType, unsupportedContent)
67
67
  itemNode.forEach(child => {
68
68
  if (child.type === paragraphType) {
69
69
  inlineContent.push(...child.children);
70
- } else if (child.isText) {
70
+ } else if (child.isInline) {
71
71
  inlineContent.push(child);
72
72
  // Nested lists will be extracted and placed as siblings in the taskList
73
73
  } else if (!isListWithIndentation(child.type.name, schema)) {