@atlaskit/editor-plugin-block-menu 6.0.7 → 6.0.9

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 (26) hide show
  1. package/CHANGELOG.md +19 -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 +26 -18
  4. package/dist/cjs/editor-commands/transform-node-utils/steps/wrapMixedContentStep.js +79 -45
  5. package/dist/cjs/editor-commands/transform-node-utils/transform.js +16 -16
  6. package/dist/cjs/editor-commands/transformNode.js +8 -2
  7. package/dist/es2019/editor-commands/transform-node-utils/flattenStep.js +0 -8
  8. package/dist/es2019/editor-commands/transform-node-utils/steps/applyTargetTextTypeStep.js +26 -18
  9. package/dist/es2019/editor-commands/transform-node-utils/steps/wrapMixedContentStep.js +79 -45
  10. package/dist/es2019/editor-commands/transform-node-utils/transform.js +16 -16
  11. package/dist/es2019/editor-commands/transformNode.js +8 -2
  12. package/dist/esm/editor-commands/transform-node-utils/flattenStep.js +0 -10
  13. package/dist/esm/editor-commands/transform-node-utils/steps/applyTargetTextTypeStep.js +26 -18
  14. package/dist/esm/editor-commands/transform-node-utils/steps/wrapMixedContentStep.js +80 -46
  15. package/dist/esm/editor-commands/transform-node-utils/transform.js +16 -16
  16. package/dist/esm/editor-commands/transformNode.js +8 -2
  17. package/dist/types/editor-commands/transform-node-utils/steps/applyTargetTextTypeStep.d.ts +10 -7
  18. package/dist/types/editor-commands/transform-node-utils/steps/wrapMixedContentStep.d.ts +3 -0
  19. package/dist/types-ts4.5/editor-commands/transform-node-utils/steps/applyTargetTextTypeStep.d.ts +10 -7
  20. package/dist/types-ts4.5/editor-commands/transform-node-utils/steps/wrapMixedContentStep.d.ts +3 -0
  21. package/package.json +3 -3
  22. package/dist/cjs/editor-commands/transform-node-utils/steps/wrapTextToCodeblock.js +0 -21
  23. package/dist/es2019/editor-commands/transform-node-utils/steps/wrapTextToCodeblock.js +0 -18
  24. package/dist/esm/editor-commands/transform-node-utils/steps/wrapTextToCodeblock.js +0 -16
  25. package/dist/types/editor-commands/transform-node-utils/steps/wrapTextToCodeblock.d.ts +0 -9
  26. package/dist/types-ts4.5/editor-commands/transform-node-utils/steps/wrapTextToCodeblock.d.ts +0 -9
@@ -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: {
@@ -175,7 +172,9 @@ const TRANSFORM_STEPS_OVERRIDE = {
175
172
  bulletList: [decisionListToListStep],
176
173
  orderedList: [decisionListToListStep],
177
174
  taskList: [decisionListToListStep],
178
- layoutSection: [wrapMixedContentStep]
175
+ layoutSection: [wrapMixedContentStep],
176
+ blockquote: [unwrapListStep, wrapStep],
177
+ codeBlock: [unwrapListStep, wrapMixedContentStep]
179
178
  },
180
179
  blockCard: {
181
180
  layoutSection: [wrapMixedContentStep],
@@ -216,10 +215,11 @@ const TRANSFORM_STEPS_OVERRIDE = {
216
215
  decisionList: null
217
216
  },
218
217
  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
218
+ heading: [applyTargetTextTypeStep]
219
+ // Similar to heading, all structures are kept as is
220
+ // EG: transformed: other lists, paragarph, headings
221
+ // eg: not-transformed: quotes, codeblocks ... all typeof 'containers'
222
+ // decisionList: [],
223
223
  }
224
224
  };
225
225
  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,28 @@ 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) {
34
+ // If codeblock, return nodes as is
35
+ if (targetNodeTypeName === 'heading' && node.type.name === 'codeBlock') {
36
+ return node;
37
+ }
35
38
  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);
39
+ // Convert textblock nodes to the target type with content preserved
40
+ var attrs = {};
41
+ if (targetNodeTypeName === 'heading') {
42
+ var level = typeof (targetAttrs === null || targetAttrs === void 0 ? void 0 : targetAttrs.level) === 'number' ? targetAttrs.level : 1;
43
+ attrs = {
44
+ level: level
45
+ };
46
+ }
47
+ return targetType.create(attrs, node.content, node.marks);
40
48
  }
41
49
  // Non-textblock nodes are left unchanged
42
50
  return node;
