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