@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.
- package/CHANGELOG.md +20 -0
- package/dist/cjs/editor-commands/transform-node-utils/flattenStep.js +0 -10
- package/dist/cjs/editor-commands/transform-node-utils/steps/applyTargetTextTypeStep.js +22 -18
- package/dist/cjs/editor-commands/transform-node-utils/steps/decisionListToListStep.js +1 -5
- package/dist/cjs/editor-commands/transform-node-utils/steps/flattenListStep.js +1 -3
- package/dist/cjs/editor-commands/transform-node-utils/steps/listToDecisionListStep.js +1 -1
- package/dist/cjs/editor-commands/transform-node-utils/steps/listToListStep.js +1 -1
- package/dist/cjs/editor-commands/transform-node-utils/steps/wrapMixedContentStep.js +79 -45
- package/dist/cjs/editor-commands/transform-node-utils/transform.js +13 -15
- package/dist/cjs/editor-commands/transformNode.js +8 -2
- package/dist/es2019/editor-commands/transform-node-utils/flattenStep.js +0 -8
- package/dist/es2019/editor-commands/transform-node-utils/steps/applyTargetTextTypeStep.js +22 -18
- package/dist/es2019/editor-commands/transform-node-utils/steps/decisionListToListStep.js +1 -5
- package/dist/es2019/editor-commands/transform-node-utils/steps/flattenListStep.js +1 -3
- package/dist/es2019/editor-commands/transform-node-utils/steps/listToDecisionListStep.js +1 -1
- package/dist/es2019/editor-commands/transform-node-utils/steps/listToListStep.js +1 -1
- package/dist/es2019/editor-commands/transform-node-utils/steps/wrapMixedContentStep.js +79 -45
- package/dist/es2019/editor-commands/transform-node-utils/transform.js +13 -15
- package/dist/es2019/editor-commands/transformNode.js +8 -2
- package/dist/esm/editor-commands/transform-node-utils/flattenStep.js +0 -10
- package/dist/esm/editor-commands/transform-node-utils/steps/applyTargetTextTypeStep.js +22 -18
- package/dist/esm/editor-commands/transform-node-utils/steps/decisionListToListStep.js +1 -5
- package/dist/esm/editor-commands/transform-node-utils/steps/flattenListStep.js +1 -3
- package/dist/esm/editor-commands/transform-node-utils/steps/listToDecisionListStep.js +1 -1
- package/dist/esm/editor-commands/transform-node-utils/steps/listToListStep.js +1 -1
- package/dist/esm/editor-commands/transform-node-utils/steps/wrapMixedContentStep.js +80 -46
- package/dist/esm/editor-commands/transform-node-utils/transform.js +13 -15
- package/dist/esm/editor-commands/transformNode.js +8 -2
- package/dist/types/editor-commands/transform-node-utils/steps/applyTargetTextTypeStep.d.ts +10 -7
- package/dist/types/editor-commands/transform-node-utils/steps/flattenListStep.d.ts +0 -2
- package/dist/types/editor-commands/transform-node-utils/steps/wrapMixedContentStep.d.ts +3 -0
- package/dist/types-ts4.5/editor-commands/transform-node-utils/steps/applyTargetTextTypeStep.d.ts +10 -7
- package/dist/types-ts4.5/editor-commands/transform-node-utils/steps/flattenListStep.d.ts +0 -2
- package/dist/types-ts4.5/editor-commands/transform-node-utils/steps/wrapMixedContentStep.d.ts +3 -0
- package/package.json +2 -2
- package/dist/cjs/editor-commands/transform-node-utils/steps/wrapTextToCodeblock.js +0 -21
- package/dist/es2019/editor-commands/transform-node-utils/steps/wrapTextToCodeblock.js +0 -18
- package/dist/esm/editor-commands/transform-node-utils/steps/wrapTextToCodeblock.js +0 -16
- package/dist/types/editor-commands/transform-node-utils/steps/wrapTextToCodeblock.d.ts +0 -9
- 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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
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
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
-
|
|
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
|
|
144
|
+
const canNodeBeWrapped = node => {
|
|
120
145
|
const validationType = isLayout ? layoutColumn : targetNodeType;
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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,
|
|
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
|
-
|
|
220
|
-
heading
|
|
221
|
-
//
|
|
222
|
-
|
|
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.
|
|
49
|
-
|
|
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.
|
|
3
|
-
* (
|
|
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 "
|
|
9
|
-
* - paragraph "
|
|
7
|
+
* - paragraph "Text 1"
|
|
8
|
+
* - paragraph "Text 2"
|
|
10
9
|
*
|
|
11
10
|
* Output (with target: heading, level: 2):
|
|
12
|
-
* - heading (level: 2) "
|
|
13
|
-
* - heading (level: 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
|
|
27
|
-
if (!
|
|
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
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
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
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
|
|
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
|
|
142
|
+
var canNodeBeWrapped = function canNodeBeWrapped(node) {
|
|
118
143
|
var validationType = isLayout ? layoutColumn : targetNodeType;
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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,
|
|
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
|
-
|
|
220
|
-
heading
|
|
221
|
-
//
|
|
222
|
-
|
|
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) {
|