@@ -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: {
@@ -175,7 +172,9 @@ var TRANSFORM_STEPS_OVERRIDE = {
175
172
  bulletList: [decisionListToListStep],
176
173
  orderedList: [decisionListToListStep],
177
174
  taskList: [decisionListToListStep],
178
- layoutSection: [wrapMixedContentStep]
175
+ layoutSection: [wrapMixedContentStep],
176
+ blockquote: [unwrapListStep, wrapStep],
177
+ codeBlock: [unwrapListStep, wrapMixedContentStep]
179
178
  },
180
179
  blockCard: {
181
180
  layoutSection: [wrapMixedContentStep],
@@ -216,10 +215,11 @@ var TRANSFORM_STEPS_OVERRIDE = {
216
215
  decisionList: null
217
216
  },
218
217
  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
218
+ heading: [applyTargetTextTypeStep]
219
+ // Similar to heading, all structures are kept as is
220
+ // EG: transformed: other lists, paragarph, headings
221
+ // eg: not-transformed: quotes, codeblocks ... all typeof 'containers'
222
+ // decisionList: [],
223
223
  }
224
224
  };
225
225
  var getTransformStepsForNodeTypes = function getTransformStepsForNodeTypes(selectedNodeTypeName, targetNodeTypeName) {
@@ -44,8 +44,14 @@ export var transformNode = function transformNode(api) {
44
44
  });
45
45
  var content = resultNodes.length > 0 ? resultNodes : slice.content;
46
46
  if (preservedSelection instanceof NodeSelection && preservedSelection.node.type === nodes.mediaSingle) {
47
- tr.deleteRange($from.pos, $to.pos);
48
- tr.insert($from.pos, content);
47
+ // when node is media single, use tr.replaceWith freeze editor, if modify position, tr.replaceWith creates duplicats
48
+ var deleteFrom = $from.pos;
49
+ var deleteTo = $to.pos;
50
+ tr.delete(deleteFrom, deleteTo);
51
+ // After deletion, recalculate the insertion position to ensure it's valid
52
+ // especially when mediaSingle with caption is at the bottom of the document
53
+ var insertPos = Math.min(deleteFrom, tr.doc.content.size);
54
+ tr.insert(insertPos, content);
49
55
  } else {
50
56
  tr.replaceWith(sliceStart, $to.pos, content);
51
57
  }
@@ -1,17 +1,20 @@
1
1
  import type { TransformStep } from '../types';
2
2
  /**
3
- * Applies target text type conversion. If the target type is a heading, converts textblock nodes
4
- * (paragraphs, headings) to heading nodes with the specified level. Otherwise, leaves nodes unchanged.
5
- * Non-textblock nodes are always left unchanged.
3
+ * Applies target text type conversion. Converts textblock nodes to the target text type
4
+ * (paragraph or heading). Non-textblock nodes are left unchanged.
6
5
  *
7
6
  * @example
8
7
  * Input:
9
- * - paragraph "Heading 1"
10
- * - paragraph "Heading 2"
8
+ * - paragraph "Text 1"
9
+ * - paragraph "Text 2"
11
10
  *
12
11
  * Output (with target: heading, level: 2):
13
- * - heading (level: 2) "Heading 1"
14
- * - heading (level: 2) "Heading 2"
12
+ * - heading (level: 2) "Text 1"
13
+ * - heading (level: 2) "Text 2"
14
+ *
15
+ * Output (with target: paragraph):
16
+ * - paragraph "Text 1"
17
+ * - paragraph "Text 2"
15
18
  *
16
19
  * @param nodes
17
20
  * @param context
@@ -14,6 +14,9 @@ import type { TransformStep } from '../types';
14
14
  * - Layouts always require layoutColumns as children (never paragraphs directly)
15
15
  * - Layout columns can contain most block content including headings, paragraphs, lists, etc.
16
16
  *
17
+ * Special handling for codeblocks:
18
+ * - Text nodes are converted to plain text and added to the codeblock
19
+ *
17
20
  * Edge case handling:
18
21
  * - For regular containers: If all content breaks out (container → container transform with no
19
22
  * valid children), an empty container with a paragraph is created to ensure the target type exists
@@ -1,17 +1,20 @@
1
1
  import type { TransformStep } from '../types';
2
2
  /**
3
- * Applies target text type conversion. If the target type is a heading, converts textblock nodes
4
- * (paragraphs, headings) to heading nodes with the specified level. Otherwise, leaves nodes unchanged.
5
- * Non-textblock nodes are always left unchanged.
3
+ * Applies target text type conversion. Converts textblock nodes to the target text type
4
+ * (paragraph or heading). Non-textblock nodes are left unchanged.
6
5
  *
7
6
  * @example
8
7
  * Input:
9
- * - paragraph "Heading 1"
10
- * - paragraph "Heading 2"
8
+ * - paragraph "Text 1"
9
+ * - paragraph "Text 2"
11
10
  *
12
11
  * Output (with target: heading, level: 2):
13
- * - heading (level: 2) "Heading 1"
14
- * - heading (level: 2) "Heading 2"
12
+ * - heading (level: 2) "Text 1"
13
+ * - heading (level: 2) "Text 2"
14
+ *
15
+ * Output (with target: paragraph):
16
+ * - paragraph "Text 1"
17
+ * - paragraph "Text 2"
15
18
  *
16
19
  * @param nodes
17
20
  * @param context
@@ -14,6 +14,9 @@ import type { TransformStep } from '../types';
14
14
  * - Layouts always require layoutColumns as children (never paragraphs directly)
15
15
  * - Layout columns can contain most block content including headings, paragraphs, lists, etc.
16
16
  *
17
+ * Special handling for codeblocks:
18
+ * - Text nodes are converted to plain text and added to the codeblock
19
+ *
17
20
  * Edge case handling:
18
21
  * - For regular containers: If all content breaks out (container → container transform with no
19
22
  * valid children), an empty container with a paragraph is created to ensure the target type exists
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-menu",
3
- "version": "6.0.7",
3
+ "version": "6.0.9",
4
4
  "description": "BlockMenu plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -44,8 +44,8 @@
44
44
  "@atlaskit/platform-feature-flags": "^1.1.0",
45
45
  "@atlaskit/platform-feature-flags-react": "^0.4.0",
46
46
  "@atlaskit/primitives": "^17.0.0",
47
- "@atlaskit/tmp-editor-statsig": "^16.4.0",
48
- "@atlaskit/tokens": "^9.0.0",
47
+ "@atlaskit/tmp-editor-statsig": "^16.5.0",
48
+ "@atlaskit/tokens": "^9.1.0",
49
49
  "@babel/runtime": "^7.0.0"
50
50
  },
51
51
  "peerDependencies": {
@@ -1,21 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.wrapTextToCodeblockStep = void 0;
7
- var _utils = require("../utils");
8
- /**
9
- * Transforms a paragraph (or heading) into a codeBlock by extracting its text content.
10
- * This step handles the conversion of inline content (including marks) to plain text,
11
- * which is required because codeBlocks can only contain plain text nodes.
12
- *
13
- * Example: paragraph with bold/italic/status → codeBlock with plain text
14
- */
15
- var wrapTextToCodeblockStep = exports.wrapTextToCodeblockStep = function wrapTextToCodeblockStep(nodes, context) {
16
- var schema = context.schema;
17
- return nodes.map(function (node) {
18
- var codeBlockNode = schema.nodes.codeBlock.createAndFill({}, schema.text((0, _utils.createTextContent)(node)));
19
- return codeBlockNode !== null && codeBlockNode !== void 0 ? codeBlockNode : node;
20
- });
21
- };
@@ -1,18 +0,0 @@
1
- import { createTextContent } from '../utils';
2
-
3
- /**
4
- * Transforms a paragraph (or heading) into a codeBlock by extracting its text content.
5
- * This step handles the conversion of inline content (including marks) to plain text,
6
- * which is required because codeBlocks can only contain plain text nodes.
7
- *
8
- * Example: paragraph with bold/italic/status → codeBlock with plain text
9
- */
10
- export const wrapTextToCodeblockStep = (nodes, context) => {
11
- const {
12
- schema
13
- } = context;
14
- return nodes.map(node => {
15
- const codeBlockNode = schema.nodes.codeBlock.createAndFill({}, schema.text(createTextContent(node)));
16
- return codeBlockNode !== null && codeBlockNode !== void 0 ? codeBlockNode : node;
17
- });
18
- };
@@ -1,16 +0,0 @@
1
- import { createTextContent } from '../utils';
2
-
3
- /**
4
- * Transforms a paragraph (or heading) into a codeBlock by extracting its text content.
5
- * This step handles the conversion of inline content (including marks) to plain text,
6
- * which is required because codeBlocks can only contain plain text nodes.
7
- *
8
- * Example: paragraph with bold/italic/status → codeBlock with plain text
9
- */
10
- export var wrapTextToCodeblockStep = function wrapTextToCodeblockStep(nodes, context) {
11
- var schema = context.schema;
12
- return nodes.map(function (node) {
13
- var codeBlockNode = schema.nodes.codeBlock.createAndFill({}, schema.text(createTextContent(node)));
14
- return codeBlockNode !== null && codeBlockNode !== void 0 ? codeBlockNode : node;
15
- });
16
- };
@@ -1,9 +0,0 @@
1
- import type { TransformStep } from '../types';
2
- /**
3
- * Transforms a paragraph (or heading) into a codeBlock by extracting its text content.
4
- * This step handles the conversion of inline content (including marks) to plain text,
5
- * which is required because codeBlocks can only contain plain text nodes.
6
- *
7
- * Example: paragraph with bold/italic/status → codeBlock with plain text
8
- */
9
- export declare const wrapTextToCodeblockStep: TransformStep;
@@ -1,9 +0,0 @@
1
- import type { TransformStep } from '../types';
2
- /**
3
- * Transforms a paragraph (or heading) into a codeBlock by extracting its text content.
4
- * This step handles the conversion of inline content (including marks) to plain text,
5
- * which is required because codeBlocks can only contain plain text nodes.
6
- *
7
- * Example: paragraph with bold/italic/status → codeBlock with plain text
8
- */
9
- export declare const wrapTextToCodeblockStep: TransformStep;